<script setup>
const props = defineProps({
  action: String,
  info: Object,
  tab: String
})

const tab = ref(props.tab || 'rma_line')
const tabs = ref([
  {value: 'rma_line', text: 'RMA Line'},
  {value: 'rma_tax', text: 'RMA Tax'},
])

watch(() => props.tab, () => {
  tab.value = props.tab
})

const openTab = async (val) => {
  if(tab.value !== val) {
    tab.value = val
    sessionStorage.setItem('customer_rma_detail_record', tab.value)
  }
}
onMounted(() => {
  const getSessionStorageTab = sessionStorage.getItem('customer_rma_detail_record')
  if(getSessionStorageTab) {
    openTab(getSessionStorageTab)
  }
})
</script>

<template>
  <div class="card sd-none bd-1px_solid_hexe4e3e6">
    <DetailRecordTab v-model="tab" :tabs="tabs" @handler="(val) => openTab(val.value)" />
    <RmasCustomerRmaDetailRecordLine v-if="tab === 'rma_line'" :action="action" :info="info" />
    <RmasCustomerRmaDetailRecordTax v-else-if="tab === 'rma_tax'" :action="action" :info="info" />
  </div>
</template>