"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[635],{70635:(t,e,i)=>{i.r(e),i.d(e,{AttributeSetManagementPage:()=>f});var r=i(50493),s=i(68784),o=i(16682),a=i(94430),n=i(56765),d=i(27805),l=i(53421),c=i(36179);let p=class extends((0,l.NC)(l.z2)(a.oi)){render(){return a.dy`
      <ox-grist
        .mode=${(0,c.s2)()?"LIST":"GRID"}
        .config=${this.gristConfig}
        .fetchHandler=${this.fetchHandler.bind(this)}
      ></ox-grist>
      <div class="button-container">
        <mwc-button raised danger @click=${this.deleteAttributeSetItems.bind(this)}
          >${l.z2.t("button.delete")}</mwc-button
        >
        <mwc-button raised @click=${this.updateAttributeSetItems.bind(this)}>${l.z2.t("button.save")}</mwc-button>
      </div>
    `}async firstUpdated(){this.gristConfig={list:{fields:["name","description","active"]},columns:[{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"gutter",gutterName:"button",icon:"add",handlers:{click:"record-copy"}},{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"button",icon:"arrow_upward",handlers:{click:"move-up"}},{type:"gutter",gutterName:"button",icon:"arrow_downward",handlers:{click:"move-down"}},{type:"string",name:"name",header:l.z2.t("field.name"),record:{editable:!0},width:140},{type:"string",name:"description",header:l.z2.t("field.description"),record:{editable:!0},width:180},{type:"string",name:"tag",header:l.z2.t("field.tag"),record:{editable:!0},width:180},{type:"checkbox",name:"active",label:!0,header:l.z2.t("field.active"),record:{editable:!0},sortable:!0,width:60},{type:"checkbox",name:"hidden",label:!0,header:l.z2.t("field.hidden"),record:{editable:!0},sortable:!0,width:60},{type:"select",name:"type",header:l.z2.t("field.type"),record:{options:["","number","text","select","boolean","date","datetime","file"],editable:!0},width:120},{type:"parameters",name:"options",header:l.z2.t("field.options"),record:{editable:!0,renderer:"json5",options:async(t,e,i,r,s)=>({name:i.type,help:"",spec:"select"===i.type?[{type:"options",name:"options",label:"options"}]:[],context:this.grist,objectified:!0})},width:120}],rows:{selectable:{multiple:!0}},pagination:{infinite:!0},sorters:[]}}async fetchHandler({filters:t,page:e,limit:i,sortings:r=[]}){const s=this.attribute.items||[];return{total:s.length,records:s}}async updateAttributeSetItems(){this.grist.commit();(await d.Lp.mutate({mutation:o.ZP`
        mutation ($id: String!, $patch: AttributeSetPatch!) {
          updateAttributeSet(id: $id, patch: $patch) {
            entity
          }
        }
      `,variables:{id:this.attribute.id,patch:{items:this.grist.data.records,cuFlag:"M"}}})).errors||await document.dispatchEvent(new CustomEvent("notify",{detail:{message:l.z2.t("text.info_x_successfully",{x:l.z2.t("button.save")})}}))}async deleteAttributeSetItems(){confirm(l.z2.t("text.sure_to_x",{x:l.z2.t("text.delete")}))&&this.grist.deleteSelectedRecords(!1)}};p.styles=[a.iv`
      :host {
        display: flex;
        flex-direction: column;

        background-color: #fff;
      }

      ox-grist {
        flex: 1;
      }

      .button-container {
        display: flex;
        margin-left: auto;
        padding: var(--padding-default);
      }

      [danger] {
        --mdc-theme-primary: var(--mdc-danger-button-primary-color);
      }
      mwc-button {
        margin-left: var(--margin-default);
      }
    `],(0,r.gn)([(0,n.Cb)({type:Object}),(0,r.w6)("design:type",Object)],p.prototype,"attribute",void 0),(0,r.gn)([(0,n.SB)(),(0,r.w6)("design:type",Object)],p.prototype,"gristConfig",void 0),(0,r.gn)([(0,n.IO)("ox-grist"),(0,r.w6)("design:type",s.Nw)],p.prototype,"grist",void 0),p=(0,r.gn)([(0,n.Mo)("attribute-set-item-list")],p);var u=i(28120),g=i(37077),m=i(77675),h=i(15633),b=i(64312);let f=class extends((0,u.$)(m.h)((0,l.NC)(l.z2)(m.B4))){constructor(){super(...arguments),this.mode=(0,c.s2)()?"CARD":"GRID"}get context(){var t;return{title:l.z2.t("title.attributes"),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:l.z2.t("button.save"),action:this.updateAttributeSet.bind(this)},h.jO.save),Object.assign({title:l.z2.t("button.delete"),action:this.deleteAttributeSet.bind(this)},h.jO.delete)]}}render(){const t=this.mode||((0,c.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 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>
            <mwc-icon @click=${()=>this.mode="CARD"} ?active=${"CARD"==t}>apps</mwc-icon>
          </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:l.z2.t("title.attribute model"),icon:"reorder",handlers:{click:(t,e,i,r,s)=>{if(!r.id)return;(0,g.Mw)(a.dy` <attribute-set-item-list .attribute=${r}></attribute-set-item-list> `,{backdrop:!0,help:"attribute/ui/attribute-set-item-list",size:"large",title:l.z2.t("title.attribute-item list")}).onclosed=()=>{this.grist.fetch()}}}},{type:"string",name:"entity",header:l.z2.t("field.entity"),record:{editable:!0},filter:"search",sortable:!0,width:150},{type:"string",name:"description",header:l.z2.t("field.description"),record:{editable:!0},filter:"search",width:200},{type:"datetime",name:"updatedAt",header:l.z2.t("field.updated_at"),record:{editable:!1},sortable:!0,width:180}],rows:{selectable:{multiple:!0}},sorters:[{name:"name"}]}}async fetchHandler({page:t,limit:e,sortings:i=[],filters:r=[]}){const s=await d.Lp.query({query:o.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          responses: attributeSets(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              entity
              description
              updatedAt
              items {
                name
                description
                tag
                active
                hidden
                type
                options
              }
            }
            total
          }
        }
      `,variables:{filters:r,pagination:{page:t,limit:e},sortings:i}});return{total:s.data.responses.total||0,records:s.data.responses.items||[]}}async deleteAttributeSet(){if(confirm(l.z2.t("text.sure_to_x",{x:l.z2.t("text.delete")}))){const t=this.grist.selected.map((t=>t.id));if(t&&t.length>0){(await d.Lp.mutate({mutation:o.ZP`
            mutation ($ids: [String!]!) {
              deleteAttributeSets(ids: $ids)
            }
          `,variables:{ids:t}})).errors||(this.grist.fetch(),(0,g.h4)({message:l.z2.t("text.info_x_successfully",{x:l.z2.t("text.delete")})}))}}}async updateAttributeSet(){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 d.Lp.mutate({mutation:o.ZP`
          mutation ($patches: [AttributeSetPatch!]!) {
            updateMultipleAttributeSet(patches: $patches) {
              entity
            }
          }
        `,variables:{patches:t},context:{hasUpload:!0}})).errors||this.grist.fetch()}}};f.styles=[h.Ix,h.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.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",b.WP)],f.prototype,"sortersControl",void 0),f=(0,r.gn)([(0,n.Mo)("attribute-set-management")],f)}}]);