<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 Details show a brief summary and expand to show additional content.
 * @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-details--docs
 * @status stable
 * @since 2.3.0
 *
 * @dependency syn-icon
 *
 * @slot - The details' main content.
 * @slot summary - The details' summary. Alternatively, you can use the `summary` attribute.
 * @slot expand-icon - Optional expand icon to use instead of the default. Works best with `<syn-icon>`.
 * @slot collapse-icon - Optional collapse icon to use instead of the default. Works best with `<syn-icon>`.
 *
 * @event syn-show - Emitted when the details opens.
 * @event syn-after-show - Emitted after the details opens and all animations are complete.
 * @event syn-hide - Emitted when the details closes.
 * @event syn-after-hide - Emitted after the details closes and all animations are complete.
 *
 * @csspart base - The component's base wrapper.
 * @csspart header - The header that wraps both the summary and the expand/collapse icon.
 * @csspart summary - The container that wraps the summary.
 * @csspart summary-icon - The container that wraps the expand/collapse icons.
 * @csspart content - The details content.
 * @csspart body - The container that wraps the details content.
 *
 * @animation details.show - The animation to use when showing details. You can use `height: auto` with this animation.
 * @animation details.hide - The animation to use when hiding details. You can use `height: auto` with this animation.
 *
 * @cssproperty --syn-details-open-rotation - The rotation angle of the summary icon when the details is open.
 */
import { computed, ref } from 'vue';
import '@synergy-design-system/components/components/details/details.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 SynDetails from '@synergy-design-system/components/components/details/details.component.js';

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

defineExpose({
  nativeElement,
});

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

  /**
   * The summary to show in the header.
   * If you need to display HTML, use the `summary` slot instead.
   */
  summary?: SynDetails['summary'];

  /**
   * Disables the details so it can't be toggled.
   */
  disabled?: SynDetails['disabled'];

  /**
   * Draws the details as contained element.
   */
  contained?: SynDetails['contained'];

  /**
   * The details's size.
   */
  size?: SynDetails['size'];
}>();

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

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

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

  /**
   * Emitted after the details 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-details
    @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-details>
</template>
