nothumanallowed 15.1.59 → 15.1.61

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nothumanallowed",
3
- "version": "15.1.59",
3
+ "version": "15.1.61",
4
4
  "description": "NotHumanAllowed — 38 AI agents, 80 tools, Studio (visual agentic workflows). Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, Alexandria E2E messaging, GitHub, Notion, Slack, voice chat, free AI (Liara), 28 languages. Zero-dependency CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.mjs CHANGED
@@ -63,6 +63,10 @@ export async function main(argv) {
63
63
  info(`Run "nha update" (recommended — auto-installs npm + agents)`);
64
64
  info(`Or copy-paste this ENTIRE line (note: --prefer-online, not --pref-online):`);
65
65
  info(` npm cache clean --force && npm install -g nothumanallowed@${result.latest} --prefer-online && hash -r && nha version`);
66
+ info(`⚠ If you ran the install WITHOUT "hash -r" at the end and now get`);
67
+ info(` "bash: ...node/vX.Y.Z/bin/nha: No such file", run: hash -r`);
68
+ info(` (or just close and reopen the terminal). It's a bash path cache issue,`);
69
+ info(` not an install failure — your nha package is already updated.`);
66
70
  }
67
71
  }).catch(() => {});
68
72
  }
package/src/constants.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
 
8
- export const VERSION = '15.1.59';
8
+ export const VERSION = '15.1.61';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -651,13 +651,13 @@ ${e.map(e=>`<div class="section"><div class="agent-header"><span class="icon">${
651
651
  ${f}
652
652
  <div class="footer">NHA Studio · nothumanallowed.com · ${new Date().getFullYear()}</div>
653
653
  </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))},P=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`)},Se=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),ue.current=``,w(null),M.current=null,te(!1),b({in:0,out:0}),v(null),O(!1);try{sessionStorage.removeItem(ut)}catch{}}},Ce=i.some(e=>e.output||e.status===`running`);return(0,A.jsxs)(`div`,{className:F.root,children:[(0,A.jsxs)(`div`,{className:F.header,children:[(0,A.jsxs)(`div`,{className:F.headerLeft,children:[(0,A.jsx)(`div`,{className:F.title,children:`Studio`}),(0,A.jsx)(`div`,{className:F.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,A.jsxs)(`div`,{className:F.headerActions,children:[y.in+y.out>0&&(0,A.jsxs)(`div`,{className:F.tokenBar,children:[(0,A.jsxs)(`span`,{className:F.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,A.jsx)(`span`,{className:F.tokDim,children:` in `}),(0,A.jsxs)(`span`,{className:F.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,A.jsx)(`span`,{className:F.tokDim,children:` out`})]}),(0,A.jsxs)(`div`,{style:{position:`relative`},ref:de,children:[(0,A.jsxs)(`button`,{className:F.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,A.jsx)(`div`,{className:F.sessionsDrawer,children:f.length===0?(0,A.jsx)(`div`,{className:F.noSessions,children:`No saved sessions yet.`}):(0,A.jsxs)(A.Fragment,{children:[f.map(e=>(0,A.jsxs)(`div`,{className:F.sessionItem,children:[(0,A.jsxs)(`div`,{className:F.sessionInfo,onClick:()=>_e(e),children:[(0,A.jsx)(`div`,{className:F.sessionTask,children:e.task.slice(0,80)}),(0,A.jsxs)(`div`,{className:F.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,A.jsxs)(`div`,{className:F.sessionBtns,children:[(0,A.jsx)(`button`,{className:F.importBtn,onClick:()=>P(e),children:`→ Chat`}),(0,A.jsx)(`button`,{className:F.delSessionBtn,onClick:()=>ve(e.id),children:`✕`})]})]},e.id)),(0,A.jsx)(`div`,{className:F.sessionsFooter,children:(0,A.jsx)(`button`,{className:F.clearAllSessionsBtn,onClick:ye,children:`Clear All`})})]})})]}),x&&(0,A.jsx)(`button`,{className:F.canvasToggleBtn,onClick:()=>{O(!0),k(`canvas`)},children:`📊 Panel`}),c&&(0,A.jsx)(`button`,{className:F.pdfBtn,onClick:be,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,A.jsx)(`button`,{className:F.clearBtn,onClick:Se,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,A.jsxs)(`div`,{className:F.inputArea,children:[(0,A.jsxs)(`div`,{className:F.inputRow,children:[(0,A.jsx)(`textarea`,{className:F.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(),me())}}),(0,A.jsxs)(`div`,{className:F.inputControls,children:[u?(0,A.jsx)(`button`,{className:F.stopBtn,onClick:he,children:`■ Stop`}):(0,A.jsx)(`button`,{className:F.runBtn,onClick:me,disabled:!n.trim(),children:`Run ▶`}),(0,A.jsxs)(`label`,{className:F.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,A.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>pe(e.target.files?.[0])})]})]})]}),g&&(0,A.jsxs)(`div`,{className:F.attachBadge,children:[`📎 `,g.name,(0,A.jsx)(`button`,{className:F.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:F.examples,children:Oe.map((e,t)=>(0,A.jsx)(`button`,{className:F.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,A.jsxs)(`div`,{className:F.financeSection,children:[(0,A.jsx)(`div`,{className:F.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,A.jsx)(`div`,{className:F.financePresets,children:Ee.map((e,t)=>(0,A.jsx)(`button`,{className:F.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:F.officeSceneWrap,style:{overflow:`hidden`,position:`relative`,height:`180px`},children:(0,A.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,A.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,A.jsx)(Ze,{nodes:i,running:u})}),(0,A.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,A.jsx)(nt,{agents:T.length>0?T:i,council:C})})]})}),(0,A.jsxs)(`div`,{className:`${F.pipelineWrap} ${u?F.pipelineRunning:``}`,children:[(0,A.jsxs)(`div`,{className:F.pipelineTitle,children:[`Agent Pipeline`,u&&(0,A.jsx)(`span`,{className:F.pipelineLiveTag,children:`● LIVE`})]}),(0,A.jsx)(`div`,{className:F.pipelineNodes,children:i.map((e,t)=>(0,A.jsxs)(`div`,{className:F.pipelineStep,children:[(0,A.jsxs)(`div`,{className:`${F.agentChip} ${F[`chip_${e.status}`]}`,children:[(0,A.jsx)(`span`,{className:F.chipIcon,children:e.icon}),(0,A.jsx)(`span`,{className:F.chipLabel,children:e.label}),e.status===`running`&&(0,A.jsxs)(`span`,{className:F.chipDots,children:[(0,A.jsx)(`span`,{className:F.dot1,children:`.`}),(0,A.jsx)(`span`,{className:F.dot2,children:`.`}),(0,A.jsx)(`span`,{className:F.dot3,children:`.`})]}),e.status===`done`&&(0,A.jsx)(`span`,{className:F.chipCheck,children:`✓`}),e.status===`error`&&(0,A.jsx)(`span`,{className:F.chipErr,children:`✗`})]}),t<i.length-1&&(0,A.jsx)(`div`,{className:`${F.arrow} ${u?F.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,A.jsx)(`div`,{className:F.reasonRow,children:i.map((e,t)=>e.reason?(0,A.jsxs)(`div`,{className:F.reasonChip,title:e.reason,children:[(0,A.jsx)(`span`,{className:F.reasonIcon,children:e.icon}),(0,A.jsxs)(`span`,{className:F.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,A.jsxs)(`div`,{className:F.body,ref:le,children:[(o.length>0||Ce)&&(0,A.jsxs)(`div`,{className:F.twoCol,children:[(0,A.jsxs)(`div`,{className:F.logPanel,children:[(0,A.jsx)(`div`,{className:F.panelTitle,children:`Live Log`}),(0,A.jsx)(`div`,{className:F.logBody,ref:ce,children:o.map((e,t)=>(0,A.jsxs)(`div`,{className:`${F.logEntry} ${F[`log_${e.type}`]}`,children:[(0,A.jsx)(`span`,{className:F.logTime,children:e.time}),(0,A.jsx)(`span`,{className:F.logIcon,children:e.icon}),(0,A.jsx)(`span`,{className:F.logAgent,children:e.agent}),(0,A.jsx)(`span`,{className:F.logText,children:e.text})]},t))})]}),(0,A.jsx)(`div`,{className:F.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,A.jsxs)(`div`,{className:`${F.liveBlock} ${e.status===`running`?F.liveBlockActive:``} ${e.status===`done`&&e.output?F.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?oe(e):void 0,children:[(0,A.jsxs)(`div`,{className:F.liveBlockHeader,children:[(0,A.jsx)(`span`,{className:F.liveBlockIcon,children:e.icon}),(0,A.jsx)(`span`,{className:F.liveBlockLabel,children:e.label}),e.reason&&(0,A.jsx)(`span`,{className:F.liveBlockReason,title:e.reason,children:`ℹ`}),(0,A.jsx)(`span`,{className:`${F.outputStatus} ${F[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,A.jsx)(`span`,{className:F.expandHint,children:`↗ espandi`})]}),e.status===`running`&&(0,A.jsxs)(`div`,{className:F.liveBlockWorking,children:[(0,A.jsx)(`span`,{className:F.workingDot}),(0,A.jsx)(`span`,{className:F.workingDot}),(0,A.jsx)(`span`,{className:F.workingDot}),(0,A.jsx)(`span`,{className:F.workingLabel,children:e.statusLine??`elaborazione in corso`})]}),(0,A.jsx)(`div`,{className:`${F.liveBlockBody} ${e.status===`done`&&e.output?F.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:xe(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,A.jsxs)(`div`,{className:F.parliamentPrompt,children:[(0,A.jsx)(`div`,{className:F.parliamentPromptIcon,children:`🏛️`}),(0,A.jsxs)(`div`,{className:F.parliamentPromptContent,children:[(0,A.jsx)(`div`,{className:F.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,A.jsxs)(`div`,{className:F.parliamentPromptDesc,children:[T.length,` agenti (`,T.map(e=>e.label).join(`, `),`) hanno prodotto output. Il Geth Consensus eseguirà cross-reading, refinement e mediazione HERALD per raggiungere un consenso collettivo.`]}),(0,A.jsxs)(`div`,{className:F.parliamentPromptMeta,children:[`Complessità: `,T.length<=3?`⚡ Rapido (~30s)`:T.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,A.jsxs)(`div`,{className:F.parliamentPromptBtns,children:[(0,A.jsx)(`button`,{className:F.parliamentActivateBtn,onClick:ge,children:`🏛️ Attiva`}),(0,A.jsx)(`button`,{className:F.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,A.jsx)(`div`,{className:F.councilWrapper,children:(0,A.jsx)(_t,{council:C})}),c&&!u&&(0,A.jsxs)(`details`,{className:F.resultAccordion,open:i.length<=1,children:[(0,A.jsxs)(`summary`,{className:F.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,A.jsx)(`div`,{className:F.resultAccordionBody,dangerouslySetInnerHTML:{__html:xe(c)}})]})]}),D&&(0,A.jsxs)(`div`,{className:F.canvasPanel,children:[(0,A.jsxs)(`div`,{className:F.canvasPanelHeader,children:[(0,A.jsxs)(`div`,{className:F.panelTabs,children:[(0,A.jsx)(`button`,{className:`${F.panelTabBtn} ${re===`canvas`?F.panelTabActive:``}`,onClick:()=>k(`canvas`),children:`📊 Canvas`}),(0,A.jsx)(`button`,{className:`${F.panelTabBtn} ${re===`browser`?F.panelTabActive:``}`,onClick:()=>k(`browser`),children:`🌐 Browser`})]}),(0,A.jsxs)(`div`,{className:F.canvasPanelActions,children:[re===`canvas`&&x&&(0,A.jsx)(`button`,{className:F.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,A.jsx)(`button`,{className:F.canvasPanelClose,onClick:()=>O(!1),children:`✕`})]})]}),re===`canvas`?x?(0,A.jsx)(`iframe`,{className:F.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,A.jsx)(`div`,{className:F.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,A.jsxs)(`div`,{className:F.browserPanel,children:[(0,A.jsxs)(`div`,{className:F.browserBar,children:[(0,A.jsx)(`input`,{className:F.browserInput,value:ie,onChange:e=>j(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&j(ie)}}),(0,A.jsx)(`button`,{className:F.browserGo,onClick:()=>j(ie),children:`Go`})]}),ie?(0,A.jsx)(`iframe`,{className:F.canvasFrame,src:ie,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,A.jsx)(`div`,{className:F.panelEmpty,children:`Enter a URL above to browse`})]})]}),ae&&(0,A.jsx)(`div`,{className:F.blockModalOverlay,onClick:()=>oe(null),children:(0,A.jsxs)(`div`,{className:F.blockModal,onClick:e=>e.stopPropagation(),children:[(0,A.jsxs)(`div`,{className:F.blockModalHeader,children:[(0,A.jsx)(`span`,{className:F.liveBlockIcon,children:ae.icon}),(0,A.jsx)(`span`,{className:F.blockModalTitle,children:ae.label}),(0,A.jsx)(`button`,{className:F.blockModalClose,onClick:()=>oe(null),children:`✕`})]}),(0,A.jsx)(`div`,{className:`${F.liveBlockBody} ${F.blockModalBody}`,dangerouslySetInnerHTML:{__html:xe(ae.output)}})]})})]})}var z={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`},yt=[{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`}],bt={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 xt(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function St(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function Ct(){let e=ne(e=>e.setView),t=M(),[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)};E(`/api/tasks`).then(e=>t(r)(e?.tasks??[])),E(`/api/emails?page=0&pageSize=8`).then(e=>t(a)(e?.emails??[])),E(`/api/calendar`).then(e=>t(s)(e?.events??[])),E(`/api/status`).then(t(l));let n=localStorage.getItem(`nha_weather_location`),i=t=>E(`/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(yt.map(e=>e.group))];return(0,A.jsxs)(`div`,{className:z.root,children:[(0,A.jsxs)(`div`,{className:z.hero,children:[(0,A.jsxs)(`div`,{className:z.heroLeft,children:[(0,A.jsx)(`div`,{className:z.heroDate,children:y}),(0,A.jsx)(`div`,{className:z.heroTitle,children:c?(0,A.jsxs)(A.Fragment,{children:[`NHA `,(0,A.jsxs)(`span`,{className:z.heroVer,children:[`v`,c.version]}),` · `,(0,A.jsxs)(`span`,{className:z.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,A.jsx)(`div`,{className:z.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),d(null),E(`/api/weather?location=${encodeURIComponent(e)}`).then(e=>{e&&e.city&&d(e)}))},children:u?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`span`,{className:z.wIcon,children:bt[u.desc]??u.icon??`🌡️`}),(0,A.jsxs)(`div`,{className:z.wInfo,children:[(0,A.jsxs)(`span`,{className:z.wTemp,children:[u.tempC,`°C`]}),(0,A.jsxs)(`span`,{className:z.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,A.jsxs)(`span`,{className:z.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,A.jsxs)(`span`,{className:z.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,A.jsxs)(`div`,{className:z.kpiRow,children:[(0,A.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,A.jsx)(`span`,{className:z.kpiNum,children:m.length}),(0,A.jsx)(`span`,{className:z.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,A.jsx)(`div`,{className:z.kpiBar,children:(0,A.jsx)(`div`,{className:z.kpiFill,style:{width:`${g}%`}})})]}),(0,A.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,A.jsx)(`span`,{className:z.kpiNum,children:v>0?v:i.length}),(0,A.jsx)(`span`,{className:z.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,A.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,A.jsx)(`span`,{className:z.kpiNum,children:o.length}),(0,A.jsx)(`span`,{className:z.kpiLbl,children:`Today's events`})]}),u&&(0,A.jsxs)(`div`,{className:z.kpi,children:[(0,A.jsxs)(`span`,{className:z.kpiNum,children:[u.feelsC,`°`]}),(0,A.jsx)(`span`,{className:z.kpiLbl,children:`Feels like`})]})]}),(0,A.jsxs)(`div`,{className:z.liveGrid,children:[o.length>0&&(0,A.jsxs)(`div`,{className:z.liveCard,children:[(0,A.jsxs)(`div`,{className:z.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,A.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,A.jsx)(`span`,{className:z.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,A.jsxs)(`div`,{className:z.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,A.jsx)(`span`,{className:z.liveTime,children:t.isAllDay?`All day`:xt(t.start)}),(0,A.jsxs)(`div`,{className:z.liveBody,children:[(0,A.jsx)(`span`,{className:z.liveTitle,children:t.summary}),t.location&&(0,A.jsx)(`span`,{className:z.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,A.jsxs)(`div`,{className:z.liveCard,children:[(0,A.jsxs)(`div`,{className:z.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,A.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,A.jsx)(`span`,{className:z.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,A.jsxs)(`div`,{className:`${z.liveRow} ${t.isUnread?z.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,A.jsx)(`span`,{className:z.liveTime,children:St(t.date)}),(0,A.jsxs)(`div`,{className:z.liveBody,children:[(0,A.jsx)(`span`,{className:z.liveTitle,children:t.subject}),(0,A.jsx)(`span`,{className:z.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,A.jsxs)(`div`,{className:z.liveCard,children:[(0,A.jsxs)(`div`,{className:z.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,A.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,A.jsx)(`span`,{className:z.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,A.jsxs)(`div`,{className:z.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,A.jsx)(`span`,{className:`${z.prio} ${z[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,A.jsx)(`div`,{className:z.liveBody,children:(0,A.jsx)(`span`,{className:z.liveTitle,children:t.description})})]},n))]})]}),(0,A.jsx)(`div`,{className:z.launcher,children:b.map(t=>(0,A.jsxs)(`div`,{className:z.launchGroup,children:[(0,A.jsx)(`div`,{className:z.launchGroupLabel,children:t}),(0,A.jsx)(`div`,{className:z.launchTiles,children:yt.filter(e=>e.group===t).map(t=>(0,A.jsxs)(`button`,{className:z.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,A.jsx)(`span`,{className:z.tileIcon,children:t.icon}),(0,A.jsx)(`span`,{className:z.tileLabel,children:t.label})]},t.view))})]},t))})]})}var wt={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 Tt(){let e=M(),[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=()=>E(`/api/tasks`).then(e=>{n(e?.tasks??[]),i(!1)});(0,_.useEffect)(()=>{f()},[]);let p=async()=>{a.trim()&&(u(!0),await D(`/api/tasks`,{description:a.trim(),priority:s}),o(``),u(!1),f(),d.current?.focus())},m=e=>D(`/api/tasks/${e}/done`,{},`PATCH`).then(f),h=e=>D(`/api/tasks/${e}/delete`,{}).then(f),g=()=>D(`/api/tasks/clear`,{filter:`done`}).then(f),v=()=>{confirm(e(`tasks.deleteTask`))&&D(`/api/tasks/clear`,{filter:`all`}).then(f)},y=t.filter(e=>e.status!==`done`),b=t.filter(e=>e.status===`done`);return r?(0,A.jsxs)(`div`,{className:wt.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,A.jsxs)(`div`,{className:wt.root,children:[(0,A.jsxs)(`div`,{className:wt.bar,children:[(0,A.jsx)(`input`,{ref:d,className:wt.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,A.jsxs)(`select`,{className:wt.select,value:s,onChange:e=>c(e.target.value),children:[(0,A.jsx)(`option`,{value:`high`,children:`High`}),(0,A.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,A.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,A.jsx)(`button`,{className:wt.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,A.jsxs)(`div`,{className:wt.actions,children:[(0,A.jsx)(`button`,{className:wt.clearDone,onClick:g,children:`Clear completed`}),(0,A.jsx)(`button`,{className:wt.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,A.jsxs)(`div`,{className:wt.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,A.jsx)(`span`,{className:wt.progress,children:(0,A.jsx)(`span`,{className:wt.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,A.jsx)(`div`,{className:wt.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,A.jsxs)(`div`,{className:wt.task,children:[(0,A.jsx)(`span`,{className:wt.check,onClick:()=>m(e.id)}),(0,A.jsx)(`span`,{className:wt.desc,onClick:()=>m(e.id),children:e.description}),(0,A.jsx)(`span`,{className:`${wt.badge} ${wt[`badge_`+e.priority]}`,children:e.priority}),(0,A.jsx)(`span`,{className:wt.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:wt.doneLabel,children:`Completed`}),b.map(e=>(0,A.jsxs)(`div`,{className:`${wt.task} ${wt.taskDone}`,children:[(0,A.jsx)(`span`,{className:`${wt.check} ${wt.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,A.jsx)(`span`,{className:wt.desc,onClick:()=>m(e.id),children:e.description}),(0,A.jsx)(`span`,{className:`${wt.badge} ${wt[`badge_`+e.priority]}`,children:e.priority}),(0,A.jsx)(`span`,{className:wt.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var B={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`},Et={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function Dt({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,A.jsxs)(`div`,{className:B.field,children:[(0,A.jsx)(`label`,{className:B.fieldLabel,children:t}),(0,A.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:B.fieldInput})]})}function Ot(){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=()=>{E(`/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 D(`/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,A.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,A.jsx)(`div`,{style:{fontSize:14,fontWeight:800,marginBottom:4},children:`Credentials Vault 🔐`}),(0,A.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,A.jsx)(`code`,{children:"${cred.NAME}"}),`. The raw value never leaves your computer.`]}),e.length>0&&(0,A.jsx)(`div`,{style:{marginBottom:12,border:`1px solid rgba(148,163,184,0.15)`,borderRadius:6},children:e.map(e=>(0,A.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,A.jsx)(`code`,{style:{background:`rgba(99,102,241,0.12)`,padding:`2px 6px`,borderRadius:4,color:`#a5b4fc`,fontWeight:700},children:e.name}),(0,A.jsx)(`span`,{style:{flex:1,opacity:.7},children:e.description||(0,A.jsx)(`em`,{children:`no description`})}),(0,A.jsx)(`span`,{style:{fontSize:10,opacity:.5},children:new Date(e.updatedAt).toLocaleString()}),e.hasError&&(0,A.jsx)(`span`,{style:{color:`#ef4444`,fontSize:10},children:`⚠ decrypt error`}),(0,A.jsx)(`button`,{onClick:()=>m(e.name),style:{background:`transparent`,border:`none`,cursor:`pointer`,color:`#ef4444`,fontSize:14},children:`✕`})]},e.name))}),(0,A.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:8},children:[(0,A.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,A.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,A.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,A.jsx)(`div`,{style:{color:`#ef4444`,fontSize:11,marginTop:4},children:u}),(0,A.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 kt(){let{setConfig:e}=ne(),t=M(),[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)(``),[T,O]=(0,_.useState)(``),[re,k]=(0,_.useState)(``),[ie,j]=(0,_.useState)(``),[ae,oe]=(0,_.useState)(``),[se,ce]=(0,_.useState)(``),[le,ue]=(0,_.useState)(``),[N,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(!1),[me,he]=(0,_.useState)(``),[ge,_e]=(0,_.useState)(`en`),[ve,ye]=(0,_.useState)(`07:00`),[be,xe]=(0,_.useState)(`18:00`),[P,Se]=(0,_.useState)(`30`),[Ce,we]=(0,_.useState)(`off`),[Te,F]=(0,_.useState)(``),[Ee,De]=(0,_.useState)(``),[Oe,I]=(0,_.useState)(``),[L,ke]=(0,_.useState)(`agent`),[Ae,je]=(0,_.useState)(``),[Me,Ne]=(0,_.useState)(!0),[Pe,Fe]=(0,_.useState)(!0),[Ie,Le]=(0,_.useState)(`3`),[Re,R]=(0,_.useState)(`0.30`),[ze,Be]=(0,_.useState)(!0),[Ve,He]=(0,_.useState)(!1),[Ue,We]=(0,_.useState)(!1),[Ge,Ke]=(0,_.useState)(!1),[qe,Je]=(0,_.useState)(!1),[Ye,Xe]=(0,_.useState)(!1),[Ze,Qe]=(0,_.useState)(!1),[$e,et]=(0,_.useState)(!0),[tt,nt]=(0,_.useState)(``),[rt,it]=(0,_.useState)(!1),[at,ot]=(0,_.useState)(!1),[st,ct]=(0,_.useState)(!0),[lt,ut]=(0,_.useState)(``),[dt,ft]=(0,_.useState)(``),[pt,mt]=(0,_.useState)(``),[ht,gt]=(0,_.useState)(``),[_t,vt]=(0,_.useState)(`common`),[z,yt]=(0,_.useState)(!1),[bt,xt]=(0,_.useState)(``);(0,_.useEffect)(()=>{E(`/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`),he(t?.model??``),_e(t?.lang??`en`),ye(t?.planTime??`07:00`),xe(t?.summaryTime??`18:00`),Se(String(t?.meetingAlert??`30`)),we(t?.thinking??`off`),te(``);let i=t?.responder,o=i?.telegram;I(String(o?.botName??``));let s=String(o?.personaMode??`agent`);ke(s===`persona`||s===`persona-only`||s===`persona+role`?s:`agent`),je(Array.isArray(o?.allowedChatIds)?o.allowedChatIds.join(`, `):``),Ne(i?.autoRoute!==!1);let c=t?.deliberation;Fe(c?.enabled!==!1),Le(String(c?.rounds??`3`)),R(String(c?.convergence??`0.30`)),Be(c?.tribunalEnabled!==!1);let l=t?.ops?.proactive;He(!!l?.enabled),We(!!l?.emailFollowUp),Ke(!!l?.meetingPrep),Je(!!l?.patterns),Xe(!!l?.deadlines);let u=t?.voice;Qe(!!u?.preferWhisper),et(u?.speechSynthesis!==!1),nt(String(u?.language??``));let d=t?.features;it(!!d?.verbose),ot(!!d?.immersive),ct(d?.knowledgeEnabled!==!1),ut(``),ft(String(t?.github?.defaultRepo??``)),mt(``),gt(``);let f=t?.microsoft;vt(String(f?.tenantId??`common`));let p=t?.plugins;yt(!!p?.autoRun),xt(String(p?.directory??``)),a(!1),t&&e(t)}),St()},[]);let St=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),Ct=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},wt=()=>Ct(`profile`,x),Tt=()=>{Ct(`provider`,C),Ct(`model`,me),Ct(`thinking`,Ce),ee&&Ct(`key`,ee),T&&Ct(`groq-key`,T),re&&Ct(`openai-key`,re),ie&&Ct(`gemini-key`,ie),ae&&Ct(`deepseek-key`,ae),se&&Ct(`grok-key`,se),le&&Ct(`mistral-key`,le),N&&Ct(`cohere-key`,N)},kt=()=>{Ct(`planTime`,ve),Ct(`summaryTime`,be),Ct(`meetingAlert`,Number(P))},At=()=>{v(t(`settings.googleOpening`)),D(`/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))},jt=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},V=()=>{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…`),D(e?`/api/imap/accounts/update`:`/api/imap/accounts`,t).then(e=>{e?.ok||e?.id?(h(`Saved!`),p(null),St()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},Mt=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>St())},Nt=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(St,3e3))},Pt=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 D(`/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}`)}}},Ft=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 D(`/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,A.jsxs)(`div`,{className:B.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let It=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,A.jsxs)(`div`,{className:B.root,children:[(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:t(`settings.profile`)}),(0,A.jsx)(`div`,{className:B.cardSub,children:t(`settings.profileSub`)}),(0,A.jsx)(`div`,{className:B.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,A.jsx)(Dt,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:wt,children:[It(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,A.jsxs)(`div`,{className:B.nhaFree,children:[(0,A.jsx)(`div`,{className:B.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,A.jsx)(`div`,{className:B.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,A.jsx)(`button`,{className:B.nhaFreeBtn,onClick:()=>{D(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),he(``),te(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:t(`settings.llmProvider`)}),(0,A.jsx)(`div`,{className:B.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,A.jsxs)(`div`,{className:B.keySummary,children:[(0,A.jsx)(`span`,{className:B.keySummaryIcon,children:`🔑`}),(0,A.jsxs)(`span`,{children:[`Chiavi configurate: `,(0,A.jsx)(`strong`,{children:e.join(`, `)})]})]})})(),(0,A.jsxs)(`div`,{className:B.field,children:[(0,A.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.provider`)}),(0,A.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:B.fieldInput,children:[(0,A.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,A.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,A.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,A.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,A.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,A.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,A.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,A.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,A.jsx)(`div`,{className:B.keySet,children:t(`settings.apiKeySet`)}):null),(0,A.jsx)(Dt,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,A.jsx)(Dt,{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:T,onChange:O}),(0,A.jsx)(`div`,{style:{marginTop:8,marginBottom:4},children:(0,A.jsxs)(`button`,{type:`button`,onClick:()=>pe(!fe),style:{background:`transparent`,border:`none`,color:`var(--accent, #6366f1)`,cursor:`pointer`,fontSize:12,padding:0,fontWeight:600},children:[fe?`▾`:`▸`,` Optional provider keys (OpenAI, Gemini, DeepSeek, Grok, Mistral, Cohere)`]})}),fe&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(Dt,{id:`openaiKey`,label:`OpenAI Key`,placeholder:n.hasOpenaiKey?`✓ configured — leave empty to keep`:`sk-... (platform.openai.com)`,type:`password`,value:re,onChange:k}),(0,A.jsx)(Dt,{id:`geminiKey`,label:`Gemini Key (Google)`,placeholder:n.hasGeminiKey?`✓ configured — leave empty to keep`:`AIza... (aistudio.google.com)`,type:`password`,value:ie,onChange:j}),(0,A.jsx)(Dt,{id:`deepseekKey`,label:`DeepSeek Key`,placeholder:n.hasDeepseekKey?`✓ configured — leave empty to keep`:`sk-... (platform.deepseek.com)`,type:`password`,value:ae,onChange:oe}),(0,A.jsx)(Dt,{id:`grokKey`,label:`Grok Key (X.AI)`,placeholder:n.hasGrokKey?`✓ configured — leave empty to keep`:`xai-... (console.x.ai)`,type:`password`,value:se,onChange:ce}),(0,A.jsx)(Dt,{id:`mistralKey`,label:`Mistral Key`,placeholder:n.hasMistralKey?`✓ configured — leave empty to keep`:`... (console.mistral.ai)`,type:`password`,value:le,onChange:ue}),(0,A.jsx)(Dt,{id:`cohereKey`,label:`Cohere Key`,placeholder:n.hasCohereKey?`✓ configured — leave empty to keep`:`... (dashboard.cohere.com)`,type:`password`,value:N,onChange:de})]}),(0,A.jsx)(Dt,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:me,onChange:he}),(0,A.jsxs)(`div`,{className:B.field,children:[(0,A.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.thinking`)}),(0,A.jsxs)(`select`,{value:Ce,onChange:e=>we(e.target.value),className:B.fieldInput,children:[(0,A.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,A.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:Tt,children:[It(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:t(`settings.language`)}),(0,A.jsxs)(`div`,{className:B.field,children:[(0,A.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.languageLabel`)}),(0,A.jsx)(`select`,{value:ge,onChange:t=>{let r=t.target.value;_e(r),Ct(`lang`,r),e({...n,lang:r})},className:B.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,A.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:t(`settings.telegram`)}),(0,A.jsx)(`div`,{className:B.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,A.jsxs)(`div`,{className:B.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,A.jsxs)(`div`,{className:B.connected,children:[`Discord: `,t(`common.connected`)]}),(0,A.jsx)(Dt,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:Te,onChange:F}),(0,A.jsx)(Dt,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:Ee,onChange:De}),(0,A.jsx)(Dt,{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:Oe,onChange:I}),(0,A.jsxs)(`div`,{className:B.field,children:[(0,A.jsx)(`label`,{className:B.fieldLabel,children:`Persona display mode`}),(0,A.jsxs)(`select`,{value:L,onChange:e=>ke(e.target.value),className:B.fieldInput,children:[(0,A.jsx)(`option`,{value:`agent`,children:`agent — show internal name [HERALD] (legacy/debug)`}),(0,A.jsx)(`option`,{value:`persona`,children:`persona — show [BotName] only (recommended)`}),(0,A.jsx)(`option`,{value:`persona-only`,children:`persona-only — no prefix at all (most natural)`}),(0,A.jsx)(`option`,{value:`persona+role`,children:`persona+role — [BotName · agent] (power users)`})]})]}),(0,A.jsx)(Dt,{id:`allowedChatIds`,label:`Allowed Chat IDs (Telegram)`,placeholder:`comma-separated numeric chat IDs (empty = anyone can chat with the bot)`,value:Ae,onChange:je}),(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:Me,onChange:e=>Ne(e.target.checked)}),` `,`Auto-route messages to specialist agents (recommended)`]})}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{Te&&Ct(`telegram-bot-token`,Te),Ee&&Ct(`discord-bot-token`,Ee),Ct(`bot-name`,Oe),Ct(`persona-mode`,L),Ct(`responder.telegram.allowedChatIds`,Ae.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>Number(e)||e)),Ct(`responder-auto-route`,Me)},children:[It(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:t(`settings.dailyOps`)}),(0,A.jsx)(Dt,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ve,onChange:ye}),(0,A.jsx)(Dt,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:be,onChange:xe}),(0,A.jsx)(Dt,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:P,onChange:Se}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:kt,children:[It(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:`Deliberation (Geth Consensus)`}),(0,A.jsx)(`div`,{className:B.cardSub,children:`Multi-round inter-agent reasoning for higher-quality answers`}),(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:Pe,onChange:e=>Fe(e.target.checked)}),` `,`Enable deliberation`]})}),(0,A.jsx)(Dt,{id:`delibRounds`,label:`Rounds (1–5)`,placeholder:`3`,value:Ie,onChange:Le}),(0,A.jsx)(Dt,{id:`delibConvergence`,label:`Convergence threshold (0–1, lower = stricter)`,placeholder:`0.30`,value:Re,onChange:R}),(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:ze,onChange:e=>Be(e.target.checked)}),` `,`Tribunal (final HERALD mediation)`]})}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{Ct(`deliberation`,Pe),Ct(`rounds`,Number(Ie)),Ct(`convergence`,Number(Re)),Ct(`tribunal`,ze)},children:[It(`deliberation`),` Save deliberation`]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:`Proactive Intelligence`}),(0,A.jsx)(`div`,{className:B.cardSub,children:`The bot acts on its own initiative (follow-ups, meeting prep, pattern detection)`}),[[`proactive`,`Master switch — enable proactive`,Ve,He],[`proactive-email`,`Email follow-up reminders`,Ue,We],[`proactive-meeting`,`Meeting preparation digests`,Ge,Ke],[`proactive-patterns`,`Behavioural pattern detection`,qe,Je],[`proactive-deadlines`,`Deadline tracking`,Ye,Xe]].map(([e,t,n,r])=>(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{Ct(`proactive`,Ve),Ct(`proactive-email`,Ue),Ct(`proactive-meeting`,Ge),Ct(`proactive-patterns`,qe),Ct(`proactive-deadlines`,Ye)},children:[It(`proactive`),` Save proactive`]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:`Voice`}),(0,A.jsx)(`div`,{className:B.cardSub,children:`Transcription (Whisper via Groq) and text-to-speech`}),(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:Ze,onChange:e=>Qe(e.target.checked)}),` `,`Prefer Whisper (Groq) over local STT`]})}),(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:$e,onChange:e=>et(e.target.checked)}),` `,`Speech synthesis (read replies aloud)`]})}),(0,A.jsx)(Dt,{id:`voiceLanguage`,label:`Voice language (BCP 47, e.g. it-IT, en-US)`,placeholder:`empty = use UI language`,value:tt,onChange:nt}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{Ct(`voice-whisper`,Ze),Ct(`voice-speech`,$e),tt&&Ct(`voice-language`,tt)},children:[It(`voice-whisper`),` Save voice`]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:`Features`}),(0,A.jsx)(`div`,{className:B.cardSub,children:`Core behaviour toggles`}),[[`verbose`,`Verbose logging (more diagnostics, more tokens)`,rt,it],[`immersive`,`Immersive office scene animation in Studio`,at,ot],[`knowledge`,`Knowledge base (memories + skills retrieval)`,st,ct]].map(([e,t,n,r])=>(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{Ct(`verbose`,rt),Ct(`immersive`,at),Ct(`knowledge`,st)},children:[It(`verbose`),` Save features`]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:`Integration tokens`}),(0,A.jsx)(`div`,{className:B.cardSub,children:`GitHub, Notion, Slack — used by the corresponding tools`}),(0,A.jsx)(Dt,{id:`githubToken`,label:`GitHub Token (PAT)`,placeholder:n.hasGithubToken?`✓ configured — leave empty to keep`:`ghp_... — needs repo + read:org scopes`,type:`password`,value:lt,onChange:ut}),(0,A.jsx)(Dt,{id:`githubRepo`,label:`Default GitHub repo (owner/name)`,placeholder:`acme/website`,value:dt,onChange:ft}),(0,A.jsx)(Dt,{id:`notionToken`,label:`Notion Token (Internal Integration)`,placeholder:n.hasNotionToken?`✓ configured — leave empty to keep`:`secret_...`,type:`password`,value:pt,onChange:mt}),(0,A.jsx)(Dt,{id:`slackToken`,label:`Slack Bot Token (xoxb-)`,placeholder:n.hasSlackToken?`✓ configured — leave empty to keep`:`xoxb-...`,type:`password`,value:ht,onChange:gt}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{lt&&Ct(`github-token`,lt),dt&&Ct(`github-repo`,dt),pt&&Ct(`notion-token`,pt),ht&&Ct(`slack-token`,ht)},children:[It(`github-token`),` Save tokens`]})]}),(0,A.jsx)(Ot,{}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:`Advanced`}),(0,A.jsx)(`div`,{className:B.cardSub,children:`Plugins, Microsoft tenant ID, runtime extras`}),(0,A.jsx)(`div`,{className:B.field,children:(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>yt(e.target.checked)}),` `,`Auto-run plugins at startup`]})}),(0,A.jsx)(Dt,{id:`pluginDir`,label:`Plugin directory (absolute path)`,placeholder:`empty = ~/.nha/plugins`,value:bt,onChange:xt}),(0,A.jsx)(Dt,{id:`microsoftTenant`,label:`Microsoft Tenant ID`,placeholder:`common (default) | organizations | consumers | <GUID>`,value:_t,onChange:vt}),(0,A.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{Ct(`plugin-autorun`,z),bt&&Ct(`plugin-dir`,bt),Ct(`microsoft-tenant`,_t)},children:[It(`plugin-autorun`),` Save advanced`]})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:t(`settings.googleAccount`)}),(0,A.jsx)(`div`,{className:B.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,A.jsxs)(`div`,{className:B.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,A.jsxs)(`div`,{className:B.btnRow,children:[(0,A.jsx)(`button`,{className:B.saveBtn,onClick:At,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,A.jsx)(`button`,{className:B.dangerBtn,onClick:jt,children:t(`settings.disconnectGoogle`)})]}),g&&(0,A.jsx)(`div`,{className:B.statusMsg,children:g})]}),(0,A.jsxs)(`div`,{className:B.card,children:[(0,A.jsxs)(`div`,{className:B.cardTitleRow,children:[(0,A.jsx)(`div`,{className:B.cardTitle,children:t(`settings.imapAccounts`)}),(0,A.jsx)(`button`,{className:B.saveBtn,onClick:()=>{p({...Et}),h(``)},children:t(`settings.addAccount`)})]}),(0,A.jsx)(`div`,{className:B.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,A.jsx)(`div`,{className:B.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,A.jsxs)(`div`,{className:B.imapRow,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{className:B.imapName,children:e.display_name}),(0,A.jsxs)(`div`,{className:B.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,A.jsxs)(`div`,{className:B.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,A.jsxs)(`div`,{className:B.imapBtns,children:[(0,A.jsx)(`button`,{className:B.imapSyncBtn,onClick:()=>Nt(e.id),children:t(`settings.sync`)}),(0,A.jsx)(`button`,{className:B.imapEditBtn,onClick:()=>{p({...Et,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,A.jsx)(`button`,{className:B.imapDelBtn,onClick:()=>Mt(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,A.jsxs)(`div`,{className:B.imapForm,children:[(0,A.jsx)(`div`,{className:B.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,A.jsx)(Dt,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,A.jsxs)(`div`,{className:B.field,children:[(0,A.jsxs)(`label`,{className:B.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,A.jsx)(`span`,{className:B.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,A.jsxs)(`div`,{className:B.pwdRow,children:[(0,A.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:B.fieldInput,style:{flex:1}}),(0,A.jsx)(`button`,{className:B.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,A.jsxs)(`div`,{className:B.btnRow,children:[(0,A.jsx)(`button`,{className:B.saveBtn,onClick:V,children:t(`common.save`)}),(0,A.jsx)(`button`,{className:B.cancelBtn,onClick:()=>Ft(!1),title:`Verifica IMAP+SMTP senza inviare nulla`,children:`Test connessione`}),(0,A.jsx)(`button`,{className:B.cancelBtn,onClick:()=>Ft(!0),title:`Invia un'email di prova alla tua casella per verificare il round-trip`,children:`Invia email di prova`}),(0,A.jsx)(`button`,{className:B.cancelBtn,onClick:Pt,title:`Diagnostica raw: mostra cosa risponde realmente il server sulla porta indicata`,children:`Diagnostica porta`}),(0,A.jsx)(`button`,{className:B.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,A.jsx)(`div`,{className:B.statusMsg,style:{whiteSpace:`pre-line`},children:m})]})]})]})}var At={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 jt(){let e=M(),[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),E(`/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 D(`/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}?`)&&D(`/api/birthdays/delete`,{contactId:e.contactId}).then(p)};return r?(0,A.jsxs)(`div`,{className:At.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,A.jsx)(`div`,{className:At.err,children:a}):(0,A.jsxs)(`div`,{className:At.root,children:[(0,A.jsxs)(`div`,{className:At.header,children:[(0,A.jsx)(`div`,{className:At.title,children:`Upcoming Birthdays`}),(0,A.jsx)(`button`,{className:At.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,A.jsxs)(`div`,{className:At.empty,children:[e(`birthdays.noBirthdays`),(0,A.jsx)(`br`,{}),(0,A.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,A.jsxs)(`div`,{className:`${At.card} ${r?At.cardToday:``}`,children:[(0,A.jsx)(`span`,{className:At.icon,children:`🎂`}),(0,A.jsxs)(`div`,{className:At.info,children:[(0,A.jsx)(`div`,{className:At.name,children:t.name}),(0,A.jsx)(`div`,{className:At.date,children:t.date})]}),(0,A.jsx)(`div`,{className:r?At.labelToday:i?At.labelTomorrow:At.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{className:At.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,A.jsx)(`button`,{className:At.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,A.jsx)(`div`,{className:At.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,A.jsxs)(`div`,{className:At.modal,children:[(0,A.jsx)(`div`,{className:At.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,A.jsx)(`label`,{className:At.label,children:`Name *`}),(0,A.jsx)(`input`,{className:At.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,A.jsx)(`label`,{className:At.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,A.jsx)(`input`,{className:At.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,A.jsx)(`div`,{className:At.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,A.jsx)(`div`,{className:At.formErr,children:l}),(0,A.jsxs)(`div`,{className:At.modalBtns,children:[(0,A.jsx)(`button`,{className:At.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,A.jsx)(`button`,{className:At.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var V={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`},Mt=[{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`}],Nt=[{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.`}],Pt=[{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 Ft(){let e=M(),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),E(`/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 D(`/api/cron/update`,{id:y,schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}):await D(`/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)},T=(e,t)=>D(`/api/cron/toggle`,{id:e,enabled:!t}).then(C),O=e=>{confirm(`Delete this scheduled task?`)&&D(`/api/cron/delete`,{id:e}).then(C)},re=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},k=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,A.jsxs)(`div`,{className:V.root,children:[(0,A.jsxs)(`div`,{className:V.header,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{className:V.title,children:`⏰ Scheduled Tasks`}),(0,A.jsxs)(`div`,{className:V.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,A.jsx)(`code`,{className:V.code,children:`nha ops start`})]})]}),(0,A.jsx)(`button`,{className:V.addBtn,onClick:w,children:`+ New Task`})]}),(0,A.jsxs)(`div`,{className:V.tabs,children:[(0,A.jsxs)(`button`,{className:`${V.tab} ${x===`jobs`?V.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,A.jsx)(`button`,{className:`${V.tab} ${x===`templates`?V.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,A.jsxs)(`div`,{className:V.templates,children:[(0,A.jsx)(`div`,{className:V.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),Nt.map(t=>(0,A.jsxs)(`div`,{className:V.templateCard,children:[(0,A.jsx)(`div`,{className:V.templateLabel,children:t.label}),(0,A.jsx)(`div`,{className:V.templatePrompt,children:t.prompt}),(0,A.jsxs)(`div`,{className:V.templateBtns,children:[(0,A.jsx)(`button`,{className:V.scheduleTplBtn,onClick:()=>k(t),children:`Schedule`}),(0,A.jsxs)(`button`,{className:V.runTplBtn,onClick:()=>re(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,A.jsxs)(A.Fragment,{children:[i&&(0,A.jsxs)(`div`,{className:V.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,A.jsx)(`div`,{className:V.err,children:o}),!i&&n.length===0&&!c&&(0,A.jsxs)(`div`,{className:V.empty,children:[(0,A.jsx)(`div`,{className:V.emptyIcon,children:`⏰`}),(0,A.jsxs)(`div`,{className:V.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,A.jsx)(`div`,{className:V.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,A.jsx)(`button`,{className:V.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,A.jsxs)(`div`,{className:`${V.card} ${e.enabled?``:V.cardDisabled}`,children:[(0,A.jsxs)(`div`,{className:V.cardTop,children:[(0,A.jsxs)(`div`,{className:V.cardLeft,children:[e.name&&(0,A.jsx)(`div`,{className:V.jobName,children:e.name}),(0,A.jsx)(`code`,{className:V.schedule,children:e.schedule}),e.agent&&(0,A.jsx)(`span`,{className:V.agentBadge,children:e.agent}),(0,A.jsx)(`span`,{className:`${V.statusBadge} ${e.enabled?V.statusActive:V.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,A.jsxs)(`div`,{className:V.cardActions,children:[(0,A.jsx)(`button`,{className:V.runBtn,onClick:()=>re(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,A.jsx)(`button`,{className:V.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,A.jsx)(`button`,{className:e.enabled?V.pauseBtn:V.resumeBtn,onClick:()=>T(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,A.jsx)(`button`,{className:V.delBtn,onClick:()=>O(e.id),children:`✕`})]})]}),(0,A.jsx)(`div`,{className:V.jobPrompt,children:e.prompt??e.command}),(0,A.jsxs)(`div`,{className:V.jobMeta,children:[e.runCount!==void 0&&(0,A.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,A.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,A.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,A.jsx)(`div`,{className:V.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,A.jsxs)(`div`,{className:V.formModal,children:[(0,A.jsx)(`div`,{className:V.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,A.jsx)(`label`,{className:V.label,children:`Name (optional)`}),(0,A.jsx)(`input`,{className:V.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,A.jsx)(`label`,{className:V.label,children:`Schedule *`}),(0,A.jsx)(`div`,{className:V.presets,children:Mt.map(e=>(0,A.jsx)(`button`,{className:`${V.preset} ${u.schedule===e.value?V.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,A.jsx)(`input`,{className:V.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,A.jsx)(`div`,{className:V.cronHints,children:Pt.map(e=>(0,A.jsxs)(`span`,{className:V.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,A.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,A.jsx)(`label`,{className:V.label,children:`Task / Prompt *`}),(0,A.jsx)(`textarea`,{className:V.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,A.jsx)(`label`,{className:V.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,A.jsx)(`input`,{className:V.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,A.jsx)(`div`,{className:V.formErr,children:m}),g&&(0,A.jsx)(`div`,{className:V.formOk,children:g}),(0,A.jsxs)(`div`,{className:V.formBtns,children:[(0,A.jsx)(`button`,{className:V.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,A.jsx)(`button`,{className:V.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var It={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 Lt(){let e=M(),[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=()=>E(`/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 D(`/api/notes`,{title:s||`Untitled`,content:l}):a&&await D(`/api/notes/${a.id}`,{title:s,content:l}),f(!1),m(!1),h()},b=(e,t)=>{confirm(`Delete note "${t}"?`)&&D(`/api/notes/${e}/delete`,{}).then(h)};return r?(0,A.jsxs)(`div`,{className:It.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,A.jsxs)(`div`,{className:It.root,children:[(0,A.jsxs)(`div`,{className:It.sidebar,children:[(0,A.jsx)(`button`,{className:It.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,A.jsx)(`div`,{className:It.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,A.jsxs)(`div`,{className:`${It.noteItem} ${a?.id===e.id?It.noteItemActive:``}`,onClick:()=>g(e),children:[(0,A.jsx)(`div`,{className:It.noteTitle,children:e.title||`Untitled`}),(0,A.jsx)(`div`,{className:It.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,A.jsx)(`div`,{className:It.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,A.jsx)(`div`,{className:It.noteTags,children:e.tags.map(e=>(0,A.jsx)(`span`,{className:It.noteTag,children:e},e))})]},e.id))]}),(0,A.jsx)(`div`,{className:It.editor,children:a||p?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`input`,{className:It.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,A.jsx)(`textarea`,{className:It.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,A.jsxs)(`div`,{className:It.editorFooter,children:[a&&(0,A.jsx)(`button`,{className:It.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,A.jsx)(`button`,{className:It.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,A.jsx)(`button`,{className:It.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,A.jsx)(`div`,{className:It.emptyEditor,children:`Select a note or create a new one`})})]})}var Rt={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`},zt={name:``,email:``,phone:``,company:``,address:``,notes:``};function Bt(){let e=M(),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=``)=>{E(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({...zt}),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 D(`/api/contacts/update`,{resourceName:u.resourceName,fields:f});if(e?.error){v(`Error: `+e.error);return}}else if(u)await D(`/api/contacts/update`,{resourceName:u.id,fields:f});else{let e=await D(`/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}"?`)&&D(`/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)},T=e=>(e||`?`).split(` `).map(e=>e[0]).slice(0,2).join(``).toUpperCase();return i?(0,A.jsxs)(`div`,{className:Rt.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,A.jsx)(`div`,{className:Rt.error,children:o}):(0,A.jsxs)(`div`,{className:Rt.root,children:[(0,A.jsxs)(`div`,{className:Rt.toolbar,children:[(0,A.jsx)(`input`,{className:Rt.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,A.jsxs)(`span`,{className:Rt.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,A.jsx)(`button`,{className:Rt.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,A.jsxs)(`div`,{className:Rt.empty,children:[e(`contacts.noContacts`),(0,A.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,A.jsx)(`div`,{className:Rt.grid,children:n.map(e=>(0,A.jsxs)(`div`,{className:Rt.card,onClick:()=>C(e),children:[(0,A.jsx)(`div`,{className:Rt.avatar,children:e.photo?(0,A.jsx)(`img`,{src:e.photo,alt:e.name,className:Rt.avatarImg}):T(e.name)}),(0,A.jsxs)(`div`,{className:Rt.info,children:[(0,A.jsx)(`div`,{className:Rt.name,children:e.name||`(no name)`}),(0,A.jsxs)(`div`,{className:Rt.row,children:[e.email&&(0,A.jsx)(`span`,{className:Rt.email,children:e.email}),e.phone&&(0,A.jsx)(`span`,{className:Rt.phone,children:e.phone}),e.company&&(0,A.jsxs)(`span`,{className:Rt.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,A.jsxs)(`span`,{className:Rt.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,A.jsxs)(`div`,{className:Rt.actions,children:[e.email&&(0,A.jsx)(`button`,{className:Rt.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,A.jsx)(`button`,{className:Rt.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,A.jsx)(`button`,{className:`${Rt.iconBtn} ${Rt.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,A.jsx)(`div`,{className:Rt.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,A.jsxs)(`div`,{className:Rt.modal,children:[(0,A.jsx)(`div`,{className:Rt.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,A.jsxs)(`div`,{className:Rt.field,children:[(0,A.jsx)(`label`,{className:Rt.label,children:t}),(0,A.jsx)(`input`,{className:Rt.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,A.jsx)(`div`,{className:g.startsWith(`Error`)?Rt.formError:Rt.formStatus,children:g}),(0,A.jsxs)(`div`,{className:Rt.modalBtns,children:[(0,A.jsx)(`button`,{className:Rt.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,A.jsx)(`button`,{className:Rt.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}function Vt({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,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:a,onClick:o?t:void 0,style:{position:`fixed`,inset:0,background:`rgba(0,0,0,0.55)`,zIndex:29}}),(0,A.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,A.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 Ht(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 H={root:`_root_1u6fr_2`,topbar:`_topbar_1u6fr_11`,topbarLeft:`_topbarLeft_1u6fr_20`,topbarTitle:`_topbarTitle_1u6fr_21`,topbarSub:`_topbarSub_1u6fr_22`,topbarActions:`_topbarActions_1u6fr_23`,runBtn:`_runBtn_1u6fr_25`,runBtnActive:`_runBtnActive_1u6fr_32`,logBtn:`_logBtn_1u6fr_34`,newWfBtn:`_newWfBtn_1u6fr_41`,body:`_body_1u6fr_50`,sidebar:`_sidebar_1u6fr_53`,sidebarTitle:`_sidebarTitle_1u6fr_61`,sidebarEmpty:`_sidebarEmpty_1u6fr_65`,wfItem:`_wfItem_1u6fr_67`,wfItemActive:`_wfItemActive_1u6fr_78`,wfItemRow:`_wfItemRow_1u6fr_79`,wfItemName:`_wfItemName_1u6fr_80`,wfItemMeta:`_wfItemMeta_1u6fr_81`,wfOn:`_wfOn_1u6fr_82`,wfOff:`_wfOff_1u6fr_83`,wfDelBtn:`_wfDelBtn_1u6fr_84`,canvasArea:`_canvasArea_1u6fr_92`,canvasHeader:`_canvasHeader_1u6fr_94`,wfNameInput:`_wfNameInput_1u6fr_99`,canvasHint:`_canvasHint_1u6fr_106`,portHint:`_portHint_1u6fr_107`,connectHint:`_connectHint_1u6fr_108`,cancelConnectBtn:`_cancelConnectBtn_1u6fr_109`,canvas:`_canvas_1u6fr_92`,canvasConnecting:`_canvasConnecting_1u6fr_122`,canvasSvg:`_canvasSvg_1u6fr_124`,canvasNode:`_canvasNode_1u6fr_134`,canvasNodeSelected:`_canvasNodeSelected_1u6fr_152`,canvasNodeConnecting:`_canvasNodeConnecting_1u6fr_153`,nodeIcon:`_nodeIcon_1u6fr_155`,nodeLabel:`_nodeLabel_1u6fr_156`,nodeConfigPreview:`_nodeConfigPreview_1u6fr_157`,nodeDelBtn:`_nodeDelBtn_1u6fr_159`,portOut:`_portOut_1u6fr_171`,portActive:`_portActive_1u6fr_182`,portIn:`_portIn_1u6fr_184`,pulse:`_pulse_1u6fr_1`,canvasDrop:`_canvasDrop_1u6fr_195`,canvasEmpty:`_canvasEmpty_1u6fr_203`,canvasEmptyIcon:`_canvasEmptyIcon_1u6fr_208`,canvasEmptyTitle:`_canvasEmptyTitle_1u6fr_209`,canvasEmptyDesc:`_canvasEmptyDesc_1u6fr_210`,logPanel:`_logPanel_1u6fr_213`,logHeader:`_logHeader_1u6fr_220`,logTime:`_logTime_1u6fr_226`,logClose:`_logClose_1u6fr_227`,logEmpty:`_logEmpty_1u6fr_228`,logStep:`_logStep_1u6fr_229`,logStepError:`_logStepError_1u6fr_230`,logStepHeader:`_logStepHeader_1u6fr_231`,logStepIcon:`_logStepIcon_1u6fr_232`,logStepLabel:`_logStepLabel_1u6fr_233`,logStepErrBadge:`_logStepErrBadge_1u6fr_234`,logStepErr:`_logStepErr_1u6fr_230`,logStepOutput:`_logStepOutput_1u6fr_236`,rightPanel:`_rightPanel_1u6fr_241`,configPanel:`_configPanel_1u6fr_252`,configHeader:`_configHeader_1u6fr_253`,configClose:`_configClose_1u6fr_254`,configDesc:`_configDesc_1u6fr_255`,configFields:`_configFields_1u6fr_256`,configField:`_configField_1u6fr_256`,configLabel:`_configLabel_1u6fr_258`,configRequired:`_configRequired_1u6fr_259`,configInput:`_configInput_1u6fr_260`,configTextarea:`_configTextarea_1u6fr_267`,zoomControls:`_zoomControls_1u6fr_277`,configHint:`_configHint_1u6fr_303`,configDelete:`_configDelete_1u6fr_305`,palette:`_palette_1u6fr_309`,paletteTitle:`_paletteTitle_1u6fr_310`,paletteTabs:`_paletteTabs_1u6fr_311`,paletteTab:`_paletteTab_1u6fr_311`,paletteTabActive:`_paletteTabActive_1u6fr_317`,paletteNodes:`_paletteNodes_1u6fr_318`,paletteDef:`_paletteDef_1u6fr_320`,paletteDefIcon:`_paletteDefIcon_1u6fr_328`,paletteDefLabel:`_paletteDefLabel_1u6fr_329`,paletteDefDesc:`_paletteDefDesc_1u6fr_330`,paletteFooter:`_paletteFooter_1u6fr_332`,paletteGuide:`_paletteGuide_1u6fr_336`,guideTitle:`_guideTitle_1u6fr_344`,guideStep:`_guideStep_1u6fr_353`,guideNum:`_guideNum_1u6fr_361`,guideTip:`_guideTip_1u6fr_377`,guideCode:`_guideCode_1u6fr_388`,nodeListMobile:`_nodeListMobile_1u6fr_432`,nodeRow:`_nodeRow_1u6fr_440`,nodeRowIcon:`_nodeRowIcon_1u6fr_453`,nodeRowBody:`_nodeRowBody_1u6fr_459`,nodeRowLabel:`_nodeRowLabel_1u6fr_463`,nodeRowDesc:`_nodeRowDesc_1u6fr_469`,nodeRowIndex:`_nodeRowIndex_1u6fr_476`,nodeRowBranch:`_nodeRowBranch_1u6fr_484`,configSheet:`_configSheet_1u6fr_492`,configSheetHandle:`_configSheetHandle_1u6fr_505`,runFab:`_runFab_1u6fr_515`},Ut=[{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:`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);
654
- 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`]}]}],Wt=Object.fromEntries(Ut.map(e=>[e.id,e])),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)(1),[y,b]=(0,_.useState)({x:0,y:0}),x=(0,_.useRef)(!1),S=Ht(),C=(0,_.useRef)({x:0,y:0,px:0,py:0}),w=(0,_.useRef)(null),ee=(0,_.useRef)(null),te=(0,_.useRef)(null),ne=(0,_.useCallback)(async()=>{let e=(await E(`/api/workflows`).catch(()=>null))?.workflows??[];t(e),r(t=>t?e.find(e=>e.id===t.id)??e[0]??null:e[0]??null)},[]);(0,_.useEffect)(()=>{ne()},[ne]);let T=(0,_.useCallback)(async e=>{r(e),t(t=>t.map(t=>t.id===e.id?e:t)),await D(`/api/workflows/${e.id}`,e,`PUT`).catch(()=>null)},[]),O=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:Ut},n=(await D(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},re=async e=>{confirm(`Delete this workflow?`)&&(await D(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),ne())},k=(0,_.useCallback)(e=>{e.preventDefault();let t=ee.current;if(!t||!n)return;let r=te.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:{}};T({...n,nodes:[...n.nodes,s]}),a(s.id),ee.current=null},[n,T]),ie=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||T({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(w.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,T]),j=(0,_.useCallback)(e=>{if(!w.current||!n)return;let{id:t,ox:i,oy:a}=w.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]),ae=(0,_.useCallback)(()=>{if(!w.current||!n){w.current=null;return}n.nodes.find(e=>e.id===w.current.id)&&T(n),w.current=null},[n,T]),oe=(0,_.useCallback)(e=>{n&&(T({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,T]),se=(0,_.useCallback)((e,t)=>{n&&T({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,T]),ce=(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]),le=(0,_.useCallback)(()=>{n&&T(n)},[n,T]),ue=async()=>{if(!(!n||c)){l(!0),p(!0),d([]);try{let e={...n,nodeDefs:Ut};await D(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null),d((await D(`/api/workflows/${n.id}/run`,{}))?.steps??[]),ne()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},M=async e=>{let i={...e,enabled:!e.enabled};await D(`/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)},N=n?.nodes.find(e=>e.id===i)??null,de=N?Wt[N.defId]:null;return(0,A.jsxs)(`div`,{className:H.root,children:[(0,A.jsxs)(`div`,{className:H.topbar,children:[(0,A.jsxs)(`div`,{className:H.topbarLeft,children:[(0,A.jsx)(`span`,{className:H.topbarTitle,children:`AWF - AutoWorkFlow`}),(0,A.jsx)(`span`,{className:H.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,A.jsxs)(`div`,{className:H.topbarActions,children:[n&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{className:`${H.runBtn} ${c?H.runBtnActive:``}`,onClick:ue,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,A.jsx)(`button`,{className:H.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,A.jsx)(`button`,{className:H.newWfBtn,onClick:O,children:`+ New Workflow`})]})]}),(0,A.jsxs)(`div`,{className:H.body,children:[(0,A.jsxs)(`div`,{className:H.sidebar,children:[(0,A.jsx)(`div`,{className:H.sidebarTitle,children:`Workflows`}),e.length===0&&(0,A.jsxs)(`div`,{className:H.sidebarEmpty,children:[`No workflows yet.`,(0,A.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,A.jsxs)(`div`,{className:`${H.wfItem} ${n?.id===e.id?H.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,A.jsxs)(`div`,{className:H.wfItemRow,children:[(0,A.jsx)(`span`,{className:H.wfItemName,children:e.name}),(0,A.jsx)(`button`,{className:e.enabled?H.wfOn:H.wfOff,onClick:t=>{t.stopPropagation(),M(e)},children:e.enabled?`ON`:`OFF`})]}),(0,A.jsxs)(`div`,{className:H.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,A.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,A.jsx)(`button`,{className:H.wfDelBtn,onClick:t=>{t.stopPropagation(),re(e.id)},children:`✕`})]},e.id))]}),(0,A.jsx)(`div`,{className:H.canvasArea,children:n?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:H.canvasHeader,children:[(0,A.jsx)(`input`,{className:H.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&T(n)}),o?(0,A.jsxs)(`span`,{className:H.connectHint,children:[`Click a target node to connect · `,(0,A.jsx)(`button`,{className:H.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,A.jsxs)(`span`,{className:H.canvasHint,children:[`Drag nodes from palette · Click `,(0,A.jsx)(`span`,{className:H.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,A.jsxs)(`div`,{ref:te,className:`${H.canvas} ${o?H.canvasConnecting:``}`,onMouseMove:e=>{if(x.current){b({x:C.current.px+(e.clientX-C.current.x),y:C.current.py+(e.clientY-C.current.y)});return}j(e)},onMouseDown:e=>{e.button===1&&(e.preventDefault(),x.current=!0,C.current={x:e.clientX,y:e.clientY,px:y.x,py:y.y})},onMouseUp:()=>{x.current=!1,ae()},onMouseLeave:()=>{x.current=!1,ae()},onWheel:e=>{if(e.preventDefault(),e.ctrlKey||e.metaKey){let t=e.deltaY>0?-.1:.1;v(e=>Math.max(.3,Math.min(2,e+t)))}else b(t=>({x:t.x-e.deltaX,y:t.y-e.deltaY}))},onDragOver:e=>e.preventDefault(),onDrop:k,onClick:()=>{o||a(null)},children:[(0,A.jsxs)(`div`,{className:H.zoomControls,children:[(0,A.jsx)(`button`,{onClick:()=>v(e=>Math.min(2,e+.1)),children:`+`}),(0,A.jsxs)(`span`,{children:[Math.round(g*100),`%`]}),(0,A.jsx)(`button`,{onClick:()=>v(e=>Math.max(.3,e-.1)),children:`−`}),(0,A.jsx)(`button`,{onClick:()=>{v(1),b({x:0,y:0})},children:`⊙`})]}),(0,A.jsxs)(`div`,{style:{transform:`translate(${y.x}px, ${y.y}px) scale(${g})`,transformOrigin:`0 0`,position:`absolute`,inset:0},children:[(0,A.jsx)(`svg`,{className:H.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,A.jsxs)(`g`,{children:[(0,A.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,A.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(),se(e.from,e.to)}}),(0,A.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(),se(e.from,e.to)}}),(0,A.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=Wt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,A.jsxs)(`div`,{className:`${H.canvasNode} ${n?H.canvasNodeSelected:``} ${r?H.canvasNodeConnecting:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>ie(t,e.id),onClick:e=>e.stopPropagation(),children:[(0,A.jsx)(`button`,{className:H.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),oe(e.id)},children:`✕`}),(0,A.jsx)(`span`,{className:H.nodeIcon,children:t.icon}),(0,A.jsx)(`span`,{className:H.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,A.jsx)(`span`,{className:H.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,A.jsx)(`button`,{className:`${H.portOut} ${r?H.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,A.jsx)(`button`,{className:H.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),ie(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,A.jsx)(`div`,{className:H.canvasDrop,children:`Drag nodes from the right panel and drop here`})]})]}),f&&(0,A.jsxs)(`div`,{className:H.logPanel,children:[(0,A.jsxs)(`div`,{className:H.logHeader,children:[(0,A.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,A.jsx)(`span`,{className:H.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,A.jsx)(`button`,{className:H.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,A.jsx)(`div`,{className:H.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,A.jsxs)(`div`,{className:`${H.logStep} ${e.error?H.logStepError:``}`,children:[(0,A.jsxs)(`div`,{className:H.logStepHeader,children:[(0,A.jsx)(`span`,{className:H.logStepIcon,children:e.nodeIcon}),(0,A.jsx)(`span`,{className:H.logStepLabel,children:e.nodeLabel}),e.error&&(0,A.jsx)(`span`,{className:H.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,A.jsx)(`div`,{className:H.logStepErr,children:e.error}),e.output&&(0,A.jsx)(`div`,{className:H.logStepOutput,dangerouslySetInnerHTML:{__html:xe(e.output.slice(0,500))}})]},t))]})]}):(0,A.jsxs)(`div`,{className:H.canvasEmpty,children:[(0,A.jsx)(`div`,{className:H.canvasEmptyIcon,children:`🔗`}),(0,A.jsx)(`div`,{className:H.canvasEmptyTitle,children:`Select or create a workflow`}),(0,A.jsxs)(`div`,{className:H.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,A.jsx)(`br`,{}),`Connect them by clicking the `,(0,A.jsx)(`span`,{className:H.portHint,children:`▶`}),` output port then the target node.`,(0,A.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,A.jsx)(`button`,{className:H.newWfBtn,onClick:O,children:`+ New Workflow`})]})}),(0,A.jsx)(`div`,{className:H.rightPanel,children:N&&de&&!S?Xt(N,de,ce,le,oe,a,H):(0,A.jsxs)(`div`,{className:H.palette,children:[(0,A.jsx)(`div`,{className:H.paletteTitle,children:`Node Palette`}),(0,A.jsx)(`div`,{className:H.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,A.jsx)(`button`,{className:`${H.paletteTab} ${m===e.id?H.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,A.jsx)(`div`,{className:H.paletteNodes,children:Ut.filter(e=>e.type===m).map(e=>(0,A.jsxs)(`div`,{className:H.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{ee.current=e.id},onDragEnd:()=>{ee.current=null},children:[(0,A.jsx)(`span`,{className:H.paletteDefIcon,children:e.icon}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{className:H.paletteDefLabel,style:{color:e.color},children:e.label}),(0,A.jsx)(`div`,{className:H.paletteDefDesc,children:e.description})]})]},e.id))}),(0,A.jsxs)(`div`,{className:H.paletteGuide,children:[(0,A.jsx)(`div`,{className:H.guideTitle,children:`How to use AWF`}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`1`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`2`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`3`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`4`}),(0,A.jsxs)(`span`,{children:[`Click the `,(0,A.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,A.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`5`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,A.jsx)(`code`,{className:H.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`6`}),(0,A.jsxs)(`span`,{children:[`Press `,(0,A.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,A.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,A.jsxs)(`div`,{className:H.guideTip,children:[(0,A.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,A.jsxs)(`div`,{className:H.guideTip,children:[(0,A.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,A.jsx)(`code`,{className:H.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]}),S&&n&&(0,A.jsxs)(`ul`,{className:H.nodeListMobile,children:[n.nodes.map((e,t)=>{let r=Wt[e.defId];if(!r)return null;let i=n.edges.filter(t=>t.from===e.id);return(0,A.jsxs)(`li`,{children:[(0,A.jsxs)(`div`,{className:H.nodeRow,onClick:()=>a(e.id),role:`button`,tabIndex:0,children:[(0,A.jsx)(`span`,{className:H.nodeRowIndex,children:t+1}),(0,A.jsx)(`span`,{className:H.nodeRowIcon,style:{color:r.color},children:r.icon}),(0,A.jsxs)(`div`,{className:H.nodeRowBody,children:[(0,A.jsx)(`div`,{className:H.nodeRowLabel,children:r.label}),(0,A.jsx)(`div`,{className:H.nodeRowDesc,children:r.description})]})]}),i.length>1&&r.outputs&&(0,A.jsx)(`div`,{className:H.nodeRowBranch,children:i.map((e,t)=>{let i=n.nodes.find(t=>t.id===e.to),a=i?Wt[i.defId]:null;return(0,A.jsxs)(`div`,{children:[`↳ `,e.label||(r.outputs?.[t]??``),` → `,a?.icon,` `,a?.label??`?`]},t)})})]},e.id)}),n.nodes.length===0&&(0,A.jsx)(`li`,{className:H.nodeRow,style:{justifyContent:`center`,color:`var(--dim)`},children:`Nessun nodo. Aggiungi triggers/actions dalla palette (apri il browser per editare).`})]}),S&&n&&n.nodes.length>0&&(0,A.jsx)(`button`,{className:H.runFab,onClick:ue,disabled:c,"aria-label":`Run workflow`,title:`Esegui workflow`,children:c?`⏳`:`▶`}),S&&(0,A.jsx)(Vt,{open:!!(N&&de),onClose:()=>a(null),className:H.configSheet,handleClassName:H.configSheetHandle,ariaLabel:`Node configuration`,children:N&&de&&Xt(N,de,ce,le,oe,a,H)})]})}function Xt(e,t,n,r,i,a,o){return(0,A.jsxs)(`div`,{className:o.configPanel,children:[(0,A.jsxs)(`div`,{className:o.configHeader,children:[(0,A.jsxs)(`span`,{style:{color:t.color},children:[t.icon,` `,t.label]}),(0,A.jsx)(`button`,{className:o.configClose,onClick:()=>a(null),children:`✕`})]}),(0,A.jsx)(`div`,{className:o.configDesc,children:t.description}),(0,A.jsx)(`div`,{className:o.configFields,children:(t.configFields??[]).map(t=>(0,A.jsxs)(`div`,{className:o.configField,children:[(0,A.jsxs)(`label`,{className:o.configLabel,children:[t.label,t.required&&(0,A.jsx)(`span`,{className:o.configRequired,children:`*`})]}),t.type===`textarea`?(0,A.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,A.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,A.jsx)(`option`,{value:e,children:e},e))}):(0,A.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}),(t.placeholder?.includes(`{{`)??!1)&&(0,A.jsxs)(`div`,{className:o.configHint,children:[`Use `,(0,A.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},t.key))}),(0,A.jsx)(`button`,{className:o.configDelete,onClick:()=>i(e.id),children:`Delete node`})]})}var U={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`},Zt=[{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:`🗑`}],Qt=[{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 $t(e){return e?e.slice(0,10):``}function en(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 tn(){let e=M(),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),[T,O]=(0,_.useState)(!1),[re,k]=(0,_.useState)(``),[ie,j]=(0,_.useState)(``),[ae,oe]=(0,_.useState)(0),[se,ce]=(0,_.useState)(!1),[le,ue]=(0,_.useState)({}),[N,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(``),[me,he]=(0,_.useState)(``),[ge,_e]=(0,_.useState)(``),[ve,ye]=(0,_.useState)(``),[be,xe]=(0,_.useState)(!1),[P,Se]=(0,_.useState)(``),[Ce,we]=(0,_.useState)(!1),Te=(0,_.useRef)(null),F=(0,_.useRef)(0),Ee=[{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`}],[De,Oe]=(0,_.useState)(()=>{let e=parseInt(localStorage.getItem(`nha-email-refresh-sec`)||`600`,10);return Number.isFinite(e)?e:600}),[I,L]=(0,_.useState)(!1),[ke,Ae]=(0,_.useState)(null),[je,Me]=(0,_.useState)(null),[Ne,Pe]=(0,_.useState)(Date.now()),Fe=(0,_.useRef)(!1),Ie=e=>{Oe(e),localStorage.setItem(`nha-email-refresh-sec`,String(e))},Le=async()=>{if(!Fe.current&&o){Fe.current=!0,L(!0);try{c===`imap`?(await D(`/api/imap/sync/${o}`,{}).catch(()=>{}),o&&ze(o,f,0,re)):c===`google`&&Be(f||`INBOX`,re),Ae(Date.now())}finally{Fe.current=!1,L(!1)}}};(0,_.useEffect)(()=>{if(!De||!o){Me(null);return}Me(Date.now()+De*1e3);let e=setInterval(()=>{document.visibilityState!==`hidden`&&(Le(),Me(Date.now()+De*1e3))},De*1e3);return()=>clearInterval(e)},[De,o,c,f]),(0,_.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&(!De||!o||(ke?Date.now()-ke:1/0)>=De*1e3&&(Le(),Me(Date.now()+De*1e3)))};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[De,o,ke]),(0,_.useEffect)(()=>{if(!je)return;let e=setInterval(()=>Pe(Date.now()),1e3);return()=>clearInterval(e)},[je]);let Re=(()=>{if(!je||!De)return null;let e=Math.max(0,Math.round((je-Ne)/1e3));return`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`})();(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle)),E(`/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`?R(`google`,`google`):n===`imap`&&r&&t.some(e=>e.id===r)?R(r,`imap`):t.length>0?R(t[0].id,`imap`):R(`google`,`google`)})},[]);let R=(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`?E(`/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),ze(e,r,0,``)}):(d([]),Be(`INBOX`,``))},ze=(e,t,n,r)=>{let i=++F.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)}`),E(a).then(e=>{i===F.current&&(h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),te(!1))}).catch(()=>{i===F.current&&te(!1)})},Be=(e,t)=>{te(!0);let n=e||`INBOX`;E(`/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`&&oe(e.filter(e=>!e.is_read).length)}else h([]),v(0);te(!1)}).catch(()=>{h([]),te(!1)})},Ve=()=>{k(ie),b(0),h([]),c===`imap`&&o?ze(o,f,0,ie):Be(f||`INBOX`,ie)},He=e=>{S(e),ce(!1),O(!0),c===`google`?E(`/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)),O(!1)):D(`/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)),D(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}O(!1)}).catch(()=>O(!1))}).catch(()=>O(!1)):E(`/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)),O(!1)}).catch(()=>O(!1))},Ue=(e={})=>{ce(!0),ue(e),de(e.to??``),pe(``),he(e.subject??``),_e(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),ye(``),xe(!1),S(null),w(null)},We=async()=>{if(!N.trim()){ye(`Recipient required`);return}ye(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:N.trim(),cc:fe.trim()||void 0,subject:me.trim(),bodyHtml:ge.replace(/\n/g,`<br>`),bodyText:ge,inReplyTo:le.inReplyTo||void 0});e?.ok?(ye(`Sent!`),setTimeout(()=>ce(!1),800)):ye(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:N.trim(),subject:me.trim(),body:ge});e?.ok||e?.id?(ye(`Sent!`),setTimeout(()=>ce(!1),800)):ye(e?.error??`Error`)}}catch(e){ye(e.message??`Error`)}},Ge=e=>{confirm(`Move to trash? Email stays on the server.`)&&D(`/api/imap/trash`,{messageId:e}).then(()=>{h(t=>t.filter(t=>t.id!==e)),w(null),S(null)})},Ke=(e,t)=>{D(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},qe=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Je=()=>{!P.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:P.trim()}).then(()=>{we(!1),Se(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})},Ye=()=>{if(c===`google`){te(!0);let e=f||`INBOX`,t=m.length+50;E(`/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&&ze(o,f,e,re)}};return(0,A.jsxs)(`div`,{className:U.root,children:[(0,A.jsxs)(`div`,{className:U.sidebar,children:[(0,A.jsxs)(`div`,{className:U.sidebarSection,children:[(0,A.jsx)(`div`,{className:U.sidebarLabel,children:`Account`}),(0,A.jsxs)(`select`,{className:U.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?R(`google`,`google`):t.startsWith(`imap:`)&&R(t.slice(5),`imap`)},children:[n&&(0,A.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,A.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,A.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,A.jsx)(`div`,{className:U.sidebarCompose,children:(0,A.jsx)(`button`,{className:U.composeBtn,onClick:()=>Ue(),children:`+ Compose`})}),(0,A.jsx)(`div`,{className:U.folderList,children:c===`google`?Zt.map(e=>(0,A.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Be(e.id,re)},children:[(0,A.jsx)(`span`,{children:e.icon}),(0,A.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&ae>0&&(0,A.jsx)(`span`,{className:U.badge,children:ae})]},e.id)):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:U.labelHeader,children:[(0,A.jsx)(`span`,{children:`Labels`}),(0,A.jsx)(`button`,{className:U.addLabelBtn,onClick:()=>we(e=>!e),children:`+`})]}),Ce&&(0,A.jsxs)(`div`,{className:U.newLabelRow,children:[(0,A.jsx)(`input`,{className:U.newLabelInput,value:P,onChange:e=>Se(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Je()}),(0,A.jsx)(`button`,{className:U.newLabelSave,onClick:Je,children:`+`})]}),u.map(e=>(0,A.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&ze(o,e.id,0,re)},children:[(0,A.jsx)(`span`,{className:U.labelDot,style:{background:e.color??`var(--dim)`}}),(0,A.jsx)(`span`,{children:e.name}),e.system_type===`inbox`&&e.unread_count?(0,A.jsx)(`span`,{className:U.badge,children:e.unread_count}):null]},e.id))]})}),o&&(0,A.jsxs)(`div`,{className:U.syncArea,children:[(0,A.jsx)(`button`,{className:U.syncBtn,onClick:Le,disabled:I,title:ke?`Ultimo sync: ${new Date(ke).toLocaleTimeString()}`:`Mai sincronizzato`,children:I?`⟳ Sync…`:`Sync ora`}),(0,A.jsx)(`select`,{className:U.refreshSelect,value:De,onChange:e=>Ie(parseInt(e.target.value,10)),title:`Intervallo di aggiornamento automatico`,children:Ee.map(e=>(0,A.jsx)(`option`,{value:e.sec,children:e.label},e.sec))}),Re&&(0,A.jsxs)(`span`,{className:U.refreshCountdown,title:`Prossimo refresh tra`,children:[`⏱ `,Re]})]})]}),(0,A.jsxs)(`div`,{className:U.messageList,children:[(0,A.jsxs)(`div`,{className:U.listHeader,children:[(0,A.jsx)(`input`,{className:U.searchInput,value:ie,onChange:e=>j(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&Ve()}),(0,A.jsx)(`button`,{className:U.searchBtn,onClick:Ve,children:`Go`})]}),(0,A.jsxs)(`div`,{className:U.listBody,children:[ee&&(0,A.jsx)(`div`,{className:U.listLoading,children:(0,A.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,A.jsx)(`div`,{className:U.noMessages,children:`No messages`}),m.map(e=>(0,A.jsxs)(`div`,{className:`${U.msgRow} ${e.id===x?U.msgActive:``} ${e.is_read?``:U.msgUnread}`,onClick:()=>He(e.id),children:[(0,A.jsxs)(`div`,{className:U.msgTop,children:[(0,A.jsx)(`span`,{className:U.msgFrom,children:e.from_name||e.from_address||``}),(0,A.jsx)(`span`,{className:U.msgDate,children:$t(e.internal_date)})]}),(0,A.jsx)(`div`,{className:U.msgSubject,children:e.subject||`(no subject)`}),(0,A.jsx)(`div`,{className:U.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,A.jsxs)(`div`,{className:U.listFooter,children:[(0,A.jsxs)(`span`,{children:[g,` messages`]}),c===`imap`&&m.length<g&&(0,A.jsx)(`button`,{className:U.loadMoreBtn,onClick:Ye,children:`Load more`}),c===`google`&&m.length>=50&&(0,A.jsx)(`button`,{className:U.loadMoreBtn,onClick:Ye,disabled:ee,children:ee?`Loading...`:`Scarica altre`})]})]}),(0,A.jsx)(`div`,{className:U.pane,children:(()=>{if(se)return(0,A.jsxs)(`div`,{className:U.composePane,children:[(0,A.jsx)(`div`,{className:U.composeTitle,children:e(`email.compose`)}),(0,A.jsx)(`input`,{className:U.composeField,value:N,onChange:e=>de(e.target.value),placeholder:`To`}),(0,A.jsx)(`input`,{className:U.composeField,value:fe,onChange:e=>pe(e.target.value),placeholder:`Cc`}),(0,A.jsx)(`input`,{className:U.composeField,value:me,onChange:e=>he(e.target.value),placeholder:`Subject`}),(0,A.jsxs)(`div`,{className:U.templateRow,children:[(0,A.jsx)(`button`,{className:U.templateToggle,onClick:()=>xe(e=>!e),children:`📄 Templates`}),be&&(0,A.jsx)(`div`,{className:U.templateDrop,children:Qt.map((e,t)=>(0,A.jsxs)(`div`,{className:U.templateItem,onClick:()=>{he(t=>t||e.subject),xe(!1)},children:[(0,A.jsx)(`strong`,{children:e.name}),(0,A.jsx)(`div`,{className:U.templateSubject,children:e.subject})]},t))})]}),(0,A.jsx)(`textarea`,{className:U.composeBody,value:ge,onChange:e=>_e(e.target.value),placeholder:`Write your message…`}),(0,A.jsxs)(`div`,{className:U.composeActions,children:[(0,A.jsx)(`button`,{className:U.sendBtn,onClick:We,children:e(`email.send_ok`)}),(0,A.jsx)(`button`,{className:U.cancelBtn,onClick:()=>ce(!1),children:`Discard`}),ve&&(0,A.jsx)(`span`,{className:`${U.compStatus} ${ve===`Sent!`?U.ok:U.err}`,children:ve})]})]});if(T)return(0,A.jsx)(`div`,{className:U.emptyPane,children:(0,A.jsx)(`div`,{className:`spinner`})});if(!C)return(0,A.jsx)(`div`,{className:U.emptyPane,children:`Select a message`});let n=en(C.to_addresses);return(0,A.jsxs)(`div`,{className:U.readingPane,children:[(0,A.jsx)(`div`,{className:U.paneToolbar,children:(0,A.jsxs)(`div`,{className:U.paneActions,children:[(0,A.jsx)(`button`,{className:U.replyBtn,onClick:()=>Ue({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,A.jsx)(`button`,{className:U.fwdBtn,onClick:()=>Ue({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{className:U.trashBtn,onClick:()=>Ge(C.id),children:`🗑`}),(0,A.jsx)(`button`,{className:U.starBtn,onClick:()=>Ke(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,A.jsxs)(`select`,{className:U.labelSelect,defaultValue:``,onChange:e=>qe(C.id,e.target.value),children:[(0,A.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,A.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,A.jsx)(`button`,{className:U.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,A.jsxs)(`div`,{className:U.paneHeader,children:[(0,A.jsx)(`div`,{className:U.paneSubject,children:C.subject||`(no subject)`}),(0,A.jsxs)(`div`,{className:U.paneMeta,children:[(0,A.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,A.jsxs)(`div`,{className:U.paneMeta,children:[(0,A.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,A.jsxs)(`div`,{className:U.paneMeta,children:[(0,A.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,A.jsx)(`div`,{className:U.attachments,children:C.attachments.map((e,t)=>(0,A.jsxs)(`a`,{className:U.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,A.jsx)(`div`,{className:U.paneBody,children:C.body_html?(0,A.jsx)(`iframe`,{ref:Te,sandbox:`allow-same-origin`,className:U.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,A.jsx)(`pre`,{className:U.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var W={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 nn(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function rn(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function an(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 on(){let e=M(),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)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle))},[]);let S=(0,_.useCallback)((e,t)=>{let n=`${e}-${String(t+1).padStart(2,`0`)}`;f(!0),E(`/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=>{E(`/api/calendar?date=${e}`).then(t=>{u(n=>({...n,[e]:t?.events??[]}))})},w=(e,t,n)=>{confirm(`Delete this event?`)&&D(`/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(``)},T=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 D(`/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 D(`/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,A.jsx)(`div`,{className:W.center,children:(0,A.jsx)(`div`,{className:`spinner`})});if(!n)return(0,A.jsx)(`div`,{className:W.center,children:(0,A.jsxs)(`div`,{className:W.noGoogle,children:[(0,A.jsx)(`div`,{className:W.noGoogleIcon,children:`📅`}),(0,A.jsx)(`div`,{className:W.noGoogleTitle,children:`Calendar`}),(0,A.jsx)(`div`,{className:W.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,A.jsx)(`button`,{className:W.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let O=new Date(a,s,1).getDay(),re=new Date(a,s+1,0).getDate(),k=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ie=(O+6)%7,j=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],ae=p?l[p]??[]:[];return(0,A.jsxs)(`div`,{className:W.root,children:[(0,A.jsxs)(`div`,{className:W.calCol,children:[(0,A.jsxs)(`div`,{className:W.navRow,children:[(0,A.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,A.jsx)(`div`,{className:W.monthTitle,children:k}),(0,A.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,A.jsx)(`div`,{className:W.dayHeaders,children:j.map((e,t)=>(0,A.jsx)(`div`,{className:`${W.dayHeader} ${t>=5?W.weekend:``}`,children:e},e))}),(0,A.jsxs)(`div`,{className:W.grid,children:[Array.from({length:ie}).map((e,t)=>(0,A.jsx)(`div`,{className:`${W.cell} ${W.emptyCell} ${t>=5?W.weekendCell:``}`},`e${t}`)),Array.from({length:re}).map((e,t)=>{let n=t+1,r=nn(a,s,n),i=rn(a,s,n),o=l[r]??[],c=o.length,u=(ie+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,A.jsxs)(`div`,{className:`${W.cell} ${i?W.todayCell:u?W.weekendCell:``} ${f?W.activeCell:``} ${d?W.holidayCell:c>0?W.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,A.jsx)(`div`,{className:`${W.dayNum} ${i?W.todayNum:u?W.weekendNum:``}`,children:n}),c>0&&(0,A.jsxs)(`div`,{className:W.evtPills,children:[o.slice(0,2).map((e,t)=>(0,A.jsx)(`div`,{className:`${W.evtPill} ${e._isHoliday||e.readOnly?W.holidayPill:``}`,children:e.summary},t)),c>2&&(0,A.jsxs)(`div`,{className:W.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,A.jsx)(`div`,{className:W.loadingBar,children:`Loading events…`})]}),(0,A.jsx)(`div`,{className:W.detailCol,children:p?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:W.detailHeader,children:[(0,A.jsx)(`div`,{className:W.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,A.jsx)(`button`,{className:W.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),ae.length===0?(0,A.jsx)(`div`,{className:W.noEvts,children:`No events on this day`}):ae.map((t,n)=>{let r=t.isAllDay?`All day`:`${an(t.start)} - ${an(t.end)}`,i=t.calendarId??`primary`;return(0,A.jsxs)(`div`,{className:W.evtCard,children:[(0,A.jsxs)(`div`,{className:W.evtTop,children:[(0,A.jsx)(`div`,{className:W.evtTime,children:r}),t.id&&!t.readOnly&&(0,A.jsxs)(`div`,{className:W.evtBtns,children:[(0,A.jsx)(`button`,{className:W.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,A.jsx)(`button`,{className:W.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,A.jsx)(`span`,{className:W.readOnly,children:`read-only`})]}),(0,A.jsx)(`div`,{className:W.evtTitle,children:t.summary}),t.location&&(0,A.jsxs)(`div`,{className:W.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,A.jsxs)(`div`,{className:W.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,A.jsxs)(`div`,{className:W.attendees,children:[(0,A.jsx)(`div`,{className:W.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,A.jsxs)(`div`,{className:W.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,A.jsx)(`div`,{className:W.evtDesc,children:t.description}),t.hangoutLink&&(0,A.jsx)(`a`,{className:W.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,A.jsx)(`a`,{className:W.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,A.jsxs)(`div`,{className:W.selectDay,children:[`Click a day to see events, edit or delete them.`,(0,A.jsx)(`br`,{}),(0,A.jsx)(`br`,{}),`Use `,(0,A.jsx)(`strong`,{children:`+ Add Event`}),` to create a new event — it syncs with Google Calendar.`]})}),h&&(0,A.jsx)(`div`,{className:W.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,A.jsxs)(`div`,{className:W.formCard,children:[(0,A.jsx)(`div`,{className:W.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Title *`}),(0,A.jsx)(`input`,{className:W.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Start`}),(0,A.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,A.jsx)(`label`,{className:W.formLabel,children:`End`}),(0,A.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Location`}),(0,A.jsx)(`input`,{className:W.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Description`}),(0,A.jsx)(`textarea`,{className:W.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,A.jsx)(`div`,{className:W.formError,children:v}),(0,A.jsxs)(`div`,{className:W.formBtns,children:[(0,A.jsx)(`button`,{className:W.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,A.jsx)(`button`,{className:W.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var G={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`},sn={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 cn(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=sn[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 ln(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function un(){let e=M(),[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),T=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),k=(0,_.useRef)(new Map),ie=(0,_.useRef)(new Map),j=(0,_.useRef)(new Map),ae=(0,_.useRef)(null),oe=()=>{E(`/api/agents`).then(e=>{n((e?.agents??[]).map(cn)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{oe()},[]);let se=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],ce=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))}),le=e=>{u(t=>{let n=t.findIndex(t=>t.agent.id===e.id);return n>=0?(O.current.get(e.id)?.abort(),O.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,ln(e)]})},ue=e=>{O.current.get(e)?.abort(),O.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},N=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},de=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},fe=(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}}))},pe=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;de(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),N(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 D(`/api/chat`,e);de(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{de(i,{role:`assistant`,content:`Error sending attachment.`})}N(i,{streaming:!1});return}de(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;O.current.set(i,o);let s=``;try{await re(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,fe(i,s);let t=k.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{N(i,{streaming:!1}),O.current.delete(i)}},me=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;de(r,{role:`user`,content:e}),N(r,{streaming:!0});let i=``,a=new AbortController;O.current.set(r,a),de(r,{role:`assistant`,content:``,streaming:!0});try{await re(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,fe(r,i);let t=k.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{N(r,{streaming:!1}),O.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(`
654
+ 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`]}]}],Wt=Object.fromEntries(Ut.map(e=>[e.id,e])),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)(1),[y,b]=(0,_.useState)({x:0,y:0}),x=(0,_.useRef)(!1),S=Ht(),C=(0,_.useRef)({x:0,y:0,px:0,py:0}),w=(0,_.useRef)(null),ee=(0,_.useRef)(null),te=(0,_.useRef)(null),ne=(0,_.useCallback)(async()=>{let e=(await E(`/api/workflows`).catch(()=>null))?.workflows??[];t(e),r(t=>t?e.find(e=>e.id===t.id)??e[0]??null:e[0]??null)},[]);(0,_.useEffect)(()=>{ne()},[ne]);let T=(0,_.useCallback)(async e=>{r(e),t(t=>t.map(t=>t.id===e.id?e:t)),await D(`/api/workflows/${e.id}`,e,`PUT`).catch(()=>null)},[]),O=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:Ut},n=(await D(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},re=async e=>{confirm(`Delete this workflow?`)&&(await D(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),ne())},k=(0,_.useCallback)(e=>{e.preventDefault();let t=ee.current;if(!t||!n)return;let r=te.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:{}};T({...n,nodes:[...n.nodes,s]}),a(s.id),ee.current=null},[n,T]),ie=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||T({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(w.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,T]),j=(0,_.useCallback)(e=>{if(!w.current||!n)return;let{id:t,ox:i,oy:a}=w.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]),ae=(0,_.useCallback)(()=>{if(!w.current||!n){w.current=null;return}n.nodes.find(e=>e.id===w.current.id)&&T(n),w.current=null},[n,T]),oe=(0,_.useCallback)(e=>{n&&(T({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,T]),se=(0,_.useCallback)((e,t)=>{n&&T({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,T]),ce=(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]),le=(0,_.useCallback)(()=>{n&&T(n)},[n,T]),ue=async()=>{if(!(!n||c)){l(!0),p(!0),d([]);try{let e={...n,nodeDefs:Ut};await D(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null),d((await D(`/api/workflows/${n.id}/run`,{}))?.steps??[]),ne()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},M=async e=>{let i={...e,enabled:!e.enabled};await D(`/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)},N=n?.nodes.find(e=>e.id===i)??null,de=N?Wt[N.defId]:null;return(0,A.jsxs)(`div`,{className:H.root,children:[(0,A.jsxs)(`div`,{className:H.topbar,children:[(0,A.jsxs)(`div`,{className:H.topbarLeft,children:[(0,A.jsx)(`span`,{className:H.topbarTitle,children:`AWF - AutoWorkFlow`}),(0,A.jsx)(`span`,{className:H.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,A.jsxs)(`div`,{className:H.topbarActions,children:[n&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{className:`${H.runBtn} ${c?H.runBtnActive:``}`,onClick:ue,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,A.jsx)(`button`,{className:H.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,A.jsx)(`button`,{className:H.newWfBtn,onClick:O,children:`+ New Workflow`})]})]}),(0,A.jsxs)(`div`,{className:H.body,children:[(0,A.jsxs)(`div`,{className:H.sidebar,children:[(0,A.jsx)(`div`,{className:H.sidebarTitle,children:`Workflows`}),e.length===0&&(0,A.jsxs)(`div`,{className:H.sidebarEmpty,children:[`No workflows yet.`,(0,A.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,A.jsxs)(`div`,{className:`${H.wfItem} ${n?.id===e.id?H.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,A.jsxs)(`div`,{className:H.wfItemRow,children:[(0,A.jsx)(`span`,{className:H.wfItemName,children:e.name}),(0,A.jsx)(`button`,{className:e.enabled?H.wfOn:H.wfOff,onClick:t=>{t.stopPropagation(),M(e)},children:e.enabled?`ON`:`OFF`})]}),(0,A.jsxs)(`div`,{className:H.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,A.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,A.jsx)(`button`,{className:H.wfDelBtn,onClick:t=>{t.stopPropagation(),re(e.id)},children:`✕`})]},e.id))]}),(0,A.jsx)(`div`,{className:H.canvasArea,children:n?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:H.canvasHeader,children:[(0,A.jsx)(`input`,{className:H.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&T(n)}),o?(0,A.jsxs)(`span`,{className:H.connectHint,children:[`Click a target node to connect · `,(0,A.jsx)(`button`,{className:H.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,A.jsxs)(`span`,{className:H.canvasHint,children:[`Drag nodes from palette · Click `,(0,A.jsx)(`span`,{className:H.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,A.jsxs)(`div`,{ref:te,className:`${H.canvas} ${o?H.canvasConnecting:``}`,onMouseMove:e=>{if(x.current){b({x:C.current.px+(e.clientX-C.current.x),y:C.current.py+(e.clientY-C.current.y)});return}j(e)},onMouseDown:e=>{e.button===1&&(e.preventDefault(),x.current=!0,C.current={x:e.clientX,y:e.clientY,px:y.x,py:y.y})},onMouseUp:()=>{x.current=!1,ae()},onMouseLeave:()=>{x.current=!1,ae()},onWheel:e=>{if(e.preventDefault(),e.ctrlKey||e.metaKey){let t=e.deltaY>0?-.1:.1;v(e=>Math.max(.3,Math.min(2,e+t)))}else b(t=>({x:t.x-e.deltaX,y:t.y-e.deltaY}))},onDragOver:e=>e.preventDefault(),onDrop:k,onClick:()=>{o||a(null)},children:[(0,A.jsxs)(`div`,{className:H.zoomControls,children:[(0,A.jsx)(`button`,{onClick:()=>v(e=>Math.min(2,e+.1)),children:`+`}),(0,A.jsxs)(`span`,{children:[Math.round(g*100),`%`]}),(0,A.jsx)(`button`,{onClick:()=>v(e=>Math.max(.3,e-.1)),children:`−`}),(0,A.jsx)(`button`,{onClick:()=>{v(1),b({x:0,y:0})},children:`⊙`})]}),(0,A.jsxs)(`div`,{style:{transform:`translate(${y.x}px, ${y.y}px) scale(${g})`,transformOrigin:`0 0`,position:`absolute`,inset:0},children:[(0,A.jsx)(`svg`,{className:H.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,A.jsxs)(`g`,{children:[(0,A.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,A.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(),se(e.from,e.to)}}),(0,A.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(),se(e.from,e.to)}}),(0,A.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=Wt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,A.jsxs)(`div`,{className:`${H.canvasNode} ${n?H.canvasNodeSelected:``} ${r?H.canvasNodeConnecting:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>ie(t,e.id),onClick:e=>e.stopPropagation(),children:[(0,A.jsx)(`button`,{className:H.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),oe(e.id)},children:`✕`}),(0,A.jsx)(`span`,{className:H.nodeIcon,children:t.icon}),(0,A.jsx)(`span`,{className:H.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,A.jsx)(`span`,{className:H.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,A.jsx)(`button`,{className:`${H.portOut} ${r?H.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,A.jsx)(`button`,{className:H.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),ie(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,A.jsx)(`div`,{className:H.canvasDrop,children:`Drag nodes from the right panel and drop here`})]})]}),f&&(0,A.jsxs)(`div`,{className:H.logPanel,children:[(0,A.jsxs)(`div`,{className:H.logHeader,children:[(0,A.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,A.jsx)(`span`,{className:H.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,A.jsx)(`button`,{className:H.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,A.jsx)(`div`,{className:H.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,A.jsxs)(`div`,{className:`${H.logStep} ${e.error?H.logStepError:``}`,children:[(0,A.jsxs)(`div`,{className:H.logStepHeader,children:[(0,A.jsx)(`span`,{className:H.logStepIcon,children:e.nodeIcon}),(0,A.jsx)(`span`,{className:H.logStepLabel,children:e.nodeLabel}),e.error&&(0,A.jsx)(`span`,{className:H.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,A.jsx)(`div`,{className:H.logStepErr,children:e.error}),e.output&&(0,A.jsx)(`div`,{className:H.logStepOutput,dangerouslySetInnerHTML:{__html:xe(e.output.slice(0,500))}})]},t))]})]}):(0,A.jsxs)(`div`,{className:H.canvasEmpty,children:[(0,A.jsx)(`div`,{className:H.canvasEmptyIcon,children:`🔗`}),(0,A.jsx)(`div`,{className:H.canvasEmptyTitle,children:`Select or create a workflow`}),(0,A.jsxs)(`div`,{className:H.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,A.jsx)(`br`,{}),`Connect them by clicking the `,(0,A.jsx)(`span`,{className:H.portHint,children:`▶`}),` output port then the target node.`,(0,A.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,A.jsx)(`button`,{className:H.newWfBtn,onClick:O,children:`+ New Workflow`})]})}),(0,A.jsx)(`div`,{className:H.rightPanel,children:N&&de&&!S?Xt(N,de,ce,le,oe,a,H):(0,A.jsxs)(`div`,{className:H.palette,children:[(0,A.jsx)(`div`,{className:H.paletteTitle,children:`Node Palette`}),(0,A.jsx)(`div`,{className:H.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,A.jsx)(`button`,{className:`${H.paletteTab} ${m===e.id?H.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,A.jsx)(`div`,{className:H.paletteNodes,children:Ut.filter(e=>e.type===m).map(e=>(0,A.jsxs)(`div`,{className:H.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{ee.current=e.id},onDragEnd:()=>{ee.current=null},children:[(0,A.jsx)(`span`,{className:H.paletteDefIcon,children:e.icon}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{className:H.paletteDefLabel,style:{color:e.color},children:e.label}),(0,A.jsx)(`div`,{className:H.paletteDefDesc,children:e.description})]})]},e.id))}),(0,A.jsxs)(`div`,{className:H.paletteGuide,children:[(0,A.jsx)(`div`,{className:H.guideTitle,children:`How to use AWF`}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`1`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`2`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`3`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`4`}),(0,A.jsxs)(`span`,{children:[`Click the `,(0,A.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,A.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`5`}),(0,A.jsxs)(`span`,{children:[(0,A.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,A.jsx)(`code`,{className:H.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,A.jsxs)(`div`,{className:H.guideStep,children:[(0,A.jsx)(`span`,{className:H.guideNum,children:`6`}),(0,A.jsxs)(`span`,{children:[`Press `,(0,A.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,A.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,A.jsxs)(`div`,{className:H.guideTip,children:[(0,A.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,A.jsxs)(`div`,{className:H.guideTip,children:[(0,A.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,A.jsx)(`code`,{className:H.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]}),S&&n&&(0,A.jsxs)(`ul`,{className:H.nodeListMobile,children:[n.nodes.map((e,t)=>{let r=Wt[e.defId];if(!r)return null;let i=n.edges.filter(t=>t.from===e.id);return(0,A.jsxs)(`li`,{children:[(0,A.jsxs)(`div`,{className:H.nodeRow,onClick:()=>a(e.id),role:`button`,tabIndex:0,children:[(0,A.jsx)(`span`,{className:H.nodeRowIndex,children:t+1}),(0,A.jsx)(`span`,{className:H.nodeRowIcon,style:{color:r.color},children:r.icon}),(0,A.jsxs)(`div`,{className:H.nodeRowBody,children:[(0,A.jsx)(`div`,{className:H.nodeRowLabel,children:r.label}),(0,A.jsx)(`div`,{className:H.nodeRowDesc,children:r.description})]})]}),i.length>1&&r.outputs&&(0,A.jsx)(`div`,{className:H.nodeRowBranch,children:i.map((e,t)=>{let i=n.nodes.find(t=>t.id===e.to),a=i?Wt[i.defId]:null;return(0,A.jsxs)(`div`,{children:[`↳ `,e.label||(r.outputs?.[t]??``),` → `,a?.icon,` `,a?.label??`?`]},t)})})]},e.id)}),n.nodes.length===0&&(0,A.jsx)(`li`,{className:H.nodeRow,style:{justifyContent:`center`,color:`var(--dim)`},children:`Nessun nodo. Aggiungi triggers/actions dalla palette (apri il browser per editare).`})]}),S&&n&&n.nodes.length>0&&(0,A.jsx)(`button`,{className:H.runFab,onClick:ue,disabled:c,"aria-label":`Run workflow`,title:`Esegui workflow`,children:c?`⏳`:`▶`}),S&&(0,A.jsx)(Vt,{open:!!(N&&de),onClose:()=>a(null),className:H.configSheet,handleClassName:H.configSheetHandle,ariaLabel:`Node configuration`,children:N&&de&&Xt(N,de,ce,le,oe,a,H)})]})}function Xt(e,t,n,r,i,a,o){return(0,A.jsxs)(`div`,{className:o.configPanel,children:[(0,A.jsxs)(`div`,{className:o.configHeader,children:[(0,A.jsxs)(`span`,{style:{color:t.color},children:[t.icon,` `,t.label]}),(0,A.jsx)(`button`,{className:o.configClose,onClick:()=>a(null),children:`✕`})]}),(0,A.jsx)(`div`,{className:o.configDesc,children:t.description}),(0,A.jsx)(`div`,{className:o.configFields,children:(t.configFields??[]).map(t=>(0,A.jsxs)(`div`,{className:o.configField,children:[(0,A.jsxs)(`label`,{className:o.configLabel,children:[t.label,t.required&&(0,A.jsx)(`span`,{className:o.configRequired,children:`*`})]}),t.type===`textarea`?(0,A.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,A.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,A.jsx)(`option`,{value:e,children:e},e))}):(0,A.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}),(t.placeholder?.includes(`{{`)??!1)&&(0,A.jsxs)(`div`,{className:o.configHint,children:[`Use `,(0,A.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},t.key))}),(0,A.jsx)(`button`,{className:o.configDelete,onClick:()=>i(e.id),children:`Delete node`})]})}var U={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`},Zt=[{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:`🗑`}],Qt=[{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 $t(e){return e?e.slice(0,10):``}function en(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 tn(){let e=M(),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),[T,O]=(0,_.useState)(!1),[re,k]=(0,_.useState)(``),[ie,j]=(0,_.useState)(``),[ae,oe]=(0,_.useState)(0),[se,ce]=(0,_.useState)(!1),[le,ue]=(0,_.useState)({}),[N,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(``),[me,he]=(0,_.useState)(``),[ge,_e]=(0,_.useState)(``),[ve,ye]=(0,_.useState)(``),[be,xe]=(0,_.useState)(!1),[P,Se]=(0,_.useState)(``),[Ce,we]=(0,_.useState)(!1),Te=(0,_.useRef)(null),F=(0,_.useRef)(0),Ee=[{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`}],[De,Oe]=(0,_.useState)(()=>{let e=parseInt(localStorage.getItem(`nha-email-refresh-sec`)||`600`,10);return Number.isFinite(e)?e:600}),[I,L]=(0,_.useState)(!1),[ke,Ae]=(0,_.useState)(null),[je,Me]=(0,_.useState)(null),[Ne,Pe]=(0,_.useState)(Date.now()),Fe=(0,_.useRef)(!1),Ie=e=>{Oe(e),localStorage.setItem(`nha-email-refresh-sec`,String(e))},Le=async()=>{if(!Fe.current&&o){Fe.current=!0,L(!0);try{c===`imap`?(await D(`/api/imap/sync/${o}`,{}).catch(()=>{}),o&&ze(o,f,0,re)):c===`google`&&Be(f||`INBOX`,re),Ae(Date.now())}finally{Fe.current=!1,L(!1)}}};(0,_.useEffect)(()=>{if(!De||!o){Me(null);return}Me(Date.now()+De*1e3);let e=setInterval(()=>{document.visibilityState!==`hidden`&&(Le(),Me(Date.now()+De*1e3))},De*1e3);return()=>clearInterval(e)},[De,o,c,f]),(0,_.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&(!De||!o||(ke?Date.now()-ke:1/0)>=De*1e3&&(Le(),Me(Date.now()+De*1e3)))};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[De,o,ke]),(0,_.useEffect)(()=>{if(!je)return;let e=setInterval(()=>Pe(Date.now()),1e3);return()=>clearInterval(e)},[je]);let Re=(()=>{if(!je||!De)return null;let e=Math.max(0,Math.round((je-Ne)/1e3));return`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`})();(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle)),E(`/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`?R(`google`,`google`):n===`imap`&&r&&t.some(e=>e.id===r)?R(r,`imap`):t.length>0?R(t[0].id,`imap`):R(`google`,`google`)})},[]);let R=(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`?E(`/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),ze(e,r,0,``)}):(d([]),Be(`INBOX`,``))},ze=(e,t,n,r)=>{let i=++F.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)}`),E(a).then(e=>{i===F.current&&(h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),te(!1))}).catch(()=>{i===F.current&&te(!1)})},Be=(e,t)=>{te(!0);let n=e||`INBOX`;E(`/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`&&oe(e.filter(e=>!e.is_read).length)}else h([]),v(0);te(!1)}).catch(()=>{h([]),te(!1)})},Ve=()=>{k(ie),b(0),h([]),c===`imap`&&o?ze(o,f,0,ie):Be(f||`INBOX`,ie)},He=e=>{S(e),ce(!1),O(!0),c===`google`?E(`/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)),O(!1)):D(`/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)),D(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}O(!1)}).catch(()=>O(!1))}).catch(()=>O(!1)):E(`/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)),O(!1)}).catch(()=>O(!1))},Ue=(e={})=>{ce(!0),ue(e),de(e.to??``),pe(``),he(e.subject??``),_e(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),ye(``),xe(!1),S(null),w(null)},We=async()=>{if(!N.trim()){ye(`Recipient required`);return}ye(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:N.trim(),cc:fe.trim()||void 0,subject:me.trim(),bodyHtml:ge.replace(/\n/g,`<br>`),bodyText:ge,inReplyTo:le.inReplyTo||void 0});e?.ok?(ye(`Sent!`),setTimeout(()=>ce(!1),800)):ye(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:N.trim(),subject:me.trim(),body:ge});e?.ok||e?.id?(ye(`Sent!`),setTimeout(()=>ce(!1),800)):ye(e?.error??`Error`)}}catch(e){ye(e.message??`Error`)}},Ge=e=>{confirm(`Move to trash? Email stays on the server.`)&&D(`/api/imap/trash`,{messageId:e}).then(()=>{h(t=>t.filter(t=>t.id!==e)),w(null),S(null)})},Ke=(e,t)=>{D(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},qe=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Je=()=>{!P.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:P.trim()}).then(()=>{we(!1),Se(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})},Ye=()=>{if(c===`google`){te(!0);let e=f||`INBOX`,t=m.length+50;E(`/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&&ze(o,f,e,re)}};return(0,A.jsxs)(`div`,{className:U.root,children:[(0,A.jsxs)(`div`,{className:U.sidebar,children:[(0,A.jsxs)(`div`,{className:U.sidebarSection,children:[(0,A.jsx)(`div`,{className:U.sidebarLabel,children:`Account`}),(0,A.jsxs)(`select`,{className:U.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?R(`google`,`google`):t.startsWith(`imap:`)&&R(t.slice(5),`imap`)},children:[n&&(0,A.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,A.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,A.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,A.jsx)(`div`,{className:U.sidebarCompose,children:(0,A.jsx)(`button`,{className:U.composeBtn,onClick:()=>Ue(),children:`+ Compose`})}),(0,A.jsx)(`div`,{className:U.folderList,children:c===`google`?Zt.map(e=>(0,A.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Be(e.id,re)},children:[(0,A.jsx)(`span`,{children:e.icon}),(0,A.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&ae>0&&(0,A.jsx)(`span`,{className:U.badge,children:ae})]},e.id)):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:U.labelHeader,children:[(0,A.jsx)(`span`,{children:`Labels`}),(0,A.jsx)(`button`,{className:U.addLabelBtn,onClick:()=>we(e=>!e),children:`+`})]}),Ce&&(0,A.jsxs)(`div`,{className:U.newLabelRow,children:[(0,A.jsx)(`input`,{className:U.newLabelInput,value:P,onChange:e=>Se(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Je()}),(0,A.jsx)(`button`,{className:U.newLabelSave,onClick:Je,children:`+`})]}),u.map(e=>(0,A.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&ze(o,e.id,0,re)},children:[(0,A.jsx)(`span`,{className:U.labelDot,style:{background:e.color??`var(--dim)`}}),(0,A.jsx)(`span`,{children:e.name}),e.system_type===`inbox`&&e.unread_count?(0,A.jsx)(`span`,{className:U.badge,children:e.unread_count}):null]},e.id))]})}),o&&(0,A.jsxs)(`div`,{className:U.syncArea,children:[(0,A.jsx)(`button`,{className:U.syncBtn,onClick:Le,disabled:I,title:ke?`Ultimo sync: ${new Date(ke).toLocaleTimeString()}`:`Mai sincronizzato`,children:I?`⟳ Sync…`:`Sync ora`}),(0,A.jsx)(`select`,{className:U.refreshSelect,value:De,onChange:e=>Ie(parseInt(e.target.value,10)),title:`Intervallo di aggiornamento automatico`,children:Ee.map(e=>(0,A.jsx)(`option`,{value:e.sec,children:e.label},e.sec))}),Re&&(0,A.jsxs)(`span`,{className:U.refreshCountdown,title:`Prossimo refresh tra`,children:[`⏱ `,Re]})]})]}),(0,A.jsxs)(`div`,{className:U.messageList,children:[(0,A.jsxs)(`div`,{className:U.listHeader,children:[(0,A.jsx)(`input`,{className:U.searchInput,value:ie,onChange:e=>j(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&Ve()}),(0,A.jsx)(`button`,{className:U.searchBtn,onClick:Ve,children:`Go`})]}),(0,A.jsxs)(`div`,{className:U.listBody,children:[ee&&(0,A.jsx)(`div`,{className:U.listLoading,children:(0,A.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,A.jsx)(`div`,{className:U.noMessages,children:`No messages`}),m.map(e=>(0,A.jsxs)(`div`,{className:`${U.msgRow} ${e.id===x?U.msgActive:``} ${e.is_read?``:U.msgUnread}`,onClick:()=>He(e.id),children:[(0,A.jsxs)(`div`,{className:U.msgTop,children:[(0,A.jsx)(`span`,{className:U.msgFrom,children:e.from_name||e.from_address||``}),(0,A.jsx)(`span`,{className:U.msgDate,children:$t(e.internal_date)})]}),(0,A.jsx)(`div`,{className:U.msgSubject,children:e.subject||`(no subject)`}),(0,A.jsx)(`div`,{className:U.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,A.jsxs)(`div`,{className:U.listFooter,children:[(0,A.jsxs)(`span`,{children:[g,` messages`]}),c===`imap`&&m.length<g&&(0,A.jsx)(`button`,{className:U.loadMoreBtn,onClick:Ye,children:`Load more`}),c===`google`&&m.length>=50&&(0,A.jsx)(`button`,{className:U.loadMoreBtn,onClick:Ye,disabled:ee,children:ee?`Loading...`:`Scarica altre`})]})]}),(0,A.jsx)(`div`,{className:U.pane,children:(()=>{if(se)return(0,A.jsxs)(`div`,{className:U.composePane,children:[(0,A.jsx)(`div`,{className:U.composeTitle,children:e(`email.compose`)}),(0,A.jsx)(`input`,{className:U.composeField,value:N,onChange:e=>de(e.target.value),placeholder:`To`}),(0,A.jsx)(`input`,{className:U.composeField,value:fe,onChange:e=>pe(e.target.value),placeholder:`Cc`}),(0,A.jsx)(`input`,{className:U.composeField,value:me,onChange:e=>he(e.target.value),placeholder:`Subject`}),(0,A.jsxs)(`div`,{className:U.templateRow,children:[(0,A.jsx)(`button`,{className:U.templateToggle,onClick:()=>xe(e=>!e),children:`📄 Templates`}),be&&(0,A.jsx)(`div`,{className:U.templateDrop,children:Qt.map((e,t)=>(0,A.jsxs)(`div`,{className:U.templateItem,onClick:()=>{he(t=>t||e.subject),xe(!1)},children:[(0,A.jsx)(`strong`,{children:e.name}),(0,A.jsx)(`div`,{className:U.templateSubject,children:e.subject})]},t))})]}),(0,A.jsx)(`textarea`,{className:U.composeBody,value:ge,onChange:e=>_e(e.target.value),placeholder:`Write your message…`}),(0,A.jsxs)(`div`,{className:U.composeActions,children:[(0,A.jsx)(`button`,{className:U.sendBtn,onClick:We,children:e(`email.send_ok`)}),(0,A.jsx)(`button`,{className:U.cancelBtn,onClick:()=>ce(!1),children:`Discard`}),ve&&(0,A.jsx)(`span`,{className:`${U.compStatus} ${ve===`Sent!`?U.ok:U.err}`,children:ve})]})]});if(T)return(0,A.jsx)(`div`,{className:U.emptyPane,children:(0,A.jsx)(`div`,{className:`spinner`})});if(!C)return(0,A.jsx)(`div`,{className:U.emptyPane,children:`Select a message`});let n=en(C.to_addresses);return(0,A.jsxs)(`div`,{className:U.readingPane,children:[(0,A.jsx)(`div`,{className:U.paneToolbar,children:(0,A.jsxs)(`div`,{className:U.paneActions,children:[(0,A.jsx)(`button`,{className:U.replyBtn,onClick:()=>Ue({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,A.jsx)(`button`,{className:U.fwdBtn,onClick:()=>Ue({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{className:U.trashBtn,onClick:()=>Ge(C.id),children:`🗑`}),(0,A.jsx)(`button`,{className:U.starBtn,onClick:()=>Ke(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,A.jsxs)(`select`,{className:U.labelSelect,defaultValue:``,onChange:e=>qe(C.id,e.target.value),children:[(0,A.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,A.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,A.jsx)(`button`,{className:U.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,A.jsxs)(`div`,{className:U.paneHeader,children:[(0,A.jsx)(`div`,{className:U.paneSubject,children:C.subject||`(no subject)`}),(0,A.jsxs)(`div`,{className:U.paneMeta,children:[(0,A.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,A.jsxs)(`div`,{className:U.paneMeta,children:[(0,A.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,A.jsxs)(`div`,{className:U.paneMeta,children:[(0,A.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,A.jsx)(`div`,{className:U.attachments,children:C.attachments.map((e,t)=>(0,A.jsxs)(`a`,{className:U.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,A.jsx)(`div`,{className:U.paneBody,children:C.body_html?(0,A.jsx)(`iframe`,{ref:Te,sandbox:`allow-same-origin allow-popups`,className:U.bodyFrame,srcDoc:C.body_html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,``),title:`Email body`}):(0,A.jsx)(`pre`,{className:U.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var W={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 nn(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function rn(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function an(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 on(){let e=M(),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)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle))},[]);let S=(0,_.useCallback)((e,t)=>{let n=`${e}-${String(t+1).padStart(2,`0`)}`;f(!0),E(`/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=>{E(`/api/calendar?date=${e}`).then(t=>{u(n=>({...n,[e]:t?.events??[]}))})},w=(e,t,n)=>{confirm(`Delete this event?`)&&D(`/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(``)},T=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 D(`/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 D(`/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,A.jsx)(`div`,{className:W.center,children:(0,A.jsx)(`div`,{className:`spinner`})});if(!n)return(0,A.jsx)(`div`,{className:W.center,children:(0,A.jsxs)(`div`,{className:W.noGoogle,children:[(0,A.jsx)(`div`,{className:W.noGoogleIcon,children:`📅`}),(0,A.jsx)(`div`,{className:W.noGoogleTitle,children:`Calendar`}),(0,A.jsx)(`div`,{className:W.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,A.jsx)(`button`,{className:W.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let O=new Date(a,s,1).getDay(),re=new Date(a,s+1,0).getDate(),k=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ie=(O+6)%7,j=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],ae=p?l[p]??[]:[];return(0,A.jsxs)(`div`,{className:W.root,children:[(0,A.jsxs)(`div`,{className:W.calCol,children:[(0,A.jsxs)(`div`,{className:W.navRow,children:[(0,A.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,A.jsx)(`div`,{className:W.monthTitle,children:k}),(0,A.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,A.jsx)(`div`,{className:W.dayHeaders,children:j.map((e,t)=>(0,A.jsx)(`div`,{className:`${W.dayHeader} ${t>=5?W.weekend:``}`,children:e},e))}),(0,A.jsxs)(`div`,{className:W.grid,children:[Array.from({length:ie}).map((e,t)=>(0,A.jsx)(`div`,{className:`${W.cell} ${W.emptyCell} ${t>=5?W.weekendCell:``}`},`e${t}`)),Array.from({length:re}).map((e,t)=>{let n=t+1,r=nn(a,s,n),i=rn(a,s,n),o=l[r]??[],c=o.length,u=(ie+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,A.jsxs)(`div`,{className:`${W.cell} ${i?W.todayCell:u?W.weekendCell:``} ${f?W.activeCell:``} ${d?W.holidayCell:c>0?W.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,A.jsx)(`div`,{className:`${W.dayNum} ${i?W.todayNum:u?W.weekendNum:``}`,children:n}),c>0&&(0,A.jsxs)(`div`,{className:W.evtPills,children:[o.slice(0,2).map((e,t)=>(0,A.jsx)(`div`,{className:`${W.evtPill} ${e._isHoliday||e.readOnly?W.holidayPill:``}`,children:e.summary},t)),c>2&&(0,A.jsxs)(`div`,{className:W.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,A.jsx)(`div`,{className:W.loadingBar,children:`Loading events…`})]}),(0,A.jsx)(`div`,{className:W.detailCol,children:p?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:W.detailHeader,children:[(0,A.jsx)(`div`,{className:W.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,A.jsx)(`button`,{className:W.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),ae.length===0?(0,A.jsx)(`div`,{className:W.noEvts,children:`No events on this day`}):ae.map((t,n)=>{let r=t.isAllDay?`All day`:`${an(t.start)} - ${an(t.end)}`,i=t.calendarId??`primary`;return(0,A.jsxs)(`div`,{className:W.evtCard,children:[(0,A.jsxs)(`div`,{className:W.evtTop,children:[(0,A.jsx)(`div`,{className:W.evtTime,children:r}),t.id&&!t.readOnly&&(0,A.jsxs)(`div`,{className:W.evtBtns,children:[(0,A.jsx)(`button`,{className:W.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,A.jsx)(`button`,{className:W.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,A.jsx)(`span`,{className:W.readOnly,children:`read-only`})]}),(0,A.jsx)(`div`,{className:W.evtTitle,children:t.summary}),t.location&&(0,A.jsxs)(`div`,{className:W.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,A.jsxs)(`div`,{className:W.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,A.jsxs)(`div`,{className:W.attendees,children:[(0,A.jsx)(`div`,{className:W.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,A.jsxs)(`div`,{className:W.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,A.jsx)(`div`,{className:W.evtDesc,children:t.description}),t.hangoutLink&&(0,A.jsx)(`a`,{className:W.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,A.jsx)(`a`,{className:W.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,A.jsxs)(`div`,{className:W.selectDay,children:[`Click a day to see events, edit or delete them.`,(0,A.jsx)(`br`,{}),(0,A.jsx)(`br`,{}),`Use `,(0,A.jsx)(`strong`,{children:`+ Add Event`}),` to create a new event — it syncs with Google Calendar.`]})}),h&&(0,A.jsx)(`div`,{className:W.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,A.jsxs)(`div`,{className:W.formCard,children:[(0,A.jsx)(`div`,{className:W.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Title *`}),(0,A.jsx)(`input`,{className:W.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Start`}),(0,A.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,A.jsx)(`label`,{className:W.formLabel,children:`End`}),(0,A.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Location`}),(0,A.jsx)(`input`,{className:W.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,A.jsx)(`label`,{className:W.formLabel,children:`Description`}),(0,A.jsx)(`textarea`,{className:W.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,A.jsx)(`div`,{className:W.formError,children:v}),(0,A.jsxs)(`div`,{className:W.formBtns,children:[(0,A.jsx)(`button`,{className:W.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,A.jsx)(`button`,{className:W.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var G={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`},sn={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 cn(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=sn[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 ln(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function un(){let e=M(),[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),T=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),k=(0,_.useRef)(new Map),ie=(0,_.useRef)(new Map),j=(0,_.useRef)(new Map),ae=(0,_.useRef)(null),oe=()=>{E(`/api/agents`).then(e=>{n((e?.agents??[]).map(cn)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{oe()},[]);let se=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],ce=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))}),le=e=>{u(t=>{let n=t.findIndex(t=>t.agent.id===e.id);return n>=0?(O.current.get(e.id)?.abort(),O.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,ln(e)]})},ue=e=>{O.current.get(e)?.abort(),O.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},N=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},de=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},fe=(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}}))},pe=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;de(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),N(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 D(`/api/chat`,e);de(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{de(i,{role:`assistant`,content:`Error sending attachment.`})}N(i,{streaming:!1});return}de(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;O.current.set(i,o);let s=``;try{await re(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,fe(i,s);let t=k.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{N(i,{streaming:!1}),O.current.delete(i)}},me=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;de(r,{role:`user`,content:e}),N(r,{streaming:!0});let i=``,a=new AbortController;O.current.set(r,a),de(r,{role:`assistant`,content:``,streaming:!0});try{await re(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,fe(r,i);let t=k.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{N(r,{streaming:!1}),O.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(`
655
655
 
656
656
  ---
657
657
 
658
658
  `),r=`The user asked: "${e}"\n\nHere are the responses from ${t.length} specialist agents:\n\n${n}\n\nSynthesize these responses into a unified analysis.`,i=``;try{await re(`/api/chat/stream`,{message:r,systemPrompt:`You are the Conductor — a meta-agent that synthesizes the outputs of multiple specialist AI agents.
659
659
  Your job: examine all agent responses to a user's question, identify agreements, disagreements, complementary insights, and deliver a unified, high-quality synthesis.
660
- Be concise. Highlight what each agent contributed uniquely. Give your own synthesis verdict at the end.`},e=>{i+=e,g(i)})}catch{}finally{y(!1)}},he=e=>{let t=window.SpeechRecognition??window.webkitSpeechRecognition;if(!t){alert(`Speech recognition not supported.`);return}let n=T.current.get(e);if(l.find(t=>t.agent.id===e)?.voiceActive&&n){n.stop(),N(e,{voiceActive:!1});return}let r=new t;T.current.set(e,r),r.lang=`it-IT`,r.continuous=!1,r.interimResults=!1,r.onresult=t=>{let n=t.results[0][0].transcript;N(e,{input:(l.find(t=>t.agent.id===e)?.input??``)+(l.find(t=>t.agent.id===e)?.input?` `:``)+n})},r.onend=()=>N(e,{voiceActive:!1}),r.onerror=()=>N(e,{voiceActive:!1}),r.start(),N(e,{voiceActive:!0})},ge=(e,t)=>{if(!t)return;let n=t.name.toLowerCase().endsWith(`.pdf`)||t.type===`application/pdf`,r=new FileReader;n?(r.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedFile:{name:t.name,size:t.size,base64:r,mimeType:`application/pdf`,isPDF:!0},attachedImage:null})},r.readAsDataURL(t)):(r.onload=n=>{N(e,{attachedFile:{name:t.name,size:t.size,content:n.target?.result},attachedImage:null})},r.readAsText(t))},_e=(e,t)=>{if(!t)return;let n=new FileReader;n.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedImage:{name:t.name,size:t.size,base64:r,mimeType:t.type||`image/jpeg`},attachedFile:null})},n.readAsDataURL(t)},ve=()=>{x({name:``,tagline:``,systemPrompt:``}),C(`create`),ee(``)},ye=async e=>{let t=await E(`/api/agents/${e.id}`).catch(()=>null);x({name:e.id,tagline:t?.tagline??e.description,systemPrompt:t?.systemPrompt??``}),C(`edit`),ee(``)},be=async()=>{if(b){if(!b.tagline.trim()||!b.systemPrompt.trim()){ee(`Tagline and system prompt are required.`);return}ne(!0),ee(``);try{if(S===`create`){let e=b.name.toLowerCase().replace(/[^a-z0-9_-]/g,``);if(!e){ee(`Agent name required (lowercase, no spaces).`),ne(!1);return}let t=await D(`/api/agents`,{name:e,tagline:b.tagline,systemPrompt:b.systemPrompt});if(t?.error){ee(`Error: `+t.error),ne(!1);return}}else await D(`/api/agents/${b.name}`,{tagline:b.tagline,systemPrompt:b.systemPrompt,category:`custom`},`PUT`);x(null),oe()}catch(e){ee(`Error: `+e.message)}finally{ne(!1)}}},P=e=>{confirm(`Delete agent "${e.label}"?`)&&D(`/api/agents/${e.id}`,{},`DELETE`).then(()=>oe())};return r?(0,A.jsx)(`div`,{className:G.root,children:(0,A.jsx)(`div`,{className:G.loading,children:(0,A.jsx)(`div`,{className:`spinner`})})}):(0,A.jsxs)(`div`,{className:G.root,children:[(0,A.jsxs)(`div`,{className:G.gridSection,children:[(0,A.jsxs)(`div`,{className:G.gridHeader,children:[(0,A.jsxs)(`div`,{className:G.headerRow,children:[(0,A.jsx)(`input`,{className:G.search,value:a,onChange:e=>o(e.target.value),placeholder:`Search agents…`}),(0,A.jsx)(`button`,{className:G.createBtn,onClick:ve,children:`+ Create`})]}),(0,A.jsx)(`div`,{className:G.catTabs,children:se.map(e=>(0,A.jsxs)(`button`,{className:`${G.catTab} ${s===e?G.catActive:``}`,onClick:()=>c(e),children:[e,` (`,e===`All`?t.length:t.filter(t=>t.category===e).length,`)`]},e))})]}),(0,A.jsx)(`div`,{className:G.grid,children:ce.map(e=>{let t=l.some(t=>t.agent.id===e.id);return(0,A.jsxs)(`div`,{className:`${G.agentCard} ${t?G.agentActive:``}`,onClick:()=>le(e),children:[(0,A.jsxs)(`div`,{className:G.agentCardTop,children:[(0,A.jsx)(`div`,{className:G.agentIcon,children:e.icon}),e.isCustom&&(0,A.jsxs)(`div`,{className:G.agentActions,children:[(0,A.jsx)(`button`,{className:G.agentEditBtn,onClick:t=>{t.stopPropagation(),ye(e)},children:`✏️`}),(0,A.jsx)(`button`,{className:G.agentDelBtn,onClick:t=>{t.stopPropagation(),P(e)},children:`🗑`})]})]}),(0,A.jsx)(`div`,{className:G.agentLabel,children:e.label}),(0,A.jsx)(`div`,{className:G.agentDesc,children:e.description}),(0,A.jsx)(`div`,{className:G.agentCat,children:e.category})]},e.id)})})]}),(0,A.jsx)(`div`,{className:G.chatArea,children:l.length===0?(0,A.jsxs)(`div`,{className:G.emptyChat,children:[(0,A.jsx)(`span`,{children:`Click an agent above to open a chat`}),(0,A.jsx)(`span`,{className:G.emptyChatHint,children:`Open multiple agents to run them in parallel`})]}):l.map(e=>{let{agent:t}=e,n=e.attachedFile?`📎 ${e.attachedFile.name}`:e.attachedImage?`🖼 ${e.attachedImage.name}`:null;return(0,A.jsxs)(`div`,{className:G.chatPanel,children:[(0,A.jsxs)(`div`,{className:G.chatHeader,children:[(0,A.jsx)(`span`,{className:G.chatIcon,children:t.icon}),(0,A.jsxs)(`div`,{className:G.chatHeaderInfo,children:[(0,A.jsx)(`div`,{className:G.chatAgentName,children:t.label}),(0,A.jsx)(`div`,{className:G.chatAgentDesc,children:t.description})]}),(0,A.jsx)(`button`,{className:G.closeChat,onClick:()=>ue(t.id),children:`✕`})]}),(0,A.jsxs)(`div`,{className:G.chatMessages,ref:e=>{k.current.set(t.id,e)},children:[e.history.length===0&&(0,A.jsxs)(`div`,{className:G.chatEmpty,children:[`Ask `,t.label,` anything…`]}),e.history.map((e,t)=>(0,A.jsx)(`div`,{className:`${G.chatMsg} ${e.role===`user`?G.msgUser:G.msgAgent}`,children:e.role===`assistant`?(0,A.jsx)(`div`,{dangerouslySetInnerHTML:{__html:xe(e.content||`…`)}}):(0,A.jsx)(`span`,{children:e.content})},t)),e.streaming&&e.history[e.history.length-1]?.role===`assistant`&&e.history[e.history.length-1]?.content===``&&(0,A.jsxs)(`div`,{className:G.thinking,children:[(0,A.jsx)(`span`,{className:G.dot}),(0,A.jsx)(`span`,{className:G.dot}),(0,A.jsx)(`span`,{className:G.dot})]})]}),n&&(0,A.jsxs)(`div`,{className:G.attachBar,children:[(0,A.jsx)(`span`,{children:n}),(0,A.jsx)(`button`,{className:G.attachClear,onClick:()=>N(t.id,{attachedFile:null,attachedImage:null}),children:`×`})]}),(0,A.jsxs)(`div`,{className:G.chatInput,children:[(0,A.jsxs)(`div`,{className:G.chatTools,children:[(0,A.jsx)(`button`,{className:`${G.toolBtn} ${e.voiceActive?G.toolBtnActive:``}`,onClick:()=>he(t.id),title:`Voice`,children:`🎤`}),(0,A.jsx)(`button`,{className:G.toolBtn,onClick:()=>ie.current.get(t.id)?.click(),title:`Attach file`,children:`📎`}),(0,A.jsx)(`button`,{className:G.toolBtn,onClick:()=>j.current.get(t.id)?.click(),title:`Attach image`,children:`🖼`}),(0,A.jsx)(`input`,{type:`file`,style:{display:`none`},ref:e=>{ie.current.set(t.id,e)},onChange:e=>ge(t.id,e.target.files?.[0])}),(0,A.jsx)(`input`,{type:`file`,accept:`image/*`,style:{display:`none`},ref:e=>{j.current.set(t.id,e)},onChange:e=>_e(t.id,e.target.files?.[0])})]}),(0,A.jsxs)(`div`,{className:G.chatInputRow,children:[(0,A.jsx)(`textarea`,{className:G.chatTextarea,value:e.input,onChange:e=>N(t.id,{input:e.target.value}),placeholder:`Message ${t.label}…`,rows:2,onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),pe(e,e.input,e.attachedFile,e.attachedImage))}}),(0,A.jsx)(`button`,{className:G.sendBtn,onClick:()=>pe(e,e.input,e.attachedFile,e.attachedImage),disabled:e.streaming||!e.input.trim()&&!e.attachedFile&&!e.attachedImage,children:e.streaming?`…`:`→`})]})]})]},t.id)})}),l.length>=2&&(0,A.jsxs)(`div`,{className:G.orchBar,children:[(0,A.jsxs)(`div`,{className:G.orchLabel,children:[`🎼 Conductor · `,l.map(e=>`${e.agent.icon} ${e.agent.label}`).join(` · `)]}),(0,A.jsxs)(`div`,{className:G.orchRow,children:[(0,A.jsx)(`textarea`,{ref:ae,className:G.orchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Ask all agents — Conductor will synthesize a unified response…`,rows:1,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),me())}}),(0,A.jsx)(`button`,{className:G.orchBtn,onClick:me,disabled:p||v||!d.trim(),children:p?`⏳`:v?`🔄`:`🎼 Run`})]}),(v||h)&&(0,A.jsxs)(`div`,{className:G.orchSynthesis,children:[(0,A.jsxs)(`div`,{className:G.orchSynthHeader,children:[(0,A.jsx)(`span`,{children:`🎼 Conductor Synthesis`}),v&&(0,A.jsx)(`span`,{className:G.orchSynthSpinner,children:`synthesizing…`})]}),(0,A.jsx)(`div`,{className:G.orchSynthBody,dangerouslySetInnerHTML:{__html:xe(h||`…`)}})]})]}),b&&(0,A.jsx)(`div`,{className:G.modalOverlay,onClick:e=>{e.target===e.currentTarget&&x(null)},children:(0,A.jsxs)(`div`,{className:G.modal,children:[(0,A.jsx)(`div`,{className:G.modalTitle,children:S===`create`?`+ New Agent`:`✏️ Edit Agent`}),S===`create`&&(0,A.jsxs)(`div`,{className:G.formField,children:[(0,A.jsx)(`label`,{className:G.formLabel,children:`Agent name (lowercase, no spaces)`}),(0,A.jsx)(`input`,{className:G.formInput,placeholder:`my-agent`,value:b.name,onChange:e=>x(t=>t&&{...t,name:e.target.value})})]}),(0,A.jsxs)(`div`,{className:G.formField,children:[(0,A.jsx)(`label`,{className:G.formLabel,children:`Tagline`}),(0,A.jsx)(`input`,{className:G.formInput,placeholder:`Short description`,value:b.tagline,onChange:e=>x(t=>t&&{...t,tagline:e.target.value})})]}),(0,A.jsxs)(`div`,{className:G.formField,children:[(0,A.jsx)(`label`,{className:G.formLabel,children:`System Prompt`}),(0,A.jsx)(`textarea`,{className:G.formTextarea,placeholder:`You are an expert in…`,value:b.systemPrompt,onChange:e=>x(t=>t&&{...t,systemPrompt:e.target.value})})]}),w&&(0,A.jsx)(`div`,{className:G.formError,children:w}),(0,A.jsxs)(`div`,{className:G.modalBtns,children:[(0,A.jsx)(`button`,{className:G.cancelBtn,onClick:()=>x(null),children:e(`common.cancel`)}),(0,A.jsx)(`button`,{className:G.modalSaveBtn,onClick:be,disabled:te,children:te?`…`:S===`create`?`Create Agent`:`Save`})]})]})})]})}var K={root:`_root_1mam6_1`,error:`_error_1mam6_10`,errorHint:`_errorHint_1mam6_16`,quotaBar:`_quotaBar_1mam6_29`,quotaText:`_quotaText_1mam6_37`,quotaUsed:`_quotaUsed_1mam6_43`,quotaPct:`_quotaPct_1mam6_44`,quotaTrack:`_quotaTrack_1mam6_46`,quotaFill:`_quotaFill_1mam6_53`,actionBar:`_actionBar_1mam6_59`,filterBtn:`_filterBtn_1mam6_67`,filterActive:`_filterActive_1mam6_79`,spacer:`_spacer_1mam6_85`,newBtn:`_newBtn_1mam6_87`,uploadBtn:`_uploadBtn_1mam6_98`,searchRow:`_searchRow_1mam6_108`,searchInput:`_searchInput_1mam6_114`,searchBtn:`_searchBtn_1mam6_126`,loading:`_loading_1mam6_136`,empty:`_empty_1mam6_141`,fileList:`_fileList_1mam6_151`,fileRow:`_fileRow_1mam6_159`,fileIcon:`_fileIcon_1mam6_172`,fileInfo:`_fileInfo_1mam6_174`,fileName:`_fileName_1mam6_176`,fileMeta:`_fileMeta_1mam6_184`,fileBtns:`_fileBtns_1mam6_190`,editBtn:`_editBtn_1mam6_196`,viewBtn:`_viewBtn_1mam6_197`,pdfBtn:`_pdfBtn_1mam6_198`,openBtn:`_openBtn_1mam6_199`,delBtn:`_delBtn_1mam6_200`,editorRoot:`_editorRoot_1mam6_204`,editorToolbar:`_editorToolbar_1mam6_211`,backBtn:`_backBtn_1mam6_221`,editorName:`_editorName_1mam6_231`,saveBtn:`_saveBtn_1mam6_238`,editorArea:`_editorArea_1mam6_251`,editorMeta:`_editorMeta_1mam6_266`,viewerRoot:`_viewerRoot_1mam6_276`,imgContainer:`_imgContainer_1mam6_283`,imgView:`_imgView_1mam6_292`,pdfFrame:`_pdfFrame_1mam6_298`};function dn(e,t){return e===`folder`?`📁`:e===`image`?`🖼`:e===`pdf`||t.includes(`pdf`)?`📕`:e===`video`?`🎬`:e===`audio`?`🎵`:t.includes(`spreadsheet`)||t.includes(`excel`)?`📊`:t.includes(`presentation`)||t.includes(`powerpoint`)?`📽`:t.includes(`document`)||t.includes(`word`)?`📄`:t.includes(`zip`)||t.includes(`archive`)?`📦`:`📄`}function fn(e){let t=e.mimeType;return e.type===`text`||e.type===`doc`||t.includes(`text`)||t.includes(`json`)||t.includes(`javascript`)||t.includes(`xml`)||t.includes(`csv`)||t.includes(`yaml`)||t.includes(`markdown`)||t.includes(`html`)||t.includes(`css`)||t.includes(`python`)||t.includes(`vnd.google-apps.document`)}function pn(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(`list`),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(!1),w=(0,_.useRef)(null),ee=(e=s,t=l)=>{i(!0);let r=`/api/drive`;e&&(r+=`?filter=${e}`),t&&(r+=`${e?`&`:`?`}search=${encodeURIComponent(t)}`),E(r).then(e=>{n(e??{files:[]}),i(!1)}).catch(e=>{o(e.message??`Error`),i(!1)})};(0,_.useEffect)(()=>{ee()},[]);let te=e=>{c(e),ee(e,l)},ne=()=>{u(d),ee(s,d)},T=(e,t)=>{i(!0),E(`/api/drive/read/${e}`).then(n=>{g({id:e,name:t,content:n?.content??``}),y(n?.content??``),m(`editor`),i(!1)}).catch(()=>i(!1))},O=async()=>{if(h&&confirm(`Save changes to "${h.name}" on Drive?`)){C(!0);try{await D(`/api/drive/update/${h.id}`,{content:v}),g(e=>e&&{...e,content:v}),alert(`Saved!`)}catch(e){alert(`Save failed: `+e.message)}finally{C(!1)}}},re=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{x({id:e,name:t,src:`data:${n?.mimeType??`image/jpeg`};base64,${n?.base64}`,mode:`image`}),m(`image`),i(!1)}).catch(()=>i(!1))},k=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{x({id:e,name:t,src:`data:application/pdf;base64,${n?.base64}`,mode:`pdf`}),m(`pdf`),i(!1)}).catch(()=>i(!1))},ie=(e,t)=>{confirm(`Delete "${t}" from Drive? (moved to trash)`)&&D(`/api/drive/delete/${e}`,{}).then(()=>{n(null),ee()})},j=()=>{let e=prompt(`File name (e.g. notes.txt, script.py):`);e&&D(`/api/drive/upload`,{name:e,content:``,mimeType:`text/plain`}).then(t=>{t?.id?T(t.id,e):ee()}).catch(e=>alert(`Error: `+e.message))},ae=()=>{w.current?.click()},oe=e=>{if(!e)return;let t=new FileReader;t.onload=t=>{let r=(t.target?.result).split(`,`)[1]??``;D(`/api/drive/upload`,{name:e.name,content:r,mimeType:e.type||`application/octet-stream`,encoding:`base64`}).then(()=>{n(null),ee()}).catch(e=>alert(`Upload error: `+e.message))},t.readAsDataURL(e)};if(a)return(0,A.jsxs)(`div`,{className:K.error,children:[(0,A.jsx)(`div`,{children:a}),(0,A.jsxs)(`div`,{className:K.errorHint,children:[`Run: `,(0,A.jsx)(`code`,{children:`nha google revoke`}),` then `,(0,A.jsx)(`code`,{children:`nha google auth`})]})]});if(p===`editor`&&h)return(0,A.jsxs)(`div`,{className:K.editorRoot,children:[(0,A.jsxs)(`div`,{className:K.editorToolbar,children:[(0,A.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,A.jsx)(`span`,{className:K.editorName,children:h.name}),(0,A.jsx)(`button`,{className:K.saveBtn,onClick:O,disabled:S,children:S?`Saving…`:`Save to Drive`})]}),(0,A.jsx)(`textarea`,{className:K.editorArea,value:v,onChange:e=>y(e.target.value),spellCheck:!1,onKeyDown:e=>{if(e.key===`Tab`){e.preventDefault();let t=e.currentTarget.selectionStart,n=e.currentTarget.selectionEnd,r=e.currentTarget.value;e.currentTarget.value=r.slice(0,t)+` `+r.slice(n),e.currentTarget.selectionStart=e.currentTarget.selectionEnd=t+2}}}),(0,A.jsxs)(`div`,{className:K.editorMeta,children:[`File ID: `,h.id,` · Tab = 2 spaces · Not auto-saved`]})]});if(p===`image`&&b)return(0,A.jsxs)(`div`,{className:K.viewerRoot,children:[(0,A.jsxs)(`div`,{className:K.editorToolbar,children:[(0,A.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,A.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,A.jsx)(`div`,{className:K.imgContainer,children:(0,A.jsx)(`img`,{src:b.src,alt:b.name,className:K.imgView})})]});if(p===`pdf`&&b)return(0,A.jsxs)(`div`,{className:K.viewerRoot,children:[(0,A.jsxs)(`div`,{className:K.editorToolbar,children:[(0,A.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,A.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,A.jsx)(`iframe`,{className:K.pdfFrame,src:b.src,title:b.name})]});let se=t?.files??[],ce=t?.quota;return(0,A.jsxs)(`div`,{className:K.root,children:[ce&&(0,A.jsxs)(`div`,{className:K.quotaBar,children:[(0,A.jsxs)(`div`,{className:K.quotaText,children:[(0,A.jsxs)(`span`,{className:K.quotaUsed,children:[ce.usage,` of `,ce.limit,` used`]}),(0,A.jsxs)(`span`,{className:K.quotaPct,children:[ce.percentUsed,`%`]})]}),(0,A.jsx)(`div`,{className:K.quotaTrack,children:(0,A.jsx)(`div`,{className:K.quotaFill,style:{width:`${Math.min(ce.percentUsed,100)}%`,background:ce.percentUsed>90?`var(--red)`:ce.percentUsed>70?`var(--amber)`:`var(--green)`}})})]}),(0,A.jsxs)(`div`,{className:K.actionBar,children:[[``,`recent`,`starred`,`shared`].map(e=>(0,A.jsx)(`button`,{className:`${K.filterBtn} ${s===e?K.filterActive:``}`,onClick:()=>te(e),children:e?e.charAt(0).toUpperCase()+e.slice(1):`All Files`},e)),(0,A.jsx)(`div`,{className:K.spacer}),(0,A.jsx)(`button`,{className:K.newBtn,onClick:j,children:`+ New File`}),(0,A.jsx)(`button`,{className:K.uploadBtn,onClick:ae,children:e(`drive.upload`)}),(0,A.jsx)(`input`,{ref:w,type:`file`,style:{display:`none`},onChange:e=>oe(e.target.files?.[0])})]}),(0,A.jsxs)(`div`,{className:K.searchRow,children:[(0,A.jsx)(`input`,{className:K.searchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Search files…`,onKeyDown:e=>e.key===`Enter`&&ne()}),(0,A.jsx)(`button`,{className:K.searchBtn,onClick:ne,children:`Search`})]}),r&&(0,A.jsx)(`div`,{className:K.loading,children:(0,A.jsx)(`div`,{className:`spinner`})}),!r&&se.length===0&&(0,A.jsxs)(`div`,{className:K.empty,children:[e(`drive.noFiles`),` found`]}),(0,A.jsx)(`div`,{className:K.fileList,children:se.map(e=>{let t=fn(e),n=e.type===`image`,r=e.type===`pdf`||e.mimeType.includes(`pdf`);return(0,A.jsxs)(`div`,{className:K.fileRow,onClick:()=>{t?T(e.id,e.name):n?re(e.id,e.name):r?k(e.id,e.name):e.webViewLink&&window.open(e.webViewLink,`_blank`)},style:{cursor:t||n||r||e.webViewLink?`pointer`:`default`},children:[(0,A.jsx)(`span`,{className:K.fileIcon,children:dn(e.type,e.mimeType)}),(0,A.jsxs)(`div`,{className:K.fileInfo,children:[(0,A.jsx)(`div`,{className:K.fileName,children:e.name}),(0,A.jsxs)(`div`,{className:K.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``,e.shared?` · Shared`:``,e.starred?` ★`:``]})]}),(0,A.jsxs)(`div`,{className:K.fileBtns,children:[t&&(0,A.jsx)(`button`,{className:K.editBtn,onClick:t=>{t.stopPropagation(),T(e.id,e.name)},children:`Edit`}),n&&(0,A.jsx)(`button`,{className:K.viewBtn,onClick:t=>{t.stopPropagation(),re(e.id,e.name)},children:`View`}),r&&(0,A.jsx)(`button`,{className:K.pdfBtn,onClick:t=>{t.stopPropagation(),k(e.id,e.name)},children:`PDF`}),e.webViewLink&&(0,A.jsx)(`a`,{className:K.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open ↗`}),(0,A.jsx)(`button`,{className:K.delBtn,onClick:t=>{t.stopPropagation(),ie(e.id,e.name)},children:`Del`})]})]},e.id)})})]})}var mn={root:`_root_p82nk_1`,loading:`_loading_p82nk_10`,errorBox:`_errorBox_p82nk_12`,errorHint:`_errorHint_p82nk_13`,connectBox:`_connectBox_p82nk_17`,connectIcon:`_connectIcon_p82nk_27`,connectTitle:`_connectTitle_p82nk_28`,connectDesc:`_connectDesc_p82nk_29`,connectLink:`_connectLink_p82nk_30`,connectRow:`_connectRow_p82nk_31`,connectInput:`_connectInput_p82nk_32`,connectBtn:`_connectBtn_p82nk_43`,connectError:`_connectError_p82nk_55`,userRow:`_userRow_p82nk_57`,avatar:`_avatar_p82nk_68`,userLogin:`_userLogin_p82nk_70`,userName:`_userName_p82nk_71`,disconnectBtn:`_disconnectBtn_p82nk_73`,repoBar:`_repoBar_p82nk_84`,repoInput:`_repoInput_p82nk_90`,issuesBtn:`_issuesBtn_p82nk_102`,prsBtn:`_prsBtn_p82nk_113`,repoPills:`_repoPills_p82nk_124`,repoPill:`_repoPill_p82nk_124`,issueCount:`_issueCount_p82nk_147`,tabs:`_tabs_p82nk_153`,tab:`_tab_p82nk_153`,tabActive:`_tabActive_p82nk_172`,markRead:`_markRead_p82nk_178`,content:`_content_p82nk_189`,empty:`_empty_p82nk_191`,notifRow:`_notifRow_p82nk_193`,issueRow:`_issueRow_p82nk_193`,prRow:`_prRow_p82nk_193`,notifRepo:`_notifRepo_p82nk_207`,notifType:`_notifType_p82nk_208`,notifTitle:`_notifTitle_p82nk_209`,notifMeta:`_notifMeta_p82nk_210`,issueNum:`_issueNum_p82nk_212`,issueTitle:`_issueTitle_p82nk_213`,issueMeta:`_issueMeta_p82nk_214`,issueLabel:`_issueLabel_p82nk_215`,prNum:`_prNum_p82nk_217`,prTitle:`_prTitle_p82nk_218`,prAuthor:`_prAuthor_p82nk_219`,prDraft:`_prDraft_p82nk_220`,prMeta:`_prMeta_p82nk_221`};function hn(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(`notifs`),d=(e=``)=>{i(!0),E(e?`/api/github?repo=${encodeURIComponent(e)}`:`/api/github`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{d()},[]);let f=()=>{let e=s.trim();o(e),d(e),u(`issues`)},p=()=>{let e=s.trim();o(e),d(e),u(`prs`)},m=()=>D(`/api/github/mark-read`,{}).then(()=>d(a)),h=()=>{confirm(`Remove GitHub connection? You can reconnect anytime.`)&&D(`/api/config`,{key:`github-token`,value:``}).then(()=>{n(null),i(!1)})},[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),x=t?.user;if(r)return(0,A.jsx)(`div`,{className:mn.loading,children:(0,A.jsx)(`div`,{className:`spinner`})});let S=async()=>{g.trim()&&(b(!0),await D(`/api/config`,{key:`github-token`,value:g.trim()}),v(``),b(!1),d())};if(t?.error||!x?.login&&!r)return(0,A.jsxs)(`div`,{className:mn.connectBox,children:[(0,A.jsx)(`div`,{className:mn.connectIcon,children:`🔗`}),(0,A.jsx)(`div`,{className:mn.connectTitle,children:`Connect GitHub`}),(0,A.jsxs)(`div`,{className:mn.connectDesc,children:[`Enter your Personal Access Token to connect GitHub.`,(0,A.jsx)(`br`,{}),`Create one at `,(0,A.jsx)(`a`,{href:`https://github.com/settings/tokens`,target:`_blank`,rel:`noreferrer`,className:mn.connectLink,children:`github.com/settings/tokens`}),` with `,(0,A.jsx)(`strong`,{children:`repo`}),` scope.`]}),(0,A.jsxs)(`div`,{className:mn.connectRow,children:[(0,A.jsx)(`input`,{className:mn.connectInput,type:`password`,value:g,onChange:e=>v(e.target.value),placeholder:`ghp_xxxxxxxxxxxxxxxxxxxx`,onKeyDown:e=>e.key===`Enter`&&S()}),(0,A.jsx)(`button`,{className:mn.connectBtn,onClick:S,disabled:y||!g.trim(),children:y?`Connecting...`:`Connect`})]}),t?.error&&(0,A.jsx)(`div`,{className:mn.connectError,children:t.error})]});let C=Array.isArray(t?.notifications)?t.notifications:[],w=Array.isArray(t?.issues)?t.issues:[],ee=Array.isArray(t?.prs)?t.prs:[];return(0,A.jsxs)(`div`,{className:mn.root,children:[x?.login&&(0,A.jsxs)(`div`,{className:mn.userRow,children:[x.avatar&&(0,A.jsx)(`img`,{src:x.avatar,className:mn.avatar,alt:x.login}),(0,A.jsxs)(`div`,{style:{flex:1},children:[(0,A.jsxs)(`div`,{className:mn.userLogin,children:[`@`,x.login]}),x.name&&(0,A.jsx)(`div`,{className:mn.userName,children:x.name})]}),(0,A.jsx)(`button`,{className:mn.disconnectBtn,onClick:h,children:`Disconnect`})]}),(0,A.jsxs)(`div`,{className:mn.repoBar,children:[(0,A.jsx)(`input`,{className:mn.repoInput,value:s,onChange:e=>c(e.target.value),placeholder:`owner/repo`,onKeyDown:e=>e.key===`Enter`&&f()}),(0,A.jsx)(`button`,{className:mn.issuesBtn,onClick:f,children:`Issues`}),(0,A.jsx)(`button`,{className:mn.prsBtn,onClick:p,children:`PRs`})]}),x?.repos&&x.repos.length>0&&(0,A.jsx)(`div`,{className:mn.repoPills,children:x.repos.slice(0,12).map(e=>(0,A.jsxs)(`button`,{className:mn.repoPill,onClick:()=>{c(e.full_name),o(e.full_name),d(e.full_name),u(`issues`)},title:e.description??``,children:[e.private?`🔒 `:``,e.full_name,e.open_issues?(0,A.jsx)(`span`,{className:mn.issueCount,children:e.open_issues}):null]},e.full_name))}),(0,A.jsxs)(`div`,{className:mn.tabs,children:[(0,A.jsxs)(`button`,{className:`${mn.tab} ${l===`notifs`?mn.tabActive:``}`,onClick:()=>u(`notifs`),children:[`Notifications `,C.length>0?`(${C.length})`:``]}),w.length>0&&(0,A.jsxs)(`button`,{className:`${mn.tab} ${l===`issues`?mn.tabActive:``}`,onClick:()=>u(`issues`),children:[`Issues (`,w.length,`)`]}),ee.length>0&&(0,A.jsxs)(`button`,{className:`${mn.tab} ${l===`prs`?mn.tabActive:``}`,onClick:()=>u(`prs`),children:[`PRs (`,ee.length,`)`]}),l===`notifs`&&C.length>0&&(0,A.jsx)(`button`,{className:mn.markRead,onClick:m,children:`Mark all read`})]}),(0,A.jsxs)(`div`,{className:mn.content,children:[l===`notifs`&&(C.length===0?(0,A.jsx)(`div`,{className:mn.empty,children:`No notifications`}):C.map((e,t)=>(0,A.jsxs)(`a`,{className:mn.notifRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,A.jsx)(`span`,{className:mn.notifRepo,children:e.repo}),(0,A.jsxs)(`span`,{className:mn.notifType,children:[`[`,e.type,`]`]}),(0,A.jsx)(`div`,{className:mn.notifTitle,children:e.title}),(0,A.jsxs)(`div`,{className:mn.notifMeta,children:[e.reason,` · `,e.updated]})]},t))),l===`issues`&&(w.length===0?(0,A.jsxs)(`div`,{className:mn.empty,children:[e(`github.noIssues`),` for `,a]}):w.map((e,t)=>(0,A.jsxs)(`a`,{className:mn.issueRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,A.jsxs)(`span`,{className:mn.issueNum,children:[`#`,e.number]}),(0,A.jsx)(`span`,{className:mn.issueTitle,children:e.title}),e.assignee&&(0,A.jsxs)(`span`,{className:mn.issueMeta,children:[`→ `,e.assignee]}),e.labels&&(0,A.jsxs)(`span`,{className:mn.issueLabel,children:[`[`,e.labels,`]`]}),(0,A.jsx)(`div`,{className:mn.issueMeta,children:e.updated})]},t))),l===`prs`&&(ee.length===0?(0,A.jsxs)(`div`,{className:mn.empty,children:[`No PRs for `,a]}):ee.map((e,t)=>(0,A.jsxs)(`a`,{className:mn.prRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,A.jsxs)(`span`,{className:mn.prNum,children:[`#`,e.number]}),(0,A.jsx)(`span`,{className:mn.prTitle,children:e.title}),(0,A.jsxs)(`span`,{className:mn.prAuthor,children:[`by `,e.author]}),e.draft&&(0,A.jsx)(`span`,{className:mn.prDraft,children:`DRAFT`}),(0,A.jsx)(`div`,{className:mn.prMeta,children:e.updated})]},t)))]})]})}var gn={loading:`_loading_1h5ss_1`,errorBox:`_errorBox_1h5ss_3`,errorHint:`_errorHint_1h5ss_4`,twoPane:`_twoPane_1h5ss_7`,sidebar:`_sidebar_1h5ss_13`,sidebarTitle:`_sidebarTitle_1h5ss_24`,workspace:`_workspace_1h5ss_36`,searchRow:`_searchRow_1h5ss_42`,searchInput:`_searchInput_1h5ss_50`,searchBtn:`_searchBtn_1h5ss_63`,channelItem:`_channelItem_1h5ss_73`,channelActive:`_channelActive_1h5ss_83`,pageTitle:`_pageTitle_1h5ss_89`,pageMeta:`_pageMeta_1h5ss_97`,disconnectBtn:`_disconnectBtn_1h5ss_99`,empty:`_empty_1h5ss_110`,messagePane:`_messagePane_1h5ss_112`,channelHeader:`_channelHeader_1h5ss_120`,emptyPane:`_emptyPane_1h5ss_129`,message:`_message_1h5ss_112`,msgUser:`_msgUser_1h5ss_146`,msgText:`_msgText_1h5ss_147`,msgTs:`_msgTs_1h5ss_148`,openLink:`_openLink_1h5ss_150`,pageBody:`_pageBody_1h5ss_160`};function _n({onSaved:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),s=async()=>{if(t.trim()){if(t.startsWith(`xoxe-`)){o(`"xoxe-" è un refresh token (Token Rotation attivata). NHA ha bisogno di "xoxb-". Disabilita Token Rotation in "OAuth & Permissions → Advanced Token Security" oppure crea una nuova app senza Token Rotation.`);return}if(t.startsWith(`xoxp-`)){o(`"xoxp-" è uno User OAuth Token. NHA usa il Bot Token "xoxb-". In "OAuth & Permissions" copia "Bot User OAuth Token" (la prima riga), non lo User Token.`);return}if(t.startsWith(`xoxa-`)||t.startsWith(`xoxr-`)||t.startsWith(`xoxs-`)){o(`Token type "${t.slice(0,5)}" non supportato. NHA accetta solo Bot User OAuth Token che iniziano con "xoxb-".`);return}if(!t.startsWith(`xoxb-`)){o(`Il token deve iniziare con "xoxb-" (Bot User OAuth Token).`);return}i(!0),o(``);try{await D(`/api/config`,{key:`slack-token`,value:t.trim()}),n(``),e()}catch(e){o(e.message||`errore`)}finally{i(!1)}}};return(0,A.jsxs)(`div`,{style:{display:`flex`,gap:6,marginTop:8,flexWrap:`wrap`},children:[(0,A.jsx)(`input`,{type:`password`,autoFocus:!0,placeholder:`xoxb-...`,value:t,onChange:e=>{n(e.target.value),o(``)},onKeyDown:e=>{e.key===`Enter`&&s()},style:{flex:1,minWidth:260,padding:`6px 10px`,borderRadius:6,border:`1px solid rgba(148,163,184,0.25)`,background:`rgba(15,23,42,0.4)`,color:`inherit`,fontFamily:`SF Mono, monospace`,fontSize:12}}),(0,A.jsx)(`button`,{onClick:s,disabled:!t.trim()||r,style:{padding:`6px 16px`,borderRadius:6,border:`none`,background:`#6366f1`,color:`white`,fontWeight:700,cursor:`pointer`,opacity:!t.trim()||r?.5:1},children:r?`Salvo...`:`Salva e connetti`}),a&&(0,A.jsx)(`div`,{style:{width:`100%`,color:`#ef4444`,fontSize:11},children:a})]})}function vn(){let e=M(),[t,n]=(0,_.useState)(null),[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)(``),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(null),[w,ee]=(0,_.useState)(!0),te=(0,_.useRef)(null),ne=()=>{i(!0),E(`/api/slack/channels`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},T=e=>{o(e),C(null),E(`/api/slack/messages?channel=${e.id}&limit=80`).then(e=>c(e?.messages??[])),D(`/api/slack/mark-read`,{channel:e.id}).catch(()=>{})},O=e=>{a&&E(`/api/slack/thread?channel=${a.id}&ts=${e.ts}`).then(t=>C({parent:e,replies:(t?.messages??[]).filter(t=>t.ts!==e.ts)}))},re=async()=>{if(!(!a||!l.trim()||d)){f(!0);try{let e={channel:a.id,text:l};S&&(e.threadTs=S.parent.ts),await D(`/api/slack/send`,e),u(``),S?O(S.parent):T(a)}finally{f(!1)}}},k=async()=>{if(!h.trim()){y(null);return}x(!0);try{y((await E(`/api/slack/search?q=${encodeURIComponent(h)}&count=30`))?.results??[])}finally{x(!1)}},ie=async(e,t)=>{a&&(await D(`/api/slack/react`,{channel:a.id,ts:e.ts,emoji:t}),T(a))};if((0,_.useEffect)(()=>{ne()},[]),(0,_.useEffect)(()=>(te.current&&window.clearInterval(te.current),w&&a&&(te.current=window.setInterval(()=>T(a),15e3)),()=>{te.current&&window.clearInterval(te.current)}),[w,a?.id]),r)return(0,A.jsxs)(`div`,{className:gn.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return/token not configured|missing.*token|slack.*token/i.test(t.error)?(0,A.jsxs)(`div`,{style:{maxWidth:720,margin:`40px auto`,padding:24,background:`rgba(15,23,42,0.4)`,border:`1px solid rgba(99,102,241,0.2)`,borderRadius:12,color:`inherit`},children:[(0,A.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,marginBottom:8},children:[(0,A.jsx)(`span`,{style:{fontSize:32},children:`💬`}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{style:{fontSize:20,fontWeight:800},children:`Collega il tuo Slack a NHA`}),(0,A.jsx)(`div`,{style:{fontSize:12,opacity:.7},children:`Bastano 4 passaggi · ~3 minuti · gratis`})]})]}),(0,A.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`32px 1fr`,gap:`12px 10px`,marginTop:16,fontSize:13,lineHeight:1.55},children:[(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`1.`}),(0,A.jsxs)(`div`,{children:[`Apri `,(0,A.jsx)(`a`,{href:`https://api.slack.com/apps?new_app=1`,target:`_blank`,rel:`noreferrer`,style:{color:`#6366f1`,fontWeight:700},children:`api.slack.com/apps → Create New App`}),` e scegli "From scratch". Dai un nome (es. `,(0,A.jsx)(`code`,{children:`NHA Bot`}),`) e seleziona il tuo workspace.`]}),(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`2.`}),(0,A.jsxs)(`div`,{children:[`Nel pannello sinistro vai su `,(0,A.jsx)(`strong`,{children:`OAuth & Permissions`}),`. In "Scopes → Bot Token Scopes" aggiungi `,(0,A.jsx)(`strong`,{children:`tutti questi`}),` permessi:`,(0,A.jsx)(`div`,{style:{marginTop:6,display:`flex`,flexWrap:`wrap`,gap:4,fontFamily:`SF Mono, monospace`,fontSize:11},children:[`channels:read`,`channels:history`,`groups:read`,`groups:history`,`im:read`,`im:history`,`mpim:read`,`mpim:history`,`users:read`,`users:read.email`,`team:read`,`chat:write`,`reactions:write`,`search:read`].map(e=>(0,A.jsx)(`code`,{style:{background:`rgba(99,102,241,0.12)`,padding:`2px 6px`,borderRadius:4,color:`#c4b5fd`},children:e},e))})]}),(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`3.`}),(0,A.jsxs)(`div`,{children:[`In cima alla stessa pagina clicca `,(0,A.jsx)(`strong`,{children:`"Install to Workspace"`}),` e conferma. Slack ti darà un `,(0,A.jsx)(`strong`,{children:`Bot User OAuth Token`}),` che inizia per `,(0,A.jsx)(`code`,{children:`xoxb-`}),`.`]}),(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`4.`}),(0,A.jsxs)(`div`,{children:[`Copia il token e incollalo qui sotto, oppure vai in `,(0,A.jsx)(`strong`,{children:`Settings → Integration tokens`}),`:`,(0,A.jsx)(_n,{onSaved:ne})]})]}),(0,A.jsxs)(`div`,{style:{marginTop:18,padding:10,background:`rgba(99,102,241,0.06)`,borderRadius:8,fontSize:11,opacity:.8},children:[(0,A.jsx)(`strong`,{children:`Privacy:`}),` il token resta sul tuo computer in `,(0,A.jsx)(`code`,{children:`~/.nha/config.json`}),`. NHA non lo invia ai server.`,(0,A.jsx)(`br`,{}),(0,A.jsx)(`strong`,{children:`Tip:`}),` se hai canali privati che vuoi leggere, il bot deve essere invitato. Da Slack scrivi `,(0,A.jsx)(`code`,{children:`/invite @nome-del-bot`}),` nel canale.`]})]}):(0,A.jsxs)(`div`,{className:gn.errorBox,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`strong`,{children:`⚠ Slack:`}),` `,t.error]}),(0,A.jsxs)(`div`,{className:gn.errorHint,children:[`Se il problema persiste, verifica gli scopes del bot in `,(0,A.jsx)(`a`,{href:`https://api.slack.com/apps`,target:`_blank`,rel:`noreferrer`,children:`api.slack.com/apps`}),`.`]})]});let j=t?.channels??[],ae=p?j.filter(e=>e.name.toLowerCase().includes(p.toLowerCase())):j,oe=ae.filter(e=>!e.is_im&&!e.is_mpim&&!e.is_private),se=ae.filter(e=>e.is_private&&!e.is_im&&!e.is_mpim),ce=ae.filter(e=>e.is_im||e.is_mpim),le=(e,t)=>(0,A.jsxs)(`div`,{className:gn.message,style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,A.jsxs)(`div`,{style:{display:`flex`,alignItems:`baseline`,gap:6},children:[(0,A.jsx)(`span`,{className:gn.msgUser,style:{fontWeight:700},children:e.user||`Unknown`}),(0,A.jsx)(`span`,{className:gn.msgTs,style:{fontSize:11,opacity:.6},children:new Date(parseFloat(e.ts)*1e3).toLocaleString()}),e.reply_count?(0,A.jsxs)(`button`,{onClick:()=>O(e),style:{background:`transparent`,border:`none`,color:`#6366f1`,cursor:`pointer`,fontSize:11},children:[`💬 `,e.reply_count,` `,e.reply_count===1?`reply`:`replies`]}):null]}),(0,A.jsx)(`div`,{className:gn.msgText,style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`},children:e.text}),e.files&&e.files.length>0&&(0,A.jsx)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`,marginTop:2},children:e.files.map(e=>(0,A.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,style:{fontSize:11,padding:`2px 6px`,background:`rgba(99,102,241,0.1)`,borderRadius:4,color:`#6366f1`,textDecoration:`none`},children:[`📎 `,e.name]},e.id))}),e.reactions&&e.reactions.length>0&&(0,A.jsxs)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`,marginTop:2},children:[e.reactions.map((e,t)=>(0,A.jsxs)(`span`,{style:{fontSize:11,padding:`1px 6px`,background:`rgba(99,102,241,0.08)`,borderRadius:10},children:[`:`,e.name,`: `,e.count]},t)),(0,A.jsx)(`button`,{onClick:()=>ie(e,`thumbsup`),style:{background:`transparent`,border:`1px dashed rgba(148,163,184,0.3)`,borderRadius:10,fontSize:11,padding:`0 6px`,cursor:`pointer`},children:`+ 👍`})]})]},t);return(0,A.jsxs)(`div`,{className:gn.twoPane,children:[(0,A.jsxs)(`div`,{className:gn.sidebar,children:[(0,A.jsxs)(`div`,{className:gn.sidebarTitle,children:[(0,A.jsxs)(`span`,{children:[`💬 `,t?.workspace||`Slack`]}),(0,A.jsx)(`button`,{className:gn.disconnectBtn,onClick:ne,title:`Refresh`,children:`↻`})]}),(0,A.jsx)(`input`,{type:`text`,placeholder:`🔎 Filter channels...`,value:p,onChange:e=>m(e.target.value),style:{width:`100%`,padding:`6px 8px`,marginBottom:6,borderRadius:6,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontSize:12}}),(0,A.jsx)(`input`,{type:`text`,placeholder:`Search messages...`,value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k()},style:{width:`100%`,padding:`6px 8px`,marginBottom:8,borderRadius:6,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontSize:12}}),v!==null&&(0,A.jsxs)(`div`,{style:{marginBottom:8},children:[(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,marginBottom:2},children:b?`Searching…`:`${v.length} result(s)`}),(0,A.jsx)(`button`,{onClick:()=>{y(null),g(``)},style:{fontSize:11,background:`transparent`,border:`none`,color:`#6366f1`,cursor:`pointer`,padding:0},children:`← back to channels`})]}),v===null&&(0,A.jsxs)(A.Fragment,{children:[oe.length>0&&(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,marginTop:8,marginBottom:2},children:`Channels`}),oe.map(e=>(0,A.jsxs)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>T(e),children:[`# `,e.name,(e.unread_count??0)>0&&(0,A.jsx)(`span`,{style:{float:`right`,background:`#ef4444`,color:`white`,borderRadius:8,padding:`0 6px`,fontSize:10},children:e.unread_count})]},e.id)),se.length>0&&(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,marginTop:8,marginBottom:2},children:`Private`}),se.map(e=>(0,A.jsxs)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>T(e),children:[`🔒 `,e.name]},e.id)),ce.length>0&&(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,marginTop:8,marginBottom:2},children:`Direct Messages`}),ce.map(e=>(0,A.jsx)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>T(e),children:e.name},e.id))]})]}),(0,A.jsx)(`div`,{className:gn.messagePane,style:{display:`flex`,flexDirection:`column`,height:`100%`},children:v===null?a?S?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:gn.channelHeader,style:{display:`flex`,justifyContent:`space-between`},children:[(0,A.jsxs)(`span`,{children:[`💬 Thread in #`,a.name]}),(0,A.jsx)(`button`,{onClick:()=>C(null),style:{background:`transparent`,border:`none`,color:`#6366f1`,cursor:`pointer`},children:`✕ Close thread`})]}),(0,A.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,padding:8},children:[(0,A.jsx)(`div`,{style:{borderLeft:`3px solid #6366f1`,paddingLeft:8,marginBottom:8,opacity:.85},children:le(S.parent,-1)}),(0,A.jsxs)(`div`,{style:{fontSize:11,color:`#94a3b8`,textTransform:`uppercase`,margin:`8px 0 4px`},children:[S.replies.length,` `,S.replies.length===1?`reply`:`replies`]}),S.replies.map((e,t)=>le(e,t))]})]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:gn.channelHeader,style:{display:`flex`,justifyContent:`space-between`},children:[(0,A.jsxs)(`span`,{children:[`#`,a.name,a.topic?(0,A.jsxs)(`span`,{style:{fontWeight:400,opacity:.6,marginLeft:8},children:[`— `,a.topic]}):null]}),(0,A.jsxs)(`label`,{style:{fontSize:11,opacity:.7},children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>ee(e.target.checked)}),` auto-refresh`]})]}),(0,A.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,padding:8},children:[s.length===0&&(0,A.jsx)(`div`,{className:gn.empty,children:`No messages`}),s.map((e,t)=>le(e,t))]}),(0,A.jsxs)(`div`,{style:{borderTop:`1px solid rgba(148,163,184,0.2)`,padding:8,display:`flex`,gap:6},children:[(0,A.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&re()},placeholder:`Message #${a.name} (Cmd/Ctrl+Enter to send)`,rows:2,style:{flex:1,padding:6,borderRadius:6,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontFamily:`inherit`,resize:`vertical`}}),(0,A.jsx)(`button`,{onClick:re,disabled:!l.trim()||d,className:gn.disconnectBtn,style:{minWidth:80},children:d?`Sending…`:`Send`})]})]}):(0,A.jsx)(`div`,{className:gn.emptyPane,children:`Select a channel from the left`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:gn.channelHeader,children:[`🔎 Search results for "`,h,`"`]}),(0,A.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,padding:8},children:[v.length===0&&(0,A.jsx)(`div`,{className:gn.empty,children:`No matches`}),v.map((e,t)=>(0,A.jsxs)(`div`,{className:gn.message,style:{marginBottom:6},children:[(0,A.jsxs)(`div`,{style:{display:`flex`,alignItems:`baseline`,gap:6},children:[(0,A.jsx)(`span`,{style:{fontWeight:700},children:e.user}),(0,A.jsxs)(`span`,{style:{fontSize:11,opacity:.6},children:[`in #`,e.channel]}),(0,A.jsx)(`span`,{style:{fontSize:11,opacity:.5},children:new Date(parseFloat(e.ts)*1e3).toLocaleString()}),e.permalink&&(0,A.jsx)(`a`,{href:e.permalink,target:`_blank`,rel:`noreferrer`,style:{fontSize:11,color:`#6366f1`},children:`↗ Slack`})]}),(0,A.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,marginTop:2},children:e.text})]},t))]})]})})]})}function yn(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),d=(e=``)=>{i(!0),E(e?`/api/notion/search?q=${encodeURIComponent(e)}`:`/api/notion`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},f=e=>{o(e),E(`/api/notion/page?id=${encodeURIComponent(e.id)}`).then(e=>c(e?.content??``))};(0,_.useEffect)(()=>{d()},[]);let p=()=>d(l);if(r)return(0,A.jsxs)(`div`,{className:gn.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,A.jsxs)(`div`,{className:gn.errorBox,children:[(0,A.jsx)(`div`,{children:t.error}),(0,A.jsxs)(`div`,{className:gn.errorHint,children:[`Run: `,(0,A.jsx)(`code`,{children:`nha config set notion-token secret_YOUR_TOKEN`})]})]});let m=t?.pages??[];return(0,A.jsxs)(`div`,{className:gn.twoPane,children:[(0,A.jsxs)(`div`,{className:gn.sidebar,children:[(0,A.jsx)(`div`,{className:gn.sidebarTitle,children:`📋 Notion`}),(0,A.jsxs)(`div`,{className:gn.searchRow,children:[(0,A.jsx)(`input`,{className:gn.searchInput,value:l,onChange:e=>u(e.target.value),placeholder:`Search pages…`,onKeyDown:e=>e.key===`Enter`&&p()}),(0,A.jsx)(`button`,{className:gn.searchBtn,onClick:p,children:`Go`})]}),m.length===0&&(0,A.jsx)(`div`,{className:gn.empty,children:`No pages found`}),m.map(e=>(0,A.jsxs)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>f(e),children:[(0,A.jsx)(`div`,{className:gn.pageTitle,children:e.title||`Untitled`}),e.last_edited&&(0,A.jsx)(`div`,{className:gn.pageMeta,children:e.last_edited.slice(0,10)})]},e.id)),(0,A.jsx)(`button`,{className:gn.disconnectBtn,onClick:()=>D(`/api/config`,{key:`notion-token`,value:``}).then(()=>d()),children:`Disconnect`})]}),(0,A.jsx)(`div`,{className:gn.messagePane,children:a?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:gn.channelHeader,children:a.title}),a.url&&(0,A.jsx)(`a`,{className:gn.openLink,href:a.url,target:`_blank`,rel:`noreferrer`,children:`Open in Notion ↗`}),(0,A.jsx)(`div`,{className:gn.pageBody,dangerouslySetInnerHTML:{__html:xe(s||`Loading…`)}})]}):(0,A.jsx)(`div`,{className:gn.emptyPane,children:`Select a page`})})]})}var bn={root:`_root_1l3ll_1`,sidebar:`_sidebar_1l3ll_8`,sidebarHeader:`_sidebarHeader_1l3ll_18`,sidebarTitle:`_sidebarTitle_1l3ll_19`,sidebarBtns:`_sidebarBtns_1l3ll_21`,createBtn:`_createBtn_1l3ll_22`,joinBtn:`_joinBtn_1l3ll_23`,noChannels:`_noChannels_1l3ll_25`,channelItem:`_channelItem_1l3ll_27`,channelActive:`_channelActive_1l3ll_29`,channelName:`_channelName_1l3ll_30`,channelMeta:`_channelMeta_1l3ll_31`,channelCode:`_channelCode_1l3ll_32`,channelDel:`_channelDel_1l3ll_34`,main:`_main_1l3ll_38`,chatHeader:`_chatHeader_1l3ll_41`,chatChannelName:`_chatChannelName_1l3ll_50`,chatChannelId:`_chatChannelId_1l3ll_51`,statusDot:`_statusDot_1l3ll_52`,connected:`_connected_1l3ll_53`,disconnected:`_disconnected_1l3ll_54`,statusText:`_statusText_1l3ll_55`,messages:`_messages_1l3ll_58`,emptyMsgs:`_emptyMsgs_1l3ll_66`,msg:`_msg_1l3ll_68`,msgSelf:`_msgSelf_1l3ll_69`,msgOther:`_msgOther_1l3ll_70`,msgSender:`_msgSender_1l3ll_71`,msgContent:`_msgContent_1l3ll_72`,msgTime:`_msgTime_1l3ll_82`,inputRow:`_inputRow_1l3ll_85`,textInput:`_textInput_1l3ll_86`,sendBtn:`_sendBtn_1l3ll_88`,welcome:`_welcome_1l3ll_92`,welcomeIcon:`_welcomeIcon_1l3ll_103`,welcomeTitle:`_welcomeTitle_1l3ll_104`,welcomeSub:`_welcomeSub_1l3ll_105`,welcomeBox:`_welcomeBox_1l3ll_106`,welcomeBoxTitle:`_welcomeBoxTitle_1l3ll_107`,welcomeStep:`_welcomeStep_1l3ll_108`,welcomeHint:`_welcomeHint_1l3ll_109`,cliCmd:`_cliCmd_1l3ll_110`};function xn(e){return e.content||e.plaintext||e.message||``}function Sn(e){return e.senderName||e.senderFingerprint?.slice(0,8)||e.sender||`unknown`}function Cn(){let e=M(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(!1),[d]=(0,_.useState)(()=>`nha-ui-${Math.random().toString(36).slice(2,8)}`),f=(0,_.useRef)(null),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/collab/channels`).then(e=>{n(e?.channels??[])}).catch(()=>{})},[]),(0,_.useEffect)(()=>{if(r)return m(r),h(r),()=>{f.current?.close(),u(!1)}},[r]);let m=e=>{E(`/api/collab/messages?channelId=${e}`).then(e=>{e?.messages&&(o(e.messages),setTimeout(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight)},50))}).catch(()=>{})},h=e=>{f.current?.close();let t=window.location.protocol===`https:`?`wss:`:`ws:`,n=window.location.port===`3030`||window.location.port===`3031`?`3020`:window.location.port||`3020`,r=`${t}//${window.location.hostname}:${n}/ws/alexandria?channel=${e}&agentId=${encodeURIComponent(d)}`,i=new WebSocket(r);f.current=i,i.onopen=()=>u(!0),i.onclose=()=>u(!1),i.onmessage=e=>{try{let t=JSON.parse(e.data);if(!t)return;o(e=>[...e,{...t,id:t.id||Date.now().toString(),type:`message`}]),p.current&&(p.current.scrollTop=p.current.scrollHeight)}catch{}}},g=async()=>{let e=prompt(`Channel name:`);if(!e)return;let t=await D(`/api/collab/create`,{name:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error creating channel`);return}let r=t.id;await D(`/api/collab/channels`,{id:r,name:e,role:`creator`}).catch(()=>{});let a={id:r,name:e,role:`creator`};n(e=>[...e,a]),i(r),prompt(`Share this invite code with collaborators:`,r)},v=async()=>{let e=prompt(`Invite code:`);if(!e)return;let t=await D(`/api/collab/join`,{channelId:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error joining channel`);return}let r=t.name||e.slice(0,8);await D(`/api/collab/channels`,{id:e,name:r,role:`member`}).catch(()=>{}),n(t=>[...t,{id:e,name:r,role:`member`}]),i(e)},y=async e=>{confirm(`Delete this channel? Messages will be lost.`)&&(D(`/api/collab/delete`,{channelId:e}).catch(()=>{}),n(t=>t.filter(t=>t.id!==e)),r===e&&(i(null),o([]),f.current?.close(),u(!1)))},b=async()=>{let e=s.trim();if(!e||!r)return;c(``);let t=await D(`/api/collab/send`,{channelId:r,message:e}).catch(()=>null);t?.error&&alert(t.error),l||m(r)},x=e=>{navigator.clipboard.writeText(e).catch(()=>{})};return(0,A.jsxs)(`div`,{className:bn.root,children:[(0,A.jsxs)(`div`,{className:bn.sidebar,children:[(0,A.jsx)(`div`,{className:bn.sidebarHeader,children:(0,A.jsx)(`div`,{className:bn.sidebarTitle,children:`Alexandria`})}),(0,A.jsxs)(`div`,{className:bn.sidebarBtns,children:[(0,A.jsx)(`button`,{className:bn.createBtn,onClick:g,children:`+ Create`}),(0,A.jsx)(`button`,{className:bn.joinBtn,onClick:v,children:`Join`})]}),t.length===0?(0,A.jsxs)(`div`,{className:bn.noChannels,children:[e(`collab.noChannels`),` yet`]}):t.map(e=>(0,A.jsxs)(`div`,{className:`${bn.channelItem} ${r===e.id?bn.channelActive:``}`,onClick:()=>i(e.id),children:[(0,A.jsx)(`div`,{className:bn.channelName,children:e.name}),(0,A.jsxs)(`div`,{className:bn.channelMeta,children:[(0,A.jsxs)(`span`,{className:bn.channelCode,onClick:t=>{t.stopPropagation(),x(e.id)},title:`Click to copy invite code`,children:[e.id.slice(0,8),`…`]}),(0,A.jsx)(`button`,{className:bn.channelDel,onClick:t=>{t.stopPropagation(),y(e.id)},children:`del`})]})]},e.id))]}),(0,A.jsx)(`div`,{className:bn.main,children:r?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:bn.chatHeader,children:[(0,A.jsx)(`div`,{className:bn.chatChannelName,children:t.find(e=>e.id===r)?.name??r.slice(0,12)}),(0,A.jsx)(`div`,{className:bn.chatChannelId,children:r}),(0,A.jsx)(`div`,{className:`${bn.statusDot} ${l?bn.connected:bn.disconnected}`}),(0,A.jsx)(`span`,{className:bn.statusText,children:l?`Live`:`HTTP`})]}),(0,A.jsxs)(`div`,{className:bn.messages,ref:p,children:[a.length===0&&(0,A.jsx)(`div`,{className:bn.emptyMsgs,children:`No messages yet`}),a.map((e,t)=>{let n=Sn(e),r=xn(e),i=n===d;return(0,A.jsxs)(`div`,{className:`${bn.msg} ${i?bn.msgSelf:bn.msgOther}`,children:[!i&&(0,A.jsx)(`div`,{className:bn.msgSender,children:n}),(0,A.jsx)(`div`,{className:bn.msgContent,children:r}),(0,A.jsx)(`div`,{className:bn.msgTime,children:new Date(e.timestamp).toLocaleTimeString()})]},e.id||t)})]}),(0,A.jsxs)(`div`,{className:bn.inputRow,children:[(0,A.jsx)(`input`,{className:bn.textInput,value:s,onChange:e=>c(e.target.value),placeholder:`Send an encrypted message…`,onKeyDown:e=>e.key===`Enter`&&!e.shiftKey&&b()}),(0,A.jsx)(`button`,{className:bn.sendBtn,onClick:b,disabled:!s.trim(),children:e(`collab.send`)})]})]}):(0,A.jsxs)(`div`,{className:bn.welcome,children:[(0,A.jsx)(`div`,{className:bn.welcomeIcon,children:`🔐`}),(0,A.jsx)(`div`,{className:bn.welcomeTitle,children:`Alexandria`}),(0,A.jsx)(`div`,{className:bn.welcomeSub,children:`E2E encrypted messaging for AI agents and teams`}),(0,A.jsxs)(`div`,{className:bn.welcomeBox,children:[(0,A.jsx)(`div`,{className:bn.welcomeBoxTitle,children:`HOW TO USE`}),(0,A.jsxs)(`div`,{className:bn.welcomeStep,children:[(0,A.jsx)(`strong`,{children:`1. Create a channel`}),` — Click [+ Create] in the sidebar. Give it a name.`]}),(0,A.jsx)(`div`,{className:bn.welcomeHint,children:`You get an invite code. Share it with your team or another AI session.`}),(0,A.jsxs)(`div`,{className:bn.welcomeStep,children:[(0,A.jsx)(`strong`,{children:`2. Others join`}),` — They click [Join] and paste the invite code.`]}),(0,A.jsx)(`div`,{className:bn.welcomeHint,children:`Works from this web UI, the Android app, or the CLI.`}),(0,A.jsxs)(`div`,{className:bn.welcomeStep,children:[(0,A.jsx)(`strong`,{children:`3. Chat encrypted`}),` — All messages are E2E encrypted. The server sees only ciphertext.`]})]}),(0,A.jsxs)(`div`,{className:bn.welcomeBox,children:[(0,A.jsx)(`div`,{className:bn.welcomeBoxTitle,children:`FROM CLI (same channels)`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab create "Project X"`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab join <invite-code>`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab send "Hello from CLI"`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab read`})]})]})})]})}var wn=[],Tn=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?Tn:wn).push(n+=e[t])})();function En(e){if(e<768)return!1;for(let t=0,n=wn.length;;){let r=t+n>>1;if(e<wn[r])n=r;else if(e>=Tn[r])t=r+1;else return!0;if(t==n)return!1}}function Dn(e){return e>=127462&&e<=127487}var On=8205;function kn(e,t,n=!0,r=!0){return(n?An:jn)(e,t,r)}function An(e,t,n){if(t==e.length)return t;t&&Nn(e.charCodeAt(t))&&Pn(e.charCodeAt(t-1))&&t--;let r=Mn(e,t);for(t+=Fn(r);t<e.length;){let i=Mn(e,t);if(r==On||i==On||n&&En(i))t+=Fn(i),r=i;else if(Dn(i)){let n=0,r=t-2;for(;r>=0&&Dn(Mn(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function jn(e,t,n){for(;t>0;){let r=An(e,t-2,n);if(r<t)return r;t--}return 0}function Mn(e,t){let n=e.charCodeAt(t);if(!Pn(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return Nn(r)?(n-55296<<10)+(r-56320)+65536:n}function Nn(e){return e>=56320&&e<57344}function Pn(e){return e>=55296&&e<56320}function Fn(e){return e<65536?1:2}var In=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=Kn(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Rn.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Kn(this,e,t);let n=[];return this.decompose(e,t,n,0),Rn.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new Hn(this),i=new Hn(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new Hn(this,e)}iterRange(e,t=this.length){return new Un(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Wn(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new Ln(t):Rn.from(Ln.split(t,[]))}},Ln=class e extends In{constructor(e,t=zn(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new Gn(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(Vn(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=Bn(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=Kn(this,t,n);let i=Bn(this.text,Bn(r.text,Vn(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):Rn.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
660
+ Be concise. Highlight what each agent contributed uniquely. Give your own synthesis verdict at the end.`},e=>{i+=e,g(i)})}catch{}finally{y(!1)}},he=e=>{let t=window.SpeechRecognition??window.webkitSpeechRecognition;if(!t){alert(`Speech recognition not supported.`);return}let n=T.current.get(e);if(l.find(t=>t.agent.id===e)?.voiceActive&&n){n.stop(),N(e,{voiceActive:!1});return}let r=new t;T.current.set(e,r),r.lang=`it-IT`,r.continuous=!1,r.interimResults=!1,r.onresult=t=>{let n=t.results[0][0].transcript;N(e,{input:(l.find(t=>t.agent.id===e)?.input??``)+(l.find(t=>t.agent.id===e)?.input?` `:``)+n})},r.onend=()=>N(e,{voiceActive:!1}),r.onerror=()=>N(e,{voiceActive:!1}),r.start(),N(e,{voiceActive:!0})},ge=(e,t)=>{if(!t)return;let n=t.name.toLowerCase().endsWith(`.pdf`)||t.type===`application/pdf`,r=new FileReader;n?(r.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedFile:{name:t.name,size:t.size,base64:r,mimeType:`application/pdf`,isPDF:!0},attachedImage:null})},r.readAsDataURL(t)):(r.onload=n=>{N(e,{attachedFile:{name:t.name,size:t.size,content:n.target?.result},attachedImage:null})},r.readAsText(t))},_e=(e,t)=>{if(!t)return;let n=new FileReader;n.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedImage:{name:t.name,size:t.size,base64:r,mimeType:t.type||`image/jpeg`},attachedFile:null})},n.readAsDataURL(t)},ve=()=>{x({name:``,tagline:``,systemPrompt:``}),C(`create`),ee(``)},ye=async e=>{let t=await E(`/api/agents/${e.id}`).catch(()=>null);x({name:e.id,tagline:t?.tagline??e.description,systemPrompt:t?.systemPrompt??``}),C(`edit`),ee(``)},be=async()=>{if(b){if(!b.tagline.trim()||!b.systemPrompt.trim()){ee(`Tagline and system prompt are required.`);return}ne(!0),ee(``);try{if(S===`create`){let e=b.name.toLowerCase().replace(/[^a-z0-9_-]/g,``);if(!e){ee(`Agent name required (lowercase, no spaces).`),ne(!1);return}let t=await D(`/api/agents`,{name:e,tagline:b.tagline,systemPrompt:b.systemPrompt});if(t?.error){ee(`Error: `+t.error),ne(!1);return}}else await D(`/api/agents/${b.name}`,{tagline:b.tagline,systemPrompt:b.systemPrompt,category:`custom`},`PUT`);x(null),oe()}catch(e){ee(`Error: `+e.message)}finally{ne(!1)}}},P=e=>{confirm(`Delete agent "${e.label}"?`)&&D(`/api/agents/${e.id}`,{},`DELETE`).then(()=>oe())};return r?(0,A.jsx)(`div`,{className:G.root,children:(0,A.jsx)(`div`,{className:G.loading,children:(0,A.jsx)(`div`,{className:`spinner`})})}):(0,A.jsxs)(`div`,{className:G.root,children:[(0,A.jsxs)(`div`,{className:G.gridSection,children:[(0,A.jsxs)(`div`,{className:G.gridHeader,children:[(0,A.jsxs)(`div`,{className:G.headerRow,children:[(0,A.jsx)(`input`,{className:G.search,value:a,onChange:e=>o(e.target.value),placeholder:`Search agents…`}),(0,A.jsx)(`button`,{className:G.createBtn,onClick:ve,children:`+ Create`})]}),(0,A.jsx)(`div`,{className:G.catTabs,children:se.map(e=>(0,A.jsxs)(`button`,{className:`${G.catTab} ${s===e?G.catActive:``}`,onClick:()=>c(e),children:[e,` (`,e===`All`?t.length:t.filter(t=>t.category===e).length,`)`]},e))})]}),(0,A.jsx)(`div`,{className:G.grid,children:ce.map(e=>{let t=l.some(t=>t.agent.id===e.id);return(0,A.jsxs)(`div`,{className:`${G.agentCard} ${t?G.agentActive:``}`,onClick:()=>le(e),children:[(0,A.jsxs)(`div`,{className:G.agentCardTop,children:[(0,A.jsx)(`div`,{className:G.agentIcon,children:e.icon}),e.isCustom&&(0,A.jsxs)(`div`,{className:G.agentActions,children:[(0,A.jsx)(`button`,{className:G.agentEditBtn,onClick:t=>{t.stopPropagation(),ye(e)},children:`✏️`}),(0,A.jsx)(`button`,{className:G.agentDelBtn,onClick:t=>{t.stopPropagation(),P(e)},children:`🗑`})]})]}),(0,A.jsx)(`div`,{className:G.agentLabel,children:e.label}),(0,A.jsx)(`div`,{className:G.agentDesc,children:e.description}),(0,A.jsx)(`div`,{className:G.agentCat,children:e.category})]},e.id)})})]}),(0,A.jsx)(`div`,{className:G.chatArea,children:l.length===0?(0,A.jsxs)(`div`,{className:G.emptyChat,children:[(0,A.jsx)(`span`,{children:`Click an agent above to open a chat`}),(0,A.jsx)(`span`,{className:G.emptyChatHint,children:`Open multiple agents to run them in parallel`})]}):l.map(e=>{let{agent:t}=e,n=e.attachedFile?`📎 ${e.attachedFile.name}`:e.attachedImage?`🖼 ${e.attachedImage.name}`:null;return(0,A.jsxs)(`div`,{className:G.chatPanel,children:[(0,A.jsxs)(`div`,{className:G.chatHeader,children:[(0,A.jsx)(`span`,{className:G.chatIcon,children:t.icon}),(0,A.jsxs)(`div`,{className:G.chatHeaderInfo,children:[(0,A.jsx)(`div`,{className:G.chatAgentName,children:t.label}),(0,A.jsx)(`div`,{className:G.chatAgentDesc,children:t.description})]}),(0,A.jsx)(`button`,{className:G.closeChat,onClick:()=>ue(t.id),children:`✕`})]}),(0,A.jsxs)(`div`,{className:G.chatMessages,ref:e=>{k.current.set(t.id,e)},children:[e.history.length===0&&(0,A.jsxs)(`div`,{className:G.chatEmpty,children:[`Ask `,t.label,` anything…`]}),e.history.map((e,t)=>(0,A.jsx)(`div`,{className:`${G.chatMsg} ${e.role===`user`?G.msgUser:G.msgAgent}`,children:e.role===`assistant`?(0,A.jsx)(`div`,{dangerouslySetInnerHTML:{__html:xe(e.content||`…`)}}):(0,A.jsx)(`span`,{children:e.content})},t)),e.streaming&&e.history[e.history.length-1]?.role===`assistant`&&e.history[e.history.length-1]?.content===``&&(0,A.jsxs)(`div`,{className:G.thinking,children:[(0,A.jsx)(`span`,{className:G.dot}),(0,A.jsx)(`span`,{className:G.dot}),(0,A.jsx)(`span`,{className:G.dot})]})]}),n&&(0,A.jsxs)(`div`,{className:G.attachBar,children:[(0,A.jsx)(`span`,{children:n}),(0,A.jsx)(`button`,{className:G.attachClear,onClick:()=>N(t.id,{attachedFile:null,attachedImage:null}),children:`×`})]}),(0,A.jsxs)(`div`,{className:G.chatInput,children:[(0,A.jsxs)(`div`,{className:G.chatTools,children:[(0,A.jsx)(`button`,{className:`${G.toolBtn} ${e.voiceActive?G.toolBtnActive:``}`,onClick:()=>he(t.id),title:`Voice`,children:`🎤`}),(0,A.jsx)(`button`,{className:G.toolBtn,onClick:()=>ie.current.get(t.id)?.click(),title:`Attach file`,children:`📎`}),(0,A.jsx)(`button`,{className:G.toolBtn,onClick:()=>j.current.get(t.id)?.click(),title:`Attach image`,children:`🖼`}),(0,A.jsx)(`input`,{type:`file`,style:{display:`none`},ref:e=>{ie.current.set(t.id,e)},onChange:e=>ge(t.id,e.target.files?.[0])}),(0,A.jsx)(`input`,{type:`file`,accept:`image/*`,style:{display:`none`},ref:e=>{j.current.set(t.id,e)},onChange:e=>_e(t.id,e.target.files?.[0])})]}),(0,A.jsxs)(`div`,{className:G.chatInputRow,children:[(0,A.jsx)(`textarea`,{className:G.chatTextarea,value:e.input,onChange:e=>N(t.id,{input:e.target.value}),placeholder:`Message ${t.label}…`,rows:2,onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),pe(e,e.input,e.attachedFile,e.attachedImage))}}),(0,A.jsx)(`button`,{className:G.sendBtn,onClick:()=>pe(e,e.input,e.attachedFile,e.attachedImage),disabled:e.streaming||!e.input.trim()&&!e.attachedFile&&!e.attachedImage,children:e.streaming?`…`:`→`})]})]})]},t.id)})}),l.length>=2&&(0,A.jsxs)(`div`,{className:G.orchBar,children:[(0,A.jsxs)(`div`,{className:G.orchLabel,children:[`🎼 Conductor · `,l.map(e=>`${e.agent.icon} ${e.agent.label}`).join(` · `)]}),(0,A.jsxs)(`div`,{className:G.orchRow,children:[(0,A.jsx)(`textarea`,{ref:ae,className:G.orchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Ask all agents — Conductor will synthesize a unified response…`,rows:1,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),me())}}),(0,A.jsx)(`button`,{className:G.orchBtn,onClick:me,disabled:p||v||!d.trim(),children:p?`⏳`:v?`🔄`:`🎼 Run`})]}),(v||h)&&(0,A.jsxs)(`div`,{className:G.orchSynthesis,children:[(0,A.jsxs)(`div`,{className:G.orchSynthHeader,children:[(0,A.jsx)(`span`,{children:`🎼 Conductor Synthesis`}),v&&(0,A.jsx)(`span`,{className:G.orchSynthSpinner,children:`synthesizing…`})]}),(0,A.jsx)(`div`,{className:G.orchSynthBody,dangerouslySetInnerHTML:{__html:xe(h||`…`)}})]})]}),b&&(0,A.jsx)(`div`,{className:G.modalOverlay,onClick:e=>{e.target===e.currentTarget&&x(null)},children:(0,A.jsxs)(`div`,{className:G.modal,children:[(0,A.jsx)(`div`,{className:G.modalTitle,children:S===`create`?`+ New Agent`:`✏️ Edit Agent`}),S===`create`&&(0,A.jsxs)(`div`,{className:G.formField,children:[(0,A.jsx)(`label`,{className:G.formLabel,children:`Agent name (lowercase, no spaces)`}),(0,A.jsx)(`input`,{className:G.formInput,placeholder:`my-agent`,value:b.name,onChange:e=>x(t=>t&&{...t,name:e.target.value})})]}),(0,A.jsxs)(`div`,{className:G.formField,children:[(0,A.jsx)(`label`,{className:G.formLabel,children:`Tagline`}),(0,A.jsx)(`input`,{className:G.formInput,placeholder:`Short description`,value:b.tagline,onChange:e=>x(t=>t&&{...t,tagline:e.target.value})})]}),(0,A.jsxs)(`div`,{className:G.formField,children:[(0,A.jsx)(`label`,{className:G.formLabel,children:`System Prompt`}),(0,A.jsx)(`textarea`,{className:G.formTextarea,placeholder:`You are an expert in…`,value:b.systemPrompt,onChange:e=>x(t=>t&&{...t,systemPrompt:e.target.value})})]}),w&&(0,A.jsx)(`div`,{className:G.formError,children:w}),(0,A.jsxs)(`div`,{className:G.modalBtns,children:[(0,A.jsx)(`button`,{className:G.cancelBtn,onClick:()=>x(null),children:e(`common.cancel`)}),(0,A.jsx)(`button`,{className:G.modalSaveBtn,onClick:be,disabled:te,children:te?`…`:S===`create`?`Create Agent`:`Save`})]})]})})]})}var K={root:`_root_1mam6_1`,error:`_error_1mam6_10`,errorHint:`_errorHint_1mam6_16`,quotaBar:`_quotaBar_1mam6_29`,quotaText:`_quotaText_1mam6_37`,quotaUsed:`_quotaUsed_1mam6_43`,quotaPct:`_quotaPct_1mam6_44`,quotaTrack:`_quotaTrack_1mam6_46`,quotaFill:`_quotaFill_1mam6_53`,actionBar:`_actionBar_1mam6_59`,filterBtn:`_filterBtn_1mam6_67`,filterActive:`_filterActive_1mam6_79`,spacer:`_spacer_1mam6_85`,newBtn:`_newBtn_1mam6_87`,uploadBtn:`_uploadBtn_1mam6_98`,searchRow:`_searchRow_1mam6_108`,searchInput:`_searchInput_1mam6_114`,searchBtn:`_searchBtn_1mam6_126`,loading:`_loading_1mam6_136`,empty:`_empty_1mam6_141`,fileList:`_fileList_1mam6_151`,fileRow:`_fileRow_1mam6_159`,fileIcon:`_fileIcon_1mam6_172`,fileInfo:`_fileInfo_1mam6_174`,fileName:`_fileName_1mam6_176`,fileMeta:`_fileMeta_1mam6_184`,fileBtns:`_fileBtns_1mam6_190`,editBtn:`_editBtn_1mam6_196`,viewBtn:`_viewBtn_1mam6_197`,pdfBtn:`_pdfBtn_1mam6_198`,openBtn:`_openBtn_1mam6_199`,delBtn:`_delBtn_1mam6_200`,editorRoot:`_editorRoot_1mam6_204`,editorToolbar:`_editorToolbar_1mam6_211`,backBtn:`_backBtn_1mam6_221`,editorName:`_editorName_1mam6_231`,saveBtn:`_saveBtn_1mam6_238`,editorArea:`_editorArea_1mam6_251`,editorMeta:`_editorMeta_1mam6_266`,viewerRoot:`_viewerRoot_1mam6_276`,imgContainer:`_imgContainer_1mam6_283`,imgView:`_imgView_1mam6_292`,pdfFrame:`_pdfFrame_1mam6_298`};function dn(e,t){return e===`folder`?`📁`:e===`image`?`🖼`:e===`pdf`||t.includes(`pdf`)?`📕`:e===`video`?`🎬`:e===`audio`?`🎵`:t.includes(`spreadsheet`)||t.includes(`excel`)?`📊`:t.includes(`presentation`)||t.includes(`powerpoint`)?`📽`:t.includes(`document`)||t.includes(`word`)?`📄`:t.includes(`zip`)||t.includes(`archive`)?`📦`:`📄`}function fn(e){let t=e.mimeType;return e.type===`text`||e.type===`doc`||t.includes(`text`)||t.includes(`json`)||t.includes(`javascript`)||t.includes(`xml`)||t.includes(`csv`)||t.includes(`yaml`)||t.includes(`markdown`)||t.includes(`html`)||t.includes(`css`)||t.includes(`python`)||t.includes(`vnd.google-apps.document`)}function pn(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(`list`),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(!1),w=(0,_.useRef)(null),ee=(e=s,t=l)=>{i(!0);let r=`/api/drive`;e&&(r+=`?filter=${e}`),t&&(r+=`${e?`&`:`?`}search=${encodeURIComponent(t)}`),E(r).then(e=>{n(e??{files:[]}),i(!1)}).catch(e=>{o(e.message??`Error`),i(!1)})};(0,_.useEffect)(()=>{ee()},[]);let te=e=>{c(e),ee(e,l)},ne=()=>{u(d),ee(s,d)},T=(e,t)=>{i(!0),E(`/api/drive/read/${e}`).then(n=>{g({id:e,name:t,content:n?.content??``}),y(n?.content??``),m(`editor`),i(!1)}).catch(()=>i(!1))},O=async()=>{if(h&&confirm(`Save changes to "${h.name}" on Drive?`)){C(!0);try{await D(`/api/drive/update/${h.id}`,{content:v}),g(e=>e&&{...e,content:v}),alert(`Saved!`)}catch(e){alert(`Save failed: `+e.message)}finally{C(!1)}}},re=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{x({id:e,name:t,src:`data:${n?.mimeType??`image/jpeg`};base64,${n?.base64}`,mode:`image`}),m(`image`),i(!1)}).catch(()=>i(!1))},k=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{let r=Uint8Array.from(atob(n?.base64??``),e=>e.charCodeAt(0)),a=new Blob([r],{type:`application/pdf`});x({id:e,name:t,src:URL.createObjectURL(a),mode:`pdf`}),m(`pdf`),i(!1)}).catch(()=>i(!1))},ie=(e,t)=>{confirm(`Delete "${t}" from Drive? (moved to trash)`)&&D(`/api/drive/delete/${e}`,{}).then(()=>{n(null),ee()})},j=()=>{let e=prompt(`File name (e.g. notes.txt, script.py):`);e&&D(`/api/drive/upload`,{name:e,content:``,mimeType:`text/plain`}).then(t=>{t?.id?T(t.id,e):ee()}).catch(e=>alert(`Error: `+e.message))},ae=()=>{w.current?.click()},oe=e=>{if(!e)return;let t=new FileReader;t.onload=t=>{let r=(t.target?.result).split(`,`)[1]??``;D(`/api/drive/upload`,{name:e.name,content:r,mimeType:e.type||`application/octet-stream`,encoding:`base64`}).then(()=>{n(null),ee()}).catch(e=>alert(`Upload error: `+e.message))},t.readAsDataURL(e)};if(a)return(0,A.jsxs)(`div`,{className:K.error,children:[(0,A.jsx)(`div`,{children:a}),(0,A.jsxs)(`div`,{className:K.errorHint,children:[`Run: `,(0,A.jsx)(`code`,{children:`nha google revoke`}),` then `,(0,A.jsx)(`code`,{children:`nha google auth`})]})]});if(p===`editor`&&h)return(0,A.jsxs)(`div`,{className:K.editorRoot,children:[(0,A.jsxs)(`div`,{className:K.editorToolbar,children:[(0,A.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,A.jsx)(`span`,{className:K.editorName,children:h.name}),(0,A.jsx)(`button`,{className:K.saveBtn,onClick:O,disabled:S,children:S?`Saving…`:`Save to Drive`})]}),(0,A.jsx)(`textarea`,{className:K.editorArea,value:v,onChange:e=>y(e.target.value),spellCheck:!1,onKeyDown:e=>{if(e.key===`Tab`){e.preventDefault();let t=e.currentTarget.selectionStart,n=e.currentTarget.selectionEnd,r=e.currentTarget.value;e.currentTarget.value=r.slice(0,t)+` `+r.slice(n),e.currentTarget.selectionStart=e.currentTarget.selectionEnd=t+2}}}),(0,A.jsxs)(`div`,{className:K.editorMeta,children:[`File ID: `,h.id,` · Tab = 2 spaces · Not auto-saved`]})]});if(p===`image`&&b)return(0,A.jsxs)(`div`,{className:K.viewerRoot,children:[(0,A.jsxs)(`div`,{className:K.editorToolbar,children:[(0,A.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,A.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,A.jsx)(`div`,{className:K.imgContainer,children:(0,A.jsx)(`img`,{src:b.src,alt:b.name,className:K.imgView})})]});if(p===`pdf`&&b)return(0,A.jsxs)(`div`,{className:K.viewerRoot,children:[(0,A.jsxs)(`div`,{className:K.editorToolbar,children:[(0,A.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,A.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,A.jsx)(`iframe`,{className:K.pdfFrame,src:b.src,title:b.name})]});let se=t?.files??[],ce=t?.quota;return(0,A.jsxs)(`div`,{className:K.root,children:[ce&&(0,A.jsxs)(`div`,{className:K.quotaBar,children:[(0,A.jsxs)(`div`,{className:K.quotaText,children:[(0,A.jsxs)(`span`,{className:K.quotaUsed,children:[ce.usage,` of `,ce.limit,` used`]}),(0,A.jsxs)(`span`,{className:K.quotaPct,children:[ce.percentUsed,`%`]})]}),(0,A.jsx)(`div`,{className:K.quotaTrack,children:(0,A.jsx)(`div`,{className:K.quotaFill,style:{width:`${Math.min(ce.percentUsed,100)}%`,background:ce.percentUsed>90?`var(--red)`:ce.percentUsed>70?`var(--amber)`:`var(--green)`}})})]}),(0,A.jsxs)(`div`,{className:K.actionBar,children:[[``,`recent`,`starred`,`shared`].map(e=>(0,A.jsx)(`button`,{className:`${K.filterBtn} ${s===e?K.filterActive:``}`,onClick:()=>te(e),children:e?e.charAt(0).toUpperCase()+e.slice(1):`All Files`},e)),(0,A.jsx)(`div`,{className:K.spacer}),(0,A.jsx)(`button`,{className:K.newBtn,onClick:j,children:`+ New File`}),(0,A.jsx)(`button`,{className:K.uploadBtn,onClick:ae,children:e(`drive.upload`)}),(0,A.jsx)(`input`,{ref:w,type:`file`,style:{display:`none`},onChange:e=>oe(e.target.files?.[0])})]}),(0,A.jsxs)(`div`,{className:K.searchRow,children:[(0,A.jsx)(`input`,{className:K.searchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Search files…`,onKeyDown:e=>e.key===`Enter`&&ne()}),(0,A.jsx)(`button`,{className:K.searchBtn,onClick:ne,children:`Search`})]}),r&&(0,A.jsx)(`div`,{className:K.loading,children:(0,A.jsx)(`div`,{className:`spinner`})}),!r&&se.length===0&&(0,A.jsxs)(`div`,{className:K.empty,children:[e(`drive.noFiles`),` found`]}),(0,A.jsx)(`div`,{className:K.fileList,children:se.map(e=>{let t=fn(e),n=e.type===`image`,r=e.type===`pdf`||e.mimeType.includes(`pdf`);return(0,A.jsxs)(`div`,{className:K.fileRow,onClick:()=>{t?T(e.id,e.name):n?re(e.id,e.name):r?k(e.id,e.name):e.webViewLink&&window.open(e.webViewLink,`_blank`)},style:{cursor:t||n||r||e.webViewLink?`pointer`:`default`},children:[(0,A.jsx)(`span`,{className:K.fileIcon,children:dn(e.type,e.mimeType)}),(0,A.jsxs)(`div`,{className:K.fileInfo,children:[(0,A.jsx)(`div`,{className:K.fileName,children:e.name}),(0,A.jsxs)(`div`,{className:K.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``,e.shared?` · Shared`:``,e.starred?` ★`:``]})]}),(0,A.jsxs)(`div`,{className:K.fileBtns,children:[t&&(0,A.jsx)(`button`,{className:K.editBtn,onClick:t=>{t.stopPropagation(),T(e.id,e.name)},children:`Edit`}),n&&(0,A.jsx)(`button`,{className:K.viewBtn,onClick:t=>{t.stopPropagation(),re(e.id,e.name)},children:`View`}),r&&(0,A.jsx)(`button`,{className:K.pdfBtn,onClick:t=>{t.stopPropagation(),k(e.id,e.name)},children:`PDF`}),e.webViewLink&&(0,A.jsx)(`a`,{className:K.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open ↗`}),(0,A.jsx)(`button`,{className:K.delBtn,onClick:t=>{t.stopPropagation(),ie(e.id,e.name)},children:`Del`})]})]},e.id)})})]})}var mn={root:`_root_p82nk_1`,loading:`_loading_p82nk_10`,errorBox:`_errorBox_p82nk_12`,errorHint:`_errorHint_p82nk_13`,connectBox:`_connectBox_p82nk_17`,connectIcon:`_connectIcon_p82nk_27`,connectTitle:`_connectTitle_p82nk_28`,connectDesc:`_connectDesc_p82nk_29`,connectLink:`_connectLink_p82nk_30`,connectRow:`_connectRow_p82nk_31`,connectInput:`_connectInput_p82nk_32`,connectBtn:`_connectBtn_p82nk_43`,connectError:`_connectError_p82nk_55`,userRow:`_userRow_p82nk_57`,avatar:`_avatar_p82nk_68`,userLogin:`_userLogin_p82nk_70`,userName:`_userName_p82nk_71`,disconnectBtn:`_disconnectBtn_p82nk_73`,repoBar:`_repoBar_p82nk_84`,repoInput:`_repoInput_p82nk_90`,issuesBtn:`_issuesBtn_p82nk_102`,prsBtn:`_prsBtn_p82nk_113`,repoPills:`_repoPills_p82nk_124`,repoPill:`_repoPill_p82nk_124`,issueCount:`_issueCount_p82nk_147`,tabs:`_tabs_p82nk_153`,tab:`_tab_p82nk_153`,tabActive:`_tabActive_p82nk_172`,markRead:`_markRead_p82nk_178`,content:`_content_p82nk_189`,empty:`_empty_p82nk_191`,notifRow:`_notifRow_p82nk_193`,issueRow:`_issueRow_p82nk_193`,prRow:`_prRow_p82nk_193`,notifRepo:`_notifRepo_p82nk_207`,notifType:`_notifType_p82nk_208`,notifTitle:`_notifTitle_p82nk_209`,notifMeta:`_notifMeta_p82nk_210`,issueNum:`_issueNum_p82nk_212`,issueTitle:`_issueTitle_p82nk_213`,issueMeta:`_issueMeta_p82nk_214`,issueLabel:`_issueLabel_p82nk_215`,prNum:`_prNum_p82nk_217`,prTitle:`_prTitle_p82nk_218`,prAuthor:`_prAuthor_p82nk_219`,prDraft:`_prDraft_p82nk_220`,prMeta:`_prMeta_p82nk_221`};function hn(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(`notifs`),d=(e=``)=>{i(!0),E(e?`/api/github?repo=${encodeURIComponent(e)}`:`/api/github`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{d()},[]);let f=()=>{let e=s.trim();o(e),d(e),u(`issues`)},p=()=>{let e=s.trim();o(e),d(e),u(`prs`)},m=()=>D(`/api/github/mark-read`,{}).then(()=>d(a)),h=()=>{confirm(`Remove GitHub connection? You can reconnect anytime.`)&&D(`/api/config`,{key:`github-token`,value:``}).then(()=>{n(null),i(!1)})},[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),x=t?.user;if(r)return(0,A.jsx)(`div`,{className:mn.loading,children:(0,A.jsx)(`div`,{className:`spinner`})});let S=async()=>{g.trim()&&(b(!0),await D(`/api/config`,{key:`github-token`,value:g.trim()}),v(``),b(!1),d())};if(t?.error||!x?.login&&!r)return(0,A.jsxs)(`div`,{className:mn.connectBox,children:[(0,A.jsx)(`div`,{className:mn.connectIcon,children:`🔗`}),(0,A.jsx)(`div`,{className:mn.connectTitle,children:`Connect GitHub`}),(0,A.jsxs)(`div`,{className:mn.connectDesc,children:[`Enter your Personal Access Token to connect GitHub.`,(0,A.jsx)(`br`,{}),`Create one at `,(0,A.jsx)(`a`,{href:`https://github.com/settings/tokens`,target:`_blank`,rel:`noreferrer`,className:mn.connectLink,children:`github.com/settings/tokens`}),` with `,(0,A.jsx)(`strong`,{children:`repo`}),` scope.`]}),(0,A.jsxs)(`div`,{className:mn.connectRow,children:[(0,A.jsx)(`input`,{className:mn.connectInput,type:`password`,value:g,onChange:e=>v(e.target.value),placeholder:`ghp_xxxxxxxxxxxxxxxxxxxx`,onKeyDown:e=>e.key===`Enter`&&S()}),(0,A.jsx)(`button`,{className:mn.connectBtn,onClick:S,disabled:y||!g.trim(),children:y?`Connecting...`:`Connect`})]}),t?.error&&(0,A.jsx)(`div`,{className:mn.connectError,children:t.error})]});let C=Array.isArray(t?.notifications)?t.notifications:[],w=Array.isArray(t?.issues)?t.issues:[],ee=Array.isArray(t?.prs)?t.prs:[];return(0,A.jsxs)(`div`,{className:mn.root,children:[x?.login&&(0,A.jsxs)(`div`,{className:mn.userRow,children:[x.avatar&&(0,A.jsx)(`img`,{src:x.avatar,className:mn.avatar,alt:x.login}),(0,A.jsxs)(`div`,{style:{flex:1},children:[(0,A.jsxs)(`div`,{className:mn.userLogin,children:[`@`,x.login]}),x.name&&(0,A.jsx)(`div`,{className:mn.userName,children:x.name})]}),(0,A.jsx)(`button`,{className:mn.disconnectBtn,onClick:h,children:`Disconnect`})]}),(0,A.jsxs)(`div`,{className:mn.repoBar,children:[(0,A.jsx)(`input`,{className:mn.repoInput,value:s,onChange:e=>c(e.target.value),placeholder:`owner/repo`,onKeyDown:e=>e.key===`Enter`&&f()}),(0,A.jsx)(`button`,{className:mn.issuesBtn,onClick:f,children:`Issues`}),(0,A.jsx)(`button`,{className:mn.prsBtn,onClick:p,children:`PRs`})]}),x?.repos&&x.repos.length>0&&(0,A.jsx)(`div`,{className:mn.repoPills,children:x.repos.slice(0,12).map(e=>(0,A.jsxs)(`button`,{className:mn.repoPill,onClick:()=>{c(e.full_name),o(e.full_name),d(e.full_name),u(`issues`)},title:e.description??``,children:[e.private?`🔒 `:``,e.full_name,e.open_issues?(0,A.jsx)(`span`,{className:mn.issueCount,children:e.open_issues}):null]},e.full_name))}),(0,A.jsxs)(`div`,{className:mn.tabs,children:[(0,A.jsxs)(`button`,{className:`${mn.tab} ${l===`notifs`?mn.tabActive:``}`,onClick:()=>u(`notifs`),children:[`Notifications `,C.length>0?`(${C.length})`:``]}),w.length>0&&(0,A.jsxs)(`button`,{className:`${mn.tab} ${l===`issues`?mn.tabActive:``}`,onClick:()=>u(`issues`),children:[`Issues (`,w.length,`)`]}),ee.length>0&&(0,A.jsxs)(`button`,{className:`${mn.tab} ${l===`prs`?mn.tabActive:``}`,onClick:()=>u(`prs`),children:[`PRs (`,ee.length,`)`]}),l===`notifs`&&C.length>0&&(0,A.jsx)(`button`,{className:mn.markRead,onClick:m,children:`Mark all read`})]}),(0,A.jsxs)(`div`,{className:mn.content,children:[l===`notifs`&&(C.length===0?(0,A.jsx)(`div`,{className:mn.empty,children:`No notifications`}):C.map((e,t)=>(0,A.jsxs)(`a`,{className:mn.notifRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,A.jsx)(`span`,{className:mn.notifRepo,children:e.repo}),(0,A.jsxs)(`span`,{className:mn.notifType,children:[`[`,e.type,`]`]}),(0,A.jsx)(`div`,{className:mn.notifTitle,children:e.title}),(0,A.jsxs)(`div`,{className:mn.notifMeta,children:[e.reason,` · `,e.updated]})]},t))),l===`issues`&&(w.length===0?(0,A.jsxs)(`div`,{className:mn.empty,children:[e(`github.noIssues`),` for `,a]}):w.map((e,t)=>(0,A.jsxs)(`a`,{className:mn.issueRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,A.jsxs)(`span`,{className:mn.issueNum,children:[`#`,e.number]}),(0,A.jsx)(`span`,{className:mn.issueTitle,children:e.title}),e.assignee&&(0,A.jsxs)(`span`,{className:mn.issueMeta,children:[`→ `,e.assignee]}),e.labels&&(0,A.jsxs)(`span`,{className:mn.issueLabel,children:[`[`,e.labels,`]`]}),(0,A.jsx)(`div`,{className:mn.issueMeta,children:e.updated})]},t))),l===`prs`&&(ee.length===0?(0,A.jsxs)(`div`,{className:mn.empty,children:[`No PRs for `,a]}):ee.map((e,t)=>(0,A.jsxs)(`a`,{className:mn.prRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,A.jsxs)(`span`,{className:mn.prNum,children:[`#`,e.number]}),(0,A.jsx)(`span`,{className:mn.prTitle,children:e.title}),(0,A.jsxs)(`span`,{className:mn.prAuthor,children:[`by `,e.author]}),e.draft&&(0,A.jsx)(`span`,{className:mn.prDraft,children:`DRAFT`}),(0,A.jsx)(`div`,{className:mn.prMeta,children:e.updated})]},t)))]})]})}var gn={loading:`_loading_1h5ss_1`,errorBox:`_errorBox_1h5ss_3`,errorHint:`_errorHint_1h5ss_4`,twoPane:`_twoPane_1h5ss_7`,sidebar:`_sidebar_1h5ss_13`,sidebarTitle:`_sidebarTitle_1h5ss_24`,workspace:`_workspace_1h5ss_36`,searchRow:`_searchRow_1h5ss_42`,searchInput:`_searchInput_1h5ss_50`,searchBtn:`_searchBtn_1h5ss_63`,channelItem:`_channelItem_1h5ss_73`,channelActive:`_channelActive_1h5ss_83`,pageTitle:`_pageTitle_1h5ss_89`,pageMeta:`_pageMeta_1h5ss_97`,disconnectBtn:`_disconnectBtn_1h5ss_99`,empty:`_empty_1h5ss_110`,messagePane:`_messagePane_1h5ss_112`,channelHeader:`_channelHeader_1h5ss_120`,emptyPane:`_emptyPane_1h5ss_129`,message:`_message_1h5ss_112`,msgUser:`_msgUser_1h5ss_146`,msgText:`_msgText_1h5ss_147`,msgTs:`_msgTs_1h5ss_148`,openLink:`_openLink_1h5ss_150`,pageBody:`_pageBody_1h5ss_160`};function _n({onSaved:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),s=async()=>{if(t.trim()){if(t.startsWith(`xoxe-`)){o(`"xoxe-" è un refresh token (Token Rotation attivata). NHA ha bisogno di "xoxb-". Disabilita Token Rotation in "OAuth & Permissions → Advanced Token Security" oppure crea una nuova app senza Token Rotation.`);return}if(t.startsWith(`xoxp-`)){o(`"xoxp-" è uno User OAuth Token. NHA usa il Bot Token "xoxb-". In "OAuth & Permissions" copia "Bot User OAuth Token" (la prima riga), non lo User Token.`);return}if(t.startsWith(`xoxa-`)||t.startsWith(`xoxr-`)||t.startsWith(`xoxs-`)){o(`Token type "${t.slice(0,5)}" non supportato. NHA accetta solo Bot User OAuth Token che iniziano con "xoxb-".`);return}if(!t.startsWith(`xoxb-`)){o(`Il token deve iniziare con "xoxb-" (Bot User OAuth Token).`);return}i(!0),o(``);try{await D(`/api/config`,{key:`slack-token`,value:t.trim()}),n(``),e()}catch(e){o(e.message||`errore`)}finally{i(!1)}}};return(0,A.jsxs)(`div`,{style:{display:`flex`,gap:6,marginTop:8,flexWrap:`wrap`},children:[(0,A.jsx)(`input`,{type:`password`,autoFocus:!0,placeholder:`xoxb-...`,value:t,onChange:e=>{n(e.target.value),o(``)},onKeyDown:e=>{e.key===`Enter`&&s()},style:{flex:1,minWidth:260,padding:`6px 10px`,borderRadius:6,border:`1px solid rgba(148,163,184,0.25)`,background:`rgba(15,23,42,0.4)`,color:`inherit`,fontFamily:`SF Mono, monospace`,fontSize:12}}),(0,A.jsx)(`button`,{onClick:s,disabled:!t.trim()||r,style:{padding:`6px 16px`,borderRadius:6,border:`none`,background:`#6366f1`,color:`white`,fontWeight:700,cursor:`pointer`,opacity:!t.trim()||r?.5:1},children:r?`Salvo...`:`Salva e connetti`}),a&&(0,A.jsx)(`div`,{style:{width:`100%`,color:`#ef4444`,fontSize:11},children:a})]})}function vn(){let e=M(),[t,n]=(0,_.useState)(null),[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)(``),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(null),[w,ee]=(0,_.useState)(!0),te=(0,_.useRef)(null),ne=()=>{i(!0),E(`/api/slack/channels`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},T=e=>{o(e),C(null),E(`/api/slack/messages?channel=${e.id}&limit=80`).then(e=>c(e?.messages??[])),D(`/api/slack/mark-read`,{channel:e.id}).catch(()=>{})},O=e=>{a&&E(`/api/slack/thread?channel=${a.id}&ts=${e.ts}`).then(t=>C({parent:e,replies:(t?.messages??[]).filter(t=>t.ts!==e.ts)}))},re=async()=>{if(!(!a||!l.trim()||d)){f(!0);try{let e={channel:a.id,text:l};S&&(e.threadTs=S.parent.ts),await D(`/api/slack/send`,e),u(``),S?O(S.parent):T(a)}finally{f(!1)}}},k=async()=>{if(!h.trim()){y(null);return}x(!0);try{y((await E(`/api/slack/search?q=${encodeURIComponent(h)}&count=30`))?.results??[])}finally{x(!1)}},ie=async(e,t)=>{a&&(await D(`/api/slack/react`,{channel:a.id,ts:e.ts,emoji:t}),T(a))};if((0,_.useEffect)(()=>{ne()},[]),(0,_.useEffect)(()=>(te.current&&window.clearInterval(te.current),w&&a&&(te.current=window.setInterval(()=>T(a),15e3)),()=>{te.current&&window.clearInterval(te.current)}),[w,a?.id]),r)return(0,A.jsxs)(`div`,{className:gn.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return/token not configured|missing.*token|slack.*token/i.test(t.error)?(0,A.jsxs)(`div`,{style:{maxWidth:720,margin:`40px auto`,padding:24,background:`rgba(15,23,42,0.4)`,border:`1px solid rgba(99,102,241,0.2)`,borderRadius:12,color:`inherit`},children:[(0,A.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,marginBottom:8},children:[(0,A.jsx)(`span`,{style:{fontSize:32},children:`💬`}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{style:{fontSize:20,fontWeight:800},children:`Collega il tuo Slack a NHA`}),(0,A.jsx)(`div`,{style:{fontSize:12,opacity:.7},children:`Bastano 4 passaggi · ~3 minuti · gratis`})]})]}),(0,A.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`32px 1fr`,gap:`12px 10px`,marginTop:16,fontSize:13,lineHeight:1.55},children:[(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`1.`}),(0,A.jsxs)(`div`,{children:[`Apri `,(0,A.jsx)(`a`,{href:`https://api.slack.com/apps?new_app=1`,target:`_blank`,rel:`noreferrer`,style:{color:`#6366f1`,fontWeight:700},children:`api.slack.com/apps → Create New App`}),` e scegli "From scratch". Dai un nome (es. `,(0,A.jsx)(`code`,{children:`NHA Bot`}),`) e seleziona il tuo workspace.`]}),(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`2.`}),(0,A.jsxs)(`div`,{children:[`Nel pannello sinistro vai su `,(0,A.jsx)(`strong`,{children:`OAuth & Permissions`}),`. In "Scopes → Bot Token Scopes" aggiungi `,(0,A.jsx)(`strong`,{children:`tutti questi`}),` permessi:`,(0,A.jsx)(`div`,{style:{marginTop:6,display:`flex`,flexWrap:`wrap`,gap:4,fontFamily:`SF Mono, monospace`,fontSize:11},children:[`channels:read`,`channels:history`,`groups:read`,`groups:history`,`im:read`,`im:history`,`mpim:read`,`mpim:history`,`users:read`,`users:read.email`,`team:read`,`chat:write`,`reactions:write`,`search:read`].map(e=>(0,A.jsx)(`code`,{style:{background:`rgba(99,102,241,0.12)`,padding:`2px 6px`,borderRadius:4,color:`#c4b5fd`},children:e},e))})]}),(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`3.`}),(0,A.jsxs)(`div`,{children:[`In cima alla stessa pagina clicca `,(0,A.jsx)(`strong`,{children:`"Install to Workspace"`}),` e conferma. Slack ti darà un `,(0,A.jsx)(`strong`,{children:`Bot User OAuth Token`}),` che inizia per `,(0,A.jsx)(`code`,{children:`xoxb-`}),`.`]}),(0,A.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:`#a78bfa`},children:`4.`}),(0,A.jsxs)(`div`,{children:[`Copia il token e incollalo qui sotto, oppure vai in `,(0,A.jsx)(`strong`,{children:`Settings → Integration tokens`}),`:`,(0,A.jsx)(_n,{onSaved:ne})]})]}),(0,A.jsxs)(`div`,{style:{marginTop:18,padding:10,background:`rgba(99,102,241,0.06)`,borderRadius:8,fontSize:11,opacity:.8},children:[(0,A.jsx)(`strong`,{children:`Privacy:`}),` il token resta sul tuo computer in `,(0,A.jsx)(`code`,{children:`~/.nha/config.json`}),`. NHA non lo invia ai server.`,(0,A.jsx)(`br`,{}),(0,A.jsx)(`strong`,{children:`Tip:`}),` se hai canali privati che vuoi leggere, il bot deve essere invitato. Da Slack scrivi `,(0,A.jsx)(`code`,{children:`/invite @nome-del-bot`}),` nel canale.`]})]}):(0,A.jsxs)(`div`,{className:gn.errorBox,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`strong`,{children:`⚠ Slack:`}),` `,t.error]}),(0,A.jsxs)(`div`,{className:gn.errorHint,children:[`Se il problema persiste, verifica gli scopes del bot in `,(0,A.jsx)(`a`,{href:`https://api.slack.com/apps`,target:`_blank`,rel:`noreferrer`,children:`api.slack.com/apps`}),`.`]})]});let j=t?.channels??[],ae=p?j.filter(e=>e.name.toLowerCase().includes(p.toLowerCase())):j,oe=ae.filter(e=>!e.is_im&&!e.is_mpim&&!e.is_private),se=ae.filter(e=>e.is_private&&!e.is_im&&!e.is_mpim),ce=ae.filter(e=>e.is_im||e.is_mpim),le=(e,t)=>(0,A.jsxs)(`div`,{className:gn.message,style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,A.jsxs)(`div`,{style:{display:`flex`,alignItems:`baseline`,gap:6},children:[(0,A.jsx)(`span`,{className:gn.msgUser,style:{fontWeight:700},children:e.user||`Unknown`}),(0,A.jsx)(`span`,{className:gn.msgTs,style:{fontSize:11,opacity:.6},children:new Date(parseFloat(e.ts)*1e3).toLocaleString()}),e.reply_count?(0,A.jsxs)(`button`,{onClick:()=>O(e),style:{background:`transparent`,border:`none`,color:`#6366f1`,cursor:`pointer`,fontSize:11},children:[`💬 `,e.reply_count,` `,e.reply_count===1?`reply`:`replies`]}):null]}),(0,A.jsx)(`div`,{className:gn.msgText,style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`},children:e.text}),e.files&&e.files.length>0&&(0,A.jsx)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`,marginTop:2},children:e.files.map(e=>(0,A.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,style:{fontSize:11,padding:`2px 6px`,background:`rgba(99,102,241,0.1)`,borderRadius:4,color:`#6366f1`,textDecoration:`none`},children:[`📎 `,e.name]},e.id))}),e.reactions&&e.reactions.length>0&&(0,A.jsxs)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`,marginTop:2},children:[e.reactions.map((e,t)=>(0,A.jsxs)(`span`,{style:{fontSize:11,padding:`1px 6px`,background:`rgba(99,102,241,0.08)`,borderRadius:10},children:[`:`,e.name,`: `,e.count]},t)),(0,A.jsx)(`button`,{onClick:()=>ie(e,`thumbsup`),style:{background:`transparent`,border:`1px dashed rgba(148,163,184,0.3)`,borderRadius:10,fontSize:11,padding:`0 6px`,cursor:`pointer`},children:`+ 👍`})]})]},t);return(0,A.jsxs)(`div`,{className:gn.twoPane,children:[(0,A.jsxs)(`div`,{className:gn.sidebar,children:[(0,A.jsxs)(`div`,{className:gn.sidebarTitle,children:[(0,A.jsxs)(`span`,{children:[`💬 `,t?.workspace||`Slack`]}),(0,A.jsx)(`button`,{className:gn.disconnectBtn,onClick:ne,title:`Refresh`,children:`↻`})]}),(0,A.jsx)(`input`,{type:`text`,placeholder:`🔎 Filter channels...`,value:p,onChange:e=>m(e.target.value),style:{width:`100%`,padding:`6px 8px`,marginBottom:6,borderRadius:6,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontSize:12}}),(0,A.jsx)(`input`,{type:`text`,placeholder:`Search messages...`,value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k()},style:{width:`100%`,padding:`6px 8px`,marginBottom:8,borderRadius:6,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontSize:12}}),v!==null&&(0,A.jsxs)(`div`,{style:{marginBottom:8},children:[(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,marginBottom:2},children:b?`Searching…`:`${v.length} result(s)`}),(0,A.jsx)(`button`,{onClick:()=>{y(null),g(``)},style:{fontSize:11,background:`transparent`,border:`none`,color:`#6366f1`,cursor:`pointer`,padding:0},children:`← back to channels`})]}),v===null&&(0,A.jsxs)(A.Fragment,{children:[oe.length>0&&(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,marginTop:8,marginBottom:2},children:`Channels`}),oe.map(e=>(0,A.jsxs)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>T(e),children:[`# `,e.name,(e.unread_count??0)>0&&(0,A.jsx)(`span`,{style:{float:`right`,background:`#ef4444`,color:`white`,borderRadius:8,padding:`0 6px`,fontSize:10},children:e.unread_count})]},e.id)),se.length>0&&(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,marginTop:8,marginBottom:2},children:`Private`}),se.map(e=>(0,A.jsxs)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>T(e),children:[`🔒 `,e.name]},e.id)),ce.length>0&&(0,A.jsx)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,marginTop:8,marginBottom:2},children:`Direct Messages`}),ce.map(e=>(0,A.jsx)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>T(e),children:e.name},e.id))]})]}),(0,A.jsx)(`div`,{className:gn.messagePane,style:{display:`flex`,flexDirection:`column`,height:`100%`},children:v===null?a?S?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:gn.channelHeader,style:{display:`flex`,justifyContent:`space-between`},children:[(0,A.jsxs)(`span`,{children:[`💬 Thread in #`,a.name]}),(0,A.jsx)(`button`,{onClick:()=>C(null),style:{background:`transparent`,border:`none`,color:`#6366f1`,cursor:`pointer`},children:`✕ Close thread`})]}),(0,A.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,padding:8},children:[(0,A.jsx)(`div`,{style:{borderLeft:`3px solid #6366f1`,paddingLeft:8,marginBottom:8,opacity:.85},children:le(S.parent,-1)}),(0,A.jsxs)(`div`,{style:{fontSize:11,color:`#94a3b8`,textTransform:`uppercase`,margin:`8px 0 4px`},children:[S.replies.length,` `,S.replies.length===1?`reply`:`replies`]}),S.replies.map((e,t)=>le(e,t))]})]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:gn.channelHeader,style:{display:`flex`,justifyContent:`space-between`},children:[(0,A.jsxs)(`span`,{children:[`#`,a.name,a.topic?(0,A.jsxs)(`span`,{style:{fontWeight:400,opacity:.6,marginLeft:8},children:[`— `,a.topic]}):null]}),(0,A.jsxs)(`label`,{style:{fontSize:11,opacity:.7},children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>ee(e.target.checked)}),` auto-refresh`]})]}),(0,A.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,padding:8},children:[s.length===0&&(0,A.jsx)(`div`,{className:gn.empty,children:`No messages`}),s.map((e,t)=>le(e,t))]}),(0,A.jsxs)(`div`,{style:{borderTop:`1px solid rgba(148,163,184,0.2)`,padding:8,display:`flex`,gap:6},children:[(0,A.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&re()},placeholder:`Message #${a.name} (Cmd/Ctrl+Enter to send)`,rows:2,style:{flex:1,padding:6,borderRadius:6,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontFamily:`inherit`,resize:`vertical`}}),(0,A.jsx)(`button`,{onClick:re,disabled:!l.trim()||d,className:gn.disconnectBtn,style:{minWidth:80},children:d?`Sending…`:`Send`})]})]}):(0,A.jsx)(`div`,{className:gn.emptyPane,children:`Select a channel from the left`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:gn.channelHeader,children:[`🔎 Search results for "`,h,`"`]}),(0,A.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,padding:8},children:[v.length===0&&(0,A.jsx)(`div`,{className:gn.empty,children:`No matches`}),v.map((e,t)=>(0,A.jsxs)(`div`,{className:gn.message,style:{marginBottom:6},children:[(0,A.jsxs)(`div`,{style:{display:`flex`,alignItems:`baseline`,gap:6},children:[(0,A.jsx)(`span`,{style:{fontWeight:700},children:e.user}),(0,A.jsxs)(`span`,{style:{fontSize:11,opacity:.6},children:[`in #`,e.channel]}),(0,A.jsx)(`span`,{style:{fontSize:11,opacity:.5},children:new Date(parseFloat(e.ts)*1e3).toLocaleString()}),e.permalink&&(0,A.jsx)(`a`,{href:e.permalink,target:`_blank`,rel:`noreferrer`,style:{fontSize:11,color:`#6366f1`},children:`↗ Slack`})]}),(0,A.jsx)(`div`,{style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,marginTop:2},children:e.text})]},t))]})]})})]})}function yn(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),d=(e=``)=>{i(!0),E(e?`/api/notion/search?q=${encodeURIComponent(e)}`:`/api/notion`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},f=e=>{o(e),E(`/api/notion/page?id=${encodeURIComponent(e.id)}`).then(e=>c(e?.content??``))};(0,_.useEffect)(()=>{d()},[]);let p=()=>d(l);if(r)return(0,A.jsxs)(`div`,{className:gn.loading,children:[(0,A.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,A.jsxs)(`div`,{className:gn.errorBox,children:[(0,A.jsx)(`div`,{children:t.error}),(0,A.jsxs)(`div`,{className:gn.errorHint,children:[`Run: `,(0,A.jsx)(`code`,{children:`nha config set notion-token secret_YOUR_TOKEN`})]})]});let m=t?.pages??[];return(0,A.jsxs)(`div`,{className:gn.twoPane,children:[(0,A.jsxs)(`div`,{className:gn.sidebar,children:[(0,A.jsx)(`div`,{className:gn.sidebarTitle,children:`📋 Notion`}),(0,A.jsxs)(`div`,{className:gn.searchRow,children:[(0,A.jsx)(`input`,{className:gn.searchInput,value:l,onChange:e=>u(e.target.value),placeholder:`Search pages…`,onKeyDown:e=>e.key===`Enter`&&p()}),(0,A.jsx)(`button`,{className:gn.searchBtn,onClick:p,children:`Go`})]}),m.length===0&&(0,A.jsx)(`div`,{className:gn.empty,children:`No pages found`}),m.map(e=>(0,A.jsxs)(`div`,{className:`${gn.channelItem} ${a?.id===e.id?gn.channelActive:``}`,onClick:()=>f(e),children:[(0,A.jsx)(`div`,{className:gn.pageTitle,children:e.title||`Untitled`}),e.last_edited&&(0,A.jsx)(`div`,{className:gn.pageMeta,children:e.last_edited.slice(0,10)})]},e.id)),(0,A.jsx)(`button`,{className:gn.disconnectBtn,onClick:()=>D(`/api/config`,{key:`notion-token`,value:``}).then(()=>d()),children:`Disconnect`})]}),(0,A.jsx)(`div`,{className:gn.messagePane,children:a?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:gn.channelHeader,children:a.title}),a.url&&(0,A.jsx)(`a`,{className:gn.openLink,href:a.url,target:`_blank`,rel:`noreferrer`,children:`Open in Notion ↗`}),(0,A.jsx)(`div`,{className:gn.pageBody,dangerouslySetInnerHTML:{__html:xe(s||`Loading…`)}})]}):(0,A.jsx)(`div`,{className:gn.emptyPane,children:`Select a page`})})]})}var bn={root:`_root_1l3ll_1`,sidebar:`_sidebar_1l3ll_8`,sidebarHeader:`_sidebarHeader_1l3ll_18`,sidebarTitle:`_sidebarTitle_1l3ll_19`,sidebarBtns:`_sidebarBtns_1l3ll_21`,createBtn:`_createBtn_1l3ll_22`,joinBtn:`_joinBtn_1l3ll_23`,noChannels:`_noChannels_1l3ll_25`,channelItem:`_channelItem_1l3ll_27`,channelActive:`_channelActive_1l3ll_29`,channelName:`_channelName_1l3ll_30`,channelMeta:`_channelMeta_1l3ll_31`,channelCode:`_channelCode_1l3ll_32`,channelDel:`_channelDel_1l3ll_34`,main:`_main_1l3ll_38`,chatHeader:`_chatHeader_1l3ll_41`,chatChannelName:`_chatChannelName_1l3ll_50`,chatChannelId:`_chatChannelId_1l3ll_51`,statusDot:`_statusDot_1l3ll_52`,connected:`_connected_1l3ll_53`,disconnected:`_disconnected_1l3ll_54`,statusText:`_statusText_1l3ll_55`,messages:`_messages_1l3ll_58`,emptyMsgs:`_emptyMsgs_1l3ll_66`,msg:`_msg_1l3ll_68`,msgSelf:`_msgSelf_1l3ll_69`,msgOther:`_msgOther_1l3ll_70`,msgSender:`_msgSender_1l3ll_71`,msgContent:`_msgContent_1l3ll_72`,msgTime:`_msgTime_1l3ll_82`,inputRow:`_inputRow_1l3ll_85`,textInput:`_textInput_1l3ll_86`,sendBtn:`_sendBtn_1l3ll_88`,welcome:`_welcome_1l3ll_92`,welcomeIcon:`_welcomeIcon_1l3ll_103`,welcomeTitle:`_welcomeTitle_1l3ll_104`,welcomeSub:`_welcomeSub_1l3ll_105`,welcomeBox:`_welcomeBox_1l3ll_106`,welcomeBoxTitle:`_welcomeBoxTitle_1l3ll_107`,welcomeStep:`_welcomeStep_1l3ll_108`,welcomeHint:`_welcomeHint_1l3ll_109`,cliCmd:`_cliCmd_1l3ll_110`};function xn(e){return e.content||e.plaintext||e.message||``}function Sn(e){return e.senderName||e.senderFingerprint?.slice(0,8)||e.sender||`unknown`}function Cn(){let e=M(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(!1),[d]=(0,_.useState)(()=>`nha-ui-${Math.random().toString(36).slice(2,8)}`),f=(0,_.useRef)(null),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/collab/channels`).then(e=>{n(e?.channels??[])}).catch(()=>{})},[]),(0,_.useEffect)(()=>{if(r)return m(r),h(r),()=>{f.current?.close(),u(!1)}},[r]);let m=e=>{E(`/api/collab/messages?channelId=${e}`).then(e=>{e?.messages&&(o(e.messages),setTimeout(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight)},50))}).catch(()=>{})},h=e=>{f.current?.close();let t=window.location.protocol===`https:`?`wss:`:`ws:`,n=window.location.port===`3030`||window.location.port===`3031`?`3020`:window.location.port||`3020`,r=`${t}//${window.location.hostname}:${n}/ws/alexandria?channel=${e}&agentId=${encodeURIComponent(d)}`,i=new WebSocket(r);f.current=i,i.onopen=()=>u(!0),i.onclose=()=>u(!1),i.onmessage=e=>{try{let t=JSON.parse(e.data);if(!t)return;o(e=>[...e,{...t,id:t.id||Date.now().toString(),type:`message`}]),p.current&&(p.current.scrollTop=p.current.scrollHeight)}catch{}}},g=async()=>{let e=prompt(`Channel name:`);if(!e)return;let t=await D(`/api/collab/create`,{name:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error creating channel`);return}let r=t.id;await D(`/api/collab/channels`,{id:r,name:e,role:`creator`}).catch(()=>{});let a={id:r,name:e,role:`creator`};n(e=>[...e,a]),i(r),prompt(`Share this invite code with collaborators:`,r)},v=async()=>{let e=prompt(`Invite code:`);if(!e)return;let t=await D(`/api/collab/join`,{channelId:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error joining channel`);return}let r=t.name||e.slice(0,8);await D(`/api/collab/channels`,{id:e,name:r,role:`member`}).catch(()=>{}),n(t=>[...t,{id:e,name:r,role:`member`}]),i(e)},y=async e=>{confirm(`Delete this channel? Messages will be lost.`)&&(D(`/api/collab/delete`,{channelId:e}).catch(()=>{}),n(t=>t.filter(t=>t.id!==e)),r===e&&(i(null),o([]),f.current?.close(),u(!1)))},b=async()=>{let e=s.trim();if(!e||!r)return;c(``);let t=await D(`/api/collab/send`,{channelId:r,message:e}).catch(()=>null);t?.error&&alert(t.error),l||m(r)},x=e=>{navigator.clipboard.writeText(e).catch(()=>{})};return(0,A.jsxs)(`div`,{className:bn.root,children:[(0,A.jsxs)(`div`,{className:bn.sidebar,children:[(0,A.jsx)(`div`,{className:bn.sidebarHeader,children:(0,A.jsx)(`div`,{className:bn.sidebarTitle,children:`Alexandria`})}),(0,A.jsxs)(`div`,{className:bn.sidebarBtns,children:[(0,A.jsx)(`button`,{className:bn.createBtn,onClick:g,children:`+ Create`}),(0,A.jsx)(`button`,{className:bn.joinBtn,onClick:v,children:`Join`})]}),t.length===0?(0,A.jsxs)(`div`,{className:bn.noChannels,children:[e(`collab.noChannels`),` yet`]}):t.map(e=>(0,A.jsxs)(`div`,{className:`${bn.channelItem} ${r===e.id?bn.channelActive:``}`,onClick:()=>i(e.id),children:[(0,A.jsx)(`div`,{className:bn.channelName,children:e.name}),(0,A.jsxs)(`div`,{className:bn.channelMeta,children:[(0,A.jsxs)(`span`,{className:bn.channelCode,onClick:t=>{t.stopPropagation(),x(e.id)},title:`Click to copy invite code`,children:[e.id.slice(0,8),`…`]}),(0,A.jsx)(`button`,{className:bn.channelDel,onClick:t=>{t.stopPropagation(),y(e.id)},children:`del`})]})]},e.id))]}),(0,A.jsx)(`div`,{className:bn.main,children:r?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:bn.chatHeader,children:[(0,A.jsx)(`div`,{className:bn.chatChannelName,children:t.find(e=>e.id===r)?.name??r.slice(0,12)}),(0,A.jsx)(`div`,{className:bn.chatChannelId,children:r}),(0,A.jsx)(`div`,{className:`${bn.statusDot} ${l?bn.connected:bn.disconnected}`}),(0,A.jsx)(`span`,{className:bn.statusText,children:l?`Live`:`HTTP`})]}),(0,A.jsxs)(`div`,{className:bn.messages,ref:p,children:[a.length===0&&(0,A.jsx)(`div`,{className:bn.emptyMsgs,children:`No messages yet`}),a.map((e,t)=>{let n=Sn(e),r=xn(e),i=n===d;return(0,A.jsxs)(`div`,{className:`${bn.msg} ${i?bn.msgSelf:bn.msgOther}`,children:[!i&&(0,A.jsx)(`div`,{className:bn.msgSender,children:n}),(0,A.jsx)(`div`,{className:bn.msgContent,children:r}),(0,A.jsx)(`div`,{className:bn.msgTime,children:new Date(e.timestamp).toLocaleTimeString()})]},e.id||t)})]}),(0,A.jsxs)(`div`,{className:bn.inputRow,children:[(0,A.jsx)(`input`,{className:bn.textInput,value:s,onChange:e=>c(e.target.value),placeholder:`Send an encrypted message…`,onKeyDown:e=>e.key===`Enter`&&!e.shiftKey&&b()}),(0,A.jsx)(`button`,{className:bn.sendBtn,onClick:b,disabled:!s.trim(),children:e(`collab.send`)})]})]}):(0,A.jsxs)(`div`,{className:bn.welcome,children:[(0,A.jsx)(`div`,{className:bn.welcomeIcon,children:`🔐`}),(0,A.jsx)(`div`,{className:bn.welcomeTitle,children:`Alexandria`}),(0,A.jsx)(`div`,{className:bn.welcomeSub,children:`E2E encrypted messaging for AI agents and teams`}),(0,A.jsxs)(`div`,{className:bn.welcomeBox,children:[(0,A.jsx)(`div`,{className:bn.welcomeBoxTitle,children:`HOW TO USE`}),(0,A.jsxs)(`div`,{className:bn.welcomeStep,children:[(0,A.jsx)(`strong`,{children:`1. Create a channel`}),` — Click [+ Create] in the sidebar. Give it a name.`]}),(0,A.jsx)(`div`,{className:bn.welcomeHint,children:`You get an invite code. Share it with your team or another AI session.`}),(0,A.jsxs)(`div`,{className:bn.welcomeStep,children:[(0,A.jsx)(`strong`,{children:`2. Others join`}),` — They click [Join] and paste the invite code.`]}),(0,A.jsx)(`div`,{className:bn.welcomeHint,children:`Works from this web UI, the Android app, or the CLI.`}),(0,A.jsxs)(`div`,{className:bn.welcomeStep,children:[(0,A.jsx)(`strong`,{children:`3. Chat encrypted`}),` — All messages are E2E encrypted. The server sees only ciphertext.`]})]}),(0,A.jsxs)(`div`,{className:bn.welcomeBox,children:[(0,A.jsx)(`div`,{className:bn.welcomeBoxTitle,children:`FROM CLI (same channels)`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab create "Project X"`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab join <invite-code>`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab send "Hello from CLI"`}),(0,A.jsx)(`div`,{className:bn.cliCmd,children:`nha collab read`})]})]})})]})}var wn=[],Tn=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?Tn:wn).push(n+=e[t])})();function En(e){if(e<768)return!1;for(let t=0,n=wn.length;;){let r=t+n>>1;if(e<wn[r])n=r;else if(e>=Tn[r])t=r+1;else return!0;if(t==n)return!1}}function Dn(e){return e>=127462&&e<=127487}var On=8205;function kn(e,t,n=!0,r=!0){return(n?An:jn)(e,t,r)}function An(e,t,n){if(t==e.length)return t;t&&Nn(e.charCodeAt(t))&&Pn(e.charCodeAt(t-1))&&t--;let r=Mn(e,t);for(t+=Fn(r);t<e.length;){let i=Mn(e,t);if(r==On||i==On||n&&En(i))t+=Fn(i),r=i;else if(Dn(i)){let n=0,r=t-2;for(;r>=0&&Dn(Mn(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function jn(e,t,n){for(;t>0;){let r=An(e,t-2,n);if(r<t)return r;t--}return 0}function Mn(e,t){let n=e.charCodeAt(t);if(!Pn(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return Nn(r)?(n-55296<<10)+(r-56320)+65536:n}function Nn(e){return e>=56320&&e<57344}function Pn(e){return e>=55296&&e<56320}function Fn(e){return e<65536?1:2}var In=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=Kn(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Rn.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Kn(this,e,t);let n=[];return this.decompose(e,t,n,0),Rn.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new Hn(this),i=new Hn(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new Hn(this,e)}iterRange(e,t=this.length){return new Un(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Wn(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new Ln(t):Rn.from(Ln.split(t,[]))}},Ln=class e extends In{constructor(e,t=zn(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new Gn(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(Vn(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=Bn(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=Kn(this,t,n);let i=Bn(this.text,Bn(r.text,Vn(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):Rn.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
661
661
  `){[e,t]=Kn(this,e,t);let r=``;for(let i=0,a=0;i<=t&&a<this.text.length;a++){let o=this.text[a],s=i+o.length;i>e&&a&&(r+=n),e<s&&t>i&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}},Rn=class e extends In{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(e<=s&&t>=a){let i=r&(a<=e|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=Kn(this,t,n),r.lines<this.lines)for(let i=0,a=0;i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(t>=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines<l>>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=`
662
662
  `){[e,t]=Kn(this,e,t);let r=``;for(let i=0,a=0;i<this.children.length&&a<=t;i++){let o=this.children[i],s=a+o.length;a>e&&i&&(r+=n),e<s&&t>a&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new Ln(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof Ln&&c&&(n=u[u.length-1])instanceof Ln&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new Ln(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}};In.empty=new Ln([``],0);function zn(e){let t=-1;for(let n of e)t+=n.length+1;return t}function Bn(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a<e.length&&i<=r;a++){let s=e[a],c=i+s.length;c>=n&&(c>r&&(s=s.slice(0,r-i)),i<n&&(s=s.slice(n-i)),o?(t[t.length-1]+=s,o=!1):t.push(s)),i=c+1}return t}function Vn(e,t,n){return Bn(e,[``],t,n)}var Hn=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof Ln?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof Ln?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
663
663
  `,this;e--}else if(r instanceof Ln){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof Ln?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},Un=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new Hn(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},Wn=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(In.prototype[Symbol.iterator]=function(){return this.iter()},Hn.prototype[Symbol.iterator]=Un.prototype[Symbol.iterator]=Wn.prototype[Symbol.iterator]=function(){return this});var Gn=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function Kn(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function qn(e,t,n=!0,r=!0){return kn(e,t,n,r)}function Jn(e){return e>=56320&&e<57344}function Yn(e){return e>=55296&&e<56320}function Xn(e,t){let n=e.charCodeAt(t);if(!Yn(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return Jn(r)?(n-55296<<10)+(r-56320)+65536:n}function Zn(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}function Qn(e){return e<65536?1:2}var $n=/\r\n?|\n/,er=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(er||={}),tr=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){ar(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:sr(this,e)}mapDesc(e,t=!1){return e.empty?this:or(this,e,t)}mapPos(e,t=-1,n=er.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=er.Simple&&c>=e&&(n==er.TrackDel&&r<e&&c>e||n==er.TrackBefore&&r<e||n==er.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},nr=class e extends tr{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return ar(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return or(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(In.empty);r.push(a?t.slice(i,i+a):In.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:sr(this,e,!0)}map(e,t=!1){return e.empty?this:or(this,e,t,!0)}iterChanges(e,t=!1){ar(this,e,t)}get desc(){return tr.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new cr(this);done:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break done;let e=Math.min(a.len,s-o);rr(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;rr(n,e,t),t>0&&ir(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break done;let e=Math.min(a.len,c-o);rr(n,e,-1),rr(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:tr.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&rr(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?In.of(l.split(r||$n)):l:In.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&rr(i,e-o,-1),rr(i,s-e,d),ir(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(In.empty);r[e]=In.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function rr(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function ir(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(In.empty);e.push(n)}}function ar(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=In.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function or(e,t,n,r=!1){let i=[],a=r?[]:null,o=new cr(e),s=new cr(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);rr(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(rr(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(rr(i,0,o.ins),a&&ir(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;rr(i,t,e<o.i?o.ins:0),a&&e<o.i&&ir(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?nr.createSet(i,a):tr.create(i);else throw Error(`Mismatched change set lengths`)}function sr(e,t,n=!1){let r=[],i=n?[]:null,a=new cr(e),o=new cr(t);for(let e=!1;;)if(a.done&&o.done)return i?nr.createSet(r,i):tr.create(r);else if(a.ins==0)rr(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)rr(r,0,o.ins,e),i&&ir(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;rr(r,t,n,e),i&&n&&ir(i,r,o.text)}else o.ins==-1?(rr(r,a.off?0:a.len,t,e),i&&ir(i,r,a.textBit(t))):(rr(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&ir(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var cr=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?In.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?In.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},lr=class e{constructor(e,t,n){this.from=e,this.to=t,this.flags=n}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return q.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return q.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return q.range(e.anchor,e.head)}static create(t,n,r){return new e(t,n,r)}},q=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>lr.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return lr.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n))|(r??16777215)<<6)}static range(e,t,n,r,i){let a=(n??16777215)<<6|(r==null?7:Math.min(6,r));return!i&&e!=t&&(i=t<e?1:-1),t<e?lr.create(t,e,48|a):lr.create(e,t,(i?i<0?8:16:0)|a)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function ur(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}var dr=0,J=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=dr++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:fr),!!t.static,t.enables)}of(e){return new pr([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new pr(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new pr(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function fr(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var pr=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=dr++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||hr(e,c)){let r=t(e);if(a?!mr(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=Or(o,c);if(this.dependencies.every(t=>t instanceof J?o.facet(t)===e.facet(t):t instanceof vr?o.field(t,!1)==e.field(t,!1):!0)||(a?mr(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}};function mr(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function hr(e,t){let n=!1;for(let r of t)Dr(e,r)&1&&(n=!0);return n}function gr(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=Or(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)Dr(e,t);return e.values[o]=s(e),1},update(e,n){if(!hr(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=hr(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&fr(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}var _r=J.define({static:!0}),vr=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(dr++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(_r).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(_r),i=n.facet(_r),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,_r.of({field:this,create:e})]}get extension(){return this}},yr={lowest:4,low:3,default:2,high:1,highest:0};function br(e){return t=>new Sr(t,e)}var xr={highest:br(yr.highest),high:br(yr.high),default:br(yr.default),low:br(yr.low),lowest:br(yr.lowest)},Sr=class{constructor(e,t){this.inner=e,this.prec=t}},Cr=class e{of(e){return new wr(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},wr=class{constructor(e,t){this.compartment=e,this.inner=t}},Tr=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of Er(t,n,o))e instanceof vr?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0))if(s[n.id]=c.length<<1|1,fr(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>gr(e,n,t))}}return new e(t,o,l.map(e=>e(s)),s,c,a)}};function Er(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof wr&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof wr){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof Sr)a(e.inner,e.prec);else if(e instanceof vr)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof pr)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,yr.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,yr.default),r.reduce((e,t)=>e.concat(t))}function Dr(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function Or(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}var kr=J.define(),Ar=J.define({combine:e=>e.some(e=>e),static:!0}),jr=J.define({combine:e=>e.length?e[0]:void 0,static:!0}),Mr=J.define(),Nr=J.define(),Pr=J.define(),Fr=J.define({combine:e=>e.length?e[0]:!1}),Ir=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Lr}},Lr=class{of(e){return new Ir(this,e)}},Rr=class{constructor(e){this.map=e}of(e){return new zr(this,e)}},zr=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new Rr(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};zr.reconfigure=zr.define(),zr.appendConfig=zr.define();var Br=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&ur(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};Br.time=Ir.define(),Br.userEvent=Ir.define(),Br.addToHistory=Ir.define(),Br.remote=Ir.define();function Vr(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function Hr(e,t,n){let r,i,a;return n?(r=t.changes,i=nr.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:zr.mapEffects(e.effects,r).concat(zr.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function Ur(e,t,n){let r=t.selection,i=Jr(t.annotations);return t.userEvent&&(i=i.concat(Br.userEvent.of(t.userEvent))),{changes:t.changes instanceof nr?t.changes:nr.of(t.changes||[],n,e.facet(jr)),selection:r&&(r instanceof q?r:q.single(r.anchor,r.head)),effects:Jr(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function Wr(e,t,n){let r=Ur(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=Hr(r,Ur(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=Br.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return Kr(n?Gr(i):i)}function Gr(e){let t=e.startState,n=!0;for(let r of t.facet(Mr)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:Vr(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=nr.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=Br.create(t,r,e.selection&&e.selection.map(i),zr.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(Nr);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof Br?i:Array.isArray(i)&&i.length==1&&i[0]instanceof Br?i[0]:Wr(t,Jr(i),!1)}return e}function Kr(e){let t=e.startState,n=t.facet(Pr),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=Hr(r,Ur(t,a,e.changes.newLength),!0))}return r==e?e:Br.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}var qr=[];function Jr(e){return e==null?qr:Array.isArray(e)?e:[e]}var Yr=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})(Yr||={}),Xr=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Zr;try{Zr=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function Qr(e){if(Zr)return Zr.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>`€`&&(n.toUpperCase()!=n.toLowerCase()||Xr.test(n)))return!0}return!1}function $r(e){return t=>{if(!/\S/.test(t))return Yr.Space;if(Qr(t))return Yr.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return Yr.Word;return Yr.Other}}var ei=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)Dr(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`);return}return Dr(this,n),Or(this,n)}update(...e){return Wr(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(Cr.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(zr.reconfigure)?(n=null,r=e.value):e.is(zr.appendConfig)&&(n=null,r=Jr(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=Tr.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(Ar)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:q.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=Jr(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=zr.mapEffects(a,c).concat(zr.mapEffects(Jr(o.effects),l))}return{changes:r,selection:q.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof nr?t:nr.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return In.of(t.split(this.facet(e.lineSeparator)||$n))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Dr(this,t),Or(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof vr&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:q.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=Tr.resolve(t.extensions||[],new Map),r=t.doc instanceof In?t.doc:In.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||$n)),i=t.selection?t.selection instanceof q?t.selection:q.single(t.selection.anchor,t.selection.head):q.single(0);return ur(i,r.length),n.staticFacet(Ar)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`
@@ -8,7 +8,7 @@
8
8
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
10
  <title>NHA — NotHumanAllowed</title>
11
- <script type="module" crossorigin src="/assets/index-BCHO85Mr.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-BNhySWYT.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-IQn8QiFW.css">
13
13
  </head>
14
14
  <body>