<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 Alerts are used to display important messages inline or as toast notifications.
 * @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-alert--docs
 * @status stable
 * @since 1.20.0
 *
 * @dependency syn-icon-button
 *
 * @slot - The alert's main content.
 * @slot icon - An icon to show in the alert. Works best with `<syn-icon>`.
 *
 * @event syn-show - Emitted when the alert opens.
 * @event syn-after-show - Emitted after the alert opens and all animations are complete.
 * @event syn-hide - Emitted when the alert closes.
 * @event syn-after-hide - Emitted after the alert closes and all animations are complete.
 *
 * @csspart base - The component's base wrapper.
 * @csspart icon - The container that wraps the optional icon.
 * @csspart message - The container that wraps the alert's main content.
 * @csspart close-button - The close button, an `<syn-icon-button>`.
 * @csspart close-button__base - The close button's exported `base` part.
 *
 * @animation alert.show - The animation to use when showing the alert.
 * @animation alert.hide - The animation to use when hiding the alert.
 */
import { computed, ref } from 'vue';
import '@synergy-design-system/components/components/alert/alert.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 SynAlert from '@synergy-design-system/components/components/alert/alert.component.js';

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

defineExpose({
  nativeElement,
});

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

  /**
   * Enables a close button that allows the user to dismiss the alert.
   */
  closable?: SynAlert['closable'];

  /**
   * The alert's theme variant.
   */
  variant?: SynAlert['variant'];

  /**
* The length of time, in milliseconds, the alert will show before closing itself.
* If the user interacts with
the alert before it closes (e.g.
* moves the mouse over it), the timer will restart.
* Defaults to `Infinity`, meaning
the alert will not close on its own.
 */
  duration?: SynAlert['duration'];

  /**
   * The alert's size.
   */
  size?: SynAlert['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 alert opens.
   */
  'syn-show': [e: SynShowEvent];

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

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

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