/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { FormFieldComponentDelegate } from '../core';
import { SWITCH_CONSTANTS } from './switch-constants';
export class SwitchComponentDelegate extends FormFieldComponentDelegate {
    constructor(config) {
        super(config);
    }
    get value() {
        return this._element.selected;
    }
    set value(value) {
        this._element.selected = value;
    }
    get disabled() {
        return this._element.disabled;
    }
    set disabled(value) {
        this._element.disabled = value;
    }
    get labelElement() {
        return this._labelElement;
    }
    onChange(listener) {
        this._element.addEventListener('forge-switch-select', ({ detail }) => listener(detail));
    }
    onFocus(listener) {
        this._element.addEventListener('focus', evt => listener(evt));
    }
    onBlur(listener) {
        this._element.addEventListener('blur', evt => listener(evt));
    }
    setLabel(text) {
        if (text) {
            if (this._labelElement) {
                this._labelElement.textContent = text;
            }
            else {
                this._createLabel(text);
            }
        }
        else if (this._labelElement) {
            this._element.removeChild(this._labelElement);
            this._labelElement = undefined;
        }
    }
    _build() {
        return document.createElement(SWITCH_CONSTANTS.elementName);
    }
    _configure() {
        var _a, _b, _c;
        if (typeof ((_a = this._config.options) === null || _a === void 0 ? void 0 : _a.label) === 'string') {
            this._createLabel(this._config.options.label);
        }
        if (((_b = this._config.options) === null || _b === void 0 ? void 0 : _b.selected) !== undefined) {
            this._element.selected = this._config.options.selected;
        }
        if ((_c = this._config.options) === null || _c === void 0 ? void 0 : _c.id) {
            this._element.id = this._config.options.id;
        }
    }
    _createLabel(text) {
        this._labelElement = document.createElement('label');
        this._labelElement.textContent = text;
        this._element.appendChild(this._labelElement);
    }
}
