nothumanallowed 16.0.62 → 16.0.63

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)(``),[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);
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_1qowo_2`,topbar:`_topbar_1qowo_11`,topbarLeft:`_topbarLeft_1qowo_20`,topbarTitle:`_topbarTitle_1qowo_21`,topbarSub:`_topbarSub_1qowo_22`,topbarActions:`_topbarActions_1qowo_23`,runBtn:`_runBtn_1qowo_25`,runBtnActive:`_runBtnActive_1qowo_32`,logBtn:`_logBtn_1qowo_34`,newWfBtn:`_newWfBtn_1qowo_41`,body:`_body_1qowo_50`,sidebar:`_sidebar_1qowo_53`,sidebarTitle:`_sidebarTitle_1qowo_61`,sidebarEmpty:`_sidebarEmpty_1qowo_65`,wfItem:`_wfItem_1qowo_67`,wfItemActive:`_wfItemActive_1qowo_78`,wfItemRow:`_wfItemRow_1qowo_79`,wfItemName:`_wfItemName_1qowo_80`,wfItemMeta:`_wfItemMeta_1qowo_81`,wfOn:`_wfOn_1qowo_82`,wfOff:`_wfOff_1qowo_83`,wfDelBtn:`_wfDelBtn_1qowo_84`,canvasArea:`_canvasArea_1qowo_96`,canvasHeader:`_canvasHeader_1qowo_98`,wfNameInput:`_wfNameInput_1qowo_103`,canvasHint:`_canvasHint_1qowo_110`,portHint:`_portHint_1qowo_111`,connectHint:`_connectHint_1qowo_112`,cancelConnectBtn:`_cancelConnectBtn_1qowo_113`,canvas:`_canvas_1qowo_96`,canvasConnecting:`_canvasConnecting_1qowo_126`,canvasSvg:`_canvasSvg_1qowo_128`,canvasNode:`_canvasNode_1qowo_138`,canvasNodeSelected:`_canvasNodeSelected_1qowo_156`,canvasNodeConnecting:`_canvasNodeConnecting_1qowo_157`,nodeIcon:`_nodeIcon_1qowo_159`,nodeLabel:`_nodeLabel_1qowo_160`,nodeConfigPreview:`_nodeConfigPreview_1qowo_161`,nodeDelBtn:`_nodeDelBtn_1qowo_163`,portOut:`_portOut_1qowo_175`,portActive:`_portActive_1qowo_186`,portIn:`_portIn_1qowo_188`,pulse:`_pulse_1qowo_1`,canvasDrop:`_canvasDrop_1qowo_199`,canvasEmpty:`_canvasEmpty_1qowo_207`,canvasEmptyIcon:`_canvasEmptyIcon_1qowo_212`,canvasEmptyTitle:`_canvasEmptyTitle_1qowo_213`,canvasEmptyDesc:`_canvasEmptyDesc_1qowo_214`,logPanel:`_logPanel_1qowo_217`,logHeader:`_logHeader_1qowo_224`,logTime:`_logTime_1qowo_230`,logClose:`_logClose_1qowo_231`,logEmpty:`_logEmpty_1qowo_232`,logStep:`_logStep_1qowo_233`,logStepError:`_logStepError_1qowo_234`,logStepHeader:`_logStepHeader_1qowo_235`,logStepIcon:`_logStepIcon_1qowo_236`,logStepLabel:`_logStepLabel_1qowo_237`,logStepErrBadge:`_logStepErrBadge_1qowo_238`,logStepErr:`_logStepErr_1qowo_234`,logStepOutput:`_logStepOutput_1qowo_240`,rightPanel:`_rightPanel_1qowo_245`,configPanel:`_configPanel_1qowo_256`,configHeader:`_configHeader_1qowo_257`,configClose:`_configClose_1qowo_258`,configDesc:`_configDesc_1qowo_259`,configFields:`_configFields_1qowo_260`,configField:`_configField_1qowo_260`,configLabel:`_configLabel_1qowo_262`,configRequired:`_configRequired_1qowo_263`,configInput:`_configInput_1qowo_264`,configTextarea:`_configTextarea_1qowo_271`,zoomControls:`_zoomControls_1qowo_281`,configHint:`_configHint_1qowo_307`,configDelete:`_configDelete_1qowo_309`,palette:`_palette_1qowo_313`,paletteTitle:`_paletteTitle_1qowo_314`,paletteTabs:`_paletteTabs_1qowo_315`,paletteTab:`_paletteTab_1qowo_315`,paletteTabActive:`_paletteTabActive_1qowo_321`,paletteNodes:`_paletteNodes_1qowo_322`,paletteDef:`_paletteDef_1qowo_324`,paletteDefIcon:`_paletteDefIcon_1qowo_332`,paletteDefLabel:`_paletteDefLabel_1qowo_333`,paletteDefDesc:`_paletteDefDesc_1qowo_334`,paletteFooter:`_paletteFooter_1qowo_336`,paletteGuide:`_paletteGuide_1qowo_340`,guideTitle:`_guideTitle_1qowo_348`,guideStep:`_guideStep_1qowo_357`,guideNum:`_guideNum_1qowo_365`,guideTip:`_guideTip_1qowo_381`,guideCode:`_guideCode_1qowo_392`,nodeListMobile:`_nodeListMobile_1qowo_436`,nodeRow:`_nodeRow_1qowo_444`,nodeRowIcon:`_nodeRowIcon_1qowo_457`,nodeRowBody:`_nodeRowBody_1qowo_463`,nodeRowLabel:`_nodeRowLabel_1qowo_467`,nodeRowDesc:`_nodeRowDesc_1qowo_473`,nodeRowIndex:`_nodeRowIndex_1qowo_480`,nodeRowBranch:`_nodeRowBranch_1qowo_488`,configSheet:`_configSheet_1qowo_496`,configSheetHandle:`_configSheetHandle_1qowo_509`,runFab:`_runFab_1qowo_519`,debuggerPanel:`_debuggerPanel_1qowo_548`,dbgHeader:`_dbgHeader_1qowo_564`,dbgTimeline:`_dbgTimeline_1qowo_565`,dbgWatcher:`_dbgWatcher_1qowo_566`,dbgEmpty:`_dbgEmpty_1qowo_567`,dbgInspector:`_dbgInspector_1qowo_563`,dbgHeaderLeft:`_dbgHeaderLeft_1qowo_591`,dbgHeaderRight:`_dbgHeaderRight_1qowo_600`,dbgTitle:`_dbgTitle_1qowo_609`,dbgRunSelect:`_dbgRunSelect_1qowo_610`,dbgStats:`_dbgStats_1qowo_619`,dbgPausedBadge:`_dbgPausedBadge_1qowo_620`,dbgPulse:`_dbgPulse_1qowo_1`,dbgBtnResume:`_dbgBtnResume_1qowo_634`,dbgBtnReplay:`_dbgBtnReplay_1qowo_634`,dbgTlStep:`_dbgTlStep_1qowo_673`,dbgTlStepOk:`_dbgTlStepOk_1qowo_691`,dbgTlStepErr:`_dbgTlStepErr_1qowo_692`,dbgTlStepPaused:`_dbgTlStepPaused_1qowo_693`,dbgTlStepActive:`_dbgTlStepActive_1qowo_694`,dbgTlIcon:`_dbgTlIcon_1qowo_699`,dbgTlLabel:`_dbgTlLabel_1qowo_700`,dbgTlMs:`_dbgTlMs_1qowo_708`,dbgInspHeader:`_dbgInspHeader_1qowo_719`,dbgInspLabel:`_dbgInspLabel_1qowo_729`,dbgInspIcon:`_dbgInspIcon_1qowo_738`,dbgInspDuration:`_dbgInspDuration_1qowo_739`,dbgInspActions:`_dbgInspActions_1qowo_747`,dbgBtnExplain:`_dbgBtnExplain_1qowo_755`,dbgBtnReplayFrom:`_dbgBtnReplayFrom_1qowo_767`,dbgBtnBp:`_dbgBtnBp_1qowo_778`,dbgBtnBpActive:`_dbgBtnBpActive_1qowo_787`,dbgBpGroup:`_dbgBpGroup_1qowo_792`,dbgBpCondition:`_dbgBpCondition_1qowo_800`,dbgExplanation:`_dbgExplanation_1qowo_820`,dbgExplanationIcon:`_dbgExplanationIcon_1qowo_833`,dbgExplanationText:`_dbgExplanationText_1qowo_834`,dbgTabs:`_dbgTabs_1qowo_836`,dbgTab:`_dbgTab_1qowo_836`,dbgTabActive:`_dbgTabActive_1qowo_854`,dbgTabBody:`_dbgTabBody_1qowo_858`,dbgPre:`_dbgPre_1qowo_872`,dbgPreErr:`_dbgPreErr_1qowo_883`,dbgMuted:`_dbgMuted_1qowo_884`,canvasNodeOk:`_canvasNodeOk_1qowo_887`,canvasNodeErr:`_canvasNodeErr_1qowo_888`,canvasNodePaused:`_canvasNodePaused_1qowo_889`,canvasNodeFocused:`_canvasNodeFocused_1qowo_893`,nodeBpBadge:`_nodeBpBadge_1qowo_898`,dbgWatcherHeader:`_dbgWatcherHeader_1qowo_926`,dbgWatcherTitle:`_dbgWatcherTitle_1qowo_934`,dbgWatcherSub:`_dbgWatcherSub_1qowo_939`,dbgWatcherBody:`_dbgWatcherBody_1qowo_943`,dbgWatcherRow:`_dbgWatcherRow_1qowo_948`,dbgWatcherKey:`_dbgWatcherKey_1qowo_954`,dbgWatcherVal:`_dbgWatcherVal_1qowo_961`,dbgEditConfig:`_dbgEditConfig_1qowo_974`,dbgEditTitle:`_dbgEditTitle_1qowo_979`,dbgEditRow:`_dbgEditRow_1qowo_985`,dbgEditLabel:`_dbgEditLabel_1qowo_992`,dbgEditInput:`_dbgEditInput_1qowo_998`,dbgEditActions:`_dbgEditActions_1qowo_1013`,dbgDiffPicker:`_dbgDiffPicker_1qowo_1020`,dbgDiffOverlay:`_dbgDiffOverlay_1qowo_1021`,dbgDiffModal:`_dbgDiffModal_1qowo_1035`,dbgDiffHeader:`_dbgDiffHeader_1qowo_1045`,dbgDiffBody:`_dbgDiffBody_1qowo_1060`,dbgDiffRow:`_dbgDiffRow_1qowo_1068`,dbgDiffOk:`_dbgDiffOk_1qowo_1074`,dbgDiffChanged:`_dbgDiffChanged_1qowo_1075`,dbgDiffAdded:`_dbgDiffAdded_1qowo_1076`,dbgDiffRemoved:`_dbgDiffRemoved_1qowo_1077`,dbgDiffNodeLabel:`_dbgDiffNodeLabel_1qowo_1078`,dbgDiffDuration:`_dbgDiffDuration_1qowo_1086`,dbgDiffSplit:`_dbgDiffSplit_1qowo_1093`,dbgDiffSide:`_dbgDiffSide_1qowo_1099`,dbgDiffSideLabel:`_dbgDiffSideLabel_1qowo_1105`,envSelect:`_envSelect_1qowo_1113`,backupStatus:`_backupStatus_1qowo_1123`,templateCard:`_templateCard_1qowo_1130`,templateHeader:`_templateHeader_1qowo_1139`,templateName:`_templateName_1qowo_1145`,templateTag:`_templateTag_1qowo_1150`,templateDesc:`_templateDesc_1qowo_1159`,templateMeta:`_templateMeta_1qowo_1165`,varPickerBtn:`_varPickerBtn_1qowo_1171`,varPickerMenu:`_varPickerMenu_1qowo_1185`,varPickerTitle:`_varPickerTitle_1qowo_1198`,varPickerItem:`_varPickerItem_1qowo_1205`,varPickerLabel:`_varPickerLabel_1qowo_1224`,varPickerHint:`_varPickerHint_1qowo_1229`,varPickerToken:`_varPickerToken_1qowo_1235`},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