import{getRegisteredActionExtensions}from"./ActionRegistration.js";import{Context}from"./Context.js";let actionRegistryInstance;export class ActionRegistry{constructor(){this._actionsById=new Map,this._registerActions()}static instance(t={forceNew:null}){const{forceNew:n}=t;return actionRegistryInstance&&!n||(actionRegistryInstance=new ActionRegistry),actionRegistryInstance}static removeInstance(){actionRegistryInstance=void 0}_registerActions(){for(const t of getRegisteredActionExtensions())this._actionsById.set(t.id(),t),t.canInstantiate()||t.setEnabled(!1)}availableActions(){return this.applicableActions([...this._actionsById.keys()],Context.instance())}actions(){return[...this._actionsById.values()]}applicableActions(t,n){const e=[];for(const i of t){const t=this._actionsById.get(i);t&&t.enabled()&&s(t,n.flavors())&&e.push(t)}return e;function s(t,n){const e=t.contextTypes();if(!e)return!0;for(let s=0;s<e.length;++s){const t=e[s];if(Boolean(t)&&n.has(t))return!0}return!1}}action(t){return this._actionsById.get(t)||null}}