import*as Platform from"../../../core/platform/platform.js";import*as ComponentHelpers from"../../components/helpers/helpers.js";import*as LitHtml from"../../lit-html/lit-html.js";import textPromptStyles from"./textPrompt.css.js";export class PromptInputEvent extends Event{static eventName="promptinputchanged";data;constructor(t){super(PromptInputEvent.eventName),this.data=t}}export class TextPrompt extends HTMLElement{static litTagName=LitHtml.literal`devtools-text-prompt`;#t=this.attachShadow({mode:"open"});#e="";#s="";#i="";connectedCallback(){this.#t.adoptedStyleSheets=[textPromptStyles]}set data(t){this.#e=t.ariaLabel,this.#s=t.prefix,this.#i=t.suggestion,this.#n()}get data(){return{ariaLabel:this.#e,prefix:this.#s,suggestion:this.#i}}focus(){this.#o().focus()}#o(){const t=this.#t.querySelector(".input");if(!t)throw new Error("Expected an input element!");return t}moveCaretToEndOfInput(){this.setSelectedRange(this.#r().length,this.#r().length)}onInput(){this.#a().value=this.#r(),this.dispatchEvent(new PromptInputEvent(this.#r()))}onKeyDown(t){t.key===Platform.KeyboardUtilities.ENTER_KEY&&t.preventDefault()}setSelectedRange(t,e){if(t<0)throw new RangeError("Selected range start must be a nonnegative integer");const s=this.#r().length;e>s&&(e=s),e<t&&(e=t),this.#o().setSelectionRange(t,e)}setPrefix(t){this.#s=t,this.#n()}setSuggestion(t){this.#i=t,this.#a().value+=this.#i,this.#n()}setText(t){this.#o().value=t,this.#a().value=this.#r(),this.#o().hasFocus()&&(this.moveCaretToEndOfInput(),this.#o().scrollIntoView())}#a(){const t=this.#t.querySelector(".suggestion");if(!t)throw new Error("Expected an suggestion element!");return t}#r(){return this.#o().value||""}#n(){const t=LitHtml.html`
      <span class="prefix">${this.#s} </span>
      <span class="text-prompt-input"><input class="input" aria-label=${this.#e} spellcheck="false" @input=${this.onInput} @keydown=${this.onKeyDown}/><input class="suggestion" aria-label=${this.#e+" Suggestion"}></span>`;LitHtml.render(t,this.#t,{host:this})}}ComponentHelpers.CustomElements.defineComponent("devtools-text-prompt",TextPrompt);