"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[2566],{62566:(t,e,i)=>{i.r(e),i.d(e,{NotificationRuleListPage:()=>y});var o=i(50493),r=i(68784),s=i(15633),a=i(77675),n=i(94430),d=i(56765),l=i(69292),c=i(27805),p=i(53421),u=i(37077),h=i(64312),f=i(36179),m=i(28120),g=i(16682);class b extends n.oi{constructor(){super(...arguments),this.notificationRules=[],this.columns={list:{fields:["name","description"]},pagination:{infinite:!0},columns:[{type:"string",name:"name",header:p.z2.t("field.name"),width:150},{type:"string",name:"description",header:p.z2.t("field.description"),width:200},{type:"checkbox",name:"active",header:p.z2.t("field.active"),width:60}]}}render(){return n.dy`
      <ox-grist
        .mode=${(0,f.s2)()?"LIST":"GRID"}
        .config=${this.columns}
        .data=${{records:this.notificationRules}}
      ></ox-grist>

      <div class="button-container">
        <mwc-button raised @click="${this.save.bind(this)}">${p.z2.t("button.save")}</mwc-button>
      </div>
    `}async save(){var t;(null===(t=(await c.Lp.mutate({mutation:g.ZP`
        mutation importNotificationRules($notificationRules: [NotificationRulePatch!]!) {
          importNotificationRules(notificationRules: $notificationRules)
        }
      `,variables:{notificationRules:this.notificationRules}})).errors)||void 0===t?void 0:t.length)||this.dispatchEvent(new CustomEvent("imported"))}}b.styles=[n.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);
      }

      mwc-button {
        margin-left: var(--margin-default);
      }
    `],(0,o.gn)([(0,d.Cb)({type:Array}),(0,o.w6)("design:type",Array)],b.prototype,"notificationRules",void 0),(0,o.gn)([(0,d.Cb)({type:Object}),(0,o.w6)("design:type",Object)],b.prototype,"columns",void 0);let y=class extends((0,m.$)(a.h)((0,p.NC)(p.z2)((0,l.f)(a.B4)))){constructor(){super(...arguments),this.mode=(0,f.s2)()?"CARD":"GRID"}static get scopedElements(){return{"notification-rule-importer":b}}get context(){var t;return{title:p.z2.t("title.notification-rule list"),search:{handler:t=>{this.grist.searchText=t},value:(null===(t=this.grist)||void 0===t?void 0:t.searchText)||""},filter:{handler:()=>{this.grist.toggleHeadroom()}},help:"notification/notification-rule",actions:[Object.assign({title:p.z2.t("button.save"),action:this._updateNotificationRule.bind(this)},s.jO.save),Object.assign({title:p.z2.t("button.delete"),action:this._deleteNotificationRule.bind(this)},s.jO.delete)],exportable:{name:p.z2.t("title.notification-rule list"),data:this.exportHandler.bind(this)},importable:{handler:this.importHandler.bind(this)}}}render(){const t=this.mode||((0,f.s2)()?"CARD":"GRID");return n.dy`
      <ox-grist .mode=${t} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>
        <div slot="headroom">
          <div id="filters">
            <ox-filters-form autofocus></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:{thumbnail:"thumbnail",fields:["name","description"],details:["title","updatedAt"]},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"string",name:"name",header:p.z2.t("field.name"),record:{editable:!0},filter:"search",sortable:!0,width:150},{type:"string",name:"description",header:p.z2.t("field.description"),record:{editable:!0},filter:"search",width:200},{type:"string",name:"title",header:p.z2.t("field.title"),record:{editable:!0},filter:"search",sortable:!0,width:150},{type:"text",name:"body",header:p.z2.t("field.body"),record:{editable:!0},filter:"search",sortable:!0,width:150},{type:"string",name:"url",header:p.z2.t("field.url"),record:{editable:!0},sortable:!0,width:150},{type:"image",name:"thumbnail",header:p.z2.t("field.thumbnail"),record:{editable:!0},width:120},{type:"select",name:"state",label:!0,header:p.z2.t("field.state"),record:{options:[{},{display:p.z2.t("text.draft"),value:"DRAFT"},{display:p.z2.t("text.released"),value:"RELEASED"}]},sortable:!0,filter:!0,width:60},{type:"recipients",name:"recipients",header:p.z2.t("field.recipients"),record:{editable:!0},width:50},{type:"resource-object",name:"updater",header:p.z2.t("field.updater"),record:{editable:!1},sortable:!0,width:120},{type:"datetime",name:"updatedAt",header:p.z2.t("field.updated_at"),record:{editable:!1},sortable:!0,width:180}],rows:{selectable:{multiple:!0}},sorters:[{name:"name"}]}}async pageUpdated(t,e){this.active}async fetchHandler({page:t=1,limit:e=100,sortings:i=[],filters:o=[]}){const r=await c.Lp.query({query:g.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          responses: notificationRules(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              name
              description
              title
              body
              url
              thumbnail
              state
              updater {
                id
                name
              }
              updatedAt
            }
            total
          }
        }
      `,variables:{filters:o,pagination:{page:t,limit:e},sortings:i}});return{total:r.data.responses.total||0,records:r.data.responses.items||[]}}async _deleteNotificationRule(){if(confirm(p.z2.t("text.sure_to_x",{x:p.z2.t("text.delete")}))){const t=this.grist.selected.map((t=>t.id));if(t&&t.length>0){(await c.Lp.mutate({mutation:g.ZP`
            mutation ($ids: [String!]!) {
              deleteNotificationRules(ids: $ids)
            }
          `,variables:{ids:t}})).errors||(this.grist.fetch(),(0,u.h4)({message:p.z2.t("text.info_x_successfully",{x:p.z2.t("text.delete")})}))}}}async _updateNotificationRule(){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.cuFlag=t.__dirty__,e}));(await c.Lp.mutate({mutation:g.ZP`
          mutation ($patches: [NotificationRulePatch!]!) {
            updateMultipleNotificationRule(patches: $patches) {
              name
            }
          }
        `,variables:{patches:t}})).errors||this.grist.fetch()}}async exportHandler(){const t=this.grist.selected.length?this.grist.selected:this.grist.dirtyData.records,e=new Set(["id","name","description","active"]);return t.map((t=>{let i={};for(const o of e)i[o]=t[o];return i}))}async importHandler(t){(0,u.Mw)(n.dy`
        <notification-rule-importer
          .notificationRules=${t}
          @imported=${()=>{history.back(),this.grist.fetch()}}
        ></notification-rule-importer>
      `,{backdrop:!0,size:"large",title:p.z2.t("title.import notification-rule")}).onclosed=()=>{this.grist.fetch()}}};y.styles=[s.Ix,s.Pn,n.iv`
      :host {
        display: flex;

        width: 100%;

        --grid-record-emphasized-background-color: red;
        --grid-record-emphasized-color: yellow;
      }
    `],(0,o.gn)([(0,d.Cb)({type:Object}),(0,o.w6)("design:type",Object)],y.prototype,"gristConfig",void 0),(0,o.gn)([(0,d.Cb)({type:String}),(0,o.w6)("design:type",String)],y.prototype,"mode",void 0),(0,o.gn)([(0,d.IO)("ox-grist"),(0,o.w6)("design:type",r.Nw)],y.prototype,"grist",void 0),(0,o.gn)([(0,d.IO)("#sorter-control"),(0,o.w6)("design:type",h.WP)],y.prototype,"sortersControl",void 0),y=(0,o.gn)([(0,d.Mo)("notification-rule-list-page")],y)}}]);