1import{j as e}from"./vendor-data-Z5doMMu-.js";import{r}from"./vendor-react-zNM0AU50.js";import{u as $,b as d,c as q}from"./index-D1K3lVhu.js";import{u as G}from"./imageService-5xt-7IGi.js";import{z as o,M as k,aa as J,aI as Q,O as W,X as Z,r as ee,ak as te,D as se,ad as ae,f as ne,az as re,T as ie,a4 as le}from"./vendor-ui-CW5bJ11U.js";import{R as ce}from"./RichTextEditor-D4OTyKrK.js";import{F as de,a as z}from"./FileAttachments-DlLJW4q3.js";import{B as I}from"./staff-communication-CbPIwj0F.js";import"./vendor-firebase-Da9KY1q_.js";import"./vendor-charts-08G1rM8P.js";const oe={free:k,prayer:W,resource:Q};function we(){const{user:i}=$(),[m,M]=r.useState("free"),[A,x]=r.useState([]),[K,E]=r.useState(!0),[p,w]=r.useState(null),[F,D]=r.useState({}),[H,N]=r.useState(!1),[u,B]=r.useState(null),[h,v]=r.useState(""),[_,C]=r.useState(""),[g,f]=r.useState([]),[y,P]=r.useState([]),[T,L]=r.useState(!1),[b,R]=r.useState({});r.useEffect(()=>{S()},[m]);async function S(){try{E(!0),x(await d.getByBoard(m))}catch{o.error("ê²ì물ì ë¶ë¬ì¬ ì ììµëë¤")}finally{E(!1)}}function j(){N(!1),B(null),v(""),C(""),f([]),P([])}function U(t){B(t.id),v(t.title),C(t.content),f([]),P(t.attachments||[]),N(!0)}async function V(){if(!i||!h.trim()||!_.trim()){o.error("ì 목과 ë´ì©ì ì
ë ¥í´ì£¼ì¸ì");return}L(!0);try{let t=[];g.length>0&&(t=(await G(g,"staff_files/posts")).map(s=>({name:s.name,url:s.url,type:s.type,size:s.size})));const a=[...y||[],...t],l={board_type:m,title:h.trim(),content:_,attachments:a,author_id:i.uid,author_name:i.name};u?(await d.update(u,l),o.success("ê²ìë¬¼ì´ ìì ëììµëë¤")):(await d.create(l),o.success("ê²ìë¬¼ì´ ë±ë¡ëììµëë¤")),j(),await S()}catch{o.error("ì ì¥ì ì¤í¨íìµëë¤")}finally{L(!1)}}async function X(t){if(confirm("ì´ ê²ì물ì ìì íìê² ìµëê¹?"))try{await d.delete(t),o.success("ê²ìë¬¼ì´ ìì ëììµëë¤"),p===t&&w(null),await S()}catch{o.error("ìì ì ì¤í¨íìµëë¤")}}async function Y(t){var a;if(p===t.id){w(null);return}if(w(t.id),i&&!((a=t.viewed_by)!=null&&a.includes(i.uid))&&(d.markAsViewed(t.id,i.uid),x(l=>l.map(n=>n.id===t.id?{...n,view_count:(n.view_count||0)+1,viewed_by:[...n.viewed_by||[],i.uid]}:n))),!F[t.id])try{const l=await d.getComments(t.id);D(n=>({...n,[t.id]:l}))}catch{}}async function O(t){var l;const a=(l=b[t])==null?void 0:l.trim();if(!(!i||!a))try{await d.addComment({post_id:t,content:a,author_id:i.uid,author_name:i.name}),R(s=>({...s,[t]:""}));const n=await d.getComments(t);D(s=>({...s,[t]:n})),x(s=>s.map(c=>c.id===t?{...c,comment_count:n.length}:c)),o.success("ëê¸ì´ ë±ë¡ëììµëë¤")}catch{o.error("ëê¸ ë±ë¡ì ì¤í¨íìµëë¤")}}return e.jsxs("div",{className:"p-3 sm:p-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4 sm:mb-6",children:[e.jsx("div",{className:"w-9 h-9 sm:w-10 sm:h-10 bg-blue-50 rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(k,{className:"w-4 h-4 sm:w-5 sm:h-5 text-blue-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-lg sm:text-xl font-bold text-gray-900",children:"ê²ìí"}),e.jsx("p",{className:"text-[11px] sm:text-xs text-gray-500",children:"ìì ê²ìí · 기ëì 목 · ìë£ê³µì "})]}),e.jsxs("button",{onClick:()=>{j(),N(!0)},className:"px-3 sm:px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition-colors flex items-center gap-1.5",children:[e.jsx(J,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"ê¸ì°ê¸°"})]})]}),e.jsx("div",{className:"flex gap-1 mb-4 bg-gray-100 rounded-lg p-1 w-full sm:w-fit",children:["free","prayer","resource"].map(t=>{const a=oe[t];return e.jsxs("button",{onClick:()=>M(t),className:q("flex-1 sm:flex-initial px-3 sm:px-4 py-2 text-sm font-medium rounded-md transition-all flex items-center gap-1.5 justify-center",m===t?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"),children:[e.jsx(a,{className:"w-3.5 h-3.5"}),I[t]]},t)})}),H&&e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm mb-6 overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold text-gray-900 text-sm",children:u?"ê¸ ìì ":`${I[m]}ì ê¸ì°ê¸°`}),e.jsx("button",{onClick:j,className:"p-1 hover:bg-gray-100 rounded-lg",children:e.jsx(Z,{className:"w-4 h-4 text-gray-500"})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("input",{type:"text",value:h,onChange:t=>v(t.target.value),placeholder:"ì 목ì ì
ë ¥íì¸ì",className:"w-full border border-gray-200 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent",autoFocus:!0}
1),e.jsx(ce,{value:_,onChange:C,placeholder:"ë´ì©ì ì
ë ¥íì¸ì...",height:200}),e.jsx(de,{files:g,onAdd:t=>f(a=>[...a,...t]),onRemove:t=>f(a=>a.filter((l,n)=>n!==t)),accentColor:"blue"}),y&&y.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:"기존 첨ë¶íì¼"}),e.jsx(z,{attachments:y})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:j,className:"px-4 py-2 text-sm text-gray-600 hover:bg-gray-100 rounded-lg",children:"ì·¨ì"}),e.jsx("button",{onClick:V,disabled:T||!h.trim(),className:"px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 disabled:opacity-50 transition-colors",children:T?g.length>0?"ì
ë¡ë ì¤...":"ì ì¥ ì¤...":u?"ìì ":"ë±ë¡"})]})]})]}),K?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}):A.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-12 text-center text-gray-400",children:[e.jsx(ee,{className:"w-10 h-10 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"ìì§ ê²ìë¬¼ì´ ììµëë¤"})]}):e.jsx("div",{className:"space-y-3",children:A.map(t=>{const a=p===t.id,l=F[t.id]||[],n=(i==null?void 0:i.uid)===t.author_id;return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 overflow-hidden",children:[e.jsxs("button",{onClick:()=>Y(t),className:"w-full text-left px-5 py-4 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:t.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-gray-400",children:[e.jsx("span",{children:t.author_name}),e.jsx("span",{children:new Date(t.created_at).toLocaleDateString("ko-KR")}),(t.view_count||0)>0&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(te,{className:"w-3 h-3"}),t.view_count]}),t.comment_count>0&&e.jsxs("span",{className:"flex items-center gap-0.5 text-blue-500",children:[e.jsx(k,{className:"w-3 h-3"}),t.comment_count]}),(t.download_count||0)>0&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(se,{className:"w-3 h-3"}),t.download_count]})]})]}),a?e.jsx(ae,{className:"w-4 h-4 text-gray-400"}):e.jsx(ne,{className:"w-4 h-4 text-gray-400"})]}),a&&e.jsxs("div",{className:"border-t border-gray-100",children:[e.jsx("div",{className:"px-5 py-4 text-sm text-gray-700 [&_p]:mb-2 [&_ul]:list-disc [&_ul]:ml-4 [&_img]:max-w-full [&_img]:rounded",dangerouslySetInnerHTML:{__html:t.content}}),t.attachments&&t.attachments.length>0&&e.jsx("div",{className:"px-5 pb-3",children:e.jsx(z,{attachments:t.attachments,onDownload:()=>{d.incrementDownloadCount(t.id),x(s=>s.map(c=>c.id===t.id?{...c,download_count:(c.download_count||0)+1}:c))}})}),n&&e.jsxs("div",{className:"px-5 py-2 flex items-center gap-2 border-t border-gray-50",children:[e.jsxs("button",{onClick:()=>U(t),className:"text-xs text-blue-600 hover:underline flex items-center gap-0.5",children:[e.jsx(re,{className:"w-3 h-3"})," ìì "]}),e.jsxs("button",{onClick:()=>X(t.id),className:"text-xs text-red-600 hover:underline flex items-center gap-0.5",children:[e.jsx(ie,{className:"w-3 h-3"})," ìì "]})]}),e.jsxs("div",{className:"px-5 py-3 bg-gray-50 border-t border-gray-100 space-y-2",children:[l.map(s=>e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"text-xs",children:[e.jsx("span",{className:"font-medium text-gray-700",children:s.author_name}),e.jsx("span",{className:"text-gray-400 ml-1.5",children:new Date(s.created_at).toLocaleDateString("ko-KR",{month:"numeric",day:"numeric"})})]}),e.jsx("p",{className:"text-xs text-gray-600 flex-1",children:s.content})]},s.id)),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("input",{type:"text",value:b[t.id]||"",onChange:s=>R(c=>({...c,[t.id]:s.target.value})),placeholder:"ëê¸ì ì
ë ¥íì¸ì...",className:"flex-1 border border-gray-200 rounded-lg px-3 py-1.5 text-xs focus:ring-1 focus:ring-blue-500 bg-white",onKeyDown:s=>{s.key==="Enter"&&(b[t.id]||"").trim()&&O(t.id)}}),e.jsx("button",{onClick:()=>O(t.id),disabled:!(b[t.id]||"").trim(),className:"px-3 py-1.5 bg-blue-600 text-white text-xs rounded-lg hover:bg-blue-700 disabled:opacity-50 transition-colors",children:e.jsx(le,{className:"w-3 h-3"})})]})]})]})]},t.id)})})]})}export{we as StaffBoardPage};
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.