wizards 0.3.8 → 0.4.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 (91) hide show
  1. package/README.md +28 -14
  2. package/apps/runtime/dist/agents/studio-assistant.js +67 -20
  3. package/apps/runtime/dist/auth/account.js +36 -4
  4. package/apps/runtime/dist/auth/device.js +101 -0
  5. package/apps/runtime/dist/auth/index.js +4 -4
  6. package/apps/runtime/dist/cli/account.js +289 -0
  7. package/apps/runtime/dist/cli/install-env.js +33 -0
  8. package/apps/runtime/dist/cli/main.js +17 -3
  9. package/apps/runtime/dist/cli/menu.js +19 -5
  10. package/apps/runtime/dist/cli/setup.js +9 -16
  11. package/apps/runtime/dist/cli/status.js +4 -1
  12. package/apps/runtime/dist/cli/ui.js +14 -0
  13. package/apps/runtime/dist/docs/dev/plugins/reference.md +7 -4
  14. package/apps/runtime/dist/docs/dev/plugins/server.md +3 -1
  15. package/apps/runtime/dist/docs/dev/plugins/space.md +19 -1
  16. package/apps/runtime/dist/docs/dev/plugins/studio.md +43 -6
  17. package/apps/runtime/dist/docs/dev/plugins/styling.md +8 -1
  18. package/apps/runtime/dist/docs/user/command-line.md +3 -2
  19. package/apps/runtime/dist/docs/user/create-account.md +47 -0
  20. package/apps/runtime/dist/docs/user/first-start.md +9 -1
  21. package/apps/runtime/dist/docs/user/index.md +16 -12
  22. package/apps/runtime/dist/docs/user/install.md +3 -1
  23. package/apps/runtime/dist/docs/user/local-only.md +38 -0
  24. package/apps/runtime/dist/docs/user/meta.json +3 -1
  25. package/apps/runtime/dist/docs/user/models.md +3 -2
  26. package/apps/runtime/dist/docs/user/space.md +4 -4
  27. package/apps/runtime/dist/engine/steps.js +3 -2
  28. package/apps/runtime/dist/engine/template.js +14 -10
  29. package/apps/runtime/dist/film/project.js +15 -3
  30. package/apps/runtime/dist/manage.js +12 -0
  31. package/apps/runtime/dist/plugins/loader.js +38 -2
  32. package/apps/runtime/dist/plugins/pro.js +16 -16
  33. package/apps/runtime/dist/routes/studio.js +69 -3
  34. package/apps/runtime/dist/services/brand.js +61 -1
  35. package/apps/runtime/dist/services/cloud.js +10 -10
  36. package/apps/runtime/dist/services/onboarding.js +152 -0
  37. package/apps/runtime/dist/services/projects.js +19 -10
  38. package/apps/runtime/dist/tools/plugin.js +11 -3
  39. package/apps/web/dist/assets/AboutDialog-CXEpsI6L.js +1 -0
  40. package/apps/web/dist/assets/{ChangelogDialog-DsSEkayM.js → ChangelogDialog-Cc2APUGI.js} +1 -1
  41. package/apps/web/dist/assets/ChatView-B2r4dW_m.js +10 -0
  42. package/apps/web/dist/assets/EditorPage-CNAYlSms.js +3 -0
  43. package/apps/web/dist/assets/{FlowPreview-C_x5Kc2j.js → FlowPreview-DzU1nGDb.js} +1 -1
  44. package/apps/web/dist/assets/{Harness-CvvtSTZC.js → Harness-ALQ9Csm6.js} +2 -2
  45. package/apps/web/dist/assets/NewWizardChannels-DMPqHkCF.js +1 -0
  46. package/apps/web/dist/assets/NewWizardPage-pi053e8N.js +7 -0
  47. package/apps/web/dist/assets/OnboardingPage-TYNX6Umd.js +1 -0
  48. package/apps/web/dist/assets/ProjectPage-CvEkx_Ux.js +1 -0
  49. package/apps/web/dist/assets/PublicRunner-BrivKNHo.js +1 -0
  50. package/apps/web/dist/assets/{ReadOnly-C1UcqOlS.js → ReadOnly-DQPHmvS0.js} +1 -1
  51. package/apps/web/dist/assets/RunDrawer-3osugizk.js +4 -0
  52. package/apps/web/dist/assets/{RunnerView-ii-PP5c-.js → RunnerView-Ci4_WzVv.js} +1 -1
  53. package/apps/web/dist/assets/SettingsPage-DKntf7-9.js +1 -0
  54. package/apps/web/dist/assets/SetupPage-DZQxEQyk.js +1 -0
  55. package/apps/web/dist/assets/SharePage-B9l4KthU.js +1 -0
  56. package/apps/web/dist/assets/changelog-CxdXZo3V.js +1 -0
  57. package/apps/web/dist/assets/{circle-alert-D-Q6DK7b.js → circle-alert-DCBV7n5k.js} +1 -1
  58. package/apps/web/dist/assets/{esm-CTna4iL0.js → esm-CuqXcPS3.js} +1 -1
  59. package/apps/web/dist/assets/index-CmxVazOf.css +1 -0
  60. package/apps/web/dist/assets/index-j09nLtEs.js +14 -0
  61. package/apps/web/dist/assets/{lock-DwGN_KOC.js → lock-DlzTfwxP.js} +1 -1
  62. package/apps/web/dist/assets/{phone-XIVIe17d.js → phone-BFD815nc.js} +1 -1
  63. package/apps/web/dist/assets/{settings-menu-JuSRq6NP.js → settings-menu-C7VsRpe9.js} +1 -1
  64. package/apps/web/dist/assets/ui-DTuixH4y.js +134 -0
  65. package/apps/web/dist/assets/{upload-CDxTpAqx.js → upload-BEf5-d6X.js} +1 -1
  66. package/apps/web/dist/index.html +4 -5
  67. package/apps/web/dist/install.sh +17 -7
  68. package/apps/web/dist/mcp/flow.html +2 -2
  69. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +36 -2
  70. package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +44 -1
  71. package/node_modules/@engenty-wizards/shared/dist/feature-flags.d.ts +18 -0
  72. package/node_modules/@engenty-wizards/shared/dist/feature-flags.js +18 -0
  73. package/node_modules/@engenty-wizards/shared/dist/projects.d.ts +22 -6
  74. package/node_modules/@engenty-wizards/shared/dist/projects.js +20 -0
  75. package/package.json +1 -1
  76. package/apps/web/dist/assets/AboutDialog-ClV4gNiW.js +0 -1
  77. package/apps/web/dist/assets/ChatView-BdYCnDLk.js +0 -10
  78. package/apps/web/dist/assets/EditorPage-7PZzkNBT.js +0 -3
  79. package/apps/web/dist/assets/NewWizardChannels-g1qCd_tQ.js +0 -1
  80. package/apps/web/dist/assets/NewWizardPage-B3hswj5r.js +0 -7
  81. package/apps/web/dist/assets/ProjectPage-CFDncRxT.js +0 -1
  82. package/apps/web/dist/assets/PublicRunner-C9N5r-sT.js +0 -1
  83. package/apps/web/dist/assets/RunDrawer-B8YzFvgz.js +0 -4
  84. package/apps/web/dist/assets/SettingsPage-ClEP5Q0t.js +0 -1
  85. package/apps/web/dist/assets/SetupPage-CDFzo6LT.js +0 -1
  86. package/apps/web/dist/assets/SharePage-BV2S0g84.js +0 -1
  87. package/apps/web/dist/assets/changelog-wZI-UaUi.js +0 -1
  88. package/apps/web/dist/assets/index-DUjJx-uk.css +0 -1
  89. package/apps/web/dist/assets/index-DnQgOKOQ.js +0 -15
  90. package/apps/web/dist/assets/logo-C4V2_3Ar.js +0 -1
  91. package/apps/web/dist/assets/ui-DrjXmHdO.js +0 -133
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{$t as a,At as o,Cn as s,Ct as c,E as l,Et as u,Gt as d,Ht as f,Lt as p,Ot as m,Pt as h,Qt as g,Sn as _,St as v,Tt as y,Vt as b,Yt as x,Zt as S,_n as C,_t as w,bn as ee,bt as T,dt as E,en as D,ft as O,gt as k,ht as A,ln as te,mt as j,nn as M,pn as N,pt as P,sn as F,u as I,ut as L,wt as ne,xn as re,xt as R,zt as ie}from"./ui-DrjXmHdO.js";import{_ as ae,a as oe,b as z,c as se,d as ce,f as B,g as le,h as ue,i as de,l as fe,m as pe,n as V,o as me,p as he,s as ge,u as _e,v as ve,x as H,y as U}from"./RunDrawer-B8YzFvgz.js";import{t as W}from"./phone-XIVIe17d.js";import{n as ye,r as be,t as xe}from"./ReadOnly-C1UcqOlS.js";import{t as G}from"./upload-CDxTpAqx.js";import{$ as Se,At as Ce,B as we,G as K,H as Te,I as q,J as Ee,K as De,Kt as Oe,L as J,Ot as ke,Q as Ae,R as je,U as Y,V as Me,Vt as Ne,W as Pe,Wt as Fe,X as Ie,Xt as Le,Y as Re,Yt as ze,Z as X,Zt as Be,_ as Ve,an as He,at as Ue,ct as We,d as Ge,et as Ke,f as qe,g as Je,in as Ye,it as Xe,kt as Ze,l as Qe,mt as $e,nt as et,ot as tt,p as nt,q as rt,rt as it,s as at,st as ot,tt as st,u as ct,un as lt,v as ut,vn as dt,z as ft}from"./index-DnQgOKOQ.js";import{a as Z,c as pt,f as mt,i as ht,n as gt,o as _t,r as vt,s as yt,t as bt,u as xt}from"./settings-menu-JuSRq6NP.js";import{t as St}from"./RunnerView-ii-PP5c-.js";var Ct={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Ct.node;var wt=N(Ct),Tt={name:`box`,size:24,node:[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]};Tt.node;var Et=N(Tt),Dt={name:`case-upper`,size:24,node:[[`path`,{d:`M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5`,key:`nxs35`}],[`path`,{d:`m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16`,key:`d5nyq2`}],[`path`,{d:`M3.304 13h6.392`,key:`1q3zxz`}]]};Dt.node;var Ot=N(Dt),kt={name:`folder-plus`,size:24,node:[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};kt.node;var At=N(kt),jt={name:`grid-2x2`,size:24,node:[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]],aliases:[`grid-2-x-2`]};jt.node;var Mt=N(jt),Nt={name:`layers`,size:24,node:[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]],aliases:[`layers-3`]};Nt.node;var Pt=N(Nt),Ft={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Ft.node;var It=N(Ft),Lt={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};Lt.node;var Rt=N(Lt),zt={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};zt.node;var Bt=N(zt),Vt={name:`music`,size:24,node:[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]};Vt.node;var Ht=N(Vt),Q=e(t(),1),$=e(n(),1),Ut={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function Wt({file:e,actions:t}){let[n,r]=(0,Q.useState)(e.description),i=(0,Q.useRef)(e.description),a=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Q.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let s=e.status===`pending`&&!n;return t.readOnly?n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,$.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:o(s?`project.describing`:`project.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function Gt(e,t){confirm(o(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function Kt({projectId:e,file:t,small:n}){let r=Xe(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:u(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,$.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,$.jsx)(qt,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,$.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,$.jsx)(Ht,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(g,{className:i}):t.mime===`application/json`?(0,$.jsx)(p,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(Et,{className:i}):(0,$.jsx)(S,{className:i}),n?null:(0,$.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function qt({src:e,small:t}){let[n,r]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,$.jsx)(`div`,{className:u(`flex size-full items-center justify-center text-ink`,t?`text-[1.25rem]`:`text-[2.75rem]`),style:n?{fontFamily:`"${n}"`}:void 0,children:`Aa`})}var Jt=`application/x-wizards-logo`;function Yt({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:a,onUpload:s,onPreview:c,mainId:l,onMakeMain:u,moveTo:d,onRemove:f}){let p=e=>f?f(e):Gt(e,r);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,$.jsxs)(`div`,{draggable:d&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(Jt,n.id),className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[n.id===l?(0,$.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,$.jsx)(O,{tone:`ember`,children:o(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?Ut:void 0,children:[c&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${o(`project.preview`)}: ${n.name}`,onClick:()=>c(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(Kt,{projectId:e,file:n})}):(0,$.jsx)(Kt,{projectId:e,file:n}),(0,$.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[c?(0,$.jsx)(A,{label:o(`project.preview`),onClick:()=>c(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(lt,{className:`size-4`})}):null,u&&n.id!==l&&!r.readOnly?(0,$.jsx)(A,{label:o(`project.logoMakeMain`),onClick:()=>u(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(Oe,{className:`size-4`})}):null,d&&!r.readOnly?(0,$.jsx)(we,{options:d.options,value:d.current(n),onChange:e=>d.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:()=>p(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]}),t===`asset`?(0,$.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,$.jsx)(Wt,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,$.jsxs)(je,{accept:i,multiple:!1,onFiles:e=>s?s(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,$.jsx)(R,{className:`size-5`}):(0,$.jsx)(b,{className:`size-5`}),a]}):null]})}function Xt({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,a]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),g=async()=>{c(!0),d(null);try{let a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(p(a.candidates),h([a.candidates[0].url])):d(o(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){d(e.message)}c(!1)},_=async()=>{c(!0),d(null);let e=[];try{for(let n of m){let r=await t(n);r.file&&e.push(r.file)}}catch(e){d(e.message)}c(!1),e.length&&n(e),e.length===m.length&&r()};return(0,$.jsx)(P,{open:!0,onClose:r,wide:f?!0:void 0,title:o(f?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:f?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:o(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:f.map(t=>{let n=m.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>h(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:u(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:Ut,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:u(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(F,{className:`size-3.5`})}):null]},t.url)})}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>p(null),children:o(`run.back`)}),(0,$.jsx)(L,{busy:s,disabled:!m.length,onClick:()=>void _(),children:m.length>1?o(`project.addMany`,{n:m.length}):o(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:r,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:s,disabled:!i.trim(),children:o(`run.next`)})]})]})})}function Zt(e,t,n){return i({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>I.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function Qt(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var $t=e=>[Qt(e),e.pages?o(`project.pages`,{n:e.pages}):null,it(e.size)].filter(Boolean).join(` · `),en=2e5;function tn({projectId:e,fileId:t,readOnly:n,onGone:i}){let s=r(),c=We(e),l=pe(e),d=tt(e,n),f=c.data?.files.find(e=>e.id===t),p=f?f.mime===`application/pdf`||f.mime.startsWith(`image/`):!1,[m,g]=(0,Q.useState)(null);if(!f)return c.isLoading?(0,$.jsx)(R,{className:`mx-auto text-ink-3`}):null;let _=m??(p?`original`:`text`),v=l.data?.items.find(e=>e.key===`f:${f.id}`),y=Xe(e,f.id),b=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":_===e,onClick:()=>g(e),className:u(`rounded-full px-3 py-1 text-[0.8125rem] transition`,_===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,$.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:f.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:$t(f)}),(0,$.jsx)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,"aria-label":o(`project.openOriginal`),title:o(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(a,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:o(`project.reindex`),onClick:async()=>{await d.reindex(f.id),await s.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(ie,{className:`size-4`})}),(0,$.jsx)(A,{label:o(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(o(`data.confirmDelete`,{title:f.name}))&&(await d.remove(f.id),await s.invalidateQueries({queryKey:[`knowledge`,e]}),i())},children:(0,$.jsx)(h,{className:`size-4`})})]})]}),(0,$.jsx)(B,{projectId:e,itemKey:`f:${f.id}`,has:v?.categories??[],originLabel:v?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(Wt,{file:f,actions:d})}),f.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:f.error}):null,(0,$.jsxs)(E,{className:`flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[p?b(`original`,o(`project.original`)):null,b(`text`,o(`project.readText`))]}),_===`original`?f.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:y,title:f.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:y,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(nn,{projectId:e,file:f})]})]})}function nn({projectId:e,file:t}){let n=Zt(e,t,en);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(R,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(l,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:o(`project.textCut`,{shown:n.data.text.length.toLocaleString(),total:n.data.chars.toLocaleString()})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:o(`project.noText`)})}var rn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,an=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),it(e.size)].filter(Boolean).join(` · `);function on({projectId:e,file:t,actions:n,onClose:r}){let i=Xe(e,t.id);return(0,$.jsxs)(P,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,$.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:an(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":o(`project.openOriginal`),title:o(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(a,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:Ut,children:(0,$.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,$.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,$.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(Wt,{file:t,actions:n})})]})}function sn({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,$.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`${o(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(Kt,{projectId:e,file:t,small:!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:an(t)})]}),(0,$.jsx)(Wt,{file:t,actions:n})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,$.jsx)(A,{label:o(`project.preview`),onClick:i,children:(0,$.jsx)(lt,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(we,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})}function cn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,a]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(P,{open:!0,onClose:r,title:o(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.assetSectionName`)}),(0,$.jsx)(k,{autoFocus:!0,value:i,maxLength:80,placeholder:o(`project.assetSectionTitle`),onChange:e=>a(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(L,{variant:`danger`,onClick:n,children:o(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(L,{variant:`ghost`,onClick:r,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,disabled:!i.trim(),children:o(e?`settings.save`:`project.add`)})]})]})})}function ln({projectId:e,data:t,readOnly:n,sections:r,save:i}){let a=tt(e,n),[s,c]=ot(`assets`,`cards`),[l,u]=(0,Q.useState)(``),[d,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(r),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),S=(0,Q.useRef)(null),C=Ue({assetSections:m},i),w=t.files.filter(e=>e.kind===`asset`),ee=new Map(w.map(e=>[e.id,e])),T=new Set(m.flatMap(e=>e.assets)),E=m.find(e=>e.id===g)??null,D=E?E.assets.map(e=>ee.get(e)).filter(e=>!!e):w.filter(e=>!T.has(e.id)),O=w.find(e=>e.id===d),k=l.trim().toLowerCase(),te=k?D.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(k)):D,j=(e,t)=>h(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),M=async e=>{let t=E?.id??null;for(let n of await a.upload(`asset`,e))j(n.id,t)},N=e=>{confirm(o(`project.removeConfirm`,{name:e.name}))&&(a.remove(e.id),j(e.id,null))},P=m.length?{options:[{value:``,label:o(`project.assetsGeneral`)},...m.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))],current:e=>m.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>j(e.id,t||null)}:void 0,F=[{label:o(`project.assetUpload`),icon:(0,$.jsx)(G,{className:`size-4 shrink-0`}),onPick:()=>S.current?.click()},{label:o(`project.assetFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>x(!0)},...m.length<X.logoSections?[{label:o(`project.assetSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>y(`new`)}]:[]],I=m.length||w.length?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[m.length?(0,$.jsx)(ne,{value:g,onChange:e=>{_(e),u(``)},label:o(`project.assets`),options:[{id:``,label:o(`project.assetsGeneral`)},...m.map(e=>({id:e.id,label:e.title||o(`project.sectionUntitled`)}))]}):null,E&&!n?(0,$.jsx)(A,{label:o(`project.assetSectionRename`),onClick:()=>y(`current`),children:(0,$.jsx)(f,{className:`size-4`})}):null]}),D.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(Te,{value:l,onChange:u,placeholder:o(`project.assetSearch`)})}),(0,$.jsx)(A,{label:o(s===`list`?`project.viewCards`:`project.viewList`),onClick:c,children:s===`list`?(0,$.jsx)(It,{className:`size-4`}):(0,$.jsx)(Bt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(Y,{title:o(`project.assets`),hint:o(`project.assetsHint`),save:C,tabs:I,action:n?null:(0,$.jsx)(q,{entries:F}),children:[(0,$.jsx)(`input`,{ref:S,type:`file`,multiple:!0,accept:rn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&M(t)}}),te.length?s===`cards`?(0,$.jsx)(Yt,{projectId:e,kind:`asset`,files:te,actions:a,moveTo:P,onRemove:N,onPreview:e=>p(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:te.map(t=>(0,$.jsx)(sn,{projectId:e,file:t,actions:a,moveTo:P,onPreview:()=>p(t.id),onRemove:()=>N(t)},t.id))}):D.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`project.staysLocal`)}):(0,$.jsxs)(je,{accept:rn,onFiles:e=>void M(e),className:`h-16 w-full`,children:[a.busy?(0,$.jsx)(R,{className:`size-4`}):(0,$.jsx)(G,{className:`size-4`}),o(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:o(`project.assetAdd`)})]}),a.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error}):null,O?(0,$.jsx)(on,{projectId:e,file:O,actions:a,onClose:()=>p(null)}):null,v?(0,$.jsx)(cn,{section:v===`current`?E:null,onClose:()=>y(null),onSave:e=>{if(v===`current`&&E)h(t=>t.map(t=>t.id===E.id?{...t,title:e}:t));else{let t=K();h(n=>[...n,{id:t,title:e,assets:[]}]),_(t)}},onRemove:v===`current`&&E?()=>{(!E.assets.length||confirm(o(`project.assetSectionRemoveConfirm`,{name:E.title})))&&(h(e=>e.filter(e=>e.id!==E.id)),_(``),y(null))}:void 0}):null,b?(0,$.jsx)(Xt,{kind:`asset`,onClose:()=>x(!1),fetchUrl:e=>a.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)j(t.id,E?.id??null)}}):null]})}var un=/^#[0-9a-fA-F]{6}$/;async function dn(e,t){let[n,r]=[1920,1080],i=document.createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return;let o=e.angle*Math.PI/180,s;if(e.type===`radial`)s=a.createRadialGradient(n/2,r/2,0,n/2,r/2,Math.hypot(n,r)/2);else if(e.type===`conic`)s=a.createConicGradient(o-Math.PI/2,n/2,r/2);else{let e=Math.abs(n*Math.sin(o))+Math.abs(r*Math.cos(o)),[t,i]=[Math.sin(o)*e/2,-Math.cos(o)*e/2];s=a.createLinearGradient(n/2-t,r/2-i,n/2+t,r/2+i)}for(let t of[...e.stops].sort((e,t)=>e.at-t.at))s.addColorStop(Math.min(1,Math.max(0,t.at/100)),t.color);a.fillStyle=s,a.fillRect(0,0,n,r);let c=await new Promise(e=>i.toBlob(e,`image/png`));if(c){let e=document.createElement(`a`);e.href=URL.createObjectURL(c),e.download=`${t||`gradient`}.png`,e.click(),setTimeout(()=>URL.revokeObjectURL(e.href),5e3)}}var fn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function pn({gradient:e,brand:t,onSave:n,onClose:r}){let[i,a]=(0,Q.useState)(e),[s,c]=(0,Q.useState)(Ke(e)),[l,d]=(0,Q.useState)(!1),f=e=>{a(e),c(Ke(e)),d(!1)},p=(e,t)=>f({...i,stops:i.stops.map((n,r)=>r===e?{...n,...t}:n)}),m=e=>{let t=[...i.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));f({...i,stops:[...i.stops,{color:e??t[0]?.color??`#888888`,at:n}]})};return(0,$.jsx)(P,{open:!0,onClose:r,wide:!0,title:o(`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:Ke(i)}}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-48 flex-1`,children:[(0,$.jsx)(w,{children:o(`project.gradientName`)}),(0,$.jsx)(k,{value:i.name,maxLength:80,placeholder:o(`project.gradientNamePlaceholder`),onChange:e=>a({...i,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:Ie.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":i.type===e,onClick:()=>f({...i,type:e}),className:u(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,i.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:o(fn[e])},e))})]}),i.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(w,{children:o(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:i.angle,"aria-label":o(`project.gradientAngle`),onChange:e=>f({...i,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(i.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(v,{value:un.test(e.color)?e.color:`#888888`,onChange:e=>p(t,{color:e.target.value})}),(0,$.jsx)(k,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();un.test(n)&&p(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":o(`project.gradientAt`),onChange:e=>p(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,$.jsx)(A,{label:o(`project.remove`),disabled:i.stops.length<=2,onClick:()=>f({...i,stops:i.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[i.stops.length<12?(0,$.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>m(),children:[(0,$.jsx)(b,{className:`size-4`}),` `,o(`project.gradientStopAdd`)]}):null,t.length&&i.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:o(`project.gradientFromBrand`)}),t.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>m(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:`CSS`}),(0,$.jsx)(k,{value:s,spellCheck:!1,onChange:e=>{c(e.target.value);let t=et(e.target.value);d(!t),t&&a({...i,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:u(`mt-1.5 text-[0.8125rem]`,l?`text-rose`:`text-ink-3`),children:o(l?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:r,children:o(`common.cancel`)}),(0,$.jsx)(L,{onClick:()=>{n(i),r()},children:o(`settings.save`)})]})]})})}var mn=`flex shrink-0 opacity-0 transition focus-within:opacity-100 group-hover/card:opacity-100 coarse:opacity-100`;function hn({gradient:e,readOnly:t,onEdit:n,onRename:r,onRemove:i}){let a=Ke(e),[s,c]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":o(`project.gradientEdit`),onClick:n,className:`h-28 rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-0.5`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:t?(0,$.jsx)(`span`,{className:`text-[0.875rem]`,children:e.name}):(0,$.jsx)(ft,{value:e.name,label:o(`project.gradientName`),placeholder:o(`project.gradientName`),maxLength:80,onChange:r,className:`font-medium text-[0.875rem]`})}),(0,$.jsxs)(`div`,{className:mn,children:[(0,$.jsx)(A,{label:o(s?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),c(!0),setTimeout(()=>c(!1),1500)},className:`size-8`,children:(0,$.jsx)(M,{className:`size-4`})}),(0,$.jsx)(A,{label:o(`project.download`),onClick:()=>void dn(e,e.name),className:`size-8`,children:(0,$.jsx)(D,{className:`size-4`})}),t?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:i,className:`size-8 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})]})}function gn({projectId:e,pattern:t,fileName:n,readOnly:r,onChange:i,onRemove:a}){let s=Xe(e,t.file);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`div`,{className:`h-28 rounded-md ring-1 ring-border-soft`,style:{backgroundImage:`url("${s}")`,backgroundSize:t.tile?`64px`:`cover`,backgroundRepeat:t.tile?`repeat`:`no-repeat`,backgroundPosition:`center`}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-0.5`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:r?(0,$.jsx)(`span`,{className:`text-[0.875rem]`,children:t.name||n}):(0,$.jsx)(ft,{value:t.name,label:o(`project.patternName`),placeholder:n,maxLength:80,onChange:e=>i({name:e}),className:`font-medium text-[0.875rem]`})}),(0,$.jsxs)(`div`,{className:mn,children:[r?null:(0,$.jsx)(A,{label:t.tile?o(`project.patternFill`):o(`project.patternTile`),"aria-pressed":!!t.tile,onClick:()=>i({tile:!t.tile}),className:u(`size-8`,t.tile&&`bg-paper-2 text-ink`),children:(0,$.jsx)(Mt,{className:`size-4`})}),(0,$.jsx)(`a`,{href:s,download:n,"aria-label":o(`project.download`),title:o(`project.download`),className:`inline-flex size-8 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(D,{className:`size-4`})}),r?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:a,className:`size-8 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})]})}var _n=/^#[0-9a-fA-F]{6}$/;function vn({sections:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(`#e0531b`),[a,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),u=_n.test(r);return(0,$.jsx)(P,{open:!0,onClose:n,title:o(`project.colorAddTitle`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),u&&(t({name:a.trim(),value:r.toLowerCase(),...c?{section:c}:{}}),n())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.colorValue`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(v,{value:u?r:`#888888`,onChange:e=>i(e.target.value)}),(0,$.jsx)(k,{value:r,placeholder:`#e0531b`,spellCheck:!1,onChange:e=>i(e.target.value.trim()),className:`font-mono text-[0.875rem]`})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.colorUseLabel`)}),(0,$.jsx)(k,{autoFocus:!0,value:a,maxLength:120,placeholder:o(`project.colorName`),onChange:e=>s(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.colorUse`)})]}),e.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.colorSectionLabel`)}),(0,$.jsx)(T,{value:c,onChange:l,options:[{value:``,label:o(`project.sectionStandard`)},...e.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))]})]}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:n,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,disabled:!u,children:o(`project.add`)})]})]})})}function yn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)([]),h=async()=>{s(!0),l(null);try{let{colors:t}=await I.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(f(t),m([])):l(o(`project.colorsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(P,{open:!0,onClose:n,wide:d?!0:void 0,title:o(d?`project.colorsFound`:`project.colorsFromUrl`),children:d?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:o(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:d.map(e=>{let t=p.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>m(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:u(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,$.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,$.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(F,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>f(null),children:o(`run.back`)}),(0,$.jsx)(L,{disabled:!p.length,onClick:()=>{t(d.filter(e=>p.includes(e.value))),n()},children:p.length>1?o(`project.addMany`,{n:p.length}):o(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.colorsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:n,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:a,disabled:!r.trim(),children:o(`run.next`)})]})]})})}function bn({projectId:e,data:t,colors:n,sections:r,gradients:i,patterns:a,rules:s,save:c,readOnly:l}){let[u,d]=(0,Q.useState)(()=>n.map(e=>({...e,id:K()}))),[f,p]=(0,Q.useState)(r),[m,g]=(0,Q.useState)(i),[_,y]=(0,Q.useState)(a),[x,S]=(0,Q.useState)(null),C=tt(e,l),w=De(s),[ee,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),N=Ue({colors:u.filter(e=>_n.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:f,gradients:m,patterns:_,colorRules:w.rules},c),P=f.filter(e=>(e.kind??`colors`)===`colors`),F=e=>P.some(t=>t.id===e.section),I=u.filter(e=>!F(e)),L=(I[0]??u[0])?.id,ne=(e,t)=>d(n=>n.map(n=>n.id===e?{...n,...t}:n)),re=e=>d(t=>[...t,...e.map(e=>({...e,id:K()}))].slice(0,X.colors)),ie=[{value:``,label:o(`project.sectionStandard`)},...P.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))],ae=(e,t)=>{let n=K();T(n),p(r=>[...r,{id:n,title:t,description:``,...e===`colors`?{}:{kind:e}}])},oe=e=>({id:K(),name:``,section:e,type:`linear`,angle:90,stops:[{color:u[0]?.value&&_n.test(u[0].value)?u[0].value:`#4b73ff`,at:0},{color:u[1]?.value&&_n.test(u[1].value)?u[1].value:`#ff6d1b`,at:100}]}),z=async(e,t)=>{let n=await C.upload(`pattern`,t);y(t=>[...t,...n.map(t=>({id:K(),name:t.name.replace(/\.[^.]+$/,``),section:e,file:t.id}))])},se=[...u.length<X.colors?[{label:o(`project.colorNew`),icon:(0,$.jsx)(b,{className:`size-4 shrink-0`}),onPick:()=>D(!0)},{label:o(`project.colorsFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>M(!0)}]:[],...f.length<X.logoSections?[{label:o(`project.colorSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>ae(`colors`,``)},{label:o(`project.gradientSectionAdd`),icon:(0,$.jsx)(wt,{className:`size-4 shrink-0`}),onPick:()=>ae(`gradients`,o(`project.gradientSectionTitle`))},{label:o(`project.patternSectionAdd`),icon:(0,$.jsx)(Mt,{className:`size-4 shrink-0`}),onPick:()=>ae(`patterns`,o(`project.patternSectionTitle`))}]:[],...w.full?[]:[{label:o(`project.ruleNew`),icon:(0,$.jsx)(He,{className:`size-4 shrink-0`}),onPick:()=>w.add()}]],ce=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(v,{value:_n.test(e.value)?e.value:`#888888`,onChange:t=>ne(e.id,{value:t.target.value})}),(0,$.jsx)(k,{value:e.name,placeholder:o(`project.colorName`),maxLength:120,onChange:t=>ne(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(k,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>ne(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===L?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(O,{tone:`ember`,children:o(`project.colorAccent`)})}):l?null:(0,$.jsx)(A,{label:o(`project.colorFirst`),onClick:()=>d(t=>[{...e,section:void 0},...t.filter(t=>t.id!==e.id)]),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:(0,$.jsx)(te,{className:`size-4`})}),l||!f.length?null:(0,$.jsx)(we,{options:ie,value:F(e)?e.section??``:``,onChange:t=>ne(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),l?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:()=>d(t=>t.filter(t=>t.id!==e.id)),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]},e.id);return(0,$.jsxs)(Y,{title:o(`project.colors`),hint:o(`project.colorsHint`),save:N,locked:l,action:l?null:(0,$.jsx)(q,{entries:se}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[I.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:I.map(ce)}),l?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.colorUse`)})]}):u.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`project.colorsEmpty`)}),f.map(n=>{let r=n.kind??`colors`,i=u.filter(e=>e.section===n.id),a=m.filter(e=>e.section===n.id),s=_.filter(e=>e.section===n.id),c=r===`gradients`?a.length:r===`patterns`?s.length:i.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(Pe,{title:n.title,description:n.description,titlePlaceholder:o(r===`gradients`?`project.gradientSectionTitlePlaceholder`:r===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),descriptionPlaceholder:o(`project.colorSectionUse`),autoFocus:ee===n.id,readOnly:l,onChange:e=>p(t=>t.map(t=>t.id===n.id?{...t,...e}:t)),onRemove:()=>{if(!c||confirm(o(r===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:n.title||o(`project.sectionUntitled`)}))){p(e=>e.filter(e=>e.id!==n.id)),d(e=>e.map(e=>e.section===n.id?{...e,section:void 0}:e)),g(e=>e.filter(e=>e.section!==n.id));for(let e of s)C.remove(e.file);y(e=>e.filter(e=>e.section!==n.id))}}}),r===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(e=>(0,$.jsx)(hn,{gradient:e,readOnly:l,onEdit:()=>S(e),onRename:t=>g(n=>n.map(n=>n.id===e.id?{...n,name:t}:n)),onRemove:()=>g(t=>t.filter(t=>t.id!==e.id))},e.id)),l||m.length>=X.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>S(oe(n.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(b,{className:`size-5`}),o(`project.gradientAdd`)]})]}):r===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[s.map(n=>(0,$.jsx)(gn,{projectId:e,pattern:n,fileName:t.files.find(e=>e.id===n.file)?.name??`pattern`,readOnly:l,onChange:e=>y(t=>t.map(t=>t.id===n.id?{...t,...e}:t)),onRemove:()=>{C.remove(n.file),y(e=>e.filter(e=>e.id!==n.id))}},n.id)),l?null:(0,$.jsxs)(je,{accept:`image/*`,onFiles:e=>void z(n.id,e),className:`min-h-28 flex-col p-3`,children:[C.busy?(0,$.jsx)(R,{className:`size-5`}):(0,$.jsx)(b,{className:`size-5`}),o(`project.patternAdd`)]})]}):i.length?(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.map(ce)}):null]},n.id)}),(0,$.jsx)(Me,{rules:w,placeholder:o(`project.colorRulePlaceholder`),readOnly:l})]}),C.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:C.error}):null,E?(0,$.jsx)(vn,{sections:P,onClose:()=>D(!1),onAdd:e=>re([e])}):null,x?(0,$.jsx)(pn,{gradient:x,brand:u.filter(e=>_n.test(e.value)),onClose:()=>S(null),onSave:e=>g(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,j?(0,$.jsx)(yn,{projectId:e,onClose:()=>M(!1),onAdd:re}):null]})}var xn=e=>/^(ja|yes|true)$/i.test(e.trim()),Sn={text:Fe,longtext:be,number:z,date:H,url:x,email:Ye,phone:W,boolean:U};function Cn({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{c.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let l=Sn[e??t],d=`${o(`project.factType`)}: ${o(`project.type.${e??t}`)}`,f=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,p=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":d,title:d,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{s(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:u(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,r?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,$.jsx)(l,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:u(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,a?`bottom-12`:`top-12`),children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:f,onClick:()=>p(void 0),children:[(0,$.jsx)(Ne,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:o(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:o(`project.type.${t}`)}),(0,$.jsx)(F,{className:u(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),Ee.map(t=>{let n=Sn[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:f,onClick:()=>p(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:o(`project.type.${t}`)}),(0,$.jsx)(F,{className:u(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function wn({facts:e,save:t,readOnly:n}){let r=(0,Q.useRef)(0),i=(0,Q.useRef)(null),[a,s]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),l=Ue(a.filter(e=>e.key&&e.label.trim()).map(({key:e,label:t,value:n,type:r})=>({key:e,label:t.trim(),value:n,...r?{type:r}:{}})),t),u=(e,t)=>s(n=>n.map(n=>n.id===e?{...n,...t}:n)),d=(e,t,n=!1)=>{let a=`f${r.current++}`;i.current=`${a}:${t}`;let o={id:a,key:``,label:``,value:``,...e};s(e=>n?[o,...e]:[...e,o])},f=e=>t=>{t&&i.current===e&&(i.current=null,t.focus())},p=rt.filter(e=>!a.some(t=>t.key===e.key));return(0,$.jsxs)(Y,{title:o(`project.facts`),hint:o(`project.factsHint`),save:l,locked:n,action:a.length<X.facts&&!n?(0,$.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>d({},`label`,!0),children:[(0,$.jsx)(b,{className:`size-4`}),` `,o(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>{let t=Ae(e.value),r=e.type??t;return(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,$.jsx)(k,{ref:f(`${e.id}:label`),value:e.label,placeholder:o(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>u(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&u(e.id,{key:Se(e.label,a.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(c,{checked:xn(e.value),label:e.label,onChange:t=>u(e.id,{value:o(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:xn(e.value)?o(`project.yes`):o(`project.no`)})]}):(0,$.jsx)(y,{ref:f(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:o(`project.factValue`),onChange:t=>u(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(Cn,{type:e.type,detected:t,onChange:t=>u(e.id,{type:t})}),n?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:()=>s(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]},e.id)})}),a.length<X.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${a.length?`mt-4`:``}`,children:[(0,$.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>d({},`label`),children:[(0,$.jsx)(b,{className:`size-4`}),` `,o(`project.factAdd`)]}),p.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d({key:e.key,label:m===`en`?e.en:e.de},`value`),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,$.jsx)(b,{className:`size-3.5`}),` `,m===`en`?e.en:e.de]},e.key))]}):null]})}function Tn({onLogo:e,children:t,className:n}){let[r,i]=(0,Q.useState)(!1);return e?(0,$.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(Jt);i(!1),n&&(t.preventDefault(),e(n))},className:u(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,$.jsx)(`div`,{className:n,children:t})}function En({projectId:e,data:t,readOnly:n,sections:r,rules:i,save:a}){let s=tt(e,n),[c,l]=(0,Q.useState)(r),u=De(i),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(!1),h=(0,Q.useRef)(null),g=Ue({logoSections:c,logoRules:u.rules},a),_=t.files.filter(e=>e.kind===`logo`),v=new Map(_.map(e=>[e.id,e])),y=new Set(c.flatMap(e=>e.logos)),b=_.filter(e=>!y.has(e.id)),x=st(_,c)?.id,S=(e,t)=>l(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),C=(e,t)=>l(n=>n.map(n=>n.id===e?{...n,...t}:n)),w=async(e,t)=>{let n=await s.upload(`logo`,e);for(let e of n)S(e.id,t)},ee=c.length?{options:[{value:``,label:o(`project.sectionStandard`)},...c.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))],current:e=>c.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>S(e.id,t||null)}:void 0,T=(t,n,r)=>(0,$.jsx)(Yt,{projectId:e,kind:`logo`,files:t,actions:s,accept:`image/*`,addLabel:r?o(`project.logoAdd`):void 0,onUpload:e=>void w(e,n),mainId:x,onMakeMain:e=>{S(e.id,null),s.order(`logo`,[e.id,..._.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:ee,onRemove:e=>{confirm(o(`project.removeConfirm`,{name:e.name}))&&(s.remove(e.id),S(e.id,null))}}),E=n?void 0:e=>t=>S(t,e),D=[{label:o(`project.logoUpload`),icon:(0,$.jsx)(G,{className:`size-4 shrink-0`}),onPick:()=>h.current?.click()},{label:o(`project.logoFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>m(!0)},...c.length<X.logoSections?[{label:o(`project.logoSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>{let e=K();f(e),l(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...u.full?[]:[{label:o(`project.ruleNew`),icon:(0,$.jsx)(He,{className:`size-4 shrink-0`}),onPick:()=>u.add()}]];return(0,$.jsxs)(Y,{title:o(`project.logos`),hint:o(`project.logosHint`),save:g,action:n?null:(0,$.jsx)(q,{entries:D}),children:[(0,$.jsx)(`input`,{ref:h,type:`file`,accept:`image/*`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&w(t,null)}}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(Tn,{onLogo:E?.(null),children:T(b,null,!0)}),c.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(Tn,{onLogo:E?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(Pe,{title:e.title,description:e.description,titlePlaceholder:o(`project.logoSectionTitle`),descriptionPlaceholder:o(`project.logoSectionUse`),autoFocus:d===e.id,readOnly:n,onChange:t=>C(e.id,t),onRemove:()=>{(!e.logos.length||confirm(o(`project.logoSectionRemoveConfirm`,{name:e.title||o(`project.sectionUntitled`)})))&&l(t=>t.filter(t=>t.id!==e.id))}}),T(e.logos.map(e=>v.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),(0,$.jsx)(Me,{rules:u,placeholder:o(`project.logoRulePlaceholder`),readOnly:n})]}),s.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error}):null,p?(0,$.jsx)(Xt,{kind:`logo`,onClose:()=>m(!1),fetchUrl:e=>s.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)S(t.id,null)}}):null]})}var Dn=new Set;function On(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Dn.has(t))return;Dn.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${Re.join(`,`)}&display=swap`,document.head.append(n)},[e])}var kn=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function An({unit:e,label:t,...n}){return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,$.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var jn=`h-8 rounded-md border border-input bg-card px-1.5 text-[0.8125rem] text-ink outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`;function Mn({font:e,first:t,readOnly:n,autoFocus:r,onChange:i,onRemove:a}){return On(e.family),(0,$.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:kn(e.family)},children:[(0,$.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,$.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:e.family}),e.role?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:e.role}):null]}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ft,{value:e.family,label:o(`project.fontFamily`),placeholder:o(`project.fontFamily`),maxLength:80,autoFocus:r,onChange:e=>i({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(ft,{value:e.role,label:o(`project.fontRole`),placeholder:o(t?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>i({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Re.map(t=>{let r=e.weights.includes(t);return(0,$.jsx)(`button`,{type:`button`,disabled:n,"aria-pressed":r,onClick:()=>i({weights:r?e.weights.filter(e=>e!==t):[...e.weights,t].sort((e,t)=>e-t)}),style:{fontFamily:kn(e.family),fontWeight:t},className:u(`h-7 rounded-full px-2.5 text-[0.8125rem] tabular-nums transition`,r?`bg-ink text-paper`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!r&&`hidden`),children:t},t)})}),n?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:a,className:`absolute top-4 right-4 size-8 bg-card opacity-0 shadow-soft transition focus:opacity-100 group-hover/font:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})}function Nn({style:e,fonts:t,sample:n,readOnly:r,autoFocus:i,onChange:a,onRemove:s}){let c=t.find(t=>t.id===e.font)??t[0],l={fontFamily:kn(c?.family),fontWeight:e.weight,fontSize:`${Math.min(e.size,56)}px`,lineHeight:`${e.lineHeight}%`,letterSpacing:`${e.tracking/100}em`,textTransform:e.uppercase?`uppercase`:void 0};return(0,$.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-ink`,style:l,children:n}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,$.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,$.jsx)(`div`,{className:`w-40`,children:(0,$.jsx)(ft,{value:e.name,label:o(`project.styleName`),placeholder:o(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":o(`project.styleFont`),value:c?.id??``,onChange:e=>a({font:e.target.value}),className:u(jn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||o(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":o(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:jn,children:[...new Set([...Re,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(An,{unit:`px`,label:o(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,$.jsx)(An,{unit:o(`project.styleLine`),label:o(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(An,{unit:o(`project.styleTracking`),label:o(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:o(`project.styleUpper`),"aria-label":o(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:u(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,$.jsx)(Ot,{className:`size-4`})})]}),r?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:s,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})}function Pn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{s(!0),l(null);try{let{fonts:t}=await I.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(d(t),p(t.slice(0,2).map(e=>e.family))):l(o(`project.fontsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(P,{open:!0,onClose:n,wide:u?!0:void 0,title:o(u?`project.fontsFound`:`project.fontsFromUrl`),children:u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:o(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map(e=>(0,$.jsx)(Fn,{font:e,on:f.includes(e.family),onToggle:()=>p(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>d(null),children:o(`run.back`)}),(0,$.jsx)(L,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.family))),n()},children:f.length>1?o(`project.addMany`,{n:f.length}):o(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.fontsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:n,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:a,disabled:!r.trim(),children:o(`run.next`)})]})]})})}function Fn({font:e,on:t,onToggle:n}){return On(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:u(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:kn(e.family)},children:`Aa`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):o(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(F,{className:`size-3.5`})}):null]})}function In({projectId:e,fonts:t,styles:n,rules:r,sample:i,save:a,readOnly:s}){let[c,l]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(n),f=De(r),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=Ue({fonts:c,textStyles:u,typeRules:f.rules},a),v=(e,t=!1)=>{let n=e.map(e=>({id:K(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&m(n[0].id),l(e=>[...e,...n].slice(0,X.fonts))},y=()=>{let e=K();m(e),d(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},x=[...c.length<X.fonts?[{label:o(`project.fontNew`),icon:(0,$.jsx)(b,{className:`size-4 shrink-0`}),onPick:()=>v([{family:``,weights:[400,700]}],!0)},{label:o(`project.fontsFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>g(!0)}]:[],...u.length<X.textStyles?[{label:o(`project.styleNew`),icon:(0,$.jsx)(Le,{className:`size-4 shrink-0`}),onPick:y}]:[],...f.full?[]:[{label:o(`project.ruleNew`),icon:(0,$.jsx)(He,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,$.jsxs)(Y,{title:o(`project.typography`),hint:o(`project.typographyHint`),save:_,action:s?null:(0,$.jsx)(q,{entries:x}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[c.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:c.map((e,t)=>(0,$.jsx)(Mn,{font:e,first:t===0,readOnly:s,autoFocus:p===e.id,onChange:t=>l(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>l(t=>t.filter(t=>t.id!==e.id))},e.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`project.fontsEmpty`)}),u.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:o(`project.styles`)}),s?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:o(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:u.map(e=>(0,$.jsx)(Nn,{style:e,fonts:c,sample:i,readOnly:s,autoFocus:p===e.id,onChange:t=>d(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>d(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,(0,$.jsx)(Me,{rules:f,placeholder:o(`project.typeRulePlaceholder`),readOnly:s})]}),h?(0,$.jsx)(Pn,{projectId:e,onClose:()=>g(!1),onAdd:e=>v(e)}):null]})}function Ln({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[i,a]=(0,Q.useState)(e.brand.about??``),s=Ue({name:n.trim(),about:i.trim()},e=>t({brand:e}));return(0,$.jsx)(Y,{title:o(`project.base`),hint:o(`project.baseHint`),save:s,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.title`)}),(0,$.jsx)(k,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.about`)}),(0,$.jsx)(y,{minRows:4,value:i,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.aboutHint`)})]})]})})}function Rn({project:e,group:t,children:n}){let i=r(),a=We(e.id),[s,c]=(0,Q.useState)(0),l=async t=>{await I.patch(`/api/studio/projects/${e.id}`,t),await i.invalidateQueries({queryKey:[`projects`]})},u=dt({mutationFn:()=>I.del(`/api/studio/projects/${e.id}`),onSuccess:()=>i.invalidateQueries({queryKey:[`projects`]})}),d=Ce(),f=Ze(),p=a.data??{files:[],embeddings:!0},m=`${e.id}:${s}`,h=e.readOnly,g=t===`knowledge`;return $e(h?{}:{title:o(g?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:o(g?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:o(g?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:g?[{label:o(`assistant.suggest.knowledgeHow`)},{label:o(`assistant.suggest.knowledgeSite`),fill:!0},{label:o(`assistant.suggest.knowledgeCategories`)}]:[{label:o(`assistant.suggest.readSite`),fill:!0},{label:o(`assistant.suggest.missing`)},{label:o(`assistant.suggest.facts`)}],summary:g?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${p.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>c(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[h?(0,$.jsx)(xe,{children:ye(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(J,{id:`base`,children:(0,$.jsx)(Ln,{project:e,save:l},`base:${m}`)}),(0,$.jsx)(J,{id:`facts`,children:(0,$.jsx)(wn,{facts:e.facts,save:e=>l({facts:e}),readOnly:h},`facts:${m}`)}),(0,$.jsx)(J,{id:`logos`,children:(0,$.jsx)(En,{projectId:e.id,data:p,readOnly:h,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],save:e=>l({brand:e})},`logos:${m}`)}),(0,$.jsx)(J,{id:`colors`,children:(0,$.jsx)(bn,{projectId:e.id,data:p,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],save:e=>l({brand:e}),readOnly:h},`colors:${m}`)}),(0,$.jsx)(J,{id:`typography`,children:(0,$.jsx)(In,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],sample:e.brand.name||o(`project.typeSample`),save:e=>l({brand:e}),readOnly:h},`typography:${m}`)}),(0,$.jsx)(J,{id:`assets`,children:(0,$.jsx)(ln,{projectId:e.id,data:p,readOnly:h,sections:e.brand.assetSections??[],save:e=>l({brand:e})},`assets:${m}`)})]}):null,n,t===`info`&&d&&!h&&f?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{variant:`danger`,busy:u.isPending,onClick:()=>confirm(`${o(`settings.delete`)}?`)&&u.mutate(),children:o(`settings.delete`)}),u.error?(0,$.jsx)(`p`,{className:`mt-2 text-[0.875rem] text-rose`,children:u.error.message}):null]}):null]})}var zn={q:``,mode:``,days:0};function Bn(e,t,n){let r=new URLSearchParams;t&&r.set(`wizard`,t),n.q.trim()&&r.set(`q`,n.q.trim()),n.mode&&r.set(`mode`,n.mode),n.days&&r.set(`days`,String(n.days));let a=r.toString();return i({queryKey:[`results`,e,a],queryFn:()=>I.get(`/api/studio/projects/${e}/results${a&&`?${a}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function Vn({filter:e,onFilter:t}){let[n,r]=(0,Q.useState)(e.q);return(0,Q.useEffect)(()=>{if(n===e.q)return;let r=setTimeout(()=>t({...e,q:n}),250);return()=>clearTimeout(r)},[n,e,t]),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,$.jsx)(ze,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(k,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:o(`space.resultsSearch`),"aria-label":o(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(T,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:o(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(T,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:o(`space.resultsAnyTime`)},{value:`1`,label:o(`space.resultsDay`)},{value:`7`,label:o(`space.resultsDays`,{n:7})},{value:`30`,label:o(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function Hn({data:e,wizardId:t,filter:n,onFilter:r}){let[i,a]=(0,Q.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(m,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Y,{title:t?s(t):o(`space.resultsAll`),hint:o(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(Vn,{filter:n,onFilter:r}),e.runs.length?(0,$.jsx)(E,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,o(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:o(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(d,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(O,{children:`Test`}):(0,$.jsxs)(O,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(E,{children:(0,$.jsx)(j,{children:n.q.trim()||n.mode||n.days?o(`space.resultsNone`):o(`space.resultsEmpty`)})})]}),i?(0,$.jsx)(V,{header:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(i.wizardId)}),i.mode===`test`?(0,$.jsx)(O,{children:`Test`}):(0,$.jsxs)(O,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>a(null),children:(0,$.jsx)(St,{runId:i.id,compact:!0},i.id)}):null]})}function Un({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.name),s=dt({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:o(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,$.jsx)(f,{className:`size-4`})}),(0,$.jsx)(P,{open:n,onClose:()=>r(!1),title:o(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&s.mutate()},children:[(0,$.jsx)(k,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),s.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>r(!1),children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:s.isPending,disabled:!i.trim(),children:o(`settings.save`)})]})]})})]})}function Wn({project:e}){let t=r();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(ut,{}),e.readOnly?null:(0,$.jsx)(Un,{project:e,save:async n=>{await I.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function Gn(e){let t=e.join(` `),[n,r]=(0,Q.useState)(e[0]);return(0,Q.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=Je(),i=t.scrollTop>0&&t.clientHeight+t.scrollTop>=t.scrollHeight-4,a=(t===document.documentElement?0:t.getBoundingClientRect().top)+Math.max(120,t.clientHeight/3),o=e[0];for(let t of e){let e=document.getElementById(t)?.getBoundingClientRect().top;e!==void 0&&e<=a&&(o=t)}r(i?e.at(-1):o)},a=()=>{n||=requestAnimationFrame(i)};return i(),window.addEventListener(`scroll`,a,{passive:!0,capture:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,a,{capture:!0}),window.removeEventListener(`resize`,a)}},[t]),n}function Kn(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function qn({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(Z,{icon:e.icon??Be,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(ht,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function Jn(){let{group:e}=_(),[t,n]=s(),r=re(),i=ee(),{hash:a}=i,{project:c,loading:l}=ke(),d=Ce(),f=Qe(),p=xt(),[m,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),x=Ge(e)?e:void 0,S=i.state?.parts===!0,w=nt().map(e=>({...e,to:`/space/${e.id}`})),T=w.find(e=>e.id===x),E=t.get(`show`),D=x?E?2:1:0,O=p?Math.min(D,1):x&&y!==x&&!S?1:0,k=mt(O),A=mt(D),te=(0,Q.useMemo)(()=>({slot:m,narrow:p,setDetail:v}),[m,p]),M=c?c.brand.name?.trim()||c.name:o(`nav.project`),N=x&&x!==`results`?qe(x,f):[],P=x?qe(x,f).filter(e=>e.plugin):[],F=Gn([...N,...x===`results`?P:[]].flatMap(e=>e.sections.map(e=>e.id))),I=x===`results`&&E&&E!==`all`?E:null,[L,ne]=(0,Q.useState)(zn),R=Bn(x===`results`?c?.id:void 0,I,L),ie=R.data?.wizards.find(e=>e.id===I)?.title,z=x===`data`&&E&&E!==`all`||x===`knowledge`&&E&&/^[ptfcvs]:/.test(E)?E:null,B=z?.startsWith(`s:`)?f.spaceSections.find(e=>e.id===z.slice(2)):void 0,V=x===`knowledge`&&z&&/^[ptf]:/.test(z)?z:null,H=se(x===`data`?c?.id:void 0),U=pe(x===`knowledge`?c?.id:void 0),W=ve(z?.startsWith(`v:`)?z.slice(2):``),ye=U.data?.categories.find(e=>e.id===(z?.startsWith(`c:`)?z.slice(2):W.data?.category.id)),be=x===`knowledge`?B?B.label():z?.startsWith(`v:`)?W.data&&`${W.data.category.name}: ${W.data.value}`:z?.startsWith(`c:`)?ye?.name:U.data?.items.find(e=>e.key===z)?.title:H.data?ge(H.data).flatMap(e=>e.items).find(e=>e.key===z)?.title:void 0;Ve([{label:o(`nav.project`),to:`/space`},...T?[{label:T.label,to:`/space/${T.id}`}]:[],...T&&(g??ie??be)?[{label:g??ie??be}]:[]]);let xe={p:`page`,t:`table`,f:`file`,c:`kategorie`,v:`kategorie value`,s:`plugin section`};$e({...x===`data`||x===`results`?{compact:!0}:{},...x===`data`?{suggestions:[{label:o(`assistant.suggest.dataWhat`)},{label:o(`assistant.suggest.dataWho`)},{label:o(`assistant.suggest.dataEdit`)}]}:x===`results`?{suggestions:[{label:o(`assistant.suggest.resultsFailed`)},{label:o(`assistant.suggest.resultsCost`)},{label:o(`assistant.suggest.resultsShare`)}]}:{},...z&&be?{open:{kind:xe[z[0]]??`item`,id:z.slice(2),label:be}}:I&&ie?{open:{kind:`wizard`,id:I,label:ie}}:{}});let G=x===`results`||x===`data`||z?a.slice(1):E||a.slice(1),Se=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${x}#${G}`;G&&Se.current!==e&&document.getElementById(G)&&(Se.current=e,requestAnimationFrame(()=>Kn(G,!1)))},[x,G,c?.id,f.spaceSections]),!x){let t=a.slice(1),n=t?ct(t,f):null;if(n===`knowledge`&&f.spaceSections.some(e=>e.id===t))return(0,$.jsx)(C,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(C,{to:p?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if(t&&f.status!==`ready`)return null;if(e!==void 0||!p)return(0,$.jsx)(C,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(x===`knowledge`&&!E&&f.spaceSections.some(e=>e.id===a.slice(1)))return(0,$.jsx)(C,{to:`/space/knowledge?show=s:${a.slice(1)}`,replace:!0});let we=e=>{if(p){r({search:`?show=${e}`});return}Se.current=`${x}#${e}`,Kn(e,!0),r({search:``,hash:e},{replace:!0})},K=e=>p?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),Te=e=>e.flatMap(e=>e.sections).map(e=>f.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(J,{id:e.id,children:(0,$.jsx)(Y,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(at,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),q=p?void 0:F;return(0,$.jsx)(_t.Provider,{value:te,children:(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`,children:[(0,$.jsxs)(`aside`,{className:u(`min-w-0 md:sticky md:top-6 md:self-start`,p&&D===2&&`hidden`,p&&A===`back`&&pt(`back`)),children:[(0,$.jsx)(gt,{title:M,open:O===1?T??null:null,onBack:()=>p?r(`/space`):b(x??null)}),(0,$.jsx)(`div`,{className:u(pt(k)),children:O===0?(0,$.jsx)(vt,{entries:w,current:p?void 0:T,onPick:()=>b(null)}):(0,$.jsx)(`div`,{ref:h})},O)]}),x?(0,$.jsxs)(`div`,{className:u(`min-w-0`,p&&D<2&&`hidden`,p&&A===`deeper`&&pt(`deeper`)),children:[p?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(bt,{label:T?.label??M,onBack:()=>r(`/space/${x}`)})}):null,d&&c?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(Wn,{project:c})}):null,x===`results`?(0,$.jsxs)(yt,{children:[(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(Z,{icon:Pt,label:o(`space.resultsAll`),selected:!p&&!I,onPick:()=>K(`all`)}),R.data?.wizards.filter(e=>e.results||e.id===I).map(e=>(0,$.jsx)(Z,{icon:Ne,label:e.title,badge:e.results?(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!p&&e.id===I,onPick:()=>K(e.id)},e.id))]}),(0,$.jsx)(qn,{groups:P,current:q,onPick:we})]}):x===`data`?(0,$.jsxs)(yt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(Z,{icon:It,label:o(`data.all`),selected:!p&&!z,onPick:()=>K(`all`)})}),H.data?ge(H.data).map(e=>(0,$.jsx)(ht,{label:e.label,children:e.items.map(e=>(0,$.jsx)(Z,{icon:oe[e.kind],label:e.title,selected:!p&&e.key===z,onPick:()=>K(e.key)},e.key))},e.key)):null,(0,$.jsx)(qn,{groups:P,current:q,onPick:we})]}):x===`knowledge`?(0,$.jsxs)(yt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(Z,{icon:It,label:o(`know.all`),selected:!(p||z),onPick:()=>K(`all`)})}),U.data?.categories.length?(0,$.jsx)(ht,{label:o(`know.categories`),children:U.data.categories.map(e=>(0,$.jsx)(Z,{icon:ue[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!p&&(z===`c:${e.id}`||W.data?.category.id===e.id),onPick:()=>K(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(qn,{groups:P,current:p?void 0:B?.id,onPick:e=>K(`s:${e}`)})]}):(0,$.jsx)(yt,{children:(0,$.jsx)(qn,{groups:N,current:q,onPick:we})}),c&&(x===`info`||x===`knowledge`)?(0,$.jsxs)(Rn,{project:c,group:x,children:[x===`knowledge`?V?V.startsWith(`p:`)?(0,$.jsx)(fe,{pageId:V.slice(2),onGone:()=>K(`all`),onOpen:K},V):V.startsWith(`t:`)?(0,$.jsx)(de,{tableId:V.slice(2),onGone:()=>K(`all`)},V):(0,$.jsx)(tn,{projectId:c.id,fileId:V.slice(2),readOnly:c.readOnly,onGone:()=>K(`all`)},V):U.data?B?(0,$.jsx)(Y,{title:B.label(),hint:B.hint?.(),plain:!0,children:(0,$.jsx)(at,{of:B,children:(0,$.jsx)(B.component,{})})},z):z?.startsWith(`c:`)?ye?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(le,{projectId:c.id,category:ye,readOnly:c.readOnly,onOpen:K,onGone:()=>K(`all`)}),ye.type===`choice`?null:(0,$.jsx)(_e,{projectId:c.id,category:ye,categories:U.data.categories,onOpen:K})]},z):null:z?.startsWith(`v:`)?W.data?(0,$.jsx)(ae,{value:W.data,readOnly:c.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[W.data.items.length?(0,$.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:W.data.items.map(e=>(0,$.jsx)(ce,{item:e,categories:U.data.categories.filter(e=>e.id!==W.data?.category.id),onOpen:K},e.key))}):null,W.data.rows.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>K(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:o(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},z):null:(0,$.jsx)(J,{id:`documents`,children:(0,$.jsx)(he,{projectId:c.id,data:U.data,readOnly:c.readOnly,onOpen:K})}):null:null,x===`info`?Te(P):null]},c.id):null,c&&x===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:z?.startsWith(`t:`)?(0,$.jsx)(de,{tableId:z.slice(2),onGone:()=>K(`all`)},z):z?.startsWith(`p:`)?(0,$.jsx)(fe,{pageId:z.slice(2),onGone:()=>K(`all`)},z):(0,$.jsxs)($.Fragment,{children:[H.data?(0,$.jsx)(me,{projectId:c.id,data:H.data,readOnly:c.readOnly,onOpen:K}):null,Te(P)]})}):null,c&&x===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[R.data?(0,$.jsx)(Hn,{data:R.data,wizardId:I,filter:L,onFilter:ne}):null,R.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:R.error.message}):null,Te(P)]}):null,c||l?null:(0,$.jsx)(j,{children:o(`settings.noProject`)})]}):null]})})})}export{Jn as ProjectPage};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{r}from"./logo-C4V2_3Ar.js";import{At as i,Et as a,Mt as o,Sn as s,_n as c,ht as l,lt as u,m as d,pn as f,u as p,un as m,ut as h,xn as g,xt as _,y as v}from"./ui-DrjXmHdO.js";import{a as y,i as b,n as x,o as S,r as C,s as w,t as T}from"./ChatView-BdYCnDLk.js";import{Bt as ee,Ft as E,It as D,Lt as O,a as k,n as A,o as j}from"./index-DnQgOKOQ.js";import{t as M}from"./RunnerView-ii-PP5c-.js";var N={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};N.node;var te=f(N),P={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};P.node;var F=f(P),I={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};I.node;var L=f(I),R=e(t(),1);function ne(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var z=ne(),re=z?new URLSearchParams(window.location.search).get(`page`):null,B=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),ie=()=>B(`close`);function ae(e){(0,R.useEffect)(()=>{if(z===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>B(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(z===`modal`||z===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&B(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var V=e(n(),1);function H(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function U(e,t){(0,R.useEffect)(()=>{if(!e||!t)return;let n=v(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var W=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,G=W||/Android/.test(navigator.userAgent);function K(){let[e,t]=(0,R.useState)(()=>window.wizardInstall??null),[n,r]=(0,R.useState)(!1);if((0,R.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||G&&!e&&!W)return null;let a=/Mac/.test(navigator.platform),o=i(G?`install.ios`:a?`install.bookmark.mac`:`install.bookmark.pc`);return(0,V.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{G&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[G?(0,V.jsx)(L,{className:`size-4`}):(0,V.jsx)(te,{className:`size-4`}),i(G?`install.add`:`install.bookmark`)]}),n?(0,V.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:o}):null]})}function q({brand:e,toggle:t=!0}){return(0,V.jsx)(`header`,{className:`safe-top`,children:(0,V.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,V.jsx)(`img`,{src:v(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,V.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,V.jsx)(`div`,{className:`absolute right-3`,children:(0,V.jsx)(O,{})}):null]})})}function J({siteKey:e,onToken:t}){let n=(0,R.useRef)(null);return(0,R.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,V.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function oe({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||A||z?null:(0,V.jsxs)(`a`,{href:k(`${window.location.origin}${d}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,V.jsx)(F,{className:`size-4`}),` `,i(`install.app`)]})}var Y=e=>`wz.run.${e}`,X=A&&new URLSearchParams(window.location.search).get(`start`)===`1`,Z=z===`inline`?`min-h-80`:`min-h-dvh`;function Q(e,t){let n=g(),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),l=(()=>{try{return localStorage.getItem(Y(e.token))}catch{return null}})();return{busy:r,error:a,captcha:s,setCaptcha:c,start:async()=>{i(!0),o(null);try{let{runId:r}=await p.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:s??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(Y(e.token),r)}catch{}n(`${t}/${r}`,{replace:X})}catch(e){o(e.message),i(!1)}},resume:l?()=>n(`${t}/${l}`):null}}function se({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:a,start:o,resume:s}=Q(e,`/w/${e.token}`),c=X&&e.available&&!e.turnstileSiteKey,l=(0,R.useRef)(!1);return(0,R.useEffect)(()=>{c&&!l.current&&(l.current=!0,o())},[c]),c&&!n?(0,V.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,V.jsx)(_,{})}):(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,V.jsx)(D,{kind:e.avatar,size:190,fluffy:!0}),(0,V.jsx)(`h1`,{className:`mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,V.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(h,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:o,children:[i(`run.start`),` `,(0,V.jsx)(m,{className:`size-4`})]}),e.turnstileSiteKey?(0,V.jsx)(J,{siteKey:e.turnstileSiteKey,onToken:a}):null,s?(0,V.jsx)(`button`,{type:`button`,onClick:s,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:i(`run.resume`)}):null,(0,V.jsx)(ce,{wizard:e,current:`steps`}),z||A?null:(0,V.jsx)(K,{}),(0,V.jsx)(oe,{token:e.token})]}):(0,V.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??i(`run.unavailable`)}),n?(0,V.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,V.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,V.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:i(`run.orAs`,{label:e.label})},e.id))}):null}function le({wizard:e}){let t=w();return(0,V.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,V.jsx)(`span`,{className:a(t?.speaking&&`animate-breathe`),children:(0,V.jsx)(D,{kind:e.avatar,size:38})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,V.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,V.jsx)(`img`,{src:v(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,V.jsx)(O,{}),z===`popout`?(0,V.jsx)(l,{label:i(`common.close`),onClick:ie,children:(0,V.jsx)(o,{className:`size-5`})}):null]})})}function $({door:e,wizard:t,header:n,footer:r}){let{busy:a,error:o,captcha:s,setCaptcha:c,start:l,resume:u}=Q(t,`/w/${t.token}/${e}`),d=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&d.push({key:e,who:`bot`,node:i(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||d.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??i(`run.unavailable`)}),o&&d.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&d.push(S(`start`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(b,{primary:!0,busy:a,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[i(`run.start`),` `,(0,V.jsx)(m,{className:`size-4`})]}),u?(0,V.jsx)(b,{onClick:u,children:i(`run.resume`)}):null,t.turnstileSiteKey?(0,V.jsx)(J,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,V.jsxs)(x,{header:n,footer:r,children:[(0,V.jsx)(y,{avatar:t.avatar,lines:d}),(0,V.jsx)(C,{})]})}function ue({className:e}){return(0,V.jsx)(`footer`,{className:a(`text-center text-ink-4`,e),children:(0,V.jsx)(`a`,{href:`${d}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:i(`run.madeWith`).replace(`engenty wizards`,E.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:o=!1}){let{token:l,runId:f}=s(),m=g(),v=r({queryKey:[`public`,l],queryFn:()=>p.get(`/api/public/wizards/${l}`),retry:(e,t)=>u(t)&&e<3}),y=v.data?.runners??[],b=!v.data||y.some(e=>e.id===`talk`),x=!v.data||y.some(e=>e.id===`video`),S=!v.data||y.some(e=>e.id===`chat`)||n&&b||o&&x,C=y[0]?.id,w=e||z===`popout`||!t&&!f&&S&&(C===`chat`||C===`talk`||C===`video`),O=o&&x||!t&&!e&&!n&&C===`video`,k=!O&&(n&&b||!t&&!e&&C===`talk`),N=O?`video`:k?`talk`:`chat`;if(H(v.data?.brand.accent),ee(v.data?.avatar),U(l,v.data?.title),ae(w),(0,R.useEffect)(()=>{v.data&&(document.title=v.data.title)},[v.data]),(0,R.useEffect)(()=>{l&&f&&j(`run`,{token:l,runId:f})},[l,f]),v.isLoading)return(0,V.jsx)(`div`,{className:a(`flex items-center justify-center text-ink-4`,Z),children:(0,V.jsx)(_,{})});if(e&&v.data&&!S||n&&v.data&&!b||o&&v.data&&!x)return(0,V.jsx)(c,{to:`/w/${l}`,replace:!0});if(!v.data){let e=u(v.error);return(0,V.jsxs)(`div`,{className:a(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Z),children:[(0,V.jsx)(D,{kind:`pebble`,size:80}),(0,V.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:i(e?`common.offline`:`run.notFound`)}),e?(0,V.jsx)(h,{variant:`secondary`,onClick:()=>void v.refetch(),children:i(`common.retry`)}):null]})}if(w){let e=(0,V.jsx)(le,{wizard:v.data}),t=A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,V.jsx)(`div`,{className:`flex h-dvh flex-col`,children:f?(0,V.jsx)(T,{runId:f,talk:k,call:O?`video`:k?`audio`:!1,onRestart:()=>m(`/w/${l}/${N}`),header:O||k?void 0:e,footer:t}):(0,V.jsx)($,{wizard:v.data,header:e,footer:t,door:N})})}return(0,V.jsxs)(`div`,{className:a(`flex flex-col`,Z),children:[z===`inline`||A?null:(0,V.jsx)(q,{brand:v.data.brand,toggle:!z}),(0,V.jsx)(`div`,{className:`flex-1`,children:f?(0,V.jsx)(M,{runId:f,onRestart:()=>m(`/w/${l}`)}):(0,V.jsx)(se,{wizard:v.data})}),A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,V.jsx)(`a`,{href:`${d}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:i(`run.madeWith`).replace(`engenty wizards`,E.name)})})]})}export{q as BrandHeader,de as PublicRunner,H as useBrandAccent};
@@ -1,4 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{At as a,Ct as o,E as s,Et as c,Gt as l,Jt as u,Mt as d,Ot as f,Pt as p,Qt as m,Tt as h,Vt as g,_t as _,bt as v,ct as y,dt as b,ft as x,gt as S,ht as C,in as w,mt as T,on as E,pn as D,pt as O,sn as k,u as A,ut as j,xt as M,yt as N,zt as P}from"./ui-DrjXmHdO.js";import{t as ee}from"./upload-CDxTpAqx.js";import{Gt as te,H as ne,R as re,U as F,Wt as ie,at as ae,it as I,ot as oe,vn as L}from"./index-DnQgOKOQ.js";var se={name:`calendar`,size:24,node:[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};se.node;var ce=D(se),le={name:`files`,size:24,node:[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]};le.node;var ue=D(le),de={name:`hash`,size:24,node:[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]};de.node;var fe=D(de),R={name:`list-ordered`,size:24,node:[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]};R.node;var pe=D(R),z={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};z.node;var B=D(z),V={name:`minimize-2`,size:24,node:[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]};V.node;var me=D(V),he={name:`tags`,size:24,node:[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]};he.node;var ge=D(he),_e={name:`toggle-left`,size:24,node:[[`circle`,{cx:`9`,cy:`12`,r:`3`,key:`u3jwor`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]};_e.node;var H=D(_e),U=e(t(),1),W=e(n(),1),G={choice:ge,date:ce,number:fe,text:ie,boolean:H},K=e=>[`knowledge`,e];function ve(e){return e===1?a(`know.item`):a(`know.items`,{n:e})}function q(e,t){if(e.type===`boolean`||typeof t==`boolean`)return a(t?`know.yes`:`know.no`);if(e.type===`date`&&typeof t==`string`){let[e,n]=t.split(` `),r=new Date(`${e}T00:00:00`),i=Number.isNaN(r.getTime())?t:r.toLocaleDateString(f,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(f)}${e.unit?` ${e.unit}`:``}`:String(t)}function ye(e,t){return e.flatMap(e=>{let n=t.find(t=>t.categoryId===e.id);return n?e.type===`boolean`?n.values[0]===!0?[e.name]:[]:[n.values.map(t=>q(e,t)).join(`, `)]:[]}).join(` · `)}function be({trigger:e,open:t,onOpen:n,children:r}){let i=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t)return;let e=e=>{i.current?.contains(e.target)||n(!1)},r=e=>e.key===`Escape`&&n(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,r)}},[t,n]),(0,W.jsxs)(`div`,{ref:i,className:`relative inline-flex`,children:[e,t?(0,W.jsx)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:r}):null]})}function xe({category:e,current:t,onSave:n}){let[r,i]=(0,U.useState)(t[0]===void 0?``:String(t[0]));if(e.type===`choice`){let o=t.map(String);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[e.values.length?(0,W.jsx)(N,{multi:!0,value:o,options:e.values.map(e=>e.value),onChange:t=>n(e.multiple?t:t.filter(e=>!o.includes(e)).slice(0,1))}):null,(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),r.trim()&&n(e.multiple?[...o,r.trim()]:[r.trim()])},children:[(0,W.jsx)(S,{"data-autofocus":!0,value:o.includes(r)?``:r,placeholder:a(`know.addValue`),onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(C,{label:a(`know.addValue`),type:`submit`,children:(0,W.jsx)(g,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,W.jsx)(N,{value:t[0]===!0?a(`know.yes`):t[0]===!1?a(`know.no`):``,options:[a(`know.yes`),a(`know.no`)],onChange:e=>n([e===a(`know.yes`)])}):(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(r.trim()?[e.type===`number`?Number(r.replace(`,`,`.`)):r.trim()]:[])},children:[(0,W.jsx)(S,{"data-autofocus":!0,type:e.type===`date`?`date`:e.type===`number`?`number`:`text`,step:`any`,value:e.type===`date`?r.slice(0,10):r,onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(j,{type:`submit`,size:`sm`,children:`OK`})]})}function Se({projectId:e,itemKey:t,has:n,categories:i,readOnly:o}){let s=r(),[c,l]=(0,U.useState)(null),[u,f]=(0,U.useState)(n);(0,U.useEffect)(()=>f(n),[n]);let p=L({mutationFn:({categoryId:n,next:r})=>A.put(`/api/studio/projects/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>s.invalidateQueries({queryKey:K(e)})}),m=i.filter(e=>!(e.proposed||e.tableId)),h=(e,t)=>{f(n=>[...n.filter(t=>t.categoryId!==e.id),...t.length?[{categoryId:e.id,values:t,by:`person`}]:[]]),p.mutate({categoryId:e.id,next:t}),l(null)},_=m.filter(e=>u.some(t=>t.categoryId===e.id)),v=m.filter(e=>!u.some(t=>t.categoryId===e.id));return m.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[_.map(e=>{let t=u.find(t=>t.categoryId===e.id),n=G[e.type],r=(0,W.jsxs)(`button`,{type:`button`,disabled:o,title:`${e.name} · ${a(`know.by.${t.by}`)}`,onClick:()=>l(c===e.id?null:e.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink disabled:pointer-events-none`,children:[(0,W.jsx)(n,{className:`size-3.5 text-ink-3`}),(0,W.jsx)(`span`,{className:`text-ink-3`,children:e.name}),(0,W.jsx)(`span`,{className:`font-medium`,children:t.values.map(t=>q(e,t)).join(`, `)})]},e.id);return o?(0,W.jsx)(`span`,{children:r},e.id):(0,W.jsxs)(be,{trigger:r,open:c===e.id,onOpen:t=>l(t?e.id:null),children:[(0,W.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:e.name}),(0,W.jsx)(C,{label:a(`know.remove`),onClick:()=>h(e,[]),className:`size-7`,children:(0,W.jsx)(d,{className:`size-3.5`})})]}),(0,W.jsx)(xe,{category:e,current:t.values,onSave:t=>h(e,t)})]},e.id)}),o||!v.length?null:(0,W.jsx)(be,{open:c===`+`,onOpen:e=>l(e?`+`:null),trigger:(0,W.jsxs)(`button`,{type:`button`,onClick:()=>l(c===`+`?null:`+`),className:`inline-flex h-7 items-center gap-1 rounded-full px-2 text-[0.75rem] text-ink-3 ring-1 ring-border-soft transition hover:text-ink hover:ring-border`,children:[(0,W.jsx)(g,{className:`size-3.5`}),` `,a(`know.category`)]}),children:(0,W.jsx)(Ce,{categories:v,onSave:h})})]}):null}function Ce({categories:e,onSave:t}){let[n,r]=(0,U.useState)(e[0]?.id??``),i=e.find(e=>e.id===n);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,W.jsx)(v,{value:n,onChange:r,options:e.map(e=>({value:e.id,label:e.name}))}),i?(0,W.jsx)(xe,{category:i,current:[],onSave:e=>t(i,e)},i.id):null]})}function we({projectId:e,open:t,onClose:n,onMade:i}){let s=r(),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(`choice`),[f,p]=(0,U.useState)(``),[m,g]=(0,U.useState)(!1),[y,b]=(0,U.useState)(!1),[x,C]=(0,U.useState)(``),[w,T]=(0,U.useState)(``),E=L({mutationFn:()=>A.post(`/api/studio/projects/${e}/categories`,{name:c.trim(),type:u,unit:u===`number`&&f.trim()||null,multiple:u===`choice`&&m,ordered:u===`choice`&&y,hint:w.trim()||null,values:u===`choice`?x.split(`
2
- `).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await s.invalidateQueries({queryKey:K(e)}),l(``),C(``),T(``),i(t)}});return(0,W.jsx)(O,{open:t,onClose:n,title:a(`know.newCategory`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),c.trim()&&E.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`know.name`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:c,maxLength:80,onChange:e=>l(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`know.type`)}),(0,W.jsx)(v,{value:u,onChange:e=>d(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:a(`know.type.${e}`)}))})]}),u===`number`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{hint:a(`know.unitHint`),children:a(`know.unit`)}),(0,W.jsx)(S,{value:f,maxLength:20,onChange:e=>p(e.target.value)})]}):null,u===`choice`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{hint:a(`know.valuesHint`),children:a(`know.values`)}),(0,W.jsx)(h,{minRows:3,value:x,onChange:e=>C(e.target.value)})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[a(`know.multiple`),(0,W.jsx)(o,{checked:m,onChange:g})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[a(`know.ordered`),(0,W.jsx)(o,{checked:y,onChange:b})]})]}):null,(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{hint:a(`know.hintFieldHint`),children:a(`know.hintField`)}),(0,W.jsx)(S,{value:w,maxLength:120,onChange:e=>T(e.target.value)})]}),E.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:E.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(j,{variant:`ghost`,onClick:n,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:E.isPending,disabled:!c.trim(),children:a(`know.create`)})]})]})})}function Te({projectId:e,category:t,readOnly:n,onOpen:i,onGone:o}){let s=r(),c=()=>s.invalidateQueries({queryKey:K(e)}),[l,u]=(0,U.useState)(``),d=L({mutationFn:e=>e(),onSuccess:c}),f=G[t.type],m=new Map(t.values.map(e=>[e.id,e]));return(0,W.jsxs)(F,{title:t.name,hint:[a(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,W.jsx)(C,{label:a(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(a(`know.confirmCategory`,{name:t.name}))&&d.mutate(async()=>{await A.del(`/api/studio/categories/${t.id}`),o()}),children:(0,W.jsx)(p,{className:`size-4`})}),children:[t.proposed&&!n?(0,W.jsxs)(b,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(x,{tone:`ember`,children:a(`know.proposed`)}),(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:a(`know.proposedHint`)}),(0,W.jsx)(j,{size:`sm`,onClick:()=>d.mutate(()=>A.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:a(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=m.get(e),i=m.get(t);if(!(r&&i))return null;let[o,s]=r.count<i.count?[r,i]:[i,r];return(0,W.jsxs)(b,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:a(`know.alike`,{a:o.value,b:s.value})}),n?null:(0,W.jsx)(j,{size:`sm`,variant:`secondary`,busy:d.isPending,onClick:()=>d.mutate(()=>A.post(`/api/studio/values/${o.id}/merge`,{into:s.id})),children:a(`know.merge`)})]},`${e}:${t}`)}),(0,W.jsxs)(b,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(`v:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,W.jsx)(x,{children:a(`know.summary`)}):null,(0,W.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:ve(e.count)})]},e.id)):(0,W.jsx)(T,{children:a(`know.empty`)}):(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,W.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?a(`know.range`,{min:q(t,t.range.min),max:q(t,t.range.max)}):a(`know.unset`)}),(0,W.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:ve(t.count)})]}),t.type===`choice`&&!n?(0,W.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=l.trim();n&&(u(``),d.mutate(()=>A.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,W.jsx)(S,{value:l,placeholder:a(`know.addValue`),onChange:e=>u(e.target.value),className:`h-9`}),(0,W.jsx)(C,{label:a(`know.addValue`),type:`submit`,children:(0,W.jsx)(g,{className:`size-4`})})]}):null]}),d.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null]})}function Ee(e){return i({queryKey:[`knowledge-value`,e],queryFn:()=>A.get(`/api/studio/values/${e}`),enabled:!!e})}function De({value:e,readOnly:t,children:n}){let i=r(),o=L({mutationFn:()=>A.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>i.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,W.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,W.jsx)(F,{title:a(`know.summary`),hint:a(`know.summaryHint`),plain:!0,action:t?null:(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,busy:o.isPending,onClick:()=>o.mutate(),children:[e.summary?(0,W.jsx)(P,{className:`size-4`}):null,e.summary?a(`know.summaryAgain`):a(`know.summaryWrite`)]}),children:(0,W.jsxs)(b,{className:`p-4 sm:p-5`,children:[o.isPending?(0,W.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,W.jsx)(M,{})}):e.summary?(0,W.jsx)(s,{text:e.summary,className:`text-[0.875rem]`}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:a(`know.summaryEmpty`)}),o.error?(0,W.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null]})}),(0,W.jsx)(F,{title:a(`know.toc`),plain:!0,children:n})]})}function Oe(e){return i({queryKey:[`knowledge`,e],queryFn:()=>A.get(`/api/studio/projects/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function ke(e){return e.kind===`table`?e.format===`faq`?B:te:e.kind===`file`?l:e.children?ue:m}function J({item:e,categories:t,onOpen:n}){let r=ke(e),i=[ye(t,e.categories),e.children?e.children===1?a(`know.oneSub`):a(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?a(`know.row`):a(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e.key),disabled:e.status===`pending`,className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,W.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,W.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,W.jsx)(M,{className:`size-3`}),` `,a(`know.reading`)]}):e.review?(0,W.jsx)(x,{tone:`warn`,title:e.review,children:a(`know.review`)}):null]})}function Y({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:o,file:s,readOnly:c,onReviewed:u}){let d=Oe(e),f=[r?a(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[d.data?(0,W.jsx)(Se,{projectId:e,itemKey:t,has:n,categories:d.data.categories,readOnly:c}):null,f.length||s||o?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.8125rem] text-ink-3`,children:[f.map(e=>(0,W.jsx)(`span`,{children:e},e)),s?(0,W.jsxs)(`a`,{href:I(e,s.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,W.jsx)(l,{className:`size-3.5`}),` `,a(`know.original`),`: `,s.name]}):null,o?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(x,{tone:`warn`,children:a(`know.review`)}),(0,W.jsx)(`span`,{children:o}),c?null:(0,W.jsx)(`button`,{type:`button`,onClick:u,className:`underline hover:text-ink`,children:a(`know.reviewed`)})]}):null]}):null]})}function Ae(e){let t=e.filter(Number.isFinite).sort((e,t)=>e-t);if(new Set(t).size<=4)return[];let n=t[0],r=t.at(-1),i=e=>e.slice(0,-1).map((t,n)=>({lo:t,hi:e[n+1]})).filter(e=>t.some(t=>t>=e.lo&&t<e.hi));if(n>0&&r/n>=30){let e=Math.floor(Math.log10(n)),t=Math.floor(Math.log10(r))+1;for(let a of[[1,2,5],[1,3],[1]]){let o=[];for(let n=e;n<=t;n++)for(let e of a)o.push(e*10**n);let s=i(o.filter((e,t)=>e<=n||o[t-1]<=r));if(s.length<=7)return s}}let a=(r-n)/5,o=10**Math.floor(Math.log10(a)),s=([1,2,2.5,5,10].map(e=>e*o).find(e=>e>=a)??a)||1,c=[];for(let e=Math.floor(n/s)*s;e<=r;e+=s)c.push(e);return c.push(c.at(-1)+s),i(c)}function je({projectId:e,category:t,categories:n,onOpen:r}){let o=i({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>A.get(`/api/studio/categories/${t.id}/items`)});if(!o.data)return o.isLoading?(0,W.jsx)(M,{className:`mx-auto size-4 text-ink-3`}):null;let s=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],c=[...o.data.items].sort((e,t)=>{let n=s(e),r=s(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),f)}),l=t.type===`number`?Ae(c.map(s).filter(e=>typeof e==`number`)):[],u=new Intl.NumberFormat(f,{notation:`compact`,maximumFractionDigits:1}),d=t.unit?` ${t.unit}`:``,p=new Map;for(let e of c){let n=s(e),r=typeof n==`number`?l.find(e=>n>=e.lo&&n<e.hi):void 0,i=n===void 0?``:t.type===`date`?new Date(`${String(n).slice(0,7)}-01T00:00:00`).toLocaleDateString(f,{month:`long`,year:`numeric`}):r?a(`know.range`,{min:`${u.format(r.lo)}${d}`,max:`${u.format(r.hi)}${d}`}):q(t,n);p.set(i,[...p.get(i)??[],e])}return(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...p].map(([e,t])=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,W.jsx)(J,{item:e,categories:n,onOpen:r},e.key))})]},e)),o.data.rows.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>r(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:a(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function Me(e,t,n){return Array.isArray(n)?t.some(e=>n.map(String).includes(String(e))):typeof n==`object`&&n?t.some(t=>{if(e.type===`number`&&typeof t==`number`)return(n.gte===void 0||t>=n.gte)&&(n.lte===void 0||t<=n.lte);if(e.type===`date`){let e=String(t).slice(0,10);return(!n.after||e>=n.after)&&(!n.before||e<=n.before)}return!n.contains||String(t).toLowerCase().includes(n.contains.toLowerCase())}):t.some(e=>e===n)}function Ne(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return a(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${a(`know.contains`)} ${t.contains}`:[n===void 0?``:`${a(`know.minimum`)} ${q(e,n)}`,r===void 0?``:`${a(`know.maximum`)} ${q(e,r)}`].filter(Boolean).join(` `)}return String(t)}function Pe({category:e,value:t,onChange:n}){let[r,i]=(0,U.useState)(!1),o=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!r)return;let e=e=>!o.current?.contains(e.target)&&i(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]);let s=G[e.type],l=typeof t==`object`&&t&&!Array.isArray(t)?t:{},u=(t,r)=>{let i={...l,[t]:r===``?void 0:e.type===`number`?Number(r):r},a=Object.fromEntries(Object.entries(i).filter(([,e])=>e!==void 0));n(Object.keys(a).length?a:void 0)};return(0,W.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:c(`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-[0.8125rem] transition`,t===void 0?`text-ink-2 ring-1 ring-border-soft hover:ring-border`:`bg-ember-tint text-ink ring-1 ring-ember/30`),children:[(0,W.jsx)(s,{className:`size-3.5 text-ink-3`}),e.name,t===void 0?null:(0,W.jsxs)(`span`,{className:`font-medium`,children:[`: `,Ne(e,t)]}),(0,W.jsx)(E,{className:`size-3.5 text-ink-3`})]}),r?(0,W.jsxs)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:[e.type===`choice`?(0,W.jsx)(N,{multi:!0,value:Array.isArray(t)?t.map(String):[],options:e.values.map(e=>e.value),onChange:e=>n(e.length?e:void 0)}):e.type===`boolean`?(0,W.jsx)(N,{value:t===!0?a(`know.yes`):t===!1?a(`know.no`):``,options:[a(`know.yes`),a(`know.no`)],onChange:e=>n(e===a(`know.yes`))}):e.type===`text`?(0,W.jsx)(S,{"data-autofocus":!0,value:l.contains??``,placeholder:a(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:`h-9`}):(0,W.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(n===0?`know.minimum`:`know.maximum`)}),(0,W.jsx)(S,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(l[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>u(t,e.target.value),className:`h-9`})]},t))}),t===void 0?null:(0,W.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),i(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:a(`know.clear`)})]}):null]})}function Fe({found:e,onOpen:t}){return e.hits.length?(0,W.jsxs)(`div`,{className:`flex flex-col`,children:[(0,W.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:e.checked?a(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):a(`know.searchUnchecked`,{hits:e.hits.length})}),e.hits.map(e=>{let n=e.open;return(0,W.jsxs)(`button`,{type:`button`,disabled:!n,onClick:()=>n&&t(n),className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,W.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,W.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,W.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(f,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,W.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:a(`know.searchNone`)})}function Ie({kind:e,projectId:t,onClose:n,onMade:i}){let s=r(),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(!1),f=L({mutationFn:()=>A.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:c.trim(),...e===`table`&&u?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await s.invalidateQueries({queryKey:[`knowledge`,t]}),i(`${e===`table`?`t`:`p`}:${n}`),l(``),d(!1)}});return(0,W.jsx)(O,{open:e!==null,onClose:n,title:a(e===`table`?`know.newTable`:`know.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),c.trim()&&f.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.title`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:c,maxLength:120,onChange:e=>l(e.target.value)})]}),e===`table`?(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[a(`know.asFaq`),(0,W.jsx)(o,{checked:u,onChange:d})]}):null,f.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(j,{variant:`ghost`,onClick:n,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:f.isPending,disabled:!c.trim(),children:a(`know.create`)})]})]})})}function Le({projectId:e,data:t,readOnly:n,onOpen:i}){let o=r(),s=oe(e,n),[c,l]=(0,U.useState)({}),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(!1),[_,v]=(0,U.useState)(null),y=t.categories.filter(e=>!e.proposed&&e.count>0),S=t.categories.filter(e=>e.proposed),C=t.items.filter(e=>Object.entries(c).every(([n,r])=>{let i=t.categories.find(e=>e.name===n),a=e.categories.find(e=>e.categoryId===i?.id);return i&&a?Me(i,a.values,r):!1})),w=async()=>{if(!u.trim()){p(null);return}h(!0);try{p(await A.post(`/api/studio/projects/${e}/search`,{query:u,...Object.keys(c).length?{where:c}:{}}))}catch{p({hits:[],candidates:0,checked:!1,filtered:null})}finally{h(!1)}},E=L({mutationFn:({id:e,keep:t})=>t?A.patch(`/api/studio/categories/${e}`,{proposed:!1}):A.del(`/api/studio/categories/${e}`),onSuccess:()=>o.invalidateQueries({queryKey:[`knowledge`,e]})});return(0,W.jsxs)(F,{title:a(`know.title`),hint:a(`know.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>v(`page`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.page`)]}),(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>v(`table`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.table`)]}),(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>v(`category`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.category`)]})]}),children:[S.length&&!n?(0,W.jsx)(b,{className:`flex flex-col gap-2 p-4`,children:S.map(e=>{let t=G[e.type];return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,W.jsx)(x,{tone:`ember`,children:a(`know.proposed`)}),(0,W.jsx)(t,{className:`size-4 text-ink-3`}),(0,W.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[a(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,W.jsx)(j,{size:`sm`,variant:`ghost`,onClick:()=>E.mutate({id:e.id,keep:!1}),children:a(`know.dismiss`)}),(0,W.jsx)(j,{size:`sm`,onClick:()=>E.mutate({id:e.id,keep:!0}),children:a(`know.accept`)})]},e.id)})}):null,t.items.length?(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsx)(ne,{value:u,placeholder:a(`know.search`),busy:m,onEnter:()=>void w(),onChange:e=>{d(e),e.trim()||p(null)}}),y.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[y.map(e=>(0,W.jsx)(Pe,{category:e,value:c[e.name],onChange:t=>{p(null),l(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),Object.keys(c).length?(0,W.jsx)(`button`,{type:`button`,onClick:()=>l({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:a(`know.clear`)}):null]}):null]}):null,(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:f?(0,W.jsx)(Fe,{found:f,onOpen:i}):C.length?C.map(e=>(0,W.jsx)(J,{item:e,categories:t.categories,onOpen:i},e.key)):(0,W.jsx)(T,{children:a(`know.empty`)})}),n?null:(0,W.jsxs)(re,{accept:`.pdf,.docx,.doc,.xlsx,.csv,.tsv,.txt,.md,.json,.html,.eml,image/*`,onFiles:async t=>{await s.upload(`document`,t),await o.invalidateQueries({queryKey:[`knowledge`,e]})},className:`h-14 w-full`,children:[s.busy?(0,W.jsx)(M,{className:`size-4`}):(0,W.jsx)(ee,{className:`size-4`}),a(`know.drop`),` `,(0,W.jsx)(`span`,{className:`underline`,children:a(`know.pick`)})]}),s.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,W.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:a(`know.keywordsOnly`),t.checked?``:a(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,W.jsx)(Ie,{kind:_===`page`||_===`table`?_:null,projectId:e,onClose:()=>v(null),onMade:e=>{v(null),i(e)}}),(0,W.jsx)(we,{projectId:e,open:_===`category`,onClose:()=>v(null),onMade:e=>{v(null),i(`c:${e}`)}})]})}function Re({page:e,onGone:t,onOpen:n}){let i=r(),[o,l]=(0,U.useState)(e.title),[u,d]=(0,U.useState)(e.markdown),[f,h]=(0,U.useState)(e.markdown?`read`:`write`),_=e.knowledge,v=async()=>{await i.invalidateQueries({queryKey:[`space-data`,e.projectId]}),await i.invalidateQueries({queryKey:[`knowledge`,e.projectId]})},y=ae({title:o.trim()||e.title,markdown:u},async t=>{await A.patch(`/api/studio/pages/${e.id}`,t),i.setQueryData([`space-page`,e.id],e=>e&&{...e,...t}),t.title!==e.title&&await v()}),x=L({mutationFn:()=>A.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await v(),t()}}),S=L({mutationFn:()=>A.post(`/api/studio/projects/${e.projectId}/pages`,{title:a(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await v(),n?.(`p:${e}`)}}),T=L({mutationFn:()=>A.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>i.invalidateQueries({queryKey:[`space-page`,e.id]})}),E=async t=>{let r=t.target.closest(`a`)?.getAttribute(`href`);if(!(r?.startsWith(`pages/`)&&n))return;t.preventDefault();let i=await A.get(`/api/studio/projects/${e.projectId}/resolve?path=${encodeURIComponent(r)}`).catch(()=>null);i?.kind===`page`&&n(`p:${i.id}`)},D=e.readOnly,O=_?.file&&(_.file.mime===`application/pdf`||_.file.mime.startsWith(`image/`))?_.file:null,N=(e,t)=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>h(e),className:c(`rounded-full px-3 py-1 text-[0.8125rem] transition`,f===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[_?.parents.length&&n?(0,W.jsx)(`nav`,{className:`-mb-1.5 flex flex-wrap items-center gap-1 px-1 text-[0.8125rem] text-ink-3`,children:_.parents.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`hover:text-ink`,children:e.title}),(0,W.jsx)(w,{className:`size-3.5`})]},e.id))}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:o,disabled:D,maxLength:200,onChange:e=>l(e.target.value),"aria-label":a(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),y.state===`saving`?(0,W.jsx)(M,{className:`size-3.5 text-ink-3`}):y.state===`saved`?(0,W.jsx)(k,{className:`size-4 text-moss`,"aria-label":a(`settings.saved`)}):null,D?null:(0,W.jsx)(C,{label:a(`data.deletePage`),onClick:()=>confirm(a(`data.confirmDelete`,{title:e.title}))&&x.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(p,{className:`size-4`})})]}),_?(0,W.jsx)(Y,{projectId:e.projectId,itemKey:`p:${e.id}`,has:_.categories,originLabel:_.originLabel,kept:_.kept,review:_.review,file:O?null:_.file,readOnly:D,onReviewed:()=>T.mutate()}):null,(0,W.jsxs)(b,{className:`flex flex-col`,children:[D&&!O?null:(0,W.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[D?null:N(`write`,a(`data.write`)),N(`read`,a(`data.preview`)),O?N(`original`,a(`know.original`)):null,(0,W.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:f===`original`&&O?O.name:a(`data.markdownHint`)})]}),f===`original`&&O?O.mime===`application/pdf`?(0,W.jsx)(`iframe`,{src:I(e.projectId,O.id),title:O.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,W.jsx)(`img`,{src:I(e.projectId,O.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):f===`write`&&!D?(0,W.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),"aria-label":e.title,placeholder:a(`data.pageEmpty`),className:`field-sizing-content min-h-[50vh] w-full resize-none bg-transparent p-4 font-mono text-[0.8125rem] leading-relaxed outline-none placeholder:text-ink-4 sm:p-5`}):(0,W.jsx)(`div`,{className:`min-h-40 p-4 sm:p-5`,onClick:E,children:u.trim()?(0,W.jsx)(s,{text:u}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:a(`data.pageEmpty`)})})]}),y.state===`error`&&y.error?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:y.error}):null,_&&n&&(_.children.length||!D)?(0,W.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,W.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:_.children.length?a(`know.subPages`):null}),D?null:(0,W.jsxs)(j,{variant:`ghost`,size:`sm`,busy:S.isPending,onClick:()=>S.mutate(),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.addSub`)]})]}),_.children.length?(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:_.children.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left transition hover:bg-accent`,children:[(0,W.jsx)(m,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title})]},e.id))}):null]}):null]})}function ze({pageId:e,onGone:t,onOpen:n}){let r=i({queryKey:[`space-page`,e],queryFn:()=>A.get(`/api/studio/pages/${e}`),refetchOnWindowFocus:!1});return r.data?(0,W.jsx)(Re,{page:r.data,onGone:t,onOpen:n},r.data.id):r.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:r.error.message}):null}function Be(e){return i({queryKey:[`space-data`,e],queryFn:()=>A.get(`/api/studio/projects/${e}/data`),enabled:!!e})}function Ve(e){let t=t=>[...e.tables.filter(e=>e.wizardId===t).map(e=>({key:`t:${e.id}`,kind:`table`,title:e.title,rows:e.rows})),...e.pages.filter(e=>e.wizardId===t).map(e=>({key:`p:${e.id}`,kind:`page`,title:e.title}))];return[{key:`own`,label:a(`data.own`),items:t(null)},...e.wizards.map(e=>({key:e.id,label:e.title,items:t(e.id)}))].filter(e=>e.items.length)}var He={table:te,page:m};function Ue({kind:e,projectId:t,data:n,onClose:i,onMade:o}){let s=r(),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(``),f=L({mutationFn:()=>A.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:c.trim(),wizardId:u||null}),onSuccess:async({id:n})=>{await s.invalidateQueries({queryKey:[`space-data`,t]}),o(`${e===`table`?`t`:`p`}:${n}`),l(``),d(``)}});return(0,W.jsx)(O,{open:e!==null,onClose:i,title:a(e===`table`?`data.newTable`:`data.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),c.trim()&&f.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.title`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:c,maxLength:120,onChange:e=>l(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.owner`)}),(0,W.jsx)(v,{value:u,onChange:d,options:[{value:``,label:a(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),f.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(j,{variant:`ghost`,onClick:i,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:f.isPending,disabled:!c.trim(),children:a(`data.create`)})]})]})})}function We({projectId:e,data:t,readOnly:n,onOpen:r}){let[i,o]=(0,U.useState)(null),s=Ve(t),c=new Map([...t.tables.map(e=>[`t:${e.id}`,e.updatedAt]),...t.pages.map(e=>[`p:${e.id}`,e.updatedAt])]),l=new Intl.DateTimeFormat(f,{dateStyle:`medium`});return(0,W.jsxs)(F,{title:a(`space.data`),hint:a(`data.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>o(`table`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`data.table`)]}),(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>o(`page`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`data.page`)]})]}),children:[s.length?(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:s.map(e=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e.label}),(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:e.items.map(e=>{let t=He[e.kind];return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(e.key),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,W.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:[e.kind===`table`?`${a(`data.rows`,{n:e.rows??0})} · `:``,l.format(new Date(c.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,W.jsx)(b,{children:(0,W.jsx)(T,{children:a(`data.empty`)})}),(0,W.jsx)(Ue,{kind:i,projectId:e,data:t,onClose:()=>o(null),onMade:e=>{o(null),r(e)}})]})}function Ge(e,t){let n=e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/^[^a-z]+/,``).slice(0,48)||`column`,r=n,i=2;for(;t.includes(r);)r=`${n}_${i++}`;return r}var Ke={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},qe=[`text`,`number`,`date`,`duration`,`select`,`boolean`];function Je(e,t){if(t==null)return``;if(e.type===`duration`&&typeof t==`number`)return String(t/Ke[e.format.inputUnit]);if(e.type===`date`&&e.format.kind===`datetime`&&typeof t==`string`){let e=new Date(t);return new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString().slice(0,16)}return String(t)}function Ye(e,t){return t.trim()===``?null:e.type===`date`&&e.format.kind===`datetime`?new Date(t).toISOString():t}var X=`w-full min-w-0 rounded-md bg-transparent px-2 py-1.5 text-[0.875rem] outline-none transition placeholder:text-ink-4 hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`;function Xe({column:e,value:t,readOnly:n,invalid:r,onSave:i}){let o=Je(e,t),[s,l]=(0,U.useState)(o);(0,U.useEffect)(()=>l(o),[o]);let u=(t=s)=>{t!==o&&i(Ye(e,t))};if(e.type===`boolean`)return(0,W.jsx)(`div`,{className:`px-2 py-1.5`,children:(0,W.jsx)(`input`,{type:`checkbox`,checked:t===!0,disabled:n,onChange:e=>i(e.target.checked),"aria-label":e.name,className:`size-4 accent-[var(--ember)]`})});if(e.type===`select`&&e.format.multiple){let r=Array.isArray(t)?t:[],o=t=>e.format.options.find(e=>e.id===t)?.label??t;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-2 py-1`,children:[r.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-paper-2 py-0.5 pr-1 pl-2 text-[0.75rem]`,children:[o(e),n?null:(0,W.jsx)(`button`,{type:`button`,"aria-label":a(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,W.jsx)(d,{className:`size-3`})})]},e)),n?null:(0,W.jsxs)(`select`,{value:``,onChange:e=>e.target.value&&i([...r,e.target.value]),"aria-label":e.name,className:`h-7 rounded-md bg-transparent px-1 text-[0.75rem] text-ink-3 outline-none hover:bg-accent`,children:[(0,W.jsx)(`option`,{value:``,children:`+`}),e.format.options.filter(e=>!r.includes(e.id)).map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})}if(e.type===`select`)return(0,W.jsxs)(`select`,{value:typeof t==`string`?t:``,disabled:n,onChange:e=>i(e.target.value||null),"aria-label":e.name,className:X,children:[(0,W.jsx)(`option`,{value:``}),e.format.options.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]});if(e.type===`text`&&e.format?.style&&e.format.style!==`single`)return(0,W.jsx)(`textarea`,{value:s,rows:1,disabled:n,onChange:e=>l(e.target.value),onBlur:()=>u(),"aria-label":e.name,className:c(X,`field-sizing-content max-h-40 resize-none`)});let f=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,W.jsx)(`input`,{type:f,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:s,disabled:n,onChange:t=>{l(t.target.value),e.type===`date`&&u(t.target.value)},onBlur:()=>e.type!==`date`&&u(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&l(o)},"aria-label":e.name,className:c(X,(e.type===`number`||e.type===`duration`)&&`text-right tabular-nums`,r&&`ring-1 ring-rose`)})}function Ze(e){return e.type===`number`&&e.format.style===`currency`?e.format.currency??null:e.type===`number`&&e.format.style===`percent`?`%`:e.type===`duration`?a(`data.unit.${e.format.inputUnit}`):null}function Qe(e){return{name:e?.name??``,type:e?.type??`text`,required:e?.required??!1,textStyle:e?.type===`text`&&(e.format?.style??`single`)!==`single`?`multiline`:`single`,numberStyle:e?.type===`number`?e.format.style:`decimal`,currency:e?.type===`number`?e.format.currency??`EUR`:`EUR`,dateKind:e?.type===`date`?e.format.kind:`date`,unit:e?.type===`duration`&&[`minutes`,`hours`,`days`].includes(e.format.inputUnit)?e.format.inputUnit:`minutes`,options:e?.type===`select`?e.format.options.map(e=>e.label).join(`
3
- `):``,multiple:e?.type===`select`&&!!e.format.multiple}}function $e(e,t,n){let r={id:t,name:e.name.trim(),...e.required?{required:!0}:{}};switch(e.type){case`number`:return{...r,type:`number`,format:e.numberStyle===`currency`?{style:`currency`,currency:e.currency.trim().toUpperCase()}:{style:e.numberStyle}};case`date`:return{...r,type:`date`,format:{kind:e.dateKind}};case`duration`:return{...r,type:`duration`,format:{inputUnit:e.unit,display:`hms`}};case`select`:{let t=n?.type===`select`?n.format.options:[],i=[],a=e.options.split(`
4
- `).map(e=>e.trim()).filter(Boolean).map(e=>{let n=t.find(t=>t.label===e)?.id??Ge(e,i);return i.push(n),{id:n,label:e}});return{...r,type:`select`,format:{allowCustom:!1,options:a,...e.multiple?{multiple:!0}:{}}}}case`boolean`:return{...r,type:`boolean`};default:return{...r,type:`text`,...e.textStyle===`multiline`?{format:{style:`multiline`}}:{}}}}function et({open:e,column:t,columns:n,onClose:r,onSave:i}){let[s,c]=(0,U.useState)(()=>Qe(t)),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(!1);(0,U.useEffect)(()=>{e&&(c(Qe(t)),u(null))},[e,t]);let p=e=>c(t=>({...t,...e})),m=async e=>{f(!0),u(null);try{await i(e),r()}catch(e){u(e.message)}finally{f(!1)}},g=()=>{let e=t?.id??Ge(s.name,n.map(e=>e.id)),r=$e(s,e,t);return m(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,W.jsx)(O,{open:e,onClose:r,title:t?t.name:a(`data.newColumn`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),s.name.trim()&&g()},children:[(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.columnName`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:s.name,maxLength:128,onChange:e=>p({name:e.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.columnType`)}),(0,W.jsx)(v,{value:s.type,onChange:e=>p({type:e}),options:qe.map(e=>({value:e,label:a(`data.type.${e}`)}))})]})]}),s.type===`text`?(0,W.jsx)(v,{value:s.textStyle,onChange:e=>p({textStyle:e}),options:[{value:`single`,label:a(`data.text.single`)},{value:`multiline`,label:a(`data.text.multiline`)}]}):null,s.type===`number`?(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)(v,{value:s.numberStyle,onChange:e=>p({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:a(`data.number.${e}`)}))}),s.numberStyle===`currency`?(0,W.jsx)(S,{value:s.currency,maxLength:3,"aria-label":a(`data.currency`),placeholder:`EUR`,onChange:e=>p({currency:e.target.value})}):null]}):null,s.type===`date`?(0,W.jsx)(v,{value:s.dateKind,onChange:e=>p({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:a(`data.date.${e}`)}))}):null,s.type===`duration`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.unit`)}),(0,W.jsx)(v,{value:s.unit,onChange:e=>p({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:a(`data.unit.${e}`)}))})]}):null,s.type===`select`?(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.options`)}),(0,W.jsx)(h,{minRows:3,value:s.options,onChange:e=>p({options:e.target.value})})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(o,{checked:s.multiple,onChange:e=>p({multiple:e})}),a(`data.multiple`)]})]}):null,(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(o,{checked:s.required,onChange:e=>p({required:e})}),a(`data.required`)]}),l?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,W.jsx)(j,{variant:`ghost`,className:`text-rose`,disabled:d,onClick:()=>confirm(a(`data.confirmDelete`,{title:t.name}))&&void m(n.filter(e=>e.id!==t.id)),children:a(`data.deleteColumn`)}):null,(0,W.jsx)(`span`,{className:`flex-1`}),(0,W.jsx)(j,{variant:`ghost`,onClick:r,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:d,disabled:!s.name.trim(),children:a(`settings.save`)})]})]})})}function tt({tableId:e,onGone:t}){let n=r(),o=[`space-table`,e],s=i({queryKey:o,queryFn:()=>A.get(`/api/studio/tables/${e}`)}),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,m]=(0,U.useState)(null),[h,_]=(0,U.useState)(``);(0,U.useEffect)(()=>_(s.data?.title??``),[s.data?.title]);let v=async()=>{await n.invalidateQueries({queryKey:[`space-data`,s.data?.projectId]}),await n.invalidateQueries({queryKey:[`knowledge`,s.data?.projectId]})},x=e=>n.setQueryData(o,t=>t&&{...t,rows:e(t.rows)}),S=e=>{d(e.message),s.refetch()},w=async t=>{await A.patch(`/api/studio/tables/${e}`,t),await s.refetch(),await v()},T=L({mutationFn:({row:t,column:n,value:r})=>A.patch(`/api/studio/tables/${e}/rows/${t}`,{cells:{[n]:r}}),onSuccess:(e,{row:t,column:n})=>{d(null),m(e=>e===`${t}:${n}`?null:e),x(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof y&&e.body?.column===n){let e=s.data?.columns.find(e=>e.id===n)?.name??n;m(`${t}:${n}`),d(a(`data.badCell`,{column:e}));return}S(e)}}),E=L({mutationFn:()=>A.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{x(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await v()},onError:S}),D=L({mutationFn:t=>A.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{x(e=>e.filter(e=>e.id!==t)),await v()},onError:S}),O=L({mutationFn:()=>A.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await v(),t()}});if(!s.data)return s.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error.message}):null;let{columns:k,rows:M,readOnly:N}=s.data,P=!!s.data.list;return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:h,disabled:N,maxLength:120,onChange:e=>_(e.target.value),onBlur:()=>h.trim()&&h!==s.data?.title&&void w({title:h}).catch(S),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":a(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),N?null:(0,W.jsx)(C,{label:a(`data.deleteTable`),onClick:()=>confirm(a(`data.confirmDelete`,{title:s.data.title}))&&O.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(p,{className:`size-4`})})]}),P?(0,W.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:a(`data.fromList`)}):null,s.data.knowledge?(0,W.jsx)(Y,{projectId:s.data.projectId,itemKey:`t:${s.data.id}`,has:s.data.knowledge.categories,originLabel:s.data.knowledge.originLabel,kept:s.data.knowledge.kept,review:s.data.knowledge.review,file:s.data.knowledge.file,readOnly:N,onReviewed:()=>void A.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>s.refetch()).catch(S)}):null,(0,W.jsxs)(b,{className:`overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full border-collapse text-left`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[k.map(e=>(0,W.jsx)(`th`,{className:`min-w-36 border-border-soft border-l p-1 font-medium first:border-l-0`,children:(0,W.jsxs)(`button`,{type:`button`,disabled:N||P,onClick:()=>l(e),className:`flex w-full items-center gap-1 rounded-md px-2 py-1.5 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink disabled:hover:bg-transparent`,children:[(0,W.jsx)(`span`,{className:`truncate`,children:e.name}),e.required?(0,W.jsx)(`span`,{className:`text-ember`,children:`*`}):null,Ze(e)?(0,W.jsx)(`span`,{className:`font-normal text-ink-4`,children:Ze(e)}):null]})},e.id)),(0,W.jsx)(`th`,{className:`w-10 p-1`,children:N||P?null:(0,W.jsx)(C,{label:a(`data.newColumn`),onClick:()=>l(`new`),className:`size-8`,children:(0,W.jsx)(g,{className:`size-4`})})})]})}),(0,W.jsx)(`tbody`,{children:M.map(e=>(0,W.jsxs)(`tr`,{className:`group border-border-soft border-b last:border-b-0`,children:[k.map(t=>(0,W.jsx)(`td`,{className:`border-border-soft border-l p-1 align-top first:border-l-0`,children:(0,W.jsx)(Xe,{column:t,value:e.cells[t.id],readOnly:N,invalid:f===`${e.id}:${t.id}`,onSave:n=>T.mutate({row:e.id,column:t.id,value:n})})},t.id)),(0,W.jsx)(`td`,{className:`w-10 p-1 align-top`,children:N?null:(0,W.jsx)(C,{label:a(`data.deleteRow`),onClick:()=>D.mutate(e.id),className:`size-8 opacity-0 hover:text-rose focus:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:(0,W.jsx)(p,{className:`size-3.5`})})})]},e.id))})]})}),M.length?null:(0,W.jsx)(`p`,{className:`px-4 py-6 text-center text-[0.875rem] text-ink-3`,children:a(`data.noRows`)}),N?null:(0,W.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,W.jsxs)(j,{variant:`ghost`,size:`sm`,busy:E.isPending,onClick:()=>E.mutate(),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`data.addRow`)]})})]}),u?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:u}):null,(0,W.jsx)(et,{open:c!==null,column:c===`new`?null:c,columns:k,onClose:()=>l(null),onSave:e=>w({columns:e})})]})}var nt=`wizards.runDrawer.width`,rt=`wizards.runDrawer.wide`,it=`wizards.runDrawer.look`,at=680,Z=400,ot=()=>Math.max(Z,window.innerWidth-120);function Q(e){try{return localStorage.getItem(e)}catch{return null}}function $(e,t){try{localStorage.setItem(e,t)}catch{}}function st(){let[e,t]=(0,U.useState)(()=>{let e=Number(Q(nt));return e?Math.min(Math.max(e,Z),ot()):at}),[n,r]=(0,U.useState)(()=>Q(rt)===`1`),i=(0,U.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,Z),ot()));t(n),$(nt,String(n))},[]);return{width:e,wide:n,toggleWide:()=>{r(!n),$(rt,n?`0`:`1`)},onPointerDown:t=>{t.preventDefault();let n=t.clientX,r=e,a=e=>i(r+n-e.clientX),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)};document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)},onKeyDown:t=>{let n=t.shiftKey?64:16;t.key===`ArrowLeft`?(t.preventDefault(),i(e+n)):t.key===`ArrowRight`&&(t.preventDefault(),i(e-n))},reset:()=>i(at)}}function ct(){let[e,t]=(0,U.useState)(()=>Q(it)===`chat`?`chat`:`steps`);return[e,e=>{t(e),$(it,e)}]}function lt({look:e,onChange:t}){let n=[{id:`steps`,label:a(`chat.steps`),Icon:pe},{id:`chat`,label:a(`chat.chat`),Icon:B}];return(0,W.jsx)(`fieldset`,{"aria-label":a(`chat.view`),className:`m-0 flex min-w-0 rounded-full border-0 bg-paper-2 p-0.5`,children:n.map(({id:n,label:r,Icon:i})=>(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":e===n,title:r,onClick:()=>t(n),className:c(`inline-flex h-7 items-center gap-1.5 rounded-full px-2.5 font-medium text-[0.75rem] transition coarse:h-9`,e===n?`bg-card text-ink shadow-soft`:`text-ink-3 hover:text-ink`),children:[(0,W.jsx)(i,{className:`size-3.5`}),(0,W.jsx)(`span`,{className:`max-sm:hidden`,children:r})]},n))})}function ut({header:e,actions:t,onClose:n,children:r}){let i=st();return(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 flex justify-end bg-[oklch(20%_0.01_60/0.22)] backdrop-blur-[1px]`,onClick:n,children:(0,W.jsxs)(`div`,{className:c(`relative flex h-full w-full animate-rise flex-col bg-background shadow-overlay`,!i.wide&&`sm:w-[var(--drawer)]`),style:{"--drawer":`${i.width}px`},onClick:e=>e.stopPropagation(),children:[i.wide?null:(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":a(`editor.resize`),"aria-valuenow":i.width,tabIndex:0,title:a(`editor.resize`),onPointerDown:i.onPointerDown,onKeyDown:i.onKeyDown,onDoubleClick:i.reset,className:`group -left-2.5 absolute inset-y-0 z-10 hidden w-5 cursor-col-resize outline-none sm:block`,children:(0,W.jsx)(`span`,{className:`-translate-y-1/2 absolute top-1/2 left-[7px] h-12 w-1.5 rounded-full bg-ink-4/40 transition group-hover:bg-ember/70 group-focus-visible:bg-ember group-active:h-16 group-active:bg-ember`})}),(0,W.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4`,children:[(0,W.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:e}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t,(0,W.jsx)(C,{label:a(i.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:i.toggleWide,className:`max-sm:hidden`,children:i.wide?(0,W.jsx)(me,{className:`size-4`}):(0,W.jsx)(u,{className:`size-4`})}),(0,W.jsx)(C,{label:a(`editor.close`),onClick:n,children:(0,W.jsx)(d,{className:`size-5`})})]})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}export{De as _,He as a,fe as b,Be as c,J as d,Y as f,Te as g,G as h,tt as i,ze as l,Oe as m,ut as n,We as o,Le as p,ct as r,Ve as s,lt as t,je as u,Ee as v,ce as x,H as y};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{$t as a,At as o,Cn as s,Ct as c,Et as l,H as u,Ot as d,Pt as f,Sn as p,Vt as m,Wt as h,Yt as g,_n as _,bt as v,dt as y,ft as b,gt as x,hn as S,ht as C,in as w,mt as ee,nn as te,on as T,pn as E,sn as D,u as O,un as k,ut as A,vt as ne,xn as re,xt as ie,zt as ae}from"./ui-DrjXmHdO.js";import{t as oe}from"./circle-alert-D-Q6DK7b.js";import{t as se}from"./lock-DwGN_KOC.js";import{n as ce,r as le,t as ue}from"./ReadOnly-C1UcqOlS.js";import{A as de,At as fe,Ct as pe,Ht as me,Mt as he,Ot as ge,Pt as _e,Qt as ve,Tt as ye,U as be,Ut as xe,Yt as Se,_ as Ce,c as we,cn as Te,dn as Ee,en as De,fn as Oe,gn as ke,h as Ae,ht as je,j as Me,k as Ne,l as Pe,ln as Fe,mt as Ie,pn as Le,rn as Re,s as ze,sn as Be,ut as j,v as Ve,vn as M}from"./index-DnQgOKOQ.js";import{a as N,c as He,d as Ue,f as We,i as P,l as Ge,n as Ke,o as qe,r as Je,s as Ye,t as Xe,u as Ze}from"./settings-menu-JuSRq6NP.js";import{t as Qe}from"./Harness-CvvtSTZC.js";var $e={name:`ear`,size:24,node:[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]};$e.node;var et=E($e),tt={name:`key-round`,size:24,node:[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]};tt.node;var F=E(tt),nt={name:`mail-plus`,size:24,node:[[`path`,{d:`M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8`,key:`12jkf8`}],[`path`,{d:`m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7`,key:`1ocrg3`}],[`path`,{d:`M19 16v6`,key:`tddt3s`}],[`path`,{d:`M16 19h6`,key:`xwg31i`}]]};nt.node;var rt=E(nt),it={name:`rotate-cw`,size:24,node:[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]};it.node;var at=E(it),ot={name:`wrench`,size:24,node:[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]};ot.node;var st=E(ot),I=e(t(),1),L=e(n(),1);function ct(){let e=Pe(),[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(null),a=async e=>{n(e??`*`),i(null);try{await we(e)}catch(e){i(e.message)}finally{n(null)}};return(0,L.jsxs)(be,{title:o(`plugins.title`),hint:e.canReload?o(`plugins.hint`):o(`plugins.hintManaged`),action:e.canReload?(0,L.jsx)(A,{variant:`secondary`,busy:t===`*`,onClick:()=>void a(),children:o(`plugins.rescan`)}):null,children:[e.plugins.length||e.problems.length?null:(0,L.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`plugins.none`)}),(0,L.jsxs)(`ul`,{className:`divide-y divide-border-soft`,children:[e.plugins.map(n=>{let r=e.failed[n.id];return(0,L.jsxs)(`li`,{className:`flex items-start gap-4 py-4 first:pt-0 last:pb-0`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1`,children:[(0,L.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:n.name}),n.name===n.id?null:(0,L.jsxs)(`span`,{className:`font-mono text-[0.75rem] text-ink-4`,children:[n.id,` · `,n.version]})]}),n.description?(0,L.jsx)(`p`,{className:`mt-0.5 text-[0.875rem] text-ink-3`,children:n.description}):null,n.tools.length?(0,L.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[o(`plugins.tools`),n.tools.map(e=>(0,L.jsx)(b,{children:e.id},e.id))]}):null,n.error?(0,L.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:o(`plugins.serverFailed`,{error:n.error})}):null,r?(0,L.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:o(`plugins.studioFailed`,{error:r})}):null]}),e.canReload?(0,L.jsx)(C,{label:o(`plugins.reload`),disabled:t!==null,onClick:()=>void a(n.id),children:(0,L.jsx)(at,{className:t===n.id?`size-4 animate-spin`:`size-4`})}):null]},n.id)}),e.problems.map(e=>(0,L.jsxs)(`li`,{className:`py-4 first:pt-0 last:pb-0`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1`,children:[(0,L.jsx)(b,{tone:`warn`,children:o(`plugins.problems`)}),(0,L.jsx)(`span`,{className:`break-all font-mono text-[0.75rem] text-ink-3`,children:e.path})]}),(0,L.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:e.message})]},e.path))]}),r?(0,L.jsx)(`p`,{className:`mt-4 text-[0.8125rem] text-rose`,children:r}):null]})}var lt=[`pro-modules`],ut=`/api/studio/plugins/-/pro`,dt={managed:`pro.held.plan`,not_installed:`pro.held.release`,release:`pro.held.release`,unconfirmed:`pro.held.unconfirmed`,plan:`pro.held.plan`},ft=e=>new Date(e).toLocaleDateString(d===`de`?`de-AT`:`en-GB`,{day:`numeric`,month:`long`});function pt(){let e=r(),{canReload:t}=Pe(),n=i({queryKey:lt,queryFn:()=>O.get(ut),enabled:t}),s=t=>e.setQueryData(lt,t),c=M({mutationFn:()=>O.post(`${ut}/refresh`),onSuccess:s}),l=M({mutationFn:e=>O.post(`${ut}/${e}`),onSuccess:s}),u=M({mutationFn:e=>O.del(`${ut}/${e}`),onSuccess:s}),d=n.data,f=l.isPending||u.isPending,p=l.error??u.error??c.error;return t?(0,L.jsx)(be,{title:o(`pro.title`),hint:o(`pro.hint`),action:d?.linked?(0,L.jsx)(A,{variant:`secondary`,busy:c.isPending,onClick:()=>c.mutate(),children:o(`pro.check`)}):null,children:d?d.linked?(0,L.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 text-[0.8125rem] text-ink-3`,children:[(0,L.jsxs)(`span`,{children:[d.plan?o(`pro.plan`,{plan:d.plan.name}):null,d.plan&&d.expiresAt?` · `:null,d.expiresAt?o(`pro.confirmedUntil`,{date:ft(d.expiresAt)}):null]}),(0,L.jsxs)(A,{variant:`ghost`,onClick:()=>j(`${d.accountUrl}/billing`),children:[o(`pro.plans`),` `,(0,L.jsx)(a,{className:`size-4`})]})]}),d.error?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:d.error}):null,d.modules.length?(0,L.jsx)(`ul`,{className:`divide-y divide-border-soft`,children:d.modules.map(e=>(0,L.jsxs)(`li`,{className:`flex items-start gap-4 py-4 first:pt-0 last:pb-0`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1`,children:[(0,L.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.name}),(0,L.jsxs)(`span`,{className:`font-mono text-[0.75rem] text-ink-4`,children:[e.id,` · `,e.installed?.version??e.version]}),e.loaded?(0,L.jsx)(b,{tone:`live`,children:o(`pro.on`)}):null,e.included?null:(0,L.jsx)(b,{children:o(`pro.notInPlan`)}),e.installed&&e.heldBack&&e.included?(0,L.jsx)(b,{tone:`warn`,children:o(dt[e.heldBack])}):null]}),e.description?(0,L.jsx)(`p`,{className:`mt-0.5 text-[0.875rem] text-ink-3`,children:e.description}):null]}),(0,L.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[e.included&&(!e.installed||e.update)?(0,L.jsx)(A,{busy:l.isPending&&l.variables===e.id,disabled:f,onClick:()=>l.mutate(e.id),children:e.installed?o(`pro.update`):o(`pro.install`)}):null,e.installed?(0,L.jsx)(A,{variant:`secondary`,busy:u.isPending&&u.variables===e.id,disabled:f,onClick:()=>u.mutate(e.id),children:o(`pro.remove`)}):null]})]},e.id))}):(0,L.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`pro.none`,{runtime:d.runtime})}),p?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:p.message}):null]}):(0,L.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`pro.notLinked`)}):(0,L.jsx)(ie,{})}):null}function mt({connector:e}){let[t,n]=(0,I.useState)(!1);return(0,L.jsxs)(`div`,{className:`rounded-lg bg-paper ring-1 ring-border-soft`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`flex w-full items-center gap-3 px-3 py-2 text-left`,children:[(0,L.jsx)(`span`,{className:l(`size-2 shrink-0 rounded-full`,e.usable?`bg-moss`:`bg-ink-4`)}),(0,L.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem]`,children:[e.name,` `,(0,L.jsx)(`span`,{className:`font-mono text-[0.6875rem] text-ink-4`,children:e.id})]}),(0,L.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3`,children:e.usable?o(`connectors.actions`,{n:e.actions.length,r:e.actions.filter(e=>e.group===`read`).length}):o(`connectors.notSetUp`)})]}),t?(0,L.jsxs)(`div`,{className:`border-border-soft border-t px-3 py-2 text-[0.75rem]`,children:[e.missingSetup?(0,L.jsxs)(`p`,{className:`mb-1 text-ink-3`,children:[o(`connectors.setup`),` `,(0,L.jsx)(`span`,{className:`font-mono text-ink-2`,children:e.missingSetup})]}):null,(0,L.jsx)(`p`,{className:`text-ink-4`,children:e.actions.map(e=>e.group===`read`?e.id:`${e.id} (${o(`connectors.group.${e.group}`)})`).join(` · `)})]}):null]})}var ht={none:`connectors.authNone`,oauth2:`connectors.authOauth`,api_key:`connectors.authKey`};function gt({projectId:e,connector:t,readOnly:n}){let i=r(),[a,s]=(0,I.useState)(!1),c=()=>i.invalidateQueries({queryKey:[`connectors`,e]}),u=`/api/studio/projects/${e}/connectors/${t.id}`,d=M({mutationFn:()=>O.post(`${u}/refresh`),onSuccess:c}),p=M({mutationFn:()=>O.del(u),onSuccess:c}),m=t.actions.filter(e=>e.group===`read`).length;return(0,L.jsxs)(`div`,{className:`rounded-lg bg-paper ring-1 ring-border-soft`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 p-3`,children:[(0,L.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 text-ink-2`,children:(0,L.jsx)(ve,{className:`size-4`})}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`min-w-0 flex-1 text-left`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`truncate font-medium text-[0.875rem]`,children:t.name}),(0,L.jsx)(`span`,{className:`font-mono text-[0.6875rem] text-ink-4`,children:t.id})]}),(0,L.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t.domain,` · `,t.sourceKind===`mcp`?`MCP`:`OpenAPI`,` ·`,` `,o(ht[t.auth]),` ·`,` `,t.toolsPending?o(`connectors.pending`):o(`connectors.actions`,{n:t.actions.length,r:m})]})]}),n?null:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(C,{label:o(`connectors.refresh`),onClick:()=>d.mutate(),children:d.isPending?(0,L.jsx)(ie,{className:`size-4`}):(0,L.jsx)(ae,{className:`size-4`})}),(0,L.jsx)(C,{label:o(`connectors.remove`),className:`hover:text-rose`,onClick:()=>confirm(`${t.name}: ${o(`connectors.remove`)}?`)&&p.mutate(),children:(0,L.jsx)(f,{className:`size-4`})})]})]}),t.needsOAuthClient?(0,L.jsx)(`p`,{className:`border-border-soft border-t px-3 py-2 text-[0.75rem] text-rose`,children:o(`connectors.needsClient`)}):null,d.error??p.error?(0,L.jsx)(`p`,{className:`border-border-soft border-t px-3 py-2 text-[0.75rem] text-rose`,children:(d.error??p.error).message}):null,a&&t.actions.length?(0,L.jsx)(`ul`,{className:`max-h-64 overflow-y-auto border-border-soft border-t px-3 py-2`,children:t.actions.map(e=>(0,L.jsxs)(`li`,{className:`flex items-baseline gap-2 py-1 text-[0.75rem]`,children:[(0,L.jsx)(`span`,{className:l(`w-14 shrink-0 text-[0.6875rem] uppercase tracking-wide`,e.group===`read`?`text-moss`:e.group===`write`?`text-ink-3`:`text-rose`),children:o(`connectors.group.${e.group}`)}),(0,L.jsx)(`span`,{className:`shrink-0 font-mono text-ink-2`,children:e.id}),(0,L.jsx)(`span`,{className:`min-w-0 truncate text-ink-4`,children:e.summary})]},e.id))}):null]})}function _t({projectId:e,domain:t,source:n,taken:i,onDone:a}){let s=r(),[c,l]=(0,I.useState)({id:``,secret:``}),[u,d]=(0,I.useState)(!1),f=i.includes(n.suggestedId),p=M({mutationFn:()=>O.post(`/api/studio/projects/${e}/connectors`,{domain:t,sourceKind:n.sourceKind,sourceUrl:n.sourceUrl,id:n.suggestedId,toolPrefix:n.suggestedToolPrefix,...n.name?{name:n.name}:{},...c.id&&c.secret?{oauthClientId:c.id,oauthClientSecret:c.secret}:{}}),onSuccess:async t=>{await s.invalidateQueries({queryKey:[`connectors`,e]}),a(t.warnings)}});return(0,L.jsxs)(`div`,{className:`rounded-lg bg-card p-3 ring-1 ring-border-soft`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(b,{tone:n.sourceKind===`mcp`?`ember`:`neutral`,children:n.sourceKind===`mcp`?`MCP`:`OpenAPI`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`truncate text-[0.8125rem]`,children:n.name??n.suggestedId}),(0,L.jsx)(`div`,{className:`truncate font-mono text-[0.6875rem] text-ink-4`,children:n.sourceUrl})]}),n.blocked||f?null:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`text-[0.75rem] text-ink-3 hover:text-ink`,children:o(`connectors.ownClient`)}),(0,L.jsx)(A,{size:`sm`,busy:p.isPending,onClick:()=>p.mutate(),children:o(`connectors.import`)})]})]}),n.blocked?(0,L.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-ink-3`,children:n.blocked}):null,f?(0,L.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-ink-3`,children:o(`connectors.exists`)}):null,u?(0,L.jsxs)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2`,children:[(0,L.jsx)(x,{placeholder:`OAuth Client-ID`,value:c.id,onChange:e=>l(t=>({...t,id:e.target.value}))}),(0,L.jsx)(x,{type:`password`,autoComplete:`off`,placeholder:`OAuth Client-Secret`,value:c.secret,onChange:e=>l(t=>({...t,secret:e.target.value}))})]}):null,p.error?(0,L.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-rose`,children:p.error.message}):null]})}function vt({projectId:e,readOnly:t}){let n=pe(`unsetConnectors`),[r,a]=(0,I.useState)(``),[s,c]=(0,I.useState)(null),[l,u]=(0,I.useState)(null),[d,f]=(0,I.useState)([]),p=i({queryKey:[`connectors`,e],queryFn:()=>O.get(`/api/studio/projects/${e}/connectors`)}),m=M({mutationFn:()=>O.post(`/api/studio/connectors/search`,{query:r}),onSuccess:e=>{c(e),u(null),f([])}}),h=M({mutationFn:e=>O.get(`/api/studio/connectors/registry/${encodeURIComponent(e)}`),onSuccess:u}),g=p.data??[],_=g.filter(e=>e.sourceKind===`builtin`&&(n||e.usable)),v=g.filter(e=>e.sourceKind!==`builtin`);return(0,L.jsxs)(y,{className:`p-4 sm:p-6`,children:[(0,L.jsx)(`h2`,{className:`font-display font-semibold text-lg`,children:o(`connectors.title`)}),(0,L.jsx)(`p`,{className:`mt-1 mb-5 text-[0.875rem] text-ink-3`,children:o(`connectors.hint`)}),_.length?(0,L.jsx)(`div`,{className:`mb-5 grid gap-1.5 sm:grid-cols-2`,children:_.map(e=>(0,L.jsx)(mt,{connector:e},e.id))}):null,(0,L.jsx)(`h3`,{className:`mb-2 font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.07em]`,children:o(`connectors.imported`)}),v.length?(0,L.jsx)(`div`,{className:`mb-4 flex flex-col gap-2`,children:v.map(n=>(0,L.jsx)(gt,{projectId:e,connector:n,readOnly:t},n.id))}):null,t?v.length?null:(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:o(`connectors.noneImported`)}):(0,L.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),r.trim()&&m.mutate()},children:[(0,L.jsx)(x,{value:r,placeholder:o(`connectors.search`),onChange:e=>a(e.target.value)}),(0,L.jsxs)(A,{type:`submit`,variant:`secondary`,busy:m.isPending,children:[(0,L.jsx)(Se,{className:`size-4`}),` `,o(`connectors.find`)]})]}),m.error?(0,L.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:m.error.message}):null,s&&!l?(0,L.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[s.length?null:(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:o(`connectors.none`)}),s.map(e=>(0,L.jsxs)(`button`,{type:`button`,disabled:!e.kinds.length,onClick:()=>h.mutate(e.domain),className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left transition hover:bg-paper-2 disabled:opacity-50`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:e.domain}),(0,L.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.description})]}),(0,L.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4 uppercase`,children:e.kinds.join(` · `)}),(0,L.jsx)(T,{className:`-rotate-90 size-4 text-ink-4`})]},e.domain)),h.isPending?(0,L.jsx)(ie,{className:`mx-auto mt-2 size-4 text-ink-4`}):null,h.error?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:h.error.message}):null]}):null,l?(0,L.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,L.jsx)(`div`,{className:`font-medium text-[0.875rem]`,children:l.domain}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>u(null),className:`text-[0.75rem] text-ink-3 hover:text-ink`,children:o(`run.back`)})]}),l.summary?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:l.summary}):null,l.sources.map(t=>(0,L.jsx)(_t,{projectId:e,domain:l.domain,source:t,taken:g.map(e=>e.id),onDone:f},`${t.sourceKind}:${t.sourceUrl}`)),l.credentials.filter(e=>e.setup||e.url).map(e=>(0,L.jsxs)(`p`,{className:`text-[0.75rem] text-ink-3`,children:[(0,L.jsxs)(`span`,{className:`text-ink-2`,children:[e.label,`:`]}),` `,e.setup,` `,e.url?(0,L.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-ember underline`,children:e.url}):null]},e.label)),d.map(e=>(0,L.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:e},e))]}):null]})}var R=`engenty-wizards`,yt=`engenty wizards`,bt=`ENGENTY_WIZARDS_KEY`,xt=[{id:`claude-desktop`,name:`Claude Desktop`,widgets:!0,connector:!0},{id:`claude-code`,name:`Claude Code`,widgets:!1},{id:`codex`,name:`Codex · ChatGPT app`,widgets:!1},{id:`cursor`,name:`Cursor`,widgets:!0},{id:`vscode`,name:`VS Code (Copilot)`,widgets:!0},{id:`windsurf`,name:`Windsurf`,widgets:!1},{id:`gemini`,name:`Gemini CLI`,widgets:!1},{id:`goose`,name:`Goose`,widgets:!0},{id:`openclaw`,name:`OpenClaw`,widgets:!1},{id:`lm-studio`,name:`LM Studio`,widgets:!1},{id:`claude-ai`,name:`claude.ai`,widgets:!0,oauth:!0},{id:`chatgpt`,name:`ChatGPT`,widgets:!0,oauth:!0}],St={"claude-ai":{open:`https://claude.ai/settings/connectors`,where:`integrate.claudeAiWhere`,host:`claude.ai`},"claude-desktop":{where:`integrate.desktopWhere`,host:`claude.ai`},chatgpt:{where:`integrate.chatgptWhere`,host:`chatgpt.com`}};function z({text:e,muted:t}){let[n,r]=(0,I.useState)(!1);return(0,L.jsxs)(`div`,{className:l(`flex items-start gap-2 rounded-lg bg-paper-2 p-3`,t&&`text-ink-3 opacity-80`),children:[(0,L.jsx)(`code`,{className:`min-w-0 flex-1 whitespace-pre-wrap break-all font-mono text-[0.75rem] leading-relaxed`,children:e}),(0,L.jsx)(C,{label:o(n?`settings.copied`:`settings.copy`),onClick:async()=>{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)},children:n?(0,L.jsx)(D,{className:`size-4`}):(0,L.jsx)(te,{className:`size-4`})})]})}function Ct(e){try{let t=new URL(e);return t.protocol===`https:`&&!/(^|\.)localhost$/.test(t.hostname)&&!/^(127\.|10\.|192\.168\.|\[::1\])/.test(t.hostname)}catch{return!1}}function B({children:e}){return(0,L.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-relaxed`,children:e})}function V({title:e,children:t}){return(0,L.jsxs)(`section`,{className:`flex flex-col gap-2.5 border-border-soft border-t pt-5 first:border-t-0 first:pt-0`,children:[(0,L.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:e}),t]})}var wt=`https://github.com/engenty/engenty-wizards-wp-plugin/releases/latest/download/engenty-wizards.zip`;function Tt({managed:e}){return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight`,children:`WordPress`}),(0,L.jsx)(`p`,{className:`mt-1 text-[0.9375rem] text-ink-2`,children:o(`integrate.wpIntro`)})]}),(0,L.jsxs)(y,{className:`flex flex-col gap-5 p-5`,children:[(0,L.jsxs)(V,{title:o(`integrate.wpInstall`),children:[(0,L.jsx)(B,{children:o(`integrate.wpInstallHint`)}),(0,L.jsx)(`div`,{children:(0,L.jsx)(A,{variant:`secondary`,size:`sm`,onClick:()=>window.open(wt,`_blank`),children:o(`integrate.wpDownload`)})})]}),(0,L.jsx)(V,{title:o(`integrate.wpConnect`),children:(0,L.jsx)(B,{children:o(e?`integrate.wpConnectHint`:`integrate.wpConnectLocal`)})}),(0,L.jsxs)(V,{title:o(`integrate.wpPlace`),children:[(0,L.jsx)(B,{children:o(`integrate.wpPlaceHint`)}),(0,L.jsx)(z,{text:`[engenty_wizard id="ID" mode="modal" label="${o(`integrate.wpSampleLabel`)}"]`})]}),(0,L.jsx)(V,{title:o(`integrate.wpPro`),children:(0,L.jsx)(B,{children:o(`integrate.wpProHint`)})}),(0,L.jsx)(V,{title:o(`integrate.wpLocal`),children:(0,L.jsx)(B,{children:o(`integrate.wpLocalHint`)})})]})]})}function Et(e,t){return JSON.stringify({[e]:{[R]:t}},null,2)}function Dt({id:e,url:t,apiKey:n}){let r=n?`Authorization: Bearer ${n}`:null,i=n?{headers:{Authorization:`Bearer ${n}`}}:{};switch(e){case`claude-code`:{let e=t.replace(/\/api\/mcp$/,`/api/claude-plugin`);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`mcp.terminal`)}),(0,L.jsx)(z,{text:`claude mcp add --transport http --scope user ${R} ${t}${r?` --header "${r}"`:``}`}),!n&&Ct(t)?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`mcp.ccPlugin`)}),(0,L.jsx)(z,{text:`claude plugin marketplace add ${e}/marketplace.json`}),(0,L.jsx)(z,{text:`claude plugin install ${R}@engenty`})]}):null]})}case`codex`:return n?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`mcp.codexKey`)}),(0,L.jsx)(z,{text:`echo 'export ${bt}=${n}' >> ~/.zshrc && source ~/.zshrc`}),(0,L.jsx)(z,{text:`codex mcp add ${R} --url ${t} --bearer-token-env-var ${bt}`})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`mcp.terminal`)}),(0,L.jsx)(z,{text:`codex mcp add ${R} --url ${t}`}),(0,L.jsx)(z,{text:`codex mcp login ${R}`})]});case`gemini`:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`mcp.terminal`)}),(0,L.jsx)(z,{text:`gemini mcp add --scope user --transport http ${R} ${t}${r?` -H "${r}"`:``}`})]});case`cursor`:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.file`,{file:`~/.cursor/mcp.json`})}),(0,L.jsx)(z,{text:Et(`mcpServers`,{url:t,...i})})]});case`vscode`:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.vscode`)}),(0,L.jsx)(z,{text:Et(`servers`,{type:`http`,url:t,...i})})]});case`windsurf`:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.file`,{file:`~/.codeium/windsurf/mcp_config.json`})}),(0,L.jsx)(z,{text:Et(`mcpServers`,{serverUrl:t,...i})})]});case`lm-studio`:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.file`,{file:`~/.lmstudio/mcp.json`})}),(0,L.jsx)(z,{text:Et(`mcpServers`,{url:t,...i})})]});case`claude-desktop`:case`claude-ai`:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`mcp.claudeAi`)}),(0,L.jsx)(z,{text:t})]});case`chatgpt`:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.chatgpt`)}),(0,L.jsx)(z,{text:t})]});default:return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.generic`)}),(0,L.jsx)(z,{text:t}),r?(0,L.jsx)(z,{text:r}):null]})}}function Ot(){let e=r(),t=i({queryKey:[`api-keys`],queryFn:()=>O.get(`/api/studio/api-keys`)}),n=M({mutationFn:e=>O.del(`/api/studio/api-keys/${e}`),onSuccess:()=>e.invalidateQueries({queryKey:[`api-keys`]})});return t.data?.length?(0,L.jsxs)(`section`,{children:[(0,L.jsx)(`h2`,{className:`font-display font-semibold text-lg`,children:o(`mcp.keys`)}),(0,L.jsx)(`p`,{className:`mt-1 mb-4 text-[0.875rem] text-ink-3`,children:o(`mcp.keysHint`)}),(0,L.jsx)(y,{className:`flex flex-col gap-2 p-3`,children:t.data.map(e=>(0,L.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg px-3 py-2`,children:[(0,L.jsx)(F,{className:`size-4 shrink-0 text-ink-4`}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:e.name}),(0,L.jsxs)(`div`,{className:`font-mono text-[0.6875rem] text-ink-4`,children:[e.start,`… ·`,` `,e.lastRequest?o(`settings.lastUsed`,{when:new Date(e.lastRequest).toLocaleString()}):o(`settings.neverUsed`)]})]}),(0,L.jsx)(C,{label:o(`settings.revoke`),onClick:()=>n.mutate(e.id),className:`hover:text-rose`,children:(0,L.jsx)(f,{className:`size-4`})})]},e.id))})]}):null}function kt(e,t){return t?.toolAt?`works`:e?.connected||t?`added`:`none`}var At={works:`done`,added:`on`,none:void 0},jt={works:`integrate.stateWorks`,added:`integrate.stateAdded`,none:`integrate.stateNone`};function Mt({standing:e}){return e===`none`?(0,L.jsx)(`span`,{className:`w-2 text-center text-ink-4 leading-none`,children:`–`}):(0,L.jsx)(`span`,{className:l(`size-2 shrink-0 rounded-full`,e===`works`?`bg-moss`:`bg-ember`)})}function Nt(){return(0,L.jsx)(`div`,{className:`mt-5 flex flex-col gap-1.5 rounded-lg bg-paper-2 px-3 py-2.5 text-[0.75rem] text-ink-3`,children:[`works`,`added`,`none`].map(e=>(0,L.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,L.jsx)(Mt,{standing:e}),o(jt[e])]},e))})}function H({client:e,signIn:t}){let n=(e,t)=>(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-card px-2.5 py-1 text-[0.8125rem] text-ink-2 ring-1 ring-border-soft`,children:[e,t]}),r=(0,L.jsx)(D,{className:`size-3.5 text-moss`,strokeWidth:3});return(0,L.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[n(r,o(`integrate.outRun`)),e.widgets?n(r,o(`integrate.outWidget`)):n((0,L.jsx)(le,{className:`size-3.5 text-ink-3`}),o(`integrate.outText`)),t?n((0,L.jsx)(se,{className:`size-3.5 text-ink-3`}),o(`integrate.outSignIn`)):null]})}function U({client:e,works:t,children:n}){return(0,L.jsxs)(`div`,{children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,L.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight`,children:e.name}),t?(0,L.jsx)(b,{tone:`live`,icon:(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}),children:o(`integrate.works`)}):null]}),n]})}function W({n:e,state:t,title:n,children:r}){return(0,L.jsxs)(`li`,{"aria-current":t===`now`?`step`:void 0,className:l(`grid grid-cols-[28px_minmax(0,1fr)] gap-x-3.5 rounded-xl px-3 py-3`,t===`now`&&`bg-ember-tint/40 ring-1 ring-ember-strong/25`),children:[(0,L.jsx)(`span`,{className:l(`grid size-7 place-items-center rounded-full font-semibold text-[0.8125rem]`,t===`done`&&`bg-moss text-white`,(t===`now`||t===`todo`)&&`bg-primary text-primary-foreground`,t===`later`&&`bg-paper text-ink-3 ring-1 ring-border`),children:t===`done`?(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}):e}),(0,L.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 pt-1`,children:[(0,L.jsx)(`span`,{className:l(`font-medium text-[0.9375rem]`,t===`later`&&`text-ink-2`),children:n}),r?(0,L.jsx)(`div`,{className:l(`flex flex-col gap-2`,t===`later`&&`opacity-70`),children:r}):null]})]})}function Pt({children:e}){return(0,L.jsxs)(y,{className:`p-3 sm:p-4`,children:[(0,L.jsx)(`h3`,{className:`px-3 pt-2 pb-2 font-medium text-[0.9375rem]`,children:o(`integrate.steps`)}),(0,L.jsx)(`ol`,{className:`flex flex-col gap-1`,children:e})]})}function Ft({app:e}){return(0,L.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.8125rem] text-ember-strong`,children:[(0,L.jsx)(`span`,{className:`size-2 rounded-full bg-ember`}),o(`integrate.waiting`,{app:e})]})}function It({client:e,seen:t}){let n=(e,t)=>(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[e?(0,L.jsx)(D,{className:`size-3.5 text-moss`,strokeWidth:3}):(0,L.jsx)(`span`,{className:`size-2.5 rounded-full ring-2 ring-ink-4 ring-inset`}),t]});return(0,L.jsxs)(`p`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-[0.8125rem] text-ink-2`,children:[n(!!t,o(`integrate.checkSeen`)),n(!!t?.toolAt,o(`integrate.checkTool`)),e.widgets?n(!!t?.widgetAt,o(`integrate.checkWidget`)):null]})}function Lt(){let e=he().data,{project:t}=ge(),n=i({queryKey:[`wizards`,t?.id,!!e?.account],queryFn:()=>O.get(`/api/studio/projects/${t.id}/wizards`),enabled:!!t}).data??[];return n.find(e=>e.published)??n[0]??null}function Rt({client:e,footer:t}){let n=Lt(),r=n?[{label:o(`integrate.labelRun`),text:o(`integrate.askRun`,{title:n.title})},{label:o(`integrate.labelBuild`),text:o(`integrate.askBuild`)},{label:o(`integrate.labelExplain`),text:o(`integrate.askExplain`,{title:n.title})}]:[{label:o(`integrate.labelAsk`),text:o(`integrate.askTool`)},{label:o(`integrate.labelBuild`),text:o(`integrate.askBuild`)}];return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(y,{className:`flex flex-col gap-4 p-5 sm:p-6`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:o(`integrate.next`)}),(0,L.jsx)(B,{children:o(`integrate.nextHint`,{app:e.name})})]}),(0,L.jsx)(`ul`,{className:`flex flex-col gap-2`,children:r.map(e=>(0,L.jsxs)(`li`,{className:`grid items-start gap-1 sm:grid-cols-[5.5rem_minmax(0,1fr)] sm:gap-3`,children:[(0,L.jsx)(`span`,{className:`pt-3 text-[0.75rem] text-ink-3`,children:e.label}),(0,L.jsx)(z,{text:e.text})]},e.label))})]}),e.widgets?null:(0,L.jsxs)(`p`,{className:`flex items-start gap-3 rounded-xl bg-paper-2 px-4 py-3 text-[0.875rem] text-ink-2 leading-relaxed`,children:[(0,L.jsx)(le,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),o(`integrate.textOnly`,{app:e.name})]}),t]})}function zt({children:e}){return(0,L.jsx)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-[0.8125rem] text-ink-3`,children:e})}var G=`inline-flex items-center gap-1 text-ember-strong underline-offset-2 transition hover:underline`;function Bt({client:e,local:t,seen:n,url:i}){let a=r(),[s,c]=(0,I.useState)(!1),[u,d]=(0,I.useState)(null),[f,p]=(0,I.useState)(!1),h=M({mutationFn:t=>O.post(`/api/studio/local/apps/${e.id}`,{connect:t}),onSuccess:e=>d(e),onError:e=>d({ok:!1,message:e.message}),onSettled:()=>a.invalidateQueries({queryKey:[`local-apps`]})}),g=!!t?.connected,_=!!n?.toolAt;if(s)return(0,L.jsx)(Vt,{client:e,seen:n,url:i,onBack:()=>c(!1)});let v=t=>(0,L.jsxs)(L.Fragment,{children:[t?(0,L.jsx)(`span`,{children:o(`integrate.addedIn`,{app:e.name})}):null,(0,L.jsxs)(`button`,{type:`button`,className:G,onClick:()=>p(!f),children:[o(`integrate.details`),(0,L.jsx)(w,{className:l(`size-3.5 transition`,f&&`rotate-90`)})]}),(0,L.jsx)(`button`,{type:`button`,className:G,disabled:h.isPending,onClick:()=>h.mutate(!1),children:o(`mcp.appsDisconnect`)})]}),y=f&&t?.where?(0,L.jsx)(`p`,{className:`w-full font-mono text-[0.6875rem] text-ink-4`,children:t.where}):null;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(U,{client:e,works:_,children:(0,L.jsx)(H,{client:e})}),_?(0,L.jsx)(Rt,{client:e,footer:(0,L.jsxs)(zt,{children:[v(!0),y]})}):(0,L.jsxs)(Pt,{children:[(0,L.jsxs)(W,{n:1,state:g?`done`:`now`,title:o(g?`integrate.connected`:`integrate.connect`,{app:e.name}),children:[g?(0,L.jsxs)(zt,{children:[v(!1),y]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:t?.installed===!1?o(`integrate.notInstalled`,{app:e.name}):o(`integrate.connectHint`,{app:e.name})}),(0,L.jsx)(`div`,{children:(0,L.jsxs)(A,{busy:h.isPending,onClick:()=>h.mutate(!0),children:[(0,L.jsx)(m,{className:`size-4`}),` `,o(`integrate.connect`,{app:e.name})]})})]}),u&&!u.ok?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:u.message}):null,u?.snippet?(0,L.jsx)(z,{text:u.snippet}):null]}),(0,L.jsx)(W,{n:2,state:n?`done`:g?`now`:`later`,title:o(`integrate.restart`,{app:e.name}),children:n?null:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.restartHint`)}),g?(0,L.jsx)(Ft,{app:e.name}):null]})}),(0,L.jsxs)(W,{n:3,state:n?`now`:`later`,title:o(`integrate.try`),children:[(0,L.jsx)(B,{children:o(`integrate.tryHint`)}),(0,L.jsx)(z,{text:o(`integrate.askTool`),muted:!n})]})]}),(0,L.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[0.875rem] text-ink-2`,children:[(0,L.jsx)(Fe,{className:`size-4 text-ink-3`}),o(`integrate.elsewhere`,{app:e.name}),(0,L.jsx)(`button`,{type:`button`,className:G,onClick:()=>c(!0),children:o(`integrate.byAddress`)})]})]})}function Vt({client:e,seen:t,url:n,onBack:i}){let a=r(),[s,c]=(0,I.useState)(),l=M({mutationFn:()=>O.post(`/api/studio/api-keys`,{name:e.name.slice(0,32)}),onSuccess:async e=>{c(e.key),await a.invalidateQueries({queryKey:[`api-keys`]})}}),u=(0,L.jsx)(`p`,{className:`text-[0.875rem]`,children:(0,L.jsxs)(`button`,{type:`button`,className:G,onClick:i,children:[(0,L.jsx)(De,{className:`size-4`}),o(`integrate.backHere`)]})});return t?.toolAt?(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(U,{client:e,works:!0,children:(0,L.jsx)(H,{client:e})}),(0,L.jsx)(Rt,{client:e,footer:u})]}):(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(U,{client:e,works:!1,children:(0,L.jsx)(H,{client:e})}),(0,L.jsxs)(Pt,{children:[(0,L.jsx)(W,{n:1,state:s?`done`:`now`,title:s?o(`integrate.keyReady`):o(`integrate.keyCreate`,{app:e.name}),children:s?null:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B,{children:o(`integrate.keyHint`,{app:e.name})}),(0,L.jsx)(`div`,{children:(0,L.jsxs)(A,{variant:`secondary`,busy:l.isPending,onClick:()=>l.mutate(),children:[(0,L.jsx)(F,{className:`size-4`}),` `,o(`integrate.keyCreate`,{app:e.name})]})})]})}),(0,L.jsx)(W,{n:2,state:s?t?`done`:`now`:`later`,title:o(`integrate.add`),children:s&&!t?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Dt,{id:e.id,url:n,apiKey:s}),(0,L.jsx)(`p`,{className:`text-[0.75rem] text-ink-4`,children:o(`integrate.addressLocal`)}),(0,L.jsx)(Ft,{app:e.name})]}):null}),(0,L.jsxs)(W,{n:3,state:t?`now`:`later`,title:o(`integrate.try`),children:[(0,L.jsx)(B,{children:o(`integrate.tryHint`)}),(0,L.jsx)(z,{text:o(`integrate.askTool`),muted:!t})]})]}),u]})}function Ht({app:e,host:t}){return(0,L.jsxs)(`div`,{"aria-hidden":`true`,className:`flex w-56 shrink-0 flex-col items-center gap-2 rounded-xl bg-paper px-4 py-3.5 text-center ring-1 ring-border-soft`,children:[(0,L.jsx)(`span`,{className:`font-display font-semibold text-[0.8125rem] leading-snug`,children:o(`integrate.consentPreview`,{app:e})}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.6875rem] text-moss`,children:[(0,L.jsx)(se,{className:`size-3`}),t]}),(0,L.jsxs)(`span`,{className:`flex w-full gap-1.5`,children:[(0,L.jsx)(`span`,{className:`h-5 flex-1 rounded-full bg-card ring-1 ring-border`}),(0,L.jsx)(`span`,{className:`h-5 flex-1 rounded-full bg-primary`})]})]})}function Ut({client:e,url:t,seen:n,tracked:r,accountUrl:i}){let s=St[e.id]??St[`claude-desktop`],c=e.id===`chatgpt`?`ChatGPT`:`Claude`;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(Pt,{children:[(0,L.jsx)(W,{n:1,state:`todo`,title:o(`integrate.open`,{app:e.name}),children:s.open?(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,L.jsxs)(A,{onClick:()=>j(s.open),children:[o(`integrate.openConnectors`),(0,L.jsx)(a,{className:`size-4`})]}),(0,L.jsx)(B,{children:o(s.where)})]}):(0,L.jsx)(B,{children:o(s.where)})}),(0,L.jsx)(W,{n:2,state:`todo`,title:o(`integrate.nameAddress`),children:(0,L.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:o(`integrate.name`)}),(0,L.jsx)(z,{text:yt})]}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,L.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:o(`integrate.address`)}),(0,L.jsx)(z,{text:t})]})]})}),(0,L.jsx)(W,{n:3,state:n?`done`:`todo`,title:o(`integrate.allow`),children:n?null:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,L.jsx)(`p`,{className:`min-w-0 flex-[1_1_16rem] text-[0.875rem] text-ink-3 leading-relaxed`,children:o(`integrate.allowHint`)}),(0,L.jsx)(Ht,{app:c,host:s.host})]})}),(0,L.jsxs)(W,{n:4,state:n?.toolAt?`done`:n?`now`:`later`,title:o(`integrate.try`),children:[n?.toolAt?null:(0,L.jsx)(z,{text:o(`integrate.askTool`),muted:!n}),r?(0,L.jsx)(It,{client:e,seen:n}):null]})]}),i?(0,L.jsx)(Wt,{accountUrl:i}):null]})}function Wt({accountUrl:e}){return(0,L.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-[0.8125rem] text-ink-3`,children:[o(`integrate.revoke`),(0,L.jsxs)(`button`,{type:`button`,className:G,onClick:()=>j(e),children:[o(`integrate.revokeLink`),(0,L.jsx)(k,{className:`size-3.5`})]})]})}function Gt({client:e,me:t,onDesktop:n}){let r=t.account?.signedIn?t.account:null,i=Me(!!r),a=t.features.account===!0;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(U,{client:e,works:!1,children:(0,L.jsx)(`p`,{className:`mt-2 max-w-2xl text-[0.9375rem] text-ink-2 leading-relaxed`,children:o(`integrate.remoteWhy`,{app:e.name})})}),r?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`p`,{className:`flex items-start gap-2 text-[0.875rem] text-ink-2`,children:[(0,L.jsx)(Oe,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),o(`integrate.linked`,{email:r.email,app:e.name})]}),(0,L.jsx)(Ut,{client:e,url:`${r.cloudUrl}/api/mcp`,tracked:!1,accountUrl:r.url})]}):a?(0,L.jsxs)(y,{className:`flex flex-col gap-5 p-5 sm:p-6`,children:[(0,L.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:o(`integrate.viaAccount`)}),(0,L.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[{icon:De,title:o(`integrate.tileHere`),text:o(`integrate.tileHereText`)},{icon:Oe,title:`engenty.ai`,text:o(`integrate.tileCloudText`)},{icon:Re,title:e.name,text:o(`integrate.tileAppText`)}].map(e=>(0,L.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl bg-paper px-4 py-3.5`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2 font-medium`,children:[(0,L.jsx)(e.icon,{className:`size-4 text-ink-2`}),e.title]}),(0,L.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 leading-relaxed`,children:e.text})]},e.title))}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,L.jsxs)(A,{busy:i.link.isPending,onClick:()=>i.link.mutate({}),children:[(0,L.jsx)(Oe,{className:`size-4`}),` `,o(`integrate.linkAccount`)]}),(0,L.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:o(`integrate.linkHint`,{app:e.name})})]}),(0,L.jsx)(de,{...i})]}):null,r?null:(0,L.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 rounded-xl bg-paper-2 px-4 py-3 text-[0.875rem] text-ink-2`,children:[o(`integrate.noAccount`),(0,L.jsxs)(`button`,{type:`button`,className:G,onClick:n,children:[o(`integrate.useDesktop`),(0,L.jsx)(k,{className:`size-3.5`})]})]})]})}function Kt({client:e,seen:t,url:n,me:r}){let i=!!t?.toolAt,a=r.manageUrl?`${r.manageUrl}/account`:null;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(U,{client:e,works:i,children:(0,L.jsx)(H,{client:e,signIn:!0})}),i?(0,L.jsx)(Rt,{client:e}):(0,L.jsxs)(Pt,{children:[(0,L.jsx)(W,{n:1,state:t?`done`:`now`,title:o(`integrate.add`),children:t?null:(0,L.jsx)(Dt,{id:e.id,url:n})}),(0,L.jsx)(W,{n:2,state:t?`done`:`later`,title:o(`integrate.allowFirst`),children:t?null:(0,L.jsx)(B,{children:o(`integrate.allowFirstHint`,{app:e.name})})}),(0,L.jsx)(W,{n:3,state:t?`now`:`later`,title:o(`integrate.try`),children:(0,L.jsx)(z,{text:o(`integrate.askTool`),muted:!t})})]}),a?(0,L.jsx)(Wt,{accountUrl:a}):null]})}function qt({client:e,standing:t,onOpen:n,onConnect:r,busy:i}){return(0,L.jsxs)(y,{className:`flex flex-col gap-3 p-4`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,L.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-[10px] bg-paper-2 text-ink-2`,children:e.widgets?(0,L.jsx)(ke,{className:`size-5`}):(0,L.jsx)(st,{className:`size-5`})}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`truncate font-medium`,children:e.name}),(0,L.jsxs)(`div`,{className:l(`flex items-center gap-1.5 text-[0.8125rem]`,t===`works`&&`font-medium text-moss`,t===`added`&&`text-ember-strong`,t===`none`&&`text-ink-3`),children:[t===`works`?(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}):null,o(jt[t])]})]})]}),(0,L.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[e.widgets?(0,L.jsx)(ke,{className:`size-3.5`}):(0,L.jsx)(le,{className:`size-3.5`}),o(e.widgets?`integrate.outWidget`:`integrate.outText`)]}),(0,L.jsx)(`div`,{children:t===`none`&&r?(0,L.jsx)(A,{size:`sm`,variant:`secondary`,busy:i,onClick:r,children:o(`integrate.connectShort`)}):(0,L.jsx)(A,{size:`sm`,variant:t===`added`?`primary`:`secondary`,onClick:n,children:o(t===`works`?`integrate.view`:t===`added`?`integrate.testIt`:`integrate.connectShort`)})})]})}function Jt({managed:e,here:t,web:n,standing:i,open:a}){let s=r(),c=M({mutationFn:e=>O.post(`/api/studio/local/apps/${e}`,{connect:!0}),onSettled:()=>s.invalidateQueries({queryKey:[`local-apps`]}),onSuccess:(e,t)=>a(t)}),l=(e,t)=>(0,L.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-[repeat(auto-fill,minmax(15rem,1fr))]`,children:e.map(e=>(0,L.jsx)(qt,{client:e,standing:i(e.id),onOpen:()=>a(e.id),onConnect:t?()=>c.mutate(e.id):void 0,busy:c.isPending&&c.variables===e.id},e.id))});return(0,L.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`h2`,{className:`font-display font-semibold text-[1.625rem] leading-tight tracking-tight`,children:o(`integrate.title`)}),(0,L.jsx)(`p`,{className:`mt-2 max-w-2xl text-[0.9375rem] text-ink-2 leading-relaxed`,children:o(e?`integrate.introManaged`:`integrate.intro`)})]}),e?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:o(`integrate.groupBrowser`)}),l(n,!1)]}),(0,L.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:o(`integrate.groupDesktop`)}),l(t,!1)]})]}):(0,L.jsxs)(L.Fragment,{children:[t.length?(0,L.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:o(`integrate.found`)}),l(t,!0)]}):null,(0,L.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,L.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:o(`integrate.groupCloud`)}),(0,L.jsxs)(y,{className:`flex flex-wrap items-center gap-4 p-5`,children:[(0,L.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-[10px] bg-paper-2 text-ink-2`,children:(0,L.jsx)(Oe,{className:`size-5`})}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-[1_1_18rem]`,children:[(0,L.jsx)(`div`,{className:`font-medium`,children:o(`integrate.cloudTitle`)}),(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-relaxed`,children:o(`integrate.cloudText`)})]}),(0,L.jsx)(A,{variant:`secondary`,onClick:()=>a(`claude-ai`),children:o(`integrate.cloudButton`)})]})]})]})]})}function Yt(){let e=he(),t=e.data?.mode===`managed`,n=i({queryKey:[`local-apps`],queryFn:()=>O.get(`/api/studio/local/apps`),enabled:e.data?.mode===`local`}),r=i({queryKey:[`integrations-seen`],queryFn:()=>O.get(`/api/studio/integrations/seen`),refetchInterval:2500}),[a,c]=s(),{narrow:l}=Ue(),u=a.get(`show`),d=xt.find(e=>e.id===u)??null;if(Ge(u===`wordpress`?`WordPress`:d?.name??null),!e.data||!t&&!n.data)return null;let f=e=>n.data?.find(t=>t.id===e),p=e=>r.data?.[e],m=e=>kt(f(e),p(e)),h=e=>c({show:e},{replace:!l}),_=e=>!!(f(e.id)?.installed||f(e.id)?.connected),v=xt.filter(e=>e.oauth),y=xt.filter(e=>!e.oauth&&(t||_(e))),b=t?[]:xt.filter(e=>!e.oauth&&!_(e)),x=e.data.mcpUrl??``,S=e=>(0,L.jsx)(N,{icon:e.oauth?Oe:e.widgets?ke:st,label:e.name,tone:At[m(e.id)],toneLabel:o(jt[m(e.id)]),selected:e.id===d?.id,onPick:()=>h(e.id)},e.id),C=e.data.manageUrl?`${e.data.manageUrl}/account`:null,w;return w=u===`wordpress`?(0,L.jsx)(Tt,{managed:t}):d?t&&(d.oauth||d.connector)?Ct(x)?(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(U,{client:d,works:!!p(d.id)?.toolAt,children:(0,L.jsx)(H,{client:d,signIn:!0})}),p(d.id)?.toolAt?(0,L.jsx)(Rt,{client:d,footer:C?(0,L.jsx)(Wt,{accountUrl:C}):null}):(0,L.jsx)(Ut,{client:d,url:x,seen:p(d.id),tracked:!0,accountUrl:C})]}):(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(U,{client:d,works:!1}),(0,L.jsx)(B,{children:o(`integrate.needsPublic`,{app:d.name})})]}):t?(0,L.jsx)(Kt,{client:d,seen:p(d.id),url:x,me:e.data}):d.oauth?(0,L.jsx)(Gt,{client:d,me:e.data,onDesktop:()=>h(`claude-desktop`)}):(0,L.jsx)(Bt,{client:d,local:f(d.id),seen:p(d.id),url:x}):(0,L.jsx)(Jt,{managed:t,here:y,web:v,standing:m,open:h}),(0,L.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,L.jsxs)(Ye,{children:[(0,L.jsx)(P,{label:o(t?`integrate.groupBrowser`:`integrate.groupHere`),children:(t?v:y).map(S)}),(0,L.jsx)(P,{label:o(t?`integrate.groupDesktop`:`integrate.groupCloud`),children:(t?y:v).map(S)}),b.length?(0,L.jsx)(P,{label:o(`integrate.groupMore`),collapsible:!0,open:b.some(e=>e.id===d?.id),count:b.length,children:b.map(S)}):null,(0,L.jsxs)(P,{label:o(`integrate.groupShare`),children:[(0,L.jsx)(N,{icon:g,label:o(`integrate.shareLink`),badge:(0,L.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4`,children:o(`integrate.soon`)}),selected:!1,disabled:!0}),(0,L.jsx)(N,{icon:Fe,label:`WordPress`,selected:u===`wordpress`,onPick:()=>h(`wordpress`)}),(0,L.jsx)(N,{icon:Fe,label:o(`integrate.shareSite`),badge:(0,L.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4`,children:o(`integrate.soon`)}),selected:!1,disabled:!0})]}),(0,L.jsx)(Nt,{})]}),(0,L.jsx)(`div`,{children:w},d?.id??`start`),t||u===`wordpress`?null:(0,L.jsx)(Ot,{})]})}var Xt=[`text`,`image`,`video`,`speech`,`listening`],Zt={text:[`classifier`,`standard`,`high`,`highest`],image:[`image`],video:[`video`],speech:[`speech`],listening:[`audio`]},Qt=`credits`,$t=`${Qt}:`;function en(e){return e===`credits`||!!e?.startsWith($t)}function tn(e){return e?.startsWith($t)&&e.slice($t.length)||null}function nn(e){return e?`${$t}${e}`:Qt}function rn(e){return e===`transcription`?`listening`:e}var an=[`openai`,`anthropic`,`google`,`fal`,`elevenlabs`,`replicate`,`gateway`],K=(e,t)=>({de:e,en:t}),on=[{id:`openai`,name:`OpenAI`,about:K(`GPT-Modelle, GPT Image und Stimmen.`,`GPT models, GPT Image and voices.`),keyUrl:`https://platform.openai.com/api-keys`,keyPlaceholder:`sk-…`,text:{classifier:`openai:gpt-5.4-mini`,standard:`openai:gpt-5.4-mini`,high:`openai:gpt-5.5`,highest:`openai:gpt-5.5`},models:{text:[{ref:`openai:gpt-5.4-mini`,label:`GPT-5.4 mini`,note:K(`schnell`,`fast`)},{ref:`openai:gpt-5.5`,label:`GPT-5.5`,note:K(`gründlich`,`thorough`)}],image:[{ref:`openai:gpt-image-2`,label:`GPT Image 2`,note:K(`vielseitig`,`versatile`)},{ref:`openai:gpt-image-1-mini`,label:`GPT Image 1 mini`,note:K(`günstig`,`low cost`)}],speech:[{ref:`openai:gpt-4o-mini-tts`,label:`GPT-4o mini TTS`,note:K(`günstig`,`low cost`)}],listening:[{ref:`openai:gpt-4o-mini-transcribe`,label:`GPT-4o mini Transcribe`,note:K(`schnell, günstig`,`fast, low cost`)},{ref:`openai:whisper-1`,label:`Whisper`}]}},{id:`anthropic`,name:`Anthropic`,about:K(`Die Claude-Modelle.`,`The Claude models.`),keyUrl:`https://console.anthropic.com/settings/keys`,keyPlaceholder:`sk-ant-…`,text:{classifier:`anthropic:claude-haiku-4-5`,standard:`anthropic:claude-haiku-4-5`,high:`anthropic:claude-sonnet-5-5`,highest:`anthropic:claude-opus-5-5`},models:{text:[{ref:`anthropic:claude-haiku-4-5`,label:`Claude Haiku 4.5`,note:K(`schnell`,`fast`)},{ref:`anthropic:claude-sonnet-5-5`,label:`Claude Sonnet 5.5`},{ref:`anthropic:claude-opus-5-5`,label:`Claude Opus 5.5`,note:K(`am stärksten`,`strongest`)}]}},{id:`google`,name:`Google Gemini`,about:K(`Gemini, Veo für Videos und Stimmen – ein Key aus dem AI Studio.`,`Gemini, Veo for video and voices – one key from AI Studio.`),keyUrl:`https://aistudio.google.com/apikey`,keyPlaceholder:`AIza…`,text:{classifier:`google:gemini-flash-lite-latest`,standard:`google:gemini-flash-latest`,high:`google:gemini-pro-latest`,highest:`google:gemini-pro-latest`},models:{text:[{ref:`google:gemini-flash-lite-latest`,label:`Gemini Flash-Lite`,note:K(`günstig`,`low cost`)},{ref:`google:gemini-flash-latest`,label:`Gemini Flash`},{ref:`google:gemini-pro-latest`,label:`Gemini Pro`,note:K(`gründlich`,`thorough`)}],image:[{ref:`google:gemini-3.1-flash-image-preview`,label:`Gemini 3.1 Flash Image`,note:K(`schnell, bearbeitet Fotos`,`fast, edits photos`)},{ref:`google:gemini-3-pro-image-preview`,label:`Gemini 3 Pro Image`,note:K(`beste Qualität`,`best quality`)}],video:[{ref:`google:veo-3.1-fast-generate-preview`,label:`Veo 3.1 Fast`,note:K(`mit Ton`,`with sound`)},{ref:`google:veo-3.1-generate-preview`,label:`Veo 3.1`,note:K(`beste Qualität`,`best quality`)}],speech:[{ref:`google:gemini-3.8-flash-tts`,label:`Gemini Flash TTS`}],listening:[{ref:`google:gemini-flash-lite-latest`,label:`Gemini Flash-Lite`}]}},{id:`fal`,name:`fal.ai`,about:K(`Hunderte Bild-, Video- und Audio-Modelle mit einem Key: FLUX, Recraft, Veo, Luma, MiniMax.`,`Hundreds of image, video and audio models with one key: FLUX, Recraft, Veo, Luma, MiniMax.`),keyUrl:`https://fal.ai/dashboard/keys`,keyPlaceholder:`xxxxxxxx-…:…`,models:{image:[{ref:`fal:fal-ai/flux/schnell`,label:`FLUX.1 schnell`,note:K(`schnell, günstig`,`fast, low cost`)},{ref:`fal:fal-ai/flux-pro/v1.1`,label:`FLUX 1.1 pro`,note:K(`hohe Qualität`,`high quality`)},{ref:`fal:fal-ai/recraft/v3/text-to-image`,label:`Recraft V3`,note:K(`Grafiken, Logos, Text im Bild`,`graphics, logos, text in images`)},{ref:`fal:fal-ai/imagen4/preview`,label:`Imagen 4`,note:K(`fotorealistisch`,`photorealistic`)}],video:[{ref:`fal:veo3/fast`,label:`Veo 3 Fast`,note:K(`mit Ton`,`with sound`)},{ref:`fal:luma-ray-2-flash`,label:`Luma Ray 2 Flash`,note:K(`schnell`,`fast`)},{ref:`fal:minimax-video`,label:`MiniMax Hailuo`}],speech:[{ref:`fal:fal-ai/minimax/speech-02-turbo`,label:`MiniMax Speech-02 Turbo`,note:K(`schnell`,`fast`)},{ref:`fal:fal-ai/minimax/speech-02-hd`,label:`MiniMax Speech-02 HD`}],listening:[{ref:`fal:wizper`,label:`Wizper`,note:K(`schnell`,`fast`)},{ref:`fal:whisper`,label:`Whisper`}]}},{id:`elevenlabs`,name:`ElevenLabs`,about:K(`Natürliche Stimmen in vielen Sprachen und genaue Transkripte.`,`Natural voices in many languages and accurate transcripts.`),keyUrl:`https://elevenlabs.io/app/settings/api-keys`,keyPlaceholder:`sk_…`,models:{speech:[{ref:`elevenlabs:eleven_multilingual_v2`,label:`Multilingual v2`,note:K(`natürlich, viele Sprachen`,`natural, many languages`)},{ref:`elevenlabs:eleven_flash_v2_5`,label:`Flash v2.5`,note:K(`schnell, günstig`,`fast, low cost`)},{ref:`elevenlabs:eleven_v3`,label:`Eleven v3`,note:K(`ausdrucksstark`,`expressive`)}],listening:[{ref:`elevenlabs:scribe_v2`,label:`Scribe v2`,note:K(`sehr genau`,`very accurate`)}]}},{id:`replicate`,name:`Replicate`,about:K(`Offene Bild- und Video-Modelle, abgerechnet pro Lauf.`,`Open image and video models, billed per run.`),keyUrl:`https://replicate.com/account/api-tokens`,keyPlaceholder:`r8_…`,models:{image:[{ref:`replicate:black-forest-labs/flux-schnell`,label:`FLUX.1 schnell`,note:K(`schnell, günstig`,`fast, low cost`)},{ref:`replicate:black-forest-labs/flux-1.1-pro`,label:`FLUX 1.1 pro`},{ref:`replicate:recraft-ai/recraft-v3`,label:`Recraft V3`}],video:[{ref:`replicate:minimax/video-01`,label:`MiniMax Video-01`}]}},{id:`gateway`,name:`Vercel AI Gateway`,about:K(`Ein Key für die Modelle vieler Anbieter, abgerechnet bei Vercel.`,`One key for many providers' models, billed by Vercel.`),keyUrl:`https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway%2Fapi-keys`,keyPlaceholder:`vck_…`,text:{classifier:`anthropic/claude-haiku-4.5`,standard:`anthropic/claude-haiku-4.5`,high:`anthropic/claude-sonnet-5.5`,highest:`anthropic/claude-sonnet-5.5`},models:{text:[{ref:`anthropic/claude-haiku-4.5`,label:`Claude Haiku 4.5`,note:K(`schnell`,`fast`)},{ref:`anthropic/claude-sonnet-5.5`,label:`Claude Sonnet 5.5`},{ref:`openai/gpt-5.5`,label:`GPT-5.5`},{ref:`google/gemini-3.5-flash`,label:`Gemini 3.5 Flash`}],image:[{ref:`google/gemini-3.1-flash-image`,label:`Gemini 3.1 Flash Image`}],video:[{ref:`google/veo-3.1-fast-generate-001`,label:`Veo 3.1 Fast`,note:K(`mit Ton`,`with sound`)}],speech:[{ref:`google/gemini-3.8-flash-tts`,label:`Gemini Flash TTS`}],listening:[{ref:`google/gemini-3.5-flash-lite`,label:`Gemini 3.5 Flash-Lite`}]}}];function q(e){return on.find(t=>t.id===e)??null}function sn(e){if(en(e))return null;let t=/^([a-z]+):/.exec(e)?.[1];return t?an.includes(t)?t:null:e?.includes(`/`)?`gateway`:null}function J(e){for(let t of on)for(let n of Object.values(t.models)){let t=n?.find(t=>t.ref===e);if(t)return t.label}return e.replace(/^[a-z]+:/,``)}function cn(e,t){let n=t===`auto`?e.mode===`managed`:t===`cloud`,r=t===`auto`||t===`linked`?e.account??(t===`linked`?{name:e.user.name,email:e.user.email,credits:1250,expiring:[],url:``,cloudUrl:``,signedIn:!0}:null):null;return{cloud:n,account:n?null:r,credits:n||!!r?.signedIn,balance:n?e.credits??(t===`cloud`?1250:null):r?.credits??null,topUp:Ae(e),harnesses:n?[]:e.harnesses,canEdit:!n||e.tenant.role!==`member`,ownKeys:!n||e.features.ownKeys!==!1}}var ln={text:h,image:Te,video:Le,speech:me,listening:et},Y={text:`standard`,image:`image`,video:`video`,speech:`speech`,listening:`audio`},X=e=>e===`text`,un=(e,t)=>e?.[t]??``;function dn(e,t){return JSON.stringify(e)===JSON.stringify(t)}function fn(e,t,n){let r=Y[t];if(X(t)&&!n.cloud){if(e.bindings.standard?.startsWith(`apple:`))return{kind:`local`,by:`apple`};if(e.source===`account`)return{kind:`credits`};if(e.source!==`own`)return{kind:`client`,id:e.source}}let i=e.bindings[r];if(en(i))return{kind:`credits`};if(i?.startsWith(`ollama:`))return{kind:`local`,by:`ollama`};if(i?.startsWith(`apple:`))return{kind:`local`,by:`apple`};let a=i?sn(i):null;if(a)return{kind:`key`,provider:a};if(i&&/^(claude|codex|gemini|cursor)\//.test(i))return{kind:`client`,id:i.split(`/`)[0]};let o=e.ways[r];switch(o.kind){case`client`:return{kind:`client`,id:o.by};case`key`:return q(o.by??``)?{kind:`key`,provider:o.by}:null;case`local`:return{kind:`local`,by:o.by===`apple`?`apple`:`ollama`};case`credits`:return{kind:`credits`};default:return null}}function pn(e,t,n){if(X(t)&&e.text)return e.text;let r=Y[t],i=n.bindings[r],a=i&&sn(i)===e.id?i:e.models[t]?.[0]?.ref;return a?{[r]:a}:{}}function mn(e){return e.version===null?{note:o(`models.noteMissing`),noteTone:`warn`}:e.auth===`none`?{note:o(`models.noteSignedOut`),noteTone:`warn`}:e.auth===`api_key`?{note:o(`models.noteShellKey`)}:{note:o(`models.noteIncluded`),noteTone:`done`}}function hn(e,t){switch(e.kind){case`client`:return{text:t.harnesses.find(t=>t.id===e.by)?.name??e.by??``,tone:`done`};case`key`:return{text:q(e.by??``)?.name??e.by??``,tone:`done`};case`local`:return{text:e.by===`apple`?o(`models.optApple`):o(`models.way.local`),tone:`done`};case`credits`:return{text:t.cloud?o(`models.way.creditsTeam`):o(`models.way.credits`),tone:`ok`};default:return{text:o(`models.way.none`),tone:`warn`}}}function gn(){return i({queryKey:[`models`],queryFn:()=>O.get(`/api/studio/models`)})}function Z(){let e=r();return M({mutationFn:e=>O.put(`/api/studio/models`,e),onSuccess:async t=>{e.setQueryData([`models`],t),await e.invalidateQueries({queryKey:[`me`]})}})}function Q({title:e,aside:t,children:n}){return(0,L.jsxs)(`section`,{className:`flex flex-col gap-3 border-border-soft border-t pt-5 first:border-t-0 first:pt-0`,children:[(0,L.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,L.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:e}),t]}),n]})}function $({children:e}){return(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:e})}function _n({text:e,tone:t}){return(0,L.jsxs)(`span`,{className:l(`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-full px-3 font-medium text-[0.75rem]`,t===`done`&&`bg-moss-tint text-moss`,t===`ok`&&`bg-amber-tint text-ink-2`,t===`warn`&&`bg-paper-2 text-ink-3`),children:[t===`done`?(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}):null,t===`ok`?(0,L.jsx)(Ee,{className:`size-3.5`}):null,t===`warn`?(0,L.jsx)(oe,{className:`size-3.5`}):null,e]})}function vn({icon:e,title:t,lead:n,status:r}){return(0,L.jsxs)(`div`,{className:`flex items-start gap-3 sm:gap-4`,children:[(0,L.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-xl bg-ember-tint text-ember-strong`,children:(0,L.jsx)(e,{className:`size-5`})}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,L.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight`,children:t}),r]}),(0,L.jsx)(`p`,{className:`mt-0.5 text-[0.875rem] text-ink-3`,children:n})]})]})}function yn({label:e,children:t}){return(0,L.jsxs)(`div`,{className:`grid items-start gap-x-4 gap-y-1.5 sm:grid-cols-[7.5rem_minmax(0,1fr)]`,children:[(0,L.jsx)(`span`,{className:`pt-2 text-[0.75rem] text-ink-3`,children:e}),(0,L.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t})]})}function bn({selected:e,title:t,note:n,noteTone:r,disabled:i,onPick:a}){return(0,L.jsxs)(`button`,{type:`button`,onClick:a,disabled:i,"aria-pressed":e,title:n,className:l(`inline-flex h-9 items-center gap-1.5 rounded-full border px-3.5 text-[0.8125rem] transition coarse:h-11`,e?`border-ember bg-ember-tint font-medium text-ink`:r===`done`?`border-input bg-card text-ink hover:border-ink-4`:`border-border-soft border-dashed text-ink-3 hover:border-ink-4 hover:text-ink`,i&&`cursor-not-allowed opacity-50`),children:[r===`done`?(0,L.jsx)(D,{className:`size-3.5 text-moss`,strokeWidth:3}):null,t,(0,L.jsxs)(`span`,{className:`sr-only`,children:[`: `,n]})]})}function xn({provider:e,stored:t,place:n}){let r=Z(),[i,s]=(0,I.useState)(``),[c,u]=(0,I.useState)(!1),[d,f]=(0,I.useState)(null),p=M({mutationFn:t=>O.post(`/api/studio/models/keys/${e.id}/check`,t?{key:t}:{})}),m=async()=>{f(null);let t=await p.mutateAsync(i.trim());if(!t.ok){f({ok:!1,message:t.message??o(`models.keyBad`)});return}await r.mutateAsync({keys:{[e.id]:i.trim()}}),s(``),u(!1),f({ok:!0,message:o(`models.keyOk`)})},h=!t||c;return n.ownKeys?(0,L.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[h?(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(x,{type:`password`,autoComplete:`off`,className:`min-w-0 flex-1 font-mono text-[0.8125rem]`,placeholder:e.keyPlaceholder,value:i,disabled:!n.canEdit,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i.trim()&&m()}}),(0,L.jsx)(A,{busy:p.isPending||r.isPending,disabled:!i.trim()||!n.canEdit,onClick:()=>void m(),children:o(`models.keySave`)}),c?(0,L.jsx)(A,{variant:`ghost`,onClick:()=>u(!1),children:o(`common.cancel`)}):null]}):(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[(0,L.jsxs)(`span`,{className:`flex items-center gap-2 text-[0.875rem] text-ink-2`,children:[(0,L.jsx)(F,{className:`size-4 text-moss`}),` `,o(`models.keyStored`)]}),(0,L.jsx)(A,{size:`sm`,variant:`ghost`,busy:p.isPending,onClick:async()=>{let e=await p.mutateAsync(void 0);f(e.ok?{ok:!0,message:o(`models.keyOk`)}:{ok:!1,message:e.message??o(`models.keyBad`)})},children:o(`models.keyCheck`)}),n.canEdit?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(A,{size:`sm`,variant:`ghost`,onClick:()=>u(!0),children:o(`models.keyReplace`)}),(0,L.jsx)(A,{size:`sm`,variant:`danger`,busy:r.isPending,onClick:()=>{f(null),r.mutate({keys:{[e.id]:``}})},children:o(`models.keyRemove`)})]}):null]}),d?(0,L.jsxs)(`p`,{className:l(`flex items-center gap-1.5 text-[0.8125rem]`,d.ok?`text-moss`:`text-rose`),children:[d.ok?(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}):null,d.message]}):null,(0,L.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.75rem] text-ink-4`,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>j(e.keyUrl),className:`inline-flex items-center gap-1 font-medium text-ember-strong hover:underline`,children:[o(`models.keyGet`,{name:e.name}),` `,(0,L.jsx)(a,{className:`size-3`})]}),(0,L.jsx)(`span`,{children:n.cloud?o(`models.keyWhereCloud`):o(`models.keyWhereLocal`)})]})]}):(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:o(`models.ownKeysPlan`)})}var Sn=`__custom__`;function Cn({provider:e,cap:t,value:n,onPick:r,disabled:i}){let a=d,s=e.models[t]??[],c=s.some(e=>e.ref===n),[l,u]=(0,I.useState)(!c&&!!n),[f,p]=(0,I.useState)(c?``:n.replace(/^[a-z]+:/,``)),m=e.id===`gateway`?``:`${e.id}:`;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,L.jsx)(v,{value:l?Sn:n,onChange:e=>{if(e===Sn){u(!0);return}u(!1),r(e)},options:[...s.map(e=>({value:e.ref,label:e.note?`${e.label} – ${un(e.note,a)}`:e.label})),{value:Sn,label:o(`models.modelCustom`)}]}),l?(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(x,{className:`min-w-0 flex-1 font-mono text-[0.8125rem]`,value:f,disabled:i,placeholder:s[0]?.ref.replace(/^[a-z]+:/,``)??``,onChange:e=>p(e.target.value)}),(0,L.jsx)(A,{variant:`secondary`,disabled:!f.trim()||i,onClick:()=>r(`${m}${f.trim()}`),children:o(`settings.save`)})]}):null]})}function wn({provider:e,state:t}){let n=n=>J(t.bindings[n]??e.text?.[n]??``);return(0,L.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1 text-[0.875rem]`,children:[(0,L.jsx)(`dt`,{className:`text-ink-3`,children:o(`models.textSimple`)}),(0,L.jsx)(`dd`,{className:`truncate font-medium`,children:n(`standard`)}),(0,L.jsx)(`dt`,{className:`text-ink-3`,children:o(`models.textDemanding`)}),(0,L.jsx)(`dd`,{className:`truncate font-medium`,children:n(`high`)})]})}function Tn({provider:e,state:t,onPick:n,disabled:r}){return(0,L.jsxs)(`details`,{className:`group rounded-lg ring-1 ring-border-soft`,children:[(0,L.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2.5 text-[0.8125rem] text-ink-2 hover:text-ink`,children:(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,L.jsx)(k,{className:`size-3.5 transition group-open:rotate-90`}),o(`models.perClass`)]})}),(0,L.jsx)(`div`,{className:`flex flex-col gap-3 px-3 pt-1 pb-3`,children:u.map(i=>(0,L.jsxs)(`div`,{className:`grid items-center gap-2 sm:grid-cols-[9rem_minmax(0,1fr)]`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[0.8125rem] text-ink-2`,children:o(`class.${i}`)}),(0,L.jsx)(`div`,{className:`text-[0.6875rem] text-ink-4 leading-snug`,children:o(`class.${i}.hint`)})]}),(0,L.jsx)(Cn,{provider:e,cap:`text`,value:t.bindings[i]??e.text?.[i]??``,disabled:r,onPick:e=>n(i,e)})]},i))})]})}function En({cap:e,disabled:t}){let n=Y[e],r=M({mutationFn:()=>O.post(`/api/studio/models/test`,{cls:n,lang:d})}),i=r.data;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,L.jsx)(A,{variant:`secondary`,busy:r.isPending,disabled:t,onClick:()=>r.mutate(),children:o(`models.try.${e}`)}),(0,L.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:e===`video`?o(`models.tryCostVideo`):X(e)?null:o(`models.tryCost`)})]}),r.isPending&&e!==`text`?(0,L.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,L.jsx)(ie,{className:`size-3.5`}),` `,o(e===`video`?`models.tryWaitVideo`:`models.tryWait`)]}):null,i?.ok?(0,L.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i.media&&e===`image`?(0,L.jsx)(`img`,{src:i.media,alt:``,className:`size-48 rounded-lg object-cover ring-1 ring-border-soft`}):null,i.media&&e===`speech`?(0,L.jsx)(`audio`,{src:i.media,controls:!0,autoPlay:!0,className:`w-full max-w-sm`}):null,i.media&&e===`video`?(0,L.jsx)(`video`,{src:i.media,controls:!0,autoPlay:!0,muted:!0,className:`w-full max-w-md rounded-lg`}):null,(0,L.jsxs)(`p`,{className:`flex items-start gap-2 text-[0.8125rem] text-ink-2`,children:[(0,L.jsx)(D,{className:`mt-0.5 size-3.5 shrink-0 text-moss`,strokeWidth:3}),(0,L.jsx)(`span`,{children:e===`listening`?i.reply?o(`models.tryHeard`,{text:i.reply}):o(`models.tryHeardNothing`):X(e)?o(`local.testOk`,{s:(i.ms/1e3).toFixed(1),ref:J(i.ref??``),reply:i.reply??``}):o(`models.tryOk`,{s:(i.ms/1e3).toFixed(1),model:J(i.ref??``)})})]})]}):null,i&&!i.ok?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:o(`models.tryFailed`,{error:i.error??``})}):null,r.isError?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:o(`models.tryFailed`,{error:r.error.message})}):null]})}function Dn(e){let t=e=>(e<10?Math.round(e*10)/10:Math.ceil(e)).toLocaleString();return e?.creditsPerImage?o(`models.notePerImage`,{n:t(e.creditsPerImage)}):e?.creditsPerSecond?o(`models.notePerSecond`,{n:t(e.creditsPerSecond)}):e?.creditsPer1kCharacters?o(`models.notePer1k`,{n:t(e.creditsPer1kCharacters)}):e?.creditsPerMinute?o(`models.notePerMinute`,{n:t(e.creditsPerMinute)}):o(`models.noteUsage`)}function On(e,t){let n=tn(t.bindings[Y[e]]);return Dn((n?t.creditModels.find(e=>e.id===n):null)??t.prices?.[Y[e]])}function kn(e,t,n){return e.creditModels.filter(e=>rn(e.kind)===t&&(!n||e.source===n||e.provider===n))}function An({cap:e,state:t,disabled:n}){let r=Z(),i=Y[e],a=tn(t.bindings[i]),s=kn(t,e),c=t.prices?.[i]?.model,l=e=>e.source===`ai-gateway`?q(e.provider)?.name??e.provider:q(e.source)?.name??e.source;return(0,L.jsx)(v,{value:a??``,onChange:e=>r.mutate({bindings:{[i]:nn(e||null)}}),options:[{value:``,label:c?o(`models.creditsAuto`,{model:J(c)}):o(`models.creditsAutoNone`)},...s.map(e=>({value:e.id,label:`${e.name} · ${l(e)} – ${Dn(e)}`,disabled:n}))]})}function jn({models:e,state:t,place:n}){let r=Z();return(0,L.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:e.map(e=>{let i=rn(e.kind),a=Y[i],s=t.bindings[a]===nn(e.id);return(0,L.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2.5`,children:[(0,L.jsx)(Ee,{className:`size-4 shrink-0 text-ink-3`}),(0,L.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`span`,{className:`block font-medium text-[0.875rem]`,children:e.name}),(0,L.jsxs)(`span`,{className:`block text-[0.75rem] text-ink-3`,children:[o(`models.cap.${i}`),` · `,Dn(e)]})]}),s?(0,L.jsxs)(`span`,{className:`flex items-center gap-1 font-medium text-[0.75rem] text-moss`,children:[(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}),` `,o(`models.inUse`)]}):(0,L.jsx)(A,{size:`sm`,variant:`secondary`,disabled:!n.canEdit||!n.credits,busy:r.isPending&&r.variables?.bindings?.[a]===nn(e.id),onClick:()=>r.mutate({bindings:{[a]:nn(e.id)}}),children:o(`models.useFor`)})]},e.id)})})}function Mn({cap:e,state:t,place:n,me:r,onOpen:i}){let a=Z(),s=Y[e],c=t.ways[s],l=fn(t,e,n),[u,d]=(0,I.useState)(!1),f=hn(c,n),p=n.harnesses.filter(t=>(X(e)||e===`image`&&t.images)&&(t.version!==null||l?.kind===`client`&&l.id===t.id)),m=on.filter(t=>t.models[e]?.length),h=r=>{if(d(!1),r.kind===`credits`&&!n.credits){d(!0);return}if(dn(r,l))return;let i=Zt[e],o=e=>Object.fromEntries(i.map(t=>[t,e]));switch(r.kind){case`client`:a.mutate(X(e)?{source:r.id,bindings:_e(t.bindings)}:{bindings:{[s]:`${r.id}/image`}});return;case`key`:{let i=q(r.provider);a.mutate({...X(e)&&!n.cloud?{source:`own`}:{},bindings:pn(i,e,t)});return}case`local`:a.mutate(r.by===`apple`?{bindings:X(e)?Nn(t):{audio:`apple:transcribe`}}:{source:`own`,bindings:o(`ollama:qwen3`)});return;case`credits`:a.mutate(X(e)&&!n.cloud?{source:`account`,bindings:_e(t.bindings)}:{bindings:o(Qt)});return}},g=l?.kind===`key`?q(l.provider):null,_=g?!t.keys[g.id]:!1,v=l?.kind===`client`?n.harnesses.find(e=>e.id===l.id):null,b=c.kind!==`none`;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(vn,{icon:ln[e],title:o(`models.cap.${e}`),lead:o(`models.cap.${e}.hint`),status:(0,L.jsx)(_n,{...f})}),(0,L.jsxs)(y,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,L.jsxs)(Q,{title:o(`models.who`),children:[(0,L.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[p.length?(0,L.jsx)(yn,{label:o(`models.optSubscription`),children:p.map(e=>(0,L.jsx)(bn,{title:e.name,...mn(e),selected:l?.kind===`client`&&l.id===e.id,disabled:!n.canEdit,onPick:()=>h({kind:`client`,id:e.id})},e.id))}):null,(0,L.jsx)(yn,{label:o(`models.optKey`),children:m.map(e=>(0,L.jsx)(bn,{title:e.name,note:t.keys[e.id]?o(`models.noteKey`):o(`models.noteNoKey`),noteTone:t.keys[e.id]?`done`:void 0,selected:l?.kind===`key`&&l.provider===e.id,disabled:!n.canEdit,onPick:()=>h({kind:`key`,provider:e.id})},e.id))}),(0,L.jsxs)(yn,{label:X(e)&&!n.cloud?o(`models.optOther`):o(`models.optCreditsGroup`),children:[(X(e)||e===`listening`)&&!n.cloud&&t.apple?.supported?(0,L.jsx)(bn,{title:o(`models.optApple`),note:X(e)?Pn(t.apple):o(`models.optAppleNote`),noteTone:X(e)&&!t.apple.available?void 0:`done`,selected:l?.kind===`local`&&l.by===`apple`,disabled:!n.canEdit||X(e)&&!t.apple.available,onPick:()=>h({kind:`local`,by:`apple`})}):null,X(e)&&!n.cloud?(0,L.jsx)(bn,{title:o(`models.optLocal`),note:o(`models.optLocalNote`),selected:l?.kind===`local`&&l.by===`ollama`,disabled:!n.canEdit,onPick:()=>h({kind:`local`,by:`ollama`})}):null,(0,L.jsx)(bn,{title:n.cloud?o(`models.creditsTeam`):o(`models.creditsName`),note:n.credits?On(e,t):o(`models.noteNeedsAccount`),noteTone:n.credits?`done`:void 0,selected:l?.kind===`credits`,disabled:!n.canEdit,onPick:()=>h({kind:`credits`})})]})]}),u?(0,L.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:[o(`local.sourceNeedsAccount`),` `,(0,L.jsx)(Bn,{})]}):null,a.isError?(0,L.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:a.error.message}):null]}),g?(0,L.jsxs)(L.Fragment,{children:[_?(0,L.jsxs)(Q,{title:o(`models.keyFor`,{name:g.name}),children:[(0,L.jsx)(xn,{provider:g,stored:!1,place:n}),n.credits?(0,L.jsxs)($,{children:[(0,L.jsx)(Ee,{className:`mr-1 inline size-3.5 align-[-2px]`}),o(`models.keyFallback`)]}):null]}):null,_&&n.credits&&kn(t,e,g.id).length?(0,L.jsx)(Q,{title:o(`models.viaCredits`,{name:g.name}),children:(0,L.jsx)(jn,{models:kn(t,e,g.id),state:t,place:n})}):null,(0,L.jsx)(Q,{title:o(`models.model`),aside:_?null:(0,L.jsx)(`button`,{type:`button`,onClick:()=>i({type:`provider`,id:g.id}),className:`text-[0.75rem] text-ink-3 hover:text-ink`,children:o(`models.manageKey`,{name:g.name})}),children:X(e)&&g.text?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(wn,{provider:g,state:t}),(0,L.jsx)(Tn,{provider:g,state:t,disabled:!n.canEdit,onPick:(e,t)=>a.mutate({bindings:{[e]:t}})})]}):(0,L.jsx)(Cn,{provider:g,cap:e,value:t.bindings[s]??g.models[e]?.[0]?.ref??``,disabled:!n.canEdit,onPick:e=>a.mutate({bindings:{[s]:e}})},`${g.id}:${t.bindings[s]??``}`)})]}):null,l?.kind===`client`&&v?X(e)?(0,L.jsx)(Q,{title:v.name,children:(0,L.jsx)(Qe,{me:r,id:v.id})}):(0,L.jsx)(Q,{title:v.name,children:(0,L.jsx)($,{children:o(`models.clientImages`,{name:v.name,sub:o(`harness.sub.${v.id}`)})})}):null,l?.kind===`local`?l.by===`apple`?(0,L.jsx)(Fn,{cap:e,state:t,place:n}):(0,L.jsx)(In,{state:t,disabled:!n.canEdit}):null,l?.kind===`credits`&&n.credits?X(e)?(0,L.jsx)(Q,{title:o(`models.creditsName`),children:(0,L.jsxs)($,{children:[o(`models.creditsPicks`),c.kind===`credits`&&c.ref?` ${o(`models.creditsModel`,{model:J(c.ref)})}`:``]})}):(0,L.jsxs)(Q,{title:o(`models.model`),children:[(0,L.jsx)(An,{cap:e,state:t,disabled:!n.canEdit}),(0,L.jsx)($,{children:o(`models.creditsPickHint`)})]}):null,c.problem?(0,L.jsxs)(`p`,{className:`flex items-start gap-2 rounded-lg bg-paper-2 px-3 py-2.5 text-[0.8125rem] text-ink-2`,children:[(0,L.jsx)(oe,{className:`mt-0.5 size-3.5 shrink-0 text-ink-3`}),(0,L.jsx)(`span`,{children:(0,L.jsx)(ne,{text:c.problem})})]}):null,l?.kind===`client`&&X(e)?null:(0,L.jsx)(Q,{title:o(`models.try`),children:(0,L.jsx)(En,{cap:e,disabled:!b||!n.canEdit},`${e}:${c.ref}`)}),X(e)&&r.subscriptions.includes(`claude`)&&!n.cloud?(0,L.jsx)(Ln,{me:r}):null]})]})}function Nn(e){let t=t=>{let n=e.bindings[t]??``;return/^(ollama|apple):/.test(n)?``:n};return{classifier:`apple:default`,standard:`apple:default`,high:t(`high`),highest:t(`highest`)}}function Pn(e){if(e.available)return o(`models.optAppleNote`);switch(e.reason){case`off`:return o(`models.appleOff`);case`loading`:return o(`models.appleLoading`);default:return o(`models.appleDevice`)}}function Fn({cap:e,state:t,place:n}){return(0,L.jsx)(Q,{title:o(`models.optApple`),children:(0,L.jsx)($,{children:X(e)?o(`models.appleHint`,{way:hn(t.ways.high,n).text}):o(`models.appleListenHint`)})})}function In({state:e,disabled:t}){let n=Z(),[r,i]=(0,I.useState)(e.ollamaUrl),[a,s]=(0,I.useState)((e.bindings.standard??`ollama:qwen3`).replace(/^ollama:/,``));return(0,L.jsxs)(Q,{title:o(`models.optLocal`),children:[(0,L.jsx)($,{children:o(`models.ollamaHint`)}),(0,L.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(0,1fr)_12rem_auto]`,children:[(0,L.jsx)(x,{className:`font-mono text-[0.8125rem]`,value:r,disabled:t,onChange:e=>i(e.target.value)}),(0,L.jsx)(x,{className:`font-mono text-[0.8125rem]`,value:a,disabled:t,onChange:e=>s(e.target.value)}),(0,L.jsx)(A,{variant:`secondary`,busy:n.isPending,disabled:t||!a.trim(),onClick:()=>n.mutate({ollamaUrl:r,bindings:Object.fromEntries(u.map(e=>[e,`ollama:${a.trim()}`]))}),children:o(`settings.save`)})]})]})}function Ln({me:e}){let t=r(),n=M({mutationFn:e=>O.put(`/api/studio/local/chat`,{engine:e}),onSuccess:()=>t.invalidateQueries({queryKey:[`me`]})});return(0,L.jsxs)(Q,{title:o(`local.chat`),children:[(0,L.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[`models`,`claude`].map(t=>(0,L.jsx)(`button`,{type:`button`,"aria-pressed":e.chatEngine===t,onClick:()=>n.mutate(t),className:l(`h-9 rounded-full border px-3.5 text-[0.8125rem] transition`,e.chatEngine===t?`border-ember bg-ember-tint text-ink`:`border-input bg-card text-ink-2 hover:text-ink`),children:o(t===`claude`?`local.chatClaude`:`local.chatModels`)},t))}),(0,L.jsx)($,{children:o(`local.subscription`)})]})}function Rn({provider:e,state:t,place:n,onOpen:r}){let i=Z(),a=Xt.filter(t=>e.models[t]?.length),s=t.keys[e.id],c=e.id===`gateway`?[]:t.creditModels.filter(t=>t.source===e.id||t.provider===e.id);return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(vn,{icon:F,title:e.name,lead:un(e.about,d),status:(0,L.jsx)(_n,{text:o(s?`models.keyStored`:`models.keyNone`),tone:s?`done`:`warn`})}),(0,L.jsxs)(y,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,L.jsx)(Q,{title:o(`models.key`),children:(0,L.jsx)(xn,{provider:e,stored:s,place:n})}),(0,L.jsx)(Q,{title:o(`models.uses`),children:(0,L.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:a.map(a=>{let s=ln[a],c=fn(t,a,n),l=c?.kind===`key`&&c.provider===e.id;return(0,L.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2.5`,children:[(0,L.jsx)(s,{className:`size-4 shrink-0 text-ink-3`}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>r({type:`cap`,id:a}),className:`min-w-0 flex-1 text-left`,children:[(0,L.jsx)(`span`,{className:`block font-medium text-[0.875rem]`,children:o(`models.cap.${a}`)}),(0,L.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:(e.models[a]??[]).map(e=>e.label).join(` · `)})]}),l?(0,L.jsxs)(`span`,{className:`flex items-center gap-1 font-medium text-[0.75rem] text-moss`,children:[(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}),` `,o(`models.inUse`)]}):(0,L.jsx)(A,{size:`sm`,variant:`secondary`,disabled:!n.canEdit,busy:i.isPending&&i.variables?.bindings!==void 0,onClick:()=>i.mutate({...X(a)&&!n.cloud?{source:`own`}:{},bindings:pn(e,a,t)}),children:o(`models.useFor`)})]},a)})})}),c.length?(0,L.jsxs)(Q,{title:o(`models.viaCredits`,{name:e.name}),children:[(0,L.jsx)($,{children:n.credits?o(`models.viaCreditsHint`):o(`models.viaCreditsNeedsAccount`)}),(0,L.jsx)(jn,{models:c,state:t,place:n})]}):null]})]})}function zn({me:e,id:t,state:n,place:r}){let i=Z(),a=r.harnesses.find(e=>e.id===t);if(!a)return null;let s=n.source===t,c=a.version!==null&&a.auth!==`none`;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(vn,{icon:Be,title:a.name,lead:o(`harness.desc.${t}`),status:(0,L.jsx)(_n,{text:mn(a).note,tone:c?`done`:`warn`})}),(0,L.jsxs)(y,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,L.jsx)(Q,{title:o(`models.clientSignIn`),children:(0,L.jsx)(Qe,{me:e,id:t})}),(0,L.jsxs)(Q,{title:o(`models.uses`),children:[(0,L.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:[`text`,...a.images?[`image`]:[]].map(e=>{let a=ln[e],s=fn(n,e,r),c=s?.kind===`client`&&s.id===t;return(0,L.jsxs)(`li`,{className:`flex items-center gap-3 py-2.5`,children:[(0,L.jsx)(a,{className:`size-4 shrink-0 text-ink-3`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 font-medium text-[0.875rem]`,children:o(`models.cap.${e}`)}),c?(0,L.jsxs)(`span`,{className:`flex items-center gap-1 font-medium text-[0.75rem] text-moss`,children:[(0,L.jsx)(D,{className:`size-3.5`,strokeWidth:3}),` `,o(`models.inUse`)]}):(0,L.jsx)(A,{size:`sm`,variant:`secondary`,busy:i.isPending,onClick:()=>i.mutate(e===`text`?{source:t,bindings:_e(n.bindings)}:{bindings:{image:`${t}/image`}}),children:o(`models.useFor`)})]},e)})}),s?null:(0,L.jsx)($,{children:o(`models.clientNotChosen`,{name:a.name})})]})]})]})}function Bn(){return(0,L.jsx)(S,{to:`/settings/account`,className:`font-medium text-ember-strong underline-offset-2 hover:underline`,children:o(`local.toAccount`)})}function Vn({state:e,place:t,onOpen:n}){let r=Z(),i=Xt.filter(t=>e.ways[Y[t]].kind===`credits`),s=t.cloud?o(`models.creditsTeam`):o(`models.creditsName`);return(0,L.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,L.jsx)(vn,{icon:Ee,title:s,lead:t.cloud?o(`models.creditsCloudHint`):o(`models.creditsLocalLead`),status:t.balance===null?void 0:(0,L.jsx)(`span`,{className:`font-display font-semibold text-[1.25rem] tabular-nums`,children:o(`nav.credits`,{n:Math.floor(t.balance).toLocaleString()})})}),(0,L.jsxs)(y,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[!t.cloud&&!t.account?(0,L.jsxs)(Q,{title:o(`models.creditsConnectTitle`),children:[(0,L.jsx)($,{children:o(`models.creditsLocalHint`)}),(0,L.jsx)(`div`,{children:(0,L.jsx)(S,{to:`/settings/account`,children:(0,L.jsx)(A,{children:o(`models.creditsConnect`)})})})]}):null,t.account&&!t.account.signedIn?(0,L.jsxs)(`p`,{className:`text-[0.8125rem] text-rose`,children:[o(`local.accountExpired`),` `,(0,L.jsx)(Bn,{})]}):null,t.account?(0,L.jsx)(Q,{title:o(`models.creditsFallback`),children:(0,L.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,L.jsx)(c,{checked:e.creditFallback,disabled:!t.canEdit,onChange:e=>r.mutate({creditFallback:e}),label:o(`models.creditsFallback`)}),(0,L.jsx)($,{children:e.creditFallback?o(`models.creditsFallbackOn`):o(`models.creditsFallbackOff`)})]})}):null,t.credits?(0,L.jsx)(Q,{title:o(`models.creditsOn`),aside:t.topUp?(0,L.jsxs)(`a`,{href:t.topUp,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 font-medium text-[0.8125rem] text-ember-strong hover:underline`,children:[o(`models.creditsTopUp`),` `,(0,L.jsx)(a,{className:`size-3`})]}):null,children:i.length?(0,L.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:i.map(t=>{let r=ln[t],i=e.ways[Y[t]];return(0,L.jsx)(`li`,{children:(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n({type:`cap`,id:t}),className:`flex w-full items-center gap-3 py-2.5 text-left`,children:[(0,L.jsx)(r,{className:`size-4 shrink-0 text-ink-3`}),(0,L.jsx)(`span`,{className:`min-w-0 flex-1 font-medium text-[0.875rem]`,children:o(`models.cap.${t}`)}),(0,L.jsxs)(`span`,{className:`truncate text-[0.75rem] text-ink-3`,children:[i.ref?J(i.ref):``,` · `,On(t,e)]})]})},t)})}):(0,L.jsx)($,{children:o(`models.creditsNone`)})}):null]})]})}function Hn(e){return e?e===`credits`?{type:`credits`}:Xt.includes(e)?{type:`cap`,id:e}:q(e)?{type:`provider`,id:e}:{type:`client`,id:e}:{type:`cap`,id:`text`}}var Un=e=>e.type===`credits`?`credits`:e.id;function Wn({view:e,onView:t}){return null}function Gn(e){return e.kind===`none`?`off`:e.kind===`credits`?`credits`:`done`}function Kn(e,t){switch(e.type){case`cap`:return o(`models.cap.${e.id}`);case`provider`:return q(e.id)?.name??e.id;case`client`:return t?.harnesses.find(t=>t.id===e.id)?.name??e.id;default:return t?.mode===`managed`?o(`models.creditsTeam`):o(`models.creditsName`)}}function qn(){let e=he(),t=gn(),[n,r]=s(),[i,a]=(0,I.useState)(`auto`),{narrow:c}=Ue(),l=n.get(`show`),u=Hn(l);if(Ge(l||!c?Kn(u,e.data):null),!e.data||!t.data)return t.isError?(0,L.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:t.error.message}):null;let d=t.data,f=cn(e.data,i),p=e=>r({show:Un(e)},{replace:!c}),m=e=>!(!l&&c)&&Un(e)===Un(u),h=f.harnesses.filter(e=>e.version!==null||d.source===e.id),g=on.filter(e=>d.keys[e.id]),_=on.filter(e=>!d.keys[e.id]);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(Ye,{children:[(0,L.jsx)(P,{label:o(`models.groupCaps`),children:Xt.map(e=>{let t=d.ways[Y[e]];return(0,L.jsx)(N,{icon:ln[e],label:o(`models.cap.${e}`),tone:Gn(t),toneLabel:hn(t,f).text,selected:m({type:`cap`,id:e}),onPick:()=>p({type:`cap`,id:e})},e)})}),(0,L.jsxs)(P,{label:o(`models.groupAccess`),children:[(0,L.jsx)(N,{icon:Ee,label:f.cloud?o(`models.creditsTeam`):o(`models.creditsName`),badge:f.balance===null?null:(0,L.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:Math.floor(f.balance).toLocaleString()}),tone:f.credits?void 0:`off`,toneLabel:f.credits?void 0:o(`models.noteNeedsAccount`),selected:m({type:`credits`}),onPick:()=>p({type:`credits`})}),h.map(e=>(0,L.jsx)(N,{icon:Be,label:e.name,tone:e.version!==null&&e.auth===`subscription`?`done`:e.auth===`api_key`?`on`:`off`,toneLabel:mn(e).note,selected:m({type:`client`,id:e.id}),onPick:()=>p({type:`client`,id:e.id})},e.id)),g.map(e=>(0,L.jsx)(N,{icon:F,label:e.name,tone:`done`,toneLabel:o(`models.noteKey`),selected:m({type:`provider`,id:e.id}),onPick:()=>p({type:`provider`,id:e.id})},e.id))]}),_.length?(0,L.jsx)(P,{label:o(`models.groupMore`),collapsible:!0,open:_.some(e=>m({type:`provider`,id:e.id})),count:_.length,children:_.map(e=>(0,L.jsx)(N,{icon:F,label:e.name,selected:m({type:`provider`,id:e.id}),onPick:()=>p({type:`provider`,id:e.id})},e.id))}):null,(0,L.jsx)(Wn,{view:i,onView:a})]}),f.canEdit?null:(0,L.jsx)(`p`,{className:`mb-4 rounded-lg bg-paper-2 px-3 py-2 text-[0.8125rem] text-ink-2`,children:o(`models.readOnly`)}),u.type===`cap`?(0,L.jsx)(Mn,{cap:u.id,state:d,place:f,me:e.data,onOpen:p},u.id):u.type===`provider`&&q(u.id)?(0,L.jsx)(Rn,{provider:q(u.id),state:d,place:f,onOpen:p},u.id):u.type===`client`?(0,L.jsx)(zn,{me:e.data,id:u.id,state:d,place:f},u.id):(0,L.jsx)(Vn,{state:d,place:f,onOpen:p})]})}function Jn({name:e,image:t}){return t?(0,L.jsx)(`img`,{src:t,alt:``,className:`size-9 shrink-0 rounded-full object-cover`}):(0,L.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 font-medium text-[0.75rem] text-ink-2`,children:ye(e)})}function Yn({me:e}){let t=i({queryKey:[`team`,e.tenant.id],queryFn:()=>O.get(`/api/studio/team`)}),n=t.data,r=n?.plan??e.tenant.plan,s=n?.seats;return(0,L.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,L.jsxs)(be,{title:o(`team.title`),hint:o(`team.hint`),children:[(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:o(`team.plan`)}),(0,L.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:r?.name??o(`team.planFree`)}),s?(0,L.jsx)(b,{children:s.limit===null?o(`team.seatsUnlimited`):o(`team.seats`,{taken:s.taken,limit:s.limit})}):null]})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsxs)(A,{variant:`secondary`,onClick:()=>j(`${e.manageUrl}/billing`),children:[o(`team.changePlan`),` `,(0,L.jsx)(a,{className:`size-4`})]}),n?.canManage?(0,L.jsxs)(A,{onClick:()=>j(`${e.manageUrl}/`),children:[o(`team.manage`),` `,(0,L.jsx)(a,{className:`size-4`})]}):null]})]}),(0,L.jsx)(`p`,{className:`mt-4 text-[0.8125rem] text-ink-3 leading-relaxed`,children:e.tenant.role===`member`?o(`team.memberNote`):o(`team.roles`)})]}),(0,L.jsx)(be,{title:o(`team.members`),children:t.isPending?(0,L.jsx)(ie,{}):t.isError||!n?(0,L.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:o(`team.failed`)}):(0,L.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[n.members.map(t=>(0,L.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,L.jsx)(Jn,{name:t.name,image:t.image}),(0,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsxs)(`div`,{className:`truncate text-[0.9375rem]`,children:[t.name,t.userId===e.user.id?(0,L.jsxs)(`span`,{className:`text-ink-4`,children:[` · `,o(`team.you`)]}):null]}),(0,L.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:t.email})]}),(0,L.jsx)(b,{tone:t.role===`member`?void 0:`live`,children:o(`team.role.${t.role}`)})]},t.userId)),n.invitations.map(e=>(0,L.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,L.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 text-ink-3`,children:(0,L.jsx)(rt,{className:`size-4`})}),(0,L.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-[0.9375rem]`,children:e.email}),(0,L.jsxs)(b,{tone:`warn`,children:[o(`team.invited`),` · `,o(`team.role.${e.role}`)]})]},e.id)),n.members.length===0&&n.invitations.length===0?(0,L.jsxs)(`div`,{className:`flex items-center gap-3 text-[0.875rem] text-ink-3`,children:[(0,L.jsx)(xe,{className:`size-4`}),` –`]}):null]})})]})}function Xn(e,t){let n=e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/^[^a-z]+/,``).slice(0,24)||`system`,r=n,i=2;for(;t.includes(r);)r=`${n}_${i++}`;return r}function Zn({project:e}){let t=r(),[n,i]=(0,I.useState)(e.mcpServers.map(e=>({...e,auth:e.headers?.Authorization??e.headers?.authorization??``}))),[a,s]=(0,I.useState)(!1),c=e.readOnly,l=M({mutationFn:()=>O.patch(`/api/studio/projects/${e.id}`,{mcpServers:n.filter(e=>e.name&&e.url).map(({auth:e,headers:t,...n})=>({...n,headers:e?{...t,Authorization:e}:void 0}))}),onSuccess:async()=>{await t.invalidateQueries({queryKey:[`projects`]}),s(!0),setTimeout(()=>s(!1),1800)}});return(0,L.jsxs)(y,{className:`p-4 sm:p-6`,children:[(0,L.jsx)(`h2`,{className:`font-display font-semibold text-lg`,children:o(`settings.mcp`)}),(0,L.jsx)(`p`,{className:`mt-1 mb-5 text-[0.875rem] text-ink-3`,children:o(`settings.mcpHint`)}),(0,L.jsxs)(`fieldset`,{disabled:c,className:`flex min-w-0 flex-col gap-3`,children:[n.map((e,t)=>(0,L.jsxs)(`div`,{className:`grid gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft sm:grid-cols-[1fr_2fr_auto]`,children:[(0,L.jsx)(x,{placeholder:o(`settings.serverName`),value:e.name,onChange:e=>i(n=>n.map((r,i)=>i===t?{...r,name:e.target.value,id:r.id||Xn(e.target.value,n.map(e=>e.id))}:r))}),(0,L.jsx)(x,{placeholder:`${o(`settings.serverUrl`)} (https://…/mcp)`,value:e.url,onChange:e=>i(n=>n.map((n,r)=>r===t?{...n,url:e.target.value}:n))}),c?(0,L.jsx)(`span`,{}):(0,L.jsx)(C,{label:`Entfernen`,onClick:()=>i(e=>e.filter((e,n)=>n!==t)),className:`hover:text-rose`,children:(0,L.jsx)(f,{className:`size-4`})}),(0,L.jsx)(x,{className:`sm:col-span-2`,placeholder:o(`settings.serverHeader`),value:e.auth??``,onChange:e=>i(n=>n.map((n,r)=>r===t?{...n,auth:e.target.value}:n))}),e.id?(0,L.jsx)(`span`,{className:`self-center font-mono text-[0.6875rem] text-ink-4`,children:e.id}):null]},t)),c?null:(0,L.jsxs)(A,{variant:`secondary`,className:`self-start`,onClick:()=>i(e=>[...e,{id:``,name:``,url:``,auth:``}]),children:[(0,L.jsx)(m,{className:`size-4`}),` `,o(`settings.addServer`)]})]}),c?null:(0,L.jsxs)(`div`,{className:`mt-5 flex items-center justify-end gap-3`,children:[l.error?(0,L.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l.error.message}):null,(0,L.jsx)(A,{busy:l.isPending,onClick:()=>l.mutate(),children:o(a?`settings.saved`:`settings.save`)})]})]})}var Qn=new Set([`models`,`integrate`]);function $n(){let{section:e}=p(),[t]=s(),n=re(),r=he(),{project:i,loading:a}=ge(),c=fe(),[u,d]=(0,I.useState)(i?.id);(0,I.useEffect)(()=>d(i?.id),[i?.id]);let f=Pe(),m=Ze(),[h,g]=(0,I.useState)(null),[v,y]=(0,I.useState)(null),[b,x]=(0,I.useState)(null),S=je(r.data,f),C=S.find(t=>t.id===e),w=S.map(e=>({...e,to:`/settings/${e.id}`})),te=w.find(t=>t.id===e),T=C?Qn.has(C.id):!1,E=C?T&&!t.get(`show`)?1:2:0,D=m?Math.min(E,1):T&&b!==e?1:0,O=We(D),k=We(E),A=(0,I.useMemo)(()=>({slot:h,narrow:m,setDetail:y}),[h,m]);if(Ie(C?.id===`models`?{suggestions:[{label:o(`assistant.suggest.modelsNow`)},{label:o(`assistant.suggest.modelsMissing`)},{label:o(`assistant.suggest.modelsCost`)}]}:C?.id===`account`?{suggestions:[{label:o(`assistant.suggest.credits`)},{label:o(`assistant.suggest.accountWhy`)},{label:o(`assistant.suggest.plans`)}]}:C?.id===`integrate`?{suggestions:[{label:o(`assistant.suggest.integrateWhat`)},{label:o(`assistant.suggest.integrateClaude`)},{label:o(`assistant.suggest.what`)}]}:C?.id===`connectors`?{suggestions:[{label:o(`assistant.suggest.connectorsWhat`)},{label:o(`assistant.suggest.connectorsAdd`),fill:!0},{label:o(`assistant.suggest.what`)}]}:{}),Ce([{label:o(`settings.title`),to:`/settings`},...C?[{label:C.label,to:`/settings/${C.id}`}]:[],...C&&v?[{label:v}]:[]]),!C){if(e===`build`)return(0,L.jsx)(_,{to:`/settings/integrate`,replace:!0});if(e===`project`)return(0,L.jsx)(_,{to:`/space`,replace:!0});if(e!==void 0||!m)return f.status===`ready`||e===void 0?(0,L.jsx)(_,{to:`/settings/account`,replace:!0}):null}let ne=C?.id===`connectors`&&c;return(0,L.jsx)(qe.Provider,{value:A,children:(0,L.jsx)(`div`,{className:`animate-rise`,children:(0,L.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`,children:[(0,L.jsxs)(`aside`,{className:l(`min-w-0 md:sticky md:top-6 md:self-start`,m&&E===2&&`hidden`,m&&k===`back`&&He(`back`)),children:[(0,L.jsx)(Ke,{title:o(`settings.title`),open:D===1?te??null:null,onBack:()=>m?n(`/settings`):x(e??null)}),(0,L.jsx)(`div`,{className:l(He(O)),children:D===0?(0,L.jsx)(Je,{entries:w,current:m?void 0:te,onPick:()=>x(null)}):(0,L.jsx)(`div`,{ref:g})},D)]}),C?(0,L.jsxs)(`div`,{className:l(`min-w-0`,![`integrate`,`models`].includes(C.id)&&`max-w-2xl`,m&&E<2&&`hidden`,m&&k===`deeper`&&He(`deeper`)),children:[m?(0,L.jsx)(`div`,{className:`mb-3`,children:(0,L.jsx)(Xe,{label:T?C.label:o(`settings.title`),onBack:()=>n(T?`/settings/${C.id}`:`/settings`)})}):null,ne?(0,L.jsx)(`div`,{className:`mb-6`,children:(0,L.jsx)(Ve,{})}):null,C.id===`connectors`&&i?(0,L.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[i.readOnly?(0,L.jsx)(ue,{children:ce(i)}):null,(0,L.jsx)(vt,{projectId:i.id,readOnly:i.readOnly},u),(0,L.jsx)(Zn,{project:i},u)]}):null,C.id===`connectors`&&!i&&!a?(0,L.jsx)(ee,{children:o(`settings.noProject`)}):null,C.id===`models`?(0,L.jsx)(qn,{}):null,C.id===`integrate`?(0,L.jsx)(Yt,{}):null,C.id===`account`&&r.data?(0,L.jsx)(Ne,{me:r.data}):null,C.id===`team`&&r.data?(0,L.jsx)(Yn,{me:r.data}):null,C.id===`plugins`?(0,L.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,L.jsx)(ct,{}),(0,L.jsx)(pt,{})]}):null,C.plugin?(0,L.jsx)(ze,{of:C.plugin,children:(0,L.jsx)(C.plugin.component,{})}):null]}):null]})})})}export{$n as SettingsPage};