1import{j as e}from"./ui-vendor-sc7Ix2AM.js";import{a as t}from"./react-vendor-DrGUvmao.js";import{u as n,h as s,C as r,b as i,c as o,d as a,H as c,B as l,e as d,L as m,I as p,s as u,l as h}from"./index-BczH2x_6.js";import{T as x}from"./textarea-hEVT000h.js";import{S as y}from"./switch-DguQVS_f.js";import{c as j,v as g}from"./sanitizer-BRsFgRMf.js";import{B as f}from"./bell-DmvALQKB.js";import{G as v}from"./globe-DYMA8_Df.js";import{I as k}from"./info-Bv1cyCCH.js";import{S as _}from"./square-pen-FpyQ_E1z.js";import{S as N}from"./save-Cl0Y8qH2.js";import"./supabase-vendor-C0sqOAb0.js";import"./utils-Bmne0XXo.js";import"./query-vendor-DbH7i3FQ.js";function b(){const{userProfile:b}=n(),{toast:w}=s(),[S,C]=t.useState([]),[E,O]=t.useState(!1),[I,T]=t.useState(null),[A,L]=t.useState({}),P=[{key:"announcements_title",label:"Announcements Title",type:"text",placeholder:"Announcements",icon:f,color:"text-blue-600"},{key:"announcements_description",label:"Announcements Description",type:"text",placeholder:"Program updates and seasonal reminders",icon:f,color:"text-blue-600"},{key:"announcements_content",label:"Announcements Content",type:"html",placeholder:"<ul><li>⢠Spring prep checklist posted</li><li>⢠Orientation webinar next month</li></ul>",icon:f,color:"text-blue-600"},{key:"external_resources_title",label:"External Resources Title",type:"text",placeholder:"External Resources",icon:v,color:"text-green-600"},{key:"external_resources_description",label:"External Resources Description",type:"text",placeholder:"Helpful beekeeping organizations",icon:v,color:"text-green-600"},{key:"external_resources_links",label:"External Resources Links",type:"json",placeholder:'[{"title": "Operation BeeStrong", "url": "https://www.beestrong.ca/"}, {"title": "Ontario Beekeepers Association", "url": "https://www.ontariobee.com/"}]',icon:v,color:"text-green-600"},{key:"program_info_title",label:"Program Information Title",type:"text",placeholder:"Get Started",icon:k,color:"text-purple-600"},{key:"program_info_description",label:"Program Information Description",type:"text",placeholder:"Join the beekeeping community",icon:k,color:"text-purple-600"},{key:"program_info_content",label:"Program Information Content",type:"html",placeholder:"<div>Custom HTML content for program information</div>",icon:k,color:"text-purple-600"}],B=async()=>{try{const{data:e,error:t}=await u.from("page_content").select("*").eq("page_slug","community").order("section_key");if(t)throw t;C(e||[]);const n={};e?.forEach(e=>{n[e.section_key]=e.content_value||""}),L(n)}catch(e){h.error("Error fetching community content:",e),w({variant:"destructive",title:"Error",description:"Failed to fetch community content."})}};t.useEffect(()=>{B()},[]);const H=e=>{const t=S.find(t=>t.section_key===e);return t?.content_value||""};if("admin"!==b?.role)return e.jsx("div",{className:"container mx-auto py-10",children:e.jsx(r,{children:e.jsxs(i,{children:[e.jsx(o,{children:"Access Restricted"}),e.jsx(a,{children:"You need admin privileges to manage community content."})]})})});const J=P.reduce((e,t)=>{const n=t.key.split("_")[0];return e[n]||(e[n]=[]),e[n].push(t),e},{});return e.jsxs(e.Fragment,{children:[e.jsxs(c,{children:[e.jsx("title",{children:"Community Content ⢠Operation BeeStrong Admin"}),e.jsx("meta",{name:"description",content:"Manage community page content sections for Operation BeeStrong."})]}),e.jsxs("div",{className:"container mx-auto py-6 space-y-6 px-4 sm:px-6 max-w-full",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Community Page Content"}),e.jsx("p",{className:"text-muted-foreground",children:"Edit the content sections that appear on the community page including announcements, external resources, and program information."})]}),e.jsx("div",{className:"space-y-8",children:Object.entries(J).map(([t,n])=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-2xl font-semibold capitalize",children:[t.replace("_"," ")," Section"]}),e.jsx("div",{className:"grid gap-6",children:n.map(t=>{const n=I===t.key,s=n?A[t.key]||"":H(t.key),c=(e=>{const t=S.find(t=>t.section_key===e);
1return!1!==t?.is_active})(t.key),f=S.find(e=>e.section_key===t.key),v=t.icon;return e.jsxs(r,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(o,{className:"flex items-center gap-2",children:[e.jsx(v,{className:`h-5 w-5 ${t.color}`}),t.label,!c&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"(Inactive)"})]}),e.jsxs(a,{children:["Edit the content for: ",t.key]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[f&&e.jsx(y,{checked:c,onCheckedChange:()=>(async e=>{try{const{error:t}=await u.from("page_content").update({is_active:!e.is_active,updated_at:(new Date).toISOString()}).eq("id",e.id);if(t)throw t;w({title:"Status updated",description:`Section ${e.is_active?"deactivated":"activated"} successfully.`}),B()}catch(t){h.error("Error updating section status:",t),w({variant:"destructive",title:"Error",description:"Failed to update section status."})}})(f)}),n?e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{variant:"outline",size:"sm",onClick:()=>T(null),children:"Cancel"}),e.jsxs(l,{size:"sm",onClick:()=>(async e=>{O(!0);try{const t=A[e]||"",n=P.find(t=>t.key===e);if("html"===n?.type&&t&&!g(t))return w({variant:"destructive",title:"Invalid Content",description:"The HTML content contains potentially unsafe elements. Please review and try again."}),void O(!1);const s=S.find(t=>t.section_key===e);if(s){const{error:e}=await u.from("page_content").update({content_value:t,updated_at:(new Date).toISOString()}).eq("id",s.id);if(e)throw e}else{const{error:s}=await u.from("page_content").insert([{page_slug:"community",section_key:e,content_type:n?.type||"text",content_value:t,is_active:!0}]);if(s)throw s}w({title:"Content saved",description:`${n?.label||e} has been updated successfully.`}),T(null),B()}catch(t){h.error("Error saving content:",t),w({variant:"destructive",title:"Error",description:"Failed to save content."})}finally{O(!1)}})(t.key),disabled:E,children:[e.jsx(N,{className:"h-4 w-4 mr-1"}),E?"Saving...":"Save"]})]}):e.jsxs(l,{variant:"outline",size:"sm",onClick:()=>{T(t.key),L(e=>({...e,[t.key]:H(t.key)}))},children:[e.jsx(_,{className:"h-4 w-4"}),"Edit"]})]})]})}),e.jsx(d,{children:n?e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:t.key,children:"Content"}),"html"===t.type||"json"===t.type?e.jsx(x,{id:t.key,value:A[t.key]||"",onChange:e=>L(n=>({...n,[t.key]:e.target.value})),placeholder:t.placeholder,rows:"json"===t.type?6:4}):e.jsx(p,{id:t.key,value:A[t.key]||"",onChange:e=>L(n=>({...n,[t.key]:e.target.value})),placeholder:t.placeholder}),"json"===t.type&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Format: ",'[{"title": "Link Name", "url": "https://example.com"}]']})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Current Content"}),e.jsx("div",{className:"p-3 bg-muted rounded-md min-h-[60px]",children:s?"html"===t.type?e.jsx("div",{dangerouslySetInnerHTML:j(s)}):"json"===t.type?(()=>{let t=s||"[]";t=t.replace(/\n/g,"").replace(/\r/g,"").trim(),t=t.replace(/,\s*]/g,"]");try{let n;try{n=JSON.parse(t)}catch{n=JSON.parse(JSON.parse(t))}return e.jsx("pre",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:JSON.stringify(n,null,2)})}catch{return e.jsx("div",{children:e.jsxs("pre",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:[" ",JSON.stringify(t,null,2)]})})}})():e.jsx("p",{children:s}):e.jsx("p",{className:"text-muted-foreground italic",children:"No content set"})})]})})]},t.key)})})]},t))}),e.jsxs(r,{children:[e.jsxs(i,{children:[e.jsx(o,{children:"Content Guidelines"}),e.jsx(a,{children:"Best practices for community content management"})]}),e.jsx(d,{children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"text-sm",children:[e.jsx("h4",{className:"font-medium mb-2",children:"Content Guidelines:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-muted-foreground",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Announcements:"})," Use HTML for lists and formatting (e.g., <ul><li>Item</li></ul>)"]}
1),e.jsxs("li",{children:[e.jsx("strong",{children:"External Resources:"})," JSON format for links: ",'[{"title": "Name", "url": "https://..."}]']}),e.jsxs("li",{children:[e.jsx("strong",{children:"Program Information:"})," Can include HTML for buttons and formatting"]}),e.jsx("li",{children:"Use the toggle switches to show/hide sections on the community page"}),e.jsx("li",{children:"Content updates are immediately visible on the community page"})]})]})})})]})]})]})}export{b 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.