heyhank 0.2.0 → 0.3.0

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.
Files changed (37) hide show
  1. package/dist/assets/{AgentsPage-B-AAmsMK.js → AgentsPage-DqjDAcIw.js} +1 -1
  2. package/dist/assets/{AssistantPage-BV1Mfwdt.js → AssistantPage-C50CQFSB.js} +1 -1
  3. package/dist/assets/{BusinessPage-tLpNEz19.js → BusinessPage-AY70tf1k.js} +1 -1
  4. package/dist/assets/{CronManager-B-K_n3Jg.js → CronManager-Dt7LLuRr.js} +1 -1
  5. package/dist/assets/{HelpPage-Bhf_j6Xr.js → HelpPage-tlGx7fQF.js} +1 -1
  6. package/dist/assets/{IntegrationsPage-DAMjs9tM.js → IntegrationsPage-B4XOuHXu.js} +1 -1
  7. package/dist/assets/{JarvisHUD-C_TGXCCn.js → JarvisHUD-BDvuRd0I.js} +1 -1
  8. package/dist/assets/{MediaPage-C48HTTrt.js → MediaPage-CofV9Rd-.js} +1 -1
  9. package/dist/assets/{MemoryPage-JkC-qtgp.js → MemoryPage-Cj7FeqmJ.js} +1 -1
  10. package/dist/assets/{PlatformDashboard-AUo7tNnE.js → PlatformDashboard-B9kXAlH1.js} +1 -1
  11. package/dist/assets/{Playground-AzNMsRBL.js → Playground-Cka-pRkP.js} +1 -1
  12. package/dist/assets/{ProcessPanel-DpE_2sX3.js → ProcessPanel-BqhQgfYj.js} +1 -1
  13. package/dist/assets/{PromptsPage-C2RQOs6p.js → PromptsPage-VveKc9uX.js} +1 -1
  14. package/dist/assets/RunsPage-DXVEk0AZ.js +1 -0
  15. package/dist/assets/{SandboxManager-jHvYjwfh.js → SandboxManager-DACcwfDF.js} +1 -1
  16. package/dist/assets/{SettingsPage-BBJax6gt.js → SettingsPage-jfuQh8Tu.js} +1 -1
  17. package/dist/assets/{SkillsMarketplace-IjmjfdjD.js → SkillsMarketplace-DrigiApe.js} +1 -1
  18. package/dist/assets/{SocialMediaPage-DoPZHhr2.js → SocialMediaPage-DOh3IPe8.js} +1 -1
  19. package/dist/assets/{TailscalePage-DDEY7ckO.js → TailscalePage-DLhJWATT.js} +1 -1
  20. package/dist/assets/{TelephonyPage-OPNBZYKt.js → TelephonyPage-9C4C3_ot.js} +1 -1
  21. package/dist/assets/{TerminalPage-BjMbHHW3.js → TerminalPage-ChX-8Wu7.js} +1 -1
  22. package/dist/assets/index-C6Q5UQHD.js +229 -0
  23. package/dist/assets/index-ZxGXgiV3.css +32 -0
  24. package/dist/assets/sw-register-BBYuk-kw.js +1 -0
  25. package/dist/assets/workbox-window.prod.es5-BBnX5xw4.js +2 -0
  26. package/dist/index.html +2 -2
  27. package/dist/sw.js +1 -1
  28. package/dist/{workbox-d2a0910a.js → workbox-080c8b91.js} +1 -1
  29. package/package.json +1 -1
  30. package/server/agent-executor.ts +65 -0
  31. package/server/execution-store.ts +54 -1
  32. package/server/routes/agent-routes.ts +42 -0
  33. package/dist/assets/RunsPage-B9UOyO79.js +0 -1
  34. package/dist/assets/index-BgYM4wXw.js +0 -205
  35. package/dist/assets/index-BkjSoVgn.css +0 -32
  36. package/dist/assets/sw-register-C7NOHtIu.js +0 -1
  37. package/dist/assets/workbox-window.prod.es5-BIl4cyR9.js +0 -2
