// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { getSlotElementOfType } from '../../../../Dom/Slot';
import { on } from '@breadstone/mosaik-elements';
import { ClickOutsideController } from '../../../Controllers/ClickOutsideController';
import { Component } from '../../../Decorators/ComponentDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { FloatingElement } from './FloatingElement';
import { floatingTriggerElementTemplate } from './FloatingTriggerElementTemplate';
import { floatingTriggerElementJoyStyle } from './Themes/FloatingTriggerElement.Joy';
import { floatingTriggerElementMemphisStyle } from './Themes/FloatingTriggerElement.Memphis';
import { floatingTriggerElementCosmopolitanStyle } from './Themes/FloatingTriggerElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
// #endregion
/**
 * FloatingTrigger - A convenience wrapper that manages trigger-floating element interactions automatically.
 *
 * @description
 * The FloatingTrigger component simplifies the common pattern of showing/hiding floating elements in response
 * to trigger interactions. It automatically connects a trigger element to a floating element, handling click
 * interactions, click-outside detection, and managing the active state. This component eliminates boilerplate
 * code for common dropdown, popover, and menu patterns by providing declarative trigger-content relationships.
 *
 * @name FloatingTrigger
 * @element mosaik-floating-trigger
 * @category Primitives
 *
 * @slot - The trigger element that activates the floating content (typically a button)
 * @slot floating - The floating element to show/hide (typically mosaik-floating)
 *
 * @cssprop {String} --floating-trigger-font-family - The trigger font family CSS custom property.
 * @cssprop {String} --floating-trigger-font-letter-spacing - The trigger font letter spacing CSS custom property.
 * @cssprop {String} --floating-trigger-font-line-height - The trigger font line height CSS custom property.
 * @cssprop {String} --floating-trigger-font-size - The trigger font size CSS custom property.
 * @cssprop {String} --floating-trigger-font-text-decoration - The trigger font text decoration CSS custom property.
 * @cssprop {String} --floating-trigger-font-text-transform - The trigger font text transform CSS custom property.
 * @cssprop {String} --floating-trigger-font-weight - The trigger font weight CSS custom property.
 * @cssprop {String} --floating-trigger-gap - The trigger gap CSS custom property.
 * @cssprop {String} --floating-trigger-padding-bottom - The trigger padding bottom CSS custom property.
 * @cssprop {String} --floating-trigger-padding-left - The trigger padding left CSS custom property.
 * @cssprop {String} --floating-trigger-padding-right - The trigger padding right CSS custom property.
 * @cssprop {String} --floating-trigger-padding-top - The trigger padding top CSS custom property.
 * @cssprop {String} --floating-trigger-shadow - The trigger shadow CSS custom property.
 * @cssprop {String} --floating-trigger-shadow-blur - The trigger shadow blur CSS custom property.
 * @cssprop {String} --floating-trigger-shadow-color - The trigger shadow color CSS custom property.
 * @cssprop {String} --floating-trigger-shadow-offset-x - The trigger shadow offset x CSS custom property.
 * @cssprop {String} --floating-trigger-shadow-offset-y - The trigger shadow offset y CSS custom property.
 * @cssprop {String} --floating-trigger-shadow-spread - The trigger shadow spread CSS custom property.
 * @cssprop {String} --floating-trigger-transition-duration - The trigger transition duration CSS custom property.
 * @cssprop {String} --floating-trigger-transition-mode - The trigger transition mode CSS custom property.
 * @cssprop {String} --floating-trigger-transition-property - The trigger transition property CSS custom property.
 * @cssprop {String} --floating-trigger-translate - The trigger translate CSS custom property.
 *
 * @example
 * Basic dropdown trigger:
 * ```html
 * <mosaik-floating-trigger>
 *   <mosaik-button label="Open Menu"></mosaik-button>
 *   <mosaik-floating slot="floating" placement="bottom-start">
 *     <mosaik-menu>
 *       <mosaik-menu-item label="Option 1"></mosaik-menu-item>
 *       <mosaik-menu-item label="Option 2"></mosaik-menu-item>
 *     </mosaik-menu>
 *   </mosaik-floating>
 * </mosaik-floating-trigger>
 * ```
 *
 * @example
 * Popover with custom trigger:
 * ```html
 * <mosaik-floating-trigger>
 *   <div class="custom-trigger">Click for more info</div>
 *   <mosaik-floating slot="floating" placement="top">
 *     <mosaik-card>
 *       <p>Additional information here</p>
 *     </mosaik-card>
 *   </mosaik-floating>
 * </mosaik-floating-trigger>
 * ```
 *
 * @example
 * Icon button with dropdown:
 * ```html
 * <mosaik-floating-trigger>
 *   <mosaik-button icon="more-vertical" appearance="plain"></mosaik-button>
 *   <mosaik-floating slot="floating" placement="bottom-end">
 *     <mosaik-list>
 *       <mosaik-list-item>Edit</mosaik-list-item>
 *       <mosaik-list-item>Delete</mosaik-list-item>
 *     </mosaik-list>
 *   </mosaik-floating>
 * </mosaik-floating-trigger>
 * ```
 *
 * @public
 */
let FloatingTriggerElement = class FloatingTriggerElement extends Themeable(CustomElement) {
    // #region Fields
    _clickOutsideController;
    _clickSubscription;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._clickSubscription = null;
        this._clickOutsideController = new ClickOutsideController(this, {
            skipInitial: true,
            callback: () => this.onClickedOutside()
        });
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-floating-trigger';
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    disconnectedCallback() {
        super.disconnectedCallback();
        this._clickSubscription?.dispose();
    }
    /**
     * @internal
     * @template
     */
    onSlotChange(event) {
        const assignedElements = event.target.assignedElements();
        const firstElement = assignedElements.at(0);
        if (firstElement) {
            this._clickSubscription = on(firstElement, 'click', () => {
                const floatingElement = getSlotElementOfType(this.shadowRoot, FloatingElement, 'floating');
                if (!floatingElement.active) {
                    floatingElement.active = true;
                    this._clickOutsideController.observe();
                }
                else {
                    floatingElement.active = false;
                    this._clickOutsideController.unobserve();
                }
            });
        }
        if (assignedElements.length > 1) {
            throw new Error('Only one element is allowed in the slot.');
        }
    }
    /**
     * @private
     */
    onClickedOutside() {
        this._clickOutsideController.unobserve();
        const floatingElement = getSlotElementOfType(this.shadowRoot, FloatingElement, 'floating');
        floatingElement.active = false;
    }
};
FloatingTriggerElement = __decorate([
    Component({
        selector: 'mosaik-floating-trigger',
        template: floatingTriggerElementTemplate,
        themes: {
            joy: floatingTriggerElementJoyStyle,
            memphis: floatingTriggerElementMemphisStyle,
            cosmopolitan: floatingTriggerElementCosmopolitanStyle
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], FloatingTriggerElement);
export { FloatingTriggerElement };
//# sourceMappingURL=FloatingTriggerElement.js.map