var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { I18N } from 'aurelia-i18n';
import { createOverrideContext, Container, ViewResources, autoinject } from 'aurelia-framework';
import { ViewCompiler, ViewSlot } from "aurelia-templating";
var CustomHtmlRendererEditor = (function () {
    function CustomHtmlRendererEditor() {
    }
    Object.defineProperty(CustomHtmlRendererEditor.prototype, "uiSelect", {
        get: function () {
            var _a;
            var controllers = (_a = this.view) === null || _a === void 0 ? void 0 : _a.controllers;
            if ((controllers === null || controllers === void 0 ? void 0 : controllers.length) > 0) {
                var uiSelectController = controllers.find(function (c) { var _a; return ((_a = c.viewModel) === null || _a === void 0 ? void 0 : _a.constructor.name) == "UISelect"; });
                if (uiSelectController != null) {
                    return uiSelectController.viewModel;
                }
            }
        },
        enumerable: false,
        configurable: true
    });
    CustomHtmlRendererEditor.prototype.getValue = function () {
        return this.params.value;
    };
    CustomHtmlRendererEditor.prototype.isPopup = function () {
        var _a;
        return (_a = this.params.isPopup) !== null && _a !== void 0 ? _a : false;
    };
    CustomHtmlRendererEditor.prototype.init = function (params) {
        this.params = params;
        this.setupGui();
    };
    CustomHtmlRendererEditor.prototype.setupGui = function () {
        this.eGui = document.createElement('div');
        this.eGui.style.width = '100%';
        this.eGui.style.height = '100%';
        var content = this.setupContentGui();
        var html = "<template>".concat(content, "</template>");
        this.i18n = Container.instance.get(I18N);
        var viewCompiler = Container.instance.get(ViewCompiler);
        var viewResources = Container.instance.get(ViewResources);
        var viewFactory = viewCompiler.compile(html, viewResources);
        this.view = viewFactory.create(Container.instance);
        this.viewSlot = new ViewSlot(this.eGui, true);
        this.viewSlot.add(this.view);
        this.view.bind(this, createOverrideContext(this));
        this.viewSlot.attached();
    };
    CustomHtmlRendererEditor.prototype.afterGuiAttached = function () {
        var _this = this;
        setTimeout(function () { var _a; return (_a = _this.uiSelect) === null || _a === void 0 ? void 0 : _a.open(); }, 10);
    };
    CustomHtmlRendererEditor.prototype.getGui = function () {
        return this.eGui;
    };
    CustomHtmlRendererEditor.prototype.refresh = function (params) {
        return true;
    };
    CustomHtmlRendererEditor.prototype.destroy = function () {
        var _a;
        (_a = this.uiSelect) === null || _a === void 0 ? void 0 : _a.close();
        if (this.uiSelect != null) {
            var id = this.uiSelect.select2Instance.id;
            var uiScrollElts = $('.ui-scroll');
            var scrollEvent = 'scroll.select2.' + id;
            var resizeEvent = 'resize.select2.' + id;
            uiScrollElts.off(scrollEvent);
            uiScrollElts.off(resizeEvent);
        }
        if (this.view)
            this.view.unbind();
        if (this.viewSlot)
            this.viewSlot.detached();
    };
    CustomHtmlRendererEditor.prototype.setupContentGui = function () {
        return this.params.getHtml(this);
    };
    CustomHtmlRendererEditor = __decorate([
        autoinject,
        __metadata("design:paramtypes", [])
    ], CustomHtmlRendererEditor);
    return CustomHtmlRendererEditor;
}());
export default CustomHtmlRendererEditor;

//# sourceMappingURL=custom-html-renderer-editor.js.map
