/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { addClass, getShadowElement, isDefined, removeClass, toggleElementPlaceholder, deepQuerySelectorAll, toggleAttribute, toggleClass } from '@tylertech/forge-core';
import { BaseAdapter } from '../../core/base/base-adapter';
import { APP_BAR_SEARCH_CONSTANTS } from './app-bar-search-constants';
/**
 * Provides facilities for interacting with the internal DOM of `AppBarSearchComponent`.
 */
export class AppBarSearchAdapter extends BaseAdapter {
    constructor(component) {
        super(component);
        this._rootElement = getShadowElement(component, APP_BAR_SEARCH_CONSTANTS.selectors.ROOT);
        this._globalIconContainer = getShadowElement(component, APP_BAR_SEARCH_CONSTANTS.selectors.GLOBAL_ICON_CONTAINER);
        this._contextContainerElement = getShadowElement(component, APP_BAR_SEARCH_CONSTANTS.selectors.CONTEXT_CONTAINER);
    }
    initialize() {
        const inputElements = deepQuerySelectorAll(this._component, APP_BAR_SEARCH_CONSTANTS.selectors.INPUT, false);
        if (inputElements.length) {
            this._inputElement = inputElements[0];
        }
    }
    hasInputElement() {
        return isDefined(this._inputElement);
    }
    addRootClass(className) {
        addClass(className, this._rootElement);
    }
    removeRootClass(className) {
        removeClass(className, this._rootElement);
    }
    /**
     * Adds an event to the search input element.
     * @param {string} type The event type.
     * @param {Function} listener The event listener.
     */
    addSearchInputEventListener(type, listener) {
        this._inputElement.addEventListener(type, listener);
    }
    /**
     * Removes an event from the search input element.
     * @param {string} type The event type.
     * @param {Function} listener The event listener.
     */
    removeSearchInputEventListener(type, listener) {
        this._inputElement.removeEventListener(type, listener);
    }
    /**
     * Toggles the disabled attribute on the search input.
     * @param {boolean} disabled Whether the attribute should be set or not.
     */
    setDisabled(disabled) {
        toggleClass(this._rootElement, disabled, APP_BAR_SEARCH_CONSTANTS.classes.DISABLED);
        toggleAttribute(this._inputElement, disabled, APP_BAR_SEARCH_CONSTANTS.attributes.DISABLED);
    }
    getInputValue() {
        return this._inputElement.value;
    }
    setInputValue(value) {
        this._inputElement.value = value;
    }
    setInputPlaceholder(value) {
        this._inputElement.placeholder = value;
    }
    setGlobalIconVisibility(isVisible) {
        this._globalIconPlaceholder = toggleElementPlaceholder(this._component, isVisible, APP_BAR_SEARCH_CONSTANTS.elementName, APP_BAR_SEARCH_CONSTANTS.selectors.GLOBAL_ICON_CONTAINER, this._globalIconContainer, this._globalIconPlaceholder);
    }
    setContextVisibility(isVisible) {
        this._contextContainerPlaceholder = toggleElementPlaceholder(this._component, isVisible, APP_BAR_SEARCH_CONSTANTS.elementName, APP_BAR_SEARCH_CONSTANTS.selectors.CONTEXT_CONTAINER, this._contextContainerElement, this._contextContainerPlaceholder);
    }
}
