(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", "./AtomControl", "./AtomGridView"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.AtomGridSplitter = void 0;
    const AtomControl_1 = require("./AtomControl");
    const AtomGridView_1 = require("./AtomGridView");
    /**
     * Grid Splitter can only be added inside a Grid
     */
    class AtomGridSplitter extends AtomControl_1.AtomControl {
        constructor() {
            super(...arguments);
            this.dragging = false;
        }
        preCreate() {
            this.direction = "vertical";
            this.dragging = false;
        }
        create() {
            this.bind(this.element, "styleCursor", [["direction"]], false, (v) => v === "vertical" ? "ew-resize" : "ns-resize");
            this.bind(this.element, "styleBackgroundColor", [["dragging"]], false, (v) => v ? "blue" : "lightgray");
            const style = this.element.style;
            style.position = "absolute";
            style.left = style.top = style.bottom = style.right = "0";
            this.bindEvent(this.element, "mousedown", (e) => {
                e.preventDefault();
                this.dragging = true;
                const parent = this.parent;
                const isVertical = this.direction === "vertical";
                const disposables = [];
                const rect = { x: e.screenX, y: e.screenY };
                const { column, row } = AtomGridView_1.AtomGridView.getCellInfo(this.element);
                const ss = document.createElement("style");
                ss.textContent = "iframe { pointer-events: none }";
                document.head.appendChild(ss);
                disposables.push({
                    dispose: () => ss.remove()
                });
                disposables.push(this.bindEvent(document.body, "mousemove", (me) => {
                    // do drag....
                    const { screenX, screenY } = me;
                    const dx = screenX - rect.x;
                    const dy = screenY - rect.y;
                    if (isVertical) {
                        parent.resize("column", column, dx);
                    }
                    else {
                        parent.resize("row", row, dy);
                    }
                    rect.x = screenX;
                    rect.y = screenY;
                }));
                disposables.push(this.bindEvent(document.body, "mouseup", (mup) => {
                    // stop
                    this.dragging = false;
                    for (const iterator of disposables) {
                        iterator.dispose();
                    }
                }));
            });
        }
    }
    exports.AtomGridSplitter = AtomGridSplitter;
});
//# sourceMappingURL=AtomGridSplitter.js.map