import { UMB_SUBMITTABLE_WORKSPACE_CONTEXT } from '../../../../contexts/tokens/index.js';
import { UmbWorkspaceActionBase } from '../../workspace-action-base.controller.js';
export class UmbSubmitWorkspaceAction extends UmbWorkspaceActionBase {
    constructor(host, args) {
        super(host, args);
        // TODO: Could we make change label depending on the state? [NL]
        this._retrieveWorkspaceContext = this.consumeContext(args.workspaceContextToken ?? UMB_SUBMITTABLE_WORKSPACE_CONTEXT, (context) => {
            this._workspaceContext = context;
            this.#observeUnique();
            this._gotWorkspaceContext();
        }).asPromise();
    }
    #observeUnique() {
        this.observe(this._workspaceContext?.unique, (unique) => {
            // We can't save if we don't have a unique
            if (unique === undefined) {
                this.disable();
            }
            else {
                // Dangerous, cause this could enable despite a class extension decided to disable it?. [NL]
                this.enable();
            }
        }, 'saveWorkspaceActionUniqueObserver');
    }
    _gotWorkspaceContext() {
        // Override in subclass
    }
    async execute() {
        await this._retrieveWorkspaceContext;
        return await this._workspaceContext.requestSubmit();
    }
}
