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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
import { activationStrategy } from 'aurelia-router';
import { EventAggregator } from 'aurelia-event-aggregator';
import { Container } from 'aurelia-framework';
import { I18N } from 'aurelia-i18n';
import { Box } from '../modules/box';
import { Datacontext } from '../data/data-context';
import { Config } from '../config';
import { AuthService } from '../security/auth-service';
import { DisposableViewModelBase } from './disposable-view-model-base';
import { Actions } from '../constants/constants';
var ViewModelBase = (function (_super) {
    __extends(ViewModelBase, _super);
    function ViewModelBase(router, logger) {
        var _this = _super.call(this) || this;
        _this.router = router;
        _this.logger = logger;
        _this.showLoadingSpinner = false;
        _this.isDialogView = false;
        _this.entityMatcher = function (a, b) {
            var a_id = a != null && a.id != null ? a.id : a;
            var b_id = b != null && b.id != null ? b.id : b;
            if (a_id == "")
                a_id = 0;
            if (b_id == "")
                b_id = 0;
            return (a_id != null && b_id != null && a_id.toString != null && b_id.toString != null) ? a_id.toString() === b_id.toString() : a_id == b_id;
        };
        _this.eventAggregator = Container.instance.get(EventAggregator);
        _this.i18n = Container.instance.get(I18N);
        _this.box = Container.instance.get(Box);
        _this.datacontext = Container.instance.get(Datacontext);
        _this.config = Container.instance.get(Config);
        _this.authService = Container.instance.get(AuthService);
        return _this;
    }
    ViewModelBase.prototype.activate = function (params) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                if (params === null || params === void 0 ? void 0 : params.dialogType)
                    this.isDialogView = true;
                return [2];
            });
        });
    };
    ViewModelBase.prototype.navigateBack = function () {
        this.router.navigateBack();
    };
    ViewModelBase.prototype.determineActivationStrategy = function () {
        return activationStrategy.replace;
    };
    ViewModelBase.prototype.canDeactivate = function () {
        return Promise.resolve(true);
    };
    ViewModelBase.prototype.log = function (message, data, showToast, translationOptions) {
        message = this.i18n.tr(message, translationOptions);
        this.logger.Log(message, data, 'ViewModelBase', showToast);
    };
    ViewModelBase.prototype.logError = function (message, error, showToast, translationOptions) {
        if (showToast === void 0) { showToast = true; }
        message = this.i18n.tr(message, translationOptions);
        this.logger.LogError(message, error, 'ViewModelBase', showToast);
    };
    ViewModelBase.prototype.navigateTo = function (url, options) {
        if (options == null)
            options = { replace: false, trigger: true };
        if (options.replace == null)
            options.replace = false;
        if (options.trigger == null)
            options.trigger = true;
        this.router.navigate(url, options);
    };
    Object.defineProperty(ViewModelBase.prototype, "canAdd", {
        get: function () {
            return this.authService.checkAccess(this.ressourceName, Actions.Create);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ViewModelBase.prototype, "canDelete", {
        get: function () {
            return this.authService.checkAccess(this.ressourceName, Actions.Delete);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ViewModelBase.prototype, "canUpdate", {
        get: function () {
            return this.authService.checkAccess(this.ressourceName, Actions.Update);
        },
        enumerable: false,
        configurable: true
    });
    return ViewModelBase;
}(DisposableViewModelBase));
export { ViewModelBase };

//# sourceMappingURL=view-model-base.js.map
