import{A as i,s as n}from"./index-C-9v46qO.js";async function h(){const{data:t,error:s}=await n.from("orders").select("*").order("created_at",{ascending:!1}).limit(500);if(s)throw new Error(s.message);return t??[]}const v=()=>i({queryKey:["admin","orders"],queryFn:h,staleTime:1e4});async function _(){const{data:t,error:s}=await n.from("products").select("id, slug, name, category, fabric, description, price, old_price, sizes, is_active, is_new, is_bestseller, display_order, created_at, product_variants(id, color_name, color_hex, image_url, display_order)").order("display_order",{ascending:!0});if(s)throw new Error(s.message);return t??[]}const D=()=>i({queryKey:["admin","products"],queryFn:_,staleTime:1e4});async function y(){const{data:t,error:s}=await n.from("blacklisted_phones").select("id, phone, reason, created_at").order("created_at",{ascending:!1});if(s)throw new Error(s.message);return t??[]}const A=()=>i({queryKey:["admin","blacklist"],queryFn:y,staleTime:3e4});async function w(){const[t,s]=await Promise.all([n.from("orders").select("status, payment_status, total_amount, shipping_cost, customer_phone, is_flagged, created_at"),n.from("products").select("is_active")]);if(t.error)throw new Error(t.error.message);if(s.error)throw new Error(s.error.message);const l=Date.now()-1440*60*1e3,r=t.data??[],d=s.data??[],u=new Set(r.map(e=>e.customer_phone)).size,m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],f=new Date().getFullYear(),o=new Map;for(let e=0;e<12;e++)o.set(e,{orders:0,revenue:0});for(const e of r){const a=new Date(e.created_at);if(a.getFullYear()!==f)continue;const g=a.getMonth(),c=o.get(g);c.orders+=1,(e.payment_status==="paid"||e.status==="delivered")&&(c.revenue+=Number(e.total_amount))}const p=m.map((e,a)=>({month:e,orders:o.get(a).orders,revenue:o.get(a).revenue}));return{totalSale:r.filter(e=>e.status==="delivered").length,totalProducts:d.length,activeProducts:d.filter(e=>e.is_active).length,totalCustomers:u,pendingOrders:r.filter(e=>e.status==="pending").length,confirmedOrders:r.filter(e=>e.status==="confirmed").length,shippedOrders:r.filter(e=>e.status==="shipped").length,deliveredOrders:r.filter(e=>e.status==="delivered").length,cancelledOrders:r.filter(e=>e.status==="cancelled").length,flaggedOrders:r.filter(e=>e.is_flagged).length,totalRevenue:r.filter(e=>e.status==="delivered").reduce((e,a)=>e+Number(a.total_amount),0),deliveryEarned:r.filter(e=>e.status==="delivered").reduce((e,a)=>e+Number(a.shipping_cost),0),pendingAmount:r.filter(e=>e.payment_status==="unpaid"&&e.status!=="cancelled").reduce((e,a)=>e+Number(a.total_amount),0),todayOrders:r.filter(e=>new Date(e.created_at).getTime()>l).length,totalOrders:r.length,monthlyOrders:p}}const T=()=>i({queryKey:["admin","dashboard-stats"],queryFn:w,staleTime:1e4});function S(t){return`৳${Number(t).toLocaleString("bn-BD",{maximumFractionDigits:0})}`}function q(t){return(typeof t=="string"?new Date(t):t).toLocaleString("bn-BD",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}const E={pending:"অপেক্ষমান",confirmed:"নিশ্চিত",shipped:"শিপড",delivered:"ডেলিভারড",cancelled:"বাতিল"},F={unpaid:"অপরিশোধিত",paid:"পরিশোধিত",refunded:"রিফান্ডেড"};export{E as O,F as P,D as a,v as b,q as c,T as d,A as e,S as f};
