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", "./AtomControl", "./AtomGridView"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.AtomGridSplitter = void 0;
    var AtomControl_1 = require("./AtomControl");
    var AtomGridView_1 = require("./AtomGridView");
    /**
     * Grid Splitter can only be added inside a Grid
     */
    var AtomGridSplitter = /** @class */ (function (_super) {
        __extends(AtomGridSplitter, _super);
        function AtomGridSplitter() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.dragging = false;
            return _this;
        }
        AtomGridSplitter.prototype.preCreate = function () {
            this.direction = "vertical";
            this.dragging = false;
        };
        AtomGridSplitter.prototype.create = function () {
            var _this = this;
            this.bind(this.element, "styleCursor", [["direction"]], false, function (v) { return v === "vertical" ? "ew-resize" : "ns-resize"; });
            this.bind(this.element, "styleBackgroundColor", [["dragging"]], false, function (v) { return v ? "blue" : "lightgray"; });
            var style = this.element.style;
            style.position = "absolute";
            style.left = style.top = style.bottom = style.right = "0";
            this.bindEvent(this.element, "mousedown", function (e) {
                e.preventDefault();
                _this.dragging = true;
                var parent = _this.parent;
                var isVertical = _this.direction === "vertical";
                var disposables = [];
                var rect = { x: e.screenX, y: e.screenY };
                var _a = AtomGridView_1.AtomGridView.getCellInfo(_this.element), column = _a.column, row = _a.row;
                disposables.push(_this.bindEvent(document.body, "mousemove", function (me) {
                    // do drag....
                    var screenX = me.screenX, screenY = me.screenY;
                    var dx = screenX - rect.x;
                    var 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", function (mup) {
                    // stop
                    _this.dragging = false;
                    for (var _i = 0, disposables_1 = disposables; _i < disposables_1.length; _i++) {
                        var iterator = disposables_1[_i];
                        iterator.dispose();
                    }
                }));
            });
        };
        return AtomGridSplitter;
    }(AtomControl_1.AtomControl));
    exports.AtomGridSplitter = AtomGridSplitter;
});
//# sourceMappingURL=AtomGridSplitter.js.map