PageSourceSearch

https://www.faithassembly.org.uk/assets/ServiceManager-DRr4Asr0.js

js faithassembly.org.uk collected 2026-09-25 13:55:31 UTC 12,127 bytes, 1 lines download raw bytes

1import{r as c,j as e,ag as d}from"./vendor-BFIOfVip.js";import{bq as u,b as D,a2 as O,a1 as U,eg as _,bs as p,bt as P,eh as z,a9 as B,f as J,g as K}from"./vendor-icons-BjlO8Ivt.js";import{a as V,k as W,C as G,E as Q,I as X,J as Y,u as H,K as Z,j as ee,l as te}from"./vendor-firebase-dJP658Hw.js";const ne=()=>{const[f,A]=c.useState([]),[T,y]=c.useState(!0),[F,g]=c.useState(!1),[h,j]=c.useState(!1),[N,v]=c.useState(null),[a,n]=c.useState({title:"",date:"",time:"",location:"",segments:[]}),[i,m]=c.useState({time:"",title:"",anchor:""}),[o,x]=c.useState(null),b=V(),w=W(b,"servicePlans");c.useEffect(()=>{const t=G(w,Q("date","desc")),s=X(t,r=>{const l=r.docs.map(E=>({id:E.id,...E.data()}));A(l),y(!1)},r=>{console.error("Error fetching services:",r),d.error("Failed to load service plans"),y(!1)});return()=>s()},[]);const S=()=>{n({title:"",date:"",time:"",location:"Main Sanctuary",segments:[]}),m({time:"",title:"",anchor:""}),x(null),j(!1),v(null)},I=t=>{n({title:t.title,date:t.date,time:t.time||"",location:t.location||"",segments:t.segments||[]}),v(t.id),j(!0),g(!0)},M=async t=>{if(window.confirm("Are you sure you want to delete this service plan?"))try{await Y(H(b,"servicePlans",t)),d.success("Service plan deleted")}catch(s){console.error("Delete error:",s),d.error("Failed to delete")}},k=()=>{if(!i.time||!i.title){d.error("Please fill in both time and title for the segment");return}o!==null?(n(t=>{const s=[...t.segments];return s[o]=i,{...t,segments:s}}),x(null),d.success("Segment updated")):n(t=>({...t,segments:[...t.segments,i]})),m({time:"",title:"",anchor:""})},L=t=>{const s=a.segments[t];m(s),x(t)},R=t=>{n(s=>({...s,segments:s.segments.filter((r,l)=>l!==t)})),o===t&&(x(null),m({time:"",title:"",anchor:""}))},C=(t,s)=>{n(r=>{const l=[...r.segments];return s==="up"&&t>0?[l[t],l[t-1]]=[l[t-1],l[t]]:s==="down"&&t<l.length-1&&([l[t],l[t+1]]=[l[t+1],l[t]]),{...r,segments:l}})},$=()=>{n(t=>({...t,segments:[...t.segments].sort((s,r)=>s.time.localeCompare(r.time))})),d.success("Segments sorted by time")},q=async t=>{t.preventDefault();try{const s={...a,updatedAt:new Date().toISOString()};h&&N?(await Z(H(b,"servicePlans",N),s),d.success("Service plan updated successfully!")):(await ee(w,{...s,createdAt:te()}),d.success("Service plan created successfully!")),g(!1),S()}catch(s){console.error("Error saving service:",s),d.error("Failed to save service plan")}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-800",children:"Service Manager"}),e.jsx("p",{className:"text-slate-500",children:"Plan and manage upcoming church services."})]}),e.jsxs("button",{onClick:()=>{S(),g(!0)},className:"bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 flex items-center gap-2 transition",children:[e.jsx(u,{})," New Service"]})]}),e.jsx("div",{className:"grid gap-4",children:T?e.jsx("p",{className:"text-gray-500",children:"Loading plans..."}):f.length===0?e.jsxs("div",{className:"bg-white p-8 rounded-xl border border-dashed border-gray-300 text-center",children:[e.jsx(D,{className:"mx-auto text-4xl text-gray-300 mb-2"}),e.jsx("p",{className:"text-gray-500",children:"No service plans found. Create one to get started."})]}):f.map(t=>e.jsx("div",{className:"bg-white p-6 rounded-xl shadow-sm border border-slate-200",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-2",children:[e.jsxs("span",{className:"bg-blue-100 text-blue-700 px-3 py-1 rounded-full text-sm font-semibold flex items-center",children:[e.jsx(D,{className:"mr-1"}),new Date(t.date).toLocaleDateString(void 0,{weekday:"long",year:"numeric",month:"long",day:"numeric"})]}),e.jsxs("span",{className:"text-slate-500 text-sm flex items-center",children:[e.jsx(O,{className:"mr-1"}),t.time]}),e.jsxs("span",{className:"text-slate-500 text-sm flex items-center",children:[e.jsx(U,{className:"mr-1"}),t.location]})]}),e.jsx("h3",{className:"text-xl font-bold text-gray-900 mb-2",children:t.title}),t.segments&&t.segments.length>0&&e.jsxs("div",{className:"mt-4 bg-gray-50 p-4 rounded-lg",children:[e.jsxs("h4",{className:"text-sm font-semibold text-gray-700 mb-2 flex items-center",children:[e.jsx(_,{className:"mr-2"})," Service Order (",t.segments.length," items)"]}),e.jsxs("div",{className:"space-y-1",children:[t.segments.slice(0,3).map((s,r)=>e.jsxs("div",{className:"text-sm text-gray-600 grid grid-cols-[80px_1fr_1fr] gap-2",children:[e.jsx("span",{className:"font-medium text-gray-900",children:s.time}),e.jsx("span",{children:s.title}),e.jsx("span",{className:"text-gray-500 text-xs truncate",children:s.anchor})]},r)),t.segments.length>3&&e.jsxs("p",{className:"text-xs text-gray-400 italic pl-[80px]",children:["...and ",t.segments.length-3," more"]})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>I(t),className:"p-2 text-gray-400 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition",title:"Edit",children:e.jsx(p,{className:"text-xl"})}),e.jsx("button",{onClick:()=>M(t.id),className:"p-2 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition",title:"Delete",children:e.jsx(P,{className:"text-xl"})})]})]})},t.id))}),F&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto shadow-2xl animate-fade-in flex flex-col",children:[e.jsxs("div",{className:"px-6 py-4 bg-gray-50 border-b border-gray-100 flex justify-between items-center sticky top-0 z-10",children:[e.jsx("h2",{className:"font-bold text-lg text-gray-800",children:h?"Edit Service Plan":"New Service Plan"}),e.jsx("button",{onClick:()=>g(!1),className:"text-gray-400 hover:text-gray-600",children:e.jsx(u,{className:"rotate-45 text-2xl"})})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Service Title"}),e.jsx("input",{type:"text",className:"w-full border border-gray-300 rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-blue-500",value:a.title,onChange:t=>n({...a,title:t.target.value}),placeholder:"e.g. Sunday Celebration Service"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Location"}),e.jsx("input",{type:"text",className:"w-full border border-gray-300 rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-blue-500",value:a.location,onChange:t=>n({...a,location:t.target.value}),placeholder:"e.g. Main Sanctuary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date"}),e.jsx("input",{type:"date",className:"w-full border border-gray-300 rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-blue-500",value:a.date,onChange:t=>n({...a,date:t.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Start Time"}),e.jsx("input",{type:"time",className:"w-full border border-gray-300 rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-blue-500",value:a.time,onChange:t=>n({...a,time:t.target.value})})]})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsx("h3",{className:"font-semibold text-gray-800",children:"Service Order / Segments"}),a.segments.length>1&&e.jsxs("button",{onClick:$,className:"text-xs flex items-center gap-1 text-blue-600 hover:text-blue-700 bg-blue-50 px-2 py-1 rounded hover:bg-blue-100 transition",title:"Sort all segments by time",children:[e.jsx(z,{})," Sort by Time"]})]}),e.jsxs("div",{className:"bg-gray-50 p-4 rounded-xl border border-gray-200 mb-4 transition-all ring-1 ring-transparent focus-within:ring-blue-500",children:[e.jsx("h4",{className:"text-xs uppercase tracking-wider font-bold text-gray-400 mb-3",children:o!==null?"Edit Segment":"Add New Segment"}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-2 items-end",children:[e.jsxs("div",{className:"w-full md:w-1/4",children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Time"}),e.jsx("input",{type:"text",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-500",placeholder:"10:00",value:i.time,onChange:t=>m({...i,time:t.target.value})})]}),e.jsxs("div",{className:"w-full md:w-1/3",children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Activity"}),e.jsx("input",{type:"text",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Worship",value:i.title,onChange:t=>m({...i,title:t.target.value})})]}),e.jsxs("div",{className:"w-full md:w-1/3",children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Anchor Person"}),e.jsx("input",{type:"text",className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Pastor John",value:i.anch
1or||"",onChange:t=>m({...i,anchor:t.target.value}),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),k())}})]}),e.jsx("button",{type:"button",onClick:k,className:`${o!==null?"bg-amber-500 hover:bg-amber-600":"bg-green-600 hover:bg-green-700"} text-white p-2 rounded-lg transition shrink-0`,title:o!==null?"Update Segment":"Add Segment",children:o!==null?e.jsx(p,{}):e.jsx(u,{})}),o!==null&&e.jsx("button",{type:"button",onClick:()=>{x(null),m({time:"",title:"",anchor:""})},className:"bg-gray-400 text-white p-2 rounded-lg hover:bg-gray-500 transition shrink-0",title:"Cancel Edit",children:e.jsx(u,{className:"rotate-45"})})]})]}),e.jsxs("div",{className:"space-y-2 max-h-60 overflow-y-auto",children:[a.segments.length===0&&e.jsx("p",{className:"text-center text-gray-400 text-sm py-2",children:"No segments added yet."}),a.segments.map((t,s)=>e.jsxs("div",{className:`flex justify-between items-center p-3 rounded-lg border group transition ${o===s?"bg-amber-50 border-amber-200 ring-1 ring-amber-300":"bg-gray-50 border-gray-100"}`,children:[e.jsxs("div",{className:"flex gap-4 items-center flex-1",children:[e.jsx("span",{className:"font-mono text-xs font-bold bg-gray-200 text-gray-600 px-2 py-1 rounded w-16 text-center",children:t.time}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-gray-800",children:t.title}),t.anchor&&e.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1",children:[e.jsx(B,{className:"inline w-3 h-3"})," ",t.anchor]})]})]}),e.jsxs("div",{className:"flex gap-1 ml-2 border-l pl-2 border-gray-200",children:[e.jsxs("div",{className:"flex flex-col gap-1 mr-1",children:[e.jsx("button",{type:"button",onClick:()=>C(s,"up"),disabled:s===0,className:`p-0.5 rounded ${s===0?"text-gray-300":"text-gray-400 hover:text-blue-600 hover:bg-gray-100"}`,children:e.jsx(J,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",onClick:()=>C(s,"down"),disabled:s===a.segments.length-1,className:`p-0.5 rounded ${s===a.segments.length-1?"text-gray-300":"text-gray-400 hover:text-blue-600 hover:bg-gray-100"}`,children:e.jsx(K,{className:"w-4 h-4"})})]}),e.jsx("button",{onClick:()=>L(s),className:"p-1.5 text-blue-400 hover:text-blue-600 hover:bg-blue-50 rounded",title:"Edit Segment",children:e.jsx(p,{})}),e.jsx("button",{onClick:()=>R(s),className:"p-1.5 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded",title:"Remove Segment",children:e.jsx(P,{})})]})]},s))]})]})]}),e.jsx("div",{className:"p-6 bg-gray-50 border-t border-gray-100 sticky bottom-0",children:e.jsx("button",{onClick:q,className:"w-full bg-blue-600 text-white font-bold py-3 rounded-xl hover:bg-blue-700 transition",children:h?"Save Changes":"Create Service Plan"})})]})})]})};export{ne 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.