nothumanallowed 14.1.39 → 14.1.41

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": "14.1.39",
3
+ "version": "14.1.41",
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/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 = '14.1.39';
8
+ export const VERSION = '14.1.41';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -780,6 +780,50 @@ ${rawOutput.slice(-800)}`;
780
780
  if (!fs.existsSync(memFile)) {
781
781
  fs.writeFileSync(memFile, `# ${projectName} — Project Memory\n\n_Add architectural decisions, preferences, and notes here._\n`, 'utf-8');
782
782
  }
783
+
784
+ // Generate skills.md with project context knowledge structure
785
+ const skillsFile = path.join(ctxDir, 'skills.md');
786
+ if (!fs.existsSync(skillsFile)) {
787
+ const skillsContent = `# ${projectName} — Skills & Knowledge Structure
788
+
789
+ ## Context Discovery Strategy
790
+
791
+ This project uses a hierarchical knowledge discovery system:
792
+
793
+ ### 1. **Immediate Context** (Always Loaded)
794
+ - \`memory.md\` — Core architectural decisions and preferences
795
+ - \`changes.log.md\` — Recent development history
796
+ - Project metadata (tech stack, dependencies)
797
+
798
+ ### 2. **On-Demand Context** (Loaded When Needed)
799
+ - **File-specific context**: When editing specific files, load related documentation
800
+ - **Feature-specific context**: Load relevant docs when working on specific features
801
+ - **Error-specific context**: Load debugging guides when errors occur
802
+
803
+ ### 3. **Smart Context Loading**
804
+ Instead of loading everything at once, agents:
805
+ 1. **Start with core context** (memory.md + recent changes)
806
+ 2. **Analyze the task** to determine what additional context is needed
807
+ 3. **Load specific context** files based on the task type
808
+ 4. **Cache loaded context** for the duration of the conversation
809
+
810
+ ### 4. **Context File Structure**
811
+ - \`docs/\` — Feature documentation and guides
812
+ - \`specs/\` — Technical specifications and requirements
813
+ - \`examples/\` — Code examples and patterns
814
+ - \`troubleshooting/\` — Common issues and solutions
815
+
816
+ ### 5. **Context Relevance Scoring**
817
+ Agents score context relevance based on:
818
+ - **Keywords** in user requests
819
+ - **File paths** being modified
820
+ - **Error messages** encountered
821
+ - **Recent changes** in the codebase
822
+
823
+ This approach ensures agents have the right context without being overwhelmed by irrelevant information.
824
+ `;
825
+ fs.writeFileSync(skillsFile, skillsContent, 'utf-8');
826
+ }
783
827
  const logFile = path.join(ctxDir, 'changes.log.md');
784
828
  const logEntry = `## ${new Date().toISOString().slice(0, 10)} — Initial generation\n- Generated ${generatedFiles.length} files\n- Tokens in: ${totalTokensIn} / out: ${totalTokensOut}\n- Description: ${description}\n`;
785
829
  fs.writeFileSync(logFile, (fs.existsSync(logFile) ? fs.readFileSync(logFile, 'utf-8') : '') + logEntry, 'utf-8');
