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

const tab = ref(props.tab || 'order_line')
const tabs = ref([
  {value: 'order_line', text: 'Order Line'},
  {value: 'order_tax', text: 'Order Tax'},
  {value: 'payment_schedule', text: 'Payment Schedule'}
])

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

const openTab = async (val) => {
  if(tab.value !== val) {
    tab.value = val
    sessionStorage.setItem('purchase_order_detail_record', tab.value)
  }
}
onMounted(() => {
  const getSessionStorageTab = sessionStorage.getItem('purchase_order_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)" />
    <ProcurementsOrderDetailRecordLine v-if="tab === 'order_line'" :action="action" :info="info" />
    <ProcurementsOrderDetailRecordTax v-else-if="tab === 'order_tax'" :action="action" :info="info" />
    <ProcurementsOrderDetailRecordPaymentSchedule v-else-if="tab === 'payment_schedule'" :action="action" :info="info" />
  </div>
</template>