import*as Common from"../common/common.js";import*as Root from"../root/root.js";import{Context}from"./Context.js";export class Action extends Common.ObjectWrapper.ObjectWrapper{constructor(t){super(),this._enabled=!0,this._toggled=!1,this.actionRegistration=t}id(){return this.actionRegistration.actionId}async execute(){if(!this.actionRegistration.loadActionDelegate)return!1;const t=await this.actionRegistration.loadActionDelegate(),e=this.id();return t.handleAction(Context.instance(),e)}icon(){return this.actionRegistration.iconClass}toggledIcon(){return this.actionRegistration.toggledIconClass}toggleWithRedColor(){return Boolean(this.actionRegistration.toggleWithRedColor)}setEnabled(t){this._enabled!==t&&(this._enabled=t,this.dispatchEventToListeners(Events.Enabled,t))}enabled(){return this._enabled}category(){return this.actionRegistration.category}tags(){if(this.actionRegistration.tags)return this.actionRegistration.tags.map((t=>t())).join("\0")}toggleable(){return Boolean(this.actionRegistration.toggleable)}title(){let t=this.actionRegistration.title?this.actionRegistration.title():"";const e=this.actionRegistration.options;if(e)for(const o of e)o.value!==this._toggled&&(t=o.title());return t}toggled(){return this._toggled}setToggled(t){console.assert(this.toggleable(),"Shouldn't be toggling an untoggleable action",this.id()),this._toggled!==t&&(this._toggled=t,this.dispatchEventToListeners(Events.Toggled,t))}options(){return this.actionRegistration.options}contextTypes(){if(this.actionRegistration.contextTypes)return this.actionRegistration.contextTypes()}canInstantiate(){return Boolean(this.actionRegistration.loadActionDelegate)}bindings(){return this.actionRegistration.bindings}experiment(){return this.actionRegistration.experiment}condition(){return this.actionRegistration.condition}order(){return this.actionRegistration.order}}const registeredActionExtensions=[],actionIdSet=new Set;export function registerActionExtension(t){const e=t.actionId;if(actionIdSet.has(e))throw new Error(`Duplicate Action id '${e}': ${(new Error).stack}`);actionIdSet.add(e),registeredActionExtensions.push(new Action(t))}export function getRegisteredActionExtensions(){return registeredActionExtensions.filter((t=>Root.Runtime.Runtime.isDescriptorEnabled({experiment:t.experiment(),condition:t.condition()}))).sort(((t,e)=>(t.order()||0)-(e.order()||0)))}export const Events={Enabled:Symbol("Enabled"),Toggled:Symbol("Toggled")};export const ActionCategory={ELEMENTS:"Elements",SCREENSHOT:"Screenshot",NETWORK:"Network",MEMORY:"Memory",JAVASCRIPT_PROFILER:"JavaScript Profiler",CONSOLE:"Console",PERFORMANCE:"Performance",MOBILE:"Mobile",SENSORS:"Sensors",HELP:"Help",INPUTS:"Inputs",LAYERS:"Layers",NAVIGATION:"Navigation",DRAWER:"Drawer",GLOBAL:"Global",RESOURCES:"Resources",BACKGROUND_SERVICES:"Background Services",SETTINGS:"Settings",DEBUGGER:"Debugger",RECORDER:"Recorder",SOURCES:"Sources"};