/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { BUTTON_TOGGLE_CONSTANTS } from './button-toggle-constants';
export class ButtonToggleFoundation {
    constructor(_adapter) {
        this._adapter = _adapter;
        this._selected = false;
        this._disabled = false;
        this._dense = false;
        this._clickListener = evt => this._onClick(evt);
    }
    initialize() {
        this._rippleInstance = this._adapter.initializeRipple();
        this._adapter.addEventListener('click', this._clickListener);
        this._adapter.setSelected(this._selected);
        this._adapter.setDisabled(this._disabled);
        this._adapter.setDense(this._dense);
        this._adapter.detectStretchState();
    }
    disconnect() {
        if (this._rippleInstance) {
            this._rippleInstance.destroy();
        }
        this._adapter.removeEventListener('click', this._clickListener);
    }
    _onClick(evt) {
        this._selected = !this._selected;
        this._updateSelectedState();
        this._adapter.emitHostEvent(BUTTON_TOGGLE_CONSTANTS.events.SELECT, { value: this._value, selected: this._selected });
    }
    _updateSelectedState() {
        this._adapter.setSelected(this._selected);
        this._adapter.setHostAttribute(BUTTON_TOGGLE_CONSTANTS.attributes.SELECTED, this._selected.toString());
    }
    get value() {
        return this._value;
    }
    set value(value) {
        this._value = value;
    }
    get selected() {
        return this._selected;
    }
    set selected(value) {
        if (this._selected !== value) {
            this._selected = value;
            this._updateSelectedState();
        }
    }
    get disabled() {
        return this._disabled;
    }
    set disabled(value) {
        if (this._disabled !== value) {
            this._disabled = value;
            this._adapter.setDisabled(this._disabled);
        }
    }
    get dense() {
        return this._dense;
    }
    set dense(value) {
        if (this._dense !== value) {
            this._dense = value;
            this._adapter.setDense(this._dense);
        }
    }
    setFocus() {
        this._adapter.requestFocus();
    }
}
