import*as Common from"../../../core/common/common.js";import*as LitHtml from"../../lit-html/lit-html.js";import*as i18n from"../../../core/i18n/i18n.js";import*as ComponentHelpers from"../../components/helpers/helpers.js";import*as IconButton from"../icon_button/icon_button.js";import surveyLinkStyles from"./surveyLink.css.js";const UIStrings={openingSurvey:"Opening survey …",thankYouForYourFeedback:"Thank you for your feedback",anErrorOccurredWithTheSurvey:"An error occurred with the survey"},str_=i18n.i18n.registerUIStrings("ui/components/survey_link/SurveyLink.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class SurveyLink extends HTMLElement{static litTagName=LitHtml.literal`devtools-survey-link`;#t=this.attachShadow({mode:"open"});#e="";#i=Common.UIString.LocalizedEmptyString;#n=()=>{};#r=()=>{};#s="Checking";connectedCallback(){this.#t.adoptedStyleSheets=[surveyLinkStyles]}set data(t){this.#e=t.trigger,this.#i=t.promptText,this.#n=t.canShowSurvey,this.#r=t.showSurvey,this.#o()}#o(){this.#s="Checking",this.#n(this.#e,(({canShowSurvey:t})=>{this.#s=t?"ShowLink":"DontShowLink",this.#h()}))}#a(){this.#s="Sending",this.#h(),this.#r(this.#e,(({surveyShown:t})=>{this.#s=t?"SurveyShown":"Failed",this.#h()}))}#h(){if("Checking"===this.#s||"DontShowLink"===this.#s)return;let t=this.#i;"Sending"===this.#s?t=i18nString(UIStrings.openingSurvey):"SurveyShown"===this.#s?t=i18nString(UIStrings.thankYouForYourFeedback):"Failed"===this.#s&&(t=i18nString(UIStrings.anErrorOccurredWithTheSurvey));let e="";"Sending"===this.#s?e="pending-link":"Failed"!==this.#s&&"SurveyShown"!==this.#s||(e="disabled-link");const i="ShowLink"!==this.#s,n=LitHtml.html`
      <button class="link ${e}" tabindex=${i?"-1":"0"} .disabled=${i} aria-disabled=${i} @click=${this.#a}>
        <${IconButton.Icon.Icon.litTagName} class="link-icon" .data=${{iconName:"review",color:"var(--color-link)",width:"var(--issue-link-icon-size, 16px)",height:"var(--issue-link-icon-size, 16px)"}}></${IconButton.Icon.Icon.litTagName}><!--
      -->${t}
      </button>
    `;LitHtml.render(n,this.#t,{host:this})}}ComponentHelpers.CustomElements.defineComponent("devtools-survey-link",SurveyLink);