heyhank 0.1.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 (161) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -10
  3. package/bin/cli.ts +7 -7
  4. package/bin/ctl.ts +42 -42
  5. package/dist/assets/{AgentsPage-BPhirnCe.js → AgentsPage-DqjDAcIw.js} +3 -3
  6. package/dist/assets/AssistantPage-C50CQFSB.js +2 -0
  7. package/dist/assets/BusinessPage-AY70tf1k.js +1 -0
  8. package/dist/assets/{CronManager-DDbz-yiT.js → CronManager-Dt7LLuRr.js} +1 -1
  9. package/dist/assets/HelpPage-tlGx7fQF.js +1 -0
  10. package/dist/assets/{IntegrationsPage-CrOitCmJ.js → IntegrationsPage-B4XOuHXu.js} +1 -1
  11. package/dist/assets/JarvisHUD-BDvuRd0I.js +120 -0
  12. package/dist/assets/MediaPage-CofV9Rd-.js +1 -0
  13. package/dist/assets/MemoryPage-Cj7FeqmJ.js +1 -0
  14. package/dist/assets/{PlatformDashboard-Do6F0O2p.js → PlatformDashboard-B9kXAlH1.js} +1 -1
  15. package/dist/assets/{Playground-Fc5cdc5p.js → Playground-Cka-pRkP.js} +1 -1
  16. package/dist/assets/{ProcessPanel-CslEiZkI.js → ProcessPanel-BqhQgfYj.js} +1 -1
  17. package/dist/assets/{PromptsPage-D2EhsdNO.js → PromptsPage-VveKc9uX.js} +2 -2
  18. package/dist/assets/RunsPage-DXVEk0AZ.js +1 -0
  19. package/dist/assets/{SandboxManager-a1AVI5q2.js → SandboxManager-DACcwfDF.js} +1 -1
  20. package/dist/assets/SettingsPage-jfuQh8Tu.js +51 -0
  21. package/dist/assets/SkillsMarketplace-DrigiApe.js +1 -0
  22. package/dist/assets/SocialMediaPage-DOh3IPe8.js +10 -0
  23. package/dist/assets/{TailscalePage-CHiFhZXF.js → TailscalePage-DLhJWATT.js} +1 -1
  24. package/dist/assets/TelephonyPage-9C4C3_ot.js +9 -0
  25. package/dist/assets/{TerminalPage-Drwyrnfd.js → TerminalPage-ChX-8Wu7.js} +1 -1
  26. package/dist/assets/{gemini-live-client-C7rqAW7G.js → gemini-live-client-C70FEtX2.js} +11 -8
  27. package/dist/assets/index-C6Q5UQHD.js +229 -0
  28. package/dist/assets/index-ZxGXgiV3.css +32 -0
  29. package/dist/assets/sw-register-BBYuk-kw.js +1 -0
  30. package/dist/assets/text-chat-client-BSbLJerZ.js +2 -0
  31. package/dist/assets/workbox-window.prod.es5-BBnX5xw4.js +2 -0
  32. package/dist/index.html +2 -2
  33. package/dist/sw.js +1 -1
  34. package/dist/{workbox-d2a0910a.js → workbox-080c8b91.js} +1 -1
  35. package/package.json +6 -1
  36. package/server/agent-executor.ts +102 -2
  37. package/server/agent-store.ts +3 -3
  38. package/server/agent-types.ts +11 -0
  39. package/server/assistant-store.ts +232 -6
  40. package/server/auth-manager.ts +9 -0
  41. package/server/cache-headers.ts +1 -1
  42. package/server/calendar-service.ts +10 -0
  43. package/server/ceo/document-store.ts +129 -0
  44. package/server/ceo/finance-store.ts +343 -0
  45. package/server/ceo/kpi-store.ts +208 -0
  46. package/server/ceo/memory-import.ts +277 -0
  47. package/server/ceo/news-store.ts +208 -0
  48. package/server/ceo/template-store.ts +134 -0
  49. package/server/ceo/time-tracking-store.ts +227 -0
  50. package/server/claude-auth-monitor.ts +128 -0
  51. package/server/claude-code-worker.ts +86 -0
  52. package/server/claude-session-discovery.ts +74 -1
  53. package/server/cli-launcher.ts +32 -10
  54. package/server/codex-adapter.ts +2 -2
  55. package/server/codex-ws-proxy.cjs +1 -1
  56. package/server/container-manager.ts +4 -4
  57. package/server/content-intelligence/content-engine.ts +1112 -0
  58. package/server/content-intelligence/platform-knowledge.ts +870 -0
  59. package/server/cron-store.ts +3 -3
  60. package/server/embedding-service.ts +49 -0
  61. package/server/event-bus-types.ts +13 -0
  62. package/server/execution-store.ts +54 -1
  63. package/server/federation/node-store.ts +5 -4
  64. package/server/fs-utils.ts +28 -1
  65. package/server/hank-notifications-store.ts +91 -0
  66. package/server/hank-tool-executor.ts +1835 -0
  67. package/server/hank-tools.ts +2107 -0
  68. package/server/image-pull-manager.ts +2 -2
  69. package/server/index.ts +25 -2
  70. package/server/llm-providers-streaming.ts +541 -0
  71. package/server/llm-providers.ts +12 -0
  72. package/server/marketplace.ts +249 -0
  73. package/server/mcp-registry.ts +158 -0
  74. package/server/memory-service.ts +296 -0
  75. package/server/obsidian-sync.ts +184 -0
  76. package/server/provider-manager.ts +5 -2
  77. package/server/provider-registry.ts +12 -0
  78. package/server/reminder-scheduler.ts +37 -1
  79. package/server/routes/agent-routes.ts +44 -1
  80. package/server/routes/assistant-routes.ts +198 -5
  81. package/server/routes/ceo-finance-kpi-routes.ts +167 -0
  82. package/server/routes/ceo-news-time-routes.ts +137 -0
  83. package/server/routes/ceo-routes.ts +99 -0
  84. package/server/routes/content-routes.ts +116 -0
  85. package/server/routes/email-routes.ts +147 -0
  86. package/server/routes/env-routes.ts +3 -3
  87. package/server/routes/fs-routes.ts +12 -9
  88. package/server/routes/hank-chat-routes.ts +592 -0
  89. package/server/routes/llm-routes.ts +12 -0
  90. package/server/routes/marketplace-routes.ts +63 -0
  91. package/server/routes/media-routes.ts +1 -1
  92. package/server/routes/memory-routes.ts +127 -0
  93. package/server/routes/platform-routes.ts +14 -675
  94. package/server/routes/sandbox-routes.ts +1 -1
  95. package/server/routes/settings-routes.ts +51 -1
  96. package/server/routes/socialmedia-routes.ts +152 -2
  97. package/server/routes/system-routes.ts +2 -2
  98. package/server/routes/team-routes.ts +71 -0
  99. package/server/routes/telephony-routes.ts +98 -18
  100. package/server/routes.ts +36 -9
  101. package/server/session-creation-service.ts +2 -2
  102. package/server/session-orchestrator.ts +54 -2
  103. package/server/session-types.ts +2 -0
  104. package/server/settings-manager.ts +50 -2
  105. package/server/skill-discovery.ts +68 -0
  106. package/server/socialmedia/adapters/browser-adapter.ts +179 -0
  107. package/server/socialmedia/adapters/postiz-adapter.ts +291 -14
  108. package/server/socialmedia/manager.ts +234 -15
  109. package/server/socialmedia/store.ts +51 -1
  110. package/server/socialmedia/types.ts +35 -2
  111. package/server/socialview/browser-manager.ts +150 -0
  112. package/server/socialview/extractors.ts +1298 -0
  113. package/server/socialview/image-describe.ts +188 -0
  114. package/server/socialview/library.ts +119 -0
  115. package/server/socialview/poster.ts +276 -0
  116. package/server/socialview/routes.ts +371 -0
  117. package/server/socialview/style-analyzer.ts +187 -0
  118. package/server/socialview/style-profiles.ts +67 -0
  119. package/server/socialview/types.ts +166 -0
  120. package/server/socialview/vision.ts +127 -0
  121. package/server/socialview/vnc-manager.ts +110 -0
  122. package/server/style-injector.ts +135 -0
  123. package/server/team-service.ts +239 -0
  124. package/server/team-store.ts +75 -0
  125. package/server/team-types.ts +52 -0
  126. package/server/telephony/audio-bridge.ts +281 -35
  127. package/server/telephony/audio-recorder.ts +132 -0
  128. package/server/telephony/call-manager.ts +803 -104
  129. package/server/telephony/call-types.ts +67 -1
  130. package/server/telephony/esl-client.ts +319 -0
  131. package/server/telephony/freeswitch-sync.ts +155 -0
  132. package/server/telephony/phone-utils.ts +63 -0
  133. package/server/telephony/telephony-store.ts +9 -8
  134. package/server/url-validator.ts +82 -0
  135. package/server/vault-markdown.ts +317 -0
  136. package/server/vault-migration.ts +121 -0
  137. package/server/vault-store.ts +466 -0
  138. package/server/vault-watcher.ts +59 -0
  139. package/server/vector-store.ts +210 -0
  140. package/server/voice-pipeline/gemini-live-adapter.ts +97 -0
  141. package/server/voice-pipeline/greeting-cache.ts +200 -0
  142. package/server/voice-pipeline/manager.ts +249 -0
  143. package/server/voice-pipeline/pipeline.ts +335 -0
  144. package/server/voice-pipeline/providers/index.ts +47 -0
  145. package/server/voice-pipeline/providers/llm-internal.ts +527 -0
  146. package/server/voice-pipeline/providers/stt-google.ts +157 -0
  147. package/server/voice-pipeline/providers/tts-google.ts +126 -0
  148. package/server/voice-pipeline/types.ts +247 -0
  149. package/server/ws-bridge-types.ts +6 -1
  150. package/dist/assets/AssistantPage-DJ-cMQfb.js +0 -1
  151. package/dist/assets/HelpPage-DMfkzERp.js +0 -1
  152. package/dist/assets/MediaPage-CE5rdvkC.js +0 -1
  153. package/dist/assets/RunsPage-C5BZF5Rx.js +0 -1
  154. package/dist/assets/SettingsPage-DirhjQrJ.js +0 -51
  155. package/dist/assets/SocialMediaPage-DBuM28vD.js +0 -1
  156. package/dist/assets/TelephonyPage-x0VV0fOo.js +0 -1
  157. package/dist/assets/index-C8M_PUmX.css +0 -32
  158. package/dist/assets/index-CEqZnThB.js +0 -204
  159. package/dist/assets/sw-register-LSSpj6RU.js +0 -1
  160. package/dist/assets/workbox-window.prod.es5-BIl4cyR9.js +0 -2
  161. package/server/socialmedia/adapters/ayrshare-adapter.ts +0 -169
