<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 Flexible button / link component that can be used to quickly build navigations.
 * @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-nav-item--docs
 * Takes one of 3 forms:
 * - button (default),
 * - link (overrides button if a 'href' is provided),
 * - or accordion (overrides all other if 'children' slot is defined).
 *
 * @status stable
 * @since 1.15.0
 *
 * @dependency syn-divider
 * @dependency syn-icon
 *
 * @event syn-show - Emitted when the navigation item:
 * - has children,
 * - and is clicked while HTML details are hidden.
 *
 * @event syn-hide - Emitted when the navigation item:
 * - has children,
 * - and is clicked while HTML details are shown.
 *
 * @event syn-blur - Emitted when the button loses focus.
 * @event syn-focus - Emitted when the button gains focus.
 *
 * @slot - The navigation item's label.
 * @slot prefix - A presentational prefix icon or similar element.
 * @slot suffix - A presentational suffix icon or similar element.
 * @slot children - Slot used to provide nested child navigation elements.
 * If provided, details and summary elements will be used.
 * A chevron will be shown on the right side regardless of the chevron property.
 *
 * @csspart base - The component's base wrapper including children.
 * @csspart children - The wrapper that holds the children
 * @csspart content-wrapper - The component's content wrapper.
 * @csspart content - The component's content excluding children.
 * @csspart current-indicator - The indicator used when current is set to true
 * @csspart chevron - The container that wraps the chevron.
 * @csspart details - The details element rendered when there are children available
 * @csspart divider - The components optional top divider.
 * @csspart prefix - The container that wraps the prefix.
 * @csspart suffix - The container that wraps the suffix.
 *
 * @cssproperty --indentation - Numeric value, indicating the level the item is placed at.
 * @cssproperty --indentation-stepping - The amount of pixels each level will indent.
 * @cssproperty --display-children - Display property of the children. Defaults to "contents"
 */
import { computed, ref } from 'vue';
import '@synergy-design-system/components/components/nav-item/nav-item.js';

import type { SynShowEvent } from '@synergy-design-system/components';
import type { SynHideEvent } from '@synergy-design-system/components';
import type { SynBlurEvent } from '@synergy-design-system/components';
import type { SynFocusEvent } from '@synergy-design-system/components';
import type SynNavItem from '@synergy-design-system/components/components/nav-item/nav-item.component.js';

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

defineExpose({
  nativeElement,
});

// Map attributes
const props = defineProps<{
  /**
* The navigation item's href target.
If provided, the navigation item will use an anchor tag otherwise it will use a button tag.

If the 'children' slot is provided, the navigation item will ignore the 'href' and use
accordion behavior.
 */
  href?: SynNavItem['href'];

  /**
   * Tells the browser where to open the link.
   * Only used when `href` is present.
   */
  target?: SynNavItem['target'];

  /**
* When using `href`, this attribute will map to the underlying link's `rel` attribute.
Unlike regular links, the default is `noreferrer noopener` to prevent security exploits.

However, if you're using `target` to point to a specific tab/window,
this will prevent that from working correctly.

You can remove or change the default value by setting the attribute
to an empty string or a value of your choice, respectively.
 */
  rel?: SynNavItem['rel'];

  current?: SynNavItem['current'];

  /**
   * Disables the navigation item.
   */
  disabled?: SynNavItem['disabled'];

  /**
   * The navigation item's orientation.
   */
  horizontal?: SynNavItem['horizontal'];

  /**
* Appends a chevron to the right side of a navigation item.
Only used if `horizontal` is false.
 */
  chevron?: SynNavItem['chevron'];

  /**
* Reflects HTML details element state and allows control from parent.
Only used if `horizontal` is false and `children` is defined.
 */
  open?: SynNavItem['open'];

  /**
* Toggle to true to show a divider above the element.
Only available when horizontal is false.
 */
  divider?: SynNavItem['divider'];
}>();

// 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 navigation item: - has children, - and is clicked while HTML details are hidden.
   */
  'syn-show': [e: SynShowEvent];

  /**
   * Emitted when the navigation item: - has children, - and is clicked while HTML details are shown.
   */
  'syn-hide': [e: SynHideEvent];

  /**
   * Emitted when the button loses focus.
   */
  'syn-blur': [e: SynBlurEvent];

  /**
   * Emitted when the button gains focus.
   */
  'syn-focus': [e: SynFocusEvent];
}>();
</script>

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

<template>
  <syn-nav-item
    @syn-show="$emit('syn-show', $event)"
    @syn-hide="$emit('syn-hide', $event)"
    @syn-blur="$emit('syn-blur', $event)"
    @syn-focus="$emit('syn-focus', $event)"
    v-bind="visibleProps"
    ref="nativeElement">
    <slot></slot>
  </syn-nav-item>
</template>
