1import{j as e}from"./ui-vendor-B12AOeKi.js";import{e as H,r as m,R as w}from"./react-vendor-DZt7wVAJ.js";import{p as Y,B as C,ap as q,q as O,v as U,w as J,ab as K,y as Q,L as o,I as g,s as R}from"./index-BZo64Z7H.js";import{S as x,a as v,b as y,c as j,d as u}from"./select-B9Z9mxdV.js";import{d as _}from"./workTypeUtils-Bo2690wQ.js";import{u as Z,M as ee}from"./MaintenancePage-BNLaHdGn.js";import{u as ae,A as se}from"./useAppDisabled-Cq6rXEPc.js";import{I as re}from"./InstallPrompt-AIyOUZfc.js";import{V as te}from"./VinScanner-BrQOjoRJ.js";import{A as ie,a as ne,b as le,c as oe,d as ce,e as de,g as me,f as he}from"./alert-dialog-Diwn5aYx.js";import{C as ue}from"./camera-j2kdOu-W.js";import{S as pe}from"./save-Cxi2VgTj.js";import"./charts-vendor-B6q1L48j.js";import"./supabase-vendor-dOy44Gxq.js";import"./animation-vendor-BAVy02gd.js";import"./circle-check-big-3X4sON1s.js";import"./index-D9T2E487.js";import"./scan-CVmb7D1y.js";const X="6af71e81-70e8-4b3f-8a68-f46cb331c7c5",ge="CNS",Ve=()=>{var T;const A=H(),{toast:c}=Y(),M=m.useRef(null),[xe,ve]=m.useState(!0),[ye,je]=m.useState(null),[a,n]=m.useState({stockNumber:"",vinLast8:"",miles:"",color:"",vehicleType:"NEW",year:"",make:"",model:"",yearMakeModel:"",workType:"",arrivalDate:new Date().toISOString().split("T")[0],receivedBy:"",keys:""}),[d,k]=m.useState([]),[E,S]=m.useState(!1),[i,I]=m.useState(null),[P,p]=m.useState(!1),{isMaintenanceMode:N,isLoading:f}=Z(),{isDisabled:D,isLoading:b}=ae("vehicles");m.useEffect(()=>{const s=document.querySelector('link[rel="manifest"]');if(s)s.setAttribute("href","/manifest-mobile-cnm.json");else{const r=document.createElement("link");r.rel="manifest",r.href="/manifest-mobile-cnm.json",document.head.appendChild(r)}},[]),new Date().getFullYear();const V=Array.from({length:36},(s,r)=>2030-r),G=["Volkswagen","Hyundai","Genesis","Volvo","Nissan","Toyota","Ford","Chevrolet","Honda","Jaguar","Jeep","BMW","Audi","Mazda","Subaru","Ram","GMC","Kia","Mercedes-Benz","Lexus","Dodge","Acura","Buick"],F={Volkswagen:["Jetta","Passat","Golf","Tiguan","Atlas","Arteon","ID.4","Taos","Atlas Cross Sport","GLI"],Toyota:["Camry","Corolla","RAV4","Highlander","Prius","Tacoma","Tundra","Sienna","4Runner","Avalon"],Ford:["F-150","Explorer","Escape","Mustang","Edge","Expedition","Bronco","Ranger","Maverick","EcoSport"],Chevrolet:["Silverado","Equinox","Malibu","Traverse","Tahoe","Suburban","Camaro","Cruze","Trailblazer","Blazer"],Honda:["Civic","Accord","CR-V","Pilot","HR-V","Passport","Ridgeline","Odyssey","Insight","Fit"],Nissan:["Altima","Sentra","Rogue","Pathfinder","Frontier","Titan","Versa","Murano","Armada","Kicks"],Hyundai:["Elantra","Sonata","Tucson","Santa Fe","Palisade","Kona","Venue","Genesis","Ioniq","Santa Cruz"],Jaguar:["F-PACE","E-PACE","I-PACE","F-TYPE","XF"],Jeep:["Wrangler","Grand Cherokee","Cherokee","Compass","Renegade","Gladiator","Wagoneer","Grand Wagoneer","Patriot","Liberty"],BMW:["3 Series","5 Series","X3","X5","X1","X7","7 Series","4 Series","X2","i4"],Audi:["A4","A6","Q5","Q7","A3","Q3","A8","e-tron","Q8","A5"],Mazda:["CX-5","CX-9","Mazda3","Mazda6","CX-30","CX-50","MX-5 Miata","CX-3","CX-90","Mazda2"],Subaru:["Outback","Forester","Crosstrek","Impreza","Legacy","Ascent","WRX","BRZ","Solterra","Wilderness"],Ram:["1500","2500","3500","ProMaster","Chassis Cab","ProMaster City","1500 Classic","TRX","Rebel","Laramie"],GMC:["Sierra","Terrain","Acadia","Canyon","Yukon","Yukon XL","Hummer EV","Sierra HD","Savana","Denali"],Kia:["Forte","Optima","Sorento","Sportage","Telluride","Soul","Seltos","K5","Stinger","Carnival"],"Mercedes-Benz":["C-Class","E-Class","GLE","GLC","S-Class","GLA","GLB","A-Class","CLS","GLS"],Lexus:["RX","ES","NX","IS","GX","LS","UX","LX","RC","LC"],Dodge:["Charger","Challenger","Durango","Journey","Hornet","Grand Caravan","Ram","Viper","Dart","Avenger"],Acura:["MDX","RDX","TLX","ILX","Integra","NSX","ZDX","RLX","TSX","RSX"],Buick:["Enclave","Encore","Envision","Encore GX","LaCrosse","Regal","Verano","Cascada","Lucerne","Century"],Genesis:["G70","G80","G90","GV60","GV70","GV80","Electrified G80","Electrified GV70","G70 Shooting Brake","GV70 Sport"],Volvo:["XC90","XC60","XC40","S60","S90","V60","V90","C40 Recharge","XC40 Recharge","XC90 Recharge"]},B=async()=>
1{if(a.year&&a.make&&a.model){const s=`${a.year} ${a.make} ${a.model}`,r=await _(s,a.vehicleType,"CNM",parseInt(a.miles)||void 0);n(l=>({...l,yearMakeModel:s,workType:r}))}};w.useEffect(()=>{B()},[a.year,a.make,a.model,a.vehicleType]),w.useEffect(()=>{if(a.year){const s=parseInt(a.year),r=new Date().getFullYear();s>=r?(console.log("[AutoDetect] Year >= current, setting NEW"),n(l=>({...l,vehicleType:"NEW"}))):s<r-1&&(console.log("[AutoDetect] Year < current-1, setting USED"),n(l=>({...l,vehicleType:"USED"})))}},[a.year]);const $=()=>{var s;(s=M.current)==null||s.click()},W=s=>{const r=Array.from(s.target.files||[]),l=d.length+r.length;if(l>15){const h=15-d.length;c({title:"Photo Limit Reached",description:`Maximum 15 photos allowed. Adding only ${h} photo${h!==1?"s":""}.`,variant:"destructive"}),k(t=>[...t,...r.slice(0,h)])}else k(h=>[...h,...r]),c({title:"Photos Added",description:`${r.length} photo(s) selected. Total: ${l}`})},L=async(s,r=!1)=>{s.preventDefault();const l=a.miles.trim();if(!a.stockNumber.trim()||!a.vinLast8.trim()||!l||!a.color.trim()||!a.year||!a.make||!a.model){const t=[];
1a.stockNumber.trim()||t.push("Stock Number"),a.vinLast8.trim()||t.push("VIN"),l||t.push("Miles"),a.color.trim()||t.push("Color"),a.year||t.push("Year"),a.make||t.push("Make"),a.model||t.push("Model"),c({title:"Missing Information",description:`Please fill in: ${t.join(", ")}`,variant:"destructive"});return}if(!r){const{data:t}=await R.from("recon360_vehicles").select("id, stock_number, vin_last_8, year_make_model").eq("dealership_id",X).or(`stock_number.eq.${a.stockNumber},vin_last_8.eq.${a.vinLast8}`).not("status","in","(archived,completed)").limit(1).maybeSingle();if(t){I(t),p(!0);return}}if(!a.workType){const t=await _(a.yearMakeModel,a.vehicleType,"CNM",parseInt(a.miles)||void 0);if(!t){c({title:"â Error",description:"Unable to determine work type. Please try selecting year, make, and model again.",variant:"destructive"});return}n(z=>({...z,workType:t})),c({title:"â Error",description:"Work type was missing. Please submit again.",variant:"destructive"});return}const h=parseInt(l);if(isNaN(h)||h<0){c({title:"Invalid Miles",description:"Please enter a valid number for miles",variant:"destructive"});return}S(!0);try{const{error:t}=await R.rpc("recon360_create_vehicle_direct",{p_dealership_id:X,p_stock_number:a.stockNumber,p_vin_last_8:a.vinLast8,p_year_make_model:a.yearMakeModel||`${a.year} ${a.make} ${a.model}`.trim(),p_work_type:a.workType,p_vehicle_type:a.vehicleType,p_priority:"normal"});if(t){if(t.code==="23505"||/already exists/i.test(t.message||"")){c({title:"Duplicate Stock Number",description:`Stock #${a.stockNumber} already exists in Recon360.`,variant:"destructive"}),S(!1);return}throw t}c({title:"Added to Recon360",description:`Stock #${a.stockNumber} was added directly to Recon360.`}),n({stockNumber:"",vinLast8:"",miles:"",color:"",vehicleType:"NEW",year:"",make:"",model:"",yearMakeModel:"",workType:"",arrivalDate:new Date().toISOString().split("T")[0],receivedBy:"",keys:""}),k([])}catch(t){console.error("Failed to add vehicle:",t),c({title:"Error",description:t instanceof Error?t.message:"Failed to add vehicle. Please try again.",variant:"destructive"})}finally{S(!1)}};return e.jsxs(e.Fragment,{children:[(f||b)&&e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading..."})})}),!f&&N&&e.jsx(ee,{}),!f&&!N&&!b&&D&&e.jsx(se,{appName:"Lot Manager"}),!f&&!N&&!b&&!D&&e.jsxs(e.Fragment,{children:[e.jsx(re,{}),e.jsx("div",{className:"min-h-screen bg-background p-4",children:e.jsxs("div",{className:"max-w-md mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx(C,{variant:"ghost",size:"icon",onClick:()=>A("/"),children:e.jsx(q,{className:"h-6 w-6"})}),e.jsxs("h1",{className:"text-2xl font-bold",children:[ge," - Quick Vehicle Entry"]})]}),e.jsxs(O,{children:[e.jsx(U,{children:e.jsxs(J,{className:"flex items-center gap-2",children:[e.jsx(K,{className:"h-5 w-5"}),"Add New Vehicle"]})}),e.jsx(Q,{children:e.jsxs("form",{onSubmit:L,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"VIN (Last 8 Characters) *"}),e.jsx(te,{onVinScanned:s=>n(r=>({...r,vinLast8:s})),extractLast8Only:!0}),e.jsx(g,{value:a.vinLast8,onChange:s=>n(r=>({...r,vinLast8:s.target.value.toUpperCase()})),maxLength:8,placeholder:"Enter last 8 characters",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"stockNumber",children:"Stock Number *"}),e.jsx(g,{id:"stockNumber",value:a.stockNumber,onChange:s=>n(r=>({...r,stockNumber:s.target.value})),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"miles",children:"Miles *"}),e.jsx(g,{id:"miles",type:"number",value:a.miles,onChange:s=>n(r=>({...r,miles:s.target.value})),required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"color",children:"Color *"}),e.jsx(g,{id:"color",value:a.color,onChange:s=>n(r=>({...r,color:s.target.value})),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Vehicle Type *"}),e.jsxs(x,{value:a.vehicleType,onValueChange:s=>n(r=>({...r,vehicleType:s})),children:[e.jsx(v,{children:e.jsx(y,{})}),e.jsxs(j,{children:[e.jsx(u,{value:"NEW",children:"NEW"}),e.jsx(u,{value:"USED",children:"USED"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Year *"}),e.jsxs(x,{value:a.year,onValueChange:s=>n(r=>({...r,year:s})),children:[e.jsx(v,{children:e.jsx(y,{placeholder:"Select year"})}),e.jsx(j,{children:V.map(s=>e.jsx(u,{value:s.toString(),children:s},s))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Make *"}),e.jsxs(x,{value:a.make,onValueChange:s=>n(r=>({...r,make:s,model:""})),children:[e.jsx(v,{children:e.jsx(y,{placeholder:"Select make"})}),e.jsx(j,{children:G.map(s=>e.jsx(u,{value:s,children:s},s))})]})]}),a.make&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Model *"}),e.jsxs(x,{value:a.model,onValueChange:s=>n(r=>({...r,model:s})),children:[e.jsx(v,{children:e.jsx(y,{placeholder:"Select model"})}),e.jsx(j,{children:(T=F[a.make])==null?void 0:T.map(s=>e.jsx(u,{value:s,children:s},s))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"receivedBy",children:"Received By"}),e.jsx(g,{id:"receivedBy",value:a.receivedBy,onChange:s=>n(r=>({...r,receivedBy:s.target.value})),placeholder:""})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Keys"}),e.jsxs(x,{value:a.keys,onValueChange:s=>n(r=>({...r,keys:s})),children:[e.jsx(v,{children:e.jsx(y,{placeholder:"Select number of keys"})}),e.jsxs(j,{children:[e.jsx(u,{value:"1",children:"1"}),e.jsx(u,{value:"2+",children:"2+"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{className:"text-base",children:"Vehicle Photos (Optional)"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Add up to 15 photos (front, rear, sides, interior)"}),e.jsxs(C,{type:"button",onClick:$,className:"w-full",variant:"outline",children:[e.jsx(ue,{className:"h-4 w-4 mr-2"}),d.length===0?"Add Photos (Optional)":`${d.length} Photo${d.length>
11?"s":""} Added`]}),d.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:[d.length," photo",d.length>1?"s":""," added",d.length>=15&&" ⢠Maximum reached"]}),e.jsx("input",{ref:M,type:"file",accept:"image/*",multiple:!0,capture:"environment",onChange:W,className:"hidden"})]}),e.jsxs(C,{type:"submit",className:"w-full",disabled:E,children:[e.jsx(pe,{className:"h-4 w-4 mr-2"}),E?"Adding Vehicle...":"Add to Review Queue"]})]})})]}),e.jsx(ie,{open:P,onOpenChange:p,children:e.jsxs(ne,{children:[e.jsxs(le,{children:[e.jsx(oe,{children:"Vehicle Already Exists"}),e.jsxs(ce,{children:["A vehicle with Stock #",i==null?void 0:i.stock_number," or VIN ",i==null?void 0:i.vin_last_8," already exists in the system.",e.jsxs("div",{className:"mt-2 text-sm",children:[e.jsx("strong",{children:"Existing Vehicle:"}),e.jsxs("div",{className:"mt-1",children:["Stock: ",i==null?void 0:i.stock_number,e.jsx("br",{}),"VIN: ",i==null?void 0:i.vin_last_8,e.jsx("br",{}),"Vehicle: ",i==null?void 0:i.year_make_model,e.jsx("br",{}),"Status: ",i==null?void 0:i.status]})]})]})]}),e.jsxs(de,{children:[e.jsx(me,{onClick:()=>p(!1),children:"Cancel"}),e.jsx(C,{variant:"outline",onClick:s=>{s.preventDefault(),p(!1),L(s,!0)},children:"Ignore & Add Anyway"}),e.jsx(he,{onClick:()=>{p(!1),A("/vehicles/mobile-manager",{state:{highlightVehicle:i==null?void 0:i.id}})},children:"View Existing Record"})]})]})})]})})]})]})};export{Ve 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.