import{h as N,g as c,k as B,l as e,L as D,B as i,R as n,v as o,y as d,z as m,A as E,w as x,j as h}from"./index-CQ7DJRNL.js";import{D as b}from"./database-BZl-0QP4.js";import{P as M}from"./plus-DFYoktwD.js";import{C as S}from"./clock-hkQwCYtX.js";import{D as z}from"./download-D3NtqG_i.js";import{T as A}from"./trash-2-8OuYgQfp.js";import{C as F}from"./circle-alert-Dq6_hFem.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const R=N("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const L=N("FileJson",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"1oajmo"}],["path",{d:"M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"mpwhp6"}]]),G=()=>{const[p,v]=c.useState([]),[l,u]=c.useState(!0),[f,j]=c.useState(!1),{toast:t}=B(),r=async()=>{u(!0);try{const s=await h.listBackups();if(s.error)throw new Error(s.error);v(s.data||[])}catch(s){t({title:"Error",description:s instanceof Error?s.message:"Failed to load backups",variant:"destructive"})}finally{u(!1)}};c.useEffect(()=>{r()},[]);const g=async()=>{j(!0);try{const s=await h.createBackup();if(s.error)throw new Error(s.error);t({title:"Success",description:"Database backup created successfully"}),r()}catch(s){t({title:"Error",description:s instanceof Error?s.message:"Backup failed",variant:"destructive"})}finally{j(!1)}},k=async s=>{if(confirm(`Are you sure you want to delete backup ${s}?`))try{const a=await h.deleteBackup(s);if(a.error)throw new Error(a.error);t({title:"Deleted",description:"Backup archive removed"}),r()}catch(a){t({title:"Error",description:a instanceof Error?a.message:"Deletion failed",variant:"destructive"})}},w=s=>{if(s===0)return"0 Bytes";const a=1024,C=["Bytes","KB","MB","GB"],y=Math.floor(Math.log(s)/Math.log(a));return parseFloat((s/Math.pow(a,y)).toFixed(2))+" "+C[y]};return e.jsx(D,{children:e.jsxs("div",{className:"container mx-auto p-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-2",children:[e.jsx(b,{className:"w-8 h-8 text-flashcore-purple"}),"Backup & Recovery"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Manage database snapshots and system backups for disaster recovery."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(i,{variant:"outline",onClick:r,disabled:l,children:[e.jsx(n,{className:`w-4 h-4 mr-2 ${l?"animate-spin":""}`}),"Refresh"]}),e.jsx(i,{onClick:g,disabled:f,children:f?e.jsxs(e.Fragment,{children:[e.jsx(n,{className:"w-4 h-4 mr-2 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"w-4 h-4 mr-2"}),"Create Snapshot"]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs(o,{className:"md:col-span-2",children:[e.jsxs(d,{children:[e.jsx(m,{children:"Backup History"}),e.jsx(E,{children:"A list of all available database snapshots."})]}),e.jsx(x,{children:l?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(n,{className:"w-8 h-8 animate-spin text-flashcore-purple"})}):p.length===0?e.jsxs("div",{className:"text-center py-12 border-2 border-dashed rounded-xl",children:[e.jsx(b,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4 opacity-20"}),e.jsx("p",{className:"text-muted-foreground",children:"No backups found."}),e.jsx(i,{variant:"link",onClick:g,className:"mt-2 text-flashcore-purple",children:"Create your first backup now"})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-sm font-medium text-muted-foreground",children:[e.jsx("th",{className:"text-left py-3 px-4",children:"Filename"}),e.jsx("th",{className:"text-left py-3 px-4",children:"Date Created"}),e.jsx("th",{className:"text-left py-3 px-4",children:"Size"}),e.jsx("th",{className:"text-right py-3 px-4",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:p.map(s=>e.jsxs("tr",{className:"hover:bg-muted/50 transition-colors",children:[e.jsx("td",{className:"py-4 px-4 font-mono text-xs",children:s.filename}),e.jsx("td",{className:"py-4 px-4 text-sm",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(S,{className:"w-3 h-3 opacity-50"}),s.created_at]})}),e.jsx("td",{className:"py-4 px-4 text-sm font-medium",children:w(s.size)}),e.jsx("td",{className:"py-4 px-4 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("a",{href:`/fcorex/backend/api/backups.php?action=download&filename=${s.filename}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-9 w-9",title:"Download",children:e.jsx(z,{className:"h-4 w-4"})}),e.jsx(i,{variant:"outline",size:"icon",className:"text-destructive hover:bg-destructive/10",onClick:()=>k(s.filename),title:"Delete",children:e.jsx(A,{className:"h-4 w-4"})})]})})]},s.filename))})]})})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(o,{children:[e.jsx(d,{children:e.jsx(m,{className:"text-lg",children:"Storage Health"})}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-green-500/10 rounded-lg border border-green-500/20",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(R,{className:"w-5 h-5 text-green-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Permissions"})]}),e.jsx("span",{className:"text-xs font-bold text-green-500",children:"Writable"})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-blue-500/10 rounded-lg border border-blue-500/20",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{className:"w-5 h-5 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Protection"})]}),e.jsx("span",{className:"text-xs font-bold text-blue-500",children:"Locked"})]}),e.jsx("div",{className:"pt-2",children:e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Backups are stored in a secured directory protected by .htaccess. Recommended frequency: **Daily**."})})]})]}),e.jsxs(o,{className:"bg-gradient-to-br from-flashcore-purple/10 via-background to-flashcore-green/10 border-flashcore-purple/20",children:[e.jsx(d,{children:e.jsx(m,{className:"text-lg",children:"Quick Tip"})}),e.jsxs(x,{children:[e.jsx("p",{className:"text-sm text-muted-foreground italic leading-relaxed",children:'"Always verify your backups after creation. A backup that cannot be restored is no backup at all."'}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx(L,{className:"w-8 h-8 opacity-20"})})]})]})]})]})]})})};export{G as default};
