/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { FormFieldComponentDelegate } from '../core/delegates/form-field-component-delegate';
import { SELECT_CONSTANTS } from './select/select-constants';
export class SelectComponentDelegate extends FormFieldComponentDelegate {
    constructor(config) {
        super(config);
    }
    _build() {
        return document.createElement(SELECT_CONSTANTS.elementName);
    }
    _configure() {
        var _a;
        if (typeof ((_a = this._config.options) === null || _a === void 0 ? void 0 : _a.helperText) === 'string') {
            this.setHelperText(this._config.options.helperText);
        }
    }
    get value() {
        return this._element.value;
    }
    set value(value) {
        this._element.value = value;
    }
    get disabled() {
        return this._element.disabled;
    }
    set disabled(value) {
        this._element.disabled = value;
    }
    get invalid() {
        return this._element.invalid || false;
    }
    set invalid(value) {
        this._element.invalid = value;
    }
    onChange(listener) {
        this._element.addEventListener('change', (evt) => listener(evt.detail));
    }
    onFocus(listener) {
        this._element.addEventListener('focus', evt => listener(evt));
    }
    onBlur(listener) {
        this._element.addEventListener('blur', evt => listener(evt));
    }
    setHelperText(text) {
        if (text) {
            if (!this._helperTextElement) {
                this._helperTextElement = document.createElement('span');
                this._helperTextElement.slot = 'helper-text';
                this._element.appendChild(this._helperTextElement);
            }
            this._helperTextElement.textContent = text;
        }
        else if (this._helperTextElement && this._helperTextElement.isConnected) {
            this._element.removeChild(this._helperTextElement);
            this._helperTextElement = undefined;
        }
    }
}
