PageSourceSearch

https://senioradvisor.co.nz/assets/PartnerPortalContentTab-Cf04Z4SM.js

js senioradvisor.co.nz collected 2026-10-09 22:04:13 UTC 37,496 bytes, 1 lines download raw bytes

1import{j as e}from"./ui-vendor-DSl4G1OJ.js";import{a as u,k as et}from"./react-vendor-JYAUlju1.js";import{j as le,Y as re,_ as pe,p as ie,q as H,a5 as tt,a6 as at,a7 as st,aA as lt,B as j,G as V,aW as rt,ax as it,D as Ae,e as Te,f as Ee,g as Le,i as De,r as ce,an as Ie,ao as Oe,ap as qe,aq as Be,ar as Ue,a2 as nt,b7 as ot}from"./index-iv8p4bGb.js";import{u as ae}from"./useMutation-CCxofYKg.js";import{I as Z}from"./input-Cbpm_RuX.js";import{T as ct}from"./textarea-BRROE69Y.js";import{B as O}from"./badge-BmcgN26q.js";import{C as dt}from"./checkbox-DrqWENIb.js";import{T as mt,a as pt,b as C,c as S}from"./tabs-Fwe9v5pI.js";import{u as ut}from"./useOperatorAdminAuth-rTm5JdCw.js";import{p as T}from"./villageAdminApi-DOJto46D.js";import{u as Ce,U as Se,S as ht,G as xt,I as gt,a as ft,F as bt}from"./ContentEditorDialogs-D_M5sumg.js";import{F as Ye}from"./FlyerTemplatePicker-DORFj8LR.js";import{F as $e}from"./FlyerCard-B5QDl4n1.js";import{C as yt}from"./ContentPreviewModal-CjXpsRn-.js";import{F as me}from"./flyerTypes-9hssLjTL.js";import{C as jt}from"./ContentBuilderWizard-OFtUYcpy.js";import{P as se}from"./PortalImage-BbpNRxd9.js";import{M as vt}from"./MaintenancePortfolioPanel-OBckEhbQ.js";import{A as Nt}from"./AuditAttributionStamp-CkHW-e4D.js";import{u as wt}from"./useAdminIntent-E1wvpJJB.js";import{E as ue}from"./eye-BYyEwTRq.js";import{P as Ve}from"./plus-CUoCthEr.js";import{S as de}from"./search-T0VyIefC.js";import{P as ke}from"./pin-xngoi13m.js";import{P as _t}from"./pencil-CNiM8VJV.js";import{C as Fe}from"./crown-A1dU65xL.js";import{N as Ge}from"./newspaper-CNavWVwr.js";import{S as Ct}from"./star-qjwcq55i.js";import{W as St}from"./wrench-Bw5Exsal.js";import{C as Me}from"./shopping-basket-BNCr6aoj.js";import{V as he}from"./wallet-DvcdSpiq.js";import{U as Ke}from"./users-DbO-ebqj.js";import{H as Re}from"./heart-pulse-DDyL749i.js";import{B as kt}from"./sticky-note-CCKGNJaT.js";import{U as Ft}from"./user-round-B4bN6HjC.js";import{B as Pt}from"./book-open-DtepqIpV.js";import{A as At}from"./align-left-C0Lwsr3G.js";import{P as Tt}from"./palette-CbfG7AQ6.js";import{C as Et}from"./calendar-days-BVXeHu32.js";import"./adminImageUpload-CiF90r15.js";import"./popover-DEdUl_IA.js";import"./ImageFocalPointPicker-CY8hNTzh.js";import"./move-DfXcQZfB.js";import"./image-up-BpSN1vfT.js";import"./book-open-text-Cyu0_dwP.js";import"./sparkles-B69mEhZg.js";import"./paw-print-C-RpNn8r.js";import"./heart-BPFyKUkJ.js";import"./cake-cNdzcpqp.js";import"./house-wtkLENOb.js";import"./heart-handshake-y3moal3U.js";import"./badge-check-6143vj-R.js";import"./map-pin-DEg-YZMi.js";import"./phone-3sP_NsCN.js";import"./image-off-C7aXBmsc.js";import"./adminUi-C-PNoBx1.js";import"./inbox-DIy2Ab5G.js";import"./lightbulb-C1BwJnva.js";import"./arrow-left-CB-rKhHH.js";import"./arrow-right-CpQyeIWr.js";import"./AdminWorkflowBoardPanel-Dx51kZml.js";import"./core.esm-B6W7VHjL.js";import"./dropdown-menu-CtK-pbB0.js";import"./circle-CYVKuV9a.js";import"./slider-LVjVMn5v.js";import"./operatorWorkflowApi-DwMjzjiG.js";import"./supabaseFunctions-Xsh4_ii9.js";import"./separator-B5XvKDXG.js";import"./maintenanceStatus-B7k7O61U.js";import"./ContractorsPanel-DbQj7qva.js";import"./SuppliersPanel-CuaaMlIO.js";import"./archive-D-wQiML4.js";import"./archive-restore-vuWKOS29.js";import"./mail-C6tfkY_l.js";import"./globe-Bj0lOFSW.js";import"./hard-hat-CxRRPxGN.js";import"./building-2-Nk2huxI0.js";import"./shield-check-DdfSfcbh.js";import"./AdminConfirmProvider-DQiZ5_dx.js";import"./earth-1jnmmksv.js";import"./shopping-cart-9WYIsMA4.js";import"./package-check-CFJTfML-.js";import"./send-BQLfd1fb.js";import"./arrow-right-left-DhgZW33C.js";import"./target-BhiqlrDH.js";import"./package-Ku2d12eQ.js";import"./maintenanceOperations-DuyrFk8x.js";import"./AdminEquipmentPanel-D-VJLJvA.js";import"./table-Dfj6cfpN.js";import"./calendar-clock-C-Thri2i.js";import"./image-CXOC1B2L.js";import"./upload-DE7_nTcl.js";import"./message-circle-question-CcWIATFu.js";import"./circle-check-CkPJ4dRt.js";import"./zoom-in-BLylRQQ9.js";import"./settings-2-CGmnlkBo.js";import"./circle-pause-CBY48RNg.js";import"./circle-play-DAzhU0nl.js";import"./queryFreshness-c8gK6bGm.js";import"./columns-3-rR1xZLzJ.js";import"./list-D-SJaLGd.js";import"./minimize-2-D441W9xs.js";import"./maximize-2-D4CQmil9.js";import"./clock-3-BrQmv96_.js";import"./filter-Cim0pAWg.js";import"./user-plus-D6130qlo.js";import"./arrow-up-right-COe01Lj2.js";import"./shield-alert-CWDHjdq3.js";import"./bell-ring-2Jr7CrB_.js";import"./ellipsis-zwecaC52.js";import"./droplets-h56iYgE4.js";import"./plug-2IBlpzDh.js";import"./leaf-DsWhn8fF.js";import"./key-round-BlddUsqF.js";function Zs(){le();const{token:s}=ut();re();const[a]=et(),[i,c]=u.useState("news"),[g,o]=u.useState(null),n=a.get("id");u.useEffect(()=>{const f=a.get("view");f?.includes("maintenance")&&c("maintenance"),f==="r-staff"&&c("staff")},[a]);const{data:y,isLoading:h}=pe({queryKey:["partner-portal-config",s],queryFn:()=>T("portals","GET",{},void 0,s)}),l=y?.portals||[],r=g?l.find(f=>f.id===g):l[0];if(!g&&l.length>0,h)return e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ie,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!r)return e.jsx(H,{children:e.jsx(ce,{className:"p-8 text-center text-muted-foreground",children:"No resident portal has been configured for your account. Please contact an administrator."})});const x=g||r.id;return e.jsxs("div",{className:"space-y-4",children:[l.length>1&&e.jsx(H,{children:e.jsx(ce,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(V,{className:"text-sm font-medium shrink-0",children:"Village:"}),e.jsxs(Ie,{value:x,onValueChange:o,children:[e.jsx(Oe,{className:"max-w-xs",children:e.jsx(qe,{})}),e.jsx(Be,{children:l.map(f=>e.jsx(Ue,{value:f.id,children:e.jsxs("span",{className:"flex items-center gap-2",children:[f.village_name||f.operator_name,f.is_default&&e.jsx(Fe,{className:"h-3 w-3 text-primary"})]})},f.id))})]})]})})}),e.jsx(H,{children:e.jsx(ce,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-8 w-8 rounded-lg flex items-center justify-center text-primary-foreground font-bold text-sm",style:{backgroundColor:r.accent_color||"#0EA5E9"},children:r.operator_name?.charAt(0)||"P"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-semibold",children:r.village_name||r.operator_name}),r.is_default&&e.jsxs(O,{variant:"default",className:"text-xs gap-1",children:[e.jsx(Fe,{className:"h-3 w-3"})," Default"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["/operators/",r.slug]})]})]})})}),e.jsxs(mt,{value:i,onValueChange:c,children:[e.jsxs(pt,{className:"flex-wrap h-auto gap-1",children:[e.jsxs(C,{value:"news",className:"gap-1",children:[e.jsx(Ge,{className:"h-3 w-3"})," News"]}),e.jsxs(C,{value:"spotlights",className:"gap-1",children:[e.jsx(Ct,{className:"h-3 w-3"})," Spotlights"]}),e.jsxs(C,{value:"maintenance",className:"gap-1",children:[e.jsx(St,{className:"h-3 w-3"})," Maintenance"]}),e.jsxs(C,{value:"gallery",className:"gap-1",children:[e.jsx(Me,{className:"h-3 w-3"})," Gallery"]}),e.jsxs(C,{value:"videos",className:"gap-1",children:[e.jsx(he,{className:"h-3 w-3"})," Videos"]}),e.jsxs(C,{value:"staff",className:"gap-1",children:[e.jsx(Ke,{className:"h-3 w-3"})," Directory"]}),e.jsxs(C,{value:"wellness",className:"gap-1",children:[e.jsx(Re,{className:"h-3 w-3"})," Wellness"]}),e.jsxs(C,{value:"suggestions",className:"gap-1",children:[e.jsx(nt,{className:"h-3 w-3"})," Suggestions"]}),e.jsxs(C,{value:"agents",className:"gap-1",children:[e.jsx(kt,{className:"h-3 w-3"})," Agents"]})]}),e.jsx(S,{value:"news",children:e.jsx(I,{portalId:x,entity:"news",label:"News",siblingCount:l.length,authToken:s})}),e.jsx(S,{value:"spotlights",children:e.jsx(I,{portalId:x,entity:"spotlights",label:"Spotlights",siblingCount:l.length,authToken:s})}),e.jsx(S,{value:"maintenance",children:e.jsx(vt,{authToken:s})}),e.jsx(S,{value:"gallery",children:e.jsx(I,{portalId:x,entity:"gallery_albums",label:"Gallery Albums",siblingCount:l.length,authToken:s,openItemId:i==="gallery"?n:null})}),e.jsx(S,{value:"videos",children:e.jsx(I,{portalId:x,entity:"videos",label:"Videos",siblingCount:l.length,authToken:s,openItemId:i==="videos"?n:null})}),e.jsx(S,{value:"staff",className:"pt-4",children:e.jsx(I,{portalId:x,entity:"staff",label:"Staff Directory",siblingCount:l.length,authToken:s,openItemId:i==="staff"?n:null,staffDirectoryStyle:r.feature_flags?.staff_directory_style,portalFeatureFlags:r.feature_flags||{}})}),e.jsx(S,{value:"wellness",children:e.jsx(I,{portalId:x,entity:"wellness",label:"Wellness Tips",siblingCount:l.length,authToken:s})}),e.jsx(S,{value:"suggestions",children:e.jsx(I,{portalId:x,entity:"suggestions",label:"Suggestions",readonly:!0,authToken:s})}),e.jsx(S,{value:"agents",children:e.jsx(Vt,{portalId:x,authToken:s})})]})]})}function Lt({portalId:s,authToken:a,currentStyle:i,featureFlags:c={}}){const{toast:g}=le(),o=re(),[n,y]=u.useState(!1),h=me.some(b=>b.value===i)?i:"classic",[l,r]=u.useState(h),[x,f]=u.useState(h),[G,p]=u.useState(!1);u.useEffect(()=>{const b=me.some(q=>q.value===i)?i:"classic";f(b),n||r(b)},[i,n]);const k=ae({mutationFn:()=>T("portals","PUT",{id:s},{id:s,feature_flags:{...c,staff_directory_style:l}},a),onSuccess:()=>{o.invalidateQueries({queryKey:["partner-portal-config",a]}),o.invalidateQueries({queryKey:["admin-portals-list",a]}),o.invalidateQueries({queryKey:["portal"]}),f(l),g({title:"Staff directory template saved",description:"The layout now applies to every staff profile."}),y(!1)},onError:b=>g({title:"Error",description:b.message==="Admin only"?"System Admin & Village Admin only":b.message,variant:"destructive"})});return e.jsxs(e.Fragment,{children:[e.jsxs(j,{size:"sm",variant:"outline",className:"gap-1.5",onClick:()=>{r(x),y(!0)},children:[e.jsx(Ke,{className:"h-3.5 w-3.5"})," Templates"]}),e.jsx(Ae,{open:n,onOpenChange:y,children:e.jsxs(Te,{className:"max-h-[90vh] max-w-3xl overflow-y-auto",children:[e.jsx(Ee,{children:e.jsx(Le,{children:"Staff directory template"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose from the same flyer layouts used by Spotlights. O
1ne selection applies to every existing and future staff card."}),e.jsx(Ye,{value:l,onChange:r}),e.jsxs(j,{type:"button",variant:"outline",size:"sm",className:"w-fit gap-1.5",onClick:()=>p(!0),children:[e.jsx(ue,{className:"h-3.5 w-3.5"})," Preview"]}),e.jsxs(De,{children:[e.jsx(j,{variant:"ghost",onClick:()=>y(!1),children:"Cancel"}),e.jsxs(j,{onClick:()=>k.mutate(),disabled:k.isPending,children:[k.isPending&&e.jsx(ie,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Save for all cards"]})]})]})}),e.jsx(yt,{open:G,onOpenChange:p,label:"Staff directory preview",children:e.jsx(Dt,{style:l||x})})]})}function Dt({style:s}){const a=[{name:"Margaret Reid",role:"Village Manager",bio:"Here for anything roster, billing, or move-in related.",phone:"09 555 0142"},{name:"Tom Ngata",role:"Wellness Nurse",bio:"Available weekdays for health and medication queries.",phone:"09 555 0188"}];return e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:a.map(i=>e.jsx($e,{compact:!0,template:s,title:i.name,subtitle:i.role,body:i.bio,category:"Staff",contact:i.phone},i.name))})}function It({fields:s,values:a,onChange:i,portalId:c,authToken:g,entity:o,supportsFlyer:n,flyerPreview:y}){const h=n??s.some(l=>l.type==="flyer_template");return e.jsx(e.Fragment,{children:s.map(l=>e.jsx("div",{className:"space-y-1",children:l.type==="image"?e.jsxs(e.Fragment,{children:[e.jsx(gt,{portalId:c,authToken:g,folder:"content",label:l.label,aspect:l.aspect,value:a[l.key]||"",onChange:r=>i({...a,[l.key]:r})}),h&&a[l.key]&&a.layout_template&&e.jsx(ft,{imageUrl:a[l.key],imageFocalX:a.image_focal_x?Number(a.image_focal_x):50,imageFocalY:a.image_focal_y?Number(a.image_focal_y):50,imageFitContain:a.image_fit_contain==="true",aspect:me.find(r=>r.value===a.layout_template)?.aspect||"16:9",onChange:r=>i({...a,image_focal_x:String(r.imageFocalX),image_focal_y:String(r.imageFocalY),image_fit_contain:String(r.imageFitContain)})})]}):l.type==="flyer_template"?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"text-sm",children:l.label}),e.jsx(Ye,{value:a[l.key]||"classic",onChange:r=>i({...a,[l.key]:r}),previewContent:y}),a[l.key]&&e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>i({...a,[l.key]:""}),children:"Use plain card instead"}),a[l.key]&&e.jsx(bt,{value:a.accent_color||null,onChange:r=>i({...a,accent_color:r||""})})]}):l.type==="date"?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"text-sm",children:l.label}),e.jsx(Z,{type:"date",value:a[l.key]||"",onChange:r=>i({...a,[l.key]:r.target.value})})]}):l.type==="select"?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"text-sm",children:l.label}),e.jsxs(Ie,{value:a[l.key]||void 0,onValueChange:r=>i({...a,[l.key]:r}),children:[e.jsx(Oe,{children:e.jsx(qe,{placeholder:`Choose ${l.label.toLocaleLowerCase("en-NZ")}`})}),e.jsx(Be,{children:(l.options||[]).map(r=>e.jsx(Ue,{value:r.value,children:r.label},r.value))})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"text-sm",children:l.label}),l.type==="textarea"?e.jsx(ct,{value:a[l.key]||"",onChange:r=>i({...a,[l.key]:r.target.value}),rows:l.rows||3,placeholder:l.placeholder}):e.jsx(Z,{value:a[l.key]||"",onChange:r=>i({...a,[l.key]:r.target.value}),placeholder:l.placeholder}),l.help&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.help})]})},l.key))})}const Ot={news:{icon:Ge,summary:"You're writing a Village News story — a short update residents will read and can have read aloud.",appearsIn:"Notice board → Village News on the resident app, the Newsletter Builder and the village display screens.",tips:["Lead with the most important sentence.","Add a photo and a flyer layout to make it stand out."]},wellness:{icon:Re,summary:"You're adding a wellness tip — practical, encouraging advice for everyday wellbeing.",appearsIn:"Wellbeing on the resident and family apps.",tips:["Keep it to one idea residents can try today.","Avoid medical advice — point to the nurse or GP instead."]},articles:{icon:Pt,summary:"You're adding an article for the Reading Lounge.",appearsIn:"Reading Lounge on the resident app.",tips:["Save as draft first if someone needs to check it."]},videos:{icon:he,summary:"You're adding a YouTube video for residents to wat
1ch.",appearsIn:"Media & Memories → Village Videos on the resident app.",tips:["Use a standard YouTube link.","Leave the thumbnail empty to use YouTube's own picture."]},staff:{icon:Ft,summary:"You're updating the public staff directory card residents and families see.",appearsIn:"Staff directory on the resident and family apps.",tips:["Name, role, photo and active status come from Staff 360. This card adds the public bio and contact number."]}},qt={title:{placeholder:"A clear, short headline"},subtitle:{placeholder:"One line that adds context",help:"Optional — shown under the title."},body:{rows:8,placeholder:"Write the full text here…"},display_date:{help:"Optional — the date shown on the flyer, e.g. the event day."},url:{placeholder:"https://www.youtube.com/watch?v=…"},contact_number:{placeholder:"e.g. 03 555 0123"},bio:{rows:6,placeholder:"A friendly introduction residents will see"},status:{help:'Type "draft" to keep it hidden, or "published" to show it.'}};function Bt(s,a){return["news","wellness","articles","videos"].includes(s)&&!a.title?.trim()?"Add a title to continue.":s==="news"&&!a.body?.trim()?"Add the story text to continue.":s==="videos"&&!a.url?.trim()?"Add the YouTube link to continue.":null}function Pe({open:s,onRequestClose:a,mode:i,entity:c,label:g,fields:o,values:n,onChange:y,portalId:h,authToken:l,onSubmit:r,submitting:x,disperseControl:f,previewForm:G}){const p=m=>({...qt[m.key],...m}),k=o.some(m=>m.type==="flyer_template"),b=o.filter(m=>!m.type||m.type==="select").filter(m=>!["body","bio"].includes(m.key)).map(p),q=o.filter(m=>m.type==="textarea"||["body","bio"].includes(m.key)).map(p),E=o.filter(m=>m.type==="image").map(p),B=o.filter(m=>m.type==="flyer_template").map(p),F=o.filter(m=>m.type==="date").map(p),M=Bt(c,n),U=Ot[c]||{icon:Ve,summary:`You're ${i==="add"?"adding":"editing"} ${g.toLowerCase()}.`},P={title:n.title||"Title",subtitle:n.subtitle,body:n.body||"The text will appear here…",dateLabel:te(n.display_date),imageUrl:n.image_url,imageFocalX:n.image_focal_x?Number(n.image_focal_x):50,imageFocalY:n.image_focal_y?Number(n.image_focal_y):50,imageFitContain:n.image_fit_contain==="true",accentColor:n.accent_color||null},w=m=>e.jsx(It,{fields:m,values:n,onChange:y,portalId:h,authToken:l,entity:c,supportsFlyer:k,flyerPreview:P}),L=["news","wellness","articles","videos"].includes(c)&&!n.title?.trim()?"Add a title to continue.":c==="videos"&&!n.url?.trim()?"Add the YouTube link to continue.":null,X=[b.length>0&&{id:"basics",label:"Basics",icon:ot,description:"Start with the headline details.",blocker:L,content:w(b)},q.length>0&&{id:"words",label:c==="staff"?"Bio":"Words",icon:At,description:"Write the main text. Short paragraphs are easiest to read.",blocker:c==="news"&&!n.body?.trim()?"Add the story text to continue.":null,content:w(q)},E.length>0&&{id:"media",label:"Photo",icon:Me,optional:!0,description:"Add a photo or picture. Only use images you have permission to share.",content:w(E)},B.length>0&&{id:"design",label:"Design",icon:Tt,optional:!0,description:"Choose a flyer layout — each option shows your real content — and a colour.",content:w(B)},(F.length>0||f)&&{id:"dates",label:"Dates & sharing",icon:Et,optional:!0,description:"Set the date shown and where it goes.",content:e.jsxs(e.Fragment,{children:[w(F),f]})}].filter(Boolean),v=G||n,K=k?e.jsx(Yt,{form:v}):e.jsx($t,{entity:c,form:v,authToken:l});return e.jsx(jt,{open:s,onRequestClose:a,title:`${i==="add"?"Add":"Edit"} ${g}`,icon:U.icon,intro:U,steps:X,preview:K,previewLabel:`${g} preview`,submitLabel:i==="add"?"Save":"Save changes",onSubmit:r,submitting:x,submitBlocker:M,allowSaveFromAnyStep:i==="edit"})}function te(s){if(s)try{return new Date(`${s}T00:00:00`).toLocaleDateString("en-NZ",{weekday:"long",day:"numeric",month:"long",year:"numeric"})}catch{return}}function I({portalId:s,entity:a,label:i,readonly:c,siblingCount:g,authToken:o,openItemId:n,staffDirectoryStyle:y,portalFeatureFlags:h,canManageStaffDirectoryTemplate:l=!1}){const{toast:r}=le(),x=re(),{data:f,isLoading:G}=pe({queryKey:["partner-portal",a,s,o],queryFn:()=>T(a,"GET",{portal_id:s},void 0,o)}),p=f?.items||[],k=ae({mutationFn:t=>
1T(a,"DELETE",{id:t},void 0,o),onSuccess:()=>{x.invalidateQueries({queryKey:["partner-portal",a,s,o]}),r({title:"Deleted"})}}),b=ae({mutationFn:({id:t,updates:d})=>T(a,"PUT",{id:t},d,o),onSuccess:()=>{x.invalidateQueries({queryKey:["partner-portal",a,s,o]}),r({title:"Updated"})}}),[q,E]=u.useState(!1),[B,F]=u.useState({}),[M,U]=u.useState(!1),[P,w]=u.useState(null),[L,X]=u.useState({}),[v,K]=u.useState(null),[m,Y]=u.useState(""),[R,xe]=u.useState("all"),[J,ge]=u.useState("all"),$={news:[{key:"title",label:"Title"},{key:"subtitle",label:"Subtitle (optional)"},{key:"display_date",label:"Date (optional)",type:"date"},{key:"body",label:"Body",type:"textarea"},{key:"image_url",label:"Image",type:"image"},{key:"layout_template",label:"Flyer layout",type:"flyer_template"}],spotlights:[{key:"person_name",label:"Name"}],gallery_albums:[{key:"title",label:"Title"}],articles:[{key:"title",label:"Title"},{key:"body",label:"Body",type:"textarea"},{key:"image_url",label:"Image",type:"image"},{key:"status",label:"Status (draft/published)"}],wellness:[{key:"title",label:"Title"},{key:"subtitle",label:"Subtitle (optional)"},{key:"display_date",label:"Date (optional)",type:"date"},{key:"body",label:"Body",type:"textarea"},{key:"image_url",label:"Image (optional)",type:"image"},{key:"layout_template",label:"Flyer layout",type:"flyer_template"}],videos:[{key:"title",label:"Title"},{key:"url",label:"YouTube URL"},{key:"category",label:"Category",type:"select",options:[{value:"village-memories",label:"Village Memories"},{value:"village-updates",label:"Village Updates"},{value:"getting-started",label:"Getting Started"},{value:"tutorials",label:"How-to Guides"},{value:"wellbeing",label:"Wellbeing"},{value:"exercise",label:"Exercise"}]},{key:"thumbnail_url",label:"Thumbnail",type:"image"}],staff:[{key:"contact_number",label:"Public contact number"},{key:"bio",label:"Public bio",type:"textarea"}]}[a]||[],ne=!c&&$.length>0,fe=a==="spotlights"||a==="gallery_albums",[A,W]=u.useState(null),be=wt("new");u.useEffect(()=>{be===0||c||a==="staff"||(a==="spotlights"||a==="gallery_albums"?W("new"):(F(a==="videos"?{category:"village-memories"}:{}),E(!0)))},[a,be,c]);const We=$.some(t=>t.type==="flyer_template"),[Qe,ze]=u.useState({}),oe=a==="news"||a==="gallery_albums"?p.filter(t=>{const d=m.trim().toLocaleLowerCase("en-NZ"),N=a==="gallery_albums"?[t.title,t.description,t.event_date]:[t.title,t.subtitle,t.body];return d&&!N.some(_=>String(_||"").toLocaleLowerCase("en-NZ").includes(d))?!1:a==="gallery_albums"?J==="active"?t.status==="active"||t.status==="published":J==="archived"?t.status==="archived":!0:R==="pinned"?t.is_pinned===!0:R==="active"?t.status==="active"||t.status==="published":R==="archived"?t.status==="archived":!0}):p.filter(t=>{const d=m.trim().toLocaleLowerCase("en-NZ");return d?[t.title,t.name,t.person_name,t.role,t.subtitle,t.description,t.body,t.bio,t.category].some(N=>String(N||"").toLocaleLowerCase("en-NZ").includes(d)):!0}),ye=a==="news"||a==="gallery_albums",je=a==="wellness",ve=t=>je?t.is_active===!1:t.status&&t.status!=="active"&&t.status!=="published",He=t=>{if(je)b.mutate({id:t.id,updates:{is_active:!t.is_active}});else{const d=ve(t)?a==="articles"?"published":"active":"archived";b.mutate({id:t.id,updates:{status:d}})}},Ne=t=>b.mutate({id:t.id,updates:{is_pinned:!t.is_pinned}}),ee=t=>{if(fe){W(t);return}const d={};$.forEach(N=>{d[N.key]=t[N.key]??""}),We&&(d.image_focal_x=t.image_focal_x!=null?String(t.image_focal_x):"",d.image_focal_y=t.image_focal_y!=null?String(t.image_focal_y):"",d.image_fit_contain=String(!!t.image_fit_contain),d.accent_color=t.accent_color||""),X(d),ze(d),w(t)};u.useEffect(()=>{if(!n||!p.length||P||v||A)return;const t=p.find(d=>d.id===n);t&&(ne?ee(t):K(t))},[n,p,P,v,A,ne]);const we=()=>{P&&b.mutate({id:P.id,updates:L},{onSuccess:()=>w(null)})},Ze=Object.values(B).some(t=>t),Xe=JSON.stringify(L)!==JSON.stringify(Qe),Q=Ce(()=>{E(!1),F({}),U(!1)}),z=Ce(()=>w(null)),Je=t=>{if(!t)return"";try{return new Date(t).toLocaleDateString("en-NZ",{weekday:"short",day:"numeric",month:"short",year:"numeric"})}catch{return""}},_e=async()=>{try{const t={};M&&(t.disperse="true"),await T(a,"POST",t,{portal_id:s,...B},o),x.invalidateQueries({queryKey:["partner-portal",a,s,o]}),E(!1),F({}),U(!1),r({title:M?"Sent to all villages":"Added"})}catch(t){r({title:"Error",description:t.message,variant:"destructive"})}};return G?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(ie,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[m||a==="news"&&R!=="all"||a==="gallery_albums"&&J!=="all"?`${oe.length} of ${p.length}`:p.length," items"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[!c&&a==="staff"&&l&&e.jsx(Lt,{portalId:s,authToken:o,currentStyle:y,featureFlags:h}),!c&&$.length>0&&a!=="staff"&&e.jsxs(j,{size:"sm",variant:"outline",onClick:()=>{fe?W("new"):(F(a==="videos"?{category:"village-memories"}:{}),E(!0))},className:"gap-1",children:[e.jsx(Ve,{className:"h-3 w-3"})," Add"]})]})]}),a==="staff"&&e.jsx("div",{className:"rounded-lg border border-sky-200 bg-sky-50 p-3 text-sm text-sky-950 dark:border-sky-900 dark:bg-sky-950/30 dark:text-sky-100",children:"Staff 360 manages each person's name, role, photo and active status. This directory manages only the bio and contact number shown to residents and families."}),a==="news"&&e.jsxs("div",{className:"grid gap-3 rounded-xl border bg-card/60 p-3 sm:grid-cols-[minmax(0,1fr)_180px]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(de,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Z,{value:m,onChange:t=>Y(t.target.value),"data-update-transient":"true",placeholder:"Search news by title or text","aria-label":"Search village news",className:"pl-9"})]}),e.jsxs("select",{value:R,onChange:t=>xe(t.target.value),"aria-label":"Filter village news",className:"h-10 rounded-md border border-input bg-background px-3 text-sm",children:[e.jsx("option",{value:"all",children:"All news"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"pinned",children:"Pinned"}),e.jsx("option",{value:"archived",children:"Archived"})]})]}),a==="gallery_albums"&&e.jsxs("div",{className:"grid gap-3 rounded-xl border bg-card/60 p-3 sm:grid-cols-[minmax(0,1fr)_180px]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(de,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Z,{value:m,onChange:t=>Y(t.target.value),"data-update-transient":"true",placeholder:"Search albums by title or description","aria-label":"Search gallery albums",className:"pl-9"})]}),e.jsxs("select",{value:J,onChange:t=>ge(t.target.value),"aria-label":"Filter gallery albums",className:"h-10 rounded-md border border-input bg-background px-3 text-sm",children:[e.jsx("option",{value:"all",children:"All albums"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"archived",children:"Archived"})]})]}),!ye&&p.length>0&&e.jsxs("div",{className:"relative rounded-xl border bg-card/60 p-3",children:[e.jsx(de,{className:"absolute left-6 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Z,{value:m,onChange:t=>Y(t.target.value),placeholder:`Search ${i.toLowerCase()}`,"aria-label":`Search ${i.toLowerCase()}`,className:"pl-9"})]}),e.jsx(Pe,{open:q,onRequestClose:()=>Q.attemptClose(Ze),mode:"add",entity:a,label:i,fields:$,values:B,onChange:F,portalId:s,authToken:o,onSubmit:_e,disperseControl:(g||0)>1?e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border p-3",children:[e.jsx(dt,{id:`partner-disperse-${a}`,checked:M,onCheckedChange:t=>U(!!t)}),e.jsx(V,{htmlFor:`partner-disperse-${a}`,className:"text-sm cursor-pointer",children:"Send to all villages"})]}):void 0}),e.jsx(Se,{open:Q.promptOpen,onOpenChange:Q.setPromptOpen,onDiscard:Q.discard,onSave:()=>{Q.setPromptOpen(!1),_e()}}),oe.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{children:p.length===0?`No ${i.toLowerCase()}
1 yet.`:a==="gallery_albums"?"No albums match this search or filter.":a==="news"?"No news matches this search or filter.":`No ${i.toLowerCase()} match “${m}”.`}),!ye&&p.length>0&&e.jsx(j,{type:"button",variant:"link",onClick:()=>Y(""),children:"Clear search"}),a==="news"&&p.length>0&&e.jsx(j,{type:"button",variant:"link",onClick:()=>{Y(""),xe("all")},children:"Show all news"}),a==="gallery_albums"&&p.length>0&&e.jsx(j,{type:"button",variant:"link",onClick:()=>{Y(""),ge("all")},children:"Show all albums"})]}):e.jsx("div",{className:"space-y-2",children:oe.map(t=>{const d=a==="news"&&t.display_date?t.display_date:t.published_at||t.created_at,N=ve(t),_=ne;return e.jsx(H,{className:`p-3 transition-colors ${_?"cursor-pointer hover:bg-accent/40":""} ${N?"opacity-60":""}`,onClick:()=>_&&ee(t),role:_?"button":void 0,tabIndex:_?0:void 0,onKeyDown:D=>{_&&(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),ee(t))},children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[(t.photo_url||t.cover_url||t.image_url||t.thumbnail_url)&&e.jsx(se,{src:t.photo_url||t.cover_url||t.image_url||t.thumbnail_url,authToken:o,alt:"",className:`h-10 w-10 shrink-0 object-cover ${a==="spotlights"||a==="staff"?"rounded-full":"rounded-md"} border`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:t.title||t.person_name||t.name||t.message?.slice(0,60)||t.issue_type||"Item"}),e.jsxs("div",{className:"flex gap-2 mt-1 flex-wrap items-center",children:[a==="news"&&t.subtitle&&e.jsx("span",{className:"line-clamp-1 basis-full text-sm text-muted-foreground",children:t.subtitle}),a==="staff"&&t.role&&e.jsx(O,{variant:"outline",className:"text-xs",children:t.role}),a==="staff"&&t.staff_user_id&&e.jsx(O,{variant:"secondary",className:"text-xs",children:"Linked to Staff 360"}),t.status&&e.jsx(O,{variant:"outline",className:"text-xs",children:t.status}),t.is_pinned&&e.jsx("button",{onClick:D=>{D.stopPropagation(),Ne(t)},title:"Click to unpin",className:"inline-flex",children:e.jsxs(O,{variant:"secondary",className:"text-xs gap-1 hover:bg-destructive/10 hover:text-destructive",children:[e.jsx(ke,{className:"h-3 w-3"})," Pinned"]})}),d&&e.jsx("span",{className:"text-xs text-muted-foreground",children:Je(d)}),t.audit_stamp&&e.jsx("span",{className:"basis-full pt-1",children:e.jsx(Nt,{value:t.audit_stamp,compact:!0})}),a==="news"&&t.body&&e.jsx("p",{className:"line-clamp-2 basis-full text-sm text-muted-foreground",children:t.body}),a==="gallery_albums"&&t.description&&e.jsx("p",{className:"line-clamp-2 basis-full text-sm text-muted-foreground",children:t.description})]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",onClick:D=>D.stopPropagation(),children:[a==="news"&&!t.is_pinned&&!c&&e.jsx(j,{size:"sm",variant:"ghost",title:"Pin",onClick:()=>Ne(t),children:e.jsx(ke,{className:"h-3 w-3"})}),_&&e.jsx(j,{size:"sm",variant:"ghost",title:"Edit",onClick:()=>ee(t),children:e.jsx(_t,{className:"h-3 w-3"})}),_&&(a!=="staff"||!t.staff_user_id)&&e.jsx(j,{size:"sm",variant:"ghost",title:N?"Enable":"Disable",onClick:()=>He(t),children:N?e.jsx(ue,{className:"h-3 w-3"}):e.jsx(rt,{className:"h-3 w-3"})}),!c&&(a!=="staff"||!t.staff_user_id)&&e.jsx(j,{size:"sm",variant:"ghost",className:"text-destructive",title:"Delete",onClick:()=>k.mutate(t.id),children:e.jsx(it,{className:"h-3 w-3"})})]})]})},t.id)})}),e.jsx(Pe,{open:!!P,onRequestClose:()=>z.attemptClose(Xe),mode:"edit",entity:a,label:i,fields:$,values:L,onChange:X,portalId:s,authToken:o,onSubmit:we,submitting:b.isPending,previewForm:a==="staff"?{...P,...L}:L}),e.jsx(Se,{open:z.promptOpen,onOpenChange:z.setPromptOpen,onDiscard:z.discard,onSave:()=>{z.setPromptOpen(!1),we()},saving:b.isPending}),e.jsx(Ae,{open:!!v,onOpenChange:t=>{t||K(null)},children:e.jsxs(Te,{className:"max-w-lg",children:[e.jsx(Ee,{children:e.jsxs(Le,{children:[i," detail"]})}),v&&e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsx("p",{className:"font-medium text-foreground",children:v.title||v.person_name||v.name||v.issue_type||"Item"}),Object.entries(v).filter(([t,d])=>d!=null&&d!==""&&!["id","portal_id","agent_id"].includes(t)).slice(0,12).map(([t,d])=>e.jsxs("div",{className:"border-t pt-2",children:[e.jsx("p",{className:"text-xs uppercase text-muted-foreground",children:t.replace(/_/g," ")}),e.jsx("p",{className:"break-words text-foreground",children:typeof d=="object"?JSON.stringify(d,null,2):String(d)})]},t))]}),e.jsx(De,{children:e.jsx(j,{variant:"outline",onClick:()=>K(null),children:"Close"})})]})}),a==="spotlights"&&e.jsx(ht,{open:!!A,onOpenChange:t=>{t||W(null)},portalId:s,authToken:o,item:A==="new"?null:A,siblingCount:g,onSaved:()=>x.invalidateQueries({queryKey:["partner-portal",a,s,o]})}),a==="gallery_albums"&&e.jsx(xt,{open:!!A,onOpenChange:t=>{t||W(null)},portalId:s,authToken:o,item:A==="new"?null:A,onSaved:()=>x.invalidateQueries({queryKey:["partner-portal",a,s,o]})})]})}function Ut(s){if(!s)return null;const a=s.match(/(?:youtube\.com\/(?:watch\?.*v=|shorts\/|embed\/)|youtu\.be\/)([\w-]{6,})/);return a?`https://img.youtube.com/vi/${a[1]}/hqdefault.jpg`:null}function Yt({form:s}){return s.layout_template?e.jsx($e,{template:s.layout_template,title:s.title||"Title",subt
1itle:s.subtitle,body:s.body||"The text will appear here…",dateLabel:te(s.display_date),imageUrl:s.image_url,imageFocalX:s.image_focal_x?Number(s.image_focal_x):50,imageFocalY:s.image_focal_y?Number(s.image_focal_y):50,imageFitContain:s.image_fit_contain==="true",accentColor:s.accent_color||null}):e.jsxs("div",{className:"overflow-hidden rounded-xl border bg-card shadow-sm",children:[s.image_url&&e.jsx(se,{src:s.image_url,alt:"",className:"max-h-48 w-full object-cover"}),e.jsxs("div",{className:"p-4",children:[e.jsx("p",{className:"font-semibold",children:s.title||"Title"}),s.subtitle&&e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:s.subtitle}),te(s.display_date)&&e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:te(s.display_date)}),s.body&&e.jsx("p",{className:"mt-2 whitespace-pre-wrap text-sm text-muted-foreground",children:s.body})]})]})}function $t({entity:s,form:a,authToken:i}){if(s==="staff")return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase text-muted-foreground",children:"Preview"}),e.jsxs("div",{className:"flex items-start gap-3 rounded-xl border bg-card p-3 shadow-sm",children:[a.photo_url?e.jsx(se,{src:a.photo_url,authToken:i,alt:"",className:"h-14 w-14 rounded-full border object-cover"}):e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-full bg-primary/10 text-lg font-semibold text-primary",children:(a.name||"?").charAt(0)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold",children:a.name||"Name"}),a.role&&e.jsx(O,{variant:"secondary",className:"mt-0.5 text-[10px]",children:a.role}),a.contact_number&&e.jsx("p",{className:"mt-1 text-sm font-medium text-primary",children:a.contact_number}),a.bio&&e.jsx("p",{className:"mt-1 line-clamp-3 text-sm text-muted-foreground",children:a.bio})]})]})]});if(s==="videos"){const c=a.thumbnail_url||Ut(a.url);return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase text-muted-foreground",children:"Preview"}),e.jsxs("div",{className:"max-w-sm overflow-hidden rounded-xl border bg-card shadow-sm",children:[e.jsxs("div",{className:"relative aspect-video bg-muted",children:[c?e.jsx("img",{src:c,alt:"",className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:e.jsx(he,{className:"h-8 w-8"})}),e.jsx("span",{className:"absolute inset-0 m-auto flex h-10 w-10 items-center justify-center rounded-full bg-black/60 text-white",children:"▶"})]}),e.jsxs("div",{className:"p-3",children:[e.jsx("p",{className:"font-semibold",children:a.title||"Video title"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[a.category&&e.jsx(O,{variant:"outline",className:"text-[10px]",children:a.category}),!a.thumbnail_url&&c&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"thumbnail from YouTube link"})]})]})]})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase text-muted-foreground",children:"Preview"}),e.jsxs("div",{className:"overflow-hidden rounded-xl border bg-card shadow-sm",children:[a.image_url&&e.jsx(se,{src:a.image_url,authToken:i,alt:"",className:"max-h-40 w-full object-cover"}),e.jsxs("div",{className:"p-3",children:[e.jsx("p",{className:"font-semibold",children:a.title||"Title"}),a.body&&e.jsx("p",{className:"mt-1 line-clamp-4 whitespace-pre-wrap text-sm text-muted-foreground",children:a.body})]})]})]})}function Vt({portalId:s,authToken:a}){const{toast:i}=le(),c=re(),{data:g,isLoading:o}=pe({queryKey:["partner-portal","portal_agents",s,a],queryFn:()=>T("portal_agents","GET",{portal_id:s},void 0,a)}),n=g?.items||[],y=ae({mutationFn:({id:h,is_visible:l})=>T("portal_agents","PUT",{id:h},{is_visible:l},a),onSuccess:()=>{c.invalidateQueries({queryKey:["partner-portal","portal_agents",s,a]}),i({title:"Visibility updated"})},onError:h=>i({title:"Error",description:h.message,variant:"destructive"})});return o?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(ie,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No agents have been assigned to this portal by an administrator."}):e.jsxs("div",{className:"space-y-2 pt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Toggle which agents are visible to residents on your portal."}),n.map(h=>{const l=h.agents||{};return e.jsx(H,{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(tt,{className:"h-8 w-8",children:[e.jsx(at,{src:l.avatar_url||void 0}),e.jsx(st,{className:"text-xs",children:l.name?.charAt(0)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-foreground truncate",children:l.name||h.agent_id}),l.title&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:l.title})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ue,{className:"h-3 w-3 text-muted-foreground"}),e.jsx(lt,{checked:h.is_visible,onCheckedChange:r=>y.mutate({id:h.id,is_visible:r})})]})]})},h.id)})]})}export{Vt as PartnerAgentsTab,I as PartnerContentList,Zs as PartnerPortalContentTab};

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.