var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(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", "../../core/AtomBinder", "../../core/AtomLoader", "../../core/AtomUri", "./AtomContentControl", "./AtomItemsControl"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.AtomViewPager = void 0;
    const AtomBinder_1 = require("../../core/AtomBinder");
    const AtomLoader_1 = require("../../core/AtomLoader");
    const AtomUri_1 = require("../../core/AtomUri");
    const AtomContentControl_1 = require("./AtomContentControl");
    const AtomItemsControl_1 = require("./AtomItemsControl");
    class AtomViewPager extends AtomItemsControl_1.AtomItemsControl {
        dispose(e) {
            if (!e) {
                for (const iterator of this.items) {
                    iterator.dispose();
                }
            }
            this.selectedItem = null;
            super.dispose(e);
        }
        onCollectionChanged() {
            // do nothing...
        }
        create() {
            super.create();
            const eStyle = this.element.style;
            eStyle.position = "absolute";
            eStyle.left = eStyle.right = eStyle.bottom = eStyle.top = "0";
            const cc = new AtomContentControl_1.AtomContentControl(this.app);
            this.append(cc);
            const style = cc.element.style;
            style.position = "absolute";
            style.top = style.left = style.right = style.bottom = "0";
            cc.bind(cc.element, "content", [["this", "selectedItem"]], false, (si) => {
                if (!si) {
                    return undefined;
                }
                if (si.view) {
                    return si.view;
                }
                this.app.runAsync(() => __awaiter(this, void 0, void 0, function* () {
                    const { view: ctrl } = yield AtomLoader_1.AtomLoader.loadView(new AtomUri_1.AtomUri(si.value), this.app, false);
                    si.view = ctrl;
                    ctrl.element._logicalParent = this.element;
                    AtomBinder_1.AtomBinder.refreshValue(this, "selectedItem");
                    si.dispose = () => {
                        ctrl.dispose();
                        ctrl.element._logicalParent = null;
                    };
                }));
                return undefined;
            }, this);
        }
    }
    exports.AtomViewPager = AtomViewPager;
});
//# sourceMappingURL=AtomViewPager.js.map