/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { coerceBoolean } from '@tylertech/forge-core';
import { FIELD_CONSTANTS } from '../field-constants';
import { BASE_FIELD_CONSTANTS } from './base-field-constants';
/**
 * Provides a consistent passthrough API to the underlying field component, for
 * field-like wrapper components.
 *
 * @param base The base component to mix into.
 * @returns The mixed-in base component.
 */
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function WithBaseField(base) {
    class BaseFieldComponent extends base {
        constructor(...args) {
            super(...args);
        }
        /**
         * @internal
         */
        initializeFieldInstance(fieldElement) {
            this._fieldElement = fieldElement;
            // Ensure the field element is upgraded if it hasn't been already.
            // This is necessary for imperative creation of elements before they
            // are connected to the DOM.
            if (!this._fieldElement.shadowRoot) {
                window.customElements.upgrade(this._fieldElement);
            }
        }
        attributeChangedCallback(name, oldValue, newValue) {
            var _a;
            switch (name) {
                case BASE_FIELD_CONSTANTS.observedAttributes.LABEL_POSITION:
                    this.labelPosition = newValue;
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.LABEL_ALIGNMENT:
                    this.labelAlignment = newValue;
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.INVALID:
                    this.invalid = coerceBoolean(newValue);
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.REQUIRED:
                    this.required = coerceBoolean(newValue);
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.OPTIONAL:
                    this.optional = coerceBoolean(newValue);
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.DISABLED:
                    this.disabled = coerceBoolean(newValue);
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.FLOAT_LABEL:
                    this.floatLabel = coerceBoolean(newValue);
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.VARIANT:
                    this.variant = newValue;
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.THEME:
                    this.theme = newValue;
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.SHAPE:
                    this.shape = newValue;
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.DENSITY:
                    this.density = newValue;
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.DENSE:
                    this.dense = coerceBoolean(newValue);
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.POPOVER_ICON:
                    this.popoverIcon = coerceBoolean(newValue);
                    return;
                case BASE_FIELD_CONSTANTS.observedAttributes.SUPPORT_TEXT_INSET:
                    this.supportTextInset = newValue;
                    return;
            }
            (_a = super.attributeChangedCallback) === null || _a === void 0 ? void 0 : _a.call(this, name, oldValue, newValue);
        }
        get labelPosition() {
            return this._fieldElement.labelPosition;
        }
        set labelPosition(value) {
            if (this._fieldElement.labelPosition !== value) {
                this._fieldElement.labelPosition = value;
                this.setAttribute(FIELD_CONSTANTS.attributes.LABEL_POSITION, value);
            }
        }
        get labelAlignment() {
            return this._fieldElement.labelAlignment;
        }
        set labelAlignment(value) {
            if (this._fieldElement.labelAlignment !== value) {
                this._fieldElement.labelAlignment = value;
                this.setAttribute(FIELD_CONSTANTS.attributes.LABEL_ALIGNMENT, value);
            }
        }
        get invalid() {
            return this._fieldElement.invalid;
        }
        set invalid(value) {
            if (this._fieldElement.invalid !== value) {
                this._fieldElement.invalid = value;
                this.toggleAttribute(FIELD_CONSTANTS.attributes.INVALID, value);
            }
        }
        get required() {
            return this._fieldElement.required;
        }
        set required(value) {
            if (this._fieldElement.required !== value) {
                this._fieldElement.required = value;
                this.toggleAttribute(FIELD_CONSTANTS.attributes.REQUIRED, value);
            }
        }
        get optional() {
            return this._fieldElement.optional;
        }
        set optional(value) {
            if (this._fieldElement.optional !== value) {
                this._fieldElement.optional = value;
                this.toggleAttribute(FIELD_CONSTANTS.attributes.OPTIONAL, value);
            }
        }
        get disabled() {
            return this._fieldElement.disabled;
        }
        set disabled(value) {
            if (this._fieldElement.disabled !== value) {
                this._fieldElement.disabled = value;
                this.toggleAttribute(FIELD_CONSTANTS.attributes.DISABLED, value);
            }
        }
        get floatLabel() {
            return this._fieldElement.floatLabel;
        }
        set floatLabel(value) {
            if (this._fieldElement.floatLabel !== value) {
                this._fieldElement.floatLabel = value;
                this.toggleAttribute(FIELD_CONSTANTS.attributes.FLOAT_LABEL, value);
            }
        }
        get variant() {
            return this._fieldElement.variant;
        }
        set variant(value) {
            if (this._fieldElement.variant !== value) {
                this._fieldElement.variant = value;
                this.setAttribute(FIELD_CONSTANTS.attributes.VARIANT, value);
            }
        }
        get theme() {
            return this._fieldElement.theme;
        }
        set theme(value) {
            if (this._fieldElement.theme !== value) {
                this._fieldElement.theme = value;
                this.setAttribute(FIELD_CONSTANTS.attributes.THEME, value);
            }
        }
        get shape() {
            return this._fieldElement.shape;
        }
        set shape(value) {
            if (this._fieldElement.shape !== value) {
                this._fieldElement.shape = value;
                this.setAttribute(FIELD_CONSTANTS.attributes.SHAPE, value);
            }
        }
        get density() {
            return this._fieldElement.density;
        }
        set density(value) {
            if (this._fieldElement.density !== value) {
                this._fieldElement.density = value;
                this.setAttribute(FIELD_CONSTANTS.attributes.DENSITY, value);
            }
        }
        get dense() {
            return this._fieldElement.dense;
        }
        set dense(value) {
            if (this._fieldElement.dense !== value) {
                this._fieldElement.dense = value;
                this.toggleAttribute(FIELD_CONSTANTS.attributes.DENSE, value);
            }
        }
        get popoverIcon() {
            return this._fieldElement.popoverIcon;
        }
        set popoverIcon(value) {
            if (this._fieldElement.popoverIcon !== value) {
                this._fieldElement.popoverIcon = value;
                this.toggleAttribute(FIELD_CONSTANTS.attributes.POPOVER_ICON, value);
            }
        }
        get supportTextInset() {
            return this._fieldElement.supportTextInset;
        }
        set supportTextInset(value) {
            if (this._fieldElement.supportTextInset !== value) {
                this._fieldElement.supportTextInset = value;
                this.setAttribute(FIELD_CONSTANTS.attributes.SUPPORT_TEXT_INSET, value);
            }
        }
        floatLabelWithoutAnimation(value) {
            this._fieldElement.floatLabelWithoutAnimation(value);
        }
    }
    return BaseFieldComponent;
}