@@ -0,0 +1,51 @@
1
+ import{r as s,b as o,j as e,u as k,n as Is,a as Ts}from"./index-C6Q5UQHD.js";import{unsubscribeFromPush as Os,subscribeToPush as Ls}from"./sw-register-BBYuk-kw.js";function Rs(){const[a,f]=s.useState(null),[C,v]=s.useState(""),[m,x]=s.useState([]),[p,b]=s.useState([]),[g,A]=s.useState(!0),[j,d]=s.useState(!1),[y,T]=s.useState(""),[M,R]=s.useState(""),[F,i]=s.useState(""),[E,V]=s.useState(""),[$,z]=s.useState(""),G=s.useCallback(async()=>{try{const[r,h,se]=await Promise.all([o.getFederationIdentity(),o.getFederationNodes(),o.getFederationRemoteSessions()]);f(r),v(r.name),x(h.nodes),b(se.sessions)}catch{}A(!1)},[]);s.useEffect(()=>{G()},[G]),s.useEffect(()=>{const r=setInterval(G,1e4);return()=>clearInterval(r)},[G]);const L=(r,h=!1)=>{h?(T(r),R("")):(R(r),T("")),setTimeout(()=>{T(""),R("")},4e3)},le=async()=>{if(C.trim()){d(!0);try{await o.updateFederationIdentity(C.trim()),L("Node name saved")}catch(r){L(r instanceof Error?r.message:"Failed to save",!0)}d(!1)}},de=async()=>{if(!F.trim()||!E.trim()){L("URL and shared secret are required",!0);return}d(!0);try{await o.addFederationNode({url:F.trim(),secret:E.trim(),name:$.trim()}),i(""),V(""),z(""),L("Node added, connecting..."),setTimeout(G,2e3)}catch(r){L(r instanceof Error?r.message:"Failed to add node",!0)}d(!1)},ye=async r=>{try{await o.removeFederationNode(r),L("Node removed"),G()}catch(h){L(h instanceof Error?h.message:"Failed to remove",!0)}},ue=async r=>{try{const h=await o.testFederationNode(r);L(h.connected?"Connection OK":"Not connected")}catch(h){L(h instanceof Error?h.message:"Test failed",!0)}};return g?e.jsx("div",{className:"text-sm text-cc-muted",children:"Loading federation..."}):e.jsxs("div",{className:"space-y-5",children:[y&&e.jsx("div",{className:"text-sm text-cc-error bg-cc-error/5 border border-cc-error/20 rounded-lg px-3 py-2",children:y}),M&&e.jsx("div",{className:"text-sm text-cc-success bg-cc-success/5 border border-cc-success/20 rounded-lg px-3 py-2",children:M}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider mb-2",children:"This Node"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:C,onChange:r=>v(r.target.value),onKeyDown:r=>r.key==="Enter"&&le(),placeholder:"Node name",className:"flex-1 px-3 py-2 text-sm rounded-lg bg-cc-hover border border-cc-border text-cc-fg outline-none focus:border-cc-primary/50"}),e.jsx("button",{onClick:le,disabled:j,className:"px-3 py-2 text-sm rounded-lg bg-cc-hover border border-cc-border text-cc-fg hover:bg-cc-active transition-colors cursor-pointer disabled:opacity-50",children:"Save"})]}),a&&e.jsxs("p",{className:"text-[10px] text-cc-muted/60 font-mono mt-1 break-all",children:["ID: ",a.nodeId]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider mb-2",children:"Add Node"}),e.jsx("p",{className:"text-xs text-cc-muted mb-2",children:"Enter the URL and shared secret of a remote HeyHank instance."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{type:"url",value:F,onChange:r=>i(r.target.value),placeholder:"https://other-hank.example.com",className:"w-full px-3 py-2 text-sm rounded-lg bg-cc-hover border border-cc-border text-cc-fg outline-none focus:border-cc-primary/50"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:E,onChange:r=>V(r.target.value),placeholder:"Shared secret",className:"flex-1 px-3 py-2 text-sm rounded-lg bg-cc-hover border border-cc-border text-cc-fg outline-none focus:border-cc-primary/50"}),e.jsx("input",{type:"text",value:$,onChange:r=>z(r.target.value),placeholder:"Name (optional)",className:"flex-1 px-3 py-2 text-sm rounded-lg bg-cc-hover border border-cc-border text-cc-fg outline-none focus:border-cc-primary/50"})]}),e.jsx("button",{onClick:de,disabled:j,className:"w-full px-3 py-2.5 text-sm font-medium rounded-lg bg-cc-primary/10 border border-cc-primary/30 text-cc-primary hover:bg-cc-primary/15 transition-colors cursor-pointer disabled:opacity-50",children:"Connect Node"})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Connected Nodes (",m.length,")"]}),m.length===0?e.jsx("p",{className:"text-xs text-cc-muted/50",children:"No nodes configured."}):e.jsx("div",{className:"space-y-2",children:m.map(r=>e.jsxs("div",{className:"border border-cc-border/60 rounded-lg p-3 bg-cc-card/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("span",{className:"text-sm font-medium text-cc-fg flex items-center gap-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${r.connected?"bg-cc-success shadow-[0_0_6px_rgba(74,222,128,0.4)]":"bg-cc-error/60"}`}),r.remoteName||r.name||"Unknown"]}),e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[r.connected?"Connected":"Offline"," · ",r.sessionCount," sessions"]})]}),e.jsx("p",{className:"text-[10px] text-cc-muted/60 break-all mb-2",children:r.url}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>ue(r.id),className:"px-2 py-1 text-[11px] rounded bg-cc-hover border border-cc-border text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:"Test"}),e.jsx("button",{onClick:()=>ye(r.id),className:"px-2 py-1 text-[11px] rounded bg-cc-hover border border-cc-error/20 text-cc-error hover:bg-cc-error/5 transition-colors cursor-pointer",children:"Remove"})]})]},r.id))})]}),p.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider mb-2",children:["Remote Sessions (",p.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:p.map(r=>e.jsxs("div",{className:"border border-cc-border/40 rounded-lg px-3 py-2 bg-cc-card/30",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-medium text-cc-fg truncate",children:r.name||r.sessionId.slice(0,8)}),e.jsx("span",{className:"text-[9px] font-semibold px-1.5 py-0.5 rounded bg-cc-primary/15 text-cc-primary leading-none shrink-0",children:r.nodeName})]}),e.jsxs("p",{className:"text-[10px] text-cc-muted/60 truncate mt-0.5",children:[r.model||""," · ",r.cwd||r.sessionId]})]},`${r.nodeId}:${r.sessionId}`))})]})]})}const Fs={cloud:"Cloud Providers",gateway:"Gateways & Proxies",local:"Local / Self-Hosted",custom:"Custom"},Vs=["cloud","gateway","local","custom"];function $s(){const[a,f]=s.useState([]),[C,v]=s.useState(!0),[m,x]=s.useState(null),[p,b]=s.useState(""),g=s.useCallback(()=>{o.getProviders().then(f).catch(()=>{}).finally(()=>v(!1))},[]);if(s.useEffect(()=>{g()},[g]),C)return e.jsx("p",{className:"text-xs text-cc-muted",children:"Loading providers..."});const A=p?a.filter(d=>d.name.toLowerCase().includes(p.toLowerCase())||d.description.toLowerCase().includes(p.toLowerCase())):a,j=Vs.map(d=>({category:d,label:Fs[d]||d,items:A.filter(y=>y.category===d)})).filter(d=>d.items.length>0);return e.jsxs("div",{className:"space-y-4",children:[a.length>10&&e.jsx("input",{type:"text",value:p,onChange:d=>b(d.target.value),placeholder:"Search providers...",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"}),j.map(d=>e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-medium text-cc-muted uppercase tracking-wide mb-2",children:d.label}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:d.items.map(y=>e.jsx(Ks,{provider:y,expanded:m===y.id,onToggle:()=>x(m===y.id?null:y.id),onUpdate:g},y.id))})]},d.category))]})}function Ks({provider:a,expanded:f,onToggle:C,onUpdate:v}){const[m,x]=s.useState({}),[p,b]=s.useState(!1),[g,A]=s.useState(!1),[j,d]=s.useState(""),[y,T]=s.useState(!1);s.useEffect(()=>{f&&!y&&o.getProvider(a.id).then(i=>{var V;const E={};for(const $ of a.envFields)!$.secret&&((V=i.envValues)!=null&&V[$.key])&&(E[$.key]=i.envValues[$.key]);x(E),T(!0)}).catch(()=>{})},[f,y,a.id,a.envFields]);const M=async()=>{b(!0),d(""),A(!1);try{const i={};for(const[E,V]of Object.entries(m))V.trim()&&(i[E]=V.trim());await o.updateProvider(a.id,{enabled:!0,envValues:i}),A(!0),setTimeout(()=>A(!1),2e3),x({}),T(!1),v()}catch(i){d(i instanceof Error?i.message:String(i))}finally{b(!1)}},R=async()=>{try{await o.deleteProvider(a.id),x({}),T(!1),v()}catch{}},F=async()=>{try{await o.updateProvider(a.id,{enabled:!a.enabled}),v()}catch{}};return e.jsxs("div",{className:`rounded-lg border transition-colors ${a.configured&&a.enabled?"border-cc-success/30 bg-cc-success/5":a.configured?"border-cc-warning/30 bg-cc-warning/5":"border-cc-border bg-cc-bg"}`,children:[e.jsxs("button",{type:"button",onClick:C,className:"w-full flex items-center justify-between px-3 py-2.5 cursor-pointer text-left",children:[e.jsxs("div",{className:"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:a.name}),a.configured&&a.enabled&&e.jsx("span",{className:"shrink-0 w-1.5 h-1.5 rounded-full bg-cc-success"}),a.configured&&!a.enabled&&e.jsx("span",{className:"shrink-0 w-1.5 h-1.5 rounded-full bg-cc-warning"})]}),e.jsx("p",{className:"text-[11px] text-cc-muted truncate",children:a.description})]}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`shrink-0 w-3.5 h-3.5 text-cc-muted transition-transform ${f?"rotate-180":""}`,children:e.jsx("path",{fillRule:"evenodd",d:"M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z"})})]}),f&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-cc-border/50 pt-3",children:[a.envFields.map(i=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"block text-xs text-cc-muted",htmlFor:`prov-${a.id}-${i.key}`,children:[i.label,i.required&&e.jsx("span",{className:"text-cc-error ml-0.5",children:"*"}),a.envConfigured[i.key]&&i.secret&&e.jsx("span",{className:"ml-1 text-cc-success",children:"(configured)"})]}),e.jsx("input",{id:`prov-${a.id}-${i.key}`,type:i.secret?"password":"text",value:m[i.key]??"",onChange:E=>x({...m,[i.key]:E.target.value}),placeholder:a.envConfigured[i.key]&&i.secret?"Enter new value to replace":i.placeholder||"",className:"w-full px-2.5 py-1.5 text-sm bg-cc-input-bg rounded-md text-cc-fg placeholder:text-cc-muted/50 focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]},i.key)),a.docsUrl&&e.jsxs("a",{href:a.docsUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-cc-primary hover:underline",children:["Documentation",e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M3.75 2a.75.75 0 0 0 0 1.5h5.69L2.22 10.72a.75.75 0 1 0 1.06 1.06L10.5 4.56v5.69a.75.75 0 0 0 1.5 0V2.75a.75.75 0 0 0-.75-.75H3.75Z"})})]}),j&&e.jsx("p",{className:"text-xs text-cc-error",children:j}),g&&e.jsx("p",{className:"text-xs text-cc-success",children:"Saved!"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:M,disabled:p||Object.values(m).every(i=>!i.trim()),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${p||Object.values(m).every(i=>!i.trim())?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white cursor-pointer"}`,children:p?"Saving...":"Save"}),a.configured&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:F,className:"px-3 py-1.5 rounded-md text-xs font-medium bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:a.enabled?"Disable":"Enable"}),e.jsx("button",{type:"button",onClick:R,className:"px-3 py-1.5 rounded-md text-xs font-medium text-cc-error hover:bg-cc-error/10 transition-colors cursor-pointer",children:"Remove"})]})]})]})]})}const ct=[{id:"general",label:"General"},{id:"connectivity",label:"Connectivity"},{id:"authentication",label:"Authentication"},{id:"notifications",label:"Notifications"},{id:"providers",label:"Providers"},{id:"gemini",label:"Gemini"},{id:"hank-chat",label:"Hank Chat"},{id:"email",label:"Email"},{id:"calendar",label:"Calendar"},{id:"updates",label:"Updates"},{id:"appearance",label:"Appearance"},{id:"environments",label:"Environments"},{id:"federation",label:"Federation"},{id:"backup",label:"Backup"}];function Ds(){const[a,f]=s.useState(!1),[C,v]=s.useState(!0);s.useEffect(()=>{(async()=>{var x;try{const p=await((x=navigator.serviceWorker)==null?void 0:x.ready);if(p){const b=await p.pushManager.getSubscription();f(!!b)}}catch{}v(!1)})()},[]);const m=async()=>{v(!0);try{if(a)await Os(),f(!1);else{if(Notification.permission!=="granted"&&await Notification.requestPermission()!=="granted"){v(!1);return}const x=await Ls();f(!!x)}}catch(x){console.error("[push] Toggle failed:",x)}v(!1)};return typeof Notification>"u"||!("serviceWorker"in navigator)?null:e.jsxs("button",{type:"button",onClick:m,disabled:C,className:"w-full flex items-center justify-between px-3 py-3 min-h-[44px] rounded-lg text-sm bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer disabled:opacity-50",children:[e.jsx("span",{children:"Push Notifications (Agent Alerts)"}),e.jsx("span",{className:"text-xs text-cc-muted",children:C?"...":a?"On":"Off"})]})}function I({id:a,title:f,status:C,defaultOpen:v=!1,forceOpen:m,sectionRef:x,children:p}){const[b,g]=s.useState(()=>{const j=localStorage.getItem(`settings-section-${a}`);return j!==null?j==="true":v});s.useEffect(()=>{m&&(g(!0),localStorage.setItem(`settings-section-${a}`,"true"))},[m,a]);const A=()=>{const j=!b;g(j),localStorage.setItem(`settings-section-${a}`,String(j))};return e.jsxs("section",{id:a,ref:x,children:[e.jsxs("button",{type:"button",onClick:A,className:"w-full flex items-center gap-2 group cursor-pointer mb-2 py-1 -mx-1 px-1 rounded-lg hover:bg-cc-hover/50 transition-colors","aria-expanded":b,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 text-cc-muted transition-transform duration-150 ${b?"rotate-90":""}`,children:e.jsx("path",{d:"M6 4l4 4-4 4"})}),e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:f}),!b&&C&&e.jsx("span",{className:"text-[11px] text-cc-muted ml-auto",children:C})]}),b&&e.jsx("div",{className:"space-y-3 ml-0.5",children:p})]})}function Js({embedded:a=!1}){const[f,C]=s.useState(""),[v,m]=s.useState("claude-sonnet-4-6"),[x,p]=s.useState(!1),[b,g]=s.useState(!1),[A,j]=s.useState(!1),[d,y]=s.useState(!1),[T,M]=s.useState(!0),[R,F]=s.useState(!1),[i,E]=s.useState(""),[V,$]=s.useState(!1),z=k(t=>t.darkMode),G=k(t=>t.toggleDarkMode),L=k(t=>t.diffBase),le=k(t=>t.setDiffBase),de=k(t=>t.notificationSound),ye=k(t=>t.toggleNotificationSound),ue=k(t=>t.notificationDesktop),r=k(t=>t.setNotificationDesktop),h=k(t=>t.updateInfo),se=k(t=>t.setUpdateInfo),ss=k(t=>t.setUpdateOverlayActive),cs=k(t=>t.setEditorTabEnabled),as=typeof Notification<"u",[W,ce]=s.useState("stable"),[me,je]=s.useState(!1),[Ne,at]=s.useState(!1),[ke,rt]=s.useState(!1),[nt,ae]=s.useState(""),[ot,xe]=s.useState(""),[_,we]=s.useState("gemini-live"),[it,lt]=s.useState(""),[Se,Ce]=s.useState(!0),[pe,Ae]=s.useState(!1),[Ee,Pe]=s.useState(!0),[Ue,Ie]=s.useState(!1),[J,Te]=s.useState(""),[dt,ut]=s.useState("general"),[P,mt]=s.useState(null),[Gs,_s]=s.useState(!1),[Bs,zs]=s.useState(!1),[Ws,Ys]=s.useState(null),[Z,xt]=s.useState(""),[he,pt]=s.useState(!1),[X,ht]=s.useState(""),[re,gt]=s.useState(!1),[Oe,ft]=s.useState(!1),[rs,Le]=s.useState(!1),[bt,vt]=s.useState(""),[ns,yt]=s.useState(!1),[os,jt]=s.useState(!1),[l,Nt]=s.useState(null),[u,kt]=s.useState(null),[ne,wt]=s.useState(""),[ee,St]=s.useState(!1),[Re,Fe]=s.useState("Kore"),[is,Ct]=s.useState("Kore"),[Ve,$e]=s.useState(""),[ls,At]=s.useState(""),[Ke,De]=s.useState(""),[ds,Et]=s.useState(""),[us,Pt]=s.useState(!1),[He,Ut]=s.useState(!1),[ms,Me]=s.useState(!1),[It,Tt]=s.useState(""),[ge,xs]=s.useState([]),[ps,Ot]=s.useState(!1),[Lt,Ge]=s.useState(""),[Rt,Ft]=s.useState(""),[K,Vt]=s.useState(null),[hs,_e]=s.useState(!1),[N,O]=s.useState({name:"",email:"",imapHost:"",imapPort:"993",imapSecure:!0,smtpHost:"",smtpPort:"465",smtpSecure:!0,authUser:"",authPass:""}),[$t,Kt]=s.useState(null),[oe,Be]=s.useState(null),[fe,gs]=s.useState([]),[fs,Dt]=s.useState(!1),[Ht,be]=s.useState(""),[Mt,Gt]=s.useState(""),[Y,_t]=s.useState(null),[Bt,ze]=s.useState(!1),[w,q]=s.useState({name:"",provider:"google",serverUrl:"",authUser:"",authPass:""}),[zt,Wt]=s.useState(null),[Q,We]=s.useState(null),[te,Yt]=s.useState(null),[Ye,qt]=s.useState(!1),[H,Qt]=s.useState(null),[ve,bs]=s.useState(0),[qe,Jt]=s.useState(!1),[Qe,Zt]=s.useState(!1),[vs,Xt]=s.useState(!1),es=s.useRef(null),Je=s.useRef({});s.useEffect(()=>{const t=es.current;if(!t)return;const c=new IntersectionObserver(n=>{var D;let S=null;for(const ie of n)ie.isIntersecting&&(!S||ie.boundingClientRect.top<S.boundingClientRect.top)&&(S=ie);(D=S==null?void 0:S.target)!=null&&D.id&&ut(S.target.id)},{root:t,rootMargin:"-10% 0px -70% 0px",threshold:0});for(const n of ct){const S=Je.current[n.id];S&&c.observe(S)}return()=>c.disconnect()},[T]);const ts=s.useCallback(t=>{ut(t),mt(t),setTimeout(()=>mt(null),100),requestAnimationFrame(()=>{const c=Je.current[t];c&&c.scrollIntoView({behavior:"smooth",block:"start"})})},[]);s.useEffect(()=>{o.getSettings().then(t=>{g(t.anthropicApiKeyConfigured),j(t.anthropicApiKeyConfigured),typeof t.openrouterApiKeyConfigured=="boolean"&&y(t.openrouterApiKeyConfigured),o.getProviders().then(c=>{c.some(n=>n.configured&&n.enabled)&&g(!0)}).catch(()=>{}),pt(t.claudeCodeOAuthTokenConfigured),gt(t.openaiApiKeyConfigured),t.claudeCliAuth&&Nt(t.claudeCliAuth),t.codexCliAuth&&kt(t.codexCliAuth),St(t.geminiApiKeyConfigured),t.geminiVoice&&(Fe(t.geminiVoice),Ct(t.geminiVoice)),typeof t.assistantName=="string"&&($e(t.assistantName),At(t.assistantName)),typeof t.userName=="string"&&(De(t.userName),Et(t.userName)),m(t.anthropicModel||"claude-sonnet-4-6"),p(t.editorTabEnabled),cs(t.editorTabEnabled),typeof t.aiValidationEnabled=="boolean"&&Ae(t.aiValidationEnabled),typeof t.aiValidationAutoApprove=="boolean"&&Pe(t.aiValidationAutoApprove),typeof t.aiValidationAutoDeny=="boolean"&&Ie(t.aiValidationAutoDeny),typeof t.hankChatProvider=="string"&&we(t.hankChatProvider),typeof t.hankChatModel=="string"&&lt(t.hankChatModel),typeof t.hankChatAvatarEnabled=="boolean"&&Ce(t.hankChatAvatarEnabled),(t.updateChannel==="stable"||t.updateChannel==="prerelease")&&ce(t.updateChannel),typeof t.dockerAutoUpdate=="boolean"&&je(t.dockerAutoUpdate),typeof t.publicUrl=="string"&&(Te(t.publicUrl),k.getState().setPublicUrl(t.publicUrl))}).catch(t=>E(t instanceof Error?t.message:String(t))).finally(()=>M(!1)),o.getAuthToken().then(t=>Yt(t.token)).catch(()=>{}),Ze(),et()},[]);function Ze(){Ot(!0),fetch("/api/email-accounts",{headers:{...B()}}).then(t=>t.json()).then(t=>xs(t)).catch(()=>{}).finally(()=>Ot(!1))}function B(){const t=localStorage.getItem("auth_token")||sessionStorage.getItem("auth_token");return t?{Authorization:`Bearer ${t}`}:{}}function Xe(){O({name:"",email:"",imapHost:"",imapPort:"993",imapSecure:!0,smtpHost:"",smtpPort:"465",smtpSecure:!0,authUser:"",authPass:""}),Vt(null),_e(!1)}async function ys(){Ge("");const t={name:N.name.trim(),email:N.email.trim(),imap:{host:N.imapHost.trim(),port:parseInt(N.imapPort)||993,secure:N.imapSecure},smtp:{host:N.smtpHost.trim(),port:parseInt(N.smtpPort)||465,secure:N.smtpSecure},auth:{user:N.authUser.trim(),pass:N.authPass}};if(!t.name||!t.email||!t.imap.host||!t.smtp.host||!t.auth.user||!t.auth.pass){Ge("All fields are required.");return}try{const c=K?`/api/email-accounts/${K.id}`:"/api/email-accounts",S=await fetch(c,{method:K?"PUT":"POST",headers:{"Content-Type":"application/json",...B()},body:JSON.stringify(t)});if(!S.ok){const D=await S.json().catch(()=>({}));throw new Error(D.error||"Failed")}Ft(K?"Account updated.":"Account added."),setTimeout(()=>Ft(""),2e3),Xe(),Ze()}catch(c){Ge(c instanceof Error?c.message:String(c))}}async function js(t){if(confirm("Delete this email account?"))try{await fetch(`/api/email-accounts/${t}`,{method:"DELETE",headers:B()}),Ze()}catch{}}async function Ns(t){Kt(t),Be(null);try{const n=await(await fetch(`/api/email-accounts/${t}/test`,{method:"POST",headers:B()})).json();Be({id:t,ok:n.ok,message:n.ok?n.message:n.error})}catch(c){Be({id:t,ok:!1,message:c instanceof Error?c.message:"Connection failed"})}finally{Kt(null)}}function ks(t){Vt(t),O({name:t.name,email:t.email,imapHost:t.imap.host,imapPort:String(t.imap.port),imapSecure:t.imap.secure,smtpHost:t.smtp.host,smtpPort:String(t.smtp.port),smtpSecure:t.smtp.secure,authUser:t.auth.user,authPass:""}),_e(!0)}function et(){Dt(!0),fetch("/api/calendar-accounts",{headers:{...B()}}).then(t=>t.json()).then(t=>gs(t)).catch(()=>{}).finally(()=>Dt(!1))}function tt(){q({name:"",provider:"google",serverUrl:"",authUser:"",authPass:""}),_t(null),ze(!1)}function ws(t){const c={google:{serverUrl:"https://apidata.googleusercontent.com/caldav/v2/"},icloud:{serverUrl:"https://caldav.icloud.com/"},outlook:{serverUrl:"https://outlook.office365.com/caldav/"},caldav:{serverUrl:""}};q(n=>{var S;return{...n,provider:t,serverUrl:((S=c[t])==null?void 0:S.serverUrl)||""}})}async function Ss(){be("");const t=w.provider==="outlook"?"caldav":w.provider,c={name:w.name.trim(),provider:t,serverUrl:w.serverUrl.trim(),auth:{user:w.authUser.trim(),pass:w.authPass}};if(!c.name||!c.auth.user||!c.auth.pass){be("Name, user and password are required.");return}if((w.provider==="caldav"||w.provider==="outlook")&&!c.serverUrl){be("Server URL is required for custom CalDAV.");return}try{const n=Y?`/api/calendar-accounts/${Y.id}`:"/api/calendar-accounts",D=await fetch(n,{method:Y?"PUT":"POST",headers:{"Content-Type":"application/json",...B()},body:JSON.stringify(c)});if(!D.ok){const ie=await D.json().catch(()=>({}));throw new Error(ie.error||"Failed")}Gt(Y?"Account updated.":"Account added."),setTimeout(()=>Gt(""),2e3),tt(),et()}catch(n){be(n instanceof Error?n.message:String(n))}}async function Cs(t){if(confirm("Delete this calendar account?"))try{await fetch(`/api/calendar-accounts/${t}`,{method:"DELETE",headers:B()}),et()}catch{}}async function As(t){Wt(t),We(null);try{const n=await(await fetch(`/api/calendar-accounts/${t}/test`,{method:"POST",headers:B()})).json();We({id:t,ok:n.ok,message:n.ok?n.message:n.error,calendars:n.calendars})}catch(c){We({id:t,ok:!1,message:c instanceof Error?c.message:"Connection failed"})}finally{Wt(null)}}function Es(t){_t(t),q({name:t.name,provider:t.provider,serverUrl:t.serverUrl,authUser:t.auth.user,authPass:""}),ze(!0)}async function st(t){const c=t==="aiValidationEnabled"?pe:t==="aiValidationAutoApprove"?Ee:Ue,n=!c;t==="aiValidationEnabled"?Ae(n):t==="aiValidationAutoApprove"?Pe(n):Ie(n);try{await o.updateSettings({[t]:n})}catch{t==="aiValidationEnabled"?Ae(c):t==="aiValidationAutoApprove"?Pe(c):Ie(c)}}async function Ps(){at(!0),ae(""),xe("");try{const t=await o.forceCheckForUpdate();se(t),t.updateAvailable&&t.latestVersion?ae(`Update v${t.latestVersion} is available.`):ae("You are up to date.")}catch(t){xe(t instanceof Error?t.message:String(t))}finally{at(!1)}}async function Us(){rt(!0),ae(""),xe("");try{localStorage.setItem("heyhank_docker_prompt_pending","1");const t=await o.triggerUpdate();ae(t.message),ss(!0)}catch(t){localStorage.removeItem("heyhank_docker_prompt_pending"),xe(t instanceof Error?t.message:String(t)),rt(!1)}}const U=s.useCallback(t=>c=>{Je.current[t]=c},[]);return e.jsxs("div",{className:`${a?"h-full":"h-[100dvh]"} bg-cc-bg text-cc-fg font-sans-ui antialiased flex flex-col`,children:[e.jsx("div",{className:"shrink-0 max-w-5xl w-full mx-auto px-4 sm:px-8 pt-6 sm:pt-10",children:e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Settings"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Configure API access, notifications, appearance, and workspace defaults."})]}),!a&&e.jsx("button",{onClick:()=>{const t=k.getState().currentSessionId;t?Is(t):Ts()},className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"})]})}),e.jsx("div",{className:"sm:hidden shrink-0 border-b border-cc-border",children:e.jsx("nav",{className:"flex gap-1 px-4 py-2 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","aria-label":"Settings categories",children:ct.map(t=>e.jsx("button",{type:"button",onClick:()=>ts(t.id),className:`shrink-0 px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors cursor-pointer ${dt===t.id?"text-cc-primary bg-cc-primary/8":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:t.label},t.id))})}),e.jsxs("div",{className:"flex-1 min-h-0 flex max-w-5xl w-full mx-auto",children:[e.jsx("nav",{className:"hidden sm:flex flex-col gap-0.5 w-44 shrink-0 pt-2 pr-6 pl-8 sticky top-0 self-start max-h-[calc(100vh-3rem)] overflow-y-auto","aria-label":"Settings categories",children:ct.map(t=>e.jsx("button",{type:"button",onClick:()=>ts(t.id),className:`text-left px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors cursor-pointer ${dt===t.id?"text-cc-primary bg-cc-primary/8":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:t.label},t.id))}),e.jsx("div",{ref:es,className:"flex-1 min-w-0 overflow-y-auto px-4 sm:px-8 sm:pl-0 pb-safe",children:e.jsxs("div",{className:"space-y-10 py-4 sm:py-2",children:[e.jsxs(I,{id:"general",title:"General",defaultOpen:!0,forceOpen:P==="general",sectionRef:U("general"),children:[e.jsxs("button",{type:"button",onClick:G,className:"w-full flex items-center justify-between px-3 py-3 min-h-[44px] rounded-lg text-sm bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:[e.jsx("span",{children:"Theme"}),e.jsx("span",{className:"text-xs text-cc-muted",children:z?"Dark":"Light"})]}),e.jsxs("button",{type:"button",onClick:()=>p(t=>!t),className:"w-full flex items-center justify-between px-3 py-3 min-h-[44px] rounded-lg text-sm bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:[e.jsx("span",{children:"Enable Editor tab (CodeMirror)"}),e.jsx("span",{className:"text-xs text-cc-muted",children:x?"On":"Off"})]}),e.jsx("p",{className:"text-xs text-cc-muted px-1",children:"Shows a simple in-app file editor in the session tabs."}),e.jsxs("button",{type:"button",onClick:()=>le(L==="last-commit"?"default-branch":"last-commit"),className:"w-full flex items-center justify-between px-3 py-3 min-h-[44px] rounded-lg text-sm bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:[e.jsx("span",{children:"Diff compare against"}),e.jsx("span",{className:"text-xs text-cc-muted",children:L==="last-commit"?"Last commit (HEAD)":"Default branch"})]}),e.jsx("p",{className:"text-xs text-cc-muted px-1",children:"Last commit shows only uncommitted changes. Default branch shows all changes since diverging from main."})]}),e.jsxs(I,{id:"connectivity",title:"Connectivity",status:J||"Not configured",forceOpen:P==="connectivity",sectionRef:U("connectivity"),children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"HeyHank needs an externally-reachable HTTPS URL for mobile access (PWA), webhooks (GitHub), and OAuth callbacks."}),e.jsxs("div",{className:"bg-cc-hover/50 rounded-lg p-3 space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider",children:"Public URL"}),e.jsx("p",{className:"text-[11px] text-cc-muted",children:"If you have your own domain with a reverse proxy (nginx, Caddy), enter the URL here."}),e.jsx("input",{id:"public-url",type:"url","aria-label":"Public URL",value:J,onChange:t=>Te(t.target.value),placeholder:"https://your-domain.example.com",className:"w-full px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg border border-cc-border text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary font-mono-code"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:async()=>{F(!0),E("");try{const t=await o.updateSettings({publicUrl:J.trim()});Te(t.publicUrl),k.getState().setPublicUrl(t.publicUrl),$(!0),setTimeout(()=>$(!1),1800)}catch(t){E(t instanceof Error?t.message:String(t))}finally{F(!1)}},disabled:R,className:"px-3 py-1.5 rounded-lg text-xs font-medium bg-cc-primary text-white hover:opacity-90 transition-opacity disabled:opacity-50 cursor-pointer",children:R?"Saving...":V?"Saved!":"Save"}),J&&e.jsxs("span",{className:"text-[11px] text-green-500 font-medium",children:["Active: ",J]}),!J&&e.jsxs("span",{className:"text-[11px] text-cc-muted",children:["Not set — using ",typeof window<"u"?window.location.origin:"http://localhost:3456"]})]})]}),e.jsxs("div",{className:"bg-cc-hover/50 rounded-lg p-3 space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider",children:"Tailscale (no domain needed)"}),e.jsx("p",{className:"text-[11px] text-cc-muted",children:"No domain? Tailscale Funnel gives you a free HTTPS URL automatically. Install Tailscale on your server, then enable Funnel here."}),e.jsx(Hs,{})]}),e.jsxs("div",{className:"bg-cc-hover/50 rounded-lg p-3 space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider",children:"What the Public URL enables"}),e.jsxs("ul",{className:"text-[11px] text-cc-muted space-y-1 list-disc pl-4",children:[e.jsx("li",{children:"Mobile access — install HeyHank as PWA on your phone"}),e.jsx("li",{children:"Webhooks — receive events from GitHub and other services"}),e.jsx("li",{children:"OAuth callbacks — authenticate with external services"}),e.jsx("li",{children:"Federation — connect multiple HeyHank instances"})]})]})]}),e.jsxs(I,{id:"authentication",title:"Authentication",status:te?"Token set":"No token",forceOpen:P==="authentication",sectionRef:U("authentication"),children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Use the auth token or QR code to connect additional devices (e.g. mobile over Tailscale)."}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",children:"Auth Token"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg text-cc-fg font-mono-code select-all break-all flex items-center",children:te?Ye?te:"••••••••••••••••":e.jsx("span",{className:"text-cc-muted",children:"Loading..."})}),e.jsx("button",{type:"button",onClick:()=>qt(t=>!t),className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm bg-cc-hover hover:bg-cc-active text-cc-fg transition-colors cursor-pointer",title:Ye?"Hide token":"Show token",children:Ye?"Hide":"Show"}),e.jsx("button",{type:"button",onClick:()=>{te&&navigator.clipboard.writeText(te).then(()=>{Xt(!0),setTimeout(()=>Xt(!1),1500)})},disabled:!te,className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm bg-cc-hover hover:bg-cc-active text-cc-fg transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:"Copy token to clipboard",children:vs?"Copied":"Copy"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",children:"Mobile Login QR"}),H&&H.length>0?e.jsxs("div",{className:"space-y-3",children:[H.length>1&&e.jsx("div",{className:"flex gap-1",children:H.map((t,c)=>e.jsx("button",{type:"button",onClick:()=>bs(c),className:`px-3 py-1.5 rounded-md text-xs font-medium transition-colors cursor-pointer ${c===ve?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:t.label},t.label))}),e.jsx("div",{className:"inline-block rounded-lg bg-white p-2",children:e.jsx("img",{src:H[ve].qrDataUrl,alt:`QR code for ${H[ve].label} login`,className:"w-48 h-48"})}),e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-bg text-sm font-mono-code text-cc-fg break-all select-all",children:H[ve].url}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Scan with your phone's camera app — it will open the URL and auto-authenticate."})]}):H&&H.length===0?e.jsx("p",{className:"text-xs text-cc-muted",children:"No remote addresses detected (LAN or Tailscale). Connect to a network to generate a QR code."}):e.jsx("button",{type:"button",onClick:async()=>{Jt(!0);try{const t=await o.getAuthQr();Qt(t.qrCodes)}catch{}finally{Jt(!1)}},disabled:qe,className:`px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors ${qe?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-hover hover:bg-cc-active text-cc-fg cursor-pointer"}`,children:qe?"Generating...":"Show QR Code"})]}),e.jsxs("div",{className:"pt-2",children:[e.jsx("button",{type:"button",onClick:async()=>{if(confirm("Regenerate auth token? All existing sessions on other devices will be signed out.")){Zt(!0);try{const t=await o.regenerateAuthToken();Yt(t.token),qt(!0),Qt(null)}catch{}finally{Zt(!1)}}},disabled:Qe,className:`px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors ${Qe?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-error/10 hover:bg-cc-error/20 text-cc-error cursor-pointer"}`,children:Qe?"Regenerating...":"Regenerate Token"}),e.jsx("p",{className:"mt-1.5 text-xs text-cc-muted",children:"Creates a new token. All other signed-in devices will need to re-authenticate."})]})]}),e.jsxs(I,{id:"notifications",title:"Notifications",status:de?"Sound on":"Sound off",forceOpen:P==="notifications",sectionRef:U("notifications"),children:[e.jsxs("button",{type:"button",onClick:ye,className:"w-full flex items-center justify-between px-3 py-3 min-h-[44px] rounded-lg text-sm bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:[e.jsx("span",{children:"Sound"}),e.jsx("span",{className:"text-xs text-cc-muted",children:de?"On":"Off"})]}),as&&e.jsxs("button",{type:"button",onClick:async()=>{if(ue)r(!1);else{if(Notification.permission!=="granted"&&await Notification.requestPermission()!=="granted")return;r(!0)}},className:"w-full flex items-center justify-between px-3 py-3 min-h-[44px] rounded-lg text-sm bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:[e.jsx("span",{children:"Desktop Alerts"}),e.jsx("span",{className:"text-xs text-cc-muted",children:ue?"On":"Off"})]}),e.jsx(Ds,{})]}),e.jsxs(I,{id:"providers",title:"Providers",defaultOpen:!0,forceOpen:P==="providers",status:b?"Configured":"Not configured",sectionRef:U("providers"),children:[e.jsxs("p",{className:"text-xs text-cc-muted",children:["Connect AI backends to power your agent sessions. Configure CLI backends (Claude Code, Codex) and additional model providers for Claude Code's ",e.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg",children:"--provider"})," flag."]}),e.jsxs("div",{className:"space-y-3 p-4 bg-cc-bg rounded-lg border border-cc-border",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:"Claude Code"}),(l==null?void 0:l.cliVersion)&&e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:l.cliVersion})]}),((l==null?void 0:l.authenticated)??(l==null?void 0:l.loggedIn))||he?e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-cc-success/15 text-cc-success border border-cc-success/20",children:"Authenticated"}):e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-cc-error/15 text-cc-error border border-cc-error/20",children:"Not configured"})]}),((l==null?void 0:l.authenticated)??(l==null?void 0:l.loggedIn))&&e.jsxs("div",{className:"px-3 py-2 rounded-lg bg-cc-success/5 border border-cc-success/10 text-xs text-cc-muted",children:[l.method==="cli_login"&&e.jsxs(e.Fragment,{children:["Authenticated via ",e.jsx("strong",{className:"text-cc-fg",children:"CLI login"}),". Sessions authenticate automatically."]}),l.method==="env_api_key"&&e.jsxs(e.Fragment,{children:["Authenticated via ",e.jsx("strong",{className:"text-cc-fg",children:"ANTHROPIC_API_KEY"})," env var."]}),l.method==="env_oauth"&&e.jsxs(e.Fragment,{children:["Authenticated via ",e.jsx("strong",{className:"text-cc-fg",children:"CLAUDE_CODE_OAUTH_TOKEN"})," env var."]}),l.method==="env_auth_token"&&e.jsxs(e.Fragment,{children:["Authenticated via ",e.jsx("strong",{className:"text-cc-fg",children:"ANTHROPIC_AUTH_TOKEN"})," env var."]})]}),!((l==null?void 0:l.authenticated)??(l==null?void 0:l.loggedIn))&&!he&&e.jsxs("div",{className:"px-3 py-2.5 rounded-lg bg-cc-primary/5 border border-cc-primary/15 text-xs text-cc-muted space-y-1.5",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"CLI Login:"})," Run ",e.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg",children:"claude login"})," on the server."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"OAuth Token:"})," Paste a token from ",e.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg",children:"claude setup-token"})," below."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"block text-xs text-cc-muted",htmlFor:"claude-code-token",children:["OAuth Token ",(l==null?void 0:l.authenticated)??(l==null?void 0:l.loggedIn)?"(optional)":""]}),e.jsx("input",{id:"claude-code-token",type:"password",value:he&&!ns&&!Z?"••••••••••••••••":Z,onChange:t=>xt(t.target.value),onFocus:()=>yt(!0),onBlur:()=>yt(!1),placeholder:he?"Enter a new token to replace":"Paste token from claude setup-token",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"})]})]}),e.jsxs("div",{className:"space-y-3 p-4 bg-cc-bg rounded-lg border border-cc-border",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:"OpenAI Codex"}),(u==null?void 0:u.cliVersion)&&e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:u.cliVersion})]}),((u==null?void 0:u.authenticated)??(u==null?void 0:u.loggedIn))||re?e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-cc-success/15 text-cc-success border border-cc-success/20",children:"Authenticated"}):e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-cc-error/15 text-cc-error border border-cc-error/20",children:"Not configured"})]}),((u==null?void 0:u.authenticated)??(u==null?void 0:u.loggedIn))&&e.jsxs("div",{className:"px-3 py-2 rounded-lg bg-cc-success/5 border border-cc-success/10 text-xs text-cc-muted",children:[u.method==="cli_login"&&e.jsxs(e.Fragment,{children:["Authenticated via ",e.jsx("strong",{className:"text-cc-fg",children:"device login"}),"."]}),u.method==="env_api_key"&&e.jsxs(e.Fragment,{children:["Authenticated via ",e.jsx("strong",{className:"text-cc-fg",children:"OPENAI_API_KEY"})," env var."]})]}),!((u==null?void 0:u.authenticated)??(u==null?void 0:u.loggedIn))&&!re&&e.jsxs("div",{className:"px-3 py-2.5 rounded-lg bg-cc-primary/5 border border-cc-primary/15 text-xs text-cc-muted space-y-1.5",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Device Login:"})," Run ",e.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg",children:"codex --login"})," on the server."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"API Key:"})," Enter your key below from ",e.jsx("a",{href:"https://platform.openai.com/api-keys",target:"_blank",rel:"noopener noreferrer",className:"text-cc-primary hover:underline",children:"platform.openai.com"}),"."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"block text-xs text-cc-muted",htmlFor:"openai-api-key",children:["API Key ",(u==null?void 0:u.authenticated)??(u==null?void 0:u.loggedIn)?"(optional)":""]}),e.jsx("input",{id:"openai-api-key",type:"password",value:re&&!os&&!X?"••••••••••••••••":X,onChange:t=>ht(t.target.value),onFocus:()=>jt(!0),onBlur:()=>jt(!1),placeholder:re?"Enter a new key to replace":"sk-...",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"})]})]}),bt&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:bt}),rs&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-success/10 border border-cc-success/20 text-xs text-cc-success",children:"Provider settings saved."}),e.jsx("button",{type:"button",disabled:Oe||!Z.trim()&&!X.trim(),onClick:async()=>{ft(!0),vt(""),Le(!1);try{const t={};Z.trim()&&(t.claudeCodeOAuthToken=Z.trim()),X.trim()&&(t.openaiApiKey=X.trim());const c=await o.updateSettings(t);pt(c.claudeCodeOAuthTokenConfigured),gt(c.openaiApiKeyConfigured),c.claudeCliAuth&&Nt(c.claudeCliAuth),c.codexCliAuth&&kt(c.codexCliAuth),xt(""),ht(""),Le(!0),setTimeout(()=>Le(!1),1800)}catch(t){vt(t instanceof Error?t.message:String(t))}finally{ft(!1)}},className:`px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors ${Oe||!Z.trim()&&!X.trim()?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white cursor-pointer"}`,children:Oe?"Saving...":"Save CLI Backend Settings"}),e.jsxs("details",{className:"border-t border-cc-border pt-4 group",children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer list-none",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:"Additional Providers"}),e.jsxs("p",{className:"text-xs text-cc-muted mt-0.5",children:["Configure model providers for Claude Code's ",e.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg text-[10px]",children:"--provider"})," flag."]})]}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-muted transition-transform group-open:rotate-180",children:e.jsx("path",{fillRule:"evenodd",d:"M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z"})})]}),e.jsx("div",{className:"mt-4",children:e.jsx($s,{})})]})]}),e.jsxs(I,{id:"gemini",title:"Gemini",status:ee?"Key set":"Not configured",forceOpen:P==="gemini",sectionRef:U("gemini"),children:[e.jsxs("p",{className:"text-xs text-cc-muted",children:["Configure Gemini Live for voice chat. Get an API key from"," ",e.jsx("a",{href:"https://aistudio.google.com/apikey",target:"_blank",rel:"noopener noreferrer",className:"text-cc-primary hover:underline",children:"Google AI Studio"}),"."]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"gemini-api-key",children:"Gemini API Key"}),e.jsx("input",{id:"gemini-api-key",type:"password",value:ee&&!us&&!ne?"••••••••••••••••":ne,onChange:t=>wt(t.target.value),onFocus:()=>Pt(!0),onBlur:()=>Pt(!1),placeholder:ee?"Enter a new key to replace":"AIza...",className:"w-full px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"}),e.jsx("p",{className:"text-xs text-cc-muted",children:ee?"Gemini API key configured":"Gemini API key not configured"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"assistant-name",children:"Assistant Name"}),e.jsx("input",{id:"assistant-name",type:"text",value:Ve,onChange:t=>$e(t.target.value),placeholder:"e.g. Jarvis, Friday, Max",className:"w-full px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Give your voice assistant a custom name. Leave empty for default."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"user-name",children:"Your Name"}),e.jsx("input",{id:"user-name",type:"text",value:Ke,onChange:t=>De(t.target.value),placeholder:"e.g. Markus",className:"w-full px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Your name so Gemini knows who it's talking to."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"gemini-voice",children:"Voice"}),e.jsxs("select",{id:"gemini-voice",value:Re,onChange:t=>Fe(t.target.value),className:"w-full px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg text-cc-fg focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow",children:[e.jsx("option",{value:"Kore",children:"Kore (female, firm)"}),e.jsx("option",{value:"Puck",children:"Puck (male, playful)"}),e.jsx("option",{value:"Charon",children:"Charon (male, deep)"}),e.jsx("option",{value:"Fenrir",children:"Fenrir (male, bold)"}),e.jsx("option",{value:"Aoede",children:"Aoede (female, bright)"}),e.jsx("option",{value:"Leda",children:"Leda (female, gentle)"}),e.jsx("option",{value:"Orus",children:"Orus (male, clear)"}),e.jsx("option",{value:"Zephyr",children:"Zephyr (neutral, calm)"})]})]}),It&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:It}),ms&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-success/10 border border-cc-success/20 text-xs text-cc-success",children:"Gemini settings saved."}),e.jsx("button",{type:"button",disabled:He||!ne.trim()&&Re===is&&Ve===ls&&Ke===ds,onClick:async()=>{Ut(!0),Tt(""),Me(!1);try{const t={};ne.trim()&&(t.geminiApiKey=ne.trim()),t.assistantName=Ve,t.userName=Ke,t.geminiVoice=Re;const c=await o.updateSettings(t);St(c.geminiApiKeyConfigured),c.geminiVoice&&(Fe(c.geminiVoice),Ct(c.geminiVoice)),typeof c.assistantName=="string"&&($e(c.assistantName),At(c.assistantName)),typeof c.userName=="string"&&(De(c.userName),Et(c.userName)),wt(""),Me(!0),setTimeout(()=>Me(!1),1800)}catch(t){Tt(t instanceof Error?t.message:String(t))}finally{Ut(!1)}},className:`px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors ${He?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white cursor-pointer"}`,children:He?"Saving...":"Save Gemini Settings"})]}),e.jsxs(I,{id:"email",title:"Email Accounts",status:`${ge.length} account${ge.length!==1?"s":""}`,forceOpen:P==="email",sectionRef:U("email"),children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Configure IMAP/SMTP email accounts for the voice assistant. Gemini can read, search, and send emails on your behalf."}),ps?e.jsx("p",{className:"text-xs text-cc-muted",children:"Loading accounts..."}):ge.length===0?e.jsx("p",{className:"text-xs text-cc-muted",children:"No email accounts configured."}):e.jsx("div",{className:"space-y-2",children:ge.map(t=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5 bg-cc-bg rounded-lg",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-cc-fg truncate",children:t.name}),e.jsx("div",{className:"text-xs text-cc-muted truncate",children:t.email}),e.jsxs("div",{className:"text-xs text-cc-muted",children:["IMAP: ",t.imap.host,":",t.imap.port," | SMTP: ",t.smtp.host,":",t.smtp.port]}),(oe==null?void 0:oe.id)===t.id&&e.jsx("div",{className:`text-xs mt-1 ${oe.ok?"text-cc-success":"text-cc-error"}`,children:oe.message})]}),e.jsxs("div",{className:"flex gap-1.5 ml-2 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Ns(t.id),disabled:$t===t.id,className:"px-2 py-1 text-xs rounded bg-cc-hover text-cc-fg hover:bg-cc-border transition-colors",children:$t===t.id?"...":"Test"}),e.jsx("button",{type:"button",onClick:()=>ks(t),className:"px-2 py-1 text-xs rounded bg-cc-hover text-cc-fg hover:bg-cc-border transition-colors",children:"Edit"}),e.jsx("button",{type:"button",onClick:()=>js(t.id),className:"px-2 py-1 text-xs rounded bg-cc-error/10 text-cc-error hover:bg-cc-error/20 transition-colors",children:"Delete"})]})]},t.id))}),hs?e.jsxs("div",{className:"space-y-3 p-4 bg-cc-bg rounded-lg border border-cc-border",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:K?`Edit: ${K.name}`:"Add Email Account"}),!K&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-cc-muted font-medium",children:"Quick presets:"}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[{label:"Gmail",imap:"imap.gmail.com",smtp:"smtp.gmail.com",imapPort:"993",smtpPort:"465",info:`1. Go to myaccount.google.com
2
+ 2. Security → 2-Step Verification (must be ON)
3
+ 3. Search for "App passwords" or go to myaccount.google.com/apppasswords
4
+ 4. Create a new App Password (name: e.g. "Email Agent")
5
+ 5. Copy the 16-character password
6
+ 6. Use your Gmail address as both Email and Username
7
+
8
+ Note: If "App passwords" is not available, 2-Step Verification is not enabled yet.`},{label:"Outlook",imap:"outlook.office365.com",smtp:"smtp.office365.com",imapPort:"993",smtpPort:"587",smtpSecure:!1,info:`1. Go to account.microsoft.com
9
+ 2. Security → Advanced security options
10
+ 3. Enable 2-Step Verification if not active
11
+ 4. App passwords → Create a new app password
12
+ 5. Copy the generated password
13
+ 6. Use your Outlook/Hotmail email as both Email and Username
14
+
15
+ Note: SMTP uses port 587 with STARTTLS (not SSL). For work/school accounts, ask your admin about IMAP access.`},{label:"Hostinger",imap:"imap.hostinger.com",smtp:"smtp.hostinger.com",imapPort:"993",smtpPort:"465",info:`1. Use the email address you created in Hostinger
16
+ 2. Use the same password you set for the email account
17
+ 3. IMAP: imap.hostinger.com (Port 993, SSL)
18
+ 4. SMTP: smtp.hostinger.com (Port 465, SSL)
19
+
20
+ No App Password needed — use your regular email password.`},{label:"World4You",imap:"imap.world4you.com",smtp:"smtp.world4you.com",imapPort:"993",smtpPort:"465",info:`1. Use your World4You email address
21
+ 2. Use the password from your World4You control panel
22
+ 3. IMAP: imap.world4you.com (Port 993, SSL)
23
+ 4. SMTP: smtp.world4you.com (Port 465, SSL)
24
+
25
+ No App Password needed — use your regular email password.`}].map(t=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>O(c=>({...c,imapHost:t.imap,smtpHost:t.smtp,imapPort:t.imapPort,smtpPort:t.smtpPort,imapSecure:!0,smtpSecure:t.smtpSecure!==!1})),className:"px-2 py-1 text-xs rounded bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer border border-cc-border",children:t.label}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"w-4 h-4 flex items-center justify-center rounded-full bg-cc-hover text-cc-muted text-[10px] font-bold cursor-help border border-cc-border group-hover:bg-cc-primary group-hover:text-white group-hover:border-cc-primary transition-colors",children:"i"}),e.jsxs("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-72 p-3 rounded-lg bg-cc-card border border-cc-border shadow-lg text-xs text-cc-fg whitespace-pre-line opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto transition-opacity z-50",children:[e.jsxs("div",{className:"font-semibold mb-1.5 text-cc-primary",children:[t.label," Setup"]}),t.info,e.jsx("div",{className:"absolute top-full left-1/2 -translate-x-1/2 -mt-px w-2 h-2 bg-cc-card border-r border-b border-cc-border rotate-45"})]})]})]},t.label))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Display Name"}),e.jsx("input",{type:"text",value:N.name,onChange:t=>O(c=>({...c,name:t.target.value})),placeholder:"e.g. Gmail, Work, Personal",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Email Address"}),e.jsx("input",{type:"email",value:N.email,onChange:t=>O(c=>({...c,email:t.target.value})),placeholder:"user@example.com",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1 font-medium",children:"IMAP (Incoming)"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx("input",{type:"text",value:N.imapHost,onChange:t=>O(c=>({...c,imapHost:t.target.value})),placeholder:"imap.example.com",className:"col-span-2 px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"}),e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:N.imapPort,onChange:t=>O(c=>({...c,imapPort:t.target.value})),placeholder:"993",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})})]}),e.jsxs("label",{className:"flex items-center gap-2 mt-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:N.imapSecure,onChange:t=>O(c=>({...c,imapSecure:t.target.checked})),className:"rounded"}),"SSL/TLS"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1 font-medium",children:"SMTP (Outgoing)"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx("input",{type:"text",value:N.smtpHost,onChange:t=>O(c=>({...c,smtpHost:t.target.value})),placeholder:"smtp.example.com",className:"col-span-2 px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"}),e.jsx("input",{type:"text",value:N.smtpPort,onChange:t=>O(c=>({...c,smtpPort:t.target.value})),placeholder:"465",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]}),e.jsxs("label",{className:"flex items-center gap-2 mt-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:N.smtpSecure,onChange:t=>O(c=>({...c,smtpSecure:t.target.checked})),className:"rounded"}),"SSL/TLS"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1 font-medium",children:"Authentication"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{type:"text",value:N.authUser,onChange:t=>O(c=>({...c,authUser:t.target.value})),placeholder:"Username / Email",className:"px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"}),e.jsx("input",{type:"password",value:N.authPass,onChange:t=>O(c=>({...c,authPass:t.target.value})),placeholder:K?"New password (leave empty to keep)":"Password / App Password",className:"px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]})]}),Lt&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:Lt}),Rt&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-success/10 border border-cc-success/20 text-xs text-cc-success",children:Rt}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:ys,className:"px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white transition-colors cursor-pointer",children:K?"Update Account":"Add Account"}),e.jsx("button",{type:"button",onClick:Xe,className:"px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium bg-cc-hover text-cc-fg hover:bg-cc-border transition-colors cursor-pointer",children:"Cancel"})]})]}):e.jsx("button",{type:"button",onClick:()=>{Xe(),_e(!0)},className:"px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white transition-colors cursor-pointer",children:"Add Email Account"})]}),e.jsxs(I,{id:"calendar",title:"Calendar Accounts",status:`${fe.length} account${fe.length!==1?"s":""}`,forceOpen:P==="calendar",sectionRef:U("calendar"),children:[e.jsx("p",{className:"text-xs text-cc-muted mb-4",children:"Connect CalDAV calendars (Google Calendar, iCloud, Outlook, Nextcloud, etc.) so your assistant can manage events."}),Ht&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error mb-2",children:Ht}),Mt&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-success/10 border border-cc-success/20 text-xs text-cc-success mb-2",children:Mt}),fs?e.jsx("div",{className:"text-xs text-cc-muted",children:"Loading..."}):fe.length>0?e.jsx("div",{className:"space-y-2 mb-4",children:fe.map(t=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5 bg-cc-bg rounded-lg",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-cc-fg truncate",children:t.name}),e.jsxs("div",{className:"text-xs text-cc-muted truncate",children:[t.auth.user," (",t.provider,")"]}),(Q==null?void 0:Q.id)===t.id&&e.jsxs("div",{className:`text-xs mt-1 ${Q.ok?"text-cc-success":"text-cc-error"}`,children:[Q.message,Q.calendars&&e.jsxs("span",{className:"text-cc-muted",children:[" — Calendars: ",Q.calendars.join(", ")]})]})]}),e.jsxs("div",{className:"flex gap-1.5 ml-2 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>As(t.id),disabled:zt===t.id,className:"px-2 py-1 text-xs rounded bg-cc-hover text-cc-fg hover:bg-cc-border transition-colors",children:zt===t.id?"...":"Test"}),e.jsx("button",{type:"button",onClick:()=>Es(t),className:"px-2 py-1 text-xs rounded bg-cc-hover text-cc-fg hover:bg-cc-border transition-colors",children:"Edit"}),e.jsx("button",{type:"button",onClick:()=>Cs(t.id),className:"px-2 py-1 text-xs rounded bg-cc-error/10 text-cc-error hover:bg-cc-error/20 transition-colors",children:"Delete"})]})]},t.id))}):e.jsx("div",{className:"text-xs text-cc-muted mb-4",children:"No calendar accounts configured."}),!Bt&&e.jsx("button",{type:"button",onClick:()=>{tt(),ze(!0)},className:"px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white transition-colors cursor-pointer",children:"Add Calendar Account"}),Bt&&e.jsxs("div",{className:"space-y-3 p-4 bg-cc-bg rounded-lg border border-cc-border",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:Y?"Edit Calendar Account":"Add Calendar Account"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1 font-medium",children:"Provider"}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[{id:"google",label:"Google",info:`1. Go to myaccount.google.com
26
+ 2. Security → 2-Step Verification (must be ON)
27
+ 3. Search for "App passwords" or go to myaccount.google.com/apppasswords
28
+ 4. Create a new App Password (name: e.g. "Calendar")
29
+ 5. Copy the 16-character password (format: xxxx xxxx xxxx xxxx)
30
+ 6. Use your Gmail address as username and the App Password here`},{id:"icloud",label:"iCloud",info:`1. Go to appleid.apple.com and sign in
31
+ 2. Sign-In and Security → App-Specific Passwords
32
+ 3. Click "+" to generate a new password
33
+ 4. Name it (e.g. "Calendar Agent")
34
+ 5. Copy the generated password (format: xxxx-xxxx-xxxx-xxxx)
35
+ 6. Use your Apple ID email as username and the App-Specific Password here
36
+
37
+ Note: 2-Factor Authentication must be enabled (default for iCloud)`},{id:"outlook",label:"Outlook",info:`1. Go to account.microsoft.com and sign in
38
+ 2. Security → Advanced security options
39
+ 3. App passwords → Create a new app password
40
+ 4. Copy the generated password
41
+ 5. Use your Outlook/Hotmail email as username
42
+
43
+ CalDAV URL: https://outlook.office365.com/caldav/
44
+
45
+ Note: App Passwords require 2-Step Verification to be enabled. For work/school accounts, your admin may need to enable CalDAV access.`},{id:"caldav",label:"CalDAV",info:`For Nextcloud:
46
+ URL: https://your-server.com/remote.php/dav/
47
+
48
+ For Synology:
49
+ URL: https://your-nas:5001/caldav/
50
+
51
+ For other servers, check your provider's CalDAV documentation for the correct URL.`}].map(t=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>ws(t.id),className:`px-2 py-1 text-xs rounded border transition-colors cursor-pointer ${w.provider===t.id?"bg-cc-primary-btn text-white border-cc-primary-btn":"bg-cc-hover text-cc-fg border-cc-border hover:bg-cc-active"}`,children:t.label}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"w-4 h-4 flex items-center justify-center rounded-full bg-cc-hover text-cc-muted text-[10px] font-bold cursor-help border border-cc-border group-hover:bg-cc-primary group-hover:text-white group-hover:border-cc-primary transition-colors",children:"i"}),e.jsxs("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-72 p-3 rounded-lg bg-cc-card border border-cc-border shadow-lg text-xs text-cc-fg whitespace-pre-line opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto transition-opacity z-50",children:[e.jsxs("div",{className:"font-semibold mb-1.5 text-cc-primary",children:[t.label," Setup"]}),t.info,e.jsx("div",{className:"absolute top-full left-1/2 -translate-x-1/2 -mt-px w-2 h-2 bg-cc-card border-r border-b border-cc-border rotate-45"})]})]})]},t.id))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Display Name"}),e.jsx("input",{type:"text",value:w.name,onChange:t=>q(c=>({...c,name:t.target.value})),placeholder:"e.g. Google, iCloud, Work",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]}),(w.provider==="caldav"||w.provider==="outlook")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Server URL"}),e.jsx("input",{type:"text",value:w.serverUrl,onChange:t=>q(c=>({...c,serverUrl:t.target.value})),placeholder:w.provider==="outlook"?"https://outlook.office365.com/caldav/":"https://cloud.example.com/remote.php/dav/",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Username / Email"}),e.jsx("input",{type:"text",value:w.authUser,onChange:t=>q(c=>({...c,authUser:t.target.value})),placeholder:w.provider==="google"?"you@gmail.com":w.provider==="icloud"?"you@icloud.com":w.provider==="outlook"?"you@outlook.com":"username",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-cc-muted mb-1",children:"Password / App Password"}),e.jsx("input",{type:"password",value:w.authPass,onChange:t=>q(c=>({...c,authPass:t.target.value})),placeholder:Y?"New password (leave empty to keep)":"App Password",className:"w-full px-3 py-2 text-sm bg-cc-input-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:Ss,className:"px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white transition-colors cursor-pointer",children:Y?"Update Account":"Add Account"}),e.jsx("button",{type:"button",onClick:tt,className:"px-4 py-2 min-h-[44px] rounded-lg text-sm font-medium bg-cc-hover text-cc-fg hover:bg-cc-border transition-colors cursor-pointer",children:"Cancel"})]})]})]}),e.jsxs(I,{id:"hank-chat",title:"Hank Chat",forceOpen:P==="hank-chat",status:_!=="gemini-live"?{claude:"Claude",openai:"OpenAI",ollama:"Ollama",openrouter:"OpenRouter","gemini-text":"Gemini Text"}[_]||_:"Gemini Live",sectionRef:U("hank-chat"),children:[e.jsx("p",{className:"text-xs text-cc-muted leading-relaxed",children:"Configure the default provider and model for the Hank Chat overlay."}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1.5",children:"Default Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{id:"gemini-live",label:"Gemini Live",desc:"Voice + Text",hasKey:ee,keySection:"gemini",keyLabel:"Gemini API Key"},{id:"claude",label:"Claude",desc:"Text",hasKey:A,keySection:"claude-code",keyLabel:"Anthropic API Key"},{id:"openai",label:"OpenAI",desc:"Text",hasKey:re,keySection:"codex",keyLabel:"OpenAI API Key"},{id:"ollama",label:"Ollama",desc:"Local",hasKey:!0,keySection:"",keyLabel:""},{id:"openrouter",label:"OpenRouter",desc:"Text",hasKey:d,keySection:"",keyLabel:"OPENROUTER_API_KEY env var"},{id:"gemini-text",label:"Gemini",desc:"Text",hasKey:ee,keySection:"gemini",keyLabel:"Gemini API Key"}].map(c=>{const n=!c.hasKey;return e.jsxs("button",{onClick:async()=>{if(!n){we(c.id);try{await o.updateSettings({hankChatProvider:c.id}),window.dispatchEvent(new Event("heyhank-settings-changed"))}catch{we(_)}}},disabled:n,className:`p-2.5 rounded-lg border text-left transition-all ${n?"border-cc-border bg-cc-card opacity-50 cursor-not-allowed":_===c.id?"border-cc-accent bg-cc-accent/10":"border-cc-border bg-cc-card hover:border-cc-accent/30"}`,children:[e.jsx("div",{className:`text-xs font-medium ${n?"text-cc-muted":"text-cc-fg"}`,children:c.label}),n?e.jsxs("div",{className:"text-[9px] text-red-400 mt-0.5",children:["API Key missing — set in ",e.jsx("a",{href:`#settings/${c.keySection}`,className:"underline hover:text-red-300",onClick:S=>{var D;S.stopPropagation(),(D=document.getElementById(c.keySection))==null||D.scrollIntoView({behavior:"smooth"})},children:c.keyLabel})]}):e.jsx("div",{className:"text-[9px] text-cc-muted mt-0.5",children:c.desc})]},c.id)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1.5",children:"Model Override"}),e.jsx("p",{className:"text-[9px] text-cc-muted mb-1.5",children:"Leave empty for provider default."}),e.jsx("input",{type:"text",value:it,onChange:t=>lt(t.target.value),onBlur:async()=>{try{await o.updateSettings({hankChatModel:it})}catch{}},placeholder:_==="claude"?"claude-sonnet-4-20250514":_==="ollama"?"llama3.2":_==="gemini-text"?"gemini-2.5-flash":"default",className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg focus:outline-none focus:border-cc-accent/50"})]}),e.jsx("button",{type:"button",onClick:async()=>{try{const t=await fetch("/api/hank/chat/config",{headers:{Authorization:`Bearer ${localStorage.getItem("heyhank_auth_token")||""}`}});t.ok?alert("Connection OK — provider config loaded successfully."):alert("Connection failed: "+t.status)}catch(t){alert("Connection failed: "+(t instanceof Error?t.message:"Unknown error"))}},className:"px-4 py-2 text-xs font-medium rounded-md text-cc-muted hover:text-cc-fg border border-cc-border hover:border-cc-accent/30 transition-colors",children:"Test Connection"}),e.jsx("div",{className:"border-t border-cc-border my-2"}),e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1.5",children:"Visualization"}),e.jsxs("button",{type:"button",onClick:async()=>{const t=!Se;Ce(t);try{await o.updateSettings({hankChatAvatarEnabled:t}),window.dispatchEvent(new Event("heyhank-settings-changed"))}catch{Ce(!t)}},className:"w-full flex items-center justify-between px-3 py-2.5 rounded-lg bg-cc-hover hover:bg-cc-active text-cc-fg transition-colors cursor-pointer",children:[e.jsxs("div",{className:"text-left",children:[e.jsx("span",{className:"text-sm",children:"Show HUD"}),e.jsx("p",{className:"text-[11px] text-cc-muted mt-0.5",children:"HUD-style, audio-reactive visualization that reacts when Hank speaks or thinks. No face."})]}),e.jsx("span",{className:`text-xs font-medium ${Se?"text-cc-success":"text-cc-muted"}`,children:Se?"On":"Off"})]}),e.jsx("div",{className:"border-t border-cc-border my-2"}),e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1.5",children:"AI Features"}),e.jsxs("div",{className:"px-3 py-2.5 rounded-lg bg-cc-hover/50 border border-cc-border",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-cc-fg",children:"Auto-Rename Sessions"}),e.jsx("span",{className:`text-xs font-medium ${b?"text-cc-success":"text-cc-muted"}`,children:b?"Active":"No provider"})]}),e.jsx("p",{className:"text-[11px] text-cc-muted mt-1",children:"Automatically generates a short title for new sessions based on the first message."})]}),e.jsxs("div",{className:"space-y-3 p-3 bg-cc-bg rounded-lg border border-cc-border",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-fg",children:"AI Validation"}),e.jsx("p",{className:"text-[11px] text-cc-muted leading-relaxed",children:"An AI model evaluates tool calls before execution. Safe ops are auto-approved, dangerous ones blocked. Uses any configured provider. Per-session overrides via the shield icon."}),e.jsxs("button",{type:"button",onClick:()=>st("aiValidationEnabled"),className:"w-full flex items-center justify-between px-3 py-2.5 rounded-lg bg-cc-hover hover:bg-cc-active text-cc-fg transition-colors cursor-pointer",children:[e.jsx("span",{className:"text-sm",children:"AI Validation"}),e.jsx("span",{className:`text-xs font-medium ${pe?"text-cc-success":"text-cc-muted"}`,children:pe?"On":"Off"})]}),pe&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>st("aiValidationAutoApprove"),className:"w-full flex items-center justify-between px-3 py-2.5 rounded-lg bg-cc-hover hover:bg-cc-active text-cc-fg transition-colors cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm",children:"Auto-approve safe tools"}),e.jsx("p",{className:"text-[11px] text-cc-muted mt-0.5",children:"Allow read-only tools automatically"})]}),e.jsx("span",{className:`text-xs font-medium ${Ee?"text-cc-success":"text-cc-muted"}`,children:Ee?"On":"Off"})]}),e.jsxs("button",{type:"button",onClick:()=>st("aiValidationAutoDeny"),className:"w-full flex items-center justify-between px-3 py-2.5 rounded-lg bg-cc-hover hover:bg-cc-active text-cc-fg transition-colors cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm",children:"Auto-deny dangerous tools"}),e.jsx("p",{className:"text-[11px] text-cc-muted mt-0.5",children:"Block destructive commands like rm -rf"})]}),e.jsx("span",{className:`text-xs font-medium ${Ue?"text-cc-success":"text-cc-muted"}`,children:Ue?"On":"Off"})]})]})]})]}),e.jsxs(I,{id:"updates",title:"Updates",status:h?`v${h.currentVersion}`:"",forceOpen:P==="updates",sectionRef:U("updates"),children:[h?e.jsxs("p",{className:"text-xs text-cc-muted",children:["Current version: v",h.currentVersion,h.latestVersion?` • Latest: v${h.latestVersion}`:"",h.channel==="prerelease"?" (prerelease)":""]}):e.jsx("p",{className:"text-xs text-cc-muted",children:"Version information not loaded yet."}),e.jsxs("div",{children:[e.jsx("span",{id:"update-channel-label",className:"block text-sm font-medium mb-1.5",children:"Update Channel"}),e.jsxs("div",{className:"flex gap-1",role:"radiogroup","aria-labelledby":"update-channel-label",children:[e.jsx("button",{type:"button",role:"radio","aria-checked":W==="stable",onClick:async()=>{if(W!=="stable"){ce("stable");try{await o.updateSettings({updateChannel:"stable"})}catch{ce("prerelease");return}try{const t=await o.forceCheckForUpdate();se(t)}catch{}}},className:`px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors cursor-pointer ${W==="stable"?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg hover:bg-cc-active"}`,children:"Stable"}),e.jsx("button",{type:"button",role:"radio","aria-checked":W==="prerelease",onClick:async()=>{if(W!=="prerelease"){ce("prerelease");try{await o.updateSettings({updateChannel:"prerelease"})}catch{ce("stable");return}try{const t=await o.forceCheckForUpdate();se(t)}catch{}}},className:`px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors cursor-pointer ${W==="prerelease"?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg hover:bg-cc-active"}`,children:"Prerelease"})]}),e.jsx("p",{className:"mt-1.5 text-xs text-cc-muted",children:W==="prerelease"?"Tracking prerelease channel. You will receive preview builds from the latest main branch.":"Tracking stable channel. You will only receive versioned releases."})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-sm font-medium",children:"Auto-update Docker image"}),e.jsx("p",{className:"mt-0.5 text-xs text-cc-muted",children:"Automatically re-pull the sandbox Docker image when updating HeyHank"})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":me,onClick:async()=>{const t=!me;je(t);try{await o.updateSettings({dockerAutoUpdate:t})}catch{je(!t)}},className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors ${me?"bg-cc-primary":"bg-cc-hover"}`,children:e.jsx("span",{className:`pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform transition-transform ${me?"translate-x-5":"translate-x-0"}`})})]}),ot&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:ot}),nt&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-success/10 border border-cc-success/20 text-xs text-cc-success",children:nt}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:Ps,disabled:Ne,className:`px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors ${Ne?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-hover hover:bg-cc-active text-cc-fg cursor-pointer"}`,children:Ne?"Checking...":"Check for updates"}),h!=null&&h.isServiceMode?e.jsx("button",{type:"button",onClick:Us,disabled:ke||h.updateInProgress||!h.updateAvailable,className:`px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium transition-colors ${ke||h.updateInProgress||!h.updateAvailable?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white cursor-pointer"}`,children:ke||h.updateInProgress?"Updating...":"Update & Restart"}):e.jsxs("p",{className:"text-xs text-cc-muted self-center",children:["Install service mode with ",e.jsx("code",{className:"font-mono-code bg-cc-code-bg px-1 py-0.5 rounded text-cc-code-fg",children:"heyhank install"})," to enable one-click updates."]})]})]}),e.jsxs(I,{id:"appearance",title:"Appearance",status:z?"Dark":"Light",forceOpen:P==="appearance",sectionRef:U("appearance"),children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-cc-fg font-medium block mb-2",children:"Theme"}),e.jsx("div",{className:"flex items-center gap-2",children:["light","dark","system"].map(t=>{const c=t==="system"?localStorage.getItem("cc-dark-mode")===null:t==="dark"?z&&localStorage.getItem("cc-dark-mode")!==null:!z&&localStorage.getItem("cc-dark-mode")!==null;return e.jsxs("button",{type:"button",onClick:()=>{if(t==="system"){localStorage.removeItem("cc-dark-mode");const n=window.matchMedia("(prefers-color-scheme: dark)").matches;k.getState().setDarkMode(n),localStorage.removeItem("cc-dark-mode")}else k.getState().setDarkMode(t==="dark")},className:`flex items-center gap-2 px-3 py-2 min-h-[44px] rounded-lg text-xs font-medium transition-colors cursor-pointer ${c?"bg-cc-primary/15 text-cc-primary border border-cc-primary/30":"bg-cc-hover text-cc-muted border border-transparent hover:text-cc-fg"}`,children:[t==="light"&&e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"5"}),e.jsx("path",{d:"M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"})]}),t==="dark"&&e.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"})}),t==="system"&&e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]}),t.charAt(0).toUpperCase()+t.slice(1)]},t)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-cc-fg font-medium block mb-2",children:"Font Size"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[10px] text-cc-muted shrink-0",children:"Small"}),e.jsx("input",{id:"font-size-slider",type:"range",min:"12",max:"18",step:"2",value:parseInt(localStorage.getItem("cc-font-size")||"14",10),onChange:t=>{const c=t.target.value;localStorage.setItem("cc-font-size",c),document.documentElement.style.fontSize=`${c}px`},className:"flex-1 accent-cc-primary cursor-pointer"}),e.jsx("span",{className:"text-[10px] text-cc-muted shrink-0",children:"Large"})]}),e.jsx("div",{className:"flex justify-between px-0.5 mt-1",children:[{val:"12",label:"Small"},{val:"14",label:"Medium"},{val:"16",label:"Large"},{val:"18",label:"XL"}].map(t=>e.jsx("button",{type:"button",onClick:()=>{localStorage.setItem("cc-font-size",t.val),document.documentElement.style.fontSize=`${t.val}px`},className:`text-[10px] transition-colors cursor-pointer ${(localStorage.getItem("cc-font-size")||"14")===t.val?"text-cc-primary font-medium":"text-cc-muted hover:text-cc-fg"}`,children:t.label},t.val))})]})]}),e.jsxs(I,{id:"environments",title:"Environments",forceOpen:P==="environments",sectionRef:U("environments"),children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Manage reusable environment profiles used when creating sessions."}),e.jsx("button",{type:"button",onClick:()=>{window.location.hash="#/environments"},className:"px-3 py-2 min-h-[44px] rounded-lg text-sm font-medium bg-cc-primary-btn hover:bg-cc-primary-btn-hover text-white transition-colors cursor-pointer",children:"Open Environments Page"})]}),e.jsxs(I,{id:"federation",title:"Federation",forceOpen:P==="federation",sectionRef:U("federation"),children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Connect multiple HeyHank instances into a peer-to-peer mesh."}),e.jsx(Rs,{})]}),e.jsx(I,{id:"backup",title:"Export & Backup",forceOpen:P==="backup",sectionRef:U("backup"),children:e.jsx(Ms,{})})]})})]})]})}function Hs(){const[a,f]=s.useState(null),[C,v]=s.useState(!0),[m,x]=s.useState(!1);s.useEffect(()=>{o.getTailscaleStatus().then(g=>f(g)).catch(()=>f(null)).finally(()=>v(!1))},[]);async function p(){x(!0);try{const g=await o.startTailscaleFunnel();f(g),g.funnelUrl&&!g.error&&k.getState().setPublicUrl(g.funnelUrl)}catch{}x(!1)}async function b(){x(!0);try{const g=await o.stopTailscaleFunnel();f(g);const A=k.getState().publicUrl;(!A||A===(a==null?void 0:a.funnelUrl))&&k.getState().setPublicUrl("")}catch{}x(!1)}return C?e.jsx("p",{className:"text-[11px] text-cc-muted",children:"Checking Tailscale..."}):!a||!a.installed?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-cc-muted"}),e.jsx("span",{className:"text-xs text-cc-muted",children:"Not installed"})]}),e.jsx("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noopener noreferrer",className:"text-[11px] text-cc-primary hover:underline",children:"Install Tailscale"})]}):a.connected?a.funnelActive?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),e.jsx("span",{className:"text-xs text-green-500 font-medium",children:"Funnel active"})]}),e.jsx("button",{onClick:b,disabled:m,className:"text-[11px] text-red-400 hover:text-red-300 transition-colors cursor-pointer disabled:opacity-50",children:m?"Stopping...":"Disable"})]}),e.jsx("p",{className:"text-[11px] text-cc-fg font-mono",children:a.funnelUrl}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"This URL was automatically set as your Public URL."})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-500"}),e.jsxs("span",{className:"text-xs text-cc-muted",children:["Connected as ",a.dnsName]})]}),a.needsOperatorMode&&e.jsxs("div",{className:"rounded-lg bg-amber-500/10 border border-amber-500/20 px-3 py-2 space-y-1",children:[e.jsx("p",{className:"text-[11px] text-amber-500 font-medium",children:"Setup needed: operator mode"}),e.jsx("div",{className:"font-mono text-[11px] text-cc-fg",children:"sudo tailscale set --operator=$USER"})]}),e.jsx("button",{onClick:p,disabled:m,className:"px-3 py-1.5 rounded-lg text-xs font-medium bg-cc-primary text-white hover:opacity-90 transition-opacity cursor-pointer disabled:opacity-50",children:m?"Starting...":"Enable HTTPS via Funnel"}),a.error&&!a.needsOperatorMode&&e.jsx("p",{className:"text-[11px] text-red-400",children:a.error})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-500"}),e.jsx("span",{className:"text-xs text-cc-muted",children:"Installed but not connected"})]}),e.jsx("div",{className:"rounded-lg bg-cc-bg border border-cc-border px-3 py-1.5 font-mono text-[11px] text-cc-fg",children:"sudo tailscale up"})]})}function Ms(){const[a,f]=s.useState(!1),[C,v]=s.useState(!1),[m,x]=s.useState(null),p=s.useRef(null);async function b(){f(!0);try{const A=await o.exportAll(),j=new Blob([JSON.stringify(A,null,2)],{type:"application/json"}),d=URL.createObjectURL(j),y=document.createElement("a");y.href=d,y.download=`heyhank-backup-${new Date().toISOString().slice(0,10)}.json`,y.click(),URL.revokeObjectURL(d)}catch{}f(!1)}async function g(A){var d;const j=(d=A.target.files)==null?void 0:d[0];if(j){v(!0),x(null);try{const y=await j.text(),T=JSON.parse(y),M=await o.importData({agents:T.agents,notes:T.notes,todos:T.todos}),R=Object.entries(M.imported).map(([F,i])=>`${i} ${F}`);x(`Imported: ${R.join(", ")||"nothing new"}`)}catch{x("Import failed — invalid file format")}v(!1),p.current&&(p.current.value="")}}return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Export all agents, settings, notes, todos, and Gemini conversations as a JSON file. Import to restore on a new instance."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:b,disabled:a,className:"px-3 py-2 text-xs font-medium rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer disabled:opacity-50",children:a?"Exporting...":"Export Backup"}),e.jsxs("label",{className:"px-3 py-2 text-xs font-medium rounded-lg bg-cc-hover text-cc-fg hover:bg-cc-active transition-colors cursor-pointer",children:[C?"Importing...":"Import Backup",e.jsx("input",{ref:p,type:"file",accept:".json",onChange:g,className:"hidden"})]})]}),m&&e.jsx("p",{className:`text-xs ${m.startsWith("Import failed")?"text-cc-error":"text-cc-success"}`,children:m})]})}export{Js as SettingsPage};
@@ -0,0 +1 @@
1
+ import{r as l,b as d,j as s}from"./index-C6Q5UQHD.js";function B({embedded:U}){const[c,h]=l.useState("available"),[p,C]=l.useState([]),[i,g]=l.useState(null),[x,I]=l.useState([]),[r,f]=l.useState([]),[j,y]=l.useState(!1),[N,n]=l.useState(null),[o,L]=l.useState(""),[v,m]=l.useState(null);l.useEffect(()=>{let e=!1;return Promise.all([d.marketplaceListSources(),d.listSkills()]).then(([t,a])=>{e||(C(t),f(a),t.length>0&&g(t[0].id))}).catch(t=>!e&&n(t instanceof Error?t.message:String(t))),()=>{e=!0}},[]),l.useEffect(()=>{if(!i)return;let e=!1;return y(!0),n(null),d.marketplaceListSkills(i).then(t=>{e||I(t)}).catch(t=>{e||n(t instanceof Error?t.message:String(t))}).finally(()=>{e||y(!1)}),()=>{e=!0}},[i]);const E=l.useMemo(()=>new Set(r.map(e=>e.slug)),[r]),u=l.useMemo(()=>{const e=o.trim().toLowerCase();return e?x.filter(t=>t.slug.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)):x},[x,o]),b=l.useMemo(()=>{const e=o.trim().toLowerCase();return e?r.filter(t=>t.slug.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)):r},[r,o]);async function S(){try{const e=await d.listSkills();f(e)}catch{}}async function w(e,t=!1){if(i){m(e.slug),n(null);try{await d.marketplaceInstall(i,e.slug,t),await S()}catch(a){n(a instanceof Error?a.message:String(a))}finally{m(null)}}}async function k(e){if(confirm(`Uninstall skill "${e}"? This removes the folder from ~/.claude/skills/.`)){m(e),n(null);try{await d.deleteSkill(e),await S()}catch(t){n(t instanceof Error?t.message:String(t))}finally{m(null)}}}const M=p.length>1;return s.jsx("div",{className:"absolute inset-0 overflow-auto bg-cc-bg text-cc-fg",children:s.jsxs("div",{className:"max-w-5xl mx-auto p-6",children:[s.jsxs("header",{className:"mb-4",children:[s.jsx("h1",{className:"text-xl font-semibold mb-1",children:"Skills"}),s.jsxs("p",{className:"text-sm text-cc-muted",children:["Browse and install Claude Code skills, or manage what's already in"," ",s.jsx("code",{className:"text-xs bg-cc-card px-1 py-0.5 rounded",children:"~/.claude/skills/"}),"."]})]}),s.jsxs("div",{role:"tablist","aria-label":"Skills view",className:"mb-4 flex gap-1 border-b border-cc-border",children:[s.jsx("button",{type:"button",role:"tab","aria-selected":c==="available",onClick:()=>h("available"),className:`px-3 py-2 text-sm border-b-2 -mb-px transition-colors ${c==="available"?"border-cc-accent text-cc-fg font-medium":"border-transparent text-cc-muted hover:text-cc-fg"}`,children:"Marketplace"}),s.jsxs("button",{type:"button",role:"tab","aria-selected":c==="installed",onClick:()=>h("installed"),className:`px-3 py-2 text-sm border-b-2 -mb-px transition-colors ${c==="installed"?"border-cc-accent text-cc-fg font-medium":"border-transparent text-cc-muted hover:text-cc-fg"}`,children:["Installed (",r.length,")"]})]}),c==="available"&&M&&s.jsxs("section",{"aria-labelledby":"sources-heading",className:"mb-6",children:[s.jsx("h2",{id:"sources-heading",className:"text-sm font-semibold mb-2",children:"Sources"}),s.jsx("div",{className:"flex flex-wrap gap-2",children:p.map(e=>{const t=e.id===i;return s.jsxs("button",{type:"button",onClick:()=>g(e.id),className:`px-3 py-2 rounded-md border text-left text-sm transition-colors ${t?"border-cc-accent bg-cc-accent/10 text-cc-fg":"border-cc-border bg-cc-card hover:bg-cc-hover text-cc-fg"}`,"aria-pressed":t,children:[s.jsx("div",{className:"font-medium",children:e.name}),s.jsxs("div",{className:"text-xs text-cc-muted",children:["by ",e.owner]})]},e.id)})})]}),s.jsxs("div",{className:"mb-4",children:[s.jsx("label",{className:"sr-only",htmlFor:"skill-search",children:"Search skills"}),s.jsx("input",{id:"skill-search",type:"search",value:o,onChange:e=>L(e.target.value),placeholder:"Search skills…",className:"w-full px-3 py-2 rounded-md border border-cc-border bg-cc-card text-sm focus:outline-none focus:ring-2 focus:ring-cc-accent"})]}),N&&s.jsx("div",{role:"alert",className:"mb-4 px-3 py-2 rounded-md border border-red-500/40 bg-red-500/10 text-sm text-red-400",children:N}),c==="available"&&s.jsxs("section",{"aria-labelledby":"skills-heading",children:[s.jsxs("h2",{id:"skills-heading",className:"text-sm font-semibold mb-2",children:["Available skills",j?" (loading…)":` (${u.length})`]}),j?s.jsx("div",{className:"text-sm text-cc-muted",children:"Fetching skills…"}):u.length===0?s.jsx("div",{className:"text-sm text-cc-muted",children:"No skills match your search."}):s.jsx("ul",{className:"space-y-2",children:u.map(e=>{const t=E.has(e.slug),a=v===e.slug;return s.jsxs("li",{className:"px-3 py-3 rounded-md border border-cc-border bg-cc-card flex items-start gap-3",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:"font-medium",children:e.name}),s.jsx("code",{className:"text-xs text-cc-muted",children:e.slug}),t&&s.jsx("span",{className:"text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded bg-green-500/15 text-green-400",children:"Installed"})]}),e.description&&s.jsx("p",{className:"text-sm text-cc-muted mt-1 line-clamp-3",children:e.description})]}),s.jsx("div",{className:"flex flex-col gap-1.5 shrink-0",children:t?s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",disabled:a,onClick:()=>w(e,!0),className:"px-3 py-1 text-xs rounded border border-cc-border hover:bg-cc-hover disabled:opacity-50",children:a?"Updating…":"Update"}),s.jsx("button",{type:"button",disabled:a,onClick:()=>k(e.slug),className:"px-3 py-1 text-xs rounded border border-red-500/40 text-red-400 hover:bg-red-500/10 disabled:opacity-50",children:a?"Removing…":"Uninstall"})]}):s.jsx("button",{type:"button",disabled:a,onClick:()=>w(e,!1),className:"px-3 py-1 text-xs rounded bg-cc-accent text-white hover:opacity-90 disabled:opacity-50",children:a?"Installing…":"Install"})})]},e.slug)})})]}),c==="installed"&&s.jsxs("section",{"aria-labelledby":"installed-heading",children:[s.jsxs("h2",{id:"installed-heading",className:"text-sm font-semibold mb-2",children:["Installed skills (",b.length,")"]}),b.length===0?s.jsx("div",{className:"text-sm text-cc-muted",children:r.length===0?"No skills installed yet. Switch to the Marketplace tab to browse.":"No installed skills match your search."}):s.jsx("ul",{className:"space-y-2",children:b.map(e=>{const t=v===e.slug;return s.jsxs("li",{className:"px-3 py-3 rounded-md border border-cc-border bg-cc-card flex items-start gap-3",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:"font-medium",children:e.name}),s.jsx("code",{className:"text-xs text-cc-muted",children:e.slug})]}),e.description&&s.jsx("p",{className:"text-sm text-cc-muted mt-1 line-clamp-3",children:e.description}),s.jsx("div",{className:"text-[11px] text-cc-muted mt-1 truncate",title:e.path,children:e.path})]}),s.jsx("div",{className:"flex flex-col gap-1.5 shrink-0",children:s.jsx("button",{type:"button",disabled:t,onClick:()=>k(e.slug),className:"px-3 py-1 text-xs rounded border border-red-500/40 text-red-400 hover:bg-red-500/10 disabled:opacity-50",children:t?"Removing…":"Uninstall"})})]},e.slug)})})]})]})})}export{B as SkillsMarketplace};
@@ -0,0 +1,10 @@
1
+ import{r as d,j as e,b as L}from"./index-C6Q5UQHD.js";const Z={instagram:"Instagram",twitter:"X (Twitter)",linkedin:"LinkedIn",facebook:"Facebook",tiktok:"TikTok"},ve=["instagram","twitter","linkedin","facebook","tiktok"];function se(){const t=typeof window<"u"?localStorage.getItem("heyhank_auth_token"):null;return t?{Authorization:`Bearer ${t}`}:{}}async function ye(t){const c=await fetch(t,{headers:se()});if(!c.ok)throw new Error(`${c.status} ${c.statusText}`);return c.json()}async function ee(t,c){const i=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...se()},body:c?JSON.stringify(c):void 0});if(!i.ok){const s=await i.json().catch(()=>null);throw new Error((s==null?void 0:s.error)||`${i.status} ${i.statusText}`)}return i.json()}function Ne({showMessage:t}){var B;const[c,i]=d.useState(null),[s,m]=d.useState(null),[j,v]=d.useState(null),[S,P]=d.useState(""),[T,k]=d.useState("role-model"),[C,u]=d.useState([]),A=d.useCallback(async()=>{try{const a=await ye("/api/socialview/status");i(a)}catch(a){t(a instanceof Error?a.message:"Failed to load status",!0)}},[t]);d.useEffect(()=>{A();const a=setInterval(A,5e3);return()=>clearInterval(a)},[A]);async function g(a){v(a);try{await ee(`/api/socialview/${a}/start`),t(`${Z[a]} browser started.`),m(a),await A()}catch(x){t(x instanceof Error?x.message:"Start failed",!0)}finally{v(null)}}async function n(a){v(a);try{await ee(`/api/socialview/${a}/stop`),t(`${Z[a]} browser stopped.`),s===a&&m(null),await A()}catch(x){t(x instanceof Error?x.message:"Stop failed",!0)}finally{v(null)}}async function l(){if(!(!s||!S.trim())){v(s);try{await ee(`/api/socialview/${s}/goto`,{url:S.trim()}),t(`Navigated to ${S}`),P(""),await A()}catch(a){t(a instanceof Error?a.message:"Navigation failed",!0)}finally{v(null)}}}async function o(){if(!s)return;const a=b.find(E=>E.platform===s),x=(a==null?void 0:a.currentUrl)||"(unknown)",N=`Extract from this URL?
2
+
3
+ ${x}
4
+
5
+ Source: ${T}
6
+
7
+ Make sure the browser is on the correct page (the intended profile/post) before confirming.`;if(typeof window<"u"&&!window.confirm(N))return;v("extract"),u([`→ Starting extract from ${x}`]);const w=E=>u(R=>[...R,E]);try{const E=await fetch(`/api/socialview/${s}/extract-stream`,{method:"POST",headers:{"Content-Type":"application/json",...se()},body:JSON.stringify({source:T})});if(!E.ok||!E.body)throw new Error(`${E.status} ${E.statusText}`);const R=E.body.getReader(),p=new TextDecoder;let U="",D=null,O=!1;for(;;){const{done:h,value:F}=await R.read();if(h)break;U+=p.decode(F,{stream:!0});let I;for(;(I=U.indexOf(`
8
+
9
+ `))!==-1;){const G=U.slice(0,I);U=U.slice(I+2);let K="message",X="";for(const H of G.split(`
10
+ `))H.startsWith("event:")?K=H.slice(6).trim():H.startsWith("data:")&&(X+=H.slice(5).trim());let M={};try{M=JSON.parse(X)}catch{}if(K==="log")w(String(M.message??""));else if(K==="url")w(`URL at start: ${M.url??""}`);else if(K==="done"){const H=Number(M.extracted)||0,W=Array.isArray(M.errors)?M.errors:[];w(`✓ Done — extracted ${H} post${H===1?"":"s"}`);for(const f of W)w(` ! ${f}`);D=H>0?`Extracted ${H} post${H===1?"":"s"}. Review in Library tab.`:W.length>0?W.join("; "):"Nothing extracted on this page",O=H===0}else K==="fatal"&&(w(`✗ Fatal: ${M.error??"extract failed"}`),D=String(M.error??"Extract failed"),O=!0)}}D&&t(D,O)}catch(E){const R=E instanceof Error?E.message:"Extract failed";w(`✗ ${R}`),t(R,!0)}finally{v(null)}}const b=(c==null?void 0:c.platforms)??ve.map(a=>({platform:a,running:!1,loggedIn:null,currentUrl:null,startedAt:null})),y=b.some(a=>a.running),r=!!(c!=null&&c.vnc.websockify)&&!!(c!=null&&c.vnc.x11vnc);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-xs text-cc-muted bg-cc-surface border border-cc-border rounded-md p-3",children:[e.jsx("strong",{className:"text-cc-fg",children:"Wie das funktioniert:"}),' Klick "Start" bei einer Plattform. Der Server öffnet einen echten Browser. Unten siehst du den Browser — logg dich einmal ein. Die Session bleibt erhalten (Cookies persistieren auf dem Server). Später kann der Content Agent hier Posts ansehen zum Lernen.']}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:b.map(a=>{const x=j===a.platform,N=s===a.platform;return e.jsxs("div",{className:`border rounded-md p-3 transition-colors ${N?"border-cc-accent bg-cc-accent/5":"border-cc-border bg-cc-surface"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:Z[a.platform]}),a.running&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${a.loggedIn?"bg-green-500/15 text-green-400":"bg-yellow-500/15 text-yellow-400"}`,children:a.loggedIn?"logged in":"login required"})]}),e.jsx("div",{className:"flex gap-1",children:a.running?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>m(a.platform),disabled:N,className:"text-xs px-2 py-1 rounded bg-cc-accent/10 text-cc-accent border border-cc-accent/30 disabled:opacity-50",children:N?"Viewing":"View"}),e.jsx("button",{onClick:()=>n(a.platform),disabled:x,className:"text-xs px-2 py-1 rounded bg-red-500/10 text-red-400 border border-red-500/30 hover:bg-red-500/20 disabled:opacity-50",children:x?"…":"Stop"})]}):e.jsx("button",{onClick:()=>g(a.platform),disabled:x,className:"text-xs px-2 py-1 rounded bg-cc-accent text-white hover:bg-cc-accent/90 disabled:opacity-50",children:x?"Starting…":"Start"})})]}),a.currentUrl&&e.jsx("div",{className:"text-[11px] text-cc-muted truncate",title:a.currentUrl,children:a.currentUrl})]},a.platform)})}),s&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"url",value:S,onChange:a=>P(a.target.value),onKeyDown:a=>{a.key==="Enter"&&l()},placeholder:"z.B. https://www.instagram.com/username/",className:"flex-1 text-xs px-2 py-1.5 rounded-md bg-cc-bg border border-cc-border text-cc-fg"}),e.jsx("button",{onClick:l,disabled:!S.trim()||j===s,className:"text-xs px-3 py-1.5 rounded-md bg-cc-accent text-white hover:bg-cc-accent/90 disabled:opacity-50",children:"Go"})]}),e.jsxs("div",{className:"border border-cc-border rounded-md bg-cc-bg p-2 text-[11px]",children:[e.jsx("div",{className:"text-cc-muted mb-0.5",children:"Browser ist aktuell auf:"}),e.jsx("div",{className:"font-mono text-cc-fg break-all",children:((B=b.find(a=>a.platform===s))==null?void 0:B.currentUrl)||"(unbekannt — Browser starten)"})]}),e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("label",{className:"text-[11px] text-cc-muted",children:"Source:"}),e.jsxs("select",{value:T,onChange:a=>k(a.target.value),className:"text-xs px-2 py-1 rounded-md bg-cc-bg border border-cc-border text-cc-fg",children:[e.jsx("option",{value:"role-model",children:"Role Model (fremd, Best-Practice lernen)"}),e.jsx("option",{value:"own",children:"Own (eigener Account, Stil-Konsistenz)"})]}),e.jsx("button",{onClick:o,disabled:j==="extract",className:"text-xs px-3 py-1.5 rounded-md bg-green-500/20 text-green-400 border border-green-500/30 hover:bg-green-500/30 disabled:opacity-50",title:"Extract the post or profile currently shown below",children:j==="extract"?"Extracting…":"Extract this page → Library"}),C.length>0&&e.jsx("button",{onClick:()=>u([]),className:"text-[11px] px-2 py-1 rounded-md bg-cc-bg border border-cc-border text-cc-muted hover:text-cc-fg",children:"Clear log"})]}),C.length>0&&e.jsx("div",{className:"border border-cc-border rounded-md bg-black/40 p-2 max-h-48 overflow-auto font-mono text-[11px] leading-relaxed text-cc-fg",children:C.map((a,x)=>e.jsx("div",{className:"whitespace-pre-wrap break-all",children:a},x))})]}),e.jsx("div",{className:"border border-cc-border rounded-md overflow-hidden bg-black",children:y&&r?e.jsx("iframe",{src:"/socialview/vnc/vnc.html?autoconnect=1&resize=remote&reconnect=1&show_dot=1&path=socialview/vnc/websockify",title:"Social View Browser",className:"w-full",style:{height:"720px"}}):e.jsx("div",{className:"p-12 text-center text-sm text-cc-muted",children:y?"VNC wird gestartet…":"Starte eine Plattform oben, um den Browser hier zu sehen."})})]})}function ce(){const t=typeof window<"u"?localStorage.getItem("heyhank_auth_token"):null;return t?{Authorization:`Bearer ${t}`}:{}}async function we(t){const c=await fetch(t,{headers:ce()});if(!c.ok)throw new Error(`${c.status}`);return c.json()}async function te(t,c){const i=await fetch(t,{method:"PATCH",headers:{"Content-Type":"application/json",...ce()},body:JSON.stringify(c)});if(!i.ok)throw new Error(`${i.status}`);return i.json()}async function ke(t){const c=await fetch(t,{method:"DELETE",headers:ce()});if(!c.ok)throw new Error(`${c.status}`);return c.json()}function Se({showMessage:t}){const[c,i]=d.useState([]),[s,m]=d.useState("all"),[j,v]=d.useState("all"),[S,P]=d.useState(!1),[T,k]=d.useState(!1),[C,u]=d.useState(null),[A,g]=d.useState({}),n=d.useCallback(async()=>{k(!0);try{const r=new URLSearchParams;s!=="all"&&r.set("platform",s),j!=="all"&&r.set("source",j),S&&r.set("goldOnly","true");const $=await we(`/api/socialview/library?${r}`);i($.posts)}catch(r){t(r instanceof Error?r.message:"Failed to load library",!0)}finally{k(!1)}},[s,j,S,t]);d.useEffect(()=>{n()},[n]);async function l(r){try{await te(`/api/socialview/library/${r.platform}/${r.id}`,{isGold:!r.isGold}),t(r.isGold?"Removed gold mark":"Marked as gold standard"),await n()}catch($){t($ instanceof Error?$.message:"Update failed",!0)}}async function o(r){const $=(A[r.id]||"").trim();if(!$)return;const B=Array.from(new Set([...r.tags,$]));try{await te(`/api/socialview/library/${r.platform}/${r.id}`,{tags:B}),g({...A,[r.id]:""}),await n()}catch(a){t(a instanceof Error?a.message:"Tag failed",!0)}}async function b(r,$){const B=r.tags.filter(a=>a!==$);try{await te(`/api/socialview/library/${r.platform}/${r.id}`,{tags:B}),await n()}catch(a){t(a instanceof Error?a.message:"Tag remove failed",!0)}}async function y(r){if(confirm("Delete this library post permanently?"))try{await ke(`/api/socialview/library/${r.platform}/${r.id}`),t("Deleted"),await n()}catch($){t($ instanceof Error?$.message:"Delete failed",!0)}}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsxs("select",{value:s,onChange:r=>m(r.target.value),className:"text-xs px-2 py-1 rounded-md bg-cc-bg border border-cc-border text-cc-fg",children:[e.jsx("option",{value:"all",children:"All platforms"}),e.jsx("option",{value:"instagram",children:"Instagram"}),e.jsx("option",{value:"twitter",children:"X (Twitter)"}),e.jsx("option",{value:"linkedin",children:"LinkedIn"}),e.jsx("option",{value:"facebook",children:"Facebook"}),e.jsx("option",{value:"tiktok",children:"TikTok"})]}),e.jsxs("select",{value:j,onChange:r=>v(r.target.value),className:"text-xs px-2 py-1 rounded-md bg-cc-bg border border-cc-border text-cc-fg",children:[e.jsx("option",{value:"all",children:"All sources"}),e.jsx("option",{value:"own",children:"Own"}),e.jsx("option",{value:"role-model",children:"Role Model"})]}),e.jsxs("label",{className:"flex items-center gap-1 text-xs text-cc-fg",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:r=>P(r.target.checked)}),"Gold only"]}),e.jsx("button",{onClick:n,className:"text-xs px-2 py-1 rounded-md bg-cc-surface border border-cc-border text-cc-fg hover:bg-cc-bg",children:"Refresh"}),e.jsxs("span",{className:"text-xs text-cc-muted ml-auto",children:[c.length," posts"]})]}),T&&e.jsx("div",{className:"text-xs text-cc-muted",children:"Loading…"}),!T&&c.length===0&&e.jsx("div",{className:"text-xs text-cc-muted border border-dashed border-cc-border rounded-md p-6 text-center",children:'No posts yet. Use the View tab to open a platform, navigate to a post or profile, and click "Extract this page → Library".'}),e.jsx("div",{className:"space-y-2",children:c.map(r=>{var B,a;const $=C===r.id;return e.jsxs("div",{className:`border rounded-md p-3 transition-colors ${r.isGold?"border-yellow-500/40 bg-yellow-500/5":"border-cc-border bg-cc-surface"}`,children:[e.jsxs("div",{className:"flex items-start gap-3",children:[((B=r.media[0])==null?void 0:B.remoteUrl)&&e.jsx("img",{src:r.media[0].remoteUrl,alt:"",className:"w-16 h-16 object-cover rounded shrink-0 bg-cc-bg",onError:x=>{x.target.style.display="none"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-bg text-cc-muted uppercase",children:r.platform}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-bg text-cc-muted",children:r.source}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-bg text-cc-muted",children:r.postType}),r.author.handle&&e.jsxs("span",{className:"text-xs font-medium text-cc-fg",children:["@",r.author.handle]}),r.isGold&&e.jsx("span",{className:"text-[10px] text-yellow-400",children:"★ gold"})]}),e.jsx("div",{className:"text-xs text-cc-fg line-clamp-2",children:r.hook||r.text.slice(0,140)}),r.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:r.tags.map(x=>e.jsxs("button",{onClick:()=>b(r,x),className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-accent/10 text-cc-accent hover:bg-red-500/20 hover:text-red-400",title:"Click to remove",children:[x," ×"]},x))})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>l(r),className:`text-xs px-2 py-1 rounded border ${r.isGold?"bg-yellow-500/20 border-yellow-500/40 text-yellow-400":"bg-cc-bg border-cc-border text-cc-muted hover:text-yellow-400"}`,title:"Mark as gold standard — only gold posts are used as few-shot for the agent",children:r.isGold?"★":"☆"}),e.jsx("button",{onClick:()=>u($?null:r.id),className:"text-xs px-2 py-1 rounded bg-cc-bg border border-cc-border text-cc-fg hover:bg-cc-surface",children:$?"Hide":"Open"}),e.jsx("button",{onClick:()=>y(r),className:"text-xs px-2 py-1 rounded bg-red-500/10 border border-red-500/30 text-red-400 hover:bg-red-500/20",children:"Del"})]})]}),$&&e.jsxs("div",{className:"mt-3 space-y-2 text-xs border-t border-cc-border pt-3",children:[r.url&&e.jsx("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"text-cc-accent hover:underline break-all",children:r.url}),e.jsx("div",{className:"whitespace-pre-wrap text-cc-fg",children:r.text}),r.cta&&e.jsxs("div",{children:[e.jsx("span",{className:"text-cc-muted",children:"CTA: "}),e.jsx("span",{className:"text-cc-fg",children:r.cta})]}),((a=r.media[0])==null?void 0:a.description)&&e.jsxs("div",{className:"bg-cc-bg border border-cc-border rounded p-2",children:[e.jsx("div",{className:"text-cc-muted text-[10px] mb-1",children:"Visual analysis (Claude):"}),e.jsx("div",{className:"text-cc-fg whitespace-pre-wrap",children:r.media[0].description})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{type:"text",value:A[r.id]||"",onChange:x=>g({...A,[r.id]:x.target.value}),onKeyDown:x=>{x.key==="Enter"&&o(r)},placeholder:"Add tag (e.g. B2B, personal-story, humor)",className:"flex-1 text-xs px-2 py-1 rounded-md bg-cc-bg border border-cc-border text-cc-fg"}),e.jsx("button",{onClick:()=>o(r),className:"text-xs px-2 py-1 rounded-md bg-cc-accent text-white hover:bg-cc-accent/90",children:"Add"})]})]})]},r.id)})})]})}function ae(){const t=typeof window<"u"?localStorage.getItem("heyhank_auth_token"):null;return t?{Authorization:`Bearer ${t}`}:{}}async function de(t){const c=await fetch(t,{headers:ae()});if(!c.ok)throw new Error(`${c.status}`);return c.json()}async function Ce(t,c){const i=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...ae()},body:void 0});if(!i.ok){const s=await i.json().catch(()=>null);throw new Error((s==null?void 0:s.error)||`${i.status}`)}return i.json()}async function Pe(t){const c=await fetch(t,{method:"DELETE",headers:ae()});if(!c.ok)throw new Error(`${c.status}`);return c.json()}function Ae({showMessage:t}){const[c,i]=d.useState([]),[s,m]=d.useState([]),[j,v]=d.useState(!1),[S,P]=d.useState(null),[T,k]=d.useState(null),C=d.useCallback(async()=>{v(!0);try{const[l,o]=await Promise.all([de("/api/socialview/style-profiles"),de("/api/socialview/library")]);i(l.profiles),m(o.posts)}catch(l){t(l instanceof Error?l.message:"Failed to load personas",!0)}finally{v(!1)}},[t]);d.useEffect(()=>{C()},[C]);const u=(()=>{const l=new Map;for(const o of s){const b=`${o.platform}:${o.author.handle.toLowerCase()}`,y=l.get(b);y?y.count+=1:l.set(b,{platform:o.platform,handle:o.author.handle,displayName:o.author.displayName??o.author.handle,count:1})}return Array.from(l.values()).sort((o,b)=>b.count-o.count)})();function A(l,o){return c.find(b=>b.platform===l&&b.handle.toLowerCase()===o.toLowerCase())}async function g(l,o){const b=`${l}:${o}`;P(b);try{const y=await Ce(`/api/socialview/style-profiles/${l}/${encodeURIComponent(o)}/analyze`);t(`Persona erstellt für @${o}`),await C(),k(y.profile)}catch(y){t(y instanceof Error?y.message:"Analyse fehlgeschlagen",!0)}finally{P(null)}}async function n(l,o){if(confirm(`Persona für @${o} löschen?`))try{await Pe(`/api/socialview/style-profiles/${l}/${encodeURIComponent(o)}`),t("Persona gelöscht"),await C()}catch(b){t(b instanceof Error?b.message:"Löschen fehlgeschlagen",!0)}}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-cc-fg",children:"Personas"}),e.jsx("div",{className:"text-[11px] text-cc-muted",children:"Destillierte Schreib-Profile pro (Plattform, Handle). Werden vom Content-Agent als Schreib-Anweisung genutzt — Hank kennt die Handles und mappt Personennamen darauf."})]}),e.jsx("button",{onClick:C,className:"text-xs px-2 py-1 rounded-md bg-cc-surface border border-cc-border text-cc-fg hover:bg-cc-bg",children:"Refresh"})]}),j&&e.jsx("div",{className:"text-xs text-cc-muted",children:"Lade…"}),!j&&u.length===0&&e.jsx("div",{className:"text-xs text-cc-muted border border-dashed border-cc-border rounded-md p-6 text-center",children:"Noch keine extrahierten Posts. Geh in den View-Tab, öffne ein Profil eines Role-Models und extrahiere Posts in die Library — dann erscheinen hier Persona-Karten."}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:u.map(l=>{const o=A(l.platform,l.handle),b=`${l.platform}:${l.handle}`,y=S===b,r=o&&l.count>o.basedOnPostCount,$=r?l.count-o.basedOnPostCount:0;return e.jsxs("div",{className:`rounded-lg border p-3 space-y-2 ${o?"border-cc-accent/30 bg-cc-accent/5":"border-cc-border bg-cc-surface"}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-bg text-cc-muted uppercase",children:l.platform}),e.jsxs("span",{className:"text-sm font-semibold text-cc-fg truncate",children:["@",l.handle]})]}),l.displayName&&l.displayName!==l.handle&&e.jsx("div",{className:"text-xs text-cc-muted truncate mt-0.5",children:l.displayName})]}),o&&e.jsx("span",{className:"text-[10px] text-green-400 shrink-0",title:"Persona vorhanden",children:"✓"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-[11px] text-cc-muted",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-cc-fg font-medium",children:l.count})," Posts in Library"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Basis: ",e.jsx("span",{className:"text-cc-fg font-medium",children:o.basedOnPostCount})]}),e.jsx("span",{children:"·"}),e.jsx("span",{className:"capitalize",children:o.lengthCategory}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Ø ",o.averageWordCount," Wörter"]})]})]}),r&&e.jsxs("div",{className:"text-[10px] px-2 py-1 rounded bg-yellow-500/10 border border-yellow-500/30 text-yellow-400",children:["⚠ ",$," ",$===1?"neuer Post":"neue Posts"," seit letzter Analyse — Aktualisierung empfohlen"]}),o&&o.toneOfVoice&&e.jsxs("div",{className:"text-xs text-cc-fg line-clamp-2 italic",children:["„",o.toneOfVoice,'"']}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 pt-1",children:[o&&e.jsx("button",{onClick:()=>k(o),className:"text-[11px] px-2 py-1 rounded bg-cc-surface border border-cc-border text-cc-fg hover:bg-cc-bg",children:"Ansehen"}),e.jsx("button",{onClick:()=>g(l.platform,l.handle),disabled:y,className:"text-[11px] px-2 py-1 rounded bg-cc-accent/15 border border-cc-accent/40 text-cc-accent hover:bg-cc-accent/25 disabled:opacity-50",title:o?"Auf Basis aller Posts neu erstellen":"Persona aus Library-Posts destillieren",children:y?"Analysiere…":o?"Aktualisieren":"Generieren"}),o&&e.jsx("button",{onClick:()=>n(l.platform,l.handle),className:"text-[11px] px-2 py-1 rounded bg-red-500/10 border border-red-500/30 text-red-400 hover:bg-red-500/20",children:"Löschen"})]})]},b)})}),T&&e.jsx($e,{profile:T,onClose:()=>k(null)})]})}function $e({profile:t,onClose:c}){const i=Math.max(1,...t.hookPatterns.map(s=>s.frequency),...t.ctaPatterns.map(s=>s.frequency));return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4",onClick:c,children:e.jsxs("div",{className:"bg-cc-surface border border-cc-border rounded-lg max-w-2xl w-full max-h-[85vh] overflow-y-auto",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start justify-between p-4 border-b border-cc-border sticky top-0 bg-cc-surface z-10",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-bg text-cc-muted uppercase",children:t.platform}),e.jsxs("span",{className:"text-sm font-semibold text-cc-fg",children:["@",t.handle]})]}),t.displayName&&t.displayName!==t.handle&&e.jsx("div",{className:"text-xs text-cc-muted mt-0.5",children:t.displayName})]}),e.jsx("button",{onClick:c,className:"text-cc-muted hover:text-cc-fg text-lg leading-none","aria-label":"Schließen",children:"×"})]}),e.jsxs("div",{className:"p-4 space-y-4 text-xs",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"bg-cc-bg border border-cc-border rounded p-2",children:[e.jsx("div",{className:"text-[10px] text-cc-muted",children:"Basis"}),e.jsxs("div",{className:"text-cc-fg font-medium",children:[t.basedOnPostCount," Posts"]})]}),e.jsxs("div",{className:"bg-cc-bg border border-cc-border rounded p-2",children:[e.jsx("div",{className:"text-[10px] text-cc-muted",children:"Ø Wörter"}),e.jsx("div",{className:"text-cc-fg font-medium",children:t.averageWordCount})]}),e.jsxs("div",{className:"bg-cc-bg border border-cc-border rounded p-2",children:[e.jsx("div",{className:"text-[10px] text-cc-muted",children:"Länge"}),e.jsx("div",{className:"text-cc-fg font-medium capitalize",children:t.lengthCategory})]})]}),t.toneOfVoice&&e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Tonfall"}),e.jsx("div",{className:"text-cc-fg whitespace-pre-wrap",children:t.toneOfVoice})]}),t.hookPatterns.length>0&&e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Hook-Muster"}),e.jsx("div",{className:"space-y-2",children:t.hookPatterns.slice().sort((s,m)=>m.frequency-s.frequency).map((s,m)=>e.jsxs("div",{className:"bg-cc-bg border border-cc-border rounded p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-cc-fg font-medium flex-1",children:s.type}),e.jsxs("span",{className:"text-cc-muted text-[10px]",children:[s.frequency,"×"]})]}),e.jsx("div",{className:"h-1 bg-cc-surface rounded mt-1 overflow-hidden",children:e.jsx("div",{className:"h-full bg-cc-accent",style:{width:`${s.frequency/i*100}%`}})}),s.examples.length>0&&e.jsx("ul",{className:"mt-1.5 space-y-0.5",children:s.examples.slice(0,3).map((j,v)=>e.jsxs("li",{className:"text-cc-muted italic",children:["„",j,'"']},v))})]},m))})]}),t.ctaPatterns.length>0&&e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"CTA-Muster"}),e.jsx("div",{className:"space-y-2",children:t.ctaPatterns.slice().sort((s,m)=>m.frequency-s.frequency).map((s,m)=>e.jsxs("div",{className:"bg-cc-bg border border-cc-border rounded p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-cc-fg font-medium flex-1",children:s.type}),e.jsxs("span",{className:"text-cc-muted text-[10px]",children:[s.frequency,"×"]})]}),s.examples.length>0&&e.jsx("ul",{className:"mt-1 space-y-0.5",children:s.examples.slice(0,3).map((j,v)=>e.jsxs("li",{className:"text-cc-muted italic",children:["„",j,'"']},v))})]},m))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Emoji-Stil"}),e.jsx("div",{className:"text-cc-fg capitalize",children:t.emojiStyle}),t.emojiList.length>0&&e.jsx("div",{className:"text-base mt-1",children:t.emojiList.join(" ")})]}),e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Hashtag-Stil"}),e.jsx("div",{className:"text-cc-fg capitalize",children:t.hashtagStyle})]})]}),t.contentPillars.length>0&&e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Content-Säulen"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.contentPillars.map((s,m)=>e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-cc-accent/15 text-cc-accent border border-cc-accent/30",children:s},m))})]}),t.commentEngagementPattern&&e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Kommentar-Verhalten"}),e.jsx("div",{className:"text-cc-fg whitespace-pre-wrap",children:t.commentEngagementPattern})]}),t.visualStyle&&e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Visueller Stil"}),e.jsx("div",{className:"text-cc-fg whitespace-pre-wrap",children:t.visualStyle})]}),t.rawAnalysis&&e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] uppercase text-cc-muted mb-1",children:"Gesamt-Analyse"}),e.jsx("div",{className:"bg-cc-bg border border-cc-border rounded p-2 text-cc-fg whitespace-pre-wrap",children:t.rawAnalysis})]}),e.jsxs("div",{className:"text-[10px] text-cc-muted pt-2 border-t border-cc-border flex justify-between",children:[e.jsxs("span",{children:["Erstellt: ",new Date(t.createdAt).toLocaleString()]}),e.jsxs("span",{children:["Aktualisiert: ",new Date(t.updatedAt).toLocaleString()]})]})]})]})})}const ue=["twitter","instagram","linkedin","facebook","tiktok","threads"],Te=["January","February","March","April","May","June","July","August","September","October","November","December"],Ee=["Mo","Tu","We","Th","Fr","Sa","Su"],J={twitter:"𝕏",instagram:"📷",linkedin:"in",facebook:"f",tiktok:"♪",threads:"@"};function De(t){if(!Array.isArray(t))return[];const c=[];for(const i of t){if(typeof i=="string"&&i){c.push(i);continue}if(i&&typeof i=="object"){const s=i;if(typeof s.name=="string"&&s.name){c.push(s.name);continue}if(typeof s.platform=="string"&&s.platform){c.push(s.platform);continue}}}return c}function re(t){return{...t,platforms:De(t.platforms)}}function oe(t){const c=t.scheduledAt||t.updatedAt||t.createdAt,i=c?Date.parse(c):NaN;return Number.isFinite(i)?i:0}function _(t){return t>=1e6?(t/1e6).toFixed(1)+"M":t>=1e3?(t/1e3).toFixed(1)+"K":String(t)}function ne(t){const c=Date.now()-new Date(t).getTime(),i=Math.floor(c/6e4);if(i<1)return"just now";if(i<60)return`${i}m ago`;const s=Math.floor(i/60);if(s<24)return`${s}h ago`;const m=Math.floor(s/24);return m<7?`${m}d ago`:new Date(t).toLocaleDateString()}function Me({embedded:t}){const c=(()=>{const r=window.location.hash.match(/#\/socialmedia\/(\w+)/);return r&&["posts","drafts","calendar","view","library","personas","analytics","settings"].includes(r[1])?r[1]:"posts"})(),[i,s]=d.useState(c),[m,j]=d.useState(""),[v,S]=d.useState(!1),[P,T]=d.useState(!1),[k,C]=d.useState(null),[u,A]=d.useState(0);function g(y,r=!1){j(y),S(r),setTimeout(()=>j(""),r?5e3:3e3)}function n(){A(y=>y+1)}function l(y){C(y||null),T(!0)}function o(){T(!1),C(null)}const b=[{id:"posts",label:"Queue"},{id:"drafts",label:"Drafts"},{id:"calendar",label:"Calendar"},{id:"view",label:"View"},{id:"library",label:"Library"},{id:"personas",label:"Personas"},{id:"analytics",label:"Analytics"},{id:"settings",label:"Settings"}];return e.jsx("div",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-4xl mx-auto px-4 sm:px-8 py-6 sm:py-10 pb-safe space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Social Media"}),e.jsx("button",{onClick:()=>l(),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/90 transition-colors",children:"+ New Post"})]}),e.jsx("div",{className:"flex gap-1 border-b border-cc-border pb-2",children:b.map(y=>e.jsx("button",{onClick:()=>s(y.id),className:`px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors ${i===y.id?"bg-cc-accent/10 text-cc-accent border-b-2 border-cc-accent":"text-cc-muted hover:text-cc-fg"}`,children:y.label},y.id))}),m&&e.jsx("div",{className:`text-xs px-3 py-2 rounded-md ${v?"bg-red-500/10 text-red-400 border border-red-500/20":"bg-green-500/10 text-green-400 border border-green-500/20"}`,children:m}),P&&e.jsx(Le,{post:k,onClose:o,onSuccess:y=>{o(),g(y),n()},showMessage:g}),i==="posts"&&e.jsx(Ue,{refreshKey:u,showMessage:g,onEdit:l,onRefresh:n}),i==="drafts"&&e.jsx(Be,{refreshKey:u,showMessage:g,onEdit:l,onRefresh:n}),i==="calendar"&&e.jsx(Fe,{refreshKey:u,showMessage:g,onEdit:l,onRefresh:n}),i==="view"&&e.jsx(Ne,{showMessage:g}),i==="library"&&e.jsx(Se,{showMessage:g}),i==="personas"&&e.jsx(Ae,{showMessage:g}),i==="analytics"&&e.jsx(Re,{showMessage:g}),i==="settings"&&e.jsx(Ie,{showMessage:g,onSwitchTab:s})]})})}function Le({post:t,onClose:c,onSuccess:i,showMessage:s}){var W;const[m,j]=d.useState((t==null?void 0:t.text)||""),[v,S]=d.useState((t==null?void 0:t.platforms)||[]),[P,T]=d.useState((t==null?void 0:t.title)||""),[k,C]=d.useState((t==null?void 0:t.firstComment)||""),[u,A]=d.useState(((W=t==null?void 0:t.mediaUrls)==null?void 0:W.join(", "))||""),[g,n]=d.useState((t==null?void 0:t.videoUrl)||""),[l,o]=d.useState((t==null?void 0:t.thumbnailUrl)||""),[b,y]=d.useState((t==null?void 0:t.status)==="draft"?"draft":t!=null&&t.scheduledAt?"schedule":"now"),[r,$]=d.useState(t!=null&&t.scheduledAt?new Date(t.scheduledAt).toISOString().slice(0,16):""),[B,a]=d.useState(!1),[x,N]=d.useState(!!(t!=null&&t.firstComment||t!=null&&t.videoUrl||t!=null&&t.thumbnailUrl)),w=d.useRef(null),[E,R]=d.useState(!1),[p,U]=d.useState(!1),D=!!t,O=m.length,h={twitter:280,instagram:2200,facebook:63206,linkedin:3e3,tiktok:2200,threads:500},F=v.filter(f=>h[f]&&O>h[f]),I=F.length>0,G=v.reduce((f,z)=>{const V=h[z];return V?f===null?V:Math.min(f,V):f},null);function K(f){S(z=>z.includes(f)?z.filter(V=>V!==f):[...z,f])}async function X(f){const z=f.target.files;if(z!=null&&z.length){R(!0);try{const V=[];for(const q of Array.from(z)){const Q=new FileReader,pe=await new Promise(je=>{Q.onload=()=>je(Q.result.split(",")[1]),Q.readAsDataURL(q)}),ge=await L.uploadMedia(pe,q.type,q.name);V.push(ge.url)}const ie=u.split(",").map(q=>q.trim()).filter(Boolean);A([...ie,...V].join(", "))}catch(V){s(V instanceof Error?V.message:"Upload failed",!0)}finally{R(!1),f.target.value=""}}}async function M(){if(!m.trim()){s("Post text is required.",!0);return}if(!v.length){s("Select at least one platform.",!0);return}if(b==="schedule"&&!r){s("Select a date and time.",!0);return}if(b!=="draft"&&I){const f=F.map(z=>`${z.charAt(0).toUpperCase()+z.slice(1)}: ${O}/${h[z]}`).join(", ");s(`Text too long for: ${f}`,!0);return}a(!0);try{const f={text:m.trim(),platforms:v,scheduledAt:b==="schedule"?new Date(r).toISOString():null,mediaUrls:u.split(",").map(z=>z.trim()).filter(Boolean),title:P.trim()||void 0,firstComment:k.trim()||void 0,videoUrl:g.trim()||void 0,thumbnailUrl:l.trim()||void 0,isDraft:b==="draft",createdBy:"user"};D?(await L.updateSocialPost(t.id,f),t.status==="draft"&&b!=="draft"?(await L.publishSocialPost(t.id),i(b==="schedule"?"Post scheduled!":"Post published!")):i("Post updated!")):(await L.createSocialPost(f),i(b==="draft"?"Draft saved!":b==="schedule"?"Post scheduled!":"Post created!"))}catch(f){s(f instanceof Error?f.message:"Failed",!0)}finally{a(!1)}}const H=u.split(",").map(f=>f.trim()).filter(Boolean);return e.jsxs("div",{className:"border border-cc-accent/30 rounded-xl bg-cc-card shadow-lg shadow-cc-accent/5 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-cc-border/50 bg-cc-bg/50",children:[e.jsx("span",{className:"text-xs font-medium text-cc-fg",children:D?"Edit Post":"New Post"}),e.jsx("button",{onClick:c,className:"text-cc-muted hover:text-cc-fg transition-colors text-sm leading-none",children:"×"})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1.5",children:"Channels"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ue.map(f=>e.jsxs("button",{onClick:()=>K(f),className:`flex items-center gap-1 px-2.5 py-1 rounded-full text-[11px] font-medium transition-all border ${v.includes(f)?"bg-cc-accent/15 text-cc-accent border-cc-accent/40":"bg-cc-bg text-cc-muted border-cc-border hover:border-cc-accent/30 hover:text-cc-fg"}`,children:[e.jsx("span",{className:"text-[10px]",children:J[f]}),f.charAt(0).toUpperCase()+f.slice(1)]},f))})]}),e.jsx("input",{value:P,onChange:f=>T(f.target.value),placeholder:"Title (optional)",className:"w-full bg-transparent text-sm font-medium text-cc-fg placeholder:text-cc-muted/50 focus:outline-none"}),e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{value:m,onChange:f=>j(f.target.value),rows:4,placeholder:"What would you like to share?",className:"w-full bg-cc-bg border border-cc-border rounded-lg p-3 text-sm text-cc-fg resize-y focus:outline-none focus:border-cc-accent/50 min-h-[100px]"}),G!==null&&e.jsx("div",{className:"absolute bottom-2 right-2 flex gap-2",children:v.map(f=>{const z=h[f];if(!z)return null;const V=O>z;return e.jsxs("span",{className:`text-[10px] ${V?"text-red-400 font-medium":"text-cc-muted"}`,children:[f==="twitter"?"X":f.charAt(0).toUpperCase()+f.slice(1)," ",O,"/",z]},f)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{var f;return(f=w.current)==null?void 0:f.click()},disabled:E,className:"flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg border border-cc-border rounded-md hover:border-cc-accent/30 transition-colors disabled:opacity-50",children:E?"Uploading...":"📎 Add Media"}),e.jsx("button",{onClick:()=>U(!0),className:"flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg border border-cc-border rounded-md hover:border-cc-accent/30 transition-colors",children:"🖼️ Media Library"}),e.jsx(Ve,{open:p,onClose:()=>U(!1),onSelect:f=>{const z=u.split(",").map(V=>V.trim()).filter(Boolean);A([...z,...f].join(", "))}}),e.jsx("input",{ref:w,type:"file",accept:"image/*,video/*",multiple:!0,onChange:X,className:"hidden"}),H.length>0&&e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[H.length," file(s)"]})]}),H.length>0&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:H.map((f,z)=>e.jsxs("div",{className:"relative group shrink-0",children:[e.jsx("img",{src:f,alt:`Media ${z+1}`,className:"h-20 w-20 rounded-lg border border-cc-border/50 object-cover"}),e.jsx("button",{onClick:()=>{const V=H.filter((ie,q)=>q!==z);A(V.join(", "))},className:"absolute -top-1 -right-1 w-4 h-4 bg-red-500 text-white rounded-full text-[9px] leading-none flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:"×"})]},z))})]}),e.jsx("button",{onClick:()=>N(!x),className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors",children:x?"▾ Less options":"▸ More options (first comment, video, thumbnail)"}),x&&e.jsxs("div",{className:"space-y-2 pl-2 border-l-2 border-cc-border/30",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted block mb-1",children:"First Comment (Instagram, LinkedIn)"}),e.jsx("textarea",{value:k,onChange:f=>C(f.target.value),rows:2,placeholder:"Hashtags, links, additional context...",className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg resize-y focus:outline-none focus:border-cc-accent/50"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted block mb-1",children:"Video URL"}),e.jsx("input",{value:g,onChange:f=>n(f.target.value),placeholder:"https://...",className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted block mb-1",children:"Thumbnail URL"}),e.jsx("input",{value:l,onChange:f=>o(f.target.value),placeholder:"https://...",className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs 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.5",children:"When to post"}),e.jsx("div",{className:"flex gap-1.5",children:[{id:"now",label:"Post Now"},{id:"schedule",label:"Schedule"},{id:"draft",label:"Save as Draft"}].map(f=>e.jsx("button",{onClick:()=>y(f.id),className:`px-3 py-1.5 text-[11px] font-medium rounded-md transition-all border ${b===f.id?"bg-cc-accent/15 text-cc-accent border-cc-accent/40":"bg-cc-bg text-cc-muted border-cc-border hover:border-cc-accent/30"}`,children:f.label},f.id))})]}),b==="schedule"&&e.jsx("input",{type:"datetime-local",value:r,onChange:f=>$(f.target.value),className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg focus:outline-none focus:border-cc-accent/50"}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx("button",{onClick:M,disabled:B,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/90 disabled:opacity-50 transition-colors",children:B?"Saving...":b==="now"?D?"Update & Post":"Post Now":b==="schedule"?D?"Update & Schedule":"Schedule":D?"Update Draft":"Save Draft"}),e.jsx("button",{onClick:c,className:"px-3 py-2 text-xs text-cc-muted hover:text-cc-fg transition-colors",children:"Cancel"})]})]})]})}function Ue({refreshKey:t,showMessage:c,onEdit:i,onRefresh:s}){const[m,j]=d.useState([]),[v,S]=d.useState("all"),[P,T]=d.useState(""),[k,C]=d.useState("newest"),[u,A]=d.useState(new Set),[g,n]=d.useState(!1),l=d.useCallback(async()=>{try{const p=await L.listSocialPosts({limit:200});j((p.posts||[]).filter(U=>U.status!=="draft").map(re))}catch{}},[]);d.useEffect(()=>{l()},[l,t]);async function o(p){try{await L.deleteSocialPost(p),c("Post deleted."),l(),s()}catch(U){c(U instanceof Error?U.message:"Failed",!0)}}async function b(p,U){try{U?await L.archiveSocialPost(p):await L.unarchiveSocialPost(p),c(U?"Post archived.":"Post unarchived."),l(),s()}catch(D){c(D instanceof Error?D.message:"Failed",!0)}}function y(p){A(U=>{const D=new Set(U);return D.has(p)?D.delete(p):D.add(p),D})}const r=m.filter(p=>!((v==="all"?p.status==="archived":p.status!==v)||P&&!p.platforms.includes(P))).sort((p,U)=>{const D=oe(U)-oe(p);return k==="newest"?D:-D}),$=r.map(p=>p.id),B=$.filter(p=>u.has(p)).length,a=$.length>0&&B===$.length;function x(){A(p=>{const U=new Set(p);return a?$.forEach(D=>U.delete(D)):$.forEach(D=>U.add(D)),U})}async function N(p,U){const D=Array.from(u);if(D.length===0)return;n(!0);let O=0,h=0;for(const F of D)try{await p(F),O++}catch{h++}n(!1),A(new Set),c(h===0?`${U} ${O} post(s).`:`${U} ${O} post(s) — ${h} failed.`,h>0),l(),s()}async function w(){await N(p=>L.archiveSocialPost(p),"Archived")}async function E(){await N(p=>L.unarchiveSocialPost(p),"Unarchived")}async function R(){confirm(`Delete ${u.size} post(s)? This cannot be undone.`)&&await N(p=>L.deleteSocialPost(p),"Deleted")}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsx("div",{className:"flex gap-1",children:["all","published","scheduled","failed","archived"].map(p=>e.jsx("button",{onClick:()=>S(p),className:`px-2 py-1 text-[10px] font-medium rounded-md transition-colors ${v===p?"bg-cc-accent/15 text-cc-accent":"text-cc-muted hover:text-cc-fg"}`,children:p==="all"?"All":p.charAt(0).toUpperCase()+p.slice(1)},p))}),e.jsxs("select",{value:P,onChange:p=>T(p.target.value),className:"bg-cc-bg border border-cc-border rounded-md px-2 py-1 text-[10px] text-cc-fg focus:outline-none",children:[e.jsx("option",{value:"",children:"All platforms"}),ue.map(p=>e.jsx("option",{value:p,children:p.charAt(0).toUpperCase()+p.slice(1)},p))]}),e.jsx("button",{onClick:()=>C(k==="newest"?"oldest":"newest"),title:k==="newest"?"Sorted: newest first. Click for oldest first.":"Sorted: oldest first. Click for newest first.",className:"px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg bg-cc-bg border border-cc-border rounded-md transition-colors",children:k==="newest"?"↓ Newest":"↑ Oldest"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-cc-muted cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:a,ref:p=>{p&&(p.indeterminate=B>0&&!a)},onChange:x,disabled:r.length===0,className:"accent-cc-accent"}),"Select all"]}),e.jsxs("span",{className:"text-[10px] text-cc-muted ml-auto",children:[r.length," post(s)"]})]}),u.size>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-accent/10 border border-cc-accent/30 rounded-md",children:[e.jsxs("span",{className:"text-[11px] font-medium text-cc-accent",children:[u.size," selected"]}),e.jsxs("div",{className:"flex gap-1 ml-auto",children:[e.jsx("button",{onClick:w,disabled:g,className:"px-2 py-1 text-[10px] font-medium text-cc-fg hover:bg-cc-hover rounded-md transition-colors disabled:opacity-50",children:"Archive"}),e.jsx("button",{onClick:E,disabled:g,className:"px-2 py-1 text-[10px] font-medium text-cc-fg hover:bg-cc-hover rounded-md transition-colors disabled:opacity-50",children:"Unarchive"}),e.jsx("button",{onClick:R,disabled:g,className:"px-2 py-1 text-[10px] font-medium text-red-400 hover:bg-red-400/10 rounded-md transition-colors disabled:opacity-50",children:"Delete"}),e.jsx("button",{onClick:()=>A(new Set),disabled:g,className:"px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover rounded-md transition-colors disabled:opacity-50",children:"Clear"})]})]}),r.length===0?e.jsx(he,{text:v==="all"?"No posts yet. Create your first post!":`No ${v} posts.`}):e.jsx("div",{className:"space-y-2",children:r.map(p=>e.jsx(me,{post:p,selected:u.has(p.id),onToggleSelect:y,onEdit:i,onDelete:o,onArchive:b,showMessage:c,onRefresh:()=>{l(),s()}},p.id))})]})}function Be({refreshKey:t,showMessage:c,onEdit:i,onRefresh:s}){const[m,j]=d.useState([]),[v,S]=d.useState(null),[P,T]=d.useState(new Set),[k,C]=d.useState(!1),u=d.useCallback(async()=>{try{const a=await L.listSocialPosts({limit:50,status:"draft"});j((a.posts||[]).map(re))}catch{}},[]);d.useEffect(()=>{u()},[u,t]);function A(a){T(x=>{const N=new Set(x);return N.has(a)?N.delete(a):N.add(a),N})}const g=m.map(a=>a.id),n=g.filter(a=>P.has(a)).length,l=g.length>0&&n===g.length;function o(){T(a=>{const x=new Set(a);return l?g.forEach(N=>x.delete(N)):g.forEach(N=>x.add(N)),x})}async function b(a,x){const N=Array.from(P);if(N.length===0)return;C(!0);let w=0,E=0;for(const R of N)try{await a(R),w++}catch{E++}C(!1),T(new Set),c(E===0?`${x} ${w} draft(s).`:`${x} ${w} draft(s) — ${E} failed.`,E>0),u(),s()}async function y(){confirm(`Delete ${P.size} draft(s)? This cannot be undone.`)&&await b(a=>L.deleteSocialPost(a),"Deleted")}const r={twitter:280,instagram:2200,facebook:63206,linkedin:3e3,tiktok:2200,threads:500};async function $(a){const x=m.find(N=>N.id===a);if(x){const N=x.text.length,w=x.platforms.filter(E=>r[E]&&N>r[E]);if(w.length>0){const E=w.map(R=>`${R.charAt(0).toUpperCase()+R.slice(1)}: ${N}/${r[R]}`).join(", ");c(`Text too long for: ${E}. Edit the draft first.`,!0);return}}S(a);try{const N=await L.publishSocialPost(a);if((N==null?void 0:N.status)==="failed"){const w=N.backendData,E=(Array.isArray(w==null?void 0:w.message)?w.message.join(" • "):w==null?void 0:w.message)||(Array.isArray(w==null?void 0:w.details)?w.details.join(" • "):w==null?void 0:w.details)||(w==null?void 0:w.error)||"Publish failed";c(String(E),!0)}else c("Post published!");u(),s()}catch(N){c(N instanceof Error?N.message:"Failed to publish",!0)}finally{S(null)}}async function B(a){try{await L.deleteSocialPost(a),c("Draft deleted."),u(),s()}catch(x){c(x instanceof Error?x.message:"Failed",!0)}}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-cc-muted cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:l,ref:a=>{a&&(a.indeterminate=n>0&&!l)},onChange:o,disabled:m.length===0,className:"accent-cc-accent"}),"Select all"]}),e.jsxs("span",{className:"text-[10px] text-cc-muted ml-auto",children:[m.length," draft(s)"]})]}),P.size>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-cc-accent/10 border border-cc-accent/30 rounded-md",children:[e.jsxs("span",{className:"text-[11px] font-medium text-cc-accent",children:[P.size," selected"]}),e.jsxs("div",{className:"flex gap-1 ml-auto",children:[e.jsx("button",{onClick:y,disabled:k,className:"px-2 py-1 text-[10px] font-medium text-red-400 hover:bg-red-400/10 rounded-md transition-colors disabled:opacity-50",children:"Delete"}),e.jsx("button",{onClick:()=>T(new Set),disabled:k,className:"px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover rounded-md transition-colors disabled:opacity-50",children:"Clear"})]})]}),m.length===0?e.jsx(he,{text:"No drafts. Drafts created by you, Gemini, or agents will appear here."}):e.jsx("div",{className:"space-y-2",children:m.map(a=>e.jsx(me,{post:a,selected:P.has(a.id),onToggleSelect:A,onEdit:i,onDelete:B,showMessage:c,onRefresh:()=>{u(),s()},onPublish:$,isPublishing:v===a.id},a.id))})]})}function me({post:t,selected:c,onToggleSelect:i,onEdit:s,onDelete:m,onArchive:j,showMessage:v,onRefresh:S,onPublish:P,isPublishing:T}){const[k,C]=d.useState(!1),[u,A]=d.useState([]),g=t.status==="draft",n=t.status==="archived",l=t.mediaUrls||[];async function o(){if(k){C(!1);return}try{const y=await L.getSocialPostComments(t.id);A(y.comments||[]),C(!0)}catch{C(!0)}}async function b(y,r){try{const $=await L.replySocialComment(t.id,y,r);if($.ok){v("Reply sent.");const B=await L.getSocialPostComments(t.id);A(B.comments||[])}else v($.error||"Failed",!0)}catch($){v($ instanceof Error?$.message:"Failed",!0)}}return e.jsxs("div",{className:`border rounded-xl overflow-hidden transition-colors ${c?"bg-cc-accent/5 border-cc-accent/50":g?"bg-cc-card border-yellow-500/25":"bg-cc-card border-cc-border/50"}`,children:[e.jsxs("div",{className:"p-3.5 space-y-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[i&&e.jsx("input",{type:"checkbox",checked:!!c,onChange:()=>i(t.id),"aria-label":"Select post",className:"mt-0.5 accent-cc-accent cursor-pointer"}),t.title&&e.jsx("h3",{className:"text-xs font-semibold text-cc-fg flex-1",children:t.title})]}),e.jsx("p",{className:"text-sm text-cc-fg whitespace-pre-wrap break-words leading-relaxed",children:t.text}),(t.thumbnailUrl||l.length>0)&&e.jsxs("div",{className:"flex gap-2 overflow-x-auto",children:[t.thumbnailUrl&&e.jsx("img",{src:t.thumbnailUrl,alt:"Thumbnail",className:"h-24 rounded-lg border border-cc-border/30 object-cover"}),l.map((y,r)=>e.jsx("img",{src:y,alt:`Media ${r+1}`,className:"h-24 rounded-lg border border-cc-border/30 object-cover"},r))]}),t.videoUrl&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-cc-muted bg-cc-bg rounded-md px-2 py-1",children:[e.jsx("span",{children:"🎬"}),e.jsx("span",{className:"truncate",children:t.videoUrl})]}),t.firstComment&&e.jsx("div",{className:"text-[11px] text-cc-muted/80 border-l-2 border-cc-accent/20 pl-2.5 italic",children:t.firstComment}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(be,{status:t.status}),t.createdBy&&e.jsx(fe,{by:t.createdBy}),t.platforms.map(y=>e.jsx(le,{platform:y},y)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:t.scheduledAt?`Scheduled: ${new Date(t.scheduledAt).toLocaleString()}`:t.createdAt?ne(t.createdAt):""})]})]}),e.jsxs("div",{className:"flex items-center gap-1 px-3.5 py-2 border-t border-cc-border/30 bg-cc-bg/30",children:[g&&P&&e.jsx("button",{onClick:()=>P(t.id),disabled:T,className:"flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-green-400 hover:bg-green-400/10 rounded-md transition-colors disabled:opacity-50",children:T?"Publishing...":"▶ Publish"}),e.jsx("button",{onClick:()=>s(t),className:"flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover rounded-md transition-colors",children:"Edit"}),e.jsx("button",{onClick:o,className:"flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover rounded-md transition-colors",children:"Comments"}),!g&&e.jsx("button",{onClick:async()=>{if(window.confirm("Move this post back to drafts? This will delete the post from your social platform(s) (best-effort) so you can edit and re-publish."))try{await L.moveSocialPostToDraft(t.id),v("Moved to drafts."),S()}catch(y){v(y instanceof Error?y.message:"Failed",!0)}},className:"flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover rounded-md transition-colors ml-auto",children:"↩ Move to Draft"}),j&&!g&&e.jsx("button",{onClick:()=>j(t.id,!n),className:"flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover rounded-md transition-colors",children:n?"Unarchive":"Archive"}),e.jsx("button",{onClick:()=>m(t.id),className:`flex items-center gap-1 px-2 py-1 text-[10px] font-medium text-red-400/70 hover:text-red-400 hover:bg-red-400/10 rounded-md transition-colors${j&&!g?"":" ml-auto"}`,children:"Delete"})]}),k&&e.jsx("div",{className:"px-3.5 pb-3 border-t border-cc-border/30",children:e.jsx(ze,{comments:u,onReply:b})})]})}function ze({comments:t,onReply:c}){return e.jsxs("div",{className:"pt-2.5 space-y-2",children:[t.length===0&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No comments."}),t.map(i=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium text-cc-accent",children:i.author}),e.jsx("span",{className:"text-[9px] text-cc-muted",children:i.createdAt?ne(i.createdAt):""}),i.likes?e.jsxs("span",{className:"text-[9px] text-cc-muted",children:["· ",i.likes," likes"]}):null]}),e.jsx("p",{className:"text-[11px] text-cc-fg",children:i.text}),e.jsx(xe,{onSubmit:s=>c(i.id,s),placeholder:"Reply..."})]},i.id)),e.jsx(xe,{onSubmit:i=>c(null,i),placeholder:"New comment..."})]})}function xe({onSubmit:t,placeholder:c}){const[i,s]=d.useState("");return e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("input",{value:i,onChange:m=>s(m.target.value),placeholder:c,className:"flex-1 bg-cc-bg border border-cc-border/50 rounded-md px-2 py-1 text-[10px] text-cc-fg focus:outline-none focus:border-cc-accent/50",onKeyDown:m=>{m.key==="Enter"&&i.trim()&&(t(i.trim()),s(""))}}),e.jsx("button",{onClick:()=>{i.trim()&&(t(i.trim()),s(""))},className:"text-[10px] text-cc-accent hover:text-cc-accent/80 transition-colors px-2",children:"Send"})]})}function Fe({refreshKey:t,showMessage:c,onEdit:i,onRefresh:s}){const m=new Date,[j,v]=d.useState(m.getFullYear()),[S,P]=d.useState(m.getMonth()),[T,k]=d.useState({}),[C,u]=d.useState(null),A=`${j}-${String(S+1).padStart(2,"0")}`,g=d.useCallback(async()=>{try{const x=await L.getSocialCalendar(A);k(x.days||{})}catch{}},[A]);d.useEffect(()=>{g()},[g,t]);function n(){S===0?(P(11),v(j-1)):P(S-1),u(null)}function l(){S===11?(P(0),v(j+1)):P(S+1),u(null)}const o=new Date(j,S+1,0).getDate();let b=new Date(j,S,1).getDay();b=b===0?6:b-1;const y=new Date().toISOString().slice(0,10);async function r(x){const N=prompt("New date/time (YYYY-MM-DDTHH:MM):");if(N)try{await L.updateSocialPost(x,{scheduledAt:new Date(N).toISOString()}),c("Post rescheduled."),g(),s()}catch(w){c(w instanceof Error?w.message:"Failed",!0)}}async function $(x){try{await L.deleteSocialPost(x),c("Post deleted."),g(),s()}catch(N){c(N instanceof Error?N.message:"Failed",!0)}}const B=C?T[C]||[]:[],a={published:"border-l-green-400",scheduled:"border-l-blue-400",draft:"border-l-yellow-400",failed:"border-l-red-400"};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("button",{onClick:n,className:"px-2.5 py-1 text-cc-muted hover:text-cc-fg transition-colors rounded-md hover:bg-cc-hover text-sm",children:"←"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-sm font-semibold text-cc-fg",children:[Te[S]," ",j]}),e.jsx("button",{onClick:()=>{v(m.getFullYear()),P(m.getMonth()),u(null)},className:"text-[10px] px-2 py-0.5 rounded-md text-cc-muted hover:text-cc-fg border border-cc-border hover:border-cc-accent/30 transition-colors",children:"Today"})]}),e.jsx("button",{onClick:l,className:"px-2.5 py-1 text-cc-muted hover:text-cc-fg transition-colors rounded-md hover:bg-cc-hover text-sm",children:"→"})]}),e.jsxs("div",{className:"flex gap-3 justify-center text-[9px] text-cc-muted",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400 inline-block"})," Published"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 inline-block"})," Scheduled"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-yellow-400 inline-block"})," Draft"]})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-px bg-cc-border/30 rounded-xl overflow-hidden border border-cc-border/30",children:[Ee.map(x=>e.jsx("div",{className:"text-center text-[9px] font-semibold text-cc-muted py-2 bg-cc-bg uppercase tracking-wider",children:x},x)),Array.from({length:b}).map((x,N)=>e.jsx("div",{className:"min-h-[90px] bg-cc-bg/50"},`e-${N}`)),Array.from({length:o}).map((x,N)=>{const w=N+1,E=`${A}-${String(w).padStart(2,"0")}`,R=T[E]||[],p=E===y,U=E===C;return e.jsxs("button",{onClick:()=>u(U?null:E),className:`min-h-[90px] flex flex-col p-1 text-left transition-all relative ${U?"bg-cc-accent/10 ring-1 ring-inset ring-cc-accent/40":"bg-cc-card hover:bg-cc-hover/50"}`,children:[e.jsx("span",{className:`text-[10px] leading-none mb-1 self-end px-1 py-0.5 rounded ${p?"bg-cc-accent text-white font-bold":"text-cc-muted"}`,children:w}),e.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 w-full overflow-hidden",children:[R.slice(0,3).map(D=>e.jsxs("div",{className:`rounded px-1 py-0.5 text-[8px] leading-tight truncate border-l-2 ${a[D.status]||"border-l-cc-muted"} bg-cc-bg/80`,title:D.text,children:[e.jsx("span",{className:"text-cc-muted mr-0.5",children:D.platforms.map(O=>J[O]||O.charAt(0)).join("")}),e.jsxs("span",{className:"text-cc-fg",children:[D.text.slice(0,30),D.text.length>30?"...":""]})]},D.id)),R.length>3&&e.jsxs("span",{className:"text-[8px] text-cc-muted text-center",children:["+",R.length-3," more"]})]})]},w)}),(()=>{const N=(b+o)%7;return N===0?null:Array.from({length:7-N}).map((w,E)=>e.jsx("div",{className:"min-h-[90px] bg-cc-bg/50"},`t-${E}`))})()]}),C&&e.jsxs("div",{className:"border border-cc-border rounded-xl overflow-hidden bg-cc-card",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-cc-border/50 bg-cc-bg/50",children:[e.jsx("h3",{className:"text-xs font-semibold text-cc-fg",children:new Date(C+"T00:00:00").toLocaleDateString(void 0,{weekday:"long",day:"numeric",month:"long",year:"numeric"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[B.length," post(s)"]}),e.jsx("button",{onClick:()=>i({id:"",text:"",status:"draft",platforms:[],createdAt:"",scheduledAt:C+"T12:00:00"}),className:"text-[10px] px-2 py-1 rounded-md bg-cc-accent/10 text-cc-accent border border-cc-accent/30 hover:bg-cc-accent/20 transition-colors cursor-pointer",children:"+ New Post"}),e.jsx("button",{onClick:()=>u(null),className:"text-cc-muted hover:text-cc-fg text-sm leading-none",children:"×"})]})]}),e.jsx("div",{className:"p-3 space-y-2",children:B.length===0?e.jsx("p",{className:"text-[11px] text-cc-muted py-4 text-center",children:'No posts on this day. Click "+ New Post" to create one.'}):B.map(x=>{var N;return e.jsxs("div",{className:"border rounded-lg overflow-hidden bg-cc-bg/50 border-cc-border/30",children:[e.jsxs("div",{className:"flex gap-3 p-3",children:[(((N=x.mediaUrls)==null?void 0:N.length)??0)>0&&e.jsx("img",{src:x.mediaUrls[0],alt:"",className:"w-16 h-16 rounded-lg object-cover border border-cc-border/30 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1.5",children:[x.title&&e.jsx("div",{className:"text-[11px] font-semibold text-cc-fg",children:x.title}),e.jsx("p",{className:"text-[11px] text-cc-fg break-words leading-relaxed line-clamp-3",children:x.text}),e.jsxs("div",{className:"flex flex-wrap gap-1 items-center",children:[e.jsx(be,{status:x.status}),x.createdBy&&e.jsx(fe,{by:x.createdBy}),x.platforms.map(w=>e.jsx(le,{platform:w},w)),(x.scheduledAt||x.createdAt)&&e.jsx("span",{className:"text-[9px] text-cc-muted ml-auto",children:new Date(x.scheduledAt||x.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 px-3 py-1.5 border-t border-cc-border/20 bg-cc-bg/30",children:[e.jsx("button",{onClick:()=>i(x),className:"text-[10px] px-2 py-0.5 text-cc-muted hover:text-cc-fg hover:bg-cc-hover rounded transition-colors",children:"Edit"}),e.jsx("button",{onClick:()=>r(x.id),className:"text-[10px] px-2 py-0.5 text-cc-accent hover:bg-cc-accent/10 rounded transition-colors",children:"Reschedule"}),e.jsx("button",{onClick:()=>$(x.id),className:"text-[10px] px-2 py-0.5 text-red-400 hover:bg-red-400/10 rounded transition-colors ml-auto",children:"Delete"})]})]},x.id)})})]})]})}function Re({showMessage:t}){const[c,i]=d.useState([]),[s,m]=d.useState(""),[j,v]=d.useState(null),[S,P]=d.useState([]),[T,k]=d.useState(!1);d.useEffect(()=>{L.getSocialProfiles().then(u=>i(u.profiles||[])).catch(()=>{})},[]);async function C(){if(!s){t("Select a profile.",!0);return}k(!0);try{const u=await L.getSocialAccountAnalytics(s);v(u);const A=await L.listSocialPosts({limit:10}),g=await Promise.all((A.posts||[]).map(re).filter(n=>n.status==="published").map(async n=>{try{const l=await L.getSocialPostAnalytics(n.id);return{post:n,analytics:l}}catch{return{post:n,analytics:{impressions:0,likes:0,shares:0,comments:0}}}}));P(g)}catch(u){t(u instanceof Error?u.message:"Failed",!0)}finally{k(!1)}}return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Profile"}),e.jsxs("select",{value:s,onChange:u=>m(u.target.value),className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg focus:outline-none",children:[e.jsx("option",{value:"",children:"Select profile..."}),c.map(u=>e.jsxs("option",{value:u.id,children:[J[u.platform]||""," ",u.platform," — ",u.name]},u.id))]})]}),e.jsx("button",{onClick:C,disabled:T,className:"px-3 py-2 text-xs font-medium rounded-md bg-cc-accent/10 text-cc-accent border border-cc-accent/30 hover:bg-cc-accent/20 disabled:opacity-50 transition-colors",children:T?"Loading...":"Load"})]}),j&&e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:"Followers",value:j.followers},{label:"Following",value:j.following},{label:"Posts",value:j.posts}].map(u=>e.jsxs("div",{className:"border border-cc-border rounded-xl p-3.5 bg-cc-card text-center",children:[e.jsx("div",{className:"text-xl font-bold text-cc-accent",children:_(u.value)}),e.jsx("div",{className:"text-[9px] text-cc-muted uppercase tracking-wider mt-1",children:u.label})]},u.label))}),S.length>0&&(()=>{const u=S.reduce((n,{analytics:l})=>({impressions:n.impressions+l.impressions,likes:n.likes+l.likes,shares:n.shares+l.shares,comments:n.comments+l.comments}),{impressions:0,likes:0,shares:0,comments:0}),A=u.impressions>0?((u.likes+u.shares+u.comments)/u.impressions*100).toFixed(2):"0.00",g=S.reduce((n,l)=>{const o=l.analytics.likes+l.analytics.shares+l.analytics.comments,b=n.analytics.likes+n.analytics.shares+n.analytics.comments;return o>b?l:n},S[0]);return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid grid-cols-5 gap-2",children:[{label:"Total Views",value:_(u.impressions)},{label:"Total Likes",value:_(u.likes)},{label:"Total Shares",value:_(u.shares)},{label:"Total Comments",value:_(u.comments)},{label:"Engagement",value:`${A}%`}].map(n=>e.jsxs("div",{className:"border border-cc-border rounded-xl p-2.5 bg-cc-card text-center",children:[e.jsx("div",{className:"text-sm font-bold text-cc-accent",children:n.value}),e.jsx("div",{className:"text-[8px] text-cc-muted uppercase tracking-wider mt-0.5",children:n.label})]},n.label))}),g&&g.analytics.likes+g.analytics.shares+g.analytics.comments>0&&e.jsxs("div",{className:"border border-cc-accent/30 rounded-xl p-3.5 bg-cc-accent/5 space-y-2",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-accent/20 text-cc-accent font-medium",children:"Top Post"})}),e.jsxs("p",{className:"text-[11px] text-cc-fg break-words",children:[g.post.text.slice(0,150),g.post.text.length>150?"...":""]}),e.jsxs("div",{className:"flex gap-3 text-[10px] text-cc-muted",children:[e.jsxs("span",{children:[_(g.analytics.impressions)," views"]}),e.jsxs("span",{children:[_(g.analytics.likes)," likes"]}),e.jsxs("span",{children:[_(g.analytics.shares)," shares"]})]})]}),e.jsx("h3",{className:"text-[10px] text-cc-muted uppercase tracking-wider font-medium",children:"Post Performance"}),S.map(({post:n,analytics:l})=>e.jsxs("div",{className:"border border-cc-border rounded-xl p-3.5 bg-cc-card space-y-2",children:[e.jsxs("p",{className:"text-[11px] text-cc-fg break-words",children:[n.text.slice(0,120),n.text.length>120?"...":""]}),e.jsxs("div",{className:"flex gap-1 text-[10px]",children:[n.platforms.map(o=>e.jsx(le,{platform:o},o)),e.jsx("span",{className:"text-cc-muted",children:n.createdAt?ne(n.createdAt):""}),l.impressions>0&&e.jsxs("span",{className:"text-cc-muted ml-auto",children:[((l.likes+l.shares+l.comments)/l.impressions*100).toFixed(1),"% eng."]})]}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:[{label:"Views",value:l.impressions},{label:"Likes",value:l.likes},{label:"Shares",value:l.shares},{label:"Comments",value:l.comments}].map(o=>e.jsxs("div",{className:"border border-cc-border/30 rounded-lg p-2 bg-cc-bg text-center",children:[e.jsx("div",{className:"text-sm font-bold text-cc-fg",children:_(o.value)}),e.jsx("div",{className:"text-[8px] text-cc-muted uppercase tracking-wider",children:o.label})]},o.label))})]},n.id))]})})()]})}function Ie({showMessage:t,onSwitchTab:c}){const[i,s]=d.useState(""),[m,j]=d.useState("hosted"),[v,S]=d.useState(""),[P,T]=d.useState(""),[k,C]=d.useState(""),[u,A]=d.useState(""),[g,n]=d.useState([]),[l,o]=d.useState(!1),[b,y]=d.useState(!1),[r,$]=d.useState(!1),[B,a]=d.useState([]),[x,N]=d.useState([]),w=d.useCallback(async()=>{try{const h=await L.getSocialBrowserStatus();N(h.platforms)}catch{}},[]);d.useEffect(()=>{L.getSocialSettings().then(h=>{var F,I;if(s(h.backend||""),A(h.backend||""),(F=h.backends)!=null&&F.postiz){const G=h.backends.postiz.url||"";S(G),T(h.backends.postiz.apiKey||""),j(G&&G!=="https://api.postiz.com"?"selfhosted":"hosted")}(I=h.backends)!=null&&I.buffer&&C(h.backends.buffer.apiKey||""),h.requireApproval&&$(!0),Array.isArray(h.browserPlatforms)&&a(h.browserPlatforms)}).catch(()=>{}),w()},[w]);function E(h){a(F=>F.includes(h)?F.filter(I=>I!==h):[...F,h])}async function R(h){try{const F=await fetch(`/api/socialview/${h}/start`,{method:"POST"});if(!F.ok)throw new Error(`HTTP ${F.status}`);c&&c("view"),t(`Opened ${h} browser — sign in via the noVNC viewer.`),w()}catch(F){t(F instanceof Error?F.message:"Failed to open browser",!0)}}async function p(){const h={};i==="postiz"&&(h.postiz={url:m==="selfhosted"?v:"",apiKey:P}),i==="buffer"&&(h.buffer={apiKey:k}),await L.updateSocialSettings({backend:i||null,backends:h,defaultPlatforms:[],requireApproval:r,browserPlatforms:B}),A(i)}async function U(){o(!0);try{await p(),t("Settings saved.")}catch(h){t(h instanceof Error?h.message:"Failed",!0)}finally{o(!1)}}async function D(){y(!0);try{await p();const h=await L.testSocialConnection();if(h.ok){t("Connection successful!");const F=await L.getSocialProfiles();n(F.profiles||[])}else t("Connection failed: "+(h.error||"unknown"),!0)}catch(h){t(h instanceof Error?h.message:"Failed",!0)}finally{y(!1)}}const O=[{id:"buffer",label:"Buffer",desc:"SaaS — GraphQL API"},{id:"postiz",label:"Postiz",desc:"Hosted or Self-hosted"}];return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Backend"}),e.jsx("p",{className:"text-[9px] text-cc-muted mb-2",children:"One active backend at a time. Switching will replace the current configuration."}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:O.map(h=>e.jsxs("button",{onClick:()=>s(h.id),className:`p-3 rounded-xl border text-left transition-all ${i===h.id?"border-cc-accent bg-cc-accent/10":"border-cc-border bg-cc-card hover:border-cc-accent/30"}`,children:[e.jsxs("div",{className:"text-xs font-medium text-cc-fg flex items-center gap-1.5",children:[h.label,u===h.id&&e.jsx("span",{className:"text-[8px] px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-400 font-medium",children:"Active"})]}),e.jsx("div",{className:"text-[9px] text-cc-muted mt-0.5",children:h.desc})]},h.id))})]}),i==="postiz"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1.5",children:"Hosting"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>j("hosted"),className:`p-2.5 rounded-lg border text-left transition-all ${m==="hosted"?"border-cc-accent bg-cc-accent/10":"border-cc-border bg-cc-card hover:border-cc-accent/30"}`,children:[e.jsx("div",{className:"text-xs font-medium text-cc-fg",children:"Standard"}),e.jsx("div",{className:"text-[9px] text-cc-muted mt-0.5",children:"api.postiz.com"})]}),e.jsxs("button",{onClick:()=>j("selfhosted"),className:`p-2.5 rounded-lg border text-left transition-all ${m==="selfhosted"?"border-cc-accent bg-cc-accent/10":"border-cc-border bg-cc-card hover:border-cc-accent/30"}`,children:[e.jsx("div",{className:"text-xs font-medium text-cc-fg",children:"Self-hosted"}),e.jsx("div",{className:"text-[9px] text-cc-muted mt-0.5",children:"Custom URL"})]})]})]}),m==="selfhosted"&&e.jsx(Y,{label:"Postiz URL",value:v,onChange:S,placeholder:"https://postiz.example.com"}),e.jsx(Y,{label:"API Key",value:P,onChange:T,placeholder:"Settings → Developers → Public API",password:!0})]}),i==="buffer"&&e.jsx(Y,{label:"Buffer API Key",value:k,onChange:C,placeholder:"Access Token from publish.buffer.com/settings/api",password:!0}),i&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:U,disabled:l,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/90 disabled:opacity-50 transition-colors",children:l?"Saving...":"Save"}),e.jsx("button",{onClick:D,disabled:b,className:"px-4 py-2 text-xs font-medium rounded-md text-cc-muted hover:text-cc-fg border border-cc-border hover:border-cc-accent/30 disabled:opacity-50 transition-colors",children:b?"Testing...":"Test Connection"})]}),g.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-[10px] text-cc-muted uppercase tracking-wider font-medium mb-2",children:"Connected Channels"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:g.map(h=>e.jsxs("div",{className:"flex items-center gap-2.5 p-2.5 rounded-lg border border-cc-border/50 bg-cc-card",children:[h.picture?e.jsx("img",{src:h.picture,alt:"",className:"w-7 h-7 rounded-full"}):e.jsx("div",{className:"w-7 h-7 rounded-full bg-cc-accent/10 flex items-center justify-center text-[10px] text-cc-accent font-medium",children:J[h.platform]||"?"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] font-medium text-cc-fg",children:h.name}),e.jsx("div",{className:"text-[9px] text-cc-muted",children:h.platform})]})]},h.id))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-cc-bg border border-cc-border",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-cc-fg",children:"Require Approval"}),e.jsx("div",{className:"text-[9px] text-cc-muted mt-0.5",children:"Voice assistant must get manual approval before publishing"})]}),e.jsx("button",{onClick:()=>$(!r),className:`w-10 h-5 rounded-full transition-colors relative ${r?"bg-cc-accent":"bg-cc-border"}`,children:e.jsx("span",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${r?"left-5":"left-0.5"}`})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider",children:"Browser Posting"}),e.jsx("button",{onClick:w,className:"text-[9px] text-cc-muted hover:text-cc-fg",children:"Refresh status"})]}),e.jsxs("div",{className:"rounded-lg border border-yellow-500/30 bg-yellow-500/5 p-3 text-[10px] text-yellow-200/90",children:[e.jsx("strong",{children:"Account-Risiko:"})," X und TikTok verbieten Automation formell in den ToS. Nutze diese Option nur für eigene Accounts. Die Sessions bleiben lokal in"," ",e.jsx("code",{className:"text-[9px]",children:"~/.heyhank/browser-profiles/<platform>/"})," persistent."]}),["twitter","tiktok"].map(h=>{const F=B.includes(h),I=x.find(K=>K.platform===h),G=h==="twitter"?"X (Twitter)":"TikTok";return e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs font-medium text-cc-fg",children:[G," über Browser posten"]}),e.jsxs("div",{className:"text-[9px] text-cc-muted mt-0.5",children:["Statt ",u||"Postiz"," wird eine persistente Playwright-Session genutzt."]})]}),e.jsx("button",{onClick:()=>E(h),className:`w-10 h-5 rounded-full transition-colors relative ${F?"bg-cc-accent":"bg-cc-border"}`,"aria-label":`Toggle browser posting for ${G}`,children:e.jsx("span",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${F?"left-5":"left-0.5"}`})})]}),F&&e.jsxs("div",{className:"flex items-center justify-between mt-2 pt-2 border-t border-cc-border/50",children:[e.jsx("div",{className:"text-[10px] text-cc-muted",children:I!=null&&I.running?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-green-400",children:"●"})," Running",I.loggedIn===!0&&e.jsx("span",{className:"ml-2 text-green-400",children:"· logged in"}),I.loggedIn===!1&&e.jsx("span",{className:"ml-2 text-yellow-400",children:"· not logged in"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-cc-muted",children:"○"})," Not running",(I==null?void 0:I.hasProfile)&&e.jsx("span",{className:"ml-2",children:"· profile exists"})]})}),e.jsx("button",{onClick:()=>R(h),className:"text-[10px] px-2.5 py-1 rounded-md border border-cc-border hover:border-cc-accent/50 text-cc-fg",children:"Browser öffnen"})]})]},h)})]}),e.jsx(He,{showMessage:t})]})}const Oe=[{key:"popular",label:"Popular",desc:">1M posts, high reach",color:"text-green-400"},{key:"medium",label:"Medium",desc:"100K-1M posts, balanced",color:"text-blue-400"},{key:"niche",label:"Niche",desc:"<100K posts, targeted",color:"text-purple-400"},{key:"branded",label:"Branded",desc:"Your own brand hashtags",color:"text-cc-accent"},{key:"blocked",label:"Blocked",desc:"Never use these",color:"text-red-400"}];function He({showMessage:t}){const[c,i]=d.useState([]),[s,m]=d.useState(null),[j,v]=d.useState(!1),[S,P]=d.useState(!1),T=d.useCallback(async()=>{try{const n=await L.listHashtagPools();i(n.pools||[])}catch{}},[]);d.useEffect(()=>{T()},[T]);function k(){m({id:"",name:"",industry:"",language:"de",popular:[],medium:[],niche:[],branded:[],blocked:[],createdAt:"",updatedAt:""}),v(!0)}function C(n){m({...n}),v(!1)}async function u(){if(!s||!s.name.trim()){t("Name is required",!0);return}P(!0);try{j?await L.createHashtagPool(s):await L.updateHashtagPool(s.id,s),t("Hashtag pool saved."),m(null),await T()}catch(n){t(n instanceof Error?n.message:"Failed to save",!0)}finally{P(!1)}}async function A(n){if(confirm(`Delete hashtag pool "${n.name}"?`))try{await L.deleteHashtagPool(n.id),t("Pool deleted."),await T()}catch(l){t(l instanceof Error?l.message:"Failed",!0)}}function g(n,l){if(!s)return;const o=l.split(/[,\n]/).map(b=>b.trim()).filter(Boolean).map(b=>b.startsWith("#")?b:`#${b}`);m({...s,[n]:o})}return s?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-[10px] text-cc-muted uppercase tracking-wider font-medium",children:j?"New Hashtag Pool":"Edit Hashtag Pool"}),e.jsx("button",{onClick:()=>m(null),className:"text-[10px] text-cc-muted hover:text-cc-fg",children:"Cancel"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(Y,{label:"Business / Brand Name",value:s.name,onChange:n=>m({...s,name:n}),placeholder:"e.g. Ferienhaus Steiermark"}),e.jsx(Y,{label:"Industry",value:s.industry,onChange:n=>m({...s,industry:n}),placeholder:"e.g. tourism, saas, fashion"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted block mb-1",children:"Language"}),e.jsxs("select",{value:s.language,onChange:n=>m({...s,language:n.target.value}),className:"bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg focus:outline-none focus:border-cc-accent/50",children:[e.jsx("option",{value:"de",children:"Deutsch"}),e.jsx("option",{value:"en",children:"English"}),e.jsx("option",{value:"fr",children:"French"}),e.jsx("option",{value:"es",children:"Spanish"}),e.jsx("option",{value:"it",children:"Italian"})]})]}),Oe.map(({key:n,label:l,desc:o,color:b})=>e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] text-cc-muted block mb-1",children:[e.jsx("span",{className:b,children:l}),e.jsx("span",{className:"ml-1.5 text-cc-muted/60",children:o})]}),e.jsx("textarea",{value:s[n].join(", "),onChange:y=>g(n,y.target.value),placeholder:"#tag1, #tag2, #tag3",rows:2,className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg focus:outline-none focus:border-cc-accent/50 resize-none"}),e.jsxs("div",{className:"text-[9px] text-cc-muted/50 mt-0.5",children:[s[n].length," hashtags"]})]},n)),e.jsx("button",{onClick:u,disabled:S,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/90 disabled:opacity-50 transition-colors",children:S?"Saving...":j?"Create Pool":"Save Changes"})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[10px] text-cc-muted uppercase tracking-wider font-medium",children:"Hashtag Pools"}),e.jsx("p",{className:"text-[9px] text-cc-muted mt-0.5",children:"Curated hashtag sets per business. The Content Agent picks from these automatically."})]}),e.jsx("button",{onClick:k,className:"px-3 py-1.5 text-[10px] font-medium rounded-md bg-cc-accent/10 text-cc-accent hover:bg-cc-accent/20 border border-cc-accent/20 transition-colors",children:"+ New Pool"})]}),c.length===0?e.jsxs("div",{className:"text-center py-6 border border-dashed border-cc-border rounded-lg",children:[e.jsx("p",{className:"text-xs text-cc-muted mb-1",children:"No hashtag pools yet"}),e.jsx("p",{className:"text-[9px] text-cc-muted/60",children:"Create a pool to give the Content Agent curated hashtags for your businesses."})]}):e.jsx("div",{className:"space-y-2",children:c.map(n=>{const l=n.popular.length+n.medium.length+n.niche.length+n.branded.length;return e.jsxs("div",{className:"p-3 rounded-lg border border-cc-border bg-cc-card",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-cc-fg",children:n.name}),e.jsxs("div",{className:"text-[9px] text-cc-muted mt-0.5",children:[n.industry&&e.jsxs("span",{children:[n.industry," · "]}),l," hashtags",n.blocked.length>0&&e.jsxs("span",{children:[" · ",n.blocked.length," blocked"]})]})]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>C(n),className:"text-[10px] text-cc-muted hover:text-cc-accent transition-colors",children:"Edit"}),e.jsx("button",{onClick:()=>A(n),className:"text-[10px] text-cc-muted hover:text-red-400 transition-colors",children:"Delete"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[n.popular.slice(0,3).map(o=>e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-green-500/10 text-green-400 border border-green-500/20",children:o},o)),n.medium.slice(0,3).map(o=>e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-blue-500/10 text-blue-400 border border-blue-500/20",children:o},o)),n.niche.slice(0,2).map(o=>e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 border border-purple-500/20",children:o},o)),n.branded.slice(0,2).map(o=>e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-cc-accent/10 text-cc-accent border border-cc-accent/20",children:o},o)),l>10&&e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 text-cc-muted",children:["+",l-10," more"]})]})]},n.id)})})]})}function Y({label:t,value:c,onChange:i,placeholder:s,password:m}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted block mb-1",children:t}),e.jsx("input",{type:m?"password":"text",value:c,onChange:j=>i(j.target.value),placeholder:s,className:"w-full bg-cc-bg border border-cc-border rounded-md p-2 text-xs text-cc-fg focus:outline-none focus:border-cc-accent/50"})]})}function he({text:t}){return e.jsxs("div",{className:"text-center py-12",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-8 h-8 text-cc-muted/20 mx-auto mb-3",children:e.jsx("path",{d:"M8 0a8 8 0 100 16A8 8 0 008 0zm3.5 5.3l-1 4.5a.75.75 0 01-.37.47.73.73 0 01-.58.05L7.7 9.58l-1.22 1.18a.25.25 0 01-.43-.17V9.13L10.5 5l-4.4 3.56-1.7-.56a.5.5 0 01-.02-.94l8.5-3.5a.5.5 0 01.62.74z"})}),e.jsx("p",{className:"text-xs text-cc-muted",children:t})]})}function be({status:t}){const c={published:"text-green-400 border-green-400/30 bg-green-400/5",scheduled:"text-cc-accent border-cc-accent/30 bg-cc-accent/5",failed:"text-red-400 border-red-400/30 bg-red-400/5",draft:"text-yellow-400 border-yellow-400/30 bg-yellow-400/5",partial:"text-orange-400 border-orange-400/30 bg-orange-400/5",archived:"text-cc-muted border-cc-border/50 bg-cc-bg"};return e.jsx("span",{className:`inline-block text-[9px] font-medium uppercase tracking-wider border rounded-full px-1.5 py-0.5 ${c[t]||c.draft}`,children:t})}function fe({by:t}){const c={gemini:"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300",agent:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300",user:"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400"},i=t==="gemini"?"Voice":t==="agent"?"Agent":"Manual";return e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${c[t]||c.user}`,children:i})}function le({platform:t}){return e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] font-medium text-cc-accent/80 border border-cc-accent/20 bg-cc-accent/5 rounded-full px-1.5 py-0.5",children:[e.jsx("span",{className:"text-[8px]",children:J[t]||""}),t]})}function Ve({open:t,onClose:c,onSelect:i}){const[s,m]=d.useState([]),[j,v]=d.useState(new Set),[S,P]=d.useState(!0);if(d.useEffect(()=>{t&&(P(!0),v(new Set),L.listMedia().then(k=>{m((k.files||k.media||[]).filter(C=>!C.type||C.type.startsWith("image/")))}).catch(()=>{}).finally(()=>P(!1)))},[t]),!t)return null;function T(k){v(C=>{const u=new Set(C);return u.has(k)?u.delete(k):u.add(k),u})}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:c,children:e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl w-full max-w-lg max-h-[70vh] flex flex-col",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-cc-border",children:[e.jsx("h3",{className:"text-sm font-semibold text-cc-fg",children:"Media Library"}),e.jsx("button",{onClick:c,className:"text-cc-muted hover:text-cc-fg text-lg",children:"×"})]}),e.jsx("div",{className:"flex-1 overflow-auto p-3",children:S?e.jsx("p",{className:"text-xs text-cc-muted text-center py-8",children:"Loading..."}):s.length===0?e.jsx("p",{className:"text-xs text-cc-muted text-center py-8",children:"No images found. Generate images via Hank or upload files."}):e.jsx("div",{className:"grid grid-cols-4 gap-2",children:s.map(k=>e.jsxs("button",{onClick:()=>T(`/api/media/file/${k.filename}`),className:`relative aspect-square rounded-lg overflow-hidden border-2 transition-all ${j.has(`/api/media/file/${k.filename}`)?"border-cc-accent ring-2 ring-cc-accent/30":"border-transparent hover:border-cc-border"}`,children:[e.jsx("img",{src:`/api/media/file/${k.filename}`,alt:k.filename,className:"w-full h-full object-cover"}),j.has(`/api/media/file/${k.filename}`)&&e.jsx("div",{className:"absolute top-1 right-1 w-5 h-5 rounded-full bg-cc-accent text-white flex items-center justify-center text-[10px] font-bold",children:"✓"})]},k.filename))})}),j.size>0&&e.jsxs("div",{className:"p-3 border-t border-cc-border flex justify-between items-center",children:[e.jsxs("span",{className:"text-xs text-cc-muted",children:[j.size," selected"]}),e.jsx("button",{onClick:()=>{i(Array.from(j)),c()},className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/90 transition-colors",children:"Attach Selected"})]})]})})}export{Me as SocialMediaPage};