1import{j as e}from"./vendor-data-Z5doMMu-.js";import{r as m}from"./vendor-react-zNM0AU50.js";import{a7 as n,a0 as $,i as E,bq as Q,j as V,L as _,R as W,bm as X,br as P,ad as Z,f as ee,aL as te,bd as se,U as ae,D as le,T as ne}from"./vendor-ui-CW5bJ11U.js";import{d as C,h as y,g as re,o as ce,u as oe}from"./index-D1K3lVhu.js";import{k as T,K as ie,j as de,q as ue,B as me,x as xe,l as he,m as pe,T as L}from"./vendor-firebase-Da9KY1q_.js";import"./vendor-charts-08G1rM8P.js";const j=re(ce,"us-central1"),be="backup_history",A="system/backup_settings",h={async startFullBackup(){return(await y(j,"backupFullDatabase",{timeout:6e5})()).data},async startSelectiveBackup(t){return(await y(j,"backupCollections",{timeout:6e5})({collections:t,includeChurchSub:!0})).data},async startAuthBackup(){return(await y(j,"backupAuth",{timeout:3e5})()).data},async getBackupHistory(t=50){const a=ue(he(C,be),xe("created_at","desc"),me(t));return(await pe(a)).docs.map(c=>{const l=c.data();return{id:c.id,type:l.type,status:l.status,output_uri:l.output_uri,download_urls:l.download_urls,collections:l.collections,document_count:l.document_count,file_size_bytes:l.file_size_bytes,error_message:l.error_message,created_by:l.created_by,created_by_name:l.created_by_name,created_at:l.created_at instanceof L?l.created_at.toDate().toISOString():l.created_at||"",completed_at:l.completed_at instanceof L?l.completed_at.toDate().toISOString():l.completed_at}})},async getDownloadUrl(t){return(await y(j,"getBackupDownloadUrl")({filePath:t})).data.url},async deleteBackup(t){await y(j,"deleteBackup")({backupId:t})},async getBackupSettings(){const t=T(C,A),a=await de(t);return a.exists()?a.data():{auto_backup_enabled:!1,schedule_time:"03:00",retention_days:30,include_auth:!1}},async saveBackupSettings(t,a){const r=T(C,A);await ie(r,{...t,updated_by:a,updated_at:new Date().toISOString()},{merge:!0})}},ge={firestore_native:"Firestore ì ì²´ ë°±ì
",json_selective:"JSON ì í ë°±ì
",auth:"ì¬ì©ì ê³ì ë°±ì
",scheduled:"ìë ì¤ì¼ì¤ ë°±ì
"},fe={pending:"ë기 ì¤",running:"ì§í ì¤",completed:"ìë£",failed:"ì¤í¨"},ye={pending:{bg:"bg-gray-100",text:"text-gray-600",dot:"bg-gray-400"},running:{bg:"bg-blue-100",text:"text-blue-700",dot:"bg-blue-500"},completed:{bg:"bg-green-100",text:"text-green-700",dot:"bg-green-500"},failed:{bg:"bg-red-100",text:"text-red-700",dot:"bg-red-500"}},je=[{label:"êµì¸/ì¬ì©ì",collections:["users","members","newMembers"],sensitive:!0},{label:"ì¬ì ",collections:["offerings","expenses","budgets","accounts"],sensitive:!0},{label:"목ì/ìë´",collections:["visit_records","pastoral_counseling","prayer_requests"],sensitive:!0},{label:"êµììì¤",collections:["staff_reports","staff_report_comments","staff_report_templates","staff_schedules","staff_announcements","staff_posts","staff_post_comments","staff_notifications","staff_approvals"]},{label:"ì½í
ì¸ /ìíµ",collections:["communications","posts","bulletins","notices","banners","albums","qt_contents","qt_daily"]},{label:"ì¶ì/ì¼ì ",collections:["attendance","calendar","events"]},{label:"ë¹í",collections:["council_posts","resource_library"]},{label:"ì²ë
ë¶",collections:["youth_members","youthMembers","youth_homes","youth_posts","youth_events","youth_challenges","youth_attendance"]},{label:"êµì¡ë¶ì (ì¤ë±/ê³ ë±/ì´ë±)",collections:["departments"]},{label:"í¬ê²ë",collections:["togetherMembers","togetherPosts","togetherGroups","togetherEvents"]},{label:"ë¨ì êµí/ì¬ì ëí",collections:["menPosts","menEvents","womenPosts","womenEvents","group_schedules","group_boards","group_prayers"]},{label:"문íê°ì¢/ìì¹´ë°ë¯¸",collections:["cultureSemesters","cultureCourses","cultureEnrollments","academyPrograms","academyEnrollments"]},{label:"ìì¤í
/ì¤ì ",collections:["church_settings","app_settings","system","fcm_tokens","notification_subscriptions","notification_settings","devices","error_reports","accessLogs"]}];function Te(){const{user:t}=oe(),[a,r]=m.useState("history"),[c,l]=m.useState([]),[x,N]=m.useState({auto_backup_enabled:!1,schedule_time:"03:00",retention_days:30,include_auth:!1}),[S,w]=m.useState(!1),[d,f]=m.useState(!0),[p,b]=m.useState(null),[i,v]=m.useState([]),[F,O]=m.useState({}),g=m.useCallback(async()=>{try{f(!0);const s=await h.getBackupHistory();l(s)}catch(s){console.error("ë°±ì
ì´ë ¥ ì¡°í ì¤í¨:",s),n.error("ë°±ì
ì´ë ¥ì ë¶ë¬ì¬ ì ììµëë¤.")}finally{f(!1)}},[]),D=m.useCallback(async()=>{try{const s=await h.getBackupSettings();N(s)}catch(s){console.error("ì¤ì ì¡°í ì¤í¨:",s)}},[]);m.useEffect(()=>{g(),D()},[g,D]);const G=async()=>
1{if(!p&&confirm("ì ì²´ ë°ì´í°ë² ì´ì¤ë¥¼ ë°±ì
í©ëë¤. ëª ë¶ì´ ììë ì ììµëë¤. ì§ííìê² ìµëê¹?"))try{b("full"),n.loading("ì ì²´ ë°±ì
ì§í ì¤...",{id:"backup"});const s=await h.startFullBackup();n.success(`ì ì²´ ë°±ì
ìë£! ${s.totalDocs.toLocaleString()}ê° ë¬¸ì, ${k(s.totalSize)}`,{id:"backup",duration:5e3}),g()}catch(s){n.error(`ë°±ì
ì¤í¨: ${s.message}`,{id:"backup"})}finally{b(null)}},M=async()=>{if(!p){if(i.length===0){n.error("ë°±ì
í 컬ë ì
ì ì íí´ì£¼ì¸ì.");return}if(confirm(`${i.length}ê° ì»¬ë ì
ì ë°±ì
í©ëë¤. ì§ííìê² ìµëê¹?`))try{b("selective"),n.loading("ì í ë°±ì
ì§í ì¤...",{id:"backup"});const s=await h.startSelectiveBackup(i);n.success(`ì í ë°±ì
ìë£! ${s.totalDocs.toLocaleString()}ê° ë¬¸ì, ${k(s.totalSize)}`,{id:"backup",duration:5e3}),v([]),g()}catch(s){n.error(`ë°±ì
ì¤í¨: ${s.message}`,{id:"backup"})}finally{b(null)}}},z=async()=>{if(!p&&confirm("ì¬ì©ì ê³ì ì 보를 ë°±ì
í©ëë¤. ì§ííìê² ìµëê¹?"))try{b("auth"),n.loading("ì¬ì©ì ê³ì ë°±ì
ì§í ì¤...",{id:"backup"});const s=await h.startAuthBackup();n.success(`ê³ì ë°±ì
ìë£! ${s.userCount}ëª
, ${k(s.totalSize)}`,{id:"backup",duration:5e3}),g()}catch(s){n.error(`ë°±ì
ì¤í¨: ${s.message}`,{id:"backup"})}finally{b(null)}},H=async s=>{if(!s.output_uri){n.error("ë¤ì´ë¡ë ê²½ë¡ê° ììµëë¤.");return}try{n.loading("ë¤ì´ë¡ë URL ìì± ì¤...",{id:"download"});const o=`${s.output_uri}_metadata.json`,u=await h.getDownloadUrl(o);window.open(u,"_blank"),n.success("ë¤ì´ë¡ëê° ììë©ëë¤.",{id:"download"})}catch{try{if(s.collections&&s.collections.length>0){const o=s.collections[0],u=`${s.output_uri}${o}.json`,B=await h.getDownloadUrl(u);window.open(B,"_blank"),n.success("ë¤ì´ë¡ëê° ììë©ëë¤.",{id:"download"})}else n.error("ë¤ì´ë¡ëí íì¼ì ì°¾ì ì ììµëë¤.",{id:"download"})}catch(o){n.error(`ë¤ì´ë¡ë ì¤í¨: ${o.message}`,{id:"download"})}}},K=async s=>{if(confirm(`ì´ ë°±ì
ì ìì íìê² ìµëê¹? (${U(s.created_at)})`))try{await h.deleteBackup(s.id),n.success("ë°±ì
ì´ ìì ëììµëë¤."),g()}catch(o){n.error(`ìì ì¤í¨: ${o.message}`)}},R=async()=>{if(t!=null&&t.uid)try{w(!0),await h.saveBackupSettings(x,t.uid),n.success("ë°±ì
ì¤ì ì´ ì ì¥ëììµëë¤.")}catch(s){n.error(`ì¤ì ì ì¥ ì¤í¨: ${s.message}`)}finally{w(!1)}},q=s=>{O(o=>({...o,[s]:!o[s]}))},I=s=>{v(o=>o.includes(s)?o.filter(u=>u!==s):[...o,s])},Y=s=>{const o=s.every(u=>i.includes(u));v(o?u=>u.filter(B=>!s.includes(B)):u=>[...new Set([...u,...s])])},J=[{key:"history",label:"ë°±ì
íí©",icon:E},{key:"manual",label:"ìë ë°±ì
",icon:Q},{key:"settings",label:"ìë ë°±ì
ì¤ì ",icon:V}];return e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-10 h-10 bg-blue-50 rounded-xl flex items-center justify-center",children:e.jsx($,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900",children:"ë°ì´í° ë°±ì
"}),e.jsx("p",{className:"text-sm text-gray-500",children:"ì ì²´ íë«í¼ ë°ì´í°ë¥¼ ìì íê² ë°±ì
íê³ ê´ë¦¬í©ëë¤."})]})]}),e.jsx("div",{className:"flex border-b border-gray-200 mb-6",children:J.map(s=>e.jsxs("button",{onClick:()=>r(s.key),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium border-b-2 transition-colors ${a===s.key?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:[e.jsx(s.icon,{className:"w-4 h-4"}),s.label]},s.key))}),a==="history"&&e.jsx(_e,{history:c,loading:d,onRefresh:g,onDownload:H,onDelete:K}),a==="manual"&&e.jsx(we,{backupRunning:p,selectedCollections:i,expandedGroups:F,onFullBackup:G,onSelectiveBackup:M,onAuthBackup:z,onToggleGroup:q,onToggleCollection:I,onToggleGroupCollections:Y}),a==="settings"&&e.jsx(ve,{settings:x,loading:S,onSettingsChange:N,onSave:R})]})}function _e({history:t,loading:a,onRefresh:r,onDownload:c,onDelete:l}){return a?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(_,{className:"w-8 h-8 text-blue-500 animate-spin"})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("p",{className:"text-sm text-gray-500",children:["ì´ ",t.length,"ê°ì ë°±ì
기ë¡"]}),e.jsxs("button",{onClick:r,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors",children:[e.jsx(W,{className:"w-4 h-4"}),"ìë¡ê³ 침"]})]}),t.length===0?e.jsxs("div",{className:"text-center py-20 bg-gray-50 rounded-xl",children:[e.jsx($,{className:"w-12 h-12 text-gray-300 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-500",children:"ìì§ ë°±ì
기ë¡ì´ ììµëë¤."}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"'ìë ë°±ì
' íìì 첫 ë°±ì
ì ììíì¸ì."})]}):e.jsx("div",{className:"space-y-3",children:t.map(x=>e.jsx(Ne,{record:x,onDownload:()=>c(x),onDelete:()=>l(x)},x.id))})]})}function Ne({record:t,onDownload:a,onDelete:r}){const c=ye[t.status];return e.jsx("div",{className:"bg-white border border-gray-200 rounded-xl p-4 hover:shadow-sm transition-shadow",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded-full ${c.bg} ${c.text}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${c.dot}`}),fe[t.status]]}),e.jsx("span",{className:"text-xs text-gray-400",children:ge[t.type]})]}),e.jsx("p",{className:"text-sm font-medium text-gray-900",children:U(t.created_at)}),e.jsxs("div",{className:"flex items-center gap-4 mt-1.5 text-xs text-gray-500",children:[t.document_count!==void 0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(P,{className:"w-3.5 h-3.5"}
1),t.document_count.toLocaleString(),"ê° ë¬¸ì"]}),t.file_size_bytes!==void 0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(se,{className:"w-3.5 h-3.5"}),k(t.file_size_bytes)]}),t.created_by==="system"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(E,{className:"w-3.5 h-3.5"}),"ìë ë°±ì
"]}):e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ae,{className:"w-3.5 h-3.5"}),"ìë ë°±ì
"]})]}),t.error_message&&e.jsx("p",{className:"mt-2 text-xs text-red-600 bg-red-50 p-2 rounded-lg",children:t.error_message})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[t.status==="completed"&&t.output_uri&&e.jsx("button",{onClick:a,className:"p-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",title:"ë¤ì´ë¡ë",children:e.jsx(le,{className:"w-4 h-4"})}),e.jsx("button",{onClick:r,className:"p-2 text-red-500 hover:bg-red-50 rounded-lg transition-colors",title:"ìì ",children:e.jsx(ne,{className:"w-4 h-4"})})]})]})})}function we({backupRunning:t,selectedCollections:a,expandedGroups:r,onFullBackup:c,onSelectiveBackup:l,onAuthBackup:x,onToggleGroup:N,onToggleCollection:S,onToggleGroupCollections:w}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("button",{onClick:c,disabled:!!t,className:"flex items-center gap-3 p-4 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-sm",children:[t==="full"?e.jsx(_,{className:"w-8 h-8 animate-spin"}):e.jsx($,{className:"w-8 h-8"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-bold",children:"ì ì²´ ë°±ì
"}),e.jsx("p",{className:"text-xs text-blue-100",children:"모ë Firestore ë°ì´í°"})]})]}),e.jsxs("button",{onClick:x,disabled:!!t,className:"flex items-center gap-3 p-4 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-sm",children:[t==="auth"?e.jsx(_,{className:"w-8 h-8 animate-spin"}):e.jsx(X,{className:"w-8 h-8"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-bold",children:"ê³ì ë°±ì
"}),e.jsx("p",{className:"text-xs text-blue-100",children:"Firebase Auth ì¬ì©ì"})]})]}),e.jsxs("button",{onClick:l,disabled:!!t||a.length===0,className:"flex items-center gap-3 p-4 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-sm",children:[t==="selective"?e.jsx(_,{className:"w-8 h-8 animate-spin"}):e.jsx(P,{className:"w-8 h-8"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-bold",children:"ì í ë°±ì
"}),e.jsx("p",{className:"text-xs text-blue-100",children:a.length>0?`${a.length}ê° ì»¬ë ì
ì íë¨`:"ìëìì 컬ë ì
ì í"})]})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-xl",children:[e.jsxs("div",{className:"p-4 border-b border-gray-100",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"컬ë ì
ì í (ì í ë°±ì
ì©)"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"ë°±ì
í ë°ì´í° 그룹ì ì ííì¸ì. ë¯¼ê° ë°ì´í°ë ë³ë íìë©ëë¤."})]}),e.jsx("div",{className:"divide-y divide-gray-100",children:je.map(d=>{const f=r[d.label],p=d.collections.filter(i=>a.includes(i)).length,b=p===d.collections.length;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between p-3 hover:bg-gray-50 cursor-pointer",onClick:()=>N(d.label),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:i=>{i.stopPropagation(),w(d.collections)},className:"w-4 h-4 text-blue-500 rounded border-gray-300"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:d.label}),d.sensitive&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-amber-100 text-amber-700 rounded",children:"민ê°"}),p>0&&e.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-100 text-blue-700 rounded",children:[p,"/",d.collections.length]})]}),f?e.jsx(Z,{className:"w-4 h-4 text-gray-400"}):e.jsx(ee,{className:"w-4 h-4 text-gray-400"})]}),f&&e.jsx("div",{className:"px-4 pb-3 ml-7 space-y-1",children:d.collections.map(i=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-gray-50 rounded cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.includes(i),onChange:()=>S(i),className:"w-3.5 h-3.5 text-blue-500 rounded border-gray-300"}),e.jsx("code",{className:"text-xs text-gray-600 bg-gray-100 px-1.5 py-0.5 rounded",children:i})]},i))})]},d.label)})})]})]})}function ve({settings:t,loading:a,onSettingsChange:r,onSave:c}
1){return e.jsx("div",{className:"max-w-xl",children:e.jsxs("div",{className:"bg-white border border-gray-200 rounded-xl p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-1",children:"ìë ë°±ì
ì¤ì "}),e.jsx("p",{className:"text-xs text-gray-500",children:"ë§¤ì¼ ìëì¼ë¡ 주ì ë°ì´í°ë¥¼ ë°±ì
í©ëë¤."})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700",children:"ìë ë°±ì
"}),e.jsx("p",{className:"text-xs text-gray-500",children:"ë§¤ì¼ ìë²½ 3ìì ìë ì¤í"})]}),e.jsx("button",{onClick:()=>r({...t,auto_backup_enabled:!t.auto_backup_enabled}),className:`relative w-11 h-6 rounded-full transition-colors ${t.auto_backup_enabled?"bg-blue-500":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow transition-transform ${t.auto_backup_enabled?"translate-x-5":""}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"ë³´ê´ ê¸°ê°"}),e.jsxs("select",{value:t.retention_days,onChange:l=>r({...t,retention_days:Number(l.target.value)}),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:7,children:"7ì¼"}),e.jsx("option",{value:30,children:"30ì¼"}),e.jsx("option",{value:90,children:"90ì¼"}),e.jsx("option",{value:0,children:"ì구 ë³´ê´"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:t.retention_days>0?`${t.retention_days}ì¼ì´ ì§ë ìë ë°±ì
ì ìëì¼ë¡ ìì ë©ëë¤.`:"ìë ë°±ì
ì´ ìì ëì§ ììµëë¤. ìëì¼ë¡ ê´ë¦¬í´ì£¼ì¸ì."})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700",children:"ê³ì ì ë³´ í¬í¨"}),e.jsx("p",{className:"text-xs text-gray-500",children:"ìë ë°±ì
ì Auth ë°ì´í° í¬í¨"})]}),e.jsx("button",{onClick:()=>r({...t,include_auth:!t.include_auth}),className:`relative w-11 h-6 rounded-full transition-colors ${t.include_auth?"bg-blue-500":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow transition-transform ${t.include_auth?"translate-x-5":""}`})})]}),e.jsxs("button",{onClick:c,disabled:a,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-blue-500 text-white text-sm font-medium rounded-lg hover:bg-blue-600 disabled:opacity-50 transition-colors",children:[a?e.jsx(_,{className:"w-4 h-4 animate-spin"}):e.jsx(te,{className:"w-4 h-4"}),"ì¤ì ì ì¥"]})]})})}function k(t){if(t===0)return"0 B";const a=1024,r=["B","KB","MB","GB"],c=Math.floor(Math.log(t)/Math.log(a));return`${parseFloat((t/Math.pow(a,c)).toFixed(1))} ${r[c]}`}function U(t){if(!t)return"-";try{return new Date(t).toLocaleString("ko-KR",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}catch{return t}}export{Te as BackupManagementPage};
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.