/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { ICON_CLASS_NAME } from '../../constants';
import { BaseComponentDelegate } from '../../core/delegates/base-component-delegate';
import { ICON_CONSTANTS } from '../../icon/icon-constants';
import { DEPRECATED_ICON_BUTTON_CONSTANTS } from './deprecated-icon-button-constants';
export class DeprecatedIconButtonComponentDelegate extends BaseComponentDelegate {
    constructor(config) {
        super(config);
    }
    destroy() {
        this._buttonElement = undefined;
    }
    get buttonElement() {
        return this._buttonElement;
    }
    _build() {
        var _a;
        const component = document.createElement(DEPRECATED_ICON_BUTTON_CONSTANTS.elementName);
        this._buttonElement = document.createElement('button');
        this._buttonElement.type = 'button';
        component.appendChild(this._buttonElement);
        if ((_a = this._config.options) === null || _a === void 0 ? void 0 : _a.tooltip) {
            const tooltip = document.createElement('forge-tooltip');
            tooltip.textContent = this._config.options.tooltip;
            if (this._config.options.tooltipPosition) {
                tooltip.position = this._config.options.tooltipPosition;
            }
            component.appendChild(tooltip);
        }
        return component;
    }
    onClick(listener) {
        var _a;
        (_a = this._buttonElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', listener);
    }
    onFocus(listener) {
        var _a;
        (_a = this._buttonElement) === null || _a === void 0 ? void 0 : _a.addEventListener('focus', listener);
    }
    onBlur(listener) {
        var _a;
        (_a = this._buttonElement) === null || _a === void 0 ? void 0 : _a.addEventListener('blur', listener);
    }
    get iconElement() {
        return this._iconElement;
    }
    get disabled() {
        var _a;
        return !!((_a = this._buttonElement) === null || _a === void 0 ? void 0 : _a.disabled);
    }
    set disabled(value) {
        if (this._buttonElement) {
            this._buttonElement.disabled = value;
        }
    }
    _configure() {
        this._configureIcon();
    }
    _configureIcon() {
        var _a, _b, _c, _d;
        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];
                (_c = this._buttonElement) === null || _c === void 0 ? void 0 : _c.classList.add(...classes);
                if (this._buttonElement) {
                    this._buttonElement.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) {
                    this._iconElement.classList.add(...this._config.options.iconClass);
                }
                (_d = this._buttonElement) === null || _d === void 0 ? void 0 : _d.appendChild(this._iconElement);
                break;
        }
    }
}
