import*as Host from"../../../core/host/host.js";import*as i18n from"../../../core/i18n/i18n.js";import*as ComponentHelpers from"../../../ui/components/helpers/helpers.js";import*as LitHtml from"../../../ui/lit-html/lit-html.js";import{SelectButton}from"./SelectButton.js";const UIStrings={ReplayNormalButtonLabel:"Replay",ReplayNormalItemLabel:"Normal (Default)",ReplaySlowButtonLabel:"Slow replay",ReplaySlowItemLabel:"Slow",ReplayVerySlowButtonLabel:"Very slow replay",ReplayVerySlowItemLabel:"Very slow",ReplayExtremelySlowButtonLabel:"Extremely slow replay",ReplayExtremelySlowItemLabel:"Extremely slow",speedGroup:"Speed",extensionGroup:"Extensions"},items=[{value:"normal",buttonIconName:"play",buttonLabel:()=>i18nString(UIStrings.ReplayNormalButtonLabel),label:()=>i18nString(UIStrings.ReplayNormalItemLabel)},{value:"slow",buttonIconName:"play",buttonLabel:()=>i18nString(UIStrings.ReplaySlowButtonLabel),label:()=>i18nString(UIStrings.ReplaySlowItemLabel)},{value:"very_slow",buttonIconName:"play",buttonLabel:()=>i18nString(UIStrings.ReplayVerySlowButtonLabel),label:()=>i18nString(UIStrings.ReplayVerySlowItemLabel)},{value:"extremely_slow",buttonIconName:"play",buttonLabel:()=>i18nString(UIStrings.ReplayExtremelySlowButtonLabel),label:()=>i18nString(UIStrings.ReplayExtremelySlowItemLabel)}],replaySpeedToMetricSpeedMap={normal:Host.UserMetrics.RecordingReplaySpeed.Normal,slow:Host.UserMetrics.RecordingReplaySpeed.Slow,very_slow:Host.UserMetrics.RecordingReplaySpeed.VerySlow,extremely_slow:Host.UserMetrics.RecordingReplaySpeed.ExtremelySlow},str_=i18n.i18n.registerUIStrings("panels/recorder/components/ReplayButton.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class StartReplayEvent extends Event{speed;extension;static eventName="startreplay";constructor(e,t){super(StartReplayEvent.eventName,{bubbles:!0,composed:!0}),this.speed=e,this.extension=t}}const REPLAY_EXTENSION_PREFIX="extension";export class ReplayButton extends HTMLElement{static litTagName=LitHtml.literal`devtools-replay-button`;#e=this.attachShadow({mode:"open"});#t=this.#n.bind(this);#s={disabled:!1};#l;#o=[];set data(e){this.#l=e.settings,this.#o=e.replayExtensions}get disabled(){return this.#s.disabled}set disabled(e){this.#s.disabled=e,ComponentHelpers.ScheduledRender.scheduleRender(this,this.#t)}connectedCallback(){ComponentHelpers.ScheduledRender.scheduleRender(this,this.#t)}#r(e){if(e.stopPropagation(),e.value.startsWith("extension")){this.#l&&(this.#l.replayExtension=e.value);const t=Number(e.value.substring(9));return this.dispatchEvent(new StartReplayEvent("normal",this.#o[t])),void ComponentHelpers.ScheduledRender.scheduleRender(this,this.#t)}const t=e.value;this.#l&&(this.#l.speed=t,this.#l.replayExtension=""),Host.userMetrics.recordingReplaySpeed(replaySpeedToMetricSpeedMap[t]),this.dispatchEvent(new StartReplayEvent(e.value)),ComponentHelpers.ScheduledRender.scheduleRender(this,this.#t)}#n(){const e=[{name:i18nString(UIStrings.speedGroup),items:items}];this.#o.length&&e.push({name:i18nString(UIStrings.extensionGroup),items:this.#o.map(((e,t)=>({value:"extension"+t,buttonIconName:"play",buttonLabel:()=>e.getName(),label:()=>e.getName()})))}),LitHtml.render(LitHtml.html`
    <${SelectButton.litTagName}
      @selectbuttonclick=${this.#r}
      .variant=${"primary"}
      .showItemDivider=${!1}
      .disabled=${this.#s.disabled}
      .action=${"chrome_recorder.replay-recording"}
      .value=${this.#l?.replayExtension||this.#l?.speed}
      .groups=${e}>
    </${SelectButton.litTagName}>`,this.#e,{host:this})}}ComponentHelpers.CustomElements.defineComponent("devtools-replay-button",ReplayButton);