"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[9449],{39449:(t,e,i)=>{i.r(e),i.d(e,{AuthProviderManagementPage:()=>f});var r=i(50493),s=i(68784),o=i(16682),a=i(94430),n=i(56765),d=i(28120),l=i(27805),p=i(53421),c=i(37077),h=i(77675),u=i(15633),g=i(36179),y=i(64312),m=i(88704);let f=class extends((0,d.$)(h.h)((0,p.NC)(p.z2)(h.B4))){constructor(){super(...arguments),this.mode=(0,g.s2)()?"CARD":"GRID",this.authProviderTypes=[]}get context(){var t;return{title:p.z2.t("title.auth-provider"),search:{handler:t=>{this.grist.searchText=t},value:(null===(t=this.grist)||void 0===t?void 0:t.searchText)||""},filter:{handler:()=>{this.grist.toggleHeadroom()}},actions:[Object.assign({title:p.z2.t("button.save"),action:this.updateAuthProvider.bind(this)},u.jO.save),Object.assign({title:p.z2.t("button.delete"),action:this.deleteAuthProvider.bind(this)},u.jO.delete)]}}render(){const t=this.mode||((0,g.s2)()?"CARD":"GRID");return a.dy`
      <ox-grist
        .mode=${t}
        .config=${this.gristConfig}
        .fetchHandler=${this.fetchHandler.bind(this)}
        ?url-params-sensitive=${this.active}
      >
        <div slot="headroom">
          <div id="filters">
            <ox-filters-form autofocus without-search></ox-filters-form>
          </div>

          <div id="sorters">
            Sort
            <mwc-icon
              @click=${t=>{const e=t.currentTarget;this.sortersControl.open({right:0,top:e.offsetTop+e.offsetHeight})}}
              >expand_more</mwc-icon
            >
            <ox-popup id="sorter-control">
              <ox-sorters-control> </ox-sorters-control>
            </ox-popup>
          </div>
        </div>
      </ox-grist>
    `}async pageInitialized(t){this.gristConfig={list:{fields:["entity","description"]},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"gutter",gutterName:"button",title:p.z2.t("title.auth-provider"),icon:"sync",handlers:{click:(t,e,i,r,s)=>{r.id&&this.synchronizeUsers(r.id)}}},{type:"select",name:"type",header:p.z2.t("field.type"),record:{editable:!0,options:()=>["",...this.authProviderTypes.map((({type:t})=>t))]},filter:"search",sortable:!0,width:150},{type:"boolean",name:"active",header:p.z2.t("field.active"),record:{editable:!0},sortable:!0,width:150},{type:"string",name:"tenantId",header:p.z2.t("field.tenant-id"),record:{editable:!0},width:200},{type:"string",name:"clientId",header:p.z2.t("field.client-id"),record:{editable:!0},width:200},{type:"string",name:"clientSecret",header:p.z2.t("field.client-secret"),record:{editable:!0},width:200},{type:"string",name:"privateKey",header:p.z2.t("field.private-key"),record:{editable:!0},width:200},{type:"parameters",name:"params",header:p.z2.t("field.params"),record:{editable:!0,options:async(t,e,i,r,s)=>{const{description:o,help:a,parameterSpec:n}=i.type?this.authProviderTypes[i.type]:{};return{description:o,help:a,spec:n,context:this.grist}},renderer:"json5"},width:200},{type:"datetime",name:"updatedAt",header:p.z2.t("field.updated_at"),record:{editable:!1},sortable:!0,width:180}],rows:{selectable:{multiple:!0}},sorters:[{name:"type"}]}}async fetchHandler({page:t,limit:e,sortings:i=[],filters:r=[]}){const s=await l.Lp.query({query:o.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          authProviderTypes {
            items {
              type
              description
              help
              parameterSpec {
                type
                label
                name
                placeholder
                property
              }
            }
            total
          }

          responses: authProviders(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              type
              active
              tenantId
              clientId
              clientSecret
              privateKey
              params
              updatedAt
            }
            total
          }
        }
      `,variables:{filters:r,pagination:{page:t,limit:e},sortings:i}});return this.authProviderTypes=s.data.authProviderTypes.items,{total:s.data.responses.total||0,records:s.data.responses.items||[]}}async deleteAuthProvider(){if(await m.u.open({title:p.z2.t("text.are_you_sure"),text:p.z2.t("text.sure_to_x",{x:p.z2.t("text.delete")}),confirmButton:{text:p.z2.t("button.confirm")},cancelButton:{text:p.z2.t("button.cancel")}})){const t=this.grist.selected.map((t=>t.id));if(t&&t.length>0){(await l.Lp.mutate({mutation:o.ZP`
            mutation ($ids: [String!]!) {
              deleteAuthProviders(ids: $ids)
            }
          `,variables:{ids:t}})).errors||(this.grist.fetch(),(0,c.h4)({message:p.z2.t("text.info_x_successfully",{x:p.z2.t("text.delete")})}))}}}async updateAuthProvider(){let t=this.grist.dirtyRecords;if(t&&t.length){t=t.map((t=>{let e=t.id?{id:t.id}:{};const i=t.__dirtyfields__;for(let t in i)e[t]=i[t].after;return e.reportTemplate instanceof FileList&&(e.reportTemplate=e.reportTemplate[0]),e.cuFlag=t.__dirty__,e}));(await l.Lp.mutate({mutation:o.ZP`
          mutation ($patches: [AuthProviderPatch!]!) {
            updateMultipleAuthProvider(patches: $patches) {
              id
            }
          }
        `,variables:{patches:t}})).errors||this.grist.fetch()}}async synchronizeUsers(t){if(await m.u.open({title:p.z2.t("text.are_you_sure"),text:p.z2.t("text.sure_to_x",{x:p.z2.t("text.synchronize")}),confirmButton:{text:p.z2.t("button.confirm")},cancelButton:{text:p.z2.t("button.cancel")}})&&t&&t.length>0){(await l.Lp.mutate({mutation:o.ZP`
            mutation ($id: String!) {
              synchronizeAuthProviderUsers(id: $id)
            }
          `,variables:{id:t}})).errors||(this.grist.fetch(),(0,c.h4)({message:p.z2.t("text.info_x_successfully",{x:p.z2.t("text.synchronize")})}))}}};f.styles=[u.Ix,u.Pn,a.iv`
      :host {
        display: flex;

        width: 100%;

        --grid-record-emphasized-background-color: red;
        --grid-record-emphasized-color: yellow;
      }
    `],(0,r.gn)([(0,n.SB)(),(0,r.w6)("design:type",Object)],f.prototype,"gristConfig",void 0),(0,r.gn)([(0,n.SB)(),(0,r.w6)("design:type",String)],f.prototype,"mode",void 0),(0,r.gn)([(0,n.SB)(),(0,r.w6)("design:type",Array)],f.prototype,"authProviderTypes",void 0),(0,r.gn)([(0,n.IO)("ox-grist"),(0,r.w6)("design:type",s.Nw)],f.prototype,"grist",void 0),(0,r.gn)([(0,n.IO)("#sorter-control"),(0,r.w6)("design:type",y.WP)],f.prototype,"sortersControl",void 0),f=(0,r.gn)([(0,n.Mo)("auth-provider-management")],f)}}]);