"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var vdom_1 = require("@dojo/framework/core/vdom");
var focus_1 = require("@dojo/framework/core/middleware/focus");
var popup_1 = require("../popup");
var theme_1 = require("../middleware/theme");
var icache_1 = require("@dojo/framework/core/middleware/icache");
var css = require("../theme/default/context-popup.m.css");
var icache = icache_1.createICacheMiddleware();
var factory = vdom_1.create({ icache: icache, focus: focus_1.default, theme: theme_1.default })
    .properties()
    .children();
var CursorWidth = 2;
var CursorHeight = 4;
exports.ContextPopup = factory(function ContextPopup(_a) {
    var properties = _a.properties, children = _a.children, _b = _a.middleware, icache = _b.icache, focus = _b.focus;
    var _c = properties(), variant = _c.variant, theme = _c.theme, classes = _c.classes;
    var x = icache.getOrSet('x', 0);
    var y = icache.getOrSet('y', 0);
    var _d = children()[0], trigger = _d.trigger, content = _d.content;
    var close = function () {
        var onClose = properties().onClose;
        icache.set('open', false);
        onClose && onClose();
    };
    return (vdom_1.tsx("virtual", null,
        vdom_1.tsx("div", { classes: css.trigger, key: "trigger", oncontextmenu: function (event) {
                var onOpen = properties().onOpen;
                event.preventDefault();
                focus.focus();
                icache.set('x', event.pageX - CursorWidth);
                icache.set('y', event.pageY - CursorHeight);
                icache.set('open', true);
                onOpen && onOpen();
            } }, trigger),
        vdom_1.tsx(popup_1.default, { key: "popup", theme: theme, variant: variant, classes: classes, yTop: y, yBottom: document.documentElement.scrollTop + document.documentElement.clientHeight, xLeft: x, xRight: x, onClose: close, position: "below", open: icache.get('open') },
            vdom_1.tsx("div", null, content({ close: close, shouldFocus: focus.shouldFocus })))));
});
exports.default = exports.ContextPopup;

/*# sourceMappingURL=index.js.map*/