// #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 { Appearanceable } from '../../../Behaviors/Appearanceable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Variantable } from '../../../Behaviors/Variantable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { InkBarPosition } from '../../../Types/InkBarPosition';
import { CustomElement } from '../../Abstracts/CustomElement';
import { inkBarElementTemplate } from './InkBarElementTemplate';
import { inkBarElementJoyStyle } from './Themes/InkBarElement.Joy';
import { inkBarElementMemphisStyle } from './Themes/InkBarElement.Memphis';
import { inkBarElementCosmopolitanStyle } from './Themes/InkBarElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
// #endregion
/**
 * The `{@link InkBarElement}` element.
 *
 * @public
 */
let InkBarElement = class InkBarElement extends Themeable(Variantable(Appearanceable(Disableable(CustomElement)))) {
    // #region Fields
    _position;
    _target;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._position = InkBarPosition.Bottom;
        this._target = null;
    }
    // #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-ink-bar';
    }
    /**
     * Gets or sets the `target` property.
     *
     * @public
     */
    get target() {
        return this._target;
    }
    set target(value) {
        if (this._target !== value) {
            this._target = value;
            this.requestUpdate('target');
        }
    }
    /**
     * 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');
        }
    }
    // #endregion
    // #region Methods
    /**
     * Aligns the ink bar to the target element.
     *
     * @public
     */
    align() {
        this.alignToElement();
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        this.alignToElement();
    }
    /**
     * @protected
     */
    onPositionPropertyChanged() {
        this.alignToElement();
    }
    /**
     * @protected
     */
    onTargetPropertyChanged() {
        this.alignToElement();
    }
    /**
     * @private
     */
    alignToElement() {
        const target = this._target;
        if (target) {
            requestAnimationFrame(() => {
                if (this._position === InkBarPosition.Bottom || this._position === InkBarPosition.Top) {
                    this.style.top = '';
                    this.style.height = '';
                    this.style.left = `${target.offsetLeft}px`;
                    this.style.width = `${target.offsetWidth}px`;
                }
                else {
                    this.style.left = '';
                    this.style.width = '';
                    this.style.top = `${target.offsetTop}px`;
                    this.style.height = `${target.offsetHeight}px`;
                }
            });
        }
        else {
            this.style.top = '';
            this.style.left = '';
            this.style.width = '';
            this.style.height = '';
        }
    }
};
__decorate([
    Property({ type: Object }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], InkBarElement.prototype, "target", null);
__decorate([
    Attribute({ type: InkBarPosition }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], InkBarElement.prototype, "position", null);
__decorate([
    Watch('position', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], InkBarElement.prototype, "onPositionPropertyChanged", null);
__decorate([
    Watch('target'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], InkBarElement.prototype, "onTargetPropertyChanged", null);
InkBarElement = __decorate([
    Component({
        selector: 'mosaik-ink-bar',
        template: inkBarElementTemplate,
        themes: {
            joy: inkBarElementJoyStyle,
            memphis: inkBarElementMemphisStyle,
            cosmopolitan: inkBarElementCosmopolitanStyle
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], InkBarElement);
export { InkBarElement };
//# sourceMappingURL=InkBarElement.js.map