import { UMB_ENTITY_CONTEXT } from '../entity.context-token.js';
import { UmbConditionBase } from '../../extension-registry/index.js';
export class UmbEntityUniqueCondition extends UmbConditionBase {
    constructor(host, args) {
        super(host, args);
        this.consumeContext(UMB_ENTITY_CONTEXT, (context) => {
            this.observe(context?.unique, (unique) => this.#check(unique), 'umbEntityUniqueObserver');
        });
    }
    #check(value) {
        if (value === undefined) {
            this.permitted = false;
            return;
        }
        // if the config has a match, we only check that
        if (this.config.match !== undefined) {
            this.permitted = value === this.config.match;
            return;
        }
        this.permitted = this.config.oneOf?.some((configValue) => configValue === value) ?? false;
    }
}
export { UmbEntityUniqueCondition as api };
