<script setup>
const props = defineProps({
  modelValue: String,
  tabs: Array
})

const emit = defineEmits(['update:modelValue', 'handler'])

const openTab = async (val) => {
  if(props.modelValue !== val.value) {
    emit('update:modelValue', val.value)
    emit('handler', val)
  }
}
</script>

<template>
  <nav class="detailRecordTab sd-none">
    <div class="tabs is-boxed">
      <ul>
        <li v-for="(tab, index) in tabs" :key="tab.value" :class="{'is-active': tab.value === modelValue}">
          <a @click="openTab(tab)">
            <span :class="{'tab-inactive': tab.value !== modelValue}">{{ tab.text }}</span>
          </a>
        </li>
      </ul>
    </div>
  </nav>
</template>

<style scoped>
.item:not(.active) {
  color: inherit;
}

.detailRecordTab {
  background-color: var(--theme-surface);
  transition: background-color 0.3s ease;
}

.tab-inactive {
  color: var(--theme-text-muted);
}

/* Tab styling */
.detailRecordTab .tabs.is-boxed li a {
  background-color: var(--theme-bg-tertiary);
  border-color: var(--theme-border);
  color: var(--theme-text-primary);
}

.detailRecordTab .tabs.is-boxed li a:hover {
  background-color: var(--theme-bg-hover);
}

.detailRecordTab .tabs.is-boxed li.is-active a {
  background-color: var(--theme-surface) !important;
  border-color: var(--theme-border) !important;
  border-bottom-color: var(--theme-surface) !important;
  color: var(--theme-text-primary) !important;
  font-weight: bold;
}
</style>