demoo / assets /AiCodeExplainer-C0HS8Khr.js
admin08077's picture
Upload 85 files
edfe4af verified
import{r,j as e}from"./react-D_B_5QVd.js";import{e as g,a as b}from"./index-QBya0NjG.js";import{M as N}from"./MarkdownRenderer-BDaVxTSW.js";import"./jszip-C9ownNzX.js";import"./react-dom-EAO2-NBm.js";import"./scheduler-DYLXRpC5.js";import"./@google-4tyssLU_.js";import"./idb-Dob3nYDb.js";import"./marked-CesSW9Du.js";const f=({text:l="AI is analyzing..."})=>e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-cyan-400 animate-pulse",style:{animationDelay:"0s"}}),e.jsx("div",{className:"w-2 h-2 rounded-full bg-cyan-400 animate-pulse",style:{animationDelay:"0.2s"}}),e.jsx("div",{className:"w-2 h-2 rounded-full bg-cyan-400 animate-pulse",style:{animationDelay:"0.4s"}}),e.jsx("span",{className:"text-slate-400 ml-2",children:l})]}),v=`const bubbleSort = (arr) => {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
}
}
return arr;
};`,T=({initialCode:l})=>{const[d,m]=r.useState(l||v),[a,x]=r.useState(null),[n,u]=r.useState(!1),[i,c]=r.useState(""),[p,h]=r.useState("summary"),o=r.useCallback(async s=>{if(!s.trim()){c("Please enter some code to explain.");return}u(!0),c(""),x(null),h("summary");try{const t=await g(s);x(t)}catch(t){const y=t instanceof Error?t.message:"An unknown error occurred.";c(`Failed to get explanation: ${y}`)}finally{u(!1)}},[]);r.useEffect(()=>{l&&(m(l),o(l))},[l,o]);const j=()=>{if(!a)return null;switch(p){case"summary":return e.jsx(N,{content:a.summary});case"lineByLine":return e.jsx("div",{className:"space-y-3",children:a.lineByLine.map((s,t)=>e.jsxs("div",{className:"p-3 bg-slate-900/50 rounded-md",children:[e.jsxs("p",{className:"font-mono text-xs text-cyan-400 mb-1",children:["Lines: ",s.lines]}),e.jsx("p",{className:"text-sm",children:s.explanation})]},t))});case"complexity":return e.jsxs("div",{children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Time Complexity:"})," ",e.jsx("span",{className:"font-mono text-amber-400",children:a.complexity.time})]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Space Complexity:"})," ",e.jsx("span",{className:"font-mono text-amber-400",children:a.complexity.space})]})]});case"suggestions":return e.jsx("ul",{className:"list-disc list-inside space-y-2",children:a.suggestions.map((s,t)=>e.jsx("li",{children:s},t))})}};return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-slate-300",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold text-slate-100 flex items-center",children:[e.jsx(b,{}),e.jsx("span",{className:"ml-3",children:"AI Code Explainer"})]}),e.jsx("p",{className:"text-slate-400 mt-1",children:"Get a detailed, structured analysis of any code snippet."})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-1 lg:grid-cols-2 gap-6 min-h-0",children:[e.jsxs("div",{className:"flex flex-col min-h-0",children:[e.jsx("label",{htmlFor:"code-input",className:"text-sm font-medium text-slate-400 mb-2",children:"Your Code"}),e.jsx("textarea",{id:"code-input",value:d,onChange:s=>m(s.target.value),placeholder:"Paste your code here...",className:"flex-grow p-4 bg-slate-900 border border-slate-700 rounded-md resize-none font-mono text-sm text-cyan-300 focus:ring-2 focus:ring-cyan-500 focus:outline-none"}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:()=>o(d),disabled:n,className:"w-full flex items-center justify-center px-6 py-3 bg-cyan-500 text-slate-900 font-bold rounded-md hover:bg-cyan-400 transition-colors disabled:bg-slate-600 disabled:cursor-not-allowed",children:n?e.jsx(f,{text:"Analyzing..."}):"Analyze Code"})})]}),e.jsxs("div",{className:"flex flex-col min-h-0",children:[e.jsx("label",{className:"text-sm font-medium text-slate-400 mb-2",children:"AI Analysis"}),e.jsxs("div",{className:"relative flex-grow flex flex-col bg-slate-800/50 border border-slate-700/50 rounded-md overflow-hidden",children:[e.jsx("div",{className:"flex-shrink-0 flex border-b border-slate-700",children:["summary","lineByLine","complexity","suggestions"].map(s=>e.jsx("button",{onClick:()=>h(s),disabled:!a,className:`px-4 py-2 text-sm font-medium capitalize transition-colors ${p===s?"bg-slate-700/50 text-cyan-300":"text-slate-400 hover:bg-slate-700/30 disabled:text-slate-600"}`,children:s.replace(/([A-Z])/g," $1")},s))}),e.jsxs("div",{className:"p-4 flex-grow overflow-y-auto",children:[n&&e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(f,{})}),i&&e.jsx("p",{className:"text-red-400",children:i}),a&&!n&&j(),!n&&!a&&!i&&e.jsx("div",{className:"text-slate-500 h-full flex items-center justify-center",children:"The analysis will appear here."})]})]})]})]})]})};export{T as AiCodeExplainer};
//# sourceMappingURL=AiCodeExplainer-C0HS8Khr.js.map