1import{m as X,r as c,s as Pe,j as e,f as ie,h as fs,c as Ue,X as Be,u as bs,d as js,b as vs}from"./index-ddyum2IO.js";import{M as Ns}from"./ModuleGate-D2UCdNGz.js";import{B as R}from"./button-DG0MSE83.js";import{I as de}from"./input-mzjF7Oqi.js";import{W as qe}from"./WhatsAppIcon-x4gJ08s1.js";import{B as ve}from"./badge-DQWT4vho.js";import{M as ys,g as ws}from"./safe-rehype-D_HKBECE.js";import{a as Cs,C as ts,Z as Ae,M as ce}from"./zap-CWnW395F.js";import{S as _e}from"./sparkles-Vk-HiAdu.js";import{M as Te}from"./monitor-C8UnD83_.js";import{C as Fe}from"./index-CPF8MiZG.js";import{W as ks}from"./wrench-BYdVxFbr.js";import{e as _s,C as rs}from"./select-6itW5X5Y.js";import{C as As}from"./circle-check-nVJoi7Rd.js";import{C as Ms}from"./circle-alert-BwOqLbOj.js";import{B as Me,S as Ss,a as Ts,b as zs,c as $s}from"./sheet-D7V0Tvr2.js";import{L as me}from"./loader-circle-BTIRdVHE.js";import{P as Ps}from"./pencil-DQcoko5X.js";import{R as qs,B as Ds,T as Es,W as Is}from"./webhook-esDbZ00A.js";import{M as Rs}from"./mic-CfWNtzBM.js";import{A as ns}from"./arrow-up-6EP600k5.js";import{P as Oe}from"./phone-nzmmWB-2.js";import{S as Ls}from"./send-BTps-By0.js";import{C as De}from"./code-xml-CS3kto3U.js";import{D as Se}from"./database-DngaDOa7.js";import{A as Ws}from"./arrow-right-p73rLO39.js";import{C as he}from"./chart-column-BzppRihC.js";import{U as le,C as Ie,A as Re,T as Je,B as Fs}from"./rbac-anvhikL4.js";import{S as Ne}from"./settings-D8d8Wyet.js";import{S as Ve}from"./search-CW965JYQ.js";import{C as Os}from"./checkbox-DULFCGH-.js";import{R as Us}from"./refresh-cw-CKMzqBCd.js";import{P as Ge}from"./plus-BX9tVbBX.js";import{D as Qe}from"./download-fn41UruN.js";import{C as Bs}from"./clock-Bo3zuwpM.js";import{I as Xe,L as Vs,a as Gs}from"./IntegrationsGrid-CkDHpKh9.js";import{S as os}from"./switch-Bl5E-7Ex.js";import{T as ze}from"./textarea-CrlrCstl.js";import{S as Hs}from"./scroll-area-DCdDh24J.js";import{S as is}from"./shield-BKPXsPA1.js";import{F as ls}from"./file-text-DuKYL_dh.js";import{I as Ks}from"./image-p8_JkiKZ.js";import{U as He}from"./upload-CnHBIT1v.js";import{B as Js}from"./bell-XM6lD86i.js";import{L as Ze}from"./lock-BS4S5OrO.js";import{G as Qs}from"./globe-BgSXGCaU.js";import{T as Xs}from"./trash-2-BG9X7O63.js";import{L as Zs}from"./link-2-BymLPpx-.js";import{C as Ys}from"./credit-card-CuHtzwQ5.js";import{S as ea}from"./save-B9LyqlqZ.js";import{E as sa}from"./eye-Jk18laCA.js";import{L as aa}from"./use-module-access-Bj28_9pQ.js";import"./Combination-DQ9kAQl5.js";import"./dialog-CkYswXaE.js";import"./separator-B6bqBeA0.js";import"./collapsible-BT3eCWdP.js";import"./use-crm-BzNLvHu0.js";import"./useQuery-DEyeC88j.js";import"./triangle-alert-BZCfSr8b.js";import"./settings-2-B5LsIHDK.js";import"./telnyx-logo.png.asset-B4ngzeB5.js";import"./key-round-BC4GDOmr.js";import"./eye-off-CQiuL_Xd.js";import"./external-link-CuAKenWR.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ta=X("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ra=X("ArrowUpDown",[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Ke=X("Earth",[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const ds=X("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",ke
21y:"1mlx9k"}]]);/** 22 * @license lucide-react v0.462.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const na=X("FileUp",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"m15 15-3-3-3 3",key:"15xj92"}]]);/** 27 * @license lucide-react v0.462.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const cs=X("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/** 32 * @license lucide-react v0.462.0 - ISC 33 * 34 * This source code is licensed under the ISC license. 35 * See the LICENSE file in the root directory of this source tree. 36 */const oa=X("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/** 37 * @license lucide-react v0.462.0 - ISC 38 * 39 * This source code is licensed under the ISC license. 40 * See the LICENSE file in the root directory of this source tree. 41 */const ia=X("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/** 42 * @license lucide-react v0.462.0 - ISC 43 * 44 * This source code is licensed under the ISC license. 45 * See the LICENSE file in the root directory of this source tree. 46 */const la=X("Layers",[["path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z",key:"8b97xw"}],["path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65",key:"dd6zsq"}],["path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65",key:"ep9fru"}]]);/** 47 * @license lucide-react v0.462.0 - ISC 48 * 49 * This source code is licensed under the ISC license. 50 * See the LICENSE file in the root directory of this source tree. 51 */const da=X("LockOpen",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]]);/** 52 * @license lucide-react v0.462.0 - ISC 53 * 54 * This source code is licensed under the ISC license. 55 * See the LICENSE file in the root directory of this source tree. 56 */const ca=X("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]);/** 57 * @license lucide-react v0.462.0 - ISC 58 * 59 * This source code is licensed under the ISC license. 60 * See the LICENSE file in the root directory of this source tree. 61 */const ma=X("PanelLeftOpen",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]]);/** 62 * @license lucide-react v0.462.0 - ISC 63 * 64 * This source code is licensed under the ISC license. 65 * See the LICENSE file in the root directory of this source tree. 66 */const $e=X("PanelsTopLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]]);/** 67 * @license lucide-react v0.462.0 - ISC 68 * 69 * This source code is licensed under the ISC license. 70 * See the LICENSE file in the root directory of this source tree. 71 */const xa=X("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);/** 72 * @license lucide-react v0.462.0 - ISC 73 * 74 * This source code is licensed under the ISC license. 75 * See the LICENSE file in the root directory of this source tree. 76 */const pa=X("Table",[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]]),ms=c.createContext(null),oe=()=>{const t=c.useContext(ms);if(!t)throw new Error("useAppBuilder must be used within AppBuilderProvider");return t};function ua(t){const n=t.slice(0,60);return[{name:"index.html",path:"/index.html",content:`<!doctype html> 77<html lang="pt-BR"> 78 <head> 79 <meta charset="UTF-8" /> 80 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 81 <title>Meu App</title> 82 </head> 83 <body> 84 <div id="root"></div> 85 <script type="module" src="/src/main.tsx"><\/script> 86 </body> 87</html>`},{name:"App.tsx",path:"/src/App.tsx",content:`import { BrowserRouter, Routes, Route } from "react-router-dom"; 88import Sidebar from "./components/Sidebar"; 89import Header from "./components/Header"; 90import Dashboard from "./pages/Dashboard"; 91import Home from "./pages/Home"; 92 93// ${n} 94export default function App() { 95 return ( 96 <BrowserRouter> 97 <div className="flex h-screen"> 98 <Sidebar /> 99 <div className="flex-1 flex flex-col"> 100 <Header /> 101 <main className="flex-1 p-6 overflow-auto"> 102 <Routes> 103 <Route path="/" element={<Home />} /> 104 <Route path="/dashboard" element={<Dashboard />} /> 105 </Routes> 106 </main> 107 </div> 108 </div> 109 </BrowserRouter> 110 ); 111}`},{name:"Dashboard.tsx",path:"/src/pages/Dashboard.tsx",content:`import MetricCard from "../components/MetricCard"; 112 113export default function Dashboard() { 114 return ( 115 <div className="space-y-6"> 116 <h1 className="text-2xl font-bold">Dashboard</h1> 117 <div className="grid grid-cols-4 gap-4">
118 <MetricCard title="Usuários" value="0" change="+0%" /> 119 <MetricCard title="Receita" value="R$ 0" change="+0%" /> 120 </div> 121 </div> 122 ); 123}`},{name:"MetricCard.tsx",path:"/src/components/MetricCard.tsx",content:`interface Props { title: string; value: string; change: string; } 124 125export default function MetricCard({ title, value, change }: Props) { 126 return ( 127 <div className="rounded-xl border p-4 bg-card"> 128 <p className="text-sm text-muted-foreground">{title}</p> 129 <p className="text-2xl font-bold mt-1">{value}</p> 130 <span className="text-xs text-green-500">{change}</span> 131 </div> 132 ); 133}`},{name:"Sidebar.tsx",path:"/src/components/Sidebar.tsx",content:`export default function Sidebar() { 134 return ( 135 <aside className="w-60 border-r bg-card p-4"> 136 <nav className="space-y-1"> 137 <a href="/" className="block px-3 py-2 rounded-md text-sm">Home</a> 138 <a href="/dashboard" className="block px-3 py-2 rounded-md text-sm">Dashboard</a> 139 </nav> 140 </aside> 141 ); 142}`},{name:"Header.tsx",path:"/src/components/Header.tsx",content:`export default function Header() { 143 return ( 144 <header className="h-14 border-b flex items-center px-6"> 145 <h1 className="text-lg font-semibold">Meu App</h1> 146 </header> 147 ); 148}`}]}function ha(t){return[{name:"main-agent.ts",path:"/src/agents/main-agent.ts",content:`// ${t.slice(0,60)} 149// Agente principal do WhatsApp Bot 150 151import { WhatsAppAPI } from "../integrations/whatsapp-api"; 152import { config } from "../config"; 153 154export class MainAgent { 155 private api: WhatsAppAPI; 156 157 constructor() { 158 this.api = new WhatsAppAPI(config.token, config.phoneNumberId); 159 } 160 161 async handle(from: string, text: string, stage: string) { 162 // Lógica principal do agente 163 } 164}`},{name:"qualifier.ts",path:"/src/agents/qualifier.ts",content:`// Agente de qualificação de leads 165 166export class QualifierAgent { 167 private questions = [ 168 "Qual é o seu nome completo?", 169 "Qual é o seu principal objetivo?", 170 "Qual o seu orçamento estimado?", 171 ]; 172 173 async qualify(from: string, step: number) {} 174}`},{name:"whatsapp-api.ts",path:"/src/integrations/whatsapp-api.ts",content:`const BASE_URL = "https://graph.facebook.com/v21.0"; 175 176export class WhatsAppAPI { 177 constructor(private token: string, private phoneId: string) {} 178 179 async sendText(to: string, body: string) {} 180 async sendButtons(to: string, body: string, buttons: string[]) {} 181 async sendList(to: string, body: string, sections: any[]) {} 182}`},{name:"webhook.ts",path:"/src/handlers/webhook.ts",content:`export async function handleWebhook(req: Request) { 183 const body = await req.json(); 184 const entry = body.entry?.[0]?.changes?.[0]?.value; 185 const message = entry?.messages?.[0]; 186 if (!message) return new Response("OK"); 187}`},{name:"config.ts",path:"/src/config.ts",content:`export const config = { 188 phoneNumberId: "", 189 token: "", 190 botName: "Assistente", 191 language: "pt-BR", 192};`}]}function ga(){return[{name:"users",columns:[{name:"id",type:"UUID",isPK:!0},{name:"email",type:"TEXT"},{name:"full_name",type:"TEXT"},{name:"created_at",type:"TIMESTAMP"}],rows:[]},{name:"profiles",columns:[{name:"id",type:"UUID",isPK:!0},{name:"user_id",type:"UUID"},{name:"avatar_url",type:"TEXT"},{name:"bio",type:"TEXT"}],rows:[]},{name:"settings",columns:[{name:"id",type:"UUID",isPK:!0},{name:"user_id",type:"UUID"},{name:"theme",type:"TEXT"},{name:"notifications",type:"BOOLEAN"}],rows:[]}]}function fa(){return[{name:"contacts",columns:[{name:"id",type:"UUID",isPK:!0},{name:"phone",type:"TEXT"},{name:"name",type:"TEXT"},{name:"stage",type:"TEXT"},{name:"created_at",type:"TIMESTAMP"}],rows:[]},{name:"conversations",columns:[{name:"id",type:"UUID",isPK:!0},{name:"contact_id",type:"UUID"},{name:"status",type:"TEXT"},{name:"started_at",type:"TIMESTAMP"},{name:"ended_at",type:"TIMESTAMP"}],rows:[]},{name:"messages",columns:[{name:"id",type:"UUID",isPK:!0},{name:"conversation_id",type:"UUID"},{name:"direction",type:"TEXT"},{name:"content",type:"TEXT"},{name:"sent_at",type:"TIMESTAMP"}],rows:[]},{name:"leads",columns:[{name:"id",type:"UUID",isPK:!0},{name:"contact_id",type:"UUID"},{name:"score",type:"INTEGER"},{name:"qualified",type:"BOOLEAN"},{name:"data",type:"JSONB"}],rows:[]}]}
192function ba(){return[{label:"Usuários Ativos",value:"0",change:"--",up:!0},{label:"Pageviews",value:"0",change:"--",up:!0},{label:"Conversão",value:"0%",change:"--",up:!0},{label:"Bounce Rate",value:"0%",change:"--",up:!0}]}function ja(){return[{label:"Conversas Ativas",value:"0",change:"--",up:!0},{label:"Leads Qualificados",value:"0",change:"--",up:!0},{label:"Taxa de Resposta",value:"0%",change:"--",up:!0},{label:"Tempo Médio",value:"--",change:"--",up:!0}]}function va(t,n){return n!=null&&n.metrics&&Array.isArray(n.metrics)&&n.metrics.length>0?n.metrics.map(o=>({label:o.label||o.title||"Métrica",value:String(o.value??"0"),change:o.change||"--",up:o.up??!0})):t==="whatsapp"?[{label:"Usuários",value:"0",change:"placeholder",up:!0},{label:"Conversas",value:"0",change:"placeholder",up:!0},{label:"Sessões",value:"0",change:"placeholder",up:!0}]:[{label:"Usuários",value:"0",change:"placeholder",up:!0},{label:"Sessões",value:"0",change:"placeholder",up:!0},{label:"Conversões",value:"0",change:"placeholder",up:!0}]}function Na(t,n,o){const m=t.files.map(d=>({name:d.path.split("/").pop()||d.path,path:d.path,content:`// ${d.purpose} 193// ${d.content_summary}`})),a=t.database.tables.map(d=>({name:d.name,columns:d.columns.map(s=>({name:s.name,type:s.type,isPK:s.name==="id"||void 0})),rows:[]})),i=t.preview.screen_data,x=va(t.app_meta.type,i);return{files:m.length>0?m:n,tables:a.length>0?a:o,metrics:x}}function ya({children:t,initialChannel:n="web",existingAppId:o}){const m={prompt:"",companyName:"",appName:"",tone:"professional_friendly",language:"pt-BR",introMessage:"",maxMessages:2,onboarding:"soft",selectedFeatures:[],businessContext:"",constraints:""},[a,i]=c.useState(o||null),[x,d]=c.useState({channel:n,files:[],tables:[],terminalLogs:[],dashboardMetrics:[],appName:"Meu App",isGenerating:!1,wizardConfig:null,chatMessages:[],wizardStep:"discover",wizardData:m,structuredConfig:null,appState:null}),s=c.useCallback(f=>d(g=>({...g,channel:f})),[]),C=c.useCallback(f=>d(g=>{const $=g.files.findIndex(k=>k.name===f.name);if($>=0){const k=[...g.files];return k[$]=f,{...g,files:k}}return{...g,files:[...g.files,f]}}),[]),A=c.useCallback(f=>d(g=>({...g,files:f})),[]),N=c.useCallback(f=>d(g=>{const $=g.tables.findIndex(k=>k.name===f.name);if($>=0){const k=[...g.tables];return k[$]=f,{...g,tables:k}}return{...g,tables:[...g.tables,f]}}),[]),q=c.useCallback(f=>d(g=>({...g,tables:f})),[]),j=c.useCallback(f=>d(g=>({...g,terminalLogs:[...g.terminalLogs,f]})),[]),D=c.useCallback(f=>d(g=>({...g,dashboardMetrics:f})),[]),p=c.useCallback(f=>d(g=>({...g,appName:f})),[]),z=c.useCallback(f=>d(g=>({...g,isGenerating:f})),[]),v=c.useCallback(f=>d(g=>({...g,chatMessages:f})),[]),T=c.useCallback(f=>d(g=>({...g,wizardStep:f})),[]),h=c.useCallback(f=>d(g=>({...g,wizardData:f})),[]),_=c.useCallback(f=>d(g=>({...g,wizardConfig:f})),[]),y=c.useCallback(f=>d(g=>({...g,structuredConfig:f})),[]),M=c.useCallback(f=>{d(g=>{var Z,K,B;if(!f)return{...g,appState:null};const $={...f,runtime:{render_ready:!0,mocked:((Z=f.runtime)==null?void 0:Z.mocked)??!0,warnings:((K=f.runtime)==null?void 0:K.warnings)??[],next_build_targets:((B=f.runtime)==null?void 0:B.next_build_targets)??[]}},{files:k,tables:E,metrics:H}=Na($,g.files,g.tables);return{...g,appState:$,channel:$.app_meta.type||g.channel,files:k,tables:E,dashboardMetrics:H,appName:$.app_meta.name||g.appName,isGenerating:!1}})},[]),W=c.useCallback((f,g)=>{const $=f==="whatsapp"?ha(g):ua(g),k=f==="whatsapp"?fa():ga(),E=f==="whatsapp"?ja():ba(),H=[{text:"$ aikortex init --channel="+f,type:"command",timestamp:Date.now()},{text:"â Projeto inicializado com sucesso",type:"success",timestamp:Date.now()+100},{text:`â ${$.length} arquivos gerados`,type:"success",timestamp:Date.now()+200},{text:`â ${k.length} tabelas criadas`,type:"success",timestamp:Date.now()+300},{text:"$ npm run dev",type:"command",timestamp:Date.now()+400},{text:"â Local: http://localhost:5173/",type:"success",timestamp:Date.now()+500},{text:"ready in 320ms",type:"output",timestamp:Date.now()+600}];d(Z=>({...Z,channel:f,files:$,tables:k,terminalLogs:H,dashboardMetrics:E,isGenerating:!1}))},[]),F=c.useCallback(async f=>{const g={chatMessages:x.chatMessages,wizardStep:x.wizardStep,wizardData:x.wizardData,wizardConfig:x.wizardConfig,structuredConfig:x.structuredConfig,appState:x.appState},$={user_id:f,name:x.appName,description:"",channel:x.channel,files:JSON.parse(JSON.stringify(x.files)),tables_schema:JSON.parse(JSON.stringify(x.tables)),config:JSON.parse(JSON.stringify(g)),status:"draft"};if(a){const{error:k}=await Pe.from("user_apps").update($).eq("id",a);return k?(console.error(k),null):a}else{const{data:k,error:E}=await Pe.from("user_apps").insert($).select("id").single();return E||!k?(console.error(E),null):(i(k.id),k.id)}},[x,a]);return e.jsx(ms.Provider,{value:{...x,setChannel:s,addFile:C,setFiles:A,addTable:N,setTables:q,addTerminalLog:j,setDashboardMetrics:D,setAppName:p,setIsGenerating:z,setWizardConfig:_,setChatMessages:v,setWizardStep:T,setWizardData:h,setStructuredConfig:y,setAppState:M,initializeProject:W,saveApp:F,appId:a,setAppId:i},children:t})}async function xs(){const{data:{session:t}}=await Pe.auth.getSession();if(!(t!=null&&t.access_token))throw new Error("Sessão expirada. Faça login novamente.");return t.access_token}const ps=fs("app-chat"),Ye=[{id:"discover",label:"Descobrir",num:1},{id:"structure",label:"Estruturar",num:2},{id:"build",label:"Construir",num:3}],Le={professional_friendly:"Profissional e Amigável",formal:"Formal",casual:"Casual e DescontraÃdo",empathetic:"Empático e Acolhedor",direct:"Direto e Objetivo"},es={none:"Nenhum",soft:"Suave",strict:"Rigoroso"};function us(t){let n=t.replace(/^```(?:json)?\s*\n?/gm,"").replace(/\n?```\s*$/gm,"").trim();return n=n.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,""),n=n.replace(/,\s*([}\]])/g,"$1"),JSON.parse(n)}function wa(t){const n=(t==null?void 0:t.app_state)||t;return!(n!=null&&n.app_meta)&&!(n!=null&&n.preview)?null:{app_meta:n.app_meta||{type:"web",name:"App",description:"",tone:"",language:"pt-BR",status:"draft"},preview:n.preview||{type:"web",title:"",subtitle:"",layout:{},screen_data:{},interactions:[]}
193,agent_config:n.agent_config||{intro_message:"",max_turn_messages:2,onboarding_level:"soft",personality_rules:[],conversation_rules:[],cta_primary:"",quick_replies:[]},flows:n.flows||[],database:n.database||{tables:[]},files:n.files||[],ui_modules:n.ui_modules||[],runtime:n.runtime||{render_ready:!0,mocked:!0,warnings:[],next_build_targets:[]}}}async function ss(t,n,o){var x,d;const m=await xs(),a=await fetch(ps,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${m}`},body:JSON.stringify({messages:t,appContext:n,mode:o})});if(a.status===429)return{appState:null,chatSummary:"",error:"Limite de requisições excedido."};if(a.status===402)return{appState:null,chatSummary:"",error:"Créditos insuficientes."};if(!a.ok)return{appState:null,chatSummary:"",error:"Erro no serviço de IA"};const i=await a.json();if(i.error)return{appState:null,chatSummary:"",error:i.error};try{const s=typeof i.appStateRaw=="string"?us(i.appStateRaw):i.appStateRaw,C=wa(s);if(!C)return console.error("Invalid app_state schema:",s),{appState:null,chatSummary:"",error:"Resposta da IA não contém um app_state válido."};const A=(s==null?void 0:s.chat_summary)||"";return{appState:C,chatSummary:A}}catch(s){return console.error("JSON parse error:",s,(d=(x=i.appStateRaw)==null?void 0:x.slice)==null?void 0:d.call(x,0,200)),{appState:null,chatSummary:"",error:"Erro ao processar resposta da IA"}}}async function Ca(t,n,o){const m=await xs(),a=await fetch(ps,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${m}`},body:JSON.stringify({messages:[{role:"user",content:t}],appContext:{app_type:n,language:o},mode:"structure"})});if(!a.ok)return null;const i=await a.json();try{return typeof i.structuredConfig=="string"?us(i.structuredConfig):i.structuredConfig}catch{return null}}const ka=({onBack:t,initialPrompt:n})=>{var pe;const{channel:o,initializeProject:m,addTerminalLog:a,setIsGenerating:i,setAppName:x,setWizardConfig:d,setAppState:s,chatMessages:C,setChatMessages:A,wizardStep:N,setWizardStep:q,wizardData:j,setWizardData:D,structuredConfig:p,setStructuredConfig:z,appState:v}=oe(),T=c.useRef(C);T.current=C;const h=c.useCallback(r=>{A(typeof r=="function"?r(T.current):r)},[A]),_=C,y=j,M=r=>{D(typeof r=="function"?r(j):r)},[W,F]=c.useState(""),[f,g]=c.useState(!1),[$,k]=c.useState(0),[E,H]=c.useState(!0),[Z,K]=c.useState([]),[B,ee]=c.useState(!1),[ae,V]=c.useState(!1),[Y,te]=c.useState(!1),se=c.useRef(null),w=c.useRef(!1),P=c.useRef(!1);c.useEffect(()=>{N==="done"&&C.length>0&&(P.current=!0,w.current=!0)},[]),c.useEffect(()=>{n&&!w.current&&(w.current=!0,M(r=>({...r,prompt:n})),h([{role:"user",content:n}]),re(n))},[n]),c.useEffect(()=>{var r;(r=se.current)==null||r.scrollTo({top:se.current.scrollHeight,behavior:"smooth"})},[_,B]);const ge=()=>{if(y.prompt.length<10){ie.error("Descreva com pelo menos 10 caracteres.");return}h(r=>[...r,{role:"user",content:y.prompt}]),re(y.prompt)},re=async r=>{q("structure"),ee(!0),h(l=>[...l,{role:"assistant",content:"ð§ Analisando sua ideia e estruturando o app..."}]);const u=await Ca(r,o,y.language||"pt-BR");u?(z(u),M(l=>({...l,appName:u.app_name||l.appName,prompt:u.app_description||l.prompt,tone:u.tone||l.tone,language:u.language||l.language,introMessage:u.intro_message||l.introMessage,maxMessages:u.max_turn_messages||l.maxMessages,onboarding:u.onboarding_level||l.onboarding,selectedFeatures:u.selected_features||l.selectedFeatures,businessContext:u.business_context||l.businessContext,constraints:u.constraints||l.constraints})),x(u.app_name||"Meu App"),h(l=>[...l.filter(I=>I.content!=="ð§ Analisando sua ideia e estruturando o app..."),{role:"assistant",content:`â Estrutura definida para **${u.app_name}**! 194 195Revise a configuração abaixo e clique em **Construir** quando estiver pronto.`}])):(ie.error("Erro ao estruturar. Tente novamente."),q("discover"),h(l=>l.filter(G=>G.content!=="ð§ Analisando sua ideia e estruturando o app..."))),ee(!1)},fe=async()=>{var ue,ye,we,Ce;if(!p)return;q("build"),V(!0),i(!0),d({prompt:y.prompt,companyName:y.companyName,appName:p.app_name,tone:p.tone,language:p.language,introMessage:p.intro_message,maxMessages:p.max_turn_messages,onboarding:p.onboarding_level||"soft",selectedFeatures:p.selected_features||[],businessContext:p.business_context||"",constraints:p.constraints||""});const r=U=>U.replace(/[_-]+/g," ").replace(/\b\w/g,J=>J.toUpperCase()),u=(p.selected_features||[]).map(r).join(", "),l=`ð **Iniciando construção de ${p.app_name}** 196 197Canal: ${o==="whatsapp"?"WhatsApp":"Web App"} · Tom: ${Le[p.tone]||p.tone} · Idioma: ${p.language} 198 199Funcionalidades: ${u} 200 201Gerando app state...`;h(U=>[...U,{role:"assistant",content:l}]),P.current||(P.current=!0,m(o,y.prompt)),k(U=>U+1),K(U=>[...U,{label:"Gerando estado do app...",status:"success"}]),a({text:"$ aikortex build --mode=create",type:"command",timestamp:Date.now()});const G=`Crie um ${o==="whatsapp"?"WhatsApp App":"Web App"} chamado "${p.app_name}". 202Descrição: ${p.app_description} 203Tom: ${p.tone} 204Idioma: ${p.language} 205Mensagem de introdução: ${p.intro_message} 206Máx mensagens por turno: ${p.max_turn_messages} 207Onboarding: ${p.onboarding_level} 208Funcionalidades: ${(p.selected_features||[]).join(", ")} 209${p.business_context?`Contexto: ${p.business_context}`:""} 210${p.constraints?`Restrições: ${p.constraints}`:""}`,I=p,ne={app_type:o,app_name:I.app_name||"Meu App",app_description:I.app_description||y.prompt||"",tone:I.tone||"professional_friendly",language:I.language||"pt-BR",intro_message:I.intro_message||"",max_turn_messages:String(I.max_turn_messages||2),onboarding_level:I.onboarding_level||"soft",selected_features:(I.selected_features||[]).join(", "),business_context:I.business_context||"",constraints:I.constraints||"",is_patch:"false"},{appState:O,chatSummary:b,error:S}=await ss([{role:"user",content:G}],ne,"build");if(S){ie.error(S),K(U=>[...U,{label:S,status:"error"}]),a({text:`â ${S}`,type:"error",timestamp:Date.now()}),h(U=>[...U.filter(J=>J.content!==l),{role:"assistant",content:`â ${S}`}]),V(!1),i(!1);return}if(O){s(O),V(!1),i(!1),q("done");const U=((ue=O.files)==null?void 0:ue.length)||0,J=((we=(ye=O.database)==null?void 0:ye.tables)==null?void 0:we.length)||0;K(ke=>[...ke,{label:`${U} arquivo(s) gerado(s)`,status:"success"},{label:`${J} tabela(s) criada(s)`,status:"success"}]),a({text:`â ${U} arquivos gerados`,type:"success",timestamp:Date.now()}),a({text:`â ${J} tabelas criadas`,type:"success",timestamp:Date.now()}),a({text:"â Preview atualizado",type:"success",timestamp:Date.now()}),a({text:"â Dashboard atualizado",type:"success",timestamp:Date.now()});const Ee=b||`â **${((Ce=O.app_meta)==null?void 0:Ce.name)||I.app_name}** criado com sucesso! 211 212O preview e o dashboard já foram atualizados.`;h(ke=>[...ke.filter(gs=>gs.content!==l),{role:"assistant",content:Ee}
212]);return}V(!1),i(!1)},xe=async r=>{if(!r.trim()||f)return;const u={role:"user",content:r.trim()};h(b=>[...b,u]),F(""),g(!0),i(!0),k(b=>b+1),P.current||(P.current=!0,m(o,r.trim())),K(b=>[...b,{label:`Processando: "${r.trim().slice(0,40)}..."`,status:"success"}]),a({text:"$ aikortex patch",type:"command",timestamp:Date.now()});const l=p,G={app_type:o,app_name:(l==null?void 0:l.app_name)||y.appName||"Meu App",app_description:(l==null?void 0:l.app_description)||y.prompt||"",tone:(l==null?void 0:l.tone)||y.tone||"professional_friendly",language:(l==null?void 0:l.language)||y.language||"pt-BR",intro_message:(l==null?void 0:l.intro_message)||y.introMessage||"",max_turn_messages:String((l==null?void 0:l.max_turn_messages)||y.maxMessages||2),onboarding_level:(l==null?void 0:l.onboarding_level)||y.onboarding||"soft",selected_features:((l==null?void 0:l.selected_features)||y.selectedFeatures||[]).join(", "),business_context:(l==null?void 0:l.business_context)||y.businessContext||"",constraints:(l==null?void 0:l.constraints)||y.constraints||"",is_patch:"true",current_state:v?JSON.stringify(v).slice(0,4e3):""},{appState:I,chatSummary:ne,error:O}=await ss([..._,u],G,"build");if(O)ie.error(O),h(b=>[...b,{role:"assistant",content:`â ${O}`}]),K(b=>[...b,{label:O,status:"error"}]),a({text:`â ${O}`,type:"error",timestamp:Date.now()});else if(I){s(I),a({text:"â Atualizado",type:"success",timestamp:Date.now()});const b=ne||"â Atualização aplicada! O preview foi atualizado.";h(S=>[...S,{role:"assistant",content:b}])}g(!1),i(!1)},be=r=>{if(r.key==="Enter"&&!r.shiftKey)if(r.preventDefault(),N==="discover"){if(W.trim().length>=10){M(l=>({...l,prompt:W.trim()}));const u=W.trim();F(""),h(l=>[...l,{role:"user",content:u}]),re(u)}}else N==="done"&&xe(W)},je=_.length===0;return e.jsxs("div",{className:"w-[440px] min-w-[360px] max-w-[520px] border-r border-border flex flex-col bg-card/20",children:[e.jsxs("div",{className:"h-12 border-b border-border flex items-center justify-between px-4 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:t,children:e.jsx(Cs,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-primary/15 flex items-center justify-center",children:e.jsx(_e,{className:"w-3.5 h-3.5 text-primary"})}),e.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"Studio"})]})]}),e.jsxs("span",{className:`flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium ${o==="whatsapp"?"bg-green-500/10 text-green-500 border border-green-500/20":"bg-primary/10 text-primary border border-primary/20"}`,children:[o==="whatsapp"?e.jsx(qe,{className:"w-3 h-3"}):e.jsx(Te,{className:"w-3 h-3"}),o==="whatsapp"?"WhatsApp":"Web"]})]}),N!=="done"&&e.jsx("div",{className:"px-4 py-2.5 border-b border-border bg-card/30",children:e.jsx("div",{className:"flex items-center gap-1",children:Ye.map((r,u)=>{const l=["discover","structure","build"],G=l.indexOf(N),ne=l.indexOf(r.id)<G,O=r.id===N;return e.jsxs("div",{className:"flex items-center flex-1 last:flex-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:`w-5 h-5 rounded-full flex items-center justify-center text-[9px] font-bold transition-all ${ne||O?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:ne?e.jsx(Fe,{className:"w-3 h-3"}):r.num}),e.jsx("span",{className:`text-[10px] font-medium ${O?"text-foreground":"text-muted-foreground"}`,children:r.label})]}),u<Ye.length-1&&e.jsx("div",{className:`flex-1 h-px mx-2 ${ne?"bg-primary":"bg-border"}`})]},r.id)})})}),$>0&&e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("button",{onClick:()=>H(!E),className:"flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors bg-muted/30 rounded-lg px-2.5 py-1.5 w-full",children:[e.jsx(ks,{className:"w-3 h-3"}),e.jsxs("span",{children:[$," ações"]}),E?e.jsx(_s,{className:"w-3 h-3 ml-auto"}):e.jsx(rs,{className:"w-3 h-3 ml-auto"})]}),E&&Z.length>0&&e.jsx("div",{className:"mt-1.5 space-y-0.5 pl-1",children:Z.slice(-6).map((r,u)=>e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[r.status==="success"?e.jsx(As,{className:"w-3 h-3 text-green-500 shrink-0"}):e.jsx(Ms,{className:"w-3 h-3 text-destructive shrink-0"}),e.jsx("span",{className:"text-muted-foreground truncate",children:r.label})]},u))})]}),e.jsxs("div",{ref:se,className:"flex-1 overflow-y-auto px-4 py-3 space-y-4",children:[N==="discover"&&je&&e.jsxs("div",{className:"flex flex-col items-center justify-center h-full pt-12",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-primary/10 flex items-center justify-center mb-4",children:e.jsx(_e,{className:"w-6 h-6 text-primary"})}),e.jsx("h2",{className:"text-base font-semibold text-foreground mb-1",children:"Descreva seu app"}),e.jsx("p",{className:"text-xs text-muted-foreground text-center max-w-[280px] mb-6",children:o==="whatsapp"?"Conte o que seu WhatsApp App deve fazer. A IA vai estruturar tudo automaticamente.":"Conte o que seu Web App deve fazer. A IA vai estruturar tudo automaticamente."}),e.jsxs("div",{className:"mt-6 w-full max-w-[340px]",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-2 text-center",children:"ou comece com uma ideia:"}),e.jsx("div",{className:"space-y-1.5",children:(o==="whatsapp"?["Bot de qualificação de leads via WhatsApp","Sistema de agendamento para clÃnicas por WhatsApp","CRM conversacional com follow-up automático","Onboarding guiado com coleta de dados via chat"]:["Dashboard de gestão com métricas e relatórios","Sistema de cadastro de clientes com CRM visual","Plataforma de agendamento com calendário interativo","Painel administrativo com controle de equipe e tarefas"]).map(r=>e.jsx("button",{onClick:()=>{M(u=>({...u,prompt:r})),F(r)},className:"w-full text-left text-[11px] px-3 py-2 rounded-lg border border-border hover:border-primary/30 hover:bg-accent/20 text-muted-foreground hover:text-foreground transition-all",children:r},r))})]})]}),_.map((r,u)=>r.role==="assistant"&&!r.content?null:e.jsx("div",{children:r.role==="user"?e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"bg-primary/10 border border-primary/20 rounded-2xl rounded-br-sm px-4 py-2.5 max-w-[90%] text-sm",children:e.jsx("p",{className:"whitespace-pre-wrap text-foreground",children:r.content})})}):e.jsxs("div",{className:"flex gap-2.5",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:e.jsx(Me,{className:"w-3.5 h-3.5 text-primary"})}),e.jsx("div",{className:"text-sm leading-relaxed text-foreground flex-1 min-w-0",children:e.jsx("div",{className:`prose prose-sm dark:prose-invert max-w-none 213 [&_p]:mb-2 [&_ul]:mb-2 [&_ol]:mb-2 [&_li]:mb-0.5 214 [&_strong]:text-foreground 215 [&_h1]:text-base [&_h2]:text-sm [&_h3]:text-sm`,children:e.jsx(ys,{rehypePlugins:ws(),children:r.content})})})]})},u)),B&&e.jsxs("div",{className:"flex items-center gap-3 bg-card/50 border border-border rounded-xl p-4",children:[e.jsx(me,{className:"w-5 h-5 text-primary animate-spin"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:"Estruturando com IA..."}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Analisando descrição e definindo arquitetura"})]})]}),N==="structure"&&p&&!B&&e.jsxs("div",{className:"bg-card/50 border border-border rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-primary/15 flex items-center justify-center",children:e.jsx(Fe,{className:"w-3 h-3 text-primary"})}),e.jsx("h3",{className:"text-xs font-semibold text-foreground",children:"Configuração Estruturada"})]}),e.jsxs("button",{onClick:()=>te(!Y),className:"text-[10px] text-muted-foreground hover:text-foreground flex items-center gap-1 transition-colors",children:[e.jsx(Ps,{className:"w-3 h-3"}),Y?"Fechar":"Editar"]})]}),Y?e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground mb-1 block",children:"Nome"}),e.jsx(de,{value:p.app_name,onChange:r=>z({...p,app_name:r.target.value}),className:"h-7 text-xs bg-background"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground mb-1 block",children:"Tom"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Object.entries(Le).map(([r,u])=>e.jsx("button",{onClick:()=>z({...p,tone:r}),className:`px-2 py-1 rounded-md text-[9px] font-medium border transition-all ${p.tone===r?"bg-primary/10 border-primary/30 text-primary":"bg-card border-border text-muted-foreground"}`,children:u},r))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground mb-1 block",children:"Idioma"}),e.jsx("div",{className:"flex gap-1",children:[["pt-BR","ð§ð· PT"],["en","ðºð¸ EN"],["es","ðªð¸ ES"]].map(([r,u])=>e.jsx("button",{onClick:()=>z({...p,language:r}),className:`px-2 py-1 rounded-md text-[9px] font-medium border transition-all ${p.language===r?"bg-primary/10 border-primary/30 text-primary":"bg-card border-border text-muted-foreground"}`,children:u},r))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground mb-1 block",children:"Mensagem inicial"}),e.jsx("textarea",{value:p.intro_message,onChange:r=>z({...p,intro_message:r.target.value}),className:"w-full bg-background border border-border rounded-md text-xs px-2 py-1.5 min-h-[50px] resize-none outline-none focus:border-primary/30 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground mb-1 block",children:"Onboarding"}),e.jsx("div",{className:"flex gap-1",children:["none","soft","strict"].map(r=>e.jsx("button",{onClick:()=>z({...p,onboarding_level:r}),className:`flex-1 px-2 py-1 rounded-md text-[9px] font-medium border transition-all ${p.onboarding_level===r?"bg-primary/10 border-primary/30 text-primary":"bg-card border-border text-muted-foreground"}`,children:es[r]},r))})]})]}):e.jsxs("div",{className:"space-y-2 text-[11px]",children:[e.jsxs("div",{className:"flex justify-between py-1 border-b border-border/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Nome"}),e.jsx("span",{className:"font-medium text-foreground",children:p.app_name})]}),e.jsxs("div",{className:"flex justify-between py-1 border-b border-border/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Tom"}),e.jsx("span",{className:"font-medium text-foreground",children:Le[p.tone]||p.tone})]}),e.jsxs("div",{className:"flex justify-between py-1 border-b border-border/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Idioma"}),e.jsx("span",{className:"font-medium text-foreground",children:p.language})]}),e.jsxs("div",{className:"flex justify-between py-1 border-b border-border/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Onboarding"}),e.jsx("span",{className:"font-medium text-foreground",children:es[p.onboarding_level]||p.onboarding_level})]}),e.jsxs("div",{className:"py-1 border-b border-border/50",children:[e.jsx("span",{className:"text-muted-foreground block mb-1",children:"Mensagem inicial"}),e.jsxs("span",{className:"text-foreground italic",children:['"',p.intro_message,'"']})]}),e.jsxs("div",{className:"py-1",children:[e.jsx("span",{className:"text-muted-foreground block mb-1",children:"Funcionalidades"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:(p.selected_features||[]).map((r,u)=>e.jsx(ve,{variant:"secondary",className:"text-[9px] px-1.5 py-0.5",children:r.replace(/[_-]+/g," ").replace(/\b\w/g,l=>l.toUpperCase())},u))})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs(R,{variant:"outline",size:"sm",className:"flex-1 h-8 text-xs rounded-lg gap-1",onClick:()=>re(y.prompt),children:[e.jsx(qs,{className:"w-3 h-3"}),"Re-estruturar"]}),e.jsxs(R,{size:"sm",className:"flex-1 h-8 text-xs rounded-lg gap-1",onClick:fe,children:[e.jsx(_e,{className:"w-3 h-3"}),"Construir"]})]})]}),ae&&e.jsxs("div",{className:"flex items-center gap-3 bg-card/50 border border-border rounded-xl p-4",children:[e.jsx(me,{className:"w-5 h-5 text-primary animate-spin"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium text-foreground",children:["Construindo ",y.appName,"..."]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:o==="whatsapp"?"Gerando fluxos, agentes e estado do app":"Gerando páginas, componentes e estado do app"})]})]}),f&&((pe=_[_.length-1])==null?void 0:pe.role)==="user"&&e.jsxs("div",{className:"flex gap-2.5",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(Me,{className:"w-3.5 h-3.5 text-primary animate-pulse"})}),e.jsxs("div",{className:"text-sm text-muted-foreground animate-pulse flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary/50 animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary/50 animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary/50 animate-bounce",style:{animationDelay:"300ms"}})]}),e.jsx("span",{className:"text-xs",children:"Construindo..."})]})]})]}),e.jsx("div",{className:"p-3 border-t border-border",children:e.jsxs("div",{className:`rounded-xl border border-border bg-card/50 p-1 transition-colors ${N==="done"||N==="discover"?"focus-within:border-primary/30":"opacity-60"}`,children:[e.jsx("textarea",{value:N==="discover"?W||y.prompt:W,onChange:r=>{N==="discover"?(F(r.target.value),M(u=>({...u,prompt:r.target.value}))):F(r.target.value)},onKeyDown:be,placeholder:N==="discover"?o==="whatsapp"?"Ex: Um bot de qualificação de leads que coleta nome, email e interesse via WhatsApp...":"Ex: Um painel de gestão com dashboard de métricas, cadastro de clientes e relatórios...":N==="done"?"Peça alterações... (modo patch)":"Complete as etapas acima para começar...",rows:2,disabled:N!=="done"&&N!=="discover",className:"w-full bg-transparent border-none outline-none resize-none text-sm text-foreground placeholder:text-muted-foreground px-3 py-2 min-h-[36px] max-h-[120px] disabled:cursor-not-allowed"}),e.jsxs("div",{className:"flex items-center justify-between px-2 pb-1",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("button",{className:"text-muted-foreground hover:text-foreground transition-colors p-1 rounded",disabled:N!=="done"&&N!=="discover",children:e.jsx(Rs,{className:"w-3.5 h-3.5"})})}),N==="discover"?e.jsxs(R,{size:"sm",onClick:ge,disabled:y.prompt.length<10||B,className:"h-8 rounded-full bg-primary hover:bg-primary/90 gap-1.5 text-xs px-4",children:[e.jsx(_e,{className:"w-3.5 h-3.5"}),"Estruturar com IA"]}):e.jsx(R,{size:"icon",onClick:()=>xe(W),disabled:!W.trim()||f||N!=="done",className:"h-8 w-8 rounded-full bg-primary hover:bg-primary/90",children:e.jsx(ns,{className:"w-3.5 h-3.5"})})]})]})})]})};function _a(t){const n={};t.forEach(m=>{const a=m.path.replace(/^\//,"").split("/");let i=n;a.forEach((x,d)=>{i[x]||(i[x]=d===a.length-1?{__file:!0}:{}),i=i[x]})});function o(m){return Object.entries(m).filter(([a])=>a!=="__file").map(([a,i])=>{if(i.__file)return{name:a,type:"file"};const x=o(i);return{name:a,type:"folder",children:x}}).sort((a,i)=>a.type!==i.type?a.type==="folder"?-1:1:a.name.localeCompare(i.name))}return o(n)}const hs=({node:t,depth:n,selectedFile:o,onSelect:m})=>{var s;const[a,i]=c.useState(n===0),x=t.type==="folder",d=o===t.name;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>{x?i(!a):m(t.name)},className:Ue("flex items-center gap-1.5 w-full text-left px-2 py-1 text-xs hover:bg-accent/50 rounded transition-colors",d&&"bg-accent text-accent-foreground"),style:{paddingLeft:`${n*14+8}px`},children:[x?e.jsxs(e.Fragment,{children:[a?e.jsx(rs,{className
215:"w-3 h-3 text-muted-foreground shrink-0"}):e.jsx(ts,{className:"w-3 h-3 text-muted-foreground shrink-0"}),a?e.jsx(oa,{className:"w-3.5 h-3.5 text-primary shrink-0"}):e.jsx(ia,{className:"w-3.5 h-3.5 text-primary shrink-0"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-3 shrink-0"}),e.jsx(cs,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"})]}),e.jsx("span",{className:"truncate",children:t.name})]}),x&&a&&((s=t.children)==null?void 0:s.map(C=>e.jsx(hs,{node:C,depth:n+1,selectedFile:o,onSelect:m},C.name)))]})},Aa=({selectedFile:t,onSelectFile:n,channel:o})=>{const{files:m}=oe(),a=c.useMemo(()=>_a(m),[m]);return m.length===0?e.jsx("div",{className:"w-[220px] min-w-[180px] border-r border-border bg-card/50 flex items-center justify-center text-xs text-muted-foreground p-4 text-center",children:o==="whatsapp"?"Envie uma mensagem no Studio para gerar os fluxos e handlers do bot":"Envie uma mensagem no Studio para gerar as páginas e componentes do app"}):e.jsxs("div",{className:"w-[220px] min-w-[180px] border-r border-border bg-card/50 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[e.jsx(cs,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[m.length," arquivos"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:a.map(i=>e.jsx(hs,{node:i,depth:0,selectedFile:t,onSelect:n},i.name))})]})},Ma=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),Sa=t=>Ma(t).replace(/\b(import|from|export|default|function|return|const|let|var|if|else|switch|case|break|new|this|await|async|class|private|interface|type)\b/g,'<span class="text-purple-400">$1</span>').replace(/(".*?"|'.*?'|`.*?`)/g,'<span class="text-green-400">$1</span>').replace(/(\/\/.*)/g,'<span class="text-muted-foreground">$1</span>'),Ta=({fileName:t})=>{const{files:n}=oe(),o=n.find(a=>a.name===t),m=o?o.content.split(` 216`):[];return t?o?e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:[e.jsx("div",{className:"flex items-center border-b border-border bg-card/30",children:e.jsxs("div",{className:Ue("flex items-center gap-2 px-3 py-1.5 text-xs border-r border-border bg-background"),children:[e.jsx("span",{children:t}),e.jsx(Be,{className:"w-3 h-3 text-muted-foreground hover:text-foreground cursor-pointer"})]})}),e.jsx("div",{className:"px-4 py-1 text-[11px] text-muted-foreground border-b border-border bg-card/20",children:o.path}),e.jsx("div",{className:"flex-1 overflow-auto font-mono text-xs leading-5",children:m.map((a,i)=>e.jsxs("div",{className:"flex hover:bg-accent/20",children:[e.jsx("span",{className:"w-10 shrink-0 text-right pr-3 text-muted-foreground/50 select-none",children:i+1}),e.jsx("pre",{className:"flex-1 whitespace-pre",dangerouslySetInnerHTML:{__html:Sa(a)}})]},i))})]}):e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:["Arquivo não encontrado: ",t]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Selecione um arquivo para visualizar o código"})};function as(t){return t.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().toLowerCase().replace(new RegExp("\\b\\p{L}","gu"),n=>n.toUpperCase()).replace(/\bDe\b/g,"de").replace(/\bDa\b/g,"da").replace(/\bDo\b/g,"do").replace(/\bDas\b/g,"das").replace(/\bDos\b/g,"dos").replace(/\bE\b/g,"e")}const za={professional_friendly:"ð¤",formal:"ð",casual:"ð",empathetic:"ð",direct:"â¡"},We={professional_friendly:"Profissional e Amigável",formal:"Formal",casual:"Casual e DescontraÃdo",empathetic:"Empático e Acolhedor",direct:"Direto e Objetivo"};function $a(t,n,o){var q,j;const m=t==null?void 0:t.agent_config,a=(q=t==null?void 0:t.preview)==null?void 0:q.screen_data,i=(a==null?void 0:a.bot_name)||(m==null?void 0:m.cta_primary)||((j=t==null?void 0:t.app_meta)==null?void 0:j.name)||n,x=(a==null?void 0:a.greeting)||(m==null?void 0:m.intro_message)||o||`Olá! ð Sou o ${i}. Como posso ajudar?`,d=((a==null?void 0:a.quick_replies)||(m==null?void 0:m.quick_replies)||[]).map(as),s=(a==null?void 0:a.stages)||[],C=(a==null?void 0:a.conversation_flow)||[],A={agendamento:{question:"Qual dia e horário funcionam melhor pra você?",options:["Hoje","Amanhã","Próxima semana"]},triagem:{question:"Vou te fazer algumas perguntas rápidas. Pode ser?",options:["Sim, vamos lá","Tenho dúvidas antes"]},suporte:{question:"Me conta o que está acontecendo para eu te ajudar:",options:["Problema técnico","Dúvida de uso"]},preços:{question:"Qual plano te interessa mais?",options:["Básico","Profissional","Empresarial"]},cadastro:{question:"Vou precisar de alguns dados. Pode me passar seu nome completo?",options:["Começar cadastro"]},pedido:{question:"O que você gostaria de pedir?",options:["Ver cardápio","Repetir último pedido"]},cardápio:{question:"Temos várias opções! Alguma preferência?",options:["Ver tudo","Promoções","Mais pedidos"]},pagamento:{question:"Qual forma de pagamento você prefere?",options:["Pix","Cartão","Boleto"]},nutrição:{question:"Vou montar algo personalizado! Me conta: qual é o seu objetivo principal?",options:["Emagrecer","Ganhar massa","Manter peso"]},refeição:{question:"Qual refeição você quer registrar?",options:["Café da manhã","Almoço","Jantar","Lanche"]}};return{botName:i,greeting:x,quickReplies:d,stages:s,getResponse:D=>{const p=D.toLowerCase().trim();for(const T of C)if(p.includes(T.trigger.toLowerCase()))return{text:T.response,suggestions:T.suggestions};const z={oi:`Olá! ð Sou o ${i}. Como posso te ajudar?`,olá:"Oi! ð Que bom te ver aqui. Em que posso ajudar?","bom dia":"Bom dia! âï¸ Estou aqui para te ajudar. O que precisa?","boa tarde":"Boa tarde! ð¤ï¸ Como posso ser útil?","boa noite":"Boa noite! ð Em que posso ajudar?",obrigado:"De nada! ð Precisa de mais alguma coisa?",obrigada:"Por nada! ð Estou aqui se precisar de algo mais.",tchau:"Até logo! ð Foi um prazer ajudar. Volte quando precisar!",sim:"Ãtimo! Vamos lá então. O que você precisa?",não:"Tudo bem! Se mudar de ideia, estou por aqui. ð"};for(const[T,h]of Object.entries(z))if(p.includes(T))return{text:h,suggestions:d.length>0?d.slice(0,3):void 0};for(const[T,h]of Object.entries(A))if(p.includes(T))return{text:`Claro! Vou te ajudar com ${as(T)}. ð 217 218${h.question}`,suggestions:h.options};const v=[{text:"Entendi! Me conta um pouco mais para eu te direcionar melhor. ð",suggestions:d.slice(0,3)},{text:"Perfeito! Para te atender melhor, qual dessas opções faz mais sentido pra você?",suggestions:d.slice(0,3)},{text:"Claro! Esse é um dos meus pontos fortes ðª O que você precisa resolver?",suggestions:["Tenho uma dúvida","Quero começar"]},{text:"Sem problemas! Vamos resolver isso juntos. O que seria mais útil agora?",suggestions:d.slice(0,2)}];return v[Math.floor(Math.random()*v.length)]}}}const Pa=()=>{var B,ee,ae,V,Y,te,se,w,P,ge,re,fe,xe,be,je,pe;const{files:t,appName:n,isGenerating:o,tables:m,wizardData:a,wizardConfig:i,wizardStep:x,structuredConfig:d,appState:s}=oe(),C=!!((B=s==null?void 0:s.runtime)!=null&&B.render_ready),A=t.length>0||!!s,N=x==="done",q=!C&&!N,j=N&&!C&&!o,D=x!=="discover"||A,p=C||A||D,z=((ee=s==null?void 0:s.app_meta)==null?void 0:ee.name)||a.appName||(i==null?void 0:i.appName)||n,v=((ae=s==null?void 0:s.agent_c
218onfig)==null?void 0:ae.intro_message)||a.introMessage||(i==null?void 0:i.introMessage)||"",T=((V=s==null?void 0:s.app_meta)==null?void 0:V.tone)||a.tone||(i==null?void 0:i.tone)||"professional_friendly",h=c.useMemo(()=>$a(s,z,v),[s,z,v]),[_,y]=c.useState([]),[M,W]=c.useState(""),[F,f]=c.useState(!1),g=c.useRef(h.botName);c.useEffect(()=>{g.current!==h.botName&&(g.current=h.botName,y([]))},[h.botName]);const $=()=>{const r=new Date;return`${r.getHours().toString().padStart(2,"0")}:${r.getMinutes().toString().padStart(2,"0")}`},k=r=>{const u=(r||M).trim();u&&(W(""),y(l=>[...l,{role:"user",text:u,time:$()}]),f(!0),setTimeout(()=>{f(!1);const l=h.getResponse(u);y(G=>[...G,{role:"bot",text:l.text,time:$(),suggestions:l.suggestions}])},800+Math.random()*600))},E=Array.isArray((te=(Y=s==null?void 0:s.preview)==null?void 0:Y.screen_data)==null?void 0:te.messages)?(w=(se=s==null?void 0:s.preview)==null?void 0:se.screen_data)==null?void 0:w.messages:[],H=((P=s==null?void 0:s.preview)==null?void 0:P.title)||z||h.botName,Z=((ge=s==null?void 0:s.preview)==null?void 0:ge.subtitle)||"online",K=(()=>{var r,u,l,G;return o?"gerando...":j?"finalizando...":C?`${((r=s.files)==null?void 0:r.length)||0} arquivo(s)${(u=s.flows)!=null&&u.length?` ⢠${s.flows.length} fluxo(s)`:""}${(G=(l=s.database)==null?void 0:l.tables)!=null&&G.length?` ⢠${s.database.tables.length} tabela(s)`:""}`:A?`${t.length} arquivo(s)${m.length>0?` ⢠${m.length} tabelas`:""}`:"Configurando..."})();return e.jsxs("div",{className:"flex-1 flex items-center justify-center bg-muted/5 p-4 gap-6",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"w-[370px] rounded-[2.5rem] border-[3px] border-muted/30 bg-card shadow-2xl overflow-hidden",children:[e.jsx("div",{className:"h-7 bg-[#075e54] dark:bg-[#1f2c34] flex items-center justify-center",children:e.jsx("div",{className:"w-20 h-4 rounded-full bg-black/20"})}),e.jsxs("div",{className:"bg-[#075e54] dark:bg-[#1f2c34] px-4 py-2.5 flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/15 flex items-center justify-center",children:e.jsx(Me,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-white",children:H}),e.jsx("p",{className:"text-[10px] text-white/60",children:o||F?"digitando...":Z})]}),e.jsx(Oe,{className:"w-4 h-4 text-white/70"})]}),e.jsx("div",{className:"bg-[#ece5dd] dark:bg-[#0b141a] p-4 space-y-3 min-h-[380px] max-h-[440px] overflow-y-auto",children:p?e.jsxs(e.Fragment,{children:[j&&e.jsx("div",{className:"flex justify-center animate-in fade-in duration-300",children:e.jsxs("span",{className:"px-3 py-1.5 rounded-full bg-white/80 dark:bg-[#202c33]/80 text-[9px] text-muted-foreground border border-border/30 shadow-sm flex items-center gap-1.5",children:[e.jsx(me,{className:"w-3 h-3 animate-spin"})," Finalizando app..."]})}),E.length>0?E.map((r,u)=>{const l=r.role==="user";return e.jsx("div",{className:`flex ${l?"justify-end":"gap-2"} animate-in fade-in duration-200`,children:e.jsxs("div",{className:`rounded-xl px-3 py-2 max-w-[80%] shadow-sm ${l?"bg-[#dcf8c6] dark:bg-[#005c4b] rounded-tr-sm":"bg-white dark:bg-[#202c33] rounded-tl-sm"}`,children:[e.jsx("p",{className:"text-xs text-foreground whitespace-pre-line",children:r.text||r.content||h.greeting}),e.jsx("p",{className:"text-[9px] text-muted-foreground text-right mt-1",children:r.time||"10:30"})]})},`${r.role}-${u}`)}):e.jsx("div",{className:"flex gap-2 animate-in fade-in slide-in-from-left-2 duration-300",children:e.jsxs("div",{className:"bg-white dark:bg-[#202c33] rounded-xl rounded-tl-sm px-3 py-2 max-w-[80%] shadow-sm",children:[e.jsx("p",{className:"text-xs text-foreground",children:h.greeting}),e.jsx("p",{className:"text-[9px] text-muted-foreground text-right mt-1",children:"10:30"})]})}),q&&T&&e.jsx("div",{className:"flex justify-center animate-in fade-in duration-300",children:e.jsxs("span",{className:"px-2.5 py-1 rounded-full bg-white/80 dark:bg-[#202c33]/80 text-[9px] text-muted-foreground border border-border/30 shadow-sm",children:[za[T]||"ð¤"," Tom: ",We[T]||T]})}),_.length===0&&h.quickReplies.length>0&&e.jsx("div",{className:"flex gap-1.5 flex-wrap animate-in fade-in duration-300 delay-300",children:h.quickReplies.map(r=>e.jsx("button",{onClick:()=>k(r),className:"px-3 py-1.5 rounded-full border border-green-600/30 text-[10px] font-medium text-green-700 dark:text-green-400 bg-white dark:bg-[#202c33] shadow-sm cursor-pointer hover:bg-green-50 dark:hover:bg-[#2a3942] transition-colors",children:r},r))}),_.map((r,u)=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:`flex ${r.role==="user"?"justify-end":"gap-2"} animate-in fade-in duration-200`,children:e.jsxs("div",{className:`rounded-xl px-3 py-2 max-w-[80%] shadow-sm ${r.role==="user"?"bg-[#dcf8c6] dark:bg-[#005c4b] rounded-tr-sm":"bg-white dark:bg-[#202c33] rounded-tl-sm"}`,children:[e.jsx("p",{className:"text-xs text-foreground whitespace-pre-line",children:r.text}),e.jsx("p",{className:"text-[9px] text-muted-foreground text-right mt-1",children:r.time})]})}),r.role==="bot"&&r.suggestions&&r.suggestions.length>0&&u===_.length-1&&e.jsx("div",{className:"flex gap-1.5 flex-wrap animate-in fade-in duration-300",children:r.suggestions.map(l=>e.jsx("button",{onClick:()=>k(l),className:"px-3 py-1.5 rounded-full border border-green-600/30 text-[10px] font-medium text-green-700 dark:text-green-400 bg-white dark:bg-[#202c33] shadow-sm cursor-pointer hover:bg-green-50 dark:hover:bg-[#2a3942] transition-colors",children:l},l))})]},u)),(o||F)&&e.jsx("div",{className:"flex gap-2 animate-in fade-in duration-200",children:e.jsx("div",{className:"bg-white dark:bg-[#202c33] rounded-xl rounded-tl-sm px-4 py-3 shadow-sm",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground
218/50 animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/50 animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground/50 animate-bounce",style:{animationDelay:"300ms"}})]})})})]}):e.jsx("div",{className:"flex items-center justify-center h-full min-h-[300px] text-xs text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(xa,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground/30"}),e.jsxs("p",{children:["Descreva seu app no Studio",e.jsx("br",{}),"para ver o preview aqui"]})]})})}),e.jsxs("div",{className:"bg-[#f0f0f0] dark:bg-[#202c33] px-3 py-2.5 flex items-center gap-2 border-t border-border/30",children:[e.jsx("input",{type:"text",value:M,onChange:r=>W(r.target.value),onKeyDown:r=>r.key==="Enter"&&k(),placeholder:((fe=(re=s==null?void 0:s.preview)==null?void 0:re.screen_data)==null?void 0:fe.input_placeholder)||"Teste seu agente...",disabled:!N,className:"flex-1 bg-white dark:bg-[#2a3942] rounded-full px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground outline-none disabled:opacity-50"}),e.jsx("button",{onClick:()=>k(),disabled:!M.trim()||F||!N,className:"w-8 h-8 rounded-full bg-green-600 flex items-center justify-center shadow-sm hover:bg-green-700 transition-colors disabled:opacity-50",children:e.jsx(Ls,{className:"w-3.5 h-3.5 text-white"})})]}),e.jsx("div",{className:"h-5 bg-[#f0f0f0] dark:bg-[#202c33] flex items-center justify-center",children:e.jsx("div",{className:"w-24 h-1 rounded-full bg-muted-foreground/20"})})]}),D&&e.jsx("div",{className:"absolute -bottom-3 left-1/2 -translate-x-1/2 bg-card border border-border rounded-full px-3 py-1 shadow-lg whitespace-nowrap",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o||j?"bg-yellow-500 animate-pulse":"bg-green-500"}`}),K]})})]}),(A||D)&&e.jsxs("div",{className:"w-[240px] space-y-3 animate-in fade-in slide-in-from-right-4 duration-500",children:[q&&e.jsxs("div",{className:"rounded-xl border border-primary/20 bg-primary/5 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-primary uppercase tracking-wider",children:[e.jsx(Ae,{className:"w-3 h-3"})," Configuração Atual"]}),e.jsxs("div",{className:"space-y-1.5 text-[10px]",children:[z&&z!=="Meu App"&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Nome"}),e.jsx("span",{className:"text-foreground font-medium",children:z})]}),T&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Tom"}),e.jsx("span",{className:"text-foreground font-medium",children:We[T]||T})]}),v&&e.jsxs("div",{className:"pt-0.5",children:[e.jsx("span",{className:"text-muted-foreground block mb-0.5",children:"Intro"}),e.jsxs("span",{className:"text-foreground italic text-[9px]",children:['"',v.slice(0,60),v.length>60?"...":"",'"']})]})]})]}),C&&s&&e.jsxs("div",{className:"rounded-xl border border-green-500/20 bg-green-500/5 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-green-600 uppercase tracking-wider",children:[e.jsx(Ae,{className:"w-3 h-3"})," App Criado"]}),e.jsxs("div",{className:"space-y-1.5 text-[10px]",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Nome"}),e.jsx("span",{className:"text-foreground font-medium",children:s.app_meta.name})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Tom"}),e.jsx("span",{className:"text-foreground font-medium",children:We[s.app_meta.tone]||s.app_meta.tone})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Idioma"}),e.jsx("span",{className:"text-foreground font-medium",children:s.app_meta.language})]})]})]}),(((xe=s==null?void 0:s.files)==null?void 0:xe.length)||t.length>0)&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx(ds,{className:"w-3 h-3"})," Arquivos"]}),e.jsx("div",{className:"space-y-1 max-h-[140px] overflow-y-auto",children:((s==null?void 0:s.files)||t.map(r=>({path:r.path,type:"",purpose:"",content_summary:""}))).map((r,u)=>e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-foreground
218/80 py-0.5",children:[e.jsx(De,{className:"w-3 h-3 text-primary/60 shrink-0"}),e.jsx("span",{className:"truncate",children:r.path.split("/").pop()||r.path})]},u))})]}),(((je=(be=s==null?void 0:s.database)==null?void 0:be.tables)==null?void 0:je.length)||m.length>0)&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx(Se,{className:"w-3 h-3"})," Tabelas"]}),e.jsx("div",{className:"space-y-1",children:(((pe=s==null?void 0:s.database)==null?void 0:pe.tables)||m).map((r,u)=>e.jsxs("div",{className:"flex items-center justify-between text-[10px] py-0.5",children:[e.jsx("span",{className:"text-foreground/80",children:r.name}),e.jsxs(ve,{variant:"secondary",className:"text-[8px] h-4 px-1.5",children:[r.columns.length," cols"]})]},u))})]}),(s==null?void 0:s.flows)&&s.flows.length>0&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx(ce,{className:"w-3 h-3"})," Fluxos"]}),e.jsx("div",{className:"space-y-1",children:s.flows.map((r,u)=>e.jsxs("div",{className:"flex items-center gap-2 text-[10px] py-0.5",children:[e.jsx("span",{className:"w-4 h-4 rounded-full bg-primary/10 text-primary text-[8px] font-bold flex items-center justify-center shrink-0",children:u+1}),e.jsx("span",{className:"text-foreground/80 truncate",children:r.name})]},u))})]}),h.stages.length>0&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx(Ws,{className:"w-3 h-3"})," Jornada"]}),e.jsx("div",{className:"space-y-1",children:h.stages.map((r,u)=>e.jsxs("div",{className:"flex items-center gap-2 text-[10px] py-0.5",children:[e.jsx("span",{className:"w-4 h-4 rounded-full bg-primary/10 text-primary text-[8px] font-bold flex items-center justify-center shrink-0",children:u+1}),e.jsx("span",{className:"text-foreground/80 truncate",children:r})]},u))})]}),(o||j)&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-primary animate-pulse px-1",children:[e.jsx(me,{className:"w-3 h-3 animate-spin"}),j?"Finalizando app...":"Atualizando em tempo real..."]}
218)]})]})},qa=()=>{var W,F,f,g,$,k,E,H,Z,K,B,ee,ae,V,Y,te,se,w,P,ge,re,fe,xe,be,je,pe,r,u,l,G,I,ne,O;const{files:t,appName:n,isGenerating:o,dashboardMetrics:m,tables:a,wizardData:i,wizardConfig:x,wizardStep:d,appState:s}=oe(),C=!!((W=s==null?void 0:s.runtime)!=null&&W.render_ready),A=t.length>0||!!s,N=d==="done",q=!C&&!N,j=N&&!C&&!o,D=d!=="discover"||A,p=C||A||D,z=((F=s==null?void 0:s.app_meta)==null?void 0:F.name)||i.appName||(x==null?void 0:x.appName)||n,v=(f=s==null?void 0:s.preview)==null?void 0:f.screen_data,T=c.useMemo(()=>{if(v!=null&&v.nav_items&&Array.isArray(v.nav_items)&&v.nav_items.length>0){const b={dashboard:he,clientes:le,clients:le,users:le,agenda:Ie,calendar:Ie,mensagens:ce,messages:ce,config:Ne,settings:Ne,home:$e,configurações:Ne,relatórios:he,reports:he};return v.nav_items.map(S=>({label:typeof S=="string"?S:S.label||S.name||"Page",icon:b[(typeof S=="string"?S:S.label||"").toLowerCase()]||$e}))}return[{label:"Dashboard",icon:he},{label:"Clientes",icon:le},{label:"Agenda",icon:Ie},{label:"Mensagens",icon:ce},{label:"Configurações",icon:Ne}]},[v]),h=c.useMemo(()=>v!=null&&v.metrics&&Array.isArray(v.metrics)&&v.metrics.length>0?v.metrics.slice(0,4).map(b=>({label:b.label||b.title||"",value:String(b.value||"0"),change:b.change||""})):m.length>0?m.slice(0,4).map(b=>({label:b.label,value:b.value,change:b.change})):[{label:"Usuários",value:"0"},{label:"Receita",value:"R$ 0"},{label:"Conversão",value:"0%"}],[v,m]),_=(v==null?void 0:v.active_page)||((g=T[0])==null?void 0:g.label)||"Dashboard",y=(v==null?void 0:v.page_title)||_,M=v==null?void 0:v.table_data;return e.jsxs("div",{className:"flex-1 flex items-center justify-center bg-muted/5 p-4 gap-6",children:[e.jsxs("div",{className:"w-full max-w-[780px] rounded-xl border border-border bg-card shadow-2xl overflow-hidden transition-all duration-500",children:[e.jsxs("div",{className:"bg-muted/40 px-3 py-2 flex items-center gap-2 border-b border-border",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-red-400/80"}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-yellow-400/80"}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-400/80"})]}),e.jsx("div",{className:"flex-1 mx-8",children:e.jsxs("div",{className:"bg-background rounded-md px-3 py-1 text-[10px] text-muted-foreground text-center border border-border/50",children:["ð ",z.toLowerCase().replace(/\s+/g,""),".aikortex.com"]})}),(o||j)&&e.jsx(me,{className:"w-3.5 h-3.5 text-primary animate-spin mr-1"})]}),p?e.jsxs("div",{className:"flex h-[420px]",children:[e.jsxs("div",{className:"w-[160px] border-r border-border bg-card/80 p-3 space-y-1",children:[e.jsxs("div",{className:"px-2 py-2 mb-2",children:[e.jsx("p",{className:"text-xs font-semibold text-foreground",children:z}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:i.companyName||(($=s==null?void 0:s.preview)==null?void 0:$.subtitle)||"Painel de Gestão"})]}),T.map((b,S)=>e.jsxs("div",{className:`flex items-center gap-2 px-2.5 py-2 rounded-lg text-[11px] transition-colors ${S===0?"bg-primary/10 text-primary font-medium":"text-muted-foreground hover:bg-muted/30"}`,children:[e.jsx(b.icon,{className:"w-3.5 h-3.5"}),b.label]},b.label))]}),e.jsxs("div",{className:"flex-1 p-5 space-y-4 overflow-auto",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:y}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:j?"Finalizando app...":q?"Configurando seu app...":((k=s==null?void 0:s.preview)==null?void 0:k.subtitle)||"Visão geral do sistema"})]}),(o||j)&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-primary animate-pulse",children:[e.jsx(me,{className:"w-3 h-3 animate-spin"}),j?"Finalizando...":"Atualizando..."]})]}),q&&i.prompt&&e.jsxs("div",{className:"rounded-xl border border-primary/20 bg-primary/5 p-3 space-y-1.5 animate-in fade-in duration-300",children:[e.jsx("p",{className:"text-[10px] font-semibold text-primary",children:"ð Descrição do App"}
218),e.jsxs("p",{className:"text-[10px] text-foreground/80 leading-relaxed",children:[i.prompt.slice(0,150),i.prompt.length>150?"...":""]})]}),e.jsx("div",{className:`grid gap-3 ${h.length<=3?"grid-cols-3":"grid-cols-4"}`,children:h.map(b=>e.jsxs("div",{className:"rounded-xl border border-border p-3 bg-card/50 animate-in fade-in duration-300",children:[e.jsx("p",{className:"text-[9px] text-muted-foreground mb-0.5",children:b.label}),e.jsx("p",{className:"text-base font-bold text-foreground",children:b.value}),b.change&&e.jsx("span",{className:"text-[9px] text-muted-foreground",children:b.change})]},b.label))}),e.jsxs("div",{className:"rounded-xl border border-border p-4 bg-card/50",children:[e.jsx("p",{className:"text-[10px] font-medium text-foreground mb-3",children:((E=v==null?void 0:v.chart_data)==null?void 0:E.title)||"Atividade recente"}),e.jsx("div",{className:"flex items-end gap-1.5 h-[80px]",children:[40,65,45,80,55,90,70,95,60,85,75,100].map((b,S)=>e.jsx("div",{className:"flex-1 rounded-sm transition-all duration-500 overflow-hidden",style:{height:`${b}%`},children:e.jsx("div",{className:"w-full h-full bg-gradient-to-t from-primary/60 to-primary/20 rounded-sm"})},S))})]}),(M||((Z=(H=s==null?void 0:s.database)==null?void 0:H.tables)==null?void 0:Z.length)||a.length>0)&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/50 overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-2.5 border-b border-border flex items-center justify-between",children:[e.jsx("p",{className:"text-[10px] font-medium text-foreground",children:(M==null?void 0:M.name)||((ee=(B=(K=s==null?void 0:s.database)==null?void 0:K.tables)==null?void 0:B[0])==null?void 0:ee.name)||((ae=a[0])==null?void 0:ae.name)||"Dados"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ve,{variant:"secondary",className:"text-[8px] h-4",children:[((V=M==null?void 0:M.columns)==null?void 0:V.length)||((w=(se=(te=(Y=s==null?void 0:s.database)==null?void 0:Y.tables)==null?void 0:te[0])==null?void 0:se.columns)==null?void 0:w.length)||((ge=(P=a[0])==null?void 0:P.columns)==null?void 0:ge.length)||0," colunas"]}),e.jsx(Ve,{className:"w-3 h-3 text-muted-foreground"})]})]}),e.jsxs("div",{className:"px-4 py-1",children:[e.jsx("div",{className:"flex items-center gap-3 py-1.5 border-b border-border/50",children:((M==null?void 0:M.columns)||((be=(xe=(fe=(re=s==null?void 0:s.database)==null?void 0:re.tables)==null?void 0:fe[0])==null?void 0:xe.columns)==null?void 0:be.map(b=>b.name))||((pe=(je=a[0])==null?void 0:je.columns)==null?void 0:pe.map(b=>b.name))||[]).slice(0,4).map(b=>{const S=typeof b=="string"?b:b.name||b;return e.jsx("div",{className:"flex-1",children:e.jsx("span",{className:"text-[8px] font-semibold text-muted-foreground uppercase",children:S})},S)})}),[1,2,3].map(b=>{var S,ue,ye,we,Ce,U;return e.jsx("div",{className:"flex items-center gap-3 py-2",children:((M==null?void 0:M.columns)||((we=(ye=(ue=(S=s==null?void 0:s.database)==null?void 0:S.tables)==null?void 0:ue[0])==null?void 0:ye.columns)==null?void 0:we.map(J=>J.name))||((U=(Ce=a[0])==null?void 0:Ce.columns)==null?void 0:U.map(J=>J.name))||[]).slice(0,4).map((J,Ee)=>{const ke=typeof J=="string"?J:J.name||J;return e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:`h-2 bg-muted/40 rounded ${Ee===0?"w-16":"w-12"}`})},ke)})},b)})]})]})]})]}):e.jsx("div",{className:"h-[420px] flex items-center justify-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Te,{className:"w-10 h-10 mx-auto mb-3 text-muted-foreground/20"}),e.jsxs("p",{className:"text-xs",children:["Descreva seu app no Studio",e.jsx("br",{}),"para ver o preview aqui"]})]})})]}),(A||D)&&e.jsxs("div",{className:"w-[220px] space-y-3 animate-in fade-in slide-in-from-right-4 duration-500",children:[C&&s?e.jsxs("div",{className:"rounded-xl border border-green-500/20 bg-green-500/5 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-green-600 uppercase tracking-wider",children:[e.jsx(Ae,{className:"w-3 h-3"})," App Criado"]}),e.jsxs("div",{className:"space-y-1.5 text-[10px]",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Nome"}),e.jsx("span",{className:"text-foreground font-medium",children:s.app_meta.name})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Idioma"}),e.jsx("span",{className:"text-foreground font-medium",children:s.app_meta.language})]})]})]}):q?e.jsxs("div",{className:"rounded-xl border border-primary/20 bg-primary/5 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-primary uppercase tracking-wider",children:[e.jsx(Ae,{className:"w-3 h-3"})," Configuração"]}),e.jsx("div",{className:"space-y-1.5 text-[10px]",children:z&&z!=="Meu App"&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Nome"}),e.jsx("span",{className:"text-foreground font-medium",children:z})]})})]}):null,(((r=s==null?void 0:s.files)==null?void 0:r.length)||t.length>0)&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx(ds,{className:"w-3 h-3"})," Arquivos (",((u=s==null?void 0:s.files)==null?void 0:u.length)||t.length,")"]}),e.jsx("div",{className:"space-y-1 max-h-[160px] overflow-y-auto",children:((s==null?void 0:s.files)||t.map(b=>({path:b.path}))).map((b,S)=>{var ue;return e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-foreground
218/80 py-0.5",children:[e.jsx(De,{className:"w-3 h-3 text-primary/60 shrink-0"}),e.jsx("span",{className:"truncate",children:((ue=b.path)==null?void 0:ue.split("/").pop())||b.name})]},S)})})]}),(((G=(l=s==null?void 0:s.database)==null?void 0:l.tables)==null?void 0:G.length)||a.length>0)&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx(Se,{className:"w-3 h-3"})," Tabelas (",((ne=(I=s==null?void 0:s.database)==null?void 0:I.tables)==null?void 0:ne.length)||a.length,")"]}),e.jsx("div",{className:"space-y-1",children:(((O=s==null?void 0:s.database)==null?void 0:O.tables)||a).map((b,S)=>e.jsxs("div",{className:"flex items-center justify-between text-[10px] py-0.5",children:[e.jsx("span",{className:"text-foreground/80",children:b.name}),e.jsxs(ve,{variant:"secondary",className:"text-[8px] h-4 px-1.5",children:[b.columns.length," cols"]})]},S))})]}),(s==null?void 0:s.ui_modules)&&s.ui_modules.length>0&&e.jsxs("div",{className:"rounded-xl border border-border bg-card/60 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx($e,{className:"w-3 h-3"})," Módulos"]}),e.jsx("div",{className:"space-y-1",children:s.ui_modules.map((b,S)=>e.jsx("div",{className:"text-[10px] text-foreground/80 py-0.5 truncate",children:b.name},S))})]}),(o||j)&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-primary animate-pulse px-1",children:[e.jsx(me,{className:"w-3 h-3 animate-spin"}),j?"Finalizando app...":"Atualizando em tempo real..."]}
218)]})]})},Da=({})=>{const{channel:t}=oe();return t==="whatsapp"?e.jsx(Pa,{}):e.jsx(qa,{})},Ea=()=>{var d;const{tables:t}=oe(),[n,o]=c.useState(""),[m,a]=c.useState(""),i=n||((d=t[0])==null?void 0:d.name)||"",x=t.find(s=>s.name===i)||t[0];return t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Envie uma mensagem no Studio para gerar as tabelas do banco de dados"}):e.jsxs("div",{className:"flex-1 flex bg-background overflow-hidden",children:[e.jsxs("div",{className:"w-[200px] min-w-[180px] border-r border-border flex flex-col bg-card/50",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-3 border-b border-border",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"Tables"}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-6 w-6",title:"Atualizar",children:e.jsx(Us,{className:"w-3.5 h-3.5 text-muted-foreground"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),className:Ue("flex items-center gap-2 w-full text-left px-3 py-2 text-xs transition-colors",i===s.name?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:[e.jsx(pa,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:s.name})]},s.name))})]}),x&&e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:x.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:x.rows.length===0?"No rows":`${x.rows.length} rows`})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(Ge,{className:"w-3.5 h-3.5"})}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(Qe,{className:"w-3.5 h-3.5 rotate-180"})}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(Qe,{className:"w-3.5 h-3.5"})}),e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7",children:e.jsx(De,{className:"w-3.5 h-3.5"})})]})]}),e.jsx("div",{className:"px-4 py-2 border-b border-border",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ve,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),e.jsx(de,{placeholder:"Search...",value:m,onChange:s=>a(s.target.value),className:"h-8 pl-8 text-xs bg-muted/30 border-border"})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/30",children:[e.jsx("th",{className:"w-10 px-3 py-2 text-left",children:e.jsx(Os,{className:"h-3.5 w-3.5"})}),x.columns.map(s=>e.jsx("th",{className:"px-3 py-2 text-left font-medium text-muted-foreground whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:s.name}),e.jsxs("span",{className:"text-[10px] text-muted-foreground/60",children:["(",s.type,")"]}),s.isPK&&e.jsx("span",{className:"text-[9px] font-semibold text-primary",children:"PK"}),e.jsx(ra,{className:"w-3 h-3 text-muted-foreground/40 shrink-0 cursor-pointer hover:text-foreground"})]})},s.name))]})}),e.jsx("tbody",{children:x.rows.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:x.columns.length+1,className:"text-center py-16 text-sm text-muted-foreground",children:"No data found"})})})]})})]})]})},Ia=({})=>{var p,z,v,T;const{channel:t,dashboardMetrics:n,tables:o,isGenerating:m,appState:a,wizardStep:i}=oe(),x={"Conversas Ativas":ce,"Leads Qualificados":le,"Taxa de Resposta":Re,"Tempo Médio":Bs,"Usuários Ativos":le,Pageviews:he,Conversão:Je,"Bounce Rate":Re,Usuários:le,Conversas:ce,Sessões:Re,Conversões:Je},d=((p=a==null?void 0:a.app_meta)==null?void 0:p.type)||t,s=((z=a==null?void 0:a.app_meta)==null?void 0:z.name)||"Meu App",C=i==="done",A=!!a,N=n.length>0,q=o.length>
2180,j=N?n:d==="whatsapp"?[{label:"Usuários",value:"0",change:"--",up:!0},{label:"Conversas",value:"0",change:"--",up:!0},{label:"Sessões",value:"0",change:"--",up:!0}]:[{label:"Usuários",value:"0",change:"--",up:!0},{label:"Sessões",value:"0",change:"--",up:!0},{label:"Conversões",value:"0",change:"--",up:!0}],D=(T=(v=a==null?void 0:a.database)==null?void 0:v.tables)!=null&&T.length?a.database.tables.map(h=>({name:h.name,columns:h.columns.map(_=>({name:_.name,type:_.type,isPK:_.name==="id",required:_.required}))})):o;return!A&&!N&&!q?m||C?e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(me,{className:"w-6 h-6 text-primary animate-spin"}),e.jsx("span",{className:"text-xs",children:t==="whatsapp"?"Gerando dashboard de conversas...":"Gerando dashboard do app..."})]})}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm text-center px-8",children:e.jsxs("div",{children:[e.jsx(Se,{className:"w-10 h-10 mx-auto mb-3 text-muted-foreground/20"}),e.jsx("p",{className:"text-xs",children:t==="whatsapp"?"Crie um WhatsApp App no Studio para ver o dashboard aqui":"Crie um Web App no Studio para ver o dashboard aqui"})]})}):e.jsxs("div",{className:"flex-1 overflow-auto p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Painel de Gestão"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s," · ",d==="whatsapp"?"WhatsApp App":"Web App"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-primary animate-pulse",children:[e.jsx(me,{className:"w-3 h-3 animate-spin"})," Atualizando..."]}),e.jsxs("span",{className:`flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-medium border ${d==="whatsapp"?"bg-green-500/10 text-green-600 border-green-500/20":"bg-primary/10 text-primary border-primary/20"}`,children:[d==="whatsapp"?e.jsx(qe,{className:"w-3 h-3"}):e.jsx(Te,{className:"w-3 h-3"}),d==="whatsapp"?"WhatsApp":"Web App"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 xl:grid-cols-4 gap-4",children:j.map(h=>{const _=x[h.label]||he,y=h.change==="--"||h.change==="placeholder";return e.jsxs("div",{className:"rounded-xl border border-border p-4 bg-card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(_,{className:"w-4 h-4 text-muted-foreground"}),!y&&e.jsxs("span",{className:`flex items-center gap-0.5 text-[10px] font-medium ${h.up?"text-primary":"text-destructive"}`,children:[h.up?e.jsx(ns,{className:"w-3 h-3"}):e.jsx(ta,{className:"w-3 h-3"}),h.change]})]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:h.value}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:h.label})]},h.label)})}),D.length>0&&e.jsxs("div",{className:"rounded-xl border border-border p-5 bg-card space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Tabelas do Banco"}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[D.length," tabela(s)"]})]}),e.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-4",children:D.map(h=>e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"font-mono text-sm text-foreground",children:h.name}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[h.columns.length," colunas"]})]}),e.jsx("div",{className:"space-y-2",children:h.columns.map(_=>e.jsxs("div",{className:"rounded-md border border-border/70 px-3 py-2 text-xs bg-card",children:[e.jsx("span",{className:"font-mono text-foreground",children:_.name}),e.jsxs("span",{className:"text-muted-foreground",children:[":",String(_.type).toUpperCase(),"required"in _&&_.required?" ⢠obrigatório":"",_.isPK?" ⢠PK":""]})]},`${h.name}-${_.name}`))})]},h.name))})]}),(a==null?void 0:a.flows)&&a.flows.length>0&&e.jsxs("div",{className:"rounded-xl border border-border p-5 bg-card space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Fluxos de Conversa"})]}),e.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-3",children:a.flows.map((h,_)=>e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-primary/10 text-primary text-[9px] font-bold flex items-center justify-center shrink-0",children:_+1}),e.jsx("span",{className:"text-xs font-medium text-foreground",children:h.name})]}),h.description&&e.jsx("p",{className:"text-[10px] text-muted-foreground pl-7",children:h.description})]},h.id||_))})]})]})},Ra=[{id:"overview",label:"Geral",icon:la},{id:"intelligence",label:"IA",icon:Ds},{id:"access",label:"Acesso",icon:is},{id:"knowledge",label:"Dados",icon:Fs},{id:"channels",label:"Canais",icon:Ke}];function L({title:t,icon:n,children:o,badge:m}){return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center",children:e.jsx(n,{className:"w-3.5 h-3.5 text-primary"})}),e.jsx("h3",{className:"text-xs font-semibold text-foreground flex-1",children:t}),m&&e.jsx(ve,{variant:"outline",className:"text-[9px] h-4",children:m})]}),o]})}function Q({label:t,desc:n,defaultOn:o=!1}){const[m,a]=c.useState(o);return e.jsxs("div",{className:"flex items-center justify-between gap-3 p-2.5 rounded-lg border border-border bg-card/50 hover:bg-card transition-colors",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs text-foreground block",children:t}),n&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n})]}),e.jsx(os,{checked:m,onCheckedChange:a,className:"shrink-0"})]})}const La=({channel:t})=>{const{wizardConfig:n,appName:o}=oe(),[m,a]=c.useState((n==null?void 0:n.prompt)||""),[i,x]=c.useState("draft"),[d,s]=c.useState((n==null?void 0:n.introMessage)||"Olá! ð Como posso ajudar?"),[C,A]=c.useState((n==null?void 0:n.tone)||"professional_friendly"),[N,q]=c.useState((n==null?void 0:n.language)||"pt-BR");return c.useEffect(()=>{n&&(a(n.prompt),s(n.introMessage),A(n.tone),q(n.language))},[n]),e.jsxs("div",{className:"space-y-5",children:[e.jsx(L,{title:"Sobre o App",icon:ls,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Descrição"}),e.jsx(ze,{value:m,onChange:j=>a(j.target.value),placeholder:"Descreva o que seu app faz...",className:"text-xs min-h-[70px] bg-card/50 border-border/50 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1.5 block",children:"Status"}),e.jsx("div",{className:"flex gap-1.5",children:["draft","active","paused"].map(j=>e.jsx("button",{onClick:()=>x(j),className:`flex-1 px-2 py-1.5 rounded-md text-[10px] font-medium border transition-all ${i===j?j==="active"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":j==="paused"?"bg-amber-500/15 text-amber-400 border-amber-500/30":"bg-primary/10 text-primary border-primary/30":"bg-card/50 text-muted-foreground border-border hover:border-border/80"}`,children:j==="draft"?"Rascunho":j==="active"?"Ativo":"Pausado"},j))})]})]})}),e.jsx(L,{title:"Identidade Visual",icon:Ks,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-dashed border-border bg-card/30 hover:border-primary/30 transition-colors cursor-pointer",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/10",children:e.jsx(He,{className:"w-5 h-5 text-primary/60"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:"Ãcone do App"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"PNG, SVG · 512x512px"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Cor principal"}),e.jsx("div",{className:"flex gap-1.5",children:["#6366f1","#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#06b6d4"].map(j=>e.jsx("button",{className:"w-6 h-6 rounded-full border-2 border-transparent hover:border-foreground
218/20 transition-all hover:scale-110",style:{backgroundColor:j}},j))})]})]})}),e.jsx(L,{title:"Perfil do App",icon:Es,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Tom de voz"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Object.entries({professional_friendly:"Profissional e Amigável",formal:"Formal",casual:"Casual e DescontraÃdo",empathetic:"Empático e Acolhedor",direct:"Direto e Objetivo"}).map(([j,D])=>e.jsx("button",{onClick:()=>A(j),className:`px-2.5 py-1.5 rounded-lg text-[10px] font-medium border transition-all ${C===j?"bg-primary/10 border-primary/30 text-primary":"bg-card border-border text-muted-foreground hover:border-border/80"}`,children:D},j))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Idioma"}),e.jsx("div",{className:"flex gap-1.5",children:[["pt-BR","ð§ð· Português"],["en","ðºð¸ English"],["es","ðªð¸ Español"]].map(([j,D])=>e.jsx("button",{onClick:()=>q(j),className:`px-2.5 py-1.5 rounded-lg text-[10px] font-medium border transition-all ${N===j?"bg-primary/10 border-primary/30 text-primary":"bg-card border-border text-muted-foreground hover:border-border/80"}`,children:D},j))})]})]})}),t==="whatsapp"&&e.jsx(L,{title:"Mensagens Padrão",icon:ce,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Saudação"}),e.jsx(ze,{value:d,onChange:j=>s(j.target.value),className:"text-xs min-h-[50px] bg-card/50 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Fallback"}),e.jsx(ze,{defaultValue:"Desculpe, não entendi. Pode reformular?",className:"text-xs min-h-[50px] bg-card/50 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Fora do horário"}),e.jsx(ze,{defaultValue:"Estamos fora do horário. Retornaremos em breve!",className:"text-xs min-h-[50px] bg-card/50 resize-none"})]})]})}),e.jsx(L,{title:"Notificações",icon:Js,children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{label:"Lead qualificado",desc:"Notificar ao captar lead"}),e.jsx(Q,{label:"Conversa sem resposta",desc:"Alerta após 5min inativo"}),e.jsx(Q,{label:"Resumo diário",desc:"Relatório por e-mail"})]})})]})},Wa=()=>e.jsxs("div",{className:"space-y-5",children:[e.jsx(Xe,{providers:Vs,title:"Modelos de IA (LLMs)",subtitle:"Conecte provedores de IA para potencializar seu app."}),e.jsx(Xe,{providers:Gs,title:"Serviços & Ferramentas",subtitle:"Conecte ferramentas externas para expandir as capacidades."})]}),Fa=()=>{const[t,n]=c.useState("public"),[o,m]=c.useState([{email:"[email protected]",role:"admin"}]),[a,i]=c.useState(""),x=()=>{a.trim()&&(m([...o,{email:a.trim(),role:"user"}]),i(""))};return e.jsxs("div",{className:"space-y-5",children:[e.jsx(L,{title:"Modo de Acesso",icon:t==="public"?da:Ze,children:e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>n("public"),className:`flex flex-col items-center gap-2 p-4 rounded-xl border transition-all ${t==="public"?"bg-emerald-500/10 border-emerald-500/30 shadow-sm":"bg-card/50 border-border hover:border-border/80"}`,children:[e.jsx(Qs,{className:`w-5 h-5 ${t==="public"?"text-emerald-400":"text-muted-foreground"}`}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:"Público"}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"Qualquer pessoa"})]})]}),e.jsxs("button",{onClick:()=>n("private"),className:`flex flex-col items-center gap-2 p-4 rounded-xl border transition-all ${t==="private"?"bg-amber-500/10 border-amber-500/30 shadow-sm":"bg-card/50 border-border hover:border-border/80"}`,children:[e.jsx(Ze,{className:`w-5 h-5 ${t==="private"?"text-amber-400":"text-muted-foreground"}`}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:"Privado"}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"Apenas autorizados"})]})]})]})}),t==="private"&&e.jsx(L,{title:"Usuários Autorizados",icon:le,badge:`${o.length}`,children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(de,{value:a,onChange:d=>i(d.target.value),placeholder:"[email protected]",className:"h-8 text-xs bg-card/50 flex-1",onKeyDown:d=>d.key==="Enter"&&x()}),e.jsx(R,{size:"sm",className:"h-8 w-8 p-0 shrink-0",onClick:x,children:e.jsx(Ge,{className:"w-3.5 h-3.5"})})]}),o.map((d,s)=>e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-card/50 border border-border",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx("span",{className:"text-[9px] font-bold text-primary",children:d.email[0].toUpperCase()})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-[11px] text-foreground truncate",children:d.email})}),e.jsx(ve,{variant:"outline",className:"text-[8px] h-4 capitalize",children:d.role}),e.jsx("button",{onClick:()=>m(o.filter((C,A)=>A!==s)),className:"text-muted-foreground hover:text-destructive transition-colors",children:e.jsx(Be,{className:"w-3 h-3"})})]},s))]})}),e.jsx(L,{title:"Autenticação",icon:is,children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{label:"Login obrigatório",desc:"Exigir autenticação para usar"}),e.jsx(Q,{label:"Registro aberto",desc:"Permitir novos cadastros",defaultOn:!0}),e.jsx(Q,{label:"Login social",desc:"Google, Apple"})]})}),e.jsx(L,{title:"Limites de Uso",icon:he,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Msgs / usuário / dia"}),e.jsx(de,{type:"number",defaultValue:100,className:"h-8 text-xs bg-card/50"})]}),e.jsx(Q,{label:"Rate limiting",desc:"Anti-spam automático",defaultOn:!0})]})})]})},Oa=()=>{const[t,n]=c.useState([{name:"catalogo-produtos.pdf",size:"2.4 MB",type:"PDF"}]),[o,m]=c.useState(["https://meusite.com.br"]),[a,i]=c.useState(""),x=()=>{a.trim()&&(m([...o,a.trim()]),i(""))};return e.jsxs("div",{className:"space-y-5",children:[e.jsx(L,{title:"Arquivos de Conhecimento",icon:na,badge:`${t.length}`,children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center justify-center p-6 rounded-xl border-2 border-dashed border-border bg-card/20 hover:border-primary/30 hover:bg-primary/5 transition-all cursor-pointer group",children:e.jsxs("div",{className:"text-center",children:[e.jsx(He,{className:"w-6 h-6 mx-auto mb-2 text-muted-foreground group-hover:text-primary transition-colors"}),e.jsx("p",{className:"text-xs text-muted-foreground group-hover:text-foreground transition-colors",children:"Arraste arquivos ou clique para enviar"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"PDF, TXT, CSV, DOCX · até 10MB"})]})}),t.map((d,s)=>e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-lg bg-card/50 border border-border",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-red-500/10 flex items-center justify-center",children:e.jsx(ls,{className:"w-4 h-4 text-red-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[11px] font-medium text-foreground truncate",children:d.name}),e.jsxs("p",{className:"text-[9px] text-muted-foreground",children:[d.size," · ",d.type]})]}),e.jsx("button",{onClick:()=>n(t.filter((C,A)=>A!==s)),className:"text-muted-foreground hover:text-destructive transition-colors",children:e.jsx(Xs,{className:"w-3.5 h-3.5"})})]},s))]})}),e.jsx(L,{title:"Fontes Web",icon:Ve,badge:`${o.length}`,children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(de,{value:a,onChange:d=>i(d.target.value),placeholder:"https://meusite.com.br/docs",className:"h-8 text-xs bg-card/50 flex-1",onKeyDown:d=>d.key==="Enter"&&x()}),e.jsx(R,{size:"sm",className:"h-8 w-8 p-0 shrink-0",onClick:x,children:e.jsx(Ge,{className:"w-3.5 h-3.5"})})]}),o.map((d,s)=>e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-card/50 border border-border",children:[e.jsx(Ke,{className:"w-3.5 h-3.5 text-blue-400 shrink-0"}),e.jsx("span",{className:"text-[11px] text-foreground truncate flex-1",children:d}),e.jsx("button",{onClick:()=>m(o.filter((C,A)=>A!==s)),className:"text-muted-foreground hover:text-destructive transition-colors",children:e.jsx(Be,{className:"w-3 h-3"})})]},s)),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"O conteúdo será indexado automaticamente para consulta da IA."})]})}),e.jsx(L,{title:"Configurações de Busca",icon:_e,children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{label:"Busca semântica",desc:"Busca por similaridade de significado",defaultOn:!0}),e.jsx(Q,{label:"Web search",desc:"Pesquisar na internet em tempo real"}),e.jsx(Q,{label:"Auto-indexação",desc:"Re-indexar ao atualizar arquivos",defaultOn:!0})]})})]})},Ua=({channel:t,onChannelChange:n})=>e.jsxs("div",{className:"space-y-5",children:[e.jsx(L,{title:"Canal Principal",icon:Ke,children:e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>n("whatsapp"),className:`flex flex-col items-center gap-2 p-4 rounded-xl border transition-all ${t==="whatsapp"?"bg-emerald-500/10 border-emerald-500/30 shadow-sm":"bg-card/50 border-border hover:border-border/80"}`,children:[e.jsx(Oe,{className:`w-5 h-5 ${t==="whatsapp"?"text-emerald-400":"text-muted-foreground"}`}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:"WhatsApp"}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"Chatbot conversacional"})]})]}),e.jsxs("button",{onClick:()=>n("web"),className:`flex flex-col items-center gap-2 p-4 rounded-xl border transition-all ${t==="web"?"bg-primary/10 border-primary/30 shadow-sm":"bg-card/50 border-border hover:border-border/80"}`,children:[e.jsx(Te,{className:`w-5 h-5 ${t==="web"?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:"Web App"}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:"Interface visual"})]})]})]})}),t==="whatsapp"&&e.jsxs(e.Fragment,{children:[e.jsx(L,{title:"WhatsApp Business API",icon:()=>e.jsx(qe,{className:"w-4 h-4"}),children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5 p-3 rounded-lg border border-border bg-card/50",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-emerald-500/15 flex items-center justify-center",children:e.jsx(Oe,{className:"w-4 h-4 text-emerald-500"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:"WABA"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Não conectado"})]}),e.jsx(R,{variant:"outline",size:"sm",className:"h-7 text-[10px]",children:"Conectar"})]}),e.jsx(de,{placeholder:"Phone Number ID",className:"h-8 text-xs bg-card/50"}),e.jsx(de,{placeholder:"Access Token",type:"password",className:"h-8 text-xs bg-card/50"}),e.jsx(de,{placeholder:"Verify Token",className:"h-8 text-xs bg-card/50"})]})}),e.jsx(L,{title:"Jornada Conversacional",icon:Ae,children:e.jsxs("div",{className:"space-y-1.5",children:[["Saudação","Qualificação","Atendimento","Follow-up","Encerramento"].map((o,m)=>e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-lg border border-border bg-card/50 hover:border-primary/20 transition-colors cursor-pointer group",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-primary/10 text-primary text-[10px] font-bold flex items-center justify-center shrink-0",children:m+1}),e.jsx("span",{className:"text-xs text-foreground flex-1",children:o}),e.jsx(ts,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary transition-colors"})]},o)),e.jsx(R,{variant:"outline",size:"sm",className:"w-full h-7 text-[10px] mt-1",children:"+ Adicionar etapa"})]})}),e.jsx(L,{title:"Agentes",icon:Me,children:e.jsxs("div",{className:"space-y-1.5",children:[[{name:"Qualificador",desc:"Coleta e qualifica leads"},{name:"Atendente",desc:"Responde dúvidas gerais"}].map(o=>e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-lg border border-border bg-card/50 cursor-pointer hover:border-primary/20 transition-colors",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(Me,{className:"w-3.5 h-3.5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[11px] font-medium text-foreground",children:o.name}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:o.desc})]}),e.jsx(Ne,{className:"w-3 h-3 text-muted-foreground"})]},o.name)),e.jsx(R,{variant:"outline",size:"sm",className:"w-full h-7 text-[10px]",children:"+ Adicionar agente"})]})})]}),t==="web"&&e.jsxs(e.Fragment,{children:[e.jsx(L,{title:"Configurações Web",icon:$e,children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{label:"Design responsivo",desc:"Adaptar para mobile",defaultOn:!0}),e.jsx(Q,{label:"PWA",desc:"Instalável no celular"}),e.jsx(Q,{label:"SEO",desc:"Otimização para buscadores",defaultOn:!0})]})}),e.jsx(L,{title:"Widget de Chat",icon:ce,children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Q,{label:"Chat integrado",desc:"Widget flutuante no site"}),e.jsx(Q,{label:"Chat WhatsApp",desc:"Redirecionar para WhatsApp"})]})})]}),e.jsx(L,{title:"Integrações",icon:Zs,children:e.jsx("div",{className:"space-y-1.5",children:[{name:"CRM",desc:"Sincronizar leads",icon:le},{name:"Calendário",desc:"Agendamentos",icon:he},{name:"Pagamentos",desc:"Cobranças",icon:Ys}
218,{name:"Webhook",desc:"Eventos externos",icon:Is}].map(o=>e.jsxs("div",{className:"flex items-center justify-between gap-2 p-2.5 rounded-lg border border-border bg-card/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o.icon,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-foreground",children:o.name}),e.jsx("p",{className:"text-[9px] text-muted-foreground",children:o.desc})]})]}),e.jsx(os,{})]},o.name))})})]}),Ba=({channel:t,onChannelChange:n,open:o,onClose:m})=>{const[a,i]=c.useState("overview");return e.jsx(Ss,{open:o,onOpenChange:x=>!x&&m(),children:e.jsxs(Ts,{side:"right",className:"w-full sm:w-[380px] p-0 border-l border-border flex flex-col",children:[e.jsxs(zs,{className:"px-3 py-2.5 border-b border-border shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2.5",children:[e.jsx($s,{className:"text-sm font-semibold text-foreground truncate min-w-0",children:"Configurações"}),e.jsxs(ve,{variant:"outline",className:"text-[10px] gap-1 h-5",children:[t==="whatsapp"?e.jsx(qe,{className:"w-3 h-3 text-emerald-500"}):e.jsx(Te,{className:"w-3 h-3 text-primary"}),t==="whatsapp"?"WhatsApp":"Web"]})]}),e.jsx("div",{className:"flex gap-0.5 p-0.5 bg-muted/40 rounded-lg",children:Ra.map(x=>e.jsxs("button",{onClick:()=>i(x.id),className:`flex-1 flex items-center justify-center gap-1 py-1.5 rounded-md text-[10px] font-medium transition-all ${a===x.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(x.icon,{className:"w-3 h-3"}),e.jsx("span",{className:"hidden xl:inline",children:x.label})]},x.id))})]}),e.jsx(Hs,{className:"flex-1",children:e.jsxs("div",{className:"px-3 py-4",children:[a==="overview"&&e.jsx(La,{channel:t}),a==="intelligence"&&e.jsx(Wa,{}),a==="access"&&e.jsx(Fa,{}),a==="knowledge"&&e.jsx(Oa,{}),a==="channels"&&e.jsx(Ua,{channel:t,onChannelChange:n})]})}),e.jsx("div",{className:"px-3 py-2.5 border-t border-border shrink-0",children:e.jsxs(R,{className:"w-full h-8 text-xs rounded-lg gap-1.5",onClick:m,children:[e.jsx(Fe,{className:"w-3.5 h-3.5"}),"Salvar Configurações"]})})]})})},Va=[{id:"preview",label:"Preview",icon:sa},{id:"dashboard",label:"Dashboard",icon:aa},{id:"code",label:"Código",icon:De},{id:"database",label:"Database",icon:Se}],Ga=({initialPrompt:t})=>{const n=js(),{channel:o,setChannel:m,saveApp:a,appName:i,appId:x,files:d,tables:s,isGenerating:C,chatMessages:A,setFiles:N,setTables:q,setAppName:j,setChannel:D,setChatMessages:p,setWizardStep:z,setWizardData:v,setWizardConfig:T,setStructuredConfig:h,setAppState:_}=oe(),{user:y}=vs(),[M,W]=c.useState("preview"),[F,f]=c.useState(null),[g,$]=c.useState(!1),[k,E]=c.useState(!1),[H,Z]=c.useState(!1),[K,B]=c.useState(!1),[ee,ae]=c.useState(""),V=c.useRef(null),Y=c.useRef(!1);c.useEffect(()=>{if(!(!y||C||d.length===0)){if(!Y.current){Y.current=!0;return}return V.current&&clearTimeout(V.current),V.current=setTimeout(async()=>{E(!0);const w=await a(y.id);E(!1),w&&ie.success("Salvo automaticamente",{duration:1500})},3e3),()=>{V.current&&clearTimeout(V.current)}}},[d,s,i,o,A,y,C]);const te=()=>{const w=ee.trim();w&&w!==i&&(j(w),ie.success("Projeto renomeado!")),B(!1)};c.useEffect(()=>{x&&Pe.from("user_apps").select("*").eq("id",x).single().then(({data:w})=>{if(!w)return;j(w.name),D(w.channel),Array.isArray(w.files)&&N(w.files),Array.isArray(w.tables_schema)&&q(w.tables_schema);const P=w.config;P&&typeof P=="object"&&(Array.isArray(P.chatMessages)&&p(P.chatMessages),P.wizardStep&&z(P.wizardStep),P.wizardData&&v(P.wizardData),P.wizardConfig&&T(P.wizardConfig),P.structuredConfig&&h(P.structuredConfig),P.appState&&_(P.appState))})},[x]);const se=async()=>{if(!y){ie.error("Faça login para salvar.");return}E(!0);const w=await a(y.id);E(!1),w?ie.success("App salvo!"):ie.error("Erro ao salvar.")};return e.jsxs("div",{className:"flex h-screen bg-background text-foreground overflow-hidden",children:[!H&&e.jsx(ka,{onBack:()=>n("/apps"),initialPrompt:t}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-background",children:[e.jsxs("div",{className:"h-12 border-b border-border flex items-center justify-between px-3 shrink-0 bg-card/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>Z(!H),title:H?"Abrir chat":"Fechar chat",children:H?e.jsx(ma,{className:"w-3.5 h-3.5"}):e.jsx(ca,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"h-5 w-px bg-border"}),K?e.jsx("form",{onSubmit:w=>{w.preventDefault(),te()},className:"flex items-center gap-1",children:e.jsx(de,{autoFocus:!0,value:ee,onChange:w=>ae(w.target.value),onBlur:te,className:"h-6 w-40 text-xs px-1.5 py-0"})}):e.jsx("button",{className:"text-xs font-semibold text-foreground tracking-tight hover:text-primary transition-colors cursor-text",onClick:()=>{ae(i),B(!0)},title:"Clique para renomear",children:i}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["â ",o==="whatsapp"?"WhatsApp App":"Web App"]}
218)]}),e.jsx("div",{className:"flex items-center gap-0.5 bg-muted/40 rounded-lg p-0.5",children:Va.map(w=>e.jsxs("button",{onClick:()=>W(w.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-all ${M===w.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(w.icon,{className:"w-3.5 h-3.5"}),w.label]},w.id))}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(R,{variant:g?"secondary":"ghost",size:"icon",className:"h-7 w-7",title:"Configurações do App",onClick:()=>$(!g),children:e.jsx(Ne,{className:"w-3.5 h-3.5"})}),e.jsx("div",{className:"h-5 w-px bg-border"}),e.jsxs(R,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1 rounded-full",onClick:se,disabled:k,children:[e.jsx(ea,{className:"w-3 h-3"}),k?"Salvando...":"Salvar"]}),e.jsxs(R,{size:"sm",className:"h-7 text-xs gap-1 rounded-full bg-primary hover:bg-primary/90",children:[e.jsx(He,{className:"w-3 h-3"}),"Publicar"]})]})]}),e.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:e.jsxs("div",{className:"flex-1 flex min-h-0",children:[M==="preview"&&e.jsx(Da,{channel:o}),M==="dashboard"&&e.jsx(Ia,{channel:o}),M==="code"&&e.jsxs(e.Fragment,{children:[e.jsx(Aa,{selectedFile:F,onSelectFile:f,channel:o}),e.jsx(Ta,{fileName:F,channel:o})]}),M==="database"&&e.jsx(Ea,{})]})})]}),e.jsx(Ba,{channel:o,onChannelChange:m,open:g,onClose:()=>$(!1)})]})},tr=()=>{const n=bs().state,o=(n==null?void 0:n.initialPrompt)||"",m=(n==null?void 0:n.channel)||"web",a=(n==null?void 0:n.appId)||null;return e.jsx(Ns,{moduleKey:"aikortex.apps",children:e.jsx(ya,{initialChannel:m,existingAppId:a,children:e.jsx(Ga,{initialPrompt:o})})})};export{tr 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.