// #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);
};
var DropDownButtonElement_1;
import { Themeable } from '../../../../Controls/Behaviors/Themeable';
import { Busyable } from '../../../Behaviors/Busyable';
import { ContentAlignable } from '../../../Behaviors/ContentAlignable';
import { DropDownable } from '../../../Behaviors/DropDownable';
import { Fitable } from '../../../Behaviors/Fitable';
import { Iconable } from '../../../Behaviors/Iconable';
import { Labelable } from '../../../Behaviors/Labelable';
import { Orientable } from '../../../Behaviors/Orientable';
import { Reversible } from '../../../Behaviors/Reversible';
import { ClickOutsideController } from '../../../Controllers/ClickOutsideController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { RippleElement } from '../../Effects/Ripple/RippleElement';
import { StackElement } from '../../Layouts/Stack/StackElement';
import { IconElement } from '../../Media/Icon/IconElement';
import { FloatingElement } from '../../Primitives/Floating/FloatingElement';
import { FocusRingElement } from '../../Primitives/FocusRing/FocusRingElement';
import { PortalElement } from '../../Primitives/Portal/PortalElement';
import { ProjectionController } from '../../Primitives/Portal/ProjectionController';
import { TextElement } from '../../Primitives/Text/TextElement';
import { ProgressRingElement } from '../../Ranges/ProgressRing/ProgressRingElement';
import { MenuElement } from '../../Selectors/Menu/MenuElement';
import { ButtonBaseElement } from '../Abstracts/ButtonBaseElement';
import { dropDownButtonElementTemplate } from './DropDownButtonElementTemplate';
import { dropDownButtonElementCosmopolitanStyle } from './Themes/DropDownButtonElement.Cosmopolitan';
import { dropDownButtonElementJoyStyle } from './Themes/DropDownButtonElement.Joy';
import { dropDownButtonElementMemphisStyle } from './Themes/DropDownButtonElement.Memphis';
// #endregion
/**
 * Drop Down Button - A button that opens a menu when clicked, allowing users to select from a list of options.
 *
 * @description
 * The Drop Down Button is a versatile user interface component that triggers a dropdown menu containing additional
 * options or actions. When clicked, the button reveals a menu with a list of choices, providing users with multiple
 * actions or selections in a compact and organized manner. Drop Down Buttons are commonly used in navigation bars,
 * toolbars, and other interactive areas where a set of related options needs to be presented.
 *
 * @name Drop Down Button
 * @element mosaik-dropdown-button
 * @category Buttons
 *
 * @slot - The default dropdown content slot.
 * @slot icon - The icon slot.
 * @slot label - The label slot.
 * @slot overlay - The overlay slot (useful for badges).
 *
 * @csspart button - The button part.
 * @csspart focusRing - The focus ring part.
 * @csspart icon - The icon part.
 * @csspart iconCaret - The icon caret part.
 * @csspart innerStack - The innerStack part.
 * @csspart label - The label part.
 * @csspart popup - The popup part.
 * @csspart portal - The portal part.
 * @csspart progressRing - The progress ring part.
 * @csspart projection - The projection part.
 * @csspart ripple - The ripple part.
 *
 * @cssprop {Color} --drop-down-button-background-color - The background color of the drop down button.
 * @cssprop {Color} --drop-down-button-border-color - The border color of the drop down button.
 * @cssprop {String} --drop-down-button-border-radius - The border radius of the drop down button.
 * @cssprop {String} --drop-down-button-border-style - The down button border style CSS custom property.
 * @cssprop {String} --drop-down-button-border-width - The border width of the drop down button.
 * @cssprop {String} --drop-down-button-focus-ring-active-width - The down button focus ring active width CSS custom property.
 * @cssprop {String} --drop-down-button-focus-ring-color - The down button focus ring color CSS custom property.
 * @cssprop {String} --drop-down-button-focus-ring-inward-offset - The down button focus ring inward offset CSS custom property.
 * @cssprop {String} --drop-down-button-focus-ring-outward-offset - The down button focus ring outward offset CSS custom property.
 * @cssprop {String} --drop-down-button-font-family - The font family of the drop down button.
 * @cssprop {String} --drop-down-button-font-letter-spacing - The letter spacing of the drop down button font.
 * @cssprop {String} --drop-down-button-font-line-height - The line height of the drop down button font.
 * @cssprop {String} --drop-down-button-font-size - The font size of the drop down button.
 * @cssprop {String} --drop-down-button-font-text-decoration - The text decoration of the drop down button font.
 * @cssprop {String} --drop-down-button-font-text-transform - The text transform of the drop down button font.
 * @cssprop {String} --drop-down-button-font-weight - The font weight of the drop down button.
 * @cssprop {Color} --drop-down-button-foreground-color - The foreground color of the drop down button.
 * @cssprop {String} --drop-down-button-gap - The gap between elements in the drop down button.
 * @cssprop {String} --drop-down-button-height - The down button height CSS custom property.
 * @cssprop {String} --drop-down-button-icon-min-height - The down button icon min height CSS custom property.
 * @cssprop {String} --drop-down-button-icon-min-width - The down button icon min width CSS custom property.
 * @cssprop {String} --drop-down-button-line-height - The down button line height CSS custom property.
 * @cssprop {String} --drop-down-button-min-height - The down button min height CSS custom property.
 * @cssprop {String} --drop-down-button-min-width - The down button min width CSS custom property.
 * @cssprop {String} --drop-down-button-padding-bottom - The bottom padding of the drop down button.
 * @cssprop {String} --drop-down-button-padding-left - The left padding of the drop down button.
 * @cssprop {String} --drop-down-button-padding-right - The right padding of the drop down button.
 * @cssprop {String} --drop-down-button-padding-top - The top padding of the drop down button.
 * @cssprop {String} --drop-down-button-progress-ring-width - The down button progress ring width CSS custom property.
 * @cssprop {String} --drop-down-button-progress-thickness - The down button progress thickness CSS custom property.
 * @cssprop {Color} --drop-down-button-ripple-color - The down button ripple color CSS custom property.
 * @cssprop {String} --drop-down-button-ripple-duration - The down button ripple duration CSS custom property.
 * @cssprop {String} --drop-down-button-shadow - The shadow of the drop down button.
 * @cssprop {String} --drop-down-button-shadow-blur - The down button shadow blur CSS custom property.
 * @cssprop {String} --drop-down-button-shadow-color - The down button shadow color CSS custom property.
 * @cssprop {String} --drop-down-button-shadow-offset-x - The down button shadow offset x CSS custom property.
 * @cssprop {String} --drop-down-button-shadow-offset-y - The down button shadow offset y CSS custom property.
 * @cssprop {String} --drop-down-button-shadow-spread - The down button shadow spread CSS custom property.
 * @cssprop {String} --drop-down-button-transform - The down button transform CSS custom property.
 * @cssprop {String} --drop-down-button-transition-duration - The transition duration of the drop down button.
 * @cssprop {String} --drop-down-button-transition-mode - The down button transition mode CSS custom property.
 * @cssprop {String} --drop-down-button-transition-property - The down button transition property CSS custom property.
 * @cssprop {String} --drop-down-button-translate - The down button translate CSS custom property.
 * @cssprop {String} --drop-down-button-width - The down button width CSS custom property.
 *
 * @dependency mosaik-floating - The Floating element.
 * @dependency mosaik-focus-ring - The Focus Ring element.
 * @dependency mosaik-icon - The Icon element.
 * @dependency mosaik-portal - The Portal element.
 * @dependency mosaik-progress-ring - The Progress Ring element.
 * @dependency mosaik-ripple - The Ripple element.
 * @dependency mosaik-stack - The Stack element.
 * @dependency mosaik-text - The Text element.
 *
 * @example
 * Basic dropdown button:
 * ```html
 * <mosaik-dropdown-button label="Options">
 *   <mosaik-menu>
 *     <mosaik-menu-item label="Option 1"></mosaik-menu-item>
 *     <mosaik-menu-item label="Option 2"></mosaik-menu-item>
 *   </mosaik-menu>
 * </mosaik-dropdown-button>
 * ```
 *
 * @example
 * Dropdown button with variant and no caret:
 * ```html
 * <mosaik-dropdown-button label="Actions" variant="primary" caret-visible="false">
 *   <mosaik-menu>
 *     <mosaik-menu-item label="Edit"></mosaik-menu-item>
 *     <mosaik-menu-item label="Delete"></mosaik-menu-item>
 *   </mosaik-menu>
 * </mosaik-dropdown-button>
 * ```
 *
 * @public
 */
