// #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 { growHorIn, growVerIn, growVerOut } from '../../../../Animations/Presets/Grow';
import { Animatable } from '../../../Behaviors/Animatable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Expandable } from '../../../Behaviors/Expandable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { ExpandDirection } from '../../../Types/ExpandDirection';
import { CustomElement } from '../../Abstracts/CustomElement';
import { expandableElementTemplate } from './ExpandableElementTemplate';
import { expandableElementCosmopolitanStyle } from './Themes/ExpandableElement.Cosmopolitan';
import { expandableElementJoyStyle } from './Themes/ExpandableElement.Joy';
import { expandableElementMemphisStyle } from './Themes/ExpandableElement.Memphis';
// #endregion
/**
 * Expandable - A collapsible container that can be expanded or collapsed to reveal or hide its content.
 *
 * @description
 * The Expandable component provides a way to organize and display content that can be toggled to show or hide.
 * It typically consists of a header section that serves as a toggle button and a content section that can be expanded or collapsed.
 * Expandables are commonly used in UIs to manage space and provide a cleaner user experience by allowing users to focus on relevant information.
 *
 * @element mosaik-expandable
 * @category Layout
 *
 * @fires expanded {ExpandedEvent} - Called when the element is expanded.
 * @fires collapsed {CollapsedEvent} - Called when the element is collapsed.
 * @fires toggled {ToggledEvent} - Called when the element is toggled.
 *
 * @example
 * ```html
 * <mosaik-expandable>
 *   <!-- Content to be revealed or hidden -->
 * </mosaik-expandable>
 * ```
 *
 * @public
 */
let ExpandableElement = class ExpandableElement extends Themeable(Expandable(Animatable(Disableable(CustomElement)))) {
    // #region Fields
    _direction;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._direction = ExpandDirection.Down;
    }
    // #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-expandable';
    }
    /**
     * Gets or sets the `direction` property.
     *
     * @public
     * @attr
     */
    get direction() {
        return this._direction;
    }
    set direction(value) {
        if (this._direction !== value) {
            this._direction = value;
            this.requestUpdate('direction');
        }
    }
    // #endregion
    // #region Methods
    /**
     * This method is invoked when the `isExpanded` property is changed.
     * Handles the animation based on the expand direction.
     *
     * @param prev - The previous value of `isExpanded`.
     * @param next - The new value of `isExpanded`.
     * @public
     * @override
     */
    onIsExpandedChanged(prev, next) {
        if (prev === next) {
            return;
        }
        // Handle initial state without animation
        if (this.isUpdatePending) {
            super.onIsExpandedChanged(prev, next);
            return;
        }
        // Determine animations based on direction
        const inAnimation = this._direction === ExpandDirection.Down || this._direction === ExpandDirection.Up
            ? growVerIn
            : growHorIn;
        const outAnimation = this._direction === ExpandDirection.Down || this._direction === ExpandDirection.Up
            ? growVerOut
            : growHorIn;
        // Play animation before calling super (which emits events)
        if (next) {
            void this.play(inAnimation);
        }
        else {
            void this.play(outAnimation);
        }
        // Call super to update state and emit events
        super.onIsExpandedChanged(prev, next);
    }
};
__decorate([
    Attribute({ type: ExpandDirection }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], ExpandableElement.prototype, "direction", null);
ExpandableElement = __decorate([
    Component({
        selector: 'mosaik-expandable',
        template: expandableElementTemplate,
        themes: {
            joy: expandableElementJoyStyle,
            memphis: expandableElementMemphisStyle,
            cosmopolitan: expandableElementCosmopolitanStyle
        },
        host: {
            'attr.exportparts': 'content:expandable-content'
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], ExpandableElement);
export { ExpandableElement };
//# sourceMappingURL=ExpandableElement.js.map