@engenty/wizards-runtime 0.12.1 → 0.12.2
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.
- package/apps/runtime/dist/agents/studio-assistant.js +17 -1
- package/apps/runtime/dist/app.js +4 -2
- package/apps/runtime/dist/db/live-triggers.js +13 -3
- package/apps/runtime/dist/db/migrations/tenant/0027_space_skill.sql +48 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +4120 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +31 -0
- package/apps/runtime/dist/docs/dev/skills.md +116 -0
- package/apps/runtime/dist/docs/user-guide/skills.md +85 -0
- package/apps/runtime/dist/engine/steps.js +10 -1
- package/apps/runtime/dist/harness/model.js +4 -0
- package/apps/runtime/dist/live/views.js +2 -0
- package/apps/runtime/dist/models.js +4 -0
- package/apps/runtime/dist/prompts/goose.md +7 -0
- package/apps/runtime/dist/prompts/step.md +19 -1
- package/apps/runtime/dist/prompts/tools.md +33 -0
- package/apps/runtime/dist/routes/skills.js +84 -0
- package/apps/runtime/dist/services/skills-registry.js +209 -0
- package/apps/runtime/dist/services/skills.js +478 -0
- package/apps/runtime/dist/sync/records.js +81 -1
- package/apps/runtime/dist/texts.js +39 -0
- package/apps/runtime/dist/tools/index.js +4 -2
- package/apps/runtime/dist/tools/net-guard.js +8 -4
- package/apps/runtime/dist/tools/skills.js +197 -0
- package/apps/web/dist/assets/{AboutDialog-uGYGy2R2.js → AboutDialog-CLgnoYTI.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-BWaEdlt3.js → ChangelogDialog-CKLgFL6r.js} +1 -1
- package/apps/web/dist/assets/CodeEditor-B3nto_26.js +2 -0
- package/apps/web/dist/assets/EditorPage-D9JDdAAI.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DXpzFBRj.js → FlowPreview-zJCtixSi.js} +1 -1
- package/apps/web/dist/assets/Marketplace-D4e0Oac9.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-B5wuTm7J.js → NewWizardChannels-B4N7GIYh.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-Ci1ZsTJk.js → NewWizardPage-Dpt0Mzk8.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-QkdluEZk.js → OnboardingPage-CDoYVjRC.js} +1 -1
- package/apps/web/dist/assets/PreviewPane-DPB5nEd5.js +10 -0
- package/apps/web/dist/assets/ProjectPage-408YOoNa.js +10 -0
- package/apps/web/dist/assets/{PublicRunner-Bt8gMxit.js → PublicRunner-BZ66xdRX.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-Cap_e5ke.js → ReadOnly-C9oGMkUB.js} +1 -1
- package/apps/web/dist/assets/{SettingsPage-C2rmXm_Q.js → SettingsPage-Dq3AZwJS.js} +2 -2
- package/apps/web/dist/assets/{SetupPage-CbqGgFPZ.js → SetupPage-CP3lbyZc.js} +1 -1
- package/apps/web/dist/assets/{SharePage-DEeVGatD.js → SharePage-DdMm1Y8K.js} +1 -1
- package/apps/web/dist/assets/SkillEditor-b5NMFB90.js +1 -0
- package/apps/web/dist/assets/changelog-82-DHogQ.js +1 -0
- package/apps/web/dist/assets/code-xml-Hx7YxCg0.js +1 -0
- package/apps/web/dist/assets/{dist-BwhPmMDu.js → dist-BdDd1FxP.js} +1 -1
- package/apps/web/dist/assets/dist-EBVTpvRr.js +10 -0
- package/apps/web/dist/assets/dist-GlRRx9Xl.js +1 -0
- package/apps/web/dist/assets/dist-H1UN89OA.js +1 -0
- package/apps/web/dist/assets/eye-BkMFLnYu.js +1 -0
- package/apps/web/dist/assets/i18n-CKKh3Pn0.js +55 -0
- package/apps/web/dist/assets/index-Cy2NHzAx.js +49 -0
- package/apps/web/dist/assets/index-wR_-1hfN.css +1 -0
- package/apps/web/dist/assets/json-CEsfHdlZ.js +1 -0
- package/apps/web/dist/assets/{lock-D-CjMpqn.js → lock-CGXM95Mi.js} +1 -1
- package/apps/web/dist/assets/markdown-5-I9_izp.js +29 -0
- package/apps/web/dist/assets/{oss-credits-CUpVhKSr.js → oss-credits-DpRWUPjD.js} +1 -1
- package/apps/web/dist/assets/{phone-CXSrxw3H.js → phone-DMfwuh9V.js} +1 -1
- package/apps/web/dist/assets/{runners-D71NjXtA.js → runners-D5qz6b_s.js} +1 -1
- package/apps/web/dist/assets/{session-B2LtqeDq.js → session-DRy0k0nh.js} +1 -1
- package/apps/web/dist/assets/{theme-Dab079EV.js → theme-DNPm6r4e.js} +2 -2
- package/apps/web/dist/assets/{ui-DQX_CQ7c.js → ui-CwFQAfE-.js} +2 -2
- package/apps/web/dist/assets/{upload-hLkuT3Q6.js → upload-DQJwLSGj.js} +1 -1
- package/apps/web/dist/assets/{useMutation-C3XBoSVf.js → useMutation-C20c2EH3.js} +1 -1
- package/apps/web/dist/assets/{volume-2-DIxdTlaA.js → volume-2-CC5qamYT.js} +1 -1
- package/apps/web/dist/index.html +9 -8
- package/apps/web/dist/mcp/flow.html +66 -66
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +3 -2
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +6 -0
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +1 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +2 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +165 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.js +346 -0
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +4 -2
- package/node_modules/@engenty/wizards-shared/dist/sync.js +2 -1
- package/package.json +7 -7
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/CodeEditor-B5hV1IvK.js +0 -2
- package/apps/web/dist/assets/EditorPage-j9BOx5-V.js +0 -3
- package/apps/web/dist/assets/Marketplace-DSo6uZF6.js +0 -2
- package/apps/web/dist/assets/PreviewPane-swAH89un.js +0 -10
- package/apps/web/dist/assets/ProjectPage-Djv5EOYU.js +0 -1
- package/apps/web/dist/assets/changelog-DAY6ZEyy.js +0 -1
- package/apps/web/dist/assets/dist-DVpDdhG9.js +0 -1
- package/apps/web/dist/assets/dist-DzdNG7Sf.js +0 -10
- package/apps/web/dist/assets/i18n-B3J2ypKu.js +0 -55
- package/apps/web/dist/assets/index-Dxwbli0m.css +0 -1
- package/apps/web/dist/assets/index-WY5lJ_-h.js +0 -49
- package/apps/web/dist/assets/json-D2GVvTXK.js +0 -1
- package/apps/web/dist/assets/markdown-DwdMW7q0.js +0 -29
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FlowPreview-DXpzFBRj.js","assets/rolldown-runtime-hePW80VL.js","assets/jsx-runtime-BNakU3Ej.js","assets/ui-DQX_CQ7c.js","assets/preload-helper-DpV6A1kQ.js","assets/i18n-B3J2ypKu.js","assets/esm-BdxDT9Km.js","assets/react-dom-hf6EcyAr.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{n,t as r}from"./jsx-runtime-BNakU3Ej.js";import{G as i,Gn as a,Gt as o,Hn as s,Kt as c,Mn as l,Mr as u,Sn as d,Sr as f,Tn as p,Un as m,W as h,Wt as g,Xn as _,cn as v,cr as y,dr as b,fr as x,hn as ee,ir as S,lr as C,on as w,qt as te,sn as T,sr as E,tn as D,wn as ne,zn as O}from"./ui-DQX_CQ7c.js";import{t as k}from"./useMutation-C3XBoSVf.js";import{t as A}from"./preload-helper-DpV6A1kQ.js";import{i as j,n as re,r as ie,t as ae}from"./volume-2-DIxdTlaA.js";import{d as oe,h as se,k as ce,x as le}from"./session-B2LtqeDq.js";import{c as ue,s as de}from"./engenty-CNjaZCVM.js";import{F as M,P as fe,U as pe,X as me,Y as he,g as ge,n as N,nt as _e,q as P,s as F}from"./i18n-B3J2ypKu.js";var ve=class extends C{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:b(t,n.data),hasPreviousPage:x(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function ye(e,t){return y(e,ve,t)}var be={name:`app-window`,size:24,node:[[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}],[`path`,{d:`M10 4v4`,key:`pp8u80`}],[`path`,{d:`M2 8h20`,key:`d11cs7`}],[`path`,{d:`M6 4v4`,key:`1svtjw`}]]};be.node;var I=_(be),xe={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};xe.node;var L=_(xe),Se={name:`circle-dollar-sign`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8`,key:`1h4pet`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}]]};Se.node;var Ce=_(Se),we={name:`circle-euro`,size:24,node:[[`path`,{d:`M15 9.4a4 4 0 1 0 0 5.2`,key:`1makmb`}],[`path`,{d:`M7 12h5`,key:`gblrwe`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};we.node;var Te=_(we),Ee={name:`clapperboard`,size:24,node:[[`path`,{d:`m12.296 3.464 3.02 3.956`,key:`qash78`}],[`path`,{d:`M20.2 6 3 11l-.9-2.4c-.3-1.1.3-2.2 1.3-2.5l13.5-4c1.1-.3 2.2.3 2.5 1.3z`,key:`1h7j8b`}],[`path`,{d:`M3 11h18v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`4lm6w1`}],[`path`,{d:`m6.18 5.276 3.1 3.899`,key:`zjj9t3`}]]};Ee.node;var R=_(Ee),De={name:`cloud-off`,size:24,node:[[`path`,{d:`M10.94 5.274A7 7 0 0 1 15.71 10h1.79a4.5 4.5 0 0 1 4.222 6.057`,key:`1uxyv8`}],[`path`,{d:`M18.796 18.81A4.5 4.5 0 0 1 17.5 19H9A7 7 0 0 1 5.79 5.78`,key:`99tcn7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};De.node;var Oe=_(De),ke={name:`coins`,size:24,node:[[`path`,{d:`M13.744 17.736a6 6 0 1 1-7.48-7.48`,key:`bq4yh3`}],[`path`,{d:`M15 6h1v4`,key:`11y1tn`}],[`path`,{d:`m6.134 14.768.866-.5 2 3.464`,key:`17snzx`}],[`circle`,{cx:`16`,cy:`8`,r:`6`,key:`14bfc9`}]]};ke.node;var Ae=_(ke),je={name:`eye`,size:24,node:[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]};je.node;var z=_(je),Me={name:`flag`,size:24,node:[[`path`,{d:`M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528`,key:`1jaruq`}]]};Me.node;var B=_(Me),Ne={name:`image`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]};Ne.node;var V=_(Ne),Pe={name:`layout-dashboard`,size:24,node:[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]};Pe.node;var Fe=_(Pe),Ie={name:`layout-template`,size:24,node:[[`rect`,{width:`18`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`f1a2em`}],[`rect`,{width:`9`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`jqznyg`}],[`rect`,{width:`5`,height:`7`,x:`16`,y:`14`,rx:`1`,key:`q5h2i8`}]]};Ie.node;var Le=_(Ie),Re={name:`list-checks`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`path`,{d:`m3 7 2 2 4-4`,key:`1obspn`}]]};Re.node;var ze=_(Re),Be={name:`puzzle`,size:24,node:[[`path`,{d:`M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z`,key:`w46dr5`}]]};Be.node;var Ve=_(Be),He={name:`scan-text`,size:24,node:[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`path`,{d:`M7 8h8`,key:`1jbsf9`}],[`path`,{d:`M7 12h10`,key:`b7w52i`}],[`path`,{d:`M7 16h6`,key:`1vyc9m`}]]};He.node;var Ue=_(He),We={name:`star`,size:24,node:[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]};We.node;var H=_(We),Ge={name:`table-2`,size:24,node:[[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]};Ge.node;var Ke=_(Ge),qe={name:`terminal`,size:24,node:[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]};qe.node;var Je=_(qe),Ye={name:`type`,size:24,node:[[`path`,{d:`M12 4v16`,key:`1654pz`}],[`path`,{d:`M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2`,key:`e0r10z`}],[`path`,{d:`M9 20h6`,key:`s66wpe`}]]};Ye.node;var Xe=_(Ye),Ze={name:`wand-sparkles`,size:24,node:[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]],aliases:[`wand-2`]};Ze.node;var Qe=_(Ze),$e=[`text`,`web`,`browser`,`documents`,`image`,`video`,`speech`,`listening`,`code`,`connectors`,`motion-graphics`],et=new Set([`html`,`md`,`txt`,`csv`,`json`]),tt=new Set([`code`]),nt=new Set([`web_search`,`browser`,`sandbox`,`image`]),rt=new Set([`web_fetch`,`http`]),it=/\{\{\s*memory\b/;function at(e){switch(e.type){case`agent`:return[e.instructions,e.call?JSON.stringify(e.call.input):``];case`generate`:return[e.prompt,e.options?.style??``];case`motion-graphics`:return[e.brief];case`widget`:case`surface`:return Object.values(e.data).map(e=>`{{${M(e)}}}`);default:return[]}}function ot(e,t){return e.steps.slice(t+1).some(e=>e.type===`agent`&&!e.call||e.type===`generate`||e.type===`motion-graphics`)}function st(e,t){let n=[],r=(t,r)=>{let i=n.find(e=>e.need===t);i?i.hard||=r:n.push({stepId:e.id,need:t,hard:r})},i=t.steps.indexOf(e);for(let t of at(e))it.test(t)&&r(`memory`,!0),_e(t).some(e=>e.startsWith(`lists.`))&&r(`lists`,!0);switch(e.type){case`page`:for(let n of e.fields){switch(n.kind){case`audio`:r(`field:audio`,!!n.required);break;case`connection`:r(`field:connection`,!0);break;case`slot`:r(`field:slot`,!0);break;case`list`:r(`lists`,!0);break;case`location`:r(`field:location`,!1);break;case`image`:r(`field:image`,!1);break;case`file`:ot(t,i)?r(`field:file-read`,!0):r(`field:file`,!1)}n.optionsFrom&&P(M(n.optionsFrom).split(`.`).slice(0,2).join(`.`))&&r(`lists`,!0)}break;case`agent`:{let t=e.call?[...e.tools,e.call.tool]:e.tools;for(let e of t){let t=he(e);t?r(`plugin:${t.plugin}`,!0):rt.has(e)||tt.has(e)||(nt.has(e)?r(`tool:${e}`,!0):r(`tool:${e}`,!1))}e.connections?.length&&r(`connections`,!0),e.each&&(P(M(e.each))?r(`lists`,!0):r(`each`,!1));break}case`generate`:e.asset!==`document`&&e.asset!==`dashboard`&&r(`asset:${e.asset}`,!0);break;case`motion-graphics`:r(`motion-graphics`,!0);break;case`widget`:r(e.video?`widget:video`:`widget`,!0);break;case`surface`:Object.values(e.data).some(e=>P(M(e)))&&r(`lists`,!0);break;case`review`:e.show.some(e=>P(e))&&r(`lists`,!0);break;case`result`:for(let n of e.deliverables){if(P(n.from)){r(`lists`,!0);continue}let e=t.steps.find(e=>e.id===n.from);if(e?.type!==`agent`&&(e?.type!==`generate`||e.asset!==`document`&&e.asset!==`dashboard`))continue;let i=n.formats.some(e=>et.has(e));for(let t of n.formats)et.has(t)||(t!==`pdf`||e?.type!==`agent`)&&r(`format:${t}`,t!==`pdf`&&!i)}}return n}function ct(e){let t=e.steps.flatMap(t=>st(t,e));e.lists?.length&&!t.some(e=>e.need===`lists`)&&t.push({stepId:e.steps[0]?.id??``,need:`lists`,hard:!0}),e.connections?.length&&!t.some(e=>e.need===`connections`)&&t.push({stepId:e.steps[0]?.id??``,need:`connections`,hard:!0});let n=dt(e);return{fit:t.some(e=>e.hard&&n.has(e.stepId))?`no`:t.length?`less`:`full`,notes:t}}function lt(e){switch(e){case`tool:web_search`:case`tool:web_fetch`:return`web`;case`tool:browser`:return`browser`;case`tool:sandbox`:return`code`;case`tool:image`:case`asset:image`:return`image`;case`asset:video`:case`motion-graphics`:case`widget:video`:return`video`;case`asset:voice`:return`speech`;case`field:audio`:return`listening`;case`tool:http`:case`connections`:case`field:connection`:return`connectors`;case`field:image`:case`field:file`:case`field:file-read`:return`documents`;default:return null}}function ut(e){let t=ct(e),n=dt(e),r=new Set,i=new Set,a=new Set,o=new Set;for(let e of t.notes){if(e.need.startsWith(`plugin:`)){a.add(e.need.slice(7));continue}if(e.need.startsWith(`format:`)){o.add(e.need.slice(7));continue}let t=lt(e.need);t&&(e.hard&&n.has(e.stepId)?r.add(t):i.add(t))}for(let e of r)i.delete(e);return{...t,missing:[...r],optional:[...i],needs:[...a].sort(),without:[...o]}}function dt(e){return e.steps.length?ft(e,e.steps[0].id,{}):new Set}function ft(e,t,n){let r=new Map(e.steps.map((e,t)=>[e.id,t])),i=r.get(t)??0,a=t=>{let i=[];for(let a of e.steps[t].next??[]){if(pe(a))continue;let t=a.goto===`end`?e.steps.length:r.get(a.goto)??-1;if(a.ask||!fe(a.when).every(e=>e.field in n)){t>=0&&i.push(t);continue}if(me(a,n))return t>=0?[...i,t]:i}return i.push(pt(e,t,r)),i},o=t=>{if(t===i)return!1;let n=new Set([i]),r=[i];for(;r.length;){let i=r.shift();if(i>=e.steps.length)return!0;for(let e of a(i))e!==t&&!n.has(e)&&(n.add(e),r.push(e))}return!1};return new Set(e.steps.filter((e,t)=>!o(t)).map(e=>e.id))}function pt(e,t,n){let r=e.steps[t].next?.find(pe)?.goto;return r===void 0?t+1:r===`end`?e.steps.length:n.get(r)??t+1}var mt=[`text`,`document`,`table`,`image`,`video`,`audio`,`dashboard`],ht=[`any`,`trades`,`gastronomy`,`hospitality`,`realEstate`,`retail`,`health`,`professional`,`agency`,`events`,`publicSector`],gt=[`marketing`,`sales`,`accounting`,`service`,`research`,`hr`,`operations`,`website`,`visuals`,`inquiries`,`advice`],_t=[`free`,`pro`],vt={"format.text":`Text`,"format.document":`Document (PDF, Word)`,"format.table":`Table`,"format.image":`Image`,"format.video":`Video`,"format.audio":`Audio`,"format.dashboard":`Dashboard`,"industry.any":`Any industry`,"industry.trades":`Trades`,"industry.gastronomy":`Food service`,"industry.hospitality":`Hotels & tourism`,"industry.realEstate":`Real estate`,"industry.retail":`Retail`,"industry.health":`Health`,"industry.professional":`Professional services`,"industry.agency":`Agency & marketing`,"industry.events":`Events`,"industry.publicSector":`Associations & public sector`,"useCase.marketing":`Marketing & social media`,"useCase.sales":`Offers & sales`,"useCase.accounting":`Accounting & receipts`,"useCase.service":`Customer service`,"useCase.research":`Research & analysis`,"useCase.hr":`HR & applications`,"useCase.operations":`Planning & operations`,"useCase.website":`Website helpers`,"useCase.visuals":`Images & video`,"useCase.inquiries":`Inquiries & bookings`,"useCase.advice":`Advice & pricing`,"capability.text":`Writes text`,"capability.web":`Web search`,"capability.browser":`Drives a browser`,"capability.documents":`Reads documents & photos`,"capability.image":`Makes images`,"capability.video":`Makes video`,"capability.speech":`Speech output`,"capability.listening":`Understands voice notes`,"capability.code":`Runs code`,"capability.connectors":`Connected accounts & systems`,"capability.motion-graphics":`Motion graphics with Claude Code (on your subscription)`,"cost.low":`low cost`,"cost.medium":`medium cost`,"cost.high":`high cost`,"plan.free":`Free`,"plan.pro":`Pro`,"outline.otherwise":`otherwise`,"outline.and":`{first} and {second}`,"outline.with":`with {name}`,"outline.without":`without {name}`,"outline.contains":`{name} contains {value}`},yt={en:vt,de:{"format.text":`Text`,"format.document":`Dokument (PDF, Word)`,"format.table":`Tabelle`,"format.image":`Bild`,"format.video":`Video`,"format.audio":`Audio`,"format.dashboard":`Dashboard`,"industry.any":`Jede Branche`,"industry.trades":`Handwerk`,"industry.gastronomy":`Gastronomie`,"industry.hospitality":`Hotel & Tourismus`,"industry.realEstate":`Immobilien`,"industry.retail":`Handel`,"industry.health":`Gesundheit`,"industry.professional":`Kanzlei & Beratung`,"industry.agency":`Agentur & Marketing`,"industry.events":`Veranstaltungen`,"industry.publicSector":`Vereine & Öffentliches`,"useCase.marketing":`Marketing & Social Media`,"useCase.sales":`Angebote & Verkauf`,"useCase.accounting":`Buchhaltung & Belege`,"useCase.service":`Kundenservice`,"useCase.research":`Recherche & Analyse`,"useCase.hr":`Personal & Bewerbungen`,"useCase.operations":`Planung & Abläufe`,"useCase.website":`Helfer für die Website`,"useCase.visuals":`Bilder & Video`,"useCase.inquiries":`Anfragen & Termine`,"useCase.advice":`Beratung & Preise`,"capability.text":`Text schreiben`,"capability.web":`Websuche`,"capability.browser":`Browser bedienen`,"capability.documents":`Dokumente & Fotos lesen`,"capability.image":`Bilder erzeugen`,"capability.video":`Videos erzeugen`,"capability.speech":`Sprachausgabe`,"capability.listening":`Sprachnotizen verstehen`,"capability.code":`Code ausführen`,"capability.connectors":`Verbundene Konten & Systeme`,"capability.motion-graphics":`Motion-Grafik mit Claude Code (auf deinem Abo)`,"cost.low":`günstig`,"cost.medium":`mittel`,"cost.high":`teuer`,"plan.free":`Kostenlos`,"plan.pro":`Pro`,"outline.otherwise":`sonst`,"outline.and":`{first} und {second}`,"outline.with":`mit {name}`,"outline.without":`ohne {name}`,"outline.contains":`{name} enthält {value}`}};function bt(e,t,n,r){let i=`${e}.${t}`;return i in vt?ge(yt,i,n,r):t}var U=t(n(),1);function xt(e){switch(e.type){case`page`:return ze;case`agent`:return j;case`generate`:return e.asset===`image`?V:e.asset===`video`?v:e.asset===`dashboard`?Fe:l;case`widget`:return I;case`surface`:return Le;case`motion-graphics`:return R;case`review`:return z;case`result`:return B}return Qe}var St={page:`bg-cobalt-tint text-cobalt`,agent:`bg-ember-tint text-ember-strong`,generate:`bg-amber-tint text-ink-2`,widget:`bg-ember-veil text-ember-strong`,surface:`bg-ember-veil text-ember-strong`,"motion-graphics":`bg-amber-tint text-ink-2`,review:`bg-moss-tint text-moss`,result:`bg-paper-2 text-ink-2`};function Ct(e){return F(`type.${e.type}`)}var wt=[`web_search`,`web_fetch`,`browser`,`sandbox`,`image`,`http`,`pages`,`code`];function Tt(e){return wt.includes(e)?F(`tool.${e}`):e}function Et(e){switch(e.type){case`page`:return e.fields.map(e=>e.label).join(` · `);case`agent`:return e.tools.map(Tt).join(` · `)||e.instructions.slice(0,90);case`generate`:{let t=[e.asset];return e.options?.aspectRatio&&t.push(e.options.aspectRatio),e.options?.duration&&t.push(`${e.options.duration}s`),e.options?.resolution&&t.push(e.options.resolution),e.options?.template&&t.push(e.options.template),t.join(` · `)}case`widget`:return[e.entry,Object.keys(e.data).join(`, `)].filter(Boolean).join(` · `);case`surface`:return e.candidates?e.candidates.map(e=>e.id).join(` · `):Object.keys(e.data).join(`, `);case`motion-graphics`:return[e.format,e.seconds?`${e.seconds}s`:null,e.skills.join(`, `)].filter(Boolean).join(` · `);case`review`:return[e.edit?F(`editor.reviewEditable`):null,e.regenerate?F(`editor.reviewRedo`):null].filter(Boolean).join(` · `);case`result`:return e.deliverables.map(e=>`${e.label??e.from} (${e.formats.join(`, `)})`).join(` · `)}return``}var Dt=e({EntryDialog:()=>Q,MarketplaceBrowser:()=>Xt,MarketplaceCards:()=>Yt,MarketplaceFit:()=>Jt,MarketplaceHits:()=>Kt,ProChip:()=>Lt,useFit:()=>qt,useSettled:()=>$}),W=t(r(),1),Ot=(0,U.lazy)(()=>A(()=>import(`./FlowPreview-DXpzFBRj.js`),__vite__mapDeps([0,1,2,3,4,5,6,7])));function kt({level:e}){let t=e.next,n=t?Math.max(0,t.runs-e.progress.runs):0,r=t?Math.max(0,t.published-e.progress.published):0,i=t?Math.min(1,(Math.min(e.progress.runs/Math.max(1,t.runs),1)+Math.min(e.progress.published/Math.max(1,t.published||1),1))/2):1;return(0,W.jsxs)(`div`,{className:`mx-auto mt-3 flex max-w-md items-center gap-3 text-[0.78125rem] text-ink-3`,children:[(0,W.jsx)(`span`,{className:`shrink-0 font-medium text-ink-2`,children:F(`market.level`,{level:e.level,name:e.name})}),(0,W.jsx)(`span`,{className:`h-1.5 flex-1 overflow-hidden rounded-full bg-paper-3`,children:(0,W.jsx)(`span`,{className:`block h-full rounded-full bg-primary`,style:{width:`${i*100}%`}})}),(0,W.jsx)(`span`,{className:`shrink-0`,children:t?F(r?`market.levelNextPublish`:`market.levelNext`,{runs:n,published:r,name:t.name}):F(`market.levelTop`)})]})}var At={useCase:``,industry:``,format:``,capability:``,plan:``},G=(e,t)=>bt(e,t,N),jt={en:Ce,de:Te};function Mt(e){if(e<1)return 1;let t=10**Math.floor(Math.log10(e));return Math.round(e/t)*t}function Nt(e){return e.credits?F(`market.credits`,{n:Mt(e.credits.credits)}):G(`cost`,e.costTier)}var Pt={text:Xe,document:l,table:Ke,image:V,video:v,audio:a,dashboard:L};function K({format:e,className:t}){let n=Pt[e],r=G(`format`,e);return(0,W.jsx)(`span`,{title:r,className:`inline-flex`,children:(0,W.jsx)(n,{className:t,"aria-label":r,role:`img`})})}var Ft=[`low`,`medium`,`high`];function It({entry:e}){let t=Ft.indexOf(e.costTier)+1,n=jt[N];return(0,W.jsxs)(`span`,{title:Nt(e),className:`inline-flex items-center gap-1`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`inline-flex shrink-0`,children:Ft.slice(0,t).map((e,t)=>(0,W.jsx)(`span`,{className:w(`rounded-full bg-(--coin-bg,var(--color-card))`,t>0&&`-ml-1.5`),children:(0,W.jsx)(n,{className:`size-4`})},e))}),G(`cost`,e.costTier)]})}function Lt(){return(0,W.jsx)(c,{tone:`ember`,title:F(`market.proHint`),children:F(`market.pro`)})}function Rt({plugin:e}){return(0,W.jsx)(c,{icon:(0,W.jsx)(Ve,{className:`size-3.5`}),title:F(`market.fromPlugin`,{name:e.name}),children:e.name})}function q({entry:e,onOpen:t,why:n}){return(0,W.jsxs)(o,{role:`button`,tabIndex:0,onClick:t,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())},className:w(`relative flex min-h-[124px] cursor-pointer flex-col gap-5 p-4 text-left transition sm:min-h-[136px] sm:p-5 hover:shadow-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus`,(!e.usable||e.missing.length>0||!!e.needs?.length)&&`opacity-60`),children:[(0,W.jsx)(`span`,{className:`-top-4 pointer-events-none absolute right-4`,children:(0,W.jsx)(le,{kind:e.avatar,costume:e.costume,size:68})}),(0,W.jsxs)(`div`,{className:`min-w-0 pr-20`,children:[(0,W.jsxs)(`div`,{className:`font-display font-semibold text-[0.9375rem]`,children:[e.title,e.plan===`pro`?(0,W.jsx)(`span`,{className:`ml-1.5 inline-flex align-middle`,children:(0,W.jsx)(Lt,{})}):null,e.starred?(0,W.jsx)(H,{className:`ml-1.5 inline size-3.5 fill-amber align-[-2px] text-amber`,"aria-label":F(`market.starred`)}):null]}),e.featured?(0,W.jsx)(`div`,{className:`mt-1`,children:(0,W.jsx)(c,{tone:`ember`,children:F(`market.recommended`)})}):null,(0,W.jsx)(`div`,{className:`mt-0.5 text-[0.8125rem] text-ink-3 leading-snug`,children:e.pitch})]}),(0,W.jsxs)(`div`,{className:`mt-auto flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[0.75rem] text-ink-3`,children:[n?(0,W.jsx)(c,{children:n}):null,e.plugin?(0,W.jsx)(Rt,{plugin:e.plugin}):null,e.needs?.length?(0,W.jsx)(c,{tone:`warn`,children:F(`market.needsPro`,{list:e.needs.join(`, `)})}):e.usable&&e.missing.length?(0,W.jsx)(c,{tone:`warn`,children:F(`market.missing`,{list:Y(e.missing)})}):e.usable?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,W.jsx)(O,{className:`size-3.5`}),` `,F(`market.minutes`,{n:e.effort.minutes})]}),(0,W.jsx)(It,{entry:e}),e.optional?.length?(0,W.jsx)(c,{title:F(`market.optionalHint`,{list:Y(e.optional)}),children:F(`market.without`,{list:Y(e.optional)})}):null,(0,W.jsx)(`span`,{className:`ml-auto inline-flex items-center gap-1.5`,children:e.formats.map(e=>(0,W.jsx)(K,{format:e,className:`size-4`},e))})]}):(0,W.jsx)(c,{tone:`warn`,children:F(`market.needsUpdate`)})]})]})}function J({title:e,children:t}){return(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`mb-1.5 font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.06em]`,children:e}),t]})}var Y=e=>e.map(e=>G(`capability`,e)).join(`, `),zt={text:d,web:ie,browser:ne,documents:Ue,image:V,video:v,speech:ae,listening:p,code:Je,connectors:re,"motion-graphics":R};function Bt(e){switch(e.type){case`page`:return ze;case`agent`:return j;case`generate`:return e.asset===`image`?V:e.asset===`video`?v:e.asset===`voice`?ae:e.asset===`dashboard`?L:l;case`widget`:return e.video?R:I;case`surface`:return I;case`motion-graphics`:return R;case`review`:return z;case`result`:return B}return Qe}function Vt(e){let t=new Set;for(let[n,r]of e.entries())for(let i of r.branches??[]){let r=i.to===`end`?e.length:e.findIndex(e=>e.id===i.to);for(let i=n+1;i<r;i++)t.add(e[i].id)}return t}function Ht(e){let t=Vt(e);return e.map(e=>({id:e.id,title:e.title,icon:Bt(e),tone:St[e.type]??`bg-paper-2 text-ink-2`,optional:t.has(e.id),branches:e.branches}))}function X({title:e,children:t}){return(0,W.jsx)(`span`,{title:e,className:`inline-flex items-center gap-2 border-border border-l px-4 first:border-l-0 first:pl-0`,children:t})}function Z({icon:e,children:t,more:n}){return(0,W.jsxs)(`div`,{className:`flex gap-2.5`,children:[(0,W.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:e}),(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-[0.875rem] text-ink leading-snug`,children:t}),n?(0,W.jsx)(`div`,{className:`text-[0.75rem] text-ink-3 leading-snug`,children:n}):null]})]})}function Ut({className:e,children:t}){let n=(0,U.useRef)(null),[r,i]=(0,U.useState)({above:!1,below:!1});(0,U.useEffect)(()=>{let e=n.current;if(!e)return;let t=()=>{let t=e.scrollTop>1,n=e.scrollTop+e.clientHeight<e.scrollHeight-1;i(e=>e.above===t&&e.below===n?e:{above:t,below:n})};t(),e.addEventListener(`scroll`,t,{passive:!0});let r=new ResizeObserver(t);return r.observe(e),e.firstElementChild&&r.observe(e.firstElementChild),()=>{e.removeEventListener(`scroll`,t),r.disconnect()}},[]);let a=`linear-gradient(to bottom, ${r.above?`transparent`:`black`} 0, black 28px, black calc(100% - 44px), ${r.below?`transparent`:`black`} 100%)`;return(0,W.jsx)(`div`,{ref:n,className:e,style:{maskImage:a,WebkitMaskImage:a},children:(0,W.jsx)(`div`,{children:t})})}function Q({id:e,fallback:t,onClose:n,onUse:r,busy:a}){let o=u(),s=S(),c=E({queryKey:[`marketplace-entry`,e,N],queryFn:()=>i.get(`/api/studio/marketplace/${encodeURIComponent(e)}?lang=${N}`),enabled:!!e,retry:!1}),l=c.data??t,d=k({mutationFn:t=>{let n=`/api/studio/marketplace/${encodeURIComponent(e)}/star`;return t?i.put(n):i.del(n)},onSuccess:()=>Promise.all([o.invalidateQueries({queryKey:[`marketplace`]}),o.invalidateQueries({queryKey:[`marketplace-entry`,e]})])}),f=ce()===`dark`,p=de[ue[l?.avatar||`round`]],m=f?`var(--card)`:`color-mix(in oklch, ${p??`var(--ink-4)`} 14%, var(--paper-2))`;return(0,W.jsx)(te,{open:!!e,onClose:n,wide:!0,bare:!0,children:l?(0,W.jsxs)(`div`,{className:`relative flex max-h-[calc(100dvh-48px)] flex-col rounded-2xl bg-card shadow-overlay max-sm:h-dvh max-sm:max-h-none max-sm:rounded-none`,children:[(0,W.jsx)(`button`,{type:`button`,"aria-label":F(`common.close`),onClick:n,className:`sm:-top-3.5 sm:-right-3.5 absolute top-3 right-3 z-20 flex size-9 items-center justify-center rounded-full bg-card text-ink-2 shadow-elevated ring-1 ring-border-soft transition hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus`,children:(0,W.jsx)(T,{className:`size-4`})}),(0,W.jsxs)(`header`,{className:`relative shrink-0 border-border-soft border-b px-5 pt-5 pb-4 text-ink sm:rounded-t-2xl sm:px-7`,style:{background:m,"--coin-bg":m},children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 overflow-hidden sm:rounded-t-2xl`,children:(0,W.jsx)(`span`,{className:w(`-top-28 -right-10 absolute size-80 rounded-full bg-white blur-3xl`,f?`opacity-[0.14]`:`opacity-80`)})}),(0,W.jsx)(`div`,{className:`-bottom-5 absolute right-9 z-10 max-sm:hidden`,children:(0,W.jsx)(le,{kind:l.avatar,costume:l.costume,size:104})}),(0,W.jsxs)(`div`,{className:`relative sm:pr-36`,children:[(0,W.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight max-sm:pr-10`,children:l.title}),(0,W.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-2 leading-snug`,children:c.data?.description||l.pitch})]}),l.usable?(0,W.jsxs)(`div`,{className:`-mx-5 sm:-mx-7 relative mt-3.5 flex flex-wrap items-center gap-y-2 border-border-soft border-t px-5 pt-3 font-medium text-[0.875rem] sm:px-7 sm:pr-40`,children:[(0,W.jsxs)(X,{title:F(`market.duration`),children:[(0,W.jsx)(O,{className:`size-4 text-ink-3`}),F(`market.minutes`,{n:l.effort.minutes})]}),(0,W.jsx)(X,{title:F(`market.cost`),children:(0,W.jsx)(It,{entry:l})}),(0,W.jsx)(X,{title:F(`market.result`),children:l.formats.map(e=>(0,W.jsx)(K,{format:e,className:`size-4`},e))})]}):null]}),l.usable?(0,W.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-x-7 gap-y-6 px-5 pt-6 max-sm:overflow-y-auto max-sm:pb-4 sm:grid-cols-[230px_minmax(0,1fr)] sm:grid-rows-[minmax(0,1fr)] sm:px-7`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-5 sm:min-h-0 sm:overflow-y-auto`,children:[(0,W.jsx)(J,{title:F(`market.duration`),children:(0,W.jsx)(Z,{icon:(0,W.jsx)(O,{className:`size-4 text-moss`}),more:F(`market.durationHint`,{n:l.effort.fields}),children:F(`market.minutes`,{n:l.effort.minutes})})}),(0,W.jsx)(J,{title:F(`market.cost`),children:(0,W.jsx)(Z,{icon:(0,W.jsx)(Ae,{className:`size-4 text-amber`}),more:l.credits?F(`market.creditsHint`):void 0,children:(0,W.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,W.jsx)(It,{entry:l}),l.credits?(0,W.jsx)(`span`,{className:`text-ink-2`,children:F(`market.creditsRange`,{n:Mt(l.credits.credits)})}):null]})})}),(0,W.jsx)(J,{title:F(`market.result`),children:(0,W.jsx)(`div`,{className:`flex flex-col gap-2`,children:(c.data?.results??[]).map(e=>(0,W.jsx)(Z,{icon:(0,W.jsx)(K,{format:e.kind,className:`size-4 text-ember-strong`}),more:e.formats.map(e=>e.toUpperCase()).join(` · `),children:e.title},e.title))})}),(0,W.jsx)(J,{title:F(`market.needs`),children:(0,W.jsx)(`ul`,{className:`flex flex-col gap-2`,children:l.capabilities.map(e=>{let t=zt[e],n=l.missing.includes(e),r=l.optional?.includes(e);return(0,W.jsxs)(`li`,{className:w(`flex items-center gap-2.5 text-[0.875rem]`,n?`text-ink-3`:`text-ink-2`),children:[(0,W.jsx)(t,{className:w(`size-4 shrink-0`,n?`text-rose`:r?`text-amber`:`text-cobalt`)}),G(`capability`,e),n?(0,W.jsx)(`span`,{className:`text-[0.75rem] text-rose`,children:F(`market.unavailable`)}):r?(0,W.jsx)(`span`,{className:`text-[0.75rem] text-amber`,children:F(`market.optional`)}):null]},e)})})})]}),(0,W.jsxs)(`div`,{className:`flex flex-col sm:min-h-0`,children:[(0,W.jsx)(`div`,{className:`mb-1.5 shrink-0 font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.06em]`,children:F(`market.steps`)}),(0,W.jsx)(Ut,{className:`-mr-2 overscroll-contain pt-1 pr-2 pl-1 sm:min-h-0 sm:flex-1 sm:overflow-y-auto`,children:c.isLoading?(0,W.jsx)(D,{className:`size-5 text-ink-3`}):(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(D,{className:`size-5 text-ink-3`}),children:(0,W.jsx)(Ot,{steps:Ht(c.data?.outline??[])})})})]})]}):(0,W.jsx)(`div`,{className:`flex-1 px-5 pt-6 sm:px-7`,children:(0,W.jsx)(`p`,{className:`rounded-lg bg-amber-tint p-3 text-[0.875rem] text-ink-2`,children:F(`market.needsUpdateHint`)})}),(0,W.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 px-5 pt-4 pb-5 max-sm:border-border-soft max-sm:border-t sm:px-7 sm:pb-6`,children:[l.plugin?(0,W.jsx)(`span`,{className:`mr-auto flex items-center`,children:(0,W.jsx)(Rt,{plugin:l.plugin})}):(0,W.jsxs)(g,{variant:`ghost`,className:`mr-auto`,title:F(`market.starHint`),"aria-pressed":l.starred,busy:d.isPending,onClick:()=>d.mutate(!l.starred),children:[(0,W.jsx)(H,{className:w(`size-4`,l.starred&&`fill-amber text-amber`)}),(0,W.jsx)(`span`,{className:`max-sm:sr-only`,children:F(l.starred?`market.starred`:`market.star`)})]}),(0,W.jsx)(g,{variant:`secondary`,onClick:n,children:F(`common.close`)}),l.usable&&l.missing.length?(0,W.jsx)(g,{variant:`secondary`,onClick:()=>s(`/settings/models`),children:F(`editor.models.settings`)}):null,r?(0,W.jsx)(g,{disabled:!l.usable||l.missing.length>0||!!l.needs?.length,title:l.needs?.length?F(`market.needsProHint`,{list:l.needs.join(`, `)}):l.missing.length?F(`market.missingHint`,{list:Y(l.missing)}):l.optional?.length?F(`market.optionalHint`,{list:Y(l.optional)}):void 0,busy:a,onClick:()=>r(l),children:F(`market.use`)}):null]})]}):(0,W.jsx)(`div`,{className:`flex min-h-48 flex-col items-center justify-center gap-3 rounded-2xl bg-card p-8 text-[0.875rem] text-ink-2 shadow-overlay`,children:c.isLoading?(0,W.jsx)(D,{className:`size-6 text-ink-3`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{children:F(`market.notFound`)}),(0,W.jsx)(g,{variant:`secondary`,onClick:n,children:F(`common.close`)})]})})})}function Wt({name:e,value:t,options:n,onChange:r}){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)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let c=n.find(e=>e.value===t);return(0,W.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,W.jsxs)(`div`,{className:w(`flex h-8 items-center rounded-full text-[0.8125rem] transition`,c?`bg-ember-tint text-ink`:`text-ink-2 hover:bg-paper-2 hover:text-ink`,i&&!c&&`bg-paper-2 text-ink`),children:[(0,W.jsx)(`button`,{type:`button`,"aria-haspopup":`listbox`,"aria-expanded":i,onClick:()=>a(!i),className:w(`flex h-full items-center gap-1.5 rounded-full pl-3 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus`,c?`pr-1`:`pr-2.5`),children:c?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-ink-3`,children:e}),(0,W.jsx)(`span`,{className:`font-medium`,children:c.label})]}):(0,W.jsxs)(W.Fragment,{children:[e,(0,W.jsx)(s,{className:w(`size-3.5 transition`,i&&`rotate-180`)})]})}),c?(0,W.jsx)(`button`,{type:`button`,"aria-label":`${e}: ${F(`market.reset`)}`,onClick:()=>r(``),className:`mr-1 flex size-6 items-center justify-center rounded-full text-ink-3 hover:bg-card hover:text-ink`,children:(0,W.jsx)(T,{className:`size-3.5`})}):null]}),i?(0,W.jsx)(`div`,{role:`listbox`,"aria-label":e,className:`absolute top-full left-0 z-30 mt-1.5 max-h-80 min-w-60 overflow-y-auto rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:n.map(e=>(0,W.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":e.value===t,disabled:!e.count||e.unavailable,onClick:()=>{r(e.value===t?``:e.value),a(!1)},className:w(`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[0.875rem] transition coarse:py-2.5`,e.count&&!e.unavailable?`text-ink-2 hover:bg-paper-2 hover:text-ink`:`text-ink-4`,e.value===t&&`font-medium text-ink`),children:[e.icon,(0,W.jsx)(`span`,{className:`flex-1 whitespace-nowrap`,children:e.label}),e.value===t?(0,W.jsx)(m,{className:`size-4 text-ember`}):e.unavailable?(0,W.jsx)(`span`,{className:`whitespace-nowrap text-[0.75rem] text-ink-4`,children:F(`market.unavailable`)}):(0,W.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:e.count})]},e.value))}):null]})}function $(e,t){let[n,r]=(0,U.useState)(e);return(0,U.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}var Gt=60;function Kt({query:e,onUse:t,busy:n,limit:r=6}){let[a,o]=(0,U.useState)(null),s=$(e.trim(),250),c=E({queryKey:[`marketplace`,N,s,`hits`,r],queryFn:()=>i.get(`/api/studio/marketplace?${new URLSearchParams({lang:N,limit:String(r),offset:`0`,q:s})}`),enabled:!!s,placeholderData:f}),l=s?c.data?.entries??[]:[];return l.length?(0,W.jsxs)(`section`,{className:`mt-10`,children:[(0,W.jsxs)(`h2`,{className:`mb-5 flex items-center gap-2 font-medium text-[0.8125rem] text-ink-3 uppercase tracking-[0.08em]`,children:[F(`market.hits`),c.isFetching?(0,W.jsx)(D,{className:`size-3.5`}):null]}),(0,W.jsx)(`div`,{className:`flex flex-col gap-4 sm:grid sm:grid-cols-2 lg:grid-cols-3`,children:l.map(e=>(0,W.jsx)(q,{entry:e,onOpen:()=>o(e.id)},e.id))}),(0,W.jsx)(Q,{id:a,fallback:l.find(e=>e.id===a)??null,onClose:()=>o(null),onUse:t,busy:n})]}):null}function qt(){let e=E({queryKey:[`marketplace`,N,`fit`],queryFn:()=>i.get(`/api/studio/marketplace?${new URLSearchParams({lang:N,limit:`12`,offset:`0`,fit:`1`})}`)});return e.data?.context&&e.data.entries.some(e=>e.fit)?e.data:null}function Jt({page:e,organization:t,onUse:n,busy:r,onAll:i}){let[a,o]=(0,U.useState)(null),s=e.context??{sector:null,sectorName:null},c=e.entries,l=e=>e.fit===`sector`||e.fit===`industry`?s.sectorName:e.fit===`wish`?F(`market.fitWish`):null;return(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`h2`,{className:`mt-16 text-center font-medium text-[0.8125rem] text-ink-3 uppercase tracking-[0.08em]`,children:F(`market.fitTitle`,{organization:t})}),(0,W.jsx)(`p`,{className:`mt-2 mb-5 text-center text-[0.875rem] text-ink-3`,children:s.sectorName?F(`market.fitLine`,{sector:s.sectorName}):F(`market.fitLinePlain`)}),(0,W.jsx)(`div`,{className:`flex flex-col gap-4 sm:grid sm:grid-cols-2 lg:grid-cols-3`,children:c.map((e,t)=>(0,W.jsx)(`div`,{className:w(`contents`,t>=4&&`max-sm:hidden`,t>=8&&`sm:max-lg:hidden`),children:(0,W.jsx)(q,{entry:e,why:l(e),onOpen:()=>o(e.id)})},e.id))}),(0,W.jsx)(`div`,{className:`mt-6 flex justify-center`,children:(0,W.jsx)(g,{variant:`secondary`,onClick:i,children:F(`market.fitAll`,{n:e.all||e.total})})}),(0,W.jsx)(Q,{id:a,fallback:c.find(e=>e.id===a)??null,onClose:()=>o(null),onUse:n,busy:r})]})}function Yt({entries:e}){let t=u(),n=S(),{project:r}=oe(),a=se()&&!!r&&!r?.readOnly,[o,s]=(0,U.useState)(null),c=k({mutationFn:e=>i.post(`/api/studio/wizards`,{projectId:r.id,starterId:e,lang:N}),onSuccess:async({id:e})=>{await t.invalidateQueries({queryKey:h.spaces()}),await t.invalidateQueries({queryKey:[`wizards`]}),s(null),n(`/edit/${e}`)}});return(0,W.jsxs)(`div`,{className:`@container mt-3`,children:[(0,W.jsx)(`div`,{className:`flex flex-col gap-4 @xl:grid @xl:grid-cols-2`,children:e.map(e=>(0,W.jsx)(q,{entry:e,onOpen:()=>s(e.id)},e.id))}),c.error?(0,W.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:c.error.message}):null,(0,W.jsx)(Q,{id:o,fallback:e.find(e=>e.id===o)??null,onClose:()=>s(null),onUse:a?e=>!c.isPending&&c.mutate(e.id):void 0,busy:c.isPending})]})}function Xt({onUse:e,busy:t,open:n,search:r,onGuestOpen:a}){let[o,s]=(0,U.useState)(``);(0,U.useEffect)(()=>{r&&s(r.text)},[r]);let[c,l]=(0,U.useState)(At),[u,d]=(0,U.useState)(!1),[p,m]=(0,U.useState)(n??null),h=$(o.trim(),250),_=(0,U.useRef)(null);(0,U.useEffect)(()=>{let e=_.current;h&&e&&window.matchMedia(`(max-width: 639px)`).matches&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[h]);let v=ye({queryKey:[`marketplace`,N,h,c,u],queryFn:({pageParam:e})=>{let t=new URLSearchParams({lang:N,limit:String(Gt),offset:String(e)});h&&t.set(`q`,h);for(let[e,n]of Object.entries(c))n&&t.set(e,n);return u&&t.set(`starred`,`1`),i.get(`/api/${a?`guest`:`studio`}/marketplace?${t}`)},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.entries.length,0);return n<e.total?n:void 0},placeholderData:f}),y=v.data?.pages[0],b=v.data?.pages.flatMap(e=>e.entries)??[],x=y?.all??0,S=o.trim()!==h||v.isFetching&&!v.isFetchingNextPage,C=(e,t,n,r)=>n.filter(t=>y?.facets[e]?.[t]!==void 0).map(n=>({value:n,label:G(t,n),icon:r?.(n),count:(y?.facets[e])[n]??0,unavailable:e===`capability`&&te.has(n)})),te=new Set(y?.unavailable??[]),E=C(`useCase`,`useCase`,gt),ne=[{key:`industry`,name:F(`market.industry`),options:C(`industry`,`industry`,ht)},{key:`format`,name:F(`market.format`),options:C(`format`,`format`,mt,e=>(0,W.jsx)(K,{format:e,className:`size-4 text-ink-3`}))},{key:`plan`,name:F(`market.plan`),options:C(`plan`,`plan`,_t)},{key:`capability`,name:F(`market.capability`),options:C(`capability`,`capability`,$e,e=>{let t=zt[e];return(0,W.jsx)(t,{className:`size-4 text-ink-3`})})}],O=!!o.trim()||u||Object.values(c).some(Boolean),k=()=>{l(At),s(``),d(!1)};if(v.isLoading)return(0,W.jsx)(`div`,{className:`flex justify-center py-10`,children:(0,W.jsx)(D,{className:`size-6 text-ink-3`})});let A=y?.offline?(0,W.jsxs)(`p`,{className:`mt-4 flex items-center justify-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,W.jsx)(Oe,{className:`size-4 shrink-0`}),F(`market.offline`)]}):null;if(!x&&!O)return A;let j=o?(0,W.jsx)(`button`,{type:`button`,"aria-label":F(`market.reset`),onClick:()=>s(``),className:`-mr-1.5 flex size-7 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-paper-2 hover:text-ink`,children:(0,W.jsx)(T,{className:`size-4`})}):null,re=e=>w(`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-full px-2.5 text-[0.78125rem] transition`,e?`bg-card font-medium text-ink shadow-soft ring-1 ring-border-soft`:`text-ink-3 hover:bg-card/60 hover:text-ink`);return(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`label`,{ref:_,className:`relative mx-auto flex h-10 max-w-md scroll-mt-4 items-center gap-2.5 rounded-full bg-card px-4 shadow-soft ring-1 ring-border-soft transition focus-within:ring-2 focus-within:ring-focus sm:h-11`,children:[S?(0,W.jsx)(D,{className:`size-4 shrink-0 text-ink-3`}):(0,W.jsx)(ee,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`input`,{type:`search`,value:o,onChange:e=>s(e.target.value),placeholder:F(`market.search`),"aria-label":F(`market.search`),className:`min-w-0 flex-1 bg-transparent text-[0.9375rem] outline-none placeholder:text-ink-4 [&::-webkit-search-cancel-button]:hidden`}),j]}),A,y?.level?(0,W.jsx)(kt,{level:y.level}):null,(0,W.jsxs)(`div`,{className:`max-sm:-mx-3 mt-4 flex gap-1 max-sm:overflow-x-auto max-sm:px-3 max-sm:[scrollbar-width:none] sm:flex-wrap sm:justify-center max-sm:[&::-webkit-scrollbar]:hidden`,children:[[{value:``,label:F(`market.all`)},...E].map(e=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":!u&&c.useCase===e.value,onClick:()=>{d(!1),l({...c,useCase:e.value})},className:re(!u&&c.useCase===e.value),children:e.label},e.value)),a?null:(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":u,onClick:()=>d(!u),className:re(u),children:[(0,W.jsx)(H,{className:w(`size-3.5`,u&&`fill-amber text-amber`)}),F(`market.starred`)]})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-1 gap-y-2 sm:mt-6`,children:[u?null:ne.map(e=>(0,W.jsx)(Wt,{name:e.name,value:c[e.key],options:e.options,onChange:t=>l({...c,[e.key]:t})},e.key)),(0,W.jsxs)(`span`,{className:`ml-auto flex items-center gap-3 whitespace-nowrap pl-2 text-[0.8125rem] text-ink-3`,children:[O?(0,W.jsxs)(`button`,{type:`button`,onClick:k,className:`inline-flex items-center gap-1 text-ember-strong underline-offset-2 hover:underline`,children:[(0,W.jsx)(T,{className:`size-3.5 max-sm:size-4`}),(0,W.jsx)(`span`,{className:`max-sm:sr-only`,children:F(`market.resetShort`)})]}):null,O?(0,W.jsx)(`span`,{className:`tabular-nums sm:hidden`,children:F(`market.countOfShort`,{n:y?.total??0,all:x})}):null,(0,W.jsx)(`span`,{className:w(`tabular-nums`,O&&`max-sm:hidden`),children:O?F(`market.countOf`,{n:y?.total??0,all:x}):F(`market.count`,{n:x})})]})]}),b.length?(0,W.jsx)(`div`,{className:`mt-4 flex flex-col gap-4 sm:grid sm:grid-cols-2 lg:grid-cols-3`,children:b.map(e=>(0,W.jsx)(q,{entry:e,onOpen:()=>a?a(e):m(e.id)},e.id))}):(0,W.jsxs)(`div`,{className:`py-10 text-center text-[0.875rem] text-ink-3`,children:[(0,W.jsx)(`p`,{children:F(u?`market.noneStarred`:`market.none`)}),(0,W.jsx)(g,{variant:`ghost`,className:`mt-2`,onClick:k,children:F(`market.reset`)})]}),v.hasNextPage?(0,W.jsx)(`div`,{className:`mt-6 flex justify-center`,children:(0,W.jsx)(g,{variant:`secondary`,busy:v.isFetchingNextPage,onClick:()=>void v.fetchNextPage(),children:F(`market.more`)})}):null,(0,W.jsx)(Q,{id:p,fallback:b.find(e=>e.id===p)??null,onClose:()=>m(null),onUse:e,busy:t})]})}export{L as A,Le as C,Ae as D,z as E,ye as M,Oe as O,ze as S,B as T,Qe as _,Dt as a,H as b,$ as c,Et as d,Tt as f,ut as g,lt as h,Kt as i,I as j,R as k,St as l,bt as m,Xt as n,Lt as o,Ct as p,Jt as r,qt as s,Q as t,xt as u,Xe as v,V as w,Ve as x,Ke as y};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodeEditor-B5hV1IvK.js","assets/rolldown-runtime-hePW80VL.js","assets/jsx-runtime-BNakU3Ej.js","assets/i18n-B3J2ypKu.js","assets/dist-DzdNG7Sf.js","assets/dist-DVpDdhG9.js","assets/markdown-DwdMW7q0.js","assets/dist-BwhPmMDu.js","assets/json-D2GVvTXK.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
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,B as i,Bn as a,Cn as o,Dn as s,En as c,G as l,Gt as u,Hn as d,Jn as f,Jt as p,Kt as m,Lt as h,Mn as g,Mr as _,Sr as v,Un as y,V as b,W as x,Wt as S,Xn as C,Xt as w,Yt as T,Zt as E,_n as D,_t as O,an as k,bn as ee,en as A,gn as te,ir as j,ln as M,m as N,mn as P,on as F,pt as ne,qt as I,rn as L,sn as R,sr as z,tn as B,un as V,v as H,y as U,yn as W,yt as G,z as re}from"./ui-DQX_CQ7c.js";import{E as ie,v as ae,y as oe}from"./Marketplace-DSo6uZF6.js";import{t as K}from"./useMutation-C3XBoSVf.js";import{t as q}from"./preload-helper-DpV6A1kQ.js";import{i as J}from"./volume-2-DIxdTlaA.js";import{b as se,d as ce,f as le,p as ue,r as de,t as fe}from"./theme-Dab079EV.js";import{M as pe,N as me,g as he,x as ge}from"./session-B2LtqeDq.js";import{t as _e}from"./upload-hLkuT3Q6.js";import{K as ve,V as ye,at as be,m as xe,n as Y,q as Se,rt as Ce,s as X}from"./i18n-B3J2ypKu.js";import{A as we,At as Te,C as Ee,Ct as De,D as Oe,E as ke,Gt as Ae,Jt as je,O as Me,S as Ne,T as Pe,a as Fe,i as Ie,k as Le,n as Re,o as ze,r as Be,sn as Ve,w as He,zt as Ue}from"./index-WY5lJ_-h.js";import{t as We}from"./runners-D71NjXtA.js";var Ge={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`}]]};Ge.node;var Ke=C(Ge),qe={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`}]]};qe.node;var Je=C(qe),Ye={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`}]]};Ye.node;var Xe=C(Ye),Ze={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`}]]};Ze.node;var Qe=C(Ze),$e={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`}]]};$e.node;var et=C($e),tt={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`}]]};tt.node;var nt=C(tt),rt={name:`panel-right-close`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]};rt.node;var it=C(rt),at={name:`panel-right-open`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]};at.node;var ot=C(at),st={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};st.node;var ct=C(st),lt={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`}]]};lt.node;var ut=C(lt),dt={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`}]]};dt.node;var ft=C(dt),pt={name:`user`,size:24,node:[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]};pt.node;var mt=C(pt),Z=e(n(),1),Q=e(t(),1);function ht(e){return z({queryKey:[`share-targets`,e,Y],queryFn:()=>l.get(`/api/studio/wizards/${e}/share-targets?lang=${Y}`),enabled:!!e,staleTime:6e4})}var gt=(0,Q.createContext)(null);function _t(e){return e.share?e.share.length?`own`:`off`:`default`}var vt=e=>e.byDefault&&e.usable;function yt(e,t){let n=_t(e),r=e.share??[],i=new Map,a=e=>{let t=i.get(e)??0;return i.set(e,t+1),`${e}#${t}`},o=e=>({key:a(e.id),target:e.id,info:e,index:null,option:null,on:!1,name:e.name});if(n==="default")return{mode:n,rows:t.filter(vt).map(e=>({...o(e),on:!0})),unset:t.filter(e=>e.byDefault&&!e.usable)};let s=r.map((e,n)=>{let r=t.find(t=>t.id===e.target);return{key:a(e.target),target:e.target,info:r,index:n,option:e,on:!0,name:e.label||r?.name||e.target}}),c=new Set(r.map(e=>e.target));return s.push(...t.filter(e=>vt(e)&&!c.has(e.id)).map(o)),{mode:n,rows:s,unset:t.filter(e=>e.byDefault&&!e.usable&&!c.has(e.id))}}function bt(e,t){let n=t.filter(e=>e.on&&e.info?.usable);return{visitors:n.filter(t=>!(e==="default"&&t.info?.agent)),onlyYou:e==="default"?n.filter(e=>e.info?.agent):[],broken:t.filter(e=>e.on&&!e.info?.usable)}}function xt(e){return e.filter(e=>vt(e)&&!e.agent).map(e=>({target:e.id}))}function St(e,t){let n=_t(e);return n===`own`?e.share??[]:n==="default"?xt(t):[]}function Ct(e,t,n,r){let i=St(e,t);return r?[...i,{target:n.target}]:n.index===null?i.filter(e=>e.target!==n.target):i.filter((e,t)=>t!==n.index)}function wt(e,t,n,r){let i=St(e,t),a=n.index??i.findIndex(e=>e.target===n.target);return a===-1?[...i,r]:i.map((e,t)=>t===a?r:e)}function Tt(e,t,n){return[...St(e,t),{target:n}]}function Et(e,t){let n=new Set(e.map(e=>e.target));return t.filter(e=>e.usable&&!e.byDefault&&!n.has(e.id))}function Dt(e,t){let n=e.steps.slice(0,e.steps.indexOf(t));return[...n.flatMap(e=>e.type===`page`?e.fields.filter(e=>e.kind!==`image`&&e.kind!==`file`&&e.kind!==`signature`).map(e=>({ref:e.id,label:e.label})):[]),...n.flatMap(e=>e.type===`agent`&&e.output.format!==`json`?[{ref:`steps.${e.id}`,label:e.title}]:[]),{ref:`brand.name`,label:X(`shareEditor.brandName`)}]}function Ot(e){return new Intl.ListFormat(Y===`en`?`en-GB`:Y,{style:`long`,type:`conjunction`}).format(e)}var kt=(0,Q.lazy)(async()=>{let[{default:e},{markdownParts:t}]=await Promise.all([q(()=>import(`./CodeEditor-B5hV1IvK.js`),__vite__mapDeps([0,1,2,3,4,5])),q(()=>import(`./markdown-DwdMW7q0.js`),__vite__mapDeps([6,4,5,7]))]),n=t();return{default:t=>(0,Z.jsx)(e,{...t,languageParts:n})}}),At=(0,Q.lazy)(async()=>{let[{default:e},{jsonParts:t}]=await Promise.all([q(()=>import(`./CodeEditor-B5hV1IvK.js`),__vite__mapDeps([0,1,2,3,4,5])),q(()=>import(`./json-D2GVvTXK.js`),__vite__mapDeps([8,4,7]))]),n=t();return{default:t=>(0,Z.jsx)(e,{...t,languageParts:n})}});function jt(e){return(0,Z.jsx)(Q.Suspense,{fallback:(0,Z.jsx)(`textarea`,{value:e.value,readOnly:e.readOnly,onChange:t=>e.onChange(t.target.value),"aria-label":e.ariaLabel,placeholder:e.placeholder,className:F(`field-sizing-content block w-full resize-none bg-transparent px-4 py-4 outline-none`,e.language===`json`?`font-mono text-[0.75rem]`:`text-[0.9375rem] leading-[1.65]`,e.className)}),children:e.language===`json`?(0,Z.jsx)(At,{...e}):(0,Z.jsx)(kt,{...e})})}var Mt=(e,t)=>`${e}/${t}`;function Nt(e,t,n){if(e.endsWith(`.localhost`)){let r=n&&URL.canParse(n)?new URL(n).port:``;return`http://${e}${r?`:${r}`:``}/${t}`}return`https://${e}/${t}`}var Pt=e=>e.lang===`en`?`en`:e.form===`sie`?`de-sie`:`de-du`;function Ft(e){return e===`en`?{lang:`en`}:{lang:`de`,form:e===`de-sie`?`sie`:`du`}}function It(e,t,n){let r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)r++;let i=e.length,a=t.length;for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--;let o=[];for(let e=0;e<r;e++)o.push([e,e]);let s=i-r,c=a-r;if(s>0&&c>0){let i=s+c,a=i,l=new Int32Array(2*i+2),u=[],d=!1;for(let o=0;o<=i&&o<=n;o++){u.push(l.slice());for(let n=-o;n<=o;n+=2){let i=n===-o||n!==o&&l[a+n-1]<l[a+n+1]?l[a+n+1]:l[a+n-1]+1,u=i-n;for(;i<s&&u<c&&e[r+i]===t[r+u];)i++,u++;if(l[a+n]=i,i>=s&&u>=c){d=!0;break}}if(d)break}if(!d)return null;let f=[],p=s,m=c;for(let e=u.length-1;e>=0&&(p>0||m>0);e--){let t=u[e],n=p-m,i=n===-e||n!==e&&t[a+n-1]<t[a+n+1]?n+1:n-1,o=e===0?0:t[a+i],s=o-i;for(;p>o&&m>s;)p--,m--,f.push([r+p,r+m]);e>0&&(p=o,m=s)}o.push(...f.reverse())}for(let t=0;t<e.length-i;t++)o.push([i+t,a+t]);return o}var Lt=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Rt=4e3;function zt(e,t,n){if(t===n||n===e)return{text:t,clean:!0,conflicts:0};if(t===e)return{text:n,clean:!0,conflicts:0};let r=e.split(`
|
|
3
|
-
`),i=t.split(`
|
|
4
|
-
`),a=n.split(`
|
|
5
|
-
`),o=It(r,i,Rt),s=It(r,a,Rt);if(!o||!s)return{text:t,clean:!1,conflicts:1};let c=new Map(o.map(([e,t])=>[e,t])),l=new Map(s.map(([e,t])=>[e,t])),u=[],d=0,f=0,p=0,m=0,h=(e,t,n)=>{let o=r.slice(f,e),s=i.slice(p,t),c=a.slice(m,n);Lt(s,o)?u.push(...c):(Lt(c,o)||Lt(s,c)||d++,u.push(...s))};for(let e=0;e<r.length;e++){let t=c.get(e),n=l.get(e);t===void 0||n===void 0||t<p||n<m||(h(e,t,n),u.push(r[e]),f=e+1,p=t+1,m=n+1)}return h(r.length,i.length,a.length),{text:u.join(`
|
|
6
|
-
`),clean:d===0,conflicts:d}}var Bt=class extends Error{theirs;constructor(e){super(`changed elsewhere`),this.theirs=e}},Vt=(e,t)=>Date.parse(e)>Date.parse(t);function Ht(e){let t=(0,Q.useRef)(e);t.current=e;let n=(0,Q.useRef)(e.initial),r=(0,Q.useRef)(null),i=(0,Q.useRef)(null),[a,o]=(0,Q.useState)(null),s=(0,Q.useCallback)(e=>{n.current=e,t.current.surface.apply(e.value)},[]);(0,Q.useEffect)(()=>we(e.kind,e.id,e=>{let a=e.view===void 0?null:t.current.fromView(e.view);a&&Vt(a.at,n.current.at)&&(i.current?i.current=a:t.current.surface.hasUnsavedEdits()?r.current=a:s(a))}),[e.kind,e.id,s]),(0,Q.useEffect)(()=>{if(a!==`merged`)return;let e=setTimeout(()=>o(null),6e3);return()=>clearTimeout(e)},[a]);let c=(0,Q.useCallback)(async(e,a=1)=>{let s=t.current;if(i.current)return;let l=e,u=n.current.at,d=r.current;if(r.current=null,d){let t=s.merge(n.current.value,e,d.value);if(!t.clean){i.current=d,o(`conflict`);return}l=t.value,u=d.at,s.same(l,e)||s.surface.apply(l),o(`merged`)}try{let e=await s.send(l,u);n.current={value:l,at:e}}catch(e){if(e instanceof Bt&&a>0)return r.current=e.theirs,c(l,a-1);throw e}},[]);return{save:e=>c(e),notice:a,keepMine:(0,Q.useCallback)(()=>{let e=i.current;i.current=null,o(null),e&&(n.current={value:n.current.value,at:e.at}),t.current.surface.saveNow()},[]),takeTheirs:(0,Q.useCallback)(()=>{let e=i.current;i.current=null,o(null),e&&s(e)},[s])}}var Ut={choice:ut,date:Ke,number:Xe,text:ae,boolean:ft},Wt=e=>x.knowledge(e);function Gt(e){return e===1?X(`know.item`):X(`know.items`,{n:e})}function $(e,t){if(e.type===`boolean`||typeof t==`boolean`)return X(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(Y,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(Y)}${e.unit?` ${e.unit}`:``}`:String(t)}function Kt(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=>$(e,t)).join(`, `)]:[]}).join(` · `)}function qt({trigger:e,open:t,onOpen:n,children:r}){let i=(0,Q.useRef)(null);return(0,Q.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,Z.jsxs)(`div`,{ref:i,className:`relative inline-flex`,children:[e,t?(0,Z.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 Jt({category:e,current:t,onSave:n}){let[i,a]=(0,Q.useState)(t[0]===void 0?``:String(t[0]));if(e.type===`choice`){let o=t.map(String);return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[e.values.length?(0,Z.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,Z.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),i.trim()&&n(e.multiple?[...o,i.trim()]:[i.trim()])},children:[(0,Z.jsx)(w,{"data-autofocus":!0,value:o.includes(i)?``:i,placeholder:X(`know.addValue`),onChange:e=>a(e.target.value),className:`h-9`}),(0,Z.jsx)(T,{label:X(`know.addValue`),type:`submit`,children:(0,Z.jsx)(W,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,Z.jsx)(r,{value:t[0]===!0?X(`know.yes`):t[0]===!1?X(`know.no`):``,options:[X(`know.yes`),X(`know.no`)],onChange:e=>n([e===X(`know.yes`)])}):(0,Z.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(i.trim()?[e.type===`number`?Number(i.replace(`,`,`.`)):i.trim()]:[])},children:[(0,Z.jsx)(w,{"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,Z.jsx)(S,{type:`submit`,size:`sm`,children:`OK`})]})}function Yt({projectId:e,itemKey:t,has:n,categories:r,readOnly:i}){let a=_(),[o,s]=(0,Q.useState)(null),[c,u]=(0,Q.useState)(n);(0,Q.useEffect)(()=>u(n),[n]);let d=K({mutationFn:({categoryId:n,next:r})=>l.put(`/api/studio/projects/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>a.invalidateQueries({queryKey:Wt(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}),s(null)},m=f.filter(e=>c.some(t=>t.categoryId===e.id)),h=f.filter(e=>!c.some(t=>t.categoryId===e.id));return f.length?(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[m.map(e=>{let t=c.find(t=>t.categoryId===e.id),n=Ut[e.type],r=(0,Z.jsxs)(`button`,{type:`button`,disabled:i,title:`${e.name} · ${X(`know.by.${t.by}`)}`,onClick:()=>s(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,Z.jsx)(n,{className:`size-3.5 text-ink-3`}),(0,Z.jsx)(`span`,{className:`text-ink-3`,children:e.name}),(0,Z.jsx)(`span`,{className:`font-medium`,children:t.values.map(t=>$(e,t)).join(`, `)})]},e.id);return i?(0,Z.jsx)(`span`,{children:r},e.id):(0,Z.jsxs)(qt,{trigger:r,open:o===e.id,onOpen:t=>s(t?e.id:null),children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:e.name}),(0,Z.jsx)(T,{label:X(`know.remove`),onClick:()=>p(e,[]),className:`size-7`,children:(0,Z.jsx)(R,{className:`size-3.5`})})]}),(0,Z.jsx)(Jt,{category:e,current:t.values,onSave:t=>p(e,t)})]},e.id)}),i||!h.length?null:(0,Z.jsx)(qt,{open:o===`+`,onOpen:e=>s(e?`+`:null),trigger:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>s(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,Z.jsx)(W,{className:`size-3.5`}),` `,X(`know.category`)]}),children:(0,Z.jsx)(Xt,{categories:h,onSave:p})})]}):null}function Xt({categories:e,onSave:t}){let[n,r]=(0,Q.useState)(e[0]?.id??``),i=e.find(e=>e.id===n);return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,Z.jsx)(A,{value:n,onChange:r,options:e.map(e=>({value:e.id,label:e.name}))}),i?(0,Z.jsx)(Jt,{category:i,current:[],onSave:e=>t(i,e)},i.id):null]})}function Zt({projectId:e,open:t,onClose:n,onMade:r}){let i=_(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(`choice`),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(``),x=K({mutationFn:()=>l.post(`/api/studio/projects/${e}/categories`,{name:a.trim(),type:s,unit:s===`number`&&u.trim()||null,multiple:s===`choice`&&f,ordered:s===`choice`&&m,hint:y.trim()||null,values:s===`choice`?g.split(`
|
|
7
|
-
`).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await i.invalidateQueries({queryKey:Wt(e)}),o(``),v(``),b(``),r(t)}});return(0,Z.jsx)(I,{open:t,onClose:n,title:X(`know.newCategory`),children:(0,Z.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.trim()&&x.mutate()},children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`know.name`)}),(0,Z.jsx)(w,{"data-autofocus":!0,value:a,maxLength:80,onChange:e=>o(e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`know.type`)}),(0,Z.jsx)(A,{value:s,onChange:e=>c(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:X(`know.type.${e}`)}))})]}),s===`number`?(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{hint:X(`know.unitHint`),children:X(`know.unit`)}),(0,Z.jsx)(w,{value:u,maxLength:20,onChange:e=>d(e.target.value)})]}):null,s===`choice`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{hint:X(`know.valuesHint`),children:X(`know.values`)}),(0,Z.jsx)(k,{minRows:3,value:g,onChange:e=>v(e.target.value)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[X(`know.multiple`),(0,Z.jsx)(L,{checked:f,onChange:p})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[X(`know.ordered`),(0,Z.jsx)(L,{checked:m,onChange:h})]})]}):null,(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{hint:X(`know.hintFieldHint`),children:X(`know.hintField`)}),(0,Z.jsx)(w,{value:y,maxLength:120,onChange:e=>b(e.target.value)})]}),x.error?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:x.error.message}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(S,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Z.jsx)(S,{type:`submit`,busy:x.isPending,disabled:!a.trim(),children:X(`know.create`)})]})]})})}function Qt({projectId:e,category:t,readOnly:n,onOpen:r,onGone:i}){let a=_(),o=()=>a.invalidateQueries({queryKey:Wt(e)}),[s,c]=(0,Q.useState)(``),d=K({mutationFn:e=>e(),onSuccess:o}),f=Ut[t.type],h=new Map(t.values.map(e=>[e.id,e]));return(0,Z.jsxs)(U,{title:t.name,hint:[X(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,Z.jsx)(T,{label:X(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(X(`know.confirmCategory`,{name:t.name}))&&d.mutate(async()=>{await l.del(`/api/studio/categories/${t.id}`),i()}),children:(0,Z.jsx)(V,{className:`size-4`})}),children:[t.proposed&&!n?(0,Z.jsxs)(u,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,Z.jsx)(m,{tone:`ember`,children:X(`know.proposed`)}),(0,Z.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:X(`know.proposedHint`)}),(0,Z.jsx)(S,{size:`sm`,onClick:()=>d.mutate(()=>l.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:X(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=h.get(e),i=h.get(t);if(!(r&&i))return null;let[a,o]=r.count<i.count?[r,i]:[i,r];return(0,Z.jsxs)(u,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,Z.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:X(`know.alike`,{a:a.value,b:o.value})}),n?null:(0,Z.jsx)(S,{size:`sm`,variant:`secondary`,busy:d.isPending,onClick:()=>d.mutate(()=>l.post(`/api/studio/values/${a.id}/merge`,{into:o.id})),children:X(`know.merge`)})]},`${e}:${t}`)}),(0,Z.jsxs)(u,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,Z.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,Z.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,Z.jsx)(m,{children:X(`know.summary`)}):null,(0,Z.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:Gt(e.count)})]},e.id)):(0,Z.jsx)(p,{children:X(`know.empty`)}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,Z.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,Z.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?X(`know.range`,{min:$(t,t.range.min),max:$(t,t.range.max)}):X(`know.unset`)}),(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:Gt(t.count)})]}),t.type===`choice`&&!n?(0,Z.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=s.trim();n&&(c(``),d.mutate(()=>l.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,Z.jsx)(w,{value:s,placeholder:X(`know.addValue`),onChange:e=>c(e.target.value),className:`h-9`}),(0,Z.jsx)(T,{label:X(`know.addValue`),type:`submit`,children:(0,Z.jsx)(W,{className:`size-4`})})]}):null]}),d.error?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null]})}function $t(e){return z({queryKey:[`knowledge-value`,e],queryFn:()=>l.get(`/api/studio/values/${e}`),enabled:!!e})}function en({value:e,readOnly:t,children:n}){let r=_(),i=K({mutationFn:()=>l.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>r.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,Z.jsx)(U,{title:X(`know.summary`),hint:X(`know.summaryHint`),plain:!0,action:t?null:(0,Z.jsxs)(S,{variant:`secondary`,size:`sm`,busy:i.isPending,onClick:()=>i.mutate(),children:[e.summary?(0,Z.jsx)(D,{className:`size-4`}):null,e.summary?X(`know.summaryAgain`):X(`know.summaryWrite`)]}),children:(0,Z.jsxs)(u,{className:`p-4 sm:p-5`,children:[i.isPending?(0,Z.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,Z.jsx)(B,{})}):e.summary?(0,Z.jsx)(G,{text:e.summary,className:`text-[0.875rem]`}):(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`know.summaryEmpty`)}),i.error?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:i.error.message}):null]})}),(0,Z.jsx)(U,{title:X(`know.toc`),plain:!0,children:n})]})}function tn(e){return z({queryKey:x.knowledge(e),queryFn:()=>l.get(`/api/studio/projects/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function nn(e){return e.kind===`table`?e.format===`faq`?et:oe:e.kind===`file`?o:e.children?Je:g}function rn({item:e,categories:t,onOpen:n}){let r=nn(e),i=[Kt(t,e.categories),e.children?e.children===1?X(`know.oneSub`):X(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?X(`know.row`):X(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,Z.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,Z.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,Z.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,Z.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,Z.jsx)(B,{className:`size-3`}),` `,X(`know.reading`)]}):e.review?(0,Z.jsx)(m,{tone:`warn`,title:e.review,children:X(`know.review`)}):null]})}function an({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:a,file:s,readOnly:c,onReviewed:l}){let u=tn(e),d=[r?X(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[u.data?(0,Z.jsx)(Yt,{projectId:e,itemKey:t,has:n,categories:u.data.categories,readOnly:c}):null,d.length||s||a?(0,Z.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,Z.jsx)(`span`,{children:e},e)),s?(0,Z.jsxs)(`a`,{href:re(e,s.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,Z.jsx)(o,{className:`size-3.5`}),` `,X(`know.original`),`: `,s.name]}):null,a?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Z.jsx)(m,{tone:`warn`,children:X(`know.review`)}),(0,Z.jsx)(`span`,{children:a}),c?null:(0,Z.jsx)(`button`,{type:`button`,onClick:l,className:`underline hover:text-ink`,children:X(`know.reviewed`)})]}):null]}):null]})}function on(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 sn({projectId:e,category:t,categories:n,onOpen:r}){let i=z({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>l.get(`/api/studio/categories/${t.id}/items`)});if(!i.data)return i.isLoading?(0,Z.jsx)(B,{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??``),Y)}),s=t.type===`number`?on(o.map(a).filter(e=>typeof e==`number`)):[],c=new Intl.NumberFormat(Y,{notation:`compact`,maximumFractionDigits:1}),d=t.unit?` ${t.unit}`:``,f=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(Y,{month:`long`,year:`numeric`}):r?X(`know.range`,{min:`${c.format(r.lo)}${d}`,max:`${c.format(r.hi)}${d}`}):$(t,n);f.set(i,[...f.get(i)??[],e])}return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...f].map(([e,t])=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,Z.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,Z.jsx)(u,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,Z.jsx)(rn,{item:e,categories:n,onOpen:r},e.key))})]},e)),i.data.rows.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>r(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:X(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function cn(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 ln(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return X(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${X(`know.contains`)} ${t.contains}`:[n===void 0?``:`${X(`know.minimum`)} ${$(e,n)}`,r===void 0?``:`${X(`know.maximum`)} ${$(e,r)}`].filter(Boolean).join(` `)}return String(t)}function un({category:e,value:t,onChange:n}){let[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(null);(0,Q.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=Ut[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,Z.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:F(`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,Z.jsx)(s,{className:`size-3.5 text-ink-3`}),e.name,t===void 0?null:(0,Z.jsxs)(`span`,{className:`font-medium`,children:[`: `,ln(e,t)]}),(0,Z.jsx)(d,{className:`size-3.5 text-ink-3`})]}),i?(0,Z.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,Z.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,Z.jsx)(r,{value:t===!0?X(`know.yes`):t===!1?X(`know.no`):``,options:[X(`know.yes`),X(`know.no`)],onChange:e=>n(e===X(`know.yes`))}):e.type===`text`?(0,Z.jsx)(w,{"data-autofocus":!0,value:c.contains??``,placeholder:X(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:`h-9`}):(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(n===0?`know.minimum`:`know.maximum`)}),(0,Z.jsx)(w,{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,Z.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),a(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:X(`know.clear`)})]}):null]})}function dn({found:e,onOpen:t}){return e.hits.length?(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:e.checked?X(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):X(`know.searchUnchecked`,{hits:e.hits.length})}),e.hits.map(e=>{let n=e.open;return(0,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,Z.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,Z.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,Z.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(Y,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,Z.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:X(`know.searchNone`)})}function fn({kind:e,projectId:t,onClose:n,onMade:r}){let i=_(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),u=K({mutationFn:()=>l.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:x.knowledge(t)}),r(`${e===`table`?`t`:`p`}:${n}`),o(``),c(!1)}});return(0,Z.jsx)(I,{open:e!==null,onClose:n,title:X(e===`table`?`know.newTable`:`know.newPage`),children:(0,Z.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.trim()&&u.mutate()},children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`data.title`)}),(0,Z.jsx)(w,{"data-autofocus":!0,value:a,maxLength:120,onChange:e=>o(e.target.value)})]}),e===`table`?(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[X(`know.asFaq`),(0,Z.jsx)(L,{checked:s,onChange:c})]}):null,u.error?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u.error.message}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(S,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Z.jsx)(S,{type:`submit`,busy:u.isPending,disabled:!a.trim(),children:X(`know.create`)})]})]})})}function pn({projectId:e,data:t,readOnly:n,onOpen:r}){let i=_(),a=b(e,n),[o,s]=(0,Q.useState)({}),[c,d]=(0,Q.useState)(``),[f,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)(!1),[y,C]=(0,Q.useState)(null),w=t.categories.filter(e=>!e.proposed&&e.count>0),T=t.categories.filter(e=>e.proposed),E=t.items.filter(e=>Object.entries(o).every(([n,r])=>{let i=t.categories.find(e=>e.name===n),a=e.categories.find(e=>e.categoryId===i?.id);return i&&a?cn(i,a.values,r):!1})),D=async()=>{if(!c.trim()){h(null);return}v(!0);try{h(await l.post(`/api/studio/projects/${e}/search`,{query:c,...Object.keys(o).length?{where:o}:{}}))}catch{h({hits:[],candidates:0,checked:!1,filtered:null})}finally{v(!1)}},O=K({mutationFn:({id:e,keep:t})=>t?l.patch(`/api/studio/categories/${e}`,{proposed:!1}):l.del(`/api/studio/categories/${e}`),onSuccess:()=>i.invalidateQueries({queryKey:x.knowledge(e)})});return(0,Z.jsxs)(U,{title:X(`know.title`),hint:X(`know.hint`),plain:!0,action:n?null:(0,Z.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,Z.jsxs)(S,{variant:`secondary`,size:`sm`,onClick:()=>C(`page`),children:[(0,Z.jsx)(W,{className:`size-4`}),` `,X(`know.page`)]}),(0,Z.jsxs)(S,{variant:`secondary`,size:`sm`,onClick:()=>C(`table`),children:[(0,Z.jsx)(W,{className:`size-4`}),` `,X(`know.table`)]}),(0,Z.jsxs)(S,{variant:`secondary`,size:`sm`,onClick:()=>C(`category`),children:[(0,Z.jsx)(W,{className:`size-4`}),` `,X(`know.category`)]})]}),children:[T.length&&!n?(0,Z.jsx)(u,{className:`flex flex-col gap-2 p-4`,children:T.map(e=>{let t=Ut[e.type];return(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,Z.jsx)(m,{tone:`ember`,children:X(`know.proposed`)}),(0,Z.jsx)(t,{className:`size-4 text-ink-3`}),(0,Z.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[X(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,Z.jsx)(S,{size:`sm`,variant:`ghost`,onClick:()=>O.mutate({id:e.id,keep:!1}),children:X(`know.dismiss`)}),(0,Z.jsx)(S,{size:`sm`,onClick:()=>O.mutate({id:e.id,keep:!0}),children:X(`know.accept`)})]},e.id)})}):null,t.items.length?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(H,{value:c,placeholder:X(`know.search`),busy:g,onEnter:()=>void D(),onChange:e=>{d(e),e.trim()||h(null)}}),w.length?(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[w.map(e=>(0,Z.jsx)(un,{category:e,value:o[e.name],onChange:t=>{h(null),s(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),Object.keys(o).length?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>s({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:X(`know.clear`)}):null]}):null]}):null,(0,Z.jsx)(u,{className:`flex flex-col p-1.5`,children:f?(0,Z.jsx)(dn,{found:f,onOpen:r}):E.length?E.map(e=>(0,Z.jsx)(rn,{item:e,categories:t.categories,onOpen:r},e.key)):(0,Z.jsx)(p,{children:X(`know.empty`)})}),n?null:(0,Z.jsxs)(N,{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:x.knowledge(e)})},className:`h-14 w-full`,children:[a.busy?(0,Z.jsx)(B,{className:`size-4`}):(0,Z.jsx)(_e,{className:`size-4`}),X(`know.drop`),` `,(0,Z.jsx)(`span`,{className:`underline`,children:X(`know.pick`)})]}),a.error?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:a.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,Z.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:X(`know.keywordsOnly`),t.checked?``:X(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,Z.jsx)(fn,{kind:y===`page`||y===`table`?y:null,projectId:e,onClose:()=>C(null),onMade:e=>{C(null),r(e)}}),(0,Z.jsx)(Zt,{projectId:e,open:y===`category`,onClose:()=>C(null),onMade:e=>{C(null),r(`c:${e}`)}})]})}function mn({page:e,onGone:t,onOpen:n}){let r=_(),[o,s]=(0,Q.useState)(e.title),[c,d]=(0,Q.useState)(e.markdown),[f,p]=(0,Q.useState)(e.markdown?`read`:`write`),v=e.knowledge,b=he().data?.user.id,[C,w]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!C)return;let e=setTimeout(()=>w(!1),1e4);return()=>clearTimeout(e)},[C,c,o]),Le(`page`,e.id,{state:C?`editing`:`viewing`,place:E?.id,placeLabel:E?.label});let O=Pe(`page`,e.id,b,C?E?.id:null),k=ke(`page`,e.id,b),ee=k.filter(e=>e.place?.startsWith(`h:`)&&e.placeLabel).map(e=>({heading:e.placeLabel??``,color:Ee(e.who),title:He(e)})),A=(e,t)=>{let n=gn(e,t);D(e=>e?.id===n?.id?e:n)},te=async()=>{await r.invalidateQueries({queryKey:x.spaceData(e.projectId)}),await r.invalidateQueries({queryKey:x.knowledge(e.projectId)})},j=i({title:o.trim()||e.title,markdown:c},e=>M.save(e)),M=Ht({kind:`page`,id:e.id,initial:{value:{title:e.title,markdown:e.markdown},at:e.updatedAt},fromView:e=>{let t=e;return{value:{title:t.title,markdown:t.markdown},at:t.updatedAt}},merge:(e,t,n)=>{let r=zt(e.markdown,t.markdown,n.markdown),i=t.title===n.title||n.title===e.title?t.title:t.title===e.title?n.title:null;return{value:{title:i??t.title,markdown:r.text},clean:r.clean&&i!==null}},same:(e,t)=>e.title===t.title&&e.markdown===t.markdown,surface:{apply:t=>{s(t.title),d(t.markdown),j.markSaved(t),r.setQueryData(x.page(e.id),e=>e&&{...e,...t})},hasUnsavedEdits:()=>j.pending(),saveNow:()=>j.saveNow()},send:async(t,n)=>{try{let{updatedAt:i}=await l.patch(`/api/studio/pages/${e.id}`,{...t,baseUpdatedAt:n});return r.setQueryData(x.page(e.id),e=>e&&{...e,...t,updatedAt:i}),t.title!==e.title&&await te(),i}catch(e){let t=e instanceof h&&e.status===409?e.body?.page:null;throw t?new Bt({value:{title:t.title,markdown:t.markdown},at:t.updatedAt}):e}}}),N=K({mutationFn:()=>l.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await te(),t()}}),P=K({mutationFn:()=>l.post(`/api/studio/projects/${e.projectId}/pages`,{title:X(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await te(),n?.(`p:${e}`)}}),ne=K({mutationFn:()=>l.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>r.invalidateQueries({queryKey:x.page(e.id)})}),I=async t=>{let r=n?await yn(e.projectId,t):null;r&&n?.(r)},L=e=>{let t=e.target.closest(`a`)?.getAttribute(`href`);t&&_n.test(t)&&n&&(e.preventDefault(),I(t))},R=(tn(e.projectId).data?.items??[]).filter(t=>t.id!==e.id).map(e=>({title:e.title,path:e.path,kind:X(vn[e.kind])})),z=e.readOnly,H=v?.file&&(v.file.mime===`application/pdf`||v.file.mime.startsWith(`image/`))?v.file:null,U=(e,t)=>(0,Z.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>p(e),className:F(`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,Z.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[v?.parents.length&&n?(0,Z.jsx)(`nav`,{className:`-mb-1.5 flex flex-wrap items-center gap-1 px-1 text-[0.8125rem] text-ink-3`,children:v.parents.map(e=>(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`hover:text-ink`,children:e.title}),(0,Z.jsx)(a,{className:`size-3.5`})]},e.id))}):null,(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Z.jsx)(`input`,{value:o,disabled:z,maxLength:200,onChange:e=>{s(e.target.value),w(!0)},"aria-label":X(`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`}),M.notice===`merged`?(0,Z.jsx)(m,{icon:(0,Z.jsx)(Ve,{className:`size-3`}),children:k[0]?X(`editor.mergedWith`,{name:k[0].name}):X(`editor.merged`)}):null,(0,Z.jsx)(Ne,{kind:`page`,item:e.id,me:b}),M.notice===`conflict`?null:j.state===`saving`?(0,Z.jsx)(B,{className:`size-3.5 text-ink-3`}):j.state===`saved`?(0,Z.jsx)(y,{className:`size-4 text-moss`,"aria-label":X(`settings.saved`)}):null,z?null:(0,Z.jsx)(T,{label:X(`data.deletePage`),onClick:()=>confirm(X(`data.confirmDelete`,{title:e.title}))&&N.mutate(),className:`hover:text-rose`,children:(0,Z.jsx)(V,{className:`size-4`})})]}),O&&M.notice!==`conflict`?(0,Z.jsx)(`p`,{className:`-mt-1 px-1 text-[0.8125rem] text-ink-3`,children:X(`presence.alsoHere`,{name:O.name})}):null,M.notice===`conflict`?(0,Z.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-2 rounded-lg bg-paper-2 px-3 py-2 text-[0.8125rem]`,children:[(0,Z.jsx)(Ve,{className:`size-4 shrink-0 text-ink-3`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:X(`data.changedElsewhere`)}),(0,Z.jsx)(S,{size:`sm`,variant:`ghost`,onClick:M.takeTheirs,children:X(`data.takeTheirs`)}),(0,Z.jsx)(S,{size:`sm`,onClick:M.keepMine,children:X(`data.keepMine`)})]}):null,v?(0,Z.jsx)(an,{projectId:e.projectId,itemKey:`p:${e.id}`,has:v.categories,originLabel:v.originLabel,kept:v.kept,review:v.review,file:H?null:v.file,readOnly:z,onReviewed:()=>ne.mutate()}):null,(0,Z.jsxs)(u,{className:`flex flex-col`,children:[z&&!H?null:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[z?null:U(`write`,X(`data.write`)),U(`read`,X(`data.preview`)),H?U(`original`,X(`know.original`)):null,(0,Z.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:f===`original`&&H?H.name:X(`data.markdownHint`)})]}),f===`original`&&H?H.mime===`application/pdf`?(0,Z.jsx)(`iframe`,{src:re(e.projectId,H.id),title:H.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,Z.jsx)(`img`,{src:re(e.projectId,H.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):f===`write`&&!z?(0,Z.jsx)(jt,{value:c,onChange:e=>{d(e),w(!0)},onCaret:A,marks:ee,links:R,onLink:e=>void I(e),language:`markdown`,ariaLabel:e.title,placeholder:X(`data.pageEmpty`),className:`min-h-[50vh] [&_.cm-editor]:min-h-[50vh] sm:[&_.cm-content]:py-5 sm:[&_.cm-line]:px-5`}):(0,Z.jsx)(`div`,{className:`min-h-40 p-4 sm:p-5`,onClick:L,children:c.trim()?(0,Z.jsx)(G,{text:c}):(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`data.pageEmpty`)})})]}),j.state===`error`&&j.error?(0,Z.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:j.error}):null,v&&n&&(v.children.length||!z)?(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,Z.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:v.children.length?X(`know.subPages`):null}),z?null:(0,Z.jsxs)(S,{variant:`ghost`,size:`sm`,busy:P.isPending,onClick:()=>P.mutate(),children:[(0,Z.jsx)(W,{className:`size-4`}),` `,X(`know.addSub`)]})]}),v.children.length?(0,Z.jsx)(u,{className:`flex flex-col p-1.5`,children:v.children.map(e=>(0,Z.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,Z.jsx)(g,{className:`size-4 shrink-0 text-ink-3`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title})]},e.id))}):null]}):null]})}function hn({pageId:e,onGone:t,onOpen:n}){let r=z({queryKey:x.page(e),queryFn:()=>l.get(`/api/studio/pages/${e}`),refetchOnWindowFocus:!1});return r.data?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(De,{kind:`page`,item:e}),(0,Z.jsx)(mn,{page:r.data,onGone:t,onOpen:n},r.data.id)]}):r.isError?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:r.error.message}):null}function gn(e,t){let n=e.slice(0,t).split(`
|
|
8
|
-
`);for(let e=n.length-1;e>=0;e--){let t=/^#{1,6}\s+(.+?)\s*#*$/.exec(n[e]??``);if(t?.[1])return{id:`h:${t[1].toLowerCase()}`,label:t[1]}}return null}var _n=/^(pages|tables|files)\//,vn={page:`know.kind.page`,table:`know.kind.table`,file:`know.kind.file`};async function yn(e,t){if(!_n.test(t))return null;let n=await l.get(`/api/studio/projects/${e}/resolve?path=${encodeURIComponent(t)}`).catch(()=>null);return n?`${n.kind[0]}:${n.id}`:null}function bn(e){return z({queryKey:x.spaceData(e),queryFn:()=>l.get(`/api/studio/projects/${e}/data`),enabled:!!e})}function xn(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:X(`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 Sn={table:oe,page:g};function Cn({kind:e,projectId:t,data:n,onClose:r,onMade:i}){let a=_(),[o,s]=(0,Q.useState)(``),[c,u]=(0,Q.useState)(``),d=K({mutationFn:()=>l.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:o.trim(),wizardId:c||null}),onSuccess:async({id:n})=>{await a.invalidateQueries({queryKey:x.spaceData(t)}),i(`${e===`table`?`t`:`p`}:${n}`),s(``),u(``)}});return(0,Z.jsx)(I,{open:e!==null,onClose:r,title:X(e===`table`?`data.newTable`:`data.newPage`),children:(0,Z.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&d.mutate()},children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`data.title`)}),(0,Z.jsx)(w,{"data-autofocus":!0,value:o,maxLength:120,onChange:e=>s(e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`data.owner`)}),(0,Z.jsx)(A,{value:c,onChange:u,options:[{value:``,label:X(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),d.error?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(S,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Z.jsx)(S,{type:`submit`,busy:d.isPending,disabled:!o.trim(),children:X(`data.create`)})]})]})})}function wn({projectId:e,data:t,readOnly:n,onOpen:r}){let[i,a]=(0,Q.useState)(null);Te(n?null:{icon:W,label:X(`data.newTable`),run:()=>a(`table`)});let o=xn(t),s=new Map([...t.tables.map(e=>[`t:${e.id}`,e.updatedAt]),...t.pages.map(e=>[`p:${e.id}`,e.updatedAt])]),c=new Intl.DateTimeFormat(Y,{dateStyle:`medium`});return(0,Z.jsxs)(U,{title:X(`space.data`),hint:X(`data.hint`),plain:!0,action:n?null:(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(S,{variant:`secondary`,size:`sm`,onClick:()=>a(`table`),children:[(0,Z.jsx)(W,{className:`size-4`}),` `,X(`data.table`)]}),(0,Z.jsxs)(S,{variant:`secondary`,size:`sm`,onClick:()=>a(`page`),children:[(0,Z.jsx)(W,{className:`size-4`}),` `,X(`data.page`)]})]}),children:[o.length?(0,Z.jsx)(`div`,{className:`flex flex-col gap-5`,children:o.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Z.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e.label}),(0,Z.jsx)(u,{className:`flex flex-col p-1.5`,children:e.items.map(e=>{let t=Sn[e.kind];return(0,Z.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,Z.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,Z.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:[e.kind===`table`?`${X(`data.rows`,{n:e.rows??0})} · `:``,c.format(new Date(s.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,Z.jsx)(u,{children:(0,Z.jsx)(p,{children:X(`data.empty`)})}),(0,Z.jsx)(Cn,{kind:i,projectId:e,data:t,onClose:()=>a(null),onMade:e=>{a(null),r(e)}})]})}function Tn(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 En={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},Dn=[`text`,`number`,`date`,`duration`,`select`,`boolean`];function On(e,t){if(t==null)return``;if(e.type===`duration`&&typeof t==`number`)return String(t/En[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)}var kn=`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 An({column:e,value:t,readOnly:n,invalid:r,onSave:i}){let a=On(e,t),[o,s]=(0,Q.useState)(a),c=(0,Q.useRef)(a);(0,Q.useEffect)(()=>{s(e=>e===c.current?a:e),c.current=a},[a]);let l=(t=o)=>{t!==a&&i(be(e,t))};if(e.type===`boolean`)return(0,Z.jsx)(`div`,{className:`px-2 py-1.5`,children:(0,Z.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,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-2 py-1`,children:[r.map(e=>(0,Z.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,Z.jsx)(`button`,{type:`button`,"aria-label":X(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,Z.jsx)(R,{className:`size-3`})})]},e)),n?null:(0,Z.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,Z.jsx)(`option`,{value:``,children:`+`}),e.format.options.filter(e=>!r.includes(e.id)).map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})}if(e.type===`select`)return(0,Z.jsxs)(`select`,{value:typeof t==`string`?t:``,disabled:n,onChange:e=>i(e.target.value||null),"aria-label":e.name,className:kn,children:[(0,Z.jsx)(`option`,{value:``}),e.format.options.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.label},e.id))]});if(e.type===`text`&&e.format?.style&&e.format.style!==`single`)return(0,Z.jsx)(`textarea`,{value:o,rows:1,disabled:n,onChange:e=>s(e.target.value),onBlur:()=>l(),"aria-label":e.name,className:F(kn,`field-sizing-content max-h-40 resize-none`)});let u=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,Z.jsx)(`input`,{type:u,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:o,disabled:n,onChange:t=>{s(t.target.value),e.type===`date`&&l(t.target.value)},onBlur:()=>e.type!==`date`&&l(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&s(a)},"aria-label":e.name,className:F(kn,(e.type===`number`||e.type===`duration`)&&`text-right tabular-nums`,r&&`ring-1 ring-rose`)})}function jn(e){return e.type===`number`&&e.format.style===`currency`?e.format.currency??null:e.type===`number`&&e.format.style===`percent`?`%`:e.type===`duration`?X(`data.unit.${e.format.inputUnit}`):null}function Mn(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(`
|
|
9
|
-
`):``,multiple:e?.type===`select`&&!!e.format.multiple}}function Nn(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(`
|
|
10
|
-
`).map(e=>e.trim()).filter(Boolean).map(e=>{let n=t.find(t=>t.label===e)?.id??Tn(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 Pn({open:e,column:t,columns:n,onClose:r,onSave:i}){let[a,o]=(0,Q.useState)(()=>Mn(t)),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{e&&(o(Mn(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??Tn(a.name,n.map(e=>e.id)),r=Nn(a,e,t);return f(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,Z.jsx)(I,{open:e,onClose:r,title:t?t.name:X(`data.newColumn`),children:(0,Z.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.name.trim()&&p()},children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`data.columnName`)}),(0,Z.jsx)(w,{"data-autofocus":!0,value:a.name,maxLength:128,onChange:e=>d({name:e.target.value})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`data.columnType`)}),(0,Z.jsx)(A,{value:a.type,onChange:e=>d({type:e}),options:Dn.map(e=>({value:e,label:X(`data.type.${e}`)}))})]})]}),a.type===`text`?(0,Z.jsx)(A,{value:a.textStyle,onChange:e=>d({textStyle:e}),options:[{value:`single`,label:X(`data.text.single`)},{value:`multiline`,label:X(`data.text.multiline`)}]}):null,a.type===`number`?(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsx)(A,{value:a.numberStyle,onChange:e=>d({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:X(`data.number.${e}`)}))}),a.numberStyle===`currency`?(0,Z.jsx)(w,{value:a.currency,maxLength:3,"aria-label":X(`data.currency`),placeholder:`EUR`,onChange:e=>d({currency:e.target.value})}):null]}):null,a.type===`date`?(0,Z.jsx)(A,{value:a.dateKind,onChange:e=>d({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:X(`data.date.${e}`)}))}):null,a.type===`duration`?(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`data.unit`)}),(0,Z.jsx)(A,{value:a.unit,onChange:e=>d({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:X(`data.unit.${e}`)}))})]}):null,a.type===`select`?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(E,{children:X(`data.options`)}),(0,Z.jsx)(k,{minRows:3,value:a.options,onChange:e=>d({options:e.target.value})})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,Z.jsx)(L,{checked:a.multiple,onChange:e=>d({multiple:e})}),X(`data.multiple`)]})]}):null,(0,Z.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,Z.jsx)(L,{checked:a.required,onChange:e=>d({required:e})}),X(`data.required`)]}),s?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,Z.jsx)(S,{variant:`ghost`,className:`text-rose`,disabled:l,onClick:()=>confirm(X(`data.confirmDelete`,{title:t.name}))&&void f(n.filter(e=>e.id!==t.id)),children:X(`data.deleteColumn`)}):null,(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsx)(S,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Z.jsx)(S,{type:`submit`,busy:l,disabled:!a.name.trim(),children:X(`settings.save`)})]})]})})}function Fn({id:e,by:t,children:n}){let r=Oe(e);return(0,Z.jsx)(`tr`,{"data-row":e,title:t?He(t):void 0,className:F(`group border-border-soft border-b last:border-b-0`,r),style:t?{boxShadow:`inset 3px 0 0 ${Ee(t.who)}`}:void 0,children:n})}function In({tableId:e,onGone:t}){let n=_(),r=x.table(e),i=z({queryKey:r,queryFn:()=>l.get(`/api/studio/tables/${e}`)}),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(``);(0,Q.useEffect)(()=>m(i.data?.title??``),[i.data?.title]);let g=he().data?.user.id,[v,y]=(0,Q.useState)(null);Le(`table`,e,{state:v?`editing`:`viewing`,place:v?`row:${v}`:null,placeLabel:v?X(`data.rowN`,{n:(i.data?.rows.findIndex(e=>e.id===v)??0)+1}):null});let b=Me(`table`,e,g),C=new Map(b.filter(e=>e.state===`editing`&&e.place?.startsWith(`row:`)).map(e=>[e.place?.slice(4)??``,e])),w=async()=>{await n.invalidateQueries({queryKey:x.spaceData(i.data?.projectId)}),await n.invalidateQueries({queryKey:x.knowledge(i.data?.projectId)})},E=e=>n.setQueryData(r,t=>t&&{...t,rows:e(t.rows)}),D=e=>{c(e.message),i.refetch()},O=async t=>{await l.patch(`/api/studio/tables/${e}`,t),await i.refetch(),await w()},k=K({mutationFn:({row:t,column:n,value:r})=>l.patch(`/api/studio/tables/${e}/rows/${t}`,{cells:{[n]:r}}),onSuccess:(e,{row:t,column:n})=>{c(null),f(e=>e===`${t}:${n}`?null:e),E(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells,updatedAt:e.updatedAt??t.updatedAt}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof h&&e.body?.column===n){let e=i.data?.columns.find(e=>e.id===n)?.name??n;f(`${t}:${n}`),c(X(`data.badCell`,{column:e}));return}D(e)}}),ee=K({mutationFn:()=>l.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{E(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await w()},onError:D}),A=K({mutationFn:t=>l.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{E(e=>e.filter(e=>e.id!==t)),await w()},onError:D}),te=K({mutationFn:()=>l.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await w(),t()}});if(!i.data)return i.isError?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:i.error.message}):null;let{columns:j,rows:M,readOnly:N}=i.data,P=!!i.data.list;return(0,Z.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Z.jsx)(De,{kind:`table`,item:e}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Z.jsx)(`input`,{value:p,disabled:N,maxLength:120,onChange:e=>m(e.target.value),onBlur:()=>p.trim()&&p!==i.data?.title&&void O({title:p}).catch(D),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":X(`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`}),(0,Z.jsx)(Ne,{kind:`table`,item:e,me:g}),N?null:(0,Z.jsx)(T,{label:X(`data.deleteTable`),onClick:()=>confirm(X(`data.confirmDelete`,{title:i.data.title}))&&te.mutate(),className:`hover:text-rose`,children:(0,Z.jsx)(V,{className:`size-4`})})]}),P?(0,Z.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:X(`data.fromList`)}):null,i.data.knowledge?(0,Z.jsx)(an,{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 l.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>i.refetch()).catch(D)}):null,(0,Z.jsxs)(u,{className:`overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Z.jsxs)(`table`,{className:`w-full border-collapse text-left`,onFocus:e=>y(e.target.closest(`tr[data-row]`)?.getAttribute(`data-row`)??null),onBlur:()=>y(null),children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[j.map(e=>(0,Z.jsx)(`th`,{className:`min-w-36 border-border-soft border-l p-1 font-medium first:border-l-0`,children:(0,Z.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,Z.jsx)(`span`,{className:`truncate`,children:e.name}),e.required?(0,Z.jsx)(`span`,{className:`text-ember`,children:`*`}):null,jn(e)?(0,Z.jsx)(`span`,{className:`font-normal text-ink-4`,children:jn(e)}):null]})},e.id)),(0,Z.jsx)(`th`,{className:`w-10 p-1`,children:N||P?null:(0,Z.jsx)(T,{label:X(`data.newColumn`),onClick:()=>o(`new`),className:`size-8`,children:(0,Z.jsx)(W,{className:`size-4`})})})]})}),(0,Z.jsx)(`tbody`,{children:M.map(e=>(0,Z.jsxs)(Fn,{id:e.id,by:C.get(e.id),children:[j.map(t=>(0,Z.jsx)(`td`,{className:`border-border-soft border-l p-1 align-top first:border-l-0`,children:(0,Z.jsx)(An,{column:t,value:e.cells[t.id],readOnly:N,invalid:d===`${e.id}:${t.id}`,onSave:n=>k.mutate({row:e.id,column:t.id,value:n})})},t.id)),(0,Z.jsx)(`td`,{className:`w-10 p-1 align-top`,children:N?null:(0,Z.jsx)(T,{label:X(`data.deleteRow`),onClick:()=>A.mutate(e.id),className:`size-8 opacity-0 hover:text-rose focus:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:(0,Z.jsx)(V,{className:`size-3.5`})})})]},e.id))})]})}),M.length?null:(0,Z.jsx)(`p`,{className:`px-4 py-6 text-center text-[0.875rem] text-ink-3`,children:X(`data.noRows`)}),N?null:(0,Z.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,Z.jsxs)(S,{variant:`ghost`,size:`sm`,busy:ee.isPending,onClick:()=>ee.mutate(),children:[(0,Z.jsx)(W,{className:`size-4`}),` `,X(`data.addRow`)]})})]}),s?(0,Z.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:s}):null,(0,Z.jsx)(Pn,{open:a!==null,column:a===`new`?null:a,columns:j,onClose:()=>o(null),onSave:e=>O({columns:e})})]})}var Ln=`wizards.runDrawer.width`,Rn=`wizards.runDrawer.wide`,zn=680,Bn=400,Vn=()=>Math.max(Bn,window.innerWidth-120);function Hn(e){try{return localStorage.getItem(e)}catch{return null}}function Un(e,t){try{localStorage.setItem(e,t)}catch{}}function Wn(){let[e,t]=(0,Q.useState)(()=>{let e=Number(Hn(Ln));return e?Math.min(Math.max(e,Bn),Vn()):zn}),[n,r]=(0,Q.useState)(()=>Hn(Rn)===`1`),i=(0,Q.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,Bn),Vn()));t(n),Un(Ln,String(n))},[]);return{width:e,wide:n,toggleWide:()=>{r(!n),Un(Rn,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(zn)}}function Gn({look:e,onChange:t,ways:n=[`steps`,`chat`]}){let r=[{id:`steps`,label:X(`chat.steps`),Icon:Qe},{id:`chat`,label:X(`chat.chat`),Icon:et}].filter(e=>n.includes(e.id));return(0,Z.jsx)(`fieldset`,{"aria-label":X(`chat.view`),className:`m-0 flex min-w-0 rounded-full border-0 bg-paper-2 p-0.5`,children:r.map(({id:n,label:r,Icon:i})=>(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":e===n,title:r,onClick:()=>t(n),className:F(`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,Z.jsx)(i,{className:`size-3.5`}),(0,Z.jsx)(`span`,{className:F(e!==n&&`sr-only`),children:r})]},n))})}function Kn({header:e,actions:t,onClose:n,children:r}){let i=Wn();return(0,Z.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,Z.jsxs)(`div`,{className:F(`relative flex h-full w-full animate-rise flex-col bg-background shadow-overlay`,!i.wide&&`sm:w-[var(--drawer)]`),style:{"--drawer":`${i.width}px`},onClick:e=>e.stopPropagation(),children:[i.wide?null:(0,Z.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":X(`editor.resize`),"aria-valuenow":i.width,tabIndex:0,title:X(`editor.resize`),onPointerDown:i.onPointerDown,onKeyDown:i.onKeyDown,onDoubleClick:i.reset,className:`group -left-2.5 absolute inset-y-0 z-10 hidden w-5 cursor-col-resize outline-none sm:block`,children:(0,Z.jsx)(`span`,{className:`-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2 h-8 w-1 rounded-full bg-ink-4/20 transition group-hover:bg-ember/60 group-focus-visible:bg-ember group-active:h-12 group-active:bg-ember`})}),(0,Z.jsxs)(`div`,{className:`kb-hide flex h-14 shrink-0 items-center gap-3 px-4`,children:[(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:e}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t,(0,Z.jsx)(T,{label:X(i.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:i.toggleWide,className:`max-sm:hidden`,children:i.wide?(0,Z.jsx)(nt,{className:`size-4`}):(0,Z.jsx)(c,{className:`size-4`})}),(0,Z.jsx)(T,{label:X(`editor.close`),onClick:n,children:(0,Z.jsx)(R,{className:`size-5`})})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}function qn(e,t){return t.deliverables.map(t=>{let n=Se(t.from),r=n?e.lists?.find(e=>e.id===n)?.title:e.steps.find(e=>e.id===t.from)?.title;return{from:t.from,label:t.label??r??t.from,formats:t.formats}})}function Jn({wizardId:e,def:t,step:n,revision:r,audience:i,onAudience:a,lead:o,under:s,end:c,onTest:d,testBusy:f,testDisabled:p}){let m=z({queryKey:[`share-preview`,e,n.id,r,i,Y],queryFn:()=>l.get(`/api/studio/wizards/${e}/share-preview?step=${encodeURIComponent(n.id)}&as=${i}&lang=${Y}`),placeholderData:v}),[h,g]=(0,Q.useState)(!0),[_,y]=(0,Q.useState)(null),b=m.data,x=b?.targets.find(e=>e.key===_),C=qn(t,n),w=b?.run?new Intl.DateTimeFormat(Y,{dateStyle:`short`,timeStyle:`short`}).format(new Date(b.run.at)):null;return(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center gap-2 border-ember border-b-2 px-3`,children:[o,(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsx)(`fieldset`,{"aria-label":X(`resultPreview.seenBy`),className:`m-0 flex rounded-full border-0 bg-paper-2 p-0.5`,children:[`visitor`,`owner`].map(e=>(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":i===e,onClick:()=>a(e),className:F(`inline-flex h-7 items-center gap-1.5 whitespace-nowrap rounded-full px-2.5 font-medium text-[0.8125rem] transition coarse:h-9`,i===e?`bg-card text-ink shadow-soft`:`text-ink-3 hover:text-ink`),children:[e===`visitor`?(0,Z.jsx)(Ue,{className:`size-3.5`}):(0,Z.jsx)(mt,{className:`size-3.5`}),(0,Z.jsx)(`span`,{className:`max-sm:sr-only`,children:X(e===`visitor`?`resultPreview.visitor`:`resultPreview.you`)})]},e))}),(0,Z.jsxs)(S,{size:`sm`,variant:`secondary`,busy:f,disabled:p,onClick:d,children:[(0,Z.jsx)(ct,{className:`size-3.5`}),X(`editor.test`)]}),c]}),s,(0,Z.jsx)(`div`,{className:`@container min-h-0 flex-1 overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`mx-auto max-w-2xl px-4 py-5 sm:px-6`,children:[(0,Z.jsxs)(`p`,{className:`mb-5 flex items-center gap-2 text-[0.75rem] text-ink-3`,children:[m.isFetching?(0,Z.jsx)(B,{className:`size-3.5 shrink-0`}):(0,Z.jsx)(Ae,{className:`size-3.5 shrink-0`}),w?X(`resultPreview.from`,{time:w}):X(`resultPreview.none`)]}),(0,Z.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-center gap-x-4 gap-y-4`,children:[(0,Z.jsx)(ge,{kind:t.avatar,costume:t.costume,size:56,interactive:!1}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 basis-[12rem]`,children:[(0,Z.jsx)(`h2`,{className:`text-balance font-display font-semibold text-[1.5rem] leading-tight tracking-tight`,children:n.title}),n.message?(0,Z.jsx)(`p`,{className:`mt-1 text-[0.9375rem] text-ink-3`,children:n.message}):null]}),(0,Z.jsxs)(S,{variant:`secondary`,"aria-expanded":h,onClick:()=>g(!h),className:F(h&&`ring-2 ring-ember`),children:[(0,Z.jsx)(P,{className:`size-4`}),` `,X(`shareRun.button`)]})]}),h?(0,Z.jsx)(u,{className:`mb-6 p-4 shadow-elevated sm:p-5`,children:x?(0,Z.jsx)(Xn,{target:x,deliverables:C,hasRun:!!b?.run,onBack:()=>y(null)},`${x.key}:${JSON.stringify(x.fields.map(e=>e.value))}`):(0,Z.jsx)(Yn,{data:b,onPick:y})}):null,(0,Z.jsx)(`div`,{className:`flex flex-col gap-6`,children:C.map(e=>{let t=b?.outputs[e.from];return(0,Z.jsxs)(u,{className:`p-4 sm:p-5`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,Z.jsx)(`h3`,{className:`font-display font-semibold text-[1.0625rem]`,children:e.label}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.formats.map(e=>(0,Z.jsx)(`span`,{className:`inline-flex h-7 items-center rounded-full bg-paper-2 px-3 font-medium text-[0.75rem] text-ink-2`,children:O[e]},e))})]}),t?(0,Z.jsx)(`div`,{className:`max-h-72 overflow-hidden [mask-image:linear-gradient(to_bottom,black_70%,transparent)]`,children:(0,Z.jsx)(G,{text:t})}):(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`resultPreview.notMade`)})]},e.from)})})]})})]})}function Yn({data:e,onPick:t}){let n=j(),r=e?.left.filter(e=>e.why===`agent`)??[],i=e?.left.filter(e=>e.why===`setup`)??[];return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Z.jsx)(`h3`,{className:`font-medium text-[1.0625rem]`,children:X(`shareRun.title`)}),(0,Z.jsxs)(`div`,{className:`grid gap-2.5 @lg:grid-cols-2`,children:[(0,Z.jsx)(Re,{icon:s,name:X(`share.link`),description:X(`shareRun.linkHint`)}),(e?.targets??[]).map(e=>(0,Z.jsx)(Re,{icon:ze[e.icon],name:e.name,description:e.description,onClick:()=>t(e.key)},e.key))]}),r.length?(0,Z.jsxs)(`p`,{className:`flex items-start gap-2 rounded-lg bg-paper-2 px-3 py-2.5 text-[0.8125rem] text-ink-2 leading-relaxed`,children:[(0,Z.jsx)(ie,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),X(`resultPreview.agentLeft`,{names:Ot(r.map(e=>e.name))})]}):null,i.length?(0,Z.jsxs)(`p`,{className:`flex flex-wrap items-start gap-x-2 gap-y-1 rounded-lg bg-amber-tint px-3 py-2.5 text-[0.8125rem] text-ink-2 leading-relaxed`,children:[(0,Z.jsx)(M,{className:`mt-0.5 size-4 shrink-0 text-amber`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:X(`resultPreview.setupLeft`,{names:Ot(i.map(e=>e.name))})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>n(`/settings/connectors`),className:`font-medium text-ember-strong hover:underline`,children:X(`shareEditor.setUp`)})]}):null]})}function Xn({target:e,deliverables:t,hasRun:n,onBack:r}){let[i,a]=(0,Q.useState)(()=>Object.fromEntries(e.fields.map(e=>[e.id,e.value??``]))),[o,s]=(0,Q.useState)(()=>Object.fromEntries(t.map(e=>[e.from,e.formats[0]]))),c=[...e.connection?[X(`shareRun.stepAccount`)]:[],X(`shareRun.stepForm`),X(`shareRun.stepSend`)];return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(T,{label:X(`run.back`),onClick:r,className:`-ml-2`,children:(0,Z.jsx)(f,{className:`size-4`})}),(0,Z.jsx)(`h3`,{className:`min-w-0 flex-1 truncate font-medium text-[1.0625rem]`,children:e.name})]}),(0,Z.jsx)(`div`,{className:`-mb-6`,children:(0,Z.jsx)(Fe,{steps:c,now:+!!e.connection})}),e.connection?.account?(0,Z.jsx)(`p`,{className:`rounded-lg bg-paper-2 px-3 py-2 text-[0.8125rem] text-ink-2`,children:X(`shareRun.as`,{account:e.connection.account.label})}):null,e.agent?(0,Z.jsxs)(`p`,{className:`flex items-start gap-2.5 rounded-lg bg-ember-tint px-3 py-2.5 text-[0.8125rem] text-ink-2 leading-relaxed`,children:[(0,Z.jsx)(J,{className:`mt-0.5 size-4 shrink-0 text-ember-strong`}),` `,X(`shareRun.agentHint`)]}):null,e.fields.map(e=>(0,Z.jsx)(Be,{field:e,value:i[e.id]??``,choices:[],onChange:t=>a(n=>({...n,[e.id]:t}))},e.id)),n&&e.empty.length?(0,Z.jsxs)(`p`,{className:`flex items-start gap-2 rounded-lg bg-amber-tint px-3 py-2.5 text-[0.8125rem] text-ink-2`,children:[(0,Z.jsx)(M,{className:`mt-0.5 size-4 shrink-0 text-amber`}),X(`resultPreview.empty`,{names:e.empty.map(e=>`{{${e}}}`).join(`, `)})]}):null,e.takes===`files`&&t.length?(0,Z.jsx)(Ie,{deliverables:t,picked:o,onPick:(e,t)=>s(n=>({...n,[e]:t}))}):null,(0,Z.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:X(`resultPreview.nothingSent`)})]})}function Zn({label:e,value:t,onChange:n,options:r,named:i}){return(0,Z.jsx)(`fieldset`,{"aria-label":e,className:`m-0 flex shrink-0 rounded-full border-0 bg-paper-2 p-0.5`,children:r.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":t===e.id,title:e.label,onClick:()=>n(e.id),className:F(`inline-flex h-7 items-center gap-1.5 whitespace-nowrap rounded-full px-2.5 font-medium text-[0.75rem] transition coarse:h-9`,t===e.id?`bg-card text-ink shadow-soft`:`text-ink-3 hover:text-ink`),children:[e.icon,(0,Z.jsx)(`span`,{className:F(!!e.icon&&!(i&&t===e.id)&&`sr-only`,i&&`@min-[26rem]:not-sr-only`),children:e.label})]},e.id))})}function Qn({label:e,value:t,onChange:n,options:r}){return(0,Z.jsxs)(`label`,{className:`relative flex shrink-0 items-center`,children:[(0,Z.jsx)(`span`,{className:`sr-only`,children:e}),(0,Z.jsx)(`select`,{value:t,onChange:e=>n(e.target.value),title:e,className:F(`h-8 appearance-none truncate rounded-full border-0 bg-paper-2 py-0 pr-7 pl-3 font-medium text-[0.75rem] text-ink outline-none focus-visible:ring-2 focus-visible:ring-ember coarse:h-10 max-w-40`),children:r.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,Z.jsx)(`svg`,{"aria-hidden":`true`,className:`pointer-events-none absolute right-2.5 size-3 text-ink-3`,viewBox:`0 0 16 16`,fill:`none`,children:(0,Z.jsx)(`path`,{d:`M4 6l4 4 4-4`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})})]})}function $n(e){return e.name??X(e.id==="default"?`inspector.lookThemeDefault`:`inspector.lookThemeBrand`)}function er({wizard:e,runId:t,runView:n,onView:r,stepId:i,audience:a,onAudience:o,test:s,column:c,onColumn:u,onClose:d,building:f,log:p,strip:m,lead:h,onShowRun:g,onEdit:_}){let y=e.draft,b=z({queryKey:[`wizard-looks`,e.id,e.revision],queryFn:()=>l.get(`/api/studio/wizards/${e.id}/looks`),placeholderData:v}).data?.looks,[C,w]=(0,Q.useState)(null),E=b?.find(e=>e.id===C)??b?.[0]??null,D=E?.theme??n?.brand.theme??null,[O,k]=(0,Q.useState)(null),A=D?.prefer??(D?.dark?`dark`:`light`),j=O??A,M=de(D,O),N=e.runners??We,P=[`steps`,`chat`].filter(e=>N.enabled.includes(e)||N.default===e),I=N.default===`chat`&&P.includes(`chat`)?`chat`:`steps`,[L,B]=(0,Q.useState)(null),V=L??I,H=Ce(y),U=z({queryKey:x.translations(e.id),queryFn:()=>l.get(`/api/studio/wizards/${e.id}/translations`),enabled:e.published&&e.translate}),W=[H,...e.translate?(U.data?.translations??[]).map(e=>e.lang):[]].filter((e,t,n)=>n.indexOf(e)===t),[G,re]=(0,Q.useState)(H),ie=(0,Q.useRef)({run:null,lang:H});(0,Q.useEffect)(()=>{if(!t)return;let e=ie.current;ie.current={run:t,lang:G},!(e.run===t?e.lang===G:G===H)&&l.post(`/api/runs/${t}/lang`,{lang:G===H?null:G}).catch(()=>void 0)},[t,G,H]),(0,Q.useEffect)(()=>(G!==H&&ye(G)&&xe(G),()=>xe(Y)),[G,H]);let[ae,oe]=(0,Q.useState)(`desk`),K=i?y.steps.find(e=>e.id===i)??null:null,q=z({queryKey:[`draft-step-view`,e.id,K?.id,e.revision,G],queryFn:()=>l.get(`/api/studio/wizards/${e.id}/steps/${encodeURIComponent(K?.id??``)}/view${G===H?``:`?lang=${encodeURIComponent(G)}`}`),enabled:!!(K&&K.type!==`result`),placeholderData:(e,t)=>t?.queryKey[2]===K?.id?e:void 0}),J=async()=>!1,he=K&&q.data?{view:q.data,notFound:!1,error:null,busy:!1,fieldErrors:{},submitPage:J,accept:J,regenerate:J,back:J,retry:J}:null,_e=K?.type===`result`?K:null,be=c===null?null:(0,Z.jsx)(T,{label:X(c?`editor.columnHide`:`editor.columnShow`),onClick:()=>u(!c),children:c?(0,Z.jsx)(it,{className:`size-4`}):(0,Z.jsx)(ot,{className:`size-4`})});return(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[_e?(0,Z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Z.jsx)(Jn,{wizardId:e.id,def:y,step:_e,revision:e.revision,audience:a,onAudience:o,lead:h,under:m,end:be,onTest:s.start,testBusy:s.busy,testDisabled:s.disabled})}):null,(0,Z.jsxs)(`div`,{className:F(`flex min-h-0 flex-1 flex-col`,_e&&`hidden`),children:[(0,Z.jsxs)(`div`,{className:`kb-hide flex h-12 shrink-0 items-center gap-1.5 overflow-x-auto border-border-soft border-b px-3 [scrollbar-width:none]`,children:[h,P.length>1&&!K?(0,Z.jsx)(`span`,{className:`shrink-0`,children:(0,Z.jsx)(Gn,{look:V,onChange:B,ways:[...P]})}):null,g?(0,Z.jsxs)(`button`,{type:`button`,onClick:g,className:`inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-paper-2 px-3 font-medium text-[0.75rem] text-ink-2 transition hover:text-ink`,children:[(0,Z.jsx)(ct,{className:`size-3.5`}),X(`run.testChip`)]}):null,(0,Z.jsx)(`span`,{className:`flex-1`}),_?(0,Z.jsxs)(S,{variant:`secondary`,size:`sm`,onClick:_,children:[(0,Z.jsx)(ee,{className:`size-3.5`}),X(`editor.edit`)]}):null,b&&b.length>1&&E?(0,Z.jsx)(Qn,{label:X(`editor.previewTheme`),value:E.id,onChange:w,options:b.map(e=>({value:e.id,label:$n(e)}))}):null,fe(D)?(0,Z.jsx)(Zn,{label:X(`editor.previewMode`),value:j,onChange:k,options:[{id:`light`,label:X(`theme.light`),icon:(0,Z.jsx)(pe,{className:`size-3.5`})},{id:`dark`,label:X(`theme.dark`),icon:(0,Z.jsx)(me,{className:`size-3.5`})}]}):null,W.length>1?(0,Z.jsx)(Qn,{label:X(`editor.previewLang`),value:G,onChange:re,options:W.map(e=>({value:e,label:ve(e)}))}):null,(0,Z.jsx)(`span`,{className:`max-sm:hidden`,children:(0,Z.jsx)(Zn,{label:X(`editor.device`),value:ae,onChange:oe,options:[{id:`desk`,label:X(`editor.deviceDesk`),icon:(0,Z.jsx)(je,{className:`size-3.5`})},{id:`phone`,label:X(`editor.devicePhone`),icon:(0,Z.jsx)(se,{className:`size-3.5`})}]})}),t?(0,Z.jsx)(T,{label:X(`editor.restart`),disabled:s.disabled||s.busy,onClick:s.start,children:(0,Z.jsx)(te,{className:`size-4`})}):(0,Z.jsxs)(S,{size:`sm`,variant:`secondary`,busy:s.busy,disabled:s.disabled,onClick:s.start,children:[(0,Z.jsx)(ct,{className:`size-3.5`}),X(`editor.test`)]}),be,t?(0,Z.jsx)(T,{label:X(`editor.close`),onClick:d,children:(0,Z.jsx)(R,{className:`size-4`})}):null]}),m,(0,Z.jsx)(`div`,{className:F(`relative flex min-h-0 flex-1 justify-center`,ae===`phone`&&`bg-paper-2 py-4`),children:(0,Z.jsxs)(`div`,{className:F(`relative min-h-0 w-full`,M?.className,ae===`phone`&&`max-w-[390px] overflow-hidden rounded-[2rem] shadow-elevated ring-8 ring-paper-3`),style:M?.style,children:[(0,Z.jsx)(ce,{effects:D?.effects,contained:!0}),(0,Z.jsx)(`div`,{className:`absolute inset-0 overflow-y-auto bg-background`,children:f?(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-[0.875rem] text-ink-3`,children:f}):K||t?(0,Z.jsxs)(Z.Fragment,{children:[K&&he?(0,Z.jsx)(ne,{run:he,compact:!0,studio:!0},K.id):null,t?(0,Z.jsx)(`div`,{className:F(K&&`hidden`),children:V===`chat`?(0,Z.jsx)(ue,{runId:t,onRestart:s.start,onView:r},t):(0,Z.jsx)(le,{runId:t,compact:!0,studio:!0,onRestart:s.start,onView:r},t)}):null]}):(0,Z.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-4 px-6 text-center`,children:[(0,Z.jsx)(ge,{kind:y.avatar,costume:y.costume,size:160,fluffy:!0}),(0,Z.jsx)(`h2`,{className:`text-balance font-display font-semibold text-[1.5rem] tracking-tight`,children:y.title}),y.description?(0,Z.jsx)(`p`,{className:`max-w-md text-balance text-[0.9375rem] text-ink-2`,children:y.description}):null,(0,Z.jsxs)(S,{busy:s.busy,disabled:s.disabled,onClick:s.start,children:[(0,Z.jsx)(ct,{className:`size-4`}),X(`editor.test`)]}),(0,Z.jsx)(`p`,{className:`max-w-sm text-balance text-[0.8125rem] text-ink-3`,children:X(`editor.previewEmpty`)})]})})]})}),t&&!K?p:null]})]})}export{wt as A,jt as C,Et as D,bt as E,ct as F,Xe as I,Ke as L,Ct as M,ht as N,Ot as O,ft as P,Pt as S,Tt as T,en as _,Sn as a,Mt as b,bn as c,rn as d,an as f,Qt as g,Ut as h,In as i,yt as j,Dt as k,hn as l,tn as m,er as n,wn as o,pn as p,Kn as r,xn as s,Zn as t,sn as u,$t as v,gt as w,Nt as x,Ft as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,A as i,An as a,B as o,C as s,Cn as c,D as l,Dn as u,E as d,G as f,Gt as p,H as m,I as h,In as g,Jt as _,Kn as v,Kt as y,L as b,M as x,Mn as S,Mr as C,N as w,Nn as T,O as E,On as D,P as O,Qn as k,R as ee,Rn as te,S as A,T as j,U as M,Un as N,V as P,W as ne,Wt as F,Xn as I,Xt as L,Yt as R,Zt as z,_ as B,_n as V,an as H,ar as re,b as ie,bn as U,d as W,en as ae,er as oe,f as se,g as ce,h as G,hn as le,in as ue,ir as de,j as fe,jn as pe,k as K,kn as me,m as he,nn as ge,on as q,or as _e,p as J,pn as ve,qt as ye,rn as be,rr as xe,sr as Se,tn as Ce,un as we,v as Te,w as Ee,x as De,y as Y,yn as Oe,yt as ke,z as Ae}from"./ui-DQX_CQ7c.js";import{E as je,S as Me,_ as Ne,b as Pe,v as Fe,x as Ie}from"./Marketplace-DSo6uZF6.js";import{t as Le}from"./useMutation-C3XBoSVf.js";import{I as Re,L as ze,P as Be,S as Ve,_ as He,a as Ue,b as We,c as Ge,d as Ke,f as qe,g as Je,h as Ye,i as Xe,l as Ze,m as Qe,o as $e,p as et,r as tt,s as nt,t as rt,u as it,v as at,x as ot,y as st}from"./PreviewPane-swAH89un.js";import{b as ct,f as lt}from"./theme-Dab079EV.js";import{d as ut,f as dt,g as ft,p as pt,x as mt}from"./session-B2LtqeDq.js";import{t as ht}from"./phone-CXSrxw3H.js";import{n as gt,r as _t,t as vt}from"./ReadOnly-Cap_e5ke.js";import{t as yt}from"./upload-hLkuT3Q6.js";import{lt as bt,n as xt,s as X}from"./i18n-B3J2ypKu.js";import{$ as St,$t as Ct,At as wt,Ft as Tt,H as Et,J as Dt,Jt as Ot,Q as kt,U as At,Ut as jt,X as Mt,Y as Nt,Z as Pt,an as Ft,c as It,d as Lt,en as Rt,et as zt,f as Bt,fn as Vt,h as Ht,it as Ut,m as Wt,nt as Gt,p as Kt,q as qt,qt as Jt,s as Yt,tn as Xt,u as Zt,v as Qt,y as $t}from"./index-WY5lJ_-h.js";var en={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};en.node;var tn=I(en),nn={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`}]]};nn.node;var rn=I(nn),an={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`}]]};an.node;var on=I(an),sn={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`}]]};sn.node;var cn=I(sn),ln={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`]};ln.node;var un=I(ln),dn={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`}]]};dn.node;var fn=I(dn),pn={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`}]]};pn.node;var mn=I(pn),hn={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`}]]};hn.node;var gn=I(hn),_n={name:`tablet`,size:24,node:[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,ry:`2`,key:`76otgf`}],[`line`,{x1:`12`,x2:`12.01`,y1:`18`,y2:`18`,key:`1dp563`}]]};_n.node;var vn=I(_n),Z=e(t(),1),Q=e(n(),1),yn={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function bn({file:e,actions:t}){let[n,r]=(0,Z.useState)(e.description),i=(0,Z.useRef)(e.description),a=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Z.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,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,Q.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:X(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 xn(e,t){confirm(X(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function Sn({projectId:e,file:t,small:n}){let r=Ae(e,t.id);if(t.mime.startsWith(`image/`))return(0,Q.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:q(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,Q.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,Q.jsx)(Cn,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,Q.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,Q.jsx)(gn,{className:i}):t.mime===`application/pdf`?(0,Q.jsx)(S,{className:i}):t.mime===`application/json`?(0,Q.jsx)(ve,{className:i}):t.mime.startsWith(`model/`)?(0,Q.jsx)(rn,{className:i}):(0,Q.jsx)(pe,{className:i}),n?null:(0,Q.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function Cn({src:e,small:t}){let[n,r]=(0,Z.useState)(null);return(0,Z.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,Q.jsx)(`div`,{className:q(`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 wn=`application/x-wizards-logo`;function Tn({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:a,onUpload:o,onPreview:s,mainId:c,onMakeMain:l,moveTo:u,onRemove:d}){let f=e=>d?d(e):xn(e,r);return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,Q.jsxs)(`div`,{draggable:u&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(wn,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===c?(0,Q.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,Q.jsx)(y,{tone:`ember`,children:X(`project.logoMain`)})}):null,(0,Q.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?yn:void 0,children:[s&&n.mime.startsWith(`image/`)?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`project.preview`)}: ${n.name}`,onClick:()=>s(n),className:`block size-full cursor-zoom-in`,children:(0,Q.jsx)(Sn,{projectId:e,file:n})}):(0,Q.jsx)(Sn,{projectId:e,file:n}),(0,Q.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:[s?(0,Q.jsx)(R,{label:X(`project.preview`),onClick:()=>s(n),className:`size-8 bg-card shadow-soft`,children:(0,Q.jsx)(je,{className:`size-4`})}):null,l&&n.id!==c&&!r.readOnly?(0,Q.jsx)(R,{label:X(`project.logoMakeMain`),onClick:()=>l(n),className:`size-8 bg-card shadow-soft`,children:(0,Q.jsx)(Pe,{className:`size-4`})}):null,u&&!r.readOnly?(0,Q.jsx)(ce,{options:u.options,value:u.current(n),onChange:e=>u.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,Q.jsx)(R,{label:X(`project.remove`),onClick:()=>f(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,Q.jsx)(we,{className:`size-4`})})]})]}),t===`asset`?(0,Q.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,Q.jsx)(bn,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,Q.jsxs)(he,{accept:i,multiple:!1,onFiles:e=>o?o(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,Q.jsx)(Ce,{className:`size-5`}):(0,Q.jsx)(Oe,{className:`size-5`}),a]}):null]})}function En({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.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(X(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,Q.jsx)(ye,{open:!0,onClose:r,wide:u?!0:void 0,title:X(u?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:u?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,Q.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,Q.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>p(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:q(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:yn,children:[(0,Q.jsx)(`img`,{src:t.url,alt:``,className:q(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,Q.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(N,{className:`size-3.5`})}):null]},t.url)})}),c?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:()=>d(null),children:X(`run.back`)}),(0,Q.jsx)(F,{busy:o,disabled:!f.length,onClick:()=>void h(),children:f.length>1?X(`project.addMany`,{n:f.length}):X(`project.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.logoUrl`)}),(0,Q.jsx)(L,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),c?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Q.jsx)(F,{type:`submit`,busy:o,disabled:!i.trim(),children:X(`run.next`)})]})]})})}function Dn(e,t,n){return Se({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>f.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function On(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var kn=e=>[On(e),e.pages?X(`project.pages`,{n:e.pages}):null,bt(e.size)].filter(Boolean).join(` · `),An=2e5;function jn({projectId:e,fileId:t,readOnly:n,onGone:r}){let i=C(),a=M(e),o=Qe(e),s=P(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,Z.useState)(null);if(!c)return a.isLoading?(0,Q.jsx)(Ce,{className:`mx-auto text-ink-3`}):null;let f=u??(l?`original`:`text`),m=o.data?.items.find(e=>e.key===`f:${c.id}`),h=Ae(e,c.id),g=(e,t)=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>d(e),className:q(`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,Q.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Q.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:c.name}),(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:kn(c)}),(0,Q.jsx)(`a`,{href:h,target:`_blank`,rel:`noreferrer`,"aria-label":X(`project.openOriginal`),title:X(`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,Q.jsx)(T,{className:`size-4`})}),n?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(R,{label:X(`project.reindex`),onClick:async()=>{await s.reindex(c.id),await i.invalidateQueries({queryKey:ne.knowledge(e)})},children:(0,Q.jsx)(V,{className:`size-4`})}),(0,Q.jsx)(R,{label:X(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(X(`data.confirmDelete`,{title:c.name}))&&(await s.remove(c.id),await i.invalidateQueries({queryKey:ne.knowledge(e)}),r())},children:(0,Q.jsx)(we,{className:`size-4`})})]})]}),(0,Q.jsx)(qe,{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,Q.jsx)(`div`,{className:`px-1`,children:(0,Q.jsx)(bn,{file:c,actions:s})}),c.status===`failed`?(0,Q.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:c.error}):null,(0,Q.jsxs)(p,{className:`flex flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[l?g(`original`,X(`project.original`)):null,g(`text`,X(`project.readText`))]}),f===`original`?c.mime===`application/pdf`?(0,Q.jsx)(`iframe`,{src:h,title:c.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,Q.jsx)(`img`,{src:h,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,Q.jsx)(Mn,{projectId:e,file:c})]})]})}function Mn({projectId:e,file:t}){let n=Dn(e,t,An);return n.isLoading||t.status===`pending`?(0,Q.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,Q.jsx)(Ce,{})}):n.data?.text?(0,Q.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,Q.jsx)(ke,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:X(`project.textCut`,{shown:n.data.text.length.toLocaleString(xt),total:n.data.chars.toLocaleString(xt)})}):null]}):(0,Q.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:X(`project.noText`)})}var Nn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,Pn=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),bt(e.size)].filter(Boolean).join(` · `);function Fn({projectId:e,file:t,actions:n,onClose:r}){let i=Ae(e,t.id);return(0,Q.jsxs)(ye,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,Q.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:Pn(t)}),(0,Q.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":X(`project.openOriginal`),title:X(`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,Q.jsx)(T,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,Q.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:yn,children:(0,Q.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,Q.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,Q.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(bn,{file:t,actions:n})})]})}function In({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,Q.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,Q.jsx)(Sn,{projectId:e,file:t,small:!0})}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,Q.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,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:Pn(t)})]}),(0,Q.jsx)(bn,{file:t,actions:n})]}),(0,Q.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,Q.jsx)(R,{label:X(`project.preview`),onClick:i,children:(0,Q.jsx)(je,{className:`size-4`})}),r&&!n.readOnly?(0,Q.jsx)(ce,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,Q.jsx)(R,{label:X(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,Q.jsx)(we,{className:`size-4`})})]})]})}function Ln({section:e,onSave:t,onRemove:n,onClose:r}){let[i,a]=(0,Z.useState)(e?.title??``);return(0,Q.jsx)(ye,{open:!0,onClose:r,title:X(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.assetSectionName`)}),(0,Q.jsx)(L,{autoFocus:!0,value:i,maxLength:80,placeholder:X(`project.assetSectionTitle`),onChange:e=>a(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,Q.jsx)(F,{variant:`danger`,onClick:n,children:X(`project.sectionRemove`)}):null,(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsx)(F,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Q.jsx)(F,{type:`submit`,disabled:!i.trim(),children:X(e?`settings.save`:`project.add`)})]})]})})}function Rn({projectId:e,data:t,readOnly:n,sections:r,save:a}){let s=P(e,n),[c,l]=m(`assets`,`cards`),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(r),[_,v]=(0,Z.useState)(``),[y,b]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(!1),C=(0,Z.useRef)(null),w=o({assetSections:h},a),T=t.files.filter(e=>e.kind===`asset`),E=new Map(T.map(e=>[e.id,e])),D=new Set(h.flatMap(e=>e.assets)),O=h.find(e=>e.id===_)??null,k=O?O.assets.map(e=>E.get(e)).filter(e=>!!e):T.filter(e=>!D.has(e.id)),ee=T.find(e=>e.id===f),te=u.trim().toLowerCase(),A=te?k.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(te)):k,j=(e,t)=>g(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),M=async e=>{let t=O?.id??null;for(let n of await s.upload(`asset`,e))j(n.id,t)},N=e=>{confirm(X(`project.removeConfirm`,{name:e.name}))&&(s.remove(e.id),j(e.id,null))},ne=h.length?{options:[{value:``,label:X(`project.assetsGeneral`)},...h.map(e=>({value:e.id,label:e.title||X(`project.sectionUntitled`)}))],current:e=>h.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>j(e.id,t||null)}:void 0,F=[{label:X(`project.assetUpload`),icon:(0,Q.jsx)(yt,{className:`size-4 shrink-0`}),onPick:()=>C.current?.click()},{label:X(`project.assetFromUrl`),icon:(0,Q.jsx)(fn,{className:`size-4 shrink-0`}),onPick:()=>S(!0)},...h.length<i.logoSections?[{label:X(`project.assetSectionAdd`),icon:(0,Q.jsx)(cn,{className:`size-4 shrink-0`}),onPick:()=>b(`new`)}]:[]],I=h.length||T.length?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.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,Q.jsx)(ue,{value:_,onChange:e=>{v(e),d(``)},label:X(`project.assets`),options:[{id:``,label:X(`project.assetsGeneral`)},...h.map(e=>({id:e.id,label:e.title||X(`project.sectionUntitled`)}))]}):null,O&&!n?(0,Q.jsx)(R,{label:X(`project.assetSectionRename`),onClick:()=>b(`current`),children:(0,Q.jsx)(U,{className:`size-4`})}):null]}),k.length?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,Q.jsx)(Te,{value:u,onChange:d,placeholder:X(`project.assetSearch`)})}),(0,Q.jsx)(R,{label:X(c===`list`?`project.viewCards`:`project.viewList`),onClick:l,children:c===`list`?(0,Q.jsx)(Rt,{className:`size-4`}):(0,Q.jsx)(mn,{className:`size-4`})})]}):null]}):null;return(0,Q.jsxs)(Y,{title:X(`project.assets`),hint:X(`project.assetsHint`),save:w,tabs:I,action:n?null:(0,Q.jsx)(W,{entries:F}),children:[(0,Q.jsx)(`input`,{ref:C,type:`file`,multiple:!0,accept:Nn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&M(t)}}),A.length?c===`cards`?(0,Q.jsx)(Tn,{projectId:e,kind:`asset`,files:A,actions:s,moveTo:ne,onRemove:N,onPreview:e=>p(e.id)}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:A.map(t=>(0,Q.jsx)(In,{projectId:e,file:t,actions:s,moveTo:ne,onPreview:()=>p(t.id),onRemove:()=>N(t)},t.id))}):k.length?null:n?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`project.staysLocal`)}):(0,Q.jsxs)(he,{accept:Nn,onFiles:e=>void M(e),className:`h-16 w-full`,children:[s.busy?(0,Q.jsx)(Ce,{className:`size-4`}):(0,Q.jsx)(yt,{className:`size-4`}),X(`project.drop`),` `,(0,Q.jsx)(`span`,{className:`underline`,children:X(`project.assetAdd`)})]}),s.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error}):null,ee?(0,Q.jsx)(Fn,{projectId:e,file:ee,actions:s,onClose:()=>p(null)}):null,y?(0,Q.jsx)(Ln,{section:y===`current`?O:null,onClose:()=>b(null),onSave:e=>{if(y===`current`&&O)g(t=>t.map(t=>t.id===O.id?{...t,title:e}:t));else{let t=De();g(n=>[...n,{id:t,title:e,assets:[]}]),v(t)}},onRemove:y===`current`&&O?()=>{(!O.assets.length||confirm(X(`project.assetSectionRemoveConfirm`,{name:O.title})))&&(g(e=>e.filter(e=>e.id!==O.id)),v(``),b(null))}:void 0}):null,x?(0,Q.jsx)(En,{kind:`asset`,onClose:()=>S(!1),fetchUrl:e=>s.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)j(t.id,O?.id??null)}}):null]})}var zn=/^#[0-9a-fA-F]{6}$/;async function Bn(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 Vn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function Hn({projectId:e,gradient:t,isNew:n,brand:r,onSave:i,onClose:a}){let[o,s]=(0,Z.useState)(t),[c,u]=(0,Z.useState)(O(t)),[d,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(!n),S=e=>{s(e),u(O(e)),p(!1)},C=(e,t)=>S({...o,stops:o.stops.map((n,r)=>r===e?{...n,...t}:n)}),w=e=>{let t=[...o.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));S({...o,stops:[...o.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},T=async()=>{_(!0),y(null);try{let{gradient:t}=await f.post(`/api/studio/projects/${e}/gradients/describe`,{text:m.trim(),...b?{gradient:{name:o.name,type:o.type,angle:o.angle,stops:o.stops}}:{}});S({...o,...t,name:o.name.trim()?o.name:t.name}),h(``),x(!0)}catch(e){y(e.message)}_(!1)};return(0,Q.jsx)(ye,{open:!0,onClose:a,wide:!0,title:X(n?`project.gradientNew`:`project.gradientEdit`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m.trim()&&!g&&T()},children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(L,{"data-autofocus":n||void 0,value:m,maxLength:1e3,"aria-label":X(`project.gradientDescribe`),placeholder:X(b?`project.gradientDescribeChange`:`project.gradientDescribeNew`),onChange:e=>h(e.target.value),className:`min-w-0 flex-1`}),(0,Q.jsxs)(F,{type:`submit`,variant:`secondary`,busy:g,disabled:!m.trim(),children:[(0,Q.jsx)(ve,{className:`size-4`}),X(b?`project.gradientDescribeApply`:`project.gradientDescribeMake`)]})]}),(0,Q.jsx)(`p`,{className:q(`mt-1.5 text-[0.8125rem]`,v?`text-rose`:`text-ink-3`),children:v??X(`project.gradientDescribeHint`)})]}),(0,Q.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:O(o)}}),(0,Q.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.gradientName`)}),(0,Q.jsx)(L,{value:o.name,maxLength:80,placeholder:X(`project.gradientNamePlaceholder`),onChange:e=>s({...o,name:e.target.value})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.fillUseLabel`)}),(0,Q.jsx)(L,{value:o.description??``,maxLength:400,placeholder:X(`project.gradientUse`),onChange:e=>s({...o,description:e.target.value})})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.gradientType`)}),(0,Q.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:l.map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":o.type===e,onClick:()=>S({...o,type:e}),className:q(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,o.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:X(Vn[e])},e))})]}),o.type===`radial`?null:(0,Q.jsxs)(`div`,{className:`min-w-56`,children:[(0,Q.jsx)(z,{children:X(`project.gradientAngle`)}),(0,Q.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Q.jsx)(`input`,{type:`range`,min:0,max:360,value:o.angle,"aria-label":X(`project.gradientAngle`),onChange:e=>S({...o,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,Q.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(o.angle),`°`]})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.gradientStops`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.stops.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(ge,{value:zn.test(e.color)?e.color:`#888888`,onChange:e=>C(t,{color:e.target.value})}),(0,Q.jsx)(L,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();zn.test(n)&&C(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,Q.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":X(`project.gradientAt`),onChange:e=>C(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,Q.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,Q.jsx)(R,{label:X(`project.remove`),disabled:o.stops.length<=2,onClick:()=>S({...o,stops:o.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,Q.jsx)(we,{className:`size-4`})})]},t))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[o.stops.length<12?(0,Q.jsxs)(F,{variant:`secondary`,size:`sm`,onClick:()=>w(),children:[(0,Q.jsx)(Oe,{className:`size-4`}),` `,X(`project.gradientStopAdd`)]}):null,r.length&&o.stops.length<12?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:X(`project.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,Q.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>w(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:`CSS`}),(0,Q.jsx)(L,{value:c,spellCheck:!1,onChange:e=>{u(e.target.value);let t=ee(e.target.value);p(!t),t&&s({...o,...t})},className:`font-mono text-[0.8125rem]`}),(0,Q.jsx)(`p`,{className:q(`mt-1.5 text-[0.8125rem]`,d?`text-rose`:`text-ink-3`),children:X(d?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:a,children:X(`common.cancel`)}),(0,Q.jsx)(F,{onClick:()=>{i(o),a()},children:X(`settings.save`)})]})]})})}var Un=`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`,Wn=`size-8 bg-card shadow-soft hover:bg-card`;function Gn({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,Q.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,Q.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,Q.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,Q.jsx)(G,{value:e,label:X(`project.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,Q.jsx)(G,{value:n??``,label:X(`project.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function Kn({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=O(e),[o,s]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:t,"aria-label":X(`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,Q.jsxs)(`div`,{className:Un,children:[(0,Q.jsx)(R,{label:X(o?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:Wn,children:(0,Q.jsx)(te,{className:`size-4`})}),(0,Q.jsx)(R,{label:X(`project.download`),onClick:()=>void Bn(e,e.name),className:Wn,children:(0,Q.jsx)(g,{className:`size-4`})}),t?null:(0,Q.jsx)(R,{label:X(`project.remove`),onClick:i,className:q(Wn,`hover:text-rose`),children:(0,Q.jsx)(we,{className:`size-4`})})]})]}),(0,Q.jsx)(Gn,{name:e.name,namePlaceholder:X(`project.gradientName`),description:e.description,usePlaceholder:X(`project.gradientUse`),readOnly:t,onChange:r})]})}function qn(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function Jn({projectId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:o}){let s=Ae(e,t.file);return(0,Q.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:r,"aria-label":X(`project.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:qn(s,t.tile)}),(0,Q.jsxs)(`div`,{className:Un,children:[(0,Q.jsx)(`a`,{href:s,download:n,"aria-label":X(`project.download`),title:X(`project.download`),className:q(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,Wn),children:(0,Q.jsx)(g,{className:`size-4`})}),r?null:(0,Q.jsx)(R,{label:X(`project.remove`),onClick:o,className:q(Wn,`hover:text-rose`),children:(0,Q.jsx)(we,{className:`size-4`})})]})]}),(0,Q.jsx)(Gn,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:X(`project.patternUse`),readOnly:r,onChange:a})]})}function Yn({projectId:e,pattern:t,isNew:n,fileName:r,busy:i,error:a,upload:o,removeFile:s,onSave:c,onClose:l}){let[u,d]=(0,Z.useState)(t),[f,p]=(0,Z.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,Q.jsx)(ye,{open:!0,onClose:h,wide:!0,title:X(n?`project.patternNew`:`project.patternEdit`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[u.file?(0,Q.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:qn(Ae(e,u.file),u.tile),children:(0,Q.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,Q.jsx)(Ce,{className:`size-4`}):(0,Q.jsx)(D,{className:`size-4`}),X(`project.patternReplace`)]})}):(0,Q.jsxs)(he,{accept:`image/*`,multiple:!1,onFiles:e=>void m(e),className:`h-40 flex-col`,children:[i?(0,Q.jsx)(Ce,{className:`size-5`}):(0,Q.jsx)(D,{className:`size-5`}),X(`project.patternPick`)]}),(0,Q.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.patternName`)}),(0,Q.jsx)(L,{value:u.name,maxLength:80,placeholder:u.file?r(u.file):X(`project.patternNamePlaceholder`),onChange:e=>d({...u,name:e.target.value})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.fillUseLabel`)}),(0,Q.jsx)(L,{value:u.description??``,maxLength:400,placeholder:X(`project.patternUse`),onChange:e=>d({...u,description:e.target.value})})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.patternShow`)}),(0,Q.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,Q.jsx)(`button`,{type:`button`,"aria-pressed":!!u.tile===e,onClick:()=>d({...u,tile:e||void 0}),className:q(`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:X(e?`project.patternTile`:`project.patternFill`)},String(e)))})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[a?(0,Q.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:a}):null,(0,Q.jsx)(F,{variant:`ghost`,onClick:h,children:X(`common.cancel`)}),(0,Q.jsx)(F,{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:X(n?`project.add`:`settings.save`)})]})]})})}var Xn=/^#[0-9a-fA-F]{6}$/;function Zn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,p]=(0,Z.useState)([]),m=async()=>{o(!0),c(null);try{let{colors:t}=await f.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(u(t),p([])):c(X(`project.colorsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,Q.jsx)(ye,{open:!0,onClose:n,wide:l?!0:void 0,title:X(l?`project.colorsFound`:`project.colorsFromUrl`),children:l?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`project.colorsFoundHint`)}),(0,Q.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,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>p(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:q(`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,Q.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,Q.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,Q.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,Q.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(N,{className:`size-3.5`})}):null]},e.value)})}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:()=>u(null),children:X(`run.back`)}),(0,Q.jsx)(F,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.value))),n()},children:d.length>1?X(`project.addMany`,{n:d.length}):X(`project.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.logoUrl`)}),(0,Q.jsx)(L,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`project.colorsUrlHint`)})]}),s?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Q.jsx)(F,{type:`submit`,busy:a,disabled:!r.trim(),children:X(`run.next`)})]})]})})}function Qn({projectId:e,data:t,colors:n,sections:r,gradients:a,patterns:s,rules:c,sectioned:l,ruled:u,save:d,readOnly:f}){let[p,m]=(0,Z.useState)(()=>n.map(e=>({...e,id:De()}))),[h,g]=(0,Z.useState)(r),[_,b]=(0,Z.useState)(a),[x,S]=(0,Z.useState)(s),[C,w]=(0,Z.useState)(null),[T,E]=(0,Z.useState)(null),D=P(e,f),O=A(c),[k,ee]=(0,Z.useState)(null),[te,j]=(0,Z.useState)(null),[M,N]=(0,Z.useState)(!1),ne=o({colors:p.filter(e=>Xn.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:h,gradients:_,patterns:x,colorRules:O.rules},d),F=l?h:[],I=F.filter(e=>(e.kind??`colors`)===`colors`),z=e=>I.some(t=>t.id===e.section),V=p.filter(e=>!z(e)),H=(V[0]??p[0])?.id,re=(e,t)=>m(n=>n.map(n=>n.id===e?{...n,...t}:n)),U=e=>m(t=>[...t,...e.map(e=>({...e,id:De()}))].slice(0,i.colors)),ae=[{value:``,label:X(`project.sectionStandard`)},...I.map(e=>({value:e.id,label:e.title||X(`project.sectionUntitled`)}))],oe=(e,t)=>{let n=De();ee(n),g(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},G=e=>({id:De(),name:``,section:e,type:`linear`,angle:90,stops:[{color:p[0]?.value&&Xn.test(p[0].value)?p[0].value:`#4b73ff`,at:0},{color:p[1]?.value&&Xn.test(p[1].value)?p[1].value:`#ff6d1b`,at:100}]}),le=e=>t.files.find(t=>t.id===e)?.name??`pattern`,ue=[...p.length<i.colors?[{label:X(`project.colorNew`),icon:(0,Q.jsx)(Oe,{className:`size-4 shrink-0`}),onPick:()=>fe()},{label:X(`project.colorsFromUrl`),icon:(0,Q.jsx)(fn,{className:`size-4 shrink-0`}),onPick:()=>N(!0)}]:[],...l&&h.length<i.logoSections?[{label:X(`project.colorSectionAdd`),icon:(0,Q.jsx)(cn,{className:`size-4 shrink-0`}),onPick:()=>oe(`colors`,``)},{label:X(`project.gradientSectionAdd`),icon:(0,Q.jsx)(tn,{className:`size-4 shrink-0`}),onPick:()=>oe(`gradients`,X(`project.gradientSectionTitle`))},{label:X(`project.patternSectionAdd`),icon:(0,Q.jsx)(un,{className:`size-4 shrink-0`}),onPick:()=>oe(`patterns`,X(`project.patternSectionTitle`))}]:[],...!u||O.full?[]:[{label:X(`project.ruleNew`),icon:(0,Q.jsx)(Me,{className:`size-4 shrink-0`}),onPick:()=>O.add()}]],de=e=>(0,Q.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,Q.jsx)(ge,{value:Xn.test(e.value)?e.value:`#888888`,onChange:t=>re(e.id,{value:t.target.value})}),(0,Q.jsx)(L,{value:e.name,autoFocus:e.id===te,placeholder:X(`project.colorName`),maxLength:120,onChange:t=>re(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,Q.jsx)(L,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>re(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,Q.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===H?(0,Q.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,Q.jsx)(y,{tone:`ember`,children:X(`project.colorAccent`)})}):f?null:(0,Q.jsx)(R,{label:X(`project.colorFirst`),onClick:()=>m(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,Q.jsx)(v,{className:`size-4`})}),f||!I.length?null:(0,Q.jsx)(ce,{options:ae,value:z(e)?e.section??``:``,onChange:t=>re(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),f?null:(0,Q.jsx)(R,{label:X(`project.remove`),onClick:()=>m(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,Q.jsx)(we,{className:`size-4`})})]})]},e.id),fe=e=>{let t=De();j(t),m(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,Q.jsxs)(Y,{title:X(`project.colors`),hint:X(`project.colorsHint`),save:ne,locked:f,action:f?null:(0,Q.jsx)(W,{entries:ue}),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[V.length?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:V.map(de)}),f?null:(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`project.colorUse`)})]}):p.length?null:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`project.colorsEmpty`)}),F.map(t=>{let n=t.kind??`colors`,r=p.filter(e=>e.section===t.id),a=_.filter(e=>e.section===t.id),o=x.filter(e=>e.section===t.id),s=n===`gradients`?a.length:n===`patterns`?o.length:r.length;return(0,Q.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,Q.jsx)(ie,{title:t.title,titlePlaceholder:X(n===`gradients`?`project.gradientSectionTitlePlaceholder`:n===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),kind:n===`gradients`?{icon:(0,Q.jsx)(tn,{}),label:X(`project.kindGradients`)}:n===`patterns`?{icon:(0,Q.jsx)(un,{}),label:X(`project.kindPatterns`)}:{icon:(0,Q.jsx)(Jt,{}),label:X(`project.kindColors`)},autoFocus:k===t.id,readOnly:f,onChange:e=>g(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!s||confirm(X(n===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:t.title||X(`project.sectionUntitled`)}))){g(e=>e.filter(e=>e.id!==t.id)),m(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),b(e=>e.filter(e=>e.section!==t.id));for(let e of o)D.remove(e.file);S(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(e=>(0,Q.jsx)(Kn,{gradient:e,readOnly:f,onEdit:()=>w(e),onChange:t=>b(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>b(t=>t.filter(t=>t.id!==e.id))},e.id)),f||_.length>=i.gradients?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>w(G(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,Q.jsx)(Oe,{className:`size-5`}),X(`project.gradientAdd`)]})]}):n===`patterns`?(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[o.map(t=>(0,Q.jsx)(Jn,{projectId:e,pattern:t,fileName:le(t.file),readOnly:f,onEdit:()=>E(t),onChange:e=>S(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{D.remove(t.file),S(e=>e.filter(e=>e.id!==t.id))}},t.id)),f||x.length>=i.files.pattern?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>E({id:De(),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,Q.jsx)(Oe,{className:`size-5`}),X(`project.patternAdd`)]})]}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(de),f||p.length>=i.colors?null:(0,Q.jsx)(se,{label:X(`project.colorAdd`),onClick:()=>fe(t.id)})]})]},t.id)}),u?(0,Q.jsx)(B,{rules:O,placeholder:X(`project.colorRulePlaceholder`),readOnly:f}):null]}),D.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:D.error}):null,C?(0,Q.jsx)(Hn,{projectId:e,gradient:C,isNew:!_.some(e=>e.id===C.id),brand:p.filter(e=>Xn.test(e.value)),onClose:()=>w(null),onSave:e=>b(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,T?(0,Q.jsx)(Yn,{projectId:e,pattern:T,isNew:!x.some(e=>e.id===T.id),fileName:le,busy:D.busy,error:D.error,upload:async e=>(await D.upload(`pattern`,[e]))[0]??null,removeFile:e=>void D.remove(e),onClose:()=>E(null),onSave:e=>S(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,M?(0,Q.jsx)(Zn,{projectId:e,onClose:()=>N(!1),onAdd:U}):null]})}var $n=e=>/^(ja|yes|true)$/i.test(e.trim()),er={text:Fe,longtext:_t,number:Re,date:ze,url:u,email:Ct,phone:ht,boolean:Be};function tr({type:e,detected:t,onChange:n}){let[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),s=(0,Z.useRef)(null);(0,Z.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=er[e??t],l=`${X(`project.factType`)}: ${X(`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,Q.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,Q.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:q(`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,Q.jsx)(c,{className:`size-4`})}),r?(0,Q.jsxs)(`div`,{role:`menu`,className:q(`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,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:u,onClick:()=>d(void 0),children:[(0,Q.jsx)(Ne,{className:`size-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:X(`project.factAuto`)}),(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:X(`project.type.${t}`)}),(0,Q.jsx)(N,{className:q(`size-4 shrink-0`,e&&`invisible`)})]}),(0,Q.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),Ee.map(t=>{let n=er[t];return(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:u,onClick:()=>d(t),children:[(0,Q.jsx)(n,{className:`size-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:X(`project.type.${t}`)}),(0,Q.jsx)(N,{className:q(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function nr({facts:e,save:t,readOnly:n}){let r=(0,Z.useRef)(0),a=(0,Z.useRef)(null),[c,l]=(0,Z.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),u=o(c.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),d=(e,t)=>l(n=>n.map(n=>n.id===e?{...n,...t}:n)),f=(e,t,n=!1)=>{let i=`f${r.current++}`;a.current=`${i}:${t}`;let o={id:i,key:``,label:``,value:``,...e};l(e=>n?[o,...e]:[...e,o])},p=e=>t=>{t&&a.current===e&&(a.current=null,t.focus())},m=s.filter(e=>!c.some(t=>t.key===e));return(0,Q.jsxs)(Y,{title:X(`project.facts`),hint:X(`project.factsHint`),save:u,locked:n,action:c.length<i.facts&&!n?(0,Q.jsxs)(F,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`,!0),children:[(0,Q.jsx)(Oe,{className:`size-4`}),` `,X(`project.factAdd`)]}):null,children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:c.map(e=>{let t=fe(e.value),r=e.type??t;return(0,Q.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,Q.jsx)(L,{ref:p(`${e.id}:label`),value:e.label,placeholder:X(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>d(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&d(e.id,{key:x(e.label,c.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,Q.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Q.jsx)(be,{checked:$n(e.value),label:e.label,onChange:t=>d(e.id,{value:X(t?`project.yes`:`project.no`)})}),(0,Q.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:$n(e.value)?X(`project.yes`):X(`project.no`)})]}):(0,Q.jsx)(H,{ref:p(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:X(`project.factValue`),onChange:t=>d(e.id,{value:t.target.value}),className:`min-h-11`}),(0,Q.jsx)(tr,{type:e.type,detected:t,onChange:t=>d(e.id,{type:t})}),n?null:(0,Q.jsx)(R,{label:X(`project.remove`),onClick:()=>l(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,Q.jsx)(we,{className:`size-4`})})]},e.id)})}),c.length<i.facts&&!n?(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${c.length?`mt-4`:``}`,children:[(0,Q.jsxs)(F,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`),children:[(0,Q.jsx)(Oe,{className:`size-4`}),` `,X(`project.factAdd`)]}),m.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f({key:e,label:X(`fact.${e}`)},`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,Q.jsx)(Oe,{className:`size-3.5`}),` `,X(`fact.${e}`)]},e))]}):null]})}function rr({onLogo:e,children:t,className:n}){let[r,i]=(0,Z.useState)(!1);return e?(0,Q.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(wn);i(!1),n&&(t.preventDefault(),e(n))},className:q(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,Q.jsx)(`div`,{className:n,children:t})}function ir({projectId:e,data:t,readOnly:n,sections:r,rules:a,sectioned:s,ruled:c,save:l}){let u=P(e,n),[d,f]=(0,Z.useState)(r),p=A(a),[m,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(!1),y=(0,Z.useRef)(null),b=o({logoSections:d,logoRules:p.rules},l),x=t.files.filter(e=>e.kind===`logo`),S=new Map(x.map(e=>[e.id,e])),C=s?d:[],w=new Set(C.flatMap(e=>e.logos)),T=x.filter(e=>!w.has(e.id)),E=h(x,d)?.id,D=(e,t)=>f(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),O=(e,t)=>f(n=>n.map(n=>n.id===e?{...n,...t}:n)),k=async(e,t)=>{let n=await u.upload(`logo`,e);for(let e of n)D(e.id,t)},ee=C.length?{options:[{value:``,label:X(`project.sectionStandard`)},...C.map(e=>({value:e.id,label:e.title||X(`project.sectionUntitled`)}))],current:e=>C.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>D(e.id,t||null)}:void 0,te=(t,n,r)=>(0,Q.jsx)(Tn,{projectId:e,kind:`logo`,files:t,actions:u,accept:`image/*`,addLabel:r?X(`project.logoAdd`):void 0,onUpload:e=>void k(e,n),mainId:E,onMakeMain:e=>{D(e.id,null),u.order(`logo`,[e.id,...x.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:ee,onRemove:e=>{confirm(X(`project.removeConfirm`,{name:e.name}))&&(u.remove(e.id),D(e.id,null))}}),j=n?void 0:e=>t=>D(t,e),M=[{label:X(`project.logoUpload`),icon:(0,Q.jsx)(yt,{className:`size-4 shrink-0`}),onPick:()=>y.current?.click()},{label:X(`project.logoFromUrl`),icon:(0,Q.jsx)(fn,{className:`size-4 shrink-0`}),onPick:()=>v(!0)},...s&&d.length<i.logoSections?[{label:X(`project.logoSectionAdd`),icon:(0,Q.jsx)(cn,{className:`size-4 shrink-0`}),onPick:()=>{let e=De();g(e),f(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!c||p.full?[]:[{label:X(`project.ruleNew`),icon:(0,Q.jsx)(Me,{className:`size-4 shrink-0`}),onPick:()=>p.add()}]];return(0,Q.jsxs)(Y,{title:X(`project.logos`),hint:X(`project.logosHint`),save:b,action:n?null:(0,Q.jsx)(W,{entries:M}),children:[(0,Q.jsx)(`input`,{ref:y,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&&k(t,null)}}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Q.jsx)(rr,{onLogo:j?.(null),children:te(T,null,!0)}),C.map(e=>(0,Q.jsx)(`div`,{className:`group/section`,children:(0,Q.jsxs)(rr,{onLogo:j?.(e.id),className:`flex flex-col gap-3`,children:[(0,Q.jsx)(ie,{title:e.title,description:e.description,titlePlaceholder:X(`project.logoSectionTitle`),descriptionPlaceholder:X(`project.logoSectionUse`),autoFocus:m===e.id,readOnly:n,onChange:t=>O(e.id,t),onRemove:()=>{(!e.logos.length||confirm(X(`project.logoSectionRemoveConfirm`,{name:e.title||X(`project.sectionUntitled`)})))&&f(t=>t.filter(t=>t.id!==e.id))}}),te(e.logos.map(e=>S.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),c?(0,Q.jsx)(B,{rules:p,placeholder:X(`project.logoRulePlaceholder`),readOnly:n}):null]}),u.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:u.error}):null,_?(0,Q.jsx)(En,{kind:`logo`,onClose:()=>v(!1),fetchUrl:e=>u.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)D(t.id,null)}}):null]})}var ar=e=>URL.canParse(e)?new URL(e).host:e;async function or(e,t){let n=w({family:t,source:{url:e}});if(!n)return`down`;if(n.stylesheet)return await sr(e,t);let r=await fetch(e,{mode:`cors`}).catch(()=>null);return r?r.ok?await new FontFace(`engenty-check-${Date.now()}`,await r.arrayBuffer()).load().then(()=>`ok`,()=>`noFont`):`down`:await fetch(e,{mode:`no-cors`}).then(()=>!0,()=>!1)?`cors`:`down`}function sr(e,t){let n=new Set(document.fonts),r=document.createElement(`link`);return r.rel=`stylesheet`,r.href=e,new Promise(e=>{r.onerror=()=>e(`down`),r.onload=async()=>{let r=[...document.fonts].filter(e=>!n.has(e)&&e.family.replace(/^["']|["']$/g,``)===t),i=await Promise.allSettled(r.map(e=>e.load()));e(r.length===0?`missing`:i.some(e=>e.status===`fulfilled`)?`ok`:`cors`)},document.head.append(r)}).finally(()=>r.remove())}function cr(e,t){let n=e.source;if(!n)return X(`project.fontSourceNone`);if(`file`in n){let e=t.find(e=>e.id===n.file)?.name??``;return X(`project.fontSourceFile`,{name:e})}return X(`project.fontSourceUrl`,{host:ar(n.url)})}function lr({projectId:e,font:t,onSave:n,onClose:i}){let a=(M(e).data?.files??[]).filter(e=>e.mime.startsWith(`font/`)),o=P(e),s=(0,Z.useRef)(null),[c,l]=(0,Z.useState)(t.source&&`url`in t.source?`url`:`file`),[u,d]=(0,Z.useState)(t.source&&`file`in t.source?t.source.file:``),[f,p]=(0,Z.useState)(t.source&&`url`in t.source?t.source.url:``),[m,h]=(0,Z.useState)(t.source&&`url`in t.source?{url:t.source.url,result:`ok`}:null),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(t.license??``),[b,x]=(0,Z.useState)(!1),S=f.trim(),C=async()=>{_(!0),h({url:S,result:await or(S,t.family.trim())}),_(!1)},w=c===`file`?u?{file:u}:null:m?.url===S&&m.result===`ok`?{url:S}:null,T=m?.url===S?m.result:null;return(0,Q.jsx)(ye,{open:!0,onClose:i,title:X(`project.fontSourceTitle`,{family:t.family}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`project.fontSourceHint`)}),(0,Q.jsx)(r,{value:c,options:[`file`,`url`],label:e=>X(`project.fontSourceKind.${e}`),onChange:e=>l(e)}),c===`file`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.fontSourceFiles`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":u===e.id,onClick:()=>d(e.id),className:q(`rounded-lg px-3 py-2 text-left text-[0.875rem] ring-1 transition`,u===e.id?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:e.name},e.id))}),(0,Q.jsx)(`input`,{ref:s,type:`file`,accept:`.woff2,.woff,.ttf,.otf`,className:`hidden`,onChange:async e=>{let t=[...e.target.files??[]];e.target.value=``;let[n]=await o.upload(`asset`,t);n&&d(n.id)}}),(0,Q.jsxs)(F,{variant:`ghost`,className:`mt-2`,busy:o.busy,onClick:()=>s.current?.click(),children:[(0,Q.jsx)(yt,{className:`size-4`}),X(`project.fontSourceUpload`)]}),o.error?(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-rose`,children:o.error}):null]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),C()},children:[(0,Q.jsx)(z,{children:X(`project.fontSourceUrlLabel`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(L,{value:f,inputMode:`url`,placeholder:X(`project.fontSourceUrlPlaceholder`),onChange:e=>p(e.target.value)}),(0,Q.jsx)(F,{type:`submit`,variant:`ghost`,busy:g,disabled:!S.startsWith(`https://`),children:X(`project.fontSourceCheck`)})]}),T?(0,Q.jsx)(`p`,{className:q(`mt-1.5 text-[0.875rem]`,T===`ok`?`text-ink-3`:`text-rose`),children:X(`project.fontCheck.${T}`,{host:ar(S),family:t.family})}):null,T===`ok`?(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-ink-3`,children:X(`project.fontPrivacy`,{host:ar(S)})}):null]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{hint:X(`project.fontLicenseHint`),children:X(`project.fontLicense`)}),(0,Q.jsx)(L,{value:v,maxLength:200,placeholder:X(`project.fontLicensePlaceholder`),onChange:e=>y(e.target.value)}),(0,Q.jsxs)(`label`,{className:`mt-2 flex items-start gap-2 text-[0.875rem]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 accent-ember`,checked:b,onChange:e=>x(e.target.checked)}),X(`project.fontLicenseConfirm`,{family:t.family})]})]}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[t.source?(0,Q.jsx)(F,{variant:`ghost`,className:`mr-auto`,onClick:()=>{n({source:void 0,license:t.license}),i()},children:X(`project.fontSourceRemove`)}):null,(0,Q.jsx)(F,{variant:`ghost`,onClick:i,children:X(`common.cancel`)}),(0,Q.jsx)(F,{disabled:!(w&&b),onClick:()=>{w&&(n({source:w,license:v.trim()||void 0}),i())},children:X(`project.fontSourceSave`)})]})]})})}var ur=new Set;function dr(e){(0,Z.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||ur.has(t))return;ur.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${d.join(`,`)}&display=swap`,document.head.append(n)},[e])}var fr=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function pr({unit:e,label:t,...n}){return(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,Q.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 mr=`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`,hr={web:`project.fontUseWeb`,documents:`project.fontUseDocuments`,print:`project.fontUsePrint`,images:`project.fontUseImages`,video:`project.fontUseVideo`};function gr({projectId:e,font:t,first:n,readOnly:r,autoFocus:i,onChange:a,onRemove:o}){dr(t.family);let s=M(e).data?.files??[],[c,l]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,Q.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:fr(t.family)},children:[(0,Q.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,Q.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:t.family}),t.role?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:t.role}):null]}):(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(G,{value:t.family,label:X(`project.fontFamily`),placeholder:X(`project.fontFamily`),maxLength:80,autoFocus:i,onChange:e=>a({family:e}),className:`font-medium text-[0.9375rem]`}),(0,Q.jsx)(G,{value:t.role,label:X(`project.fontRole`),placeholder:X(n?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>a({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>{let n=t.weights.includes(e);return(0,Q.jsx)(`button`,{type:`button`,disabled:r,"aria-pressed":n,onClick:()=>a({weights:n?t.weights.filter(t=>t!==e):[...t.weights,e].sort((e,t)=>e-t)}),style:{fontFamily:fr(t.family),fontWeight:e},className:q(`h-7 rounded-full px-2.5 text-[0.8125rem] tabular-nums transition`,n?`bg-ink text-paper`:`bg-paper-2 text-ink-3 hover:text-ink`,r&&!n&&`hidden`),children:e},e)})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[r?t.license?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:t.license}):null:(0,Q.jsx)(G,{value:t.license??``,label:X(`project.fontLicense`),placeholder:X(`project.fontLicensePlaceholder`),maxLength:200,onChange:e=>a({license:e}),className:`text-[0.8125rem] text-ink-3`}),r&&!t.uses?.length?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:X(`project.fontUses`)}),j.map(e=>{let n=!!t.uses?.includes(e);return(0,Q.jsxs)(`button`,{type:`button`,disabled:r,"aria-pressed":n,onClick:()=>{let r=n?(t.uses??[]).filter(t=>t!==e):j.filter(n=>n===e||t.uses?.includes(n));a({uses:r.length?r:void 0})},className:q(`inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-[0.8125rem] transition`,n?`bg-card text-ink ring-1 ring-border`:`bg-paper-2 text-ink-3 hover:text-ink`,r&&!n&&`hidden`),children:[n?(0,Q.jsx)(N,{className:`size-3.5`}):null,X(hr[e])]},e)})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[0.8125rem] text-ink-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:cr(t,s)}),r||!t.family.trim()?null:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>l(!0),className:`text-ink underline decoration-border underline-offset-2 hover:decoration-ink`,children:X(t.source?`project.fontSourceChange`:`project.fontSourceSet`)})]}),c?(0,Q.jsx)(lr,{projectId:e,font:t,onSave:a,onClose:()=>l(!1)}):null,r?null:(0,Q.jsx)(R,{label:X(`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,Q.jsx)(we,{className:`size-4`})})]})}function _r({style:e,fonts:t,sample:n,readOnly:r,autoFocus:i,onChange:a,onRemove:o}){let s=t.find(t=>t.id===e.font)??t[0],c={fontFamily:fr(s?.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,Q.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,Q.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,Q.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,Q.jsx)(`div`,{className:`w-40`,children:(0,Q.jsx)(G,{value:e.name,label:X(`project.styleName`),placeholder:X(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,Q.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,Q.jsx)(`select`,{"aria-label":X(`project.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:q(mr,`max-w-40`),children:t.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.family||X(`project.fontFamily`)},e.id))}):null,(0,Q.jsx)(`select`,{"aria-label":X(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:mr,children:[...new Set([...d,e.weight])].sort().map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))}),(0,Q.jsx)(pr,{unit:`px`,label:X(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,Q.jsx)(pr,{unit:X(`project.styleLine`),label:X(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,Q.jsx)(pr,{unit:X(`project.styleTracking`),label:X(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:X(`project.styleUpper`),"aria-label":X(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:q(`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,Q.jsx)(on,{className:`size-4`})})]}),r?null:(0,Q.jsx)(R,{label:X(`project.remove`),onClick:o,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,Q.jsx)(we,{className:`size-4`})})]})]})}function vr({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,p]=(0,Z.useState)([]),m=async()=>{o(!0),c(null);try{let{fonts:t}=await f.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(u(t),p(t.slice(0,2).map(e=>e.family))):c(X(`project.fontsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,Q.jsx)(ye,{open:!0,onClose:n,wide:l?!0:void 0,title:X(l?`project.fontsFound`:`project.fontsFromUrl`),children:l?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`project.fontsFoundHint`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,Q.jsx)(yr,{font:e,on:d.includes(e.family),onToggle:()=>p(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:()=>u(null),children:X(`run.back`)}),(0,Q.jsx)(F,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.family))),n()},children:d.length>1?X(`project.addMany`,{n:d.length}):X(`project.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.logoUrl`)}),(0,Q.jsx)(L,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`project.fontsUrlHint`)})]}),s?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Q.jsx)(F,{type:`submit`,busy:a,disabled:!r.trim(),children:X(`run.next`)})]})]})})}function yr({font:e,on:t,onToggle:n}){return dr(e.family),(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:q(`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,Q.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:fr(e.family)},children:`Aa`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):X(`project.fontWeightsUnknown`)})]}),t?(0,Q.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(N,{className:`size-3.5`})}):null]})}function br({projectId:e,fonts:t,styles:n,rules:r,ruled:a,sample:s,save:c,readOnly:l}){let[u,d]=(0,Z.useState)(t),[f,p]=(0,Z.useState)(n),m=A(r),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(!1),y=o({fonts:u,textStyles:f,typeRules:m.rules},c),b=(e,t=!1)=>{let n=e.map(e=>({id:De(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&g(n[0].id),d(e=>[...e,...n].slice(0,i.fonts))},x=()=>{let e=De();g(e),p(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},S=[...u.length<i.fonts?[{label:X(`project.fontNew`),icon:(0,Q.jsx)(Oe,{className:`size-4 shrink-0`}),onPick:()=>b([{family:``,weights:[400,700]}],!0)},{label:X(`project.fontsFromUrl`),icon:(0,Q.jsx)(fn,{className:`size-4 shrink-0`}),onPick:()=>v(!0)}]:[],...f.length<i.textStyles?[{label:X(`project.styleNew`),icon:(0,Q.jsx)(jt,{className:`size-4 shrink-0`}),onPick:x}]:[],...!a||m.full?[]:[{label:X(`project.ruleNew`),icon:(0,Q.jsx)(Me,{className:`size-4 shrink-0`}),onPick:()=>m.add()}]];return(0,Q.jsxs)(Y,{title:X(`project.typography`),hint:X(`project.typographyHint`),save:y,action:l?null:(0,Q.jsx)(W,{entries:S}),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[u.length?(0,Q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:u.map((t,n)=>(0,Q.jsx)(gr,{projectId:e,font:t,first:n===0,readOnly:l,autoFocus:h===t.id,onChange:e=>d(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>d(e=>e.filter(e=>e.id!==t.id))},t.id))}):(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`project.fontsEmpty`)}),f.length?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:X(`project.styles`)}),l?null:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:X(`project.stylesHint`)}),(0,Q.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:f.map(e=>(0,Q.jsx)(_r,{style:e,fonts:u,sample:s,readOnly:l,autoFocus:h===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))})]}):null,a?(0,Q.jsx)(B,{rules:m,placeholder:X(`project.typeRulePlaceholder`),readOnly:l}):null]}),_?(0,Q.jsx)(vr,{projectId:e,onClose:()=>v(!1),onAdd:e=>b(e)}):null]})}function xr({projectId:e,logo:t}){let n=X(t?`project.logoPeek`:`project.logoPeekAdd`);return(0,Q.jsxs)(`div`,{className:`shrink-0`,children:[(0,Q.jsx)(z,{children:X(`project.logo`)}),(0,Q.jsx)(k,{to:{pathname:`/space/brand`,hash:`logos`},title:n,"aria-label":n,className:q(`grid size-[4.5rem] place-items-center overflow-hidden rounded-xl transition`,t?`bg-card ring-1 ring-border-soft hover:ring-border`:`text-ink-4 ring-1 ring-border ring-dashed hover:text-ink-2`),children:t?(0,Q.jsx)(Sn,{projectId:e,file:t,small:!0}):(0,Q.jsx)(me,{className:`size-5`})})]})}function Sr({project:e,logo:t,save:n}){let[r,i]=(0,Z.useState)(e.brand.name??``),[a,s]=(0,Z.useState)(e.brand.about??``),c=o({name:r.trim(),about:a.trim()},e=>n({brand:e}));return(0,Q.jsx)(Y,{title:X(`project.base`),hint:X(`project.baseHint`),save:c,locked:e.readOnly,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(z,{children:X(`project.title`)}),(0,Q.jsx)(L,{value:r,maxLength:120,onChange:e=>i(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`project.titleHint`)})]}),(0,Q.jsx)(xr,{projectId:e.id,logo:t})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(z,{children:X(`project.about`)}),(0,Q.jsx)(H,{minRows:4,value:a,onChange:e=>s(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`project.aboutHint`)})]})]})})}function Cr({project:e,group:t,top:n=!1,children:r}){let i=C(),a=M(e.id),[o,s]=(0,Z.useState)(0),[c,l]=(0,Z.useState)(!1),u=async t=>{await f.patch(`/api/studio/projects/${e.id}`,t),await i.invalidateQueries({queryKey:ne.spaces()})},d=Le({mutationFn:()=>f.del(`/api/studio/projects/${e.id}`),onSuccess:()=>i.invalidateQueries({queryKey:ne.spaces()})}),p=pt(),m=dt(),g=a.data??{files:[],embeddings:!0},_=`${e.id}:${o}`,v=e.readOnly,y=t===`knowledge`,b=Tt(`brandSections`),x=Tt(`brandRules`),S=Tt(`typography`);return At(v?{}:{title:X(y?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:X(y?`project.assistantHelloKnowledge`:`project.assistantHello`),about:X(y?`project.assistantAboutKnowledge`:`project.assistantAbout`),placeholder:X(y?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:y?[{label:X(`assistant.suggest.knowledgeHow`)},{label:X(`assistant.suggest.knowledgeSite`),fill:!0},{label:X(`assistant.suggest.knowledgeCategories`)}]:[{label:X(`assistant.suggest.readSite`),fill:!0},{label:X(`assistant.suggest.missing`)},...t===`info`?[{label:X(`assistant.suggest.facts`)}]:[]],summary:y?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${g.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>s(e=>e+1)}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[v?(0,Q.jsx)(vt,{children:gt(e)}):n?(0,Q.jsx)(Et,{}):null,t===`info`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(J,{id:`base`,children:(0,Q.jsx)(Sr,{project:e,logo:h(g.files.filter(e=>e.kind===`logo`),e.brand.logoSections),save:u},`base:${_}`)}),(0,Q.jsx)(J,{id:`facts`,children:(0,Q.jsx)(nr,{facts:e.facts,save:e=>u({facts:e}),readOnly:v},`facts:${_}`)})]}):null,t===`brand`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(J,{id:`logos`,children:(0,Q.jsx)(ir,{projectId:e.id,data:g,readOnly:v,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:b,ruled:x,save:e=>u({brand:e})},`logos:${_}`)}),(0,Q.jsx)(J,{id:`colors`,children:(0,Q.jsx)(Qn,{projectId:e.id,data:g,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],sectioned:b,ruled:x,save:e=>u({brand:e}),readOnly:v},`colors:${_}`)}),S?(0,Q.jsx)(J,{id:`typography`,children:(0,Q.jsx)(br,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:x,sample:e.brand.name||X(`project.typeSample`),save:e=>u({brand:e}),readOnly:v},`typography:${_}`)}):null,(0,Q.jsx)(J,{id:`assets`,children:(0,Q.jsx)(Rn,{projectId:e.id,data:g,readOnly:v,sections:e.brand.assetSections??[],save:e=>u({brand:e})},`assets:${_}`)})]}):null,r,t===`info`&&p&&!v&&m?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(F,{variant:`danger`,onClick:()=>l(!0),children:X(`settings.delete`)}),(0,Q.jsxs)(ye,{open:c,onClose:()=>l(!1),title:X(`settings.deleteTitle`,{name:e.name}),children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:X(`settings.deleteBody`)}),d.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:d.error.message}):null,(0,Q.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Q.jsx)(F,{variant:`ghost`,onClick:()=>l(!1),children:X(`common.cancel`)}),(0,Q.jsx)(F,{variant:`danger`,busy:d.isPending,onClick:()=>d.mutate(),children:X(`common.delete`)})]})]})]}):null]})}var wr=[{value:`de-du`,label:`page.lang.deDu`},{value:`de-sie`,label:`page.lang.deSie`},{value:`en`,label:`page.lang.en`}],$=`text-[0.8125rem] text-ink-3 leading-snug`,Tr=`font-mono text-[0.875rem]`,Er=e=>e.slice(e.indexOf(`.`)+1);function Dr(){let[e,t]=(0,Z.useState)(!1),n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),{copied:e,copy:e=>navigator.clipboard.writeText(e).then(()=>{t(!0),clearTimeout(n.current),n.current=setTimeout(()=>t(!1),1500)}).catch(()=>t(!1))}}function Or(){let e=X(`page.sources`).split(/(\{brand\}|\{facts\})/);return(0,Q.jsxs)(`p`,{className:$,children:[e.map((e,t)=>e===`{brand}`?(0,Q.jsx)(k,{to:`/space/brand`,className:`text-ink underline-offset-2 hover:underline`,children:X(`space.brand`)},t):e===`{facts}`?(0,Q.jsx)(k,{to:`/space/info#facts`,className:`text-ink underline-offset-2 hover:underline`,children:X(`project.facts`)},t):e),` `,X(`page.onlyShared`)]})}function kr({host:e,value:t,onChange:n,disabled:r}){let i=K.test(t);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex h-11 items-stretch overflow-hidden rounded-lg border border-input bg-card focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,children:[(0,Q.jsxs)(`span`,{title:`${e}/`,className:`flex max-w-[55%] items-center truncate bg-paper-2 px-3 font-mono text-[0.75rem] text-ink-3`,children:[`…`,Er(e),`/`]}),(0,Q.jsx)(`input`,{value:t,disabled:r,"aria-label":X(`page.address`),maxLength:E.slug,onChange:e=>n(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,`-`)),className:q(`min-w-0 flex-1 bg-transparent px-3 outline-none`,Tr)})]}),(0,Q.jsx)(`p`,{className:q(`mt-1.5`,$,!i&&t&&`text-rose`),children:X(`page.addressRules`)})]})}function Ar({host:e,words:t,onChange:n,disabled:r}){return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-5 sm:grid-cols-[repeat(2,minmax(0,1fr))]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(z,{children:X(`page.title`)}),(0,Q.jsx)(L,{value:t.title,disabled:r,maxLength:E.title,onChange:e=>n({title:e.target.value})}),(0,Q.jsx)(`p`,{className:q(`mt-1.5`,$),children:X(`page.titleHint`)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(z,{children:X(`page.address`)}),(0,Q.jsx)(kr,{host:e,value:t.slug,disabled:r,onChange:e=>n({slug:e})}),(0,Q.jsx)(`p`,{className:q(`mt-1`,$),children:X(`page.addressChange`)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 sm:col-span-2`,children:[(0,Q.jsx)(z,{children:X(`page.headline`)}),(0,Q.jsx)(L,{value:t.headline??``,disabled:r,maxLength:E.headline,onChange:e=>n({headline:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 sm:col-span-2`,children:[(0,Q.jsx)(z,{children:X(`page.words`)}),(0,Q.jsx)(H,{value:t.intro??``,disabled:r,minRows:3,maxLength:E.intro,onChange:e=>n({intro:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(z,{children:X(`page.lang`)}),(0,Q.jsx)(ae,{value:t.voice,onChange:e=>n({voice:e}),options:wr.map(e=>({value:e.value,label:X(e.label)}))}),(0,Q.jsx)(`p`,{className:q(`mt-1.5`,$),children:X(`page.langHint`)})]})]})}function jr(e,t){if(!e.published)return X(`page.draftNote`);if(!e.shareEnabled)return X(`page.notSharedNote`);let n=e.description.trim();return t?[n,X(`page.first`)].filter(Boolean).join(` · `):n}function Mr({wizard:e,first:t,on:n,disabled:r,onToggle:i,drag:o}){return(0,Q.jsxs)(`li`,{draggable:o?!0:void 0,onDragStart:o?.onDragStart,onDragOver:o?.onDragOver,onDrop:o?.onDrop,className:q(`flex items-center gap-3 border-border-soft border-t py-2.5 first:border-t-0`,!e.published&&`opacity-60`),children:[o?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`page.moveUp`)} / ${X(`page.moveDown`)}`,onKeyDown:o.onKeyDown,className:`grid size-7 shrink-0 cursor-grab place-items-center rounded-md text-ink-4 hover:text-ink focus:text-ink`,children:(0,Q.jsx)(a,{className:`size-4`})}):(0,Q.jsx)(`span`,{className:`size-7 shrink-0`}),(0,Q.jsx)(mt,{kind:e.avatar,costume:e.costume,size:36,interactive:!1}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium text-[0.9375rem]`,children:e.title}),(0,Q.jsx)(`p`,{className:q(`truncate`,$),children:jr(e,t)})]}),(0,Q.jsx)(be,{checked:n,disabled:r||!e.published,label:X(`page.showOnPage`),onChange:i})]})}function Nr({title:e,text:t,picked:n,disabled:r,later:i,onPick:a}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":n,disabled:r||i,onClick:a,className:q(`flex min-h-20 flex-col items-start gap-1 rounded-xl px-4 py-3 text-left transition`,n?`bg-accent ring-2 ring-primary`:i?`border border-border border-dashed opacity-60`:`ring-1 ring-border-soft hover:bg-paper-2`,(r||i)&&`cursor-not-allowed`),children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e}),(0,Q.jsx)(`span`,{className:$,children:t})]})}var Pr={desktop:1280,tablet:768,mobile:390},Fr=`wizards.pagePreviewDevice`,Ir=`wizards.pagePreviewHeight`,Lr=360,Rr=e=>e?640:480,zr=()=>Math.max(Lr,window.innerHeight-140);function Br(){try{let e=Number(localStorage.getItem(Ir));return e>=Lr?e:null}catch{return null}}function Vr(e){try{e===null?localStorage.removeItem(Ir):localStorage.setItem(Ir,String(Math.round(e)))}catch{}}function Hr(){try{let e=localStorage.getItem(Fr);return e&&e in Pr?e:`desktop`}catch{return`desktop`}}function Ur(e){try{localStorage.setItem(Fr,e)}catch{}}function Wr({url:e,version:t,device:n}){let r=(0,Z.useRef)(null),[i,a]=(0,Z.useState)({width:0,tall:!0});(0,Z.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>a({width:e.clientWidth,tall:e.clientWidth>=640});t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let o=Pr[n],[s,c]=(0,Z.useState)(Br),[l,u]=(0,Z.useState)(!1),d=(0,Z.useRef)(null),f=Math.min(s??Rr(i.tall),i.width?zr():9999),p=e=>{let t=Math.round(Math.min(zr(),Math.max(Lr,e)));return c(t),t},m=n===`mobile`,h=m?12:0,g=i.width?Math.min(1,(i.width-2*h)/o):1,_=(0,Q.jsxs)(`div`,{className:q(`relative overflow-hidden bg-paper-2`,m?`rounded-[1.5rem]`:`rounded-lg ring-1 ring-border-soft`),style:{width:Math.round(o*g),height:f},children:[i.width?(0,Q.jsx)(`iframe`,{title:X(`page.previewTitle`),src:`${e}${e.includes(`?`)?`&`:`?`}v=${t}`,tabIndex:-1,className:q(`absolute top-0 left-0 border-0`,l&&`pointer-events-none`),style:{width:o,height:Math.ceil(f/g),transform:`scale(${g})`,transformOrigin:`top left`}},t):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":X(`page.resize`),title:X(`page.resize`),onPointerDown:e=>{e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}d.current={y:e.clientY,height:f},u(!0)},onPointerMove:e=>{d.current&&p(d.current.height+e.clientY-d.current.y)},onPointerUp:e=>{d.current&&=(Vr(p(d.current.height+e.clientY-d.current.y)),null),u(!1)},onPointerCancel:()=>{d.current=null,u(!1)},onDoubleClick:()=>{c(null),Vr(null)},onKeyDown:e=>{(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),Vr(p(f+(e.key===`ArrowDown`?24:-24))))},className:`absolute right-1 bottom-1 z-10 grid size-7 cursor-ns-resize touch-none place-items-center rounded-md bg-card/90 text-ink-3 shadow-soft ring-1 ring-border-soft hover:text-ink coarse:size-9`,children:(0,Q.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 12 12`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`M11 1 1 11M11 5 5 11M11 9 9 11`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})})})]});return(0,Q.jsx)(`div`,{ref:r,className:`flex w-full justify-center`,children:m?(0,Q.jsx)(`div`,{className:`rounded-[2.25rem] bg-ink p-3 shadow-soft`,children:_}):_})}function Gr({host:e,page:t,disabled:n,save:r,onState:i}){let a=(0,Z.useRef)(t);a.current=t;let[s,c]=(0,Z.useState)(()=>({slug:t.slug,title:t.title,headline:t.headline??``,intro:t.intro??``,voice:Ve(t)})),l=o(s,async e=>{if(!(K.test(e.slug)&&e.title.trim()))return;let{lang:t,form:n}=st(e.voice);await r({...a.current,slug:e.slug,title:e.title.trim(),headline:e.headline?.trim()||void 0,intro:e.intro?.trim()||void 0,lang:t,form:n})}),{state:u,error:d}=l;return(0,Z.useEffect)(()=>i(l),[u,d]),(0,Q.jsx)(Ar,{host:e,words:s,disabled:n,onChange:e=>c(t=>({...t,...e}))})}function Kr({project:e}){let t=C(),n=ft(),r=n.data?.tenant.pagesHost??null,i=n.data?.manageUrl??null,a=e.readOnly,o=e.page,s=!!o?.on,c=Se({queryKey:ne.projectWizards(e.id),queryFn:()=>f.get(`/api/studio/projects/${e.id}/wizards`)}),[l,u]=(0,Z.useState)(1),[d,m]=(0,Z.useState)(Hr),h=(0,Z.useRef)(o);h.current=o;let g=async n=>{await f.patch(`/api/studio/projects/${e.id}`,{page:n}),await t.invalidateQueries({queryKey:ne.spaces()}),u(e=>e+1)},_=Le({mutationFn:e=>{let t=h.current;return t?g({...t,...e}):Promise.resolve()}}),[v,y]=(0,Z.useState)({state:`idle`,error:null}),{copied:x,copy:S}=Dr(),w=c.data??[],T=(o?.wizards??[]).map(e=>w.find(t=>t.id===e)).filter(e=>e!==void 0),E=w.filter(e=>!o?.wizards.includes(e.id)),[D,O]=(0,Z.useState)(null),k=(e,t)=>{let n=[...o?.wizards??[]];if(t<0||t>=n.length||e===t)return;let[r]=n.splice(e,1);n.splice(t,0,r),_.mutate({wizards:n})},ee=(e,t)=>_.mutate({wizards:t?[...o?.wizards??[],e]:(o?.wizards??[]).filter(t=>t!==e)}),A=e.brand.name?.trim()||e.name,j=Le({mutationFn:()=>g({on:!0,slug:b(A)||`page`,title:A,...st(xt===`de`?`de-du`:`en`),wizards:w.filter(e=>e.published&&e.shareEnabled).map(e=>e.id),examples:{}})}),M=e=>{o?_.mutate({on:e}):e&&j.mutate()},P=_.isPending||j.isPending,I=_.error??j.error;if(!r)return(0,Q.jsx)(J,{id:`page`,children:(0,Q.jsx)(Y,{title:X(`space.page`),hint:X(`page.intro`),children:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:X(`page.cloudOnly`)})})});let L=o?.slug||b(A)||`…`,R=We(r,L),z=ot(r,L,i),B=(0,Q.jsxs)(`span`,{className:q(Tr,`min-w-0 truncate`),children:[(0,Q.jsxs)(`span`,{className:`text-ink-3`,children:[r,`/`]}),(0,Q.jsx)(`b`,{className:`text-ink`,children:L})]}),V=a||!o,H=(0,Q.jsxs)(p,{className:`flex flex-col gap-2.5 p-4`,children:[(0,Q.jsxs)(`div`,{className:`@container flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:X(`page.previewTitle`)}),s?(0,Q.jsx)(rt,{named:!0,label:X(`editor.device`),value:d,onChange:e=>{m(e),Ur(e)},options:[{id:`desktop`,label:X(`editor.deviceDesk`),icon:(0,Q.jsx)(Ot,{className:`size-3.5`})},{id:`tablet`,label:X(`page.deviceTablet`),icon:(0,Q.jsx)(vn,{className:`size-3.5`})},{id:`mobile`,label:X(`editor.devicePhone`),icon:(0,Q.jsx)(ct,{className:`size-3.5`})}]}):null]}),s?(0,Q.jsx)(Wr,{url:z,version:l,device:d}):(0,Q.jsx)(`p`,{className:$,children:X(`page.previewOff`)}),s?(0,Q.jsx)(`p`,{className:$,children:X(`page.previewHint`)}):null]}),re=(0,Q.jsxs)(p,{className:`flex flex-col gap-3 p-4`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:X(`page.inShare`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-paper-2 px-3 py-2.5`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium text-[0.875rem]`,children:X(`share.onPage`,{space:o?.title||A})}),(0,Q.jsx)(`span`,{className:q(`block truncate font-mono`,$),children:R})]}),(0,Q.jsx)(be,{checked:!0,disabled:!0,label:X(`page.showOnPage`),onChange:()=>{}})]}),(0,Q.jsx)(`p`,{className:$,children:X(`page.inShareHint`)})]});return(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-9`,children:[(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(J,{id:`page`,children:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`px-1`,children:[(0,Q.jsx)(`h2`,{className:`font-display font-semibold text-lg leading-tight`,children:X(`space.page`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-3 leading-snug`,children:X(`page.intro`)})]}),(0,Q.jsxs)(p,{className:`flex flex-wrap items-center gap-3 p-3 sm:pl-4`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:q(`size-2 shrink-0 rounded-full`,s?`bg-moss`:`bg-ink-4`),"aria-hidden":!0}),B]}),(0,Q.jsxs)(`span`,{className:`flex w-full items-center gap-2 sm:w-auto sm:shrink-0`,children:[(0,Q.jsxs)(F,{variant:`secondary`,size:`sm`,className:`max-sm:flex-1`,disabled:!s,onClick:()=>S(z),children:[x?(0,Q.jsx)(N,{className:`size-3.5`}):(0,Q.jsx)(te,{className:`size-3.5`}),X(x?`share.copied`:`share.copyMain`)]}),(0,Q.jsxs)(F,{size:`sm`,className:`max-sm:flex-1`,disabled:!s,onClick:()=>window.open(z,`_blank`,`noopener`),children:[X(`page.open`),` `,(0,Q.jsx)(Vt,{className:`size-3.5`})]})]})]}),(0,Q.jsxs)(Y,{title:X(`page.sectionPage`),locked:a,children:[(0,Q.jsxs)(`fieldset`,{"aria-label":X(`page.sectionPage`),className:`grid min-w-0 gap-3 sm:grid-cols-[repeat(3,minmax(0,1fr))]`,children:[(0,Q.jsx)(Nr,{title:X(`page.whoOff`),text:X(`page.whoOffHint`),picked:!s,disabled:a||P,onPick:()=>M(!1)}),(0,Q.jsx)(Nr,{title:X(`page.whoPublic`),text:X(`page.whoPublicHint`),picked:s,disabled:a||P,onPick:()=>M(!0)}),(0,Q.jsx)(Nr,{title:X(`page.whoMembers`),text:X(`page.whoMembersHint`),picked:!1,later:!0,onPick:()=>{}})]}),I?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:I.message}):null]})]})}),H,(0,Q.jsx)(J,{id:`page-words`,children:(0,Q.jsx)(Y,{title:X(`page.sectionWords`),hint:o?void 0:X(`page.notYet`),save:o?v:void 0,locked:V,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[o?(0,Q.jsx)(Gr,{host:r,page:o,disabled:a,save:g,onState:y},`${e.id}:${o.slug}`):(0,Q.jsx)(Ar,{host:r,disabled:!0,words:{slug:L,title:A,headline:``,intro:``,voice:xt===`de`?`de-du`:`en`},onChange:()=>{}}),(0,Q.jsxs)(`div`,{id:`page-wizards`,className:`scroll-mt-6 border-border-soft border-t pt-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:X(`page.sectionWizards`)}),(0,Q.jsx)(`span`,{className:$,children:X(`page.wizardsHint`)})]}),(0,Q.jsxs)(`ul`,{className:`mt-2 flex flex-col`,children:[T.map((e,t)=>(0,Q.jsx)(Mr,{wizard:e,first:t===0,on:!0,disabled:V,onToggle:t=>ee(e.id,t),drag:{onDragStart:()=>O(t),onDragOver:e=>e.preventDefault(),onDrop:()=>{D!==null&&k(D,t),O(null)},onKeyDown:e=>{(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),k(t,e.key===`ArrowUp`?t-1:t+1))}}},e.id)),E.map(e=>(0,Q.jsx)(Mr,{wizard:e,first:!1,on:!1,disabled:V,onToggle:t=>ee(e.id,t)},e.id))]}),w.length?null:(0,Q.jsx)(`p`,{className:q(`mt-2`,$),children:X(`page.noWizards`)}),(0,Q.jsx)(`p`,{className:q(`mt-4`,$),children:X(`page.wizardsNote`)})]}),(0,Q.jsx)(Or,{})]})})})]}),re]})}var qr=`results-search`,Jr={q:``,mode:``,days:0};function Yr(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 Se({queryKey:[`results`,e,i],queryFn:()=>f.get(`/api/studio/projects/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function Xr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Z.useState)(r.q);return wt({icon:le,label:X(`space.resultsSearch`),run:()=>{let e=document.getElementById(qr);e?.scrollIntoView({block:`center`,behavior:`smooth`}),e?.focus()}}),(0,Z.useEffect)(()=>{if(a===r.q)return;let e=setTimeout(()=>i({...r,q:a}),250);return()=>clearTimeout(e)},[a,r,i]),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(ae,{value:t??``,onChange:e=>n(e||null),options:[{value:``,label:X(`space.resultsAllWizards`)},...e.wizards.filter(e=>e.results||e.id===t).map(e=>({value:e.id,label:`${e.title} (${e.results})`}))],className:`w-56 max-sm:w-full`}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,Q.jsx)(le,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,Q.jsx)(L,{type:`search`,value:a,onChange:e=>o(e.target.value),id:qr,placeholder:X(`space.resultsSearch`),"aria-label":X(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,Q.jsx)(ae,{value:r.mode,onChange:e=>i({...r,mode:e}),options:[{value:``,label:X(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,Q.jsx)(ae,{value:String(r.days),onChange:e=>i({...r,days:Number(e)}),options:[{value:`0`,label:X(`space.resultsAnyTime`)},{value:`1`,label:X(`space.resultsDay`)},{value:`7`,label:X(`space.resultsDays`,{n:7})},{value:`30`,label:X(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function Zr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Z.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,l=new Intl.DateTimeFormat(xt,{dateStyle:`medium`,timeStyle:`short`});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Y,{title:t?s(t):X(`space.resultsAll`),hint:X(`space.resultsHint`),plain:!0,children:[(0,Q.jsx)(Xr,{data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}),e.runs.length?(0,Q.jsx)(p,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,Q.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,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?l.format(new Date(e.doneAt)):s(e.wizardId)}),(0,Q.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${l.format(new Date(e.doneAt))} · `,X(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:X(`space.resultFiles`,{n:e.assets}),children:[(0,Q.jsx)(c,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,Q.jsx)(y,{children:X(`run.testChip`)}):(0,Q.jsxs)(y,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,Q.jsx)(p,{children:(0,Q.jsx)(_,{children:r.q.trim()||r.mode||r.days?X(`space.resultsNone`):X(`space.resultsEmpty`)})})]}),a?(0,Q.jsx)(tt,{header:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(a.wizardId)}),a.mode===`test`?(0,Q.jsx)(y,{children:X(`run.testChip`)}):(0,Q.jsxs)(y,{tone:`live`,children:[`Live v`,a.version]})]}),onClose:()=>o(null),children:(0,Q.jsx)(lt,{runId:a.id,compact:!0,studio:!0},a.id)}):null]})}function Qr(e){let t=e.join(` `),[n,r]=(0,Z.useState)(e[0]);return(0,Z.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=Qt(),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 $r(){let[e,t]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{let e=Qt(),n=()=>t(e.clientHeight);n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),e}function ei(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function ti({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,Q.jsx)(Pt,{icon:e.icon??Ie,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,Q.jsx)(Mt,{label:e.label,children:r},e.plugin):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function ni(){let{group:e}=re(),[t,n]=_e(),r=de(),i=xe(),{hash:a}=i,{project:o,loading:s}=ut(),c=Zt(),l=Gt(),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(null),g=Bt(e)?e:void 0,v=g?void 0:c.spaceParts.find(t=>t.id===e),y=g??v?.id,b=i.state?.parts===!0,x=Tt(`pages`),S=Wt().filter(e=>x||e.id!==`page`),C=Ht(S,c).map(e=>({...e,to:`/space/${e.id}`})),w={id:`results`,label:X(`space.results`),icon:Ft,to:`/space/results`},T=g===`results`?w:C.find(e=>e.id===y),E=t.get(`show`),D=g===`results`?2:y?E?2:1:0,O=g===`results`?1:l?Math.min(D,1):y&&m!==y&&!b?1:0,k=Ut(O),ee=Ut(D),te=(0,Z.useMemo)(()=>({slot:u,narrow:l,setDetail:p}),[u,l]),A=o?o.brand.name?.trim()||o.name:X(`nav.space`),j=Tt(`typography`)?[]:[`typography`],M=v?c.spaceMenus[v.id]??[]:[],N=v?[{plugin:null,label:null,sections:M}]:g&&g!==`results`?Kt(g,c,j):[],P=g?Kt(g,c).filter(e=>e.plugin):[],ne=Qr([...N,...g===`results`?P:[]].flatMap(e=>e.sections.map(e=>e.id))),F=g===`results`&&E&&E!==`all`?E:null,[I,L]=(0,Z.useState)(Jr),R=Yr(g===`results`?o?.id:void 0,F,I),z=R.data?.wizards.find(e=>e.id===F)?.title,B=g===`data`&&E&&E!==`all`||g===`knowledge`&&E&&/^[ptfcvs]:/.test(E)?E:null,V=B?.startsWith(`s:`)?c.spaceSections.find(e=>e.id===B.slice(2)):void 0,H=g===`knowledge`&&B&&/^[ptf]:/.test(B)?B:null,ie=Ge(g===`data`?o?.id:void 0),U=Qe(g===`knowledge`?o?.id:void 0),W=at(B?.startsWith(`v:`)?B.slice(2):``),ae=U.data?.categories.find(e=>e.id===(B?.startsWith(`c:`)?B.slice(2):W.data?.category.id)),se=g===`knowledge`?V?V.label():B?.startsWith(`v:`)?W.data&&`${W.data.category.name}: ${W.data.value}`:B?.startsWith(`c:`)?ae?.name:U.data?.items.find(e=>e.key===B)?.title:ie.data?nt(ie.data).flatMap(e=>e.items).find(e=>e.key===B)?.title:void 0;$t([...g===`results`?[]:[{label:X(`nav.sources`),to:`/space`}],...T?[{label:T.label,to:`/space/${T.id}`}]:[],...T&&(f??z??se)?[{label:f??z??se}]:[]]);let ce={p:`page`,t:`table`,f:`file`,c:`category`,v:`category value`,s:`plugin section`};At({...g===`data`||g===`results`?{compact:!0}:{},...g===`data`?{suggestions:[{label:X(`assistant.suggest.dataWhat`)},{label:X(`assistant.suggest.dataWho`)},{label:X(`assistant.suggest.dataEdit`)}]}:g===`results`?{suggestions:[{label:X(`assistant.suggest.resultsFailed`)},{label:X(`assistant.suggest.resultsCost`)},{label:X(`assistant.suggest.resultsShare`)}]}:{},...B&&se?{open:{kind:ce[B[0]]??`item`,id:B.slice(2),label:se}}:F&&z?{open:{kind:`wizard`,id:F,label:z}}:{}});let G=g===`results`||g===`data`||B?a.slice(1):E||a.slice(1),le=(0,Z.useRef)(``);(0,Z.useEffect)(()=>{let e=`${y}#${G}`;G&&le.current!==e&&document.getElementById(G)&&(le.current=e,requestAnimationFrame(()=>ei(G,!1)))},[y,G,o?.id,c.spaceSections,M.length]),(0,Z.useEffect)(()=>{!l&&(y===`knowledge`||y===`data`)&&Qt().scrollTo({top:0})},[l,y,B]);let ue=$r();if(!y){let t=a.slice(1),n=t?Lt(t,c):null;if(n===`knowledge`&&c.spaceSections.some(e=>e.id===t))return(0,Q.jsx)(oe,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,Q.jsx)(oe,{to:l?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if((t||e)&&c.status!==`ready`)return null;if(e!==void 0||!l)return(0,Q.jsx)(oe,{to:`/space/info`,replace:!0,state:{parts:!0}})}let fe=g===`info`?E??a.slice(1):``;if(fe&&Lt(fe,c)===`brand`)return(0,Q.jsx)(oe,{to:l?`/space/brand?show=${fe}`:{pathname:`/space/brand`,hash:fe},replace:!0});if(g===`knowledge`&&!E&&c.spaceSections.some(e=>e.id===a.slice(1)))return(0,Q.jsx)(oe,{to:`/space/knowledge?show=s:${a.slice(1)}`,replace:!0});let pe=e=>{if(l){r({search:`?show=${e}`});return}le.current=`${y}#${e}`,ei(e,!0),r({search:``,hash:e},{replace:!0})},K=e=>l?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),me=e=>e.flatMap(e=>e.sections).map(e=>c.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,Q.jsx)(J,{id:e.id,children:(0,Q.jsx)(Y,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,Q.jsx)(Yt,{of:e,children:(0,Q.jsx)(e.component,{})})})},e.serial)),he=l?void 0:ne,ge=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Dt,{title:A,open:O===1?T??null:null,onBack:g===`results`?void 0:()=>l?r(`/space`):h(y??null),root:{icon:Xt,label:X(`nav.sources`),backLabel:X(`nav.wizards`),onBack:()=>r(`/`)}}),(0,Q.jsx)(`div`,{className:q(zt(k)),children:O===0?(0,Q.jsx)(Nt,{entries:C,current:l?void 0:T,onPick:()=>h(null)}):(0,Q.jsx)(`div`,{ref:d})},O)]});return(0,Q.jsx)(kt.Provider,{value:te,children:(0,Q.jsx)(`div`,{className:`animate-rise`,children:(0,Q.jsxs)(`div`,{className:q(`grid gap-6`,g!==`results`&&`md:grid-cols-[10.5rem_minmax(0,1fr)] md:gap-5 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[g===`results`?null:(0,Q.jsx)(`aside`,{className:q(`min-w-0 md:sticky md:top-6 md:self-start md:overflow-y-auto md:overscroll-contain`,l&&D===2&&`hidden`,l&&ee===`back`&&zt(`back`)),style:!l&&ue?{maxHeight:ue-48,paddingBottom:`var(--assistant-dock, 0px)`}:void 0,children:ge}),y?(0,Q.jsxs)(`div`,{className:q(`min-w-0`,l&&D<2&&`hidden`,l&&ee===`deeper`&&zt(`deeper`)),children:[l&&g!==`results`?(0,Q.jsx)(`div`,{className:`mb-3`,children:(0,Q.jsx)(qt,{label:T?.label??A,onBack:()=>r(`/space/${y}`)})}):null,g===`data`?(0,Q.jsxs)(St,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Q.jsx)(Pt,{icon:Rt,label:X(`data.all`),selected:!l&&!B,onPick:()=>K(`all`)})}),ie.data?nt(ie.data).map(e=>(0,Q.jsx)(Mt,{label:e.label,children:e.items.map(e=>(0,Q.jsx)(Pt,{icon:Ue[e.kind],label:e.title,selected:!l&&e.key===B,onPick:()=>K(e.key)},e.key))},e.key)):null,(0,Q.jsx)(ti,{groups:P,current:he,onPick:pe})]}):g===`knowledge`?(0,Q.jsxs)(St,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Q.jsx)(Pt,{icon:Rt,label:X(`know.all`),selected:!(l||B),onPick:()=>K(`all`)})}),U.data?.categories.length?(0,Q.jsx)(Mt,{label:X(`know.categories`),children:U.data.categories.map(e=>(0,Q.jsx)(Pt,{icon:Ye[e.type],label:e.name,badge:(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!l&&(B===`c:${e.id}`||W.data?.category.id===e.id),onPick:()=>K(`c:${e.id}`)},e.id))}):null,(0,Q.jsx)(ti,{groups:P,current:l?void 0:V?.id,onPick:e=>K(`s:${e}`)})]}):(0,Q.jsx)(St,{children:(0,Q.jsx)(ti,{groups:N,current:he,onPick:pe})}),o&&(g===`info`||g===`brand`||g===`knowledge`)?(0,Q.jsxs)(Cr,{project:o,group:g,top:!B||!!V,children:[g===`knowledge`?H?H.startsWith(`p:`)?(0,Q.jsx)(Ze,{pageId:H.slice(2),onGone:()=>K(`all`),onOpen:K},H):H.startsWith(`t:`)?(0,Q.jsx)(Xe,{tableId:H.slice(2),onGone:()=>K(`all`)},H):(0,Q.jsx)(jn,{projectId:o.id,fileId:H.slice(2),readOnly:o.readOnly,onGone:()=>K(`all`)},H):U.data?V?(0,Q.jsx)(Y,{title:V.label(),hint:V.hint?.(),plain:!0,children:(0,Q.jsx)(Yt,{of:V,children:(0,Q.jsx)(V.component,{})})},B):B?.startsWith(`c:`)?ae?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(Je,{projectId:o.id,category:ae,readOnly:o.readOnly,onOpen:K,onGone:()=>K(`all`)}),ae.type===`choice`?null:(0,Q.jsx)(it,{projectId:o.id,category:ae,categories:U.data.categories,onOpen:K})]},B):null:B?.startsWith(`v:`)?W.data?(0,Q.jsx)(He,{value:W.data,readOnly:o.readOnly,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[W.data.items.length?(0,Q.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:W.data.items.map(e=>(0,Q.jsx)(Ke,{item:e,categories:U.data.categories.filter(e=>e.id!==W.data?.category.id),onOpen:K},e.key))}):null,W.data.rows.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>K(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:X(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},B):null:(0,Q.jsx)(J,{id:`documents`,children:(0,Q.jsx)(et,{projectId:o.id,data:U.data,readOnly:o.readOnly,onOpen:K})}):null:null,g===`info`||g===`brand`?me(P):null]},o.id):null,o&&g===`page`&&x?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[(0,Q.jsx)(Kr,{project:o},o.id),me(P)]}):null,o&&v?(0,Q.jsx)(Yt,{of:v,children:(0,Q.jsx)(It,{part:v.id,children:(0,Q.jsx)(v.component,{})},o.id)}):null,o&&g===`data`?(0,Q.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:B?.startsWith(`t:`)?(0,Q.jsx)(Xe,{tableId:B.slice(2),onGone:()=>K(`all`)},B):B?.startsWith(`p:`)?(0,Q.jsx)(Ze,{pageId:B.slice(2),onGone:()=>K(`all`)},B):(0,Q.jsxs)(Q.Fragment,{children:[ie.data?(0,Q.jsx)($e,{projectId:o.id,data:ie.data,readOnly:o.readOnly,onOpen:K}):null,me(P)]})}):null,o&&g===`results`?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[R.data?(0,Q.jsx)(Zr,{data:R.data,wizardId:F,onWizard:e=>K(e??`all`),filter:I,onFilter:L}):null,R.isError?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:R.error.message}):null,me(P)]}):null,o||s?null:(0,Q.jsx)(_,{children:X(`settings.noProject`)})]}):null]})})})}export{ni as ProjectPage};
|