import { UMB_CURRENT_USER_CONTEXT } from '../../../user/current-user/index.js';
import { UmbConditionBase } from '../../../core/extension-registry/index.js';
export class UmbLanguageUserPermissionCondition extends UmbConditionBase {
    constructor(host, args) {
        super(host, args);
        this.consumeContext(UMB_CURRENT_USER_CONTEXT, (context) => {
            this.observe(context?.currentUser, (currentUser) => {
                this.#check(currentUser);
            }, 'umbLanguageUserPermissionConditionObserver');
        });
    }
    #check(currentUser) {
        if (currentUser?.hasAccessToAllLanguages) {
            this.permitted = true;
            return;
        }
        const cultures = currentUser?.languages ?? [];
        /* we default to true se we don't require both allOf and oneOf to be defined
         but they can be combined for more complex scenarios */
        let allOfPermitted = true;
        let oneOfPermitted = true;
        // check if all of the verbs are present
        if (this.config.allOf?.length) {
            allOfPermitted = this.config.allOf.every((verb) => cultures.includes(verb));
        }
        // check if at least one of the verbs is present
        if (this.config.oneOf?.length) {
            oneOfPermitted = this.config.oneOf.some((verb) => cultures.includes(verb));
        }
        this.permitted = allOfPermitted && oneOfPermitted;
    }
}
export { UmbLanguageUserPermissionCondition as api };
