PageSourceSearch

https://stone-profit-flow.base44.app/assets/CustomerJobPortal-Bbrokzy8.js

js stone-profit-flow.base44.app collected 2026-10-03 03:11:21 UTC 38,886 bytes, 6 lines download raw bytes

1import{u as Pe,d as S,j as e,a as b}from"./vendor-query-B-_nDQQY.js";import{u as Me,L as he}from"./vendor-react-BUIlT3ms.js";import{y as qe,C as m,d as x,W as H,a as y,c as v,e as j,n as J,B as w,b as p,ac as De,J as _,r as pe,M as ge,a1 as Le,ap as Fe,U as je,ax as $e,ah as Te,L as Ie,w as fe,t as k,a4 as Re,m as me,F as M,v as Ne,I as ze}from"./index-D8ww6b7J.js";import{S as B}from"./skeleton-BNNdi7sc.js";import"./textarea-Bhj0eADY.js";import{L as Ae}from"./LiveTracking-JJZBSzAM.js";import{A as Je}from"./arrow-down-left-CPeAj20z.js";import{A as Ee}from"./arrow-up-right-DBBxPKcd.js";import{C as V}from"./circle-check-BXjz6L8_.js";import{C as Ue}from"./circle-x-CIIBFH3_.js";import{R as Oe}from"./reply-Cbt0RATV.js";import{f as P}from"./format-C2V2JF1Z.js";import{L as be}from"./layers-De-P0_bF.js";import{C as Ke}from"./circle-check-big-4Ew-rpqG.js";import{P as E}from"./phone-CA5yr35z.js";import{U as Be}from"./user-CHo1Apvy.js";import{M as Qe}from"./message-circle-Cg6XlpSC.js";import{E as We}from"./external-link-H0n6aDkP.js";import{P as xe}from"./package-kgQR05VR.js";import{N as Ge}from"./navigation-TAQUAeuu.js";import{C as Q}from"./camera-B5zm8J-v.js";import{W as He}from"./wallet-C4-qL3_a.js";import{S as Ve}from"./send-DJBvsBZ5.js";import{F as Ye}from"./file-pen-line-Cf5esZdC.js";import{P as Xe}from"./pen-line-B9s7pdJm.js";import"./vendor-three-1K-S22da.js";import"./vendor-charts-i-522T5A.js";import"./vendor-pdf-Bwkk3Ew0.js";import"./vendor-radix-X0WMATEu.js";/* empty css                */import"./vendor-leaflet-CQpbWEOL.js";import"./car-D_76LGWF.js";import"./differenceInMinutes-DsMRFadK.js";import"./differenceInMilliseconds-C_4QHjWc.js";import"./constants-yGZMfuMC.js";/**
2 * @license lucide-react v1.21.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 Ze=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],es=qe("file-exclamation-point",Ze);function ss({jobId:r,job:n}){Pe();const{data:c=[],isLoading:a}=S({queryKey:["job-messages",r],queryFn:()=>p.entities.Communication.filter({job_id:r},"-date",100),enabled:!!r});return a?e.jsx(m,{children:e.jsx(x,{className:"py-8 text-center text-muted-foreground text-sm",children:"Loading messages…"})}):c.length===0?e.jsx(m,{children:e.jsxs(x,{className:"py-12 text-center text-muted-foreground",children:[e.jsx(H,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"No messages yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Customer replies to appointment reminders will appear here."})]})}):e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-5 h-5 text-blue-500"}),"Customer Messages",e.jsx(j,{variant:"secondary",className:"ml-1",children:c.length})]})}),e.jsx(x,{className:"space-y-3",children:c.map(d=>{var h,l;const i=d.direction==="inbound",t=(h=d.subject)==null?void 0:h.includes("confirmed"),u=(l=d.subject)==null?void 0:l.includes("denied");return e.jsx("div",{className:`flex ${i?"justify-start":"justify-end"}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-lg p-3 ${i?t?"bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-800":u?"bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-800":"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800":"bg-muted border border-border"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[i?e.jsx(Je,{className:"w-3 h-3 text-blue-500"}):e.jsx(Ee,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-[10px] font-medium text-muted-foreground uppercase",children:d.type==="text"?"SMS":d.type}),t&&e.jsx(V,{className:"w-3 h-3 text-green-500"}),u&&e.jsx(Ue,{className:"w-3 h-3 text-red-500"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ml-auto flex items-center gap-0.5",children:[e.jsx(J,{className:"w-2.5 h-2.5"}
6),d.date?P(new Date(d.date),"MMM d, h:mm a"):""]})]}),d.subject&&!t&&!u&&e.jsx("p",{className:"text-xs font-semibold mb-0.5",children:d.subject}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:d.notes||d.subject}),d.follow_up_required&&e.jsx(j,{variant:"outline",className:"mt-2 text-[9px] bg-amber-50 text-amber-700 border-amber-200",children:"Follow-up needed"}),i&&(n==null?void 0:n.customer_phone)&&e.jsxs(w,{variant:"ghost",size:"sm",className:"mt-2 h-7 text-xs gap-1",onClick:()=>{window.location.href=`sms:${n.customer_phone}`},children:[e.jsx(Oe,{className:"w-3 h-3"})," Reply"]})]})},d.id)})})]})}function ts({pieces:r}){if(!r||r.length===0)return null;const n=r.filter(a=>a.status==="completed"||a.status==="ready").length,c=Math.round(n/r.length*100);return e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(be,{className:"w-5 h-5 text-primary"}),"Production Pieces",e.jsx(j,{variant:"secondary",className:"ml-1",children:r.length})]})}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Progress"}),e.jsxs("span",{className:"font-medium",children:[c,"% Complete"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:e.jsx("div",{className:"bg-primary h-2 rounded-full transition-all",style:{width:`${c}%`}})})]}),e.jsx("div",{className:"space-y-2",children:r.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-card",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.name||a.piece_name||"Unnamed Piece"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a.length&&a.width?`${a.length}" × ${a.width}"`:"",a.material_type&&` · ${a.material_type}`]})]}),e.jsx(j,{variant:a.status==="completed"||a.status==="ready"?"default":a.status==="in_progress"||a.status==="cutting"||a.status==="polishing"?"secondary":"outline",className:"text-xs",children:a.status||"pending"})]},a.id))})]})]})}function as({checklist:r}){if(!r||r.length===0)return null;const n=r.filter(a=>a.done).length,c=Math.round(n/r.length*100);return e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(De,{className:"w-5 h-5 text-primary"}),"Project Checklist",e.jsxs(j,{variant:"secondary",className:"ml-1",children:[n,"/",r.length]})]})}),e.jsxs(x,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Completion"}),e.jsxs("span",{className:"font-medium",children:[c,"%"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:e.jsx("div",{className:"bg-primary h-2 rounded-full transition-all",style:{width:`${c}%`}})})]}),e.jsx("div",{className:"space-y-2",children:r.map((a,d)=>e.jsxs("div",{className:_("flex items-center gap-3 p-3 rounded-lg border",a.done?"bg-green-50 dark:bg-green-950/20 border-green-200 dark:border-green-800":"bg-card"),children:[e.jsx("div",{className:_("w-5 h-5 rounded-full border-2 flex items-center justify-center",a.done?"bg-green-600 border-green-600 text-white":"border-muted-foreground"),children:a.done&&e.jsx(Ke,{className:"w-3 h-3"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:_("text-sm",a.done?"line-through text-muted-foreground":"font-medium"),children:a.title}),a.assigned_to&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Assigned to: ",a.assigned_to]})]}),a.due_date&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(pe,{className:"w-3 h-3"}),e.jsx("span",{children:P(new Date(a.due_date),"MMM d")})]})]},d))})]})]})}function rs({packages:r}){return!r||r.length===0?null:e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(be,{className:"w-5 h-5 text-primary"}),"Project Packages",e.jsx(j,{variant:"secondary",className:"ml-1",children:r.length})]})}),e.jsx(x,{className:"space-y-3",children:r.map((n,c)=>{var a;return e.jsxs("div",{className:"p-4 rounded-lg border bg-card space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-semibold",children:n.name||`Package ${c+1}`}),e.jsx(j,{variant:"outline",children:n.material_type})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Size:"}),e.jsxs("span",{className:"font-medium",children:[n.sqft," sqft"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Price:"}),e.jsxs("span",{className:"font-medium",children:["$",(a=n.selling_price)==null?void 0:a.toLocaleStr
6ing()]})]})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-xs",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-1",children:"Template"}),e.jsx(j,{variant:n.templating_status==="completed"?"default":n.templating_status==="in_progress"?"secondary":"outline",className:"text-[10px]",children:n.templating_status})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-1",children:"Cutting"}),e.jsx(j,{variant:n.cutting_status==="completed"?"default":n.cutting_status==="in_progress"?"secondary":"outline",className:"text-[10px]",children:n.cutting_status})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-1",children:"Install"}),e.jsx(j,{variant:n.installation_status==="completed"?"default":n.installation_status==="in_progress"?"secondary":"outline",className:"text-[10px]",children:n.installation_status})]})]})})]},c)})})]})}function ns({job:r}){const{data:n}=S({queryKey:["quote-settings-portal-branding"],queryFn:()=>p.entities.QuoteSettings.list().then(l=>l[0]||null),staleTime:6e5}),{data:c}=S({queryKey:["company-profile-portal-branding"],queryFn:()=>p.entities.CompanyProfile.list().then(l=>l[0]||null),staleTime:600*1e3}),a=(n==null?void 0:n.company_name)||(c==null?void 0:c.company_name)||"Countertops",d=n==null?void 0:n.company_logo_url,i=(n==null?void 0:n.phone)||(c==null?void 0:c.phone),t=n==null?void 0:n.email,u=n==null?void 0:n.website,h=(n==null?void 0:n.primary_color)||"#1d4ed8";return e.jsx("header",{className:"border-b",style:{backgroundColor:h},children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[d?e.jsx("img",{src:d,alt:a,className:"h-9 w-auto object-contain rounded bg-white/10 p-1 max-w-[160px]"}):e.jsx("div",{className:"h-9 px-3 rounded-lg bg-white/15 flex items-center justify-center text-white font-heading font-bold text-base",children:a}),d&&e.jsx("span",{className:"text-white font-heading font-bold text-sm sm:text-base truncate hidden sm:block",children:a})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[i&&e.jsxs("a",{href:`tel:${i}`,className:"text-white/85 hover:text-white flex items-center gap-1 text-xs",title:i,children:[e.jsx(E,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:i})]}),t&&e.jsx("a",{href:`mailto:${t}`,className:"text-white/85 hover:text-white",title:t,children:e.jsx(ge,{className:"w-4 h-4"})}),u&&e.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer",className:"text-white/85 hover:text-white",title:"Website",children:e.jsx(Le,{className:"w-4 h-4"})})]})]})})}function ls({job:r}){const n=(r==null?void 0:r.assigned_employee_ids)||[],{data:c=[]}=S({queryKey:["portal-crew",n.join(",")],queryFn:()=>n.length>0?p.entities.Employee.filter({id:{$in:n}}):Promise.resolve([]),enabled:n.length>0,staleTime:300*1e3}),a=(r==null?void 0:r.assigned_employee_names)||[],d=c.length>0,i=a.length>0;if(!d&&!i)return null;const u=(r==null?void 0:r.status)==="installation"||(r==null?void 0:r.status)==="quality_control"?"Your Installation Crew":"Your Project Team",h=[...c.map(l=>({name:l.name,role:l.role||"Crew Member",photo:l.profile_photo_url||l.selfie_url,rating:l.average_rating})),...a.filter(l=>!c.find(C=>C.name===l)).map(l=>({name:l,role:"Crew Member",photo:null,rating:null}))];return e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(Fe,{className:"w-5 h-5 text-primary"}),u]})}),e.jsx(x,{children:e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:h.map((l,C)=>e.jsxs("div",{className:"flex flex-col items-center text-center p-3 rounded-lg border bg-card",children:[e.jsx("div",{className:"w-14 h-14 rounded-full overflow-hidden border-2 border-primary/20 mb-2 bg-muted",children:l.photo?e.jsx("img",{src:l.photo,alt:l.name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full bg-primary/10 flex items-center justify-center",children:e.jsx(je,{className:"w-6 h-6 text-primary/50"})})}),e.jsx("p",{className:"text-sm font-medium truncate w-full",children:l.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate w-full",children:l.role}),l.rating>0&&e.jsxs(j,{variant:"outline",className:"text-[10px] mt-1",children:["★ ",l.rating.toFixed(1)]})]},C))})})]})}function is({job:r}){const[n,c]=b.useState(null),[a,d]=b.useState(!1),i=(r==null?void 0:r.assigned_employee_ids)||[],{data:t=[]}=S({queryKey:["portal-team",i.join(",")],queryFn:()=>i.length>0?p.entities.Employee.filter({id:{$in:i}}):Promise.resolve([]),enabled:i.length>0,staleTime:300*1e3}),u=[...r!=null&&r.salesperson_name?[{name:r.salesperson_name,role:"Sales Representative",phone:null,email:null,photo:null}]:[],...t.map(l=>({name:l.name,role:l.role||"Crew Member",phone:l.phone,email:l.email,photo:l.profile_photo_url||l.selfie_url})),...((r==null?void 0:r.assigned_employee_names)||[]).filter(l=>!t.find(C=>
6C.name===l)).map(l=>({name:l,role:"Crew Member",phone:null,email:null,photo:null}))].filter((l,C,D)=>D.findIndex(T=>T.name===l.name)===C);if(u.length===0)return null;const h=a?u:u.slice(0,2);return e.jsx(m,{children:e.jsxs(x,{className:"pt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(je,{className:"w-5 h-5 text-primary"}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Your Team"})]}),e.jsx("div",{className:"space-y-2",children:h.map((l,C)=>{const D=(n==null?void 0:n.name)===l.name;return e.jsxs("div",{className:_("flex items-center gap-3 p-2 rounded-lg border transition-colors",D?"border-primary bg-primary/5":"border-border"),children:[e.jsxs("button",{onClick:()=>c(D?null:l),className:"flex items-center gap-3 flex-1 min-w-0 text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-full overflow-hidden border border-border shrink-0 bg-muted",children:l.photo?e.jsx("img",{src:l.photo,alt:l.name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full bg-primary/10 flex items-center justify-center",children:e.jsx(Be,{className:"w-5 h-5 text-primary/50"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:l.name}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:l.role})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[l.phone&&e.jsx(w,{size:"icon",variant:"ghost",className:"h-8 w-8",asChild:!0,children:e.jsx("a",{href:`tel:${l.phone}`,children:e.jsx(E,{className:"w-3.5 h-3.5"})})}),l.email&&e.jsx(w,{size:"icon",variant:"ghost",className:"h-8 w-8",asChild:!0,children:e.jsx("a",{href:`mailto:${l.email}`,children:e.jsx(Qe,{className:"w-3.5 h-3.5"})})})]})]},C)})}),u.length>2&&e.jsxs(w,{variant:"ghost",size:"sm",className:"w-full mt-2",onClick:()=>d(!a),children:[a?e.jsx($e,{className:"w-4 h-4 mr-1"}):e.jsx(Te,{className:"w-4 h-4 mr-1"}),a?"Show Less":`Show All ${u.length}`]})]})})}function cs({job:r}){const[n,c]=b.useState(!1),{data:a}=S({queryKey:["quote-settings-review-btn"],queryFn:()=>p.entities.QuoteSettings.list().then(h=>h[0]||null),staleTime:600*1e3}),{data:d}=S({queryKey:["company-profile-review-btn"],queryFn:()=>p.entities.CompanyProfile.list().then(h=>h[0]||null),staleTime:600*1e3}),i=(d==null?void 0:d.company_name)||(a==null?void 0:a.company_name)||"countertop company",t=(a==null?void 0:a.google_review_link)||`https://www.google.com/search?q=${encodeURIComponent(i+" reviews")}`,u=async()=>{var h;c(!0);try{(h=(await p.functions.invoke("sendGoogleReviewRequest",{job_id:r.id,customer_phone:r.customer_phone,customer_email:r.customer_email})).data)!=null&&h.success?k.success("Review request sent! Check your email."):window.open(t,"_blank")}catch{window.open(t,"_blank")}c(!1)};return r.status!=="completed"?null:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(w,{onClick:u,disabled:n,className:"w-full",size:"lg",children:[n?e.jsx(Ie,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(fe,{className:"w-4 h-4 mr-2"}),n?"Sending...":"Leave Us a Review"]}),e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-center text-primary hover:underline flex items-center justify-center gap-1",children:["Open Google Reviews ",e.jsx(We,{className:"w-3 h-3"})]})]})}const W=["quote","template","cnc_programming","cutting","polishing","installation","completed"],ue={quote:"Quote",template:"Templating",cnc_programming:"CNC Programming",cutting:"Cutting",polishing:"Polishing",installation:"Installation",completed:"Complete"};function Bs(){var le,ie,ce,de;const{jobId:r}=Me(),c=new URLSearchParams(window.location.search).get("token"),[a,d]=b.useState(null),i=r||a,[t,u]=b.useState(null),[h,l]=b.useState([]),[C,D]=b.useState(!0),[T,Y]=b.useState(!1),[ye,ve]=b.useState(new Date),[I,X]=b.useState(""),[L,Z]=b.useState(0),[ee,se]=b.useState("");b.useEffect(()=>{c&&!r&&!a&&p.functions.invoke("generatePortalToken",{action:"validate",token:c}).then(s=>{var o,f;(o=s.data)!=null&&o.valid&&((f=s.data)!=null&&f.job_id)?d(s.data.job_id):k.error("Invalid or expired link")}
6).catch(()=>k.error("Invalid or expired link"))},[c,r,a]);const{data:g}=S({queryKey:["job-quote",i],queryFn:()=>p.entities.Quote.filter({converted_to_job_id:i}).then(s=>s[0]||null),enabled:!!i,staleTime:300*1e3}),{data:U=[]}=S({queryKey:["job-activities-portal",i],queryFn:()=>p.entities.ScheduledActivity.filter({job_id:i},"scheduled_date"),enabled:!!i,staleTime:300*1e3}),{data:we=[]}=S({queryKey:["job-pieces",i],queryFn:()=>p.entities.ProductionPiece.filter({job_id:i},"-created_date"),enabled:!!i,staleTime:300*1e3}),{data:R=[]}=S({queryKey:["job-change-orders",i],queryFn:()=>{var s;return((s=p.entities.ChangeOrder)==null?void 0:s.filter({job_id:i}))||Promise.resolve([])},enabled:!!i,staleTime:300*1e3});b.useEffect(()=>{if(!i)return;const s=p.entities.Job.subscribe(f=>{var N;((N=f.data)==null?void 0:N.id)===i&&z()}),o=p.entities.JobPhoto.subscribe(f=>{var N;((N=f.data)==null?void 0:N.job_id)===i&&z()});return()=>{s(),o()}},[i]);async function z(){try{const s=await p.entities.Job.get(i);u(s);const o=await p.entities.JobPhoto.filter({job_id:i},"-created_date");l(o),ve(new Date),(Object.values(s.employee_completion_status||{}).some(F=>F==="traveling"||F==="on_site")||s.driver_status==="started"||s.driver_status==="in_progress")&&Y(!0)}finally{D(!1)}}b.useEffect(()=>{z();const s=setInterval(()=>{z()},3e4);return()=>clearInterval(s)},[i]);const te=async()=>{if(!(!I.trim()||!t))try{await p.entities.Communication.create({job_id:i,customer_id:t.customer_name,customer_name:t.customer_name,type:"text",direction:"inbound",notes:I,date:new Date().toISOString()}),k.success("Message sent!"),X("")}catch{k.error("Failed to send message")}},_e=async()=>{if(!(!t||L===0))try{await p.entities.Job.update(i,{customer_survey:{rating:L,feedback:ee,submitted_at:new Date().toISOString(),would_recommend:L>=4,all_positive:L>=4}}),k.success("Thank you for your feedback!"),Z(0),se("")}catch{k.error("Failed to submit survey")}};if(C)return e.jsx("div",{className:"min-h-screen bg-background p-3 sm:p-6",children:e.jsxs("div",{className:"max-w-5xl mx-auto space-y-4",children:[e.jsx(B,{className:"h-12 w-full"}),e.jsx(B,{className:"h-24 w-full"}),e.jsx(B,{className:"h-64 w-full"})]})});if(!t)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-6",children:e.jsx(m,{className:"max-w-md text-center",children:e.jsxs(x,{className:"pt-6",children:[e.jsx(xe,{className:"w-12 h-12 text-muted-foreground mx-auto mb-3 opacity-50"}),e.jsx("h1",{className:"text-xl font-heading font-bold mb-2",children:"Job Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This job link may be invalid or expired."})]})})});const O=W.indexOf(t.status),A=Object.values(t.employee_completion_status||{}).some(s=>s==="traveling"||s==="on_site")||t.driver_status==="started"||t.driver_status==="in_progress",K=h.filter(s=>s.is_visible_to_customer),Ce=(t.deposit_amount||0)+((g==null?void 0:g.payment_amount_paid)||0),ke=t.selling_price||0,ae=Math.max(0,ke-Ce),re=s=>{if(s==="quote")return t.created_date;const f={template:["template","templating"],cnc_programming:["cnc","programming"],cutting:["cutting","cut"],polishing:["polish","polishing"],installation:["install","installation"],completed:["install","installation"]}[s];if(!f)return t.job_date;const N=U.find(F=>f.some(Se=>{var oe;return(oe=F.activity_name)==null?void 0:oe.toLowerCase().includes(Se)}));return(N==null?void 0:N.completed_at)||(N==null?void 0:N.scheduled_date)},ne=s=>{if(!s)return null;try{return P(new Date(s),"MMM d")}catch{return null}};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(ns,{job:t}),e.jsx("header",{className:"sticky top-0 z-50 bg-background/95 backdrop-blur border-b",children:e.jsx("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(w,{variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",asChild:!0,children:e.jsx(he,{to:"/",children:e.jsx(Re,{className:"w-4 h-4"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-lg font-heading font-bold truncate",children:t.customer_name}),t.job_address&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1 truncate",children:[e.jsx(me,{className:"w-3 h-3 shrink-0"}),e.jsx("span",{className:"truncate",children:t.job_address})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[A&&e.jsxs(j,{className:"bg-accent/10 text-accent-foreground border border-accent/20 gap-1",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-accent rounded-full animate-pulse"}),"LIVE"]}),e.jsx(j,{className:_("border",t.status==="completed"?"bg-primary/10 text-primary border-primary/20":"bg-
6accent/10 text-accent-foreground border-accent/20"),children:ue[t.status]||t.status})]})]})})}),e.jsxs("main",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-6 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(m,{className:_("cursor-pointer transition-shadow hover:shadow-md",A&&"ring-2 ring-accent"),onClick:()=>Y(!T),children:e.jsxs(x,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"p-2 bg-accent/10 rounded-lg",children:e.jsx(Ge,{className:"w-4 h-4 text-accent-foreground animate-bounce"})}),A&&e.jsx(j,{className:"bg-accent text-accent-foreground text-[10px] animate-pulse",children:"Active"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase",children:"Live Tracking"}),e.jsx("p",{className:"text-sm font-bold",children:A?"Active":"Tap to view"})]})}),e.jsx(m,{children:e.jsxs(x,{className:"p-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(Q,{className:"w-4 h-4 text-primary"})})}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase",children:"Photos"}),e.jsx("p",{className:"text-sm font-bold",children:h.length})]})}),e.jsx(m,{children:e.jsxs(x,{className:"p-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(M,{className:"w-4 h-4 text-primary"})})}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase",children:"Documents"}),e.jsx("p",{className:"text-sm font-bold",children:t.pdf_url?"Ready":"Pending"})]})}),e.jsx(m,{children:e.jsxs(x,{className:"p-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(He,{className:"w-4 h-4 text-primary"})})}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase",children:"Balance"}),e.jsxs("p",{className:_("text-sm font-bold",ae>0?"text-destructive":"text-primary"),children:["$",ae.toLocaleString()]})]})})]}),T&&e.jsx(m,{className:"overflow-hidden",children:e.jsx(Ae,{job:t})}),e.jsxs("div",{className:"grid lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(pe,{className:"w-5 h-5 text-primary"}),"Project Status"]}),e.jsxs(j,{variant:"outline",className:"text-xs gap-1",children:[e.jsx(V,{className:"w-3 h-3 text-primary"}),"On schedule"]})]})}),e.jsx(x,{children:e.jsx("div",{className:"space-y-1",children:W.map((s,o)=>{const f=O>o,N=O===o,F=O<o;return e.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[e.jsxs("div",{className:"flex-shrink-0 relative",children:[f?e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary flex items-center justify-center",children:e.jsx(V,{className:"w-4 h-4 text-primary-foreground"})}):N?e.jsxs("div",{className:"w-8 h-8 rounded-full bg-accent flex items-center justify-center relative",children:[e.jsx("div",{className:"absolute inset-0 rounded-full bg-accent/40 animate-ping"}),e.jsx(J,{className:"w-4 h-4 text-accent-foreground relative z-10 animate-spin",style:{animationDuration:"3s"}})]}):e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-muted flex items-center justify-center",children:e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-muted-foreground/40"})}),o<W.length-1&&e.jsx("div",{className:_("absolute left-1/2 -translate-x-1/2 top-8 w-0.5 h-6",f?"bg-primary":"bg-muted")})]}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:_("text-sm font-medium",f?"text-foreground":N?"text-accent-foreground":"text-muted-foreground"),children:ue[s]})}),e.jsxs("div",{className:"flex-shrink-0",children:[f&&e.jsx("span",{className:"text-xs text-muted-foreground",children:ne(re(s))||"Done"}),N&&e.jsx(j,{className:"bg-accent/10 text-accent-foreground text-xs",children:"NOW"}),F&&e.jsx("span",{className:"text-xs text-muted-foreground",children:ne(re(s))||"Pending"})]})]},s)})})})]}),e.jsx(ls,{job:t}),e.jsx(ts,{pieces:we}),e.jsx(as,{checklist:t.checklist}),U.length>0&&e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(J,{className:"w-5 h-5 text-primary"}),"Scheduled Appointments"]})}),e.jsx(x,{children:e.jsx("div",{className:"space-y-2",children:U.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-lg border bg-card",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${s.status==="completed"?"bg-green-100 text-green-600":s.status==="in_progress"?"bg-blue-100 text-blue-600":s.status==="cancelled"?"bg-red-100 text-red-600":"bg-amber-100 text-amber-600"}`,children:e.jsx(J,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s.activity_name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[new Date(s.scheduled_date).toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),s.scheduled_time&&` at ${s.scheduled_time}`,s.assigned_employee_name&&` · ${s.assigned_employee_name}`]})]})]}),e.jsx(j,{variant:s.status==="completed"?"default":s.status==="in_progress"?"secondary":s.status==="cancelled"?"destructive":"outline",className:"text-xs",children:s.status==="pending"?"Scheduled":s.status.replace(/_/g," ")})]},s.id))})})]}),(R==null?void 0:R.filter(s=>s.status==="pending_customer_approval").length)>0&&e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(es,{className:"w-5 h-5 text-amber-600"}),"Change Orders Requiring Approval"]})}),e.jsx(x,{className:"space-y-3",children:R.filter(s=>s.status==="pending_customer_approval").map(s=>{var o;return e.jsxs("div",{className:"p-4 rounded-lg border bg-amber-50 dark:bg-amber-950/20 border-amber-200",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:s.description||s.title}),e.jsxs("p",{className:"text-lg font-bold text-amber-700 mb-3",children:["$",((o=s.price_adjustment)==null?void 0:o.toLocaleStr
6ing())||"0"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(w,{size:"sm",onClick:async()=>{try{await p.entities.ChangeOrder.update(s.id,{status:"approved",customer_approved_date:new Date().toISOString()}),k.success("Change order approved!")}catch{k.error("Failed to approve")}},children:"Approve"}),e.jsx(w,{variant:"outline",size:"sm",onClick:async()=>{try{await p.entities.ChangeOrder.update(s.id,{status:"declined",customer_declined_date:new Date().toISOString()}),k.success("Change order declined")}catch{k.error("Failed to decline")}},children:"Decline"})]})]},s.id)})})]}),K.length>0&&e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(Q,{className:"w-5 h-5 text-primary"}),"Site Photos",e.jsx(j,{variant:"secondary",className:"ml-1",children:K.length})]})}),e.jsx(x,{children:e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:K.map((s,o)=>e.jsxs("div",{className:"group relative aspect-square rounded-lg overflow-hidden bg-muted cursor-pointer",children:[e.jsx("img",{src:s.photo_url,alt:`Site ${o+1}`,className:"w-full h-full object-cover transition-transform duration-300 group-hover:scale-110"}),e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/60 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:[s.taken_by_name&&e.jsxs("p",{className:"text-[10px] text-white/90 truncate",children:["📷 ",s.taken_by_name]}),s.taken_at&&e.jsx("p",{className:"text-[10px] text-white/70",children:P(new Date(s.taken_at),"MMM d, h:mm a")})]})]},s.id))})})]}),h.length>0&&e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(Q,{className:"w-5 h-5 text-primary"}),"Project Gallery",e.jsx(j,{variant:"secondary",className:"ml-1",children:h.length})]})}),e.jsx(x,{children:e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:h.map((s,o)=>e.jsxs("div",{className:"group relative aspect-square rounded-lg overflow-hidden bg-muted cursor-pointer",children:[e.jsx("img",{src:s.photo_url||s.url||s.image_url,alt:`Project ${o+1}`,className:"w-full h-full object-cover transition-transform duration-300 group-hover:scale-110"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/50 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity"}),(s.photo_url||s.url)&&e.jsx(w,{size:"icon",variant:"secondary",className:"absolute bottom-2 right-2 h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",asChild:!0,children:e.jsx("a",{href:s.photo_url||s.url,target:"_blank",rel:"noopener noreferrer",children:e.jsx(Ne,{className:"w-3 h-3"})})})]},s.id))})})]}),e.jsx(ss,{jobId:i,job:t}),e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(H,{className:"w-5 h-5 text-primary"}),"Send a Message"]})}),e.jsx(x,{children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ze,{placeholder:"Type your message...",value:I,onChange:s=>X(s.target.value),onKeyDown:s=>s.key==="Enter"&&te()}),e.jsx(w,{onClick:te,disabled:!I.trim(),children:e.jsx(Ve,{className:"w-4 h-4"})})]})})]}),t.status==="completed"&&!t.customer_survey&&e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(fe,{className:"w-5 h-5 text-primary"}),"How Did We Do?"]})}),e.jsxs(x,{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-1",children:[1,2,3,4,5].map(s=>e.jsx("button",{onClick:()=>Z(s),className:_("text-3xl transition-transform hover:scale-110",s<=L?"text-yellow-500":"text-gray-300"),children:"★"},s))}),L>0&&e.jsxs(e.Fragment,{children:[e.jsx("textarea",{className:"w-full p-3 border rounded-lg text-sm resize-none",rows:3,placeholder:"Tell us about your experience...",value:ee,onChange:s=>se(s.target.value)}),e.jsx(w,{onClick:_e,className:"w-full",children:"Submit Feedback"})]})]})]}),t.status==="completed"&&e.jsx(m,{children:e.jsx(x,{className:"pt-4",children:e.jsx(cs,{job:t})})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(is,{job:t}),e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(xe,{className:"w-5 h-5 text-primary"}),"Project Details"]}
6)}),e.jsxs(x,{className:"space-y-2",children:[e.jsx($,{label:"Material",value:t.material_type||"TBD",capitalize:!0}),e.jsx($,{label:"Square Feet",value:`${t.square_feet||"0"} sqft`}),e.jsx($,{label:"Scheduled",value:t.job_date?P(new Date(t.job_date),"MMM d, yyyy"):"TBD"}),e.jsx($,{label:"Job Number",value:t.job_number||"N/A"}),t.zip_code&&e.jsx($,{label:"ZIP Code",value:t.zip_code})]})]}),e.jsx(rs,{packages:t.packages}),e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(M,{className:"w-5 h-5 text-primary"}),"Documents"]})}),e.jsxs(x,{className:"space-y-3",children:[g&&e.jsx(q,{icon:M,title:`Quote ${g.quote_number||""}`,subtitle:g.created_date?P(new Date(g.created_date),"MMM d, yyyy"):"Quote",action:"View Quote",href:`/sign-quote?sign=${g.id}`}),g!=null&&g.customer_signature?e.jsx(q,{icon:Ye,title:"Signed Contract",subtitle:g.signature_date?P(new Date(g.signature_date),"MMM d, yyyy"):"Contract Signed",action:"View Contract",href:`/sign-quote?sign=${g.id}`,primary:!0}):g&&(g.contract_status==="sent"||!g.customer_signature)?e.jsx(q,{icon:Xe,title:"Sign Your Contract",subtitle:g.contract_status==="sent"?"Awaiting signature":"E-signature required",action:"Sign Now",href:`/sign-quote?sign=${g.id}`,primary:!0}):null,t.pdf_url&&e.jsx(q,{icon:M,title:"Shop Drawing",subtitle:"PDF Document",url:t.pdf_url}),((le=t.template_checklist)==null?void 0:le.pdf_url)&&e.jsx(q,{icon:M,title:"Template Drawing",subtitle:"Field measurements",url:t.template_checklist.pdf_url}),(ce=(ie=t.template_checklist)==null?void 0:ie.dxf_files)==null?void 0:ce.map((s,o)=>e.jsx(q,{icon:M,title:`DXF File ${o+1}`,subtitle:"CAD drawing",url:s},o)),(de=t.field_documents)==null?void 0:de.map((s,o)=>e.jsx(q,{icon:M,title:s.name||`Document ${o+1}`,subtitle:s.uploaded_at?P(new Date(s.uploaded_at),"MMM d, yyyy"):"Field Document",url:s.url},o)),!g&&!t.pdf_url&&(!t.field_documents||t.field_documents.length===0)&&e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(M,{className:"w-8 h-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"Documents will be available soon"})]})]})]}),e.jsxs(m,{children:[e.jsx(y,{children:e.jsxs(v,{className:"font-heading flex items-center gap-2",children:[e.jsx(E,{className:"w-5 h-5 text-primary"}),"Contact Us"]})}),e.jsxs(x,{className:"space-y-2",children:[e.jsx(G,{icon:E,label:"Call Us",value:"(555) 123-4567",href:"tel:5551234567"}),e.jsx(G,{icon:ge,label:"Email",value:"[email protected]",href:"mailto:[email protected]"}),e.jsx(G,{icon:me,label:"Showroom",value:"123 Countertop Lane"})]})]})]})]}),e.jsxs("footer",{className:"text-center py-6 border-t",children:[e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 bg-primary rounded-full animate-pulse"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Live updates enabled"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last updated: ",P(ye,"h:mm:ss a")]})]})]})]})}function $({label:r,value:n,capitalize:c}){return e.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-border last:border-0",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:r}),e.jsx("span",{className:_("text-sm font-semibold",c&&"capitalize"),children:n})]})}function q({icon:r,title:n,subtitle:c,url:a,action:d,href:i,primary:t}){const u=e.jsxs("div",{className:_("flex items-center justify-between p-3 rounded-lg border transition-colors",t?"bg-primary/5 border-primary/30 hover:bg-primary/10":"bg-muted/50 border-border hover:bg-muted"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:_("w-9 h-9 rounded-lg flex items-center justify-center",t?"bg-primary text-primary-foreground":"bg-primary/10 text-primary"),children:e.jsx(r,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:n}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c})]})]}),d?e.jsx(w,{size:"sm",variant:t?"default":"outline",children:d}):e.jsx(w,{size:"icon",variant:"ghost",className:"h-8 w-8",children:e.jsx(Ne,{className:"w-4 h-4"})})]});return i?e.jsx(he,{to:i,children:u}):a?e.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",children:u}):u}function G({icon:r,label:n,value:c,href:a}){const d=e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(r,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:n}),e.jsx("div",{className:"text-sm font-semibold truncate",children:c})]})]});return a?e.jsx("a",{href:a,children:d}):d}export{Bs 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.