1import{u as h,r as i,j as e,k as p,l as g,o as j,p as f,q as N,t as b,v as y,R as v,b5 as C,a5 as w,Z as k,y as E,a8 as M,ay as n}from"./index-C34-5sQl.js";import{A as L}from"./AdminLayout-CZRi1sII.js";import{S as A}from"./switch-yHgPvYHO.js";import{L as R}from"./label-Ck7Df8QO.js";import{C as c}from"./calendar-DCNUhSkt.js";import{C as m}from"./circle-alert-D53nCIRW.js";import{C as S}from"./circle-check-C0_E_5jr.js";import"./chart-column-C2IAlK0M.js";import"./dollar-sign-3rmWXEq_.js";import"./camera-CFUiLc3W.js";import"./eye-BE6O3arH.js";import"./git-branch-BuCDTQQU.js";function Z(){const{t:U}=h(),[l,d]=i.useState(!1),[r,x]=i.useState(!0),[s,o]=i.useState(null),u=async()=>{d(!0),o(null);try{const a=await E(M,"migrateFreeUsersCreditsExpiration")({dryRun:r});o(a.data),r?n.info("Simulation terminée",{description:`${a.data.usersToMigrate} utilisateurs à migrer`}):n.success("Migration terminée",{description:`${a.data.migratedCount} utilisateurs migrés`})}catch(t){n.error("Erreur lors de la migration",{description:t instanceof Error?t.message:String(t)})}finally{d(!1)}};return e.jsx(L,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Migrations"}),e.jsx("p",{className:"text-muted-foreground",children:"Outils de migration et de correction des données"})]})}),e.jsxs(p,{className:"border-primary/20",children:[e.jsx(g,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-gradient-to-br from-amber-500 to-orange-600 text-white",children:e.jsx(c,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx(j,{children:"Correction expiration crédits plan gratuit"}),e.jsx(f,{children:"Les crédits du plan gratuit ne devraient pas expirer. Cette migration corrige les utilisateurs existants en mettant expiresAt à null."})]})]})}),e.jsxs(N,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(R,{htmlFor:"dry-run",className:"text-base font-medium",children:"Mode simulation (Dry Run)"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"Aucune modification ne sera effectuée":"â ï¸ Les modifications seront appliquées en base"})]}),e.jsx(A,{id:"dry-run",checked:r,onCheckedChange:x})]}),!r&&e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-amber-500/50 bg-amber-500/10 p-4",children:[e.jsx(m,{className:"h-5 w-5 shrink-0 text-amber-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-amber-700 dark:text-amber-300",children:"Attention : Mode exécution réelle"}),e.jsx("p",{className:"text-sm text-amber-600 dark:text-amber-400",children:"Les modifications seront appliquées directement en base de données. Assurez-vous d'avoir testé en mode simulation avant."})]})]}),e.jsx(b,{onClick:u,disabled:l,className:"w-full gap-2",variant:r?"outline":"default",children:l?e.jsxs(e.Fragment,{children:[e.jsx(y,{className:"h-4 w-4 animate-spin"}),r?"Simulation en cours...":"Migration en cours..."]}):e.jsxs(e.Fragment,{children:[r?e.jsx(v,{className:"h-4 w-4"}):e.jsx(C,{className:"h-4 w-4"}),r?"Lancer la simulation":"Exécuter la migration"]})}),s&&e.jsxs("div",{className:"space-y-4 rounded-lg border bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold",children:"Résultats"}),e.jsx(w,{variant:s.dryRun?"secondary":"default",children:s.dryRun?"Simulation":"Exécuté"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border bg-background p-3 text-center",children:[e.jsx(k,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-1 text-2xl font-bold",children:s.totalFreeUsers}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Utilisateurs gratuits"})]}),e.jsxs("div",{className:"rounded-lg border bg-background p-3 text-center",children:[e.jsx(c,{className:"mx-auto h-5 w-5 text-amber-500"}),e.jsx("p",{className:"mt-1 text-2xl font-bold text-amber-600",children:s.usersToMigrate}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"à migrer"})]}),e.jsxs("div",{className:"rounded-lg border bg-background p-3 text-center",children:[e.jsx(S,{className:"mx-auto h-5 w-5 text-emerald-500"}),e.jsx("p",{className:"mt-1 text-2xl font-bold text-emerald-600",children:s.migratedCount}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Migrés"})]}),e.jsxs("div",{className:"rounded-lg border bg-background p-3 text-center",children:[e.jsx(m,{className:"mx-auto h-5 w-5 text-rose-500"}),e.jsx("p",{className:"mt-1 text-2xl font-bold text-rose-600",children:s.errors}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Erreurs"})]})]}),s.details.usersToMigrate.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-sm font-medium",children:["Utilisateurs à migrer (",s.usersToMigrate,")"]}),e.jsx("div",{className:"max-h-60 overflow-auto rounded-lg border bg-background",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Email"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"User ID"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Expiration actuelle"})]})}),e.jsx("tbody",{children:s.details.usersToMigrate.map((t,a)=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"px-3 py-2",children:t.email}),e.jsxs("td",{className:"px-3 py-2 font-mono text-xs",children:[t.userId.slice(0,12),"..."]}),e.jsx("td",{className:"px-3 py-2",children:t.currentExpiresAt?new Date(t.currentExpiresAt).toLocaleDateString():"N/A"})]},a))})]})})]}),s.details.errors.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-sm font-medium text-rose-600",children:["Erreurs (",s.errors,")"]}),e.jsx("div",{className:"max-h-40 overflow-auto rounded-lg border border-rose-500/30 bg-rose-500/10 p-3",children:s.details.errors.map((t,a)=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-mono",children:t.userId}),":"," ",t.error]},a))})]})]})]})]})]})})}export{Z 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.