/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { addClass } from '@tylertech/forge-core';
import { ICON_CLASS_NAME } from '../constants';
import { BaseComponentDelegate } from '../core/delegates/base-component-delegate';
import { ICON_CONSTANTS } from '../icon/icon-constants';
import { FLOATING_ACTION_BUTTON_CONSTANTS } from './floating-action-button-constants';
export class FloatingActionButtonComponentDelegate extends BaseComponentDelegate {
    constructor(config) {
        super(config);
    }
    _build() {
        var _a, _b, _c, _d, _e;
        const component = document.createElement(FLOATING_ACTION_BUTTON_CONSTANTS.elementName);
        if ((_a = this._config.options) === null || _a === void 0 ? void 0 : _a.theme) {
            component.theme = this._config.options.theme;
        }
        if ((_b = this._config.options) === null || _b === void 0 ? void 0 : _b.density) {
            component.density = this._config.options.density;
        }
        if ((_c = this._config.options) === null || _c === void 0 ? void 0 : _c.elevation) {
            component.elevation = this._config.options.elevation;
        }
        if ((_e = (_d = this._config.options) === null || _d === void 0 ? void 0 : _d.label) === null || _e === void 0 ? void 0 : _e.trim().length) {
            const span = document.createElement('span');
            span.slot = 'label';
            component.textContent = this._config.options.label;
            component.appendChild(span);
        }
        return component;
    }
    _configure() {
        this._configureIcon();
    }
    _configureIcon() {
        var _a, _b;
        if (!((_a = this._config.options) === null || _a === void 0 ? void 0 : _a.iconName)) {
            return;
        }
        const type = ((_b = this._config.options) === null || _b === void 0 ? void 0 : _b.iconType) || 'component';
        switch (type) {
            case 'font':
                const classes = Array.isArray(this._config.options.iconClass) ? this._config.options.iconClass : [ICON_CLASS_NAME];
                addClass(classes, this._element);
                this._element.textContent = this._config.options.iconName;
                break;
            case 'component':
                this._iconElement = document.createElement(ICON_CONSTANTS.elementName);
                this._iconElement.name = this._config.options.iconName;
                if (this._config.options.iconExternal !== undefined) {
                    this._iconElement.external = !!this._config.options.iconExternal;
                }
                if (this._config.options.iconExternalType) {
                    this._iconElement.externalType = this._config.options.iconExternalType;
                }
                if (this._config.options.iconClass) {
                    addClass(this._config.options.iconClass, this._iconElement);
                }
                this._element.appendChild(this._iconElement);
                break;
        }
    }
    get iconElement() {
        return this._iconElement;
    }
    get disabled() {
        return !!this._element.disabled;
    }
    set disabled(value) {
        this._element.disabled = value;
    }
    onClick(listener) {
        this._element.addEventListener('click', listener);
    }
    onFocus(listener) {
        this._element.addEventListener('focus', evt => listener(evt));
    }
    onBlur(listener) {
        this._element.addEventListener('blur', evt => listener(evt));
    }
}
