"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Set_1 = require("@dojo/framework/shim/Set");
var css = require("../theme/default/accordion.m.css");
var titlePaneCss = require("../theme/default/title-pane.m.css");
var title_pane_1 = require("../title-pane");
var theme_1 = require("../middleware/theme");
var vdom_1 = require("@dojo/framework/core/vdom");
var icache_1 = require("@dojo/framework/core/middleware/icache");
var icache = icache_1.createICacheMiddleware();
var factory = vdom_1.create({
    icache: icache,
    theme: theme_1.default
})
    .properties()
    .children();
exports.Accordion = factory(function Accordion(_a) {
    var _b = _a.middleware, icache = _b.icache, theme = _b.theme, properties = _a.properties, children = _a.children;
    var themedCss = theme.classes(css);
    var _c = properties(), exclusive = _c.exclusive, panes = _c.panes, variant = _c.variant, classes = _c.classes;
    var openIndexes = icache.getOrSet('openIndexes', new Set_1.default());
    var onOpen = function (index) {
        if (exclusive) {
            icache.set('openIndexes', new Set_1.default([index]));
        }
        else {
            var openIndexes_1 = icache.getOrSet('openIndexes', new Set_1.default());
            openIndexes_1.add(index);
            icache.set('openIndexes', openIndexes_1);
        }
    };
    var onClose = function (index) {
        var openIndexes = icache.getOrSet('openIndexes', new Set_1.default());
        openIndexes.delete(index);
        icache.set('openIndexes', openIndexes);
    };
    return (vdom_1.tsx("div", { classes: [theme.variant(), themedCss.root] }, panes.map(function (paneName, index) {
        return (vdom_1.tsx(title_pane_1.default, { key: "pane-" + index, open: openIndexes.has(index), onOpen: function () {
                onOpen(index);
            }, onClose: function () {
                onClose(index);
            }, theme: theme.compose(titlePaneCss, css, 'pane'), classes: classes, variant: variant, name: paneName }, children()[index]));
    })));
});
exports.default = exports.Accordion;

/*# sourceMappingURL=index.js.map*/