1import{a3 as I,j as e,A as E,m as N,ba as v,bb as w,bc as y,B as L,k as j,l as n,X as V,a6 as W,M as C,aG as O,a0 as H,aP as J,a8 as _,$ as M,U as D,aV as G,S as X,I as q}from"./App-Cg173DAt.js";import{r as T}from"./index-caxmlYbZ.js";import{C as A,b as F}from"./card-698OG_lS.js";import{T as K,a as Q,b,c as d,d as Y,e as r}from"./table-d1MHdUxV.js";import{h as Z,i as ee}from"./useAdminData-lz2wMfSv.js";import{u as se}from"./use-mobile-D3273OON.js";import{u as ae}from"./useDebouncedValue-BKSTyU8a.js";import{I as te}from"./InfiniteScrollSentinel-DyLiA_Uo.js";import{C as le}from"./copy-CQqhbZih.js";import{I as re,L as ie}from"./linkedin-DQbi096r.js";import{T as ne}from"./twitter-BdB0RHfw.js";import{C as $}from"./calendar-jzsAUYk7.js";import{f as de}from"./formatDistanceToNow-ukJeSM4z.js";import{f as p}from"./format-wcA9gTUs.js";import{P as oe,A as ce,C as xe,a as me}from"./AdminAnimations-BCkauIpp.js";import{u as he,S as U,i as pe}from"./SignedBadge-M6RCNJjS.js";import"./index--RATyRBH.js";import"./index-DIE_uK0V.js";import"./i18nInstance-C81hCH34.js";import"./useInfinitePaged-2MCTLR0C.js";import"./en-US-4RaJY4CL.js";import"./policySignature-BjJIkJIz.js";import"./shield-alert-BKbsL7tm.js";const je=({customer:a,onClose:c})=>{var l;const{formatPrice:f}=I();if(!a)return null;const g=()=>{if(!a.phone){M({title:"No phone number",description:"This customer has no phone number."});return}const i=a.phone.replace(/\D/g,""),m=`Hi ${a.full_name||"there"}, `;window.open(`https://wa.me/${i}?text=${encodeURIComponent(m)}`,"_blank")},x=()=>{a.email&&(navigator.clipboard.writeText(a.email),M({title:"Copied",description:"Email copied to clipboard"}))},u=a.social_instagram||a.social_twitter||a.social_linkedin||a.social_website,o=((l=a.full_name)==null?void 0:l.split(" ").map(i=>i[0]).join("").toUpperCase().slice(0,2))||"U";return e.jsx(E,{children:e.jsxs(N.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx(N.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/50 dark:bg-black/70 backdrop-blur-sm",onClick:c}),e.jsxs(N.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-[calc(100%-1.5rem)] sm:w-full max-w-lg max-h-[85vh] overflow-y-auto bg-card rounded-2xl border border-border shadow-xl",children:[e.jsx("div",{className:"h-1.5 bg-gradient-to-r from-accent via-primary to-primary rounded-t-2xl"}),e.jsxs("div",{className:"p-5 sm:p-6 pb-0 flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"p-0.5 rounded-full bg-gradient-to-br from-primary to-accent",children:e.jsxs(v,{className:"w-14 h-14 border-2 border-card",children:[e.jsx(w,{src:a.avatar_url||void 0,alt:a.full_name||""}),e.jsx(y,{className:"bg-primary/10 text-primary font-bold text-lg",children:o})]})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-lg font-bold truncate",children:a.full_name||"Unnamed"}),a.job_title&&e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(L,{className:"w-3 h-3 shrink-0"}),e.jsx("span",{className:"truncate",children:a.job_title})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(j,{variant:"secondary",className:"text-[10px]",children:a.orderCount>0?"Active Buyer":"Registered"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["Joined ",de(new Date(a.created_at),{addSuffix:!0})]})]})]})]}),e.jsx(n,{variant:"ghost",size:"icon",onClick:c,className:"shrink-0 -mt-1 -mr-1",children:e.jsx(V,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 sm:p-6 space-y-5",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-gradient-to-br from-muted/80 to-muted/40 border border-border/50 space-y-3",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4 text-primary"}),"Contact Information"]}),e.jsxs("div",{className:"space-y-2.5",children:[a.email&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(C,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("a",{href:`mailto:${a.email}`,className:"text-sm hover:text-primary transition-colors truncate",children:a.email})]}),e.jsx(n,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:x,children:e.jsx(le,{className:"w-3 h-3"})})]}),a.phone&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("a",{href:`tel:${a.phone}`,className:"text-sm hover:text-primary transition-colors",children:a.phone})]}),!a.email&&!a.phone&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No contact information"})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[a.phone&&e.jsxs(n,{variant:"outline",size:"sm",className:"text-xs gap-1.5",onClick:g,children:[e.jsx(H,{className:"w-3 h-3"}),"WhatsApp"]}),a.email&&e.jsx(n,{variant:"outline",size:"sm",className:"text-xs gap-1.5",asChild:!0,children:e.jsxs("a",{href:`mailto:${a.email}`,children:[e.jsx(C,{className:"w-3 h-3"}),"Email"]})})]})]}),u&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.social_instagram&&e.jsx(n,{variant:"outline",size:"sm",className:"text-xs gap-1.5",asChild:!0,children:e.jsxs("a",{href:`https://instagram.com/${a.social_instagram}`,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(re,{className:"w-3.5 h-3.5"}),"Instagram"]})}),a.social_twitter&&e.jsx(n,{variant:"outline",size:"sm",className:"text-xs gap-1.5",asChild:!0,children:e.jsxs("a",{href:`https://x.com/${a.social_twitter}`,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ne,{className:"w-3.5 h-3.5"}),"X"]})}),a.social_linkedin&&e.jsx(n,{variant:"outline",size:"sm",className:"text-xs gap-1.5",asChild:!0,children:e.jsxs("a",{href:a.social_linkedin,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ie,{className:"w-3.5 h-3.5"}),"LinkedIn"]})}),a.social_website&&e.jsx(n,{variant:"outline",size:"sm",className:"text-xs gap-1.5",asChild:!0,children:e.jsxs("a",{href:a.social_website,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Website"]})})]}),a.bio&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Bio"}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:a.bio})]}),a.interests&&a.interests.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Interests"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.interests.map((i,m)=>e.jsx(j,{variant:"secondary",className:"text-xs",children:i},m))})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-muted/50 text-center",children:[e.jsx(_,{className:"w-4 h-4 text-primary mx-auto mb-1"}),e.jsx("p",{className:"text-lg font-bold",children:a.orderCount}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Orders"})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-muted/50 text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Spent"}),e.jsx("p",{className:"text-sm font-bold text-primary",children:a.totalSpent>0?f(a.totalSpent):"â"})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-muted/50 text-center",children:[e.jsx($,{className:"w-4 h-4 text-muted-foreground mx-auto mb-1"}),e.jsx("p",{className:"text-xs font-medium",children:a.lastOrder?p(new Date(a.lastOrder),"MMM d"):"â"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Last Order"})]})]})]})]})]})})};function Re(){const a=se(),[c,f]=T.useState(""),[g,x]=T.useState(null),u=ae(c,300),{formatPrice:o}=I(),{rows:l,isLoading:i,hasNextPage:m,isLoadingMore:B,loadMore:P}=Z({search:u}),{data:t}
1=ee(),{data:z}=he(l.map(s=>s.phone),l.map(s=>s.user_id)),k=s=>pe(z,s.phone,s.user_id),S=s=>(s==null?void 0:s.split(" ").map(h=>h[0]).join("").toUpperCase().slice(0,2))||"U",R=[{label:"Total Customers",value:(t==null?void 0:t.totalCustomers)??0,icon:D},{label:"Active Buyers",value:(t==null?void 0:t.activeCustomers)??0,icon:_},{label:"Total Revenue",value:o((t==null?void 0:t.totalRevenue)??0),icon:G,countUp:!1},{label:"Avg Order Value",value:((t==null?void 0:t.avgOrderValue)??0)>0?o(t.avgOrderValue):"â",icon:_,countUp:!1}];return e.jsx(oe,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold lg:text-xl",children:"Customers"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"View registered users and their activity"})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:R.map((s,h)=>e.jsx(ce,{title:s.label,value:s.value,icon:s.icon,index:h,countUp:s.countUp!==!1},s.label))}),e.jsxs("div",{className:"relative",children:[e.jsx(X,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(q,{placeholder:"Search by name, email, or phone...",value:c,onChange:s=>f(s.target.value),className:"pl-10"})]}),i?e.jsx(xe,{count:5}):a?e.jsx("div",{className:"space-y-3",children:l.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground text-sm",children:"No customers found"}):l.map((s,h)=>e.jsx(me,{index:h,children:e.jsx(A,{className:`cursor-pointer hover:border-primary/50 hover:shadow-sm transition-all duration-200 overflow-hidden ${s.orderCount>0?"border-l-2 border-l-emerald-500":"border-l-2 border-l-muted"}`,onClick:()=>x(s),children:e.jsxs(F,{className:"p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(v,{className:"w-9 h-9",children:[e.jsx(w,{src:s.avatar_url||void 0,alt:""}),e.jsx(y,{className:"bg-muted text-muted-foreground text-xs font-bold",children:S(s.full_name)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"font-medium text-sm truncate",children:s.full_name||"Unnamed"}),e.jsx(U,{signed:k(s),showLabel:!1})]}),s.email&&e.jsxs("p",{className:"text-xs text-muted-foreground truncate flex items-center gap-1",children:[e.jsx(C,{className:"w-3 h-3 shrink-0"}),s.email]}),s.phone&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(O,{className:"w-3 h-3 shrink-0"}),s.phone]})]})]}),s.job_title&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(L,{className:"w-3 h-3 shrink-0"}),s.job_title]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(j,{variant:"secondary",className:"text-[10px]",children:[s.orderCount," orders"]}),e.jsx("span",{className:"font-medium text-primary",children:s.totalSpent>0?o(s.totalSpent):"â"})]}),e.jsxs("span",{className:"text-muted-foreground flex items-center gap-1",children:[e.jsx($,{className:"w-3 h-3"}),p(new Date(s.created_at),"MMM d")]})]})]})})},s.user_id))}):e.jsx(A,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(K,{children:[e.jsx(Q,{children:e.jsxs(b,{children:[e.jsx(d,{children:"Customer"}),e.jsx(d,{children:"Email"}),e.jsx(d,{children:"Phone"}),e.jsx(d,{children:"Job Title"}),e.jsx(d,{children:"Orders"}),e.jsx(d,{children:"Total Spent"}),e.jsx(d,{children:"Last Order"}),e.jsx(d,{children:"Joined"})]})}),e.jsx(Y,{children:l.length===0?e.jsx(b,{children:e.jsx(r,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"No customers found"})}):l.map(s=>e.jsxs(b,{className:"hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>x(s),children:[e.jsx(r,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(v,{className:"w-8 h-8",children:[e.jsx(w,{src:s.avatar_url||void 0,alt:""}),e.jsx(y,{className:"bg-muted text-muted-foreground text-xs font-bold",children:S(s.full_name)})]}),e.jsx("span",{className:"font-medium text-sm",children:s.full_name||"Unnamed"}),e.jsx(U,{signed:k(s),showLabel:!1})]})}),e.jsx(r,{children:s.email?e.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[180px] block",children:s.email}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"â"})}),e.jsx(r,{children:e.jsx("span",{className:"text-sm text-muted-foreground",children:s.phone||"â"})}),e.jsx(r,{children:e.jsx("span",{className:"text-sm text-muted-foreground",children:s.job_title||"â"})}),e.jsx(r,{children:e.jsx(j,{variant:"secondary",children:s.orderCount})}),e.jsx(r,{className:"font-medium",children:s.totalSpent>0?o(s.totalSpent):"â"}),e.jsx(r,{className:"text-sm text-muted-foreground",children:s.lastOrder?p(new Date(s.lastOrder),"MMM d, yyyy"):"â"}),e.jsx(r,{className:"text-sm text-muted-foreground",children:p(new Date(s.created_at),"MMM d, yyyy")})]}
1,s.user_id))})]})})}),!i&&e.jsx(te,{onLoadMore:P,hasMore:!!m,loading:B,endLabel:l.length>0?`All ${l.length} customers loaded`:null}),e.jsx(je,{customer:g,onClose:()=>x(null)})]})})}export{Re as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.