/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { getShadowElement } from '@tylertech/forge-core';
import { ForgeRipple } from '../../ripple';
import { BaseAdapter } from '../../core/base/base-adapter';
import { BUTTON_TOGGLE_CONSTANTS } from './button-toggle-constants';
export class ButtonToggleAdapter extends BaseAdapter {
    constructor(component) {
        super(component);
        this._buttonElement = getShadowElement(component, BUTTON_TOGGLE_CONSTANTS.selectors.BUTTON);
    }
    setSelected(value) {
        if (value) {
            this._buttonElement.classList.add(BUTTON_TOGGLE_CONSTANTS.classes.SELECTED);
        }
        else {
            this._buttonElement.classList.remove(BUTTON_TOGGLE_CONSTANTS.classes.SELECTED);
        }
        this._buttonElement.setAttribute('aria-pressed', value.toString());
    }
    addEventListener(type, listener) {
        this._buttonElement.addEventListener(type, listener);
    }
    removeEventListener(type, listener) {
        this._buttonElement.removeEventListener(type, listener);
    }
    initializeRipple() {
        return new ForgeRipple(this._buttonElement);
    }
    setDisabled(value) {
        this._buttonElement.disabled = value;
        if (value) {
            this._buttonElement.setAttribute('aria-disabled', value.toString());
        }
        else {
            this._buttonElement.removeAttribute('aria-disabled');
        }
    }
    setDense(value) {
        if (value) {
            this._buttonElement.classList.add(BUTTON_TOGGLE_CONSTANTS.classes.DENSE);
        }
        else {
            this._buttonElement.classList.remove(BUTTON_TOGGLE_CONSTANTS.classes.DENSE);
        }
    }
    requestFocus() {
        this._buttonElement.focus();
    }
    detectStretchState() {
        if (this._component.hasAttribute(BUTTON_TOGGLE_CONSTANTS.attributes.STRETCH)) {
            return;
        }
        const buttonToggleGroup = this._component.parentElement;
        if (buttonToggleGroup && buttonToggleGroup.hasAttribute(BUTTON_TOGGLE_CONSTANTS.attributes.STRETCH) && buttonToggleGroup.stretch) {
            this._component.setAttribute(BUTTON_TOGGLE_CONSTANTS.attributes.STRETCH, '');
        }
    }
}