@@ -483,6 +483,18 @@ export function messageExists(accountId, folderPath, uid) {
483
483
  export function insertMessage(data) {
484
484
  const db = getDb();
485
485
  const id = data.id || randomUUID();
486
+
487
+ // Validate required fields for foreign key constraints
488
+ if (!data.account_id) {
489
+ throw new Error('account_id is required for insertMessage');
490
+ }
491
+
492
+ // Check if account exists
493
+ const account = db.prepare('SELECT id FROM email_accounts WHERE id = ?').get(data.account_id);
494
+ if (!account) {
495
+ throw new Error(`Account ${data.account_id} does not exist`);
496
+ }
497
+
486
498
  db.prepare(`
487
499
  INSERT OR IGNORE INTO email_messages
488
500
  (id, account_id, folder_id, imap_folder_path, uid, message_id, in_reply_to, references_list,
@@ -515,9 +527,10 @@ export function saveMessage(accountId, data) {
515
527
  return insertMessage({
516
528
  ...data,
517
529
  account_id: accountId,
518
- imap_folder_path: 'INBOX',
519
- uid: Date.now(), // Fake UID for Gmail API messages
520
- source: 'gmail_api'
530
+ folder_id: data.folder_id || null,
531
+ imap_folder_path: data.imap_folder_path || 'INBOX',
532
+ uid: data.uid || Date.now(), // Fake UID for Gmail API messages
533
+ source: data.source || 'gmail_api'
521
534
  });
522
535
  }
523
536
 
@@ -362,7 +362,7 @@ async function cacheMessages(messages) {
362
362
 
363
363
  // ENTERPRISE LOCAL-FIRST: Also save to IMAP database for Web UI offline access
364
364
  try {
365
- const { ensureGoogleAccount, saveMessage } = await import('./email-db.mjs');
365
+ const { ensureGoogleAccount, upsertFolder, getSystemLabel, saveMessage } = await import('./email-db.mjs');
366
366
 
367
367
  // Ensure Google account exists in IMAP database
368
368
  const googleAccount = ensureGoogleAccount({
@@ -375,9 +375,16 @@ async function cacheMessages(messages) {
375
375
  is_active: 1
376
376
  });
377
377
 
378
+ // Ensure INBOX folder exists for Gmail account
379
+ const inboxFolderId = upsertFolder(googleAccount.id, 'INBOX', 'Inbox', 'inbox', 1, 0);
380
+
381
+ // Get system labels (inbox, sent, etc.) - they are auto-created by ensureGoogleAccount
382
+ const inboxLabel = getSystemLabel(googleAccount.id, 'inbox');
383
+
378
384
  // Save each message to IMAP database
379
385
  for (const msg of messages) {
380
386
  saveMessage(googleAccount.id, {
387
+ folder_id: inboxFolderId,
381
388
  message_id: msg.id,
382
389
  thread_id: msg.threadId || msg.id,
383
390
  subject: msg.subject || '(no subject)',
@@ -389,7 +396,6 @@ async function cacheMessages(messages) {
389
396
  internal_date: new Date(msg.date || Date.now()).toISOString(),
390
397
  is_read: !msg.isUnread,
391
398
  is_starred: !!msg.isImportant,
392
- labels: (msg.labels || []).join(','),
393
399
  has_attachments: false
394
400
  });
395
401
  }
@@ -569,7 +569,7 @@ ${l}
569
569
  ${e.map(e=>`<div class="section"><div class="agent-header"><span class="icon">${e.icon}</span><div class="agent-name">${e.label}</div></div><div class="section-body"><p>${r(e.output)}</p></div></div>`).join(``)}
570
570
  ${u}
571
571
  <div class="footer">NHA Studio · nothumanallowed.com · ${new Date().getFullYear()}</div>
572
- </body></html>`,f=new Blob([d],{type:`text/html`}),p=URL.createObjectURL(f),m=document.createElement(`a`);m.href=p,m.download=`nha-report-${Date.now()}.html`,m.click(),URL.revokeObjectURL(p);let h=window.open(``,`_blank`,`width=1100,height=800`);h&&(h.document.open(),h.document.write(d),h.document.close(),h.onload=()=>setTimeout(()=>{h.focus(),h.print()},600))},ve=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`)},I=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),le.current=``,w(null),M.current=null,te(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(tt)}catch{}}},be=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:L.root,children:[(0,k.jsxs)(`div`,{className:L.header,children:[(0,k.jsxs)(`div`,{className:L.headerLeft,children:[(0,k.jsx)(`div`,{className:L.title,children:`Studio`}),(0,k.jsx)(`div`,{className:L.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:L.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:L.tokenBar,children:[(0,k.jsxs)(`span`,{className:L.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:L.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` out`})]}),(0,k.jsxs)(`div`,{style:{position:`relative`},ref:P,children:[(0,k.jsxs)(`button`,{className:L.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,k.jsx)(`div`,{className:L.sessionsDrawer,children:f.length===0?(0,k.jsx)(`div`,{className:L.noSessions,children:`No saved sessions yet.`}):(0,k.jsxs)(k.Fragment,{children:[f.map(e=>(0,k.jsxs)(`div`,{className:L.sessionItem,children:[(0,k.jsxs)(`div`,{className:L.sessionInfo,onClick:()=>me(e),children:[(0,k.jsx)(`div`,{className:L.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:L.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,k.jsxs)(`div`,{className:L.sessionBtns,children:[(0,k.jsx)(`button`,{className:L.importBtn,onClick:()=>ve(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:L.delSessionBtn,onClick:()=>he(e.id),children:`✕`})]})]},e.id)),(0,k.jsx)(`div`,{className:L.sessionsFooter,children:(0,k.jsx)(`button`,{className:L.clearAllSessionsBtn,onClick:ge,children:`Clear All`})})]})})]}),x&&(0,k.jsx)(`button`,{className:L.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:L.pdfBtn,onClick:_e,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:L.clearBtn,onClick:I,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,k.jsxs)(`div`,{className:L.inputArea,children:[(0,k.jsxs)(`div`,{className:L.inputRow,children:[(0,k.jsx)(`textarea`,{className:L.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(),de())}}),(0,k.jsxs)(`div`,{className:L.inputControls,children:[u?(0,k.jsx)(`button`,{className:L.stopBtn,onClick:fe,children:`■ Stop`}):(0,k.jsx)(`button`,{className:L.runBtn,onClick:de,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:L.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>ue(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:L.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:L.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:L.examples,children:Ee.map((e,t)=>(0,k.jsx)(`button`,{className:L.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:L.financeSection,children:[(0,k.jsx)(`div`,{className:L.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:L.financePresets,children:we.map((e,t)=>(0,k.jsx)(`button`,{className:L.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:L.officeSceneWrap,children:(0,k.jsx)(Ye,{nodes:i,running:u})}),(0,k.jsxs)(`div`,{className:`${L.pipelineWrap} ${u?L.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:L.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:L.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:L.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:L.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${L.agentChip} ${L[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:L.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:L.chipDots,children:[(0,k.jsx)(`span`,{className:L.dot1,children:`.`}),(0,k.jsx)(`span`,{className:L.dot2,children:`.`}),(0,k.jsx)(`span`,{className:L.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:L.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:L.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${L.arrow} ${u?L.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:L.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:L.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:L.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:L.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,k.jsxs)(`div`,{className:L.body,children:[(o.length>0||be)&&(0,k.jsxs)(`div`,{className:L.twoCol,children:[(0,k.jsxs)(`div`,{className:L.logPanel,children:[(0,k.jsx)(`div`,{className:L.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:L.logBody,ref:ce,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.logEntry} ${L[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:L.logTime,children:e.time}),(0,k.jsx)(`span`,{className:L.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:L.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:L.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.liveBlock} ${e.status===`running`?L.liveBlockActive:``} ${e.status===`done`&&e.output?L.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?oe(e):void 0,children:[(0,k.jsxs)(`div`,{className:L.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:L.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:L.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${L.outputStatus} ${L[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:L.expandHint,children:`↗ espandi`})]}),e.status===`running`&&(0,k.jsxs)(`div`,{className:L.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingLabel,children:e.statusLine??`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${L.liveBlockBody} ${e.status===`done`&&e.output?L.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:ye(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:L.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:L.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:L.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,k.jsxs)(`div`,{className:L.parliamentPromptMeta,children:[`Complessità: `,T.length<=3?`⚡ Rapido (~30s)`:T.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:L.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:L.parliamentActivateBtn,onClick:pe,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:L.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:L.councilWrapper,children:(0,k.jsx)(ct,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:L.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:L.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:L.resultAccordionBody,dangerouslySetInnerHTML:{__html:ye(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:L.canvasPanel,children:[(0,k.jsxs)(`div`,{className:L.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:L.panelTabs,children:[(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`canvas`?L.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`browser`?L.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:L.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:L.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:L.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:L.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:L.browserPanel,children:[(0,k.jsxs)(`div`,{className:L.browserBar,children:[(0,k.jsx)(`input`,{className:L.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:L.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:L.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`Enter a URL above to browse`})]})]}),j&&(0,k.jsx)(`div`,{className:L.blockModalOverlay,onClick:()=>oe(null),children:(0,k.jsxs)(`div`,{className:L.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:L.blockModalHeader,children:[(0,k.jsx)(`span`,{className:L.liveBlockIcon,children:j.icon}),(0,k.jsx)(`span`,{className:L.blockModalTitle,children:j.label}),(0,k.jsx)(`button`,{className:L.blockModalClose,onClick:()=>oe(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${L.liveBlockBody} ${L.blockModalBody}`,dangerouslySetInnerHTML:{__html:ye(j.output)}})]})})]})}var V={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`},ut=[{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:`Connectors`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],dt={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 ft(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function pt(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function mt(){let e=ne(e=>e.setView),t=N(),[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?.tempC&&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(ut.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:V.root,children:[(0,k.jsxs)(`div`,{className:V.hero,children:[(0,k.jsxs)(`div`,{className:V.heroLeft,children:[(0,k.jsx)(`div`,{className:V.heroDate,children:y}),(0,k.jsx)(`div`,{className:V.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:V.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:V.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:V.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),location.reload())},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:V.wIcon,children:dt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:V.wInfo,children:[(0,k.jsxs)(`span`,{className:V.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:V.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:V.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:V.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:V.kpiRow,children:[(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:V.kpiBar,children:(0,k.jsx)(`div`,{className:V.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:V.kpi,children:[(0,k.jsxs)(`span`,{className:V.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:V.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:t.isAllDay?`All day`:ft(t.start)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:V.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${V.liveRow} ${t.isUnread?V.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:pt(t.date)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:V.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${V.prio} ${V[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:V.liveBody,children:(0,k.jsx)(`span`,{className:V.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:V.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:V.launchGroup,children:[(0,k.jsx)(`div`,{className:V.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:V.launchTiles,children:ut.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:V.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:V.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:V.tileLabel,children:t.label})]},t.view))})]},t))})]})}var ht={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 gt(){let e=N(),[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,k.jsxs)(`div`,{className:ht.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:ht.root,children:[(0,k.jsxs)(`div`,{className:ht.bar,children:[(0,k.jsx)(`input`,{ref:d,className:ht.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:ht.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:ht.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ht.actions,children:[(0,k.jsx)(`button`,{className:ht.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:ht.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ht.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:ht.progress,children:(0,k.jsx)(`span`,{className:ht.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:ht.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:ht.task,children:[(0,k.jsx)(`span`,{className:ht.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:ht.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ht.badge} ${ht[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ht.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:ht.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${ht.task} ${ht.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${ht.check} ${ht.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:ht.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ht.badge} ${ht[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ht.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var H={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`},_t={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function vt({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:H.fieldInput})]})}function yt(){let{setConfig:e}=ne(),t=N(),[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,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(`en`),[ae,A]=(0,_.useState)(`07:00`),[j,oe]=(0,_.useState)(`18:00`),[se,ce]=(0,_.useState)(`30`),[le,M]=(0,_.useState)(`off`),[P,F]=(0,_.useState)(``),[ue,de]=(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`),re(t?.model??``),O(t?.lang??`en`),A(t?.planTime??`07:00`),oe(t?.summaryTime??`18:00`),ce(String(t?.meetingAlert??`30`)),M(t?.thinking??`off`),te(``),a(!1),t&&e(t)}),fe()},[]);let fe=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),pe=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},me=()=>pe(`profile`,x),he=()=>{pe(`provider`,C),pe(`model`,T),pe(`thinking`,le),ee&&pe(`key`,ee)},ge=()=>{pe(`planTime`,ae),pe(`summaryTime`,j),pe(`meetingAlert`,Number(se))},_e=()=>{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))},ve=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},ye=()=>{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),fe()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},I=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>fe())},be=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(fe,3e3))};if(i)return(0,k.jsxs)(`div`,{className:H.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let xe=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:H.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(vt,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:me,children:[xe(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:H.nhaFree,children:[(0,k.jsx)(`div`,{className:H.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:H.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:H.nhaFreeBtn,onClick:()=>{D(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),re(``),te(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.llmProviderSub`)}),(()=>{let e=[];return n.hasApiKey&&e.push(`Anthropic`),n.hasOpenaiKey&&e.push(`OpenAI`),n.hasGeminiKey&&e.push(`Gemini`),n.hasDeepseekKey&&e.push(`DeepSeek`),n.hasGrokKey&&e.push(`Grok`),n.hasMistralKey&&e.push(`Mistral`),n.hasCohereKey&&e.push(`Cohere`),e.length===0?null:(0,k.jsxs)(`div`,{className:H.keySummary,children:[(0,k.jsx)(`span`,{className:H.keySummaryIcon,children:`🔑`}),(0,k.jsxs)(`span`,{children:[`Chiavi configurate: `,(0,k.jsx)(`strong`,{children:e.join(`, `)})]})]})})(),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:H.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(vt,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(vt,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:T,onChange:re}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:le,onChange:e=>M(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:he,children:[xe(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:ie,onChange:t=>{let r=t.target.value;O(r),pe(`lang`,r),e({...n,lang:r})},className:H.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(vt,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:P,onChange:F}),(0,k.jsx)(vt,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:ue,onChange:de}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:()=>{P&&pe(`telegram-bot-token`,P),ue&&pe(`discord-bot-token`,ue)},children:[xe(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(vt,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ae,onChange:A}),(0,k.jsx)(vt,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:j,onChange:oe}),(0,k.jsx)(vt,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:se,onChange:ce}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:ge,children:[xe(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:H.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:_e,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:H.dangerBtn,onClick:ve,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:H.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsxs)(`div`,{className:H.cardTitleRow,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:H.saveBtn,onClick:()=>{p({..._t}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:H.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:H.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:H.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:H.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:H.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:H.imapBtns,children:[(0,k.jsx)(`button`,{className:H.imapSyncBtn,onClick:()=>be(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:H.imapEditBtn,onClick:()=>{p({..._t,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:H.imapDelBtn,onClick:()=>I(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:H.imapForm,children:[(0,k.jsx)(`div`,{className:H.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(vt,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsxs)(`label`,{className:H.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:H.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:H.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:H.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:H.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:ye,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:H.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:H.statusMsg,children:m})]})]})]})}var bt={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 xt(){let e=N(),[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,k.jsxs)(`div`,{className:bt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:bt.err,children:a}):(0,k.jsxs)(`div`,{className:bt.root,children:[(0,k.jsxs)(`div`,{className:bt.header,children:[(0,k.jsx)(`div`,{className:bt.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:bt.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:bt.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${bt.card} ${r?bt.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:bt.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:bt.info,children:[(0,k.jsx)(`div`,{className:bt.name,children:t.name}),(0,k.jsx)(`div`,{className:bt.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?bt.labelToday:i?bt.labelTomorrow:bt.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:bt.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:bt.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:bt.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:bt.modal,children:[(0,k.jsx)(`div`,{className:bt.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:bt.label,children:`Name *`}),(0,k.jsx)(`input`,{className:bt.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:bt.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:bt.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:bt.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:bt.formErr,children:l}),(0,k.jsxs)(`div`,{className:bt.modalBtns,children:[(0,k.jsx)(`button`,{className:bt.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:bt.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var U={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`},St=[{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`}],Ct=[{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.`}],wt=[{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 Tt(){let e=N(),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),re=e=>{confirm(`Delete this scheduled task?`)&&D(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:U.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:U.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:U.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:U.tabs,children:[(0,k.jsxs)(`button`,{className:`${U.tab} ${x===`jobs`?U.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${U.tab} ${x===`templates`?U.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:U.templates,children:[(0,k.jsx)(`div`,{className:U.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),Ct.map(t=>(0,k.jsxs)(`div`,{className:U.templateCard,children:[(0,k.jsx)(`div`,{className:U.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:U.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:U.templateBtns,children:[(0,k.jsx)(`button`,{className:U.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:U.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:U.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:U.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:U.empty,children:[(0,k.jsx)(`div`,{className:U.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:U.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:U.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${U.card} ${e.enabled?``:U.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:U.cardTop,children:[(0,k.jsxs)(`div`,{className:U.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:U.jobName,children:e.name}),(0,k.jsx)(`code`,{className:U.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:U.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${U.statusBadge} ${e.enabled?U.statusActive:U.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:U.cardActions,children:[(0,k.jsx)(`button`,{className:U.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:U.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?U.pauseBtn:U.resumeBtn,onClick:()=>T(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:U.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:U.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:U.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:U.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:U.formModal,children:[(0,k.jsx)(`div`,{className:U.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:U.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:U.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:U.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:U.presets,children:St.map(e=>(0,k.jsx)(`button`,{className:`${U.preset} ${u.schedule===e.value?U.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:U.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:U.cronHints,children:wt.map(e=>(0,k.jsxs)(`span`,{className:U.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:U.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:U.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:U.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:U.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:U.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:U.formOk,children:g}),(0,k.jsxs)(`div`,{className:U.formBtns,children:[(0,k.jsx)(`button`,{className:U.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:U.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var Et={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 Dt(){let e=N(),[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,k.jsxs)(`div`,{className:Et.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Et.root,children:[(0,k.jsxs)(`div`,{className:Et.sidebar,children:[(0,k.jsx)(`button`,{className:Et.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:Et.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${Et.noteItem} ${a?.id===e.id?Et.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:Et.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:Et.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:Et.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:Et.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:Et.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:Et.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:Et.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:Et.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:Et.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:Et.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:Et.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Et.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:Et.emptyEditor,children:`Select a note or create a new one`})})]})}var Ot={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`},kt={name:``,email:``,phone:``,company:``,address:``,notes:``};function At(){let e=N(),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({...kt}),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,k.jsxs)(`div`,{className:Ot.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:Ot.error,children:o}):(0,k.jsxs)(`div`,{className:Ot.root,children:[(0,k.jsxs)(`div`,{className:Ot.toolbar,children:[(0,k.jsx)(`input`,{className:Ot.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:Ot.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:Ot.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:Ot.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:Ot.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:Ot.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:Ot.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:Ot.avatarImg}):T(e.name)}),(0,k.jsxs)(`div`,{className:Ot.info,children:[(0,k.jsx)(`div`,{className:Ot.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:Ot.row,children:[e.email&&(0,k.jsx)(`span`,{className:Ot.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:Ot.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:Ot.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:Ot.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:Ot.actions,children:[e.email&&(0,k.jsx)(`button`,{className:Ot.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:Ot.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${Ot.iconBtn} ${Ot.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:Ot.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:Ot.modal,children:[(0,k.jsx)(`div`,{className:Ot.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:Ot.field,children:[(0,k.jsx)(`label`,{className:Ot.label,children:t}),(0,k.jsx)(`input`,{className:Ot.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?Ot.formError:Ot.formStatus,children:g}),(0,k.jsxs)(`div`,{className:Ot.modalBtns,children:[(0,k.jsx)(`button`,{className:Ot.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Ot.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var W={root:`_root_19042_2`,topbar:`_topbar_19042_11`,topbarLeft:`_topbarLeft_19042_20`,topbarTitle:`_topbarTitle_19042_21`,topbarSub:`_topbarSub_19042_22`,topbarActions:`_topbarActions_19042_23`,runBtn:`_runBtn_19042_25`,runBtnActive:`_runBtnActive_19042_32`,logBtn:`_logBtn_19042_34`,newWfBtn:`_newWfBtn_19042_41`,body:`_body_19042_50`,sidebar:`_sidebar_19042_53`,sidebarTitle:`_sidebarTitle_19042_61`,sidebarEmpty:`_sidebarEmpty_19042_65`,wfItem:`_wfItem_19042_67`,wfItemActive:`_wfItemActive_19042_78`,wfItemRow:`_wfItemRow_19042_79`,wfItemName:`_wfItemName_19042_80`,wfItemMeta:`_wfItemMeta_19042_81`,wfOn:`_wfOn_19042_82`,wfOff:`_wfOff_19042_83`,wfDelBtn:`_wfDelBtn_19042_84`,canvasArea:`_canvasArea_19042_92`,canvasHeader:`_canvasHeader_19042_94`,wfNameInput:`_wfNameInput_19042_99`,canvasHint:`_canvasHint_19042_106`,portHint:`_portHint_19042_107`,connectHint:`_connectHint_19042_108`,cancelConnectBtn:`_cancelConnectBtn_19042_109`,canvas:`_canvas_19042_92`,canvasConnecting:`_canvasConnecting_19042_122`,canvasSvg:`_canvasSvg_19042_124`,canvasNode:`_canvasNode_19042_134`,canvasNodeSelected:`_canvasNodeSelected_19042_152`,canvasNodeConnecting:`_canvasNodeConnecting_19042_153`,nodeIcon:`_nodeIcon_19042_155`,nodeLabel:`_nodeLabel_19042_156`,nodeConfigPreview:`_nodeConfigPreview_19042_157`,nodeDelBtn:`_nodeDelBtn_19042_159`,portOut:`_portOut_19042_171`,portActive:`_portActive_19042_182`,portIn:`_portIn_19042_184`,pulse:`_pulse_19042_1`,canvasDrop:`_canvasDrop_19042_195`,canvasEmpty:`_canvasEmpty_19042_203`,canvasEmptyIcon:`_canvasEmptyIcon_19042_208`,canvasEmptyTitle:`_canvasEmptyTitle_19042_209`,canvasEmptyDesc:`_canvasEmptyDesc_19042_210`,logPanel:`_logPanel_19042_213`,logHeader:`_logHeader_19042_220`,logTime:`_logTime_19042_226`,logClose:`_logClose_19042_227`,logEmpty:`_logEmpty_19042_228`,logStep:`_logStep_19042_229`,logStepError:`_logStepError_19042_230`,logStepHeader:`_logStepHeader_19042_231`,logStepIcon:`_logStepIcon_19042_232`,logStepLabel:`_logStepLabel_19042_233`,logStepErrBadge:`_logStepErrBadge_19042_234`,logStepErr:`_logStepErr_19042_230`,logStepOutput:`_logStepOutput_19042_236`,rightPanel:`_rightPanel_19042_241`,configPanel:`_configPanel_19042_252`,configHeader:`_configHeader_19042_253`,configClose:`_configClose_19042_254`,configDesc:`_configDesc_19042_255`,configFields:`_configFields_19042_256`,configField:`_configField_19042_256`,configLabel:`_configLabel_19042_258`,configRequired:`_configRequired_19042_259`,configInput:`_configInput_19042_260`,configHint:`_configHint_19042_267`,configDelete:`_configDelete_19042_269`,palette:`_palette_19042_273`,paletteTitle:`_paletteTitle_19042_274`,paletteTabs:`_paletteTabs_19042_275`,paletteTab:`_paletteTab_19042_275`,paletteTabActive:`_paletteTabActive_19042_281`,paletteNodes:`_paletteNodes_19042_282`,paletteDef:`_paletteDef_19042_284`,paletteDefIcon:`_paletteDefIcon_19042_292`,paletteDefLabel:`_paletteDefLabel_19042_293`,paletteDefDesc:`_paletteDefDesc_19042_294`,paletteFooter:`_paletteFooter_19042_296`,paletteGuide:`_paletteGuide_19042_300`,guideTitle:`_guideTitle_19042_308`,guideStep:`_guideStep_19042_317`,guideNum:`_guideNum_19042_325`,guideTip:`_guideTip_19042_341`,guideCode:`_guideCode_19042_352`},jt=[{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.`,configFields:[{key:`path`,label:`Path`,placeholder:`/hook/my-trigger`}]},{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}}`}]}],Mt=Object.fromEntries(jt.map(e=>[e.id,e])),Nt=90,Pt=72;function Ft(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function It(e,t){return{x:e.x+(t===`out`?Nt:0),y:e.y+Pt/2}}function Lt(){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=(0,_.useRef)(null),v=(0,_.useRef)(null),y=(0,_.useRef)(null),b=(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)(()=>{b()},[b]);let x=(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)},[]),S=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:jt},n=(await D(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},C=async e=>{confirm(`Delete this workflow?`)&&(await D(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),b())},w=(0,_.useCallback)(e=>{e.preventDefault();let t=v.current;if(!t||!n)return;let r=y.current.getBoundingClientRect(),i=Math.round((e.clientX-r.left-Nt/2)/20)*20,o=Math.round((e.clientY-r.top-Pt/2)/20)*20,s={id:Ft(),defId:t,x:Math.max(0,i),y:Math.max(0,o),config:{}};x({...n,nodes:[...n.nodes,s]}),a(s.id),v.current=null},[n,x]),ee=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||x({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(g.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,x]),te=(0,_.useCallback)(e=>{if(!g.current||!n)return;let{id:t,ox:i,oy:a}=g.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]),ne=(0,_.useCallback)(()=>{if(!g.current||!n){g.current=null;return}n.nodes.find(e=>e.id===g.current.id)&&x(n),g.current=null},[n,x]),T=(0,_.useCallback)(e=>{n&&(x({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,x]),re=(0,_.useCallback)((e,t)=>{n&&x({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,x]),ie=(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]),O=(0,_.useCallback)(()=>{n&&x(n)},[n,x]),ae=async()=>{if(!(!n||c)){l(!0),p(!0),d([]);try{let e={...n,nodeDefs:jt};await D(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null),d((await D(`/api/workflows/${n.id}/run`,{}))?.steps??[]),b()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},A=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)},j=n?.nodes.find(e=>e.id===i)??null,oe=j?Mt[j.defId]:null;return(0,k.jsxs)(`div`,{className:W.root,children:[(0,k.jsxs)(`div`,{className:W.topbar,children:[(0,k.jsxs)(`div`,{className:W.topbarLeft,children:[(0,k.jsx)(`span`,{className:W.topbarTitle,children:`Connectors`}),(0,k.jsx)(`span`,{className:W.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:W.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${W.runBtn} ${c?W.runBtnActive:``}`,onClick:ae,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:W.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})]}),(0,k.jsxs)(`div`,{className:W.body,children:[(0,k.jsxs)(`div`,{className:W.sidebar,children:[(0,k.jsx)(`div`,{className:W.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:W.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${W.wfItem} ${n?.id===e.id?W.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:W.wfItemRow,children:[(0,k.jsx)(`span`,{className:W.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?W.wfOn:W.wfOff,onClick:t=>{t.stopPropagation(),A(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:W.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,k.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,k.jsx)(`button`,{className:W.wfDelBtn,onClick:t=>{t.stopPropagation(),C(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:W.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:W.canvasHeader,children:[(0,k.jsx)(`input`,{className:W.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&x(n)}),o?(0,k.jsxs)(`span`,{className:W.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:W.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:W.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:y,className:`${W.canvas} ${o?W.canvasConnecting:``}`,onMouseMove:te,onMouseUp:ne,onMouseLeave:ne,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>{o||a(null)},children:[(0,k.jsx)(`svg`,{className:W.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=It(r,`out`),o=It(i,`in`),s=(a.x+o.x)/2;return(0,k.jsxs)(`g`,{children:[(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`var(--green3)`,strokeWidth:`2`,fill:`none`,strokeDasharray:`6,3`,opacity:`0.8`}),(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`transparent`,strokeWidth:`12`,fill:`none`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`circle`,{cx:s,cy:(a.y+o.y)/2,r:`7`,fill:`var(--bg2)`,stroke:`var(--border)`,strokeWidth:`1.5`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`text`,{x:s,y:(a.y+o.y)/2+4,textAnchor:`middle`,fill:`var(--dim)`,fontSize:`9`,style:{cursor:`pointer`,pointerEvents:`none`},children:`✕`})]},t)})}),n.nodes.map(e=>{let t=Mt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,k.jsxs)(`div`,{className:`${W.canvasNode} ${n?W.canvasNodeSelected:``} ${r?W.canvasNodeConnecting:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>ee(t,e.id),onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(`button`,{className:W.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),T(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:W.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:W.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,k.jsx)(`span`,{className:W.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${W.portOut} ${r?W.portActive:``}`,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),s(t=>t===e.id?null:e.id)},title:`Connect from here`,children:`▶`}),o&&o!==e.id&&(0,k.jsx)(`button`,{className:W.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),ee(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,k.jsx)(`div`,{className:W.canvasDrop,children:`Drag nodes from the right panel and drop here`})]}),f&&(0,k.jsxs)(`div`,{className:W.logPanel,children:[(0,k.jsxs)(`div`,{className:W.logHeader,children:[(0,k.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,k.jsx)(`span`,{className:W.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,k.jsx)(`button`,{className:W.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,k.jsx)(`div`,{className:W.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,k.jsxs)(`div`,{className:`${W.logStep} ${e.error?W.logStepError:``}`,children:[(0,k.jsxs)(`div`,{className:W.logStepHeader,children:[(0,k.jsx)(`span`,{className:W.logStepIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:W.logStepLabel,children:e.nodeLabel}),e.error&&(0,k.jsx)(`span`,{className:W.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,k.jsx)(`div`,{className:W.logStepErr,children:e.error}),e.output&&(0,k.jsx)(`div`,{className:W.logStepOutput,dangerouslySetInnerHTML:{__html:ye(e.output.slice(0,500))}})]},t))]})]}):(0,k.jsxs)(`div`,{className:W.canvasEmpty,children:[(0,k.jsx)(`div`,{className:W.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:W.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:W.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,k.jsx)(`br`,{}),`Connect them by clicking the `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` output port then the target node.`,(0,k.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:W.rightPanel,children:j&&oe?(0,k.jsxs)(`div`,{className:W.configPanel,children:[(0,k.jsxs)(`div`,{className:W.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:oe.color},children:[oe.icon,` `,oe.label]}),(0,k.jsx)(`button`,{className:W.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:W.configDesc,children:oe.description}),(0,k.jsx)(`div`,{className:W.configFields,children:(oe.configFields??[]).map(e=>(0,k.jsxs)(`div`,{className:W.configField,children:[(0,k.jsxs)(`label`,{className:W.configLabel,children:[e.label,e.required&&(0,k.jsx)(`span`,{className:W.configRequired,children:`*`})]}),(0,k.jsx)(`input`,{className:W.configInput,value:j.config[e.key]??``,placeholder:e.placeholder??``,onChange:t=>ie(j.id,e.key,t.target.value),onBlur:O}),(e.placeholder?.includes(`{{`)??!1)&&(0,k.jsxs)(`div`,{className:W.configHint,children:[`Use `,(0,k.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},e.key))}),(0,k.jsx)(`button`,{className:W.configDelete,onClick:()=>T(j.id),children:`Delete node`})]}):(0,k.jsxs)(`div`,{className:W.palette,children:[(0,k.jsx)(`div`,{className:W.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:W.paletteTabs,children:[{id:`trigger`,label:`Triggers`,color:`#fbbf24`},{id:`action`,label:`Actions`,color:`#38bdf8`},{id:`ai`,label:`AI`,color:`#a5b4fc`}].map(e=>(0,k.jsx)(`button`,{className:`${W.paletteTab} ${m===e.id?W.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,k.jsx)(`div`,{className:W.paletteNodes,children:jt.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:W.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{v.current=e.id},onDragEnd:()=>{v.current=null},children:[(0,k.jsx)(`span`,{className:W.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:W.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:W.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:W.paletteGuide,children:[(0,k.jsx)(`div`,{className:W.guideTitle,children:`How to use Connectors`}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`2`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`3`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`4`}),(0,k.jsxs)(`span`,{children:[`Click the `,(0,k.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,k.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`5`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`6`}),(0,k.jsxs)(`span`,{children:[`Press `,(0,k.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,k.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`Tip:`}),` Click an edge to delete it. Drag nodes on the canvas to reposition. All 80 NHA tools are pre-authenticated — no extra setup.`]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]})]})}var G={root:`_root_1ssbe_1`,sidebar:`_sidebar_1ssbe_12`,sidebarSection:`_sidebarSection_1ssbe_23`,sidebarLabel:`_sidebarLabel_1ssbe_28`,accountSelect:`_accountSelect_1ssbe_36`,sidebarCompose:`_sidebarCompose_1ssbe_46`,composeBtn:`_composeBtn_1ssbe_51`,folderList:`_folderList_1ssbe_63`,folderItem:`_folderItem_1ssbe_69`,folderActive:`_folderActive_1ssbe_82`,badge:`_badge_1ssbe_88`,labelHeader:`_labelHeader_1ssbe_103`,addLabelBtn:`_addLabelBtn_1ssbe_114`,newLabelRow:`_newLabelRow_1ssbe_123`,newLabelInput:`_newLabelInput_1ssbe_129`,newLabelSave:`_newLabelSave_1ssbe_139`,labelDot:`_labelDot_1ssbe_150`,syncArea:`_syncArea_1ssbe_158`,syncBtn:`_syncBtn_1ssbe_163`,messageList:`_messageList_1ssbe_175`,listHeader:`_listHeader_1ssbe_185`,searchInput:`_searchInput_1ssbe_194`,searchBtn:`_searchBtn_1ssbe_204`,listBody:`_listBody_1ssbe_214`,listLoading:`_listLoading_1ssbe_219`,noMessages:`_noMessages_1ssbe_224`,msgRow:`_msgRow_1ssbe_231`,msgUnread:`_msgUnread_1ssbe_242`,msgActive:`_msgActive_1ssbe_247`,msgTop:`_msgTop_1ssbe_251`,msgFrom:`_msgFrom_1ssbe_257`,msgDate:`_msgDate_1ssbe_270`,msgSubject:`_msgSubject_1ssbe_277`,msgPreview:`_msgPreview_1ssbe_289`,listFooter:`_listFooter_1ssbe_300`,loadMoreBtn:`_loadMoreBtn_1ssbe_311`,pane:`_pane_1ssbe_322`,emptyPane:`_emptyPane_1ssbe_330`,readingPane:`_readingPane_1ssbe_337`,paneToolbar:`_paneToolbar_1ssbe_344`,paneActions:`_paneActions_1ssbe_354`,replyBtn:`_replyBtn_1ssbe_360`,fwdBtn:`_fwdBtn_1ssbe_371`,trashBtn:`_trashBtn_1ssbe_371`,starBtn:`_starBtn_1ssbe_371`,aiBtn:`_aiBtn_1ssbe_384`,labelSelect:`_labelSelect_1ssbe_394`,paneHeader:`_paneHeader_1ssbe_403`,paneSubject:`_paneSubject_1ssbe_409`,paneMeta:`_paneMeta_1ssbe_416`,attachments:`_attachments_1ssbe_424`,attachLink:`_attachLink_1ssbe_431`,paneBody:`_paneBody_1ssbe_441`,bodyFrame:`_bodyFrame_1ssbe_447`,bodyText:`_bodyText_1ssbe_455`,composePane:`_composePane_1ssbe_465`,composeTitle:`_composeTitle_1ssbe_474`,composeField:`_composeField_1ssbe_483`,templateRow:`_templateRow_1ssbe_495`,templateToggle:`_templateToggle_1ssbe_500`,templateDrop:`_templateDrop_1ssbe_510`,templateItem:`_templateItem_1ssbe_524`,templateSubject:`_templateSubject_1ssbe_534`,composeBody:`_composeBody_1ssbe_540`,composeActions:`_composeActions_1ssbe_556`,sendBtn:`_sendBtn_1ssbe_563`,cancelBtn:`_cancelBtn_1ssbe_574`,compStatus:`_compStatus_1ssbe_584`,ok:`_ok_1ssbe_585`,err:`_err_1ssbe_586`},Rt=[{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:`🗑`}],zt=[{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 Bt(e){return e?e.slice(0,10):``}function Vt(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 Ht(){let e=N(),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,re]=(0,_.useState)(!1),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[j,oe]=(0,_.useState)(0),[se,ce]=(0,_.useState)(!1),[le,M]=(0,_.useState)({}),[P,F]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(``),[me,he]=(0,_.useState)(``),[ge,_e]=(0,_.useState)(``),[ve,ye]=(0,_.useState)(!1),[I,be]=(0,_.useState)(``),[xe,Se]=(0,_.useState)(!1),Ce=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle)),E(`/api/imap/accounts`).then(e=>{let t=e?.accounts??[];a(t);let n=localStorage.getItem(`nha-email-account-type`),r=localStorage.getItem(`nha-email-account-id`);n===`google`?L(`google`,`google`):n===`imap`&&r&&t.some(e=>e.id===r)?L(r,`imap`):t.length>0?L(t[0].id,`imap`):L(`google`,`google`)})},[]);let L=(e,t)=>{s(e),l(t),p(t===`google`?`INBOX`:null),localStorage.setItem(`nha-email-account-type`,t),localStorage.setItem(`nha-email-account-id`,e),h([]),b(0),S(null),w(null),t===`imap`?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),we(e,r,0,``)}):(d([]),Te(`INBOX`,``))},we=(e,t,n,r)=>{te(!0);let i=`/api/imap/messages?accountId=${encodeURIComponent(e)}&limit=50&offset=${n}`;t&&(i+=`&labelId=${encodeURIComponent(t)}`),r&&(i+=`&search=${encodeURIComponent(r)}`),E(i).then(e=>{h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),te(!1)}).catch(()=>te(!1))},Te=(e,t)=>{te(!0);let n=e===`INBOX`||!e?`all`:e.toLowerCase(),r=`/api/emails?filter=${encodeURIComponent(t||n)}&page=0&pageSize=50`;t&&(r=`/api/emails?filter=${encodeURIComponent(t)}&page=0&pageSize=50`),E(r).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);let n=t.filter(e=>!e.is_read).length;oe(n),te(!1)}).catch(()=>te(!1))},Ee=()=>{O(ae),b(0),h([]),c===`imap`&&o?we(o,f,0,ae):Te(f??`INBOX`,ae)},R=e=>{S(e),ce(!1),re(!0),c===`google`?E(`/api/imap/message?messageId=${encodeURIComponent(e)}&accountId=google`).then(t=>{if(t?.message){w({...t.message,id:e,_google:!0}),re(!1);return}D(`/api/email/read`,{messageId:e}).then(t=>{if(t?.message){let n=t.message;w({...n,body_text:n.body||n.body_text,body_html:n.body_html,from_address:n.from||n.from_address,from_name:n.from_name,id:e,_google:!0}),re(!1),D(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}else re(!1)}).catch(()=>re(!1))}).catch(()=>{re(!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)),re(!1)}).catch(()=>re(!1))},z=(e={})=>{ce(!0),M(e),F(e.to??``),de(``),pe(e.subject??``),he(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),_e(``),ye(!1),S(null),w(null)},De=async()=>{if(!P.trim()){_e(`Recipient required`);return}_e(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:P.trim(),cc:ue.trim()||void 0,subject:fe.trim(),bodyHtml:me.replace(/\n/g,`<br>`),bodyText:me,inReplyTo:le.inReplyTo||void 0});e?.ok?(_e(`Sent!`),setTimeout(()=>ce(!1),800)):_e(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:P.trim(),subject:fe.trim(),body:me});e?.ok||e?.id?(_e(`Sent!`),setTimeout(()=>ce(!1),800)):_e(e?.error??`Error`)}}catch(e){_e(e.message??`Error`)}},Oe=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})})},Ae=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},je=()=>{!I.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:I.trim()}).then(()=>{Se(!1),be(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})};return(0,k.jsxs)(`div`,{className:G.root,children:[(0,k.jsxs)(`div`,{className:G.sidebar,children:[(0,k.jsxs)(`div`,{className:G.sidebarSection,children:[(0,k.jsx)(`div`,{className:G.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:G.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?L(`google`,`google`):t.startsWith(`imap:`)&&L(t.slice(5),`imap`)},children:[n&&(0,k.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,k.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,k.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,k.jsx)(`div`,{className:G.sidebarCompose,children:(0,k.jsx)(`button`,{className:G.composeBtn,onClick:()=>z(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:G.folderList,children:c===`google`?Rt.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Te(e.id,ie)},children:[(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&j>0&&(0,k.jsx)(`span`,{className:G.badge,children:j})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:G.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:G.addLabelBtn,onClick:()=>Se(e=>!e),children:`+`})]}),xe&&(0,k.jsxs)(`div`,{className:G.newLabelRow,children:[(0,k.jsx)(`input`,{className:G.newLabelInput,value:I,onChange:e=>be(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&je()}),(0,k.jsx)(`button`,{className:G.newLabelSave,onClick:je,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&we(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:G.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.unread_count?(0,k.jsx)(`span`,{className:G.badge,children:e.unread_count}):null]},e.id))]})}),c===`imap`&&o&&(0,k.jsx)(`div`,{className:G.syncArea,children:(0,k.jsx)(`button`,{className:G.syncBtn,onClick:()=>{o&&c===`imap`&&D(`/api/imap/sync/${o}`,{})},children:`Sync now`})})]}),(0,k.jsxs)(`div`,{className:G.messageList,children:[(0,k.jsxs)(`div`,{className:G.listHeader,children:[(0,k.jsx)(`input`,{className:G.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&Ee()}),(0,k.jsx)(`button`,{className:G.searchBtn,onClick:Ee,children:`Go`})]}),(0,k.jsxs)(`div`,{className:G.listBody,children:[ee&&(0,k.jsx)(`div`,{className:G.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:G.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${G.msgRow} ${e.id===x?G.msgActive:``} ${e.is_read?``:G.msgUnread}`,onClick:()=>R(e.id),children:[(0,k.jsxs)(`div`,{className:G.msgTop,children:[(0,k.jsx)(`span`,{className:G.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:G.msgDate,children:Bt(e.internal_date)})]}),(0,k.jsx)(`div`,{className:G.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:G.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:G.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),m.length<g&&c===`imap`&&(0,k.jsx)(`button`,{className:G.loadMoreBtn,onClick:()=>{let e=y+50;b(e),o&&we(o,f,e,ie)},children:`Load more`})]})]}),(0,k.jsx)(`div`,{className:G.pane,children:(()=>{if(se)return(0,k.jsxs)(`div`,{className:G.composePane,children:[(0,k.jsx)(`div`,{className:G.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:G.composeField,value:P,onChange:e=>F(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:G.composeField,value:ue,onChange:e=>de(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:G.composeField,value:fe,onChange:e=>pe(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:G.templateRow,children:[(0,k.jsx)(`button`,{className:G.templateToggle,onClick:()=>ye(e=>!e),children:`📄 Templates`}),ve&&(0,k.jsx)(`div`,{className:G.templateDrop,children:zt.map((e,t)=>(0,k.jsxs)(`div`,{className:G.templateItem,onClick:()=>{pe(t=>t||e.subject),ye(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:G.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:G.composeBody,value:me,onChange:e=>he(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:G.composeActions,children:[(0,k.jsx)(`button`,{className:G.sendBtn,onClick:De,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:G.cancelBtn,onClick:()=>ce(!1),children:`Discard`}),ge&&(0,k.jsx)(`span`,{className:`${G.compStatus} ${ge===`Sent!`?G.ok:G.err}`,children:ge})]})]});if(T)return(0,k.jsx)(`div`,{className:G.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:G.emptyPane,children:`Select a message`});let n=Vt(C.to_addresses);return(0,k.jsxs)(`div`,{className:G.readingPane,children:[(0,k.jsx)(`div`,{className:G.paneToolbar,children:(0,k.jsxs)(`div`,{className:G.paneActions,children:[(0,k.jsx)(`button`,{className:G.replyBtn,onClick:()=>z({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,k.jsx)(`button`,{className:G.fwdBtn,onClick:()=>z({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:G.trashBtn,onClick:()=>Oe(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:G.starBtn,onClick:()=>ke(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:G.labelSelect,defaultValue:``,onChange:e=>Ae(C.id,e.target.value),children:[(0,k.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsx)(`button`,{className:G.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:G.paneHeader,children:[(0,k.jsx)(`div`,{className:G.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:G.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:G.attachLink,href:`/api/imap/attachment?messageId=${encodeURIComponent(C.id)}&partId=${encodeURIComponent(e.part_id??``)}&accountId=${encodeURIComponent(o??``)}`,download:e.filename??`attachment`,children:[`📎 `,e.filename??`attachment`,` (`,Math.round((e.size_bytes??0)/1024),`KB)`]},t))})]}),(0,k.jsx)(`div`,{className:G.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:Ce,sandbox:`allow-same-origin`,className:G.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,k.jsx)(`pre`,{className:G.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var K={root:`_root_1u06k_1`,center:`_center_1u06k_10`,noGoogle:`_noGoogle_1u06k_17`,noGoogleIcon:`_noGoogleIcon_1u06k_26`,noGoogleTitle:`_noGoogleTitle_1u06k_27`,noGoogleSub:`_noGoogleSub_1u06k_28`,connectBtn:`_connectBtn_1u06k_30`,calCol:`_calCol_1u06k_42`,navRow:`_navRow_1u06k_50`,navBtn:`_navBtn_1u06k_57`,monthTitle:`_monthTitle_1u06k_70`,dayHeaders:`_dayHeaders_1u06k_78`,dayHeader:`_dayHeader_1u06k_78`,weekend:`_weekend_1u06k_92`,grid:`_grid_1u06k_94`,cell:`_cell_1u06k_103`,emptyCell:`_emptyCell_1u06k_119`,weekendCell:`_weekendCell_1u06k_121`,todayCell:`_todayCell_1u06k_122`,activeCell:`_activeCell_1u06k_123`,hasEvtsCell:`_hasEvtsCell_1u06k_124`,holidayCell:`_holidayCell_1u06k_125`,dayNum:`_dayNum_1u06k_127`,todayNum:`_todayNum_1u06k_133`,weekendNum:`_weekendNum_1u06k_134`,evtPills:`_evtPills_1u06k_136`,evtPill:`_evtPill_1u06k_136`,holidayPill:`_holidayPill_1u06k_156`,morePill:`_morePill_1u06k_158`,loadingBar:`_loadingBar_1u06k_164`,detailCol:`_detailCol_1u06k_173`,detailHeader:`_detailHeader_1u06k_184`,detailDate:`_detailDate_1u06k_192`,addEvtBtn:`_addEvtBtn_1u06k_198`,noEvts:`_noEvts_1u06k_210`,selectDay:`_selectDay_1u06k_217`,evtCard:`_evtCard_1u06k_224`,evtTop:`_evtTop_1u06k_234`,evtTime:`_evtTime_1u06k_241`,evtBtns:`_evtBtns_1u06k_247`,editBtn:`_editBtn_1u06k_253`,delBtn:`_delBtn_1u06k_263`,readOnly:`_readOnly_1u06k_273`,evtTitle:`_evtTitle_1u06k_280`,evtLoc:`_evtLoc_1u06k_286`,evtMeta:`_evtMeta_1u06k_287`,attendees:`_attendees_1u06k_289`,attendee:`_attendee_1u06k_289`,evtDesc:`_evtDesc_1u06k_300`,joinBtn:`_joinBtn_1u06k_310`,gcalLink:`_gcalLink_1u06k_317`,overlay:`_overlay_1u06k_324`,formCard:`_formCard_1u06k_334`,formTitle:`_formTitle_1u06k_348`,formLabel:`_formLabel_1u06k_355`,formInput:`_formInput_1u06k_361`,formTextarea:`_formTextarea_1u06k_374`,formError:`_formError_1u06k_390`,formBtns:`_formBtns_1u06k_395`,cancelFormBtn:`_cancelFormBtn_1u06k_402`,saveFormBtn:`_saveFormBtn_1u06k_412`};function Ut(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function Wt(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function Gt(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 Kt(){let e=N(),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,k.jsx)(`div`,{className:K.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:K.center,children:(0,k.jsxs)(`div`,{className:K.noGoogle,children:[(0,k.jsx)(`div`,{className:K.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:K.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:K.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:K.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let re=new Date(a,s,1).getDay(),ie=new Date(a,s+1,0).getDate(),O=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ae=(re+6)%7,A=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],j=p?l[p]??[]:[];return(0,k.jsxs)(`div`,{className:K.root,children:[(0,k.jsxs)(`div`,{className:K.calCol,children:[(0,k.jsxs)(`div`,{className:K.navRow,children:[(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:K.monthTitle,children:O}),(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:K.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${K.dayHeader} ${t>=5?K.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:K.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.cell} ${K.emptyCell} ${t>=5?K.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=Ut(a,s,n),i=Wt(a,s,n),o=l[r]??[],c=o.length,u=(ae+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,k.jsxs)(`div`,{className:`${K.cell} ${i?K.todayCell:u?K.weekendCell:``} ${f?K.activeCell:``} ${d?K.holidayCell:c>0?K.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${K.dayNum} ${i?K.todayNum:u?K.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:K.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.evtPill} ${e._isHoliday||e.readOnly?K.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:K.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:K.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:K.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:K.detailHeader,children:[(0,k.jsx)(`div`,{className:K.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:K.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),j.length===0?(0,k.jsx)(`div`,{className:K.noEvts,children:`No events on this day`}):j.map((t,n)=>{let r=t.isAllDay?`All day`:`${Gt(t.start)} - ${Gt(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:K.evtCard,children:[(0,k.jsxs)(`div`,{className:K.evtTop,children:[(0,k.jsx)(`div`,{className:K.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:K.evtBtns,children:[(0,k.jsx)(`button`,{className:K.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:K.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:K.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:K.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:K.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:K.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:K.attendees,children:[(0,k.jsx)(`div`,{className:K.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:K.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:K.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:K.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:K.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsx)(`div`,{className:K.selectDay,children:`Select a day to see events`})}),h&&(0,k.jsx)(`div`,{className:K.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:K.formCard,children:[(0,k.jsx)(`div`,{className:K.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:K.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:K.formError,children:v}),(0,k.jsxs)(`div`,{className:K.formBtns,children:[(0,k.jsx)(`button`,{className:K.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:K.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var q={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`},qt={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 Jt(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=qt[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 Yt(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function Xt(){let e=N(),[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),re=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),ae=(0,_.useRef)(new Map),A=(0,_.useRef)(new Map),j=(0,_.useRef)(null),oe=()=>{E(`/api/agents`).then(e=>{n((e?.agents??[]).map(Jt)),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?(re.current.get(e.id)?.abort(),re.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,Yt(e)]})},M=e=>{re.current.get(e)?.abort(),re.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},P=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},F=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},ue=(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}}))},de=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;F(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),P(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);F(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{F(i,{role:`assistant`,content:`Error sending attachment.`})}P(i,{streaming:!1});return}F(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;re.current.set(i,o);let s=``;try{await ie(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,ue(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{P(i,{streaming:!1}),re.current.delete(i)}},fe=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;F(r,{role:`user`,content:e}),P(r,{streaming:!0});let i=``,a=new AbortController;re.current.set(r,a),F(r,{role:`assistant`,content:``,streaming:!0});try{await ie(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,ue(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{P(r,{streaming:!1}),re.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(`
572
+ </body></html>`,f=new Blob([d],{type:`text/html`}),p=URL.createObjectURL(f),m=document.createElement(`a`);m.href=p,m.download=`nha-report-${Date.now()}.html`,m.click(),URL.revokeObjectURL(p);let h=window.open(``,`_blank`,`width=1100,height=800`);h&&(h.document.open(),h.document.write(d),h.document.close(),h.onload=()=>setTimeout(()=>{h.focus(),h.print()},600))},ve=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`)},I=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),le.current=``,w(null),M.current=null,te(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(tt)}catch{}}},be=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:L.root,children:[(0,k.jsxs)(`div`,{className:L.header,children:[(0,k.jsxs)(`div`,{className:L.headerLeft,children:[(0,k.jsx)(`div`,{className:L.title,children:`Studio`}),(0,k.jsx)(`div`,{className:L.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:L.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:L.tokenBar,children:[(0,k.jsxs)(`span`,{className:L.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:L.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` out`})]}),(0,k.jsxs)(`div`,{style:{position:`relative`},ref:P,children:[(0,k.jsxs)(`button`,{className:L.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,k.jsx)(`div`,{className:L.sessionsDrawer,children:f.length===0?(0,k.jsx)(`div`,{className:L.noSessions,children:`No saved sessions yet.`}):(0,k.jsxs)(k.Fragment,{children:[f.map(e=>(0,k.jsxs)(`div`,{className:L.sessionItem,children:[(0,k.jsxs)(`div`,{className:L.sessionInfo,onClick:()=>me(e),children:[(0,k.jsx)(`div`,{className:L.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:L.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,k.jsxs)(`div`,{className:L.sessionBtns,children:[(0,k.jsx)(`button`,{className:L.importBtn,onClick:()=>ve(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:L.delSessionBtn,onClick:()=>he(e.id),children:`✕`})]})]},e.id)),(0,k.jsx)(`div`,{className:L.sessionsFooter,children:(0,k.jsx)(`button`,{className:L.clearAllSessionsBtn,onClick:ge,children:`Clear All`})})]})})]}),x&&(0,k.jsx)(`button`,{className:L.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:L.pdfBtn,onClick:_e,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:L.clearBtn,onClick:I,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,k.jsxs)(`div`,{className:L.inputArea,children:[(0,k.jsxs)(`div`,{className:L.inputRow,children:[(0,k.jsx)(`textarea`,{className:L.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(),de())}}),(0,k.jsxs)(`div`,{className:L.inputControls,children:[u?(0,k.jsx)(`button`,{className:L.stopBtn,onClick:fe,children:`■ Stop`}):(0,k.jsx)(`button`,{className:L.runBtn,onClick:de,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:L.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>ue(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:L.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:L.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:L.examples,children:Ee.map((e,t)=>(0,k.jsx)(`button`,{className:L.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:L.financeSection,children:[(0,k.jsx)(`div`,{className:L.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:L.financePresets,children:we.map((e,t)=>(0,k.jsx)(`button`,{className:L.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:L.officeSceneWrap,children:(0,k.jsx)(Ye,{nodes:i,running:u})}),(0,k.jsxs)(`div`,{className:`${L.pipelineWrap} ${u?L.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:L.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:L.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:L.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:L.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${L.agentChip} ${L[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:L.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:L.chipDots,children:[(0,k.jsx)(`span`,{className:L.dot1,children:`.`}),(0,k.jsx)(`span`,{className:L.dot2,children:`.`}),(0,k.jsx)(`span`,{className:L.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:L.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:L.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${L.arrow} ${u?L.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:L.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:L.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:L.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:L.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,k.jsxs)(`div`,{className:L.body,children:[(o.length>0||be)&&(0,k.jsxs)(`div`,{className:L.twoCol,children:[(0,k.jsxs)(`div`,{className:L.logPanel,children:[(0,k.jsx)(`div`,{className:L.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:L.logBody,ref:ce,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.logEntry} ${L[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:L.logTime,children:e.time}),(0,k.jsx)(`span`,{className:L.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:L.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:L.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.liveBlock} ${e.status===`running`?L.liveBlockActive:``} ${e.status===`done`&&e.output?L.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?oe(e):void 0,children:[(0,k.jsxs)(`div`,{className:L.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:L.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:L.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${L.outputStatus} ${L[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:L.expandHint,children:`↗ espandi`})]}),e.status===`running`&&(0,k.jsxs)(`div`,{className:L.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingLabel,children:e.statusLine??`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${L.liveBlockBody} ${e.status===`done`&&e.output?L.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:ye(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:L.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:L.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:L.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,k.jsxs)(`div`,{className:L.parliamentPromptMeta,children:[`Complessità: `,T.length<=3?`⚡ Rapido (~30s)`:T.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:L.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:L.parliamentActivateBtn,onClick:pe,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:L.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:L.councilWrapper,children:(0,k.jsx)(ct,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:L.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:L.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:L.resultAccordionBody,dangerouslySetInnerHTML:{__html:ye(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:L.canvasPanel,children:[(0,k.jsxs)(`div`,{className:L.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:L.panelTabs,children:[(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`canvas`?L.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`browser`?L.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:L.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:L.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:L.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:L.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:L.browserPanel,children:[(0,k.jsxs)(`div`,{className:L.browserBar,children:[(0,k.jsx)(`input`,{className:L.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:L.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:L.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`Enter a URL above to browse`})]})]}),j&&(0,k.jsx)(`div`,{className:L.blockModalOverlay,onClick:()=>oe(null),children:(0,k.jsxs)(`div`,{className:L.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:L.blockModalHeader,children:[(0,k.jsx)(`span`,{className:L.liveBlockIcon,children:j.icon}),(0,k.jsx)(`span`,{className:L.blockModalTitle,children:j.label}),(0,k.jsx)(`button`,{className:L.blockModalClose,onClick:()=>oe(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${L.liveBlockBody} ${L.blockModalBody}`,dangerouslySetInnerHTML:{__html:ye(j.output)}})]})})]})}var V={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`},ut=[{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:`Connectors`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],dt={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 ft(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function pt(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function mt(){let e=ne(e=>e.setView),t=N(),[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?.tempC&&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(ut.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:V.root,children:[(0,k.jsxs)(`div`,{className:V.hero,children:[(0,k.jsxs)(`div`,{className:V.heroLeft,children:[(0,k.jsx)(`div`,{className:V.heroDate,children:y}),(0,k.jsx)(`div`,{className:V.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:V.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:V.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:V.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),location.reload())},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:V.wIcon,children:dt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:V.wInfo,children:[(0,k.jsxs)(`span`,{className:V.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:V.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:V.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:V.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:V.kpiRow,children:[(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:V.kpiBar,children:(0,k.jsx)(`div`,{className:V.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:V.kpi,children:[(0,k.jsxs)(`span`,{className:V.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:V.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:t.isAllDay?`All day`:ft(t.start)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:V.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${V.liveRow} ${t.isUnread?V.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:pt(t.date)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:V.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${V.prio} ${V[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:V.liveBody,children:(0,k.jsx)(`span`,{className:V.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:V.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:V.launchGroup,children:[(0,k.jsx)(`div`,{className:V.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:V.launchTiles,children:ut.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:V.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:V.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:V.tileLabel,children:t.label})]},t.view))})]},t))})]})}var ht={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 gt(){let e=N(),[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,k.jsxs)(`div`,{className:ht.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:ht.root,children:[(0,k.jsxs)(`div`,{className:ht.bar,children:[(0,k.jsx)(`input`,{ref:d,className:ht.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:ht.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:ht.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ht.actions,children:[(0,k.jsx)(`button`,{className:ht.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:ht.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ht.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:ht.progress,children:(0,k.jsx)(`span`,{className:ht.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:ht.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:ht.task,children:[(0,k.jsx)(`span`,{className:ht.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:ht.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ht.badge} ${ht[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ht.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:ht.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${ht.task} ${ht.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${ht.check} ${ht.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:ht.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ht.badge} ${ht[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ht.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var H={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`},_t={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function vt({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:H.fieldInput})]})}function yt(){let{setConfig:e}=ne(),t=N(),[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,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(`en`),[ae,A]=(0,_.useState)(`07:00`),[j,oe]=(0,_.useState)(`18:00`),[se,ce]=(0,_.useState)(`30`),[le,M]=(0,_.useState)(`off`),[P,F]=(0,_.useState)(``),[ue,de]=(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`),re(t?.model??``),O(t?.lang??`en`),A(t?.planTime??`07:00`),oe(t?.summaryTime??`18:00`),ce(String(t?.meetingAlert??`30`)),M(t?.thinking??`off`),te(``),a(!1),t&&e(t)}),fe()},[]);let fe=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),pe=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},me=()=>pe(`profile`,x),he=()=>{pe(`provider`,C),pe(`model`,T),pe(`thinking`,le),ee&&pe(`key`,ee)},ge=()=>{pe(`planTime`,ae),pe(`summaryTime`,j),pe(`meetingAlert`,Number(se))},_e=()=>{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))},ve=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},ye=()=>{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),fe()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},I=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>fe())},be=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(fe,3e3))};if(i)return(0,k.jsxs)(`div`,{className:H.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let xe=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:H.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(vt,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:me,children:[xe(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:H.nhaFree,children:[(0,k.jsx)(`div`,{className:H.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:H.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:H.nhaFreeBtn,onClick:()=>{D(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),re(``),te(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.llmProviderSub`)}),(()=>{let e=[];return n.hasApiKey&&e.push(`Anthropic`),n.hasOpenaiKey&&e.push(`OpenAI`),n.hasGeminiKey&&e.push(`Gemini`),n.hasDeepseekKey&&e.push(`DeepSeek`),n.hasGrokKey&&e.push(`Grok`),n.hasMistralKey&&e.push(`Mistral`),n.hasCohereKey&&e.push(`Cohere`),e.length===0?null:(0,k.jsxs)(`div`,{className:H.keySummary,children:[(0,k.jsx)(`span`,{className:H.keySummaryIcon,children:`🔑`}),(0,k.jsxs)(`span`,{children:[`Chiavi configurate: `,(0,k.jsx)(`strong`,{children:e.join(`, `)})]})]})})(),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:H.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(vt,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(vt,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:T,onChange:re}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:le,onChange:e=>M(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:he,children:[xe(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:ie,onChange:t=>{let r=t.target.value;O(r),pe(`lang`,r),e({...n,lang:r})},className:H.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(vt,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:P,onChange:F}),(0,k.jsx)(vt,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:ue,onChange:de}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:()=>{P&&pe(`telegram-bot-token`,P),ue&&pe(`discord-bot-token`,ue)},children:[xe(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(vt,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ae,onChange:A}),(0,k.jsx)(vt,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:j,onChange:oe}),(0,k.jsx)(vt,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:se,onChange:ce}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:ge,children:[xe(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:H.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:_e,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:H.dangerBtn,onClick:ve,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:H.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsxs)(`div`,{className:H.cardTitleRow,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:H.saveBtn,onClick:()=>{p({..._t}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:H.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:H.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:H.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:H.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:H.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:H.imapBtns,children:[(0,k.jsx)(`button`,{className:H.imapSyncBtn,onClick:()=>be(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:H.imapEditBtn,onClick:()=>{p({..._t,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:H.imapDelBtn,onClick:()=>I(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:H.imapForm,children:[(0,k.jsx)(`div`,{className:H.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(vt,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsxs)(`label`,{className:H.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:H.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:H.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:H.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:H.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:ye,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:H.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:H.statusMsg,children:m})]})]})]})}var bt={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 xt(){let e=N(),[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,k.jsxs)(`div`,{className:bt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:bt.err,children:a}):(0,k.jsxs)(`div`,{className:bt.root,children:[(0,k.jsxs)(`div`,{className:bt.header,children:[(0,k.jsx)(`div`,{className:bt.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:bt.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:bt.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${bt.card} ${r?bt.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:bt.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:bt.info,children:[(0,k.jsx)(`div`,{className:bt.name,children:t.name}),(0,k.jsx)(`div`,{className:bt.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?bt.labelToday:i?bt.labelTomorrow:bt.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:bt.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:bt.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:bt.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:bt.modal,children:[(0,k.jsx)(`div`,{className:bt.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:bt.label,children:`Name *`}),(0,k.jsx)(`input`,{className:bt.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:bt.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:bt.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:bt.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:bt.formErr,children:l}),(0,k.jsxs)(`div`,{className:bt.modalBtns,children:[(0,k.jsx)(`button`,{className:bt.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:bt.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var U={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`},St=[{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`}],Ct=[{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.`}],wt=[{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 Tt(){let e=N(),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),re=e=>{confirm(`Delete this scheduled task?`)&&D(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:U.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:U.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:U.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:U.tabs,children:[(0,k.jsxs)(`button`,{className:`${U.tab} ${x===`jobs`?U.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${U.tab} ${x===`templates`?U.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:U.templates,children:[(0,k.jsx)(`div`,{className:U.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),Ct.map(t=>(0,k.jsxs)(`div`,{className:U.templateCard,children:[(0,k.jsx)(`div`,{className:U.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:U.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:U.templateBtns,children:[(0,k.jsx)(`button`,{className:U.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:U.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:U.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:U.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:U.empty,children:[(0,k.jsx)(`div`,{className:U.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:U.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:U.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${U.card} ${e.enabled?``:U.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:U.cardTop,children:[(0,k.jsxs)(`div`,{className:U.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:U.jobName,children:e.name}),(0,k.jsx)(`code`,{className:U.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:U.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${U.statusBadge} ${e.enabled?U.statusActive:U.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:U.cardActions,children:[(0,k.jsx)(`button`,{className:U.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:U.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?U.pauseBtn:U.resumeBtn,onClick:()=>T(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:U.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:U.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:U.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:U.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:U.formModal,children:[(0,k.jsx)(`div`,{className:U.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:U.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:U.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:U.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:U.presets,children:St.map(e=>(0,k.jsx)(`button`,{className:`${U.preset} ${u.schedule===e.value?U.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:U.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:U.cronHints,children:wt.map(e=>(0,k.jsxs)(`span`,{className:U.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:U.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:U.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:U.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:U.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:U.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:U.formOk,children:g}),(0,k.jsxs)(`div`,{className:U.formBtns,children:[(0,k.jsx)(`button`,{className:U.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:U.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var Et={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 Dt(){let e=N(),[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,k.jsxs)(`div`,{className:Et.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Et.root,children:[(0,k.jsxs)(`div`,{className:Et.sidebar,children:[(0,k.jsx)(`button`,{className:Et.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:Et.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${Et.noteItem} ${a?.id===e.id?Et.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:Et.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:Et.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:Et.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:Et.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:Et.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:Et.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:Et.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:Et.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:Et.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:Et.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:Et.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Et.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:Et.emptyEditor,children:`Select a note or create a new one`})})]})}var Ot={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`},kt={name:``,email:``,phone:``,company:``,address:``,notes:``};function At(){let e=N(),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({...kt}),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,k.jsxs)(`div`,{className:Ot.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:Ot.error,children:o}):(0,k.jsxs)(`div`,{className:Ot.root,children:[(0,k.jsxs)(`div`,{className:Ot.toolbar,children:[(0,k.jsx)(`input`,{className:Ot.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:Ot.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:Ot.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:Ot.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:Ot.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:Ot.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:Ot.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:Ot.avatarImg}):T(e.name)}),(0,k.jsxs)(`div`,{className:Ot.info,children:[(0,k.jsx)(`div`,{className:Ot.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:Ot.row,children:[e.email&&(0,k.jsx)(`span`,{className:Ot.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:Ot.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:Ot.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:Ot.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:Ot.actions,children:[e.email&&(0,k.jsx)(`button`,{className:Ot.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:Ot.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${Ot.iconBtn} ${Ot.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:Ot.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:Ot.modal,children:[(0,k.jsx)(`div`,{className:Ot.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:Ot.field,children:[(0,k.jsx)(`label`,{className:Ot.label,children:t}),(0,k.jsx)(`input`,{className:Ot.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?Ot.formError:Ot.formStatus,children:g}),(0,k.jsxs)(`div`,{className:Ot.modalBtns,children:[(0,k.jsx)(`button`,{className:Ot.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Ot.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var W={root:`_root_19042_2`,topbar:`_topbar_19042_11`,topbarLeft:`_topbarLeft_19042_20`,topbarTitle:`_topbarTitle_19042_21`,topbarSub:`_topbarSub_19042_22`,topbarActions:`_topbarActions_19042_23`,runBtn:`_runBtn_19042_25`,runBtnActive:`_runBtnActive_19042_32`,logBtn:`_logBtn_19042_34`,newWfBtn:`_newWfBtn_19042_41`,body:`_body_19042_50`,sidebar:`_sidebar_19042_53`,sidebarTitle:`_sidebarTitle_19042_61`,sidebarEmpty:`_sidebarEmpty_19042_65`,wfItem:`_wfItem_19042_67`,wfItemActive:`_wfItemActive_19042_78`,wfItemRow:`_wfItemRow_19042_79`,wfItemName:`_wfItemName_19042_80`,wfItemMeta:`_wfItemMeta_19042_81`,wfOn:`_wfOn_19042_82`,wfOff:`_wfOff_19042_83`,wfDelBtn:`_wfDelBtn_19042_84`,canvasArea:`_canvasArea_19042_92`,canvasHeader:`_canvasHeader_19042_94`,wfNameInput:`_wfNameInput_19042_99`,canvasHint:`_canvasHint_19042_106`,portHint:`_portHint_19042_107`,connectHint:`_connectHint_19042_108`,cancelConnectBtn:`_cancelConnectBtn_19042_109`,canvas:`_canvas_19042_92`,canvasConnecting:`_canvasConnecting_19042_122`,canvasSvg:`_canvasSvg_19042_124`,canvasNode:`_canvasNode_19042_134`,canvasNodeSelected:`_canvasNodeSelected_19042_152`,canvasNodeConnecting:`_canvasNodeConnecting_19042_153`,nodeIcon:`_nodeIcon_19042_155`,nodeLabel:`_nodeLabel_19042_156`,nodeConfigPreview:`_nodeConfigPreview_19042_157`,nodeDelBtn:`_nodeDelBtn_19042_159`,portOut:`_portOut_19042_171`,portActive:`_portActive_19042_182`,portIn:`_portIn_19042_184`,pulse:`_pulse_19042_1`,canvasDrop:`_canvasDrop_19042_195`,canvasEmpty:`_canvasEmpty_19042_203`,canvasEmptyIcon:`_canvasEmptyIcon_19042_208`,canvasEmptyTitle:`_canvasEmptyTitle_19042_209`,canvasEmptyDesc:`_canvasEmptyDesc_19042_210`,logPanel:`_logPanel_19042_213`,logHeader:`_logHeader_19042_220`,logTime:`_logTime_19042_226`,logClose:`_logClose_19042_227`,logEmpty:`_logEmpty_19042_228`,logStep:`_logStep_19042_229`,logStepError:`_logStepError_19042_230`,logStepHeader:`_logStepHeader_19042_231`,logStepIcon:`_logStepIcon_19042_232`,logStepLabel:`_logStepLabel_19042_233`,logStepErrBadge:`_logStepErrBadge_19042_234`,logStepErr:`_logStepErr_19042_230`,logStepOutput:`_logStepOutput_19042_236`,rightPanel:`_rightPanel_19042_241`,configPanel:`_configPanel_19042_252`,configHeader:`_configHeader_19042_253`,configClose:`_configClose_19042_254`,configDesc:`_configDesc_19042_255`,configFields:`_configFields_19042_256`,configField:`_configField_19042_256`,configLabel:`_configLabel_19042_258`,configRequired:`_configRequired_19042_259`,configInput:`_configInput_19042_260`,configHint:`_configHint_19042_267`,configDelete:`_configDelete_19042_269`,palette:`_palette_19042_273`,paletteTitle:`_paletteTitle_19042_274`,paletteTabs:`_paletteTabs_19042_275`,paletteTab:`_paletteTab_19042_275`,paletteTabActive:`_paletteTabActive_19042_281`,paletteNodes:`_paletteNodes_19042_282`,paletteDef:`_paletteDef_19042_284`,paletteDefIcon:`_paletteDefIcon_19042_292`,paletteDefLabel:`_paletteDefLabel_19042_293`,paletteDefDesc:`_paletteDefDesc_19042_294`,paletteFooter:`_paletteFooter_19042_296`,paletteGuide:`_paletteGuide_19042_300`,guideTitle:`_guideTitle_19042_308`,guideStep:`_guideStep_19042_317`,guideNum:`_guideNum_19042_325`,guideTip:`_guideTip_19042_341`,guideCode:`_guideCode_19042_352`},jt=[{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.`,configFields:[{key:`path`,label:`Path`,placeholder:`/hook/my-trigger`}]},{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}}`}]}],Mt=Object.fromEntries(jt.map(e=>[e.id,e])),Nt=90,Pt=72;function Ft(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function It(e,t){return{x:e.x+(t===`out`?Nt:0),y:e.y+Pt/2}}function Lt(){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=(0,_.useRef)(null),v=(0,_.useRef)(null),y=(0,_.useRef)(null),b=(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)(()=>{b()},[b]);let x=(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)},[]),S=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:jt},n=(await D(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},C=async e=>{confirm(`Delete this workflow?`)&&(await D(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),b())},w=(0,_.useCallback)(e=>{e.preventDefault();let t=v.current;if(!t||!n)return;let r=y.current.getBoundingClientRect(),i=Math.round((e.clientX-r.left-Nt/2)/20)*20,o=Math.round((e.clientY-r.top-Pt/2)/20)*20,s={id:Ft(),defId:t,x:Math.max(0,i),y:Math.max(0,o),config:{}};x({...n,nodes:[...n.nodes,s]}),a(s.id),v.current=null},[n,x]),ee=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||x({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(g.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,x]),te=(0,_.useCallback)(e=>{if(!g.current||!n)return;let{id:t,ox:i,oy:a}=g.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]),ne=(0,_.useCallback)(()=>{if(!g.current||!n){g.current=null;return}n.nodes.find(e=>e.id===g.current.id)&&x(n),g.current=null},[n,x]),T=(0,_.useCallback)(e=>{n&&(x({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,x]),re=(0,_.useCallback)((e,t)=>{n&&x({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,x]),ie=(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]),O=(0,_.useCallback)(()=>{n&&x(n)},[n,x]),ae=async()=>{if(!(!n||c)){l(!0),p(!0),d([]);try{let e={...n,nodeDefs:jt};await D(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null),d((await D(`/api/workflows/${n.id}/run`,{}))?.steps??[]),b()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},A=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)},j=n?.nodes.find(e=>e.id===i)??null,oe=j?Mt[j.defId]:null;return(0,k.jsxs)(`div`,{className:W.root,children:[(0,k.jsxs)(`div`,{className:W.topbar,children:[(0,k.jsxs)(`div`,{className:W.topbarLeft,children:[(0,k.jsx)(`span`,{className:W.topbarTitle,children:`Connectors`}),(0,k.jsx)(`span`,{className:W.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:W.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${W.runBtn} ${c?W.runBtnActive:``}`,onClick:ae,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:W.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})]}),(0,k.jsxs)(`div`,{className:W.body,children:[(0,k.jsxs)(`div`,{className:W.sidebar,children:[(0,k.jsx)(`div`,{className:W.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:W.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${W.wfItem} ${n?.id===e.id?W.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:W.wfItemRow,children:[(0,k.jsx)(`span`,{className:W.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?W.wfOn:W.wfOff,onClick:t=>{t.stopPropagation(),A(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:W.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,k.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,k.jsx)(`button`,{className:W.wfDelBtn,onClick:t=>{t.stopPropagation(),C(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:W.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:W.canvasHeader,children:[(0,k.jsx)(`input`,{className:W.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&x(n)}),o?(0,k.jsxs)(`span`,{className:W.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:W.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:W.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:y,className:`${W.canvas} ${o?W.canvasConnecting:``}`,onMouseMove:te,onMouseUp:ne,onMouseLeave:ne,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>{o||a(null)},children:[(0,k.jsx)(`svg`,{className:W.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=It(r,`out`),o=It(i,`in`),s=(a.x+o.x)/2;return(0,k.jsxs)(`g`,{children:[(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`var(--green3)`,strokeWidth:`2`,fill:`none`,strokeDasharray:`6,3`,opacity:`0.8`}),(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`transparent`,strokeWidth:`12`,fill:`none`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`circle`,{cx:s,cy:(a.y+o.y)/2,r:`7`,fill:`var(--bg2)`,stroke:`var(--border)`,strokeWidth:`1.5`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`text`,{x:s,y:(a.y+o.y)/2+4,textAnchor:`middle`,fill:`var(--dim)`,fontSize:`9`,style:{cursor:`pointer`,pointerEvents:`none`},children:`✕`})]},t)})}),n.nodes.map(e=>{let t=Mt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,k.jsxs)(`div`,{className:`${W.canvasNode} ${n?W.canvasNodeSelected:``} ${r?W.canvasNodeConnecting:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>ee(t,e.id),onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(`button`,{className:W.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),T(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:W.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:W.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,k.jsx)(`span`,{className:W.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${W.portOut} ${r?W.portActive:``}`,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),s(t=>t===e.id?null:e.id)},title:`Connect from here`,children:`▶`}),o&&o!==e.id&&(0,k.jsx)(`button`,{className:W.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),ee(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,k.jsx)(`div`,{className:W.canvasDrop,children:`Drag nodes from the right panel and drop here`})]}),f&&(0,k.jsxs)(`div`,{className:W.logPanel,children:[(0,k.jsxs)(`div`,{className:W.logHeader,children:[(0,k.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,k.jsx)(`span`,{className:W.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,k.jsx)(`button`,{className:W.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,k.jsx)(`div`,{className:W.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,k.jsxs)(`div`,{className:`${W.logStep} ${e.error?W.logStepError:``}`,children:[(0,k.jsxs)(`div`,{className:W.logStepHeader,children:[(0,k.jsx)(`span`,{className:W.logStepIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:W.logStepLabel,children:e.nodeLabel}),e.error&&(0,k.jsx)(`span`,{className:W.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,k.jsx)(`div`,{className:W.logStepErr,children:e.error}),e.output&&(0,k.jsx)(`div`,{className:W.logStepOutput,dangerouslySetInnerHTML:{__html:ye(e.output.slice(0,500))}})]},t))]})]}):(0,k.jsxs)(`div`,{className:W.canvasEmpty,children:[(0,k.jsx)(`div`,{className:W.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:W.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:W.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,k.jsx)(`br`,{}),`Connect them by clicking the `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` output port then the target node.`,(0,k.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:W.rightPanel,children:j&&oe?(0,k.jsxs)(`div`,{className:W.configPanel,children:[(0,k.jsxs)(`div`,{className:W.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:oe.color},children:[oe.icon,` `,oe.label]}),(0,k.jsx)(`button`,{className:W.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:W.configDesc,children:oe.description}),(0,k.jsx)(`div`,{className:W.configFields,children:(oe.configFields??[]).map(e=>(0,k.jsxs)(`div`,{className:W.configField,children:[(0,k.jsxs)(`label`,{className:W.configLabel,children:[e.label,e.required&&(0,k.jsx)(`span`,{className:W.configRequired,children:`*`})]}),(0,k.jsx)(`input`,{className:W.configInput,value:j.config[e.key]??``,placeholder:e.placeholder??``,onChange:t=>ie(j.id,e.key,t.target.value),onBlur:O}),(e.placeholder?.includes(`{{`)??!1)&&(0,k.jsxs)(`div`,{className:W.configHint,children:[`Use `,(0,k.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},e.key))}),(0,k.jsx)(`button`,{className:W.configDelete,onClick:()=>T(j.id),children:`Delete node`})]}):(0,k.jsxs)(`div`,{className:W.palette,children:[(0,k.jsx)(`div`,{className:W.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:W.paletteTabs,children:[{id:`trigger`,label:`Triggers`,color:`#fbbf24`},{id:`action`,label:`Actions`,color:`#38bdf8`},{id:`ai`,label:`AI`,color:`#a5b4fc`}].map(e=>(0,k.jsx)(`button`,{className:`${W.paletteTab} ${m===e.id?W.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,k.jsx)(`div`,{className:W.paletteNodes,children:jt.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:W.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{v.current=e.id},onDragEnd:()=>{v.current=null},children:[(0,k.jsx)(`span`,{className:W.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:W.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:W.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:W.paletteGuide,children:[(0,k.jsx)(`div`,{className:W.guideTitle,children:`How to use Connectors`}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`2`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`3`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`4`}),(0,k.jsxs)(`span`,{children:[`Click the `,(0,k.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,k.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`5`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`6`}),(0,k.jsxs)(`span`,{children:[`Press `,(0,k.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,k.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`Tip:`}),` Click an edge to delete it. Drag nodes on the canvas to reposition. All 80 NHA tools are pre-authenticated — no extra setup.`]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]})]})}var G={root:`_root_1ssbe_1`,sidebar:`_sidebar_1ssbe_12`,sidebarSection:`_sidebarSection_1ssbe_23`,sidebarLabel:`_sidebarLabel_1ssbe_28`,accountSelect:`_accountSelect_1ssbe_36`,sidebarCompose:`_sidebarCompose_1ssbe_46`,composeBtn:`_composeBtn_1ssbe_51`,folderList:`_folderList_1ssbe_63`,folderItem:`_folderItem_1ssbe_69`,folderActive:`_folderActive_1ssbe_82`,badge:`_badge_1ssbe_88`,labelHeader:`_labelHeader_1ssbe_103`,addLabelBtn:`_addLabelBtn_1ssbe_114`,newLabelRow:`_newLabelRow_1ssbe_123`,newLabelInput:`_newLabelInput_1ssbe_129`,newLabelSave:`_newLabelSave_1ssbe_139`,labelDot:`_labelDot_1ssbe_150`,syncArea:`_syncArea_1ssbe_158`,syncBtn:`_syncBtn_1ssbe_163`,messageList:`_messageList_1ssbe_175`,listHeader:`_listHeader_1ssbe_185`,searchInput:`_searchInput_1ssbe_194`,searchBtn:`_searchBtn_1ssbe_204`,listBody:`_listBody_1ssbe_214`,listLoading:`_listLoading_1ssbe_219`,noMessages:`_noMessages_1ssbe_224`,msgRow:`_msgRow_1ssbe_231`,msgUnread:`_msgUnread_1ssbe_242`,msgActive:`_msgActive_1ssbe_247`,msgTop:`_msgTop_1ssbe_251`,msgFrom:`_msgFrom_1ssbe_257`,msgDate:`_msgDate_1ssbe_270`,msgSubject:`_msgSubject_1ssbe_277`,msgPreview:`_msgPreview_1ssbe_289`,listFooter:`_listFooter_1ssbe_300`,loadMoreBtn:`_loadMoreBtn_1ssbe_311`,pane:`_pane_1ssbe_322`,emptyPane:`_emptyPane_1ssbe_330`,readingPane:`_readingPane_1ssbe_337`,paneToolbar:`_paneToolbar_1ssbe_344`,paneActions:`_paneActions_1ssbe_354`,replyBtn:`_replyBtn_1ssbe_360`,fwdBtn:`_fwdBtn_1ssbe_371`,trashBtn:`_trashBtn_1ssbe_371`,starBtn:`_starBtn_1ssbe_371`,aiBtn:`_aiBtn_1ssbe_384`,labelSelect:`_labelSelect_1ssbe_394`,paneHeader:`_paneHeader_1ssbe_403`,paneSubject:`_paneSubject_1ssbe_409`,paneMeta:`_paneMeta_1ssbe_416`,attachments:`_attachments_1ssbe_424`,attachLink:`_attachLink_1ssbe_431`,paneBody:`_paneBody_1ssbe_441`,bodyFrame:`_bodyFrame_1ssbe_447`,bodyText:`_bodyText_1ssbe_455`,composePane:`_composePane_1ssbe_465`,composeTitle:`_composeTitle_1ssbe_474`,composeField:`_composeField_1ssbe_483`,templateRow:`_templateRow_1ssbe_495`,templateToggle:`_templateToggle_1ssbe_500`,templateDrop:`_templateDrop_1ssbe_510`,templateItem:`_templateItem_1ssbe_524`,templateSubject:`_templateSubject_1ssbe_534`,composeBody:`_composeBody_1ssbe_540`,composeActions:`_composeActions_1ssbe_556`,sendBtn:`_sendBtn_1ssbe_563`,cancelBtn:`_cancelBtn_1ssbe_574`,compStatus:`_compStatus_1ssbe_584`,ok:`_ok_1ssbe_585`,err:`_err_1ssbe_586`},Rt=[{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:`🗑`}],zt=[{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 Bt(e){return e?e.slice(0,10):``}function Vt(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 Ht(){let e=N(),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,re]=(0,_.useState)(!1),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[j,oe]=(0,_.useState)(0),[se,ce]=(0,_.useState)(!1),[le,M]=(0,_.useState)({}),[P,F]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(``),[me,he]=(0,_.useState)(``),[ge,_e]=(0,_.useState)(``),[ve,ye]=(0,_.useState)(!1),[I,be]=(0,_.useState)(``),[xe,Se]=(0,_.useState)(!1),Ce=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle)),E(`/api/imap/accounts`).then(e=>{let t=e?.accounts??[];a(t);let n=localStorage.getItem(`nha-email-account-type`),r=localStorage.getItem(`nha-email-account-id`);n===`google`?L(`google`,`google`):n===`imap`&&r&&t.some(e=>e.id===r)?L(r,`imap`):t.length>0?L(t[0].id,`imap`):L(`google`,`google`)})},[]);let L=(e,t)=>{s(e),l(t),p(t===`google`?`INBOX`:null),localStorage.setItem(`nha-email-account-type`,t),localStorage.setItem(`nha-email-account-id`,e),h([]),b(0),S(null),w(null),t===`imap`?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),we(e,r,0,``)}):(d([]),Te(`INBOX`,``))},we=(e,t,n,r)=>{te(!0);let i=`/api/imap/messages?accountId=${encodeURIComponent(e)}&limit=50&offset=${n}`;t&&(i+=`&labelId=${encodeURIComponent(t)}`),r&&(i+=`&search=${encodeURIComponent(r)}`),E(i).then(e=>{h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),te(!1)}).catch(()=>te(!1))},Te=(e,t)=>{te(!0);let n=e===`INBOX`||!e?`all`:e.toLowerCase(),r=`/api/emails?filter=${encodeURIComponent(t||n)}&page=0&pageSize=50`;t&&(r=`/api/emails?filter=${encodeURIComponent(t)}&page=0&pageSize=50`),E(r).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);let n=t.filter(e=>!e.is_read).length;oe(n),te(!1)}).catch(()=>te(!1))},Ee=()=>{O(ae),b(0),h([]),c===`imap`&&o?we(o,f,0,ae):Te(f??`INBOX`,ae)},R=e=>{S(e),ce(!1),re(!0),c===`google`?E(`/api/imap/message?messageId=${encodeURIComponent(e)}&accountId=google`).then(t=>{if(t?.message){w({...t.message,id:e,_google:!0}),re(!1);return}D(`/api/email/read`,{messageId:e}).then(t=>{if(t?.message){let n=t.message;w({...n,body_text:n.body||n.body_text,body_html:n.body_html,from_address:n.from||n.from_address,from_name:n.from_name,id:e,_google:!0}),re(!1),D(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}else re(!1)}).catch(()=>re(!1))}).catch(()=>{re(!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)),re(!1)}).catch(()=>re(!1))},z=(e={})=>{ce(!0),M(e),F(e.to??``),de(``),pe(e.subject??``),he(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),_e(``),ye(!1),S(null),w(null)},De=async()=>{if(!P.trim()){_e(`Recipient required`);return}_e(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:P.trim(),cc:ue.trim()||void 0,subject:fe.trim(),bodyHtml:me.replace(/\n/g,`<br>`),bodyText:me,inReplyTo:le.inReplyTo||void 0});e?.ok?(_e(`Sent!`),setTimeout(()=>ce(!1),800)):_e(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:P.trim(),subject:fe.trim(),body:me});e?.ok||e?.id?(_e(`Sent!`),setTimeout(()=>ce(!1),800)):_e(e?.error??`Error`)}}catch(e){_e(e.message??`Error`)}},Oe=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})})},Ae=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},je=()=>{!I.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:I.trim()}).then(()=>{Se(!1),be(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})};return(0,k.jsxs)(`div`,{className:G.root,children:[(0,k.jsxs)(`div`,{className:G.sidebar,children:[(0,k.jsxs)(`div`,{className:G.sidebarSection,children:[(0,k.jsx)(`div`,{className:G.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:G.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?L(`google`,`google`):t.startsWith(`imap:`)&&L(t.slice(5),`imap`)},children:[n&&(0,k.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,k.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,k.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,k.jsx)(`div`,{className:G.sidebarCompose,children:(0,k.jsx)(`button`,{className:G.composeBtn,onClick:()=>z(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:G.folderList,children:c===`google`?Rt.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Te(e.id,ie)},children:[(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&j>0&&(0,k.jsx)(`span`,{className:G.badge,children:j})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:G.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:G.addLabelBtn,onClick:()=>Se(e=>!e),children:`+`})]}),xe&&(0,k.jsxs)(`div`,{className:G.newLabelRow,children:[(0,k.jsx)(`input`,{className:G.newLabelInput,value:I,onChange:e=>be(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&je()}),(0,k.jsx)(`button`,{className:G.newLabelSave,onClick:je,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&we(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:G.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.unread_count?(0,k.jsx)(`span`,{className:G.badge,children:e.unread_count}):null]},e.id))]})}),c===`imap`&&o&&(0,k.jsx)(`div`,{className:G.syncArea,children:(0,k.jsx)(`button`,{className:G.syncBtn,onClick:()=>{o&&c===`imap`&&D(`/api/imap/sync/${o}`,{})},children:`Sync now`})}),c===`google`&&(0,k.jsx)(`div`,{className:G.syncArea,children:(0,k.jsx)(`button`,{className:G.syncBtn,onClick:()=>{h([]),Te(f||`INBOX`,ie)},children:`Refresh`})})]}),(0,k.jsxs)(`div`,{className:G.messageList,children:[(0,k.jsxs)(`div`,{className:G.listHeader,children:[(0,k.jsx)(`input`,{className:G.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&Ee()}),(0,k.jsx)(`button`,{className:G.searchBtn,onClick:Ee,children:`Go`})]}),(0,k.jsxs)(`div`,{className:G.listBody,children:[ee&&(0,k.jsx)(`div`,{className:G.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:G.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${G.msgRow} ${e.id===x?G.msgActive:``} ${e.is_read?``:G.msgUnread}`,onClick:()=>R(e.id),children:[(0,k.jsxs)(`div`,{className:G.msgTop,children:[(0,k.jsx)(`span`,{className:G.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:G.msgDate,children:Bt(e.internal_date)})]}),(0,k.jsx)(`div`,{className:G.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:G.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:G.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),m.length<g&&c===`imap`&&(0,k.jsx)(`button`,{className:G.loadMoreBtn,onClick:()=>{let e=y+50;b(e),o&&we(o,f,e,ie)},children:`Load more`})]})]}),(0,k.jsx)(`div`,{className:G.pane,children:(()=>{if(se)return(0,k.jsxs)(`div`,{className:G.composePane,children:[(0,k.jsx)(`div`,{className:G.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:G.composeField,value:P,onChange:e=>F(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:G.composeField,value:ue,onChange:e=>de(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:G.composeField,value:fe,onChange:e=>pe(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:G.templateRow,children:[(0,k.jsx)(`button`,{className:G.templateToggle,onClick:()=>ye(e=>!e),children:`📄 Templates`}),ve&&(0,k.jsx)(`div`,{className:G.templateDrop,children:zt.map((e,t)=>(0,k.jsxs)(`div`,{className:G.templateItem,onClick:()=>{pe(t=>t||e.subject),ye(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:G.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:G.composeBody,value:me,onChange:e=>he(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:G.composeActions,children:[(0,k.jsx)(`button`,{className:G.sendBtn,onClick:De,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:G.cancelBtn,onClick:()=>ce(!1),children:`Discard`}),ge&&(0,k.jsx)(`span`,{className:`${G.compStatus} ${ge===`Sent!`?G.ok:G.err}`,children:ge})]})]});if(T)return(0,k.jsx)(`div`,{className:G.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:G.emptyPane,children:`Select a message`});let n=Vt(C.to_addresses);return(0,k.jsxs)(`div`,{className:G.readingPane,children:[(0,k.jsx)(`div`,{className:G.paneToolbar,children:(0,k.jsxs)(`div`,{className:G.paneActions,children:[(0,k.jsx)(`button`,{className:G.replyBtn,onClick:()=>z({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,k.jsx)(`button`,{className:G.fwdBtn,onClick:()=>z({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:G.trashBtn,onClick:()=>Oe(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:G.starBtn,onClick:()=>ke(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:G.labelSelect,defaultValue:``,onChange:e=>Ae(C.id,e.target.value),children:[(0,k.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsx)(`button`,{className:G.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:G.paneHeader,children:[(0,k.jsx)(`div`,{className:G.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:G.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:G.attachLink,href:`/api/imap/attachment?messageId=${encodeURIComponent(C.id)}&partId=${encodeURIComponent(e.part_id??``)}&accountId=${encodeURIComponent(o??``)}`,download:e.filename??`attachment`,children:[`📎 `,e.filename??`attachment`,` (`,Math.round((e.size_bytes??0)/1024),`KB)`]},t))})]}),(0,k.jsx)(`div`,{className:G.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:Ce,sandbox:`allow-same-origin`,className:G.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,k.jsx)(`pre`,{className:G.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var K={root:`_root_1u06k_1`,center:`_center_1u06k_10`,noGoogle:`_noGoogle_1u06k_17`,noGoogleIcon:`_noGoogleIcon_1u06k_26`,noGoogleTitle:`_noGoogleTitle_1u06k_27`,noGoogleSub:`_noGoogleSub_1u06k_28`,connectBtn:`_connectBtn_1u06k_30`,calCol:`_calCol_1u06k_42`,navRow:`_navRow_1u06k_50`,navBtn:`_navBtn_1u06k_57`,monthTitle:`_monthTitle_1u06k_70`,dayHeaders:`_dayHeaders_1u06k_78`,dayHeader:`_dayHeader_1u06k_78`,weekend:`_weekend_1u06k_92`,grid:`_grid_1u06k_94`,cell:`_cell_1u06k_103`,emptyCell:`_emptyCell_1u06k_119`,weekendCell:`_weekendCell_1u06k_121`,todayCell:`_todayCell_1u06k_122`,activeCell:`_activeCell_1u06k_123`,hasEvtsCell:`_hasEvtsCell_1u06k_124`,holidayCell:`_holidayCell_1u06k_125`,dayNum:`_dayNum_1u06k_127`,todayNum:`_todayNum_1u06k_133`,weekendNum:`_weekendNum_1u06k_134`,evtPills:`_evtPills_1u06k_136`,evtPill:`_evtPill_1u06k_136`,holidayPill:`_holidayPill_1u06k_156`,morePill:`_morePill_1u06k_158`,loadingBar:`_loadingBar_1u06k_164`,detailCol:`_detailCol_1u06k_173`,detailHeader:`_detailHeader_1u06k_184`,detailDate:`_detailDate_1u06k_192`,addEvtBtn:`_addEvtBtn_1u06k_198`,noEvts:`_noEvts_1u06k_210`,selectDay:`_selectDay_1u06k_217`,evtCard:`_evtCard_1u06k_224`,evtTop:`_evtTop_1u06k_234`,evtTime:`_evtTime_1u06k_241`,evtBtns:`_evtBtns_1u06k_247`,editBtn:`_editBtn_1u06k_253`,delBtn:`_delBtn_1u06k_263`,readOnly:`_readOnly_1u06k_273`,evtTitle:`_evtTitle_1u06k_280`,evtLoc:`_evtLoc_1u06k_286`,evtMeta:`_evtMeta_1u06k_287`,attendees:`_attendees_1u06k_289`,attendee:`_attendee_1u06k_289`,evtDesc:`_evtDesc_1u06k_300`,joinBtn:`_joinBtn_1u06k_310`,gcalLink:`_gcalLink_1u06k_317`,overlay:`_overlay_1u06k_324`,formCard:`_formCard_1u06k_334`,formTitle:`_formTitle_1u06k_348`,formLabel:`_formLabel_1u06k_355`,formInput:`_formInput_1u06k_361`,formTextarea:`_formTextarea_1u06k_374`,formError:`_formError_1u06k_390`,formBtns:`_formBtns_1u06k_395`,cancelFormBtn:`_cancelFormBtn_1u06k_402`,saveFormBtn:`_saveFormBtn_1u06k_412`};function Ut(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function Wt(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function Gt(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 Kt(){let e=N(),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,k.jsx)(`div`,{className:K.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:K.center,children:(0,k.jsxs)(`div`,{className:K.noGoogle,children:[(0,k.jsx)(`div`,{className:K.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:K.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:K.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:K.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let re=new Date(a,s,1).getDay(),ie=new Date(a,s+1,0).getDate(),O=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ae=(re+6)%7,A=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],j=p?l[p]??[]:[];return(0,k.jsxs)(`div`,{className:K.root,children:[(0,k.jsxs)(`div`,{className:K.calCol,children:[(0,k.jsxs)(`div`,{className:K.navRow,children:[(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:K.monthTitle,children:O}),(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:K.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${K.dayHeader} ${t>=5?K.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:K.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.cell} ${K.emptyCell} ${t>=5?K.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=Ut(a,s,n),i=Wt(a,s,n),o=l[r]??[],c=o.length,u=(ae+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,k.jsxs)(`div`,{className:`${K.cell} ${i?K.todayCell:u?K.weekendCell:``} ${f?K.activeCell:``} ${d?K.holidayCell:c>0?K.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${K.dayNum} ${i?K.todayNum:u?K.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:K.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.evtPill} ${e._isHoliday||e.readOnly?K.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:K.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:K.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:K.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:K.detailHeader,children:[(0,k.jsx)(`div`,{className:K.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:K.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),j.length===0?(0,k.jsx)(`div`,{className:K.noEvts,children:`No events on this day`}):j.map((t,n)=>{let r=t.isAllDay?`All day`:`${Gt(t.start)} - ${Gt(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:K.evtCard,children:[(0,k.jsxs)(`div`,{className:K.evtTop,children:[(0,k.jsx)(`div`,{className:K.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:K.evtBtns,children:[(0,k.jsx)(`button`,{className:K.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:K.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:K.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:K.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:K.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:K.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:K.attendees,children:[(0,k.jsx)(`div`,{className:K.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:K.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:K.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:K.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:K.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsx)(`div`,{className:K.selectDay,children:`Select a day to see events`})}),h&&(0,k.jsx)(`div`,{className:K.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:K.formCard,children:[(0,k.jsx)(`div`,{className:K.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:K.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:K.formError,children:v}),(0,k.jsxs)(`div`,{className:K.formBtns,children:[(0,k.jsx)(`button`,{className:K.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:K.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var q={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`},qt={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 Jt(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=qt[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 Yt(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function Xt(){let e=N(),[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),re=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),ae=(0,_.useRef)(new Map),A=(0,_.useRef)(new Map),j=(0,_.useRef)(null),oe=()=>{E(`/api/agents`).then(e=>{n((e?.agents??[]).map(Jt)),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?(re.current.get(e.id)?.abort(),re.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,Yt(e)]})},M=e=>{re.current.get(e)?.abort(),re.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},P=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},F=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},ue=(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}}))},de=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;F(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),P(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);F(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{F(i,{role:`assistant`,content:`Error sending attachment.`})}P(i,{streaming:!1});return}F(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;re.current.set(i,o);let s=``;try{await ie(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,ue(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{P(i,{streaming:!1}),re.current.delete(i)}},fe=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;F(r,{role:`user`,content:e}),P(r,{streaming:!0});let i=``,a=new AbortController;re.current.set(r,a),F(r,{role:`assistant`,content:``,streaming:!0});try{await ie(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,ue(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{P(r,{streaming:!1}),re.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(`
573
573
 
574
574
  ---
575
575
 
@@ -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-CsqatWGe.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-B88PlySv.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-BRTO-LWg.css">
13
13
  </head>
14
14
  <body>