// #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 { Busyable } from '../../../Behaviors/Busyable';
import { ContentAlignable } from '../../../Behaviors/ContentAlignable';
import { DropDownable } from '../../../Behaviors/DropDownable';
import { Fitable } from '../../../Behaviors/Fitable';
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 { TextElement } from '../../Primitives/Text/TextElement';
import { ProgressRingElement } from '../../Ranges/ProgressRing/ProgressRingElement';
import { MenuElement } from '../../Selectors/Menu/MenuElement';
import { ButtonBaseElement } from '../Abstracts/ButtonBaseElement';
import { dropDownButtonElementRetroStyle } from './Themes/DropDownButtonElement.Retro';
import { dropDownButtonElementTemplate } from './DropDownButtonElementTemplate';
import { dropDownButtonElementJoyStyle } from './Themes/DropDownButtonElement.Joy';
import { Themeable } from '../../../../Controls/Behaviors/Themeable';
import { dropDownButtonElementCosmopolitanStyle } from './Themes/DropDownButtonElement.Cosmopolitan';
import { Iconable } from '../../../Behaviors/Iconable';
// #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 icon - The icon slot.
 * @slot label - The label slot.
 * @slot overlay - The overlay slot (useful for badges).
 * @slot - The default dropdown content slot.
 *
 * @csspart button - The button part.
 * @csspart focusRing - The focus ring part.
 * @csspart ripple - The ripple part.
 * @csspart icon - The icon part.
 * @csspart label - The label part.
 * @csspart progressRing - The progress ring part.
 * @csspart popup - The popup part.
 * @csspart menu - The menu part.
 * @csspart iconCaret - The icon caret part.
 *
 * @cssprop {String} --dropdown-button-font-family - The font family for the Drop Down Button.
 * @cssprop {String} --dropdown-button-font-size - The font size for the Drop Down Button.
 * @cssprop {String} --dropdown-button-font-line-height - The line height for the Drop Down Button font.
 * @cssprop {String} --dropdown-button-font-weight - The font weight for the Drop Down Button.
 * @cssprop {String} --dropdown-button-font-letter-spacing - The letter spacing for the Drop Down Button font.
 * @cssprop {String} --dropdown-button-font-text-decoration - The text decoration for the Drop Down Button font.
 * @cssprop {String} --dropdown-button-font-text-transform - The text transform for the Drop Down Button font.
 * @cssprop {String} --dropdown-button-padding-top - The top padding for the Drop Down Button.
 * @cssprop {String} --dropdown-button-padding-right - The right padding for the Drop Down Button.
 * @cssprop {String} --dropdown-button-padding-bottom - The bottom padding for the Drop Down Button.
 * @cssprop {String} --dropdown-button-padding-left - The left padding for the Drop Down Button.
 * @cssprop {String} --dropdown-button-gap - The gap between Drop Down Button elements.
 * @cssprop {String} --dropdown-button-transition-duration - The transition duration for the Drop Down Button.
 * @cssprop {String} --dropdown-button-transition-mode - The transition mode for the Drop Down Button.
 * @cssprop {String} --dropdown-button-transition-property - The transition property for the Drop Down Button.
 * @cssprop {String} --dropdown-button-background-color - The background color of the Drop Down Button.
 * @cssprop {String} --dropdown-button-border-color - The border color of the Drop Down Button.
 * @cssprop {String} --dropdown-button-foreground-color - The foreground color of the Drop Down Button.
 * @cssprop {String} --dropdown-button-border-width - The border width of the Drop Down Button.
 * @cssprop {String} --dropdown-button-border-radius - The border radius of the Drop Down Button.
 * @cssprop {String} --dropdown-button-border-style - The border style of the Drop Down Button.
 * @cssprop {String} --dropdown-button-shadow - The shadow of the Drop Down Button.
 * @cssprop {String} --focus-ring-outward-offset - The outward offset for the focus ring.
 * @cssprop {String} --dropdown-button-line-height - The line height for the Drop Down Button text.
 *
 * @dependency {StackElement} - The Stack element.
 * @dependency {IconElement} - The Icon element.
 * @dependency {RippleElement} - The Ripple element.
 * @dependency {FocusRingElement} - The Focus Ring element.
 * @dependency {TextElement} - The Text element.
 * @dependency {ProgressRingElement} - The Progress Ring element.
 * @dependency {FloatingElement} - The Floating element.
 * @dependency {MenuElement} - The Menu element.
 *
 * @example
 * ```html
 * <mosaik-dropdown-button label="Options" icon="menu">
 *   <mosaik-menu>
 *     <mosaik-menu-item>Option 1</mosaik-menu-item>
 *     <mosaik-menu-item>Option 2</mosaik-menu-item>
 *   </mosaik-menu>
 * </mosaik-dropdown-button>
 * ```
 *
 * @public
 */
let DropDownButtonElement = class DropDownButtonElement extends Themeable(Reversible(Orientable(ContentAlignable(Fitable(DropDownable(Busyable(Labelable(Iconable(ButtonBaseElement))))))))) {
    // #region Fields
    _clickOutsideController;
    _caretVisible;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._caretVisible = true;
        this._clickOutsideController = new ClickOutsideController(this, {
            skipInitial: true,
            callback: () => this.onClickedOutside()
        });
        // TODO: set this with object.assign
        this.maxDropDownHeight = 0;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link 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
     */
    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 = __decorate([
    Component({
        selector: 'mosaik-dropdown-button',
        template: dropDownButtonElementTemplate,
        themes: {
            joy: dropDownButtonElementJoyStyle,
            retro: dropDownButtonElementRetroStyle,
            cosmopolitan: dropDownButtonElementCosmopolitanStyle
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        },
        imports: [
            StackElement,
            IconElement,
            RippleElement,
            FocusRingElement,
            TextElement,
            ProgressRingElement,
            FloatingElement,
            MenuElement
        ]
    }),
    __metadata("design:paramtypes", [])
], DropDownButtonElement);
export { DropDownButtonElement };
//# sourceMappingURL=DropDownButtonElement.js.map