@engenty/wizards-runtime 0.9.1 → 0.9.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.
Files changed (54) hide show
  1. package/README.md +24 -13
  2. package/apps/runtime/dist/docs/dev/plugins/runners.md +1 -1
  3. package/apps/runtime/dist/docs/dev/wizard-format/index.md +4 -53
  4. package/apps/runtime/dist/docs/dev/wizard-format/meta.json +1 -0
  5. package/apps/runtime/dist/docs/dev/wizard-format/pages-and-fields.md +17 -0
  6. package/apps/runtime/dist/docs/dev/wizard-format/themes.md +220 -0
  7. package/apps/runtime/dist/docs/dev/wizard-format/wizard-file.md +2 -0
  8. package/apps/runtime/dist/docs/user/run.md +15 -1
  9. package/apps/runtime/dist/docs/user/space.md +4 -0
  10. package/apps/runtime/dist/files/upload-check.js +622 -0
  11. package/apps/runtime/dist/harness/terminal.js +14 -7
  12. package/apps/runtime/dist/index.js +2 -0
  13. package/apps/runtime/dist/no-webstorage.js +6 -0
  14. package/apps/runtime/dist/plugins/runs.js +8 -5
  15. package/apps/runtime/dist/routes/runs.js +22 -6
  16. package/apps/runtime/dist/routes/studio.js +2 -2
  17. package/apps/runtime/dist/services/project-files.js +14 -6
  18. package/apps/web/dist/assets/{AboutDialog-DKfHXQUv.js → AboutDialog-BUdEn9X_.js} +1 -1
  19. package/apps/web/dist/assets/{ChangelogDialog-BsM9zGdh.js → ChangelogDialog-ClkjHGE_.js} +1 -1
  20. package/apps/web/dist/assets/{EditorPage-CRcgupmQ.js → EditorPage-j5HjqTMV.js} +2 -2
  21. package/apps/web/dist/assets/{FlowPreview-szPmsT2-.js → FlowPreview-DZRkWedM.js} +1 -1
  22. package/apps/web/dist/assets/{Harness-CXx-Js4U.js → Harness-FiDeF3LX.js} +1 -1
  23. package/apps/web/dist/assets/{NewWizardChannels-C6R1HV0I.js → NewWizardChannels-DeJP5h5I.js} +1 -1
  24. package/apps/web/dist/assets/{NewWizardPage-D6Z6DYeT.js → NewWizardPage-CIS3qNUz.js} +1 -1
  25. package/apps/web/dist/assets/{OnboardingPage-DrN26Afr.js → OnboardingPage-CoTYSubc.js} +1 -1
  26. package/apps/web/dist/assets/{ProjectPage-CNyhwfgz.js → ProjectPage-XVhe87S4.js} +1 -1
  27. package/apps/web/dist/assets/{PublicRunner-CREvMYW_.js → PublicRunner-Bc-3e7UU.js} +1 -1
  28. package/apps/web/dist/assets/{ReadOnly-BUyOPou5.js → ReadOnly-I-Lm7a8y.js} +1 -1
  29. package/apps/web/dist/assets/{RunDrawer-8iWXyXjL.js → RunDrawer-DXqyxTsm.js} +1 -1
  30. package/apps/web/dist/assets/{RunnerView-CufG6xDP.js → RunnerView-DeDApA-9.js} +1 -1
  31. package/apps/web/dist/assets/{SettingsPage-B4M4DrMS.js → SettingsPage-ChpDzJVn.js} +2 -2
  32. package/apps/web/dist/assets/{SetupPage-D-Op38jE.js → SetupPage-E5JoQMBM.js} +1 -1
  33. package/apps/web/dist/assets/{SharePage-BXYVZ3Fa.js → SharePage-DW1b2g9t.js} +1 -1
  34. package/apps/web/dist/assets/changelog-DuSV2HiU.js +1 -0
  35. package/apps/web/dist/assets/{esm-CetquljB.js → esm-yMT-rSPa.js} +1 -1
  36. package/apps/web/dist/assets/{index-C5Qmfm_0.css → index-D9oqYYa8.css} +1 -1
  37. package/apps/web/dist/assets/{index-TJhB4-x8.js → index-DfHH4icT.js} +4 -4
  38. package/apps/web/dist/assets/oss-credits-6A3pxilr.js +1 -0
  39. package/apps/web/dist/assets/{phone-CJVAobUx.js → phone-BprN_SDS.js} +1 -1
  40. package/apps/web/dist/assets/{settings-menu-DjgZMuyV.js → settings-menu-CVl54phq.js} +1 -1
  41. package/apps/web/dist/assets/{theme-BucH2rUv.js → theme-DZZXa238.js} +1 -1
  42. package/apps/web/dist/assets/{ui-LJgQlXbd.js → ui-kIzOrA_W.js} +1 -1
  43. package/apps/web/dist/assets/{upload-Dz86uI5u.js → upload-Cvztyjuj.js} +1 -1
  44. package/apps/web/dist/assets/{wrench-Dr5LakQv.js → wrench-CWT9IGKq.js} +1 -1
  45. package/apps/web/dist/index.html +3 -3
  46. package/apps/web/dist/install.sh +43 -3
  47. package/apps/web/dist/mcp/flow.html +2 -2
  48. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +4 -0
  49. package/node_modules/@engenty/wizards-shared/dist/run.js +8 -0
  50. package/package.json +2 -4
  51. package/plugin/.claude-plugin/plugin.json +1 -1
  52. package/plugin/plugin.json +1 -1
  53. package/apps/web/dist/assets/changelog-KvwOYLcI.js +0 -1
  54. package/apps/web/dist/assets/oss-credits-BvQGQEzd.js +0 -1
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{A as r,B as i,Bt as a,C as o,Ci as s,Cr as c,D as l,Dr as u,E as d,F as f,Ft as p,Gn as m,Gr as h,Gt as g,I as _,It as v,Jr as y,Jt as b,Kt as x,L as S,Lr as C,Lt as w,M as T,O as E,P as D,Pr as O,Pt as k,Qr as A,Qt as j,R as ee,Rt as te,S as ne,T as M,Tr as re,Ut as N,V as P,Vr as F,Vt as I,Wt as ie,Xr as ae,Xt as L,Yr as oe,Yt as R,Zr as se,_ as ce,b as z,br as B,cr as V,d as H,f as U,fr as W,g as le,gr as ue,h as G,j as de,k as fe,kr as pe,lt as K,m as me,or as he,p as ge,pr as _e,qt as ve,rn as q,rr as J,ur as ye,v as be,w as xe,wr as Se,x as Y,xr as Ce,y as X,z as we,zt as Z}from"./ui-LJgQlXbd.js";import{S as Te,_ as Ee,a as De,c as Oe,d as ke,f as Ae,g as je,h as Me,i as Ne,l as Pe,m as Fe,n as Ie,o as Le,p as Re,s as ze,u as Be,v as Ve,x as He,y as Ue}from"./RunDrawer-8iWXyXjL.js";import{t as We}from"./phone-CJVAobUx.js";import{n as Ge,r as Ke,t as qe}from"./ReadOnly-BUyOPou5.js";import{t as Je}from"./upload-Dz86uI5u.js";import{Ct as Ye,Gt as Xe,Qt as Ze,Sn as Qe,St as $e,Ut as et,Yt as tt,an as nt,b as rt,c as it,d as at,f as ot,h as st,in as ct,m as lt,mn as ut,mt as dt,nt as ft,p as pt,qt as mt,s as ht,sn as gt,u as _t,un as vt,ut as yt,v as bt,wt as xt,y as St,zt as Ct}from"./index-TJhB4-x8.js";import{a as wt,c as Tt,f as Et,i as Dt,n as Ot,o as kt,r as At,s as jt,t as Mt,u as Nt}from"./settings-menu-DjgZMuyV.js";import{t as Pt}from"./RunnerView-CufG6xDP.js";var Ft={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Ft.node;var It=F(Ft),Lt={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`}]]};Lt.node;var Rt=F(Lt),zt={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`}]]};zt.node;var Bt=F(zt),Vt={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`}]]};Vt.node;var Ht=F(Vt),Ut={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`]};Ut.node;var Wt=F(Ut),Gt={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Gt.node;var Kt=F(Gt),qt={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};qt.node;var Jt=F(qt),Yt={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};Yt.node;var Xt=F(Yt),Zt={name:`music`,size:24,node:[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]};Zt.node;var Qt=F(Zt),Q=e(t(),1),$=e(n(),1),$t={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function en({file:e,actions:t}){let[n,r]=(0,Q.useState)(e.description),i=(0,Q.useRef)(e.description),a=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Q.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,$.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:q(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 tn(e,t){confirm(q(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function nn({projectId:e,file:t,small:n}){let r=_(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:L(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,$.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,$.jsx)(rn,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,$.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,$.jsx)(Qt,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(Se,{className:i}):t.mime===`application/json`?(0,$.jsx)(he,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(Rt,{className:i}):(0,$.jsx)(c,{className:i}),n?null:(0,$.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function rn({src:e,small:t}){let[n,r]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,$.jsx)(`div`,{className:L(`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 an=`application/x-wizards-logo`;function on({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):tn(e,r);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,$.jsxs)(`div`,{draggable:u&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(an,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,$.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,$.jsx)(v,{tone:`ember`,children:q(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?$t:void 0,children:[s&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${q(`project.preview`)}: ${n.name}`,onClick:()=>s(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(nn,{projectId:e,file:n})}):(0,$.jsx)(nn,{projectId:e,file:n}),(0,$.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,$.jsx)(Z,{label:q(`project.preview`),onClick:()=>s(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(ut,{className:`size-4`})}):null,l&&n.id!==c&&!r.readOnly?(0,$.jsx)(Z,{label:q(`project.logoMakeMain`),onClick:()=>l(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(Xe,{className:`size-4`})}):null,u&&!r.readOnly?(0,$.jsx)(le,{options:u.options,value:u.current(n),onChange:e=>u.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:()=>f(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})]}),t===`asset`?(0,$.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,$.jsx)(en,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,$.jsxs)(me,{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,$.jsx)(g,{className:`size-5`}):(0,$.jsx)(W,{className:`size-5`}),a]}):null]})}function sn({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)([]),h=async()=>{c(!0),u(null);try{let a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(f(a.candidates),m([a.candidates[0].url])):u(q(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){u(e.message)}c(!1)},g=async()=>{c(!0),u(null);let e=[];try{for(let n of p){let r=await t(n);r.file&&e.push(r.file)}}catch(e){u(e.message)}c(!1),e.length&&n(e),e.length===p.length&&r()};return(0,$.jsx)(w,{open:!0,onClose:r,wide:d?!0:void 0,title:q(d?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:d?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:d.map(t=>{let n=p.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>m(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:L(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:$t,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:L(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(O,{className:`size-3.5`})}):null]},t.url)})}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>f(null),children:q(`run.back`)}),(0,$.jsx)(k,{busy:s,disabled:!p.length,onClick:()=>void g(),children:p.length>1?q(`project.addMany`,{n:p.length}):q(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.logoUrl`)}),(0,$.jsx)(a,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>o(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:r,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:s,disabled:!i.trim(),children:q(`run.next`)})]})]})})}function cn(e,t,n){return A({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>P.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function ln(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var un=e=>[ln(e),e.pages?q(`project.pages`,{n:e.pages}):null,m(e.size)].filter(Boolean).join(` · `),dn=2e5;function fn({projectId:e,fileId:t,readOnly:n,onGone:r}){let a=s(),o=i(e),c=Fe(e),l=ee(e,n),u=o.data?.files.find(e=>e.id===t),d=u?u.mime===`application/pdf`||u.mime.startsWith(`image/`):!1,[f,m]=(0,Q.useState)(null);if(!u)return o.isLoading?(0,$.jsx)(g,{className:`mx-auto text-ink-3`}):null;let h=f??(d?`original`:`text`),v=c.data?.items.find(e=>e.key===`f:${u.id}`),y=_(e,u.id),b=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":h===e,onClick:()=>m(e),className:L(`rounded-full px-3 py-1 text-[0.8125rem] transition`,h===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,$.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:u.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:un(u)}),(0,$.jsx)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,"aria-label":q(`project.openOriginal`),title:q(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(re,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{label:q(`project.reindex`),onClick:async()=>{await l.reindex(u.id),await a.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(ye,{className:`size-4`})}),(0,$.jsx)(Z,{label:q(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(q(`data.confirmDelete`,{title:u.name}))&&(await l.remove(u.id),await a.invalidateQueries({queryKey:[`knowledge`,e]}),r())},children:(0,$.jsx)(J,{className:`size-4`})})]})]}),(0,$.jsx)(Ae,{projectId:e,itemKey:`f:${u.id}`,has:v?.categories??[],originLabel:v?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(en,{file:u,actions:l})}),u.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:u.error}):null,(0,$.jsxs)(p,{className:`flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[d?b(`original`,q(`project.original`)):null,b(`text`,q(`project.readText`))]}),h===`original`?u.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:y,title:u.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:y,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(pn,{projectId:e,file:u})]})]})}function pn({projectId:e,file:t}){let n=cn(e,t,dn);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(g,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(K,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:q(`project.textCut`,{shown:n.data.text.length.toLocaleString(j),total:n.data.chars.toLocaleString(j)})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:q(`project.noText`)})}var mn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,hn=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),m(e.size)].filter(Boolean).join(` · `);function gn({projectId:e,file:t,actions:n,onClose:r}){let i=_(e,t.id);return(0,$.jsxs)(w,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,$.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:hn(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":q(`project.openOriginal`),title:q(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(re,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:$t,children:(0,$.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,$.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,$.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(en,{file:t,actions:n})})]})}function _n({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,$.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`${q(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(nn,{projectId:e,file:t,small:!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:hn(t)})]}),(0,$.jsx)(en,{file:t,actions:n})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,$.jsx)(Z,{label:q(`project.preview`),onClick:i,children:(0,$.jsx)(ut,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(le,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})]})}function vn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,o]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(w,{open:!0,onClose:r,title:q(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.assetSectionName`)}),(0,$.jsx)(a,{autoFocus:!0,value:i,maxLength:80,placeholder:q(`project.assetSectionTitle`),onChange:e=>o(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(k,{variant:`danger`,onClick:n,children:q(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(k,{variant:`ghost`,onClick:r,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,disabled:!i.trim(),children:q(e?`settings.save`:`project.add`)})]})]})})}function yn({projectId:e,data:t,readOnly:n,sections:r,save:i}){let a=ee(e,n),[o,s]=we(`assets`,`cards`),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(r),[m,h]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(null),[y,x]=(0,Q.useState)(!1),C=(0,Q.useRef)(null),w=S({assetSections:f},i),T=t.files.filter(e=>e.kind===`asset`),D=new Map(T.map(e=>[e.id,e])),O=new Set(f.flatMap(e=>e.assets)),k=f.find(e=>e.id===m)??null,A=k?k.assets.map(e=>D.get(e)).filter(e=>!!e):T.filter(e=>!O.has(e.id)),j=T.find(e=>e.id===u),te=c.trim().toLowerCase(),ne=te?A.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(te)):A,M=(e,t)=>p(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),re=async e=>{let t=k?.id??null;for(let n of await a.upload(`asset`,e))M(n.id,t)},N=e=>{confirm(q(`project.removeConfirm`,{name:e.name}))&&(a.remove(e.id),M(e.id,null))},P=f.length?{options:[{value:``,label:q(`project.assetsGeneral`)},...f.map(e=>({value:e.id,label:e.title||q(`project.sectionUntitled`)}))],current:e=>f.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>M(e.id,t||null)}:void 0,F=[{label:q(`project.assetUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>C.current?.click()},{label:q(`project.assetFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>x(!0)},...f.length<E.logoSections?[{label:q(`project.assetSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>v(`new`)}]:[]],I=f.length||T.length?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[f.length?(0,$.jsx)(b,{value:m,onChange:e=>{h(e),l(``)},label:q(`project.assets`),options:[{id:``,label:q(`project.assetsGeneral`)},...f.map(e=>({id:e.id,label:e.title||q(`project.sectionUntitled`)}))]}):null,k&&!n?(0,$.jsx)(Z,{label:q(`project.assetSectionRename`),onClick:()=>v(`current`),children:(0,$.jsx)(_e,{className:`size-4`})}):null]}),A.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(be,{value:c,onChange:l,placeholder:q(`project.assetSearch`)})}),(0,$.jsx)(Z,{label:q(o===`list`?`project.viewCards`:`project.viewList`),onClick:s,children:o===`list`?(0,$.jsx)(Kt,{className:`size-4`}):(0,$.jsx)(Xt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(X,{title:q(`project.assets`),hint:q(`project.assetsHint`),save:w,tabs:I,action:n?null:(0,$.jsx)(H,{entries:F}),children:[(0,$.jsx)(`input`,{ref:C,type:`file`,multiple:!0,accept:mn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&re(t)}}),ne.length?o===`cards`?(0,$.jsx)(on,{projectId:e,kind:`asset`,files:ne,actions:a,moveTo:P,onRemove:N,onPreview:e=>d(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:ne.map(t=>(0,$.jsx)(_n,{projectId:e,file:t,actions:a,moveTo:P,onPreview:()=>d(t.id),onRemove:()=>N(t)},t.id))}):A.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:q(`project.staysLocal`)}):(0,$.jsxs)(me,{accept:mn,onFiles:e=>void re(e),className:`h-16 w-full`,children:[a.busy?(0,$.jsx)(g,{className:`size-4`}):(0,$.jsx)(Je,{className:`size-4`}),q(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:q(`project.assetAdd`)})]}),a.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error}):null,j?(0,$.jsx)(gn,{projectId:e,file:j,actions:a,onClose:()=>d(null)}):null,_?(0,$.jsx)(vn,{section:_===`current`?k:null,onClose:()=>v(null),onSave:e=>{if(_===`current`&&k)p(t=>t.map(t=>t.id===k.id?{...t,title:e}:t));else{let t=Y();p(n=>[...n,{id:t,title:e,assets:[]}]),h(t)}},onRemove:_===`current`&&k?()=>{(!k.assets.length||confirm(q(`project.assetSectionRemoveConfirm`,{name:k.title})))&&(p(e=>e.filter(e=>e.id!==k.id)),h(``),v(null))}:void 0}):null,y?(0,$.jsx)(sn,{kind:`asset`,onClose:()=>x(!1),fetchUrl:e=>a.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)M(t.id,k?.id??null)}}):null]})}var bn=/^#[0-9a-fA-F]{6}$/;async function xn(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 Sn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function Cn({projectId:e,gradient:t,isNew:n,brand:r,onSave:i,onClose:o}){let[s,c]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(T(t)),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!n),E=e=>{c(e),d(T(e)),m(!1)},D=(e,t)=>E({...s,stops:s.stops.map((n,r)=>r===e?{...n,...t}:n)}),O=e=>{let t=[...s.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));E({...s,stops:[...s.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},A=async()=>{v(!0),b(null);try{let{gradient:t}=await P.post(`/api/studio/projects/${e}/gradients/describe`,{text:h.trim(),...S?{gradient:{name:s.name,type:s.type,angle:s.angle,stops:s.stops}}:{}});E({...s,...t,name:s.name.trim()?s.name:t.name}),g(``),C(!0)}catch(e){b(e.message)}v(!1)};return(0,$.jsx)(w,{open:!0,onClose:o,wide:!0,title:q(n?`project.gradientNew`:`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h.trim()&&!_&&A()},children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(a,{"data-autofocus":n||void 0,value:h,maxLength:1e3,"aria-label":q(`project.gradientDescribe`),placeholder:q(S?`project.gradientDescribeChange`:`project.gradientDescribeNew`),onChange:e=>g(e.target.value),className:`min-w-0 flex-1`}),(0,$.jsxs)(k,{type:`submit`,variant:`secondary`,busy:_,disabled:!h.trim(),children:[(0,$.jsx)(he,{className:`size-4`}),q(S?`project.gradientDescribeApply`:`project.gradientDescribeMake`)]})]}),(0,$.jsx)(`p`,{className:L(`mt-1.5 text-[0.8125rem]`,y?`text-rose`:`text-ink-3`),children:y??q(`project.gradientDescribeHint`)})]}),(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:T(s)}}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.gradientName`)}),(0,$.jsx)(a,{value:s.name,maxLength:80,placeholder:q(`project.gradientNamePlaceholder`),onChange:e=>c({...s,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.fillUseLabel`)}),(0,$.jsx)(a,{value:s.description??``,maxLength:400,placeholder:q(`project.gradientUse`),onChange:e=>c({...s,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:l.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":s.type===e,onClick:()=>E({...s,type:e}),className:L(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,s.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:q(Sn[e])},e))})]}),s.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(I,{children:q(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:s.angle,"aria-label":q(`project.gradientAngle`),onChange:e=>E({...s,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(s.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:s.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(x,{value:bn.test(e.color)?e.color:`#888888`,onChange:e=>D(t,{color:e.target.value})}),(0,$.jsx)(a,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();bn.test(n)&&D(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":q(`project.gradientAt`),onChange:e=>D(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,$.jsx)(Z,{label:q(`project.remove`),disabled:s.stops.length<=2,onClick:()=>E({...s,stops:s.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[s.stops.length<12?(0,$.jsxs)(k,{variant:`secondary`,size:`sm`,onClick:()=>O(),children:[(0,$.jsx)(W,{className:`size-4`}),` `,q(`project.gradientStopAdd`)]}):null,r.length&&s.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:q(`project.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>O(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:`CSS`}),(0,$.jsx)(a,{value:u,spellCheck:!1,onChange:e=>{d(e.target.value);let t=f(e.target.value);m(!t),t&&c({...s,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:L(`mt-1.5 text-[0.8125rem]`,p?`text-rose`:`text-ink-3`),children:q(p?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:o,children:q(`common.cancel`)}),(0,$.jsx)(k,{onClick:()=>{i(s),o()},children:q(`settings.save`)})]})]})})}var wn=`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`,Tn=`size-8 bg-card shadow-soft hover:bg-card`;function En({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(G,{value:e,label:q(`project.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,$.jsx)(G,{value:n??``,label:q(`project.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function Dn({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=T(e),[o,s]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":q(`project.gradientEdit`),onClick:n,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:wn,children:[(0,$.jsx)(Z,{label:q(o?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:Tn,children:(0,$.jsx)(pe,{className:`size-4`})}),(0,$.jsx)(Z,{label:q(`project.download`),onClick:()=>void xn(e,e.name),className:Tn,children:(0,$.jsx)(u,{className:`size-4`})}),t?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:i,className:L(Tn,`hover:text-rose`),children:(0,$.jsx)(J,{className:`size-4`})})]})]}),(0,$.jsx)(En,{name:e.name,namePlaceholder:q(`project.gradientName`),description:e.description,usePlaceholder:q(`project.gradientUse`),readOnly:t,onChange:r})]})}function On(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function kn({projectId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:o}){let s=_(e,t.file);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:r,"aria-label":q(`project.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:On(s,t.tile)}),(0,$.jsxs)(`div`,{className:wn,children:[(0,$.jsx)(`a`,{href:s,download:n,"aria-label":q(`project.download`),title:q(`project.download`),className:L(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,Tn),children:(0,$.jsx)(u,{className:`size-4`})}),r?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:o,className:L(Tn,`hover:text-rose`),children:(0,$.jsx)(J,{className:`size-4`})})]})]}),(0,$.jsx)(En,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:q(`project.patternUse`),readOnly:r,onChange:a})]})}function An({projectId:e,pattern:t,isNew:n,fileName:r,busy:i,error:o,upload:s,removeFile:c,onSave:l,onClose:u}){let[d,f]=(0,Q.useState)(t),[p,m]=(0,Q.useState)([]),h=async e=>{let t=e[0];if(!t)return;let n=await s(t);n&&(m(e=>[...e,n.id]),f(e=>({...e,file:n.id,name:e.name||n.name.replace(/\.[^.]+$/,``)})))},v=()=>{for(let e of p)c(e);u()};return(0,$.jsx)(w,{open:!0,onClose:v,wide:!0,title:q(n?`project.patternNew`:`project.patternEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[d.file?(0,$.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:On(_(e,d.file),d.tile),children:(0,$.jsxs)(me,{accept:`image/*`,multiple:!1,onFiles:e=>void h(e),className:`absolute right-2 bottom-2 h-9 border-solid bg-card px-3.5 text-ink-2 shadow-soft`,children:[i?(0,$.jsx)(g,{className:`size-4`}):(0,$.jsx)(Ce,{className:`size-4`}),q(`project.patternReplace`)]})}):(0,$.jsxs)(me,{accept:`image/*`,multiple:!1,onFiles:e=>void h(e),className:`h-40 flex-col`,children:[i?(0,$.jsx)(g,{className:`size-5`}):(0,$.jsx)(Ce,{className:`size-5`}),q(`project.patternPick`)]}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.patternName`)}),(0,$.jsx)(a,{value:d.name,maxLength:80,placeholder:d.file?r(d.file):q(`project.patternNamePlaceholder`),onChange:e=>f({...d,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.fillUseLabel`)}),(0,$.jsx)(a,{value:d.description??``,maxLength:400,placeholder:q(`project.patternUse`),onChange:e=>f({...d,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.patternShow`)}),(0,$.jsx)(`div`,{className:`flex w-fit gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:[!1,!0].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!d.tile===e,onClick:()=>f({...d,tile:e||void 0}),className:L(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,!!d.tile===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:q(e?`project.patternTile`:`project.patternFill`)},String(e)))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[o?(0,$.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:o}):null,(0,$.jsx)(k,{variant:`ghost`,onClick:v,children:q(`common.cancel`)}),(0,$.jsx)(k,{disabled:!d.file||i,onClick:()=>{for(let e of p.filter(e=>e!==d.file))c(e);t.file&&t.file!==d.file&&c(t.file),l({...d,name:d.name.trim(),description:d.description?.trim()||void 0}),u()},children:q(n?`project.add`:`settings.save`)})]})]})})}var jn=/^#[0-9a-fA-F]{6}$/;function Mn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{s(!0),l(null);try{let{colors:t}=await P.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(d(t),p([])):l(q(`project.colorsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(w,{open:!0,onClose:n,wide:u?!0:void 0,title:q(u?`project.colorsFound`:`project.colorsFromUrl`),children:u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:u.map(e=>{let t=f.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>p(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:L(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,$.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,$.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(O,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>d(null),children:q(`run.back`)}),(0,$.jsx)(k,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.value))),n()},children:f.length>1?q(`project.addMany`,{n:f.length}):q(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.logoUrl`)}),(0,$.jsx)(a,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.colorsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:n,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:o,disabled:!r.trim(),children:q(`run.next`)})]})]})})}function Nn({projectId:e,data:t,colors:n,sections:r,gradients:i,patterns:o,rules:s,sectioned:c,ruled:l,save:u,readOnly:d}){let[f,p]=(0,Q.useState)(()=>n.map(e=>({...e,id:Y()}))),[m,h]=(0,Q.useState)(r),[g,_]=(0,Q.useState)(i),[y,b]=(0,Q.useState)(o),[w,T]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),k=ee(e,d),A=ne(s),[j,te]=(0,Q.useState)(null),[M,re]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(!1),F=S({colors:f.filter(e=>jn.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:m,gradients:g,patterns:y,colorRules:A.rules},u),I=c?m:[],ie=I.filter(e=>(e.kind??`colors`)===`colors`),ae=e=>ie.some(t=>t.id===e.section),L=f.filter(e=>!ae(e)),oe=(L[0]??f[0])?.id,R=(e,t)=>p(n=>n.map(n=>n.id===e?{...n,...t}:n)),se=e=>p(t=>[...t,...e.map(e=>({...e,id:Y()}))].slice(0,E.colors)),B=[{value:``,label:q(`project.sectionStandard`)},...ie.map(e=>({value:e.id,label:e.title||q(`project.sectionUntitled`)}))],V=(e,t)=>{let n=Y();te(n),h(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},ue=e=>({id:Y(),name:``,section:e,type:`linear`,angle:90,stops:[{color:f[0]?.value&&jn.test(f[0].value)?f[0].value:`#4b73ff`,at:0},{color:f[1]?.value&&jn.test(f[1].value)?f[1].value:`#ff6d1b`,at:100}]}),G=e=>t.files.find(t=>t.id===e)?.name??`pattern`,de=[...f.length<E.colors?[{label:q(`project.colorNew`),icon:(0,$.jsx)(W,{className:`size-4 shrink-0`}),onPick:()=>pe()},{label:q(`project.colorsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>P(!0)}]:[],...c&&m.length<E.logoSections?[{label:q(`project.colorSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>V(`colors`,``)},{label:q(`project.gradientSectionAdd`),icon:(0,$.jsx)(It,{className:`size-4 shrink-0`}),onPick:()=>V(`gradients`,q(`project.gradientSectionTitle`))},{label:q(`project.patternSectionAdd`),icon:(0,$.jsx)(Wt,{className:`size-4 shrink-0`}),onPick:()=>V(`patterns`,q(`project.patternSectionTitle`))}]:[],...!l||A.full?[]:[{label:q(`project.ruleNew`),icon:(0,$.jsx)(nt,{className:`size-4 shrink-0`}),onPick:()=>A.add()}]],fe=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(x,{value:jn.test(e.value)?e.value:`#888888`,onChange:t=>R(e.id,{value:t.target.value})}),(0,$.jsx)(a,{value:e.name,autoFocus:e.id===M,placeholder:q(`project.colorName`),maxLength:120,onChange:t=>R(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(a,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>R(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===oe?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(v,{tone:`ember`,children:q(`project.colorAccent`)})}):d?null:(0,$.jsx)(Z,{label:q(`project.colorFirst`),onClick:()=>p(t=>[{...e,section:void 0},...t.filter(t=>t.id!==e.id)]),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:(0,$.jsx)(C,{className:`size-4`})}),d||!ie.length?null:(0,$.jsx)(le,{options:B,value:ae(e)?e.section??``:``,onChange:t=>R(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),d?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:()=>p(t=>t.filter(t=>t.id!==e.id)),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})]},e.id),pe=e=>{let t=Y();re(t),p(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,$.jsxs)(X,{title:q(`project.colors`),hint:q(`project.colorsHint`),save:F,locked:d,action:d?null:(0,$.jsx)(H,{entries:de}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[L.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:L.map(fe)}),d?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.colorUse`)})]}):f.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:q(`project.colorsEmpty`)}),I.map(t=>{let n=t.kind??`colors`,r=f.filter(e=>e.section===t.id),i=g.filter(e=>e.section===t.id),a=y.filter(e=>e.section===t.id),o=n===`gradients`?i.length:n===`patterns`?a.length:r.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(z,{title:t.title,titlePlaceholder:q(n===`gradients`?`project.gradientSectionTitlePlaceholder`:n===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),kind:n===`gradients`?{icon:(0,$.jsx)(It,{}),label:q(`project.kindGradients`)}:n===`patterns`?{icon:(0,$.jsx)(Wt,{}),label:q(`project.kindPatterns`)}:{icon:(0,$.jsx)(Ze,{}),label:q(`project.kindColors`)},autoFocus:j===t.id,readOnly:d,onChange:e=>h(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!o||confirm(q(n===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:t.title||q(`project.sectionUntitled`)}))){h(e=>e.filter(e=>e.id!==t.id)),p(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),_(e=>e.filter(e=>e.section!==t.id));for(let e of a)k.remove(e.file);b(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[i.map(e=>(0,$.jsx)(Dn,{gradient:e,readOnly:d,onEdit:()=>T(e),onChange:t=>_(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>_(t=>t.filter(t=>t.id!==e.id))},e.id)),d||g.length>=E.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>T(ue(t.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(W,{className:`size-5`}),q(`project.gradientAdd`)]})]}):n===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(t=>(0,$.jsx)(kn,{projectId:e,pattern:t,fileName:G(t.file),readOnly:d,onEdit:()=>O(t),onChange:e=>b(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{k.remove(t.file),b(e=>e.filter(e=>e.id!==t.id))}},t.id)),d||y.length>=E.files.pattern?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>O({id:Y(),name:``,section:t.id,file:``}),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(W,{className:`size-5`}),q(`project.patternAdd`)]})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(fe),d||f.length>=E.colors?null:(0,$.jsx)(U,{label:q(`project.colorAdd`),onClick:()=>pe(t.id)})]})]},t.id)}),l?(0,$.jsx)(ce,{rules:A,placeholder:q(`project.colorRulePlaceholder`),readOnly:d}):null]}),k.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:k.error}):null,w?(0,$.jsx)(Cn,{projectId:e,gradient:w,isNew:!g.some(e=>e.id===w.id),brand:f.filter(e=>jn.test(e.value)),onClose:()=>T(null),onSave:e=>_(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,D?(0,$.jsx)(An,{projectId:e,pattern:D,isNew:!y.some(e=>e.id===D.id),fileName:G,busy:k.busy,error:k.error,upload:async e=>(await k.upload(`pattern`,[e]))[0]??null,removeFile:e=>void k.remove(e),onClose:()=>O(null),onSave:e=>b(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,N?(0,$.jsx)(Mn,{projectId:e,onClose:()=>P(!1),onAdd:se}):null]})}var Pn=e=>/^(ja|yes|true)$/i.test(e.trim()),Fn={text:et,longtext:Ke,number:He,date:Te,url:B,email:ct,phone:We,boolean:Ue};function In({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let c=Fn[e??t],l=`${q(`project.factType`)}: ${q(`project.type.${e??t}`)}`,u=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,d=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:l,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:L(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,r?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,$.jsx)(c,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:L(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,a?`bottom-12`:`top-12`),children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:u,onClick:()=>d(void 0),children:[(0,$.jsx)(Ct,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:q(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:q(`project.type.${t}`)}),(0,$.jsx)(O,{className:L(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),xe.map(t=>{let n=Fn[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:u,onClick:()=>d(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:q(`project.type.${t}`)}),(0,$.jsx)(O,{className:L(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Ln({facts:e,save:t,readOnly:n}){let i=(0,Q.useRef)(0),s=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${i.current++}`}))),u=S(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 r=`f${i.current++}`;s.current=`${r}:${t}`;let a={id:r,key:``,label:``,value:``,...e};l(e=>n?[a,...e]:[...e,a])},p=e=>t=>{t&&s.current===e&&(s.current=null,t.focus())},m=o.filter(e=>!c.some(t=>t.key===e));return(0,$.jsxs)(X,{title:q(`project.facts`),hint:q(`project.factsHint`),save:u,locked:n,action:c.length<E.facts&&!n?(0,$.jsxs)(k,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`,!0),children:[(0,$.jsx)(W,{className:`size-4`}),` `,q(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:c.map(e=>{let t=fe(e.value),i=e.type??t;return(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,$.jsx)(a,{ref:p(`${e.id}:label`),value:e.label,placeholder:q(`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:r(e.label,c.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(ve,{checked:Pn(e.value),label:e.label,onChange:t=>d(e.id,{value:q(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Pn(e.value)?q(`project.yes`):q(`project.no`)})]}):(0,$.jsx)(R,{ref:p(`${e.id}:value`),rows:1,minRows:i===`longtext`?2:1,maxRows:10,value:e.value,placeholder:q(`project.factValue`),onChange:t=>d(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(In,{type:e.type,detected:t,onChange:t=>d(e.id,{type:t})}),n?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:()=>l(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]},e.id)})}),c.length<E.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${c.length?`mt-4`:``}`,children:[(0,$.jsxs)(k,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`),children:[(0,$.jsx)(W,{className:`size-4`}),` `,q(`project.factAdd`)]}),m.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f({key:e,label:q(`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,$.jsx)(W,{className:`size-3.5`}),` `,q(`fact.${e}`)]},e))]}):null]})}function Rn({onLogo:e,children:t,className:n}){let[r,i]=(0,Q.useState)(!1);return e?(0,$.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(an);i(!1),n&&(t.preventDefault(),e(n))},className:L(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,$.jsx)(`div`,{className:n,children:t})}function zn({projectId:e,data:t,readOnly:n,sections:r,rules:i,sectioned:a,ruled:o,save:s}){let c=ee(e,n),[l,u]=(0,Q.useState)(r),d=ne(i),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),g=(0,Q.useRef)(null),_=S({logoSections:l,logoRules:d.rules},s),v=t.files.filter(e=>e.kind===`logo`),y=new Map(v.map(e=>[e.id,e])),b=a?l:[],x=new Set(b.flatMap(e=>e.logos)),C=v.filter(e=>!x.has(e.id)),w=D(v,l)?.id,T=(e,t)=>u(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),O=(e,t)=>u(n=>n.map(n=>n.id===e?{...n,...t}:n)),k=async(e,t)=>{let n=await c.upload(`logo`,e);for(let e of n)T(e.id,t)},A=b.length?{options:[{value:``,label:q(`project.sectionStandard`)},...b.map(e=>({value:e.id,label:e.title||q(`project.sectionUntitled`)}))],current:e=>b.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>T(e.id,t||null)}:void 0,j=(t,n,r)=>(0,$.jsx)(on,{projectId:e,kind:`logo`,files:t,actions:c,accept:`image/*`,addLabel:r?q(`project.logoAdd`):void 0,onUpload:e=>void k(e,n),mainId:w,onMakeMain:e=>{T(e.id,null),c.order(`logo`,[e.id,...v.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:A,onRemove:e=>{confirm(q(`project.removeConfirm`,{name:e.name}))&&(c.remove(e.id),T(e.id,null))}}),te=n?void 0:e=>t=>T(t,e),M=[{label:q(`project.logoUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>g.current?.click()},{label:q(`project.logoFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>h(!0)},...a&&l.length<E.logoSections?[{label:q(`project.logoSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>{let e=Y();p(e),u(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!o||d.full?[]:[{label:q(`project.ruleNew`),icon:(0,$.jsx)(nt,{className:`size-4 shrink-0`}),onPick:()=>d.add()}]];return(0,$.jsxs)(X,{title:q(`project.logos`),hint:q(`project.logosHint`),save:_,action:n?null:(0,$.jsx)(H,{entries:M}),children:[(0,$.jsx)(`input`,{ref:g,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,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(Rn,{onLogo:te?.(null),children:j(C,null,!0)}),b.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(Rn,{onLogo:te?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(z,{title:e.title,description:e.description,titlePlaceholder:q(`project.logoSectionTitle`),descriptionPlaceholder:q(`project.logoSectionUse`),autoFocus:f===e.id,readOnly:n,onChange:t=>O(e.id,t),onRemove:()=>{(!e.logos.length||confirm(q(`project.logoSectionRemoveConfirm`,{name:e.title||q(`project.sectionUntitled`)})))&&u(t=>t.filter(t=>t.id!==e.id))}}),j(e.logos.map(e=>y.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),o?(0,$.jsx)(ce,{rules:d,placeholder:q(`project.logoRulePlaceholder`),readOnly:n}):null]}),c.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:c.error}):null,m?(0,$.jsx)(sn,{kind:`logo`,onClose:()=>h(!1),fetchUrl:e=>c.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)T(t.id,null)}}):null]})}var Bn=e=>URL.canParse(e)?new URL(e).host:e;async function Vn(e,t){let n=de({family:t,source:{url:e}});if(!n)return`down`;if(n.stylesheet)return await Hn(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 Hn(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 Un(e,t){let n=e.source;if(!n)return q(`project.fontSourceNone`);if(`file`in n){let e=t.find(e=>e.id===n.file)?.name??``;return q(`project.fontSourceFile`,{name:e})}return q(`project.fontSourceUrl`,{host:Bn(n.url)})}function Wn({projectId:e,font:t,onSave:n,onClose:r}){let o=(i(e).data?.files??[]).filter(e=>e.mime.startsWith(`font/`)),s=ee(e),c=(0,Q.useRef)(null),[l,u]=(0,Q.useState)(t.source&&`url`in t.source?`url`:`file`),[d,f]=(0,Q.useState)(t.source&&`file`in t.source?t.source.file:``),[p,m]=(0,Q.useState)(t.source&&`url`in t.source?t.source.url:``),[h,g]=(0,Q.useState)(t.source&&`url`in t.source?{url:t.source.url,result:`ok`}:null),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(t.license??``),[x,S]=(0,Q.useState)(!1),C=p.trim(),T=async()=>{v(!0),g({url:C,result:await Vn(C,t.family.trim())}),v(!1)},E=l===`file`?d?{file:d}:null:h?.url===C&&h.result===`ok`?{url:C}:null,D=h?.url===C?h.result:null;return(0,$.jsx)(w,{open:!0,onClose:r,title:q(`project.fontSourceTitle`,{family:t.family}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(`project.fontSourceHint`)}),(0,$.jsx)(N,{value:l,options:[`file`,`url`],label:e=>q(`project.fontSourceKind.${e}`),onChange:e=>u(e)}),l===`file`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.fontSourceFiles`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":d===e.id,onClick:()=>f(e.id),className:L(`rounded-lg px-3 py-2 text-left text-[0.875rem] ring-1 transition`,d===e.id?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:e.name},e.id))}),(0,$.jsx)(`input`,{ref:c,type:`file`,accept:`.woff2,.woff,.ttf,.otf`,className:`hidden`,onChange:async e=>{let t=[...e.target.files??[]];e.target.value=``;let[n]=await s.upload(`asset`,t);n&&f(n.id)}}),(0,$.jsxs)(k,{variant:`ghost`,className:`mt-2`,busy:s.busy,onClick:()=>c.current?.click(),children:[(0,$.jsx)(Je,{className:`size-4`}),q(`project.fontSourceUpload`)]}),s.error?(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-rose`,children:s.error}):null]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),T()},children:[(0,$.jsx)(I,{children:q(`project.fontSourceUrlLabel`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(a,{value:p,inputMode:`url`,placeholder:q(`project.fontSourceUrlPlaceholder`),onChange:e=>m(e.target.value)}),(0,$.jsx)(k,{type:`submit`,variant:`ghost`,busy:_,disabled:!C.startsWith(`https://`),children:q(`project.fontSourceCheck`)})]}),D?(0,$.jsx)(`p`,{className:L(`mt-1.5 text-[0.875rem]`,D===`ok`?`text-ink-3`:`text-rose`),children:q(`project.fontCheck.${D}`,{host:Bn(C),family:t.family})}):null,D===`ok`?(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-ink-3`,children:q(`project.fontPrivacy`,{host:Bn(C)})}):null]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{hint:q(`project.fontLicenseHint`),children:q(`project.fontLicense`)}),(0,$.jsx)(a,{value:y,maxLength:200,placeholder:q(`project.fontLicensePlaceholder`),onChange:e=>b(e.target.value)}),(0,$.jsxs)(`label`,{className:`mt-2 flex items-start gap-2 text-[0.875rem]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 accent-ember`,checked:x,onChange:e=>S(e.target.checked)}),q(`project.fontLicenseConfirm`,{family:t.family})]})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[t.source?(0,$.jsx)(k,{variant:`ghost`,className:`mr-auto`,onClick:()=>{n({source:void 0,license:t.license}),r()},children:q(`project.fontSourceRemove`)}):null,(0,$.jsx)(k,{variant:`ghost`,onClick:r,children:q(`common.cancel`)}),(0,$.jsx)(k,{disabled:!(E&&x),onClick:()=>{E&&(n({source:E,license:y.trim()||void 0}),r())},children:q(`project.fontSourceSave`)})]})]})})}var Gn=new Set;function Kn(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Gn.has(t))return;Gn.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 qn=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function Jn({unit:e,label:t,...n}){return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,$.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var Yn=`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`,Xn={web:`project.fontUseWeb`,documents:`project.fontUseDocuments`,print:`project.fontUsePrint`,images:`project.fontUseImages`,video:`project.fontUseVideo`};function Zn({projectId:e,font:t,first:n,readOnly:r,autoFocus:a,onChange:o,onRemove:s}){Kn(t.family);let c=i(e).data?.files??[],[l,u]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:qn(t.family)},children:[(0,$.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,$.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:t.family}),t.role?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:t.role}):null]}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(G,{value:t.family,label:q(`project.fontFamily`),placeholder:q(`project.fontFamily`),maxLength:80,autoFocus:a,onChange:e=>o({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(G,{value:t.role,label:q(`project.fontRole`),placeholder:q(n?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>o({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>{let n=t.weights.includes(e);return(0,$.jsx)(`button`,{type:`button`,disabled:r,"aria-pressed":n,onClick:()=>o({weights:n?t.weights.filter(t=>t!==e):[...t.weights,e].sort((e,t)=>e-t)}),style:{fontFamily:qn(t.family),fontWeight:e},className:L(`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,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[r?t.license?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:t.license}):null:(0,$.jsx)(G,{value:t.license??``,label:q(`project.fontLicense`),placeholder:q(`project.fontLicensePlaceholder`),maxLength:200,onChange:e=>o({license:e}),className:`text-[0.8125rem] text-ink-3`}),r&&!t.uses?.length?null:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:q(`project.fontUses`)}),M.map(e=>{let n=!!t.uses?.includes(e);return(0,$.jsxs)(`button`,{type:`button`,disabled:r,"aria-pressed":n,onClick:()=>{let r=n?(t.uses??[]).filter(t=>t!==e):M.filter(n=>n===e||t.uses?.includes(n));o({uses:r.length?r:void 0})},className:L(`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,$.jsx)(O,{className:`size-3.5`}):null,q(Xn[e])]},e)})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[0.8125rem] text-ink-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:Un(t,c)}),r||!t.family.trim()?null:(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:`text-ink underline decoration-border underline-offset-2 hover:decoration-ink`,children:q(t.source?`project.fontSourceChange`:`project.fontSourceSet`)})]}),l?(0,$.jsx)(Wn,{projectId:e,font:t,onSave:o,onClose:()=>u(!1)}):null,r?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:s,className:`absolute top-4 right-4 size-8 bg-card opacity-0 shadow-soft transition focus:opacity-100 group-hover/font:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})}function Qn({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:qn(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,$.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,$.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,$.jsx)(`div`,{className:`w-40`,children:(0,$.jsx)(G,{value:e.name,label:q(`project.styleName`),placeholder:q(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":q(`project.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:L(Yn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||q(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":q(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:Yn,children:[...new Set([...d,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(Jn,{unit:`px`,label:q(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,$.jsx)(Jn,{unit:q(`project.styleLine`),label:q(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(Jn,{unit:q(`project.styleTracking`),label:q(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:q(`project.styleUpper`),"aria-label":q(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:L(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,$.jsx)(Bt,{className:`size-4`})})]}),r?null:(0,$.jsx)(Z,{label:q(`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,$.jsx)(J,{className:`size-4`})})]})]})}function $n({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{s(!0),l(null);try{let{fonts:t}=await P.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(d(t),p(t.slice(0,2).map(e=>e.family))):l(q(`project.fontsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(w,{open:!0,onClose:n,wide:u?!0:void 0,title:q(u?`project.fontsFound`:`project.fontsFromUrl`),children:u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map(e=>(0,$.jsx)(er,{font:e,on:f.includes(e.family),onToggle:()=>p(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>d(null),children:q(`run.back`)}),(0,$.jsx)(k,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.family))),n()},children:f.length>1?q(`project.addMany`,{n:f.length}):q(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.logoUrl`)}),(0,$.jsx)(a,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.fontsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:n,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:o,disabled:!r.trim(),children:q(`run.next`)})]})]})})}function er({font:e,on:t,onToggle:n}){return Kn(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:L(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:qn(e.family)},children:`Aa`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):q(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(O,{className:`size-3.5`})}):null]})}function tr({projectId:e,fonts:t,styles:n,rules:r,ruled:i,sample:a,save:o,readOnly:s}){let[c,l]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(n),f=ne(r),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=S({fonts:c,textStyles:u,typeRules:f.rules},o),v=(e,t=!1)=>{let n=e.map(e=>({id:Y(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&m(n[0].id),l(e=>[...e,...n].slice(0,E.fonts))},y=()=>{let e=Y();m(e),d(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},b=[...c.length<E.fonts?[{label:q(`project.fontNew`),icon:(0,$.jsx)(W,{className:`size-4 shrink-0`}),onPick:()=>v([{family:``,weights:[400,700]}],!0)},{label:q(`project.fontsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>g(!0)}]:[],...u.length<E.textStyles?[{label:q(`project.styleNew`),icon:(0,$.jsx)(mt,{className:`size-4 shrink-0`}),onPick:y}]:[],...!i||f.full?[]:[{label:q(`project.ruleNew`),icon:(0,$.jsx)(nt,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,$.jsxs)(X,{title:q(`project.typography`),hint:q(`project.typographyHint`),save:_,action:s?null:(0,$.jsx)(H,{entries:b}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[c.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:c.map((t,n)=>(0,$.jsx)(Zn,{projectId:e,font:t,first:n===0,readOnly:s,autoFocus:p===t.id,onChange:e=>l(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>l(e=>e.filter(e=>e.id!==t.id))},t.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:q(`project.fontsEmpty`)}),u.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:q(`project.styles`)}),s?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:q(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:u.map(e=>(0,$.jsx)(Qn,{style:e,fonts:c,sample:a,readOnly:s,autoFocus:p===e.id,onChange:t=>d(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>d(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,i?(0,$.jsx)(ce,{rules:f,placeholder:q(`project.typeRulePlaceholder`),readOnly:s}):null]}),h?(0,$.jsx)($n,{projectId:e,onClose:()=>g(!1),onAdd:e=>v(e)}):null]})}function nr({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[i,o]=(0,Q.useState)(e.brand.about??``),s=S({name:n.trim(),about:i.trim()},e=>t({brand:e}));return(0,$.jsx)(X,{title:q(`project.base`),hint:q(`project.baseHint`),save:s,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.title`)}),(0,$.jsx)(a,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.about`)}),(0,$.jsx)(R,{minRows:4,value:i,onChange:e=>o(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.aboutHint`)})]})]})})}function rr({project:e,group:t,children:n}){let r=s(),a=i(e.id),[o,c]=(0,Q.useState)(0),[l,u]=(0,Q.useState)(!1),d=async t=>{await P.patch(`/api/studio/projects/${e.id}`,t),await r.invalidateQueries({queryKey:[`projects`]})},f=Qe({mutationFn:()=>P.del(`/api/studio/projects/${e.id}`),onSuccess:()=>r.invalidateQueries({queryKey:[`projects`]})}),p=xt(),m=Ye(),h=a.data??{files:[],embeddings:!0},g=`${e.id}:${o}`,_=e.readOnly,v=t===`knowledge`,y=dt(`brandSections`),b=dt(`brandRules`),x=dt(`typography`);return ft(_?{}:{title:q(v?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:q(v?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:q(v?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:v?[{label:q(`assistant.suggest.knowledgeHow`)},{label:q(`assistant.suggest.knowledgeSite`),fill:!0},{label:q(`assistant.suggest.knowledgeCategories`)}]:[{label:q(`assistant.suggest.readSite`),fill:!0},{label:q(`assistant.suggest.missing`)},{label:q(`assistant.suggest.facts`)}],summary:v?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${h.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>c(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[_?(0,$.jsx)(qe,{children:Ge(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ge,{id:`base`,children:(0,$.jsx)(nr,{project:e,save:d},`base:${g}`)}),(0,$.jsx)(ge,{id:`facts`,children:(0,$.jsx)(Ln,{facts:e.facts,save:e=>d({facts:e}),readOnly:_},`facts:${g}`)}),(0,$.jsx)(ge,{id:`logos`,children:(0,$.jsx)(zn,{projectId:e.id,data:h,readOnly:_,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:y,ruled:b,save:e=>d({brand:e})},`logos:${g}`)}),(0,$.jsx)(ge,{id:`colors`,children:(0,$.jsx)(Nn,{projectId:e.id,data:h,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],sectioned:y,ruled:b,save:e=>d({brand:e}),readOnly:_},`colors:${g}`)}),x?(0,$.jsx)(ge,{id:`typography`,children:(0,$.jsx)(tr,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:b,sample:e.brand.name||q(`project.typeSample`),save:e=>d({brand:e}),readOnly:_},`typography:${g}`)}):null,(0,$.jsx)(ge,{id:`assets`,children:(0,$.jsx)(yn,{projectId:e.id,data:h,readOnly:_,sections:e.brand.assetSections??[],save:e=>d({brand:e})},`assets:${g}`)})]}):null,n,t===`info`&&p&&!_&&m?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(k,{variant:`danger`,onClick:()=>u(!0),children:q(`settings.delete`)}),(0,$.jsxs)(w,{open:l,onClose:()=>u(!1),title:q(`settings.deleteTitle`,{name:e.name}),children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:q(`settings.deleteBody`)}),f.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:f.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>u(!1),children:q(`common.cancel`)}),(0,$.jsx)(k,{variant:`danger`,busy:f.isPending,onClick:()=>f.mutate(),children:q(`common.delete`)})]})]})]}):null]})}var ir=`results-search`,ar={q:``,mode:``,days:0};function or(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 A({queryKey:[`results`,e,i],queryFn:()=>P.get(`/api/studio/projects/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function sr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[o,s]=(0,Q.useState)(r.q);return yt({icon:V,label:q(`space.resultsSearch`),run:()=>{let e=document.getElementById(ir);e?.scrollIntoView({block:`center`,behavior:`smooth`}),e?.focus()}}),(0,Q.useEffect)(()=>{if(o===r.q)return;let e=setTimeout(()=>i({...r,q:o}),250);return()=>clearTimeout(e)},[o,r,i]),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(ie,{value:t??``,onChange:e=>n(e||null),options:[{value:``,label:q(`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,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,$.jsx)(V,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(a,{type:`search`,value:o,onChange:e=>s(e.target.value),id:ir,placeholder:q(`space.resultsSearch`),"aria-label":q(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(ie,{value:r.mode,onChange:e=>i({...r,mode:e}),options:[{value:``,label:q(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(ie,{value:String(r.days),onChange:e=>i({...r,days:Number(e)}),options:[{value:`0`,label:q(`space.resultsAnyTime`)},{value:`1`,label:q(`space.resultsDay`)},{value:`7`,label:q(`space.resultsDays`,{n:7})},{value:`30`,label:q(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function cr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Q.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(j,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{title:t?s(t):q(`space.resultsAll`),hint:q(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(sr,{data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}),e.runs.length?(0,$.jsx)(p,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,q(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:q(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(ue,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(v,{children:q(`run.testChip`)}):(0,$.jsxs)(v,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(p,{children:(0,$.jsx)(te,{children:r.q.trim()||r.mode||r.days?q(`space.resultsNone`):q(`space.resultsEmpty`)})})]}),a?(0,$.jsx)(Ie,{header:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(a.wizardId)}),a.mode===`test`?(0,$.jsx)(v,{children:q(`run.testChip`)}):(0,$.jsxs)(v,{tone:`live`,children:[`Live v`,a.version]})]}),onClose:()=>o(null),children:(0,$.jsx)(Pt,{runId:a.id,compact:!0,studio:!0},a.id)}):null]})}function lr({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,o]=(0,Q.useState)(e.name),s=Qe({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{label:q(`project.rename`),onClick:()=>{o(e.name),r(!0)},children:(0,$.jsx)(_e,{className:`size-4`})}),(0,$.jsx)(w,{open:n,onClose:()=>r(!1),title:q(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&s.mutate()},children:[(0,$.jsx)(a,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>o(e.target.value)}),s.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>r(!1),children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:s.isPending,disabled:!i.trim(),children:q(`settings.save`)})]})]})})]})}function ur({project:e}){let t=s();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(rt,{}),e.readOnly?null:(0,$.jsx)(lr,{project:e,save:async n=>{await P.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function dr(e){let t=e.join(` `),[n,r]=(0,Q.useState)(e[0]);return(0,Q.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=bt(),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 fr(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function pr({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(wt,{icon:e.icon??tt,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(Dt,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function mr(){let{group:e}=ae(),[t,n]=se(),r=oe(),i=y(),{hash:a}=i,{project:o,loading:s}=$e(),c=xt(),l=_t(),u=Nt(),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),v=ot(e)?e:void 0,b=v?void 0:l.spaceParts.find(t=>t.id===e),x=v??b?.id,S=i.state?.parts===!0,C=st(lt(),l).map(e=>({...e,to:`/space/${e.id}`})),w={id:`results`,label:q(`space.results`),icon:vt,to:`/space/results`},T=v===`results`?w:C.find(e=>e.id===x),E=t.get(`show`),D=v===`results`?2:x?E?2:1:0,O=v===`results`?1:u?Math.min(D,1):x&&g!==x&&!S?1:0,k=Et(O),A=Et(D),j=(0,Q.useMemo)(()=>({slot:d,narrow:u,setDetail:m}),[d,u]),ee=o?o.brand.name?.trim()||o.name:q(`nav.project`),ne=dt(`typography`)?[]:[`typography`],M=b?l.spaceMenus[b.id]??[]:[],re=b?[{plugin:null,label:null,sections:M}]:v&&v!==`results`?pt(v,l,ne):[],N=v?pt(v,l).filter(e=>e.plugin):[],P=dr([...re,...v===`results`?N:[]].flatMap(e=>e.sections.map(e=>e.id))),F=v===`results`&&E&&E!==`all`?E:null,[I,ie]=(0,Q.useState)(ar),R=or(v===`results`?o?.id:void 0,F,I),ce=R.data?.wizards.find(e=>e.id===F)?.title,z=v===`data`&&E&&E!==`all`||v===`knowledge`&&E&&/^[ptfcvs]:/.test(E)?E:null,B=z?.startsWith(`s:`)?l.spaceSections.find(e=>e.id===z.slice(2)):void 0,V=v===`knowledge`&&z&&/^[ptf]:/.test(z)?z:null,H=Oe(v===`data`?o?.id:void 0),U=Fe(v===`knowledge`?o?.id:void 0),W=Ve(z?.startsWith(`v:`)?z.slice(2):``),le=U.data?.categories.find(e=>e.id===(z?.startsWith(`c:`)?z.slice(2):W.data?.category.id)),ue=v===`knowledge`?B?B.label():z?.startsWith(`v:`)?W.data&&`${W.data.category.name}: ${W.data.value}`:z?.startsWith(`c:`)?le?.name:U.data?.items.find(e=>e.key===z)?.title:H.data?ze(H.data).flatMap(e=>e.items).find(e=>e.key===z)?.title:void 0;St([...v===`results`?[]:[{label:q(`nav.project`),to:`/space`}],...T?[{label:T.label,to:`/space/${T.id}`}]:[],...T&&(p??ce??ue)?[{label:p??ce??ue}]:[]]);let G={p:`page`,t:`table`,f:`file`,c:`category`,v:`category value`,s:`plugin section`};ft({...v===`data`||v===`results`?{compact:!0}:{},...v===`data`?{suggestions:[{label:q(`assistant.suggest.dataWhat`)},{label:q(`assistant.suggest.dataWho`)},{label:q(`assistant.suggest.dataEdit`)}]}:v===`results`?{suggestions:[{label:q(`assistant.suggest.resultsFailed`)},{label:q(`assistant.suggest.resultsCost`)},{label:q(`assistant.suggest.resultsShare`)}]}:{},...z&&ue?{open:{kind:G[z[0]]??`item`,id:z.slice(2),label:ue}}:F&&ce?{open:{kind:`wizard`,id:F,label:ce}}:{}});let de=v===`results`||v===`data`||z?a.slice(1):E||a.slice(1),fe=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${x}#${de}`;de&&fe.current!==e&&document.getElementById(de)&&(fe.current=e,requestAnimationFrame(()=>fr(de,!1)))},[x,de,o?.id,l.spaceSections,M.length]),!x){let t=a.slice(1),n=t?at(t,l):null;if(n===`knowledge`&&l.spaceSections.some(e=>e.id===t))return(0,$.jsx)(h,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(h,{to:u?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if((t||e)&&l.status!==`ready`)return null;if(e!==void 0||!u)return(0,$.jsx)(h,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(v===`knowledge`&&!E&&l.spaceSections.some(e=>e.id===a.slice(1)))return(0,$.jsx)(h,{to:`/space/knowledge?show=s:${a.slice(1)}`,replace:!0});let pe=e=>{if(u){r({search:`?show=${e}`});return}fe.current=`${x}#${e}`,fr(e,!0),r({search:``,hash:e},{replace:!0})},K=e=>u?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),me=e=>e.flatMap(e=>e.sections).map(e=>l.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(ge,{id:e.id,children:(0,$.jsx)(X,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(ht,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),he=u?void 0:P,_e=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ot,{title:ee,open:O===1?T??null:null,onBack:v===`results`?void 0:()=>u?r(`/space`):_(x??null),root:{icon:gt,label:q(`nav.project`),backLabel:q(`nav.wizards`),onBack:()=>r(`/`)}}),(0,$.jsx)(`div`,{className:L(Tt(k)),children:O===0?(0,$.jsx)(At,{entries:C,current:u?void 0:T,onPick:()=>_(null)}):(0,$.jsx)(`div`,{ref:f})},O)]});return(0,$.jsx)(kt.Provider,{value:j,children:(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:L(`grid gap-6`,v!==`results`&&`md:grid-cols-[10.5rem_minmax(0,1fr)] md:gap-5 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[v===`results`?null:(0,$.jsx)(`aside`,{className:L(`min-w-0 md:sticky md:top-6 md:self-start`,u&&D===2&&`hidden`,u&&A===`back`&&Tt(`back`)),children:_e}),x?(0,$.jsxs)(`div`,{className:L(`min-w-0`,u&&D<2&&`hidden`,u&&A===`deeper`&&Tt(`deeper`)),children:[u&&v!==`results`?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(Mt,{label:T?.label??ee,onBack:()=>r(`/space/${x}`)})}):null,c&&o?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(ur,{project:o})}):null,v===`data`?(0,$.jsxs)(jt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(wt,{icon:Kt,label:q(`data.all`),selected:!u&&!z,onPick:()=>K(`all`)})}),H.data?ze(H.data).map(e=>(0,$.jsx)(Dt,{label:e.label,children:e.items.map(e=>(0,$.jsx)(wt,{icon:De[e.kind],label:e.title,selected:!u&&e.key===z,onPick:()=>K(e.key)},e.key))},e.key)):null,(0,$.jsx)(pr,{groups:N,current:he,onPick:pe})]}):v===`knowledge`?(0,$.jsxs)(jt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(wt,{icon:Kt,label:q(`know.all`),selected:!(u||z),onPick:()=>K(`all`)})}),U.data?.categories.length?(0,$.jsx)(Dt,{label:q(`know.categories`),children:U.data.categories.map(e=>(0,$.jsx)(wt,{icon:Me[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!u&&(z===`c:${e.id}`||W.data?.category.id===e.id),onPick:()=>K(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(pr,{groups:N,current:u?void 0:B?.id,onPick:e=>K(`s:${e}`)})]}):(0,$.jsx)(jt,{children:(0,$.jsx)(pr,{groups:re,current:he,onPick:pe})}),o&&(v===`info`||v===`knowledge`)?(0,$.jsxs)(rr,{project:o,group:v,children:[v===`knowledge`?V?V.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:V.slice(2),onGone:()=>K(`all`),onOpen:K},V):V.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:V.slice(2),onGone:()=>K(`all`)},V):(0,$.jsx)(fn,{projectId:o.id,fileId:V.slice(2),readOnly:o.readOnly,onGone:()=>K(`all`)},V):U.data?B?(0,$.jsx)(X,{title:B.label(),hint:B.hint?.(),plain:!0,children:(0,$.jsx)(ht,{of:B,children:(0,$.jsx)(B.component,{})})},z):z?.startsWith(`c:`)?le?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(je,{projectId:o.id,category:le,readOnly:o.readOnly,onOpen:K,onGone:()=>K(`all`)}),le.type===`choice`?null:(0,$.jsx)(Be,{projectId:o.id,category:le,categories:U.data.categories,onOpen:K})]},z):null:z?.startsWith(`v:`)?W.data?(0,$.jsx)(Ee,{value:W.data,readOnly:o.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[W.data.items.length?(0,$.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:W.data.items.map(e=>(0,$.jsx)(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,$.jsx)(`button`,{type:`button`,onClick:()=>K(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:q(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},z):null:(0,$.jsx)(ge,{id:`documents`,children:(0,$.jsx)(Re,{projectId:o.id,data:U.data,readOnly:o.readOnly,onOpen:K})}):null:null,v===`info`?me(N):null]},o.id):null,o&&b?(0,$.jsx)(ht,{of:b,children:(0,$.jsx)(it,{part:b.id,children:(0,$.jsx)(b.component,{})},o.id)}):null,o&&v===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:z?.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:z.slice(2),onGone:()=>K(`all`)},z):z?.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:z.slice(2),onGone:()=>K(`all`)},z):(0,$.jsxs)($.Fragment,{children:[H.data?(0,$.jsx)(Le,{projectId:o.id,data:H.data,readOnly:o.readOnly,onOpen:K}):null,me(N)]})}):null,o&&v===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[R.data?(0,$.jsx)(cr,{data:R.data,wizardId:F,onWizard:e=>K(e??`all`),filter:I,onFilter:ie}):null,R.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:R.error.message}):null,me(N)]}):null,o||s?null:(0,$.jsx)(te,{children:q(`settings.noProject`)})]}):null]})})})}export{mr as ProjectPage};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{A as r,B as i,Bt as a,C as o,Ci as s,Cr as c,D as l,Dr as u,E as d,F as f,Ft as p,Gn as m,Gr as h,Gt as g,I as _,It as v,Jr as y,Jt as b,Kt as x,L as S,Lr as C,Lt as w,M as T,O as E,P as D,Pr as O,Pt as k,Qr as A,Qt as j,R as ee,Rt as te,S as ne,T as M,Tr as re,Ut as N,V as P,Vr as F,Vt as I,Wt as ie,Xr as ae,Xt as L,Yr as oe,Yt as R,Zr as se,_ as ce,b as z,br as B,cr as V,d as H,f as U,fr as W,g as le,gr as ue,h as G,j as de,k as fe,kr as pe,lt as K,m as me,or as he,p as ge,pr as _e,qt as ve,rn as q,rr as J,ur as ye,v as be,w as xe,wr as Se,x as Y,xr as Ce,y as X,z as we,zt as Z}from"./ui-kIzOrA_W.js";import{S as Te,_ as Ee,a as De,c as Oe,d as ke,f as Ae,g as je,h as Me,i as Ne,l as Pe,m as Fe,n as Ie,o as Le,p as Re,s as ze,u as Be,v as Ve,x as He,y as Ue}from"./RunDrawer-DXqyxTsm.js";import{t as We}from"./phone-BprN_SDS.js";import{n as Ge,r as Ke,t as qe}from"./ReadOnly-I-Lm7a8y.js";import{t as Je}from"./upload-Cvztyjuj.js";import{Ct as Ye,Gt as Xe,Qt as Ze,Sn as Qe,St as $e,Ut as et,Yt as tt,an as nt,b as rt,c as it,d as at,f as ot,h as st,in as ct,m as lt,mn as ut,mt as dt,nt as ft,p as pt,qt as mt,s as ht,sn as gt,u as _t,un as vt,ut as yt,v as bt,wt as xt,y as St,zt as Ct}from"./index-DfHH4icT.js";import{a as wt,c as Tt,f as Et,i as Dt,n as Ot,o as kt,r as At,s as jt,t as Mt,u as Nt}from"./settings-menu-CVl54phq.js";import{t as Pt}from"./RunnerView-DeDApA-9.js";var Ft={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Ft.node;var It=F(Ft),Lt={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`}]]};Lt.node;var Rt=F(Lt),zt={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`}]]};zt.node;var Bt=F(zt),Vt={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`}]]};Vt.node;var Ht=F(Vt),Ut={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`]};Ut.node;var Wt=F(Ut),Gt={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Gt.node;var Kt=F(Gt),qt={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};qt.node;var Jt=F(qt),Yt={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};Yt.node;var Xt=F(Yt),Zt={name:`music`,size:24,node:[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]};Zt.node;var Qt=F(Zt),Q=e(t(),1),$=e(n(),1),$t={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function en({file:e,actions:t}){let[n,r]=(0,Q.useState)(e.description),i=(0,Q.useRef)(e.description),a=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Q.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,$.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:q(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 tn(e,t){confirm(q(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function nn({projectId:e,file:t,small:n}){let r=_(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:L(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,$.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,$.jsx)(rn,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,$.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,$.jsx)(Qt,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(Se,{className:i}):t.mime===`application/json`?(0,$.jsx)(he,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(Rt,{className:i}):(0,$.jsx)(c,{className:i}),n?null:(0,$.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function rn({src:e,small:t}){let[n,r]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,$.jsx)(`div`,{className:L(`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 an=`application/x-wizards-logo`;function on({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):tn(e,r);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,$.jsxs)(`div`,{draggable:u&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(an,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,$.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,$.jsx)(v,{tone:`ember`,children:q(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?$t:void 0,children:[s&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${q(`project.preview`)}: ${n.name}`,onClick:()=>s(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(nn,{projectId:e,file:n})}):(0,$.jsx)(nn,{projectId:e,file:n}),(0,$.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,$.jsx)(Z,{label:q(`project.preview`),onClick:()=>s(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(ut,{className:`size-4`})}):null,l&&n.id!==c&&!r.readOnly?(0,$.jsx)(Z,{label:q(`project.logoMakeMain`),onClick:()=>l(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(Xe,{className:`size-4`})}):null,u&&!r.readOnly?(0,$.jsx)(le,{options:u.options,value:u.current(n),onChange:e=>u.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:()=>f(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})]}),t===`asset`?(0,$.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,$.jsx)(en,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,$.jsxs)(me,{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,$.jsx)(g,{className:`size-5`}):(0,$.jsx)(W,{className:`size-5`}),a]}):null]})}function sn({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)([]),h=async()=>{c(!0),u(null);try{let a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(f(a.candidates),m([a.candidates[0].url])):u(q(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){u(e.message)}c(!1)},g=async()=>{c(!0),u(null);let e=[];try{for(let n of p){let r=await t(n);r.file&&e.push(r.file)}}catch(e){u(e.message)}c(!1),e.length&&n(e),e.length===p.length&&r()};return(0,$.jsx)(w,{open:!0,onClose:r,wide:d?!0:void 0,title:q(d?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:d?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:d.map(t=>{let n=p.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>m(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:L(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:$t,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:L(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(O,{className:`size-3.5`})}):null]},t.url)})}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>f(null),children:q(`run.back`)}),(0,$.jsx)(k,{busy:s,disabled:!p.length,onClick:()=>void g(),children:p.length>1?q(`project.addMany`,{n:p.length}):q(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.logoUrl`)}),(0,$.jsx)(a,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>o(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:r,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:s,disabled:!i.trim(),children:q(`run.next`)})]})]})})}function cn(e,t,n){return A({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>P.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function ln(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var un=e=>[ln(e),e.pages?q(`project.pages`,{n:e.pages}):null,m(e.size)].filter(Boolean).join(` · `),dn=2e5;function fn({projectId:e,fileId:t,readOnly:n,onGone:r}){let a=s(),o=i(e),c=Fe(e),l=ee(e,n),u=o.data?.files.find(e=>e.id===t),d=u?u.mime===`application/pdf`||u.mime.startsWith(`image/`):!1,[f,m]=(0,Q.useState)(null);if(!u)return o.isLoading?(0,$.jsx)(g,{className:`mx-auto text-ink-3`}):null;let h=f??(d?`original`:`text`),v=c.data?.items.find(e=>e.key===`f:${u.id}`),y=_(e,u.id),b=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":h===e,onClick:()=>m(e),className:L(`rounded-full px-3 py-1 text-[0.8125rem] transition`,h===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,$.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:u.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:un(u)}),(0,$.jsx)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,"aria-label":q(`project.openOriginal`),title:q(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(re,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{label:q(`project.reindex`),onClick:async()=>{await l.reindex(u.id),await a.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(ye,{className:`size-4`})}),(0,$.jsx)(Z,{label:q(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(q(`data.confirmDelete`,{title:u.name}))&&(await l.remove(u.id),await a.invalidateQueries({queryKey:[`knowledge`,e]}),r())},children:(0,$.jsx)(J,{className:`size-4`})})]})]}),(0,$.jsx)(Ae,{projectId:e,itemKey:`f:${u.id}`,has:v?.categories??[],originLabel:v?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(en,{file:u,actions:l})}),u.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:u.error}):null,(0,$.jsxs)(p,{className:`flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[d?b(`original`,q(`project.original`)):null,b(`text`,q(`project.readText`))]}),h===`original`?u.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:y,title:u.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:y,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(pn,{projectId:e,file:u})]})]})}function pn({projectId:e,file:t}){let n=cn(e,t,dn);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(g,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(K,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:q(`project.textCut`,{shown:n.data.text.length.toLocaleString(j),total:n.data.chars.toLocaleString(j)})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:q(`project.noText`)})}var mn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,hn=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),m(e.size)].filter(Boolean).join(` · `);function gn({projectId:e,file:t,actions:n,onClose:r}){let i=_(e,t.id);return(0,$.jsxs)(w,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,$.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:hn(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":q(`project.openOriginal`),title:q(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(re,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:$t,children:(0,$.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,$.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,$.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(en,{file:t,actions:n})})]})}function _n({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,$.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`${q(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(nn,{projectId:e,file:t,small:!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:hn(t)})]}),(0,$.jsx)(en,{file:t,actions:n})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,$.jsx)(Z,{label:q(`project.preview`),onClick:i,children:(0,$.jsx)(ut,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(le,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})]})}function vn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,o]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(w,{open:!0,onClose:r,title:q(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.assetSectionName`)}),(0,$.jsx)(a,{autoFocus:!0,value:i,maxLength:80,placeholder:q(`project.assetSectionTitle`),onChange:e=>o(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(k,{variant:`danger`,onClick:n,children:q(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(k,{variant:`ghost`,onClick:r,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,disabled:!i.trim(),children:q(e?`settings.save`:`project.add`)})]})]})})}function yn({projectId:e,data:t,readOnly:n,sections:r,save:i}){let a=ee(e,n),[o,s]=we(`assets`,`cards`),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(r),[m,h]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(null),[y,x]=(0,Q.useState)(!1),C=(0,Q.useRef)(null),w=S({assetSections:f},i),T=t.files.filter(e=>e.kind===`asset`),D=new Map(T.map(e=>[e.id,e])),O=new Set(f.flatMap(e=>e.assets)),k=f.find(e=>e.id===m)??null,A=k?k.assets.map(e=>D.get(e)).filter(e=>!!e):T.filter(e=>!O.has(e.id)),j=T.find(e=>e.id===u),te=c.trim().toLowerCase(),ne=te?A.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(te)):A,M=(e,t)=>p(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),re=async e=>{let t=k?.id??null;for(let n of await a.upload(`asset`,e))M(n.id,t)},N=e=>{confirm(q(`project.removeConfirm`,{name:e.name}))&&(a.remove(e.id),M(e.id,null))},P=f.length?{options:[{value:``,label:q(`project.assetsGeneral`)},...f.map(e=>({value:e.id,label:e.title||q(`project.sectionUntitled`)}))],current:e=>f.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>M(e.id,t||null)}:void 0,F=[{label:q(`project.assetUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>C.current?.click()},{label:q(`project.assetFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>x(!0)},...f.length<E.logoSections?[{label:q(`project.assetSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>v(`new`)}]:[]],I=f.length||T.length?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[f.length?(0,$.jsx)(b,{value:m,onChange:e=>{h(e),l(``)},label:q(`project.assets`),options:[{id:``,label:q(`project.assetsGeneral`)},...f.map(e=>({id:e.id,label:e.title||q(`project.sectionUntitled`)}))]}):null,k&&!n?(0,$.jsx)(Z,{label:q(`project.assetSectionRename`),onClick:()=>v(`current`),children:(0,$.jsx)(_e,{className:`size-4`})}):null]}),A.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(be,{value:c,onChange:l,placeholder:q(`project.assetSearch`)})}),(0,$.jsx)(Z,{label:q(o===`list`?`project.viewCards`:`project.viewList`),onClick:s,children:o===`list`?(0,$.jsx)(Kt,{className:`size-4`}):(0,$.jsx)(Xt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(X,{title:q(`project.assets`),hint:q(`project.assetsHint`),save:w,tabs:I,action:n?null:(0,$.jsx)(H,{entries:F}),children:[(0,$.jsx)(`input`,{ref:C,type:`file`,multiple:!0,accept:mn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&re(t)}}),ne.length?o===`cards`?(0,$.jsx)(on,{projectId:e,kind:`asset`,files:ne,actions:a,moveTo:P,onRemove:N,onPreview:e=>d(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:ne.map(t=>(0,$.jsx)(_n,{projectId:e,file:t,actions:a,moveTo:P,onPreview:()=>d(t.id),onRemove:()=>N(t)},t.id))}):A.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:q(`project.staysLocal`)}):(0,$.jsxs)(me,{accept:mn,onFiles:e=>void re(e),className:`h-16 w-full`,children:[a.busy?(0,$.jsx)(g,{className:`size-4`}):(0,$.jsx)(Je,{className:`size-4`}),q(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:q(`project.assetAdd`)})]}),a.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error}):null,j?(0,$.jsx)(gn,{projectId:e,file:j,actions:a,onClose:()=>d(null)}):null,_?(0,$.jsx)(vn,{section:_===`current`?k:null,onClose:()=>v(null),onSave:e=>{if(_===`current`&&k)p(t=>t.map(t=>t.id===k.id?{...t,title:e}:t));else{let t=Y();p(n=>[...n,{id:t,title:e,assets:[]}]),h(t)}},onRemove:_===`current`&&k?()=>{(!k.assets.length||confirm(q(`project.assetSectionRemoveConfirm`,{name:k.title})))&&(p(e=>e.filter(e=>e.id!==k.id)),h(``),v(null))}:void 0}):null,y?(0,$.jsx)(sn,{kind:`asset`,onClose:()=>x(!1),fetchUrl:e=>a.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)M(t.id,k?.id??null)}}):null]})}var bn=/^#[0-9a-fA-F]{6}$/;async function xn(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 Sn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function Cn({projectId:e,gradient:t,isNew:n,brand:r,onSave:i,onClose:o}){let[s,c]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(T(t)),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!n),E=e=>{c(e),d(T(e)),m(!1)},D=(e,t)=>E({...s,stops:s.stops.map((n,r)=>r===e?{...n,...t}:n)}),O=e=>{let t=[...s.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));E({...s,stops:[...s.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},A=async()=>{v(!0),b(null);try{let{gradient:t}=await P.post(`/api/studio/projects/${e}/gradients/describe`,{text:h.trim(),...S?{gradient:{name:s.name,type:s.type,angle:s.angle,stops:s.stops}}:{}});E({...s,...t,name:s.name.trim()?s.name:t.name}),g(``),C(!0)}catch(e){b(e.message)}v(!1)};return(0,$.jsx)(w,{open:!0,onClose:o,wide:!0,title:q(n?`project.gradientNew`:`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h.trim()&&!_&&A()},children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(a,{"data-autofocus":n||void 0,value:h,maxLength:1e3,"aria-label":q(`project.gradientDescribe`),placeholder:q(S?`project.gradientDescribeChange`:`project.gradientDescribeNew`),onChange:e=>g(e.target.value),className:`min-w-0 flex-1`}),(0,$.jsxs)(k,{type:`submit`,variant:`secondary`,busy:_,disabled:!h.trim(),children:[(0,$.jsx)(he,{className:`size-4`}),q(S?`project.gradientDescribeApply`:`project.gradientDescribeMake`)]})]}),(0,$.jsx)(`p`,{className:L(`mt-1.5 text-[0.8125rem]`,y?`text-rose`:`text-ink-3`),children:y??q(`project.gradientDescribeHint`)})]}),(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:T(s)}}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.gradientName`)}),(0,$.jsx)(a,{value:s.name,maxLength:80,placeholder:q(`project.gradientNamePlaceholder`),onChange:e=>c({...s,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.fillUseLabel`)}),(0,$.jsx)(a,{value:s.description??``,maxLength:400,placeholder:q(`project.gradientUse`),onChange:e=>c({...s,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:l.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":s.type===e,onClick:()=>E({...s,type:e}),className:L(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,s.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:q(Sn[e])},e))})]}),s.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(I,{children:q(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:s.angle,"aria-label":q(`project.gradientAngle`),onChange:e=>E({...s,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(s.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:s.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(x,{value:bn.test(e.color)?e.color:`#888888`,onChange:e=>D(t,{color:e.target.value})}),(0,$.jsx)(a,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();bn.test(n)&&D(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":q(`project.gradientAt`),onChange:e=>D(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,$.jsx)(Z,{label:q(`project.remove`),disabled:s.stops.length<=2,onClick:()=>E({...s,stops:s.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[s.stops.length<12?(0,$.jsxs)(k,{variant:`secondary`,size:`sm`,onClick:()=>O(),children:[(0,$.jsx)(W,{className:`size-4`}),` `,q(`project.gradientStopAdd`)]}):null,r.length&&s.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:q(`project.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>O(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:`CSS`}),(0,$.jsx)(a,{value:u,spellCheck:!1,onChange:e=>{d(e.target.value);let t=f(e.target.value);m(!t),t&&c({...s,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:L(`mt-1.5 text-[0.8125rem]`,p?`text-rose`:`text-ink-3`),children:q(p?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:o,children:q(`common.cancel`)}),(0,$.jsx)(k,{onClick:()=>{i(s),o()},children:q(`settings.save`)})]})]})})}var wn=`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`,Tn=`size-8 bg-card shadow-soft hover:bg-card`;function En({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(G,{value:e,label:q(`project.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,$.jsx)(G,{value:n??``,label:q(`project.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function Dn({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=T(e),[o,s]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":q(`project.gradientEdit`),onClick:n,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:wn,children:[(0,$.jsx)(Z,{label:q(o?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:Tn,children:(0,$.jsx)(pe,{className:`size-4`})}),(0,$.jsx)(Z,{label:q(`project.download`),onClick:()=>void xn(e,e.name),className:Tn,children:(0,$.jsx)(u,{className:`size-4`})}),t?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:i,className:L(Tn,`hover:text-rose`),children:(0,$.jsx)(J,{className:`size-4`})})]})]}),(0,$.jsx)(En,{name:e.name,namePlaceholder:q(`project.gradientName`),description:e.description,usePlaceholder:q(`project.gradientUse`),readOnly:t,onChange:r})]})}function On(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function kn({projectId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:o}){let s=_(e,t.file);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:r,"aria-label":q(`project.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:On(s,t.tile)}),(0,$.jsxs)(`div`,{className:wn,children:[(0,$.jsx)(`a`,{href:s,download:n,"aria-label":q(`project.download`),title:q(`project.download`),className:L(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,Tn),children:(0,$.jsx)(u,{className:`size-4`})}),r?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:o,className:L(Tn,`hover:text-rose`),children:(0,$.jsx)(J,{className:`size-4`})})]})]}),(0,$.jsx)(En,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:q(`project.patternUse`),readOnly:r,onChange:a})]})}function An({projectId:e,pattern:t,isNew:n,fileName:r,busy:i,error:o,upload:s,removeFile:c,onSave:l,onClose:u}){let[d,f]=(0,Q.useState)(t),[p,m]=(0,Q.useState)([]),h=async e=>{let t=e[0];if(!t)return;let n=await s(t);n&&(m(e=>[...e,n.id]),f(e=>({...e,file:n.id,name:e.name||n.name.replace(/\.[^.]+$/,``)})))},v=()=>{for(let e of p)c(e);u()};return(0,$.jsx)(w,{open:!0,onClose:v,wide:!0,title:q(n?`project.patternNew`:`project.patternEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[d.file?(0,$.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:On(_(e,d.file),d.tile),children:(0,$.jsxs)(me,{accept:`image/*`,multiple:!1,onFiles:e=>void h(e),className:`absolute right-2 bottom-2 h-9 border-solid bg-card px-3.5 text-ink-2 shadow-soft`,children:[i?(0,$.jsx)(g,{className:`size-4`}):(0,$.jsx)(Ce,{className:`size-4`}),q(`project.patternReplace`)]})}):(0,$.jsxs)(me,{accept:`image/*`,multiple:!1,onFiles:e=>void h(e),className:`h-40 flex-col`,children:[i?(0,$.jsx)(g,{className:`size-5`}):(0,$.jsx)(Ce,{className:`size-5`}),q(`project.patternPick`)]}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.patternName`)}),(0,$.jsx)(a,{value:d.name,maxLength:80,placeholder:d.file?r(d.file):q(`project.patternNamePlaceholder`),onChange:e=>f({...d,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.fillUseLabel`)}),(0,$.jsx)(a,{value:d.description??``,maxLength:400,placeholder:q(`project.patternUse`),onChange:e=>f({...d,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.patternShow`)}),(0,$.jsx)(`div`,{className:`flex w-fit gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:[!1,!0].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!d.tile===e,onClick:()=>f({...d,tile:e||void 0}),className:L(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,!!d.tile===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:q(e?`project.patternTile`:`project.patternFill`)},String(e)))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[o?(0,$.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:o}):null,(0,$.jsx)(k,{variant:`ghost`,onClick:v,children:q(`common.cancel`)}),(0,$.jsx)(k,{disabled:!d.file||i,onClick:()=>{for(let e of p.filter(e=>e!==d.file))c(e);t.file&&t.file!==d.file&&c(t.file),l({...d,name:d.name.trim(),description:d.description?.trim()||void 0}),u()},children:q(n?`project.add`:`settings.save`)})]})]})})}var jn=/^#[0-9a-fA-F]{6}$/;function Mn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{s(!0),l(null);try{let{colors:t}=await P.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(d(t),p([])):l(q(`project.colorsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(w,{open:!0,onClose:n,wide:u?!0:void 0,title:q(u?`project.colorsFound`:`project.colorsFromUrl`),children:u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:u.map(e=>{let t=f.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>p(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:L(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,$.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,$.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(O,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>d(null),children:q(`run.back`)}),(0,$.jsx)(k,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.value))),n()},children:f.length>1?q(`project.addMany`,{n:f.length}):q(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.logoUrl`)}),(0,$.jsx)(a,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.colorsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:n,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:o,disabled:!r.trim(),children:q(`run.next`)})]})]})})}function Nn({projectId:e,data:t,colors:n,sections:r,gradients:i,patterns:o,rules:s,sectioned:c,ruled:l,save:u,readOnly:d}){let[f,p]=(0,Q.useState)(()=>n.map(e=>({...e,id:Y()}))),[m,h]=(0,Q.useState)(r),[g,_]=(0,Q.useState)(i),[y,b]=(0,Q.useState)(o),[w,T]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),k=ee(e,d),A=ne(s),[j,te]=(0,Q.useState)(null),[M,re]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(!1),F=S({colors:f.filter(e=>jn.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:m,gradients:g,patterns:y,colorRules:A.rules},u),I=c?m:[],ie=I.filter(e=>(e.kind??`colors`)===`colors`),ae=e=>ie.some(t=>t.id===e.section),L=f.filter(e=>!ae(e)),oe=(L[0]??f[0])?.id,R=(e,t)=>p(n=>n.map(n=>n.id===e?{...n,...t}:n)),se=e=>p(t=>[...t,...e.map(e=>({...e,id:Y()}))].slice(0,E.colors)),B=[{value:``,label:q(`project.sectionStandard`)},...ie.map(e=>({value:e.id,label:e.title||q(`project.sectionUntitled`)}))],V=(e,t)=>{let n=Y();te(n),h(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},ue=e=>({id:Y(),name:``,section:e,type:`linear`,angle:90,stops:[{color:f[0]?.value&&jn.test(f[0].value)?f[0].value:`#4b73ff`,at:0},{color:f[1]?.value&&jn.test(f[1].value)?f[1].value:`#ff6d1b`,at:100}]}),G=e=>t.files.find(t=>t.id===e)?.name??`pattern`,de=[...f.length<E.colors?[{label:q(`project.colorNew`),icon:(0,$.jsx)(W,{className:`size-4 shrink-0`}),onPick:()=>pe()},{label:q(`project.colorsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>P(!0)}]:[],...c&&m.length<E.logoSections?[{label:q(`project.colorSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>V(`colors`,``)},{label:q(`project.gradientSectionAdd`),icon:(0,$.jsx)(It,{className:`size-4 shrink-0`}),onPick:()=>V(`gradients`,q(`project.gradientSectionTitle`))},{label:q(`project.patternSectionAdd`),icon:(0,$.jsx)(Wt,{className:`size-4 shrink-0`}),onPick:()=>V(`patterns`,q(`project.patternSectionTitle`))}]:[],...!l||A.full?[]:[{label:q(`project.ruleNew`),icon:(0,$.jsx)(nt,{className:`size-4 shrink-0`}),onPick:()=>A.add()}]],fe=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(x,{value:jn.test(e.value)?e.value:`#888888`,onChange:t=>R(e.id,{value:t.target.value})}),(0,$.jsx)(a,{value:e.name,autoFocus:e.id===M,placeholder:q(`project.colorName`),maxLength:120,onChange:t=>R(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(a,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>R(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===oe?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(v,{tone:`ember`,children:q(`project.colorAccent`)})}):d?null:(0,$.jsx)(Z,{label:q(`project.colorFirst`),onClick:()=>p(t=>[{...e,section:void 0},...t.filter(t=>t.id!==e.id)]),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:(0,$.jsx)(C,{className:`size-4`})}),d||!ie.length?null:(0,$.jsx)(le,{options:B,value:ae(e)?e.section??``:``,onChange:t=>R(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),d?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:()=>p(t=>t.filter(t=>t.id!==e.id)),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})]},e.id),pe=e=>{let t=Y();re(t),p(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,$.jsxs)(X,{title:q(`project.colors`),hint:q(`project.colorsHint`),save:F,locked:d,action:d?null:(0,$.jsx)(H,{entries:de}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[L.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:L.map(fe)}),d?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.colorUse`)})]}):f.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:q(`project.colorsEmpty`)}),I.map(t=>{let n=t.kind??`colors`,r=f.filter(e=>e.section===t.id),i=g.filter(e=>e.section===t.id),a=y.filter(e=>e.section===t.id),o=n===`gradients`?i.length:n===`patterns`?a.length:r.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(z,{title:t.title,titlePlaceholder:q(n===`gradients`?`project.gradientSectionTitlePlaceholder`:n===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),kind:n===`gradients`?{icon:(0,$.jsx)(It,{}),label:q(`project.kindGradients`)}:n===`patterns`?{icon:(0,$.jsx)(Wt,{}),label:q(`project.kindPatterns`)}:{icon:(0,$.jsx)(Ze,{}),label:q(`project.kindColors`)},autoFocus:j===t.id,readOnly:d,onChange:e=>h(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!o||confirm(q(n===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:t.title||q(`project.sectionUntitled`)}))){h(e=>e.filter(e=>e.id!==t.id)),p(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),_(e=>e.filter(e=>e.section!==t.id));for(let e of a)k.remove(e.file);b(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[i.map(e=>(0,$.jsx)(Dn,{gradient:e,readOnly:d,onEdit:()=>T(e),onChange:t=>_(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>_(t=>t.filter(t=>t.id!==e.id))},e.id)),d||g.length>=E.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>T(ue(t.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(W,{className:`size-5`}),q(`project.gradientAdd`)]})]}):n===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(t=>(0,$.jsx)(kn,{projectId:e,pattern:t,fileName:G(t.file),readOnly:d,onEdit:()=>O(t),onChange:e=>b(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{k.remove(t.file),b(e=>e.filter(e=>e.id!==t.id))}},t.id)),d||y.length>=E.files.pattern?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>O({id:Y(),name:``,section:t.id,file:``}),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(W,{className:`size-5`}),q(`project.patternAdd`)]})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(fe),d||f.length>=E.colors?null:(0,$.jsx)(U,{label:q(`project.colorAdd`),onClick:()=>pe(t.id)})]})]},t.id)}),l?(0,$.jsx)(ce,{rules:A,placeholder:q(`project.colorRulePlaceholder`),readOnly:d}):null]}),k.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:k.error}):null,w?(0,$.jsx)(Cn,{projectId:e,gradient:w,isNew:!g.some(e=>e.id===w.id),brand:f.filter(e=>jn.test(e.value)),onClose:()=>T(null),onSave:e=>_(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,D?(0,$.jsx)(An,{projectId:e,pattern:D,isNew:!y.some(e=>e.id===D.id),fileName:G,busy:k.busy,error:k.error,upload:async e=>(await k.upload(`pattern`,[e]))[0]??null,removeFile:e=>void k.remove(e),onClose:()=>O(null),onSave:e=>b(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,N?(0,$.jsx)(Mn,{projectId:e,onClose:()=>P(!1),onAdd:se}):null]})}var Pn=e=>/^(ja|yes|true)$/i.test(e.trim()),Fn={text:et,longtext:Ke,number:He,date:Te,url:B,email:ct,phone:We,boolean:Ue};function In({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let c=Fn[e??t],l=`${q(`project.factType`)}: ${q(`project.type.${e??t}`)}`,u=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,d=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:l,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:L(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,r?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,$.jsx)(c,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:L(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,a?`bottom-12`:`top-12`),children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:u,onClick:()=>d(void 0),children:[(0,$.jsx)(Ct,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:q(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:q(`project.type.${t}`)}),(0,$.jsx)(O,{className:L(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),xe.map(t=>{let n=Fn[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:u,onClick:()=>d(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:q(`project.type.${t}`)}),(0,$.jsx)(O,{className:L(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Ln({facts:e,save:t,readOnly:n}){let i=(0,Q.useRef)(0),s=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${i.current++}`}))),u=S(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 r=`f${i.current++}`;s.current=`${r}:${t}`;let a={id:r,key:``,label:``,value:``,...e};l(e=>n?[a,...e]:[...e,a])},p=e=>t=>{t&&s.current===e&&(s.current=null,t.focus())},m=o.filter(e=>!c.some(t=>t.key===e));return(0,$.jsxs)(X,{title:q(`project.facts`),hint:q(`project.factsHint`),save:u,locked:n,action:c.length<E.facts&&!n?(0,$.jsxs)(k,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`,!0),children:[(0,$.jsx)(W,{className:`size-4`}),` `,q(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:c.map(e=>{let t=fe(e.value),i=e.type??t;return(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,$.jsx)(a,{ref:p(`${e.id}:label`),value:e.label,placeholder:q(`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:r(e.label,c.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(ve,{checked:Pn(e.value),label:e.label,onChange:t=>d(e.id,{value:q(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Pn(e.value)?q(`project.yes`):q(`project.no`)})]}):(0,$.jsx)(R,{ref:p(`${e.id}:value`),rows:1,minRows:i===`longtext`?2:1,maxRows:10,value:e.value,placeholder:q(`project.factValue`),onChange:t=>d(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(In,{type:e.type,detected:t,onChange:t=>d(e.id,{type:t})}),n?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:()=>l(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]},e.id)})}),c.length<E.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${c.length?`mt-4`:``}`,children:[(0,$.jsxs)(k,{variant:`secondary`,size:`sm`,onClick:()=>f({},`label`),children:[(0,$.jsx)(W,{className:`size-4`}),` `,q(`project.factAdd`)]}),m.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f({key:e,label:q(`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,$.jsx)(W,{className:`size-3.5`}),` `,q(`fact.${e}`)]},e))]}):null]})}function Rn({onLogo:e,children:t,className:n}){let[r,i]=(0,Q.useState)(!1);return e?(0,$.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(an);i(!1),n&&(t.preventDefault(),e(n))},className:L(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,$.jsx)(`div`,{className:n,children:t})}function zn({projectId:e,data:t,readOnly:n,sections:r,rules:i,sectioned:a,ruled:o,save:s}){let c=ee(e,n),[l,u]=(0,Q.useState)(r),d=ne(i),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),g=(0,Q.useRef)(null),_=S({logoSections:l,logoRules:d.rules},s),v=t.files.filter(e=>e.kind===`logo`),y=new Map(v.map(e=>[e.id,e])),b=a?l:[],x=new Set(b.flatMap(e=>e.logos)),C=v.filter(e=>!x.has(e.id)),w=D(v,l)?.id,T=(e,t)=>u(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),O=(e,t)=>u(n=>n.map(n=>n.id===e?{...n,...t}:n)),k=async(e,t)=>{let n=await c.upload(`logo`,e);for(let e of n)T(e.id,t)},A=b.length?{options:[{value:``,label:q(`project.sectionStandard`)},...b.map(e=>({value:e.id,label:e.title||q(`project.sectionUntitled`)}))],current:e=>b.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>T(e.id,t||null)}:void 0,j=(t,n,r)=>(0,$.jsx)(on,{projectId:e,kind:`logo`,files:t,actions:c,accept:`image/*`,addLabel:r?q(`project.logoAdd`):void 0,onUpload:e=>void k(e,n),mainId:w,onMakeMain:e=>{T(e.id,null),c.order(`logo`,[e.id,...v.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:A,onRemove:e=>{confirm(q(`project.removeConfirm`,{name:e.name}))&&(c.remove(e.id),T(e.id,null))}}),te=n?void 0:e=>t=>T(t,e),M=[{label:q(`project.logoUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>g.current?.click()},{label:q(`project.logoFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>h(!0)},...a&&l.length<E.logoSections?[{label:q(`project.logoSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>{let e=Y();p(e),u(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!o||d.full?[]:[{label:q(`project.ruleNew`),icon:(0,$.jsx)(nt,{className:`size-4 shrink-0`}),onPick:()=>d.add()}]];return(0,$.jsxs)(X,{title:q(`project.logos`),hint:q(`project.logosHint`),save:_,action:n?null:(0,$.jsx)(H,{entries:M}),children:[(0,$.jsx)(`input`,{ref:g,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,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(Rn,{onLogo:te?.(null),children:j(C,null,!0)}),b.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(Rn,{onLogo:te?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(z,{title:e.title,description:e.description,titlePlaceholder:q(`project.logoSectionTitle`),descriptionPlaceholder:q(`project.logoSectionUse`),autoFocus:f===e.id,readOnly:n,onChange:t=>O(e.id,t),onRemove:()=>{(!e.logos.length||confirm(q(`project.logoSectionRemoveConfirm`,{name:e.title||q(`project.sectionUntitled`)})))&&u(t=>t.filter(t=>t.id!==e.id))}}),j(e.logos.map(e=>y.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),o?(0,$.jsx)(ce,{rules:d,placeholder:q(`project.logoRulePlaceholder`),readOnly:n}):null]}),c.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:c.error}):null,m?(0,$.jsx)(sn,{kind:`logo`,onClose:()=>h(!1),fetchUrl:e=>c.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)T(t.id,null)}}):null]})}var Bn=e=>URL.canParse(e)?new URL(e).host:e;async function Vn(e,t){let n=de({family:t,source:{url:e}});if(!n)return`down`;if(n.stylesheet)return await Hn(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 Hn(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 Un(e,t){let n=e.source;if(!n)return q(`project.fontSourceNone`);if(`file`in n){let e=t.find(e=>e.id===n.file)?.name??``;return q(`project.fontSourceFile`,{name:e})}return q(`project.fontSourceUrl`,{host:Bn(n.url)})}function Wn({projectId:e,font:t,onSave:n,onClose:r}){let o=(i(e).data?.files??[]).filter(e=>e.mime.startsWith(`font/`)),s=ee(e),c=(0,Q.useRef)(null),[l,u]=(0,Q.useState)(t.source&&`url`in t.source?`url`:`file`),[d,f]=(0,Q.useState)(t.source&&`file`in t.source?t.source.file:``),[p,m]=(0,Q.useState)(t.source&&`url`in t.source?t.source.url:``),[h,g]=(0,Q.useState)(t.source&&`url`in t.source?{url:t.source.url,result:`ok`}:null),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(t.license??``),[x,S]=(0,Q.useState)(!1),C=p.trim(),T=async()=>{v(!0),g({url:C,result:await Vn(C,t.family.trim())}),v(!1)},E=l===`file`?d?{file:d}:null:h?.url===C&&h.result===`ok`?{url:C}:null,D=h?.url===C?h.result:null;return(0,$.jsx)(w,{open:!0,onClose:r,title:q(`project.fontSourceTitle`,{family:t.family}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(`project.fontSourceHint`)}),(0,$.jsx)(N,{value:l,options:[`file`,`url`],label:e=>q(`project.fontSourceKind.${e}`),onChange:e=>u(e)}),l===`file`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.fontSourceFiles`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":d===e.id,onClick:()=>f(e.id),className:L(`rounded-lg px-3 py-2 text-left text-[0.875rem] ring-1 transition`,d===e.id?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:e.name},e.id))}),(0,$.jsx)(`input`,{ref:c,type:`file`,accept:`.woff2,.woff,.ttf,.otf`,className:`hidden`,onChange:async e=>{let t=[...e.target.files??[]];e.target.value=``;let[n]=await s.upload(`asset`,t);n&&f(n.id)}}),(0,$.jsxs)(k,{variant:`ghost`,className:`mt-2`,busy:s.busy,onClick:()=>c.current?.click(),children:[(0,$.jsx)(Je,{className:`size-4`}),q(`project.fontSourceUpload`)]}),s.error?(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-rose`,children:s.error}):null]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),T()},children:[(0,$.jsx)(I,{children:q(`project.fontSourceUrlLabel`)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(a,{value:p,inputMode:`url`,placeholder:q(`project.fontSourceUrlPlaceholder`),onChange:e=>m(e.target.value)}),(0,$.jsx)(k,{type:`submit`,variant:`ghost`,busy:_,disabled:!C.startsWith(`https://`),children:q(`project.fontSourceCheck`)})]}),D?(0,$.jsx)(`p`,{className:L(`mt-1.5 text-[0.875rem]`,D===`ok`?`text-ink-3`:`text-rose`),children:q(`project.fontCheck.${D}`,{host:Bn(C),family:t.family})}):null,D===`ok`?(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-ink-3`,children:q(`project.fontPrivacy`,{host:Bn(C)})}):null]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{hint:q(`project.fontLicenseHint`),children:q(`project.fontLicense`)}),(0,$.jsx)(a,{value:y,maxLength:200,placeholder:q(`project.fontLicensePlaceholder`),onChange:e=>b(e.target.value)}),(0,$.jsxs)(`label`,{className:`mt-2 flex items-start gap-2 text-[0.875rem]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 accent-ember`,checked:x,onChange:e=>S(e.target.checked)}),q(`project.fontLicenseConfirm`,{family:t.family})]})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[t.source?(0,$.jsx)(k,{variant:`ghost`,className:`mr-auto`,onClick:()=>{n({source:void 0,license:t.license}),r()},children:q(`project.fontSourceRemove`)}):null,(0,$.jsx)(k,{variant:`ghost`,onClick:r,children:q(`common.cancel`)}),(0,$.jsx)(k,{disabled:!(E&&x),onClick:()=>{E&&(n({source:E,license:y.trim()||void 0}),r())},children:q(`project.fontSourceSave`)})]})]})})}var Gn=new Set;function Kn(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Gn.has(t))return;Gn.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 qn=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function Jn({unit:e,label:t,...n}){return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,$.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var Yn=`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`,Xn={web:`project.fontUseWeb`,documents:`project.fontUseDocuments`,print:`project.fontUsePrint`,images:`project.fontUseImages`,video:`project.fontUseVideo`};function Zn({projectId:e,font:t,first:n,readOnly:r,autoFocus:a,onChange:o,onRemove:s}){Kn(t.family);let c=i(e).data?.files??[],[l,u]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:qn(t.family)},children:[(0,$.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,$.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:t.family}),t.role?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:t.role}):null]}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(G,{value:t.family,label:q(`project.fontFamily`),placeholder:q(`project.fontFamily`),maxLength:80,autoFocus:a,onChange:e=>o({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(G,{value:t.role,label:q(`project.fontRole`),placeholder:q(n?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>o({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>{let n=t.weights.includes(e);return(0,$.jsx)(`button`,{type:`button`,disabled:r,"aria-pressed":n,onClick:()=>o({weights:n?t.weights.filter(t=>t!==e):[...t.weights,e].sort((e,t)=>e-t)}),style:{fontFamily:qn(t.family),fontWeight:e},className:L(`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,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[r?t.license?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:t.license}):null:(0,$.jsx)(G,{value:t.license??``,label:q(`project.fontLicense`),placeholder:q(`project.fontLicensePlaceholder`),maxLength:200,onChange:e=>o({license:e}),className:`text-[0.8125rem] text-ink-3`}),r&&!t.uses?.length?null:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:q(`project.fontUses`)}),M.map(e=>{let n=!!t.uses?.includes(e);return(0,$.jsxs)(`button`,{type:`button`,disabled:r,"aria-pressed":n,onClick:()=>{let r=n?(t.uses??[]).filter(t=>t!==e):M.filter(n=>n===e||t.uses?.includes(n));o({uses:r.length?r:void 0})},className:L(`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,$.jsx)(O,{className:`size-3.5`}):null,q(Xn[e])]},e)})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[0.8125rem] text-ink-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:Un(t,c)}),r||!t.family.trim()?null:(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:`text-ink underline decoration-border underline-offset-2 hover:decoration-ink`,children:q(t.source?`project.fontSourceChange`:`project.fontSourceSet`)})]}),l?(0,$.jsx)(Wn,{projectId:e,font:t,onSave:o,onClose:()=>u(!1)}):null,r?null:(0,$.jsx)(Z,{label:q(`project.remove`),onClick:s,className:`absolute top-4 right-4 size-8 bg-card opacity-0 shadow-soft transition focus:opacity-100 group-hover/font:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(J,{className:`size-4`})})]})}function Qn({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:qn(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,$.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,$.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,$.jsx)(`div`,{className:`w-40`,children:(0,$.jsx)(G,{value:e.name,label:q(`project.styleName`),placeholder:q(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":q(`project.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:L(Yn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||q(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":q(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:Yn,children:[...new Set([...d,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(Jn,{unit:`px`,label:q(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,$.jsx)(Jn,{unit:q(`project.styleLine`),label:q(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(Jn,{unit:q(`project.styleTracking`),label:q(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:q(`project.styleUpper`),"aria-label":q(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:L(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,$.jsx)(Bt,{className:`size-4`})})]}),r?null:(0,$.jsx)(Z,{label:q(`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,$.jsx)(J,{className:`size-4`})})]})]})}function $n({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{s(!0),l(null);try{let{fonts:t}=await P.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(d(t),p(t.slice(0,2).map(e=>e.family))):l(q(`project.fontsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(w,{open:!0,onClose:n,wide:u?!0:void 0,title:q(u?`project.fontsFound`:`project.fontsFromUrl`),children:u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:q(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map(e=>(0,$.jsx)(er,{font:e,on:f.includes(e.family),onToggle:()=>p(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>d(null),children:q(`run.back`)}),(0,$.jsx)(k,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.family))),n()},children:f.length>1?q(`project.addMany`,{n:f.length}):q(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.logoUrl`)}),(0,$.jsx)(a,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.fontsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:n,children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:o,disabled:!r.trim(),children:q(`run.next`)})]})]})})}function er({font:e,on:t,onToggle:n}){return Kn(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:L(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:qn(e.family)},children:`Aa`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):q(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(O,{className:`size-3.5`})}):null]})}function tr({projectId:e,fonts:t,styles:n,rules:r,ruled:i,sample:a,save:o,readOnly:s}){let[c,l]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(n),f=ne(r),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=S({fonts:c,textStyles:u,typeRules:f.rules},o),v=(e,t=!1)=>{let n=e.map(e=>({id:Y(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&m(n[0].id),l(e=>[...e,...n].slice(0,E.fonts))},y=()=>{let e=Y();m(e),d(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},b=[...c.length<E.fonts?[{label:q(`project.fontNew`),icon:(0,$.jsx)(W,{className:`size-4 shrink-0`}),onPick:()=>v([{family:``,weights:[400,700]}],!0)},{label:q(`project.fontsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>g(!0)}]:[],...u.length<E.textStyles?[{label:q(`project.styleNew`),icon:(0,$.jsx)(mt,{className:`size-4 shrink-0`}),onPick:y}]:[],...!i||f.full?[]:[{label:q(`project.ruleNew`),icon:(0,$.jsx)(nt,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,$.jsxs)(X,{title:q(`project.typography`),hint:q(`project.typographyHint`),save:_,action:s?null:(0,$.jsx)(H,{entries:b}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[c.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:c.map((t,n)=>(0,$.jsx)(Zn,{projectId:e,font:t,first:n===0,readOnly:s,autoFocus:p===t.id,onChange:e=>l(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>l(e=>e.filter(e=>e.id!==t.id))},t.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:q(`project.fontsEmpty`)}),u.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:q(`project.styles`)}),s?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:q(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:u.map(e=>(0,$.jsx)(Qn,{style:e,fonts:c,sample:a,readOnly:s,autoFocus:p===e.id,onChange:t=>d(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>d(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,i?(0,$.jsx)(ce,{rules:f,placeholder:q(`project.typeRulePlaceholder`),readOnly:s}):null]}),h?(0,$.jsx)($n,{projectId:e,onClose:()=>g(!1),onAdd:e=>v(e)}):null]})}function nr({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[i,o]=(0,Q.useState)(e.brand.about??``),s=S({name:n.trim(),about:i.trim()},e=>t({brand:e}));return(0,$.jsx)(X,{title:q(`project.base`),hint:q(`project.baseHint`),save:s,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.title`)}),(0,$.jsx)(a,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(I,{children:q(`project.about`)}),(0,$.jsx)(R,{minRows:4,value:i,onChange:e=>o(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:q(`project.aboutHint`)})]})]})})}function rr({project:e,group:t,children:n}){let r=s(),a=i(e.id),[o,c]=(0,Q.useState)(0),[l,u]=(0,Q.useState)(!1),d=async t=>{await P.patch(`/api/studio/projects/${e.id}`,t),await r.invalidateQueries({queryKey:[`projects`]})},f=Qe({mutationFn:()=>P.del(`/api/studio/projects/${e.id}`),onSuccess:()=>r.invalidateQueries({queryKey:[`projects`]})}),p=xt(),m=Ye(),h=a.data??{files:[],embeddings:!0},g=`${e.id}:${o}`,_=e.readOnly,v=t===`knowledge`,y=dt(`brandSections`),b=dt(`brandRules`),x=dt(`typography`);return ft(_?{}:{title:q(v?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:q(v?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:q(v?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:v?[{label:q(`assistant.suggest.knowledgeHow`)},{label:q(`assistant.suggest.knowledgeSite`),fill:!0},{label:q(`assistant.suggest.knowledgeCategories`)}]:[{label:q(`assistant.suggest.readSite`),fill:!0},{label:q(`assistant.suggest.missing`)},{label:q(`assistant.suggest.facts`)}],summary:v?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${h.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>c(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[_?(0,$.jsx)(qe,{children:Ge(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ge,{id:`base`,children:(0,$.jsx)(nr,{project:e,save:d},`base:${g}`)}),(0,$.jsx)(ge,{id:`facts`,children:(0,$.jsx)(Ln,{facts:e.facts,save:e=>d({facts:e}),readOnly:_},`facts:${g}`)}),(0,$.jsx)(ge,{id:`logos`,children:(0,$.jsx)(zn,{projectId:e.id,data:h,readOnly:_,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:y,ruled:b,save:e=>d({brand:e})},`logos:${g}`)}),(0,$.jsx)(ge,{id:`colors`,children:(0,$.jsx)(Nn,{projectId:e.id,data:h,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],sectioned:y,ruled:b,save:e=>d({brand:e}),readOnly:_},`colors:${g}`)}),x?(0,$.jsx)(ge,{id:`typography`,children:(0,$.jsx)(tr,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:b,sample:e.brand.name||q(`project.typeSample`),save:e=>d({brand:e}),readOnly:_},`typography:${g}`)}):null,(0,$.jsx)(ge,{id:`assets`,children:(0,$.jsx)(yn,{projectId:e.id,data:h,readOnly:_,sections:e.brand.assetSections??[],save:e=>d({brand:e})},`assets:${g}`)})]}):null,n,t===`info`&&p&&!_&&m?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(k,{variant:`danger`,onClick:()=>u(!0),children:q(`settings.delete`)}),(0,$.jsxs)(w,{open:l,onClose:()=>u(!1),title:q(`settings.deleteTitle`,{name:e.name}),children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:q(`settings.deleteBody`)}),f.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:f.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>u(!1),children:q(`common.cancel`)}),(0,$.jsx)(k,{variant:`danger`,busy:f.isPending,onClick:()=>f.mutate(),children:q(`common.delete`)})]})]})]}):null]})}var ir=`results-search`,ar={q:``,mode:``,days:0};function or(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 A({queryKey:[`results`,e,i],queryFn:()=>P.get(`/api/studio/projects/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function sr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[o,s]=(0,Q.useState)(r.q);return yt({icon:V,label:q(`space.resultsSearch`),run:()=>{let e=document.getElementById(ir);e?.scrollIntoView({block:`center`,behavior:`smooth`}),e?.focus()}}),(0,Q.useEffect)(()=>{if(o===r.q)return;let e=setTimeout(()=>i({...r,q:o}),250);return()=>clearTimeout(e)},[o,r,i]),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(ie,{value:t??``,onChange:e=>n(e||null),options:[{value:``,label:q(`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,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,$.jsx)(V,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(a,{type:`search`,value:o,onChange:e=>s(e.target.value),id:ir,placeholder:q(`space.resultsSearch`),"aria-label":q(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(ie,{value:r.mode,onChange:e=>i({...r,mode:e}),options:[{value:``,label:q(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(ie,{value:String(r.days),onChange:e=>i({...r,days:Number(e)}),options:[{value:`0`,label:q(`space.resultsAnyTime`)},{value:`1`,label:q(`space.resultsDay`)},{value:`7`,label:q(`space.resultsDays`,{n:7})},{value:`30`,label:q(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function cr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Q.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(j,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{title:t?s(t):q(`space.resultsAll`),hint:q(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(sr,{data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}),e.runs.length?(0,$.jsx)(p,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,q(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:q(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(ue,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(v,{children:q(`run.testChip`)}):(0,$.jsxs)(v,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(p,{children:(0,$.jsx)(te,{children:r.q.trim()||r.mode||r.days?q(`space.resultsNone`):q(`space.resultsEmpty`)})})]}),a?(0,$.jsx)(Ie,{header:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(a.wizardId)}),a.mode===`test`?(0,$.jsx)(v,{children:q(`run.testChip`)}):(0,$.jsxs)(v,{tone:`live`,children:[`Live v`,a.version]})]}),onClose:()=>o(null),children:(0,$.jsx)(Pt,{runId:a.id,compact:!0,studio:!0},a.id)}):null]})}function lr({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,o]=(0,Q.useState)(e.name),s=Qe({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{label:q(`project.rename`),onClick:()=>{o(e.name),r(!0)},children:(0,$.jsx)(_e,{className:`size-4`})}),(0,$.jsx)(w,{open:n,onClose:()=>r(!1),title:q(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&s.mutate()},children:[(0,$.jsx)(a,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>o(e.target.value)}),s.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(k,{variant:`ghost`,onClick:()=>r(!1),children:q(`common.cancel`)}),(0,$.jsx)(k,{type:`submit`,busy:s.isPending,disabled:!i.trim(),children:q(`settings.save`)})]})]})})]})}function ur({project:e}){let t=s();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(rt,{}),e.readOnly?null:(0,$.jsx)(lr,{project:e,save:async n=>{await P.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function dr(e){let t=e.join(` `),[n,r]=(0,Q.useState)(e[0]);return(0,Q.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=bt(),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 fr(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function pr({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(wt,{icon:e.icon??tt,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(Dt,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function mr(){let{group:e}=ae(),[t,n]=se(),r=oe(),i=y(),{hash:a}=i,{project:o,loading:s}=$e(),c=xt(),l=_t(),u=Nt(),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),v=ot(e)?e:void 0,b=v?void 0:l.spaceParts.find(t=>t.id===e),x=v??b?.id,S=i.state?.parts===!0,C=st(lt(),l).map(e=>({...e,to:`/space/${e.id}`})),w={id:`results`,label:q(`space.results`),icon:vt,to:`/space/results`},T=v===`results`?w:C.find(e=>e.id===x),E=t.get(`show`),D=v===`results`?2:x?E?2:1:0,O=v===`results`?1:u?Math.min(D,1):x&&g!==x&&!S?1:0,k=Et(O),A=Et(D),j=(0,Q.useMemo)(()=>({slot:d,narrow:u,setDetail:m}),[d,u]),ee=o?o.brand.name?.trim()||o.name:q(`nav.project`),ne=dt(`typography`)?[]:[`typography`],M=b?l.spaceMenus[b.id]??[]:[],re=b?[{plugin:null,label:null,sections:M}]:v&&v!==`results`?pt(v,l,ne):[],N=v?pt(v,l).filter(e=>e.plugin):[],P=dr([...re,...v===`results`?N:[]].flatMap(e=>e.sections.map(e=>e.id))),F=v===`results`&&E&&E!==`all`?E:null,[I,ie]=(0,Q.useState)(ar),R=or(v===`results`?o?.id:void 0,F,I),ce=R.data?.wizards.find(e=>e.id===F)?.title,z=v===`data`&&E&&E!==`all`||v===`knowledge`&&E&&/^[ptfcvs]:/.test(E)?E:null,B=z?.startsWith(`s:`)?l.spaceSections.find(e=>e.id===z.slice(2)):void 0,V=v===`knowledge`&&z&&/^[ptf]:/.test(z)?z:null,H=Oe(v===`data`?o?.id:void 0),U=Fe(v===`knowledge`?o?.id:void 0),W=Ve(z?.startsWith(`v:`)?z.slice(2):``),le=U.data?.categories.find(e=>e.id===(z?.startsWith(`c:`)?z.slice(2):W.data?.category.id)),ue=v===`knowledge`?B?B.label():z?.startsWith(`v:`)?W.data&&`${W.data.category.name}: ${W.data.value}`:z?.startsWith(`c:`)?le?.name:U.data?.items.find(e=>e.key===z)?.title:H.data?ze(H.data).flatMap(e=>e.items).find(e=>e.key===z)?.title:void 0;St([...v===`results`?[]:[{label:q(`nav.project`),to:`/space`}],...T?[{label:T.label,to:`/space/${T.id}`}]:[],...T&&(p??ce??ue)?[{label:p??ce??ue}]:[]]);let G={p:`page`,t:`table`,f:`file`,c:`category`,v:`category value`,s:`plugin section`};ft({...v===`data`||v===`results`?{compact:!0}:{},...v===`data`?{suggestions:[{label:q(`assistant.suggest.dataWhat`)},{label:q(`assistant.suggest.dataWho`)},{label:q(`assistant.suggest.dataEdit`)}]}:v===`results`?{suggestions:[{label:q(`assistant.suggest.resultsFailed`)},{label:q(`assistant.suggest.resultsCost`)},{label:q(`assistant.suggest.resultsShare`)}]}:{},...z&&ue?{open:{kind:G[z[0]]??`item`,id:z.slice(2),label:ue}}:F&&ce?{open:{kind:`wizard`,id:F,label:ce}}:{}});let de=v===`results`||v===`data`||z?a.slice(1):E||a.slice(1),fe=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${x}#${de}`;de&&fe.current!==e&&document.getElementById(de)&&(fe.current=e,requestAnimationFrame(()=>fr(de,!1)))},[x,de,o?.id,l.spaceSections,M.length]),!x){let t=a.slice(1),n=t?at(t,l):null;if(n===`knowledge`&&l.spaceSections.some(e=>e.id===t))return(0,$.jsx)(h,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(h,{to:u?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if((t||e)&&l.status!==`ready`)return null;if(e!==void 0||!u)return(0,$.jsx)(h,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(v===`knowledge`&&!E&&l.spaceSections.some(e=>e.id===a.slice(1)))return(0,$.jsx)(h,{to:`/space/knowledge?show=s:${a.slice(1)}`,replace:!0});let pe=e=>{if(u){r({search:`?show=${e}`});return}fe.current=`${x}#${e}`,fr(e,!0),r({search:``,hash:e},{replace:!0})},K=e=>u?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),me=e=>e.flatMap(e=>e.sections).map(e=>l.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(ge,{id:e.id,children:(0,$.jsx)(X,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(ht,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),he=u?void 0:P,_e=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ot,{title:ee,open:O===1?T??null:null,onBack:v===`results`?void 0:()=>u?r(`/space`):_(x??null),root:{icon:gt,label:q(`nav.project`),backLabel:q(`nav.wizards`),onBack:()=>r(`/`)}}),(0,$.jsx)(`div`,{className:L(Tt(k)),children:O===0?(0,$.jsx)(At,{entries:C,current:u?void 0:T,onPick:()=>_(null)}):(0,$.jsx)(`div`,{ref:f})},O)]});return(0,$.jsx)(kt.Provider,{value:j,children:(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:L(`grid gap-6`,v!==`results`&&`md:grid-cols-[10.5rem_minmax(0,1fr)] md:gap-5 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[v===`results`?null:(0,$.jsx)(`aside`,{className:L(`min-w-0 md:sticky md:top-6 md:self-start`,u&&D===2&&`hidden`,u&&A===`back`&&Tt(`back`)),children:_e}),x?(0,$.jsxs)(`div`,{className:L(`min-w-0`,u&&D<2&&`hidden`,u&&A===`deeper`&&Tt(`deeper`)),children:[u&&v!==`results`?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(Mt,{label:T?.label??ee,onBack:()=>r(`/space/${x}`)})}):null,c&&o?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(ur,{project:o})}):null,v===`data`?(0,$.jsxs)(jt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(wt,{icon:Kt,label:q(`data.all`),selected:!u&&!z,onPick:()=>K(`all`)})}),H.data?ze(H.data).map(e=>(0,$.jsx)(Dt,{label:e.label,children:e.items.map(e=>(0,$.jsx)(wt,{icon:De[e.kind],label:e.title,selected:!u&&e.key===z,onPick:()=>K(e.key)},e.key))},e.key)):null,(0,$.jsx)(pr,{groups:N,current:he,onPick:pe})]}):v===`knowledge`?(0,$.jsxs)(jt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(wt,{icon:Kt,label:q(`know.all`),selected:!(u||z),onPick:()=>K(`all`)})}),U.data?.categories.length?(0,$.jsx)(Dt,{label:q(`know.categories`),children:U.data.categories.map(e=>(0,$.jsx)(wt,{icon:Me[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!u&&(z===`c:${e.id}`||W.data?.category.id===e.id),onPick:()=>K(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(pr,{groups:N,current:u?void 0:B?.id,onPick:e=>K(`s:${e}`)})]}):(0,$.jsx)(jt,{children:(0,$.jsx)(pr,{groups:re,current:he,onPick:pe})}),o&&(v===`info`||v===`knowledge`)?(0,$.jsxs)(rr,{project:o,group:v,children:[v===`knowledge`?V?V.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:V.slice(2),onGone:()=>K(`all`),onOpen:K},V):V.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:V.slice(2),onGone:()=>K(`all`)},V):(0,$.jsx)(fn,{projectId:o.id,fileId:V.slice(2),readOnly:o.readOnly,onGone:()=>K(`all`)},V):U.data?B?(0,$.jsx)(X,{title:B.label(),hint:B.hint?.(),plain:!0,children:(0,$.jsx)(ht,{of:B,children:(0,$.jsx)(B.component,{})})},z):z?.startsWith(`c:`)?le?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(je,{projectId:o.id,category:le,readOnly:o.readOnly,onOpen:K,onGone:()=>K(`all`)}),le.type===`choice`?null:(0,$.jsx)(Be,{projectId:o.id,category:le,categories:U.data.categories,onOpen:K})]},z):null:z?.startsWith(`v:`)?W.data?(0,$.jsx)(Ee,{value:W.data,readOnly:o.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[W.data.items.length?(0,$.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:W.data.items.map(e=>(0,$.jsx)(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,$.jsx)(`button`,{type:`button`,onClick:()=>K(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:q(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},z):null:(0,$.jsx)(ge,{id:`documents`,children:(0,$.jsx)(Re,{projectId:o.id,data:U.data,readOnly:o.readOnly,onOpen:K})}):null:null,v===`info`?me(N):null]},o.id):null,o&&b?(0,$.jsx)(ht,{of:b,children:(0,$.jsx)(it,{part:b.id,children:(0,$.jsx)(b.component,{})},o.id)}):null,o&&v===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:z?.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:z.slice(2),onGone:()=>K(`all`)},z):z?.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:z.slice(2),onGone:()=>K(`all`)},z):(0,$.jsxs)($.Fragment,{children:[H.data?(0,$.jsx)(Le,{projectId:o.id,data:H.data,readOnly:o.readOnly,onOpen:K}):null,me(N)]})}):null,o&&v===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[R.data?(0,$.jsx)(cr,{data:R.data,wizardId:F,onWizard:e=>K(e??`all`),filter:I,onFilter:ie}):null,R.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:R.error.message}):null,me(N)]}):null,o||s?null:(0,$.jsx)(te,{children:q(`settings.noProject`)})]}):null]})})})}export{mr as ProjectPage};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{G as r,Gr as i,Gt as a,Mn as o,Ot as s,Pt as c,Qr as l,Rr as u,V as d,Vr as f,X as p,Xr as m,Xt as h,Yr as g,Z as _,an as v,er as y,nt as ee,rn as b,tn as x,tt as S,zt as C}from"./ui-LJgQlXbd.js";import{_ as w,d as te,f as T,g as E,h as D,m as O,p as k,t as ne,u as A}from"./theme-BucH2rUv.js";import{$ as j,At as M,It as re,jt as N,kt as P}from"./index-TJhB4-x8.js";import{t as ie}from"./RunnerView-CufG6xDP.js";var F={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};F.node;var ae=f(F),I={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};I.node;var oe=f(I),se={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};se.node;var ce=f(se),L=e(t(),1);function le(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var R=le(),ue=R?new URLSearchParams(window.location.search).get(`page`):null,z=new URLSearchParams(window.location.search).get(`theme`),B=z?`?theme=${encodeURIComponent(z)}`:``,V=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),de=()=>V(`close`);function fe(e){(0,L.useEffect)(()=>{if(R===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>V(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(R===`modal`||R===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&V(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var H=e(n(),1),U=`wizards.runner.translate`,W=new Set;function pe(){try{return localStorage.getItem(U)===`on`}catch{return!1}}function me(e){try{localStorage.setItem(U,e?`on`:`off`)}catch{}for(let e of W)e()}function he(){return(0,L.useSyncExternalStore)(e=>(W.add(e),()=>W.delete(e)),pe)}function ge(e){let t=he(),[n]=(0,L.useState)(()=>v()),r=e?.lang??`en`,i=e?.translatable&&n&&n!==r?n:null,a=i&&t?i:r,s=e?.token,c=l({queryKey:[`public-translation`,s,a],enabled:!!(s&&a!==r),queryFn:()=>d.post(`/api/public/wizards/${s}/translation${B}`,{lang:a}),staleTime:1/0,retry:!1}),u=l({queryKey:[`public-texts`,s,a],enabled:!(!s||o(a)),queryFn:()=>d.get(`/api/public/wizards/${s}/texts/${a}`),staleTime:1/0,retry:!1}),f=!o(a),p=a===r||c.data&&(!f||u.data),m=a!==r&&(c.isError||f&&u.isError),h=p&&!m?a:r,g=(0,L.useMemo)(()=>!o(h)&&u.data?.lang===h?{lang:u.data.lang,runner:u.data.runner,notes:u.data.notes}:null,[h,u.data]);if((0,L.useEffect)(()=>{e&&x(h,g)},[e,h,g]),(0,L.useEffect)(()=>()=>x(null),[]),!e)return null;let _=h!==r&&c.data?c.data:null;return{own:r,other:i,shown:h,wizard:_??e,translating:a!==r&&!p&&!m,failed:!!m,translated:!!_,machine:_?.translation?.machine??!1,pick:e=>me(e!==r)}}function G({page:e,tone:t=`ground`}){if(!e?.other)return null;let n=e.translating?e.other:e.shown;return(0,H.jsx)(j,{langs:[e.own,e.other],value:n,onPick:e.pick,tone:t})}function K({page:e,small:t}){if(!e)return null;let n=t?`truncate text-[0.75rem]`:`text-[0.8125rem]`;return e.failed?(0,H.jsx)(`p`,{className:h(`text-ink-3`,n),children:b(`translation.failed`)}):e.translated?(0,H.jsxs)(`p`,{className:h(`text-ink-3`,n),children:[e.machine?(0,H.jsxs)(H.Fragment,{children:[b(`translation.machine`),` · `]}):null,(0,H.jsx)(`button`,{type:`button`,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,onClick:()=>e.pick(e.own),children:b(`translation.showOriginal`)})]}):null}function _e(e,t){let n=(0,L.useRef)(null),r=t&&!t.translating?t.translated?t.shown:null:void 0;(0,L.useEffect)(()=>{if(!e||r===void 0)return;let t=`${e}:${r}`;n.current!==t&&(n.current=t,d.post(`/api/runs/${e}/lang`,{lang:r}).catch(()=>void 0))},[e,r])}function ve(e,t){(0,L.useEffect)(()=>{if(!e||!t)return;let n=p(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var q=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,J=q||/Android/.test(navigator.userAgent);function ye(){let[e,t]=(0,L.useState)(()=>window.wizardInstall??null),[n,r]=(0,L.useState)(!1);if((0,L.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||J&&!e&&!q)return null;let i=/Mac/.test(navigator.platform),a=b(J?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,H.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>{J&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[J?(0,H.jsx)(ce,{className:`size-4`}):(0,H.jsx)(ae,{className:`size-4`}),b(J?`install.add`:`install.bookmark`)]}),n?(0,H.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function Y({brand:e,toggle:t=!0,start:n}){return(0,H.jsx)(`header`,{className:`safe-top`,children:(0,H.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[n?(0,H.jsx)(`div`,{className:`absolute left-3`,children:n}):null,e.logoUrl?(0,H.jsx)(`img`,{src:p(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,H.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,H.jsx)(`div`,{className:`absolute right-3`,children:(0,H.jsx)(N,{})}):null]})})}function X({siteKey:e,onToken:t}){let n=(0,L.useRef)(null);return(0,L.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,H.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function be({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||_||R?null:(0,H.jsxs)(`a`,{href:S(`${window.location.origin}${r}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,H.jsx)(oe,{className:`size-4`}),` `,b(`install.app`)]})}var Z=e=>`wz.run.${e}`,xe=_&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=R===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t,n){let r=g(),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),u=(()=>{try{return localStorage.getItem(Z(e.token))}catch{return null}})();return{busy:i,error:o,captcha:c,setCaptcha:l,start:async()=>{a(!0),s(null);try{let{runId:i}=await d.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:R!==null,origin:ue??void 0,lang:n??void 0});try{localStorage.setItem(Z(e.token),i)}catch{}r(`${t}/${i}`,{replace:xe})}catch(e){s(e.message),a(!1)}},resume:u?()=>r(`${t}/${u}`):null}}function Se({wizard:e,page:t}){let{busy:n,error:r,captcha:i,setCaptcha:o,start:s,resume:l}=$(e,`/w/${e.token}`,t?.translated?t.shown:null),d=xe&&e.available&&!e.turnstileSiteKey,f=(0,L.useRef)(!1);return(0,L.useEffect)(()=>{d&&!f.current&&(f.current=!0,s())},[d]),d&&!r?(0,H.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,H.jsx)(a,{})}):(0,H.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,H.jsx)(M,{kind:e.avatar,costume:e.costume,size:190,fluffy:!0}),(0,H.jsx)(`h1`,{className:`wizard-title mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,H.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,(0,H.jsx)(`div`,{className:`mt-3`,children:(0,H.jsx)(K,{page:t})}),e.available?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(c,{size:`lg`,className:`mt-10 min-w-48`,busy:n,disabled:!!e.turnstileSiteKey&&!i,onClick:s,children:[b(`run.start`),` `,(0,H.jsx)(u,{className:`size-4`})]}),e.turnstileSiteKey?(0,H.jsx)(X,{siteKey:e.turnstileSiteKey,onToken:o}):null,l?(0,H.jsx)(`button`,{type:`button`,onClick:l,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:b(`run.resume`)}):null,(0,H.jsx)(Ce,{wizard:e,current:`steps`}),R||_?null:(0,H.jsx)(ye,{}),(0,H.jsx)(be,{token:e.token})]}):(0,H.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??b(`run.unavailable`)}),r?(0,H.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:r}):null]})}function Ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,H.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,H.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:b(`run.orAs`,{label:e.label})},e.id))}):null}function we({wizard:e,page:t}){let n=w();return(0,H.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,H.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,H.jsx)(`span`,{className:h(n?.speaking&&`animate-breathe`),children:(0,H.jsx)(M,{kind:e.avatar,costume:e.costume,size:38})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null,(0,H.jsx)(K,{page:t,small:!0})]}),e.brand.logoUrl&&R!==`popout`?(0,H.jsx)(`img`,{src:p(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,(0,H.jsx)(G,{page:t,tone:`surface`}),R?null:(0,H.jsx)(N,{}),R===`popout`?(0,H.jsx)(C,{label:b(`common.close`),onClick:de,children:(0,H.jsx)(y,{className:`size-5`})}):null]})})}function Te({door:e,wizard:t,page:n,header:r,footer:i}){let{busy:a,error:o,captcha:s,setCaptcha:c,start:l,resume:d}=$(t,`/w/${t.token}/${e}`,n?.translated?n.shown:null),f=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&f.push({key:e,who:`bot`,node:b(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||f.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??b(`run.unavailable`)}),o&&f.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&f.push(E(`start`,(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(O,{primary:!0,busy:a,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[b(`run.start`),` `,(0,H.jsx)(u,{className:`size-4`})]}),d?(0,H.jsx)(O,{onClick:d,children:b(`run.resume`)}):null,t.turnstileSiteKey?(0,H.jsx)(X,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,H.jsxs)(T,{header:r,footer:i,children:[(0,H.jsx)(D,{avatar:t.avatar,costume:t.costume,lines:f}),(0,H.jsx)(k,{})]})}function Ee({className:e}){return(0,H.jsx)(`footer`,{className:h(`text-center text-ink-4`,e),children:(0,H.jsx)(`a`,{href:`${r}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:b(`run.madeWith`).replace(`engenty wizards`,P.name)})})}function De({chat:e=!1,steps:t=!1,talk:n=!1,video:o=!1}){let{token:u,runId:f}=m(),p=g(),v=l({queryKey:[`public`,u,B],queryFn:()=>d.get(`/api/public/wizards/${u}${B}`),retry:(e,t)=>s(t)&&e<3}),y=v.data?.runners??[],x=!v.data||y.some(e=>e.id===`talk`),S=!v.data||y.some(e=>e.id===`video`),C=!v.data||y.some(e=>e.id===`chat`)||n&&x||o&&S,w=y[0]?.id,T=e||R===`popout`||!t&&!f&&C&&(w===`chat`||w===`talk`||w===`video`),E=o&&S||!t&&!e&&!n&&w===`video`,D=!E&&(n&&x||!t&&!e&&w===`talk`),O=E?`video`:D?`talk`:`chat`,k=ge(v.data);_e(f,k),ne(v.data?.brand.theme),re(v.data?.avatar),ve(u,v.data?.title),fe(T);let j=k?.wizard.title??v.data?.title;if((0,L.useEffect)(()=>{j&&(document.title=j)},[j]),(0,L.useEffect)(()=>{u&&f&&ee(`run`,{token:u,runId:f})},[u,f]),v.isLoading)return(0,H.jsx)(`div`,{className:h(`flex items-center justify-center text-ink-4`,Q),children:(0,H.jsx)(a,{})});if(e&&v.data&&!C||n&&v.data&&!x||o&&v.data&&!S)return(0,H.jsx)(i,{to:`/w/${u}`,replace:!0});if(!v.data){let e=s(v.error);return(0,H.jsxs)(`div`,{className:h(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,H.jsx)(M,{kind:`pebble`,size:80}),(0,H.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:b(e?`common.offline`:`run.notFound`)}),e?(0,H.jsx)(c,{variant:`secondary`,onClick:()=>void v.refetch(),children:b(`common.retry`)}):null]})}let N=k?.wizard??v.data,F=k?.translating?(0,H.jsxs)(`div`,{className:h(`flex flex-col items-center justify-center gap-3 text-ink-3`,Q),children:[(0,H.jsx)(a,{}),(0,H.jsx)(`p`,{className:`text-[0.875rem]`,children:b(`translation.working`)})]}):null;if(T){let e=(0,H.jsx)(we,{wizard:N,page:k}),t=_?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(Ee,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,H.jsxs)(`div`,{className:`wizard-page flex h-dvh flex-col`,children:[(0,H.jsx)(A,{effects:v.data.brand.theme.effects}),F??(f?(0,H.jsx)(te,{runId:f,talk:D,call:E?`video`:D?`audio`:!1,onRestart:()=>p(`/w/${u}/${O}`),header:E||D?void 0:e,footer:t}):(0,H.jsx)(Te,{wizard:N,page:k,header:e,footer:t,door:O}))]})}return(0,H.jsxs)(`div`,{className:h(`wizard-page flex flex-col`,Q),children:[(0,H.jsx)(A,{effects:v.data.brand.theme.effects}),R===`inline`||_?null:(0,H.jsx)(Y,{brand:v.data.brand,toggle:!R,start:(0,H.jsx)(G,{page:k})}),R===`inline`||_?(0,H.jsx)(`div`,{className:`flex justify-end px-3 pt-2`,children:(0,H.jsx)(G,{page:k,tone:`surface`})}):null,f&&(k?.translated||k?.failed)?(0,H.jsx)(`div`,{className:`flex justify-center px-5`,children:(0,H.jsx)(K,{page:k})}):null,(0,H.jsx)(`div`,{className:`flex-1`,children:F??(f?(0,H.jsx)(ie,{runId:f,onRestart:()=>p(`/w/${u}`)}):(0,H.jsx)(Se,{wizard:N,page:k}))}),_?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,H.jsx)(`a`,{href:`${r}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:b(`run.madeWith`).replace(`engenty wizards`,P.name)})})]})}export{Y as BrandHeader,De as PublicRunner};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{G as r,Gr as i,Gt as a,Mn as o,Ot as s,Pt as c,Qr as l,Rr as u,V as d,Vr as f,X as p,Xr as m,Xt as h,Yr as g,Z as _,an as v,er as y,nt as ee,rn as b,tn as x,tt as S,zt as C}from"./ui-kIzOrA_W.js";import{_ as w,d as te,f as T,g as E,h as D,m as O,p as k,t as ne,u as A}from"./theme-DZZXa238.js";import{$ as j,At as M,It as re,jt as N,kt as P}from"./index-DfHH4icT.js";import{t as ie}from"./RunnerView-DeDApA-9.js";var F={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};F.node;var ae=f(F),I={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};I.node;var oe=f(I),se={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};se.node;var ce=f(se),L=e(t(),1);function le(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var R=le(),ue=R?new URLSearchParams(window.location.search).get(`page`):null,z=new URLSearchParams(window.location.search).get(`theme`),B=z?`?theme=${encodeURIComponent(z)}`:``,V=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),de=()=>V(`close`);function fe(e){(0,L.useEffect)(()=>{if(R===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>V(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(R===`modal`||R===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&V(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var H=e(n(),1),U=`wizards.runner.translate`,W=new Set;function pe(){try{return localStorage.getItem(U)===`on`}catch{return!1}}function me(e){try{localStorage.setItem(U,e?`on`:`off`)}catch{}for(let e of W)e()}function he(){return(0,L.useSyncExternalStore)(e=>(W.add(e),()=>W.delete(e)),pe)}function ge(e){let t=he(),[n]=(0,L.useState)(()=>v()),r=e?.lang??`en`,i=e?.translatable&&n&&n!==r?n:null,a=i&&t?i:r,s=e?.token,c=l({queryKey:[`public-translation`,s,a],enabled:!!(s&&a!==r),queryFn:()=>d.post(`/api/public/wizards/${s}/translation${B}`,{lang:a}),staleTime:1/0,retry:!1}),u=l({queryKey:[`public-texts`,s,a],enabled:!(!s||o(a)),queryFn:()=>d.get(`/api/public/wizards/${s}/texts/${a}`),staleTime:1/0,retry:!1}),f=!o(a),p=a===r||c.data&&(!f||u.data),m=a!==r&&(c.isError||f&&u.isError),h=p&&!m?a:r,g=(0,L.useMemo)(()=>!o(h)&&u.data?.lang===h?{lang:u.data.lang,runner:u.data.runner,notes:u.data.notes}:null,[h,u.data]);if((0,L.useEffect)(()=>{e&&x(h,g)},[e,h,g]),(0,L.useEffect)(()=>()=>x(null),[]),!e)return null;let _=h!==r&&c.data?c.data:null;return{own:r,other:i,shown:h,wizard:_??e,translating:a!==r&&!p&&!m,failed:!!m,translated:!!_,machine:_?.translation?.machine??!1,pick:e=>me(e!==r)}}function G({page:e,tone:t=`ground`}){if(!e?.other)return null;let n=e.translating?e.other:e.shown;return(0,H.jsx)(j,{langs:[e.own,e.other],value:n,onPick:e.pick,tone:t})}function K({page:e,small:t}){if(!e)return null;let n=t?`truncate text-[0.75rem]`:`text-[0.8125rem]`;return e.failed?(0,H.jsx)(`p`,{className:h(`text-ink-3`,n),children:b(`translation.failed`)}):e.translated?(0,H.jsxs)(`p`,{className:h(`text-ink-3`,n),children:[e.machine?(0,H.jsxs)(H.Fragment,{children:[b(`translation.machine`),` · `]}):null,(0,H.jsx)(`button`,{type:`button`,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,onClick:()=>e.pick(e.own),children:b(`translation.showOriginal`)})]}):null}function _e(e,t){let n=(0,L.useRef)(null),r=t&&!t.translating?t.translated?t.shown:null:void 0;(0,L.useEffect)(()=>{if(!e||r===void 0)return;let t=`${e}:${r}`;n.current!==t&&(n.current=t,d.post(`/api/runs/${e}/lang`,{lang:r}).catch(()=>void 0))},[e,r])}function ve(e,t){(0,L.useEffect)(()=>{if(!e||!t)return;let n=p(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var q=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,J=q||/Android/.test(navigator.userAgent);function ye(){let[e,t]=(0,L.useState)(()=>window.wizardInstall??null),[n,r]=(0,L.useState)(!1);if((0,L.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||J&&!e&&!q)return null;let i=/Mac/.test(navigator.platform),a=b(J?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,H.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>{J&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[J?(0,H.jsx)(ce,{className:`size-4`}):(0,H.jsx)(ae,{className:`size-4`}),b(J?`install.add`:`install.bookmark`)]}),n?(0,H.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function Y({brand:e,toggle:t=!0,start:n}){return(0,H.jsx)(`header`,{className:`safe-top`,children:(0,H.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[n?(0,H.jsx)(`div`,{className:`absolute left-3`,children:n}):null,e.logoUrl?(0,H.jsx)(`img`,{src:p(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,H.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,H.jsx)(`div`,{className:`absolute right-3`,children:(0,H.jsx)(N,{})}):null]})})}function X({siteKey:e,onToken:t}){let n=(0,L.useRef)(null);return(0,L.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,H.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function be({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||_||R?null:(0,H.jsxs)(`a`,{href:S(`${window.location.origin}${r}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,H.jsx)(oe,{className:`size-4`}),` `,b(`install.app`)]})}var Z=e=>`wz.run.${e}`,xe=_&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=R===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t,n){let r=g(),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),u=(()=>{try{return localStorage.getItem(Z(e.token))}catch{return null}})();return{busy:i,error:o,captcha:c,setCaptcha:l,start:async()=>{a(!0),s(null);try{let{runId:i}=await d.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:R!==null,origin:ue??void 0,lang:n??void 0});try{localStorage.setItem(Z(e.token),i)}catch{}r(`${t}/${i}`,{replace:xe})}catch(e){s(e.message),a(!1)}},resume:u?()=>r(`${t}/${u}`):null}}function Se({wizard:e,page:t}){let{busy:n,error:r,captcha:i,setCaptcha:o,start:s,resume:l}=$(e,`/w/${e.token}`,t?.translated?t.shown:null),d=xe&&e.available&&!e.turnstileSiteKey,f=(0,L.useRef)(!1);return(0,L.useEffect)(()=>{d&&!f.current&&(f.current=!0,s())},[d]),d&&!r?(0,H.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,H.jsx)(a,{})}):(0,H.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,H.jsx)(M,{kind:e.avatar,costume:e.costume,size:190,fluffy:!0}),(0,H.jsx)(`h1`,{className:`wizard-title mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,H.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,(0,H.jsx)(`div`,{className:`mt-3`,children:(0,H.jsx)(K,{page:t})}),e.available?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(c,{size:`lg`,className:`mt-10 min-w-48`,busy:n,disabled:!!e.turnstileSiteKey&&!i,onClick:s,children:[b(`run.start`),` `,(0,H.jsx)(u,{className:`size-4`})]}),e.turnstileSiteKey?(0,H.jsx)(X,{siteKey:e.turnstileSiteKey,onToken:o}):null,l?(0,H.jsx)(`button`,{type:`button`,onClick:l,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:b(`run.resume`)}):null,(0,H.jsx)(Ce,{wizard:e,current:`steps`}),R||_?null:(0,H.jsx)(ye,{}),(0,H.jsx)(be,{token:e.token})]}):(0,H.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??b(`run.unavailable`)}),r?(0,H.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:r}):null]})}function Ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,H.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,H.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:b(`run.orAs`,{label:e.label})},e.id))}):null}function we({wizard:e,page:t}){let n=w();return(0,H.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,H.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,H.jsx)(`span`,{className:h(n?.speaking&&`animate-breathe`),children:(0,H.jsx)(M,{kind:e.avatar,costume:e.costume,size:38})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,H.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null,(0,H.jsx)(K,{page:t,small:!0})]}),e.brand.logoUrl&&R!==`popout`?(0,H.jsx)(`img`,{src:p(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,(0,H.jsx)(G,{page:t,tone:`surface`}),R?null:(0,H.jsx)(N,{}),R===`popout`?(0,H.jsx)(C,{label:b(`common.close`),onClick:de,children:(0,H.jsx)(y,{className:`size-5`})}):null]})})}function Te({door:e,wizard:t,page:n,header:r,footer:i}){let{busy:a,error:o,captcha:s,setCaptcha:c,start:l,resume:d}=$(t,`/w/${t.token}/${e}`,n?.translated?n.shown:null),f=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&f.push({key:e,who:`bot`,node:b(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||f.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??b(`run.unavailable`)}),o&&f.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&f.push(E(`start`,(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(O,{primary:!0,busy:a,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[b(`run.start`),` `,(0,H.jsx)(u,{className:`size-4`})]}),d?(0,H.jsx)(O,{onClick:d,children:b(`run.resume`)}):null,t.turnstileSiteKey?(0,H.jsx)(X,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,H.jsxs)(T,{header:r,footer:i,children:[(0,H.jsx)(D,{avatar:t.avatar,costume:t.costume,lines:f}),(0,H.jsx)(k,{})]})}function Ee({className:e}){return(0,H.jsx)(`footer`,{className:h(`text-center text-ink-4`,e),children:(0,H.jsx)(`a`,{href:`${r}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:b(`run.madeWith`).replace(`engenty wizards`,P.name)})})}function De({chat:e=!1,steps:t=!1,talk:n=!1,video:o=!1}){let{token:u,runId:f}=m(),p=g(),v=l({queryKey:[`public`,u,B],queryFn:()=>d.get(`/api/public/wizards/${u}${B}`),retry:(e,t)=>s(t)&&e<3}),y=v.data?.runners??[],x=!v.data||y.some(e=>e.id===`talk`),S=!v.data||y.some(e=>e.id===`video`),C=!v.data||y.some(e=>e.id===`chat`)||n&&x||o&&S,w=y[0]?.id,T=e||R===`popout`||!t&&!f&&C&&(w===`chat`||w===`talk`||w===`video`),E=o&&S||!t&&!e&&!n&&w===`video`,D=!E&&(n&&x||!t&&!e&&w===`talk`),O=E?`video`:D?`talk`:`chat`,k=ge(v.data);_e(f,k),ne(v.data?.brand.theme),re(v.data?.avatar),ve(u,v.data?.title),fe(T);let j=k?.wizard.title??v.data?.title;if((0,L.useEffect)(()=>{j&&(document.title=j)},[j]),(0,L.useEffect)(()=>{u&&f&&ee(`run`,{token:u,runId:f})},[u,f]),v.isLoading)return(0,H.jsx)(`div`,{className:h(`flex items-center justify-center text-ink-4`,Q),children:(0,H.jsx)(a,{})});if(e&&v.data&&!C||n&&v.data&&!x||o&&v.data&&!S)return(0,H.jsx)(i,{to:`/w/${u}`,replace:!0});if(!v.data){let e=s(v.error);return(0,H.jsxs)(`div`,{className:h(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,H.jsx)(M,{kind:`pebble`,size:80}),(0,H.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:b(e?`common.offline`:`run.notFound`)}),e?(0,H.jsx)(c,{variant:`secondary`,onClick:()=>void v.refetch(),children:b(`common.retry`)}):null]})}let N=k?.wizard??v.data,F=k?.translating?(0,H.jsxs)(`div`,{className:h(`flex flex-col items-center justify-center gap-3 text-ink-3`,Q),children:[(0,H.jsx)(a,{}),(0,H.jsx)(`p`,{className:`text-[0.875rem]`,children:b(`translation.working`)})]}):null;if(T){let e=(0,H.jsx)(we,{wizard:N,page:k}),t=_?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(Ee,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,H.jsxs)(`div`,{className:`wizard-page flex h-dvh flex-col`,children:[(0,H.jsx)(A,{effects:v.data.brand.theme.effects}),F??(f?(0,H.jsx)(te,{runId:f,talk:D,call:E?`video`:D?`audio`:!1,onRestart:()=>p(`/w/${u}/${O}`),header:E||D?void 0:e,footer:t}):(0,H.jsx)(Te,{wizard:N,page:k,header:e,footer:t,door:O}))]})}return(0,H.jsxs)(`div`,{className:h(`wizard-page flex flex-col`,Q),children:[(0,H.jsx)(A,{effects:v.data.brand.theme.effects}),R===`inline`||_?null:(0,H.jsx)(Y,{brand:v.data.brand,toggle:!R,start:(0,H.jsx)(G,{page:k})}),R===`inline`||_?(0,H.jsx)(`div`,{className:`flex justify-end px-3 pt-2`,children:(0,H.jsx)(G,{page:k,tone:`surface`})}):null,f&&(k?.translated||k?.failed)?(0,H.jsx)(`div`,{className:`flex justify-center px-5`,children:(0,H.jsx)(K,{page:k})}):null,(0,H.jsx)(`div`,{className:`flex-1`,children:F??(f?(0,H.jsx)(ie,{runId:f,onRestart:()=>p(`/w/${u}`)}):(0,H.jsx)(Se,{wizard:N,page:k}))}),_?(0,H.jsx)(`div`,{className:`safe-bottom`}):(0,H.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,H.jsx)(`a`,{href:`${r}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:b(`run.madeWith`).replace(`engenty wizards`,P.name)})})]})}export{Y as BrandHeader,De as PublicRunner};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{Vr as n,rn as r}from"./ui-LJgQlXbd.js";import{cn as i}from"./index-TJhB4-x8.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return r(e.origin===`local`?`readonly.project`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-amber-tint px-4 py-3 font-medium text-[0.875rem] text-ink leading-relaxed`,children:[(0,s.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-amber`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{Vr as n,rn as r}from"./ui-kIzOrA_W.js";import{cn as i}from"./index-DfHH4icT.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return r(e.origin===`local`?`readonly.project`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-amber-tint px-4 py-3 font-medium text-[0.875rem] text-ink leading-relaxed`,children:[(0,s.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-amber`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};