import{o as e}from"./chunk-QXcFz7f5.js";import{c as t,t as n}from"./app-G6wC4CCm.js";import{f as r,g as i,l as a,p as o}from"./ui-D0zPIw82.js";import{n as s}from"./shared-BpivAtxV.js";var c=e(t(),1),l=n();function u({kit:e,onClose:t,onDeleted:n}){let[u,d]=(0,c.useState)(``),[f,p]=(0,c.useState)(!1),[m,h]=(0,c.useState)(null),g=u===e.key,_=async()=>{if(!(!g||f)){p(!0),h(null);try{let t=await fetch(`/admin/kits/${encodeURIComponent(e.key)}`,{method:`DELETE`,credentials:`same-origin`,headers:s(),body:JSON.stringify({confirm_key:e.key})});if(!t.ok&&t.status!==204){h((await t.json().catch(()=>null))?.message??`Delete failed (${t.status}).`);return}n()}catch{h(`Network error. Try again.`)}finally{p(!1)}}};return(0,l.jsxs)(a,{open:!0,onClose:t,size:`md`,onSubmit:e=>{e.preventDefault(),_()},closeOnBackdrop:!1,closeOnEsc:!f,"data-testid":`admin-kits-delete-modal`,"aria-labelledby":`admin-kits-delete-title`,children:[(0,l.jsx)(a.Header,{eyebrow:`Delete kit`,eyebrowClassName:`text-destructive`,titleId:`admin-kits-delete-title`,title:(0,l.jsxs)(l.Fragment,{children:[`Delete “`,e.name,`”?`]})}),(0,l.jsxs)(a.Body,{fade:!1,children:[(0,l.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This will remove the kit's files + marketing previews. This cannot be undone. Existing projects that were scaffolded from this kit aren't affected — they own copies of the assets.`}),(0,l.jsxs)(`div`,{children:[(0,l.jsxs)(r,{htmlFor:`admin-kits-delete-confirm-input`,children:[`Type the kit key`,` `,(0,l.jsx)(`span`,{className:`font-mono text-[11px] text-foreground/80`,children:e.key}),` `,`to confirm`]}),(0,l.jsx)(o,{id:`admin-kits-delete-confirm-input`,value:u,onChange:e=>d(e.target.value),placeholder:e.key,className:`mt-1 font-mono`,disabled:f,autoFocus:!0,"data-testid":`admin-kits-delete-confirm-input`})]}),m&&(0,l.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,"data-testid":`admin-kits-delete-error`,children:m})]}),(0,l.jsxs)(a.Footer,{children:[(0,l.jsx)(i,{type:`button`,variant:`ghost`,onClick:t,disabled:f,children:`Cancel`}),(0,l.jsx)(i,{type:`button`,variant:`danger`,onClick:_,disabled:!g||f,"data-testid":`admin-kits-delete-confirm`,children:f?`Deleting…`:`Delete kit`})]})]})}export{u as DeleteModal};