/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { EXPANSION_PANEL_CONSTANTS } from '../expansion-panel/expansion-panel-constants';
import { ACCORDION_CONSTANTS } from './accordion-constants';
export class AccordionCore {
    constructor(_adapter) {
        this._adapter = _adapter;
        this._hostInteractionCallback = this._hostInteraction.bind(this);
    }
    initialize() {
        this._attachListeners();
    }
    _attachListeners() {
        this._adapter.addHostListener(EXPANSION_PANEL_CONSTANTS.events.TOGGLE, this._hostInteractionCallback);
    }
    _hostInteraction(evt) {
        if (!evt.detail || (this._panelSelector && !evt.target.matches(this._panelSelector))) {
            return;
        }
        evt.stopPropagation();
        if (this._adapter.isNestedPanel(evt.target)) {
            return;
        }
        const panels = this._adapter.getChildPanels(this._panelSelector);
        panels.forEach(panel => {
            if (evt.target !== panel && !this._adapter.isNestedPanel(panel)) {
                panel.open = false;
            }
        });
    }
    get panelSelector() {
        return this._panelSelector;
    }
    set panelSelector(value) {
        if (this._panelSelector !== value) {
            this._panelSelector = value;
            this._adapter.setHostAttribute(ACCORDION_CONSTANTS.attributes.PANEL_SELECTOR, this._panelSelector);
        }
    }
}
