1import{a as j,j as e}from"./vendor-query-ENmfDhBq.js";import{r as _,e as B}from"./vendor-react-Cmo9WzyS.js";import{k as E,e as p,C as g,i as y,B as N}from"./index-CznMJwf7.js";import{a as A}from"./useCustomerPortal-C5W5gf48.js";import{B as d}from"./badge-D-GfAQVU.js";import{S as M}from"./skeleton-CLOVS70K.js";import{a as S}from"./currency-BEM_IRAX.js";import{r as T,g as I}from"./getProductPhotoUrl-LNwQLOd3.js";import{aq as w,P as b,o as v,ar as F,b as L,a6 as D,a as H,a3 as K}from"./vendor-ui-DI8clteo.js";import{a as U}from"./format-fTIrYzIB.js";import"./vendor-pdf-CnsmIwn4.js";import"./vendor-radix-OnsNJ2sB.js";import"./vendor-supabase-INnzmioh.js";import"./vendor-charts-CNk8afJ_.js";import"./vendor-auth-Ftfj713I.js";import"./react-CNmCGiw2.js";import"./en-US-DNi5-IO7.js";import"./startOfDay-DJ_G3h2O.js";const ne=_.forwardRef(function(O,q){var f;const h=B(),{data:m}=A(),u=(f=m==null?void 0:m.customer)==null?void 0:f.id,{t:c}=E(),{data:i,isLoading:C}=j({queryKey:["customer-requests",u],enabled:!!u,queryFn:async()=>{const{data:s,error:t}=await p.from("customer_order_requests").select("*").eq("customer_id",u).order("created_at",{ascending:!1});if(t)throw t;return s||[]}}),l=_.useMemo(()=>{const s=new Set;return(i||[]).forEach(t=>{t.request_type==="reorder"&&(Array.isArray(t.items)?t.items:[]).forEach(o=>{o!=null&&o.product_id&&s.add(o.product_id)})}),Array.from(s)},[i]),{data:x}=j({queryKey:["customer-request-item-photos",l],enabled:l.length>0,queryFn:async()=>{const s=new Map,[t,o]=await Promise.all([p.from("products").select("id, primary_image_url, photos:product_catalog_photos(photo_url, is_primary)").in("id",l),p.from("product_photos").select("product_id, url, is_main").in("product_id",l)]),a=new Map;return(o.data||[]).forEach(r=>{a.has(r.product_id)||a.set(r.product_id,[]),a.get(r.product_id).push({url:r.url,is_main:r.is_main})}),(t.data||[]).forEach(r=>{const n=T(I({...r,product_photos:a.get(r.id)||[]}));n&&s.set(r.id,n)}),s}}),R=s=>{switch(s){case"reorder":return e.jsx(F,{className:"h-4 w-4 text-primary"});case"new_product":return e.jsx(b,{className:"h-4 w-4 text-amber-500"});case"quote_request":return e.jsx(v,{className:"h-4 w-4 text-blue-500"});default:return e.jsx(w,{className:"h-4 w-4"})}},P=s=>{const t=c.requests;switch(s){case"pending":return e.jsxs(d,{className:"bg-amber-100 text-amber-800",children:[e.jsx(K,{className:"h-3 w-3 mr-1"}),t.pending]});case"reviewed":return e.jsxs(d,{variant:"secondary",children:[e.jsx(H,{className:"h-3 w-3 mr-1"}),t.underReview]});case"quoted":return e.jsxs(d,{className:"bg-blue-100 text-blue-800",children:[e.jsx(v,{className:"h-3 w-3 mr-1"}),t.quoted]});case"order_created":return e.jsxs(d,{className:"bg-primary/20 text-primary",children:[e.jsx(D,{className:"h-3 w-3 mr-1"}),t.orderCreated]});case"rejected":return e.jsxs(d,{variant:"outline",children:[e.jsx(L,{className:"h-3 w-3 mr-1"}),t.declined]});default:return e.jsx(d,{variant:"outline",children:s})}},k=s=>{const t=c.requests;switch(s){case"reorder":return t.reorderRequest;case"new_product":return t.newProductRequest;case"quote_request":return t.quoteRequest;default:return s}};return e.jsxs("div",{ref:q,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:c.requests.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.requests.subtitle})]}),C?e.jsx("div",{className:"space-y-3",children:[...Array(3)].map((s,t)=>e.jsx(M,{className:"h-24"},t))}):!i||i.length===0?e.jsx(g,{children:e.jsxs(y,{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx(w,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsx("p",{className:"font-medium",children:c.requests.noRequestsYet}),e.jsx("p",{className:"text-sm",children:c.requests.noRequestsDesc}),e.jsx(N,{className:"mt-4",onClick:()=>h("/customer/products"),children:c.requests.browseProducts})]})}):e.jsx("div",{className:"space-y-3",children:i.map(s=>{const t=Array.isArray(s.items)?s.items:[],o=s.estimated_total||t.reduce((a,r)=>a+(r.quantity||0)*(r.last_price||0),0);return e.jsx(g,{className:"hover:border-primary/30 transition-colors",children:e.jsx(y,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"mt-0.5",children:R(s.request_type)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm",children:k(s.request_type)}),P(s.status)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:U(new Date(s.created_at),"MMM d, yyyy · HH:mm")}
1),s.request_type==="reorder"&&t.length>0&&e.jsxs("div",{className:"mt-2 space-y-1.5",children:[e.jsxs("div",{className:"flex gap-1.5 flex-wrap",children:[t.slice(0,5).map((a,r)=>{const n=a.photo_url||a.product_id&&(x==null?void 0:x.get(a.product_id))||a.primary_image_url;return e.jsx("div",{className:"h-10 w-10 rounded bg-muted overflow-hidden border flex-shrink-0",children:n?e.jsx("img",{src:n,alt:"",className:"h-full w-full object-cover"}):e.jsx("div",{className:"h-full w-full flex items-center justify-center",children:e.jsx(b,{className:"h-3 w-3 text-muted-foreground/30"})})},r)}),t.length>5&&e.jsxs("div",{className:"h-10 w-10 rounded bg-muted flex items-center justify-center text-xs text-muted-foreground border",children:["+",t.length-5]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.length," ",t.length!==1?c.requests.itemsPlural:c.requests.items," · ",t.reduce((a,r)=>a+(r.quantity||0),0).toLocaleString()," ",c.requests.pcs]})]}),s.request_type==="new_product"&&s.new_product_description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 truncate max-w-[300px]",children:s.new_product_description}),s.status_message&&e.jsx("p",{className:"text-xs text-primary mt-1",children:s.status_message})]})]}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[o>0&&e.jsx("p",{className:"font-mono font-semibold text-sm",children:S(o)}),s.status==="order_created"&&s.created_order_id&&e.jsxs(N,{variant:"link",size:"sm",className:"text-xs h-auto p-0 mt-1",onClick:()=>h(`/customer/orders/${s.created_order_id}`),children:[c.requests.viewOrder," ",s.created_order_number||""]})]})]})})},s.id)})})]})});export{ne 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.