"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[4449],{24449:(e,t,i)=>{i.r(t),i.d(t,{EmployeeListPage:()=>w});var r=i(50493),o=i(68784),a=(i(80803),i(16682)),n=i(94430),s=i(56765),d=i(27805),l=i(53421),c=i(64312),p=i(36179),m=i(15633);let h=class extends n.oi{constructor(){super(...arguments),this.data=o.zH,this.selectedRecords=[],this.fetchHandler=async({page:e=1,limit:t=100,sortings:i=[],filters:r=[]})=>{const o=await d.Lp.query({query:a.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          fetch: contacts(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              name
              company
              email
              phone
              address
              department
              note
              profile {
                left
                top
                zoom
                picture
              }
              updater {
                id
                name
              }
              updatedAt
            }
            total
          }
        }
      `,variables:{filters:r,pagination:{page:e,limit:t},sortings:i},context:(0,d.Bn)()});if(!o.errors){return{records:o.data.fetch.items.map((e=>(this.value&&this.value===e.id&&(this.selectedRecords=[e],e.__selected__=!0),e))),total:o.data.fetch.total,limit:t,page:e}}}}render(){return n.dy`
      <ox-grist
        .mode=${(0,p.s2)()?"LIST":"GRID"}
        .config=${this.config}
        .data=${this.data}
        .fetchHandler=${this.fetchHandler.bind(this)}
        .selectedRecords=${this.selectedRecords}
      >
        <div id="filters" slot="headroom">
          <ox-filters-form autofocus></ox-filters-form>
        </div>
      </ox-grist>

      <div class="button-container">
        <mwc-button @click=${this.onEmpty.bind(this)}>${l.z2.t("button.empty")}</mwc-button>
        <mwc-button @click=${this.onCancel.bind(this)}>${l.z2.t("button.cancel")}</mwc-button>
        <mwc-button @click=${this.onConfirm.bind(this)}>${l.z2.t("button.confirm")}</mwc-button>
      </div>
    `}onEmpty(){this.confirmCallback&&this.confirmCallback(),(0,c.j4)(this)}onCancel(){(0,c.j4)(this)}onConfirm(){this.confirmCallback&&this.confirmCallback(this.selected),(0,c.j4)(this)}async firstUpdated(){this.config={pagination:{pages:[100,200,500]},list:{thumbnail:"profile",fields:["name","company"],details:["email","updatedAt"]},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!1},{type:"string",name:"name",header:l.z2.t("field.name"),record:{editable:!1},filter:"search",sortable:!0,width:100},{type:"string",name:"company",header:l.z2.t("field.company"),record:{editable:!1},filter:"search",sortable:!0,width:135},{type:"string",name:"department",header:l.z2.t("field.department"),record:{editable:!1},sortable:!0,width:135},{type:"string",name:"email",header:l.z2.t("field.email"),record:{editable:!1},sortable:!0,width:190},{type:"string",name:"phone",header:l.z2.t("field.phone"),record:{editable:!1},sortable:!0,width:120},{type:"string",name:"address",header:l.z2.t("field.address"),record:{editable:!1},sortable:!0,width:375},{type:"image",name:"profile",record:{renderer:function(e,t,i,r,o){return n.dy`<ox-pfp-view
                style="height:90%; width: unset; aspect-ratio: 1 / 1;"
                .profile=${i.profile}
                .name=${i.name}
              ></ox-pfp-view>`}},hidden:!0}],rows:{selectable:{multiple:!1},handlers:{click:"select-row"},appendable:!1},sorters:[{name:"name"},{name:"company"}]}}get selected(){var e=this.renderRoot.querySelector("ox-grist").selected;return e&&e.length>0?e[0]:void 0}};h.styles=[m.bx,n.iv`
      :host {
        display: flex;
        flex-direction: column;

        background-color: #fff;

        width: var(--overlay-center-normal-width, 50%);
        height: var(--overlay-center-normal-height, 50%);
      }

      ox-grist {
        flex: 1;
      }

      #filters {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
      }

      #filters > * {
        padding: var(--padding-default) var(--padding-wide);
      }
    `],(0,r.gn)([(0,s.Cb)({type:String}),(0,r.w6)("design:type",String)],h.prototype,"value",void 0),(0,r.gn)([(0,s.Cb)({type:Object}),(0,r.w6)("design:type",Object)],h.prototype,"config",void 0),(0,r.gn)([(0,s.Cb)({type:Object}),(0,r.w6)("design:type",Object)],h.prototype,"data",void 0),(0,r.gn)([(0,s.Cb)({type:Object}),(0,r.w6)("design:type",Function)],h.prototype,"confirmCallback",void 0),(0,r.gn)([(0,s.Cb)({type:Array}),(0,r.w6)("design:type",Array)],h.prototype,"selectedRecords",void 0),(0,r.gn)([(0,s.Cb)({type:Object}),(0,r.w6)("design:type",Object)],h.prototype,"list",void 0),(0,r.gn)([(0,s.IO)("ox-grist"),(0,r.w6)("design:type",o.Nw)],h.prototype,"grist",void 0),h=(0,r.gn)([(0,s.Mo)("contact-selector")],h);var g=i(28120),y=i(69292),f=i(37077),u=i(77675);class b extends n.oi{constructor(){super(...arguments),this.employees=[],this.columns={list:{fields:["name","description"]},pagination:{infinite:!0},columns:[{type:"string",name:"name",header:l.z2.t("field.name"),width:150},{type:"string",name:"description",header:l.z2.t("field.description"),width:200},{type:"checkbox",name:"active",header:l.z2.t("field.active"),width:60}]}}render(){return n.dy`
      <ox-grist
        .mode=${(0,p.s2)()?"LIST":"GRID"}
        .config=${this.columns}
        .data=${{records:this.employees}}
      ></ox-grist>

      <div class="button-container">
        <mwc-button raised @click="${this.save.bind(this)}">${l.z2.t("button.save")}</mwc-button>
      </div>
    `}async save(){var e;(null===(e=(await d.Lp.mutate({mutation:a.ZP`
        mutation importEmployees($employees: [EmployeePatch!]!) {
          importEmployees(employees: $employees)
        }
      `,variables:{employees:this.employees}})).errors)||void 0===e?void 0:e.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,r.gn)([(0,s.Cb)({type:Array}),(0,r.w6)("design:type",Array)],b.prototype,"employees",void 0),(0,r.gn)([(0,s.Cb)({type:Object}),(0,r.w6)("design:type",Object)],b.prototype,"columns",void 0);let w=class extends((0,g.$)(u.h)((0,l.NC)(l.z2)((0,y.f)(u.B4)))){constructor(){super(...arguments),this.mode=(0,p.s2)()?"CARD":"GRID"}static get scopedElements(){return{"employee-importer":b}}get context(){var e;return{title:l.z2.t("title.employee list"),search:{handler:e=>{this.grist.searchText=e},value:(null===(e=this.grist)||void 0===e?void 0:e.searchText)||""},filter:{handler:()=>{this.grist.toggleHeadroom()}},help:"organization/employee",actions:[Object.assign({title:l.z2.t("button.save"),action:this._updateEmployee.bind(this)},m.jO.save),Object.assign({title:l.z2.t("button.delete"),action:this._deleteEmployee.bind(this)},m.jO.delete)],exportable:{name:l.z2.t("title.employee list"),data:this.exportHandler.bind(this)},importable:{handler:this.importHandler.bind(this)}}}render(){const e=this.mode||((0,p.s2)()?"CARD":"GRID");return n.dy`
      <ox-grist .mode=${e} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>
        <div slot="headroom">
          <div id="filters">
            <ox-filters-form autofocus without-search></ox-filters-form>
          </div>

          <div id="sorters">
            Sort
            <mwc-icon
              @click=${e=>{const t=e.currentTarget;this.sortersControl.open({right:0,top:t.offsetTop+t.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"==e}>grid_on</mwc-icon>
            <mwc-icon @click=${()=>this.mode="LIST"} ?active=${"LIST"==e}>format_list_bulleted</mwc-icon>
            <mwc-icon @click=${()=>this.mode="CARD"} ?active=${"CARD"==e}>apps</mwc-icon>
          </div>
        </div>
      </ox-grist>
    `}async pageInitialized(e){this.gristConfig={pagination:{pages:[50,100,200]},list:{thumbnail:"profile",fields:["controlNo","name"],details:["email","department","hiredOn","updatedAt"]},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"gutter",gutterName:"button",icon:"contact_page",forList:!0,title:l.z2.t("title.contact"),handlers:{click:async(e,t,i,r,o)=>{r.contact?this.openContactPopup(r):r.id&&this.openContactSelector(r)}}},{type:"string",name:"controlNo",header:l.z2.t("field.control-no"),record:{editable:!0},filter:"search",sortable:!0,width:105},{type:"string",name:"name",header:l.z2.t("field.name"),record:{editable:!0},filter:"search",sortable:!0,width:100},{type:"string",name:"alias",header:l.z2.t("label.alias"),record:{editable:!0},filter:"search",sortable:!0,width:110},{type:"resource-object",name:"user",header:l.z2.t("field.user"),record:{editable:!0,options:{title:l.z2.t("title.lookup user"),queryName:"users",basicArgs:{filters:[{name:"userType",operator:"eq",value:"user"}]},descriptionField:"email",columns:[{name:"id",hidden:!0},{name:"name",header:l.z2.t("field.name"),filter:"search"},{name:"email",header:l.z2.t("field.email"),filter:"search"}],list:{fields:["name","email"]}}},sortable:!0,filter:!1,width:100},{type:"code",name:"type",header:l.z2.t("field.type"),width:115,sortable:!1,filter:!1,record:{editable:!0,codeName:"EMPLOYEE_TYPE"}},{type:"department-object",name:"department",header:l.z2.t("field.department"),record:{editable:!0},sortable:!0,filter:!1,width:130},{type:"resource-object",name:"supervisor",header:l.z2.t("field.supervisor"),record:{editable:!0,options:{title:l.z2.t("title.employee list"),queryName:"employees",pagination:{pages:[50,100,200]},basicArgs:{filters:[{name:"active",operator:"eq",value:!0}]},list:{fields:["controlNo","name","alias","hiredOn"]},columns:[{name:"id",hidden:!0},{name:"controlNo",width:120,header:{renderer:()=>l.z2.t("field.control-no")},filter:"search",sortable:!0},{name:"name",width:120,header:{renderer:()=>l.z2.t("field.name")},filter:"search",sortable:!0},{name:"alias",width:150,header:{renderer:()=>l.z2.t("label.alias")},filter:"search",sortable:!0},{type:"code",name:"type",width:110,header:{renderer:()=>l.z2.t("label.type")},record:{editable:!1,codeName:"EMPLOYEE_TYPE"}},{type:"code",name:"jobPosition",width:110,header:{renderer:()=>l.z2.t("label.job-position")},record:{editable:!1,codeName:"JOB_POSITION"}},{type:"code",name:"jobResponsibility",width:200,header:{renderer:()=>l.z2.t("label.job-responsibility")},record:{editable:!1,codeName:"JOB_RESPONSIBILITY"}},{type:"date",name:"hiredOn",header:{renderer:()=>l.z2.t("field.hired-on")},width:100}],valueField:"id",nameField:"name",descriptionField:"controlNo"}},sortable:!0,width:120},{type:"string",name:"email",header:l.z2.t("field.email"),width:200,record:{editable:!1,renderer:function(e,t,i,r,o){return i.contact?i.contact.email:""}},sortable:!0},{type:"string",name:"phone",header:l.z2.t("field.phone"),width:110,record:{editable:!1,renderer:function(e,t,i,r,o){return i.contact?i.contact.phone:""}},sortable:!0},{type:"code",name:"jobResponsibility",header:l.z2.t("label.job-responsibility"),width:175,record:{editable:!0,codeName:"JOB_RESPONSIBILITY"}},{type:"code",name:"jobPosition",header:l.z2.t("label.job-position"),width:100,record:{editable:!0,codeName:"JOB_POSITION"}},{type:"date",name:"hiredOn",header:l.z2.t("field.hired-on"),width:100,record:{editable:!0},sortable:!0},{type:"date",name:"retiredAt",header:l.z2.t("label.retired-at"),width:100,record:{editable:!0}},{type:"checkbox",name:"active",label:!0,header:l.z2.t("field.active"),width:70,record:{align:"center",editable:!0},filter:!0,sortable:!0},{type:"string",name:"note",header:l.z2.t("field.note"),width:200,record:{editable:!0},filter:"search"},{type:"resource-object",name:"updater",header:l.z2.t("field.updater"),width:90,sortable:!1},{type:"datetime",name:"updatedAt",header:l.z2.t("field.updated_at"),width:180,sortable:!0},{type:"image",name:"profile",record:{renderer:function(e,t,i,r,o){return n.dy`<ox-pfp-view
                style="height:90%; width: unset; aspect-ratio: 1 / 1;"
                .profile=${i.profile}
                .name=${i.name}
              ></ox-pfp-view>`}},hidden:!0}],rows:{selectable:{multiple:!0}},sorters:[{name:"controlNo"}]}}async pageUpdated(e,t){this.active}async fetchHandler({page:e=1,limit:t=100,sortings:i=[],filters:r=[]}){const o=await d.Lp.query({query:a.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          responses: employees(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              controlNo
              name
              alias
              type
              jobResponsibility
              jobPosition
              active
              email
              phone
              user {
                id
                name
              }
              department {
                id
                name
                description
              }
              supervisor {
                id
                name
                controlNo
              }
              note
              hiredOn
              retiredAt
              contact {
                id
                email
                phone
                address
              }
              profile {
                left
                top
                zoom
                picture
              }
              updater {
                id
                name
              }
              updatedAt
            }
            total
          }
        }
      `,variables:{filters:r,pagination:{page:e,limit:t},sortings:i}}),n=o.data.responses.items;return{total:o.data.responses.total||0,records:n}}async _deleteEmployee(){if(confirm(l.z2.t("text.sure_to_x",{x:l.z2.t("text.delete")}))){const e=this.grist.selected.map((e=>e.id));if(e&&e.length>0){(await d.Lp.mutate({mutation:a.ZP`
            mutation ($ids: [String!]!) {
              deleteEmployees(ids: $ids)
            }
          `,variables:{ids:e}})).errors||(this.grist.fetch(),(0,f.h4)({message:l.z2.t("text.info_x_successfully",{x:l.z2.t("text.delete")})}))}}}async _updateEmployee(){let e=this.grist.dirtyRecords;if(e&&e.length){e=e.map((e=>{let t=e.id?{id:e.id}:{};const i=e.__dirtyfields__;for(let e in i)t[e]=i[e].after;return t.cuFlag=e.__dirty__,t}));(await d.Lp.mutate({mutation:a.ZP`
          mutation ($patches: [EmployeePatch!]!) {
            updateMultipleEmployee(patches: $patches) {
              name
            }
          }
        `,variables:{patches:e}})).errors||this.grist.fetch()}}async exportHandler(){const e=this.grist.selected.length?this.grist.selected:this.grist.dirtyData.records,t=new Set(["id","controlNo","name","alias","type","hiredOn","retiredAt","active","note"]);return e.map((e=>{let i={};for(const r of t)i[r]=e[r];return i}))}async importHandler(e){(0,f.Mw)(n.dy`
        <employee-importer
          .employees=${e}
          @imported=${()=>{history.back(),this.grist.fetch()}}
        ></employee-importer>
      `,{backdrop:!0,size:"large",title:l.z2.t("title.import employee")}).onclosed=()=>{this.grist.fetch()}}async openContactPopup(e){var t;if(!(null===(t=e.contact)||void 0===t?void 0:t.id))return;const i=await d.Lp.query({query:a.ZP`
        query ($id: String!) {
          contact(id: $id) {
            id
            name
            company
            department
            email
            phone
            address
            note
            items {
              type
              label
              value
            }
            profile {
              left
              top
              zoom
              picture
            }
          }
        }
      `,variables:{id:e.contact.id}}),{contact:r}=i.data;(0,f.Mw)(n.dy`
        <contact-popup
          .contact=${r}
          @change=${()=>{this.grist.fetch()}}
          @detach=${()=>{this.detachContact(e)}}
          detachable
        ></contact-popup>
      `,{backdrop:!0,size:"large",title:l.z2.t("title.contact")})}async openContactSelector(e){(0,f.Mw)(n.dy`
        <contact-selector .confirmCallback=${t=>this.attachContact(e,t)}></contact-selector>
      `,{backdrop:!0,size:"large",title:l.z2.t("title.contact")})}async attachContact(e,t){await d.Lp.mutate({mutation:a.ZP`
        mutation ($id: String!, $contactId: String!) {
          attachContact(id: $id, contactId: $contactId) {
            id
          }
        }
      `,variables:{id:e.id,contactId:t.id}});this.grist.fetch()}async detachContact(e){await d.Lp.mutate({mutation:a.ZP`
        mutation ($id: String!) {
          detachContact(id: $id) {
            id
          }
        }
      `,variables:{id:e.id}});this.grist.fetch()}};w.styles=[m.Ix,m.Pn,n.iv`
      :host {
        display: flex;

        width: 100%;

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