/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { getShadowElement } from '@tylertech/forge-core';
import { FILE_PICKER_CONSTANTS } from './file-picker-constants';
import { BaseAdapter } from '../core';
export class FilePickerAdapter extends BaseAdapter {
    constructor(component) {
        super(component);
        this._container = getShadowElement(component, FILE_PICKER_CONSTANTS.selectors.CONTAINER);
        this._buttonSlot = getShadowElement(component, FILE_PICKER_CONSTANTS.selectors.BUTTON_SLOT);
        this._input = getShadowElement(component, FILE_PICKER_CONSTANTS.selectors.INPUT);
        this._inputEventListener = () => {
            this._input.value = '';
            this._input.click();
        };
        this._container.addEventListener('click', this._inputEventListener);
    }
    registerButtonSlotListener(listener) {
        this._buttonSlot.addEventListener('slotchange', listener);
    }
    registerInputChangeListener(listener) {
        this._input.addEventListener('change', listener);
    }
    registerDragEnterListener(listener) {
        this._container.addEventListener('dragenter', listener);
    }
    registerDragLeaveListener(listener) {
        this._container.addEventListener('dragleave', listener);
    }
    registerDragOverListener(listener) {
        this._container.addEventListener('dragover', listener);
    }
    registerDropListener(listener) {
        this._container.addEventListener('drop', listener);
    }
    removeDragEnterListener(listener) {
        this._container.removeEventListener('dragenter', listener);
    }
    removeDragLeaveListener(listener) {
        this._container.removeEventListener('dragleave', listener);
    }
    removeDragOverListener(listener) {
        this._container.removeEventListener('dragover', listener);
    }
    removeDropListener(listener) {
        this._container.removeEventListener('drop', listener);
    }
    initializeButton() {
        const button = this._component.querySelector('forge-button');
        this._button = button || undefined;
    }
    /**
     * Sets the highlight state of the file picker.
     * @param value True if the highlight should be applied and false if not.
     */
    setHighlightState(value) {
        if (this._container.classList.contains(FILE_PICKER_CONSTANTS.classes.HIGHLIGHT) !== value) {
            this._container.classList.toggle(FILE_PICKER_CONSTANTS.classes.HIGHLIGHT);
        }
    }
    /**
     * Sets the accept attribute of the input.
     * @param value The accept string.
     */
    setAccept(value) {
        if (value) {
            this._input.setAttribute('accept', value);
        }
        else {
            this._input.removeAttribute('accept');
        }
    }
    /**
     * Sets the capture attribute of the input.
     * @param value The capture string.
     */
    setCapture(value) {
        if (value) {
            this._input.setAttribute('capture', value);
        }
        else {
            this._input.removeAttribute('capture');
        }
    }
    /**
     * Sets the multiple attribute of the input.
     * @param value The multiple state.
     */
    setMultiple(value) {
        if (value) {
            this._input.setAttribute('multiple', '');
        }
        else {
            this._input.removeAttribute('multiple');
        }
    }
    /**
     * Sets the disabled state of the file picker.
     * @param value The disabled state.
     */
    setDisabled(value) {
        var _a, _b;
        if (value) {
            this._container.removeEventListener('click', this._inputEventListener);
            (_a = this._button) === null || _a === void 0 ? void 0 : _a.setAttribute('disabled', '');
            this._container.setAttribute('disabled', '');
        }
        else {
            this._container.addEventListener('click', this._inputEventListener);
            (_b = this._button) === null || _b === void 0 ? void 0 : _b.removeAttribute('disabled');
            this._container.removeAttribute('disabled');
        }
    }
    /**
     * Sets the compact state of the file picker.
     * @param value The compact state.
     */
    setCompact(value) {
        if (this._container.classList.contains(FILE_PICKER_CONSTANTS.classes.COMPACT) !== value) {
            this._container.classList.toggle(FILE_PICKER_CONSTANTS.classes.COMPACT);
        }
    }
    /**
     * Sets the borderless state of the file picker.
     * @param value The borderless state.
     */
    setBorderless(value) {
        if (this._container.classList.contains(FILE_PICKER_CONSTANTS.classes.BORDERLESS) !== value) {
            this._container.classList.toggle(FILE_PICKER_CONSTANTS.classes.BORDERLESS);
        }
    }
}
