wizards 0.4.3 → 0.4.5

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 (129) hide show
  1. package/apps/runtime/dist/agents/architect.js +32 -13
  2. package/apps/runtime/dist/agents/subscription.js +12 -12
  3. package/apps/runtime/dist/app.js +9 -5
  4. package/apps/runtime/dist/assistant/knows.js +2 -2
  5. package/apps/runtime/dist/authoring/example.js +21 -20
  6. package/apps/runtime/dist/authoring/guide.js +4 -2
  7. package/apps/runtime/dist/connectors/imap.js +4 -4
  8. package/apps/runtime/dist/connectors/index.js +40 -15
  9. package/apps/runtime/dist/connectors/plugin-connections.js +3 -2
  10. package/apps/runtime/dist/connectors/via-account.js +8 -6
  11. package/apps/runtime/dist/docs/dev/plugins/connections.md +1 -1
  12. package/apps/runtime/dist/docs/dev/plugins/reference.md +5 -1
  13. package/apps/runtime/dist/docs/dev/plugins/routes.md +35 -1
  14. package/apps/runtime/dist/docs/dev/plugins/server.md +27 -1
  15. package/apps/runtime/dist/docs/dev/plugins/starters.md +1 -1
  16. package/apps/runtime/dist/documents/parse.js +5 -3
  17. package/apps/runtime/dist/engine/events.js +1 -1
  18. package/apps/runtime/dist/engine/input.js +28 -8
  19. package/apps/runtime/dist/engine/prepare.js +2 -2
  20. package/apps/runtime/dist/engine/requirements.js +12 -3
  21. package/apps/runtime/dist/engine/runner.js +34 -23
  22. package/apps/runtime/dist/engine/steps.js +6 -5
  23. package/apps/runtime/dist/engine/surface.js +2 -1
  24. package/apps/runtime/dist/engine/template.js +1 -1
  25. package/apps/runtime/dist/engine/types.js +2 -1
  26. package/apps/runtime/dist/film/project.js +1 -1
  27. package/apps/runtime/dist/film/skills.js +2 -2
  28. package/apps/runtime/dist/film/sounds.js +1 -1
  29. package/apps/runtime/dist/film/step.js +7 -4
  30. package/apps/runtime/dist/film/tools.js +1 -1
  31. package/apps/runtime/dist/geocode.js +1 -1
  32. package/apps/runtime/dist/harness/apple.js +0 -5
  33. package/apps/runtime/dist/harness/claude.js +2 -1
  34. package/apps/runtime/dist/harness/codex.js +2 -1
  35. package/apps/runtime/dist/harness/model.js +4 -3
  36. package/apps/runtime/dist/harness/terminal.js +4 -3
  37. package/apps/runtime/dist/manage.js +29 -0
  38. package/apps/runtime/dist/model-errors.js +8 -3
  39. package/apps/runtime/dist/models.js +58 -38
  40. package/apps/runtime/dist/plugins/channels.js +77 -0
  41. package/apps/runtime/dist/plugins/loader.js +9 -1
  42. package/apps/runtime/dist/plugins/public.js +16 -2
  43. package/apps/runtime/dist/plugins/registry.js +1 -0
  44. package/apps/runtime/dist/plugins/runs.js +2 -1
  45. package/apps/runtime/dist/routes/api.js +16 -5
  46. package/apps/runtime/dist/routes/lang.js +13 -0
  47. package/apps/runtime/dist/routes/plugin-public.js +65 -12
  48. package/apps/runtime/dist/routes/runs.js +12 -19
  49. package/apps/runtime/dist/routes/studio.js +40 -28
  50. package/apps/runtime/dist/services/access.js +4 -3
  51. package/apps/runtime/dist/services/architect.js +15 -4
  52. package/apps/runtime/dist/services/assistant-chats.js +2 -1
  53. package/apps/runtime/dist/services/brand.js +3 -2
  54. package/apps/runtime/dist/services/errors.js +7 -5
  55. package/apps/runtime/dist/services/knowledge-model.js +3 -2
  56. package/apps/runtime/dist/services/marketplace.js +6 -5
  57. package/apps/runtime/dist/services/package.js +10 -3
  58. package/apps/runtime/dist/services/profile.js +12 -0
  59. package/apps/runtime/dist/services/project-files.js +13 -12
  60. package/apps/runtime/dist/services/projects.js +11 -6
  61. package/apps/runtime/dist/services/runs.js +18 -11
  62. package/apps/runtime/dist/services/shares.js +2 -1
  63. package/apps/runtime/dist/services/site.js +21 -10
  64. package/apps/runtime/dist/services/space-categories.js +7 -6
  65. package/apps/runtime/dist/services/space-data.js +19 -16
  66. package/apps/runtime/dist/services/spaces.js +8 -7
  67. package/apps/runtime/dist/services/wizards.js +41 -20
  68. package/apps/runtime/dist/store/errors.js +2 -1
  69. package/apps/runtime/dist/store/index.js +21 -4
  70. package/apps/runtime/dist/store/shared-lists.js +2 -3
  71. package/apps/runtime/dist/tools/index.js +17 -2
  72. package/apps/runtime/dist/tools/plugin.js +3 -2
  73. package/apps/runtime/dist/widgets/render.js +1 -1
  74. package/apps/runtime/dist/widgets/step.js +2 -1
  75. package/apps/web/dist/assets/{AboutDialog-DWaBKvI6.js → AboutDialog-BCtnYRj2.js} +1 -1
  76. package/apps/web/dist/assets/{ChangelogDialog-BcM1gXPM.js → ChangelogDialog-DBjoIIHL.js} +1 -1
  77. package/apps/web/dist/assets/ChatView-BcyUYN0Q.js +10 -0
  78. package/apps/web/dist/assets/EditorPage-Ce1QD-DK.js +3 -0
  79. package/apps/web/dist/assets/{FlowPreview-S1s1yRaP.js → FlowPreview-BtpAdyt-.js} +1 -1
  80. package/apps/web/dist/assets/{Harness-DILx5Edb.js → Harness-DJJ_yMLY.js} +2 -2
  81. package/apps/web/dist/assets/NewWizardChannels-BrYLMV6F.js +1 -0
  82. package/apps/web/dist/assets/NewWizardPage-827zwhhW.js +7 -0
  83. package/apps/web/dist/assets/{OnboardingPage-xoGrKIJ-.js → OnboardingPage-jC6FidpF.js} +1 -1
  84. package/apps/web/dist/assets/ProjectPage-BYcM1-1H.js +1 -0
  85. package/apps/web/dist/assets/{PublicRunner-Cab2jUy6.js → PublicRunner-BofZl0MO.js} +1 -1
  86. package/apps/web/dist/assets/{ReadOnly-DQPHmvS0.js → ReadOnly-B4nIGkoj.js} +1 -1
  87. package/apps/web/dist/assets/RunDrawer-Dx-BRCkY.js +4 -0
  88. package/apps/web/dist/assets/RunnerView-CDCp61aq.js +1 -0
  89. package/apps/web/dist/assets/SettingsPage-B49nLHwv.js +1 -0
  90. package/apps/web/dist/assets/SetupPage-4tzzHUq0.js +1 -0
  91. package/apps/web/dist/assets/SharePage-Bs4s73h4.js +1 -0
  92. package/apps/web/dist/assets/changelog-D-12LwZB.js +1 -0
  93. package/apps/web/dist/assets/{circle-alert-DCBV7n5k.js → circle-alert-BueS7qO8.js} +1 -1
  94. package/apps/web/dist/assets/esm-CjGdsKU4.js +7 -0
  95. package/apps/web/dist/assets/index-BRDn-5v_.js +14 -0
  96. package/apps/web/dist/assets/index-mlnAPOdf.css +1 -0
  97. package/apps/web/dist/assets/{lock-DlzTfwxP.js → lock-CkXYnQux.js} +1 -1
  98. package/apps/web/dist/assets/{phone-BFD815nc.js → phone-CHkEf-Dz.js} +1 -1
  99. package/apps/web/dist/assets/settings-menu-CrVpArM_.js +1 -0
  100. package/apps/web/dist/assets/ui-DrdqFaQt.js +134 -0
  101. package/apps/web/dist/assets/{upload-BEf5-d6X.js → upload-CzkkZqAo.js} +1 -1
  102. package/apps/web/dist/index.html +4 -4
  103. package/apps/web/dist/mcp/flow.html +76 -76
  104. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +98 -2
  105. package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.js +6 -1
  106. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +6 -2
  107. package/node_modules/@engenty-wizards/shared/dist/definition.js +13 -5
  108. package/node_modules/@engenty-wizards/shared/dist/knowledge.js +1 -1
  109. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +11 -1
  110. package/node_modules/@engenty-wizards/shared/dist/run.js +11 -1
  111. package/node_modules/@engenty-wizards/shared/dist/store.d.ts +8 -0
  112. package/node_modules/@engenty-wizards/shared/dist/store.js +8 -0
  113. package/package.json +1 -1
  114. package/apps/web/dist/assets/ChatView-D0RRIl15.js +0 -10
  115. package/apps/web/dist/assets/EditorPage-DrJ6e_2q.js +0 -3
  116. package/apps/web/dist/assets/NewWizardChannels-CEILDADp.js +0 -1
  117. package/apps/web/dist/assets/NewWizardPage-DxOtK2E-.js +0 -7
  118. package/apps/web/dist/assets/ProjectPage-6E5z4nZA.js +0 -1
  119. package/apps/web/dist/assets/RunDrawer-B3FNYpgZ.js +0 -4
  120. package/apps/web/dist/assets/RunnerView-D6sGVnRy.js +0 -1
  121. package/apps/web/dist/assets/SettingsPage-DHtIqmOJ.js +0 -1
  122. package/apps/web/dist/assets/SetupPage-Cn9iQbJx.js +0 -1
  123. package/apps/web/dist/assets/SharePage-CMr72PeU.js +0 -1
  124. package/apps/web/dist/assets/changelog-DfmWTlav.js +0 -1
  125. package/apps/web/dist/assets/esm-BPfTI3lL.js +0 -7
  126. package/apps/web/dist/assets/index-B-D8UvL9.js +0 -14
  127. package/apps/web/dist/assets/index-CmxVazOf.css +0 -1
  128. package/apps/web/dist/assets/settings-menu-BJm0CwOj.js +0 -1
  129. package/apps/web/dist/assets/ui-DTuixH4y.js +0 -134
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{Er as r,Qn as i,Rn as a,Vn as o,an as s,kn as c,tn as l,z as u}from"./ui-DTuixH4y.js";import{t as d}from"./upload-BEf5-d6X.js";import{B as f,Jt as p,dt as m,gt as h,pt as g,rt as _,st as v}from"./index-B-D8UvL9.js";var y=e(t(),1),b=e(n(),1),x=`oklch(50% 0.2 262)`,S=`oklch(32% 0.15 262)`,C={"--on":`white`,"--dot":`oklch(90% 0.1 80)`,"--ink-2":`oklch(96% 0.02 262)`,"--ink-3":`oklch(90% 0.035 262)`,"--moss":`oklch(90% 0.14 150)`,"--rose":`oklch(89% 0.09 45)`},w=`w-full rounded-[18px] border border-white/30 bg-white/15 px-6 py-5 text-[1.375rem] text-white outline-none placeholder:text-white/55 focus:border-white/60`;function T(){return(0,b.jsxs)(`span`,{className:`inline-flex items-center gap-2.5`,children:[(0,b.jsx)(h,{size:28}),(0,b.jsxs)(`span`,{className:`font-display font-semibold text-[1.0625rem] tracking-tight`,children:[`engenty`,(0,b.jsx)(`span`,{className:`mr-[0.09em] ml-[0.06em] text-(color:--dot)`,children:`.`}),(0,b.jsx)(`span`,{className:`font-normal text-white/70`,children:`wizards`})]})]})}function E({children:e,busy:t,onClick:n,type:r=`button`}){return(0,b.jsxs)(`button`,{type:r,disabled:t,onClick:n,className:`inline-flex h-13 cursor-pointer items-center gap-2.5 rounded-full bg-white px-7 font-semibold text-[1rem] transition hover:bg-white/90 disabled:cursor-default disabled:opacity-70`,style:{color:S},children:[e,(0,b.jsx)(o,{className:`size-[18px]`})]})}function D({children:e,onClick:t}){return(0,b.jsx)(`button`,{type:`button`,onClick:t,className:`cursor-pointer font-semibold text-[0.9375rem] text-white/85 transition hover:text-white`,children:e})}function O({step:e}){return(0,b.jsx)(`span`,{className:`ml-auto inline-flex gap-1.5`,role:`img`,"aria-label":s(`onboard.step`,{n:e}),children:[1,2,3,4].map(t=>(0,b.jsx)(`span`,{className:l(`size-2 rounded-full`,t===e?`bg-white`:`bg-white/40`)},t))})}function k(){g(x);let e=v(),t=r(),n=i(),{project:o}=_(),[h,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)([]),B=(0,y.useRef)(null),V=p({mutationFn:e=>u.put(`/api/studio/team`,{name:e}),onSuccess:()=>t.invalidateQueries({queryKey:[`team`]})}),H=p({mutationFn:e=>u.post(`/api/studio/projects/${o?.id}/website`,{url:e}),onSuccess:async e=>{L(e),await t.invalidateQueries({queryKey:[`projects`]})}}),U=p({mutationFn:e=>u.patch(`/api/studio/projects/${o?.id}`,{brand:{about:e}}),onSuccess:()=>t.invalidateQueries({queryKey:[`projects`]})}),W=p({mutationFn:()=>u.post(`/api/studio/onboarding/done`),onSuccess:async()=>{await t.invalidateQueries({queryKey:[`me`]}),n(`/new`,{replace:!0})}}),G=e.data?.user.name??``,K=G.includes(`@`)?``:G.split(` `)[0],q=async e=>{if(e&&o){for(let t of Array.from(e)){z(e=>[...e,{name:t.name,state:`uploading`}]);try{await u.upload(`/api/studio/projects/${o.id}/files?kind=document`,t),z(e=>e.map(e=>e.name===t.name?{...e,state:`done`}:e))}catch{z(e=>e.map(e=>e.name===t.name?{...e,state:`failed`}:e))}}await t.invalidateQueries({queryKey:[`projects`]})}},J=I?[I.about?s(`onboard.readAbout`):``,I.colors?s(`onboard.readColors`,{n:I.colors}):``,I.logo?s(`onboard.readLogo`):``].join(``):``;return(0,b.jsxs)(`div`,{className:`flex min-h-dvh flex-col px-6 text-white sm:px-10`,style:{...C,background:x},children:[(0,b.jsxs)(`header`,{className:`flex items-center justify-between pt-6 sm:pt-8`,children:[(0,b.jsx)(T,{}),(0,b.jsx)(f,{tone:`ground`,ink:S})]}),(0,b.jsxs)(`main`,{className:`mx-auto grid w-full max-w-6xl flex-1 items-center gap-10 py-10 lg:grid-cols-[5fr_7fr] lg:gap-12`,children:[(0,b.jsx)(`div`,{className:`flex justify-center max-lg:order-first`,children:(0,b.jsx)(m,{kind:`drop`,size:240,fluffy:!0,coat:`fur`})}),(0,b.jsxs)(`div`,{className:`flex min-w-0 max-w-2xl animate-rise flex-col gap-5`,children:[h===1?(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault();let t=A.trim();t?V.mutate(t,{onSuccess:()=>k(2)}):k(2)},children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:K?s(`onboard.kicker1`,{name:K}):s(`onboard.kicker1Anon`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.team`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.teamSub`)}),(0,b.jsx)(`input`,{value:A,onChange:e=>j(e.target.value),placeholder:s(`onboard.teamPlaceholder`),maxLength:80,"aria-label":s(`onboard.team`),className:w}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{type:`submit`,busy:V.isPending,children:s(`onboard.continue`)}),(0,b.jsx)(O,{step:1})]})]}):null,h===2?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:s(`onboard.kicker2`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.site`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.siteSub`)}),P===null?(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault(),M.trim()&&!H.isPending&&H.mutate(M.trim())},children:[(0,b.jsx)(`input`,{value:M,onChange:e=>N(e.target.value),placeholder:s(`onboard.sitePlaceholder`),inputMode:`url`,autoCapitalize:`none`,"aria-label":s(`onboard.site`),className:w}),I?(0,b.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.9375rem] text-(color:--moss)`,children:[(0,b.jsx)(a,{className:`size-4`}),s(`onboard.readDone`,{name:I.name,details:J})]}):H.isError?(0,b.jsx)(`p`,{className:`text-[0.9375rem] text-(color:--rose)`,children:s(`onboard.readFailed`)}):null,(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[I?(0,b.jsx)(E,{onClick:()=>k(3),children:s(`onboard.continue`)}):(0,b.jsx)(E,{type:`submit`,busy:H.isPending,children:H.isPending?s(`onboard.reading`):s(`onboard.read`)}),(0,b.jsx)(D,{onClick:()=>F(``),children:s(`onboard.line`)}),(0,b.jsx)(D,{onClick:()=>k(3),children:s(`onboard.skip`)}),(0,b.jsx)(O,{step:2})]})]}):(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault();let t=P.trim();t?U.mutate(t,{onSuccess:()=>k(3)}):k(3)},children:[(0,b.jsx)(`textarea`,{value:P,onChange:e=>F(e.target.value),placeholder:s(`onboard.linePlaceholder`),rows:3,maxLength:8e3,"aria-label":s(`onboard.line`),className:l(w,`resize-none text-[1.125rem] leading-relaxed`)}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{type:`submit`,busy:U.isPending,children:s(`onboard.continue`)}),(0,b.jsx)(D,{onClick:()=>F(null),children:s(`onboard.site`)}),(0,b.jsx)(D,{onClick:()=>k(3),children:s(`onboard.skip`)}),(0,b.jsx)(O,{step:2})]})]})]}):null,h===3?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:s(`onboard.kicker3`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.know`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.knowSub`)}),(0,b.jsxs)(`button`,{type:`button`,onClick:()=>B.current?.click(),onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),q(e.dataTransfer.files)},className:`flex cursor-pointer flex-col items-center gap-2 rounded-[18px] border-2 border-white/45 border-dashed bg-white/10 px-6 py-7 text-center transition hover:bg-white/15`,children:[(0,b.jsx)(d,{className:`size-7`}),(0,b.jsx)(`span`,{className:`font-semibold text-[1.0625rem]`,children:s(`onboard.drop`)}),(0,b.jsx)(`span`,{className:`text-[0.875rem] text-white/80`,children:`PDF · Word · Excel · Markdown`}),(0,b.jsx)(`input`,{ref:B,type:`file`,multiple:!0,className:`sr-only`,onChange:e=>{q(e.target.files),e.target.value=``}})]}),R.length?(0,b.jsx)(`ul`,{className:`flex flex-col gap-2`,children:R.map(e=>(0,b.jsxs)(`li`,{className:`flex items-center gap-2.5 rounded-xl bg-white/15 px-3.5 py-2.5 text-[0.875rem]`,children:[(0,b.jsx)(c,{className:`size-4 shrink-0`}),(0,b.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,b.jsx)(`span`,{className:l(`text-white/80`,e.state===`failed`?`text-(color:--rose)`:``),children:e.state===`uploading`?s(`onboard.uploading`):e.state===`done`?s(`onboard.uploaded`):s(`onboard.uploadFailed`)})]},e.name))}):null,(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{busy:R.some(e=>e.state===`uploading`),onClick:()=>k(4),children:s(`onboard.continue`)}),R.length?null:(0,b.jsx)(D,{onClick:()=>k(4),children:s(`onboard.skip`)}),(0,b.jsx)(O,{step:3})]})]}):null,h===4?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:s(`onboard.kicker4`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.space`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.spaceSub`,{space:o?.name??``})}),(0,b.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[[`partInfo`,`partInfoText`,!!(I||P)],[`partKnow`,`partKnowText`,R.some(e=>e.state===`done`)],[`partData`,`partDataText`,!1],[`partResults`,`partResultsText`,!1]].map(([e,t,n])=>(0,b.jsxs)(`div`,{className:`flex flex-col gap-1.5 rounded-2xl border border-white/20 bg-white/10 px-4.5 py-4`,children:[(0,b.jsxs)(`span`,{className:`flex items-center gap-2 font-semibold text-[1rem]`,children:[n?(0,b.jsx)(a,{className:`size-4 text-(color:--moss)`}):null,s(`onboard.${e}`)]}),(0,b.jsx)(`span`,{className:`text-[0.84375rem] text-white/85 leading-snug`,children:s(`onboard.${t}`)})]},e))}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{busy:W.isPending,onClick:()=>W.mutate(),children:s(`onboard.build`)}),(0,b.jsx)(O,{step:4})]})]}):null]},h)]}),(0,b.jsxs)(`footer`,{className:`mx-auto flex w-full max-w-6xl items-center justify-between pb-6 text-[0.75rem] text-white/55 sm:pb-8`,children:[(0,b.jsx)(`span`,{children:`engenty`}),(0,b.jsx)(`span`,{"aria-hidden":`true`,className:`size-[3px] bg-(color:--dot)`})]})]})}export{k as OnboardingPage};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{Fn as r,Nr as i,W as a,Wn as o,dn as s,ir as c,on as l,qn as u}from"./ui-DrdqFaQt.js";import{t as d}from"./upload-CzkkZqAo.js";import{V as f,Yt as p,_t as m,ct as h,ft as g,it as _,mt as v}from"./index-BRDn-5v_.js";var y=e(t(),1),b=e(n(),1),x=`oklch(50% 0.2 262)`,S=`oklch(32% 0.15 262)`,C={"--on":`white`,"--dot":`oklch(90% 0.1 80)`,"--ink-2":`oklch(96% 0.02 262)`,"--ink-3":`oklch(90% 0.035 262)`,"--moss":`oklch(90% 0.14 150)`,"--rose":`oklch(89% 0.09 45)`},w=`w-full rounded-[18px] border border-white/30 bg-white/15 px-6 py-5 text-[1.375rem] text-white outline-none placeholder:text-white/55 focus:border-white/60`;function T(){return(0,b.jsxs)(`span`,{className:`inline-flex items-center gap-2.5`,children:[(0,b.jsx)(m,{size:28}),(0,b.jsxs)(`span`,{className:`font-display font-semibold text-[1.0625rem] tracking-tight`,children:[`engenty`,(0,b.jsx)(`span`,{className:`mr-[0.09em] ml-[0.06em] text-(color:--dot)`,children:`.`}),(0,b.jsx)(`span`,{className:`font-normal text-white/70`,children:`wizards`})]})]})}function E({children:e,busy:t,onClick:n,type:r=`button`}){return(0,b.jsxs)(`button`,{type:r,disabled:t,onClick:n,className:`inline-flex h-13 cursor-pointer items-center gap-2.5 rounded-full bg-white px-7 font-semibold text-[1rem] transition hover:bg-white/90 disabled:cursor-default disabled:opacity-70`,style:{color:S},children:[e,(0,b.jsx)(u,{className:`size-[18px]`})]})}function D({children:e,onClick:t}){return(0,b.jsx)(`button`,{type:`button`,onClick:t,className:`cursor-pointer font-semibold text-[0.9375rem] text-white/85 transition hover:text-white`,children:e})}function O({step:e}){return(0,b.jsx)(`span`,{className:`ml-auto inline-flex gap-1.5`,role:`img`,"aria-label":s(`onboard.step`,{n:e}),children:[1,2,3,4].map(t=>(0,b.jsx)(`span`,{className:l(`size-2 rounded-full`,t===e?`bg-white`:`bg-white/40`)},t))})}function k(){v(x);let e=h(),t=i(),n=c(),{project:u}=_(),[m,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)([]),B=(0,y.useRef)(null),V=p({mutationFn:e=>a.put(`/api/studio/team`,{name:e}),onSuccess:()=>t.invalidateQueries({queryKey:[`team`]})}),H=p({mutationFn:e=>a.post(`/api/studio/projects/${u?.id}/website`,{url:e}),onSuccess:async e=>{L(e),await t.invalidateQueries({queryKey:[`projects`]})}}),U=p({mutationFn:e=>a.patch(`/api/studio/projects/${u?.id}`,{brand:{about:e}}),onSuccess:()=>t.invalidateQueries({queryKey:[`projects`]})}),W=p({mutationFn:()=>a.post(`/api/studio/onboarding/done`),onSuccess:async()=>{await t.invalidateQueries({queryKey:[`me`]}),n(`/new`,{replace:!0})}}),G=e.data?.user.name??``,K=G.includes(`@`)?``:G.split(` `)[0],q=async e=>{if(e&&u){for(let t of Array.from(e)){z(e=>[...e,{name:t.name,state:`uploading`}]);try{await a.upload(`/api/studio/projects/${u.id}/files?kind=document`,t),z(e=>e.map(e=>e.name===t.name?{...e,state:`done`}:e))}catch{z(e=>e.map(e=>e.name===t.name?{...e,state:`failed`}:e))}}await t.invalidateQueries({queryKey:[`projects`]})}},J=I?[I.about?s(`onboard.readAbout`):``,I.colors?s(`onboard.readColors`,{n:I.colors}):``,I.logo?s(`onboard.readLogo`):``].join(``):``;return(0,b.jsxs)(`div`,{className:`flex min-h-dvh flex-col px-6 text-white sm:px-10`,style:{...C,background:x},children:[(0,b.jsxs)(`header`,{className:`flex items-center justify-between pt-6 sm:pt-8`,children:[(0,b.jsx)(T,{}),(0,b.jsx)(f,{tone:`ground`,ink:S})]}),(0,b.jsxs)(`main`,{className:`mx-auto grid w-full max-w-6xl flex-1 items-center gap-10 py-10 lg:grid-cols-[5fr_7fr] lg:gap-12`,children:[(0,b.jsx)(`div`,{className:`flex justify-center max-lg:order-first`,children:(0,b.jsx)(g,{kind:`drop`,size:240,fluffy:!0,coat:`fur`})}),(0,b.jsxs)(`div`,{className:`flex min-w-0 max-w-2xl animate-rise flex-col gap-5`,children:[m===1?(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault();let t=A.trim();t?V.mutate(t,{onSuccess:()=>k(2)}):k(2)},children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:K?s(`onboard.kicker1`,{name:K}):s(`onboard.kicker1Anon`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.team`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.teamSub`)}),(0,b.jsx)(`input`,{value:A,onChange:e=>j(e.target.value),placeholder:s(`onboard.teamPlaceholder`),maxLength:80,"aria-label":s(`onboard.team`),className:w}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{type:`submit`,busy:V.isPending,children:s(`onboard.continue`)}),(0,b.jsx)(O,{step:1})]})]}):null,m===2?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:s(`onboard.kicker2`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.site`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.siteSub`)}),P===null?(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault(),M.trim()&&!H.isPending&&H.mutate(M.trim())},children:[(0,b.jsx)(`input`,{value:M,onChange:e=>N(e.target.value),placeholder:s(`onboard.sitePlaceholder`),inputMode:`url`,autoCapitalize:`none`,"aria-label":s(`onboard.site`),className:w}),I?(0,b.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.9375rem] text-(color:--moss)`,children:[(0,b.jsx)(o,{className:`size-4`}),s(`onboard.readDone`,{name:I.name,details:J})]}):H.isError?(0,b.jsx)(`p`,{className:`text-[0.9375rem] text-(color:--rose)`,children:s(`onboard.readFailed`)}):null,(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[I?(0,b.jsx)(E,{onClick:()=>k(3),children:s(`onboard.continue`)}):(0,b.jsx)(E,{type:`submit`,busy:H.isPending,children:H.isPending?s(`onboard.reading`):s(`onboard.read`)}),(0,b.jsx)(D,{onClick:()=>F(``),children:s(`onboard.line`)}),(0,b.jsx)(D,{onClick:()=>k(3),children:s(`onboard.skip`)}),(0,b.jsx)(O,{step:2})]})]}):(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault();let t=P.trim();t?U.mutate(t,{onSuccess:()=>k(3)}):k(3)},children:[(0,b.jsx)(`textarea`,{value:P,onChange:e=>F(e.target.value),placeholder:s(`onboard.linePlaceholder`),rows:3,maxLength:8e3,"aria-label":s(`onboard.line`),className:l(w,`resize-none text-[1.125rem] leading-relaxed`)}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{type:`submit`,busy:U.isPending,children:s(`onboard.continue`)}),(0,b.jsx)(D,{onClick:()=>F(null),children:s(`onboard.site`)}),(0,b.jsx)(D,{onClick:()=>k(3),children:s(`onboard.skip`)}),(0,b.jsx)(O,{step:2})]})]})]}):null,m===3?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:s(`onboard.kicker3`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.know`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.knowSub`)}),(0,b.jsxs)(`button`,{type:`button`,onClick:()=>B.current?.click(),onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),q(e.dataTransfer.files)},className:`flex cursor-pointer flex-col items-center gap-2 rounded-[18px] border-2 border-white/45 border-dashed bg-white/10 px-6 py-7 text-center transition hover:bg-white/15`,children:[(0,b.jsx)(d,{className:`size-7`}),(0,b.jsx)(`span`,{className:`font-semibold text-[1.0625rem]`,children:s(`onboard.drop`)}),(0,b.jsx)(`span`,{className:`text-[0.875rem] text-white/80`,children:`PDF · Word · Excel · Markdown`}),(0,b.jsx)(`input`,{ref:B,type:`file`,multiple:!0,className:`sr-only`,onChange:e=>{q(e.target.files),e.target.value=``}})]}),R.length?(0,b.jsx)(`ul`,{className:`flex flex-col gap-2`,children:R.map(e=>(0,b.jsxs)(`li`,{className:`flex items-center gap-2.5 rounded-xl bg-white/15 px-3.5 py-2.5 text-[0.875rem]`,children:[(0,b.jsx)(r,{className:`size-4 shrink-0`}),(0,b.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,b.jsx)(`span`,{className:l(`text-white/80`,e.state===`failed`?`text-(color:--rose)`:``),children:e.state===`uploading`?s(`onboard.uploading`):e.state===`done`?s(`onboard.uploaded`):s(`onboard.uploadFailed`)})]},e.name))}):null,(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{busy:R.some(e=>e.state===`uploading`),onClick:()=>k(4),children:s(`onboard.continue`)}),R.length?null:(0,b.jsx)(D,{onClick:()=>k(4),children:s(`onboard.skip`)}),(0,b.jsx)(O,{step:3})]})]}):null,m===4?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:s(`onboard.kicker4`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:s(`onboard.space`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:s(`onboard.spaceSub`,{space:u?.name??``})}),(0,b.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[[`partInfo`,`partInfoText`,!!(I||P)],[`partKnow`,`partKnowText`,R.some(e=>e.state===`done`)],[`partData`,`partDataText`,!1],[`partResults`,`partResultsText`,!1]].map(([e,t,n])=>(0,b.jsxs)(`div`,{className:`flex flex-col gap-1.5 rounded-2xl border border-white/20 bg-white/10 px-4.5 py-4`,children:[(0,b.jsxs)(`span`,{className:`flex items-center gap-2 font-semibold text-[1rem]`,children:[n?(0,b.jsx)(o,{className:`size-4 text-(color:--moss)`}):null,s(`onboard.${e}`)]}),(0,b.jsx)(`span`,{className:`text-[0.84375rem] text-white/85 leading-snug`,children:s(`onboard.${t}`)})]},e))}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{busy:W.isPending,onClick:()=>W.mutate(),children:s(`onboard.build`)}),(0,b.jsx)(O,{step:4})]})]}):null]},m)]}),(0,b.jsxs)(`footer`,{className:`mx-auto flex w-full max-w-6xl items-center justify-between pb-6 text-[0.75rem] text-white/55 sm:pb-8`,children:[(0,b.jsx)(`span`,{children:`engenty`}),(0,b.jsx)(`span`,{"aria-hidden":`true`,className:`size-[3px] bg-(color:--dot)`})]})]})}export{k as OnboardingPage};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{A as r,B as i,C as a,Cn as o,D as s,Dn as c,E as l,F as u,Fn as d,Gt as f,H as p,I as m,In as h,Jt as g,Kn as _,Kt as v,L as y,Ln as b,M as x,Mn as S,N as C,Nr as w,O as T,P as E,Pn as D,R as ee,S as O,T as k,U as A,V as te,W as j,Wn as M,Wt as N,Xn as P,Xt as F,Yt as I,Zt as L,_ as R,a as ne,an as re,ar as ie,b as ae,cn as z,cr as oe,dn as B,en as V,er as se,g as H,h as U,hn as W,in as G,ir as ce,j as K,jn as q,k as le,nn as ue,on as J,or as de,ot as fe,qt as Y,rn as pe,rr as me,sr as X,tn as Z,v as he,vn as ge,w as _e,wn as ve,x as ye,xn as be,y as xe,yn as Se,z as Ce,zn as we}from"./ui-DrdqFaQt.js";import{_ as Te,a as Ee,b as De,c as Oe,d as ke,f as Ae,g as je,h as Me,i as Ne,l as Pe,m as Fe,n as Ie,o as Le,p as Re,s as ze,u as Be,v as Ve,x as He,y as Ue}from"./RunDrawer-Dx-BRCkY.js";import{t as We}from"./phone-CHkEf-Dz.js";import{n as Ge,r as Ke,t as qe}from"./ReadOnly-B4nIGkoj.js";import{t as Je}from"./upload-CzkkZqAo.js";import{At as Ye,Bt as Xe,Ct as Ze,Dt as Qe,Et as $e,Ft as et,G as tt,Ht as nt,It as rt,Yt as it,_ as at,at as ot,b as st,c as ct,et as lt,g as ut,h as dt,it as ft,m as pt,ot as mt,p as ht,s as gt,u as _t,v as vt,vt as yt,xt as bt,y as xt}from"./index-BRDn-5v_.js";import{a as St,c as Ct,f as wt,i as Tt,n as Et,o as Dt,r as Ot,s as kt,t as At,u as jt}from"./settings-menu-CrVpArM_.js";import{t as Mt}from"./RunnerView-CDCp61aq.js";var Nt={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Nt.node;var Pt=P(Nt),Ft={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`}]]};Ft.node;var It=P(Ft),Lt={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`}]]};Lt.node;var Rt=P(Lt),zt={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`}]]};zt.node;var Bt=P(zt),Vt={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`]};Vt.node;var Ht=P(Vt),Ut={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`]};Ut.node;var Wt=P(Ut),Gt={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`}]]};Gt.node;var Kt=P(Gt),qt={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`}]]};qt.node;var Jt=P(qt),Yt={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`}]]};Yt.node;var Xt=P(Yt),Zt={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`}]]};Zt.node;var Qt=P(Zt),$t=X(),Q=e(t(),1),$=e(n(),1),en={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function tn({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 o=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:B(o?`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 nn(e,t){confirm(B(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function rn({projectId:e,file:t,small:n}){let r=Ce(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:J(`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)(an,{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)(Qt,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(d,{className:i}):t.mime===`application/json`?(0,$.jsx)(ge,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(It,{className:i}):(0,$.jsx)(D,{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 an({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:J(`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 on=`application/x-wizards-logo`;function sn({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):nn(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(on,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)(v,{tone:`ember`,children:B(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?en:void 0,children:[c&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${B(`project.preview`)}: ${n.name}`,onClick:()=>c(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(rn,{projectId:e,file:n})}):(0,$.jsx)(rn,{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)(I,{label:B(`project.preview`),onClick:()=>c(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(nt,{className:`size-4`})}):null,u&&n.id!==l&&!r.readOnly?(0,$.jsx)(I,{label:B(`project.logoMakeMain`),onClick:()=>u(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(Ze,{className:`size-4`})}):null,d&&!r.readOnly?(0,$.jsx)(ae,{options:d.options,value:d.current(n),onChange:e=>d.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(I,{label:B(`project.remove`),onClick:()=>p(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(W,{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)(tn,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,$.jsxs)(he,{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)(Z,{className:`size-5`}):(0,$.jsx)(o,{className:`size-5`}),a]}):null]})}function cn({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,a]=(0,Q.useState)(``),[o,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 a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(d(a.candidates),p([a.candidates[0].url])):l(B(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){l(e.message)}s(!1)},h=async()=>{s(!0),l(null);let e=[];try{for(let n of f){let r=await t(n);r.file&&e.push(r.file)}}catch(e){l(e.message)}s(!1),e.length&&n(e),e.length===f.length&&r()};return(0,$.jsx)(Y,{open:!0,onClose:r,wide:u?!0:void 0,title:B(u?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),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:B(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:u.map(t=>{let n=f.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>p(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:J(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:en,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:J(`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)(M,{className:`size-3.5`})}):null]},t.url)})}),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)(N,{variant:`ghost`,onClick:()=>d(null),children:B(`run.back`)}),(0,$.jsx)(N,{busy:o,disabled:!f.length,onClick:()=>void h(),children:f.length>1?B(`project.addMany`,{n:f.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.logoUrl`)}),(0,$.jsx)(F,{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:B(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),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)(N,{variant:`ghost`,onClick:r,children:B(`common.cancel`)}),(0,$.jsx)(N,{type:`submit`,busy:o,disabled:!i.trim(),children:B(`run.next`)})]})]})})}function ln(e,t,n){return oe({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>j.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function un(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var dn=e=>[un(e),e.pages?B(`project.pages`,{n:e.pages}):null,ee(e.size)].filter(Boolean).join(` · `),fn=2e5;function pn({projectId:e,fileId:t,readOnly:n,onGone:r}){let i=w(),a=A(e),o=Fe(e),s=te(e,n),c=a.data?.files.find(e=>e.id===t),l=c?c.mime===`application/pdf`||c.mime.startsWith(`image/`):!1,[u,d]=(0,Q.useState)(null);if(!c)return a.isLoading?(0,$.jsx)(Z,{className:`mx-auto text-ink-3`}):null;let p=u??(l?`original`:`text`),m=o.data?.items.find(e=>e.key===`f:${c.id}`),g=Ce(e,c.id),_=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>d(e),className:J(`rounded-full px-3 py-1 text-[0.8125rem] transition`,p===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:c.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:dn(c)}),(0,$.jsx)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,"aria-label":B(`project.openOriginal`),title:B(`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)(h,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{label:B(`project.reindex`),onClick:async()=>{await s.reindex(c.id),await i.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(be,{className:`size-4`})}),(0,$.jsx)(I,{label:B(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(B(`data.confirmDelete`,{title:c.name}))&&(await s.remove(c.id),await i.invalidateQueries({queryKey:[`knowledge`,e]}),r())},children:(0,$.jsx)(W,{className:`size-4`})})]})]}),(0,$.jsx)(Ae,{projectId:e,itemKey:`f:${c.id}`,has:m?.categories??[],originLabel:m?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(tn,{file:c,actions:s})}),c.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:c.error}):null,(0,$.jsxs)(f,{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:[l?_(`original`,B(`project.original`)):null,_(`text`,B(`project.readText`))]}),p===`original`?c.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:g,title:c.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:g,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(mn,{projectId:e,file:c})]})]})}function mn({projectId:e,file:t}){let n=ln(e,t,fn);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(Z,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(fe,{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:B(`project.textCut`,{shown:n.data.text.length.toLocaleString(z),total:n.data.chars.toLocaleString(z)})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:B(`project.noText`)})}var hn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,gn=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),ee(e.size)].filter(Boolean).join(` · `);function _n({projectId:e,file:t,actions:n,onClose:r}){let i=Ce(e,t.id);return(0,$.jsxs)(Y,{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:gn(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":B(`project.openOriginal`),title:B(`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)(h,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:en,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)(tn,{file:t,actions:n})})]})}function vn({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":`${B(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(rn,{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:gn(t)})]}),(0,$.jsx)(tn,{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)(I,{label:B(`project.preview`),onClick:i,children:(0,$.jsx)(nt,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(ae,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(I,{label:B(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(W,{className:`size-4`})})]})]})}function yn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,a]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(Y,{open:!0,onClose:r,title:B(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)(L,{children:B(`project.assetSectionName`)}),(0,$.jsx)(F,{autoFocus:!0,value:i,maxLength:80,placeholder:B(`project.assetSectionTitle`),onChange:e=>a(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(N,{variant:`danger`,onClick:n,children:B(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(N,{variant:`ghost`,onClick:r,children:B(`common.cancel`)}),(0,$.jsx)(N,{type:`submit`,disabled:!i.trim(),children:B(e?`settings.save`:`project.add`)})]})]})})}function bn({projectId:e,data:t,readOnly:n,sections:r,save:o}){let s=te(e,n),[c,l]=p(`assets`,`cards`),[u,d]=(0,Q.useState)(``),[f,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(r),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),w=(0,Q.useRef)(null),T=i({assetSections:h},o),E=t.files.filter(e=>e.kind===`asset`),D=new Map(E.map(e=>[e.id,e])),ee=new Set(h.flatMap(e=>e.assets)),A=h.find(e=>e.id===_)??null,j=A?A.assets.map(e=>D.get(e)).filter(e=>!!e):E.filter(e=>!ee.has(e.id)),M=E.find(e=>e.id===f),N=u.trim().toLowerCase(),P=N?j.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(N)):j,F=(e,t)=>g(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),L=async e=>{let t=A?.id??null;for(let n of await s.upload(`asset`,e))F(n.id,t)},R=e=>{confirm(B(`project.removeConfirm`,{name:e.name}))&&(s.remove(e.id),F(e.id,null))},ne=h.length?{options:[{value:``,label:B(`project.assetsGeneral`)},...h.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],current:e=>h.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>F(e.id,t||null)}:void 0,re=[{label:B(`project.assetUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>w.current?.click()},{label:B(`project.assetFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>C(!0)},...h.length<x.logoSections?[{label:B(`project.assetSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>b(`new`)}]:[]],ie=h.length||E.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:[h.length?(0,$.jsx)(G,{value:_,onChange:e=>{v(e),d(``)},label:B(`project.assets`),options:[{id:``,label:B(`project.assetsGeneral`)},...h.map(e=>({id:e.id,label:e.title||B(`project.sectionUntitled`)}))]}):null,A&&!n?(0,$.jsx)(I,{label:B(`project.assetSectionRename`),onClick:()=>b(`current`),children:(0,$.jsx)(ve,{className:`size-4`})}):null]}),j.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(O,{value:u,onChange:d,placeholder:B(`project.assetSearch`)})}),(0,$.jsx)(I,{label:B(c===`list`?`project.viewCards`:`project.viewList`),onClick:l,children:c===`list`?(0,$.jsx)(Kt,{className:`size-4`}):(0,$.jsx)(Xt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(a,{title:B(`project.assets`),hint:B(`project.assetsHint`),save:T,tabs:ie,action:n?null:(0,$.jsx)(U,{entries:re}),children:[(0,$.jsx)(`input`,{ref:w,type:`file`,multiple:!0,accept:hn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&L(t)}}),P.length?c===`cards`?(0,$.jsx)(sn,{projectId:e,kind:`asset`,files:P,actions:s,moveTo:ne,onRemove:R,onPreview:e=>m(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:P.map(t=>(0,$.jsx)(vn,{projectId:e,file:t,actions:s,moveTo:ne,onPreview:()=>m(t.id),onRemove:()=>R(t)},t.id))}):j.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.staysLocal`)}):(0,$.jsxs)(he,{accept:hn,onFiles:e=>void L(e),className:`h-16 w-full`,children:[s.busy?(0,$.jsx)(Z,{className:`size-4`}):(0,$.jsx)(Je,{className:`size-4`}),B(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:B(`project.assetAdd`)})]}),s.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error}):null,M?(0,$.jsx)(_n,{projectId:e,file:M,actions:s,onClose:()=>m(null)}):null,y?(0,$.jsx)(yn,{section:y===`current`?A:null,onClose:()=>b(null),onSave:e=>{if(y===`current`&&A)g(t=>t.map(t=>t.id===A.id?{...t,title:e}:t));else{let t=k();g(n=>[...n,{id:t,title:e,assets:[]}]),v(t)}},onRemove:y===`current`&&A?()=>{(!A.assets.length||confirm(B(`project.assetSectionRemoveConfirm`,{name:A.title})))&&(g(e=>e.filter(e=>e.id!==A.id)),v(``),b(null))}:void 0}):null,S?(0,$.jsx)(cn,{kind:`asset`,onClose:()=>C(!1),fetchUrl:e=>s.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)F(t.id,A?.id??null)}}):null]})}var xn=/^#[0-9a-fA-F]{6}$/;async function Sn(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 Cn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function wn({projectId:e,gradient:t,isNew:n,brand:r,onSave:i,onClose:a}){let[s,c]=(0,Q.useState)(t),[l,d]=(0,Q.useState)(u(t)),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(!n),C=e=>{c(e),d(u(e)),p(!1)},w=(e,t)=>C({...s,stops:s.stops.map((n,r)=>r===e?{...n,...t}:n)}),T=e=>{let t=[...s.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));C({...s,stops:[...s.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},E=async()=>{_(!0),b(null);try{let{gradient:t}=await j.post(`/api/studio/projects/${e}/gradients/describe`,{text:m.trim(),...x?{gradient:{name:s.name,type:s.type,angle:s.angle,stops:s.stops}}:{}});C({...s,...t,name:s.name.trim()?s.name:t.name}),h(``),S(!0)}catch(e){b(e.message)}_(!1)};return(0,$.jsx)(Y,{open:!0,onClose:a,wide:!0,title:B(n?`project.gradientNew`:`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m.trim()&&!g&&E()},children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(F,{"data-autofocus":n||void 0,value:m,maxLength:1e3,"aria-label":B(`project.gradientDescribe`),placeholder:B(x?`project.gradientDescribeChange`:`project.gradientDescribeNew`),onChange:e=>h(e.target.value),className:`min-w-0 flex-1`}),(0,$.jsxs)(N,{type:`submit`,variant:`secondary`,busy:g,disabled:!m.trim(),children:[(0,$.jsx)(ge,{className:`size-4`}),B(x?`project.gradientDescribeApply`:`project.gradientDescribeMake`)]})]}),(0,$.jsx)(`p`,{className:J(`mt-1.5 text-[0.8125rem]`,v?`text-rose`:`text-ink-3`),children:v??B(`project.gradientDescribeHint`)})]}),(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:u(s)}}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.gradientName`)}),(0,$.jsx)(F,{value:s.name,maxLength:80,placeholder:B(`project.gradientNamePlaceholder`),onChange:e=>c({...s,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.fillUseLabel`)}),(0,$.jsx)(F,{value:s.description??``,maxLength:400,placeholder:B(`project.gradientUse`),onChange:e=>c({...s,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:K.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":s.type===e,onClick:()=>C({...s,type:e}),className:J(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,s.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:B(Cn[e])},e))})]}),s.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(L,{children:B(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:s.angle,"aria-label":B(`project.gradientAngle`),onChange:e=>C({...s,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(s.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:s.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(ue,{value:xn.test(e.color)?e.color:`#888888`,onChange:e=>w(t,{color:e.target.value})}),(0,$.jsx)(F,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();xn.test(n)&&w(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":B(`project.gradientAt`),onChange:e=>w(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)(I,{label:B(`project.remove`),disabled:s.stops.length<=2,onClick:()=>C({...s,stops:s.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(W,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[s.stops.length<12?(0,$.jsxs)(N,{variant:`secondary`,size:`sm`,onClick:()=>T(),children:[(0,$.jsx)(o,{className:`size-4`}),` `,B(`project.gradientStopAdd`)]}):null,r.length&&s.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:B(`project.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>T(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)(L,{children:`CSS`}),(0,$.jsx)(F,{value:l,spellCheck:!1,onChange:e=>{d(e.target.value);let t=y(e.target.value);p(!t),t&&c({...s,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:J(`mt-1.5 text-[0.8125rem]`,f?`text-rose`:`text-ink-3`),children:B(f?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(N,{variant:`ghost`,onClick:a,children:B(`common.cancel`)}),(0,$.jsx)(N,{onClick:()=>{i(s),a()},children:B(`settings.save`)})]})]})})}var Tn=`absolute top-1.5 right-1.5 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover/card:opacity-100 coarse:opacity-100`,En=`size-8 bg-card shadow-soft hover:bg-card`;function Dn({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(xe,{value:e,label:B(`project.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,$.jsx)(xe,{value:n??``,label:B(`project.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function On({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=u(e),[o,s]=(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,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":B(`project.gradientEdit`),onClick:n,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:Tn,children:[(0,$.jsx)(I,{label:B(o?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:En,children:(0,$.jsx)(we,{className:`size-4`})}),(0,$.jsx)(I,{label:B(`project.download`),onClick:()=>void Sn(e,e.name),className:En,children:(0,$.jsx)(b,{className:`size-4`})}),t?null:(0,$.jsx)(I,{label:B(`project.remove`),onClick:i,className:J(En,`hover:text-rose`),children:(0,$.jsx)(W,{className:`size-4`})})]})]}),(0,$.jsx)(Dn,{name:e.name,namePlaceholder:B(`project.gradientName`),description:e.description,usePlaceholder:B(`project.gradientUse`),readOnly:t,onChange:r})]})}function kn(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function An({projectId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:o}){let s=Ce(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,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:r,"aria-label":B(`project.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:kn(s,t.tile)}),(0,$.jsxs)(`div`,{className:Tn,children:[(0,$.jsx)(`a`,{href:s,download:n,"aria-label":B(`project.download`),title:B(`project.download`),className:J(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,En),children:(0,$.jsx)(b,{className:`size-4`})}),r?null:(0,$.jsx)(I,{label:B(`project.remove`),onClick:o,className:J(En,`hover:text-rose`),children:(0,$.jsx)(W,{className:`size-4`})})]})]}),(0,$.jsx)(Dn,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:B(`project.patternUse`),readOnly:r,onChange:a})]})}function jn({projectId:e,pattern:t,isNew:n,fileName:r,busy:i,error:a,upload:o,removeFile:s,onSave:c,onClose:l}){let[u,d]=(0,Q.useState)(t),[f,p]=(0,Q.useState)([]),m=async e=>{let t=e[0];if(!t)return;let n=await o(t);n&&(p(e=>[...e,n.id]),d(e=>({...e,file:n.id,name:e.name||n.name.replace(/\.[^.]+$/,``)})))},h=()=>{for(let e of f)s(e);l()};return(0,$.jsx)(Y,{open:!0,onClose:h,wide:!0,title:B(n?`project.patternNew`:`project.patternEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[u.file?(0,$.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:kn(Ce(e,u.file),u.tile),children:(0,$.jsxs)(he,{accept:`image/*`,multiple:!1,onFiles:e=>void m(e),className:`absolute right-2 bottom-2 h-9 border-solid bg-card px-3.5 text-ink-2 shadow-soft`,children:[i?(0,$.jsx)(Z,{className:`size-4`}):(0,$.jsx)(S,{className:`size-4`}),B(`project.patternReplace`)]})}):(0,$.jsxs)(he,{accept:`image/*`,multiple:!1,onFiles:e=>void m(e),className:`h-40 flex-col`,children:[i?(0,$.jsx)(Z,{className:`size-5`}):(0,$.jsx)(S,{className:`size-5`}),B(`project.patternPick`)]}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.patternName`)}),(0,$.jsx)(F,{value:u.name,maxLength:80,placeholder:u.file?r(u.file):B(`project.patternNamePlaceholder`),onChange:e=>d({...u,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.fillUseLabel`)}),(0,$.jsx)(F,{value:u.description??``,maxLength:400,placeholder:B(`project.patternUse`),onChange:e=>d({...u,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.patternShow`)}),(0,$.jsx)(`div`,{className:`flex w-fit gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:[!1,!0].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!u.tile===e,onClick:()=>d({...u,tile:e||void 0}),className:J(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,!!u.tile===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:B(e?`project.patternTile`:`project.patternFill`)},String(e)))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[a?(0,$.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:a}):null,(0,$.jsx)(N,{variant:`ghost`,onClick:h,children:B(`common.cancel`)}),(0,$.jsx)(N,{disabled:!u.file||i,onClick:()=>{for(let e of f.filter(e=>e!==u.file))s(e);t.file&&t.file!==u.file&&s(t.file),c({...u,name:u.name.trim(),description:u.description?.trim()||void 0}),l()},children:B(n?`project.add`:`settings.save`)})]})]})})}var Mn=/^#[0-9a-fA-F]{6}$/;function Nn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),p=async()=>{o(!0),c(null);try{let{colors:t}=await j.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(u(t),f([])):c(B(`project.colorsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(Y,{open:!0,onClose:n,wide:l?!0:void 0,title:B(l?`project.colorsFound`:`project.colorsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:l.map(e=>{let t=d.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>f(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:J(`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)(M,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(N,{variant:`ghost`,onClick:()=>u(null),children:B(`run.back`)}),(0,$.jsx)(N,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.value))),n()},children:d.length>1?B(`project.addMany`,{n:d.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.logoUrl`)}),(0,$.jsx)(F,{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:B(`project.colorsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(N,{variant:`ghost`,onClick:n,children:B(`common.cancel`)}),(0,$.jsx)(N,{type:`submit`,busy:a,disabled:!r.trim(),children:B(`run.next`)})]})]})})}function Pn({projectId:e,data:t,colors:n,sections:r,gradients:s,patterns:c,rules:u,sectioned:d,ruled:f,save:p,readOnly:m}){let[h,g]=(0,Q.useState)(()=>n.map(e=>({...e,id:k()}))),[y,b]=(0,Q.useState)(r),[S,C]=(0,Q.useState)(s),[w,T]=(0,Q.useState)(c),[E,D]=(0,Q.useState)(null),[ee,O]=(0,Q.useState)(null),A=te(e,m),j=l(u),[M,N]=(0,Q.useState)(null),[P,L]=(0,Q.useState)(null),[R,ne]=(0,Q.useState)(!1),re=i({colors:h.filter(e=>Mn.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:y,gradients:S,patterns:w,colorRules:j.rules},p),ie=d?y:[],z=ie.filter(e=>(e.kind??`colors`)===`colors`),oe=e=>z.some(t=>t.id===e.section),V=h.filter(e=>!oe(e)),se=(V[0]??h[0])?.id,G=(e,t)=>g(n=>n.map(n=>n.id===e?{...n,...t}:n)),ce=e=>g(t=>[...t,...e.map(e=>({...e,id:k()}))].slice(0,x.colors)),K=[{value:``,label:B(`project.sectionStandard`)},...z.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],q=(e,t)=>{let n=k();N(n),b(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},le=e=>({id:k(),name:``,section:e,type:`linear`,angle:90,stops:[{color:h[0]?.value&&Mn.test(h[0].value)?h[0].value:`#4b73ff`,at:0},{color:h[1]?.value&&Mn.test(h[1].value)?h[1].value:`#ff6d1b`,at:100}]}),J=e=>t.files.find(t=>t.id===e)?.name??`pattern`,de=[...h.length<x.colors?[{label:B(`project.colorNew`),icon:(0,$.jsx)(o,{className:`size-4 shrink-0`}),onPick:()=>Y()},{label:B(`project.colorsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>ne(!0)}]:[],...d&&y.length<x.logoSections?[{label:B(`project.colorSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>q(`colors`,``)},{label:B(`project.gradientSectionAdd`),icon:(0,$.jsx)(Pt,{className:`size-4 shrink-0`}),onPick:()=>q(`gradients`,B(`project.gradientSectionTitle`))},{label:B(`project.patternSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>q(`patterns`,B(`project.patternSectionTitle`))}]:[],...!f||j.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)(rt,{className:`size-4 shrink-0`}),onPick:()=>j.add()}]],fe=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(ue,{value:Mn.test(e.value)?e.value:`#888888`,onChange:t=>G(e.id,{value:t.target.value})}),(0,$.jsx)(F,{value:e.name,autoFocus:e.id===P,placeholder:B(`project.colorName`),maxLength:120,onChange:t=>G(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(F,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>G(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===se?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(v,{tone:`ember`,children:B(`project.colorAccent`)})}):m?null:(0,$.jsx)(I,{label:B(`project.colorFirst`),onClick:()=>g(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)(_,{className:`size-4`})}),m||!z.length?null:(0,$.jsx)(ae,{options:K,value:oe(e)?e.section??``:``,onChange:t=>G(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),m?null:(0,$.jsx)(I,{label:B(`project.remove`),onClick:()=>g(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)(W,{className:`size-4`})})]})]},e.id),Y=e=>{let t=k();L(t),g(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,$.jsxs)(a,{title:B(`project.colors`),hint:B(`project.colorsHint`),save:re,locked:m,action:m?null:(0,$.jsx)(U,{entries:de}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[V.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:V.map(fe)}),m?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.colorUse`)})]}):h.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.colorsEmpty`)}),ie.map(t=>{let n=t.kind??`colors`,r=h.filter(e=>e.section===t.id),i=S.filter(e=>e.section===t.id),a=w.filter(e=>e.section===t.id),s=n===`gradients`?i.length:n===`patterns`?a.length:r.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(_e,{title:t.title,titlePlaceholder:B(n===`gradients`?`project.gradientSectionTitlePlaceholder`:n===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),kind:n===`gradients`?{icon:(0,$.jsx)(Pt,{}),label:B(`project.kindGradients`)}:n===`patterns`?{icon:(0,$.jsx)(Ht,{}),label:B(`project.kindPatterns`)}:{icon:(0,$.jsx)(Ye,{}),label:B(`project.kindColors`)},autoFocus:M===t.id,readOnly:m,onChange:e=>b(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!s||confirm(B(n===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:t.title||B(`project.sectionUntitled`)}))){b(e=>e.filter(e=>e.id!==t.id)),g(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),C(e=>e.filter(e=>e.section!==t.id));for(let e of a)A.remove(e.file);T(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[i.map(e=>(0,$.jsx)(On,{gradient:e,readOnly:m,onEdit:()=>D(e),onChange:t=>C(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>C(t=>t.filter(t=>t.id!==e.id))},e.id)),m||S.length>=x.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>D(le(t.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)(o,{className:`size-5`}),B(`project.gradientAdd`)]})]}):n===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(t=>(0,$.jsx)(An,{projectId:e,pattern:t,fileName:J(t.file),readOnly:m,onEdit:()=>O(t),onChange:e=>T(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{A.remove(t.file),T(e=>e.filter(e=>e.id!==t.id))}},t.id)),m||w.length>=x.files.pattern?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>O({id:k(),name:``,section:t.id,file:``}),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)(o,{className:`size-5`}),B(`project.patternAdd`)]})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(fe),m||h.length>=x.colors?null:(0,$.jsx)(H,{label:B(`project.colorAdd`),onClick:()=>Y(t.id)})]})]},t.id)}),f?(0,$.jsx)(ye,{rules:j,placeholder:B(`project.colorRulePlaceholder`),readOnly:m}):null]}),A.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:A.error}):null,E?(0,$.jsx)(wn,{projectId:e,gradient:E,isNew:!S.some(e=>e.id===E.id),brand:h.filter(e=>Mn.test(e.value)),onClose:()=>D(null),onSave:e=>C(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,ee?(0,$.jsx)(jn,{projectId:e,pattern:ee,isNew:!w.some(e=>e.id===ee.id),fileName:J,busy:A.busy,error:A.error,upload:async e=>(await A.upload(`pattern`,[e]))[0]??null,removeFile:e=>void A.remove(e),onClose:()=>O(null),onSave:e=>T(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,R?(0,$.jsx)(Nn,{projectId:e,onClose:()=>ne(!1),onAdd:ce}):null]})}var Fn=e=>/^(ja|yes|true)$/i.test(e.trim()),In={text:bt,longtext:Ke,number:De,date:He,url:q,email:et,phone:We,boolean:Ue};function Ln({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{s.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 c=In[e??t],l=`${B(`project.factType`)}: ${B(`project.type.${e??t}`)}`,u=`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`,d=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:l,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:J(`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)(c,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:J(`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:u,onClick:()=>d(void 0),children:[(0,$.jsx)(yt,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:B(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:B(`project.type.${t}`)}),(0,$.jsx)(M,{className:J(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),T.map(t=>{let n=In[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:u,onClick:()=>d(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:B(`project.type.${t}`)}),(0,$.jsx)(M,{className:J(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Rn({facts:e,save:t,readOnly:n}){let r=(0,Q.useRef)(0),c=(0,Q.useRef)(null),[l,u]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),d=i(l.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),f=(e,t)=>u(n=>n.map(n=>n.id===e?{...n,...t}:n)),p=(e,t,n=!1)=>{let i=`f${r.current++}`;c.current=`${i}:${t}`;let a={id:i,key:``,label:``,value:``,...e};u(e=>n?[a,...e]:[...e,a])},m=e=>t=>{t&&c.current===e&&(c.current=null,t.focus())},h=s.filter(e=>!l.some(t=>t.key===e.key));return(0,$.jsxs)(a,{title:B(`project.facts`),hint:B(`project.factsHint`),save:d,locked:n,action:l.length<x.facts&&!n?(0,$.jsxs)(N,{variant:`secondary`,size:`sm`,onClick:()=>p({},`label`,!0),children:[(0,$.jsx)(o,{className:`size-4`}),` `,B(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>{let t=C(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)(F,{ref:m(`${e.id}:label`),value:e.label,placeholder:B(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>f(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&f(e.id,{key:E(e.label,l.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)(pe,{checked:Fn(e.value),label:e.label,onChange:t=>f(e.id,{value:B(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Fn(e.value)?B(`project.yes`):B(`project.no`)})]}):(0,$.jsx)(re,{ref:m(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:B(`project.factValue`),onChange:t=>f(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(Ln,{type:e.type,detected:t,onChange:t=>f(e.id,{type:t})}),n?null:(0,$.jsx)(I,{label:B(`project.remove`),onClick:()=>u(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(W,{className:`size-4`})})]},e.id)})}),l.length<x.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${l.length?`mt-4`:``}`,children:[(0,$.jsxs)(N,{variant:`secondary`,size:`sm`,onClick:()=>p({},`label`),children:[(0,$.jsx)(o,{className:`size-4`}),` `,B(`project.factAdd`)]}),h.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>p({key:e.key,label:z===`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)(o,{className:`size-3.5`}),` `,z===`en`?e.en:e.de]},e.key))]}):null]})}function zn({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(on);i(!1),n&&(t.preventDefault(),e(n))},className:J(`-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 Bn({projectId:e,data:t,readOnly:n,sections:r,rules:o,sectioned:s,ruled:c,save:u}){let d=te(e,n),[f,p]=(0,Q.useState)(r),h=l(o),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(!1),b=(0,Q.useRef)(null),S=i({logoSections:f,logoRules:h.rules},u),C=t.files.filter(e=>e.kind===`logo`),w=new Map(C.map(e=>[e.id,e])),T=s?f:[],E=new Set(T.flatMap(e=>e.logos)),D=C.filter(e=>!E.has(e.id)),ee=m(C,f)?.id,O=(e,t)=>p(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),A=(e,t)=>p(n=>n.map(n=>n.id===e?{...n,...t}:n)),j=async(e,t)=>{let n=await d.upload(`logo`,e);for(let e of n)O(e.id,t)},M=T.length?{options:[{value:``,label:B(`project.sectionStandard`)},...T.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],current:e=>T.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>O(e.id,t||null)}:void 0,N=(t,n,r)=>(0,$.jsx)(sn,{projectId:e,kind:`logo`,files:t,actions:d,accept:`image/*`,addLabel:r?B(`project.logoAdd`):void 0,onUpload:e=>void j(e,n),mainId:ee,onMakeMain:e=>{O(e.id,null),d.order(`logo`,[e.id,...C.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:M,onRemove:e=>{confirm(B(`project.removeConfirm`,{name:e.name}))&&(d.remove(e.id),O(e.id,null))}}),P=n?void 0:e=>t=>O(t,e),F=[{label:B(`project.logoUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>b.current?.click()},{label:B(`project.logoFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>y(!0)},...s&&f.length<x.logoSections?[{label:B(`project.logoSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>{let e=k();_(e),p(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!c||h.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)(rt,{className:`size-4 shrink-0`}),onPick:()=>h.add()}]];return(0,$.jsxs)(a,{title:B(`project.logos`),hint:B(`project.logosHint`),save:S,action:n?null:(0,$.jsx)(U,{entries:F}),children:[(0,$.jsx)(`input`,{ref:b,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&&j(t,null)}}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(zn,{onLogo:P?.(null),children:N(D,null,!0)}),T.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(zn,{onLogo:P?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(_e,{title:e.title,description:e.description,titlePlaceholder:B(`project.logoSectionTitle`),descriptionPlaceholder:B(`project.logoSectionUse`),autoFocus:g===e.id,readOnly:n,onChange:t=>A(e.id,t),onRemove:()=>{(!e.logos.length||confirm(B(`project.logoSectionRemoveConfirm`,{name:e.title||B(`project.sectionUntitled`)})))&&p(t=>t.filter(t=>t.id!==e.id))}}),N(e.logos.map(e=>w.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),c?(0,$.jsx)(ye,{rules:h,placeholder:B(`project.logoRulePlaceholder`),readOnly:n}):null]}),d.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:d.error}):null,v?(0,$.jsx)(cn,{kind:`logo`,onClose:()=>y(!1),fetchUrl:e=>d.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)O(t.id,null)}}):null]})}var Vn=new Set;function Hn(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Vn.has(t))return;Vn.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${r.join(`,`)}&display=swap`,document.head.append(n)},[e])}var Un=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function Wn({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 Gn=`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`,Kn={web:`project.fontUseWeb`,documents:`project.fontUseDocuments`,print:`project.fontUsePrint`,images:`project.fontUseImages`,video:`project.fontUseVideo`};function qn({font:e,first:t,readOnly:n,autoFocus:i,onChange:a,onRemove:o}){return Hn(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:Un(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)(xe,{value:e.family,label:B(`project.fontFamily`),placeholder:B(`project.fontFamily`),maxLength:80,autoFocus:i,onChange:e=>a({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(xe,{value:e.role,label:B(`project.fontRole`),placeholder:B(t?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>a({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map(t=>{let r=e.weights.includes(t);return(0,$.jsx)(`button`,{type:`button`,disabled:n,"aria-pressed":r,onClick:()=>a({weights:r?e.weights.filter(e=>e!==t):[...e.weights,t].sort((e,t)=>e-t)}),style:{fontFamily:Un(e.family),fontWeight:t},className:J(`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)})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[n?e.license?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:e.license}):null:(0,$.jsx)(xe,{value:e.license??``,label:B(`project.fontLicense`),placeholder:B(`project.fontLicensePlaceholder`),maxLength:200,onChange:e=>a({license:e}),className:`text-[0.8125rem] text-ink-3`}),n&&!e.uses?.length?null:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:B(`project.fontUses`)}),le.map(t=>{let r=!!e.uses?.includes(t);return(0,$.jsxs)(`button`,{type:`button`,disabled:n,"aria-pressed":r,onClick:()=>{let n=r?(e.uses??[]).filter(e=>e!==t):le.filter(n=>n===t||e.uses?.includes(n));a({uses:n.length?n:void 0})},className:J(`inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-[0.8125rem] transition`,r?`bg-card text-ink ring-1 ring-border`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!r&&`hidden`),children:[r?(0,$.jsx)(M,{className:`size-3.5`}):null,B(Kn[t])]},t)})]})]}),n?null:(0,$.jsx)(I,{label:B(`project.remove`),onClick:o,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)(W,{className:`size-4`})})]})}function Jn({style:e,fonts:t,sample:n,readOnly:i,autoFocus:a,onChange:o,onRemove:s}){let c=t.find(t=>t.id===e.font)??t[0],l={fontFamily:Un(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:[i?(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)(xe,{value:e.name,label:B(`project.styleName`),placeholder:B(`project.styleName`),maxLength:60,autoFocus:a,onChange:e=>o({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:i,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":B(`project.styleFont`),value:c?.id??``,onChange:e=>o({font:e.target.value}),className:J(Gn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||B(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":B(`project.styleWeight`),value:e.weight,onChange:e=>o({weight:Number(e.target.value)}),className:Gn,children:[...new Set([...r,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(Wn,{unit:`px`,label:B(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>o({size:Number(e.target.value)||16})}),(0,$.jsx)(Wn,{unit:B(`project.styleLine`),label:B(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>o({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(Wn,{unit:B(`project.styleTracking`),label:B(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>o({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:B(`project.styleUpper`),"aria-label":B(`project.styleUpper`),onClick:()=>o({uppercase:!e.uppercase}),className:J(`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)(Rt,{className:`size-4`})})]}),i?null:(0,$.jsx)(I,{label:B(`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)(W,{className:`size-4`})})]})]})}function Yn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),p=async()=>{o(!0),c(null);try{let{fonts:t}=await j.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(u(t),f(t.slice(0,2).map(e=>e.family))):c(B(`project.fontsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(Y,{open:!0,onClose:n,wide:l?!0:void 0,title:B(l?`project.fontsFound`:`project.fontsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,$.jsx)(Xn,{font:e,on:d.includes(e.family),onToggle:()=>f(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)(N,{variant:`ghost`,onClick:()=>u(null),children:B(`run.back`)}),(0,$.jsx)(N,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.family))),n()},children:d.length>1?B(`project.addMany`,{n:d.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.logoUrl`)}),(0,$.jsx)(F,{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:B(`project.fontsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(N,{variant:`ghost`,onClick:n,children:B(`common.cancel`)}),(0,$.jsx)(N,{type:`submit`,busy:a,disabled:!r.trim(),children:B(`run.next`)})]})]})})}function Xn({font:e,on:t,onToggle:n}){return Hn(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:J(`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:Un(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(` · `):B(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(M,{className:`size-3.5`})}):null]})}function Zn({projectId:e,fonts:t,styles:n,rules:r,ruled:s,sample:c,save:u,readOnly:d}){let[f,p]=(0,Q.useState)(t),[m,h]=(0,Q.useState)(n),g=l(r),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(!1),S=i({fonts:f,textStyles:m,typeRules:g.rules},u),C=(e,t=!1)=>{let n=e.map(e=>({id:k(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&v(n[0].id),p(e=>[...e,...n].slice(0,x.fonts))},w=()=>{let e=k();v(e),h(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},T=[...f.length<x.fonts?[{label:B(`project.fontNew`),icon:(0,$.jsx)(o,{className:`size-4 shrink-0`}),onPick:()=>C([{family:``,weights:[400,700]}],!0)},{label:B(`project.fontsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>b(!0)}]:[],...m.length<x.textStyles?[{label:B(`project.styleNew`),icon:(0,$.jsx)($e,{className:`size-4 shrink-0`}),onPick:w}]:[],...!s||g.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)(rt,{className:`size-4 shrink-0`}),onPick:()=>g.add()}]];return(0,$.jsxs)(a,{title:B(`project.typography`),hint:B(`project.typographyHint`),save:S,action:d?null:(0,$.jsx)(U,{entries:T}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[f.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:f.map((e,t)=>(0,$.jsx)(qn,{font:e,first:t===0,readOnly:d,autoFocus:_===e.id,onChange:t=>p(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>p(t=>t.filter(t=>t.id!==e.id))},e.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.fontsEmpty`)}),m.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:B(`project.styles`)}),d?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:B(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:m.map(e=>(0,$.jsx)(Jn,{style:e,fonts:f,sample:c,readOnly:d,autoFocus:_===e.id,onChange:t=>h(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>h(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,s?(0,$.jsx)(ye,{rules:g,placeholder:B(`project.typeRulePlaceholder`),readOnly:d}):null]}),y?(0,$.jsx)(Yn,{projectId:e,onClose:()=>b(!1),onAdd:e=>C(e)}):null]})}function Qn({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[o,s]=(0,Q.useState)(e.brand.about??``),c=i({name:n.trim(),about:o.trim()},e=>t({brand:e}));return(0,$.jsx)(a,{title:B(`project.base`),hint:B(`project.baseHint`),save:c,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.title`)}),(0,$.jsx)(F,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{children:B(`project.about`)}),(0,$.jsx)(re,{minRows:4,value:o,onChange:e=>s(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.aboutHint`)})]})]})})}function $n({project:e,group:t,children:n}){let r=w(),i=A(e.id),[a,o]=(0,Q.useState)(0),s=async t=>{await j.patch(`/api/studio/projects/${e.id}`,t),await r.invalidateQueries({queryKey:[`projects`]})},c=it({mutationFn:()=>j.del(`/api/studio/projects/${e.id}`),onSuccess:()=>r.invalidateQueries({queryKey:[`projects`]})}),l=mt(),u=ot(),d=i.data??{files:[],embeddings:!0},f=`${e.id}:${a}`,p=e.readOnly,m=t===`knowledge`,h=lt(`brandSections`),g=lt(`brandRules`),_=lt(`typography`);return tt(p?{}:{title:B(m?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:B(m?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:B(m?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:m?[{label:B(`assistant.suggest.knowledgeHow`)},{label:B(`assistant.suggest.knowledgeSite`),fill:!0},{label:B(`assistant.suggest.knowledgeCategories`)}]:[{label:B(`assistant.suggest.readSite`),fill:!0},{label:B(`assistant.suggest.missing`)},{label:B(`assistant.suggest.facts`)}],summary:m?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${d.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>o(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[p?(0,$.jsx)(qe,{children:Ge(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{id:`base`,children:(0,$.jsx)(Qn,{project:e,save:s},`base:${f}`)}),(0,$.jsx)(R,{id:`facts`,children:(0,$.jsx)(Rn,{facts:e.facts,save:e=>s({facts:e}),readOnly:p},`facts:${f}`)}),(0,$.jsx)(R,{id:`logos`,children:(0,$.jsx)(Bn,{projectId:e.id,data:d,readOnly:p,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:h,ruled:g,save:e=>s({brand:e})},`logos:${f}`)}),(0,$.jsx)(R,{id:`colors`,children:(0,$.jsx)(Pn,{projectId:e.id,data:d,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],sectioned:h,ruled:g,save:e=>s({brand:e}),readOnly:p},`colors:${f}`)}),_?(0,$.jsx)(R,{id:`typography`,children:(0,$.jsx)(Zn,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:g,sample:e.brand.name||B(`project.typeSample`),save:e=>s({brand:e}),readOnly:p},`typography:${f}`)}):null,(0,$.jsx)(R,{id:`assets`,children:(0,$.jsx)(bn,{projectId:e.id,data:d,readOnly:p,sections:e.brand.assetSections??[],save:e=>s({brand:e})},`assets:${f}`)})]}):null,n,t===`info`&&l&&!p&&u?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(N,{variant:`danger`,busy:c.isPending,onClick:()=>confirm(`${B(`settings.delete`)}?`)&&c.mutate(),children:B(`settings.delete`)}),c.error?(0,$.jsx)(`p`,{className:`mt-2 text-[0.875rem] text-rose`,children:c.error.message}):null]}):null]})}var er={q:``,mode:``,days:0};function tr(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 i=r.toString();return oe({queryKey:[`results`,e,i],queryFn:()=>j.get(`/api/studio/projects/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function nr({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)(Se,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(F,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:B(`space.resultsSearch`),"aria-label":B(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(V,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:B(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(V,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:B(`space.resultsAnyTime`)},{value:`1`,label:B(`space.resultsDay`)},{value:`7`,label:B(`space.resultsDays`,{n:7})},{value:`30`,label:B(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function rr({data:e,wizardId:t,filter:n,onFilter:r}){let[i,o]=(0,Q.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,l=new Intl.DateTimeFormat(z,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(a,{title:t?s(t):B(`space.resultsAll`),hint:B(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(nr,{filter:n,onFilter:r}),e.runs.length?(0,$.jsx)(f,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(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?l.format(new Date(e.doneAt)):s(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${l.format(new Date(e.doneAt))} · `,B(`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:B(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(c,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(v,{children:`Test`}):(0,$.jsxs)(v,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(f,{children:(0,$.jsx)(g,{children:n.q.trim()||n.mode||n.days?B(`space.resultsNone`):B(`space.resultsEmpty`)})})]}),i?(0,$.jsx)(Ie,{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)(v,{children:`Test`}):(0,$.jsxs)(v,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>o(null),children:(0,$.jsx)(Mt,{runId:i.id,compact:!0},i.id)}):null]})}function ir({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.name),o=it({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(I,{label:B(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,$.jsx)(ve,{className:`size-4`})}),(0,$.jsx)(Y,{open:n,onClose:()=>r(!1),title:B(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&o.mutate()},children:[(0,$.jsx)(F,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),o.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(N,{variant:`ghost`,onClick:()=>r(!1),children:B(`common.cancel`)}),(0,$.jsx)(N,{type:`submit`,busy:o.isPending,disabled:!i.trim(),children:B(`settings.save`)})]})]})})]})}function ar({project:e}){let t=w();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(st,{}),e.readOnly?null:(0,$.jsx)(ir,{project:e,save:async n=>{await j.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function or(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=ht(),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 sr(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function cr({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(St,{icon:e.icon??Qe,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(Tt,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function lr(){let{group:e}=ie(),[t,n]=de(),r=ce(),i=me(),{hash:o}=i,{project:s,loading:c}=ft(),l=mt(),u=_t(),d=jt(),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),y=ut(e)?e:void 0,b=y?void 0:u.spaceParts.find(t=>t.id===e),x=y??b?.id,S=i.state?.parts===!0,C=xt(vt(),u).map(e=>({...e,to:`/space/${e.id}`})),w=C.find(e=>e.id===x),T=t.get(`show`),E=x?T?2:1:0,D=d?Math.min(E,1):x&&_!==x&&!S?1:0,ee=wt(D),O=wt(E),k=(0,Q.useMemo)(()=>({slot:f,narrow:d,setDetail:h}),[f,d]),A=s?s.brand.name?.trim()||s.name:B(`nav.project`),te=ne(),j=!!te&&!d,M=lt(`typography`)?[]:[`typography`],N=b?u.spaceMenus[b.id]??[]:[],P=b?[{plugin:null,label:null,sections:N}]:y&&y!==`results`?at(y,u,M):[],F=y?at(y,u).filter(e=>e.plugin):[],I=or([...P,...y===`results`?F:[]].flatMap(e=>e.sections.map(e=>e.id))),L=y===`results`&&T&&T!==`all`?T:null,[re,ae]=(0,Q.useState)(er),z=tr(y===`results`?s?.id:void 0,L,re),oe=z.data?.wizards.find(e=>e.id===L)?.title,V=y===`data`&&T&&T!==`all`||y===`knowledge`&&T&&/^[ptfcvs]:/.test(T)?T:null,H=V?.startsWith(`s:`)?u.spaceSections.find(e=>e.id===V.slice(2)):void 0,U=y===`knowledge`&&V&&/^[ptf]:/.test(V)?V:null,W=Oe(y===`data`?s?.id:void 0),G=Fe(y===`knowledge`?s?.id:void 0),K=Ve(V?.startsWith(`v:`)?V.slice(2):``),q=G.data?.categories.find(e=>e.id===(V?.startsWith(`c:`)?V.slice(2):K.data?.category.id)),le=y===`knowledge`?H?H.label():V?.startsWith(`v:`)?K.data&&`${K.data.category.name}: ${K.data.value}`:V?.startsWith(`c:`)?q?.name:G.data?.items.find(e=>e.key===V)?.title:W.data?ze(W.data).flatMap(e=>e.items).find(e=>e.key===V)?.title:void 0;pt([{label:B(`nav.project`),to:`/space`},...w?[{label:w.label,to:`/space/${w.id}`}]:[],...w&&(m??oe??le)?[{label:m??oe??le}]:[]]);let ue={p:`page`,t:`table`,f:`file`,c:`kategorie`,v:`kategorie value`,s:`plugin section`};tt({...y===`data`||y===`results`?{compact:!0}:{},...y===`data`?{suggestions:[{label:B(`assistant.suggest.dataWhat`)},{label:B(`assistant.suggest.dataWho`)},{label:B(`assistant.suggest.dataEdit`)}]}:y===`results`?{suggestions:[{label:B(`assistant.suggest.resultsFailed`)},{label:B(`assistant.suggest.resultsCost`)},{label:B(`assistant.suggest.resultsShare`)}]}:{},...V&&le?{open:{kind:ue[V[0]]??`item`,id:V.slice(2),label:le}}:L&&oe?{open:{kind:`wizard`,id:L,label:oe}}:{}});let fe=y===`results`||y===`data`||V?o.slice(1):T||o.slice(1),Y=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${x}#${fe}`;fe&&Y.current!==e&&document.getElementById(fe)&&(Y.current=e,requestAnimationFrame(()=>sr(fe,!1)))},[x,fe,s?.id,u.spaceSections,N.length]),!x){let t=o.slice(1),n=t?dt(t,u):null;if(n===`knowledge`&&u.spaceSections.some(e=>e.id===t))return(0,$.jsx)(se,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(se,{to:d?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if((t||e)&&u.status!==`ready`)return null;if(e!==void 0||!d)return(0,$.jsx)(se,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(y===`knowledge`&&!T&&u.spaceSections.some(e=>e.id===o.slice(1)))return(0,$.jsx)(se,{to:`/space/knowledge?show=s:${o.slice(1)}`,replace:!0});let pe=e=>{if(d){r({search:`?show=${e}`});return}Y.current=`${x}#${e}`,sr(e,!0),r({search:``,hash:e},{replace:!0})},X=e=>d?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),Z=e=>e.flatMap(e=>e.sections).map(e=>u.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(R,{id:e.id,children:(0,$.jsx)(a,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(gt,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),he=d?void 0:I,ge=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Et,{title:A,open:D===1?w??null:null,onBack:()=>d?r(`/space`):v(x??null),root:{icon:Xe,label:B(`nav.project`),backLabel:B(`nav.wizards`),onBack:()=>r(`/`)}}),(0,$.jsx)(`div`,{className:J(Ct(ee)),children:D===0?(0,$.jsx)(Ot,{entries:C,current:d?void 0:w,onPick:()=>v(null)}):(0,$.jsx)(`div`,{ref:p})},D)]});return(0,$.jsxs)(Dt.Provider,{value:k,children:[j&&te?(0,$t.createPortal)(ge,te):null,(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:J(`grid gap-6`,!j&&`md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[j?null:(0,$.jsx)(`aside`,{className:J(`min-w-0 md:sticky md:top-6 md:self-start`,d&&E===2&&`hidden`,d&&O===`back`&&Ct(`back`)),children:ge}),x?(0,$.jsxs)(`div`,{className:J(`min-w-0`,d&&E<2&&`hidden`,d&&O===`deeper`&&Ct(`deeper`)),children:[d?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(At,{label:w?.label??A,onBack:()=>r(`/space/${x}`)})}):null,l&&s?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(ar,{project:s})}):null,y===`results`?(0,$.jsxs)(kt,{children:[(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(St,{icon:Wt,label:B(`space.resultsAll`),selected:!d&&!L,onPick:()=>X(`all`)}),z.data?.wizards.filter(e=>e.results||e.id===L).map(e=>(0,$.jsx)(St,{icon:yt,label:e.title,badge:e.results?(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!d&&e.id===L,onPick:()=>X(e.id)},e.id))]}),(0,$.jsx)(cr,{groups:F,current:he,onPick:pe})]}):y===`data`?(0,$.jsxs)(kt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(St,{icon:Kt,label:B(`data.all`),selected:!d&&!V,onPick:()=>X(`all`)})}),W.data?ze(W.data).map(e=>(0,$.jsx)(Tt,{label:e.label,children:e.items.map(e=>(0,$.jsx)(St,{icon:Ee[e.kind],label:e.title,selected:!d&&e.key===V,onPick:()=>X(e.key)},e.key))},e.key)):null,(0,$.jsx)(cr,{groups:F,current:he,onPick:pe})]}):y===`knowledge`?(0,$.jsxs)(kt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(St,{icon:Kt,label:B(`know.all`),selected:!(d||V),onPick:()=>X(`all`)})}),G.data?.categories.length?(0,$.jsx)(Tt,{label:B(`know.categories`),children:G.data.categories.map(e=>(0,$.jsx)(St,{icon:Me[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!d&&(V===`c:${e.id}`||K.data?.category.id===e.id),onPick:()=>X(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(cr,{groups:F,current:d?void 0:H?.id,onPick:e=>X(`s:${e}`)})]}):(0,$.jsx)(kt,{children:(0,$.jsx)(cr,{groups:P,current:he,onPick:pe})}),s&&(y===`info`||y===`knowledge`)?(0,$.jsxs)($n,{project:s,group:y,children:[y===`knowledge`?U?U.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:U.slice(2),onGone:()=>X(`all`),onOpen:X},U):U.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:U.slice(2),onGone:()=>X(`all`)},U):(0,$.jsx)(pn,{projectId:s.id,fileId:U.slice(2),readOnly:s.readOnly,onGone:()=>X(`all`)},U):G.data?H?(0,$.jsx)(a,{title:H.label(),hint:H.hint?.(),plain:!0,children:(0,$.jsx)(gt,{of:H,children:(0,$.jsx)(H.component,{})})},V):V?.startsWith(`c:`)?q?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(je,{projectId:s.id,category:q,readOnly:s.readOnly,onOpen:X,onGone:()=>X(`all`)}),q.type===`choice`?null:(0,$.jsx)(Be,{projectId:s.id,category:q,categories:G.data.categories,onOpen:X})]},V):null:V?.startsWith(`v:`)?K.data?(0,$.jsx)(Te,{value:K.data,readOnly:s.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[K.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:K.data.items.map(e=>(0,$.jsx)(ke,{item:e,categories:G.data.categories.filter(e=>e.id!==K.data?.category.id),onOpen:X},e.key))}):null,K.data.rows.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>X(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:B(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},V):null:(0,$.jsx)(R,{id:`documents`,children:(0,$.jsx)(Re,{projectId:s.id,data:G.data,readOnly:s.readOnly,onOpen:X})}):null:null,y===`info`?Z(F):null]},s.id):null,s&&b?(0,$.jsx)(gt,{of:b,children:(0,$.jsx)(ct,{part:b.id,children:(0,$.jsx)(b.component,{})},s.id)}):null,s&&y===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:V?.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:V.slice(2),onGone:()=>X(`all`)},V):V?.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:V.slice(2),onGone:()=>X(`all`)},V):(0,$.jsxs)($.Fragment,{children:[W.data?(0,$.jsx)(Le,{projectId:s.id,data:W.data,readOnly:s.readOnly,onOpen:X}):null,Z(F)]})}):null,s&&y===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[z.data?(0,$.jsx)(rr,{data:z.data,wizardId:L,filter:re,onFilter:ae}):null,z.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:z.error.message}):null,Z(F)]}):null,s||c?null:(0,$.jsx)(g,{children:B(`settings.noProject`)})]}):null]})})]})}export{lr as ProjectPage};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$n as r,J as i,Jn as a,Qn as o,Rt as s,U as c,Vn as l,Wn as u,Wt as d,Xt as f,an as p,sn as m,tn as h,tr as g,z as _,zt as v}from"./ui-DTuixH4y.js";import{a as y,i as b,n as x,o as S,r as C,s as w,t as ee}from"./ChatView-D0RRIl15.js";import{a as T,dt as E,ft as D,ht as te,n as O,o as k,ut as A}from"./index-B-D8UvL9.js";import{t as j}from"./RunnerView-D6sGVnRy.js";var M={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`}]]};M.node;var ne=u(M),N={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`}]]};N.node;var P=u(N),F={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`]};F.node;var I=u(F),L=e(t(),1);function R(){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=R(),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 V(e){(0,L.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 H=e(n(),1);function U(e){(0,L.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function W(e,t){(0,L.useEffect)(()=>{if(!e||!t)return;let n=i(`/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}]}),a=document.createElement(`meta`);return a.name=`apple-mobile-web-app-title`,a.content=t,document.head.appendChild(a),()=>{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);a.remove()}},[e,t])}var G=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,K=G||/Android/.test(navigator.userAgent);function q(){let[e,t]=(0,L.useState)(()=>window.wizardInstall??null),[n,r]=(0,L.useState)(!1);if((0,L.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||K&&!e&&!G)return null;let i=/Mac/.test(navigator.platform),a=p(K?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,H.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>{K&&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:[K?(0,H.jsx)(I,{className:`size-4`}):(0,H.jsx)(ne,{className:`size-4`}),p(K?`install.add`:`install.bookmark`)]}),n?(0,H.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function J({brand:e,toggle:t=!0}){return(0,H.jsx)(`header`,{className:`safe-top`,children:(0,H.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,H.jsx)(`img`,{src:i(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,H.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,H.jsx)(`div`,{className:`absolute right-3`,children:(0,H.jsx)(D,{})}):null]})})}function Y({siteKey:e,onToken:t}){let n=(0,L.useRef)(null);return(0,L.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,H.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function ae({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||O||z?null:(0,H.jsxs)(`a`,{href:T(`${window.location.origin}${c}/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,H.jsx)(P,{className:`size-4`}),` `,p(`install.app`)]})}var X=e=>`wz.run.${e}`,Z=O&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=z===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t){let n=o(),[r,i]=(0,L.useState)(!1),[a,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),u=(()=>{try{return localStorage.getItem(X(e.token))}catch{return null}})();return{busy:r,error:a,captcha:c,setCaptcha:l,start:async()=>{i(!0),s(null);try{let{runId:r}=await _.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(X(e.token),r)}catch{}n(`${t}/${r}`,{replace:Z})}catch(e){s(e.message),i(!1)}},resume:u?()=>n(`${t}/${u}`):null}}function oe({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:i,start:a,resume:o}=$(e,`/w/${e.token}`),s=Z&&e.available&&!e.turnstileSiteKey,c=(0,L.useRef)(!1);return(0,L.useEffect)(()=>{s&&!c.current&&(c.current=!0,a())},[s]),s&&!n?(0,H.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,H.jsx)(f,{})}):(0,H.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,H.jsx)(E,{kind:e.avatar,size:190,fluffy:!0}),(0,H.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,H.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(v,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:a,children:[p(`run.start`),` `,(0,H.jsx)(l,{className:`size-4`})]}),e.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:e.turnstileSiteKey,onToken:i}):null,o?(0,H.jsx)(`button`,{type:`button`,onClick:o,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:p(`run.resume`)}):null,(0,H.jsx)(se,{wizard:e,current:`steps`}),z||O?null:(0,H.jsx)(q,{}),(0,H.jsx)(ae,{token:e.token})]}):(0,H.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??p(`run.unavailable`)}),n?(0,H.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function se({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,H.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,H.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:p(`run.orAs`,{label:e.label})},e.id))}):null}function ce({wizard:e}){let t=w();return(0,H.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,H.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,H.jsx)(`span`,{className:h(t?.speaking&&`animate-breathe`),children:(0,H.jsx)(E,{kind:e.avatar,size:38})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,H.jsx)(`img`,{src:i(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,H.jsx)(D,{}),z===`popout`?(0,H.jsx)(d,{label:p(`common.close`),onClick:ie,children:(0,H.jsx)(m,{className:`size-5`})}):null]})})}function le({door:e,wizard:t,header:n,footer:r}){let{busy:i,error:a,captcha:o,setCaptcha:s,start:c,resume:u}=$(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:p(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||d.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??p(`run.unavailable`)}),a&&d.push({key:`error`,who:`bot`,node:a,tone:`error`}),t.available&&d.push(S(`start`,(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(b,{primary:!0,busy:i,disabled:!!t.turnstileSiteKey&&!o,onClick:()=>void c(),children:[p(`run.start`),` `,(0,H.jsx)(l,{className:`size-4`})]}),u?(0,H.jsx)(b,{onClick:u,children:p(`run.resume`)}):null,t.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:t.turnstileSiteKey,onToken:s}):null]}))),(0,H.jsxs)(x,{header:n,footer:r,children:[(0,H.jsx)(y,{avatar:t.avatar,lines:d}),(0,H.jsx)(C,{})]})}function ue({className:e}){return(0,H.jsx)(`footer`,{className:h(`text-center text-ink-4`,e),children:(0,H.jsx)(`a`,{href:`${c}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:p(`run.madeWith`).replace(`engenty wizards`,A.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:i=!1}){let{token:l,runId:u}=r(),d=o(),m=g({queryKey:[`public`,l],queryFn:()=>_.get(`/api/public/wizards/${l}`),retry:(e,t)=>s(t)&&e<3}),y=m.data?.runners??[],b=!m.data||y.some(e=>e.id===`talk`),x=!m.data||y.some(e=>e.id===`video`),S=!m.data||y.some(e=>e.id===`chat`)||n&&b||i&&x,C=y[0]?.id,w=e||z===`popout`||!t&&!u&&S&&(C===`chat`||C===`talk`||C===`video`),T=i&&x||!t&&!e&&!n&&C===`video`,D=!T&&(n&&b||!t&&!e&&C===`talk`),M=T?`video`:D?`talk`:`chat`;if(U(m.data?.brand.accent),te(m.data?.avatar),W(l,m.data?.title),V(w),(0,L.useEffect)(()=>{m.data&&(document.title=m.data.title)},[m.data]),(0,L.useEffect)(()=>{l&&u&&k(`run`,{token:l,runId:u})},[l,u]),m.isLoading)return(0,H.jsx)(`div`,{className:h(`flex items-center justify-center text-ink-4`,Q),children:(0,H.jsx)(f,{})});if(e&&m.data&&!S||n&&m.data&&!b||i&&m.data&&!x)return(0,H.jsx)(a,{to:`/w/${l}`,replace:!0});if(!m.data){let e=s(m.error);return(0,H.jsxs)(`div`,{className:h(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,H.jsx)(E,{kind:`pebble`,size:80}),(0,H.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:p(e?`common.offline`:`run.notFound`)}),e?(0,H.jsx)(v,{variant:`secondary`,onClick:()=>void m.refetch(),children:p(`common.retry`)}):null]})}if(w){let e=(0,H.jsx)(ce,{wizard:m.data}),t=O?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,H.jsx)(`div`,{className:`flex h-dvh flex-col`,children:u?(0,H.jsx)(ee,{runId:u,talk:D,call:T?`video`:D?`audio`:!1,onRestart:()=>d(`/w/${l}/${M}`),header:T||D?void 0:e,footer:t}):(0,H.jsx)(le,{wizard:m.data,header:e,footer:t,door:M})})}return(0,H.jsxs)(`div`,{className:h(`flex flex-col`,Q),children:[z===`inline`||O?null:(0,H.jsx)(J,{brand:m.data.brand,toggle:!z}),(0,H.jsx)(`div`,{className:`flex-1`,children:u?(0,H.jsx)(j,{runId:u,onRestart:()=>d(`/w/${l}`)}):(0,H.jsx)(oe,{wizard:m.data})}),O?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,H.jsx)(`a`,{href:`${c}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:p(`run.madeWith`).replace(`engenty wizards`,A.name)})})]})}export{J as BrandHeader,de as PublicRunner,U as useBrandAccent};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,J as i,Ut as a,W as o,Wt as s,Xn as c,Yt as l,ar as u,cr as d,dn as f,er as ee,ir as p,on as m,pn as h,qn as g,tn as _}from"./ui-DrdqFaQt.js";import{a as v,i as y,n as b,o as x,r as S,s as C,t as w}from"./ChatView-BcyUYN0Q.js";import{a as T,dt as E,ft as D,gt as te,n as O,o as k,pt as A}from"./index-BRDn-5v_.js";import{t as j}from"./RunnerView-CDCp61aq.js";var M={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`}]]};M.node;var ne=c(M),N={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`}]]};N.node;var P=c(N),F={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`]};F.node;var I=c(F),L=e(t(),1);function R(){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=R(),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 V(e){(0,L.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 H=e(n(),1);function U(e){(0,L.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function W(e,t){(0,L.useEffect)(()=>{if(!e||!t)return;let n=r(`/api/public/wizards/${e}`),i=[{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}]}),a=document.createElement(`meta`);return a.name=`apple-mobile-web-app-title`,a.content=t,document.head.appendChild(a),()=>{for(let{link:e,before:t}of i)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);a.remove()}},[e,t])}var G=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,K=G||/Android/.test(navigator.userAgent);function q(){let[e,t]=(0,L.useState)(()=>window.wizardInstall??null),[n,r]=(0,L.useState)(!1);if((0,L.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||K&&!e&&!G)return null;let i=/Mac/.test(navigator.platform),a=f(K?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,H.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>{K&&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:[K?(0,H.jsx)(I,{className:`size-4`}):(0,H.jsx)(ne,{className:`size-4`}),f(K?`install.add`:`install.bookmark`)]}),n?(0,H.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function J({brand:e,toggle:t=!0}){return(0,H.jsx)(`header`,{className:`safe-top`,children:(0,H.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,H.jsx)(`img`,{src:r(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,H.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,H.jsx)(`div`,{className:`absolute right-3`,children:(0,H.jsx)(A,{})}):null]})})}function Y({siteKey:e,onToken:t}){let n=(0,L.useRef)(null);return(0,L.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,H.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function ae({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||O||z?null:(0,H.jsxs)(`a`,{href:T(`${window.location.origin}${i}/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,H.jsx)(P,{className:`size-4`}),` `,f(`install.app`)]})}var X=e=>`wz.run.${e}`,Z=O&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=z===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t){let n=p(),[r,i]=(0,L.useState)(!1),[a,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),u=(()=>{try{return localStorage.getItem(X(e.token))}catch{return null}})();return{busy:r,error:a,captcha:c,setCaptcha:l,start:async()=>{i(!0),s(null);try{let{runId:r}=await o.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(X(e.token),r)}catch{}n(`${t}/${r}`,{replace:Z})}catch(e){s(e.message),i(!1)}},resume:u?()=>n(`${t}/${u}`):null}}function oe({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:i,start:a,resume:o}=$(e,`/w/${e.token}`),c=Z&&e.available&&!e.turnstileSiteKey,l=(0,L.useRef)(!1);return(0,L.useEffect)(()=>{c&&!l.current&&(l.current=!0,a())},[c]),c&&!n?(0,H.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,H.jsx)(_,{})}):(0,H.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,H.jsx)(D,{kind:e.avatar,size:190,fluffy:!0}),(0,H.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,H.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(s,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:a,children:[f(`run.start`),` `,(0,H.jsx)(g,{className:`size-4`})]}),e.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:e.turnstileSiteKey,onToken:i}):null,o?(0,H.jsx)(`button`,{type:`button`,onClick:o,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.resume`)}):null,(0,H.jsx)(se,{wizard:e,current:`steps`}),z||O?null:(0,H.jsx)(q,{}),(0,H.jsx)(ae,{token:e.token})]}):(0,H.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??f(`run.unavailable`)}),n?(0,H.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function se({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,H.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,H.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.orAs`,{label:e.label})},e.id))}):null}function ce({wizard:e}){let t=C();return(0,H.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,H.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,H.jsx)(`span`,{className:m(t?.speaking&&`animate-breathe`),children:(0,H.jsx)(D,{kind:e.avatar,size:38})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,H.jsx)(`img`,{src:r(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,H.jsx)(A,{}),z===`popout`?(0,H.jsx)(l,{label:f(`common.close`),onClick:ie,children:(0,H.jsx)(h,{className:`size-5`})}):null]})})}function le({door:e,wizard:t,header:n,footer:r}){let{busy:i,error:a,captcha:o,setCaptcha:s,start:c,resume:l}=$(t,`/w/${t.token}/${e}`),u=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&u.push({key:e,who:`bot`,node:f(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||u.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??f(`run.unavailable`)}),a&&u.push({key:`error`,who:`bot`,node:a,tone:`error`}),t.available&&u.push(x(`start`,(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(y,{primary:!0,busy:i,disabled:!!t.turnstileSiteKey&&!o,onClick:()=>void c(),children:[f(`run.start`),` `,(0,H.jsx)(g,{className:`size-4`})]}),l?(0,H.jsx)(y,{onClick:l,children:f(`run.resume`)}):null,t.turnstileSiteKey?(0,H.jsx)(Y,{siteKey:t.turnstileSiteKey,onToken:s}):null]}))),(0,H.jsxs)(b,{header:n,footer:r,children:[(0,H.jsx)(v,{avatar:t.avatar,lines:u}),(0,H.jsx)(S,{})]})}function ue({className:e}){return(0,H.jsx)(`footer`,{className:m(`text-center text-ink-4`,e),children:(0,H.jsx)(`a`,{href:`${i}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,E.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:r=!1}){let{token:c,runId:l}=u(),h=p(),g=d({queryKey:[`public`,c],queryFn:()=>o.get(`/api/public/wizards/${c}`),retry:(e,t)=>a(t)&&e<3}),v=g.data?.runners??[],y=!g.data||v.some(e=>e.id===`talk`),b=!g.data||v.some(e=>e.id===`video`),x=!g.data||v.some(e=>e.id===`chat`)||n&&y||r&&b,S=v[0]?.id,C=e||z===`popout`||!t&&!l&&x&&(S===`chat`||S===`talk`||S===`video`),T=r&&b||!t&&!e&&!n&&S===`video`,A=!T&&(n&&y||!t&&!e&&S===`talk`),M=T?`video`:A?`talk`:`chat`;if(U(g.data?.brand.accent),te(g.data?.avatar),W(c,g.data?.title),V(C),(0,L.useEffect)(()=>{g.data&&(document.title=g.data.title)},[g.data]),(0,L.useEffect)(()=>{c&&l&&k(`run`,{token:c,runId:l})},[c,l]),g.isLoading)return(0,H.jsx)(`div`,{className:m(`flex items-center justify-center text-ink-4`,Q),children:(0,H.jsx)(_,{})});if(e&&g.data&&!x||n&&g.data&&!y||r&&g.data&&!b)return(0,H.jsx)(ee,{to:`/w/${c}`,replace:!0});if(!g.data){let e=a(g.error);return(0,H.jsxs)(`div`,{className:m(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,H.jsx)(D,{kind:`pebble`,size:80}),(0,H.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:f(e?`common.offline`:`run.notFound`)}),e?(0,H.jsx)(s,{variant:`secondary`,onClick:()=>void g.refetch(),children:f(`common.retry`)}):null]})}if(C){let e=(0,H.jsx)(ce,{wizard:g.data}),t=O?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,H.jsx)(`div`,{className:`flex h-dvh flex-col`,children:l?(0,H.jsx)(w,{runId:l,talk:A,call:T?`video`:A?`audio`:!1,onRestart:()=>h(`/w/${c}/${M}`),header:T||A?void 0:e,footer:t}):(0,H.jsx)(le,{wizard:g.data,header:e,footer:t,door:M})})}return(0,H.jsxs)(`div`,{className:m(`flex flex-col`,Q),children:[z===`inline`||O?null:(0,H.jsx)(J,{brand:g.data.brand,toggle:!z}),(0,H.jsx)(`div`,{className:`flex-1`,children:l?(0,H.jsx)(j,{runId:l,onRestart:()=>h(`/w/${c}`)}):(0,H.jsx)(oe,{wizard:g.data})}),O?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,H.jsx)(`a`,{href:`${i}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,E.name)})})]})}export{J as BrandHeader,de as PublicRunner,U as useBrandAccent};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{Wn as n,an as r}from"./ui-DTuixH4y.js";import{t as i}from"./lock-DlzTfwxP.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return r(e.origin===`local`?`readonly.project`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{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,s.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{Xn as n,dn as r}from"./ui-DrdqFaQt.js";import{t as i}from"./lock-CkXYnQux.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return r(e.origin===`local`?`readonly.project`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{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,s.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};
@@ -0,0 +1,4 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,An as i,B as a,C as o,Cn as s,Dn as c,Fn as l,Gt as u,Ht as d,Jt as f,Kt as p,Nr as m,S as h,Un as g,V as _,Vn as v,W as y,Wn as b,Wt as x,Xn as S,Xt as C,Yt as w,Zt as T,an as E,cn as D,cr as O,dn as k,en as A,hn as j,on as M,ot as N,pn as P,qt as F,rn as I,tn as L,v as ee,xn as te,z as R}from"./ui-DrdqFaQt.js";import{t as ne}from"./upload-CzkkZqAo.js";import{St as re,Yt as z,xt as ie}from"./index-BRDn-5v_.js";var ae={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`}]]};ae.node;var oe=S(ae),se={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`}]]};se.node;var ce=S(se),le={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`}]]};le.node;var ue=S(le),de={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`}]]};de.node;var fe=S(de),B={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`}]]};B.node;var V=S(B),pe={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`}]]};pe.node;var me=S(pe),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=S(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=S(_e),U=e(t(),1),W=e(n(),1),G={choice:ge,date:oe,number:ue,text:ie,boolean:H},K=e=>[`knowledge`,e];function ve(e){return e===1?k(`know.item`):k(`know.items`,{n:e})}function q(e,t){if(e.type===`boolean`||typeof t==`boolean`)return k(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(D,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(D)}${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[i,a]=(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)(r,{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(),i.trim()&&n(e.multiple?[...o,i.trim()]:[i.trim()])},children:[(0,W.jsx)(C,{"data-autofocus":!0,value:o.includes(i)?``:i,placeholder:k(`know.addValue`),onChange:e=>a(e.target.value),className:`h-9`}),(0,W.jsx)(w,{label:k(`know.addValue`),type:`submit`,children:(0,W.jsx)(s,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,W.jsx)(r,{value:t[0]===!0?k(`know.yes`):t[0]===!1?k(`know.no`):``,options:[k(`know.yes`),k(`know.no`)],onChange:e=>n([e===k(`know.yes`)])}):(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(i.trim()?[e.type===`number`?Number(i.replace(`,`,`.`)):i.trim()]:[])},children:[(0,W.jsx)(C,{"data-autofocus":!0,type:e.type===`date`?`date`:e.type===`number`?`number`:`text`,step:`any`,value:e.type===`date`?i.slice(0,10):i,onChange:e=>a(e.target.value),className:`h-9`}),(0,W.jsx)(x,{type:`submit`,size:`sm`,children:`OK`})]})}function Se({projectId:e,itemKey:t,has:n,categories:r,readOnly:i}){let a=m(),[o,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(n);(0,U.useEffect)(()=>u(n),[n]);let d=z({mutationFn:({categoryId:n,next:r})=>y.put(`/api/studio/projects/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>a.invalidateQueries({queryKey:K(e)})}),f=r.filter(e=>!(e.proposed||e.tableId)),p=(e,t)=>{u(n=>[...n.filter(t=>t.categoryId!==e.id),...t.length?[{categoryId:e.id,values:t,by:`person`}]:[]]),d.mutate({categoryId:e.id,next:t}),c(null)},h=f.filter(e=>l.some(t=>t.categoryId===e.id)),g=f.filter(e=>!l.some(t=>t.categoryId===e.id));return f.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[h.map(e=>{let t=l.find(t=>t.categoryId===e.id),n=G[e.type],r=(0,W.jsxs)(`button`,{type:`button`,disabled:i,title:`${e.name} · ${k(`know.by.${t.by}`)}`,onClick:()=>c(o===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 i?(0,W.jsx)(`span`,{children:r},e.id):(0,W.jsxs)(be,{trigger:r,open:o===e.id,onOpen:t=>c(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)(w,{label:k(`know.remove`),onClick:()=>p(e,[]),className:`size-7`,children:(0,W.jsx)(P,{className:`size-3.5`})})]}),(0,W.jsx)(xe,{category:e,current:t.values,onSave:t=>p(e,t)})]},e.id)}),i||!g.length?null:(0,W.jsx)(be,{open:o===`+`,onOpen:e=>c(e?`+`:null),trigger:(0,W.jsxs)(`button`,{type:`button`,onClick:()=>c(o===`+`?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)(s,{className:`size-3.5`}),` `,k(`know.category`)]}),children:(0,W.jsx)(Ce,{categories:g,onSave:p})})]}):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)(A,{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:r}){let i=m(),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(`choice`),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(!1),[p,h]=(0,U.useState)(!1),[g,_]=(0,U.useState)(``),[v,b]=(0,U.useState)(``),S=z({mutationFn:()=>y.post(`/api/studio/projects/${e}/categories`,{name:a.trim(),type:s,unit:s===`number`&&l.trim()||null,multiple:s===`choice`&&d,ordered:s===`choice`&&p,hint:v.trim()||null,values:s===`choice`?g.split(`
2
+ `).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await i.invalidateQueries({queryKey:K(e)}),o(``),_(``),b(``),r(t)}});return(0,W.jsx)(F,{open:t,onClose:n,title:k(`know.newCategory`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.trim()&&S.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`know.name`)}),(0,W.jsx)(C,{"data-autofocus":!0,value:a,maxLength:80,onChange:e=>o(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`know.type`)}),(0,W.jsx)(A,{value:s,onChange:e=>c(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:k(`know.type.${e}`)}))})]}),s===`number`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{hint:k(`know.unitHint`),children:k(`know.unit`)}),(0,W.jsx)(C,{value:l,maxLength:20,onChange:e=>u(e.target.value)})]}):null,s===`choice`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{hint:k(`know.valuesHint`),children:k(`know.values`)}),(0,W.jsx)(E,{minRows:3,value:g,onChange:e=>_(e.target.value)})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[k(`know.multiple`),(0,W.jsx)(I,{checked:d,onChange:f})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[k(`know.ordered`),(0,W.jsx)(I,{checked:p,onChange:h})]})]}):null,(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{hint:k(`know.hintFieldHint`),children:k(`know.hintField`)}),(0,W.jsx)(C,{value:v,maxLength:120,onChange:e=>b(e.target.value)})]}),S.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:S.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(x,{variant:`ghost`,onClick:n,children:k(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:S.isPending,disabled:!a.trim(),children:k(`know.create`)})]})]})})}function Te({projectId:e,category:t,readOnly:n,onOpen:r,onGone:i}){let a=m(),c=()=>a.invalidateQueries({queryKey:K(e)}),[l,d]=(0,U.useState)(``),h=z({mutationFn:e=>e(),onSuccess:c}),g=G[t.type],_=new Map(t.values.map(e=>[e.id,e]));return(0,W.jsxs)(o,{title:t.name,hint:[k(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,W.jsx)(w,{label:k(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(k(`know.confirmCategory`,{name:t.name}))&&h.mutate(async()=>{await y.del(`/api/studio/categories/${t.id}`),i()}),children:(0,W.jsx)(j,{className:`size-4`})}),children:[t.proposed&&!n?(0,W.jsxs)(u,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(p,{tone:`ember`,children:k(`know.proposed`)}),(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:k(`know.proposedHint`)}),(0,W.jsx)(x,{size:`sm`,onClick:()=>h.mutate(()=>y.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:k(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=_.get(e),i=_.get(t);if(!(r&&i))return null;let[a,o]=r.count<i.count?[r,i]:[i,r];return(0,W.jsxs)(u,{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:k(`know.alike`,{a:a.value,b:o.value})}),n?null:(0,W.jsx)(x,{size:`sm`,variant:`secondary`,busy:h.isPending,onClick:()=>h.mutate(()=>y.post(`/api/studio/values/${a.id}/merge`,{into:o.id})),children:k(`know.merge`)})]},`${e}:${t}`)}),(0,W.jsxs)(u,{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:()=>r(`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)(g,{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)(p,{children:k(`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)(f,{children:k(`know.empty`)}):(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,W.jsx)(g,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?k(`know.range`,{min:q(t,t.range.min),max:q(t,t.range.max)}):k(`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&&(d(``),h.mutate(()=>y.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,W.jsx)(C,{value:l,placeholder:k(`know.addValue`),onChange:e=>d(e.target.value),className:`h-9`}),(0,W.jsx)(w,{label:k(`know.addValue`),type:`submit`,children:(0,W.jsx)(s,{className:`size-4`})})]}):null]}),h.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:h.error.message}):null]})}function Ee(e){return O({queryKey:[`knowledge-value`,e],queryFn:()=>y.get(`/api/studio/values/${e}`),enabled:!!e})}function De({value:e,readOnly:t,children:n}){let r=m(),i=z({mutationFn:()=>y.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>r.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,W.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,W.jsx)(o,{title:k(`know.summary`),hint:k(`know.summaryHint`),plain:!0,action:t?null:(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,busy:i.isPending,onClick:()=>i.mutate(),children:[e.summary?(0,W.jsx)(te,{className:`size-4`}):null,e.summary?k(`know.summaryAgain`):k(`know.summaryWrite`)]}),children:(0,W.jsxs)(u,{className:`p-4 sm:p-5`,children:[i.isPending?(0,W.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,W.jsx)(L,{})}):e.summary?(0,W.jsx)(N,{text:e.summary,className:`text-[0.875rem]`}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:k(`know.summaryEmpty`)}),i.error?(0,W.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:i.error.message}):null]})}),(0,W.jsx)(o,{title:k(`know.toc`),plain:!0,children:n})]})}function Oe(e){return O({queryKey:[`knowledge`,e],queryFn:()=>y.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`?V:re:e.kind===`file`?c:e.children?ce:l}function J({item:e,categories:t,onOpen:n}){let r=ke(e),i=[ye(t,e.categories),e.children?e.children===1?k(`know.oneSub`):k(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?k(`know.row`):k(`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)(L,{className:`size-3`}),` `,k(`know.reading`)]}):e.review?(0,W.jsx)(p,{tone:`warn`,title:e.review,children:k(`know.review`)}):null]})}function Y({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:a,file:o,readOnly:s,onReviewed:l}){let u=Oe(e),d=[r?k(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[u.data?(0,W.jsx)(Se,{projectId:e,itemKey:t,has:n,categories:u.data.categories,readOnly:s}):null,d.length||o||a?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.8125rem] text-ink-3`,children:[d.map(e=>(0,W.jsx)(`span`,{children:e},e)),o?(0,W.jsxs)(`a`,{href:R(e,o.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,W.jsx)(c,{className:`size-3.5`}),` `,k(`know.original`),`: `,o.name]}):null,a?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(p,{tone:`warn`,children:k(`know.review`)}),(0,W.jsx)(`span`,{children:a}),s?null:(0,W.jsx)(`button`,{type:`button`,onClick:l,className:`underline hover:text-ink`,children:k(`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 i=O({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>y.get(`/api/studio/categories/${t.id}/items`)});if(!i.data)return i.isLoading?(0,W.jsx)(L,{className:`mx-auto size-4 text-ink-3`}):null;let a=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],o=[...i.data.items].sort((e,t)=>{let n=a(e),r=a(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),D)}),s=t.type===`number`?Ae(o.map(a).filter(e=>typeof e==`number`)):[],c=new Intl.NumberFormat(D,{notation:`compact`,maximumFractionDigits:1}),l=t.unit?` ${t.unit}`:``,d=new Map;for(let e of o){let n=a(e),r=typeof n==`number`?s.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(D,{month:`long`,year:`numeric`}):r?k(`know.range`,{min:`${c.format(r.lo)}${l}`,max:`${c.format(r.hi)}${l}`}):q(t,n);d.set(i,[...d.get(i)??[],e])}return(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...d].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)(u,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,W.jsx)(J,{item:e,categories:n,onOpen:r},e.key))})]},e)),i.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:k(`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 k(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${k(`know.contains`)} ${t.contains}`:[n===void 0?``:`${k(`know.minimum`)} ${q(e,n)}`,r===void 0?``:`${k(`know.maximum`)} ${q(e,r)}`].filter(Boolean).join(` `)}return String(t)}function Pe({category:e,value:t,onChange:n}){let[i,a]=(0,U.useState)(!1),o=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!i)return;let e=e=>!o.current?.contains(e.target)&&a(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]);let s=G[e.type],c=typeof t==`object`&&t&&!Array.isArray(t)?t:{},l=(t,r)=>{let i={...c,[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:()=>a(!i),className:M(`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)(g,{className:`size-3.5 text-ink-3`})]}),i?(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)(r,{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)(r,{value:t===!0?k(`know.yes`):t===!1?k(`know.no`):``,options:[k(`know.yes`),k(`know.no`)],onChange:e=>n(e===k(`know.yes`))}):e.type===`text`?(0,W.jsx)(C,{"data-autofocus":!0,value:c.contains??``,placeholder:k(`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)(T,{children:k(n===0?`know.minimum`:`know.maximum`)}),(0,W.jsx)(C,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(c[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>l(t,e.target.value),className:`h-9`})]},t))}),t===void 0?null:(0,W.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),a(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:k(`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?k(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):k(`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(D,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,W.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:k(`know.searchNone`)})}function Ie({kind:e,projectId:t,onClose:n,onMade:r}){let i=m(),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(!1),l=z({mutationFn:()=>y.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:a.trim(),...e===`table`&&s?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await i.invalidateQueries({queryKey:[`knowledge`,t]}),r(`${e===`table`?`t`:`p`}:${n}`),o(``),c(!1)}});return(0,W.jsx)(F,{open:e!==null,onClose:n,title:k(e===`table`?`know.newTable`:`know.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.trim()&&l.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`data.title`)}),(0,W.jsx)(C,{"data-autofocus":!0,value:a,maxLength:120,onChange:e=>o(e.target.value)})]}),e===`table`?(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[k(`know.asFaq`),(0,W.jsx)(I,{checked:s,onChange:c})]}):null,l.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(x,{variant:`ghost`,onClick:n,children:k(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:l.isPending,disabled:!a.trim(),children:k(`know.create`)})]})]})})}function Le({projectId:e,data:t,readOnly:n,onOpen:r}){let i=m(),a=_(e,n),[c,l]=(0,U.useState)({}),[d,g]=(0,U.useState)(``),[v,b]=(0,U.useState)(null),[S,C]=(0,U.useState)(!1),[w,T]=(0,U.useState)(null),E=t.categories.filter(e=>!e.proposed&&e.count>0),D=t.categories.filter(e=>e.proposed),O=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})),A=async()=>{if(!d.trim()){b(null);return}C(!0);try{b(await y.post(`/api/studio/projects/${e}/search`,{query:d,...Object.keys(c).length?{where:c}:{}}))}catch{b({hits:[],candidates:0,checked:!1,filtered:null})}finally{C(!1)}},j=z({mutationFn:({id:e,keep:t})=>t?y.patch(`/api/studio/categories/${e}`,{proposed:!1}):y.del(`/api/studio/categories/${e}`),onSuccess:()=>i.invalidateQueries({queryKey:[`knowledge`,e]})});return(0,W.jsxs)(o,{title:k(`know.title`),hint:k(`know.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>T(`page`),children:[(0,W.jsx)(s,{className:`size-4`}),` `,k(`know.page`)]}),(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>T(`table`),children:[(0,W.jsx)(s,{className:`size-4`}),` `,k(`know.table`)]}),(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>T(`category`),children:[(0,W.jsx)(s,{className:`size-4`}),` `,k(`know.category`)]})]}),children:[D.length&&!n?(0,W.jsx)(u,{className:`flex flex-col gap-2 p-4`,children:D.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)(p,{tone:`ember`,children:k(`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:[k(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,W.jsx)(x,{size:`sm`,variant:`ghost`,onClick:()=>j.mutate({id:e.id,keep:!1}),children:k(`know.dismiss`)}),(0,W.jsx)(x,{size:`sm`,onClick:()=>j.mutate({id:e.id,keep:!0}),children:k(`know.accept`)})]},e.id)})}):null,t.items.length?(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsx)(h,{value:d,placeholder:k(`know.search`),busy:S,onEnter:()=>void A(),onChange:e=>{g(e),e.trim()||b(null)}}),E.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[E.map(e=>(0,W.jsx)(Pe,{category:e,value:c[e.name],onChange:t=>{b(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:k(`know.clear`)}):null]}):null]}):null,(0,W.jsx)(u,{className:`flex flex-col p-1.5`,children:v?(0,W.jsx)(Fe,{found:v,onOpen:r}):O.length?O.map(e=>(0,W.jsx)(J,{item:e,categories:t.categories,onOpen:r},e.key)):(0,W.jsx)(f,{children:k(`know.empty`)})}),n?null:(0,W.jsxs)(ee,{accept:`.pdf,.docx,.doc,.xlsx,.csv,.tsv,.txt,.md,.json,.html,.eml,image/*`,onFiles:async t=>{await a.upload(`document`,t),await i.invalidateQueries({queryKey:[`knowledge`,e]})},className:`h-14 w-full`,children:[a.busy?(0,W.jsx)(L,{className:`size-4`}):(0,W.jsx)(ne,{className:`size-4`}),k(`know.drop`),` `,(0,W.jsx)(`span`,{className:`underline`,children:k(`know.pick`)})]}),a.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:a.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?``:k(`know.keywordsOnly`),t.checked?``:k(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,W.jsx)(Ie,{kind:w===`page`||w===`table`?w:null,projectId:e,onClose:()=>T(null),onMade:e=>{T(null),r(e)}}),(0,W.jsx)(we,{projectId:e,open:w===`category`,onClose:()=>T(null),onMade:e=>{T(null),r(`c:${e}`)}})]})}function Re({page:e,onGone:t,onOpen:n}){let r=m(),[i,o]=(0,U.useState)(e.title),[c,d]=(0,U.useState)(e.markdown),[f,p]=(0,U.useState)(e.markdown?`read`:`write`),h=e.knowledge,g=async()=>{await r.invalidateQueries({queryKey:[`space-data`,e.projectId]}),await r.invalidateQueries({queryKey:[`knowledge`,e.projectId]})},_=a({title:i.trim()||e.title,markdown:c},async t=>{await y.patch(`/api/studio/pages/${e.id}`,t),r.setQueryData([`space-page`,e.id],e=>e&&{...e,...t}),t.title!==e.title&&await g()}),S=z({mutationFn:()=>y.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await g(),t()}}),C=z({mutationFn:()=>y.post(`/api/studio/projects/${e.projectId}/pages`,{title:k(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await g(),n?.(`p:${e}`)}}),T=z({mutationFn:()=>y.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>r.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 y.get(`/api/studio/projects/${e.projectId}/resolve?path=${encodeURIComponent(r)}`).catch(()=>null);i?.kind===`page`&&n(`p:${i.id}`)},D=e.readOnly,O=h?.file&&(h.file.mime===`application/pdf`||h.file.mime.startsWith(`image/`))?h.file:null,A=(e,t)=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>p(e),className:M(`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:[h?.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:h.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)(v,{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:i,disabled:D,maxLength:200,onChange:e=>o(e.target.value),"aria-label":k(`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`}),_.state===`saving`?(0,W.jsx)(L,{className:`size-3.5 text-ink-3`}):_.state===`saved`?(0,W.jsx)(b,{className:`size-4 text-moss`,"aria-label":k(`settings.saved`)}):null,D?null:(0,W.jsx)(w,{label:k(`data.deletePage`),onClick:()=>confirm(k(`data.confirmDelete`,{title:e.title}))&&S.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(j,{className:`size-4`})})]}),h?(0,W.jsx)(Y,{projectId:e.projectId,itemKey:`p:${e.id}`,has:h.categories,originLabel:h.originLabel,kept:h.kept,review:h.review,file:O?null:h.file,readOnly:D,onReviewed:()=>T.mutate()}):null,(0,W.jsxs)(u,{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:A(`write`,k(`data.write`)),A(`read`,k(`data.preview`)),O?A(`original`,k(`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:k(`data.markdownHint`)})]}),f===`original`&&O?O.mime===`application/pdf`?(0,W.jsx)(`iframe`,{src:R(e.projectId,O.id),title:O.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,W.jsx)(`img`,{src:R(e.projectId,O.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):f===`write`&&!D?(0,W.jsx)(`textarea`,{value:c,onChange:e=>d(e.target.value),"aria-label":e.title,placeholder:k(`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:c.trim()?(0,W.jsx)(N,{text:c}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:k(`data.pageEmpty`)})})]}),_.state===`error`&&_.error?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:_.error}):null,h&&n&&(h.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:h.children.length?k(`know.subPages`):null}),D?null:(0,W.jsxs)(x,{variant:`ghost`,size:`sm`,busy:C.isPending,onClick:()=>C.mutate(),children:[(0,W.jsx)(s,{className:`size-4`}),` `,k(`know.addSub`)]})]}),h.children.length?(0,W.jsx)(u,{className:`flex flex-col p-1.5`,children:h.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)(l,{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=O({queryKey:[`space-page`,e],queryFn:()=>y.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 O({queryKey:[`space-data`,e],queryFn:()=>y.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:k(`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:re,page:l};function Ue({kind:e,projectId:t,data:n,onClose:r,onMade:i}){let a=m(),[o,s]=(0,U.useState)(``),[c,l]=(0,U.useState)(``),u=z({mutationFn:()=>y.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:o.trim(),wizardId:c||null}),onSuccess:async({id:n})=>{await a.invalidateQueries({queryKey:[`space-data`,t]}),i(`${e===`table`?`t`:`p`}:${n}`),s(``),l(``)}});return(0,W.jsx)(F,{open:e!==null,onClose:r,title:k(e===`table`?`data.newTable`:`data.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&u.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`data.title`)}),(0,W.jsx)(C,{"data-autofocus":!0,value:o,maxLength:120,onChange:e=>s(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`data.owner`)}),(0,W.jsx)(A,{value:c,onChange:l,options:[{value:``,label:k(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),u.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(x,{variant:`ghost`,onClick:r,children:k(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:u.isPending,disabled:!o.trim(),children:k(`data.create`)})]})]})})}function We({projectId:e,data:t,readOnly:n,onOpen:r}){let[i,a]=(0,U.useState)(null),c=Ve(t),l=new Map([...t.tables.map(e=>[`t:${e.id}`,e.updatedAt]),...t.pages.map(e=>[`p:${e.id}`,e.updatedAt])]),d=new Intl.DateTimeFormat(D,{dateStyle:`medium`});return(0,W.jsxs)(o,{title:k(`space.data`),hint:k(`data.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>a(`table`),children:[(0,W.jsx)(s,{className:`size-4`}),` `,k(`data.table`)]}),(0,W.jsxs)(x,{variant:`secondary`,size:`sm`,onClick:()=>a(`page`),children:[(0,W.jsx)(s,{className:`size-4`}),` `,k(`data.page`)]})]}),children:[c.length?(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:c.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)(u,{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`?`${k(`data.rows`,{n:e.rows??0})} · `:``,d.format(new Date(l.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,W.jsx)(u,{children:(0,W.jsx)(f,{children:k(`data.empty`)})}),(0,W.jsx)(Ue,{kind:i,projectId:e,data:t,onClose:()=>a(null),onMade:e=>{a(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 a=Je(e,t),[o,s]=(0,U.useState)(a);(0,U.useEffect)(()=>s(a),[a]);let c=(t=o)=>{t!==a&&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:[],a=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:[a(e),n?null:(0,W.jsx)(`button`,{type:`button`,"aria-label":k(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,W.jsx)(P,{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:o,rows:1,disabled:n,onChange:e=>s(e.target.value),onBlur:()=>c(),"aria-label":e.name,className:M(X,`field-sizing-content max-h-40 resize-none`)});let l=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,W.jsx)(`input`,{type:l,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:o,disabled:n,onChange:t=>{s(t.target.value),e.type===`date`&&c(t.target.value)},onBlur:()=>e.type!==`date`&&c(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&s(a)},"aria-label":e.name,className:M(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`?k(`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[a,o]=(0,U.useState)(()=>Qe(t)),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(!1);(0,U.useEffect)(()=>{e&&(o(Qe(t)),c(null))},[e,t]);let d=e=>o(t=>({...t,...e})),f=async e=>{u(!0),c(null);try{await i(e),r()}catch(e){c(e.message)}finally{u(!1)}},p=()=>{let e=t?.id??Ge(a.name,n.map(e=>e.id)),r=$e(a,e,t);return f(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,W.jsx)(F,{open:e,onClose:r,title:t?t.name:k(`data.newColumn`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.name.trim()&&p()},children:[(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`data.columnName`)}),(0,W.jsx)(C,{"data-autofocus":!0,value:a.name,maxLength:128,onChange:e=>d({name:e.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`data.columnType`)}),(0,W.jsx)(A,{value:a.type,onChange:e=>d({type:e}),options:qe.map(e=>({value:e,label:k(`data.type.${e}`)}))})]})]}),a.type===`text`?(0,W.jsx)(A,{value:a.textStyle,onChange:e=>d({textStyle:e}),options:[{value:`single`,label:k(`data.text.single`)},{value:`multiline`,label:k(`data.text.multiline`)}]}):null,a.type===`number`?(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)(A,{value:a.numberStyle,onChange:e=>d({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:k(`data.number.${e}`)}))}),a.numberStyle===`currency`?(0,W.jsx)(C,{value:a.currency,maxLength:3,"aria-label":k(`data.currency`),placeholder:`EUR`,onChange:e=>d({currency:e.target.value})}):null]}):null,a.type===`date`?(0,W.jsx)(A,{value:a.dateKind,onChange:e=>d({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:k(`data.date.${e}`)}))}):null,a.type===`duration`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`data.unit`)}),(0,W.jsx)(A,{value:a.unit,onChange:e=>d({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:k(`data.unit.${e}`)}))})]}):null,a.type===`select`?(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(T,{children:k(`data.options`)}),(0,W.jsx)(E,{minRows:3,value:a.options,onChange:e=>d({options:e.target.value})})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(I,{checked:a.multiple,onChange:e=>d({multiple:e})}),k(`data.multiple`)]})]}):null,(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(I,{checked:a.required,onChange:e=>d({required:e})}),k(`data.required`)]}),s?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,W.jsx)(x,{variant:`ghost`,className:`text-rose`,disabled:l,onClick:()=>confirm(k(`data.confirmDelete`,{title:t.name}))&&void f(n.filter(e=>e.id!==t.id)),children:k(`data.deleteColumn`)}):null,(0,W.jsx)(`span`,{className:`flex-1`}),(0,W.jsx)(x,{variant:`ghost`,onClick:r,children:k(`common.cancel`)}),(0,W.jsx)(x,{type:`submit`,busy:l,disabled:!a.name.trim(),children:k(`settings.save`)})]})]})})}function tt({tableId:e,onGone:t}){let n=m(),r=[`space-table`,e],i=O({queryKey:r,queryFn:()=>y.get(`/api/studio/tables/${e}`)}),[a,o]=(0,U.useState)(null),[c,l]=(0,U.useState)(null),[f,p]=(0,U.useState)(null),[h,g]=(0,U.useState)(``);(0,U.useEffect)(()=>g(i.data?.title??``),[i.data?.title]);let _=async()=>{await n.invalidateQueries({queryKey:[`space-data`,i.data?.projectId]}),await n.invalidateQueries({queryKey:[`knowledge`,i.data?.projectId]})},v=e=>n.setQueryData(r,t=>t&&{...t,rows:e(t.rows)}),b=e=>{l(e.message),i.refetch()},S=async t=>{await y.patch(`/api/studio/tables/${e}`,t),await i.refetch(),await _()},C=z({mutationFn:({row:t,column:n,value:r})=>y.patch(`/api/studio/tables/${e}/rows/${t}`,{cells:{[n]:r}}),onSuccess:(e,{row:t,column:n})=>{l(null),p(e=>e===`${t}:${n}`?null:e),v(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof d&&e.body?.column===n){let e=i.data?.columns.find(e=>e.id===n)?.name??n;p(`${t}:${n}`),l(k(`data.badCell`,{column:e}));return}b(e)}}),T=z({mutationFn:()=>y.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{v(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await _()},onError:b}),E=z({mutationFn:t=>y.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{v(e=>e.filter(e=>e.id!==t)),await _()},onError:b}),D=z({mutationFn:()=>y.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await _(),t()}});if(!i.data)return i.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:i.error.message}):null;let{columns:A,rows:M,readOnly:N}=i.data,P=!!i.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=>g(e.target.value),onBlur:()=>h.trim()&&h!==i.data?.title&&void S({title:h}).catch(b),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":k(`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)(w,{label:k(`data.deleteTable`),onClick:()=>confirm(k(`data.confirmDelete`,{title:i.data.title}))&&D.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(j,{className:`size-4`})})]}),P?(0,W.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:k(`data.fromList`)}):null,i.data.knowledge?(0,W.jsx)(Y,{projectId:i.data.projectId,itemKey:`t:${i.data.id}`,has:i.data.knowledge.categories,originLabel:i.data.knowledge.originLabel,kept:i.data.knowledge.kept,review:i.data.knowledge.review,file:i.data.knowledge.file,readOnly:N,onReviewed:()=>void y.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>i.refetch()).catch(b)}):null,(0,W.jsxs)(u,{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:[A.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:()=>o(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)(w,{label:k(`data.newColumn`),onClick:()=>o(`new`),className:`size-8`,children:(0,W.jsx)(s,{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:[A.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=>C.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)(w,{label:k(`data.deleteRow`),onClick:()=>E.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)(j,{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:k(`data.noRows`)}),N?null:(0,W.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,W.jsxs)(x,{variant:`ghost`,size:`sm`,busy:T.isPending,onClick:()=>T.mutate(),children:[(0,W.jsx)(s,{className:`size-4`}),` `,k(`data.addRow`)]})})]}),c?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:c}):null,(0,W.jsx)(et,{open:a!==null,column:a===`new`?null:a,columns:A,onClose:()=>o(null),onSave:e=>S({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:k(`chat.steps`),Icon:fe},{id:`chat`,label:k(`chat.chat`),Icon:V}];return(0,W.jsx)(`fieldset`,{"aria-label":k(`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:M(`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 a=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:M(`relative flex h-full w-full animate-rise flex-col bg-background shadow-overlay`,!a.wide&&`sm:w-[var(--drawer)]`),style:{"--drawer":`${a.width}px`},onClick:e=>e.stopPropagation(),children:[a.wide?null:(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":k(`editor.resize`),"aria-valuenow":a.width,tabIndex:0,title:k(`editor.resize`),onPointerDown:a.onPointerDown,onKeyDown:a.onKeyDown,onDoubleClick:a.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)(w,{label:k(a.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:a.toggleWide,className:`max-sm:hidden`,children:a.wide?(0,W.jsx)(me,{className:`size-4`}):(0,W.jsx)(i,{className:`size-4`})}),(0,W.jsx)(w,{label:k(`editor.close`),onClick:n,children:(0,W.jsx)(P,{className:`size-5`})})]})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}export{De as _,He as a,ue 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,oe as x,H as y};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,Ht as i,W as a,et as o}from"./ui-DrdqFaQt.js";import{i as s,r as c}from"./index-BRDn-5v_.js";var l=e(t(),1),u=e(n(),1),d=[`classifier`,`standard`],f=12e3;function p(e){s(`think`)&&a.post(`/api/runs/${e}/device`,{think:{classes:d,maxChars:f}}).catch(()=>void 0)}async function m(e,t){if(t.kind!==`think`)return;let n;try{let e=await c(`think`,{system:t.system,prompt:t.prompt,schema:t.schema});n={text:String(e?.text??``)}}catch(e){n={error:e.message.slice(0,500)}}await a.post(`/api/runs/${e}/device/${t.id}`,n).catch(()=>void 0)}var h=45e3;function g(e){let[t,n]=(0,l.useState)(null),[o,s]=(0,l.useState)(null),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(!1),[g,_]=(0,l.useState)({});(0,l.useEffect)(()=>{if(n(null),u(!1),!e)return;let t=!1,o=0,s,c=null,l=Date.now(),d=()=>{t=!0,c?.close(),u(!0)},f=async()=>{try{let r=await a.get(`/api/runs/${e}`);t||n(r)}catch(e){e instanceof i&&e.status===404&&d()}},g=()=>{if(clearTimeout(s),c?.close(),t)return;let i=new EventSource(r(`/api/runs/${e}/stream`),{withCredentials:!0});c=i,l=Date.now(),p(e),i.addEventListener(`device`,t=>{l=Date.now(),m(e,JSON.parse(t.data))}),i.addEventListener(`view`,e=>{o=0,l=Date.now(),n(JSON.parse(e.data))}),i.addEventListener(`ping`,()=>{l=Date.now()}),i.onerror=()=>{i.close(),!(t||c!==i)&&(c=null,f(),o=Math.min(o+1,6),s=setTimeout(g,500*2**o))}},_=()=>{t||document.visibilityState!==`visible`||(!c||c.readyState===EventSource.CLOSED||Date.now()-l>h?(o=0,g()):f())},v=setInterval(()=>{!t&&c&&Date.now()-l>h&&(o=0,g())},15e3);return g(),document.addEventListener(`visibilitychange`,_),window.addEventListener(`pageshow`,_),window.addEventListener(`online`,_),()=>{t=!0,clearTimeout(s),clearInterval(v),document.removeEventListener(`visibilitychange`,_),window.removeEventListener(`pageshow`,_),window.removeEventListener(`online`,_),c?.close()}},[e]);let v=(0,l.useCallback)(async(t,n)=>{if(!e)return!1;f(!0),s(null),_({});try{return await a.post(`/api/runs/${e}/${t}`,n),!0}catch(e){return e instanceof i&&e.status===422&&Array.isArray(e.body?.fields)&&_(Object.fromEntries(e.body.fields.map(e=>[e.field,e.message]))),s(e.message),!1}finally{f(!1)}},[e]);return{view:t,notFound:c,error:o,busy:d,fieldErrors:g,submitPage:(e,t)=>v(`pages/${e}`,{values:t}),accept:(e,t)=>v(`reviews/${e}`,{type:`accept`,edits:t}),regenerate:(e,t,n,r)=>v(`reviews/${e}`,{type:`regenerate`,target:t,note:n,items:r?.length?r:void 0}),back:()=>v(`back`),retry:()=>v(`retry`)}}function _({runId:e,...t}){let n=g(e);return(0,u.jsx)(o,{run:n,...t})}export{g as n,_ as t};