"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShowEditDialogOptions = exports.Box = void 0;
var config_1 = require("../config");
var aurelia_dialog_1 = require("aurelia-dialog");
var dialog_box_1 = require("./dialogs/dialog-box");
var aurelia_framework_1 = require("aurelia-framework");
var Box = exports.Box = (function () {
    function Box(dialogService, config) {
        this.dialogService = dialogService;
        this.config = config;
    }
    Box.prototype.showError = function (message, title, actions, isTranslated, lock, keyboard) {
        if (actions === void 0) { actions = null; }
        if (isTranslated === void 0) { isTranslated = true; }
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: {
                message: message,
                title: title,
                actions: actions,
                dialogType: dialog_box_1.CustomDialogType.Error,
                isTranslated: isTranslated
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: true,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add("container-error-view-box");
                modalOverlay.classList.add("overlay-error-view-box");
            }
        });
    };
    Box.prototype.showQuestion = function (message, title, actions, lock, keyboard) {
        if (actions === void 0) { actions = null; }
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: {
                message: message,
                title: title,
                actions: actions,
                dialogType: dialog_box_1.CustomDialogType.Question
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: true,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add("container-question-view-box");
                modalOverlay.classList.add("overlay-question-view-box");
            }
        });
    };
    Box.prototype.showWarning = function (message, title, actions, lock, keyboard) {
        if (actions === void 0) { actions = null; }
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: {
                message: message,
                title: title,
                actions: actions,
                dialogType: dialog_box_1.CustomDialogType.Warning
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: true,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add("container-warning-view-box");
                modalOverlay.classList.add("overlay-warning-view-box");
            }
        });
    };
    Box.prototype.showNotification = function (message, title, actions, lock, keyboard) {
        if (actions === void 0) { actions = null; }
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: {
                message: message,
                title: title,
                actions: actions,
                dialogType: dialog_box_1.CustomDialogType.Notification
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: true,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add("container-notification-view-box");
                modalOverlay.classList.add("overlay-notification-view-box");
            }
        });
    };
    Box.prototype.showEditDialog = function (viewModel, entityIdToEdit, title, optionsOrCallback, optionsObj) {
        var callback = null;
        var options = null;
        if (optionsOrCallback != null) {
            if (isFunction(optionsOrCallback)) {
                callback = optionsOrCallback;
                options = optionsObj;
            }
            else {
                options = optionsOrCallback;
            }
        }
        else if (optionsObj != null) {
            options = optionsObj;
        }
        if (options == null) {
            options = new ShowEditDialogOptions();
        }
        else {
            options = new ShowEditDialogOptions(options);
        }
        var model = {
            title: title,
            actions: options === null || options === void 0 ? void 0 : options.actions,
            dialogType: dialog_box_1.CustomDialogType.Edit,
            editVm: viewModel,
            param1: entityIdToEdit,
            callback: callback || (options === null || options === void 0 ? void 0 : options.callback),
            canSave: options === null || options === void 0 ? void 0 : options.canSave,
            icon: options === null || options === void 0 ? void 0 : options.icon,
            position: options === null || options === void 0 ? void 0 : options.position,
            size: options === null || options === void 0 ? void 0 : options.size
        };
        Object.assign(model, options === null || options === void 0 ? void 0 : options.model);
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: model,
            lock: options === null || options === void 0 ? void 0 : options.lock,
            keyboard: options === null || options === void 0 ? void 0 : options.keyboard,
            rejectOnCancel: false,
            position: function (modalContainer, modalOverlay) {
                if ((options === null || options === void 0 ? void 0 : options.containerClass) != null) {
                    modalContainer.classList.add(options.containerClass);
                }
                if ((options === null || options === void 0 ? void 0 : options.overlayClass) != null) {
                    modalOverlay.classList.add(options.overlayClass);
                }
            }
        });
    };
    Box.prototype.showCustomDialog = function (viewModel, entityIdToEdit, title, optionsOrCallback, optionsObj) {
        var callback = null;
        var options = null;
        if (optionsOrCallback != null) {
            if (isFunction(optionsOrCallback)) {
                callback = optionsOrCallback;
                options = optionsObj;
            }
            else {
                options = optionsOrCallback;
            }
        }
        else if (optionsObj != null) {
            options = optionsObj;
        }
        if (options == null) {
            options = new ShowEditDialogOptions();
        }
        else {
            options = new ShowEditDialogOptions(options);
        }
        var model = {
            title: title,
            dialogType: dialog_box_1.CustomDialogType.Custom,
            editVm: viewModel,
            param1: entityIdToEdit,
            callback: callback || (options === null || options === void 0 ? void 0 : options.callback),
            canSave: options === null || options === void 0 ? void 0 : options.canSave,
            icon: options === null || options === void 0 ? void 0 : options.icon,
            position: options === null || options === void 0 ? void 0 : options.position,
            size: options === null || options === void 0 ? void 0 : options.size
        };
        Object.assign(model, options.model);
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: model,
            lock: options === null || options === void 0 ? void 0 : options.lock,
            keyboard: options === null || options === void 0 ? void 0 : options.keyboard,
            rejectOnCancel: false,
            position: function (modalContainer, modalOverlay) {
                if ((options === null || options === void 0 ? void 0 : options.containerClass) != null) {
                    modalContainer.classList.add(options.containerClass);
                }
                if ((options === null || options === void 0 ? void 0 : options.overlayClass) != null) {
                    modalOverlay.classList.add(options.overlayClass);
                }
            }
        });
    };
    Box.prototype.showInput = function (message, title, required, lock, keyboard, icon) {
        if (required === void 0) { required = true; }
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        if (icon === void 0) { icon = null; }
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: {
                message: message,
                title: title,
                dialogType: dialog_box_1.CustomDialogType.Input,
                required: required,
                icon: icon
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: true,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add("container-input-view-box");
                modalOverlay.classList.add("overlay-input-view-box");
            }
        });
    };
    Box.prototype.showRichInput = function (message, title, content, lock, keyboard, icon) {
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        if (icon === void 0) { icon = null; }
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: {
                message: message,
                title: title,
                dialogType: dialog_box_1.CustomDialogType.RichText,
                content: content,
                required: false,
                icon: icon
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: true,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add("container-rich-text-view-box");
                modalOverlay.classList.add("overlay-rich-text-view-box");
            }
        });
    };
    Box.prototype.showSelect = function (message, title, service, optionsText, optionsValue, icon, lock, keyboard, isMultiple, select, sortColumn, filterProperties) {
        if (icon === void 0) { icon = null; }
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        if (isMultiple === void 0) { isMultiple = true; }
        if (select === void 0) { select = null; }
        if (sortColumn === void 0) { sortColumn = null; }
        if (filterProperties === void 0) { filterProperties = null; }
        return this.dialogService.open({
            viewModel: dialog_box_1.DialogBoxViewModel,
            model: {
                message: message,
                title: title,
                dialogType: dialog_box_1.CustomDialogType.Select,
                service: service,
                optionsText: optionsText,
                optionsValue: optionsValue,
                icon: icon,
                isMultiple: isMultiple,
                select: select,
                sortColumn: sortColumn !== null && sortColumn !== void 0 ? sortColumn : optionsText,
                filterProperties: filterProperties !== null && filterProperties !== void 0 ? filterProperties : [optionsText]
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: true,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add("container-select-view-box");
                modalOverlay.classList.add("overlay-select-view-box");
            }
        });
    };
    Box.prototype.showFloatingBox = function (viewModel, lock, keyboard) {
        if (lock === void 0) { lock = true; }
        if (keyboard === void 0) { keyboard = false; }
        var openPromise = this.dialogService.open({
            host: this.config.containerConfig.DialogContainer.anchor,
            viewModel: viewModel,
            view: viewModel.view,
            model: {
                dialogService: this.dialogService
            },
            lock: lock,
            keyboard: keyboard,
            rejectOnCancel: false,
            startingZIndex: 500,
            position: function (modalContainer, modalOverlay) {
                modalContainer.classList.add('floating-box', viewModel.size);
                modalOverlay.classList.add('overlay-floating-box');
            }
        });
        openPromise.then(function (openResult) {
            if (openResult.controller) {
                viewModel.setDialogController(openResult.controller);
            }
            else {
                debugger;
            }
        });
        return openPromise;
    };
    Box = __decorate([
        aurelia_framework_1.autoinject,
        __metadata("design:paramtypes", [aurelia_dialog_1.DialogService, config_1.Config])
    ], Box);
    return Box;
}());
var ShowEditDialogOptions = (function () {
    function ShowEditDialogOptions(data) {
        Object.assign(this, {
            canSave: true,
            lock: true,
            keyboard: false,
            size: 'lg',
            position: 'right'
        }, data);
    }
    return ShowEditDialogOptions;
}());
exports.ShowEditDialogOptions = ShowEditDialogOptions;

//# sourceMappingURL=box.js.map
