export const id=6520;export const ids=[6520];export const modules={6520:(i,e,a)=>{a.r(e),a.d(e,{DialogAddApplicationCredential:()=>_});var t=a(5461),n=(a(3981),a(8597)),s=a(196),o=a(3167),l=(a(1074),a(3279),a(6442),a(8762));a(5966),a(9373),a(6494);var d=a(1238),r=a(3799),c=a(1750);const h="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z",p=i=>n.qy`<mwc-list-item>
    <span>${i.name}</span>
  </mwc-list-item>`;let _=(0,t.A)([(0,s.EM)("dialog-add-application-credential")],(function(i,e){return{F:class extends e{constructor(...e){super(...e),i(this)}},d:[{kind:"field",decorators:[(0,s.MZ)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_loading",value(){return!1}},{kind:"field",decorators:[(0,s.wk)()],key:"_error",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_params",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_domain",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_manifest",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_name",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_description",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_clientId",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_clientSecret",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_domains",value:void 0},{kind:"field",decorators:[(0,s.wk)()],key:"_config",value:void 0},{kind:"method",key:"showDialog",value:function(i){this._params=i,this._domain=i.selectedDomain,this._manifest=i.manifest,this._name="",this._description="",this._clientId="",this._clientSecret="",this._error=void 0,this._loading=!1,this._fetchConfig()}},{kind:"method",key:"_fetchConfig",value:async function(){this._config=await(async i=>i.callWS({type:"application_credentials/config"}))(this.hass),this._domains=Object.keys(this._config.integrations).map((i=>({id:i,name:(0,d.p$)(this.hass.localize,i)}))),await this.hass.loadBackendTranslation("application_credentials"),this._updateDescription()}},{kind:"method",key:"render",value:function(){if(!this._params||!this._domains)return n.s6;const i=this._params.selectedDomain?(0,d.p$)(this.hass.localize,this._domain):"";return n.qy`
      <ha-dialog
        open
        @closed=${this._abortDialog}
        scrimClickAction
        escapeKeyAction
        .heading=${(0,l.l)(this.hass,this.hass.localize("ui.panel.config.application_credentials.editor.caption"))}
      >
        <div>
          ${this._error?n.qy`<ha-alert alert-type="error">${this._error}</ha-alert> `:""}
          ${this._params.selectedDomain&&!this._description?n.qy`<p>
                ${this.hass.localize("ui.panel.config.application_credentials.editor.missing_credentials",{integration:i})}
                ${this._manifest?.is_built_in||this._manifest?.documentation?n.qy`<a
                      href=${this._manifest.is_built_in?(0,c.o)(this.hass,`/integrations/${this._domain}`):this._manifest.documentation}
                      target="_blank"
                      rel="noreferrer"
                    >
                      ${this.hass.localize("ui.panel.config.application_credentials.editor.missing_credentials_domain_link",{integration:i})}
                      <ha-svg-icon .path=${h}></ha-svg-icon>
                    </a>`:""}
              </p>`:""}
          ${this._params.selectedDomain&&this._description?"":n.qy`<p>
                ${this.hass.localize("ui.panel.config.application_credentials.editor.description")}
                <a
                  href=${(0,c.o)(this.hass,"/integrations/application_credentials")}
                  target="_blank"
                  rel="noreferrer"
                >
                  ${this.hass.localize("ui.panel.config.application_credentials.editor.view_documentation")}
                  <ha-svg-icon .path=${h}></ha-svg-icon>
                </a>
              </p>`}
          ${this._params.selectedDomain?"":n.qy`<ha-combo-box
                name="domain"
                .hass=${this.hass}
                .label=${this.hass.localize("ui.panel.config.application_credentials.editor.domain")}
                .value=${this._domain}
                .renderer=${p}
                .items=${this._domains}
                item-id-path="id"
                item-value-path="id"
                item-label-path="name"
                required
                @value-changed=${this._handleDomainPicked}
              ></ha-combo-box>`}
          ${this._description?n.qy`<ha-markdown
                breaks
                .content=${this._description}
              ></ha-markdown>`:""}
          <ha-textfield
            class="name"
            name="name"
            .label=${this.hass.localize("ui.panel.config.application_credentials.editor.name")}
            .value=${this._name}
            required
            @input=${this._handleValueChanged}
            .validationMessage=${this.hass.localize("ui.common.error_required")}
            dialogInitialFocus
          ></ha-textfield>
          <ha-textfield
            class="clientId"
            name="clientId"
            .label=${this.hass.localize("ui.panel.config.application_credentials.editor.client_id")}
            .value=${this._clientId}
            required
            @input=${this._handleValueChanged}
            .validationMessage=${this.hass.localize("ui.common.error_required")}
            dialogInitialFocus
            .helper=${this.hass.localize("ui.panel.config.application_credentials.editor.client_id_helper")}
            helperPersistent
          ></ha-textfield>
          <ha-textfield
            .label=${this.hass.localize("ui.panel.config.application_credentials.editor.client_secret")}
            type="password"
            name="clientSecret"
            .value=${this._clientSecret}
            required
            @input=${this._handleValueChanged}
            .validationMessage=${this.hass.localize("ui.common.error_required")}
            .helper=${this.hass.localize("ui.panel.config.application_credentials.editor.client_secret_helper")}
            helperPersistent
          ></ha-textfield>
        </div>
        ${this._loading?n.qy`
              <div slot="primaryAction" class="submit-spinner">
                <ha-circular-progress indeterminate></ha-circular-progress>
              </div>
            `:n.qy`
              <ha-button slot="secondaryAction" @click=${this._abortDialog}>
                ${this.hass.localize("ui.common.cancel")}
              </ha-button>
              <ha-button
                slot="primaryAction"
                .disabled=${!this._domain||!this._clientId||!this._clientSecret}
                @click=${this._addApplicationCredential}
              >
                ${this.hass.localize("ui.panel.config.application_credentials.editor.add")}
              </ha-button>
            `}
      </ha-dialog>
    `}},{kind:"method",key:"closeDialog",value:function(){this._params=void 0,this._domains=void 0,(0,o.r)(this,"dialog-closed",{dialog:this.localName})}},{kind:"method",key:"_handleDomainPicked",value:function(i){i.stopPropagation(),this._domain=i.detail.value,this._updateDescription()}},{kind:"method",key:"_updateDescription",value:async function(){if(!this._domain)return;await this.hass.loadBackendTranslation("application_credentials",this._domain);const i=this._config.integrations[this._domain];this._description=this.hass.localize(`component.${this._domain}.application_credentials.description`,i.description_placeholders)}},{kind:"method",key:"_handleValueChanged",value:function(i){this._error=void 0;const e=i.target.name,a=i.target.value;this[`_${e}`]=a}},{kind:"method",key:"_abortDialog",value:function(){this._params&&this._params.dialogAbortedCallback&&this._params.dialogAbortedCallback(),this.closeDialog()}},{kind:"method",key:"_addApplicationCredential",value:async function(i){if(i.preventDefault(),!this._domain||!this._clientId||!this._clientSecret)return;let e;this._loading=!0,this._error="";try{e=await(async(i,e,a,t,n)=>i.callWS({type:"application_credentials/create",domain:e,client_id:a,client_secret:t,name:n}))(this.hass,this._domain,this._clientId,this._clientSecret,this._name)}catch(a){return this._loading=!1,void(this._error=a.message)}this._params.applicationCredentialAddedCallback(e),this.closeDialog()}},{kind:"get",static:!0,key:"styles",value:function(){return[r.nA,n.AH`
        ha-dialog {
          --mdc-dialog-max-width: 500px;
          --dialog-z-index: 10;
        }
        .row {
          display: flex;
          padding: 8px 0;
        }
        ha-combo-box {
          display: block;
          margin-bottom: 24px;
        }
        ha-textfield {
          display: block;
          margin-bottom: 24px;
        }
        a {
          text-decoration: none;
        }
        a ha-svg-icon {
          --mdc-icon-size: 16px;
        }
        ha-markdown {
          margin-bottom: 16px;
        }
      `]}}]}}),n.WF)}};
//# sourceMappingURL=gSOUD4-8.js.map