import { UMB_USER_GROUP_DETAIL_REPOSITORY_ALIAS } from '../../repository/index.js';
import { UMB_USER_GROUP_ENTITY_TYPE, UMB_USER_GROUP_ROOT_ENTITY_TYPE } from '../../entity.js';
import { UmbUserGroupWorkspaceEditorElement } from './user-group-workspace-editor.element.js';
import { UMB_USER_GROUP_WORKSPACE_ALIAS } from './constants.js';
import { UmbEntityNamedDetailWorkspaceContextBase, UmbWorkspaceIsNewRedirectController, } from '../../../../core/workspace/index.js';
export class UmbUserGroupWorkspaceContext extends UmbEntityNamedDetailWorkspaceContextBase {
    constructor(host) {
        super(host, {
            workspaceAlias: UMB_USER_GROUP_WORKSPACE_ALIAS,
            entityType: UMB_USER_GROUP_ENTITY_TYPE,
            detailRepositoryAlias: UMB_USER_GROUP_DETAIL_REPOSITORY_ALIAS,
        });
        this.alias = this._data.createObservablePartOfCurrent((data) => data?.alias || '');
        this.aliasCanBeChanged = this._data.createObservablePartOfCurrent((data) => data?.aliasCanBeChanged);
        this.icon = this._data.createObservablePartOfCurrent((data) => data?.icon || null);
        this.sections = this._data.createObservablePartOfCurrent((data) => data?.sections || []);
        this.languages = this._data.createObservablePartOfCurrent((data) => data?.languages || []);
        this.hasAccessToAllLanguages = this._data.createObservablePartOfCurrent((data) => data?.hasAccessToAllLanguages || false);
        this.documentStartNode = this._data.createObservablePartOfCurrent((data) => data?.documentStartNode || null);
        this.documentRootAccess = this._data.createObservablePartOfCurrent((data) => data?.documentRootAccess || false);
        this.mediaStartNode = this._data.createObservablePartOfCurrent((data) => data?.mediaStartNode || null);
        this.mediaRootAccess = this._data.createObservablePartOfCurrent((data) => data?.mediaRootAccess || false);
        this.fallbackPermissions = this._data.createObservablePartOfCurrent((data) => data?.fallbackPermissions || []);
        this.permissions = this._data.createObservablePartOfCurrent((data) => data?.permissions || []);
        this.description = this._data.createObservablePartOfCurrent((data) => data?.description || '');
        this.routes.setRoutes([
            {
                path: 'create',
                component: UmbUserGroupWorkspaceEditorElement,
                setup: async () => {
                    await this.createScaffold({ parent: { entityType: UMB_USER_GROUP_ROOT_ENTITY_TYPE, unique: null } });
                    new UmbWorkspaceIsNewRedirectController(this, this, this.getHostElement().shadowRoot.querySelector('umb-router-slot'));
                },
            },
            {
                path: 'edit/:unique',
                component: UmbUserGroupWorkspaceEditorElement,
                setup: (component, info) => {
                    const unique = info.match.params.unique;
                    this.load(unique);
                },
            },
        ]);
    }
    updateProperty(alias, value) {
        this._data.updateCurrent({ [alias]: value });
    }
    /**
     * Gets the user group user permissions.
     * @memberof UmbUserGroupWorkspaceContext
     */
    getPermissions() {
        return this._data.getCurrent()?.permissions ?? [];
    }
    /**
     * Sets the user group user permissions.
     * @param {Array<UmbUserPermissionModel>} permissions
     * @memberof UmbUserGroupWorkspaceContext
     */
    setPermissions(permissions) {
        this._data.updateCurrent({ permissions: permissions });
    }
    /**
     * Gets the user group fallback permissions.
     * @memberof UmbUserGroupWorkspaceContext
     */
    getFallbackPermissions() {
        return this._data.getCurrent()?.fallbackPermissions ?? [];
    }
    /**
     * Sets the user group fallback permissions.
     * @param {Array<string>} fallbackPermissions
     * @memberof UmbUserGroupWorkspaceContext
     */
    setFallbackPermissions(fallbackPermissions) {
        this._data.updateCurrent({ fallbackPermissions });
    }
    /**
     * Sets the description
     * @param {string} description - The description
     * @memberof UmbUserGroupWorkspaceContext
     */
    setDescription(description) {
        this._data.updateCurrent({ description });
    }
}
export { UmbUserGroupWorkspaceContext as api };
