// #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 { 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 { Slottable } from '../../../Behaviors/Slottable';
import { Themeable } from '../../../Behaviors/Themeable';
import { addFocusTrapController } from '../../../Controllers/FocusTrapController';
import { addInheritanceProviderController } from '../../../Controllers/InheritanceProviderController';
import { RegistryController } from '../../../Controllers/RegistryController';
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 { BackdropElement } from '../../Primitives/Backdrop/BackdropElement';
import { DismissElement } from '../../Primitives/Dismiss/DismissElement';
import { ElevationElement } from '../../Primitives/Elevation/ElevationElement';
import { TextElement } from '../../Primitives/Text/TextElement';
import { OverlayElement } from '../Abstracts/OverlayElement';
import { DrawerContainerElement } from './DrawerContainerElement';
import { drawerElementTemplate } from './DrawerElementTemplate';
import { DrawerFooterElement } from './DrawerFooterElement';
import { DrawerHeaderElement } from './DrawerHeaderElement';
import { DrawerHeaderSubTextElement } from './DrawerHeaderSubTextElement';
import { DrawerHeaderTextElement } from './DrawerHeaderTextElement';
import { DRAWER_INHERITANCE_CONTEXT } from './DrawerInheritanceContext';
import { DRAWER_REGISTRY } from './DrawerService';
import { drawerElementCosmopolitanStyle } from './Themes/DrawerElement.Cosmopolitan';
import { drawerElementJoyStyle } from './Themes/DrawerElement.Joy';
import { drawerElementMemphisStyle } from './Themes/DrawerElement.Memphis';
// #endregion
/**
 * Drawer - A hidden side panel that slides in from the edge of the viewport.
 *
 * @description
 * A side-navigation or off-canvas panel that supports `over` and `side` modes,
 * multiple positions (left/right/top/bottom), fullscreen mode, and optional shadow.
 *
 * @name Drawer
 * @element mosaik-drawer
 * @category Overlays
 *
 * @slot - The default content slot.
 * @slot actions - The actions content slot.
 * @slot footer - The footer content slot.
 * @slot header - The header content slot.
 *
 * @csspart actions - The actions part.
 * @csspart backdrop - The backdrop element.
 * @csspart elevation - The elevation element.
 * @csspart footer - The footer element.
 * @csspart header - The header container element.
 * @csspart main - The main part.
 * @csspart root - The root container element.
 *
 * @cssprop {String} --drawer-background-color - The background color CSS custom property.
 * @cssprop {String} --drawer-border-color - The border color CSS custom property.
 * @cssprop {String} --drawer-border-radius - The border radius CSS custom property.
 * @cssprop {String} --drawer-border-style - The border style CSS custom property.
 * @cssprop {String} --drawer-border-width - The border width CSS custom property.
 * @cssprop {String} --drawer-divider-height - The divider height CSS custom property.
 * @cssprop {String} --drawer-font-family - The font family CSS custom property.
 * @cssprop {String} --drawer-font-letter-spacing - The font letter spacing CSS custom property.
 * @cssprop {String} --drawer-font-line-height - The font line height CSS custom property.
 * @cssprop {String} --drawer-font-size - The font size CSS custom property.
 * @cssprop {String} --drawer-font-text-decoration - The font text decoration CSS custom property.
 * @cssprop {String} --drawer-font-text-transform - The font text transform CSS custom property.
 * @cssprop {String} --drawer-font-weight - The font weight CSS custom property.
 * @cssprop {String} --drawer-foreground-color - The foreground color CSS custom property.
 * @cssprop {String} --drawer-gap - The gap CSS custom property.
 * @cssprop {String} --drawer-height - The height CSS custom property.
 * @cssprop {String} --drawer-line-thickness - The line thickness CSS custom property.
 * @cssprop {String} --drawer-padding-bottom - The padding bottom CSS custom property.
 * @cssprop {String} --drawer-padding-left - The padding left CSS custom property.
 * @cssprop {String} --drawer-padding-right - The padding right CSS custom property.
 * @cssprop {String} --drawer-padding-top - The padding top CSS custom property.
 * @cssprop {String} --drawer-shadow - The shadow CSS custom property.
 * @cssprop {String} --drawer-shadow-blur - The shadow blur CSS custom property.
 * @cssprop {String} --drawer-shadow-color - The shadow color CSS custom property.
 * @cssprop {String} --drawer-shadow-offset-x - The shadow offset x CSS custom property.
 * @cssprop {String} --drawer-shadow-offset-y - The shadow offset y CSS custom property.
 * @cssprop {String} --drawer-shadow-spread - The shadow spread CSS custom property.
 * @cssprop {String} --drawer-transition-duration - The transition duration CSS custom property.
 * @cssprop {String} --drawer-transition-mode - The transition mode CSS custom property.
 * @cssprop {String} --drawer-transition-property - The transition property CSS custom property.
 * @cssprop {String} --drawer-translate - The translate CSS custom property.
 * @cssprop {String} --drawer-width - The width CSS custom property.
 *
 * @fires closed {ClosedEvent} - Dispatched when the drawer is closed.
 * @fires opened {OpenedEvent} - Dispatched when the drawer is opened.
 *
 * @dependency mosaik-backdrop - The Backdrop element.
 * @dependency mosaik-dismiss - The Dismiss element.
 * @dependency mosaik-drawer-header - The Drawer Header element.
 * @dependency mosaik-drawer-header-sub-text - The Drawer Header Sub Text element.
 * @dependency mosaik-drawer-header-text - The Drawer Header Text element.
 * @dependency mosaik-elevation - The Elevation element.
 *
 * @example
 * Basic left drawer in over mode:
 * ```html
 * <mosaik-drawer position="left" mode="over" header="Navigation"></mosaik-drawer>
 * ```
 *
 * @example
 * Persistent side drawer with shadow:
 * ```html
 * <mosaik-drawer position="left" mode="side" has-shadow></mosaik-drawer>
 * ```
 *
 * @example
 * Fullscreen drawer from the right:
 * ```html
 * <mosaik-drawer position="right" mode="over" is-full-screen></mosaik-drawer>
 * ```
 *
 * @public
 */
