PageSourceSearch

https://stone-profit-flow.base44.app/assets/Leads-D3F60ssC.js

js stone-profit-flow.base44.app collected 2026-10-03 03:10:36 UTC 102,990 bytes, 35 lines download raw bytes

1import{a as j,d as ce,j as e,u as Ge,e as ve}from"./vendor-query-B-_nDQQY.js";import{y as We,q as X,h as Y,i as J,j as Z,k as ee,l as b,I as V,b as z,C as U,a as te,c as ie,p as he,d as O,M as oe,B as D,e as B,Z as Te,s as de,L as ge,t as T,F as ae,D as re,X as rs,x as je,n as $e,R as qe,r as fe,aI as ns,$ as is,a0 as cs,a2 as ds,a3 as Se,f as Xe,v as os,U as He,Q as ms}from"./index-D8ww6b7J.js";import{T as us,a as xs,b as Qe}from"./tabs-DfRYzyJY.js";import{D as Ye,a as Je,b as Ze,c as es,e as hs}from"./dialog-BQWtAG_x.js";import{V as ps}from"./ViewQuoteDialog-Rwxu8CnQ.js";import{L as ss}from"./layers-De-P0_bF.js";import{T as Fe}from"./trash-2-LBknmkIl.js";import{W as gs}from"./wrench-vruAejjf.js";import{C as Ae}from"./camera-B5zm8J-v.js";import{U as be}from"./user-CHo1Apvy.js";import{P as ye}from"./phone-CA5yr35z.js";import{A as Pe}from"./arrow-right-BeikyhzV.js";import{U as pe}from"./upload-DN-6vN7H.js";import{R as Ve}from"./refresh-cw-B9y4TrLK.js";import{C as we}from"./circle-check-BXjz6L8_.js";import{R as Re}from"./ruler-Bcj6zKuq.js";import{C as Ue}from"./circle-x-CIIBFH3_.js";import{DragDropContext as js,Droppable as fs,Draggable as Ns}from"./vendor-dnd-D8GD0lRu.js";import{m as G}from"./vendor-framer-DvY-ewtn.js";import{T as Le}from"./target-sa9DKzQo.js";import vs from"./AutoFollowUp-CBJjrEPv.js";import{I as ts}from"./inbox-Du39YS_i.js";import{C as Ne}from"./circle-check-big-4Ew-rpqG.js";import{A as bs}from"./arrow-up-right-DBBxPKcd.js";import{A as ys}from"./arrow-down-right-B2vfQYTC.js";import{A as ws}from"./award-C2Pk5WYF.js";import{L as _s}from"./layout-grid-DZ51q6Z2.js";import{F as Cs}from"./funnel-Dec4yW_G.js";import{E as as}from"./eye-DQ9YWbv-.js";import{b as Me}from"./vendor-react-BUIlT3ms.js";import{P as ks}from"./PageHeader-DOQecRZi.js";import{p as Ss}from"./quoteNotes-BK67QilA.js";import{P as ze}from"./plus-MQo5wr8n.js";import{P as Ds}from"./package-kgQR05VR.js";import{P as Ts}from"./pencil-iBu5MVPj.js";import{L as ls}from"./link-2-BDggyP-Z.js";import{C as $s}from"./copy-CeElQ86j.js";import{S as Be}from"./send-DJBvsBZ5.js";import"./vendor-three-1K-S22da.js";import"./vendor-charts-i-522T5A.js";import"./vendor-pdf-Bwkk3Ew0.js";import"./vendor-radix-X0WMATEu.js";import"./RevisionsPanel-B3uhU7fe.js";import"./textarea-Bhj0eADY.js";import"./format-C2V2JF1Z.js";import"./constants-yGZMfuMC.js";import"./differenceInMinutes-DsMRFadK.js";import"./differenceInMilliseconds-C_4QHjWc.js";import"./image-W2HJP6c8.js";import"./square-pen-C05cPBRr.js";/**
2 * @license lucide-react v1.21.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 qs=[["path",{d:"M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z",key:"c7niix"}]],Fs=We("droplet",qs);/**
7 * @license lucide-react v1.21.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Ls=[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]],Ps=We("table",Ls);function Ms({sqft:a=0,suggestedMaterial:n="",onChange:i}){const[o,d]=j.useState(""),[u,m]=j.useState([]),[N,x]=j.useState([]),{data:k=[]}=ce({queryKey:["photo-quote-materials"],queryFn:async()=>await z.entities.MaterialPriceList.filter({is_active:!0})||[]}),{data:r=[]}=ce({queryKey:["photo-quote-services"],queryFn:async()=>await z.entities.ServicePriceList.filter({is_active:!0})||[]}),{data:v=[]}=ce({queryKey:["photo-quote-sinks"],queryFn:async()=>await z.entities.ProductPriceList.filter({is_active:!0,product_type:"sink"})||[]}),P=j.useMemo(()=>r.filter(t=>t.service_type==="cutout"),[r]),M=j.useMemo(()=>r.filter(t=>t.service_type!=="cutout"),[r]);j.useEffect(()=>{if(!o&&k.length>0){const t=n?k.find(g=>g.material_type===n):null;d((t||k[0]).id)}},[k,n,o]);const A=k.find(t=>t.id===o),I=j.useMemo(()=>{const t=A?(A.selling_price_per_sqft||0)*(a||0):0,g=N.reduce((R,l)=>{const w=r.find(q=>q.id===l.id);if(!w)return R;const y=w.selling_price||0,$=l.qty||0;return R+y*$},0),S=u.reduce((R,l)=>{const w=v.find(y=>y.id===l.id);return w?R+(w.selling_price||0)*(l.qty||0):R},0),H=t+g+S;return{materialPrice:t,servicesTotal:g,sinksTotal:S,grandTotal:H}},[A,N,u,v,r,a]);j.useEffect(()=>{i&&i({material:A,sinks:u.map(t=>({...v.find(g=>g.id===t.id),qty:t.qty})),services:N.map(t=>({...r.find(g=>g.id===t.id),qty:t.qty})),totals:I})},[A,u,N,v,I,r,i]);const f=t=>{!t||N.some(g=>g.id===t)||x([...N,{id:t,qty:1}])},c=(t,g)=>{x(N.map(S=>S.id===t?{...S,qty:Math.max(0,g)}:S))},p=t=>{x(N.filter(g=>g.id!==t))},E=t=>{!t||u.some(g=>g.id===t)||m([...u,{id:t,qty:1}])},Q=(t,g)=>{m(u.map(S=>S.id===t?{...S,qty:Math.max(0,g)}:S))},h=t=>{m(u.filter(g=>g.id!==t))};return e.jsxs("div",{className:"space-y-4 p-4 bg-background rounded-lg border",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(X,{className:"text-xs font-semibold flex items-center gap-1.5",children:[e.jsx(ss,{className:"w-3.5 h-3.5"})," Material"]}),e.jsxs(Y,{value:o,onValueChange:d,children:[e.jsx(J,{className:"h-9 text-sm",children:e.jsx(Z,{placeholder:"Select material"})}),e.jsx(ee,{className:"max-h-60",children:k.map(t=>e.jsxs(b,{value:t.id,children:[t.material_name," — ",t.material_type]},t.id))})]}),A&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[A.supplier," · ",A.thickness||"standard"," · ",a==null?void 0:a.toFixed(1)," sqft"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(X,{className:"text-xs font-semibold flex items-center gap-1.5",children:[e.jsx(Fs,{className:"w-3.5 h-3.5"})," Sinks"]}),v.length>0?e.jsxs(e.Fragment,{children:[e.jsxs(Y,{onValueChange:E,children:[e.jsx(J,{className:"h-9 text-sm",children:e.jsx(Z,{placeholder:"+ Add sink"})}),e.jsx(ee,{className:"max-h-60",children:v.map(t=>e.jsxs(b,{value:t.id,children:[t.product_name," — ",t.brand||t.material||""," ($",t.selling_price,")"]},t.id))})]}),u.length>0?e.jsx("div",{className:"space-y-1.5",children:u.map(t=>{const g=v.find(S=>S.id===t.id);return g?e.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-md p-1.5",children:[e.jsx("span",{className:"text-xs flex-1 truncate",children:g.product_name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["$",g.selling_price]}),e.jsx(V,{type:"number",min:"1",value:t.qty,onChange:S=>Q(t.id,parseInt(S.target.value)||0),className:"w-14 h-7 text-xs"}),e.jsxs("span",{className:"text-xs font-medium w-14 text-right",children:["$",(g.selling_price*t.qty).toFixed(0)]}),e.jsx("button",{onClick:()=>h(t.id),className:"text-muted-foreground hover:text-destructive",children:e.jsx(Fe,{className:"w-3.5 h-3.5"})})]},t.id):null})}):e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"No sinks added yet."})]}):e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"No sink products available."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(X,{className:"text-xs font-semibold flex items-center gap-1.5",children:[e.jsx(gs,{className:"w-3.5 h-3.5"})," Cutouts & Services"]}),P.length>0&&e.jsxs(Y,{onValueChange:f,children:[e.jsx(J,{className:"h-9 text-sm",children:e.jsx(Z,{placeholder:"+ Add cutout (sink, cooktop, etc.)"})}),e.jsx(ee,{className:"max-h-60",children:P.map(t=>
11e.jsxs(b,{value:t.id,children:[t.service_name," ($",t.selling_price,")"]},t.id))})]}),M.length>0&&e.jsxs(Y,{onValueChange:f,children:[e.jsx(J,{className:"h-9 text-sm",children:e.jsx(Z,{placeholder:"+ Add service (edge, install, etc.)"})}),e.jsx(ee,{className:"max-h-60",children:M.map(t=>e.jsxs(b,{value:t.id,children:[t.service_name," ($",t.selling_price,")"]},t.id))})]}),N.length>0?e.jsx("div",{className:"space-y-1.5",children:N.map(t=>{const g=r.find(S=>S.id===t.id);return g?e.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-md p-1.5",children:[e.jsx("span",{className:"text-xs flex-1 truncate",children:g.service_name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["$",g.selling_price]}),e.jsx(V,{type:"number",min:"1",value:t.qty,onChange:S=>c(t.id,parseInt(S.target.value)||0),className:"w-14 h-7 text-xs"}),e.jsxs("span",{className:"text-xs font-medium w-14 text-right",children:["$",(g.selling_price*t.qty).toFixed(0)]}),e.jsx("button",{onClick:()=>p(t.id),className:"text-muted-foreground hover:text-destructive",children:e.jsx(Fe,{className:"w-3.5 h-3.5"})})]},t.id):null})}):e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"No cutouts or services added yet."})]}),e.jsxs("div",{className:"pt-2 border-t space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Material (",a==null?void 0:a.toFixed(1)," sqft)"]}),e.jsxs("span",{className:"font-medium",children:["$",I.materialPrice.toFixed(0)]})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Sinks"}),e.jsxs("span",{className:"font-medium",children:["$",I.sinksTotal.toFixed(0)]})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Services & Cutouts"}),e.jsxs("span",{className:"font-medium",children:["$",I.servicesTotal.toFixed(0)]})]}),e.jsxs("div",{className:"flex justify-between text-sm font-bold pt-1 border-t",children:[e.jsx("span",{children:"Estimated Total"}),e.jsxs("span",{className:"text-primary",children:["$",I.grandTotal.toFixed(0)]})]})]})]})}function Qs({onConvertToLead:a}){var E,Q,h,t,g,S,H,R,l,w,y,$,q;const n=j.useRef(null),[i,o]=j.useState("info"),[d,u]=j.useState({customer_name:"",customer_phone:"",customer_email:""}),[m,N]=j.useState(null),[x,k]=j.useState(null),[r,v]=j.useState(null),[P,M]=j.useState(null),A=()=>{if(!d.customer_name.trim()){T.error("Name is required");return}if(!d.customer_phone.trim()){T.error("Phone number is required");return}o("photo")},I=async _=>{var C;const K=(C=_.target.files)==null?void 0:C[0];if(K){v(null);try{const F=await z.integrations.Core.UploadFile({file:K});N(F.file_url)}catch{v("Failed to upload photo. Please try again.")}}},f=async()=>{var _,K,C;if(!m){T.error("Please upload a photo first");return}o("analyzing"),v(null);try{const F=await z.integrations.Core.InvokeLLM({prompt:`You are a professional stone countertop estimator. Analyze this photo of a countertop (or countertop space/area) and provide precise measurements and pricing.
12
13Follow these rules:
141. Look for visual cues of scale — standard countertops are typically 25.5" deep, sinks are 22" x 30", stoves are 30" wide, and standard base cabinets are 24" deep. Use these as reference points.
152. If there's a person or object visible, use it for scale reference.
163. Count sink cutouts, cooktop cutouts, and any other visible features.
174. Identify the material if visible (granite, quartz, marble, etc).
185. Detect the shape: rectangular, L-shape, U-shape, or other.
196. Calculate estimated sqft based on your measurements.
207. Price range based on material: granite $45-85/sqft, quartz $55-100/sqft, marble $65-130/sqft, quartzite $70-120/sqft. Use a mid-range price for the material detected.
218. Confidence should be "high" if clear photo with good reference points, "medium" if somewhat clear, "low" if blurry or lacks scale reference.
229. ALWAYS include suggested_material_type from: granite, quartz, marble, quartzite, soapstone, laminate, butcher_block, or other.
23
24If the photo is clearly NOT a countertop or kitchen area, set confidence to "low" and note it in additional_notes.`,response_json_schema:{type:"object",properties:{estimated_width_inches:{type:"number",description:"Estimated width/depth of countertop in inches"},estimated_length_inches:{type:"number",description:"Estimated total length in inches"},shape:{type:"string",enum:["rectangular","l_shape","u_shape","other"]},suggested_material_type:{type:"string",description:"Material if identifiable: granite, quartz, marble, quartzite, soapstone, laminate, butcher_block, other"},cutouts:{type:"array",items:{type:"object",properties:{type:{type:"string",enum:["sink","cooktop","faucet","other"]},description:{type:"string"}}}},estimated_sqft:{type:"number"},confidence:{type:"string",enum:["high","medium","low"]},suggested_price_range:{type:"object",properties:{low:{type:"number"},mid:{type:"number"},high:{type:"number"}}},additional_notes:{type:"string",description:"Any useful observations for the estimator"}}},file_urls:[m],model:"gemini_3_flash"});k(F);const se={customer_name:d.customer_name,customer_email:d.customer_email,customer_phone:d.customer_phone,source:"photo_ai",status:"new",project_type:"kitchen",estimated_sqft:F.estimated_sqft||0,estimated_value:((_=F.suggested_price_range)==null?void 0:_.mid)||0,notes:`AI Photo Analysis: ${F.shape||""} countertop, ${((K=F.estimated_sqft)==null?void 0:K.toFixed(1))||0} sqft, ${((C=F.cutouts)==null?void 0:C.length)||0} cutouts. Confidence: ${F.confidence}. ${F.additional_notes||""}`,follow_up_date:new Date(Date.now()+1440*60*1e3).toISOString().split("T")[0]};a&&a(se),o("result")}catch{v("AI analysis failed. Try a clearer photo or try again."),o("photo")}},c=()=>{o("info"),N(null),k(null),v(null),M(null),u({customer_name:"",customer_phone:"",customer_email:""}),n.current&&(n.current.value="")},p={high:{color:"bg-green-100 text-green-800",icon:we,label:"High Confidence"},medium:{color:"bg-yellow-100 text-yellow-800",icon:de,label:"Medium Confidence"},low:{color:"bg-red-100 text-red-800",icon:de,label:"Low Confidence"}};return e.jsxs(U,{className:"border-2 border-dashed border-primary/30 bg-primary/5",children:[e.jsxs(te,{children:[e.jsxs(ie,{className:"flex items-center gap-2 text-lg",children:[e.jsx(Ae,{className:"w-5 h-5 text-primary"}),"AI Photo-to-Quote"]}),e.jsx(he,{children:"Enter your details, snap a photo of your countertop, and get an instant price estimate."})]}),e.jsxs(O,{className:"space-y-4",children:[i==="info"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-center pb-2",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-2xl bg-primary/10 flex items-center justify-center mb-2",children:e.jsx(be,{className:"w-8 h-8 text-primary"})}),e.jsx("p",{className:"font-semibold",children:"Let's get started"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Enter your name and phone number so we can follow up with your estimate."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(be,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{placeholder:"Your name *",value:d.customer_name,onChange:_=>u({...d,customer_name:_.target.value}),className:"pl-9 h-10"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(ye,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{placeholder:"Phone number *",type:"tel",value:d.customer_phone,onChange:_=>u({...d,customer_phone:_.target.value}),className:"pl-9 h-10"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(oe,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{placeholder:"Email (optional)",type:"email",value:d.customer_email,onChange:_=>u({...d,customer_email:_.target.value}),className:"pl-9 h-10"})]})]}),e.jsxs(D,{className:"w-full",onClick:A,children:["Continue ",e.jsx(Pe,{className:"w-4 h-4 ml-1"})]})]}),i==="photo"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsxs(B,{variant:"secondary",className:"gap-1",children:[e.jsx(be,{className:"w-3 h-3"})," ",d.customer_name]}),e.jsxs(B,{variant:"outline",className:"gap-1",children:[e.jsx(ye,{className:"w-3 h-3"})," ",d.customer_phone]})]}),m?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:m,alt:"Countertop",className:"w-full max-h-64 object-cover rounded-lg shadow"}),e.jsxs(D,{variant:"secondary",size:"sm",className:"absolute top-2 right-2 gap-1",onClick:()=>{N(null),n.current&&(n.current.value="")},children:[e.jsx(Ve,{className:"w-3.5 h-3.5"})," Retake"]})]}),e.jsxs(D,{className:"w-full",size:"lg",onClick:f,children:[e.jsx(Te,{className:"w-4 h-4 mr-1"})," Get Price"]})]}):e.jsxs("div",{className:"text-center py-6 space-y-4",children:[e.jsx("div",{className:"w-20 h-20 mx-auto rounded-2xl bg-primary/10 flex items-center justify-center",children:e.jsx(Ae,{className:"w-10 h-10 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:"Take a photo of your countertop"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Upload a photo of any countertop — existing or empty space — and our AI will estimate dimensions, detect cutouts, and give you a price."})]}),e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[e.jsxs(D,{onClick:()=>{var _;return(_=n.current)==null?void 0:_.click()},className:"gap-2",children:[e.jsx(pe,{className:"w-4 h-4"}),"Upload Photo"]}),e.jsxs(D,{variant:"outline",onClick:()=>{var _;return(_=n.current)==null?void 0:_.click()},className:"gap-2",children:[e.jsx(Ae,{className:"w-4 h-4"}),"Take Photo"]})]}),e.jsx("input",{ref:n,type:"file",accept:"image/*",capture:"environment",onChange:I,className:"hidden"})]}),r&&e.jsxs("div",{className:"text-center py-4 space-y-2",children:[e.jsx(de,{className:"w-8 h-8 text-red-600 mx-auto"}),e.jsx("p",{className:"text-red-600 font-medium text-sm",children:r})]})]}),i==="analyzing"&&e.jsxs("div",{className:"text-center py-10 space-y-4",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(ge,{className:"w-8 h-8 text-primary animate-spin"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:"Analyzing your photo..."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Detecting dimensions, cutouts, and material type"})]}),m&&e.jsx("img",{src:m,alt:"Analyzing",className:"max-h-48 mx-auto rounded-lg shadow"})]}),i==="result"&&x&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-green-50 rounded-lg border border-green-200",children:[e.jsx(we,{className:"w-5 h-5 text-green-600 shrink-0"}),e.jsx("p",{className:"text-sm text-green-800 font-medium",children:"Your estimate is ready! We've saved your details and will follow up soon."})]}),e.jsxs("div",{className:"flex items-start gap-4",children:[m&&e.jsx("img",{src:m,alt:"Countertop",className:"w-24 h-24 object-cover rounded-lg shadow shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(B,{className:(E=p[x.confidence])==null?void 0:E.
24color,children:((Q=p[x.confidence])==null?void 0:Q.label)||x.confidence}),x.shape&&e.jsx(B,{variant:"outline",className:"capitalize",children:x.shape.replace("_"," ")})]}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",(h=P==null?void 0:P.totals)!=null&&h.grandTotal?P.totals.grandTotal.toLocaleString(void 0,{maximumFractionDigits:0}):((g=(t=x.suggested_price_range)==null?void 0:t.mid)==null?void 0:g.toLocaleString())||0]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(S=P==null?void 0:P.totals)!=null&&S.grandTotal?"updated estimate":`est. price · $${(R=(H=x.suggested_price_range)==null?void 0:H.low)==null?void 0:R.toLocaleString()} – $${(w=(l=x.suggested_price_range)==null?void 0:l.high)==null?void 0:w.toLocaleString()} range`})]}),e.jsx(D,{variant:"ghost",size:"icon",onClick:c,className:"shrink-0",children:e.jsx(Ve,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"p-3 bg-background rounded-lg border text-center",children:[e.jsx(Re,{className:"w-4 h-4 text-primary mx-auto mb-1"}),e.jsxs("p",{className:"text-lg font-bold",children:[x.estimated_width_inches,'" × ',x.estimated_length_inches,'"']}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Est. Dimensions"})]}),e.jsxs("div",{className:"p-3 bg-background rounded-lg border text-center",children:[e.jsx(Te,{className:"w-4 h-4 text-amber-500 mx-auto mb-1"}),e.jsxs("p",{className:"text-lg font-bold",children:[(y=x.estimated_sqft)==null?void 0:y.toFixed(1)," sqft"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Est. Sq Ft"})]}),e.jsxs("div",{className:"p-3 bg-background rounded-lg border text-center",children:[e.jsx("span",{className:"text-lg block mb-1",children:"🔲"}),e.jsx("p",{className:"text-lg font-bold",children:(($=x.cutouts)==null?void 0:$.length)||0}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Cutouts Detected"})]}),e.jsxs("div",{className:"p-3 bg-background rounded-lg border text-center",children:[e.jsx("span",{className:"text-lg block mb-1",children:"🪨"}),e.jsx("p",{className:"text-sm font-bold capitalize",children:x.suggested_material_type||"unknown"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Material"})]})]}),((q=x.cutouts)==null?void 0:q.length)>0&&e.jsxs("div",{className:"p-3 bg-background rounded-lg border",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground mb-2",children:"Cutouts Detected"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:x.cutouts.map((_,K)=>e.jsxs(B,{variant:"secondary",className:"capitalize",children:[_.type==="sink"?"🚰":_.type==="cooktop"?"🔥":_.type==="faucet"?"💧":"📐"," ",_.type,_.description?` – ${_.description}`:""]},K))})]}),x.additional_notes&&e.jsxs("p",{className:"text-xs text-muted-foreground italic",children:["💡 ",x.additional_notes]}),e.jsx(Ms,{sqft:x.estimated_sqft||0,suggestedMaterial:x.suggested_material_type,onChange:M})]})]})]})}const As=[{value:"granite",label:"Granite",rates:"$45–85/sqft"},{value:"quartz",label:"Quartz",rates:"$55–100/sqft"},{value:"marble",label:"Marble",rates:"$65–130/sqft"},{value:"quartzite",label:"Quartzite",rates:"$70–120/sqft"},{value:"soapstone",label:"Soapstone",rates:"$60–100/sqft"},{value:"laminate",label:"Laminate",rates:"$25–55/sqft"},{value:"butcher_block",label:"Butcher Block",rates:"$35–75/sqft"},{value:"other",label:"Other",rates:"$45–90/sqft"}];function Es({onQuoteCreated:a}){var H,R;const n=j.useRef(null),[i,o]=j.useState(null),[d,u]=j.useState(!1),[m,N]=j.useState(null),[x,k]=j.useState(null),[r,v]=j.useState(""),[P,M]=j.useState(""),[A,I]=j.useState(""),[f,c]=j.useState("quartz"),[p,E]=j.useState("kitchen"),[Q,h]=j.useState("upload"),t=l=>{var y;const w=(y=l.target.files)==null?void 0:y[0];if(w){if(!w.name.toLowerCase().endsWith(".dxf")){T.error("Please select a .dxf file");return}o(w),k(null),N(null),h("customer")}},g=async()=>{var l,w,y;if(!r.trim()){T.error("Customer name is required");return}if(i){u(!0),k(null);try{const $=await i.text();if($.includes("\0")&&!$.startsWith(`0
25`)){k("Binary DXF not supported. Please use ASCII DXF."),u(!1);return}const q=await z.functions.invoke("dxfToQuotePipeline",{dxfContent:$,customerName:r.trim(),customerEmail:P.trim(),customerPhone:A.trim(),materialType:f,projectType:p});(l=q==null?void 0:q.data)!=null&&l.success?(N(q.data),h("done"),T.success(`Quote created: ${q.data.summary.totalSqft} sqft, ${q.data.summary.piecesFound} pieces`),a&&a(q.data.quote)):(k(((w=q==null?void 0:q.data)==null?void 0:w.error)||"Pipeline failed"),T.error(((y=q==null?void 0:q.data)==null?void 0:y.error)||"Failed to create quote"))}catch{k("Failed to process DXF. Make sure it's a valid countertop DXF file.")}u(!1)}},S=()=>{o(null),N(null),k(null),v(""),M(""),I(""),h("upload"),n.current&&(n.current.value="")};return e.jsxs(U,{children:[e.jsxs(te,{children:[e.jsxs(ie,{className:"flex items-center gap-2 text-base",children:[e.jsx(ae,{className:"w-5 h-5 text-primary"}),"DXF → Quote Pipeline"]}),e.jsx(he,{children:"Drop a DXF file. Get an instant quote with sqft, edges, cutouts, and pricing — ready to send."})]}),e.jsxs(O,{className:"space-y-4",children:[Q==="upload"&&e.jsxs("div",{className:"text-center py-8 border-2 border-dashed border-muted-foreground
25/25 rounded-lg",children:[e.jsx(pe,{className:"w-12 h-12 text-muted-foreground mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"font-medium mb-1",children:"Drop your DXF here"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"From LT-2D3D, Proliner, Flexijet, or any CAD"}),e.jsxs(D,{onClick:()=>{var l;return(l=n.current)==null?void 0:l.click()},children:[e.jsx(pe,{className:"w-4 h-4 mr-1"})," Select DXF File"]}),e.jsx("input",{ref:n,type:"file",accept:".dxf,.DXF",onChange:t,className:"hidden"})]}),Q==="customer"&&i&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:i.name}),e.jsxs(B,{variant:"outline",className:"text-[10px]",children:[(i.size/1024).toFixed(1)," KB"]})]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:S,children:"Change"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Customer Name *"}),e.jsx(V,{value:r,onChange:l=>v(l.target.value),placeholder:"John Smith",className:"h-9"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Email"}),e.jsx(V,{type:"email",value:P,onChange:l=>M(l.target.value),placeholder:"[email protected]",className:"h-9"})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Phone"}),e.jsx(V,{value:A,onChange:l=>I(l.target.value),placeholder:"(555) 123-4567",className:"h-9"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Material"}),e.jsxs(Y,{value:f,onValueChange:c,children:[e.jsx(J,{className:"h-9",children:e.jsx(Z,{})}),e.jsx(ee,{children:As.map(l=>e.jsxs(b,{value:l.value,children:[l.label," ",e.jsx("span",{className:"text-muted-foreground text-[10px] ml-1",children:l.rates})]},l.value))})]})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Project"}),e.jsxs(Y,{value:p,onValueChange:E,children:[e.jsx(J,{className:"h-9",children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(b,{value:"kitchen",children:"Kitchen"}),e.jsx(b,{value:"bathroom",children:"Bathroom"}),e.jsx(b,{value:"commercial",children:"Commercial"}),e.jsx(b,{value:"outdoor",children:"Outdoor"}),e.jsx(b,{value:"other",children:"Other"})]})]})]})]})]}),e.jsx(D,{onClick:g,disabled:d||!r.trim(),className:"w-full",children:d?e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"w-4 h-4 animate-spin mr-1"})," Processing DXF..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"w-4 h-4 mr-1"})," Generate Quote from DXF"]})})]}),x&&e.jsxs("div",{className:"p-3 bg-red-50 rounded-lg text-sm text-red-600 flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4 shrink-0"}),x,e.jsx(D,{variant:"ghost",size:"sm",className:"ml-auto text-red-600",onClick:S,children:"Retry"})]}),Q==="done"&&m&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-600",children:[e.jsx(we,{className:"w-5 h-5"}),e.jsx("span",{className:"font-semibold",children:"Quote Generated"}),e.jsx(B,{variant:"default",className:"ml-auto",children:(H=m.quote)==null?void 0:H.quote_number})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"p-2 bg-muted/50 rounded-lg text-center",children:[e.jsx(Re,{className:"w-4 h-4 text-primary mx-auto mb-1"}),e.jsxs("p",{className:"font-bold text-sm",children:[m.summary.totalSqft," sqft"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Total Area"})]}),e.jsxs("div",{className:"p-2 bg-muted/50 rounded-lg text-center",children:[e.jsx(ae,{className:"w-4 h-4 text-primary mx-auto mb-1"}),e.jsx("p",{className:"font-bold text-sm",children:m.summary.piecesFound}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Pieces Found"})]}),e.jsxs("div",{className:"p-2 bg-muted/50 rounded-lg text-center",children:[e.jsx(re,{className:"w-4 h-4 text-green-600 mx-auto mb-1"}),e.jsxs("p",{className:"font-bold text-sm",children:["$",(R=m.summary.sellingPrice)==null?void 0:R.toLocaleStr
25ing()]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Selling Price"})]}),e.jsxs("div",{className:"p-2 bg-muted/50 rounded-lg text-center",children:[e.jsx("span",{className:"text-sm",children:"🔲"}),e.jsx("p",{className:"font-bold text-sm",children:m.summary.cutoutsDetected}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Cutouts"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"p-2 bg-muted/30 rounded-lg text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Good"}),e.jsxs("p",{className:"font-bold text-sm",children:["$",Math.round(m.summary.ratesApplied.goodBetterBest.good*m.summary.totalSqft).toLocaleString()]}),e.jsxs("p",{className:"text-[9px] text-muted-foreground",children:["$",m.summary.ratesApplied.goodBetterBest.good,"/sqft"]})]}),e.jsxs("div",{className:"p-2 bg-primary/10 rounded-lg text-center border border-primary/20",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Better"}),e.jsxs("p",{className:"font-bold text-sm",children:["$",Math.round(m.summary.ratesApplied.goodBetterBest.better*m.summary.totalSqft).toLocaleString()]}),e.jsxs("p",{className:"text-[9px] text-muted-foreground",children:["$",m.summary.ratesApplied.goodBetterBest.better,"/sqft"]})]}),e.jsxs("div",{className:"p-2 bg-muted/30 rounded-lg text-center",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Best"}),e.jsxs("p",{className:"font-bold text-sm",children:["$",Math.round(m.summary.ratesApplied.goodBetterBest.best*m.summary.totalSqft).toLocaleString()]}),e.jsxs("p",{className:"text-[9px] text-muted-foreground",children:["$",m.summary.ratesApplied.goodBetterBest.best,"/sqft"]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("a",{href:"/leads",className:"flex-1",children:e.jsxs(D,{variant:"outline",className:"w-full",children:[e.jsx(ae,{className:"w-4 h-4 mr-1"})," View Leads"]})}),e.jsxs(D,{variant:"default",className:"flex-1",onClick:S,children:[e.jsx(pe,{className:"w-4 h-4 mr-1"})," New DXF"]})]})]})]})]})}const Is=[{value:"granite",label:"Granite"},{value:"quartz",label:"Quartz"},{value:"marble",label:"Marble"},{value:"quartzite",label:"Quartzite"},{value:"soapstone",label:"Soapstone"},{value:"laminate",label:"Laminate"},{value:"butcher_block",label:"Butcher Block"},{value:"other",label:"Other"}],zs={queued:{label:"Queued",color:"text-muted-foreground",icon:ae},processing:{label:"Processing",color:"text-blue-600",icon:ge},success:{label:"Done",color:"text-green-600",icon:we},error:{label:"Failed",color:"text-red-600",icon:Ue}};function Rs({onQuotesCreated:a}){const n=j.useRef(null),[i,o]=j.useState([]),[d,u]=j.useState(""),[m,N]=j.useState(""),[x,k]=j.useState(""),[r,v]=j.useState("quartz"),[P,M]=j.useState("kitchen"),[A,I]=j.useState(!1),[f,c]=j.useState(!1),p=l=>{const w=Array.from(l.target.files||[]),y=w.filter(_=>{const K=_.name.toLowerCase().split(".").pop();return["dxf","pdf","png","jpg","jpeg"].includes(K)}),$=w.length-y.length;$>0&&T.warning(`${$} file(s) skipped — only DXF, PDF, or images supported`);const q=y.map((_,K)=>({id:`${Date.now()}-${K}`,file:_,name:_.name,type:_.name.toLowerCase().split(".").pop(),status:"queued",result:null,error:null}));o(_=>[..._,...q]),c(!1),n.current&&(n.current.value="")},E=l=>{o(w=>w.filter(y=>y.id!==l))},Q=(l,w)=>{o(y=>y.map($=>$.id===l?{...$,...w}:$))},h=async l=>{var _e,Ce;if(l.type==="dxf"){const ue=await l.file.text();if(ue.includes("\0")&&!ue.startsWith(`0
26`))throw new Error("Binary DXF not supported — use ASCII DXF");const le=await z.functions.invoke("dxfToQuotePipeline",{dxfContent:ue,customerName:d.trim(),customerEmail:m.trim(),customerPhone:x.trim(),materialType:r,projectType:P});if((_e=le==null?void 0:le.data)!=null&&_e.success)return{quote:le.data.quote,summary:le.data.summary};throw new Error(((Ce=le==null?void 0:le.data)==null?void 0:Ce.error)||"DXF pipeline failed")}const{file_url:w}=await z.integrations.Core.UploadFile({file:l.file}),y=await z.functions.invoke("parseJobPdf",{pdf_url:w}),$=(y==null?void 0:y.data)||{};if(!$.customer_name&&!$.square_feet)throw new Error("Could not extract usable data from this file");const q=parseFloat($.square_feet)||0,K={granite:65,quartz:80,marble:95,quartzite:95,soapstone:80,laminate:40,butcher_block:55,other:65}[r]||65,C=Math.round(q*K),F=Math.round(q*K*.45),se=Math.round(q*30),me=`Q-${Date.now().toString(36).toUpperCase().slice(-6)}`;return{quote:await z.entities.Quote.create({quote_number:me,customer_name:$.customer_name||d.trim(),customer_email:m.trim()||$.customer_email||"",customer_phone:x.trim()||"",project_type:P,material_type:r,sqft:q,material_cost:F,labor_cost:se,total_cost:F+se,selling_price:C,status:"draft",created_date:new Date().toISOString().split("T")[0],notes:JSON.stringify({source:"batch_pdf_import",original_file:l.name,extracted_address:$.job_address||"",document_type:$.document_type||"unknown",created_at:new Date().toISOString()})}),summary:{totalSqft:q,sellingPrice:C,piecesFound:0,cutoutsDetected:0}}},t=async()=>
26{if(!d.trim()){T.error("Customer name is required for all quotes");return}if(i.length===0)return;I(!0),c(!1);const l=[];for(const w of i)if(w.status!=="success"){Q(w.id,{status:"processing",error:null});try{const y=await h(w);Q(w.id,{status:"success",result:y}),l.push(y.quote)}catch(y){Q(w.id,{status:"error",error:y.message||"Processing failed"})}}I(!1),c(!0),l.length>0?(T.success(`${l.length} quote(s) created from ${i.length} file(s)`),a&&a(l)):T.error("No quotes were created — check file errors below")},g=()=>{o([]),u(""),N(""),k(""),c(!1)},S=i.filter(l=>l.status==="success"&&l.result).reduce((l,w)=>{var y;return l+(((y=w.result.summary)==null?void 0:y.totalSqft)||0)},0),H=i.filter(l=>l.status==="success"&&l.result).reduce((l,w)=>{var y;return l+(((y=w.result.summary)==null?void 0:y.sellingPrice)||0)},0),R=i.filter(l=>l.status==="success").length;return e.jsxs(U,{children:[e.jsxs(te,{children:[e.jsxs(ie,{className:"flex items-center gap-2 text-base",children:[e.jsx(ss,{className:"w-5 h-5 text-primary"}),"Batch Plan Importer"]}),e.jsx(he,{children:"Drop multiple DXF, PDF, or image floor plans. Set one customer + material, and we'll generate a quote for each."})]}),e.jsxs(O,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Customer Name *"}),e.jsx(V,{value:d,onChange:l=>u(l.target.value),placeholder:"John Smith",className:"h-9"})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Email"}),e.jsx(V,{type:"email",value:m,onChange:l=>N(l.target.value),placeholder:"[email protected]",className:"h-9"})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Phone"}),e.jsx(V,{value:x,onChange:l=>k(l.target.value),placeholder:"(555) 123-4567",className:"h-9"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Material"}),e.jsxs(Y,{value:r,onValueChange:v,children:[e.jsx(J,{className:"h-9",children:e.jsx(Z,{})}),e.jsx(ee,{children:Is.map(l=>e.jsx(b,{value:l.value,children:l.label},l.value))})]})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:"Project"}),e.jsxs(Y,{value:P,onValueChange:M,children:[e.jsx(J,{className:"h-9",children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(b,{value:"kitchen",children:"Kitchen"}),e.jsx(b,{value:"bathroom",children:"Bathroom"}),e.jsx(b,{value:"commercial",children:"Commercial"}),e.jsx(b,{value:"outdoor",children:"Outdoor"})]})]})]})]})]}),e.jsxs("div",{className:"border-2 border-dashed border-muted-foreground/25 rounded-lg p-4 text-center hover:border-primary/40 transition-colors cursor-pointer",onClick:()=>{var l;return(l=n.current)==null?void 0:l.click()},onDragOver:l=>l.preventDefault(),onDrop:l=>{l.preventDefault();const y={target:{files:Array.from(l.dataTransfer.files||[])}};p(y)},children:[e.jsx(pe,{className:"w-8 h-8 text-muted-foreground mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm font-medium",children:"Drop multiple plans here or click to select"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Supports .dxf, .pdf, .png, .jpg — all processed with the same customer info"}),e.jsx("input",{ref:n,type:"file",accept:".dxf,.pdf,.png,.jpg,.jpeg",multiple:!0,onChange:p,className:"hidden"})]}),i.length>0&&e.jsx("div",{className:"space-y-1.5",children:i.map(l=>{var $,q,_,K;const w=zs[l.status],y=w.icon;return e.jsxs("div",{className:"flex items-center gap-2 p-2 border rounded-lg text-sm",children:[e.jsx(y,{className:`w-4 h-4 shrink-0 ${w.color} ${l.status==="processing"?"animate-spin":""}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium truncate",children:l.name}),e.jsx(B,{variant:"outline",className:"text-[9px] uppercase",children:l.type})]}),l.status==="success"&&l.result&&e.jsxs("span",{className:"text-[11px] text-green-600",children:[(($=l.result.summary)==null?void 0:$.totalSqft)||0," sqft · $",((_=(q=l.result.summary)==null?void 0:q.sellingPrice)==null?void 0:_.toLocaleStr
26ing())||0," · ",(K=l.result.quote)==null?void 0:K.quote_number]}),l.status==="error"&&e.jsx("span",{className:"text-[11px] text-red-600",children:l.error})]}),!A&&l.status!=="success"&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>E(l.id),children:e.jsx(rs,{className:"w-3 h-3"})})]},l.id)})}),i.length>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-stretch sm:items-center justify-between",children:[f&&R>0&&e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"w-4 h-4 text-green-600"})," ",R," quotes created"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Re,{className:"w-4 h-4 text-primary"})," ",S.toLocaleString()," sqft"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(re,{className:"w-4 h-4 text-green-600"})," $",H.toLocaleString()]})]}),e.jsxs("div",{className:"flex gap-2 sm:ml-auto",children:[f&&e.jsxs(D,{variant:"outline",onClick:g,children:[e.jsx(pe,{className:"w-4 h-4 mr-1"})," New Batch"]}),e.jsx(D,{onClick:t,disabled:A||!d.trim()||i.filter(l=>l.status!=="success").length===0,children:A?e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"w-4 h-4 mr-1 animate-spin"})," Processing ",i.filter(l=>l.status==="processing"||l.status==="queued").length," files..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"w-4 h-4 mr-1"})," Process ",i.filter(l=>l.status!=="success").length," File(s)"]})})]})]})]})]})}function Us(){return e.jsx(G.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.02},className:"mb-8",children:e.jsx("div",{className:"relative overflow-hidden rounded-2xl bg-gradient-to-br from-primary/10 via-accent/5 to-transparent border border-border p-6 shadow-lg",children:e.jsxs("div",{className:"relative",children:[e.jsx(G.div,{className:"flex justify-center mb-4",initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},transition:{delay:.1},children:e.jsxs("div",{className:"inline-flex items-center gap-2 px-4 py-2 rounded-full bg-card border border-border shadow-sm",children:[e.jsx(je,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-bold text-primary",children:"Sales Pipeline Dashboard"})]})}),e.jsxs(G.div,{className:"text-center",initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.15},children:[e.jsxs("h1",{className:"text-3xl md:text-4xl font-black mb-3",children:["Every deal tracked.",e.jsx("br",{}),e.jsx("span",{className:"text-primary",children:"Every dollar chased."})]}),e.jsx("p",{className:"text-muted-foreground max-w-2xl mx-auto",children:"Track your pipeline from lead to close with automated follow-ups and real-time analytics."})]}),e.jsxs(G.div,{className:"grid grid-cols-1 md:grid-cols-3 gap-4 max-w-4xl mx-auto mt-6",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2},children:[e.jsx(Ee,{icon:je,label:"Pipeline Value",delay:.25}),e.jsx(Ee,{icon:Le,label:"Win Rate",delay:.3}),e.jsx(Ee,{icon:$e,label:"Avg Close Time",delay:.35})]})]})})})}function Ee({icon:a,label:n,delay:i}){return e.jsxs(G.div,{initial:{opacity:0,y:15},animate:{opacity:1,y:0},transition:{delay:i},whileHover:{scale:1.05,y:-5},className:"group flex items-center gap-4 p-4 bg-card rounded-2xl border border-border shadow-sm hover:shadow-md transition-all",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-primary/10 flex items-center justify-center group-hover:scale-110 transition-transform",children:e.jsx(a,{className:"w-6 h-6 text-primary"})}),e.jsx("div",{children:e.jsx("p",{className:"text-xs font-bold text-muted-foreground uppercase tracking-wider",children:n})})]})}function Os({quote:a}){var d;if(!a)return e.jsx(U,{className:"border-0 shadow-lg overflow-hidden",children:e.jsxs(O,{className:"p-6 flex flex-col items-center justify-center min-h-[300px] text-center",children:[e.jsx(ts,{className:"w-12 h-12 text-muted-foreground mb-3"}),e.jsx("h3",{className:"text-lg font-bold mb-1",children:"Deal Timeline"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a deal to view its timeline"})]})});const n=[{id:"created",label:"Lead created",icon:ae,color:"bg-muted-foreground",date:a.created_date},{id:"quoted",label:"Quote drafted",icon:re,color:"bg-info",date:a.created_date},{id:"sent",label:"Sent to customer",icon:oe,color:"bg-purple-500",date:a.sent_date},{id:"accepted",label:"Accepted",icon:Ne,color:"bg-success",date:a.signature_date}].filter(u=>u.date),i=n.length-1,o=u=>u?new Date(u).toLocaleDateString("en-US",{month:"short",day:"numeric"}):null;return e.jsx(U,{className:"border-0 shadow-lg overflow-hidden",children:e.jsxs(O,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary flex items-center justify-center shadow-lg",children:e.jsx(je,{className:"w-5 h-5 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",children:"Deal Timeline"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:"secondary",className:"text-xs",children:a.customer_name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["#",a.quote_number]})]})]})]}),e.jsx(B,{className:a.status==="accepted"?"bg-success/15 text-success":"bg-warning/15 text-warning",children:a.status.toUpperCase()})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute left-5 top-5 bottom-5 w-0.5 bg-border"}),e.jsx("div",{className:"space-y-6",children:n.map((u,m)=>{const N=m<i,x=m===i,k=u.icon;return e.jsxs(G.div,{initial:{opacity:0,x:-20}
26,animate:{opacity:1,x:0},transition:{delay:m*.1},className:"relative flex items-start gap-4",children:[e.jsx("div",{className:`relative z-10 w-10 h-10 rounded-full flex items-center justify-center transition-all ${N||x?u.color:"bg-muted"}`,children:N?e.jsx(Ne,{className:"w-5 h-5 text-white"}):e.jsx(k,{className:`w-5 h-5 ${x?"text-white":"text-muted-foreground"}`})}),e.jsxs("div",{className:"flex-1 pt-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:`font-semibold ${N||x?"":"text-muted-foreground"}`,children:u.label}),u.date&&e.jsx("span",{className:"text-xs text-muted-foreground",children:o(u.date)})]}),x&&a.status!=="accepted"&&e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs(B,{className:"bg-warning/15 text-warning text-xs",children:[e.jsx(de,{className:"w-3 h-3 mr-1"}),"Pending"]}),a.created_date&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[Math.ceil((Date.now()-new Date(a.created_date+"T00:00:00").getTime())/(1e3*60*60*24))," days in stage"]})]})]})]},u.id)})})]}),e.jsxs("div",{className:"mt-6 pt-6 border-t border-border",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Deal Value"})]}),e.jsxs("span",{className:"text-xl font-bold",children:["$",((d=a.selling_price)==null?void 0:d.toLocaleString())||"0"]})]}),a.margin_pct!==null&&a.margin_pct!==void 0&&e.jsx("div",{className:"flex items-center gap-2 mt-2",children:e.jsxs(B,{className:"bg-success/15 text-success text-xs",children:[a.margin_pct,"% margin"]})})]})]})})}const Vs={staleTime:6e4};function Bs(){const{data:a=[]}=ce({queryKey:["quotes"],queryFn:()=>z.entities.Quote.list(),...Vs}),n=j.useMemo(()=>{const i=a.filter(c=>["accepted","rejected","expired"].includes(c.status)).length,o=a.filter(c=>c.status==="accepted").length,d=i>0?Math.round(o/i*100):0,u={new:.1,contacted:.25,measured:.5,quoted:.7,sent:.8,revised:.85,draft:.6},m=a.filter(c=>["draft","sent","revised"].includes(c.status)).reduce((c,p)=>{const E=u[p.status]||.5;return c+(p.selling_price||0)*E},0),N=a.filter(c=>c.status==="accepted"&&c.signature_date),x=N.length>0?Math.round(N.reduce((c,p)=>{const E=new Date(p.created_date+"T00:00:00").getTime(),Q=new Date(p.signature_date).getTime();return c+(Q-E)/(1e3*60*60*24)},0)/N.length):0,r=a.filter(c=>{if(!["sent","revised"].includes(c.status))return!1;const p=new Date(c.created_date+"T00:00:00"),E=(Date.now()-p.getTime())/(1e3*60*60*24);return E>7&&E<30}).reduce((c,p)=>c+(p.selling_price||0),0),v=new Date,P=a.filter(c=>{const p=new Date(c.created_date+"T00:00:00");return p.getMonth()===v.getMonth()&&p.getFullYear()===v.getFullYear()}),M=new Date(v.getFullYear(),v.getMonth()-1,1),A=a.filter(c=>{const p=new Date(c.created_date+"T00:00:00");return p.getMonth()===M.getMonth()&&p.getFullYear()===M.getFullYear()}),I=A.length>0?Math.round((P.length-A.length)/A.length*100):0,f=a.filter(c=>c.status==="accepted"&&new Date(c.created_date+"T00:00:00")>=new Date(v.getFullYear(),v.getMonth(),1)).reduce((c,p)=>c+(p.selling_price||0),0);return{winRate:d,weightedValue:m,avgDaysToClose:x,forecastRevenue:r,pipelineGrowth:I,totalPipeline:a.filter(c=>["draft","sent","revised"].includes(c.status)).length,wonCount:o,wonThisMonthValue:f}}
26,[a]);return e.jsxs(U,{className:"overflow-hidden relative",children:[e.jsx(te,{className:"pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(G.div,{className:"w-14 h-14 rounded-2xl bg-success flex items-center justify-center shadow-lg",whileHover:{scale:1.1,rotate:5},transition:{type:"spring",stiffness:300},children:e.jsx(qe,{className:"w-7 h-7 text-success-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-black",children:"Sales Forecast"}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Predict your revenue"})]})]}),e.jsxs(B,{className:"bg-success/10 text-success border-success/20 px-3 py-1.5 text-xs font-bold",children:[e.jsx(Le,{className:"w-3 h-3 mr-1"}),"AI-POWERED"]})]})}),e.jsxs(O,{className:"relative",children:[e.jsxs(G.div,{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-6",initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.1},children:[e.jsx(De,{label:"Win Rate",value:`${n.winRate}%`,subtext:`${n.wonCount} won deals`,icon:Le,color:"text-success",delay:.15}),e.jsx(De,{label:"Weighted Pipeline",value:`$${(n.weightedValue/1e3).toFixed(1)}K`,subtext:"Probability-based",icon:re,color:"text-info",delay:.2,hasBorder:!0}),e.jsx(De,{label:"Avg Days to Close",value:n.avgDaysToClose,subtext:"From quote to sign",icon:fe,color:"text-purple-500",delay:.25,hasBorder:!0}),e.jsx(De,{label:"30-Day Forecast",value:`$${(n.forecastRevenue/1e3).toFixed(1)}K`,subtext:"Next month revenue",icon:je,color:"text-warning",delay:.3})]}),e.jsxs(G.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.35},className:"p-5 bg-gradient-to-r from-success to-emerald-600 rounded-2xl text-white relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-white/10 rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-white/10 rounded-full blur-xl"}),e.jsxs("div",{className:"relative flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-white/80 uppercase tracking-wider mb-1",children:"Pipeline Growth"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("p",{className:"text-3xl font-black",children:[n.pipelineGrowth>=0?"+":"",n.pipelineGrowth,"%"]}),e.jsxs("div",{className:`flex items-center gap-1 px-2 py-1 rounded-lg ${n.pipelineGrowth>0?"bg-white/20":n.pipelineGrowth<0?"bg-red-500/30":"bg-white/10"}`,children:[n.pipelineGrowth>0?e.jsx(bs,{className:"w-4 h-4"}):n.pipelineGrowth<0?e.jsx(ys,{className:"w-4 h-4"}):e.jsx(ns,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs font-bold",children:"vs last month"})]})]}),e.jsxs("p",{className:"text-xs text-white/80 mt-2",children:[n.totalPipeline," active deals in pipeline"]})]}),e.jsx(G.div,{className:"hidden lg:block",animate:{y:[0,-5,0]},transition:{duration:2,repeat:1/0},children:e.jsx("div",{className:"w-24 h-24 bg-white/10 rounded-xl flex items-center justify-center",children:e.jsx(qe,{className:"w-12 h-12 text-white/80"})})})]})]}),e.jsxs(G.div,{className:"grid grid-cols-3 gap-3 mt-6",initial:{opacity:0}
26,animate:{opacity:1},transition:{delay:.4},children:[e.jsx(Ie,{label:"Won This Month",value:`$${n.wonThisMonthValue.toLocaleString()}`,color:"from-emerald-500 to-teal-500"}),e.jsx(Ie,{label:"Conversion",value:`${n.winRate}%`,color:"from-blue-500 to-cyan-500"}),e.jsx(Ie,{label:"Avg Deal",value:`$${n.forecastRevenue>0?Math.round(n.forecastRevenue/Math.max(n.totalPipeline,1)).toLocaleString():"0"}`,color:"from-purple-500 to-pink-500"})]})]})]})}function De({label:a,value:n,subtext:i,icon:o,color:d,delay:u,hasBorder:m}){return e.jsxs(G.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:u},className:`space-y-2 ${m?"border-l border-border pl-4":""}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-muted flex items-center justify-center",children:e.jsx(o,{className:`w-5 h-5 ${d}`})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:a}),e.jsx("p",{className:"text-xl font-black",children:n})]})]}),e.jsx("p",{className:`text-[10px] font-bold ${d}`,children:i})]})}function Ie({label:a,value:n,color:i}){return e.jsxs(G.div,{whileHover:{scale:1.05,y:-2},className:`p-3 rounded-xl bg-gradient-to-br ${i} text-white text-center shadow-lg`,children:[e.jsx("p",{className:"text-[10px] font-bold text-white/90 uppercase tracking-wider mb-0.5",children:a}),e.jsx("p",{className:"text-sm font-black",children:n})]})}function xe({label:a,value:n,subvalue:i,icon:o,color:d,delay:u}){return e.jsxs(G.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:u},whileHover:{scale:1.05,y:-3},className:"relative group",children:[e.jsx("div",{className:`absolute inset-0 bg-gradient-to-r ${d} opacity-5 rounded-2xl blur-xl group-hover:opacity-20 transition-opacity duration-300`}),e.jsxs("div",{className:"relative bg-card border border-border rounded-2xl p-4 overflow-hidden",children:[e.jsx("div",{className:`absolute top-0 right-0 w-20 h-20 bg-gradient-to-br ${d} opacity-10 rounded-bl-full`}),e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg bg-gradient-to-br ${d} flex items-center justify-center`,children:e.jsx(o,{className:"w-4 h-4 text-white"})}),e.jsx("span",{className:"text-[9px] font-bold text-muted-foreground uppercase tracking-wider",children:a})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"text-2xl font-black",children:n}),e.jsx("p",{className:"text-[10px] font-bold text-muted-foreground",children:i})]})]})]})}function Ks({stats:a}){if(!a)return null;const n=i=>i>=1e6?"$"+(i/1e6).toFixed(2)+"M":i>=1e3?"$"+(i/1e3).toFixed(0)+"K":"$"+(i||0);return e.jsx(G.div,{initial:{opacity:0,y:-20},animate:{opacity:1,y:0},className:"mb-6",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(xe,{label:"PIPELINE",value:a.pipelineCount||0,subvalue:n(a.pipelineValue),icon:je,color:"from-blue-500 to-cyan-500",delay:0}),e.jsx(xe,{label:"WEIGHTED",value:a.weightedCount||0,subvalue:n(a.weightedValue),icon:re,color:"from-purple-500 to-pink-500",delay:.05}),e.jsx(xe,{label:"CLOSING THIS MO",value:a.closingThisMonthCount||0,subvalue:n(a.closingThisMonthValue),icon:fe,color:"from-orange-500 to-amber-500",delay:.1}),e.jsx(xe,{label:"WON THIS MO",value:a.wonThisMonthCount||0,subvalue:n(a.wonThisMonthValue),icon:ws,color:"from-emerald-500 to-green-500",delay:.15}),e.jsx(xe,{label:"WIN RATE (90D)",value:`${a.winRate||0}%`,subvalue:`${a.wonCount||0} won / ${a.totalClosed||0} closed`,icon:Le,color:"from-rose-500 to-red-500",delay:.2}),e.jsx(xe,{label:"AVG CLOSE",value:a.avgCloseDays||0,subvalue:"days",icon:$e,color:"from-indigo-500 to-violet-500",delay:.25})]})})}function Gs({viewMode:a,setViewMode:n,onExport:i,totalItems:o,onFilterChange:d,searchTerm:u,onSearchChange:m}){return e.jsxs(G.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-muted rounded-xl p-1",children:[e.jsxs("button",{onClick:()=>n("kanban"),className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ${a==="kanban"?"bg-primary text-primary-foreground shadow":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(_s,{className:"w-4 h-4"}),"Kanban"]}),e.jsxs("button",{onClick:()=>n("table"),className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ${a==="table"?"bg-primary text-primary-foreground shadow":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(Ps,{className:"w-4 h-4"}),"Table"]})]}),e.jsxs(is,{children:[e.jsx(cs,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:"h-10",children:[e.jsx(Cs,{className:"w-4 h-4 mr-2"}),"Filter"]})}),e.jsxs(ds,{children:[e.jsx(Se,{onClick:()=>d==null?void 0:d("all"),children:"All Deals"}),e.jsx(Se,{onClick:()=>d==null?void 0:d("my"),children:"My Pipeline"}),e.jsx(Se,{onClick:()=>d==null?void 0:d("salesperson"),children:"By Salesperson"}),e.jsx(Se,{onClick:()=>d==null?void 0:d("unassigned"),children:"Unassigned"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Xe,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{placeholder:"Search deals...",value:u||"",onChange:N=>m==null?void 0:m(N.target.value),className:"pl-8 w-48"})]}),e.jsxs(D,{onClick:i,children:[e.jsx(os,{className:"w-4 h-4 mr-2"}),"Export"]})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-border",children:[e.jsxs(B,{variant:"outline",className:"text-xs",children:[o," open deals"]}
26),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Last 90 days"})]})]})}function Ws(a){const n=a.signature_date||a.sent_date||a.created_date;if(!n)return 0;const i=new Date(n.includes("T")?n:n+"T00:00:00"),o=Date.now()-i.getTime();return Math.max(0,Math.floor(o/(1e3*60*60*24)))}function Xs({data:a,onViewDeal:n,onCreateQuote:i}){return!a||a.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center border border-dashed rounded-xl",children:[e.jsx(ts,{className:"w-12 h-12 text-muted-foreground mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:"No deals in pipeline"})]}):e.jsxs(G.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-12 gap-4 px-4 py-3 bg-muted/50 border border-border rounded-xl text-xs font-bold text-muted-foreground uppercase tracking-wider",children:[e.jsx("div",{className:"col-span-3",children:"Customer"}),e.jsx("div",{className:"col-span-2",children:"Value"}),e.jsx("div",{className:"col-span-1",children:"Stage"}),e.jsx("div",{className:"col-span-1",children:"Age"}),e.jsx("div",{className:"col-span-2",children:"Salesperson"}),e.jsx("div",{className:"col-span-2",children:"Contact"}),e.jsx("div",{className:"col-span-1 text-right",children:"Actions"})]}),a.map(o=>{var m;const d=Ws(o),u=o.assigned_to||o.salesperson_name;return e.jsxs(G.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},whileHover:{scale:1.01},className:"grid grid-cols-12 gap-4 px-4 py-4 bg-card border border-border rounded-xl hover:bg-accent/50 transition-all cursor-pointer",onClick:()=>n==null?void 0:n(o),children:[e.jsxs("div",{className:"col-span-3 flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary flex items-center justify-center text-primary-foreground font-bold text-sm shadow",children:((m=o.customer_name)==null?void 0:m.charAt(0))||"?"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-sm",children:o.customer_name}),o.project_type&&e.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:o.project_type})]})]}),e.jsx("div",{className:"col-span-2 flex items-center",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(re,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs("span",{className:"font-bold",children:["$",(o.selling_price||o.estimated_value||0).toLocaleString()]})]})}),e.jsx("div",{className:"col-span-1 flex items-center",children:e.jsx(B,{className:`text-xs ${o.status==="won"||o.status==="accepted"?"bg-success/15 text-success":o.status==="sent"?"bg-info/15 text-info":o.status==="draft"||o.status==="quoted"?"bg-warning/15 text-warning":"bg-muted text-muted-foreground"}`,children:o.status})}),e.jsxs("div",{className:"col-span-1 flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(fe,{className:"w-3 h-3"}),d,"d"]}),e.jsxs("div",{className:"col-span-2 flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center text-xs",children:(u==null?void 0:u.charAt(0))||"U"}),e.jsx("span",{className:"text-sm",children:u||"Unassigned"})]}),e.jsxs("div",{className:"col-span-2 flex items-center gap-3 text-xs text-muted-foreground",children:[o.customer_email&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(oe,{className:"w-3 h-3"}),e.jsx("span",{className:"truncate",children:o.customer_email})]}),o.customer_phone&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ye,{className:"w-3 h-3"}),e.jsx("span",{children:o.customer_phone})]})]}),e.jsxs("div",{className:"col-span-1 flex items-center justify-end gap-2",children:[e.jsx(D,{size:"sm",variant:"outline",onClick:N=>{N.stopPropagation(),n==null||n(o)},className:"h-8",children:e.jsx(as,{className:"w-3 h-3"})}),o.status!=="won"&&o.status!=="accepted"&&e.jsx(D,{size:"sm",onClick:N=>{N.stopPropagation(),i==null||i(o)},className:"h-8",children:e.jsx(Pe,{className:"w-3 h-3"})})]})]},o.id)})]})}const Ke={staleTime:6e4};function Hs(){const a=Ge(),n=Me(),[i,o]=j.useState(""),[d,u]=j.useState("kanban"),[m,N]=j.useState("all"),{data:x=[]}=ce({queryKey:["leads"],queryFn:()=>z.entities.Lead.list("-created_date"),...Ke}),{data:k=[]}=ce({queryKey:["quotes"],queryFn:()=>z.entities.Quote.list("-created_date"),...Ke}),r=j.useMemo(()=>{const f=new Date,c=new Date(f.getTime()-2160*60*60*1e3),p=new Date(f.getFullYear(),f.getMonth(),1),E=x.filter(C=>!["won","lost"].includes(C.status)),Q=k.filter(C=>["draft","sent","revised"].includes(C.status)),h=k.filter(C=>["accepted","rejected","expired"].includes(C.status)),t=E.reduce((C,F)=>C+(F.estimated_value||0),0)+Q.reduce((C,F)=>C+(F.selling_price||0),0),g={new:.1,contacted:.25,measured:.5,quoted:.7,sent:.8,revised:.85,draft:.6},S=Q.reduce((C,F)=>{const se=g[F.status]||.5;return C+(F.selling_price||0)*se},0),H=k.filter(C=>C.status==="accepted"&&new Date(C.created_date+"T00:00:00")>=p),R=H.reduce((C,F)=>C+(F.selling_price||0),0),l=Q.filter(C=>{const F=new Date(C.created_date+"T00:00:00"),se=(Date.now()-F.getTime())/(1e3*60*60*24);return se>7&&se<30}),w=l.reduce((C,F)=>C+(F.selling_price||0),0),y=h.filter(C=>new Date(C.created_date+"T00:00:00")>=c),$=y.filter(C=>C.status==="accepted"),q=y.length>0?Math.round($.length/y.length*100):0,_=$.filter(C=>C.signature_date),K=_.length>0?Math.round(_.reduce((C,F)=>{const se=new Date(F.created_date+"T00:00:00").getTime(),me=new Date(F.signature_date).getTime();return C+(me-se)/(1e3*60*60*24)},0)/_.length):0;return{pipelineCount:E.length+Q.length,pipelineValue:t,weightedCount:Q.length,weightedValue:S,closingThisMonthCount:l.length,closingThisMonthValue:w,wonThisMonthCount:H.length,wonThisMonthValue:R,winRate:q,totalClosed:y.length,wonCount:$.length,avgCloseDays:K}},[x,k]),v=ve({mutationFn:({id:f,data:c})=>z.entities.Lead.update(f,c),onSuccess:()=>{a.invalidateQueries({queryKey:["leads"]}),T.success("Lead updated")}}),P=ve({mutationFn:({id:f,data:c})=>z.entities.Quote.update(f,c),onSuccess:()=>{a.invalidateQueries({queryKey:["quotes"]}),T.success("Quote updated")}}),M=j.useMemo(()=>{const f=x.filter(t=>!["won","lost"].includes(t.status)),c=k.filter(t=>["draft","sent","revised"].includes(t.status)),p=i.toLowerCase(),E=t=>p?(t.customer_name||"").toLowerCase().includes(p)||(t.customer_email||"").toLowerCase().includes(p):!0,Q=t=>m==="all"?!0:m==="unassigned"?!t.assigned_to&&!t.salesperson_name:m==="my"?t.assigned_to||t.s
26alesperson_name:!0,h=t=>E(t)&&Q(t);return{lead:f.filter(t=>["new","contacted"].includes(t.status)).filter(h),quoted:c.filter(t=>t.status==="draft").filter(h),sent:c.filter(t=>["sent","revised"].includes(t.status)).filter(h),won:x.filter(t=>t.status==="won").filter(h)}},[x,k,i,m]),A=f=>{const{destination:c,source:p,draggableId:E}=f;if(!c||c.droppableId===p.droppableId&&c.index===p.index)return;const Q=E.indexOf(":");if(Q===-1)return;const h=E.substring(0,Q),t=E.substring(Q+1);if(h==="lead"){const g={lead:"new",quoted:"quoted",won:"won"};v.mutate({id:t,data:{status:g[c.droppableId]||"new"}})}else if(h==="quote"){const g={lead:"draft",quoted:"draft",sent:"sent",won:"accepted"};P.mutate({id:t,data:{status:g[c.droppableId]||"draft"}})}},I=[{id:"lead",title:"LEAD",icon:He,accent:"text-info"},{id:"quoted",title:"QUOTED",icon:ae,accent:"text-warning"},{id:"sent",title:"SENT",icon:oe,accent:"text-purple-500"},{id:"won",title:"WON",icon:Ne,accent:"text-success"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Us,{}),e.jsx(Ks,{stats:r}),e.jsx(Gs,{viewMode:d,setViewMode:u,onExport:()=>T.info("Exporting pipeline..."),totalItems:I.reduce((f,c)=>{var p;return f+(((p=M[c.id])==null?void 0:p.length)||0)},0),onFilterChange:N,searchTerm:i,onSearchChange:o}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(vs,{}),e.jsx(Os,{})]}),e.jsx(Bs,{}),d==="kanban"?e.jsx(js,{onDragEnd:A,children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:I.map((f,c)=>{var p;return e.jsx(G.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:c*.1},children:e.jsxs(U,{className:"overflow-hidden",children:[e.jsx(te,{className:"pb-3 border-b",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-muted flex items-center justify-center",children:e.jsx(f.icon,{className:`w-4 h-4 ${f.accent}`})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold uppercase tracking-wider",children:f.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[((p=M[f.id])==null?void 0:p.length)||0," items"]})]})]})})}),e.jsx(O,{className:"p-3",children:e.jsx(fs,{droppableId:f.id,children:(E,Q)=>e.jsxs("div",{ref:E.innerRef,...E.droppableProps,className:`space-y-2 min-h-[300px] transition-colors rounded-lg ${Q.isDraggingOver?"bg-accent/50":""}`,children:[(M[f.id]||[]).map((h,t)=>e.jsx(Ys,{item:h,type:f.id==="lead"||f.id==="won"?"lead":"quote",index:t},h.id)),E.placeholder]})})})]})},f.id)})})}):e.jsx(Xs,{data:[...M.lead,...M.quoted,...M.sent],onViewDeal:f=>T.info(`View ${f.customer_name}`),onCreateQuote:f=>{n(`/quote?customer_name=${encodeURIComponent(f.customer_name)}`)}})]})}function Ys({item:a,type:n,index:i}){const o=Me(),d=n==="lead",u=d?a.estimated_value||0:a.selling_price||0,m=d?null:a.margin_pct,N=x=>x>=1e6?`$${(x/1e6).toFixed(1)}M`:x>=1e3?`$${(x/1e3).toFixed(0)}K`:`$${x.toLocaleString()}`;return e.jsx(Ns,{draggableId:`${n}:${a.id}`,index:i,children:(x,k)=>e.jsx(G.div,{ref:x.innerRef,...x.draggableProps,...x.dragHandleProps,initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:i*.05},className:`bg-card rounded-xl p-4 shadow-sm border border-border hover:shadow-md transition-all cursor-grab active:cursor-grabbing ${k.isDragging?"shadow-xl ring-2 ring-primary z-50":""}`,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-sm",children:a.customer_name}),d&&a.project_type&&e.jsxs("p",{className:"text-xs text-muted-foreground capitalize mt-0.5",children:[a.project_type," • ",a.estimated_sqft||0," sqft"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(re,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-bold",children:N(u)})]}),m!=null&&e.jsxs(B,{className:"bg-success/15 text-success text-xs",children:[m,"% margin"]})]}),e.jsxs("div",{className:"space-y-1.5 pt-2 border-t border-border",children:[a.customer_email&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(oe,{className:"w-3 h-3"}),e.jsx("span",{className:"truncate",children:a.customer_email})]}),a.customer_phone&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(ye,{className:"w-3 h-3"}),e.jsx("span",{children:a.customer_phone})]}),a.follow_up_date&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(fe,{className:"w-3 h-3"}),e.jsx("span",{children:new Date(a.follow_up_date+"T00:00:00").toLocaleDateString()})]})]}),d&&a.status!=="won"&&e.jsxs(D,{size:"sm",className:"w-full mt-2 text-xs",onClick:r=>{r.stopPropagation(),o(`/quote?customer_name=${encodeURIComponent(a.customer_name)}&project_type=${a.project_type||"kitchen"}`)},children:["Create Quote",e.jsx(Pe,{className:"w-3 h-3 ml-1"})]})]})})})}function Js({quotes:a,isLoadingQuotes:n,quoteStats:i,pipelineValue:o,onSendFollowUps:d,onViewQuote:u,onEditQuote:m,onDeleteQuote:N,onConvertToJob:x}){const k=Me();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-playfair font-bold text-foreground tracking-tight",children:"Quote Dashboard"}),e.jsx("p",{className:"text-sm text-muted-foreground font-light",children:"Track quote status and customer engagement"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{variant:"outline",onClick:()=>k("/quote"),children:[e.jsx(ze,{className:"w-4 h-4 mr-2"}),"New Quote"]}),e.jsxs(D,{onClick:d,className:"bg-primary hover:bg-primary/90",children:[e.jsx(oe,{className:"w-4 h-4 mr-2"}),"Send Follow-ups"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 ga
26p-4",children:[e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-blue-100 dark:bg-blue-900 rounded-lg",children:e.jsx(ae,{className:"w-6 h-6 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Quotes"}),e.jsx("p",{className:"text-2xl font-bold",children:i.total})]})]})})}),e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-orange-100 dark:bg-orange-900 rounded-lg",children:e.jsx($e,{className:"w-6 h-6 text-orange-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pending"}),e.jsx("p",{className:"text-2xl font-bold",children:i.pending})]})]})})}),e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-green-100 dark:bg-green-900 rounded-lg",children:e.jsx(Ne,{className:"w-6 h-6 text-green-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Accepted"}),e.jsx("p",{className:"text-2xl font-bold",children:i.accepted})]})]})})}),e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900 rounded-lg",children:e.jsx(Ue,{className:"w-6 h-6 text-red-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Rejected"}),e.jsx("p",{className:"text-2xl font-bold",children:i.rejected})]})]})})}),e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-purple-100 dark:bg-purple-900 rounded-lg",children:e.jsx(re,{className:"w-6 h-6 text-purple-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pipeline Value"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",o.toLocaleString()]})]})]})})})]}),e.jsxs(U,{children:[e.jsxs(te,{children:[e.jsxs(ie,{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"w-5 h-5"}),"Quote Status Overview"]}),e.jsxs(he,{children:["Conversion rate: ",i.total>0?(i.accepted/i.total*100).toFixed(1):0,"%"]})]}),e.jsx(O,{children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[e.jsxs("div",{className:"text-center p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-blue-600",children:i.pending}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Pending"})]}),e.jsxs("div",{className:"text-center p-4 bg-green-50 dark:bg-green-900/20 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-green-600",children:i.accepted}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Accepted"})]}),e.jsxs("div",{className:"text-center p-4 bg-red-50 dark:bg-red-900/20 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-red-600",children:i.rejected}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Rejected"})]}),e.jsxs("div",{className:"text-center p-4 bg-yellow-50 dark:bg-yellow-900/20 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-yellow-600",children:i.expired}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Expired"})]}),e.jsxs("div",{className:"text-center p-4 bg-purple-50 dark:bg-purple-900/20 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-purple-600",children:i.needsFollowUp}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Needs Follow-up"})]})]})})]}),i.needsFollowUp>0&&e.jsxs(U,{className:"border-amber-200 dark:border-amber-800 bg-amber-50 dark:bg-amber-900/10",children:[e.jsxs(te,{children:[e.jsxs(ie,{className:"flex items-center gap-2 text-amber-800 dark:text-amber-400",children:[e.jsx(de,{className:"w-5 h-5"}),"Quotes Requiring Follow-up (",i.needsFollowUp,")"]}),e.jsx(he,{children:"These quotes are older than 48 hours and haven't been accepted yet"})]}),e.jsx(O,{children:e.jsx("div",{className:"space-y-2",children:a.filter(r=>{if(!["draft","sent","revised"].includes(r.status))return!1;const v=new Date(r.created_date),P=new Date(Date.now()-2880*60*1e3);return v<P}).map(r=>{var v;return e.jsxs("div",{className:"flex items-center justify-between p-3 bg-white dark:bg-slate-800 rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:r.customer_name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Quote #",r.quote_number," • $",(v=r.selling_price)==null?void 0:v.toLocaleStr
26ing()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:new Date(r.created_date).toLocaleDateString()}),e.jsx(D,{size:"sm",onClick:()=>window.open(`/quote?id=${r.id}`,"_blank"),children:"View Quote"})]})]},r.id)})})})]}),n?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-slate-800 rounded-full animate-spin"})}):e.jsxs(U,{children:[e.jsxs(te,{children:[e.jsx(ie,{children:"All Quotes"}),e.jsx(he,{children:"Complete history of AI-generated quotes"})]}),e.jsx(O,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-muted/50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-4 font-medium",children:"Quote / Customer"}),e.jsx("th",{className:"text-left p-4 font-medium",children:"Amount"}),e.jsx("th",{className:"text-left p-4 font-medium",children:"Status"}),e.jsx("th",{className:"text-left p-4 font-medium hidden md:table-cell",children:"Created / Activity"}),e.jsx("th",{className:"text-left p-4 font-medium hidden lg:table-cell",children:"Details"}),e.jsx("th",{className:"text-right p-4 font-medium",children:"Actions"})]})}),e.jsx("tbody",{children:a.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"text-center py-12 text-muted-foreground",children:"No quotes yet. Create quotes from the Leads tab."})}):a.map(r=>{var A,I;const v=Ss(r.notes),P=v!=null&&v.last_follow_up_date?new Date(v.last_follow_up_date):null,M=(v==null?void 0:v.follow_up_count)||0;return e.jsxs("tr",{className:"border-b hover:bg-muted/30",children:[e.jsxs("td",{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:r.quote_number}),e.jsx("span",{className:"text-sm font-medium",children:r.customer_name})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"capitalize",children:r.project_type}),r.sqft?` • ${r.sqft} sqft`:""]})]}),e.jsxs("td",{className:"p-4 font-medium",children:["$",((A=r.selling_price)==null?void 0:A.toLocaleString())||"0",r.addon_total>0&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["+$",r.addon_total.toLocaleString()," add-ons"]})]}),e.jsx("td",{className:"p-4",children:e.jsx(B,{variant:r.status==="accepted"?"default":r.status==="rejected"?"destructive":r.status==="expired"?"secondary":"outline",children:r.status})}),e.jsxs("td",{className:"p-4 hidden md:table-cell",children:[e.jsx("div",{children:new Date(r.created_date).toLocaleDateString()}),P?e.jsxs("div",{className:"text-xs text-muted-foreground",children:[M," follow-up",M!==1?"s":""]}):e.jsx("div",{className:"text-xs text-muted-foreground",children:"No activity"})]}),e.jsx("td",{className:"p-4 hidden lg:table-cell",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.customer_signature?e.jsxs(B,{className:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",children:[e.jsx(Ne,{className:"w-3 h-3 mr-1"}),"Signed"]}):e.jsx(B,{variant:"outline",children:"Not Signed"}),((I=r.reserved_slab_ids)==null?void 0:I.length)>0&&e.jsxs(B,{variant:"outline",className:"gap-1",children:[e.jsx(Ds,{className:"w-3 h-3"}),r.reserved_slab_ids.length]})]})}),e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{size:"sm",variant:"outline",onClick:()=>u(r.id),children:e.jsx(as,{className:"w-4 h-4"})}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>m(r.id),children:e.jsx(Ts,{className:"w-4 h-4"})}),e.jsx(D,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-900/20",onClick:()=>N(r),children:e.jsx(Fe,{className:"w-4 h-4"})}),(r.status==="sent"||r.status==="draft"||r.status==="revised"||r.status==="accepted")&&!r.converted_to_job_id&&e.jsxs(D,{size:"sm",variant:"default",onClick:()=>x(r),children:[e.jsx(Pe,{className:"w-4 h-4 mr-1"}),"Convert to Job"]})]})})]},r.id)})})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mt-6",children:[e.jsxs(U,{children:[e.jsxs(te,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ie,{className:"text-sm font-medium",children:"Pending Review"}),e.jsx($e,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(O,{children:[e.jsx("div",{className:"text-2xl font-bold",children:a.filter(r=>["draft","sent"].includes(r.status)).length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Quotes awaiting customer decision"})]})]}),e.jsxs(U,{children:[e.jsxs(te,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ie,{className:"text-sm font-medium",children:"Needs Follow-up"}),e.jsx(de,{className:"h-4 w-4 text-orange-500"})]}),e.jsxs(O,{children:[e.jsx("div",{className:"text-2xl font-bold",children:a.filter(r=>{if(!["draft","sent"].includes(r.status))return!1;const v=new Date(r.created_date);return(Date.now()-v.getTime())/(1e3*60*60)>48}).length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Quotes older than 48 hours"})]})]}),e.jsxs(U,{children:[e.jsxs(te,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ie,{className:"text-sm font-medium",children:"Conversion Rate"}),e.jsx(qe,{className:"h-4 w-4 text-green-500"})]}),e.jsxs(O,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[a.length>0?Math.round(a.filter(r=>r.status==="accepted").length/a.length*100):0,"%"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a.filter(r=>r.status==="accepted").length," of ",a.length," quotes accepted"]})]})]})]})]})}function Zs({open:a,onOpenChange:n,prefillEmail:i="",prefillPhone:o=""}){const d=typeof window<"u"?`${window.location.origin}
26/quick-estimate`:"/quick-estimate",[u,m]=j.useState(i),[N,x]=j.useState(o),[k,r]=j.useState(!1),[v,P]=j.useState(null),M=async()=>{try{await navigator.clipboard.writeText(d),r(!0),T.success("Link copied!"),setTimeout(()=>r(!1),2e3)}catch{T.error("Could not copy link")}},A=async()=>{var f,c;if(!u){T.error("Enter the customer's email first.");return}P("email");try{const p=await z.functions.invoke("sendEmail",{to:u,subject:"Get your free countertop estimate",body:`Hi,
27
28Get an instant countertop estimate in seconds! Just upload your cabinet plan PDF or a photo of your kitchen, and our AI will calculate the price range for you.
29
30Click here to start: ${d}
31
32It's free and there's no obligation. A team member will follow up after you get your estimate.
33
34Best regards,
35The Countertop Team`});if((f=p.data)!=null&&f.success||p.status===200)T.success(`Estimate link emailed to ${u}`),m("");else throw new Error(((c=p.data)==null?void 0:c.error)||"Failed to send")}catch(p){T.error("Failed to send email: "+(p.message||"Unknown error"))}finally{P(null)}},I=async()=>{var f,c;if(!N){T.error("Enter the customer's phone first.");return}P("sms");try{const p=await z.functions.invoke("sendSms",{to:N,body:`Get your free countertop estimate! Upload your cabinet plan or photo and get instant pricing: ${d}`});if((f=p.data)!=null&&f.success||p.status===200)T.success(`Estimate link texted to ${N}`),x("");else throw new Error(((c=p.data)==null?void 0:c.error)||"Failed to send")}catch(p){T.error("Failed to send text: "+(p.message||"Unknown error"))}finally{P(null)}};return e.jsx(Ye,{open:a,onOpenChange:n,children:e.jsxs(Je,{className:"max-w-md",children:[e.jsxs(Ze,{children:[e.jsxs(es,{className:"flex items-center gap-2",children:[e.jsx(ls,{className:"w-5 h-5 text-primary"}),"Send Quick Estimate Link"]}),e.jsx(hs,{children:"Send this link to your customer. They upload their plan or photo, the AI prices it from your live price list, and a new lead appears on your Leads page automatically."})]}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsx(U,{className:"bg-stone-50",children:e.jsxs(O,{className:"py-3 flex items-center gap-2",children:[e.jsx("code",{className:"text-xs flex-1 truncate",children:d}),e.jsxs(D,{size:"sm",variant:"outline",onClick:M,className:"shrink-0",children:[k?e.jsx(ms,{className:"w-3.5 h-3.5 text-green-600"}):e.jsx($s,{className:"w-3.5 h-3.5"}),k?"Copied":"Copy"]})]})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:"Send by email"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{className:"pl-9",type:"email",value:u,onChange:f=>m(f.target.value),placeholder:"[email protected]"})]}),e.jsx(D,{onClick:A,disabled:v==="email",className:"shrink-0",children:v==="email"?e.jsx(ge,{className:"w-4 h-4 animate-spin"}):e.jsx(Be,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:"Send by text"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ye,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{className:"pl-9",value:N,onChange:f=>x(f.target.value),placeholder:"(555) 123-4567"})]}),e.jsx(D,{onClick:I,disabled:v==="sms",variant:"secondary",className:"shrink-0",children:v==="sms"?e.jsx(ge,{className:"w-4 h-4 animate-spin"}):e.jsx(Be,{className:"w-4 h-4"})})]})]})]})]})})}function Ht(){const a=Me(),[n,i]=j.useState(null),[o,d]=j.useState(!1),[u,m]=j.useState(""),[N,x]=j.useState("all"),[k,r]=j.useState(!1),[v,P]=j.useState(null),[M,A]=j.useState("leads"),[I,f]=j.useState("all"),[c,p]=j.useState(""),[E,Q]=j.useState(!1),[h,t]=j.useState({customer_name:"",customer_email:"",customer_phone:"",source:"website",status:"new",project_type:"kitchen",estimated_sqft:"",estimated_value:"",notes:"",follow_up_date:"",assigned_to:"",tags:[]}),g=Ge(),{data:S=[],isLoading:H}=ce({queryKey:["leads"],queryFn:()=>z.entities.Lead.list("-created_date"),staleTime:6e4}),{data:R=[],isLoading:l}=ce({queryKey:["quotes"],queryFn:()=>z.entities.Quote.list("-created_date"),staleTime:6e4}),{data:w=[]}=ce({queryKey:["accounts"],queryFn:()=>z.entities.Account.list(),staleTime:6e4}),y=j.useMemo(()=>{const s=new Map;
35return w.forEach(L=>{L.account_name&&s.set(L.account_name.toLowerCase(),L)}),s},[w]),$={total:R.length,pending:R.filter(s=>["draft","sent"].includes(s.status)).length,accepted:R.filter(s=>s.status==="accepted").length,rejected:R.filter(s=>s.status==="rejected").length,expired:R.filter(s=>s.status==="expired").length,needsFollowUp:R.filter(s=>{if(!["draft","sent","revised"].includes(s.status))return!1;const L=new Date(s.created_date+"T00:00:00"),ne=new Date(Date.now()-2880*60*1e3);return L<ne}).length},q=R.filter(s=>["draft","sent","revised"].includes(s.status)).reduce((s,L)=>s+(L.selling_price||0),0),_=ve({mutationFn:s=>z.entities.Lead.create(s),onSuccess:()=>{g.invalidateQueries({queryKey:["leads"]}),g.invalidateQueries({queryKey:["accounts"]}),r(!1),t({customer_name:"",customer_email:"",customer_phone:"",source:"website",status:"new",project_type:"kitchen",estimated_sqft:"",estimated_value:"",notes:"",follow_up_date:"",assigned_to:"",tags:[]}),T.success("Lead created successfully!")}}),K=ve({mutationFn:({id:s,data:L})=>z.entities.Lead.update(s,L),onSuccess:()=>{g.invalidateQueries({queryKey:["leads"]}),g.invalidateQueries({queryKey:["accounts"]}),T.success("Lead updated successfully!")}}),C=()=>{if(!h.customer_name){T.error("Customer name is required");return}const s=y.get(h.customer_name.toLowerCase());_.mutate({...h,estimated_sqft:parseFloat(h.estimated_sqft)||0,estimated_value:parseFloat(h.estimated_value)||0,account_id:(s==null?void 0:s.id)||null,account_name:(s==null?void 0:s.account_name)||null})},F=ve({mutationFn:s=>z.entities.Lead.delete(s),onSuccess:()=>{g.invalidateQueries({queryKey:["leads"]}),T.success("Lead deleted")},onError:()=>T.error("Failed to delete lead")}),se=s=>{confirm(`Delete lead for ${s.customer_name}? This cannot be undone.`)&&F.mutate(s.id)},me=s=>{if(!s)return null;try{const L=typeof s=="string"&&s.length===10?new Date(s+"T00:00:00"):new Date(s);return isNaN(L.getTime())?null:L.toLocaleDateString()}catch{return null}},Oe=(s,L)=>{K.mutate({id:s,data:{status:L}})},_e=s=>{const L=new URLSearchParams({leadId:s.id,customer_name:s.customer_name,customer_email:s.customer_email||"",customer_phone:s.customer_phone||"",project_type:s.project_type||"kitchen",estimated_sqft:s.estimated_sqft||""});s.account_id&&L.set("account_id",s.account_id),a(`/quote?${L.toString()}`)},Ce=[...new Set(S.flatMap(s=>s.tags||[]))],ue=S.filter(s=>{const L=u.toLowerCase(),ne=(s.customer_name||"").toLowerCase().includes(L)||(s.customer_email||"").toLowerCase().includes(L)||(s.customer_phone||"").includes(L)||(s.assigned_to||"").toLowerCase().includes(L),W=N==="all"||s.status===N,ke=I==="all"||(s.tags||[]).includes(I);return ne&&W&&ke}),le={kitchen:"🏠",bathroom:"🚿",commercial:"🏢",outdoor:"🌳",other:"📋"};return e.jsx("div",{className:"min-h-screen bg-background p-4 sm:p-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsx("div",{className:"mb-6",children:e.jsx(ks,{icon:He,title:"Leads & Quotes",subtitle:"Manage your sales pipeline"})}),e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx(us,{value:M,onValueChange:A,children:e.jsxs(xs,{className:"h-10 rounded-xl",children:[e.jsxs(Qe,{value:"pipeline",className:"text-xs sm:text-sm rounded-lg",children:[e.jsx(je,{className:"w-3 h-3 sm:w-4 sm:h-4 mr-1 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Pipeline"})]}),e.jsxs(Qe,{value:"leads",className:"text-xs sm:text-sm rounded-lg",children:[e.jsx(be,{className:"w-3 h-3 sm:w-4 sm:h-4 mr-1 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Leads"})]}),e.jsxs(Qe,{value:"quotes",className:"text-xs sm:text-sm rounded-lg",children:[e.jsx(ae,{className:"w-3 h-3 sm:w-4 sm:h-4 mr-1 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Quotes"})]})]})}),e.jsxs(D,{variant:"outline",className:"rounded-xl ml-auto",onClick:()=>Q(!0),children:[e.jsx(ls,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Send Estimate Link"}),e.jsx("span",{className:"sm:hidden",children:"Link"})]}),M==="leads"&&e.jsxs(D,{className:"rounded-xl",onClick:()=>r(!0),children:[e.jsx(ze,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Add Lead"}),e.jsx("span",{className:"sm:hidden",children:"Add"})]})]}),M==="pipeline"&&e.jsx(Hs,{}),M==="leads"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(Qs,{onConvertToLead:s=>{_.mutate({...s})}}),e.jsx(Es,{onQuoteCreated:()=>{g.invalidateQueries({queryKey:["quotes"]})}})]}),e.jsx(Rs,{onQuotesCreated:()=>{g.invalidateQueries({queryKey:["quotes"]})}}),e.jsx(Ye,{open:k,onOpenChange:r,children:e.jsxs(Je,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Ze,{children:e.jsx(es,{children:"Add New Lead"})}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Customer Name *"}),e.jsx(V,{value:h.customer_name,onChange:s=>t({...h,customer_name:s.target.value}),placeholder:"John Doe"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Email"}),e.jsx(V,{type:"email",value:h.customer_email,onChange:s=>t({...h,customer_email:s.target.value}),placeholder:"[email protected]"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Phone"}),e.jsx(V,{value:h.customer_phone,onChange:s=>t({...h,customer_phone:s.target.value}),placeholder:"(555) 123-4567"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Source"}),e.jsxs(Y,{value:h.source,onValueChange:s=>t({...h,source:s}),children:[e.jsx(J,{children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(b,{value:"website",children:"Website"}),e.jsx(b,{value:"referral",children:"Referral"}),e.jsx(b,{value:"google",children:"Google"}),e.jsx(b,{value:"social_media",children:"Social Media"}),e.jsx(b,{value:"showroom",children:"Showroom"}),e.jsx(b,{value:"phone",children:"Phone"}),e.jsx(b,{value:"other",children:"Other"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Project Type"}),e.jsxs(Y,{value:h.project_type,onValueChange:s=>t({...h,project_type:s}),children:[e.jsx(J,{children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(b,{value:"kitchen",children:"Kitchen"}),e.jsx(b,{value:"bathroom",children:"Bathroom"}),e.jsx(b,{value:"commercial",children:"Commercial"}),e.jsx(b,{value:"outdoor",children:"Outdoor"}),e.jsx(b,{value:"other",children:"Other"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Status"}),e.jsxs(Y,{value:h.status,onValueChange:s=>t({...h,status:s}),children:[e.jsx(J,{children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(b,{value:"new",children:"New"}),e.jsx(b,{value:"contacted",children:"Contacted"}),e.jsx(b,{value:"measured",children:"Measured"}),e.jsx(b,{value:"quoted",children:"Quoted"}),e.jsx(b,{value:"won",children:"Won"}),e.jsx(b,{value:"lost",children:"Lost"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Estimated Sq Ft"}),e.jsx(V,{type:"number",value:h.estimated_sqft,onChange:s=>t({...h,estimated_sqft:s.target.value}),placeholder:"50"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Estimated Value ($)"}),e.jsx(V,{type:"number",value:h.estimated_value,onChange:s=>t({...h,estimated_value:s.target.value}),placeholder:"5000"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Follow-up Date"}),e.jsx(V,{type:"date",value:h.follow_up_date,onChange:s=>t({...h,follow_up_date:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Assigned To"}),e.jsx(V,{value:h.assigned_to,onChange:s=>t({...h,assigned_to:s.target.value}),placeholder:"Salesperson name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Notes"}),e.jsx(V,{value:h.notes,onChange:s=>t({...h,notes:s.target.value}),placeholder:"Additional notes..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Tags"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(V,{value:c,onChange:s=>p(s.target.value),placeholder:"Add a tag and press Enter",onKeyDown:s=>{s.key==="Enter"&&c.trim()&&(s.preventDefault(),h.tags.includes(c.trim())||t({...h,tags:[...h.tags,c.trim()]}),p(""))}}),e.jsx(D,{type:"button",variant:"outline",size:"sm",onClick:()=>{c.trim()&&!h.tags.includes(c.trim())&&t({...h,tags:[...h.tags,c.trim()]}),p("")},children:e.jsx(ze,{className:"w-4 h-4"})})]}),h.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:h.tags.map(s=>e.jsxs(B,{variant:"secondary",className:"gap-1",children:[s,e.jsx("button",{onClick:()=>t({...h,tags:h.tags.filter(L=>L!==s)}),className:"ml-1 hover:text-destructive",children:e.jsx(Ue,{className:"w-3 h-3"})})]},s))})]}),e.jsx(D,{onClick:C,className:"w-full",children:"Create Lead"})]})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 mb-6",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Xe,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground w-4 h-4"}),e.jsx(V,{placeholder:"Search by name, email, or phone...",value:u,onChange:s=>m(s.target.value),className:"pl-10"})]}),e.jsxs(Y,{value:N,onValueChange:x,children:[e.jsx(J,{className:"w-full sm:w-48",children:e.jsx(Z,{placeholder:"Filter by status"})}),e.jsxs(ee,{children:[e.jsx(b,{value:"all",children:"All Statuses"}),e.jsx(b,{value:"new",children:"New"}),e.jsx(b,{value:"contacted",children:"Contacted"}),e.jsx(b,{value:"measured",children:"Measured"}),e.jsx(b,{value:"quoted",children:"Quoted"}),e.jsx(b,{value:"won",children:"Won"}),e.jsx(b,{value:"lost",children:"Lost"})]})]}),e.jsxs(Y,{value:I,onValueChange:f,children:[e.jsx(J,{className:"w-full sm:w-40",children:e.jsx(Z,{placeholder:"Filter by tag"})}),e.jsxs(ee,{children:[e.jsx(b,{value:"all",children:"All Tags"}),Ce.map(s=>e.jsx(b,{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6",children:[e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-blue-100 dar
35k:bg-blue-900 rounded-lg",children:e.jsx(be,{className:"w-6 h-6 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Leads"}),e.jsx("p",{className:"text-2xl font-bold",children:S.length})]})]})})}),e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-green-100 dark:bg-green-900 rounded-lg",children:e.jsx(Ne,{className:"w-6 h-6 text-green-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Won"}),e.jsx("p",{className:"text-2xl font-bold",children:S.filter(s=>s.status==="won").length})]})]})})}),e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-orange-100 dark:bg-orange-900 rounded-lg",children:e.jsx(ae,{className:"w-6 h-6 text-orange-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Quoted"}),e.jsx("p",{className:"text-2xl font-bold",children:S.filter(s=>s.status==="quoted").length})]})]})})}),e.jsx(U,{children:e.jsx(O,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-purple-100 dark:bg-purple-900 rounded-lg",children:e.jsx(re,{className:"w-6 h-6 text-purple-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pipeline Value"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",S.filter(s=>s.status!=="lost").reduce((s,L)=>s+(L.estimated_value||0),0).toLocaleString()]})]})]})})})]}),H?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx("div",{className:"w-8 h-8 border-4 border-muted border-t-primary rounded-full animate-spin"})}):e.jsx(U,{children:e.jsx(O,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-muted/50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-4 font-medium",children:"Customer"}),e.jsx("th",{className:"text-left p-4 font-medium hidden sm:table-cell",children:"Contact"}),e.jsx("th",{className:"text-left p-4 font-medium hidden sm:table-cell",children:"Account"}),e.jsx("th",{className:"text-left p-4 font-medium",children:"Project"}),e.jsx("th",{className:"text-left p-4 font-medium hidden md:table-cell",children:"Est. Value"}),e.jsx("th",{className:"text-left p-4 font-medium",children:"Status"}),e.jsx("th",{className:"text-left p-4 font-medium hidden md:table-cell",children:"Date Added"}),e.jsx("th",{className:"text-left p-4 font-medium hidden lg:table-cell",children:"Follow-up"}),e.jsx("th",{className:"text-right p-4 font-medium",children:"Actions"})]})}),e.jsx("tbody",{children:ue.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"text-center py-12 text-muted-foreground",children:"No leads found. Add your first lead to get started."})}):ue.map(s=>{var L,ne;return e.jsxs("tr",{className:"border-b hover:bg-muted/30",children:[e.jsxs("td",{className:"p-4",children:[e.jsx("div",{className:"font-medium",children:s.customer_name}),((L=s.tags)==null?void 0:L.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:s.tags.map(W=>e.jsx(B,{variant:"outline",className:"text-xs py-0 px-1.5",children:W},W))}),e.jsx("div",{className:"text-sm text-muted-foreground sm:hidden",children:s.customer_phone})]}),e.jsxs("td",{className:"p-4 hidden sm:table-cell",children:[e.jsx("div",{className:"text-sm",children:s.customer_email}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s.customer_phone})]}),e.jsx("td",{className:"p-4 hidden sm:table-cell",children:s.account_name?e.jsx("a",{href:`/account/${s.account_id}`,className:"text-primary hover:underline text-sm",children:s.account_name}):(()=>{var ke;const W=y.get((ke=s.customer_name)==null?void 0:ke.toLowerCase());return W?e.jsx("a",{href:`/account/${W.id}`,className:"text-primary hover:underline text-sm",children:W.account_name}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"—"})})()}),e.jsxs("td",{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:le[s.project_type]||"📋"}),e.jsx("span",{className:"capitalize",children:s.project_type})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s.estimated_sqft?`${s.estimated_sqft} sqft`:""})]}),e.jsx("td",{className:"p-4 hidden md:table-cell",children:e.jsxs("div",{className:"font-medium",children:["$",((ne=s.estimated_value)==null?void 0:ne.toLocaleStr
35ing())||"0"]})}),e.jsx("td",{className:"p-4",children:e.jsxs(Y,{value:s.status,onValueChange:W=>Oe(s.id,W),children:[e.jsx(J,{className:"w-32",children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(b,{value:"new",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"}),"New"]})}),e.jsx(b,{value:"contacted",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-yellow-500"}),"Contacted"]})}),e.jsx(b,{value:"measured",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-purple-500"}),"Measured"]})}),e.jsx(b,{value:"quoted",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-orange-500"}),"Quoted"]})}),e.jsx(b,{value:"won",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500"}),"Won"]})}),e.jsx(b,{value:"lost",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-red-500"}),"Lost"]})})]})]})}),e.jsx("td",{className:"p-4 hidden md:table-cell",children:me(s.created_date)?e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(fe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{children:me(s.created_date)})]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx("td",{className:"p-4 hidden lg:table-cell",children:s.follow_up_date?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{children:new Date(s.follow_up_date+"T00:00:00").toLocaleDateString()})]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs(D,{size:"sm",variant:"outline",onClick:()=>_e(s),disabled:s.status==="won"||s.status==="lost",children:[e.jsx(ae,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Create Quote"})]}),e.jsx(D,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>se(s),disabled:F.isPending,title:"Delete lead",children:e.jsx(Fe,{className:"w-4 h-4"})})]})})]},s.id)})})]})})})})]}),M==="quotes"&&e.jsx(Js,{quotes:R,isLoadingQuotes:l,quoteStats:$,pipelineValue:q,onSendFollowUps:async()=>{try{await z.functions.invoke("sendQuoteFollowUp",{}),T.success("Follow-up emails sent!"),g.invalidateQueries({queryKey:["quotes"]})}catch{T.error("Failed to send follow-ups")}},onViewQuote:s=>{i(s),d(!0)},onEditQuote:s=>a(`/quote?id=${s}`),onDeleteQuote:async s=>{if(confirm(`Delete quote ${s.quote_number} for ${s.customer_name}?`))try{await z.entities.Quote.delete(s.id),T.success("Quote deleted"),g.invalidateQueries({queryKey:["quotes"]})}catch{T.error("Failed to delete quote")}},onConvertToJob:async s=>{var L,ne;try{s.status!=="accepted"&&await z.entities.Quote.update(s.id,{status:"accepted"});const W=await z.functions.invoke("convertQuoteToJob",{quoteId:s.id});if(!((L=W.data)!=null&&L.success))throw new Error(((ne=W.data)==null?void 0:ne.error)||"Conversion failed");T.success(`Job ${W.data.jobNumber} created!`),g.invalidateQueries({queryKey:["quotes"]}),g.invalidateQueries({queryKey:["jobs"]}),g.invalidateQueries({queryKey:["accounts"]}),g.invalidateQueries({queryKey:["leads"]})}catch(W){T.error("Failed to convert quote: "+((W==null?void 0:W.message)||"Unknown error"))}}}),e.jsx(ps,{quoteId:n,open:o,onOpenChange:d,onQuoteEdited:()=>{g.invalidateQueries({queryKey:["quotes"]})}}),e.jsx(Zs,{open:E,onOpenChange:Q})]})})}export{Ht 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.