<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 Dropdowns expose additional content that "drops down" in a panel.
 * @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-dropdown--docs
 * @status stable
 * @since 1.12.0
 *
 * @dependency syn-popup
 *
 * @slot - The dropdown's main content.
 * @slot trigger - The dropdown's trigger, usually a `<syn-button>` element.
 *
 * @event syn-show - Emitted when the dropdown opens.
 * @event syn-after-show - Emitted after the dropdown opens and all animations are complete.
 * @event syn-hide - Emitted when the dropdown closes.
 * @event syn-after-hide - Emitted after the dropdown closes and all animations are complete.
 *
 * @csspart base - The component's base wrapper, an `<syn-popup>` element.
 * @csspart base__popup - The popup's exported `popup` part. Use this to target the tooltip's popup container.
 * @csspart trigger - The container that wraps the trigger.
 * @csspart panel - The panel that gets shown when the dropdown is open.
 *
 * @animation dropdown.show - The animation to use when showing the dropdown.
 * @animation dropdown.hide - The animation to use when hiding the dropdown.
 */
import { computed, ref } from 'vue';
import '@synergy-design-system/components/components/dropdown/dropdown.js';

import type { SynShowEvent } from '@synergy-design-system/components';
import type { SynAfterShowEvent } from '@synergy-design-system/components';
import type { SynHideEvent } from '@synergy-design-system/components';
import type { SynAfterHideEvent } from '@synergy-design-system/components';
import type SynDropdown from '@synergy-design-system/components/components/dropdown/dropdown.component.js';

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

defineExpose({
  nativeElement,
});

// Map attributes
const props = defineProps<{
  /**
* Indicates whether or not the dropdown is open.
* You can toggle this attribute to show and hide the dropdown, or you
can use the `show()` and `hide()` methods and this attribute will reflect the dropdown's open state.
 */
  open?: SynDropdown['open'];

  /**
* The preferred placement of the dropdown panel.
* Note that the actual placement may vary as needed to keep the panel
inside of the viewport.
 */
  placement?: SynDropdown['placement'];

  /**
   * Disables the dropdown so the panel will not open.
   */
  disabled?: SynDropdown['disabled'];

  /**
* By default, the dropdown is closed when an item is selected.
* This attribute will keep it open instead.
* Useful for
dropdowns that allow for multiple interactions.
 */
  stayOpenOnSelect?: SynDropdown['stayOpenOnSelect'];

  /**
   * The distance in pixels from which to offset the panel away from its trigger.
   */
  distance?: SynDropdown['distance'];

  /**
   * The distance in pixels from which to offset the panel along its trigger.
   */
  skidding?: SynDropdown['skidding'];

  /**
   * Syncs the popup width or height to that of the trigger element.
   */
  sync?: SynDropdown['sync'];

  /**
* The dropdown will close when the user interacts outside of this element (e.g.
* clicking).
* Useful for composing other
components that use a dropdown internally.
 */
  containingElement?: SynDropdown['containingElement'];
}>();

// 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 dropdown opens.
   */
  'syn-show': [e: SynShowEvent];

  /**
   * Emitted after the dropdown opens and all animations are complete.
   */
  'syn-after-show': [e: SynAfterShowEvent];

  /**
   * Emitted when the dropdown closes.
   */
  'syn-hide': [e: SynHideEvent];

  /**
   * Emitted after the dropdown closes and all animations are complete.
   */
  'syn-after-hide': [e: SynAfterHideEvent];
}>();
</script>

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

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