import{u as c,r as d,j as e,L as o}from"./index-TmnhPDhN.js";import{u as m,A as u,b as x}from"./AppLayout-D6Er1EDx.js";import{i as h}from"./dms-data-CWIVRcv_.js";import{s as p}from"./shopService-BfAIW9qI.js";import{c as f,L as g}from"./apiClient-BjaOLWhY.js";const b=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],j=f("arrow-right",b);function _(){const a=c(),r=typeof window<"u",l=r&&localStorage.getItem("user_name")||"Distributor",i=r?localStorage.getItem("user_role"):null;d.useEffect(()=>{i||a({to:"/login"})},[i,a]);const{data:t,isLoading:n}=m({queryKey:["shops"],queryFn:()=>p.getAll()});return n?e.jsx("div",{className:"flex h-screen items-center justify-center bg-[#0a0a0b]",children:e.jsx(g,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsx(u,{title:`Hello, ${l} 🚚`,subtitle:"Pick a shop to start a new bill.",children:e.jsxs("section",{className:"card-elevated p-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold",children:"Choose a shop"}),e.jsx(o,{to:"/billing",className:"text-xs font-semibold text-primary hover:underline",children:"Go to billing →"})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2 xl:grid-cols-3",children:[t?.data?.map(s=>e.jsxs(o,{to:"/billing",className:"group card-elevated p-4 transition hover:-translate-y-0.5 hover:shadow-[var(--shadow-glow)]",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:s.name}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[s.owner," · ",s.city]})]}),e.jsx("div",{className:"grid h-9 w-9 place-items-center rounded-xl gradient-primary text-primary-foreground",children:e.jsx(x,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsx("div",{className:`rounded-full px-2 py-0.5 text-[11px] font-semibold ${Number(s.due_balance)>0?"bg-destructive/10 text-destructive":"bg-success/15 text-success"}`,children:Number(s.due_balance)>0?`Due ${h(Number(s.due_balance))}`:"All cleared"}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold text-primary opacity-0 transition group-hover:opacity-100",children:["Start bill ",e.jsx(j,{className:"h-3 w-3"})]})]})]},s.id)),(!t?.data||t?.data?.length===0)&&e.jsx("div",{className:"col-span-full py-8 text-center text-muted-foreground italic",children:"No shops found. Contact Admin to add shops."})]})]})})}export{_ as component};
