1import{r as l,j as e}from"./vendor-react-DKbe1Umz.js";import{a as nt,y as it,u as rt,aM as lt,C as R,s as O,t as z,w as B,v as V,B as x,aX as ot,au as Se,aw as Ae,l as T,m as ct,I as m,k as re,K as _,aO as dt,aP as C,aQ as v,aR as b,aS as w,aT as S,P as mt,O as ut,R as xt,T as pt,o as D,q as ht}from"./index-DZ74KeH3.js";import{a as ke}from"./vendor-data-CjSe2wkl.js";import{a as jt,t as gt,o as ft,s as g,l as yt}from"./vendor-forms-C2vWC2ab.js";import{C as Ie}from"./checkbox-B-BhVsyi.js";import{T as bt,a as Nt,b as Pe,c as k,d as Ct,e as I}from"./table-CAeITjOT.js";import{O as vt,a as wt,b as St}from"./ObjectUploader-BErHjEh8.js";import{C as At}from"./CrmOrganizationSelector-CfmdFwur.js";import{C as kt}from"./calendar-D1tc6ow-.js";import{A as It}from"./ArchetypeSelector-GOxI05Ue.js";import{X as Pt,bz as Te,b5 as de,au as M,O as Z,Y as le,c0 as H,F as oe,cZ as Ee,c1 as K,a_ as ce,J as De,cD as Et,b3 as Dt,k as Lt}from"./vendor-ui-DMaW9-Ov.js";import{a as Le,p as X}from"./vendor-dates-5UNeOyFW.js";import"./vendor-charts-DWX9qznF.js";const Fe=[{id:1,name:"Bid Info",icon:Te,description:"Enter bid information"},{id:2,name:"Upload Documents",icon:de,description:"Upload bid invitation, plans, and specs"},{id:3,name:"AI Review",icon:M,description:"AI analyzes your documents"},{id:4,name:"Confirm Scope",icon:Z,description:"Review and modify SOW items"}],Ft=ft({name:g().min(1,"Bid name is required"),clientName:g().min(1,"Client name is required"),clientContactName:g().optional(),clientContactEmail:g().email().optional().or(yt("")),clientContactPhone:g().optional(),dueDate:g().optional(),locationAddress:g().optional(),city:g().optional(),state:g().optional(),description:g().optional(),gcOrganizationId:g().optional(),ownerRepOrganizationId:g().optional()});function es(){const[,G]=nt(),{user:L}=it(),{toast:f}=rt(),Me=lt(L==null?void 0:L.role),[h,y]=l.useState(1),[N,me]=l.useState([]),[Q,ue]=l.useState(!1),[Tt,Mt]=l.useState(!1),[A,$e]=l.useState(null),[$,qe]=l.useState(void 0),[q,Ue]=l.useState(void 0),[j,W]=l.useState([]),[P,J]=l.useState([]),[ee,xe]=l.useState(""),[pe,he]=l.useState(""),[je,ge]=l.useState(""),[fe,ye]=l.useState(""),[be,Ne]=l.useState(""),[te,Re]=l.useState(null),[se,Oe]=l.useState(null),[$t,qt]=l.useState(null),[Ut,Rt]=l.useState(null),[E,ze]=l.useState(null),c=jt({resolver:gt(Ft),defaultValues:{name:"",clientName:"",clientContactName:"",clientContactEmail:"",clientContactPhone:"",dueDate:"",locationAddress:"",city:"",state:"",description:""}}),Be=l.useCallback(()=>{ue(!0)},[]),Ve=l.useCallback(t=>{ue(!1);const n=t.successful??[],a=t.failed??[];if(a.length>0&&n.length===0){f({title:"Upload failed",description:`${a.length} file(s) could not be uploaded. Please try again.`,variant:"destructive"});return}if(n.length===0)return;const s=n.map((d,p)=>{var o,u,F;return{id:`doc-${Date.now()}-${p}`,name:d.name||d.fileName||`Document ${p+1}`,url:((o=d.uploadURL)==null?void 0:o.split("?")[0])||((F=(u=d.response)==null?void 0:u.uploadURL)==null?void 0:F.split("?")[0])||"",type:d.type||"application/pdf",size:d.size||0}}),i=s.filter(d=>d.url),r=s.length-i.length;i.length>0&&(me(d=>[...d,...i]),f({title:"Documents uploaded",description:`${i.length} file(s) uploaded successfully`})),r>0&&f({title:"Some files had issues",description:`${r} file(s) could not be processed. Please try uploading them again.`,variant:"destructive"})},[f]),_e=t=>{me(n=>n.filter(a=>a.id!==t))},Y=ke({mutationFn:async()=>{const t=await D("POST","/api/ai-bid-wizard/analyze",{documents:N.map(n=>({url:n.url,name:n.name}))});if(!t.ok){const n=await t.json().catch(()=>({error:"Analysis failed"}));throw new Error(n.error||"Failed to analyze documents")}return t.json()},onSuccess:t=>{$e(t),qe(t.scopeDocumentUrl??void 0),Ue(t.analysisId??void 0);const n=(t.scopeItems||[]).map((s,i)=>({...s,id:`ai-${i}`,quantity:typeof s.quantity=="number"&&!isNaN(s.quantity)?s.quantity:null,unit:s.unit||"LS",category:s.category||"GENERAL",csiDivision:s.csiDivision??null,selected:!0,unitMaterialCost:typeof s.unitMaterialCost=="number"&&s.unitMaterialCost>0?s.unitMaterialCost:null,unitLaborCost:typeof s.unitLaborCost=="number"&&s.unitLaborCost>0?s.unitLaborCost:null,aiPrefilledMat:typeof s.unitMaterialCost=="number"&&s.unitMaterialCost>0,aiPrefilledLabor:typeof s.unitLaborCost=="number"&&s.unitLaborCost>0}));W(n);const a=(s,i)=>{if(!i)return;const r=c.getValues(s);(r==null||r==="")&&c.setValue(s,i)};a("name",t.projectName),a("clientName",t.clientName),a("clientContactName",t.clientContactName),a("clientContactEmail",t.clientContactEmail),a("clientContactPhone",t.clientContactPhone),a("dueDate",t.dueDate),a("locationAddress",t.locationAddress),a("city",t.city),a("state",t.state),a("description",t.description),t.aiError?f({title:"AI analysis incomplete",description:t.message||"You can enter information manually.",variant:"default"}):f({title:"Analysis complete",description:`Found ${n.length} scope items`}),y(4)},onError:t=>{ve(t.message||"Failed to analyze documents. You can still proceed manually.")}}),ae=ke({mutationFn:async t=>{const n=[...j.filter(o=>o.selected),...P],a=await D("POST","/api/bids",{...t,estimatorId:L==null?void 0:L.id});if(!a.ok){const o=await a.json().catch(()=>({message:"Failed to create bid"}));throw new Error(o.message||"Failed to create bid")}const s=await a.json();if(E)try{await D("PUT","/api/spec-regime/org-settings",{archetypeId:E.id})}catch{}if(q)try{await D("PATCH",`/api/ai/bid-document-analysis/${q}/link-bid`,{bidCode:s.code})}catch{}if(N.length>0)for(const o of N)try{await D("POST",`/api/bids/${s.code}/documents`,{title:o.name,fileName:o.name,fileUrl:o.url,objectKey:o.url,fileSize:o.size,mimeType:o.type,type:"PLANS"})}catch(u){console.error("Failed to attach document to bid:",o.name,u)}const i=await D("POST",`/api/bids/${s.id}/estimate`);
1if(!i.ok){const o=await i.json().catch(()=>({message:"Failed to create estimate"}));throw new Error(o.message||"Failed to create estimate for bid. Please try again.")}const r=await i.json(),d=["CONCRETE","EXCAVATION","PAVERS","BOLLARDS","GC","OVERHEAD","PROFIT","GENERAL"],p=o=>{if(!o)return"GENERAL";const u=o.toUpperCase();return d.includes(u)?u:"GENERAL"};if(n.length>0&&(r!=null&&r.id)){const o=[];for(const u of n){const F=u.quantity!=null&&Number.isFinite(u.quantity)&&u.quantity>0?u.quantity:1,tt=((u.unitMaterialCost??0)*F).toFixed(2),st=((u.unitLaborCost??0)*F).toFixed(2),at={description:u.description,quantity:F.toString(),unit:u.unit||"EA",category:p(u.category),notes:u.notes,source:"GENERATED",materialCost:tt,laborCost:st,laborHours:"0",equipmentHours:"0",equipmentCost:"0",consumablesCost:"0",subcontractCost:"0",overheadAllocation:"0",profitAllocation:"0",totalCost:"0"};(await D("POST",`/api/estimates/${r.id}/line-items`,at)).ok||o.push(u.description)}if(o.length>0)throw new Error(`Failed to add ${o.length} scope item(s) to estimate. Please add them manually.`)}return s},onSuccess:t=>{ht.invalidateQueries({queryKey:["/api/bids"]}),f({title:"Bid created successfully",description:`Bid ${t.code} has been created with ${j.filter(n=>n.selected).length+P.length} line items`}),G(`/bids/${t.code}?step=2`)},onError:t=>{f({title:"Failed to create bid",description:t.message||"An error occurred",variant:"destructive"})}}),He=t=>{Re(t),t?(c.setValue("gcOrganizationId",t.id),c.setValue("clientName",t.name)):c.setValue("gcOrganizationId",void 0)},Ge=t=>{Oe(t),t&&(c.setValue("clientContactName",`${t.firstName} ${t.lastName}`.trim()),c.setValue("clientContactEmail",t.email||""),c.setValue("clientContactPhone",t.phone||t.mobile||""))},Qe=t=>{W(n=>n.map(a=>a.id===t?{...a,selected:!a.selected}:a))},We=()=>{if(!ee.trim())return;const t=parseFloat(pe),n=Number.isFinite(t)&&t>0?t:1,a=parseFloat(fe),s=parseFloat(be),i={id:`custom-${Date.now()}`,description:ee.trim(),quantity:n,unit:je||"EA",category:"CUSTOM",selected:!0,unitMaterialCost:Number.isFinite(a)&&a>=0?a:null,unitLaborCost:Number.isFinite(s)&&s>=0?s:null};J(r=>[...r,i]),xe(""),he(""),ge(""),ye(""),Ne("")},Ce=(t,n,a)=>{J(s=>s.map(i=>{if(i.id!==t)return i;if(n==="unitMaterialCost"||n==="unitLaborCost"){const r=parseFloat(a),d=n==="unitMaterialCost"?i.unitMaterialCost:i.unitLaborCost;return{...i,[n]:a===""?null:Number.isFinite(r)&&r>=0?r:d}}return{...i,[n]:a}}))},Ye=t=>{J(n=>n.filter(a=>a.id!==t))},Ke=t=>{if(t<h)y(t);else if(t===h+1){if(h===2&&N.length===0){f({title:"Upload required",description:"Please upload at least one document",variant:"destructive"});return}y(t)}},[ne,ve]=l.useState(null),ie=l.useRef(!1);l.useEffect(()=>{h===3&&!Y.isPending&&!A&&!ne&&!ie.current&&(ie.current=!0,Y.mutate())},[h]);const we=()=>{y(4)},U=(t,n,a)=>{W(s=>s.map(i=>{if(i.id!==t)return i;if(n==="quantity"){const r=parseFloat(a);return{...i,quantity:Number.isFinite(r)&&r>0?r:1}}if(n==="unitMaterialCost"||n==="unitLaborCost"){const r=parseFloat(a),d=n==="unitMaterialCost"?i.unitMaterialCost:i.unitLaborCost,p=n==="unitMaterialCost"?"aiPrefilledMat":"aiPrefilledLabor";return{...i,[n]:a===""?null:Number.isFinite(r)?r:d,[p]:!1}}return{...i,[n]:a}}))},Xe=t=>{W(n=>n.map(a=>({...a,selected:t})))},Ze=c.handleSubmit(t=>{ae.mutate(t)},t=>{const n={name:"Bid Name",clientName:"Client Name"},a=Object.keys(t).map(s=>n[s]||s).join(", ");f({title:"Missing required information",description:a?`Please fill in: ${a}`:"Please complete the required fields on the Bid Info step.",variant:"destructive"}),y(1)}),Je=async()=>{if(!await c.trigger(["name","clientName"])){f({title:"Missing required information",description:"Please enter at least a Bid Name and Client Name to continue.",variant:"destructive"});return}y(2)},et=h/Fe.length*100;return Me?e.jsx("div",{className:"min-h-screen bg-background",children:e.jsxs("div",{className:"px-3 sm:px-6 py-4 sm:py-6",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Create New Bid"}),e.jsx("p",{className:"text-muted-foreground",children:"AI-powered bid creation wizard"})]}),e.jsxs(x,{variant:"outline",onClick:()=>G("/bids"),"data-testid":"button-cancel-wizard",children:[e.jsx(Pt,{className:"h-4 w-4 mr-2"}),"Cancel"]})]}),e.jsx(ot,{value:et,className:"h-2 mb-4"}),e.jsx("div",{className:"flex justify-between",children:Fe.map(t=>e.jsxs("div",{className:`flex items-center gap-2 cursor-pointer transition-opacity ${t.id<=h?"opacity-100":"opacity-50"}`,onClick:()=>t.id<h&&y(t.id),"data-testid":`wizard-step-${t.id}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${t.id<h?"bg-primary text-primary-foreground":t.id===h?"bg-primary/20 text-primary border-2 border-primary":"bg-muted text-muted-foreground"}`,children:t.id<h?e.jsx(le,{className:"h-4 w-4"}):e.jsx(t.icon,{className:"h-4 w-4"})}),e.jsxs("div",{className:"hidden md:block",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.description})]})]},t.id))})]}),h===2&&e.jsxs(R,{"data-testid":"step-upload-documents",children:[e.jsxs(O,{children:[e.jsxs(z,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"h-5 w-5"}),"Upload Bid Documents"]}),e.jsx(B,{children:"Upload bid invitation, construction drawings, specifications, and any other relevant documents. Our AI will analyze them to extract scope of work items and project details."})]}),e.jsxs(V,{className:"space-y-6",children:[e.jsx(vt,{fileType:"DOCUMENT",onComplete:Ve,onProcessingStart:Be,allowedFileTypes:[".pdf",".png",".jpg",".jpeg",".doc",".docx",".xls",".xlsx"],maxNumberOfFiles:wt,children:e.jsxs("div",{className:"flex flex-col items-center justify-center p-8 border-2 border-dashed rounded-lg hover:border-primary transition-colors",children:[e.jsx(de,{className:"h-10 w-10 text-muted-foreground mb-4"}),e.jsx("p",{className:"font-medium",children:"Click to upload or drag and drop"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1","data-testid":"hint-batch-upload-limit",children:["PDF, Images, Word, Excel â ",St]})]})}),Q&&e.jsxs("div",{className:"flex items-center gap-3 p-4 rounded-md border bg-muted/30 text-muted-foreground","data-testid":"upload-processing-indicator",children:[e.jsx(H,{className:"h-5 w-5 animate-spin shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Processing your uploadsâ¦"})]}),!Q&&N.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"font-medium",children:["Uploaded Documents (",N.length,")"]}),e.jsx("div",{className:"space-y-2",children:N.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-md border bg-muted/30","data-testid":`uploaded-doc-${t.id}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(oe,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(t.size/1024).toFixed(1)," KB"]}
1)]})]}),e.jsx(x,{variant:"ghost",size:"icon",onClick:()=>_e(t.id),"data-testid":`remove-doc-${t.id}`,children:e.jsx(Ee,{className:"h-4 w-4 text-destructive"})})]},t.id))})]}),e.jsxs("div",{className:"flex justify-between pt-4",children:[e.jsxs(x,{variant:"outline",onClick:()=>y(1),"data-testid":"button-back-to-bid-info",children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Back to Bid Info"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(x,{variant:"outline",onClick:we,"data-testid":"button-skip-analysis",children:"Skip AI Analysis"}),e.jsx(x,{onClick:()=>Ke(3),disabled:N.length===0||Q,"data-testid":"button-analyze-documents",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"h-4 w-4 mr-2 animate-spin"}),"Processingâ¦"]}):e.jsxs(e.Fragment,{children:["Analyze Documents",e.jsx(ce,{className:"h-4 w-4 ml-2"})]})})]})]})]})]}),h===3&&e.jsxs(R,{"data-testid":"step-ai-review",children:[e.jsxs(O,{children:[e.jsxs(z,{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-5 w-5"}),"AI Document Analysis"]}),e.jsx(B,{children:"Our AI is analyzing your documents to extract project details and scope of work items."})]}),e.jsxs(V,{className:"space-y-6",children:[e.jsx("div",{className:"flex flex-col items-center justify-center py-12",children:ne?e.jsxs(e.Fragment,{children:[e.jsx(De,{className:"h-12 w-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-medium",children:"AI Analysis Failed"}),e.jsxs(Se,{variant:"destructive",className:"max-w-md mt-4",children:[e.jsx(De,{className:"h-4 w-4"}),e.jsx(Ae,{children:ne})]}),e.jsx("p",{className:"text-muted-foreground text-center max-w-md mt-4",children:"You can still create your bid by entering scope items and details manually. Click below to proceed to manual entry."}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsxs(x,{variant:"outline",onClick:()=>{ve(null),ie.current=!1,Y.mutate()},"data-testid":"button-retry-analysis",children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"Retry Analysis"]}),e.jsxs(x,{onClick:()=>y(4),"data-testid":"button-proceed-manual",children:[e.jsx(oe,{className:"h-4 w-4 mr-2"}),"Proceed to Manual Entry"]})]})]}):Y.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"h-12 w-12 animate-spin text-primary mb-4"}),e.jsx("h3",{className:"text-lg font-medium",children:"Analyzing Documents..."}),e.jsx("p",{className:"text-muted-foreground text-center max-w-md mt-2",children:"AI is reading your documents to extract project information, scope items, and key requirements. This may take a minute."}),e.jsx("div",{className:"flex gap-2 mt-6",children:N.map((t,n)=>e.jsxs(T,{variant:"outline",className:"flex items-center gap-1",children:[e.jsx(oe,{className:"h-3 w-3"}),t.name.length>20?t.name.substring(0,20)+"...":t.name]},t.id))})]}):e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"h-12 w-12 animate-spin text-primary mb-4"}),e.jsx("h3",{className:"text-lg font-medium",children:"Starting Analysis..."}),e.jsxs("p",{className:"text-muted-foreground text-center max-w-md mt-2",children:["Preparing to analyze your ",N.length," document(s)..."]})]})}),e.jsxs("div",{className:"flex justify-between pt-4",children:[e.jsxs(x,{variant:"outline",onClick:()=>y(2),"data-testid":"button-back-to-upload",children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Back"]}),e.jsxs(x,{variant:"outline",onClick:we,"data-testid":"button-skip-to-scope",children:["Skip to Scope Entry",e.jsx(ce,{className:"h-4 w-4 ml-2"})]})]})]})]}),h===4&&e.jsxs(R,{"data-testid":"step-confirm-scope",children:[e.jsxs(O,{children:[e.jsxs(z,{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5"}),"Confirm Scope of Work"]}),e.jsx(B,{children:"Review the AI-extracted scope items, modify as needed, and add your own items."})]}),e.jsxs(V,{className:"space-y-6",children:[A&&e.jsxs(Se,{className:"bg-primary/5 border-primary/20",children:[e.jsx(M,{className:"h-4 w-4"}),e.jsx(Ae,{children:e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("span",{children:["AI found ",e.jsx("strong",{children:j.length})," scope items across"," ",e.jsx("strong",{children:new Set(j.map(t=>
1t.csiDivision).filter(Boolean)).size})," CSI divisions.",A.keyRequirements&&A.keyRequirements.length>0&&e.jsxs("span",{className:"block mt-1 text-xs",children:["Key requirements: ",A.keyRequirements.slice(0,3).join(", ")]})]}),(q||$)&&e.jsxs(x,{size:"sm",variant:"outline",className:"h-7 gap-1 text-xs shrink-0",onClick:async()=>{try{if(q){const t=await fetch(`/api/ai-bid-wizard/analyses/${q}/scope-document`,{credentials:"include"});if(t.ok){const{url:n}=await t.json();window.open(n,"_blank");return}}$&&window.open($,"_blank")}catch{$&&window.open($,"_blank")}},"data-testid":"button-view-scope-document",children:[e.jsx(Et,{className:"h-3.5 w-3.5"}),"View Scope Document"]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium",children:j.length>0?"AI-Extracted Items (by CSI Division)":"Scope Items"}),e.jsxs(T,{variant:"outline",children:[j.filter(t=>t.selected).length+P.length," selected"]})]}),j.length>0?(()=>{const t=j.reduce((a,s)=>{const i=s.csiDivision||"Uncategorized";return a[i]||(a[i]=[]),a[i].push(s),a},{}),n=Object.keys(t).sort((a,s)=>a==="Uncategorized"?1:s==="Uncategorized"?-1:a.localeCompare(s));return e.jsx(ct,{className:"h-[380px] rounded-md border",children:e.jsxs("div",{className:"p-1",children:[e.jsxs("div",{className:"flex items-center px-3 py-2 border-b",children:[e.jsx(Ie,{checked:j.length>0&&j.every(a=>a.selected),onCheckedChange:a=>Xe(!!a),"data-testid":"checkbox-select-all"}),e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"Select all"})]}),n.map(a=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1.5 bg-muted/40 border-y text-xs font-semibold text-muted-foreground uppercase tracking-wide","data-testid":`division-header-${a}`,children:a}),e.jsxs(bt,{children:[e.jsx(Nt,{children:e.jsxs(Pe,{children:[e.jsx(k,{className:"w-10"}),e.jsx(k,{children:"Description"}),e.jsx(k,{className:"w-24",children:"Quantity"}),e.jsx(k,{className:"w-16",children:"Unit"}),e.jsx(k,{className:"w-28",children:"Category"}),e.jsx(k,{className:"w-28",children:"Unit Mat. $"}),e.jsx(k,{className:"w-28",children:"Unit Labor $"}),e.jsx(k,{className:"w-28 text-right",children:"AI Est. Total"})]})}),e.jsx(Ct,{children:t[a].map(s=>{const i=s.quantity!=null&&Number.isFinite(s.quantity)&&s.quantity>0?s.quantity:1,r=((s.unitMaterialCost??0)+(s.unitLaborCost??0))*i,d=s.unitMaterialCost!=null||s.unitLaborCost!=null;return e.jsxs(Pe,{"data-testid":`scope-item-${s.id}`,children:[e.jsx(I,{className:"w-10",children:e.jsx(Ie,{checked:s.selected,onCheckedChange:()=>Qe(s.id),"data-testid":`checkbox-${s.id}`})}),e.jsxs(I,{children:[e.jsx(m,{className:"h-7 text-sm font-medium",value:s.description,onChange:p=>U(s.id,"description",p.target.value),"data-testid":`input-desc-${s.id}`}),s.notes&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 pl-0.5",children:s.notes})]}),e.jsx(I,{children:e.jsx(m,{type:"number",className:"h-7 w-20 text-sm",value:s.quantity??"",placeholder:"â",onChange:p=>U(s.id,"quantity",p.target.value),"data-testid":`input-qty-${s.id}`})}),e.jsx(I,{children:e.jsx(m,{className:"h-7 w-16 text-sm",value:s.unit,onChange:p=>U(s.id,"unit",p.target.value),"data-testid":`input-unit-${s.id}`})}),e.jsx(I,{children:e.jsx("span",{className:"text-xs text-muted-foreground","data-testid":`text-category-${s.id}`,children:s.category||"GENERAL"})}),e.jsx(I,{children:e.jsxs("div",{className:"relative inline-flex items-center",children:[e.jsx(m,{type:"number",min:"0",step:"0.01",className:re("h-7 w-24 text-sm",s.aiPrefilledMat&&"bg-amber-50 dark:bg-amber-950/40 border-amber-300 dark:border-amber-700 pr-6"),value:s.unitMaterialCost??"",placeholder:d?"0.00":"â",onChange:p=>U(s.id,"unitMaterialCost",p.target.value),"data-testid":`input-mat-cost-${s.id}`,title:s.aiPrefilledMat?"AI-estimated â edit to confirm":void 0}),s.aiPrefilledMat&&e.jsx(M,{className:"absolute right-1.5 h-3 w-3 text-amber-500 pointer-events-none","data-testid":`ai-badge-mat-${s.id}`})]})}),e.jsx(I,{children:e.jsxs("div",{className:"relative inline-flex items-center",children:[e.jsx(m,{type:"number",min:"0",step:"0.01",className:re("h-7 w-24 text-sm",s.aiPrefilledLabor&&"bg-amber-50 dark:bg-amber-950/40 border-amber-300 dark:border-amber-700 pr-6"),value:s.unitLaborCost??"",placeholder:d?"0.00":"â",onChange:p=>U(s.id,"unitLaborCost",p.target.value),"data-testid":`input-labor-cost-${s.id}`,title:s.aiPrefilledLabor?"AI-estimated â edit to confirm":void 0}),s.aiPrefilledLabor&&e.jsx(M,{className:"absolute right-1.5 h-3 w-3 text-amber-500 pointer-events-none","data-testid":`ai-badge-labor-${s.id}`})]})}),e.jsx(I,{className:"text-right",children:d?e.jsx("span",{className:"text-sm font-medium","data-testid":`ai-est-${s.id}
1`,children:r.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0})}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"})})]},s.id)})})]})]},a))]})})})():e.jsxs("div",{className:"text-center py-8 border rounded-md bg-muted/30",children:[e.jsx(Z,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"No AI-extracted items. Add your own below."})]}),P.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"Your Custom Items"}),e.jsx("div",{className:"space-y-2",children:P.map(t=>{const n=typeof t.quantity=="number"&&t.quantity>0?t.quantity:1,a=((t.unitMaterialCost??0)+(t.unitLaborCost??0))*n,s=t.unitMaterialCost!=null||t.unitLaborCost!=null;return e.jsxs("div",{className:"p-3 rounded-md border bg-muted/30 space-y-2","data-testid":`custom-item-${t.id}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(le,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("span",{className:"font-medium",children:t.description}),e.jsxs(T,{variant:"outline",children:[t.quantity," ",t.unit]})]}),e.jsx(x,{variant:"ghost",size:"icon",onClick:()=>Ye(t.id),"data-testid":`remove-custom-${t.id}`,children:e.jsx(Ee,{className:"h-4 w-4 text-destructive"})})]}),e.jsxs("div",{className:"flex items-center gap-3 pl-7",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"Unit Mat. $"}),e.jsx(m,{type:"number",min:"0",step:"0.01",className:"h-7 w-24 text-sm",value:t.unitMaterialCost??"",placeholder:"0.00",onChange:i=>Ce(t.id,"unitMaterialCost",i.target.value),"data-testid":`input-custom-mat-cost-${t.id}`})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"Unit Labor $"}),e.jsx(m,{type:"number",min:"0",step:"0.01",className:"h-7 w-24 text-sm",value:t.unitLaborCost??"",placeholder:"0.00",onChange:i=>Ce(t.id,"unitLaborCost",i.target.value),"data-testid":`input-custom-labor-cost-${t.id}`})]}),s&&e.jsxs("span",{className:"text-sm font-medium ml-2","data-testid":`custom-ai-est-${t.id}`,children:["Est. ",a.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0})]})]})]},t.id)})})]}),e.jsx(_,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium text-sm",children:"Add Custom Scope Item"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(m,{placeholder:"Description",value:ee,onChange:t=>xe(t.target.value),className:"flex-1 min-w-40","data-testid":"input-custom-description"}),e.jsx(m,{placeholder:"Qty",type:"number",value:pe,onChange:t=>he(t.target.value),className:"w-20","data-testid":"input-custom-quantity"}),e.jsx(m,{placeholder:"Unit",value:je,onChange:t=>ge(t.target.value),className:"w-20","data-testid":"input-custom-unit"}),e.jsx(m,{placeholder:"Unit Mat. $",type:"number",min:"0",step:"0.01",value:fe,onChange:t=>ye(t.target.value),className:"w-28","data-testid":"input-custom-mat-cost"}),e.jsx(m,{placeholder:"Unit Labor $",type:"number",min:"0",step:"0.01",value:be,onChange:t=>Ne(t.target.value),className:"w-28","data-testid":"input-custom-labor-cost"}),e.jsx(x,{onClick:We,"data-testid":"button-add-custom-item",children:e.jsx(Dt,{className:"h-4 w-4"})})]})]})]}),(()=>{if(j.filter(a=>a.selected&&(a.unitMaterialCost!=null||a.unitLaborCost!=null)).length===0)return null;const n=j.filter(a=>a.selected).reduce((a,s)=>{const i=s.quantity??0;return a+((s.unitMaterialCost??0)+(s.unitLaborCost??0))*i},0);return e.jsx("div",{className:"flex justify-center pt-2 pb-1",children:e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"text-estimated-total",children:["Estimated Total:"," ",e.jsx("span",{className:"font-semibold text-foreground",children:new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(n)})]})})})(),e.jsxs("div",{className:"flex justify-between pt-4",children:[e.jsxs(x,{variant:"outline",onClick:()=>y(3),"data-testid":"button-back-to-ai-review",children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Back to AI Review"]}),e.jsx(x,{onClick:()=>Ze(),disabled:ae.isPending,"data-testid":"button-create-bid",children:ae.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"h-4 w-4 mr-2"}),"Create Bid & Start Takeoff"]})})]})]})]}),h===1&&e.jsxs(R,{"data-testid":"step-bid-details",children:[e.jsxs(O,{children:[e.jsxs(z,{className:"flex items-center gap-2",children:[e.jsx(Te,{className:"h-5 w-5"}),"Bid Details"]}
1),e.jsx(B,{children:"Enter the bid information. Some fields may be pre-filled from AI analysis."})]}),e.jsx(V,{children:e.jsx(dt,{...c,children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(C,{control:c.control,name:"name",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"Bid Name *"}),e.jsx(w,{children:e.jsx(m,{placeholder:"e.g., City Hall Renovation",...t,"data-testid":"input-bid-name"})}),e.jsx(S,{})]})}),e.jsx(C,{control:c.control,name:"dueDate",render:({field:t})=>e.jsxs(v,{className:"flex flex-col",children:[e.jsx(b,{className:"mt-[5px] mb-[5px]",children:"Due Date"}),e.jsxs(mt,{children:[e.jsx(ut,{asChild:!0,children:e.jsx(w,{children:e.jsxs(x,{variant:"outline",className:re("w-full pl-3 text-left font-normal",!t.value&&"text-muted-foreground"),"data-testid":"input-due-date",children:[t.value&&!isNaN(X(t.value).getTime())?Le(X(t.value),"PPP"):"Pick a date",e.jsx(Lt,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(xt,{className:"w-auto p-0",align:"start",children:e.jsx(kt,{mode:"single",selected:t.value&&!isNaN(X(t.value).getTime())?X(t.value):void 0,onSelect:n=>t.onChange(n?Le(n,"yyyy-MM-dd"):""),initialFocus:!0})})]}),e.jsx(S,{})]})})]}),e.jsx(_,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-medium",children:"Client Information"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Select from CRM (optional)"}),e.jsx(At,{value:te==null?void 0:te.id,onSelect:He,selectedContactId:se==null?void 0:se.id,onContactSelect:Ge,filterTypes:["CONTRACTOR"],placeholder:"Search for client organization..."})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(C,{control:c.control,name:"clientName",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"Client Name *"}),e.jsx(w,{children:e.jsx(m,{placeholder:"Client company name",...t,"data-testid":"input-client-name"})}),e.jsx(S,{})]})}),e.jsx(C,{control:c.control,name:"clientContactName",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"Contact Name"}),e.jsx(w,{children:e.jsx(m,{placeholder:"Primary contact",...t,"data-testid":"input-contact-name"})}),e.jsx(S,{})]})}),e.jsx(C,{control:c.control,name:"clientContactEmail",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"Contact Email"}),e.jsx(w,{children:e.jsx(m,{type:"email",placeholder:"[email protected]",...t,"data-testid":"input-contact-email"})}),e.jsx(S,{})]})}),e.jsx(C,{control:c.control,name:"clientContactPhone",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"Contact Phone"}),e.jsx(w,{children:e.jsx(m,{placeholder:"(555) 123-4567",...t,"data-testid":"input-contact-phone"})}),e.jsx(S,{})]})})]})]}),e.jsx(_,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-medium",children:"Location"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(C,{control:c.control,name:"locationAddress",render:({field:t})=>e.jsxs(v,{className:"md:col-span-3",children:[e.jsx(b,{children:"Address"}),e.jsx(w,{children:e.jsx(m,{placeholder:"Street address",...t,"data-testid":"input-address"})}),e.jsx(S,{})]})}),e.jsx(C,{control:c.control,name:"city",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"City"}),e.jsx(w,{children:e.jsx(m,{placeholder:"City",...t,"data-testid":"input-city"})}),e.jsx(S,{})]})}),e.jsx(C,{control:c.control,name:"state",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"State"}),e.jsx(w,{children:e.jsx(m,{placeholder:"State",...t,"data-testid":"input-state"})}),e.jsx(S,{})]})})]})]}),e.jsx(_,{}),e.jsx(C,{control:c.control,name:"description",render:({field:t})=>e.jsxs(v,{children:[e.jsx(b,{children:"Description / Notes"}),e.jsx(w,{children:e.jsx(pt,{placeholder:"Additional notes about this bid...",className:"min-h-[100px]",...t,"data-testid":"input-description"})}),e.jsx(S,{})]})}),e.jsx(_,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:"Contractor Archetype"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select your firm's profile to pre-populate default units, waste factors, and reconciliation rules. You can override any setting per project."})]}),E&&e.jsx(T,{variant:"outline",className:"ml-2 flex-shrink-0",children:E.name})]}
1),e.jsx(It,{selectedCode:E==null?void 0:E.code,onSelect:t=>ze(n=>(n==null?void 0:n.code)===t.code?null:t),compact:!0})]}),e.jsxs("div",{className:"border rounded-md p-4 bg-muted/30 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4"}),"Scope Summary"]}),e.jsxs(T,{variant:"outline","data-testid":"badge-scope-total",children:[j.filter(t=>t.selected).length+P.length," items"]})]}),(()=>{const t=[...j.filter(s=>s.selected),...P],n={};t.forEach(s=>{const i=s.category||"GENERAL";n[i]=(n[i]||0)+1});const a=Object.entries(n).sort((s,i)=>i[1]-s[1]);return a.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(([s,i])=>e.jsxs(T,{variant:"secondary",className:"text-xs","data-testid":`badge-category-${s}`,children:[s,": ",i]},s))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No scope items selected."})})(),(A==null?void 0:A.estimatedValue)&&e.jsxs("div",{className:"flex items-center gap-2 pt-1 border-t",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Estimated Project Value:"}),e.jsxs("span",{className:"text-sm font-semibold","data-testid":"text-estimated-value",children:["$",A.estimatedValue.toLocaleString()]})]})]}),e.jsxs("div",{className:"flex justify-between pt-4",children:[e.jsxs(x,{type:"button",variant:"outline",onClick:()=>G("/bids"),"data-testid":"button-back-to-bids",children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Back to Bids"]}),e.jsxs(x,{type:"button",onClick:Je,"data-testid":"button-continue-to-upload",children:["Continue to Upload",e.jsx(ce,{className:"h-4 w-4 ml-2"})]})]})]})})})]})]})}):e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsxs(R,{className:"max-w-md",children:[e.jsxs(O,{children:[e.jsx(z,{children:"Access Restricted"}),e.jsx(B,{children:"You do not have permission to create new bids. Please contact your administrator if you need this access."})]}),e.jsx(V,{children:e.jsx(x,{onClick:()=>G("/bids"),"data-testid":"button-back-to-bids",children:"Back to Bids"})})]})})}export{es 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.