1import{M as ks,u as As,i as Ts,g as Os,r,s as B,e as X,j as e,C as P,d as D,B as o,N as zs,L as i,I as l,ai as h,T as f,a as Ls,b as Es,v as Bs,w as Ms,x as Us,y as Fs,z as de,H as qs}from"./index-CKuJyNNt.js";import{B as Vs,D as is,F as os}from"./field-report-data-4ctpyQAt.js";import{P as Hs}from"./progress-BnEOpLK7.js";import{C as Gs}from"./ClientAutocomplete-DXETS1kE.js";import{S as $s}from"./save-7g_gm8oK.js";import{A as Qs}from"./arrow-right-DfEeQx94.js";import{P as x}from"./plus-JCEVnDWl.js";import{U as Ws}from"./upload-DAIg7XnP.js";import{I as Ys}from"./image-CPdLzG9L.js";import"./checkbox-GXAu5pl0.js";const me=()=>crypto.randomUUID(),Js=N=>{const w=["Report Type","Project & Client","Visit Details"];return N==="iaq_report"?[...w,"Executive Summary","Sampling Data","Recommendations","Review"]:N==="construction_observation"?[...w,"Observations","Recommendations","Photos","Review"]:N==="environmental_field_report"?[...w,"Observations","Damages & Recommendations","Photos","Review"]:[...w,"Observations","Progress & Discussion","Photos","Review"]},it=()=>{const{id:N}=ks(),w=As(),{user:he}=Ts(),[cs]=Os(),Z=cs.get("client_id"),I=!!N,[c,xe]=r.useState("architecture_field_report"),[R,ue]=r.useState(0),[pe,je]=r.useState(!1),[ds,ms]=r.useState(I),[ee,ge]=r.useState(""),[se,ve]=r.useState(""),[te,F]=r.useState(""),[ae,q]=r.useState(null),[ne,fe]=r.useState(""),[Ne,be]=r.useState(""),[ye,Ce]=r.useState(""),[_e,Se]=r.useState(""),[we,Re]=r.useState(""),[Pe,De]=r.useState(""),[re,Ie]=r.useState(1),[le,ke]=r.useState(""),[Ae,Te]=r.useState(new Date().toISOString().slice(0,10)),[Oe,ze]=r.useState(""),[Le,Ee]=r.useState(""),[Be,Me]=r.useState(""),[ie,Ue]=r.useState(""),[k,V]=r.useState([""]),[A,H]=r.useState([""]),[Fe,qe]=r.useState(""),[u,b]=r.useState([{id:me(),text:"",subItems:[]}]),[M,G]=r.useState(Vs.map(s=>({name:s,observations:[""]}))),[v,T]=r.useState([{priority:"High",deficiency:"",recommendation:""}]),[O,$]=r.useState([""]),[z,Q]=r.useState([""]),[L,W]=r.useState([""]),[y,E]=r.useState([{location:"",description:"",measurement:""}]),[Ve,He]=r.useState(""),[Ge,$e]=r.useState(""),[Qe,We]=r.useState(""),[Ye,Je]=r.useState(""),[p,C]=r.useState([{sampleId:"",location:"",sampleType:"",concentration:"",sporeTypes:""}]),[j,_]=r.useState([{location:"",temp:"",humidity:"",co2:"",co:""}]),[Ke,Xe]=r.useState(is),[U,Y]=r.useState([]),[oe,Ze]=r.useState(!1),[hs,xs]=r.useState([]);r.useEffect(()=>{B.from("clients").select("id, name, company").then(({data:s})=>{if(xs(s||[]),Z&&!I&&s){const n=s.find(t=>t.id===Z);n&&(q(n.id),F(n.name))}})},[Z,I]),r.useEffect(()=>{I&&(async()=>{var a,d,m,S,K,ss,ts,as,ns,rs,ls;const{data:s,error:n}=await B.from("field_reports").select("*").eq("id",N).single();if(n||!s){X.error("Report not found"),w("/field-reports");return}const t=s;xe(t.report_type),ge(t.project_name||""),ve(t.project_number||""),F(t.client_name||""),q(t.client_id),fe(t.facility_name||""),be(t.facility_address||""),Ce(t.general_contractor||""),Se(t.project_owner||""),Re(t.program_manager||""),De(t.remediation_contractor||""),Ie(t.report_number||1),ke(t.site_visit_date||""),Te(t.report_date||""),ze(t.date_of_loss||""),Ee(t.dates_covered||""),Me(t.weather_conditions||""),Ue(t.report_by||""),V((a=t.ghp_representatives)!=null&&a.length?t.ghp_representatives:[""]),H((d=t.others_present)!=null&&d.length?t.others_present:[""]),qe(t.background_info||""),(m=t.observations)!=null&&m.length&&b(t.observations),(S=t.building_systems)!=null&&S.length&&G(t.building_systems),(K=t.recommendations)!=null&&K.length&&(typeof t.recommendations[0]=="string"?$(t.recommendations):T(t.recommendations)),(ss=t.planned_progress)!=null&&ss.length&&Q(t.planned_progress),(ts=t.additional_discussion)!=null&&ts.length&&W(t.additional_discussion),(as=t.damages_measurements)!=null&&as.length&&E(t.damages_measurements),He(t.re_line||""),$e(t.executive_summary||""),We(t.limitations||""),Je(t.methodology||""),(ns=t.sampling_data)!=null&&ns.length&&C(t.sampling_data),(rs=t.iaq_readings)!=null&&rs.length&&_(t.iaq_readings),Xe(t.disclaimer||is),(ls=t.photos)!=null&&ls.length&&Y(t.photos),ms(!1)})()},[N]);const J=Js(c),us=(R+1)/J.length*100,ps=()=>({report_type:c,created_by:he.id,report_number:re,project_name:ee,project_number:se,client_name:te,client_id:ae,facility_name:ne,facility_address:Ne,general_contractor:ye,project_owner:_e,program_manager:we,remediation_contractor:Pe,report_by:ie,ghp_representatives:k.filter(
1Boolean),others_present:A.filter(Boolean),site_visit_date:le||null,report_date:Ae||null,date_of_loss:Oe||null,dates_covered:Le,weather_conditions:Be,background_info:Fe,observations:u,building_systems:M,recommendations:c==="construction_observation"?v:O.filter(Boolean),planned_progress:z.filter(Boolean),additional_discussion:L.filter(Boolean),damages_measurements:y,re_line:Ve,executive_summary:Ge,limitations:Qe,methodology:Ye,sampling_data:p,iaq_readings:j,disclaimer:Ke,photos:U}),es=async(s=!0)=>{je(!0);const n=ps();s||(n.status="in_review");let t;if(I){const{created_by:a,...d}=n;({error:t}=await B.from("field_reports").update(d).eq("id",N))}else({error:t}=await B.from("field_reports").insert(n));if(je(!1),t){X.error("Save failed: "+t.message);return}X.success(s?"Draft saved":"Submitted for review"),w("/field-reports")};if(ds)return e.jsx("div",{className:"flex min-h-screen items-center justify-center",children:e.jsx("div",{className:"animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"})});const js=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold mb-1",children:"Choose Report Type"}),e.jsx("p",{className:"text-muted-foreground",children:"Select the type of field report."})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:os.map(s=>e.jsxs("button",{onClick:()=>xe(s.id),className:`text-left p-4 rounded-lg border-2 transition-all hover:shadow-md ${c===s.id?"border-primary bg-primary/5":"border-border hover:border-primary/30"}`,children:[e.jsx("div",{className:"text-2xl mb-2",children:s.icon}),e.jsx("h3",{className:"font-semibold text-sm mb-1",children:s.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.description})]},s.id))})]}),gs=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Project & Client"}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(i,{children:"Project Name"}),e.jsx(l,{value:ee,onChange:s=>ge(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Project Number"}),e.jsx(l,{value:se,onChange:s=>ve(s.target.value)})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(i,{children:"Client"}),e.jsx(Gs,{clients:hs,value:ae,onSelect:s=>{if(!s){q(null);return}q(s.client.id),F(s.client.name)},placeholder:"Search or select a clientâ¦"}),!ae&&e.jsx(l,{className:"mt-2",placeholder:"Client name",value:te,onChange:s=>F(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Facility / Site Name"}),e.jsx(l,{value:ne,onChange:s=>fe(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Facility Address"}),e.jsx(l,{value:Ne,onChange:s=>be(s.target.value)})]}),(c==="architecture_field_report"||c==="construction_observation")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(i,{children:"General Contractor"}),e.jsx(l,{value:ye,onChange:s=>Ce(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Project Owner"}),e.jsx(l,{value:_e,onChange:s=>Se(s.target.value)})]})]}),c==="construction_observation"&&e.jsxs("div",{children:[e.jsx(i,{children:"Program Manager"}),e.jsx(l,{value:we,onChange:s=>Re(s.target.value)})]}),c==="environmental_field_report"&&e.jsxs("div",{children:[e.jsx(i,{children:"Remediation Contractor"}),e.jsx(l,{value:Pe,onChange:s=>De(s.target.value)})]}),c==="iaq_report"&&e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(i,{children:"RE Line"}),e.jsx(l,{value:Ve,onChange:s=>He(s.target.value),placeholder:"e.g. Indoor Air Quality Assessment â Building Name"})]})]})]}),vs=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Visit Details"}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(i,{children:"Report Number"}),e.jsx(l,{type:"number",min:1,value:re,onChange:s=>Ie(Number(s.target.value))})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Report By"}),e.jsx(l,{value:ie,onChange:s=>Ue(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Site Visit Date"}),e.jsx(l,{type:"date",value:le,onChange:s=>ke(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Report Date"}),e.jsx(l,{type:"date",value:Ae,onChange:s=>Te(s.target.value)})]}),c==="environmental_field_report"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(i,{children:"Date of Loss"}),e.jsx(l,{type:"date",value:Oe,onChange:s=>ze(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Dates Covered"}),e.jsx(l,{value:Le,onChange:s=>Ee(s.target.value),placeholder:"e.g. 01/15/2026 â 01/17/2026"})]})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Weather Conditions"}),e.jsx(l,{value:Be,onChange:s=>Me(s.target.value)})]})]}),e.jsxs("div",{children:[e.jsx(i,{children:"GHP Representatives"}),k.map((s,n)=>e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(l,{value:s,onChange:t=>{const a=[...k];a[n]=t.target.value,V(a)},placeholder:"Name, Title"}),k.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>V(k.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]},n)),e.jsxs(o,{variant:"outline",size:"sm",className:"mt-2 gap-1",onClick:()=>V([...k,""]),children:[e.jsx(x,{className:"h-3 w-3"}),"Add"]})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Others Present"}),A.map((s,n)=>e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(l,{value:s,onChange:t=>{const a=[...A];a[n]=t.target.value,H(a)},placeholder:"Name, Company"}),A.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>H(A.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]},n)),e.jsxs(o,{variant:"outline",size:"sm",className:"mt-2 gap-1",onClick:()=>H([...A,""]),children:[e.jsx(x,{className:"h-3 w-3"}),"Add"]})]}),(c==="construction_observation"||c==="environmental_field_report")&&e.jsxs("div",{children:[e.jsx(i,{children:"Backgroun
1d Information"}),e.jsx(f,{rows:4,value:Fe,onChange:s=>qe(s.target.value)})]})]}),fs=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Observations"}),u.map((s,n)=>e.jsx(P,{children:e.jsxs(D,{className:"pt-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-bold text-muted-foreground",children:[n+1,"."]}),e.jsx(l,{value:s.text,onChange:t=>{const a=[...u];a[n]={...s,text:t.target.value},b(a)},placeholder:"Observation",className:"flex-1"}),u.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>b(u.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]}),s.subItems.map((t,a)=>e.jsxs("div",{className:"flex items-center gap-2 pl-8",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[String.fromCharCode(97+a),"."]}),e.jsx(l,{value:t,onChange:d=>{const m=[...u];m[n].subItems[a]=d.target.value,b(m)},className:"flex-1"}),e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>{const d=[...u];d[n].subItems=d[n].subItems.filter((m,S)=>S!==a),b(d)},children:e.jsx(h,{className:"h-3 w-3"})})]},a)),e.jsxs(o,{variant:"outline",size:"sm",className:"ml-8 gap-1",onClick:()=>{const t=[...u];t[n].subItems=[...t[n].subItems,""],b(t)},children:[e.jsx(x,{className:"h-3 w-3"}),"Sub-item"]})]})},s.id)),e.jsxs(o,{variant:"outline",className:"gap-1",onClick:()=>b([...u,{id:me(),text:"",subItems:[]}]),children:[e.jsx(x,{className:"h-4 w-4"}),"Add Observation"]})]}),Ns=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Building System Observations"}),M.map((s,n)=>e.jsxs(P,{children:[e.jsx(Ls,{className:"pb-2",children:e.jsx(Es,{className:"text-base",children:s.name})}),e.jsxs(D,{className:"space-y-2",children:[s.observations.map((t,a)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{value:t,onChange:d=>{const m=[...M];m[n].observations[a]=d.target.value,G(m)},rows:2,className:"flex-1"}),s.observations.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>{const d=[...M];d[n].observations=d[n].observations.filter((m,S)=>S!==a),G(d)},children:e.jsx(h,{className:"h-4 w-4"})})]},a)),e.jsxs(o,{variant:"outline",size:"sm",className:"gap-1",onClick:()=>{const t=[...M];t[n].observations=[...t[n].observations,""],G(t)},children:[e.jsx(x,{className:"h-3 w-3"}),"Add"]})]})]},s.name))]}),bs=()=>{var s;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Field Observations"}),e.jsx(f,{rows:8,value:((s=u[0])==null?void 0:s.text)||"",onChange:n=>{var t;return b([{id:((t=u[0])==null?void 0:t.id)||me(),text:n.target.value,subItems:[]}])},placeholder:"Describe field observations in narrative formâ¦"})]})},ys=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Executive Summary & Methodology"}),e.jsxs("div",{children:[e.jsx(i,{children:"Executive Summary"}),e.jsx(f,{rows:6,value:Ge,onChange:s=>$e(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Limitations"}),e.jsx(f,{rows:4,value:Qe,onChange:s=>We(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Methodology"}),e.jsx(f,{rows:4,value:Ye,onChange:s=>Je(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Disclaimer"}),e.jsx(f,{rows:3,value:Ke,onChange:s=>Xe(s.target.value)})]})]}),Cs=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Sampling Data"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter air/surface sampling results."}),e.jsx("div",{className:"overflow-auto",children:e.jsxs("table",{className:"w-full text-sm border",children:[e.jsx("thead",{className:"bg-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-2 text-left",children:"Sample ID"}),e.jsx("th",{className:"p-2 text-left",children:"Location"}),e.jsx("th",{className:"p-2 text-left",children:"Type"}),e.jsx("th",{className:"p-2 text-left",children:"Concentration"}),e.jsx("th",{className:"p-2 text-left",children:"Spore Types"}),e.jsx("th",{className:"p-2 w-10"})]})}),e.jsx("tbody",{children:p.map((s,n)=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.sampleId,onChange:t=>{const a=[...p];a[n]={...s,sampleId:t.target.value},C(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.location,onChange:t=>{const a=[...p];a[n]={...s,location:t.target.value},C(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.sampleType,onCh
1ange:t=>{const a=[...p];a[n]={...s,sampleType:t.target.value},C(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.concentration,onChange:t=>{const a=[...p];a[n]={...s,concentration:t.target.value},C(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.sporeTypes,onChange:t=>{const a=[...p];a[n]={...s,sporeTypes:t.target.value},C(a)}})}),e.jsx("td",{className:"p-1",children:p.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>C(p.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})})]},n))})]})}),e.jsxs(o,{variant:"outline",size:"sm",className:"gap-1",onClick:()=>C([...p,{sampleId:"",location:"",sampleType:"",concentration:"",sporeTypes:""}]),children:[e.jsx(x,{className:"h-3 w-3"}),"Add Row"]}),e.jsx("h3",{className:"text-lg font-semibold mt-6",children:"IAQ Comfort Parameters"}),e.jsx("div",{className:"overflow-auto",children:e.jsxs("table",{className:"w-full text-sm border",children:[e.jsx("thead",{className:"bg-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-2 text-left",children:"Location"}),e.jsx("th",{className:"p-2 text-left",children:"Temp (°F)"}),e.jsx("th",{className:"p-2 text-left",children:"Humidity (%)"}),e.jsx("th",{className:"p-2 text-left",children:"COâ (ppm)"}),e.jsx("th",{className:"p-2 text-left",children:"CO (ppm)"}),e.jsx("th",{className:"p-2 w-10"})]})}),e.jsx("tbody",{children:j.map((s,n)=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.location,onChange:t=>{const a=[...j];a[n]={...s,location:t.target.value},_(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.temp,onChange:t=>{const a=[...j];a[n]={...s,temp:t.target.value},_(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.humidity,onChange:t=>{const a=[...j];a[n]={...s,humidity:t.target.value},_(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.co2,onChange:t=>{const a=[...j];a[n]={...s,co2:t.target.value},_(a)}})}),e.jsx("td",{className:"p-1",children:e.jsx(l,{value:s.co,onChange:t=>{const a=[...j];a[n]={...s,co:t.target.value},_(a)}})}),e.jsx("td",{className:"p-1",children:j.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>_(j.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})})]},n))})]})}),e.jsxs(o,{variant:"outline",size:"sm",className:"gap-1",onClick:()=>_([...j,{location:"",temp:"",humidity:"",co2:"",co:""}]),children:[e.jsx(x,{className:"h-3 w-3"}),"Add Row"]})]}),_s=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Recommendations"}),v.map((s,n)=>e.jsx(P,{children:e.jsxs(D,{className:"pt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(i,{children:"Priority"}),e.jsxs(Bs,{value:s.priority,onValueChange:t=>{const a=[...v];a[n]={...s,priority:t},T(a)},children:[e.jsx(Ms,{children:e.jsx(Us,{})}),e.jsxs(Fs,{children:[e.jsx(de,{value:"High",children:"High"}),e.jsx(de,{value:"Medium",children:"Medium"}),e.jsx(de,{value:"Low",children:"Low"})]})]})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Deficiency"}),e.jsx(l,{value:s.deficiency,onChange:t=>{const a=[...v];a[n]={...s,deficiency:t.target.value},T(a)}})]}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(i,{children:"Recommendation"}),e.jsx(l,{value:s.recommendation,onChange:t=>{const a=[...v];a[n]={...s,recommendation:t.target.value},T(a)}})]}),v.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>T(v.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]})]})},n)),e.jsxs(o,{variant:"outline",className:"gap-1",onClick:()=>T([...v,{priority:"Medium",deficiency:"",recommendation:""}]),children:[e.jsx(x,{className:"h-4 w-4"}),"Add"]})]}),ce=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Recommendations"}),O.map((s,n)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{value:s,onChange:t=>{const a=[...O];a[n]=t.target.value,$(a)},rows:2,className:"flex-1"}),O.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>$(O.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]},n)),e.jsxs(o,{variant:"outline",className:"gap-1",onClick:()=>$([...O,""]),children:[e.jsx(x,{className:"h-4 w-4"}),"Add"]})]}),Ss=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Planned Progress"}),z.map((s,n)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{value:s,onChange:t=>{const a=[...z];a[n]=t.target.value,Q(a)},className:"flex-1"}),z.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>Q(z.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]},n)),e.jsxs(o,{variant:"outline",size:"sm",className:"gap-1",onClick:()=>Q([...z,""]),children:[e.jsx(x,{className:"h-3 w-3"}),"Add"]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-xl font-bold",children:"Additional Discussion"}),L.map((s,n)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{value:s,onChange:t=>{const a=[...L];a[n]=t.target.value,W(a)},rows:2,className:"flex-1"}),L.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>W(L.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]},n)),e.jsxs(o,{variant:"outline",size:"sm",className:"gap-1",onClick:()=>W([...L,""]),children:[e.jsx(x,{className:"h-3 w-3"}),"Add"]})]}),ce()]}),ws=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Damages & Measurements"}),y.map((s,n)=>e.jsx(P,{children:e.jsxs(D,{className:"pt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(i,{children:"Location"}),e.jsx(l,{value:s.location,onChange:t=>{const a=[...y];a[n]={...s,location:t.target.value},E(a)}})]}),e.jsxs("div",{children:[e.jsx(i,{children:"Description"}),e.jsx(l,{value:s.description,onChange:t=>{const a=[...y];a[n]={...s,description:t.target.value},E(a)}})]}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(i,{children:"Measurement"}),e.jsx(l,{value:s.measurement,onChange:t=>{const a=[...y];a[n]={...s,measurement:t.target.value},E(a)}})]}),y.length>1&&e.jsx(o,{variant:"ghost",size:"icon",onClick:()=>E(y.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-4 w-4"})})]})]})}
1,n)),e.jsxs(o,{variant:"outline",className:"gap-1",onClick:()=>E([...y,{location:"",description:"",measurement:""}]),children:[e.jsx(x,{className:"h-4 w-4"}),"Add"]})]}),ce()]}),Rs=async s=>{const n=s.target.files;if(!n||n.length===0)return;Ze(!0);const t=[];for(const a of Array.from(n)){const d=a.name.split(".").pop(),m=`field-reports/${he.id}/${crypto.randomUUID()}.${d}`,{error:S}=await B.storage.from("proposal-documents").upload(m,a,{contentType:a.type});if(S){X.error(`Upload failed: ${a.name}`);continue}const{data:K}=B.storage.from("proposal-documents").getPublicUrl(m);t.push({url:K.publicUrl,caption:a.name.replace(/\.[^.]+$/,"")})}Y(a=>[...a,...t]),Ze(!1),s.target.value=""},Ps=()=>e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Photo Log"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Upload site photos and add captions for the report."}),e.jsxs("label",{className:"flex flex-col items-center justify-center gap-2 border-2 border-dashed border-border rounded-lg p-8 cursor-pointer hover:border-primary/50 hover:bg-accent/30 transition-colors",children:[oe?e.jsx(qs,{className:"h-8 w-8 animate-spin text-muted-foreground"}):e.jsx(Ws,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:oe?"Uploadingâ¦":"Click to upload or drag photos here"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"JPG, PNG, HEIC â multiple files OK"}),e.jsx("input",{type:"file",accept:"image/*",multiple:!0,onChange:Rs,className:"hidden",disabled:oe})]}),U.length>0&&e.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:U.map((s,n)=>e.jsxs(P,{className:"overflow-hidden",children:[e.jsxs("div",{className:"aspect-video bg-muted relative",children:[s.url?e.jsx("img",{src:s.url,alt:s.caption,className:"w-full h-full object-cover"}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Ys,{className:"h-10 w-10 text-muted-foreground/40"})}),e.jsx(o,{variant:"destructive",size:"icon",className:"absolute top-2 right-2 h-7 w-7",onClick:()=>Y(U.filter((t,a)=>a!==n)),children:e.jsx(h,{className:"h-3 w-3"})}),e.jsxs("div",{className:"absolute bottom-2 left-2 bg-background/80 text-xs font-medium px-2 py-0.5 rounded",children:["Photo ",n+1]})]}),e.jsx(D,{className:"p-3",children:e.jsx(l,{value:s.caption,onChange:t=>{const a=[...U];a[n]={...s,caption:t.target.value},Y(a)},placeholder:"Caption",className:"text-sm"})})]},n))})]}),Ds=()=>{var s;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Review"}),e.jsx(P,{children:e.jsxs(D,{className:"pt-4 space-y-2 text-sm",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Type:"})," ",(s=os.find(n=>n.id===c))==null?void 0:s.label]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Project:"})," ",ee," (",se,")"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Client:"})," ",te]}
1),e.jsxs("p",{children:[e.jsx("strong",{children:"Facility:"})," ",ne]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Visit Date:"})," ",le||"â"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Report #:"})," ",re]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Report By:"})," ",ie]}),c==="iaq_report"&&e.jsxs("p",{children:[e.jsx("strong",{children:"Samples:"})," ",p.filter(n=>n.sampleId).length," sampling rows, ",j.filter(n=>n.location).length," IAQ readings"]}),c==="construction_observation"&&e.jsxs("p",{children:[e.jsx("strong",{children:"Recommendations:"})," ",v.filter(n=>n.deficiency).length," items"]})]})})]})},g=J[R],Is=()=>g==="Report Type"?js():g==="Project & Client"?gs():g==="Visit Details"?vs():g==="Observations"?c==="construction_observation"?Ns():c==="environmental_field_report"?bs():fs():g==="Executive Summary"?ys():g==="Sampling Data"?Cs():g==="Recommendations"?c==="construction_observation"?_s():ce():g==="Progress & Discussion"?Ss():g==="Damages & Recommendations"?ws():g==="Photos"?Ps():g==="Review"?Ds():null;return e.jsxs("div",{className:"container py-8 max-w-3xl",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold mb-2",children:[I?"Edit":"New"," Field Report"]}),e.jsx("div",{className:"flex items-center gap-4 text-sm text-muted-foreground mb-2",children:J.map((s,n)=>e.jsx("span",{className:n===R?"text-primary font-semibold":"",children:s},s))}),e.jsx(Hs,{value:us,className:"h-2"})]}),e.jsx(P,{children:e.jsx(D,{className:"pt-6",children:Is()})}),e.jsxs("div",{className:"flex justify-between mt-6",children:[e.jsxs(o,{variant:"outline",disabled:R===0,onClick:()=>ue(R-1),className:"gap-2",children:[e.jsx(zs,{className:"h-4 w-4"})," Back"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(o,{variant:"outline",onClick:()=>es(!0),disabled:pe,className:"gap-2",children:[e.jsx($s,{className:"h-4 w-4"})," Save Draft"]}),R<J.length-1?e.jsxs(o,{onClick:()=>ue(R+1),className:"gap-2",children:["Next ",e.jsx(Qs,{className:"h-4 w-4"})]}):e.jsx(o,{onClick:()=>es(!1),disabled:pe,children:"Submit for Review"})]})]})]})};export{it 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.