// #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 SplitButtonElement_1;
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 { 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 { splitButtonElementTemplate } from './SplitButtonElementTemplate';
import { splitButtonElementJoyStyle } from './Themes/SplitButtonElement.Joy';
import { splitButtonElementRetroStyle } from './Themes/SplitButtonElement.Retro';
import { splitButtonElementCosmopolitanStyle } from './Themes/SplitButtonElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
import { Iconable } from '../../../Behaviors/Iconable';
import { PortalElement } from '../../Primitives/Portal/PortalElement';
import { ProjectionController } from '../../Primitives/Portal/ProjectionController';
// #endregion
/**
 * Split Button - A user interface element that combines a regular button with a dropdown menu.
 *
 * @description
 * The Split Button is a versatile user interface component that merges the functionality of a standard button
 * with that of a dropdown menu. It typically consists of a visible button element and an attached dropdown menu.
 * When users click the button, it triggers a default action, while clicking the arrow or a designated part of the
 * button reveals a dropdown menu with additional options or actions. Split Buttons are commonly used for providing
 * both a primary action and a set of related secondary actions in applications.
 *
 * @name Split Button
 * @element mosaik-split-button
 * @category Buttons
 *
 * @slot icon - The icon slot.
 * @slot label - The label slot.
 * @slot overlay - The overlay slot (useful for badge).
 * @slot - The default dropdown content slot.
 *
 * @csspart button - The button part of the split button.
 * @csspart button split - The split button part.
 * @csspart focusRing - The focus ring part of the split button.
 * @csspart ripple - The ripple part of the split button.
 * @csspart icon - The icon part of the split button.
 * @csspart label - The label part of the split button.
 * @csspart progressRing - The progress ring part of the split button.
 * @csspart popup - The popup part of the split button.
 * @csspart menu - The menu part of the split button.
 * @csspart buttonSplit - The part of the button responsible for splitting the button from the dropdown.
 * @csspart iconCaret - The caret icon part used for dropdown indication.
 *
 * @cssprop {String} --split-button-font-family - The font family of the split button.
 * @cssprop {String} --split-button-font-size - The font size of the split button.
 * @cssprop {String} --split-button-font-line-height - The font line height of the split button.
 * @cssprop {String} --split-button-font-weight - The font weight of the split button.
 * @cssprop {String} --split-button-font-letter-spacing - The font letter spacing of the split button.
 * @cssprop {String} --split-button-font-text-decoration - The font text decoration of the split button.
 * @cssprop {String} --split-button-font-text-transform - The font text transform of the split button.
 * @cssprop {String} --split-button-padding-top - The padding top of the split button.
 * @cssprop {String} --split-button-padding-right - The padding right of the split button.
 * @cssprop {String} --split-button-padding-bottom - The padding bottom of the split button.
 * @cssprop {String} --split-button-padding-left - The padding left of the split button.
 * @cssprop {String} --split-button-gap - The gap between elements of the split button.
 * @cssprop {String} --split-button-transition-duration - The transition duration for the split button.
 * @cssprop {String} --split-button-transition-mode - The transition mode for the split button.
 * @cssprop {String} --split-button-transition-property - The transition property for the split button.
 * @cssprop {String} --split-button-background-color - The background color of the split button.
 * @cssprop {String} --split-button-border-color - The border color of the split button.
 * @cssprop {String} --split-button-foreground-color - The foreground color of the split button.
 * @cssprop {String} --split-button-border-width - The border width of the split button.
 * @cssprop {String} --split-button-border-radius - The border radius of the split button.
 * @cssprop {String} --split-button-border-style - The border style of the split button.
 * @cssprop {String} --split-button-shadow - The shadow of the split button.
 * @cssprop {String} --focus-ring-outward-offset - The outward offset of the focus ring.
 * @cssprop {String} --split-button-line-height - The line height of the split button text.
 *
 * @dependency {StackElement} mosaik-stack - The Stack component, used for layout management.
 * @dependency {IconElement} mosaik-icon - The Icon component, used for displaying the icon.
 * @dependency {RippleElement} mosaik-ripple - The Ripple component, used for the ripple effect.
 * @dependency {FocusRingElement} mosaik-focus-ring - The Focus Ring component, used for focus indication.
 * @dependency {TextElement} mosaik-text - The Text component, used for displaying the label text.
 * @dependency {ProgressRingElement} mosaik-progress-ring - The Progress Ring component, used for progress indication.
 * @dependency {FloatingElement} mosaik-floating - The Floating component, used for floating behavior.
 * @dependency {MenuElement} mosaik-menu - The Menu component, used for dropdown menu functionality.
 *
 * @example
 * ```html
 * <mosaik-split-button>
 *   <span>Button</span>
 *   <mosaik-menu>
 *     <mosaik-menu-item>Option 1</mosaik-menu-item>
 *     <mosaik-menu-item>Option 2</mosaik-menu-item>
 *   </mosaik-menu>
 * </mosaik-split-button>
 * ```
 *
 * @public
 */
let SplitButtonElement = SplitButtonElement_1 = class SplitButtonElement extends Themeable(Reversible(Orientable(ContentAlignable(Fitable(DropDownable(Busyable(Labelable(Iconable(ButtonBaseElement))))))))) {
    // #region Fields
    _clickOutsideController;
    _projectionController;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._clickOutsideController = new ClickOutsideController(this, {
            skipInitial: true,
            callback: () => this.onClickedOutside()
        });
        this._projectionController = new ProjectionController(this, {
            slotName: '',
            targetSelector: '[part="projection"]',
            projecting: (element) => {
                element.setAttribute(`${SplitButtonElement_1.is}-projection`, '');
            }
        });
        // REMARK: This is a workaround for the issue with the docs generation.
        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-split-button';
    }
    // #endregion
    // #region Methods
    /**
     * @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();
        }
    }
    onIsBusyPropertyChanged(_prev, next) {
        // if busy, close the popup
        if (next) {
            this.isDropDownOpen = false;
        }
    }
    onSplit(e) {
        this.toggle();
    }
    /**
     * @private
     */
    onClickedOutside() {
        this.close();
    }
};
__decorate([
    Watch('isDropDownOpen', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], SplitButtonElement.prototype, "onIsDropDownOpenPropertyChanged", null);
__decorate([
    Watch('isBusy', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], SplitButtonElement.prototype, "onIsBusyPropertyChanged", null);
SplitButtonElement = SplitButtonElement_1 = __decorate([
    Component({
        selector: 'mosaik-split-button',
        template: splitButtonElementTemplate,
        themes: {
            joy: splitButtonElementJoyStyle,
            retro: splitButtonElementRetroStyle,
            cosmopolitan: splitButtonElementCosmopolitanStyle
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        },
        imports: [
            StackElement,
            IconElement,
            RippleElement,
            FocusRingElement,
            TextElement,
            ProgressRingElement,
            FloatingElement,
            MenuElement,
            PortalElement
        ]
    }),
    __metadata("design:paramtypes", [])
], SplitButtonElement);
export { SplitButtonElement };
//# sourceMappingURL=SplitButtonElement.js.map