<script setup lang="ts">
// ---------------------------------------------------------------------
// 🔒 AUTOGENERATED @synergy-design-system/vue wrappers for @synergy-design-system/components
// Please do not edit this file directly!
// It will get recreated when running pnpm build.
// ---------------------------------------------------------------------

/**
 * @summary Tabs are used inside [tab groups](/components/tab-group) to represent and activate [tab panels](/components/tab-panel).
 * @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-tab--docs
 * @status stable
 * @since 2.1.0
 *
 * @dependency syn-icon-button
 *
 * @slot - The tab's label.
 *
 * @event syn-close - Emitted when the tab is closable and the close button is activated.
 *
 * @csspart base - The component's base wrapper.
 * @csspart close-button - The close button, an `<syn-icon-button>`.
 * @csspart close-button__base - The close button's exported `base` part.
 */
import { computed, ref } from 'vue';
import '@synergy-design-system/components/components/tab/tab.js';

import type { SynCloseEvent } from '@synergy-design-system/components';
import type SynTab from '@synergy-design-system/components/components/tab/tab.component.js';

// DOM Reference to the element
const nativeElement = ref<SynTab>();

defineExpose({
  nativeElement,
});

// Map attributes
const props = defineProps<{
  /**
   * The name of the tab panel this tab is associated with.
   * The panel must be located in the same tab group.
   */
  panel?: SynTab['panel'];

  /**
   * Draws the tab in an active state.
   */
  active?: SynTab['active'];

  /**
   * Makes the tab closable and shows a close button.
   */
  closable?: SynTab['closable'];

  /**
   * Disables the tab and prevents selection.
   */
  disabled?: SynTab['disabled'];
}>();

// Make sure prop binding only forwards the props that are actually there.
// This is needed because :param="param" also adds an empty attribute
// when using web-components, which breaks optional arguments like size in SynInput
// @see https://github.com/vuejs/core/issues/5190#issuecomment-1003112498
const visibleProps = computed(() =>
  Object.fromEntries(
    Object.entries(props).filter(([, value]) => typeof value !== 'undefined'),
  ),
);

// Map events
defineEmits<{
  /**
   * Emitted when the tab is closable and the close button is activated.
   */
  'syn-close': [e: SynCloseEvent];
}>();
</script>

<script lang="ts">
export type { SynCloseEvent } from '@synergy-design-system/components';
</script>

<template>
  <syn-tab
    @syn-close="$emit('syn-close', $event)"
    v-bind="visibleProps"
    ref="nativeElement">
    <slot></slot>
  </syn-tab>
</template>
