1import{r as i,j as e,T as h,e0 as b,F as N,d as C,dP as k,aU as w,q as A,I}from"./ui-vendor-Cm2ZkKHv.js";import{C as y,a as S,b as E,c as T,d as R}from"./card-CyibmazC.js";import{L as B,I as D,j as g,B as F,C as z,aC as M}from"./index-DVu_w4ho.js";import{S as L}from"./switch-CZO0JRho.js";import{A as Z,b as P,a as V}from"./alert-DclhisZg.js";import{A as q,a as O,b as U,c as G,d as H,e as K,f as W,g as J}from"./alert-dialog-DtkKANN3.js";import{t as Q}from"./tenantBackupService--TlD_j-l.js";import"./radix-vendor-CtEXKD-D.js";import"./chart-vendor-b_bTPWgQ.js";import"./table-vendor-C2kIG4hh.js";import"./react-vendor-DVzxkp4A.js";const X=s=>{if(s===0)return"0 Bytes";const n=1024,o=["Bytes","KB","MB","GB"],d=Math.floor(Math.log(s)/Math.log(n));return parseFloat((s/Math.pow(n,d)).toFixed(2))+" "+o[d]},de=()=>{const[s,n]=i.useState(null),[o,d]=i.useState(!0),[r,m]=i.useState(!1),[f,c]=i.useState(!1),[x,p]=i.useState(!1),{toast:l}=M(),a=i.useMemo(()=>s?{name:s.name,size:X(s.size),lastModified:new Date(s.lastModified).toLocaleString("es-GT"),isValidZip:s.name.toLowerCase().endsWith(".zip")}:null,[s]),j=()=>{if(!s){l({variant:"destructive",title:"Archivo requerido",description:"Selecciona un archivo .zip para continuar."});return}if(!(a!=null&&a.isValidZip)){l({variant:"destructive",title:"Formato incorrecto",description:"El archivo seleccionado debe tener extensión .zip."});return}p(!1),c(!0)},v=async()=>{if(s)try{m(!0),c(!1);const t=await Q.importBackup(s,o);if(!t.success)throw new Error(t.error||"No se pudo importar el backup");l({title:"Restauración completada con éxito",description:"El paquete de respaldo fue procesado e integrado en el tenant activo."}),n(null)}catch(t){l({variant:"destructive",title:"Error en la restauración",description:(t==null?void 0:t.message)||"No se pudo importar el backup."})}finally{m(!1)}};return e.jsxs("div",{className:"space-y-6 max-w-4xl",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight text-foreground",children:"Importar Backup Tenant"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Carga un archivo ZIP de respaldo para restaurar o migrar los datos del tenant activo."})]}),e.jsxs(Z,{variant:"destructive",className:"border-destructive/40 bg-destructive/10",children:[e.jsx(h,{className:"h-4 w-4 text-destructive"}),e.jsx(P,{className:"font-semibold",children:"Zona de Alto Impacto Operativo"}),e.jsx(V,{className:"text-xs text-muted-foreground mt-1",children:"La restauración de respaldo interactúa directamente con la base de datos y archivos multimedia del tenant en sesión. Asegúrate de haber verificado el origen del archivo antes de proceder."})]}),e.jsxs(y,{children:[e.jsxs(S,{children:[e.jsxs(E,{className:"flex items-center gap-2 text-base",children:[e.jsx(b,{className:"h-5 w-5 text-primary"}),"Paquete de Respaldo a Restaurar"]}),e.jsx(T,{children:"Formato requerido: archivo .ZIP generado mediante la herramienta de exportación de tenant."})]}),e.jsxs(R,{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"backup-file",className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Seleccionar Archivo (.ZIP)"}),e.jsx(D,{id:"backup-file",type:"file",accept:".zip,application/zip",onChange:t=>{var u;return n(((u=t.target.files)==null?void 0:u[0])||null)},className:"bg-background/60"})]}),a&&e.jsxs("div",{className:"p-3.5 rounded-lg border border-border/70 bg-muted/30 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-sm font-semibold text-foreground truncate max-w-xs sm:max-w-md",children:a.name})]}),a.isValidZip?e.jsx(g,{variant:"outline",className:"border-emerald-500/40 text-emerald-600 dark:text-emerald-400 bg-emerald-500/5 text-xs",children:"ZIP Válido"}):e.jsx(g,{variant:"destructive",className:"text-xs",children:"Formato Inválido"})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2 text-xs text-muted-foreground border-t border-border/40 pt-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-[10px] uppercase font-medium",children:"Tamaño"}),e.jsx("span",{className:"font-semibold text-foreground",children:a.size})]}),e.jsxs("div",{children:[e.jsx("span",{className:"block text-[10px] uppercase font-medium",children:"Ãltima Modificación"}),e.jsx("span",{className:"font-medium text-foreground",children:a.lastModified})]}),e.jsxs("div",{className:"col-span-2 sm:col-span-1",children:[e.jsx("span",{className:"block text-[10px] uppercase font-medium",children:"Estado"}),e.jsxs("span",{className:"font-medium text-emerald-600 dark:text-emerald-400 flex items-center gap-1",children:[e.jsx(C,{className:"h-3 w-3"})," Listo para inspección"]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border/60 p-3.5 bg-background",children:[e.jsxs("div",{className:"space-y-0.5 pr-4",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Sobrescribir datos existentes del tenant"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Si está activo, purga previamente los registros de las entidades del tenant antes de importar. Si está inactivo, agrega los datos sin borrar los previos."})]}),e.jsx(L,{checked:o,onCheckedChange:d})]}),e.jsxs(F,{onClick:j,disabled:r||!s,className:"gap-2 w-full sm:w-auto",children:[r?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(w,{className:"h-4 w-4"}),r?"Restaurando...":"Iniciar Restauración"]})]})]}),e.jsx(q,{open:f,onOpenChange:c,children:e.jsxs(O,{className:"max-w-md",children:[e.jsxs(U,{children:[e.jsxs("div",{className:"flex items-center gap-2.5 text-destructive",children:[e.jsx(A,{className:"h-5 w-5"}),e.jsx(G,{children:"Confirmar Restauración de Tenant"})]}),e.jsx(H,{asChild:!0,children:e.jsxs("div",{className:"space-y-3 pt-2 text-sm text-foreground",children:[e.jsxs("p",{children:["Estás a punto de restaurar el respaldo ",e.jsx("strong",{children:s==null?void 0:s.name})," (",a==null?void 0:a.size,") en el tenant activo."]}),o?e.jsxs("div",{className:"p-3 rounded-md bg-destructive/10 border border-destructive/30 text-destructive text-xs space-y-1",children:[e.jsxs("p",{className:"font-bold flex items-center gap-1.5",children:[e.jsx(h,{className:"h-3.5 w-3.5 shrink-0"}),"ACCIÃN DESTRUCTIVA E IRREVERSIBLE"]}),e.jsx("p",{className:"text-destructive/90",children:"La opción de sobrescritura está ACTIVADA. Todos los registros actuales del tenant serán purgados y reemplazados por el contenido de este archivo ZIP."})]}):e.jsxs("div",{className:"p-3 rounded-md bg-muted/60 border border-border/60 text-xs space-y-1 text-muted-foreground",children:[e.jsxs("p",{className:"font-semibold text-foreground flex items-center gap-1.5",children:[e.jsx(I,{className:"h-3.5 w-3.5 text-primary shrink-0"}),"Fusión de datos"]}),e.jsx("p",{children:"Los datos del respaldo se añadirán a los registros existentes del tenant sin eliminarlos previamente."})]}),e.jsxs("div",{className:"flex items-start space-x-2 pt-2",children:[e.jsx(z,{id:"confirm-risk",checked:x,onCheckedChange:t=>p(!!t)}),e.jsx("label",{htmlFor:"confirm-risk",className:"text-xs text-muted-foreground leading-tight cursor-pointer select-none",children:"Entiendo el impacto de esta operación y confirmo la ejecución de la restauración."})]})]})})]}),e.jsxs(K,{className:"mt-4 gap-2",children:[e.jsx(W,{disabled:r,children:"Cancelar"}),e.jsx(J,{onClick:v,disabled:!x||r,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:r?"Procesando...":"Confirmar e Importar"})]})]})})]})};export{de 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.