import LocalStorage from "./LocalStorage";
import { PermissionHelper, } from "../../Types/Permission";
export default class PermissionUtil {
    static getGlobalPermissions() {
        if (!LocalStorage.getItem("global_permissions")) {
            return null;
        }
        const globalPermissions = LocalStorage.getItem("global_permissions");
        return globalPermissions;
    }
    static getAllPermissions() {
        let permissions = [];
        const globalPermissions = this.getGlobalPermissions();
        if (globalPermissions) {
            permissions = [...globalPermissions.globalPermissions];
        }
        const projectPermissions = this.getProjectPermissions();
        if (projectPermissions) {
            permissions = [
                ...permissions,
                ...projectPermissions.permissions.map((i) => {
                    return i.permission;
                }),
            ];
        }
        return permissions;
    }
    static getProjectPermissions() {
        if (!LocalStorage.getItem("project_permissions")) {
            return null;
        }
        const permissions = LocalStorage.getItem("project_permissions");
        const userTenantAccessPermission = permissions;
        userTenantAccessPermission._type = "UserTenantAccessPermission";
        return userTenantAccessPermission;
    }
    static projectPermissionsAsDropdownOptions() {
        const permissions = PermissionHelper.getTenantPermissionProps();
        const groupMap = new Map();
        for (const permissionProp of permissions) {
            const group = permissionProp.group;
            if (!groupMap.has(group)) {
                groupMap.set(group, []);
            }
            groupMap.get(group).push({
                value: permissionProp.permission,
                label: permissionProp.title,
            });
        }
        const groups = [];
        for (const [group, options] of groupMap) {
            groups.push({
                label: group,
                options,
            });
        }
        return groups;
    }
    static setGlobalPermissions(permissions) {
        LocalStorage.setItem("global_permissions", permissions);
    }
    static setProjectPermissions(permissions) {
        LocalStorage.setItem("project_permissions", permissions);
    }
    static clearProjectPermissions() {
        LocalStorage.setItem("project_permissions", null);
    }
}
//# sourceMappingURL=Permission.js.map