@@ -1,4 +1,4 @@
1
- import{r as l,j as e,J as be,E as ve,H as je,K as ye,b as E,F as we,u as Ne}from"./index-BgYM4wXw.js";import{t as pe}from"./time-ago-B6r_l9u1.js";const me="heyhank_public_url_dismissed";function ke({publicUrl:s}){const[o,x]=l.useState(()=>localStorage.getItem(me)==="1");return s||o?null:e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs flex items-start justify-between gap-3",role:"alert",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"No public URL configured."})," ","Webhook URLs currently use your browser address, which external services may not be able to reach."," ",e.jsx("a",{href:"#/settings",className:"underline hover:text-amber-300",children:"Set your public URL in Settings"}),"."]}),e.jsx("button",{onClick:()=>{localStorage.setItem(me,"1"),x(!0)},className:"text-amber-400 hover:text-amber-200 transition-colors cursor-pointer flex-shrink-0","aria-label":"Dismiss public URL banner",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})}const Ce=["bot","terminal","pencil","search","shield","chart","flask","rocket","wrench","clipboard","lightbulb","code","globe","zap","database","git-branch","mail","cpu"];function ae({icon:s,className:o="w-5 h-5"}){const n={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:`${o} shrink-0`,role:"img","aria-label":s||"bot"};switch(s){case"bot":return e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]});case"terminal":return e.jsxs("svg",{...n,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]});case"pencil":return e.jsx("svg",{...n,children:e.jsx("path",{d:"M17 3a2.83 2.83 0 114 4L7.5 20.5 2 22l1.5-5.5Z"})});case"search":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]});case"shield":return e.jsx("svg",{...n,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})});case"chart":return e.jsxs("svg",{...n,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]});case"flask":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M9 3h6V8l5 10a1 1 0 01-.9 1.4H4.9A1 1 0 014 18L9 8V3z"}),e.jsx("line",{x1:"9",y1:"3",x2:"15",y2:"3"})]});case"rocket":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 00-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 012-3.95A12.88 12.88 0 0122 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 01-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]});case"wrench":return e.jsx("svg",{...n,children:e.jsx("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"})});case"clipboard":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M16 4h2a2 2 0 012 2v14a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"})]});case"lightbulb":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M9 18h6"}),e.jsx("path",{d:"M10 22h4"}),e.jsx("path",{d:"M12 2a7 7 0 00-3 13.33V17h6v-1.67A7 7 0 0012 2z"})]});case"code":return e.jsxs("svg",{...n,children:[e.jsx("polyline",{points:"16 18 22 12 16 6"}),e.jsx("polyline",{points:"8 6 2 12 8 18"})]});case"globe":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),e.jsx("path",{d:"M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"})]});case"zap":return e.jsx("svg",{...n,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})});case"database":return e.jsxs("svg",{...n,children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"}),e.jsx("path",{d:"M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"})]});case"git-branch":return e.jsxs("svg",{...n,children:[e.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),e.jsx("circle",{cx:"18",cy:"6",r:"3"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("path",{d:"M18 9a9 9 0 01-9 9"})]});case"mail":return e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),e.jsx("polyline",{points:"22 7 12 13 2 7"})]});case"cpu":return e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("rect",{x:"9",y:"9",width:"6",height:"6"}),e.jsx("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),e.jsx("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),e.jsx("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),e.jsx("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),e.jsx("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),e.jsx("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),e.jsx("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),e.jsx("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]});default:return s?e.jsx("span",{className:o,children:s}):e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]})}}function Ae({agent:s,copiedWebhook:o,onEdit:x,onDelete:n,onToggle:h,onExport:S,onCopyWebhook:p,onRegenerateSecret:v}){var z,N;const[g,b]=l.useState(!1),a=l.useRef(null);l.useEffect(()=>{if(!g)return;function m(k){a.current&&!a.current.contains(k.target)&&b(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[g]),l.useEffect(()=>{if(!g)return;function m(k){k.key==="Escape"&&b(!1)}return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[g]);const f=(N=(z=s.triggers)==null?void 0:z.webhook)==null?void 0:N.enabled;function w(m){b(!1),m()}return e.jsxs("div",{className:"relative",ref:a,children:[e.jsx("button",{onClick:()=>b(!g),className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",title:"More actions","aria-label":"More actions","aria-expanded":g,"aria-haspopup":"true",children:e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[e.jsx("circle",{cx:"8",cy:"3",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"8",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"13",r:"1.5"})]})}),g&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-xl shadow-lg z-20 py-1 origin-top-right",style:{animation:"menu-appear 120ms ease-out"},role:"menu",children:[e.jsxs("button",{onClick:()=>w(x),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61z"})}),"Edit"]}),e.jsxs("button",{onClick:()=>w(S),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M3.5 13a.5.5 0 01-.5-.5V11h1v1h8v-1h1v1.5a.5.5 0 01-.5.5h-9zM8 2a.5.5 0 01.5.5v6.793l2.146-2.147a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 01.708-.708L7.5 9.293V2.5A.5.5 0 018 2z"})}),"Export JSON"]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(p),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M4.715 6.542L3.343 7.914a3 3 0 104.243 4.243l1.828-1.829A3 3 0 008.586 5.5L8 6.086a1 1 0 00-.154.199 2 2 0 01.861 3.337L6.88 11.45a2 2 0 11-2.83-2.83l.793-.792a4.018 4.018 0 01-.128-1.287z"}),e.jsx("path",{d:"M11.285 9.458l1.372-1.372a3 3 0 10-4.243-4.243L6.586 5.671A3 3 0 007.414 10.5l.586-.586a1 1 0 00.154-.199 2 2 0 01-.861-3.337L9.12 4.55a2 2 0 112.83 2.83l-.793.792c.112.42.155.855.128 1.287z"})]}),o===s.id?"Copied!":"Copy Webhook URL"]}),e.jsxs("button",{onClick:()=>w(v),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M11.534 7h3.932a.25.25 0 01.192.41l-1.966 2.36a.25.25 0 01-.384 0l-1.966-2.36a.25.25 0 01.192-.41zm-7 2H.602a.25.25 0 01-.192-.41l1.966-2.36a.25.25 0 01.384 0l1.966 2.36a.25.25 0 01-.192.41z"}),e.jsx("path",{d:"M8 3a5 5 0 014.546 2.914.5.5 0 00.908-.418A6 6 0 002 8c0 .088.002.176.006.264l-.058-.024a.5.5 0 00-.394.908l2 1a.5.5 0 00.668-.17L5.59 7.864a.5.5 0 00-.274-.846l-.09-.016A4 4 0 018 3zm.002 10a4 4 0 002.49-4.002l.09.016a.5.5 0 00.274.846l-1.367 2.114a.5.5 0 01-.668.17l-2-1a.5.5 0 01.394-.908l.058.024A5.972 5.972 0 008.002 13a5 5 0 01-4.546-2.914.5.5 0 00-.908.418A6 6 0 008.002 13z"})]}),"Regenerate Secret"]})]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(h),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:s.enabled?e.jsx("path",{d:"M5 3a5 5 0 000 10h6a5 5 0 000-10H5zm6 3a2 2 0 110 4 2 2 0 010-4z"}):e.jsx("path",{d:"M11 3a5 5 0 010 10H5A5 5 0 015 3h6zM5 6a2 2 0 100 4 2 2 0 000-4z"})}),s.enabled?"Disable":"Enable"]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(n),className:"w-full px-3 py-2 text-xs text-left text-cc-error hover:bg-cc-error/10 transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M5.5 5.5a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm-7-3A1.5 1.5 0 015 1h6a1.5 1.5 0 011.5 1.5H14a.5.5 0 010 1h-.554L12.2 14.118A1.5 1.5 0 0110.706 15H5.294a1.5 1.5 0 01-1.494-.882L2.554 3.5H2a.5.5 0 010-1h1.5z"})}),"Delete"]})]})]})}function Se(s,o){if(!o)return"One-time";const x=s.trim().split(/\s+/);if(x.length!==5)return s;const[n,h,,,S]=x;if(s==="* * * * *")return"Every minute";if(h==="*"&&n.startsWith("*/")){const p=parseInt(n.slice(2),10);return p===1?"Every minute":`Every ${p} minutes`}if(n==="0"&&h==="*")return"Every hour";if(n==="0"&&h.startsWith("*/")){const p=parseInt(h.slice(2),10);return p===1?"Every hour":`Every ${p} hours`}if(n!=="*"&&h!=="*"&&!h.includes("/")&&!h.includes(",")){const p=parseInt(h,10),v=parseInt(n,10);if(!isNaN(p)&&!isNaN(v)){const g=p>=12?"PM":"AM",b=p===0?12:p>12?p-12:p,a=v.toString().padStart(2,"0"),f=`${b}:${a} ${g}`;if(S==="*")return`Daily at ${f}`;if(S==="1-5")return`Weekdays at ${f}`}}return s}function Me(s,o){var n,h;return`${o||window.location.origin}/api/agents/${encodeURIComponent(s.id)}/webhook/${((h=(n=s.triggers)==null?void 0:n.webhook)==null?void 0:h.secret)||""}`}function Ee({agent:s,publicUrl:o,onEdit:x,onDelete:n,onToggle:h,onRun:S,onExport:p,onCopyWebhook:v,onRegenerateSecret:g,copiedWebhook:b}){var f,w,z,N;const a=["Manual"];return(w=(f=s.triggers)==null?void 0:f.webhook)!=null&&w.enabled&&a.push("Webhook"),(N=(z=s.triggers)==null?void 0:z.schedule)!=null&&N.enabled&&a.push(Se(s.triggers.schedule.expression,s.triggers.schedule.recurring)),e.jsxs("div",{className:`
1
+ import{r as l,j as e,J as be,E as ve,H as je,K as ye,b as E,F as we,u as Ne}from"./index-C6Q5UQHD.js";import{t as pe}from"./time-ago-B6r_l9u1.js";const me="heyhank_public_url_dismissed";function ke({publicUrl:s}){const[o,x]=l.useState(()=>localStorage.getItem(me)==="1");return s||o?null:e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs flex items-start justify-between gap-3",role:"alert",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"No public URL configured."})," ","Webhook URLs currently use your browser address, which external services may not be able to reach."," ",e.jsx("a",{href:"#/settings",className:"underline hover:text-amber-300",children:"Set your public URL in Settings"}),"."]}),e.jsx("button",{onClick:()=>{localStorage.setItem(me,"1"),x(!0)},className:"text-amber-400 hover:text-amber-200 transition-colors cursor-pointer flex-shrink-0","aria-label":"Dismiss public URL banner",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})}const Ce=["bot","terminal","pencil","search","shield","chart","flask","rocket","wrench","clipboard","lightbulb","code","globe","zap","database","git-branch","mail","cpu"];function ae({icon:s,className:o="w-5 h-5"}){const n={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:`${o} shrink-0`,role:"img","aria-label":s||"bot"};switch(s){case"bot":return e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]});case"terminal":return e.jsxs("svg",{...n,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]});case"pencil":return e.jsx("svg",{...n,children:e.jsx("path",{d:"M17 3a2.83 2.83 0 114 4L7.5 20.5 2 22l1.5-5.5Z"})});case"search":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]});case"shield":return e.jsx("svg",{...n,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})});case"chart":return e.jsxs("svg",{...n,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]});case"flask":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M9 3h6V8l5 10a1 1 0 01-.9 1.4H4.9A1 1 0 014 18L9 8V3z"}),e.jsx("line",{x1:"9",y1:"3",x2:"15",y2:"3"})]});case"rocket":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 00-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 012-3.95A12.88 12.88 0 0122 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 01-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]});case"wrench":return e.jsx("svg",{...n,children:e.jsx("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"})});case"clipboard":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M16 4h2a2 2 0 012 2v14a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"})]});case"lightbulb":return e.jsxs("svg",{...n,children:[e.jsx("path",{d:"M9 18h6"}),e.jsx("path",{d:"M10 22h4"}),e.jsx("path",{d:"M12 2a7 7 0 00-3 13.33V17h6v-1.67A7 7 0 0012 2z"})]});case"code":return e.jsxs("svg",{...n,children:[e.jsx("polyline",{points:"16 18 22 12 16 6"}),e.jsx("polyline",{points:"8 6 2 12 8 18"})]});case"globe":return e.jsxs("svg",{...n,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),e.jsx("path",{d:"M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"})]});case"zap":return e.jsx("svg",{...n,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})});case"database":return e.jsxs("svg",{...n,children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"}),e.jsx("path",{d:"M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"})]});case"git-branch":return e.jsxs("svg",{...n,children:[e.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),e.jsx("circle",{cx:"18",cy:"6",r:"3"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("path",{d:"M18 9a9 9 0 01-9 9"})]});case"mail":return e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),e.jsx("polyline",{points:"22 7 12 13 2 7"})]});case"cpu":return e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("rect",{x:"9",y:"9",width:"6",height:"6"}),e.jsx("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),e.jsx("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),e.jsx("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),e.jsx("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),e.jsx("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),e.jsx("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),e.jsx("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),e.jsx("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]});default:return s?e.jsx("span",{className:o,children:s}):e.jsxs("svg",{...n,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]})}}function Ae({agent:s,copiedWebhook:o,onEdit:x,onDelete:n,onToggle:h,onExport:S,onCopyWebhook:p,onRegenerateSecret:v}){var z,N;const[g,b]=l.useState(!1),a=l.useRef(null);l.useEffect(()=>{if(!g)return;function m(k){a.current&&!a.current.contains(k.target)&&b(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[g]),l.useEffect(()=>{if(!g)return;function m(k){k.key==="Escape"&&b(!1)}return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[g]);const f=(N=(z=s.triggers)==null?void 0:z.webhook)==null?void 0:N.enabled;function w(m){b(!1),m()}return e.jsxs("div",{className:"relative",ref:a,children:[e.jsx("button",{onClick:()=>b(!g),className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",title:"More actions","aria-label":"More actions","aria-expanded":g,"aria-haspopup":"true",children:e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[e.jsx("circle",{cx:"8",cy:"3",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"8",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"13",r:"1.5"})]})}),g&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-xl shadow-lg z-20 py-1 origin-top-right",style:{animation:"menu-appear 120ms ease-out"},role:"menu",children:[e.jsxs("button",{onClick:()=>w(x),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61z"})}),"Edit"]}),e.jsxs("button",{onClick:()=>w(S),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M3.5 13a.5.5 0 01-.5-.5V11h1v1h8v-1h1v1.5a.5.5 0 01-.5.5h-9zM8 2a.5.5 0 01.5.5v6.793l2.146-2.147a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 01.708-.708L7.5 9.293V2.5A.5.5 0 018 2z"})}),"Export JSON"]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(p),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M4.715 6.542L3.343 7.914a3 3 0 104.243 4.243l1.828-1.829A3 3 0 008.586 5.5L8 6.086a1 1 0 00-.154.199 2 2 0 01.861 3.337L6.88 11.45a2 2 0 11-2.83-2.83l.793-.792a4.018 4.018 0 01-.128-1.287z"}),e.jsx("path",{d:"M11.285 9.458l1.372-1.372a3 3 0 10-4.243-4.243L6.586 5.671A3 3 0 007.414 10.5l.586-.586a1 1 0 00.154-.199 2 2 0 01-.861-3.337L9.12 4.55a2 2 0 112.83 2.83l-.793.792c.112.42.155.855.128 1.287z"})]}),o===s.id?"Copied!":"Copy Webhook URL"]}),e.jsxs("button",{onClick:()=>w(v),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M11.534 7h3.932a.25.25 0 01.192.41l-1.966 2.36a.25.25 0 01-.384 0l-1.966-2.36a.25.25 0 01.192-.41zm-7 2H.602a.25.25 0 01-.192-.41l1.966-2.36a.25.25 0 01.384 0l1.966 2.36a.25.25 0 01-.192.41z"}),e.jsx("path",{d:"M8 3a5 5 0 014.546 2.914.5.5 0 00.908-.418A6 6 0 002 8c0 .088.002.176.006.264l-.058-.024a.5.5 0 00-.394.908l2 1a.5.5 0 00.668-.17L5.59 7.864a.5.5 0 00-.274-.846l-.09-.016A4 4 0 018 3zm.002 10a4 4 0 002.49-4.002l.09.016a.5.5 0 00.274.846l-1.367 2.114a.5.5 0 01-.668.17l-2-1a.5.5 0 01.394-.908l.058.024A5.972 5.972 0 008.002 13a5 5 0 01-4.546-2.914.5.5 0 00-.908.418A6 6 0 008.002 13z"})]}),"Regenerate Secret"]})]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(h),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:s.enabled?e.jsx("path",{d:"M5 3a5 5 0 000 10h6a5 5 0 000-10H5zm6 3a2 2 0 110 4 2 2 0 010-4z"}):e.jsx("path",{d:"M11 3a5 5 0 010 10H5A5 5 0 015 3h6zM5 6a2 2 0 100 4 2 2 0 000-4z"})}),s.enabled?"Disable":"Enable"]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(n),className:"w-full px-3 py-2 text-xs text-left text-cc-error hover:bg-cc-error/10 transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M5.5 5.5a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm-7-3A1.5 1.5 0 015 1h6a1.5 1.5 0 011.5 1.5H14a.5.5 0 010 1h-.554L12.2 14.118A1.5 1.5 0 0110.706 15H5.294a1.5 1.5 0 01-1.494-.882L2.554 3.5H2a.5.5 0 010-1h1.5z"})}),"Delete"]})]})]})}function Se(s,o){if(!o)return"One-time";const x=s.trim().split(/\s+/);if(x.length!==5)return s;const[n,h,,,S]=x;if(s==="* * * * *")return"Every minute";if(h==="*"&&n.startsWith("*/")){const p=parseInt(n.slice(2),10);return p===1?"Every minute":`Every ${p} minutes`}if(n==="0"&&h==="*")return"Every hour";if(n==="0"&&h.startsWith("*/")){const p=parseInt(h.slice(2),10);return p===1?"Every hour":`Every ${p} hours`}if(n!=="*"&&h!=="*"&&!h.includes("/")&&!h.includes(",")){const p=parseInt(h,10),v=parseInt(n,10);if(!isNaN(p)&&!isNaN(v)){const g=p>=12?"PM":"AM",b=p===0?12:p>12?p-12:p,a=v.toString().padStart(2,"0"),f=`${b}:${a} ${g}`;if(S==="*")return`Daily at ${f}`;if(S==="1-5")return`Weekdays at ${f}`}}return s}function Me(s,o){var n,h;return`${o||window.location.origin}/api/agents/${encodeURIComponent(s.id)}/webhook/${((h=(n=s.triggers)==null?void 0:n.webhook)==null?void 0:h.secret)||""}`}function Ee({agent:s,publicUrl:o,onEdit:x,onDelete:n,onToggle:h,onRun:S,onExport:p,onCopyWebhook:v,onRegenerateSecret:g,copiedWebhook:b}){var f,w,z,N;const a=["Manual"];return(w=(f=s.triggers)==null?void 0:f.webhook)!=null&&w.enabled&&a.push("Webhook"),(N=(z=s.triggers)==null?void 0:z.schedule)!=null&&N.enabled&&a.push(Se(s.triggers.schedule.expression,s.triggers.schedule.recurring)),e.jsxs("div",{className:`
2
2
  group relative rounded-xl border bg-cc-card p-4
3
3
  transition-all duration-150
4
4
  ${s.enabled?"border-cc-border hover:border-cc-primary/30 hover:shadow-[0_2px_12px_rgba(217,119,87,0.06)]":"border-cc-border/60 opacity-75 hover:opacity-100"}
@@ -1,2 +1,2 @@
1
- import{r as t,j as e,b as M,d as Q,t as X,c as Y,e as W}from"./index-BgYM4wXw.js";const ve={high:"text-red-400 bg-red-500/10 border-red-500/20",medium:"text-yellow-400 bg-yellow-500/10 border-yellow-500/20",low:"text-green-400 bg-green-500/10 border-green-500/20"};function K(x){const m=Date.now()-new Date(x).getTime(),o=Math.floor(m/6e4);if(o<1)return"just now";if(o<60)return`${o}m ago`;const k=Math.floor(o/60);if(k<24)return`${k}h ago`;const p=Math.floor(k/24);return p<7?`${p}d ago`:new Date(x).toLocaleDateString()}function ue(x){return new Date(x).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function De(){const[x,m]=t.useState("todos"),[o,k]=t.useState(0);function p(){k(n=>n+1)}const A=[{id:"todos",label:"Todos"},{id:"notes",label:"Notes"},{id:"reminders",label:"Reminders"},{id:"email",label:"Email"},{id:"contacts",label:"Contacts"},{id:"decisions",label:"Decisions"},{id:"documents",label:"Documents"},{id:"templates",label:"Templates"},{id:"time",label:"Time"},{id:"news",label:"News"}];return e.jsxs("div",{className:"h-full flex flex-col bg-cc-bg overflow-hidden",children:[e.jsx("div",{className:"shrink-0 border-b border-cc-border",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Assistant"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Personal todos, notes & reminders — managed by Gemini Live"})]})}),e.jsx("div",{className:"flex gap-1 mt-3",children:A.map(n=>e.jsx("button",{type:"button",onClick:()=>m(n.id),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors cursor-pointer ${x===n.id?"bg-cc-accent text-white":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:n.label},n.id))})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-6 pb-safe",children:[x==="todos"&&e.jsx(je,{refreshKey:o,onRefresh:p}),x==="notes"&&e.jsx(ye,{refreshKey:o,onRefresh:p}),x==="reminders"&&e.jsx(Ne,{refreshKey:o,onRefresh:p}),x==="email"&&e.jsx(we,{refreshKey:o,onRefresh:p}),x==="contacts"&&e.jsx(Se,{refreshKey:o,onRefresh:p}),x==="decisions"&&e.jsx(Ce,{refreshKey:o,onRefresh:p}),x==="documents"&&e.jsx(ke,{refreshKey:o,onRefresh:p}),x==="templates"&&e.jsx(Te,{refreshKey:o,onRefresh:p}),x==="time"&&e.jsx(Ae,{refreshKey:o,onRefresh:p}),x==="news"&&e.jsx(Ee,{refreshKey:o,onRefresh:p})]})})]})}function je({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState("all"),[u,$]=t.useState(""),[T,j]=t.useState("medium"),[l,b]=t.useState(""),[f,R]=t.useState(!1),[w,y]=t.useState(null),[g,S]=t.useState(""),[C,P]=t.useState(""),v=t.useCallback(async()=>{A(!0);try{const a={};n==="active"&&(a.done=!1),n==="done"&&(a.done=!0);const c=await M.listTodos(a);k(c.todos)}catch{}A(!1)},[n]);t.useEffect(()=>{v()},[v,x]);async function F(a){if(a.preventDefault(),!!u.trim()){R(!0);try{await M.addTodo({text:u.trim(),priority:T,category:l.trim()||void 0}),$(""),b(""),m()}catch{}R(!1)}}async function E(a){try{await M.updateTodo(a.id,{done:!a.done}),m()}catch{}}async function i(a){try{await M.deleteTodo(a),m()}catch{}}async function N(a){if(g.trim())try{await M.updateTodo(a,{text:g.trim()}),y(null),m()}catch{}}const z=C?o.filter(a=>a.project===C):o,B=z.filter(a=>!a.done),I=z.filter(a=>a.done),V=n==="all"?[...B,...I]:z,d=[...new Set(o.map(a=>a.project).filter(Boolean))];return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("form",{onSubmit:F,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:a=>$(a.target.value),placeholder:"Add a todo...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:T,onChange:a=>j(a.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"high",children:"High"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"low",children:"Low"})]}),e.jsx("input",{type:"text",value:l,onChange:a=>b(a.target.value),placeholder:"Category",className:"w-24 px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none"}),e.jsx("button",{type:"submit",disabled:f||!u.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Add"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex gap-1",children:["all","active","done"].map(a=>e.jsx("button",{type:"button",onClick:()=>L(a),className:`px-2.5 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===a?"bg-cc-hover text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:a.charAt(0).toUpperCase()+a.slice(1)},a))}),d.length>0&&e.jsxs("select",{value:C,onChange:a=>P(a.target.value),className:"px-2 py-1 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"",children:"All projects"}),d.map(a=>e.jsx("option",{value:a,children:a},a))]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):V.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n==="done"?"No completed todos":n==="active"?"All done!":"No todos yet. Add one above or ask Gemini Live."}):e.jsx("div",{className:"space-y-1",children:V.map(a=>e.jsxs("div",{className:`group flex items-start gap-3 px-3 py-2.5 rounded-lg border transition-colors ${a.done?"bg-cc-bg border-cc-border/50 opacity-60":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsx("button",{type:"button",onClick:()=>E(a),className:`mt-0.5 w-4 h-4 rounded border-2 shrink-0 flex items-center justify-center cursor-pointer transition-colors ${a.done?"bg-cc-accent border-cc-accent":"border-cc-muted hover:border-cc-accent"}`,children:a.done&&e.jsx("svg",{viewBox:"0 0 12 12",className:"w-2.5 h-2.5 text-white",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M2 6l3 3 5-5"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[w===a.id?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:g,onChange:c=>S(c.target.value),onKeyDown:c=>{c.key==="Enter"&&N(a.id),c.key==="Escape"&&y(null)},className:"flex-1 px-2 py-1 text-sm bg-cc-input border border-cc-border rounded text-cc-fg focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("button",{type:"button",onClick:()=>N(a.id),className:"text-xs text-cc-accent hover:underline cursor-pointer",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>y(null),className:"text-xs text-cc-muted hover:underline cursor-pointer",children:"Cancel"})]}):e.jsx("span",{className:`text-sm ${a.done?"line-through text-cc-muted":"text-cc-fg"}`,onDoubleClick:()=>{y(a.id),S(a.text)},children:a.text}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded border ${ve[a.priority]}`,children:a.priority}),a.category&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:a.category}),a.project&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:a.project}),a.delegatedTo&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-purple-500/10 text-purple-400 border border-purple-500/20",children:[a.delegatedTo,a.dueDate?` · ${a.dueDate}`:""]}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:K(a.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:()=>i(a.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]},a.id))})]})}function ye({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),[T,j]=t.useState(!1),[l,b]=t.useState(""),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(!1),C=t.useCallback(async()=>{A(!0);try{const i=await M.listNotes(n||void 0);k(i.notes)}catch{}A(!1)},[n]);t.useEffect(()=>{C()},[C,x]);function P(){$(null),b(""),R(""),y(""),j(!0)}function v(i){$(i),b(i.title),R(i.content),y(i.tags.join(", ")),j(!0)}async function F(){if(!l.trim())return;S(!0);const i=w.split(",").map(N=>N.trim()).filter(Boolean);try{u?await M.updateNote(u.id,{title:l.trim(),content:f,tags:i}):await M.addNote({title:l.trim(),content:f,tags:i}),j(!1),m()}catch{}S(!1)}async function E(i){try{await M.deleteNote(i),(u==null?void 0:u.id)===i&&j(!1),m()}catch{}}return T?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>j(!1),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("span",{className:"text-xs text-cc-muted",children:u?"Edit Note":"New Note"})]}),e.jsx("input",{type:"text",value:l,onChange:i=>b(i.target.value),placeholder:"Title",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("textarea",{value:f,onChange:i=>R(i.target.value),placeholder:"Write your note...",rows:12,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y font-mono"}),e.jsx("input",{type:"text",value:w,onChange:i=>y(i.target.value),placeholder:"Tags (comma separated)",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:F,disabled:g||!l.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:g?"Saving...":"Save"}),e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-4 py-2 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"Cancel"})]})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:i=>L(i.target.value),placeholder:"Search notes...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:P,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"New Note"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching notes":"No notes yet. Create one or ask Gemini Live."}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:o.map(i=>e.jsxs("div",{className:"group p-4 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors cursor-pointer",onClick:()=>v(i),children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate flex-1",children:i.title}),e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),E(i.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 -mr-1 -mt-1",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]}),i.content&&e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-3",children:i.content}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[i.tags.map(N=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:N},N)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(i.updatedAt)})]})]},i.id))})]})}function Ne({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(!1),[u,$]=t.useState(""),[T,j]=t.useState(""),[l,b]=t.useState(""),[f,R]=t.useState(!1),[w,y]=t.useState(null),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),E=t.useCallback(async()=>{A(!0);try{const c=await M.listReminders(n);k(c.reminders)}catch{}A(!1)},[n]);t.useEffect(()=>{E()},[E,x]);async function i(c){if(c.preventDefault(),!(!u.trim()||!T||!l)){R(!0);try{const s=new Date(`${T}T${l}`).toISOString();await M.addReminder({text:u.trim(),triggerAt:s}),$(""),j(""),b(""),m()}catch{}R(!1)}}async function N(c){try{await M.deleteReminder(c),m()}catch{}}function z(c){y(c.id),S(c.text);const s=new Date(c.triggerAt);P(s.toISOString().slice(0,10)),F(s.toTimeString().slice(0,5))}async function B(c){if(c.preventDefault(),!(!w||!g.trim()||!C||!v))try{const s=new Date(`${C}T${v}`).toISOString();await M.updateReminder(w,{text:g.trim(),triggerAt:s}),y(null),m()}catch{}}const I=new Date,V=o.filter(c=>!c.fired&&new Date(c.triggerAt)>I),d=o.filter(c=>!c.fired&&new Date(c.triggerAt)<=I),a=o.filter(c=>c.fired);return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("form",{onSubmit:i,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:c=>$(c.target.value),placeholder:"Remind me to...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"date",value:T,onChange:c=>j(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("input",{type:"time",value:l,onChange:c=>b(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("button",{type:"submit",disabled:f||!u.trim()||!T||!l,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Add"})]})]}),w&&e.jsxs("form",{onSubmit:B,className:"flex flex-col sm:flex-row gap-2 p-3 bg-cc-accent/5 border border-cc-accent/20 rounded-lg",children:[e.jsx("input",{type:"text",value:g,onChange:c=>S(c.target.value),className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"date",value:C,onChange:c=>P(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("input",{type:"time",value:v,onChange:c=>F(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("button",{type:"submit",disabled:!g.trim()||!C||!v,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>y(null),className:"px-3 py-2 text-xs font-medium rounded-md text-cc-muted hover:text-cc-fg border border-cc-border cursor-pointer",children:"Cancel"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("button",{type:"button",onClick:()=>L(!n),className:`text-xs cursor-pointer ${n?"text-cc-accent":"text-cc-muted hover:text-cc-fg"}`,children:n?"Hide fired":"Show all"})}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No reminders yet. Add one above or ask Gemini Live."}):e.jsxs("div",{className:"space-y-4",children:[d.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-red-400 mb-2",children:"Overdue"}),e.jsx("div",{className:"space-y-1",children:d.map(c=>e.jsx(re,{reminder:c,onDelete:N,onEdit:z,isOverdue:!0},c.id))})]}),V.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-fg mb-2",children:"Upcoming"}),e.jsx("div",{className:"space-y-1",children:V.map(c=>e.jsx(re,{reminder:c,onDelete:N,onEdit:z},c.id))})]}),n&&a.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Completed"}),e.jsx("div",{className:"space-y-1",children:a.map(c=>e.jsx(re,{reminder:c,onDelete:N,isFired:!0},c.id))})]})]})]})}function re({reminder:x,onDelete:m,onEdit:o,isOverdue:k,isFired:p}){return e.jsxs("div",{className:`group flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-colors ${p?"bg-cc-bg border-cc-border/50 opacity-60":k?"bg-red-500/5 border-red-500/20":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${p?"bg-cc-muted":k?"bg-red-400 animate-pulse":"bg-cc-accent"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:`text-sm ${p?"line-through text-cc-muted":"text-cc-fg"}`,children:x.text}),e.jsxs("div",{className:"text-[10px] text-cc-muted mt-0.5",children:[ue(x.triggerAt),x.calendarEventUid&&e.jsx("span",{className:"inline-flex items-center gap-0.5 text-cc-accent ml-1",title:"Synced to calendar",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-2.5 h-2.5",fill:"currentColor",children:e.jsx("path",{d:"M4.5 0a.5.5 0 01.5.5V1h6V.5a.5.5 0 011 0V1h1.5A1.5 1.5 0 0115 2.5v11a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-11A1.5 1.5 0 012.5 1H4V.5a.5.5 0 01.5-.5zM2 5v8.5a.5.5 0 00.5.5h11a.5.5 0 00.5-.5V5H2z"})})})]})]}),!p&&o&&e.jsx("button",{type:"button",onClick:()=>o(x),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-cc-accent transition-opacity cursor-pointer p-1",title:"Edit",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61zM11.189 3.07l1.74 1.74 1.131-1.131a.25.25 0 000-.354L12.974 2.24a.25.25 0 00-.354 0L11.49 3.07z"})})}),e.jsx("button",{type:"button",onClick:()=>m(x.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]})}const ie={gmail:{imap:{host:"imap.gmail.com",port:993,secure:!0},smtp:{host:"smtp.gmail.com",port:465,secure:!0}},outlook:{imap:{host:"outlook.office365.com",port:993,secure:!0},smtp:{host:"smtp.office365.com",port:587,secure:!1}},icloud:{imap:{host:"imap.mail.me.com",port:993,secure:!0},smtp:{host:"smtp.mail.me.com",port:587,secure:!1}},yahoo:{imap:{host:"imap.mail.yahoo.com",port:993,secure:!0},smtp:{host:"smtp.mail.yahoo.com",port:465,secure:!0}}};function we({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState("accounts"),[u,$]=t.useState(null),[T,j]=t.useState([]),[l,b]=t.useState(null),[f,R]=t.useState([]),[w,y]=t.useState(!1),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(""),[B,I]=t.useState("gmail"),[V,d]=t.useState("imap.gmail.com"),[a,c]=t.useState(993),[s,U]=t.useState("smtp.gmail.com"),[G,h]=t.useState(465),[H,O]=t.useState(!1),[_,q]=t.useState(""),[Z,ee]=t.useState(""),[J,te]=t.useState(""),[ne,oe]=t.useState(!1),[ce,le]=t.useState(null),de=t.useCallback(async()=>{A(!0);try{const[r,D]=await Promise.allSettled([M.listEmailAccounts(),M.getUnreadSummary()]);r.status==="fulfilled"&&k(r.value.accounts||[]),D.status==="fulfilled"&&R(D.value.summary||[])}catch{}A(!1)},[]);t.useEffect(()=>{de()},[de,x]);function xe(r){I(r);const D=ie[r];D&&(d(D.imap.host),c(D.imap.port),U(D.smtp.host),h(D.smtp.port))}async function me(r){if(r.preventDefault(),!(!C.trim()||!v.trim()||!E.trim()||!N.trim())){O(!0);try{await M.addEmailAccount({name:C.trim(),email:v.trim(),imap:{host:V,port:a,secure:a===993},smtp:{host:s,port:G,secure:G===465},auth:{user:E.trim(),pass:N}}),P(""),F(""),i(""),z(""),L("accounts"),m()}catch(D){S(D instanceof Error?D.message:"Failed to add account")}O(!1)}}async function pe(r){try{await M.deleteEmailAccount(r),m()}catch{}}async function he(r){S("Testing connection...");try{const D=await M.testEmailAccount(r);S(D.ok?"Connection successful!":`Failed: ${D.error}`)}catch(D){S(D instanceof Error?D.message:"Test failed")}}async function se(r){$(r),L("inbox"),y(!0);try{const D=await M.listEmails(r.id,{limit:20});j(D.emails||[])}catch{j([])}y(!1)}async function be(r){y(!0);try{const D=await M.readEmail(r.accountId,r.uid);b(D),L("read")}catch{}y(!1)}function ae(r){$(u),r?(le(r.uid),q(r.from),ee(r.subject.startsWith("Re:")?r.subject:`Re: ${r.subject}`),te("")):(le(null),q(""),ee(""),te("")),L("compose")}async function ge(r){if(r.preventDefault(),!(!u||!_.trim()||!J.trim())){oe(!0);try{ce?await M.replyToEmail(u.id,{uid:ce,body:J}):await M.sendEmailMessage(u.id,{to:_,subject:Z,body:J}),S("Email sent!"),L("inbox"),se(u)}catch(D){S(D instanceof Error?D.message:"Failed to send")}oe(!1)}}return t.useEffect(()=>{if(g){const r=setTimeout(()=>S(""),3e3);return()=>clearTimeout(r)}},[g]),n==="add-account"?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>L("accounts"),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:"Add Email Account"}),e.jsxs("form",{onSubmit:me,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Provider"}),e.jsxs("div",{className:"flex gap-1 flex-wrap",children:[Object.keys(ie).map(r=>e.jsx("button",{type:"button",onClick:()=>xe(r),className:`px-2.5 py-1 text-xs rounded-md cursor-pointer transition-colors ${B===r?"bg-cc-accent text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:r.charAt(0).toUpperCase()+r.slice(1)},r)),e.jsx("button",{type:"button",onClick:()=>I("custom"),className:`px-2.5 py-1 text-xs rounded-md cursor-pointer transition-colors ${B==="custom"?"bg-cc-accent text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:"Custom"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Display Name"}),e.jsx("input",{type:"text",value:C,onChange:r=>P(r.target.value),placeholder:"Work",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Email Address"}),e.jsx("input",{type:"email",value:v,onChange:r=>F(r.target.value),placeholder:"user@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Username"}),e.jsx("input",{type:"text",value:E,onChange:r=>i(r.target.value),placeholder:"user@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Password / App Password"}),e.jsx("input",{type:"password",value:N,onChange:r=>z(r.target.value),placeholder:"App-specific password",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]})]}),B==="custom"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"IMAP Host"}),e.jsx("input",{type:"text",value:V,onChange:r=>d(r.target.value),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"IMAP Port"}),e.jsx("input",{type:"number",value:a,onChange:r=>c(Number(r.target.value)),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"SMTP Host"}),e.jsx("input",{type:"text",value:s,onChange:r=>U(r.target.value),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"SMTP Port"}),e.jsx("input",{type:"number",value:G,onChange:r=>h(Number(r.target.value)),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]})]}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"For Gmail/iCloud, use an App Password (not your regular password). Go to your account security settings to generate one."}),e.jsx("button",{type:"submit",disabled:H||!C.trim()||!v.trim()||!E.trim()||!N.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:H?"Adding...":"Add Account"})]})]}):n==="compose"&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>L(l?"read":"inbox"),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:ce?"Reply":"New Email"}),g&&e.jsx("div",{className:"text-xs text-cc-accent",children:g}),e.jsxs("form",{onSubmit:ge,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"From"}),e.jsxs("div",{className:"text-xs text-cc-fg",children:[u.name," <",u.email,">"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"To"}),e.jsx("input",{type:"text",value:_,onChange:r=>q(r.target.value),placeholder:"recipient@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Subject"}),e.jsx("input",{type:"text",value:Z,onChange:r=>ee(r.target.value),placeholder:"Subject",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Message"}),e.jsx("textarea",{value:J,onChange:r=>te(r.target.value),rows:10,placeholder:"Write your message...",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y font-mono"})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"submit",disabled:ne||!_.trim()||!J.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:ne?"Sending...":"Send"})})]})]}):n==="read"&&l&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>{L("inbox"),b(null)},className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back to Inbox"]}),e.jsxs("div",{className:"border border-cc-border rounded-lg p-4 bg-cc-card space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:l.subject}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-cc-muted",children:[e.jsxs("span",{children:["From: ",l.from]}),e.jsx("span",{children:ue(l.date)})]}),e.jsxs("div",{className:"text-[10px] text-cc-muted",children:["To: ",l.to]}),e.jsx("div",{className:"border-t border-cc-border pt-3",children:e.jsx("pre",{className:"text-xs text-cc-fg whitespace-pre-wrap font-mono leading-relaxed",children:l.textBody})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ae(l),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent/10 text-cc-accent border border-cc-accent/30 hover:bg-cc-accent/20 cursor-pointer",children:"Reply"}),e.jsx("button",{type:"button",onClick:()=>ae(),className:"px-3 py-1.5 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"New Email"})]})]}):n==="inbox"&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>{L("accounts"),$(null)},className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg font-medium",children:u.name}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:u.email})]}),e.jsx("button",{type:"button",onClick:()=>ae(),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"Compose"})]}),w?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading emails..."}):T.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No emails found."}):e.jsx("div",{className:"space-y-0.5",children:T.map(r=>e.jsxs("button",{type:"button",onClick:()=>be(r),className:`w-full text-left px-3 py-2.5 rounded-lg border transition-colors cursor-pointer ${r.seen?"bg-cc-bg border-cc-border/50":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!r.seen&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-cc-accent shrink-0"}),e.jsx("span",{className:`text-xs truncate flex-1 ${r.seen?"text-cc-muted":"text-cc-fg font-medium"}`,children:r.from}),e.jsx("span",{className:"text-[10px] text-cc-muted shrink-0",children:K(r.date)})]}),e.jsx("div",{className:`text-xs truncate mt-0.5 ${r.seen?"text-cc-muted":"text-cc-fg"}`,children:r.subject})]},r.uid))})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[g&&e.jsx("div",{className:"text-xs px-3 py-2 rounded-md bg-cc-accent/10 text-cc-accent",children:g}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-cc-muted",children:o.length===0?"No email accounts configured.":`${o.length} account${o.length>1?"s":""}`}),e.jsx("button",{type:"button",onClick:()=>L("add-account"),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"Add Account"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):e.jsx("div",{className:"space-y-2",children:o.map(r=>{const D=f.find(fe=>fe.email===r.email);return e.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-accent/10 text-cc-accent flex items-center justify-center text-sm font-bold shrink-0",children:r.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>se(r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:r.name}),D&&D.unread>0&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-cc-accent text-white font-medium",children:D.unread})]}),e.jsx("div",{className:"text-[10px] text-cc-muted truncate",children:r.email})]}),e.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{type:"button",onClick:()=>se(r),className:"px-2 py-1 text-[10px] text-cc-accent hover:underline cursor-pointer",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>he(r.id),className:"px-2 py-1 text-[10px] text-cc-muted hover:text-cc-fg cursor-pointer",children:"Test"}),e.jsx("button",{type:"button",onClick:()=>pe(r.id),className:"px-2 py-1 text-[10px] text-cc-muted hover:text-red-400 cursor-pointer",children:"Delete"})]})]},r.id)})}),o.length===0&&!p&&e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Add an email account to read, send, and manage emails."}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Gemini Live can also manage your emails via voice."})]})]})}function Se({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),[T,j]=t.useState(!1),[l,b]=t.useState(null),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(!1),B=t.useCallback(async()=>{A(!0);try{const c=await M.listCrmContacts(n||void 0);k(c.contacts)}catch{}A(!1)},[n]);t.useEffect(()=>{B()},[B,x]);function I(){b(null),R(""),y(""),S(""),P(""),F(""),i(""),j(!0)}function V(c){b(c),R(c.name),y(c.company||""),S(c.email||""),P(c.phone||""),F(c.notes||""),i(c.tags.join(", ")),j(!0)}async function d(){if(!f.trim())return;z(!0);const c=E.split(",").map(s=>s.trim()).filter(Boolean);try{l?await M.updateCrmContact(l.id,{name:f.trim(),company:w.trim()||void 0,email:g.trim()||void 0,phone:C.trim()||void 0,notes:v,tags:c}):await M.addCrmContact({name:f.trim(),company:w.trim()||void 0,email:g.trim()||void 0,phone:C.trim()||void 0,notes:v,tags:c}),j(!1),m()}catch{}z(!1)}async function a(c){try{await M.deleteCrmContact(c),m()}catch{}}return T?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>j(!1),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("span",{className:"text-xs text-cc-muted",children:l?"Edit Contact":"New Contact"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"text",value:f,onChange:c=>R(c.target.value),placeholder:"Name *",className:"col-span-2 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("input",{type:"text",value:w,onChange:c=>y(c.target.value),placeholder:"Company",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"email",value:g,onChange:c=>S(c.target.value),placeholder:"Email",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"tel",value:C,onChange:c=>P(c.target.value),placeholder:"Phone",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:E,onChange:c=>i(c.target.value),placeholder:"Tags (comma separated)",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsx("textarea",{value:v,onChange:c=>F(c.target.value),placeholder:"Notes...",rows:4,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:d,disabled:N||!f.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:N?"Saving...":"Save"}),e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-4 py-2 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"Cancel"})]})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:c=>L(c.target.value),placeholder:"Search contacts...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:I,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"New Contact"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching contacts":"No contacts yet. Add one or ask Hank."}):e.jsx("div",{className:"space-y-2",children:o.map(c=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 cursor-pointer",onClick:()=>$(u===c.id?null:c.id),children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-accent/20 text-cc-accent flex items-center justify-center text-xs font-medium shrink-0",children:c.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg truncate",children:c.name}),c.company&&e.jsx("span",{className:"text-xs text-cc-muted truncate",children:c.company})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted mt-0.5",children:[c.email&&e.jsx("span",{children:c.email}),c.phone&&e.jsx("span",{children:c.phone}),c.lastContactDate&&e.jsxs("span",{children:["Last: ",K(c.lastContactDate)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),V(c)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-cc-accent transition-opacity cursor-pointer p-1",title:"Edit",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61zM11.189 3.07l1.74 1.74 1.131-1.131a.25.25 0 000-.354L12.974 2.24a.25.25 0 00-.354 0L11.49 3.07z"})})}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),a(c.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]})]}),u===c.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[c.tags.length>0&&e.jsx("div",{className:"flex gap-1 flex-wrap",children:c.tags.map(s=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:s},s))}),c.notes&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Notes"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:c.notes})]}),c.interactions.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Interactions"}),e.jsx("div",{className:"space-y-1",children:c.interactions.slice().reverse().map((s,U)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[e.jsx("span",{className:"text-cc-muted shrink-0",children:s.date.slice(0,10)}),e.jsx("span",{className:`px-1 py-0.5 rounded text-[10px] shrink-0 ${s.type==="call"?"bg-blue-500/10 text-blue-400":s.type==="email"?"bg-green-500/10 text-green-400":s.type==="meeting"?"bg-purple-500/10 text-purple-400":"bg-cc-hover text-cc-muted"}`,children:s.type}),e.jsx("span",{className:"text-cc-fg",children:s.summary})]},U))})]})]})]},c.id))})]})}function Ce({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),T=t.useCallback(async()=>{A(!0);try{const l=await M.listDecisions(n||void 0);k(l.decisions)}catch{}A(!1)},[n]);t.useEffect(()=>{T()},[T,x]);async function j(l){try{await M.deleteDecision(l),m()}catch{}}return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:n,onChange:l=>L(l.target.value),placeholder:"Search decisions...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching decisions":"No decisions logged yet. Hank will record decisions from conversations."}):e.jsx("div",{className:"space-y-3",children:o.map(l=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 cursor-pointer",onClick:()=>$(u===l.id?null:l.id),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:l.title}),e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-2",children:l.decision}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[l.tags.map(b=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:b},b)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(l.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),j(l.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 shrink-0",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]}),u===l.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[l.context&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Context"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:l.context})]}),l.alternatives.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Alternatives Considered"}),e.jsx("ul",{className:"text-xs text-cc-fg space-y-0.5",children:l.alternatives.map((b,f)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-cc-muted",children:"-"}),e.jsx("span",{children:b})]},f))})]}),l.reasoning&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Reasoning"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:l.reasoning})]})]})]},l.id))})]})}function ke({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(""),[T,j]=t.useState([]),[l,b]=t.useState(!1),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState("markdown"),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(!1),N=t.useCallback(async()=>{A(!0);try{if(n){const d=await Q.search(n);k(d.documents)}else{const d=await Q.list(u||void 0);k(d.documents)}}catch{}A(!1)},[n,u]),z=t.useCallback(async()=>{try{const d=await Q.folders();j(d.folders)}catch{}},[]);t.useEffect(()=>{N()},[N,x]),t.useEffect(()=>{z()},[z]);async function B(d){if(d.preventDefault(),!(!f.trim()||!w.trim())){i(!0);try{await Q.create({title:f.trim(),content:w,fileType:g,folder:C.trim()||void 0,tags:v?v.split(",").map(a=>a.trim()).filter(Boolean):void 0}),R(""),y(""),S("markdown"),P(""),F(""),b(!1),m()}catch{}i(!1)}}async function I(d){try{await Q.delete(d),m()}catch{}}const V={markdown:"text-blue-400 bg-blue-500/10",text:"text-gray-400 bg-gray-500/10",json:"text-yellow-400 bg-yellow-500/10",csv:"text-green-400 bg-green-500/10",html:"text-orange-400 bg-orange-500/10"};return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:d=>L(d.target.value),placeholder:"Search documents...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("select",{value:u,onChange:d=>$(d.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"All folders"}),T.map(d=>e.jsx("option",{value:d,children:d},d))]}),e.jsx("button",{type:"button",onClick:()=>b(!l),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ New"})]}),l&&e.jsxs("form",{onSubmit:B,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:f,onChange:d=>R(d.target.value),placeholder:"Document title",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("textarea",{value:w,onChange:d=>y(d.target.value),placeholder:"Document content...",rows:6,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:g,onChange:d=>S(d.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"html",children:"HTML"})]}),e.jsx("input",{type:"text",value:C,onChange:d=>P(d.target.value),placeholder:"Folder (optional)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:v,onChange:d=>F(d.target.value),placeholder:"Tags (comma-sep)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:E||!f.trim()||!w.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:E?"Saving...":"Save Document"})]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n||u?"No matching documents":"No documents yet. Click + New to create one."}):e.jsx("div",{className:"space-y-2",children:o.map(d=>e.jsxs("div",{className:"group flex items-start gap-3 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors px-4 py-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:d.title}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${V[d.fileType]||"text-cc-muted bg-cc-hover"}`,children:d.fileType})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[d.folder&&e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[d.folder,"/"]}),d.tags.map(a=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:a},a)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(d.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:()=>I(d.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 shrink-0",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},d.id))})]})}function Te({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState([]),[T,j]=t.useState(!1),[l,b]=t.useState(""),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(!1),[C,P]=t.useState(null),[v,F]=t.useState({}),[E,i]=t.useState(null),N=t.useCallback(async()=>{A(!0);try{const c=await X.list(n||void 0);k(c.templates)}catch{}A(!1)},[n]),z=t.useCallback(async()=>{try{const c=await X.categories();$(c.categories)}catch{}},[]);t.useEffect(()=>{N()},[N,x]),t.useEffect(()=>{z()},[z]);async function B(c){if(c.preventDefault(),!(!l.trim()||!f.trim()||!w.trim())){S(!0);try{await X.create({name:l.trim(),content:f,category:w.trim()}),b(""),R(""),y(""),j(!1),m()}catch{}S(!1)}}async function I(c){try{await X.delete(c),m()}catch{}}function V(c){P(c.id),i(null);const s={};for(const U of c.variables)s[U.name]=U.defaultValue||"";F(s)}async function d(c){try{const s=await X.use(c,v);i(s.result)}catch{}}const a={email:"text-blue-400 bg-blue-500/10",report:"text-purple-400 bg-purple-500/10",contract:"text-orange-400 bg-orange-500/10",invoice:"text-green-400 bg-green-500/10"};return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:n,onChange:c=>L(c.target.value),className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"All categories"}),u.map(c=>e.jsx("option",{value:c,children:c},c))]}),e.jsx("button",{type:"button",onClick:()=>j(!T),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ New"})]}),T&&e.jsxs("form",{onSubmit:B,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:l,onChange:c=>b(c.target.value),placeholder:"Template name",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("textarea",{value:f,onChange:c=>R(c.target.value),placeholder:`Template content...
1
+ import{r as t,j as e,b as M,d as Q,t as X,c as Y,e as W}from"./index-C6Q5UQHD.js";const ve={high:"text-red-400 bg-red-500/10 border-red-500/20",medium:"text-yellow-400 bg-yellow-500/10 border-yellow-500/20",low:"text-green-400 bg-green-500/10 border-green-500/20"};function K(x){const m=Date.now()-new Date(x).getTime(),o=Math.floor(m/6e4);if(o<1)return"just now";if(o<60)return`${o}m ago`;const k=Math.floor(o/60);if(k<24)return`${k}h ago`;const p=Math.floor(k/24);return p<7?`${p}d ago`:new Date(x).toLocaleDateString()}function ue(x){return new Date(x).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function De(){const[x,m]=t.useState("todos"),[o,k]=t.useState(0);function p(){k(n=>n+1)}const A=[{id:"todos",label:"Todos"},{id:"notes",label:"Notes"},{id:"reminders",label:"Reminders"},{id:"email",label:"Email"},{id:"contacts",label:"Contacts"},{id:"decisions",label:"Decisions"},{id:"documents",label:"Documents"},{id:"templates",label:"Templates"},{id:"time",label:"Time"},{id:"news",label:"News"}];return e.jsxs("div",{className:"h-full flex flex-col bg-cc-bg overflow-hidden",children:[e.jsx("div",{className:"shrink-0 border-b border-cc-border",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Assistant"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Personal todos, notes & reminders — managed by Gemini Live"})]})}),e.jsx("div",{className:"flex gap-1 mt-3",children:A.map(n=>e.jsx("button",{type:"button",onClick:()=>m(n.id),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors cursor-pointer ${x===n.id?"bg-cc-accent text-white":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:n.label},n.id))})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-6 pb-safe",children:[x==="todos"&&e.jsx(je,{refreshKey:o,onRefresh:p}),x==="notes"&&e.jsx(ye,{refreshKey:o,onRefresh:p}),x==="reminders"&&e.jsx(Ne,{refreshKey:o,onRefresh:p}),x==="email"&&e.jsx(we,{refreshKey:o,onRefresh:p}),x==="contacts"&&e.jsx(Se,{refreshKey:o,onRefresh:p}),x==="decisions"&&e.jsx(Ce,{refreshKey:o,onRefresh:p}),x==="documents"&&e.jsx(ke,{refreshKey:o,onRefresh:p}),x==="templates"&&e.jsx(Te,{refreshKey:o,onRefresh:p}),x==="time"&&e.jsx(Ae,{refreshKey:o,onRefresh:p}),x==="news"&&e.jsx(Ee,{refreshKey:o,onRefresh:p})]})})]})}function je({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState("all"),[u,$]=t.useState(""),[T,j]=t.useState("medium"),[l,b]=t.useState(""),[f,R]=t.useState(!1),[w,y]=t.useState(null),[g,S]=t.useState(""),[C,P]=t.useState(""),v=t.useCallback(async()=>{A(!0);try{const a={};n==="active"&&(a.done=!1),n==="done"&&(a.done=!0);const c=await M.listTodos(a);k(c.todos)}catch{}A(!1)},[n]);t.useEffect(()=>{v()},[v,x]);async function F(a){if(a.preventDefault(),!!u.trim()){R(!0);try{await M.addTodo({text:u.trim(),priority:T,category:l.trim()||void 0}),$(""),b(""),m()}catch{}R(!1)}}async function E(a){try{await M.updateTodo(a.id,{done:!a.done}),m()}catch{}}async function i(a){try{await M.deleteTodo(a),m()}catch{}}async function N(a){if(g.trim())try{await M.updateTodo(a,{text:g.trim()}),y(null),m()}catch{}}const z=C?o.filter(a=>a.project===C):o,B=z.filter(a=>!a.done),I=z.filter(a=>a.done),V=n==="all"?[...B,...I]:z,d=[...new Set(o.map(a=>a.project).filter(Boolean))];return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("form",{onSubmit:F,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:a=>$(a.target.value),placeholder:"Add a todo...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:T,onChange:a=>j(a.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"high",children:"High"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"low",children:"Low"})]}),e.jsx("input",{type:"text",value:l,onChange:a=>b(a.target.value),placeholder:"Category",className:"w-24 px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none"}),e.jsx("button",{type:"submit",disabled:f||!u.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Add"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex gap-1",children:["all","active","done"].map(a=>e.jsx("button",{type:"button",onClick:()=>L(a),className:`px-2.5 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===a?"bg-cc-hover text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:a.charAt(0).toUpperCase()+a.slice(1)},a))}),d.length>0&&e.jsxs("select",{value:C,onChange:a=>P(a.target.value),className:"px-2 py-1 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"",children:"All projects"}),d.map(a=>e.jsx("option",{value:a,children:a},a))]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):V.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n==="done"?"No completed todos":n==="active"?"All done!":"No todos yet. Add one above or ask Gemini Live."}):e.jsx("div",{className:"space-y-1",children:V.map(a=>e.jsxs("div",{className:`group flex items-start gap-3 px-3 py-2.5 rounded-lg border transition-colors ${a.done?"bg-cc-bg border-cc-border/50 opacity-60":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsx("button",{type:"button",onClick:()=>E(a),className:`mt-0.5 w-4 h-4 rounded border-2 shrink-0 flex items-center justify-center cursor-pointer transition-colors ${a.done?"bg-cc-accent border-cc-accent":"border-cc-muted hover:border-cc-accent"}`,children:a.done&&e.jsx("svg",{viewBox:"0 0 12 12",className:"w-2.5 h-2.5 text-white",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M2 6l3 3 5-5"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[w===a.id?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:g,onChange:c=>S(c.target.value),onKeyDown:c=>{c.key==="Enter"&&N(a.id),c.key==="Escape"&&y(null)},className:"flex-1 px-2 py-1 text-sm bg-cc-input border border-cc-border rounded text-cc-fg focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("button",{type:"button",onClick:()=>N(a.id),className:"text-xs text-cc-accent hover:underline cursor-pointer",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>y(null),className:"text-xs text-cc-muted hover:underline cursor-pointer",children:"Cancel"})]}):e.jsx("span",{className:`text-sm ${a.done?"line-through text-cc-muted":"text-cc-fg"}`,onDoubleClick:()=>{y(a.id),S(a.text)},children:a.text}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded border ${ve[a.priority]}`,children:a.priority}),a.category&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:a.category}),a.project&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:a.project}),a.delegatedTo&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-purple-500/10 text-purple-400 border border-purple-500/20",children:[a.delegatedTo,a.dueDate?` · ${a.dueDate}`:""]}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:K(a.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:()=>i(a.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]},a.id))})]})}function ye({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),[T,j]=t.useState(!1),[l,b]=t.useState(""),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(!1),C=t.useCallback(async()=>{A(!0);try{const i=await M.listNotes(n||void 0);k(i.notes)}catch{}A(!1)},[n]);t.useEffect(()=>{C()},[C,x]);function P(){$(null),b(""),R(""),y(""),j(!0)}function v(i){$(i),b(i.title),R(i.content),y(i.tags.join(", ")),j(!0)}async function F(){if(!l.trim())return;S(!0);const i=w.split(",").map(N=>N.trim()).filter(Boolean);try{u?await M.updateNote(u.id,{title:l.trim(),content:f,tags:i}):await M.addNote({title:l.trim(),content:f,tags:i}),j(!1),m()}catch{}S(!1)}async function E(i){try{await M.deleteNote(i),(u==null?void 0:u.id)===i&&j(!1),m()}catch{}}return T?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>j(!1),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("span",{className:"text-xs text-cc-muted",children:u?"Edit Note":"New Note"})]}),e.jsx("input",{type:"text",value:l,onChange:i=>b(i.target.value),placeholder:"Title",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("textarea",{value:f,onChange:i=>R(i.target.value),placeholder:"Write your note...",rows:12,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y font-mono"}),e.jsx("input",{type:"text",value:w,onChange:i=>y(i.target.value),placeholder:"Tags (comma separated)",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:F,disabled:g||!l.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:g?"Saving...":"Save"}),e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-4 py-2 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"Cancel"})]})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:i=>L(i.target.value),placeholder:"Search notes...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:P,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"New Note"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching notes":"No notes yet. Create one or ask Gemini Live."}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:o.map(i=>e.jsxs("div",{className:"group p-4 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors cursor-pointer",onClick:()=>v(i),children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate flex-1",children:i.title}),e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),E(i.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 -mr-1 -mt-1",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]}),i.content&&e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-3",children:i.content}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[i.tags.map(N=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:N},N)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(i.updatedAt)})]})]},i.id))})]})}function Ne({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(!1),[u,$]=t.useState(""),[T,j]=t.useState(""),[l,b]=t.useState(""),[f,R]=t.useState(!1),[w,y]=t.useState(null),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),E=t.useCallback(async()=>{A(!0);try{const c=await M.listReminders(n);k(c.reminders)}catch{}A(!1)},[n]);t.useEffect(()=>{E()},[E,x]);async function i(c){if(c.preventDefault(),!(!u.trim()||!T||!l)){R(!0);try{const s=new Date(`${T}T${l}`).toISOString();await M.addReminder({text:u.trim(),triggerAt:s}),$(""),j(""),b(""),m()}catch{}R(!1)}}async function N(c){try{await M.deleteReminder(c),m()}catch{}}function z(c){y(c.id),S(c.text);const s=new Date(c.triggerAt);P(s.toISOString().slice(0,10)),F(s.toTimeString().slice(0,5))}async function B(c){if(c.preventDefault(),!(!w||!g.trim()||!C||!v))try{const s=new Date(`${C}T${v}`).toISOString();await M.updateReminder(w,{text:g.trim(),triggerAt:s}),y(null),m()}catch{}}const I=new Date,V=o.filter(c=>!c.fired&&new Date(c.triggerAt)>I),d=o.filter(c=>!c.fired&&new Date(c.triggerAt)<=I),a=o.filter(c=>c.fired);return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("form",{onSubmit:i,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:c=>$(c.target.value),placeholder:"Remind me to...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"date",value:T,onChange:c=>j(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("input",{type:"time",value:l,onChange:c=>b(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("button",{type:"submit",disabled:f||!u.trim()||!T||!l,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Add"})]})]}),w&&e.jsxs("form",{onSubmit:B,className:"flex flex-col sm:flex-row gap-2 p-3 bg-cc-accent/5 border border-cc-accent/20 rounded-lg",children:[e.jsx("input",{type:"text",value:g,onChange:c=>S(c.target.value),className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"date",value:C,onChange:c=>P(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("input",{type:"time",value:v,onChange:c=>F(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("button",{type:"submit",disabled:!g.trim()||!C||!v,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>y(null),className:"px-3 py-2 text-xs font-medium rounded-md text-cc-muted hover:text-cc-fg border border-cc-border cursor-pointer",children:"Cancel"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("button",{type:"button",onClick:()=>L(!n),className:`text-xs cursor-pointer ${n?"text-cc-accent":"text-cc-muted hover:text-cc-fg"}`,children:n?"Hide fired":"Show all"})}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No reminders yet. Add one above or ask Gemini Live."}):e.jsxs("div",{className:"space-y-4",children:[d.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-red-400 mb-2",children:"Overdue"}),e.jsx("div",{className:"space-y-1",children:d.map(c=>e.jsx(re,{reminder:c,onDelete:N,onEdit:z,isOverdue:!0},c.id))})]}),V.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-fg mb-2",children:"Upcoming"}),e.jsx("div",{className:"space-y-1",children:V.map(c=>e.jsx(re,{reminder:c,onDelete:N,onEdit:z},c.id))})]}),n&&a.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Completed"}),e.jsx("div",{className:"space-y-1",children:a.map(c=>e.jsx(re,{reminder:c,onDelete:N,isFired:!0},c.id))})]})]})]})}function re({reminder:x,onDelete:m,onEdit:o,isOverdue:k,isFired:p}){return e.jsxs("div",{className:`group flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-colors ${p?"bg-cc-bg border-cc-border/50 opacity-60":k?"bg-red-500/5 border-red-500/20":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${p?"bg-cc-muted":k?"bg-red-400 animate-pulse":"bg-cc-accent"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:`text-sm ${p?"line-through text-cc-muted":"text-cc-fg"}`,children:x.text}),e.jsxs("div",{className:"text-[10px] text-cc-muted mt-0.5",children:[ue(x.triggerAt),x.calendarEventUid&&e.jsx("span",{className:"inline-flex items-center gap-0.5 text-cc-accent ml-1",title:"Synced to calendar",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-2.5 h-2.5",fill:"currentColor",children:e.jsx("path",{d:"M4.5 0a.5.5 0 01.5.5V1h6V.5a.5.5 0 011 0V1h1.5A1.5 1.5 0 0115 2.5v11a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-11A1.5 1.5 0 012.5 1H4V.5a.5.5 0 01.5-.5zM2 5v8.5a.5.5 0 00.5.5h11a.5.5 0 00.5-.5V5H2z"})})})]})]}),!p&&o&&e.jsx("button",{type:"button",onClick:()=>o(x),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-cc-accent transition-opacity cursor-pointer p-1",title:"Edit",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61zM11.189 3.07l1.74 1.74 1.131-1.131a.25.25 0 000-.354L12.974 2.24a.25.25 0 00-.354 0L11.49 3.07z"})})}),e.jsx("button",{type:"button",onClick:()=>m(x.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]})}const ie={gmail:{imap:{host:"imap.gmail.com",port:993,secure:!0},smtp:{host:"smtp.gmail.com",port:465,secure:!0}},outlook:{imap:{host:"outlook.office365.com",port:993,secure:!0},smtp:{host:"smtp.office365.com",port:587,secure:!1}},icloud:{imap:{host:"imap.mail.me.com",port:993,secure:!0},smtp:{host:"smtp.mail.me.com",port:587,secure:!1}},yahoo:{imap:{host:"imap.mail.yahoo.com",port:993,secure:!0},smtp:{host:"smtp.mail.yahoo.com",port:465,secure:!0}}};function we({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState("accounts"),[u,$]=t.useState(null),[T,j]=t.useState([]),[l,b]=t.useState(null),[f,R]=t.useState([]),[w,y]=t.useState(!1),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(""),[B,I]=t.useState("gmail"),[V,d]=t.useState("imap.gmail.com"),[a,c]=t.useState(993),[s,U]=t.useState("smtp.gmail.com"),[G,h]=t.useState(465),[H,O]=t.useState(!1),[_,q]=t.useState(""),[Z,ee]=t.useState(""),[J,te]=t.useState(""),[ne,oe]=t.useState(!1),[ce,le]=t.useState(null),de=t.useCallback(async()=>{A(!0);try{const[r,D]=await Promise.allSettled([M.listEmailAccounts(),M.getUnreadSummary()]);r.status==="fulfilled"&&k(r.value.accounts||[]),D.status==="fulfilled"&&R(D.value.summary||[])}catch{}A(!1)},[]);t.useEffect(()=>{de()},[de,x]);function xe(r){I(r);const D=ie[r];D&&(d(D.imap.host),c(D.imap.port),U(D.smtp.host),h(D.smtp.port))}async function me(r){if(r.preventDefault(),!(!C.trim()||!v.trim()||!E.trim()||!N.trim())){O(!0);try{await M.addEmailAccount({name:C.trim(),email:v.trim(),imap:{host:V,port:a,secure:a===993},smtp:{host:s,port:G,secure:G===465},auth:{user:E.trim(),pass:N}}),P(""),F(""),i(""),z(""),L("accounts"),m()}catch(D){S(D instanceof Error?D.message:"Failed to add account")}O(!1)}}async function pe(r){try{await M.deleteEmailAccount(r),m()}catch{}}async function he(r){S("Testing connection...");try{const D=await M.testEmailAccount(r);S(D.ok?"Connection successful!":`Failed: ${D.error}`)}catch(D){S(D instanceof Error?D.message:"Test failed")}}async function se(r){$(r),L("inbox"),y(!0);try{const D=await M.listEmails(r.id,{limit:20});j(D.emails||[])}catch{j([])}y(!1)}async function be(r){y(!0);try{const D=await M.readEmail(r.accountId,r.uid);b(D),L("read")}catch{}y(!1)}function ae(r){$(u),r?(le(r.uid),q(r.from),ee(r.subject.startsWith("Re:")?r.subject:`Re: ${r.subject}`),te("")):(le(null),q(""),ee(""),te("")),L("compose")}async function ge(r){if(r.preventDefault(),!(!u||!_.trim()||!J.trim())){oe(!0);try{ce?await M.replyToEmail(u.id,{uid:ce,body:J}):await M.sendEmailMessage(u.id,{to:_,subject:Z,body:J}),S("Email sent!"),L("inbox"),se(u)}catch(D){S(D instanceof Error?D.message:"Failed to send")}oe(!1)}}return t.useEffect(()=>{if(g){const r=setTimeout(()=>S(""),3e3);return()=>clearTimeout(r)}},[g]),n==="add-account"?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>L("accounts"),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:"Add Email Account"}),e.jsxs("form",{onSubmit:me,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Provider"}),e.jsxs("div",{className:"flex gap-1 flex-wrap",children:[Object.keys(ie).map(r=>e.jsx("button",{type:"button",onClick:()=>xe(r),className:`px-2.5 py-1 text-xs rounded-md cursor-pointer transition-colors ${B===r?"bg-cc-accent text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:r.charAt(0).toUpperCase()+r.slice(1)},r)),e.jsx("button",{type:"button",onClick:()=>I("custom"),className:`px-2.5 py-1 text-xs rounded-md cursor-pointer transition-colors ${B==="custom"?"bg-cc-accent text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:"Custom"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Display Name"}),e.jsx("input",{type:"text",value:C,onChange:r=>P(r.target.value),placeholder:"Work",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Email Address"}),e.jsx("input",{type:"email",value:v,onChange:r=>F(r.target.value),placeholder:"user@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Username"}),e.jsx("input",{type:"text",value:E,onChange:r=>i(r.target.value),placeholder:"user@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Password / App Password"}),e.jsx("input",{type:"password",value:N,onChange:r=>z(r.target.value),placeholder:"App-specific password",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]})]}),B==="custom"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"IMAP Host"}),e.jsx("input",{type:"text",value:V,onChange:r=>d(r.target.value),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"IMAP Port"}),e.jsx("input",{type:"number",value:a,onChange:r=>c(Number(r.target.value)),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"SMTP Host"}),e.jsx("input",{type:"text",value:s,onChange:r=>U(r.target.value),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"SMTP Port"}),e.jsx("input",{type:"number",value:G,onChange:r=>h(Number(r.target.value)),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]})]}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"For Gmail/iCloud, use an App Password (not your regular password). Go to your account security settings to generate one."}),e.jsx("button",{type:"submit",disabled:H||!C.trim()||!v.trim()||!E.trim()||!N.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:H?"Adding...":"Add Account"})]})]}):n==="compose"&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>L(l?"read":"inbox"),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:ce?"Reply":"New Email"}),g&&e.jsx("div",{className:"text-xs text-cc-accent",children:g}),e.jsxs("form",{onSubmit:ge,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"From"}),e.jsxs("div",{className:"text-xs text-cc-fg",children:[u.name," <",u.email,">"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"To"}),e.jsx("input",{type:"text",value:_,onChange:r=>q(r.target.value),placeholder:"recipient@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Subject"}),e.jsx("input",{type:"text",value:Z,onChange:r=>ee(r.target.value),placeholder:"Subject",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Message"}),e.jsx("textarea",{value:J,onChange:r=>te(r.target.value),rows:10,placeholder:"Write your message...",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y font-mono"})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"submit",disabled:ne||!_.trim()||!J.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:ne?"Sending...":"Send"})})]})]}):n==="read"&&l&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>{L("inbox"),b(null)},className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back to Inbox"]}),e.jsxs("div",{className:"border border-cc-border rounded-lg p-4 bg-cc-card space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:l.subject}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-cc-muted",children:[e.jsxs("span",{children:["From: ",l.from]}),e.jsx("span",{children:ue(l.date)})]}),e.jsxs("div",{className:"text-[10px] text-cc-muted",children:["To: ",l.to]}),e.jsx("div",{className:"border-t border-cc-border pt-3",children:e.jsx("pre",{className:"text-xs text-cc-fg whitespace-pre-wrap font-mono leading-relaxed",children:l.textBody})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ae(l),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent/10 text-cc-accent border border-cc-accent/30 hover:bg-cc-accent/20 cursor-pointer",children:"Reply"}),e.jsx("button",{type:"button",onClick:()=>ae(),className:"px-3 py-1.5 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"New Email"})]})]}):n==="inbox"&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>{L("accounts"),$(null)},className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg font-medium",children:u.name}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:u.email})]}),e.jsx("button",{type:"button",onClick:()=>ae(),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"Compose"})]}),w?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading emails..."}):T.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No emails found."}):e.jsx("div",{className:"space-y-0.5",children:T.map(r=>e.jsxs("button",{type:"button",onClick:()=>be(r),className:`w-full text-left px-3 py-2.5 rounded-lg border transition-colors cursor-pointer ${r.seen?"bg-cc-bg border-cc-border/50":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!r.seen&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-cc-accent shrink-0"}),e.jsx("span",{className:`text-xs truncate flex-1 ${r.seen?"text-cc-muted":"text-cc-fg font-medium"}`,children:r.from}),e.jsx("span",{className:"text-[10px] text-cc-muted shrink-0",children:K(r.date)})]}),e.jsx("div",{className:`text-xs truncate mt-0.5 ${r.seen?"text-cc-muted":"text-cc-fg"}`,children:r.subject})]},r.uid))})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[g&&e.jsx("div",{className:"text-xs px-3 py-2 rounded-md bg-cc-accent/10 text-cc-accent",children:g}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-cc-muted",children:o.length===0?"No email accounts configured.":`${o.length} account${o.length>1?"s":""}`}),e.jsx("button",{type:"button",onClick:()=>L("add-account"),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"Add Account"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):e.jsx("div",{className:"space-y-2",children:o.map(r=>{const D=f.find(fe=>fe.email===r.email);return e.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-accent/10 text-cc-accent flex items-center justify-center text-sm font-bold shrink-0",children:r.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>se(r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:r.name}),D&&D.unread>0&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-cc-accent text-white font-medium",children:D.unread})]}),e.jsx("div",{className:"text-[10px] text-cc-muted truncate",children:r.email})]}),e.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{type:"button",onClick:()=>se(r),className:"px-2 py-1 text-[10px] text-cc-accent hover:underline cursor-pointer",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>he(r.id),className:"px-2 py-1 text-[10px] text-cc-muted hover:text-cc-fg cursor-pointer",children:"Test"}),e.jsx("button",{type:"button",onClick:()=>pe(r.id),className:"px-2 py-1 text-[10px] text-cc-muted hover:text-red-400 cursor-pointer",children:"Delete"})]})]},r.id)})}),o.length===0&&!p&&e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Add an email account to read, send, and manage emails."}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Gemini Live can also manage your emails via voice."})]})]})}function Se({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),[T,j]=t.useState(!1),[l,b]=t.useState(null),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(!1),B=t.useCallback(async()=>{A(!0);try{const c=await M.listCrmContacts(n||void 0);k(c.contacts)}catch{}A(!1)},[n]);t.useEffect(()=>{B()},[B,x]);function I(){b(null),R(""),y(""),S(""),P(""),F(""),i(""),j(!0)}function V(c){b(c),R(c.name),y(c.company||""),S(c.email||""),P(c.phone||""),F(c.notes||""),i(c.tags.join(", ")),j(!0)}async function d(){if(!f.trim())return;z(!0);const c=E.split(",").map(s=>s.trim()).filter(Boolean);try{l?await M.updateCrmContact(l.id,{name:f.trim(),company:w.trim()||void 0,email:g.trim()||void 0,phone:C.trim()||void 0,notes:v,tags:c}):await M.addCrmContact({name:f.trim(),company:w.trim()||void 0,email:g.trim()||void 0,phone:C.trim()||void 0,notes:v,tags:c}),j(!1),m()}catch{}z(!1)}async function a(c){try{await M.deleteCrmContact(c),m()}catch{}}return T?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>j(!1),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("span",{className:"text-xs text-cc-muted",children:l?"Edit Contact":"New Contact"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"text",value:f,onChange:c=>R(c.target.value),placeholder:"Name *",className:"col-span-2 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("input",{type:"text",value:w,onChange:c=>y(c.target.value),placeholder:"Company",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"email",value:g,onChange:c=>S(c.target.value),placeholder:"Email",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"tel",value:C,onChange:c=>P(c.target.value),placeholder:"Phone",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:E,onChange:c=>i(c.target.value),placeholder:"Tags (comma separated)",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsx("textarea",{value:v,onChange:c=>F(c.target.value),placeholder:"Notes...",rows:4,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:d,disabled:N||!f.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:N?"Saving...":"Save"}),e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-4 py-2 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"Cancel"})]})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:c=>L(c.target.value),placeholder:"Search contacts...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:I,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"New Contact"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching contacts":"No contacts yet. Add one or ask Hank."}):e.jsx("div",{className:"space-y-2",children:o.map(c=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 cursor-pointer",onClick:()=>$(u===c.id?null:c.id),children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-accent/20 text-cc-accent flex items-center justify-center text-xs font-medium shrink-0",children:c.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg truncate",children:c.name}),c.company&&e.jsx("span",{className:"text-xs text-cc-muted truncate",children:c.company})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted mt-0.5",children:[c.email&&e.jsx("span",{children:c.email}),c.phone&&e.jsx("span",{children:c.phone}),c.lastContactDate&&e.jsxs("span",{children:["Last: ",K(c.lastContactDate)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),V(c)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-cc-accent transition-opacity cursor-pointer p-1",title:"Edit",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61zM11.189 3.07l1.74 1.74 1.131-1.131a.25.25 0 000-.354L12.974 2.24a.25.25 0 00-.354 0L11.49 3.07z"})})}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),a(c.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]})]}),u===c.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[c.tags.length>0&&e.jsx("div",{className:"flex gap-1 flex-wrap",children:c.tags.map(s=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:s},s))}),c.notes&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Notes"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:c.notes})]}),c.interactions.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Interactions"}),e.jsx("div",{className:"space-y-1",children:c.interactions.slice().reverse().map((s,U)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[e.jsx("span",{className:"text-cc-muted shrink-0",children:s.date.slice(0,10)}),e.jsx("span",{className:`px-1 py-0.5 rounded text-[10px] shrink-0 ${s.type==="call"?"bg-blue-500/10 text-blue-400":s.type==="email"?"bg-green-500/10 text-green-400":s.type==="meeting"?"bg-purple-500/10 text-purple-400":"bg-cc-hover text-cc-muted"}`,children:s.type}),e.jsx("span",{className:"text-cc-fg",children:s.summary})]},U))})]})]})]},c.id))})]})}function Ce({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),T=t.useCallback(async()=>{A(!0);try{const l=await M.listDecisions(n||void 0);k(l.decisions)}catch{}A(!1)},[n]);t.useEffect(()=>{T()},[T,x]);async function j(l){try{await M.deleteDecision(l),m()}catch{}}return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:n,onChange:l=>L(l.target.value),placeholder:"Search decisions...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching decisions":"No decisions logged yet. Hank will record decisions from conversations."}):e.jsx("div",{className:"space-y-3",children:o.map(l=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 cursor-pointer",onClick:()=>$(u===l.id?null:l.id),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:l.title}),e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-2",children:l.decision}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[l.tags.map(b=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:b},b)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(l.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),j(l.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 shrink-0",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]}),u===l.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[l.context&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Context"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:l.context})]}),l.alternatives.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Alternatives Considered"}),e.jsx("ul",{className:"text-xs text-cc-fg space-y-0.5",children:l.alternatives.map((b,f)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-cc-muted",children:"-"}),e.jsx("span",{children:b})]},f))})]}),l.reasoning&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Reasoning"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:l.reasoning})]})]})]},l.id))})]})}function ke({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(""),[T,j]=t.useState([]),[l,b]=t.useState(!1),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState("markdown"),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(!1),N=t.useCallback(async()=>{A(!0);try{if(n){const d=await Q.search(n);k(d.documents)}else{const d=await Q.list(u||void 0);k(d.documents)}}catch{}A(!1)},[n,u]),z=t.useCallback(async()=>{try{const d=await Q.folders();j(d.folders)}catch{}},[]);t.useEffect(()=>{N()},[N,x]),t.useEffect(()=>{z()},[z]);async function B(d){if(d.preventDefault(),!(!f.trim()||!w.trim())){i(!0);try{await Q.create({title:f.trim(),content:w,fileType:g,folder:C.trim()||void 0,tags:v?v.split(",").map(a=>a.trim()).filter(Boolean):void 0}),R(""),y(""),S("markdown"),P(""),F(""),b(!1),m()}catch{}i(!1)}}async function I(d){try{await Q.delete(d),m()}catch{}}const V={markdown:"text-blue-400 bg-blue-500/10",text:"text-gray-400 bg-gray-500/10",json:"text-yellow-400 bg-yellow-500/10",csv:"text-green-400 bg-green-500/10",html:"text-orange-400 bg-orange-500/10"};return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:d=>L(d.target.value),placeholder:"Search documents...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("select",{value:u,onChange:d=>$(d.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"All folders"}),T.map(d=>e.jsx("option",{value:d,children:d},d))]}),e.jsx("button",{type:"button",onClick:()=>b(!l),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ New"})]}),l&&e.jsxs("form",{onSubmit:B,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:f,onChange:d=>R(d.target.value),placeholder:"Document title",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("textarea",{value:w,onChange:d=>y(d.target.value),placeholder:"Document content...",rows:6,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:g,onChange:d=>S(d.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"html",children:"HTML"})]}),e.jsx("input",{type:"text",value:C,onChange:d=>P(d.target.value),placeholder:"Folder (optional)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:v,onChange:d=>F(d.target.value),placeholder:"Tags (comma-sep)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:E||!f.trim()||!w.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:E?"Saving...":"Save Document"})]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n||u?"No matching documents":"No documents yet. Click + New to create one."}):e.jsx("div",{className:"space-y-2",children:o.map(d=>e.jsxs("div",{className:"group flex items-start gap-3 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors px-4 py-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:d.title}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${V[d.fileType]||"text-cc-muted bg-cc-hover"}`,children:d.fileType})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[d.folder&&e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[d.folder,"/"]}),d.tags.map(a=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:a},a)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(d.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:()=>I(d.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 shrink-0",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},d.id))})]})}function Te({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState([]),[T,j]=t.useState(!1),[l,b]=t.useState(""),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(!1),[C,P]=t.useState(null),[v,F]=t.useState({}),[E,i]=t.useState(null),N=t.useCallback(async()=>{A(!0);try{const c=await X.list(n||void 0);k(c.templates)}catch{}A(!1)},[n]),z=t.useCallback(async()=>{try{const c=await X.categories();$(c.categories)}catch{}},[]);t.useEffect(()=>{N()},[N,x]),t.useEffect(()=>{z()},[z]);async function B(c){if(c.preventDefault(),!(!l.trim()||!f.trim()||!w.trim())){S(!0);try{await X.create({name:l.trim(),content:f,category:w.trim()}),b(""),R(""),y(""),j(!1),m()}catch{}S(!1)}}async function I(c){try{await X.delete(c),m()}catch{}}function V(c){P(c.id),i(null);const s={};for(const U of c.variables)s[U.name]=U.defaultValue||"";F(s)}async function d(c){try{const s=await X.use(c,v);i(s.result)}catch{}}const a={email:"text-blue-400 bg-blue-500/10",report:"text-purple-400 bg-purple-500/10",contract:"text-orange-400 bg-orange-500/10",invoice:"text-green-400 bg-green-500/10"};return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:n,onChange:c=>L(c.target.value),className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"All categories"}),u.map(c=>e.jsx("option",{value:c,children:c},c))]}),e.jsx("button",{type:"button",onClick:()=>j(!T),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ New"})]}),T&&e.jsxs("form",{onSubmit:B,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:l,onChange:c=>b(c.target.value),placeholder:"Template name",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("textarea",{value:f,onChange:c=>R(c.target.value),placeholder:`Template content...
2
2
  Use {{variable_name}} for variables`,rows:6,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsx("input",{type:"text",value:w,onChange:c=>y(c.target.value),placeholder:"Category (e.g. email, report, contract)",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:g||!l.trim()||!f.trim()||!w.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:g?"Saving...":"Save Template"})]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No templates in this category":"No templates yet. Click + New to create one."}):e.jsx("div",{className:"space-y-2",children:o.map(c=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:c.name}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${a[c.category]||"text-cc-muted bg-cc-hover"}`,children:c.category})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1.5",children:[e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[c.variables.length," variable",c.variables.length!==1?"s":""]}),e.jsxs("span",{className:"text-[10px] text-cc-muted",children:["Used ",c.usageCount,"x"]}),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(c.createdAt)})]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>V(c),className:"text-[11px] px-2 py-1 rounded text-cc-accent hover:bg-cc-accent/10 transition-colors cursor-pointer",children:"Use"}),e.jsx("button",{type:"button",onClick:()=>I(c.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})]}),C===c.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[c.variables.length>0?e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider",children:"Fill Variables"}),c.variables.map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-cc-muted w-28 shrink-0",children:s.name}),e.jsx("input",{type:"text",value:v[s.name]||"",onChange:U=>F({...v,[s.name]:U.target.value}),placeholder:s.description||s.name,className:"flex-1 px-2 py-1 text-xs bg-cc-input border border-cc-border rounded text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]},s.name))]}):e.jsx("p",{className:"text-xs text-cc-muted",children:"No variables in this template."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>d(c.id),className:"px-3 py-1.5 text-xs bg-cc-accent text-white rounded hover:bg-cc-accent/80 transition-colors cursor-pointer",children:"Generate"}),e.jsx("button",{type:"button",onClick:()=>{P(null),i(null)},className:"px-3 py-1.5 text-xs text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"})]}),E&&e.jsxs("div",{className:"mt-2 p-3 rounded bg-cc-hover border border-cc-border",children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Result"}),e.jsx("pre",{className:"text-xs text-cc-fg whitespace-pre-wrap break-words",children:E})]})]})]},c.id))})]})}function Ae({refreshKey:x,onRefresh:m}){const[o,k]=t.useState(null),[p,A]=t.useState([]),[n,L]=t.useState(null),[u,$]=t.useState(!0),[T,j]=t.useState(""),[l,b]=t.useState(!1),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(""),[C,P]=t.useState(!1),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(""),[B,I]=t.useState(!1),[V,d]=t.useState(!1),a=t.useCallback(async()=>{$(!0);try{const[h,H,O]=await Promise.all([Y.getTimer(),Y.listEntries(),Y.report("week")]);k(h.timer),A(H.entries),L(O)}catch{}$(!1)},[]);t.useEffect(()=>{a()},[a,x]),t.useEffect(()=>{if(!o){j("");return}function h(){if(!o)return;const O=Date.now()-new Date(o.startTime).getTime(),_=Math.floor(O/36e5),q=Math.floor(O%36e5/6e4),Z=Math.floor(O%6e4/1e3);j(`${_.toString().padStart(2,"0")}:${q.toString().padStart(2,"0")}:${Z.toString().padStart(2,"0")}`)}h();const H=setInterval(h,1e3);return()=>clearInterval(H)},[o]);async function c(h){if(h.preventDefault(),!!f.trim()){I(!0);try{await Y.startTimer(f.trim(),w.trim()||void 0,g.trim()||void 0),R(""),y(""),S(""),b(!1),m()}catch{}I(!1)}}async function s(){try{await Y.stopTimer(),m()}catch{}}async function U(h){h.preventDefault();const H=parseFloat(E);if(!(!v.trim()||isNaN(H)||H<=0)){d(!0);try{await Y.logTime({task:v.trim(),duration:H,project:N.trim()||void 0}),F(""),i(""),z(""),P(!1),m()}catch{}d(!1)}}function G(h){if(h<60)return`${Math.round(h)}m`;const H=Math.floor(h/60),O=Math.round(h%60);return O>0?`${H}h ${O}m`:`${H}h`}return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[o&&e.jsx("div",{className:"rounded-lg border border-cc-accent/50 bg-cc-accent/5 p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-400 animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:o.task}),o.project&&e.jsx("span",{className:"text-[10px] text-cc-muted",children:o.project})]}),e.jsx("span",{className:"text-sm font-mono text-cc-accent",children:T}),e.jsx("button",{type:"button",onClick:s,className:"px-3 py-1.5 text-xs bg-red-500/10 text-red-400 rounded hover:bg-red-500/20 transition-colors cursor-pointer",children:"Stop"})]})}),e.jsxs("div",{className:"flex gap-2",children:[!o&&e.jsx("button",{type:"button",onClick:()=>{b(!l),P(!1)},className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer",children:"Start Timer"}),e.jsx("button",{type:"button",onClick:()=>{P(!C),b(!1)},className:"px-3 py-2 text-sm border border-cc-border text-cc-fg rounded-md hover:bg-cc-hover transition-colors cursor-pointer",children:"Quick Log"})]}),l&&e.jsxs("form",{onSubmit:c,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:f,onChange:h=>R(h.target.value),placeholder:"What are you working on?",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:w,onChange:h=>y(h.target.value),placeholder:"Project (optional)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:g,onChange:h=>S(h.target.value),placeholder:"Category (optional)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:B||!f.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:B?"Starting...":"Start"})]})]}),C&&e.jsxs("form",{onSubmit:U,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:v,onChange:h=>F(h.target.value),placeholder:"Task description",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"number",value:E,onChange:h=>i(h.target.value),placeholder:"Minutes",min:"1",step:"1",className:"w-24 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsx("input",{type:"text",value:N,onChange:h=>z(h.target.value),placeholder:"Project (optional)",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>P(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:V||!v.trim()||!E,className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:V?"Logging...":"Log Time"})]})]}),u?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):e.jsxs(e.Fragment,{children:[n&&n.totalMinutes>0&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted uppercase tracking-wider mb-3",children:"This Week"}),e.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[e.jsx("span",{className:"text-2xl font-semibold text-cc-fg",children:G(n.totalMinutes)}),e.jsx("span",{className:"text-xs text-cc-muted",children:"total"})]}),Object.keys(n.byProject).length>0&&e.jsx("div",{className:"space-y-1.5",children:Object.entries(n.byProject).sort(([,h],[,H])=>H-h).map(([h,H])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg flex-1 truncate",children:h||"No project"}),e.jsx("span",{className:"text-xs text-cc-muted",children:G(H)}),e.jsx("div",{className:"w-20 h-1.5 rounded-full bg-cc-hover overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-cc-accent",style:{width:`${Math.round(H/n.totalMinutes*100)}%`}})})]},h))})]}),p.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted uppercase tracking-wider",children:"Recent Entries"}),p.slice(0,20).map(h=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-cc-border bg-cc-card px-4 py-2.5",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm text-cc-fg",children:h.task}),h.project&&e.jsx("span",{className:"text-[10px] text-cc-muted ml-2",children:h.project})]}),e.jsx("span",{className:"text-xs text-cc-muted shrink-0",children:h.duration!=null?G(h.duration):"running"}),e.jsx("span",{className:"text-[10px] text-cc-muted shrink-0",children:K(h.startTime)})]},h.id))]}),p.length===0&&!o&&e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No time entries yet. Start a timer or log time manually."})]})]})}function Ee({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState([]),[n,L]=t.useState(null),[u,$]=t.useState(!0),[T,j]=t.useState(""),[l,b]=t.useState(!1),[f,R]=t.useState(!1),[w,y]=t.useState(""),[g,S]=t.useState("rss"),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(!1),B=t.useCallback(async()=>{$(!0);try{if(T){const s=await W.search(T);k(s.items)}else{const[s,U,G]=await Promise.all([W.list({limit:50}),W.stats(),W.listSources()]);k(s.items),L(U),A(G.sources)}}catch{}$(!1)},[T]);t.useEffect(()=>{B()},[B,x]);async function I(s){if(s.preventDefault(),!(!w.trim()||!E.trim())){z(!0);try{await W.addSource({name:w.trim(),type:g,category:E.trim(),url:C.trim()||void 0,keywords:v?v.split(",").map(U=>U.trim()).filter(Boolean):void 0}),y(""),S("rss"),P(""),F(""),i(""),b(!1),m()}catch{}z(!1)}}async function V(s){try{await W.deleteSource(s),m()}catch{}}async function d(s){try{await W.markRead(s),m()}catch{}}async function a(s){try{await W.toggleSaved(s),m()}catch{}}async function c(){try{await W.markAllRead(),m()}catch{}}return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[n&&e.jsxs("div",{className:"flex items-center gap-4 text-xs text-cc-muted",children:[e.jsxs("span",{children:[n.total," articles"]}),e.jsxs("span",{className:n.unread>0?"text-cc-accent font-medium":"",children:[n.unread," unread"]}),e.jsxs("span",{children:[n.sources," sources"]}),n.unread>0&&e.jsx("button",{type:"button",onClick:c,className:"ml-auto text-xs text-cc-accent hover:text-cc-accent/80 transition-colors cursor-pointer",children:"Mark all read"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:T,onChange:s=>j(s.target.value),placeholder:"Search news...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:()=>{R(!f),b(!1)},className:"px-3 py-2 text-sm border border-cc-border text-cc-fg rounded-md hover:bg-cc-hover transition-colors cursor-pointer",children:"Sources"}),e.jsx("button",{type:"button",onClick:()=>{b(!l),R(!1)},className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ Source"})]}),f&&p.length>0&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted uppercase tracking-wider mb-2",children:"Sources"}),p.map(s=>e.jsxs("div",{className:"group flex items-center gap-3 py-1.5",children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${s.enabled?"bg-green-400":"bg-gray-500"}`}),e.jsx("span",{className:"text-sm text-cc-fg flex-1 truncate",children:s.name}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:s.type}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:s.category}),e.jsx("button",{type:"button",onClick:()=>V(s.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete source",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},s.id))]}),l&&e.jsxs("form",{onSubmit:I,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:w,onChange:s=>y(s.target.value),placeholder:"Source name",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:g,onChange:s=>S(s.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"rss",children:"RSS Feed"}),e.jsx("option",{value:"website",children:"Website"}),e.jsx("option",{value:"keyword",children:"Keyword Monitor"})]}),e.jsx("input",{type:"text",value:E,onChange:s=>i(s.target.value),placeholder:"Category",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),(g==="rss"||g==="website")&&e.jsx("input",{type:"text",value:C,onChange:s=>P(s.target.value),placeholder:"URL",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),g==="keyword"&&e.jsx("input",{type:"text",value:v,onChange:s=>F(s.target.value),placeholder:"Keywords (comma-separated)",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:N||!w.trim()||!E.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:N?"Adding...":"Add Source"})]})]}),u?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:T?"No matching articles":"No news yet. Add sources to start monitoring."}):e.jsx("div",{className:"space-y-2",children:o.map(s=>e.jsx("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors px-4 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 ${s.read?"bg-transparent":"bg-cc-accent"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:`text-sm font-medium ${s.read?"text-cc-muted":"text-cc-fg"}`,children:s.url?e.jsx("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"hover:underline",children:s.title}):s.title}),s.summary&&e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-2",children:s.summary}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("span",{className:"text-[10px] text-cc-muted",children:s.sourceName}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:s.category}),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(s.publishedAt)})]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[!s.read&&e.jsx("button",{type:"button",onClick:()=>d(s.id),className:"text-[10px] px-1.5 py-0.5 text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",title:"Mark read",children:"read"}),e.jsx("button",{type:"button",onClick:()=>a(s.id),className:`text-[10px] px-1.5 py-0.5 transition-colors cursor-pointer ${s.saved?"text-yellow-400":"text-cc-muted hover:text-yellow-400"}`,title:s.saved?"Saved":"Save",children:s.saved?"saved":"save"})]})]})},s.id))})]})}export{De as AssistantPage};
