1import{f as Re,r as u,w as De,j as e,L as Oe,t as ve}from"./app-BCbJ3cHy.js";import{P as Me}from"./PortalLayout-DfcbiI2A.js";import{P as Ee}from"./ProjectNav-BjQaYmEO.js";import{f as Be,u as N,d as qe,e as Le,S,a as g,g as _,b as a,C as B,c,D as U,E as C,j as ye,k as We,W as Fe,i as $,l as Ue,T as I}from"./sheet-autosave-BockEHsQ.js";import{s as m,f as z}from"./sheet-tokens-D38S4Yvu.js";import{supabase as x}from"./client-DyLLhy84.js";import{u as $e}from"./usePortalAuth-BQ21v18A.js";import{C as ze}from"./chevron-left-BC87j4U-.js";import"./Logo-gHVdN8Hn.js";import"./UndoRedoControls-BNb_kPgq.js";import"./dropdown-menu-B4oTx0JA.js";import"./index-CR6Kn7Ie.js";import"./Combination-BgEfPLD2.js";import"./index-LZlREorB.js";const be=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function ge(r){const P=new Intl.DateTimeFormat("en-US",{timeZone:"America/New_York",year:"numeric",month:"2-digit",day:"2-digit",weekday:"short"}).formatToParts(new Date),l=Number(P.find(b=>b.type==="year").value),q=Number(P.find(b=>b.type==="month").value),V=Number(P.find(b=>b.type==="day").value),L=P.find(b=>b.type==="weekday").value,W={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6}[L],Y=(r-W+7)%7,T=new Date(Date.UTC(l,q-1,V));return T.setUTCDate(T.getUTCDate()+Y),T.toISOString().slice(0,10)}const fe=[{value:"on_track",label:"On Track"},{value:"watch",label:"Watch"},{value:"at_risk",label:"At Risk"},{value:"complete",label:"Complete"},{value:"pending",label:"Pending"}],ke=[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}],Ve=[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"},{value:"critical",label:"Critical"}],Ye=[{value:"pending",label:"Pending"},{value:"in_progress",label:"In Progress"},{value:"complete",label:"Complete"},{value:"rejected",label:"Rejected"}],He=[{value:"open",label:"Open"},{value:"in_progress",label:"In Progress"},{value:"resolved",label:"Resolved"},{value:"closed",label:"Closed"}],Ke=[{value:"open",label:"Open"},{value:"in_progress",label:"In Progress"},{value:"mitigated",label:"Mitigated"},{value:"closed",label:"Closed"}],dt=()=>{const{id:r}=Re(),{user:y,canEditAll:P}=$e(),[l,q]=u.useState(null),[V,L]=u.useState(null),[te,W]=u.useState(null),[Y,T]=u.useState(null),[b,H]=u.useState([]),[we,se]=u.useState([]),[oe,K]=u.useState([]),[ie,G]=u.useState([]),[ne,Z]=u.useState([]),[f,ae]=u.useState({executive_position:null,advisory_outlook_p1:null,advisory_outlook_p2:null,advisory_outlook_p3:null}),[j,le]=u.useState({approved_budget:0,executed_to_date:0,remaining_budget:0,co_approved_count:0,co_approved_value:0,co_pending_approval_count:0,co_pending_approval_value:0,co_pending_submission_count:0,co_pending_submission_value:0,co_rejected_count:0,co_rejected_value:0}),[re,J]=u.useState(()=>{const t=new Date,o=t.getDay(),s=o===0?0:7-o;return t.setDate(t.getDate()+s),t.toISOString().slice(0,10)}),[Se,Ce]=u.useState(null),[Q,X]=u.useState(!0),de=!!l&&(P||l.pm_user_id===(y==null?void 0:y.id)||l.principal_user_id===(y==null?void 0:y.id)),i=!de,ce=u.useCallback(async()=>{if(!r)return;const{data:t}=await x.from("projects").select("id, name, pm_user_id, principal_user_id, client_id, address, city, state_region, postal_code, weekly_report_day_of_week").eq("id",r).maybeSingle();if(!t){X(!1);return}q(t);const o=t.weekly_report_day_of_week??5;J(ge(o));const s=[];t.client_id?s.push(Promise.resolve(x.from("clients").select("name").eq("id",t.client_id).maybeSingle().then(({data:d})=>L((d==null?void 0:d.name)??null)))):L(null);const n=[t.pm_user_id,t.principal_user_id].filter(Boolean);n.length?s.push(Promise.resolve(x.from("profiles").select("user_id, display_name, email").in("user_id",n).then(({data:d})=>{const k=new Map;(d??[]).forEach(v=>k.set(v.user_id,v.display_name||v.email)),W(t.pm_user_id?k.get(t.pm_user_id)??null:null),T(t.principal_user_id?k.get(t.principal_user_id)??null:null)}))):(W(null),T(null)),s.push(Promise.resolve(x.from("project_milestones").select("id, name, scheduled_date, forecast_actual_date, variance_text, status, display_order").eq("project_id",r).order("display_order").then(({data:d})=>
1H(d??[])))),s.push(Promise.resolve(x.from("project_assessments").select("id, area_name, status, assessment_text, display_order").eq("project_id",r).order("display_order").then(({data:d})=>se(d??[])))),s.push(Promise.resolve(x.from("project_risks").select("id, description, category, probability, impact, status, display_order").eq("project_id",r).order("display_order").then(({data:d})=>K(d??[])))),s.push(Promise.resolve(x.from("project_actions").select("id, action_required, owner, due_date, estimated_value, status, display_order").eq("project_id",r).order("display_order").then(({data:d})=>G(d??[])))),s.push(Promise.resolve(x.from("project_issues").select("id, description, raised_by, date_opened, priority, status, display_order").eq("project_id",r).order("display_order").then(({data:d})=>Z(d??[])))),s.push(Promise.resolve(x.from("weekly_report_drafts").select("executive_position, advisory_outlook_p1, advisory_outlook_p2, advisory_outlook_p3").eq("project_id",r).maybeSingle().then(({data:d})=>ae(d??{executive_position:null,advisory_outlook_p1:null,advisory_outlook_p2:null,advisory_outlook_p3:null})))),s.push(Promise.resolve(x.from("cost_lines").select("baseline_amount, committed_amount").eq("project_id",r).then(({data:d})=>{const k=d??[],v=k.reduce((w,A)=>w+Number(A.baseline_amount||0),0),E=k.reduce((w,A)=>w+Number(A.committed_amount||0),0);le(w=>({...w,approved_budget:v,executed_to_date:E,remaining_budget:v-E}))}))),s.push(Promise.resolve(x.from("change_orders").select("status, amount").eq("project_id",r).then(({data:d})=>{const k=d??[],v=p=>k.filter(F=>p(F.status)).reduce((F,Ie)=>({count:F.count+1,value:F.value+Number(Ie.amount||0)}),{count:0,value:0}),E=v(p=>p==="approved"),w=v(p=>p==="submitted"||p==="under_review"),A=v(p=>p==="draft"),he=v(p=>p==="rejected");le(p=>({...p,co_approved_count:E.count,co_approved_value:E.value,co_pending_approval_count:w.count,co_pending_approval_value:w.value,co_pending_submission_count:A.count,co_pending_submission_value:A.value,co_rejected_count:he.count,co_rejected_value:he.value}))}))),await Promise.all(s),X(!1)},[r]);u.useEffect(()=>{X(!0),ce()},[ce]);const ue=De();u.useEffect(()=>{if(Q)return;const t=ue.hash.replace("#","");if(!t)return;const o=document.getElementById(t);o&&requestAnimationFrame(()=>o.scrollIntoView({behavior:"smooth",block:"start"}))},[Q,ue.hash]);const h=()=>Ce(new Date),R=async(t,o)=>{H(s=>s.map(n=>n.id===t?{...n,...o}:n)),await N("project_milestones",t,o),h()},pe=async()=>{var s;const t=(((s=b.at(-1))==null?void 0:s.display_order)??0)+1,o=await $("project_milestones",{project_id:r,name:"New milestone",status:"on_track",display_order:t});o&&H(n=>[...n,o]),h()},ee=async(t,o)=>{se(s=>s.map(n=>n.id===t?{...n,...o}:n)),await N("project_assessments",t,o),h()},D=async(t,o)=>{K(s=>s.map(n=>n.id===t?{...n,...o}:n)),await N("project_risks",t,o),h()},_e=async()=>{var s;const t=(((s=oe.at(-1))==null?void 0:s.display_order)??0)+1,o=await $("project_risks",{project_id:r,description:"New risk",probability:"medium",impact:"medium",status:"open",display_order:t});o&&K(n=>[...n,o]),h()},O=async(t,o)=>{G(s=>s.map(n=>n.id===t?{...n,...o}:n)),await N("project_actions",t,o),h()},me=async()=>{var s;const t=(((s=ie.at(-1))==null?void 0:s.display_order)??0)+1,o=await $("project_actions",{project_id:r,action_required:"New action",status:"pending",display_order:t});o&&G(n=>[...n,o]),h()},M=async(t,o)=>{Z(s=>s.map(n=>n.id===t?{...n,...o}:n)),await N("project_issues",t,o),h()},xe=async()=>{var s;const t=(((s=ne.at(-1))==null?void 0:s.display_order)??0)+1,o=await $("project_issues",{project_id:r,description:"New issue",priority:"medium",status:"open",display_order:t});o&&Z(n=>[...n,o]),h()},je=async t=>{ae(o=>({...o,...t})),await Ue(r,t,y==null?void 0:y.id),h()},Pe=async()=>{if(!r)return;const{data:t,error:o}=await x.rpc("publish_weekly_report",{p_project_id:r,p_week_ending_date:re,p_executive_position:f.executive_position,p_outlook_p1:f.advisory_outlook_p1,p_outlook_p2:f.advisory_outlook_p2,p_outlook_p3:f.advisory_outlook_p3});if(o){ve({title:"Publish failed",description:o.message,variant:"destructive"});return}ve({title:"Weekly Report published",description:`Snapshot id: ${t}`})}
1,Te=l?[l.address,l.city,l.state_region,l.postal_code].filter(Boolean).join(", "):"",Ae=e.jsx(Be,{title:"Project Dashboard",project:l?{id:l.id,name:l.name,client_name:V,address_one_line:Te||null,pm_name:te,principal_name:Y}:null,savedAt:Se,rightSlot:e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:11,letterSpacing:1.5,textTransform:"uppercase",color:m.cellTextMuted,marginBottom:4},children:"Week Ending"}),e.jsx("input",{type:"date",value:re,onChange:t=>J(t.target.value),style:{padding:"6px 10px",border:`1px solid ${m.btnSheetBorder}`,borderRadius:4,fontFamily:m.numberFont,fontSize:13,backgroundColor:m.sheetCellBg}}),e.jsxs("div",{style:{marginTop:6,fontSize:11,color:m.cellTextMuted},children:["Cadence:"," ",de?e.jsx("select",{value:(l==null?void 0:l.weekly_report_day_of_week)??5,onChange:async t=>{const o=Number(t.target.value);q(s=>s&&{...s,weekly_report_day_of_week:o}),J(ge(o)),await N("projects",l.id,{weekly_report_day_of_week:o}),h()},style:{border:`1px solid ${m.btnSheetBorder}`,borderRadius:4,padding:"2px 6px",fontSize:11,backgroundColor:m.sheetCellBg},children:be.map((t,o)=>e.jsx("option",{value:o,children:t},o))}):e.jsx("strong",{children:be[(l==null?void 0:l.weekly_report_day_of_week)??5]})," ","· America/New_York"]})]})}),Ne=e.jsxs(e.Fragment,{children:[e.jsx(I,{onClick:pe,disabled:i,children:"+ Milestone"}),e.jsx(I,{onClick:_e,disabled:i,children:"+ Risk"}),e.jsx(I,{onClick:xe,disabled:i,children:"+ Issue"}),e.jsx(I,{onClick:me,disabled:i,children:"+ Action"}),e.jsx("span",{style:{flex:1}}),e.jsx(I,{disabled:!0,title:"Coming in v2",children:"Export .xlsx"}),e.jsx(I,{onClick:()=>window.print(),children:"Print"})]});return e.jsx(Me,{children:e.jsxs("div",{className:"-mx-6 -mt-12",children:[e.jsx(Ee,{}),e.jsx(qe,{}),Q?e.jsx("p",{className:"px-6 py-12 font-sans text-sm text-muted-foreground",children:"Loadingâ¦"}):l?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-6 pt-4",children:e.jsxs(Oe,{to:`/portal/projects/${r}`,className:"inline-flex items-center gap-1 font-sans text-xs uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(ze,{size:14})," ",l.name]})}),e.jsxs(Le,{header:Ae,toolbar:Ne,children:[e.jsx(S,{number:"01",title:"Executive Position",anchorId:"executive"}),e.jsx(g,{children:e.jsx("tbody",{children:e.jsx("tr",{children:e.jsx(_,{value:f.executive_position,readOnly:i,multiline:!0,placeholder:"Click to add executive position narrative for this week...",onCommit:t=>je({executive_position:t||null})})})})}),e.jsx(S,{number:"02",title:"Financial Snapshot",anchorId:"financial"}),e.jsxs(g,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(a,{w:"33%",children:"Approved Budget"}),e.jsx(a,{w:"33%",children:"Executed To Date"}),e.jsx(a,{w:"34%",children:"Remaining"})]})}),e.jsx("tbody",{children:e.jsxs("tr",{children:[e.jsx(B,{value:z(j.approved_budget),bold:!0}),e.jsx(B,{value:z(j.executed_to_date),bold:!0}),e.jsx(B,{value:z(j.remaining_budget),bold:!0})]})})]}),e.jsx("div",{style:{height:8}}),e.jsxs(g,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(a,{children:"Change Order Status"}),e.jsx(a,{w:120,right:!0,children:"Count"}),e.jsx(a,{w:180,right:!0,children:"Value"})]})}),e.jsx("tbody",{children:[["Approved",j.co_approved_count,j.co_approved_value],["Pending Approval",j.co_pending_approval_count,j.co_pending_approval_value],["Pending Submission",j.co_pending_submission_count,j.co_pending_submission_value],["Rejected",j.co_rejected_count,j.co_rejected_value]].map(([t,o,s],n)=>e.jsxs("tr",{children:[e.jsx(c,{alt:n%2===1,children:t}),e.jsx(B,{value:o}),e.jsx(B,{value:z(s)})]},String(t)))})]}),e.jsx(S,{number:"03",title:"Master Schedule",anchorId:"schedule"}),e.jsxs(g,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(a,{children:"Milestone"}),e.jsx(a,{w:140,children:"Scheduled"}),e.jsx(a,{w:140,children:"Forecast / Actual"}),e.jsx(a,{w:150,children:"Variance"}),e.jsx(a,{w:120,children:"Status"})]})}),e.jsxs("tbody",{children:[b.map((t,o)=>e.jsxs("tr",{children:[e.jsx(_,{alt:o%2===1,value:t.name,readOnly:i,onCommit:s=>R(t.id,{name:s})}),e.jsx(U,{alt:o%2===1,value:t.scheduled_date,readOnly:i,onCommit:s=>R(t.id,{scheduled_date:s})}),e.jsx(U,{alt:o%2===1,value:t.forecast_actual_date,readOnly:i,onCommit:s=>R(t.id,{forecast_actual_date:s})}),e.jsx(_,{alt:o%2===1,value:t.variance_text,placeholder:"â",readOnly:i,onCommit:s=>R(t.id,{variance_text:s||null})}),e.jsx(C,{alt:o%2===1,value:t.status,options:fe,readOnly:i,renderDisplay:s=>e.jsx(ye,{status:s??"pending"}),onCommit:s=>R(t.id,{status:s})})]},t.id)),!i&&e.jsxs("tr",{onClick:pe,style:{cursor:"pointer"},children:[e.jsx(c,{children:e.jsx("span",{style:{color:m.cellTextMuted},children:"+ Add milestone"})}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{})]})]})]}),e.jsx(S,{number:"04",title:"Management Assessment",anchorId:"assessment"}),e.jsxs(g,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(a,{w:240,children:"Area"}),e.jsx(a,{w:130,children:"Status"}),e.jsx(a,{children:"Assessment"})]})}),e.jsx("tbody",{children:we.map((t,o)=>e.jsxs("tr",{children:[e.jsx(_,{alt:o%2===1,value:t.area_name,readOnly:i,onCommit:s=>ee(t.id,{area_name:s})}),e.jsx(C,{alt:o%2===1,value:t.status,options:fe,readOnly:i,renderDisplay:s=>e.jsx(ye,{status:s??"pending"}),onCommit:s=>ee(t.id,{status:s})}),e.jsx(_,{alt:o%2===1,value:t.assessment_text,multiline:!0,placeholder:"Click to add narrative...",readOnly:i,onCommit:s=>ee(t.id,{assessment_text:s||null})})]},t.id))})]}),e.jsx(S,{number:"05",title:"Risk Register",anchorId:"risks"}),e.jsxs(g,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(a,{children:"Risk"}),e.jsx(a,{w:160,children:"Category"}),e.jsx(a,{w:120,children:"Probability"}),e.jsx(a,{w:120,children:"Impact"}),e.jsx(a,{w:140,children:"Status"})]})}),e.jsxs("tbody",{children:[oe.map((t,o)=>e.jsxs("tr",{style:t.status==="closed"?{opacity:.55}:void 0,children:[e.jsx(_,{alt:o%2===1,value:t.description,readOnly:i,onCommit:s=>D(t.id,{description:s})}),e.jsx(_,{alt:o%2===1,value:t.category,placeholder:"â",readOnly:i,onCommit:s=>D(t.id,{category:s||null})}),e.jsx(C,{alt:o%2===1,value:t.probability,options:ke,readOnly:i,onCommit:s=>D(t.id,{probability:s})}),e.jsx(C,{alt:o%2===1,value:t.impact,options:ke,readOnly:i,onCommit:s=>D(t.id,{impact:s})}),e.jsx(C,{alt:o%2===1,value:t.status,options:Ke,readOnly:i,onCommit:s=>D(t.id,{status:s})})]},t.id)),!i&&e.jsxs("tr",{onClick:_e,style:{cursor:"pointer"},children:[e.jsx(c,{children:e.jsx("span",{style:{color:m.cellTextMuted},children:"+ Add risk"})}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{})]})]})]}
1),e.jsx(S,{number:"06",title:"Approvals & Pending Actions",anchorId:"actions"}),e.jsxs(g,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(a,{children:"Action Required"}),e.jsx(a,{w:160,children:"Owner"}),e.jsx(a,{w:140,children:"Due"}),e.jsx(a,{w:140,right:!0,children:"Value"}),e.jsx(a,{w:140,children:"Status"})]})}),e.jsxs("tbody",{children:[ie.map((t,o)=>e.jsxs("tr",{children:[e.jsx(_,{alt:o%2===1,value:t.action_required,readOnly:i,onCommit:s=>O(t.id,{action_required:s})}),e.jsx(_,{alt:o%2===1,value:t.owner,placeholder:"â",readOnly:i,onCommit:s=>O(t.id,{owner:s||null})}),e.jsx(U,{alt:o%2===1,value:t.due_date,readOnly:i,onCommit:s=>O(t.id,{due_date:s})}),e.jsx(We,{alt:o%2===1,value:t.estimated_value,readOnly:i,onCommit:s=>O(t.id,{estimated_value:s})}),e.jsx(C,{alt:o%2===1,value:t.status,options:Ye,readOnly:i,onCommit:s=>O(t.id,{status:s})})]},t.id)),!i&&e.jsxs("tr",{onClick:me,style:{cursor:"pointer"},children:[e.jsx(c,{children:e.jsx("span",{style:{color:m.cellTextMuted},children:"+ Add action"})}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{})]})]})]}),e.jsx(S,{number:"07",title:"Open Issues",anchorId:"issues"}),e.jsxs(g,{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(a,{children:"Issue"}),e.jsx(a,{w:160,children:"Raised By"}),e.jsx(a,{w:140,children:"Opened"}),e.jsx(a,{w:120,children:"Priority"}),e.jsx(a,{w:140,children:"Status"})]})}),e.jsxs("tbody",{children:[ne.map((t,o)=>e.jsxs("tr",{children:[e.jsx(_,{alt:o%2===1,value:t.description,readOnly:i,onCommit:s=>M(t.id,{description:s})}),e.jsx(_,{alt:o%2===1,value:t.raised_by,placeholder:"â",readOnly:i,onCommit:s=>M(t.id,{raised_by:s||null})}),e.jsx(U,{alt:o%2===1,value:t.date_opened,readOnly:i,onCommit:s=>M(t.id,{date_opened:s})}),e.jsx(C,{alt:o%2===1,value:t.priority,options:Ve,readOnly:i,onCommit:s=>M(t.id,{priority:s})}),e.jsx(C,{alt:o%2===1,value:t.status,options:He,readOnly:i,onCommit:s=>M(t.id,{status:s})})]},t.id)),!i&&e.jsxs("tr",{onClick:xe,style:{cursor:"pointer"},children:[e.jsx(c,{children:e.jsx("span",{style:{color:m.cellTextMuted},children:"+ Add issue"})}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{}),e.jsx(c,{})]})]})]}),e.jsx(S,{number:"08",title:"Forward Outlook",anchorId:"outlook"}),e.jsx(g,{children:e.jsx("tbody",{children:[["advisory_outlook_p1",f.advisory_outlook_p1,1],["advisory_outlook_p2",f.advisory_outlook_p2,2],["advisory_outlook_p3",f.advisory_outlook_p3,3]].map(([t,o,s])=>e.jsx("tr",{children:e.jsx(_,{value:o,multiline:!0,placeholder:`Click to add paragraph ${s}...`,readOnly:i,onCommit:n=>je({[t]:n||null})})},t))})}),!i&&e.jsx("div",{style:{marginTop:32,paddingTop:16,borderTop:`1px solid ${m.sheetCellBorder}`,display:"flex",justifyContent:"flex-end",gap:12},children:e.jsx(Fe,{onClick:Pe,children:"Publish Weekly Report"})})]})]}):e.jsx("p",{className:"px-6 py-12 font-sans text-sm text-muted-foreground",children:"Project not found."})]})})};export{dt 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.