1import{r as o,j as e}from"./vendor-react-BKK2cemD.js";import{M as H,a as J}from"./MerchantContextBanner-BaSQMf0n.js";import{s as w,E as U}from"./index-dYSgqNAK.js";import{P as M,p as q,n as G,o as X,X as Y,q as Z}from"./vendor-lucide-Cg1iQ9zl.js";import{a as K}from"./vendor-router-MWzdZqT4.js";import"./vendor-posthog-DaPeprxb.js";import"./vendor-maplibre-CpI4tf7S.js";const N={name:"",tag:"",dates:"",description:"",image:"",imageAlt:"",applicationOpen:!0,applicationUrl:"/application",openingNote:"",reversed:!1},re=()=>{const b=K(),[r,x]=o.useState([]),[E,k]=o.useState(!0),[z,y]=o.useState(!1),[c,F]=o.useState(null),[_,S]=o.useState(null),[O,I]=o.useState([]),[p,g]=o.useState(null),[D,f]=o.useState(!1),[l,m]=o.useState(N),[P,j]=o.useState(null),B=async()=>{try{const s=await fetch("/api/cms/session",{credentials:"include"});if(s.ok){const t=await s.json();t.authenticated?(F(t.user),t.user.role!=="admin"&&t.user.businessId!==100&&b("/merchant/dashboard")):b("/merchant/login")}else b("/merchant/login")}catch{b("/merchant/login")}},C=async()=>{k(!0);try{const[s,t]=await Promise.all([fetch("/api/data/opportunities.json"),fetch("/api/data/businesses.json")]);if(s.ok){const a=await s.json(),n=Array.isArray(a)?a:a.items||[];x([...n].sort((i,h)=>i.order-h.order))}if(t.ok){const a=await t.json();I(a),S(a.find(n=>n.id==="100")||a[0]||null)}}catch{console.error("Failed to load data")}finally{k(!1)}},u=async s=>{y(!0);try{let t={};try{const i=await fetch("/api/data/opportunities.json");if(i.ok){const h=await i.json();t=Array.isArray(h)?{}:h}}catch{}const a={...t,items:s};if(!(await fetch("/api/data/opportunities.json",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a),credentials:"include"})).ok)throw new Error("Save failed")}catch{alert("Failed to save changes. Please try again."),await C()}finally{y(!1)}};o.useEffect(()=>{B(),C()},[]);const A=()=>{g(null),m(N),f(!0)},T=s=>{g(s);const{id:t,order:a,...n}=s;m(n),f(!0)},v=()=>{f(!1),g(null),m(N)},R=async()=>{if(!l.name.trim()){alert("Please enter a venue/event name.");return}let s;if(p)s=r.map(t=>t.id===p.id?{...p,...l}:t);else{const t={...l,id:`opp-${Date.now()}`,order:r.length};s=[...r,t]}x(s),v(),await u(s)},$=async s=>{const t=r.filter(a=>a.id!==s).map((a,n)=>({...a,order:n}));x(t),j(null),await u(t)},L=async s=>{if(s===0)return;const t=[...r];[t[s-1],t[s]]=[t[s],t[s-1]];const a=t.map((n,i)=>({...n,order:i}));x(a),await u(a)},V=async s=>{if(s>=r.length-1)return;const t=[...r];[t[s],t[s+1]]=[t[s+1],t[s]];const a=t.map((n,i)=>({...n,order:i}));x(a),await u(a)},d=(s,t,a="text")=>a==="toggle"?e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-zinc-100 dark:border-zinc-800",children:[e.jsx("label",{className:"text-sm font-semibold text-zinc-700 dark:text-zinc-300",children:t}),e.jsx("button",{type:"button",onClick:()=>m(n=>({...n,[s]:!n[s]})),className:`relative w-12 h-6 rounded-none transition-all ${l[s]?"bg-primary":"bg-zinc-300 dark:bg-zinc-600"}`,children:e.jsx("span",{className:`absolute top-1 left-1 w-4 h-4 bg-white rounded-none shadow transition-transform ${l[s]?"translate-x-6":""}`})})]},s):a==="textarea"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-sm font-semibold text-zinc-700 dark:text-zinc-300",children:t}),e.jsx("textarea",{rows:3,value:l[s]||"",onChange:n=>m(i=>({...i,[s]:n.target.value})),className:"px-3 py-2 rounded-none border border-zinc-300 dark:border-zinc-700 bg-white dark:bg-zinc-800 text-sm outline-none focus:ring-2 focus:ring-primary resize-none"})]},s):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-sm font-semibold text-zinc-700 dark:text-zinc-300",children:t}),e.jsx("input",{type:"text",value:l[s]||"",onChange:n=>m(i=>({...i,[s]:n.target.value})),className:"px-3 py-2 rounded-none border border-zinc-300 dark:border-zinc-700 bg-white dark:bg-zinc-800 text-sm outline-none focus:ring-2 focus:ring-primary"})]},s);return e.jsxs("div",{className:"flex h-screen overflow-hidden bg-background-light dark:bg-background-dark",children:[e.jsx(H,{currentUser:c,selectedBusiness:_,businesses:O,handleBusinessSelect:s=>{S(s),localStorage.setItem("selectedBusinessId",s.id)},showBusinessSelector:!1,setShowBusinessSelector:()=>{}}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(J,{business:null,isAdmin:(c==null?void 0:c.role)==="admin"||(c==null?void 0:c.businessId)===100}),e.jsx("header",{className:"sticky top-0 z-10 border-b border-gray-200 dark:border-white/10 bg-white/80 dark:bg-black/60 backdrop-blur-md shrink-0",children:e.jsxs("div",{className:"max-w-7xl mx-auto w-full px-8 py-6 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-semibold mb-1 border-l-4 border-primary pl-4 text-black dark:text-white",children:"Managed Festivals"}),e.jsx("p",{className:"text-sm text-[#8a7960] pl-4",children:"Manage the festivals listed on the public-facing page"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("a",{href:"/opportunities",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-4 py-2 rounded-none border border-zinc-300 dark:border-zinc-700 text-sm font-semibold hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-base",children:"open_in_new"}),"Preview Page"]}),e.jsxs("button",{onClick:A,className:"flex items-center gap-2 px-5 py-2.5 bg-primary text-black rounded-none font-semibold text-sm hover:bg-primary/90 transition-colors shadow-sm",children:[e.jsx(M,{size:16}),"Add Festival"]})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx("div",{className:"max-w-7xl mx-auto px-8 py-8",children:E?e.
1jsxs("div",{className:"text-center py-24 text-muted",children:[e.jsx("span",{className:"material-symbols-outlined text-4xl animate-spin mb-2",children:"progress_activity"}),e.jsx("p",{children:"Loading festivalsâ¦"})]}):r.length===0?e.jsxs("div",{className:"text-center py-24",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-none bg-zinc-100 dark:bg-zinc-800 mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-muted",children:"venue"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No festivals yet"}),e.jsx("p",{className:"text-muted mb-6",children:"Add your first festival to get started."}),e.jsxs("button",{onClick:A,className:"flex items-center gap-2 mx-auto px-6 py-3 bg-primary text-black rounded-none font-semibold hover:bg-primary/90 transition-colors",children:[e.jsx(M,{size:16}),"Add First Festival"]})]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"grid grid-cols-[auto_1fr_auto_auto_auto] gap-4 items-center px-4 py-2",children:[e.jsx("span",{className:"text-xs font-semibold text-muted uppercase tracking-wider w-10",children:"Order"}),e.jsx("span",{className:"text-xs font-semibold text-muted uppercase tracking-wider",children:"Festival"}),e.jsx("span",{className:"text-xs font-semibold text-muted uppercase tracking-wider",children:"Applications"}),e.jsx("span",{className:"text-xs font-semibold text-muted uppercase tracking-wider",children:"Edit"}),e.jsx("span",{className:"text-xs font-semibold text-muted uppercase tracking-wider",children:"Delete"})]}),r.map((s,t)=>e.jsx("div",{className:"bg-white dark:bg-zinc-900 rounded-none border border-zinc-200 dark:border-zinc-800 overflow-hidden hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr_auto_auto_auto] gap-4 items-center px-4 py-4",children:[e.jsxs("div",{className:"flex flex-col items-center gap-0.5 w-10",children:[e.jsx("button",{onClick:()=>L(t),disabled:t===0,className:"p-1 rounded-none hover:bg-zinc-100 dark:hover:bg-zinc-700 disabled:opacity-30 transition-colors",title:"Move up",children:e.jsx("span",{className:"material-symbols-outlined text-sm",children:"arrow_upward"})}),e.jsx(q,{size:14,className:"text-zinc-300"}),e.jsx("button",{onClick:()=>V(t),disabled:t===r.length-1,className:"p-1 rounded-none hover:bg-zinc-100 dark:hover:bg-zinc-700 disabled:opacity-30 transition-colors",title:"Move down",children:e.jsx("span",{className:"material-symbols-outlined text-sm",children:"arrow_downward"})})]}),e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("div",{className:"w-20 h-14 rounded-none overflow-hidden shrink-0 bg-zinc-100 dark:bg-zinc-800",children:s.image?e.jsx("img",{src:s.image,alt:s.imageAlt,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-muted",children:"image"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",children:w(s.name)}),e.jsxs("p",{className:"text-xs text-muted truncate",children:[w(s.tag)," · ",s.dates]}),e.jsx("p",{className:"text-xs text-muted line-clamp-1 mt-0.5",children:w(s.description)})]})]}),e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:`px-3 py-1 rounded-none text-xs font-semibold ${s.applicationOpen?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-zinc-100 text-muted dark:bg-zinc-800 dark:text-muted"}`,children:s.applicationOpen?"Open":"Closed"})}),e.jsx("button",{onClick:()=>T(s),className:"p-2 rounded-none border border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors",title:"Edit",children:e.jsx(G,{size:15})}),P===s.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>$(s.id),className:"px-2 py-1 rounded-none bg-red-500 text-white text-xs font-semibold hover:bg-red-600 transition-colors",children:"Confirm"}),e.jsx("button",{onClick:()=>j(null),className:"px-2 py-1 rounded-none border border-zinc-300 text-xs font-semibold hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors",children:"Cancel"})]}):e.jsx("button",{onClick:()=>j(s.id),className:"p-2 rounded-none border border-red-200 dark:border-red-900 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",title:"Delete",children:e.jsx(X,{size:15})})]})},s.id)),e.jsxs("p",{className:"text-xs text-center text-muted mt-2",children:[r.length," festival",r.length!==1?"s":""," · Use the arrows to reorder"]}
1)]})})})]}),D&&e.jsx("div",{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white dark:bg-zinc-900 rounded-none w-full max-w-2xl max-h-[90vh] overflow-y-auto shadow-2xl",children:[e.jsxs("div",{className:"sticky top-0 bg-white dark:bg-zinc-900 border-b border-zinc-200 dark:border-zinc-800 px-6 py-4 flex items-center justify-between z-10",children:[e.jsx("h2",{className:"text-xl font-semibold",children:p?"Edit Festival":"Add New Festival"}),e.jsx("button",{onClick:v,className:"p-2 rounded-none hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors",children:e.jsx(Y,{size:18})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[d("name","Event / Venue Name *"),d("tag","Category Tag (e.g. Heritage Event, Seasonal Market)"),d("dates","Dates (e.g. May 23-26, 2024)"),d("description","Description","textarea"),e.jsxs("div",{className:"border-t border-zinc-100 dark:border-zinc-800 pt-4 space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted uppercase tracking-wider",children:"Festival Image"}),e.jsx("div",{className:"relative w-full h-48 border border-dashed border-zinc-300 dark:border-zinc-700 bg-zinc-50 dark:bg-zinc-800 flex items-center justify-center",children:e.jsx(U,{src:l.image||"",alt:l.imageAlt||"Festival image",onChange:s=>m(t=>({...t,image:s})),isEditMode:!0,className:"w-full h-full object-cover",effectiveFolder:"business/100"})}),d("imageAlt","Image Alt Text")]}),e.jsxs("div",{className:"border-t border-zinc-100 dark:border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs font-semibold text-muted uppercase tracking-wider mb-3",children:"Application Settings"}),d("applicationOpen","Applications Open","toggle"),d("applicationUrl","Zapplication link (if applicable)"),!l.applicationOpen&&d("openingNote","Closed Note (e.g. Application Opens July)"),d("reversed","Mirror Layout (image on right)","toggle")]})]}),e.jsxs("div",{className:"sticky bottom-0 bg-white dark:bg-zinc-900 border-t border-zinc-200 dark:border-zinc-800 px-6 py-4 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:v,className:"px-5 py-2.5 rounded-none border border-zinc-300 dark:border-zinc-700 text-sm font-semibold hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:R,disabled:z,className:"px-5 py-2.5 rounded-none bg-primary text-black text-sm font-semibold flex items-center gap-2 hover:bg-primary/90 transition-colors disabled:opacity-60",children:[e.jsx(Z,{size:15}),z?"Savingâ¦":p?"Save Changes":"Add Festival"]})]})]})})]})};export{re 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.