import { UMB_USER_WORKSPACE_CONTEXT } from '../workspace/user/user-workspace.context-token.js';
import { isCurrentUser } from '../../current-user/index.js';
import { UmbConditionBase } from '../../../core/extension-registry/index.js';
import { observeMultiple } from '../../../../libs/observable-api/index.js';
export class UmbUserActionConditionBase extends UmbConditionBase {
    /**
     * Creates an instance of UmbUserActionConditionBase.
     * @param {UmbControllerHost} host The host controller
     * @param {UmbConditionControllerArguments<UmbConditionConfigBase>} args The condition arguments
     * @memberof UmbUserActionConditionBase
     */
    constructor(host, args) {
        super(host, args);
        this.consumeContext(UMB_USER_WORKSPACE_CONTEXT, (context) => {
            if (context) {
                this.observe(observeMultiple([context.unique, context.state, context.kind]), ([unique, state, kind]) => {
                    this.userUnique = unique ?? undefined;
                    this.userState = state;
                    this.userKind = kind;
                    this._onUserDataChange();
                }, '_umbActiveUser');
            }
            else {
                this.removeUmbControllerByAlias('_umbActiveUser');
            }
        });
    }
    /**
     * Check if the current user is the same as the user being edited
     * @protected
     * @returns {Promise<boolean>}
     * @memberof UmbUserActionConditionBase
     */
    async isCurrentUser() {
        return this.userUnique ? isCurrentUser(this._host, this.userUnique) : false;
    }
}
