(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "../styles/AtomListBoxStyle", "./AtomItemsControl"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.AtomListBox = void 0;
    const AtomListBoxStyle_1 = require("../styles/AtomListBoxStyle");
    const AtomItemsControl_1 = require("./AtomItemsControl");
    class AtomListBox extends AtomItemsControl_1.AtomItemsControl {
        preCreate() {
            this.selectItemOnClick = true;
            super.preCreate();
            this.defaultControlStyle = AtomListBoxStyle_1.AtomListBoxStyle;
            this.registerItemClick();
            this.runAfterInit(() => this.setElementClass(this.element, {
                [this.controlStyle.name]: 1,
                "atom-list-box": 1
            }));
        }
        registerItemClick() {
            this.bindEvent(this.element, "click", (e) => {
                const p = this.atomParent(e.target);
                if (p === this) {
                    return;
                }
                if (p.element._logicalParent === this.element) {
                    // this is child..
                    const data = p.data;
                    if (!data) {
                        return;
                    }
                    if (this.selectItemOnClick) {
                        this.toggleSelection(data);
                        const ce = new CustomEvent("selectionChanged", {
                            bubbles: false,
                            cancelable: false,
                            detail: data
                        });
                        this.element.dispatchEvent(ce);
                    }
                }
            });
        }
        createChild(df, data) {
            const child = super.createChild(df, data);
            child.bind(child.element, "styleClass", [
                ["this", "version"],
                ["data"],
                ["this", "selectedItems"]
            ], false, (version, itemData, selectedItems) => {
                return {
                    "list-item": true,
                    "item": true,
                    "selected-item": selectedItems
                        && selectedItems.find((x) => x === itemData),
                    "selected-list-item": selectedItems
                        && selectedItems.find((x) => x === itemData)
                };
            }, this);
            return child;
        }
    }
    exports.AtomListBox = AtomListBox;
});
//# sourceMappingURL=AtomListBox.js.map