1import{j as e,d as W,u as J,e as P}from"./vendor-data-_Pz25YLs.js";import{r as S,i as we,L as re}from"./vendor-react-C5ET9VRQ.js";import{c as de,e as j,I as ve,B as D,W as H,a6 as K,s as f,aC as me,L as B,r as ue,t as pe,an as Se,ca as ke,cb as xe,M as Ce,C as he,af as qe,ai as Me,ag as Ee,ax as De,ay as Te,bh as Fe,T as Le,n as Ie,cc as Ae,bw as Pe,ah as ne,cd as Je}from"./index-C15KveKt.js";import{S as ie}from"./StorageDownloadButton-DqxhNbwy.js";import{C,a as q,b as M,c as E}from"./card-DKtZ9FmL.js";import{u as Oe,a as Be,J as Re}from"./JobRFIExpandable-CDemBByW.js";import{u as Ue,M as oe}from"./useTimeEntries-DN3SDW_N.js";import{C as O}from"./clock-ByM7PWKN.js";import{S as Ke}from"./square-DyVo5jC0.js";import{P as ze}from"./play-CvdaJrKg.js";import{f as L}from"./format-Bo4AVCK2.js";import{C as Qe}from"./circle-check-CpVsBeTs.js";import{S as $}from"./send-CNlcoSAp.js";import{E as $e}from"./eye-off-TjaKtBI5.js";import{S as We}from"./SendForApprovalDialog-CmNFu6lb.js";import{n as He,g as Ge}from"./approvalPacketValidation-Vk45mPi_.js";import{E as Ve}from"./external-link-Cg93dYqn.js";import{L as Ze}from"./link-HdT-i0Qn.js";import{S as ce}from"./square-check-big-oFrP6YiW.js";import"./storage-Epskv-5y.js";import"./errorLog-Cu-LEhg8.js";import"./download-B3pOWHS0.js";import"./mail-Eg027Dpq.js";import"./calendar-days-CQ9NU205.js";import"./zod-kfNAg4qD.js";import"./form-CHClfEH6.js";import"./switch-BpXxs5tu.js";import"./useApprovalPackets-D5-gnzR6.js";import"./user-plus-C130fs6T.js";import"./trash-2-CeDNviAG.js";import"./types-Dhp_If05.js";import"./addDays-Caep41KN.js";/** 2 * @license lucide-react v0.462.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 Xe=de("Car",[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]]);/** 7 * @license lucide-react v0.462.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 Ye=de("DoorOpen",[["path",{d:"M13 4h3a2 2 0 0 1 2 2v14",key:"hrm0s9"}],["path",{d:"M2 20h3",key:"1gaodv"}],["path",{d:"M13 20h9",key:"s90cdi"}],["path",{d:"M10 12v.01",key:"vx6srw"}],["path",{d:"M13 4.562v16.157a1 1 0 0 1-1.242.97L5 20V5.562a2 2 0 0 1 1.515-1.94l4-1A2 2 0 0 1 13 4.561Z",key:"199qr4"}]]);function et({jobId:s,contractorId:l,teamMemberId:r}){const[o,g]=S.useState(""),{timeEntries:p,activeEntry:x,totalHours:N,clockIn:d,clockOut:m}=Ue(s),h=()=>{d.mutate({teamMemberId:r,contractorId:l})},i=()=>{x&&(m.mutate({entryId:x.id,notes:o}),g(""))};return e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(O,{className:"h-4 w-4"}),"Time Tracking"]}),e.jsxs(j,{variant:"secondary",children:[N.toFixed(1)," hours logged"]})]})}),e.jsxs(E,{className:"space-y-4",children:[x?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between p-3 bg-green-500/10 border border-green-500/20 rounded-lg",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-green-500 animate-pulse"}),e.jsxs("span",{className:"text-sm font-medium text-green-600",children:["Clocked in at ",L(new Date(x.clock_in),"h:mm a")]})]})}),e.jsx(ve,{placeholder:"Add notes for this session (optional)",value:o,onChange:n=>g(n.target.value)}),e.jsxs(D,{className:"w-full",variant:"destructive",onClick:i,disabled:m.isPending,children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Clock Out"]})]}):e.jsxs(D,{className:"w-full",onClick:h,disabled:d.isPending,children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Clock In"]}),p.length>0&&e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Recent Sessions"}),p.slice(0,3).map(n=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:L(new Date(n.clock_in),"MMM d")}),e.jsx("span",{children:n.clock_out?e.jsxs(e.Fragment,{children:[Math.round((new Date(n.clock_out).getTime()-new Date(n.clock_in).getTime())/(1e3*60*60)*10)/10,"h"]}):e.jsx(j,{className:"bg-green-500/10 text-green-600 border-green-500/20 text-xs",children:"Active"})})]},n.id))]})]})]})}const G=[{status:"scheduled",label:"Scheduled",icon:"ð "},{status:"en_route",label:"En Route",icon:"ð"},{status:"arrived_on_site",label:"Arrived",icon:"ð"},{status:"in_progress",label:"In Progress",icon:"ð§"},{status:"waiting_on_parts",label:"Waiting on Parts",icon:"â³"},{status:"completed",label:"Completed",icon:"â "},{status:"left_site",label:"Left Site",icon:"ðª"}];
11function tt(s){switch(s){case"pending":return"pending";case"scheduled":return"scheduled";case"en_route":case"arrived_on_site":case"in_progress":case"waiting_on_parts":return"in-progress";case"completed":case"left_site":return"complete";case"overdue":return"overdue";default:return"pending"}}function st(s){var d;const{toast:l}=H(),{user:r}=K(),o=W(),{data:g=[],isLoading:p}=J({queryKey:["job-status-events",s],queryFn:async()=>{if(!s)return[];const{data:m,error:h}=await f.from("job_status_events").select("*").eq("job_id",s).order("changed_at",{ascending:!1});if(h)throw h;return m},enabled:!!s}),x=((d=g[0])==null?void 0:d.status)||"pending",N=P({mutationFn:async({status:m,notes:h,changedByType:i="contractor_user"})=>{if(!s)throw new Error("Job ID required");const{error:n}=await f.from("job_status_events").insert({job_id:s,status:m,changed_by_type:i,changed_by_user_id:(r==null?void 0:r.id)||null,notes:h||null});if(n)throw n;const _=tt(m),y={status:_};m==="arrived_on_site"&&(y.arrived_at=new Date().toISOString()),m==="left_site"&&(y.departed_at=new Date().toISOString()),_==="complete"&&(y.completed_at=new Date().toISOString());const{error:a}=await f.from("jobs").update(y).eq("id",s);if(a)throw a;return await at(s,m),me(s).catch(console.error),{status:m,basicStatus:_}},onSuccess:(m,h)=>{o.invalidateQueries({queryKey:["job-status-events",s]}),o.invalidateQueries({queryKey:["contractor-job",s]}),o.invalidateQueries({queryKey:["job",s]}),o.invalidateQueries({queryKey:["jobs"]}),o.invalidateQueries({queryKey:["hubspot-sync-logs"]});const i=G.find(n=>n.status===h.status);l({title:`Status: ${(i==null?void 0:i.label)||h.status}`,description:"Status updated and synced"})},onError:m=>{l({title:"Error updating status",description:m.message,variant:"destructive"})}});return{events:g,latestStatus:x,isLoading:p,updateStatus:N}}async function at(s,l){var r;try{const{data:o}=await f.from("jobs").select("title, owner_user_id, dispatcher_user_id").eq("id",s).single();if(!o)return;const g=((r=G.find(x=>x.status===l))==null?void 0:r.label)||l,p=[o.owner_user_id,o.dispatcher_user_id].filter(Boolean);for(const x of p)x&&await f.from("notifications").insert({recipient_user_id:x,type:"job_status_changed",entity_type:"job",entity_id:s,title:`Job Status: ${g}`,body:`"${o.title}" status changed to ${g}`})}catch(o){console.error("Failed to create status notification:",o)}}const Q={pending:e.jsx(O,{className:"h-4 w-4"}),scheduled:e.jsx(ue,{className:"h-4 w-4"}),en_route:e.jsx(Xe,{className:"h-4 w-4"}),arrived_on_site:e.jsx(pe,{className:"h-4 w-4"}),in_progress:e.jsx(Se,{className:"h-4 w-4"}),waiting_on_parts:e.jsx(O,{className:"h-4 w-4"}),completed:e.jsx(Qe,{className:"h-4 w-4"}),left_site:e.jsx(Ye,{className:"h-4 w-4"}),overdue:e.jsx(O,{className:"h-4 w-4"})};function rt({jobId:s,currentBasicStatus:l,compact:r=!1}){var h;const{events:o,latestStatus:g,updateStatus:p}=st(s),N=(()=>{switch(g){case"pending":case"scheduled":return["en_route","arrived_on_site"];case"en_route":return["arrived_on_site"];case"arrived_on_site":return["in_progress"];case"in_progress":return["waiting_on_parts","completed"];case"waiting_on_parts":return["in_progress","completed"];case"completed":return["left_site"];case"left_site":return[];default:return["en_route","arrived_on_site"]}})(),d=i=>G.find(n=>n.status===i),m=i=>{p.mutate({status:i,changedByType:"contractor_user"})};if(r){const i=N[0];if(!i)return null;const n=d(i);return e.jsxs(D,{size:"sm",onClick:()=>m(i),disabled:p.isPending,className:"gap-2",children:[p.isPending?e.jsx(B,{className:"h-4 w-4 animate-spin"}):Q[i],(n==null?void 0:n.label)||i]})}return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Current:"}),e.jsxs(j,{variant:"outline",className:"gap-1",children:[Q[g],((h=d(g))==null?void 0:h.label)||g]})]}),N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(i=>{const n=d(i);return e.jsxs(D,{size:"lg",variant:i==="completed"?"default":"outline",onClick:()=>m(i),disabled:p.isPending,className:"gap-2",children:[p.isPending?e.jsx(B,{className:"h-4 w-4 animate-spin"}):Q[i],(n==null?void 0:n.label)||i]},i)})}),o.length>0&&e.jsxs("div",{className:"pt-2 border-t",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Recent Updates"}),e.jsx("div",{className:"space-y-1",children:o.slice(0,3).map(i=>{var n;return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:new Date(i.changed_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),e.jsx(j,{variant:"secondary",className:"text-xs",children:((n=d(i.status))==null?void 0:n.label)||i.status}),i.hubspot_synced_at&&e.jsx("span",{className:"text-green-600",children:"â Synced"})]},i.id)})})]})]})}async function le(s,l,r){try{const[{data:o},g]=await Promise.all([f.from("jobs").select("title, owner_user_id").eq("id",s).maybeSingle(),ke(s,l)]),p=new Set(g);
11if(o!=null&&o.owner_user_id&&p.add(o.owner_user_id),l&&p.delete(l),p.size===0)return;await xe({jobId:s,jobTitle:(o==null?void 0:o.title)||"Job",authorName:r,recipientUserIds:Array.from(p)})}catch(o){console.error("[useJobNotes] fireJobNoteNotification failed",o)}}function nt(s){const{toast:l}=H(),{user:r}=K(),o=W(),{data:g=[],isLoading:p}=J({queryKey:["job-notes-enhanced",s],queryFn:async()=>{if(!s)return[];const{data:d,error:m}=await f.from("job_notes").select("*").eq("job_id",s).order("created_at",{ascending:!1});if(m)throw m;const h=[...new Set((d||[]).map(n=>n.user_id).filter(Boolean))];let i={};if(h.length>0){const{data:n}=await f.from("profiles").select("id, full_name, email").in("id",h);n&&(i=Object.fromEntries(n.map(_=>[_.id,_])))}return(d||[]).map(n=>({...n,profile:n.user_id&&i[n.user_id]||null}))},enabled:!!s}),x=P({mutationFn:async({content:d,authorType:m="portal_user"})=>{var n;if(!s)throw new Error("Job ID required");const{data:h,error:i}=await f.from("job_notes").insert({job_id:s,user_id:(r==null?void 0:r.id)||null,content:d,visibility:"internal_only",author_type:m}).select().single();if(i)throw i;return await le(s,(r==null?void 0:r.id)??null,((n=r==null?void 0:r.user_metadata)==null?void 0:n.full_name)||(r==null?void 0:r.email)||"Someone"),h},onSuccess:()=>{o.invalidateQueries({queryKey:["job-notes-enhanced",s]}),o.invalidateQueries({queryKey:["notifications"]}),l({title:"Note added"})},onError:d=>{l({title:"Error adding note",description:d.message,variant:"destructive"})}}),N=P({mutationFn:async({internalContent:d,customerMessage:m,authorType:h="contractor_user"})=>{var y;if(!s)throw new Error("Job ID required");const{data:i,error:n}=await f.from("job_notes").insert({job_id:s,user_id:(r==null?void 0:r.id)||null,content:d,visibility:"customer_candidate",author_type:h}).select().single();if(n)throw n;const{error:_}=await f.from("customer_updates").insert({job_id:s,source_note_id:i.id,body:m,status:"needs_review"});if(_)throw _;return await le(s,(r==null?void 0:r.id)??null,((y=r==null?void 0:r.user_metadata)==null?void 0:y.full_name)||(r==null?void 0:r.email)||"Someone"),i},onSuccess:()=>{o.invalidateQueries({queryKey:["job-notes-enhanced",s]}),o.invalidateQueries({queryKey:["customer-updates"]}),l({title:"Note added and customer update queued for review"})},onError:d=>{l({title:"Error adding note",description:d.message,variant:"destructive"})}});return{notes:g,isLoading:p,addInternalNote:x,addNoteWithCustomerUpdate:N,internalNotes:g.filter(d=>d.visibility==="internal_only"),customerCandidateNotes:g.filter(d=>d.visibility==="customer_candidate")}}function it({jobId:s}){const{user:l}=K(),[r,o]=S.useState(""),[g,p]=S.useState([]),[x,N]=S.useState(!1),[d,m]=S.useState(""),[h,i]=S.useState([]),n=async(b,F)=>{var U;const T=[...new Set(b.map(w=>w.userId))].filter(w=>!!w);if(T.length)try{const{data:w}=await f.from("jobs").select("title").eq("id",s).maybeSingle();await Ee({recipientUserIds:T,authorName:((U=l==null?void 0:l.user_metadata)==null?void 0:U.full_name)||(l==null?void 0:l.email)||"Someone",contextLabel:(w==null?void 0:w.title)||"Job note",entityType:"job",entityId:s,snippet:F})}catch(w){console.error("[ContractorNotesSection] mention notify failed",w)}},{notes:_,isLoading:y,addInternalNote:a,addNoteWithCustomerUpdate:R}=nt(s),I=()=>{if(r.trim())if(x&&d.trim()){const b=[...g,...h];R.mutate({internalContent:r.trim(),customerMessage:d.trim(),authorType:"contractor_user"},{onSuccess:()=>{n(b,r.trim()),o(""),m(""),p([]),i([]),N(!1)}})}else{const b=g;a.mutate({content:r.trim(),authorType:"contractor_user"},{onSuccess:()=>{n(b,r.trim()),o(""),p([])}})}},A=a.isPending||R.isPending;return e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Ce,{className:"h-4 w-4"}),"Notes & Updates"]})}),e.jsxs(E,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(oe,{placeholder:"Add a note about the job... Use @ to tag a teammate.",value:r,onChange:o,onMentionsChange:p,rows:3}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(he,{id:"customer-update",checked:x,onCheckedChange:b=>N(b)}),e.jsx("label",{htmlFor:"customer-update",className:"text-sm text-muted-foreground cursor-pointer",children:"Request customer update (will be reviewed before sending)"})]}),x&&e.jsxs("div",{className:"pl-6 space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Suggested customer message:"}),e.jsx(oe,{placeholder:"Write a customer-friendly version of your update...",value:d,onChange:m,onMentionsChange:i,rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This will be reviewed and possibly edited before being sent to the customer."})]}),e.jsxs(D,{onClick:I,disabled:!r.trim()||A||x&&!d.trim(),className:"gap-2",children:[A?e.jsx(B,{className:"h-4 w-4 animate-spin"}):e.jsx($,{className:"h-4 w-4"}),x?"Submit for Review":"Add Note"]})]}),e.jsx(qe,{}),y?e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(B,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):_.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No notes yet"}):e.jsx("div",{className:"space-y-3",children:_.map(b=>{var F,T;return e.jsxs("div",{className:"p-3 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:((F=b.profile)==null?void 0:F.full_name)||((T=b.profile)==null?void 0:T.email)||"Unknown"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:L(new Date(b.created_at),"MMM d, yyyy h:mm a")})]}),e.jsx("div",{className:"flex items-center gap-1",children:b.visibility==="customer_candidate"?e.jsxs(j,{variant:"outline",className:"text-xs gap-1",children:[e.jsx(Me,{className:"h-3 w-3"}),"Customer Update Requested"]}):e.jsxs(j,{variant:"secondary",className:"text-xs gap-1",children:[e.jsx($e,{className:"h-3 w-3"}),"Internal"]}
11)})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:b.content})]},b.id)})})]})]})}function Bt(){var Y,ee,te;const{id:s}=we(),{user:l}=K(),{toast:r}=H(),o=W(),[g,p]=S.useState(""),[x,N]=S.useState("all"),[d,m]=S.useState(!1),[h,i]=S.useState(null),[n,_]=S.useState(null),y=async t=>{var c,u;i(t.id);try{const{data:v}=await f.auth.getSession();if(!v.session)throw new Error("Not authenticated");const k=He({entity_type:"project",entity_id:t.project_id,document_id:t.id,message_to_approvers:"Please review and approve this document.",recipients:[{name:"Shared Link Recipient",email:"[email protected]",role_label:"Reviewer"}]}),se=Ge(k);if(se)throw new Error(se);const z=await fetch("https://nblhnpkxepwbpmhghpmk.supabase.co/functions/v1/guest-approval",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${v.session.access_token}`},body:JSON.stringify(k)});if(!z.ok){const ye=await z.json();throw new Error(ye.error||"Failed to generate link")}const ae=(u=(c=(await z.json()).recipients)==null?void 0:c[0])==null?void 0:u.token;if(!ae)throw new Error("Failed to get approval token");const _e=Pe(ae);await navigator.clipboard.writeText(_e),ne.success("Link copied to clipboard!")}catch(v){console.error("Error generating link:",v),ne.error(v.message||"Failed to generate link")}finally{i(null)}},{data:a,isLoading:R}=J({queryKey:["contractor-job",s],queryFn:async()=>{const{data:t,error:c}=await f.from("jobs").select(` 12 *, 13 contractors (id, name, company_name), 14 projects (id, name) 15 `).eq("id",s).single();if(c)throw c;return t},enabled:!!s}),{data:I=[]}=J({queryKey:["job-checklist",s],queryFn:async()=>{const{data:t,error:c}=await f.from("job_checklist_items").select("*").eq("job_id",s).order("sort_order",{ascending:!0});if(c)throw c;return t},enabled:!!s});J({queryKey:["job-notes",s],queryFn:async()=>{const{data:t,error:c}=await f.from("job_notes").select("*").eq("job_id",s).order("created_at",{ascending:!1});if(c)throw c;return t},enabled:!!s});const{jobDocuments:A,rfis:b,submittals:F,transmittals:T,isLoading:U}=Oe(s,a==null?void 0:a.project_id);P({mutationFn:async t=>{const c={status:t};t==="complete"&&(c.completed_at=new Date().toISOString());const{error:u}=await f.from("jobs").update(c).eq("id",s);if(u)throw u;await me(s)},onSuccess:()=>{o.invalidateQueries({queryKey:["contractor-job",s]}),o.invalidateQueries({queryKey:["hubspot-sync-logs"]}),r({title:"Job status updated"})},onError:t=>{r({title:"Error updating status",description:t.message,variant:"destructive"})}});const w=P({mutationFn:async({itemId:t,isCompleted:c})=>{const{error:u}=await f.from("job_checklist_items").update({is_completed:c,completed_at:c?new Date().toISOString():null}).eq("id",t);if(u)throw u;return{isCompleted:c}},onSuccess:t=>{o.invalidateQueries({queryKey:["job-checklist",s]}),t.isCompleted&&s&&(a!=null&&a.organization_id)&&f.from("job_checklist_items").select("id, is_completed").eq("job_id",s).then(({data:c})=>{c&&c.length>0&&c.every(u=>u.is_completed)&&f.from("user_roles").select("user_id").eq("organization_id",a.organization_id).eq("role","general_contractor").then(({data:u})=>{const v=(u||[]).map(k=>k.user_id).filter(k=>k!==(l==null?void 0:l.id));v.length>0&&Je({jobId:s,jobTitle:a.title||"Job",recipientUserIds:v}).catch(console.error)})})},onError:t=>{r({title:"Error updating checklist",description:t.message,variant:"destructive"})}});P({mutationFn:async t=>{const{error:c}=await f.from("job_notes").insert({job_id:s,user_id:l==null?void 0:l.id,content:t});if(c)throw c},onSuccess:()=>{o.invalidateQueries({queryKey:["job-notes",s]}),p(""),r({title:"Note added"}),a!=null&&a.organization_id&&s&&f.from("user_roles").select("user_id").eq("organization_id",a.organization_id).eq("role","general_contractor").then(({data:t})=>{var u,v;const c=(t||[]).map(k=>k.user_id).filter(k=>k!==(l==null?void 0:l.id));c.length>0&&xe({jobId:s,jobTitle:a.title||"Job",authorName:((u=a.contractors)==null?void 0:u.company_name)||((v=a.contractors)==null?void 0:v.name)||"Contractor",recipientUserIds:c}).catch(console.error)})},onError:t=>{r({title:"Error adding note",description:t.message,variant:"destructive"})}});const V=t=>{switch(t){case"complete":return e.jsx(j,{className:"bg-green-500/10 text-green-600 border-green-500/20",children:"Complete"});case"in-progress":return e.jsx(j,{className:"bg-blue-500/10 text-blue-600 border-blue-500/20",children:"In Progress"});case"scheduled":return e.jsx(j,{className:"bg-purple-500/10 text-purple-600 border-purple-500/20",children:"Scheduled"});case"overdue":return e.jsx(j,{variant:"destructive",children:"Overdue"});default:return e.jsx(j,{variant:"outline",children:"Pending"})}},ge=t=>{switch(t){case"urgent":return e.jsx(j,{variant:"destructive",children:"Urgent"});case"high":return e.jsx(j,{className:"bg-orange-500/10 text-orange-600 border-orange-500/20",children:"High"});default:return null}},fe=t=>{switch(t){case"IFC":return e.jsx(j,{className:"bg-green-500/10 text-green-600 border-green-500/20",children:"IFC"});case"IFR":return e.jsx(j,{className:"bg-amber-500/10 text-amber-600 border-amber-500/20",children:"IFR"});default:return e.jsx(j,{variant:"outline",children:t})}},Z=[...new Set(A.map(t=>{var c;return(c=t.document)==null?void 0:c.discipline}
15).filter(Boolean))],X=x==="all"?A:A.filter(t=>{var c;return((c=t.document)==null?void 0:c.discipline)===x});if(R)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})});if(!a)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-muted-foreground",children:"Job not found"})});const je=I.filter(t=>t.is_completed).length,be=I.length,Ne=a.status==="overdue"||!!a.blocking_reason;return e.jsxs("div",{className:"space-y-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs(re,{to:"/contractor/jobs",className:"inline-flex items-center gap-2 text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(De,{className:"h-4 w-4"}),"Back to Jobs"]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:a.title}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[V(a.status||"pending"),a.priority&&ge(a.priority),((Y=a.contractors)==null?void 0:Y.company_name)&&e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(Te,{className:"h-4 w-4"}),a.contractors.company_name]})]}),((ee=a.projects)==null?void 0:ee.name)&&e.jsxs(re,{to:"/contractor/projects",className:"text-sm text-primary hover:underline flex items-center gap-1",children:[e.jsx(Fe,{className:"h-4 w-4"}),"Project: ",a.projects.name]})]})]}),Ne&&a.blocking_reason&&e.jsxs("div",{className:"flex items-start gap-3 p-4 bg-destructive/10 border border-destructive/20 rounded-lg",children:[e.jsx(Le,{className:"h-5 w-5 text-destructive shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-destructive",children:"Blocking Issue"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.blocking_reason})]})]}),e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsx(M,{className:"text-base font-semibold",children:"Scope & Location"})}),e.jsxs(E,{className:"space-y-4",children:[a.description&&e.jsx("p",{className:"text-foreground",children:a.description}),(a.address||a.site)&&e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(pe,{className:"h-4 w-4 text-muted-foreground mt-1 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:a.address||a.site}),a.address&&e.jsxs("a",{href:`https://maps.google.com/?q=${encodeURIComponent(a.address)}`,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline flex items-center gap-1",children:["Open in Maps ",e.jsx(Ve,{className:"h-3 w-3"})]})]})]}),a.access_notes&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-muted/50 rounded-lg",children:[e.jsx("span",{className:"text-sm",children:"ðª"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.access_notes})]})]})]}),e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ue,{className:"h-4 w-4"}),"Schedule"]})}),e.jsx(E,{children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[a.scheduled_date&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Start"}),e.jsx("p",{className:"font-medium",children:L(new Date(a.scheduled_date),"MMM d, yyyy")}),a.scheduled_time&&e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(O,{className:"h-3 w-3"})," ",a.scheduled_time]})]}),a.due_date&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Target Completion"}),e.jsx("p",{className:"font-medium",children:L(new Date(a.due_date),"MMM d, yyyy")})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Status"}),e.jsx("div",{className:"mt-1",children:V(a.status||"pending")})]})]})})]}),e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"Drawings & Specs"]}),Z.length>1&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(D,{variant:x==="all"?"default":"outline",size:"sm",onClick:()=>N("all"),children:"All"}),Z.map(t=>e.jsx(D,{variant:x===t?"default":"outline",size:"sm",onClick:()=>N(t),children:t},t))]})]})}),e.jsx(E,{children:U?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading documents..."}):X.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No documents linked to this job"}):e.jsx("div",{className:"space-y-2",children:X.map(({document:t,revisions:c})=>t&&e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between p-3 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 min-w-0",children:[e.jsx("span",{className:"font-mono text-sm font-medium",children:t.document_number}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-sm",children:t.title||"Untitled"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(j,{variant:"outline",className:"text-xs",children:t.discipline}),e.jsxs(j,{variant:"outline",className:"text-xs",children:["Rev ",t.revision]}),fe(t.status),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{_({id:t.id,document_number:t.document_number,title:t.title,project_id:a.project_id||""}),m(!0)},title:"Send for Approval",children:e.jsx($,{className:"h-4 w-4"})}),e.jsx(D,{variant:"ghost",size:"sm",disabled:h===t.id,onClick:()=>y({id:t.id,document_number:t.document_number,title:t.title,project_id:a.project_id||""}),title:"Copy Link",children:h===t.id?e.jsx(B,{className:"h-4 w-4 animate-spin"}):e.jsx(Ze,{className:"h-4 w-4"})}),t.file_url&&e.jsx(ie,{bucket:"project-documents",urlOrPath:t.file_url,variant:"ghost",size:"sm"})]})]}),c&&c.length>0&&e.jsxs("div",{className:"border-t bg-muted/30 px-3 py-2 space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Guest Revisions"}),c.map(u=>e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between p-2 bg-background rounded border",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 min-w-0",children:[e.jsxs(j,{variant:"secondary",className:"text-xs",children:["Rev ",u.revision_number]}),e.jsx("span",{className:"text-sm",children:u.title||`Revision ${u.revision_number}`}),u.uploaded_by_email&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["by ",u.uploaded_by_email]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:L(new Date(u.created_at),"MMM d, yyyy h:mm a")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[u.notes&&e.jsx("span",{className:"text-xs text-muted-foreground max-w-[200px] truncate",title:u.notes,children:u.notes}),u.file_url&&e.jsx(ie,{bucket:"project-documents",urlOrPath:u.file_url,variant:"ghost",size:"sm"})]})]},u.id))]})]},t.id))})})]}),e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ce,{className:"h-4 w-4"}),"Approved Submittals"]})}),e.jsx(E,{children:F.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No approved submittals for this job"}):e.jsx("div",{className:"space-y-2",children:F.map(t=>e.jsx(Be,{submittal:t,projectId:a==null?void 0:a.project_id},t.id))})})]}),e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Ae,{className:"h-4 w-4"}),"RFIs Impacting This Job"]})}),e.jsx(E,{children:b.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No RFIs for this job"}):e.jsx("div",{className:"space-y-2",children:b.map(t=>e.jsx(Re,{rfi:t},t.id))})})]}),e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx($,{className:"h-4 w-4"}),"Transmittals"]})}),e.jsx(E,{children:T.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No transmittals containing job documents"}):e.jsx("div",{className:"space-y-2",children:T.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"font-mono text-sm font-medium",children:["T-",String(t.transmittal_number).padStart(3,"0")]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Issued ",L(new Date(t.issued_at),"MMM d, yyyy")]})]}),e.jsx(j,{variant:"outline",children:t.purpose})]},t.id))})})]}),I.length>0&&e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(M,{className:"text-base font-semibold flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"h-4 w-4"}),"Checklist"]}),e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:[je,"/",be," complete"]})]})}),e.jsx(E,{children:e.jsx("div",{className:"space-y-2",children:I.map(t=>e.jsxs("div",{className:`flex items-center gap-3 p-3 rounded-lg border ${t.is_completed?"bg-muted/50 border-muted":""}`,children:[e.jsx(he,{checked:t.is_completed||!1,onCheckedChange:c=>{w.mutate({itemId:t.id,isCompleted:c})}}),e.jsx("span",{className:t.is_completed?"line-through text-muted-foreground":"",children:t.label}),t.is_required&&e.jsx(j,{variant:"outline",className:"ml-auto text-xs",children:"Required"})]},t.id))})})]}),e.jsx(it,{jobId:s}),a.status==="in-progress"&&((te=a.contractors)==null?void 0:te.id)&&e.jsx(et,{jobId:s,contractorId:a.contractors.id,teamMemberId:a.contractors.id}),a.status!=="complete"&&e.jsxs(C,{children:[e.jsx(q,{className:"pb-3",children:e.jsx(M,{className:"text-base font-semibold",children:"Update Status"})}),e.jsx(E,{children:e.jsx(rt,{jobId:s,currentBasicStatus:a.status||"pending"})})]}),n&&e.jsx(We,{open:d,onOpenChange:m,entity:{id:n.id,number:n.document_number,title:n.title,project_id:n.project_id,type:"document"},entityType:"job",entityId:s})]})}export{Bt 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.