1import{u as xe,I as pe,r,j as e,S as me,B as k,L as le,A as ge,N as je,a1 as v,X as ve}from"./index-B_WxU4PL.js";import{s as x}from"./LeadHandled-BI3AzXR2.js";import{C as fe,a as ye}from"./SellerProfile-MRzDRQOl.js";import{I as c}from"./input-BB-xqz_7.js";import{L as l}from"./label-BQUKg8vX.js";import{T as be}from"./textarea-DKlewkVN.js";import{S as f}from"./switch-WRvIi4_R.js";import{S as P,a as A,b as _,c as U,d as n}from"./select-BkhXwY4N.js";import{U as Ce}from"./upload-cUZHjN4m.js";import"./index-DRnWRyVM.js";import"./tslib.es6-Be4nv5Yv.js";import"./index-B32UXCTs.js";import"./index-BUvkVUg3.js";const L=["Category","Details","Specs","Photos","Location","Contact","Review"];function Ie(){const m=xe(),{id:u}=pe(),p=!!u,[a,C]=r.useState(0),[g,T]=r.useState(!1),[ie,$]=r.useState(!1),[j,R]=r.useState("furniture"),[y,V]=r.useState(""),[D,W]=r.useState(""),[E,H]=r.useState("used"),[S,O]=r.useState(""),[F,z]=r.useState(!0),[I,Q]=r.useState("1"),[t,o]=r.useState({}),[h,M]=r.useState([]),[N,X]=r.useState(""),[q,Y]=r.useState(!0),[w,G]=r.useState(!1),[B,J]=r.useState("10"),[K,Z]=r.useState(!0),[ee,se]=r.useState(!1),[te,ae]=r.useState(!1);r.useEffect(()=>{!p||!u||(async()=>{const{data:s}=await x.from("marketplace_listings").select("*").eq("id",u).single();if(!s)return;R(s.category??"other"),V(s.title??""),W(s.description??""),H(s.condition??"used"),O(String(s.price??"")),z(!!s.accepts_offers),Q(String(s.quantity??1)),o(s.vehicle_specs??{}),M(Array.isArray(s.photos)?s.photos:[]),X(s.postcode??"");const i=s.delivery_options??{};Y(i.collection??!0),G(i.delivery??!1),J(String(i.radius??"10"));const d=s.contact_prefs??{};Z(d.inApp??!0),se(!!d.phone),ae(!!d.whatsapp)})()},[u,p]);async function ne(s){if(!(s!=null&&s.length))return;$(!0);const{data:{user:i}}=await x.auth.getUser();if(!i){v({title:"Sign in first"}),$(!1);return}const d=[];for(const b of Array.from(s).slice(0,10-h.length)){const he=b.name.split(".").pop(),re=`${i.id}/${Date.now()}-${Math.random().toString(36).slice(2)}.${he}`,{error:ue}=await x.storage.from("marketplace-photos").upload(re,b);ue||d.push(re)}M([...h,...d]),$(!1)}async function ce(s){M(h.filter(i=>i!==s)),await x.storage.from("marketplace-photos").remove([s])}async function oe(){T(!0);const{data:{user:s}}=await x.auth.getUser();if(!s){v({title:"Sign in first"}),T(!1);return}const i={user_id:s.id,title:y,description:D,category:j,condition:E,price:Number(S)||0,accepts_offers:F,quantity:Number(I)||1,photos:h,vehicle_specs:j==="vehicle"?t:null,postcode:N,delivery_options:{collection:q,delivery:w,radius:Number(B)},contact_prefs:{inApp:K,phone:ee,whatsapp:te},status:"active"};if(p&&u){const{error:d}=await x.from("marketplace_listings").update(i).eq("id",u);d?v({title:"Save failed",description:d.message}):(v({title:"Listing updated"}),m(`/platform/marketplace/${u}`))}else{const d=`lst_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,{error:b}=await x.from("marketplace_listings").insert({id:d,...i});b?v({title:"Publish failed",description:b.message}):(v({title:"Listing published"}),m(`/platform/marketplace/${d}`))}T(!1)}const de=a===0&&!!j||a===1&&y.trim().length>=3&&Number(S)>=0||a===2||a===3&&h.length>0||a===4&&N.trim().length>=3||a===5||a===6;return e.jsxs("div",{className:"p-4 md:p-8 max-w-3xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(me,{className:"w-6 h-6 text-primary"})," ",p?"Edit":"New"," listing"]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:()=>m("/platform/marketplace"),children:"Cancel"})]}),e.jsx("div",{className:"flex gap-1 mb-6",children:L.map((s,i)=>e.jsx("div",{className:`flex-1 h-1.5 rounded ${i<=a?"bg-primary":"bg-muted"}`},s))}),e.jsxs("p",{className:"text-xs uppercase tracking-widest text-muted-foreground mb-3",children:["Step ",a+1,"/",L.length," â ",L[a]]}),e.jsx(fe,{children:e.jsxs(ye,{className:"p-6 space-y-4",children:[a===0&&e.jsxs("div",{children:[e.jsx(l,{children:"What are you selling?"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2 mt-2",children:["vehicle","furniture","electronics","tools","other"].map(s=>e.jsx("button",{type:"button",onClick:()=>R(s),className:`p-4 rounded-lg border text-sm font-medium capitalize ${j===s?"border-primary bg-primary/10":"border-border hover:bg-muted"}`,children:s},s))})]}),a===1&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(l,{children:"Title"}),e.jsx(c,{value:y,onChange:s=>V(s.target.value),placeholder:"e.g. 2018 Ford Transit L2H2"})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Description"}),e.jsx(be,{rows:5,value:D,onChange:s=>W(s.target.value),placeholder:"Be specific. Buyers love detail."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{children:"Condition"}),e.jsxs(P,{value:E,onValueChange:H,children:[e.jsx(A,{children:e.jsx(_,{})}),e.jsxs(U,{children:[e.jsx(n,{value:"new",children:"New"}),e.jsx(n,{value:"like-new",children:"Like new"}),e.jsx(n,{value:"used",children:"Used â good"}),e.jsx(n,{value:"fair",children:"Used â fair"}),e.jsx(n,{value:"spares",children:"Spares or repair"})]})]})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Quantity"}
1),e.jsx(c,{type:"number",min:1,value:I,onChange:s=>Q(s.target.value)})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 items-end",children:[e.jsxs("div",{children:[e.jsx(l,{children:"Price (£)"}),e.jsx(c,{type:"number",min:0,value:S,onChange:s=>O(s.target.value),placeholder:"0"})]}),e.jsxs("label",{className:"flex items-center gap-2 pb-2",children:[e.jsx(f,{checked:F,onCheckedChange:z})," Accept offers"]})]})]}),a===2&&e.jsx(e.Fragment,{children:j==="vehicle"?e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(l,{children:"Make"}),e.jsx(c,{value:t.make??"",onChange:s=>o({...t,make:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Model"}),e.jsx(c,{value:t.model??"",onChange:s=>o({...t,model:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Year"}),e.jsx(c,{value:t.year??"",onChange:s=>o({...t,year:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Mileage"}),e.jsx(c,{value:t.mileage??"",onChange:s=>o({...t,mileage:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Fuel"}),e.jsxs(P,{value:t.fuel??"",onValueChange:s=>o({...t,fuel:s}),children:[e.jsx(A,{children:e.jsx(_,{placeholder:"Selectâ¦"})}),e.jsxs(U,{children:[e.jsx(n,{value:"petrol",children:"Petrol"}),e.jsx(n,{value:"diesel",children:"Diesel"}),e.jsx(n,{value:"hybrid",children:"Hybrid"}),e.jsx(n,{value:"electric",children:"Electric"})]})]})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Transmission"}),e.jsxs(P,{value:t.transmission??"",onValueChange:s=>o({...t,transmission:s}),children:[e.jsx(A,{children:e.jsx(_,{placeholder:"Selectâ¦"})}),e.jsxs(U,{children:[e.jsx(n,{value:"manual",children:"Manual"}),e.jsx(n,{value:"automatic",children:"Automatic"})]})]})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Body type"}),e.jsx(c,{value:t.bodyType??"",onChange:s=>o({...t,bodyType:s.target.value}),placeholder:"e.g. Luton, Panel, SWB"})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Colour"}),e.jsx(c,{value:t.colour??"",onChange:s=>o({...t,colour:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(l,{children:"MOT expiry"}),e.jsx(c,{type:"date",value:t.motExpiry??"",onChange:s=>o({...t,motExpiry:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Service history"}),e.jsxs(P,{value:t.serviceHistory??"",onValueChange:s=>o({...t,serviceHistory:s}),children:[e.jsx(A,{children:e.jsx(_,{placeholder:"Selectâ¦"})}),e.jsxs(U,{children:[e.jsx(n,{value:"full",children:"Full"}),e.jsx(n,{value:"partial",children:"Partial"}),e.jsx(n,{value:"none",children:"None"})]})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(l,{children:"Reg plate (hidden from listing)"}),e.jsx(c,{value:t.regPlate??"",onChange:s=>o({...t,regPlate:s.target.value}),placeholder:"Only shared with serious buyers"})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No extra specs needed for this category. Continue."})}),a===3&&e.jsxs("div",{children:[e.jsxs(l,{children:["Photos (",h.length,"/10)"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-2",children:[h.map((s,i)=>e.jsx(Se,{path:s,cover:i===0,onRemove:()=>ce(s)},s)),h.length<10&&e.jsxs("label",{className:"aspect-square border-2 border-dashed border-border rounded-lg flex flex-col items-center justify-center cursor-pointer hover:border-primary text-muted-foreground text-xs",children:[ie?e.jsx(le,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"w-5 h-5 mb-1"})," Add photo"]}),e.jsx("input",{type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:s=>ne(s.target.files)})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"First photo is the cover. Up to 10 images."})]}),a===4&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(l,{children:"Postcode"}),e.jsx(c,{value:N,onChange:s=>X(s.target.value.toUpperCase()),placeholder:"e.g. SW1A 1AA"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(f,{checked:q,onCheckedChange:Y})," Buyer collects"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(f,{checked:w,onCheckedChange:G})," I can deliver"]}
1),w&&e.jsxs("div",{children:[e.jsx(l,{children:"Delivery radius (miles)"}),e.jsx(c,{type:"number",value:B,onChange:s=>J(s.target.value)})]})]}),a===5&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(f,{checked:K,onCheckedChange:Z})," In-app messages"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(f,{checked:ee,onCheckedChange:se})," Show my phone"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(f,{checked:te,onCheckedChange:ae})," WhatsApp button"]})]}),a===6&&e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("h3",{className:"font-bold text-lg",children:y||"(no title)"}),e.jsxs("div",{children:["£",S||"0"," ",F&&e.jsx("span",{className:"text-muted-foreground",children:"or best offer"})]}),e.jsxs("div",{className:"text-muted-foreground",children:[j," · ",E," · qty ",I]}),e.jsx("p",{className:"whitespace-pre-wrap",children:D}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[N," · ",q?"Collection":""," ",w?`· Delivery (${B}mi)`:""]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[h.length," photos"]})]})]})}),e.jsxs("div",{className:"flex justify-between mt-4",children:[e.jsxs(k,{variant:"outline",onClick:()=>C(s=>Math.max(0,s-1)),disabled:a===0,children:[e.jsx(ge,{className:"w-4 h-4 mr-1"})," Back"]}),a<L.length-1?e.jsxs(k,{onClick:()=>C(s=>s+1),disabled:!de,children:["Next ",e.jsx(je,{className:"w-4 h-4 ml-1"})]}):e.jsxs(k,{onClick:oe,disabled:g||h.length===0||!y,children:[g&&e.jsx(le,{className:"w-4 h-4 mr-2 animate-spin"})," ",p?"Save changes":"Publish listing"]})]})]})}function Se({path:m,cover:u,onRemove:p}){const[a,C]=r.useState(null);return r.useEffect(()=>{x.storage.from("marketplace-photos").createSignedUrl(m,3600).then(({data:g})=>{C((g==null?void 0:g.signedUrl)??null)})},[m]),e.jsxs("div",{className:"relative aspect-square rounded-lg overflow-hidden border bg-muted",children:[a&&e.jsx("img",{src:a,alt:"",className:"w-full h-full object-cover"}),u&&e.jsx("span",{className:"absolute top-1 left-1 text-[10px] bg-primary text-primary-foreground px-1.5 py-0.5 rounded",children:"Cover"}),e.jsx("button",{type:"button",onClick:p,className:"absolute top-1 right-1 w-6 h-6 rounded-full bg-black/60 text-white flex items-center justify-center",children:e.jsx(ve,{className:"w-3 h-3"})})]})}export{Ie 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.