PageSourceSearch

https://senioradvisor.co.nz/assets/ReceptionPortal-voCl4Tfh.js

js senioradvisor.co.nz collected 2026-10-09 22:03:25 UTC 267,119 bytes, 15 lines download raw bytes

1import{j as e}from"./ui-vendor-DSl4G1OJ.js";import{c as $t,q as tt,r as st,G as P,T as Qt,B as k,p as U,ae as Ma,a2 as Ie,ay as zs,W as Bs,a as $,ab as at,bp as lt,ba as Oa,bc as Ia,bd as Va,be as qa,bf as Ua,a0 as Ka,_ as B,X as as,j as pe,Y as oe,c2 as gs,D as ce,e as de,f as me,g as xe,i as he,h as kt,al as mt,an as ee,ao as te,ap as se,aq as ae,ar as q,aw as za,aP as Dt,w as Ba,x as Qa,F as Wa,R as Qs,aJ as Ha,aj as Ws,ax as Ya,aE as Rt,b7 as Ga,bm as Za,J as Ja}from"./index-iv8p4bGb.js";import{a as i,L as At,k as Xa,l as en}from"./react-vendor-JYAUlju1.js";import{u as tn}from"./useSignInFreshness-CPGLrYS5.js";import{I as O}from"./input-Cbpm_RuX.js";import{l as Hs}from"./darkmodebg-C8gitIld.js";import{l as sn,f as Ze,u as xt,r as Be,a as Lt,b as an,c as nn,d as rn,n as Ys,e as Gs,g as fs,h as ln,i as ns,R as Zs,j as Js,k as on,m as Xs,o as cn,t as rs,p as ie,q as ea,s as is,v as ta,w as sa,x as aa,y as dn,z as mn,A as xn,B as pn,C as un,D as na,E as hn,F as gn,G as fn,V as jn,H as bn,I as vn,J as yn,K as ra,L as Nn,M as wn,N as js,O as kn,P as _n,Q as Cn,S as Sn,T as Rn,U as Pn,W as En,X as Tn,Y as Fn,Z as $n,_ as Dn,$ as An,a0 as Ln,a1 as Mn,a2 as ia,a3 as la,a4 as On,a5 as In,a6 as oa,a7 as Vn,a8 as qn,a9 as Un,aa as Kn,ab as zn}from"./receptionStore-CzXKKwCp.js";import{L as bs}from"./leaf-DsWhn8fF.js";import{H as ca}from"./heart-BPFyKUkJ.js";import{U as Pt}from"./user-plus-D6130qlo.js";import{S as Mt}from"./shield-check-DdfSfcbh.js";import{L as da}from"./layout-dashboard-CtcoWl-n.js";import{U as ze}from"./users-DbO-ebqj.js";import{C as bt}from"./clipboard-list-UebIQ0GV.js";import{P as Oe}from"./package-Ku2d12eQ.js";import{W as Ee}from"./wrench-Bw5Exsal.js";import{L as Bn}from"./lightbulb-C1BwJnva.js";import{S as vt}from"./siren-C_x0Kwf9.js";import{B as Wt}from"./building-2-Nk2huxI0.js";import{U as pt}from"./user-round-B4bN6HjC.js";import{E as ma}from"./ellipsis-zwecaC52.js";import{P as Qn,V as Wn}from"./VillageHelper-B9c_GwAn.js";import{t as xa,f as Hn,p as Yn,r as Gn,a as Zn}from"./operatorWorkflowApi-DwMjzjiG.js";import{A as Jn,r as pa,a as Xn,P as er}from"./AssistantVisibilityToggle-DixiZzHv.js";import{U as Je}from"./user-check-eaJpOJYh.js";import{B as Me}from"./bell-ring-2Jr7CrB_.js";import{C as Ve}from"./clock-5zm-oHtJ.js";import{L as tr}from"./LiveClock-DZcBc8i5.js";import{j as sr}from"./portalNavConfig-C4GEqJnP.js";import{C as ar,a as vs,S as nr,b as rr}from"./snowflake-BhQp3Hn6.js";import{u as z}from"./useMutation-CCxofYKg.js";import{S as qe}from"./search-T0VyIefC.js";import{D as ot}from"./door-open-C5_rd61i.js";import{M as Qe}from"./map-pin-DEg-YZMi.js";import{C as Re}from"./checkbox-DrqWENIb.js";import{T as ve}from"./textarea-BRROE69Y.js";import{B as Ht}from"./badge-check-6143vj-R.js";import{B as L}from"./badge-BmcgN26q.js";import{U as ua}from"./user-DF5rGTA5.js";import{S as ls}from"./send-BQLfd1fb.js";import{F as yt}from"./flag-CXHeyxos.js";import{P as Xe}from"./phone-3sP_NsCN.js";import{M as ir}from"./mail-C6tfkY_l.js";import{S as et,A as lr}from"./sticky-note-CCKGNJaT.js";import{C as Yt}from"./calendar-check-_eoiXHa_.js";import{H as ct}from"./hard-hat-CxRRPxGN.js";import{C as ys}from"./cake-cNdzcpqp.js";import{P as or}from"./PrivacyCollectionNotice-C9UGCs1Z.js";import{F as ha}from"./file-text-BAux0Bto.js";import{C as cr}from"./calendar-clock-C-Thri2i.js";import{P as nt}from"./plus-CUoCthEr.js";import{R as dr}from"./repeat-Coby08vz.js";import{C as Gt}from"./calendar-days-BVXeHu32.js";import{B as Zt}from"./book-user-Ds0VMWUB.js";import{S as os}from"./save-BoqqgZsU.js";import{D as mr,a as xr,b as pr,e as _t}from"./dropdown-menu-CtK-pbB0.js";import{P as ga,F as Ns}from"./package-check-CFJTfML-.js";import{U as ur}from"./undo-2-Bay1gl_t.js";import{T as hr}from"./truck-DeJO4iBY.js";import{P as cs}from"./pencil-CNiM8VJV.js";import{A as gr}from"./archive-restore-vuWKOS29.js";import{A as ds}from"./archive-D-wQiML4.js";import{e as Ct,n as Ge,g as fr,A as fa,S as jr}from"./maintenanceStatus-B7k7O61U.js";import{P as ws}from"./PortalImage-BbpNRxd9.js";import{m as Jt,a as br}from"./maintenanceOperations-DuyrFk8x.js";import{C as vr}from"./columns-3-rR1xZLzJ.js";import{A as yr}from"./arrow-up-down-C_jGfwIC.js";import{S as dt}from"./shield-alert-CWDHjdq3.js";import{M as ja}from"./message-circle-question-CcWIATFu.js";import{E as ms}from"./eye-BYyEwTRq.js";import{U as ba}from"./user-x-Bo3d9uo_.js";import{C as Nr}from"./circle-check-CkPJ4dRt.js";import{I as wr}from"./inbox-DIy2Ab5G.js";import{P as Vt}from"./phone-call-CMPKmMxo.js";import{s as kr}from"./spreadsheetCsv-4akGStHQ.js";import{P as _r}from"./printer-BGRXm7h5.js";import{C as Cr}
1from"./check-check-Cw6RZ6ve.js";import{S as Sr}from"./square-Cr646zmF.js";import{C as Rr}from"./circle-dot-CChup7Jx.js";import{H as ks}from"./house-wtkLENOb.js";import{C as Pr}from"./target-BhiqlrDH.js";import{P as Er}from"./palette-CbfG7AQ6.js";import{E as Tr}from"./external-link-BHekLCTg.js";import{L as Fr}from"./list-checks-Q0Kixbmy.js";import{I as $r}from"./id-card-CKvhkO6Z.js";import{A as Dr}from"./AuditAttributionStamp-CkHW-e4D.js";import{f as _s}from"./adminUi-C-PNoBx1.js";import{u as Ar}from"./usePreloadBackgrounds-1AMK6OqS.js";import{s as Lr}from"./supabaseFunctions-Xsh4_ii9.js";import"./book-open-DtepqIpV.js";import"./volume-2-BnUTl3at.js";import"./volume-x-SfaEfpUl.js";import"./compass-CDFQcs-U.js";import"./wand-sparkles-BYJCovUC.js";import"./message-circle-CJrNXJUk.js";import"./portalSectionHint-CmqkpozB.js";import"./sparkles-B69mEhZg.js";import"./square-pen-D6d6ez1J.js";import"./arrow-right-CpQyeIWr.js";import"./index-BOBh4OZm.js";import"./wallet-DvcdSpiq.js";import"./heart-pulse-DDyL749i.js";import"./utensils-crossed-DN5plLEW.js";import"./newspaper-CNavWVwr.js";import"./megaphone-eKmCVPjV.js";import"./flower-2-tVIDRMED.js";import"./coffee-rTdsowb4.js";import"./shopping-basket-BNCr6aoj.js";import"./users-round-DZsl1kUg.js";import"./life-buoy-gqvf2NHR.js";import"./handshake-CAGXZ2Vx.js";import"./circle-user-BKU7QE1X.js";import"./circle-help-ms_ZceeK.js";import"./trophy-CetmQQEo.js";import"./key-round-BlddUsqF.js";import"./activity-DXsghgOT.js";import"./settings-2-CGmnlkBo.js";import"./bus-CZoRz5sV.js";import"./tv-minimal-D4A3PPFB.js";import"./chart-column-Lvf8PWcm.js";import"./audio-lines-CLwpQQld.js";import"./rocket-Caxl3fhV.js";import"./circle-CYVKuV9a.js";const va=$t("AlarmClock",[["circle",{cx:"12",cy:"13",r:"8",key:"3y4lt7"}],["path",{d:"M12 9v4l2 2",key:"1c63tq"}],["path",{d:"M5 3 2 6",key:"18tl5t"}],["path",{d:"m22 6-3-3",key:"1opdir"}],["path",{d:"M6.38 18.7 4 21",key:"17xu3x"}],["path",{d:"M17.64 18.67 20 21",key:"kv2oe2"}]]);const Mr=$t("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);const ya=$t("PlaneTakeoff",[["path",{d:"M2 22h20",key:"272qi7"}],["path",{d:"M6.36 17.4 4 17l-2-4 1.1-.55a2 2 0 0 1 1.8 0l.17.1a2 2 0 0 0 1.8 0L8 12 5 6l.9-.45a2 2 0 0 1 2.09.2l4.02 3a2 2 0 0 0 2.1.2l4.19-2.06a2.41 2.41 0 0 1 1.73-.17L21 7a1.4 1.4 0 0 1 .87 1.99l-.38.76c-.23.46-.6.84-1.07 1.08L7.58 17.2a2 2 0 0 1-1.22.18Z",key:"fkigj9"}]]);const Or=$t("UserRoundPlus",[["path",{d:"M2 21a8 8 0 0 1 13.292-6",key:"bjp14o"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M22 19h-6",key:"vcuq98"}]]),Cs="text-lg font-semibold text-slate-700",Ss="h-16 rounded-2xl border-slate-200 bg-white/90 text-xl text-slate-800 shadow-sm placeholder:text-slate-400 focus-visible:ring-[#9aa58f]/35",Ir="h-16 w-full gap-2 rounded-2xl bg-[#6f7d68] text-xl font-semibold text-white shadow-sm hover:bg-[#62725d]",Vr="flex items-start gap-3 rounded-2xl border border-[#ded6ca] bg-[#f6f2ec] px-5 py-4 text-lg font-medium text-[#765f52]";function qr({slug:t,villageName:s,logoUrl:a,visitorsHref:r,onSuccess:d}){const l=tn(),[n,g]=i.useState(""),[c,m]=i.useState(""),[x,o]=i.useState(""),[w,p]=i.useState(!1),j=async C=>{C.preventDefault();const T=C.currentTarget;o(""),p(!0);try{const v=await sn(t,n.trim(),c),u=sessionStorage.getItem(`portal_auth_reception_${t}`);await l(window.location.href,T,()=>sessionStorage.getItem(`portal_auth_reception_${t}`)===u)||d(v)}catch(v){o(v.message||"Login failed")}finally{p(!1)}};return e.jsxs("div",{className:"relative min-h-screen overflow-hidden bg-[#f4f2ee] text-slate-800",children:[e.jsx("div",{className:"absolute -inset-6 scale-105 bg-cover bg-center blur-[3px]",style:{backgroundImage:`url(${Hs})`}}),e.jsx("div",{className:"absolute inset-0 bg-white/20"}),e.jsx("main",{className:"relative z-10 flex min-h-screen w-full items-center justify-center px-4 py-6 sm:px-6 sm:py-8 lg:px-10 lg:py-6",children:e.jsxs("div",{className:"w-full",children:[e.jsxs("header",{className:"mb-4 text-center sm:mb-5",children:[e.jsx("h1",{className:"text-4xl font-light uppercase leading-none tracking-[0.22em] text-slate-700 sm:text-5xl sm:tracking-[0.28em] lg:text-6xl xl:text-7xl",children:"RECEPTION"}),e.jsx("p",{className:"mt-3 text-2xl font-light tracking-normal text-[#98887c] sm:text-4xl xl:text-5xl",children:s}),e.jsxs("div",{className:"mt-3 flex items-center justify-center gap-3 text-[#8d9a87] sm:mt-4",children:[e.jsx("span",{className:"h-px w-12 bg-[#aeb7a8]"}),e.jsx(bs,{className:"h-5 w-5","aria-hidden":"true"}),e.jsx("span",{className:"h-px w-12 bg-[#aeb7a8]"})]})]}),e.jsx(tt,{className:"mx-auto w-full max-w-5xl overflow-hidden rounded-[2rem] border border-white/75 bg-white/90 text-slate-800 shadow-[0_24px_70px_rgba(51,65,85,0.18)] backdrop-blur-xl",children:e.jsx(st,{className:"p-6 lg:p-7 xl:p-10",children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-[0.86fr_1.14fr] md:gap-6 lg:grid-cols-[0.95fr_1.05fr] xl:gap-10",children:[e.jsxs("section",{className:"flex flex-col items-center justify-center text-center md:border-r md:border-slate-200/80 md:pr-6 xl:pr-10",children:[a?e.jsx("img",{src:a,alt:s,className:"h-36 w-full max-w-sm object-contain sm:h-44 xl:h-60"}):e.jsxs("div",{className:"flex h-36 w-36 flex-col items-center justify-center rounded-full border border-[#cbd3c5] bg-[#f6f7f3] text-[#75836
1d] sm:h-44 sm:w-44 xl:h-52 xl:w-52",children:[e.jsx(bs,{className:"mb-3 h-12 w-12 xl:h-14 xl:w-14","aria-hidden":"true"}),e.jsx("span",{className:"px-5 text-center text-xl font-medium leading-tight text-slate-700",children:s})]}),e.jsx("div",{className:"mt-4 h-px w-14 bg-[#aeb7a8] xl:mt-6"}),e.jsx(ca,{className:"mt-4 h-7 w-7 text-[#87947f] xl:mt-5 xl:h-8 xl:w-8","aria-hidden":"true"}),e.jsxs("p",{className:"mt-4 max-w-sm text-lg leading-relaxed text-slate-600 sm:text-xl xl:mt-5 xl:text-2xl",children:[e.jsx("span",{className:"block",children:"Welcome back."}),e.jsx("span",{className:"block",children:"Please sign in to open the"}),e.jsx("span",{className:"block",children:"reception desk."})]})]}),e.jsxs("section",{className:"flex flex-col justify-center",children:[e.jsxs("div",{className:"mb-4 text-center md:text-left xl:mb-6",children:[e.jsx("p",{className:"text-lg font-semibold uppercase tracking-[0.28em] text-slate-600",children:"Desk Access"}),e.jsx("h2",{className:"mt-2 text-3xl font-semibold tracking-tight text-slate-800 xl:mt-3 xl:text-4xl",children:"Sign in"}),e.jsx("p",{className:"mt-1 text-lg leading-relaxed text-slate-600 xl:mt-2 xl:text-xl",children:"Use your reception username and password."})]}),e.jsxs("form",{"data-app-login-form":"true",onSubmit:j,className:"space-y-4 xl:space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"reception-username",className:Cs,children:"Username"}),e.jsx(O,{id:"reception-username",value:n,onChange:C=>g(C.target.value),placeholder:"e.g. reception",className:Ss,autoComplete:"username",autoCapitalize:"none",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"reception-password",className:Cs,children:"Password"}),e.jsx(O,{id:"reception-password",type:"password",value:c,onChange:C=>m(C.target.value),placeholder:"Enter password",className:Ss,autoComplete:"current-password",required:!0})]}),x&&e.jsxs("div",{className:Vr,role:"alert",children:[e.jsx(Qt,{className:"mt-0.5 h-5 w-5 shrink-0"}),e.jsx("span",{children:x})]}),e.jsxs(k,{type:"submit",className:Ir,disabled:w,children:[w?e.jsx(U,{className:"h-6 w-6 animate-spin"}):e.jsx(Ma,{className:"h-6 w-6"})," Sign in"]})]}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-[#e3e0d8] bg-[#f8f7f2]/80 p-3 text-center shadow-sm xl:mt-6 xl:p-4",children:[e.jsx(k,{asChild:!0,variant:"ghost",className:"h-11 gap-2 rounded-xl text-base font-semibold text-slate-700 hover:bg-[#eef1ea] hover:text-slate-900 xl:h-12 xl:text-lg",children:e.jsxs(At,{to:r,children:[e.jsx(Pt,{className:"h-5 w-5"})," Visitors Kiosk"]})}),e.jsxs("p",{className:"mt-1 flex items-center justify-center gap-2 text-sm text-slate-600 xl:mt-2 xl:text-base",children:[e.jsx(Mt,{className:"h-4 w-4 text-[#87947f]"})," Reception logins are created by your village admin."]})]})]})]})})})]})})]})}const Ur=["dashboard","residents","visitors","deliveries","maintenance","suggestions","messages","rollcall","activity","settings"];function Xt(t){return!!t&&Ur.includes(t)}function ne(t,s="Guest"){const a=t?.trim();return a?a.replace(new RegExp("\\b\\p{L}","gu"),r=>r.toLocaleUpperCase("en-NZ")):s}const es=[{value:"default",label:"Default",description:"Comfortable, larger desk text"},{value:"medium",label:"Medium",description:"Bigger labels and controls"},{value:"large",label:"Large",description:"Large, easy-to-read text"},{value:"extra-large",label:"Extra Large",description:"Maximum readability"}],Na=[{value:"blue",label:"Reception blue",description:"The current clear blue accent",color:"#2563eb"},{value:"reception-green",label:"Reception green",description:"The sage green used across Reception",color:"#6f7d68"},{value:"resident",label:"Resident colour",description:"Matches the village resident-facing accent"}],jt={fontSize:"default",accent:"blue"};function Rs(t){return`seniorsites:reception-preferences:${t}`}function Kr(t){if(!t)return jt;try{const s=JSON.parse(t),a=es.some(d=>d.value===s.fontSize)?s.fontSize:jt.fontSize,r=Na.some(d=>d.value===s.accent)?s.accent:jt.accent;return{fontSize:a,accent:r}}catch{return jt}}function zr(t){const[s,a]=i.useState(jt);return i.useEffect(()=>{typeof window>"u"||a(Kr(window.localStorage.getItem(Rs(t))))},[t]),[s,d=>{a(d),typeof window<"u"&&window.localStorage.setItem(Rs(t),JSON.stringify(d))}]}const W="reception-workspace-card rounded-2xl border border-border shadow-sm backdrop-blur-xl",Y="bg-primary text-primary-foreground shadow-sm hover:bg-primary/90 focus-visible:ring-ring",Q="border-border bg-card text-card-foreground hover:border-primary/40 hover:bg-accent/25 hover:text-foreground",Br="rounded-2xl border border-border bg-card",qt=[{key:"dashboard",label:"Dashboard",icon:da},{key:"residents",label:"Residents",icon:ze},{key:"visitors",label:"Visitors",icon:bt},{key:"deliveries",label:"Deliveries",icon:Oe},{key:"maintenance",label:"Maintenance",icon:Ee},{key:"suggestions",label:"Suggestions",icon:Bn},{key:"messages",label:"Messages",icon:Ie},{key:"rollcall",label:"Roll Call",icon:vt},{key:"activity",label:"My Activity",icon:zs},{key:"settings",label:"Settings",icon:Bs}],wa=["dashboard","residents","visitors"],Qr=["deliveries","maintenance","suggestions","messages","rollcall","activity","settings"],Wr=new Set(wa);function Et(t,s){return t==="dashboard"||t==="activity"||t==="settings"?!0:t==="residents"?s.has("resident_search"):t==="visitors"?["visitor_log","expected_visitors","contractor_induction"].some(a=>s.has(a)):t==="deliveries"?s.has("deliveries"):t==="maintenance"?s.has("maintenance_request"):t==="suggestions"?s.has("suggestions"):t==="messages"?s.has("phone_messages")||s.has("reception_notes"):s.has("emergency_contacts")}
1function Hr({section:t,onSelect:s,enabled:a,villageName:r,displayName:d,onLogout:l,helpAction:n}){const[g,c]=i.useState(!1),[m,x]=i.useState(()=>typeof window>"u"?!1:window.localStorage.getItem("seniorsites:reception-sidebar-collapsed")==="1"),o=qt.find(u=>u.key===t)??qt[0],w=qt.filter(u=>Et(u.key,a)),p=w.filter(u=>wa.includes(u.key)),j=w.filter(u=>Qr.includes(u.key)),C=j.some(u=>u.key===t)&&!Wr.has(t),T=ne(d,"Reception");i.useEffect(()=>{window.localStorage.setItem("seniorsites:reception-sidebar-collapsed",m?"1":"0")},[m]);const v=u=>{s(u),c(!1)};return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:$("reception-panel reception-sidebar sticky top-0 hidden h-full shrink-0 flex-col px-3 py-5 transition-[width] duration-300 ease-out lg:flex",m?"w-[76px]":"w-48"),"data-reception-sidebar-collapsed":m,children:[e.jsx("div",{className:$("mb-6 flex items-center px-1",m?"justify-center":"justify-start"),children:e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-[var(--reception-accent-tint)] text-[var(--reception-accent)]",title:r,children:e.jsx(Wt,{className:"h-6 w-6","aria-hidden":!0})})}),e.jsx("button",{type:"button",onClick:()=>x(u=>!u),className:"reception-panel-tab reception-panel-tab--left","aria-label":m?"Show menu":"Hide menu","aria-expanded":!m,title:m?"Show menu":"Hide menu",children:e.jsx(at,{className:$("h-4 w-4 transition-transform duration-200",!m&&"rotate-180"),strokeWidth:2})}),!m&&e.jsx("p",{className:"mb-2 px-3 text-[12px] font-semibold text-black dark:text-white",children:"Desk menu"}),e.jsx("nav",{className:"flex flex-1 flex-col gap-1","aria-label":"Reception desk sections",children:w.map(u=>{const N=u.icon,f=t===u.key;return e.jsxs("button",{type:"button",onClick:()=>s(u.key),"aria-current":f?"page":void 0,"aria-label":m?u.label:void 0,title:m?u.label:void 0,className:$("group relative flex h-12 min-h-12 items-center gap-3 overflow-hidden rounded-xl px-3 text-[14px] font-semibold transition-all duration-200",m&&"justify-center px-0",f?"bg-[var(--reception-accent-tint)] text-[var(--reception-accent)]":"text-black hover:bg-[var(--reception-surface-2)] hover:text-black dark:text-white dark:hover:text-white"),children:[e.jsx(N,{className:$("h-6 w-6 shrink-0 transition-colors",f?"text-[var(--reception-accent)]":"text-black group-hover:text-black dark:text-white dark:group-hover:text-white")}),!m&&e.jsx("span",{className:"truncate",children:u.label})]},u.key)})}),e.jsxs("div",{className:"mt-2 border-t border-[var(--reception-hairline)] pt-4",children:[e.jsxs("div",{className:$("mb-3 flex items-center gap-3",m?"justify-center":"px-2"),title:m?`${T}, on duty`:void 0,children:[e.jsxs("span",{className:"relative flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-[var(--reception-tile)] text-[var(--reception-label-3)]",children:[e.jsx(pt,{className:"h-[18px] w-[18px]"}),e.jsx("span",{className:"absolute bottom-[-1px] right-[-1px] h-2.5 w-2.5 rounded-full border-2 border-[var(--reception-surface)] bg-[var(--reception-accent)]"})]}),!m&&e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[14px] font-semibold text-[var(--reception-label)]",children:T}),e.jsx("span",{className:"block text-[12px] text-[var(--reception-label-3)]",children:"On duty"})]})]}),e.jsxs(k,{variant:"ghost",className:$("h-11 w-full gap-2 rounded-xl text-[14px] text-black hover:bg-[var(--reception-surface-2)] hover:text-black dark:text-white dark:hover:text-white",m?"justify-center px-0":"justify-start"),onClick:l,"aria-label":m?"Sign out":void 0,title:m?"Sign out":void 0,children:[e.jsx(lt,{className:"h-5 w-5"})," ",!m&&"Sign out"]})]})]}),e.jsx("div",{className:"sticky top-0 z-30 border-b border-border bg-card/70 backdrop-blur-xl lg:hidden",children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2 px-3 py-3 sm:px-4",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-accent text-accent-foreground shadow-sm",children:e.jsx(Wt,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:"Reception Desk"}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:r}),e.jsx("p",{className:"truncate text-xs font-medium text-foreground sm:hidden",children:o.label})]})]}),e.jsx("div",{className:"hidden min-w-0 flex-1 justify-center px-2 sm:flex",children:e.jsx("span",{className:"truncate border-b-2 border-primary px-2 py-1 text-sm font-medium text-foreground",children:o.label})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n,e.jsxs(k,{variant:"ghost",size:"sm",className:"h-10 shrink-0 gap-1.5 px-2 text-muted-foreground hover:bg-accent/25 hover:text-foreground",onClick:l,"aria-label":"Sign out of Reception Desk",children:[e.jsx(lt,{className:"h-5 w-5"})," ",e.jsx("span",{className:"hidden sm:inline",children:"Sign out"})]})]})]})}),e.jsxs("nav",{className:"fixed inset-x-0 bottom-0 z-40 grid grid-flow-col auto-cols-fr border-t border-border bg-card/70 px-1 pt-1 shadow-xl backdrop-blur-xl pb-[env(safe-area-inset-bottom)] lg:hidden","aria-label":"Reception mobile navigation",children:[p.map(u=>{const N=u.icon,f=t===u.key;return e.jsxs("button",{type:"button",onClick:()=>v(u.key),"aria-current":f?"page":void 0,className:$("flex min-h-14 min-w-0 flex-col items-center justify-center gap-1 rounded-xl px-1 py-2 text-[13px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring sm:text-sm",f?"bg-accent text-accent-foreground":"text-black hover:bg-accent/25 hover:text-black dark:text-white dark:hover:text-white"),children:[e.jsx(N,{className:$("h-6 w-6 shrink-0",f?"text-accent-foreground":"text-black dark:text-white")}),e.jsx("span",{className:"max-w-full truncate leading-tight",children:u.label})]},u.key)}),e.jsxs(Oa,{open:g,onOpenChange:c,children:[e.jsxs("button",{type:"button",onClick:()=>c(!0),"data-pippa-menu-button":"","aria-label":`Open more reception sections${C?`, current section ${o.label}`:""}`,"aria-current":C?"page":void 0,className:$("flex min-h-14 min-w-0 flex-col items-center justify-center gap-1 rounded-xl px-1 py-2 text-[13px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring sm:text-sm",C?"bg-accent text-accent-foreground":"text-black hover:bg-accent/25 hover:text-black dark:text-white dark:hover:text-white"),children:[e.jsx(ma,{className:$("h-6 w-6 shrink-0",C?"text-accent-foreground":"text-black dark:text-white")}),e.jsx("span",{className:"max-w-full truncate leading-tight",children:C?o.label:"More"})]}),e.jsxs(Ia,{side:"bottom",className:"max-h-[85vh] rounded-t-2xl border-border bg-card/90 px-3 pb-[calc(1rem+env(safe-area-inset-bottom))] pt-4 shadow-2xl backdrop-blur-xl sm:px-4 lg:hidden",children:[e.jsxs(Va,{className:"pr-10 text-left",children:[e.jsx(qa,{className:"text-base text-foreground",children:"Reception sections"}),e.jsx(Ua,{className:"truncate text-sm text-muted-foreground",children:r})]}),e.jsx("div",{className:"mt-4 grid gap-2",children:[...p,...j].map(u=>{const N=u.icon,f=t===u.key;return e.jsxs("button",{type:"button",onClick:()=>v(u.key),"aria-current":f?"page":void 0,className:$("flex min-h-[52px] min-w-0 items-center gap-3 rounded-xl border px-3 text-left text-base font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",f?"border-primary/35 bg-accent text-accent-foreground":"border-border bg-card text-card-foreground hover:border-primary/35 hover:bg-accent/25"),children:[e.jsx(N,{className:$("h-6 w-6 shrink-0",f?"text-accent-foreground":"text-black dark:text-white")}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.label}),f&&e.jsx("span",{className:"shrink-0 text-xs font-semibold uppercase tracking-wide text-primary",children:"Active"})]},u.key)})})]})]})]})]})}function Ps({item:t,onOpen:s}){const a=t.icon;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:s,className:"reception-list-row group flex w-full items-center gap-3 rounded-xl px-2 text-left transition-all duration-150 hover:translate-x-0.5 hover:bg-[var(--reception-blue-tint)] focu
1s-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx("span",{className:$("reception-activity-icon grid h-10 w-10 shrink-0 place-items-center rounded-xl",t.urgent&&"reception-activity-icon--urgent"),children:e.jsx(a,{className:"h-5 w-5",strokeWidth:1.75})}),e.jsxs("div",{className:"min-w-0 flex-1 transition-colors group-hover:text-[var(--reception-blue-700)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"truncate text-[14px] font-semibold text-[var(--reception-label)]",children:t.title}),e.jsx("time",{className:"shrink-0 text-[12px] font-medium tabular-nums text-black/70 dark:text-white/70",children:Ze(t.at)})]}),e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[13px] font-medium text-black/80 dark:text-white/80",children:t.detail})]})]})})}function Ut(t){return new Intl.DateTimeFormat("en-CA",{timeZone:"Pacific/Auckland"}).format(new Date(t))}function Es(t){const s=new Intl.DateTimeFormat("en-NZ",{timeZone:"Pacific/Auckland",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(t)),a=Number(s.find(d=>d.type==="hour")?.value||0),r=Number(s.find(d=>d.type==="minute")?.value||0);return a*60+r}function Ts({open:t,onToggle:s,overview:a,enabled:r,navigate:d,variant:l="rail"}){const[n,g]=i.useState("all"),c=r.has("phone_messages")||r.has("reception_notes"),m=r.has("expected_visitors"),x=a?.lists.overdue||[],o=a?.lists.expected||[],w=i.useMemo(()=>{const S=new Set(x.map(_=>_.id));return[...x.map(_=>({id:`overdue-${_.id}`,type:"alerts",icon:va,title:"Sign-out overdue",detail:ne(`${_.first_name} ${_.last_name}`),at:_.signed_in_at,section:"visitors",urgent:!0})),...(a?.lists.signed_in||[]).filter(_=>!S.has(_.id)).map(_=>({id:`visitor-${_.id}`,type:"visitors",icon:Je,title:"Visitor on site",detail:ne(`${_.first_name} ${_.last_name}`),at:_.signed_in_at,section:"visitors"})),...(a?.lists.deliveries||[]).map(_=>({id:`delivery-${_.id}`,type:"deliveries",icon:Oe,title:"Parcel delivered",detail:_.resident_name?`For ${ne(_.resident_name)}`:_.courier||"Waiting at Reception",at:_.created_at,section:"deliveries",targetId:_.id})),...(a?.lists.phone||[]).map(_=>({id:`message-${_.id}`,type:_.urgency==="urgent"?"alerts":"messages",icon:_.urgency==="urgent"?Me:Ie,title:ne(_.caller_name,"Reception message"),detail:_.message,at:_.created_at,section:"messages",urgent:_.urgency==="urgent"}))].sort((_,V)=>new Date(V.at).getTime()-new Date(_.at).getTime())},[x,a]),p=n==="all"?w:w.filter(S=>S.type===n),j=p.slice(0,8),C=Ut(new Date().toISOString()),T=(S,_)=>new Date(_.at).getTime()-new Date(S.at).getTime(),v=j.filter(S=>Ut(S.at)===C).sort(T),u=j.filter(S=>Ut(S.at)!==C).sort((S,_)=>Es(_.at)-Es(S.at)||T(S,_)),N=[{label:"Today",items:v},...u.length>0?[{label:"Earlier",items:u}]:[]],f=e.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-6 scrollbar-hide",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-[17px] font-semibold text-[var(--reception-label)]",children:"Activity"}),c&&e.jsx("button",{type:"button",onClick:()=>d("messages"),className:"min-h-11 rounded-xl px-3 text-[13px] font-semibold text-[var(--reception-blue-600)] transition-colors hover:bg-[var(--reception-blue-tint)] hover:text-[var(--reception-blue-700)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"View all"})]}),e.jsx("div",{className:"mt-3 grid grid-cols-4 rounded-full bg-[var(--reception-surface-2)] p-[3px]",role:"group","aria-label":"Filter activity",children:["all","messages","deliveries","alerts"].map(S=>e.jsx("button",{type:"button",onClick:()=>g(S),"aria-pressed":n===S,className:$("min-h-9 rounded-full px-2 text-[12px] font-medium capitalize transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",n===S?"bg-[var(--reception-blue-600)] text-white shadow-sm hover:bg-[var(--reception-blue-500)]":"text-black/75 hover:bg-[var(--reception-blue-tint)] hover:text-black dark:text-white/75 dark:hover:text-white"),children:S},S))}),e.jsxs("div",{className:"mt-5 space-y-4",children:[p.length>0&&N.map(S=>e.jsxs("section",{"aria-label":`${S.label} activity`,children:[e.jsx("h3",{className:"px-2 text-[13px] font-bold text-black dark:text-white",children:S.label}),S.items.length>0?e.jsx("ul",{className:"mt-1 divide-y divide-[var(--reception-hairline)]",children:S.items.map(_=>e.jsx(Ps,{item:_,onOpen:()=>d(_.section,_.targetId)},_.id))}):e.jsx("p",{className:"px-2 pt-2 text-[13px] font-medium text-black/75 dark:text-white/75",children:"No activity yet today."})]},S.label)),p.length===0&&e.jsxs("p",{className:"flex min-h-[72px] items-center gap-2 px-2 text-[13px] font-medium text-black/75 dark:text-white/75",children:[e.jsx(Ve,{className:"h-5 w-5 text-black dark:text-white"})," No matching activity."]})]}),m&&e.jsxs("section",{className:"mt-7 border-t border-[var(--reception-hairline)] pt-5","aria-labelledby":"upcoming-arrivals-heading",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h2",{id:"upcoming-arrivals-heading",className:"text-[17px] font-semibold text-[var(--reception-label)]",children:"Upcoming arrivals"}),m&&o.length>0&&e.jsx("button",{type:"button",onClick:()=>d("visitors"),className:"min-h-11 rounded-xl px-3 text-[13px] font-semibold text-[var(--reception-blue-600)] transition-colors hover:bg-[var(--reception-blue-tint)] hover:text-[var(--reception-blue-700)]",children:"View all"})]}),o.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-[var(--reception-label-2)]",children:"None expected today."}):e.jsx("ul",{className:"mt-2 divide-y divide-[var(--reception-hairline)]",children:o.slice(0,3).map(S=>e.jsx(Ps,{onOpen:()=>d("visitors"),item:{id:S.id,type:"visitors",icon:ze,title:ne(S.visitor_name),detail:S.resident_name?`Visiting ${ne(S.resident_name)}`:S.visitor_company||"Expected at Reception",at:S.expected_at||S.created_at||new Date().toISOString(),section:"visitors"}},`expected-${S.id}`))})]})]}),c&&e.jsx("div",{className:"border-t border-[var(--reception-hairline)] p-5",children:e.jsxs(k,{variant:"outline",className:"h-11 w-full gap-2 rounded-[14px] border-[var(--reception-hairline)] bg-[var(--reception-surface)] text-[14px] font-semibold text-[var(--reception-label)] hover:bg-[var(--reception-surface-2)]",onClick:()=>d("messages"),children:[e.jsx(Ie,{className:"h-5 w-5 text-black dark:text-white"})," New message"]})})]});return l==="inline"?e.jsx("section",{className:"reception-panel max-w-full overflow-hidden min-[1180px]:hidden","aria-label":"Activity",children:f}):e.jsxs("div",{className:$("relative hidden h-full shrink-0 overflow-visible transition-[width] duration-300 ease-out min-[1180px]:block",t?"w-[340px]":"w-0"),children:[e.jsxs("button",{type:"button",onClick:s,"aria-label":t?"Hide activity":w.length>0?`Show activity, ${w.length} items`:"Show activity","aria-expanded":t,title:t?"Hide activity":"Show activity",className:"reception-panel-tab reception-panel-tab--right relative",children:[e.jsx(at,{className:$("h-4 w-4 transition-transform duration-200",!t&&"rotate-180"),strokeWidth:2}),!t&&w.length>0&&e.jsx("span",{className:"absolute -top-2 left-1/2 flex h-5 min-w-5 -translate-x-1/2 items-center justify-center rounded-full bg-[var(--reception-red-600)] px-1 text-[10px] font-bold leading-none text-white shadow-sm",children:w.length>99?"99+":w.length})]}),e.jsx("aside",{className:$("reception-panel h-full w-[340px] transition-transform duration-300 ease-out",t?"translate-x-0":"pointer-events-none translate-x-full"),"aria-hidden":!t,children:f})]})}function Yr({code:t}){const s="h-5 w-5";return t==null||t<=1?e.jsx(Ka,{className:s}):t<=3?e.jsx(ar,{className:s}):t>=51&&t<=67?e.jsx(vs,{className:s}):t>=71&&t<=77?e.jsx(nr,{className:s}):t>=80?e.jsx(vs,{className:s}):e.jsx(rr,{className:s})}function Fs(t){return t==null?"Weather":t<=1?"Sunny":t===2?"Partly cloudy":t===3?"Overcast":t>=51&&t<=55?"Drizzle":t>=61&&t<=67?"Rain":t>=71&&t<=77?"Snow":t>=80&&t<=82?"Showers":t>=95?"Thunderstorm":"Cloudy"}function Gr({villageName:t,displayName:s,latitude:a,longitude:r,slug:d,helpAction:l}){const[n,g]=i.useState(null),c=new Date().toLocaleDateString("en-NZ",{weekday:"short",day:"numeric",month:"short",year:"numeric"}),m=new Date().getHours(),x=m<12?"Good morning":m<18?"Good afternoon":"Good evening",o=ne(s,"Reception");return i.useEffect(()=>{if(a==null||r==null)return;const w=new AbortController;return fetch(`https://api.open-meteo.com/v1/forecast?latitude=${a}&longitude=${r}&current_weather=true`,{signal:w.signal}).then(p=>p.json()).then(p=>{p.current_weather&&g({temp:Math.round(p.current_weather.temperature),code:p.current_weather.weathercode})}).catch(()=>{}),()=>w.abort()},[a,r]),e.jsxs("header",{className:"relative isolate -mx-4 -mt-4 flex min-h-[94px] min-w-0 items-center justify-between gap-4 overflow-hidden rounded-b-[20px] rounded-t-[24px] border border-white/70 bg-[var(--reception-surface)] bg-[length:100%_100%] bg-center bg-no-repeat px-4 py-3 shadow-[0_10px_28px_rgba(35,55,80,0.07)] md:-mx-6 md:-mt-6 md:px-5 lg:-mx-8 lg:-mt-8",style:{backgroundImage:"url(/reception/reception-desk-header-background-v2.png?v=1)"},children:[e.jsx("span",{className:"pointer-events-none absolute inset-0 z-[1] bg-gradient-to-r from-white/20 via-trans
1parent to-white/20 dark:from-slate-950/75 dark:via-slate-950/55 dark:to-slate-950/75","aria-hidden":"true"}),e.jsxs("div",{className:"relative z-10 flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm","aria-hidden":!0,children:e.jsx(sr,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("h1",{className:"truncate text-[26px] font-semibold tracking-tight text-[var(--reception-label)]",children:"Reception Desk"}),d&&e.jsx(Jn,{scope:pa(d),className:"h-8 w-8 rounded-lg"})]}),e.jsx("p",{className:"mt-0.5 truncate text-[13px] text-[var(--reception-label-2)]",children:t})]})]}),e.jsxs("div",{className:"relative z-10 flex shrink-0 items-center gap-4",children:[l&&e.jsx("div",{className:"hidden lg:block",children:l}),e.jsxs("p",{className:"hidden text-[14px] font-medium text-[var(--reception-label-2)] md:block",children:[x,", ",e.jsx("span",{className:"font-semibold text-[var(--reception-label)]",children:o})]}),e.jsxs("div",{className:"text-right",children:[e.jsx(tr,{className:"block text-[17px] font-semibold normal-case tracking-normal tabular-nums text-[var(--reception-label)]"}),e.jsx("span",{className:"block text-[12px] font-normal text-[var(--reception-label-3)]",children:c})]}),e.jsxs("div",{className:"flex h-11 min-w-11 items-center justify-center gap-2 rounded-xl bg-[var(--reception-tile)] px-3 text-[var(--reception-label-3)]",title:n?`${n.temp}°C, ${Fs(n.code)}`:"Current weather","aria-label":n?`${n.temp} degrees, ${Fs(n.code)}`:"Current weather",children:[e.jsx(Yr,{code:n?.code}),n&&e.jsxs("span",{className:"hidden text-[13px] font-semibold tabular-nums text-[var(--reception-label)] sm:inline",children:[n.temp,"°"]})]})]})]})}function Zr({slug:t,overview:s,onResident:a,onVisitor:r}){const[d,l]=i.useState(""),[n,g]=i.useState(!1),c=xt(d.trim(),220),{data:m,isLoading:x}=B({queryKey:["reception-residents",t,c],queryFn:()=>Lt(t,c),enabled:c.length>0,staleTime:3e4,retry:1}),o=i.useMemo(()=>{if(!c)return[];const j=c.toLocaleLowerCase("en-NZ"),C=(m||[]).slice(0,6).map(v=>({id:`resident-${v.id}`,kind:"resident",title:Be(v),detail:v.unit_room?/^unit\b/i.test(v.unit_room)?v.unit_room:`Unit ${v.unit_room}`:v.status||"Resident",resident:v})),T=[...(s?.lists.signed_in||[]).map(v=>({id:`visitor-${v.id}`,title:ne(`${v.first_name} ${v.last_name}`),detail:v.resident_name?`Visiting ${ne(v.resident_name)}`:"Visitor on site"})),...(s?.lists.expected||[]).map(v=>({id:`expected-${v.id}`,title:ne(v.visitor_name),detail:v.resident_name?`Expected for ${ne(v.resident_name)}`:"Expected visitor"}))].filter(v=>`${v.title} ${v.detail}`.toLocaleLowerCase("en-NZ").includes(j));return[...C,...T.slice(0,4).map(v=>({...v,kind:"visitor"}))]},[c,s,m]),w=n&&d.trim().length>0,p=()=>{l(""),g(!1)};return e.jsxs("div",{className:"relative min-w-0 flex-1",onBlur:j=>{j.currentTarget.contains(j.relatedTarget)||g(!1)},children:[e.jsx(qe,{className:"pointer-events-none absolute left-4 top-1/2 z-10 h-4 w-4 -translate-y-1/2 text-[var(--reception-label-3)]",strokeWidth:1.5}),e.jsx(O,{autoFocus:!0,value:d,onFocus:()=>g(!0),onChange:j=>l(j.target.value),"data-update-transient":"true",placeholder:"Search residents, visitors or units…","aria-label":"Search residents, visitors or units","aria-expanded":w,"aria-controls":"reception-desk-search-results",className:"reception-solid-control h-11 rounded-[14px] border-[var(--reception-hairline)] pl-11 pr-3 text-[14px] text-[var(--reception-label)] shadow-none placeholder:text-[var(--reception-label-3)] focus-visible:ring-2"}),w&&e.jsx("div",{id:"reception-desk-search-results",role:"listbox",className:"absolute inset-x-0 top-[calc(100%+0.5rem)] z-50 max-h-80 overflow-y-auto rounded-[16px] border border-[var(--reception-hairline)] bg-[var(--reception-surface)] p-2 shadow-[var(--reception-panel-shadow)]",children:x?e.jsxs("p",{className:"flex items-center gap-2 px-3 py-4 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Searching…"]}):o.length===0?e.jsxs("p",{className:"px-3 py-4 text-sm text-muted-foreground",children:["No residents, visitors or units match “",d.trim(),"”."]}):o.map(j=>e.jsxs("button",{type:"button",role:"option",className:"reception-list-row flex w-full items-center gap-3 px-3 text-left hover:bg-[var(--reception-surface-2)] focu
1s-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>{j.kind==="resident"?a(j.resident):r(),p()},children:[e.jsx("span",{className:"reception-icon-tile reception-icon-tile--small",children:j.kind==="resident"?e.jsx(pt,{className:"h-4 w-4",strokeWidth:1.5}):e.jsx(ot,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] font-semibold text-[var(--reception-label)]",children:j.title}),e.jsxs("span",{className:"mt-0.5 flex items-center gap-1 truncate text-[12px] text-[var(--reception-label-2)]",children:[j.kind==="resident"&&e.jsx(Qe,{className:"h-3 w-3"}),j.detail]})]})]},j.id))})]})}function Te({slug:t,value:s,onChange:a,placeholder:r="Search residents...",optional:d}){const[l,n]=i.useState(""),g=xt(l,250),{data:c}=B({queryKey:["reception-residents",t,g],queryFn:()=>Lt(t,g),enabled:!s&&g.trim().length>=1,staleTime:3e4}),m=(c||[]).filter(x=>!x.status||x.status==="active");return s?e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] px-3 py-2.5 dark:border-slate-700 dark:bg-slate-800",children:[e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:[Be(s),s.unit_room&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Qe,{className:"h-3 w-3"})," ",s.unit_room]})]}),e.jsxs(k,{type:"button",size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-muted-foreground",onClick:()=>a(null),children:[e.jsx(as,{className:"h-3.5 w-3.5"})," Change"]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(O,{value:l,onChange:x=>n(x.target.value),placeholder:r,className:"h-11 border-[#dcd8cf] pl-9 focus-visible:ring-[#9aa58f]/40 dark:border-slate-700"})]}),m.length>0&&e.jsx("ul",{className:"max-h-44 divide-y divide-border/60 overflow-auto rounded-xl border border-border/60 bg-card shadow-sm",children:m.map(x=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>{a(x),n("")},className:"flex w-full items-center justify-between gap-2 px-3 py-2.5 text-left text-sm transition-colors hover:bg-[#f8f7f2] dark:hover:bg-slate-800",children:[e.jsx("span",{className:"font-medium text-foreground",children:Be(x)}),x.unit_room&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Qe,{className:"h-3 w-3"})," ",x.unit_room]})]})},x.id))}),d&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional - leave blank if it isn't for a specific resident."})]})}function Ot({slug:t,value:s,onChange:a,toolKey:r,placeholder:d="Search staff..."}){const[l,n]=i.useState(""),g=xt(l,250),{data:c}=B({queryKey:["reception-staff-list",t,r,g],queryFn:()=>an(t,r,g),enabled:!s,staleTime:3e4}),m=c||[];return s?e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] px-3 py-2.5 dark:border-slate-700 dark:bg-slate-800",children:[e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-2 text-sm font-medium text-foreground",children:[e.jsx(Ht,{className:"h-4 w-4 text-[#6f7d68]"})," ",s.name,s.role_title&&e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:s.role_title})]}),e.jsxs(k,{type:"button",size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-muted-foreground",onClick:()=>a(null),children:[e.jsx(as,{className:"h-3.5 w-3.5"})," Change"]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(O,{value:l,onChange:x=>n(x.target.value),placeholder:d,className:"h-11 border-[#dcd8cf] pl-9 focus-visible:ring-[#9aa58f]/40 dark:border-slate-700"})]}),m.length>0&&e.jsx("ul",{className:"max-h-44 divide-y divide-border/60 overflow-auto rounded-xl border border-border/60 bg-card shadow-sm",children:m.map(x=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>{a(x),n("")},className:"flex w-full items-center justify-between gap-2 px-3 py-2.5 text-left text-sm transition-colors hover:bg-[#f8f7f2] dark:hover:bg-slate-800",children:[e.jsx("span",{className:"font-medium text-foreground",children:x.name}),x.role_title&&e.jsx("span",{className:"text-xs text-muted-foreground",children:x.role_title})]})},x.id))})]})}function ut(t){const{toast:s}=pe(),a=oe(),r=()=>a.invalidateQueries({queryKey:["front-desk-notices",t]}),d=z({mutationFn:n=>nn(t,n),onSuccess:()=>{s({title:"Notice resent"}),r()},onError:n=>s({title:"Couldn't resend",description:n instanceof Error?n.message:"Please try again.",variant:"destructive"})}),l=z({mutationFn:n=>
1rn(t,n),onSuccess:(n,g)=>{s({title:"Notice recalled",description:"It's been removed from their view.",action:e.jsx(gs,{altText:"Resend notice",onClick:()=>d.mutate(g),children:"Resend"})}),r()},onError:n=>s({title:"Couldn't undo",description:n instanceof Error?n.message:"Please try again.",variant:"destructive"})});return(n,g)=>{if(!n){s({title:g?.title||"Notice sent"});return}s({title:g?.title||"Notice sent",action:e.jsx(gs,{altText:"Undo send",onClick:()=>l.mutate(n),children:"Undo send"})})}}const St="A package has arrived for you at reception. Please collect it when convenient.",$s="A package has arrived at reception.";function Jr({slug:t,open:s,onOpenChange:a}){const{toast:r}=pe(),d=oe(),l=ut(t),[n,g]=i.useState(null),[c,m]=i.useState(""),[x,o]=i.useState(""),[w,p]=i.useState(""),[j,C]=i.useState(""),[T,v]=i.useState(!1),[u,N]=i.useState("resident"),[f,S]=i.useState(null),[_,V]=i.useState("Package arrived"),[b,M]=i.useState(St),A=()=>{d.invalidateQueries({queryKey:["reception-deliveries",t]}),d.invalidateQueries({queryKey:["reception-overview",t]})},E=()=>{g(null),m(""),o(""),p(""),C(""),v(!1),N("resident"),S(null),V("Package arrived"),M(St)},K=D=>{D||E(),a(D)},G=z({mutationFn:D=>Ys(t,D),onSuccess:D=>{l(D.notice_id),A()},onError:D=>r({title:"Couldn't send notice",description:D instanceof Error?D.message:"Please try again.",variant:"destructive"})}),H=z({mutationFn:()=>Gs(t,{resident_id:n?.id??null,resident_name:n&&n.display_name||null,courier:c.trim()||null,tracking_number:x.trim()||null,storage_location:w.trim()||null,description:j.trim()||null}),onSuccess:D=>{T?G.mutate({id:D.id,target_type:u,target_resident_id:u==="resident"?n?.id??null:null,target_staff_user_id:u==="staff"?f?.id??null:null,title:_.trim()||"Package arrived",body:b.trim()||(u==="staff"?$s:St)}):r({title:"Delivery logged"}),A(),K(!1)},onError:D=>r({title:"Couldn't log delivery",description:D instanceof Error?D.message:"Please try again.",variant:"destructive"})}),ge=D=>{N(D),M(D==="staff"?$s:St)};return e.jsx(ce,{open:s,onOpenChange:K,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"Log a delivery"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"For resident"}),e.jsx(Te,{slug:t,value:n,onChange:g,optional:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"delivery-courier",children:"Courier / sender"}),e.jsx(O,{id:"delivery-courier",value:c,onChange:D=>m(D.target.value),placeholder:"NZ Post, CourierPost..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"delivery-tracking",children:"Tracking #"}),e.jsx(O,{id:"delivery-tracking",value:x,onChange:D=>o(D.target.value),placeholder:"Optional"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"delivery-storage",children:"Storage location"}),e.jsx(O,{id:"delivery-storage",value:w,onChange:D=>p(D.target.value),placeholder:"Front desk, parcel room..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"delivery-description",children:"Description"}),e.jsx(ve,{id:"delivery-description",value:j,onChange:D=>C(D.target.value),placeholder:"Small box, flowers, signed-for letter...",rows:2})]}),e.jsxs("label",{className:"flex min-h-[44px] items-center gap-3 rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] px-3 py-2.5 text-sm font-medium text-foreground dark:border-slate-700 dark:bg-slate-800",children:[e.jsx(Re,{checked:T,onCheckedChange:D=>v(D===!0),className:"h-5 w-5"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Me,{className:"h-4 w-4 text-[#6f7d68]"})," Notify resident/staff now"]})]}),T&&e.jsxs("div",{className:"space-y-3 rounded-xl border border-[#e3e0d8] bg-white/70 p-3 dark:border-slate-800 dark:bg-slate-900",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2",children:["resident","staff"].map(D=>e.jsx("button",{type:"button",onClick:()=>ge(D),className:`rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors ${u===D?"border-[#87947f] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-600 dar
1k:bg-slate-800 dark:text-slate-100":"border-[#dcd8cf] bg-white text-slate-600 hover:border-[#b7c1af] dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300"}`,children:D==="resident"?"The resident":"A staff member"},D))}),u==="resident"?!n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pick a resident above to notify them."}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Staff member"}),e.jsx(Ot,{slug:t,value:f,onChange:S,toolKey:"deliveries"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"delivery-notice-title",children:"Title"}),e.jsx(O,{id:"delivery-notice-title",value:_,onChange:D=>V(D.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"delivery-notice-body",children:"Message preview"}),e.jsx(ve,{id:"delivery-notice-body",value:b,onChange:D=>M(D.target.value),rows:2})]})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>K(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>H.mutate(),disabled:H.isPending||G.isPending||!n&&!j.trim()&&!c.trim()||T&&(u==="resident"?!n:!f),children:[(H.isPending||G.isPending)&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," ",T?"Log & notify":"Log delivery"]})]})]})})}function ka({slug:t,message:s,open:a,onOpenChange:r,onNotified:d}){const{toast:l}=pe(),n=oe(),g=ut(t),c=!!(s?.target_resident_id||s?.target_staff_user_id),m=s?.target_staff_user_id?"staff":"resident",[x,o]=i.useState(m),[w,p]=i.useState(null),[j,C]=i.useState(null);i.useEffect(()=>{a&&(o(s?.target_staff_user_id?"staff":"resident"),p(null),C(null))},[a,s]);const T=z({mutationFn:()=>{if(!s)throw new Error("No message");return c?fs(t,{id:s.id}):fs(t,{id:s.id,target_type:x,target_resident_id:x==="resident"?w?.id??null:null,target_staff_user_id:x==="staff"?j?.id??null:null})},onSuccess:N=>{g(N.id,{title:"They've been notified"}),n.invalidateQueries({queryKey:["reception-phone-messages",t]}),s&&d?.(s.id),r(!1)},onError:N=>l({title:"Couldn't send notice",description:N instanceof Error?N.message:"Please try again.",variant:"destructive"})}),v=!T.isPending&&(c||(x==="resident"?!!w:!!j)),u=s?.resident_name||s?.target_label||"the resident";return e.jsx(ce,{open:a,onOpenChange:r,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(Me,{className:"h-5 w-5 text-[#6f7d68]"})," Let them know"]}),e.jsx(kt,{children:"Send a Front Desk notice so they know a phone message is waiting. This does not mark the message done."})]}),e.jsx("div",{className:"space-y-3",children:c?e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] px-3 py-2.5 text-sm font-medium text-foreground dark:border-slate-700 dark:bg-slate-800",children:[e.jsx(ua,{className:"h-4 w-4 text-[#6f7d68]"})," ",u]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",onClick:()=>o("resident"),className:`rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors ${x==="resident"?"border-[#87947f] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100":"border-[#dcd8cf] bg-white text-slate-600 hover:border-[#b7c1af] dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300"}`,children:"A resident"}),e.jsx("button",{type:"button",onClick:()=>o("staff"),className:`rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors ${x==="staff"?"border-[#87947f] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100":"border-[#dcd8cf] bg-white text-slate-600 hover:border-[#b7c1af] dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300"}`,children:"A staff member"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:x==="staff"?"Staff member":"Resident"}),x==="staff"?e.jsx(Ot,{slug:t,value:j,onChange:C,toolKey:"phone_messages"}):e.jsx(Te,{slug:t,value:w,onChange:p})]})]})}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>T.mutate(),disabled:!v,children:[T.isPending?e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ls,{className:"mr-2 h-4 w-4"})," Send notice"]})]})]})})}const Xr=["General","Plumbing","Electrical","Heating/Cooling","Appliance","Grounds/Garden","Other"];function Nt(t){return t instanceof Error?t.message:"Something went wrong. Please try again."}function wt({resident:t}){return e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] px-3 py-2 text-sm font-medium text-slate-800 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100",children:[Be(t),t.unit_room&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-normal text-[#5f6e58] dark:text-slate-300",children:[e.jsx(Qe,{className:"h-3 w-3"})," ",t.unit_room]})]})}function xs({slug:t,resident:s,lockResident:a,open:r,onOpenChange:d}){const{toast:l}=pe(),n=oe(),g=ut(t),[c,m]=i.useState(s??null),[x,o]=i.useState(""),[w,p]=i.useState("General"),[j,C]=i.useState("Normal"),[T,v]=i.useState(!1),[u,N]=i.useState(null),[f,S]=i.useState(!1);i.useEffect(()=>{r&&(m(s??null),N(null),S(!1))},[r,s]);const _=()=>{o(""),p("General"),C("Normal"),v(!1),N(null),S(!1)},V=()=>{d(!1),_()},b=z({mutationFn:()=>ln(t,{body:x,category:w,priority:j,follow_up_required:T,resident_id:c?.id??null}),onSuccess:A=>{l({title:"Note added"}),n.invalidateQueries({queryKey:["reception-notes",t]}),N(A)},onError:A=>l({title:"Couldn't save note",description:Nt(A),variant:"destructive"})}),M=z({mutationFn:()=>ns(t,{target_type:"resident",target_resident_id:u.resident_id,source_type:"reception_note",source_id:u.id,title:"Note from reception",body:(u.body||"").trim().slice(0,600)}),onSuccess:A=>{g(A.id,{title:"Sent to resident Front Desk"}),V()},onError:A=>l({title:"Couldn't send",description:Nt(A),variant:"destructive"})});if(u){const A=!!u.resident_id;return e.jsx(ce,{open:r,onOpenChange:E=>
1{E||V()},children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(mt,{className:"h-5 w-5 text-[#6f7d68]"})," Note saved"]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] p-4 text-sm dark:border-slate-700 dark:bg-slate-800",children:[u.category&&e.jsx(L,{variant:"secondary",className:"mb-2",children:u.category}),e.jsx("p",{className:"whitespace-pre-wrap text-foreground",children:u.body})]}),A?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-start gap-2.5 rounded-xl border border-[#dcd8cf] bg-white p-3 text-sm text-foreground dark:border-slate-700 dark:bg-slate-900",children:[e.jsx(Re,{checked:f,onCheckedChange:E=>S(E===!0),className:"mt-0.5"}),e.jsx("span",{children:"This note is safe for the resident to see."})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only resident-safe content should go to the Front Desk. The reception note itself stays unchanged."})]}):e.jsx("p",{className:"rounded-xl border border-dashed border-[#dcd8cf] bg-[#f8f7f2]/70 px-3 py-3 text-sm text-muted-foreground dark:border-slate-700 dark:bg-slate-800/40",children:"Link this note to a resident to be able to send it to their Front Desk."})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"outline",className:Q,onClick:V,children:"Done"}),e.jsxs(k,{className:Y,disabled:!A||!f||M.isPending,onClick:()=>M.mutate(),children:[M.isPending?e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ls,{className:"mr-2 h-4 w-4"})," Send to resident Front Desk"]})]})]})})}return e.jsx(ce,{open:r,onOpenChange:d,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"Add reception note"})}),e.jsxs("div",{className:"space-y-3",children:[a&&s?e.jsx(wt,{resident:s}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Resident"}),e.jsx(Te,{slug:t,value:c,onChange:m,optional:!0})]}),e.jsx(ve,{value:x,onChange:A=>o(A.target.value),rows:4,placeholder:"What happened? e.g. Parcel left at reception for Villa 12.",className:"text-base"}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Category"}),e.jsxs(ee,{value:w,onValueChange:A=>p(A),children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:Zs.map(A=>e.jsx(q,{value:A,children:A},A))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Priority"}),e.jsxs(ee,{value:j,onValueChange:A=>C(A),children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:Js.map(A=>e.jsx(q,{value:A,children:A},A))})]})]})]}),e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-foreground",children:[e.jsx(Re,{checked:T,onCheckedChange:A=>v(A===!0)}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(yt,{className:"h-4 w-4 text-muted-foreground"})," Follow-up required"]})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>d(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>b.mutate(),disabled:b.isPending||!x.trim(),children:[b.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Add note"]})]})]})})}function ps({slug:t,resident:s,lockResident:a,open:r,onOpenChange:d}){const{toast:l}=pe(),n=oe(),[g,c]=i.useState(s??null),[m,x]=i.useState(""),[o,w]=i.useState(""),[p,j]=i.useState("resident"),[C,T]=i.useState(""),[v,u]=i.useState(""),[N,f]=i.useState("normal"),[S,_]=i.useState(!1),[V,b]=i.useState(""),[M,A]=i.useState(null),[E,K]=i.useState(!1);i.useEffect(()=>{r&&(c(s??null),j("resident"),u(""),A(null))},[r,s]);const{data:G,isLoading:H}=B({queryKey:["reception-resident-family",t,g?.id],queryFn:()=>ea(t,g.id),enabled:p==="family"&&!!g,staleTime:15e3}),ge=G||[],D=()=>{x(""),w(""),T(""),u(""),f("normal"),_(!1),b(""),A(null)},Z=()=>{d(!1),D()},X=z({mutationFn:()=>on(t,{caller_name:m.trim()||null,caller_phone:o.trim()||null,target_type:p,target_resident_id:p==="resident"?g?.id??null:null,target_family_member_id:p==="family"&&v||null,target_label:p==="resident"?g?.display_name||null:p==="family"?ge.find(I=>I.id===v)?.name||null:C.trim()||null,urgency:N,callback_required:S,message:V.trim()}),onSuccess:I=>
1{l({title:"Message saved"}),n.invalidateQueries({queryKey:["reception-phone-messages",t]}),n.invalidateQueries({queryKey:["reception-overview",t]}),A({...I,resident_name:p==="resident"?g?.display_name??I.resident_name??null:I.resident_name})},onError:I=>l({title:"Couldn't log message",description:Nt(I),variant:"destructive"})});return M?e.jsxs(e.Fragment,{children:[e.jsx(ce,{open:r,onOpenChange:I=>{I||Z()},children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(mt,{className:"h-5 w-5 text-[#6f7d68]"})," Message saved"]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] p-4 text-sm dark:border-slate-700 dark:bg-slate-800",children:[e.jsxs("p",{className:"font-medium text-foreground",children:[M.caller_name||"Caller",M.callback_required?" — callback required":""]}),e.jsxs("p",{className:"mt-1 text-muted-foreground",children:["For ",M.resident_name||M.target_label||M.target_type]}),e.jsx("p",{className:"mt-2 whitespace-pre-wrap text-foreground",children:M.message})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Would you like to let the resident or staff member know a message is waiting?"})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"outline",className:Q,onClick:Z,children:"Done"}),e.jsxs(k,{className:Y,onClick:()=>K(!0),children:[e.jsx(Me,{className:"mr-2 h-4 w-4"})," Let resident/staff know"]})]})]})}),e.jsx(ka,{slug:t,message:M,open:E,onOpenChange:K,onNotified:Z})]}):e.jsx(ce,{open:r,onOpenChange:d,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"New phone message"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"pm-caller",children:"Caller name"}),e.jsx(O,{id:"pm-caller",value:m,onChange:I=>x(I.target.value),placeholder:"Who called?"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"pm-phone",children:"Phone number"}),e.jsx(O,{id:"pm-phone",type:"tel",inputMode:"tel",value:o,onChange:I=>w(I.target.value),placeholder:"e.g. 021 555 0100"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Message for"}),a&&s?e.jsx("div",{className:"flex h-11 items-center rounded-md border border-input bg-muted/40 px-3 text-sm text-muted-foreground",children:"A resident"}):e.jsxs(ee,{value:p,onValueChange:I=>{j(I),u("")},children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"resident",children:"A resident"}),e.jsx(q,{value:"staff",children:"Staff"}),e.jsx(q,{value:"family",children:"Family"}),e.jsx(q,{value:"other",children:"Other"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Priority"}),e.jsxs(ee,{value:N,onValueChange:f,children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"normal",children:"Normal"}),e.jsx(q,{value:"important",children:"Important"}),e.jsx(q,{value:"urgent",children:"Urgent"})]})]})]})]}),p==="resident"?a&&s?e.jsx(wt,{resident:s}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Resident"}),e.jsx(Te,{slug:t,value:g,onChange:c})]}):p==="family"?e.jsxs("div",{className:"space-y-3",children:[a&&s?e.jsx(wt,{resident:s}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Resident"}),e.jsx(Te,{slug:t,value:g,onChange:I=>{c(I),u("")}})]}),g&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Family member"}),e.jsxs(ee,{value:v,onValueChange:u,children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{placeholder:H?"Loading...":"Select family member"})}),e.jsx(ae,{children:ge.map(I=>e.jsxs(q,{value:I.id,children:[I.name,I.relationship?` (${I.relationship})`:""]},I.id))})]}),!H&&ge.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No family members linked to this resident."})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"pm-target",children:"Who is it for?"}),e.jsx(O,{id:"pm-target",value:C,onChange:I=>T(I.target.value),placeholder:"Name or role"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"pm-msg",children:"Message"}),e.jsx(ve,{id:"pm-msg",value:V,onChange:I=>b(I.target.value),rows:3,placeholder:"What was the message?"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:S,onCheckedChange:I=>_(I===!0)})," Callback required"]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>d(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>X.mutate(),disabled:X.isPending||!V.trim()||p==="family"&&!v,children:[X.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Save message"]})]})]})})}function ei({slug:t,resident:s,lockResident:a,open:r,onOpenChange:d}){const{toast:l}=pe(),n=oe(),[g,c]=i.useState(s??null),[m,x]=i.useState("General"),[o,w]=i.useState(s?.unit_room??""),[p,j]=i.useState("normal"),[C,T]=i.useState("");i.useEffect(()=>{r&&(c(s??null),w(s?.unit_room??""))},[r,s]);const v=()=>{x("General"),w(""),j("normal"),T("")},u=z({mutationFn:()=>
1Xs(t,{resident_id:g?.id??null,issue_type:m,location:o.trim()||null,priority:p,notes:C.trim()||null}),onSuccess:()=>{l({title:"Maintenance request raised"}),n.invalidateQueries({queryKey:["reception-maintenance",t]}),n.invalidateQueries({queryKey:["reception-overview",t]}),d(!1),v()},onError:N=>l({title:"Couldn't raise request",description:Nt(N),variant:"destructive"})});return e.jsx(ce,{open:r,onOpenChange:d,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"Raise maintenance request"})}),e.jsxs("div",{className:"space-y-3",children:[a&&s?e.jsx(wt,{resident:s}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"For resident"}),e.jsx(Te,{slug:t,value:g,onChange:N=>{c(N),N?.unit_room&&!o.trim()&&w(N.unit_room)},optional:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Issue type"}),e.jsxs(ee,{value:m,onValueChange:x,children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:Xr.map(N=>e.jsx(q,{value:N,children:N},N))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Priority"}),e.jsxs(ee,{value:p,onValueChange:j,children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"low",children:"Low"}),e.jsx(q,{value:"normal",children:"Normal"}),e.jsx(q,{value:"high",children:"High"}),e.jsx(q,{value:"urgent",children:"Urgent"})]})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"mt-loc",children:"Location"}),e.jsx(O,{id:"mt-loc",value:o,onChange:N=>w(N.target.value),placeholder:"Unit / area"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"mt-notes",children:"Details"}),e.jsx(ve,{id:"mt-notes",value:C,onChange:N=>T(N.target.value),rows:3,placeholder:"Describe the problem..."})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>d(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>u.mutate(),disabled:u.isPending||!C.trim(),children:[u.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Raise request"]})]})]})})}function ti({slug:t,resident:s,open:a,onOpenChange:r}){const{toast:d}=pe(),l=oe(),[n,g]=i.useState(""),[c,m]=i.useState(""),[x,o]=i.useState(""),[w,p]=i.useState("");i.useEffect(()=>{a&&(g(""),m(""),o(""),p(""))},[a]);const j=z({mutationFn:()=>cn(t,{resident_id:s.id,start_date:n,end_date:c,reason:x.trim()||null,emergency_contact:w.trim()||null}),onSuccess:()=>{d({title:"Away notice logged"}),l.invalidateQueries({queryKey:["reception-overview",t]}),r(!1)},onError:C=>d({title:"Couldn't save",description:Nt(C),variant:"destructive"})});return e.jsx(ce,{open:a,onOpenChange:r,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(ya,{className:"h-5 w-5 text-[#6f7d68]"})," Away / return"]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(wt,{resident:s}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"aw-start",children:"From"}),e.jsx(O,{id:"aw-start",type:"date",value:n,onChange:C=>g(C.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"aw-end",children:"To"}),e.jsx(O,{id:"aw-end",type:"date",value:c,onChange:C=>m(C.target.value)})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"aw-reason",children:"Reason"}),e.jsx(O,{id:"aw-reason",value:x,onChange:C=>o(C.target.value),placeholder:"Optional"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"aw-contact",children:"Emergency contact"}),e.jsx(O,{id:"aw-contact",value:w,onChange:C=>p(C.target.value),placeholder:"Optional - name and phone"})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>j.mutate(),disabled:j.isPending||!n||!c,children:[j.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Log away notice"]})]})]})})}const si={Normal:"border-border bg-muted text-muted-foreground",Important:"border-[#ded6ca] bg-[#f1ece7] text-[#765f52] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",Urgent:"border-[#d8b9ab] bg-[#f6e9e4] text-[#8a5c4b] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200"};function ai({slug:t,resident:s,open:a,onOpenChange:r}){const{data:d,isLoading:l,isError:n}=B({queryKey:["reception-notes",t],queryFn:()=>is(t),enabled:a,staleTime:15e3}),g=(d||[]).filter(c=>c.resident_id===s.id);return e.jsx(ce,{open:a,onOpenChange:r,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs(xe,{children:["Recent notes - ",Be(s)]})}),e.jsx("div",{className:"max-h-[60vh] space-y-2.5 overflow-y-auto",children:l?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):n?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load notes."}):g.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"No reception notes linked to this resident yet."}):g.slice(0,25).map(c=>{const m=rs(c.priority);return e.jsxs("div",{className:"rounded-xl border border-border/60 bg-muted/20 p-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.category&&e.jsx(L,{variant:"secondary",children:c.category}),e.jsx(L,{variant:"outline",className:si[m],children:m}),c.follow_up_required&&e.jsxs(L,{variant:"outline",className:"gap-1 border-[#b7c1af] text-[#5f6e58]",children:[e.jsx(yt,{className:"h-3 w-3"})," Follow-up"]})]}),e.jsx("p",{className:"mt-2 whitespace-pre-wrap text-sm text-foreground",children:c.body}),e.jsxs("p",{className:"mt-2 inline-flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Ve,{className:"h-3 w-3"})," ",ie(c.created_at),c.created_by?` - ${c.created_by}`:""]})]},c.id)})}),e.jsx(he,{children:e.jsx(k,{variant:"ghost",onClick:()=>r(!1),children:"Close"})})]})})}function ni({slug:t,resident:s,open:a,onOpenChange:r}){const{data:d,isLoading:l,isError:n}=B({queryKey:["reception-resident-family",t,s.id],queryFn:()=>ea(t,s.id),enabled:a,staleTime:15e3}),g=d||[];return e.jsx(ce,{open:a,onOpenChange:r,children:e.jsxs(de,{children:[e.jsx(me,{children:e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-5 w-5 text-[#6f7d68]"})," Family - ",Be(s)]})}),e.jsx("div",{className:"max-h-[60vh] space-y-2.5 overflow-y-auto",children:l?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):n?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load family contacts."}):g.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"No family members linked to this resident yet."}):g.map(c=>e.jsxs("div",{className:"rounded-xl border border-border/60 bg-muted/20 p-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"font-medium text-foreground",children:c.name}),c.relationship&&e.jsx(L,{variant:"secondary",children:c.relationship}),c.is_epoa&&e.jsxs(L,{variant:"outline",className:"gap-1 border-[#b7c1af] text-[#5f6e58]",children:[e.jsx(Mt,{className:"h-3 w-3"})," EPOA"]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-3 text-sm",children:[c.p
1hone&&e.jsxs("a",{href:`tel:${c.phone}`,className:"inline-flex items-center gap-1.5 text-[#6f7d68] hover:underline",children:[e.jsx(Xe,{className:"h-3.5 w-3.5"})," ",c.phone]}),c.email&&e.jsxs("a",{href:`mailto:${c.email}`,className:"inline-flex items-center gap-1.5 text-[#6f7d68] hover:underline",children:[e.jsx(ir,{className:"h-3.5 w-3.5"})," ",c.email]}),!c.phone&&!c.email&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"No phone or email on file."})]})]},c.id))}),e.jsx(he,{children:e.jsx(k,{variant:"ghost",onClick:()=>r(!1),children:"Close"})})]})})}function _a({slug:t,open:s,onOpenChange:a,heading:r,description:d,allowStaff:l=!1,allowResident:n=!0,staffToolKey:g,presetResident:c=null,defaultTitle:m,defaultResidentBody:x,defaultStaffBody:o,submitLabel:w="Send notice",submitting:p=!1,onSubmit:j}){const[C,T]=i.useState(n?"resident":"staff"),[v,u]=i.useState(n?c:null),[N,f]=i.useState(null),[S,_]=i.useState(m),[V,b]=i.useState(x),[M,A]=i.useState(!1);i.useEffect(()=>{s&&(T(n?"resident":"staff"),u(n?c:null),f(null),_(m),b(x),A(!1))},[s,c,m,x,n]),i.useEffect(()=>{M||b(C==="staff"&&o||x)},[C,M,x,o]);const K=(C==="resident"?!!v:!!N)&&S.trim().length>0&&V.trim().length>0&&!p,G=()=>{K&&j({target_type:C,target_resident_id:C==="resident"?v?.id??null:null,target_staff_user_id:C==="staff"?N?.id??null:null,title:S.trim(),body:V.trim()})};return e.jsx(ce,{open:s,onOpenChange:a,children:e.jsxs(de,{className:"max-h-[92vh] overflow-y-auto",children:[e.jsxs(me,{children:[e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(Me,{className:"h-5 w-5 text-primary"})," ",r]}),d&&e.jsx(kt,{children:d})]}),e.jsxs("div",{className:"space-y-3",children:[l&&n&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",onClick:()=>T("resident"),className:`rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors ${C==="resident"?"border-primary/40 bg-accent text-accent-foreground":"border-border bg-card text-card-foreground hover:border-primary/40"}`,children:"A resident"}),e.jsx("button",{type:"button",onClick:()=>T("staff"),className:`rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors ${C==="staff"?"border-primary/40 bg-accent text-accent-foreground":"border-border bg-card text-card-foreground hover:border-primary/40"}`,children:"A staff member"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:C==="staff"?"Staff member":"Resident"}),C==="staff"?e.jsx(Ot,{slug:t,value:N,onChange:f,toolKey:g}):n?e.jsx(Te,{slug:t,value:v,onChange:u}):null]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"notify-title",children:"Title"}),e.jsx(O,{id:"notify-title",value:S,onChange:H=>_(H.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"notify-body",children:"Message"}),e.jsx(ve,{id:"notify-body",value:V,rows:3,onChange:H=>{b(H.target.value),A(!0)}}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This appears on their home screen and in their Front Desk tab."})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:G,disabled:!K,children:[p?e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ls,{className:"mr-2 h-4 w-4"})," ",w]})]})]})})}const ri=new Set(["completed","resolved","closed","cancelled","canceled"]),ii=new Set(["received","awaiting_collection","notified"]);function li(t,s="Maintenance request"){const a=t?.trim();return a?a.toLocaleLowerCase("en-NZ").replace(new RegExp("\\b\\p{L}","gu"),r=>r.toLocaleUpperCase("en-NZ")):s}function oi(t){return Math.max(0,Math.floor((Date.now()-new Date(t).getTime())/6e4))}function Ds(t){if(t<60)return`${t} min`;if(t>=1440){const r=Math.floor(t/1440);return`${r} ${r===1?"day":"days"}`}const s=Math.floor(t/60),a=t%60;return a?`${s} hr ${a} min`:`${s} hr`}function ci(t){return Math.max(0,Math.floor((Date.now()-new Date(t).getTime())/864e5))}function di(t){return t>30?"text-[var(--reception-red-600)]":t>=7?"text-[var(--reception-amber-600)]":"text-[var(--reception-label-3)]"}function Tt({title:t,count:s,action:a}){return e.jsxs("div",{className:"mb-4 flex min-h-8 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("h2",{className:"truncate text-[17px] font-semibold text-[var(--reception-label)]",children:t}),s!==void 0&&e.jsx("span",{className:"shrink-0 text-[13px] font-normal tabular-nums text-[var(--reception-label-2)]",children:s})]}),a]})}function Ke({icon:t,label:s,description:a,onClick:r,href:d,primary:l=!1,compact:n=!1}){const g=$("group flex items-center gap-3 rounded-[14px] text-left text-[14px] font-semibold transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",n?"h-11 min-h-11 px-4":"reception-card min-h-[86px] px-5",l?"border-transparent bg-[var(--reception-blue-600)] text-white shadow-[0_4px_12px_rgba(37,99,235,0.25)] hover:bg-[var(--reception-blue-500)] active:bg-[var(--reception-blue-700)]":"reception-solid-control border border-[var(--reception-hairline)] text-[var(--reception-label)] hover:bg-[var(--reception-surface-2)]"),c=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:$("reception-dashboard-action-icon grid shrink-0 place-items-center",n?"h-5 w-5":"reception-icon-tile",l&&"reception-dashboard-action-icon--inverse",l&&!n&&"bg-white/15 text-white"),children:e.jsx(t,{className:n?"h-4 w-4":"h-5 w-5",strokeWidth:1.5})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate",children:s}),!n&&a&&e.jsx("span",{className:"mt-1 block text-[12px] font-normal leading-snug text-[var(--reception-label-2)]",children:a})]}),!n&&e.jsx(at,{className:"h-4 w-4 shrink-0 text-[var(--reception-label-3)] transition-transform group-hover:translate-x-0.5"})]});
1return d?e.jsx(At,{to:d,className:g,children:c}):e.jsx("button",{type:"button",onClick:r,className:g,children:c})}function mi({metric:t}){const s=t.icon;return e.jsxs("button",{type:"button",onClick:t.onClick,className:"reception-card reception-status-button flex min-h-[140px] w-full flex-col items-center justify-center gap-2.5 p-4 text-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsxs("span",{className:"flex items-center justify-center gap-3",children:[e.jsx("span",{className:$("reception-icon-tile",`reception-icon-tile--${t.state}`),children:e.jsx(s,{strokeWidth:1.75})}),e.jsx("span",{className:"text-[28px] font-semibold leading-none tabular-nums text-[var(--reception-label)]",children:t.value})]}),e.jsxs("span",{className:"min-w-0 max-w-full text-center",children:[e.jsx("span",{className:"block text-balance text-[13px] font-medium leading-tight text-[var(--reception-label)]",children:t.label}),e.jsx("span",{className:"mt-1 block text-balance text-[12px] leading-tight text-[var(--reception-label-2)]",children:t.subtitle})]})]})}const xi=["actions","maintenance","parcels"];function pi({active:t,onChange:s,maintenanceCount:a,parcelCount:r,showMaintenance:d,showParcels:l}){const n=[{id:"actions",label:"Desk actions"},...d?[{id:"maintenance",label:"Maintenance",count:a,state:"overdue"}]:[],...l?[{id:"parcels",label:"Parcels",count:r,state:"waiting"}]:[]],g=i.useRef([]),c=Math.max(0,n.findIndex(o=>o.id===t)),m=o=>{const w=n[o];w&&(s(w.id),g.current[o]?.focus())},x=(o,w)=>{if(o.key==="ArrowRight"||o.key==="ArrowLeft"){o.preventDefault();const p=o.key==="ArrowRight"?1:-1;m((w+p+n.length)%n.length)}else o.key==="Home"?(o.preventDefault(),m(0)):o.key==="End"&&(o.preventDefault(),m(n.length-1))};return e.jsxs("div",{className:"reception-dashboard-submenu relative grid w-full gap-0.5 rounded-[14px] p-1",style:{gridTemplateColumns:`repeat(${n.length}, minmax(0, 1fr))`},role:"tablist","aria-label":"Reception dashboard sections",children:[e.jsx("span",{"aria-hidden":!0,className:"reception-section-indicator reception-dashboard-submenu-indicator pointer-events-none absolute bottom-1 left-1 top-1 rounded-[10px]",style:{width:`calc((100% - 8px - ${(n.length-1)*2}px) / ${n.length})`,transform:`translateX(calc(${c*100}% + ${c*2}px))`}}),n.map((o,w)=>e.jsxs("button",{ref:p=>{g.current[w]=p},type:"button",role:"tab",id:`reception-dashboard-tab-${o.id}`,"aria-controls":`reception-dashboard-panel-${o.id}`,"aria-selected":t===o.id,tabIndex:t===o.id?0:-1,onClick:()=>s(o.id),onKeyDown:p=>x(p,w),className:$("relative z-10 flex h-10 min-h-10 min-w-0 items-center justify-center rounded-[10px] px-4 text-[14px] font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--reception-blue-600)]",t===o.id?"text-white":"text-[var(--reception-blue-700)] hover:text-[var(--reception-label)]"),children:[e.jsx("span",{className:"truncate",children:o.label}),"count"in o&&e.jsx("span",{className:$("reception-section-badge",o.state==="overdue"?"reception-section-badge--overdue":"reception-section-badge--waiting"),children:o.count})]},o.id))]})}function ui({metric:t}){const s=t.icon;return e.jsxs("button",{type:"button",onClick:t.onClick,className:"reception-status-button flex min-h-11 items-center gap-2 rounded-[14px] border border-[var(--reception-hairline)] px-3 text-left text-[13px] font-medium text-[var(--reception-label-2)] hover:text-[var(--reception-label)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx(s,{className:"h-4 w-4 text-[var(--reception-label-3)]",strokeWidth:1.5}),e.jsx("span",{className:"tabular-nums",children:"0"}),t.label]})}function hi({slug:t,enabled:s,overview:a,visitorsHref:r,session:d,navigate:l}){const n=oe(),g=ut(t),c=a?.tiles,m=a?.lists.overdue||[],x=a?.resident_occasions||[],[o,w]=i.useState(!1),[p,j]=i.useState(null),[C,T]=i.useState(!1),[v,u]=i.useState(!1),[N,f]=i.useState(!1),[S,_]=i.useState(3),[V,b]=i.useState(3),M=s.has("reception_notes"),A=s.has("phone_messages"),E=s.has("deliveries"),K=s.has("maintenance_request"),G=s.has("visitor_log"),H=s.has("expected_visitors"),ge=s.has("internal_notification"),D=`seniorsites:reception-dashboard-view:${t}:${d.reception_user_id}`,[Z,X]=i.useState(()=>{if(typeof window>"u")return"actions";const F=window.localStorage.getItem(D);return xi.includes(F)?F:"actions"});i.useEffect(()=>{window.localStorage.setItem(D,Z)},[Z,D]);const I=Z==="maintenance"&&!K||Z==="parcels"&&!E?"actions":Z,{data:J}=B({queryKey:["reception-notes",t],queryFn:()=>is(t),enabled:M,staleTime:3e4}),{data:Fe}=B({queryKey:["reception-deliveries",t,!1],queryFn:()=>sa(t),enabled:E,staleTime:15e3}),{data:Ue,isLoading:Ne,isError:Ce}=B({queryKey:["reception-maintenance",t],queryFn:()=>aa(t),enabled:K,staleTime:15e3,retry:1}),He=(J||[]).filter(F=>F.follow_up_required&&F.status!=="done"&&F.status!=="closed").length,$e=(Fe||[]).filter(F=>ii.has(String(F.status).toLocaleLowerCase("en-NZ"))&&!F.archived_at),De=(Ue||[]).filter(F=>!ri.has(String(F.status).toLocaleLowerCase("en-NZ"))),re=[...De].sort((F,be)=>!!F.acknowledged_at!=!!be.acknowledged_at?F.acknowledged_at?1:-1:new Date(F.created_at).getTime()-new Date(be.created_at).getTime()),Ae=i.useMemo(()=>{const F=R=>new Intl.DateTimeFormat("en-CA",{timeZone:"Pacific/Auckland"}).format(new Date(R)),be=F(new Date),ke=(a?.lists.signed_in||[]).filter(R=>F(R.signed_in_at)===be).length;return Math.max(c?.visitors_today??0,ke)},[a?.lists.signed_in,c?.visitors_today]),_e=i.useMemo(()=>
1[G&&{key:"onsite",label:"On site",subtitle:"Signed in now",value:Math.max(c?.signed_in_now??0,a?.lists.signed_in.length??0),icon:ze,state:"info",onClick:()=>l("visitors")},E&&{key:"parcels",label:"Parcels waiting",subtitle:"Ready for collection",value:$e.length||c?.deliveries_waiting||0,icon:Oe,state:"waiting",onClick:()=>l("deliveries")},A&&{key:"messages",label:"Open messages",subtitle:"To follow up",value:Math.max(c?.phone_messages_open??0,a?.lists.phone.length??0),icon:Ie,state:"waiting",onClick:()=>l("messages")},M&&{key:"notes",label:"Reception notes",subtitle:"Follow-ups due",value:He,icon:et,state:"waiting",onClick:()=>l("messages")},G&&{key:"today",label:"Visitors today",subtitle:"Arrived today",value:Ae,icon:Yt,state:"info",onClick:()=>l("visitors")},s.has("service_people")&&{key:"contractors",label:"Contractors",subtitle:"On site now",value:c?.contractors_onsite??0,icon:ct,state:"info",onClick:()=>l("visitors")},H&&{key:"expected",label:"Expected arrivals",subtitle:"Due today",value:c?.expected_today??a?.lists.expected.length??0,icon:Yt,state:"info",onClick:()=>l("visitors")}].filter(Boolean),[Ae,s,He,Ce,Ne,l,De.length,a,E,H,K,M,A,G,c,$e.length]),Le=_e.filter(F=>F.value>0),Se=_e.filter(F=>F.value===0),fe=z({mutationFn:F=>ta(t,F),onSuccess:()=>{n.invalidateQueries({queryKey:["reception-overview",t]}),n.invalidateQueries({queryKey:["reception-visitors",t]})}}),we=z({mutationFn:F=>ns(t,{...F,source_type:"general"}),onSuccess:F=>{g(F.id,{title:"Front Desk notice sent"}),f(!1)},onError:F=>za({title:"Couldn't send notice",description:F instanceof Error?F.message:"Please try again.",variant:"destructive"})}),je=F=>{j(F),w(!0)};return e.jsxs("div",{className:"reception-dashboard-page space-y-6",children:[e.jsx("section",{"aria-label":"Reception desk actions",className:"reception-dashboard-search-panel sticky top-0 z-30 -mx-2 rounded-[20px] border border-[var(--reception-hairline)] p-3 shadow-[0_8px_24px_rgba(16,24,40,0.06)] backdrop-blur-xl",children:e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center",children:[s.has("resident_search")&&e.jsx(Zr,{slug:t,overview:a,onResident:M?je:()=>l("residents"),onVisitor:()=>l("visitors")}),e.jsxs("div",{className:"grid shrink-0 grid-cols-1 gap-2 sm:grid-cols-3",children:[G&&e.jsx(Ke,{icon:Pt,label:"Visitors Kiosk",href:r,primary:!0,compact:!0}),A&&e.jsx(Ke,{icon:Xe,label:"Phone message",onClick:()=>T(!0),compact:!0}),E&&e.jsx(Ke,{icon:Oe,label:"Log a delivery",onClick:()=>u(!0),compact:!0})]})]})}),G&&m.length>0&&e.jsxs("section",{className:"reception-card reception-card--alert p-5","aria-labelledby":"needs-attention-heading","aria-live":"polite",children:[e.jsxs("div",{className:"mb-3 flex items-baseline gap-2",children:[e.jsx("h2",{id:"needs-attention-heading",className:"text-[17px] font-semibold text-[var(--reception-label)]",children:"Needs attention"}),e.jsx("span",{className:"text-[13px] tabular-nums text-[var(--reception-label-2)]",children:m.length})]}),e.jsx("ul",{className:"divide-y divide-[var(--reception-hairline)]",children:m.slice(0,S).map(F=>{const be=oi(F.signed_in_at),ke=Math.max(0,be-(a?.threshold_minutes||0));return e.jsxs("li",{className:"flex min-h-[72px] flex-wrap items-center justify-between gap-4 py-2 first:pt-0 last:pb-0",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"grid h-[60px] w-[60px] flex-[0_0_60px] place-items-center rounded-2xl bg-[var(--reception-alert-tint)] text-[var(--reception-alert)]",children:e.jsx(va,{className:"h-8 w-8",strokeWidth:1.75})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-[var(--reception-alert)]",children:"Overdue sign-out"}),e.jsx("p",{className:"mt-1 text-[15px] font-semibold text-[var(--reception-label)]",children:ne(`${F.first_name} ${F.last_name}`)}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-2 text-[13px] text-[var(--reception-label-2)]",children:[F.resident_name&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ot,{className:"h-3.5 w-3.5"})," ",ne(F.resident_name)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ve,{className:"h-3.5 w-3.5"})," In ",Ze(F.signed_in_at)," · ",ke>0?`${Ds(ke)} overdue`:`${Ds(be)} on site`]})]})]})]}),e.jsxs(k,{size:"sm",variant:"outline",className:"min-h-11 gap-2 rounded-[14px] border-[var(--reception-hairline)] bg-[var(--reception-surface)] px-4 text-[14px] font-semibold text-[var(--reception-alert)] hover:bg-[var(--reception-surface-2)] hover:text-[var(--reception-alert)]",onClick:()=>fe.mutate(F.id),disabled:fe.isPending,children:[e.jsx(lt,{className:"h-4 w-4"})," Sign out"]})]},F.id)})}),S<m.length&&e.jsx("div",{className:"mt-4 flex justify-center border-t border-[var(--reception-hairline)] pt-4",children:e.jsx(k,{type:"button",variant:"outline",className:"min-h-11 rounded-[14px] border-[var(--reception-hairline)] bg-[var(--reception-surface)] px-5 text-[14px] font-semibold",onClick:()=>_(F=>Math.min(F+3,m.length)),children:"Load more needs attention"})})]}),x.length>0&&e.jsxs("section",{className:"reception-card border-rose-200/80 bg-rose-50/65 p-5 dark:border-rose-400/20 dark:bg-rose-950/20","aria-labelledby":"resident-occasions-heading",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsx(ys,{className:"h-5 w-5 text-rose-600 dar
1k:text-rose-300"}),e.jsx("h2",{id:"resident-occasions-heading",className:"text-[17px] font-semibold text-[var(--reception-label)]",children:"Resident occasions"}),e.jsx("span",{className:"rounded-full border border-rose-200 bg-white/70 px-2 py-0.5 text-[11px] font-medium text-rose-700 dark:border-rose-400/25 dark:bg-rose-950/35 dark:text-rose-200",children:"Private Reception reminder"})]}),e.jsx("ul",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:x.slice(0,V).map(F=>{const be=F.type==="birthday"?ys:ca;return e.jsxs("li",{className:"flex min-h-14 items-center gap-3 rounded-[14px] border border-rose-100 bg-white/75 px-4 py-3 dark:border-rose-400/15 dark:bg-slate-950/45",children:[e.jsx(be,{className:"h-4 w-4 shrink-0 text-rose-600 dark:text-rose-300"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"truncate text-[14px] font-semibold text-[var(--reception-label)]",children:[F.resident_name,F.unit_room?` · ${F.unit_room}`:""]}),e.jsx("p",{className:"text-[12px] text-[var(--reception-label-2)]",children:gi(F.type,F.days_until)})]})]},`${F.resident_id}-${F.type}`)})}),V<x.length&&e.jsx("div",{className:"mt-3 flex justify-center border-t border-rose-200/70 pt-3 dark:border-rose-400/20",children:e.jsx(k,{type:"button",variant:"outline",className:"min-h-11 rounded-[14px] border-rose-200 bg-white/70 px-5 text-[14px] font-semibold text-rose-700 hover:bg-white dark:border-rose-400/25 dark:bg-rose-950/35 dark:text-rose-200",onClick:()=>b(F=>Math.min(F+3,x.length)),children:"Show more occasions"})})]}),e.jsxs("section",{"aria-labelledby":"reception-status-heading",children:[e.jsx("div",{id:"reception-status-heading",children:e.jsx(Tt,{title:"Status"})}),e.jsx("ul",{className:"grid items-stretch gap-3 sm:grid-cols-2 md:grid-cols-4","aria-label":"Live Reception metrics",children:Le.map(F=>e.jsx("li",{className:"h-full",children:e.jsx(mi,{metric:F})},F.key))}),Se.length>0&&e.jsx("ul",{className:"mt-4 flex flex-wrap gap-2","aria-label":"Idle Reception metrics",children:Se.map(F=>e.jsx("li",{children:e.jsx(ui,{metric:F})},F.key))})]}),e.jsx(pi,{active:I,onChange:X,maintenanceCount:Ne?"…":Ce?"!":De.length,parcelCount:$e.length,showMaintenance:K,showParcels:E}),I==="actions"&&e.jsxs("section",{id:"reception-dashboard-panel-actions",role:"tabpanel","aria-labelledby":"reception-dashboard-tab-actions desk-actions-heading",children:[e.jsx("div",{id:"desk-actions-heading",children:e.jsx(Tt,{title:"Desk actions"})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[G&&e.jsx(Ke,{icon:Pt,label:"Visitors Kiosk",description:"Open the visitor form and record an arrival.",href:r}),s.has("service_people")&&e.jsx(Ke,{icon:ct,label:"Contractor sign-in",description:"Register a contractor arriving on site.",href:r}),M&&e.jsx(Ke,{icon:et,label:"Add reception note",description:"Record a note or resident follow-up.",onClick:()=>je(null)}),ge&&e.jsx(Ke,{icon:Me,label:"Send Front Desk notice",description:"Message a resident or staff member.",onClick:()=>f(!0)}),E&&e.jsx(Ke,{icon:Oe,label:"Log a delivery",description:"Record a parcel and its storage location.",onClick:()=>u(!0)}),K&&e.jsx(Ke,{icon:Ee,label:"Raise maintenance request",description:"Create a request for the maintenance team.",onClick:()=>l("maintenance")})]})]}),I==="maintenance"&&K&&e.jsx("div",{id:"reception-dashboard-panel-maintenance",role:"tabpanel","aria-labelledby":"reception-dashboard-tab-maintenance",children:e.jsx(fi,{requests:re,total:De.length,loading:Ne,error:Ce,onView:()=>l("maintenance"),onOpen:F=>l("maintenance",F)})}),I==="parcels"&&E&&e.jsx("div",{id:"reception-dashboard-panel-parcels",role:"tabpanel","aria-labelledby":"reception-dashboard-tab-parcels",children:e.jsx(ji,{deliveries:$e,onView:()=>l("deliveries"),onOpen:F=>l("deliveries",F)})}),M&&e.jsx(xs,{slug:t,resident:p,lockResident:!!p,open:o,onOpenChange:w}),A&&e.jsx(ps,{slug:t,open:C,onOpenChange:T}),E&&e.jsx(Jr,{slug:t,open:v,onOpenChange:u}),ge&&e.jsx(_a,{slug:t,open:N,onOpenChange:f,heading:"Send Front Desk notice",description:"Choose a resident or staff member, then review the message before sending.",allowStaff:!0,allowResident:s.has("resident_search"),staffToolKey:"internal_notification",defaultTitle:"Message from Reception",defaultResidentBody:"Reception has a message for you. Please contact the front desk when convenient.",defaultStaffBody:"Reception has a message for you. Please contact the front desk when convenient.",submitting:we.isPending,onSubmit:F=>we.mutate(F)})]})}function gi(t,s){const a=t==="birthday"?"Birthday":"Wedding anniversary";return s===0?`${a} today`:s===1?`${a} tomorrow`:`${a} in ${s} days`}function fi({requests:t,total:s,loading:a,error:r,onView:d,onOpen:l}){const[n,g]=i.useState(3),c=t.slice(0,n);return e.jsxs("section",{"aria-labelledby":"maintenance-preview-heading",children:[e.jsx("div",{id:"maintenance-preview-heading",children:e.jsx(Tt,{title:"Maintenance",count:a?"Loading…":r?"Unavailable":`${s} open`,action:!a&&!r?e.jsx(Ca,{count:s,onClick:d}):void 0})}),a?e.jsx("p",{className:"text-[13px] text-[var(--reception-label-2)]",children:"Loading maintenance requests…"}):r?e.jsx("p",{className:"text-[13px] text-[var(--reception-label-2)]",children:"Maintenance totals are temporarily unavailable. Open Maintenance to retry."}):t.length===0?e.jsx("p",{className:"text-[13px] text-[var(--reception-label-2)]",children:"No open maintenance requests."}):e.jsx("ul",{className:"reception-card divide-y divide-[var(--reception-hairline)] overflow-hidden p-1",children:c.map(m=>{const x=ci(m.created_at);return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>l(m.id),className:"reception-list-row group flex w-full items-center gap-3 rounded-xl px-5 text-left transition-all hover:bg-[var(--reception-blue-tint)] focu
1s-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx("span",{className:"reception-icon-tile reception-icon-tile--small",children:e.jsx(Ee,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[15px] font-semibold text-[var(--reception-label)]",children:li(m.issue_type)}),e.jsxs("span",{className:"mt-1 block truncate text-[13px] text-[var(--reception-label-2)]",children:[m.property_label||m.location||"Location not set",m.notes?` · ${m.notes}`:""]})]}),!m.acknowledged_at&&e.jsxs("span",{className:$("shrink-0 text-[12px] font-semibold tabular-nums",di(x)),children:["Unacknowledged",x>0?` ${x} days`:""]}),e.jsx(at,{className:"h-4 w-4 shrink-0 text-[var(--reception-label-3)] transition-transform group-hover:translate-x-0.5"})]})},m.id)})}),!a&&!r&&n<t.length&&e.jsx("div",{className:"mt-3 flex justify-center",children:e.jsx(k,{type:"button",variant:"outline",className:"min-h-11 rounded-[14px] border-[var(--reception-hairline)] px-5",onClick:()=>g(m=>Math.min(m+3,t.length)),children:"Load more maintenance"})})]})}function ji({deliveries:t,onView:s,onOpen:a}){const[r,d]=i.useState(3),l=t.slice(0,r);return e.jsxs("section",{"aria-labelledby":"delivery-preview-heading",children:[e.jsx("div",{id:"delivery-preview-heading",children:e.jsx(Tt,{title:"Parcels awaiting collection",count:t.length,action:e.jsx(Ca,{count:t.length,onClick:s})})}),t.length===0?e.jsx("p",{className:"text-[13px] text-[var(--reception-label-2)]",children:"No parcels are awaiting collection."}):e.jsx("ul",{className:"reception-card divide-y divide-[var(--reception-hairline)] overflow-hidden p-1",children:l.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>a(n.id),className:"reception-list-row group flex w-full items-center gap-3 rounded-xl px-5 text-left transition-all hover:bg-[var(--reception-blue-tint)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsx("span",{className:"reception-icon-tile reception-icon-tile--small",children:e.jsx(Oe,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[15px] font-semibold text-[var(--reception-label)]",children:n.tracking_number?`#${n.tracking_number}`:ne(n.resident_name,"Unassigned parcel")}),e.jsxs("span",{className:"mt-1 block truncate text-[13px] text-[var(--reception-label-2)]",children:[n.storage_location||"Front desk",n.description?` · ${n.description}`:"",n.resident_name?` · ${ne(n.resident_name)}`:""]})]}),e.jsx(at,{className:"h-4 w-4 shrink-0 text-[var(--reception-label-3)] transition-transform group-hover:translate-x-0.5"})]})},n.id))}),r<t.length&&e.jsx("div",{className:"mt-3 flex justify-center",children:e.jsx(k,{type:"button",variant:"outline",className:"min-h-11 rounded-[14px] border-[var(--reception-hairline)] px-5",onClick:()=>d(n=>Math.min(n+3,t.length)),children:"Load more parcels"})})]})}function Ca({count:t,onClick:s}){return e.jsxs("button",{type:"button",onClick:s,className:"inline-flex min-h-11 items-center gap-1 text-[13px] font-semibold text-[var(--reception-blue-600)] hover:text-[var(--reception-blue-500)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:["View all ",t,e.jsx(at,{className:"h-4 w-4"})]})}function As(){const t=new Date;return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}function Sa({slug:t,open:s,onOpenChange:a,initialResident:r=null,trigger:d}){const{toast:l}=pe(),n=oe(),[g,c]=i.useState(r),[m,x]=i.useState(""),[o,w]=i.useState(""),[p,j]=i.useState(As()),[C,T]=i.useState(""),[v,u]=i.useState(!1),[N,f]=i.useState("");i.useEffect(()=>{s&&c(r)},[r,s]);const S=()=>{c(null),x(""),w(""),j(As()),T(""),u(!1),f("")},_=b=>{b||S(),a(b)},V=z({mutationFn:()=>dn(t,{resident_id:g?.id??null,resident_name:g?.display_name??null,visitor_name:m.trim(),visitor_company:o.trim()||null,expected_date:p||null,expected_at:p&&C?new Date(`${p}T${C}`).toISOString():null,recurring:v,notes:N.trim()||null}),onSuccess:()=>{l({title:"Expected visitor added",description:"The arrival is now visible in Reception's Expected Visitors queue."}),n.invalidateQueries({queryKey:["reception-expected",t]}),n.invalidateQueries({queryKey:["reception-overview",t]}),_(!1)},onError:b=>l({title:"Couldn't add expected visitor",description:b.message,variant:"destructive"})});return e.jsxs(ce,{open:s,onOpenChange:_,children:[d&&e.jsx(Dt,{asChild:!0,children:d}),e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"Add an expected visitor"})}),e.jsx(or,{kind:"indirect",compact:!0}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Visiting resident"}),e.jsx(Te,{slug:t,value:g,onChange:c,optional:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"expected-visitor-name",children:"Visitor name"}),e.jsx(O,{id:"expected-visitor-name",value:m,onChange:b=>x(b.target.value),placeholder:"Who is coming?"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"expected-visitor-company",children:"Company"}),e.jsx(O,{id:"expected-visitor-company",value:o,onChange:b=>w(b.target.value),placeholder:"Optional"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"expected-visitor-date",children:"Date"}),e.jsx(O,{id:"expected-visitor-date",type:"date",value:p,onChange:b=>j(b.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"expected-visitor-time",children:"Time"}),e.jsx(O,{id:"expected-visitor-time",type:"time",value:C,onChange:b=>T(b.target.value)})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"expected-visitor-notes",children:"Notes"}),e.jsx(ve,{id:"expected-visitor-notes",value:N,onChange:b=>f(b.target.value),rows:2,placeholder:"Optional"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:v,onCheckedChange:b=>u(b===!0)})," Recurring visitor"]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>_(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>V.mutate(),disabled:V.isPending||!m.trim(),children:[V.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Add expected visitor"]})]})]})]})}function ht({icon:t,title:s,message:a}){return e.jsxs("div",{"data-pippa-not-enabled":"",className:$(W,"border-dashed p-10 text-center"),children:[e.jsx("div",{className:"mx-auto mb-3 flex h-14 w-14 items-center justify-center rounded-2xl bg-slate-100 text-slate-400 dark:bg-slate-800 dark:text-slate-500",children:e.jsx(t,{className:"h-7 w-7"})}),e.jsx("p",{className:"text-base font-semibold text-slate-800 dark:text-slate-100",children:s}),e.jsx("p",{className:"mx-auto mt-1 max-w-md text-sm text-slate-500 dark:text-slate-400",children:a})]})}function We({icon:t,eyebrow:s="Reception workspace",title:a,description:r,action:d,className:l}){return e.jsxs("header",{className:$("flex flex-wrap items-center justify-between gap-4",l),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3.5",children:[e.jsx("span",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(t,{className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-[0.18em] text-primary",children:s}),e.jsx("h1",{className:"mt-0.5 text-3xl font-bold tracking-tight text-foreground",children:a}),e.jsx("p",{className:"mt-1 max-w-3xl text-lg font-medium text-black dark:text-white",children:r})]})]}),d&&e.jsx("div",{className:"shrink-0",children:d})]})}function bi({slug:t,enabled:s}){const[a,r]=i.useState(""),d=xt(a,250),[l,n]=i.useState(null),g=s.has("resident_search"),c=s.has("reception_notes"),m=s.has("phone_messages"),x=s.has("maintenance_request"),o=s.has("away_notifications"),w=s.has("emergency_contacts"),p=s.has("expected_visitors"),{data:j,isLoading:C,isError:T}=B({queryKey:["reception-residents",t,d],queryFn:()=>Lt(t,d),enabled:g,staleTime:3e4}),v=j||[];return e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:ze,title:"Residents",description:"Search the directory and start a note, message, or request using reception-safe details."}),g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-4 top-1/2 h-5 w-5 -translate-y-1/2 text-muted-foreground"}),e.jsx(O,{value:a,onChange:u=>r(u.target.value),"data-update-transient":"true",placeholder:"Search by name, preferred name or unit/room...",className:"h-14 roun
1ded-xl border-border bg-card pl-12 text-base shadow-sm","aria-label":"Search residents"})]}),C?e.jsxs("p",{className:"flex items-center gap-2 py-10 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading residents..."]}):T?e.jsx("div",{className:$(W,"border-dashed p-10 text-center text-sm text-muted-foreground"),children:"Couldn't load residents right now. Please try again."}):v.length===0?e.jsxs("div",{className:$(W,"border-dashed p-10 text-center"),children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(ze,{className:"h-6 w-6"})}),e.jsx("p",{className:"text-base font-semibold text-foreground",children:d?`No residents match "${d}".`:"No residents found."}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Try a different name, preferred name, or unit number."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[v.length," resident",v.length===1?"":"s"]}),e.jsx("ul",{className:"grid grid-cols-1 gap-3 2xl:grid-cols-2",children:v.map(u=>e.jsxs("li",{className:$(W,"overflow-hidden p-5 transition-all hover:border-primary/20 hover:shadow-md"),children:[e.jsx("div",{className:"flex flex-wrap items-start justify-between gap-3",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"reception-solid-control grid h-12 w-12 shrink-0 place-items-center rounded-2xl text-[var(--reception-blue-600)] shadow-sm",children:e.jsx(pt,{className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"truncate text-[17px] font-semibold text-foreground",children:[Be(u),u.preferred_name&&e.jsxs("span",{className:"ml-2 text-sm font-normal text-muted-foreground",children:['"',u.preferred_name,'"']})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground",children:[u.unit_room&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3.5 w-3.5"})," ",u.unit_room]}),u.status&&e.jsx(L,{variant:"outline",className:"capitalize",children:u.status})]})]})]})}),e.jsxs("div",{className:"reception-resident-actions mt-4 grid grid-cols-2 gap-2 border-t border-border/60 pt-4 sm:grid-cols-3",children:[c&&e.jsxs(k,{variant:"outline",className:"h-auto min-h-[58px] justify-start gap-2 rounded-xl border-primary/20 bg-primary/10 px-3 text-primary hover:bg-primary/15",onClick:()=>n({type:"note",resident:u}),children:[e.jsx(et,{className:"h-4 w-4"})," ",e.jsxs("span",{className:"text-left",children:[e.jsx("span",{className:"block text-[13px] font-semibold",children:"Add note"}),e.jsx("span",{className:"block text-[11px] font-normal opacity-75",children:"Reception note"})]})]}),m&&e.jsxs(k,{variant:"outline",className:"reception-solid-control h-auto min-h-[58px] justify-start gap-2 rounded-xl border-border/70 px-3",onClick:()=>n({type:"message",resident:u}),children:[e.jsx(Xe,{className:"h-4 w-4 text-primary"})," ",e.jsxs("span",{className:"text-left",children:[e.jsx("span",{className:"block text-[13px] font-semibold",children:"Message"}),e.jsx("span",{className:"block text-[11px] font-normal text-muted-foreground",children:"Phone follow-up"})]})]}),x&&e.jsxs(k,{variant:"outline",className:"reception-solid-control h-auto min-h-[58px] justify-start gap-2 rounded-xl border-border/70 px-3",onClick:()=>n({type:"maintenance",resident:u}),children:[e.jsx(Ee,{className:"h-4 w-4 text-primary"})," ",e.jsxs("span",{className:"text-left",children:[e.jsx("span",{className:"block text-[13px] font-semibold",children:"Maintenance"}),e.jsx("span",{className:"block text-[11px] font-normal text-muted-foreground",children:"Raise request"})]})]}),c&&e.jsxs(k,{variant:"outline",className:"reception-solid-control h-auto min-h-[58px] justify-start gap-2 rounded-xl border-border/70 px-3",onClick:()=>n({type:"notes",resident:u}),children:[e.jsx(ha,{className:"h-4 w-4 text-primary"})," ",e.jsxs("span",{className:"text-left",children:[e.jsx("span",{className:"block text-[13px] font-semibold",children:"Resident notes"}),e.jsx("span",{className:"block text-[11px] font-normal text-muted-foreground",children:"Recent history"})]})]}),w&&e.jsxs(k,{variant:"outline",className:"reception-solid-control h-auto min-h-[58px] justify-start gap-2 rounded-xl border-border/70 px-3",onClick:()=>n({type:"family",resident:u}),children:[e.jsx(ze,{className:"h-4 w-4 text-primary"})," ",e.jsxs("span",{className:"text-left",children:[e.jsx("span",{className:"block text-[13px] font-semibold",children:"Family"}),e.jsx("span",{className:"block text-[11px] font-normal text-muted-foreground",children:"Contacts"})]})]}),o&&e.jsxs(k,{variant:"outline",className:"reception-solid-control h-auto min-h-[58px] justify-start gap-2 rounded-xl border-border/70 px-3",onClick:()=>n({type:"away",resident:u}),children:[e.jsx(ya,{className:"h-4 w-4 text-primary"})," ",e.jsxs("span",{className:"text-left",children:[e.jsx("span",{className:"block text-[13px] font-semibold",children:"Away"}),e.jsx("span",{className:"block text-[11px] font-normal text-muted-foreground",children:"Record absence"})]})]}),p&&e.jsxs(k,{variant:"outline",className:"reception-solid-control h-auto min-h-[58px] justify-start gap-2 rounded-xl border-border/70 px-3",onClick:()=>n({type:"expected",resident:u}),children:[e.jsx(Yt,{className:"h-4 w-4 text-primary"})," ",e.jsxs("span",{className:"text-left",children:[e.jsx("span",{className:"block text-[13px] font-semibold",children:"Expected visitor"}),e.jsx("span",{className:"block text-[11px] font-normal text-muted-foreground",children:"Record arrival plan"})]})]})]})]},u.id))})]})]}):e.jsx(ht,{icon:ze,title:"Resident search isn't enabled",message:"Ask your village admin to enable Resident Search under Reception & Visitors - Reception Tools."}),c&&l?.type==="note"&&e.jsx(xs,{slug:t,resident:l.resident,lockResident:!0,open:!0,onOpenChange:u=>!u&&n(null)}),l?.type==="message"&&e.jsx(ps,{slug:t,resident:l.resident,lockResident:!0,open:!0,onOpenChange:u=>!u&&n(null)}),l?.type==="maintenance"&&e.jsx(ei,{slug:t,resident:l.resident,lockResident:!0,open:!0,onOpenChange:u=>!u&&n(null)}),l?.type==="away"&&e.jsx(ti,{slug:t,resident:l.resident,open:!0,onOpenChange:u=>!u&&n(null)}),c&&l?.type==="notes"&&e.jsx(ai,{slug:t,resident:l.resident,open:!0,onOpenChange:u=>!u&&n(null)}),l?.type==="family"&&e.jsx(ni,{slug:t,resident:l.resident,open:!0,onOpenChange:u=>!u&&n(null)}),p&&l?.type==="expected"&&e.jsx(Sa,{slug:t,initialResident:l.resident,open:!0,onOpenChange:u=>!u&&n(null)})]})}
1const vi={default:"bg-[#eef1ea] text-[#6f7d68] dark:bg-slate-800 dark:text-slate-200",warning:"bg-[#f1ece7] text-[#765f52] dark:bg-slate-800 dark:text-slate-200",danger:"bg-[#f6e9e4] text-[#8a5c4b] dark:bg-slate-800 dark:text-slate-200"},yi={default:"text-slate-800 dark:text-slate-100",warning:"text-[#765f52] dark:text-slate-200",danger:"text-[#8a5c4b] dark:text-slate-200"};function gt({icon:t,title:s,tone:a="default",meta:r,action:d,className:l}){return e.jsx(Ba,{className:$("pb-4",l),children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs(Qa,{className:$("flex items-center gap-3 text-xl",yi[a]),children:[e.jsx("span",{className:$("flex h-12 w-12 shrink-0 items-center justify-center rounded-xl",vi[a]),children:e.jsx(t,{className:"h-6 w-6",strokeWidth:2})}),s]}),(r||d)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r,d]})]})})}function Ni({slug:t}){const{toast:s}=pe(),a=oe(),[r,d]=i.useState(!1),{data:l,isLoading:n,isError:g}=B({queryKey:["reception-expected",t],queryFn:()=>xn(t),staleTime:15e3}),c=l||[],m=()=>{a.invalidateQueries({queryKey:["reception-expected",t]}),a.invalidateQueries({queryKey:["reception-overview",t]})},x=z({mutationFn:o=>mn(t,o),onSuccess:()=>{s({title:"Visitor signed in"}),m(),a.invalidateQueries({queryKey:["reception-visitors",t]})},onError:o=>s({title:"Couldn't sign in",description:o.message,variant:"destructive"})});return e.jsxs(tt,{className:W,children:[e.jsx(gt,{icon:cr,title:"Expected today",action:e.jsx(Sa,{slug:t,open:r,onOpenChange:d,trigger:e.jsxs(k,{size:"sm",className:`gap-1.5 ${Y}`,children:[e.jsx(nt,{className:"h-4 w-4"})," Add expected"]})})}),e.jsx(st,{children:n?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):g?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load expected visitors."}):c.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"No visitors expected today."}):e.jsx("ul",{className:"space-y-2.5",children:c.map(o=>{const w=o.status==="arrived";return e.jsx("li",{className:"reception-workspace-row rounded-[16px] p-3.5",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-base font-semibold text-foreground",children:[ne(o.visitor_name),o.recurring&&e.jsx(dr,{className:"ml-1.5 inline h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground",children:[o.resident_name&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ot,{className:"h-3.5 w-3.5"})," ",ne(o.resident_name)]}),o.visitor_company&&e.jsx("span",{children:o.visitor_company}),o.expected_at&&e.jsx("span",{children:Ze(o.expected_at)})]})]}),e.jsx("div",{className:"flex flex-col items-end gap-2",children:w?e.jsxs(L,{variant:"outline",className:"gap-1 border-[#b7c1af] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:[e.jsx(Je,{className:"h-3.5 w-3.5"})," Arrived"]}):e.jsxs(k,{size:"sm",className:`gap-1.5 ${Y}`,disabled:x.isPending,onClick:()=>x.mutate(o.id),children:[e.jsx(Je,{className:"h-4 w-4"})," Sign in"]})})]})},o.id)})})})]})}function wi(){const t=new Date;return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}function ki(t){return t?t<wi()?e.jsx(L,{variant:"outline",className:"border-[#d8b9ab] bg-[#f6e9e4] text-[#8a5c4b] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:"Expired"}):e.jsxs(L,{variant:"outline",className:"border-[#b7c1af] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:["Valid to ",t]}):e.jsx(L,{variant:"secondary",children:"No expiry"})}function _i({slug:t}){const{toast:s}=pe(),a=oe(),[r,d]=i.useState(!1),[l,n]=i.useState(""),[g,c]=i.useState(""),[m,x]=i.useState(""),[o,w]=i.useState(!1),[p,j]=i.useState(!1),{data:C,isLoading:T,isError:v}=B({queryKey:["reception-inductions",t],queryFn:()=>un(t),staleTime:3e4}),u=C||[],{data:N}=B({queryKey:["reception-settings",t],queryFn:()=>na(t),staleTime:6e4,retry:1}),{data:f=[],isLoading:S}=B({queryKey:["reception-maintenance-contractors",t],queryFn:()=>hn(t),staleTime:6e4}),_=()=>{n(""),c(""),x(""),w(!1),j(!1)},V=z({mutationFn:()=>pn(t,{contractor_name:l.trim(),maintenance_contractor_id:g,expiry_date:m||null,documents_complete:o}),onSuccess:()=>{s({title:"Contractor inducted"}),d(!1),_(),a.invalidateQueries({queryKey:["reception-inductions",t]})},onError:b=>s({title:"Couldn't save induction",description:b.message,variant:"destructive"})});return e.jsxs(tt,{className:W,children:[e.jsx(gt,{icon:ct,title:"Contractor induction",action:e.jsxs(ce,{open:r,onOpenChange:d,children:[e.jsx(Dt,{asChild:!0,children:e.jsxs(k,{size:"sm",className:`gap-1.5 ${Y}`,children:[e.jsx(nt,{className:"h-4 w-4"})," Induct"]})}),e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"Induct a contractor"})}),e.jsxs("div",{className:"space-y-3",children:[N?.contractor_induction_text&&e.jsxs("div",{className:"max-h-40 overflow-auto rounded-xl border border-border/70 bg-muted/30 p-3 text-sm text-muted-foreground",children:[N.contractor_induction_version&&e.jsxs("p",{className:"mb-1 text-xs font-medium text-foreground",children:["Version ",N.contractor_induction_version]}),e.jsx("p",{className:"whitespace-pre-wrap",children:N.contractor_induction_text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"i-name",children:"Contractor name"}
1),e.jsx(O,{id:"i-name",value:l,onChange:b=>n(b.target.value),placeholder:"Full name"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Company / contractor organisation"}),e.jsxs(ee,{value:g,onValueChange:c,children:[e.jsx(te,{children:e.jsx(se,{placeholder:S?"Loading central directory…":"Choose from central directory"})}),e.jsx(ae,{children:f.map(b=>e.jsxs(q,{value:b.id,children:[b.business_name,b.trade_category?` · ${b.trade_category.replace(/_/g," ")}`:""]},b.id))})]})]})]}),!S&&f.length===0&&e.jsx("p",{className:"rounded-xl border border-dashed p-3 text-sm text-muted-foreground",children:"No active contractors are available. Add the organisation in Admin → Maintenance → Contractors before recording an induction."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"i-expiry",children:"Induction expiry"}),e.jsx(O,{id:"i-expiry",type:"date",value:m,onChange:b=>x(b.target.value)})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:o,onCheckedChange:b=>w(b===!0)})," Required documents sighted"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:p,onCheckedChange:b=>j(b===!0)})," Contractor has read & accepted the induction"]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>d(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>V.mutate(),disabled:V.isPending||!l.trim()||!g||!p,children:[V.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Save induction"]})]})]})]})}),e.jsx(st,{children:T?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):v?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load inductions."}):u.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"No contractor inductions yet."}):e.jsx("ul",{className:"space-y-2.5",children:u.slice(0,25).map(b=>e.jsx("li",{className:"reception-workspace-row rounded-[16px] p-3.5",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-base font-semibold text-foreground",children:b.contractor_name}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground",children:[b.company&&e.jsx("span",{children:b.company}),b.induction_version&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Mt,{className:"h-3.5 w-3.5"})," v",b.induction_version]}),b.accepted_at&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Gt,{className:"h-3.5 w-3.5"})," ",new Date(b.accepted_at).toLocaleDateString("en-NZ",{weekday:"short",day:"numeric",month:"short",year:"numeric"})]})]})]}),ki(b.expiry_date)]})},b.id))})})]})}const Ci=[{key:"all",label:"All"},{key:"family",label:"Family / friend"},{key:"contractor",label:"Contractor / service"},{key:"delivery",label:"Delivery"},{key:"company",label:"Company"},{key:"recent",label:"Recently used"}],Si=25,Ra=t=>t?String(t).replace(/_/g," "):"Visitor";function Ri({slug:t,id:s,onBack:a,onSaved:r}){const{toast:d}=pe(),l=oe(),{data:n,isLoading:g,isError:c}=B({queryKey:["reception-visitor-directory-detail",t,s],queryFn:()=>bn(t,s),staleTime:1e4}),[m,x]=i.useState({});i.useEffect(()=>{n?.item&&x({...n.item})},[n?.item]);const o=(p,j)=>x(C=>({...C,[p]:j})),w=z({mutationFn:()=>fn(t,s,{first_name:m.first_name,last_name:m.last_name,phone:m.phone??null,email:m.email??null,company:m.company??null,visitor_type:m.visitor_type??void 0,service_type:m.service_type??null,is_service_person:m.is_service_person,is_active:m.is_active,notes:m.notes??null}),onSuccess:p=>{d({title:"Visitor profile updated"}),l.invalidateQueries({queryKey:["reception-visitor-directory-detail",t,s]}),r(p)},onError:p=>d({title:"Couldn't save",description:p.message,variant:"destructive"})});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:a,className:"inline-flex items-center gap-1 text-sm font-medium text-[#5f6e58] hover:underline dark:text-slate-300",children:[e.jsx(Wa,{className:"h-4 w-4"})," Back to list"]}),g?e.jsxs("p",{className:"flex items-center gap-2 py-8 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading profile..."]}):c||!n?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load this visitor."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-slate-400",children:"Contact details"}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"v-first",children:"First name"}),e.jsx(O,{id:"v-first",value:m.first_name||"",onChange:p=>o("first_name",p.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"v-last",children:"Last name"}),e.jsx(O,{id:"v-last",value:m.last_name||"",onChange:p=>o("last_name",p.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"v-phone",children:"Phone"}),e.jsx(O,{id:"v-phone",type:"tel",inputMode:"tel",value:m.phone||"",onChange:p=>o("phone",p.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"v-email",children:"Email"}),e.jsx(O,{id:"v-email",type:"email",value:m.email||"",onChange:p=>o("email",p.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"v-company",children:"Company"}),e.jsx(O,{id:"v-company",value:m.company||"",onChange:p=>o("company",p.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Visitor type"}),e.jsxs(ee,{value:m.visitor_type||"visitor",onValueChange:p=>o("visitor_type",p),children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:jn.map(p=>e.jsx(q,{value:p,children:Ra(p)},p))})]})]})]}),(m.is_service_person||m.visitor_type==="service_person"||m.visitor_type==="contractor")&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"v-service",children:"Service type"}),e.jsx(O,{id:"v-service",value:m.service_type||"",onChange:p=>o("service_type",p.target.value),placeholder:"Maintenance, Healthcare, Cleaning...",className:"h-11"})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:!!m.is_service_person,onCheckedChange:p=>o("is_service_person",p===!0)}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ee,{className:"h-4 w-4 text-muted-foreground"})," Service / contractor"]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:m.is_active!==!1,onCheckedChange:p=>o("is_active",p===!0)}),"Active"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"v-notes",children:"Internal reception notes"}),e.jsx(ve,{id:"v-notes",value:m.notes||"",onChange:p=>o("notes",p.target.value),rows:3,placeholder:"Notes visible only to reception."})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(k,{className:`gap-1.5 ${Y}`,disabled:w.isPending||!m.first_name?.trim()||!m.last_name?.trim(),onClick:()=>w.mutate(),children:[w.isPending?e.jsx(U,{className:"h-4 w-4 animate-spin"}):e.jsx(os,{className:"h-4 w-4"})," Save changes"]})})]}),e.jsxs("div",{className:"space-y-2 border-t border-[#e3e0d8] pt-4 dark:border-slate-800",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-slate-400",children:"Visit history (read-only)"}),e.jsxs("div",{className:"flex flex-wrap gap-x-6 gap-y-1 text-sm text-muted-foreground",children:[e.jsxs("span",{children:[n.visit_count," visit",n.visit_count===1?"":"s"," recorded"]}),n.item.created_at&&e.jsxs("span",{children:["Added ",ie(n.item.created_at)]}),n.item.last_seen_at&&e.jsxs("span",{children:["Last seen ",ie(n.item.last_seen_at)]})]}),n.visits.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-4 text-center text-sm text-muted-foreground",children:"No visits recorded yet."}):e.jsx("ul",{className:"max-h-48 space-y-1.5 overflow-y-auto",children:n.visits.map(p=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border border-slate-100 bg-slate-50/60 px-3 py-2 text-sm dark:border-slate-800 dark:bg-slate-800/30",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-foreground",children:[e.jsx(Ve,{className:"h-3.5 w-3.5 text-muted-foreground"})," ",ie(p.signed_in_at),p.signed_out_at&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["– out ",Ze(p.signed_out_at)]})]}),e.jsxs("span",{className:"inline-flex items-center gap-2 text-xs text-muted-foreground",children:[p.resident_name&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ot,{className:"h-3 w-3"})," ",p.resident_name]}),p.purpose&&e.jsx("span",{children:p.purpose}),e.jsx(L,{variant:p.status==="signed_in"?"secondary":"outline",className:"capitalize",children:String(p.status).replace(/_/g," ")})]})]}
1,p.id))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Visit logs are recorded automatically and can't be edited here."})]})]})]})}function Pi({slug:t}){const[s,a]=i.useState(!1),[r,d]=i.useState(""),l=xt(r,250),[n,g]=i.useState("all"),[c,m]=i.useState([]),[x,o]=i.useState(0),[w,p]=i.useState(!1),[j,C]=i.useState(!1),[T,v]=i.useState(!1),[u,N]=i.useState(null),f=async _=>{C(!0);const V=_?0:x;try{const b=await gn(t,{q:l,filter:n,limit:Si,offset:V});v(!!b.setup_required),m(M=>_?b.items:[...M,...b.items]),p(b.has_more),o(V+b.items.length)}catch{_&&m([]),p(!1)}finally{C(!1)}};i.useEffect(()=>{!s||u||f(!0)},[s,l,n]);const S=_=>{m(V=>V.map(b=>b.id===_.id?{...b,..._}:b))};return e.jsxs(e.Fragment,{children:[e.jsxs(k,{variant:"outline",className:`gap-1.5 ${Q}`,onClick:()=>a(!0),children:[e.jsx(Zt,{className:"h-4 w-4"})," Browse registered visitors"]}),e.jsx(ce,{open:s,onOpenChange:_=>{a(_),_||N(null)},children:e.jsxs(de,{className:"flex max-h-[92vh] max-w-2xl flex-col overflow-hidden",children:[e.jsx(me,{children:e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(Zt,{className:"h-5 w-5 text-[#6f7d68]"})," Registered visitors"]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:u?e.jsx(Ri,{slug:t,id:u,onBack:()=>N(null),onSaved:S}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx(O,{value:r,onChange:_=>d(_.target.value),"data-update-transient":"true",placeholder:"Search name or company...",className:"h-11 pl-9"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Ci.map(_=>e.jsx("button",{type:"button",onClick:()=>g(_.key),className:$("rounded-full border px-3 py-1.5 text-sm font-medium transition-colors",n===_.key?"border-[#87947f] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100":"border-[#dcd8cf] bg-white text-slate-600 hover:border-[#b7c1af] dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300"),children:_.label},_.key))}),T?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"The visitor directory isn't set up for this village yet."}):c.length===0&&!j?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"No registered visitors match this view."}):e.jsx("ul",{className:"space-y-2",children:c.map(_=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>N(_.id),className:"flex w-full items-center justify-between gap-3 rounded-xl border border-slate-200 bg-white px-4 py-3 text-left transition-colors hover:border-[#b7c1af] dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"block truncate text-sm font-semibold text-slate-900 dark:text-white",children:[_.first_name," ",_.last_name]}),e.jsxs("span",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground",children:[_.is_service_person&&e.jsx(Ee,{className:"h-3 w-3"}),e.jsx("span",{className:"capitalize",children:Ra(_.visitor_type)}),_.company&&e.jsxs("span",{className:"truncate",children:["· ",_.company]}),_.last_seen_at&&e.jsxs("span",{children:["· seen ",ie(_.last_seen_at)]})]})]}),e.jsx(at,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})},_.id))}),j&&e.jsxs("p",{className:"flex items-center justify-center gap-2 py-3 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}),w&&!j&&e.jsx("div",{className:"flex justify-center",children:e.jsx(k,{variant:"outline",className:Q,onClick:()=>f(!1),children:"Load more"})}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:"Full profiles are visible to reception only. The public kiosk never shows phone or email."})]})})]})})]})}const Ls=t=>t.visitor_type==="contractor"||t.visitor_type==="service_person",Ms=t=>t.visitor_type==="family"||t.visitor_type==="friend"||t.purpose==="Family visit"||t.purpose==="Friend visit",Os=t=>t.visitor_type==="delivery"||t.purpose==="Delivery",ts=t=>ne(`${t.first_name} ${t.last_name}`);function Ei({entry:t,onSignOut:s,signingOut:a,notified:r,onNotify:d,notifying:l}){const n=t.status==="signed_in",g=n&&!!t.resident_id;return e.jsxs("li",{className:"reception-workspace-row flex flex-wrap items-center justify-between gap-3 rounded-[14px] p-4",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-4 self-stretch",children:[e.jsx("span",{className:$("grid h-16 w-16 shrink-0 place-items-center self-center rounded-2xl bg-[var(--reception-tile)] text-[var(--reception-label-3)]",n&&"bg-[var(--reception-blue-tint)] text-[var(--reception-blue-600)]"),children:e.jsx(Je,{className:"h-8 w-8"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-base font-semibold text-foreground",children:ts(t)}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground",children:[t.resident_name&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ot,{className:"h-3.5 w-3.5"})," Visiting ",ne(t.resident_name)]}),t.company&&e.jsx("span",{children:t.company}),t.purpose&&e.jsx("span",{children:t.purpose}),!t.resident_name&&t.destination_label&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),t.destination_label]})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ve,{className:"h-3 w-3"})," In ",Ze(t.signed_in_at)]}),t.signed_out_at&&e.jsxs("span",{children:["- Out ",Ze(t.signed_out_at),t.auto_signed_out?" (midnight safety close)":""]})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[n?e.jsxs(L,{variant:"outline",className:"gap-1 border-primary/30 bg-primary/10 text-primary",children:[e.jsx(Je,{className:"h-3.5 w-3.5"})," On site"]}):e.jsx(L,{variant:"secondary",children:"Signed out"}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-1.5",children:[g&&(r?e.jsxs(L,{variant:"outline",className:"gap-1 border-primary/30 bg-primary/10 text-primary",children:[e.jsx(mt,{className:"h-3.5 w-3.5"})," Resident notified"]}):e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,onClick:d,disabled:l,children:[e.jsx(Me,{className:"h-4 w-4"})," Notify resident"]})),n&&e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,onClick:s,disabled:a,children:[e.jsx(lt,{className:"h-4 w-4"})," Sign out"]})]})]})]})}function Ti({slug:t}){const[s,a]=i.useState(""),r=xt(s,250),{data:d,isFetching:l}=B({queryKey:["visitor-directory-search",t,r],queryFn:()=>vn(t,r),enabled:r.trim().length>=2,staleTime:1e4}),n=d||[],g=r.trim().length>=2;return e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("h2",{className:"flex items-center gap-3 text-xl font-semibold text-foreground",children:[e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(Zt,{className:"h-6 w-6"})}),"Registered visitor directory"]}),e.jsx(Pi,{slug:t})]}),e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(O,{value:s,onChange:c=>a(c.target.value),placeholder:"Look up a returning visitor by name...",className:"h-11 pl-9"}),l&&e.jsx(U,{className:"absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 animate-spin text-muted-foreground"})]}),g&&e.jsx("ul",{className:"mt-3 space-y-2",children:n.length===0&&!l?e.jsxs("li",{className:"rounded-xl border border-dashed border-border bg-muted/40 px-4 py-4 text-center text-sm text-muted-foreground",children:['No registered visitor matches "',r,'".']}):n.map(c=>e.jsxs("li",{className:"reception-workspace-row flex items-center justify-between gap-3 rounded-xl px-4 py-3 text-sm",children:[e.jsx("span",{className:"font-medium text-foreground",children:ne(`${c.first_name} ${c.last_name}`)}),e.jsxs("span",{className:"flex items-center gap-1.5 text-muted-foreground",children:[c.is_service_person&&e.jsx(Ee,{className:"h-3.5 w-3.5"}),c.company||(c.visitor_type?String(c.visitor_type).replace(/_/g," "):"")]})]},c.id))}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Sign-in happens at the visitor kiosk. This lookup is read-only and never shows phone or email."})]})}function Fi({slug:t,enabled:s,overview:a,visitorsHref:r}){const{toast:d}=pe(),l=oe(),[n,g]=i.useState("all"),c=s.has("visitor_log"),m=s.has("expected_visitors"),x=s.has("contractor_induction"),{data:o,isLoading:w,isError:p}=B({queryKey:["reception-visitors",t],queryFn:()=>yn(t),enabled:c,staleTime:1e4,retry:1}),j=i.useMemo(()=>{const E=new Map;for(const K of o||[])E.set(K.id,K);for(const K of a?.lists.signed_in||[])E.set(K.id,K);return Array.from(E.values())},[o,a]),C=i.useMemo(()=>new Set((a?.lists.overdue||[]).map(E=>E.id)),[a]),T=j.filter(E=>E.status==="signed_in").length,v=z({mutationFn:E=>ta(t,E),onSuccess:()=>{d({title:"Signed out"}
1),l.invalidateQueries({queryKey:["reception-visitors",t]}),l.invalidateQueries({queryKey:["reception-overview",t]})},onError:E=>d({title:"Couldn't sign out",description:E instanceof Error?E.message:"Please try again.",variant:"destructive"})}),u=ut(t),[N,f]=i.useState(new Set),[S,_]=i.useState(null),V=z({mutationFn:E=>ns(t,{target_type:"resident",target_resident_id:E.resident_id,source_type:"visitor_arrival",source_id:E.id,title:`${ts(E)} has arrived`,body:`${ts(E)} has signed in at reception to visit you.`}),onMutate:E=>_(E.id),onSuccess:(E,K)=>{f(G=>new Set(G).add(K.id)),u(E.id,{title:"Resident notified"})},onError:E=>d({title:"Couldn't notify resident",description:E instanceof Error?E.message:"Please try again.",variant:"destructive"}),onSettled:()=>_(null)}),b=i.useMemo(()=>({all:j.length,signed_in:j.filter(E=>E.status==="signed_in").length,signed_out:j.filter(E=>E.status==="signed_out").length,overdue:j.filter(E=>C.has(E.id)).length,family:j.filter(Ms).length,delivery:j.filter(Os).length,contractor:j.filter(Ls).length}),[j,C]),M=i.useMemo(()=>j.filter(E=>{switch(n){case"signed_in":return E.status==="signed_in";case"signed_out":return E.status==="signed_out";case"overdue":return C.has(E.id);case"family":return Ms(E);case"delivery":return Os(E);case"contractor":return Ls(E);default:return!0}}),[j,n,C]),A=[{key:"all",label:"All"},{key:"signed_in",label:"On site"},{key:"signed_out",label:"Signed out"},{key:"overdue",label:"Overdue"},{key:"family",label:"Family / friend"},{key:"delivery",label:"Delivery"},{key:"contractor",label:"Contractor"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:bt,title:"Visitors",description:"Today's visitor activity, everyone on site, and the registered visitor directory.",action:e.jsx(k,{asChild:!0,className:`gap-1.5 ${Y}`,children:e.jsxs(At,{to:r,children:[e.jsx(Pt,{className:"h-4 w-4"})," Quick sign-in"]})})}),!c&&!m&&!x&&e.jsx(ht,{icon:bt,title:"Visitor tools aren't enabled",message:"Ask your village admin to enable Visitor Log, Expected Visitors, or Contractor Induction under Reception Tools."}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:$(W,"flex items-center gap-4 border-primary/25 bg-primary/10 p-4"),children:[e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-card text-primary",children:e.jsx(Je,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold tabular-nums text-primary",children:T}),e.jsxs("p",{className:"text-sm font-medium text-foreground",children:["visitor",T===1?"":"s"," currently on site"]})]})]}),e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-base font-semibold text-foreground",children:[e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(bt,{className:"h-6 w-6"})}),"Visitor activity"]}),e.jsx("div",{className:"mb-5 flex gap-1 overflow-x-auto rounded-[14px] border border-primary/15 bg-primary/10 p-1 scrollbar-hide",role:"tablist","aria-label":"Filter visitor log",children:A.map(E=>e.jsxs("button",{type:"button",onClick:()=>g(E.key),className:$("inline-flex min-h-10 shrink-0 items-center gap-1.5 rounded-[10px] px-3 py-2 text-sm font-semibold transition-all",n===E.key?"bg-primary text-primary-foreground shadow-sm":"text-muted-foreground hover:bg-card/70 hover:text-foreground"),children:[E.label,e.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:b[E.key]})]},E.key))}),w?e.jsxs("p",{className:"flex items-center gap-2 py-8 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading visitors..."]}):p?e.jsx("div",{className:"rounded-xl border border-dashed border-border bg-muted/40 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load today's visitors."}):M.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-border bg-muted/40 px-4 py-8 text-center text-sm text-muted-foreground",children:"No visitors in this view."}):e.jsx("ul",{className:"space-y-2.5",children:M.map(E=>e.jsx(Ei,{entry:E,onSignOut:()=>v.mutate(E.id),signingOut:v.isPending,notified:N.has(E.id),notifying:S===E.id,onNotify:()=>V.mutate(E)},E.id))})]}),e.jsx(Ti,{slug:t})]}),m&&e.jsx(Ni,{slug:t}),x&&e.jsx(_i,{slug:t})]})}const $i=[{value:"received",label:"Received"},{value:"awaiting_collection",label:"Awaiting collection"},{value:"notified",label:"Resident notified"},{value:"collected",label:"Collected"},{value:"returned",label:"Returned"}];function Di({slug:t,delivery:s,open:a,onOpenChange:r}){const{toast:d}=pe(),l=oe(),[n,g]=i.useState(null),[c,m]=i.useState(""),[x,o]=i.useState(""),[w,p]=i.useState(""),[j,C]=i.useState(""),[T,v]=i.useState("received");i.useEffect(()=>{!a||!s||(g(s.resident_id?{id:s.resident_id,display_name:s.resident_name||"Resident"}:null),m(s.courier||""),o(s.tracking_number||""),p(s.description||""),C(s.storage_location||""),v(s.status||"received"))},[a,s]);const u=()=>
1{l.invalidateQueries({queryKey:["reception-deliveries",t]}),l.invalidateQueries({queryKey:["reception-overview",t]})},N=z({mutationFn:f=>ra(t,s.id,{resident_id:n?.id??null,resident_name:n&&n.display_name||null,courier:c.trim()||null,tracking_number:x.trim()||null,description:w.trim()||null,storage_location:j.trim()||null,status:T,...f}),onSuccess:()=>{d({title:"Delivery updated"}),u(),r(!1)},onError:f=>d({title:"Couldn't update delivery",description:f instanceof Error?f.message:"Please try again.",variant:"destructive"})});return e.jsx(ce,{open:a,onOpenChange:r,children:e.jsxs(de,{className:"max-h-[92vh] overflow-y-auto",children:[e.jsx(me,{children:e.jsx(xe,{children:"Edit delivery"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"For resident"}),e.jsx(Te,{slug:t,value:n,onChange:g,optional:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"ed-courier",children:"Courier / sender"}),e.jsx(O,{id:"ed-courier",value:c,onChange:f=>m(f.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"ed-track",children:"Tracking #"}),e.jsx(O,{id:"ed-track",value:x,onChange:f=>o(f.target.value),className:"h-11"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"ed-store",children:"Storage location"}),e.jsx(O,{id:"ed-store",value:j,onChange:f=>C(f.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"ed-desc",children:"Description / notes"}),e.jsx(ve,{id:"ed-desc",value:w,onChange:f=>p(f.target.value),rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Status"}),e.jsxs(ee,{value:T,onValueChange:v,children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:$i.map(f=>e.jsx(q,{value:f.value,children:f.label},f.value))})]})]})]}),e.jsxs(he,{className:"flex-col gap-2 sm:flex-row sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(k,{variant:"outline",className:`gap-1.5 ${Q}`,disabled:N.isPending,onClick:()=>{v("collected"),N.mutate({status:"collected"})},children:[e.jsx(ga,{className:"h-4 w-4"})," Mark collected"]}),e.jsxs(k,{variant:"outline",className:`gap-1.5 ${Q}`,disabled:N.isPending,onClick:()=>{v("returned"),N.mutate({status:"returned"})},children:[e.jsx(ur,{className:"h-4 w-4"})," Mark returned"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsxs(k,{className:`gap-1.5 ${Y}`,disabled:N.isPending,onClick:()=>N.mutate(void 0),children:[N.isPending?e.jsx(U,{className:"h-4 w-4 animate-spin"}):e.jsx(os,{className:"h-4 w-4"})," Save changes"]})]})]})]})})}const ft="A package has arrived for you at reception. Please collect it when convenient.",Kt="A package has arrived at reception.",zt=12;function Ai(t){switch(t){case"collected":return e.jsx(L,{variant:"outline",className:"border-[#b7c1af] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:"Collected"});case"notified":return e.jsx(L,{variant:"outline",className:"border-[#dcd8cf] bg-[#f8f7f2] text-slate-600 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:"Resident notified"});case"returned":return e.jsx(L,{variant:"secondary",children:"Returned"});default:return e.jsx(L,{variant:"outline",className:"border-[#ded6ca] bg-[#f1ece7] text-[#765f52] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:"Awaiting collection"})}}const Li=[{value:"all",label:"All active"},{value:"waiting",label:"Waiting"},{value:"received",label:"Received"},{value:"awaiting_collection",label:"Awaiting collection"},{value:"notified",label:"Resident notified"},{value:"collected",label:"Collected"},{value:"returned",label:"Returned"},{value:"archived",label:"Archived"}];function Is(t){return t.status!=="collected"&&t.status!=="returned"}function Mi({slug:t,mode:s="card",focusDeliveryId:a,onFocusHandled:r}){const{toast:d}=pe(),l=oe(),[n,g]=i.useState(!1),[c,m]=i.useState(""),[x,o]=i.useState("all"),[w,p]=i.useState(zt),[j,C]=i.useState(null),[T,v]=i.useState(""),[u,N]=i.useState(""),[f,S]=i.useState(""),[_,V]=i.useState(""),[b,M]=i.useState(!1),[A,E]=i.useState("resident"),[K,G]=i.useState(null),[H,ge]=i.useState("Package arrived"),[D,Z]=i.useState(ft),[X,I]=i.useState(null),J=i.useRef(null),Fe=ut(t),Ue=()=>{C(null),v(""),N(""),S(""),V(""),M(!1),E("resident"),G(null),ge("Package arrived"),Z(ft)},Ne=y=>{E(y),Z(y==="staff"?Kt:ft)},Ce=x==="archived",{data:He,isLoading:$e,isError:De}=B({queryKey:["reception-deliveries",t,Ce],queryFn:()=>sa(t,{archived:Ce}),staleTime:15e3}),re=He||[],Ae=re.filter(Is),_e=s==="page",Le=i.useMemo(()=>{const y=c.trim().toLowerCase();return re.filter(h=>(x==="all"||x==="archived"?!0:x==="waiting"?Is(h):h.status===x)?y?[h.resident_name,h.courier,h.tracking_number,h.storage_location,h.description].some(Ye=>String(Ye||"").toLowerCase().includes(y)):!0:!1)},[re,c,x]),Se=_e?Le.slice(0,w):re.slice(0,25);i.useEffect(()=>{p(zt)},[c,x]),i.useEffect(()=>{if(!a){J.current=null;return}if(J.current===a)return;const y=re.find(h=>h.id===a);y&&(J.current=a,o("all"),m(""),I(y))},[re,a]);const fe=()=>
1{l.invalidateQueries({queryKey:["reception-deliveries",t]}),l.invalidateQueries({queryKey:["reception-overview",t]})},[we,je]=i.useState(null),F=z({mutationFn:y=>Ys(t,{...y}),onSuccess:y=>{Fe(y.notice_id),je(null),fe()},onError:y=>d({title:"Couldn't send notice",description:y instanceof Error?y.message:"Please try again.",variant:"destructive"})}),be=z({mutationFn:()=>Gs(t,{resident_id:j?.id??null,resident_name:j&&j.display_name||null,courier:T.trim()||null,tracking_number:u.trim()||null,storage_location:f.trim()||null,description:_.trim()||null}),onSuccess:y=>{b?F.mutate({id:y.id,target_type:A,target_resident_id:A==="resident"?j?.id??null:null,target_staff_user_id:A==="staff"?K?.id??null:null,title:H.trim()||"Package arrived",body:D.trim()||(A==="staff"?Kt:ft)}):d({title:"Delivery logged"}),g(!1),Ue(),fe()},onError:y=>d({title:"Couldn't log delivery",description:y instanceof Error?y.message:"Please try again.",variant:"destructive"})}),ke=z({mutationFn:({id:y,updates:h})=>ra(t,y,h),onSuccess:()=>fe(),onError:y=>d({title:"Couldn't update delivery",description:y instanceof Error?y.message:"Please try again.",variant:"destructive"})}),R=z({mutationFn:({id:y,archived:h})=>Nn(t,y,h),onSuccess:(y,h)=>{d({title:h.archived?"Delivery archived":"Delivery restored"}),fe()},onError:y=>d({title:"Couldn't update delivery",description:y instanceof Error?y.message:"Please try again.",variant:"destructive"})}),le=we?.resident_id?{id:we.resident_id,display_name:we.resident_name||"Resident"}:null;return e.jsxs(e.Fragment,{children:[e.jsxs(tt,{className:W,children:[e.jsx(gt,{icon:Oe,title:"Deliveries",meta:!Ce&&Ae.length>0&&e.jsxs(L,{variant:"secondary",className:"bg-[#eef1ea] text-[#5f6e58]",children:[Ae.length," waiting"]}),action:e.jsxs(ce,{open:n,onOpenChange:g,children:[e.jsx(Dt,{asChild:!0,children:e.jsxs(k,{size:"sm",className:`gap-1.5 ${Y}`,children:[e.jsx(nt,{className:"h-4 w-4"})," Log delivery"]})}),e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"Log a delivery"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"For resident"}),e.jsx(Te,{slug:t,value:j,onChange:C,optional:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"d-courier",children:"Courier / sender"}),e.jsx(O,{id:"d-courier",value:T,onChange:y=>v(y.target.value),placeholder:"NZ Post, CourierPost..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"d-track",children:"Tracking #"}),e.jsx(O,{id:"d-track",value:u,onChange:y=>N(y.target.value),placeholder:"Optional"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"d-store",children:"Storage location"}),e.jsx(O,{id:"d-store",value:f,onChange:y=>S(y.target.value),placeholder:"Front desk, parcel room..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"d-desc",children:"Description"}),e.jsx(ve,{id:"d-desc",value:_,onChange:y=>V(y.target.value),placeholder:"Small box, flowers, signed-for letter...",rows:2})]}),e.jsxs("label",{className:"flex min-h-[44px] items-center gap-3 rounded-xl border border-[#dcd8cf] bg-[#f8f7f2] px-3 py-2.5 text-sm font-medium text-foreground dark:border-slate-700 dark:bg-slate-800",children:[e.jsx(Re,{checked:b,onCheckedChange:y=>M(y===!0),className:"h-5 w-5"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Me,{className:"h-4 w-4 text-[#6f7d68]"})," Notify resident/staff now"]})]}),b&&e.jsxs("div",{className:"space-y-3 rounded-xl border border-[#e3e0d8] bg-white/70 p-3 dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Ne("resident"),className:`rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors ${A==="resident"?"border-[#87947f] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100":"border-[#dcd8cf] bg-white text-slate-600 hover:border-[#b7c1af] dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300"}`,children:"The resident"}),e.jsx("button",{type:"button",onClick:()=>Ne("staff"),className:`rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors ${A==="staff"?"border-[#87947f] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-600 dar
1k:bg-slate-800 dark:text-slate-100":"border-[#dcd8cf] bg-white text-slate-600 hover:border-[#b7c1af] dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300"}`,children:"A staff member"})]}),A==="resident"?!j&&e.jsx("p",{className:"text-xs text-muted-foreground",children:'Pick a resident in "For resident" above to notify them.'}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Staff member"}),e.jsx(Ot,{slug:t,value:K,onChange:G,toolKey:"deliveries"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"d-ntitle",children:"Title"}),e.jsx(O,{id:"d-ntitle",value:H,onChange:y=>ge(y.target.value),className:"h-10"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"d-nbody",children:"Message preview"}),e.jsx(ve,{id:"d-nbody",value:D,onChange:y=>Z(y.target.value),rows:2})]})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>g(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>be.mutate(),disabled:be.isPending||F.isPending||!j&&!_.trim()&&!T.trim()||b&&(A==="resident"?!j:!K),children:[(be.isPending||F.isPending)&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," ",b?"Log & notify":"Log delivery"]})]})]})]})}),e.jsxs(st,{children:[_e&&e.jsxs("div",{className:"mb-5 grid grid-cols-1 gap-3 lg:grid-cols-[1fr_260px]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx(O,{value:c,onChange:y=>m(y.target.value),"data-update-transient":"true",placeholder:"Search resident, courier, tracking number, notes...",className:"h-12 pl-10 text-base"})]}),e.jsxs(ee,{value:x,onValueChange:y=>o(y),children:[e.jsx(te,{className:"h-12 text-base",children:e.jsx(se,{})}),e.jsx(ae,{children:Li.map(y=>e.jsx(q,{value:y.value,children:y.label},y.value))})]})]}),$e?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):De?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load deliveries."}):Se.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:re.length===0?"No deliveries logged yet.":"No deliveries match this view."}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"space-y-2.5",children:Se.map(y=>e.jsx("li",{className:"reception-workspace-row rounded-[16px] p-4",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-[auto_minmax(0,1fr)_auto] md:items-start",children:[e.jsx("span",{className:"grid h-16 w-16 shrink-0 place-items-center self-center rounded-2xl bg-[var(--reception-amber-tint)] text-[var(--reception-amber-600)]",children:e.jsx(Oe,{className:"h-8 w-8"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[16px] font-semibold text-foreground",children:y.resident_name||"Unassigned parcel"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground",children:[y.courier&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(hr,{className:"h-3.5 w-3.5"})," ",y.courier]}),y.storage_location&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3.5 w-3.5"})," ",y.storage_location]}),y.tracking_number&&e.jsxs("span",{className:"text-xs",children:["#",y.tracking_number]})]}),y.description&&e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:y.description}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Logged ",ie(y.created_at)]})]}),e.jsxs("div",{className:"flex flex-col items-start gap-2 md:items-end",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-1.5",children:[y.archived_at&&e.jsx(L,{variant:"outline",className:"border-[#dcd8cf] bg-[#f8f7f2] text-slate-500 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300",children:"Archived"}),Ai(y.status)]}),y.notified_at&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Notified ",Ze(y.notified_at)]}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[!y.archived_at&&y.status!=="collected"&&y.status!=="returned"&&e.jsxs(k,{size:"sm",className:"min-h-11 gap-1.5 rounded-lg",disabled:ke.isPending,onClick:()=>ke.mutate({id:y.id,updates:{status:"collected"}}),children:[e.jsx(ga,{className:"h-4 w-4"})," Collected"]}),e.jsxs(mr,{children:[e.jsx(xr,{asChild:!0,children:e.jsx(k,{size:"icon",variant:"outline",className:`min-h-11 min-w-11 ${Q}`,"aria-label":`More actions for ${y.resident_name||"delivery"}`,children:e.jsx(ma,{className:"h-4 w-4"})})}),e.jsxs(pr,{align:"end",children:[e.jsxs(_t,{onClick:()=>I(y),children:[e.jsx(cs,{className:"mr-2 h-4 w-4"})," Edit"]}),!y.archived_at&&y.status!=="collected"&&y.status!=="returned"&&e.jsxs(_t,{disabled:F.isPending,onClick:()=>je(y),children:[e.jsx(Me,{className:"mr-2 h-4 w-4"})," ",y.status==="notified"?"Notify again":"Notify"]}),y.archived_at?e.jsxs(_t,{disabled:R.isPending,onClick:()=>R.mutate({id:y.id,archived:!1}),children:[e.jsx(gr,{className:"mr-2 h-4 w-4"})," Restore"]}):e.jsxs(_t,{disabled:R.isPending,onClick:()=>R.mutate({id:y.id,archived:!0}),children:[e.jsx(ds,{className:"mr-2 h-4 w-4"})," Archive"]})]})]})]})]})]})},y.id))}),_e&&Se.length<Le.length&&e.jsx("div",{className:"flex justify-center border-t border-[var(--reception-line)] pt-4",children:e.jsx(k,{variant:"outline",className:`min-h-11 min-w-[180px] ${Q}`,onClick:()=>p(y=>y+zt),children:"Load more deliveries"})})]})]})]}),e.jsx(_a,{slug:t,open:!!we,onOpenChange:y=>{y||je(null)},heading:"Notify about this delivery",description:"Send a Front Desk notice to a resident or staff member. The delivery stays on this list until it's collected.",allowStaff:!0,staffToolKey:"deliveries",presetResident:le,defaultTitle:"Package arrived",defaultResidentBody:ft,defaultStaffBody:Kt,submitLabel:"Send notice",submitting:F.isPending,onSubmit:y=>{we&&F.mutate({...y,id:we.id})}}),e.jsx(Di,{slug:t,delivery:X,open:!!X,onOpenChange:y=>{y||(I(null),r?.())}})]})}function Oi({slug:t,enabled:s,detailId:a,clearDetail:r}){const d=s.has("deliveries");return e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:Oe,title:"Deliveries",description:"Track parcels, courier items, resident notifications, and collected deliveries."}),d?e.jsx(Mi,{slug:t,mode:"page",focusDeliveryId:a,onFocusHandled:r}):e.jsx(ht,{icon:Oe,title:"Deliveries aren't enabled",message:"Ask your village admin to enable Deliveries under Reception Tools."})]})}const Ii=["General","Plumbing","Electrical","Heating/Cooling","Appliance","Grounds/Garden","Other"],Vi=[{value:"all",label:"All requests"},{value:"open",label:"Open requests"},{value:"resolved",label:"Resolved"},...Array.from(new Set(fr.map(t=>Ge(t)))).map(t=>({value:t,label:fa[t]||It(t)}))];function It(t){return(t||"needs_triage").replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase())}function us(t){return String(t||"Maintenance request").trim().toLocaleLowerCase("en-NZ").replace(new RegExp("\\b\\p{L}","gu"),a=>a.toLocaleUpperCase("en-NZ"))}function Vs(t){return Math.max(0,Math.floor((Date.now()-new Date(t).getTime())/864e5))}function qi(t){if(!t)return[];try{const s=JSON.parse(t);return Array.isArray(s)?s.filter(a=>
1typeof a=="string"):[t]}catch{return[t]}}function Pa(t){const s=Ge(t);return e.jsx(L,{className:$("border-transparent",jr[s]||"bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-200"),children:fa[s]||It(s)})}function Ea(t,s=!1){const a=String(t||"normal").toLowerCase();return a==="urgent"?e.jsx(L,{variant:"destructive",children:"Urgent"}):a==="high"?e.jsx(L,{children:"High"}):s?e.jsx(L,{variant:"outline",children:It(a)}):null}function Ft(t){const s=t.assignments||[];if(s.length>0){const a=s.find(d=>d.assignment_role==="lead"),r=s.filter(d=>d.assignment_role!=="lead").length;return`${a?.staff_name||s[0].staff_name}${r?` + ${r}`:""}`}return t.contractor_business_name?t.contractor_trade_category?`${t.contractor_business_name} - ${It(t.contractor_trade_category)}`:t.contractor_business_name:t.contractor_name?t.contractor_name:t.resident_arranging_own_contractor?"Resident arranging directly":null}function ye({label:t,value:s,wide:a}){return s==null||s===""?null:e.jsxs("div",{className:$("rounded-xl border border-border bg-card/80 p-3",a&&"sm:col-span-2"),children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("dd",{className:"mt-1 text-base font-medium text-foreground",children:s})]})}function Ui({request:t,slug:s,onOpenChange:a}){const{toast:r}=pe(),d=oe(),l=t?Ft(t):null,n=t?.property_label||t?.location||null,[g,c]=i.useState(""),[m,x]=i.useState(!1),[o,w]=i.useState(!1),[p,j]=i.useState(""),[C,T]=i.useState(!1),[v,u]=i.useState("Maintenance update"),[N,f]=i.useState(""),[S,_]=i.useState({}),[V,b]=i.useState(""),[M,A]=i.useState([]),[E,K]=i.useState("normal"),[G,H]=i.useState(""),[ge,D]=i.useState(""),[Z,X]=i.useState("The team is still assessing the work.");i.useEffect(()=>{c(""),x(!1),w(!1),j(""),T(!1),u("Maintenance update"),f(t?`There is an update on your maintenance request: ${t.issue_type||"maintenance"}.`:""),K(["urgent","high","normal","low"].includes(String(t?.priority||"").toLowerCase())?String(t?.priority).toLowerCase():"normal"),_({}),H(t?.expected_completion_date||""),D(t?.expected_timeframe||""),X(t?.completion_estimate_unavailable_reason||"The team is still assessing the work.")},[t]);const I=()=>d.invalidateQueries({queryKey:["reception-maintenance",s]}),J=B({queryKey:["reception-maintenance-detail",s,t?.id],queryFn:()=>Pn(s,t.id),enabled:!!t,staleTime:1e4}),Fe=B({queryKey:["reception-maintenance-assignees",s],queryFn:()=>En(s),enabled:!!t,staleTime:3e4}),Ue=J.data?.notes||[],Ne=J.data?.legacy_notes||[],Ce=J.data?.queries||[],He=J.data?.documents||[],$e=qi(J.data?.request?.photo_url??t?.photo_url),De=He.filter(h=>String(h.mime_type||"").startsWith("image/")||String(h.document_type||"").includes("photo")),re=xa(s),Ae=Ce.filter(h=>!h.answered_at),_e=()=>d.invalidateQueries({queryKey:["reception-maintenance-detail",s,t?.id]}),Le=J.data?.request?.assignments||t?.assignments||[];i.useEffect(()=>{const h=Le.find(ue=>ue.assignment_role==="lead");b(h?.staff_user_id||""),A(Le.filter(ue=>ue.assignment_role==="collaborator").map(ue=>ue.staff_user_id))},[t?.id,J.data?.request?.assignments]);const Se=z({mutationFn:({queryId:h,answer:ue})=>wn(s,h,ue),onSuccess:()=>{r({title:"Reply sent to resident"}),_e(),I()},onError:h=>r({title:"Couldn't send reply",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),fe=z({mutationFn:()=>js(s,t.id,g.trim(),m),onSuccess:()=>{r({title:m?"Resident-facing update added":"Reception note added"}),c(""),x(!1),I(),_e()},onError:h=>r({title:"Couldn't add note",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),we=z({mutationFn:()=>js(s,t.id,"Resident contacted / updated by reception.",!1),onSuccess:()=>{r({title:"Marked resident contacted"}),I()},onError:h=>r({title:"Couldn't update",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),je=z({mutationFn:h=>kn(s,{id:t.id,...h}),onSuccess:()=>{r({title:"Maintenance updated"}),I(),a(!1)},onError:h=>r({title:"Couldn't update",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),F=z({mutationFn:()=>_n(s,{request_id:t.id,lead_staff_user_id:V,collaborator_staff_user_ids:M}),onSuccess:()=>{r({title:"Maintenance team assigned"}),I(),_e()},onError:h=>r({title:"Couldn't save assignment",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),be=z({mutationFn:()=>Cn(s,t.id,E),onSuccess:()=>{r({title:"Maintenance priority updated"}),I(),_e()},onError:h=>r({title:"Couldn't update priority",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),ke=z({mutationFn:()=>Sn(s,{request_id:t.id,expected_completion_date:G||null,expected_timeframe:ge.trim()||null,completion_estimate_unavailable_reason:Z.trim()||null}),onSuccess:()=>{r({title:"Request acknowledged and resident notified"}),I(),_e()},onError:h=>r({title:"Couldn't acknowledge request",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),R=z({mutationFn:()=>Rn(s,{id:t.id,title:v.trim(),body:N.trim()}),onSuccess:()=>{r({title:"Update sent to resident"}),T(!1)},onError:h=>r({title:"Couldn't send update",description:h instanceof Error?h.message:"Please try again.",variant:"destructive"})}),le=!!(t?.scheduled_at||t?.scheduled_date),y=t?Jt({status:t.status,target_response_at:J.data?.request?.target_response_at||t.target_response_at,target_completion_at:J.data?.request?.target_completion_at||t.target_completion_at,acknowledged_at:J.data?.request?.acknowledged_at||t.acknowledged_at,
1sla_paused_at:J.data?.request?.sla_paused_at||t.sla_paused_at}).overall:"not_set";return e.jsx(ce,{open:!!t,onOpenChange:a,children:e.jsx(de,{className:"max-h-[92vh] max-w-3xl overflow-y-auto",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(xe,{className:"text-2xl",children:us(t.issue_type)}),e.jsx(kt,{children:"Reception coordinates the visit, team assignment, resident messages, and triage. Technical completion stays with the lead assignee or an authorised admin."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Pa(t.status),Ea(t.priority,!0),t.urgency_class==="emergency"&&e.jsx(L,{variant:"destructive",children:"Emergency"}),t.urgency_class==="urgent"&&e.jsx(L,{variant:"outline",children:"Urgent"}),t.request_origin==="preventive"&&e.jsx(L,{variant:"secondary",children:"Preventive"}),t.waiting_on_parts&&e.jsx(L,{variant:"outline",className:"border-[#ded6ca] bg-[#f1ece7] text-[#765f52]",children:"Waiting on parts"}),!!t.parts_summary?.waiting_lines&&e.jsxs(L,{variant:"outline",children:[t.parts_summary.waiting_lines," part line",t.parts_summary.waiting_lines===1?"":"s"," waiting"]}),!!t.parts_summary?.required_lines&&!t.parts_summary.waiting_lines&&e.jsx(L,{variant:"secondary",children:"Parts ready"}),y==="breached"&&e.jsx(L,{variant:"destructive",children:"SLA breached"}),y==="due_soon"&&e.jsx(L,{variant:"outline",children:"SLA due soon"}),(t.change_requests||0)>0&&e.jsxs(L,{variant:"secondary",children:[t.change_requests," change request",t.change_requests===1?"":"s"]})]}),e.jsxs("dl",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(ye,{label:"Resident",value:t.resident_name||"Unassigned"}),e.jsx(ye,{label:"Unit / property",value:n}),e.jsx(ye,{label:"Reference",value:J.data?.request?.reference||t.reference}),e.jsx(ye,{label:"Assigned team",value:Le.length?Le.map(h=>`${h.staff_name} (${h.assignment_role})`).join(", "):l||"Not assigned"}),e.jsx(ye,{label:"Submitted by",value:t.submitted_by_name||"Reception"}),e.jsx(ye,{label:"Raised",value:ie(t.created_at)}),e.jsx(ye,{label:"Received",value:ie(J.data?.request?.received_at||t.received_at||t.created_at)}),e.jsx(ye,{label:"Acknowledged",value:t.acknowledged_at?`${ie(t.acknowledged_at)}${t.acknowledged_by_name?` by ${t.acknowledged_by_name}`:""}`:"Not yet acknowledged"}),e.jsx(ye,{label:"Expected timeframe",value:t.expected_completion_date||t.expected_timeframe||t.completion_estimate_unavailable_reason||"Not yet provided"}),e.jsx(ye,{label:"Last updated",value:t.updated_at?ie(t.updated_at):null}),e.jsx(ye,{label:"Scheduled",value:t.scheduled_at?ie(t.scheduled_at):t.scheduled_date||null}),e.jsx(ye,{label:"Completed",value:t.completed_at?ie(t.completed_at):null}),e.jsx(ye,{label:"Entry consent",value:br(J.data?.request?.access_permission||t.access_permission)}),e.jsx(ye,{label:"Preferred time",value:J.data?.request?.preferred_visit_window||t.preferred_visit_window}),e.jsx(ye,{label:"Parts readiness",value:(()=>{const h=J.data?.request?.parts_summary||t.parts_summary;return h?.required_lines?h.waiting_lines?`${h.waiting_lines} of ${h.required_lines} part lines still waiting${h.expected_delivery_date?` · expected ${new Date(`${h.expected_delivery_date}T00:00:00`).toLocaleDateString("en-NZ",{weekday:"short",day:"numeric",month:"short",year:"numeric"})}`:""}`:"Required parts are ready":null})()}),e.jsx(ye,{label:"Access, pet or safety notes",value:J.data?.request?.access_notes||t.access_notes,wide:!0}),e.jsx(ye,{label:"Request details",value:t.notes,wide:!0}),e.jsx(ye,{label:"Resident update",value:t.admin_notes_public,wide:!0})]}),($e.length>0||De.length>0)&&e.jsxs("div",{className:"space-y-3 rounded-xl border bg-card/70 p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Request and job photos"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Private images attached by the resident or maintenance team."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3",children:[$e.map((h,ue)=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(ws,{src:h,authToken:re,alt:`Resident photo ${ue+1}`,className:"h-36 w-full rounded-xl border object-cover"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Resident photo"})]},`${h}-${ue}`)),De.map(h=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(ws,{src:h.storage_path,authToken:re,alt:h.title||"Job p
1hoto",className:"h-36 w-full rounded-xl border object-cover"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:h.title}),h.resident_visible&&e.jsx(L,{variant:"outline",className:"text-[10px]",children:"Resident visible"})]})]},h.id))]})]}),Ae.length>0&&e.jsxs("div",{className:"space-y-3 rounded-xl border border-[#d8b9ab] bg-[#f6e9e4]/60 p-4 dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-semibold text-[#8a5c4b] dark:text-slate-100",children:[e.jsx(ja,{className:"h-4 w-4"})," Resident asked for an update"]}),Ae.map(h=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"rounded-lg bg-white/80 p-3 dark:bg-slate-900",children:[h.request_type&&h.request_type!=="general"&&e.jsx(L,{variant:"outline",className:"mb-2 capitalize",children:h.request_type.replace(/_/g," ")}),e.jsx("p",{className:"text-sm text-slate-800 dark:text-slate-100",children:h.message}),e.jsxs("p",{className:"mt-0.5 text-xs text-slate-400",children:["Asked ",ie(h.created_at)]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ve,{rows:2,value:S[h.id]||"",onChange:ue=>_(Ye=>({...Ye,[h.id]:ue.target.value})),placeholder:"Write a reply the resident will see…",className:"flex-1 text-sm"}),e.jsx(k,{size:"sm",className:`self-end ${Y}`,disabled:!(S[h.id]||"").trim()||Se.isPending,onClick:()=>Se.mutate({queryId:h.id,answer:(S[h.id]||"").trim()}),children:Se.isPending?e.jsx(U,{className:"h-4 w-4 animate-spin"}):"Reply"})]})]},h.id))]}),e.jsxs("div",{className:"space-y-3 rounded-xl border border-[#e3e0d8] bg-[#f8f7f2]/70 p-4 dark:border-slate-800 dark:bg-slate-900/60",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-semibold text-slate-800 dark:text-slate-100",children:[e.jsx(et,{className:"h-4 w-4"})," Reception actions"]}),!t.acknowledged_at&&e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Acknowledge this request"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Expected completion date"}),e.jsx(O,{type:"date",value:G,onChange:h=>H(h.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Expected timeframe"}),e.jsx(O,{value:ge,onChange:h=>D(h.target.value),placeholder:"e.g. Within two weeks"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"If still assessing"}),e.jsx(O,{value:Z,onChange:h=>X(h.target.value)})]})]}),e.jsxs(k,{className:Y,disabled:ke.isPending,onClick:()=>ke.mutate(),children:[ke.isPending&&e.jsx(U,{className:"h-4 w-4 animate-spin"}),"Acknowledge and notify resident"]})]}),e.jsxs("div",{className:"grid gap-2 rounded-lg border border-border bg-card p-3 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Priority"}),e.jsxs(ee,{value:E,onValueChange:h=>K(h),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"urgent",children:"Urgent"}),e.jsx(q,{value:"high",children:"High"}),e.jsx(q,{value:"normal",children:"Normal"}),e.jsx(q,{value:"low",children:"Low"})]})]})]}),e.jsxs(k,{size:"sm",variant:"outline",className:Q,disabled:be.isPending||E===String(t.priority||"normal").toLowerCase(),onClick:()=>be.mutate(),children:[be.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"}),"Save priority"]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-card p-3",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[e.jsx(ze,{className:"h-4 w-4 text-primary"})," Assign maintenance team"]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Lead assignee"}),e.jsxs(ee,{value:V,onValueChange:h=>{b(h),A(ue=>ue.filter(Ye=>Ye!==h))},children:[e.jsx(te,{children:e.jsx(se,{placeholder:"Choose lead"})}),e.jsx(ae,{children:(Fe.data||[]).map(h=>e.jsxs(q,{value:h.id,children:[h.name||`${h.first_name||""} ${h.last_name||""}`.trim(),h.role_title?` · ${h.role_title}`:""]},h.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Collaborators"}),e.jsx("div",{className:"max-h-36 space-y-1 overflow-y-auto rounded-md border p-2",children:(Fe.data||[]).filter(h=>h.id!==V).map(h=>e.jsxs("label",{className:"flex min-h-9 items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:M.includes(h.id),onCheckedChange:ue=>A(Ye=>ue?[...Ye,h.id]:Ye.filter(La=>La!==h.id))}),h.name||`${h.first_name||""} ${h.last_name||""}`.trim()]}
1,h.id))})]})]}),e.jsxs(k,{size:"sm",variant:"outline",className:Q,disabled:!V||F.isPending,onClick:()=>F.mutate(),children:[F.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Save team assignment"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-recept-note",children:m?"Add a resident-facing update":"Add a reception note (internal)"}),e.jsx(ve,{id:"m-recept-note",value:g,onChange:h=>c(h.target.value),rows:2,placeholder:m?"What the resident will see, e.g. 'Plumber booked for Tuesday morning.'":"e.g. Resident called to ask about timing."}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[e.jsx(Re,{checked:m,onCheckedChange:h=>x(h===!0)}),"Visible to resident"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,disabled:we.isPending,onClick:()=>we.mutate(),children:[e.jsx(Je,{className:"h-4 w-4"})," Mark resident contacted"]}),e.jsxs(k,{size:"sm",variant:"outline",className:Q,disabled:!g.trim()||fe.isPending,onClick:()=>fe.mutate(),children:[fe.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," ",m?"Add update":"Add note"]})]})]})]}),e.jsxs("div",{className:"space-y-2 border-t border-[#e3e0d8] pt-3 dark:border-slate-800",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-slate-400",children:"Simple status update"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(k,{size:"sm",variant:"outline",className:Q,disabled:je.isPending,onClick:()=>je.mutate({status:"needs_triage"}),children:"Needs triage"}),e.jsx(k,{size:"sm",variant:"outline",className:Q,disabled:je.isPending,onClick:()=>je.mutate({status:"waiting_resident"}),children:"Waiting on resident"}),e.jsx(k,{size:"sm",variant:"outline",className:Q,disabled:je.isPending,onClick:()=>{le?je.mutate({status:"scheduled"}):w(h=>!h)},children:"Scheduled"})]}),o&&!le&&e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-sched",children:"Scheduled date / time"}),e.jsx(O,{id:"m-sched",type:"datetime-local",value:p,onChange:h=>j(h.target.value),className:"h-10"})]}),e.jsx(k,{size:"sm",className:Y,disabled:!p||je.isPending,onClick:()=>je.mutate({status:"scheduled",scheduled_at:new Date(p).toISOString()}),children:"Save scheduled"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Reception can coordinate and schedule. The lead staff member or an authorised admin confirms technical completion."})]}),(Ue.length>0||Ne.length>0||Ce.some(h=>h.answered_at))&&e.jsxs("div",{className:"space-y-2 border-t border-[#e3e0d8] pt-3 dark:border-slate-800",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-slate-400",children:"Notes & updates history"}),e.jsxs("div",{className:"max-h-56 space-y-2 overflow-y-auto pr-1",children:[Ue.map(h=>e.jsxs("div",{className:"rounded-lg bg-white/80 p-2.5 text-sm dark:bg-slate-900",children:[e.jsx("p",{className:"text-slate-800 dark:text-slate-100",children:h.note}),e.jsxs("p",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-slate-400",children:[e.jsx("span",{children:h.created_by||"Staff"}),e.jsxs("span",{children:["· ",ie(h.created_at)]}),h.is_visible_to_resident&&e.jsx(L,{variant:"outline",className:"px-1 py-0 text-[10px]",children:"Resident sees this"}),h.note_type==="query_reply"&&e.jsx(L,{variant:"outline",className:"px-1 py-0 text-[10px]",children:"Reply to resident"})]})]},h.id)),Ce.filter(h=>h.answered_at).map(h=>e.jsxs("div",{className:"rounded-lg bg-white/60 p-2.5 text-sm dark:bg-slate-900/60",children:[e.jsxs("p",{className:"text-slate-600 dark:text-slate-300",children:["Resident asked: ",h.message]}),e.jsxs("p",{className:"mt-0.5 text-xs text-slate-400",children:["Answered by ",h.answered_by||"staff"," · ",h.answered_at?ie(h.answered_at):""]})]},h.id)),Ne.map((h,ue)=>e.jsxs("div",{className:"rounded-lg bg-white/60 p-2.5 text-sm dark:bg-slate-900/60",children:[e.jsx("p",{className:"text-slate-600 dar
1k:text-slate-300",children:h.note}),e.jsxs("p",{className:"mt-0.5 text-xs text-slate-400",children:[h.by||"Reception",h.at?` · ${ie(h.at)}`:""]})]},`legacy-${ue}`))]})]}),t.resident_profile_id&&e.jsx("div",{className:"space-y-2 border-t border-[#e3e0d8] pt-3 dark:border-slate-800",children:C?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-notify-title",children:"Title"}),e.jsx(O,{id:"m-notify-title",value:v,onChange:h=>u(h.target.value),className:"h-10"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-notify-body",children:"Message to resident"}),e.jsx(ve,{id:"m-notify-body",value:N,onChange:h=>f(h.target.value),rows:2})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(k,{size:"sm",variant:"ghost",onClick:()=>T(!1),children:"Cancel"}),e.jsxs(k,{size:"sm",className:Y,disabled:!v.trim()||!N.trim()||R.isPending,onClick:()=>R.mutate(),children:[R.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Send update"]})]})]}):e.jsxs(k,{size:"sm",className:`gap-1.5 ${Y}`,onClick:()=>T(!0),children:[e.jsx(Me,{className:"h-4 w-4"})," Send update to resident"]})})]})]}),e.jsx(he,{children:e.jsx(k,{variant:"outline",className:Q,onClick:()=>a(!1),children:"Close"})})]})})})}function Ki(t,s){return s?[t.issue_type,t.location,t.resident_name,t.property_label,t.notes,t.submitted_by_name,t.contractor_business_name,t.contractor_name,t.admin_notes_public].some(a=>String(a||"").toLowerCase().includes(s)):!0}const zi=[{value:"updated",label:"Last updated"},{value:"created",label:"Date created"},{value:"priority",label:"Priority"},{value:"status",label:"Status"},{value:"resident",label:"Resident"},{value:"unit",label:"Unit / property"},{value:"assigned",label:"Assigned to"}],Bi={urgent:4,high:3,normal:2,low:1};function Qi(t,s){const a=[...t],r=l=>l?new Date(l).getTime():0,d=l=>Bi[String(l||"normal").toLowerCase()]||2;switch(s){case"created":a.sort((l,n)=>r(n.created_at)-r(l.created_at));break;case"priority":a.sort((l,n)=>d(n.priority)-d(l.priority));break;case"status":a.sort((l,n)=>Ge(l.status).localeCompare(Ge(n.status)));break;case"resident":a.sort((l,n)=>String(l.resident_name||"~").localeCompare(String(n.resident_name||"~")));break;case"unit":a.sort((l,n)=>String(l.property_label||l.location||"~").localeCompare(String(n.property_label||n.location||"~")));break;case"assigned":a.sort((l,n)=>String(Ft(l)||"~").localeCompare(String(Ft(n)||"~")));break;default:a.sort((l,n)=>r(n.updated_at||n.created_at)-r(l.updated_at||l.created_at));break}return a.sort((l,n)=>{const g=c=>c.urgency_class==="emergency"?3:!c.acknowledged_at&&c.target_response_at&&r(c.target_response_at)<Date.now()?2:c.urgency_class==="urgent"?1:0;return g(n)-g(l)}),a}const Bt=12;function Wi({slug:t,mode:s="card",initialRequestId:a,onDetailClose:r}){const{toast:d}=pe(),l=oe(),[n,g]=i.useState(!1),[c,m]=i.useState(null),x=i.useRef(null),[o,w]=i.useState(""),[p,j]=i.useState("open"),[C,T]=i.useState("updated"),[v,u]=i.useState(Bt),[N,f]=i.useState(null),[S,_]=i.useState("General"),[V,b]=i.useState(""),[M,A]=i.useState("normal"),[E,K]=i.useState("routine"),[G,H]=i.useState(""),[ge,D]=i.useState("not_applicable"),[Z,X]=i.useState(""),[I,J]=i.useState(""),[Fe,Ue]=i.useState("list"),Ne=s==="page",{data:Ce,isLoading:He,isError:$e,error:De}=B({queryKey:["reception-maintenance",t],queryFn:()=>aa(t),staleTime:15e3,retry:1}),re=Ce||[];i.useEffect(()=>{if(!a){x.current=null;return}if(x.current===a)return;const R=re.find(le=>le.id===a);R&&(x.current=a,m(R))},[a,re]);const Ae=De?.status,_e=Ae===403,Le=Ae===503,Se=i.useMemo(()=>re.filter(R=>!Ct.has(Ge(R.status))).length,[re]),fe=i.useMemo(()=>{const R=new Intl.DateTimeFormat("en-CA",{timeZone:"Pacific/Auckland"}).format(new Date),le=re.filter(y=>!Ct.has(Ge(y.status)));return{newUnassigned:le.filter(y=>Ge(y.status)==="needs_triage"&&!(y.assignments||[]).length&&!y.contractor_id).length,questions:le.reduce((y,h)=>y+Number(h.unanswered_queries||0),0),changes:le.reduce((y,h)=>y+Number(h.change_requests||0),0),visitsToday:le.filter(y=>y.scheduled_date===R).length,slaBreaches:le.filter(y=>
1Jt(y).overall==="breached").length,emergencies:le.filter(y=>y.urgency_class==="emergency").length,partsWaiting:le.filter(y=>Number(y.parts_summary?.waiting_lines||0)>0).length}},[re]),we=i.useMemo(()=>{const R=o.trim().toLowerCase(),le=re.filter(y=>{const h=Ge(y.status);return(p==="all"?!0:p==="open"?!Ct.has(h):p==="resolved"?Ct.has(h):h===p)&&Ki(y,R)});return Qi(le,C)},[re,o,p,C]),je=Ne?we.slice(0,v):re.slice(0,8);i.useEffect(()=>{u(Bt)},[o,p,C,Fe]);const F=R=>{f(R),R?.unit_room&&!V.trim()&&b(R.unit_room)},be=()=>{f(null),_("General"),b(""),A("normal"),K("routine"),H(""),D("not_applicable"),X(""),J("")},ke=z({mutationFn:()=>Xs(t,{resident_id:N?.id??null,issue_type:S,location:V.trim()||null,priority:M,urgency_class:E,notes:G.trim()||null,access_permission:ge,preferred_visit_window:Z.trim()||null,access_notes:I.trim()||null}),onSuccess:()=>{d({title:"Maintenance request raised"}),g(!1),be(),l.invalidateQueries({queryKey:["reception-maintenance",t]}),l.invalidateQueries({queryKey:["reception-overview",t]})},onError:R=>d({title:"Couldn't raise request",description:R instanceof Error?R.message:"Please try again.",variant:"destructive"})});return e.jsxs(e.Fragment,{children:[e.jsxs(tt,{className:W,children:[e.jsx(gt,{icon:Ee,title:"Maintenance",meta:Se>0&&e.jsxs(L,{variant:"secondary",className:"bg-primary/10 text-primary",children:[Se," open"]}),action:e.jsxs(ce,{open:n,onOpenChange:g,children:[e.jsx(Dt,{asChild:!0,children:e.jsxs(k,{size:"sm",className:`gap-1.5 ${Y}`,children:[e.jsx(nt,{className:"h-4 w-4"})," Raise request"]})}),e.jsxs(de,{children:[e.jsx(me,{children:e.jsx(xe,{children:"Raise a maintenance request"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"For resident"}),e.jsx(Te,{slug:t,value:N,onChange:F,optional:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Issue type"}),e.jsxs(ee,{value:S,onValueChange:_,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsx(ae,{children:Ii.map(R=>e.jsx(q,{value:R,children:R},R))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Priority"}),e.jsxs(ee,{value:M,onValueChange:A,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"low",children:"Low"}),e.jsx(q,{value:"normal",children:"Normal"}),e.jsx(q,{value:"high",children:"High"}),e.jsx(q,{value:"urgent",children:"Urgent"})]})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Urgency"}),e.jsxs(ee,{value:E,onValueChange:R=>K(R),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"routine",children:"Routine"}),e.jsx(q,{value:"urgent",children:"Urgent"}),e.jsx(q,{value:"emergency",children:"Emergency"})]})]}),E==="emergency"&&e.jsx("p",{className:"text-sm text-destructive",children:"Use the village emergency process for immediate threats; do not rely only on this request."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-loc",children:"Location"}),e.jsx(O,{id:"m-loc",value:V,onChange:R=>b(R.target.value),placeholder:"Unit / area"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-notes",children:"Details"}),e.jsx(ve,{id:"m-notes",value:G,onChange:R=>H(R.target.value),rows:3,placeholder:"Describe the problem..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Entry consent"}),e.jsxs(ee,{value:ge,onValueChange:R=>D(R),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"not_applicable",children:"Not applicable"}),e.jsx(q,{value:"contact_first",children:"Contact resident first"}),e.jsx(q,{value:"resident_present",children:"Resident will be present"}),e.jsx(q,{value:"permission_if_away",children:"May enter if resident is away"}),e.jsx(q,{value:"staff_escort",children:"Staff escort required"}),e.jsx(q,{value:"emergency_only",children:"Emergency access only"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-preferred-time",children:"Preferred visit time"}),e.jsx(O,{id:"m-preferred-time",value:Z,onChange:R=>X(R.target.value),placeholder:"Optional"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"m-access-notes",children:"Access, pet, or safety notes"}),e.jsx(ve,{id:"m-access-notes",value:I,onChange:R=>J(R.target.value),rows:2}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Do not record door, alarm, lockbox, or other security codes."})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>g(!1),children:"Cancel"}),e.jsxs(k,{className:Y,onClick:()=>ke.mutate(),disabled:ke.isPending||!G.trim(),children:[ke.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Raise request"]})]})]})]})}),e.jsxs(st,{children:[Ne&&e.jsx("div",{className:"mb-4 grid grid-cols-2 gap-px overflow-hidden rounded-xl border border-border bg-border sm:grid-cols-3 2xl:grid-cols-4",children:[["New / unassigned",fe.newUnassigned],["Emergencie
1s",fe.emergencies],["Resident questions",fe.questions],["Change requests",fe.changes],["Visits today",fe.visitsToday],["SLA breaches",fe.slaBreaches],["Parts waiting",fe.partsWaiting]].map(([R,le])=>e.jsxs("div",{className:"min-w-0 bg-[var(--reception-surface)] px-3 py-3",children:[e.jsx("span",{className:$("block text-base font-bold tabular-nums",Number(le)>0?"text-primary":"text-foreground"),children:le}),e.jsx("span",{className:"block text-xs font-medium leading-snug text-foreground",children:R})]},String(R)))}),Ne&&e.jsxs("div",{className:"mb-5 grid grid-cols-1 gap-3 lg:grid-cols-2 2xl:grid-cols-[auto_minmax(0,1fr)_minmax(180px,220px)_minmax(180px,220px)]",children:[e.jsxs("div",{className:"inline-flex rounded-xl border bg-muted/30 p-1",children:[e.jsxs(k,{size:"sm",variant:Fe==="list"?"default":"ghost",onClick:()=>Ue("list"),children:[e.jsx(vr,{className:"h-4 w-4"})," List"]}),e.jsxs(k,{size:"sm",variant:Fe==="week"?"default":"ghost",onClick:()=>Ue("week"),children:[e.jsx(Gt,{className:"h-4 w-4"})," Week"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(O,{value:o,onChange:R=>w(R.target.value),"data-update-transient":"true",placeholder:"Search request, resident, unit, contractor, notes...",className:"h-12 pl-10 text-base"})]}),e.jsxs(ee,{value:p,onValueChange:j,children:[e.jsx(te,{className:"h-12 text-base",children:e.jsx(se,{})}),e.jsx(ae,{children:Vi.map(R=>e.jsx(q,{value:R.value,children:R.label},R.value))})]}),e.jsxs(ee,{value:C,onValueChange:R=>T(R),children:[e.jsx(te,{className:"h-12 text-base",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(yr,{className:"h-4 w-4 text-muted-foreground"})," ",e.jsx(se,{})]})}),e.jsx(ae,{children:zi.map(R=>e.jsxs(q,{value:R.value,children:["Sort: ",R.label]},R.value))})]})]}),He?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):_e?e.jsxs("div",{className:"rounded-xl border border-dashed border-[#d8b9ab] bg-[#f6e9e4]/60 px-4 py-8 text-center dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsx(dt,{className:"mx-auto mb-2 h-7 w-7 text-[#8a5c4b]"}),e.jsx("p",{className:"text-sm font-semibold text-[#8a5c4b]",children:"You don't have permission to view maintenance requests"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Ask your village admin to enable the Maintenance tool for your reception account."})]}):Le?e.jsxs("div",{className:"rounded-xl border border-dashed border-[#ded6ca] bg-[#f1ece7]/60 px-4 py-8 text-center dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsx(dt,{className:"mx-auto mb-2 h-7 w-7 text-[#765f52]"}),e.jsx("p",{className:"text-sm font-semibold text-[#765f52]",children:"Maintenance isn't set up for this village yet"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Once the maintenance workflow is configured, resident requests will appear here."})]}):$e?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load maintenance requests. Please try again shortly."}):Fe==="week"&&Ne?e.jsx(Hi,{requests:re,onOpen:m}):je.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:re.length===0?"No maintenance requests to show.":"No maintenance requests match this view."}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"space-y-3",children:je.map(R=>{const le=Ft(R),y=R.property_label||R.location,h=Jt(R).overall;return e.jsx("li",{className:"reception-workspace-row rounded-[16px] p-4 md:p-5",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-[auto_minmax(0,1fr)_auto] md:items-start",children:[e.jsx("span",{className:$("reception-icon-tile",R.urgency_class==="emergency"||h==="breached"?"reception-icon-tile--overdue":R.acknowledged_at?"reception-icon-tile--info":"reception-icon-tile--waiting"),children:e.jsx(Ee,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-[18px] font-semibold text-foreground",children:us(R.issue_type)}),Ea(R.priority),R.urgency_class==="emergency"&&e.jsx(L,{variant:"destructive",children:"Emergency"}),R.urgency_class==="urgent"&&e.jsx(L,{variant:"outline",children:"Urgent"}),!R.acknowledged_at&&e.jsxs(L,{variant:"secondary",children:["Unacknowledged",Vs(R.created_at)>0?` · ${Vs(R.created_at)} days`:""]}),R.request_origin==="preventive"&&e.jsx(L,{variant:"secondary",children:"Preventive"}),(R.unanswered_queries||0)>0&&e.jsxs(L,{variant:"outline",className:"gap-1 border-[#d8b9ab] bg-[#f6e9e4] text-[#8a5c4b] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:[e.jsx(ja,{className:"h-3.5 w-3.5"})," Resident asked for an update"]}),(R.change_requests||0)>0&&e.jsxs(L,{variant:"secondary",children:[R.change_requests," resident change request",R.change_requests===1?"":"s"]}),h==="breached"&&e.jsx(L,{variant:"destructive",children:"SLA breached"}),h==="due_soon"&&e.jsx(L,{variant:"outline",children:"SLA due soon"})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm text-muted-foreground",children:[y&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3.5 w-3.5"})," ",y]}),R.resident_name&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(pt,{className:"h-3.5 w-3.5"})," ",R.resident_name]}),le&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Mr,{className:"h-3.5 w-3.5"})," ",le]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ve,{className:"h-3.5 w-3.5"})," Updated ",ie(R.updated_at||R.created_at)]})]}),R.notes&&e.jsx("p",{className:"mt-3 rounded-xl bg-[var(--reception-surface)] px-3 py-2 text-[14px] leading-relaxed text-[var(--reception-label-2)]",children:R.notes}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[R.reference&&e.jsx("span",{children:R.reference}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Gt,{className:"h-3.5 w-3.5"})," Raised ",ie(R.created_at)]}),R.submitted_by_name&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(bt,{className:"h-3.5 w-3.5"})," ",R.submitted_by_name]}),R.property_label&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Wt,{className:"h-3.5 w-3.5"})," ",R.property_label]})]})]}),e.jsx("div",{className:"col-span-full flex justify-end md:col-span-1 md:justify-self-end",children:Pa(R.status)}),e.jsx("div",{className:"col-span-full flex flex-col items-center gap-2 border-t border-[var(--reception-hairline)] pt-4 text-center",children:e.jsxs(k,{size:"sm",variant:"outline",className:`min-w-[180px] gap-1.5 ${Q}`,onClick:()=>m(R),children:[e.jsx(ms,{className:"h-4 w-4"})," ",R.acknowledged_at?"View details":"Acknowledge"]})})]})},R.id)})}),Ne&&je.length<we.length&&e.jsx("div",{className:"flex justify-center border-t border-[var(--reception-line)] pt-4",children:e.jsx(k,{variant:"outline",className:`min-h-11 min-w-[180px] ${Q}`,onClick:()=>u(R=>R+Bt),children:"Load more maintenance"})})]})]})]}),e.jsx(Ui,{request:c,slug:t,onOpenChange:R=>{R||(m(null),r?.())}})]})}function Hi({requests:t,onOpen:s}){const a=new Date,r=a.getDay();a.setDate(a.getDate()+(r===0?-6:1-r)),a.setHours(0,0,0,0);const d=Array.from({length:7},(l,n)=>{const g=new Date(a);g.setDate(a.getDate()+n);const c=`${g.getFullYear()}
1-${String(g.getMonth()+1).padStart(2,"0")}-${String(g.getDate()).padStart(2,"0")}`;return{date:g,key:c,jobs:t.filter(m=>m.scheduled_date===c||Yi(m.scheduled_at)===c)}});return e.jsx("div",{className:"grid gap-3 md:grid-cols-7",children:d.map(l=>e.jsxs("div",{className:"min-h-40 rounded-xl border bg-card/70 p-2",children:[e.jsx("p",{className:"mb-2 text-sm font-semibold text-foreground",children:l.date.toLocaleDateString("en-NZ",{weekday:"short",day:"numeric"})}),e.jsx("div",{className:"space-y-2",children:l.jobs.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No jobs"}):l.jobs.map(n=>e.jsxs("button",{type:"button",onClick:()=>s(n),className:"w-full rounded-lg border bg-background/80 p-2 text-left transition-colors hover:border-primary/40",children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:us(n.issue_type)}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[String(n.time_slot_start||"").slice(0,5)||Gi(n.scheduled_at),n.property_label?` · ${n.property_label}`:""]})]},n.id))})]},l.key))})}function Yi(t){if(!t)return"";const s=new Date(t);return Number.isNaN(s.getTime())?"":`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`}function Gi(t){if(!t)return"";const s=new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleTimeString("en-NZ",{hour:"2-digit",minute:"2-digit"})}function Zi({slug:t,enabled:s,detailId:a,clearDetail:r}){const d=s.has("maintenance_request");return e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:Ee,title:"Maintenance",description:"View and track shared requests from the village maintenance workflow."}),d?e.jsx(Wi,{slug:t,mode:"page",initialRequestId:a,onDetailClose:r}):e.jsx(ht,{icon:Ee,title:"Maintenance isn't enabled",message:"Ask your village admin to enable Maintenance Request under Reception Tools."})]})}const Ji={new:"New",acknowledged:"Acknowledged",planned:"Planned",in_progress:"In progress",waiting_on_resident:"Waiting on resident",done:"Resolved",archived:"Closed",under_review:"Acknowledged",actioned:"Resolved",closed:"Closed"},qs={new:"bg-[#f6e9e4] text-[#8a5c4b] dark:bg-slate-800 dark:text-slate-200",acknowledged:"bg-[#eef1ea] text-[#5f6e58] dark:bg-slate-800 dark:text-slate-200",planned:"bg-[#eceef4] text-[#5c6784] dark:bg-slate-800 dark:text-slate-200",in_progress:"bg-[#f1ece7] text-[#765f52] dark:bg-slate-800 dark:text-slate-200",waiting_on_resident:"bg-[#f1ece7] text-[#765f52] dark:bg-slate-800 dark:text-slate-200",done:"bg-[#e8f0e6] text-[#4f6a4c] dark:bg-slate-800 dark:text-slate-200",archived:"bg-slate-100 text-slate-500 dark:bg-slate-800 dark:text-slate-300"},Ta={activities:"Activities",dining:"Dining",facilities:"Village Facilities",services:"Services",general:"General Feedback",concern:"Concern",complaint:"Concern"};function Fa(t){const s=t||"new";return e.jsx(L,{className:$("border-transparent",qs[s]||qs.acknowledged),children:Ji[s]||s.replace(/_/g," ")})}function $a(t){return t.is_anonymous?{name:"Anonymous",anonymous:!0}:{name:t.submitted_by_name||"Resident",anonymous:!1}}const Us=new Set(["done","actioned","closed","archived"]);function Xi({suggestion:t,slug:s,onOpenChange:a}){const{toast:r}=pe(),d=oe(),[l,n]=i.useState(""),g=B({queryKey:["reception-suggestion-notes",s,t?.id],queryFn:()=>$n(s,t.id),enabled:!!t,staleTime:1e4}),c=g.data||[],m=()=>{d.invalidateQueries({queryKey:["reception-suggestions",s]}),d.invalidateQueries({queryKey:["reception-suggestion-notes",s,t?.id]})},x=z({mutationFn:()=>Tn(s,t.id),onSuccess:()=>{r({title:"Suggestion acknowledged"}),m()},onError:p=>r({title:"Couldn't acknowledge",description:p instanceof Error?p.message:"Please try again.",variant:"destructive"})}),o=z({mutationFn:()=>Fn(s,t.id,l.trim()),onSuccess:()=>{r({title:"Note added for the village team"}),n(""),m()},onError:p=>r({title:"Couldn't add note",description:p instanceof Error?p.message:"Please try again.",variant:"destructive"})}),w=t?$a(t):{name:"",anonymous:!1};return e.jsx(ce,{open:!!t,onOpenChange:a,children:e.jsx(de,{className:"max-h-[92vh] max-w-2xl overflow-y-auto",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(xe,{className:"text-2xl",children:"Resident suggestion"}),e.jsx(kt,{children:"Reception can acknowledge new suggestions and add internal notes. Replies, planning, and resolution stay with the village admin."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Fa(t.status),t.category&&e.jsx(L,{variant:"outline",className:"border-[#dcd8cf] bg-white/80 text-slate-600 dar
1k:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:Ta[t.category]||t.category}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-sm text-muted-foreground",children:[w.anonymous?e.jsx(ba,{className:"h-3.5 w-3.5"}):e.jsx(pt,{className:"h-3.5 w-3.5"}),w.name]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["· ",ie(t.created_at)]})]}),e.jsx("div",{className:"rounded-xl border border-[#e3e0d8] bg-white/80 p-4 dark:border-slate-800 dark:bg-slate-900",children:e.jsx("p",{className:"whitespace-pre-wrap text-base text-slate-800 dark:text-slate-100",children:t.message})}),t.admin_response&&e.jsxs("div",{className:"rounded-xl border border-[#dfe5d9] bg-[#eef1ea]/70 p-4 dark:border-slate-800 dark:bg-slate-900/60",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-[#5f6e58] dark:text-slate-300",children:"Reply from management (resident sees this)"}),e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-sm text-slate-800 dark:text-slate-100",children:t.admin_response})]}),t.status==="new"&&e.jsxs(k,{className:`gap-1.5 ${Y}`,disabled:x.isPending,onClick:()=>x.mutate(),children:[x.isPending?e.jsx(U,{className:"h-4 w-4 animate-spin"}):e.jsx(ms,{className:"h-4 w-4"}),"Acknowledge suggestion"]}),e.jsxs("div",{className:"space-y-2 rounded-xl border border-[#e3e0d8] bg-[#f8f7f2]/70 p-4 dark:border-slate-800 dark:bg-slate-900/60",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-semibold text-slate-800 dark:text-slate-100",children:[e.jsx(et,{className:"h-4 w-4"})," Internal notes (shared with the village team)"]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sugg-note",children:"Add a note"}),e.jsx(ve,{id:"sugg-note",rows:2,value:l,onChange:p=>n(p.target.value),placeholder:"e.g. Resident mentioned this again at the front desk today."}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(k,{size:"sm",variant:"outline",className:Q,disabled:!l.trim()||o.isPending,onClick:()=>o.mutate(),children:[o.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," Add note"]})})]}),g.isLoading?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading notes…"}):c.length>0?e.jsx("div",{className:"max-h-48 space-y-2 overflow-y-auto pr-1",children:c.map(p=>e.jsxs("div",{className:"rounded-lg bg-white/80 p-2.5 text-sm dark:bg-slate-900",children:[e.jsx("p",{className:"text-slate-800 dark:text-slate-100",children:p.body}),e.jsxs("p",{className:"mt-0.5 text-xs text-slate-400",children:[p.actor_name||(p.actor_role==="reception"?"Reception":"Staff")," · ",ie(p.created_at)]})]},p.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No internal notes yet."})]})]}),e.jsx(he,{children:e.jsx(k,{variant:"outline",className:Q,onClick:()=>a(!1),children:"Close"})})]})})})}function el({slug:t}){const[s,a]=i.useState(""),[r,d]=i.useState("open"),[l,n]=i.useState(null),{data:g,isLoading:c,isError:m,error:x}=B({queryKey:["reception-suggestions",t],queryFn:()=>Dn(t),staleTime:15e3,retry:1}),o=g||[],w=x?.status,p=w===403,j=w===503,C=i.useMemo(()=>o.filter(v=>(v.status||"new")==="new").length,[o]),T=i.useMemo(()=>{const v=s.trim().toLowerCase();return o.filter(u=>{const N=u.status||"new";return(r==="all"?!0:r==="open"?!Us.has(N):r==="new"?N==="new":Us.has(N))?v?[u.message,u.category,u.submitted_by_name,u.admin_response].some(S=>String(S||"").toLowerCase().includes(v)):!0:!1})},[o,s,r]);return e.jsxs(e.Fragment,{children:[e.jsxs(tt,{className:W,children:[e.jsx(gt,{icon:Ie,title:"Resident Suggestions",meta:C>0&&e.jsxs(L,{variant:"secondary",className:"bg-[#f6e9e4] text-[#8a5c4b]",children:[C," new"]})}),e.jsxs(st,{children:[e.jsxs("div",{className:"mb-5 grid grid-cols-1 gap-3 lg:grid-cols-[1fr_220px]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx(O,{value:s,onChange:v=>a(v.target.value),"data-update-transient":"true",placeholder:"Search suggestions…",className:"h-12 pl-10 text-base"})]}),e.jsxs(ee,{value:r,onValueChange:v=>d(v),children:[e.jsx(te,{className:"h-12 text-base",children:e.jsx(se,{})}),e.jsxs(ae,{children:[e.jsx(q,{value:"open",children:"Open suggestions"}),e.jsx(q,{value:"new",children:"New only"}),e.jsx(q,{value:"resolved",children:"Resolved / closed"}),e.jsx(q,{value:"all",children:"All suggestions"})]})]})]}),c?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading…"]}):p?e.jsxs("div",{className:"rounded-xl border border-dashed border-[#d8b9ab] bg-[#f6e9e4]/60 px-4 py-8 text-center dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsx(dt,{className:"mx-auto mb-2 h-7 w-7 text-[#8a5c4b]"}),e.jsx("p",{className:"text-sm font-semibold text-[#8a5c4b]",children:"You don't have permission to view suggestions"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Ask your village admin to enable the Resident Suggestions tool for your reception account."})]}
1):j?e.jsxs("div",{className:"rounded-xl border border-dashed border-[#ded6ca] bg-[#f1ece7]/60 px-4 py-8 text-center dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsx(dt,{className:"mx-auto mb-2 h-7 w-7 text-[#765f52]"}),e.jsx("p",{className:"text-sm font-semibold text-[#765f52]",children:"Suggestions aren't set up for this village yet"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Once residents start sharing feedback, their suggestions will appear here."})]}):m?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load suggestions. Please try again shortly."}):T.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:o.length===0?"No resident suggestions yet.":"No suggestions match this view."}):e.jsx("ul",{className:"space-y-3",children:T.map(v=>{const u=$a(v),N=v.status||"new";return e.jsx("li",{className:"reception-workspace-row rounded-[16px] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-base text-slate-800 dark:text-slate-100 line-clamp-2",children:v.message}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[u.anonymous?e.jsx(ba,{className:"h-3.5 w-3.5"}):e.jsx(pt,{className:"h-3.5 w-3.5"}),u.name]}),v.category&&e.jsx("span",{children:Ta[v.category]||v.category}),e.jsx("span",{children:ie(v.created_at)}),v.admin_response&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[#4f6a4c] dark:text-slate-300",children:[e.jsx(Nr,{className:"h-3.5 w-3.5"})," Replied"]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[Fa(N),e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,onClick:()=>n(v),children:[e.jsx(ms,{className:"h-4 w-4"})," View"]})]})]})},v.id)})})]})]}),e.jsx(Xi,{suggestion:l,slug:t,onOpenChange:v=>{v||n(null)}})]})}function tl({slug:t,enabled:s}){const a=s.has("suggestions");return e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:Ie,title:"Resident Suggestions",description:"Review resident ideas, acknowledge new items, and add notes for the village team."}),a?e.jsx(el,{slug:t}):e.jsx(ht,{icon:Ie,title:"Suggestions isn't enabled",message:"Ask your village admin to enable Resident Suggestions under Reception Tools."})]})}const sl=[{value:"open",label:"Open"},{value:"done",label:"Done"},{value:"archived",label:"Archived"}];function al({slug:t,note:s,open:a,onOpenChange:r}){const{toast:d}=pe(),l=oe(),[n,g]=i.useState(""),[c,m]=i.useState("General"),[x,o]=i.useState("Normal"),[w,p]=i.useState(!1),[j,C]=i.useState("open"),[T,v]=i.useState(null);i.useEffect(()=>{!a||!s||(g(s.body||""),m(s.category||"General"),o(rs(s.priority)),p(!!s.follow_up_required),C(["open","done","archived"].includes(String(s.status))?s.status:"open"),v(s.resident_id?{id:s.resident_id,display_name:"Linked resident"}:null))},[a,s]);const u=z({mutationFn:()=>An(t,s.id,{body:n.trim(),category:c,priority:x.toLowerCase(),follow_up_required:w,status:j,resident_id:T?.id??null}),onSuccess:()=>{d({title:"Note updated"}),l.invalidateQueries({queryKey:["reception-notes",t]}),r(!1)},onError:N=>d({title:"Couldn't save note",description:N instanceof Error?N.message:"Please try again.",variant:"destructive"})});return e.jsx(ce,{open:a,onOpenChange:r,children:e.jsxs(de,{className:"max-h-[92vh] overflow-y-auto",children:[e.jsx(me,{children:e.jsx(xe,{children:"Edit note / follow-up"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"en-body",children:"Note"}),e.jsx(ve,{id:"en-body",value:n,onChange:N=>g(N.target.value),rows:4,className:"text-base"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Category"}),e.jsxs(ee,{value:c,onValueChange:m,children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:Zs.map(N=>e.jsx(q,{value:N,children:N},N))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Priority"}),e.jsxs(ee,{value:x,onValueChange:N=>o(N),children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:Js.map(N=>e.jsx(q,{value:N,children:N},N))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Follow-up status"}),e.jsxs(ee,{value:j,onValueChange:N=>C(N),children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:sl.map(N=>e.jsx(q,{value:N.value,children:N.label},N.value))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Linked resident"}),e.jsx(Te,{slug:t,value:T,onChange:v,optional:!0})]})]}),e.jsxs("label",{className:"flex items-center gap-2.5 text-sm text-foreground",children:[e.jsx(Re,{checked:w,onCheckedChange:N=>p(N===!0)}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(yt,{className:"h-4 w-4 text-muted-foreground"})," Follow-up required"]})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsxs(k,{className:`gap-1.5 ${Y}`,disabled:!n.trim()||u.isPending,onClick:()=>u.mutate(),children:[u.isPending?e.jsx(U,{className:"h-4 w-4 animate-spin"}):e.jsx(os,{className:"h-4 w-4"})," Save changes"]})]})]})})}function nl({items:t,value:s,onValueChange:a,label:r,roomy:d=!1,className:l}){const n=Math.max(0,t.findIndex(c=>c.value===s)),g={"--reception-segment-count":t.length,"--reception-segment-index":n};return e.jsx("div",{"data-reception-segments":!0,role:"tablist","aria-label":r,className:$("relative grid overflow-hidden rounded-xl border border-primary/15 bg-primary/10 p-1 shadow-[0_6px_18px_rgba(37,99,235,0.06)]",d&&"rounded-2xl",l),style:{...g,gridTemplateColumns:`repeat(${t.length}, minmax(0, 1fr))`},children:t.map(c=>{const m=c.icon,x=c.value===s;return e.jsxs("button",{type:"button",role:"tab","aria-selected":x,onClick:()=>
1a(c.value),className:$("relative z-10 flex min-w-0 items-center justify-center gap-2 rounded-lg px-3 py-2.5 text-sm font-semibold transition-colors duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",d&&"min-h-16 justify-start px-4 text-left",x?"text-white":"text-primary hover:bg-card/50 hover:text-foreground"),children:[e.jsx(m,{className:$("h-4 w-4 shrink-0 transition-colors",x?"text-white":"text-primary/70")}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:c.label}),c.description&&e.jsx("span",{className:$("mt-0.5 hidden truncate text-xs font-normal md:block",x?"text-white/75":"text-muted-foreground"),children:c.description})]})]},c.value)})})}const rl={Normal:"border-border bg-muted text-muted-foreground",Important:"border-secondary/30 bg-secondary/10 text-secondary",Urgent:"border-destructive/30 bg-destructive/10 text-destructive"};function il(t){return t==="urgent"?e.jsx(L,{variant:"outline",className:"border-destructive/30 bg-destructive/10 text-destructive",children:"Urgent"}):t==="important"?e.jsx(L,{variant:"outline",className:"border-secondary/30 bg-secondary/10 text-secondary",children:"Important"}):e.jsx(L,{variant:"secondary",children:"Normal"})}function ll(t){return t==="delivered"?e.jsx(L,{variant:"outline",className:"border-primary/30 bg-primary/10 text-primary",children:"Done"}):t==="closed"?e.jsx(L,{variant:"secondary",children:"Archived"}):e.jsx(L,{variant:"outline",className:"border-border bg-muted text-muted-foreground",children:"Open"})}function ss({children:t,tone:s="default"}){const a=s==="callback"?"border-[#ded6ca] bg-[#f1ece7] text-[#765f52] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200":s==="note"?"border-[#cdd6c6] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200":"border-[#dcd8cf] bg-[#f8f7f2] text-slate-600 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300";return e.jsx("span",{className:$("inline-flex w-fit max-w-full items-center gap-1 rounded-full border px-2.5 py-0.5 text-xs font-medium",a),children:t})}function ol({slug:t}){const{toast:s}=pe(),a=oe(),[r,d]=i.useState("open"),[l,n]=i.useState(""),[g,c]=i.useState(null),[m,x]=i.useState(!1),[o,w]=i.useState(null),[p,j]=i.useState(new Set),{data:C,isLoading:T,isError:v}=B({queryKey:["reception-phone-messages",t],queryFn:()=>Mn(t),staleTime:15e3}),u=i.useMemo(()=>C||[],[C]),N=b=>b.status==="open"||b.status==="callback_required",f=i.useMemo(()=>{const b=l.trim().toLowerCase();return u.filter(M=>{const A=r==="all"||r==="open"&&N(M)||r==="done"&&M.status==="delivered"||r==="archived"&&M.status==="closed",E=!b||[M.caller_name,M.caller_phone,M.message,M.resident_name,M.target_label].some(K=>K&&K.toLowerCase().includes(b));return A&&E})},[u,r,l]),S=f.find(b=>b.id===g)||u.find(b=>b.id===g)||null,_=z({mutationFn:({id:b,status:M})=>Ln(t,b,{status:M}),onSuccess:()=>{a.invalidateQueries({queryKey:["reception-phone-messages",t]}),a.invalidateQueries({queryKey:["reception-overview",t]})},onError:b=>s({title:"Couldn't update",description:b instanceof Error?b.message:"Please try again.",variant:"destructive"})}),V=[{key:"open",label:"Open"},{key:"done",label:"Done"},{key:"archived",label:"Archived"},{key:"all",label:"All"}];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1 rounded-[14px] border border-primary/15 bg-primary/10 p-1",role:"tablist","aria-label":"Filter phone messages",children:V.map(b=>e.jsx("button",{type:"button",onClick:()=>d(b.key),className:$("rounded-[10px] px-3 py-2 text-sm font-semibold transition-all",r===b.key?"bg-primary text-primary-foreground shadow-sm":"text-muted-foreground hover:bg-card/60 hover:text-foreground"),children:b.label},b.key))}),e.jsxs(k,{className:`gap-1.5 ${Y}`,onClick:()=>x(!0),children:[e.jsx(nt,{className:"h-4 w-4"})," New message"]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-[minmax(0,360px)_1fr]",children:[e.jsxs("div",{className:$(W,"flex flex-col overflow-hidden"),children:[e.jsx("div",{className:"border-b border-border p-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}
1),e.jsx(O,{value:l,onChange:b=>n(b.target.value),"data-update-transient":"true",placeholder:"Search messages...",className:"h-10 pl-9"})]})}),e.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:T?e.jsxs("p",{className:"flex items-center gap-2 p-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):v?e.jsx("p",{className:"p-6 text-center text-sm text-muted-foreground",children:"Couldn't load messages."}):f.length===0?e.jsxs("div",{className:"p-8 text-center",children:[e.jsx(wr,{className:"mx-auto mb-3 h-10 w-10 text-black dark:text-white"}),e.jsx("p",{className:"text-base font-medium text-black dark:text-white",children:"No messages in this view."})]}):e.jsx("ul",{className:"divide-y divide-border",children:f.map(b=>{const M=S?.id===b.id;return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>c(b.id),className:$("flex w-full flex-col gap-1 px-4 py-3 text-left transition-colors",M?"bg-primary/10":"hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-foreground",children:ne(b.caller_name,"Caller")}),N(b)&&e.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[#87947f]"})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsxs(ss,{children:[e.jsx(Xe,{className:"h-3 w-3"})," Reception message"]}),b.callback_required&&e.jsxs(ss,{tone:"callback",children:[e.jsx(Vt,{className:"h-3 w-3"})," Callback"]})]}),e.jsxs("span",{className:"truncate text-xs text-muted-foreground",children:["For ",ne(b.resident_name||b.target_label||b.target_type)]}),e.jsx("span",{className:"truncate text-xs text-slate-400",children:b.message})]})},b.id)})})})]}),e.jsx("div",{className:$(W,"p-5"),children:S?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-xl font-semibold text-foreground",children:ne(S.caller_name,"Caller")}),S.caller_phone&&e.jsxs("a",{href:`tel:${S.caller_phone}`,className:"mt-1 inline-flex items-center gap-1.5 text-sm font-medium text-[#5f6e58] hover:underline dark:text-slate-300",children:[e.jsx(Xe,{className:"h-4 w-4"})," ",S.caller_phone]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ll(S.status),il(S.urgency),S.callback_required&&e.jsxs(L,{variant:"outline",className:"gap-1 border-[#dcd8cf] bg-[#f8f7f2] text-slate-600 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:[e.jsx(Vt,{className:"h-3 w-3"})," Callback"]})]})]}),e.jsxs("dl",{className:"grid grid-cols-1 gap-3 rounded-xl border border-slate-100 bg-slate-50/60 p-4 text-sm dark:border-slate-800 dark:bg-slate-800/30 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"For"}),e.jsxs("dd",{className:"mt-0.5 inline-flex items-center gap-1.5 font-medium text-foreground",children:[e.jsx(ua,{className:"h-3.5 w-3.5"})," ",ne(S.resident_name||S.target_label||S.target_type)]})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Taken"}),e.jsxs("dd",{className:"mt-0.5 inline-flex items-center gap-1.5 font-medium text-slate-800 dark:text-slate-100",children:[e.jsx(Ve,{className:"h-3.5 w-3.5"})," ",ie(S.created_at)]})]}),S.taken_by&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Taken by"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-800 dark:text-slate-100",children:S.taken_by})]}),S.assigned_to&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Assigned to"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-800 dark:text-slate-100",children:S.assigned_to})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs uppercase tracking-wide text-slate-400",children:"Message"}),e.jsx("p",{className:"whitespace-pre-wrap rounded-xl border border-slate-100 bg-white p-4 text-base text-slate-800 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-100",children:S.message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 border-t border-slate-100 pt-4 dark:border-slate-800",children:[e.jsxs(k,{className:`gap-1.5 ${Y}`,onClick:()=>w(S),children:[e.jsx(Me,{className:"h-4 w-4"})," ",p.has(S.id)?"Notify again":S.target_type==="staff"?"Notify staff":"Notify target"]}),S.status!=="delivered"&&S.status!=="closed"&&e.jsxs(k,{variant:"outline",className:`gap-1.5 ${Q}`,disabled:_.isPending,onClick:()=>_.mutate({id:S.id,status:"delivered"}),children:[e.jsx(mt,{className:"h-4 w-4"})," Mark done"]}),(S.status==="delivered"||S.status==="closed")&&e.jsxs(k,{variant:"outline",className:`gap-1.5 ${Q}`,disabled:_.isPending,onClick:()=>_.mutate({id:S.id,status:"open"}),children:[e.jsx(Qs,{className:"h-4 w-4"})," Reopen"]}),S.status!=="closed"&&e.jsxs(k,{variant:"outline",className:`gap-1.5 ${Q}`,disabled:_.isPending,onClick:()=>_.mutate({id:S.id,status:"closed"}),children:[e.jsx(ds,{className:"h-4 w-4"})," Archive"]}),S.caller_phone&&e.jsx(k,{asChild:!0,variant:"outline",className:`gap-1.5 ${Q}`,children:e.jsxs("a",{href:`tel:${S.caller_phone}`,children:[e.jsx(Vt,{className:"h-4 w-4"})," Call back"]})})]})]}):e.jsxs("div",{className:"flex h-full min-h-[40vh] flex-col items-center justify-center text-center",children:[e.jsx(Ie,{className:"mb-3 h-12 w-12 text-black dark:text-white"}),e.jsx("p",{className:"text-lg font-semibold text-black dark:text-white",children:"Select a message"}),e.jsx("p",{className:"mt-1 text-base text-slate-900 dark:text-slate-100",children:"Choose a message from the list to view details and update its status."})]})})]}),e.jsx(ps,{slug:t,open:m,onOpenChange:x}),e.jsx(ka,{slug:t,message:o,open:!!o,onOpenChange:b=>{b||w(null)},onNotified:b=>j(M=>new Set(M).add(b))})]})}const cl={open:"Open",done:"Done",archived:"Archived"};function dl({slug:t}
1){const[s,a]=i.useState(!1),[r,d]=i.useState(!1),[l,n]=i.useState(null),{data:g,isLoading:c,isError:m}=B({queryKey:["reception-notes",t],queryFn:()=>is(t),staleTime:15e3}),x=(g||[]).filter(o=>!s||o.follow_up_required);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>a(o=>!o),className:$("inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 text-sm font-medium transition-colors",s?"border-[#87947f] bg-[#eef1ea] text-[#5f6e58] dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100":"border-[#dcd8cf] bg-white text-slate-600 hover:border-[#b7c1af] dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300"),children:[e.jsx(yt,{className:"h-3.5 w-3.5"})," Follow-ups only"]}),e.jsxs(k,{className:`gap-1.5 ${Y}`,onClick:()=>d(!0),children:[e.jsx(nt,{className:"h-4 w-4"})," Add note"]})]}),c?e.jsxs("p",{className:"flex items-center gap-2 py-8 text-sm text-slate-500",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):m?e.jsx("div",{className:$(W,"border-dashed p-8 text-center text-sm text-slate-500"),children:"Couldn't load notes."}):x.length===0?e.jsx("div",{className:$(W,"border-dashed p-8 text-center text-sm text-slate-500 dark:text-slate-400"),children:s?"No follow-ups outstanding.":"No reception notes yet."}):e.jsx("ul",{className:"space-y-2.5",children:x.slice(0,50).map(o=>{const w=rs(o.priority);return e.jsxs("li",{className:"reception-workspace-row rounded-[16px] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ss,{tone:"note",children:[e.jsx(et,{className:"h-3 w-3"})," Reception note"]}),o.category&&e.jsx(L,{variant:"secondary",children:o.category}),e.jsx(L,{variant:"outline",className:rl[w],children:w}),o.status&&o.status!=="open"&&e.jsx(L,{variant:"secondary",children:cl[o.status]||o.status}),o.follow_up_required&&e.jsxs(L,{variant:"outline",className:"gap-1 border-[#b7c1af] text-[#5f6e58]",children:[e.jsx(yt,{className:"h-3 w-3"})," Follow-up"]})]}),e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,onClick:()=>n(o),children:[e.jsx(cs,{className:"h-4 w-4"})," Edit"]})]}),e.jsx("p",{className:"mt-2 whitespace-pre-wrap text-sm text-slate-800 dark:text-slate-100",children:o.body}),e.jsxs("p",{className:"mt-2 inline-flex items-center gap-1 text-xs text-slate-400",children:[e.jsx(Ve,{className:"h-3 w-3"})," ",ie(o.created_at),o.created_by?` - ${o.created_by}`:""]})]},o.id)})}),e.jsx(xs,{slug:t,open:r,onOpenChange:d}),e.jsx(al,{slug:t,note:l,open:!!l,onOpenChange:o=>{o||n(null)}})]})}function ml({slug:t,enabled:s}){const a=s.has("phone_messages"),r=s.has("reception_notes"),[d,l]=i.useState(a?"phone":"notes"),n=[a&&{value:"phone",label:"Phone Messages",icon:Xe},r&&{value:"notes",label:"Note Follow-ups",icon:et}].filter(Boolean);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:Ie,title:"Messages",description:"Phone messages, callbacks, reception notes, and follow-ups in one focused centre."}),n.length===0?e.jsxs("div",{className:$(W,"border-dashed p-10 text-center"),children:[e.jsx(Ie,{className:"mx-auto mb-3 h-10 w-10 text-slate-300"}),e.jsx("p",{className:"text-base font-semibold text-slate-800 dark:text-slate-100",children:"Messaging isn't enabled yet"}),e.jsx("p",{className:"mx-auto mt-1 max-w-md text-sm text-slate-500 dark:text-slate-400",children:"Ask your village admin to enable Phone Messages or Reception Notes under Reception Tools."})]}):e.jsxs(e.Fragment,{children:[n.length>1&&e.jsx(nl,{items:n,value:d,onValueChange:g=>l(g==="phone"?"phone":"notes"),label:"Message centre view"}),d==="phone"&&a?e.jsx(ol,{slug:t}):e.jsx(dl,{slug:t})]})]})}const Pe=t=>t?String(t).replace(/[<>&]/g,s=>({"<":"&lt;",">":"&gt;","&":"&amp;"})[s]):"";function hs(t){return new Date(t).toLocaleTimeString("en-NZ",{hour:"2-digit",minute:"2-digit"})}function xl(t,s){const a=kr(s),r=new Blob(["\uFEFF"+a],{type:"text/csv;charset=utf-8;"}),d=URL.createObjectURL(r),l=document.createElement("a");l.href=d,l.download=t,l.click(),URL.revokeObjectURL(d)}function pl(t,s){const a=[["Roll call",s||"",Ws(new Date)],[],["Name","Type","Company","Visiting","Signed in"]],r=t.signed_in.map(d=>[`${d.first_name} ${d.last_name}`.trim(),d.visitor_type||"",d.company||"",d.resident_name||"",hs(d.signed_in_at)]);xl(`roll-call-${new Date().toISOString().slice(0,10)}.csv`,[...a,...r])}function ul(t,s){const a=window.open("","_blank","width=820,height=920");if(!a)return;const r=t.signed_in.map(l=>`<tr><td>${Pe(l.first_name)} ${Pe(l.last_name)}</td><td>${Pe(l.visitor_type||"")}</td><td>${Pe(l.company||"")}</td><td>${Pe(l.resident_name||"")}</td><td>${Pe(hs(l.signed_in_at))}</td></tr>
1`).join(""),d=(t.site_numbers||[]).map(l=>`<li><strong>${Pe(l.label)}:</strong> ${Pe(l.number)}</li>`).join("");a.document.write(`<!doctype html><html><head><title>Roll call</title><meta charset="utf-8"/><style>
2    *{font-family:Inter,system-ui,sans-serif} body{margin:0;padding:20px;color:#111}
3    h1{margin:0 0 4px} .meta{color:#555;margin-bottom:14px}
4    table{width:100%;border-collapse:collapse;margin-top:10px} th,td{border:1px solid #ccc;padding:6px 8px;text-align:left;font-size:13px}
5    th{background:#f3f4f6} .nums{margin:8px 0} .nums li{margin:2px 0}
6    @media print{@page{margin:12mm}}
7  </style></head><body>
8    <h1>Emergency roll call</h1>
9    <div class="meta">${Pe(s||"")} - ${Pe(Ws(new Date))} - ${t.count} on site</div>
10    ${t.duty_manager?`<div><strong>Duty manager:</strong> ${Pe(t.duty_manager)}</div>`:""}
11    ${d?`<ul class="nums">${d}</ul>`:""}
12    ${t.emergency_notes?`<p>${Pe(t.emergency_notes)}</p>`:""}
13    <table><thead><tr><th>Name</th><th>Type</th><th>Company</th><th>Visiting</th><th>In</th></tr></thead><tbody>${r||'<tr><td colspan="5">No one signed in.</td></tr>'}</tbody></table>
14    <script>window.onload=function(){window.print();}<\/script>
15  </body></html>`),a.document.close()}function hl({p:t}){const s=t.visitor_type==="service_person"||t.visitor_type==="contractor";return e.jsxs("li",{className:"reception-workspace-row flex items-center justify-between gap-2 rounded-xl px-3.5 py-2.5 text-sm",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 font-medium text-foreground",children:[s&&e.jsx(ct,{className:"h-3.5 w-3.5 text-[#765f52]"}),t.first_name," ",t.last_name,t.company&&e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:t.company})]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[t.resident_name?`${t.resident_name} - `:"",hs(t.signed_in_at)]})]})}function gl({slug:t,villageName:s}){const{data:a,isLoading:r,isError:d}=B({queryKey:["reception-rollcall",t],queryFn:()=>ia(t),staleTime:1e4,refetchInterval:3e4});return e.jsxs(tt,{className:`${W} border-[#d8b9ab]`,children:[e.jsx(gt,{icon:vt,tone:"danger",title:"Emergency roll-call",meta:a&&e.jsxs(L,{variant:"outline",className:"border-[#d8b9ab] bg-[#f6e9e4] text-[#8a5c4b] dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:[a.count," on site"]}),action:e.jsxs(e.Fragment,{children:[e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,disabled:!a,onClick:()=>a&&ul(a,s),children:[e.jsx(_r,{className:"h-4 w-4"})," Print"]}),e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,disabled:!a,onClick:()=>a&&pl(a,s),children:[e.jsx(Ha,{className:"h-4 w-4"})," CSV"]})]})}),e.jsx(st,{className:"space-y-4",children:r?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]}):d||!a?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-8 text-center text-sm text-muted-foreground",children:"Couldn't load roll-call."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:`p-3.5 ${Br}`,children:[e.jsxs("p",{className:"mb-1.5 flex items-center gap-1.5 text-sm font-semibold text-foreground",children:[e.jsx(Xe,{className:"h-4 w-4"})," Key numbers"]}),a.duty_manager&&e.jsxs("p",{className:"text-sm text-foreground",children:["Duty manager: ",e.jsx("span",{className:"font-medium",children:a.duty_manager})]}),(a.site_numbers||[]).length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No site numbers configured."}):e.jsx("ul",{className:"space-y-0.5 text-sm",children:a.site_numbers.map((l,n)=>e.jsxs("li",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[l.label,":"]})," ",e.jsx("span",{className:"font-medium text-foreground",children:l.number})]},n))})]}),a.emergency_notes&&e.jsxs("div",{className:"rounded-2xl border border-[#ded6ca] bg-[#f1ece7]/70 p-3.5 dark:border-slate-700 dark:bg-slate-800",children:[e.jsxs("p",{className:"mb-1.5 flex items-center gap-1.5 text-sm font-semibold text-[#765f52] dark:text-slate-200",children:[e.jsx(dt,{className:"h-4 w-4"})," Procedure"]}),e.jsx("p",{className:"whitespace-pre-wrap text-sm text-[#765f52] dark:text-slate-200",children:a.emergency_notes})]})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"mb-2 text-sm font-semibold text-foreground",children:["On site now (",a.count,")"]}),a.signed_in.length===0?e.jsx("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-6 text-center text-sm text-muted-foreground",children:"No visitors or contractors currently on site."}):e.jsx("ul",{className:"space-y-1.5",children:a.signed_in.map(l=>e.jsx(hl,{p:l},l.id))})]})]})})]})}function fl({people:t}){const[s,a]=i.useState(null),[r,d]=i.useState(new Set),[l,n]=i.useState(null),g=i.useMemo(()=>t.filter(j=>j.group==="confirmed"),[t]),c=i.useMemo(()=>t.filter(j=>j.group==="verify"),[t]),m=t.filter(j=>r.has(j.id)).length,x=t.length?Math.round(m/t.length*100):0,o=j=>{a(j),d(new Set),n(new Date)},w=j=>{d(C=>{const T=new Set(C);return T.has(j)?T.delete(j):T.add(j),T})};if(!s)return e.jsx("section",{className:$(W,"overflow-hidden p-5 md:p-6"),"aria-labelledby":"evacuation-checklist-heading",children:e.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"grid h-14 w-14 shrink-0 place-items-center rounded-2xl bg-[var(--reception-red-tint)] text-[var(--reception-red-600)]",children:e.jsx(dt,{className:"h-7 w-7"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[15px] font-bold uppercase tracking-[0.08em] text-black dark:text-white",children:"Touch checklist"}),e.jsx("h2",{id:"evacuation-checklist-heading",className:"text-[22px] font-semibold text-black dark:text-white",children:"Fire test or emergency evacuation"})]})]}),e.jsx("p",{className:"mt-3 text-base font-medium leading-relaxed text-black dark:text-white",children:"Start a live checklist, then touch each person as they reach the assembly point. Confirmed visitors and temporary workers are separated from residents and staff who must be verified in person."}),e.jsx("p",{className:"mt-2 text-[15px] font-semibold text-black dark:text-white",children:"This checklist does not contact emergency services or send alerts."})]}),e.jsxs("div",{className:"grid shrink-0 gap-3 sm:grid-cols-2",children:[e.jsxs(k,{type:"button",variant:"outline",className:"min-h-14 gap-2 rounded-[14px] border-[var(--reception-amber-600)]/30 bg-[var(--reception-amber-tint)] px-5 text-base text-[var(--reception-amber-600)] hover:bg-[var(--reception-amber-tint)]/80",onClick:()=>o("fire_drill"),children:[e.jsx(Ns,{className:"h-6 w-6"})," Start fire test"]}),e.jsxs(k,{type:"button",className:"min-h-14 gap-2 rounded-[14px] bg-[var(--reception-red-600)] px-5 text-base text-white hover:bg-[var(--reception-red-600)]/90",onClick:()=>o("emergency"),children:[e.jsx(Qt,{className:"h-6 w-6"})," Start evacuation"]})]})]})});const p=(j,C,T,v)=>e.jsxs("section",{"aria-labelledby":`evacuation-${j}-heading`,children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-end justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h3",{id:`evacuation-${j}-heading`,className:"text-[16px] font-semibold text-[var(--reception-label)]",children:C}),e.jsx("p",{className:"text-[12px] text-[var(--reception-label-2)]",children:T})]}),e.jsxs("span",{className:"text-[13px] font-semibold tabular-nums text-[var(--reception-label-2)]",children:[v.filter(u=>r.has(u.id)).length,"/",v.length]})]}),v.length===0?e.jsx("p",{className:"rounded-[14px] border border-dashed border-[var(--reception-hairline)] p-4 text-[13px] text-[var(--reception-label-2)]",children:"No people in this group."}):e.jsx("ul",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:v.map(u=>{const N=r.has(u.id);return e.jsx("li",{children:e.jsxs("button",{type:"button","aria-pressed":N,onClick:()=>w(u.id),className:$("group flex min-h-[68px] w-full items-center gap-3 rounded-[14px] border px-4 text-left transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",N?"border-emerald-500/35 bg-emerald-500/10":"border-[var(--reception-hairline)] bg-[var(--reception-surface)] hover:border-[var(--reception-blue-600)]/25 hover:bg-[var(--reception-blue-tint)]"),children:[e.jsx("span",{className:$("grid h-9 w-9 shrink-0 place-items-center rounded-xl transition-colors",N?"bg-emerald-600 text-white":"bg-[var(--reception-tile)] text-[var(--reception-label-3)] group-hover:text-[var(--reception-blue-600)]"),children:N?e.jsx(mt,{className:"h-5 w-5"}):e.jsx(Sr,{className:"h-5 w-5"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:$("block truncate text-[14px] font-semibold",N?"text-emerald-800 dark:text-emerald-200":"text-[var(--reception-label)]"),children:u.name}),e.jsx("span",{className:"mt-0.5 block truncate text-[12px] text-[var(--reception-label-2)]",children:u.detail})]})]})},u.id)})})]});return e.jsxs("section",{className:$(W,"overflow-hidden border-[var(--reception-red-600)]/25 p-5 md:p-6"),"aria-label":s==="fire_drill"?"Active fire test checklist":"Active emergency evacuation checklist",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"grid h-12 w-12 place-items-center rounded-2xl bg-[var(--reception-red-tint)] text-[var(--reception-red-600)]",children:s==="fire_drill"?e.jsx(Ns,{className:"h-6 w-6"}):e.jsx(Qt,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-semibold uppercase tracking-[0.08em] text-[var(--reception-red-600)]",children:"Active checklist"}),e.jsx("h2",{className:"text-[20px] font-semibold text-[var(--reception-label)]",children:s==="fire_drill"?"Fire evacuation test":"Emergency evacuation"}),l&&e.jsxs("p",{className:"text-[12px] text-[var(--reception-label-2)]",children:["Started ",l.toLocaleTimeString("en-NZ",{hour:"2-digit",minute:"2-digit"})]})]})]}),e.jsxs(k,{type:"button",variant:"outline",className:$("min-h-11 gap-2 rounded-[14px]",Q),onClick:()=>{a(null),d(new Set)},children:[e.jsx(as,{className:"h-4 w-4"})," End checklist"]})]}),e.jsxs("div",{className:"my-5 rounded-[16px] bg-[var(--reception-surface)] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-[15px] font-semibold text-[var(--reception-label)]",children:"Assembly progress"}),e.jsxs("p",{className:"text-[18px] font-semibold tabular-nums text-[var(--reception-label)]",children:[m,"/",t.length]})]}),e.jsx("div",{className:"mt-3 h-3 overflow-hidden rounded-full bg-[var(--reception-tile)]",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-600 transition-[width] duration-300",style:{width:`${x}%`}})}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-[12px] font-medium text-[var(--reception-label-2)]",children:[x,"% accounted for"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{type:"button",size:"sm",variant:"ghost",className:"gap-1.5",onClick:()=>d(new Set),children:[e.jsx(Qs,{className:"h-4 w-4"})," Reset"]}),e.jsxs(k,{type:"button",size:"sm",variant:"outline",className:"gap-1.5",onClick:()=>d(new Set(t.map(j=>j.id))),children:[e.jsx(Cr,{className:"h-4 w-4"})," Mark all"]})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[p("confirmed","Confirmed on site","Signed-in visitors, contractors, and temporary site presence.",g),p("verify","Verify in person","Resident and staff rosters are reference lists, not confirmed physical presence.",c)]})]})}const Da=[{value:"maintenance",label:"Maintenance worker"},{value:"agency_staff",label:"Agency staff"},{value:"volunteer",label:"Volunteer"},{value:"emergency_service",label:"Emergency service"},{value:"inspector",label:"Inspector"},{value:"contractor",label:"Temporary contractor"},{value:"other",label:"Other"}],jl=t=>Da.find(s=>s.value===t)?.label||"Other",Ks={name:"",person_type:"maintenance",company:"",reason:"",location:"",phone:"",expected_leave_at:"",notes:""};function bl({slug:t,open:s,onOpenChange:a,editing:r}){const{toast:d}=pe(),l=oe(),[n,g]=i.useState(Ks);i.useEffect(()=>{s&&g(r?{name:r.name||"",person_type:r.person_type||"other",company:r.company||"",reason:r.reason||"",location:r.location||"",phone:r.phone||"",expected_leave_at:r.expected_leave_at?yl(r.expected_leave_at):"",notes:r.notes||""}:Ks)},[s,r]);const c=(o,w)=>g(p=>({...p,[o]:w})),m=()=>l.invalidateQueries({queryKey:["reception-rollcall",t]}),x=z({mutationFn:async()=>{const o={name:n.name.trim(),person_type:n.person_type,company:n.company.trim()||null,reason:n.reason.trim()||null,location:n.location.trim()||null,phone:n.phone.trim()||null,expected_leave_at:n.expected_leave_at?new Date(n.expected_leave_at).toISOString():null,notes:n.notes.trim()||null};r?await la(t,{id:r.id,...o}):await On(t,o)},onSuccess:()=>
15{d({title:r?"Updated":"Added to site presence"}),m(),a(!1)},onError:o=>d({title:"Couldn't save",description:o.message,variant:"destructive"})});return e.jsx(ce,{open:s,onOpenChange:a,children:e.jsxs(de,{className:"max-h-[92vh] overflow-y-auto",children:[e.jsxs(me,{children:[e.jsx(xe,{children:r?"Edit site presence":"Add temporary site presence"}),e.jsx(kt,{children:"Record someone on site who isn't in the staff or visitor records."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sp-name",children:"Name"}),e.jsx(O,{id:"sp-name",value:n.name,onChange:o=>c("name",o.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{children:"Type"}),e.jsxs(ee,{value:n.person_type,onValueChange:o=>c("person_type",o),children:[e.jsx(te,{className:"h-11",children:e.jsx(se,{})}),e.jsx(ae,{children:Da.map(o=>e.jsx(q,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sp-company",children:"Company / organisation"}),e.jsx(O,{id:"sp-company",value:n.company,onChange:o=>c("company",o.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sp-location",children:"Location / area"}),e.jsx(O,{id:"sp-location",value:n.location,onChange:o=>c("location",o.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sp-phone",children:"Phone (optional)"}),e.jsx(O,{id:"sp-phone",type:"tel",inputMode:"tel",value:n.phone,onChange:o=>c("phone",o.target.value),className:"h-11"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sp-leave",children:"Expected to leave"}),e.jsx(O,{id:"sp-leave",type:"datetime-local",value:n.expected_leave_at,onChange:o=>c("expected_leave_at",o.target.value),className:"h-11"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sp-reason",children:"Reason for being on site"}),e.jsx(O,{id:"sp-reason",value:n.reason,onChange:o=>c("reason",o.target.value),className:"h-11",placeholder:"e.g. Fixing the lift"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"sp-notes",children:"Notes"}),e.jsx(ve,{id:"sp-notes",value:n.notes,onChange:o=>c("notes",o.target.value),rows:2})]})]}),e.jsxs(he,{children:[e.jsx(k,{variant:"ghost",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(k,{className:Y,disabled:!n.name.trim()||x.isPending,onClick:()=>x.mutate(),children:[x.isPending&&e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"})," ",r?"Save":"Add person"]})]})]})})}function vl({slug:t,people:s}){const{toast:a}=pe(),r=oe(),[d,l]=i.useState(!1),[n,g]=i.useState(null),c=()=>r.invalidateQueries({queryKey:["reception-rollcall",t]}),m=z({mutationFn:({id:x,act:o})=>la(t,{id:x,action:o}),onSuccess:(x,o)=>{a({title:o.act==="remove"?"Removed":"Marked as left"}),c()},onError:x=>a({title:"Couldn't update",description:x.message,variant:"destructive"})});return e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("h2",{className:"flex items-center gap-3 text-xl font-semibold text-black dark:text-white",children:[e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-[#eef1ea] text-[#6f7d68] dark:bg-slate-800 dark:text-slate-200",children:e.jsx(ct,{className:"h-6 w-6"})}),"Temporary site presence"]}),e.jsxs(k,{size:"sm",className:`gap-1.5 ${Y}`,onClick:()=>{g(null),l(!0)},children:[e.jsx(nt,{className:"h-4 w-4"})," Add person"]})]}),e.jsx("p",{className:"mb-3 text-base font-medium text-black dark:text-white",children:"People on site who aren't staff or signed-in visitors (maintenance, agency, emergency services, volunteers, inspectors...)."}),s.length===0?e.jsxs("p",{className:"rounded-xl border border-dashed border-border/70 bg-muted/30 px-4 py-6 text-center text-sm text-muted-foreground",children:[e.jsx(Or,{className:"mx-auto mb-2 h-6 w-6 text-slate-300"}),"No temporary people recorded on site."]}):e.jsx("ul",{className:"space-y-2",children:s.map(x=>e.jsx("li",{className:"reception-workspace-row rounded-[16px] p-3.5",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-2 text-base font-semibold text-foreground",children:[e.jsx("span",{className:"truncate",children:x.name}),e.jsx(L,{variant:"outline",className:"border-[#dcd8cf] bg-[#f8f7f2] text-slate-600 dar
15k:border-slate-700 dark:bg-slate-800 dark:text-slate-200",children:jl(x.person_type)})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground",children:[x.company&&e.jsx("span",{children:x.company}),x.location&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3.5 w-3.5"})," ",x.location]}),x.phone&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Xe,{className:"h-3.5 w-3.5"})," ",x.phone]})]}),x.reason&&e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:x.reason}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 text-xs text-slate-400",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ve,{className:"h-3 w-3"})," In ",Ze(x.created_at)]}),x.expected_leave_at&&e.jsxs("span",{children:["Expected out ",ie(x.expected_leave_at)]})]})]}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-1.5",children:[e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,onClick:()=>{g(x),l(!0)},children:[e.jsx(cs,{className:"h-3.5 w-3.5"})," Edit"]}),e.jsxs(k,{size:"sm",variant:"outline",className:`gap-1.5 ${Q}`,disabled:m.isPending,onClick:()=>m.mutate({id:x.id,act:"mark_left"}),children:[e.jsx(lt,{className:"h-3.5 w-3.5"})," Mark left"]}),e.jsxs(k,{size:"sm",variant:"ghost",className:"gap-1.5 text-muted-foreground hover:text-destructive",disabled:m.isPending,onClick:()=>m.mutate({id:x.id,act:"remove"}),children:[e.jsx(Ya,{className:"h-3.5 w-3.5"})," Remove"]})]})]})},x.id))}),e.jsx(bl,{slug:t,open:d,onOpenChange:x=>{l(x),x||g(null)},editing:n})]})}function yl(t){const s=new Date(t),a=r=>String(r).padStart(2,"0");return`${s.getFullYear()}-${a(s.getMonth()+1)}-${a(s.getDate())}T${a(s.getHours())}:${a(s.getMinutes())}`}function rt({icon:t,label:s,value:a,tone:r}){return e.jsxs("div",{className:$(W,"flex items-center gap-3.5 p-4",r==="danger"&&"border-destructive/30 bg-destructive/5"),children:[e.jsx("span",{className:$("flex h-14 w-14 shrink-0 items-center justify-center rounded-xl",r==="danger"?"bg-destructive/10 text-destructive":"bg-primary/10 text-primary"),children:e.jsx(t,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:$("text-2xl font-bold leading-none tabular-nums",r==="danger"?"text-destructive":"text-foreground"),children:a}),e.jsx("p",{className:"mt-1 text-base font-semibold text-black dark:text-white",children:s})]})]})}function Nl({slug:t,enabled:s,villageName:a}){const r=s.has("emergency_contacts"),d=s.has("resident_search"),{data:l}=B({queryKey:["reception-rollcall",t],queryFn:()=>ia(t),enabled:r,staleTime:1e4,refetchInterval:3e4}),{data:n,isLoading:g}=B({queryKey:["reception-residents",t,""],queryFn:()=>Lt(t,""),enabled:r&&d,staleTime:6e4}),c=n||[],m=s.has("arrivals_departures"),{data:x}=B({queryKey:["reception-arrivals",t],queryFn:()=>In(t),enabled:r&&m,staleTime:6e4}),o=x||[],w=l?.signed_in.length??0,p=l?.contractors.length??0,j=l?.staff??[],C=j.filter(f=>f.rostered_today),T=j.filter(f=>!f.rostered_today),v=l?.site_presence??[],u=w+v.length+j.length+c.length,N=[...(l?.signed_in||[]).map(f=>({id:`visitor-${f.id}`,name:`${f.first_name} ${f.last_name}`.trim(),detail:f.company||(f.resident_name?`Visiting ${f.resident_name}`:f.visitor_type||"Visitor"),group:"confirmed"})),...v.map(f=>({id:`site-${f.id}`,name:f.name,detail:f.location||f.company||f.person_type.replace(/_/g," "),group:"confirmed"})),...j.map(f=>({id:`staff-${f.id}`,name:f.name,detail:f.role_title||(f.rostered_today?"Rostered today":"Active staff reference"),group:"verify"})),...c.map(f=>({id:`resident-${f.id}`,name:Be(f),detail:f.unit_room||"Resident roster",group:"verify"}))];return r?e.jsxs("div",{className:"reception-rollcall-page space-y-6",children:[e.jsx(We,{icon:vt,eyebrow:"Emergency workspace",title:"Roll Call",description:e.jsxs(e.Fragment,{children:["Emergency and evacuation reference for everyone signed in at ",a,"."]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(rt,{icon:Je,label:"Visitors on site",value:w,tone:"danger"}),e.jsx(rt,{icon:ct,label:"Contractors on site",value:p,tone:"danger"}),e.jsx(rt,{icon:Ht,label:"Staff (roster ref.)",value:j.length}),e.jsx(rt,{icon:Rr,label:"Temporary on site",value:v.length,tone:"danger"}),e.jsx(rt,{icon:ks,label:"Residents on roster",value:c.length}),e.jsx(rt,{icon:Pr,label:"Total to verify",value:u,tone:"danger"})]}),e.jsx(fl,{people:N}),e.jsx(gl,{slug:t,villageName:a}),e.jsx(vl,{slug:t,people:v}),e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2 text-base font-semibold text-foreground",children:[e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(Ht,{className:"h-6 w-6"})}),"Staff reference"]}),e.jsxs("p",{className:"mb-3 flex items-start gap-2 text-base font-medium text-black dark:text-white",children:[e.jsx(Rt,{className:"mt-0.5 h-5 w-5 shrink-0"}
15),"Staff roster reference — verify in person. ",l?.staff_roster_known?"Staff rostered on today are listed first; this is not confirmed physical presence.":"No on-duty roster signal is available, so this is the active staff list only — not confirmed presence."]}),j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active staff found."}):e.jsxs("div",{className:"space-y-4",children:[C.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:["On duty today (roster) · ",C.length]}),e.jsx("ul",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:C.map(f=>e.jsxs("li",{className:"reception-workspace-row flex items-center justify-between gap-2 rounded-xl px-3 py-2.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium text-foreground",children:f.name}),f.role_title&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:f.role_title})]},f.id))})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[C.length>0?"Other active staff":"Active staff"," · ",T.length]}),e.jsx("ul",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:T.map(f=>e.jsxs("li",{className:"reception-workspace-row flex items-center justify-between gap-2 rounded-xl px-3 py-2.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium text-foreground",children:f.name}),f.role_title&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:f.role_title})]},f.id))})]})]})]}),m&&e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("h2",{className:"mb-3 flex items-center gap-2 text-base font-semibold text-slate-800 dark:text-slate-100",children:[e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-[#eef1ea] text-[#6f7d68] dark:bg-slate-800 dark:text-slate-200",children:e.jsx(lr,{className:"h-6 w-6"})}),"Recent arrivals & departures"]}),o.length===0?e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"No recent arrivals or departures recorded."}):e.jsx("ul",{className:"space-y-1.5",children:o.slice(0,12).map(f=>e.jsxs("li",{className:"reception-workspace-row flex items-center justify-between gap-2 rounded-xl px-3 py-2.5 text-sm",children:[e.jsxs("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:[f.resident_name,f.unit_room?` - ${f.unit_room}`:""]}),e.jsxs("span",{className:"flex items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[f.event_date,e.jsx(L,{variant:f.type==="arrival"?"secondary":"outline",className:"capitalize",children:f.type})]})]},f.id))})]}),d&&e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2 text-base font-semibold text-slate-800 dark:text-slate-100",children:[e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-[#eef1ea] text-[#6f7d68] dark:bg-slate-800 dark:text-slate-200",children:e.jsx(ks,{className:"h-6 w-6"})}),"Residents roster"]}),e.jsxs("p",{className:"mb-3 flex items-start gap-2 text-base font-medium text-black dark:text-white",children:[e.jsx(Rt,{className:"mt-0.5 h-5 w-5 shrink-0"}),"Expected in village - this is the resident roster, not confirmed presence. Check each resident in person during an evacuation."]}),g?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-sm text-slate-500",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading roster..."]}):c.length===0?e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"No residents found."}):e.jsx("ul",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:c.map(f=>e.jsxs("li",{className:"reception-workspace-row flex items-center justify-between gap-2 rounded-xl px-3 py-2.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium text-slate-800 dark:text-slate-100",children:Be(f)}),f.unit_room&&e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-xs text-slate-500 dark:text-slate-400",children:[e.jsx(Qe,{className:"h-3 w-3"})," ",f.unit_room]})]},f.id))})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:vt,eyebrow:"Emergency workspace",title:"Roll Call",description:"Emergency and evacuation reference."}),e.jsx(ht,{icon:vt,title:"Roll call isn't enabled",message:"Ask your village admin to enable Emergency Contacts under Reception & Visitors - Reception Tools to use the roll-call."})]})}function it({icon:t,label:s,value:a,hint:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-border py-3 last:border-0",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",children:e.jsx(t,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s}),r&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]}),e.jsx("div",{className:"shrink-0 text-right text-sm font-semibold text-foreground",children:a})]})}function wl({slug:t,visitorsHref:s,navigate:a,preferences:r,setPreferences:d,residentAccentColor:l}){const{data:n,isLoading:g,isError:c}=B({queryKey:["reception-settings",t],queryFn:()=>na(t),staleTime:6e4,retry:1}),{data:m}=B({queryKey:["reception-tools",t],queryFn:()=>oa(t),staleTime:6e4,retry:1}),x=n?.badge_template&&Object.keys(n.badge_template).length>0;return e.jsxs("div",{className:"space-y-6",children:[e.jsx(We,{icon:Bs,title:"Settings",description:"Display preferences, desk links, and your village's read-only reception configuration."}),Xn(t)&&e.jsx("section",{className:$(W,"p-4 md:p-5"),children:e.jsx(er,{slug:t,audience:"reception"})}),e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("h2",{className:"mb-1 flex items-center gap-2 text-base font-semibold text-foreground",children:[e.jsx(Ga,{className:"h-4 w-4 text-primary"})," Display"]}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Choose a comfortable reading size and accent for this reception desk."}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-[1fr_280px] md:items-center",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"reception-font-size",className:"text-sm font-semibold text-foreground",children:"Font size"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Applies across the logged-in Reception app on this device."})]}),e.jsxs(ee,{value:r.fontSize,onValueChange:o=>d({...r,fontSize:o}),children:[e.jsx(te,{id:"reception-font-size",className:"h-12 text-base",children:e.jsx(se,{})}),e.jsx(ae,{children:es.map(o=>e.jsx(q,{value:o.value,children:o.label},o.value))})]})]}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:es.find(o=>o.value===r.fontSize)?.description}),e.jsx("div",{className:"my-5 border-t border-border"}),e.jsxs("div",{children:[e.jsxs("h3",{className:"flex items-center gap-2 text-base font-semibold text-foreground",children:[e.jsx(Er,{className:"h-5 w-5 text-primary"})," Accent colour"]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Choose a colour for selected tabs, buttons, and reception icons. Your choice saves immediately on this device."}),e.jsx("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",role:"radiogroup","aria-label":"Reception accent colour",children:Na.map(o=>{const w=r.accent===o.value,p=o.value==="resident"?l:o.color||"#2563eb";return e.jsxs("button",{type:"button",role:"radio","aria-checked":w,onClick:()=>d({...r,accent:o.value}),className:$("reception-accent-choice flex min-h-[92px] items-center gap-3 rounded-2xl border p-3 text-left transition-all",w?"bg-card shadow-sm":"border-border bg-card/60 hover:bg-card"),style:w?{borderColor:p,boxShadow:`0 0 0 2px ${p}22`}:void 0,children:[e.jsx("span",{className:"grid h-11 w-11 shrink-0 place-items-center rounded-xl text-white",style:{backgroundColor:p},children:w?e.jsx(mt,{className:"h-6 w-6"}):e.jsx("span",{className:"h-3 w-3 rounded-full bg-white/90"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-semibold text-foreground",children:o.label}),e.jsx("span",{className:"mt-0.5 block text-xs leading-snug text-muted-foreground",children:o.description})]})]},o.value)})}),e.jsx("p",{className:"mt-3 text-xs font-semibold text-foreground",children:"Saved for this Reception desk."})]})]}),e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsx("h2",{className:"mb-3 text-base font-semibold text-foreground",children:"Links"}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(k,{asChild:!0,variant:"outline",className:`h-12 justify-start gap-2 ${Q}`,children:e.jsxs(At,{to:s,children:[e.jsx(Tr,{className:"h-4 w-4"})," Open visitor kiosk"]})}),e.jsxs(k,{type:"button",variant:"outline",className:`h-12 justify-start gap-2 ${Q}`,onClick:()=>
15a("dashboard"),children:[e.jsx(da,{className:"h-4 w-4"})," Return to Reception dashboard"]})]})]}),e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("h2",{className:"mb-1 flex items-center gap-2 text-base font-semibold text-foreground",children:[e.jsx(Ee,{className:"h-4 w-4 text-primary"})," Reception tools"]}),e.jsxs("p",{className:"mb-3 flex items-start gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Rt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"})," Tools are enabled by your village admin under Reception & Visitors. Shown here for reference."]}),m?e.jsx("div",{className:"grid gap-x-6 sm:grid-cols-2",children:(m.items||[]).map(o=>e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border py-2.5 text-sm",children:[e.jsx("span",{className:$("font-medium",o.is_enabled===!1?"text-muted-foreground":"text-foreground"),children:o.label}),e.jsxs("span",{className:$("inline-flex items-center gap-1.5 text-xs font-semibold",o.is_enabled===!1?"text-muted-foreground":"text-primary"),children:[e.jsx("span",{className:$("h-2 w-2 rounded-full",o.is_enabled===!1?"bg-muted-foreground/35":"bg-primary")}),o.is_enabled===!1?"Off":"On"]})]},o.tool_key))}):e.jsxs("p",{className:"flex items-center gap-2 py-4 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading..."]})]}),e.jsxs("section",{className:$(W,"p-4 md:p-5"),children:[e.jsxs("h2",{className:"mb-1 flex items-center gap-2 text-base font-semibold text-foreground",children:[e.jsx(Mt,{className:"h-4 w-4 text-primary"})," Desk configuration"]}),e.jsxs("p",{className:"mb-2 flex items-start gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Rt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"})," Managed by your village admin. These values are read-only at the desk."]}),g?e.jsxs("p",{className:"flex items-center gap-2 py-4 text-sm text-muted-foreground",children:[e.jsx(U,{className:"h-4 w-4 animate-spin"})," Loading configuration..."]}):c||!n?e.jsx("p",{className:"rounded-xl border border-dashed border-border bg-muted/40 px-4 py-6 text-center text-sm text-muted-foreground",children:"Configuration isn't available right now."}):e.jsxs("div",{children:[e.jsx(it,{icon:Ve,label:"Overdue visitor threshold",value:`${n.overdue_minutes} min`,hint:"When a signed-in visitor is flagged overdue"}),e.jsx(it,{icon:lt,label:"Auto sign-out",value:n.auto_signout_enabled?`After ${n.auto_signout_minutes} min`:"Off"}),e.jsx(it,{icon:Fr,label:"Required visitor fields",value:n.required_kiosk_fields.length?n.required_kiosk_fields.join(", "):"None"}),e.jsx(it,{icon:ha,label:"Privacy / consent",value:n.privacy_consent_required?"Required":"Optional",hint:n.privacy_consent_text?"Consent text configured":"No consent text set"}),e.jsx(it,{icon:$r,label:"Badge printing",value:x?"Configured":"Default template"}),e.jsx(it,{icon:ds,label:"Visitor record retention",value:`${n.visitor_retention_days} days`})]})]})]})}function kl({slug:t}){const s=B({queryKey:["reception-authoritative-activity",t],queryFn:()=>Hn(t,"reception-activity","reception"),staleTime:15e3});return e.jsxs("div",{className:"space-y-5",children:[e.jsx("header",{className:`${W} p-5`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"rounded-xl bg-[var(--reception-accent-tint)] p-3 text-[var(--reception-accent)]",children:e.jsx(zs,{className:"h-7 w-7"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-black dark:text-white",children:"Reception Activity"}),e.jsx("p",{className:"mt-1 text-sm font-medium text-black/70 dark:text-white/75",children:"Your immutable Reception updates, with accountable name, initials and time."})]})]})}),s.isLoading?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(U,{className:"h-7 w-7 animate-spin"})}):s.isError?e.jsxs("div",{className:`${W} p-6 text-center`,children:[e.jsx("p",{className:"font-bold",children:"Activity could not be loaded."}),e.jsx("p",{className:"mt-1 text-sm text-black/70 dark:text-white/70",children:s.error instanceof Error?s.error.message:String(s.error)})]}):s.data?.setup_required?e.jsxs("div",{className:`${W} p-6 text-center`,children:[e.jsx("p",{className:"font-bold",children:"Activity setup required"}),e.jsx("p",{className:"mt-1 text-sm text-black/70 dark:text-white/70",children:"Apply the latest role-based audit migration first."})]}):(s.data?.items||[]).length===0?e.jsxs("div",{className:`${W} p-6 text-center`,children:[e.jsx("p",{className:"font-bold",children:"No Reception activity yet"}),e.jsx("p",{className:"mt-1 text-sm text-black/70 dark:text-white/70",children:"Completed desk actions will appear here."})]}):e.jsx("div",{className:"space-y-3",children:(s.data?.items||[]).map(a=>e.jsxs("article",{className:`${W} flex flex-col gap-3 p-4 md:flex-row md:items-start md:justify-between`,children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(L,{variant:"secondary",children:_s(a.action)}),e.jsx(L,{variant:"outline",children:_s(a.entity_type)})]}),e.jsx("p",{className:"mt-2 text-base font-bold text-black dark:text-white",children:a.summary})]}),e.jsx(Dr,{value:a})]},a.id))})]})}const Aa=[{type:"navigate",label:"Sign a visitor in",targetView:"visitors",keywords:["visitor","sign","guest","contractor","induction","expected","badge"]},{type:"navigate",label:"Log a parcel",targetView:"deliveries",keywords:["parcel","delivery","package","courier","collect"]},{type:"navigate",label:"Find a resident",targetView:"residents",keywords:["resident","find","unit","notice","front","desk","message"]},{type:"navigate",label:"Maintenance",targetView:"maintenance",keywords:["maintenance","repair","broken","job","quote","contractor"]},{type:"navigate",label:"Messages & notes",targetView:"messages",keywords:["phone","message","note","notes","call"]},{type:"navigate",label:"Emergency roll call",targetView:"rollcall",ke
15ywords:["emergency","evacuation","roll","fire","drill","site"]},{type:"navigate",label:"Suggestions",targetView:"suggestions",keywords:["suggestion","idea","feedback"]},{type:"navigate",label:"My activity",targetView:"activity",keywords:["activity","history","today","log"]},{type:"navigate",label:"Desk settings",targetView:"settings",keywords:["settings","text","font","bigger","size","colour","color"]},{type:"navigate",label:"Dashboard",targetView:"dashboard",keywords:["dashboard","home","overview"]}];function _l(t,s){const a=`${t.targetView} ${t.label}`.toLowerCase(),r=Xt(t.targetView)?t.targetView:Aa.find(d=>a.includes(d.targetView)||(d.keywords||[]).some(l=>l.length>3&&a.includes(l)))?.targetView;return r?Et(r,s)?{kind:"open",action:{...t,targetView:r}}:{kind:"blocked",message:`${t.label} isn't turned on for your desk account. Ask a village admin to enable it.`}:{kind:"blocked",message:`“${t.label}” isn't part of the Reception desk.`}}function Cl(t,s="#2f8f7a"){return t&&/^#[0-9a-f]{6}$/i.test(t)?t:s}function Sl(t){const s=t.replace("#",""),a=parseInt(s.slice(0,2),16)/255,r=parseInt(s.slice(2,4),16)/255,d=parseInt(s.slice(4,6),16)/255,l=Math.max(a,r,d),n=Math.min(a,r,d),g=l-n;let c=0;g&&(l===a?c=(r-d)/g%6:l===r?c=(d-a)/g+2:c=(a-r)/g+4,c*=60,c<0&&(c+=360));const m=(l+n)/2,x=g?g/(1-Math.abs(2*m-1)):0;return`${Math.round(c)} ${Math.round(x*100)}% ${Math.round(m*100)}%`}function Rl({slug:t,session:s,portal:a,visitorsHref:r,onLogout:d,visualPreview:l}){const[n,g]=Xa(),c=n.get("desk"),m=Xt(c)?c:"dashboard",x=m==="maintenance"?n.get("maintenance"):m==="deliveries"?n.get("delivery"):null,o=i.useRef(null),[w,p]=zr(t),[j,C]=i.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(`seniorsites:reception-activity-open:${t}`)==="1"),T=a.village_name||a.operator_name||"Your Village",v=Cl(a.accent_color),u=w.accent==="reception-green"?"#6f7d68":w.accent==="resident"?v:"#2563eb",N=Sl(u);i.useEffect(()=>{window.localStorage.setItem(`seniorsites:reception-activity-open:${t}`,j?"1":"0")},[j,t]);const{data:f}=B({queryKey:["reception-tools",t],queryFn:()=>oa(t),staleTime:6e4,retry:1,enabled:!l}),{data:S}=B({queryKey:["reception-me",t],queryFn:()=>qn(t),staleTime:6e4,retry:1,enabled:!l}),{data:_}=B({queryKey:["reception-overview",t],queryFn:()=>Un(t),staleTime:15e3,refetchInterval:3e4,retry:1,enabled:!l}),V=l?.tools||(f?f.configured?f.items:Vn:[]),b=l?.me||S,M=l?.overview||_,A=i.useMemo(()=>{if(!b)return new Set;const D=V,Z=b?.allowed_tools,X=new Set;for(const I of D)I.is_enabled!==!1&&(Z&&!Z.includes(I.tool_key)||X.add(I.tool_key));return X},[V,b]),E=(D,Z)=>{const X=new URLSearchParams(n);D==="dashboard"?X.delete("desk"):X.set("desk",D),X.delete("maintenance"),X.delete("delivery"),Z&&D==="maintenance"&&X.set("maintenance",Z),Z&&D==="deliveries"&&X.set("delivery",Z),g(X,{replace:!1})},K=()=>{const D=new URLSearchParams(n);D.delete("maintenance"),D.delete("delivery"),g(D,{replace:!0})};i.useEffect(()=>{o.current?.scrollTo({top:0,behavior:"smooth"})},[m]);const G=e.jsx(Qn,{slug:t,view:m,available:!!b&&Et(m,A),audience:"reception"}),H={slug:t,enabled:A,overview:M,villageName:T,visitorsHref:r,session:s,navigate:E,detailId:x,clearDetail:K,preferences:w,setPreferences:p,residentAccentColor:v},ge=()=>{switch(m){case"residents":return e.jsx(bi,{...H});case"visitors":return e.jsx(Fi,{...H});case"deliveries":return e.jsx(Oi,{...H});case"maintenance":return e.jsx(Zi,{...H});case"suggestions":return e.jsx(tl,{...H});case"messages":return e.jsx(ml,{...H});case"rollcall":return e.jsx(Nl,{...H});case"activity":return e.jsx(kl,{...H});case"settings":return e.jsx(wl,{...H});default:return e.jsx(hi,{...H})}};return e.jsxs("div",{"data-reception-shell":!0,"data-reception-font-size":w.fontSize,"data-reception-accent":w.accent,className:"reception-shell-background relative h-screen overflow-hidden bg-[var(--reception-bg)] text-[var(--reception-label)]",style:{"--reception-original-background":`url(${Hs})`,"--reception-blue-600":u,"--primary":N,"--ring":N},children:[e.jsxs("div",{className:"relative z-10 flex h-full w-full min-w-0 flex-col gap-3 p-0 lg:flex-row lg:gap-6 lg:p-3",children:[e.jsx(Hr,{section:m,onSelect:E,enabled:A,villageName:T,displayName:s.display_name,onLogout:d,helpAction:G}),e.jsx("div",{ref:o,className:"reception-panel min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain scrollbar-hide max-lg:rounded-none max-lg:shadow-none",children:e.jsxs("main",{className:"max-w-full space-y-6 p-4 pb-[calc(6rem+env(safe-area-inset-bottom))] md:p-6 lg:p-8 lg:pb-8",children:[e.jsx(Gr,{villageName:T,displayName:s.display_name,latitude:a.latitude,longitude:a.longitude,slug:l?void 0:t,helpAction:G}),e.jsx("section",{"data-reception-page":m,"aria-live":"polite",children:ge()},m),m==="dashboard"&&e.jsx(Ts,{variant:"inline",open:!0,onToggle:()=>C(D=>!D),overview:M,enabled:A,navigate:E})]})}),e.jsx(Ts,{open:j,onToggle:()=>C(D=>!D),overview:M,enabled:A,navigate:E})]}),!l&&s.portal_id&&e.jsx(Wn,{portalId:s.portal_id,role:"reception",currentView:m,onNavigate:D=>{Xt(D)&&E(D)},villageName:T,authToken:xa(t)||"",fallbackActions:Aa.filter(D=>Et(D.targetView,A)),resolveAction:D=>_l(D,A),className:"max-lg:bottom-[calc(5rem+env(safe-area-inset-bottom))]",visibilityScope:pa(t)})]})}async function Pl(t){const s=Zn(),a=await fetch(`${Lr("portal-public")}?slug=${t}&section=meta&namespace=${s}`);if(!a.ok)throw new Error("Portal not found");return a.json()}function Qc(){const{slug:t}=en();Ar();const[s,a]=i.useState(()=>t?Kn(t):null);i.useEffect(()=>{s&&t&&Za(`reception:${t}:${sessionStorage.getItem(`portal_auth_reception_${t}`)}`)},[s,t]);const{data:r}=B({queryKey:["portal-meta",t],queryFn:()=>Pl(t),enabled:!!t,staleTime:12e4,refetchOnMount:"always",refetchInterval:()=>document.visibilityState==="visible"?3e4:!1,refetchIntervalInBackgroun
15d:!1,retry:1});if(!t)return null;const d=r?.portal||{operator_name:t,village_name:t},l=d.village_name||d.operator_name||t,g=`${Yn(t)}/visitors`,c=async()=>{await Gn(t,sessionStorage.getItem(`portal_auth_reception_${t}`)),zn(t),a(null)};return e.jsxs(e.Fragment,{children:[e.jsxs(Ja,{children:[e.jsxs("title",{children:["Reception Desk - ",l]}),e.jsx("meta",{name:"robots",content:"noindex"})]}),s?e.jsx(Rl,{slug:t,session:s,portal:d,visitorsHref:g,onLogout:c}):e.jsx(qr,{slug:t,villageName:l,logoUrl:d.logo_url,visitorsHref:g,onSuccess:a})]})}export{Qc 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.