libre-webui 0.45.0 → 0.45.1

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 (94) hide show
  1. package/backend/dist/utils/decisionProtocol.d.ts.map +1 -1
  2. package/backend/dist/utils/decisionProtocol.js +3 -1
  3. package/backend/dist/utils/decisionProtocol.js.map +1 -1
  4. package/backend/package.json +1 -1
  5. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  6. package/frontend/dist/assets/index-MveXWX7i.js +15 -0
  7. package/frontend/dist/index.html +20 -20
  8. package/frontend/dist/js/{ArtifactContainer-DCCcjK16.js → ArtifactContainer-BiGwAZkv.js} +1 -1
  9. package/frontend/dist/js/{ArtifactDemoPage-C-1acgxJ.js → ArtifactDemoPage-Dk6bf2fr.js} +1 -1
  10. package/frontend/dist/js/{ArtifactSandboxFrame-BXWNhmtI.js → ArtifactSandboxFrame-BMQXP8E8.js} +1 -1
  11. package/frontend/dist/js/{ArtifactSlideOutPanel-CvfdP_o2.js → ArtifactSlideOutPanel-CNLSDJAJ.js} +1 -1
  12. package/frontend/dist/js/{AutomationModal-D7qiRMhj.js → AutomationModal-VMrwN5y4.js} +1 -1
  13. package/frontend/dist/js/{AutomationsPage-v98Ucl9p.js → AutomationsPage-wb5royf_.js} +1 -1
  14. package/frontend/dist/js/{AvatarUpload-W41SCHKE.js → AvatarUpload-DpeJzlyv.js} +1 -1
  15. package/frontend/dist/js/{CalendarPage-DkAa61Pa.js → CalendarPage-DeMdx8BD.js} +1 -1
  16. package/frontend/dist/js/{ChannelsPage-0Vnfpgdr.js → ChannelsPage-DJj_kG1m.js} +1 -1
  17. package/frontend/dist/js/{ChatPage-iyMY-uoE.js → ChatPage-tJ5_eAbV.js} +2 -2
  18. package/frontend/dist/js/{ConnectModels-CpWO6ALS.js → ConnectModels-7E_zzkFc.js} +1 -1
  19. package/frontend/dist/js/{EvaluationsPage-C7WHA1MJ.js → EvaluationsPage-_jLiPYYc.js} +1 -1
  20. package/frontend/dist/js/{FirstTimeSetup-B8wcelBc.js → FirstTimeSetup-BzSil7F7.js} +1 -1
  21. package/frontend/dist/js/{GalleryPage-u7dYKl3q.js → GalleryPage-CKpQMmd7.js} +1 -1
  22. package/frontend/dist/js/{HomePage-Cjlt3b9n.js → HomePage-Dr8mrmo7.js} +1 -1
  23. package/frontend/dist/js/{LanguageSwitcher-gbTZY15P.js → LanguageSwitcher-BPwDwNez.js} +1 -1
  24. package/frontend/dist/js/{ModelManagerModals-12hL-b-U.js → ModelManagerModals-eAwih0CC.js} +1 -1
  25. package/frontend/dist/js/{NotesPage-BQWBA5li.js → NotesPage-DDagHzg0.js} +1 -1
  26. package/frontend/dist/js/{PasswordStrengthMeter-DdqX0FXA.js → PasswordStrengthMeter-BwgYbk3r.js} +1 -1
  27. package/frontend/dist/js/{PersonasPage-B8mFdWcX.js → PersonasPage-uFr0Yzes.js} +1 -1
  28. package/frontend/dist/js/{PluginUsagePage-Uz6aHPIp.js → PluginUsagePage-BfIQuqIV.js} +1 -1
  29. package/frontend/dist/js/{RichMessageContent-CVk-fp0N.js → RichMessageContent-BY1I7d9d.js} +1 -1
  30. package/frontend/dist/js/{RichMessageContent-DwMoWuR_.js → RichMessageContent-otmciPPz.js} +1 -1
  31. package/frontend/dist/js/SettingsModal-D2x0muLa.js +19 -0
  32. package/frontend/dist/js/{ShareDialog-NwirTDLR.js → ShareDialog-DgVAGGOp.js} +1 -1
  33. package/frontend/dist/js/{StrandsPage-ddHNdb6J.js → StrandsPage-9UVviZ58.js} +1 -1
  34. package/frontend/dist/js/{SystemPage-C_1exwI7.js → SystemPage-ChJ8O0MR.js} +1 -1
  35. package/frontend/dist/js/{UserManagementPanel-hg7ztEtL.js → UserManagementPanel-CYuTltw4.js} +1 -1
  36. package/frontend/dist/js/{WhatsNewModal-yYk7N4KY.js → WhatsNewModal-DyK_LXtM.js} +1 -1
  37. package/frontend/dist/js/{WorkPage-i7yYRAuj.js → WorkPage-CdfTyNv_.js} +1 -1
  38. package/frontend/dist/js/{api-Dasm8tVY.js → api-BPTwf2O4.js} +1 -1
  39. package/frontend/dist/js/api-Lutao9vm.js +1 -0
  40. package/frontend/dist/js/{appNavigation-DqP7fTWU.js → appNavigation-DYXehtYu.js} +1 -1
  41. package/frontend/dist/js/{appStore-DCIUnT8X.js → appStore-C_SBNGJT.js} +2 -2
  42. package/frontend/dist/js/appVersion-C5-Afzj1.js +1 -0
  43. package/frontend/dist/js/{ar-CsCftCVF.js → ar-CMnK2iUi.js} +1 -1
  44. package/frontend/dist/js/authStore-6cAmoXEk.js +1 -0
  45. package/frontend/dist/js/{authStore-ac5-hjOH.js → authStore-Tu09JYbR.js} +3 -3
  46. package/frontend/dist/js/{bn-CvxUTZ9a.js → bn-B_6kDlG3.js} +1 -1
  47. package/frontend/dist/js/{chatStore-GhucyjJu.js → chatStore-wi8VDo6B.js} +3 -3
  48. package/frontend/dist/js/{client-DxPoTB_C.js → client-Czyqg89i.js} +2 -2
  49. package/frontend/dist/js/{config-CQJEcQtz.js → config-DWmMmE_t.js} +1 -1
  50. package/frontend/dist/js/{cs-BovmMwcD.js → cs-DN4IeMBM.js} +1 -1
  51. package/frontend/dist/js/{da-Dof1gmsv.js → da-Cx-BiRSz.js} +1 -1
  52. package/frontend/dist/js/{de-CF9CXojW.js → de-Cwlx8oC5.js} +1 -1
  53. package/frontend/dist/js/{decisionsApi-BWB64EGn.js → decisionsApi-CftWDIPz.js} +1 -1
  54. package/frontend/dist/js/decisionsApi-Dneh1e4n.js +1 -0
  55. package/frontend/dist/js/{es-BXCt50HZ.js → es-DGOk1LTg.js} +1 -1
  56. package/frontend/dist/js/{evaluationsApi-CBqKkjmI.js → evaluationsApi-C5DC-61t.js} +1 -1
  57. package/frontend/dist/js/{fr-B5QcCDIw.js → fr-DsjFEubC.js} +1 -1
  58. package/frontend/dist/js/{hi-BXYwSyKl.js → hi-YoyZTSWi.js} +1 -1
  59. package/frontend/dist/js/{id-BV3mY5L7.js → id-D7ObCsR9.js} +1 -1
  60. package/frontend/dist/js/{is-BDK4LrQC.js → is-DRfnKDHX.js} +1 -1
  61. package/frontend/dist/js/{it-DAeWl1Fm.js → it-Cb4C73dp.js} +1 -1
  62. package/frontend/dist/js/{ja-DIJV01rA.js → ja-DsDfWEWn.js} +1 -1
  63. package/frontend/dist/js/{ko-Btr9-64X.js → ko-J9IK9O8f.js} +1 -1
  64. package/frontend/dist/js/{messageCodeStyles-BugWE4s5.js → messageCodeStyles-DbG-nHEj.js} +1 -1
  65. package/frontend/dist/js/modelPresentation-4QU9r-Pl.js +1 -0
  66. package/frontend/dist/js/{ms-DgVmv5zF.js → ms-DVZBQWu-.js} +1 -1
  67. package/frontend/dist/js/{nl-Dz5HpdLi.js → nl-CotrV0Lb.js} +1 -1
  68. package/frontend/dist/js/{pl-CIATY2b0.js → pl-DlsgTT5q.js} +1 -1
  69. package/frontend/dist/js/{pt-lrDXX76Y.js → pt-B8F-CAdb.js} +1 -1
  70. package/frontend/dist/js/{ru-_zovUYcg.js → ru-B7H_WJLM.js} +1 -1
  71. package/frontend/dist/js/{strandsApi-Ck7FrcHH.js → strandsApi-c_sLVTzl.js} +1 -1
  72. package/frontend/dist/js/{sv-TkRDWCb8.js → sv-iYQWY_4T.js} +1 -1
  73. package/frontend/dist/js/{teamEventStream-O3qGbUZz.js → teamEventStream-Bnna_p2v.js} +1 -1
  74. package/frontend/dist/js/{th-CQyavDiP.js → th-BIlkYCg9.js} +1 -1
  75. package/frontend/dist/js/{tr-CBcFl4_Z.js → tr-Cb0GxFvG.js} +1 -1
  76. package/frontend/dist/js/{ui-DxaHE9GD.js → ui-Byzdw4-Y.js} +2 -2
  77. package/frontend/dist/js/{ui-vendor-DsURZnZt.js → ui-vendor-C7v9zeJX.js} +1 -1
  78. package/frontend/dist/js/{uk-BNn1cUt8.js → uk-BH7Ojiob.js} +1 -1
  79. package/frontend/dist/js/{useChat-1HyAPpCk.js → useChat-DGCDsOOs.js} +1 -1
  80. package/frontend/dist/js/useDictation-BGys860H.js +1 -0
  81. package/frontend/dist/js/{vi-Be8GO7e_.js → vi-BKN3n9CC.js} +1 -1
  82. package/frontend/dist/js/{workApi-BNGRSv7q.js → workApi-BTdJF6o5.js} +1 -1
  83. package/frontend/dist/js/workApi-DvXvzA8C.js +1 -0
  84. package/frontend/dist/js/{zh-9CUKyYw5.js → zh-CbiVZpr_.js} +1 -1
  85. package/package.json +1 -1
  86. package/frontend/dist/assets/index-C2A5Ko4-.js +0 -59
  87. package/frontend/dist/js/SettingsModal-CfjxNSmJ.js +0 -19
  88. package/frontend/dist/js/api-BU13N8gU.js +0 -1
  89. package/frontend/dist/js/appVersion-PJGaVilS.js +0 -1
  90. package/frontend/dist/js/authStore-Bp17zKvS.js +0 -1
  91. package/frontend/dist/js/decisionsApi-CoJtg4PZ.js +0 -1
  92. package/frontend/dist/js/thinking-DwlkTfPX.js +0 -1
  93. package/frontend/dist/js/useDictation-B3vNgs5D.js +0 -1
  94. package/frontend/dist/js/workApi-C5jw1ra6.js +0 -1
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{a as r,l as i,n as a,o,r as s,t as c}from"./artifactHtml-DDmfpcB0.js";import{t as l}from"./config-CQJEcQtz.js";import{t as u}from"./logger-DAQsBb8I.js";var d=e(t(),1),f=`${l.replace(/\/+$/,``)}/artifacts/sandbox`,p=window.location.protocol===`file:`?new URL(f).origin:window.location.origin,m=`/artifact-runtime`,h=`runtime`,g=`react`,_=`babel`,v=`tailwind`,y=`fonts`,b={react:g,"react-dom":g,"react-dom/client":g,"react/jsx-runtime":g,"react/jsx-dev-runtime":g,recharts:`recharts`,"lucide-react":`lucide-react`,d3:`d3`,three:`three`,papaparse:`papaparse`,lodash:`lodash`,"lodash-es":`lodash`,mermaid:`mermaid`,"chart.js":`chart`,"chart.js/auto":`chart`,tone:`tone`,mathjs:`mathjs`,"plotly.js":`plotly`,"plotly.js-dist-min":`plotly`,"framer-motion":`framer-motion`,"motion/react":`framer-motion`,motion:`framer-motion`,"three/addons/controls/OrbitControls.js":`three`,"three/examples/jsm/controls/OrbitControls.js":`three`},x=[h,g,_,v],S=[h,`mermaid`],C=[{pattern:/cdn\.tailwindcss\.com/i,bundle:v},{pattern:/(?:^|\/)tailwindcss(?:@[\d.]+)?(?:\/|$)/i,bundle:v},{pattern:/(?:^|\/)chart\.js(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)chart(?:\.min)?\.js(?:$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)d3(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)d3(?:\.min)?\.js(?:$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)three(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`three`},{pattern:/(?:^|\/)three(?:\.min)?\.js(?:$|\?)/i,bundle:`three`},{pattern:/papaparse/i,bundle:`papaparse`},{pattern:/(?:^|\/)lodash(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`lodash`},{pattern:/(?:^|\/)lodash(?:\.min)?\.js(?:$|\?)/i,bundle:`lodash`},{pattern:/fonts\.(?:googleapis|gstatic)\.com/i,bundle:y},{pattern:/mermaid/i,bundle:`mermaid`},{pattern:/(?:^|\/)tone(?:@[\d.]+)?(?:\/|$|\?)|tone(?:\.min)?\.js/i,bundle:`tone`},{pattern:/mathjs|math(?:\.min)?\.js/i,bundle:`mathjs`},{pattern:/plotly/i,bundle:`plotly`},{pattern:/framer-motion|(?:^|\/)motion(?:@[\d.]+)?(?:\/|$)/i,bundle:`framer-motion`},{pattern:/react-dom/i,bundle:g},{pattern:/(?:^|\/)react(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:g},{pattern:/babel(?:-standalone|\/standalone)/i,bundle:_}],w=`__libreArtifactRuntime`;function T(e){if(b[e])return e;let t=C.find(({pattern:t})=>t.test(e))?.bundle??Object.values(b).find(t=>e.startsWith(`${t}/`));return t?Object.entries(b).find(([,e])=>e===t)?.[0]??null:null}function E(e){let t=new Set,n=e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g);for(let[,e]of n){let n=T(e);n&&t.add(b[n])}return[...t]}var D=/\b(?:flex|grid|hidden|absolute|relative|(?:p|m|px|py|mx|my|mt|mb|ml|mr|gap|space)-\d|(?:w|h|max-w|min-h)-(?:\d|full|screen|auto)|text-(?:xs|sm|base|lg|xl|\dxl|center|left|right|white|black|gray-\d)|bg-(?:white|black|transparent|[a-z]+-\d)|rounded(?:-[a-z]+)?|shadow(?:-[a-z]+)?|border(?:-\d)?|items-(?:center|start|end)|justify-(?:center|between|around|end)|font-(?:bold|medium|semibold|light)|hover:[a-z-]+|(?:sm|md|lg|xl):[a-z-]+)\b/g;function O(e){let t=[...e.matchAll(/class\s*=\s*("|')(.*?)\1/gi)].map(e=>e[2]).join(` `);return new Set(t.match(D)??[]).size>=3}function k(e){let t=new Set;for(let[n,r]of Object.entries(b)){let i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:from|import|require)\\s*\\(?\\s*['"\`]${i}['"\`]`).test(e)&&t.add(r)}return[...t]}function A(e){return C.find(({pattern:t})=>t.test(e))?.bundle??null}function j(e){let t=new Set;for(let n of e.matchAll(/\b(?:src|href)\s*=\s*("|')(.*?)\1/gi))t.add(n[2]);for(let n of e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g))t.add(n[1]);return[...t]}function M(e){let t=new Set;for(let n of j(e)){let e=A(n);e&&t.add(e)}return[...t]}var N=`37169eff0076bd58`,P=new Map;function F(e){let t=P.get(e);if(t)return t;let n=fetch(`${p}${m}/${e}.js?v=${N}`,{credentials:`same-origin`,cache:`no-cache`}).then(t=>{if(!t.ok)throw Error(`The artifact runtime bundle "${e}" is unavailable (HTTP ${t.status}).`);return t.text()});return n.catch(()=>P.delete(e)),P.set(e,n),n}async function I(e){let t=await Promise.all(e.map(F));return Object.fromEntries(e.map((e,n)=>[e,t[n]]))}var L=`
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{a as r,l as i,n as a,o,r as s,t as c}from"./artifactHtml-DDmfpcB0.js";import{t as l}from"./config-DWmMmE_t.js";import{t as u}from"./logger-DAQsBb8I.js";var d=e(t(),1),f=`${l.replace(/\/+$/,``)}/artifacts/sandbox`,p=window.location.protocol===`file:`?new URL(f).origin:window.location.origin,m=`/artifact-runtime`,h=`runtime`,g=`react`,_=`babel`,v=`tailwind`,y=`fonts`,b={react:g,"react-dom":g,"react-dom/client":g,"react/jsx-runtime":g,"react/jsx-dev-runtime":g,recharts:`recharts`,"lucide-react":`lucide-react`,d3:`d3`,three:`three`,papaparse:`papaparse`,lodash:`lodash`,"lodash-es":`lodash`,mermaid:`mermaid`,"chart.js":`chart`,"chart.js/auto":`chart`,tone:`tone`,mathjs:`mathjs`,"plotly.js":`plotly`,"plotly.js-dist-min":`plotly`,"framer-motion":`framer-motion`,"motion/react":`framer-motion`,motion:`framer-motion`,"three/addons/controls/OrbitControls.js":`three`,"three/examples/jsm/controls/OrbitControls.js":`three`},x=[h,g,_,v],S=[h,`mermaid`],C=[{pattern:/cdn\.tailwindcss\.com/i,bundle:v},{pattern:/(?:^|\/)tailwindcss(?:@[\d.]+)?(?:\/|$)/i,bundle:v},{pattern:/(?:^|\/)chart\.js(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)chart(?:\.min)?\.js(?:$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)d3(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)d3(?:\.min)?\.js(?:$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)three(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`three`},{pattern:/(?:^|\/)three(?:\.min)?\.js(?:$|\?)/i,bundle:`three`},{pattern:/papaparse/i,bundle:`papaparse`},{pattern:/(?:^|\/)lodash(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`lodash`},{pattern:/(?:^|\/)lodash(?:\.min)?\.js(?:$|\?)/i,bundle:`lodash`},{pattern:/fonts\.(?:googleapis|gstatic)\.com/i,bundle:y},{pattern:/mermaid/i,bundle:`mermaid`},{pattern:/(?:^|\/)tone(?:@[\d.]+)?(?:\/|$|\?)|tone(?:\.min)?\.js/i,bundle:`tone`},{pattern:/mathjs|math(?:\.min)?\.js/i,bundle:`mathjs`},{pattern:/plotly/i,bundle:`plotly`},{pattern:/framer-motion|(?:^|\/)motion(?:@[\d.]+)?(?:\/|$)/i,bundle:`framer-motion`},{pattern:/react-dom/i,bundle:g},{pattern:/(?:^|\/)react(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:g},{pattern:/babel(?:-standalone|\/standalone)/i,bundle:_}],w=`__libreArtifactRuntime`;function T(e){if(b[e])return e;let t=C.find(({pattern:t})=>t.test(e))?.bundle??Object.values(b).find(t=>e.startsWith(`${t}/`));return t?Object.entries(b).find(([,e])=>e===t)?.[0]??null:null}function E(e){let t=new Set,n=e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g);for(let[,e]of n){let n=T(e);n&&t.add(b[n])}return[...t]}var D=/\b(?:flex|grid|hidden|absolute|relative|(?:p|m|px|py|mx|my|mt|mb|ml|mr|gap|space)-\d|(?:w|h|max-w|min-h)-(?:\d|full|screen|auto)|text-(?:xs|sm|base|lg|xl|\dxl|center|left|right|white|black|gray-\d)|bg-(?:white|black|transparent|[a-z]+-\d)|rounded(?:-[a-z]+)?|shadow(?:-[a-z]+)?|border(?:-\d)?|items-(?:center|start|end)|justify-(?:center|between|around|end)|font-(?:bold|medium|semibold|light)|hover:[a-z-]+|(?:sm|md|lg|xl):[a-z-]+)\b/g;function O(e){let t=[...e.matchAll(/class\s*=\s*("|')(.*?)\1/gi)].map(e=>e[2]).join(` `);return new Set(t.match(D)??[]).size>=3}function k(e){let t=new Set;for(let[n,r]of Object.entries(b)){let i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:from|import|require)\\s*\\(?\\s*['"\`]${i}['"\`]`).test(e)&&t.add(r)}return[...t]}function A(e){return C.find(({pattern:t})=>t.test(e))?.bundle??null}function j(e){let t=new Set;for(let n of e.matchAll(/\b(?:src|href)\s*=\s*("|')(.*?)\1/gi))t.add(n[2]);for(let n of e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g))t.add(n[1]);return[...t]}function M(e){let t=new Set;for(let n of j(e)){let e=A(n);e&&t.add(e)}return[...t]}var N=`5aa820254e92c469`,P=new Map;function F(e){let t=P.get(e);if(t)return t;let n=fetch(`${p}${m}/${e}.js?v=${N}`,{credentials:`same-origin`,cache:`no-cache`}).then(t=>{if(!t.ok)throw Error(`The artifact runtime bundle "${e}" is unavailable (HTTP ${t.status}).`);return t.text()});return n.catch(()=>P.delete(e)),P.set(e,n),n}async function I(e){let t=await Promise.all(e.map(F));return Object.fromEntries(e.map((e,n)=>[e,t[n]]))}var L=`
2
2
  html, body { margin: 0; min-height: 100%; }
3
3
  body {
4
4
  background: #ffffff;
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{An as ee,En as te,Ln as a,Nn as ne,Or as re,Qn as ie,Rn as o,Zn as ae,er as s,g as c,n as oe,rn as se,tn as ce,yn as l}from"./ui-vendor-DsURZnZt.js";import{t as u}from"./Button-D6d7HYoa.js";import{t as d}from"./OptimizedSyntaxHighlighter-B8vbflQA.js";import{t as f}from"./ArtifactSandboxFrame-BXWNhmtI.js";import{t as le}from"./appStore-DCIUnT8X.js";import{E as ue,t as de}from"./chatStore-GhucyjJu.js";import{i as fe,r as pe}from"./artifactHtml-DDmfpcB0.js";import{t as p}from"./utils-BXRzbHJC.js";import{t as m}from"./logger-DAQsBb8I.js";var h=e(t(),1),me=n(),g=r(),he=m(`components:artifact-slide-out-panel`),_=320,ge=.9,_e=400,ve=`(min-width: 768px)`,ye=`(min-width: 1024px)`,v=e=>{let[t,n]=(0,h.useState)(()=>typeof window<`u`&&window.matchMedia(e).matches);return(0,h.useEffect)(()=>{let t=window.matchMedia(e),r=()=>n(t.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t},y=()=>{let{t:e,i18n:t}=i(),n=ue(t.language),{artifactPanelOpen:r,artifactPanelArtifact:m,openArtifactPanel:y,closeArtifactPanel:b,theme:x,artifactPanelWidth:S,setArtifactPanelWidth:C,artifactPanelResizing:w,setArtifactPanelResizing:T,sidebarOpen:E,sidebarCompact:D}=le(),O=v(ve),k=v(ye)?E?D?64:288:0:E&&D?64:0,A=(0,h.useCallback)(()=>O?Math.max(_,window.innerWidth-k-_e):window.innerWidth*ge,[O,k]),j=de(e=>e.currentSession),M=h.useMemo(()=>{if(!m)return[];let e=m.title.trim().toLowerCase(),t=(j?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===m.id||e.content===m.content)?t:[...t,m]},[j,m]),N=M.findIndex(e=>e.id===m?.id);N===-1&&m&&(N=M.findIndex(e=>e.content===m.content));let[P,F]=(0,h.useState)(!1),[I,L]=(0,h.useState)(`preview`),R=(0,h.useRef)(null),z=(0,h.useRef)(null),B=(0,h.useRef)(0),V=(0,h.useRef)(0),H=(0,h.useRef)(null),U=(0,h.useRef)(null),W=(0,h.useRef)(S),G=m?.id??null;G!==z.current&&(z.current=G,I!==`preview`&&L(`preview`));let K=(0,h.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,C(W.current)}))},[C]),q=(0,h.useCallback)(()=>{H.current=null,T(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,C(W.current))},[T,C]),be=(0,h.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=S,B.current=e.clientX,W.current=S,e.currentTarget.setPointerCapture(e.pointerId),T(!0)},[S,T]),xe=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=n?e.key===`ArrowRight`:e.key===`ArrowLeft`,r=e.shiftKey?96:24;C(Math.min(A(),Math.max(_,S+(t?r:-r))))},J=(0,h.useCallback)(e=>{if(!w||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=Math.min(A(),Math.max(_,V.current+t));K(r)},[w,n,K,A]);if((0,h.useEffect)(()=>{if(!w){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[w,J,q]),(0,h.useEffect)(()=>{let e=()=>{let e=A();S>e&&C(e)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[S,C,A]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{e.key===`Escape`&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,b,O]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{w||R.current&&!R.current.contains(e.target)&&r&&b()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,b,w,O]),!m)return null;let Y=m,Se=async t=>{try{await navigator.clipboard.writeText(t),F(!0),setTimeout(()=>F(!1),2e3)}catch(t){he.error(`Failed to copy:`,t),re.error(e(`chat.message.copyFailed`))}},Ce=()=>{let e=Y.type===`html`?pe(Y.content,Y.title):Y.content,t=new Blob([e],{type:we(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${Te(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},we=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},Te=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},Ee=()=>{switch(Y.type){case`html`:return(0,g.jsx)(se,{className:`h-5 w-5`});case`react`:return(0,g.jsx)(a,{className:`h-5 w-5`});case`svg`:return(0,g.jsx)(l,{className:`h-5 w-5`});case`code`:return(0,g.jsx)(a,{className:`h-5 w-5`});default:return(0,g.jsx)(l,{className:`h-5 w-5`})}},X=()=>(0,g.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,g.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,g.jsx)(c,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,g.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,g.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,g.jsxs)(u,{variant:`outline`,size:`sm`,onClick:()=>L(`code`),className:`mt-4`,children:[(0,g.jsx)(o,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Z=e=>Y.content.trim()?(0,g.jsx)(f,{content:Y.content,title:Y.title,kind:e,colorScheme:x.mode===`light`?`light`:`dark`,className:p(`w-full h-full border-0 rounded-lg bg-white`,w&&`pointer-events-none`),fallback:X()}):X(),De=()=>(0,g.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:fe(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(d,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:x.mode!==`light`,className:`m-0! rounded-lg! h-full!`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:Y.content})}),Oe=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(d,{language:`json`,isDark:x.mode!==`light`,className:`m-0! rounded-lg! h-full!`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:t})})}catch{return(0,g.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,g.jsxs)(`div`,{className:`text-center`,children:[(0,g.jsx)(c,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,g.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},ke=()=>{if(I===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return De();case`json`:return Oe();default:return Q()}},Ae=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,je=$?`100%`:`${S}px`,Me=(0,g.jsxs)(g.Fragment,{children:[!O&&(0,g.jsx)(`div`,{className:p(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),w&&(0,g.jsx)(`div`,{className:p(`fixed inset-0 cursor-col-resize select-none`,O?`z-40`:`z-55`),"aria-hidden":`true`}),(0,g.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:je},className:p(`fixed top-0 inset-e-0 h-full`,O?`z-30`:`z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,g.jsxs)(`div`,{onPointerDown:be,onKeyDown:xe,role:`separator`,"aria-orientation":`vertical`,tabIndex:0,"aria-label":e(`artifacts.resizePanel`),"aria-valuenow":Math.round(S),"aria-valuemin":_,"aria-valuemax":Math.round(A()),"data-testid":`artifact-resize-handle`,title:e(`artifacts.dragEdgeToResize`),className:p(`focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500`,`absolute inset-s-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-56`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,g.jsx)(`div`,{className:p(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24 group-focus-visible:bg-primary-500`,w&&`bg-primary-500 h-24`)}),(0,g.jsx)(`div`,{className:p(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,w&&`opacity-100`),children:(0,g.jsx)(ce,{className:`h-4 w-4`})})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-gray-200 dark:border-dark-200 ps-3 pe-2 py-1.5`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,g.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 shrink-0`,children:Ee()}),(0,g.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100 truncate`,title:Y.description||`${e(`artifacts.created`)}: ${new Date(Y.createdAt).toLocaleString(t.language)}`,children:Y.title}),(0,g.jsx)(`span`,{className:`hidden sm:inline text-[10px] bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-1.5 py-0.5 rounded-full font-medium shrink-0`,children:Y.type.toUpperCase()})]}),M.length>1&&N!==-1&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,g.jsx)(u,{variant:`ghost`,size:`sm`,disabled:N===0,onClick:()=>y(M[N-1]),className:`h-7 w-7 p-0`,title:e(`artifacts.previousVersion`),"aria-label":e(`artifacts.previousVersion`),children:(0,g.jsx)(ie,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,g.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:N+1,total:M.length})}),(0,g.jsx)(u,{variant:`ghost`,size:`sm`,disabled:N===M.length-1,onClick:()=>y(M[N+1]),className:`h-7 w-7 p-0`,title:e(`artifacts.nextVersion`),"aria-label":e(`artifacts.nextVersion`),children:(0,g.jsx)(ae,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ae()&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,g.jsxs)(u,{variant:I===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`preview`),className:`h-7 px-2 text-xs`,title:e(`artifacts.previewMode`),"aria-pressed":I===`preview`,children:[(0,g.jsx)(te,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.preview`)]}),(0,g.jsxs)(u,{variant:I===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`code`),className:`h-7 px-2 text-xs`,title:e(`artifacts.codeMode`),"aria-pressed":I===`code`,children:[(0,g.jsx)(o,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.code`)]})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,g.jsx)(u,{variant:`ghost`,size:`sm`,onClick:()=>Se(Y.content),className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),"aria-label":e(`artifacts.copyContent`),children:P?(0,g.jsx)(s,{className:`h-3.5 w-3.5 text-green-500`}):(0,g.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(u,{variant:`ghost`,size:`sm`,onClick:Ce,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),"aria-label":e(`artifacts.download`),children:(0,g.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(u,{variant:`ghost`,size:`sm`,onClick:b,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(O?`common.close`:`artifacts.closePanelEsc`),"aria-label":e(O?`common.close`:`artifacts.closePanelEsc`),children:(0,g.jsx)(oe,{className:`h-4 w-4`})})]})]}),(0,g.jsx)(`div`,{className:`flex-1 p-2 overflow-hidden`,children:ke()})]})]});return(0,me.createPortal)(Me,document.body)};export{y as ArtifactSlideOutPanel};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{An as ee,En as te,Ln as a,Nn as ne,Or as re,Qn as ie,Rn as o,Zn as ae,er as s,g as c,n as oe,rn as se,tn as ce,yn as l}from"./ui-vendor-C7v9zeJX.js";import{t as u}from"./Button-D6d7HYoa.js";import{t as d}from"./OptimizedSyntaxHighlighter-B8vbflQA.js";import{t as f}from"./ArtifactSandboxFrame-BMQXP8E8.js";import{t as le}from"./appStore-C_SBNGJT.js";import{E as ue,t as de}from"./chatStore-wi8VDo6B.js";import{i as fe,r as pe}from"./artifactHtml-DDmfpcB0.js";import{t as p}from"./utils-BXRzbHJC.js";import{t as m}from"./logger-DAQsBb8I.js";var h=e(t(),1),me=n(),g=r(),he=m(`components:artifact-slide-out-panel`),_=320,ge=.9,_e=400,ve=`(min-width: 768px)`,ye=`(min-width: 1024px)`,v=e=>{let[t,n]=(0,h.useState)(()=>typeof window<`u`&&window.matchMedia(e).matches);return(0,h.useEffect)(()=>{let t=window.matchMedia(e),r=()=>n(t.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t},y=()=>{let{t:e,i18n:t}=i(),n=ue(t.language),{artifactPanelOpen:r,artifactPanelArtifact:m,openArtifactPanel:y,closeArtifactPanel:b,theme:x,artifactPanelWidth:S,setArtifactPanelWidth:C,artifactPanelResizing:w,setArtifactPanelResizing:T,sidebarOpen:E,sidebarCompact:D}=le(),O=v(ve),k=v(ye)?E?D?64:288:0:E&&D?64:0,A=(0,h.useCallback)(()=>O?Math.max(_,window.innerWidth-k-_e):window.innerWidth*ge,[O,k]),j=de(e=>e.currentSession),M=h.useMemo(()=>{if(!m)return[];let e=m.title.trim().toLowerCase(),t=(j?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===m.id||e.content===m.content)?t:[...t,m]},[j,m]),N=M.findIndex(e=>e.id===m?.id);N===-1&&m&&(N=M.findIndex(e=>e.content===m.content));let[P,F]=(0,h.useState)(!1),[I,L]=(0,h.useState)(`preview`),R=(0,h.useRef)(null),z=(0,h.useRef)(null),B=(0,h.useRef)(0),V=(0,h.useRef)(0),H=(0,h.useRef)(null),U=(0,h.useRef)(null),W=(0,h.useRef)(S),G=m?.id??null;G!==z.current&&(z.current=G,I!==`preview`&&L(`preview`));let K=(0,h.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,C(W.current)}))},[C]),q=(0,h.useCallback)(()=>{H.current=null,T(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,C(W.current))},[T,C]),be=(0,h.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=S,B.current=e.clientX,W.current=S,e.currentTarget.setPointerCapture(e.pointerId),T(!0)},[S,T]),xe=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=n?e.key===`ArrowRight`:e.key===`ArrowLeft`,r=e.shiftKey?96:24;C(Math.min(A(),Math.max(_,S+(t?r:-r))))},J=(0,h.useCallback)(e=>{if(!w||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=Math.min(A(),Math.max(_,V.current+t));K(r)},[w,n,K,A]);if((0,h.useEffect)(()=>{if(!w){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[w,J,q]),(0,h.useEffect)(()=>{let e=()=>{let e=A();S>e&&C(e)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[S,C,A]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{e.key===`Escape`&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,b,O]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{w||R.current&&!R.current.contains(e.target)&&r&&b()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,b,w,O]),!m)return null;let Y=m,Se=async t=>{try{await navigator.clipboard.writeText(t),F(!0),setTimeout(()=>F(!1),2e3)}catch(t){he.error(`Failed to copy:`,t),re.error(e(`chat.message.copyFailed`))}},Ce=()=>{let e=Y.type===`html`?pe(Y.content,Y.title):Y.content,t=new Blob([e],{type:we(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${Te(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},we=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},Te=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},Ee=()=>{switch(Y.type){case`html`:return(0,g.jsx)(se,{className:`h-5 w-5`});case`react`:return(0,g.jsx)(a,{className:`h-5 w-5`});case`svg`:return(0,g.jsx)(l,{className:`h-5 w-5`});case`code`:return(0,g.jsx)(a,{className:`h-5 w-5`});default:return(0,g.jsx)(l,{className:`h-5 w-5`})}},X=()=>(0,g.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,g.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,g.jsx)(c,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,g.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,g.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,g.jsxs)(u,{variant:`outline`,size:`sm`,onClick:()=>L(`code`),className:`mt-4`,children:[(0,g.jsx)(o,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Z=e=>Y.content.trim()?(0,g.jsx)(f,{content:Y.content,title:Y.title,kind:e,colorScheme:x.mode===`light`?`light`:`dark`,className:p(`w-full h-full border-0 rounded-lg bg-white`,w&&`pointer-events-none`),fallback:X()}):X(),De=()=>(0,g.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:fe(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(d,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:x.mode!==`light`,className:`m-0! rounded-lg! h-full!`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:Y.content})}),Oe=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(d,{language:`json`,isDark:x.mode!==`light`,className:`m-0! rounded-lg! h-full!`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:t})})}catch{return(0,g.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,g.jsxs)(`div`,{className:`text-center`,children:[(0,g.jsx)(c,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,g.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},ke=()=>{if(I===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return De();case`json`:return Oe();default:return Q()}},Ae=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,je=$?`100%`:`${S}px`,Me=(0,g.jsxs)(g.Fragment,{children:[!O&&(0,g.jsx)(`div`,{className:p(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),w&&(0,g.jsx)(`div`,{className:p(`fixed inset-0 cursor-col-resize select-none`,O?`z-40`:`z-55`),"aria-hidden":`true`}),(0,g.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:je},className:p(`fixed top-0 inset-e-0 h-full`,O?`z-30`:`z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,g.jsxs)(`div`,{onPointerDown:be,onKeyDown:xe,role:`separator`,"aria-orientation":`vertical`,tabIndex:0,"aria-label":e(`artifacts.resizePanel`),"aria-valuenow":Math.round(S),"aria-valuemin":_,"aria-valuemax":Math.round(A()),"data-testid":`artifact-resize-handle`,title:e(`artifacts.dragEdgeToResize`),className:p(`focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500`,`absolute inset-s-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-56`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,g.jsx)(`div`,{className:p(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24 group-focus-visible:bg-primary-500`,w&&`bg-primary-500 h-24`)}),(0,g.jsx)(`div`,{className:p(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,w&&`opacity-100`),children:(0,g.jsx)(ce,{className:`h-4 w-4`})})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-gray-200 dark:border-dark-200 ps-3 pe-2 py-1.5`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,g.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 shrink-0`,children:Ee()}),(0,g.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100 truncate`,title:Y.description||`${e(`artifacts.created`)}: ${new Date(Y.createdAt).toLocaleString(t.language)}`,children:Y.title}),(0,g.jsx)(`span`,{className:`hidden sm:inline text-[10px] bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-1.5 py-0.5 rounded-full font-medium shrink-0`,children:Y.type.toUpperCase()})]}),M.length>1&&N!==-1&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,g.jsx)(u,{variant:`ghost`,size:`sm`,disabled:N===0,onClick:()=>y(M[N-1]),className:`h-7 w-7 p-0`,title:e(`artifacts.previousVersion`),"aria-label":e(`artifacts.previousVersion`),children:(0,g.jsx)(ie,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,g.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:N+1,total:M.length})}),(0,g.jsx)(u,{variant:`ghost`,size:`sm`,disabled:N===M.length-1,onClick:()=>y(M[N+1]),className:`h-7 w-7 p-0`,title:e(`artifacts.nextVersion`),"aria-label":e(`artifacts.nextVersion`),children:(0,g.jsx)(ae,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ae()&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,g.jsxs)(u,{variant:I===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`preview`),className:`h-7 px-2 text-xs`,title:e(`artifacts.previewMode`),"aria-pressed":I===`preview`,children:[(0,g.jsx)(te,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.preview`)]}),(0,g.jsxs)(u,{variant:I===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`code`),className:`h-7 px-2 text-xs`,title:e(`artifacts.codeMode`),"aria-pressed":I===`code`,children:[(0,g.jsx)(o,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.code`)]})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,g.jsx)(u,{variant:`ghost`,size:`sm`,onClick:()=>Se(Y.content),className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),"aria-label":e(`artifacts.copyContent`),children:P?(0,g.jsx)(s,{className:`h-3.5 w-3.5 text-green-500`}):(0,g.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(u,{variant:`ghost`,size:`sm`,onClick:Ce,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),"aria-label":e(`artifacts.download`),children:(0,g.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(u,{variant:`ghost`,size:`sm`,onClick:b,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(O?`common.close`:`artifacts.closePanelEsc`),"aria-label":e(O?`common.close`:`artifacts.closePanelEsc`),children:(0,g.jsx)(oe,{className:`h-4 w-4`})})]})]}),(0,g.jsx)(`div`,{className:`flex-1 p-2 overflow-hidden`,children:ke()})]})]});return(0,me.createPortal)(Me,document.body)};export{y as ArtifactSlideOutPanel};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{Bn as a,Or as o,n as s,tt as c,v as l}from"./ui-vendor-DsURZnZt.js";import{t as u}from"./useDialogFocus-DpTun-ZV.js";import{T as d}from"./api-Dasm8tVY.js";import{t as f}from"./utils-BXRzbHJC.js";import{t as p}from"./workApi-BNGRSv7q.js";import{c as m,d as h,l as g,n as _}from"./calendarDates-Co3o_05Y.js";var v=e(t(),1),y=n(),b=[`channel-mention`,`channel-dm`,`channel-invite`,`share`,`calendar-reminder`,`media-ready`,`media-failed`,`budget-alert`,`work-run-finished`,`work-run-attention`,`work-takeover`,`work-approval`,`system`],x=e=>e.length>0&&e.every(e=>e.kind===`event`),S=(e,t,n)=>new Intl.DateTimeFormat(n,{hour:`numeric`,minute:`2-digit`}).format(new Date(2024,0,1,e,t)),C=(e,t)=>new Intl.DateTimeFormat(t,{weekday:`long`}).format(new Date(2024,0,7+e)),w=(e,t,n)=>new Intl.DateTimeFormat(n,{month:`long`,day:`numeric`}).format(new Date(2024,e-1,t));function T(e,t,n){switch(e.kind){case`event`:return n(e.match?`automations.trigger.eventMatching`:`automations.trigger.event`,{event:n(`automations.triggers.events.${e.event}`),match:e.match??``});case`once`:return n(`automations.trigger.once`,{when:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.at))});case`hourly`:{let t=e.startHour!==void 0||e.endHour!==void 0?` (${e.startHour??0}–${e.endHour??23})`:``;return n(`automations.trigger.hourly`,{minute:String(e.minute).padStart(2,`0`)})+t}case`daily`:return n(`automations.trigger.daily`,{time:S(e.hour,e.minute,t)});case`weekly`:return n(`automations.trigger.weekly`,{day:C(e.dayOfWeek,t),time:S(e.hour,e.minute,t)});case`monthly`:return n(`automations.trigger.monthly`,{day:e.dayOfMonth,time:S(e.hour,e.minute,t)});case`yearly`:return n(`automations.trigger.yearly`,{date:w(e.month,e.dayOfMonth,t),time:S(e.hour,e.minute,t)})}}function E(e,t,n){return e.map(e=>T(e,t,n)).join(` · `)}function D(e){let t=(e,t,n)=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=t&&e<=n;switch(e.kind){case`event`:return b.includes(e.event)&&(e.match===void 0||typeof e.match==`string`&&e.match.length<=200);case`once`:return t(e.at,0,864e13);case`hourly`:return t(e.minute,0,59)&&(e.startHour===void 0||t(e.startHour,0,23))&&(e.endHour===void 0||t(e.endHour,0,23))&&(e.startHour===void 0||e.endHour===void 0||e.endHour>=e.startHour);case`daily`:return t(e.hour,0,23)&&t(e.minute,0,59);case`weekly`:return t(e.dayOfWeek,0,6)&&t(e.hour,0,23)&&t(e.minute,0,59);case`monthly`:return t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);case`yearly`:return t(e.month,1,12)&&t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);default:return!1}}var O=r(),k=[`event`,`once`,`hourly`,`daily`,`weekly`,`monthly`,`yearly`],A=`rounded-lg border border-black/8 bg-white px-2 py-1 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-hidden dark:border-white/8 dark:bg-dark-100 dark:text-dark-900`,j=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`,M=e=>{switch(e){case`event`:return{kind:`event`,event:`channel-mention`};case`once`:{let e=new Date;return e.setHours(e.getHours()+1,0,0,0),{kind:`once`,at:e.getTime()}}case`hourly`:return{kind:`hourly`,minute:0};case`daily`:return{kind:`daily`,hour:8,minute:0};case`weekly`:return{kind:`weekly`,dayOfWeek:1,hour:9,minute:0};case`monthly`:return{kind:`monthly`,dayOfMonth:1,hour:9,minute:0};case`yearly`:return{kind:`yearly`,month:1,dayOfMonth:1,hour:9,minute:0}}};function N({trigger:e,onChange:t,onRemove:n}){let{t:r,i18n:o}=i(),s=h(o.language,`short`),c=new Intl.DateTimeFormat(o.language,{month:`long`}),u=n=>{let[r,i]=(n||`00:00`).split(`:`).map(Number);e.kind!==`hourly`&&e.kind!==`once`&&e.kind!==`event`&&t({...e,hour:r,minute:i})},d=e.kind!==`once`&&e.kind!==`hourly`&&e.kind!==`event`?(0,O.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:j(e.hour,e.minute),onChange:e=>u(e.target.value),className:A}):null;return(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-black/6 bg-black/2 px-2.5 py-2 dark:border-white/6 dark:bg-white/3`,"data-testid":`automation-trigger`,children:[(0,O.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,O.jsx)(`select`,{"aria-label":r(`automations.form.frequency`),value:e.kind,onChange:e=>t(M(e.target.value)),className:A,"data-testid":`automation-trigger-kind`,children:k.map(e=>(0,O.jsx)(`option`,{value:e,children:r(`automations.kind.${e}`)},e))}),e.kind===`event`&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`select`,{"aria-label":r(`automations.form.event`),value:e.event,onChange:n=>t({...e,event:n.target.value}),className:A,"data-testid":`automation-trigger-event`,children:b.map(e=>(0,O.jsx)(`option`,{value:e,children:r(`automations.triggers.events.${e}`)},e))}),(0,O.jsx)(`input`,{type:`text`,"aria-label":r(`automations.form.eventMatch`),placeholder:r(`automations.form.eventMatchPlaceholder`),value:e.match??``,onChange:n=>t({...e,match:n.target.value.slice(0,200)}),className:`${A} min-w-0 flex-1`,"data-testid":`automation-trigger-match`})]}),e.kind===`once`&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`input`,{type:`date`,"aria-label":r(`calendar.date`),value:m(e.at),onChange:n=>t({...e,at:_(n.target.value,g(e.at))}),className:A}),(0,O.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:g(e.at),onChange:n=>t({...e,at:_(m(e.at),n.target.value)}),className:A})]}),e.kind===`hourly`&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.minute`),(0,O.jsx)(`input`,{type:`number`,min:0,max:59,value:e.minute,onChange:n=>t({...e,minute:Math.min(59,Math.max(0,Number(n.target.value)))}),className:`${A} w-16`})]}),(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.fromHour`),(0,O.jsx)(`input`,{type:`number`,min:0,max:23,value:e.startHour??0,onChange:n=>t({...e,startHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${A} w-16`})]}),(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.toHour`),(0,O.jsx)(`input`,{type:`number`,min:0,max:23,value:e.endHour??23,onChange:n=>t({...e,endHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${A} w-16`})]})]}),e.kind===`weekly`&&(0,O.jsx)(`select`,{"aria-label":r(`automations.form.weekday`),value:e.dayOfWeek,onChange:n=>t({...e,dayOfWeek:Number(n.target.value)}),className:A,children:s.map((e,t)=>(0,O.jsx)(`option`,{value:t,children:e},e))}),(e.kind===`monthly`||e.kind===`yearly`)&&(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.dayOfMonth`),(0,O.jsx)(`input`,{type:`number`,min:1,max:31,value:e.dayOfMonth,onChange:n=>t({...e,dayOfMonth:Math.min(31,Math.max(1,Number(n.target.value)))}),className:`${A} w-16`})]}),e.kind===`yearly`&&(0,O.jsx)(`select`,{"aria-label":r(`automations.form.month`),value:e.month,onChange:n=>t({...e,month:Number(n.target.value)}),className:A,children:Array.from({length:12},(e,t)=>(0,O.jsx)(`option`,{value:t+1,children:c.format(new Date(2024,t,1))},t+1))}),d,n&&(0,O.jsx)(`button`,{type:`button`,onClick:n,"aria-label":r(`common.delete`),className:`ms-auto rounded-md p-1 text-red-500 transition-colors hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,O.jsx)(l,{className:`h-3.5 w-3.5`})})]})}var P=`w-full rounded-lg border border-black/8 bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-hidden dark:border-white/8 dark:bg-dark-100 dark:text-dark-900`,F=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,I=e=>e.isPlugin&&e.pluginId?`plugin:${e.pluginId}`:e.isAgent&&e.agentId?`agent:${e.agentId}`:`ollama`;function L({open:e,automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s}){return e?(0,O.jsx)(R,{automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s},t?.id??n?.name??`new`):null}function R({automation:e,initial:t,fixedWorkTaskId:n,models:r,saving:a,onClose:l,onSave:m}){let{t:h}=i(),g=(0,v.useRef)(null);u(g,{onClose:l});let _=!!(n??e?.workTaskId),[b,S]=(0,v.useState)(e?.name??t?.name??``),[C,w]=(0,v.useState)(e?.instructions??t?.instructions??``),[T,E]=(0,v.useState)(e?.triggers??t?.triggers??[{kind:`daily`,hour:8,minute:0}]),[k,A]=(0,v.useState)(e?.model??``),[j,M]=(0,v.useState)(e?.notify??`app`),[L,R]=(0,v.useState)(e?.target??`chat`),[z,B]=(0,v.useState)(e?.workPolicyId??``),[V,H]=(0,v.useState)([]);(0,v.useEffect)(()=>{if(L!==`work`||_)return;let e=!1;return p.listPolicies().then(t=>{!e&&t.success&&Array.isArray(t.data)&&H(t.data)}).catch(()=>void 0),()=>{e=!0}},[L,_]);let[U,W]=(0,v.useState)(e?.webhookEnabled===!0),[G,K]=(0,v.useState)(null),[q,J]=(0,v.useState)(!1),Y=async()=>{if(e){J(!0);try{let t=await d.rotateWebhookSecret(e.id);if(!t.success||!t.data)throw Error(t.error);W(!0),K(t.data)}catch{o.error(h(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{J(!1)}}},X=async()=>{if(e){J(!0);try{let t=await d.disableWebhook(e.id);if(!t.success)throw Error(t.error);W(!1),K(null)}catch{o.error(h(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{J(!1)}}},Z=b.trim().length>0&&C.trim().length>0&&T.length>0&&T.every(D);return(0,y.createPortal)((0,O.jsx)(`div`,{className:`fixed inset-0 z-2147483647 flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:l,children:(0,O.jsx)(`div`,{ref:g,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`automation-modal-title`,tabIndex:-1,"data-testid":`automation-modal`,className:`flex max-h-[90vh] w-full max-w-lg flex-col overflow-hidden rounded-3xl border border-black/[0.07] bg-white shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/8 dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:(0,O.jsxs)(`div`,{"data-testid":`automation-scroll-region`,className:`min-h-0 overflow-y-auto p-6 scrollbar-thin`,children:[(0,O.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,O.jsx)(`h3`,{id:`automation-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:h(e?`automations.editAutomation`:`automations.newAutomation`)}),(0,O.jsx)(`button`,{onClick:l,"aria-label":h(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,O.jsx)(s,{size:20,className:`text-gray-500`})})]}),(0,O.jsxs)(`div`,{className:`space-y-4`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-name`,className:F,children:h(`automations.form.name`)}),(0,O.jsx)(`input`,{id:`automation-name`,"data-testid":`automation-name`,type:`text`,value:b,onChange:e=>S(e.target.value),placeholder:h(`automations.form.namePlaceholder`),className:P,maxLength:200,autoFocus:!0})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:F,children:h(`automations.form.triggers`)}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[T.map((e,t)=>(0,O.jsx)(N,{trigger:e,onChange:e=>E(n=>n.map((n,r)=>r===t?e:n)),onRemove:T.length>1?()=>E(e=>e.filter((e,n)=>n!==t)):void 0},t)),x(T)&&(0,O.jsx)(`p`,{"data-testid":`automation-event-only-hint`,className:`text-[12px] text-gray-500 dark:text-dark-500`,children:h(`automations.form.eventOnlyHint`)}),T.length<5&&(0,O.jsxs)(`button`,{type:`button`,onClick:()=>E(e=>[...e,{kind:`daily`,hour:8,minute:0}]),"data-testid":`automation-add-trigger`,className:`flex items-center gap-1.5 rounded-lg px-2 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:[(0,O.jsx)(c,{className:`h-3.5 w-3.5`}),h(`automations.form.addTrigger`)]})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-instructions`,className:F,children:h(`automations.form.instructions`)}),(0,O.jsx)(`textarea`,{id:`automation-instructions`,"data-testid":`automation-instructions`,value:C,onChange:e=>w(e.target.value),placeholder:h(`automations.form.instructionsPlaceholder`),rows:5,className:P,maxLength:2e4})]}),_&&(0,O.jsx)(`p`,{"data-testid":`automation-task-bound-note`,className:`rounded-lg bg-primary-500/10 px-3 py-2 text-[12px] leading-relaxed text-primary-700 dark:text-primary-300`,children:h(`automations.form.taskBoundNote`,{defaultValue:`This routine runs inside the agent's own workspace and conversation, with the agent's model and runtime.`})}),(0,O.jsxs)(`div`,{className:f(`grid grid-cols-2 gap-3`,_&&`hidden`),children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-target`,className:F,children:h(`automations.form.target`)}),(0,O.jsxs)(`select`,{id:`automation-target`,"data-testid":`automation-target`,value:L,onChange:e=>R(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:`chat`,children:h(`automations.form.targetChat`)}),(0,O.jsx)(`option`,{value:`work`,children:h(`automations.form.targetWork`)})]})]}),L===`work`&&V.length>0&&(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-work-policy`,className:F,children:h(`automations.form.workPolicy`)}),(0,O.jsxs)(`select`,{id:`automation-work-policy`,"data-testid":`automation-work-policy`,value:z,onChange:e=>B(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:``,children:h(`automations.form.workPolicyDefault`)}),V.map(e=>(0,O.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,O.jsxs)(`div`,{className:f(_&&`hidden`),children:[(0,O.jsx)(`label`,{htmlFor:`automation-model`,className:F,children:h(`automations.form.model`)}),(0,O.jsxs)(`select`,{id:`automation-model`,value:k,onChange:e=>A(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:``,children:h(`automations.form.modelAuto`)}),r.map(e=>(0,O.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-notify`,className:F,children:h(`automations.form.notification`)}),(0,O.jsxs)(`select`,{id:`automation-notify`,value:j,onChange:e=>M(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:`app`,children:h(`automations.form.notifyApp`)}),(0,O.jsx)(`option`,{value:`off`,children:h(`automations.form.notifyOff`)})]})]})]}),e&&(0,O.jsxs)(`div`,{"data-testid":`automation-webhook`,className:`rounded-xl border border-gray-200 p-3 dark:border-dark-300`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:h(`automations.webhook.title`,{defaultValue:`Webhook trigger`})}),(0,O.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-600`,children:U?h(`automations.webhook.enabledHint`,{defaultValue:`External systems can fire this automation with the secret. Rotating invalidates the previous secret.`}):h(`automations.webhook.disabledHint`,{defaultValue:`Let an external system (CI, cron, home automation) fire this automation with a POST and a secret.`})})]}),(0,O.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-rotate`,onClick:()=>void Y(),disabled:q,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:U?h(`automations.webhook.rotate`,{defaultValue:`Rotate secret`}):h(`automations.webhook.enable`,{defaultValue:`Enable`})}),U&&(0,O.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-disable`,onClick:()=>void X(),disabled:q,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:h(`automations.webhook.disable`,{defaultValue:`Disable`})})]})]}),G&&(0,O.jsxs)(`div`,{"data-testid":`automation-webhook-secret`,className:`mt-2 space-y-1 rounded-lg bg-gray-50 p-2 dark:bg-dark-100`,children:[(0,O.jsx)(`p`,{className:`text-[11px] text-gray-500 dark:text-dark-600`,children:h(`automations.webhook.revealHint`,{defaultValue:`Shown once. Send it as a Bearer token or an X-Libre-Webhook-Secret header.`})}),(0,O.jsxs)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:[`POST `,G.path]}),(0,O.jsx)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:G.secret})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-end gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[(0,O.jsx)(`button`,{onClick:l,"data-testid":`automation-cancel`,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:h(`common.cancel`)}),(0,O.jsx)(`button`,{onClick:()=>{if(!Z)return;if(_){m({name:b.trim(),instructions:C.trim(),triggers:T,notify:j,target:`work`,workTaskId:n??e?.workTaskId});return}let t=r.find(e=>e.name===k);m({name:b.trim(),instructions:C.trim(),triggers:T,...t?{provider:I(t),model:t.name}:{},notify:j,target:L,...L===`work`&&z?{workPolicyId:z}:{}})},disabled:a||!Z,"data-testid":`automation-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:h(a?`common.saving`:`common.save`)})]})]})]})})}),document.body)}export{E as n,x as r,L as t};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{Bn as a,Or as o,n as s,tt as c,v as l}from"./ui-vendor-C7v9zeJX.js";import{t as u}from"./useDialogFocus-DpTun-ZV.js";import{T as d}from"./api-BPTwf2O4.js";import{t as f}from"./utils-BXRzbHJC.js";import{t as p}from"./workApi-BTdJF6o5.js";import{c as m,d as h,l as g,n as _}from"./calendarDates-Co3o_05Y.js";var v=e(t(),1),y=n(),b=[`channel-mention`,`channel-dm`,`channel-invite`,`share`,`calendar-reminder`,`media-ready`,`media-failed`,`budget-alert`,`work-run-finished`,`work-run-attention`,`work-takeover`,`work-approval`,`system`],x=e=>e.length>0&&e.every(e=>e.kind===`event`),S=(e,t,n)=>new Intl.DateTimeFormat(n,{hour:`numeric`,minute:`2-digit`}).format(new Date(2024,0,1,e,t)),C=(e,t)=>new Intl.DateTimeFormat(t,{weekday:`long`}).format(new Date(2024,0,7+e)),w=(e,t,n)=>new Intl.DateTimeFormat(n,{month:`long`,day:`numeric`}).format(new Date(2024,e-1,t));function T(e,t,n){switch(e.kind){case`event`:return n(e.match?`automations.trigger.eventMatching`:`automations.trigger.event`,{event:n(`automations.triggers.events.${e.event}`),match:e.match??``});case`once`:return n(`automations.trigger.once`,{when:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.at))});case`hourly`:{let t=e.startHour!==void 0||e.endHour!==void 0?` (${e.startHour??0}–${e.endHour??23})`:``;return n(`automations.trigger.hourly`,{minute:String(e.minute).padStart(2,`0`)})+t}case`daily`:return n(`automations.trigger.daily`,{time:S(e.hour,e.minute,t)});case`weekly`:return n(`automations.trigger.weekly`,{day:C(e.dayOfWeek,t),time:S(e.hour,e.minute,t)});case`monthly`:return n(`automations.trigger.monthly`,{day:e.dayOfMonth,time:S(e.hour,e.minute,t)});case`yearly`:return n(`automations.trigger.yearly`,{date:w(e.month,e.dayOfMonth,t),time:S(e.hour,e.minute,t)})}}function E(e,t,n){return e.map(e=>T(e,t,n)).join(` · `)}function D(e){let t=(e,t,n)=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=t&&e<=n;switch(e.kind){case`event`:return b.includes(e.event)&&(e.match===void 0||typeof e.match==`string`&&e.match.length<=200);case`once`:return t(e.at,0,864e13);case`hourly`:return t(e.minute,0,59)&&(e.startHour===void 0||t(e.startHour,0,23))&&(e.endHour===void 0||t(e.endHour,0,23))&&(e.startHour===void 0||e.endHour===void 0||e.endHour>=e.startHour);case`daily`:return t(e.hour,0,23)&&t(e.minute,0,59);case`weekly`:return t(e.dayOfWeek,0,6)&&t(e.hour,0,23)&&t(e.minute,0,59);case`monthly`:return t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);case`yearly`:return t(e.month,1,12)&&t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);default:return!1}}var O=r(),k=[`event`,`once`,`hourly`,`daily`,`weekly`,`monthly`,`yearly`],A=`rounded-lg border border-black/8 bg-white px-2 py-1 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-hidden dark:border-white/8 dark:bg-dark-100 dark:text-dark-900`,j=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`,M=e=>{switch(e){case`event`:return{kind:`event`,event:`channel-mention`};case`once`:{let e=new Date;return e.setHours(e.getHours()+1,0,0,0),{kind:`once`,at:e.getTime()}}case`hourly`:return{kind:`hourly`,minute:0};case`daily`:return{kind:`daily`,hour:8,minute:0};case`weekly`:return{kind:`weekly`,dayOfWeek:1,hour:9,minute:0};case`monthly`:return{kind:`monthly`,dayOfMonth:1,hour:9,minute:0};case`yearly`:return{kind:`yearly`,month:1,dayOfMonth:1,hour:9,minute:0}}};function N({trigger:e,onChange:t,onRemove:n}){let{t:r,i18n:o}=i(),s=h(o.language,`short`),c=new Intl.DateTimeFormat(o.language,{month:`long`}),u=n=>{let[r,i]=(n||`00:00`).split(`:`).map(Number);e.kind!==`hourly`&&e.kind!==`once`&&e.kind!==`event`&&t({...e,hour:r,minute:i})},d=e.kind!==`once`&&e.kind!==`hourly`&&e.kind!==`event`?(0,O.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:j(e.hour,e.minute),onChange:e=>u(e.target.value),className:A}):null;return(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-black/6 bg-black/2 px-2.5 py-2 dark:border-white/6 dark:bg-white/3`,"data-testid":`automation-trigger`,children:[(0,O.jsx)(a,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,O.jsx)(`select`,{"aria-label":r(`automations.form.frequency`),value:e.kind,onChange:e=>t(M(e.target.value)),className:A,"data-testid":`automation-trigger-kind`,children:k.map(e=>(0,O.jsx)(`option`,{value:e,children:r(`automations.kind.${e}`)},e))}),e.kind===`event`&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`select`,{"aria-label":r(`automations.form.event`),value:e.event,onChange:n=>t({...e,event:n.target.value}),className:A,"data-testid":`automation-trigger-event`,children:b.map(e=>(0,O.jsx)(`option`,{value:e,children:r(`automations.triggers.events.${e}`)},e))}),(0,O.jsx)(`input`,{type:`text`,"aria-label":r(`automations.form.eventMatch`),placeholder:r(`automations.form.eventMatchPlaceholder`),value:e.match??``,onChange:n=>t({...e,match:n.target.value.slice(0,200)}),className:`${A} min-w-0 flex-1`,"data-testid":`automation-trigger-match`})]}),e.kind===`once`&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`input`,{type:`date`,"aria-label":r(`calendar.date`),value:m(e.at),onChange:n=>t({...e,at:_(n.target.value,g(e.at))}),className:A}),(0,O.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:g(e.at),onChange:n=>t({...e,at:_(m(e.at),n.target.value)}),className:A})]}),e.kind===`hourly`&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.minute`),(0,O.jsx)(`input`,{type:`number`,min:0,max:59,value:e.minute,onChange:n=>t({...e,minute:Math.min(59,Math.max(0,Number(n.target.value)))}),className:`${A} w-16`})]}),(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.fromHour`),(0,O.jsx)(`input`,{type:`number`,min:0,max:23,value:e.startHour??0,onChange:n=>t({...e,startHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${A} w-16`})]}),(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.toHour`),(0,O.jsx)(`input`,{type:`number`,min:0,max:23,value:e.endHour??23,onChange:n=>t({...e,endHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${A} w-16`})]})]}),e.kind===`weekly`&&(0,O.jsx)(`select`,{"aria-label":r(`automations.form.weekday`),value:e.dayOfWeek,onChange:n=>t({...e,dayOfWeek:Number(n.target.value)}),className:A,children:s.map((e,t)=>(0,O.jsx)(`option`,{value:t,children:e},e))}),(e.kind===`monthly`||e.kind===`yearly`)&&(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.dayOfMonth`),(0,O.jsx)(`input`,{type:`number`,min:1,max:31,value:e.dayOfMonth,onChange:n=>t({...e,dayOfMonth:Math.min(31,Math.max(1,Number(n.target.value)))}),className:`${A} w-16`})]}),e.kind===`yearly`&&(0,O.jsx)(`select`,{"aria-label":r(`automations.form.month`),value:e.month,onChange:n=>t({...e,month:Number(n.target.value)}),className:A,children:Array.from({length:12},(e,t)=>(0,O.jsx)(`option`,{value:t+1,children:c.format(new Date(2024,t,1))},t+1))}),d,n&&(0,O.jsx)(`button`,{type:`button`,onClick:n,"aria-label":r(`common.delete`),className:`ms-auto rounded-md p-1 text-red-500 transition-colors hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,O.jsx)(l,{className:`h-3.5 w-3.5`})})]})}var P=`w-full rounded-lg border border-black/8 bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-hidden dark:border-white/8 dark:bg-dark-100 dark:text-dark-900`,F=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,I=e=>e.isPlugin&&e.pluginId?`plugin:${e.pluginId}`:e.isAgent&&e.agentId?`agent:${e.agentId}`:`ollama`;function L({open:e,automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s}){return e?(0,O.jsx)(R,{automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s},t?.id??n?.name??`new`):null}function R({automation:e,initial:t,fixedWorkTaskId:n,models:r,saving:a,onClose:l,onSave:m}){let{t:h}=i(),g=(0,v.useRef)(null);u(g,{onClose:l});let _=!!(n??e?.workTaskId),[b,S]=(0,v.useState)(e?.name??t?.name??``),[C,w]=(0,v.useState)(e?.instructions??t?.instructions??``),[T,E]=(0,v.useState)(e?.triggers??t?.triggers??[{kind:`daily`,hour:8,minute:0}]),[k,A]=(0,v.useState)(e?.model??``),[j,M]=(0,v.useState)(e?.notify??`app`),[L,R]=(0,v.useState)(e?.target??`chat`),[z,B]=(0,v.useState)(e?.workPolicyId??``),[V,H]=(0,v.useState)([]);(0,v.useEffect)(()=>{if(L!==`work`||_)return;let e=!1;return p.listPolicies().then(t=>{!e&&t.success&&Array.isArray(t.data)&&H(t.data)}).catch(()=>void 0),()=>{e=!0}},[L,_]);let[U,W]=(0,v.useState)(e?.webhookEnabled===!0),[G,K]=(0,v.useState)(null),[q,J]=(0,v.useState)(!1),Y=async()=>{if(e){J(!0);try{let t=await d.rotateWebhookSecret(e.id);if(!t.success||!t.data)throw Error(t.error);W(!0),K(t.data)}catch{o.error(h(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{J(!1)}}},X=async()=>{if(e){J(!0);try{let t=await d.disableWebhook(e.id);if(!t.success)throw Error(t.error);W(!1),K(null)}catch{o.error(h(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{J(!1)}}},Z=b.trim().length>0&&C.trim().length>0&&T.length>0&&T.every(D);return(0,y.createPortal)((0,O.jsx)(`div`,{className:`fixed inset-0 z-2147483647 flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:l,children:(0,O.jsx)(`div`,{ref:g,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`automation-modal-title`,tabIndex:-1,"data-testid":`automation-modal`,className:`flex max-h-[90vh] w-full max-w-lg flex-col overflow-hidden rounded-3xl border border-black/[0.07] bg-white shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/8 dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:(0,O.jsxs)(`div`,{"data-testid":`automation-scroll-region`,className:`min-h-0 overflow-y-auto p-6 scrollbar-thin`,children:[(0,O.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,O.jsx)(`h3`,{id:`automation-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:h(e?`automations.editAutomation`:`automations.newAutomation`)}),(0,O.jsx)(`button`,{onClick:l,"aria-label":h(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,O.jsx)(s,{size:20,className:`text-gray-500`})})]}),(0,O.jsxs)(`div`,{className:`space-y-4`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-name`,className:F,children:h(`automations.form.name`)}),(0,O.jsx)(`input`,{id:`automation-name`,"data-testid":`automation-name`,type:`text`,value:b,onChange:e=>S(e.target.value),placeholder:h(`automations.form.namePlaceholder`),className:P,maxLength:200,autoFocus:!0})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:F,children:h(`automations.form.triggers`)}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[T.map((e,t)=>(0,O.jsx)(N,{trigger:e,onChange:e=>E(n=>n.map((n,r)=>r===t?e:n)),onRemove:T.length>1?()=>E(e=>e.filter((e,n)=>n!==t)):void 0},t)),x(T)&&(0,O.jsx)(`p`,{"data-testid":`automation-event-only-hint`,className:`text-[12px] text-gray-500 dark:text-dark-500`,children:h(`automations.form.eventOnlyHint`)}),T.length<5&&(0,O.jsxs)(`button`,{type:`button`,onClick:()=>E(e=>[...e,{kind:`daily`,hour:8,minute:0}]),"data-testid":`automation-add-trigger`,className:`flex items-center gap-1.5 rounded-lg px-2 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:[(0,O.jsx)(c,{className:`h-3.5 w-3.5`}),h(`automations.form.addTrigger`)]})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-instructions`,className:F,children:h(`automations.form.instructions`)}),(0,O.jsx)(`textarea`,{id:`automation-instructions`,"data-testid":`automation-instructions`,value:C,onChange:e=>w(e.target.value),placeholder:h(`automations.form.instructionsPlaceholder`),rows:5,className:P,maxLength:2e4})]}),_&&(0,O.jsx)(`p`,{"data-testid":`automation-task-bound-note`,className:`rounded-lg bg-primary-500/10 px-3 py-2 text-[12px] leading-relaxed text-primary-700 dark:text-primary-300`,children:h(`automations.form.taskBoundNote`,{defaultValue:`This routine runs inside the agent's own workspace and conversation, with the agent's model and runtime.`})}),(0,O.jsxs)(`div`,{className:f(`grid grid-cols-2 gap-3`,_&&`hidden`),children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-target`,className:F,children:h(`automations.form.target`)}),(0,O.jsxs)(`select`,{id:`automation-target`,"data-testid":`automation-target`,value:L,onChange:e=>R(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:`chat`,children:h(`automations.form.targetChat`)}),(0,O.jsx)(`option`,{value:`work`,children:h(`automations.form.targetWork`)})]})]}),L===`work`&&V.length>0&&(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-work-policy`,className:F,children:h(`automations.form.workPolicy`)}),(0,O.jsxs)(`select`,{id:`automation-work-policy`,"data-testid":`automation-work-policy`,value:z,onChange:e=>B(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:``,children:h(`automations.form.workPolicyDefault`)}),V.map(e=>(0,O.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,O.jsxs)(`div`,{className:f(_&&`hidden`),children:[(0,O.jsx)(`label`,{htmlFor:`automation-model`,className:F,children:h(`automations.form.model`)}),(0,O.jsxs)(`select`,{id:`automation-model`,value:k,onChange:e=>A(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:``,children:h(`automations.form.modelAuto`)}),r.map(e=>(0,O.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{htmlFor:`automation-notify`,className:F,children:h(`automations.form.notification`)}),(0,O.jsxs)(`select`,{id:`automation-notify`,value:j,onChange:e=>M(e.target.value),className:P,children:[(0,O.jsx)(`option`,{value:`app`,children:h(`automations.form.notifyApp`)}),(0,O.jsx)(`option`,{value:`off`,children:h(`automations.form.notifyOff`)})]})]})]}),e&&(0,O.jsxs)(`div`,{"data-testid":`automation-webhook`,className:`rounded-xl border border-gray-200 p-3 dark:border-dark-300`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:h(`automations.webhook.title`,{defaultValue:`Webhook trigger`})}),(0,O.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-600`,children:U?h(`automations.webhook.enabledHint`,{defaultValue:`External systems can fire this automation with the secret. Rotating invalidates the previous secret.`}):h(`automations.webhook.disabledHint`,{defaultValue:`Let an external system (CI, cron, home automation) fire this automation with a POST and a secret.`})})]}),(0,O.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-rotate`,onClick:()=>void Y(),disabled:q,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:U?h(`automations.webhook.rotate`,{defaultValue:`Rotate secret`}):h(`automations.webhook.enable`,{defaultValue:`Enable`})}),U&&(0,O.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-disable`,onClick:()=>void X(),disabled:q,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:h(`automations.webhook.disable`,{defaultValue:`Disable`})})]})]}),G&&(0,O.jsxs)(`div`,{"data-testid":`automation-webhook-secret`,className:`mt-2 space-y-1 rounded-lg bg-gray-50 p-2 dark:bg-dark-100`,children:[(0,O.jsx)(`p`,{className:`text-[11px] text-gray-500 dark:text-dark-600`,children:h(`automations.webhook.revealHint`,{defaultValue:`Shown once. Send it as a Bearer token or an X-Libre-Webhook-Secret header.`})}),(0,O.jsxs)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:[`POST `,G.path]}),(0,O.jsx)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:G.secret})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-end gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[(0,O.jsx)(`button`,{onClick:l,"data-testid":`automation-cancel`,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:h(`common.cancel`)}),(0,O.jsx)(`button`,{onClick:()=>{if(!Z)return;if(_){m({name:b.trim(),instructions:C.trim(),triggers:T,notify:j,target:`work`,workTaskId:n??e?.workTaskId});return}let t=r.find(e=>e.name===k);m({name:b.trim(),instructions:C.trim(),triggers:T,...t?{provider:I(t),model:t.name}:{},notify:j,target:L,...L===`work`&&z?{workPolicyId:z}:{}})},disabled:a||!Z,"data-testid":`automation-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:h(a?`common.saving`:`common.save`)})]})]})]})})}),document.body)}export{E as n,x as r,L as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{d as r}from"./router-vendor-DLHZHk4K.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{Kn as a,Or as o,Rt as s,Un as c,Wn as l,Z as u,it as d,kn as ee,lt as te,st as f,t as ne,tt as re,v as ie}from"./ui-vendor-DsURZnZt.js";import{i as ae,n as p,r as m}from"./ui-DxaHE9GD.js";import{t as h}from"./confirmStore-CKkUtP9c.js";import{n as g,r as _,t as v}from"./AutomationModal-D7qiRMhj.js";import{t as y}from"./Button-D6d7HYoa.js";import{T as b}from"./api-Dasm8tVY.js";import{t as x}from"./chatStore-GhucyjJu.js";import{i as S,t as C}from"./utils-BXRzbHJC.js";import{t as w}from"./logger-DAQsBb8I.js";var T=e(t(),1),E=n();function D({days:e,locale:t}){let{t:n}=i(),r=e.reduce((e,t)=>e+t.succeeded,0),a=e.reduce((e,t)=>e+t.failed,0),o=Math.max(1,...e.map(e=>e.succeeded+e.failed)),s=new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}),c=new Date,l=e=>s.format(new Date(c.getFullYear(),c.getMonth(),c.getDate()-29+e));return(0,E.jsxs)(`div`,{className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,"data-testid":`automation-run-strip`,children:[(0,E.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,E.jsx)(`p`,{className:`text-[12px] font-medium text-gray-700 dark:text-dark-700`,children:n(`automations.runHistory`)}),(0,E.jsxs)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:[(0,E.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[r,` `,n(`automations.succeeded`)]}),` · `,(0,E.jsxs)(`span`,{className:`text-red-500 dark:text-red-400`,children:[a,` `,n(`automations.failed`)]})]})]}),(0,E.jsx)(`div`,{className:`flex h-12 items-end gap-[3px]`,children:e.map((e,t)=>{let n=e.succeeded+e.failed;if(n===0)return(0,E.jsx)(`div`,{title:l(t),className:`h-[3px] flex-1 rounded-xs bg-black/6 dark:bg-white/8`},t);let r=Math.max(6,Math.round(n/o*48)),i=Math.round(e.failed/n*r);return(0,E.jsxs)(`div`,{title:`${l(t)}: ${e.succeeded}✓ ${e.failed}✗`,className:`flex flex-1 flex-col justify-end overflow-hidden rounded-xs`,style:{height:r},children:[(0,E.jsx)(`div`,{className:`w-full bg-emerald-500/80`,style:{height:r-i}}),i>0&&(0,E.jsx)(`div`,{className:`w-full bg-red-500/80`,style:{height:i}})]},t)})})]})}var O=[{id:`morningBrief`,instructions:`Put together my morning brief: the top world, business, and tech headlines from the last 24 hours with one-line summaries, and one story worth reading in depth and why. Keep the whole thing scannable.`,triggers:[{kind:`daily`,hour:7,minute:30}]},{id:`newsDigest`,instructions:`Summarize the most important AI news from the last 24 hours: model releases, notable research papers, funding rounds, and policy changes. For each item add one sentence on why it matters. Skip minor product updates and rumors.`,triggers:[{kind:`daily`,hour:8,minute:0}]},{id:`weeklyReview`,instructions:`Help me wrap the week: prompt me to reflect on what I accomplished, what is still open, and what the top priorities for next week should be. Structure it as a short template I can fill in.`,triggers:[{kind:`weekly`,dayOfWeek:5,hour:16,minute:0}]},{id:`monthlyReport`,instructions:`Draft a monthly status report outline: key accomplishments, metrics to review, risks, and goals for the next month. Leave placeholders where my specifics belong.`,triggers:[{kind:`monthly`,dayOfMonth:1,hour:9,minute:0}]}],k=w(`pages:automations`),A=()=>{let{t:e,i18n:t}=i(),n=r(),w=x(e=>e.models),A=x(e=>e.loadModels),[M,N]=(0,T.useState)(`automations`),[P,F]=(0,T.useState)([]),[I,L]=(0,T.useState)([]),[R,z]=(0,T.useState)(null),[B,V]=(0,T.useState)(!0),[H,U]=(0,T.useState)(!1),[W,G]=(0,T.useState)(null),[K,q]=(0,T.useState)(null),[oe,J]=(0,T.useState)(!1),[Y,X]=(0,T.useState)(null),Z=(0,T.useRef)(null),[se,ce]=(0,T.useState)(0),Q=(0,T.useCallback)(()=>ce(e=>e+1),[]);(0,T.useEffect)(()=>{let t=!1;return Promise.all([b.getAutomations(),b.getRuns(),b.getRunsSummary()]).then(([e,n,r])=>{t||(e.success&&e.data&&F(e.data),n.success&&n.data&&L(n.data),r.success&&r.data&&z(r.data))}).catch(n=>{t||(k.error(`Failed to load automations:`,n),o.error(e(`automations.loadFailed`)))}).finally(()=>{t||V(!1)}),()=>{t=!0}},[se,e]),(0,T.useEffect)(()=>{w.length===0&&A({quiet:!0})},[w.length,A]),(0,T.useEffect)(()=>{M===`runs`&&b.markRunsSeen().then(()=>b.getRunsSummary()).then(e=>{e.success&&e.data&&z(e.data)}).catch(()=>void 0)},[M,I.length]),(0,T.useEffect)(()=>{if(!Y)return;Z.current?.querySelector(`[role="menuitem"]`)?.focus();let e=e=>{Z.current?.contains(e.target)||X(null)},t=e=>{e.key===`Escape`&&(Z.current?.querySelector(`[aria-haspopup="menu"]`)?.focus(),X(null))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[Y]);let le=e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=Array.from(e.currentTarget.querySelectorAll(`[role="menuitem"]`));if(t.length===0)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()},ue=()=>{G(null),q(null),U(!0)},de=t=>{G(null),q({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),U(!0)},fe=e=>{G(e),q(null),X(null),U(!0)},pe=async t=>{J(!0);try{let n=W?await b.updateAutomation(W.id,t):await b.createAutomation(t);n.success?(U(!1),Q()):o.error(n.error||e(`automations.saveFailed`))}catch(t){k.error(`Failed to save automation:`,t),o.error(e(`automations.saveFailed`))}finally{J(!1)}},$=async(t,n)=>{if(Z.current?.querySelector(`[aria-haspopup="menu"]`)?.focus(),X(null),n!==`delete`||await h({title:e(`automations.deleteConfirmTitle`,{name:t.name}),description:e(`automations.deleteConfirmDescription`),destructive:!0}))try{n===`pause`?await b.pauseAutomation(t.id):n===`resume`?await b.resumeAutomation(t.id):n===`run`?(await b.runAutomationNow(t.id),o.success(e(`automations.runQueued`))):await b.deleteAutomation(t.id),Q()}catch(t){k.error(`Automation ${n} failed:`,t),o.error(e(`automations.actionFailed`))}},me=e=>e.status===`succeeded`?(0,E.jsx)(a,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,E.jsx)(c,{className:`h-4 w-4 text-red-500`}):(0,E.jsx)(s,{className:`h-4 w-4 animate-spin text-gray-400`}),he=t=>P.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`);return(0,E.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`automations-page`,children:[(0,E.jsx)(ae,{title:e(`automations.title`),actions:(0,E.jsxs)(y,{size:`sm`,onClick:ue,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,E.jsx)(re,{className:`h-3.5 w-3.5`}),e(`automations.newAutomation`)]}),children:(0,E.jsx)(`div`,{role:`tablist`,"aria-label":e(`automations.title`),className:`flex items-center rounded-xl bg-black/4 p-0.5 dark:bg-white/6`,onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;let t=M===`automations`?`runs`:`automations`;e.preventDefault(),N(t),document.getElementById(`automations-tab-${t}`)?.focus()},children:[`automations`,`runs`].map(t=>(0,E.jsx)(`button`,{id:`automations-tab-${t}`,type:`button`,role:`tab`,"aria-selected":M===t,tabIndex:M===t?0:-1,onClick:()=>N(t),"data-testid":`automations-tab-${t}`,className:C(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,M===t?`bg-white text-gray-900 shadow-xs dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`automations.tab.${t}`)},t))})}),(0,E.jsxs)(`div`,{role:`tabpanel`,"aria-labelledby":`automations-tab-${M}`,className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-4 scrollbar-thin`,children:[M===`automations`?B?(0,E.jsx)(p,{srOnly:!0}):P.length===0?(0,E.jsx)(m,{icon:ne,title:e(`automations.empty`)}):(0,E.jsx)(`div`,{className:`mx-auto w-full max-w-3xl space-y-2`,children:P.map(n=>(0,E.jsx)(`div`,{"data-testid":`automation-row`,className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{className:`min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`p`,{className:`truncate text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.name}),(0,E.jsx)(`span`,{className:C(`rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,n.status===`active`?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:`bg-gray-500/10 text-gray-500 dark:text-dark-500`),children:e(`automations.status.${n.status}`)})]}),(0,E.jsxs)(`p`,{className:`mt-0.5 truncate text-[12px] text-gray-500 dark:text-dark-500`,children:[g(n.triggers,t.language,e),!_(n.triggers)&&n.nextRunAt&&(0,E.jsxs)(E.Fragment,{children:[` · `,e(`automations.nextRun`,{when:new Intl.DateTimeFormat(t.language,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(n.nextRunAt)})]})]})]}),(0,E.jsxs)(`div`,{ref:Y===n.id?Z:void 0,className:`relative shrink-0`,children:[(0,E.jsx)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":Y===n.id,onClick:()=>X(e=>e===n.id?null:n.id),"aria-label":e(`automations.actions`),"data-testid":`automation-menu`,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-black/4 hover:text-gray-700 dark:hover:bg-white/6 dark:hover:text-dark-800`,children:(0,E.jsx)(ee,{className:`h-4 w-4`})}),Y===n.id&&(0,E.jsxs)(`div`,{role:`menu`,onKeyDown:le,className:`absolute inset-e-0 top-8 z-20 w-44 rounded-xl border border-black/[0.07] bg-white p-1 shadow-lg dark:border-white/8 dark:bg-dark-100`,children:[(0,E.jsx)(j,{icon:f,label:e(`common.edit`),onClick:()=>fe(n)}),n.status===`active`?(0,E.jsx)(j,{icon:te,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,E.jsx)(j,{icon:d,label:e(`automations.resume`),onClick:()=>$(n,`resume`)}),(0,E.jsx)(j,{icon:u,label:e(`automations.runNow`),onClick:()=>$(n,`run`)}),(0,E.jsx)(j,{icon:ie,label:e(`common.delete`),destructive:!0,onClick:()=>$(n,`delete`)})]})]})]})},n.id))}):null,M===`automations`&&!B&&(0,E.jsxs)(`div`,{className:`mx-auto mt-8 w-full max-w-3xl`,children:[(0,E.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e(`automations.templatesTitle`)}),(0,E.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:O.map(n=>(0,E.jsxs)(`button`,{type:`button`,onClick:()=>de(n),"data-testid":`automation-template`,className:`rounded-2xl border border-black/6 bg-white/40 px-4 py-3 text-start transition-colors hover:bg-white/80 dark:border-white/[0.07] dark:bg-dark-100/40 dark:hover:bg-dark-100/80`,children:[(0,E.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:e(`automations.templates.${n.id}.name`)}),(0,E.jsx)(`p`,{className:`mt-0.5 text-[12px] text-gray-500 dark:text-dark-500`,children:e(`automations.templates.${n.id}.description`)}),(0,E.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:g(n.triggers,t.language,e)})]},n.id))})]}),M===`runs`&&(0,E.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl space-y-4`,children:[R&&(0,E.jsx)(D,{days:R.days,locale:t.language}),I.length===0?(0,E.jsx)(m,{icon:l,size:`sm`,title:e(`automations.noRuns`)}):(0,E.jsx)(`div`,{className:`space-y-1`,"data-testid":`automation-run-list`,children:I.map(r=>(0,E.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-black/5 bg-white/50 px-3 py-2 dark:border-white/6 dark:bg-dark-100/50`,children:[me(r),(0,E.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`p`,{className:`truncate text-[13px] text-gray-900 dark:text-dark-900`,children:he(r.automationId)}),(0,E.jsxs)(`p`,{className:`truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[S(r.scheduledFor,t.language),r.error&&(0,E.jsxs)(E.Fragment,{children:[` · `,(0,E.jsx)(`span`,{className:`text-red-500`,children:r.error})]})]})]}),r.sessionId&&(0,E.jsx)(`button`,{onClick:()=>n(`/c/${r.sessionId}`),"data-testid":`automation-run-open`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openChat`)}),r.workTaskId&&(0,E.jsx)(`button`,{onClick:()=>n(`/work/${r.workTaskId}`),"data-testid":`automation-run-open-task`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openTask`)})]},r.id))})]})]}),(0,E.jsx)(v,{open:H,automation:W,initial:K,models:w,saving:oe,onClose:()=>U(!1),onSave:e=>void pe(e)})]})};function j({icon:e,label:t,destructive:n,onClick:r}){return(0,E.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:r,className:C(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-start text-[13px] transition-colors`,n?`text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`:`text-gray-700 hover:bg-black/4 dark:text-dark-700 dark:hover:bg-white/6`),children:[(0,E.jsx)(e,{className:`h-3.5 w-3.5`}),t]})}export{A as default};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{d as r}from"./router-vendor-DLHZHk4K.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{Kn as a,Or as o,Rt as s,Un as c,Wn as l,Z as u,it as d,kn as ee,lt as te,st as f,t as ne,tt as re,v as ie}from"./ui-vendor-C7v9zeJX.js";import{i as ae,n as p,r as m}from"./ui-Byzdw4-Y.js";import{t as h}from"./confirmStore-CKkUtP9c.js";import{n as g,r as _,t as v}from"./AutomationModal-VMrwN5y4.js";import{t as y}from"./Button-D6d7HYoa.js";import{T as b}from"./api-BPTwf2O4.js";import{t as x}from"./chatStore-wi8VDo6B.js";import{i as S,t as C}from"./utils-BXRzbHJC.js";import{t as w}from"./logger-DAQsBb8I.js";var T=e(t(),1),E=n();function D({days:e,locale:t}){let{t:n}=i(),r=e.reduce((e,t)=>e+t.succeeded,0),a=e.reduce((e,t)=>e+t.failed,0),o=Math.max(1,...e.map(e=>e.succeeded+e.failed)),s=new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}),c=new Date,l=e=>s.format(new Date(c.getFullYear(),c.getMonth(),c.getDate()-29+e));return(0,E.jsxs)(`div`,{className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,"data-testid":`automation-run-strip`,children:[(0,E.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,E.jsx)(`p`,{className:`text-[12px] font-medium text-gray-700 dark:text-dark-700`,children:n(`automations.runHistory`)}),(0,E.jsxs)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:[(0,E.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[r,` `,n(`automations.succeeded`)]}),` · `,(0,E.jsxs)(`span`,{className:`text-red-500 dark:text-red-400`,children:[a,` `,n(`automations.failed`)]})]})]}),(0,E.jsx)(`div`,{className:`flex h-12 items-end gap-[3px]`,children:e.map((e,t)=>{let n=e.succeeded+e.failed;if(n===0)return(0,E.jsx)(`div`,{title:l(t),className:`h-[3px] flex-1 rounded-xs bg-black/6 dark:bg-white/8`},t);let r=Math.max(6,Math.round(n/o*48)),i=Math.round(e.failed/n*r);return(0,E.jsxs)(`div`,{title:`${l(t)}: ${e.succeeded}✓ ${e.failed}✗`,className:`flex flex-1 flex-col justify-end overflow-hidden rounded-xs`,style:{height:r},children:[(0,E.jsx)(`div`,{className:`w-full bg-emerald-500/80`,style:{height:r-i}}),i>0&&(0,E.jsx)(`div`,{className:`w-full bg-red-500/80`,style:{height:i}})]},t)})})]})}var O=[{id:`morningBrief`,instructions:`Put together my morning brief: the top world, business, and tech headlines from the last 24 hours with one-line summaries, and one story worth reading in depth and why. Keep the whole thing scannable.`,triggers:[{kind:`daily`,hour:7,minute:30}]},{id:`newsDigest`,instructions:`Summarize the most important AI news from the last 24 hours: model releases, notable research papers, funding rounds, and policy changes. For each item add one sentence on why it matters. Skip minor product updates and rumors.`,triggers:[{kind:`daily`,hour:8,minute:0}]},{id:`weeklyReview`,instructions:`Help me wrap the week: prompt me to reflect on what I accomplished, what is still open, and what the top priorities for next week should be. Structure it as a short template I can fill in.`,triggers:[{kind:`weekly`,dayOfWeek:5,hour:16,minute:0}]},{id:`monthlyReport`,instructions:`Draft a monthly status report outline: key accomplishments, metrics to review, risks, and goals for the next month. Leave placeholders where my specifics belong.`,triggers:[{kind:`monthly`,dayOfMonth:1,hour:9,minute:0}]}],k=w(`pages:automations`),A=()=>{let{t:e,i18n:t}=i(),n=r(),w=x(e=>e.models),A=x(e=>e.loadModels),[M,N]=(0,T.useState)(`automations`),[P,F]=(0,T.useState)([]),[I,L]=(0,T.useState)([]),[R,z]=(0,T.useState)(null),[B,V]=(0,T.useState)(!0),[H,U]=(0,T.useState)(!1),[W,G]=(0,T.useState)(null),[K,q]=(0,T.useState)(null),[oe,J]=(0,T.useState)(!1),[Y,X]=(0,T.useState)(null),Z=(0,T.useRef)(null),[se,ce]=(0,T.useState)(0),Q=(0,T.useCallback)(()=>ce(e=>e+1),[]);(0,T.useEffect)(()=>{let t=!1;return Promise.all([b.getAutomations(),b.getRuns(),b.getRunsSummary()]).then(([e,n,r])=>{t||(e.success&&e.data&&F(e.data),n.success&&n.data&&L(n.data),r.success&&r.data&&z(r.data))}).catch(n=>{t||(k.error(`Failed to load automations:`,n),o.error(e(`automations.loadFailed`)))}).finally(()=>{t||V(!1)}),()=>{t=!0}},[se,e]),(0,T.useEffect)(()=>{w.length===0&&A({quiet:!0})},[w.length,A]),(0,T.useEffect)(()=>{M===`runs`&&b.markRunsSeen().then(()=>b.getRunsSummary()).then(e=>{e.success&&e.data&&z(e.data)}).catch(()=>void 0)},[M,I.length]),(0,T.useEffect)(()=>{if(!Y)return;Z.current?.querySelector(`[role="menuitem"]`)?.focus();let e=e=>{Z.current?.contains(e.target)||X(null)},t=e=>{e.key===`Escape`&&(Z.current?.querySelector(`[aria-haspopup="menu"]`)?.focus(),X(null))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[Y]);let le=e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=Array.from(e.currentTarget.querySelectorAll(`[role="menuitem"]`));if(t.length===0)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`ArrowDown`?(n+1)%t.length:(n-1+t.length)%t.length]?.focus()},ue=()=>{G(null),q(null),U(!0)},de=t=>{G(null),q({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),U(!0)},fe=e=>{G(e),q(null),X(null),U(!0)},pe=async t=>{J(!0);try{let n=W?await b.updateAutomation(W.id,t):await b.createAutomation(t);n.success?(U(!1),Q()):o.error(n.error||e(`automations.saveFailed`))}catch(t){k.error(`Failed to save automation:`,t),o.error(e(`automations.saveFailed`))}finally{J(!1)}},$=async(t,n)=>{if(Z.current?.querySelector(`[aria-haspopup="menu"]`)?.focus(),X(null),n!==`delete`||await h({title:e(`automations.deleteConfirmTitle`,{name:t.name}),description:e(`automations.deleteConfirmDescription`),destructive:!0}))try{n===`pause`?await b.pauseAutomation(t.id):n===`resume`?await b.resumeAutomation(t.id):n===`run`?(await b.runAutomationNow(t.id),o.success(e(`automations.runQueued`))):await b.deleteAutomation(t.id),Q()}catch(t){k.error(`Automation ${n} failed:`,t),o.error(e(`automations.actionFailed`))}},me=e=>e.status===`succeeded`?(0,E.jsx)(a,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,E.jsx)(c,{className:`h-4 w-4 text-red-500`}):(0,E.jsx)(s,{className:`h-4 w-4 animate-spin text-gray-400`}),he=t=>P.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`);return(0,E.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`automations-page`,children:[(0,E.jsx)(ae,{title:e(`automations.title`),actions:(0,E.jsxs)(y,{size:`sm`,onClick:ue,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,E.jsx)(re,{className:`h-3.5 w-3.5`}),e(`automations.newAutomation`)]}),children:(0,E.jsx)(`div`,{role:`tablist`,"aria-label":e(`automations.title`),className:`flex items-center rounded-xl bg-black/4 p-0.5 dark:bg-white/6`,onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;let t=M===`automations`?`runs`:`automations`;e.preventDefault(),N(t),document.getElementById(`automations-tab-${t}`)?.focus()},children:[`automations`,`runs`].map(t=>(0,E.jsx)(`button`,{id:`automations-tab-${t}`,type:`button`,role:`tab`,"aria-selected":M===t,tabIndex:M===t?0:-1,onClick:()=>N(t),"data-testid":`automations-tab-${t}`,className:C(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,M===t?`bg-white text-gray-900 shadow-xs dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`automations.tab.${t}`)},t))})}),(0,E.jsxs)(`div`,{role:`tabpanel`,"aria-labelledby":`automations-tab-${M}`,className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-4 scrollbar-thin`,children:[M===`automations`?B?(0,E.jsx)(p,{srOnly:!0}):P.length===0?(0,E.jsx)(m,{icon:ne,title:e(`automations.empty`)}):(0,E.jsx)(`div`,{className:`mx-auto w-full max-w-3xl space-y-2`,children:P.map(n=>(0,E.jsx)(`div`,{"data-testid":`automation-row`,className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{className:`min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`p`,{className:`truncate text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.name}),(0,E.jsx)(`span`,{className:C(`rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,n.status===`active`?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:`bg-gray-500/10 text-gray-500 dark:text-dark-500`),children:e(`automations.status.${n.status}`)})]}),(0,E.jsxs)(`p`,{className:`mt-0.5 truncate text-[12px] text-gray-500 dark:text-dark-500`,children:[g(n.triggers,t.language,e),!_(n.triggers)&&n.nextRunAt&&(0,E.jsxs)(E.Fragment,{children:[` · `,e(`automations.nextRun`,{when:new Intl.DateTimeFormat(t.language,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(n.nextRunAt)})]})]})]}),(0,E.jsxs)(`div`,{ref:Y===n.id?Z:void 0,className:`relative shrink-0`,children:[(0,E.jsx)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":Y===n.id,onClick:()=>X(e=>e===n.id?null:n.id),"aria-label":e(`automations.actions`),"data-testid":`automation-menu`,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-black/4 hover:text-gray-700 dark:hover:bg-white/6 dark:hover:text-dark-800`,children:(0,E.jsx)(ee,{className:`h-4 w-4`})}),Y===n.id&&(0,E.jsxs)(`div`,{role:`menu`,onKeyDown:le,className:`absolute inset-e-0 top-8 z-20 w-44 rounded-xl border border-black/[0.07] bg-white p-1 shadow-lg dark:border-white/8 dark:bg-dark-100`,children:[(0,E.jsx)(j,{icon:f,label:e(`common.edit`),onClick:()=>fe(n)}),n.status===`active`?(0,E.jsx)(j,{icon:te,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,E.jsx)(j,{icon:d,label:e(`automations.resume`),onClick:()=>$(n,`resume`)}),(0,E.jsx)(j,{icon:u,label:e(`automations.runNow`),onClick:()=>$(n,`run`)}),(0,E.jsx)(j,{icon:ie,label:e(`common.delete`),destructive:!0,onClick:()=>$(n,`delete`)})]})]})]})},n.id))}):null,M===`automations`&&!B&&(0,E.jsxs)(`div`,{className:`mx-auto mt-8 w-full max-w-3xl`,children:[(0,E.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e(`automations.templatesTitle`)}),(0,E.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:O.map(n=>(0,E.jsxs)(`button`,{type:`button`,onClick:()=>de(n),"data-testid":`automation-template`,className:`rounded-2xl border border-black/6 bg-white/40 px-4 py-3 text-start transition-colors hover:bg-white/80 dark:border-white/[0.07] dark:bg-dark-100/40 dark:hover:bg-dark-100/80`,children:[(0,E.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:e(`automations.templates.${n.id}.name`)}),(0,E.jsx)(`p`,{className:`mt-0.5 text-[12px] text-gray-500 dark:text-dark-500`,children:e(`automations.templates.${n.id}.description`)}),(0,E.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:g(n.triggers,t.language,e)})]},n.id))})]}),M===`runs`&&(0,E.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl space-y-4`,children:[R&&(0,E.jsx)(D,{days:R.days,locale:t.language}),I.length===0?(0,E.jsx)(m,{icon:l,size:`sm`,title:e(`automations.noRuns`)}):(0,E.jsx)(`div`,{className:`space-y-1`,"data-testid":`automation-run-list`,children:I.map(r=>(0,E.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-black/5 bg-white/50 px-3 py-2 dark:border-white/6 dark:bg-dark-100/50`,children:[me(r),(0,E.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`p`,{className:`truncate text-[13px] text-gray-900 dark:text-dark-900`,children:he(r.automationId)}),(0,E.jsxs)(`p`,{className:`truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[S(r.scheduledFor,t.language),r.error&&(0,E.jsxs)(E.Fragment,{children:[` · `,(0,E.jsx)(`span`,{className:`text-red-500`,children:r.error})]})]})]}),r.sessionId&&(0,E.jsx)(`button`,{onClick:()=>n(`/c/${r.sessionId}`),"data-testid":`automation-run-open`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openChat`)}),r.workTaskId&&(0,E.jsx)(`button`,{onClick:()=>n(`/work/${r.workTaskId}`),"data-testid":`automation-run-open-task`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openTask`)})]},r.id))})]})]}),(0,E.jsx)(v,{open:H,automation:W,initial:K,models:w,saving:oe,onClose:()=>U(!1),onSave:e=>void pe(e)})]})};function j({icon:e,label:t,destructive:n,onClick:r}){return(0,E.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:r,className:C(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-start text-[13px] transition-colors`,n?`text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`:`text-gray-700 hover:bg-black/4 dark:text-dark-700 dark:hover:bg-white/6`),children:[(0,E.jsx)(e,{className:`h-3.5 w-3.5`}),t]})}export{A as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{t as r}from"./useTranslation-CKqEdZ8j.js";import{Or as i,c as a,n as o,p as s}from"./ui-vendor-DsURZnZt.js";import"./ui-DxaHE9GD.js";import{t as c}from"./Button-D6d7HYoa.js";import{t as l}from"./logger-DAQsBb8I.js";var u=e(t(),1),d=n(),f=l(`components:avatar-upload`),p=({value:e,onChange:t,className:n=``})=>{let{t:l}=r(),p=(0,u.useRef)(null),[m,h]=(0,u.useState)(!1),[g,_]=(0,u.useState)(!1),v=async e=>{if(!e.type.startsWith(`image/`))i.error(l(`user.avatar.invalidFile`));else if(e.size>2097152)i.error(l(`user.avatar.fileTooLarge`));else{h(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),i.success(l(`user.avatar.uploaded`))},n.onerror=()=>{i.error(l(`user.avatar.readFailed`))},n.readAsDataURL(e)}catch(e){f.error(`Failed to upload avatar:`,e),i.error(l(`user.avatar.uploadFailed`))}finally{h(!1)}}},y=e=>{let t=e.target.files?.[0];t&&v(t)},b=e=>{e.preventDefault(),_(!0)},x=e=>{e.preventDefault(),_(!1)},S=e=>{e.preventDefault(),_(!1);let t=e.dataTransfer.files?.[0];t&&v(t)},C=()=>{t(``),i.success(l(`user.avatar.removed`))},w=()=>e||null;return(0,d.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:l(`user.avatar.label`)}),(0,d.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,d.jsx)(`div`,{className:`shrink-0`,children:(0,d.jsx)(`div`,{className:`w-20 h-20 rounded-full overflow-hidden bg-gray-100 dark:bg-dark-200 border-2 border-gray-300 dark:border-dark-300 flex items-center justify-center`,children:w()?(0,d.jsx)(`img`,{src:w(),alt:`Avatar preview`,className:`w-full h-full object-cover`}):(0,d.jsx)(a,{className:`h-8 w-8 text-gray-400 dark:text-gray-500`})})}),(0,d.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[e?(0,d.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,d.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:l(`user.avatar.customAvatar`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l(`user.avatar.clickToChange`)})]}),(0,d.jsx)(c,{variant:`ghost`,size:`sm`,onClick:C,className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,d.jsx)(o,{className:`h-4 w-4`})})]}):(0,d.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors ${g?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>p.current?.click(),children:[(0,d.jsx)(s,{className:`h-8 w-8 mx-auto text-gray-400 dark:text-gray-500 mb-2`}),(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:l(`user.avatar.uploadAvatarImage`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-2`,children:l(`user.avatar.dragAndDrop`)}),(0,d.jsxs)(c,{variant:`outline`,size:`sm`,disabled:m,className:`mx-auto`,children:[(0,d.jsx)(s,{className:`h-4 w-4 mr-2`}),l(m?`user.avatar.uploading`:`user.avatar.chooseImage`)]})]}),(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:l(`user.avatar.enterImageUrl`)}),(0,d.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/avatar.jpg`})]})]})]}),(0,d.jsx)(`input`,{ref:p,type:`file`,accept:`image/*`,onChange:y,className:`hidden`}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:l(`user.avatar.supportedFormats`)})]})})};export{p as t};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{t as r}from"./useTranslation-CKqEdZ8j.js";import{Or as i,c as a,n as o,p as s}from"./ui-vendor-C7v9zeJX.js";import"./ui-Byzdw4-Y.js";import{t as c}from"./Button-D6d7HYoa.js";import{t as l}from"./logger-DAQsBb8I.js";var u=e(t(),1),d=n(),f=l(`components:avatar-upload`),p=({value:e,onChange:t,className:n=``})=>{let{t:l}=r(),p=(0,u.useRef)(null),[m,h]=(0,u.useState)(!1),[g,_]=(0,u.useState)(!1),v=async e=>{if(!e.type.startsWith(`image/`))i.error(l(`user.avatar.invalidFile`));else if(e.size>2097152)i.error(l(`user.avatar.fileTooLarge`));else{h(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),i.success(l(`user.avatar.uploaded`))},n.onerror=()=>{i.error(l(`user.avatar.readFailed`))},n.readAsDataURL(e)}catch(e){f.error(`Failed to upload avatar:`,e),i.error(l(`user.avatar.uploadFailed`))}finally{h(!1)}}},y=e=>{let t=e.target.files?.[0];t&&v(t)},b=e=>{e.preventDefault(),_(!0)},x=e=>{e.preventDefault(),_(!1)},S=e=>{e.preventDefault(),_(!1);let t=e.dataTransfer.files?.[0];t&&v(t)},C=()=>{t(``),i.success(l(`user.avatar.removed`))},w=()=>e||null;return(0,d.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:l(`user.avatar.label`)}),(0,d.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,d.jsx)(`div`,{className:`shrink-0`,children:(0,d.jsx)(`div`,{className:`w-20 h-20 rounded-full overflow-hidden bg-gray-100 dark:bg-dark-200 border-2 border-gray-300 dark:border-dark-300 flex items-center justify-center`,children:w()?(0,d.jsx)(`img`,{src:w(),alt:`Avatar preview`,className:`w-full h-full object-cover`}):(0,d.jsx)(a,{className:`h-8 w-8 text-gray-400 dark:text-gray-500`})})}),(0,d.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[e?(0,d.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,d.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:l(`user.avatar.customAvatar`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l(`user.avatar.clickToChange`)})]}),(0,d.jsx)(c,{variant:`ghost`,size:`sm`,onClick:C,className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,d.jsx)(o,{className:`h-4 w-4`})})]}):(0,d.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors ${g?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>p.current?.click(),children:[(0,d.jsx)(s,{className:`h-8 w-8 mx-auto text-gray-400 dark:text-gray-500 mb-2`}),(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:l(`user.avatar.uploadAvatarImage`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-2`,children:l(`user.avatar.dragAndDrop`)}),(0,d.jsxs)(c,{variant:`outline`,size:`sm`,disabled:m,className:`mx-auto`,children:[(0,d.jsx)(s,{className:`h-4 w-4 mr-2`}),l(m?`user.avatar.uploading`:`user.avatar.chooseImage`)]})]}),(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:l(`user.avatar.enterImageUrl`)}),(0,d.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/avatar.jpg`})]})]})]}),(0,d.jsx)(`input`,{ref:p,type:`file`,accept:`image/*`,onChange:y,className:`hidden`}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:l(`user.avatar.supportedFormats`)})]})})};export{p as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{d as i}from"./router-vendor-DLHZHk4K.js";import{t as a}from"./useTranslation-CKqEdZ8j.js";import{An as o,B as s,Bn as c,Kn as l,Or as u,Qn as d,Zn as f,g as p,n as m,p as h,tt as g,v as _}from"./ui-vendor-DsURZnZt.js";import{i as v}from"./ui-DxaHE9GD.js";import{t as y}from"./confirmStore-CKkUtP9c.js";import{t as b}from"./Button-D6d7HYoa.js";import{t as x}from"./utils-BXRzbHJC.js";import{a as S,c as C,d as w,i as T,l as E,n as D,o as O,r as k,s as A,t as j,u as M}from"./calendarDates-Co3o_05Y.js";import{t as N}from"./useDialogFocus-DpTun-ZV.js";import{O as P,T as F}from"./api-Dasm8tVY.js";import{t as I}from"./logger-DAQsBb8I.js";import{t as L}from"./ShareDialog-NwirTDLR.js";var R=e(t(),1),z=r(),B={event:`bg-primary-500/15 text-primary-700 hover:bg-primary-500/25 dark:text-primary-300`,automation:`bg-warning-500/15 text-ink hover:bg-warning-500/25`,runSucceeded:`bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300`,runFailed:`bg-red-500/15 text-red-700 hover:bg-red-500/25 dark:text-red-300`};function V({event:e,label:t,onClick:n}){let{t:r}=a(),i=e.variant===`automation`?{Icon:c,label:r(`calendar.chipStatus.automation`)}:e.variant===`runSucceeded`?{Icon:l,label:r(`calendar.chipStatus.runSucceeded`)}:e.variant===`runFailed`?{Icon:p,label:r(`calendar.chipStatus.runFailed`)}:null;return(0,z.jsxs)(`button`,{type:`button`,"data-testid":`calendar-event-chip`,"data-variant":e.variant??`event`,title:e.title,onClick:e=>{e.stopPropagation(),n()},className:x(`flex w-full items-center gap-1 rounded-md px-1.5 py-0.5 text-start text-[11px] leading-4 transition-colors`,B[e.variant??`event`],e.baseEventId&&`opacity-75`),children:[i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i.Icon,{className:`h-3 w-3 shrink-0`,"aria-hidden":`true`}),(0,z.jsx)(`span`,{className:`sr-only`,children:i.label})]}),(0,z.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]})}var H=3;function ee({year:e,monthIndex:t,events:n,onDayClick:r,onEventClick:i,onShowDay:o}){let{t:s,i18n:c}=a(),l=(0,R.useMemo)(()=>k(e,t),[e,t]),u=new Date,d=(0,R.useMemo)(()=>{let e=new Map;for(let t of n){let n=new Date(t.startAt),r=`${n.getFullYear()}-${n.getMonth()}-${n.getDate()}`,i=e.get(r);i?i.push(t):e.set(r,[t])}return e},[n]),f=(0,R.useMemo)(()=>w(c.language),[c.language]),p=(0,R.useMemo)(()=>new Intl.DateTimeFormat(c.language,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}),[c.language]);return(0,z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`calendar-month-grid`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-7 border-b border-black/6 dark:border-white/[0.07]`,children:f.map(e=>(0,z.jsx)(`div`,{className:`px-2 py-1.5 text-center text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e},e))}),(0,z.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-7 grid-rows-6`,children:l.map(e=>{let n=e.getMonth()===t,a=T(e,u),l=`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`,f=d.get(l)??[],m=f.length-H;return(0,z.jsxs)(`div`,{role:`gridcell`,"data-testid":`calendar-day-cell`,onClick:()=>r(e),className:x(`flex min-h-0 cursor-pointer flex-col gap-0.5 border-b border-e border-black/4 p-1 transition-colors hover:bg-black/2 dark:border-white/4 dark:hover:bg-white/3`,!n&&`opacity-40`),children:[(0,z.jsx)(`button`,{type:`button`,"aria-label":s(`calendar.newEventOn`,{date:p.format(e)}),"aria-current":a?`date`:void 0,className:x(`flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-[12px]`,a?`bg-ink font-semibold text-ink-inverse`:`text-ink-muted`),children:e.getDate()}),(0,z.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0.5 overflow-hidden`,children:[f.slice(0,H).map(e=>(0,z.jsx)(V,{event:e,label:e.allDay?e.title:`${A(e.startAt,c.language)} ${e.title}`,onClick:()=>i(e)},e.id)),m>0&&(0,z.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o?.(e)},title:s(`calendar.showDay`,{date:p.format(e)}),className:`rounded-sm px-1 text-start text-[10px] text-ink-muted hover:text-ink`,children:s(`calendar.more`,{n:m})})]})]},l)})})]})}var U=48;function te({anchor:e,events:t,dayCount:n=7,onDayClick:r,onEventClick:i}){let{t:o,i18n:s}=a(),c=(0,R.useMemo)(()=>n===1?[new Date(e.getFullYear(),e.getMonth(),e.getDate())]:M(e),[e,n]),l=new Date,u=(0,R.useMemo)(()=>new Intl.DateTimeFormat(s.language,{hour:`numeric`}),[s.language]),d=(0,R.useMemo)(()=>new Intl.DateTimeFormat(s.language,{weekday:`long`,month:`long`,day:`numeric`,hour:`numeric`}),[s.language]),f=(0,R.useRef)(null),[p,m]=(0,R.useState)(`0-9`),h=(e,t,n)=>{let r=s.dir()===`rtl`?-1:1,i={ArrowRight:[r,0],ArrowLeft:[-r,0],ArrowDown:[0,1],ArrowUp:[0,-1]}[e.key];if(!i)return;let a=Math.min(c.length-1,Math.max(0,t+i[0])),o=Math.min(23,Math.max(0,n+i[1]));e.preventDefault();let l=`${a}-${o}`;m(l),f.current?.querySelector(`[data-slot="${l}"]`)?.focus()},g=(0,R.useMemo)(()=>new Intl.DateTimeFormat(s.language,{weekday:`short`,day:`numeric`}),[s.language]),_=e=>t.filter(t=>t.allDay&&T(new Date(t.startAt),e)),v=e=>t.filter(t=>!t.allDay&&T(new Date(t.startAt),e));return(0,z.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto scrollbar-thin`,"data-testid":`calendar-week-grid`,children:(0,z.jsxs)(`div`,{ref:f,className:`grid grid-cols-[3.5rem_repeat(7,1fr)]`,children:[(0,z.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-black/6 bg-surface dark:border-white/[0.07]`}),c.map(e=>(0,z.jsxs)(`div`,{className:`sticky top-0 z-10 border-b border-e border-black/6 bg-surface px-1 py-1.5 dark:border-white/[0.07]`,children:[(0,z.jsx)(`span`,{className:x(`block truncate text-center text-[11px] font-medium`,T(e,l)?`text-primary-600 dark:text-primary-400`:`text-gray-500 dark:text-dark-500`),children:g.format(e)}),(0,z.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:_(e).map(e=>(0,z.jsx)(V,{event:e,label:e.title,onClick:()=>i(e)},e.id))})]},e.toISOString())),Array.from({length:24},(e,t)=>(0,z.jsxs)(R.Fragment,{children:[(0,z.jsx)(`div`,{className:`relative border-b border-black/4 pe-1.5 text-end text-[10px] text-gray-400 dark:border-white/4 dark:text-dark-500`,children:(0,z.jsx)(`span`,{className:`relative -top-1.5`,children:t>0?u.format(new Date(2024,0,1,t)):``})}),c.map((e,n)=>{let a=`${n}-${t}`,c=v(e).filter(e=>new Date(e.startAt).getHours()===t);return(0,z.jsxs)(`div`,{onClick:()=>r(e,t),style:{height:U},className:`relative cursor-pointer space-y-0.5 overflow-hidden border-b border-e border-black/4 p-0.5 transition-colors hover:bg-black/2 dark:border-white/4 dark:hover:bg-white/3`,children:[(0,z.jsx)(`button`,{type:`button`,"data-slot":a,tabIndex:p===a?0:-1,"aria-label":o(`calendar.newEventOn`,{date:d.format(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t))}),onFocus:()=>m(a),onKeyDown:e=>h(e,n,t),className:`absolute inset-0 focus-visible:-outline-offset-2`}),c.map(e=>(0,z.jsx)(`div`,{className:`relative`,children:(0,z.jsx)(V,{event:e,label:`${A(e.startAt,s.language)} ${e.title}`,onClick:()=>i(e)})},e.id))]},`${e.toISOString()}-${t}`)})]},t))]})})}var W=n(),G=e=>!e||e.kind===`once`||e.kind===`hourly`||e.kind===`event`?`none`:e.kind,K=(e,t)=>{let n=new Date(t),r=n.getHours(),i=n.getMinutes();switch(e){case`daily`:return{kind:`daily`,hour:r,minute:i};case`weekly`:return{kind:`weekly`,dayOfWeek:n.getDay(),hour:r,minute:i};case`monthly`:return{kind:`monthly`,dayOfMonth:n.getDate(),hour:r,minute:i};case`yearly`:return{kind:`yearly`,month:n.getMonth()+1,dayOfMonth:n.getDate(),hour:r,minute:i};default:return null}},q=`w-full rounded-lg border border-black/8 bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-100 dark:text-dark-900`,J=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`;function ne({open:e,event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s}){return e?(0,z.jsx)(Y,{event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s},`${t?.id??`new`}:${n}`):null}function Y({event:e,initialStartAt:t,calendars:n,saving:r,onClose:i,onSave:o,onDelete:s}){let{t:c}=a(),l=(0,R.useRef)(null);N(l,{onClose:i});let u=e?.startAt??t,[d,f]=(0,R.useState)(e?.title??``),[p,h]=(0,R.useState)(e?.notes??``),[g,v]=(0,R.useState)(C(u)),[b,x]=(0,R.useState)(e?E(u):`09:00`),[S,w]=(0,R.useState)(e?.endAt===void 0?``:E(e.endAt)),[T,O]=(0,R.useState)(e?.allDay??!1),[k,A]=(0,R.useState)(G(e?.recurrence)),[j,M]=(0,R.useState)(e?.calendarId??``),[P,F]=(0,R.useState)(e?.reminderMinutes===void 0?``:String(e.reminderMinutes)),I=()=>{if(!d.trim()||!g)return;let e=D(g,T?``:b),t=!T&&S?D(g,S):null;o({title:d.trim(),notes:p.trim()?p.trim():void 0,startAt:e,endAt:t!==null&&t>e?t:null,allDay:T,recurrence:K(k,e),calendarId:j||null,reminderMinutes:P?Number(P):null})},L=[{value:``,label:c(`calendar.reminderNone`)},{value:`5`,label:c(`calendar.reminderMinutes`,{minutes:5})},{value:`15`,label:c(`calendar.reminderMinutes`,{minutes:15})},{value:`30`,label:c(`calendar.reminderMinutes`,{minutes:30})},{value:`60`,label:c(`calendar.reminderHour`)},{value:`1440`,label:c(`calendar.reminderDay`)}],B=[{value:`none`,label:c(`calendar.repeatNone`)},{value:`daily`,label:c(`calendar.repeatDaily`)},{value:`weekly`,label:c(`calendar.repeatWeekly`)},{value:`monthly`,label:c(`calendar.repeatMonthly`)},{value:`yearly`,label:c(`calendar.repeatYearly`)}];return(0,W.createPortal)((0,z.jsx)(`div`,{className:`fixed inset-0 z-2147483647 flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:i,children:(0,z.jsxs)(`div`,{ref:l,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`calendar-event-modal-title`,"data-testid":`calendar-event-modal`,className:`w-full max-w-md rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/8 dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,z.jsx)(`h3`,{id:`calendar-event-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:c(e?`calendar.editEvent`:`calendar.newEvent`)}),(0,z.jsx)(`button`,{type:`button`,onClick:i,"aria-label":c(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,z.jsx)(m,{size:20,className:`text-gray-500`})})]}),(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-title`,className:J,children:c(`calendar.eventTitle`)}),(0,z.jsx)(`input`,{id:`calendar-event-title`,"data-testid":`calendar-event-title`,type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:c(`calendar.titlePlaceholder`),className:q,maxLength:200,autoFocus:!0})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-date`,className:J,children:c(`calendar.date`)}),(0,z.jsx)(`input`,{id:`calendar-event-date`,type:`date`,value:g,onChange:e=>v(e.target.value),className:q})]}),(0,z.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px] text-gray-700 dark:text-dark-700`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:T,onChange:e=>O(e.target.checked),className:`h-4 w-4 rounded-sm accent-primary-500`}),c(`calendar.allDay`)]})})]}),!T&&(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-start`,className:J,children:c(`calendar.start`)}),(0,z.jsx)(`input`,{id:`calendar-event-start`,type:`time`,value:b,onChange:e=>x(e.target.value),className:q})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-end`,className:J,children:c(`calendar.end`)}),(0,z.jsx)(`input`,{id:`calendar-event-end`,type:`time`,value:S,onChange:e=>w(e.target.value),className:q})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-repeat`,className:J,children:c(`calendar.repeat`)}),(0,z.jsx)(`select`,{id:`calendar-event-repeat`,value:k,onChange:e=>A(e.target.value),className:q,children:B.map(e=>(0,z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-notes`,className:J,children:c(`calendar.notes`)}),(0,z.jsx)(`textarea`,{id:`calendar-event-notes`,value:p,onChange:e=>h(e.target.value),rows:3,className:q,maxLength:1e4})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-calendar`,className:J,children:c(`calendar.calendarLabel`)}),(0,z.jsxs)(`select`,{id:`calendar-event-calendar`,value:j,onChange:e=>M(e.target.value),className:q,"data-testid":`calendar-event-calendar`,children:[(0,z.jsx)(`option`,{value:``,children:c(`calendar.personalCalendar`)}),n.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-reminder`,className:J,children:c(`calendar.reminderLabel`)}),(0,z.jsx)(`select`,{id:`calendar-event-reminder`,value:P,onChange:e=>F(e.target.value),className:q,"data-testid":`calendar-event-reminder`,children:L.map(e=>(0,z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[e&&s?(0,z.jsxs)(`button`,{type:`button`,onClick:async()=>{await y({title:c(`calendar.deleteEventConfirmTitle`,{title:e.title}),description:e.recurrence?c(`calendar.deleteRecurringEventConfirmDescription`):c(`calendar.deleteEventConfirmDescription`),destructive:!0})&&s()},"data-testid":`calendar-event-delete`,className:`flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:[(0,z.jsx)(_,{className:`h-4 w-4`}),c(`common.delete`)]}):(0,z.jsx)(`span`,{}),(0,z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:i,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:c(`common.cancel`)}),(0,z.jsx)(`button`,{type:`button`,onClick:I,disabled:r||!d.trim(),"data-testid":`calendar-event-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:c(r?`common.saving`:`common.save`)})]})]})]})]})}),document.body)}var X=I(`pages:calendar`),Z=()=>{let{t:e,i18n:t}=a(),n=i(),[r,c]=(0,R.useState)(`month`),[l,p]=(0,R.useState)(()=>new Date),[_,C]=(0,R.useState)([]),[w,T]=(0,R.useState)([]),[E,D]=(0,R.useState)(!1),[k,A]=(0,R.useState)(null),[M,N]=(0,R.useState)(()=>Date.now()),[I,B]=(0,R.useState)(!1),[V,H]=(0,R.useState)([]),[U,W]=(0,R.useState)(``),[G,K]=(0,R.useState)(!1),[q,J]=(0,R.useState)(null),Y=R.useRef(null),Z=(0,R.useMemo)(()=>{if(r===`month`){let e=new Date(l.getFullYear(),l.getMonth(),1),t=O(e);return{from:t.getTime(),to:j(t,42).getTime()}}if(r===`day`){let e=new Date(l.getFullYear(),l.getMonth(),l.getDate());return{from:e.getTime(),to:j(e,1).getTime()}}let e=O(l);return{from:e.getTime(),to:j(e,7).getTime()}},[l,r]),[re,ie]=(0,R.useState)(0),Q=(0,R.useCallback)(()=>ie(e=>e+1),[]);(0,R.useEffect)(()=>{P.getCalendars().then(t=>{t.success&&t.data?H(t.data):u.error(e(`calendar.loadFailed`))}).catch(t=>{X.error(`Failed to load calendars:`,t),u.error(e(`calendar.loadFailed`))})},[re,e]),(0,R.useEffect)(()=>{let t=!1;return P.getEvents(Z.from,Z.to).then(e=>{t||e.success&&e.data&&C(e.data)}).catch(n=>{t||(X.error(`Failed to load calendar events:`,n),u.error(e(`calendar.loadFailed`)))}),Promise.all([F.getOccurrences(Z.from,Z.to),F.getRuns({from:Z.from,to:Z.to}),F.getAutomations()]).then(([n,r,i])=>{if(t)return;let a=Date.now(),o=t=>i.data?.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`),s=[];for(let e of n.data??[])e.at<=a||s.push({id:`automation:${e.automationId}:${e.at}`,title:e.name,startAt:e.at,allDay:!1,createdAt:e.at,updatedAt:e.at,variant:`automation`});for(let e of r.data??[])(e.status===`succeeded`||e.status===`failed`)&&s.push({id:`run:${e.id}`,title:o(e.automationId),startAt:e.scheduledFor,allDay:!1,createdAt:e.createdAt,updatedAt:e.createdAt,variant:e.status===`succeeded`?`runSucceeded`:`runFailed`,...e.sessionId?{sessionId:e.sessionId}:{}});T(s)}).catch(e=>{t||X.error(`Failed to project automations onto the calendar:`,e)}),()=>{t=!0}},[Z.from,Z.to,re,e]);let ae=(0,R.useMemo)(()=>[..._,...w].sort((e,t)=>e.startAt-t.startAt),[_,w]),oe=e=>{p(t=>r===`month`?new Date(t.getFullYear(),t.getMonth()+e,1):j(t,e*(r===`day`?1:7)))},$=(e,t=9)=>{A(null),N(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t,0).getTime()),D(!0)},se=t=>{if(t.variant===`runSucceeded`||t.variant===`runFailed`)t.sessionId?n(`/c/${t.sessionId}`):n(`/automations`);else if(t.variant===`automation`)n(`/automations`);else if(t.shared&&t.shared.permission!==`write`)u(e(`calendar.sharedReadOnly`));else{if(t.baseEventId){let e=_.find(e=>e.id===t.baseEventId);A(e??t)}else A(t);D(!0)}},ce=async t=>{B(!0);try{let n=k?await P.updateEvent(k.id,t):await P.createEvent(t);n.success?(D(!1),Q()):u.error(n.error||e(`calendar.saveFailed`))}catch(t){X.error(`Failed to save calendar event:`,t),u.error(e(`calendar.saveFailed`))}finally{B(!1)}},le=async()=>{if(k){B(!0);try{let t=await P.deleteEvent(k.id);t.success?(D(!1),Q()):u.error(t.error||e(`calendar.deleteFailed`))}catch(t){X.error(`Failed to delete calendar event:`,t),u.error(e(`calendar.deleteFailed`))}finally{B(!1)}}},ue=r===`month`?S(l.getFullYear(),l.getMonth(),t.language):new Intl.DateTimeFormat(t.language,{month:`long`,day:`numeric`,year:`numeric`}).format(r===`day`?l:O(l)),de=async()=>{let t=U.trim();if(!t||G)return;K(!0);let n=await P.createCalendar({name:t}).catch(()=>void 0);K(!1),n?.success?(W(``),Q()):u.error(e(`calendar.calendarSaveFailed`))},fe=async t=>{if(await y({title:e(`calendar.deleteCalendarConfirmTitle`,{name:t.name}),description:e(`calendar.deleteCalendarConfirmDescription`),destructive:!0}))try{let e=await P.deleteCalendar(t.id);if(!e.success)throw Error(e.error);Q()}catch(t){X.error(`Failed to delete calendar:`,t),u.error(e(`calendar.calendarDeleteFailed`))}},pe=async t=>{try{let e=await P.exportIcs(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`calendar.ics`,r.click(),URL.revokeObjectURL(n)}catch(t){X.error(`Failed to export the calendar:`,t),u.error(e(`calendar.exportFailed`))}},me=async t=>{try{let n=await t.text(),r=await P.importIcs(n);r.success&&r.data?(u.success(e(`calendar.importResult`,{total:r.data.imported})),Q()):u.error(r.error||e(`calendar.importFailed`))}catch(t){X.error(`Failed to import the calendar:`,t),u.error(e(`calendar.importFailed`))}};return(0,z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`calendar-page`,children:[(0,z.jsx)(v,{title:e(`calendar.title`),actions:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/4 p-0.5 dark:bg-white/6`,children:[`month`,`week`,`day`].map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>c(t),"aria-pressed":r===t,"data-testid":`calendar-view-${t}`,className:x(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,r===t?`bg-white text-gray-900 shadow-xs dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`calendar.${t}`)},t))}),(0,z.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,z.jsx)(b,{size:`sm`,variant:`ghost`,onClick:()=>oe(-1),className:`h-7 w-7 p-0`,title:e(`calendar.previous`),"aria-label":e(`calendar.previous`),children:(0,z.jsx)(d,{className:`h-4 w-4 rtl:rotate-180`})}),(0,z.jsx)(b,{size:`sm`,variant:`ghost`,onClick:()=>p(new Date),className:`h-7 px-2 text-[12px]`,children:e(`calendar.today`)}),(0,z.jsx)(b,{size:`sm`,variant:`ghost`,onClick:()=>oe(1),className:`h-7 w-7 p-0`,title:e(`calendar.next`),"aria-label":e(`calendar.next`),children:(0,z.jsx)(f,{className:`h-4 w-4 rtl:rotate-180`})})]}),(0,z.jsxs)(b,{size:`sm`,onClick:()=>$(l),"data-testid":`calendar-new-event`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,z.jsx)(g,{className:`h-3.5 w-3.5`}),e(`calendar.newEvent`)]})]}),children:(0,z.jsx)(`span`,{className:`text-sm text-ink-muted`,"data-testid":`calendar-range-label`,children:ue})}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-b border-black/6 px-4 py-2 dark:border-white/[0.07]`,children:[V.map(t=>(0,z.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-black/8 px-2.5 py-1 text-xs text-gray-700 dark:border-white/10 dark:text-dark-800`,"data-testid":`calendar-chip`,children:[(0,z.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:t.color??`#8b8b8b`}}),(0,z.jsx)(`span`,{className:`truncate`,title:t.name,children:t.name}),t.shared?(0,z.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:e(`calendar.sharedBadge`)}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>J(t),className:`-my-1.5 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-ink-muted hover:text-ink`,title:e(`calendar.shareCalendar`),"aria-label":e(`calendar.shareCalendarNamed`,{name:t.name}),"data-testid":`calendar-share`,children:(0,z.jsx)(s,{className:`h-3 w-3`})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void fe(t),className:`-my-1.5 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-ink-muted hover:text-error-700`,title:e(`common.delete`),"aria-label":e(`calendar.deleteCalendarNamed`,{name:t.name}),children:(0,z.jsx)(m,{className:`h-3 w-3`})})]})]},t.id)),(0,z.jsxs)(`form`,{className:`flex min-w-0 max-w-full items-center gap-1`,onSubmit:e=>{e.preventDefault(),de()},children:[(0,z.jsx)(`input`,{type:`text`,value:U,disabled:G,onChange:e=>W(e.target.value),placeholder:e(`calendar.newCalendarPlaceholder`),"aria-label":e(`calendar.newCalendarPlaceholder`),className:`min-w-0 w-36 rounded-full border border-dashed border-black/12 bg-transparent px-2.5 py-1 text-base text-gray-700 placeholder:text-gray-400 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas dark:border-white/16 dark:text-dark-800 sm:text-xs`,"data-testid":`calendar-new-calendar`}),(0,z.jsx)(b,{type:`submit`,size:`sm`,variant:`ghost`,disabled:!U.trim(),loading:G,className:`h-7 shrink-0 px-2 text-xs`,"data-testid":`calendar-create-calendar`,children:e(`common.save`)})]}),(0,z.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,z.jsx)(`input`,{ref:Y,type:`file`,accept:`.ics,text/calendar`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&me(t),e.target.value=``}}),(0,z.jsxs)(b,{size:`sm`,variant:`ghost`,onClick:()=>Y.current?.click(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-import`,children:[(0,z.jsx)(h,{className:`h-3.5 w-3.5`}),e(`calendar.importIcs`)]}),(0,z.jsxs)(b,{size:`sm`,variant:`ghost`,onClick:()=>void pe(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-export`,children:[(0,z.jsx)(o,{className:`h-3.5 w-3.5`}),e(`calendar.exportIcs`)]})]})]}),r===`month`?(0,z.jsx)(ee,{year:l.getFullYear(),monthIndex:l.getMonth(),events:ae,onDayClick:e=>$(e),onEventClick:se,onShowDay:e=>{p(e),c(`day`)}}):(0,z.jsx)(te,{anchor:l,events:ae,dayCount:r===`day`?1:7,onDayClick:(e,t)=>$(e,t),onEventClick:se}),q&&(0,z.jsx)(L,{resourceType:`calendar`,resourceId:q.id,resourceLabel:q.name,onClose:()=>J(null)}),(0,z.jsx)(ne,{open:E,event:k,initialStartAt:M,calendars:V.filter(e=>!e.shared||e.shared.permission===`write`),saving:I,onClose:()=>D(!1),onSave:e=>void ce(e),onDelete:()=>void le()})]})};export{Z as default};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{d as i}from"./router-vendor-DLHZHk4K.js";import{t as a}from"./useTranslation-CKqEdZ8j.js";import{An as o,B as s,Bn as c,Kn as l,Or as u,Qn as d,Zn as f,g as p,n as m,p as h,tt as g,v as _}from"./ui-vendor-C7v9zeJX.js";import{i as v}from"./ui-Byzdw4-Y.js";import{t as y}from"./confirmStore-CKkUtP9c.js";import{t as b}from"./Button-D6d7HYoa.js";import{t as x}from"./utils-BXRzbHJC.js";import{a as S,c as C,d as w,i as T,l as E,n as D,o as O,r as k,s as A,t as j,u as M}from"./calendarDates-Co3o_05Y.js";import{t as N}from"./useDialogFocus-DpTun-ZV.js";import{O as P,T as F}from"./api-BPTwf2O4.js";import{t as I}from"./logger-DAQsBb8I.js";import{t as L}from"./ShareDialog-DgVAGGOp.js";var R=e(t(),1),z=r(),B={event:`bg-primary-500/15 text-primary-700 hover:bg-primary-500/25 dark:text-primary-300`,automation:`bg-warning-500/15 text-ink hover:bg-warning-500/25`,runSucceeded:`bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300`,runFailed:`bg-red-500/15 text-red-700 hover:bg-red-500/25 dark:text-red-300`};function V({event:e,label:t,onClick:n}){let{t:r}=a(),i=e.variant===`automation`?{Icon:c,label:r(`calendar.chipStatus.automation`)}:e.variant===`runSucceeded`?{Icon:l,label:r(`calendar.chipStatus.runSucceeded`)}:e.variant===`runFailed`?{Icon:p,label:r(`calendar.chipStatus.runFailed`)}:null;return(0,z.jsxs)(`button`,{type:`button`,"data-testid":`calendar-event-chip`,"data-variant":e.variant??`event`,title:e.title,onClick:e=>{e.stopPropagation(),n()},className:x(`flex w-full items-center gap-1 rounded-md px-1.5 py-0.5 text-start text-[11px] leading-4 transition-colors`,B[e.variant??`event`],e.baseEventId&&`opacity-75`),children:[i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i.Icon,{className:`h-3 w-3 shrink-0`,"aria-hidden":`true`}),(0,z.jsx)(`span`,{className:`sr-only`,children:i.label})]}),(0,z.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]})}var H=3;function ee({year:e,monthIndex:t,events:n,onDayClick:r,onEventClick:i,onShowDay:o}){let{t:s,i18n:c}=a(),l=(0,R.useMemo)(()=>k(e,t),[e,t]),u=new Date,d=(0,R.useMemo)(()=>{let e=new Map;for(let t of n){let n=new Date(t.startAt),r=`${n.getFullYear()}-${n.getMonth()}-${n.getDate()}`,i=e.get(r);i?i.push(t):e.set(r,[t])}return e},[n]),f=(0,R.useMemo)(()=>w(c.language),[c.language]),p=(0,R.useMemo)(()=>new Intl.DateTimeFormat(c.language,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}),[c.language]);return(0,z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`calendar-month-grid`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-7 border-b border-black/6 dark:border-white/[0.07]`,children:f.map(e=>(0,z.jsx)(`div`,{className:`px-2 py-1.5 text-center text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e},e))}),(0,z.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-7 grid-rows-6`,children:l.map(e=>{let n=e.getMonth()===t,a=T(e,u),l=`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`,f=d.get(l)??[],m=f.length-H;return(0,z.jsxs)(`div`,{role:`gridcell`,"data-testid":`calendar-day-cell`,onClick:()=>r(e),className:x(`flex min-h-0 cursor-pointer flex-col gap-0.5 border-b border-e border-black/4 p-1 transition-colors hover:bg-black/2 dark:border-white/4 dark:hover:bg-white/3`,!n&&`opacity-40`),children:[(0,z.jsx)(`button`,{type:`button`,"aria-label":s(`calendar.newEventOn`,{date:p.format(e)}),"aria-current":a?`date`:void 0,className:x(`flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-[12px]`,a?`bg-ink font-semibold text-ink-inverse`:`text-ink-muted`),children:e.getDate()}),(0,z.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0.5 overflow-hidden`,children:[f.slice(0,H).map(e=>(0,z.jsx)(V,{event:e,label:e.allDay?e.title:`${A(e.startAt,c.language)} ${e.title}`,onClick:()=>i(e)},e.id)),m>0&&(0,z.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o?.(e)},title:s(`calendar.showDay`,{date:p.format(e)}),className:`rounded-sm px-1 text-start text-[10px] text-ink-muted hover:text-ink`,children:s(`calendar.more`,{n:m})})]})]},l)})})]})}var U=48;function te({anchor:e,events:t,dayCount:n=7,onDayClick:r,onEventClick:i}){let{t:o,i18n:s}=a(),c=(0,R.useMemo)(()=>n===1?[new Date(e.getFullYear(),e.getMonth(),e.getDate())]:M(e),[e,n]),l=new Date,u=(0,R.useMemo)(()=>new Intl.DateTimeFormat(s.language,{hour:`numeric`}),[s.language]),d=(0,R.useMemo)(()=>new Intl.DateTimeFormat(s.language,{weekday:`long`,month:`long`,day:`numeric`,hour:`numeric`}),[s.language]),f=(0,R.useRef)(null),[p,m]=(0,R.useState)(`0-9`),h=(e,t,n)=>{let r=s.dir()===`rtl`?-1:1,i={ArrowRight:[r,0],ArrowLeft:[-r,0],ArrowDown:[0,1],ArrowUp:[0,-1]}[e.key];if(!i)return;let a=Math.min(c.length-1,Math.max(0,t+i[0])),o=Math.min(23,Math.max(0,n+i[1]));e.preventDefault();let l=`${a}-${o}`;m(l),f.current?.querySelector(`[data-slot="${l}"]`)?.focus()},g=(0,R.useMemo)(()=>new Intl.DateTimeFormat(s.language,{weekday:`short`,day:`numeric`}),[s.language]),_=e=>t.filter(t=>t.allDay&&T(new Date(t.startAt),e)),v=e=>t.filter(t=>!t.allDay&&T(new Date(t.startAt),e));return(0,z.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto scrollbar-thin`,"data-testid":`calendar-week-grid`,children:(0,z.jsxs)(`div`,{ref:f,className:`grid grid-cols-[3.5rem_repeat(7,1fr)]`,children:[(0,z.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-black/6 bg-surface dark:border-white/[0.07]`}),c.map(e=>(0,z.jsxs)(`div`,{className:`sticky top-0 z-10 border-b border-e border-black/6 bg-surface px-1 py-1.5 dark:border-white/[0.07]`,children:[(0,z.jsx)(`span`,{className:x(`block truncate text-center text-[11px] font-medium`,T(e,l)?`text-primary-600 dark:text-primary-400`:`text-gray-500 dark:text-dark-500`),children:g.format(e)}),(0,z.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:_(e).map(e=>(0,z.jsx)(V,{event:e,label:e.title,onClick:()=>i(e)},e.id))})]},e.toISOString())),Array.from({length:24},(e,t)=>(0,z.jsxs)(R.Fragment,{children:[(0,z.jsx)(`div`,{className:`relative border-b border-black/4 pe-1.5 text-end text-[10px] text-gray-400 dark:border-white/4 dark:text-dark-500`,children:(0,z.jsx)(`span`,{className:`relative -top-1.5`,children:t>0?u.format(new Date(2024,0,1,t)):``})}),c.map((e,n)=>{let a=`${n}-${t}`,c=v(e).filter(e=>new Date(e.startAt).getHours()===t);return(0,z.jsxs)(`div`,{onClick:()=>r(e,t),style:{height:U},className:`relative cursor-pointer space-y-0.5 overflow-hidden border-b border-e border-black/4 p-0.5 transition-colors hover:bg-black/2 dark:border-white/4 dark:hover:bg-white/3`,children:[(0,z.jsx)(`button`,{type:`button`,"data-slot":a,tabIndex:p===a?0:-1,"aria-label":o(`calendar.newEventOn`,{date:d.format(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t))}),onFocus:()=>m(a),onKeyDown:e=>h(e,n,t),className:`absolute inset-0 focus-visible:-outline-offset-2`}),c.map(e=>(0,z.jsx)(`div`,{className:`relative`,children:(0,z.jsx)(V,{event:e,label:`${A(e.startAt,s.language)} ${e.title}`,onClick:()=>i(e)})},e.id))]},`${e.toISOString()}-${t}`)})]},t))]})})}var W=n(),G=e=>!e||e.kind===`once`||e.kind===`hourly`||e.kind===`event`?`none`:e.kind,K=(e,t)=>{let n=new Date(t),r=n.getHours(),i=n.getMinutes();switch(e){case`daily`:return{kind:`daily`,hour:r,minute:i};case`weekly`:return{kind:`weekly`,dayOfWeek:n.getDay(),hour:r,minute:i};case`monthly`:return{kind:`monthly`,dayOfMonth:n.getDate(),hour:r,minute:i};case`yearly`:return{kind:`yearly`,month:n.getMonth()+1,dayOfMonth:n.getDate(),hour:r,minute:i};default:return null}},q=`w-full rounded-lg border border-black/8 bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-100 dark:text-dark-900`,J=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`;function ne({open:e,event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s}){return e?(0,z.jsx)(Y,{event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s},`${t?.id??`new`}:${n}`):null}function Y({event:e,initialStartAt:t,calendars:n,saving:r,onClose:i,onSave:o,onDelete:s}){let{t:c}=a(),l=(0,R.useRef)(null);N(l,{onClose:i});let u=e?.startAt??t,[d,f]=(0,R.useState)(e?.title??``),[p,h]=(0,R.useState)(e?.notes??``),[g,v]=(0,R.useState)(C(u)),[b,x]=(0,R.useState)(e?E(u):`09:00`),[S,w]=(0,R.useState)(e?.endAt===void 0?``:E(e.endAt)),[T,O]=(0,R.useState)(e?.allDay??!1),[k,A]=(0,R.useState)(G(e?.recurrence)),[j,M]=(0,R.useState)(e?.calendarId??``),[P,F]=(0,R.useState)(e?.reminderMinutes===void 0?``:String(e.reminderMinutes)),I=()=>{if(!d.trim()||!g)return;let e=D(g,T?``:b),t=!T&&S?D(g,S):null;o({title:d.trim(),notes:p.trim()?p.trim():void 0,startAt:e,endAt:t!==null&&t>e?t:null,allDay:T,recurrence:K(k,e),calendarId:j||null,reminderMinutes:P?Number(P):null})},L=[{value:``,label:c(`calendar.reminderNone`)},{value:`5`,label:c(`calendar.reminderMinutes`,{minutes:5})},{value:`15`,label:c(`calendar.reminderMinutes`,{minutes:15})},{value:`30`,label:c(`calendar.reminderMinutes`,{minutes:30})},{value:`60`,label:c(`calendar.reminderHour`)},{value:`1440`,label:c(`calendar.reminderDay`)}],B=[{value:`none`,label:c(`calendar.repeatNone`)},{value:`daily`,label:c(`calendar.repeatDaily`)},{value:`weekly`,label:c(`calendar.repeatWeekly`)},{value:`monthly`,label:c(`calendar.repeatMonthly`)},{value:`yearly`,label:c(`calendar.repeatYearly`)}];return(0,W.createPortal)((0,z.jsx)(`div`,{className:`fixed inset-0 z-2147483647 flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:i,children:(0,z.jsxs)(`div`,{ref:l,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`calendar-event-modal-title`,"data-testid":`calendar-event-modal`,className:`w-full max-w-md rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/8 dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,z.jsx)(`h3`,{id:`calendar-event-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:c(e?`calendar.editEvent`:`calendar.newEvent`)}),(0,z.jsx)(`button`,{type:`button`,onClick:i,"aria-label":c(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,z.jsx)(m,{size:20,className:`text-gray-500`})})]}),(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-title`,className:J,children:c(`calendar.eventTitle`)}),(0,z.jsx)(`input`,{id:`calendar-event-title`,"data-testid":`calendar-event-title`,type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:c(`calendar.titlePlaceholder`),className:q,maxLength:200,autoFocus:!0})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-date`,className:J,children:c(`calendar.date`)}),(0,z.jsx)(`input`,{id:`calendar-event-date`,type:`date`,value:g,onChange:e=>v(e.target.value),className:q})]}),(0,z.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px] text-gray-700 dark:text-dark-700`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:T,onChange:e=>O(e.target.checked),className:`h-4 w-4 rounded-sm accent-primary-500`}),c(`calendar.allDay`)]})})]}),!T&&(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-start`,className:J,children:c(`calendar.start`)}),(0,z.jsx)(`input`,{id:`calendar-event-start`,type:`time`,value:b,onChange:e=>x(e.target.value),className:q})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-end`,className:J,children:c(`calendar.end`)}),(0,z.jsx)(`input`,{id:`calendar-event-end`,type:`time`,value:S,onChange:e=>w(e.target.value),className:q})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-repeat`,className:J,children:c(`calendar.repeat`)}),(0,z.jsx)(`select`,{id:`calendar-event-repeat`,value:k,onChange:e=>A(e.target.value),className:q,children:B.map(e=>(0,z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-notes`,className:J,children:c(`calendar.notes`)}),(0,z.jsx)(`textarea`,{id:`calendar-event-notes`,value:p,onChange:e=>h(e.target.value),rows:3,className:q,maxLength:1e4})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-calendar`,className:J,children:c(`calendar.calendarLabel`)}),(0,z.jsxs)(`select`,{id:`calendar-event-calendar`,value:j,onChange:e=>M(e.target.value),className:q,"data-testid":`calendar-event-calendar`,children:[(0,z.jsx)(`option`,{value:``,children:c(`calendar.personalCalendar`)}),n.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`calendar-event-reminder`,className:J,children:c(`calendar.reminderLabel`)}),(0,z.jsx)(`select`,{id:`calendar-event-reminder`,value:P,onChange:e=>F(e.target.value),className:q,"data-testid":`calendar-event-reminder`,children:L.map(e=>(0,z.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[e&&s?(0,z.jsxs)(`button`,{type:`button`,onClick:async()=>{await y({title:c(`calendar.deleteEventConfirmTitle`,{title:e.title}),description:e.recurrence?c(`calendar.deleteRecurringEventConfirmDescription`):c(`calendar.deleteEventConfirmDescription`),destructive:!0})&&s()},"data-testid":`calendar-event-delete`,className:`flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:[(0,z.jsx)(_,{className:`h-4 w-4`}),c(`common.delete`)]}):(0,z.jsx)(`span`,{}),(0,z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:i,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:c(`common.cancel`)}),(0,z.jsx)(`button`,{type:`button`,onClick:I,disabled:r||!d.trim(),"data-testid":`calendar-event-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:c(r?`common.saving`:`common.save`)})]})]})]})]})}),document.body)}var X=I(`pages:calendar`),Z=()=>{let{t:e,i18n:t}=a(),n=i(),[r,c]=(0,R.useState)(`month`),[l,p]=(0,R.useState)(()=>new Date),[_,C]=(0,R.useState)([]),[w,T]=(0,R.useState)([]),[E,D]=(0,R.useState)(!1),[k,A]=(0,R.useState)(null),[M,N]=(0,R.useState)(()=>Date.now()),[I,B]=(0,R.useState)(!1),[V,H]=(0,R.useState)([]),[U,W]=(0,R.useState)(``),[G,K]=(0,R.useState)(!1),[q,J]=(0,R.useState)(null),Y=R.useRef(null),Z=(0,R.useMemo)(()=>{if(r===`month`){let e=new Date(l.getFullYear(),l.getMonth(),1),t=O(e);return{from:t.getTime(),to:j(t,42).getTime()}}if(r===`day`){let e=new Date(l.getFullYear(),l.getMonth(),l.getDate());return{from:e.getTime(),to:j(e,1).getTime()}}let e=O(l);return{from:e.getTime(),to:j(e,7).getTime()}},[l,r]),[re,ie]=(0,R.useState)(0),Q=(0,R.useCallback)(()=>ie(e=>e+1),[]);(0,R.useEffect)(()=>{P.getCalendars().then(t=>{t.success&&t.data?H(t.data):u.error(e(`calendar.loadFailed`))}).catch(t=>{X.error(`Failed to load calendars:`,t),u.error(e(`calendar.loadFailed`))})},[re,e]),(0,R.useEffect)(()=>{let t=!1;return P.getEvents(Z.from,Z.to).then(e=>{t||e.success&&e.data&&C(e.data)}).catch(n=>{t||(X.error(`Failed to load calendar events:`,n),u.error(e(`calendar.loadFailed`)))}),Promise.all([F.getOccurrences(Z.from,Z.to),F.getRuns({from:Z.from,to:Z.to}),F.getAutomations()]).then(([n,r,i])=>{if(t)return;let a=Date.now(),o=t=>i.data?.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`),s=[];for(let e of n.data??[])e.at<=a||s.push({id:`automation:${e.automationId}:${e.at}`,title:e.name,startAt:e.at,allDay:!1,createdAt:e.at,updatedAt:e.at,variant:`automation`});for(let e of r.data??[])(e.status===`succeeded`||e.status===`failed`)&&s.push({id:`run:${e.id}`,title:o(e.automationId),startAt:e.scheduledFor,allDay:!1,createdAt:e.createdAt,updatedAt:e.createdAt,variant:e.status===`succeeded`?`runSucceeded`:`runFailed`,...e.sessionId?{sessionId:e.sessionId}:{}});T(s)}).catch(e=>{t||X.error(`Failed to project automations onto the calendar:`,e)}),()=>{t=!0}},[Z.from,Z.to,re,e]);let ae=(0,R.useMemo)(()=>[..._,...w].sort((e,t)=>e.startAt-t.startAt),[_,w]),oe=e=>{p(t=>r===`month`?new Date(t.getFullYear(),t.getMonth()+e,1):j(t,e*(r===`day`?1:7)))},$=(e,t=9)=>{A(null),N(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t,0).getTime()),D(!0)},se=t=>{if(t.variant===`runSucceeded`||t.variant===`runFailed`)t.sessionId?n(`/c/${t.sessionId}`):n(`/automations`);else if(t.variant===`automation`)n(`/automations`);else if(t.shared&&t.shared.permission!==`write`)u(e(`calendar.sharedReadOnly`));else{if(t.baseEventId){let e=_.find(e=>e.id===t.baseEventId);A(e??t)}else A(t);D(!0)}},ce=async t=>{B(!0);try{let n=k?await P.updateEvent(k.id,t):await P.createEvent(t);n.success?(D(!1),Q()):u.error(n.error||e(`calendar.saveFailed`))}catch(t){X.error(`Failed to save calendar event:`,t),u.error(e(`calendar.saveFailed`))}finally{B(!1)}},le=async()=>{if(k){B(!0);try{let t=await P.deleteEvent(k.id);t.success?(D(!1),Q()):u.error(t.error||e(`calendar.deleteFailed`))}catch(t){X.error(`Failed to delete calendar event:`,t),u.error(e(`calendar.deleteFailed`))}finally{B(!1)}}},ue=r===`month`?S(l.getFullYear(),l.getMonth(),t.language):new Intl.DateTimeFormat(t.language,{month:`long`,day:`numeric`,year:`numeric`}).format(r===`day`?l:O(l)),de=async()=>{let t=U.trim();if(!t||G)return;K(!0);let n=await P.createCalendar({name:t}).catch(()=>void 0);K(!1),n?.success?(W(``),Q()):u.error(e(`calendar.calendarSaveFailed`))},fe=async t=>{if(await y({title:e(`calendar.deleteCalendarConfirmTitle`,{name:t.name}),description:e(`calendar.deleteCalendarConfirmDescription`),destructive:!0}))try{let e=await P.deleteCalendar(t.id);if(!e.success)throw Error(e.error);Q()}catch(t){X.error(`Failed to delete calendar:`,t),u.error(e(`calendar.calendarDeleteFailed`))}},pe=async t=>{try{let e=await P.exportIcs(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`calendar.ics`,r.click(),URL.revokeObjectURL(n)}catch(t){X.error(`Failed to export the calendar:`,t),u.error(e(`calendar.exportFailed`))}},me=async t=>{try{let n=await t.text(),r=await P.importIcs(n);r.success&&r.data?(u.success(e(`calendar.importResult`,{total:r.data.imported})),Q()):u.error(r.error||e(`calendar.importFailed`))}catch(t){X.error(`Failed to import the calendar:`,t),u.error(e(`calendar.importFailed`))}};return(0,z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`calendar-page`,children:[(0,z.jsx)(v,{title:e(`calendar.title`),actions:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/4 p-0.5 dark:bg-white/6`,children:[`month`,`week`,`day`].map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>c(t),"aria-pressed":r===t,"data-testid":`calendar-view-${t}`,className:x(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,r===t?`bg-white text-gray-900 shadow-xs dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`calendar.${t}`)},t))}),(0,z.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,z.jsx)(b,{size:`sm`,variant:`ghost`,onClick:()=>oe(-1),className:`h-7 w-7 p-0`,title:e(`calendar.previous`),"aria-label":e(`calendar.previous`),children:(0,z.jsx)(d,{className:`h-4 w-4 rtl:rotate-180`})}),(0,z.jsx)(b,{size:`sm`,variant:`ghost`,onClick:()=>p(new Date),className:`h-7 px-2 text-[12px]`,children:e(`calendar.today`)}),(0,z.jsx)(b,{size:`sm`,variant:`ghost`,onClick:()=>oe(1),className:`h-7 w-7 p-0`,title:e(`calendar.next`),"aria-label":e(`calendar.next`),children:(0,z.jsx)(f,{className:`h-4 w-4 rtl:rotate-180`})})]}),(0,z.jsxs)(b,{size:`sm`,onClick:()=>$(l),"data-testid":`calendar-new-event`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,z.jsx)(g,{className:`h-3.5 w-3.5`}),e(`calendar.newEvent`)]})]}),children:(0,z.jsx)(`span`,{className:`text-sm text-ink-muted`,"data-testid":`calendar-range-label`,children:ue})}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-b border-black/6 px-4 py-2 dark:border-white/[0.07]`,children:[V.map(t=>(0,z.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-black/8 px-2.5 py-1 text-xs text-gray-700 dark:border-white/10 dark:text-dark-800`,"data-testid":`calendar-chip`,children:[(0,z.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:t.color??`#8b8b8b`}}),(0,z.jsx)(`span`,{className:`truncate`,title:t.name,children:t.name}),t.shared?(0,z.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:e(`calendar.sharedBadge`)}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>J(t),className:`-my-1.5 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-ink-muted hover:text-ink`,title:e(`calendar.shareCalendar`),"aria-label":e(`calendar.shareCalendarNamed`,{name:t.name}),"data-testid":`calendar-share`,children:(0,z.jsx)(s,{className:`h-3 w-3`})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void fe(t),className:`-my-1.5 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-ink-muted hover:text-error-700`,title:e(`common.delete`),"aria-label":e(`calendar.deleteCalendarNamed`,{name:t.name}),children:(0,z.jsx)(m,{className:`h-3 w-3`})})]})]},t.id)),(0,z.jsxs)(`form`,{className:`flex min-w-0 max-w-full items-center gap-1`,onSubmit:e=>{e.preventDefault(),de()},children:[(0,z.jsx)(`input`,{type:`text`,value:U,disabled:G,onChange:e=>W(e.target.value),placeholder:e(`calendar.newCalendarPlaceholder`),"aria-label":e(`calendar.newCalendarPlaceholder`),className:`min-w-0 w-36 rounded-full border border-dashed border-black/12 bg-transparent px-2.5 py-1 text-base text-gray-700 placeholder:text-gray-400 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas dark:border-white/16 dark:text-dark-800 sm:text-xs`,"data-testid":`calendar-new-calendar`}),(0,z.jsx)(b,{type:`submit`,size:`sm`,variant:`ghost`,disabled:!U.trim(),loading:G,className:`h-7 shrink-0 px-2 text-xs`,"data-testid":`calendar-create-calendar`,children:e(`common.save`)})]}),(0,z.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,z.jsx)(`input`,{ref:Y,type:`file`,accept:`.ics,text/calendar`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&me(t),e.target.value=``}}),(0,z.jsxs)(b,{size:`sm`,variant:`ghost`,onClick:()=>Y.current?.click(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-import`,children:[(0,z.jsx)(h,{className:`h-3.5 w-3.5`}),e(`calendar.importIcs`)]}),(0,z.jsxs)(b,{size:`sm`,variant:`ghost`,onClick:()=>void pe(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-export`,children:[(0,z.jsx)(o,{className:`h-3.5 w-3.5`}),e(`calendar.exportIcs`)]})]})]}),r===`month`?(0,z.jsx)(ee,{year:l.getFullYear(),monthIndex:l.getMonth(),events:ae,onDayClick:e=>$(e),onEventClick:se,onShowDay:e=>{p(e),c(`day`)}}):(0,z.jsx)(te,{anchor:l,events:ae,dayCount:r===`day`?1:7,onDayClick:(e,t)=>$(e,t),onEventClick:se}),q&&(0,z.jsx)(L,{resourceType:`calendar`,resourceId:q.id,resourceLabel:q.name,onClose:()=>J(null)}),(0,z.jsx)(ne,{open:E,event:k,initialStartAt:M,calendars:V.filter(e=>!e.shared||e.shared.permission===`write`),saving:I,onClose:()=>D(!1),onSave:e=>void ce(e),onDelete:()=>void le()})]})};export{Z as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r}from"./router-vendor-DLHZHk4K.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{$n as a,At as o,Fn as s,H as c,It as l,Or as u,Ot as d,Qt as f,Rt as ee,W as p,Zn as m,at as h,dr as te,er as ne,n as g,r as _,s as re,st as v,tt as y,ut as ie,v as ae,wn as b,yr as oe}from"./ui-vendor-DsURZnZt.js";import{_ as x,g as S,i as se,n as ce,r as C,t as w,v as T}from"./ui-DxaHE9GD.js";import{t as E}from"./confirmStore-CKkUtP9c.js";import{i as D,t as O}from"./utils-BXRzbHJC.js";import{t as k}from"./Button-D6d7HYoa.js";import{D as A}from"./api-Dasm8tVY.js";import{t as le}from"./teamEventStream-O3qGbUZz.js";import{t as ue}from"./authStore-ac5-hjOH.js";import{t as de}from"./chatStore-GhucyjJu.js";import{t as fe}from"./logger-DAQsBb8I.js";var j=e(t(),1),M=n(),pe=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],N=180,me=({calls:e})=>{let{t}=i(),[n,r]=(0,j.useState)(!1),o=e.some(e=>e.status===`denied`);return(0,M.jsxs)(`div`,{className:`mt-1`,"data-testid":`channel-tool-calls`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,className:`flex items-center gap-1 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,"data-testid":`channel-tool-calls-toggle`,children:[n?(0,M.jsx)(a,{className:`h-3 w-3`}):(0,M.jsx)(m,{className:`h-3 w-3`}),(0,M.jsx)(_,{className:`h-3 w-3`}),t(`channels.toolCalls.summary`,{total:e.length})]}),n&&(0,M.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[e.map(e=>(0,M.jsxs)(`div`,{className:`rounded-lg border border-black/6 px-2 py-1 dark:border-white/8`,"data-testid":`channel-tool-call`,children:[(0,M.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,M.jsx)(`span`,{dir:`ltr`,className:`min-w-0 truncate text-[11px] font-medium text-gray-700 dark:text-dark-800`,children:e.name}),(0,M.jsx)(`span`,{className:O(`shrink-0 text-[10px]`,e.status===`succeeded`?`text-emerald-600 dark:text-emerald-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:e.status===`failed`?`text-red-500`:`text-gray-400 dark:text-dark-500`),children:t(`tools.callStatus.${e.status}`)})]}),e.resultPreview&&(0,M.jsx)(`p`,{dir:`ltr`,className:`mt-0.5 whitespace-pre-wrap wrap-break-word font-mono text-[10px] leading-snug text-gray-500 dark:text-dark-600`,children:e.resultPreview.slice(0,N)})]},e.id)),o&&(0,M.jsx)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:t(`channels.toolCalls.deniedHint`)})]})]})},he=({message:e,currentUserId:t,canModerate:n,actions:r,compact:a=!1})=>{let{t:o,i18n:s}=i(),[c,l]=(0,j.useState)(!1),[u,f]=(0,j.useState)(e.content),[p,m]=(0,j.useState)(!1),_=e.authorKind===`model`,re=!_&&e.author?.userId===t&&!e.deleted,y=_?e.model??o(`channels.modelAuthor`):e.author?.username??o(`channels.unknownAuthor`);return(0,M.jsxs)(`div`,{className:O(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/2.5 dark:hover:bg-white/3`,a&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,M.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[_&&(0,M.jsx)(te,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,M.jsx)(`span`,{className:O(`shrink-0 text-[13px] font-semibold`,_?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:y}),(0,M.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:D(e.createdAt,s.language)}),e.editedAt&&!e.deleted&&(0,M.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:o(`channels.edited`)}),e.pinnedAt&&(0,M.jsx)(h,{role:`img`,"aria-label":o(`channels.pins`),className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,M.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:o(`channels.deletedMessage`)}):c?(0,M.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,M.jsx)(`textarea`,{value:u,onChange:e=>f(e.target.value),rows:2,"aria-label":o(`channels.edit`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2 py-1 text-[13px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,u),l(!1)},"aria-label":o(`channels.confirmEdit`),title:o(`channels.confirmEdit`),className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,M.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>l(!1),"aria-label":o(`channels.cancelEdit`),title:o(`channels.cancelEdit`),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}):(0,M.jsxs)(M.Fragment,{children:[e.pending?(0,M.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,M.jsx)(ee,{className:`h-3.5 w-3.5 animate-spin`}),o(`channels.modelThinking`)]}):e.error?(0,M.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,M.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),_&&(e.toolCalls?.length??0)>0&&(0,M.jsx)(me,{calls:e.toolCalls}),(e.attachments?.length??0)>0&&(0,M.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/6 px-2 py-1 text-[12px] text-gray-600 hover:bg-black/3 dark:border-white/8 dark:text-dark-700 dark:hover:bg-white/4`,"data-testid":`channel-attachment`,children:[(0,M.jsx)(ie,{className:`h-3 w-3`}),(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,M.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,M.jsxs)(`button`,{type:`button`,"aria-pressed":t.mine,onClick:()=>void r.onReact(e,t.emoji,t.mine),className:O(`rounded-full border px-1.5 py-0.5 text-[11px]`,t.mine?`border-primary-400/50 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-black/8 text-gray-600 hover:bg-black/3 dark:border-white/10 dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!a&&(e.replyCount??0)>0&&r.onReply&&(0,M.jsxs)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`mt-1 flex items-center gap-1 text-[11px] font-medium text-primary-600 hover:underline dark:text-primary-400`,"data-testid":`channel-reply-count`,children:[(0,M.jsx)(d,{className:`h-3 w-3`}),o(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!c&&(0,M.jsxs)(`div`,{className:`absolute -top-2.5 inset-e-2 hidden items-center gap-0.5 rounded-lg border border-black/8 bg-white px-1 py-0.5 shadow-xs group-focus-within:flex group-hover:flex [@media(hover:none)]:flex dark:border-white/10 dark:bg-dark-50`,children:[(0,M.jsxs)(`div`,{className:`relative`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.react`),"aria-label":o(`channels.react`),"aria-haspopup":`true`,"aria-expanded":p,"data-testid":`channel-react`,children:(0,M.jsx)(b,{className:`h-3.5 w-3.5`})}),p&&(0,M.jsx)(`div`,{className:`absolute inset-e-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/8 bg-white p-1 shadow-md dark:border-white/10 dark:bg-dark-50`,children:pe.map(t=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),m(!1)},"aria-label":o(`channels.reactWith`,{emoji:t}),className:`rounded-sm p-0.5 text-sm hover:bg-black/5 dark:hover:bg-white/8`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.reply`),"aria-label":o(`channels.reply`),"data-testid":`channel-reply`,children:(0,M.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded-sm p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"aria-label":e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"data-testid":`channel-pin`,children:(0,M.jsx)(h,{className:`h-3.5 w-3.5`})}),re&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>{f(e.content),l(!0)},className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.edit`),"aria-label":o(`channels.edit`),"data-testid":`channel-edit`,children:(0,M.jsx)(v,{className:`h-3.5 w-3.5`})}),(re||n)&&(0,M.jsx)(`button`,{type:`button`,onClick:async()=>{await E({title:o(`channels.deleteMessageConfirmTitle`),description:o(`channels.deleteMessageConfirmDescription`),destructive:!0})&&await r.onDelete(e)},className:`rounded-sm p-1 text-gray-400 hover:text-red-500`,title:o(`channels.deleteMessage`),"aria-label":o(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,M.jsx)(ae,{className:`h-3.5 w-3.5`})})]})]})},P=fe(`pages:channels`),ge=e=>e.type===`dm`?(0,M.jsx)(o,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,M.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}):(0,M.jsx)(f,{className:`h-3.5 w-3.5 shrink-0`}),F=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,_e=()=>{let{t:e}=i(),t=ue(e=>e.user),n=de(e=>e.models),[a,l]=(0,j.useState)([]),[m,ne]=(0,j.useState)(null),[_,v]=(0,j.useState)(!1),[ae,b]=(0,j.useState)(!1),[x,S]=(0,j.useState)(!0),[w,T]=(0,j.useState)(null),[D,fe]=(0,j.useState)(null),[pe,N]=(0,j.useState)([]),[me,_e]=(0,j.useState)([]),[I,L]=(0,j.useState)(null),[R,z]=(0,j.useState)(null),[Se,Ce]=(0,j.useState)([]),[B,we]=(0,j.useState)(``),[V,Te]=(0,j.useState)(``),[H,Ee]=(0,j.useState)(!1),[U,De]=(0,j.useState)(null),[Oe,ke]=(0,j.useState)(!1),[Ae,je]=(0,j.useState)(!1),[W,Me]=(0,j.useState)(``),[Ne,G]=(0,j.useState)(!1),Pe=(0,j.useRef)(null),Fe=(0,j.useRef)(null),[Ie,Le]=r(),K=(0,j.useMemo)(()=>a.find(e=>e.id===w)??null,[a,w]),[Re,ze]=(0,j.useState)(null);w!==Re&&(ze(w),fe(null),z(null),L(null));let q=K?.role===`owner`,J=(0,j.useCallback)(()=>{A.listMine().then(e=>{e.success&&e.data&&l(e.data)}).catch(e=>P.error(`Failed to load channels:`,e)).finally(()=>S(!1))},[]);(0,j.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=Ie.get(`channel`);Y&&w!==Y&&T(Y),(0,j.useEffect)(()=>{Y&&Le({},{replace:!0})},[Y,Le]);let X=(0,j.useRef)(null);(0,j.useLayoutEffect)(()=>(X.current=w?{channelId:w,requestId:0}:null,()=>{X.current=null}),[w]);let Z=(0,j.useCallback)(t=>{let n=X.current;if(!n||n.channelId!==t)return;let r=++n.requestId;A.listMessages(t,{limit:100}).then(e=>{X.current===n&&n.requestId===r&&e.success&&e.data&&fe(e.data)}).catch(t=>{P.error(`Failed to load messages:`,t),u.error(e(`channels.loadFailed`),{id:`channels-load-failed`})})},[e]),Be=(0,j.useRef)(null);(0,j.useEffect)(()=>{Be.current=R},[R]);let Ve=(0,j.useCallback)(e=>{Z(e),A.markRead(e);let t=Be.current;t&&A.thread(t).then(e=>{e.success&&e.data&&Ce(e.data)}).catch(e=>P.error(`Failed to refresh thread:`,e))},[Z]);(0,j.useEffect)(()=>{if(!w)return;Z(w),A.markRead(w).then(J);let e=new AbortController;return le({path:`/channels/${w}/events`,signal:e.signal,onEvent:()=>Ve(w)}),()=>e.abort()},[w,Z,J,Ve]);let He=D?.length??0;(0,j.useEffect)(()=>{let e=Fe.current;e&&(e.scrollTop=e.scrollHeight)},[He,w]),(0,j.useEffect)(()=>{if(!w||!I)return;let t=t=>{P.error(`Failed to load channel panel:`,t),u.error(e(`channels.loadFailed`))};I===`members`?A.listMembers(w).then(e=>{e.success&&e.data?N(e.data):t(e.error)}).catch(t):A.listPins(w).then(e=>{e.success&&e.data?_e(e.data):t(e.error)}).catch(t)},[w,I,e]),(0,j.useEffect)(()=>{R&&A.thread(R).then(t=>{t.success&&t.data?Ce(t.data):u.error(e(`channels.loadFailed`))}).catch(t=>{P.error(`Failed to load thread:`,t),u.error(e(`channels.loadFailed`))})},[R,e]);let Ue=()=>{v(!0),b(!1),A.listPublic().then(e=>{e.success&&e.data?ne(e.data):b(!0)}).catch(e=>{P.error(`Failed to load public channels:`,e),b(!0)})},Q=async t=>{if(!w||H)return;let n=B.trim();if(n||U){Ee(!0);try{let r=await A.postMessage(w,{content:n,...t?{parentId:t}:{},...U?{attachmentIds:[U.id]}:{},...V?{mentionModel:V}:{}});if(r.success){if(we(``),De(null),Te(``),Z(w),t){let e=await A.thread(t);e.success&&e.data&&Ce(e.data)}}else u.error(r.error||e(`channels.sendFailed`))}catch(t){P.error(`Failed to send message:`,t),u.error(e(`channels.sendFailed`))}finally{Ee(!1)}}},We=async t=>{if(w)try{let n=await A.uploadAttachment(w,t);n.success&&n.data?De({id:n.data.id,filename:n.data.filename}):u.error(n.error||e(`channels.uploadFailed`))}catch(t){P.error(`Failed to upload attachment:`,t),u.error(e(`channels.uploadFailed`))}},Ge=async()=>{if(w&&W.trim()){if((await A.addMember(w,W.trim()).catch(()=>void 0))?.success){Me(``);let t=await A.listMembers(w).catch(()=>void 0);t?.success&&t.data&&N(t.data),u.success(e(`channels.memberAdded`))}else u.error(e(`channels.memberAddFailed`))}},Ke={onReply:e=>z(e.id),onEdit:async(t,n)=>{(await A.editMessage(t.id,n).catch(()=>void 0))?.success?w&&Z(w):u.error(e(`channels.editFailed`))},onDelete:async t=>{(await A.deleteMessage(t.id).catch(()=>void 0))?.success?w&&Z(w):u.error(e(`channels.deleteMessageFailed`))},onPin:async t=>{(await A.setPinned(t.id,!t.pinnedAt).catch(()=>void 0))?.success||u.error(e(`channels.pinFailed`)),w&&Z(w)},onReact:async(t,n,r)=>{(await(r?A.removeReaction(t.id,n):A.addReaction(t.id,n)).catch(()=>void 0))?.success||u.error(e(`channels.reactFailed`)),w&&Z(w)},onDownload:async(t,n)=>{try{let e=await A.downloadAttachment(t),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch(t){P.error(`Failed to download attachment:`,t),u.error(e(`channels.downloadFailed`))}}},$=Se[0];return(0,M.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,M.jsxs)(`aside`,{className:O(`flex w-64 shrink-0 flex-col border-e border-black/6 dark:border-white/6`,w?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,M.jsx)(se,{title:e(`channels.title`),className:`gap-y-1 px-3`,actions:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`button`,{type:`button`,onClick:Ue,title:e(`channels.browsePublic`),"aria-label":e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-browse`,children:(0,M.jsx)(s,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>je(!0),title:e(`channels.newDm`),"aria-label":e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new-dm`,children:(0,M.jsx)(o,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>ke(!0),title:e(`channels.newChannel`),"aria-label":e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new`,children:(0,M.jsx)(y,{className:`h-4 w-4`})})]})}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:x?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):a.length===0?(0,M.jsx)(C,{icon:f,size:`sm`,title:e(`channels.empty`)}):a.map(t=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>T(t.id),className:O(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-[13px]`,w===t.id?`bg-black/5 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-600 hover:bg-black/3 dark:text-dark-700 dark:hover:bg-white/4`),"data-testid":`channel-item`,children:[ge(t),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:F(t)}),(t.unreadCount??0)>0&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`rounded-full bg-primary-600 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,"aria-hidden":`true`,children:t.unreadCount}),(0,M.jsx)(`span`,{className:`sr-only`,children:e(`channels.unreadCount`,{total:t.unreadCount})})]})]},t.id))})]}),(0,M.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/6 px-4 py-2.5 dark:border-white/6`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>T(null),"aria-label":e(`common.back`),title:e(`common.back`),className:`rounded-md p-1 text-gray-500 hover:bg-black/4 md:hidden dark:text-dark-600`,children:(0,M.jsx)(oe,{className:`h-4 w-4 rtl:rotate-180`})}),ge(K),(0,M.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,"data-testid":`channel-title`,children:F(K)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(I===`pins`?null:`pins`),title:e(`channels.pins`),"aria-label":e(`channels.pins`),"aria-pressed":I===`pins`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-pins-toggle`,children:(0,M.jsx)(h,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(I===`members`?null:`members`),title:e(`channels.members`),"aria-label":e(`channels.members`),"aria-pressed":I===`members`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-members-toggle`,children:(0,M.jsx)(re,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),"aria-label":e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-settings`,children:(0,M.jsx)(c,{className:`h-4 w-4`})})]}),(0,M.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,M.jsx)(`div`,{ref:Fe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:D===null?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):D.length===0?(0,M.jsx)(C,{icon:d,size:`sm`,title:e(`channels.noMessages`)}):D.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke},e.id))}),(0,M.jsxs)(`div`,{className:`border-t border-black/6 p-3 dark:border-white/6`,children:[U&&(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/8 dark:text-dark-700`,children:[(0,M.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.filename}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>De(null),"aria-label":e(`channels.removeAttachment`),title:e(`channels.removeAttachment`),className:`rounded-sm p-0.5 text-gray-500 hover:text-red-500`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,M.jsx)(`input`,{ref:Pe,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&We(t),e.target.value=``}}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>Pe.current?.click(),title:e(`channels.attach`),"aria-label":e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-attach`,children:(0,M.jsx)(ie,{className:`h-4 w-4`})}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,M.jsx)(te,{className:O(`h-4 w-4`,V?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,M.jsxs)(`select`,{value:V,onChange:e=>Te(e.target.value),className:`max-w-[130px] rounded-md border border-black/8 bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"aria-label":e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,M.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,M.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,M.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Q())},rows:1,placeholder:e(`channels.composerPlaceholder`),"aria-label":e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/8 bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-composer`}),(0,M.jsx)(k,{size:`sm`,disabled:H||!B.trim()&&!U,onClick:()=>void Q(),"aria-label":e(`channels.send`),title:e(`channels.send`),"data-testid":`channel-send`,children:H?(0,M.jsx)(ee,{className:`h-4 w-4 animate-spin`}):(0,M.jsx)(p,{className:`h-4 w-4`})})]})]})]}),R&&(0,M.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-thread`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,M.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>z(null),"aria-label":e(`channels.closeThread`),title:e(`channels.closeThread`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:Se.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Ke,onReply:void 0},compact:!0},e.id))}),(0,M.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/6 p-2 dark:border-white/6`,children:[(0,M.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),$&&Q($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),"aria-label":e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,M.jsx)(k,{size:`sm`,disabled:H||!B.trim(),onClick:()=>$&&void Q($.id),"aria-label":e(`channels.send`),title:e(`channels.send`),children:(0,M.jsx)(p,{className:`h-3.5 w-3.5`})})]})]}),I&&(0,M.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-${I}-panel`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,M.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(I===`members`?`channels.members`:`channels.pins`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(null),"aria-label":e(`common.close`),title:e(`common.close`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:I===`members`?(0,M.jsxs)(M.Fragment,{children:[q&&K.type===`private`&&(0,M.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,M.jsx)(`input`,{type:`text`,value:W,onChange:e=>Me(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Ge()},placeholder:e(`channels.invitePlaceholder`),"aria-label":e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2 py-1 text-xs focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,M.jsx)(k,{size:`sm`,disabled:!W.trim(),onClick:()=>void Ge(),"aria-label":e(`channels.invite`),title:e(`channels.invite`),"data-testid":`channel-invite-submit`,children:(0,M.jsx)(y,{className:`h-3.5 w-3.5`})})]}),pe.map(n=>(0,M.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-700 dark:text-dark-800`,"data-testid":`channel-member`,children:[(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,M.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:n.role===`owner`?e(`channels.roleOwner`):``}),q&&n.userId!==t?.id&&K.type!==`dm`&&(0,M.jsx)(`button`,{type:`button`,onClick:async()=>{await E({title:e(`channels.removeMemberConfirm`,{name:n.username}),description:e(`channels.removeMemberConfirmDescription`),confirmLabel:e(`common.remove`),destructive:!0})&&((await A.removeMember(K.id,n.userId).catch(()=>void 0))?.success?N(e=>e.filter(e=>e.userId!==n.userId)):u.error(e(`channels.removeMemberFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),"aria-label":e(`channels.removeMemberNamed`,{name:n.username}),children:(0,M.jsx)(g,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,M.jsx)(k,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:async()=>{await E({title:e(`channels.leaveConfirm`,{name:F(K)}),description:e(`channels.leaveConfirmDescription`),confirmLabel:e(`channels.leave`),destructive:!0})&&((await A.removeMember(K.id,t?.id??``).catch(()=>void 0))?.success?(T(null),J()):u.error(e(`channels.leaveFailed`)))},"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):me.length===0?(0,M.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):me.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke,compact:!0},e.id))})]})]})]}):(0,M.jsx)(C,{icon:d,title:e(`channels.selectPrompt`),className:`flex-1 justify-center`})}),Oe&&(0,M.jsx)(ve,{onClose:()=>ke(!1),onCreated:e=>{ke(!1),J(),T(e.id)}}),Ae&&(0,M.jsx)(ye,{onClose:()=>je(!1),onOpened:e=>{je(!1),J(),T(e.id)}}),_&&(0,M.jsx)(be,{channels:m,failed:ae,onRetry:Ue,onClose:()=>v(!1),onJoined:e=>{v(!1),J(),T(e)}}),Ne&&K&&(0,M.jsx)(xe,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),T(null),J()}})]})},ve=({onClose:e,onCreated:t})=>{let{t:n}=i(),[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(`public`),[c,l]=(0,j.useState)(``),[d,f]=(0,j.useState)(!1);return(0,M.jsxs)(S,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,M.jsx)(k,{size:`sm`,disabled:d||!r.trim(),onClick:()=>{f(!0),A.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):u.error(e.error||n(`channels.createFailed`))}).catch(()=>u.error(n(`channels.createFailed`))).finally(()=>f(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-name`,className:T,children:n(`channels.nameLabel`)}),(0,M.jsx)(`input`,{id:`create-channel-name`,className:x,value:r,onChange:e=>a(e.target.value),"data-testid":`create-channel-name`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-type`,className:T,children:n(`channels.typeLabel`)}),(0,M.jsxs)(`select`,{id:`create-channel-type`,className:x,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,M.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,M.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-description`,className:T,children:n(`channels.descriptionLabel`)}),(0,M.jsx)(`textarea`,{id:`create-channel-description`,className:x,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},ye=({onClose:e,onOpened:t})=>{let{t:n}=i(),[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(!1),c=()=>{r.trim()&&(s(!0),A.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):u.error(e.error||n(`channels.dmFailed`))}).catch(()=>u.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,M.jsx)(S,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,M.jsx)(k,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,M.jsx)(`input`,{className:x,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"aria-label":n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},be=({channels:e,failed:t,onRetry:n,onClose:r,onJoined:a})=>{let{t:o}=i();return(0,M.jsx)(S,{titleId:`browse-channels-title`,title:o(`channels.browsePublic`),onClose:r,testId:`browse-channels-modal`,children:t&&e===null?(0,M.jsx)(w,{size:`sm`,message:o(`channels.loadFailed`),onRetry:n}):e===null?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):e.length===0?(0,M.jsx)(C,{icon:s,size:`sm`,title:o(`channels.noPublic`)}):e.map(e=>(0,M.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-3 py-2 dark:border-white/8`,"data-testid":`browse-channel-item`,children:[(0,M.jsx)(f,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,M.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:o(`channels.joined`)}):(0,M.jsx)(k,{size:`sm`,onClick:()=>void A.join(e.id).then(t=>{t.success?a(e.id):u.error(o(`channels.joinFailed`))}).catch(()=>u.error(o(`channels.joinFailed`))),"data-testid":`browse-channel-join`,children:o(`channels.join`)})]},e.id))})},xe=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:a}=i(),[o,s]=(0,j.useState)(e.name),[c,l]=(0,j.useState)(e.description??``),[d,f]=(0,j.useState)(!1);return(0,M.jsxs)(S,{titleId:`channel-settings-title`,title:a(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,M.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,M.jsx)(k,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:async()=>{await E({title:a(`channels.deleteConfirm`,{name:e.name}),description:a(`channels.deleteConfirmDescription`),confirmLabel:a(`channels.delete`),destructive:!0})&&((await A.delete(e.id).catch(()=>void 0))?.success?r():u.error(a(`channels.deleteFailed`)))},"data-testid":`channel-delete`,children:a(`channels.delete`)}),(0,M.jsx)(k,{size:`sm`,disabled:d||!o.trim(),onClick:()=>{f(!0),A.update(e.id,{name:o.trim(),description:c.trim()}).then(e=>{e.success?n():u.error(a(`channels.saveFailed`))}).catch(()=>u.error(a(`channels.saveFailed`))).finally(()=>f(!1))},"data-testid":`channel-settings-save`,children:a(`channels.save`)})]}),children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`channel-settings-name`,className:T,children:a(`channels.nameLabel`)}),(0,M.jsx)(`input`,{id:`channel-settings-name`,className:x,value:o,onChange:e=>s(e.target.value)})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`channel-settings-description`,className:T,children:a(`channels.descriptionLabel`)}),(0,M.jsx)(`textarea`,{id:`channel-settings-description`,className:x,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{_e as default};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r}from"./router-vendor-DLHZHk4K.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{$n as a,At as o,Fn as s,H as c,It as l,Or as u,Ot as d,Qt as f,Rt as ee,W as p,Zn as m,at as h,dr as te,er as ne,n as g,r as _,s as re,st as v,tt as y,ut as ie,v as ae,wn as b,yr as oe}from"./ui-vendor-C7v9zeJX.js";import{_ as x,g as S,i as se,n as ce,r as C,t as w,v as T}from"./ui-Byzdw4-Y.js";import{t as E}from"./confirmStore-CKkUtP9c.js";import{i as D,t as O}from"./utils-BXRzbHJC.js";import{t as k}from"./Button-D6d7HYoa.js";import{D as A}from"./api-BPTwf2O4.js";import{t as le}from"./teamEventStream-Bnna_p2v.js";import{t as ue}from"./authStore-Tu09JYbR.js";import{t as de}from"./chatStore-wi8VDo6B.js";import{t as fe}from"./logger-DAQsBb8I.js";var j=e(t(),1),M=n(),pe=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],N=180,me=({calls:e})=>{let{t}=i(),[n,r]=(0,j.useState)(!1),o=e.some(e=>e.status===`denied`);return(0,M.jsxs)(`div`,{className:`mt-1`,"data-testid":`channel-tool-calls`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,className:`flex items-center gap-1 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,"data-testid":`channel-tool-calls-toggle`,children:[n?(0,M.jsx)(a,{className:`h-3 w-3`}):(0,M.jsx)(m,{className:`h-3 w-3`}),(0,M.jsx)(_,{className:`h-3 w-3`}),t(`channels.toolCalls.summary`,{total:e.length})]}),n&&(0,M.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[e.map(e=>(0,M.jsxs)(`div`,{className:`rounded-lg border border-black/6 px-2 py-1 dark:border-white/8`,"data-testid":`channel-tool-call`,children:[(0,M.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,M.jsx)(`span`,{dir:`ltr`,className:`min-w-0 truncate text-[11px] font-medium text-gray-700 dark:text-dark-800`,children:e.name}),(0,M.jsx)(`span`,{className:O(`shrink-0 text-[10px]`,e.status===`succeeded`?`text-emerald-600 dark:text-emerald-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:e.status===`failed`?`text-red-500`:`text-gray-400 dark:text-dark-500`),children:t(`tools.callStatus.${e.status}`)})]}),e.resultPreview&&(0,M.jsx)(`p`,{dir:`ltr`,className:`mt-0.5 whitespace-pre-wrap wrap-break-word font-mono text-[10px] leading-snug text-gray-500 dark:text-dark-600`,children:e.resultPreview.slice(0,N)})]},e.id)),o&&(0,M.jsx)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:t(`channels.toolCalls.deniedHint`)})]})]})},he=({message:e,currentUserId:t,canModerate:n,actions:r,compact:a=!1})=>{let{t:o,i18n:s}=i(),[c,l]=(0,j.useState)(!1),[u,f]=(0,j.useState)(e.content),[p,m]=(0,j.useState)(!1),_=e.authorKind===`model`,re=!_&&e.author?.userId===t&&!e.deleted,y=_?e.model??o(`channels.modelAuthor`):e.author?.username??o(`channels.unknownAuthor`);return(0,M.jsxs)(`div`,{className:O(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/2.5 dark:hover:bg-white/3`,a&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,M.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[_&&(0,M.jsx)(te,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,M.jsx)(`span`,{className:O(`shrink-0 text-[13px] font-semibold`,_?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:y}),(0,M.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:D(e.createdAt,s.language)}),e.editedAt&&!e.deleted&&(0,M.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:o(`channels.edited`)}),e.pinnedAt&&(0,M.jsx)(h,{role:`img`,"aria-label":o(`channels.pins`),className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,M.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:o(`channels.deletedMessage`)}):c?(0,M.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,M.jsx)(`textarea`,{value:u,onChange:e=>f(e.target.value),rows:2,"aria-label":o(`channels.edit`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2 py-1 text-[13px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,u),l(!1)},"aria-label":o(`channels.confirmEdit`),title:o(`channels.confirmEdit`),className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,M.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>l(!1),"aria-label":o(`channels.cancelEdit`),title:o(`channels.cancelEdit`),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}):(0,M.jsxs)(M.Fragment,{children:[e.pending?(0,M.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,M.jsx)(ee,{className:`h-3.5 w-3.5 animate-spin`}),o(`channels.modelThinking`)]}):e.error?(0,M.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,M.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),_&&(e.toolCalls?.length??0)>0&&(0,M.jsx)(me,{calls:e.toolCalls}),(e.attachments?.length??0)>0&&(0,M.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/6 px-2 py-1 text-[12px] text-gray-600 hover:bg-black/3 dark:border-white/8 dark:text-dark-700 dark:hover:bg-white/4`,"data-testid":`channel-attachment`,children:[(0,M.jsx)(ie,{className:`h-3 w-3`}),(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,M.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,M.jsxs)(`button`,{type:`button`,"aria-pressed":t.mine,onClick:()=>void r.onReact(e,t.emoji,t.mine),className:O(`rounded-full border px-1.5 py-0.5 text-[11px]`,t.mine?`border-primary-400/50 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-black/8 text-gray-600 hover:bg-black/3 dark:border-white/10 dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!a&&(e.replyCount??0)>0&&r.onReply&&(0,M.jsxs)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`mt-1 flex items-center gap-1 text-[11px] font-medium text-primary-600 hover:underline dark:text-primary-400`,"data-testid":`channel-reply-count`,children:[(0,M.jsx)(d,{className:`h-3 w-3`}),o(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!c&&(0,M.jsxs)(`div`,{className:`absolute -top-2.5 inset-e-2 hidden items-center gap-0.5 rounded-lg border border-black/8 bg-white px-1 py-0.5 shadow-xs group-focus-within:flex group-hover:flex [@media(hover:none)]:flex dark:border-white/10 dark:bg-dark-50`,children:[(0,M.jsxs)(`div`,{className:`relative`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.react`),"aria-label":o(`channels.react`),"aria-haspopup":`true`,"aria-expanded":p,"data-testid":`channel-react`,children:(0,M.jsx)(b,{className:`h-3.5 w-3.5`})}),p&&(0,M.jsx)(`div`,{className:`absolute inset-e-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/8 bg-white p-1 shadow-md dark:border-white/10 dark:bg-dark-50`,children:pe.map(t=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),m(!1)},"aria-label":o(`channels.reactWith`,{emoji:t}),className:`rounded-sm p-0.5 text-sm hover:bg-black/5 dark:hover:bg-white/8`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.reply`),"aria-label":o(`channels.reply`),"data-testid":`channel-reply`,children:(0,M.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded-sm p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"aria-label":e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"data-testid":`channel-pin`,children:(0,M.jsx)(h,{className:`h-3.5 w-3.5`})}),re&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>{f(e.content),l(!0)},className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.edit`),"aria-label":o(`channels.edit`),"data-testid":`channel-edit`,children:(0,M.jsx)(v,{className:`h-3.5 w-3.5`})}),(re||n)&&(0,M.jsx)(`button`,{type:`button`,onClick:async()=>{await E({title:o(`channels.deleteMessageConfirmTitle`),description:o(`channels.deleteMessageConfirmDescription`),destructive:!0})&&await r.onDelete(e)},className:`rounded-sm p-1 text-gray-400 hover:text-red-500`,title:o(`channels.deleteMessage`),"aria-label":o(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,M.jsx)(ae,{className:`h-3.5 w-3.5`})})]})]})},P=fe(`pages:channels`),ge=e=>e.type===`dm`?(0,M.jsx)(o,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,M.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}):(0,M.jsx)(f,{className:`h-3.5 w-3.5 shrink-0`}),F=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,_e=()=>{let{t:e}=i(),t=ue(e=>e.user),n=de(e=>e.models),[a,l]=(0,j.useState)([]),[m,ne]=(0,j.useState)(null),[_,v]=(0,j.useState)(!1),[ae,b]=(0,j.useState)(!1),[x,S]=(0,j.useState)(!0),[w,T]=(0,j.useState)(null),[D,fe]=(0,j.useState)(null),[pe,N]=(0,j.useState)([]),[me,_e]=(0,j.useState)([]),[I,L]=(0,j.useState)(null),[R,z]=(0,j.useState)(null),[Se,Ce]=(0,j.useState)([]),[B,we]=(0,j.useState)(``),[V,Te]=(0,j.useState)(``),[H,Ee]=(0,j.useState)(!1),[U,De]=(0,j.useState)(null),[Oe,ke]=(0,j.useState)(!1),[Ae,je]=(0,j.useState)(!1),[W,Me]=(0,j.useState)(``),[Ne,G]=(0,j.useState)(!1),Pe=(0,j.useRef)(null),Fe=(0,j.useRef)(null),[Ie,Le]=r(),K=(0,j.useMemo)(()=>a.find(e=>e.id===w)??null,[a,w]),[Re,ze]=(0,j.useState)(null);w!==Re&&(ze(w),fe(null),z(null),L(null));let q=K?.role===`owner`,J=(0,j.useCallback)(()=>{A.listMine().then(e=>{e.success&&e.data&&l(e.data)}).catch(e=>P.error(`Failed to load channels:`,e)).finally(()=>S(!1))},[]);(0,j.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=Ie.get(`channel`);Y&&w!==Y&&T(Y),(0,j.useEffect)(()=>{Y&&Le({},{replace:!0})},[Y,Le]);let X=(0,j.useRef)(null);(0,j.useLayoutEffect)(()=>(X.current=w?{channelId:w,requestId:0}:null,()=>{X.current=null}),[w]);let Z=(0,j.useCallback)(t=>{let n=X.current;if(!n||n.channelId!==t)return;let r=++n.requestId;A.listMessages(t,{limit:100}).then(e=>{X.current===n&&n.requestId===r&&e.success&&e.data&&fe(e.data)}).catch(t=>{P.error(`Failed to load messages:`,t),u.error(e(`channels.loadFailed`),{id:`channels-load-failed`})})},[e]),Be=(0,j.useRef)(null);(0,j.useEffect)(()=>{Be.current=R},[R]);let Ve=(0,j.useCallback)(e=>{Z(e),A.markRead(e);let t=Be.current;t&&A.thread(t).then(e=>{e.success&&e.data&&Ce(e.data)}).catch(e=>P.error(`Failed to refresh thread:`,e))},[Z]);(0,j.useEffect)(()=>{if(!w)return;Z(w),A.markRead(w).then(J);let e=new AbortController;return le({path:`/channels/${w}/events`,signal:e.signal,onEvent:()=>Ve(w)}),()=>e.abort()},[w,Z,J,Ve]);let He=D?.length??0;(0,j.useEffect)(()=>{let e=Fe.current;e&&(e.scrollTop=e.scrollHeight)},[He,w]),(0,j.useEffect)(()=>{if(!w||!I)return;let t=t=>{P.error(`Failed to load channel panel:`,t),u.error(e(`channels.loadFailed`))};I===`members`?A.listMembers(w).then(e=>{e.success&&e.data?N(e.data):t(e.error)}).catch(t):A.listPins(w).then(e=>{e.success&&e.data?_e(e.data):t(e.error)}).catch(t)},[w,I,e]),(0,j.useEffect)(()=>{R&&A.thread(R).then(t=>{t.success&&t.data?Ce(t.data):u.error(e(`channels.loadFailed`))}).catch(t=>{P.error(`Failed to load thread:`,t),u.error(e(`channels.loadFailed`))})},[R,e]);let Ue=()=>{v(!0),b(!1),A.listPublic().then(e=>{e.success&&e.data?ne(e.data):b(!0)}).catch(e=>{P.error(`Failed to load public channels:`,e),b(!0)})},Q=async t=>{if(!w||H)return;let n=B.trim();if(n||U){Ee(!0);try{let r=await A.postMessage(w,{content:n,...t?{parentId:t}:{},...U?{attachmentIds:[U.id]}:{},...V?{mentionModel:V}:{}});if(r.success){if(we(``),De(null),Te(``),Z(w),t){let e=await A.thread(t);e.success&&e.data&&Ce(e.data)}}else u.error(r.error||e(`channels.sendFailed`))}catch(t){P.error(`Failed to send message:`,t),u.error(e(`channels.sendFailed`))}finally{Ee(!1)}}},We=async t=>{if(w)try{let n=await A.uploadAttachment(w,t);n.success&&n.data?De({id:n.data.id,filename:n.data.filename}):u.error(n.error||e(`channels.uploadFailed`))}catch(t){P.error(`Failed to upload attachment:`,t),u.error(e(`channels.uploadFailed`))}},Ge=async()=>{if(w&&W.trim()){if((await A.addMember(w,W.trim()).catch(()=>void 0))?.success){Me(``);let t=await A.listMembers(w).catch(()=>void 0);t?.success&&t.data&&N(t.data),u.success(e(`channels.memberAdded`))}else u.error(e(`channels.memberAddFailed`))}},Ke={onReply:e=>z(e.id),onEdit:async(t,n)=>{(await A.editMessage(t.id,n).catch(()=>void 0))?.success?w&&Z(w):u.error(e(`channels.editFailed`))},onDelete:async t=>{(await A.deleteMessage(t.id).catch(()=>void 0))?.success?w&&Z(w):u.error(e(`channels.deleteMessageFailed`))},onPin:async t=>{(await A.setPinned(t.id,!t.pinnedAt).catch(()=>void 0))?.success||u.error(e(`channels.pinFailed`)),w&&Z(w)},onReact:async(t,n,r)=>{(await(r?A.removeReaction(t.id,n):A.addReaction(t.id,n)).catch(()=>void 0))?.success||u.error(e(`channels.reactFailed`)),w&&Z(w)},onDownload:async(t,n)=>{try{let e=await A.downloadAttachment(t),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch(t){P.error(`Failed to download attachment:`,t),u.error(e(`channels.downloadFailed`))}}},$=Se[0];return(0,M.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,M.jsxs)(`aside`,{className:O(`flex w-64 shrink-0 flex-col border-e border-black/6 dark:border-white/6`,w?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,M.jsx)(se,{title:e(`channels.title`),className:`gap-y-1 px-3`,actions:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`button`,{type:`button`,onClick:Ue,title:e(`channels.browsePublic`),"aria-label":e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-browse`,children:(0,M.jsx)(s,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>je(!0),title:e(`channels.newDm`),"aria-label":e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new-dm`,children:(0,M.jsx)(o,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>ke(!0),title:e(`channels.newChannel`),"aria-label":e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new`,children:(0,M.jsx)(y,{className:`h-4 w-4`})})]})}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:x?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):a.length===0?(0,M.jsx)(C,{icon:f,size:`sm`,title:e(`channels.empty`)}):a.map(t=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>T(t.id),className:O(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-[13px]`,w===t.id?`bg-black/5 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-600 hover:bg-black/3 dark:text-dark-700 dark:hover:bg-white/4`),"data-testid":`channel-item`,children:[ge(t),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:F(t)}),(t.unreadCount??0)>0&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`rounded-full bg-primary-600 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,"aria-hidden":`true`,children:t.unreadCount}),(0,M.jsx)(`span`,{className:`sr-only`,children:e(`channels.unreadCount`,{total:t.unreadCount})})]})]},t.id))})]}),(0,M.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/6 px-4 py-2.5 dark:border-white/6`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>T(null),"aria-label":e(`common.back`),title:e(`common.back`),className:`rounded-md p-1 text-gray-500 hover:bg-black/4 md:hidden dark:text-dark-600`,children:(0,M.jsx)(oe,{className:`h-4 w-4 rtl:rotate-180`})}),ge(K),(0,M.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,"data-testid":`channel-title`,children:F(K)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(I===`pins`?null:`pins`),title:e(`channels.pins`),"aria-label":e(`channels.pins`),"aria-pressed":I===`pins`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-pins-toggle`,children:(0,M.jsx)(h,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(I===`members`?null:`members`),title:e(`channels.members`),"aria-label":e(`channels.members`),"aria-pressed":I===`members`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-members-toggle`,children:(0,M.jsx)(re,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),"aria-label":e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-settings`,children:(0,M.jsx)(c,{className:`h-4 w-4`})})]}),(0,M.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,M.jsx)(`div`,{ref:Fe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:D===null?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):D.length===0?(0,M.jsx)(C,{icon:d,size:`sm`,title:e(`channels.noMessages`)}):D.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke},e.id))}),(0,M.jsxs)(`div`,{className:`border-t border-black/6 p-3 dark:border-white/6`,children:[U&&(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/8 dark:text-dark-700`,children:[(0,M.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.filename}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>De(null),"aria-label":e(`channels.removeAttachment`),title:e(`channels.removeAttachment`),className:`rounded-sm p-0.5 text-gray-500 hover:text-red-500`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,M.jsx)(`input`,{ref:Pe,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&We(t),e.target.value=``}}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>Pe.current?.click(),title:e(`channels.attach`),"aria-label":e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-attach`,children:(0,M.jsx)(ie,{className:`h-4 w-4`})}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,M.jsx)(te,{className:O(`h-4 w-4`,V?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,M.jsxs)(`select`,{value:V,onChange:e=>Te(e.target.value),className:`max-w-[130px] rounded-md border border-black/8 bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"aria-label":e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,M.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,M.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,M.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Q())},rows:1,placeholder:e(`channels.composerPlaceholder`),"aria-label":e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/8 bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-composer`}),(0,M.jsx)(k,{size:`sm`,disabled:H||!B.trim()&&!U,onClick:()=>void Q(),"aria-label":e(`channels.send`),title:e(`channels.send`),"data-testid":`channel-send`,children:H?(0,M.jsx)(ee,{className:`h-4 w-4 animate-spin`}):(0,M.jsx)(p,{className:`h-4 w-4`})})]})]})]}),R&&(0,M.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-thread`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,M.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>z(null),"aria-label":e(`channels.closeThread`),title:e(`channels.closeThread`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:Se.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Ke,onReply:void 0},compact:!0},e.id))}),(0,M.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/6 p-2 dark:border-white/6`,children:[(0,M.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),$&&Q($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),"aria-label":e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,M.jsx)(k,{size:`sm`,disabled:H||!B.trim(),onClick:()=>$&&void Q($.id),"aria-label":e(`channels.send`),title:e(`channels.send`),children:(0,M.jsx)(p,{className:`h-3.5 w-3.5`})})]})]}),I&&(0,M.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-${I}-panel`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,M.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(I===`members`?`channels.members`:`channels.pins`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(null),"aria-label":e(`common.close`),title:e(`common.close`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:I===`members`?(0,M.jsxs)(M.Fragment,{children:[q&&K.type===`private`&&(0,M.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,M.jsx)(`input`,{type:`text`,value:W,onChange:e=>Me(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Ge()},placeholder:e(`channels.invitePlaceholder`),"aria-label":e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2 py-1 text-xs focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,M.jsx)(k,{size:`sm`,disabled:!W.trim(),onClick:()=>void Ge(),"aria-label":e(`channels.invite`),title:e(`channels.invite`),"data-testid":`channel-invite-submit`,children:(0,M.jsx)(y,{className:`h-3.5 w-3.5`})})]}),pe.map(n=>(0,M.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-700 dark:text-dark-800`,"data-testid":`channel-member`,children:[(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,M.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:n.role===`owner`?e(`channels.roleOwner`):``}),q&&n.userId!==t?.id&&K.type!==`dm`&&(0,M.jsx)(`button`,{type:`button`,onClick:async()=>{await E({title:e(`channels.removeMemberConfirm`,{name:n.username}),description:e(`channels.removeMemberConfirmDescription`),confirmLabel:e(`common.remove`),destructive:!0})&&((await A.removeMember(K.id,n.userId).catch(()=>void 0))?.success?N(e=>e.filter(e=>e.userId!==n.userId)):u.error(e(`channels.removeMemberFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),"aria-label":e(`channels.removeMemberNamed`,{name:n.username}),children:(0,M.jsx)(g,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,M.jsx)(k,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:async()=>{await E({title:e(`channels.leaveConfirm`,{name:F(K)}),description:e(`channels.leaveConfirmDescription`),confirmLabel:e(`channels.leave`),destructive:!0})&&((await A.removeMember(K.id,t?.id??``).catch(()=>void 0))?.success?(T(null),J()):u.error(e(`channels.leaveFailed`)))},"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):me.length===0?(0,M.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):me.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke,compact:!0},e.id))})]})]})]}):(0,M.jsx)(C,{icon:d,title:e(`channels.selectPrompt`),className:`flex-1 justify-center`})}),Oe&&(0,M.jsx)(ve,{onClose:()=>ke(!1),onCreated:e=>{ke(!1),J(),T(e.id)}}),Ae&&(0,M.jsx)(ye,{onClose:()=>je(!1),onOpened:e=>{je(!1),J(),T(e.id)}}),_&&(0,M.jsx)(be,{channels:m,failed:ae,onRetry:Ue,onClose:()=>v(!1),onJoined:e=>{v(!1),J(),T(e)}}),Ne&&K&&(0,M.jsx)(xe,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),T(null),J()}})]})},ve=({onClose:e,onCreated:t})=>{let{t:n}=i(),[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(`public`),[c,l]=(0,j.useState)(``),[d,f]=(0,j.useState)(!1);return(0,M.jsxs)(S,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,M.jsx)(k,{size:`sm`,disabled:d||!r.trim(),onClick:()=>{f(!0),A.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):u.error(e.error||n(`channels.createFailed`))}).catch(()=>u.error(n(`channels.createFailed`))).finally(()=>f(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-name`,className:T,children:n(`channels.nameLabel`)}),(0,M.jsx)(`input`,{id:`create-channel-name`,className:x,value:r,onChange:e=>a(e.target.value),"data-testid":`create-channel-name`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-type`,className:T,children:n(`channels.typeLabel`)}),(0,M.jsxs)(`select`,{id:`create-channel-type`,className:x,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,M.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,M.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-description`,className:T,children:n(`channels.descriptionLabel`)}),(0,M.jsx)(`textarea`,{id:`create-channel-description`,className:x,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},ye=({onClose:e,onOpened:t})=>{let{t:n}=i(),[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(!1),c=()=>{r.trim()&&(s(!0),A.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):u.error(e.error||n(`channels.dmFailed`))}).catch(()=>u.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,M.jsx)(S,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,M.jsx)(k,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,M.jsx)(`input`,{className:x,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"aria-label":n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},be=({channels:e,failed:t,onRetry:n,onClose:r,onJoined:a})=>{let{t:o}=i();return(0,M.jsx)(S,{titleId:`browse-channels-title`,title:o(`channels.browsePublic`),onClose:r,testId:`browse-channels-modal`,children:t&&e===null?(0,M.jsx)(w,{size:`sm`,message:o(`channels.loadFailed`),onRetry:n}):e===null?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):e.length===0?(0,M.jsx)(C,{icon:s,size:`sm`,title:o(`channels.noPublic`)}):e.map(e=>(0,M.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-3 py-2 dark:border-white/8`,"data-testid":`browse-channel-item`,children:[(0,M.jsx)(f,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,M.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:o(`channels.joined`)}):(0,M.jsx)(k,{size:`sm`,onClick:()=>void A.join(e.id).then(t=>{t.success?a(e.id):u.error(o(`channels.joinFailed`))}).catch(()=>u.error(o(`channels.joinFailed`))),"data-testid":`browse-channel-join`,children:o(`channels.join`)})]},e.id))})},xe=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:a}=i(),[o,s]=(0,j.useState)(e.name),[c,l]=(0,j.useState)(e.description??``),[d,f]=(0,j.useState)(!1);return(0,M.jsxs)(S,{titleId:`channel-settings-title`,title:a(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,M.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,M.jsx)(k,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:async()=>{await E({title:a(`channels.deleteConfirm`,{name:e.name}),description:a(`channels.deleteConfirmDescription`),confirmLabel:a(`channels.delete`),destructive:!0})&&((await A.delete(e.id).catch(()=>void 0))?.success?r():u.error(a(`channels.deleteFailed`)))},"data-testid":`channel-delete`,children:a(`channels.delete`)}),(0,M.jsx)(k,{size:`sm`,disabled:d||!o.trim(),onClick:()=>{f(!0),A.update(e.id,{name:o.trim(),description:c.trim()}).then(e=>{e.success?n():u.error(a(`channels.saveFailed`))}).catch(()=>u.error(a(`channels.saveFailed`))).finally(()=>f(!1))},"data-testid":`channel-settings-save`,children:a(`channels.save`)})]}),children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`channel-settings-name`,className:T,children:a(`channels.nameLabel`)}),(0,M.jsx)(`input`,{id:`channel-settings-name`,className:x,value:o,onChange:e=>s(e.target.value)})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`channel-settings-description`,className:T,children:a(`channels.descriptionLabel`)}),(0,M.jsx)(`textarea`,{id:`channel-settings-description`,className:x,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{_e as default};