/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { getShadowElement } from '@tylertech/forge-core';
import { BaseAdapter } from '../core/base/base-adapter';
import { ColorPickerValueType, COLOR_PICKER_CONSTANTS } from './color-picker-constants';
export class ColorPickerAdapter extends BaseAdapter {
    constructor(component) {
        super(component);
        this._gradientElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.GRADIENT);
        this._previewColorElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.PREVIEW_COLOR);
        this._hexInputElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.HEX_INPUT);
        this._rgbaInputRElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_RGBA_R);
        this._rgbaInputGElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_RGBA_G);
        this._rgbaInputBElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_RGBA_B);
        this._rgbaInputAElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_RGBA_A);
        this._hsvaInputHElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_HSVA_H);
        this._hsvaInputSElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_HSVA_S);
        this._hsvaInputVElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_HSVA_V);
        this._hsvaInputAElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_HSVA_A);
        this._hueSliderElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.HUE_SLIDER);
        this._hueSliderThumbElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.HUE_SLIDER_THUMB);
        this._opacitySliderElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.OPACITY_SLIDER);
        this._opacitySliderThumbElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.OPACITY_SLIDER_THUMB);
        this._hexValueContainerElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_HEX_CONTAINER);
        this._rgbaValueContainerElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_RGBA_CONTAINER);
        this._hsvaValueContainerElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.COLOR_VALUE_HSVA_CONTAINER);
        this._typeButtonElement = getShadowElement(component, COLOR_PICKER_CONSTANTS.selectors.TYPE_BUTTON);
    }
    setPreviewColor(rgbaStyle) {
        this._previewColorElement.style.backgroundColor = rgbaStyle;
    }
    setHexInputValue(value) {
        this._hexInputElement.value = value;
    }
    setRgbaInputValue(rgba) {
        this._rgbaInputRElement.value = rgba.r.toString();
        this._rgbaInputGElement.value = rgba.g.toString();
        this._rgbaInputBElement.value = rgba.b.toString();
        this._rgbaInputAElement.value = rgba.a.toString();
    }
    setHsvaInputValue(hsva) {
        this._hsvaInputHElement.value = hsva.h.toString();
        this._hsvaInputSElement.value = hsva.s.toString();
        this._hsvaInputVElement.value = hsva.v.toString();
        this._hsvaInputAElement.value = hsva.a.toString();
    }
    updateA11y(hueValue, opacityValue) {
        this._hueSliderThumbElement.setAttribute('aria-valuenow', hueValue.toString());
        this._hueSliderThumbElement.setAttribute('aria-valuetext', hueValue.toString());
        this._opacitySliderThumbElement.setAttribute('aria-valuenow', opacityValue.toString());
        this._opacitySliderThumbElement.setAttribute('aria-valuetext', opacityValue.toString());
    }
    setGradientColor(value) {
        this._gradientElement.style.backgroundColor = value;
    }
    getHueSliderElement() {
        return this._hueSliderElement;
    }
    getOpacitySliderElement() {
        return this._opacitySliderElement;
    }
    getGradientElement() {
        return this._gradientElement;
    }
    setActiveValueType(type) {
        this._hexValueContainerElement.style.display = 'none';
        this._rgbaValueContainerElement.style.display = 'none';
        this._hsvaValueContainerElement.style.display = 'none';
        switch (type) {
            case ColorPickerValueType.HEX:
                this._hexValueContainerElement.style.removeProperty('display');
                break;
            case ColorPickerValueType.RGBA:
                this._rgbaValueContainerElement.style.removeProperty('display');
                break;
            case ColorPickerValueType.HSVA:
                this._hsvaValueContainerElement.style.removeProperty('display');
                break;
        }
    }
    focusValueInput(type) {
        switch (type) {
            case ColorPickerValueType.HEX:
                this._hexInputElement.focus();
                this._hexInputElement.select();
                break;
            case ColorPickerValueType.RGBA:
                this._rgbaInputRElement.focus();
                this._rgbaInputRElement.select();
                break;
            case ColorPickerValueType.HSVA:
                this._hsvaInputHElement.focus();
                this._hsvaInputHElement.select();
                break;
        }
    }
    setTypeClickListener(listener) {
        this._typeButtonElement.addEventListener('click', listener);
    }
    removeTypeClickListener(listener) {
        this._typeButtonElement.removeEventListener('click', listener);
    }
    setHexInputListener(type, listener) {
        this._hexInputElement.addEventListener(type, listener);
    }
    removeHexInputListener(type, listener) {
        this._hexInputElement.removeEventListener(type, listener);
    }
    getHexInputValue() {
        return this._hexInputElement.value;
    }
    setRgbaInputListener(type, listener) {
        this._rgbaInputRElement.addEventListener(type, listener);
        this._rgbaInputGElement.addEventListener(type, listener);
        this._rgbaInputBElement.addEventListener(type, listener);
        this._rgbaInputAElement.addEventListener(type, listener);
    }
    removeRgbaInputListener(type, listener) {
        this._rgbaInputRElement.removeEventListener(type, listener);
        this._rgbaInputGElement.removeEventListener(type, listener);
        this._rgbaInputBElement.removeEventListener(type, listener);
        this._rgbaInputAElement.removeEventListener(type, listener);
    }
    getRgbaInputValue() {
        return {
            r: parseInt(this._rgbaInputRElement.value, 10),
            g: parseInt(this._rgbaInputGElement.value, 10),
            b: parseInt(this._rgbaInputBElement.value, 10),
            a: parseFloat(this._rgbaInputAElement.value)
        };
    }
    setHsvaInputListener(type, listener) {
        this._hsvaInputHElement.addEventListener(type, listener);
        this._hsvaInputSElement.addEventListener(type, listener);
        this._hsvaInputVElement.addEventListener(type, listener);
        this._hsvaInputAElement.addEventListener(type, listener);
    }
    removeHsvaInputListener(type, listener) {
        this._hsvaInputHElement.removeEventListener(type, listener);
        this._hsvaInputSElement.removeEventListener(type, listener);
        this._hsvaInputVElement.removeEventListener(type, listener);
        this._hsvaInputAElement.removeEventListener(type, listener);
    }
    getHsvaInputValue() {
        return {
            h: parseInt(this._hsvaInputHElement.value, 10),
            s: parseInt(this._hsvaInputSElement.value, 10),
            v: parseInt(this._hsvaInputVElement.value, 10),
            a: parseFloat(this._hsvaInputAElement.value)
        };
    }
    toggleOpacityControls(visible) {
        if (visible) {
            this._opacitySliderElement.style.removeProperty('display');
            if (this._rgbaInputAElement.parentElement) {
                this._rgbaInputAElement.parentElement.style.removeProperty('display');
            }
            if (this._hsvaInputAElement.parentElement) {
                this._hsvaInputAElement.parentElement.style.removeProperty('display');
            }
        }
        else {
            this._opacitySliderElement.style.display = 'none';
            if (this._rgbaInputAElement.parentElement) {
                this._rgbaInputAElement.parentElement.style.display = 'none';
            }
            if (this._hsvaInputAElement.parentElement) {
                this._hsvaInputAElement.parentElement.style.display = 'none';
            }
        }
    }
}
