DYGM70zT.js
10.6 KB
import{d as N,u as z,a as J,o as k,k as F,w as r,f as i,_ as $,g as e,e as h,j as v,s as S,p as y,q as re,x as ce,z as de,y as ue,A as me,l as pe,t as O,n as be,B as u,C as ge}from"./BtEn9SvP.js";import{_ as _e}from"./Cba5FCYW.js";import{_ as q}from"./CGpKcNx7.js";import{a as fe,_ as E}from"./CISWP1pQ.js";import{_ as ve,a as we,b as he}from"./Cw8QoC40.js";import{_ as Q}from"./7yIyqIY0.js";import{_ as ye}from"./3BmF-CSc.js";import{_ as Se,o as Ce,s as H}from"./Bd-k_Jez.js";import{_ as W}from"./B57PMWCO.js";import{u as X}from"./sZhUfCvq.js";import{_ as xe}from"./DYcig7R4.js";import{_ as Ue}from"./9JBjgwkJ.js";import{u as Me,_ as Ae,g as Ve}from"./K7-Fp-h8.js";import{u as $e}from"./D2DkqgtI.js";import"./D5W8WIzq.js";import"./BP6f2Ivu.js";import"./B4Klxa_r.js";import"./BHXyHhK1.js";import"./3laQJA1P.js";import"./BO2UtWXE.js";import"./CKCLIpbs.js";import"./BlfKXJ2P.js";const De={class:"flex justify-end gap-2"},Pe=N({__name:"AddModal",props:{pagePath:{default:"/customers"},buttonKey:{default:"customers.create"}},setup(D){const d=D,{t:l}=z(),{can:p,getDeniedReason:x}=X(),_=S(()=>Ce({name:H().min(2,l("settings.profile.validation.tooShort")),email:H().email(l("settings.profile.validation.invalidEmail"))})),c=y(!1),b=re({name:"",email:""}),s=J(),f=S(()=>p(d.pagePath,d.buttonKey));function w(){s.add({title:l("permission.toast.title"),description:l(x(d.pagePath,d.buttonKey)),icon:"i-lucide-shield-alert",color:"warning"})}function U(){if(!f.value){w();return}c.value=!0}async function M(C){if(!f.value){w();return}s.add({title:l("customers.addModal.successTitle"),description:l("customers.addModal.successDescription",{name:C.data.name}),color:"success"}),c.value=!1}return(C,g)=>{const A=$,V=Q,P=ye,R=Se,I=W;return k(),F(I,{open:e(c),"onUpdate:open":g[3]||(g[3]=m=>v(c)?c.value=m:null),title:e(l)("customers.addModal.title"),description:e(l)("customers.addModal.description")},{body:r(()=>[i(R,{schema:e(_),state:e(b),class:"space-y-4",onSubmit:M},{default:r(()=>[i(P,{label:e(l)("customers.addModal.name"),placeholder:e(l)("customers.addModal.namePlaceholder"),name:"name"},{default:r(()=>[i(V,{modelValue:e(b).name,"onUpdate:modelValue":g[0]||(g[0]=m=>e(b).name=m),class:"w-full"},null,8,["modelValue"])]),_:1},8,["label","placeholder"]),i(P,{label:e(l)("customers.addModal.email"),placeholder:e(l)("customers.addModal.emailPlaceholder"),name:"email"},{default:r(()=>[i(V,{modelValue:e(b).email,"onUpdate:modelValue":g[1]||(g[1]=m=>e(b).email=m),class:"w-full"},null,8,["modelValue"])]),_:1},8,["label","placeholder"]),h("div",De,[i(A,{label:e(l)("common.cancel"),color:"neutral",variant:"subtle",onClick:g[2]||(g[2]=m=>c.value=!1)},null,8,["label"]),i(A,{label:e(l)("common.create"),color:"primary",variant:"solid",type:"submit",disabled:!e(f)},null,8,["label","disabled"])])]),_:1},8,["schema","state"])]),default:r(()=>[i(A,{label:e(l)("common.newCustomer"),icon:"i-lucide-plus",disabled:!e(f),onClick:U},null,8,["label","disabled"])]),_:1},8,["open","title","description"])}}}),ke=Object.assign(Pe,{__name:"CustomersAddModal"}),Fe={class:"flex justify-end gap-2"},Re=N({__name:"DeleteModal",props:{count:{default:0}},setup(D){const d=D,{t:l}=z(),p=y(!1),x=S(()=>l("customers.deleteModal.title",{count:d.count,suffix:d.count>1?"s":""}));async function t(){await new Promise(_=>setTimeout(_,1e3)),p.value=!1}return(_,c)=>{const b=$,s=W;return k(),F(s,{open:e(p),"onUpdate:open":c[1]||(c[1]=f=>v(p)?p.value=f:null),title:e(x),description:e(l)("customers.deleteModal.description")},{body:r(()=>[h("div",Fe,[i(b,{label:e(l)("common.cancel"),color:"neutral",variant:"subtle",onClick:c[0]||(c[0]=f=>p.value=!1)},null,8,["label"]),i(b,{label:e(l)("common.delete"),color:"error",variant:"solid","loading-auto":"",onClick:t},null,8,["label"])])]),default:r(()=>[ce(_.$slots,"default")]),_:3},8,["open","title","description"])}}}),Ie=Object.assign(Re,{__name:"CustomersDeleteModal"}),Te={class:"flex flex-wrap items-center justify-between gap-1.5"},Ke={class:"flex flex-wrap items-center gap-1.5"},je={class:"flex items-center justify-between gap-3 border-t border-default pt-4 mt-auto"},Be={class:"text-sm text-muted"},Ne={class:"flex items-center gap-1.5"},G="/customers",ct=N({__name:"customers",async setup(D){let d,l;const p=$,x=q,{t}=z(),_=J(),{can:c,getDeniedReason:b}=X(),s=me("table"),f=$e(),w=S(()=>c(G,"customers.delete")),U=y([{id:"email",value:""}]),M=y(),C=y({1:!0}),{data:g,status:A}=([d,l]=de(()=>f.getCustomers()),d=await d,l(),d);function V(a){_.add({title:t("permission.toast.title"),description:t(b(G,a)),icon:"i-lucide-shield-alert",color:"warning"})}function P(a){return[{type:"label",label:t("customers.table.actions")},{label:t("customers.table.copyCustomerId"),icon:"i-lucide-copy",onSelect(){navigator.clipboard.writeText(a.original.id.toString()),_.add({title:t("customers.table.copiedTitle"),description:t("customers.table.copiedDescription")})}},{type:"separator"},{label:t("customers.table.viewDetails"),icon:"i-lucide-list"},{label:t("customers.table.viewPayments"),icon:"i-lucide-wallet"},{type:"separator"},{label:t("customers.table.deleteCustomer"),icon:"i-lucide-trash",color:"error",disabled:!w.value,onSelect(){if(!w.value){V("customers.delete");return}_.add({title:t("customers.table.deletedTitle"),description:t("customers.table.deletedDescription")})}}]}function R(){if(!w.value){V("customers.delete");return}}const I=S(()=>[{id:"select",header:({table:a})=>u(E,{modelValue:a.getIsSomePageRowsSelected()?"indeterminate":a.getIsAllPageRowsSelected(),"onUpdate:modelValue":o=>a.toggleAllPageRowsSelected(!!o),ariaLabel:t("customers.table.selectAll")}),cell:({row:a})=>u(E,{modelValue:a.getIsSelected(),"onUpdate:modelValue":o=>a.toggleSelected(!!o),ariaLabel:t("customers.table.selectRow")})},{accessorKey:"id",header:t("customers.table.id")},{accessorKey:"name",header:t("customers.table.name"),cell:({row:a})=>u("div",{class:"flex items-center gap-3"},[u(ge,{...a.original.avatar,size:"lg"}),u("div",void 0,[u("p",{class:"font-medium text-highlighted"},a.original.name),u("p",{class:""},`@${a.original.name}`)])])},{accessorKey:"email",header:({column:a})=>{const o=a.getIsSorted();return u($,{color:"neutral",variant:"ghost",label:t("customers.table.email"),icon:o?o==="asc"?"i-lucide-arrow-up-narrow-wide":"i-lucide-arrow-down-wide-narrow":"i-lucide-arrow-up-down",class:"-mx-2.5",onClick:()=>a.toggleSorting(a.getIsSorted()==="asc")})}},{accessorKey:"location",header:t("customers.table.location"),cell:({row:a})=>a.original.location},{accessorKey:"status",header:t("customers.table.status"),filterFn:"equals",cell:({row:a})=>{const o=a.original.status,j={subscribed:"success",unsubscribed:"error",bounced:"warning"}[o];return u(_e,{class:"capitalize",variant:"subtle",color:j},()=>t(`customers.status.${o}`))}},{id:"actions",cell:({row:a})=>u("div",{class:"text-right"},u(q,{content:{align:"end"},items:P(a)},()=>u($,{icon:"i-lucide-ellipsis-vertical",color:"neutral",variant:"ghost",class:"ml-auto"})))}]),m=y("all");ue(()=>m.value,a=>{if(!s?.value?.tableApi)return;const o=s.value.tableApi.getColumn("status");o&&(a==="all"?o.setFilterValue(void 0):o.setFilterValue(a))});const T=S({get:()=>s.value?.tableApi?.getColumn("email")?.getFilterValue()||"",set:a=>{s.value?.tableApi?.getColumn("email")?.setFilterValue(a||void 0)}}),Y=S(()=>[{label:t("customers.status.all"),value:"all"},{label:t("customers.status.subscribed"),value:"subscribed"},{label:t("customers.status.unsubscribed"),value:"unsubscribed"},{label:t("customers.status.bounced"),value:"bounced"}]),K=y({pageIndex:0,pageSize:10}),L={id:"customers.table.id",name:"customers.table.name",email:"customers.table.email",location:"customers.table.location",status:"customers.table.status"};return(a,o)=>{const j=he,Z=ke,ee=we,te=Q,ae=xe,oe=Ie,le=Ue,se=Ae,ne=fe,ie=ve;return k(),F(ie,{id:"customers"},{header:r(()=>[i(ee,{title:e(t)("customers.title")},{leading:r(()=>[i(j)]),right:r(()=>[i(Z,{"page-path":"/customers","button-key":"customers.create"})]),_:1},8,["title"])]),body:r(()=>[h("div",Te,[i(te,{modelValue:e(T),"onUpdate:modelValue":o[0]||(o[0]=n=>v(T)?T.value=n:null),class:"max-w-sm",icon:"i-lucide-search",placeholder:e(t)("customers.table.filterEmails")},null,8,["modelValue","placeholder"]),h("div",Ke,[i(oe,{count:e(s)?.tableApi?.getFilteredSelectedRowModel().rows.length},{default:r(()=>[e(s)?.tableApi?.getFilteredSelectedRowModel().rows.length?(k(),F(e(p),{key:0,label:e(t)("common.delete"),color:"error",variant:"subtle",icon:"i-lucide-trash",disabled:!e(w),onClick:R},{trailing:r(()=>[i(ae,null,{default:r(()=>[pe(O(e(s)?.tableApi?.getFilteredSelectedRowModel().rows.length),1)]),_:1})]),_:1},8,["label","disabled"])):be("",!0)]),_:1},8,["count"]),i(le,{modelValue:e(m),"onUpdate:modelValue":o[1]||(o[1]=n=>v(m)?m.value=n:null),items:e(Y),ui:{trailingIcon:"group-data-[state=open]:rotate-180 transition-transform duration-200"},placeholder:e(t)("customers.table.filterStatus"),class:"min-w-28"},null,8,["modelValue","items","placeholder"]),i(e(x),{items:e(s)?.tableApi?.getAllColumns().filter(n=>n.getCanHide()).map(n=>({label:L[n.id]?e(t)(L[n.id]):e(Me)(n.id),type:"checkbox",checked:n.getIsVisible(),onUpdateChecked(B){e(s)?.tableApi?.getColumn(n.id)?.toggleVisibility(!!B)},onSelect(B){B?.preventDefault()}})),content:{align:"end"}},{default:r(()=>[i(e(p),{label:e(t)("customers.table.display"),color:"neutral",variant:"outline","trailing-icon":"i-lucide-settings-2"},null,8,["label"])]),_:1},8,["items"])])]),i(se,{ref_key:"table",ref:s,"column-filters":e(U),"onUpdate:columnFilters":o[2]||(o[2]=n=>v(U)?U.value=n:null),"column-visibility":e(M),"onUpdate:columnVisibility":o[3]||(o[3]=n=>v(M)?M.value=n:null),"row-selection":e(C),"onUpdate:rowSelection":o[4]||(o[4]=n=>v(C)?C.value=n:null),pagination:e(K),"onUpdate:pagination":o[5]||(o[5]=n=>v(K)?K.value=n:null),"pagination-options":{getPaginationRowModel:e(Ve)()},class:"shrink-0",data:e(g),columns:e(I),loading:e(A)==="pending",ui:{base:"table-fixed border-separate border-spacing-0",thead:"[&>tr]:bg-elevated/50 [&>tr]:after:content-none",tbody:"[&>tr]:last:[&>td]:border-b-0",th:"py-2 first:rounded-l-lg last:rounded-r-lg border-y border-default first:border-l last:border-r",td:"border-b border-default",separator:"h-0"}},null,8,["column-filters","column-visibility","row-selection","pagination","pagination-options","data","columns","loading"]),h("div",je,[h("div",Be,O(e(t)("customers.table.selectedRows",{selected:e(s)?.tableApi?.getFilteredSelectedRowModel().rows.length||0,total:e(s)?.tableApi?.getFilteredRowModel().rows.length||0})),1),h("div",Ne,[i(ne,{"default-page":(e(s)?.tableApi?.getState().pagination.pageIndex||0)+1,"items-per-page":e(s)?.tableApi?.getState().pagination.pageSize,total:e(s)?.tableApi?.getFilteredRowModel().rows.length,"onUpdate:page":o[6]||(o[6]=n=>e(s)?.tableApi?.setPageIndex(n-1))},null,8,["default-page","items-per-page","total"])])])]),_:1})}}});export{ct as default};