nothumanallowed 16.0.51 → 16.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -700,7 +700,7 @@ ${d}
700
700
  ${e.map(e=>`<div class="section"><div class="agent-header"><span class="icon">${e.icon}</span><div class="agent-name">${e.label}</div></div><div class="section-body"><p>${r(e.output)}</p></div></div>`).join(``)}
701
701
  ${f}
702
702
  <div class="footer">NHA Studio · nothumanallowed.com · ${new Date().getFullYear()}</div>
703
- </body></html>`,m=new Blob([p],{type:`text/html`}),h=URL.createObjectURL(m),g=document.createElement(`a`);g.href=h,g.download=`nha-report-${Date.now()}.html`,g.click(),URL.revokeObjectURL(h);let _=window.open(``,`_blank`,`width=1100,height=800`);_&&(_.document.open(),_.document.write(p),_.document.close(),_.onload=()=>setTimeout(()=>{_.focus(),_.print()},600))},N=t=>{let n=`**Studio Workflow Result**\n\nTask: ${t.task}\n\nAgents: ${t.nodes.map(e=>e.label).join(` → `)}\n\n---\n\n${t.result}`;try{sessionStorage.setItem(`nha_studio_import`,n)}catch{}e(`chat`)},Ce=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),de.current=``,w(null),j.current=null,te(!1),b({in:0,out:0}),v(null),D(!1);try{sessionStorage.removeItem(dt)}catch{}}},we=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:P.root,children:[(0,k.jsxs)(`div`,{className:P.header,children:[(0,k.jsxs)(`div`,{className:P.headerLeft,children:[(0,k.jsx)(`div`,{className:P.title,children:`Studio`}),(0,k.jsx)(`div`,{className:P.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:P.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:P.tokenBar,children:[(0,k.jsxs)(`span`,{className:P.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:P.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` out`})]}),(0,k.jsxs)(`div`,{style:{position:`relative`},ref:fe,children:[(0,k.jsxs)(`button`,{className:P.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,k.jsx)(`div`,{className:P.sessionsDrawer,children:f.length===0?(0,k.jsx)(`div`,{className:P.noSessions,children:`No saved sessions yet.`}):(0,k.jsxs)(k.Fragment,{children:[f.map(e=>(0,k.jsxs)(`div`,{className:P.sessionItem,children:[(0,k.jsxs)(`div`,{className:P.sessionInfo,onClick:()=>ve(e),children:[(0,k.jsx)(`div`,{className:P.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:P.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,k.jsxs)(`div`,{className:P.sessionBtns,children:[(0,k.jsx)(`button`,{className:P.importBtn,onClick:()=>N(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:P.delSessionBtn,onClick:()=>ye(e.id),children:`✕`})]})]},e.id)),(0,k.jsx)(`div`,{className:P.sessionsFooter,children:(0,k.jsx)(`button`,{className:P.clearAllSessionsBtn,onClick:be,children:`Clear All`})})]})})]}),x&&(0,k.jsx)(`button`,{className:P.canvasToggleBtn,onClick:()=>{D(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:P.pdfBtn,onClick:xe,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:P.clearBtn,onClick:Ce,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,k.jsxs)(`div`,{className:P.inputArea,children:[(0,k.jsxs)(`div`,{className:P.inputRow,children:[(0,k.jsx)(`textarea`,{className:P.taskInput,value:n,onChange:e=>r(e.target.value),placeholder:`Describe your task… e.g. Analyze my emails and create a priority action plan`,rows:4,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),he())}}),(0,k.jsxs)(`div`,{className:P.inputControls,children:[u?(0,k.jsx)(`button`,{className:P.stopBtn,onClick:ge,children:`■ Stop`}):(0,k.jsx)(`button`,{className:P.runBtn,onClick:he,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:P.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>me(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:P.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:P.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.examples,children:ke.map((e,t)=>(0,k.jsx)(`button`,{className:P.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:P.financeSection,children:[(0,k.jsx)(`div`,{className:P.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:P.financePresets,children:De.map((e,t)=>(0,k.jsx)(`button`,{className:P.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.officeSceneWrap,style:{overflow:`hidden`,position:`relative`,height:`180px`},children:(0,k.jsxs)(`div`,{style:{display:`flex`,width:`200%`,height:`100%`,transition:`transform 700ms cubic-bezier(0.22, 1, 0.36, 1)`,transform:C&&C.phase!==`idle`&&C.phase!==`skipped`?`translateX(-50%)`:`translateX(0)`},children:[(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(Qe,{nodes:i,running:u})}),(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(rt,{agents:re.length>0?re:i,council:C})})]})}),(0,k.jsxs)(`div`,{className:`${P.pipelineWrap} ${u?P.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:P.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:P.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:P.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:P.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${P.agentChip} ${P[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:P.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:P.chipDots,children:[(0,k.jsx)(`span`,{className:P.dot1,children:`.`}),(0,k.jsx)(`span`,{className:P.dot2,children:`.`}),(0,k.jsx)(`span`,{className:P.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:P.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:P.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${P.arrow} ${u?P.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:P.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:P.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:P.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:P.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,k.jsxs)(`div`,{className:P.body,ref:ue,children:[(o.length>0||we)&&(0,k.jsxs)(`div`,{className:P.twoCol,children:[(0,k.jsxs)(`div`,{className:P.logPanel,children:[(0,k.jsx)(`div`,{className:P.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:P.logBody,ref:le,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.logEntry} ${P[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:P.logTime,children:e.time}),(0,k.jsx)(`span`,{className:P.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:P.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:P.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.liveBlock} ${e.status===`running`?P.liveBlockActive:``} ${e.status===`done`&&e.output?P.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?se(e):void 0,children:[(0,k.jsxs)(`div`,{className:P.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:P.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${P.outputStatus} ${P[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:P.expandHint,children:`↗ espandi`})]}),e.status===`running`&&(0,k.jsxs)(`div`,{className:P.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingLabel,children:e.statusLine??`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${e.status===`done`&&e.output?P.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:Se(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:P.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptDesc,children:[re.length,` agenti (`,re.map(e=>e.label).join(`, `),`) hanno prodotto output. Il Geth Consensus eseguirà cross-reading, refinement e mediazione HERALD per raggiungere un consenso collettivo.`]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptMeta,children:[`Complessità: `,re.length<=3?`⚡ Rapido (~30s)`:re.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:P.parliamentActivateBtn,onClick:_e,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:P.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:P.councilWrapper,children:(0,k.jsx)(vt,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:P.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:P.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:P.resultAccordionBody,dangerouslySetInnerHTML:{__html:Se(c)}})]})]}),E&&(0,k.jsxs)(`div`,{className:P.canvasPanel,children:[(0,k.jsxs)(`div`,{className:P.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:P.panelTabs,children:[(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`canvas`?P.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`browser`?P.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:P.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:P.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:P.canvasPanelClose,onClick:()=>D(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:P.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:P.browserPanel,children:[(0,k.jsxs)(`div`,{className:P.browserBar,children:[(0,k.jsx)(`input`,{className:P.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:P.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:P.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`Enter a URL above to browse`})]})]}),oe&&(0,k.jsx)(`div`,{className:P.blockModalOverlay,onClick:()=>se(null),children:(0,k.jsxs)(`div`,{className:P.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:P.blockModalHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:oe.icon}),(0,k.jsx)(`span`,{className:P.blockModalTitle,children:oe.label}),(0,k.jsx)(`button`,{className:P.blockModalClose,onClick:()=>se(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${P.blockModalBody}`,dangerouslySetInnerHTML:{__html:Se(oe.output)}})]})})]})}var R={root:`_root_13wnr_2`,hero:`_hero_13wnr_12`,heroLeft:`_heroLeft_13wnr_21`,heroDate:`_heroDate_13wnr_22`,heroTitle:`_heroTitle_13wnr_23`,heroVer:`_heroVer_13wnr_24`,heroUptime:`_heroUptime_13wnr_25`,heroWeather:`_heroWeather_13wnr_27`,wIcon:`_wIcon_13wnr_35`,wInfo:`_wInfo_13wnr_36`,wTemp:`_wTemp_13wnr_37`,wCity:`_wCity_13wnr_38`,wDesc:`_wDesc_13wnr_39`,wEmpty:`_wEmpty_13wnr_40`,kpiRow:`_kpiRow_13wnr_43`,kpi:`_kpi_13wnr_43`,kpiNum:`_kpiNum_13wnr_55`,kpiLbl:`_kpiLbl_13wnr_56`,kpiBar:`_kpiBar_13wnr_57`,kpiFill:`_kpiFill_13wnr_58`,liveGrid:`_liveGrid_13wnr_61`,liveCard:`_liveCard_13wnr_67`,liveHdr:`_liveHdr_13wnr_71`,liveMore:`_liveMore_13wnr_79`,liveRow:`_liveRow_13wnr_81`,liveUnread:`_liveUnread_13wnr_89`,liveTitle:`_liveTitle_13wnr_89`,liveTime:`_liveTime_13wnr_91`,liveBody:`_liveBody_13wnr_95`,liveSub:`_liveSub_13wnr_97`,prio:`_prio_13wnr_99`,prio_high:`_prio_high_13wnr_103`,prio_medium:`_prio_medium_13wnr_104`,prio_low:`_prio_low_13wnr_105`,launcher:`_launcher_13wnr_108`,launchGroup:`_launchGroup_13wnr_115`,launchGroupLabel:`_launchGroupLabel_13wnr_117`,launchTiles:`_launchTiles_13wnr_123`,tile:`_tile_13wnr_129`,tileIcon:`_tileIcon_13wnr_143`,tileLabel:`_tileLabel_13wnr_144`},bt=[{view:`chat`,icon:`💬`,label:`Chat`,color:`#38bdf8`,group:`Panoramica`},{view:`plan`,icon:`🗓️`,label:`Daily Plan`,color:`#818cf8`,group:`Panoramica`},{view:`tasks`,icon:`✅`,label:`Tasks`,color:`#4ade80`,group:`Panoramica`},{view:`email`,icon:`📧`,label:`Email`,color:`#f87171`,group:`Google`},{view:`calendar`,icon:`📅`,label:`Calendar`,color:`#fb923c`,group:`Google`},{view:`drive`,icon:`💾`,label:`Drive`,color:`#facc15`,group:`Google`},{view:`contacts`,icon:`👤`,label:`Contacts`,color:`#34d399`,group:`Google`},{view:`notes`,icon:`📝`,label:`Notes`,color:`#a78bfa`,group:`Google`},{view:`onedrive`,icon:`☁️`,label:`OneDrive`,color:`#60a5fa`,group:`Microsoft`},{view:`mstodo`,icon:`📋`,label:`MS Todo`,color:`#38bdf8`,group:`Microsoft`},{view:`github`,icon:`🐙`,label:`GitHub`,color:`#e2e8f0`,group:`Tools`},{view:`notion`,icon:`📓`,label:`Notion`,color:`#94a3b8`,group:`Tools`},{view:`slack`,icon:`💼`,label:`Slack`,color:`#e879f9`,group:`Tools`},{view:`maps`,icon:`🗺️`,label:`Maps`,color:`#2dd4bf`,group:`Tools`},{view:`reminders`,icon:`🔔`,label:`Reminders`,color:`#fbbf24`,group:`Tools`},{view:`birthdays`,icon:`🎂`,label:`Birthdays`,color:`#f472b6`,group:`Tools`},{view:`cron`,icon:`⏰`,label:`Cron`,color:`#fb923c`,group:`Tools`},{view:`screen`,icon:`🖥️`,label:`Screen`,color:`#64748b`,group:`Tools`},{view:`agents`,icon:`🤖`,label:`Agents`,color:`#4ade80`,group:`AI`},{view:`studio`,icon:`🎭`,label:`Studio`,color:`#a78bfa`,group:`AI`},{view:`webcraft`,icon:`🔨`,label:`WebCraft`,color:`#f59e0b`,group:`AI`},{view:`collab`,icon:`🏛️`,label:`Alexandria`,color:`#38bdf8`,group:`AI`},{view:`connectors`,icon:`🔗`,label:`AWF - AutoWorkFlow`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],xt={Sunny:`☀️`,Clear:`☀️`,"Partly Cloudy":`⛅`,"Partly cloudy":`⛅`,Cloudy:`☁️`,Overcast:`☁️`,"Light rain":`🌧️`,Rain:`🌧️`,Drizzle:`🌧️`,"Moderate rain":`🌧️`,"Heavy rain":`🌧️`,Snow:`❄️`,"Light snow":`❄️`,Fog:`🌫️`,Mist:`🌫️`,Thunder:`⚡`,"Thundery outbreaks":`⚡`};function St(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function Ct(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function wt(){let e=ne(e=>e.setView),t=j(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(new Date);(0,_.useEffect)(()=>{let e=setInterval(()=>p(new Date),6e4);return()=>clearInterval(e)},[]),(0,_.useEffect)(()=>{let e=!0,t=t=>n=>{e&&n!=null&&t(n)};T(`/api/tasks`).then(e=>t(r)(e?.tasks??[])),T(`/api/emails?page=0&pageSize=8`).then(e=>t(a)(e?.emails??[])),T(`/api/calendar`).then(e=>t(s)(e?.events??[])),T(`/api/status`).then(t(l));let n=localStorage.getItem(`nha_weather_location`),i=t=>T(`/api/weather?location=${encodeURIComponent(t)}`).then(t=>{e&&t&&t.city&&d(t)});return n?i(n):navigator.geolocation?.getCurrentPosition(e=>i(`${e.coords.latitude.toFixed(4)},${e.coords.longitude.toFixed(4)}`),()=>{},{timeout:6e3}),()=>{e=!1}},[]);let m=n.filter(e=>e.status!==`done`),h=n.filter(e=>e.status===`done`),g=n.length>0?Math.round(h.length/n.length*100):0,v=i.filter(e=>e.isUnread).length,y=f.toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`}),b=[...new Set(bt.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:R.root,children:[(0,k.jsxs)(`div`,{className:R.hero,children:[(0,k.jsxs)(`div`,{className:R.heroLeft,children:[(0,k.jsx)(`div`,{className:R.heroDate,children:y}),(0,k.jsx)(`div`,{className:R.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:R.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:R.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:R.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),d(null),T(`/api/weather?location=${encodeURIComponent(e)}`).then(e=>{e&&e.city&&d(e)}))},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:R.wIcon,children:xt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:R.wInfo,children:[(0,k.jsxs)(`span`,{className:R.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:R.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:R.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:R.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:R.kpiRow,children:[(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:R.kpiBar,children:(0,k.jsx)(`div`,{className:R.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:R.kpi,children:[(0,k.jsxs)(`span`,{className:R.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:R.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:t.isAllDay?`All day`:St(t.start)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:R.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${R.liveRow} ${t.isUnread?R.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:Ct(t.date)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:R.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${R.prio} ${R[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:R.liveBody,children:(0,k.jsx)(`span`,{className:R.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:R.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:R.launchGroup,children:[(0,k.jsx)(`div`,{className:R.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:R.launchTiles,children:bt.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:R.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:R.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:R.tileLabel,children:t.label})]},t.view))})]},t))})]})}var Tt={root:`_root_1pldx_1`,loading:`_loading_1pldx_2`,bar:`_bar_1pldx_4`,input:`_input_1pldx_5`,select:`_select_1pldx_6`,addBtn:`_addBtn_1pldx_7`,actions:`_actions_1pldx_10`,clearDone:`_clearDone_1pldx_11`,clearAll:`_clearAll_1pldx_12`,stats:`_stats_1pldx_14`,progress:`_progress_1pldx_15`,progressBar:`_progressBar_1pldx_16`,empty:`_empty_1pldx_18`,task:`_task_1pldx_20`,taskDone:`_taskDone_1pldx_22`,check:`_check_1pldx_23`,checkDone:`_checkDone_1pldx_25`,desc:`_desc_1pldx_26`,del:`_del_1pldx_27`,badge:`_badge_1pldx_30`,badge_high:`_badge_high_1pldx_31`,badge_medium:`_badge_medium_1pldx_32`,badge_low:`_badge_low_1pldx_33`,doneLabel:`_doneLabel_1pldx_35`};function Et(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`medium`),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=()=>T(`/api/tasks`).then(e=>{n(e?.tasks??[]),i(!1)});(0,_.useEffect)(()=>{f()},[]);let p=async()=>{a.trim()&&(u(!0),await E(`/api/tasks`,{description:a.trim(),priority:s}),o(``),u(!1),f(),d.current?.focus())},m=e=>E(`/api/tasks/${e}/done`,{},`PATCH`).then(f),h=e=>E(`/api/tasks/${e}/delete`,{}).then(f),g=()=>E(`/api/tasks/clear`,{filter:`done`}).then(f),v=()=>{confirm(e(`tasks.deleteTask`))&&E(`/api/tasks/clear`,{filter:`all`}).then(f)},y=t.filter(e=>e.status!==`done`),b=t.filter(e=>e.status===`done`);return r?(0,k.jsxs)(`div`,{className:Tt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Tt.root,children:[(0,k.jsxs)(`div`,{className:Tt.bar,children:[(0,k.jsx)(`input`,{ref:d,className:Tt.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:Tt.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:Tt.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.actions,children:[(0,k.jsx)(`button`,{className:Tt.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:Tt.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:Tt.progress,children:(0,k.jsx)(`span`,{className:Tt.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:Tt.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:Tt.task,children:[(0,k.jsx)(`span`,{className:Tt.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Tt.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${Tt.task} ${Tt.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${Tt.check} ${Tt.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var z={root:`_root_k5v14_1`,loading:`_loading_k5v14_2`,card:`_card_k5v14_4`,cardTitle:`_cardTitle_k5v14_5`,cardTitleRow:`_cardTitleRow_k5v14_6`,cardSub:`_cardSub_k5v14_7`,connected:`_connected_k5v14_8`,statusMsg:`_statusMsg_k5v14_9`,fields:`_fields_k5v14_11`,field:`_field_k5v14_11`,fieldLabel:`_fieldLabel_k5v14_13`,fieldInput:`_fieldInput_k5v14_14`,saveBtn:`_saveBtn_k5v14_17`,dangerBtn:`_dangerBtn_k5v14_18`,cancelBtn:`_cancelBtn_k5v14_19`,btnRow:`_btnRow_k5v14_20`,keySet:`_keySet_k5v14_22`,keySummary:`_keySummary_k5v14_23`,keySummaryIcon:`_keySummaryIcon_k5v14_24`,nhaFree:`_nhaFree_k5v14_26`,nhaFreeTitle:`_nhaFreeTitle_k5v14_27`,nhaFreeSub:`_nhaFreeSub_k5v14_28`,nhaFreeBtn:`_nhaFreeBtn_k5v14_29`,imapRow:`_imapRow_k5v14_31`,imapName:`_imapName_k5v14_32`,imapMeta:`_imapMeta_k5v14_33`,imapStatus:`_imapStatus_k5v14_34`,imapBtns:`_imapBtns_k5v14_38`,imapSyncBtn:`_imapSyncBtn_k5v14_39`,imapEditBtn:`_imapEditBtn_k5v14_40`,imapDelBtn:`_imapDelBtn_k5v14_41`,emptyImap:`_emptyImap_k5v14_42`,imapForm:`_imapForm_k5v14_44`,imapFormTitle:`_imapFormTitle_k5v14_45`,pwdNote:`_pwdNote_k5v14_46`,pwdRow:`_pwdRow_k5v14_47`,togglePwd:`_togglePwd_k5v14_48`},Dt={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function Ot({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:z.fieldInput})]})}function kt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),f=()=>{T(`/api/credentials`).then(e=>t(e?.credentials??[])).catch(()=>t([]))};(0,_.useEffect)(()=>{f()},[]);let p=async()=>{if(!/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(n)){d(`Name: lettere, cifre, _ — primo carattere non numerico`);return}if(!i.trim()){d(`Value required`);return}l(!0),d(``);try{let e=await E(`/api/credentials`,{name:n,value:i,description:o});e&&!e.ok&&e.error?d(e.error):(r(``),a(``),s(``),f())}finally{l(!1)}},m=async e=>{confirm(`Delete credential "${e}"?`)&&(await fetch(`/api/credentials/${encodeURIComponent(e)}`,{method:`DELETE`}),f())};return(0,k.jsxs)(`div`,{style:{marginTop:16,padding:16,background:`var(--bg2, rgba(15,23,42,0.4))`,border:`1px solid var(--border, rgba(148,163,184,0.18))`,borderRadius:10},children:[(0,k.jsx)(`div`,{style:{fontSize:14,fontWeight:800,marginBottom:4},children:`Credentials Vault 🔐`}),(0,k.jsxs)(`div`,{style:{fontSize:11,opacity:.7,marginBottom:10},children:[`Encrypted secrets (AES-256-GCM, machine-bound key). Reference them in workflow nodes with `,(0,k.jsx)(`code`,{children:"${cred.NAME}"}),`. The raw value never leaves your computer.`]}),e.length>0&&(0,k.jsx)(`div`,{style:{marginBottom:12,border:`1px solid rgba(148,163,184,0.15)`,borderRadius:6},children:e.map(e=>(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 10px`,borderBottom:`1px solid rgba(148,163,184,0.1)`,fontSize:12},children:[(0,k.jsx)(`code`,{style:{background:`rgba(99,102,241,0.12)`,padding:`2px 6px`,borderRadius:4,color:`#a5b4fc`,fontWeight:700},children:e.name}),(0,k.jsx)(`span`,{style:{flex:1,opacity:.7},children:e.description||(0,k.jsx)(`em`,{children:`no description`})}),(0,k.jsx)(`span`,{style:{fontSize:10,opacity:.5},children:new Date(e.updatedAt).toLocaleString()}),e.hasError&&(0,k.jsx)(`span`,{style:{color:`#ef4444`,fontSize:10},children:`⚠ decrypt error`}),(0,k.jsx)(`button`,{onClick:()=>m(e.name),style:{background:`transparent`,border:`none`,cursor:`pointer`,color:`#ef4444`,fontSize:14},children:`✕`})]},e.name))}),(0,k.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:8},children:[(0,k.jsx)(`input`,{placeholder:`NAME (e.g. STRIPE_KEY)`,value:n,onChange:e=>r(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontFamily:`SF Mono, monospace`}}),(0,k.jsx)(`input`,{placeholder:`Description (optional)`,value:o,onChange:e=>s(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}})]}),(0,k.jsx)(`input`,{type:`password`,placeholder:`Value (encrypted at rest)`,value:i,onChange:e=>a(e.target.value),style:{width:`100%`,marginTop:6,padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}}),u&&(0,k.jsx)(`div`,{style:{color:`#ef4444`,fontSize:11,marginTop:4},children:u}),(0,k.jsx)(`button`,{onClick:p,disabled:c,style:{marginTop:8,padding:`6px 14px`,borderRadius:4,border:`none`,background:`#6366f1`,color:`white`,fontWeight:700,cursor:`pointer`,opacity:c?.5:1},children:c?`Saving…`:`+ Add credential`})]})}function At(){let{setConfig:e}=ne(),t=j(),[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)({name:``,email:``,phone:``,homeAddress:``,workAddress:``,city:``,country:``,company:``,role:``,notes:``}),[C,w]=(0,_.useState)(`nha`),[ee,te]=(0,_.useState)(``),[re,D]=(0,_.useState)(``),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[oe,se]=(0,_.useState)(``),[ce,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[M,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(`en`),[ye,be]=(0,_.useState)(`07:00`),[xe,Se]=(0,_.useState)(`18:00`),[N,Ce]=(0,_.useState)(`30`),[we,Te]=(0,_.useState)(`off`),[Ee,P]=(0,_.useState)(``),[De,Oe]=(0,_.useState)(``),[ke,F]=(0,_.useState)(``),[I,Ae]=(0,_.useState)(`agent`),[je,Me]=(0,_.useState)(``),[Ne,Pe]=(0,_.useState)(!0),[Fe,Ie]=(0,_.useState)(!0),[Le,Re]=(0,_.useState)(`3`),[ze,L]=(0,_.useState)(`0.30`),[Be,Ve]=(0,_.useState)(!0),[He,Ue]=(0,_.useState)(!1),[We,Ge]=(0,_.useState)(!1),[Ke,qe]=(0,_.useState)(!1),[Je,Ye]=(0,_.useState)(!1),[Xe,Ze]=(0,_.useState)(!1),[Qe,$e]=(0,_.useState)(!1),[et,tt]=(0,_.useState)(!0),[nt,rt]=(0,_.useState)(``),[it,at]=(0,_.useState)(!1),[ot,st]=(0,_.useState)(!1),[ct,lt]=(0,_.useState)(!0),[ut,dt]=(0,_.useState)(``),[ft,pt]=(0,_.useState)(``),[mt,ht]=(0,_.useState)(``),[gt,_t]=(0,_.useState)(``),[vt,yt]=(0,_.useState)(`common`),[R,bt]=(0,_.useState)(!1),[xt,St]=(0,_.useState)(``);(0,_.useEffect)(()=>{T(`/api/config`).then(t=>{r(t??{});let n=t?.profile??{};S({name:n.name??``,email:n.email??``,phone:n.phone??``,homeAddress:n.homeAddress??``,workAddress:n.workAddress??``,city:n.city??``,country:n.country??``,company:n.company??``,role:n.role??``,notes:n.notes??``}),w(t?.provider??`nha`),ge(t?.model??``),ve(t?.lang??`en`),be(t?.planTime??`07:00`),Se(t?.summaryTime??`18:00`),Ce(String(t?.meetingAlert??`30`)),Te(t?.thinking??`off`),te(``);let i=t?.responder,o=i?.telegram;F(String(o?.botName??``));let s=String(o?.personaMode??`agent`);Ae(s===`persona`||s===`persona-only`||s===`persona+role`?s:`agent`),Me(Array.isArray(o?.allowedChatIds)?o.allowedChatIds.join(`, `):``),Pe(i?.autoRoute!==!1);let c=t?.deliberation;Ie(c?.enabled!==!1),Re(String(c?.rounds??`3`)),L(String(c?.convergence??`0.30`)),Ve(c?.tribunalEnabled!==!1);let l=t?.ops?.proactive;Ue(!!l?.enabled),Ge(!!l?.emailFollowUp),qe(!!l?.meetingPrep),Ye(!!l?.patterns),Ze(!!l?.deadlines);let u=t?.voice;$e(!!u?.preferWhisper),tt(u?.speechSynthesis!==!1),rt(String(u?.language??``));let d=t?.features;at(!!d?.verbose),st(!!d?.immersive),lt(d?.knowledgeEnabled!==!1),dt(``),pt(String(t?.github?.defaultRepo??``)),ht(``),_t(``);let f=t?.microsoft;yt(String(f?.tenantId??`common`));let p=t?.plugins;bt(!!p?.autoRun),St(String(p?.directory??``)),a(!1),t&&e(t)}),Ct()},[]);let Ct=()=>T(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),wt=async(e,t)=>{s(e),await E(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},Tt=()=>wt(`profile`,x),Et=()=>{wt(`provider`,C),wt(`model`,he),wt(`thinking`,we),ee&&wt(`key`,ee),re&&wt(`groq-key`,re),ie&&wt(`openai-key`,ie),ae&&wt(`gemini-key`,ae),oe&&wt(`deepseek-key`,oe),ce&&wt(`grok-key`,ce),ue&&wt(`mistral-key`,ue),M&&wt(`cohere-key`,M)},At=()=>{wt(`planTime`,ye),wt(`summaryTime`,xe),wt(`meetingAlert`,Number(N))},jt=()=>{v(t(`settings.googleOpening`)),E(`/api/google/auth`,{}).then(e=>{e?.url?(window.open(e.url,`_blank`),v(t(`settings.googleOpened`))):e?.error&&v(t(`common.error`)+`: `+e.error)}).catch(e=>v(t(`common.error`)+`: `+e.message))},Mt=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&E(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},B=()=>{if(!f)return;let e=!!f.id,t={display_name:f.display_name,email_address:f.email_address,from_name:f.from_name,imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username};f.password&&(t.password=f.password),e&&(t.id=f.id),h(`Saving…`),E(e?`/api/imap/accounts/update`:`/api/imap/accounts`,t).then(e=>{e?.ok||e?.id?(h(`Saved!`),p(null),Ct()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},Nt=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&E(`/api/imap/accounts/delete`,{id:e}).then(()=>Ct())},Pt=e=>{E(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(Ct,3e3))},Ft=async()=>{if(f){if(!f.imap_host||!f.imap_port){h(`⚠ Inserisci prima host e porta IMAP.`);return}h(`Diagnostica porta IMAP in corso…`);try{let e=await E(`/api/imap/probe`,{imap_host:f.imap_host,imap_port:Number(f.imap_port)});e?.ok?h(`✓ ${f.imap_host}:${f.imap_port} risponde\n${e.message}${e.banner?`\n\nBanner: ${e.banner}`:``}`):h(`✗ ${f.imap_host}:${f.imap_port} non risponde\n${e?.message??e?.error??`errore sconosciuto`}`)}catch(e){h(`✗ Diagnostica fallita: ${e.message}`)}}},It=async e=>{if(!f)return;if(!f.password&&!f.id){h(`⚠ Inserisci la password prima di testare.`);return}h(e?`Invio email di prova…`:`Test connessione in corso…`);let t={imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username,password:f.password,email_address:f.email_address,from_name:f.from_name,sendTest:e};try{let e=await E(`/api/imap/test`,t),n=e?.imap,r=e?.smtp,i=[];n?.ok?i.push(`✓ IMAP OK (TLS=${n.secure?`implicit`:`STARTTLS`}, ${n.folderCount??`?`} cartelle)`):i.push(`✗ IMAP errore: ${n?.error??`sconosciuto`}`),r?.ok?r.sent?i.push(`✓ SMTP OK — email di prova inviata a ${f.email_address} (id ${(r.messageId||``).slice(0,24)}…)`):i.push(`✓ SMTP OK (TLS=${r.secure?`implicit`:`STARTTLS`}, auth valida)`):i.push(`✗ SMTP errore: ${r?.error??`sconosciuto`}`),h(i.join(` · `))}catch(e){h(`✗ Test fallito: ${e.message}`)}};if(i)return(0,k.jsxs)(`div`,{className:z.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let Lt=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:z.root,children:[(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:z.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:Tt,children:[Lt(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:z.nhaFree,children:[(0,k.jsx)(`div`,{className:z.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:z.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:z.nhaFreeBtn,onClick:()=>{E(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),ge(``),te(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.llmProviderSub`)}),(()=>{let e=[];return n.hasApiKey&&e.push(`Anthropic`),n.hasOpenaiKey&&e.push(`OpenAI`),n.hasGeminiKey&&e.push(`Gemini`),n.hasDeepseekKey&&e.push(`DeepSeek`),n.hasGrokKey&&e.push(`Grok`),n.hasMistralKey&&e.push(`Mistral`),n.hasCohereKey&&e.push(`Cohere`),e.length===0?null:(0,k.jsxs)(`div`,{className:z.keySummary,children:[(0,k.jsx)(`span`,{className:z.keySummaryIcon,children:`🔑`}),(0,k.jsxs)(`span`,{children:[`Chiavi configurate: `,(0,k.jsx)(`strong`,{children:e.join(`, `)})]})]})})(),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:z.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(Ot,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(Ot,{id:`groqKey`,label:`Groq Key (voice / Whisper)`,placeholder:n.hasGroqKey?`✓ configured — leave empty to keep`:`gsk_... (free at console.groq.com/keys) — enables Telegram voice transcription`,type:`password`,value:re,onChange:D}),(0,k.jsx)(`div`,{style:{marginTop:8,marginBottom:4},children:(0,k.jsxs)(`button`,{type:`button`,onClick:()=>me(!pe),style:{background:`transparent`,border:`none`,color:`var(--accent, #6366f1)`,cursor:`pointer`,fontSize:12,padding:0,fontWeight:600},children:[pe?`▾`:`▸`,` Optional provider keys (OpenAI, Gemini, DeepSeek, Grok, Mistral, Cohere)`]})}),pe&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Ot,{id:`openaiKey`,label:`OpenAI Key`,placeholder:n.hasOpenaiKey?`✓ configured — leave empty to keep`:`sk-... (platform.openai.com)`,type:`password`,value:ie,onChange:O}),(0,k.jsx)(Ot,{id:`geminiKey`,label:`Gemini Key (Google)`,placeholder:n.hasGeminiKey?`✓ configured — leave empty to keep`:`AIza... (aistudio.google.com)`,type:`password`,value:ae,onChange:A}),(0,k.jsx)(Ot,{id:`deepseekKey`,label:`DeepSeek Key`,placeholder:n.hasDeepseekKey?`✓ configured — leave empty to keep`:`sk-... (platform.deepseek.com)`,type:`password`,value:oe,onChange:se}),(0,k.jsx)(Ot,{id:`grokKey`,label:`Grok Key (X.AI)`,placeholder:n.hasGrokKey?`✓ configured — leave empty to keep`:`xai-... (console.x.ai)`,type:`password`,value:ce,onChange:le}),(0,k.jsx)(Ot,{id:`mistralKey`,label:`Mistral Key`,placeholder:n.hasMistralKey?`✓ configured — leave empty to keep`:`... (console.mistral.ai)`,type:`password`,value:ue,onChange:de}),(0,k.jsx)(Ot,{id:`cohereKey`,label:`Cohere Key`,placeholder:n.hasCohereKey?`✓ configured — leave empty to keep`:`... (dashboard.cohere.com)`,type:`password`,value:M,onChange:fe})]}),(0,k.jsx)(Ot,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:he,onChange:ge}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:we,onChange:e=>Te(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:Et,children:[Lt(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:_e,onChange:t=>{let r=t.target.value;ve(r),wt(`lang`,r),e({...n,lang:r})},className:z.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(Ot,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:Ee,onChange:P}),(0,k.jsx)(Ot,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:De,onChange:Oe}),(0,k.jsx)(Ot,{id:`botName`,label:`Bot Persona Name`,placeholder:`e.g. Agata — what name the bot uses when replying. Empty = show internal agent name (HERALD/ATHENA/...)`,value:ke,onChange:F}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:`Persona display mode`}),(0,k.jsxs)(`select`,{value:I,onChange:e=>Ae(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`agent`,children:`agent — show internal name [HERALD] (legacy/debug)`}),(0,k.jsx)(`option`,{value:`persona`,children:`persona — show [BotName] only (recommended)`}),(0,k.jsx)(`option`,{value:`persona-only`,children:`persona-only — no prefix at all (most natural)`}),(0,k.jsx)(`option`,{value:`persona+role`,children:`persona+role — [BotName · agent] (power users)`})]})]}),(0,k.jsx)(Ot,{id:`allowedChatIds`,label:`Allowed Chat IDs (Telegram)`,placeholder:`comma-separated numeric chat IDs (empty = anyone can chat with the bot)`,value:je,onChange:Me}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Ne,onChange:e=>Pe(e.target.checked)}),` `,`Auto-route messages to specialist agents (recommended)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Ee&&wt(`telegram-bot-token`,Ee),De&&wt(`discord-bot-token`,De),wt(`bot-name`,ke),wt(`persona-mode`,I),wt(`responder.telegram.allowedChatIds`,je.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>Number(e)||e)),wt(`responder-auto-route`,Ne)},children:[Lt(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(Ot,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ye,onChange:be}),(0,k.jsx)(Ot,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:xe,onChange:Se}),(0,k.jsx)(Ot,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:N,onChange:Ce}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:At,children:[Lt(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Deliberation (Geth Consensus)`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Multi-round inter-agent reasoning for higher-quality answers`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Fe,onChange:e=>Ie(e.target.checked)}),` `,`Enable deliberation`]})}),(0,k.jsx)(Ot,{id:`delibRounds`,label:`Rounds (1–5)`,placeholder:`3`,value:Le,onChange:Re}),(0,k.jsx)(Ot,{id:`delibConvergence`,label:`Convergence threshold (0–1, lower = stricter)`,placeholder:`0.30`,value:ze,onChange:L}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Be,onChange:e=>Ve(e.target.checked)}),` `,`Tribunal (final HERALD mediation)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`deliberation`,Fe),wt(`rounds`,Number(Le)),wt(`convergence`,Number(ze)),wt(`tribunal`,Be)},children:[Lt(`deliberation`),` Save deliberation`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Proactive Intelligence`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`The bot acts on its own initiative (follow-ups, meeting prep, pattern detection)`}),[[`proactive`,`Master switch — enable proactive`,He,Ue],[`proactive-email`,`Email follow-up reminders`,We,Ge],[`proactive-meeting`,`Meeting preparation digests`,Ke,qe],[`proactive-patterns`,`Behavioural pattern detection`,Je,Ye],[`proactive-deadlines`,`Deadline tracking`,Xe,Ze]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`proactive`,He),wt(`proactive-email`,We),wt(`proactive-meeting`,Ke),wt(`proactive-patterns`,Je),wt(`proactive-deadlines`,Xe)},children:[Lt(`proactive`),` Save proactive`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Voice`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Transcription (Whisper via Groq) and text-to-speech`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Qe,onChange:e=>$e(e.target.checked)}),` `,`Prefer Whisper (Groq) over local STT`]})}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:et,onChange:e=>tt(e.target.checked)}),` `,`Speech synthesis (read replies aloud)`]})}),(0,k.jsx)(Ot,{id:`voiceLanguage`,label:`Voice language (BCP 47, e.g. it-IT, en-US)`,placeholder:`empty = use UI language`,value:nt,onChange:rt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`voice-whisper`,Qe),wt(`voice-speech`,et),nt&&wt(`voice-language`,nt)},children:[Lt(`voice-whisper`),` Save voice`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Features`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Core behaviour toggles`}),[[`verbose`,`Verbose logging (more diagnostics, more tokens)`,it,at],[`immersive`,`Immersive office scene animation in Studio`,ot,st],[`knowledge`,`Knowledge base (memories + skills retrieval)`,ct,lt]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`verbose`,it),wt(`immersive`,ot),wt(`knowledge`,ct)},children:[Lt(`verbose`),` Save features`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Integration tokens`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`GitHub, Notion, Slack — used by the corresponding tools`}),(0,k.jsx)(Ot,{id:`githubToken`,label:`GitHub Token (PAT)`,placeholder:n.hasGithubToken?`✓ configured — leave empty to keep`:`ghp_... — needs repo + read:org scopes`,type:`password`,value:ut,onChange:dt}),(0,k.jsx)(Ot,{id:`githubRepo`,label:`Default GitHub repo (owner/name)`,placeholder:`acme/website`,value:ft,onChange:pt}),(0,k.jsx)(Ot,{id:`notionToken`,label:`Notion Token (Internal Integration)`,placeholder:n.hasNotionToken?`✓ configured — leave empty to keep`:`secret_...`,type:`password`,value:mt,onChange:ht}),(0,k.jsx)(Ot,{id:`slackToken`,label:`Slack Bot Token (xoxb-)`,placeholder:n.hasSlackToken?`✓ configured — leave empty to keep`:`xoxb-...`,type:`password`,value:gt,onChange:_t}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{ut&&wt(`github-token`,ut),ft&&wt(`github-repo`,ft),mt&&wt(`notion-token`,mt),gt&&wt(`slack-token`,gt)},children:[Lt(`github-token`),` Save tokens`]})]}),(0,k.jsx)(kt,{}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Advanced`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Plugins, Microsoft tenant ID, runtime extras`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:R,onChange:e=>bt(e.target.checked)}),` `,`Auto-run plugins at startup`]})}),(0,k.jsx)(Ot,{id:`pluginDir`,label:`Plugin directory (absolute path)`,placeholder:`empty = ~/.nha/plugins`,value:xt,onChange:St}),(0,k.jsx)(Ot,{id:`microsoftTenant`,label:`Microsoft Tenant ID`,placeholder:`common (default) | organizations | consumers | <GUID>`,value:vt,onChange:yt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`plugin-autorun`,R),xt&&wt(`plugin-dir`,xt),wt(`microsoft-tenant`,vt)},children:[Lt(`plugin-autorun`),` Save advanced`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:z.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:jt,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:z.dangerBtn,onClick:Mt,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:z.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsxs)(`div`,{className:z.cardTitleRow,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:z.saveBtn,onClick:()=>{p({...Dt}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:z.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:z.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:z.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:z.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:z.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:z.imapBtns,children:[(0,k.jsx)(`button`,{className:z.imapSyncBtn,onClick:()=>Pt(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:z.imapEditBtn,onClick:()=>{p({...Dt,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:z.imapDelBtn,onClick:()=>Nt(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:z.imapForm,children:[(0,k.jsx)(`div`,{className:z.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:z.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:z.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:z.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:z.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:B,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>It(!1),title:`Verifica IMAP+SMTP senza inviare nulla`,children:`Test connessione`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>It(!0),title:`Invia un'email di prova alla tua casella per verificare il round-trip`,children:`Invia email di prova`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:Ft,title:`Diagnostica raw: mostra cosa risponde realmente il server sulla porta indicata`,children:`Diagnostica porta`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:z.statusMsg,style:{whiteSpace:`pre-line`},children:m})]})]})]})}var jt={root:`_root_o07ov_1`,loading:`_loading_o07ov_2`,err:`_err_o07ov_3`,header:`_header_o07ov_4`,title:`_title_o07ov_5`,addBtn:`_addBtn_o07ov_6`,empty:`_empty_o07ov_7`,card:`_card_o07ov_8`,cardToday:`_cardToday_o07ov_9`,icon:`_icon_o07ov_10`,info:`_info_o07ov_11`,name:`_name_o07ov_12`,date:`_date_o07ov_13`,labelToday:`_labelToday_o07ov_14`,labelTomorrow:`_labelTomorrow_o07ov_15`,labelFuture:`_labelFuture_o07ov_16`,editBtn:`_editBtn_o07ov_17`,delBtn:`_delBtn_o07ov_18`,overlay:`_overlay_o07ov_20`,modal:`_modal_o07ov_21`,modalTitle:`_modalTitle_o07ov_22`,label:`_label_o07ov_14`,input:`_input_o07ov_24`,hint:`_hint_o07ov_25`,formErr:`_formErr_o07ov_26`,modalBtns:`_modalBtns_o07ov_27`,cancelBtn:`_cancelBtn_o07ov_28`,saveBtn:`_saveBtn_o07ov_29`};function Mt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(()=>{i(!0),T(`/api/birthdays`).then(e=>{e?.error?o(e.error):n(e?.birthdays??[]),i(!1)})},[]);(0,_.useEffect)(()=>{p()},[p]);let m=()=>{c({name:``,date:``}),u(``)},h=e=>{c({name:e.name,date:e.date,contactId:e.contactId}),u(``)},g=async()=>{if(!s)return;if(!s.name.trim()){u(`Name is required`);return}if(!s.date.trim()){u(`Date is required`);return}f(!0);let e=s.date;/^\d{2}-\d{2}$/.test(e)&&(e=`${new Date().getFullYear()}-${e}`),await E(`/api/birthdays`,{name:s.name,date:e,contactId:s.contactId??null,edit:!!s.contactId}),f(!1),c(null),p()},v=e=>{confirm(`Remove birthday for ${e.name}?`)&&E(`/api/birthdays/delete`,{contactId:e.contactId}).then(p)};return r?(0,k.jsxs)(`div`,{className:jt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:jt.err,children:a}):(0,k.jsxs)(`div`,{className:jt.root,children:[(0,k.jsxs)(`div`,{className:jt.header,children:[(0,k.jsx)(`div`,{className:jt.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:jt.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:jt.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${jt.card} ${r?jt.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:jt.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:jt.info,children:[(0,k.jsx)(`div`,{className:jt.name,children:t.name}),(0,k.jsx)(`div`,{className:jt.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?jt.labelToday:i?jt.labelTomorrow:jt.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:jt.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:jt.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:jt.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:jt.modal,children:[(0,k.jsx)(`div`,{className:jt.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:jt.label,children:`Name *`}),(0,k.jsx)(`input`,{className:jt.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:jt.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:jt.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:jt.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:jt.formErr,children:l}),(0,k.jsxs)(`div`,{className:jt.modalBtns,children:[(0,k.jsx)(`button`,{className:jt.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:jt.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var B={root:`_root_1z04o_1`,header:`_header_1z04o_3`,title:`_title_1z04o_4`,subtitle:`_subtitle_1z04o_5`,code:`_code_1z04o_6`,addBtn:`_addBtn_1z04o_8`,tabs:`_tabs_1z04o_10`,tab:`_tab_1z04o_10`,tabActive:`_tabActive_1z04o_12`,loading:`_loading_1z04o_14`,err:`_err_1z04o_15`,empty:`_empty_1z04o_17`,emptyIcon:`_emptyIcon_1z04o_18`,emptyTitle:`_emptyTitle_1z04o_19`,emptySub:`_emptySub_1z04o_20`,card:`_card_1z04o_23`,cardDisabled:`_cardDisabled_1z04o_24`,cardTop:`_cardTop_1z04o_25`,cardLeft:`_cardLeft_1z04o_26`,jobName:`_jobName_1z04o_27`,schedule:`_schedule_1z04o_28`,agentBadge:`_agentBadge_1z04o_29`,statusBadge:`_statusBadge_1z04o_30`,statusActive:`_statusActive_1z04o_31`,statusPaused:`_statusPaused_1z04o_32`,jobPrompt:`_jobPrompt_1z04o_33`,jobMeta:`_jobMeta_1z04o_34`,cardActions:`_cardActions_1z04o_35`,runBtn:`_runBtn_1z04o_36`,editBtn:`_editBtn_1z04o_37`,pauseBtn:`_pauseBtn_1z04o_38`,resumeBtn:`_resumeBtn_1z04o_39`,delBtn:`_delBtn_1z04o_40`,templates:`_templates_1z04o_43`,templatesNote:`_templatesNote_1z04o_44`,templateCard:`_templateCard_1z04o_45`,templateLabel:`_templateLabel_1z04o_46`,templatePrompt:`_templatePrompt_1z04o_47`,templateBtns:`_templateBtns_1z04o_48`,scheduleTplBtn:`_scheduleTplBtn_1z04o_49`,runTplBtn:`_runTplBtn_1z04o_50`,formOverlay:`_formOverlay_1z04o_54`,formModal:`_formModal_1z04o_55`,formTitle:`_formTitle_1z04o_56`,label:`_label_1z04o_57`,input:`_input_1z04o_58`,textarea:`_textarea_1z04o_59`,presets:`_presets_1z04o_61`,preset:`_preset_1z04o_61`,presetActive:`_presetActive_1z04o_63`,cronHints:`_cronHints_1z04o_65`,cronHint:`_cronHint_1z04o_65`,formErr:`_formErr_1z04o_70`,formOk:`_formOk_1z04o_71`,formBtns:`_formBtns_1z04o_72`,cancelBtn:`_cancelBtn_1z04o_73`,saveBtn:`_saveBtn_1z04o_74`},Nt=[{label:`Every 15 min`,value:`every 15 minutes`},{label:`Every 30 min`,value:`every 30 minutes`},{label:`Every hour`,value:`every hour`},{label:`Every 6h`,value:`every 6 hours`},{label:`Daily 8am`,value:`every day at 08:00`},{label:`Daily 9am`,value:`every day at 09:00`},{label:`Daily noon`,value:`every day at 12:00`},{label:`Daily 6pm`,value:`every day at 18:00`},{label:`Mon–Fri 9am`,value:`weekdays at 09:00`},{label:`Every Monday`,value:`every monday at 09:00`}],Pt=[{label:`🌅 Morning Briefing`,prompt:`Summarize my unread emails from the last 12 hours, check today's calendar events, list my top 3 priority tasks, and give me a focused action plan for the day.`},{label:`🌆 Evening Review`,prompt:`Review what I accomplished today: check completed tasks, summarize any important emails received, flag unresolved issues, and prepare a priority list for tomorrow.`},{label:`📰 News Digest`,prompt:`Search for the top AI, tech, and finance news from the last 24 hours. Summarize the 5 most important stories with key takeaways and market implications.`},{label:`📈 Market Update`,prompt:`Provide a comprehensive market update: macro environment, major indices performance, top movers, notable events, and key levels to watch. Use herald and mercury agents.`},{label:`🐙 GitHub Monitor`,prompt:`Check my GitHub notifications, summarize open issues and pull requests that need attention, and draft brief responses for the most urgent ones.`},{label:`📊 Weekly Report`,prompt:`Generate a weekly productivity report: tasks completed vs pending, email response rate, upcoming calendar events, and 3 strategic priorities for next week.`},{label:`🔒 Security Scan`,prompt:`Run a security awareness check: scan recent code commits for potential vulnerabilities, check dependency alerts, and summarize any security-related GitHub notifications.`},{label:`🎯 Goal Tracker`,prompt:`Review my tasks and notes for goal progress. Identify what's on track, what's at risk, and suggest one concrete action to unblock the most important goal.`}],Ft=[{label:`0 9 * * 1-5`,desc:`Mon–Fri at 9:00 AM`},{label:`0 */6 * * *`,desc:`Every 6 hours`},{label:`*/30 * * * *`,desc:`Every 30 minutes`},{label:`0 8 * * *`,desc:`Daily at 8:00 AM`},{label:`0 20 * * 5`,desc:`Every Friday at 8 PM`}];function It(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({name:``,schedule:``,prompt:``,agent:``}),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(`jobs`),C=()=>{a(!0),T(`/api/cron`).then(e=>{e?.error?s(e.error):r(e?.jobs??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{C()},[]);let w=()=>{d({name:``,schedule:``,prompt:``,agent:``}),h(``),v(``),b(null),l(!0)},ee=e=>{d({name:e.name??``,schedule:e.schedule,prompt:e.prompt??e.command??``,agent:e.agent??``}),h(``),v(``),b(e.id),l(!0)},te=async()=>{if(!u.schedule.trim()){h(`Schedule is required`);return}if(!u.prompt.trim()){h(`Task prompt is required`);return}p(!0),h(``);try{y?await E(`/api/cron/update`,{id:y,schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}):await E(`/api/cron`,{schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}),v(y?`Updated!`:`Job scheduled!`),setTimeout(()=>{v(``),l(!1)},1500),C()}catch(e){h(e.message??`Failed`)}p(!1)},re=(e,t)=>E(`/api/cron/toggle`,{id:e,enabled:!t}).then(C),D=e=>{confirm(`Delete this scheduled task?`)&&E(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:B.root,children:[(0,k.jsxs)(`div`,{className:B.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:B.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:B.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:B.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:B.tabs,children:[(0,k.jsxs)(`button`,{className:`${B.tab} ${x===`jobs`?B.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${B.tab} ${x===`templates`?B.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:B.templates,children:[(0,k.jsx)(`div`,{className:B.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),Pt.map(t=>(0,k.jsxs)(`div`,{className:B.templateCard,children:[(0,k.jsx)(`div`,{className:B.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:B.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:B.templateBtns,children:[(0,k.jsx)(`button`,{className:B.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:B.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:B.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:B.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:B.empty,children:[(0,k.jsx)(`div`,{className:B.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:B.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:B.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${B.card} ${e.enabled?``:B.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:B.cardTop,children:[(0,k.jsxs)(`div`,{className:B.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:B.jobName,children:e.name}),(0,k.jsx)(`code`,{className:B.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:B.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${B.statusBadge} ${e.enabled?B.statusActive:B.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:B.cardActions,children:[(0,k.jsx)(`button`,{className:B.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:B.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?B.pauseBtn:B.resumeBtn,onClick:()=>re(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:B.delBtn,onClick:()=>D(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:B.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:B.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:B.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:B.formModal,children:[(0,k.jsx)(`div`,{className:B.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:B.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:B.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:B.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:B.presets,children:Nt.map(e=>(0,k.jsx)(`button`,{className:`${B.preset} ${u.schedule===e.value?B.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:B.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:B.cronHints,children:Ft.map(e=>(0,k.jsxs)(`span`,{className:B.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:B.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:B.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:B.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:B.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:B.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:B.formOk,children:g}),(0,k.jsxs)(`div`,{className:B.formBtns,children:[(0,k.jsx)(`button`,{className:B.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:B.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var Lt={root:`_root_1npv7_1`,loading:`_loading_1npv7_2`,sidebar:`_sidebar_1npv7_4`,newBtn:`_newBtn_1npv7_5`,empty:`_empty_1npv7_6`,noteItem:`_noteItem_1npv7_8`,noteItemActive:`_noteItemActive_1npv7_10`,noteTitle:`_noteTitle_1npv7_11`,noteMeta:`_noteMeta_1npv7_12`,notePreview:`_notePreview_1npv7_13`,noteTags:`_noteTags_1npv7_14`,noteTag:`_noteTag_1npv7_14`,editor:`_editor_1npv7_17`,emptyEditor:`_emptyEditor_1npv7_18`,titleInput:`_titleInput_1npv7_19`,contentArea:`_contentArea_1npv7_21`,editorFooter:`_editorFooter_1npv7_22`,delNoteBtn:`_delNoteBtn_1npv7_23`,cancelBtn:`_cancelBtn_1npv7_24`,saveBtn:`_saveBtn_1npv7_25`};function Rt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),h=()=>T(`/api/notes`).then(e=>{n(e?.notes??[]),i(!1)});(0,_.useEffect)(()=>{h()},[]);let g=e=>{o(e),c(e.title),u(e.content),m(!1)},v=()=>{o(null),c(``),u(``),m(!0)},y=async()=>{f(!0),p?await E(`/api/notes`,{title:s||`Untitled`,content:l}):a&&await E(`/api/notes/${a.id}`,{title:s,content:l}),f(!1),m(!1),h()},b=(e,t)=>{confirm(`Delete note "${t}"?`)&&E(`/api/notes/${e}/delete`,{}).then(h)};return r?(0,k.jsxs)(`div`,{className:Lt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Lt.root,children:[(0,k.jsxs)(`div`,{className:Lt.sidebar,children:[(0,k.jsx)(`button`,{className:Lt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:Lt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${Lt.noteItem} ${a?.id===e.id?Lt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:Lt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:Lt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:Lt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:Lt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:Lt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:Lt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:Lt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:Lt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:Lt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:Lt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:Lt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Lt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:Lt.emptyEditor,children:`Select a note or create a new one`})})]})}var zt={root:`_root_18yos_1`,loading:`_loading_18yos_2`,error:`_error_18yos_3`,toolbar:`_toolbar_18yos_5`,search:`_search_18yos_6`,addBtn:`_addBtn_18yos_7`,count:`_count_18yos_10`,empty:`_empty_18yos_12`,grid:`_grid_18yos_14`,card:`_card_18yos_16`,actions:`_actions_18yos_29`,avatar:`_avatar_18yos_31`,avatarImg:`_avatarImg_18yos_38`,info:`_info_18yos_40`,name:`_name_18yos_41`,row:`_row_18yos_42`,email:`_email_18yos_43`,phone:`_phone_18yos_44`,company:`_company_18yos_45`,birthday:`_birthday_18yos_46`,iconBtn:`_iconBtn_18yos_52`,iconBtnRed:`_iconBtnRed_18yos_58`,overlay:`_overlay_18yos_61`,modal:`_modal_18yos_62`,modalTitle:`_modalTitle_18yos_63`,field:`_field_18yos_64`,label:`_label_18yos_65`,input:`_input_18yos_66`,formStatus:`_formStatus_18yos_67`,formError:`_formError_18yos_68`,modalBtns:`_modalBtns_18yos_69`,cancelBtn:`_cancelBtn_18yos_70`,saveBtn:`_saveBtn_18yos_71`},Bt={name:``,email:``,phone:``,company:``,address:``,notes:``};function Vt(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(e=``)=>{T(e?`/api/contacts?q=${encodeURIComponent(e)}`:`/api/contacts`).then(e=>{r(e?.contacts??[]),a(!1),s(``)}).catch(()=>{s(`Could not load contacts. Run nha google revoke then nha google auth.`),a(!1)})};(0,_.useEffect)(()=>{b()},[]);let x=e=>{l(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>b(e),400)},S=()=>{d(null),p({...Bt}),v(``)},C=e=>{d(e),p({name:e.name,email:e.email??``,phone:e.phone??``,company:e.company??``,address:e.address??``,notes:e.notes??``}),v(``)},w=async()=>{if(f?.name){h(!0),v(`Saving…`);try{if(u?.resourceName){let e=await E(`/api/contacts/update`,{resourceName:u.resourceName,fields:f});if(e?.error){v(`Error: `+e.error);return}}else if(u)await E(`/api/contacts/update`,{resourceName:u.id,fields:f});else{let e=await E(`/api/contacts`,f);if(e?.error){v(`Error: `+e.error);return}}v(`Saved!`),setTimeout(()=>{p(null),d(null),b(c)},800)}catch(e){v(`Error: `+e.message)}finally{h(!1)}}},ee=(e,t)=>{e.stopPropagation(),confirm(`Delete "${t.name}"?`)&&E(`/api/contacts/delete`,{resourceName:t.resourceName||t.id}).then(e=>{let t=e;if(t?.error){alert(`Error: `+t.error);return}b(c)})},te=(e,n,r)=>{e.stopPropagation(),t(`chat`),setTimeout(()=>{let e=document.getElementById(`chatInput`);e&&(e.value=`Send an email to ${r} (${n}) about `,e.focus())},300)},re=e=>(e||`?`).split(` `).map(e=>e[0]).slice(0,2).join(``).toUpperCase();return i?(0,k.jsxs)(`div`,{className:zt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:zt.error,children:o}):(0,k.jsxs)(`div`,{className:zt.root,children:[(0,k.jsxs)(`div`,{className:zt.toolbar,children:[(0,k.jsx)(`input`,{className:zt.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:zt.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:zt.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:zt.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:zt.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:zt.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:zt.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:zt.avatarImg}):re(e.name)}),(0,k.jsxs)(`div`,{className:zt.info,children:[(0,k.jsx)(`div`,{className:zt.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:zt.row,children:[e.email&&(0,k.jsx)(`span`,{className:zt.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:zt.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:zt.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:zt.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:zt.actions,children:[e.email&&(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${zt.iconBtn} ${zt.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:zt.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:zt.modal,children:[(0,k.jsx)(`div`,{className:zt.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:zt.field,children:[(0,k.jsx)(`label`,{className:zt.label,children:t}),(0,k.jsx)(`input`,{className:zt.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?zt.formError:zt.formStatus,children:g}),(0,k.jsxs)(`div`,{className:zt.modalBtns,children:[(0,k.jsx)(`button`,{className:zt.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:zt.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}function Ht({open:e,onClose:t,children:n,className:r,handleClassName:i,backdropClassName:a,closeOnBackdrop:o=!0,ariaLabel:s}){let c=(0,_.useRef)(null),[l,u]=(0,_.useState)(0),d=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),(0,_.useEffect)(()=>{e||u(0)},[e]),e?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:a,onClick:o?t:void 0,style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.55)`,zIndex:29}}),(0,k.jsxs)(`div`,{ref:c,className:r,role:`dialog`,"aria-modal":`true`,"aria-label":s,style:{transform:`translateY(${l}px)`,transition:l===0?`transform 0.2s ease`:`none`},children:[(0,k.jsx)(`div`,{className:i,onTouchStart:e=>{d.current=e.touches[0].clientY},onTouchMove:e=>{if(d.current==null)return;let t=e.touches[0].clientY-d.current;t>0&&u(t)},onTouchEnd:()=>{l>80&&t(),u(0),d.current=null}}),n]})]}):null}function Ut(e=768){let[t,n]=(0,_.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(max-width: ${e}px)`).matches);return(0,_.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(`(max-width: ${e}px)`),r=e=>n(e.matches);return typeof t.addEventListener==`function`?(t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)):(t.addListener(r),()=>t.removeListener(r))},[e]),t}var V={root:`_root_b07pi_2`,topbar:`_topbar_b07pi_11`,topbarLeft:`_topbarLeft_b07pi_20`,topbarTitle:`_topbarTitle_b07pi_21`,topbarSub:`_topbarSub_b07pi_22`,topbarActions:`_topbarActions_b07pi_23`,runBtn:`_runBtn_b07pi_25`,runBtnActive:`_runBtnActive_b07pi_32`,logBtn:`_logBtn_b07pi_34`,newWfBtn:`_newWfBtn_b07pi_41`,body:`_body_b07pi_50`,sidebar:`_sidebar_b07pi_53`,sidebarTitle:`_sidebarTitle_b07pi_61`,sidebarEmpty:`_sidebarEmpty_b07pi_65`,wfItem:`_wfItem_b07pi_67`,wfItemActive:`_wfItemActive_b07pi_78`,wfItemRow:`_wfItemRow_b07pi_79`,wfItemName:`_wfItemName_b07pi_80`,wfItemMeta:`_wfItemMeta_b07pi_81`,wfOn:`_wfOn_b07pi_82`,wfOff:`_wfOff_b07pi_83`,wfDelBtn:`_wfDelBtn_b07pi_84`,canvasArea:`_canvasArea_b07pi_96`,canvasHeader:`_canvasHeader_b07pi_98`,wfNameInput:`_wfNameInput_b07pi_103`,canvasHint:`_canvasHint_b07pi_110`,portHint:`_portHint_b07pi_111`,connectHint:`_connectHint_b07pi_112`,cancelConnectBtn:`_cancelConnectBtn_b07pi_113`,canvas:`_canvas_b07pi_96`,canvasConnecting:`_canvasConnecting_b07pi_126`,canvasSvg:`_canvasSvg_b07pi_128`,canvasNode:`_canvasNode_b07pi_138`,canvasNodeSelected:`_canvasNodeSelected_b07pi_156`,canvasNodeConnecting:`_canvasNodeConnecting_b07pi_157`,nodeIcon:`_nodeIcon_b07pi_159`,nodeLabel:`_nodeLabel_b07pi_160`,nodeConfigPreview:`_nodeConfigPreview_b07pi_161`,nodeDelBtn:`_nodeDelBtn_b07pi_163`,portOut:`_portOut_b07pi_175`,portActive:`_portActive_b07pi_186`,portIn:`_portIn_b07pi_188`,pulse:`_pulse_b07pi_1`,canvasDrop:`_canvasDrop_b07pi_199`,canvasEmpty:`_canvasEmpty_b07pi_207`,canvasEmptyIcon:`_canvasEmptyIcon_b07pi_212`,canvasEmptyTitle:`_canvasEmptyTitle_b07pi_213`,canvasEmptyDesc:`_canvasEmptyDesc_b07pi_214`,logPanel:`_logPanel_b07pi_217`,logHeader:`_logHeader_b07pi_224`,logTime:`_logTime_b07pi_230`,logClose:`_logClose_b07pi_231`,logEmpty:`_logEmpty_b07pi_232`,logStep:`_logStep_b07pi_233`,logStepError:`_logStepError_b07pi_234`,logStepHeader:`_logStepHeader_b07pi_235`,logStepIcon:`_logStepIcon_b07pi_236`,logStepLabel:`_logStepLabel_b07pi_237`,logStepErrBadge:`_logStepErrBadge_b07pi_238`,logStepErr:`_logStepErr_b07pi_234`,logStepOutput:`_logStepOutput_b07pi_240`,rightPanel:`_rightPanel_b07pi_245`,configPanel:`_configPanel_b07pi_256`,configHeader:`_configHeader_b07pi_257`,configClose:`_configClose_b07pi_258`,configDesc:`_configDesc_b07pi_259`,configFields:`_configFields_b07pi_260`,configField:`_configField_b07pi_260`,configLabel:`_configLabel_b07pi_262`,configRequired:`_configRequired_b07pi_263`,configInput:`_configInput_b07pi_264`,configTextarea:`_configTextarea_b07pi_271`,zoomControls:`_zoomControls_b07pi_281`,configHint:`_configHint_b07pi_307`,configDelete:`_configDelete_b07pi_309`,palette:`_palette_b07pi_313`,paletteTitle:`_paletteTitle_b07pi_314`,paletteTabs:`_paletteTabs_b07pi_315`,paletteTab:`_paletteTab_b07pi_315`,paletteTabActive:`_paletteTabActive_b07pi_321`,paletteNodes:`_paletteNodes_b07pi_322`,paletteDef:`_paletteDef_b07pi_324`,paletteDefIcon:`_paletteDefIcon_b07pi_332`,paletteDefLabel:`_paletteDefLabel_b07pi_333`,paletteDefDesc:`_paletteDefDesc_b07pi_334`,paletteFooter:`_paletteFooter_b07pi_336`,paletteGuide:`_paletteGuide_b07pi_340`,guideTitle:`_guideTitle_b07pi_348`,guideStep:`_guideStep_b07pi_357`,guideNum:`_guideNum_b07pi_365`,guideTip:`_guideTip_b07pi_381`,guideCode:`_guideCode_b07pi_392`,nodeListMobile:`_nodeListMobile_b07pi_436`,nodeRow:`_nodeRow_b07pi_444`,nodeRowIcon:`_nodeRowIcon_b07pi_457`,nodeRowBody:`_nodeRowBody_b07pi_463`,nodeRowLabel:`_nodeRowLabel_b07pi_467`,nodeRowDesc:`_nodeRowDesc_b07pi_473`,nodeRowIndex:`_nodeRowIndex_b07pi_480`,nodeRowBranch:`_nodeRowBranch_b07pi_488`,configSheet:`_configSheet_b07pi_496`,configSheetHandle:`_configSheetHandle_b07pi_509`,runFab:`_runFab_b07pi_519`,debuggerPanel:`_debuggerPanel_b07pi_548`,dbgHeader:`_dbgHeader_b07pi_564`,dbgTimeline:`_dbgTimeline_b07pi_565`,dbgWatcher:`_dbgWatcher_b07pi_566`,dbgEmpty:`_dbgEmpty_b07pi_567`,dbgInspector:`_dbgInspector_b07pi_563`,dbgHeaderLeft:`_dbgHeaderLeft_b07pi_591`,dbgHeaderRight:`_dbgHeaderRight_b07pi_600`,dbgTitle:`_dbgTitle_b07pi_609`,dbgRunSelect:`_dbgRunSelect_b07pi_610`,dbgStats:`_dbgStats_b07pi_619`,dbgPausedBadge:`_dbgPausedBadge_b07pi_620`,dbgPulse:`_dbgPulse_b07pi_1`,dbgBtnResume:`_dbgBtnResume_b07pi_634`,dbgBtnReplay:`_dbgBtnReplay_b07pi_634`,dbgTlStep:`_dbgTlStep_b07pi_673`,dbgTlStepOk:`_dbgTlStepOk_b07pi_691`,dbgTlStepErr:`_dbgTlStepErr_b07pi_692`,dbgTlStepPaused:`_dbgTlStepPaused_b07pi_693`,dbgTlStepActive:`_dbgTlStepActive_b07pi_694`,dbgTlIcon:`_dbgTlIcon_b07pi_699`,dbgTlLabel:`_dbgTlLabel_b07pi_700`,dbgTlMs:`_dbgTlMs_b07pi_708`,dbgInspHeader:`_dbgInspHeader_b07pi_719`,dbgInspLabel:`_dbgInspLabel_b07pi_729`,dbgInspIcon:`_dbgInspIcon_b07pi_738`,dbgInspDuration:`_dbgInspDuration_b07pi_739`,dbgInspActions:`_dbgInspActions_b07pi_747`,dbgBtnExplain:`_dbgBtnExplain_b07pi_755`,dbgBtnReplayFrom:`_dbgBtnReplayFrom_b07pi_767`,dbgBtnBp:`_dbgBtnBp_b07pi_778`,dbgBtnBpActive:`_dbgBtnBpActive_b07pi_787`,dbgBpGroup:`_dbgBpGroup_b07pi_792`,dbgBpCondition:`_dbgBpCondition_b07pi_800`,dbgExplanation:`_dbgExplanation_b07pi_820`,dbgExplanationIcon:`_dbgExplanationIcon_b07pi_833`,dbgExplanationText:`_dbgExplanationText_b07pi_834`,dbgTabs:`_dbgTabs_b07pi_836`,dbgTab:`_dbgTab_b07pi_836`,dbgTabActive:`_dbgTabActive_b07pi_854`,dbgTabBody:`_dbgTabBody_b07pi_858`,dbgPre:`_dbgPre_b07pi_872`,dbgPreErr:`_dbgPreErr_b07pi_883`,dbgMuted:`_dbgMuted_b07pi_884`,canvasNodeOk:`_canvasNodeOk_b07pi_887`,canvasNodeErr:`_canvasNodeErr_b07pi_888`,canvasNodePaused:`_canvasNodePaused_b07pi_889`,canvasNodeFocused:`_canvasNodeFocused_b07pi_893`,nodeBpBadge:`_nodeBpBadge_b07pi_898`,dbgWatcherHeader:`_dbgWatcherHeader_b07pi_926`,dbgWatcherTitle:`_dbgWatcherTitle_b07pi_934`,dbgWatcherSub:`_dbgWatcherSub_b07pi_939`,dbgWatcherBody:`_dbgWatcherBody_b07pi_943`,dbgWatcherRow:`_dbgWatcherRow_b07pi_948`,dbgWatcherKey:`_dbgWatcherKey_b07pi_954`,dbgWatcherVal:`_dbgWatcherVal_b07pi_961`,dbgEditConfig:`_dbgEditConfig_b07pi_974`,dbgEditTitle:`_dbgEditTitle_b07pi_979`,dbgEditRow:`_dbgEditRow_b07pi_985`,dbgEditLabel:`_dbgEditLabel_b07pi_992`,dbgEditInput:`_dbgEditInput_b07pi_998`,dbgEditActions:`_dbgEditActions_b07pi_1013`,dbgDiffPicker:`_dbgDiffPicker_b07pi_1020`,dbgDiffOverlay:`_dbgDiffOverlay_b07pi_1021`,dbgDiffModal:`_dbgDiffModal_b07pi_1032`,dbgDiffHeader:`_dbgDiffHeader_b07pi_1042`,dbgDiffBody:`_dbgDiffBody_b07pi_1057`,dbgDiffRow:`_dbgDiffRow_b07pi_1065`,dbgDiffOk:`_dbgDiffOk_b07pi_1071`,dbgDiffChanged:`_dbgDiffChanged_b07pi_1072`,dbgDiffAdded:`_dbgDiffAdded_b07pi_1073`,dbgDiffRemoved:`_dbgDiffRemoved_b07pi_1074`,dbgDiffNodeLabel:`_dbgDiffNodeLabel_b07pi_1075`,dbgDiffDuration:`_dbgDiffDuration_b07pi_1083`,dbgDiffSplit:`_dbgDiffSplit_b07pi_1090`,dbgDiffSide:`_dbgDiffSide_b07pi_1096`,dbgDiffSideLabel:`_dbgDiffSideLabel_b07pi_1102`,envSelect:`_envSelect_b07pi_1110`,backupStatus:`_backupStatus_b07pi_1120`,templateCard:`_templateCard_b07pi_1127`,templateHeader:`_templateHeader_b07pi_1136`,templateName:`_templateName_b07pi_1142`,templateTag:`_templateTag_b07pi_1147`,templateDesc:`_templateDesc_b07pi_1156`,templateMeta:`_templateMeta_b07pi_1162`,varPickerBtn:`_varPickerBtn_b07pi_1168`,varPickerMenu:`_varPickerMenu_b07pi_1182`,varPickerTitle:`_varPickerTitle_b07pi_1195`,varPickerItem:`_varPickerItem_b07pi_1202`,varPickerLabel:`_varPickerLabel_b07pi_1221`,varPickerHint:`_varPickerHint_b07pi_1226`,varPickerToken:`_varPickerToken_b07pi_1232`},Wt=[{id:`trigger_manual`,type:`trigger`,label:`Manual`,icon:`▶`,color:`#6366f1`,description:`Run manually with optional text input.`,configFields:[{key:`input`,label:`Input text`,placeholder:`Optional initial input`}]},{id:`trigger_cron`,type:`trigger`,label:`Cron`,icon:`⏰`,color:`#fbbf24`,description:`Run on a schedule (cron expression).`,configFields:[{key:`schedule`,label:`Cron expression`,placeholder:`0 8 * * *`,required:!0}]},{id:`trigger_email`,type:`trigger`,label:`New Email`,icon:`📧`,color:`#38bdf8`,description:`Trigger when a new email arrives matching a filter.`,configFields:[{key:`filter`,label:`Gmail filter`,placeholder:`subject:TODO is:unread`}]},{id:`trigger_webhook`,type:`trigger`,label:`Webhook`,icon:`🔗`,color:`#a5b4fc`,description:`Trigger via HTTP POST/GET/PUT/DELETE. URL: http://localhost:3847/api/webhooks/<slug>`,configFields:[{key:`slug`,label:`Slug (URL path)`,placeholder:`my-trigger`,required:!0}]},{id:`trigger_file_watch`,type:`trigger`,label:`File Watch`,icon:`📁`,color:`#34d399`,description:`Fires when a file in the watched folder is created/modified.`,configFields:[{key:`path`,label:`Folder path`,placeholder:`/Users/me/inbox`,required:!0},{key:`recursive`,label:`Recursive (yes/no)`,placeholder:`no`}]},{id:`trigger_rss`,type:`trigger`,label:`RSS Feed`,icon:`📰`,color:`#fb923c`,description:`Polls an RSS/Atom feed; fires once per new item.`,configFields:[{key:`url`,label:`Feed URL`,placeholder:`https://example.com/feed.xml`,required:!0},{key:`intervalMin`,label:`Poll interval (min)`,placeholder:`15`}]},{id:`trigger_imap_folder`,type:`trigger`,label:`IMAP Folder`,icon:`📬`,color:`#60a5fa`,description:`Fires on new mail in a specific IMAP folder/label.`,configFields:[{key:`account`,label:`IMAP account id`,placeholder:`main`,required:!0},{key:`folder`,label:`Folder name`,placeholder:`INBOX`}]},{id:`trigger_discord_message`,type:`trigger`,label:`Discord Message`,icon:`🟣`,color:`#a78bfa`,description:`Fires on a new Discord message matching the filter (#channel or @mention).`,configFields:[{key:`filter`,label:`Filter`,placeholder:`#general OR @nha-bot`}]},{id:`action_email`,type:`action`,label:`Send Email`,icon:`✉`,color:`#38bdf8`,description:`Send email via Gmail or IMAP.`,configFields:[{key:`to`,label:`To`,placeholder:`email@example.com`,required:!0},{key:`subject`,label:`Subject`,placeholder:`Subject or {{output}}`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`action_slack`,type:`action`,label:`Slack Message`,icon:`💬`,color:`#818cf8`,description:`Post a message to a Slack channel.`,configFields:[{key:`channel`,label:`Channel`,placeholder:`#general`,required:!0},{key:`text`,label:`Text`,placeholder:`{{output}}`}]},{id:`action_calendar`,type:`action`,label:`Create Event`,icon:`📅`,color:`#4ade80`,description:`Create a Google Calendar event.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`date`,label:`Date (YYYY-MM-DD)`,placeholder:`2025-01-15`},{key:`time`,label:`Time (HH:MM)`,placeholder:`09:00`}]},{id:`action_task`,type:`action`,label:`Create Task`,icon:`✅`,color:`#fbbf24`,description:`Add a task to your task list.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`priority`,label:`Priority`,placeholder:`medium`}]},{id:`action_drive`,type:`action`,label:`Save to Drive`,icon:`💾`,color:`#a78bfa`,description:`Save a text file to Google Drive.`,configFields:[{key:`name`,label:`Filename`,placeholder:`output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_notion`,type:`action`,label:`Notion Page`,icon:`📋`,color:`#e4e4e7`,description:`Create or update a Notion page.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_github`,type:`action`,label:`GitHub Issue`,icon:`🐙`,color:`#6ee7b7`,description:`Create a GitHub issue.`,configFields:[{key:`repo`,label:`Repo (owner/name)`,placeholder:`user/repo`,required:!0},{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`body`,label:`Body`,placeholder:``}]},{id:`action_webhook`,type:`action`,label:`HTTP Request`,icon:`🌐`,color:`#38bdf8`,description:`Make an HTTP request.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://…`,required:!0},{key:`method`,label:`Method`,placeholder:`POST`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`ai_agent`,type:`ai`,label:`Run Agent`,icon:`🤖`,color:`#818cf8`,description:`Run any of the 38 NHA specialist agents.`,configFields:[{key:`agent`,label:`Agent name`,placeholder:`herald, saber, forge…`,required:!0},{key:`prompt`,label:`Prompt`,placeholder:`Summarize this: {{output}}`,required:!0}]},{id:`ai_summarize`,type:`ai`,label:`Summarize`,icon:`📝`,color:`#a5b4fc`,description:`Summarize text with AI (free via Liara).`,configFields:[{key:`prompt`,label:`Prompt`,placeholder:`Summarize: {{output}}`}]},{id:`ai_classify`,type:`ai`,label:`Classify`,icon:`🏷`,color:`#a5b4fc`,description:`Classify content into categories.`,configFields:[{key:`categories`,label:`Categories (comma-separated)`,placeholder:`urgent, normal, spam`},{key:`prompt`,label:`Prompt`,placeholder:`Classify this email: {{output}}`}]},{id:`ai_extract`,type:`ai`,label:`Extract Data`,icon:`🔍`,color:`#a5b4fc`,description:`Extract structured data from text.`,configFields:[{key:`prompt`,label:`What to extract`,placeholder:`Extract name, email, date from: {{output}}`}]},{id:`ai_translate`,type:`ai`,label:`Translate`,icon:`🌍`,color:`#a5b4fc`,description:`Translate text to another language.`,configFields:[{key:`lang`,label:`Target language`,placeholder:`Italian`,required:!0},{key:`prompt`,label:`Text`,placeholder:`{{output}}`}]},{id:`ai_code`,type:`ai`,label:`Code (JS)`,icon:`💻`,color:`#818cf8`,description:"Execute JavaScript code. Access previous output via `input` variable. Return a value.",configFields:[{key:`code`,label:`JavaScript code`,placeholder:`const data = JSON.parse(input);
703
+ </body></html>`,m=new Blob([p],{type:`text/html`}),h=URL.createObjectURL(m),g=document.createElement(`a`);g.href=h,g.download=`nha-report-${Date.now()}.html`,g.click(),URL.revokeObjectURL(h);let _=window.open(``,`_blank`,`width=1100,height=800`);_&&(_.document.open(),_.document.write(p),_.document.close(),_.onload=()=>setTimeout(()=>{_.focus(),_.print()},600))},N=t=>{let n=`**Studio Workflow Result**\n\nTask: ${t.task}\n\nAgents: ${t.nodes.map(e=>e.label).join(` → `)}\n\n---\n\n${t.result}`;try{sessionStorage.setItem(`nha_studio_import`,n)}catch{}e(`chat`)},Ce=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),de.current=``,w(null),j.current=null,te(!1),b({in:0,out:0}),v(null),D(!1);try{sessionStorage.removeItem(dt)}catch{}}},we=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:P.root,children:[(0,k.jsxs)(`div`,{className:P.header,children:[(0,k.jsxs)(`div`,{className:P.headerLeft,children:[(0,k.jsx)(`div`,{className:P.title,children:`Studio`}),(0,k.jsx)(`div`,{className:P.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:P.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:P.tokenBar,children:[(0,k.jsxs)(`span`,{className:P.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:P.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` out`})]}),(0,k.jsxs)(`div`,{style:{position:`relative`},ref:fe,children:[(0,k.jsxs)(`button`,{className:P.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,k.jsx)(`div`,{className:P.sessionsDrawer,children:f.length===0?(0,k.jsx)(`div`,{className:P.noSessions,children:`No saved sessions yet.`}):(0,k.jsxs)(k.Fragment,{children:[f.map(e=>(0,k.jsxs)(`div`,{className:P.sessionItem,children:[(0,k.jsxs)(`div`,{className:P.sessionInfo,onClick:()=>ve(e),children:[(0,k.jsx)(`div`,{className:P.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:P.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,k.jsxs)(`div`,{className:P.sessionBtns,children:[(0,k.jsx)(`button`,{className:P.importBtn,onClick:()=>N(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:P.delSessionBtn,onClick:()=>ye(e.id),children:`✕`})]})]},e.id)),(0,k.jsx)(`div`,{className:P.sessionsFooter,children:(0,k.jsx)(`button`,{className:P.clearAllSessionsBtn,onClick:be,children:`Clear All`})})]})})]}),x&&(0,k.jsx)(`button`,{className:P.canvasToggleBtn,onClick:()=>{D(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:P.pdfBtn,onClick:xe,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:P.clearBtn,onClick:Ce,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,k.jsxs)(`div`,{className:P.inputArea,children:[(0,k.jsxs)(`div`,{className:P.inputRow,children:[(0,k.jsx)(`textarea`,{className:P.taskInput,value:n,onChange:e=>r(e.target.value),placeholder:`Describe your task… e.g. Analyze my emails and create a priority action plan`,rows:4,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),he())}}),(0,k.jsxs)(`div`,{className:P.inputControls,children:[u?(0,k.jsx)(`button`,{className:P.stopBtn,onClick:ge,children:`■ Stop`}):(0,k.jsx)(`button`,{className:P.runBtn,onClick:he,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:P.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>me(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:P.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:P.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.examples,children:ke.map((e,t)=>(0,k.jsx)(`button`,{className:P.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:P.financeSection,children:[(0,k.jsx)(`div`,{className:P.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:P.financePresets,children:De.map((e,t)=>(0,k.jsx)(`button`,{className:P.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.officeSceneWrap,style:{overflow:`hidden`,position:`relative`,height:`180px`},children:(0,k.jsxs)(`div`,{style:{display:`flex`,width:`200%`,height:`100%`,transition:`transform 700ms cubic-bezier(0.22, 1, 0.36, 1)`,transform:C&&C.phase!==`idle`&&C.phase!==`skipped`?`translateX(-50%)`:`translateX(0)`},children:[(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(Qe,{nodes:i,running:u})}),(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(rt,{agents:re.length>0?re:i,council:C})})]})}),(0,k.jsxs)(`div`,{className:`${P.pipelineWrap} ${u?P.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:P.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:P.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:P.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:P.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${P.agentChip} ${P[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:P.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:P.chipDots,children:[(0,k.jsx)(`span`,{className:P.dot1,children:`.`}),(0,k.jsx)(`span`,{className:P.dot2,children:`.`}),(0,k.jsx)(`span`,{className:P.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:P.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:P.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${P.arrow} ${u?P.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:P.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:P.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:P.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:P.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,k.jsxs)(`div`,{className:P.body,ref:ue,children:[(o.length>0||we)&&(0,k.jsxs)(`div`,{className:P.twoCol,children:[(0,k.jsxs)(`div`,{className:P.logPanel,children:[(0,k.jsx)(`div`,{className:P.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:P.logBody,ref:le,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.logEntry} ${P[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:P.logTime,children:e.time}),(0,k.jsx)(`span`,{className:P.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:P.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:P.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.liveBlock} ${e.status===`running`?P.liveBlockActive:``} ${e.status===`done`&&e.output?P.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?se(e):void 0,children:[(0,k.jsxs)(`div`,{className:P.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:P.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${P.outputStatus} ${P[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:P.expandHint,children:`↗ espandi`})]}),e.status===`running`&&(0,k.jsxs)(`div`,{className:P.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingLabel,children:e.statusLine??`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${e.status===`done`&&e.output?P.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:Se(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:P.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptDesc,children:[re.length,` agenti (`,re.map(e=>e.label).join(`, `),`) hanno prodotto output. Il Geth Consensus eseguirà cross-reading, refinement e mediazione HERALD per raggiungere un consenso collettivo.`]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptMeta,children:[`Complessità: `,re.length<=3?`⚡ Rapido (~30s)`:re.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:P.parliamentActivateBtn,onClick:_e,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:P.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:P.councilWrapper,children:(0,k.jsx)(vt,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:P.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:P.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:P.resultAccordionBody,dangerouslySetInnerHTML:{__html:Se(c)}})]})]}),E&&(0,k.jsxs)(`div`,{className:P.canvasPanel,children:[(0,k.jsxs)(`div`,{className:P.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:P.panelTabs,children:[(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`canvas`?P.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`browser`?P.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:P.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:P.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:P.canvasPanelClose,onClick:()=>D(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:P.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:P.browserPanel,children:[(0,k.jsxs)(`div`,{className:P.browserBar,children:[(0,k.jsx)(`input`,{className:P.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:P.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:P.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`Enter a URL above to browse`})]})]}),oe&&(0,k.jsx)(`div`,{className:P.blockModalOverlay,onClick:()=>se(null),children:(0,k.jsxs)(`div`,{className:P.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:P.blockModalHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:oe.icon}),(0,k.jsx)(`span`,{className:P.blockModalTitle,children:oe.label}),(0,k.jsx)(`button`,{className:P.blockModalClose,onClick:()=>se(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${P.blockModalBody}`,dangerouslySetInnerHTML:{__html:Se(oe.output)}})]})})]})}var R={root:`_root_13wnr_2`,hero:`_hero_13wnr_12`,heroLeft:`_heroLeft_13wnr_21`,heroDate:`_heroDate_13wnr_22`,heroTitle:`_heroTitle_13wnr_23`,heroVer:`_heroVer_13wnr_24`,heroUptime:`_heroUptime_13wnr_25`,heroWeather:`_heroWeather_13wnr_27`,wIcon:`_wIcon_13wnr_35`,wInfo:`_wInfo_13wnr_36`,wTemp:`_wTemp_13wnr_37`,wCity:`_wCity_13wnr_38`,wDesc:`_wDesc_13wnr_39`,wEmpty:`_wEmpty_13wnr_40`,kpiRow:`_kpiRow_13wnr_43`,kpi:`_kpi_13wnr_43`,kpiNum:`_kpiNum_13wnr_55`,kpiLbl:`_kpiLbl_13wnr_56`,kpiBar:`_kpiBar_13wnr_57`,kpiFill:`_kpiFill_13wnr_58`,liveGrid:`_liveGrid_13wnr_61`,liveCard:`_liveCard_13wnr_67`,liveHdr:`_liveHdr_13wnr_71`,liveMore:`_liveMore_13wnr_79`,liveRow:`_liveRow_13wnr_81`,liveUnread:`_liveUnread_13wnr_89`,liveTitle:`_liveTitle_13wnr_89`,liveTime:`_liveTime_13wnr_91`,liveBody:`_liveBody_13wnr_95`,liveSub:`_liveSub_13wnr_97`,prio:`_prio_13wnr_99`,prio_high:`_prio_high_13wnr_103`,prio_medium:`_prio_medium_13wnr_104`,prio_low:`_prio_low_13wnr_105`,launcher:`_launcher_13wnr_108`,launchGroup:`_launchGroup_13wnr_115`,launchGroupLabel:`_launchGroupLabel_13wnr_117`,launchTiles:`_launchTiles_13wnr_123`,tile:`_tile_13wnr_129`,tileIcon:`_tileIcon_13wnr_143`,tileLabel:`_tileLabel_13wnr_144`},bt=[{view:`chat`,icon:`💬`,label:`Chat`,color:`#38bdf8`,group:`Panoramica`},{view:`plan`,icon:`🗓️`,label:`Daily Plan`,color:`#818cf8`,group:`Panoramica`},{view:`tasks`,icon:`✅`,label:`Tasks`,color:`#4ade80`,group:`Panoramica`},{view:`email`,icon:`📧`,label:`Email`,color:`#f87171`,group:`Google`},{view:`calendar`,icon:`📅`,label:`Calendar`,color:`#fb923c`,group:`Google`},{view:`drive`,icon:`💾`,label:`Drive`,color:`#facc15`,group:`Google`},{view:`contacts`,icon:`👤`,label:`Contacts`,color:`#34d399`,group:`Google`},{view:`notes`,icon:`📝`,label:`Notes`,color:`#a78bfa`,group:`Google`},{view:`onedrive`,icon:`☁️`,label:`OneDrive`,color:`#60a5fa`,group:`Microsoft`},{view:`mstodo`,icon:`📋`,label:`MS Todo`,color:`#38bdf8`,group:`Microsoft`},{view:`github`,icon:`🐙`,label:`GitHub`,color:`#e2e8f0`,group:`Tools`},{view:`notion`,icon:`📓`,label:`Notion`,color:`#94a3b8`,group:`Tools`},{view:`slack`,icon:`💼`,label:`Slack`,color:`#e879f9`,group:`Tools`},{view:`maps`,icon:`🗺️`,label:`Maps`,color:`#2dd4bf`,group:`Tools`},{view:`reminders`,icon:`🔔`,label:`Reminders`,color:`#fbbf24`,group:`Tools`},{view:`birthdays`,icon:`🎂`,label:`Birthdays`,color:`#f472b6`,group:`Tools`},{view:`cron`,icon:`⏰`,label:`Cron`,color:`#fb923c`,group:`Tools`},{view:`screen`,icon:`🖥️`,label:`Screen`,color:`#64748b`,group:`Tools`},{view:`agents`,icon:`🤖`,label:`Agents`,color:`#4ade80`,group:`AI`},{view:`studio`,icon:`🎭`,label:`Studio`,color:`#a78bfa`,group:`AI`},{view:`webcraft`,icon:`🔨`,label:`WebCraft`,color:`#f59e0b`,group:`AI`},{view:`collab`,icon:`🏛️`,label:`Alexandria`,color:`#38bdf8`,group:`AI`},{view:`connectors`,icon:`🔗`,label:`AWF - AutoWorkFlow`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],xt={Sunny:`☀️`,Clear:`☀️`,"Partly Cloudy":`⛅`,"Partly cloudy":`⛅`,Cloudy:`☁️`,Overcast:`☁️`,"Light rain":`🌧️`,Rain:`🌧️`,Drizzle:`🌧️`,"Moderate rain":`🌧️`,"Heavy rain":`🌧️`,Snow:`❄️`,"Light snow":`❄️`,Fog:`🌫️`,Mist:`🌫️`,Thunder:`⚡`,"Thundery outbreaks":`⚡`};function St(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function Ct(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function wt(){let e=ne(e=>e.setView),t=j(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(new Date);(0,_.useEffect)(()=>{let e=setInterval(()=>p(new Date),6e4);return()=>clearInterval(e)},[]),(0,_.useEffect)(()=>{let e=!0,t=t=>n=>{e&&n!=null&&t(n)};T(`/api/tasks`).then(e=>t(r)(e?.tasks??[])),T(`/api/emails?page=0&pageSize=8`).then(e=>t(a)(e?.emails??[])),T(`/api/calendar`).then(e=>t(s)(e?.events??[])),T(`/api/status`).then(t(l));let n=localStorage.getItem(`nha_weather_location`),i=t=>T(`/api/weather?location=${encodeURIComponent(t)}`).then(t=>{e&&t&&t.city&&d(t)});return n?i(n):navigator.geolocation?.getCurrentPosition(e=>i(`${e.coords.latitude.toFixed(4)},${e.coords.longitude.toFixed(4)}`),()=>{},{timeout:6e3}),()=>{e=!1}},[]);let m=n.filter(e=>e.status!==`done`),h=n.filter(e=>e.status===`done`),g=n.length>0?Math.round(h.length/n.length*100):0,v=i.filter(e=>e.isUnread).length,y=f.toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`}),b=[...new Set(bt.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:R.root,children:[(0,k.jsxs)(`div`,{className:R.hero,children:[(0,k.jsxs)(`div`,{className:R.heroLeft,children:[(0,k.jsx)(`div`,{className:R.heroDate,children:y}),(0,k.jsx)(`div`,{className:R.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:R.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:R.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:R.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),d(null),T(`/api/weather?location=${encodeURIComponent(e)}`).then(e=>{e&&e.city&&d(e)}))},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:R.wIcon,children:xt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:R.wInfo,children:[(0,k.jsxs)(`span`,{className:R.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:R.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:R.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:R.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:R.kpiRow,children:[(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:R.kpiBar,children:(0,k.jsx)(`div`,{className:R.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:R.kpi,children:[(0,k.jsxs)(`span`,{className:R.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:R.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:t.isAllDay?`All day`:St(t.start)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:R.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${R.liveRow} ${t.isUnread?R.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:Ct(t.date)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:R.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${R.prio} ${R[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:R.liveBody,children:(0,k.jsx)(`span`,{className:R.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:R.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:R.launchGroup,children:[(0,k.jsx)(`div`,{className:R.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:R.launchTiles,children:bt.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:R.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:R.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:R.tileLabel,children:t.label})]},t.view))})]},t))})]})}var Tt={root:`_root_1pldx_1`,loading:`_loading_1pldx_2`,bar:`_bar_1pldx_4`,input:`_input_1pldx_5`,select:`_select_1pldx_6`,addBtn:`_addBtn_1pldx_7`,actions:`_actions_1pldx_10`,clearDone:`_clearDone_1pldx_11`,clearAll:`_clearAll_1pldx_12`,stats:`_stats_1pldx_14`,progress:`_progress_1pldx_15`,progressBar:`_progressBar_1pldx_16`,empty:`_empty_1pldx_18`,task:`_task_1pldx_20`,taskDone:`_taskDone_1pldx_22`,check:`_check_1pldx_23`,checkDone:`_checkDone_1pldx_25`,desc:`_desc_1pldx_26`,del:`_del_1pldx_27`,badge:`_badge_1pldx_30`,badge_high:`_badge_high_1pldx_31`,badge_medium:`_badge_medium_1pldx_32`,badge_low:`_badge_low_1pldx_33`,doneLabel:`_doneLabel_1pldx_35`};function Et(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`medium`),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=()=>T(`/api/tasks`).then(e=>{n(e?.tasks??[]),i(!1)});(0,_.useEffect)(()=>{f()},[]);let p=async()=>{a.trim()&&(u(!0),await E(`/api/tasks`,{description:a.trim(),priority:s}),o(``),u(!1),f(),d.current?.focus())},m=e=>E(`/api/tasks/${e}/done`,{},`PATCH`).then(f),h=e=>E(`/api/tasks/${e}/delete`,{}).then(f),g=()=>E(`/api/tasks/clear`,{filter:`done`}).then(f),v=()=>{confirm(e(`tasks.deleteTask`))&&E(`/api/tasks/clear`,{filter:`all`}).then(f)},y=t.filter(e=>e.status!==`done`),b=t.filter(e=>e.status===`done`);return r?(0,k.jsxs)(`div`,{className:Tt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Tt.root,children:[(0,k.jsxs)(`div`,{className:Tt.bar,children:[(0,k.jsx)(`input`,{ref:d,className:Tt.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:Tt.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:Tt.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.actions,children:[(0,k.jsx)(`button`,{className:Tt.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:Tt.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:Tt.progress,children:(0,k.jsx)(`span`,{className:Tt.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:Tt.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:Tt.task,children:[(0,k.jsx)(`span`,{className:Tt.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Tt.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${Tt.task} ${Tt.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${Tt.check} ${Tt.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var z={root:`_root_k5v14_1`,loading:`_loading_k5v14_2`,card:`_card_k5v14_4`,cardTitle:`_cardTitle_k5v14_5`,cardTitleRow:`_cardTitleRow_k5v14_6`,cardSub:`_cardSub_k5v14_7`,connected:`_connected_k5v14_8`,statusMsg:`_statusMsg_k5v14_9`,fields:`_fields_k5v14_11`,field:`_field_k5v14_11`,fieldLabel:`_fieldLabel_k5v14_13`,fieldInput:`_fieldInput_k5v14_14`,saveBtn:`_saveBtn_k5v14_17`,dangerBtn:`_dangerBtn_k5v14_18`,cancelBtn:`_cancelBtn_k5v14_19`,btnRow:`_btnRow_k5v14_20`,keySet:`_keySet_k5v14_22`,keySummary:`_keySummary_k5v14_23`,keySummaryIcon:`_keySummaryIcon_k5v14_24`,nhaFree:`_nhaFree_k5v14_26`,nhaFreeTitle:`_nhaFreeTitle_k5v14_27`,nhaFreeSub:`_nhaFreeSub_k5v14_28`,nhaFreeBtn:`_nhaFreeBtn_k5v14_29`,imapRow:`_imapRow_k5v14_31`,imapName:`_imapName_k5v14_32`,imapMeta:`_imapMeta_k5v14_33`,imapStatus:`_imapStatus_k5v14_34`,imapBtns:`_imapBtns_k5v14_38`,imapSyncBtn:`_imapSyncBtn_k5v14_39`,imapEditBtn:`_imapEditBtn_k5v14_40`,imapDelBtn:`_imapDelBtn_k5v14_41`,emptyImap:`_emptyImap_k5v14_42`,imapForm:`_imapForm_k5v14_44`,imapFormTitle:`_imapFormTitle_k5v14_45`,pwdNote:`_pwdNote_k5v14_46`,pwdRow:`_pwdRow_k5v14_47`,togglePwd:`_togglePwd_k5v14_48`},Dt={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function Ot({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:z.fieldInput})]})}function kt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),f=()=>{T(`/api/credentials`).then(e=>t(e?.credentials??[])).catch(()=>t([]))};(0,_.useEffect)(()=>{f()},[]);let p=async()=>{if(!/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(n)){d(`Name: lettere, cifre, _ — primo carattere non numerico`);return}if(!i.trim()){d(`Value required`);return}l(!0),d(``);try{let e=await E(`/api/credentials`,{name:n,value:i,description:o});e&&!e.ok&&e.error?d(e.error):(r(``),a(``),s(``),f())}finally{l(!1)}},m=async e=>{confirm(`Delete credential "${e}"?`)&&(await fetch(`/api/credentials/${encodeURIComponent(e)}`,{method:`DELETE`}),f())};return(0,k.jsxs)(`div`,{style:{marginTop:16,padding:16,background:`var(--bg2, rgba(15,23,42,0.4))`,border:`1px solid var(--border, rgba(148,163,184,0.18))`,borderRadius:10},children:[(0,k.jsx)(`div`,{style:{fontSize:14,fontWeight:800,marginBottom:4},children:`Credentials Vault 🔐`}),(0,k.jsxs)(`div`,{style:{fontSize:11,opacity:.7,marginBottom:10},children:[`Encrypted secrets (AES-256-GCM, machine-bound key). Reference them in workflow nodes with `,(0,k.jsx)(`code`,{children:"${cred.NAME}"}),`. The raw value never leaves your computer.`]}),e.length>0&&(0,k.jsx)(`div`,{style:{marginBottom:12,border:`1px solid rgba(148,163,184,0.15)`,borderRadius:6},children:e.map(e=>(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 10px`,borderBottom:`1px solid rgba(148,163,184,0.1)`,fontSize:12},children:[(0,k.jsx)(`code`,{style:{background:`rgba(99,102,241,0.12)`,padding:`2px 6px`,borderRadius:4,color:`#a5b4fc`,fontWeight:700},children:e.name}),(0,k.jsx)(`span`,{style:{flex:1,opacity:.7},children:e.description||(0,k.jsx)(`em`,{children:`no description`})}),(0,k.jsx)(`span`,{style:{fontSize:10,opacity:.5},children:new Date(e.updatedAt).toLocaleString()}),e.hasError&&(0,k.jsx)(`span`,{style:{color:`#ef4444`,fontSize:10},children:`⚠ decrypt error`}),(0,k.jsx)(`button`,{onClick:()=>m(e.name),style:{background:`transparent`,border:`none`,cursor:`pointer`,color:`#ef4444`,fontSize:14},children:`✕`})]},e.name))}),(0,k.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:8},children:[(0,k.jsx)(`input`,{placeholder:`NAME (e.g. STRIPE_KEY)`,value:n,onChange:e=>r(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontFamily:`SF Mono, monospace`}}),(0,k.jsx)(`input`,{placeholder:`Description (optional)`,value:o,onChange:e=>s(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}})]}),(0,k.jsx)(`input`,{type:`password`,placeholder:`Value (encrypted at rest)`,value:i,onChange:e=>a(e.target.value),style:{width:`100%`,marginTop:6,padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}}),u&&(0,k.jsx)(`div`,{style:{color:`#ef4444`,fontSize:11,marginTop:4},children:u}),(0,k.jsx)(`button`,{onClick:p,disabled:c,style:{marginTop:8,padding:`6px 14px`,borderRadius:4,border:`none`,background:`#6366f1`,color:`white`,fontWeight:700,cursor:`pointer`,opacity:c?.5:1},children:c?`Saving…`:`+ Add credential`})]})}function At(){let{setConfig:e}=ne(),t=j(),[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)({name:``,email:``,phone:``,homeAddress:``,workAddress:``,city:``,country:``,company:``,role:``,notes:``}),[C,w]=(0,_.useState)(`nha`),[ee,te]=(0,_.useState)(``),[re,D]=(0,_.useState)(``),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[oe,se]=(0,_.useState)(``),[ce,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[M,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(!1),[_e,ve]=(0,_.useState)(``),[ye,be]=(0,_.useState)(`en`),[xe,Se]=(0,_.useState)(`07:00`),[N,Ce]=(0,_.useState)(`18:00`),[we,Te]=(0,_.useState)(`30`),[Ee,P]=(0,_.useState)(`off`),[De,Oe]=(0,_.useState)(``),[ke,F]=(0,_.useState)(``),[I,Ae]=(0,_.useState)(``),[je,Me]=(0,_.useState)(`agent`),[Ne,Pe]=(0,_.useState)(``),[Fe,Ie]=(0,_.useState)(!0),[Le,Re]=(0,_.useState)(!0),[ze,L]=(0,_.useState)(`3`),[Be,Ve]=(0,_.useState)(`0.30`),[He,Ue]=(0,_.useState)(!0),[We,Ge]=(0,_.useState)(!1),[Ke,qe]=(0,_.useState)(!1),[Je,Ye]=(0,_.useState)(!1),[Xe,Ze]=(0,_.useState)(!1),[Qe,$e]=(0,_.useState)(!1),[et,tt]=(0,_.useState)(!1),[nt,rt]=(0,_.useState)(!0),[it,at]=(0,_.useState)(``),[ot,st]=(0,_.useState)(!1),[ct,lt]=(0,_.useState)(!1),[ut,dt]=(0,_.useState)(!0),[ft,pt]=(0,_.useState)(``),[mt,ht]=(0,_.useState)(``),[gt,_t]=(0,_.useState)(``),[vt,yt]=(0,_.useState)(``),[R,bt]=(0,_.useState)(`common`),[xt,St]=(0,_.useState)(!1),[Ct,wt]=(0,_.useState)(``);(0,_.useEffect)(()=>{T(`/api/config`).then(t=>{r(t??{});let n=t?.profile??{};S({name:n.name??``,email:n.email??``,phone:n.phone??``,homeAddress:n.homeAddress??``,workAddress:n.workAddress??``,city:n.city??``,country:n.country??``,company:n.company??``,role:n.role??``,notes:n.notes??``}),w(t?.provider??`nha`),ve(t?.model??``),be(t?.lang??`en`),Se(t?.planTime??`07:00`),Ce(t?.summaryTime??`18:00`),Te(String(t?.meetingAlert??`30`)),P(t?.thinking??`off`),te(``);let i=t?.responder,o=i?.telegram;Ae(String(o?.botName??``));let s=String(o?.personaMode??`agent`);Me(s===`persona`||s===`persona-only`||s===`persona+role`?s:`agent`),Pe(Array.isArray(o?.allowedChatIds)?o.allowedChatIds.join(`, `):``),Ie(i?.autoRoute!==!1);let c=t?.deliberation;Re(c?.enabled!==!1),L(String(c?.rounds??`3`)),Ve(String(c?.convergence??`0.30`)),Ue(c?.tribunalEnabled!==!1);let l=t?.ops?.proactive;Ge(!!l?.enabled),qe(!!l?.emailFollowUp),Ye(!!l?.meetingPrep),Ze(!!l?.patterns),$e(!!l?.deadlines);let u=t?.voice;tt(!!u?.preferWhisper),rt(u?.speechSynthesis!==!1),at(String(u?.language??``));let d=t?.features;st(!!d?.verbose),lt(!!d?.immersive),dt(d?.knowledgeEnabled!==!1),pt(``),ht(String(t?.github?.defaultRepo??``)),_t(``),yt(``);let f=t?.microsoft;bt(String(f?.tenantId??`common`));let p=t?.plugins;St(!!p?.autoRun),wt(String(p?.directory??``)),a(!1),t&&e(t)}),Tt()},[]);let Tt=()=>T(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),Et=async(e,t)=>{s(e),await E(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},At=()=>Et(`profile`,x),jt=()=>{Et(`provider`,C),Et(`model`,_e),Et(`thinking`,Ee),ee&&Et(`key`,ee),re&&Et(`groq-key`,re),ie&&Et(`openai-key`,ie),ae&&Et(`gemini-key`,ae),oe&&Et(`deepseek-key`,oe),ce&&Et(`grok-key`,ce),ue&&Et(`mistral-key`,ue),M&&Et(`cohere-key`,M),pe&&Et(`openrouter-key`,pe)},Mt=()=>{Et(`planTime`,xe),Et(`summaryTime`,N),Et(`meetingAlert`,Number(we))},B=()=>{v(t(`settings.googleOpening`)),E(`/api/google/auth`,{}).then(e=>{e?.url?(window.open(e.url,`_blank`),v(t(`settings.googleOpened`))):e?.error&&v(t(`common.error`)+`: `+e.error)}).catch(e=>v(t(`common.error`)+`: `+e.message))},Nt=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&E(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},Pt=()=>{if(!f)return;let e=!!f.id,t={display_name:f.display_name,email_address:f.email_address,from_name:f.from_name,imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username};f.password&&(t.password=f.password),e&&(t.id=f.id),h(`Saving…`),E(e?`/api/imap/accounts/update`:`/api/imap/accounts`,t).then(e=>{e?.ok||e?.id?(h(`Saved!`),p(null),Tt()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},Ft=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&E(`/api/imap/accounts/delete`,{id:e}).then(()=>Tt())},It=e=>{E(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(Tt,3e3))},Lt=async()=>{if(f){if(!f.imap_host||!f.imap_port){h(`⚠ Inserisci prima host e porta IMAP.`);return}h(`Diagnostica porta IMAP in corso…`);try{let e=await E(`/api/imap/probe`,{imap_host:f.imap_host,imap_port:Number(f.imap_port)});e?.ok?h(`✓ ${f.imap_host}:${f.imap_port} risponde\n${e.message}${e.banner?`\n\nBanner: ${e.banner}`:``}`):h(`✗ ${f.imap_host}:${f.imap_port} non risponde\n${e?.message??e?.error??`errore sconosciuto`}`)}catch(e){h(`✗ Diagnostica fallita: ${e.message}`)}}},Rt=async e=>{if(!f)return;if(!f.password&&!f.id){h(`⚠ Inserisci la password prima di testare.`);return}h(e?`Invio email di prova…`:`Test connessione in corso…`);let t={imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username,password:f.password,email_address:f.email_address,from_name:f.from_name,sendTest:e};try{let e=await E(`/api/imap/test`,t),n=e?.imap,r=e?.smtp,i=[];n?.ok?i.push(`✓ IMAP OK (TLS=${n.secure?`implicit`:`STARTTLS`}, ${n.folderCount??`?`} cartelle)`):i.push(`✗ IMAP errore: ${n?.error??`sconosciuto`}`),r?.ok?r.sent?i.push(`✓ SMTP OK — email di prova inviata a ${f.email_address} (id ${(r.messageId||``).slice(0,24)}…)`):i.push(`✓ SMTP OK (TLS=${r.secure?`implicit`:`STARTTLS`}, auth valida)`):i.push(`✗ SMTP errore: ${r?.error??`sconosciuto`}`),h(i.join(` · `))}catch(e){h(`✗ Test fallito: ${e.message}`)}};if(i)return(0,k.jsxs)(`div`,{className:z.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let zt=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:z.root,children:[(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:z.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:At,children:[zt(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:z.nhaFree,children:[(0,k.jsx)(`div`,{className:z.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:z.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:z.nhaFreeBtn,onClick:()=>{E(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),ve(``),te(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.llmProviderSub`)}),(()=>{let e=[];return n.hasApiKey&&e.push(`Anthropic`),n.hasOpenaiKey&&e.push(`OpenAI`),n.hasGeminiKey&&e.push(`Gemini`),n.hasDeepseekKey&&e.push(`DeepSeek`),n.hasGrokKey&&e.push(`Grok`),n.hasMistralKey&&e.push(`Mistral`),n.hasCohereKey&&e.push(`Cohere`),e.length===0?null:(0,k.jsxs)(`div`,{className:z.keySummary,children:[(0,k.jsx)(`span`,{className:z.keySummaryIcon,children:`🔑`}),(0,k.jsxs)(`span`,{children:[`Chiavi configurate: `,(0,k.jsx)(`strong`,{children:e.join(`, `)})]})]})})(),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`openrouter`,children:`OpenRouter (100+ models)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,openrouter:n.hasOpenrouterKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:z.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(Ot,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(Ot,{id:`groqKey`,label:`Groq Key (voice / Whisper)`,placeholder:n.hasGroqKey?`✓ configured — leave empty to keep`:`gsk_... (free at console.groq.com/keys) — enables Telegram voice transcription`,type:`password`,value:re,onChange:D}),(0,k.jsx)(`div`,{style:{marginTop:8,marginBottom:4},children:(0,k.jsxs)(`button`,{type:`button`,onClick:()=>ge(!he),style:{background:`transparent`,border:`none`,color:`var(--accent, #6366f1)`,cursor:`pointer`,fontSize:12,padding:0,fontWeight:600},children:[he?`▾`:`▸`,` Optional provider keys (OpenAI, OpenRouter, Gemini, DeepSeek, Grok, Mistral, Cohere)`]})}),he&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Ot,{id:`openaiKey`,label:`OpenAI Key`,placeholder:n.hasOpenaiKey?`✓ configured — leave empty to keep`:`sk-... (platform.openai.com)`,type:`password`,value:ie,onChange:O}),(0,k.jsx)(Ot,{id:`openrouterKey`,label:`OpenRouter Key (100+ models)`,placeholder:n.hasOpenrouterKey?`✓ configured — leave empty to keep`:`sk-or-v1-... (openrouter.ai/keys) — one key for Claude/GPT/Gemini/Llama/etc`,type:`password`,value:pe,onChange:me}),(0,k.jsx)(Ot,{id:`geminiKey`,label:`Gemini Key (Google)`,placeholder:n.hasGeminiKey?`✓ configured — leave empty to keep`:`AIza... (aistudio.google.com)`,type:`password`,value:ae,onChange:A}),(0,k.jsx)(Ot,{id:`deepseekKey`,label:`DeepSeek Key`,placeholder:n.hasDeepseekKey?`✓ configured — leave empty to keep`:`sk-... (platform.deepseek.com)`,type:`password`,value:oe,onChange:se}),(0,k.jsx)(Ot,{id:`grokKey`,label:`Grok Key (X.AI)`,placeholder:n.hasGrokKey?`✓ configured — leave empty to keep`:`xai-... (console.x.ai)`,type:`password`,value:ce,onChange:le}),(0,k.jsx)(Ot,{id:`mistralKey`,label:`Mistral Key`,placeholder:n.hasMistralKey?`✓ configured — leave empty to keep`:`... (console.mistral.ai)`,type:`password`,value:ue,onChange:de}),(0,k.jsx)(Ot,{id:`cohereKey`,label:`Cohere Key`,placeholder:n.hasCohereKey?`✓ configured — leave empty to keep`:`... (dashboard.cohere.com)`,type:`password`,value:M,onChange:fe})]}),(0,k.jsx)(Ot,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:_e,onChange:ve}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:Ee,onChange:e=>P(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:jt,children:[zt(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:ye,onChange:t=>{let r=t.target.value;be(r),Et(`lang`,r),e({...n,lang:r})},className:z.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(Ot,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:De,onChange:Oe}),(0,k.jsx)(Ot,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:ke,onChange:F}),(0,k.jsx)(Ot,{id:`botName`,label:`Bot Persona Name`,placeholder:`e.g. Agata — what name the bot uses when replying. Empty = show internal agent name (HERALD/ATHENA/...)`,value:I,onChange:Ae}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:`Persona display mode`}),(0,k.jsxs)(`select`,{value:je,onChange:e=>Me(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`agent`,children:`agent — show internal name [HERALD] (legacy/debug)`}),(0,k.jsx)(`option`,{value:`persona`,children:`persona — show [BotName] only (recommended)`}),(0,k.jsx)(`option`,{value:`persona-only`,children:`persona-only — no prefix at all (most natural)`}),(0,k.jsx)(`option`,{value:`persona+role`,children:`persona+role — [BotName · agent] (power users)`})]})]}),(0,k.jsx)(Ot,{id:`allowedChatIds`,label:`Allowed Chat IDs (Telegram)`,placeholder:`comma-separated numeric chat IDs (empty = anyone can chat with the bot)`,value:Ne,onChange:Pe}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Fe,onChange:e=>Ie(e.target.checked)}),` `,`Auto-route messages to specialist agents (recommended)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{De&&Et(`telegram-bot-token`,De),ke&&Et(`discord-bot-token`,ke),Et(`bot-name`,I),Et(`persona-mode`,je),Et(`responder.telegram.allowedChatIds`,Ne.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>Number(e)||e)),Et(`responder-auto-route`,Fe)},children:[zt(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(Ot,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:xe,onChange:Se}),(0,k.jsx)(Ot,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:N,onChange:Ce}),(0,k.jsx)(Ot,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:we,onChange:Te}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:Mt,children:[zt(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Deliberation (Geth Consensus)`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Multi-round inter-agent reasoning for higher-quality answers`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Le,onChange:e=>Re(e.target.checked)}),` `,`Enable deliberation`]})}),(0,k.jsx)(Ot,{id:`delibRounds`,label:`Rounds (1–5)`,placeholder:`3`,value:ze,onChange:L}),(0,k.jsx)(Ot,{id:`delibConvergence`,label:`Convergence threshold (0–1, lower = stricter)`,placeholder:`0.30`,value:Be,onChange:Ve}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:He,onChange:e=>Ue(e.target.checked)}),` `,`Tribunal (final HERALD mediation)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Et(`deliberation`,Le),Et(`rounds`,Number(ze)),Et(`convergence`,Number(Be)),Et(`tribunal`,He)},children:[zt(`deliberation`),` Save deliberation`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Proactive Intelligence`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`The bot acts on its own initiative (follow-ups, meeting prep, pattern detection)`}),[[`proactive`,`Master switch — enable proactive`,We,Ge],[`proactive-email`,`Email follow-up reminders`,Ke,qe],[`proactive-meeting`,`Meeting preparation digests`,Je,Ye],[`proactive-patterns`,`Behavioural pattern detection`,Xe,Ze],[`proactive-deadlines`,`Deadline tracking`,Qe,$e]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Et(`proactive`,We),Et(`proactive-email`,Ke),Et(`proactive-meeting`,Je),Et(`proactive-patterns`,Xe),Et(`proactive-deadlines`,Qe)},children:[zt(`proactive`),` Save proactive`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Voice`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Transcription (Whisper via Groq) and text-to-speech`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:et,onChange:e=>tt(e.target.checked)}),` `,`Prefer Whisper (Groq) over local STT`]})}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:nt,onChange:e=>rt(e.target.checked)}),` `,`Speech synthesis (read replies aloud)`]})}),(0,k.jsx)(Ot,{id:`voiceLanguage`,label:`Voice language (BCP 47, e.g. it-IT, en-US)`,placeholder:`empty = use UI language`,value:it,onChange:at}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Et(`voice-whisper`,et),Et(`voice-speech`,nt),it&&Et(`voice-language`,it)},children:[zt(`voice-whisper`),` Save voice`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Features`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Core behaviour toggles`}),[[`verbose`,`Verbose logging (more diagnostics, more tokens)`,ot,st],[`immersive`,`Immersive office scene animation in Studio`,ct,lt],[`knowledge`,`Knowledge base (memories + skills retrieval)`,ut,dt]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Et(`verbose`,ot),Et(`immersive`,ct),Et(`knowledge`,ut)},children:[zt(`verbose`),` Save features`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Integration tokens`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`GitHub, Notion, Slack — used by the corresponding tools`}),(0,k.jsx)(Ot,{id:`githubToken`,label:`GitHub Token (PAT)`,placeholder:n.hasGithubToken?`✓ configured — leave empty to keep`:`ghp_... — needs repo + read:org scopes`,type:`password`,value:ft,onChange:pt}),(0,k.jsx)(Ot,{id:`githubRepo`,label:`Default GitHub repo (owner/name)`,placeholder:`acme/website`,value:mt,onChange:ht}),(0,k.jsx)(Ot,{id:`notionToken`,label:`Notion Token (Internal Integration)`,placeholder:n.hasNotionToken?`✓ configured — leave empty to keep`:`secret_...`,type:`password`,value:gt,onChange:_t}),(0,k.jsx)(Ot,{id:`slackToken`,label:`Slack Bot Token (xoxb-)`,placeholder:n.hasSlackToken?`✓ configured — leave empty to keep`:`xoxb-...`,type:`password`,value:vt,onChange:yt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{ft&&Et(`github-token`,ft),mt&&Et(`github-repo`,mt),gt&&Et(`notion-token`,gt),vt&&Et(`slack-token`,vt)},children:[zt(`github-token`),` Save tokens`]})]}),(0,k.jsx)(kt,{}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Advanced`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Plugins, Microsoft tenant ID, runtime extras`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:xt,onChange:e=>St(e.target.checked)}),` `,`Auto-run plugins at startup`]})}),(0,k.jsx)(Ot,{id:`pluginDir`,label:`Plugin directory (absolute path)`,placeholder:`empty = ~/.nha/plugins`,value:Ct,onChange:wt}),(0,k.jsx)(Ot,{id:`microsoftTenant`,label:`Microsoft Tenant ID`,placeholder:`common (default) | organizations | consumers | <GUID>`,value:R,onChange:bt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Et(`plugin-autorun`,xt),Ct&&Et(`plugin-dir`,Ct),Et(`microsoft-tenant`,R)},children:[zt(`plugin-autorun`),` Save advanced`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:z.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:B,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:z.dangerBtn,onClick:Nt,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:z.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsxs)(`div`,{className:z.cardTitleRow,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:z.saveBtn,onClick:()=>{p({...Dt}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:z.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:z.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:z.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:z.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:z.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:z.imapBtns,children:[(0,k.jsx)(`button`,{className:z.imapSyncBtn,onClick:()=>It(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:z.imapEditBtn,onClick:()=>{p({...Dt,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:z.imapDelBtn,onClick:()=>Ft(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:z.imapForm,children:[(0,k.jsx)(`div`,{className:z.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:z.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:z.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:z.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:z.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:Pt,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>Rt(!1),title:`Verifica IMAP+SMTP senza inviare nulla`,children:`Test connessione`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>Rt(!0),title:`Invia un'email di prova alla tua casella per verificare il round-trip`,children:`Invia email di prova`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:Lt,title:`Diagnostica raw: mostra cosa risponde realmente il server sulla porta indicata`,children:`Diagnostica porta`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:z.statusMsg,style:{whiteSpace:`pre-line`},children:m})]})]})]})}var jt={root:`_root_o07ov_1`,loading:`_loading_o07ov_2`,err:`_err_o07ov_3`,header:`_header_o07ov_4`,title:`_title_o07ov_5`,addBtn:`_addBtn_o07ov_6`,empty:`_empty_o07ov_7`,card:`_card_o07ov_8`,cardToday:`_cardToday_o07ov_9`,icon:`_icon_o07ov_10`,info:`_info_o07ov_11`,name:`_name_o07ov_12`,date:`_date_o07ov_13`,labelToday:`_labelToday_o07ov_14`,labelTomorrow:`_labelTomorrow_o07ov_15`,labelFuture:`_labelFuture_o07ov_16`,editBtn:`_editBtn_o07ov_17`,delBtn:`_delBtn_o07ov_18`,overlay:`_overlay_o07ov_20`,modal:`_modal_o07ov_21`,modalTitle:`_modalTitle_o07ov_22`,label:`_label_o07ov_14`,input:`_input_o07ov_24`,hint:`_hint_o07ov_25`,formErr:`_formErr_o07ov_26`,modalBtns:`_modalBtns_o07ov_27`,cancelBtn:`_cancelBtn_o07ov_28`,saveBtn:`_saveBtn_o07ov_29`};function Mt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(()=>{i(!0),T(`/api/birthdays`).then(e=>{e?.error?o(e.error):n(e?.birthdays??[]),i(!1)})},[]);(0,_.useEffect)(()=>{p()},[p]);let m=()=>{c({name:``,date:``}),u(``)},h=e=>{c({name:e.name,date:e.date,contactId:e.contactId}),u(``)},g=async()=>{if(!s)return;if(!s.name.trim()){u(`Name is required`);return}if(!s.date.trim()){u(`Date is required`);return}f(!0);let e=s.date;/^\d{2}-\d{2}$/.test(e)&&(e=`${new Date().getFullYear()}-${e}`),await E(`/api/birthdays`,{name:s.name,date:e,contactId:s.contactId??null,edit:!!s.contactId}),f(!1),c(null),p()},v=e=>{confirm(`Remove birthday for ${e.name}?`)&&E(`/api/birthdays/delete`,{contactId:e.contactId}).then(p)};return r?(0,k.jsxs)(`div`,{className:jt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:jt.err,children:a}):(0,k.jsxs)(`div`,{className:jt.root,children:[(0,k.jsxs)(`div`,{className:jt.header,children:[(0,k.jsx)(`div`,{className:jt.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:jt.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:jt.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${jt.card} ${r?jt.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:jt.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:jt.info,children:[(0,k.jsx)(`div`,{className:jt.name,children:t.name}),(0,k.jsx)(`div`,{className:jt.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?jt.labelToday:i?jt.labelTomorrow:jt.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:jt.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:jt.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:jt.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:jt.modal,children:[(0,k.jsx)(`div`,{className:jt.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:jt.label,children:`Name *`}),(0,k.jsx)(`input`,{className:jt.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:jt.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:jt.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:jt.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:jt.formErr,children:l}),(0,k.jsxs)(`div`,{className:jt.modalBtns,children:[(0,k.jsx)(`button`,{className:jt.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:jt.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var B={root:`_root_1z04o_1`,header:`_header_1z04o_3`,title:`_title_1z04o_4`,subtitle:`_subtitle_1z04o_5`,code:`_code_1z04o_6`,addBtn:`_addBtn_1z04o_8`,tabs:`_tabs_1z04o_10`,tab:`_tab_1z04o_10`,tabActive:`_tabActive_1z04o_12`,loading:`_loading_1z04o_14`,err:`_err_1z04o_15`,empty:`_empty_1z04o_17`,emptyIcon:`_emptyIcon_1z04o_18`,emptyTitle:`_emptyTitle_1z04o_19`,emptySub:`_emptySub_1z04o_20`,card:`_card_1z04o_23`,cardDisabled:`_cardDisabled_1z04o_24`,cardTop:`_cardTop_1z04o_25`,cardLeft:`_cardLeft_1z04o_26`,jobName:`_jobName_1z04o_27`,schedule:`_schedule_1z04o_28`,agentBadge:`_agentBadge_1z04o_29`,statusBadge:`_statusBadge_1z04o_30`,statusActive:`_statusActive_1z04o_31`,statusPaused:`_statusPaused_1z04o_32`,jobPrompt:`_jobPrompt_1z04o_33`,jobMeta:`_jobMeta_1z04o_34`,cardActions:`_cardActions_1z04o_35`,runBtn:`_runBtn_1z04o_36`,editBtn:`_editBtn_1z04o_37`,pauseBtn:`_pauseBtn_1z04o_38`,resumeBtn:`_resumeBtn_1z04o_39`,delBtn:`_delBtn_1z04o_40`,templates:`_templates_1z04o_43`,templatesNote:`_templatesNote_1z04o_44`,templateCard:`_templateCard_1z04o_45`,templateLabel:`_templateLabel_1z04o_46`,templatePrompt:`_templatePrompt_1z04o_47`,templateBtns:`_templateBtns_1z04o_48`,scheduleTplBtn:`_scheduleTplBtn_1z04o_49`,runTplBtn:`_runTplBtn_1z04o_50`,formOverlay:`_formOverlay_1z04o_54`,formModal:`_formModal_1z04o_55`,formTitle:`_formTitle_1z04o_56`,label:`_label_1z04o_57`,input:`_input_1z04o_58`,textarea:`_textarea_1z04o_59`,presets:`_presets_1z04o_61`,preset:`_preset_1z04o_61`,presetActive:`_presetActive_1z04o_63`,cronHints:`_cronHints_1z04o_65`,cronHint:`_cronHint_1z04o_65`,formErr:`_formErr_1z04o_70`,formOk:`_formOk_1z04o_71`,formBtns:`_formBtns_1z04o_72`,cancelBtn:`_cancelBtn_1z04o_73`,saveBtn:`_saveBtn_1z04o_74`},Nt=[{label:`Every 15 min`,value:`every 15 minutes`},{label:`Every 30 min`,value:`every 30 minutes`},{label:`Every hour`,value:`every hour`},{label:`Every 6h`,value:`every 6 hours`},{label:`Daily 8am`,value:`every day at 08:00`},{label:`Daily 9am`,value:`every day at 09:00`},{label:`Daily noon`,value:`every day at 12:00`},{label:`Daily 6pm`,value:`every day at 18:00`},{label:`Mon–Fri 9am`,value:`weekdays at 09:00`},{label:`Every Monday`,value:`every monday at 09:00`}],Pt=[{label:`🌅 Morning Briefing`,prompt:`Summarize my unread emails from the last 12 hours, check today's calendar events, list my top 3 priority tasks, and give me a focused action plan for the day.`},{label:`🌆 Evening Review`,prompt:`Review what I accomplished today: check completed tasks, summarize any important emails received, flag unresolved issues, and prepare a priority list for tomorrow.`},{label:`📰 News Digest`,prompt:`Search for the top AI, tech, and finance news from the last 24 hours. Summarize the 5 most important stories with key takeaways and market implications.`},{label:`📈 Market Update`,prompt:`Provide a comprehensive market update: macro environment, major indices performance, top movers, notable events, and key levels to watch. Use herald and mercury agents.`},{label:`🐙 GitHub Monitor`,prompt:`Check my GitHub notifications, summarize open issues and pull requests that need attention, and draft brief responses for the most urgent ones.`},{label:`📊 Weekly Report`,prompt:`Generate a weekly productivity report: tasks completed vs pending, email response rate, upcoming calendar events, and 3 strategic priorities for next week.`},{label:`🔒 Security Scan`,prompt:`Run a security awareness check: scan recent code commits for potential vulnerabilities, check dependency alerts, and summarize any security-related GitHub notifications.`},{label:`🎯 Goal Tracker`,prompt:`Review my tasks and notes for goal progress. Identify what's on track, what's at risk, and suggest one concrete action to unblock the most important goal.`}],Ft=[{label:`0 9 * * 1-5`,desc:`Mon–Fri at 9:00 AM`},{label:`0 */6 * * *`,desc:`Every 6 hours`},{label:`*/30 * * * *`,desc:`Every 30 minutes`},{label:`0 8 * * *`,desc:`Daily at 8:00 AM`},{label:`0 20 * * 5`,desc:`Every Friday at 8 PM`}];function It(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({name:``,schedule:``,prompt:``,agent:``}),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(`jobs`),C=()=>{a(!0),T(`/api/cron`).then(e=>{e?.error?s(e.error):r(e?.jobs??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{C()},[]);let w=()=>{d({name:``,schedule:``,prompt:``,agent:``}),h(``),v(``),b(null),l(!0)},ee=e=>{d({name:e.name??``,schedule:e.schedule,prompt:e.prompt??e.command??``,agent:e.agent??``}),h(``),v(``),b(e.id),l(!0)},te=async()=>{if(!u.schedule.trim()){h(`Schedule is required`);return}if(!u.prompt.trim()){h(`Task prompt is required`);return}p(!0),h(``);try{y?await E(`/api/cron/update`,{id:y,schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}):await E(`/api/cron`,{schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}),v(y?`Updated!`:`Job scheduled!`),setTimeout(()=>{v(``),l(!1)},1500),C()}catch(e){h(e.message??`Failed`)}p(!1)},re=(e,t)=>E(`/api/cron/toggle`,{id:e,enabled:!t}).then(C),D=e=>{confirm(`Delete this scheduled task?`)&&E(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:B.root,children:[(0,k.jsxs)(`div`,{className:B.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:B.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:B.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:B.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:B.tabs,children:[(0,k.jsxs)(`button`,{className:`${B.tab} ${x===`jobs`?B.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${B.tab} ${x===`templates`?B.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:B.templates,children:[(0,k.jsx)(`div`,{className:B.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),Pt.map(t=>(0,k.jsxs)(`div`,{className:B.templateCard,children:[(0,k.jsx)(`div`,{className:B.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:B.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:B.templateBtns,children:[(0,k.jsx)(`button`,{className:B.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:B.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:B.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:B.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:B.empty,children:[(0,k.jsx)(`div`,{className:B.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:B.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:B.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${B.card} ${e.enabled?``:B.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:B.cardTop,children:[(0,k.jsxs)(`div`,{className:B.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:B.jobName,children:e.name}),(0,k.jsx)(`code`,{className:B.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:B.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${B.statusBadge} ${e.enabled?B.statusActive:B.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:B.cardActions,children:[(0,k.jsx)(`button`,{className:B.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:B.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?B.pauseBtn:B.resumeBtn,onClick:()=>re(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:B.delBtn,onClick:()=>D(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:B.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:B.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:B.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:B.formModal,children:[(0,k.jsx)(`div`,{className:B.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:B.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:B.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:B.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:B.presets,children:Nt.map(e=>(0,k.jsx)(`button`,{className:`${B.preset} ${u.schedule===e.value?B.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:B.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:B.cronHints,children:Ft.map(e=>(0,k.jsxs)(`span`,{className:B.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:B.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:B.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:B.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:B.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:B.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:B.formOk,children:g}),(0,k.jsxs)(`div`,{className:B.formBtns,children:[(0,k.jsx)(`button`,{className:B.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:B.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var Lt={root:`_root_1npv7_1`,loading:`_loading_1npv7_2`,sidebar:`_sidebar_1npv7_4`,newBtn:`_newBtn_1npv7_5`,empty:`_empty_1npv7_6`,noteItem:`_noteItem_1npv7_8`,noteItemActive:`_noteItemActive_1npv7_10`,noteTitle:`_noteTitle_1npv7_11`,noteMeta:`_noteMeta_1npv7_12`,notePreview:`_notePreview_1npv7_13`,noteTags:`_noteTags_1npv7_14`,noteTag:`_noteTag_1npv7_14`,editor:`_editor_1npv7_17`,emptyEditor:`_emptyEditor_1npv7_18`,titleInput:`_titleInput_1npv7_19`,contentArea:`_contentArea_1npv7_21`,editorFooter:`_editorFooter_1npv7_22`,delNoteBtn:`_delNoteBtn_1npv7_23`,cancelBtn:`_cancelBtn_1npv7_24`,saveBtn:`_saveBtn_1npv7_25`};function Rt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),h=()=>T(`/api/notes`).then(e=>{n(e?.notes??[]),i(!1)});(0,_.useEffect)(()=>{h()},[]);let g=e=>{o(e),c(e.title),u(e.content),m(!1)},v=()=>{o(null),c(``),u(``),m(!0)},y=async()=>{f(!0),p?await E(`/api/notes`,{title:s||`Untitled`,content:l}):a&&await E(`/api/notes/${a.id}`,{title:s,content:l}),f(!1),m(!1),h()},b=(e,t)=>{confirm(`Delete note "${t}"?`)&&E(`/api/notes/${e}/delete`,{}).then(h)};return r?(0,k.jsxs)(`div`,{className:Lt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Lt.root,children:[(0,k.jsxs)(`div`,{className:Lt.sidebar,children:[(0,k.jsx)(`button`,{className:Lt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:Lt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${Lt.noteItem} ${a?.id===e.id?Lt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:Lt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:Lt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:Lt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:Lt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:Lt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:Lt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:Lt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:Lt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:Lt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:Lt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:Lt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Lt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:Lt.emptyEditor,children:`Select a note or create a new one`})})]})}var zt={root:`_root_18yos_1`,loading:`_loading_18yos_2`,error:`_error_18yos_3`,toolbar:`_toolbar_18yos_5`,search:`_search_18yos_6`,addBtn:`_addBtn_18yos_7`,count:`_count_18yos_10`,empty:`_empty_18yos_12`,grid:`_grid_18yos_14`,card:`_card_18yos_16`,actions:`_actions_18yos_29`,avatar:`_avatar_18yos_31`,avatarImg:`_avatarImg_18yos_38`,info:`_info_18yos_40`,name:`_name_18yos_41`,row:`_row_18yos_42`,email:`_email_18yos_43`,phone:`_phone_18yos_44`,company:`_company_18yos_45`,birthday:`_birthday_18yos_46`,iconBtn:`_iconBtn_18yos_52`,iconBtnRed:`_iconBtnRed_18yos_58`,overlay:`_overlay_18yos_61`,modal:`_modal_18yos_62`,modalTitle:`_modalTitle_18yos_63`,field:`_field_18yos_64`,label:`_label_18yos_65`,input:`_input_18yos_66`,formStatus:`_formStatus_18yos_67`,formError:`_formError_18yos_68`,modalBtns:`_modalBtns_18yos_69`,cancelBtn:`_cancelBtn_18yos_70`,saveBtn:`_saveBtn_18yos_71`},Bt={name:``,email:``,phone:``,company:``,address:``,notes:``};function Vt(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(e=``)=>{T(e?`/api/contacts?q=${encodeURIComponent(e)}`:`/api/contacts`).then(e=>{r(e?.contacts??[]),a(!1),s(``)}).catch(()=>{s(`Could not load contacts. Run nha google revoke then nha google auth.`),a(!1)})};(0,_.useEffect)(()=>{b()},[]);let x=e=>{l(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>b(e),400)},S=()=>{d(null),p({...Bt}),v(``)},C=e=>{d(e),p({name:e.name,email:e.email??``,phone:e.phone??``,company:e.company??``,address:e.address??``,notes:e.notes??``}),v(``)},w=async()=>{if(f?.name){h(!0),v(`Saving…`);try{if(u?.resourceName){let e=await E(`/api/contacts/update`,{resourceName:u.resourceName,fields:f});if(e?.error){v(`Error: `+e.error);return}}else if(u)await E(`/api/contacts/update`,{resourceName:u.id,fields:f});else{let e=await E(`/api/contacts`,f);if(e?.error){v(`Error: `+e.error);return}}v(`Saved!`),setTimeout(()=>{p(null),d(null),b(c)},800)}catch(e){v(`Error: `+e.message)}finally{h(!1)}}},ee=(e,t)=>{e.stopPropagation(),confirm(`Delete "${t.name}"?`)&&E(`/api/contacts/delete`,{resourceName:t.resourceName||t.id}).then(e=>{let t=e;if(t?.error){alert(`Error: `+t.error);return}b(c)})},te=(e,n,r)=>{e.stopPropagation(),t(`chat`),setTimeout(()=>{let e=document.getElementById(`chatInput`);e&&(e.value=`Send an email to ${r} (${n}) about `,e.focus())},300)},re=e=>(e||`?`).split(` `).map(e=>e[0]).slice(0,2).join(``).toUpperCase();return i?(0,k.jsxs)(`div`,{className:zt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:zt.error,children:o}):(0,k.jsxs)(`div`,{className:zt.root,children:[(0,k.jsxs)(`div`,{className:zt.toolbar,children:[(0,k.jsx)(`input`,{className:zt.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:zt.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:zt.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:zt.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:zt.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:zt.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:zt.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:zt.avatarImg}):re(e.name)}),(0,k.jsxs)(`div`,{className:zt.info,children:[(0,k.jsx)(`div`,{className:zt.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:zt.row,children:[e.email&&(0,k.jsx)(`span`,{className:zt.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:zt.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:zt.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:zt.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:zt.actions,children:[e.email&&(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${zt.iconBtn} ${zt.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:zt.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:zt.modal,children:[(0,k.jsx)(`div`,{className:zt.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:zt.field,children:[(0,k.jsx)(`label`,{className:zt.label,children:t}),(0,k.jsx)(`input`,{className:zt.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?zt.formError:zt.formStatus,children:g}),(0,k.jsxs)(`div`,{className:zt.modalBtns,children:[(0,k.jsx)(`button`,{className:zt.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:zt.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}function Ht({open:e,onClose:t,children:n,className:r,handleClassName:i,backdropClassName:a,closeOnBackdrop:o=!0,ariaLabel:s}){let c=(0,_.useRef)(null),[l,u]=(0,_.useState)(0),d=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),(0,_.useEffect)(()=>{e||u(0)},[e]),e?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:a,onClick:o?t:void 0,style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.55)`,zIndex:29}}),(0,k.jsxs)(`div`,{ref:c,className:r,role:`dialog`,"aria-modal":`true`,"aria-label":s,style:{transform:`translateY(${l}px)`,transition:l===0?`transform 0.2s ease`:`none`},children:[(0,k.jsx)(`div`,{className:i,onTouchStart:e=>{d.current=e.touches[0].clientY},onTouchMove:e=>{if(d.current==null)return;let t=e.touches[0].clientY-d.current;t>0&&u(t)},onTouchEnd:()=>{l>80&&t(),u(0),d.current=null}}),n]})]}):null}function Ut(e=768){let[t,n]=(0,_.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(max-width: ${e}px)`).matches);return(0,_.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(`(max-width: ${e}px)`),r=e=>n(e.matches);return typeof t.addEventListener==`function`?(t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)):(t.addListener(r),()=>t.removeListener(r))},[e]),t}var V={root:`_root_b07pi_2`,topbar:`_topbar_b07pi_11`,topbarLeft:`_topbarLeft_b07pi_20`,topbarTitle:`_topbarTitle_b07pi_21`,topbarSub:`_topbarSub_b07pi_22`,topbarActions:`_topbarActions_b07pi_23`,runBtn:`_runBtn_b07pi_25`,runBtnActive:`_runBtnActive_b07pi_32`,logBtn:`_logBtn_b07pi_34`,newWfBtn:`_newWfBtn_b07pi_41`,body:`_body_b07pi_50`,sidebar:`_sidebar_b07pi_53`,sidebarTitle:`_sidebarTitle_b07pi_61`,sidebarEmpty:`_sidebarEmpty_b07pi_65`,wfItem:`_wfItem_b07pi_67`,wfItemActive:`_wfItemActive_b07pi_78`,wfItemRow:`_wfItemRow_b07pi_79`,wfItemName:`_wfItemName_b07pi_80`,wfItemMeta:`_wfItemMeta_b07pi_81`,wfOn:`_wfOn_b07pi_82`,wfOff:`_wfOff_b07pi_83`,wfDelBtn:`_wfDelBtn_b07pi_84`,canvasArea:`_canvasArea_b07pi_96`,canvasHeader:`_canvasHeader_b07pi_98`,wfNameInput:`_wfNameInput_b07pi_103`,canvasHint:`_canvasHint_b07pi_110`,portHint:`_portHint_b07pi_111`,connectHint:`_connectHint_b07pi_112`,cancelConnectBtn:`_cancelConnectBtn_b07pi_113`,canvas:`_canvas_b07pi_96`,canvasConnecting:`_canvasConnecting_b07pi_126`,canvasSvg:`_canvasSvg_b07pi_128`,canvasNode:`_canvasNode_b07pi_138`,canvasNodeSelected:`_canvasNodeSelected_b07pi_156`,canvasNodeConnecting:`_canvasNodeConnecting_b07pi_157`,nodeIcon:`_nodeIcon_b07pi_159`,nodeLabel:`_nodeLabel_b07pi_160`,nodeConfigPreview:`_nodeConfigPreview_b07pi_161`,nodeDelBtn:`_nodeDelBtn_b07pi_163`,portOut:`_portOut_b07pi_175`,portActive:`_portActive_b07pi_186`,portIn:`_portIn_b07pi_188`,pulse:`_pulse_b07pi_1`,canvasDrop:`_canvasDrop_b07pi_199`,canvasEmpty:`_canvasEmpty_b07pi_207`,canvasEmptyIcon:`_canvasEmptyIcon_b07pi_212`,canvasEmptyTitle:`_canvasEmptyTitle_b07pi_213`,canvasEmptyDesc:`_canvasEmptyDesc_b07pi_214`,logPanel:`_logPanel_b07pi_217`,logHeader:`_logHeader_b07pi_224`,logTime:`_logTime_b07pi_230`,logClose:`_logClose_b07pi_231`,logEmpty:`_logEmpty_b07pi_232`,logStep:`_logStep_b07pi_233`,logStepError:`_logStepError_b07pi_234`,logStepHeader:`_logStepHeader_b07pi_235`,logStepIcon:`_logStepIcon_b07pi_236`,logStepLabel:`_logStepLabel_b07pi_237`,logStepErrBadge:`_logStepErrBadge_b07pi_238`,logStepErr:`_logStepErr_b07pi_234`,logStepOutput:`_logStepOutput_b07pi_240`,rightPanel:`_rightPanel_b07pi_245`,configPanel:`_configPanel_b07pi_256`,configHeader:`_configHeader_b07pi_257`,configClose:`_configClose_b07pi_258`,configDesc:`_configDesc_b07pi_259`,configFields:`_configFields_b07pi_260`,configField:`_configField_b07pi_260`,configLabel:`_configLabel_b07pi_262`,configRequired:`_configRequired_b07pi_263`,configInput:`_configInput_b07pi_264`,configTextarea:`_configTextarea_b07pi_271`,zoomControls:`_zoomControls_b07pi_281`,configHint:`_configHint_b07pi_307`,configDelete:`_configDelete_b07pi_309`,palette:`_palette_b07pi_313`,paletteTitle:`_paletteTitle_b07pi_314`,paletteTabs:`_paletteTabs_b07pi_315`,paletteTab:`_paletteTab_b07pi_315`,paletteTabActive:`_paletteTabActive_b07pi_321`,paletteNodes:`_paletteNodes_b07pi_322`,paletteDef:`_paletteDef_b07pi_324`,paletteDefIcon:`_paletteDefIcon_b07pi_332`,paletteDefLabel:`_paletteDefLabel_b07pi_333`,paletteDefDesc:`_paletteDefDesc_b07pi_334`,paletteFooter:`_paletteFooter_b07pi_336`,paletteGuide:`_paletteGuide_b07pi_340`,guideTitle:`_guideTitle_b07pi_348`,guideStep:`_guideStep_b07pi_357`,guideNum:`_guideNum_b07pi_365`,guideTip:`_guideTip_b07pi_381`,guideCode:`_guideCode_b07pi_392`,nodeListMobile:`_nodeListMobile_b07pi_436`,nodeRow:`_nodeRow_b07pi_444`,nodeRowIcon:`_nodeRowIcon_b07pi_457`,nodeRowBody:`_nodeRowBody_b07pi_463`,nodeRowLabel:`_nodeRowLabel_b07pi_467`,nodeRowDesc:`_nodeRowDesc_b07pi_473`,nodeRowIndex:`_nodeRowIndex_b07pi_480`,nodeRowBranch:`_nodeRowBranch_b07pi_488`,configSheet:`_configSheet_b07pi_496`,configSheetHandle:`_configSheetHandle_b07pi_509`,runFab:`_runFab_b07pi_519`,debuggerPanel:`_debuggerPanel_b07pi_548`,dbgHeader:`_dbgHeader_b07pi_564`,dbgTimeline:`_dbgTimeline_b07pi_565`,dbgWatcher:`_dbgWatcher_b07pi_566`,dbgEmpty:`_dbgEmpty_b07pi_567`,dbgInspector:`_dbgInspector_b07pi_563`,dbgHeaderLeft:`_dbgHeaderLeft_b07pi_591`,dbgHeaderRight:`_dbgHeaderRight_b07pi_600`,dbgTitle:`_dbgTitle_b07pi_609`,dbgRunSelect:`_dbgRunSelect_b07pi_610`,dbgStats:`_dbgStats_b07pi_619`,dbgPausedBadge:`_dbgPausedBadge_b07pi_620`,dbgPulse:`_dbgPulse_b07pi_1`,dbgBtnResume:`_dbgBtnResume_b07pi_634`,dbgBtnReplay:`_dbgBtnReplay_b07pi_634`,dbgTlStep:`_dbgTlStep_b07pi_673`,dbgTlStepOk:`_dbgTlStepOk_b07pi_691`,dbgTlStepErr:`_dbgTlStepErr_b07pi_692`,dbgTlStepPaused:`_dbgTlStepPaused_b07pi_693`,dbgTlStepActive:`_dbgTlStepActive_b07pi_694`,dbgTlIcon:`_dbgTlIcon_b07pi_699`,dbgTlLabel:`_dbgTlLabel_b07pi_700`,dbgTlMs:`_dbgTlMs_b07pi_708`,dbgInspHeader:`_dbgInspHeader_b07pi_719`,dbgInspLabel:`_dbgInspLabel_b07pi_729`,dbgInspIcon:`_dbgInspIcon_b07pi_738`,dbgInspDuration:`_dbgInspDuration_b07pi_739`,dbgInspActions:`_dbgInspActions_b07pi_747`,dbgBtnExplain:`_dbgBtnExplain_b07pi_755`,dbgBtnReplayFrom:`_dbgBtnReplayFrom_b07pi_767`,dbgBtnBp:`_dbgBtnBp_b07pi_778`,dbgBtnBpActive:`_dbgBtnBpActive_b07pi_787`,dbgBpGroup:`_dbgBpGroup_b07pi_792`,dbgBpCondition:`_dbgBpCondition_b07pi_800`,dbgExplanation:`_dbgExplanation_b07pi_820`,dbgExplanationIcon:`_dbgExplanationIcon_b07pi_833`,dbgExplanationText:`_dbgExplanationText_b07pi_834`,dbgTabs:`_dbgTabs_b07pi_836`,dbgTab:`_dbgTab_b07pi_836`,dbgTabActive:`_dbgTabActive_b07pi_854`,dbgTabBody:`_dbgTabBody_b07pi_858`,dbgPre:`_dbgPre_b07pi_872`,dbgPreErr:`_dbgPreErr_b07pi_883`,dbgMuted:`_dbgMuted_b07pi_884`,canvasNodeOk:`_canvasNodeOk_b07pi_887`,canvasNodeErr:`_canvasNodeErr_b07pi_888`,canvasNodePaused:`_canvasNodePaused_b07pi_889`,canvasNodeFocused:`_canvasNodeFocused_b07pi_893`,nodeBpBadge:`_nodeBpBadge_b07pi_898`,dbgWatcherHeader:`_dbgWatcherHeader_b07pi_926`,dbgWatcherTitle:`_dbgWatcherTitle_b07pi_934`,dbgWatcherSub:`_dbgWatcherSub_b07pi_939`,dbgWatcherBody:`_dbgWatcherBody_b07pi_943`,dbgWatcherRow:`_dbgWatcherRow_b07pi_948`,dbgWatcherKey:`_dbgWatcherKey_b07pi_954`,dbgWatcherVal:`_dbgWatcherVal_b07pi_961`,dbgEditConfig:`_dbgEditConfig_b07pi_974`,dbgEditTitle:`_dbgEditTitle_b07pi_979`,dbgEditRow:`_dbgEditRow_b07pi_985`,dbgEditLabel:`_dbgEditLabel_b07pi_992`,dbgEditInput:`_dbgEditInput_b07pi_998`,dbgEditActions:`_dbgEditActions_b07pi_1013`,dbgDiffPicker:`_dbgDiffPicker_b07pi_1020`,dbgDiffOverlay:`_dbgDiffOverlay_b07pi_1021`,dbgDiffModal:`_dbgDiffModal_b07pi_1032`,dbgDiffHeader:`_dbgDiffHeader_b07pi_1042`,dbgDiffBody:`_dbgDiffBody_b07pi_1057`,dbgDiffRow:`_dbgDiffRow_b07pi_1065`,dbgDiffOk:`_dbgDiffOk_b07pi_1071`,dbgDiffChanged:`_dbgDiffChanged_b07pi_1072`,dbgDiffAdded:`_dbgDiffAdded_b07pi_1073`,dbgDiffRemoved:`_dbgDiffRemoved_b07pi_1074`,dbgDiffNodeLabel:`_dbgDiffNodeLabel_b07pi_1075`,dbgDiffDuration:`_dbgDiffDuration_b07pi_1083`,dbgDiffSplit:`_dbgDiffSplit_b07pi_1090`,dbgDiffSide:`_dbgDiffSide_b07pi_1096`,dbgDiffSideLabel:`_dbgDiffSideLabel_b07pi_1102`,envSelect:`_envSelect_b07pi_1110`,backupStatus:`_backupStatus_b07pi_1120`,templateCard:`_templateCard_b07pi_1127`,templateHeader:`_templateHeader_b07pi_1136`,templateName:`_templateName_b07pi_1142`,templateTag:`_templateTag_b07pi_1147`,templateDesc:`_templateDesc_b07pi_1156`,templateMeta:`_templateMeta_b07pi_1162`,varPickerBtn:`_varPickerBtn_b07pi_1168`,varPickerMenu:`_varPickerMenu_b07pi_1182`,varPickerTitle:`_varPickerTitle_b07pi_1195`,varPickerItem:`_varPickerItem_b07pi_1202`,varPickerLabel:`_varPickerLabel_b07pi_1221`,varPickerHint:`_varPickerHint_b07pi_1226`,varPickerToken:`_varPickerToken_b07pi_1232`},Wt=[{id:`trigger_manual`,type:`trigger`,label:`Manual`,icon:`▶`,color:`#6366f1`,description:`Run manually with optional text input.`,configFields:[{key:`input`,label:`Input text`,placeholder:`Optional initial input`}]},{id:`trigger_cron`,type:`trigger`,label:`Cron`,icon:`⏰`,color:`#fbbf24`,description:`Run on a schedule (cron expression).`,configFields:[{key:`schedule`,label:`Cron expression`,placeholder:`0 8 * * *`,required:!0}]},{id:`trigger_email`,type:`trigger`,label:`New Email`,icon:`📧`,color:`#38bdf8`,description:`Trigger when a new email arrives matching a filter.`,configFields:[{key:`filter`,label:`Gmail filter`,placeholder:`subject:TODO is:unread`}]},{id:`trigger_webhook`,type:`trigger`,label:`Webhook`,icon:`🔗`,color:`#a5b4fc`,description:`Trigger via HTTP POST/GET/PUT/DELETE. URL: http://localhost:3847/api/webhooks/<slug>`,configFields:[{key:`slug`,label:`Slug (URL path)`,placeholder:`my-trigger`,required:!0}]},{id:`trigger_file_watch`,type:`trigger`,label:`File Watch`,icon:`📁`,color:`#34d399`,description:`Fires when a file in the watched folder is created/modified.`,configFields:[{key:`path`,label:`Folder path`,placeholder:`/Users/me/inbox`,required:!0},{key:`recursive`,label:`Recursive (yes/no)`,placeholder:`no`}]},{id:`trigger_rss`,type:`trigger`,label:`RSS Feed`,icon:`📰`,color:`#fb923c`,description:`Polls an RSS/Atom feed; fires once per new item.`,configFields:[{key:`url`,label:`Feed URL`,placeholder:`https://example.com/feed.xml`,required:!0},{key:`intervalMin`,label:`Poll interval (min)`,placeholder:`15`}]},{id:`trigger_imap_folder`,type:`trigger`,label:`IMAP Folder`,icon:`📬`,color:`#60a5fa`,description:`Fires on new mail in a specific IMAP folder/label.`,configFields:[{key:`account`,label:`IMAP account id`,placeholder:`main`,required:!0},{key:`folder`,label:`Folder name`,placeholder:`INBOX`}]},{id:`trigger_discord_message`,type:`trigger`,label:`Discord Message`,icon:`🟣`,color:`#a78bfa`,description:`Fires on a new Discord message matching the filter (#channel or @mention).`,configFields:[{key:`filter`,label:`Filter`,placeholder:`#general OR @nha-bot`}]},{id:`action_email`,type:`action`,label:`Send Email`,icon:`✉`,color:`#38bdf8`,description:`Send email via Gmail or IMAP.`,configFields:[{key:`to`,label:`To`,placeholder:`email@example.com`,required:!0},{key:`subject`,label:`Subject`,placeholder:`Subject or {{output}}`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`action_slack`,type:`action`,label:`Slack Message`,icon:`💬`,color:`#818cf8`,description:`Post a message to a Slack channel.`,configFields:[{key:`channel`,label:`Channel`,placeholder:`#general`,required:!0},{key:`text`,label:`Text`,placeholder:`{{output}}`}]},{id:`action_calendar`,type:`action`,label:`Create Event`,icon:`📅`,color:`#4ade80`,description:`Create a Google Calendar event.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`date`,label:`Date (YYYY-MM-DD)`,placeholder:`2025-01-15`},{key:`time`,label:`Time (HH:MM)`,placeholder:`09:00`}]},{id:`action_task`,type:`action`,label:`Create Task`,icon:`✅`,color:`#fbbf24`,description:`Add a task to your task list.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`priority`,label:`Priority`,placeholder:`medium`}]},{id:`action_drive`,type:`action`,label:`Save to Drive`,icon:`💾`,color:`#a78bfa`,description:`Save a text file to Google Drive.`,configFields:[{key:`name`,label:`Filename`,placeholder:`output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_notion`,type:`action`,label:`Notion Page`,icon:`📋`,color:`#e4e4e7`,description:`Create or update a Notion page.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_github`,type:`action`,label:`GitHub Issue`,icon:`🐙`,color:`#6ee7b7`,description:`Create a GitHub issue.`,configFields:[{key:`repo`,label:`Repo (owner/name)`,placeholder:`user/repo`,required:!0},{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`body`,label:`Body`,placeholder:``}]},{id:`action_webhook`,type:`action`,label:`HTTP Request`,icon:`🌐`,color:`#38bdf8`,description:`Make an HTTP request.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://…`,required:!0},{key:`method`,label:`Method`,placeholder:`POST`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`ai_agent`,type:`ai`,label:`Run Agent`,icon:`🤖`,color:`#818cf8`,description:`Run any of the 38 NHA specialist agents.`,configFields:[{key:`agent`,label:`Agent name`,placeholder:`herald, saber, forge…`,required:!0},{key:`prompt`,label:`Prompt`,placeholder:`Summarize this: {{output}}`,required:!0}]},{id:`ai_summarize`,type:`ai`,label:`Summarize`,icon:`📝`,color:`#a5b4fc`,description:`Summarize text with AI (free via Liara).`,configFields:[{key:`prompt`,label:`Prompt`,placeholder:`Summarize: {{output}}`}]},{id:`ai_classify`,type:`ai`,label:`Classify`,icon:`🏷`,color:`#a5b4fc`,description:`Classify content into categories.`,configFields:[{key:`categories`,label:`Categories (comma-separated)`,placeholder:`urgent, normal, spam`},{key:`prompt`,label:`Prompt`,placeholder:`Classify this email: {{output}}`}]},{id:`ai_extract`,type:`ai`,label:`Extract Data`,icon:`🔍`,color:`#a5b4fc`,description:`Extract structured data from text.`,configFields:[{key:`prompt`,label:`What to extract`,placeholder:`Extract name, email, date from: {{output}}`}]},{id:`ai_translate`,type:`ai`,label:`Translate`,icon:`🌍`,color:`#a5b4fc`,description:`Translate text to another language.`,configFields:[{key:`lang`,label:`Target language`,placeholder:`Italian`,required:!0},{key:`prompt`,label:`Text`,placeholder:`{{output}}`}]},{id:`ai_code`,type:`ai`,label:`Code (JS)`,icon:`💻`,color:`#818cf8`,description:"Execute JavaScript code. Access previous output via `input` variable. Return a value.",configFields:[{key:`code`,label:`JavaScript code`,placeholder:`const data = JSON.parse(input);
704
704
  return data.map(x => x.name).join(", ");`,type:`textarea`}]},{id:`logic_if`,type:`logic`,label:`If / Condition`,icon:`🔀`,color:`#f59e0b`,description:`Branch based on a condition. Outputs to "true" or "false" path.`,configFields:[{key:`condition`,label:`Condition (JS expression)`,placeholder:`{{output}}.includes("urgent")`,required:!0}],outputs:[`true`,`false`]},{id:`logic_switch`,type:`logic`,label:`Switch`,icon:`🔄`,color:`#f59e0b`,description:`Route to different paths based on value. Add cases as comma-separated values.`,configFields:[{key:`expression`,label:`Expression`,placeholder:`{{output}}`,required:!0},{key:`cases`,label:`Cases (comma-separated)`,placeholder:`urgent, normal, spam`,required:!0}]},{id:`logic_loop`,type:`logic`,label:`Loop / For Each`,icon:`🔁`,color:`#f59e0b`,description:`Iterate over items. Input should be JSON array or newline-separated text.`,configFields:[{key:`separator`,label:`Separator`,placeholder:`\\n (newline) or , (comma)`}]},{id:`logic_merge`,type:`logic`,label:`Merge`,icon:`🔗`,color:`#f59e0b`,description:`Merge outputs from multiple branches into one.`,configFields:[{key:`mode`,label:`Mode`,placeholder:`concat`,type:`select`,options:[`concat`,`json_array`,`first_non_empty`]}]},{id:`logic_delay`,type:`logic`,label:`Delay`,icon:`⏳`,color:`#f59e0b`,description:`Wait before continuing.`,configFields:[{key:`seconds`,label:`Seconds`,placeholder:`5`,required:!0}]},{id:`logic_error`,type:`logic`,label:`Error Handler`,icon:`🛡`,color:`#ef4444`,description:`Catch errors from previous nodes. Configure retry count and fallback behavior.`,configFields:[{key:`retries`,label:`Max retries`,placeholder:`3`},{key:`fallback`,label:`Fallback output`,placeholder:`Default value if all retries fail`}]},{id:`logic_subworkflow`,type:`logic`,label:`Subworkflow`,icon:`🪆`,color:`#a855f7`,description:`Run another workflow inline. Output of the sub becomes this node's output. Max nesting depth 5.`,configFields:[{key:`workflowId`,label:`Target workflow ID`,placeholder:`wf_abc123`,required:!0},{key:`inputMapping`,label:`Input expression`,placeholder:`{{output}} (default)`}]},{id:`action_browser`,type:`action`,label:`Open URL`,icon:`🌐`,color:`#60a5fa`,description:`Open a URL in headless browser and extract text content.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://example.com or {{output}}`,required:!0}]},{id:`action_file_read`,type:`action`,label:`Read File`,icon:`📖`,color:`#4ade80`,description:`Read a file from the filesystem.`,configFields:[{key:`path`,label:`File path`,placeholder:`/path/to/file.txt`,required:!0}]},{id:`action_file_write`,type:`action`,label:`Write File`,icon:`📝`,color:`#4ade80`,description:`Write content to a file.`,configFields:[{key:`path`,label:`File path`,placeholder:`/path/to/output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_contact`,type:`action`,label:`Find Contact`,icon:`👤`,color:`#38bdf8`,description:`Search Google Contacts by name or email.`,configFields:[{key:`query`,label:`Search query`,placeholder:`John or john@example.com`,required:!0}]},{id:`action_screen`,type:`action`,label:`Screenshot`,icon:`📸`,color:`#c084fc`,description:`Take a screenshot of the screen.`,configFields:[]},{id:`action_maps`,type:`action`,label:`Maps Directions`,icon:`🗺`,color:`#4ade80`,description:`Get directions between two locations.`,configFields:[{key:`from`,label:`From`,placeholder:`Milan`,required:!0},{key:`to`,label:`To`,placeholder:`Rome`,required:!0}]},{id:`action_notify`,type:`action`,label:`Notification`,icon:`🔔`,color:`#fbbf24`,description:`Send a system notification or Telegram message.`,configFields:[{key:`message`,label:`Message`,placeholder:`{{output}}`,required:!0},{key:`channel`,label:`Channel`,placeholder:`telegram or system`,type:`select`,options:[`system`,`telegram`]}]}],Gt=90,Kt=72;function qt(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function Jt(e,t){return{x:e.x+(t===`out`?Gt:0),y:e.y+Kt/2}}function Yt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(`trigger`),[g,v]=(0,_.useState)([]),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(-1),[C,w]=(0,_.useState)({}),[ee,te]=(0,_.useState)(null),[ne,re]=(0,_.useState)(`output`),[D,ie]=(0,_.useState)(null),[O,ae]=(0,_.useState)({}),[A,oe]=(0,_.useState)(``),[se,le]=(0,_.useState)(null),[ue,de]=(0,_.useState)(!1),[j,M]=(0,_.useState)([]),[fe,pe]=(0,_.useState)(!1),[me,he]=(0,_.useState)(!1),[ge,_e]=(0,_.useState)(`installed`),[ve,ye]=(0,_.useState)([]),[be,xe]=(0,_.useState)([]),[N,Ce]=(0,_.useState)(``),we=(0,_.useMemo)(()=>{let e=ve.flatMap(e=>(e.nodes||[]).map(t=>({...t,id:t.id.startsWith(`${e.id}_`)?t.id:`${e.id}_${t.id}`})));return[...Wt,...e]},[ve]),Te=(0,_.useMemo)(()=>Object.fromEntries(we.map(e=>[e.id,e])),[we]);(0,_.useEffect)(()=>{T(`/api/awf/connectors/installed`).then(e=>{e?.connectors&&ye(e.connectors)}).catch(()=>null)},[]);let Ee=(0,_.useCallback)(async()=>{let[e,t]=await Promise.all([T(`/api/awf/connectors/installed`).catch(()=>null),T(`/api/awf/connectors/registry`).catch(()=>null)]);ye(e?.connectors??[]),xe(t?.connectors??[])},[]),P=(0,_.useCallback)(async()=>{await Ee(),he(!0)},[Ee]),De=(0,_.useCallback)(async e=>{let t=await E(`/api/awf/connectors/install`,/^https?:\/\//i.test(e)?{url:e}:{url:`https://nothumanallowed.com/awf/connectors/${e}/manifest.json`}).catch(e=>({error:e.message}));t?.ok?(await Ee(),Ce(``)):alert(`Installazione fallita: `+(t?.error||`errore sconosciuto`))},[Ee]),Oe=(0,_.useCallback)(async e=>{confirm(`Disinstallare il connector "${e}"?`)&&(await E(`/api/awf/connectors/${e}`,{},`DELETE`).catch(()=>null),await Ee())},[Ee]),[ke,F]=(0,_.useState)(`prod`),[I,Ae]=(0,_.useState)(``);(0,_.useEffect)(()=>{T(`/api/awf/env`).then(e=>{e?.env&&F(e.env)}).catch(()=>null)},[]);let je=(0,_.useCallback)(async()=>{M((await T(`/api/awf/templates`).catch(()=>null))?.templates??[]),pe(!0)},[]),Me=(0,_.useCallback)(async e=>{let n=await E(`/api/awf/templates/import`,{templateId:e}).catch(()=>null);n?.workflow&&(t(e=>[...e,n.workflow]),r(n.workflow),pe(!1))},[]),Ne=(0,_.useCallback)(async e=>{F(e),await E(`/api/awf/env`,{env:e}).catch(()=>null)},[]),Pe=(0,_.useCallback)(async()=>{Ae(`⏳ Backup in corso…`);let e=await E(`/api/awf/backup`,{}).catch(e=>({error:e.message}));e?.ok?Ae(`✅ Backup salvato su Drive`):Ae(`❌ ${e?.error||`Backup fallito`}`),setTimeout(()=>Ae(``),4500)},[]),Fe=(0,_.useCallback)(async()=>{Ae(`⏳ Push in corso…`);let e=await E(`/api/awf/sync/push`,{}).catch(e=>({error:e.message}));Ae(e?.ok?`✅ Push: ${e.fileName}`:`❌ ${e?.error||`Push fallito`}`),setTimeout(()=>Ae(``),5e3)},[]),Ie=(0,_.useCallback)(async()=>{let e=confirm(`Modalità MERGE (OK) — importa solo i workflow mancanti localmente.
705
705
  Annulla = REPLACE — sovrascrive tutto col contenuto Drive.`)?`merge`:`replace`;Ae(`⏳ Pull in corso…`);let n=await E(`/api/awf/sync/pull`,{mode:e}).catch(e=>({error:e.message}));if(n?.ok){Ae(`✅ Pull (${e}): importati ${n.imported??0}, saltati ${n.skipped??0}`);let r=await T(`/api/workflows`).catch(()=>null);r?.workflows&&t(r.workflows)}else Ae(`❌ ${n?.error||`Pull fallito`}`);setTimeout(()=>Ae(``),6e3)},[]),Le=(0,_.useRef)(null),Re=(0,_.useRef)(null);Re.current=n?.id??null;let ze=ce(e=>{let t=e;if(t.type?.startsWith(`awf:`)&&t.wfId===Re.current){if(t.type===`awf:run-start`){Le.current=t.runId||null,d([]),p(!0),S(-1);return}t.runId&&t.runId!==Le.current||(t.type===`awf:step-start`?(d(e=>[...e,{nodeId:t.nodeId||``,nodeLabel:t.nodeLabel||``,nodeIcon:t.nodeIcon||`▶`,input:t.input||``,output:``,error:null,startedAt:t.ts||Date.now()}]),S(e=>e+1)):t.type===`awf:step-end`?d(e=>{let n=[...e];for(let e=n.length-1;e>=0;e--)if(n[e].nodeId===t.nodeId&&!n[e].endedAt){n[e]={...n[e],output:t.outputPreview||n[e].output,error:t.error??null,durationMs:t.durationMs,endedAt:t.ts};break}return n}):t.type===`awf:paused`?(d(e=>[...e,{nodeId:t.atNodeId||``,nodeLabel:t.nodeLabel||`paused`,nodeIcon:`⏸`,output:``,error:null,paused:!0,startedAt:t.ts,endedAt:t.ts,durationMs:0}]),S(e=>e+1)):t.type===`awf:complete`&&(Le.current=null))}}),[L,Be]=(0,_.useState)(1),[Ve,He]=(0,_.useState)({x:0,y:0}),Ue=(0,_.useRef)(!1),We=Ut(),Ge=(0,_.useRef)({x:0,y:0,px:0,py:0}),Ke=(0,_.useRef)(null),qe=(0,_.useRef)(null),Je=(0,_.useRef)(null),Ye=(0,_.useCallback)(async()=>{let e=await T(`/api/workflows`).catch(()=>null);if(!e||!Array.isArray(e.workflows))return;let n=e.workflows;t(n),r(e=>{if(!e)return n[0]??null;let t=n.find(t=>t.id===e.id);return t?{...e,...t,nodeDefs:e.nodeDefs??t.nodeDefs}:e})},[]);(0,_.useEffect)(()=>{Ye()},[Ye]);let Xe=(0,_.useCallback)(async e=>{r(e),t(t=>t.map(t=>t.id===e.id?e:t)),await E(`/api/workflows/${e.id}`,e,`PUT`).catch(()=>null)},[]),Ze=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:we},n=(await E(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},Qe=async e=>{confirm(`Delete this workflow?`)&&(await E(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),Ye())},$e=(0,_.useCallback)(e=>{e.preventDefault();let t=qe.current;if(!t||!n)return;let r=Je.current.getBoundingClientRect(),i=Math.round((e.clientX-r.left-Gt/2)/20)*20,o=Math.round((e.clientY-r.top-Kt/2)/20)*20,s={id:qt(),defId:t,x:Math.max(0,i),y:Math.max(0,o),config:{}};Xe({...n,nodes:[...n.nodes,s]}),a(s.id),qe.current=null},[n,Xe]),et=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||Xe({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(Ke.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,Xe]),tt=(0,_.useCallback)(e=>{if(!Ke.current||!n)return;let{id:t,ox:i,oy:a}=Ke.current,o=e.clientX-i,s=e.clientY-a,c=Math.max(0,Math.round(o/20)*20),l=Math.max(0,Math.round(s/20)*20);r(e=>e&&{...e,nodes:e.nodes.map(e=>e.id===t?{...e,x:c,y:l}:e)})},[n]),nt=(0,_.useCallback)(()=>{if(!Ke.current||!n){Ke.current=null;return}n.nodes.find(e=>e.id===Ke.current.id)&&Xe(n),Ke.current=null},[n,Xe]),rt=(0,_.useCallback)(e=>{n&&(Xe({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,Xe]),it=(0,_.useCallback)((e,t)=>{n&&Xe({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,Xe]),at=(0,_.useCallback)((e,i,a)=>{if(!n)return;let o={...n,nodes:n.nodes.map(t=>t.id===e?{...t,config:{...t.config,[i]:a}}:t)};r(o),t(e=>e.map(e=>e.id===o.id?o:e))},[n]),ot=(0,_.useCallback)(()=>{n&&Xe(n)},[n,Xe]),st=async()=>{if(!(!n||c)){l(!0),p(!0),d([]),b(null),S(-1);try{let e={...n,nodeDefs:we};await E(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null);let t=await E(`/api/workflows/${n.id}/run`,{breakpoints:n.breakpoints||[]}),r=t?.steps??[];d(r),t?.ts&&(b({ts:t.ts,workflowId:n.id,input:``,steps:r,paused:t.paused??null,errorCount:r.filter(e=>e.error).length,totalDurationMs:r.reduce((e,t)=>e+(t.durationMs||0),0)}),S(r.length-1)),Ye(),ct()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},ct=(0,_.useCallback)(async()=>{n&&v((await T(`/api/awf/${n.id}/run-history`).catch(()=>null))?.runs??[])},[n]);(0,_.useEffect)(()=>{ct()},[ct]);let lt=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=lt.current;lt.current=ze,e===`disconnected`&&ze===`connected`&&(Ye(),ct(),c&&n&&T(`/api/awf/${n.id}/run-history`).then(e=>{let t=e?.runs?.[0]?.ts;return t?T(`/api/awf/${n.id}/run/${t}`):null}).then(e=>{e&&(d(e.steps||[]),b(e),S((e.steps?.length??1)-1))}).catch(()=>null))},[ze,c,n,Ye,ct]),(0,_.useEffect)(()=>{let e=u[x];e&&(e.error?re(`error`):e.paused?re(`input`):re(`output`))},[x,u]),(0,_.useEffect)(()=>{if(!n||!y?.paused){ie(null),ae({});return}let e=!1;return(async()=>{let t=await T(`/api/awf/${n.id}/paused-context/${y.ts}`).catch(()=>null);!e&&t&&(ie(t),ae({...t.nodeConfig||{}}))})(),()=>{e=!0}},[n,y?.paused,y?.ts]);let ut=(0,_.useCallback)(async e=>{if(!n)return;let t=await T(`/api/awf/${n.id}/run/${e}`).catch(()=>null);t&&(b(t),d(t.steps||[]),S((t.steps?.length??1)-1),p(!0))},[n]),dt=(0,_.useCallback)(async()=>{if(!(!n||!y)){l(!0);try{let e=await E(`/api/awf/${n.id}/replay/${y.ts}`,{});e?.ts&&await ut(e.ts),ct()}finally{l(!1)}}},[n,y,ut,ct]),ft=(0,_.useCallback)(async e=>{if(!(!n||!y)){l(!0);try{let t=await E(`/api/awf/${n.id}/replay-from/${y.ts}/${e}`,{});t?.ts&&await ut(t.ts),ct()}finally{l(!1)}}},[n,y,ut,ct]),pt=(0,_.useCallback)(async()=>{if(!(!n||!y)){l(!0);try{let e=await E(`/api/awf/${n.id}/resume/${y.ts}`,{});e?.ts&&await ut(e.ts),ct()}finally{l(!1)}}},[n,y,ut,ct]),mt=(0,_.useCallback)(async e=>{if(!n||!y||!e)return;let t=await T(`/api/awf/${n.id}/diff/${y.ts}/${e}`).catch(()=>null);t&&(le(t),de(!0))},[n,y]),ht=(0,_.useCallback)(async e=>{if(!n||!y)return;let t=`${y.ts}:${e}`;if(!C[t]){te(t);try{let r=await E(`/api/awf/${n.id}/explain/${y.ts}/${e}`,{});r?.explanation&&w(e=>({...e,[t]:r.explanation}))}finally{te(null)}}},[n,y,C]),gt=e=>typeof e==`string`?e:e.nodeId,_t=(0,_.useCallback)(e=>{let t=n?.breakpoints||[];for(let n of t)if(gt(n)===e)return typeof n==`string`?{nodeId:n}:n;return null},[n]),vt=(0,_.useCallback)(async e=>{if(!n)return;let i={...n,breakpoints:e};r(i),t(e=>e.map(e=>e.id===i.id?i:e)),await E(`/api/awf/${n.id}/breakpoints`,{breakpoints:e}).catch(()=>null)},[n]),yt=(0,_.useCallback)(async e=>{n&&await vt((n.breakpoints||[]).some(t=>gt(t)===e)?(n.breakpoints||[]).filter(t=>gt(t)!==e):[...n.breakpoints||[],{nodeId:e}])},[n,vt]),R=(0,_.useCallback)(async(e,t)=>{if(!n)return;let r=[...n.breakpoints||[]],i=r.findIndex(t=>gt(t)===e),a={nodeId:e,condition:t.trim()||void 0};i>=0?r[i]=a:r.push(a),await vt(r)},[n,vt]),bt=async e=>{let i={...e,enabled:!e.enabled};await E(`/api/workflows/${e.id}`,i,`PUT`).catch(()=>null),t(t=>t.map(t=>t.id===e.id?i:t)),n?.id===e.id&&r(i)},xt=n?.nodes.find(e=>e.id===i)??null,St=xt?Te[xt.defId]:null;return(0,k.jsxs)(`div`,{className:V.root,children:[(0,k.jsxs)(`div`,{className:V.topbar,children:[(0,k.jsxs)(`div`,{className:V.topbarLeft,children:[(0,k.jsx)(`span`,{className:V.topbarTitle,children:`AWF - AutoWorkFlow`}),(0,k.jsx)(`span`,{className:V.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:V.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${V.runBtn} ${c?V.runBtnActive:``}`,onClick:st,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:V.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`🔍 Debugger`})]}),(0,k.jsxs)(`select`,{className:V.envSelect,value:ke,onChange:e=>Ne(e.target.value),title:`Ambiente attivo: cambia quali credenziali vengono usate`,children:[(0,k.jsx)(`option`,{value:`dev`,children:`🟡 dev`}),(0,k.jsx)(`option`,{value:`staging`,children:`🟠 staging`}),(0,k.jsx)(`option`,{value:`prod`,children:`🟢 prod`})]}),(0,k.jsx)(`button`,{className:V.logBtn,onClick:je,title:`Importa un workflow predefinito`,children:`📚 Templates`}),(0,k.jsx)(`button`,{className:V.logBtn,onClick:P,title:`Gestisci i connector (estensioni con nuovi nodi e template)`,children:`🔌 Connectors`}),(0,k.jsx)(`button`,{className:V.logBtn,onClick:Pe,title:`Backup ora tutti i workflow su Google Drive`,children:`💾 Backup`}),(0,k.jsx)(`button`,{className:V.logBtn,onClick:Fe,title:`Push del workspace su Drive (sincronizzazione tra macchine)`,children:`↑ Push`}),(0,k.jsx)(`button`,{className:V.logBtn,onClick:Ie,title:`Pull del workspace da Drive (sincronizzazione tra macchine)`,children:`↓ Pull`}),I&&(0,k.jsx)(`span`,{className:V.backupStatus,children:I}),(0,k.jsx)(`button`,{className:V.newWfBtn,onClick:Ze,children:`+ New Workflow`})]})]}),fe&&(0,k.jsx)(`div`,{className:V.dbgDiffOverlay,onClick:()=>pe(!1),children:(0,k.jsxs)(`div`,{className:V.dbgDiffModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:V.dbgDiffHeader,children:[(0,k.jsx)(`span`,{className:V.dbgTitle,children:`📚 Workflow Templates`}),(0,k.jsxs)(`span`,{className:V.dbgStats,children:[j.length,` disponibili (locali + community)`]}),(0,k.jsx)(`button`,{className:V.logClose,onClick:()=>pe(!1),children:`✕`})]}),(0,k.jsx)(`div`,{className:V.dbgDiffBody,children:j.length===0?(0,k.jsx)(`div`,{className:V.dbgEmpty,children:`Nessun template disponibile.`}):j.map(e=>(0,k.jsxs)(`div`,{className:V.templateCard,children:[(0,k.jsxs)(`div`,{className:V.templateHeader,children:[(0,k.jsx)(`span`,{className:V.templateName,children:e.name}),e.tags?.map(e=>(0,k.jsx)(`span`,{className:V.templateTag,children:e},e))]}),e.description&&(0,k.jsx)(`span`,{className:V.templateDesc,children:e.description}),(0,k.jsxs)(`div`,{className:V.templateMeta,children:[e.nodes?.length??0,` nodi · `,e.edges?.length??0,` connessioni`]}),(0,k.jsx)(`button`,{className:V.dbgBtnResume,onClick:()=>Me(e.id),children:`⇩ Importa`})]},e.id))})]})}),me&&(0,k.jsx)(`div`,{className:V.dbgDiffOverlay,onClick:()=>he(!1),children:(0,k.jsxs)(`div`,{className:V.dbgDiffModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:V.dbgDiffHeader,children:[(0,k.jsx)(`span`,{className:V.dbgTitle,children:`🔌 Connectors`}),(0,k.jsxs)(`span`,{className:V.dbgTabs,children:[(0,k.jsxs)(`button`,{className:`${V.dbgTab} ${ge===`installed`?V.dbgTabActive:``}`,onClick:()=>_e(`installed`),children:[`Installati (`,ve.length,`)`]}),(0,k.jsxs)(`button`,{className:`${V.dbgTab} ${ge===`marketplace`?V.dbgTabActive:``}`,onClick:()=>_e(`marketplace`),children:[`Marketplace (`,be.length,`)`]})]}),(0,k.jsx)(`button`,{className:V.logClose,onClick:()=>he(!1),children:`✕`})]}),(0,k.jsxs)(`div`,{className:V.dbgDiffBody,children:[ge===`installed`&&(0,k.jsxs)(k.Fragment,{children:[ve.length===0?(0,k.jsxs)(`div`,{className:V.dbgEmpty,children:[`Nessun connector installato. Vai su `,(0,k.jsx)(`b`,{children:`Marketplace`}),` per esplorare quelli disponibili, o installa via URL manifest qui sotto.`]}):ve.map(e=>(0,k.jsxs)(`div`,{className:V.templateCard,children:[(0,k.jsxs)(`div`,{className:V.templateHeader,children:[(0,k.jsx)(`span`,{style:{fontSize:18},children:e.icon||`🔌`}),(0,k.jsx)(`span`,{className:V.templateName,children:e.name}),(0,k.jsxs)(`span`,{className:V.templateTag,children:[`v`,e.version]}),e.author&&(0,k.jsxs)(`span`,{className:V.templateMeta,children:[`by `,e.author]})]}),e.description&&(0,k.jsx)(`span`,{className:V.templateDesc,children:e.description}),(0,k.jsxs)(`div`,{className:V.templateMeta,children:[e.nodes?.length??0,` nodi · `,e.templates?.length??0,` template`,e._installedAt&&` · installato ${new Date(e._installedAt).toLocaleDateString()}`]}),(0,k.jsx)(`button`,{className:V.dbgBtnBp,onClick:()=>Oe(e.id),children:`🗑 Disinstalla`})]},e.id)),(0,k.jsxs)(`div`,{className:V.templateCard,style:{borderStyle:`dashed`},children:[(0,k.jsx)(`div`,{className:V.templateName,children:`+ Installa via URL manifest`}),(0,k.jsx)(`span`,{className:V.templateMeta,children:`Solo host whitelisted: nothumanallowed.com, raw.githubusercontent.com`}),(0,k.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,k.jsx)(`input`,{type:`text`,placeholder:`https://… /manifest.json oppure id curato`,value:N,onChange:e=>Ce(e.target.value),className:V.dbgEditInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:V.dbgBtnResume,disabled:!N.trim(),onClick:()=>N.trim()&&De(N.trim()),children:`⇩ Installa`})]})]})]}),ge===`marketplace`&&(0,k.jsx)(k.Fragment,{children:be.length===0?(0,k.jsx)(`div`,{className:V.dbgEmpty,children:`Marketplace vuoto o irraggiungibile. Il registry è su nothumanallowed.com/awf/connectors/index.json.`}):be.map(e=>(0,k.jsxs)(`div`,{className:V.templateCard,children:[(0,k.jsxs)(`div`,{className:V.templateHeader,children:[(0,k.jsx)(`span`,{style:{fontSize:18},children:e.icon||`🔌`}),(0,k.jsx)(`span`,{className:V.templateName,children:e.name}),(0,k.jsxs)(`span`,{className:V.templateTag,children:[`v`,e.version]}),e.installed&&(0,k.jsx)(`span`,{className:V.templateTag,style:{background:`rgba(34,197,94,0.2)`,color:`#4ade80`},children:`✓ installato`})]}),e.description&&(0,k.jsx)(`span`,{className:V.templateDesc,children:e.description}),(0,k.jsxs)(`div`,{className:V.templateMeta,children:[e.nodes?.length??0,` nodi · `,e.templates?.length??0,` template`]}),(0,k.jsx)(`button`,{className:e.installed?V.dbgBtnBp:V.dbgBtnResume,onClick:()=>e.installed?Oe(e.id):De(e.id),children:e.installed?`🗑 Disinstalla`:`⇩ Installa`})]},e.id))})]})]})}),(0,k.jsxs)(`div`,{className:V.body,children:[(0,k.jsxs)(`div`,{className:V.sidebar,children:[(0,k.jsx)(`div`,{className:V.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:V.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${V.wfItem} ${n?.id===e.id?V.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:V.wfItemRow,children:[(0,k.jsx)(`span`,{className:V.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?V.wfOn:V.wfOff,onClick:t=>{t.stopPropagation(),bt(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:V.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,k.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,k.jsx)(`button`,{className:V.wfDelBtn,onClick:t=>{t.stopPropagation(),Qe(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:V.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:V.canvasHeader,children:[(0,k.jsx)(`input`,{className:V.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&Xe(n)}),o?(0,k.jsxs)(`span`,{className:V.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:V.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:V.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:V.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:Je,className:`${V.canvas} ${o?V.canvasConnecting:``}`,onMouseMove:e=>{if(Ue.current){He({x:Ge.current.px+(e.clientX-Ge.current.x),y:Ge.current.py+(e.clientY-Ge.current.y)});return}tt(e)},onMouseDown:e=>{e.button===1&&(e.preventDefault(),Ue.current=!0,Ge.current={x:e.clientX,y:e.clientY,px:Ve.x,py:Ve.y})},onMouseUp:()=>{Ue.current=!1,nt()},onMouseLeave:()=>{Ue.current=!1,nt()},onWheel:e=>{if(e.preventDefault(),e.ctrlKey||e.metaKey){let t=e.deltaY>0?-.1:.1;Be(e=>Math.max(.3,Math.min(2,e+t)))}else He(t=>({x:t.x-e.deltaX,y:t.y-e.deltaY}))},onDragOver:e=>e.preventDefault(),onDrop:$e,onClick:()=>{o||a(null)},children:[(0,k.jsxs)(`div`,{className:V.zoomControls,children:[(0,k.jsx)(`button`,{onClick:()=>Be(e=>Math.min(2,e+.1)),children:`+`}),(0,k.jsxs)(`span`,{children:[Math.round(L*100),`%`]}),(0,k.jsx)(`button`,{onClick:()=>Be(e=>Math.max(.3,e-.1)),children:`−`}),(0,k.jsx)(`button`,{onClick:()=>{Be(1),He({x:0,y:0})},children:`⊙`})]}),(0,k.jsxs)(`div`,{style:{transform:`translate(${Ve.x}px, ${Ve.y}px) scale(${L})`,transformOrigin:`0 0`,position:`absolute`,inset:0},children:[(0,k.jsx)(`svg`,{className:V.canvasSvg,children:n.edges.map((e,t)=>{let r=n.nodes.find(t=>t.id===e.from),i=n.nodes.find(t=>t.id===e.to);if(!r||!i)return null;let a=Jt(r,`out`),o=Jt(i,`in`),s=(a.x+o.x)/2;return(0,k.jsxs)(`g`,{children:[(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`var(--green3)`,strokeWidth:`2`,fill:`none`,strokeDasharray:`6,3`,opacity:`0.8`}),(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`transparent`,strokeWidth:`12`,fill:`none`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),it(e.from,e.to)}}),(0,k.jsx)(`circle`,{cx:s,cy:(a.y+o.y)/2,r:`7`,fill:`var(--bg2)`,stroke:`var(--border)`,strokeWidth:`1.5`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),it(e.from,e.to)}}),(0,k.jsx)(`text`,{x:s,y:(a.y+o.y)/2+4,textAnchor:`middle`,fill:`var(--dim)`,fontSize:`9`,style:{cursor:`pointer`,pointerEvents:`none`},children:`✕`})]},t)})}),n.nodes.map(e=>{let t=Te[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id,a=!!_t(e.id),c=u[x]?.nodeId===e.id,l=null;for(let t=u.length-1;t>=0;t--)if(u[t].nodeId===e.id){l=u[t].error?`err`:u[t].paused?`paused`:`ok`;break}let d=l===`err`?V.canvasNodeErr:l===`paused`?V.canvasNodePaused:l===`ok`?V.canvasNodeOk:``;return(0,k.jsxs)(`div`,{className:`${V.canvasNode} ${n?V.canvasNodeSelected:``} ${r?V.canvasNodeConnecting:``} ${d} ${c?V.canvasNodeFocused:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>et(t,e.id),onClick:e=>e.stopPropagation(),onContextMenu:t=>{t.preventDefault(),t.stopPropagation(),yt(e.id)},title:a?`Breakpoint attivo · click destro per toglierlo`:`Click destro per mettere un breakpoint qui`,children:[a&&(0,k.jsx)(`span`,{className:V.nodeBpBadge,title:`Breakpoint`,children:`●`}),(0,k.jsx)(`button`,{className:V.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),rt(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:V.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:V.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,k.jsx)(`span`,{className:V.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${V.portOut} ${r?V.portActive:``}`,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),s(t=>t===e.id?null:e.id)},title:`Connect from here`,children:`▶`}),o&&o!==e.id&&(0,k.jsx)(`button`,{className:V.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),et(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,k.jsx)(`div`,{className:V.canvasDrop,children:`Drag nodes from the right panel and drop here`})]})]}),f&&(0,k.jsxs)(`div`,{className:V.debuggerPanel,children:[(0,k.jsxs)(`div`,{className:V.dbgHeader,children:[(0,k.jsxs)(`div`,{className:V.dbgHeaderLeft,children:[(0,k.jsx)(`span`,{className:V.dbgTitle,children:`🔍 Debugger`}),g.length>0&&(0,k.jsxs)(`select`,{className:V.dbgRunSelect,value:y?.ts||``,onChange:e=>e.target.value&&ut(e.target.value),children:[(0,k.jsx)(`option`,{value:``,children:`— scegli una run —`}),g.map(e=>{let t=new Date(e.ts.replace(/-(\d{2})-(\d{2})-(\d{3})Z$/,`:$1:$2.$3Z`)),n=isNaN(t.getTime())?e.ts.slice(0,19):t.toLocaleString();return(0,k.jsxs)(`option`,{value:e.ts,children:[e.hasError?`❌ `:`✓ `,n,` · `,e.stepsCount,` step`,e.stepsCount===1?``:`s`,e.errorNode?` (err: ${e.errorNode})`:``]},e.ts)})]}),y?.paused&&(0,k.jsx)(`span`,{className:V.dbgPausedBadge,title:`Fermato al nodo ${y.paused.atNodeId}`,children:`⏸ FERMATO AL BREAKPOINT`}),y&&!y.paused&&(0,k.jsxs)(`span`,{className:V.dbgStats,children:[y.errorCount?`${y.errorCount} error${y.errorCount===1?``:`i`}`:`tutti i nodi OK`,` · `,y.totalDurationMs,`ms totali`]}),c&&(0,k.jsxs)(`span`,{className:V.dbgStats,children:[`⏳ `,(0,k.jsx)(`b`,{style:{color:`#fbbf24`},children:`In esecuzione…`}),u[u.length-1]?.nodeLabel?(0,k.jsxs)(`span`,{style:{marginLeft:6,color:`var(--text)`},children:[`ora: `,(0,k.jsx)(`b`,{children:u[u.length-1].nodeLabel})]}):null]})]}),(0,k.jsxs)(`div`,{className:V.dbgHeaderRight,children:[y?.paused&&(0,k.jsx)(`button`,{className:V.dbgBtnResume,onClick:pt,disabled:c,children:`▶ Riprendi`}),y&&!y.paused&&(0,k.jsx)(`button`,{className:V.dbgBtnReplay,onClick:dt,disabled:c,title:`Riesegui questa run identica`,children:`🔁 Riesegui`}),y&&g.length>=2&&(0,k.jsx)(`span`,{className:V.dbgDiffPicker,children:(0,k.jsxs)(`select`,{className:V.dbgRunSelect,value:A,onChange:e=>{oe(e.target.value),e.target.value&&mt(e.target.value)},title:`Confronta questa run con una passata per trovare regressioni`,children:[(0,k.jsx)(`option`,{value:``,children:`📊 Diff vs…`}),g.filter(e=>e.ts!==y.ts).map(e=>(0,k.jsxs)(`option`,{value:e.ts,children:[`vs `,e.ts.slice(0,19),` (`,e.stepsCount,` step`,e.hasError?` · err`:``,`)`]},e.ts))]})}),(0,k.jsx)(`button`,{className:V.logClose,onClick:()=>p(!1),children:`✕`})]})]}),y?.paused&&D&&(0,k.jsxs)(`div`,{className:V.dbgWatcher,children:[(0,k.jsxs)(`div`,{className:V.dbgWatcherHeader,children:[(0,k.jsx)(`span`,{className:V.dbgWatcherTitle,children:`👁 Variable Watcher`}),(0,k.jsxs)(`span`,{className:V.dbgWatcherSub,children:[`contesto live al nodo `,(0,k.jsx)(`b`,{children:D.atNodeId}),` · `,`letto `,D.ageMs?`${Math.round(D.ageMs/1e3)}s`:`0s`,` fa`]})]}),(0,k.jsxs)(`div`,{className:V.dbgWatcherBody,children:[(0,k.jsxs)(`div`,{className:V.dbgWatcherRow,children:[(0,k.jsx)(`span`,{className:V.dbgWatcherKey,children:`ctx.input`}),(0,k.jsx)(`pre`,{className:V.dbgWatcherVal,children:typeof D.ctx?.input==`string`?D.ctx.input:JSON.stringify(D.ctx?.input??``,null,2)})]}),(0,k.jsxs)(`div`,{className:V.dbgWatcherRow,children:[(0,k.jsx)(`span`,{className:V.dbgWatcherKey,children:`ctx.output`}),(0,k.jsx)(`pre`,{className:V.dbgWatcherVal,children:typeof D.ctx?.output==`string`?D.ctx.output:JSON.stringify(D.ctx?.output??``,null,2)})]}),D.ctx?.loopItem!==void 0&&D.ctx?.loopItem!==null&&(0,k.jsxs)(`div`,{className:V.dbgWatcherRow,children:[(0,k.jsx)(`span`,{className:V.dbgWatcherKey,children:`ctx.loopItem`}),(0,k.jsx)(`pre`,{className:V.dbgWatcherVal,children:typeof D.ctx.loopItem==`string`?D.ctx.loopItem:JSON.stringify(D.ctx.loopItem,null,2)})]})]}),D.nodeConfig&&Object.keys(D.nodeConfig).length>0&&(0,k.jsxs)(`div`,{className:V.dbgEditConfig,children:[(0,k.jsx)(`div`,{className:V.dbgEditTitle,children:`✏ Modifica config (entrerà in vigore al Riprendi)`}),Object.entries(D.nodeConfig).map(([e,t])=>(0,k.jsxs)(`div`,{className:V.dbgEditRow,children:[(0,k.jsx)(`label`,{className:V.dbgEditLabel,children:e}),(0,k.jsx)(`textarea`,{className:V.dbgEditInput,value:O[e]??String(t),onChange:t=>ae(n=>({...n,[e]:t.target.value})),rows:String(t).length>60?3:1})]},e)),(0,k.jsxs)(`div`,{className:V.dbgEditActions,children:[(0,k.jsx)(`button`,{className:V.dbgBtnResume,disabled:c,onClick:async()=>{n&&(await Xe({...n,nodes:n.nodes.map(e=>e.id===D.atNodeId?{...e,config:{...e.config,...O}}:e)}),await pt())},children:`▶ Riprendi con queste modifiche`}),(0,k.jsx)(`button`,{className:V.dbgBtnReplayFrom,onClick:()=>ae({...D.nodeConfig||{}}),children:`↺ Annulla modifiche`})]})]})]}),u.length===0&&(0,k.jsx)(`div`,{className:V.dbgEmpty,children:c?(0,k.jsx)(`span`,{children:`⏳ Sto eseguendo il workflow…`}):(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`p`,{style:{marginBottom:8},children:`Nessuna esecuzione ancora.`}),(0,k.jsxs)(`p`,{style:{opacity:.6,fontSize:12},children:[`Premi `,(0,k.jsx)(`b`,{children:`▶ Run`}),` per eseguire il workflow. Il debugger mostrerà ogni passaggio in dettaglio.`]}),(0,k.jsxs)(`p`,{style:{opacity:.5,fontSize:11,marginTop:12},children:[`💡 `,(0,k.jsx)(`b`,{children:`Tip:`}),` click destro su un nodo per mettere un `,(0,k.jsx)(`b`,{children:`breakpoint`}),`. Il workflow si fermerà prima di eseguirlo, e potrai ispezionare il contesto.`]})]})}),u.length>0&&(0,k.jsx)(`div`,{className:V.dbgTimeline,children:u.map((e,t)=>{let n=x===t,r=e.error?V.dbgTlStepErr:e.paused?V.dbgTlStepPaused:V.dbgTlStepOk;return(0,k.jsxs)(`button`,{className:`${V.dbgTlStep} ${r} ${n?V.dbgTlStepActive:``}`,onClick:()=>S(t),title:`${e.nodeLabel} · ${e.durationMs??0}ms${e.error?` · ERRORE: ${e.error}`:``}`,children:[(0,k.jsx)(`span`,{className:V.dbgTlIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:V.dbgTlLabel,children:e.nodeLabel}),typeof e.durationMs==`number`&&(0,k.jsxs)(`span`,{className:V.dbgTlMs,children:[e.durationMs,`ms`]})]},t)})}),u[x]&&(()=>{let e=u[x],t=`${y?.ts??`live`}:${e.nodeId}`,n=C[t],r=[{id:`output`,label:`Output`},{id:`input`,label:`Input`,hide:!e.input},{id:`config`,label:`Config`,hide:!e.nodeConfig||Object.keys(e.nodeConfig).length===0},{id:`error`,label:`Errore`,hide:!e.error}];return(0,k.jsxs)(`div`,{className:V.dbgInspector,children:[(0,k.jsxs)(`div`,{className:V.dbgInspHeader,children:[(0,k.jsx)(`span`,{className:V.dbgInspIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:V.dbgInspLabel,children:e.nodeLabel}),e.paused&&(0,k.jsx)(`span`,{className:V.dbgPausedBadge,children:`⏸ FERMATO QUI`}),e.error&&(0,k.jsx)(`span`,{className:V.logStepErrBadge,children:`ERRORE`}),typeof e.durationMs==`number`&&(0,k.jsxs)(`span`,{className:V.dbgInspDuration,children:[e.durationMs,`ms`]}),(0,k.jsxs)(`span`,{className:V.dbgInspActions,children:[e.error&&(0,k.jsx)(`button`,{className:V.dbgBtnExplain,onClick:()=>ht(e.nodeId),disabled:ee===t,children:ee===t?`🤔 Penso…`:`💡 Spiegami questo errore`}),(0,k.jsx)(`button`,{className:V.dbgBtnReplayFrom,onClick:()=>ft(e.nodeId),disabled:c,title:`Riesegui da questo nodo in giù (riusa output a monte)`,children:`↻ Riesegui da qui`}),(()=>{let t=_t(e.nodeId);return(0,k.jsxs)(`span`,{className:V.dbgBpGroup,children:[(0,k.jsx)(`button`,{className:`${V.dbgBtnBp} ${t?V.dbgBtnBpActive:``}`,onClick:()=>yt(e.nodeId),title:`Breakpoint on/off su questo nodo (click destro sul nodo nel canvas)`,children:t?`● BP attivo`:`○ Breakpoint`}),t&&(0,k.jsx)(`input`,{type:`text`,className:V.dbgBpCondition,placeholder:`condition (es: output.includes('errore'))`,defaultValue:t.condition||``,title:`Espressione JS valutata con (ctx, input, output). Vuoto = break sempre.`,onBlur:n=>{(n.target.value||``)!==(t.condition||``)&&R(e.nodeId,n.target.value)},onKeyDown:t=>{t.key===`Enter`&&(R(e.nodeId,t.target.value),t.target.blur())}})]})})()]})]}),n&&(0,k.jsxs)(`div`,{className:V.dbgExplanation,children:[(0,k.jsx)(`span`,{className:V.dbgExplanationIcon,children:`💡`}),(0,k.jsx)(`span`,{className:V.dbgExplanationText,children:n})]}),(0,k.jsx)(`div`,{className:V.dbgTabs,children:r.filter(e=>!e.hide).map(e=>(0,k.jsx)(`button`,{className:`${V.dbgTab} ${ne===e.id?V.dbgTabActive:``}`,onClick:()=>re(e.id),children:e.label},e.id))}),(0,k.jsxs)(`div`,{className:V.dbgTabBody,children:[ne===`output`&&(()=>{let t=e.output;return t==null||t===``?(0,k.jsx)(`span`,{className:V.dbgMuted,children:`Nessun output prodotto.`}):(0,k.jsx)(`div`,{dangerouslySetInnerHTML:{__html:Se((typeof t==`string`?t:JSON.stringify(t,null,2)).slice(0,4e3))}})})(),ne===`input`&&(0,k.jsx)(`pre`,{className:V.dbgPre,children:e.input===void 0||e.input===null?`(nessun input)`:typeof e.input==`string`?e.input:JSON.stringify(e.input,null,2)}),ne===`config`&&e.nodeConfig&&(0,k.jsx)(`pre`,{className:V.dbgPre,children:JSON.stringify(e.nodeConfig,null,2)}),ne===`error`&&e.error&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`pre`,{className:`${V.dbgPre} ${V.dbgPreErr}`,children:typeof e.error==`string`?e.error:JSON.stringify(e.error)}),(0,k.jsxs)(`div`,{style:{marginTop:8,padding:10,background:`rgba(251,191,36,0.08)`,borderLeft:`3px solid #fbbf24`,borderRadius:4,fontSize:12,lineHeight:1.5},children:[(0,k.jsx)(`b`,{style:{color:`#fbbf24`},children:`👈 Vuoi capire questo errore?`}),` Clicca `,(0,k.jsx)(`b`,{children:`💡 Spiegami questo errore`}),` in alto. Te lo spiego in italiano semplice con la soluzione concreta.`]})]})]})]})})(),ue&&se&&(0,k.jsx)(`div`,{className:V.dbgDiffOverlay,onClick:()=>de(!1),children:(0,k.jsxs)(`div`,{className:V.dbgDiffModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:V.dbgDiffHeader,children:[(0,k.jsx)(`span`,{className:V.dbgTitle,children:`📊 Confronto run`}),(0,k.jsxs)(`span`,{className:V.dbgStats,children:[(0,k.jsx)(`b`,{style:{color:`#a5b4fc`},children:`A`}),` `,se.a.ts.slice(0,19),` vs `,(0,k.jsx)(`b`,{style:{color:`#fbbf24`},children:`B`}),` `,se.b.ts.slice(0,19)]}),(0,k.jsxs)(`span`,{className:V.dbgStats,children:[`✓ `,se.summary.identical,` identici`,` · `,(0,k.jsxs)(`span`,{style:{color:`#ef4444`},children:[`≠ `,se.summary.changed,` cambiati`]}),` · `,`+ `,se.summary.added,` aggiunti`,` · `,`− `,se.summary.removed,` rimossi`]}),(0,k.jsx)(`button`,{className:V.logClose,onClick:()=>de(!1),children:`✕`})]}),(0,k.jsx)(`div`,{className:V.dbgDiffBody,children:se.diff.map((e,t)=>{let n=e.status===`identical`?V.dbgDiffOk:e.status===`changed`?V.dbgDiffChanged:e.status===`added`?V.dbgDiffAdded:V.dbgDiffRemoved;return(0,k.jsxs)(`div`,{className:`${V.dbgDiffRow} ${n}`,children:[(0,k.jsxs)(`div`,{className:V.dbgDiffNodeLabel,children:[e.status===`identical`&&`✓ `,e.status===`changed`&&`≠ `,e.status===`added`&&`+ `,e.status===`removed`&&`− `,e.nodeLabel,typeof e.durationDelta==`number`&&e.durationDelta!==0&&(0,k.jsxs)(`span`,{className:V.dbgDiffDuration,children:[e.durationDelta>0?`+`:``,e.durationDelta,`ms`]})]}),e.status===`changed`&&(0,k.jsxs)(`div`,{className:V.dbgDiffSplit,children:[(0,k.jsxs)(`div`,{className:V.dbgDiffSide,children:[(0,k.jsxs)(`span`,{className:V.dbgDiffSideLabel,children:[`A · `,e.a?.durationMs??0,`ms`]}),(0,k.jsx)(`pre`,{className:V.dbgPre,children:String(e.a?.output??``).slice(0,800)}),e.a?.error&&(0,k.jsx)(`pre`,{className:`${V.dbgPre} ${V.dbgPreErr}`,children:e.a.error})]}),(0,k.jsxs)(`div`,{className:V.dbgDiffSide,children:[(0,k.jsxs)(`span`,{className:V.dbgDiffSideLabel,children:[`B · `,e.b?.durationMs??0,`ms`]}),(0,k.jsx)(`pre`,{className:V.dbgPre,children:String(e.b?.output??``).slice(0,800)}),e.b?.error&&(0,k.jsx)(`pre`,{className:`${V.dbgPre} ${V.dbgPreErr}`,children:e.b.error})]})]}),(e.status===`added`||e.status===`removed`)&&(()=>{let t=e.a||e.b;return(0,k.jsx)(`pre`,{className:V.dbgPre,children:String(t?.output??``).slice(0,800)})})()]},`${e.nodeId}_${t}`)})})]})})]})]}):(0,k.jsxs)(`div`,{className:V.canvasEmpty,children:[(0,k.jsx)(`div`,{className:V.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:V.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:V.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,k.jsx)(`br`,{}),`Connect them by clicking the `,(0,k.jsx)(`span`,{className:V.portHint,children:`▶`}),` output port then the target node.`,(0,k.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,k.jsx)(`button`,{className:V.newWfBtn,onClick:Ze,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:V.rightPanel,children:xt&&St&&!We?Qt(xt,St,at,ot,rt,a,V):(0,k.jsxs)(`div`,{className:V.palette,children:[(0,k.jsx)(`div`,{className:V.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:V.paletteTabs,children:[{id:`trigger`,label:`Triggers`,color:`#fbbf24`},{id:`action`,label:`Actions`,color:`#38bdf8`},{id:`ai`,label:`AI`,color:`#a5b4fc`},{id:`logic`,label:`Logic`,color:`#f59e0b`}].map(e=>(0,k.jsx)(`button`,{className:`${V.paletteTab} ${m===e.id?V.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,k.jsx)(`div`,{className:V.paletteNodes,children:we.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:V.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{qe.current=e.id},onDragEnd:()=>{qe.current=null},children:[(0,k.jsx)(`span`,{className:V.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:V.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:V.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:V.paletteGuide,children:[(0,k.jsx)(`div`,{className:V.guideTitle,children:`How to use AWF`}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`2`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`3`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`4`}),(0,k.jsxs)(`span`,{children:[`Click the `,(0,k.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,k.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`5`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,k.jsx)(`code`,{className:V.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`6`}),(0,k.jsxs)(`span`,{children:[`Press `,(0,k.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,k.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,k.jsxs)(`div`,{className:V.guideTip,children:[(0,k.jsx)(`strong`,{children:`Tip:`}),` Click an edge to delete it. Drag nodes on the canvas to reposition. All 80 NHA tools are pre-authenticated — no extra setup.`]}),(0,k.jsxs)(`div`,{className:V.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:V.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]}),We&&n&&(0,k.jsxs)(`ul`,{className:V.nodeListMobile,children:[n.nodes.map((e,t)=>{let r=Te[e.defId];if(!r)return null;let i=n.edges.filter(t=>t.from===e.id);return(0,k.jsxs)(`li`,{children:[(0,k.jsxs)(`div`,{className:V.nodeRow,onClick:()=>a(e.id),role:`button`,tabIndex:0,children:[(0,k.jsx)(`span`,{className:V.nodeRowIndex,children:t+1}),(0,k.jsx)(`span`,{className:V.nodeRowIcon,style:{color:r.color},children:r.icon}),(0,k.jsxs)(`div`,{className:V.nodeRowBody,children:[(0,k.jsx)(`div`,{className:V.nodeRowLabel,children:r.label}),(0,k.jsx)(`div`,{className:V.nodeRowDesc,children:r.description})]})]}),i.length>1&&r.outputs&&(0,k.jsx)(`div`,{className:V.nodeRowBranch,children:i.map((e,t)=>{let i=n.nodes.find(t=>t.id===e.to),a=i?Te[i.defId]:null;return(0,k.jsxs)(`div`,{children:[`↳ `,e.label||(r.outputs?.[t]??``),` → `,a?.icon,` `,a?.label??`?`]},t)})})]},e.id)}),n.nodes.length===0&&(0,k.jsx)(`li`,{className:V.nodeRow,style:{justifyContent:`center`,color:`var(--dim)`},children:`Nessun nodo. Aggiungi triggers/actions dalla palette (apri il browser per editare).`})]}),We&&n&&n.nodes.length>0&&(0,k.jsx)(`button`,{className:V.runFab,onClick:st,disabled:c,"aria-label":`Run workflow`,title:`Esegui workflow`,children:c?`⏳`:`▶`}),We&&(0,k.jsx)(Ht,{open:!!(xt&&St),onClose:()=>a(null),className:V.configSheet,handleClassName:V.configSheetHandle,ariaLabel:`Node configuration`,children:xt&&St&&Qt(xt,St,at,ot,rt,a,V)})]})}var Xt=[{token:`{{output}}`,label:`L'output del nodo precedente`,hint:`Il risultato dell’ultimo nodo che ha girato prima di questo.`},{token:`{{input}}`,label:`L'input iniziale del workflow`,hint:`Il testo o JSON che hai dato al workflow quando è partito.`},{token:`{{triggerPayload.subject}}`,label:`L'oggetto dell'email che ha avviato il flusso`,hint:`Solo se il trigger è New Email / IMAP Folder.`},{token:`{{triggerPayload.from}}`,label:`Il mittente dell’email`,hint:`Indirizzo email del mittente del trigger.`},{token:`{{triggerPayload.body}}`,label:`Il testo dell’email`,hint:`Body completo del messaggio email.`},{token:`{{triggerPayload.path}}`,label:`Il percorso del file modificato`,hint:`Solo se il trigger è File Watch.`},{token:`{{triggerPayload.title}}`,label:`Il titolo dell’articolo RSS`,hint:`Solo se il trigger è RSS Feed.`},{token:`{{triggerPayload.link}}`,label:`Il link dell’articolo RSS`,hint:`Solo se il trigger è RSS Feed.`},{token:`{{loopItem}}`,label:`L’elemento corrente del ciclo (Loop)`,hint:`Disponibile solo dentro un nodo Loop/ForEach.`},{token:`{{cred.}}`,label:`Una credenziale salvata (sostituisci il nome)`,hint:`Es. {{cred.SLACK_TOKEN}} — vedi tab Credentials.`}];function Zt({selNode:e,selDef:t,updateNodeConfig:n,commitConfig:r,deleteNode:i,setSelectedNode:a,styles:o}){let[s,c]=(0,_.useState)(null),l=(t,i)=>{let a=e.config[t]??``,o=a.length===0||/\s$/.test(a)?``:` `;n(e.id,t,a+o+i),c(null),r()};return(0,k.jsxs)(`div`,{className:o.configPanel,children:[(0,k.jsxs)(`div`,{className:o.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:t.color},children:[t.icon,` `,t.label]}),(0,k.jsx)(`button`,{className:o.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:o.configDesc,children:t.description}),(0,k.jsx)(`div`,{className:o.configFields,children:(t.configFields??[]).map(t=>{let i=t.type!==`select`;return(0,k.jsxs)(`div`,{className:o.configField,children:[(0,k.jsxs)(`label`,{className:o.configLabel,children:[t.label,t.required&&(0,k.jsx)(`span`,{className:o.configRequired,children:`*`}),i&&(0,k.jsx)(`button`,{type:`button`,className:o.varPickerBtn,onClick:()=>c(e=>e===t.key?null:t.key),title:`Inserisci un dato dal flusso (es. l'output del nodo precedente)`,children:`+ Inserisci un dato`})]}),t.type===`textarea`?(0,k.jsx)(`textarea`,{className:o.configTextarea,value:e.config[t.key]??``,placeholder:t.placeholder??``,onChange:r=>n(e.id,t.key,r.target.value),onBlur:r,rows:4}):t.type===`select`&&t.options?(0,k.jsx)(`select`,{className:o.configInput,value:e.config[t.key]??t.options[0]??``,onChange:i=>{n(e.id,t.key,i.target.value),r()},children:t.options.map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}):(0,k.jsx)(`input`,{className:o.configInput,value:e.config[t.key]??``,placeholder:t.placeholder??``,onChange:r=>n(e.id,t.key,r.target.value),onBlur:r}),i&&s===t.key&&(0,k.jsxs)(`div`,{className:o.varPickerMenu,children:[(0,k.jsxs)(`div`,{className:o.varPickerTitle,children:[`Scegli cosa inserire nel campo “`,t.label,`”:`]}),Xt.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:o.varPickerItem,onClick:()=>l(t.key,e.token),children:[(0,k.jsx)(`span`,{className:o.varPickerLabel,children:e.label}),(0,k.jsx)(`span`,{className:o.varPickerHint,children:e.hint}),(0,k.jsx)(`code`,{className:o.varPickerToken,children:e.token})]},e.token))]})]},t.key)})}),(0,k.jsx)(`button`,{className:o.configDelete,onClick:()=>i(e.id),children:`Elimina nodo`})]})}function Qt(e,t,n,r,i,a,o){return(0,k.jsx)(Zt,{selNode:e,selDef:t,updateNodeConfig:n,commitConfig:r,deleteNode:i,setSelectedNode:a,styles:o})}var H={root:`_root_ohib4_1`,sidebar:`_sidebar_ohib4_12`,sidebarSection:`_sidebarSection_ohib4_23`,sidebarLabel:`_sidebarLabel_ohib4_28`,accountSelect:`_accountSelect_ohib4_36`,sidebarCompose:`_sidebarCompose_ohib4_46`,composeBtn:`_composeBtn_ohib4_51`,folderList:`_folderList_ohib4_63`,folderItem:`_folderItem_ohib4_69`,folderActive:`_folderActive_ohib4_82`,badge:`_badge_ohib4_88`,labelHeader:`_labelHeader_ohib4_103`,addLabelBtn:`_addLabelBtn_ohib4_114`,newLabelRow:`_newLabelRow_ohib4_123`,newLabelInput:`_newLabelInput_ohib4_129`,newLabelSave:`_newLabelSave_ohib4_139`,labelDot:`_labelDot_ohib4_150`,syncArea:`_syncArea_ohib4_158`,syncBtn:`_syncBtn_ohib4_166`,refreshSelect:`_refreshSelect_ohib4_186`,refreshCountdown:`_refreshCountdown_ohib4_206`,messageList:`_messageList_ohib4_217`,listHeader:`_listHeader_ohib4_227`,searchInput:`_searchInput_ohib4_236`,searchBtn:`_searchBtn_ohib4_246`,listBody:`_listBody_ohib4_256`,listLoading:`_listLoading_ohib4_261`,noMessages:`_noMessages_ohib4_266`,msgRow:`_msgRow_ohib4_273`,msgUnread:`_msgUnread_ohib4_284`,msgActive:`_msgActive_ohib4_289`,msgTop:`_msgTop_ohib4_293`,msgFrom:`_msgFrom_ohib4_299`,msgDate:`_msgDate_ohib4_312`,msgSubject:`_msgSubject_ohib4_319`,msgPreview:`_msgPreview_ohib4_331`,listFooter:`_listFooter_ohib4_342`,loadMoreBtn:`_loadMoreBtn_ohib4_353`,pane:`_pane_ohib4_364`,emptyPane:`_emptyPane_ohib4_372`,readingPane:`_readingPane_ohib4_379`,paneToolbar:`_paneToolbar_ohib4_386`,paneActions:`_paneActions_ohib4_396`,replyBtn:`_replyBtn_ohib4_402`,fwdBtn:`_fwdBtn_ohib4_413`,trashBtn:`_trashBtn_ohib4_413`,starBtn:`_starBtn_ohib4_413`,aiBtn:`_aiBtn_ohib4_426`,labelSelect:`_labelSelect_ohib4_436`,paneHeader:`_paneHeader_ohib4_445`,paneSubject:`_paneSubject_ohib4_451`,paneMeta:`_paneMeta_ohib4_458`,attachments:`_attachments_ohib4_466`,attachLink:`_attachLink_ohib4_473`,paneBody:`_paneBody_ohib4_483`,bodyFrame:`_bodyFrame_ohib4_489`,bodyText:`_bodyText_ohib4_497`,composePane:`_composePane_ohib4_507`,composeTitle:`_composeTitle_ohib4_516`,composeField:`_composeField_ohib4_525`,templateRow:`_templateRow_ohib4_537`,templateToggle:`_templateToggle_ohib4_542`,templateDrop:`_templateDrop_ohib4_552`,templateItem:`_templateItem_ohib4_566`,templateSubject:`_templateSubject_ohib4_576`,composeBody:`_composeBody_ohib4_582`,composeActions:`_composeActions_ohib4_598`,sendBtn:`_sendBtn_ohib4_605`,cancelBtn:`_cancelBtn_ohib4_616`,compStatus:`_compStatus_ohib4_626`,ok:`_ok_ohib4_627`,err:`_err_ohib4_628`},$t=[{id:`INBOX`,name:`Inbox`,icon:`✉`},{id:`SENT`,name:`Sent`,icon:`→`},{id:`DRAFTS`,name:`Drafts`,icon:`📄`},{id:`SPAM`,name:`Spam`,icon:`🛡`},{id:`TRASH`,name:`Trash`,icon:`🗑`}],en=[{name:`Product Promo`,subject:`Discover our offer on [PRODUCT]`},{name:`Monthly Newsletter`,subject:`[COMPANY] Newsletter — [MONTH] [YEAR]`},{name:`Commercial Follow-up`,subject:`Following our conversation — [TOPIC]`},{name:`Offer / Quote`,subject:`Offer [NUMBER] — [SUBJECT]`},{name:`Event Invitation`,subject:`You are invited: [EVENT NAME] — [DATE]`},{name:`Customer Thank You`,subject:`Thank you for your trust, [NAME]`}];function tn(e){return e?e.slice(0,10):``}function nn(e){if(!e)return``;try{let t=typeof e==`string`?JSON.parse(e):e;return Array.isArray(t)?t.map(e=>e.name?`${e.name} <${e.address}>`:e.address||``).join(`, `):String(e)}catch{return String(e)}}function rn(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(`google`),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(`INBOX`),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)(0),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),[ee,te]=(0,_.useState)(!1),[re,D]=(0,_.useState)(!1),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[oe,se]=(0,_.useState)(0),[ce,le]=(0,_.useState)(!1),[ue,de]=(0,_.useState)({}),[M,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(``),[ye,be]=(0,_.useState)(``),[xe,Se]=(0,_.useState)(!1),[N,Ce]=(0,_.useState)(``),[we,Te]=(0,_.useState)(!1),Ee=(0,_.useRef)(null),P=(0,_.useRef)(0),De=[{sec:0,label:`Off`},{sec:300,label:`Ogni 5 min`},{sec:600,label:`Ogni 10 min`},{sec:900,label:`Ogni 15 min`},{sec:1800,label:`Ogni 30 min`},{sec:3600,label:`Ogni 1 h`}],[Oe,ke]=(0,_.useState)(()=>{let e=parseInt(localStorage.getItem(`nha-email-refresh-sec`)||`600`,10);return Number.isFinite(e)?e:600}),[F,I]=(0,_.useState)(!1),[Ae,je]=(0,_.useState)(null),[Me,Ne]=(0,_.useState)(null),[Pe,Fe]=(0,_.useState)(Date.now()),Ie=(0,_.useRef)(!1),Le=e=>{ke(e),localStorage.setItem(`nha-email-refresh-sec`,String(e))},Re=async()=>{if(!Ie.current&&o){Ie.current=!0,I(!0);try{c===`imap`?(await E(`/api/imap/sync/${o}`,{}).catch(()=>{}),o&&Be(o,f,0,ie)):c===`google`&&Ve(f||`INBOX`,ie),je(Date.now())}finally{Ie.current=!1,I(!1)}}};(0,_.useEffect)(()=>{if(!Oe||!o){Ne(null);return}Ne(Date.now()+Oe*1e3);let e=setInterval(()=>{document.visibilityState!==`hidden`&&(Re(),Ne(Date.now()+Oe*1e3))},Oe*1e3);return()=>clearInterval(e)},[Oe,o,c,f]),(0,_.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&(!Oe||!o||(Ae?Date.now()-Ae:1/0)>=Oe*1e3&&(Re(),Ne(Date.now()+Oe*1e3)))};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Oe,o,Ae]),(0,_.useEffect)(()=>{if(!Me)return;let e=setInterval(()=>Fe(Date.now()),1e3);return()=>clearInterval(e)},[Me]);let ze=(()=>{if(!Me||!Oe)return null;let e=Math.max(0,Math.round((Me-Pe)/1e3));return`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`})();(0,_.useEffect)(()=>{T(`/api/config`).then(e=>r(!!e?.hasGoogle)),T(`/api/imap/accounts`).then(e=>{let t=(e?.accounts??[]).filter(e=>e.id!==`google`);a(t);let n=localStorage.getItem(`nha-email-account-type`),r=localStorage.getItem(`nha-email-account-id`);n===`google`?L(`google`,`google`):n===`imap`&&r&&t.some(e=>e.id===r)?L(r,`imap`):t.length>0?L(t[0].id,`imap`):L(`google`,`google`)})},[]);let L=(e,t)=>{s(e),l(t),p(t===`google`?`INBOX`:null),localStorage.setItem(`nha-email-account-type`,t),localStorage.setItem(`nha-email-account-id`,e),h([]),b(0),S(null),w(null),t===`imap`?T(`/api/imap/labels?accountId=${e}`).then(t=>{let n=t?.labels??[];d(n);let r=n.find(e=>e.system_type===`inbox`)?.id??null;p(r),Be(e,r,0,``)}):(d([]),Ve(`INBOX`,``))},Be=(e,t,n,r)=>{let i=++P.current;te(!0);let a=`/api/imap/messages?accountId=${encodeURIComponent(e)}&limit=50&offset=${n}`;t&&(a+=`&labelId=${encodeURIComponent(t)}`),r&&(a+=`&search=${encodeURIComponent(r)}`),T(a).then(e=>{i===P.current&&(h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),te(!1))}).catch(()=>{i===P.current&&te(!1)})},Ve=(e,t)=>{te(!0);let n=e||`INBOX`;T(`/api/emails?folder=${encodeURIComponent(n)}&page=0&pageSize=50${t?`&search=${encodeURIComponent(t)}`:``}`).then(e=>{if(e?.authRequired){h([]),v(0),te(!1);return}let t=e?.emails??[];if(t.length>0){let e=t.map(e=>({id:e.id,subject:e.subject,from_name:e.from,from_address:e.from,internal_date:e.date,body_preview:e.snippet,is_read:!e.isUnread,is_starred:!1,has_attachments:!1,_google:!0}));h(e),v(e.length),n===`INBOX`&&se(e.filter(e=>!e.is_read).length)}else h([]),v(0);te(!1)}).catch(()=>{h([]),te(!1)})},He=()=>{O(ae),b(0),h([]),c===`imap`&&o?Be(o,f,0,ae):Ve(f||`INBOX`,ae)},Ue=e=>{S(e),le(!1),D(!0),c===`google`?T(`/api/imap/message?id=${encodeURIComponent(e)}`).then(t=>{t?.message&&(t.message.body_text||t.message.body_html)?(w({...t.message,id:e,_google:!0}),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),D(!1)):E(`/api/email/read`,{messageId:e}).then(t=>{if(t?.message){let n=t.message;w({...t.message,body_text:n.body||n.body_text,body_html:n.body_html,from_address:n.from||n.from_address,id:e,_google:!0}),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),E(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}D(!1)}).catch(()=>D(!1))}).catch(()=>D(!1)):T(`/api/imap/message?id=${encodeURIComponent(e)}`).then(t=>{w(t?.message??null),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),D(!1)}).catch(()=>D(!1))},We=(e={})=>{le(!0),de(e),fe(e.to??``),me(``),ge(e.subject??``),ve(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),be(``),Se(!1),S(null),w(null)},Ge=async()=>{if(!M.trim()){be(`Recipient required`);return}be(`Sending…`);try{if(c===`imap`&&o){let e=await E(`/api/imap/send`,{accountId:o,to:M.trim(),cc:pe.trim()||void 0,subject:he.trim(),bodyHtml:_e.replace(/\n/g,`<br>`),bodyText:_e,inReplyTo:ue.inReplyTo||void 0});e?.ok?(be(`Sent!`),setTimeout(()=>le(!1),800)):be(e?.error??`Error`)}else{let e=await E(`/api/email/send`,{to:M.trim(),subject:he.trim(),body:_e});e?.ok||e?.id?(be(`Sent!`),setTimeout(()=>le(!1),800)):be(e?.error??`Error`)}}catch(e){be(e.message??`Error`)}},Ke=e=>{confirm(`Move to trash? Email stays on the server.`)&&E(`/api/imap/trash`,{messageId:e}).then(()=>{h(t=>t.filter(t=>t.id!==e)),w(null),S(null)})},qe=(e,t)=>{E(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},Je=(e,t)=>{t&&E(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Ye=()=>{!N.trim()||!o||E(`/api/imap/labels`,{accountId:o,name:N.trim()}).then(()=>{Te(!1),Ce(``),T(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})},Xe=()=>{if(c===`google`){te(!0);let e=f||`INBOX`,t=m.length+50;T(`/api/emails?folder=${encodeURIComponent(e)}&page=0&pageSize=${t}`).then(e=>{let t=(e?.emails??[]).map(e=>({id:e.id,subject:e.subject,from_name:e.from,from_address:e.from,internal_date:e.date,body_preview:e.snippet,is_read:!e.isUnread,is_starred:!1,has_attachments:!1,_google:!0}));h(t),v(t.length),te(!1)}).catch(()=>te(!1))}else{let e=y+50;b(e),o&&Be(o,f,e,ie)}};return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.sidebar,children:[(0,k.jsxs)(`div`,{className:H.sidebarSection,children:[(0,k.jsx)(`div`,{className:H.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:H.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?L(`google`,`google`):t.startsWith(`imap:`)&&L(t.slice(5),`imap`)},children:[n&&(0,k.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,k.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,k.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,k.jsx)(`div`,{className:H.sidebarCompose,children:(0,k.jsx)(`button`,{className:H.composeBtn,onClick:()=>We(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:H.folderList,children:c===`google`?$t.map(e=>(0,k.jsxs)(`div`,{className:`${H.folderItem} ${f===e.id?H.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Ve(e.id,ie)},children:[(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&oe>0&&(0,k.jsx)(`span`,{className:H.badge,children:oe})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:H.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:H.addLabelBtn,onClick:()=>Te(e=>!e),children:`+`})]}),we&&(0,k.jsxs)(`div`,{className:H.newLabelRow,children:[(0,k.jsx)(`input`,{className:H.newLabelInput,value:N,onChange:e=>Ce(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Ye()}),(0,k.jsx)(`button`,{className:H.newLabelSave,onClick:Ye,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${H.folderItem} ${f===e.id?H.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&Be(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:H.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.system_type===`inbox`&&e.unread_count?(0,k.jsx)(`span`,{className:H.badge,children:e.unread_count}):null]},e.id))]})}),o&&(0,k.jsxs)(`div`,{className:H.syncArea,children:[(0,k.jsx)(`button`,{className:H.syncBtn,onClick:Re,disabled:F,title:Ae?`Ultimo sync: ${new Date(Ae).toLocaleTimeString()}`:`Mai sincronizzato`,children:F?`⟳ Sync…`:`Sync ora`}),(0,k.jsx)(`select`,{className:H.refreshSelect,value:Oe,onChange:e=>Le(parseInt(e.target.value,10)),title:`Intervallo di aggiornamento automatico`,children:De.map(e=>(0,k.jsx)(`option`,{value:e.sec,children:e.label},e.sec))}),ze&&(0,k.jsxs)(`span`,{className:H.refreshCountdown,title:`Prossimo refresh tra`,children:[`⏱ `,ze]})]})]}),(0,k.jsxs)(`div`,{className:H.messageList,children:[(0,k.jsxs)(`div`,{className:H.listHeader,children:[(0,k.jsx)(`input`,{className:H.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&He()}),(0,k.jsx)(`button`,{className:H.searchBtn,onClick:He,children:`Go`})]}),(0,k.jsxs)(`div`,{className:H.listBody,children:[ee&&(0,k.jsx)(`div`,{className:H.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:H.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${H.msgRow} ${e.id===x?H.msgActive:``} ${e.is_read?``:H.msgUnread}`,onClick:()=>Ue(e.id),children:[(0,k.jsxs)(`div`,{className:H.msgTop,children:[(0,k.jsx)(`span`,{className:H.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:H.msgDate,children:tn(e.internal_date)})]}),(0,k.jsx)(`div`,{className:H.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:H.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:H.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),c===`imap`&&m.length<g&&(0,k.jsx)(`button`,{className:H.loadMoreBtn,onClick:Xe,children:`Load more`}),c===`google`&&m.length>=50&&(0,k.jsx)(`button`,{className:H.loadMoreBtn,onClick:Xe,disabled:ee,children:ee?`Loading...`:`Scarica altre`})]})]}),(0,k.jsx)(`div`,{className:H.pane,children:(()=>{if(ce)return(0,k.jsxs)(`div`,{className:H.composePane,children:[(0,k.jsx)(`div`,{className:H.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:H.composeField,value:M,onChange:e=>fe(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:H.composeField,value:pe,onChange:e=>me(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:H.composeField,value:he,onChange:e=>ge(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:H.templateRow,children:[(0,k.jsx)(`button`,{className:H.templateToggle,onClick:()=>Se(e=>!e),children:`📄 Templates`}),xe&&(0,k.jsx)(`div`,{className:H.templateDrop,children:en.map((e,t)=>(0,k.jsxs)(`div`,{className:H.templateItem,onClick:()=>{ge(t=>t||e.subject),Se(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:H.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:H.composeBody,value:_e,onChange:e=>ve(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:H.composeActions,children:[(0,k.jsx)(`button`,{className:H.sendBtn,onClick:Ge,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:H.cancelBtn,onClick:()=>le(!1),children:`Discard`}),ye&&(0,k.jsx)(`span`,{className:`${H.compStatus} ${ye===`Sent!`?H.ok:H.err}`,children:ye})]})]});if(re)return(0,k.jsx)(`div`,{className:H.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:H.emptyPane,children:`Select a message`});let n=nn(C.to_addresses);return(0,k.jsxs)(`div`,{className:H.readingPane,children:[(0,k.jsx)(`div`,{className:H.paneToolbar,children:(0,k.jsxs)(`div`,{className:H.paneActions,children:[(0,k.jsx)(`button`,{className:H.replyBtn,onClick:()=>We({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,k.jsx)(`button`,{className:H.fwdBtn,onClick:()=>We({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:H.trashBtn,onClick:()=>Ke(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:H.starBtn,onClick:()=>qe(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:H.labelSelect,defaultValue:``,onChange:e=>Je(C.id,e.target.value),children:[(0,k.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsx)(`button`,{className:H.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:H.paneHeader,children:[(0,k.jsx)(`div`,{className:H.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:H.paneMeta,children:[(0,k.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,k.jsxs)(`div`,{className:H.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:H.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:H.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:H.attachLink,href:`/api/imap/attachment?messageId=${encodeURIComponent(C.id)}&partId=${encodeURIComponent(e.part_id??``)}&accountId=${encodeURIComponent(o??``)}`,download:e.filename??`attachment`,children:[`📎 `,e.filename??`attachment`,` (`,Math.round((e.size_bytes??0)/1024),`KB)`]},t))})]}),(0,k.jsx)(`div`,{className:H.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:Ee,sandbox:`allow-same-origin allow-popups`,className:H.bodyFrame,srcDoc:C.body_html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,``),title:`Email body`}):(0,k.jsx)(`pre`,{className:H.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var U={root:`_root_7ur7d_1`,center:`_center_7ur7d_9`,noGoogle:`_noGoogle_7ur7d_16`,noGoogleIcon:`_noGoogleIcon_7ur7d_25`,noGoogleTitle:`_noGoogleTitle_7ur7d_26`,noGoogleSub:`_noGoogleSub_7ur7d_27`,connectBtn:`_connectBtn_7ur7d_29`,calCol:`_calCol_7ur7d_41`,navRow:`_navRow_7ur7d_49`,navBtn:`_navBtn_7ur7d_57`,monthTitle:`_monthTitle_7ur7d_70`,dayHeaders:`_dayHeaders_7ur7d_78`,dayHeader:`_dayHeader_7ur7d_78`,weekend:`_weekend_7ur7d_94`,grid:`_grid_7ur7d_96`,cell:`_cell_7ur7d_105`,emptyCell:`_emptyCell_7ur7d_119`,weekendCell:`_weekendCell_7ur7d_121`,todayCell:`_todayCell_7ur7d_122`,activeCell:`_activeCell_7ur7d_123`,hasEvtsCell:`_hasEvtsCell_7ur7d_124`,holidayCell:`_holidayCell_7ur7d_125`,dayNum:`_dayNum_7ur7d_127`,todayNum:`_todayNum_7ur7d_134`,weekendNum:`_weekendNum_7ur7d_135`,evtPills:`_evtPills_7ur7d_137`,evtPill:`_evtPill_7ur7d_137`,holidayPill:`_holidayPill_7ur7d_158`,morePill:`_morePill_7ur7d_160`,loadingBar:`_loadingBar_7ur7d_166`,detailCol:`_detailCol_7ur7d_175`,detailHeader:`_detailHeader_7ur7d_187`,detailDate:`_detailDate_7ur7d_197`,addEvtBtn:`_addEvtBtn_7ur7d_203`,noEvts:`_noEvts_7ur7d_218`,selectDay:`_selectDay_7ur7d_225`,evtCard:`_evtCard_7ur7d_233`,evtTop:`_evtTop_7ur7d_246`,evtTime:`_evtTime_7ur7d_253`,evtBtns:`_evtBtns_7ur7d_259`,editBtn:`_editBtn_7ur7d_265`,delBtn:`_delBtn_7ur7d_278`,readOnly:`_readOnly_7ur7d_291`,evtTitle:`_evtTitle_7ur7d_300`,evtLoc:`_evtLoc_7ur7d_306`,evtMeta:`_evtMeta_7ur7d_307`,attendees:`_attendees_7ur7d_309`,attendee:`_attendee_7ur7d_309`,evtDesc:`_evtDesc_7ur7d_320`,joinBtn:`_joinBtn_7ur7d_330`,gcalLink:`_gcalLink_7ur7d_337`,overlay:`_overlay_7ur7d_344`,formCard:`_formCard_7ur7d_354`,formTitle:`_formTitle_7ur7d_368`,formLabel:`_formLabel_7ur7d_375`,formInput:`_formInput_7ur7d_381`,formTextarea:`_formTextarea_7ur7d_394`,formError:`_formError_7ur7d_410`,formBtns:`_formBtns_7ur7d_415`,cancelFormBtn:`_cancelFormBtn_7ur7d_422`,saveFormBtn:`_saveFormBtn_7ur7d_432`};function an(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function on(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function sn(e){if(!e)return``;let t=new Date(e);return isNaN(t.getTime())?e.slice(11,16):t.toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`})}function cn(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)(null),i=new Date,[a,o]=(0,_.useState)(i.getFullYear()),[s,c]=(0,_.useState)(i.getMonth()),[l,u]=(0,_.useState)({}),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(!1);(0,_.useEffect)(()=>{T(`/api/config`).then(e=>r(!!e?.hasGoogle))},[]);let S=(0,_.useCallback)((e,t)=>{let n=`${e}-${String(t+1).padStart(2,`0`)}`;f(!0),T(`/api/calendar?month=${n}`).then(e=>{e?.byDate&&u(t=>({...t,...e.byDate})),f(!1)}).catch(()=>f(!1))},[]);(0,_.useEffect)(()=>{n&&S(a,s)},[n,a,s,S]);let C=e=>{T(`/api/calendar?date=${e}`).then(t=>{u(n=>({...n,[e]:t?.events??[]}))})},w=(e,t,n)=>{confirm(`Delete this event?`)&&E(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{},`DELETE`).then(()=>C(n))},ee=e=>{g({title:``,start:`${e}T09:00`,end:`${e}T10:00`,location:``,description:``,isEdit:!1}),y(``)},te=(e,t)=>{let n=e.start?e.start.slice(0,16):`${t}T09:00`,r=e.end?e.end.slice(0,16):`${t}T10:00`;g({id:e.id,calId:e.calendarId??`primary`,title:e.summary,start:n,end:r,location:e.location??``,description:e.description??``,isEdit:!0}),y(``)},re=async()=>{if(h){if(!h.title.trim()){y(`Title is required`);return}x(!0);try{if(h.isEdit&&h.id){let e=h.calId??`primary`;await E(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(h.id)}`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0},`PATCH`)}else{let e=h.start.split(`T`)[0];await E(`/api/calendar`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0,date:e})}let e=h.start.split(`T`)[0];C(e),g(null)}catch(e){y(`Error: `+(e.message??`Unknown`))}finally{x(!1)}}};if(n===null)return(0,k.jsx)(`div`,{className:U.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:U.center,children:(0,k.jsxs)(`div`,{className:U.noGoogle,children:[(0,k.jsx)(`div`,{className:U.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:U.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:U.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:U.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let D=new Date(a,s,1).getDay(),ie=new Date(a,s+1,0).getDate(),O=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ae=(D+6)%7,A=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],oe=p?l[p]??[]:[];return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.calCol,children:[(0,k.jsxs)(`div`,{className:U.navRow,children:[(0,k.jsx)(`button`,{className:U.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:U.monthTitle,children:O}),(0,k.jsx)(`button`,{className:U.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:U.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${U.dayHeader} ${t>=5?U.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:U.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${U.cell} ${U.emptyCell} ${t>=5?U.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=an(a,s,n),i=on(a,s,n),o=l[r]??[],c=o.length,u=(ae+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,k.jsxs)(`div`,{className:`${U.cell} ${i?U.todayCell:u?U.weekendCell:``} ${f?U.activeCell:``} ${d?U.holidayCell:c>0?U.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${U.dayNum} ${i?U.todayNum:u?U.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:U.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${U.evtPill} ${e._isHoliday||e.readOnly?U.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:U.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:U.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:U.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:U.detailHeader,children:[(0,k.jsx)(`div`,{className:U.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:U.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),oe.length===0?(0,k.jsx)(`div`,{className:U.noEvts,children:`No events on this day`}):oe.map((t,n)=>{let r=t.isAllDay?`All day`:`${sn(t.start)} - ${sn(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:U.evtCard,children:[(0,k.jsxs)(`div`,{className:U.evtTop,children:[(0,k.jsx)(`div`,{className:U.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:U.evtBtns,children:[(0,k.jsx)(`button`,{className:U.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:U.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:U.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:U.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:U.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:U.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:U.attendees,children:[(0,k.jsx)(`div`,{className:U.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:U.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:U.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:U.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:U.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsxs)(`div`,{className:U.selectDay,children:[`Click a day to see events, edit or delete them.`,(0,k.jsx)(`br`,{}),(0,k.jsx)(`br`,{}),`Use `,(0,k.jsx)(`strong`,{children:`+ Add Event`}),` to create a new event — it syncs with Google Calendar.`]})}),h&&(0,k.jsx)(`div`,{className:U.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:U.formCard,children:[(0,k.jsx)(`div`,{className:U.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:U.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:U.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:U.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:U.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:U.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:U.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:U.formError,children:v}),(0,k.jsxs)(`div`,{className:U.formBtns,children:[(0,k.jsx)(`button`,{className:U.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:U.saveFormBtn,onClick:re,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var W={root:`_root_1tngw_1`,gridSection:`_gridSection_1tngw_9`,gridHeader:`_gridHeader_1tngw_14`,headerRow:`_headerRow_1tngw_21`,search:`_search_1tngw_23`,createBtn:`_createBtn_1tngw_34`,catTabs:`_catTabs_1tngw_41`,catTab:`_catTab_1tngw_41`,catActive:`_catActive_1tngw_48`,grid:`_grid_1tngw_9`,agentCard:`_agentCard_1tngw_59`,agentActive:`_agentActive_1tngw_66`,agentCardTop:`_agentCardTop_1tngw_68`,agentIcon:`_agentIcon_1tngw_69`,agentActions:`_agentActions_1tngw_70`,agentEditBtn:`_agentEditBtn_1tngw_71`,agentDelBtn:`_agentDelBtn_1tngw_71`,agentLabel:`_agentLabel_1tngw_74`,agentDesc:`_agentDesc_1tngw_75`,agentCat:`_agentCat_1tngw_76`,loading:`_loading_1tngw_78`,chatArea:`_chatArea_1tngw_81`,emptyChat:`_emptyChat_1tngw_88`,emptyChatHint:`_emptyChatHint_1tngw_98`,chatPanel:`_chatPanel_1tngw_101`,chatHeader:`_chatHeader_1tngw_111`,chatIcon:`_chatIcon_1tngw_118`,chatHeaderInfo:`_chatHeaderInfo_1tngw_119`,chatAgentName:`_chatAgentName_1tngw_120`,chatAgentDesc:`_chatAgentDesc_1tngw_121`,closeChat:`_closeChat_1tngw_122`,chatMessages:`_chatMessages_1tngw_125`,chatEmpty:`_chatEmpty_1tngw_130`,chatMsg:`_chatMsg_1tngw_132`,msgUser:`_msgUser_1tngw_136`,msgAgent:`_msgAgent_1tngw_137`,thinking:`_thinking_1tngw_139`,dot:`_dot_1tngw_140`,dotPulse:`_dotPulse_1tngw_1`,chatInput:`_chatInput_1tngw_146`,chatTools:`_chatTools_1tngw_147`,toolBtn:`_toolBtn_1tngw_148`,toolBtnActive:`_toolBtnActive_1tngw_156`,attachBar:`_attachBar_1tngw_158`,attachClear:`_attachClear_1tngw_163`,chatInputRow:`_chatInputRow_1tngw_165`,chatTextarea:`_chatTextarea_1tngw_166`,sendBtn:`_sendBtn_1tngw_173`,orchBar:`_orchBar_1tngw_181`,orchLabel:`_orchLabel_1tngw_192`,orchRow:`_orchRow_1tngw_193`,orchInput:`_orchInput_1tngw_194`,orchBtn:`_orchBtn_1tngw_201`,orchSynthesis:`_orchSynthesis_1tngw_208`,orchSynthHeader:`_orchSynthHeader_1tngw_214`,orchSynthSpinner:`_orchSynthSpinner_1tngw_220`,blink:`_blink_1tngw_1`,orchSynthBody:`_orchSynthBody_1tngw_222`,modalOverlay:`_modalOverlay_1tngw_230`,modal:`_modal_1tngw_230`,modalTitle:`_modalTitle_1tngw_232`,formField:`_formField_1tngw_233`,formLabel:`_formLabel_1tngw_234`,formInput:`_formInput_1tngw_235`,formTextarea:`_formTextarea_1tngw_236`,formError:`_formError_1tngw_237`,modalBtns:`_modalBtns_1tngw_238`,cancelBtn:`_cancelBtn_1tngw_239`,modalSaveBtn:`_modalSaveBtn_1tngw_240`},ln={saber:{icon:`🛡`},zero:{icon:`🔍`},ade:{icon:`🔬`},heimdall:{icon:`🔒`},cassandra:{icon:`⚠`},sauron:{icon:`👁`},jarvis:{icon:`💻`},forge:{icon:`⚙`},pipe:{icon:`🔧`},shell:{icon:`📟`},glitch:{icon:`🐛`},hermes:{icon:`🔗`},babel:{icon:`🌎`},shogun:{icon:`☸`},flux:{icon:`🔄`},cron:{icon:`⏰`},atlas:{icon:`🗺`},oracle:{icon:`📊`},logos:{icon:`🧮`},navi:{icon:`🧭`},edi:{icon:`📈`},mercury:{icon:`🌐`},tempest:{icon:`⛈`},cartographer:{icon:`🌍`},scheherazade:{icon:`✍`},quill:{icon:`📝`},muse:{icon:`🎨`},murasaki:{icon:`🖌`},echo:{icon:`📡`},polyglot:{icon:`🗣`},prometheus:{icon:`🔥`},herald:{icon:`📢`},veritas:{icon:`✓`},athena:{icon:`🧠`},conductor:{icon:`🎼`},link:{icon:`🔌`},macro:{icon:`⚡`},epicure:{icon:`🍽`}};function un(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=ln[n],i=t.displayName||t.agentName||t.name||e.displayName||n,a=t.tagline||t.description||e.tagline||``,o=t.category||e.category||`Other`;return{id:n,icon:r?.icon??t.icon??`🤖`,label:i,description:a,category:o,isCustom:o===`custom`,systemPrompt:e.systemPrompt}}function dn(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function fn(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`All`),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(`create`),[w,ee]=(0,_.useState)(``),[te,ne]=(0,_.useState)(!1),re=(0,_.useRef)(new Map),D=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),ae=(0,_.useRef)(new Map),A=(0,_.useRef)(new Map),oe=(0,_.useRef)(null),se=()=>{T(`/api/agents`).then(e=>{n((e?.agents??[]).map(un)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{se()},[]);let ce=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],le=t.filter(e=>{let t=s===`All`||e.category===s,n=a.toLowerCase();return t&&(!n||e.label.toLowerCase().includes(n)||e.description.toLowerCase().includes(n))}),ue=e=>{u(t=>{let n=t.findIndex(t=>t.agent.id===e.id);return n>=0?(D.current.get(e.id)?.abort(),D.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,dn(e)]})},de=e=>{D.current.get(e)?.abort(),D.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},M=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},fe=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},pe=(e,t)=>{u(n=>n.map(n=>{if(n.agent.id!==e)return n;let r=[...n.history];return r[r.length-1]={...r[r.length-1],content:t},{...n,history:r}}))},me=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;fe(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),M(i,{streaming:!0,input:``,attachedFile:null,attachedImage:null});let a=e.history.slice(-20);if(n||r){try{let e={message:t||`Analyze this`,agent:i};n?.isPDF&&n.base64?(e.pdfBase64=n.base64,e.pdfName=n.name):n?.content&&(e.fileContent=n.content,e.fileName=n.name),r?.base64&&(e.imageBase64=r.base64,e.imageMimeType=r.mimeType??`image/jpeg`);let a=await E(`/api/chat`,e);fe(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{fe(i,{role:`assistant`,content:`Error sending attachment.`})}M(i,{streaming:!1});return}fe(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;D.current.set(i,o);let s=``;try{await ie(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,pe(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{M(i,{streaming:!1}),D.current.delete(i)}},he=async()=>{let e=d.trim();if(!e||p||l.length===0)return;f(``),m(!0),g(``);let t=[];if(await Promise.all(l.map(async n=>{let r=n.agent.id;fe(r,{role:`user`,content:e}),M(r,{streaming:!0});let i=``,a=new AbortController;D.current.set(r,a),fe(r,{role:`assistant`,content:``,streaming:!0});try{await ie(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,pe(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{M(r,{streaming:!1}),D.current.delete(r)}t.push({agentId:r,agentLabel:n.agent.label,icon:n.agent.icon,content:i})})),m(!1),t.length<2)return;y(!0);let n=t.map(e=>`## ${e.icon} ${e.agentLabel}\n${e.content}`).join(`
706
706
 
@@ -748,7 +748,7 @@ Be concise. Highlight what each agent contributed uniquely. Give your own synthe
748
748
  `,e.VT=`\v`,e.FF=`\f`,e.CR=`\r`,e.SO=``,e.SI=``,e.DLE=``,e.DC1=``,e.DC2=``,e.DC3=``,e.DC4=``,e.NAK=``,e.SYN=``,e.ETB=``,e.CAN=``,e.EM=``,e.SUB=``,e.ESC=`\x1B`,e.FS=``,e.GS=``,e.RS=``,e.US=``,e.SP=` `,e.DEL=``}(n||(t.C0=n={})),function(e){e.PAD=`€`,e.HOP=``,e.BPH=`‚`,e.NBH=`ƒ`,e.IND=`„`,e.NEL=`…`,e.SSA=`†`,e.ESA=`‡`,e.HTS=`ˆ`,e.HTJ=`‰`,e.VTS=`Š`,e.PLD=`‹`,e.PLU=`Œ`,e.RI=``,e.SS2=`Ž`,e.SS3=``,e.DCS=``,e.PU1=`‘`,e.PU2=`’`,e.STS=`“`,e.CCH=`”`,e.MW=`•`,e.SPA=`–`,e.EPA=`—`,e.SOS=`˜`,e.SGCI=`™`,e.SCI=`š`,e.CSI=`›`,e.ST=`œ`,e.OSC=``,e.PM=`ž`,e.APC=`Ÿ`}(r||(t.C1=r={})),function(e){e.ST=`${n.ESC}\\`}(i||(t.C1_ESCAPED=i={}))},7399:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.evaluateKeyboardEvent=void 0;let r=n(2584),i={48:[`0`,`)`],49:[`1`,`!`],50:[`2`,`@`],51:[`3`,`#`],52:[`4`,`$`],53:[`5`,`%`],54:[`6`,`^`],55:[`7`,`&`],56:[`8`,`*`],57:[`9`,`(`],186:[`;`,`:`],187:[`=`,`+`],188:[`,`,`<`],189:[`-`,`_`],190:[`.`,`>`],191:[`/`,`?`],192:["`",`~`],219:[`[`,`{`],220:[`\\`,`|`],221:[`]`,`}`],222:[`'`,`"`]};t.evaluateKeyboardEvent=function(e,t,n,a){let o={type:0,cancel:!1,key:void 0},s=!!e.shiftKey|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key===`UIKeyInputUpArrow`?o.key=t?r.C0.ESC+`OA`:r.C0.ESC+`[A`:e.key===`UIKeyInputLeftArrow`?o.key=t?r.C0.ESC+`OD`:r.C0.ESC+`[D`:e.key===`UIKeyInputRightArrow`?o.key=t?r.C0.ESC+`OC`:r.C0.ESC+`[C`:e.key===`UIKeyInputDownArrow`&&(o.key=t?r.C0.ESC+`OB`:r.C0.ESC+`[B`);break;case 8:if(e.altKey){o.key=r.C0.ESC+r.C0.DEL;break}o.key=r.C0.DEL;break;case 9:if(e.shiftKey){o.key=r.C0.ESC+`[Z`;break}o.key=r.C0.HT,o.cancel=!0;break;case 13:o.key=e.altKey?r.C0.ESC+r.C0.CR:r.C0.CR,o.cancel=!0;break;case 27:o.key=r.C0.ESC,e.altKey&&(o.key=r.C0.ESC+r.C0.ESC),o.cancel=!0;break;case 37:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`D`,o.key===r.C0.ESC+`[1;3D`&&(o.key=r.C0.ESC+(n?`b`:`[1;5D`))):o.key=t?r.C0.ESC+`OD`:r.C0.ESC+`[D`;break;case 39:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`C`,o.key===r.C0.ESC+`[1;3C`&&(o.key=r.C0.ESC+(n?`f`:`[1;5C`))):o.key=t?r.C0.ESC+`OC`:r.C0.ESC+`[C`;break;case 38:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`A`,n||o.key!==r.C0.ESC+`[1;3A`||(o.key=r.C0.ESC+`[1;5A`)):o.key=t?r.C0.ESC+`OA`:r.C0.ESC+`[A`;break;case 40:if(e.metaKey)break;s?(o.key=r.C0.ESC+`[1;`+(s+1)+`B`,n||o.key!==r.C0.ESC+`[1;3B`||(o.key=r.C0.ESC+`[1;5B`)):o.key=t?r.C0.ESC+`OB`:r.C0.ESC+`[B`;break;case 45:e.shiftKey||e.ctrlKey||(o.key=r.C0.ESC+`[2~`);break;case 46:o.key=s?r.C0.ESC+`[3;`+(s+1)+`~`:r.C0.ESC+`[3~`;break;case 36:o.key=s?r.C0.ESC+`[1;`+(s+1)+`H`:t?r.C0.ESC+`OH`:r.C0.ESC+`[H`;break;case 35:o.key=s?r.C0.ESC+`[1;`+(s+1)+`F`:t?r.C0.ESC+`OF`:r.C0.ESC+`[F`;break;case 33:e.shiftKey?o.type=2:e.ctrlKey?o.key=r.C0.ESC+`[5;`+(s+1)+`~`:o.key=r.C0.ESC+`[5~`;break;case 34:e.shiftKey?o.type=3:e.ctrlKey?o.key=r.C0.ESC+`[6;`+(s+1)+`~`:o.key=r.C0.ESC+`[6~`;break;case 112:o.key=s?r.C0.ESC+`[1;`+(s+1)+`P`:r.C0.ESC+`OP`;break;case 113:o.key=s?r.C0.ESC+`[1;`+(s+1)+`Q`:r.C0.ESC+`OQ`;break;case 114:o.key=s?r.C0.ESC+`[1;`+(s+1)+`R`:r.C0.ESC+`OR`;break;case 115:o.key=s?r.C0.ESC+`[1;`+(s+1)+`S`:r.C0.ESC+`OS`;break;case 116:o.key=s?r.C0.ESC+`[15;`+(s+1)+`~`:r.C0.ESC+`[15~`;break;case 117:o.key=s?r.C0.ESC+`[17;`+(s+1)+`~`:r.C0.ESC+`[17~`;break;case 118:o.key=s?r.C0.ESC+`[18;`+(s+1)+`~`:r.C0.ESC+`[18~`;break;case 119:o.key=s?r.C0.ESC+`[19;`+(s+1)+`~`:r.C0.ESC+`[19~`;break;case 120:o.key=s?r.C0.ESC+`[20;`+(s+1)+`~`:r.C0.ESC+`[20~`;break;case 121:o.key=s?r.C0.ESC+`[21;`+(s+1)+`~`:r.C0.ESC+`[21~`;break;case 122:o.key=s?r.C0.ESC+`[23;`+(s+1)+`~`:r.C0.ESC+`[23~`;break;case 123:o.key=s?r.C0.ESC+`[24;`+(s+1)+`~`:r.C0.ESC+`[24~`;break;default:if(!e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)if(n&&!a||!e.altKey||e.metaKey)!n||e.altKey||e.ctrlKey||e.shiftKey||!e.metaKey?e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?o.key=e.key:e.key&&e.ctrlKey&&(e.key===`_`&&(o.key=r.C0.US),e.key===`@`&&(o.key=r.C0.NUL)):e.keyCode===65&&(o.type=1);else{let t=i[e.keyCode]?.[+!!e.shiftKey];if(t)o.key=r.C0.ESC+t;else if(e.keyCode>=65&&e.keyCode<=90){let t=e.ctrlKey?e.keyCode-64:e.keyCode+32,n=String.fromCharCode(t);e.shiftKey&&(n=n.toUpperCase()),o.key=r.C0.ESC+n}else if(e.keyCode===32)o.key=r.C0.ESC+(e.ctrlKey?r.C0.NUL:` `);else if(e.key===`Dead`&&e.code.startsWith(`Key`)){let t=e.code.slice(3,4);e.shiftKey||(t=t.toLowerCase()),o.key=r.C0.ESC+t,o.cancel=!0}}else e.keyCode>=65&&e.keyCode<=90?o.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?o.key=r.C0.NUL:e.keyCode>=51&&e.keyCode<=55?o.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?o.key=r.C0.DEL:e.keyCode===219?o.key=r.C0.ESC:e.keyCode===220?o.key=r.C0.FS:e.keyCode===221&&(o.key=r.C0.GS)}return o}},482:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.Utf8ToUtf32=t.StringToUtf32=t.utf32ToString=t.stringFromCodePoint=void 0,t.stringFromCodePoint=function(e){return e>65535?(e-=65536,String.fromCharCode(55296+(e>>10))+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)},t.utf32ToString=function(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode(55296+(t>>10))+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r},t.StringToUtf32=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=1024*(this._interim-55296)+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=1024*(i-55296)+o-56320+65536:(t[r++]=i,t[r++]=o)}else i!==65279&&(t[r++]=i)}return r}},t.Utf8ToUtf32=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r,i,a,o,s=0,c=0,l=0;if(this.interim[0]){let r=!1,i=this.interim[0];i&=(224&i)==192?31:(240&i)==224?15:7;let a,o=0;for(;(a=63&this.interim[++o])&&o<4;)i<<=6,i|=a;let c=(224&this.interim[0])==192?2:(240&this.interim[0])==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(a=e[l++],(192&a)!=128){l--,r=!0;break}this.interim[o++]=a,i<<=6,i|=63&a}r||(c===2?i<128?l--:t[s++]=i:c===3?i<2048||i>=55296&&i<=57343||i===65279||(t[s++]=i):i<65536||i>1114111||(t[s++]=i)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;!(!(d<u)||128&(r=e[d])||128&(i=e[d+1])||128&(a=e[d+2])||128&(o=e[d+3]));)t[s++]=r,t[s++]=i,t[s++]=a,t[s++]=o,d+=4;if(r=e[d++],r<128)t[s++]=r;else if((224&r)==192){if(d>=n)return this.interim[0]=r,s;if(i=e[d++],(192&i)!=128){d--;continue}if(c=(31&r)<<6|63&i,c<128){d--;continue}t[s++]=c}else if((240&r)==224){if(d>=n)return this.interim[0]=r,s;if(i=e[d++],(192&i)!=128){d--;continue}if(d>=n)return this.interim[0]=r,this.interim[1]=i,s;if(a=e[d++],(192&a)!=128){d--;continue}if(c=(15&r)<<12|(63&i)<<6|63&a,c<2048||c>=55296&&c<=57343||c===65279)continue;t[s++]=c}else if((248&r)==240){if(d>=n)return this.interim[0]=r,s;if(i=e[d++],(192&i)!=128){d--;continue}if(d>=n)return this.interim[0]=r,this.interim[1]=i,s;if(a=e[d++],(192&a)!=128){d--;continue}if(d>=n)return this.interim[0]=r,this.interim[1]=i,this.interim[2]=a,s;if(o=e[d++],(192&o)!=128){d--;continue}if(c=(7&r)<<18|(63&i)<<12|(63&a)<<6|63&o,c<65536||c>1114111)continue;t[s++]=c}}return s}}},225:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.UnicodeV6=void 0;let n=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],r=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],i;t.UnicodeV6=class{constructor(){if(this.version=`6`,!i){i=new Uint8Array(65536),i.fill(1),i[0]=0,i.fill(0,1,32),i.fill(0,127,160),i.fill(2,4352,4448),i[9001]=2,i[9002]=2,i.fill(2,11904,42192),i[12351]=1,i.fill(2,44032,55204),i.fill(2,63744,64256),i.fill(2,65040,65050),i.fill(2,65072,65136),i.fill(2,65280,65377),i.fill(2,65504,65511);for(let e=0;e<n.length;++e)i.fill(0,n[e][0],n[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?i[e]:function(e,t){let n,r=0,i=t.length-1;if(e<t[0][0]||e>t[i][1])return!1;for(;i>=r;)if(n=r+i>>1,e>t[n][1])r=n+1;else{if(!(e<t[n][0]))return!0;i=n-1}return!1}(e,r)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}}},5981:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.WriteBuffer=void 0;let r=n(8460),i=n(844);class a extends i.Disposable{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this.register(new r.EventEmitter),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t)return void(this._syncCalls=0);if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;let n;for(this._isSyncWriting=!0;n=this._writeBuffer.shift();){this._action(n);let e=this._callbacks.shift();e&&e()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>5e7)throw Error(`write data discarded, use flow control to avoid losing data`);if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput)return this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),void this._innerWrite();setTimeout((()=>this._innerWrite()))}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let n=e||Date.now();for(;this._writeBuffer.length>this._bufferOffset;){let e=this._writeBuffer[this._bufferOffset],r=this._action(e,t);if(r){r.catch((e=>(queueMicrotask((()=>{throw e})),Promise.resolve(!1)))).then(e=>Date.now()-n>=12?setTimeout((()=>this._innerWrite(0,e))):this._innerWrite(n,e));return}let i=this._callbacks[this._bufferOffset];if(i&&i(),this._bufferOffset++,this._pendingData-=e.length,Date.now()-n>=12)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>50&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout((()=>this._innerWrite()))):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}}t.WriteBuffer=a},5941:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.toRgbString=t.parseColor=void 0;let n=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,r=/^[\da-f]+$/;function i(e,t){let n=e.toString(16),r=n.length<2?`0`+n:n;switch(t){case 4:return n[0];case 8:return r;case 12:return(r+r).slice(0,3);default:return r+r}}t.parseColor=function(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf(`rgb:`)===0){t=t.slice(4);let e=n.exec(t);if(e){let t=e[1]?15:e[4]?255:e[7]?4095:65535;return[Math.round(parseInt(e[1]||e[4]||e[7]||e[10],16)/t*255),Math.round(parseInt(e[2]||e[5]||e[8]||e[11],16)/t*255),Math.round(parseInt(e[3]||e[6]||e[9]||e[12],16)/t*255)]}}else if(t.indexOf(`#`)===0&&(t=t.slice(1),r.exec(t)&&[3,6,9,12].includes(t.length))){let e=t.length/3,n=[0,0,0];for(let r=0;r<3;++r){let i=parseInt(t.slice(e*r,e*r+e),16);n[r]=e===1?i<<4:e===2?i:e===3?i>>4:i>>8}return n}},t.toRgbString=function(e,t=16){let[n,r,a]=e;return`rgb:${i(n,t)}/${i(r,t)}/${i(a,t)}`}},5770:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.PAYLOAD_LIMIT=void 0,t.PAYLOAD_LIMIT=1e7},6351:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.DcsHandler=t.DcsParser=void 0;let r=n(482),i=n(8742),a=n(5770),o=[];t.DcsParser=class{constructor(){this._handlers=Object.create(null),this._active=o,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=o}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=o,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||o,this._active.length)for(let e=this._active.length-1;e>=0;e--)this._active[e].hook(t);else this._handlerFb(this._ident,`HOOK`,t)}put(e,t,n){if(this._active.length)for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n);else this._handlerFb(this._ident,`PUT`,(0,r.utf32ToString)(e,t,n))}unhook(e,t=!0){if(this._active.length){let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&!1===n){for(;r>=0&&(n=this._active[r].unhook(e),!0!==n);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].unhook(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}else this._handlerFb(this._ident,`UNHOOK`,e);this._active=o,this._ident=0}};let s=new i.Params;s.addParam(0),t.DcsHandler=class{constructor(e){this._handler=e,this._data=``,this._params=s,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():s,this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=(0,r.utf32ToString)(e,t,n),this._data.length>a.PAYLOAD_LIMIT&&(this._data=``,this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then((e=>(this._params=s,this._data=``,this._hitLimit=!1,e)));return this._params=s,this._data=``,this._hitLimit=!1,t}}},2015:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.EscapeSequenceParser=t.VT500_TRANSITION_TABLE=t.TransitionTable=void 0;let r=n(844),i=n(8742),a=n(6242),o=n(6351);class s{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,n,r){this.table[t<<8|e]=n<<4|r}addMany(e,t,n,r){for(let i=0;i<e.length;i++)this.table[t<<8|e[i]]=n<<4|r}}t.TransitionTable=s,t.VT500_TRANSITION_TABLE=function(){let e=new s(4095),t=Array.apply(null,Array(256)).map(((e,t)=>t)),n=(e,n)=>t.slice(e,n),r=n(32,127),i=n(0,24);i.push(25),i.push.apply(i,n(28,32));let a=n(0,14),o;for(o in e.setDefault(1,0),e.addMany(r,0,2,0),a)e.addMany([24,26,153,154],o,3,0),e.addMany(n(128,144),o,3,0),e.addMany(n(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(i,0,3,0),e.addMany(i,1,3,1),e.add(127,1,0,1),e.addMany(i,8,0,8),e.addMany(i,3,3,3),e.add(127,3,0,3),e.addMany(i,4,3,4),e.add(127,4,0,4),e.addMany(i,6,3,6),e.addMany(i,5,3,5),e.add(127,5,0,5),e.addMany(i,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(r,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(n(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(r,7,0,7),e.addMany(i,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(n(64,127),3,7,0),e.addMany(n(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(n(48,60),4,8,4),e.addMany(n(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(n(32,64),6,0,6),e.add(127,6,0,6),e.addMany(n(64,127),6,0,0),e.addMany(n(32,48),3,9,5),e.addMany(n(32,48),5,9,5),e.addMany(n(48,64),5,0,6),e.addMany(n(64,127),5,7,0),e.addMany(n(32,48),4,9,5),e.addMany(n(32,48),1,9,2),e.addMany(n(32,48),2,9,2),e.addMany(n(48,127),2,10,0),e.addMany(n(48,80),1,10,0),e.addMany(n(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(n(96,127),1,10,0),e.add(80,1,11,9),e.addMany(i,9,0,9),e.add(127,9,0,9),e.addMany(n(28,32),9,0,9),e.addMany(n(32,48),9,9,12),e.addMany(n(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(i,11,0,11),e.addMany(n(32,128),11,0,11),e.addMany(n(28,32),11,0,11),e.addMany(i,10,0,10),e.add(127,10,0,10),e.addMany(n(28,32),10,0,10),e.addMany(n(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(n(32,48),10,9,12),e.addMany(i,12,0,12),e.add(127,12,0,12),e.addMany(n(28,32),12,0,12),e.addMany(n(32,48),12,9,12),e.addMany(n(48,64),12,0,11),e.addMany(n(64,127),12,12,13),e.addMany(n(64,127),10,12,13),e.addMany(n(64,127),9,12,13),e.addMany(i,13,13,13),e.addMany(r,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(160,0,2,0),e.add(160,8,5,8),e.add(160,6,0,6),e.add(160,11,0,11),e.add(160,13,13,13),e}();class c extends r.Disposable{constructor(e=t.VT500_TRANSITION_TABLE){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new i.Params,this._params.addParam(0),this._collect=0,this.precedingCodepoint=0,this._printHandlerFb=(e,t,n)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,t)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this.register((0,r.toDisposable)((()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)}))),this._oscParser=this.register(new a.OscParser),this._dcsParser=this.register(new o.DcsParser),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:`\\`},(()=>!0))}_identifier(e,t=[64,126]){let n=0;if(e.prefix){if(e.prefix.length>1)throw Error(`only one byte as prefix supported`);if(n=e.prefix.charCodeAt(0),n&&60>n||n>63)throw Error(`prefix must be in range 0x3c .. 0x3f`)}if(e.intermediates){if(e.intermediates.length>2)throw Error(`only two bytes as intermediates are supported`);for(let t=0;t<e.intermediates.length;++t){let r=e.intermediates.charCodeAt(t);if(32>r||r>47)throw Error(`intermediate must be in range 0x20 .. 0x2f`);n<<=8,n|=r}}if(e.final.length!==1)throw Error(`final must be a single byte`);let r=e.final.charCodeAt(0);if(t[0]>r||r>t[1])throw Error(`final must be in range ${t[0]} .. ${t[1]}`);return n<<=8,n|=r,n}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(255&e)),e>>=8;return t.reverse().join(``)}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let n=this._identifier(e,[48,126]);this._escHandlers[n]===void 0&&(this._escHandlers[n]=[]);let r=this._escHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let n=this._identifier(e);this._csiHandlers[n]===void 0&&(this._csiHandlers[n]=[]);let r=this._csiHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingCodepoint=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,n,r,i){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=n,this._parseStack.transition=r,this._parseStack.chunkPos=i}parse(e,t,n){let r,i=0,a=0,o=0;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,o=this._parseStack.chunkPos+1;else{if(n===void 0||this._parseStack.state===1)throw this._parseStack.state=1,Error(`improper continuation due to previous async handler, giving up parsing`);let t=this._parseStack.handlers,a=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(!1===n&&a>-1){for(;a>=0&&(r=t[a](this._params),!0!==r);a--)if(r instanceof Promise)return this._parseStack.handlerPos=a,r}this._parseStack.handlers=[];break;case 4:if(!1===n&&a>-1){for(;a>=0&&(r=t[a](),!0!==r);a--)if(r instanceof Promise)return this._parseStack.handlerPos=a,r}this._parseStack.handlers=[];break;case 6:if(i=e[this._parseStack.chunkPos],r=this._dcsParser.unhook(i!==24&&i!==26,n),r)return r;i===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(i=e[this._parseStack.chunkPos],r=this._oscParser.end(i!==24&&i!==26,n),r)return r;i===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0}this._parseStack.state=0,o=this._parseStack.chunkPos+1,this.precedingCodepoint=0,this.currentState=15&this._parseStack.transition}for(let n=o;n<t;++n){switch(i=e[n],a=this._transitions.table[this.currentState<<8|(i<160?i:160)],a>>4){case 2:for(let r=n+1;;++r){if(r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}if(++r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}if(++r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}if(++r>=t||(i=e[r])<32||i>126&&i<160){this._printHandler(e,n,r),n=r-1;break}}break;case 3:this._executeHandlers[i]?this._executeHandlers[i]():this._executeHandlerFb(i),this.precedingCodepoint=0;break;case 0:break;case 1:if(this._errorHandler({position:n,code:i,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let o=this._csiHandlers[this._collect<<8|i],s=o?o.length-1:-1;for(;s>=0&&(r=o[s](this._params),!0!==r);s--)if(r instanceof Promise)return this._preserveStack(3,o,s,a,n),r;s<0&&this._csiHandlerFb(this._collect<<8|i,this._params),this.precedingCodepoint=0;break;case 8:do switch(i){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(i-48)}while(++n<t&&(i=e[n])>47&&i<60);n--;break;case 9:this._collect<<=8,this._collect|=i;break;case 10:let c=this._escHandlers[this._collect<<8|i],l=c?c.length-1:-1;for(;l>=0&&(r=c[l](),!0!==r);l--)if(r instanceof Promise)return this._preserveStack(4,c,l,a,n),r;l<0&&this._escHandlerFb(this._collect<<8|i),this.precedingCodepoint=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|i,this._params);break;case 13:for(let r=n+1;;++r)if(r>=t||(i=e[r])===24||i===26||i===27||i>127&&i<160){this._dcsParser.put(e,n,r),n=r-1;break}break;case 14:if(r=this._dcsParser.unhook(i!==24&&i!==26),r)return this._preserveStack(6,[],0,a,n),r;i===27&&(a|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingCodepoint=0;break;case 4:this._oscParser.start();break;case 5:for(let r=n+1;;r++)if(r>=t||(i=e[r])<32||i>127&&i<160){this._oscParser.put(e,n,r),n=r-1;break}break;case 6:if(r=this._oscParser.end(i!==24&&i!==26),r)return this._preserveStack(5,[],0,a,n),r;i===27&&(a|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingCodepoint=0}this.currentState=15&a}}}t.EscapeSequenceParser=c},6242:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.OscHandler=t.OscParser=void 0;let r=n(5770),i=n(482),a=[];t.OscParser=class{constructor(){this._state=0,this._active=a,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=a}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=a,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||a,this._active.length)for(let e=this._active.length-1;e>=0;e--)this._active[e].start();else this._handlerFb(this._id,`START`)}_put(e,t,n){if(this._active.length)for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n);else this._handlerFb(this._id,`PUT`,(0,i.utf32ToString)(e,t,n))}start(){this.reset(),this._state=1}put(e,t,n){if(this._state!==3){if(this._state===1)for(;t<n;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n)return void(this._state=3);this._id===-1&&(this._id=0),this._id=10*this._id+n-48}this._state===2&&n-t>0&&this._put(e,t,n)}}end(e,t=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),this._active.length){let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&!1===n){for(;r>=0&&(n=this._active[r].end(e),!0!==n);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].end(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}else this._handlerFb(this._id,`END`,e);this._active=a,this._id=-1,this._state=0}}},t.OscHandler=class{constructor(e){this._handler=e,this._data=``,this._hitLimit=!1}start(){this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=(0,i.utf32ToString)(e,t,n),this._data.length>r.PAYLOAD_LIMIT&&(this._data=``,this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then((e=>(this._data=``,this._hitLimit=!1,e)));return this._data=``,this._hitLimit=!1,t}}},8742:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.Params=void 0;let n=2147483647;class r{static fromArray(e){let t=new r;if(!e.length)return t;for(let n=+!!Array.isArray(e[0]);n<e.length;++n){let r=e[n];if(Array.isArray(r))for(let e=0;e<r.length;++e)t.addSubParam(r[e]);else t.addParam(r)}return t}constructor(e=32,t=32){if(this.maxLength=e,this.maxSubParamsLength=t,t>256)throw Error(`maxSubParamsLength must not be greater than 256`);this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(t),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}clone(){let e=new r(this.maxLength,this.maxSubParamsLength);return e.params.set(this.params),e.length=this.length,e._subParams.set(this._subParams),e._subParamsLength=this._subParamsLength,e._subParamsIdx.set(this._subParamsIdx),e._rejectDigits=this._rejectDigits,e._rejectSubDigits=this._rejectSubDigits,e._digitIsSub=this._digitIsSub,e}toArray(){let e=[];for(let t=0;t<this.length;++t){e.push(this.params[t]);let n=this._subParamsIdx[t]>>8,r=255&this._subParamsIdx[t];r-n>0&&e.push(Array.prototype.slice.call(this._subParams,n,r))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength)this._rejectDigits=!0;else{if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>n?n:e}}addSubParam(e){if(this._digitIsSub=!0,this.length)if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength)this._rejectSubDigits=!0;else{if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParams[this._subParamsLength++]=e>n?n:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(255&this._subParamsIdx[e])-(this._subParamsIdx[e]>>8)>0}getSubParams(e){let t=this._subParamsIdx[e]>>8,n=255&this._subParamsIdx[e];return n-t>0?this._subParams.subarray(t,n):null}getSubParamsAll(){let e={};for(let t=0;t<this.length;++t){let n=this._subParamsIdx[t]>>8,r=255&this._subParamsIdx[t];r-n>0&&(e[t]=this._subParams.slice(n,r))}return e}addDigit(e){let t;if(this._rejectDigits||!(t=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let r=this._digitIsSub?this._subParams:this.params,i=r[t-1];r[t-1]=~i?Math.min(10*i+e,n):e}}t.Params=r},5741:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.AddonManager=void 0,t.AddonManager=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}}},8771:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.BufferApiView=void 0;let r=n(3785),i=n(511);t.BufferApiView=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new r.BufferLineApiView(t)}getNullCell(){return new i.CellData}}},3785:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.BufferLineApiView=void 0;let r=n(511);t.BufferLineApiView=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new r.CellData)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}}},8285:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.BufferNamespaceApi=void 0;let r=n(8771),i=n(8460),a=n(844);class o extends a.Disposable{constructor(e){super(),this._core=e,this._onBufferChange=this.register(new i.EventEmitter),this.onBufferChange=this._onBufferChange.event,this._normal=new r.BufferApiView(this._core.buffers.normal,`normal`),this._alternate=new r.BufferApiView(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate((()=>this._onBufferChange.fire(this.active)))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}}t.BufferNamespaceApi=o},7975:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.ParserApi=void 0,t.ParserApi=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,(e=>t(e.toArray())))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,((e,n)=>t(e,n.toArray())))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}}},7090:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.UnicodeApi=void 0,t.UnicodeApi=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}}},744:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,`__esModule`,{value:!0}),t.BufferService=t.MINIMUM_ROWS=t.MINIMUM_COLS=void 0;let a=n(8460),o=n(844),s=n(5295),c=n(2585);t.MINIMUM_COLS=2,t.MINIMUM_ROWS=1;let l=t.BufferService=class extends o.Disposable{get buffer(){return this.buffers.active}constructor(e){super(),this.isUserScrolling=!1,this._onResize=this.register(new a.EventEmitter),this.onResize=this._onResize.event,this._onScroll=this.register(new a.EventEmitter),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,t.MINIMUM_COLS),this.rows=Math.max(e.rawOptions.rows||0,t.MINIMUM_ROWS),this.buffers=this.register(new s.BufferSet(e,this))}resize(e,t){this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let n=this.buffer,r;r=this._cachedBlankLine,r&&r.length===this.cols&&r.getFg(0)===e.fg&&r.getBg(0)===e.bg||(r=n.getBlankLine(e,t),this._cachedBlankLine=r),r.isWrapped=t;let i=n.ybase+n.scrollTop,a=n.ybase+n.scrollBottom;if(n.scrollTop===0){let e=n.lines.isFull;a===n.lines.length-1?e?n.lines.recycle().copyFrom(r):n.lines.push(r.clone()):n.lines.splice(a+1,0,r.clone()),e?this.isUserScrolling&&(n.ydisp=Math.max(n.ydisp-1,0)):(n.ybase++,this.isUserScrolling||n.ydisp++)}else{let e=a-i+1;n.lines.shiftElements(i+1,e-1,-1),n.lines.set(a,r.clone())}this.isUserScrolling||(n.ydisp=n.ybase),this._onScroll.fire(n.ydisp)}scrollLines(e,t,n){let r=this.buffer;if(e<0){if(r.ydisp===0)return;this.isUserScrolling=!0}else e+r.ydisp>=r.ybase&&(this.isUserScrolling=!1);let i=r.ydisp;r.ydisp=Math.max(Math.min(r.ydisp+e,r.ybase),0),i!==r.ydisp&&(t||this._onScroll.fire(r.ydisp))}};t.BufferService=l=r([i(0,c.IOptionsService)],l)},7994:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.CharsetService=void 0,t.CharsetService=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}}},1753:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,`__esModule`,{value:!0}),t.CoreMouseService=void 0;let a=n(2585),o=n(8460),s=n(844),c={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button!==4&&e.action===1&&(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>e.action!==32||e.button!==3},ANY:{events:31,restrict:e=>!0}};function l(e,t){let n=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(n|=64,n|=e.action):(n|=3&e.button,4&e.button&&(n|=64),8&e.button&&(n|=128),e.action===32?n|=32:e.action!==0||t||(n|=3)),n}let u=String.fromCharCode,d={DEFAULT:e=>{let t=[l(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?``:`${u(t[0])}${u(t[1])}${u(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`[<${l(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`[<${l(e,!0)};${e.x};${e.y}${t}`}},f=t.CoreMouseService=class extends s.Disposable{constructor(e,t){super(),this._bufferService=e,this._coreService=t,this._protocols={},this._encodings={},this._activeProtocol=``,this._activeEncoding=``,this._lastEvent=null,this._onProtocolChange=this.register(new o.EventEmitter),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(c))this.addProtocol(e,c[e]);for(let e of Object.keys(d))this.addEncoding(e,d[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol=`NONE`,this.activeEncoding=`DEFAULT`,this._lastEvent=null}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding===`SGR_PIXELS`))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding===`DEFAULT`?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(1&e),up:!!(2&e),drag:!!(4&e),move:!!(8&e),wheel:!!(16&e)}}_equalEvents(e,t,n){if(n){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return e.button===t.button&&e.action===t.action&&e.ctrl===t.ctrl&&e.alt===t.alt&&e.shift===t.shift}};t.CoreMouseService=f=r([i(0,a.IBufferService),i(1,a.ICoreService)],f)},6975:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,`__esModule`,{value:!0}),t.CoreService=void 0;let a=n(1439),o=n(8460),s=n(844),c=n(2585),l=Object.freeze({insertMode:!1}),u=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,origin:!1,reverseWraparound:!1,sendFocus:!1,wraparound:!0}),d=t.CoreService=class extends s.Disposable{constructor(e,t,n){super(),this._bufferService=e,this._logService=t,this._optionsService=n,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this.register(new o.EventEmitter),this.onData=this._onData.event,this._onUserInput=this.register(new o.EventEmitter),this.onUserInput=this._onUserInput.event,this._onBinary=this.register(new o.EventEmitter),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this.register(new o.EventEmitter),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=(0,a.clone)(l),this.decPrivateModes=(0,a.clone)(u)}reset(){this.modes=(0,a.clone)(l),this.decPrivateModes=(0,a.clone)(u)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let n=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&n.ybase!==n.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`,(()=>e.split(``).map((e=>e.charCodeAt(0))))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`,(()=>e.split(``).map((e=>e.charCodeAt(0))))),this._onBinary.fire(e))}};t.CoreService=d=r([i(0,c.IBufferService),i(1,c.ILogService),i(2,c.IOptionsService)],d)},9074:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.DecorationService=void 0;let r=n(8055),i=n(8460),a=n(844),o=n(6106),s=0,c=0;class l extends a.Disposable{get decorations(){return this._decorations.values()}constructor(){super(),this._decorations=new o.SortedList((e=>e?.marker.line)),this._onDecorationRegistered=this.register(new i.EventEmitter),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this.register(new i.EventEmitter),this.onDecorationRemoved=this._onDecorationRemoved.event,this.register((0,a.toDisposable)((()=>this.reset())))}registerDecoration(e){if(e.marker.isDisposed)return;let t=new u(e);if(t){let e=t.marker.onDispose((()=>t.dispose()));t.onDispose((()=>{t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),e.dispose())})),this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,n){let r=0,i=0;for(let a of this._decorations.getKeyIterator(t))r=a.options.x??0,i=r+(a.options.width??1),e>=r&&e<i&&(!n||(a.options.layer??`bottom`)===n)&&(yield a)}forEachDecorationAtCell(e,t,n,r){this._decorations.forEachByKey(t,(t=>{s=t.options.x??0,c=s+(t.options.width??1),e>=s&&e<c&&(!n||(t.options.layer??`bottom`)===n)&&r(t)}))}}t.DecorationService=l;class u extends a.Disposable{get isDisposed(){return this._isDisposed}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=r.css.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=r.css.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}constructor(e){super(),this.options=e,this.onRenderEmitter=this.register(new i.EventEmitter),this.onRender=this.onRenderEmitter.event,this._onDispose=this.register(new i.EventEmitter),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position=`full`)}dispose(){this._onDispose.fire(),super.dispose()}}},4348:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.InstantiationService=t.ServiceCollection=void 0;let r=n(2585),i=n(8343);class a{constructor(...e){this._entries=new Map;for(let[t,n]of e)this.set(t,n)}set(e,t){let n=this._entries.get(e);return this._entries.set(e,t),n}forEach(e){for(let[t,n]of this._entries.entries())e(t,n)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}}t.ServiceCollection=a,t.InstantiationService=class{constructor(){this._services=new a,this._services.set(r.IInstantiationService,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let n=(0,i.getServiceDependencies)(e).sort(((e,t)=>e.index-t.index)),r=[];for(let t of n){let n=this._services.get(t.id);if(!n)throw Error(`[createInstance] ${e.name} depends on UNKNOWN service ${t.id}.`);r.push(n)}let a=n.length>0?n[0].index:t.length;if(t.length!==a)throw Error(`[createInstance] First service dependency of ${e.name} at position ${a+1} conflicts with ${t.length} static arguments`);return new e(...t,...r)}}},7866:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,`__esModule`,{value:!0}),t.traceCall=t.setTraceLogger=t.LogService=void 0;let a=n(844),o=n(2585),s={trace:o.LogLevelEnum.TRACE,debug:o.LogLevelEnum.DEBUG,info:o.LogLevelEnum.INFO,warn:o.LogLevelEnum.WARN,error:o.LogLevelEnum.ERROR,off:o.LogLevelEnum.OFF},c,l=t.LogService=class extends a.Disposable{get logLevel(){return this._logLevel}constructor(e){super(),this._optionsService=e,this._logLevel=o.LogLevelEnum.OFF,this._updateLogLevel(),this.register(this._optionsService.onSpecificOptionChange(`logLevel`,(()=>this._updateLogLevel()))),c=this}_updateLogLevel(){this._logLevel=s[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]==`function`&&(e[t]=e[t]())}_log(e,t,n){this._evalLazyOptionalParams(n),e.call(console,(this._optionsService.options.logger?``:`xterm.js: `)+t,...n)}trace(e,...t){this._logLevel<=o.LogLevelEnum.TRACE&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,e,t)}debug(e,...t){this._logLevel<=o.LogLevelEnum.DEBUG&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,e,t)}info(e,...t){this._logLevel<=o.LogLevelEnum.INFO&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,e,t)}warn(e,...t){this._logLevel<=o.LogLevelEnum.WARN&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,e,t)}error(e,...t){this._logLevel<=o.LogLevelEnum.ERROR&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,e,t)}};t.LogService=l=r([i(0,o.IOptionsService)],l),t.setTraceLogger=function(e){c=e},t.traceCall=function(e,t,n){if(typeof n.value!=`function`)throw Error(`not supported`);let r=n.value;n.value=function(...e){if(c.logLevel!==o.LogLevelEnum.TRACE)return r.apply(this,e);c.trace(`GlyphRenderer#${r.name}(${e.map((e=>JSON.stringify(e))).join(`, `)})`);let t=r.apply(this,e);return c.trace(`GlyphRenderer#${r.name} return`,t),t}}},7302:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.OptionsService=t.DEFAULT_OPTIONS=void 0;let r=n(8460),i=n(844);t.DEFAULT_OPTIONS={cols:80,rows:24,cursorBlink:!1,cursorStyle:`block`,cursorWidth:1,cursorInactiveStyle:`outline`,customGlyphs:!0,drawBoldTextInBrightColors:!0,fastScrollModifier:`alt`,fastScrollSensitivity:5,fontFamily:`courier-new, courier, monospace`,fontSize:15,fontWeight:`normal`,fontWeightBold:`bold`,ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:`info`,logger:null,scrollback:1e3,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},rightClickSelectsWord:n(6114).isMac,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:` ()[]{}',"\``,altClickMovesCursor:!0,convertEol:!1,termName:`xterm`,cancelEvents:!1,overviewRulerWidth:0};let a=[`normal`,`bold`,`100`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`900`];class o extends i.Disposable{constructor(e){super(),this._onOptionChange=this.register(new r.EventEmitter),this.onOptionChange=this._onOptionChange.event;let n=Object.assign({},t.DEFAULT_OPTIONS);for(let t in e)if(t in n)try{let r=e[t];n[t]=this._sanitizeAndValidateOption(t,r)}catch(e){console.error(e)}this.rawOptions=n,this.options=Object.assign({},n),this._setupOptions()}onSpecificOptionChange(e,t){return this.onOptionChange((n=>{n===e&&t(this.rawOptions[e])}))}onMultipleOptionChange(e,t){return this.onOptionChange((n=>{e.indexOf(n)!==-1&&t()}))}_setupOptions(){let e=e=>{if(!(e in t.DEFAULT_OPTIONS))throw Error(`No option with key "${e}"`);return this.rawOptions[e]},n=(e,n)=>{if(!(e in t.DEFAULT_OPTIONS))throw Error(`No option with key "${e}"`);n=this._sanitizeAndValidateOption(e,n),this.rawOptions[e]!==n&&(this.rawOptions[e]=n,this._onOptionChange.fire(e))};for(let t in this.rawOptions){let r={get:e.bind(this,t),set:n.bind(this,t)};Object.defineProperty(this.options,t,r)}}_sanitizeAndValidateOption(e,n){switch(e){case`cursorStyle`:if(n||=t.DEFAULT_OPTIONS[e],!function(e){return e===`block`||e===`underline`||e===`bar`}(n))throw Error(`"${n}" is not a valid value for ${e}`);break;case`wordSeparator`:n||=t.DEFAULT_OPTIONS[e];break;case`fontWeight`:case`fontWeightBold`:if(typeof n==`number`&&1<=n&&n<=1e3)break;n=a.includes(n)?n:t.DEFAULT_OPTIONS[e];break;case`cursorWidth`:n=Math.floor(n);case`lineHeight`:case`tabStopWidth`:if(n<1)throw Error(`${e} cannot be less than 1, value: ${n}`);break;case`minimumContrastRatio`:n=Math.max(1,Math.min(21,Math.round(10*n)/10));break;case`scrollback`:if((n=Math.min(n,4294967295))<0)throw Error(`${e} cannot be less than 0, value: ${n}`);break;case`fastScrollSensitivity`:case`scrollSensitivity`:if(n<=0)throw Error(`${e} cannot be less than or equal to 0, value: ${n}`);break;case`rows`:case`cols`:if(!n&&n!==0)throw Error(`${e} must be numeric, value: ${n}`);break;case`windowsPty`:n??={}}return n}}t.OptionsService=o},2660:function(e,t,n){var r=this&&this.__decorate||function(e,t,n,r){var i,a=arguments.length,o=a<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o},i=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};Object.defineProperty(t,`__esModule`,{value:!0}),t.OscLinkService=void 0;let a=n(2585),o=t.OscLinkService=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let n=t.addMarker(t.ybase+t.y),r={data:e,id:this._nextId++,lines:[n]};return n.onDispose((()=>this._removeMarkerFromLink(r,n))),this._dataByLinkId.set(r.id,r),r.id}let n=e,r=this._getEntryIdKey(n),i=this._entriesWithId.get(r);if(i)return this.addLineToLink(i.id,t.ybase+t.y),i.id;let a=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(n),data:n,lines:[a]};return a.onDispose((()=>this._removeMarkerFromLink(o,a))),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let n=this._dataByLinkId.get(e);if(n&&n.lines.every((e=>e.line!==t))){let e=this._bufferService.buffer.addMarker(t);n.lines.push(e),e.onDispose((()=>this._removeMarkerFromLink(n,e)))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let n=e.lines.indexOf(t);n!==-1&&(e.lines.splice(n,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};t.OscLinkService=o=r([i(0,a.IBufferService)],o)},8343:(e,t)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.createDecorator=t.getServiceDependencies=t.serviceRegistry=void 0;let n=`di$target`,r=`di$dependencies`;t.serviceRegistry=new Map,t.getServiceDependencies=function(e){return e[r]||[]},t.createDecorator=function(e){if(t.serviceRegistry.has(e))return t.serviceRegistry.get(e);let i=function(e,t,a){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);(function(e,t,i){t[n]===t?t[r].push({id:e,index:i}):(t[r]=[{id:e,index:i}],t[n]=t)})(i,e,a)};return i.toString=()=>e,t.serviceRegistry.set(e,i),i}},2585:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.IDecorationService=t.IUnicodeService=t.IOscLinkService=t.IOptionsService=t.ILogService=t.LogLevelEnum=t.IInstantiationService=t.ICharsetService=t.ICoreService=t.ICoreMouseService=t.IBufferService=void 0;let r=n(8343);var i;t.IBufferService=(0,r.createDecorator)(`BufferService`),t.ICoreMouseService=(0,r.createDecorator)(`CoreMouseService`),t.ICoreService=(0,r.createDecorator)(`CoreService`),t.ICharsetService=(0,r.createDecorator)(`CharsetService`),t.IInstantiationService=(0,r.createDecorator)(`InstantiationService`),function(e){e[e.TRACE=0]=`TRACE`,e[e.DEBUG=1]=`DEBUG`,e[e.INFO=2]=`INFO`,e[e.WARN=3]=`WARN`,e[e.ERROR=4]=`ERROR`,e[e.OFF=5]=`OFF`}(i||(t.LogLevelEnum=i={})),t.ILogService=(0,r.createDecorator)(`LogService`),t.IOptionsService=(0,r.createDecorator)(`OptionsService`),t.IOscLinkService=(0,r.createDecorator)(`OscLinkService`),t.IUnicodeService=(0,r.createDecorator)(`UnicodeService`),t.IDecorationService=(0,r.createDecorator)(`DecorationService`)},1480:(e,t,n)=>{Object.defineProperty(t,`__esModule`,{value:!0}),t.UnicodeService=void 0;let r=n(8460),i=n(225);t.UnicodeService=class{constructor(){this._providers=Object.create(null),this._active=``,this._onChange=new r.EventEmitter,this.onChange=this._onChange.event;let e=new i.UnicodeV6;this.register(e),this._active=e.version,this._activeProvider=e}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(e){let t=0,n=e.length;for(let r=0;r<n;++r){let i=e.charCodeAt(r);if(55296<=i&&i<=56319){if(++r>=n)return t+this.wcwidth(i);let a=e.charCodeAt(r);56320<=a&&a<=57343?i=1024*(i-55296)+a-56320+65536:t+=this.wcwidth(a)}t+=this.wcwidth(i)}return t}}}},t={};function n(r){var i=t[r];if(i!==void 0)return i.exports;var a=t[r]={exports:{}};return e[r].call(a.exports,a,a.exports,n),a.exports}var r={};return(()=>{var e=r;Object.defineProperty(e,`__esModule`,{value:!0}),e.Terminal=void 0;let t=n(9042),i=n(3236),a=n(844),o=n(5741),s=n(8285),c=n(7975),l=n(7090),u=[`cols`,`rows`];class d extends a.Disposable{constructor(e){super(),this._core=this.register(new i.Terminal(e)),this._addonManager=this.register(new o.AddonManager),this._publicOptions=Object.assign({},this._core.options);let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(u.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new c.ParserApi(this._core),this._parser}get unicode(){return this._checkProposedApi(),new l.UnicodeApi(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this.register(new s.BufferNamespaceApi(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
749
749
  `,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return t}_verifyIntegers(...e){for(let t of e)if(t===1/0||isNaN(t)||t%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(let t of e)if(t&&(t===1/0||isNaN(t)||t%1!=0||t<0))throw Error(`This API only accepts positive integers`)}}e.Terminal=d})(),r})()))}))(),KT=2,qT=1,JT=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(KT,Math.floor(u/e.css.cell.width)),rows:Math.max(qT,Math.floor(l/e.css.cell.height))}}};function YT({wsUrl:e,projectDir:t,logs:n,className:r}){let i=(0,_.useRef)(null),a=(0,_.useRef)(null),o=(0,_.useRef)(null),s=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(!i.current)return;let e=new GT.Terminal({theme:{background:`#0d1117`,foreground:`#e6edf3`,cursor:`#6366f1`,selectionBackground:`rgba(99, 102, 241, 0.3)`,black:`#0d1117`,red:`#f87171`,green:`#4ade80`,yellow:`#facc15`,blue:`#60a5fa`,magenta:`#c084fc`,cyan:`#22d3ee`,white:`#e6edf3`,brightBlack:`#484f58`,brightRed:`#fca5a5`,brightGreen:`#86efac`,brightYellow:`#fde68a`,brightBlue:`#93c5fd`,brightMagenta:`#d8b4fe`,brightCyan:`#67e8f9`,brightWhite:`#ffffff`},fontSize:12,fontFamily:`'SF Mono', Monaco, 'Cascadia Code', monospace`,cursorBlink:!0,cursorStyle:`bar`,scrollback:5e3,convertEol:!0}),t=new JT;e.loadAddon(t),e.open(i.current),t.fit(),a.current=e,o.current=t;let n=new ResizeObserver(()=>{try{t.fit()}catch{}});return n.observe(i.current),()=>{n.disconnect(),e.dispose(),a.current=null,o.current=null}},[]),(0,_.useEffect)(()=>{if(!a.current)return;let n=a.current,r=window.location.protocol===`https:`?`wss:`:`ws:`,i=e||`${r}//${window.location.host}/ws/terminal${t?`?cwd=${encodeURIComponent(t)}`:``}`,o=new WebSocket(i);return s.current=o,o.binaryType=`arraybuffer`,o.onmessage=e=>{e.data instanceof ArrayBuffer?n.write(new Uint8Array(e.data)):n.write(e.data)},o.onclose=()=>{n.write(`\r
750
750
  \x1B[90m[disconnected]\x1B[0m\r
751
- `)},n.onData(e=>{o.readyState===WebSocket.OPEN&&o.send(e)}),()=>{o.close(),s.current=null}},[e,t]),(0,_.useEffect)(()=>{if(!n||!a.current)return;let e=a.current;for(let t of n)e.writeln(t)},[n]),(0,k.jsx)(`div`,{ref:i,className:r,style:{flex:1,minHeight:0,overflow:`hidden`,background:`#0d1117`}})}function XT({tabs:e,active:t,onChange:n,className:r,buttonClassName:i,activeClassName:a}){return(0,k.jsx)(`nav`,{className:r,role:`tablist`,"aria-label":`Mobile navigation`,children:e.map(e=>{let r=e.id===t;return(0,k.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":r,className:`${i??``} ${r?a??``:``}`,onClick:()=>n(e.id),children:[(0,k.jsx)(`span`,{"aria-hidden":`true`,children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.id)})})}var Q={root:`_root_1wqny_2`,header:`_header_1wqny_10`,title:`_title_1wqny_21`,subtitle:`_subtitle_1wqny_28`,headerTabs:`_headerTabs_1wqny_34`,tabBtn:`_tabBtn_1wqny_40`,tabActive:`_tabActive_1wqny_51`,body:`_body_1wqny_58`,editor:`_editor_1wqny_67`,examples:`_examples_1wqny_75`,sectionLabel:`_sectionLabel_1wqny_81`,examplePills:`_examplePills_1wqny_89`,examplePill:`_examplePill_1wqny_89`,editorCols:`_editorCols_1wqny_109`,leftSidebar:`_leftSidebar_1wqny_119`,panel:`_panel_1wqny_128`,panelHeader:`_panelHeader_1wqny_135`,panelTitle:`_panelTitle_1wqny_142`,addBtn:`_addBtn_1wqny_149`,blockLabel:`_blockLabel_1wqny_160`,blockCheck:`_blockCheck_1wqny_170`,authField:`_authField_1wqny_173`,authFieldInput:`_authFieldInput_1wqny_183`,authFieldSelect:`_authFieldSelect_1wqny_193`,authFieldReq:`_authFieldReq_1wqny_204`,removeFieldBtn:`_removeFieldBtn_1wqny_205`,skillsList:`_skillsList_1wqny_208`,skillRow:`_skillRow_1wqny_210`,skillIcon:`_skillIcon_1wqny_218`,skillName:`_skillName_1wqny_220`,skillBadge:`_skillBadge_1wqny_229`,skillBadge_skill:`_skillBadge_skill_1wqny_237`,skillBadge_memory:`_skillBadge_memory_1wqny_238`,skillBadge_provider:`_skillBadge_provider_1wqny_239`,skillBadge_log:`_skillBadge_log_1wqny_240`,skillEmpty:`_skillEmpty_1wqny_242`,skillBtn:`_skillBtn_1wqny_244`,skillsEmpty:`_skillsEmpty_1wqny_246`,snapshotRow:`_snapshotRow_1wqny_249`,snapshotTs:`_snapshotTs_1wqny_258`,snapshotCount:`_snapshotCount_1wqny_259`,snapshotBtn:`_snapshotBtn_1wqny_260`,genStatus:`_genStatus_1wqny_263`,repairStatus:`_repairStatus_1wqny_265`,repairStatusTitle:`_repairStatusTitle_1wqny_266`,repairStatusProg:`_repairStatusProg_1wqny_267`,repairStatusFile:`_repairStatusFile_1wqny_268`,actionRow:`_actionRow_1wqny_271`,actionBtn:`_actionBtn_1wqny_273`,actionBtnIcon:`_actionBtnIcon_1wqny_275`,actionBtnActive:`_actionBtnActive_1wqny_276`,repairBtn:`_repairBtn_1wqny_278`,sandboxBtn:`_sandboxBtn_1wqny_280`,statsBar:`_statsBar_1wqny_282`,rightPanel:`_rightPanel_1wqny_285`,rightTabBar:`_rightTabBar_1wqny_296`,rightTab:`_rightTab_1wqny_296`,rightTabActive:`_rightTabActive_1wqny_313`,repairBar:`_repairBar_1wqny_316`,repairBarRow:`_repairBarRow_1wqny_326`,repairBarIcon:`_repairBarIcon_1wqny_327`,repairBarLabel:`_repairBarLabel_1wqny_328`,repairBarFile:`_repairBarFile_1wqny_329`,repairBarCounter:`_repairBarCounter_1wqny_330`,repairBarTime:`_repairBarTime_1wqny_331`,genBar:`_genBar_1wqny_333`,genBarRow:`_genBarRow_1wqny_343`,genBarRobot:`_genBarRobot_1wqny_344`,robotBob:`_robotBob_1wqny_1`,genBarLabel:`_genBarLabel_1wqny_345`,genBarFile:`_genBarFile_1wqny_346`,genBarCounter:`_genBarCounter_1wqny_347`,genBarTime:`_genBarTime_1wqny_348`,progressTrack:`_progressTrack_1wqny_350`,repairProgress:`_repairProgress_1wqny_351`,genProgress:`_genProgress_1wqny_352`,genDots:`_genDots_1wqny_355`,dot:`_dot_1wqny_356`,dot1:`_dot1_1wqny_357`,dotBounce:`_dotBounce_1wqny_1`,dot2:`_dot2_1wqny_358`,dot3:`_dot3_1wqny_359`,stopBtn:`_stopBtn_1wqny_362`,codeArea:`_codeArea_1wqny_365`,sandboxWrap:`_sandboxWrap_1wqny_366`,sandboxFrame:`_sandboxFrame_1wqny_367`,sandboxEmpty:`_sandboxEmpty_1wqny_368`,sandboxStartBtn:`_sandboxStartBtn_1wqny_369`,sandboxStatusBar:`_sandboxStatusBar_1wqny_372`,sandboxStatusDot:`_sandboxStatusDot_1wqny_381`,sandboxStatusText:`_sandboxStatusText_1wqny_382`,sandboxStartBtnSmall:`_sandboxStartBtnSmall_1wqny_383`,runtimeErrors:`_runtimeErrors_1wqny_386`,runtimeErrorsHeader:`_runtimeErrorsHeader_1wqny_392`,runtimeErrorsFix:`_runtimeErrorsFix_1wqny_401`,runtimeErrorsDismiss:`_runtimeErrorsDismiss_1wqny_413`,runtimeErrorLine:`_runtimeErrorLine_1wqny_414`,sandboxConsole:`_sandboxConsole_1wqny_425`,sandboxConsoleCollapsed:`_sandboxConsoleCollapsed_1wqny_434`,sandboxConsoleHeader:`_sandboxConsoleHeader_1wqny_435`,sandboxConsoleTitle:`_sandboxConsoleTitle_1wqny_447`,sandboxConsolePort:`_sandboxConsolePort_1wqny_448`,sandboxConsoleDots:`_sandboxConsoleDots_1wqny_449`,sandboxConsoleToggle:`_sandboxConsoleToggle_1wqny_450`,sandboxReloadBtn:`_sandboxReloadBtn_1wqny_451`,sandboxStopBtn:`_sandboxStopBtn_1wqny_453`,sandboxConsoleBody:`_sandboxConsoleBody_1wqny_455`,sandboxLogLine:`_sandboxLogLine_1wqny_461`,sandboxLogPhase:`_sandboxLogPhase_1wqny_470`,sandboxLogError:`_sandboxLogError_1wqny_471`,sandboxLogWarn:`_sandboxLogWarn_1wqny_472`,sandboxLogOk:`_sandboxLogOk_1wqny_473`,codeLayout:`_codeLayout_1wqny_476`,codeRow:`_codeRow_1wqny_485`,ideTabBar:`_ideTabBar_1wqny_493`,ideTab:`_ideTab_1wqny_493`,ideTabActive:`_ideTabActive_1wqny_525`,ideTabError:`_ideTabError_1wqny_530`,ideTabPending:`_ideTabPending_1wqny_531`,ideTabIcon:`_ideTabIcon_1wqny_532`,ideTabName:`_ideTabName_1wqny_533`,ideTabDot:`_ideTabDot_1wqny_534`,ideTabUnsaved:`_ideTabUnsaved_1wqny_540`,codeEditorWrap:`_codeEditorWrap_1wqny_548`,editToggleBtn:`_editToggleBtn_1wqny_559`,editToggleBtnActive:`_editToggleBtnActive_1wqny_570`,codeEditor:`_codeEditor_1wqny_548`,genCursor:`_genCursor_1wqny_592`,cursorBlink:`_cursorBlink_1wqny_1`,diffOverlay:`_diffOverlay_1wqny_601`,diffOverlayHeader:`_diffOverlayHeader_1wqny_610`,diffOverlayActions:`_diffOverlayActions_1wqny_621`,diffAcceptBtn:`_diffAcceptBtn_1wqny_622`,diffRejectBtn:`_diffRejectBtn_1wqny_623`,diffOverlayBody:`_diffOverlayBody_1wqny_624`,diffSame:`_diffSame_1wqny_625`,diffRem:`_diffRem_1wqny_626`,diffAdd:`_diffAdd_1wqny_627`,noFiles:`_noFiles_1wqny_629`,noFilesHero:`_noFilesHero_1wqny_639`,noFilesIcon:`_noFilesIcon_1wqny_646`,noFilesTitle:`_noFilesTitle_1wqny_648`,noFilesTagline:`_noFilesTagline_1wqny_655`,noFilesSteps:`_noFilesSteps_1wqny_660`,noFilesStep:`_noFilesStep_1wqny_660`,noFilesStepNum:`_noFilesStepNum_1wqny_677`,noFilesExamplesHint:`_noFilesExamplesHint_1wqny_691`,noFilesExampleBtn:`_noFilesExampleBtn_1wqny_701`,codeViewer:`_codeViewer_1wqny_713`,codeHeader:`_codeHeader_1wqny_721`,codeFileIcon:`_codeFileIcon_1wqny_734`,codeFileName:`_codeFileName_1wqny_735`,codeFileMeta:`_codeFileMeta_1wqny_736`,fileError:`_fileError_1wqny_738`,fileSyntaxError:`_fileSyntaxError_1wqny_739`,filePending:`_filePending_1wqny_740`,codeWithLines:`_codeWithLines_1wqny_743`,lineNumbers:`_lineNumbers_1wqny_750`,lineNum:`_lineNum_1wqny_750`,code:`_code_1wqny_365`,codeError:`_codeError_1wqny_781`,codeSyntaxError:`_codeSyntaxError_1wqny_782`,fileSidebar:`_fileSidebar_1wqny_785`,fileSidebarHeader:`_fileSidebarHeader_1wqny_794`,fileTab:`_fileTab_1wqny_804`,fileTabActive:`_fileTabActive_1wqny_820`,fileTabError:`_fileTabError_1wqny_821`,fileTabRow:`_fileTabRow_1wqny_823`,fileTabIcon:`_fileTabIcon_1wqny_824`,fileTabName:`_fileTabName_1wqny_825`,fileTabSize:`_fileTabSize_1wqny_826`,fileTabDir:`_fileTabDir_1wqny_827`,fileTabTokens:`_fileTabTokens_1wqny_828`,fileTabMeta:`_fileTabMeta_1wqny_829`,projectsList:`_projectsList_1wqny_832`,emptyProjects:`_emptyProjects_1wqny_834`,emptyIcon:`_emptyIcon_1wqny_835`,emptyHint:`_emptyHint_1wqny_836`,projectCard:`_projectCard_1wqny_838`,projectInfo:`_projectInfo_1wqny_839`,projectName:`_projectName_1wqny_840`,projectDesc:`_projectDesc_1wqny_841`,projectMeta:`_projectMeta_1wqny_842`,openBtn:`_openBtn_1wqny_843`,deleteBtn:`_deleteBtn_1wqny_844`,planBanner:`_planBanner_1wqny_847`,planTitle:`_planTitle_1wqny_856`,planText:`_planText_1wqny_857`,planActions:`_planActions_1wqny_858`,planApprove:`_planApprove_1wqny_859`,planReject:`_planReject_1wqny_860`,grepPanel:`_grepPanel_1wqny_863`,grepRow:`_grepRow_1wqny_872`,grepInput:`_grepInput_1wqny_873`,grepBtn:`_grepBtn_1wqny_875`,grepClose:`_grepClose_1wqny_876`,grepCount:`_grepCount_1wqny_877`,grepResults:`_grepResults_1wqny_878`,grepEmpty:`_grepEmpty_1wqny_879`,grepMatch:`_grepMatch_1wqny_880`,grepMatchFile:`_grepMatchFile_1wqny_882`,grepMatchLine:`_grepMatchLine_1wqny_883`,diffPanel:`_diffPanel_1wqny_886`,diffHeader:`_diffHeader_1wqny_895`,diffClose:`_diffClose_1wqny_896`,diffFile:`_diffFile_1wqny_897`,diffSummary:`_diffSummary_1wqny_898`,diffArrow:`_diffArrow_1wqny_899`,diffFileName:`_diffFileName_1wqny_900`,diffAdded:`_diffAdded_1wqny_901`,diffRemoved:`_diffRemoved_1wqny_902`,diffContent:`_diffContent_1wqny_903`,diffInline:`_diffInline_1wqny_906`,diffInlineHeader:`_diffInlineHeader_1wqny_907`,diffRemLine:`_diffRemLine_1wqny_908`,diffAddLine:`_diffAddLine_1wqny_909`,chatPanel:`_chatPanel_1wqny_912`,chatPanelCollapsed:`_chatPanelCollapsed_1wqny_921`,chatCollapseBtn:`_chatCollapseBtn_1wqny_922`,chatMessages:`_chatMessages_1wqny_930`,chatWelcome:`_chatWelcome_1wqny_932`,doctrineOpenBtn:`_doctrineOpenBtn_1wqny_933`,streamingPre:`_streamingPre_1wqny_936`,streamingCursor:`_streamingCursor_1wqny_949`,streamBlink:`_streamBlink_1wqny_1`,doctrineSubtitle:`_doctrineSubtitle_1wqny_956`,doctrineSection:`_doctrineSection_1wqny_957`,doctrineSectionTitle:`_doctrineSectionTitle_1wqny_962`,doctrineSectionBody:`_doctrineSectionBody_1wqny_969`,doctrineBullet:`_doctrineBullet_1wqny_978`,chatUser:`_chatUser_1wqny_988`,chatUserBubble:`_chatUserBubble_1wqny_989`,chatAttachPreviews:`_chatAttachPreviews_1wqny_990`,chatAttachBadge:`_chatAttachBadge_1wqny_991`,chatSystem:`_chatSystem_1wqny_993`,chatSystemBubble:`_chatSystemBubble_1wqny_994`,chatSyntaxErr:`_chatSyntaxErr_1wqny_995`,chatAgent:`_chatAgent_1wqny_997`,chatAgentCard:`_chatAgentCard_1wqny_998`,chatAgentHeader:`_chatAgentHeader_1wqny_999`,chatAgentRobot:`_chatAgentRobot_1wqny_1000`,chatAgentRobotAnim:`_chatAgentRobotAnim_1wqny_1001`,chatAgentLabel:`_chatAgentLabel_1wqny_1002`,chatRunningDots:`_chatRunningDots_1wqny_1003`,chatAgentText:`_chatAgentText_1wqny_1004`,chatToolBadges:`_chatToolBadges_1wqny_1005`,toolBadge:`_toolBadge_1wqny_1006`,toolBadgeOk:`_toolBadgeOk_1wqny_1007`,toolBadgeErr:`_toolBadgeErr_1wqny_1008`,cursor:`_cursor_1wqny_1010`,blink:`_blink_1wqny_1`,attachPreviews:`_attachPreviews_1wqny_1013`,attachBadge:`_attachBadge_1wqny_1014`,removeAttachBtn:`_removeAttachBtn_1wqny_1015`,projNameRow:`_projNameRow_1wqny_1018`,projNameLabel:`_projNameLabel_1wqny_1019`,projNameInput:`_projNameInput_1wqny_1020`,projActiveRow:`_projActiveRow_1wqny_1021`,projActiveName:`_projActiveName_1wqny_1022`,chatInputRow:`_chatInputRow_1wqny_1025`,attachLabel:`_attachLabel_1wqny_1026`,chatTextarea:`_chatTextarea_1wqny_1027`,chatSendCol:`_chatSendCol_1wqny_1030`,chatSendBtn:`_chatSendBtn_1wqny_1031`,chatStopBtn:`_chatStopBtn_1wqny_1033`,modalOverlay:`_modalOverlay_1wqny_1036`,modal:`_modal_1wqny_1036`,modalHeader:`_modalHeader_1wqny_1058`,modalTitle:`_modalTitle_1wqny_1059`,modalClose:`_modalClose_1wqny_1060`,modalBody:`_modalBody_1wqny_1062`,modalRow:`_modalRow_1wqny_1064`,modalField:`_modalField_1wqny_1065`,modalLabel:`_modalLabel_1wqny_1066`,modalLabelRow:`_modalLabelRow_1wqny_1067`,modalSelect:`_modalSelect_1wqny_1069`,modalInput:`_modalInput_1wqny_1070`,modalHint:`_modalHint_1wqny_1073`,modalAiBox:`_modalAiBox_1wqny_1075`,modalAiRow:`_modalAiRow_1wqny_1076`,modalAiDesc:`_modalAiDesc_1wqny_1077`,modalAiBtn:`_modalAiBtn_1wqny_1078`,modalContentArea:`_modalContentArea_1wqny_1081`,logView:`_logView_1wqny_1084`,modalFooter:`_modalFooter_1wqny_1086`,modalCancelBtn:`_modalCancelBtn_1wqny_1087`,modalSaveBtn:`_modalSaveBtn_1wqny_1088`,fileTreeWrap:`_fileTreeWrap_1wqny_1091`,headerIconBtn:`_headerIconBtn_1wqny_1101`,headerIconBtnActive:`_headerIconBtnActive_1wqny_1112`,terminalPanel:`_terminalPanel_1wqny_1115`,terminalHeader:`_terminalHeader_1wqny_1123`,terminalTitle:`_terminalTitle_1wqny_1132`,terminalClose:`_terminalClose_1wqny_1133`,scanBanner:`_scanBanner_1wqny_1136`,scanBannerIcon:`_scanBannerIcon_1wqny_1145`,scanBannerText:`_scanBannerText_1wqny_1146`,scanBannerFix:`_scanBannerFix_1wqny_1147`,findBar:`_findBar_1wqny_1150`,findInput:`_findInput_1wqny_1159`,findCount:`_findCount_1wqny_1170`,findBtn:`_findBtn_1wqny_1171`,findClose:`_findClose_1wqny_1173`,mobileTabBar:`_mobileTabBar_1wqny_1253`,mobileTabBtn:`_mobileTabBtn_1wqny_1263`,mobileTabBtnActive:`_mobileTabBtnActive_1wqny_1276`,mobileTabBtnIcon:`_mobileTabBtnIcon_1wqny_1279`},ZT=[{id:`editor`,label:`Editor`,icon:`💻`},{id:`preview`,label:`Preview`,icon:`📱`},{id:`skills`,label:`Skills`,icon:`🛠`}];function QT(e,t){if(!e)return``;let n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`);return e.split(`
751
+ `)},n.onData(e=>{o.readyState===WebSocket.OPEN&&o.send(e)}),()=>{o.close(),s.current=null}},[e,t]),(0,_.useEffect)(()=>{if(!n||!a.current)return;let e=a.current;for(let t of n)e.writeln(t)},[n]),(0,k.jsx)(`div`,{ref:i,className:r,style:{flex:1,minHeight:0,overflow:`hidden`,background:`#0d1117`}})}function XT({tabs:e,active:t,onChange:n,className:r,buttonClassName:i,activeClassName:a}){return(0,k.jsx)(`nav`,{className:r,role:`tablist`,"aria-label":`Mobile navigation`,children:e.map(e=>{let r=e.id===t;return(0,k.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":r,className:`${i??``} ${r?a??``:``}`,onClick:()=>n(e.id),children:[(0,k.jsx)(`span`,{"aria-hidden":`true`,children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.id)})})}var Q={root:`_root_ex7bl_2`,header:`_header_ex7bl_10`,title:`_title_ex7bl_21`,subtitle:`_subtitle_ex7bl_28`,headerTabs:`_headerTabs_ex7bl_34`,tabBtn:`_tabBtn_ex7bl_40`,tabActive:`_tabActive_ex7bl_51`,body:`_body_ex7bl_58`,editor:`_editor_ex7bl_67`,examples:`_examples_ex7bl_75`,sectionLabel:`_sectionLabel_ex7bl_81`,examplePills:`_examplePills_ex7bl_89`,examplePill:`_examplePill_ex7bl_89`,editorCols:`_editorCols_ex7bl_109`,leftSidebar:`_leftSidebar_ex7bl_119`,panel:`_panel_ex7bl_128`,panelHeader:`_panelHeader_ex7bl_135`,panelTitle:`_panelTitle_ex7bl_142`,addBtn:`_addBtn_ex7bl_149`,blockLabel:`_blockLabel_ex7bl_160`,blockCheck:`_blockCheck_ex7bl_170`,authField:`_authField_ex7bl_173`,authFieldInput:`_authFieldInput_ex7bl_183`,authFieldSelect:`_authFieldSelect_ex7bl_193`,authFieldReq:`_authFieldReq_ex7bl_204`,removeFieldBtn:`_removeFieldBtn_ex7bl_205`,skillsList:`_skillsList_ex7bl_208`,skillRow:`_skillRow_ex7bl_210`,skillIcon:`_skillIcon_ex7bl_218`,skillName:`_skillName_ex7bl_220`,skillBadge:`_skillBadge_ex7bl_229`,skillBadge_skill:`_skillBadge_skill_ex7bl_237`,skillBadge_memory:`_skillBadge_memory_ex7bl_238`,skillBadge_provider:`_skillBadge_provider_ex7bl_239`,skillBadge_log:`_skillBadge_log_ex7bl_240`,skillEmpty:`_skillEmpty_ex7bl_242`,skillBtn:`_skillBtn_ex7bl_244`,skillsEmpty:`_skillsEmpty_ex7bl_246`,snapshotRow:`_snapshotRow_ex7bl_249`,snapshotTs:`_snapshotTs_ex7bl_258`,snapshotCount:`_snapshotCount_ex7bl_259`,snapshotBtn:`_snapshotBtn_ex7bl_260`,genStatus:`_genStatus_ex7bl_263`,repairStatus:`_repairStatus_ex7bl_265`,repairStatusTitle:`_repairStatusTitle_ex7bl_266`,repairStatusProg:`_repairStatusProg_ex7bl_267`,repairStatusFile:`_repairStatusFile_ex7bl_268`,actionRow:`_actionRow_ex7bl_271`,actionBtn:`_actionBtn_ex7bl_273`,actionBtnIcon:`_actionBtnIcon_ex7bl_275`,actionBtnActive:`_actionBtnActive_ex7bl_276`,repairBtn:`_repairBtn_ex7bl_278`,sandboxBtn:`_sandboxBtn_ex7bl_280`,statsBar:`_statsBar_ex7bl_282`,rightPanel:`_rightPanel_ex7bl_285`,rightTabBar:`_rightTabBar_ex7bl_296`,rightTab:`_rightTab_ex7bl_296`,rightTabActive:`_rightTabActive_ex7bl_313`,repairBar:`_repairBar_ex7bl_316`,repairBarRow:`_repairBarRow_ex7bl_326`,repairBarIcon:`_repairBarIcon_ex7bl_327`,repairBarLabel:`_repairBarLabel_ex7bl_328`,repairBarFile:`_repairBarFile_ex7bl_329`,repairBarCounter:`_repairBarCounter_ex7bl_330`,repairBarTime:`_repairBarTime_ex7bl_331`,genBar:`_genBar_ex7bl_333`,genBarRow:`_genBarRow_ex7bl_343`,genBarRobot:`_genBarRobot_ex7bl_344`,robotBob:`_robotBob_ex7bl_1`,genBarLabel:`_genBarLabel_ex7bl_345`,genBarFile:`_genBarFile_ex7bl_346`,genBarCounter:`_genBarCounter_ex7bl_347`,genBarTime:`_genBarTime_ex7bl_348`,progressTrack:`_progressTrack_ex7bl_350`,repairProgress:`_repairProgress_ex7bl_351`,genProgress:`_genProgress_ex7bl_352`,genDots:`_genDots_ex7bl_355`,dot:`_dot_ex7bl_356`,dot1:`_dot1_ex7bl_357`,dotBounce:`_dotBounce_ex7bl_1`,dot2:`_dot2_ex7bl_358`,dot3:`_dot3_ex7bl_359`,stopBtn:`_stopBtn_ex7bl_362`,codeArea:`_codeArea_ex7bl_365`,sandboxWrap:`_sandboxWrap_ex7bl_366`,sandboxFrame:`_sandboxFrame_ex7bl_367`,sandboxEmpty:`_sandboxEmpty_ex7bl_368`,sandboxStartBtn:`_sandboxStartBtn_ex7bl_369`,sandboxStatusBar:`_sandboxStatusBar_ex7bl_372`,sandboxStatusDot:`_sandboxStatusDot_ex7bl_381`,sandboxStatusText:`_sandboxStatusText_ex7bl_382`,sandboxStartBtnSmall:`_sandboxStartBtnSmall_ex7bl_383`,runtimeErrors:`_runtimeErrors_ex7bl_386`,runtimeErrorsHeader:`_runtimeErrorsHeader_ex7bl_392`,runtimeErrorsFix:`_runtimeErrorsFix_ex7bl_401`,runtimeErrorsDismiss:`_runtimeErrorsDismiss_ex7bl_413`,runtimeErrorLine:`_runtimeErrorLine_ex7bl_414`,sandboxConsole:`_sandboxConsole_ex7bl_425`,sandboxConsoleCollapsed:`_sandboxConsoleCollapsed_ex7bl_434`,sandboxConsoleHeader:`_sandboxConsoleHeader_ex7bl_435`,sandboxConsoleTitle:`_sandboxConsoleTitle_ex7bl_447`,sandboxConsolePort:`_sandboxConsolePort_ex7bl_448`,sandboxConsoleDots:`_sandboxConsoleDots_ex7bl_449`,sandboxConsoleToggle:`_sandboxConsoleToggle_ex7bl_450`,sandboxReloadBtn:`_sandboxReloadBtn_ex7bl_451`,sandboxStopBtn:`_sandboxStopBtn_ex7bl_453`,sandboxConsoleBody:`_sandboxConsoleBody_ex7bl_455`,sandboxLogLine:`_sandboxLogLine_ex7bl_461`,sandboxLogPhase:`_sandboxLogPhase_ex7bl_470`,sandboxLogError:`_sandboxLogError_ex7bl_471`,sandboxLogWarn:`_sandboxLogWarn_ex7bl_472`,sandboxLogOk:`_sandboxLogOk_ex7bl_473`,codeLayout:`_codeLayout_ex7bl_476`,codeRow:`_codeRow_ex7bl_485`,ideTabBar:`_ideTabBar_ex7bl_493`,ideTab:`_ideTab_ex7bl_493`,ideTabActive:`_ideTabActive_ex7bl_525`,ideTabError:`_ideTabError_ex7bl_530`,ideTabPending:`_ideTabPending_ex7bl_531`,ideTabIcon:`_ideTabIcon_ex7bl_532`,ideTabName:`_ideTabName_ex7bl_533`,ideTabDot:`_ideTabDot_ex7bl_534`,ideTabUnsaved:`_ideTabUnsaved_ex7bl_540`,codeEditorWrap:`_codeEditorWrap_ex7bl_548`,editToggleBtn:`_editToggleBtn_ex7bl_559`,editToggleBtnActive:`_editToggleBtnActive_ex7bl_570`,codeEditor:`_codeEditor_ex7bl_548`,genCursor:`_genCursor_ex7bl_592`,cursorBlink:`_cursorBlink_ex7bl_1`,diffOverlay:`_diffOverlay_ex7bl_601`,diffOverlayHeader:`_diffOverlayHeader_ex7bl_610`,diffOverlayActions:`_diffOverlayActions_ex7bl_621`,diffAcceptBtn:`_diffAcceptBtn_ex7bl_622`,diffRejectBtn:`_diffRejectBtn_ex7bl_623`,diffOverlayBody:`_diffOverlayBody_ex7bl_624`,diffSame:`_diffSame_ex7bl_625`,diffRem:`_diffRem_ex7bl_626`,diffAdd:`_diffAdd_ex7bl_627`,noFiles:`_noFiles_ex7bl_629`,noFilesHero:`_noFilesHero_ex7bl_639`,noFilesIcon:`_noFilesIcon_ex7bl_646`,noFilesTitle:`_noFilesTitle_ex7bl_648`,noFilesTagline:`_noFilesTagline_ex7bl_655`,noFilesSteps:`_noFilesSteps_ex7bl_660`,noFilesStep:`_noFilesStep_ex7bl_660`,noFilesStepNum:`_noFilesStepNum_ex7bl_677`,noFilesExamplesHint:`_noFilesExamplesHint_ex7bl_691`,noFilesExampleBtn:`_noFilesExampleBtn_ex7bl_701`,codeViewer:`_codeViewer_ex7bl_713`,codeHeader:`_codeHeader_ex7bl_721`,codeFileIcon:`_codeFileIcon_ex7bl_734`,codeFileName:`_codeFileName_ex7bl_735`,codeFileMeta:`_codeFileMeta_ex7bl_736`,fileError:`_fileError_ex7bl_738`,fileSyntaxError:`_fileSyntaxError_ex7bl_739`,filePending:`_filePending_ex7bl_740`,codeWithLines:`_codeWithLines_ex7bl_743`,lineNumbers:`_lineNumbers_ex7bl_750`,lineNum:`_lineNum_ex7bl_750`,code:`_code_ex7bl_365`,codeError:`_codeError_ex7bl_781`,codeSyntaxError:`_codeSyntaxError_ex7bl_782`,fileSidebar:`_fileSidebar_ex7bl_785`,fileSidebarHeader:`_fileSidebarHeader_ex7bl_794`,fileTab:`_fileTab_ex7bl_804`,fileTabActive:`_fileTabActive_ex7bl_820`,fileTabError:`_fileTabError_ex7bl_821`,fileTabRow:`_fileTabRow_ex7bl_823`,fileTabIcon:`_fileTabIcon_ex7bl_824`,fileTabName:`_fileTabName_ex7bl_825`,fileTabSize:`_fileTabSize_ex7bl_826`,fileTabDir:`_fileTabDir_ex7bl_827`,fileTabTokens:`_fileTabTokens_ex7bl_828`,fileTabMeta:`_fileTabMeta_ex7bl_829`,projectsList:`_projectsList_ex7bl_832`,emptyProjects:`_emptyProjects_ex7bl_834`,emptyIcon:`_emptyIcon_ex7bl_835`,emptyHint:`_emptyHint_ex7bl_836`,projectCard:`_projectCard_ex7bl_838`,projectInfo:`_projectInfo_ex7bl_839`,projectName:`_projectName_ex7bl_840`,projectDesc:`_projectDesc_ex7bl_841`,projectMeta:`_projectMeta_ex7bl_842`,openBtn:`_openBtn_ex7bl_843`,deleteBtn:`_deleteBtn_ex7bl_844`,planBanner:`_planBanner_ex7bl_847`,planTitle:`_planTitle_ex7bl_856`,planText:`_planText_ex7bl_857`,planActions:`_planActions_ex7bl_858`,planApprove:`_planApprove_ex7bl_859`,planReject:`_planReject_ex7bl_860`,grepPanel:`_grepPanel_ex7bl_863`,grepRow:`_grepRow_ex7bl_872`,grepInput:`_grepInput_ex7bl_873`,grepBtn:`_grepBtn_ex7bl_875`,grepClose:`_grepClose_ex7bl_876`,grepCount:`_grepCount_ex7bl_877`,grepResults:`_grepResults_ex7bl_878`,grepEmpty:`_grepEmpty_ex7bl_879`,grepMatch:`_grepMatch_ex7bl_880`,grepMatchFile:`_grepMatchFile_ex7bl_882`,grepMatchLine:`_grepMatchLine_ex7bl_883`,diffPanel:`_diffPanel_ex7bl_886`,diffHeader:`_diffHeader_ex7bl_895`,diffClose:`_diffClose_ex7bl_896`,diffFile:`_diffFile_ex7bl_897`,diffSummary:`_diffSummary_ex7bl_898`,diffArrow:`_diffArrow_ex7bl_899`,diffFileName:`_diffFileName_ex7bl_900`,diffAdded:`_diffAdded_ex7bl_901`,diffRemoved:`_diffRemoved_ex7bl_902`,diffContent:`_diffContent_ex7bl_903`,diffInline:`_diffInline_ex7bl_906`,diffInlineHeader:`_diffInlineHeader_ex7bl_907`,diffRemLine:`_diffRemLine_ex7bl_908`,diffAddLine:`_diffAddLine_ex7bl_909`,chatPanel:`_chatPanel_ex7bl_912`,chatPanelCollapsed:`_chatPanelCollapsed_ex7bl_921`,chatCollapseBtn:`_chatCollapseBtn_ex7bl_922`,chatMessages:`_chatMessages_ex7bl_930`,chatWelcome:`_chatWelcome_ex7bl_932`,doctrineOpenBtn:`_doctrineOpenBtn_ex7bl_933`,streamingPre:`_streamingPre_ex7bl_936`,streamingCursor:`_streamingCursor_ex7bl_949`,streamBlink:`_streamBlink_ex7bl_1`,doctrineSubtitle:`_doctrineSubtitle_ex7bl_956`,doctrineSection:`_doctrineSection_ex7bl_957`,doctrineSectionTitle:`_doctrineSectionTitle_ex7bl_962`,doctrineSectionBody:`_doctrineSectionBody_ex7bl_969`,doctrineBullet:`_doctrineBullet_ex7bl_978`,chatUser:`_chatUser_ex7bl_988`,chatUserBubble:`_chatUserBubble_ex7bl_989`,chatAttachPreviews:`_chatAttachPreviews_ex7bl_990`,chatAttachBadge:`_chatAttachBadge_ex7bl_991`,chatSystem:`_chatSystem_ex7bl_993`,chatSystemBubble:`_chatSystemBubble_ex7bl_994`,chatSyntaxErr:`_chatSyntaxErr_ex7bl_995`,chatAgent:`_chatAgent_ex7bl_997`,chatAgentCard:`_chatAgentCard_ex7bl_998`,chatAgentHeader:`_chatAgentHeader_ex7bl_999`,chatAgentRobot:`_chatAgentRobot_ex7bl_1000`,chatAgentRobotAnim:`_chatAgentRobotAnim_ex7bl_1001`,chatAgentLabel:`_chatAgentLabel_ex7bl_1002`,chatRunningDots:`_chatRunningDots_ex7bl_1003`,chatAgentText:`_chatAgentText_ex7bl_1004`,chatToolBadges:`_chatToolBadges_ex7bl_1005`,toolBadge:`_toolBadge_ex7bl_1006`,toolBadgeOk:`_toolBadgeOk_ex7bl_1007`,toolBadgeErr:`_toolBadgeErr_ex7bl_1008`,cursor:`_cursor_ex7bl_1010`,blink:`_blink_ex7bl_1`,attachPreviews:`_attachPreviews_ex7bl_1013`,attachBadge:`_attachBadge_ex7bl_1014`,removeAttachBtn:`_removeAttachBtn_ex7bl_1015`,projNameRow:`_projNameRow_ex7bl_1018`,projNameLabel:`_projNameLabel_ex7bl_1019`,projNameInput:`_projNameInput_ex7bl_1020`,projActiveRow:`_projActiveRow_ex7bl_1021`,projActiveName:`_projActiveName_ex7bl_1022`,chatInputRow:`_chatInputRow_ex7bl_1025`,attachLabel:`_attachLabel_ex7bl_1026`,chatTextarea:`_chatTextarea_ex7bl_1027`,chatSendCol:`_chatSendCol_ex7bl_1030`,chatSendBtn:`_chatSendBtn_ex7bl_1031`,chatStopBtn:`_chatStopBtn_ex7bl_1033`,modalOverlay:`_modalOverlay_ex7bl_1036`,modal:`_modal_ex7bl_1036`,modalHeader:`_modalHeader_ex7bl_1058`,modalTitle:`_modalTitle_ex7bl_1059`,modalClose:`_modalClose_ex7bl_1060`,modalBody:`_modalBody_ex7bl_1062`,modalRow:`_modalRow_ex7bl_1064`,modalField:`_modalField_ex7bl_1065`,modalLabel:`_modalLabel_ex7bl_1066`,modalLabelRow:`_modalLabelRow_ex7bl_1067`,modalSelect:`_modalSelect_ex7bl_1069`,modalInput:`_modalInput_ex7bl_1070`,modalHint:`_modalHint_ex7bl_1073`,modalAiBox:`_modalAiBox_ex7bl_1075`,modalAiRow:`_modalAiRow_ex7bl_1076`,modalAiDesc:`_modalAiDesc_ex7bl_1077`,modalAiBtn:`_modalAiBtn_ex7bl_1078`,modalContentArea:`_modalContentArea_ex7bl_1081`,logView:`_logView_ex7bl_1084`,modalFooter:`_modalFooter_ex7bl_1086`,modalCancelBtn:`_modalCancelBtn_ex7bl_1087`,modalSaveBtn:`_modalSaveBtn_ex7bl_1088`,fileTreeWrap:`_fileTreeWrap_ex7bl_1091`,headerIconBtn:`_headerIconBtn_ex7bl_1101`,headerIconBtnActive:`_headerIconBtnActive_ex7bl_1112`,terminalPanel:`_terminalPanel_ex7bl_1115`,terminalHeader:`_terminalHeader_ex7bl_1123`,terminalTitle:`_terminalTitle_ex7bl_1132`,terminalClose:`_terminalClose_ex7bl_1133`,scanBanner:`_scanBanner_ex7bl_1136`,scanBannerIcon:`_scanBannerIcon_ex7bl_1145`,scanBannerText:`_scanBannerText_ex7bl_1146`,scanBannerFix:`_scanBannerFix_ex7bl_1147`,scanBannerToggle:`_scanBannerToggle_ex7bl_1148`,problemsPanel:`_problemsPanel_ex7bl_1151`,problemsGroup:`_problemsGroup_ex7bl_1152`,problemsGroupHeader:`_problemsGroupHeader_ex7bl_1153`,problemsGroupCount:`_problemsGroupCount_ex7bl_1160`,problemsItem:`_problemsItem_ex7bl_1161`,problemsIcon:`_problemsIcon_ex7bl_1169`,problemsIconError:`_problemsIconError_ex7bl_1170`,problemsIconWarning:`_problemsIconWarning_ex7bl_1171`,problemsIconInfo:`_problemsIconInfo_ex7bl_1172`,problemsMsg:`_problemsMsg_ex7bl_1173`,problemsLine:`_problemsLine_ex7bl_1174`,findBar:`_findBar_ex7bl_1177`,findInput:`_findInput_ex7bl_1186`,findCount:`_findCount_ex7bl_1197`,findBtn:`_findBtn_ex7bl_1198`,findClose:`_findClose_ex7bl_1200`,mobileTabBar:`_mobileTabBar_ex7bl_1280`,mobileTabBtn:`_mobileTabBtn_ex7bl_1290`,mobileTabBtnActive:`_mobileTabBtnActive_ex7bl_1303`,mobileTabBtnIcon:`_mobileTabBtnIcon_ex7bl_1306`},ZT=[{id:`editor`,label:`Editor`,icon:`💻`},{id:`preview`,label:`Preview`,icon:`📱`},{id:`skills`,label:`Skills`,icon:`🛠`}];function QT(e,t){if(!e)return``;let n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`);return e.split(`
752
752
  `).map(e=>{let r=n(e);if(t===`css`)r=r.replace(/([a-z-]+)\s*(?=:)/g,`<span style="color:#82aaff">$1</span>`),r=r.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color:#546e7a;font-style:italic">$1</span>`);else if(t===`html`||t===`htm`)r=r.replace(/(&lt;\/?)([\w-]+)/g,`$1<span style="color:#f07178">$2</span>`),r=r.replace(/\s([\w-]+)(?==)/g,` <span style="color:#ffcb6b">$1</span>`),r=r.replace(/(["'])(?:(?!\1).)*?\1/g,`<span style="color:#c3e88d">$&</span>`);else if(t===`json`)r=r.replace(/(["'])(?:(?!\1|\\).|\\.)*?\1(?=\s*:)/g,`<span style="color:#82aaff">$&</span>`),r=r.replace(/:\s*(["'])(?:(?!\1|\\).|\\.)*?\1/g,e=>`: <span style="color:#c3e88d">`+e.slice(2)+`</span>`),r=r.replace(/:\s*(true|false|null)\b/g,`: <span style="color:#c792ea">$1</span>`),r=r.replace(/:\s*(\d+\.?\d*)/g,`: <span style="color:#f78c6c">$1</span>`);else{if(/^\s*\/\//.test(r))return`<span style="color:#546e7a;font-style:italic">`+r+`</span>`;r=r.replace(/(["'`])(?:(?!\1|\\).|\\.)*?\1/g,`<span style="color:#c3e88d">$&</span>`),r=r.replace(/\b(const|let|var|function|return|if|else|for|while|switch|case|break|continue|try|catch|throw|new|class|extends|import|export|from|default|async|await|typeof|instanceof)\b/g,`<span style="color:#c792ea">$&</span>`),r=r.replace(/\b(null|undefined|true|false)\b/g,`<span style="color:#ff5370">$&</span>`),r=r.replace(/\b(require|module|exports|console|process)\b/g,`<span style="color:#82aaff">$&</span>`)}return r}).join(`
753
753
  `)}function $T(e){if(!e)return``;let t=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`);return e.split(/(```[\s\S]*?```)/g).map(e=>{if(e.startsWith("```")&&e.endsWith("```")){let n=e.slice(3,-3),r=n.indexOf(`
754
754
  `);return`<pre style="background:rgba(0,0,0,0.3);border:1px solid rgba(255,255,255,0.08);border-radius:6px;padding:8px 10px;margin:6px 0;overflow-x:auto;font-size:11px;line-height:1.5"><code>${t(r>0?n.slice(r+1):n)}</code></pre>`}let n=t(e);return n=n.replace(/`([^`]+)`/g,`<code style="background:rgba(99,102,241,0.15);padding:1px 5px;border-radius:3px;font-size:0.9em">$1</code>`),n=n.replace(/\*\*([^*]+)\*\*/g,`<strong>$1</strong>`),n=n.replace(/\*([^*]+)\*/g,`<em>$1</em>`),n=n.replace(/^### (.+)$/gm,`<div style="font-weight:700;font-size:13px;margin-top:8px;color:#6366f1">$1</div>`),n=n.replace(/^## (.+)$/gm,`<div style="font-weight:700;font-size:14px;margin-top:10px;color:#818cf8">$1</div>`),n=n.replace(/^[-*] (.+)$/gm,`<div style="padding-left:12px">• $1</div>`),n=n.replace(/^\d+\. (.+)$/gm,(e,t)=>`<div style="padding-left:12px">${t}</div>`),n=n.replace(/\n/g,`<br/>`),n}).join(``)}var eE=[{name:`MySaaS`,desc:`Full-stack SaaS web application with Node.js/Express backend and vanilla JS frontend.
@@ -839,26 +839,26 @@ FRONTEND:
839
839
  - index.html: Job board homepage — (1) Hero: gradient background, large search widget (keyword input + location input + category select + Search button), quick stats bar (12,847 Jobs / 3,420 Companies / 45K Candidates). (2) Featured jobs: horizontal scroll row of 4 "Featured" cards with company logo (colored emoji), job title, company name, location + type badge + salary range + "Easy Apply" button. (3) Main layout: left sidebar filters (Job Type checkboxes, Salary Range slider, Category checkboxes, Location input, Posted Within select, Remote Only toggle) + right: jobs list (job row cards with company logo/title/company/location/type/salary/time-ago posted/Save bookmark/Apply button). (4) "Load More" button + results count "Showing 12 of 247 jobs". (5) Top companies section: 8 company cards with logo/name/industry/openings count. (6) Category browsing: 6 category cards with icon/name/count/link. (7) Job seeker CTA banner. (8) Newsletter.
840
840
  - job.html: Job detail page — company header (logo + name + industry + website + size + "Follow" button), job title + badges (Remote, Senior, Urgent), salary + location + posted date, Apply Now button (sticky on scroll), job description (markdown-rendered sections: About/Responsibilities/Requirements/Nice-to-Have/Benefits), company sidebar card (description + stats), similar jobs list (4 cards)
841
841
  - apply.html: Application modal/page — job summary header, form (Full Name / Email / Phone / LinkedIn URL / Portfolio URL / Cover Letter textarea with character count / Resume paste textarea), Submit button with loading state, success page with application reference number
842
- - public/css/main.css: Modern job board design — tag/badge system (Remote=blue, Onsite=green, Urgent=red), salary range display, company logo placeholder styles, filter sidebar collapse on mobile, job card hover effects, application form validation styles`}],tE=[{key:`auth`,label:`Auth (register/login/JWT)`,icon:`🔒`},{key:`cookieBanner`,label:`GDPR Cookie Banner`,icon:`🍪`},{key:`securityMiddleware`,label:`Security Middleware`,icon:`🛡️`},{key:`emailVerification`,label:`Email Verification`,icon:`✉️`}],nE={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`📋`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function rE(e){return nE[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function iE(e){let t=new TextEncoder().encode(e).length;return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(2)} MB`}function aE(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function oE(){let e=j(),[t,n]=(0,_.useState)(`new`),[r,i]=(0,_.useState)(`files`),a=Ut(),[o,s]=(0,_.useState)(`editor`);(0,_.useEffect)(()=>{a&&(o===`preview`&&i(`preview`),o===`editor`&&i(`files`))},[a,o]);let[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)({auth:!0,cookieBanner:!0,securityMiddleware:!0,emailVerification:!0}),[m,h]=(0,_.useState)([{label:`Email`,type:`email`,required:!0},{label:`Password`,type:`password`,required:!0},{label:`Name`,type:`text`,required:!0}]),[g,v]=(0,_.useState)([]),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),[ee,te]=(0,_.useState)(new Set),[ne,re]=(0,_.useState)(!1),[D,ie]=(0,_.useState)(``),[O,ae]=(0,_.useState)(``),[A,oe]=(0,_.useState)(!1),[se,ce]=(0,_.useState)(null),[le,ue]=(0,_.useState)(!1),[de,M]=(0,_.useState)([]),[fe,pe]=(0,_.useState)([]),me=(0,_.useRef)(null),he=(0,_.useRef)(null),ge=(0,_.useRef)(!0),_e=(0,_.useRef)(null),ve=(0,_.useRef)(null),ye=(0,_.useRef)(null),be=(0,_.useRef)(null),[xe,Se]=(0,_.useState)(null),[N,Ce]=(0,_.useState)(!1),[we,Te]=(0,_.useState)(!1),[Ee,P]=(0,_.useState)(0),[De,Oe]=(0,_.useState)(0),[ke,F]=(0,_.useState)(``),[I,Ae]=(0,_.useState)({fi:0,total:0,name:``}),[je,Me]=(0,_.useState)({tokIn:0,tokOut:0}),[Ne,Pe]=(0,_.useState)(null),[Fe,Ie]=(0,_.useState)([]),[Le,Re]=(0,_.useState)(``),[ze,L]=(0,_.useState)(!1),[Be,Ve]=(0,_.useState)([]),[He,Ue]=(0,_.useState)(null),[We,Ge]=(0,_.useState)([]),[Ke,qe]=(0,_.useState)(!1),[Je,Ye]=(0,_.useState)(null),[Xe,Ze]=(0,_.useState)([]),[Qe,$e]=(0,_.useState)(!1),[et,tt]=(0,_.useState)(``),[nt,rt]=(0,_.useState)([]),[it,at]=(0,_.useState)([]),[ot,st]=(0,_.useState)([]),[ct,lt]=(0,_.useState)(null),[ut,dt]=(0,_.useState)(!1),[ft,pt]=(0,_.useState)(!1),[mt,ht]=(0,_.useState)(null),[gt,_t]=(0,_.useState)([]),[vt,yt]=(0,_.useState)(`0s`),[R,bt]=(0,_.useState)(`0s`),xt=(0,_.useRef)(0),St=(0,_.useRef)(0),Ct=(0,_.useRef)(null),wt=(0,_.useRef)(null),Tt=(0,_.useRef)(null),Et=(0,_.useRef)(null),z=(0,_.useRef)(null),Dt=(0,_.useRef)(!1),Ot=(0,_.useRef)(null);function kt(e){console.log(`[WC-SCAN] scanning:`,e),E(`/api/studio/webcraft/scan`,{projectName:e}).then(e=>{console.log(`[WC-SCAN] result:`,e?.issues?.length,`issues`),e?.issues!==void 0&&pe(e.issues)}).catch(e=>{console.error(`[WC-SCAN] error:`,e)})}(0,_.useEffect)(()=>{if(!ct){M([]);return}let e=setInterval(()=>{T(`/api/studio/webcraft/sandbox/errors`).then(e=>{e?.errors?.length&&M(e.errors)}).catch(()=>{})},5e3);return()=>clearInterval(e)},[ct]);let At=(0,_.useRef)(ct);At.current=ct,(0,_.useEffect)(()=>{let e=()=>{At.current&&(navigator.sendBeacon(`/api/studio/webcraft/sandbox/stop-beacon`,``),fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`,keepalive:!0}).catch(()=>{}))};return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e),e()}},[]),(0,_.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`f`&&(e.preventDefault(),re(e=>!e)),(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),C!==null&&g[y])){let e=g[y];v(e=>e.map((e,t)=>t===y?{...e,content:C}:e)),E(`/api/studio/webcraft/file/write`,{projectName:c,path:e.name,content:C}),w(null),te(t=>{let n=new Set(t);return n.delete(e.name),n})}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[C,y,g,c]),(0,_.useEffect)(()=>{let e=()=>{let e=C===null?ye.current:ve.current;e&&be.current&&(be.current.scrollTop=e.scrollTop)},t=C===null?ye.current:ve.current;return t&&t.addEventListener(`scroll`,e),()=>{t&&t.removeEventListener(`scroll`,e)}},[C,y]);function jt(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Mt(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(N||we?Ct.current=setInterval(()=>{N&&yt(Mt(xt.current)),we&&bt(Mt(St.current))},1e3):Ct.current&&=(clearInterval(Ct.current),null),()=>{Ct.current&&clearInterval(Ct.current)}),[N,we]);function B(){Tt.current&&(Tt.current.scrollTop=Tt.current.scrollHeight)}(0,_.useEffect)(()=>{B()},[Fe]),(0,_.useEffect)(()=>{if(!c){Ge([]),qe(!1);return}Ge([]),qe(!1),T(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`).then(e=>{e?.skills&&Ge(e.skills),qe(!0)}).catch(()=>{qe(!0)})},[c]);async function Nt(e,t){if(N||!e||e.length<5)return;Ce(!0),v([]),b(0),S(null),Ae({fi:0,total:0,name:``}),Me({tokIn:0,tokOut:0}),xt.current=Date.now(),yt(`0s`),wt.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:wt.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:f,authFields:m})});if(!r.ok||!r.body){Ce(!1);return}let i=r.body.getReader(),a=wt.current,o=new TextDecoder,s=``,u=[];for(;;){if(a?.signal?.aborted){try{i.cancel()}catch{}break}let{done:e,value:t}=await i.read();if(e)break;s+=o.decode(t,{stream:!0});let r=s.split(`
842
+ - public/css/main.css: Modern job board design — tag/badge system (Remote=blue, Onsite=green, Urgent=red), salary range display, company logo placeholder styles, filter sidebar collapse on mobile, job card hover effects, application form validation styles`}],tE=[{key:`auth`,label:`Auth (register/login/JWT)`,icon:`🔒`},{key:`cookieBanner`,label:`GDPR Cookie Banner`,icon:`🍪`},{key:`securityMiddleware`,label:`Security Middleware`,icon:`🛡️`},{key:`emailVerification`,label:`Email Verification`,icon:`✉️`}],nE={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`📋`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function rE(e){return nE[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function iE(e){let t=new TextEncoder().encode(e).length;return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(2)} MB`}function aE(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function oE(){let e=j(),[t,n]=(0,_.useState)(`new`),[r,i]=(0,_.useState)(`files`),a=Ut(),[o,s]=(0,_.useState)(`editor`);(0,_.useEffect)(()=>{a&&(o===`preview`&&i(`preview`),o===`editor`&&i(`files`))},[a,o]);let[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)({auth:!0,cookieBanner:!0,securityMiddleware:!0,emailVerification:!0}),[m,h]=(0,_.useState)([{label:`Email`,type:`email`,required:!0},{label:`Password`,type:`password`,required:!0},{label:`Name`,type:`text`,required:!0}]),[g,v]=(0,_.useState)([]),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),[ee,te]=(0,_.useState)(new Set),[ne,re]=(0,_.useState)(!1),[D,ie]=(0,_.useState)(``),[O,ae]=(0,_.useState)(``),[A,oe]=(0,_.useState)(!1),[se,ce]=(0,_.useState)(null),[le,ue]=(0,_.useState)(!1),[de,M]=(0,_.useState)([]),[fe,pe]=(0,_.useState)([]),[me,he]=(0,_.useState)(!0),ge=(0,_.useRef)(null),_e=(0,_.useRef)(null),ve=(0,_.useRef)(!0),ye=(0,_.useRef)(null),be=(0,_.useRef)(null),xe=(0,_.useRef)(null),Se=(0,_.useRef)(null),[N,Ce]=(0,_.useState)(null),[we,Te]=(0,_.useState)(!1),[Ee,P]=(0,_.useState)(!1),[De,Oe]=(0,_.useState)(0),[ke,F]=(0,_.useState)(0),[I,Ae]=(0,_.useState)(``),[je,Me]=(0,_.useState)({fi:0,total:0,name:``}),[Ne,Pe]=(0,_.useState)({tokIn:0,tokOut:0}),[Fe,Ie]=(0,_.useState)(null),[Le,Re]=(0,_.useState)([]),[ze,L]=(0,_.useState)(``),[Be,Ve]=(0,_.useState)(!1),[He,Ue]=(0,_.useState)([]),[We,Ge]=(0,_.useState)(null),[Ke,qe]=(0,_.useState)([]),[Je,Ye]=(0,_.useState)(!1),[Xe,Ze]=(0,_.useState)(null),[Qe,$e]=(0,_.useState)([]),[et,tt]=(0,_.useState)(!1),[nt,rt]=(0,_.useState)(``),[it,at]=(0,_.useState)([]),[ot,st]=(0,_.useState)([]),[ct,lt]=(0,_.useState)([]),[ut,dt]=(0,_.useState)(null),[ft,pt]=(0,_.useState)(!1),[mt,ht]=(0,_.useState)(!1),[gt,_t]=(0,_.useState)(null),[vt,yt]=(0,_.useState)([]),[R,bt]=(0,_.useState)(`0s`),[xt,St]=(0,_.useState)(`0s`),Ct=(0,_.useRef)(0),wt=(0,_.useRef)(0),Tt=(0,_.useRef)(null),Et=(0,_.useRef)(null),z=(0,_.useRef)(null),Dt=(0,_.useRef)(null),Ot=(0,_.useRef)(null),kt=(0,_.useRef)(!1),At=(0,_.useRef)(null);function jt(e){console.log(`[WC-SCAN] scanning:`,e),E(`/api/studio/webcraft/scan`,{projectName:e}).then(e=>{console.log(`[WC-SCAN] result:`,e?.issues?.length,`issues`),e?.issues!==void 0&&pe(e.issues)}).catch(e=>{console.error(`[WC-SCAN] error:`,e)})}(0,_.useEffect)(()=>{if(!ut){M([]);return}let e=setInterval(()=>{T(`/api/studio/webcraft/sandbox/errors`).then(e=>{e?.errors?.length&&M(e.errors)}).catch(()=>{})},5e3);return()=>clearInterval(e)},[ut]);let Mt=(0,_.useRef)(ut);Mt.current=ut,(0,_.useEffect)(()=>{let e=()=>{Mt.current&&(navigator.sendBeacon(`/api/studio/webcraft/sandbox/stop-beacon`,``),fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`,keepalive:!0}).catch(()=>{}))};return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e),e()}},[]),(0,_.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`f`&&(e.preventDefault(),re(e=>!e)),(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),C!==null&&g[y])){let e=g[y];v(e=>e.map((e,t)=>t===y?{...e,content:C}:e)),E(`/api/studio/webcraft/file/write`,{projectName:c,path:e.name,content:C}),w(null),te(t=>{let n=new Set(t);return n.delete(e.name),n})}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[C,y,g,c]),(0,_.useEffect)(()=>{let e=()=>{let e=C===null?xe.current:be.current;e&&Se.current&&(Se.current.scrollTop=e.scrollTop)},t=C===null?xe.current:be.current;return t&&t.addEventListener(`scroll`,e),()=>{t&&t.removeEventListener(`scroll`,e)}},[C,y]);function B(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Nt(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(we||Ee?Tt.current=setInterval(()=>{we&&bt(Nt(Ct.current)),Ee&&St(Nt(wt.current))},1e3):Tt.current&&=(clearInterval(Tt.current),null),()=>{Tt.current&&clearInterval(Tt.current)}),[we,Ee]);function Pt(){z.current&&(z.current.scrollTop=z.current.scrollHeight)}(0,_.useEffect)(()=>{Pt()},[Le]),(0,_.useEffect)(()=>{if(!c){qe([]),Ye(!1);return}qe([]),Ye(!1),T(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`).then(e=>{e?.skills&&qe(e.skills),Ye(!0)}).catch(()=>{Ye(!0)})},[c]);async function Ft(e,t){if(we||!e||e.length<5)return;Te(!0),v([]),b(0),S(null),Me({fi:0,total:0,name:``}),Pe({tokIn:0,tokOut:0}),Ct.current=Date.now(),bt(`0s`),Et.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:Et.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:f,authFields:m})});if(!r.ok||!r.body){Te(!1);return}let i=r.body.getReader(),a=Et.current,o=new TextDecoder,s=``,u=[];for(;;){if(a?.signal?.aborted){try{i.cancel()}catch{}break}let{done:e,value:t}=await i.read();if(e)break;s+=o.decode(t,{stream:!0});let r=s.split(`
843
843
 
844
- `);s=r.pop()??``;for(let e of r){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);if(e.type===`project_renamed`)l(e.name);else if(e.type===`processing`||e.type===`planning`)Ae(t=>({...t,name:e.type===`planning`?`📋 Pianificazione struttura...`:e.msg||`Avvio...`}));else if(e.type===`file_start`)u.push({name:e.name,content:``,_pending:!0}),v([...u]),Ae({fi:e.fi,total:e.total,name:e.name}),me.current=u.length-1,he.current||(b(u.length-1),S(``)),ge.current=!0;else if(e.type===`file_chunk`){let t=u.find(t=>t.name===e.name);t&&(t.content+=e.chunk,t._pending=!1),v([...u]);let n=u.findIndex(t=>t.name===e.name);n>=0&&(me.current=n,S(t?t.content:null))}else if(e.type===`file_done`){let t=u.find(t=>t.name===e.name);t&&(t._pending=!1,e.syntaxError&&(t._syntaxError=e.syntaxError)),v([...u]),Ae({fi:e.fi,total:e.total,name:e.name}),(e.cumTokIn||e.cumTokOut)&&Me({tokIn:e.cumTokIn||0,tokOut:e.cumTokOut||0})}else if(e.type===`file_error`){let t=u.find(t=>t.name===e.name);t&&(t._error=!0,t._pending=!1),v([...u])}else e.type===`phase`||e.type===`status`&&!e.op?Ae(t=>({...t,name:e.msg||e.phase||``})):e.type===`done`&&(Pe({seconds:Math.round((Date.now()-n)/1e3),tokIn:e.tokIn??0,tokOut:e.tokOut??0,files:u.length}),S(null),Ce(!1),me.current=null,he.current&&=(clearTimeout(he.current),null),c&&kt(c),ue(!0),qe(!1),Ge([]),u.some(e=>e._error||e._syntaxError)?setTimeout(()=>z.current?.(),800):setTimeout(()=>Ot.current?.(),800))}catch{}}}}catch(e){e.name!==`AbortError`&&Ie(t=>[...t,{role:`system`,text:`Errore generazione: `+e.message}]),Ce(!1)}}async function Pt(e){let t=(e??Le).trim();if(!(c&&g.length>0)){if(!t||t.length<5)return;let e=c||`MyProject`;l(e),d(t),Re(``),await Nt(t,e);return}if(!t&&Be.length===0||ze||N)return;let n=[...Be];if(Ve([]),Re(``),t.toLowerCase().startsWith(`/plan `)||t.toLowerCase().startsWith(`piano: `)){let e=t.replace(/^\/plan[ ]*/i,``).replace(/^piano:[ ]*/i,``);Ie(e=>[...e,{role:`user`,text:t}]),await Ft(`[MODALITA PIANO] Descrivi cosa modificheresti per: "${e}". Elenca i file e cosa faresti. NON applicare modifiche ancora. Rispondi con il piano in bullet list.`,e,[]);return}Ie(e=>[...e,{role:`user`,text:t,attachments:n}]),await Ft(t,null,n)}async function Ft(e,t,n){if(ze)return;L(!0),c&&g.length>0&&E(`/api/studio/webcraft/snapshot`,{projectName:c}).catch(()=>{});let r={};g.forEach(e=>{r[e.name]=e.content});try{let i=new AbortController;wt.current=i;let a=await fetch(`/api/studio/webcraft/agent`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectName:c,message:e,attachments:n.map(e=>({name:e.name,mimeType:e.mimeType,base64:e.base64}))}),signal:i.signal});if(!a.ok||!a.body){Ie(e=>[...e,{role:`agent`,text:`Errore: ${a.status}`,tools:[]}]),L(!1);return}let o={role:`agent`,text:``,tools:[]};Ie(e=>[...e,o]);let s=a.body.getReader(),l=new TextDecoder,u=``,d=!1,f=``;for(;;){if(i.signal.aborted){try{s.cancel()}catch{}break}let{done:e,value:n}=await s.read();if(e)break;u+=l.decode(n,{stream:!0});let a=u.split(`
844
+ `);s=r.pop()??``;for(let e of r){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);if(e.type===`project_renamed`)l(e.name);else if(e.type===`processing`||e.type===`planning`)Me(t=>({...t,name:e.type===`planning`?`📋 Pianificazione struttura...`:e.msg||`Avvio...`}));else if(e.type===`file_start`)u.push({name:e.name,content:``,_pending:!0}),v([...u]),Me({fi:e.fi,total:e.total,name:e.name}),ge.current=u.length-1,_e.current&&=(clearTimeout(_e.current),null),b(u.length-1),S(``),ve.current=!0;else if(e.type===`file_chunk`){let t=u.find(t=>t.name===e.name);t&&(t.content+=e.chunk,t._pending=!1),v([...u]);let n=u.findIndex(t=>t.name===e.name);n>=0&&(ge.current=n,S(t?t.content:null))}else if(e.type===`file_done`){let t=u.find(t=>t.name===e.name);t&&(t._pending=!1,e.syntaxError&&(t._syntaxError=e.syntaxError)),v([...u]),Me({fi:e.fi,total:e.total,name:e.name}),(e.cumTokIn||e.cumTokOut)&&Pe({tokIn:e.cumTokIn||0,tokOut:e.cumTokOut||0})}else if(e.type===`file_error`){let t=u.find(t=>t.name===e.name);t&&(t._error=!0,t._pending=!1),v([...u])}else e.type===`phase`||e.type===`status`&&!e.op?Me(t=>({...t,name:e.msg||e.phase||``})):e.type===`done`&&(Ie({seconds:Math.round((Date.now()-n)/1e3),tokIn:e.tokIn??0,tokOut:e.tokOut??0,files:u.length}),S(null),Te(!1),ge.current=null,_e.current&&=(clearTimeout(_e.current),null),c&&jt(c),ue(!0),Ye(!1),qe([]),u.some(e=>e._error||e._syntaxError)?setTimeout(()=>Ot.current?.(),800):setTimeout(()=>At.current?.(),800))}catch{}}}}catch(e){e.name!==`AbortError`&&Re(t=>[...t,{role:`system`,text:`Errore generazione: `+e.message}]),Te(!1)}}async function It(e){let t=(e??ze).trim();if(!(c&&g.length>0)){if(!t||t.length<5)return;let e=c||`MyProject`;l(e),d(t),L(``),await Ft(t,e);return}if(!t&&He.length===0||Be||we)return;let n=[...He];if(Ue([]),L(``),t.toLowerCase().startsWith(`/plan `)||t.toLowerCase().startsWith(`piano: `)){let e=t.replace(/^\/plan[ ]*/i,``).replace(/^piano:[ ]*/i,``);Re(e=>[...e,{role:`user`,text:t}]),await Lt(`[MODALITA PIANO] Descrivi cosa modificheresti per: "${e}". Elenca i file e cosa faresti. NON applicare modifiche ancora. Rispondi con il piano in bullet list.`,e,[]);return}Re(e=>[...e,{role:`user`,text:t,attachments:n}]),await Lt(t,null,n)}async function Lt(e,t,n){if(Be)return;Ve(!0),c&&g.length>0&&E(`/api/studio/webcraft/snapshot`,{projectName:c}).catch(()=>{});let r={};g.forEach(e=>{r[e.name]=e.content});try{let i=new AbortController;Et.current=i;let a=await fetch(`/api/studio/webcraft/agent`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectName:c,message:e,attachments:n.map(e=>({name:e.name,mimeType:e.mimeType,base64:e.base64}))}),signal:i.signal});if(!a.ok||!a.body){Re(e=>[...e,{role:`agent`,text:`Errore: ${a.status}`,tools:[]}]),Ve(!1);return}let o={role:`agent`,text:``,tools:[]};Re(e=>[...e,o]);let s=a.body.getReader(),l=new TextDecoder,u=``,d=!1,f=``;for(;;){if(i.signal.aborted){try{s.cancel()}catch{}break}let{done:e,value:n}=await s.read();if(e)break;u+=l.decode(n,{stream:!0});let a=u.split(`
845
845
 
846
- `);u=a.pop()??``;for(let e of a){let n=e.replace(/^data: /,``).trim();if(n)try{let e=JSON.parse(n);if(e.type===`text`){f+=e.token;let t=f.lastIndexOf(`<`),n;t>=0&&!f.slice(t).includes(`>`)?(n=f.slice(0,t),f=f.slice(t)):(n=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``),f=``),n&&(o.text+=n)}else if(e.type===`step`)o.text+=`\n\n**[Step ${e.step}/${e.max}]** `;else if(e.type===`tool`)(e.op===`edit`||e.op===`write`)&&console.log(`[WC-DEBUG] tool event:`,e.op,e.path,`result:`,e.result,`oldSnippet:`,(e.oldSnippet||``).length,`newSnippet:`,(e.newSnippet||``).length),o.tools.push({op:e.op,path:e.path,result:e.result,oldSnippet:e.oldSnippet??``,newSnippet:e.newSnippet??``}),(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)&&(d=!0),Ie(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`files_changed`)e.files?.length&&await It(e.files,r);else if(e.type===`syntax_errors`)e.errors?.length&&(o.syntaxErrors=e.errors,Ie(e=>{let t=[...e];return t[t.length-1]={...o},t}));else if(e.type===`sandbox_restart`)o.text+=`
846
+ `);u=a.pop()??``;for(let e of a){let n=e.replace(/^data: /,``).trim();if(n)try{let e=JSON.parse(n);if(e.type===`text`){f+=e.token;let t=f.lastIndexOf(`<`),n;t>=0&&!f.slice(t).includes(`>`)?(n=f.slice(0,t),f=f.slice(t)):(n=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``),f=``),n&&(o.text+=n)}else if(e.type===`step`)o.text+=`\n\n**[Step ${e.step}/${e.max}]** `;else if(e.type===`tool`)(e.op===`edit`||e.op===`write`)&&console.log(`[WC-DEBUG] tool event:`,e.op,e.path,`result:`,e.result,`oldSnippet:`,(e.oldSnippet||``).length,`newSnippet:`,(e.newSnippet||``).length),o.tools.push({op:e.op,path:e.path,result:e.result,oldSnippet:e.oldSnippet??``,newSnippet:e.newSnippet??``}),(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)&&(d=!0),Re(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`files_changed`)e.files?.length&&await Rt(e.files,r);else if(e.type===`syntax_errors`)e.errors?.length&&(o.syntaxErrors=e.errors,Re(e=>{let t=[...e];return t[t.length-1]={...o},t}));else if(e.type===`sandbox_restart`)o.text+=`
847
847
 
848
- 🔄 `+(e.msg||`Restarting sandbox...`),Ie(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`sandbox_ready`)lt(e.port),o.text+=`
849
- ✅ Sandbox ready on port `+e.port,Ie(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`sandbox_error`)o.text+=`
850
- ❌ Sandbox error: `+e.msg,Ie(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`done`){if(f){let e=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``);e&&(o.text+=e),f=``}t&&!d&&Ue({plan:o.text,originalMessage:t}),L(!1),await It((o.tools??[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)).map(e=>e.path),r),c&&kt(c)}else e.type===`error`&&(o.text+=`
851
- Errore: `+e.msg,L(!1))}catch{}}}}catch(e){e instanceof DOMException&&e.name===`AbortError`||Ie(t=>[...t,{role:`agent`,text:`Errore di rete: `+e.message,tools:[]}])}if(L(!1),c){try{let e=await T(`/api/studio/webcraft/projects/load/${encodeURIComponent(c)}`);e?.files&&v(e.files)}catch{}setTimeout(()=>{c&&kt(c)},200)}}async function It(e,t){if(!c)return;let n=await T(`/api/studio/webcraft/projects/load/${encodeURIComponent(c)}`);if(n?.files&&(v(n.files),c&&setTimeout(()=>kt(c),300),e.length>0)){let r=e.map(e=>{let r=n.files.find(t=>t.name===e);return r?{file:e,before:t[e]??``,after:r.content??``}:null}).filter(Boolean);at(e=>[...e,...r])}}function Lt(){wt.current&&=(wt.current.abort(),null),Dt.current=!0,Ce(!1),L(!1),Te(!1),F(``),S(null),Ie(e=>[...e,{role:`system`,text:`⏹ Generazione interrotta.`}])}async function Rt(){return c?(await E(`/api/studio/webcraft/snapshot`,{projectName:c}))?.snapshot??null:null}async function zt(){let e=await Rt();e&&(Ie(t=>[...t,{role:`system`,text:`💾 Snapshot salvato (${e.slice(0,16).replace(`T`,` `)})`}]),Bt())}async function Bt(){if(!c)return;let e=await T(`/api/studio/webcraft/snapshots/${encodeURIComponent(c)}`);e?.snapshots&&Ze(e.snapshots)}async function Vt(e){confirm(`Ripristinare lo snapshot del ${e.replace(`T`,` `).slice(0,16)}? I file attuali verranno sovrascritti.`)&&await E(`/api/studio/webcraft/restore`,{projectName:c,ts:e})!==null&&(Ie(t=>[...t,{role:`agent`,text:`Snapshot ripristinato (${e}). Ricarico i file...`}]),It([],{}))}async function Ht(){if(!c)return;let e=await E(`/api/studio/webcraft/syntax-check`,{projectName:c});if(e?.results){let t=e.results.filter(e=>!e.ok);t.length>0?Ie(e=>[...e,{role:`system`,text:`⚠ Syntax check: ${t.length} errore/i trovato/i.`,syntaxErrors:t}]):Ie(e=>[...e,{role:`system`,text:`✓ Syntax check: tutti i file JS sono validi.`}])}}async function V(){let e=g.filter(e=>e._error||e._syntaxError);if(e.length===0){Ot.current?.();return}Dt.current=!1,Te(!0),P(0),Oe(e.length),St.current=Date.now(),bt(`0s`);for(let t=0;t<e.length&&!Dt.current;t++){let n=e[t];F(n.name),P(t);let r=`FIX ERROR in ${n.name}: ${n._syntaxError??`generazione fallita`}\n\nUse the edit tool to make surgical fixes. Do NOT rewrite the entire file — only change the broken parts. Read the file first, identify the exact lines with errors, and edit only those lines.`;try{await Ft(r,null,[])}catch{if(Dt.current)break}}c&&kt(c),Dt.current||(P(e.length),setTimeout(()=>Ot.current?.(),500)),F(``),Te(!1)}async function Wt(e){if(!ft){pt(!0),ht(null),lt(null),_t([]),i(`preview`);try{let t=await fetch(`/api/studio/webcraft/sandbox/start`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectName:e})});if(!t.ok||!t.body){ht(t.ok?`No response body`:`HTTP ${t.status}`),pt(!1);return}let n=t.body.getReader(),r=new TextDecoder,i=``;for(;;){let{done:e,value:t}=await n.read();if(e)break;i+=r.decode(t,{stream:!0});let a=i.split(`
848
+ 🔄 `+(e.msg||`Restarting sandbox...`),Re(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`sandbox_ready`)dt(e.port),o.text+=`
849
+ ✅ Sandbox ready on port `+e.port,Re(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`sandbox_error`)o.text+=`
850
+ ❌ Sandbox error: `+e.msg,Re(e=>{let t=[...e];return t[t.length-1]={...o},t});else if(e.type===`done`){if(f){let e=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``);e&&(o.text+=e),f=``}t&&!d&&Ge({plan:o.text,originalMessage:t}),Ve(!1),await Rt((o.tools??[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)).map(e=>e.path),r),c&&jt(c)}else e.type===`error`&&(o.text+=`
851
+ Errore: `+e.msg,Ve(!1))}catch{}}}}catch(e){e instanceof DOMException&&e.name===`AbortError`||Re(t=>[...t,{role:`agent`,text:`Errore di rete: `+e.message,tools:[]}])}if(Ve(!1),c){try{let e=await T(`/api/studio/webcraft/projects/load/${encodeURIComponent(c)}`);e?.files&&v(e.files)}catch{}setTimeout(()=>{c&&jt(c)},200)}}async function Rt(e,t){if(!c)return;let n=await T(`/api/studio/webcraft/projects/load/${encodeURIComponent(c)}`);if(n?.files&&(v(n.files),c&&setTimeout(()=>jt(c),300),e.length>0)){let r=e.map(e=>{let r=n.files.find(t=>t.name===e);return r?{file:e,before:t[e]??``,after:r.content??``}:null}).filter(Boolean);st(e=>[...e,...r])}}function zt(){Et.current&&=(Et.current.abort(),null),kt.current=!0,Te(!1),Ve(!1),P(!1),Ae(``),S(null),Re(e=>[...e,{role:`system`,text:`⏹ Generazione interrotta.`}])}async function Bt(){return c?(await E(`/api/studio/webcraft/snapshot`,{projectName:c}))?.snapshot??null:null}async function Vt(){let e=await Bt();e&&(Re(t=>[...t,{role:`system`,text:`💾 Snapshot salvato (${e.slice(0,16).replace(`T`,` `)})`}]),Ht())}async function Ht(){if(!c)return;let e=await T(`/api/studio/webcraft/snapshots/${encodeURIComponent(c)}`);e?.snapshots&&$e(e.snapshots)}async function V(e){confirm(`Ripristinare lo snapshot del ${e.replace(`T`,` `).slice(0,16)}? I file attuali verranno sovrascritti.`)&&await E(`/api/studio/webcraft/restore`,{projectName:c,ts:e})!==null&&(Re(t=>[...t,{role:`agent`,text:`Snapshot ripristinato (${e}). Ricarico i file...`}]),Rt([],{}))}async function Wt(){if(!c)return;let e=await E(`/api/studio/webcraft/syntax-check`,{projectName:c});if(e?.results){let t=e.results.filter(e=>!e.ok);t.length>0?Re(e=>[...e,{role:`system`,text:`⚠ Syntax check: ${t.length} errore/i trovato/i.`,syntaxErrors:t}]):Re(e=>[...e,{role:`system`,text:`✓ Syntax check: tutti i file JS sono validi.`}])}}async function Gt(){let e=g.filter(e=>e._error||e._syntaxError);if(e.length===0){At.current?.();return}kt.current=!1,P(!0),Oe(0),F(e.length),wt.current=Date.now(),St(`0s`);for(let t=0;t<e.length&&!kt.current;t++){let n=e[t];Ae(n.name),Oe(t);let r=`FIX ERROR in ${n.name}: ${n._syntaxError??`generazione fallita`}\n\nUse the edit tool to make surgical fixes. Do NOT rewrite the entire file — only change the broken parts. Read the file first, identify the exact lines with errors, and edit only those lines.`;try{await Lt(r,null,[])}catch{if(kt.current)break}}c&&jt(c),kt.current||(Oe(e.length),setTimeout(()=>At.current?.(),500)),Ae(``),P(!1)}async function Kt(e){if(!mt){ht(!0),_t(null),dt(null),yt([]),i(`preview`);try{let t=await fetch(`/api/studio/webcraft/sandbox/start`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectName:e})});if(!t.ok||!t.body){_t(t.ok?`No response body`:`HTTP ${t.status}`),ht(!1);return}let n=t.body.getReader(),r=new TextDecoder,i=``;for(;;){let{done:e,value:t}=await n.read();if(e)break;i+=r.decode(t,{stream:!0});let a=i.split(`
852
852
 
853
- `);i=a.pop()??``;for(let e of a){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);(e.type===`phase`||e.type===`status`||e.type===`log`||e.type===`warn`||e.type===`error`)&&_t(t=>[...t.slice(-49),{kind:e.type,msg:String(e.msg||``),ts:Date.now()}]),e.type===`ready`&&e.port?(lt(e.port),pt(!1)):e.type===`error`&&ht(e.msg)}catch{}}}}catch(e){ht(e.message||`Connection failed`)}pt(!1)}}async function Gt(){c&&await Wt(c)}(0,_.useEffect)(()=>{z.current=V,Ot.current=Gt});async function Kt(){if(!et||!c)return;let e=await E(`/api/studio/webcraft/grep`,{projectName:c,query:et});e?.matches&&rt(e.matches)}function qt(e){let t=g.findIndex(t=>t.name===e);t>=0&&(b(t),i(`files`))}function Jt(){window.open(`/api/studio/webcraft/download/${encodeURIComponent(c)}`,`_blank`)}async function Yt(e,t,n,r){t.endsWith(`.md`)||(t+=`.md`);let i={name:t,content:n,type:r},a;a=e.mode===`edit`&&e.idx!==null?We.map((t,n)=>n===e.idx?i:t):[...We,i],Ge(a),Ye(null);let o=c||`MyProject`;c||l(o),await E(`/api/studio/webcraft/skills/${encodeURIComponent(o)}`,{skills:a})}async function Xt(e){let t=We[e];!t||!confirm(`Eliminare "${t.name}"?`)||(await E(`/api/studio/webcraft/skills/${encodeURIComponent(c)}/delete`,{name:t.name}),Ge(We.filter((t,n)=>n!==e)))}async function Zt(e){let t=We[e];if(!t||!confirm(`Svuotare "${t.name}"? Il file rimane ma il contenuto viene cancellato.`))return;let n=We.map((t,n)=>n===e?{...t,content:``}:t);Ge(n),await E(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`,{skills:n})}async function Qt(){let e=await T(`/api/studio/webcraft/projects`);e?.projects&&st(e.projects)}async function H(e){let t=await T(`/api/studio/webcraft/projects/load/${encodeURIComponent(e.name)}`);if(!t)return;let r=t.projectName??e.name;l(r),d(t.description??``),v(t.files??[]),b(0),n(`new`),i(`files`),Ie([]),Ge([]),qe(!1),pe([]),kt(r);let a=await T(`/api/studio/webcraft/projects/chat/load/${encodeURIComponent(r)}`);a?.chat&&Ie(a.chat);let o=await T(`/api/studio/webcraft/skills/${encodeURIComponent(r)}`);o?.skills&&(Ge(o.skills),qe(!0))}async function $t(e){confirm(`Eliminare: ${e.name} - ${e.dir}?`)&&(await E(`/api/studio/webcraft/projects/${encodeURIComponent(e.name)}`,{},`DELETE`),st(ot.filter(t=>t.name!==e.name)),c===e.name&&(l(``),v([]),Ie([]),d(``)))}async function en(){if(!He)return;let e=He.originalMessage;Ue(null),await Ft(e+`
854
- [Piano approvato — procedi con le modifiche]`,null,[])}function tn(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];Ve(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let nn=c&&g.length>0,rn=g[y],U=ze||N;return(0,k.jsxs)(`div`,{className:Q.root,children:[(0,k.jsxs)(`div`,{className:Q.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`div`,{className:Q.title,children:[`⚙ WebCraft`,c?` — ${c}`:``]}),!c&&(0,k.jsx)(`div`,{className:Q.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,k.jsxs)(`div`,{className:Q.headerTabs,children:[(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`new`?Q.tabActive:``}`,onClick:async()=>{if(!(ee.size>0&&!confirm(`${ee.size} unsaved file(s). Discard changes and create new project?`))){if(ct){try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}lt(null)}v([]),b(0),S(null),w(null),te(new Set),Ie([]),l(``),d(``),Re(``),Ge([]),qe(!1),Pe(null),Ce(!1),L(!1),oe(!1),ce(null),n(`new`)}},children:`+ Nuovo`}),(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`projects`?Q.tabActive:``}`,onClick:()=>{n(`projects`),Qt()},children:`📁 Progetti`})]})]}),(0,k.jsx)(`div`,{className:Q.body,children:t===`projects`?(0,k.jsx)(`div`,{className:Q.projectsList,children:ot.length===0?(0,k.jsxs)(`div`,{className:Q.emptyProjects,children:[(0,k.jsx)(`span`,{className:Q.emptyIcon,children:`📁`}),(0,k.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,k.jsx)(`span`,{className:Q.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):ot.map(e=>(0,k.jsxs)(`div`,{className:Q.projectCard,children:[(0,k.jsxs)(`div`,{className:Q.projectInfo,children:[(0,k.jsx)(`div`,{className:Q.projectName,children:e.name}),(0,k.jsx)(`div`,{className:Q.projectDesc,children:e.description}),(0,k.jsxs)(`div`,{className:Q.projectMeta,children:[(0,k.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,k.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,k.jsx)(`button`,{className:Q.openBtn,onClick:()=>H(e),children:`↗ Apri`}),(0,k.jsx)(`button`,{className:Q.deleteBtn,onClick:()=>$t(e),children:`🗑`})]},e.name))}):(0,k.jsxs)(`div`,{className:Q.editor,"data-mobile-view":a?o:void 0,children:[(0,k.jsxs)(`div`,{className:Q.examples,children:[(0,k.jsx)(`div`,{className:Q.sectionLabel,children:`Esempi`}),(0,k.jsx)(`div`,{className:Q.examplePills,children:eE.map(e=>(0,k.jsx)(`button`,{className:Q.examplePill,onClick:()=>{l(e.name),d(e.desc),Re(e.desc)},children:e.name},e.name))})]}),(0,k.jsxs)(`div`,{className:Q.editorCols,children:[(0,k.jsxs)(`div`,{className:Q.leftSidebar,children:[(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Blocchi`}),tE.map(e=>(0,k.jsxs)(`label`,{className:Q.blockLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:f[e.key],onChange:t=>p(n=>({...n,[e.key]:t.target.checked})),className:Q.blockCheck}),(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.key))]}),f.auth&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Campi Auth`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>h(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),m.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.authField,children:[(0,k.jsx)(`input`,{value:e.label,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:Q.authFieldInput}),(0,k.jsx)(`select`,{value:e.type,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:Q.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}),(0,k.jsx)(`input`,{type:`checkbox`,checked:e.required,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,required:e.target.checked}:n)),title:`Required`,className:Q.authFieldReq}),(0,k.jsx)(`button`,{onClick:()=>h(e=>e.filter((e,n)=>n!==t)),className:Q.removeFieldBtn,children:`×`})]},t))]}),(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`🗂 Contesto AI`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>Ye({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),We.length>0?(0,k.jsx)(`div`,{className:Q.skillsList,children:We.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.skillRow,children:[(0,k.jsx)(`span`,{className:Q.skillIcon,children:aE(e.type)}),(0,k.jsx)(`span`,{className:Q.skillName,title:e.name,children:e.name}),(0,k.jsx)(`span`,{className:`${Q.skillBadge} ${Q[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,k.jsx)(`span`,{className:Q.skillEmpty,children:`⚠`}),(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Ye({mode:e.type===`log`?`view`:`edit`,idx:t,name:e.name,content:e.content,type:e.type,generating:!1}),children:e.type===`log`?`👁`:`✏`}),e.type!==`memory`&&e.type!==`provider`&&e.type!==`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Zt(t),children:`🗑`}),e.type===`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Xt(t),children:`🗑`})]},t))}):(0,k.jsx)(`div`,{className:Q.skillsEmpty,children:Ke?`Nessun file di contesto. Clicca "+ Skill" per aggiungerne uno.`:`Crea o carica un progetto per i file di contesto.`})]}),Xe.length>0&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`💾 Snapshot`}),Xe.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,k.jsxs)(`div`,{className:Q.snapshotRow,children:[(0,k.jsx)(`span`,{className:Q.snapshotTs,children:t}),(0,k.jsxs)(`span`,{className:Q.snapshotCount,children:[e.fileCount,`f`]}),(0,k.jsx)(`button`,{className:Q.snapshotBtn,onClick:()=>Vt(e.ts),children:`↺`})]},e.ts)})]}),N&&(0,k.jsx)(`div`,{className:Q.genStatus,children:`⏳ Generazione...`}),we&&(0,k.jsxs)(`div`,{className:Q.repairStatus,children:[(0,k.jsx)(`div`,{className:Q.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,k.jsxs)(`div`,{className:Q.repairStatusProg,children:[Ee,` / `,De,` file`]}),(0,k.jsx)(`div`,{className:Q.repairStatusFile,children:ke})]}),g.length>0&&!N&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.actionRow,children:[(0,k.jsx)(`button`,{className:Q.actionBtn,onClick:Jt,children:`⬇ ZIP`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Syntax check`,onClick:Ht,children:`✅`}),(0,k.jsx)(`button`,{className:`${Q.actionBtnIcon} ${Qe?Q.actionBtnActive:``}`,title:`Grep`,onClick:()=>$e(!Qe),children:`🔍`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Snapshot`,onClick:zt,children:`💾`})]}),g.some(e=>e._error||e._syntaxError)&&!we&&(0,k.jsx)(`button`,{className:Q.repairBtn,onClick:V,children:`🔧 Correggi tutti i file rossi`}),(0,k.jsx)(`button`,{className:Q.sandboxBtn,onClick:()=>{c?Wt(c):i(`preview`)},children:ft?`⏳ Starting...`:ct?`🌐 Sandbox Live`:`▶ Sandbox`}),Ne&&(0,k.jsxs)(`div`,{className:Q.statsBar,children:[(0,k.jsxs)(`span`,{children:[`⏱ `,Ne.seconds>=60?`${Math.floor(Ne.seconds/60)}m ${Ne.seconds%60}s`:`${Ne.seconds}s`]}),(0,k.jsxs)(`span`,{children:[`↑ `,Ne.tokIn.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`↓ `,Ne.tokOut.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`📄 `,Ne.files,` file`]})]})]})]}),(0,k.jsxs)(`div`,{className:Q.rightPanel,children:[(0,k.jsxs)(`div`,{className:Q.rightTabBar,children:[(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?``:Q.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?Q.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),we&&(0,k.jsxs)(`div`,{className:Q.repairBar,children:[(0,k.jsxs)(`div`,{className:Q.repairBarRow,children:[(0,k.jsx)(`span`,{className:Q.repairBarIcon,children:`🔧`}),(0,k.jsx)(`span`,{className:Q.repairBarLabel,children:`Auto-fix`}),(0,k.jsx)(`span`,{className:Q.repairBarFile,children:ke}),(0,k.jsxs)(`span`,{className:Q.repairBarCounter,children:[Ee,` / `,De]}),(0,k.jsx)(`span`,{className:Q.repairBarTime,children:R}),(0,k.jsx)(`button`,{className:Q.stopBtn,onClick:Lt,children:`⏹ Stop`})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.repairProgress,style:{width:De>0?`${Math.round(Ee/De*100)}%`:`0%`}})})]}),N&&(0,k.jsxs)(`div`,{className:Q.genBar,children:[(0,k.jsxs)(`div`,{className:Q.genBarRow,children:[(0,k.jsx)(`span`,{className:Q.genBarRobot,children:`🤖`}),(0,k.jsx)(`span`,{className:Q.genBarLabel,children:I.total===0?`Pianificazione...`:`Generazione`}),(0,k.jsx)(`span`,{className:Q.genBarFile,children:(I.name||``).split(`,`)[0].trim()}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:I.total>0?`${I.fi} / ${I.total}`:``}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:je.tokIn+je.tokOut>0?`↑${jt(je.tokIn)} ↓${jt(je.tokOut)}`:``}),(0,k.jsx)(`span`,{className:Q.genBarTime,children:vt}),(0,k.jsxs)(`span`,{className:Q.genDots,children:[(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot1}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot2}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot3}`})]})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.genProgress,style:{width:I.total>0?`${Math.round(I.fi/I.total*100)}%`:`0%`}})})]}),r===`preview`?(0,k.jsxs)(`div`,{className:Q.sandboxWrap,children:[(0,k.jsxs)(`div`,{className:Q.sandboxStatusBar,children:[(0,k.jsx)(`span`,{className:Q.sandboxStatusDot,style:{background:ct?`#4ade80`:ft?`#facc15`:`#64748b`}}),(0,k.jsx)(`span`,{className:Q.sandboxStatusText,children:ct?`Live :${ct}`:ft?`Starting...`:`Stopped`}),ct&&(0,k.jsx)(`button`,{className:Q.sandboxReloadBtn,onClick:()=>{let e=document.querySelector(`iframe[title="WebCraft Sandbox"]`);e&&(e.src=e.src)},children:`↻`}),ct&&(0,k.jsx)(`button`,{className:Q.sandboxStopBtn,onClick:async()=>{lt(null),M([]);try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}},children:`⏹`}),!ct&&!ft&&(0,k.jsx)(`button`,{className:Q.sandboxStartBtnSmall,onClick:()=>{c&&Wt(c)},children:`▶ Start`})]}),de.length>0&&(0,k.jsxs)(`div`,{className:Q.runtimeErrors,children:[(0,k.jsxs)(`div`,{className:Q.runtimeErrorsHeader,children:[(0,k.jsxs)(`span`,{children:[`❌ `,de.length,` runtime error`,de.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsFix,onClick:()=>{let e=`Fix these runtime errors. Use edit_file (or create_file if the file doesn't exist) to actually modify the source — do NOT respond with text descriptions. After each fix, call check_syntax to verify. If edit_file fails because old_text doesn't match, read_file again and retry with the exact text.\n\n${de.map(e=>`${e.message} (${e.source||``}:${e.line||0})`).join(`
855
- `)}`;fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),M([]),i(`files`),Pt(e)},children:`🔧 Auto-fix`}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsDismiss,onClick:()=>{fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),M([])},children:`✕`})]}),de.slice(0,3).map((e,t)=>(0,k.jsxs)(`div`,{className:Q.runtimeErrorLine,children:[e.message,e.source?` — ${e.source.split(`/`).pop()}:${e.line}`:``]},t))]}),ct?(0,k.jsx)(`iframe`,{src:`http://localhost:${ct}`,className:Q.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`}):(0,k.jsxs)(`div`,{className:Q.sandboxEmpty,children:[(0,k.jsx)(`span`,{style:{fontSize:48},children:ft?`⏳`:mt?`❌`:`🌐`}),(0,k.jsx)(`span`,{style:{fontWeight:700,fontSize:16},children:ft?`Starting sandbox...`:mt?`Sandbox Error`:`Preview`}),mt&&(0,k.jsx)(`pre`,{style:{fontSize:11,maxWidth:600,textAlign:`left`,color:`#f87171`,background:`rgba(248,113,113,0.08)`,border:`1px solid rgba(248,113,113,0.2)`,borderRadius:6,padding:`8px 12px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,margin:`8px 0`,lineHeight:1.5,maxHeight:200,overflow:`auto`},children:mt}),gt.length>0&&(0,k.jsxs)(`div`,{style:{width:`100%`,maxWidth:720,margin:`8px 0`,textAlign:`left`},children:[(0,k.jsxs)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,letterSpacing:`0.5px`,marginBottom:4},children:[`Sandbox log (`,gt.length,`)`]}),(0,k.jsx)(`pre`,{style:{fontSize:11,lineHeight:1.5,fontFamily:`SF Mono, Monaco, monospace`,background:`rgba(15, 23, 42, 0.6)`,border:`1px solid rgba(148, 163, 184, 0.18)`,borderRadius:6,padding:`8px 12px`,maxHeight:240,overflow:`auto`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,color:`#cbd5e1`},children:gt.slice(-40).map((e,t)=>(0,k.jsx)(`div`,{style:{color:e.kind===`error`?`#f87171`:e.kind===`warn`?`#fbbf24`:e.kind===`phase`?`#60a5fa`:e.kind===`status`?`#34d399`:`#94a3b8`},children:`[${e.kind}] ${e.msg}`},t))})]}),!ft&&(0,k.jsxs)(`button`,{className:Q.sandboxStartBtn,onClick:()=>{c&&Wt(c)},children:[`▶ `,mt?`Retry`:`Start Sandbox`]})]})]}):(0,k.jsx)(`div`,{className:Q.codeArea,children:g.length===0&&N?(0,k.jsx)(`div`,{className:Q.noFiles,children:(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`⏳`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`Pianificazione...`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:I.name||`Analisi della struttura del progetto in corso`})]})}):g.length===0?(0,k.jsxs)(`div`,{className:Q.noFiles,children:[(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`🔨`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`WebCraft`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:`Genera progetti web completi con AI`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesSteps,children:[(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`1`}),(0,k.jsx)(`span`,{children:`Scegli un esempio o scrivi una descrizione nel box in basso`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`2`}),(0,k.jsxs)(`span`,{children:[`Premi `,(0,k.jsx)(`strong`,{children:`▶ Genera`}),` — l'AI crea tutti i file del progetto`]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`3`}),(0,k.jsx)(`span`,{children:`Chiedi modifiche in chat, scarica lo ZIP o avvia il Sandbox`})]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesExamplesHint,children:[`💡 Prova: `,(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=eE[0];l(e.name),d(e.desc),Re(e.desc)},children:`MySaaS`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=eE[1];l(e.name),d(e.desc),Re(e.desc)},children:`MyShop`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=eE[3];l(e.name),d(e.desc),Re(e.desc)},children:`MyPortfolio`})]})]}):(0,k.jsxs)(`div`,{className:Q.codeLayout,children:[(0,k.jsx)(`div`,{className:Q.ideTabBar,children:g.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===y;return(0,k.jsxs)(`button`,{className:`${Q.ideTab} ${r?Q.ideTabActive:``} ${n?Q.ideTabError:``} ${e._pending?Q.ideTabPending:``}`,onClick:()=>{b(t),w(null),S(null),N&&me.current!==null&&t!==me.current&&(he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{me.current!==null&&(b(me.current),S(null))},1e4))},title:e.name,children:[(0,k.jsx)(`span`,{className:Q.ideTabIcon,children:e._pending?`⌛`:n?`⚠`:rE(e.name)}),(0,k.jsx)(`span`,{className:Q.ideTabName,children:(e.name||``).split(`/`).pop()}),ee.has(e.name)&&(0,k.jsx)(`span`,{className:Q.ideTabUnsaved,children:`●`}),n&&(0,k.jsx)(`span`,{className:Q.ideTabDot})]},t)})}),xe&&(0,k.jsxs)(`div`,{className:Q.diffOverlay,children:[(0,k.jsxs)(`div`,{className:Q.diffOverlayHeader,children:[(0,k.jsxs)(`span`,{children:[`✏ Modifica proposta — `,(0,k.jsx)(`strong`,{children:xe.file})]}),(0,k.jsxs)(`div`,{className:Q.diffOverlayActions,children:[(0,k.jsx)(`button`,{className:Q.diffAcceptBtn,onClick:()=>{v(e=>e.map(e=>e.name===xe.file?{...e,content:xe.after}:e)),Se(null)},children:`✓ Accetta`}),(0,k.jsx)(`button`,{className:Q.diffRejectBtn,onClick:()=>Se(null),children:`✕ Rifiuta`})]})]}),(0,k.jsx)(`div`,{className:Q.diffOverlayBody,children:(0,k.jsx)(uE,{before:xe.before,after:xe.after})})]}),(0,k.jsxs)(`div`,{className:Q.codeRow,children:[(0,k.jsxs)(`div`,{className:Q.fileTreeWrap,children:[fe.length>0&&(0,k.jsxs)(`div`,{className:Q.scanBanner,children:[(0,k.jsx)(`span`,{className:Q.scanBannerIcon,children:`⚠`}),(0,k.jsxs)(`span`,{className:Q.scanBannerText,children:[fe.length,` issue`,fe.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.scanBannerFix,onClick:async()=>{i(`files`);try{let e=await E(`/api/studio/webcraft/auto-repair`,{projectName:c});if(e?.summary){let t=(e.repairs||[]).slice(0,20).map(e=>` • ${e.file} (${e.kind}${e.source?` from ${e.source}`:``})`).join(`
856
- `);Ie(n=>[...n,{role:`agent`,text:`🔧 Auto-repair: ${e.summary}\n${t}`,tools:[]}])}let t=await E(`/api/studio/webcraft/complete`,{projectName:c}),n=t?.htmlRewrites?.length||0,r=t?.llmFills?.length||0,i=t?.stubFallbacks?.length||0;if(n+r+i>0){let e=[];n&&e.push(...(t.htmlRewrites||[]).map(e=>` • ${e.from}: ${e.oldHref} → ${e.newHref} (point to real file)`)),r&&e.push(...(t.llmFills||[]).map(e=>` • ${e.target} (${e.length} bytes, LLM-generated)`)),i&&e.push(...(t.stubFallbacks||[]).map(e=>` • ${e} (stub fallback — LLM unavailable)`)),Ie(t=>[...t,{role:`agent`,text:`✨ Asset completion: ${n} HTML rewrites, ${r} via LLM${i?`, ${i} as stubs`:``}\n${e.join(`
857
- `)}`,tools:[]}])}let a=await E(`/api/studio/webcraft/extend-styles`,{projectName:c});a?.extended&&Ie(e=>[...e,{role:`agent`,text:`🎨 Styles auto-extended: ${a.file} (${a.sizeBefore}→${a.sizeAfter} bytes, coverage ${((a.coverageBefore||0)*100).toFixed(0)}%→${((a.coverageAfter||0)*100).toFixed(0)}%, ${(a.missingBefore||0)-(a.missingAfter||0)} new selectors covered)`,tools:[]}]),await It([...e?.filesRepaired||[],...e?.filesCreated||[],...(t?.htmlRewrites||[]).map(e=>e.from),...(t?.llmFills||[]).map(e=>e.target),...a?.file?[a.file]:[]],{}),await kt(c)}catch(e){console.error(`[fix] failed:`,e)}},children:`Fix`})]}),(0,k.jsx)(WT,{files:g,activeIndex:y,unsavedFiles:ee,errorFiles:new Set(fe.filter(e=>e.severity===`error`).map(e=>e.file)),onSelect:e=>{b(e),w(null),S(null),N&&me.current!==null&&e!==me.current&&(he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{me.current!==null&&(b(me.current),S(null))},1e4))}})]}),(0,k.jsx)(`div`,{className:Q.codeEditorWrap,children:rn&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:rE(rn.name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:rn.name}),rn.content&&!rn._error&&(0,k.jsxs)(`span`,{className:Q.codeFileMeta,children:[(rn.content||``).split(`
858
- `).length,` righe · `,iE(rn.content||``)]}),!rn._pending&&!rn._error&&rn.content&&(0,k.jsx)(`button`,{className:`${Q.editToggleBtn} ${C===null?``:Q.editToggleBtnActive}`,onClick:()=>{C===null?w(rn.content):(v(e=>e.map((e,t)=>t===y?{...e,content:C}:e)),E(`/api/studio/webcraft/file/write`,{projectName:c,path:rn.name,content:C}),w(null))},children:C===null?`✏ Modifica`:`💾 Salva`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Split view`,onClick:()=>ce(se===null?+(y===0&&g.length>1):null),children:`⫼`}),(0,k.jsx)(`button`,{className:`${Q.headerIconBtn} ${A?Q.headerIconBtnActive:``}`,title:`Terminal`,onClick:()=>oe(!A),children:`⌨`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Development Guide`,onClick:()=>ue(!0),children:`📖`})]}),ne&&(0,k.jsxs)(`div`,{className:Q.findBar,children:[(0,k.jsx)(`input`,{className:Q.findInput,value:D,onChange:e=>ie(e.target.value),placeholder:`Find...`,autoFocus:!0}),(0,k.jsx)(`input`,{className:Q.findInput,value:O,onChange:e=>ae(e.target.value),placeholder:`Replace...`}),(0,k.jsx)(`span`,{className:Q.findCount,children:D?((rn.content||``).match(new RegExp(D.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`))?.length||0)+` found`:``}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!D||C===null||w(C.replace(new RegExp(D.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`i`),O))},children:`Replace`}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!D||C===null||w(C.replace(new RegExp(D.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`),O))},children:`All`}),(0,k.jsx)(`button`,{className:Q.findClose,onClick:()=>re(!1),children:`×`})]}),rn._error&&(0,k.jsx)(`div`,{className:Q.fileError,children:`⚠ Generazione fallita — chiedi al modello di rigenerare questo file`}),rn._syntaxError&&!rn._error&&(0,k.jsxs)(`div`,{className:Q.fileSyntaxError,children:[`⚠ Syntax error: `,rn._syntaxError]}),N&&x!==null?(0,k.jsx)(`pre`,{className:Q.streamingPre,ref:e=>{e&&ge.current&&(e.scrollTop=e.scrollHeight)},onScroll:e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<50?ge.current=!0:(ge.current=!1,_e.current&&clearTimeout(_e.current),_e.current=setTimeout(()=>{ge.current=!0},15e3))},dangerouslySetInnerHTML:{__html:QT(x||``,(rn.name.split(`.`).pop()||`js`).toLowerCase())+`<span class="`+Q.streamingCursor+`">▋</span>`}}):(0,k.jsx)(RT,{value:C===null?rn.content||``:C,filename:rn.name,readOnly:C===null,projectName:c,onChange:e=>{w(e),rn&&te(e=>new Set(e).add(rn.name))},onSave:e=>{v(t=>t.map((t,n)=>n===y?{...t,content:e}:t)),E(`/api/studio/webcraft/file/write`,{projectName:c,path:rn.name,content:e}),w(null),te(e=>{let t=new Set(e);return t.delete(rn.name),t})}})]})}),se!==null&&g[se]&&(0,k.jsxs)(`div`,{className:Q.codeEditorWrap,children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:rE(g[se].name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:g[se].name}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,onClick:()=>ce(null),children:`✕`})]}),(0,k.jsx)(RT,{value:g[se].content||``,filename:g[se].name,readOnly:!0})]})]}),A&&(0,k.jsxs)(`div`,{className:Q.terminalPanel,children:[(0,k.jsxs)(`div`,{className:Q.terminalHeader,children:[(0,k.jsx)(`span`,{className:Q.terminalTitle,children:`Terminal`}),(0,k.jsx)(`button`,{className:Q.terminalClose,onClick:()=>oe(!1),children:`✕`})]}),(0,k.jsx)(YT,{projectDir:c||void 0})]})]})})]})]})]})}),He&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.planBanner,children:[(0,k.jsx)(`div`,{className:Q.planTitle,children:`📌 Piano proposto — approva per eseguire`}),(0,k.jsx)(`pre`,{className:Q.planText,children:He.plan}),(0,k.jsxs)(`div`,{className:Q.planActions,children:[(0,k.jsx)(`button`,{className:Q.planApprove,onClick:en,children:`✓ Esegui`}),(0,k.jsx)(`button`,{className:Q.planReject,onClick:()=>Ue(null),children:`✕ Annulla`})]})]}),Qe&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.grepPanel,children:[(0,k.jsxs)(`div`,{className:Q.grepRow,children:[(0,k.jsx)(`input`,{className:Q.grepInput,value:et,onChange:e=>tt(e.target.value),onKeyDown:e=>e.key===`Enter`&&Kt(),placeholder:`Cerca nel codice...`}),(0,k.jsx)(`button`,{className:Q.grepBtn,onClick:Kt,children:`🔍`}),(0,k.jsx)(`button`,{className:Q.grepClose,onClick:()=>$e(!1),children:`×`})]}),nt.length>0&&(0,k.jsxs)(`div`,{className:Q.grepCount,children:[nt.length,` risultati`]}),(0,k.jsx)(`div`,{className:Q.grepResults,children:nt.length===0?(0,k.jsx)(`div`,{className:Q.grepEmpty,children:`Nessun risultato.`}):nt.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.grepMatch,onClick:()=>qt(e.file),children:[(0,k.jsxs)(`span`,{className:Q.grepMatchFile,children:[e.file,`:`,e.lineNum]}),(0,k.jsx)(`pre`,{className:Q.grepMatchLine,children:e.line})]},t))})]}),it.length>0&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.diffPanel,children:[(0,k.jsxs)(`div`,{className:Q.diffHeader,children:[(0,k.jsxs)(`span`,{children:[`🔌 Diff — `,it.length,` file modificati`]}),(0,k.jsx)(`button`,{className:Q.diffClose,onClick:()=>at([]),children:`✕ Chiudi`})]}),it.map((e,t)=>{let n=(e.after||``).split(`
853
+ `);i=a.pop()??``;for(let e of a){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);(e.type===`phase`||e.type===`status`||e.type===`log`||e.type===`warn`||e.type===`error`)&&yt(t=>[...t.slice(-49),{kind:e.type,msg:String(e.msg||``),ts:Date.now()}]),e.type===`ready`&&e.port?(dt(e.port),ht(!1)):e.type===`error`&&_t(e.msg)}catch{}}}}catch(e){_t(e.message||`Connection failed`)}ht(!1)}}async function qt(){c&&await Kt(c)}(0,_.useEffect)(()=>{Ot.current=Gt,At.current=qt});async function Jt(){if(!nt||!c)return;let e=await E(`/api/studio/webcraft/grep`,{projectName:c,query:nt});e?.matches&&at(e.matches)}function Yt(e){let t=g.findIndex(t=>t.name===e);t>=0&&(b(t),i(`files`))}function Xt(){window.open(`/api/studio/webcraft/download/${encodeURIComponent(c)}`,`_blank`)}async function Zt(e,t,n,r){t.endsWith(`.md`)||(t+=`.md`);let i={name:t,content:n,type:r},a;a=e.mode===`edit`&&e.idx!==null?Ke.map((t,n)=>n===e.idx?i:t):[...Ke,i],qe(a),Ze(null);let o=c||`MyProject`;c||l(o),await E(`/api/studio/webcraft/skills/${encodeURIComponent(o)}`,{skills:a})}async function Qt(e){let t=Ke[e];!t||!confirm(`Eliminare "${t.name}"?`)||(await E(`/api/studio/webcraft/skills/${encodeURIComponent(c)}/delete`,{name:t.name}),qe(Ke.filter((t,n)=>n!==e)))}async function H(e){let t=Ke[e];if(!t||!confirm(`Svuotare "${t.name}"? Il file rimane ma il contenuto viene cancellato.`))return;let n=Ke.map((t,n)=>n===e?{...t,content:``}:t);qe(n),await E(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`,{skills:n})}async function $t(){let e=await T(`/api/studio/webcraft/projects`);e?.projects&&lt(e.projects)}async function en(e){let t=await T(`/api/studio/webcraft/projects/load/${encodeURIComponent(e.name)}`);if(!t)return;let r=t.projectName??e.name;l(r),d(t.description??``),v(t.files??[]),b(0),n(`new`),i(`files`),Re([]),qe([]),Ye(!1),pe([]),jt(r);let a=await T(`/api/studio/webcraft/projects/chat/load/${encodeURIComponent(r)}`);a?.chat&&Re(a.chat);let o=await T(`/api/studio/webcraft/skills/${encodeURIComponent(r)}`);o?.skills&&(qe(o.skills),Ye(!0))}async function tn(e){confirm(`Eliminare: ${e.name} - ${e.dir}?`)&&(await E(`/api/studio/webcraft/projects/${encodeURIComponent(e.name)}`,{},`DELETE`),lt(ct.filter(t=>t.name!==e.name)),c===e.name&&(l(``),v([]),Re([]),d(``)))}async function nn(){if(!We)return;let e=We.originalMessage;Ge(null),await Lt(e+`
854
+ [Piano approvato — procedi con le modifiche]`,null,[])}function rn(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];Ue(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let U=c&&g.length>0,an=g[y],on=Be||we;return(0,k.jsxs)(`div`,{className:Q.root,children:[(0,k.jsxs)(`div`,{className:Q.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`div`,{className:Q.title,children:[`⚙ WebCraft`,c?` — ${c}`:``]}),!c&&(0,k.jsx)(`div`,{className:Q.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,k.jsxs)(`div`,{className:Q.headerTabs,children:[(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`new`?Q.tabActive:``}`,onClick:async()=>{if(!(ee.size>0&&!confirm(`${ee.size} unsaved file(s). Discard changes and create new project?`))){if(ut){try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}dt(null)}v([]),b(0),S(null),w(null),te(new Set),Re([]),l(``),d(``),L(``),qe([]),Ye(!1),Ie(null),Te(!1),Ve(!1),oe(!1),ce(null),n(`new`)}},children:`+ Nuovo`}),(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`projects`?Q.tabActive:``}`,onClick:()=>{n(`projects`),$t()},children:`📁 Progetti`})]})]}),(0,k.jsx)(`div`,{className:Q.body,children:t===`projects`?(0,k.jsx)(`div`,{className:Q.projectsList,children:ct.length===0?(0,k.jsxs)(`div`,{className:Q.emptyProjects,children:[(0,k.jsx)(`span`,{className:Q.emptyIcon,children:`📁`}),(0,k.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,k.jsx)(`span`,{className:Q.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):ct.map(e=>(0,k.jsxs)(`div`,{className:Q.projectCard,children:[(0,k.jsxs)(`div`,{className:Q.projectInfo,children:[(0,k.jsx)(`div`,{className:Q.projectName,children:e.name}),(0,k.jsx)(`div`,{className:Q.projectDesc,children:e.description}),(0,k.jsxs)(`div`,{className:Q.projectMeta,children:[(0,k.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,k.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,k.jsx)(`button`,{className:Q.openBtn,onClick:()=>en(e),children:`↗ Apri`}),(0,k.jsx)(`button`,{className:Q.deleteBtn,onClick:()=>tn(e),children:`🗑`})]},e.name))}):(0,k.jsxs)(`div`,{className:Q.editor,"data-mobile-view":a?o:void 0,children:[(0,k.jsxs)(`div`,{className:Q.examples,children:[(0,k.jsx)(`div`,{className:Q.sectionLabel,children:`Esempi`}),(0,k.jsx)(`div`,{className:Q.examplePills,children:eE.map(e=>(0,k.jsx)(`button`,{className:Q.examplePill,onClick:()=>{l(e.name),d(e.desc),L(e.desc)},children:e.name},e.name))})]}),(0,k.jsxs)(`div`,{className:Q.editorCols,children:[(0,k.jsxs)(`div`,{className:Q.leftSidebar,children:[(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Blocchi`}),tE.map(e=>(0,k.jsxs)(`label`,{className:Q.blockLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:f[e.key],onChange:t=>p(n=>({...n,[e.key]:t.target.checked})),className:Q.blockCheck}),(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.key))]}),f.auth&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Campi Auth`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>h(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),m.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.authField,children:[(0,k.jsx)(`input`,{value:e.label,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:Q.authFieldInput}),(0,k.jsx)(`select`,{value:e.type,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:Q.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}),(0,k.jsx)(`input`,{type:`checkbox`,checked:e.required,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,required:e.target.checked}:n)),title:`Required`,className:Q.authFieldReq}),(0,k.jsx)(`button`,{onClick:()=>h(e=>e.filter((e,n)=>n!==t)),className:Q.removeFieldBtn,children:`×`})]},t))]}),(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`🗂 Contesto AI`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>Ze({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),Ke.length>0?(0,k.jsx)(`div`,{className:Q.skillsList,children:Ke.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.skillRow,children:[(0,k.jsx)(`span`,{className:Q.skillIcon,children:aE(e.type)}),(0,k.jsx)(`span`,{className:Q.skillName,title:e.name,children:e.name}),(0,k.jsx)(`span`,{className:`${Q.skillBadge} ${Q[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,k.jsx)(`span`,{className:Q.skillEmpty,children:`⚠`}),(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Ze({mode:e.type===`log`?`view`:`edit`,idx:t,name:e.name,content:e.content,type:e.type,generating:!1}),children:e.type===`log`?`👁`:`✏`}),e.type!==`memory`&&e.type!==`provider`&&e.type!==`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>H(t),children:`🗑`}),e.type===`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Qt(t),children:`🗑`})]},t))}):(0,k.jsx)(`div`,{className:Q.skillsEmpty,children:Je?`Nessun file di contesto. Clicca "+ Skill" per aggiungerne uno.`:`Crea o carica un progetto per i file di contesto.`})]}),Qe.length>0&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`💾 Snapshot`}),Qe.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,k.jsxs)(`div`,{className:Q.snapshotRow,children:[(0,k.jsx)(`span`,{className:Q.snapshotTs,children:t}),(0,k.jsxs)(`span`,{className:Q.snapshotCount,children:[e.fileCount,`f`]}),(0,k.jsx)(`button`,{className:Q.snapshotBtn,onClick:()=>V(e.ts),children:`↺`})]},e.ts)})]}),we&&(0,k.jsx)(`div`,{className:Q.genStatus,children:`⏳ Generazione...`}),Ee&&(0,k.jsxs)(`div`,{className:Q.repairStatus,children:[(0,k.jsx)(`div`,{className:Q.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,k.jsxs)(`div`,{className:Q.repairStatusProg,children:[De,` / `,ke,` file`]}),(0,k.jsx)(`div`,{className:Q.repairStatusFile,children:I})]}),g.length>0&&!we&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.actionRow,children:[(0,k.jsx)(`button`,{className:Q.actionBtn,onClick:Xt,children:`⬇ ZIP`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Syntax check`,onClick:Wt,children:`✅`}),(0,k.jsx)(`button`,{className:`${Q.actionBtnIcon} ${et?Q.actionBtnActive:``}`,title:`Grep`,onClick:()=>tt(!et),children:`🔍`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Snapshot`,onClick:Vt,children:`💾`})]}),g.some(e=>e._error||e._syntaxError)&&!Ee&&(0,k.jsx)(`button`,{className:Q.repairBtn,onClick:Gt,children:`🔧 Correggi tutti i file rossi`}),(0,k.jsx)(`button`,{className:Q.sandboxBtn,onClick:()=>{c?Kt(c):i(`preview`)},children:mt?`⏳ Starting...`:ut?`🌐 Sandbox Live`:`▶ Sandbox`}),Fe&&(0,k.jsxs)(`div`,{className:Q.statsBar,children:[(0,k.jsxs)(`span`,{children:[`⏱ `,Fe.seconds>=60?`${Math.floor(Fe.seconds/60)}m ${Fe.seconds%60}s`:`${Fe.seconds}s`]}),(0,k.jsxs)(`span`,{children:[`↑ `,Fe.tokIn.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`↓ `,Fe.tokOut.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`📄 `,Fe.files,` file`]})]})]})]}),(0,k.jsxs)(`div`,{className:Q.rightPanel,children:[(0,k.jsxs)(`div`,{className:Q.rightTabBar,children:[(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?``:Q.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?Q.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),Ee&&(0,k.jsxs)(`div`,{className:Q.repairBar,children:[(0,k.jsxs)(`div`,{className:Q.repairBarRow,children:[(0,k.jsx)(`span`,{className:Q.repairBarIcon,children:`🔧`}),(0,k.jsx)(`span`,{className:Q.repairBarLabel,children:`Auto-fix`}),(0,k.jsx)(`span`,{className:Q.repairBarFile,children:I}),(0,k.jsxs)(`span`,{className:Q.repairBarCounter,children:[De,` / `,ke]}),(0,k.jsx)(`span`,{className:Q.repairBarTime,children:xt}),(0,k.jsx)(`button`,{className:Q.stopBtn,onClick:zt,children:`⏹ Stop`})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.repairProgress,style:{width:ke>0?`${Math.round(De/ke*100)}%`:`0%`}})})]}),we&&(0,k.jsxs)(`div`,{className:Q.genBar,children:[(0,k.jsxs)(`div`,{className:Q.genBarRow,children:[(0,k.jsx)(`span`,{className:Q.genBarRobot,children:`🤖`}),(0,k.jsx)(`span`,{className:Q.genBarLabel,children:je.total===0?`Pianificazione...`:`Generazione`}),(0,k.jsx)(`span`,{className:Q.genBarFile,children:(je.name||``).split(`,`)[0].trim()}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:je.total>0?`${je.fi} / ${je.total}`:``}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:Ne.tokIn+Ne.tokOut>0?`↑${B(Ne.tokIn)} ↓${B(Ne.tokOut)}`:``}),(0,k.jsx)(`span`,{className:Q.genBarTime,children:R}),(0,k.jsxs)(`span`,{className:Q.genDots,children:[(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot1}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot2}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot3}`})]})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.genProgress,style:{width:je.total>0?`${Math.round(je.fi/je.total*100)}%`:`0%`}})})]}),r===`preview`?(0,k.jsxs)(`div`,{className:Q.sandboxWrap,children:[(0,k.jsxs)(`div`,{className:Q.sandboxStatusBar,children:[(0,k.jsx)(`span`,{className:Q.sandboxStatusDot,style:{background:ut?`#4ade80`:mt?`#facc15`:`#64748b`}}),(0,k.jsx)(`span`,{className:Q.sandboxStatusText,children:ut?`Live :${ut}`:mt?`Starting...`:`Stopped`}),ut&&(0,k.jsx)(`button`,{className:Q.sandboxReloadBtn,onClick:()=>{let e=document.querySelector(`iframe[title="WebCraft Sandbox"]`);e&&(e.src=e.src)},children:`↻`}),ut&&(0,k.jsx)(`button`,{className:Q.sandboxStopBtn,onClick:async()=>{dt(null),M([]);try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}},children:`⏹`}),!ut&&!mt&&(0,k.jsx)(`button`,{className:Q.sandboxStartBtnSmall,onClick:()=>{c&&Kt(c)},children:`▶ Start`})]}),de.length>0&&(0,k.jsxs)(`div`,{className:Q.runtimeErrors,children:[(0,k.jsxs)(`div`,{className:Q.runtimeErrorsHeader,children:[(0,k.jsxs)(`span`,{children:[`❌ `,de.length,` runtime error`,de.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsFix,onClick:()=>{let e=`Fix these runtime errors. Use edit_file (or create_file if the file doesn't exist) to actually modify the source — do NOT respond with text descriptions. After each fix, call check_syntax to verify. If edit_file fails because old_text doesn't match, read_file again and retry with the exact text.\n\n${de.map(e=>`${e.message} (${e.source||``}:${e.line||0})`).join(`
855
+ `)}`;fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),M([]),i(`files`),It(e)},children:`🔧 Auto-fix`}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsDismiss,onClick:()=>{fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),M([])},children:`✕`})]}),de.slice(0,3).map((e,t)=>(0,k.jsxs)(`div`,{className:Q.runtimeErrorLine,children:[e.message,e.source?` — ${e.source.split(`/`).pop()}:${e.line}`:``]},t))]}),ut?(0,k.jsx)(`iframe`,{src:`http://localhost:${ut}`,className:Q.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`}):(0,k.jsxs)(`div`,{className:Q.sandboxEmpty,children:[(0,k.jsx)(`span`,{style:{fontSize:48},children:mt?`⏳`:gt?`❌`:`🌐`}),(0,k.jsx)(`span`,{style:{fontWeight:700,fontSize:16},children:mt?`Starting sandbox...`:gt?`Sandbox Error`:`Preview`}),gt&&(0,k.jsx)(`pre`,{style:{fontSize:11,maxWidth:600,textAlign:`left`,color:`#f87171`,background:`rgba(248,113,113,0.08)`,border:`1px solid rgba(248,113,113,0.2)`,borderRadius:6,padding:`8px 12px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,margin:`8px 0`,lineHeight:1.5,maxHeight:200,overflow:`auto`},children:gt}),vt.length>0&&(0,k.jsxs)(`div`,{style:{width:`100%`,maxWidth:720,margin:`8px 0`,textAlign:`left`},children:[(0,k.jsxs)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,letterSpacing:`0.5px`,marginBottom:4},children:[`Sandbox log (`,vt.length,`)`]}),(0,k.jsx)(`pre`,{style:{fontSize:11,lineHeight:1.5,fontFamily:`SF Mono, Monaco, monospace`,background:`rgba(15, 23, 42, 0.6)`,border:`1px solid rgba(148, 163, 184, 0.18)`,borderRadius:6,padding:`8px 12px`,maxHeight:240,overflow:`auto`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,color:`#cbd5e1`},children:vt.slice(-40).map((e,t)=>(0,k.jsx)(`div`,{style:{color:e.kind===`error`?`#f87171`:e.kind===`warn`?`#fbbf24`:e.kind===`phase`?`#60a5fa`:e.kind===`status`?`#34d399`:`#94a3b8`},children:`[${e.kind}] ${e.msg}`},t))})]}),!mt&&(0,k.jsxs)(`button`,{className:Q.sandboxStartBtn,onClick:()=>{c&&Kt(c)},children:[`▶ `,gt?`Retry`:`Start Sandbox`]})]})]}):(0,k.jsx)(`div`,{className:Q.codeArea,children:g.length===0&&we?(0,k.jsx)(`div`,{className:Q.noFiles,children:(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`⏳`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`Pianificazione...`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:je.name||`Analisi della struttura del progetto in corso`})]})}):g.length===0?(0,k.jsxs)(`div`,{className:Q.noFiles,children:[(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`🔨`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`WebCraft`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:`Genera progetti web completi con AI`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesSteps,children:[(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`1`}),(0,k.jsx)(`span`,{children:`Scegli un esempio o scrivi una descrizione nel box in basso`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`2`}),(0,k.jsxs)(`span`,{children:[`Premi `,(0,k.jsx)(`strong`,{children:`▶ Genera`}),` — l'AI crea tutti i file del progetto`]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`3`}),(0,k.jsx)(`span`,{children:`Chiedi modifiche in chat, scarica lo ZIP o avvia il Sandbox`})]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesExamplesHint,children:[`💡 Prova: `,(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=eE[0];l(e.name),d(e.desc),L(e.desc)},children:`MySaaS`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=eE[1];l(e.name),d(e.desc),L(e.desc)},children:`MyShop`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=eE[3];l(e.name),d(e.desc),L(e.desc)},children:`MyPortfolio`})]})]}):(0,k.jsxs)(`div`,{className:Q.codeLayout,children:[(0,k.jsx)(`div`,{className:Q.ideTabBar,children:g.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===y;return(0,k.jsxs)(`button`,{className:`${Q.ideTab} ${r?Q.ideTabActive:``} ${n?Q.ideTabError:``} ${e._pending?Q.ideTabPending:``}`,onClick:()=>{b(t),w(null),S(null),we&&ge.current!==null&&t!==ge.current&&(_e.current&&clearTimeout(_e.current),_e.current=setTimeout(()=>{ge.current!==null&&(b(ge.current),S(null))},1e4))},title:e.name,children:[(0,k.jsx)(`span`,{className:Q.ideTabIcon,children:e._pending?`⌛`:n?`⚠`:rE(e.name)}),(0,k.jsx)(`span`,{className:Q.ideTabName,children:(e.name||``).split(`/`).pop()}),ee.has(e.name)&&(0,k.jsx)(`span`,{className:Q.ideTabUnsaved,children:`●`}),n&&(0,k.jsx)(`span`,{className:Q.ideTabDot})]},t)})}),N&&(0,k.jsxs)(`div`,{className:Q.diffOverlay,children:[(0,k.jsxs)(`div`,{className:Q.diffOverlayHeader,children:[(0,k.jsxs)(`span`,{children:[`✏ Modifica proposta — `,(0,k.jsx)(`strong`,{children:N.file})]}),(0,k.jsxs)(`div`,{className:Q.diffOverlayActions,children:[(0,k.jsx)(`button`,{className:Q.diffAcceptBtn,onClick:()=>{v(e=>e.map(e=>e.name===N.file?{...e,content:N.after}:e)),Ce(null)},children:`✓ Accetta`}),(0,k.jsx)(`button`,{className:Q.diffRejectBtn,onClick:()=>Ce(null),children:`✕ Rifiuta`})]})]}),(0,k.jsx)(`div`,{className:Q.diffOverlayBody,children:(0,k.jsx)(uE,{before:N.before,after:N.after})})]}),(0,k.jsxs)(`div`,{className:Q.codeRow,children:[(0,k.jsxs)(`div`,{className:Q.fileTreeWrap,children:[fe.length>0&&(0,k.jsxs)(`div`,{className:Q.scanBanner,children:[(0,k.jsx)(`span`,{className:Q.scanBannerIcon,children:`⚠`}),(0,k.jsxs)(`span`,{className:Q.scanBannerText,children:[fe.length,` issue`,fe.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.scanBannerToggle,onClick:()=>he(!me),title:me?`Hide problems panel`:`Show problems panel`,children:me?`▴`:`▾`}),(0,k.jsx)(`button`,{className:Q.scanBannerFix,onClick:async()=>{i(`files`);try{let e=await E(`/api/studio/webcraft/auto-repair`,{projectName:c});if(e?.summary){let t=(e.repairs||[]).slice(0,20).map(e=>` • ${e.file} (${e.kind}${e.source?` from ${e.source}`:``})`).join(`
856
+ `);Re(n=>[...n,{role:`agent`,text:`🔧 Auto-repair: ${e.summary}\n${t}`,tools:[]}])}let t=await E(`/api/studio/webcraft/complete`,{projectName:c}),n=t?.htmlRewrites?.length||0,r=t?.llmFills?.length||0,i=t?.stubFallbacks?.length||0;if(n+r+i>0){let e=[];n&&e.push(...(t.htmlRewrites||[]).map(e=>` • ${e.from}: ${e.oldHref} → ${e.newHref} (point to real file)`)),r&&e.push(...(t.llmFills||[]).map(e=>` • ${e.target} (${e.length} bytes, LLM-generated)`)),i&&e.push(...(t.stubFallbacks||[]).map(e=>` • ${e} (stub fallback — LLM unavailable)`)),Re(t=>[...t,{role:`agent`,text:`✨ Asset completion: ${n} HTML rewrites, ${r} via LLM${i?`, ${i} as stubs`:``}\n${e.join(`
857
+ `)}`,tools:[]}])}let a=await E(`/api/studio/webcraft/extend-styles`,{projectName:c});a?.extended&&Re(e=>[...e,{role:`agent`,text:`🎨 Styles auto-extended: ${a.file} (${a.sizeBefore}→${a.sizeAfter} bytes, coverage ${((a.coverageBefore||0)*100).toFixed(0)}%→${((a.coverageAfter||0)*100).toFixed(0)}%, ${(a.missingBefore||0)-(a.missingAfter||0)} new selectors covered)`,tools:[]}]),await Rt([...e?.filesRepaired||[],...e?.filesCreated||[],...(t?.htmlRewrites||[]).map(e=>e.from),...(t?.llmFills||[]).map(e=>e.target),...a?.file?[a.file]:[]],{}),await jt(c)}catch(e){console.error(`[fix] failed:`,e)}},children:`Fix`})]}),fe.length>0&&me&&(()=>{let e=new Map;for(let t of fe)e.has(t.file)||e.set(t.file,[]),e.get(t.file).push(t);let t=/^Line (\d+):\s*(.+)$/;return(0,k.jsx)(`div`,{className:Q.problemsPanel,children:[...e.entries()].map(([e,n])=>{let r=n.filter(e=>e.severity===`error`).length,a=n.filter(e=>e.severity===`warning`).length;return(0,k.jsxs)(`div`,{className:Q.problemsGroup,children:[(0,k.jsxs)(`div`,{className:Q.problemsGroupHeader,onClick:()=>{let t=g.findIndex(t=>t.name===e);t>=0&&(b(t),w(null),S(null),i(`files`))},children:[(0,k.jsxs)(`span`,{children:[`📄 `,e]}),(0,k.jsxs)(`span`,{className:Q.problemsGroupCount,children:[r>0&&(0,k.jsxs)(`span`,{style:{color:`#f87171`},children:[r,` error`,r>1?`s`:``]}),r>0&&a>0&&(0,k.jsx)(`span`,{style:{color:`var(--dim)`},children:`, `}),a>0&&(0,k.jsxs)(`span`,{style:{color:`#facc15`},children:[a,` warning`,a>1?`s`:``]})]})]}),n.map((n,r)=>{let a=n.message.match(t),o=a?parseInt(a[1]):null,s=a?a[2]:n.message,c=n.severity===`error`?`✕`:n.severity===`warning`?`⚠`:`ℹ`,l=n.severity===`error`?Q.problemsIconError:n.severity===`warning`?Q.problemsIconWarning:Q.problemsIconInfo;return(0,k.jsxs)(`div`,{className:Q.problemsItem,onClick:()=>{let t=g.findIndex(t=>t.name===e);t>=0&&(b(t),w(null),S(null),i(`files`),o&&setTimeout(()=>{let e=document.querySelector(`.cm-editor .cm-scroller`);e&&(e.scrollTop=Math.max(0,(o-5)*18))},100))},title:`Click to open ${e}${o?` at line `+o:``}`,children:[(0,k.jsx)(`span`,{className:`${Q.problemsIcon} ${l}`,children:c}),(0,k.jsx)(`span`,{className:Q.problemsMsg,children:s}),o&&(0,k.jsxs)(`span`,{className:Q.problemsLine,children:[`[L`,o,`]`]})]},r)})]},e)})})})(),(0,k.jsx)(WT,{files:g,activeIndex:y,unsavedFiles:ee,errorFiles:new Set(fe.filter(e=>e.severity===`error`).map(e=>e.file)),onSelect:e=>{b(e),w(null),S(null),we&&ge.current!==null&&e!==ge.current&&(_e.current&&clearTimeout(_e.current),_e.current=setTimeout(()=>{ge.current!==null&&(b(ge.current),S(null))},1e4))}})]}),(0,k.jsx)(`div`,{className:Q.codeEditorWrap,children:an&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:rE(an.name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:an.name}),an.content&&!an._error&&(0,k.jsxs)(`span`,{className:Q.codeFileMeta,children:[(an.content||``).split(`
858
+ `).length,` righe · `,iE(an.content||``)]}),!an._pending&&!an._error&&an.content&&(0,k.jsx)(`button`,{className:`${Q.editToggleBtn} ${C===null?``:Q.editToggleBtnActive}`,onClick:()=>{C===null?w(an.content):(v(e=>e.map((e,t)=>t===y?{...e,content:C}:e)),E(`/api/studio/webcraft/file/write`,{projectName:c,path:an.name,content:C}),w(null))},children:C===null?`✏ Modifica`:`💾 Salva`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Split view`,onClick:()=>ce(se===null?+(y===0&&g.length>1):null),children:`⫼`}),(0,k.jsx)(`button`,{className:`${Q.headerIconBtn} ${A?Q.headerIconBtnActive:``}`,title:`Terminal`,onClick:()=>oe(!A),children:`⌨`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Development Guide`,onClick:()=>ue(!0),children:`📖`})]}),ne&&(0,k.jsxs)(`div`,{className:Q.findBar,children:[(0,k.jsx)(`input`,{className:Q.findInput,value:D,onChange:e=>ie(e.target.value),placeholder:`Find...`,autoFocus:!0}),(0,k.jsx)(`input`,{className:Q.findInput,value:O,onChange:e=>ae(e.target.value),placeholder:`Replace...`}),(0,k.jsx)(`span`,{className:Q.findCount,children:D?((an.content||``).match(new RegExp(D.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`))?.length||0)+` found`:``}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!D||C===null||w(C.replace(new RegExp(D.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`i`),O))},children:`Replace`}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!D||C===null||w(C.replace(new RegExp(D.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`),O))},children:`All`}),(0,k.jsx)(`button`,{className:Q.findClose,onClick:()=>re(!1),children:`×`})]}),an._error&&(0,k.jsx)(`div`,{className:Q.fileError,children:`⚠ Generazione fallita — chiedi al modello di rigenerare questo file`}),an._syntaxError&&!an._error&&(0,k.jsxs)(`div`,{className:Q.fileSyntaxError,children:[`⚠ Syntax error: `,an._syntaxError]}),we&&x!==null&&y===ge.current?(0,k.jsx)(`pre`,{className:Q.streamingPre,ref:e=>{e&&ve.current&&(e.scrollTop=e.scrollHeight)},onScroll:e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<50?ve.current=!0:(ve.current=!1,ye.current&&clearTimeout(ye.current),ye.current=setTimeout(()=>{ve.current=!0},15e3))},dangerouslySetInnerHTML:{__html:QT(x||``,(an.name.split(`.`).pop()||`js`).toLowerCase())+`<span class="`+Q.streamingCursor+`">▋</span>`}}):(0,k.jsx)(RT,{value:C===null?an.content||``:C,filename:an.name,readOnly:C===null,projectName:c,onChange:e=>{w(e),an&&te(e=>new Set(e).add(an.name))},onSave:e=>{v(t=>t.map((t,n)=>n===y?{...t,content:e}:t)),E(`/api/studio/webcraft/file/write`,{projectName:c,path:an.name,content:e}),w(null),te(e=>{let t=new Set(e);return t.delete(an.name),t})}})]})}),se!==null&&g[se]&&(0,k.jsxs)(`div`,{className:Q.codeEditorWrap,children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:rE(g[se].name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:g[se].name}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,onClick:()=>ce(null),children:`✕`})]}),(0,k.jsx)(RT,{value:g[se].content||``,filename:g[se].name,readOnly:!0})]})]}),A&&(0,k.jsxs)(`div`,{className:Q.terminalPanel,children:[(0,k.jsxs)(`div`,{className:Q.terminalHeader,children:[(0,k.jsx)(`span`,{className:Q.terminalTitle,children:`Terminal`}),(0,k.jsx)(`button`,{className:Q.terminalClose,onClick:()=>oe(!1),children:`✕`})]}),(0,k.jsx)(YT,{projectDir:c||void 0})]})]})})]})]})]})}),We&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.planBanner,children:[(0,k.jsx)(`div`,{className:Q.planTitle,children:`📌 Piano proposto — approva per eseguire`}),(0,k.jsx)(`pre`,{className:Q.planText,children:We.plan}),(0,k.jsxs)(`div`,{className:Q.planActions,children:[(0,k.jsx)(`button`,{className:Q.planApprove,onClick:nn,children:`✓ Esegui`}),(0,k.jsx)(`button`,{className:Q.planReject,onClick:()=>Ge(null),children:`✕ Annulla`})]})]}),et&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.grepPanel,children:[(0,k.jsxs)(`div`,{className:Q.grepRow,children:[(0,k.jsx)(`input`,{className:Q.grepInput,value:nt,onChange:e=>rt(e.target.value),onKeyDown:e=>e.key===`Enter`&&Jt(),placeholder:`Cerca nel codice...`}),(0,k.jsx)(`button`,{className:Q.grepBtn,onClick:Jt,children:`🔍`}),(0,k.jsx)(`button`,{className:Q.grepClose,onClick:()=>tt(!1),children:`×`})]}),it.length>0&&(0,k.jsxs)(`div`,{className:Q.grepCount,children:[it.length,` risultati`]}),(0,k.jsx)(`div`,{className:Q.grepResults,children:it.length===0?(0,k.jsx)(`div`,{className:Q.grepEmpty,children:`Nessun risultato.`}):it.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.grepMatch,onClick:()=>Yt(e.file),children:[(0,k.jsxs)(`span`,{className:Q.grepMatchFile,children:[e.file,`:`,e.lineNum]}),(0,k.jsx)(`pre`,{className:Q.grepMatchLine,children:e.line})]},t))})]}),ot.length>0&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.diffPanel,children:[(0,k.jsxs)(`div`,{className:Q.diffHeader,children:[(0,k.jsxs)(`span`,{children:[`🔌 Diff — `,ot.length,` file modificati`]}),(0,k.jsx)(`button`,{className:Q.diffClose,onClick:()=>st([]),children:`✕ Chiudi`})]}),ot.map((e,t)=>{let n=(e.after||``).split(`
859
859
  `).length-(e.before||``).split(`
860
- `).length;return(0,k.jsxs)(`details`,{open:!0,className:Q.diffFile,children:[(0,k.jsxs)(`summary`,{className:Q.diffSummary,children:[(0,k.jsx)(`span`,{className:Q.diffArrow,children:`▲`}),(0,k.jsx)(`span`,{className:Q.diffFileName,children:e.file}),(0,k.jsxs)(`span`,{className:n>=0?Q.diffAdded:Q.diffRemoved,children:[n>=0?`+`:``,n,` linee`]})]}),(0,k.jsx)(`div`,{className:Q.diffContent,children:(0,k.jsx)(uE,{before:e.before,after:e.after})})]},t)})]}),t!==`projects`&&(0,k.jsxs)(`div`,{className:`${Q.chatPanel} ${ut?Q.chatPanelCollapsed:``}`,children:[(0,k.jsxs)(`button`,{className:Q.chatCollapseBtn,onClick:()=>dt(e=>!e),children:[(0,k.jsx)(`span`,{children:ut?`▲`:`▼`}),(0,k.jsx)(`span`,{children:ut?`Show Chat`:`Hide Chat`}),Fe.length>0&&(0,k.jsxs)(`span`,{style:{opacity:.5},children:[`(`,Fe.length,`)`]})]}),(0,k.jsxs)(`div`,{className:Q.chatMessages,ref:Tt,children:[Fe.length===0&&nn&&(0,k.jsxs)(`div`,{className:Q.chatWelcome,children:[`🤖 `,e(`webcraft.doctrine.title`),` — `,(0,k.jsx)(`button`,{className:Q.doctrineOpenBtn,onClick:()=>ue(!0),children:`📖 Open Guide`})]}),Fe.map((e,t)=>(0,k.jsxs)(`div`,{className:e.role===`user`?Q.chatUser:e.role===`system`?Q.chatSystem:Q.chatAgent,children:[e.role===`user`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatUserBubble,children:e.text}),e.attachments&&e.attachments.length>0&&(0,k.jsx)(`div`,{className:Q.chatAttachPreviews,children:e.attachments.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.chatAttachBadge,children:[`📎 `,e.name]},t))})]}),e.role===`system`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatSystemBubble,children:e.text}),e.syntaxErrors?.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.chatSyntaxErr,children:[`✕ `,e.file,`: `,e.error]},t))]}),e.role===`agent`&&(()=>{let t=e.text.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/?>/g,``).trim(),n=(e.tools||[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)),r=(e.tools||[]).filter(e=>e.result?.includes(`not_found`)||e.result?.includes(`error`)||e.result===`blocked_use_edit`),a=t.match(/^(.{10,120}?)[.\n]/),o=a?a[1]+`.`:t.slice(0,120),s=t.length>130;return(0,k.jsxs)(`div`,{className:Q.chatAgentCard,children:[n.map((e,t)=>(0,k.jsxs)(`div`,{style:{margin:`6px 0`,borderRadius:8,overflow:`hidden`,border:`1px solid rgba(255,255,255,0.08)`},children:[(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`6px 10px`,background:`rgba(99,102,241,0.1)`,fontSize:11},children:[(0,k.jsxs)(`span`,{style:{fontWeight:600,color:`#818cf8`,cursor:`pointer`},onClick:()=>{let t=g.findIndex(t=>t.name===e.path);t>=0&&(b(t),i(`files`))},children:[`✏ `,e.path]}),(0,k.jsx)(`span`,{style:{color:`#4ade80`,fontSize:10,fontWeight:600},children:e.result===`ok_fuzzy`?`applied (fuzzy)`:e.result===`ok_repaired`?`applied (repaired)`:`✓ applied`})]}),e.oldSnippet||e.newSnippet?(0,k.jsx)(uE,{before:e.oldSnippet||``,after:e.newSnippet||``,contextLines:3}):(0,k.jsx)(`div`,{style:{padding:`6px 10px`,fontSize:11,color:`#4ade80`,background:`rgba(74,222,128,0.05)`},children:`File modified successfully`})]},t)),r.length>0&&(0,k.jsx)(`div`,{style:{margin:`6px 0`,padding:`6px 10px`,background:`rgba(248,113,113,0.08)`,borderRadius:6,fontSize:11,color:`#f87171`},children:r.map((e,t)=>(0,k.jsxs)(`div`,{children:[`❌ `,e.op,` `,e.path,`: `,typeof e.result==`string`?e.result.slice(0,100):``]},t))}),t&&(s?(0,k.jsxs)(`details`,{style:{margin:`6px 0`,fontSize:11},children:[(0,k.jsx)(`summary`,{style:{cursor:`pointer`,color:`var(--dim)`,padding:`4px 0`,userSelect:`none`},children:o.slice(0,100)}),(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8,marginTop:4},dangerouslySetInnerHTML:{__html:$T(t)}})]}):(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8},dangerouslySetInnerHTML:{__html:$T(t)}}))]})})()]},t)),ze&&(()=>{let e=Fe[Fe.length-1]?.tools??[],t=e[e.length-1],n=t?t.op===`read`?`Reading ${t.path}`:t.op===`edit`?`Editing ${t.path}`:t.op===`search`?`Searching...`:t.op===`lint`?`Linting ${t.path}`:t.op===`check`?`Checking ${t.path}`:t.op===`run`?`Running command...`:t.op===`sandbox`?`Starting sandbox...`:t.op:`Thinking...`;return(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`8px 12px`,fontSize:12,color:`#818cf8`},children:[(0,k.jsx)(`span`,{className:Q.chatAgentRobotAnim,style:{fontSize:14},children:`⟳`}),(0,k.jsx)(`span`,{style:{fontWeight:500},children:n})]})})()]}),Be.length>0&&(0,k.jsx)(`div`,{className:Q.attachPreviews,children:Be.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.attachBadge,children:[`📎 `,e.name,(0,k.jsx)(`button`,{className:Q.removeAttachBtn,onClick:()=>Ve(e=>e.filter((e,n)=>n!==t)),children:`×`})]},t))}),nn?(0,k.jsxs)(`div`,{className:Q.projActiveRow,children:[`📄 `,(0,k.jsx)(`strong`,{className:Q.projActiveName,children:c}),` — scrivi per modificare o migliorare il progetto`]}):(0,k.jsxs)(`div`,{className:Q.projNameRow,children:[(0,k.jsx)(`span`,{className:Q.projNameLabel,children:`Nome progetto:`}),(0,k.jsx)(`input`,{className:Q.projNameInput,value:c,onChange:e=>l(e.target.value),placeholder:`MioProgetto`})]}),(0,k.jsxs)(`div`,{className:Q.chatInputRow,children:[(0,k.jsxs)(`label`,{className:Q.attachLabel,title:`Allega immagine o PDF`,children:[`📎`,(0,k.jsx)(`input`,{ref:Et,type:`file`,multiple:!0,accept:`image/*,.pdf`,style:{display:`none`},onChange:e=>tn(e.target.files)})]}),(0,k.jsx)(`textarea`,{className:Q.chatTextarea,value:Le,onChange:e=>Re(e.target.value),placeholder:nn?`Parla con il tuo agente: chiedi correzioni, migliorie, nuove funzionalità...`:`Descrivi il progetto da creare, poi premi Genera...`,disabled:U,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Pt())},rows:4}),(0,k.jsxs)(`div`,{className:Q.chatSendCol,children:[(0,k.jsx)(`button`,{className:Q.chatSendBtn,onClick:()=>Pt(),disabled:U,children:N?`⏳`:nn?`▶`:`▶ Genera`}),U&&!we&&(0,k.jsx)(`button`,{className:Q.chatStopBtn,onClick:Lt,children:`⏹ Stop`})]})]})]}),le&&(0,k.jsx)(`div`,{className:Q.modalOverlay,onClick:()=>ue(!1),children:(0,k.jsxs)(`div`,{className:Q.modal,onClick:e=>e.stopPropagation(),style:{width:720,maxHeight:`90vh`},children:[(0,k.jsxs)(`div`,{className:Q.modalHeader,children:[(0,k.jsxs)(`span`,{className:Q.modalTitle,children:[`📖 `,e(`webcraft.doctrine.title`)]}),(0,k.jsx)(`span`,{className:Q.doctrineSubtitle,children:e(`webcraft.doctrine.subtitle`)}),(0,k.jsx)(`button`,{className:Q.modalClose,onClick:()=>ue(!1),children:`✕`})]}),(0,k.jsx)(`div`,{className:Q.modalBody,style:{gap:0},children:[`phase1`,`phase2`,`phase3`,`phase4`,`phase5`,`tools`,`golden`].map(t=>(0,k.jsxs)(`div`,{className:Q.doctrineSection,children:[(0,k.jsx)(`div`,{className:Q.doctrineSectionTitle,children:e(`webcraft.doctrine.${t}.title`)}),(0,k.jsx)(`div`,{className:Q.doctrineSectionBody,children:e(`webcraft.doctrine.${t}.desc`).split(`
861
- `).map((e,t)=>(0,k.jsx)(`p`,{className:e.startsWith(`•`)||e.startsWith(`1.`)||e.startsWith(`2.`)||e.startsWith(`3.`)||e.startsWith(`4.`)||e.startsWith(`5.`)||e.startsWith(`6.`)?Q.doctrineBullet:``,children:e},t))})]},t))}),(0,k.jsx)(`div`,{className:Q.modalFooter,children:(0,k.jsx)(`button`,{className:Q.modalSaveBtn,onClick:()=>ue(!1),style:{padding:`10px 28px`,fontSize:14},children:e(`webcraft.doctrine.close`)})})]})}),Je&&(0,k.jsx)(dE,{modal:Je,skills:We,projectName:c,onClose:()=>Ye(null),onSave:(e,t,n)=>Yt(Je,e,t,n)}),a&&t===`new`&&(0,k.jsx)(XT,{tabs:ZT,active:o,onChange:s,className:Q.mobileTabBar,buttonClassName:Q.mobileTabBtn,activeClassName:Q.mobileTabBtnActive})]})}function sE(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===r&&e.every((e,n)=>e===t[n]))return e.map((e,t)=>({type:`same`,text:e,oldLine:t+1,newLine:t+1}));if(n+r>8e3)return cE(e,t);let i=n+r,a=2*i+1,o=new Int32Array(a).fill(-1),s=i;o[s+1]=0;let c=[];outer:for(let l=0;l<=i;l++){let i=new Int32Array(a);i.set(o),c.push(i);for(let i=-l;i<=l;i+=2){let a;a=i===-l||i!==l&&o[s+i-1]<o[s+i+1]?o[s+i+1]:o[s+i-1]+1;let c=a-i;for(;a<n&&c<r&&e[a]===t[c];)a++,c++;if(o[s+i]=a,a>=n&&c>=r)break outer}}let l=[],u=n,d=r;for(let n=c.length-1;n>0;n--){let r=c[n-1],i=u-d,a;a=i===-n||i!==n&&r[s+i-1]<r[s+i+1]?i+1:i-1;let o=r[s+a],f=o-a;for(;u>o&&d>f;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});u>o?(u--,l.push({type:`rem`,text:e[u],oldLine:u+1})):d>f&&(d--,l.push({type:`add`,text:t[d],newLine:d+1}))}for(;u>0&&d>0;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});return l.reverse(),l}function cE(e,t){let n=[],r=0,i=0;for(;(r<e.length||i<t.length)&&(r>=e.length?(n.push({type:`add`,text:t[i],newLine:i+1}),i++):i>=t.length?(n.push({type:`rem`,text:e[r],oldLine:r+1}),r++):e[r]===t[i]?(n.push({type:`same`,text:e[r],oldLine:r+1,newLine:i+1}),r++,i++):(n.push({type:`rem`,text:e[r],oldLine:r+1}),n.push({type:`add`,text:t[i],newLine:i+1}),r++,i++),!(n.length>4e3)););return n}function lE(e,t){let n=(e||``).split(/(\s+)/),r=(t||``).split(/(\s+)/),i=n.length,a=r.length;if(i+a>400)return{old:(0,k.jsx)(k.Fragment,{children:e}),new:(0,k.jsx)(k.Fragment,{children:t})};let o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=1;e<=i;e++)for(let t=1;t<=a;t++)o[e][t]=n[e-1]===r[t-1]?o[e-1][t-1]+1:Math.max(o[e-1][t],o[e][t-1]);let s=[],c=[],l=i,u=a,d=[],f=[];for(;l>0||u>0;)l>0&&u>0&&n[l-1]===r[u-1]?(d.push({text:n[l-1],changed:!1}),f.push({text:r[u-1],changed:!1}),l--,u--):u>0&&(l===0||o[l][u-1]>=o[l-1][u])?(f.push({text:r[u-1],changed:!0}),u--):(d.push({text:n[l-1],changed:!0}),l--);return d.reverse().forEach(e=>s.push(e)),f.reverse().forEach(e=>c.push(e)),{old:(0,k.jsx)(k.Fragment,{children:s.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(248,113,113,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))}),new:(0,k.jsx)(k.Fragment,{children:c.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(74,222,128,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))})}}function uE({before:e,after:t,contextLines:n=3}){let r=sE((e||``).split(`
860
+ `).length;return(0,k.jsxs)(`details`,{open:!0,className:Q.diffFile,children:[(0,k.jsxs)(`summary`,{className:Q.diffSummary,children:[(0,k.jsx)(`span`,{className:Q.diffArrow,children:`▲`}),(0,k.jsx)(`span`,{className:Q.diffFileName,children:e.file}),(0,k.jsxs)(`span`,{className:n>=0?Q.diffAdded:Q.diffRemoved,children:[n>=0?`+`:``,n,` linee`]})]}),(0,k.jsx)(`div`,{className:Q.diffContent,children:(0,k.jsx)(uE,{before:e.before,after:e.after})})]},t)})]}),t!==`projects`&&(0,k.jsxs)(`div`,{className:`${Q.chatPanel} ${ft?Q.chatPanelCollapsed:``}`,children:[(0,k.jsxs)(`button`,{className:Q.chatCollapseBtn,onClick:()=>pt(e=>!e),children:[(0,k.jsx)(`span`,{children:ft?`▲`:`▼`}),(0,k.jsx)(`span`,{children:ft?`Show Chat`:`Hide Chat`}),Le.length>0&&(0,k.jsxs)(`span`,{style:{opacity:.5},children:[`(`,Le.length,`)`]})]}),(0,k.jsxs)(`div`,{className:Q.chatMessages,ref:z,children:[Le.length===0&&U&&(0,k.jsxs)(`div`,{className:Q.chatWelcome,children:[`🤖 `,e(`webcraft.doctrine.title`),` — `,(0,k.jsx)(`button`,{className:Q.doctrineOpenBtn,onClick:()=>ue(!0),children:`📖 Open Guide`})]}),Le.map((e,t)=>(0,k.jsxs)(`div`,{className:e.role===`user`?Q.chatUser:e.role===`system`?Q.chatSystem:Q.chatAgent,children:[e.role===`user`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatUserBubble,children:e.text}),e.attachments&&e.attachments.length>0&&(0,k.jsx)(`div`,{className:Q.chatAttachPreviews,children:e.attachments.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.chatAttachBadge,children:[`📎 `,e.name]},t))})]}),e.role===`system`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatSystemBubble,children:e.text}),e.syntaxErrors?.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.chatSyntaxErr,children:[`✕ `,e.file,`: `,e.error]},t))]}),e.role===`agent`&&(()=>{let t=e.text.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/?>/g,``).trim(),n=(e.tools||[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)),r=(e.tools||[]).filter(e=>e.result?.includes(`not_found`)||e.result?.includes(`error`)||e.result===`blocked_use_edit`),a=t.match(/^(.{10,120}?)[.\n]/),o=a?a[1]+`.`:t.slice(0,120),s=t.length>130;return(0,k.jsxs)(`div`,{className:Q.chatAgentCard,children:[n.map((e,t)=>(0,k.jsxs)(`div`,{style:{margin:`6px 0`,borderRadius:8,overflow:`hidden`,border:`1px solid rgba(255,255,255,0.08)`},children:[(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`6px 10px`,background:`rgba(99,102,241,0.1)`,fontSize:11},children:[(0,k.jsxs)(`span`,{style:{fontWeight:600,color:`#818cf8`,cursor:`pointer`},onClick:()=>{let t=g.findIndex(t=>t.name===e.path);t>=0&&(b(t),i(`files`))},children:[`✏ `,e.path]}),(0,k.jsx)(`span`,{style:{color:`#4ade80`,fontSize:10,fontWeight:600},children:e.result===`ok_fuzzy`?`applied (fuzzy)`:e.result===`ok_repaired`?`applied (repaired)`:`✓ applied`})]}),e.oldSnippet||e.newSnippet?(0,k.jsx)(uE,{before:e.oldSnippet||``,after:e.newSnippet||``,contextLines:3}):(0,k.jsx)(`div`,{style:{padding:`6px 10px`,fontSize:11,color:`#4ade80`,background:`rgba(74,222,128,0.05)`},children:`File modified successfully`})]},t)),r.length>0&&(0,k.jsx)(`div`,{style:{margin:`6px 0`,padding:`6px 10px`,background:`rgba(248,113,113,0.08)`,borderRadius:6,fontSize:11,color:`#f87171`},children:r.map((e,t)=>(0,k.jsxs)(`div`,{children:[`❌ `,e.op,` `,e.path,`: `,typeof e.result==`string`?e.result.slice(0,100):``]},t))}),t&&(s?(0,k.jsxs)(`details`,{style:{margin:`6px 0`,fontSize:11},children:[(0,k.jsx)(`summary`,{style:{cursor:`pointer`,color:`var(--dim)`,padding:`4px 0`,userSelect:`none`},children:o.slice(0,100)}),(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8,marginTop:4},dangerouslySetInnerHTML:{__html:$T(t)}})]}):(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8},dangerouslySetInnerHTML:{__html:$T(t)}}))]})})()]},t)),Be&&(()=>{let e=Le[Le.length-1]?.tools??[],t=e[e.length-1],n=t?t.op===`read`?`Reading ${t.path}`:t.op===`edit`?`Editing ${t.path}`:t.op===`search`?`Searching...`:t.op===`lint`?`Linting ${t.path}`:t.op===`check`?`Checking ${t.path}`:t.op===`run`?`Running command...`:t.op===`sandbox`?`Starting sandbox...`:t.op:`Thinking...`;return(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`8px 12px`,fontSize:12,color:`#818cf8`},children:[(0,k.jsx)(`span`,{className:Q.chatAgentRobotAnim,style:{fontSize:14},children:`⟳`}),(0,k.jsx)(`span`,{style:{fontWeight:500},children:n})]})})()]}),He.length>0&&(0,k.jsx)(`div`,{className:Q.attachPreviews,children:He.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.attachBadge,children:[`📎 `,e.name,(0,k.jsx)(`button`,{className:Q.removeAttachBtn,onClick:()=>Ue(e=>e.filter((e,n)=>n!==t)),children:`×`})]},t))}),U?(0,k.jsxs)(`div`,{className:Q.projActiveRow,children:[`📄 `,(0,k.jsx)(`strong`,{className:Q.projActiveName,children:c}),` — scrivi per modificare o migliorare il progetto`]}):(0,k.jsxs)(`div`,{className:Q.projNameRow,children:[(0,k.jsx)(`span`,{className:Q.projNameLabel,children:`Nome progetto:`}),(0,k.jsx)(`input`,{className:Q.projNameInput,value:c,onChange:e=>l(e.target.value),placeholder:`MioProgetto`})]}),(0,k.jsxs)(`div`,{className:Q.chatInputRow,children:[(0,k.jsxs)(`label`,{className:Q.attachLabel,title:`Allega immagine o PDF`,children:[`📎`,(0,k.jsx)(`input`,{ref:Dt,type:`file`,multiple:!0,accept:`image/*,.pdf`,style:{display:`none`},onChange:e=>rn(e.target.files)})]}),(0,k.jsx)(`textarea`,{className:Q.chatTextarea,value:ze,onChange:e=>L(e.target.value),placeholder:U?`Parla con il tuo agente: chiedi correzioni, migliorie, nuove funzionalità...`:`Descrivi il progetto da creare, poi premi Genera...`,disabled:on,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),It())},rows:4}),(0,k.jsxs)(`div`,{className:Q.chatSendCol,children:[(0,k.jsx)(`button`,{className:Q.chatSendBtn,onClick:()=>It(),disabled:on,children:we?`⏳`:U?`▶`:`▶ Genera`}),on&&!Ee&&(0,k.jsx)(`button`,{className:Q.chatStopBtn,onClick:zt,children:`⏹ Stop`})]})]})]}),le&&(0,k.jsx)(`div`,{className:Q.modalOverlay,onClick:()=>ue(!1),children:(0,k.jsxs)(`div`,{className:Q.modal,onClick:e=>e.stopPropagation(),style:{width:720,maxHeight:`90vh`},children:[(0,k.jsxs)(`div`,{className:Q.modalHeader,children:[(0,k.jsxs)(`span`,{className:Q.modalTitle,children:[`📖 `,e(`webcraft.doctrine.title`)]}),(0,k.jsx)(`span`,{className:Q.doctrineSubtitle,children:e(`webcraft.doctrine.subtitle`)}),(0,k.jsx)(`button`,{className:Q.modalClose,onClick:()=>ue(!1),children:`✕`})]}),(0,k.jsx)(`div`,{className:Q.modalBody,style:{gap:0},children:[`phase1`,`phase2`,`phase3`,`phase4`,`phase5`,`tools`,`golden`].map(t=>(0,k.jsxs)(`div`,{className:Q.doctrineSection,children:[(0,k.jsx)(`div`,{className:Q.doctrineSectionTitle,children:e(`webcraft.doctrine.${t}.title`)}),(0,k.jsx)(`div`,{className:Q.doctrineSectionBody,children:e(`webcraft.doctrine.${t}.desc`).split(`
861
+ `).map((e,t)=>(0,k.jsx)(`p`,{className:e.startsWith(`•`)||e.startsWith(`1.`)||e.startsWith(`2.`)||e.startsWith(`3.`)||e.startsWith(`4.`)||e.startsWith(`5.`)||e.startsWith(`6.`)?Q.doctrineBullet:``,children:e},t))})]},t))}),(0,k.jsx)(`div`,{className:Q.modalFooter,children:(0,k.jsx)(`button`,{className:Q.modalSaveBtn,onClick:()=>ue(!1),style:{padding:`10px 28px`,fontSize:14},children:e(`webcraft.doctrine.close`)})})]})}),Xe&&(0,k.jsx)(dE,{modal:Xe,skills:Ke,projectName:c,onClose:()=>Ze(null),onSave:(e,t,n)=>Zt(Xe,e,t,n)}),a&&t===`new`&&(0,k.jsx)(XT,{tabs:ZT,active:o,onChange:s,className:Q.mobileTabBar,buttonClassName:Q.mobileTabBtn,activeClassName:Q.mobileTabBtnActive})]})}function sE(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===r&&e.every((e,n)=>e===t[n]))return e.map((e,t)=>({type:`same`,text:e,oldLine:t+1,newLine:t+1}));if(n+r>8e3)return cE(e,t);let i=n+r,a=2*i+1,o=new Int32Array(a).fill(-1),s=i;o[s+1]=0;let c=[];outer:for(let l=0;l<=i;l++){let i=new Int32Array(a);i.set(o),c.push(i);for(let i=-l;i<=l;i+=2){let a;a=i===-l||i!==l&&o[s+i-1]<o[s+i+1]?o[s+i+1]:o[s+i-1]+1;let c=a-i;for(;a<n&&c<r&&e[a]===t[c];)a++,c++;if(o[s+i]=a,a>=n&&c>=r)break outer}}let l=[],u=n,d=r;for(let n=c.length-1;n>0;n--){let r=c[n-1],i=u-d,a;a=i===-n||i!==n&&r[s+i-1]<r[s+i+1]?i+1:i-1;let o=r[s+a],f=o-a;for(;u>o&&d>f;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});u>o?(u--,l.push({type:`rem`,text:e[u],oldLine:u+1})):d>f&&(d--,l.push({type:`add`,text:t[d],newLine:d+1}))}for(;u>0&&d>0;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});return l.reverse(),l}function cE(e,t){let n=[],r=0,i=0;for(;(r<e.length||i<t.length)&&(r>=e.length?(n.push({type:`add`,text:t[i],newLine:i+1}),i++):i>=t.length?(n.push({type:`rem`,text:e[r],oldLine:r+1}),r++):e[r]===t[i]?(n.push({type:`same`,text:e[r],oldLine:r+1,newLine:i+1}),r++,i++):(n.push({type:`rem`,text:e[r],oldLine:r+1}),n.push({type:`add`,text:t[i],newLine:i+1}),r++,i++),!(n.length>4e3)););return n}function lE(e,t){let n=(e||``).split(/(\s+)/),r=(t||``).split(/(\s+)/),i=n.length,a=r.length;if(i+a>400)return{old:(0,k.jsx)(k.Fragment,{children:e}),new:(0,k.jsx)(k.Fragment,{children:t})};let o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=1;e<=i;e++)for(let t=1;t<=a;t++)o[e][t]=n[e-1]===r[t-1]?o[e-1][t-1]+1:Math.max(o[e-1][t],o[e][t-1]);let s=[],c=[],l=i,u=a,d=[],f=[];for(;l>0||u>0;)l>0&&u>0&&n[l-1]===r[u-1]?(d.push({text:n[l-1],changed:!1}),f.push({text:r[u-1],changed:!1}),l--,u--):u>0&&(l===0||o[l][u-1]>=o[l-1][u])?(f.push({text:r[u-1],changed:!0}),u--):(d.push({text:n[l-1],changed:!0}),l--);return d.reverse().forEach(e=>s.push(e)),f.reverse().forEach(e=>c.push(e)),{old:(0,k.jsx)(k.Fragment,{children:s.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(248,113,113,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))}),new:(0,k.jsx)(k.Fragment,{children:c.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(74,222,128,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))})}}function uE({before:e,after:t,contextLines:n=3}){let r=sE((e||``).split(`
862
862
  `),(t||``).split(`
863
863
  `)),i=new Set;r.forEach((e,t)=>{e.type!==`same`&&i.add(t)});let a=new Set;if(i.forEach(e=>{for(let t=Math.max(0,e-n);t<=Math.min(r.length-1,e+n);t++)a.add(t)}),i.size===0)for(let e=0;e<Math.min(5,r.length);e++)a.add(e);let o=new Map;for(let e=0;e<r.length-1;e++)r[e].type===`rem`&&r[e+1].type===`add`&&o.set(e,lE(r[e].text,r[e+1].text));let s=[],c=-1;for(let e=0;e<r.length;e++){if(!a.has(e))continue;if(c>=0&&e-c>1){let t=e-c-1;s.push((0,k.jsxs)(`div`,{style:{padding:`2px 8px`,background:`rgba(99,102,241,0.08)`,color:`#6366f1`,fontSize:9,textAlign:`center`,borderTop:`1px solid rgba(99,102,241,0.15)`,borderBottom:`1px solid rgba(99,102,241,0.15)`,userSelect:`none`},children:[`@@ `,t,` righe nascoste @@`]},`fold-${e}`))}c=e;let t=r[e],n=t.type===`add`?`rgba(74,222,128,0.08)`:t.type===`rem`?`rgba(248,113,113,0.08)`:`transparent`,i=t.type===`add`?`3px solid #4ade80`:t.type===`rem`?`3px solid #f87171`:`3px solid transparent`,l=t.type===`add`?`#4ade80`:t.type===`rem`?`#f87171`:`var(--dim)`,u=t.type===`add`?`+`:t.type===`rem`?`-`:` `,d=t.text,f=o.get(e);f&&t.type===`rem`&&(d=f.old);let p=o.get(e-1);p&&t.type===`add`&&(d=p.new),s.push((0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`stretch`,background:n,borderLeft:i,fontFamily:`var(--mono)`,fontSize:11,lineHeight:`18px`},children:[(0,k.jsx)(`span`,{style:{width:36,textAlign:`right`,padding:`0 4px`,color:`rgba(255,255,255,0.2)`,fontSize:10,flexShrink:0,userSelect:`none`},children:t.oldLine??``}),(0,k.jsx)(`span`,{style:{width:36,textAlign:`right`,padding:`0 4px`,color:`rgba(255,255,255,0.2)`,fontSize:10,flexShrink:0,userSelect:`none`},children:t.newLine??``}),(0,k.jsx)(`span`,{style:{width:14,textAlign:`center`,color:l,fontWeight:700,flexShrink:0,userSelect:`none`},children:u}),(0,k.jsx)(`span`,{style:{flex:1,padding:`0 4px`,color:l,whiteSpace:`pre-wrap`,wordBreak:`break-all`},children:d})]},e))}return(0,k.jsx)(`div`,{style:{overflow:`auto`,maxHeight:400},children:s})}function dE({modal:e,skills:t,projectName:n,onClose:r,onSave:i}){let[a,o]=(0,_.useState)(e.name),[s,c]=(0,_.useState)(e.content),[l,u]=(0,_.useState)(e.type),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),h=l===`skill`?6e3:4e3,g=s.length>h;async function v(){if(!d.trim())return;m(!0);let e={skill:`Sei un esperto di sviluppo web fullstack. Genera un file Markdown "skill" per il WebCraft Agent. Deve contenere istruzioni, pattern di codice, best practice e snippet pronti all uso come contesto persistente. Scrivi SOLO il contenuto Markdown, niente altro.`,memory:`Sei un assistente tecnico. Genera un file Markdown "memory" per il WebCraft Agent. Deve riassumere decisioni architetturali, preferenze dello sviluppatore e contesto generale del progetto. Scrivi SOLO il Markdown.`,provider:`Sei un esperto di prompt engineering. Genera un file Markdown con istruzioni specifiche per calibrare il comportamento del modello AI. Scrivi SOLO il Markdown.`},t=await E(`/api/studio/webcraft`,{system:e[l]??e.skill,user:`Progetto: ${n}\n\n${d}`,max_tokens:2048});t?.text&&(c(t.text),a||o(l===`memory`?`memory.md`:l===`provider`?`liara.md`:d.toLowerCase().replace(/[^a-z0-9]+/g,`-`).slice(0,30)+`.md`)),m(!1)}function y(){if(!a.trim()){alert(`Inserisci un nome per il file.`);return}let n=a.endsWith(`.md`)?a:a+`.md`;if((l===`memory`||l===`provider`)&&e.mode===`new`&&t.findIndex(e=>e.type===l)>=0){alert(`Esiste già un file di tipo "${l}". Modificalo direttamente.`);return}i(n,s,l)}return(0,k.jsx)(`div`,{className:Q.modalOverlay,onClick:e=>{e.target===e.currentTarget&&r()},children:(0,k.jsxs)(`div`,{className:Q.modal,children:[(0,k.jsxs)(`div`,{className:Q.modalHeader,children:[(0,k.jsxs)(`span`,{className:Q.modalTitle,children:[aE(l),` `,e.mode===`new`?`Nuovo file di contesto`:`Modifica ${e.name}`]}),(0,k.jsx)(`button`,{className:Q.modalClose,onClick:r,children:`×`})]}),(0,k.jsx)(`div`,{className:Q.modalBody,children:e.mode===`view`?(0,k.jsx)(`pre`,{className:Q.logView,children:s}):(0,k.jsxs)(k.Fragment,{children:[e.mode===`new`&&(0,k.jsxs)(`div`,{className:Q.modalRow,children:[(0,k.jsxs)(`div`,{className:Q.modalField,children:[(0,k.jsx)(`div`,{className:Q.modalLabel,children:`TIPO`}),(0,k.jsx)(`select`,{value:l,onChange:e=>{let t=e.target.value;u(t),t===`memory`?o(`memory.md`):t===`provider`&&o(`liara.md`)},className:Q.modalSelect,children:[`skill`,`memory`,`provider`].map(e=>{let n=(e===`memory`||e===`provider`)&&t.some(t=>t.type===e);return(0,k.jsxs)(`option`,{value:e,disabled:n,children:[e,n?` (esiste già)`:``]},e)})})]}),(0,k.jsxs)(`div`,{className:Q.modalField,style:{flex:2},children:[(0,k.jsx)(`div`,{className:Q.modalLabel,children:`NOME FILE`}),(0,k.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:l===`memory`?`memory.md`:l===`provider`?`liara.md`:`nome-skill.md`,className:Q.modalInput})]})]}),(0,k.jsxs)(`div`,{className:Q.modalHint,children:[`💡 `,l===`skill`?`Istruzioni tecniche, snippet, pattern di codice specifici. Max ~6000 caratteri.`:l===`memory`?`Note persistenti sul progetto: decisioni architetturali, preferenze. Solo UN file. Max ~4000 caratteri.`:`Istruzioni specifiche per il modello AI (tono, formato, vincoli). Solo UN file. Max ~4000 caratteri.`]}),(0,k.jsxs)(`div`,{className:Q.modalAiBox,children:[(0,k.jsx)(`div`,{className:Q.modalLabel,children:`🤖 GENERA CON AI`}),(0,k.jsxs)(`div`,{className:Q.modalAiRow,children:[(0,k.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),rows:2,placeholder:`Descrivi cosa deve contenere questo file...`,className:Q.modalAiDesc}),(0,k.jsx)(`button`,{onClick:v,disabled:p,className:Q.modalAiBtn,children:p?`⏳ ...`:`▶ Genera`})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`div`,{className:Q.modalLabelRow,children:[(0,k.jsx)(`span`,{children:`CONTENUTO (markdown)`}),(0,k.jsxs)(`span`,{style:{color:g?`#e05050`:`var(--dim)`},children:[s.length,` car.`,g?` ⚠ Troppo lungo`:``]})]}),(0,k.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:14,placeholder:`# Titolo
864
864
  Scrivi le istruzioni in Markdown...`,className:Q.modalContentArea,style:{borderColor:g?`#e05050`:`var(--border2)`}})]})]})}),(0,k.jsxs)(`div`,{className:Q.modalFooter,children:[(0,k.jsx)(`button`,{onClick:r,className:Q.modalCancelBtn,children:`Annulla`}),e.mode!==`view`&&(0,k.jsx)(`button`,{onClick:y,className:Q.modalSaveBtn,children:`✓ Salva`})]})]})})}var fE={root:`_root_x9yvu_1`,loading:`_loading_x9yvu_7`,empty:`_empty_x9yvu_18`,emptyIcon:`_emptyIcon_x9yvu_29`,emptyTitle:`_emptyTitle_x9yvu_30`,emptySub:`_emptySub_x9yvu_31`,generateBtn:`_generateBtn_x9yvu_33`,summary:`_summary_x9yvu_46`,sectionTitle:`_sectionTitle_x9yvu_57`,alertTitle:`_alertTitle_x9yvu_68`,actionCard:`_actionCard_x9yvu_70`,actionTime:`_actionTime_x9yvu_81`,actionText:`_actionText_x9yvu_89`,schedCard:`_schedCard_x9yvu_95`,schedTime:`_schedTime_x9yvu_106`,schedTitle:`_schedTitle_x9yvu_114`,alertCard:`_alertCard_x9yvu_119`,alertSev:`_alertSev_x9yvu_129`,alertAction:`_alertAction_x9yvu_135`,insight:`_insight_x9yvu_141`,regenRow:`_regenRow_x9yvu_148`,regenBtn:`_regenBtn_x9yvu_153`};function pE(){let e=j(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),l=()=>{i(!0),c(!1),T(`/api/plan`).then(e=>{e?.plan?(n(e.plan),c(!1)):(n(null),c(!0)),i(!1)}).catch(()=>{i(!1),c(!0)})},u=async()=>{o(!0),i(!0),n(null);try{await E(`/api/plan/refresh`,{}),l()}catch{i(!1)}finally{o(!1)}};if((0,_.useEffect)(()=>{l()},[]),r)return(0,k.jsxs)(`div`,{className:fE.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),(0,k.jsx)(`div`,{children:a?`Generating plan with 5 agents...`:`Loading plan...`})]});if(s||!t)return(0,k.jsxs)(`div`,{className:fE.empty,children:[(0,k.jsx)(`div`,{className:fE.emptyIcon,children:`🗓️`}),(0,k.jsxs)(`div`,{className:fE.emptyTitle,children:[e(`plan.noplan`),` generated yet`]}),(0,k.jsx)(`div`,{className:fE.emptySub,children:`Generate a daily plan using your calendar, tasks, and emails.`}),(0,k.jsx)(`button`,{className:fE.generateBtn,onClick:u,children:e(`plan.generate`)})]});let d=e=>typeof e==`string`?e:e.description??e.message??e.action_required??`Alert`,f=e=>typeof e==`object`&&e.severity?` [${e.severity.toUpperCase()}]`:``,p=e=>typeof e==`object`&&e.action_required&&e.action_required!==d(e)?e.action_required:``,m=e=>typeof e==`string`?e:e.message??e.insight??``;return(0,k.jsxs)(`div`,{className:fE.root,children:[t.executive_summary&&(0,k.jsx)(`div`,{className:fE.summary,children:t.executive_summary}),t.priority_actions&&t.priority_actions.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:fE.sectionTitle,children:`Priority Actions`}),t.priority_actions.map((e,t)=>(0,k.jsxs)(`div`,{className:fE.actionCard,children:[e.time&&(0,k.jsx)(`span`,{className:fE.actionTime,children:e.time}),(0,k.jsx)(`span`,{className:fE.actionText,children:e.action})]},t))]}),t.schedule&&t.schedule.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:fE.sectionTitle,children:`Schedule`}),t.schedule.map((e,t)=>(0,k.jsxs)(`div`,{className:fE.schedCard,children:[(0,k.jsxs)(`span`,{className:fE.schedTime,children:[e.time_start,`–`,e.time_end]}),(0,k.jsx)(`span`,{className:fE.schedTitle,children:e.title})]},t))]}),t.security_alerts&&t.security_alerts.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`${fE.sectionTitle} ${fE.alertTitle}`,children:`Security Alerts`}),t.security_alerts.map((e,t)=>(0,k.jsxs)(`div`,{className:fE.alertCard,children:[(0,k.jsxs)(`span`,{className:fE.alertSev,children:[`!`,f(e)]}),(0,k.jsx)(`span`,{children:d(e)}),p(e)&&(0,k.jsxs)(`div`,{className:fE.alertAction,children:[`Action: `,p(e)]})]},t))]}),t.insights&&t.insights.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:fE.sectionTitle,children:`Insights`}),t.insights.map((e,t)=>(0,k.jsxs)(`div`,{className:fE.insight,children:[`→ `,m(e)]},t))]}),(0,k.jsx)(`div`,{className:fE.regenRow,children:(0,k.jsx)(`button`,{className:fE.regenBtn,onClick:u,disabled:a,children:a?`Regenerating…`:`↺ Regenerate`})})]})}function mE(e){return e===`folder`?`📁`:e===`image`?`🖼`:e===`pdf`?`📕`:e===`video`?`🎬`:e===`audio`?`🎵`:e===`sheet`?`📊`:e===`slides`?`📽`:`📄`}function hE(){let e=j(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),l=(e=``)=>{i(!0),T(e?`/api/onedrive?q=${encodeURIComponent(e)}`:`/api/onedrive`).then(e=>{n(e??{files:[]}),i(!1)}).catch(()=>{o(`Could not load OneDrive. Run nha microsoft auth in the terminal to connect.`),i(!1)})};if((0,_.useEffect)(()=>{l()},[]),a)return(0,k.jsx)(`div`,{className:G.error,children:a});let u=t?.files??[],d=t?.quota;return(0,k.jsxs)(`div`,{className:G.root,children:[d&&(0,k.jsxs)(`div`,{className:G.quotaBar,children:[(0,k.jsxs)(`div`,{className:G.quotaText,children:[(0,k.jsxs)(`span`,{className:G.quotaUsed,children:[d.usage,` of `,d.limit,` used`]}),(0,k.jsxs)(`span`,{className:G.quotaPct,children:[d.percentUsed,`%`]})]}),(0,k.jsx)(`div`,{className:G.quotaTrack,children:(0,k.jsx)(`div`,{className:G.quotaFill,style:{width:`${Math.min(d.percentUsed,100)}%`,background:d.percentUsed>90?`var(--red)`:d.percentUsed>70?`var(--amber)`:`var(--cyan)`}})})]}),(0,k.jsxs)(`div`,{className:G.searchRow,children:[(0,k.jsx)(`input`,{className:G.searchInput,value:s,onChange:e=>c(e.target.value),placeholder:`Search OneDrive files…`,onKeyDown:e=>e.key===`Enter`&&l(s)}),(0,k.jsx)(`button`,{className:G.searchBtn,onClick:()=>l(s),children:`Search`})]}),r&&(0,k.jsxs)(`div`,{className:G.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}),!r&&u.length===0&&(0,k.jsx)(`div`,{className:G.empty,children:e(`drive.noFiles`)}),(0,k.jsx)(`div`,{className:G.fileList,children:u.map(e=>(0,k.jsxs)(`div`,{className:G.fileRow,children:[(0,k.jsx)(`span`,{className:G.fileIcon,children:mE(e.type)}),(0,k.jsxs)(`div`,{className:G.fileInfo,children:[(0,k.jsx)(`div`,{className:G.fileName,children:e.name}),(0,k.jsxs)(`div`,{className:G.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``]})]}),(0,k.jsx)(`div`,{className:G.fileBtns,children:e.webViewLink&&(0,k.jsx)(`a`,{className:G.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,children:`Open`})})]},e.id))})]})}var gE={root:`_root_1vbmp_1`,loading:`_loading_1vbmp_2`,error:`_error_1vbmp_3`,empty:`_empty_1vbmp_4`,addRow:`_addRow_1vbmp_6`,addInput:`_addInput_1vbmp_7`,addBtn:`_addBtn_1vbmp_8`,list:`_list_1vbmp_10`,taskRow:`_taskRow_1vbmp_11`,checkBtn:`_checkBtn_1vbmp_12`,taskInfo:`_taskInfo_1vbmp_14`,taskTitle:`_taskTitle_1vbmp_15`,taskDue:`_taskDue_1vbmp_16`,taskImp:`_taskImp_1vbmp_17`};function _E(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),l=()=>{T(`/api/mstodo`).then(e=>{n(e?.tasks??[]),i(!1)}).catch(()=>{o(`Microsoft To Do requires Microsoft authentication. Run nha microsoft auth in the terminal.`),i(!1)})};(0,_.useEffect)(()=>{l()},[]);let u=()=>{let e=s.trim();e&&(c(``),E(`/api/mstodo`,{title:e}).then(e=>{e?.task&&l()}))},d=(e,t)=>{E(`/api/mstodo/${e}/complete`,{listId:t}).then(()=>l())};return r?(0,k.jsxs)(`div`,{className:gE.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:gE.error,children:a}):(0,k.jsxs)(`div`,{className:gE.root,children:[(0,k.jsxs)(`div`,{className:gE.addRow,children:[(0,k.jsx)(`input`,{className:gE.addInput,value:s,onChange:e=>c(e.target.value),placeholder:`Add a new task…`,onKeyDown:e=>e.key===`Enter`&&u()}),(0,k.jsx)(`button`,{className:gE.addBtn,onClick:u,children:`+ Add`})]}),t.length===0&&(0,k.jsx)(`div`,{className:gE.empty,children:`No active tasks`}),(0,k.jsx)(`div`,{className:gE.list,children:t.map(e=>{let t=e.importance===`high`?`var(--red)`:e.importance===`low`?`var(--dim)`:`var(--amber)`;return(0,k.jsxs)(`div`,{className:gE.taskRow,children:[(0,k.jsx)(`button`,{className:gE.checkBtn,onClick:()=>d(e.id,e.listId)}),(0,k.jsxs)(`div`,{className:gE.taskInfo,children:[(0,k.jsx)(`div`,{className:gE.taskTitle,children:e.title}),e.dueDate&&(0,k.jsxs)(`div`,{className:gE.taskDue,children:[`Due: `,e.dueDate.split(`T`)[0]]})]}),e.importance&&(0,k.jsx)(`span`,{className:gE.taskImp,style:{color:t},children:e.importance})]},e.id)})})]})}var vE={root:`_root_1ag4s_1`,header:`_header_1ag4s_3`,title:`_title_1ag4s_4`,subtitle:`_subtitle_1ag4s_5`,controls:`_controls_1ag4s_7`,monitorRow:`_monitorRow_1ag4s_8`,label:`_label_1ag4s_9`,monitorBtn:`_monitorBtn_1ag4s_10`,monitorActive:`_monitorActive_1ag4s_11`,captureBtn:`_captureBtn_1ag4s_12`,analyzeSection:`_analyzeSection_1ag4s_15`,sectionTitle:`_sectionTitle_1ag4s_16`,presets:`_presets_1ag4s_17`,preset:`_preset_1ag4s_17`,presetActive:`_presetActive_1ag4s_20`,questionRow:`_questionRow_1ag4s_21`,questionInput:`_questionInput_1ag4s_22`,analyzeBtn:`_analyzeBtn_1ag4s_23`,error:`_error_1ag4s_26`,screenshotContainer:`_screenshotContainer_1ag4s_28`,screenshot:`_screenshot_1ag4s_28`,screenshotMeta:`_screenshotMeta_1ag4s_30`,analysis:`_analysis_1ag4s_32`,analysisTitle:`_analysisTitle_1ag4s_33`,analysisText:`_analysisText_1ag4s_34`,continueInChat:`_continueInChat_1ag4s_35`,history:`_history_1ag4s_37`,historyGrid:`_historyGrid_1ag4s_38`,historyItem:`_historyItem_1ag4s_39`,historyThumb:`_historyThumb_1ag4s_40`,historyMeta:`_historyMeta_1ag4s_41`,historyTs:`_historyTs_1ag4s_42`,historyQ:`_historyQ_1ag4s_43`,historyA:`_historyA_1ag4s_44`},yE=[`Describe exactly what you see on the screen`,`Identify any errors, warnings, or issues visible`,`What application is open and what is the user doing?`,`Summarize the content visible on screen and suggest next actions`,`Read and extract all visible text from the screen`,`Analyze the code visible on screen and identify bugs or improvements`,`What financial data or charts are visible? Summarize key numbers`,`Is there anything sensitive or that should be kept private?`];function bE(){let e=j(),t=ne(e=>e.setView),n=ne(e=>e.apiBase),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(1),[p,m]=(0,_.useState)([]),h=async()=>{i(!0),c(null);try{let e=await E(`/api/screen/capture`,{monitor:d});c(e),(e?.base64||e?.file)&&m(t=>[{ts:new Date().toLocaleTimeString(),question:`Screenshot`,analysis:``,src:e.base64?`data:image/${e.format??`jpeg`};base64,${e.base64}`:`${n}/api/screenshots/${e.file}`},...t.slice(0,9)])}catch(e){c({error:e.message})}i(!1)},g=async()=>{if(l.trim()){o(!0);try{let e=await E(`/api/screen/analyze`,{question:l.trim(),monitor:d});if(c(e),e?.analysis){let t=e.base64?`data:image/${e.format??`jpeg`};base64,${e.base64}`:e.file?`${n}/api/screenshots/${e.file}`:``;m(n=>[{ts:new Date().toLocaleTimeString(),question:l.trim(),analysis:e.analysis??``,src:t},...n.slice(0,9)])}}catch(e){c({error:e.message})}o(!1)}},v=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},y=s?.base64?`data:image/${s.format??`jpeg`};base64,${s.base64}`:s?.file?`${n}/api/screenshots/${s.file}`:null;return(0,k.jsxs)(`div`,{className:vE.root,children:[(0,k.jsx)(`div`,{className:vE.header,children:(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:vE.title,children:`🖥️ Screen Capture`}),(0,k.jsxs)(`div`,{className:vE.subtitle,children:[e(`screen.capture`),` and analyze your desktop screen with AI vision`]})]})}),(0,k.jsxs)(`div`,{className:vE.controls,children:[(0,k.jsxs)(`div`,{className:vE.monitorRow,children:[(0,k.jsx)(`label`,{className:vE.label,children:`Monitor`}),[1,2,3].map(e=>(0,k.jsxs)(`button`,{className:`${vE.monitorBtn} ${d===e?vE.monitorActive:``}`,onClick:()=>f(e),children:[`Monitor `,e]},e))]}),(0,k.jsx)(`button`,{className:vE.captureBtn,onClick:h,disabled:r||a,children:r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`spinner`}),` Capturing…`]}):`📷 Capture Screen`})]}),(0,k.jsxs)(`div`,{className:vE.analyzeSection,children:[(0,k.jsx)(`div`,{className:vE.sectionTitle,children:`Capture + Analyze`}),(0,k.jsx)(`div`,{className:vE.presets,children:yE.map(e=>(0,k.jsxs)(`button`,{className:`${vE.preset} ${l===e?vE.presetActive:``}`,onClick:()=>u(e),children:[e.slice(0,50),e.length>50?`…`:``]},e))}),(0,k.jsxs)(`div`,{className:vE.questionRow,children:[(0,k.jsx)(`input`,{className:vE.questionInput,value:l,onChange:e=>u(e.target.value),placeholder:`Ask something about your screen…`,onKeyDown:e=>e.key===`Enter`&&g()}),(0,k.jsx)(`button`,{className:vE.analyzeBtn,onClick:g,disabled:!l.trim()||r||a,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`spinner`}),` Analyzing…`]}):`🔍 Analyze`})]})]}),s?.error&&(0,k.jsx)(`div`,{className:vE.error,children:s.error}),y&&(0,k.jsxs)(`div`,{className:vE.screenshotContainer,children:[(0,k.jsx)(`img`,{src:y,className:vE.screenshot,alt:`Screen capture`}),s?.width&&s?.height&&(0,k.jsxs)(`div`,{className:vE.screenshotMeta,children:[s.width,` × `,s.height,`px`]})]}),s?.analysis&&(0,k.jsxs)(`div`,{className:vE.analysis,children:[(0,k.jsx)(`div`,{className:vE.analysisTitle,children:`AI Analysis`}),(0,k.jsx)(`div`,{className:vE.analysisText,children:s.analysis}),(0,k.jsx)(`button`,{className:vE.continueInChat,onClick:()=>v(`I captured my screen. Here's what the AI saw:\n\n${s.analysis}\n\nCan you help me with this?`),children:`Continue in Chat →`})]}),p.length>0&&(0,k.jsxs)(`div`,{className:vE.history,children:[(0,k.jsx)(`div`,{className:vE.sectionTitle,children:`Recent Captures`}),(0,k.jsx)(`div`,{className:vE.historyGrid,children:p.map((e,t)=>(0,k.jsxs)(`div`,{className:vE.historyItem,children:[e.src&&(0,k.jsx)(`img`,{src:e.src,className:vE.historyThumb,alt:e.question}),(0,k.jsxs)(`div`,{className:vE.historyMeta,children:[(0,k.jsx)(`div`,{className:vE.historyTs,children:e.ts}),(0,k.jsx)(`div`,{className:vE.historyQ,children:e.question}),e.analysis&&(0,k.jsxs)(`div`,{className:vE.historyA,children:[e.analysis.slice(0,120),`…`]})]})]},t))})]})]})}var xE={root:`_root_v12qq_1`,header:`_header_v12qq_3`,title:`_title_v12qq_4`,subtitle:`_subtitle_v12qq_5`,section:`_section_v12qq_7`,sectionTitle:`_sectionTitle_v12qq_8`,quickBtns:`_quickBtns_v12qq_10`,quickBtn:`_quickBtn_v12qq_10`,searchRow:`_searchRow_v12qq_14`,searchInput:`_searchInput_v12qq_15`,searchBtn:`_searchBtn_v12qq_16`,modeRow:`_modeRow_v12qq_19`,modeBtn:`_modeBtn_v12qq_20`,modeActive:`_modeActive_v12qq_21`,routeInputs:`_routeInputs_v12qq_23`,inputWrapper:`_inputWrapper_v12qq_24`,inputIcon:`_inputIcon_v12qq_25`,routeInput:`_routeInput_v12qq_23`,swapBtn:`_swapBtn_v12qq_27`,dirBtns:`_dirBtns_v12qq_29`,dirBtn:`_dirBtn_v12qq_29`,openMapsBtn:`_openMapsBtn_v12qq_32`,error:`_error_v12qq_34`,resultCard:`_resultCard_v12qq_36`,routeSummary:`_routeSummary_v12qq_37`,routeDistance:`_routeDistance_v12qq_38`,routeDuration:`_routeDuration_v12qq_39`,routeMode:`_routeMode_v12qq_40`,steps:`_steps_v12qq_41`,step:`_step_v12qq_41`,stepNum:`_stepNum_v12qq_43`,stepText:`_stepText_v12qq_44`,mapLink:`_mapLink_v12qq_45`,askChatBtn:`_askChatBtn_v12qq_47`,savedRoute:`_savedRoute_v12qq_49`,savedFrom:`_savedFrom_v12qq_51`,savedArrow:`_savedArrow_v12qq_52`,savedTo:`_savedTo_v12qq_53`,savedTs:`_savedTs_v12qq_54`},SE=[`driving`,`walking`,`bicycling`,`transit`],CE={driving:`🚗`,walking:`🚶`,bicycling:`🚲`,transit:`🚌`},wE=[{label:`🏥 Nearest Hospital`,query:`nearest hospital`},{label:`⛽ Gas Station`,query:`gas station near me`},{label:`🛒 Supermarket`,query:`supermarket near me`},{label:`☕ Coffee Shop`,query:`coffee shop near me`},{label:`🏧 ATM`,query:`ATM near me`},{label:`🍕 Pizza`,query:`pizza restaurant near me`}];function TE(e,t,n){try{let r=JSON.parse(localStorage.getItem(`nha_maps_routes`)??`[]`),i=[{from:e,to:t,label:n,ts:new Date().toISOString()},...r.filter(n=>!(n.from===e&&n.to===t))].slice(0,10);localStorage.setItem(`nha_maps_routes`,JSON.stringify(i))}catch{}}function EE(){try{return JSON.parse(localStorage.getItem(`nha_maps_routes`)??`[]`)}catch{return[]}}function DE(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(`driving`),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(EE),[m,h]=(0,_.useState)(``),g=async()=>{if(!(!n.trim()||!i.trim())){l(!0),d(null);try{let e=await T(`/api/maps/directions?from=${encodeURIComponent(n.trim())}&to=${encodeURIComponent(i.trim())}&mode=${o}`);e&&(d(e),e.error||(TE(n.trim(),i.trim()),p(EE())))}catch{d({url:`https://www.google.com/maps/dir/${encodeURIComponent(n.trim())}/${encodeURIComponent(i.trim())}/?travelmode=${o}`}),TE(n.trim(),i.trim()),p(EE())}l(!1)}},v=e=>{let t=`https://www.google.com/maps/search/${encodeURIComponent(e)}`;window.open(t,`_blank`)},y=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},b=e=>{r(e.from),a(e.to)},x=n.trim()&&i.trim()?`https://www.google.com/maps/dir/${encodeURIComponent(n.trim())}/${encodeURIComponent(i.trim())}/?travelmode=${o}`:null;return(0,k.jsxs)(`div`,{className:xE.root,children:[(0,k.jsx)(`div`,{className:xE.header,children:(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:xE.title,children:`🗺️ Maps & Directions`}),(0,k.jsx)(`div`,{className:xE.subtitle,children:e(`maps.directions`)})]})}),(0,k.jsxs)(`div`,{className:xE.section,children:[(0,k.jsx)(`div`,{className:xE.sectionTitle,children:e(`common.search`)}),(0,k.jsx)(`div`,{className:xE.quickBtns,children:wE.map(e=>(0,k.jsx)(`button`,{className:xE.quickBtn,onClick:()=>v(e.query),children:e.label},e.label))}),(0,k.jsxs)(`div`,{className:xE.searchRow,children:[(0,k.jsx)(`input`,{className:xE.searchInput,value:m,onChange:e=>h(e.target.value),placeholder:`Search for a place, address, or business…`,onKeyDown:e=>e.key===`Enter`&&v(m)}),(0,k.jsx)(`button`,{className:xE.searchBtn,onClick:()=>v(m),disabled:!m.trim(),children:`Search ↗`})]})]}),(0,k.jsxs)(`div`,{className:xE.section,children:[(0,k.jsx)(`div`,{className:xE.sectionTitle,children:`Directions`}),(0,k.jsx)(`div`,{className:xE.modeRow,children:SE.map(e=>(0,k.jsxs)(`button`,{className:`${xE.modeBtn} ${o===e?xE.modeActive:``}`,onClick:()=>s(e),title:e,children:[CE[e],` `,e.charAt(0).toUpperCase()+e.slice(1)]},e))}),(0,k.jsxs)(`div`,{className:xE.routeInputs,children:[(0,k.jsxs)(`div`,{className:xE.inputWrapper,children:[(0,k.jsx)(`span`,{className:xE.inputIcon,children:`A`}),(0,k.jsx)(`input`,{className:xE.routeInput,value:n,onChange:e=>r(e.target.value),placeholder:`From (address, city, or 'my location')`,onKeyDown:e=>e.key===`Enter`&&g()})]}),(0,k.jsx)(`button`,{className:xE.swapBtn,onClick:()=>{r(i),a(n)},title:`Swap`,children:`⇅`}),(0,k.jsxs)(`div`,{className:xE.inputWrapper,children:[(0,k.jsx)(`span`,{className:xE.inputIcon,children:`B`}),(0,k.jsx)(`input`,{className:xE.routeInput,value:i,onChange:e=>a(e.target.value),placeholder:`To (address, city, or landmark)`,onKeyDown:e=>e.key===`Enter`&&g()})]})]}),(0,k.jsxs)(`div`,{className:xE.dirBtns,children:[(0,k.jsx)(`button`,{className:xE.dirBtn,onClick:g,disabled:c||!n.trim()||!i.trim(),children:c?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`spinner`}),` Getting route…`]}):`🗺️ Get Directions`}),x&&(0,k.jsx)(`a`,{className:xE.openMapsBtn,href:x,target:`_blank`,rel:`noreferrer`,children:`Open in Google Maps ↗`})]})]}),u?.error&&(0,k.jsx)(`div`,{className:xE.error,children:u.error}),u&&!u.error&&(0,k.jsxs)(`div`,{className:xE.resultCard,children:[(u.distance||u.duration)&&(0,k.jsxs)(`div`,{className:xE.routeSummary,children:[u.distance&&(0,k.jsxs)(`span`,{className:xE.routeDistance,children:[`📏 `,u.distance]}),u.duration&&(0,k.jsxs)(`span`,{className:xE.routeDuration,children:[`⏱ `,u.duration]}),(0,k.jsxs)(`span`,{className:xE.routeMode,children:[CE[o],` `,o]})]}),u.steps&&u.steps.length>0&&(0,k.jsx)(`div`,{className:xE.steps,children:u.steps.map((e,t)=>(0,k.jsxs)(`div`,{className:xE.step,children:[(0,k.jsx)(`span`,{className:xE.stepNum,children:t+1}),(0,k.jsx)(`span`,{className:xE.stepText,children:e})]},t))}),u.url&&(0,k.jsx)(`a`,{className:xE.mapLink,href:u.url,target:`_blank`,rel:`noreferrer`,children:`View full route on Google Maps ↗`}),(0,k.jsx)(`button`,{className:xE.askChatBtn,onClick:()=>y(`Give me directions from "${n}" to "${i}" by ${o}. Include estimated time, distance, and any traffic alerts or alternative routes.`),children:`Ask AI for detailed route advice →`})]}),f.length>0&&(0,k.jsxs)(`div`,{className:xE.section,children:[(0,k.jsx)(`div`,{className:xE.sectionTitle,children:`Recent Routes`}),f.map((e,t)=>(0,k.jsxs)(`div`,{className:xE.savedRoute,onClick:()=>b(e),children:[(0,k.jsx)(`span`,{className:xE.savedFrom,children:e.from}),(0,k.jsx)(`span`,{className:xE.savedArrow,children:`→`}),(0,k.jsx)(`span`,{className:xE.savedTo,children:e.to}),(0,k.jsx)(`span`,{className:xE.savedTs,children:new Date(e.ts).toLocaleDateString()})]},t))]})]})}var $={root:`_root_esnjz_1`,header:`_header_esnjz_3`,title:`_title_esnjz_4`,subtitle:`_subtitle_esnjz_5`,addBtn:`_addBtn_esnjz_6`,quickAdd:`_quickAdd_esnjz_8`,quickLabel:`_quickLabel_esnjz_9`,quickPresets:`_quickPresets_esnjz_10`,quickPreset:`_quickPreset_esnjz_10`,section:`_section_esnjz_14`,sectionTitle:`_sectionTitle_esnjz_15`,loading:`_loading_esnjz_17`,empty:`_empty_esnjz_18`,card:`_card_esnjz_20`,cardPast:`_cardPast_esnjz_21`,cardLeft:`_cardLeft_esnjz_22`,reminderMsg:`_reminderMsg_esnjz_23`,reminderTime:`_reminderTime_esnjz_24`,timeBadge:`_timeBadge_esnjz_25`,countdown:`_countdown_esnjz_26`,timePast:`_timePast_esnjz_27`,sentBadge:`_sentBadge_esnjz_28`,cancelledBadge:`_cancelledBadge_esnjz_29`,cancelBtn:`_cancelBtn_esnjz_30`,repeatBtn:`_repeatBtn_esnjz_31`,aiButtons:`_aiButtons_esnjz_33`,aiBtn:`_aiBtn_esnjz_34`,overlay:`_overlay_esnjz_38`,modal:`_modal_esnjz_39`,modalTitle:`_modalTitle_esnjz_40`,label:`_label_esnjz_41`,input:`_input_esnjz_42`,msgTemplates:`_msgTemplates_esnjz_44`,msgTemplate:`_msgTemplate_esnjz_44`,msgTemplateActive:`_msgTemplateActive_esnjz_47`,typeTabs:`_typeTabs_esnjz_49`,typeTab:`_typeTab_esnjz_49`,typeTabActive:`_typeTabActive_esnjz_51`,relRow:`_relRow_esnjz_53`,inLabel:`_inLabel_esnjz_54`,relInput:`_relInput_esnjz_55`,relSelect:`_relSelect_esnjz_56`,formErr:`_formErr_esnjz_58`,formOk:`_formOk_esnjz_59`,modalBtns:`_modalBtns_esnjz_60`,cancelModalBtn:`_cancelModalBtn_esnjz_61`,saveBtn:`_saveBtn_esnjz_62`},OE=[{label:`In 5 min`,value:`in 5 minutes`},{label:`In 15 min`,value:`in 15 minutes`},{label:`In 30 min`,value:`in 30 minutes`},{label:`In 1 hour`,value:`in 1 hour`},{label:`In 2 hours`,value:`in 2 hours`},{label:`In 3 hours`,value:`in 3 hours`},{label:`Tomorrow 9am`,value:`tomorrow at 09:00`},{label:`Tomorrow noon`,value:`tomorrow at 12:00`}],kE=[`Take a break and stretch`,`Check emails`,`Join the standup call`,`Review and respond to messages`,`Take your medication`,`Drink water`,`Focus review — what did you accomplish in the last hour?`,`Follow up on pending tasks`,`End of work day — log your achievements`,`Weekly review — prepare for next week`];function AE(e){if(e<1)return`now`;if(e<60)return`in ${e}m`;let t=Math.floor(e/60),n=e%60;return n>0?`in ${t}h ${n}m`:`in ${t}h`}function jE(){let e=j(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)({message:``,atTime:``,atTimeType:`relative`,relValue:`30`,relUnit:`minutes`}),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(!1),g=()=>{a(!0),T(`/api/reminders`).then(e=>{r(e?.reminders??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{g()},[]);let v=async()=>{if(!o.message.trim()){d(`Message is required`);return}let e=``;if(o.atTimeType===`relative`)e=`in ${o.relValue} ${o.relUnit}`;else{if(!o.atTime){d(`Time is required`);return}e=o.atTime}l(!0),d(``);try{await E(`/api/reminders`,{message:o.message.trim(),atTime:e}),p(`Reminder set!`),setTimeout(()=>{p(``),h(!1)},1500),g()}catch(e){d(e.message??`Failed to set reminder`)}l(!1)},y=e=>{confirm(`Cancel this reminder?`)&&E(`/api/reminders/cancel`,{id:e}).then(g)},b=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},x=n.filter(e=>e.status===`pending`),S=n.filter(e=>e.status!==`pending`);return(0,k.jsxs)(`div`,{className:$.root,children:[(0,k.jsxs)(`div`,{className:$.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:$.title,children:`🔔 Reminders`}),(0,k.jsx)(`div`,{className:$.subtitle,children:`Set one-time notifications via the NHA daemon`})]}),(0,k.jsx)(`button`,{className:$.addBtn,onClick:()=>{h(!0),d(``),p(``)},children:`+ New Reminder`})]}),(0,k.jsxs)(`div`,{className:$.quickAdd,children:[(0,k.jsx)(`div`,{className:$.quickLabel,children:`Quick reminder for now:`}),(0,k.jsx)(`div`,{className:$.quickPresets,children:OE.map(e=>(0,k.jsx)(`button`,{className:$.quickPreset,onClick:()=>{s(e=>({...e,atTimeType:`relative`,atTime:``,message:e.message||`Reminder`})),h(!0),d(``),p(``)},children:e.label},e.value))})]}),i&&(0,k.jsxs)(`div`,{className:$.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}),!i&&(0,k.jsxs)(`div`,{className:$.section,children:[(0,k.jsxs)(`div`,{className:$.sectionTitle,children:[`Pending (`,x.length,`)`]}),x.length===0&&(0,k.jsx)(`div`,{className:$.empty,children:`No pending reminders. Set one to get notified.`}),x.map(e=>(0,k.jsxs)(`div`,{className:$.card,children:[(0,k.jsxs)(`div`,{className:$.cardLeft,children:[(0,k.jsx)(`div`,{className:$.reminderMsg,children:e.message}),(0,k.jsxs)(`div`,{className:$.reminderTime,children:[(0,k.jsx)(`span`,{className:$.timeBadge,children:new Date(e.atTime).toLocaleString()}),e.minutesUntil!==void 0&&(0,k.jsx)(`span`,{className:$.countdown,children:AE(e.minutesUntil)})]})]}),(0,k.jsx)(`button`,{className:$.cancelBtn,onClick:()=>y(e.id),children:`Cancel`})]},e.id))]}),S.length>0&&(0,k.jsxs)(`div`,{className:$.section,children:[(0,k.jsxs)(`div`,{className:$.sectionTitle,children:[`Recent (`,S.length,`)`]}),S.slice(0,10).map(e=>(0,k.jsxs)(`div`,{className:`${$.card} ${$.cardPast}`,children:[(0,k.jsxs)(`div`,{className:$.cardLeft,children:[(0,k.jsx)(`div`,{className:$.reminderMsg,children:e.message}),(0,k.jsxs)(`div`,{className:$.reminderTime,children:[(0,k.jsx)(`span`,{className:e.status===`sent`?$.sentBadge:$.cancelledBadge,children:e.status}),(0,k.jsx)(`span`,{className:$.timePast,children:new Date(e.atTime).toLocaleString()})]})]}),(0,k.jsx)(`button`,{className:$.repeatBtn,onClick:()=>{s(t=>({...t,message:e.message,atTimeType:`relative`,relValue:`30`,relUnit:`minutes`})),h(!0)},children:`Repeat`})]},e.id))]}),(0,k.jsxs)(`div`,{className:$.section,children:[(0,k.jsx)(`div`,{className:$.sectionTitle,children:`AI-Powered Reminders`}),(0,k.jsxs)(`div`,{className:$.aiButtons,children:[(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder to check my emails in 30 minutes`),children:`📧 Email check in 30min`}),(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder every hour to take a break and drink water`),children:`💧 Hourly water break`}),(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder at the end of the work day (6pm) to do an evening review of my tasks and prepare tomorrow's plan`),children:`🌆 Evening review 6pm`}),(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Look at my calendar and set reminders for all events today`),children:`📅 Remind me of today's events`})]})]}),m&&(0,k.jsx)(`div`,{className:$.overlay,onClick:e=>{e.target===e.currentTarget&&h(!1)},children:(0,k.jsxs)(`div`,{className:$.modal,children:[(0,k.jsx)(`div`,{className:$.modalTitle,children:e(`reminders.new`)}),(0,k.jsx)(`div`,{className:$.label,children:`Message *`}),(0,k.jsx)(`div`,{className:$.msgTemplates,children:kE.map(e=>(0,k.jsx)(`button`,{className:`${$.msgTemplate} ${o.message===e?$.msgTemplateActive:``}`,onClick:()=>s(t=>({...t,message:e})),children:e},e))}),(0,k.jsx)(`input`,{className:$.input,value:o.message,onChange:e=>s(t=>({...t,message:e.target.value})),placeholder:`Reminder message (e.g. Call John)`}),(0,k.jsx)(`div`,{className:$.label,children:`When *`}),(0,k.jsxs)(`div`,{className:$.typeTabs,children:[(0,k.jsx)(`button`,{className:`${$.typeTab} ${o.atTimeType===`relative`?$.typeTabActive:``}`,onClick:()=>s(e=>({...e,atTimeType:`relative`})),children:`Relative`}),(0,k.jsx)(`button`,{className:`${$.typeTab} ${o.atTimeType===`absolute`?$.typeTabActive:``}`,onClick:()=>s(e=>({...e,atTimeType:`absolute`})),children:`Exact time`})]}),o.atTimeType===`relative`?(0,k.jsxs)(`div`,{className:$.relRow,children:[(0,k.jsx)(`span`,{className:$.inLabel,children:`in`}),(0,k.jsx)(`input`,{className:$.relInput,type:`number`,min:`1`,value:o.relValue,onChange:e=>s(t=>({...t,relValue:e.target.value}))}),(0,k.jsxs)(`select`,{className:$.relSelect,value:o.relUnit,onChange:e=>s(t=>({...t,relUnit:e.target.value})),children:[(0,k.jsx)(`option`,{value:`minutes`,children:`minutes`}),(0,k.jsx)(`option`,{value:`hours`,children:`hours`}),(0,k.jsx)(`option`,{value:`days`,children:`days`})]})]}):(0,k.jsx)(`input`,{className:$.input,type:`datetime-local`,value:o.atTime,onChange:e=>s(t=>({...t,atTime:e.target.value}))}),u&&(0,k.jsx)(`div`,{className:$.formErr,children:u}),f&&(0,k.jsx)(`div`,{className:$.formOk,children:f}),(0,k.jsxs)(`div`,{className:$.modalBtns,children:[(0,k.jsx)(`button`,{className:$.cancelModalBtn,onClick:()=>h(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:$.saveBtn,onClick:v,disabled:c,children:c?`Setting…`:`🔔 Set Reminder`})]})]})})]})}var ME={root:`_root_atgeb_1`,icon:`_icon_atgeb_10`,title:`_title_atgeb_11`,sub:`_sub_atgeb_12`},NE={dashboard:`⚡`,email:`📧`,calendar:`📅`,tasks:`✅`,contacts:`👤`,notes:`📝`,drive:`💾`,onedrive:`☁️`,mstodo:`📋`,github:`🐙`,slack:`💬`,notion:`📋`,collab:`🏛️`,maps:`🗺️`,cron:`⏰`,screen:`🖥️`,reminders:`🔔`,birthdays:`🎂`,settings:`⚙️`,agents:`🤖`,plan:`🗓️`,webcraft:`🔨`,connectors:`🔗`};function PE({view:e}){let t=j();return(0,k.jsxs)(`div`,{className:ME.root,children:[(0,k.jsx)(`div`,{className:ME.icon,children:NE[e]??`🔧`}),(0,k.jsx)(`div`,{className:ME.title,children:e.charAt(0).toUpperCase()+e.slice(1)}),(0,k.jsx)(`div`,{className:ME.sub,children:t(`common.comingSoon`)})]})}function FE({activeView:e}){switch(e){case`dashboard`:return(0,k.jsx)(wt,{});case`chat`:return(0,k.jsx)(Ee,{});case`email`:return(0,k.jsx)(rn,{});case`calendar`:return(0,k.jsx)(cn,{});case`tasks`:return(0,k.jsx)(Et,{});case`notes`:return(0,k.jsx)(Rt,{});case`contacts`:return(0,k.jsx)(Vt,{});case`birthdays`:return(0,k.jsx)(Mt,{});case`cron`:return(0,k.jsx)(It,{});case`connectors`:return(0,k.jsx)(Yt,{});case`agents`:return(0,k.jsx)(fn,{});case`drive`:return(0,k.jsx)(mn,{});case`onedrive`:return(0,k.jsx)(hE,{});case`mstodo`:return(0,k.jsx)(_E,{});case`github`:return(0,k.jsx)(gn,{});case`slack`:return(0,k.jsx)(yn,{});case`notion`:return(0,k.jsx)(bn,{});case`collab`:return(0,k.jsx)(wn,{});case`plan`:return(0,k.jsx)(pE,{});case`screen`:return(0,k.jsx)(bE,{});case`maps`:return(0,k.jsx)(DE,{});case`reminders`:return(0,k.jsx)(jE,{});case`settings`:return(0,k.jsx)(At,{});default:return(0,k.jsx)(PE,{view:e})}}function IE(){let{activeView:e}=ne();return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{style:{display:e===`studio`?`contents`:`none`},children:(0,k.jsx)(yt,{})}),(0,k.jsx)(`div`,{style:{display:e===`webcraft`?`contents`:`none`},children:(0,k.jsx)(oE,{})}),e!==`studio`&&e!==`webcraft`&&(0,k.jsx)(FE,{activeView:e})]})}(0,v.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(_.StrictMode,{children:(0,k.jsx)(me,{children:(0,k.jsx)(IE,{})})}));