"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var dimensions_1 = require("@dojo/framework/core/middleware/dimensions");
var focus_1 = require("@dojo/framework/core/middleware/focus");
var icache_1 = require("@dojo/framework/core/middleware/icache");
var vdom_1 = require("@dojo/framework/core/vdom");
var icon_1 = require("../icon");
var theme_1 = require("../middleware/theme");
var css = require("../theme/default/title-pane.m.css");
var fixedCss = require("./styles/title-pane.m.css");
var factory = vdom_1.create({
    dimensions: dimensions_1.default,
    focus: focus_1.default,
    icache: icache_1.createICacheMiddleware(),
    theme: theme_1.default
}).properties();
exports.TitlePane = factory(function TitlePane(_a) {
    var id = _a.id, children = _a.children, properties = _a.properties, _b = _a.middleware, dimensions = _b.dimensions, focus = _b.focus, icache = _b.icache, theme = _b.theme;
    var themeCss = theme.classes(css);
    var _c = properties(), _d = _c.closeable, closeable = _d === void 0 ? true : _d, headingLevel = _c.headingLevel, initialOpen = _c.initialOpen, onClose = _c.onClose, onOpen = _c.onOpen, name = _c.name, themeProp = _c.theme, classes = _c.classes, variant = _c.variant;
    var open = properties().open;
    var firstRender = icache.get('open') === undefined;
    if (open === undefined) {
        open = icache.get('open');
        var existingInitialOpen = icache.get('initialOpen');
        if (initialOpen !== existingInitialOpen) {
            icache.set('open', initialOpen);
            icache.set('initialOpen', initialOpen);
            open = initialOpen;
        }
    }
    return (vdom_1.tsx("div", { classes: [
            theme.variant(),
            themeCss.root,
            open ? themeCss.open : null,
            fixedCss.rootFixed
        ] },
        vdom_1.tsx("div", { "aria-level": headingLevel ? "" + headingLevel : undefined, classes: [
                themeCss.title,
                closeable ? themeCss.closeable : null,
                fixedCss.titleFixed,
                closeable ? fixedCss.closeableFixed : null
            ], role: "heading" },
            vdom_1.tsx("button", { "aria-controls": id + "-content", "aria-expanded": open ? 'true' : 'false', disabled: !closeable, classes: [fixedCss.titleButtonFixed, themeCss.titleButton], focus: focus.isFocused('title-button'), key: "title-button", onclick: function (event) {
                    event.stopPropagation();
                    icache.set('open', !open);
                    if (open) {
                        onClose && onClose();
                    }
                    else {
                        onOpen && onOpen();
                    }
                }, type: "button" },
                vdom_1.tsx("span", { classes: themeCss.arrow },
                    vdom_1.tsx(icon_1.default, { type: open ? 'downIcon' : 'rightIcon', theme: themeProp, classes: classes, variant: variant })),
                name)),
        vdom_1.tsx("div", { "aria-hidden": open ? undefined : 'true', "aria-labelledby": id + "-title", classes: [
                themeCss.content,
                !firstRender && themeCss.contentTransition,
                fixedCss.contentFixed
            ], id: id + "-content", key: "content", styles: {
                marginTop: open ? '0px' : "-" + dimensions.get('content').offset.height + "px"
            } }, children())));
});
exports.default = exports.TitlePane;

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