import{r as a,j as e}from"./react-D_B_5QVd.js";import{a as h,B as g,L as m,A as j,M as b}from"./index-BdwitBZy.js";import{d as y}from"./fileUtils-Dvg4vqd5.js";import"./jszip-C9ownNzX.js";import"./react-dom-EAO2-NBm.js";import"./scheduler-DYLXRpC5.js";import"./@google-4tyssLU_.js";import"./marked-CesSW9Du.js";import"./idb-Dob3nYDb.js";const N=`import React from 'react'; export const Greeting = ({ name }) => { if (!name) { return
Hello, Guest!
; } return
Hello, {name}!
; };`,E=()=>{const[n,f]=a.useState(N),[s,i]=a.useState(""),[r,d]=a.useState(!1),[l,c]=a.useState(""),p=a.useCallback(async()=>{if(!n.trim()){c("Please enter some code to generate tests for.");return}d(!0),c(""),i("");try{const t=h(n);let o="";for await(const u of t)o+=u,i(o)}catch(t){const o=t instanceof Error?t.message:"An unknown error occurred.";c(`Failed to generate tests: ${o}`)}finally{d(!1)}},[n]),x=t=>t.replace(/^```(?:\w+\n)?/,"").replace(/```$/,"");return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center",children:[e.jsx(g,{}),e.jsx("span",{className:"ml-3",children:"AI Unit Test Generator"})]}),e.jsx("p",{className:"text-text-secondary mt-1",children:"Provide a function or component and let AI write the tests."})]}),e.jsxs("div",{className:"flex-grow flex flex-col gap-4 min-h-0",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsx("label",{htmlFor:"code-input",className:"text-sm font-medium text-text-secondary mb-2",children:"Source Code"}),e.jsx("textarea",{id:"code-input",value:n,onChange:t=>f(t.target.value),placeholder:"Paste your source code here...",className:"flex-grow p-4 bg-surface border border-border rounded-md resize-none font-mono text-sm focus:ring-2 focus:ring-primary focus:outline-none"})]}),e.jsx("div",{className:"flex-shrink-0",children:e.jsx("button",{onClick:p,disabled:r,className:"btn-primary w-full max-w-xs mx-auto flex items-center justify-center px-6 py-3",children:r?e.jsx(m,{}):"Generate Unit Tests"})}),e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("label",{className:"text-sm font-medium text-text-secondary",children:"Generated Tests"}),s&&!r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>navigator.clipboard.writeText(x(s)),className:"px-3 py-1 bg-gray-100 text-xs rounded-md hover:bg-gray-200",children:"Copy Code"}),e.jsxs("button",{onClick:()=>y(x(s),"tests.tsx","text/typescript"),className:"flex items-center gap-1 px-3 py-1 bg-gray-100 text-xs rounded-md hover:bg-gray-200",children:[e.jsx(j,{className:"w-4 h-4"})," Download"]})]})]}),e.jsxs("div",{className:"flex-grow p-1 bg-background border border-border rounded-md overflow-y-auto",children:[r&&!s&&e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(m,{})}),l&&e.jsx("p",{className:"p-4 text-red-500",children:l}),s&&e.jsx(b,{content:s}),!r&&!s&&!l&&e.jsx("div",{className:"text-text-secondary h-full flex items-center justify-center",children:"The generated tests will appear here."})]})]})]})]})};export{E as AiUnitTestGenerator}; //# sourceMappingURL=AiUnitTestGenerator-CglcTDBa.js.map