1import{k as re,q as ne,r as o,j as e}from"./vendor-BFXU7DOE.js";import{w as G}from"./wizardService-COZKYIun.js";import{a2 as V,aF as X,c as O,B as f,d as L,aU as ae,e as W,G as ie}from"./index-0a0uir_3.js";import{W as le}from"./WizardStepIndicator-Bpr7xVrn.js";import{s as oe}from"./Lightbulb.es-CxWh2rrB.js";import{m as ce}from"./Question.es-BRa4fc7c.js";import"./ui-B_QsM55A.js";import"./radix-BmG-mZpu.js";const Y="wizard_context";function de(){try{const b=sessionStorage.getItem(Y);if(!b)return null;sessionStorage.removeItem(Y);const x=JSON.parse(b);return typeof x=="object"&&x!==null&&typeof x.description=="string"&&typeof x.source=="string"?{description:x.description,source:x.source}:null}catch{return null}}const be=()=>{const b=re(),[x]=ne(),Z=x.get("accountId")||"",[p,u]=o.useState("input"),[I,U]=o.useState(""),[M,C]=o.useState(""),[E,k]=o.useState(""),[z,_]=o.useState([]),[R,y]=o.useState({}),[v,P]=o.useState(0),[N,d]=o.useState(null),[m,c]=o.useState(!1),[F,w]=o.useState(null),[Q,g]=o.useState(!1),D=o.useRef(null),S=o.useRef(null),J=o.useRef(new Set);o.useEffect(()=>()=>{var s;(s=S.current)==null||s.call(S)},[]),o.useEffect(()=>{const s=de();s!=null&&s.description&&U(s.description)},[]),o.useEffect(()=>{if(!F||p!=="questions")return;const s=()=>{new Date(F).getTime()-Date.now()<=0&&g(!0)};s();const r=setInterval(s,1e4);return()=>clearInterval(r)},[F,p]);const K=async()=>{var r,n;const s=I.trim();if(!(!s||s.length<10)){c(!0),d(null);try{const t=await G.aiAnalyze(s);if(!t.success){d(t.error||"Analysis failed"),c(!1);return}if(t.status==="needs_clarification"){C(t.sessionId||""),k(t.understanding||""),P(t.conversationTurn||1),t.expiresAt&&w(t.expiresAt),g(!1);const a=(t.questions||[]).map((l,i)=>typeof l=="string"?{id:`q${i+1}`,question:l,why:"",inputType:"text",required:!0}:l);_(a),y({}),u("questions"),c(!1)}else t.status==="ready"&&t.data?h(t.data.options,t.data.existingResources):(d(t.error||"Unexpected response"),c(!1))}catch(t){const a=t instanceof Error&&"response"in t?t:null;d(((n=(r=a==null?void 0:a.response)==null?void 0:r.data)==null?void 0:n.error)||(t instanceof Error?t.message:"Failed to analyze. Please try again.")),c(!1)}}},H=async()=>{var r,n;if(!M)return;c(!0),d(null);const s=z.map(t=>({questionId:t.id,value:R[t.id]||""}));try{const t=await G.conversationContinue(M,s);if(!t.success){d(t.error||"Failed to continue"),c(!1);return}if(t.status==="generating"&&t.jobId){u("generating"),ee(t.jobId);return}if(t.status==="needs_clarification"){k(t.understanding||E),P(t.conversationTurn||v+1),t.expiresAt&&w(t.expiresAt),g(!1);const a=(t.questions||[]).map((l,i)=>typeof l=="string"?{id:`q${i+1}`,question:l,why:"",inputType:"text",required:!0}:l);_(a),y({}),c(!1);return}if(t.status==="ready"&&t.data){h(t.data.options,t.data.existingResources);return}d("Unexpected response"),c(!1)}catch(t){const a=t instanceof Error&&"response"in t?t:null;d(((n=(r=a==null?void 0:a.response)==null?void 0:r.data)==null?void 0:n.error)||(t instanceof Error?t.message:"Failed to continue. Please try again.")),c(!1)}},q=(s,r)=>{let n=0;const t=35,a=5e3,l=async()=>{n++;try{const i=await G.aiGenerateStatus(s);if(i.status==="ready"&&i.data){r(),h(i.data.options,i.data.existingResources);return}if(i.status==="needs_clarification"){r(),B({data:i});return}if(i.status==="error"){r(),d(i.error||"Generation failed"),u("questions"),c(!1);return}}catch{}n<t&&(D.current=setTimeout(l,a))};return setTimeout(l,a)},B=s=>{var t;const r=s.data||s.result;if((r==null?void 0:r.status)==="needs_clarification"&&r){k(r.understanding||E),P(r.conversationTurn||v+1),r.expiresAt&&w(r.expiresAt),g(!1);const a=(r.questions||[]).map((l,i)=>typeof l=="string"?{id:`q${i+1}`,question:l,why:"",inputType:"text",required:!0}:l);_(a),y({}),u("questions"),c(!1);return}if(r!=null&&r.options){h(r.options,r.existingResources);return}if((t=s.data)!=null&&t.options){h(s.data.options,s.data.existingResources);return}d(s.error||"Generation failed"),u("questions"),c(!1)},ee=s=>{let r=!1,n=null;const t=()=>{r||(r=!0,a(),n&&clearTimeout(n),D.current&&clearTimeout(D.current),clearTimeout(l))},a=ie.onMessage(i=>{if(i.type!=="WIZARD_AI_GENERATE_COMPLETE")return;const $=i.payload??i;if(!$||typeof $!="object")return;const j=$;if(j.jobId!==s)return;const T=i.eventId||j.eventId;T&&J.current.has(T)||(T&&J.current.add(T),t(),j.status==="ready"?B(j):(d(j.error||"Generation failed"),u("questions"),c(!1)))});n=q(s,t);const l=setTimeout(()=>{t(),d("Generation is taking too long. Please try again."),u("questions"),c(!1)},18e4);S.current=t},h=(s,r)=>{sessionStorage.setItem("wizard_results",JSON.stringify(s)),r&&sessionStorage.setItem("wizard_existing_resources",JSON.stringify(r)),b(`/wizard/results?accountId=${Z}`,{state:{options:s,generatedAt:new Date().toISOString(),existingResources:r}})},A=(s,r)=>{y(n=>({...n,[s]:r}))},se=z.filter(s=>s.required).every(s=>{const r=R[s.id];return!(r===void 0||r===""||r===null||Array.isArray(r)&&r.length===0)}),te=s=>{const r=R[s.id];if(s.inputType==="select"||s.inputType==="radio")return e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:(s.options||[]).map(n=>e.jsx(f,{variant:"ghost",onClick:()=>
1A(s.id,n.value),className:W("text-left p-3 rounded-lg border transition-all h-auto justify-start",r===n.value?"border-brand bg-brand/10 ring-1 ring-brand/30":"border-edge bg-surface-inset hover:border-edge-strong"),children:e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium text-fg",children:n.label}),n.description&&e.jsx("p",{className:"text-xs text-fg-subtle mt-0.5",children:n.description})]})},n.value))});if(s.inputType==="multi_select"){const n=Array.isArray(r)?r:[];return e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:(s.options||[]).map(t=>{const a=n.includes(t.value);return e.jsxs(f,{variant:"ghost",onClick:()=>{const l=a?n.filter(i=>i!==t.value):[...n,t.value];A(s.id,l)},className:W("text-left p-3 rounded-lg border transition-all h-auto justify-start",a?"border-brand bg-brand/10 ring-1 ring-brand/30":"border-edge bg-surface-inset hover:border-edge-strong"),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:W("w-4 h-4 rounded border flex items-center justify-center",a?"border-brand bg-brand":"border-edge-bright"),children:a&&e.jsx("span",{className:"text-white text-xs",children:"â"})}),e.jsx("span",{className:"text-sm font-medium text-fg",children:t.label})]}),t.description&&e.jsx("p",{className:"text-xs text-fg-subtle mt-0.5 ml-6",children:t.description})]},t.value)})})}if(s.inputType==="slider"&&s.sliderConfig){const n=typeof r=="number"?r:s.sliderConfig.min;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{id:`wizard-q-${s.id}`,type:"range",min:s.sliderConfig.min,max:s.sliderConfig.max,step:s.sliderConfig.step,value:n,onChange:t=>A(s.id,Number(t.target.value)),className:"w-full accent-brand"}),e.jsxs("div",{className:"flex justify-between text-xs text-fg-subtle",children:[e.jsxs("span",{children:[s.sliderConfig.min," ",s.sliderConfig.unit]}),e.jsxs("span",{className:"text-brand font-medium",children:[n," ",s.sliderConfig.unit]}),e.jsxs("span",{children:[s.sliderConfig.max," ",s.sliderConfig.unit]})]})]})}return e.jsx(X,{id:`wizard-q-${s.id}`,value:r||"",onChange:n=>A(s.id,n.target.value),placeholder:s.placeholder||"Type your answer...",rows:2,className:"bg-surface-inset p-3 text-fg"})};return e.jsx("div",{className:"min-h-[80vh] flex flex-col items-center justify-center px-4",children:e.jsxs("div",{className:"max-w-2xl w-full space-y-6",children:[e.jsx(le,{currentStep:1}),p==="input"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsxs("h1",{className:"text-2xl md:text-3xl font-bold text-fg inline-flex items-center gap-3 justify-center",children:[e.jsx(V,{className:"w-7 h-7 text-brand"}),"Design Your Architecture"]}),e.jsx("p",{className:"text-fg-subtle max-w-lg mx-auto",children:"Describe what you're building and our AI Solutions Architect will design a custom AWS architecture tailored to your needs."})]}
1),e.jsxs("div",{className:"space-y-4",children:[e.jsx(X,{value:I,onChange:s=>U(s.target.value),placeholder:"e.g., I'm building a video transcoding pipeline. Users upload videos via a React frontend, we process them with FFmpeg, store originals and transcoded versions in S3, and track job status in a database.",rows:5,className:"bg-surface-inset rounded-xl p-4 text-fg"}),N&&e.jsxs("div",{className:"flex items-start space-x-2 p-3 bg-red-500/10 border border-red-500/20 rounded-lg",children:[e.jsx(O,{className:"w-4 h-4 text-status-red mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-status-red",children:N})]}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(f,{onClick:K,disabled:m||I.trim().length<10,className:"flex items-center space-x-2 px-8 py-3 rounded-xl shadow-lg shadow-brand/25",children:[m?e.jsx(L,{className:"w-5 h-5 animate-spin"}):e.jsx(V,{className:"w-5 h-5"}),e.jsx("span",{children:m?"Analyzing...":"Design My Architecture"})]})})]})]}),p==="questions"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-start space-x-3 p-4 bg-brand/10 border border-brand/20 rounded-xl",children:[e.jsx(oe,{className:"w-5 h-5 text-brand mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-brand-light mb-1",children:"Guardian Pro understood:"}),e.jsx("p",{className:"text-sm text-fg-muted",children:E})]})]}),v>1&&e.jsxs("p",{className:"text-xs text-gray-500",children:["Follow-up round ",v," of ",3]}),Q&&e.jsxs("div",{className:"flex items-start space-x-2 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg",children:[e.jsx(O,{className:"w-4 h-4 text-status-amber mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-status-amber",children:"Session expired. Please start over."}),e.jsx(f,{variant:"link",size:"sm",onClick:()=>{u("input"),d(null),C(""),g(!1),w(null)},className:"text-brand hover:text-brand-light mt-1 p-0 h-auto",children:"Start new session"})]})]}),e.jsx("div",{className:"space-y-5",children:z.map(s=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("label",{htmlFor:`wizard-q-${s.id}`,className:"text-sm font-medium text-fg",children:[s.question,s.required&&e.jsx("span",{className:"text-status-red ml-1",children:"*"})]})}),s.why&&e.jsxs("div",{className:"flex items-start space-x-1.5",children:[e.jsx(ce,{className:"w-3.5 h-3.5 text-gray-500 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-gray-500",children:s.why})]}),te(s)]},s.id))}),N&&e.jsxs("div",{className:"flex items-start space-x-2 p-3 bg-red-500/10 border border-red-500/20 rounded-lg",children:[e.jsx(O,{className:"w-4 h-4 text-status-red mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-status-red",children:N})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(f,{onClick:H,disabled:m||!se||Q,className:"flex items-center space-x-2 px-8 py-3 rounded-xl shadow-lg shadow-brand/25",children:[m?e.jsx(L,{className:"w-5 h-5 animate-spin"}):e.jsx(ae,{className:"w-5 h-5"}),e.jsx("span",{children:m?"Processing...":"Continue"})]}),e.jsx(f,{variant:"link",size:"sm",onClick:()=>{u("input"),d(null),C("")},className:"text-fg-subtle hover:text-fg-muted",children:"Start over"})]})]}),p==="generating"&&e.jsxs("div",{className:"text-center space-y-5 py-12",children:[e.jsx(L,{className:"w-10 h-10 text-brand animate-spin mx-auto"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl font-bold text-fg",children:"Designing your architecture..."}),e.jsx("p",{className:"text-fg-subtle max-w-md mx-auto",children:"Our AI Solutions Architect is analyzing your requirements and designing 3 optimized tiers tailored to your use case."})]}),e.jsx("p",{className:"text-sm text-gray-500",children:"Usually takes 10-20 seconds"})]})]})})};export{be 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.