@@ -1 +1 @@
1
- import{r,j as e,f as N,k as H}from"./index-BgYM4wXw.js";function P(s,a){try{return new Intl.NumberFormat(void 0,{style:"currency",currency:a}).format(s)}catch{return`${a} ${s.toFixed(2)}`}}function te(s){switch(s){case"draft":return"bg-gray-500/20 text-gray-400";case"sent":return"bg-blue-500/20 text-blue-400";case"paid":return"bg-green-500/20 text-green-400";case"overdue":return"bg-red-500/20 text-red-400";default:return"bg-cc-hover text-cc-muted"}}function ce(s){return s==="up"?"↑":s==="down"?"↓":"→"}function J(s,a){return!s||s==="stable"?"text-cc-muted":s==="up"&&a==="higher_is_better"||s==="down"&&a==="lower_is_better"?"text-green-400":"text-red-400"}function se(s){if(s.currentValue==null||s.target==null)return"gray";const a=s.direction==="lower_is_better"?s.target/s.currentValue:s.currentValue/s.target;return a>=.9?"green":a>=.7?"yellow":"red"}function re(s){if(s.currentValue==null||s.target==null||s.target===0)return 0;const a=s.direction==="lower_is_better"?s.target/Math.max(s.currentValue,.001)*100:s.currentValue/s.target*100;return Math.min(Math.max(a,0),100)}function ne(){const[s,a]=r.useState(null),[i,I]=r.useState([]),[x,K]=r.useState([]),[E,b]=r.useState(!0),[h,f]=r.useState(""),[y,k]=r.useState(!1),[u,V]=r.useState(""),[d,w]=r.useState([{description:"",quantity:1,unitPrice:0,total:0}]),[D,_]=r.useState(""),[R,q]=r.useState(!1),[F,L]=r.useState(!1),[m,C]=r.useState(""),[g,v]=r.useState(""),[T,$]=r.useState(""),[j,U]=r.useState(""),[A,W]=r.useState(!1),c=r.useCallback(async()=>{b(!0),f("");try{const[t,n,o]=await Promise.all([N.summary(),N.listInvoices(),N.listExpenses()]);a(t),I(n.invoices),K(o.expenses)}catch(t){f(t instanceof Error?t.message:"Failed to load finance data")}b(!1)},[]);r.useEffect(()=>{c()},[c]);const p=(t,n,o)=>{w(O=>{const Q=[...O],S={...Q[t]};if(n==="description")S.description=o;else{const G=parseFloat(o)||0;n==="quantity"&&(S.quantity=G),n==="unitPrice"&&(S.unitPrice=G)}return S.total=S.quantity*S.unitPrice,Q[t]=S,Q})},M=()=>{w(t=>[...t,{description:"",quantity:1,unitPrice:0,total:0}])},z=t=>{w(n=>n.length<=1?n:n.filter((o,O)=>O!==t))},l=async()=>{if(!(!u.trim()||d.every(t=>!t.description.trim()))){q(!0);try{const t=d.filter(n=>n.description.trim()).map(n=>({description:n.description,quantity:n.quantity,unitPrice:n.unitPrice,total:n.quantity*n.unitPrice}));await N.createInvoice({clientName:u.trim(),items:t,notes:D.trim()||void 0}),k(!1),V(""),w([{description:"",quantity:1,unitPrice:0,total:0}]),_(""),c()}catch(t){f(t instanceof Error?t.message:"Failed to create invoice")}q(!1)}},X=async t=>{try{await N.markPaid(t),c()}catch{}},Y=async t=>{try{await N.deleteInvoice(t),I(n=>n.filter(o=>o.id!==t))}catch{}},Z=async()=>{if(!(!m.trim()||!g)){W(!0);try{await N.logExpense({description:m.trim(),amount:parseFloat(g),category:T.trim()||"general",vendor:j.trim()||void 0}),L(!1),C(""),v(""),$(""),U(""),c()}catch(t){f(t instanceof Error?t.message:"Failed to log expense")}W(!1)}},ee=async t=>{try{await N.deleteExpense(t),K(n=>n.filter(o=>o.id!==t))}catch{}};if(E)return e.jsx("p",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading finance data..."});if(h&&!s)return e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-sm text-red-400",children:h}),e.jsx("button",{type:"button",onClick:c,className:"mt-2 text-xs text-cc-accent hover:underline",children:"Retry"})]});const B=(s==null?void 0:s.currency)||"EUR";return e.jsxs("div",{className:"space-y-6",children:[h&&e.jsxs("div",{className:"px-3 py-2 rounded-md bg-red-500/10 border border-red-500/20 text-sm text-red-400",children:[h,e.jsx("button",{type:"button",onClick:()=>f(""),className:"ml-2 text-xs underline",children:"dismiss"})]}),s&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("p",{className:"text-xs text-cc-muted uppercase tracking-wider",children:"Revenue"}),e.jsx("p",{className:"text-xl font-semibold text-green-400 mt-1",children:P(s.totalRevenue,B)})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("p",{className:"text-xs text-cc-muted uppercase tracking-wider",children:"Expenses"}),e.jsx("p",{className:"text-xl font-semibold text-red-400 mt-1",children:P(s.totalExpenses,B)})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("p",{className:"text-xs text-cc-muted uppercase tracking-wider",children:"Profit"}),e.jsx("p",{className:`text-xl font-semibold mt-1 ${s.netProfit>=0?"text-green-400":"text-red-400"}`,children:P(s.netProfit,B)})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Invoices"}),e.jsx("button",{type:"button",onClick:()=>k(!y),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 transition-colors",children:y?"Cancel":"+ New Invoice"})]}),y&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 mb-4 space-y-3",children:[e.jsx("input",{type:"text",value:u,onChange:t=>V(t.target.value),placeholder:"Client name",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-cc-muted font-medium",children:"Line items"}),d.map((t,n)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{type:"text",value:t.description,onChange:o=>p(n,"description",o.target.value),placeholder:"Description",className:"flex-1 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"number",value:t.quantity||"",onChange:o=>p(n,"quantity",o.target.value),placeholder:"Qty",min:"1",className:"w-16 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"number",value:t.unitPrice||"",onChange:o=>p(n,"unitPrice",o.target.value),placeholder:"Price",min:"0",step:"0.01",className:"w-24 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("span",{className:"text-xs text-cc-muted w-20 text-right",children:P(t.quantity*t.unitPrice,B)}),d.length>1&&e.jsx("button",{type:"button",onClick:()=>z(n),className:"text-cc-muted hover:text-red-400 p-1 transition-colors",children:e.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},n)),e.jsx("button",{type:"button",onClick:M,className:"text-xs text-cc-accent hover:underline",children:"+ Add item"})]}),e.jsx("textarea",{value:D,onChange:t=>_(t.target.value),placeholder:"Notes (optional)",rows:2,className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent resize-none"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm font-medium text-cc-fg",children:["Total: ",P(d.reduce((t,n)=>t+n.quantity*n.unitPrice,0),B)]}),e.jsx("button",{type:"button",onClick:l,disabled:R||!u.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:R?"Creating...":"Create Invoice"})]})]}),i.length===0?e.jsx("p",{className:"text-sm text-cc-muted py-4 text-center",children:"No invoices yet"}):e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg border border-cc-border bg-cc-card group",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:t.invoiceNumber}),e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded ${te(t.status)}`,children:t.status})]}),e.jsxs("p",{className:"text-xs text-cc-muted mt-0.5",children:[t.clientName," · ",P(t.total,t.currency)," · Due ",new Date(t.dueDate).toLocaleDateString()]})]}),e.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[t.status!=="paid"&&e.jsx("button",{type:"button",onClick:()=>X(t.id),className:"text-xs px-2 py-1 rounded bg-green-500/20 text-green-400 hover:bg-green-500/30 transition-colors",title:"Mark as paid",children:"Paid"}),e.jsx("button",{type:"button",onClick:()=>Y(t.id),className:"text-cc-muted hover:text-red-400 p-1 transition-colors",title:"Delete invoice",children:e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]})]},t.id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Expenses"}),e.jsx("button",{type:"button",onClick:()=>L(!F),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 transition-colors",children:F?"Cancel":"+ Log Expense"})]}),F&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 mb-4 space-y-3",children:[e.jsx("input",{type:"text",value:m,onChange:t=>C(t.target.value),placeholder:"Description",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"number",value:g,onChange:t=>v(t.target.value),placeholder:"Amount",min:"0",step:"0.01",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"text",value:T,onChange:t=>$(t.target.value),placeholder:"Category (e.g. hosting, marketing)",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"})]}),e.jsx("input",{type:"text",value:j,onChange:t=>U(t.target.value),placeholder:"Vendor (optional)",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:Z,disabled:A||!m.trim()||!g,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:A?"Saving...":"Log Expense"})})]}),x.length===0?e.jsx("p",{className:"text-sm text-cc-muted py-4 text-center",children:"No expenses logged"}):e.jsx("div",{className:"space-y-2",children:x.map(t=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg border border-cc-border bg-cc-card group",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-cc-fg",children:t.description}),e.jsxs("p",{className:"text-xs text-cc-muted mt-0.5",children:[P(t.amount,t.currency)," · ",t.category,t.vendor&&e.jsxs(e.Fragment,{children:[" · ",t.vendor]})," ","· ",new Date(t.date).toLocaleDateString()]})]}),e.jsx("button",{type:"button",onClick:()=>ee(t.id),className:"text-cc-muted hover:text-red-400 p-1 opacity-0 group-hover:opacity-100 transition-all",title:"Delete expense",children:e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]},t.id))})]})]})}function ae(){const[s,a]=r.useState([]),[i,I]=r.useState(null),[x,K]=r.useState(!0),[E,b]=r.useState(""),[h,f]=r.useState(!1),[y,k]=r.useState(""),[u,V]=r.useState(""),[d,w]=r.useState(""),[D,_]=r.useState(""),[R,q]=r.useState("higher_is_better"),[F,L]=r.useState(!1),[m,C]=r.useState(null),[g,v]=r.useState(""),[T,$]=r.useState(!1),j=r.useCallback(async()=>{K(!0),b("");try{const c=await H.dashboard();a(c.kpis),I(c.summary)}catch(c){b(c instanceof Error?c.message:"Failed to load KPI data")}K(!1)},[]);r.useEffect(()=>{j()},[j]);const U=async()=>{if(!(!y.trim()||!u.trim()||!d.trim())){L(!0);try{await H.define({name:y.trim(),unit:u.trim(),category:d.trim(),target:D?parseFloat(D):void 0,direction:R}),f(!1),k(""),V(""),w(""),_(""),q("higher_is_better"),j()}catch(c){b(c instanceof Error?c.message:"Failed to define KPI")}L(!1)}},A=async()=>{if(!(!m||!g)){$(!0);try{await H.record(m,parseFloat(g)),C(null),v(""),j()}catch(c){b(c instanceof Error?c.message:"Failed to record value")}$(!1)}},W=async c=>{try{await H.delete(c),a(p=>p.filter(M=>M.id!==c))}catch{}};return x?e.jsx("p",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading KPI data..."}):E&&!i?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-sm text-red-400",children:E}),e.jsx("button",{type:"button",onClick:j,className:"mt-2 text-xs text-cc-accent hover:underline",children:"Retry"})]}):e.jsxs("div",{className:"space-y-6",children:[E&&e.jsxs("div",{className:"px-3 py-2 rounded-md bg-red-500/10 border border-red-500/20 text-sm text-red-400",children:[E,e.jsx("button",{type:"button",onClick:()=>b(""),className:"ml-2 text-xs underline",children:"dismiss"})]}),i&&e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-green-400",children:i.onTarget}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"On Target"})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-yellow-400",children:i.warning}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Warning"})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-red-400",children:i.critical}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Critical"})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-cc-muted",children:i.noData}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"No Data"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"KPIs"}),e.jsx("button",{type:"button",onClick:()=>f(!h),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 transition-colors",children:h?"Cancel":"+ Define KPI"})]}),h&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 mb-4 space-y-3",children:[e.jsx("input",{type:"text",value:y,onChange:c=>k(c.target.value),placeholder:"KPI Name (e.g. Monthly Revenue)",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"text",value:u,onChange:c=>V(c.target.value),placeholder:"Unit (e.g. EUR, %, users)",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"text",value:d,onChange:c=>w(c.target.value),placeholder:"Category (e.g. finance, growth)",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"number",value:D,onChange:c=>_(c.target.value),placeholder:"Target (optional)",min:"0",step:"any",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("select",{value:R,onChange:c=>q(c.target.value),className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg focus:outline-none focus:ring-1 focus:ring-cc-accent",children:[e.jsx("option",{value:"higher_is_better",children:"Higher is better"}),e.jsx("option",{value:"lower_is_better",children:"Lower is better"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:U,disabled:F||!y.trim()||!u.trim()||!d.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:F?"Saving...":"Define KPI"})})]})]}),s.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-sm text-cc-muted",children:"No KPIs defined yet"}),e.jsx("p",{className:"text-xs text-cc-muted/70 mt-1",children:'Click "Define KPI" to create your first metric.'})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:s.map(c=>{const p=se(c),M=re(c),z=p==="green"?"bg-green-500":p==="yellow"?"bg-yellow-500":p==="red"?"bg-red-500":"bg-cc-muted/30";return e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 group cursor-pointer hover:border-cc-accent/40 transition-colors",onClick:()=>{m!==c.id&&(C(c.id),v(""))},children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-cc-fg truncate",children:c.name}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:c.category})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-lg font-semibold ${J(c.trend,c.direction)}`,children:ce(c.trend)}),e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),W(c.id)},className:"text-cc-muted hover:text-red-400 p-0.5 opacity-0 group-hover:opacity-100 transition-all",title:"Delete KPI",children:e.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("span",{className:"text-2xl font-semibold text-cc-fg",children:c.currentValue!=null?c.currentValue:"--"}),e.jsx("span",{className:"text-xs text-cc-muted ml-1",children:c.unit}),c.trendPercent!=null&&e.jsxs("span",{className:`text-xs ml-2 ${J(c.trend,c.direction)}`,children:[c.trendPercent>0?"+":"",c.trendPercent.toFixed(1),"%"]})]}),c.target!=null&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex justify-between text-[10px] text-cc-muted mb-1",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{children:["Target: ",c.target," ",c.unit]})]}),e.jsx("div",{className:"w-full h-1.5 bg-cc-hover rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${z}`,style:{width:`${M}%`}})})]}),m===c.id&&e.jsx("div",{className:"mt-3 pt-3 border-t border-cc-border",onClick:l=>l.stopPropagation(),children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"number",value:g,onChange:l=>v(l.target.value),placeholder:`New value (${c.unit})`,step:"any",autoFocus:!0,className:"flex-1 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent",onKeyDown:l=>{l.key==="Enter"&&A(),l.key==="Escape"&&(C(null),v(""))}}),e.jsx("button",{type:"button",onClick:A,disabled:T||!g,className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:T?"...":"Record"}),e.jsx("button",{type:"button",onClick:()=>{C(null),v("")},className:"px-2 py-1.5 text-xs rounded-md text-cc-muted hover:text-cc-fg transition-colors",children:"Cancel"})]})})]},c.id)})})]})}function ie({embedded:s}){const[a,i]=r.useState("finance"),I=[{id:"finance",label:"Finance"},{id:"kpis",label:"KPIs"}];return e.jsxs("div",{className:"h-full flex flex-col overflow-hidden bg-cc-bg",children:[e.jsxs("div",{className:"border-b border-cc-border px-4 sm:px-8 pt-4 pb-0",children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Business"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Finance overview and KPI tracking."}),e.jsx("div",{className:"flex gap-1 mt-3",children:I.map(x=>e.jsx("button",{type:"button",onClick:()=>i(x.id),className:`px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors ${a===x.id?"bg-cc-bg text-cc-fg border border-cc-border border-b-cc-bg -mb-px":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:x.label},x.id))})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-6",children:[a==="finance"&&e.jsx(ne,{}),a==="kpis"&&e.jsx(ae,{})]})})]})}export{ie as BusinessPage};
1
+ import{r,j as e,f as N,k as H}from"./index-C6Q5UQHD.js";function P(s,a){try{return new Intl.NumberFormat(void 0,{style:"currency",currency:a}).format(s)}catch{return`${a} ${s.toFixed(2)}`}}function te(s){switch(s){case"draft":return"bg-gray-500/20 text-gray-400";case"sent":return"bg-blue-500/20 text-blue-400";case"paid":return"bg-green-500/20 text-green-400";case"overdue":return"bg-red-500/20 text-red-400";default:return"bg-cc-hover text-cc-muted"}}function ce(s){return s==="up"?"↑":s==="down"?"↓":"→"}function J(s,a){return!s||s==="stable"?"text-cc-muted":s==="up"&&a==="higher_is_better"||s==="down"&&a==="lower_is_better"?"text-green-400":"text-red-400"}function se(s){if(s.currentValue==null||s.target==null)return"gray";const a=s.direction==="lower_is_better"?s.target/s.currentValue:s.currentValue/s.target;return a>=.9?"green":a>=.7?"yellow":"red"}function re(s){if(s.currentValue==null||s.target==null||s.target===0)return 0;const a=s.direction==="lower_is_better"?s.target/Math.max(s.currentValue,.001)*100:s.currentValue/s.target*100;return Math.min(Math.max(a,0),100)}function ne(){const[s,a]=r.useState(null),[i,I]=r.useState([]),[x,K]=r.useState([]),[E,b]=r.useState(!0),[h,f]=r.useState(""),[y,k]=r.useState(!1),[u,V]=r.useState(""),[d,w]=r.useState([{description:"",quantity:1,unitPrice:0,total:0}]),[D,_]=r.useState(""),[R,q]=r.useState(!1),[F,L]=r.useState(!1),[m,C]=r.useState(""),[g,v]=r.useState(""),[T,$]=r.useState(""),[j,U]=r.useState(""),[A,W]=r.useState(!1),c=r.useCallback(async()=>{b(!0),f("");try{const[t,n,o]=await Promise.all([N.summary(),N.listInvoices(),N.listExpenses()]);a(t),I(n.invoices),K(o.expenses)}catch(t){f(t instanceof Error?t.message:"Failed to load finance data")}b(!1)},[]);r.useEffect(()=>{c()},[c]);const p=(t,n,o)=>{w(O=>{const Q=[...O],S={...Q[t]};if(n==="description")S.description=o;else{const G=parseFloat(o)||0;n==="quantity"&&(S.quantity=G),n==="unitPrice"&&(S.unitPrice=G)}return S.total=S.quantity*S.unitPrice,Q[t]=S,Q})},M=()=>{w(t=>[...t,{description:"",quantity:1,unitPrice:0,total:0}])},z=t=>{w(n=>n.length<=1?n:n.filter((o,O)=>O!==t))},l=async()=>{if(!(!u.trim()||d.every(t=>!t.description.trim()))){q(!0);try{const t=d.filter(n=>n.description.trim()).map(n=>({description:n.description,quantity:n.quantity,unitPrice:n.unitPrice,total:n.quantity*n.unitPrice}));await N.createInvoice({clientName:u.trim(),items:t,notes:D.trim()||void 0}),k(!1),V(""),w([{description:"",quantity:1,unitPrice:0,total:0}]),_(""),c()}catch(t){f(t instanceof Error?t.message:"Failed to create invoice")}q(!1)}},X=async t=>{try{await N.markPaid(t),c()}catch{}},Y=async t=>{try{await N.deleteInvoice(t),I(n=>n.filter(o=>o.id!==t))}catch{}},Z=async()=>{if(!(!m.trim()||!g)){W(!0);try{await N.logExpense({description:m.trim(),amount:parseFloat(g),category:T.trim()||"general",vendor:j.trim()||void 0}),L(!1),C(""),v(""),$(""),U(""),c()}catch(t){f(t instanceof Error?t.message:"Failed to log expense")}W(!1)}},ee=async t=>{try{await N.deleteExpense(t),K(n=>n.filter(o=>o.id!==t))}catch{}};if(E)return e.jsx("p",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading finance data..."});if(h&&!s)return e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-sm text-red-400",children:h}),e.jsx("button",{type:"button",onClick:c,className:"mt-2 text-xs text-cc-accent hover:underline",children:"Retry"})]});const B=(s==null?void 0:s.currency)||"EUR";return e.jsxs("div",{className:"space-y-6",children:[h&&e.jsxs("div",{className:"px-3 py-2 rounded-md bg-red-500/10 border border-red-500/20 text-sm text-red-400",children:[h,e.jsx("button",{type:"button",onClick:()=>f(""),className:"ml-2 text-xs underline",children:"dismiss"})]}),s&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("p",{className:"text-xs text-cc-muted uppercase tracking-wider",children:"Revenue"}),e.jsx("p",{className:"text-xl font-semibold text-green-400 mt-1",children:P(s.totalRevenue,B)})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("p",{className:"text-xs text-cc-muted uppercase tracking-wider",children:"Expenses"}),e.jsx("p",{className:"text-xl font-semibold text-red-400 mt-1",children:P(s.totalExpenses,B)})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("p",{className:"text-xs text-cc-muted uppercase tracking-wider",children:"Profit"}),e.jsx("p",{className:`text-xl font-semibold mt-1 ${s.netProfit>=0?"text-green-400":"text-red-400"}`,children:P(s.netProfit,B)})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Invoices"}),e.jsx("button",{type:"button",onClick:()=>k(!y),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 transition-colors",children:y?"Cancel":"+ New Invoice"})]}),y&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 mb-4 space-y-3",children:[e.jsx("input",{type:"text",value:u,onChange:t=>V(t.target.value),placeholder:"Client name",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-cc-muted font-medium",children:"Line items"}),d.map((t,n)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{type:"text",value:t.description,onChange:o=>p(n,"description",o.target.value),placeholder:"Description",className:"flex-1 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"number",value:t.quantity||"",onChange:o=>p(n,"quantity",o.target.value),placeholder:"Qty",min:"1",className:"w-16 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"number",value:t.unitPrice||"",onChange:o=>p(n,"unitPrice",o.target.value),placeholder:"Price",min:"0",step:"0.01",className:"w-24 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("span",{className:"text-xs text-cc-muted w-20 text-right",children:P(t.quantity*t.unitPrice,B)}),d.length>1&&e.jsx("button",{type:"button",onClick:()=>z(n),className:"text-cc-muted hover:text-red-400 p-1 transition-colors",children:e.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},n)),e.jsx("button",{type:"button",onClick:M,className:"text-xs text-cc-accent hover:underline",children:"+ Add item"})]}),e.jsx("textarea",{value:D,onChange:t=>_(t.target.value),placeholder:"Notes (optional)",rows:2,className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent resize-none"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm font-medium text-cc-fg",children:["Total: ",P(d.reduce((t,n)=>t+n.quantity*n.unitPrice,0),B)]}),e.jsx("button",{type:"button",onClick:l,disabled:R||!u.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:R?"Creating...":"Create Invoice"})]})]}),i.length===0?e.jsx("p",{className:"text-sm text-cc-muted py-4 text-center",children:"No invoices yet"}):e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg border border-cc-border bg-cc-card group",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:t.invoiceNumber}),e.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded ${te(t.status)}`,children:t.status})]}),e.jsxs("p",{className:"text-xs text-cc-muted mt-0.5",children:[t.clientName," · ",P(t.total,t.currency)," · Due ",new Date(t.dueDate).toLocaleDateString()]})]}),e.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[t.status!=="paid"&&e.jsx("button",{type:"button",onClick:()=>X(t.id),className:"text-xs px-2 py-1 rounded bg-green-500/20 text-green-400 hover:bg-green-500/30 transition-colors",title:"Mark as paid",children:"Paid"}),e.jsx("button",{type:"button",onClick:()=>Y(t.id),className:"text-cc-muted hover:text-red-400 p-1 transition-colors",title:"Delete invoice",children:e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]})]},t.id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Expenses"}),e.jsx("button",{type:"button",onClick:()=>L(!F),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 transition-colors",children:F?"Cancel":"+ Log Expense"})]}),F&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 mb-4 space-y-3",children:[e.jsx("input",{type:"text",value:m,onChange:t=>C(t.target.value),placeholder:"Description",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"number",value:g,onChange:t=>v(t.target.value),placeholder:"Amount",min:"0",step:"0.01",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"text",value:T,onChange:t=>$(t.target.value),placeholder:"Category (e.g. hosting, marketing)",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"})]}),e.jsx("input",{type:"text",value:j,onChange:t=>U(t.target.value),placeholder:"Vendor (optional)",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:Z,disabled:A||!m.trim()||!g,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:A?"Saving...":"Log Expense"})})]}),x.length===0?e.jsx("p",{className:"text-sm text-cc-muted py-4 text-center",children:"No expenses logged"}):e.jsx("div",{className:"space-y-2",children:x.map(t=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg border border-cc-border bg-cc-card group",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-cc-fg",children:t.description}),e.jsxs("p",{className:"text-xs text-cc-muted mt-0.5",children:[P(t.amount,t.currency)," · ",t.category,t.vendor&&e.jsxs(e.Fragment,{children:[" · ",t.vendor]})," ","· ",new Date(t.date).toLocaleDateString()]})]}),e.jsx("button",{type:"button",onClick:()=>ee(t.id),className:"text-cc-muted hover:text-red-400 p-1 opacity-0 group-hover:opacity-100 transition-all",title:"Delete expense",children:e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]},t.id))})]})]})}function ae(){const[s,a]=r.useState([]),[i,I]=r.useState(null),[x,K]=r.useState(!0),[E,b]=r.useState(""),[h,f]=r.useState(!1),[y,k]=r.useState(""),[u,V]=r.useState(""),[d,w]=r.useState(""),[D,_]=r.useState(""),[R,q]=r.useState("higher_is_better"),[F,L]=r.useState(!1),[m,C]=r.useState(null),[g,v]=r.useState(""),[T,$]=r.useState(!1),j=r.useCallback(async()=>{K(!0),b("");try{const c=await H.dashboard();a(c.kpis),I(c.summary)}catch(c){b(c instanceof Error?c.message:"Failed to load KPI data")}K(!1)},[]);r.useEffect(()=>{j()},[j]);const U=async()=>{if(!(!y.trim()||!u.trim()||!d.trim())){L(!0);try{await H.define({name:y.trim(),unit:u.trim(),category:d.trim(),target:D?parseFloat(D):void 0,direction:R}),f(!1),k(""),V(""),w(""),_(""),q("higher_is_better"),j()}catch(c){b(c instanceof Error?c.message:"Failed to define KPI")}L(!1)}},A=async()=>{if(!(!m||!g)){$(!0);try{await H.record(m,parseFloat(g)),C(null),v(""),j()}catch(c){b(c instanceof Error?c.message:"Failed to record value")}$(!1)}},W=async c=>{try{await H.delete(c),a(p=>p.filter(M=>M.id!==c))}catch{}};return x?e.jsx("p",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading KPI data..."}):E&&!i?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-sm text-red-400",children:E}),e.jsx("button",{type:"button",onClick:j,className:"mt-2 text-xs text-cc-accent hover:underline",children:"Retry"})]}):e.jsxs("div",{className:"space-y-6",children:[E&&e.jsxs("div",{className:"px-3 py-2 rounded-md bg-red-500/10 border border-red-500/20 text-sm text-red-400",children:[E,e.jsx("button",{type:"button",onClick:()=>b(""),className:"ml-2 text-xs underline",children:"dismiss"})]}),i&&e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-green-400",children:i.onTarget}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"On Target"})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-yellow-400",children:i.warning}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Warning"})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-red-400",children:i.critical}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Critical"})]}),e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 text-center",children:[e.jsx("p",{className:"text-2xl font-semibold text-cc-muted",children:i.noData}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"No Data"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"KPIs"}),e.jsx("button",{type:"button",onClick:()=>f(!h),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 transition-colors",children:h?"Cancel":"+ Define KPI"})]}),h&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 mb-4 space-y-3",children:[e.jsx("input",{type:"text",value:y,onChange:c=>k(c.target.value),placeholder:"KPI Name (e.g. Monthly Revenue)",className:"w-full px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"text",value:u,onChange:c=>V(c.target.value),placeholder:"Unit (e.g. EUR, %, users)",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsx("input",{type:"text",value:d,onChange:c=>w(c.target.value),placeholder:"Category (e.g. finance, growth)",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"number",value:D,onChange:c=>_(c.target.value),placeholder:"Target (optional)",min:"0",step:"any",className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent"}),e.jsxs("select",{value:R,onChange:c=>q(c.target.value),className:"px-3 py-2 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg focus:outline-none focus:ring-1 focus:ring-cc-accent",children:[e.jsx("option",{value:"higher_is_better",children:"Higher is better"}),e.jsx("option",{value:"lower_is_better",children:"Lower is better"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:U,disabled:F||!y.trim()||!u.trim()||!d.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:F?"Saving...":"Define KPI"})})]})]}),s.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-sm text-cc-muted",children:"No KPIs defined yet"}),e.jsx("p",{className:"text-xs text-cc-muted/70 mt-1",children:'Click "Define KPI" to create your first metric.'})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:s.map(c=>{const p=se(c),M=re(c),z=p==="green"?"bg-green-500":p==="yellow"?"bg-yellow-500":p==="red"?"bg-red-500":"bg-cc-muted/30";return e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 group cursor-pointer hover:border-cc-accent/40 transition-colors",onClick:()=>{m!==c.id&&(C(c.id),v(""))},children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-cc-fg truncate",children:c.name}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:c.category})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-lg font-semibold ${J(c.trend,c.direction)}`,children:ce(c.trend)}),e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),W(c.id)},className:"text-cc-muted hover:text-red-400 p-0.5 opacity-0 group-hover:opacity-100 transition-all",title:"Delete KPI",children:e.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("span",{className:"text-2xl font-semibold text-cc-fg",children:c.currentValue!=null?c.currentValue:"--"}),e.jsx("span",{className:"text-xs text-cc-muted ml-1",children:c.unit}),c.trendPercent!=null&&e.jsxs("span",{className:`text-xs ml-2 ${J(c.trend,c.direction)}`,children:[c.trendPercent>0?"+":"",c.trendPercent.toFixed(1),"%"]})]}),c.target!=null&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex justify-between text-[10px] text-cc-muted mb-1",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{children:["Target: ",c.target," ",c.unit]})]}),e.jsx("div",{className:"w-full h-1.5 bg-cc-hover rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${z}`,style:{width:`${M}%`}})})]}),m===c.id&&e.jsx("div",{className:"mt-3 pt-3 border-t border-cc-border",onClick:l=>l.stopPropagation(),children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"number",value:g,onChange:l=>v(l.target.value),placeholder:`New value (${c.unit})`,step:"any",autoFocus:!0,className:"flex-1 px-2 py-1.5 text-sm bg-cc-bg rounded-md border border-cc-border text-cc-fg placeholder:text-cc-muted/60 focus:outline-none focus:ring-1 focus:ring-cc-accent",onKeyDown:l=>{l.key==="Enter"&&A(),l.key==="Escape"&&(C(null),v(""))}}),e.jsx("button",{type:"button",onClick:A,disabled:T||!g,className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-40 transition-colors",children:T?"...":"Record"}),e.jsx("button",{type:"button",onClick:()=>{C(null),v("")},className:"px-2 py-1.5 text-xs rounded-md text-cc-muted hover:text-cc-fg transition-colors",children:"Cancel"})]})})]},c.id)})})]})}function ie({embedded:s}){const[a,i]=r.useState("finance"),I=[{id:"finance",label:"Finance"},{id:"kpis",label:"KPIs"}];return e.jsxs("div",{className:"h-full flex flex-col overflow-hidden bg-cc-bg",children:[e.jsxs("div",{className:"border-b border-cc-border px-4 sm:px-8 pt-4 pb-0",children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Business"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Finance overview and KPI tracking."}),e.jsx("div",{className:"flex gap-1 mt-3",children:I.map(x=>e.jsx("button",{type:"button",onClick:()=>i(x.id),className:`px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors ${a===x.id?"bg-cc-bg text-cc-fg border border-cc-border border-b-cc-bg -mb-px":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:x.label},x.id))})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-6",children:[a==="finance"&&e.jsx(ne,{}),a==="kpis"&&e.jsx(ae,{})]})})]})}export{ie as BusinessPage};