let DrawerElement = class DrawerElement extends Themeable(Animatable(Dimensionable(Elevatable(Slottable(OverlayElement))))) {
    // #region Fields
    _provider = addInheritanceProviderController(this, {
        context: DRAWER_INHERITANCE_CONTEXT,
        values: () => ({
            header: this.header,
            subHeader: this.subHeader,
            closeable: this.closeable
        })
    });
    _isComposed;
    _header;
    _subHeader;
    _position;
    _mode;
    _hasShadow;
    _isFullScreen;
    // #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;
        this._isFullScreen = 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
        });
        addFocusTrapController(this);
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `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 `isFullScreen` property.
     *
     * @public
     * @attr
     */
    get isFullScreen() {
        return this._isFullScreen;
    }
    set isFullScreen(value) {
        if (this._isFullScreen !== value) {
            this._isFullScreen = value;
            this.requestUpdate('isFullScreen');
        }
    }
    /**
     * 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');
        }
    }
    /**
     * Gets the animation target element.
     * For the drawer, animations are applied to the root template part instead of the host element.
     *
     * @public
     * @override
     * @readonly
     */
    get animationTarget() {
        return this.getTemplatePart('root');
    }
    // #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;
    }
    /**
     * Handles the backdrop click event.
     * Only closes the drawer if `clickOutsideToClose` is enabled.
     *
     * @private
     * @template
     */
    onBackdrop() {
        if (this.clickOutsideToClose) {
            void this.close();
        }
    }
    /**
     * @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: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], DrawerElement.prototype, "isFullScreen", 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: [
            ButtonElement,
            TextElement,
            BackdropElement,
            DismissElement,
            ElevationElement,
            DrawerHeaderElement,
            DrawerHeaderTextElement,
            DrawerHeaderSubTextElement,
            DrawerFooterElement
        ]
    }),
    __metadata("design:paramtypes", [])
], DrawerElement);
export { DrawerElement };
//# sourceMappingURL=DrawerElement.js.map