import { UMB_WORKSPACE_CONTEXT } from '../../workspace.context-token.js';
import { UMB_WORKSPACE_CONDITION_ALIAS } from './constants.js';
import { UmbConditionBase } from '../../../extension-registry/index.js';
export class UmbWorkspaceAliasCondition extends UmbConditionBase {
    constructor(host, args) {
        super(host, args);
        let permissionCheck = undefined;
        if (this.config.match) {
            permissionCheck = (context) => context.workspaceAlias === this.config.match;
        }
        else if (this.config.oneOf) {
            permissionCheck = (context) => this.config.oneOf.indexOf(context.workspaceAlias) !== -1;
        }
        if (permissionCheck !== undefined) {
            this.consumeContext(UMB_WORKSPACE_CONTEXT, (context) => {
                if (context) {
                    this.permitted = permissionCheck(context);
                }
                else {
                    this.permitted = false;
                }
            });
        }
        else {
            throw new Error(`Condition [UMB_WORKSPACE_CONDITION_ALIAS] (${UMB_WORKSPACE_CONDITION_ALIAS}) could not be initialized properly. Either "match" or "oneOf" must be defined.`);
        }
    }
}
