import*as i18n from"../../../core/i18n/i18n.js";import*as Common from"../../../core/common/common.js";import*as ComponentHelpers from"../../../ui/components/helpers/helpers.js";import*as IconButton from"../../../ui/components/icon_button/icon_button.js";import*as LitHtml from"../../../ui/lit-html/lit-html.js";import*as IssuesManager from"../../../models/issues_manager/issues_manager.js";import*as Coordinator from"../../../ui/components/render_coordinator/render_coordinator.js";import IssueLinkIconStyles from"./issueLinkIcon.css.js";import{getIssueKindIconData}from"./IssueCounter.js";const UIStrings={clickToShowIssue:"Click to show issue in the issues tab",clickToShowIssueWithTitle:"Click to open the issue tab and show issue: {title}",issueUnavailable:"Issue unavailable at this time"},str_=i18n.i18n.registerUIStrings("ui/components/issue_counter/IssueLinkIcon.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export const extractShortPath=s=>(/[^/]+$/.exec(s)||/[^/]+\/$/.exec(s)||[""])[0];const coordinator=Coordinator.RenderCoordinator.RenderCoordinator.instance();export class IssueLinkIcon extends HTMLElement{static litTagName=LitHtml.literal`devtools-issue-link-icon`;#s=this.attachShadow({mode:"open"});#e;#i=null;#t=Promise.resolve(void 0);#o;#n;#r;#l=Common.Revealer.reveal;#a=Promise.resolve(void 0);set data(s){if(this.#e=s.issue,this.#o=s.issueId,!this.#e&&!this.#o)throw new Error("Either `issue` or `issueId` must be provided");this.#n=s.issueResolver,this.#r=s.additionalOnClickAction,s.revealOverride&&(this.#l=s.revealOverride),!this.#e&&this.#o?(this.#a=this.#u(this.#o),this.#t=this.#a.then((()=>this.#h()))):this.#t=this.#h(),this.#c()}async#h(){const s=this.#e?.getDescription();if(!s)return;const e=await IssuesManager.MarkdownIssueDescription.getIssueTitleFromMarkdownDescription(s);e&&(this.#i=e)}connectedCallback(){this.#s.adoptedStyleSheets=[IssueLinkIconStyles]}#u(s){if(!this.#n)throw new Error("An `IssueResolver` must be provided if an `issueId` is provided.");return this.#n.waitFor(s).then((s=>{this.#e=s})).catch((()=>{this.#e=null}))}get data(){return{issue:this.#e,issueId:this.#o,issueResolver:this.#n,additionalOnClickAction:this.#r,revealOverride:this.#l!==Common.Revealer.reveal?this.#l:void 0}}iconData(){return this.#e?{...getIssueKindIconData(this.#e.getKind()),width:"16px",height:"16px"}:{iconName:"issue-questionmark-filled",color:"var(--icon-default)",width:"16px",height:"16px"}}handleClick(s){0===s.button&&(this.#e&&this.#l(this.#e),this.#r?.())}#d(){return this.#i?i18nString(UIStrings.clickToShowIssueWithTitle,{title:this.#i}):this.#e?i18nString(UIStrings.clickToShowIssue):i18nString(UIStrings.issueUnavailable)}#c(){return coordinator.write((()=>{LitHtml.render(LitHtml.html`
        ${LitHtml.Directives.until(this.#t.then((()=>this.#m())),this.#a.then((()=>this.#m())),this.#m())}
      `,this.#s,{host:this})}))}#m(){return LitHtml.html`
      <span class=${LitHtml.Directives.classMap({link:Boolean(this.#e)})}
            tabindex="0"
            @click=${this.handleClick}>
        <${IconButton.Icon.Icon.litTagName} .data=${this.iconData()}
          title=${this.#d()}></${IconButton.Icon.Icon.litTagName}>
      </span>`}}ComponentHelpers.CustomElements.defineComponent("devtools-issue-link-icon",IssueLinkIcon);