/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { __decorate } from "tslib";
import { coerceBoolean, CustomElement, ensureChildren, toggleClass } from '@tylertech/forge-core';
import { BaseComponent } from '../core/base/base-component';
import { ForgeRipple } from '../ripple';
import { FLOATING_ACTION_BUTTON_CONSTANTS } from './floating-action-button-constants';
/**
 * The custom element class behind the `<forge-fab>` element.
 *
 * @tag forge-fab
 */
let FloatingActionButton = class FloatingActionButton extends BaseComponent {
    constructor() {
        super();
        this._isExtended = false;
        this._isMini = false;
        this._isExited = false;
    }
    static get observedAttributes() {
        return [
            FLOATING_ACTION_BUTTON_CONSTANTS.attributes.EXITED,
            FLOATING_ACTION_BUTTON_CONSTANTS.attributes.MINI,
            FLOATING_ACTION_BUTTON_CONSTANTS.attributes.EXTENDED
        ];
    }
    connectedCallback() {
        if (this.children.length) {
            this._initialize();
        }
        else {
            ensureChildren(this).then(() => this._initialize());
        }
    }
    disconnectedCallback() {
        if (this._rippleInstance) {
            this._rippleInstance.destroy();
        }
    }
    attributeChangedCallback(name, oldValue, newValue) {
        switch (name) {
            case FLOATING_ACTION_BUTTON_CONSTANTS.attributes.EXITED:
                this.exited = coerceBoolean(newValue);
                break;
            case FLOATING_ACTION_BUTTON_CONSTANTS.attributes.MINI:
                this.mini = coerceBoolean(newValue);
                break;
            case FLOATING_ACTION_BUTTON_CONSTANTS.attributes.EXTENDED:
                this.extended = coerceBoolean(newValue);
                break;
        }
    }
    _initialize() {
        // Make sure we have a button element
        this._buttonElement = this.querySelector(FLOATING_ACTION_BUTTON_CONSTANTS.selectors.BUTTON);
        if (!this._buttonElement) {
            return;
        }
        this._buttonElement.classList.add(FLOATING_ACTION_BUTTON_CONSTANTS.classes.BUTTON);
        const rippleElement = this._buttonElement.querySelector(`.${FLOATING_ACTION_BUTTON_CONSTANTS.classes.RIPPLE}`) || document.createElement('div');
        rippleElement.classList.add(FLOATING_ACTION_BUTTON_CONSTANTS.classes.RIPPLE);
        this._buttonElement.insertAdjacentElement('afterbegin', rippleElement);
        this._sync();
        if (this._rippleInstance) {
            this._rippleInstance.destroy();
        }
        this._rippleInstance = new ForgeRipple(this._buttonElement);
    }
    _sync() {
        if (!this._buttonElement) {
            return;
        }
        toggleClass(this._buttonElement, this._isExited, FLOATING_ACTION_BUTTON_CONSTANTS.classes.EXITED);
        toggleClass(this._buttonElement, this._isMini, FLOATING_ACTION_BUTTON_CONSTANTS.classes.BUTTON_MINI);
        toggleClass(this._buttonElement, this._isExtended, FLOATING_ACTION_BUTTON_CONSTANTS.classes.BUTTON_EXTENDED);
        // Check if we need to set the label class
        const labelElement = this.querySelector(FLOATING_ACTION_BUTTON_CONSTANTS.selectors.LABEL);
        if (labelElement) {
            labelElement.classList.add(FLOATING_ACTION_BUTTON_CONSTANTS.classes.LABEL);
        }
        // Check if we need to set the icon class
        const iconElement = this.querySelector(FLOATING_ACTION_BUTTON_CONSTANTS.selectors.ICON);
        if (iconElement) {
            iconElement.classList.add(FLOATING_ACTION_BUTTON_CONSTANTS.classes.ICON);
            iconElement.setAttribute('aria-hidden', 'true');
        }
    }
    /** Gets/sets the exited state. */
    set exited(value) {
        if (this._isExited !== value) {
            this._isExited = value;
            this.setAttribute(FLOATING_ACTION_BUTTON_CONSTANTS.attributes.EXITED, this._isExited.toString());
            this._sync();
        }
    }
    get exited() {
        return this._isExited;
    }
    /** Gets/sets the mini state. */
    set mini(value) {
        if (this._isMini !== value) {
            this._isMini = value;
            this.setAttribute(FLOATING_ACTION_BUTTON_CONSTANTS.attributes.MINI, this._isMini.toString());
            this._sync();
        }
    }
    get mini() {
        return this._isMini;
    }
    /** Gets/sets the extended state. */
    set extended(value) {
        if (this._isExtended !== value) {
            this._isExtended = value;
            this.setAttribute(FLOATING_ACTION_BUTTON_CONSTANTS.attributes.EXTENDED, this._isExtended.toString());
            this._sync();
        }
    }
    get extended() {
        return this._isExtended;
    }
};
FloatingActionButton = __decorate([
    CustomElement({
        name: FLOATING_ACTION_BUTTON_CONSTANTS.elementName
    })
], FloatingActionButton);
export { FloatingActionButton };
