/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { getShadowElement, toggleClass } from '@tylertech/forge-core';
import { BaseAdapter } from '../../core/base/base-adapter';
import { CHIP_CONSTANTS } from '../chip/chip-constants';
import { CHIP_SET_CONSTANTS } from './chip-set-constants';
export class ChipSetAdapter extends BaseAdapter {
    constructor(component) {
        super(component);
        this._rootElement = getShadowElement(this._component, CHIP_SET_CONSTANTS.selectors.ROOT);
    }
    setVertical(value) {
        toggleClass(this._rootElement, value, CHIP_SET_CONSTANTS.classes.VERTICAL);
    }
    setType(value) {
        const chips = this._getChips();
        chips.forEach(c => c.type = value);
    }
    setDense(value) {
        const chips = this._getChips();
        chips.forEach(c => c.dense = value);
    }
    setDisabled(value) {
        const chips = this._getChips();
        chips.forEach(c => c.disabled = value);
    }
    tryFocusPrevious(fromChip) {
        const chips = this._getChips();
        const activeChipIndex = chips.findIndex(chip => chip === fromChip);
        if (activeChipIndex >= 0) {
            if (activeChipIndex === 0) {
                chips[chips.length - 1].tryFocusDelete();
            }
            else {
                chips[activeChipIndex - 1].tryFocusDelete();
            }
        }
    }
    tryFocusNext(fromChip) {
        const chips = this._getChips();
        const activeChipIndex = chips.findIndex(chip => chip === fromChip);
        if (activeChipIndex >= 0) {
            if (activeChipIndex === chips.length - 1) {
                chips[0].focus();
            }
            else {
                chips[activeChipIndex + 1].focus();
            }
        }
    }
    _getChips() {
        return Array.from(this._component.querySelectorAll(CHIP_CONSTANTS.elementName));
    }
}
