var _disable, _permission, _permission$, _notFound, _toPermissionObj, _emit;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
export class ZuiPermissionService {
    constructor() {
        _disable.set(this, false);
        _permission.set(this, {});
        _permission$.set(this, new Subject());
        _notFound.set(this, void 0);
        _toPermissionObj.set(this, (permissions) => permissions.reduce((acc, item) => (Object.assign(Object.assign({}, acc), { [item]: true })), {}));
        _emit.set(this, () => __classPrivateFieldGet(this, _permission$).next(__classPrivateFieldGet(this, _permission)));
        this.addPermissions = (permissions) => {
            const permissionObj = __classPrivateFieldGet(this, _toPermissionObj).call(this, permissions);
            __classPrivateFieldSet(this, _permission, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _permission)), permissionObj));
            __classPrivateFieldGet(this, _emit).call(this);
        };
        this.removePermissions = (permissions) => {
            Object.keys(__classPrivateFieldGet(this, _permission)).forEach(permission => {
                if (permissions.includes(permission))
                    delete __classPrivateFieldGet(this, _permission)[permission];
            });
            __classPrivateFieldGet(this, _emit).call(this);
        };
        this.clearPermissions = () => {
            __classPrivateFieldSet(this, _permission, {});
            __classPrivateFieldGet(this, _emit).call(this);
        };
        this.enable = () => {
            __classPrivateFieldSet(this, _disable, false);
        };
        this.disable = () => {
            __classPrivateFieldSet(this, _disable, true);
        };
        this.setNotFoundPage = (commands, extras) => {
            __classPrivateFieldSet(this, _notFound, { commands, extras });
        };
        this.clearNotFoundPage = () => {
            __classPrivateFieldSet(this, _notFound, null);
        };
    }
    get permission() {
        return __classPrivateFieldGet(this, _permission);
    }
    get dataChange$() {
        return __classPrivateFieldGet(this, _permission$);
    }
    get isDisable() {
        return __classPrivateFieldGet(this, _disable);
    }
    get notFoundPage() {
        return __classPrivateFieldGet(this, _notFound);
    }
}
_disable = new WeakMap(), _permission = new WeakMap(), _permission$ = new WeakMap(), _notFound = new WeakMap(), _toPermissionObj = new WeakMap(), _emit = new WeakMap();
ZuiPermissionService.decorators = [
    { type: Injectable }
];
//# sourceMappingURL=index.service.js.map