var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
(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;
    var AtomListBoxStyle_1 = require("../styles/AtomListBoxStyle");
    var AtomItemsControl_1 = require("./AtomItemsControl");
    var AtomListBox = /** @class */ (function (_super) {
        __extends(AtomListBox, _super);
        function AtomListBox() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        AtomListBox.prototype.preCreate = function () {
            var _this = this;
            this.selectItemOnClick = true;
            _super.prototype.preCreate.call(this);
            this.defaultControlStyle = AtomListBoxStyle_1.AtomListBoxStyle;
            this.registerItemClick();
            this.runAfterInit(function () {
                var _a;
                return _this.setElementClass(_this.element, (_a = {},
                    _a[_this.controlStyle.name] = 1,
                    _a["atom-list-box"] = 1,
                    _a));
            });
        };
        AtomListBox.prototype.registerItemClick = function () {
            var _this = this;
            this.bindEvent(this.element, "click", function (e) {
                var p = _this.atomParent(e.target);
                if (p === _this) {
                    return;
                }
                if (p.element._logicalParent === _this.element) {
                    // this is child..
                    var data = p.data;
                    if (!data) {
                        return;
                    }
                    if (_this.selectItemOnClick) {
                        _this.toggleSelection(data);
                        var ce = new CustomEvent("selectionChanged", {
                            bubbles: false,
                            cancelable: false,
                            detail: data
                        });
                        _this.element.dispatchEvent(ce);
                    }
                }
            });
        };
        AtomListBox.prototype.createChild = function (df, data) {
            var child = _super.prototype.createChild.call(this, df, data);
            child.bind(child.element, "styleClass", [
                ["this", "version"],
                ["data"],
                ["this", "selectedItems"]
            ], false, function (version, itemData, selectedItems) {
                return {
                    "list-item": true,
                    "item": true,
                    "selected-item": selectedItems
                        && selectedItems.find(function (x) { return x === itemData; }),
                    "selected-list-item": selectedItems
                        && selectedItems.find(function (x) { return x === itemData; })
                };
            }, this);
            return child;
        };
        return AtomListBox;
    }(AtomItemsControl_1.AtomItemsControl));
    exports.AtomListBox = AtomListBox;
});
//# sourceMappingURL=AtomListBox.js.map