"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[5131],{55131:(t,e,i)=>{i.r(e),i.d(e,{PartnerSettingList:()=>u});i(67475),i(39663);var r=i(68784),a=i(53421),n=i(27805),o=i(36179),s=i(15633),d=i(16682),l=i(94430);class c extends l.oi{static get styles(){return[s.Pn,l.iv`
        :host {
          display: flex;
          flex-direction: column;
          overflow: hidden;
          background-color: white;
        }
        .button-container {
          padding: var(--button-container-padding);
          margin: var(--button-container-margin);
          text-align: var(--button-container-align);
          background-color: var(--button-container-background);
          height: var(--button-container-height);
        }
      `]}static get properties(){return{config:Object,data:Object,mode:String}}render(){let t=this.mode;return l.dy`
      <ox-grist .mode=${t} auto-fetch .config=${this.config} .fetchHandler=${this.fetchHandler.bind(this)}>
        <div slot="headroom">
          <div id="filters">
            <ox-filters-form></ox-filters-form>
          </div>

          <div id="sorters">
            Sort
            <mwc-icon
              @click=${t=>{const e=t.currentTarget;this.renderRoot.querySelector("#sorter-control").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 id="modes">
            <mwc-icon @click=${()=>this.mode="GRID"} ?active=${"GRID"==t}>grid_on</mwc-icon>
            <mwc-icon @click=${()=>this.mode="LIST"} ?active=${"LIST"==t}>format_list_bulleted</mwc-icon>
          </div>
        </div>
      </ox-grist>

      <div class="button-container">
        <mwc-button raised @click="${this.select.bind(this)}">${a.z2.t("button.select")}</mwc-button>
      </div>
    `}constructor(){super(),this.mode=(0,o.s2)()?"LIST":"GRID"}get dataGrist(){return this.renderRoot?.querySelector("ox-grist")}firstUpdated(){this.config={list:{fields:["name","description"]},rows:{selectable:{multiple:!0},appendable:!1,handlers:{click:"select-row-toggle"}},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!1},{type:"string",name:"name",header:a.z2.t("field.name"),record:{editable:!1,align:"left"},sortable:!0,filter:"search",width:100},{type:"string",name:"description",header:a.z2.t("field.description"),record:{editable:!1,align:"left"},sortable:!0,filter:"search",width:200}]}}async fetchHandler({filters:t,page:e,limit:i,sorters:r=[]}){const a={page:e,limit:i},o=r,s=await n.Lp.query({query:d.ZP`
        query searchCustomers($filters: [Filter!]!, $pagination: Pagination!, $sortings: [Sorting!]!) {
          searchCustomers(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              name
              description
            }
            total
          }
        }
      `,variables:{filters:t,pagination:a,sortings:o},context:(0,n.Bn)()});return{records:s.data.searchCustomers.items||[],total:s.data.searchCustomers.total||0}}select(){const t=this.dataGrist.selected;t.length?(history.back(),this.dispatchEvent(new CustomEvent("select",{detail:t[0]}))):this.showToast(a.z2.t("text.nothing_selected"))}showToast(t){document.dispatchEvent(new CustomEvent("notify",{detail:{message:t,option:{timer:1e3}}}))}}customElements.define("partner-selector",c);var p=i(28120),m=i(37077),g=i(77675),h=i(80692);class u extends((0,p.$)(g.h)((0,a.NC)(a.z2)(g.B4))){static get styles(){return[s.Pn,s.Ix,l.iv`
        :host {
          display: flex;
          flex-direction: column;
          overflow: hidden;
        }
        fieldset {
          max-width: var(--input-container-max-width);
          border: none;
        }
        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);
          background-color: var(--theme-white-color);
          font: var(--input-font);
        }
      `]}static get properties(){return{config:Object,partnerDomain:Object,mode:String}}render(){let t=this.mode;return l.dy`
      <form class="multi-column-form">
        <fieldset>
          <label>${a.z2.t("label.partner")}</label>
          <input
            readonly
            name="partnerDomain"
            value="${this.partnerDomain?.name?this.partnerDomain.name:""}"
            @click="${this.openPartnerSelector.bind(this)}"
            placeholder=${a.z2.t("text.please_choose_partner")||""}
          />
        </fieldset>
      </form>

      <ox-grist
        .mode=${t}
        .config=${this.config}
        .fetchHandler="${this.fetchHandler.bind(this)}"
        @record-change="${this.onRecordChangeHandler.bind(this)}"
      >
        <div slot="headroom">
          <div id="filters">
            <ox-filters-form></ox-filters-form>
          </div>

          <div id="sorters">
            Sort
            <mwc-icon
              @click=${t=>{const e=t.currentTarget;this.renderRoot.querySelector("#sorter-control").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 id="modes">
            <mwc-icon @click=${()=>this.mode="GRID"} ?active=${"GRID"==t}>grid_on</mwc-icon>
            <mwc-icon @click=${()=>this.mode="LIST"} ?active=${"LIST"==t}>format_list_bulleted</mwc-icon>
          </div>
        </div>
      </ox-grist>
    `}constructor(){super(),this.refreshHandlers=[],this.mode=(0,o.s2)()?"LIST":"GRID"}get context(){return{title:a.z2.t("title.partner_setting"),help:"setting/partner-setting",actions:[{title:a.z2.t("button.save"),action:this.save.bind(this),...s.jO.save},{title:a.z2.t("button.delete"),action:this.delete.bind(this),...s.jO.delete}]}}pageInitialized(){this.config={list:{fields:["name","description","value"]},rows:{selectable:{multiple:!0}},columns:[{type:"gutter",gutterName:"dirty"},{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"object",name:"setting",header:a.z2.t("label.setting"),width:280,record:{editable:!0,options:{queryName:"settings",select:[{name:"id",hidden:!0},{name:"name",header:a.z2.t("field.name")},{name:"description",header:a.z2.t("field.description")},{name:"category",header:a.z2.t("field.category")}],list:{fields:["name","description","category"]}}}},{type:"string",name:"name",header:a.z2.t("field.name"),record:{editable:!1,align:"left"},sortable:!0,filter:"search",width:200},{type:"string",name:"description",header:a.z2.t("field.description"),record:{editable:!1,align:"left"},sortable:!0,filter:"search",width:200},{type:"code",name:"category",header:a.z2.t("field.category"),record:{editable:!1,codeName:"SETTING_CATEGORIES"},sortable:!0,width:150},{type:"string",name:"value",header:a.z2.t("field.value"),record:{editor:function(t,e,i,a,n){return(0,r.y$)(i.category)(t,e,i,a,n)},renderer:function(t,e,i,a,n){return(0,r.Bp)(i.category)(t,e,i,a,n)},editable:!0},sortable:!0,width:180},{type:"datetime",name:"updatedAt",header:a.z2.t("field.updated_at"),record:{editable:!1,align:"left"},sortable:!0,width:150},{type:"object",name:"updater",header:a.z2.t("field.updater"),record:{editable:!1,align:"left"},sortable:!0,width:150}]}}pageUpdated(){this.active&&(this.partnerDomain=null,this.dataGrist.data={records:[],total:0})}get dataGrist(){return this.renderRoot.querySelector("ox-grist")}async fetchHandler({filters:t,page:e,limit:i,sorters:r=[]}){if(!this.partnerDomain)return{total:0,records:[]};const a={page:e,limit:i},o=r,s=await n.Lp.query({query:d.ZP`
        query partnerSettings(
          $filters: [Filter!]!
          $pagination: Pagination!
          $sortings: [Sorting!]!
          $partnerDomain: ObjectRef!
        ) {
          partnerSettings(
            filters: $filters
            pagination: $pagination
            sortings: $sortings
            partnerDomain: $partnerDomain
          ) {
            items {
              id
              setting {
                id
                name
                description
                category
              }
              name
              description
              category
              value
              updatedAt
              updater {
                id
                name
                description
              }
            }
            total
          }
        }
      `,variables:{filters:t,pagination:a,sortings:o,partnerDomain:{id:this.partnerDomain.id}},context:(0,n.Bn)()});return{records:s.data.partnerSettings.items.map((t=>({...t,description:t.setting.description,category:t.setting.category})))||[],total:s.data.partnerSettings.total||0}}async save(){let t=this.dataGrist.dirtyRecords;if(!t?.length)return this.showToast(a.z2.t("text.nothing_changed"));t=t.map((t=>{let e={cuFlag:t.__dirty__,setting:{id:t.setting.id},partnerDomain:{id:this.partnerDomain.id}};return t.id&&(e.id=t.id),t.value&&(e.value=t.value),e}));const e=await n.Lp.mutate({mutation:d.ZP`
        mutation updateMultiplePartnerSetting($patches: [PartnerSettingPatch!]!) {
          updateMultiplePartnerSetting(patches: $patches) {
            name
          }
        }
      `,variables:{patches:t},context:(0,n.Bn)()});e.errors?.length||(this.showToast(a.z2.t("text.data_updated_successfully")),this.dataGrist.fetch())}async delete(){if(!this.dataGrist.selected?.length)return this.showToast(a.z2.t("text.there_is_nothing_to_delete"));const t=this.dataGrist.selected.map((t=>t.id));if(!(await(0,h.ID)({type:"warning",title:a.z2.t("button.delete"),text:a.z2.t("text.are_you_sure"),confirmButton:{text:a.z2.t("button.delete")},cancelButton:{text:a.z2.t("button.cancel")}})).value)return;(await n.Lp.mutate({mutation:d.ZP`
        mutation deletePartnerSettings($ids: [String!]!) {
          deletePartnerSettings(ids: $ids)
        }
      `,variables:{ids:t},context:(0,n.Bn)()})).errors||((0,h.ID)({type:"success",title:a.z2.t("text.completed"),text:a.z2.t("text.data_deleted_successfully"),confirmButton:{text:a.z2.t("button.confirm")}}),this.dataGrist.fetch())}openPartnerSelector(){(0,m.Mw)(l.dy`
        <partner-selector
          @select="${t=>{this.partnerDomain=t.detail,this.dataGrist.fetch()}}"
        ></partner-selector>
      `,{backdrop:!0,title:a.z2.t("label.partner")})}onRecordChangeHandler({detail:{after:t,column:e}}){"setting"===e.name&&this.fillUpFields(t)}fillUpFields(t){t.name=t.setting.name,t.description=t.setting.description,t.category=t.setting.category}showToast(t){document.dispatchEvent(new CustomEvent("notify",{detail:{message:t,option:{timer:1e3}}}))}}window.customElements.define("partner-setting-list",u)}}]);