var p=Object.defineProperty;var u=(i,t)=>{for(var e in t)p(i,e,{get:t[e],enumerable:!0})};var h={};u(h,{PromptInputEvent:()=>o,TextPrompt:()=>r});import*as l from"./../../../core/platform/platform.js";import{html as c,render as g}from"./../../lit/lit.js";var a=`:host{white-space:pre;overflow:hidden;display:flex}input{font-size:var(--sys-typescale-body3-size)}.prefix{flex:none;font-weight:var(--ref-typeface-weight-medium);font-size:var(--sys-typescale-body3-size);color:var(--sys-color-primary)}.text-prompt-input{flex:auto;position:relative}.text-prompt-input input{width:100%;border:none;outline:none;position:absolute;left:0;padding:0;z-index:2;color:var(--sys-color-on-surface);background-color:transparent;line-height:var(--sys-typescale-body3-line-height)}.text-prompt-input .suggestion{color:var(--sys-color-on-surface-subtle);line-height:var(--sys-typescale-body3-line-height);position:absolute;left:0;z-index:1}
/*# sourceURL=${import.meta.resolve("./textPrompt.css")} */`;var o=class i extends Event{static eventName="promptinputchanged";data;constructor(t){super(i.eventName),this.data=t}},r=class extends HTMLElement{#r=this.attachShadow({mode:"open"});#e="";#s="";#i="";set data(t){this.#e=t.ariaLabel,this.#s=t.prefix,this.#i=t.suggestion,this.#a()}get data(){return{ariaLabel:this.#e,prefix:this.#s,suggestion:this.#i}}focus(){this.#t().focus()}#t(){let t=this.#r.querySelector(".input");if(!t)throw new Error("Expected an input element!");return t}moveCaretToEndOfInput(){this.setSelectedRange(this.#o().length,this.#o().length)}onKeyDown(t){t.key===l.KeyboardUtilities.ENTER_KEY&&t.preventDefault()}setSelectedRange(t,e){if(t<0)throw new RangeError("Selected range start must be a nonnegative integer");let s=this.#o().length;e>s&&(e=s),e<t&&(e=t),this.#t().setSelectionRange(t,e)}setPrefix(t){this.#s=t,this.#a()}setSuggestion(t){this.#i=t,this.#n().value=this.#i,this.#a()}setText(t){this.#t().value=t,this.#t().hasFocus()&&(this.moveCaretToEndOfInput(),this.#t().scrollIntoView())}#n(){let t=this.#r.querySelector(".suggestion");if(!t)throw new Error("Expected an suggestion element!");return t}#o(){return this.#t().value||""}connectedCallback(){new MutationObserver(e=>{for(let s of e)if(s.type==="attributes"&&s.attributeName==="dir"){let n=this.#t().getAttribute("dir");if(!n){this.#n().removeAttribute("dir");return}this.#n().setAttribute("dir",n)}}).observe(this.#t(),{attributeFilter:["dir"]})}#a(){let t=c`
      <style>${a}</style>
      <span class="prefix">${this.#s} </span>
      <span class="text-prompt-input">
        <input
            class="input" aria-label=${this.#e} spellcheck="false"
            @input=${()=>this.dispatchEvent(new o(this.#o()))}
            @keydown=${this.onKeyDown}>
        <input class="suggestion" tabindex=-1 aria-label=${this.#e+" Suggestion"}>
      </span>`;g(t,this.#r,{host:this})}};customElements.define("devtools-text-prompt",r);export{h as TextPrompt};
//# sourceMappingURL=text_prompt.js.map