let DropDownButtonElement = DropDownButtonElement_1 = class DropDownButtonElement extends Themeable(Reversible(Orientable(ContentAlignable(Fitable(DropDownable(Busyable(Labelable(Iconable(ButtonBaseElement))))))))) {
    // #region Fields
    _clickOutsideController;
    _projectionController;
    _caretVisible;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._caretVisible = true;
        this._clickOutsideController = new ClickOutsideController(this, {
            skipInitial: true,
            callback: () => this.onClickedOutside()
        });
        this._projectionController = new ProjectionController(this, {
            slotName: '',
            targetSelector: '[part="projection"]',
            projecting: (element) => {
                element.setAttribute(`${DropDownButtonElement_1.is}-projection`, '');
            }
        });
        // REMARK: This is a workaround for the issue with the docs generation.
        Object.assign(this, { dropDownMaxHeight: 'auto' });
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-dropdown-button';
    }
    /**
     * Gets or sets the `caretVisible` property.
     *
     * @public
     * @attr caret-visible
     */
    get caretVisible() {
        return this._caretVisible;
    }
    set caretVisible(value) {
        if (this._caretVisible !== value) {
            this._caretVisible = value;
            this.requestUpdate('caretVisible');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    connectedCallback() {
        super.connectedCallback();
        this.on('click', (event) => {
            // check if the event.target is the button
            if (event.currentTarget !== this) {
                return;
            }
            this.toggle();
        });
    }
    /**
     * @protected
     */
    onIsDropDownOpenPropertyChanged(_prev, next) {
        // handle interaction outside of popup
        if (next) {
            // if busy, close the popup
            if (this.isBusy) {
                this.close();
                return;
            }
            this._clickOutsideController.observe();
        }
        else {
            this._clickOutsideController.unobserve();
        }
    }
    /**
     * @protected
     */
    onIsBusyPropertyChanged(_prev, next) {
        // if busy, close the popup
        if (next) {
            this.isDropDownOpen = false;
        }
    }
    /**
     * @private
     */
    onClickedOutside() {
        this.close();
    }
    /**
     * @private
     * @template
     */
    onFloatingActiveChanged(active) {
        if (!active) {
            this.close();
        }
    }
};
__decorate([
    Attribute({
        type: Boolean
        // useDefault: true // TODO: dump naming, because the default is actually true, and should be false
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DropDownButtonElement.prototype, "caretVisible", null);
__decorate([
    Watch('isDropDownOpen', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], DropDownButtonElement.prototype, "onIsDropDownOpenPropertyChanged", null);
__decorate([
    Watch('isBusy', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, String]),
    __metadata("design:returntype", void 0)
], DropDownButtonElement.prototype, "onIsBusyPropertyChanged", null);
DropDownButtonElement = DropDownButtonElement_1 = __decorate([
    Component({
        selector: 'mosaik-dropdown-button',
        template: dropDownButtonElementTemplate,
        themes: {
            joy: dropDownButtonElementJoyStyle,
            memphis: dropDownButtonElementMemphisStyle,
            cosmopolitan: dropDownButtonElementCosmopolitanStyle
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        },
        imports: [
            StackElement,
            IconElement,
            RippleElement,
            FocusRingElement,
            TextElement,
            ProgressRingElement,
            FloatingElement,
            MenuElement,
            PortalElement
        ]
    }),
    __metadata("design:paramtypes", [])
], DropDownButtonElement);
export { DropDownButtonElement };
//# sourceMappingURL=DropDownButtonElement.js.map