PageSourceSearch

https://carbidder-connect.lovable.app/assets/AdminOfferRoom-8tZ_K7mD.js

js carbidder-connect.lovable.app collected 2026-10-03 03:24:14 UTC 103,560 bytes, 25 lines download raw bytes

1import{f as gs,r as l,u as fs,s as v,J as U,j as e,B as E,a9 as ps,aU as ue,x as Ne,z as bs,Y as js,C as de,e as vs,D as Re,a1 as Ns,a2 as _s,q as ws,t as ys,a3 as ks,am as Ae,o as Cs,a as Ss,S as Be,v as ce,V as ie,b as Qe,A as Ye,ac as te,ad as re,ae,af as ne,ag as L,ab as Ze,R as Ds,av as He,w as Ge,X as $s,g as Ls,aX as Os,aY as Es,aC as Rs,aZ as As}from"./index-C7rjTsh5.js";import{T as Ms,a as Vs,b as Is,c as xe}from"./tabs-B0GSHNwt.js";import{B as oe}from"./badge-Be4waKn8.js";import{u as Ts}from"./useAuctionData-Chg0Xdx_.js";import{u as Us}from"./OfferDetailsPopoverDialog-BoTXPltS.js";import{u as Fs}from"./useDealership-Bp3K7SHu.js";import{d as Bs}from"./directSupabaseFetch-BbQSFe0u.js";import{R as he}from"./RevMeter-8CGWAzwQ.js";import{O as ve}from"./OfferDetailsPopover-LjvyQO46.js";import{L as zs}from"./layout-grid-j8Ik6fkS.js";import{D as ge,d as Me,a as fe,b as pe,c as be,e as We}from"./dialog-BqIQ1XMZ.js";import{F as Xe}from"./flame-BtS0eEEx.js";import{C as Ps}from"./copy-BlVyKajD.js";import{S as Je}from"./sticky-note-BbJG7JcD.js";import{R as Ve}from"./radio-xCuI6Hmy.js";import{f as Ks}from"./format-iV6bfs-r.js";import{C as qs}from"./circle-x-CNCJGsDv.js";import{E as Hs}from"./EditBidDataModal-zlDrsFQC.js";import{C as Gs}from"./CounterOfferModal-C0wwkhAj.js";import{L as Fe}from"./label-DEMqrK65.js";import{T as Qs}from"./textarea-DyriSEbd.js";import{N as Ys}from"./NoSaleReasonDialog-Cs25D1Pr.js";import{A as we,h as ye,a as ke,b as Ce,c as Se,d as De,e as $e,f as Le,g as Oe}from"./alert-dialog-C4HU7LiH.js";import{F as ze}from"./funnel-Cl1lUzAf.js";import{T as Ee}from"./trash-2-Dmi-p3qr.js";import{S as Zs}from"./search-BavRZthq.js";import{A as Ws}from"./AdminBreadcrumb-CkTy4H3-.js";import{u as Xs}from"./useAdminKeyboardShortcuts-CxTp9vL0.js";import{A as Js}from"./arrow-left-BnYBGNnB.js";import{Z as et}from"./zap-3Yfir6a9.js";import"./useServerTime-CYJ7qE1d.js";import"./ghlSync-CMbnb_1I.js";import"./formatters-WI8bnDfT.js";import"./save-O9juW0e-.js";import"./ConditionDetailsDisplay-DL4tkEE0.js";import"./paintbrush-DY9z_qcF.js";import"./wrench-CuLhvuJZ.js";import"./building-BT__kfYv.js";import"./phone-1rmp-Pye.js";import"./useQuery-DPL76jZ9.js";import"./en-US-BzMcWhXf.js";import"./toDate-2Nz3Yi75.js";import"./carStatusTransitions-CALkaaxS.js";import"./alert-De4v_MUd.js";import"./trending-up-BZYvG5qV.js";import"./index-K0EsK_ep.js";import"./triangle-alert-CCELUU2A.js";import"./radio-group-6Ykd0SsZ.js";/**
2 * @license lucide-react v0.555.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const st=[["path",{d:"m10 20-1.25-2.5L6 18",key:"18frcb"}],["path",{d:"M10 4 8.75 6.5 6 6",key:"7mghy3"}],["path",{d:"m14 20 1.25-2.5L18 18",key:"1chtki"}],["path",{d:"m14 4 1.25 2.5L18 6",key:"1b4wsy"}],["path",{d:"m17 21-3-6h-4",key:"15hhxa"}],["path",{d:"m17 3-3 6 1.5 3",key:"11697g"}],["path",{d:"M2 12h6.5L10 9",key:"kv9z4n"}],["path",{d:"m20 10-1.5 2 1.5 2",key:"1swlpi"}],["path",{d:"M22 12h-6.5L14 15",key:"1mxi28"}],["path",{d:"m4 10 1.5 2L4 14",key:"k9enpj"}],["path",{d:"m7 21 3-6-1.5-3",key:"j8hb9u"}],["path",{d:"m7 3 3 6h4",key:"1otusx"}]],tt=gs("snowflake",st),rt=()=>{const[r,c]=l.useState([]),[g,N]=l.useState(!0),{dealershipId:f,loading:_}=Fs(),{user:C}=fs(),y=(C==null?void 0:C.role)==="admin",p=l.useRef(!0),D=async(b=!1)=>{!b&&p.current&&N(!0);try{const t="id,make,model,year,vin,mileage,color,condition,current_bid,starting_bid,end_time,high_bi
6dder_id,high_bidder_name,images,cover_photo,reserve_met,reserve_price,status,listing_type,customer_name,customer_email,customer_phone,seller_id,bid_count,counter_offer,dealership_id,updated_at,last_customer_counter";if(y){console.log("🔄 Admin fetching ALL dealer counter cars");const u=await Bs({table:"cars",select:t,eq:{status:"dealer_counter"},or:"listing_type.is.null,listing_type.eq.auction",order:{column:"updated_at",ascending:!1}});console.log("Admin fetched dealer counter cars:",(u==null?void 0:u.length)||0),c(u||[]),N(!1);return}if(!f){c([]),N(!1);return}console.log("🔄 Fetching dealer counter cars for dealership:",f);const{data:a,error:i}=await v.rpc("get_dealer_counter_cars_v2",{p_dealership_id:f});if(i){console.error("Error fetching dealer counter cars:",i),U.error("Failed to load dealer counter cars");return}console.log("Fetched dealer counter cars:",a),c(a||[])}catch(t){console.error("Exception fetching dealer counter cars:",t),U.error("An error occurred while loading dealer counter cars")}finally{p.current&&(p.current=!1),N(!1)}};return l.useEffect(()=>{(y||!_&&f)&&D();const b=()=>{console.log("🔄 Car update event detected, refreshing dealer counter data"),D(!0)};return window.addEventListener("car-update",b),window.addEventListener("dealer-counter-updated",b),window.addEventListener("bid-data-updated",b),window.addEventListener("global-data-refresh",b),()=>{window.removeEventListener("car-update",b),window.removeEventListener("dealer-counter-updated",b),window.removeEventListener("bid-data-updated",b),window.removeEventListener("global-data-refresh",b)}},[f,_,y]),{dealerCounterCars:r,loading:g||!y&&_,fetchDealerCounterCars:D}},Pe=({view:r,onViewChange:c})=>e.jsxs("div",{className:"flex gap-1 border border-border rounded-lg p-1 bg-muted/50",children:[e.jsxs(E,{variant:r==="grid"?"default":"ghost",size:"sm",onClick:()=>c("grid"),className:"gap-2 h-8",children:[e.jsx(zs,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Grid"})]}),e.jsxs(E,{variant:r==="list"?"default":"ghost",size:"sm",onClick:()=>c("list"),className:"gap-2 h-8",children:[e.jsx(ps,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"List"})]})]}),es=({carId:r,value:c,size:g="sm",onChange:N})=>{const[f,_]=l.useState(c??null),[C,y]=l.useState(!1);ue.useEffect(()=>{_(c??null)},[c]);const p=async t=>{if(C)return;const a=f===t?null:t,i=f;_(a),y(!0);try{const{error:u}=await v.from("cars").update({deal_temperature:a}).eq("id",r);if(u)throw u;N==null||N(r,a),U.success(a?`Marked as ${a.toUpperCase()}`:"Temperature cleared")}catch(u){console.error("Error updating deal temperature:",u),_(i),U.error("Failed to update")}finally{y(!1)}},D=g==="md"?"h-4 w-4":"h-3.5 w-3.5",b=g==="md"?"h-8 px-2.5 text-xs":"h-7 px-2 text-[11px]";return e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsxs("button",{type:"button","aria-label":"Mark as hot",title:"Mark as hot",disabled:C,onClick:t=>{t.stopPropagation(),p("hot")},className:`${b} rounded-full border font-semibold uppercase tracking-wide flex items-center gap-1 transition-colors ${f==="hot"?"bg-orange-500 border-orange-500 text-white shadow-sm":"bg-background border-orange-300 dark:border-orange-500/40 text-orange-600 dark:text-orange-400 hover:bg-orange-500/10"}`,children:[e.jsx(Xe,{className:D}),"Hot"]}),e.jsxs("button",{type:"button","aria-label":"Mark as cold",title:"Mark as cold",disabled:C,onClick:t=>{t.stopPropagation(),p("cold")},className:`${b} rounded-full border font-semibold uppercase tracking-wide flex items-center gap-1 transition-colors ${f==="cold"?"bg-sky-500 border-sky-500 text-white shadow-sm":"bg-background border-sky-300 dark:border-sky-500/40 text-sky-600 dark:text-sky-400 hover:bg-sky-500/10"}`,children:[e.jsx(tt,{className:D}),"Cold"]})]})},Ke=({car:r,onManageOffer:c,statusLabel:g="On Offer",statusColor:N="blue",onTemperatureChange:f})=>{const _=Ne(),[C,y]=ue.useState(!1),[p,D]=l.useState(!0),[b,t]=l.useState([]),[a,i]=l.useState(!1),[u,k]=l.useState(""),[A,z]=l.useState(!1);l.useEffect(()=>{p&&!a&&(async()=>{const{data:$}=await v.from("admin_notes").select("*").eq("car_id",r.id).order("created_at",{ascending:!1});if($&&$.length>0){const I=[...new Set($.map(q=>q.admin_id))],{data:K}=await v.from("users").select("id, name").in("id",I),Y=Object.fromEntries((K||[]).map(q=>
6[q.id,q.name]));t($.map(q=>({...q,admin_name:Y[q.admin_id]||"Admin"})))}else t([]);i(!0)})()},[p,a,r.id]);const O=async()=>{if(!(!u.trim()||A))try{z(!0);const{data:{user:w}}=await v.auth.getUser();if(!w){U.error("You must be logged in");return}const{error:$}=await v.from("admin_notes").insert({car_id:r.id,admin_id:w.id,note_content:u.trim()});if($)throw $;const{data:I}=await v.from("users").select("name").eq("id",w.id).single();t(K=>[{id:crypto.randomUUID(),note_content:u.trim(),admin_name:(I==null?void 0:I.name)||"You",created_at:new Date().toISOString()},...K]),k(""),U.success("Note saved")}catch(w){console.error("Error saving note:",w),U.error("Failed to save note")}finally{z(!1)}},d=async()=>{if(r.vin)try{await navigator.clipboard.writeText(r.vin),y(!0),U.success("VIN copied to clipboard"),setTimeout(()=>y(!1),2e3)}catch{U.error("Failed to copy VIN")}},S=()=>{_(`/admin/vehicles/${r.id}?from=offer-room`)},s=()=>{switch(N){case"orange":return"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400";case"emerald":return"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400";case"gray":return"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400";default:return"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}},n=w=>{if(!w)return null;try{return Ks(new Date(w),"MM/dd/yyyy hh:mm a")}catch{return null}};return e.jsx(bs,{className:"overflow-hidden hover:shadow-md dark:hover:shadow-lg dark:hover:shadow-primary/5 transition-shadow flex flex-col h-full dark:border-slate-700/60 dark:bg-slate-900/80",children:e.jsxs(js,{className:"p-0 flex flex-col flex-1",children:[e.jsxs("div",{className:"flex items-start gap-3 p-4 pb-3 bg-muted/30 dark:bg-slate-800/60 border-b border-border dark:border-slate-700/50",children:[e.jsx("div",{className:"flex-shrink-0",children:r.images&&r.images.length>0?e.jsx("img",{src:r.images[0],alt:`${r.year} ${r.make} ${r.model}`,className:"w-24 h-[72px] object-cover rounded-lg border border-border"}):e.jsx("div",{className:"w-24 h-[72px] bg-muted rounded-lg flex items-center justify-center border border-border",children:e.jsx(de,{className:"h-7 w-7 text-muted-foreground"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("h3",{className:"text-base font-bold text-foreground leading-tight whitespace-normal",children:[r.year," ",r.make," ",r.model]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(es,{carId:r.id,value:r.deal_temperature,onChange:f}),e.jsx(oe,{className:`${s()} font-medium text-xs flex-shrink-0`,children:g})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-primary hover:text-primary/80 cursor-pointer",onClick:S,children:r.vin}),e.jsx("button",{className:"p-0.5 hover:bg-muted rounded",onClick:d,children:C?e.jsx(vs,{className:"h-3 w-3 text-green-500"}):e.jsx(Ps,{className:"h-3 w-3 text-muted-foreground"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[(r.mileage||0).toLocaleString()," mi"]})]})]}),e.jsxs("div",{className:"p-4 py-3 space-y-2 flex-1",children:[e.jsxs("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-1",children:[e.jsx(Re,{className:"h-3 w-3"})," Offers & Bids"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-500/10 dark:border dark:border-blue-500/20 rounded-lg p-2.5 text-center min-h-[76px] flex flex-col justify-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium uppercase",children:"High Bid"}),e.jsxs("p",{className:"text-base font-bold text-blue-600 dark:text-blue-300",children:["$",(r.current_bid||0).toLocaleString()]}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate mt-0.5 h-3.5",title:r.high_bidder_name,children:r.high_bidder_name||"No Bidder"})]}),e.jsxs("div",{className:"bg-purple-50 dark:bg-purple-500/10 dark:border dark:border-purple-500/20 rounded-lg p-2.5 text-center min-h-[76px] flex flex-col justify-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium uppercase",children:"Direct Offer"}
6),e.jsx("p",{className:"text-base font-bold text-purple-600 dark:text-purple-300",children:r.direct_offer_amount?`$${r.direct_offer_amount.toLocaleString()}`:"—"}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate mt-0.5 h-3.5",title:r.direct_offer_dealer_name||"",children:r.direct_offer_dealer_name||" "})]}),e.jsxs("div",{className:"bg-orange-50 dark:bg-orange-500/10 dark:border dark:border-orange-500/20 rounded-lg p-2.5 text-center min-h-[76px] flex flex-col justify-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium uppercase",children:"Cust. Counter"}),e.jsx("p",{className:"text-base font-bold text-orange-600 dark:text-orange-300",children:r.last_customer_counter?`$${r.last_customer_counter.toLocaleString()}`:"—"}),e.jsx("p",{className:"h-3.5"})]}),e.jsxs("div",{className:"bg-emerald-50 dark:bg-emerald-500/10 dark:border dark:border-emerald-500/20 rounded-lg p-2.5 text-center min-h-[76px] flex flex-col justify-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium uppercase",children:"Dealer Counter"}),e.jsx("p",{className:"text-base font-bold text-emerald-600 dark:text-emerald-300",children:r.counter_offer?`$${r.counter_offer.toLocaleString()}`:"—"}),e.jsx("p",{className:"h-3.5"})]})]}),(r.kbb_lending_value||r.mmr_value||r.reserve_price)&&e.jsxs("div",{className:"flex items-center gap-3 bg-muted/40 dark:bg-slate-800/50 dark:border dark:border-slate-700/40 rounded-lg px-3 py-2 text-xs mt-2",children:[r.reserve_price&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Reserve:"})," ",e.jsxs("span",{className:"font-semibold text-amber-600 dark:text-amber-400",children:["$",r.reserve_price.toLocaleString()]})]}),r.kbb_lending_value&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"KBB:"})," ",e.jsxs("span",{className:"font-medium",children:["$",r.kbb_lending_value.toLocaleString()]})]}),r.mmr_value&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"MMR:"})," ",e.jsxs("span",{className:"font-medium",children:["$",r.mmr_value.toLocaleString()]})]})]})]}),e.jsx("div",{className:"px-4 pb-3",children:e.jsxs(Ns,{open:p,onOpenChange:D,children:[e.jsx(_s,{asChild:!0,children:e.jsxs("button",{className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-full",children:[e.jsx(Je,{className:"h-3 w-3"}),e.jsx("span",{className:"font-medium",children:"Admin Notes"}),p?e.jsx(ws,{className:"h-3 w-3 ml-auto"}):e.jsx(ys,{className:"h-3 w-3 ml-auto"})]})}),e.jsxs(ks,{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("input",{type:"text",placeholder:"Add a note...",value:u,onChange:w=>k(w.target.value),onKeyDown:w=>{w.key==="Enter"&&u.trim()&&!A&&O()},className:"flex-1 h-7 text-[11px] rounded-md border border-input bg-background px-2 placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"}),e.jsx("button",{onClick:O,disabled:A||!u.trim(),className:"h-7 w-7 flex items-center justify-center rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:pointer-events-none",children:e.jsx(Ae,{className:"h-3 w-3"})})]}),a?b.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground py-1",children:"No notes yet"}):e.jsx("div",{className:"space-y-2 max-h-32 overflow-y-auto",children:b.map(w=>e.jsxs("div",{className:"bg-muted/60 dark:bg-slate-800/60 rounded-md px-2.5 py-2 text-[11px]",children:[e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground mb-0.5",children:[e.jsx("span",{className:"font-medium text-foreground",children:w.admin_name}),e.jsx("span",{children:"•"}),e.jsx("span",{children:new Date(w.created_at).toLocaleDateString()})]}),e.jsx("p",{className:"text-foreground whitespace-pre-wrap leading-relaxed",children:w.note_content})]},w.id))}):e.jsx("p",{className:"text-[11px] text-muted-foreground py-2",children:"Loading..."})]})]})}),e.jsxs("div",{className:"px-4 pb-3 flex flex-wrap items-center justify-between gap-2 text-xs border-t border-border dark:border-slate-700/50 pt-3",children:[e.jsx("div",{className:"flex items-center gap-3",children:r.customer_name&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Cs,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:r.customer_name}),r.customer_phone&&e.jsx("span",{className:"text-muted-foreground ml-1",children:r.customer_phone})]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Rep: ",e.jsx("span",{className:"font-medium text-foreground",children:r.assigned_rep_name||"Unassigned"})]}),(r.updated_at||r.created_at)&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Ss,{className:"h-3 w-3"}),e.jsx("span",{children:n(r.updated_at||r.created_at)})]})]})]}),e.jsxs("div",{className:"px-4 pb-4 flex gap-2",children:[e.jsxs(E,{onClick:()=>c(r),className:"flex-1 bg-primary hover:bg-primary/90 text-primary-foreground",size:"sm",children:[e.jsx(Be,{className:"h-4 w-4 mr-1.5"}),"Manage Offer"]}),e.jsxs(ge,{children:[e.jsx(Me,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",children:e.jsx(Ve,{className:"h-4 w-4"})})}),e.jsxs(fe,{className:"max-w-[95vw] w-[95vw] h-[90vh] p-0",children:[e.jsx(pe,{className:"px-4 pt-4 pb-2",children:e.jsx(be,{children:"GHL CRM Dashboard"})}),e.jsx("iframe",{src:"https://app.1808agency.com/v2/location/GKKSE6v4Zh75VYPCENmv/dashboard",className:"w-full flex-1 border-0 rounded-b-lg",style:{height:"calc(90vh - 60px)"},allow:"clipboard-write"})]})]})]})]})})},at=({onDataRefresh:r,onManageOffer:c,calculateRevMeterValues:g,highlightCarId:N,filterRepId:f,filterDealerId:_,filterTemperature:C})=>{const[y,p]=l.useState([]),[D,b]=l.useState(!0),[t,a]=l.useState("grid"),i=ce(),u=Ne(),k=(s,n)=>{p(w=>w.map($=>
6$.id===s?{...$,deal_temperature:n}:$))},A=l.useMemo(()=>{let s=y;return f&&f!=="all"&&(s=f==="unassigned"?s.filter(n=>!n.assigned_rep_id):s.filter(n=>n.assigned_rep_id===f)),_&&_!=="all"&&(s=s.filter(n=>n.high_bidder_id===_)),C&&C!=="all"&&(s=C==="unmarked"?s.filter(n=>!n.deal_temperature):s.filter(n=>n.deal_temperature===C)),s},[y,f,_,C]),z=async()=>{try{b(!0),console.log("🔍 Fetching ended cars with optimized batch query...");const{data:s,error:n}=await v.from("cars").select("*").eq("status","ended").order("end_time",{ascending:!1});if(n){console.error("Error fetching ended cars:",n);return}if(console.log("📊 Found ended cars:",(s==null?void 0:s.length)||0),!s||s.length===0){p([]);return}const w=[...new Set(s.filter(h=>h.high_bidder_id).map(h=>h.high_bidder_id))],$=[...new Set(s.filter(h=>h.assigned_rep_id).map(h=>h.assigned_rep_id))],I=s.map(h=>h.id),K=new Map;if(w.length>0){const{data:h}=await v.from("dealership_users").select("user_id, dealership_id, dealerships:dealership_id(name)").in("user_id",w);h&&h.forEach(M=>{var j;const me=((j=M.dealerships)==null?void 0:j.name)||"Unknown Dealer";K.set(M.user_id,me)})}const[Y,q,G]=await Promise.all([v.from("counter_offers").select("vehicle_id, dealer_id, counter_bid_amount").in("vehicle_id",I).eq("status","pending").order("counter_bid_amount",{ascending:!1}),v.from("direct_offers").select("vehicle_id, dealer_id, dealer_name, offer_amount").in("vehicle_id",I).eq("status","pending").order("offer_amount",{ascending:!1}),$.length>0?v.from("users").select("id, name, business_name").in("id",$):Promise.resolve({data:[]})]),Z=new Map;if(G.data)for(const h of G.data)Z.set(h.id,h.name||h.business_name||"Unknown");const P=Y.data||[],H=q.data||[],m=new Map;P.forEach(h=>{const M=m.get(h.vehicle_id);(!M||h.counter_bid_amount>M.amount)&&m.set(h.vehicle_id,{amount:h.counter_bid_amount,dealerId:h.dealer_id})}),H.forEach(h=>{const M=m.get(h.vehicle_id);(!M||h.offer_amount>M.amount)&&m.set(h.vehicle_id,{amount:h.offer_amount,dealerId:h.dealer_id,dealerName:h.dealer_name})});const o=[...new Set(Array.from(m.entries()).filter(([h,M])=>!M.dealerName).map(([h,M])=>M.dealerId))],R=new Map;if(o.length>0){const{data:h}=await v.from("dealership_users").select("user_id, dealership_id, dealerships:dealership_id(name)").in("user_id",o);h&&h.forEach(M=>{var j;const me=((j=M.dealerships)==null?void 0:j.name)||"Unknown Dealer";R.set(M.user_id,me)})}const T=s.map(h=>{const M=m.get(h.id),me=(M==null?void 0:M.dealerName)||(M?R.get(M.dealerId):null)||"Unknown Dealer";return{...h,high_bidder_name:(h.high_bidder_id?K.get(h.high_bidder_id):null)||h.high_bidder_name||"Unknown Dealer",customer_name:h.customer_name||"Unknown Customer",direct_offer_amount:(M==null?void 0:M.amount)||null,direct_offer_dealer_name:M?me:null,assigned_rep_name:h.assigned_rep_id&&Z.get(h.assigned_rep_id)||null}});console.log("✅ Enriched cars data:",T),p(T)}catch(s){console.error("Error in fetchEndedCars:",s)}finally{b(!1)}};l.useEffect(()=>{z()},[]);const O=s=>{var I,K;const n=g(s),w=s.counter_offer||s.current_bid||0,$=s.high_bidder_name||"Unknown Dealer";return e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 p-4 border-b border-gray-100",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:`bg-blue-600 text-white px-3 py-1 rounded-full text-sm font-bold ${i?"cursor-pointer hover:bg-blue-700 transition-colors":""}`,onClick:i?()=>u(`/admin/vehicles/${s.id}`):void 0,children:["VIN: ",((I=s.vin)==null?void 0:I.slice(-6))||"No VIN"]}),e.jsxs("div",{className:"bg-gray-100 px-2 py-1 rounded text-xs text-gray-600",children:["ID: ",((K=s.id)==null?void 0:K.slice(-6))||"No ID"]})]}),e.jsx(es,{carId:s.id,value:s.deal_temperature,size:"md",onChange:k})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl font-bold text-gray-900 leading-tight mb-1",children:[s.year," ",s.make," ",s.model]}),e.jsx("p",{className:"text-lg text-gray-600 font-medium",children:$})]})]}),e.jsxs("div",{className:"bg-green-50 border-l-4 border-green-400 p-6 text-center",children:[e.jsx("p",{className:"text-lg text-gray-700 mb-2 font-semibold",children:"Current Offer"}),e.jsxs("p",{className:"text-3xl font-bold text-green-600",children:["$",w.toLocaleStr
6ing()]})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-6",children:[e.jsxs("div",{className:"bg-gray-50 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-sm text-gray-600 mb-2 font-medium",children:"Dealer Bid"}),e.jsxs("p",{className:"text-xl font-bold text-gray-900",children:["$",(s.current_bid||0).toLocaleString()]})]}),e.jsxs("div",{className:"bg-gray-50 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-sm text-gray-600 mb-2 font-medium",children:"Counter Offer"}),e.jsxs("p",{className:"text-xl font-bold text-gray-900",children:["$",(s.counter_offer||0).toLocaleString()]})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4 mb-6",children:e.jsxs("div",{className:"bg-blue-50 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm text-gray-600 mb-1 font-medium",children:"Customer"}),s.customer_name?e.jsx(ve,{car:s,children:e.jsx("p",{className:"text-lg font-bold text-blue-600 break-words cursor-pointer hover:underline",children:s.customer_name})}):e.jsx("p",{className:"text-lg font-bold text-gray-900 break-words",children:"Unknown"}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:s.customer_phone||"No Phone"})]})}),e.jsxs("div",{className:"border-t border-gray-100 pt-6",children:[e.jsx("p",{className:"text-lg font-bold text-gray-700 mb-4 text-center",children:"Performance Metrics"}),e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx(he,{value:n.offerVsRange,color:"teal",size:"lg"}),e.jsx("p",{className:"text-sm text-gray-600 mt-3 font-semibold",children:"Value"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx(he,{value:n.offerVsReserve,color:"red",size:"lg"}),e.jsx("p",{className:"text-sm text-gray-600 mt-3 font-semibold",children:"Reserve"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx(he,{value:n.reserveVsKbb,color:"yellow",size:"lg"}),e.jsx("p",{className:"text-sm text-gray-600 mt-3 font-semibold",children:"KBB"})]})]})]}),e.jsx("div",{className:"pt-6",children:e.jsx(E,{className:"w-full bg-teal-600 hover:bg-teal-700 text-white font-bold py-4 text-lg rounded-xl shadow-lg",size:"lg",onClick:()=>c(s),children:"Manage Offer"})})]})]},s.id)},d=()=>e.jsxs("div",{className:"bg-card rounded-xl border border-border shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-8 gap-4 px-6 py-4 text-sm font-semibold text-muted-foreground bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Vehicle"}),e.jsx("span",{children:"VIN"}),e.jsx("span",{children:"Dealer"}),e.jsx("span",{children:"Original Bid"}),e.jsx("span",{children:"Direct Offer"}),e.jsx("span",{children:"Counter Offer"}),e.jsx("span",{children:"Customer"}),e.jsx("span",{children:"Actions"})]}),A.map((s,n)=>{g(s);const w=N===s.id;return e.jsxs("div",{id:`car-row-${s.id}`,className:`grid grid-cols-8 gap-4 px-6 py-5 items-center transition-all hover:bg-muted/30 ${n!==A.length-1?"border-b border-border/50":""} ${w?"ring-2 ring-primary ring-offset-2":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[s.images&&s.images.length>0?e.jsx("img",{src:s.images[0],alt:`${s.year} ${s.make} ${s.model}`,className:"w-20 h-14 object-cover rounded-lg border border-border"}):e.jsx("div",{className:"w-20 h-14 bg-muted rounded-lg flex items-center justify-center border border-border",children:e.jsx(de,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0",children:e.jsxs("p",{className:"text-sm font-semibold text-foreground leading-tight whitespace-normal",children:[s.year," ",s.make," ",s.model]})})]}),e.jsx("div",{className:"text-sm font-mono text-primary hover:text-primary/80 cursor-pointer truncate",onClick:()=>u(`/admin/vehicles/${s.id}`),children:s.vin}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground leading-tight",children:s.high_bidder_name||"No Bidder"}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:s.high_bidder_id?s.high_bidder_id.substring(0,8):"N/A"})]}),e.jsx("div",{children:e.jsxs("p",{className:"text-lg font-bold text-blue-500 dark:text-blue-400",children:["$",(s.current_bid||0).toLocaleStr
6ing()]})}),e.jsx("div",{children:s.direct_offer_amount?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-lg font-bold text-purple-500 dark:text-purple-400",children:["$",s.direct_offer_amount.toLocaleString()]}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.direct_offer_dealer_name||"Unknown Dealer"})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No offers"})}),e.jsx("div",{children:e.jsxs("p",{className:"text-lg font-bold text-emerald-500 dark:text-emerald-400",children:["$",(s.counter_offer||0).toLocaleString()]})}),e.jsxs("div",{className:"space-y-2",children:[s.customer_name?e.jsx(ve,{car:s,children:e.jsx("p",{className:"text-sm font-medium text-foreground hover:text-primary cursor-pointer truncate",children:s.customer_name})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"N/A"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.customer_phone||"No Phone"}),e.jsxs("div",{className:"flex items-center gap-3 pt-1 flex-wrap",children:[s.kbb_lending_value?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"KBB"}),e.jsxs("p",{className:"text-xs font-medium text-foreground",children:["$",s.kbb_lending_value.toLocaleString()]})]}):null,s.mmr_value?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"MMR"}),e.jsxs("p",{className:"text-xs font-medium text-foreground",children:["$",s.mmr_value.toLocaleString()]})]}):null,s.reserve_price?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Reserve"}),e.jsxs("p",{className:"text-xs font-medium text-amber-600 dark:text-amber-400",children:["$",s.reserve_price.toLocaleString()]})]}):null,!s.kbb_lending_value&&!s.mmr_value&&!s.reserve_price&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No values"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{size:"sm",onClick:()=>c(s),className:"w-full bg-primary hover:bg-primary/90 text-primary-foreground text-xs px-4 py-2 rounded-lg font-medium shadow-sm",children:"Manage Offer"}),e.jsxs(ge,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"w-full text-xs",children:[e.jsx(Ve,{className:"h-3 w-3 mr-1"}),"CRM"]})}),e.jsxs(fe,{className:"max-w-[95vw] w-[95vw] h-[90vh] p-0",children:[e.jsx(pe,{className:"px-4 pt-4 pb-2",children:e.jsx(be,{children:"GHL CRM Dashboard"})}),e.jsx("iframe",{src:"https://app.1808agency.com/v2/location/GKKSE6v4Zh75VYPCENmv/dashboard",className:"w-full flex-1 border-0 rounded-b-lg",style:{height:"calc(90vh - 60px)"},allow:"clipboard-write"})]})]})]})]},s.id)})]});return D?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(ie,{className:"h-6 w-6 animate-spin text-primary"}),e.jsx("span",{className:"ml-2 text-sm text-gray-600",children:"Loading ended auctions..."})]}):A.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-gray-500 text-lg",children:"No ended auctions found"}),e.jsx(E,{onClick:()=>{z(),r()},variant:"outline",className:"mt-4",children:"Refresh Data"})]}):i||typeof window<"u"&&window.innerWidth<768?e.jsx("div",{className:"space-y-4 p-2",children:A.map(s=>O(s))}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(Pe,{view:t,onViewChange:a})}),t==="grid"?e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:A.map(s=>e.jsx(Ke,{car:s,onManageOffer:c,statusLabel:"Ended",statusColor:"gray",onTemperatureChange:k},s.id))}):d()]})},ss=({car:r,onManageOffer:c,calculateRevMeterValues:g})=>{var D,b;const N=g(r),f=r.counter_offer||r.current_bid||0,_=r.high_bidder_name||"Unknown Dealer",C=ce(),[y,p]=l.useState([]);return l.useEffect(()=>{let t=!1;return(async()=>{if(!(r!=null&&r.id))return;const{data:a}=await v.from("admin_notes").select("id, note_content, admin_id, created_at").eq("car_id",r.id).order("created_at",{ascending:!1});if(t||!a)return;const i=[...new Set(a.map(k=>
6k.admin_id).filter(Boolean))];let u={};if(i.length){const{data:k}=await v.from("users").select("id, name").in("id",i);u=Object.fromEntries((k||[]).map(A=>[A.id,A.name]))}p(a.map(k=>({id:k.id,note_content:k.note_content,created_at:k.created_at,admin_name:u[k.admin_id]||"Admin"})))})(),()=>{t=!0}},[r==null?void 0:r.id]),e.jsxs("div",{className:"bg-card dark:bg-slate-900 rounded-xl border border-border dark:border-slate-700 p-4 md:p-6 space-y-4 md:space-y-5 shadow-sm",children:[e.jsxs("div",{className:"space-y-2 md:space-y-3",children:[e.jsxs("div",{className:"flex items-center flex-wrap gap-2 md:gap-3",children:[e.jsxs("span",{className:"text-lg md:text-2xl font-bold text-foreground",children:["VIN: ",((D=r.vin)==null?void 0:D.slice(-6))||"No VIN"]}),e.jsxs(oe,{variant:"outline",className:"text-sm md:text-base px-2 md:px-3 py-1 md:py-2",children:["ID: ",((b=r.id)==null?void 0:b.slice(-6))||"No ID"]})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl md:text-2xl font-bold text-foreground leading-tight",children:[r.year," ",r.make," ",r.model]}),e.jsx("p",{className:"text-lg md:text-xl text-muted-foreground mt-1 md:mt-2 font-medium",children:_})]})]}),e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 rounded-xl p-4 md:p-6 text-center border-2 border-green-200 dark:border-green-800",children:[e.jsx("p",{className:"text-lg md:text-xl text-muted-foreground mb-2 md:mb-3 font-semibold",children:r.counter_offer?"Dealer Counter Active":r.last_customer_counter?"Customer Counter Active":"Current Offer"}),e.jsxs("p",{className:"text-3xl md:text-4xl font-bold text-green-600 dark:text-green-400",children:["$",f.toLocaleString()]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:gap-5",children:[e.jsxs("div",{className:"space-y-1 md:space-y-3 text-center",children:[e.jsx("p",{className:"text-sm md:text-base text-muted-foreground font-semibold",children:"Original Bid"}),e.jsxs("p",{className:"text-lg md:text-xl font-bold text-blue-600 dark:text-blue-400",children:["$",(r.current_bid||0).toLocaleString()]})]}),e.jsxs("div",{className:"space-y-1 md:space-y-3 text-center",children:[e.jsx("p",{className:"text-sm md:text-base text-muted-foreground font-semibold",children:"High Direct Offer"}),r.direct_offer_amount?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-lg md:text-xl font-bold text-purple-500 dark:text-purple-400",children:["$",r.direct_offer_amount.toLocaleString()]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.direct_offer_dealer_name})]}):e.jsx("p",{className:"text-lg md:text-xl font-bold text-muted-foreground",children:"—"})]}),e.jsxs("div",{className:"space-y-1 md:space-y-3 text-center",children:[e.jsx("p",{className:"text-sm md:text-base text-muted-foreground font-semibold",children:"Cust. Counter"}),e.jsx("p",{className:"text-lg md:text-xl font-bold text-orange-600 dark:text-orange-400",children:r.last_customer_counter?`$${r.last_customer_counter.toLocaleString()}`:"—"})]}),e.jsxs("div",{className:"space-y-1 md:space-y-3 text-center",children:[e.jsx("p",{className:"text-sm md:text-base text-muted-foreground font-semibold",children:"Dealer Counter"}),e.jsx("p",{className:"text-lg md:text-xl font-bold text-emerald-600 dark:text-emerald-400",children:r.counter_offer?`$${r.counter_offer.toLocaleString()}`:"—"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("span",{className:"text-base text-muted-foreground font-semibold",children:"Customer:"}),r.customer_name&&C?e.jsx(ve,{car:r,children:e.jsx("span",{className:"text-lg font-bold text-primary cursor-pointer hover:underline",children:r.customer_name})}):e.jsx("span",{className:"text-lg font-bold text-foreground",children:r.customer_name||"Unknown"})]}),e.jsxs("div",{className:"border-t border-border dark:border-slate-700 pt-4 md:pt-6",children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-foreground mb-3 md:mb-5",children:"Performance Metrics"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 md:gap-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsx(he,{value:N.offerVsRange,color:"teal",size:"lg"}),e.jsx("p",{className:"text-base md:text-lg text-muted-foreground mt-2 md:mt-4 font-bold",children:"Value"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx(he,{value:N.offerVsReserve,color:"red",size:"lg"}),e.jsx("p",{className:"text-base md:text-lg text-muted-foreground mt-2 md:mt-4 font-bold",children:"Reserve"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx(he,{value:N.reserveVsKbb,color:"yellow",size:"lg"}),e.jsx("p",{className:"text-base md:text-lg text-muted-foreground mt-2 md:mt-4 font-bold",children:"KBB"})]})]})]}),y.length>0&&e.jsxs("div",{className:"border-t border-border dark:border-slate-700 pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Je,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("p",{className:"text-base font-bold text-foreground",children:["Admin Notes (",y.length,")"]})]}),e.jsx("div",{className:"space-y-2 max-h-64 overflow-y-auto",children:y.map(t=>e.jsxs("div",{className:"bg-muted/60 dark:bg-slate-800/60 rounded-md px-3 py-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground text-xs mb-1",children:[e.jsx("span",{className:"font-semibold text-foreground",children:t.admin_name}),e.jsx("span",{children:"•"}
6),e.jsx("span",{children:new Date(t.created_at).toLocaleString()})]}),e.jsx("p",{className:"text-foreground whitespace-pre-wrap leading-relaxed",children:t.note_content})]},t.id))})]}),e.jsx("div",{className:"pt-2 md:pt-4",children:e.jsx(E,{onClick:()=>c(r),className:"w-full bg-green-600 hover:bg-green-700 text-white font-bold py-4 md:py-6 text-xl md:text-2xl rounded-xl",size:"lg",children:"Manage Offer"})})]})},nt=({onManageOffer:r,calculateRevMeterValues:c,highlightCarId:g,filterRepId:N,filterDealerId:f,filterTemperature:_})=>{const C=Ne(),y=ce(),[p,D]=l.useState([]),[b,t]=l.useState(!0),[a,i]=l.useState("grid"),u=l.useRef(!0),k=(s,n)=>{D(w=>w.map($=>$.id===s?{...$,deal_temperature:n}:$))},A=l.useMemo(()=>{let s=p;return N&&N!=="all"&&(s=N==="unassigned"?s.filter(n=>!n.assigned_rep_id):s.filter(n=>n.assigned_rep_id===N)),f&&f!=="all"&&(s=s.filter(n=>n.high_bidder_id===f)),_&&_!=="all"&&(s=_==="unmarked"?s.filter(n=>!n.deal_temperature):s.filter(n=>n.deal_temperature===_)),s},[p,N,f,_]),z=async(s=!1)=>{!s&&u.current&&t(!0);try{console.log("🔄 Fetching cars with on_offer status...");const{data:n,error:w}=await v.from("cars").select("*").eq("status","on_offer").neq("listing_type","cdx").order("created_at",{ascending:!1});if(w){console.error("Error fetching customer counter cars:",w),U.error("Failed to load customer counter cars");return}const $=await O(n||[]);console.log("Fetched customer counter cars:",$),D($)}catch(n){console.error("Exception fetching customer counter cars:",n),U.error("An error occurred while loading customer counter cars")}finally{u.current&&(u.current=!1),t(!1)}},O=async s=>{if(!s.length)return s;const n=s.map(o=>o.id),w=[...new Set(s.filter(o=>o.high_bidder_id).map(o=>o.high_bidder_id))],$=[...new Set(s.filter(o=>o.assigned_rep_id).map(o=>o.assigned_rep_id))],[I,K,Y,q]=await Promise.all([v.from("counter_offers").select("vehicle_id, dealer_id, counter_bid_amount").in("vehicle_id",n).eq("status","pending"),v.from("direct_offers").select("vehicle_id, dealer_id, dealer_name, offer_amount").in("vehicle_id",n).eq("status","pending"),w.length>0?v.from("dealership_users").select("user_id, dealerships:dealership_id(name)").in("user_id",w):Promise.resolve({data:[]}),$.length>0?v.from("users").select("id, name, business_name").in("id",$):Promise.resolve({data:[]})]),G=new Map;if(q.data)for(const o of q.data)G.set(o.id,o.name||o.business_name||"Unknown");const Z=new Map;if(Y.data)for(const o of Y.data){const R=Array.isArray(o.dealerships)?o.dealerships[0]:o.dealerships;R!=null&&R.name&&Z.set(o.user_id,R.name)}const P=new Map;if(I.data)for(const o of I.data){const R=P.get(o.vehicle_id);(!R||o.counter_bid_amount>R.amount)&&P.set(o.vehicle_id,{amount:o.counter_bid_amount,dealerId:o.dealer_id})}if(K.data)for(const o of K.data){const R=P.get(o.vehicle_id);(!R||o.offer_amount>R.amount)&&P.set(o.vehicle_id,{amount:o.offer_amount,dealerId:o.dealer_id,dealerName:o.dealer_name})}const H=new Set;P.forEach(o=>{!o.dealerName&&o.dealerId&&H.add(o.dealerId)});const m=new Map;if(H.size>0){const{data:o}=await v.from("dealership_users").select("user_id, dealership_id, dealerships(name)").in("user_id",Array.from(H));if(o)for(const T of o){const h=T.dealerships;h!=null&&h.name&&m.set(T.user_id,h.name)}const R=Array.from(H).filter(T=>!m.has(T));if(R.length>0){const{data:T}=await v.from("users").select("id, business_name, full_name").in("id",R);if(T)for(const h of T)m.has(h.id)||m.set(h.id,h.business_name||h.full_name||"Unknown Dealer")}}return s.map(o=>{const R=P.get(o.id),T=o.high_bidder_id&&Z.get(o.high_bidder_id)||o.high_bidder_name;return{...o,high_bidder_name:T,assigned_rep_name:o.assigned_rep_id&&G.get(o.assigned_rep_id)||null,...R?{direct_offer_amount:R.amount,direct_offer_dealer_name:R.dealerName||m.get(R.dealerId)||"Unknown Dealer"}:{}}})};l.useEffect(()=>{z();const s=()=>{console.log("🔄 Car update event detected, refreshing customer counter data"),z(!0)};return window.addEventListener("car-update",s),window.addEventListener("bid-data-updated",s),window.addEventListener("global-data-refresh",s),()=>{window.removeEventListener("car-update",s),window.removeEventListener("bid-data-updated",s),window.removeEventListener("global-data-refresh",s)}},[]);const d=s=>{console.log("🎯🎯🎯 CUSTOMER COUNTER MANAGE OFFER BUTTON CLICKED!!!",s),r(s)},S=s=>{C(`/admin/vehicles/${s}?from=auction-end-room`)};return b?e.jsx("div",{className:"bg-card rounded-lg border border-border p-4",children:e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(ie,{className:"h-6 w-6 animate-spin text-muted-foreground mr-2"}),e.jsx("span",{className:"text-muted-foreground",children:"Loading customer counter cars..."})]})}):A.length===0?e.jsxs("div",{className:"text-center py-12 bg-card rounded-lg border border-border",children:[e.jsx(de,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-foreground mb-2",children:"No customer counter cars found"}),e.jsx("p",{className:"text-muted-foreground",children:"There are no cars with customer counters at the moment."})]}):y?e.jsx("div",{className:"space-y-4",children:A.map(s=>e.jsx("div",{id:`car-row-${s.id}`,children:e.jsx(ss,{car:s,onManageOffer:d,calculateRevMeterValues:c||(()=>({offerVsRange:0,offerVsReserve:0,reserveVsKbb:0}))})},s.id))}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(Pe,{view:a,onViewChange:i})}),a==="grid"?e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:A.map(s=>e.jsx("div",{id:`car-row-${s.id}`,children:e.jsx(Ke,{car:s,onManageOffer:d,statusLabel:"Customer Counter",statusColor:"orange",onTemperatureChange:k})},s.id))}):e.jsxs("div",{className:"bg-card rounded-lg border border-border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-9 gap-4 p-4 text-sm font-medium text-muted-foreground border-b border-border bg-secondary/50",children:[e.jsx("span",{children:"Vehicle"}),e.jsx("span",{children:"VIN"}),e.jsx("span",{children:"Dealer"}
6),e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:"Original Bid"}),e.jsx("span",{className:"text-purple-600 dark:text-purple-400",children:"High Direct Offer"}),e.jsx("span",{className:"text-orange-600 dark:text-orange-400",children:"Customer Counter"}),e.jsx("span",{className:"text-emerald-600 dark:text-emerald-400",children:"Dealer Counter"}),e.jsx("span",{children:"Customer"}),e.jsx("span",{children:"Actions"})]}),A.map(s=>{c&&c(s);const n=g===s.id;return e.jsxs("div",{id:`car-row-${s.id}`,className:`grid grid-cols-9 gap-4 p-4 border-b border-border last:border-b-0 items-center bg-orange-500/10 dark:bg-orange-500/5 hover:bg-orange-500/15 dark:hover:bg-orange-500/10 transition-all ${n?"ring-2 ring-primary ring-offset-2":""}`,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[s.images&&s.images.length>0?e.jsx("img",{src:s.images[0],alt:`${s.year} ${s.make} ${s.model}`,className:"w-20 h-16 object-cover rounded-md"}):e.jsx("div",{className:"w-20 h-16 bg-secondary rounded-md flex items-center justify-center",children:e.jsx(de,{className:"h-6 w-6 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0",children:e.jsxs("p",{className:"text-sm font-medium text-foreground leading-tight",children:[s.year," ",s.make," ",s.model]})})]}),e.jsx("div",{className:"text-sm text-primary hover:text-primary/80 cursor-pointer underline truncate font-mono",onClick:()=>S(s.id),children:s.vin}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s.high_bidder_name||"No Bidder"}),e.jsxs("p",{className:"text-xs text-muted-foreground font-mono",children:["ID: ",s.high_bidder_id?s.high_bidder_id.substring(0,8):"N/A"]})]}),e.jsxs("div",{className:"text-sm font-semibold text-blue-600 dark:text-blue-400",children:["$",(s.current_bid||0).toLocaleString()]}),e.jsx("div",{children:s.direct_offer_amount?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-lg font-bold text-purple-500 dark:text-purple-400",children:["$",s.direct_offer_amount.toLocaleString()]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.direct_offer_dealer_name})]}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"—"})}),e.jsx("div",{className:"text-sm font-semibold text-orange-600 dark:text-orange-400",children:s.last_customer_counter?`$${s.last_customer_counter.toLocaleString()}`:"—"}),e.jsx("div",{className:"text-sm font-semibold text-emerald-600 dark:text-emerald-400",children:s.counter_offer?`$${s.counter_offer.toLocaleString()}`:"—"}),e.jsxs("div",{children:[s.customer_name?e.jsx(ve,{car:s,children:e.jsx("p",{className:"text-sm font-medium text-foreground hover:text-primary cursor-pointer",children:s.customer_name})}):e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"N/A"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.customer_phone||"No Phone"}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[s.kbb_lending_value?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"KBB"}),e.jsxs("p",{className:"text-xs font-medium text-foreground",children:["$",s.kbb_lending_value.toLocaleString()]})]}):null,s.mmr_value?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"MMR"}),e.jsxs("p",{className:"text-xs font-medium text-foreground",children:["$",s.mmr_value.toLocaleString()]})]}):null]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{size:"sm",onClick:()=>d(s),className:"w-full bg-primary hover:bg-primary/90 text-primary-foreground text-xs px-3 py-1",children:[e.jsx(Re,{className:"h-3 w-3 mr-1"}),"Manage Offer"]}),e.jsxs(ge,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"w-full text-xs",children:[e.jsx(Ve,{className:"h-3 w-3 mr-1"}),"CRM"]})}),e.jsxs(fe,{className:"max-w-[95vw] w-[95vw] h-[90vh] p-0",children:[e.jsx(pe,{className:"px-4 pt-4 pb-2",children:e.jsx(be,{children:"GHL CRM Dashboard"})}),e.jsx("iframe",{src:"https://app.1808agency.com/v2/location/GKKSE6v4Zh75VYPCENmv/dashboard",className:"w-full flex-1 border-0 rounded-b-lg",style:{height:"calc(90vh - 60px)"},allow:"clipboard-write"})]})]})]})]},s.id)})]})]})},dt=({dealerCounterCars:r,loading:c,onManageOffer:g,calculateRevMeterValues:N,highlightCarId:f,filterRepId:_,filterDealerId:C,filterTemperature:y})=>{const p=Ne(),D=ce(),[b,t]=l.useState([]),[a,i]=l.useState(!1),[u,k]=l.useState("grid"),A=(d,S)=>{t(s=>s.map(n=>n.id===d?{...n,deal_temperature:S}:n))},z=l.useMemo(()=>{let d=b;return _&&_!=="all"&&(d=_==="unassigned"?d.filter(S=>!S.assigned_rep_id):d.filter(S=>S.assigned_rep_id===_)),C&&C!=="all"&&(d=d.filter(S=>S.high_bidder_id===C)),y&&y!=="all"&&(d=y==="unmarked"?d.filter(S=>!S.deal_temperature):d.filter(S=>S.deal_temperature===y)),d},[b,_,C,y]);l.useEffect(()=>{(async()=>
6{if(!r.length){t([]);return}i(!0);try{const S=r.map(m=>m.id),s=[...new Set(r.filter(m=>m.high_bidder_id).map(m=>m.high_bidder_id))],n=[...new Set(r.filter(m=>m.assigned_rep_id).map(m=>m.assigned_rep_id))],[w,$,I,K]=await Promise.all([v.from("counter_offers").select("vehicle_id, dealer_id, counter_bid_amount").in("vehicle_id",S).eq("status","pending"),v.from("direct_offers").select("vehicle_id, dealer_id, dealer_name, offer_amount").in("vehicle_id",S).eq("status","pending"),s.length>0?v.from("dealership_users").select("user_id, dealerships:dealership_id(name)").in("user_id",s):Promise.resolve({data:[]}),n.length>0?v.from("users").select("id, name, business_name").in("id",n):Promise.resolve({data:[]})]),Y=new Map;if(K.data)for(const m of K.data)Y.set(m.id,m.name||m.business_name||"Unknown");const q=new Map;if(I.data)for(const m of I.data){const o=Array.isArray(m.dealerships)?m.dealerships[0]:m.dealerships;o!=null&&o.name&&q.set(m.user_id,o.name)}const G=new Map;if(w.data)for(const m of w.data){const o=G.get(m.vehicle_id);(!o||m.counter_bid_amount>o.amount)&&G.set(m.vehicle_id,{amount:m.counter_bid_amount,dealerId:m.dealer_id})}if($.data)for(const m of $.data){const o=G.get(m.vehicle_id);(!o||m.offer_amount>o.amount)&&G.set(m.vehicle_id,{amount:m.offer_amount,dealerId:m.dealer_id,dealerName:m.dealer_name})}const Z=new Set;G.forEach(m=>{!m.dealerName&&m.dealerId&&Z.add(m.dealerId)});const P=new Map;if(Z.size>0){const{data:m}=await v.from("dealership_users").select("user_id, dealership_id, dealerships(name)").in("user_id",Array.from(Z));if(m)for(const R of m){const T=R.dealerships;T!=null&&T.name&&P.set(R.user_id,T.name)}const o=Array.from(Z).filter(R=>!P.has(R));if(o.length>0){const{data:R}=await v.from("users").select("id, business_name, full_name").in("id",o);if(R)for(const T of R)P.has(T.id)||P.set(T.id,T.business_name||T.full_name||"Unknown Dealer")}}const H=r.map(m=>{const o=G.get(m.id),R=m.high_bidder_id&&q.get(m.high_bidder_id)||m.high_bidder_name;return{...m,high_bidder_name:R,assigned_rep_name:m.assigned_rep_id&&Y.get(m.assigned_rep_id)||null,...o?{direct_offer_amount:o.amount,direct_offer_dealer_name:o.dealerName||P.get(o.dealerId)||"Unknown Dealer"}:{}}});t(H)}catch(S){console.error("Error enriching cars with direct offers:",S),t(r)}finally{i(!1)}})()},[r]);const O=d=>{p(`/admin/vehicles/${d}`)};return c||a?e.jsx("div",{className:"bg-card rounded-lg border border-border p-4",children:e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(ie,{className:"h-6 w-6 animate-spin text-muted-foreground mr-2"}),e.jsx("span",{className:"text-muted-foreground",children:"Loading dealer counters..."})]})}):z.length===0?e.jsx("div",{className:"bg-card rounded-lg border border-border p-4",children:e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-muted-foreground",children:"No dealer counter offers found."})})}):D?e.jsx("div",{className:"space-y-4",children:z.map((d,S)=>e.jsx("div",{id:`car-row-${d.id}`,children:e.jsx(ss,{car:d,onManageOffer:g||(()=>{}),calculateRevMeterValues:N||(()=>({offerVsRange:0,offerVsReserve:0,reserveVsKbb:0}))})},d.id||S))}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(Pe,{view:u,onViewChange:k})}),u==="grid"?e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:z.map(d=>e.jsx("div",{id:`car-row-${d.id}`,children:e.jsx(Ke,{car:d,onManageOffer:g||(()=>{}),statusLabel:"Dealer Counter",statusColor:"emerald",onTemperatureChange:A})},d.id))}):e.jsxs("div",{className:"bg-card rounded-lg border border-border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-9 gap-4 p-4 text-sm font-medium text-muted-foreground border-b border-border bg-secondary/50",children:[e.jsx("span",{children:"Vehicle"}),e.jsx("span",{children:"VIN"}),e.jsx("span",{children:"Dealer"}),e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:"Original Bid"}),e.jsx("span",{className:"text-purple-600 dark:text-purple-400",children:"High Direct Offer"}
6),e.jsx("span",{className:"text-orange-600 dark:text-orange-400",children:"Customer Counter"}),e.jsx("span",{className:"text-emerald-600 dark:text-emerald-400",children:"Dealer Counter"}),e.jsx("span",{children:"Customer"}),e.jsx("span",{children:"Actions"})]}),z.map((d,S)=>{var n;N&&N(d);const s=f===d.id;return e.jsxs("div",{id:`car-row-${d.id}`,className:`grid grid-cols-9 gap-4 p-4 border-b border-border last:border-b-0 items-center bg-red-500/10 dark:bg-red-500/5 hover:bg-red-500/15 dark:hover:bg-red-500/10 transition-all ${s?"ring-2 ring-primary ring-offset-2":""}`,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[d.images&&d.images.length>0?e.jsx("img",{src:d.images[0],alt:`${d.year} ${d.make} ${d.model}`,className:"w-20 h-16 object-cover rounded-md"}):e.jsx("div",{className:"w-20 h-16 bg-secondary rounded-md flex items-center justify-center",children:e.jsx(de,{className:"h-6 w-6 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0",children:e.jsxs("p",{className:"text-sm font-medium text-foreground leading-tight",children:[d.year," ",d.make," ",d.model]})})]}),e.jsx("div",{className:"text-sm text-primary hover:text-primary/80 cursor-pointer underline truncate font-mono",onClick:()=>O(d.id),children:d.vin}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:d.high_bidder_name||"Unknown Dealer"}),e.jsxs("p",{className:"text-xs text-muted-foreground font-mono",children:["ID: ",((n=d.high_bidder_id)==null?void 0:n.substring(0,8))||"N/A"]})]}),e.jsxs("div",{className:"text-sm font-semibold text-blue-600 dark:text-blue-400",children:["$",(d.current_bid||0).toLocaleString()]}),e.jsx("div",{children:d.direct_offer_amount?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-lg font-bold text-purple-500 dark:text-purple-400",children:["$",d.direct_offer_amount.toLocaleString()]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.direct_offer_dealer_name})]}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"—"})}),e.jsx("div",{className:"text-sm font-semibold text-orange-600 dark:text-orange-400",children:d.last_customer_counter?`$${d.last_customer_counter.toLocaleString()}`:"—"}),e.jsx("div",{className:"text-sm font-semibold text-emerald-600 dark:text-emerald-400",children:d.counter_offer?`$${d.counter_offer.toLocaleString()}`:"—"}),e.jsxs("div",{children:[d.customer_name?e.jsx(ve,{car:d,children:e.jsx("p",{className:"text-sm font-medium text-foreground hover:text-primary cursor-pointer",children:d.customer_name})}):e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"N/A"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.customer_phone||"No Phone"}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[d.kbb_lending_value?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"KBB"}),e.jsxs("p",{className:"text-xs font-medium text-foreground",children:["$",d.kbb_lending_value.toLocaleString()]})]}):null,d.mmr_value?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"MMR"}),e.jsxs("p",{className:"text-xs font-medium text-foreground",children:["$",d.mmr_value.toLocaleString()]})]}):null,d.reserve_price?e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Reserve"}),e.jsxs("p",{className:"text-xs font-medium text-amber-600 dark:text-amber-400",children:["$",d.reserve_price.toLocaleString()]})]}):null]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(E,{onClick:()=>g==null?void 0:g(d),size:"sm",className:"w-full bg-primary hover:bg-primary/90 text-primary-foreground text-xs px-3 py-1",children:[e.jsx(Be,{className:"h-3 w-3 mr-1"}),"Manage Offer"]}),e.jsxs(ge,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"w-full text-xs",children:[e.jsx(Ve,{className:"h-3 w-3 mr-1"}),"CRM"]})}),e.jsxs(fe,{className:"max-w-[95vw] w-[95vw] h-[90vh] p-0",children:[e.jsx(pe,{className:"px-4 pt-4 pb-2",children:e.jsx(be,{children:"GHL CRM Dashboard"})}),e.jsx("iframe",{src:"https://app.1808agency.com/v2/location/GKKSE6v4Zh75VYPCENmv/dashboard",className:"w-full flex-1 border-0 rounded-b-lg",style:{height:"calc(90vh - 60px)"},allow:"clipboard-write"})]})]})]})]},d.id||S)})]})]})},it=({open:r,onOpenChange:c,selectedCar:g,onAcceptOffer:N,onCounterOffer:f,onEditBid:_,onNoSale:C,onSendDirectOffer:y})=>{const p=D=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0}).format(D);return e.jsx(ge,{open:r,onOpenChange:c,children:e.jsxs(fe,{className:"sm:max-w-lg",children:[e.jsxs(pe,{children:[e.jsx(be,{children:"🎯 Manage Offer"}),e.jsxs(We,{children:["Choose an action for this vehicle offer.",g&&e.jsxs("div",{className:"mt-2 text-sm",children:["Vehicle: ",g.year," ",g.make," ",g.model]})]})]}),(g==null?void 0:g.last_customer_counter)&&e.jsxs("div",{className:"border rounded-lg p-3 bg-blue-50 border-blue-200",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Qe,{className:"h-4 w-4 text-blue-600"}),e.jsx("span",{className:"font-medium text-blue-900",children:"Last Customer Counter Offer"}),e.jsx(oe,{variant:"secondary",className:"bg-blue-100 text-blue-800",children:"Customer"})]}),e.jsx("div",{className:"space-y-1 text-sm",children:e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-blue-700",children:"Amount:"}),e.jsx("span",{className:"font-semibold text-blue-900",children:p(g.last_customer_counter)})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 py-4",children:[e.jsxs(E,{onClick:()=>g&&N(g.id),className:"bg-green-600 hover:bg-green-700 text-white justify-start",children:[e.jsx(Ye,{className:"h-4 w-4 mr-2"}),"Accept Offer"]}),e.jsxs(E,{onClick:f,variant:"outline",className:"justify-start",children:[e.jsx(Re,{className:"h-4 w-4 mr-2"}),"Counter Offer"]}),e.jsxs(E,{onClick:_,variant:"outline",className:"justify-start",children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Edit Bid"]}),e.jsxs(E,{onClick:()=>C(),variant:"outline",className:"justify-start text-red-600 border-red-300 hover:bg-red-50",children:[e.jsx(qs,{className:"h-4 w-4 mr-2"}),"No Sale"]}),e.jsxs(E,{onClick:y,variant:"outline",className:"justify-start text-blue-600 border-blue-300 hover:bg-blue-50",children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Send Direct Offer"]})]})]})})},lt=({open:r,onOpenChange:c,selectedCar:g,onSuccess:N})=>{const[f,_]=l.useState([]),[C,y]=l.useState(""),[p,D]=l.useState(""),[b,t]=l.useState(""),[a,i]=l.useState(!1),[u,k]=l.useState(!1);l.useEffect(()=>{r&&(A(),D(""),t(""),y(""))},[r]);const A=async()=>{k(!0);try{const{data:O,error:d}=await v.from("dealership_users").select(`
7          user_id,
8          dealerships:dealership_id (
9            id,
10            name
11          )
12        `).order("created_at",{ascending:!0});if(d)throw d;const S=new Map;
12(O||[]).forEach(s=>{const n=Array.isArray(s.dealerships)?s.dealerships[0]:s.dealerships;!(n!=null&&n.id)||!(n!=null&&n.name)||S.has(n.id)||S.set(n.id,{id:n.id,name:n.name,dealerId:s.user_id||null})}),_(Array.from(S.values()).sort((s,n)=>s.name.localeCompare(n.name)))}catch(O){console.error("Error fetching dealerships:",O),U.error("Failed to load dealerships")}finally{k(!1)}},z=async()=>{if(!g||!C||!p){U.error("Please fill in all required fields");return}const O=parseFloat(p.replace(/,/g,""));if(isNaN(O)||O<=0){U.error("Please enter a valid offer amount");return}const d=f.find(s=>s.id===C);if(!d){U.error("Please select a valid dealership");return}let S=d.dealerId;if(!S){const{data:s}=await v.from("dealership_users").select("user_id").eq("dealership_id",C).limit(1).maybeSingle();S=(s==null?void 0:s.user_id)||null}if(!S){U.error("No dealer user found for this dealership");return}i(!0);try{const s=new Date;s.setHours(s.getHours()+48);const{error:n}=await v.from("direct_offers").insert({vehicle_id:g.id,vin:g.vin,dealer_id:S,dealer_name:d.name,dealership_id:C,offer_amount:O,offer_message:b.trim()||null,status:"pending",expires_at:s.toISOString()});if(n)throw n;U.success(`Direct offer of $${O.toLocaleString()} sent from ${d.name}`),c(!1),N()}catch(s){console.error("Error sending direct offer:",s),U.error("Failed to send direct offer")}finally{i(!1)}};return e.jsx(ge,{open:r,onOpenChange:c,children:e.jsxs(fe,{className:"sm:max-w-md",children:[e.jsxs(pe,{children:[e.jsx(be,{children:"📩 Send Direct Offer"}),e.jsxs(We,{children:["Send a direct offer to the customer from a dealership.",g&&e.jsxs("div",{className:"mt-2 text-sm",children:["Vehicle: ",g.year," ",g.make," ",g.model]})]})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{htmlFor:"dealership",children:"Dealership *"}),e.jsxs(te,{value:C,onValueChange:y,children:[e.jsx(re,{children:e.jsx(ae,{placeholder:u?"Loading...":"Select a dealership"})}),e.jsx(ne,{children:!u&&f.length===0?e.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"No dealerships available"}):f.map(O=>e.jsx(L,{value:O.id,children:O.name},O.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{htmlFor:"amount",children:"Offer Amount ($) *"}),e.jsx(Ze,{id:"amount",type:"text",inputMode:"numeric",placeholder:"e.g. 15000",value:p,onChange:O=>{const d=O.target.value.replace(/[^0-9]/g,"");D(d)}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{htmlFor:"message",children:"Message (optional)"}),e.jsx(Qs,{id:"message",placeholder:"Add a note for the customer...",value:b,onChange:O=>t(O.target.value),rows:3})]}),e.jsxs(E,{onClick:z,disabled:a||!C||!p,className:"w-full bg-blue-600 hover:bg-blue-700 text-white",children:[a?e.jsx(ie,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Send Direct Offer"]})]})]})})},ot=()=>{const[r,c]=l.useState([]),[g,N]=l.useState(!0),[f,_]=l.useState("all"),C=ce(),y=async()=>{try{N(!0);const{data:t,error:a}=await v.from("trade_in_requests").select(`
13          *,
14          dealerships:dealership_id (name)
15        `).order("created_at",{ascending:!1});if(a){console.error("Error fetching trade-in requests:",a);return}c(t||[])}catch(t){console.error("Error in fetchRequests:",t)}finally{N(!1)}},p=async t=>{try{const{error:a}=await v.from("trade_in_requests").delete().eq("id",t);if(a)throw a;U.success("Trade-in request deleted"),c(i=>
15i.filter(u=>u.id!==t))}catch(a){console.error("Error deleting trade-in request:",a),U.error("Failed to delete request")}};l.useEffect(()=>{y()},[]);const D=t=>{const a={pending:{variant:"secondary",className:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400"},quoted:{variant:"default",className:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400"},accepted:{variant:"default",className:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400"},declined:{variant:"destructive",className:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"},expired:{variant:"outline",className:"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400"}},i=a[t]||a.pending;return e.jsx(oe,{className:i.className,children:t.charAt(0).toUpperCase()+t.slice(1)})},b=f==="all"?r:r.filter(t=>t.status===f);return g?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(ie,{className:"h-6 w-6 animate-spin text-primary"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading trade-in requests..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 bg-card rounded-lg border border-border p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Filter by status:"})]}),e.jsxs(te,{value:f,onValueChange:_,children:[e.jsx(re,{className:"w-[180px]",children:e.jsx(ae,{placeholder:"Select status"})}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Requests"}),e.jsx(L,{value:"pending",children:"Pending"}),e.jsx(L,{value:"quoted",children:"Quoted"}),e.jsx(L,{value:"accepted",children:"Accepted"}),e.jsx(L,{value:"declined",children:"Declined"}),e.jsx(L,{value:"expired",children:"Expired"})]})]})]}),b.length===0?e.jsxs("div",{className:"text-center py-12 bg-card rounded-lg border border-border",children:[e.jsx(de,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground text-lg",children:"No trade-in requests found"}),e.jsx(E,{onClick:y,variant:"outline",className:"mt-4",children:"Refresh Data"})]}):C?e.jsx("div",{className:"space-y-4",children:b.map(t=>{var a,i;return e.jsxs("div",{className:"bg-card rounded-xl border border-border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-semibold text-foreground",children:[t.year," ",t.make," ",t.model]}),D(t.status)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Customer"}),e.jsx("p",{className:"font-medium text-foreground",children:t.customer_name})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Phone"}),e.jsx("p",{className:"font-medium text-foreground",children:t.customer_phone||"N/A"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Dealership"}),e.jsx("p",{className:"font-medium text-foreground",children:((a=t.dealerships)==null?void 0:a.name)||"Unknown"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Mileage"}),e.jsx("p",{className:"font-medium text-foreground",children:((i=t.mileage)==null?void 0:i.toLocaleString())||"N/A"})]})]}),t.quote_amount&&e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 rounded-lg p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Quote Amount"}),e.jsxs("p",{className:"text-xl font-bold text-green-600 dark:text-green-400",children:["$",t.quote_amount.toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Requested: ",new Date(t.created_at).toLocaleDateString()]}),e.jsxs(we,{children:[e.jsx(ye,{asChild:!0,children:e.jsx(E,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive hover:bg-destructive/10 h-7 px-2",children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})}),e.jsxs(ke,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:"Delete Trade-In Request"}),e.jsxs(De,{children:["This will permanently delete this trade-in request for ",t.year," ",t.make," ",t.model,". This action cannot be undone."]})]}),e.jsxs($e,{children:[e.jsx(Le,{children:"Cancel"}),e.jsx(Oe,{onClick:()=>p(t.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]},t.id)})}):e.jsxs("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-8 gap-4 px-6 py-4 text-sm font-semibold text-muted-foreground bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Customer"}),e.jsx("span",{children:"Vehicle"}),e.jsx("span",{children:"Mileage"}),e.jsx("span",{children:"Dealership"}),e.jsx("span",{children:"Status"}),e.jsx("span",{children:"Quote"}),e.jsx("span",{children:"Requested"}),e.jsx("span",{})]}),b.map((t,a)=>{var i,u;return e.jsxs("div",{className:`grid grid-cols-8 gap-4 px-6 py-4 items-center hover:bg-muted/30 transition-colors ${a!==b.length-1?"border-b border-border/50":""}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:t.customer_name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.customer_email}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.customer_phone})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-foreground",children:[t.year," ",t.make," ",t.model]}),t.trim&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.trim})]}),e.jsx("div",{className:"text-sm text-foreground",children:((i=t.mileage)==null?void 0:i.toLocaleStr
15ing())||"N/A"}),e.jsx("div",{className:"text-sm text-foreground",children:((u=t.dealerships)==null?void 0:u.name)||"Unknown"}),e.jsx("div",{children:D(t.status)}),e.jsx("div",{children:t.quote_amount?e.jsxs("p",{className:"text-sm font-bold text-green-600 dark:text-green-400",children:["$",t.quote_amount.toLocaleString()]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"—"})}),e.jsx("div",{className:"text-sm text-muted-foreground",children:new Date(t.created_at).toLocaleDateString()}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(we,{children:[e.jsx(ye,{asChild:!0,children:e.jsx(E,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive hover:bg-destructive/10 h-7 w-7 p-0",children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})}),e.jsxs(ke,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:"Delete Trade-In Request"}),e.jsxs(De,{children:["This will permanently delete this trade-in request for ",t.year," ",t.make," ",t.model,". This action cannot be undone."]})]}),e.jsxs($e,{children:[e.jsx(Le,{children:"Cancel"}),e.jsx(Oe,{onClick:()=>p(t.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})})]},t.id)})]})]})},ct=()=>{const[r,c]=l.useState([]),[g,N]=l.useState(!0),[f,_]=l.useState("all"),C=ce(),y=async()=>{try{N(!0);const t=new Date;t.setDate(t.getDate()-30);const{data:a,error:i}=await v.from("direct_offers").select(`
16          *,
17          cars:vehicle_id (year, make, model, customer_name, customer_email, customer_phone)
18        `).gte("created_at",t.toISOString()).order("created_at",{ascending:!1});if(i){console.error("Error fetching direct offers:",i);return}c(a||[])}catch(t){console.error("Error in fetchOffers:",t)}finally{N(!1)}};l.useEffect(()=>{y()},[]);const p=t=>new Date(t)<new Date,D=(t,a)=>{if(p(a)&&t==="pending")return e.jsx(oe,{className:"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-400",children:"Expired"});const u={pending:{className:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400"},accepted:{className:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400"},rejected:{className:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"},countered:{className:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400"},expired:{className:"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400"}},k=u[t]||u.pending;return e.jsx(oe,{className:k.className,children:t.charAt(0).toUpperCase()+t.slice(1)})},b=f==="all"?r:r.filter(t=>f==="expired"?p(t.expires_at)&&t.status==="pending":t.status===f);return g?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(ie,{className:"h-6 w-6 animate-spin text-primary"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading direct offers..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 bg-card rounded-lg border border-border p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Filter by status:"})]}),e.jsxs(te,{value:f,onValueChange:_,children:[e.jsx(re,{className:"w-[180px]",children:e.jsx(ae,{placeholder:"Select status"})}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Offers"}),e.jsx(L,{value:"pending",children:"Pending"}),e.jsx(L,{value:"accepted",children:"Accepted"}),e.jsx(L,{value:"rejected",children:"Rejected"}),e.jsx(L,{value:"countered",children:"Countered"}),e.jsx(L,{value:"expired",children:"Expired"})]})]})]}),b.length===0?e.jsxs("div",{className:"text-center py-12 bg-card rounded-lg border border-border",children:[e.jsx(de,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground text-lg",children:"No direct offers found"}),e.jsx(E,{onClick:y,variant:"outline",className:"mt-4",children:"Refresh Data"})]}):C?e.jsx("div",{className:"space-y-4",children:b.map(t=>{var a;return e.jsxs("div",{className:"bg-card rounded-xl border border-border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:t.cars?`${t.cars.year} ${t.cars.make} ${t.cars.model}`:"Unknown Vehicle"}),D(t.status,t.expires_at)]}),e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 rounded-lg p-3 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Offer Amount"}),e.jsxs("p",{className:"text-2xl font-bold text-green-600 dark:text-green-400",children:["$",t.offer_amount.toLocaleStr
18ing()]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Dealer"}),e.jsx("p",{className:"font-medium text-foreground",children:t.dealer_name})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Customer"}),e.jsx("p",{className:"font-medium text-foreground",children:((a=t.cars)==null?void 0:a.customer_name)||"N/A"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"VIN"}),e.jsx("p",{className:"font-mono text-xs text-foreground",children:t.vin.slice(-8)})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p(t.expires_at)?"Expired":`Expires: ${new Date(t.expires_at).toLocaleDateString()}`})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Sent: ",new Date(t.created_at).toLocaleDateString()]})]},t.id)})}):e.jsxs("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-7 gap-4 px-6 py-4 text-sm font-semibold text-muted-foreground bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Dealer"}),e.jsx("span",{children:"Vehicle"}),e.jsx("span",{children:"Customer"}),e.jsx("span",{children:"Offer Amount"}),e.jsx("span",{children:"Status"}),e.jsx("span",{children:"Expires"}),e.jsx("span",{children:"Sent"})]}),b.map((t,a)=>{var i,u;return e.jsxs("div",{className:`grid grid-cols-7 gap-4 px-6 py-4 items-center hover:bg-muted/30 transition-colors ${a!==b.length-1?"border-b border-border/50":""} ${p(t.expires_at)&&t.status==="pending"?"bg-orange-50/50 dark:bg-orange-900/10":""}`,children:[e.jsx("div",{children:e.jsx("p",{className:"text-sm font-medium text-foreground",children:t.dealer_name})}),e.jsx("div",{children:t.cars?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm font-medium text-foreground",children:[t.cars.year," ",t.cars.make," ",t.cars.model]}),e.jsx("p",{className:"text-xs font-mono text-muted-foreground",children:t.vin.slice(-8)})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Unknown"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:((i=t.cars)==null?void 0:i.customer_name)||"N/A"}),((u=t.cars)==null?void 0:u.customer_phone)&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.cars.customer_phone})]}),e.jsx("div",{children:e.jsxs("p",{className:"text-lg font-bold text-green-600 dark:text-green-400",children:["$",t.offer_amount.toLocaleString()]})}),e.jsx("div",{children:D(t.status,t.expires_at)}),e.jsx("div",{className:"text-sm",children:p(t.expires_at)?e.jsx("span",{className:"text-orange-600 dark:text-orange-400 font-medium",children:"Expired"}):e.jsx("span",{className:"text-muted-foreground",children:new Date(t.expires_at).toLocaleDateString()})}),e.jsx("div",{className:"text-sm text-muted-foreground",children:new Date(t.created_at).toLocaleDateString()})]},t.id)})]})]})},mt=()=>{const[r,c]=l.useState([]),[g,N]=l.useState(!0),[f,_]=l.useState("all"),C=ce(),y=async()=>{try{N(!0);const{data:a,error:i}=await v.from("dealer_offer_requests").select(`
19          *,
20          dealerships:dealership_id (name),
21          cars:car_id (year, make, model, vin)
22        `).order("created_at",{ascending:!1});if(i){console.error("Error fetching dealer offer requests:",i);return}c(a||[])}catch(a){console.error("Error in fetchRequests:",a)}finally{N(!1)}},p=async(a,i)=>{try{const{error:u}=await v.from("dealer_offer_requests").update({status:i}).eq("id",a);if(u)throw u;U.success(`Request marked as ${i}`),await y()}catch(u){console.error("Error updating status:",u),U.error("Failed to update status")}},D=async a=>{try{const{error:i}=await v.from("dealer_offer_requests").delete().eq("id",a);if(i)throw i;U.success("Offer request deleted"),c(u=>u.filter(k=>k.id!==a))}catch(i){console.error("Error deleting offer request:",i),U.error("Failed to delete request")}};l.useEffect(()=>{y()},[]);const b=a=>{const i={pending:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400",contacted:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400",offer_sent:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400",declined:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"};return e.jsx(oe,{className:i[a]||i.pending,children:a.charAt(0).toUpperCase()+a.slice(1).replace("_"," ")})},t=f==="all"?r:r.filter(a=>a.status===f);return g?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(ie,{className:"h-6 w-6 animate-spin text-primary"}),e.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading offer requests..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 bg-card rounded-lg border border-border p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Filter by status:"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(te,{value:f,onValueChange:_,children:[e.jsx(re,{className:"w-[180px]",children:e.jsx(ae,{placeholder:"Select status"})}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Requests"}),e.jsx(L,{value:"pending",children:"Pending"}),e.jsx(L,{value:"contacted",children:"Contacted"}),e.jsx(L,{value:"offer_sent",children:"Offer Sent"}),e.jsx(L,{value:"declined",children:"Declined"})]})]}),e.jsxs(E,{onClick:y,variant:"outline",size:"sm",className:"gap-1.5",children:[e.jsx(Ds,{className:"h-3.5 w-3.5"}),"Refresh"]})]})]}),t.length===0?e.jsxs("div",{className:"text-center py-12 bg-card rounded-lg border border-border",children:[e.jsx(He,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground text-lg",children:"No offer requests found"})]}):C?e.jsx("div",{className:"space-y-4",children:t.map(a=>{var i;return e.jsxs("div",{className:"bg-card rounded-xl border border-border p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:a.cars?`${a.cars.year} ${a.cars.make} ${a.cars.model}`:"Vehicle not linked"}),b(a.status)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Customer"}),e.jsx("p",{className:"font-medium text-foreground",children:a.customer_name||"N/A"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Email"}),e.jsx("p",{className:"font-medium text-foreground truncate",children:a.customer_email||"N/A"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Dealership"}),e.jsx("p",{className:"font-medium text-foreground",children:((i=a.dealerships)==null?void 0:i.name)||"Unknown"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"Requested"}),e.jsx("p",{className:"font-medium text-foreground",children:new Date(a.created_at).toLocaleDateString()})]})]}),a.notes&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-2 text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Notes: "}),a.notes]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[a.status==="pending"&&e.jsx(E,{size:"sm",variant:"outline",className:"flex-1 text-xs",onClick:()=>
22p(a.id,"contacted"),children:"Mark Contacted"}),a.status==="contacted"&&e.jsx(E,{size:"sm",variant:"outline",className:"flex-1 text-xs",onClick:()=>p(a.id,"offer_sent"),children:"Mark Offer Sent"}),a.status!=="declined"&&a.status!=="offer_sent"&&e.jsx(E,{size:"sm",variant:"outline",className:"flex-1 text-xs text-red-600 border-red-200",onClick:()=>p(a.id,"declined"),children:"Decline"}),e.jsxs(we,{children:[e.jsx(ye,{asChild:!0,children:e.jsx(E,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive hover:bg-destructive/10 h-8 w-8 p-0",children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})}),e.jsxs(ke,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:"Delete Offer Request"}),e.jsx(De,{children:"This will permanently delete this offer request. This action cannot be undone."})]}),e.jsxs($e,{children:[e.jsx(Le,{children:"Cancel"}),e.jsx(Oe,{onClick:()=>D(a.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]},a.id)})}):e.jsxs("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-7 gap-4 px-6 py-4 text-sm font-semibold text-muted-foreground bg-muted/50 border-b border-border",children:[e.jsx("span",{children:"Customer"}),e.jsx("span",{children:"Vehicle"}),e.jsx("span",{className:"col-span-2",children:"Dealership Requested"}),e.jsx("span",{children:"Status"}),e.jsx("span",{children:"Requested"}),e.jsx("span",{children:"Actions"})]}),t.map((a,i)=>{var u;return e.jsxs("div",{className:`grid grid-cols-7 gap-4 px-6 py-4 items-center hover:bg-muted/30 transition-colors ${i!==t.length-1?"border-b border-border/50":""}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:a.customer_name||"—"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.customer_email||"—"})]}),e.jsx("div",{children:a.cars?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm font-medium text-foreground",children:[a.cars.year," ",a.cars.make," ",a.cars.model]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.cars.vin})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"—"})}),e.jsxs("div",{className:"col-span-2 flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(He,{className:"h-4 w-4 text-primary"})}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:((u=a.dealerships)==null?void 0:u.name)||"Unknown"})]}),e.jsx("div",{children:b(a.status)}),e.jsx("div",{className:"text-sm text-muted-foreground",children:new Date(a.created_at).toLocaleDateString()}),e.jsxs("div",{className:"flex flex-col gap-1",children:[a.status==="pending"&&e.jsx(E,{size:"sm",variant:"outline",className:"text-xs h-7",onClick:()=>p(a.id,"contacted"),children:"Contacted"}),a.status==="contacted"&&e.jsx(E,{size:"sm",variant:"outline",className:"text-xs h-7",onClick:()=>p(a.id,"offer_sent"),children:"Offer Sent"}),a.status!=="declined"&&a.status!=="offer_sent"&&e.jsx(E,{size:"sm",variant:"outline",className:"text-xs h-7 text-red-600 border-red-200 hover:bg-red-50",onClick:()=>p(a.id,"declined"),children:"Decline"}),e.jsxs(we,{children:[e.jsx(ye,{asChild:!0,children:e.jsxs(E,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive hover:bg-destructive/10 text-xs h-7",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 mr-1"})," Delete"]})}),e.jsxs(ke,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:"Delete Offer Request"}),e.jsx(De,{children:"This will permanently delete this offer request. This action cannot be undone."})]}),e.jsxs($e,{children:[e.jsx(Le,{children:"Cancel"}),e.jsx(Oe,{onClick:()=>D(a.id),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]},a.id)})]})]})},xt=({onSelectCar:r,isMobile:c=!1})=>{const[g,N]=l.useState(""),[f,_]=l.useState([]),[C,y]=l.useState(!1),[p,D]=l.useState(!1),b=l.useRef(null);l.useEffect(()=>{const i=u=>{b.current&&!b.current.contains(u.target)&&D(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[]),l.useEffect(()=>{const u=setTimeout(async()=>
22{if(!g.trim()||g.length<2){_([]),D(!1);return}y(!0);try{const k=g.toLowerCase(),[A,z,O]=await Promise.all([v.from("cars").select("id, vin, year, make, model, customer_name, status").eq("status","ended").or(`vin.ilike.%${k}%,make.ilike.%${k}%,model.ilike.%${k}%,customer_name.ilike.%${k}%,customer_phone.ilike.%${k}%`).limit(10),v.from("cars").select("id, vin, year, make, model, customer_name, status").eq("status","on_offer").or(`vin.ilike.%${k}%,make.ilike.%${k}%,model.ilike.%${k}%,customer_name.ilike.%${k}%,customer_phone.ilike.%${k}%`).limit(10),v.from("counter_offers").select(`
23              vehicle_id,
24              cars!inner(id, vin, year, make, model, customer_name, status)
25            `).eq("status","pending").limit(10)]),d=[];A.data&&A.data.forEach(s=>{d.push({...s,tab:"live-auctions",tabLabel:"Auction Ended"})}),z.data&&z.data.forEach(s=>{d.push({...s,tab:"ended-auctions",tabLabel:"Customer Counter"})}),O.data&&O.data.forEach(s=>{var w,$,I,K;const n=s.cars;n&&((w=n.vin)!=null&&w.toLowerCase().includes(k)||($=n.make)!=null&&$.toLowerCase().includes(k)||(I=n.model)!=null&&I.toLowerCase().includes(k)||(K=n.customer_name)!=null&&K.toLowerCase().includes(k))&&(d.some(G=>G.id===n.id)||d.push({id:n.id,vin:n.vin,year:n.year,make:n.make,model:n.model,customer_name:n.customer_name,status:n.status,tab:"dealer-counters",tabLabel:"Dealer Counter"}))});const S=d.reduce((s,n)=>{const w=`${n.id}-${n.tab}`;return s.find(I=>`${I.id}-${I.tab}`===w)||s.push(n),s},[]);_(S.slice(0,15)),D(S.length>0)}catch(k){console.error("Error searching cars:",k),_([])}finally{y(!1)}},300);return()=>clearTimeout(u)},[g]);const t=i=>{r(i),N(""),_([]),D(!1)},a=i=>{switch(i){case"live-auctions":return"bg-teal-100 text-teal-700 dark:bg-teal-900/30 dark:text-teal-400";case"ended-auctions":return"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400";case"dealer-counters":return"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400";default:return"bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"}};return e.jsxs("div",{ref:b,className:"relative",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Zs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Ze,{type:"text",placeholder:c?"Search...":"Search VIN, make, model, customer...",value:g,onChange:i=>N(i.target.value),onFocus:()=>f.length>0&&D(!0),className:Ge("pl-9 pr-8 h-9 bg-white dark:bg-slate-800 border-gray-300 dark:border-slate-700",c?"w-36":"w-72")}),g&&e.jsx("button",{onClick:()=>{N(""),_([]),D(!1)},className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:e.jsx($s,{className:"h-4 w-4"})})]}),p&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-lg shadow-lg z-50 max-h-80 overflow-y-auto",children:C?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(ie,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):f.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:"No results found"}):e.jsx("div",{className:"py-1",children:f.map(i=>e.jsxs("button",{onClick:()=>t(i),className:"w-full px-3 py-2.5 text-left hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 p-1.5 bg-gray-100 dark:bg-slate-800 rounded",children:e.jsx(de,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium text-sm text-foreground truncate",children:[i.year," ",i.make," ",i.model]}),e.jsx("span",{className:Ge("text-xs px-1.5 py-0.5 rounded font-medium flex-shrink-0",a(i.tab)),children:i.tabLabel})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:i.vin}),i.customer_name&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"•"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:i.customer_name})]})]})]})]},`${i.id}-${i.tab}`))})})]})},ir=()=>{const r=Ne(),c=ce(),[g,N]=l.useState("live-auctions"),[f,_]=l.useState(0),[C,y]=l.useState(0),[p,D]=l.useState(0),[b,t]=l.useState(0),[a,i]=l.useState(0),[u,k]=l.useState(null),[A,z]=l.useState("all"),[O,d]=l.useState("all"),[S,s]=l.useState("all"),[n,w]=l.useState([]),[$,I]=l.useState([]);l.useRef(null);const[K,Y]=l.useState(!1);l.useEffect(()=>{(async()=>{const{data:B}=await v.from("cars").select("assigned_rep_id").not("assigned_rep_id","is",null),F=[...new Set((B||[]).map(ee=>ee.assigned_rep_id))];if(F.length>0){const{data:ee}=await v.from("users").select("id, name, business_name").in("id",F);w((ee||[]).map(Q=>({id:Q.id,name:Q.name||Q.business_name||"Unknown"})).sort((Q,se)=>Q.name.localeCompare(se.name)))}const{data:W}=await v.from("cars").select("high_bidder_id").not("high_bidder_id","is",null).in("status",["ended","on_offer","dealer_counter","sold_waiting"]),J=[...new Set((W||[]).map(ee=>
25ee.high_bidder_id))];if(J.length>0){const{data:ee}=await v.from("dealership_users").select("user_id, dealerships:dealership_id(id, name)").in("user_id",J),Q=new Map;(ee||[]).forEach(V=>{const X=Array.isArray(V.dealerships)?V.dealerships[0]:V.dealerships;X!=null&&X.name&&Q.set(V.user_id,X.name)});const se=J.filter(V=>!Q.has(V));if(se.length>0){const{data:V}=await v.from("users").select("id, name, business_name").in("id",se);(V||[]).forEach(X=>{Q.set(X.id,X.business_name||X.name||"Unknown")})}const le=new Map;Q.forEach((V,X)=>{le.has(V)||le.set(V,X)}),I(Array.from(le.entries()).map(([V,X])=>({id:X,name:V})).sort((V,X)=>V.name.localeCompare(X.name)))}})()},[]);const{liveAuctions:q,endedAuctions:G,loading:Z,fetchAuctions:P}=Ts(),{dealerCounterCars:H,loading:m,fetchDealerCounterCars:o}=rt(),{isManageOfferOpen:R,setIsManageOfferOpen:T,isEditBidOpen:h,isCounterOfferOpen:M,isSendDirectOfferOpen:me,selectedCar:j,handleManageOffer:Ie,handleAcceptOffer:ts,handleCounterOffer:rs,handleEditBid:as,handleNoSale:ns,handleUpdateBidData:ds,handleCloseEditBid:is,handleSubmitCounterOffer:ls,handleCloseCounterOffer:os,handleSendDirectOffer:cs,handleCloseSendDirectOffer:ms,handleDirectOfferSuccess:xs}=Us(P),_e=ue.useCallback(async()=>{try{const[{count:x},{count:B},{count:F},{count:W}]=await Promise.all([v.from("cars").select("*",{count:"exact",head:!0}).eq("status","ended"),v.from("cars").select("*",{count:"exact",head:!0}).eq("status","on_offer"),v.from("trade_in_requests").select("*",{count:"exact",head:!0}).eq("status","pending"),v.from("direct_offers").select("*",{count:"exact",head:!0}).eq("status","pending").gt("expires_at",new Date().toISOString())]);_(x||0),y(B||0),D(F||0),t(W||0)}catch(x){console.error("Error fetching counts:",x)}},[]);ue.useEffect(()=>{_e()},[_e]);const Te=ue.useCallback(()=>{P(),o(!0),_e(),i(x=>x+1),window.dispatchEvent(new Event("global-data-refresh"))},[P,o,_e]),us=["live-auctions","ended-auctions","dealer-counters","trade-in-quotes","direct-offers"],hs=l.useMemo(()=>[{key:"r",action:()=>Te(),description:"Refresh data"},{key:"s",action:()=>{const x=document.querySelector("[data-offer-search]");x==null||x.focus()},description:"Focus search"},...us.map((x,B)=>({key:String(B+1),action:()=>N(x),description:`Switch to tab ${B+1}`}))],[Te]);Xs({shortcuts:hs});const je=l.useRef(null);ue.useEffect(()=>{const x=F=>{if((F==null?void 0:F.type)==="car-update"){const W=F==null?void 0:F.detail,J=W==null?void 0:W.status;if(J&&!["ended","on_offer","dealer_counter","sold_waiting"].includes(J))return}je.current&&clearTimeout(je.current),je.current=setTimeout(()=>{var W;P(),(W=F==null?void 0:F.type)!=null&&W.includes("bid-data")&&i(J=>J+1)},500)},B=["bid-data-updated","bid-data-force-updated","high-bidder-force-updated","dealer-changed-event","car-update","global-data-refresh"];return B.forEach(F=>{window.addEventListener(F,x)}),()=>{B.forEach(F=>{window.removeEventListener(F,x)}),je.current&&clearTimeout(je.current)}},[P]);const qe=()=>j?{id:j.id,year:j.year||0,make:j.make||"",model:j.model||"",vin:j.vin||"",mileage:j.mileage||0,color:j.color||"",condition:j.condition||"",description:j.description||"",images:j.images||[],features:j.features||[],options:j.options||[],startingBid:j.starting_bid||j.startingBid||0,currentBid:j.current_bid||j.currentBid||0,bidCount:j.bid_count||0,endTime:j.end_time||new Date().toISOString(),status:j.status||"ended",reservePrice:j.reserve_price||0,reserveMet:j.reserve_met||!1,fuelType:j.fuel_type||"gasoline",titleDetails:{present:j.title_present||!1,type:j.title_type||"",inSellerPossession:j.title_in_seller_possession||!1,ownedOutright:j.title_owned_outright||!1},keysCount:j.keys_count||1,highBidder:j.high_bidder_id?{id:j.high_bidder_id,name:j.high_bidder_name||"Unknown Bidder"}:void 0,seller:{id:j.seller_id||"",name:j.seller_name||"Unknown Seller"}}:null,Ue=x=>{const B=x.counter_offer||x.current_bid||0,F=x.market_value_low||0,W=x.market_value_high||0,J=x.reserve_price||0,ee=x.kbb_lending_value||0;let Q=25;W>0&&F>0&&(B>W?Q=100:B>=F&&B<=W?Q=50:Q=25);let se=25;if(J>0){const V=J-B;V<=500?se=100:V<=1e3?se=75:V>=2e3&&V<=3e3?se=50:V>3e3&&(se=25)}let le=25;if(ee>0){const V=ee-B;V<=999?le=100:V>=1e3&&V<=2e3?le=75:V>=3001&&V<=4500?le=50:V>4500&&(le=25)}return{offerVsRange:Math.round(Q),offerVsReserve:Math.round(se),reserveVsKbb:Math.round(le)}};return Z?e.jsx("div",{className:"min-h-screen bg-background dark:bg-black",children:e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ie,{className:"h-8 w-8 animate-spin text-primary mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading auctions..."})]})})}):e.jsxs("div",{className:`min-h-screen bg-background dark:bg-black ${c?"pb-24":""}`,children:[e.jsx("div",{className:"bg-background/90 dark:bg-black/90 backdrop-blur-xl border-b border-border sticky top-0 z-10",children:e.jsxs("div",{className:`${c?"px-3 py-3":"px-6 py-5"}`,children:[e.jsxs("div",{className:`flex items-center justify-between ${c?"mb-3":"mb-0"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[!c&&e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>r("/admin"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent",children:e.jsx(Js,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:`${c?"text-xl":"text-2xl"} font-bold text-foreground`,children:"Offer Room"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c?"Manage auction end processes":"View and manage all auction end processes"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!c&&n.length>0&&e.jsxs(te,{value:A,onValueChange:z,children:[e.jsxs(re,{className:"w-[180px] bg-card border-border text-foreground",children:[e.jsx(Ls,{className:"w-4 h-4 mr-2 text-muted-foreground"}),e.jsx(ae,{placeholder:"All Reps"})]}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Reps"}),e.jsx(L,{value:"unassigned",children:"Unassigned"}),n.map(x=>e.jsx(L,{value:x.id,children:x.name},x.id))]})]}),!c&&$.length>0&&e.jsxs(te,{value:O,onValueChange:d,children:[e.jsxs(re,{className:"w-[180px] bg-card border-border text-foreground",children:[e.jsx(de,{className:"w-4 h-4 mr-2 text-muted-foreground"}),e.jsx(ae,{placeholder:"All Dealers"})]}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Dealers"}),$.map(x=>e.jsx(L,{value:x.id,children:x.name},x.id))]})]}),!c&&e.jsxs(te,{value:S,onValueChange:s,children:[e.jsxs(re,{className:"w-[150px] bg-card border-border text-foreground",children:[e.jsx(Xe,{className:"w-4 h-4 mr-2 text-muted-foreground"}),e.jsx(ae,{placeholder:"All Deals"})]}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Deals"}),e.jsx(L,{value:"hot",children:"🔥 Hot"}),e.jsx(L,{value:"cold",children:"❄️ Cold"}),e.jsx(L,{value:"unmarked",children:"Unmarked"})]})]}),e.jsx(xt,{onSelectCar:x=>{N(x.tab),k(x.id),setTimeout(()=>{const B=document.getElementById(`car-row-${x.id}`);B&&(B.scrollIntoView({behavior:"smooth",block:"center"}),B.classList.add("ring-2","ring-primary","ring-offset-2"),setTimeout(()=>{B.classList.remove("ring-2","ring-primary","ring-offset-2"),k(null)},3e3))},100)},isMobile:c}),e.jsx(E,{onClick:Te,variant:"outline",size:"sm",className:"bg-card border-border text-foreground hover:bg-accent",disabled:Z,children:Z?e.jsx(ie,{className:"h-4 w-4 animate-spin"}):c?"Refresh":"Refresh All Data"}),!c&&e.jsxs(Os,{children:[e.jsx(Es,{asChild:!0,children:e.jsx("div",{className:"p-2 rounded-lg hover:bg-muted cursor-help transition-colors",children:e.jsx(Rs,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsxs(As,{side:"bottom",className:"text-xs max-w-[200px]",children:[e.jsx("p",{className:"font-semibold mb-1",children:"Keyboard Shortcuts"}),e.jsx("p",{children:"R — Refresh data"}),e.jsx("p",{children:"S — Focus search"}),e.jsx("p",{children:"1-5 — Switch tabs"})]})]})]})]}),c&&(n.length>0||$.length>0)&&e.jsxs("div",{className:"flex gap-2 overflow-x-auto pb-1",children:[n.length>0&&e.jsxs(te,{value:A,onValueChange:z,children:[e.jsx(re,{className:"h-8 text-xs min-w-[120px] bg-card border-border",children:e.jsx(ae,{placeholder:"All Reps"})}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Reps"}),e.jsx(L,{value:"unassigned",children:"Unassigned"}),n.map(x=>e.jsx(L,{value:x.id,children:x.name},x.id))]})]}),$.length>0&&e.jsxs(te,{value:O,onValueChange:d,children:[e.jsx(re,{className:"h-8 text-xs min-w-[120px] bg-card border-border",children:e.jsx(ae,{placeholder:"All Dealers"})}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Dealers"}),$.map(x=>e.jsx(L,{value:x.id,children:x.name},x.id))]})]}),e.jsxs(te,{value:S,onValueChange:s,children:[e.jsx(re,{className:"h-8 text-xs min-w-[110px] bg-card border-border",children:e.jsx(ae,{placeholder:"All Deals"})}),e.jsxs(ne,{children:[e.jsx(L,{value:"all",children:"All Deals"}),e.jsx(L,{value:"hot",children:"🔥 Hot"}),e.jsx(L,{value:"cold",children:"❄️ Cold"}),e.jsx(L,{value:"unmarked",children:"Unmarked"})]})]})]})]})}),e.jsxs("div",{className:`${c?"px-0 py-0":"p-6"} space-y-4`,children:[!c&&e.jsx(Ws,{}),e.jsx("div",{className:`grid ${c?"grid-cols-3 gap-2":"grid-cols-2 lg:grid-cols-5 ga
25p-4"} group`,children:[{tab:"live-auctions",icon:et,color:"teal",label:"Auction Ended",count:f},{tab:"ended-auctions",icon:Ye,color:"emerald",label:"Customer",count:C},{tab:"dealer-counters",icon:Re,color:"blue",label:"Dealer",count:(H==null?void 0:H.length)||0},{tab:"trade-in-quotes",icon:de,color:"violet",label:"Trade-In",count:p},{tab:"direct-offers",icon:Ae,color:"orange",label:"Direct Offers",count:b}].map(x=>{const B=x.icon,F=g===x.tab;return e.jsxs("div",{className:`bg-card dark:bg-gradient-to-br dark:from-slate-800 dark:to-slate-900 rounded-xl border ${F?`border-${x.color}-500/50`:"border-border dark:border-slate-700/50"} ${c?"p-3":"p-5"} shadow-sm cursor-pointer active:scale-[0.98] transition-all`,onClick:()=>N(x.tab),children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("div",{className:`${c?"p-1.5":"p-2.5"} bg-${x.color}-500/10 rounded-lg`,children:e.jsx(B,{className:`${c?"h-4 w-4":"h-5 w-5"} text-${x.color}-500 dark:text-${x.color}-400`})})}),e.jsxs("div",{children:[e.jsx("div",{className:`${c?"text-2xl":"text-4xl"} font-bold text-foreground mb-0.5`,children:x.count}),e.jsx("div",{className:`${c?"text-[10px]":"text-sm"} text-muted-foreground`,children:x.label})]})]},x.tab)})}),e.jsxs(Ms,{value:g,onValueChange:N,className:c?"space-y-0":"space-y-4",children:[e.jsx("div",{className:"bg-card dark:bg-slate-900/50 backdrop-blur-sm rounded-xl border border-border p-1.5 shadow-sm overflow-x-auto",children:e.jsx(Vs,{className:`grid w-full ${c?"grid-cols-6 min-w-[600px]":"grid-cols-6 min-w-[720px]"} bg-transparent gap-1 h-auto`,children:[{value:"live-auctions",label:"Auction Ended",count:f,activeClass:"data-[state=active]:bg-teal-500 data-[state=active]:text-teal-50"},{value:"ended-auctions",label:"Customer",count:C,activeClass:"data-[state=active]:bg-emerald-500 data-[state=active]:text-emerald-50"},{value:"dealer-counters",label:"Dealer",count:(H==null?void 0:H.length)||0,activeClass:"data-[state=active]:bg-blue-500 data-[state=active]:text-blue-50"},{value:"trade-in-quotes",label:"Trade-In",count:p,activeClass:"data-[state=active]:bg-violet-500 data-[state=active]:text-violet-50"},{value:"direct-offers",label:"Direct Offers",count:b,activeClass:"data-[state=active]:bg-orange-500 data-[state=active]:text-orange-50"},{value:"offer-requests",label:"Offer Requests",count:null,activeClass:"data-[state=active]:bg-amber-500 data-[state=active]:text-amber-50"}].map(x=>e.jsxs(Is,{value:x.value,className:`flex flex-col items-center gap-1 py-2.5 px-1.5 ${x.activeClass} data-[state=inactive]:text-muted-foreground data-[state=inactive]:hover:text-foreground data-[state=inactive]:hover:bg-accent rounded-lg text-center transition-all`,children:[e.jsx("span",{className:"text-[11px] font-semibold leading-tight",children:x.label}),x.count!==null&&e.jsx(oe,{className:"text-[10px] px-1.5 py-0 bg-muted text-muted-foreground border-0",children:x.count})]},x.value))})}),e.jsx(xe,{value:"live-auctions",className:`${c?"mt-2 p-0 bg-transparent rounded-none":"space-y-4 mt-4"}`,children:e.jsx(at,{onDataRefresh:P,onManageOffer:Ie,calculateRevMeterValues:Ue,highlightCarId:u,filterRepId:A,filterDealerId:O,filterTemperature:S},`ended-${a}`)}),e.jsx(xe,{value:"ended-auctions",className:`${c?"mt-2 p-0 bg-transparent rounded-none":"space-y-4 mt-4"}`,children:e.jsx(nt,{onManageOffer:Ie,calculateRevMeterValues:Ue,highlightCarId:u,filterRepId:A,filterDealerId:O,filterTemperature:S},`customer-${a}`)}
25),e.jsx(xe,{value:"dealer-counters",className:`${c?"mt-2 p-0 bg-transparent rounded-none":"space-y-4 mt-4"}`,children:e.jsx(dt,{dealerCounterCars:H||[],loading:m,onManageOffer:Ie,calculateRevMeterValues:Ue,highlightCarId:u,filterRepId:A,filterDealerId:O,filterTemperature:S},`dealer-${a}`)}),e.jsx(xe,{value:"trade-in-quotes",className:`${c?"mt-2 p-0 bg-transparent rounded-none":"space-y-4 mt-4"}`,children:e.jsx(ot,{})}),e.jsx(xe,{value:"direct-offers",className:`${c?"mt-2 p-0 bg-transparent rounded-none":"space-y-4 mt-4"}`,children:e.jsx(ct,{})}),e.jsx(xe,{value:"offer-requests",className:`${c?"mt-2 p-0 bg-transparent rounded-none":"space-y-4 mt-4"}`,children:e.jsx(mt,{})})]})]}),e.jsx(it,{open:R,onOpenChange:T,selectedCar:j,onAcceptOffer:ts,onCounterOffer:rs,onEditBid:as,onNoSale:()=>{T(!1),Y(!0)},onSendDirectOffer:cs}),e.jsx(lt,{open:me,onOpenChange:ms,selectedCar:j,onSuccess:xs}),e.jsx(Ys,{open:K,onOpenChange:Y,onConfirm:x=>{ns(x),Y(!1)},vehicleLabel:j?`${j.year} ${j.make} ${j.model}`:void 0}),e.jsx(Hs,{car:qe(),isOpen:h,onClose:is,onUpdateBidData:ds}),M&&j&&e.jsx(Gs,{car:qe(),currentOffer:j.current_bid||j.currentBid||0,isOpen:M,onClose:os,onSubmit:ls,isAdmin:!0,highBidder:j.high_bidder_name||"Unknown Dealer"})]})};export{ir 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.