1var __IMPORT_META_ENV={};var __PROCESS_ENV={NODE_ENV:"production"}; 2import{a as D}from"/chunks/chunk-A6NSEO7N.js";import{Ww as y,eC as C,fe as S,gB as k}from"/chunks/chunk-62QHDT2Z.js";import{c as g}from"/chunks/chunk-EWMNDR7R.js";import"/chunks/chunk-ZP4OMTXP.js";import"/chunks/chunk-DKSMBCPM.js";import"/chunks/chunk-Z2TP6DSD.js";import"/chunks/chunk-GQOIBJBD.js";import"/chunks/chunk-PE5MZRD7.js";import{a as E}from"/chunks/chunk-2F2XG2RD.js";import{d as w}from"/chunks/chunk-43M3N6VY.js";var p=w(E());var e=w(D()),N={day:"Jour",week:"Semaine",month:"Mois"};function P(a,s){if(!a)return!1;let o=new Date(a),l=new Date;if(s==="day")return o.toDateString()===l.toDateString();if(s==="week"){let b=new Date(l);return b.setDate(l.getDate()-7),o>=b}let c=new Date(l);return c.setMonth(l.getMonth()-1),o>=c}function L(a){let s=new Date(a),o=new Date(s);return o.setDate(s.getDate()-s.getDay()+1),o.toISOString().split("T")[0]}function R({orders:a,totalCA:s}){let[o,l]=(0,p.useState)("week"),[c,b]=(0,p.useState)(!1),f=(0,p.useMemo)(()=>{let t=a.filter(r=>P(r.createdAt,o)),u=t.reduce((r,A)=>r+A.total,0),x=t.length,n=new Set(t.map(r=>r.email?.toLowerCase()).filter(Boolean)),i=new Set(a.filter(r=>!P(r.createdAt,o)).map(r=>r.email?.toLowerCase()).filter(Boolean)),d=[...n].filter(r=>!i.has(r)).length,m=x>0?u/x:0;return{ca:u,count:x,newClients:d,avgBasket:m}},[a,o]),v=(0,p.useMemo)(()=>{let t=new Map,u=new Set,x=[...a].sort((n,i)=>n.createdAt.localeCompare(i.createdAt));for(let n of x){if(!n.createdAt)continue;let i=L(n.createdAt),d=t.get(i)||{ca:0,count:0,newEmails:0};d.ca+=n.total,d.count++;let m=n.email?.toLowerCase();m&&!u.has(m)&&(u.add(m),d.newEmails++),t.set(i,d)}return Array.from(t.entries()).sort((n,i)=>i[0].localeCompare(n[0])).slice(0,8).map(([n,i])=>{let d=new Date(n),m=new Date(d);return m.setDate(d.getDate()+6),{label:`${d.toLocaleDateString("fr-FR",{day:"2-digit",month:"2-digit"})} \u2013 ${m.toLocaleDateString("fr-FR",{day:"2-digit",month:"2-digit"})}`,...i}})},[a]);return(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsx)("div",{className:"flex items-center gap-1.5",children:["day","week","month"].map(t=>(0,e.jsx)("button",{onClick:()=>l(t),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${o===t?"bg-foreground text-background":"bg-muted/60 text-muted-foreground hover:text-foreground"}`,children:N[t]},t))}),(0,e.jsxs)("button",{onClick:()=>b(!c),className:"flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground",children:[(0,e.jsx)(S,{className:"w-3 h-3"})," ",c?"Masquer rapports":"Rapports hebdo"]})]}),(0,e.jsxs)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5",children:[(0,e.jsx)(h,{icon:k,label:"CA",value:g(f.ca),sub:`Total: ${g(s)}`,color:"text-emerald-500"}),(0,e.jsx)(h,{icon:y,label:"Ventes",value:String(f.count),sub:`${N[o].toLowerCase()}`,color:"text-blue-500"}),(0,e.jsx)(h,{icon:C,label:"Nouveaux clients",value:String(f.newClients),sub:`${N[o].toLowerCase()}`,color:"text-purple-500"}),(0,e.jsx)(h,{icon:y,label:"Panier moyen",value:g(f.avgBasket),sub:`sur ${f.count} cmd`,color:"text-amber-500"})]}),c&&v.length>=1&&(0,e.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,e.jsxs)("table",{className:"w-full text-xs",children:[(0,e.jsx)("thead",{className:"bg-muted/50",children:(0,e.jsxs)("tr",{children:[(0,e.jsx)("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground",children:"Semaine"}),(0,e.jsx)("th",{className:"px-3 py-2 text-right font-medium text-muted-foreground",children:"CA"}),(0,e.jsx)("th",{className:"px-3 py-2 text-right font-medium text-muted-foreground",children:"Ventes"}),(0,e.jsx)("th",{className:"px-3 py-2 text-right font-medium text-muted-foreground",children:"Nvx clients"}),(0,e.jsx)("th",{className:"px-3 py-2 text-right font-medium text-muted-foreground",children:"\xD8 Panier"})]})}),(0,e.jsx)("tbody",{children:v.map((t,u)=>(0,e.jsxs)("tr",{className:"border-t border-border hover:bg-muted/20",children:[(0,e.jsx)("td",{className:"px-3 py-2 font-medium",children:t.label}),(0,e.jsx)("td",{className:"px-3 py-2 text-right tabular-nums font-medium",children:g(t.ca)}),(0,e.jsx)("td",{className:"px-3 py-2 text-right tabular-nums",children:t.count}),(0,e.jsx)("td",{className:"px-3 py-2 text-right tabular-nums",children:t.newEmails}),(0,e.jsx)("td",{className:"px-3 py-2 text-right tabular-nums",children:t.count>=1?g(t.ca/t.count):"\u2014"})]},u))})]})})]})}function h({icon:a,label:s,value:o,sub:l,color:c}){return(0,e.jsxs)("div",{className:"p-3 rounded-xl border border-border",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1.5 mb-1.5",children:[(0,e.jsx)(a,{className:`w-3.5 h-3.5 ${c}`}),(0,e.jsx)("span",{className:"text-[10px] text-muted-foreground font-medium",children:s})]}),(0,e.jsx)("p",{className:"text-lg font-bold tabular-nums leading-tight",children:o}),(0,e.jsx)("p",{className:"text-[9px] text-muted-foreground mt-0.5",children:l})]})}
2export{R 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.