<script setup>
defineProps({
  action: String,
  info: Object
})

const tab = ref('pre_condition')
const tabs = ref([
  {value: 'pre_condition', text: 'Pre Condition'},
  {value: 'promotion_line', text: 'Promotion Line'},
  {value: 'quantity_distribution', text: 'Quantity Distribution'},
  {value: 'reward', text: 'Reward'},
])

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

<template>
  <div class="bt-2px_dashed_hexe2e2e2">
    <DetailRecordTab v-model="tab" :tabs="tabs" @handler="(val) => openTab(val.value)" />
    <MaterialsPromotionDetailRecordPreCondition v-if="tab === 'pre_condition'" :action="action" :info="info" />
    <MaterialsPromotionDetailRecordLine v-else-if="tab === 'promotion_line'" :action="action" :info="info" />
    <MaterialsPromotionDetailRecordQuantityDistribution v-else-if="tab === 'quantity_distribution'" :action="action" :info="info" />
    <MaterialsPromotionDetailRecordReward v-else-if="tab === 'reward'" :action="action" :info="info" />
  </div>
</template>