"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[1425],{91425:(t,e,i)=>{i.r(e),i.d(e,{SettingList:()=>p});i(62392),i(49005),i(68677),i(43615);var r=i(68784),a=i(53421),s=i(80692),n=i(77675),o=i(27805),d=i(15633),l=i(36179),c=i(16682),h=i(94430),u=i(28120);class p extends((0,u.$)(n.h)((0,a.NC)(a.z2)(n.B4))){static get styles(){return[d.Pn,d.Ix,h.iv`
        :host {
          display: flex;
          flex-direction: column;
          overflow: hidden;
        }
      `]}static get properties(){return{config:Object,data:Object,mode:String}}render(){let t=this.mode;return h.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>
    `}constructor(){super(),this.refreshHandlers=[],this.mode=(0,l.s2)()?"LIST":"GRID"}get context(){return{title:a.z2.t("title.setting"),help:"setting/settings",actions:[{title:a.z2.t("button.save"),action:this._saveSettings.bind(this),...d.jO.save},{title:a.z2.t("button.delete"),action:this._deleteSettings.bind(this),...d.jO.delete}],exportable:{name:a.z2.t("title.setting"),data:this._exportableData.bind(this)},importable:{handler:()=>{}}}}pageUpdated(t,e){this.active&&(this.dataGrist.fetch(),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:"string",name:"name",header:a.z2.t("field.name"),record:{editable:!0,align:"left"},sortable:!0,filter:"search",width:235},{type:"string",name:"description",header:a.z2.t("field.description"),record:{editable:!0,align:"left"},sortable:!0,filter:"search",width:275},{type:"code",name:"category",header:a.z2.t("field.category"),record:{editable:!0,codeName:"SETTING_CATEGORIES"},sortable:!0,filter:"search",width:100},{type:"string",name:"value",header:a.z2.t("field.value"),record:{editor:function(t,e,i,a,s){return(0,r.y$)(i.category)(t,e,i,a,s)},renderer:function(t,e,i,a,s){return(0,r.Bp)(i.category)(t,e,i,a,s)},editable:!0},sortable:!0,width:180},{type:"object",name:"updater",header:a.z2.t("field.updater"),record:{editable:!1,align:"left"},sortable:!0,width:90},{type:"datetime",name:"updatedAt",header:a.z2.t("field.updated_at"),record:{editable:!1,align:"left"},sortable:!0,width:180}]})}get dataGrist(){return this.renderRoot.querySelector("ox-grist")}async fetchHandler({filters:t,page:e,limit:i,sorters:r=[]}){const a={page:e,limit:i},s=r,n=await o.Lp.query({query:c.ZP`
        query settings($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          settings(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              name
              description
              category
              value
              updatedAt
              updater {
                id
                name
                description
              }
            }
            total
          }
        }
      `,variables:{filters:t,pagination:a,sortings:s},context:(0,o.Bn)()});return{total:n.data.settings.total||0,records:n.data.settings.items||[]}}async _saveSettings(){let t=this.dataGrist.dirtyRecords;if(!t?.length)return this.showToast(a.z2.t("text.nothing_changed"));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.cuFlag=t.__dirty__,e}));let e=!0;if(t.forEach((t=>{if(!("+"!==t.cuFlag||t.name&&t.category))return e=!1})),!e)return this.showToast(a.z2.t("error.value is empty",{value:"name or category"}));(await o.Lp.mutate({mutation:c.ZP`
        mutation updateMultipleSetting($patches: [SettingPatch!]!) {
          updateMultipleSetting(patches: $patches) {
            name
          }
        }
      `,variables:{patches:t},context:(0,o.Bn)()})).errors||(this.showToast(a.z2.t("text.data_updated_successfully")),this.dataGrist.fetch(),this.applyRefreshHandlers())}async _deleteSettings(){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.name));if(!(await(0,s.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 o.Lp.mutate({mutation:c.ZP`
        mutation deleteSettings($names: [String!]!) {
          deleteSettings(names: $names)
        }
      `,variables:{names:t},context:(0,o.Bn)()})).errors||((0,s.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(),this.applyRefreshHandlers())}applyRefreshHandlers(){this.refreshHandlers.forEach((t=>t()))}_exportableData(){return this.dataGrist.exportRecords()}stateChanged(t){this.refreshHandlers=t.setting?.refreshHandlers||[]}showToast(t){document.dispatchEvent(new CustomEvent("notify",{detail:{message:t,option:{timer:1e3}}}))}}window.customElements.define("setting-list",p)}}]);