/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { FIELD_CONSTANTS } from './field-constants';
export class FieldCore {
    constructor(_adapter) {
        this._adapter = _adapter;
        this._labelPosition = FIELD_CONSTANTS.defaults.DEFAULT_LABEL_POSITION;
        this._labelAlignment = FIELD_CONSTANTS.defaults.DEFAULT_LABEL_ALIGNMENT;
        this._floatLabel = false;
        this._invalid = false;
        this._required = false;
        this._optional = false;
        this._disabled = false;
        this._variant = FIELD_CONSTANTS.defaults.DEFAULT_VARIANT;
        this._theme = FIELD_CONSTANTS.defaults.DEFAULT_THEME;
        this._shape = FIELD_CONSTANTS.defaults.DEFAULT_SHAPE;
        this._density = FIELD_CONSTANTS.defaults.DEFAULT_DENSITY;
        this._dense = false;
        this._popoverIcon = false;
        this._popoverExpanded = false;
        this._multiline = false;
        this._supportTextInset = FIELD_CONSTANTS.defaults.DEFAULT_SUPPORT_TEXT_INSET;
        this._slotChangeListener = this._onSlotChange.bind(this);
        this._popoverIconClickListener = this._onPopoverIconClick.bind(this);
    }
    initialize() {
        this._adapter.addRootListener('slotchange', this._slotChangeListener);
        this._adapter.tryApplyGlobalConfiguration(['labelPosition']);
        this._adapter.setLabelPosition(this._labelPosition);
        if (this._popoverIcon) {
            this._adapter.addPopoverIconClickListener(this._popoverIconClickListener);
        }
    }
    _onSlotChange(evt) {
        this._adapter.handleSlotChange(evt.target);
    }
    _onPopoverIconClick() {
        this._adapter.dispatchHostEvent(new CustomEvent(FIELD_CONSTANTS.events.POPOVER_ICON_CLICK, { bubbles: true }));
    }
    floatLabelWithoutAnimation(value) {
        if (this._floatLabel !== value) {
            this._floatLabel = value;
            this._adapter.setFloatingLabel(this._floatLabel, true);
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.FLOAT_LABEL, this._floatLabel);
        }
    }
    get labelPosition() {
        return this._labelPosition;
    }
    set labelPosition(value) {
        if (this._labelPosition !== value) {
            this._labelPosition = value;
            this._adapter.setHostAttribute(FIELD_CONSTANTS.attributes.LABEL_POSITION, this._labelPosition);
            if (!this._adapter.isConnected) {
                return;
            }
            this._adapter.setLabelPosition(this._labelPosition);
        }
    }
    get labelAlignment() {
        return this._labelAlignment;
    }
    set labelAlignment(value) {
        if (this._labelAlignment !== value) {
            this._labelAlignment = value;
            this._adapter.setHostAttribute(FIELD_CONSTANTS.attributes.LABEL_ALIGNMENT, this._labelAlignment);
        }
    }
    get floatLabel() {
        return this._floatLabel;
    }
    set floatLabel(value) {
        if (this._floatLabel !== value) {
            this._floatLabel = value;
            this._adapter.setFloatingLabel(this._floatLabel);
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.FLOAT_LABEL, this._floatLabel);
        }
    }
    get invalid() {
        return this._invalid;
    }
    set invalid(value) {
        if (this._invalid !== value) {
            this._invalid = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.INVALID, this._invalid);
        }
    }
    get required() {
        return this._required;
    }
    set required(value) {
        if (this._required !== value) {
            this._required = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.REQUIRED, this._required);
        }
    }
    get optional() {
        return this._optional;
    }
    set optional(value) {
        if (this._optional !== value) {
            this._optional = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.OPTIONAL, this._optional);
        }
    }
    get disabled() {
        return this._disabled;
    }
    set disabled(value) {
        if (this._disabled !== value) {
            this._disabled = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.DISABLED, this._disabled);
        }
    }
    get variant() {
        return this._variant;
    }
    set variant(value) {
        if (this._variant !== value) {
            this._variant = value;
            this._adapter.setHostAttribute(FIELD_CONSTANTS.attributes.VARIANT, this._variant);
        }
    }
    get theme() {
        return this._theme;
    }
    set theme(value) {
        if (this._theme !== value) {
            this._theme = value;
            this._adapter.setHostAttribute(FIELD_CONSTANTS.attributes.THEME, this._theme);
        }
    }
    get shape() {
        return this._shape;
    }
    set shape(value) {
        if (this._shape !== value) {
            this._shape = value;
            this._adapter.setHostAttribute(FIELD_CONSTANTS.attributes.SHAPE, this._shape);
        }
    }
    get density() {
        return this._density;
    }
    set density(value) {
        if (this._density !== value) {
            this._density = value;
            this._adapter.setHostAttribute(FIELD_CONSTANTS.attributes.DENSITY, this._density);
        }
    }
    // `dense` takes precedence over `density`
    get dense() {
        return this._dense;
    }
    set dense(value) {
        if (this._dense !== value) {
            this._dense = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.DENSE, this._dense);
        }
    }
    get popoverIcon() {
        return this._popoverIcon;
    }
    set popoverIcon(value) {
        if (this._popoverIcon !== value) {
            this._popoverIcon = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.POPOVER_ICON, this._popoverIcon);
            if (!this._adapter.isConnected) {
                return;
            }
            if (this._popoverIcon) {
                this._adapter.addPopoverIconClickListener(this._popoverIconClickListener);
            }
            else {
                this._adapter.removePopoverIconClickListener(this._popoverIconClickListener);
            }
        }
    }
    get popoverExpanded() {
        return this._popoverExpanded;
    }
    set popoverExpanded(value) {
        if (this._popoverExpanded !== value) {
            this._popoverExpanded = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.POPOVER_EXPANDED, this._popoverExpanded);
        }
    }
    get multiline() {
        return this._multiline;
    }
    set multiline(value) {
        if (this._multiline !== value) {
            this._multiline = value;
            this._adapter.toggleHostAttribute(FIELD_CONSTANTS.attributes.MULTILINE, this._multiline);
        }
    }
    get supportTextInset() {
        return this._supportTextInset;
    }
    set supportTextInset(value) {
        if (this._supportTextInset !== value) {
            this._supportTextInset = value;
            this._adapter.setHostAttribute(FIELD_CONSTANTS.attributes.SUPPORT_TEXT_INSET, this._supportTextInset);
        }
    }
    get focusIndicatorTargetElement() {
        return this._adapter.focusIndicator.targetElement;
    }
    set focusIndicatorTargetElement(value) {
        this._adapter.focusIndicator.targetElement = value;
    }
    get focusIndicatorFocusMode() {
        return this._adapter.focusIndicator.focusMode;
    }
    set focusIndicatorFocusMode(value) {
        this._adapter.focusIndicator.focusMode = value;
    }
    get focusIndicatorAllowFocus() {
        return this._adapter.focusIndicator.allowFocus;
    }
    set focusIndicatorAllowFocus(value) {
        this._adapter.focusIndicator.allowFocus = value;
    }
}
