var q=Object.defineProperty;var R=(r,e)=>{for(var t in e)q(r,t,{get:e[t],enumerable:!0})};var k={};R(k,{RequestLinkIcon:()=>n,extractShortPath:()=>m});import"./../../kit/kit.js";import*as a from"./../../../core/common/common.js";import*as u from"./../../../core/i18n/i18n.js";import*as c from"./../../../panels/network/forward/forward.js";import*as f from"./../render_coordinator/render_coordinator.js";import*as i from"./../../lit/lit.js";import*as p from"./../../visual_logging/visual_logging.js";var d=`:host{display:inline-block;white-space:nowrap;color:inherit;font-size:inherit;font-family:inherit}:host([hidden]){display:none}button{border:none;background:transparent;margin:0;padding:0;font-family:inherit;font-size:inherit;color:inherit;&.link{cursor:pointer;& > span{color:var(--sys-color-primary)}}}devtools-icon{width:16px;height:16px;vertical-align:middle;color:var(--icon-no-request);.link > &{color:var(--icon-link)}}@media (forced-colors: active){devtools-icon{color:ButtonText}}
/*# sourceURL=${import.meta.resolve("./requestLinkIcon.css")} */`;var{html:o}=i,s={clickToShowRequestInTheNetwork:"Click to open the network panel and show request for URL: {url}",requestUnavailableInTheNetwork:"Request unavailable in the network panel, try reloading the inspected page",shortenedURL:"Shortened URL"},g=u.i18n.registerUIStrings("ui/components/request_link_icon/RequestLinkIcon.ts",s),h=u.i18n.getLocalizedString.bind(void 0,g),m=r=>(/[^/]+$/.exec(r)||/[^/]+\/$/.exec(r)||[""])[0],n=class extends HTMLElement{#u=this.attachShadow({mode:"open"});#n;#e;#t;#r;#l=!1;#o;#h;#s;#a;#i=a.Revealer.reveal;set data(e){if(this.#n=e.linkToPreflight,this.#e=e.request,e.affectedRequest&&(this.#s={...e.affectedRequest}),this.#t=e.highlightHeader,this.#h=e.networkTab,this.#r=e.requestResolver,this.#l=e.displayURL??!1,this.#o=e.urlToDisplay,this.#a=e.additionalOnClickAction,e.revealOverride&&(this.#i=e.revealOverride),!this.#e&&typeof e.affectedRequest?.requestId<"u"){if(!this.#r)throw new Error("A `RequestResolver` must be provided if an `affectedRequest` is provided.");this.#r.waitFor(e.affectedRequest.requestId).then(t=>(this.#e=t,this.#c())).catch(()=>{this.#e=null})}this.#c()}get data(){return{linkToPreflight:this.#n,request:this.#e,affectedRequest:this.#s,highlightHeader:this.#t,networkTab:this.#h,requestResolver:this.#r,displayURL:this.#l,urlToDisplay:this.#o,additionalOnClickAction:this.#a,revealOverride:this.#i!==a.Revealer.reveal?this.#i:void 0}}handleClick(e){if(e.button!==0)return;let t=this.#n?this.#e?.preflightRequest():this.#e;if(t){if(this.#t){let l=c.UIRequestLocation.UIRequestLocation.header(t,this.#t.section,this.#t.name);this.#i(l)}else{let l=c.UIRequestLocation.UIRequestLocation.tab(t,this.#h??"headers-component");this.#i(l)}this.#a?.(),e.consume()}}#d(){return this.#e?h(s.clickToShowRequestInTheNetwork,{url:this.#e.url()}):h(s.requestUnavailableInTheNetwork)}#f(){if(this.#l)return this.#e?this.#e.url():this.#s?.url}#p(){let e=this.#f();if(!e)return i.nothing;if(this.#o)return o`<span title=${e}>${this.#o}</span>`;let t=m(e);return o`<span aria-label=${h(s.shortenedURL)} title=${e}>${t}</span>`}async#c(){return await f.write(()=>{let e=this.#p();(this.#e||this.#s?.requestId!==void 0)&&(e=o`
          <button class=${i.Directives.classMap({link:!!this.#e})}
                  title=${this.#d()}
                  jslog=${p.link("request").track({click:!0})}
                  @click=${this.handleClick}>
            <devtools-icon name="arrow-up-down-circle"></devtools-icon>
            ${e}
          </button>`),i.render(o`<style>${d}</style>${e}`,this.#u,{host:this})})}};customElements.define("devtools-request-link-icon",n);export{k as RequestLinkIcon};
//# sourceMappingURL=request_link_icon.js.map
