1import{bu as p,j as e,B as h,_ as V,at as v,R as D,T as $,aa as G,aq as W,K as X,al as Z,ad as ee,o as te,b1 as ae,a5 as re,aw as M}from"./index-OosC7O28-v4.js";import{r as i}from"./react-vendor-Muxl3iU2-v4.js";import{Q as n}from"./ui-vendor-Bt0bJPpm-v4.js";import{E as se}from"./EmptyState-Dz0hqiOc-v4.js";import{A as le}from"./AdminPageHeader-BRGHeeDK-v4.js";import"./swiper-vendor-CLjMzi4o-v4.js";import"./framer-motion-DbzRPpXx-v4.js";const A=[{value:1,label:"January"},{value:2,label:"February"},{value:3,label:"March"},{value:4,label:"April"},{value:5,label:"May"},{value:6,label:"June"},{value:7,label:"July"},{value:8,label:"August"},{value:9,label:"September"},{value:10,label:"October"},{value:11,label:"November"},{value:12,label:"December"}],P=new Date().getFullYear(),ie=Array.from({length:6},(k,g)=>P-1+g),E={title:"",month:new Date().getMonth()+1,year:P,description:"",is_active:!0,pdf:null},pe=()=>{const[k,g]=i.useState([]),[T,N]=i.useState(!0),[j,z]=i.useState(""),[R,f]=i.useState(!1),[L,o]=i.useState(!1),[c,w]=i.useState(null),[O,C]=i.useState(!1),[F,S]=i.useState(null),[b,_]=i.useState(null),[s,x]=i.useState(E),u=i.useRef(null);i.useEffect(()=>{y()},[]);const y=async()=>{N(!0);try{const t=await p.getAll();g(t.bulletins||[])}catch{n.error("Failed to load bulletins"),g([])}finally{N(!1)}},Y=()=>{w(null),x(E),u.current&&(u.current.value=""),o(!0)},q=t=>{w(t),x({title:t.title||"",month:t.month,year:t.year,description:t.description||"",is_active:t.is_active??!0,pdf:null}),u.current&&(u.current.value=""),o(!0)},d=t=>{const{name:r,value:l,type:a,checked:K,files:Q}=t.target;x(a==="file"?m=>({...m,pdf:Q[0]||null}):a==="checkbox"?m=>({...m,[r]:K}):m=>({...m,[r]:l}))},J=async t=>{var r,l;t.preventDefault(),C(!0);try{const a=new FormData;a.append("title",s.title),a.append("month",s.month),a.append("year",s.year),a.append("description",s.description),a.append("is_active",s.is_active?"1":"0"),s.pdf&&a.append("pdf",s.pdf),c?(a.append("_method","PUT"),await p.update(c.id,a),n.success("Bulletin updated")):(await p.create(a),n.success("Bulletin created")),o(!1),y()}catch(a){n.error(((l=(r=a.response)==null?void 0:r.data)==null?void 0:l.message)||"Failed to save bulletin")}finally{C(!1)}},U=async()=>
1{try{await p.delete(b.id),n.success("Bulletin deleted"),f(!1),_(null),y()}catch{n.error("Failed to delete bulletin")}},H=async t=>{var r,l;if(window.confirm(`Send push notification for "${t.label}"?`)){S(t.id);try{const a=await p.notify(t.id);n.success(a.message||"Notifications sent"),y()}catch(a){n.error(((l=(r=a.response)==null?void 0:r.data)==null?void 0:l.message)||"Failed to send notifications")}finally{S(null)}}},B=k.filter(t=>{var r,l;return((r=t.title)==null?void 0:r.toLowerCase().includes(j.toLowerCase()))||((l=t.label)==null?void 0:l.toLowerCase().includes(j.toLowerCase()))}),I=t=>{var r;return((r=A.find(l=>l.value===Number(t)))==null?void 0:r.label)||t};return e.jsxs("div",{children:[e.jsx(le,{title:"Monthly Bulletins",subtitle:"Upload and manage monthly PDF bulletins for members",icon:e.jsx(v,{}),children:e.jsx(h,{onClick:Y,icon:e.jsx(V,{}),children:"New Bulletin"})}),e.jsx("div",{className:"mb-6 max-w-sm",children:e.jsx(D,{placeholder:"Search bulletins...",value:j,onChange:t=>z(t.target.value),icon:e.jsx($,{})})}),T?e.jsx(G,{}):B.length===0?e.jsx(se,{icon:e.jsx(v,{}),title:"No bulletins found",description:"Create the first monthly bulletin."}):e.jsx("div",{className:"bg-white dark:bg-dark-800 rounded-xl border border-gray-200 dark:border-dark-700 overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-dark-700 bg-gray-50 dark:bg-dark-900/50",children:[e.jsx("th",{className:"text-left px-6 py-4 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Period"}),e.jsx("th",{className:"text-left px-6 py-4 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Title"}),e.jsx("th",{className:"text-left px-6 py-4 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"PDF"}),e.jsx("th",{className:"text-left px-6 py-4 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Status"}),e.jsx("th",{className:"text-left px-6 py-4 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Notified"}),e.jsx("th",{className:"text-right px-6 py-4 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100 dark:divide-dark-700",children:B.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-dark-700/50 transition-colors",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"text-gold-500 shrink-0"}),e.jsxs("span",{className:"font-medium text-gray-900 dark:text-white",children:[I(t.month)," ",t.year]})]})}),e.jsx("td",{className:"px-6 py-4 text-gray-700 dark:text-gray-300 max-w-xs truncate",children:t.title}),e.jsx("td",{className:"px-6 py-4",children:t.pdf_url?e.jsxs("a",{href:t.pdf_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:underline text-sm font-medium",children:[e.jsx(v,{size:14})," View PDF"]}):e.jsx("span",{className:"text-gray-400 text-sm",children:"â"})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx(X,{variant:t.is_active?"success":"secondary",children:t.is_active?"Active":"Inactive"})}),e.jsx("td",{className:"px-6 py-4",children:t.notified?e.jsxs("span",{className:"inline-flex items-center gap-1 text-green-600 dark:text-green-400 text-sm font-medium",children:[e.jsx(Z,{size:14})," Notified"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-gray-400 text-sm",children:[e.jsx(ee,{size:14})," Pending"]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[!t.notified&&e.jsx("button",{onClick:()=>H(t),disabled:F===t.id,title:"Send push notification",className:"p-2 rounded-lg text-gray-400 hover:text-amber-500 hover:bg-amber-50 dark:hover:bg-amber-900/20 transition-colors",children:F===t.id?e.jsx("span",{className:"w-4 h-4 border-2 border-amber-500 border-t-transparent roun
1ded-full animate-spin inline-block"}):e.jsx(te,{size:16})}),e.jsx("button",{onClick:()=>q(t),className:"p-2 rounded-lg text-gray-400 hover:text-primary-600 hover:bg-primary-50 dark:hover:bg-primary-900/20 transition-colors",children:e.jsx(ae,{size:16})}),e.jsx("button",{onClick:()=>{_(t),f(!0)},className:"p-2 rounded-lg text-gray-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",children:e.jsx(re,{size:16})})]})})]},t.id))})]})}),e.jsx(M,{isOpen:L,onClose:()=>o(!1),title:c?"Edit Bulletin":"New Monthly Bulletin",size:"lg",children:e.jsxs("form",{onSubmit:J,className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Title *"}),e.jsx(D,{name:"title",value:s.title,onChange:d,placeholder:"e.g. March 2026 Bulletin",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Month *"}),e.jsx("select",{name:"month",value:s.month,onChange:d,required:!0,className:"w-full border border-gray-300 dark:border-dark-600 rounded-lg px-3 py-2 bg-white dark:bg-dark-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-primary-500",children:A.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Year *"}),e.jsx("select",{name:"year",value:s.year,onChange:d,required:!0,className:"w-full border border-gray-300 dark:border-dark-600 rounded-lg px-3 py-2 bg-white dark:bg-dark-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-primary-500",children:ie.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Description"}),e.jsx("textarea",{name:"description",value:s.description,onChange:d,rows:3,placeholder:"Optional description for this bulletin...",className:"w-full border border-gray-300 dark:border-dark-600 rounded-lg px-3 py-2 bg-white dark:bg-dark-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 resize-none"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:["PDF File ",c?"(leave blank to keep existing)":""]}),e.jsx("input",{ref:u,type:"file",name:"pdf",onChange:d,accept:"application/pdf",className:"w-full text-sm text-gray-600 dark:text-gray-400 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-primary-50 file:text-primary-700 hover:file:bg-primary-100 dark:file:bg-primary-900/30 dark:file:text-primary-400"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",id:"is_active",name:"is_active",checked:s.is_active,onChange:d,className:"w-4 h-4 rounded text-primary-600 focus:ring-primary-500"}),e.jsx("label",{htmlFor:"is_active",className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Active (visible to members)"})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx(h,{type:"button",variant:"secondary",onClick:()=>o(!1),children:"Cancel"}),e.jsx(h,{type:"submit",loading:O,children:c?"Save Changes":"Create Bulletin"})]})]})}),e.jsxs(M,{isOpen:R,onClose:()=>f(!1),title:"Delete Bulletin",size:"sm",children:[e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:["Are you sure you want to delete ",e.jsx("strong",{className:"text-gray-900 dark:text-white",children:b==null?void 0:b.label}),"? This action cannot be undone."]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(h,{variant:"secondary",onClick:()=>f(!1),children:"Cancel"}),e.jsx(h,{variant:"danger",onClick:U,children:"Delete"})]})]})]})};export{pe 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.