1import{r,j as e,g,a4 as u,D as i,N as n,P as C,L as P,_ as L,s as o,a3 as l}from"./index-DcYTpc4o.js";import{M as S}from"./MarketingLayout-E8cw8zos.js";import{T as R}from"./textarea-DIYwHNJI.js";import{P as F}from"./plus-B4I4ffRk.js";import"./MarketingFooter-DRXnGHuY.js";import"./primaryNav-B91M1_Xe.js";import"./taxonomy-T3fYtee2.js";import"./arrow-right-Bs7w3CzJ.js";import"./youtube-C2HP5xNY.js";import"./smartphone-ZP3fOHSj.js";import"./chevron-left-BCCQfyKe.js";import"./api-D0CJiBtC.js";import"./untyped-Cqm2QZQJ.js";import"./message-circle-BABIM89-.js";import"./phone-NquF6yhE.js";import"./RouteSEO-DUDttu11.js";import"./headClaim-DhQll8oM.js";const T={created:"bg-muted text-muted-foreground",accepted:"bg-ai/10 text-ai",picked_up:"bg-ai/10 text-ai",in_transit:"bg-status-warning/10 text-status-warning",delivered:"bg-status-success/10 text-status-success",returned:"bg-status-warning/10 text-status-warning",cancelled:"bg-status-danger/10 text-status-danger"};function V(){const[x,b]=r.useState([]),[w,h]=r.useState(!0),[N,p]=r.useState(!1),[f,m]=r.useState(!1),[a,t]=r.useState({recipient_name:"",recipient_phone:"",pickup_address:"",dropoff_address:"",weight_kg:"",notes:""}),_=async()=>{h(!0);const{data:s,error:c}=await o.from("packages").select("id, tracking_number, status, recipient_name, dropoff_address, created_at").order("created_at",{ascending:!1}).limit(50);c&&l.error("Failed to load packages"),b(s??[]),h(!1)};r.useEffect(()=>{_()},[]);const y=async()=>{var k,v;if(!a.recipient_name||!a.dropoff_address||!a.pickup_address){l.error("Recipient, pickup and dropoff are required");return}m(!0);const{data:s}=await o.auth.getUser(),c=`PKG-${Date.now().toString(36).toUpperCase()}`,{data:j,error:d}=await o.from("packages").insert({tracking_number:c,module:"package",sender_id:(k=s.user)==null?void 0:k.id,recipient_name:a.recipient_name,recipient_phone:a.recipient_phone||null,pickup_address:a.pickup_address,dropoff_address:a.dropoff_address,weight_kg:a.weight_kg?Number(a.weight_kg):null,status:"created",metadata:a.notes?{notes:a.notes}:{}}).select("id").single();if(d||!j){l.error((d==null?void 0:d.message)??"Failed to create"),m(!1);return}await o.from("package_events").insert({package_id:j.id,event_type:"created",actor_id:(v=s.user)==null?void 0:v.id,notes:"Package created"}),l.success(`Package ${c} created`),t({recipient_name:"",recipient_phone:"",pickup_address:"",dropoff_address:"",weight_kg:"",notes:""}),p(!1),m(!1),_()};return e.jsxs(S,{children:[e.jsx("section",{className:"bg-primary text-primary-foreground",children:e.jsxs("div",{className:"container mx-auto px-4 py-10 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold",children:"Packages"}),e.jsx("p",{className:"opacity-90 text-sm",children:"Immutable lifecycle: Created â Accepted â Picked Up â In Transit â Delivered."})]}),e.jsxs(g,{variant:"secondary",onClick:()=>p(s=>!s),children:[e.jsx(F,{className:"h-4 w-4 mr-1"})," New package"]})]})}),e.jsxs("section",{className:"container mx-auto px-4 py-8 max-w-5xl space-y-6",children:[N&&e.jsxs(u,{className:"p-5 space-y-4",children:[e.jsx("h2",{className:"font-semibold",children:"Create package"}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(i,{children:"Recipient name *"}),e.jsx(n,{value:a.recipient_name,onChange:s=>t({...a,recipient_name:s.target.value}),maxLength:120})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Recipient phone"}),e.jsx(n,{value:a.recipient_phone,onChange:s=>t({...a,recipient_phone:s.target.value}),maxLength:32})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Pickup address *"}),e.jsx(n,{value:a.pickup_address,onChange:s=>t({...a,pickup_address:s.target.value}),maxLength:240})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Dropoff address *"}),e.jsx(n,{value:a.dropoff_address,onChange:s=>t({...a,dropoff_address:s.target.value}),maxLength:240})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Weight (kg)"}),e.jsx(n,{type:"number",step:"0.1",value:a.weight_kg,onChange:s=>t({...a,weight_kg:s.target.value})})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(i,{children:"Notes"}),e.jsx(R,{value:a.notes,onChange:s=>t({...a,notes:s.target.value}),maxLength:500})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(g,{variant:"outline",onClick:()=>p(!1),children:"Cancel"}),e.jsx(g,{onClick:y,disabled:f,children:f?"Creatingâ¦":"Create package"})]})]}),w?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading packagesâ¦"}):x.length===0?e.jsxs(u,{className:"p-10 text-center",children:[e.jsx(C,{className:"h-10 w-10 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"font-medium",children:"No packages yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Create your first package to start the lifecycle."})]}):e.jsx("div",{className:"space-y-2",children:x.map(s=>e.jsx(P,{to:`/delivery/ops/packages/${s.id}`,children:e.jsxs(u,{className:"p-4 hover:border-primary/40 transition-colors flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-mono text-sm",children:s.tracking_number}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["â ",s.recipient_name??"â"," · ",s.dropoff_address??"â"]}
1)]}),e.jsx(L,{className:T[s.status]??"bg-muted",children:s.status.replace("_"," ")})]})},s.id))})]})]})}export{V as default}; 2//# sourceMappingURL=Packages-W1kWF1RF.js.map
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.