import { UMB_PROPERTY_STRUCTURE_WORKSPACE_CONTEXT } from '../../contexts/property-structure-workspace.context-token.js';
import { UmbConditionBase } from '../../../../core/extension-registry/index.js';
const ObserveSymbol = Symbol();
/**
 * Condition to apply workspace extension based on a content type unique (GUID)
 */
export class UmbWorkspaceContentTypeUniqueCondition extends UmbConditionBase {
    constructor(host, args) {
        super(host, args);
        let permissionCheck = undefined;
        if (this.config.match) {
            permissionCheck = (contentTypeUniques) => contentTypeUniques.includes(this.config.match);
        }
        else if (this.config.oneOf) {
            permissionCheck = (contentTypeUniques) => contentTypeUniques.some((item) => this.config.oneOf.includes(item));
        }
        if (permissionCheck !== undefined) {
            this.consumeContext(UMB_PROPERTY_STRUCTURE_WORKSPACE_CONTEXT, (context) => {
                this.observe(context?.structure.contentTypeUniques, (contentTypeUniques) => {
                    const result = contentTypeUniques ? permissionCheck(contentTypeUniques) : false;
                    this.permitted = result;
                }, ObserveSymbol);
            });
        }
        else {
            throw new Error('Condition `Umb.Condition.WorkspaceContentTypeUnique` could not be initialized properly. Either "match" or "oneOf" must be defined');
        }
    }
}
