1import{c as dt,r as d,al as X,j as e,g as oe,aU as ut,k as mt,i as pt,x as V,t as De,E as be,B as C,L as de,w as fe,T as ht,au as ft,aV as xt,J as ue,s as O}from"./index-BCGrvFuq.js";import{u as J,j as gt,d as bt,e as vt,g as jt,k as wt,h as St}from"./queries-CWzLUq4Z.js";import{u as yt}from"./useMutation-Dw0vjPeH.js";import{b as Ee,M as Nt,S as _t,r as kt}from"./primitives-auO43y7A.js";import{R as Ct,I as Tt,d as Ae,s as Pt,T as Rt,D as Dt,a as Et,E as Mt,b as It,c as xe,p as At}from"./weekly-report.functions-DK5ig42i.js";import{I as me}from"./input-DgtOFYLN.js";import{L as Me}from"./label-opIYTMqD.js";import{T as Vt}from"./textarea-9fgiouS3.js";import{u as Lt,a as Ve,b as Kt}from"./index-BBpOTIOW.js";import{b as Le,g as Ke,c as F,P as Bt,u as Ft}from"./index-CrZSH2-t.js";import{c as qt,u as Be,C as zt}from"./index-C6nczEkU.js";import{P as q}from"./index-DhMUBjnI.js";import{S as re}from"./skeleton-qDqPJJin.js";import{a as $t,b as Ht,d as Ot}from"./collapsible-XiEm5d2B.js";import{d as Ut,e as Wt,h as Gt,f as Qt,i as Yt,j as Jt}from"./dialog-BR-MpFEH.js";import{C as Fe}from"./calendar-days-5IO7-mQn.js";import{U as Xt}from"./upload-DNZ1HFX2.js";import{A as Zt,a as es}from"./arrow-up-BsThA1EA.js";import{S as ts}from"./send-CKnfrBWp.js";import"./auth-middleware-ret5nsuJ.js";const ss=[["path",{d:"M14 14a2 2 0 0 0 2-2V8h-2",key:"1r06pg"}],["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M8 14a2 2 0 0 0 2-2V8H8",key:"1jzu5j"}]],ns=dt("message-square-quote",ss);var rs=Object.defineProperty,g=(r,t)=>rs(r,"name",{value:t,configurable:!0}),qe=["PageUp","PageDown"],ze=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],$e={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},ie="Slider",[ve,as,os]=qt(ie),[Se,Zs]=Le(ie,[os]),[is,le]=Se(ie),He=d.forwardRef(g(function(t,o){const{name:i,min:a=0,max:n=100,step:m=1,orientation:c="horizontal",disabled:p=!1,minStepsBetweenThumbs:x=0,defaultValue:u=[a],value:f,onValueChange:l=g(()=>{},"onValueChange"),onValueCommit:h=g(()=>{},"onValueCommit"),inverted:w=!1,form:S,...y}=t,k=d.useRef(new Set),N=d.useRef(0),T=d.useRef(!1),P=c==="horizontal"?ls:cs,[L,z]=d.useState(null),W=X(o,z),[M=[],U]=Ke({prop:f,defaultProp:u,onChange:g(b=>{[...k.current][N.current]?.focus({preventScroll:!0,focusVisible:T.current}),T.current=!1,l(b)},"onChange")}),ce=d.useRef(M),ee=d.useRef(M);d.useEffect(()=>{const b=S?L?.ownerDocument.getElementById(S):L?.closest("form");if(b instanceof HTMLFormElement){const D=g(()=>U(ee.current),"reset");return b.addEventListener("reset",D),()=>b.removeEventListener("reset",D)}},[L,S,U]);function G(b){const D=Xe(M,b);$(b,D)}g(G,"handleSlideStart");function te(b){$(b,N.current)}g(te,"handleSlideMove");function Q(){String(M)!==String(ce.current)&&h(M)}g(Q,"handleSlideEnd");function $(b,D,{commit:se}={commit:!1}){const _=Ne(m),A=ae(Math.round((b-a)/m)*m+a,_),K=Ve(A,[a,n]);U((E=[])=>{const I=Ye(E,K,D);if(tt(I,x*m)){N.current=I.indexOf(K);const ne=String(I)!==String(E);return ne&&se&&h(I),ne?I:E}else return E})}return g($,"updateValues"),e.jsx(is,{scope:t.__scopeSlider,name:i,disabled:p,min:a,max:n,valueIndexToChangeRef:N,thumbs:k.current,values:M,orientation:c,form:S,children:e.jsx(ve.Provider,{scope:t.__scopeSlider,children:e.jsx(ve.Slot,{scope:t.__scopeSlider,children:e.jsx(P,{"aria-disabled":p,"data-disabled":p?"":void 0,...y,ref:W,onPointerDown:F(y.onPointerDown,()=>{p||(ce.current=M,T.current=!1)}),min:a,max:n,inverted:w,onSlideStart:p?void 0:G,onSlideMove:p?void 0:te,onSlideEnd:p?void 0:Q,onHomeKeyDown:()=>{p||(T.current=!0,$(a,0,{commit:!0}))},onEndKeyDown:()=>{p||(T.current=!0,$(n,M.length-1,{commit:!0}))},onStepKeyDown:({event:b,direction:D})=>{if(!p){T.current=!0;const A=qe.includes(b.key)||b.shiftKey&&ze.includes(b.key)?10:1,K=N.current,E=M[K],I=st(E,{min:a,step:m,direction:D,multiplier:A});$(I,K,{commit:!0})}}})})})})},"Slider")),[Oe,Ue]=Se(ie,{startEdge:"left",endEdge:"right",size:"width",direction:1}),ls=d.forwardRef(g(function(t,o){const{min:i,max:a,dir:n,inverted:m,onSlideStart:c,onSlideMove:p,onSlideEnd:x,onStepKeyDown:u,...f}=t,[l,h]=d.useState(null),w=X(o,h),S=d.useRef(void 0),y=Be(n),k=y==="ltr",N=k&&!m||!k&&m;function T(R){const P=S.current||l.getBoundingClientRect(),L=[0,P.width],W=he(L,N?[i,a]:[a,i]);return S.current=P,W(R-P.left)}return g(T,"getValueFromPointer"),e.jsx(Oe,{scope:t.__scopeSlider,startEdge:N?"left":"right",endEdge:N?"right":"left",direction:N?1:-1,size:"width",children:e.jsx(We,{dir:y,"data-orientation":"horizontal",...f,ref:w,style:{...f.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:R=>{const P=T(R.clientX);c?.(P)},onSlideMove:R=>{const P=T(R.clientX);p?.(P)},onSlideEnd:()=>{S.current=void 0,x?.()},onStepKeyDown:R=>{const L=$e[N?"from-left":"from-right"].includes(R.key);u?.({event:R,direction:L?-1:1})}})})},"SliderHorizontal")),cs=d.forwardRef(g(function(t,o){const{min:i,max:a,inverted:n,onSlideStart:m,onSlideMove:c,onSlideEnd:p,onStepKeyDown:x,...u}=t,f=d.useRef(null),l=X(o,f),h=d.useRef(void 0),w=!n;function S(y){const k=h.current||f.current.getBoundingClientRect(),N=[0,k.height],R=he(N,w?[a,i]:[i,a]);return h.current=k,R(y-k.top)}return g(S,"getValueFromPointer"),e.jsx(Oe,{scope:t.__scopeSlider,startEdge:w?"bottom":"top",endEdge:w?"top":"bottom",size:"height",direction:w?1:-1,children:e.jsx(We,{"data-orientation":"vertical",...u,ref:l,style:{...u.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:y=>{const k=S(y.clientY);m?.(k)},onSlideMove:y=>{const k=S(y.clientY);c?.(k)},onSlideEnd:()=>{h.current=void 0,p?.()},onStepKeyDown:y=>{const N=$e[w?"from-bottom":"from-top"].includes(y.key);x?.({event:y,direction:N?-1:1})}})})},"SliderVertical")),We=d.forwardRef(g(function(t,o){const{__scopeSlider:i,onSlideStart:a,onSlideMove:n,onSlideEnd:m,onHomeKeyDown:c,onEndKeyDown:p,onStepKeyDown:x,...u}=t,f=le(ie,i);return e.jsx(q.span,{...u,ref:o,onKeyDown:F(t.onKeyDown,l=>{l.key==="Home"?(c(l),l.preventDefault()):l.key==="End"?(p(l),l.preventDefault()):qe.concat(ze).includes(l.key)&&
1(x(l),l.preventDefault())}),onPointerDown:F(t.onPointerDown,l=>{const h=l.target;h.setPointerCapture(l.pointerId),l.preventDefault(),f.thumbs.has(h)?h.focus({preventScroll:!0,focusVisible:!1}):a(l)}),onPointerMove:F(t.onPointerMove,l=>{l.target.hasPointerCapture(l.pointerId)&&n(l)}),onPointerUp:F(t.onPointerUp,l=>{const h=l.target;h.hasPointerCapture(l.pointerId)&&(h.releasePointerCapture(l.pointerId),m(l))})})},"SliderImpl")),ds="SliderTrack",us=d.forwardRef(g(function(t,o){const{__scopeSlider:i,...a}=t,n=le(ds,i);return e.jsx(q.span,{"data-disabled":n.disabled?"":void 0,"data-orientation":n.orientation,...a,ref:o})},"SliderTrack")),Ie="SliderRange",ms=d.forwardRef(g(function(t,o){const{__scopeSlider:i,...a}=t,n=le(Ie,i),m=Ue(Ie,i),c=d.useRef(null),p=X(o,c),x=n.values.length,u=n.values.map(h=>ye(h,n.min,n.max)),f=x>1?Math.min(...u):0,l=100-Math.max(...u);return e.jsx(q.span,{"data-orientation":n.orientation,"data-disabled":n.disabled?"":void 0,...a,ref:p,style:{...t.style,[m.startEdge]:f+"%",[m.endEdge]:l+"%"}})},"SliderRange")),ps="SliderThumb",[hs,Ge]=Se(ps),fs="SliderThumbProvider";function Qe(r){const{__scopeSlider:t,name:o,children:i,internal_do_not_use_render:a}=r,n=le(fs,t),m=as(t),[c,p]=d.useState(null),x=d.useMemo(()=>c?m().findIndex(y=>y.ref.current===c):-1,[m,c]),u=Kt(c),f=c?!!n.form||!!c.closest("form"):!0,l=n.values[x],h=o??(n.name?n.name+(n.values.length>1?"[]":""):void 0),w=l===void 0?0:ye(l,n.min,n.max);d.useEffect(()=>{if(c)return n.thumbs.add(c),()=>{n.thumbs.delete(c)}},[c,n.thumbs]);const S={value:l,name:h,form:n.form,isFormControl:f,index:x,thumb:c,onThumbChange:p,percent:w,size:u};return e.jsx(hs,{scope:t,...S,children:nt(a)?a(S):i})}g(Qe,"SliderThumbProvider");var ge="SliderThumbTrigger",xs=d.forwardRef(g(function(t,o){const{__scopeSlider:i,...a}=t,n=le(ge,i),m=Ue(ge,i),{index:c,value:p,percent:x,size:u,onThumbChange:f}=Ge(ge,i),l=X(o,f),h=Je(c,n.values.length),w=u?.[m.size],S=w?Ze(w,x,m.direction):0;return e.jsx("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[m.startEdge]:`calc(${x}% + ${S}px)`},children:e.jsx(ve.ItemSlot,{scope:i,children:e.jsx(q.span,{role:"slider","aria-label":t["aria-label"]||h,"aria-valuemin":n.min,"aria-valuenow":p,"aria-valuemax":n.max,"aria-orientation":n.orientation,"data-orientation":n.orientation,"data-disabled":n.disabled?"":void 0,tabIndex:n.disabled?void 0:0,...a,ref:l,style:p===void 0?{display:"none"}:t.style,onFocus:F(t.onFocus,()=>{n.valueIndexToChangeRef.current=c})})})})},"SliderThumbTrigger")),gs=d.forwardRef(g(function(t,o){const{__scopeSlider:i,name:a,...n}=t;return e.jsx(Qe,{__scopeSlider:i,name:a,internal_do_not_use_render:({index:m,isFormControl:c})=>e.jsxs(e.Fragment,{children:[e.jsx(xs,{...n,ref:o,__scopeSlider:i}),c?e.jsx(vs,{__scopeSlider:i},m):null]})})},"SliderThumb")),bs="SliderBubbleInput",vs=d.forwardRef(g(function({__scopeSlider:t,...o},i){const{value:a,name:n,form:m}=Ge(bs,t),c=d.useRef(null),p=X(c,i),x=Lt(a);return d.useEffect(()=>{const u=c.current;if(!u)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"value").set;if(x!==a&&h){const w=new Event("input",{bubbles:!0});h.call(u,a),u.dispatchEvent(w)}},[x,a]),e.jsx(q.input,{style:{display:"none"},name:n,form:m,...o,ref:p,defaultValue:a})},"SliderBubbleInput"));function Ye(r=[],t,o){const i=[...r];return i[o]=t,i.sort((a,n)=>a-n)}g(Ye,"getNextSortedValues");function ye(r,t,o){const n=100/(o-t)*(r-t);return Ve(n,[0,100])}g(ye,"convertValueToPercentage");function Je(r,t){return t>2?`Value ${r+1} of ${t}`:t===2?["Minimum","Maximum"][r]:void 0}g(Je,"getLabel");function Xe(r,t){if(r.length===1)return 0;const o=r.map(a=>Math.abs(a-t)),i=Math.min(...o);return o.indexOf(i)}g(Xe,"getClosestValueIndex");function Ze(r,t,o){const i=r/2,n=he([0,50],[0,i]);return(i-n(t)*o)*o}g(Ze,"getThumbInBoundsOffset");function et(r){return r.slice(0,-1).map((t,o)=>r[o+1]-t)}g(et,"getStepsBetweenValues");function tt(r,t){if(t>0){const o=et(r);return Math.min(...o)>=t}return!0}g(tt,"hasMinStepsBetweenValues");function he(r,t){return o=>{if(r[0]===r[1]||t[0]===t[1])return t[0];const i=(t[1]-t[0])/(r[1]-r[0]);return t[0]+i*(o-r[0])}}g(he,"linearScale");function Ne(r){if(!Number.isFinite(r))return 0;const t=r.toString();if(t.includes("e")){const[i,a]=t.split("e"),n=i.split(".")[1]||"",m=Number(a);return Math.max(0,n.length-m)}const o=t.split(".")[1];return o?o.length:0}g(Ne,"getDecimalCount");function ae(r,t){const o=Math.pow(10,t);return Math.round(r*o)/o}g(ae,"roundValue");function st(r,{min:t,step:o,direction:i,multiplier:a}){const n=Ne(o),m=(r-t)/o,c=Math.round(m),p=ae(c*o+t,n)===ae(r,n);let x;return p?x=c+a*i:i>0?x=Math.ceil(m):x=Math.floor(m),ae(x*o+t,n)}g(st,"getNextStepValue");function nt(r){return typeof r=="function"}
1g(nt,"isFunction");const rt=d.forwardRef(({className:r,...t},o)=>e.jsxs(He,{ref:o,className:oe("relative flex w-full touch-none select-none items-center",r),...t,children:[e.jsx(us,{className:"relative h-1.5 w-full grow overflow-hidden rounded-full bg-primary/20",children:e.jsx(ms,{className:"absolute h-full bg-primary"})}),e.jsx(gs,{className:"block h-4 w-4 rounded-full border border-primary/50 bg-background shadow transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"})]}));rt.displayName=He.displayName;var js=Object.defineProperty,Z=(r,t)=>js(r,"name",{value:t,configurable:!0}),_e="Tabs",[ws,en]=Le(_e,[Ae]),at=Ae(),[Ss,ke]=ws(_e),ys=d.forwardRef(Z(function(t,o){const{__scopeTabs:i,value:a,onValueChange:n,defaultValue:m,orientation:c="horizontal",dir:p,activationMode:x="automatic",...u}=t,f=Be(p),[l,h]=Ke({prop:a,onChange:n,defaultProp:m??"",caller:_e});return e.jsx(Ss,{scope:i,baseId:Ft(),value:l,onValueChange:h,orientation:c,dir:f,activationMode:x,children:e.jsx(q.div,{dir:f,"data-orientation":c,...u,ref:o})})},"Tabs")),Ns="TabsList",_s=d.forwardRef(Z(function(t,o){const{__scopeTabs:i,loop:a=!0,...n}=t,m=ke(Ns,i),c=at(i);return e.jsx(Ct,{asChild:!0,...c,orientation:m.orientation,dir:m.dir,loop:a,children:e.jsx(q.div,{role:"tablist","aria-orientation":m.orientation,...n,ref:o})})},"TabsList")),ks="TabsTrigger",Cs=d.forwardRef(Z(function(t,o){const{__scopeTabs:i,value:a,disabled:n=!1,...m}=t,c=ke(ks,i),p=at(i),x=Ce(c.baseId,a),u=Te(c.baseId,a),f=a===c.value;return e.jsx(Tt,{asChild:!0,...p,focusable:!n,active:f,children:e.jsx(q.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":u,"data-state":f?"active":"inactive","data-disabled":n?"":void 0,disabled:n,id:x,...m,ref:o,onMouseDown:F(t.onMouseDown,l=>{!n&&l.button===0&&l.ctrlKey===!1?c.onValueChange(a):l.preventDefault()}),onKeyDown:F(t.onKeyDown,l=>{n||l.target!==l.currentTarget||[" ","Enter"].includes(l.key)&&c.onValueChange(a)}),onFocus:F(t.onFocus,()=>{const l=c.activationMode!=="manual";!f&&!n&&l&&c.onValueChange(a)})})})},"TabsTrigger")),Ts="TabsContent",Ps=d.forwardRef(Z(function(t,o){const{__scopeTabs:i,value:a,forceMount:n,children:m,...c}=t,p=ke(Ts,i),x=Ce(p.baseId,a),u=Te(p.baseId,a),f=a===p.value,l=d.useRef(f);return d.useEffect(()=>{const h=requestAnimationFrame(()=>l.current=!1);return()=>cancelAnimationFrame(h)},[]),e.jsx(Bt,{present:n||f,children:({present:h})=>e.jsx(q.div,{"data-state":f?"active":"inactive","data-orientation":p.orientation,role:"tabpanel","aria-labelledby":x,hidden:!h,id:u,tabIndex:0,...c,ref:o,style:{...t.style,animationDuration:l.current?"0s":void 0},children:h&&m})})},"TabsContent"));function Ce(r,t){return`${r}-trigger-${t}`}Z(Ce,"makeTriggerId");function Te(r,t){return`${r}-content-${t}`}Z(Te,"makeContentId");var Rs=ys,ot=_s,it=Cs,lt=Ps;const Ds=Rs,ct=d.forwardRef(({className:r,...t},o)=>e.jsx(ot,{ref:o,className:oe("inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",r),...t}));ct.displayName=ot.displayName;const je=d.forwardRef(({className:r,...t},o)=>e.jsx(it,{ref:o,className:oe("inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background cursor-pointer transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",r),...t}));je.displayName=it.displayName;const we=d.forwardRef(({className:r,...t},o)=>e.jsx(lt,{ref:o,className:oe("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",r),...t}));we.displayName=lt.displayName;const Es=[{key:"accomplished",label:"Accomplished this week",icon:be,help:"What the crew finished. Short lines starting with a dash become bullets for the client."},{key:"scheduled",label:"Scheduled work for the upcoming week",icon:Fe,help:"What is planned next. This is what the client reads first."},{key:"issues",label:"Issues, risks and delays",icon:ht,help:"Anything that could move the schedule. Leave blank if there is nothing to flag."},{key:"message_to_client",label:"Message to client",icon:ns,help:"A short personal note. It appears at the top of the email in your name."}];function pe({title:r,icon:t,help:o,children:i}){return e.jsxs("section",{className:"rounded-xl border border-ink/10 bg-white p-4 sm:p-5",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[e.jsx(t,{className:"h-4 w-4 shrink-0 text-gold-deep","aria-hidden":"true"}),e.jsx("h2",{className:"text-[10px] font-bold uppercase tracking-[0.2em] text-ink/55",children:r})]}),o&&e.jsx("p",{className:"mb-3 text-xs leading-relaxed text-ink/45",children:o}),i]})}function tn(){const{jobId:r,reportId:t}=ut.useParams(),{user:o}=mt(),i=pt(),a=J({queryKey:["reports","report",t],queryFn:()=>gt(t)}),n=J({queryKey:["reports","job",r],queryFn:()=>bt(r)}),m=J({queryKey:["reports","milestones",r],queryFn:()=>vt(r)}),c=J({queryKey:["reports","recipients",r],queryFn:()=>jt(r)}),p=J({queryKey:["reports","photos",t],queryFn:()=>wt(t)}
1),x=J({queryKey:["reports","list",r],queryFn:()=>St(r)}),[u,f]=d.useState(null),[l,h]=d.useState("idle"),[w,S]=d.useState(null),[y,k]=d.useState(""),[N,T]=d.useState(!1),[R,P]=d.useState(!1),[L,z]=d.useState(!1),[W,M]=d.useState(""),[U,ce]=d.useState(null),ee=d.useRef(null),G=d.useRef(null);d.useEffect(()=>{a.data&&!u&&f({week_ending:a.data.week_ending,completion_pct:a.data.completion_pct??0,accomplished:a.data.accomplished??"",scheduled:a.data.scheduled??"",issues:a.data.issues??"",message_to_client:a.data.message_to_client??"",prepared_by_name:a.data.prepared_by_name??o?.email??""})},[a.data,u,o]),d.useEffect(()=>{if(!w)return;const s=()=>k(kt(w));s();const v=setInterval(s,1e4);return()=>clearInterval(v)},[w]);const te=d.useMemo(()=>(x.data??[]).filter(v=>v.id!==t).find(v=>v.week_ending<(u?.week_ending??""))??null,[x.data,t,u?.week_ending]),Q=async(s,v)=>{h("saving");const{error:j}=await O.from("weekly_reports").update(s).eq("id",t);if(j){if(h("idle"),j.code==="23505"||/duplicate key|already exists/i.test(j.message)){v&&f(v),V.error("A report for that week already exists. Open it from the job page instead.");return}V.error(j.message);return}h("saved"),S(new Date),i.invalidateQueries({queryKey:["reports","list",r]})},$=()=>{G.current&&clearTimeout(G.current),G.current=setTimeout(async()=>{try{const s=await At({data:{reportId:t}});M(s.html)}catch{}},900)};d.useEffect(()=>{u&&$()},[u,p.data]);const b=s=>{if(!u)return;const v=u,j={...u,...s};f(j),h("saving"),ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{Q(j,v)},800)},D=async s=>{if(!s.length)return;T(!0);let v=p.data?.length??0;for(const j of s){if(!j.type.startsWith("image/")){V.error(`${j.name} is not an image.`);continue}if(j.size>10*1024*1024){V.error(`${j.name} is larger than 10 MB.`);continue}const B=j.name.split(".").pop()?.toLowerCase()??"jpg",H=`${r}/${t}/${crypto.randomUUID()}.${B}`,{error:Y}=await O.storage.from("report-photos").upload(H,j,{upsert:!1});if(Y){V.error(Y.message);continue}v+=1,await O.from("report_photos").insert({report_id:t,storage_path:H,sort_order:v,uploaded_by:o?.id??null})}T(!1),i.invalidateQueries({queryKey:["reports","photos",t]})},se=async(s,v)=>{const j=[...p.data??[]],B=s+v;if(B<0||B>=j.length)return;const H=j[s],Y=j[B];await O.from("report_photos").update({sort_order:B+1}).eq("id",H.id),await O.from("report_photos").update({sort_order:s+1}).eq("id",Y.id),i.invalidateQueries({queryKey:["reports","photos",t]})},_=yt({mutationFn:s=>Pt({data:{reportId:t,mode:s}}),onSuccess:(s,v)=>{if(z(!1),v==="test_to_me"){if(!s.ok){V.error(s.error==="no_recipients"?"We could not find your email address.":"The test email could not be sent.");return}V.success("Test sent to your inbox.");return}if(i.invalidateQueries({queryKey:["reports","report",t]}),i.invalidateQueries({queryKey:["reports","list",r]}),i.invalidateQueries({queryKey:["reports","jobs"]}),De("report_submitted",{job_number:n.data?.job_number,week_ending:u?.week_ending}),!s.ok){V.error(s.error==="no_recipients"?"Add at least one recipient before sending.":"The report was saved but the email could not be sent.");return}v==="send"?(De("report_sent",{job_number:n.data?.job_number,week_ending:u?.week_ending}),ce("recipients"in s&&Array.isArray(s.recipients)?s.recipients:(c.data??[]).map(j=>j.email))):V.success("Report submitted without sending.")},onError:s=>V.error(s.message)});if(a.isLoading||!u)return e.jsxs("div",{className:"max-w-6xl space-y-4",children:[e.jsx(re,{className:"h-8 w-52"}),e.jsx(re,{className:"h-28 rounded-xl"}),e.jsx(re,{className:"h-40 rounded-xl"}),e.jsx(re,{className:"h-40 rounded-xl"})]});if(!a.data)return e.jsx("p",{className:"text-sm text-ink/60",children:"That report could not be found."});const A=a.data.status==="submitted",K=(c.data??[]).map(s=>s.email),E=Array.from(new Set([...K,o?.email].filter(s=>!!(s&&s.trim())).map(s=>s.trim()))),I=(n.data?.pm_email??"").trim(),ne=I&&!E.some(s=>s.toLowerCase()===I.toLowerCase())?[I]:[];if(U)return e.jsx("div",{className:"mx-auto max-w-xl py-10",children:e.jsxs("div",{className:"rounded-xl border border-gold/35 bg-white p-6 text-center",children:[e.jsx(be,{className:"mx-auto h-9 w-9 text-gold","aria-hidden":"true"}),e.jsx("h1",{className:"display mt-3 text-2xl font-bold text-navy",children:"The report is on its way"}),e.jsxs("p",{className:"mt-2 text-sm text-ink/60",children:["Week ending ",Ee(u.week_ending)," for ",n.data?.property_name,"."]}),e.jsxs("ul",{className:"mx-auto mt-5 max-w-sm space-y-1 rounded-lg bg-cream p-4 text-left text-sm text-ink/70",children:[U.map(s=>e.jsx("li",{className:"truncate",children:s},s)),U.length===0&&e.jsx("li",{className:"text-ink/50",children:"No client recipients on this job yet."})]}),e.jsxs("div",{className:"mt-6 flex flex-wrap justify-center gap-2",children:[e.jsx(C,{asChild:!0,children:e.jsx(de,{to:"/reports/jobs/$jobId",params:{jobId:r},children:"Back to the job"})}),n.data?.share_token&&e.jsx(C,{asChild:!0,variant:"outline",children:e.jsx("a",{href:`/progress/${n.data.share_token}`,target:"_blank",rel:"noopener noreferrer",children:"Open the client view"})})]})]})});const Pe=e.jsxs("div",{className:"rounded-xl border border-ink/10 bg-white p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(fe,{className:"h-3.5 w-3.5 text-gold-deep","aria-hidden":"true"}),e.jsx("h2",{className:"text-[10px] font-bold uppercase tracking-[0.2em] text-ink/55",children:"Live email preview"})]}),W?e.jsx("div",{className:"h-[70vh] overflow-hidden rounded-lg border border-ink/10 bg-white",children:e.jsx("iframe",{title:"Weekly report email preview",srcDoc:W,className:"h-[117vh] w-[640px] origin-top-left scale-[0.55] border-0 bg-white sm:w-[700px] sm:scale-[0.5]"})}):e.jsx(re,{className:"h-[70vh] w-full rounded-lg"})]}),Re=e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-ink/10 bg-white p-4",children:[e.jsx("h2",{className:"mb-3 text-[10px] font-bold uppercase tracking-[0.2em] text-ink/55",children:"Milestones"}),e.jsxs("ul",{className:"space-y-2 text-sm",children:[(m.data??[]).map(s=>e.jsxs("li",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-ink/80",children:s.name}),e.jsx("span",{className:"shrink-0 text-xs text-ink/50",children:Nt[s.status]})]},s.id)),(m.data??[]).length===0&&e.jsx("li",{className:"text-sm text-ink/55",children:"No milestones yet."})]}),e.jsx(de,{to:"/reports/jobs/$jobId",params:{jobId:r},className:"mt-3 inline-block text-[10px] font-bold uppercase tracking-[0.16em] text-gold-deep underline-offset-4 hover:underline",children:"Edit milestones on the job"})]}),e.jsxs("div",{className:"rounded-xl border border-ink/10 bg-white p-4",children:[e.jsx("h2",{className:"mb-3 text-[10px] font-bold uppercase tracking-[0.2em] text-ink/55",children:"Recipients"}),e.jsxs("ul",{className:"space-y-1 text-sm text-ink/70",children:[K.map(s=>e.jsx("li",{className:"truncate",children:s},s)),K.length===0&&e.jsx("li",{className:"text-ink/55",children:"No recipients yet."})]})]})]});return e.jsxs("div",{className:"max-w-6xl pb-24",children:[e.jsx(de,{to:"/reports/jobs/$jobId",params:{jobId:r},className:"text-[10px] font-bold uppercase tracking-[0.2em] text-ink/50 transition-colors duration-150 hover:text-ink",children:"Back to job"}),e.jsxs("header",{className:"mb-6 mt-3 grid grid-cols-[minmax(0,1fr)_auto] items-start gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"truncate text-[10px] font-bold uppercase tracking-[0.22em] text-gold-deep",children:["Job ",n.data?.job_number," - ",n.data?.property_name]}),e.jsxs("h1",{className:"display mt-1 text-2xl font-bold text-navy sm:text-3xl",children:["Week ending ",Ee(u.week_ending)]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[A&&e.jsxs(C,{variant:"outline",size:"sm",className:"h-9",onClick:()=>z(!0),disabled:_.isPending,children:[e.jsx(fe,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),"Email this report"]}),e.jsx(_t,{label:A?"Submitted":"Draft",tone:A?"gold":"neutral"})]})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_380px]",children:[e.jsxs("div",{className:"min-w-0 space-y-4",children:[e.jsx(pe,{title:"Report details",icon:Fe,children:e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{htmlFor:"week_ending",children:"Week ending"}),e.jsx(me,{id:"week_ending",type:"date",className:"h-11",value:u.week_ending,onChange:s=>b({week_ending:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{htmlFor:"prepared_by",children:"Prepared by"}),e.jsx(me,{id:"prepared_by",className:"h-11",value:u.prepared_by_name,onChange:s=>b({prepared_by_name:s.target.value})}),n.data?.pm_name&&u.prepared_by_name.trim().toLowerCase()!==n.data.pm_name.trim().toLowerCase()&&e.jsxs("p",{className:"text-xs text-ink/55",children:["This job's project manager is ",n.data.pm_name,"."," ",e.jsx(de,{to:"/reports/jobs/$jobId",params:{jobId:r},className:"underline underline-offset-2",children:"Change it on the job page"}
1)," ","if that is wrong."]})]})]})}),e.jsx(pe,{title:"Total project completion",icon:be,help:"This drives the ring the client sees.",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-5",children:[e.jsxs("p",{className:"display text-5xl font-bold tabular-nums text-navy",children:[u.completion_pct,e.jsx("span",{className:"text-2xl align-super",children:"%"})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-1 items-center gap-3",children:[e.jsx(rt,{id:"completion","aria-label":"Completion percent",className:"flex-1",min:0,max:100,step:1,value:[u.completion_pct],onValueChange:([s])=>b({completion_pct:s??0})}),e.jsx(me,{type:"number",min:0,max:100,"aria-label":"Completion percent value",className:"h-11 w-20",value:u.completion_pct,onChange:s=>b({completion_pct:Math.max(0,Math.min(100,Number(s.target.value)||0))})})]}),e.jsx("div",{className:"flex gap-2",children:[5,10].map(s=>e.jsxs(C,{type:"button",variant:"outline",className:"h-11",onClick:()=>b({completion_pct:Math.min(100,u.completion_pct+s)}),children:["+",s]},s))})]})}),Es.map(({key:s,label:v,icon:j,help:B})=>{const H=te?te[s]??"":"";return e.jsxs(pe,{title:v,icon:j,help:B,children:[e.jsx(Vt,{id:s,"aria-label":v,rows:s==="message_to_client"?4:6,value:u[s],onChange:Y=>b({[s]:Y.target.value})}),H.trim()&&e.jsxs($t,{className:"mt-3",children:[e.jsxs(Ht,{className:"group flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-[0.16em] text-ink/45 transition-colors duration-150 hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-gold",children:["Last week you wrote",e.jsx(ft,{className:"h-3.5 w-3.5 transition-transform duration-200 group-data-[state=open]:rotate-180","aria-hidden":"true"})]}),e.jsx(Ot,{children:e.jsxs("div",{className:"mt-2 rounded-lg border border-ink/10 bg-cream p-3",children:[e.jsx("p",{className:"whitespace-pre-line text-xs leading-relaxed text-ink/65",children:H}),e.jsx(C,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>b({[s]:H}),children:"Copy to this week"})]})})]})]},s)}),e.jsxs(pe,{title:"Photos",icon:xt,help:"Drag images in or browse. Captions appear under each photo.",children:[e.jsxs("div",{onDragOver:s=>{s.preventDefault(),P(!0)},onDragLeave:()=>P(!1),onDrop:s=>{s.preventDefault(),P(!1),D(Array.from(s.dataTransfer.files))},className:oe("rounded-xl border-2 border-dashed p-6 text-center transition-colors duration-150",R?"border-gold bg-gold/8":"border-ink/15 bg-cream/40"),children:[e.jsx("input",{id:"photo-upload",type:"file",accept:"image/*",multiple:!0,className:"sr-only",onChange:s=>{D(Array.from(s.target.files??[]))}}),N?e.jsxs("p",{className:"flex items-center justify-center gap-2 text-sm text-ink/60",children:[e.jsx(ue,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}),"Uploading photos"]}):e.jsxs(e.Fragment,{children:[e.jsx(Xt,{className:"mx-auto h-5 w-5 text-ink/35","aria-hidden":"true"}),e.jsx("p",{className:"mt-2 text-sm text-ink/60",children:"Drag photos here"}),e.jsx(C,{asChild:!0,variant:"outline",className:"mt-3 h-11",children:e.jsx("label",{htmlFor:"photo-upload",className:"cursor-pointer",children:"Browse photos"})})]})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-3 sm:grid-cols-3",children:[(p.data??[]).map((s,v)=>e.jsxs("div",{className:"rounded-lg border border-ink/10 p-2",children:[e.jsx("img",{src:s.signed_url,alt:s.caption??`Progress photo for ${n.data?.property_name??"this job"}`,className:"aspect-video w-full rounded object-cover",loading:"lazy"}),e.jsx(me,{className:"mt-2 h-9 text-xs","aria-label":"Photo caption",placeholder:"Caption",defaultValue:s.caption??"",onBlur:async j=>{await O.from("report_photos").update({caption:j.target.value}).eq("id",s.id)}}),e.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[e.jsxs("div",{className:"flex",children:[e.jsx(C,{size:"icon",variant:"ghost","aria-label":"Move photo earlier",onClick:()=>{se(v,-1)},children:e.jsx(Zt,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(C,{size:"icon",variant:"ghost","aria-label":"Move photo later",onClick:()=>{se(v,1)},children:e.jsx(es,{className:"h-4 w-4","aria-hidden":"true"})})]}),e.jsx(C,{size:"icon",variant:"ghost","aria-label":"Remove photo",onClick:async()=>{await O.storage.from("report-photos").remove([s.storage_path]),await O.from("report_photos").delete().eq("id",s.id),i.invalidateQueries({queryKey:["reports","photos",t]})},children:e.jsx(Rt,{className:"h-4 w-4 text-emergency","aria-hidden":"true"})})]})]}
1,s.id)),(a.data.photo_urls??[]).map(s=>e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"rounded-lg border border-ink/10 p-2 text-xs text-ink/60 underline",children:"Legacy photo link"},s))]})]}),e.jsx("div",{className:"xl:hidden",children:e.jsxs(Ds,{defaultValue:"details",children:[e.jsxs(ct,{className:"w-full",children:[e.jsx(je,{value:"details",className:"flex-1",children:"Job details"}),e.jsx(je,{value:"preview",className:"flex-1",children:"Email preview"})]}),e.jsx(we,{value:"details",className:"mt-4",children:Re}),e.jsx(we,{value:"preview",className:"mt-4",children:Pe})]})})]}),e.jsxs("aside",{className:"hidden space-y-4 xl:block",children:[Pe,Re]})]}),e.jsx("div",{className:"fixed inset-x-0 bottom-0 z-30 border-t border-ink/10 bg-cream/95 px-4 py-3 backdrop-blur",children:e.jsxs("div",{className:"mx-auto flex max-w-6xl items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:"flex min-w-0 items-center gap-1.5 rounded-full bg-white px-2.5 py-1 text-[10px] font-bold uppercase tracking-[0.14em] text-ink/50 ring-1 ring-ink/10",children:[l==="saving"?e.jsx(ue,{className:"h-3 w-3 shrink-0 animate-spin","aria-hidden":"true"}):e.jsx(zt,{className:"h-3 w-3 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:l==="saving"?"Saving":w?`Saved ${y}`:"Draft"})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(C,{variant:"ghost",className:"hidden h-11 sm:inline-flex",onClick:()=>_.mutate("submit_only"),disabled:_.isPending,children:"Submit without sending"}),e.jsx(C,{variant:"outline",className:"hidden h-11 sm:inline-flex",onClick:()=>{Q(u)},children:"Save draft"}),e.jsxs(C,{className:"h-11 shrink-0 bg-gold text-ink hover:bg-gold-bright",onClick:()=>z(!0),disabled:_.isPending,children:[_.isPending?e.jsx(ue,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}):e.jsx(ts,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),A?"Update and resend":"Submit and send"]}),e.jsxs(Dt,{children:[e.jsx(Et,{asChild:!0,children:e.jsx(C,{variant:"outline",size:"icon",className:"h-11 w-11 shrink-0 sm:hidden","aria-label":"More actions",children:e.jsx(Mt,{className:"h-4 w-4","aria-hidden":"true"})})}),e.jsxs(It,{align:"end",side:"top",children:[e.jsx(xe,{onClick:()=>{Q(u)},children:"Save draft"}),e.jsx(xe,{onClick:()=>_.mutate("submit_only"),disabled:_.isPending,children:"Submit without sending"}),e.jsx(xe,{onClick:()=>_.mutate("test_to_me"),disabled:_.isPending,children:"Send a test to me"})]})]})]})]})}),e.jsx(Ut,{open:L,onOpenChange:z,children:e.jsxs(Wt,{children:[e.jsxs(Gt,{children:[e.jsx(Qt,{children:A?"Resend this report?":"Submit and send this report?"}),e.jsxs(Yt,{children:["It goes to ",E.length," recipient",E.length===1?"":"s",ne.length?", with the project manager on copy.":"."]})]}),e.jsxs("ul",{className:"max-h-40 space-y-1 overflow-y-auto text-sm text-ink/70",children:[E.map(s=>e.jsx("li",{className:"truncate",children:s},s)),ne.map(s=>e.jsxs("li",{className:"truncate text-ink/55",children:[s," (copy)"]},s)),E.length===0&&e.jsx("li",{className:"text-ink/55",children:"No recipients yet."})]}),e.jsxs(Jt,{children:[e.jsx(C,{variant:"outline",onClick:()=>z(!1),children:"Cancel"}),e.jsxs(C,{variant:"outline",onClick:()=>_.mutate("test_to_me"),disabled:_.isPending,children:[e.jsx(fe,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),"Send a test to me"]}),e.jsxs(C,{onClick:()=>_.mutate("send"),disabled:_.isPending,children:[_.isPending&&e.jsx(ue,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}),A?"Resend now":"Send now"]})]})]})})]})}export{tn as component};
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.