/*! For license information please see 5152.js.LICENSE.txt */
"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[5152],{45152:(e,i,t)=>{t.r(i);var n=t(50493),o=t(28362),a=t.n(o),r=t(16682),d=t(94430),s=t(56765),l=t(60438),c=t(28120),p=t(27805),u=t(77675),v=t(36179),f=t(51266);let g=class extends((0,c.$)(u.h)(u.B4)){get context(){return{title:{icon:"link",text:this.appbinding.name}}}render(){var e,i,t,n=this.appbinding||{},o=(null===(e=this.appbinding)||void 0===e?void 0:e.application)||{},a=null===(i=this._refreshTokenInfo)||void 0===i?void 0:i.exp,r=null===(t=this._accessTokenInfo)||void 0===t?void 0:t.exp;return d.dy`
      <div>
        <h2><mwc-icon>link</mwc-icon>&nbsp;${o.name}</h2>
        <p page-description>${o.description}</p>
      </div>

      ${o.icon?d.dy`
            <div icon>
              <img src=${o.icon} />
            </div>
          `:d.dy``}

      <form>
        <div fieldset-container>
          <fieldset>
            <legend>application</legend>
            <div field-2column>
              <div field grid-span>
                <label for="app-name">app name</label>
                <input id="app-name" type="text" .value=${o.name} readonly />
              </div>

              <div field grid-span>
                <label for="app-description">description</label>
                <input id="app-description" type="text" .value=${o.description} readonly />
              </div>

              <div field>
                <label for="contact-email">contact email</label>
                <input id="contact-email" type="text" .value=${o.email} readonly />
              </div>
            </div>
          </fieldset>
        </div>

        <div fieldset-container>
          <fieldset>
            <legend>binding</legend>
            <div field-2column>
              <div field grid-span>
                <label for="id">id</label>
                <input id="id" type="text" .value=${n.id} readonly />
              </div>

              <div field grid-span>
                <label for="name">name</label>
                <input id="name" type="text" .value=${n.email} readonly />
              </div>

              <div field>
                <label for="status">status</label>
                <input id="status" type="text" .value=${n.status} readonly />
              </div>

              <div field>
                <label for="scope">scope</label>
                <input id="scope" type="text" .value=${n.scope} readonly />
              </div>
            </div>
          </fieldset>
        </div>

        <div fieldset-container>
          <fieldset>
            <legend>binding credential</legend>
            <div field-2column>
              <div field grid-span>
                <label for="access-token">access token</label>
                <input id="access-token" type="text" .value=${this.accessToken||""} readonly />
                <button button-in-field clipboard-copy @click=${e=>e.preventDefault()}>copy</button>
                ${r?d.dy`<div input-hint>
                      expired in ${new Date(r).toLocaleString()} :
                      ${(0,l.E)(this.expTimer(r))}
                    </div>`:d.dy``}
              </div>

              <div field grid-span>
                <label for="refresh-token">refresh token</label>
                <input id="refresh-token" type="text" .value=${n.refreshToken||""} readonly />
                <button button-in-field clipboard-copy @click=${e=>e.preventDefault()}>copy</button>
                ${a?d.dy`<div input-hint>
                      expired in ${new Date(a).toLocaleString()} :
                      ${(0,l.E)(this.expTimer(a))}
                    </div>`:d.dy``}
              </div>
            </div>
          </fieldset>
        </div>

        <button @click=${this.deleteAppBinding.bind(this)}>delete this application binding</button>
        <button @click=${this.renewApplicationAccessToken.bind(this)}>renew access token</button>
      </form>
    `}expTimer(e){return(0,n.FC)(this,arguments,(function*(){for(;this.active;){var i=Math.floor(Number(e)-Date.now()/1e3);const t=Math.floor(i/86400);i-=86400*t;const o=Math.floor(i/3600);i-=3600*o;const a=Math.floor(i/60),r=i-60*a;yield yield(0,n.qq)(`${t} days ${o} hours ${a} mins ${r} seconds remain`),yield(0,n.qq)((0,v._v)(1e3))}}))}firstUpdated(){const e=this.renderRoot.querySelectorAll("[clipboard-copy]");this.clipboard=new(a())(e,{target:e=>e.parentElement.querySelector("input")})}updated(e){if(e.has("appbinding")){const{refreshToken:e}=this.appbinding||{};this._refreshTokenInfo=e?(0,v.aj)(e):{}}e.has("accessToken")&&(this._accessTokenInfo=this.accessToken?(0,v.aj)(this.accessToken):{})}async pageUpdated(e,i,t){this.active&&await this.fetchAppBinding()}async fetchAppBinding(){const e=await p.Lp.query({query:r.ZP`
        query ($id: String!) {
          appBinding(id: $id) {
            id
            name
            description
            email
            scope
            status
            application {
              id
              name
              description
              email
              icon
            }
            refreshToken
          }
        }
      `,variables:{id:this.lifecycle.resourceId}});this.appbinding=e.data.appBinding}async deleteAppBinding(e){e.preventDefault();const i=this.lifecycle.resourceId;(await p.Lp.mutate({mutation:r.ZP`
        mutation ($id: String!) {
          deleteAppBinding(id: $id)
        }
      `,variables:{id:i}})).data.deleteAppBinding?(f.log("delete sucess"),(0,u.c4)("app-bindings")):f.error("delete fail")}async renewApplicationAccessToken(e){e.preventDefault();const i=this.lifecycle.resourceId,t=await p.Lp.mutate({mutation:r.ZP`
        mutation ($id: String!) {
          renewApplicationAccessToken(id: $id) {
            accessToken
            refreshToken
          }
        }
      `,variables:{id:i}});if(t.errors)f.error("renew application access token fail");else{const{accessToken:e,refreshToken:i}=t.data.renewApplicationAccessToken;this.accessToken=e,this.appbinding=Object.assign(Object.assign({},this.appbinding),{refreshToken:i})}}};g.styles=[d.iv`
      :host {
        display: flex;
        flex-direction: column;
        overflow-y: auto;

        position: relative;

        background-color: var(--main-section-background-color);
        padding: var(--padding-wide);
      }
      h2 {
        margin: var(--title-margin);
        font: var(--title-font);
        color: var(--title-text-color);
      }
      [page-description] {
        margin: var(--page-description-margin);
        font: var(--page-description-font);
        color: var(--page-description-color);
      }
      [icon] {
        position: absolute;
        top: 10px;
        right: 10px;

        max-width: 80px;
      }
      [icon] img {
        max-width: 100%;
        max-height: 100%;
      }

      label {
        font: var(--label-font);
        color: var(--label-color);
        text-transform: var(--label-text-transform);
      }
      input {
        border: var(--border-dark-color);
        border-radius: var(--border-radius);
        margin: var(--input-margin);
        padding: var(--input-padding);
        font: var(--input-font);

        flex: 1;
      }
      select:focus,
      input:focus,
      button {
        outline: none;
      }
      form {
        max-width: var(--content-container-max-width);
      }
      [fieldset-container] {
        background-color: var(--theme-white-color);
        margin: var(--margin-wide) 0 var(--margin-default) 0;
        padding: var(--padding-default);
        border-radius: var(--border-radius);
        box-shadow: var(--box-shadow);
      }
      [fieldset-container] fieldset {
        margin: 0;
        margin-top: -15px;
      }
      fieldset {
        border-radius: var(--border-radius);
        border: var(--border-dark-color);
        margin: var(--fieldset-margin);
        padding: var(--fieldset-padding);
      }
      legend {
        padding: var(--legend-padding);
        font-weight: bold;
        color: var(--legend-color);
      }
      [field-2column] {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-gap: 15px;
      }
      [field] {
        display: flex;
        flex-direction: column;
        position: relative;
      }
      [grid-span] {
        grid-column: span 2;
      }
      button,
      [button-in-field] {
        background-color: var(--button-background-color);
        border: var(--button-border);
        border-radius: var(--button-border-radius);
        padding: var(--button-padding);
        color: var(--button-color);
        font: var(--button-font);
        text-transform: var(--button-text-transform);

        margin: var(--margin-default) 0 var(--margin-default) var(--margin-default);
        float: right;
        text-decoration: none;
      }
      button:hover {
        border: var(--button-activ-border);
        box-shadow: var(--button-active-box-shadow);
      }
      [button-in-field] {
        border-radius: 0 var(--button-border-radius) var(--button-border-radius) 0;
        position: absolute;
        top: 11px;
        right: 0;
        max-height: 36px;
      }
      [input-hint] {
        font: var(--input-hint-font);
        color: var(--input-hint-color);
      }
      @media screen and (max-width: 480px) {
        [field] {
          grid-column: span 2;
        }
      }
    `],(0,n.gn)([(0,s.Cb)({type:Object}),(0,n.w6)("design:type",Object)],g.prototype,"appbinding",void 0),(0,n.gn)([(0,s.Cb)({type:String}),(0,n.w6)("design:type",String)],g.prototype,"accessToken",void 0),(0,n.gn)([(0,s.SB)(),(0,n.w6)("design:type",Object)],g.prototype,"_refreshTokenInfo",void 0),(0,n.gn)([(0,s.SB)(),(0,n.w6)("design:type",Object)],g.prototype,"_accessTokenInfo",void 0),g=(0,n.gn)([(0,s.Mo)("app-binding-page")],g)},60438:(e,i,t)=>{t.d(i,{E:()=>l});var n=t(28773),o=t(95974);class a{constructor(e){this.G=e}disconnect(){this.G=void 0}reconnect(e){this.G=e}deref(){return this.G}}class r{constructor(){this.Y=void 0,this.Z=void 0}get(){return this.Y}pause(){var e;null!==(e=this.Y)&&void 0!==e||(this.Y=new Promise((e=>this.Z=e)))}resume(){var e;null===(e=this.Z)||void 0===e||e.call(this),this.Y=this.Z=void 0}}var d=t(62987);class s extends o.sR{constructor(){super(...arguments),this._$Cq=new a(this),this._$CK=new r}render(e,i){return n.Jb}update(e,[i,t]){if(this.isConnected||this.disconnected(),i===this._$CX)return;this._$CX=i;let o=0;const{_$Cq:a,_$CK:r}=this;return(async(e,i)=>{for await(const t of e)if(!1===await i(t))return})(i,(async e=>{for(;r.get();)await r.get();const n=a.deref();if(void 0!==n){if(n._$CX!==i)return!1;void 0!==t&&(e=t(e,o)),n.commitValue(e,o),o++}return!0})),n.Jb}commitValue(e,i){this.setValue(e)}disconnected(){this._$Cq.disconnect(),this._$CK.pause()}reconnected(){this._$Cq.reconnect(this),this._$CK.resume()}}const l=(0,d.XM)(s)}}]);