// #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 { RegistryController } from '../../../Controllers/RegistryController';
import { fadeIn, fadeOut } from '../../../../Animations/Presets/Fade';
import { DomServiceLocator } from '../../../../Dom/Dom';
import { Animatable } from '../../../Behaviors/Animatable';
import { Dimensionable } from '../../../Behaviors/Dimensionable';
import { Elevatable } from '../../../Behaviors/Elevatable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { DrawerMode } from '../../../Types/DrawerMode';
import { DrawerPosition } from '../../../Types/DrawerPosition';
import { ElevationWeight } from '../../../Types/ElevationWeight';
import { ButtonElement } from '../../Buttons/Button/ButtonElement';
import { ToolbarElement } from '../../Grouping/Toolbar/ToolbarElement';
import { BackdropElement } from '../../Primitives/Backdrop/BackdropElement';
import { ElevationElement } from '../../Primitives/Elevation/ElevationElement';
import { OverlayElement } from '../Abstracts/OverlayElement';
import { drawerElementTemplate } from './DrawerElementTemplate';
import { DRAWER_REGISTRY } from './DrawerService';
import { drawerElementJoyStyle } from './Themes/DrawerElement.Joy';
import { drawerElementMemphisStyle } from './Themes/DrawerElement.Memphis';
import { drawerElementCosmopolitanStyle } from './Themes/DrawerElement.Cosmopolitan';
import { DrawerContainerElement } from './DrawerContainerElement';
import { Themeable } from '../../../Behaviors/Themeable';
// #endregion
/**
 * Drawer - A hidden side view or container that can be opened from the side or bottom to display additional content.
 *
 * @element mosaik-drawer
 *
 * @slot - The default content element.
 * @slot end - The header end content element.
 *
 * @csspart root - The root container element.
 * @csspart elevation - The elevation element.
 * @csspart header - The header container element.
 * @csspart - The default content container element.
 * @csspart footer - The footer element.
 * @csspart backdrop - The backdrop element.
 *
 * @fires closed - Dispatched when the drawer is closed.
 * @fires opened - Dispatched when the drawer is opened.
 *
 * @public
 */
let DrawerElement = class DrawerElement extends Themeable(Animatable(Dimensionable(Elevatable(OverlayElement)))) {
    // #region Fields
    _isComposed;
    _header;
    _subHeader;
    _position;
    _mode;
    _hasShadow;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._isComposed = false;
        this._header = '';
        this._subHeader = '';
        // this._height = '100%';
        // this._width = '320px';
        this._position = DrawerPosition.Left;
        this._mode = DrawerMode.Over;
        this._hasShadow = false;
        // REMARK: This is a workaround for the issue with the docs generation.
        Object.assign(this, { elevation: ElevationWeight.Regular });
        Object.assign(this, { enter: fadeIn });
        Object.assign(this, { exit: fadeOut });
        new RegistryController(this, {
            registry: DRAWER_REGISTRY
        });
    }
    // #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-drawer';
    }
    /**
     * Gets or sets the `header` property.
     *
     * @public
     * @attr
     */
    get header() {
        return this._header;
    }
    set header(value) {
        if (this._header !== value) {
            this._header = value;
            this.requestUpdate('header');
        }
    }
    /**
     * Gets or sets the `subHeader` property.
     *
     * @public
     * @attr
     */
    get subHeader() {
        return this._subHeader;
    }
    set subHeader(value) {
        if (this._subHeader !== value) {
            this._subHeader = value;
            this.requestUpdate('subHeader');
        }
    }
    /**
     * Gets or sets the `position` property.
     *
     * @public
     * @attr
     */
    get position() {
        return this._position;
    }
    set position(value) {
        if (this._position !== value) {
            this._position = value;
            this.requestUpdate('position');
        }
    }
    /**
     * Gets or sets the `mode` property.
     *
     * @public
     * @attr
     */
    get mode() {
        return this._mode;
    }
    set mode(value) {
        if (this._mode !== value) {
            this._mode = value;
            this.requestUpdate('mode');
        }
    }
    /**
     * Gets or sets the `isComposed` property.
     *
     * @public
     * @readonly
     * @attr
     */
    get isComposed() {
        return this._isComposed;
    }
    set isComposed(value) {
        if (this._isComposed !== value) {
            this._isComposed = value;
            this.requestUpdate('isComposed');
        }
    }
    /**
     * Gets or sets the `hasShadow` property.
     *
     * @public
     * @attr
     */
    get hasShadow() {
        return this._hasShadow;
    }
    set hasShadow(value) {
        if (this._hasShadow !== value) {
            this._hasShadow = value;
            this.requestUpdate('hasShadow');
        }
    }
    // #endregion
    // #region Methods
    /**
     * Opens the drawer.
     *
     * @public
     * @override
     */
    async open() {
        return super.open().then(() => {
            void this.play(this.enter ?? { steps: [] });
        });
    }
    /**
     * Closes the drawer.
     *
     * @public
     * @override
     */
    async close() {
        return this.play(this.exit ?? { steps: [] }).then(() => super.close());
    }
    /**
     * Toggles the drawer between open and closed states.
     *
     * @public
     */
    async toggle() {
        if (this.isOpen) {
            return this.close().then(() => { });
        }
        return this.open();
    }
    /**
     * Returns the inner offset width of the drawer.
     *
     * @public
     */
    innerOffsetWidth() {
        return this.getTemplatePart('root').offsetWidth;
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        if (DomServiceLocator.current.findAncestor(this, DrawerContainerElement)) {
            this.isComposed = true;
        }
    }
};
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DrawerElement.prototype, "header", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DrawerElement.prototype, "subHeader", null);
__decorate([
    Attribute({ type: DrawerPosition }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DrawerElement.prototype, "position", null);
__decorate([
    Attribute({ type: DrawerMode }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DrawerElement.prototype, "mode", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DrawerElement.prototype, "isComposed", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DrawerElement.prototype, "hasShadow", null);
DrawerElement = __decorate([
    Component({
        selector: 'mosaik-drawer',
        template: drawerElementTemplate,
        themes: {
            joy: drawerElementJoyStyle,
            memphis: drawerElementMemphisStyle,
            cosmopolitan: drawerElementCosmopolitanStyle
        },
        imports: [
            ToolbarElement,
            ButtonElement,
            BackdropElement,
            ElevationElement
        ]
    }),
    __metadata("design:paramtypes", [])
], DrawerElement);
export { DrawerElement };
//# sourceMappingURL=DrawerElement.js.map