"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class MultiActiveArrayService {
    constructor() {
        this.setOpenHandlers = {};
        this.openAll = this.openAll.bind(this);
        this.closeAll = this.closeAll.bind(this);
    }
    addSetOpenHandler(id, fn) {
        if (!this.setOpenHandlers[id])
            this.setOpenHandlers[id] = [];
        this.setOpenHandlers[id].push(fn);
    }
    removeSetOpenHandler(id, fn) {
        if (!this.setOpenHandlers[id]) {
            console.warn(`laji-form warning: removing set accordion open handler that isn't registered for id ${id}.`);
            return;
        }
        this.setOpenHandlers[id] = this.setOpenHandlers[id].filter(_fn => fn !== _fn);
    }
    openAll() {
        this.setAllOpen(true);
    }
    closeAll() {
        this.setAllOpen(false);
    }
    setAllOpen(open) {
        Object.keys(this.setOpenHandlers).forEach(id => {
            return (this.setOpenHandlers[id] || []).forEach((fn) => {
                fn(open);
            });
        });
    }
}
exports.default = MultiActiveArrayService;
