1import{a9 as b,aa as p,ab as N,ac as j,ad as y,u as P,r as d,j as e,L as v,T as w,ae as C,af as R,v as E}from"./index-BUCFbuLp.js";import{f as S}from"./format-CRbf4Bhs.js";import{C as k}from"./circle-alert-CSN6_jT9.js";import{L as A}from"./loader-circle-DDgcSI5K.js";import{C as F}from"./check-CQuVRh8U.js";import{C as I}from"./clock-Vh7a7OWP.js";var M=class extends b{constructor(t,a){super(t,a)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(t){super.setOptions({...t,behavior:p()})}getOptimisticResult(t){return t.behavior=p(),super.getOptimisticResult(t)}fetchNextPage(t){return this.fetch({...t,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(t){return this.fetch({...t,meta:{fetchMore:{direction:"backward"}}})}createResult(t,a){const{state:s}=t,n=super.createResult(t,a),{isFetching:i,isRefetching:r,isError:c,isRefetchError:l}=n,o=s.fetchMeta?.fetchMore?.direction,x=c&&o==="forward",u=i&&o==="forward",h=c&&o==="backward",f=i&&o==="backward";return{...n,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:j(a,s.data),hasPreviousPage:N(a,s.data),isFetchNextPageError:x,isFetchingNextPage:u,isFetchPreviousPageError:h,isFetchingPreviousPage:f,isRefetchError:l&&!x&&!h,isRefetching:r&&!u&&!f}}};function L(t,a){return y(t,M)}const m=12;function D(){const{user:t,isAuthenticated:a}=P(),[s,n]=d.useState("active");return!a||!t?e.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-16 text-center md:px-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Sign in to see your sales"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"Track active and completed sales in one place."}),e.jsx(v,{to:"/login",className:"mt-6 inline-block rounded-full brand-gradient px-5 py-2.5 text-sm font-semibold text-primary-foreground",children:"Sign in"})]}):e.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6 md:py-10",children:[e.jsx("h1",{className:"mb-5 text-2xl font-bold md:text-3xl",children:"Sales"}),e.jsx("div",{className:"mb-5 flex gap-2",children:["active","completed"].map(i=>{const r=s===i;return e.jsx("button",{onClick:()=>n(i),className:"rounded-full px-4 py-2 text-sm font-semibold transition "+(r?"bg-primary/10 text-primary":"bg-muted text-muted-foreground hover:text-foreground"),children:i==="active"?"Active":"Completed"},i)})}),s==="active"?e.jsx(g,{userId:t.id,kind:"active"}):e.jsx(g,{userId:t.id,kind:"completed"})]})}function g({userId:t,kind:a}){const s=L({queryKey:["storefront",t,`${a}-sales`,{limit:m}],initialPageParam:0,queryFn:({pageParam:r})=>(a==="active"?C:R)(t,{limit:m,offset:r}),getNextPageParam:(r,c)=>{if(!(!Array.isArray(r)||r.length<m))return c.reduce((l,o)=>l+(Array.isArray(o)?o.length:0),0)},staleTime:3e4}),n=d.useMemo(()=>(s.data?.pages??[]).flat(),[s.data]),i=d.useRef(null);return d.useEffect(()=>{const r=i.current;if(!r)return;const c=new IntersectionObserver(l=>{l[0]?.isIntersecting&&s.hasNextPage&&!s.isFetchingNextPage&&s.fetchNextPage()},{rootMargin:"240px 0px"});return c.observe(r),()=>c.disconnect()},[s]),s.isLoading?e.jsx("div",{className:"space-y-4",children:[0,1,2,3].map(r=>e.jsx("div",{className:"h-[88px] animate-pulse rounded-2xl bg-muted"},r))}):s.isError&&n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center rounded-3xl border border-destructive/30 bg-destructive/5 py-12 text-center",children:[e.jsx(k,{className:"h-9 w-9 text-destructive"}),e.jsx("p",{className:"mt-3 text-base font-semibold",children:"Could not load sales"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Please try again in a moment."})]}):n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center rounded-3xl border border-border bg-card py-14 text-center",children:[e.jsx(w,{className:"h-9 w-9 text-muted-foreground"}),e.jsx("p",{className:"mt-3 text-base font-semibold",children:a==="active"?"No active sales":"No completed sales"}),e.jsx("p",{className:"mt-1 max-w-sm px-4 text-sm text-muted-foreground",children:a==="active"?"Sales in progress will appear here.":"Completed sales will show up here once they're finished."})]}):e.jsxs("div",{className:"divide-y divide-border rounded-3xl border border-border bg-card",children:[n.map(r=>e.jsx(O,{sale:r,forceCompleted:a==="completed"},r.id)),e.jsx("div",{ref:i}),s.isFetchingNextPage?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(A,{className:"h-5 w-5 animate-spin text-primary"})}):null]})}function O({sale:t,forceCompleted:a}
1){const[s,n]=d.useState(!1),i=!!t.photo&&!s,r=a||t.status==="completed";return e.jsxs(v,{to:"/sale/$id",params:{id:t.id},className:"flex items-start justify-between gap-3 p-4 transition hover:bg-muted/40",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("div",{className:"grid h-[74px] w-[74px] shrink-0 place-items-center overflow-hidden rounded-2xl bg-muted",children:i?e.jsx("img",{src:t.photo,alt:"",className:"h-full w-full object-cover",onError:()=>n(!0)}):e.jsx(E,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"truncate text-sm font-semibold",children:t.description||"Untitled"}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:["To ",t.buyer_name||"â"]})]}),r?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-semibold text-emerald-700",children:[e.jsx(F,{className:"h-3 w-3"})," Completed"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-50 px-2 py-0.5 text-[11px] font-semibold text-amber-700",children:[e.jsx(I,{className:"h-3 w-3"})," In progress"]})]})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("p",{className:"text-sm font-bold",children:S(t.price??0)}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t.created_time})]})]})}export{D as component};
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.