@engenty/wizards-runtime 0.14.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/agents/studio-assistant.js +50 -3
- package/apps/runtime/dist/app.js +9 -2
- package/apps/runtime/dist/broker/call.js +2 -0
- package/apps/runtime/dist/broker/host.js +1 -0
- package/apps/runtime/dist/broker/rwx.js +38 -4
- package/apps/runtime/dist/db/migrations/tenant/0040_rwx_elements.sql +21 -0
- package/apps/runtime/dist/db/migrations/tenant/0041_broker_log_client.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0040_snapshot.json +5153 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0041_snapshot.json +5160 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +14 -0
- package/apps/runtime/dist/db/schema.js +2 -0
- package/apps/runtime/dist/docs/dev/api.md +24 -2
- package/apps/runtime/dist/docs/dev/architecture.md +13 -2
- package/apps/runtime/dist/elements/caller.js +45 -0
- package/apps/runtime/dist/elements/catalogue.js +14 -0
- package/apps/runtime/dist/elements/connections.js +60 -0
- package/apps/runtime/dist/elements/gate.js +81 -0
- package/apps/runtime/dist/elements/knowledge.js +139 -0
- package/apps/runtime/dist/elements/outside.js +103 -0
- package/apps/runtime/dist/elements/specs.js +102 -0
- package/apps/runtime/dist/elements/wizards.js +59 -0
- package/apps/runtime/dist/env.js +5 -2
- package/apps/runtime/dist/mcp/elements.js +88 -0
- package/apps/runtime/dist/mcp/handler.js +2 -0
- package/apps/runtime/dist/mcp/scopes.js +5 -0
- package/apps/runtime/dist/prompts/authoring.md +2 -2
- package/apps/runtime/dist/prompts/tools.md +3 -0
- package/apps/runtime/dist/routes/api.js +2 -2
- package/apps/runtime/dist/routes/elements.js +76 -0
- package/apps/runtime/dist/services/work-ai.js +27 -19
- package/apps/runtime/dist/services/work-connections.js +2 -2
- package/apps/runtime/dist/tools/index.js +5 -4
- package/apps/runtime/dist/tools/skills.js +80 -54
- package/apps/runtime/dist/tools/space.js +8 -152
- package/apps/web/dist/assets/{AboutDialog-Cag3RJuT.js → AboutDialog-DaWEIHFN.js} +1 -1
- package/apps/web/dist/assets/{CapabilitiesPage-BQYiN0gT.js → CapabilitiesPage-Dt91U_sK.js} +2 -2
- package/apps/web/dist/assets/{ChangelogDialog-D_dQOMIq.js → ChangelogDialog-Do7pwmFv.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-nxoOt8ge.js → CodeEditor-Cdox-51M.js} +1 -1
- package/apps/web/dist/assets/{EditorPage-C4_8LsQN.js → EditorPage-DS_a5K3s.js} +1 -1
- package/apps/web/dist/assets/{FlowPreview-aMfwcPul.js → FlowPreview-BPS86xzA.js} +1 -1
- package/apps/web/dist/assets/{LangSwitch-DpD0inR4.js → LangSwitch-BRHbi_Sd.js} +1 -1
- package/apps/web/dist/assets/{Marketplace-CpzD9pNQ.js → Marketplace-CS7JTgiv.js} +2 -2
- package/apps/web/dist/assets/{NewWizardChannels-CcE3UMVb.js → NewWizardChannels-D-OLsex6.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-BzN7zrQx.js → NewWizardPage-BM_pkk41.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-ztHT01ah.js → OnboardingPage-Cpn5pubC.js} +1 -1
- package/apps/web/dist/assets/{PreviewPane-BabMbBZI.js → PreviewPane-BOk1-yO4.js} +1 -1
- package/apps/web/dist/assets/{PublicRunner-D-JmtqCi.js → PublicRunner-CgzMZb0r.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-GAORKKqV.js → ReadOnly-8DEx-ly3.js} +1 -1
- package/apps/web/dist/assets/{SettingsPage-BKAiYmXl.js → SettingsPage-CcrknFcI.js} +2 -2
- package/apps/web/dist/assets/{SetupPage-C1EZZHIp.js → SetupPage-D5nzjgPU.js} +1 -1
- package/apps/web/dist/assets/{SharePage-N80EhoD7.js → SharePage-PKHX8a8a.js} +1 -1
- package/apps/web/dist/assets/{SkillEditor-CqQMg2MC.js → SkillEditor-BsXTqNli.js} +1 -1
- package/apps/web/dist/assets/{Skills-CnhpgoOA.js → Skills-C_X1ZsKg.js} +1 -1
- package/apps/web/dist/assets/{SpacePage-CRR8JvV1.js → SpacePage-wZGqUoSQ.js} +2 -2
- package/apps/web/dist/assets/{UpdateCheck-CfXZBQNv.js → UpdateCheck-D6x7MqEl.js} +2 -2
- package/apps/web/dist/assets/changelog-M-eOBqgu.js +1 -0
- package/apps/web/dist/assets/{circle-alert-C8Ma-bPY.js → circle-alert-DJbCyxcg.js} +1 -1
- package/apps/web/dist/assets/{circle-check-Bu9Z3mlJ.js → circle-check-jqtsKi_b.js} +1 -1
- package/apps/web/dist/assets/{code-editor-CfTGqOpp.js → code-editor-BpCEnf8H.js} +2 -2
- package/apps/web/dist/assets/{code-xml-B4kLFZSj.js → code-xml-q88cSTV8.js} +1 -1
- package/apps/web/dist/assets/{connection-sign-in-B2D0O8W-.js → connection-sign-in-UJ6xk-TD.js} +1 -1
- package/apps/web/dist/assets/{eye-BpoKpIdt.js → eye-CgkvVlba.js} +1 -1
- package/apps/web/dist/assets/{host-BlKXX7YK.js → host-Bd_bon_c.js} +7 -7
- package/apps/web/dist/assets/{i18n-BJ7Ld6O6.js → i18n-0fUKyVRE.js} +1 -1
- package/apps/web/dist/assets/{index-66tE1oti.js → index-DOgwxnto.js} +3 -3
- package/apps/web/dist/assets/{phone-Ctvf-Am-.js → phone-CjPvZ0nk.js} +1 -1
- package/apps/web/dist/assets/{read-aloud-Da_RSm2S.js → read-aloud-CLXo_asN.js} +1 -1
- package/apps/web/dist/assets/{runners-CyIvJIHr.js → runners-BoPaPsjN.js} +1 -1
- package/apps/web/dist/assets/{scroll-text-ChrjRu9Y.js → scroll-text-2BhJO_W7.js} +1 -1
- package/apps/web/dist/assets/{session-SXPtTWRK.js → session-CpYa5hwd.js} +1 -1
- package/apps/web/dist/assets/{theme-Br1S0j5h.js → theme-Bj3wNQR0.js} +1 -1
- package/apps/web/dist/assets/{ui-Uqnx1UpK.js → ui-CktezodE.js} +1 -1
- package/apps/web/dist/assets/{upload-BchUnQGV.js → upload-CHGCFVZK.js} +1 -1
- package/apps/web/dist/assets/{useMutation-DEkZhp5c.js → useMutation-7_FOHoEl.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CU_oy81Z.js → volume-2-Bw5KASy8.js} +1 -1
- package/apps/web/dist/index.html +13 -13
- package/apps/web/dist/mcp/flow.html +1 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +3 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +6 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +3 -0
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/README.md +3 -0
- package/plugin/plugin.json +1 -1
- package/plugin/skills/work-in-space/SKILL.md +16 -0
- package/apps/web/dist/assets/changelog-6MqC8Vy8.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SkillEditor-
|
|
2
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$n as r,$t as i,A as a,B as o,Bn as s,C as c,D as l,E as u,F as d,Fn as f,G as p,Gn as m,H as h,Hn as g,In as _,Jn as v,Jt as y,Kt as b,L as x,Ln as S,M as C,N as w,O as ee,On as T,P as E,Pn as D,Qt as O,R as k,S as A,Sn as j,T as M,Tn as te,U as ne,V as N,Vn as re,W as P,Wr as ie,Xn as F,Xt as ae,Yt as I,Zt as L,_ as oe,_n as se,_r as ce,an as le,b as R,bn as ue,cn as z,dr as de,f as fe,fr as pe,g as B,gr as me,h as V,in as he,j as H,k as ge,kn as _e,lr as U,m as W,mn as G,nn as ve,on as ye,p as be,pn as K,q,qt as xe,rn as Se,rr as Ce,sn as we,sr as J,tn as Te,un as Ee,v as De,vr as Oe,w as ke,wn as Y,x as Ae,xt as je,y as Me,yr as Ne,z as Pe,zn as Fe}from"./ui-Uqnx1UpK.js";import{_ as Ie,b as Le,v as Re,y as ze}from"./Marketplace-CpzD9pNQ.js";import{t as Be}from"./useMutation-DEkZhp5c.js";import{t as Ve}from"./preload-helper-DpV6A1kQ.js";import{$t as He,Dt as Ue,Et as We,Kt as Ge,Nt as Ke,Qt as qe,Ut as Je,a as Ye,c as Xe,fn as Ze,j as Qe,l as $e,m as et,n as tt,o as nt,p as rt,qt as it,rn as at,s as ot,t as st,u as ct}from"./host-BlKXX7YK.js";import{a as lt,n as ut,s as dt}from"./Skills-CnhpgoOA.js";import{r as ft}from"./volume-2-CU_oy81Z.js";import{F as pt,I as mt,N as ht,S as gt,_ as _t,a as vt,b as yt,c as bt,d as xt,f as St,g as Ct,h as wt,i as Tt,l as Et,m as Dt,o as Ot,p as kt,r as At,s as jt,t as Mt,u as Nt,v as Pt,x as Ft,y as It}from"./PreviewPane-BabMbBZI.js";import{t as Lt}from"./scroll-text-ChrjRu9Y.js";import{t as Rt}from"./eye-BpoKpIdt.js";import{b as zt,f as Bt}from"./theme-Br1S0j5h.js";import{S as Vt,d as Ht,f as Ut,h as Wt,u as Gt}from"./session-SXPtTWRK.js";import{t as Kt}from"./phone-Ctvf-Am-.js";import{n as qt,r as Jt,t as Yt}from"./ReadOnly-GAORKKqV.js";import{t as Xt}from"./upload-BchUnQGV.js";import{gt as Zt,n as Qt,s as X}from"./i18n-BJ7Ld6O6.js";import{a as $t,c as en,f as tn,i as nn,l as rn,m as an,o as on,r as sn,s as cn,u as ln}from"./UpdateCheck-CfXZBQNv.js";import{c as un}from"./index-66tE1oti.js";var dn={name:`at-sign`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`,key:`7n84p3`}]]};dn.node;var fn=J(dn),pn={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};pn.node;var mn=J(pn),hn={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`}]]};hn.node;var gn=J(hn),_n={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`}]]};_n.node;var vn=J(_n),yn={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`}]]};yn.node;var bn=J(yn),xn={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`]};xn.node;var Sn=J(xn),Cn={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`}]]};Cn.node;var wn=J(Cn),Tn={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`}]]};Tn.node;var En=J(Tn),Dn={name:`tablet`,size:24,node:[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,ry:`2`,key:`76otgf`}],[`line`,{x1:`12`,x2:`12.01`,y1:`18`,y2:`18`,key:`1dp563`}]]};Dn.node;var On=J(Dn),kn={name:`text-quote`,size:24,node:[[`path`,{d:`M17 5H3`,key:`1cn7zz`}],[`path`,{d:`M21 12H8`,key:`scolzb`}],[`path`,{d:`M21 19H8`,key:`13qgcb`}],[`path`,{d:`M3 12v7`,key:`1ri8j3`}]]};kn.node;var An=J(kn),Z=e(t(),1),Q=e(n(),1),jn={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function Mn({file:e,actions:t}){let[n,r]=(0,Z.useState)(e.description),i=(0,Z.useRef)(e.description),a=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Z.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,Q.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:X(o?`space.describing`:`space.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function Nn(e,t){confirm(X(`space.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function Pn({spaceId:e,file:t,small:n}){let r=o(e,t.id);if(t.mime.startsWith(`image/`))return(0,Q.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:z(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,Q.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,Q.jsx)(Fn,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,Q.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,Q.jsx)(_e,{className:i}):t.mime===`application/pdf`?(0,Q.jsx)(re,{className:i}):t.mime===`application/json`?(0,Q.jsx)(se,{className:i}):t.mime.startsWith(`model/`)?(0,Q.jsx)(gn,{className:i}):(0,Q.jsx)(Fe,{className:i}),n?null:(0,Q.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function Fn({src:e,small:t}){let[n,r]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,Q.jsx)(`div`,{className:z(`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 In=`application/x-wizards-logo`;function Ln({spaceId: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):Nn(e,r);return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,Q.jsxs)(`div`,{draggable:u&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(In,n.id),className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[n.id===c?(0,Q.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,Q.jsx)(y,{tone:`ember`,children:X(`space.logoMain`)})}):null,(0,Q.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?jn:void 0,children:[s&&n.mime.startsWith(`image/`)?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`space.preview`)}: ${n.name}`,onClick:()=>s(n),className:`block size-full cursor-zoom-in`,children:(0,Q.jsx)(Pn,{spaceId:e,file:n})}):(0,Q.jsx)(Pn,{spaceId:e,file:n}),(0,Q.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,Q.jsx)(L,{label:X(`space.preview`),onClick:()=>s(n),className:`size-8 bg-card shadow-soft`,children:(0,Q.jsx)(Rt,{className:`size-4`})}):null,l&&n.id!==c&&!r.readOnly?(0,Q.jsx)(L,{label:X(`space.logoMakeMain`),onClick:()=>l(n),className:`size-8 bg-card shadow-soft`,children:(0,Q.jsx)(Re,{className:`size-4`})}):null,u&&!r.readOnly?(0,Q.jsx)(oe,{options:u.options,value:u.current(n),onChange:e=>u.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>f(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),t===`asset`?(0,Q.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,Q.jsx)(Mn,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,Q.jsxs)(V,{accept:i,multiple:!1,onFiles:e=>o?o(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,Q.jsx)(Se,{className:`size-5`}):(0,Q.jsx)(Y,{className:`size-5`}),a]}):null]})}function Rn({kind:e,fetchUrl:t,onAdded:n,onClose:a}){let[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)([]),g=async()=>{l(!0),d(null);try{let r=await t(o.trim());r.file?(n([r.file]),a()):r.candidates?.length?(p(r.candidates),h([r.candidates[0].url])):d(X(e===`logo`?`space.logoNoneFound`:`space.assetNoneFound`))}catch(e){d(e.message)}l(!1)},_=async()=>{l(!0),d(null);let e=[];try{for(let n of m){let r=await t(n);r.file&&e.push(r.file)}}catch(e){d(e.message)}l(!1),e.length&&n(e),e.length===m.length&&a()};return(0,Q.jsx)(I,{open:!0,onClose:a,wide:f?!0:void 0,title:X(f?e===`logo`?`space.logoFound`:`space.assetFound`:e===`logo`?`space.logoFromUrl`:`space.assetFromUrl`),children:f?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(e===`logo`?`space.logoFoundHint`:`space.assetFoundHint`)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:f.map(t=>{let n=m.includes(t.url);return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>h(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:z(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:jn,children:[(0,Q.jsx)(`img`,{src:t.url,alt:``,className:z(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,Q.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(r,{className:`size-3.5`})}):null]},t.url)})}),u?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>p(null),children:X(`run.back`)}),(0,Q.jsx)(b,{busy:c,disabled:!m.length,onClick:()=>void _(),children:m.length>1?X(`space.addMany`,{n:m.length}):X(`space.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.logoUrl`)}),(0,Q.jsx)(O,{autoFocus:!0,value:o,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>s(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(e===`logo`?`space.logoUrlHint`:`space.assetUrlHint`)})]}),u?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:a,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,busy:c,disabled:!o.trim(),children:X(`run.next`)})]})]})})}function zn(e,t,n){return Ne({queryKey:[`space-file-text`,t.id,t.chars,n],queryFn:()=>q.get(`/api/studio/spaces/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function Bn(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var Vn=e=>[Bn(e),e.pages?X(`space.pages`,{n:e.pages}):null,Zt(e.size)].filter(Boolean).join(` · `),Hn=2e5;function Un({spaceId:e,fileId:t,readOnly:n,onGone:r}){let i=ie(),a=P(e),s=Dt(e),c=h(e,n),l=a.data?.files.find(e=>e.id===t),u=l?l.mime===`application/pdf`||l.mime.startsWith(`image/`):!1,[d,f]=(0,Z.useState)(null);if(!l)return a.isLoading?(0,Q.jsx)(Se,{className:`mx-auto text-ink-3`}):null;let m=d??(u?`original`:`text`),_=s.data?.items.find(e=>e.key===`f:${l.id}`),v=o(e,l.id),y=(e,t)=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":m===e,onClick:()=>f(e),className:z(`rounded-full px-3 py-1 text-[0.8125rem] transition`,m===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,Q.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Q.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:l.name}),(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:Vn(l)}),(0,Q.jsx)(`a`,{href:v,target:`_blank`,rel:`noreferrer`,"aria-label":X(`space.openOriginal`),title:X(`space.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Q.jsx)(g,{className:`size-4`})}),n?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(L,{label:X(`space.reindex`),onClick:async()=>{await c.reindex(l.id),await i.invalidateQueries({queryKey:p.knowledge(e)})},children:(0,Q.jsx)(j,{className:`size-4`})}),(0,Q.jsx)(L,{label:X(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(X(`data.confirmDelete`,{title:l.name}))&&(await c.remove(l.id),await i.invalidateQueries({queryKey:p.knowledge(e)}),r())},children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),(0,Q.jsx)(St,{spaceId:e,itemKey:`f:${l.id}`,has:_?.categories??[],originLabel:_?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,Q.jsx)(`div`,{className:`px-1`,children:(0,Q.jsx)(Mn,{file:l,actions:c})}),l.status===`failed`?(0,Q.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:l.error}):null,(0,Q.jsxs)(xe,{className:`flex flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[u?y(`original`,X(`space.original`)):null,y(`text`,X(`space.readText`))]}),m===`original`?l.mime===`application/pdf`?(0,Q.jsx)(`iframe`,{src:v,title:l.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,Q.jsx)(`img`,{src:v,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,Q.jsx)(Wn,{spaceId:e,file:l})]})]})}function Wn({spaceId:e,file:t}){let n=zn(e,t,Hn);return n.isLoading||t.status===`pending`?(0,Q.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,Q.jsx)(Se,{})}):n.data?.text?(0,Q.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,Q.jsx)(je,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:X(`space.textCut`,{shown:n.data.text.length.toLocaleString(Qt),total:n.data.chars.toLocaleString(Qt)})}):null]}):(0,Q.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:X(`space.noText`)})}var Gn=[{value:`de-du`,label:`page.lang.deDu`},{value:`de-sie`,label:`page.lang.deSie`},{value:`en`,label:`page.lang.en`}],$=`text-[0.8125rem] text-ink-3 leading-snug`,Kn=`font-mono text-[0.875rem]`,qn=e=>e.slice(e.indexOf(`.`)+1);function Jn(){let[e,t]=(0,Z.useState)(!1),n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),{copied:e,copy:e=>navigator.clipboard.writeText(e).then(()=>{t(!0),clearTimeout(n.current),n.current=setTimeout(()=>t(!1),1500)}).catch(()=>t(!1))}}function Yn(){let e=X(`page.sources`).split(/(\{brand\}|\{facts\})/);return(0,Q.jsxs)(`p`,{className:$,children:[e.map((e,t)=>e===`{brand}`?(0,Q.jsx)(U,{to:`/space/brand`,className:`text-ink underline-offset-2 hover:underline`,children:X(`space.brand`)},t):e===`{facts}`?(0,Q.jsx)(U,{to:`/space/info#facts`,className:`text-ink underline-offset-2 hover:underline`,children:X(`space.facts`)},t):e),` `,X(`page.onlyShared`)]})}function Xn({host:e,value:t,onChange:n,disabled:r}){let i=a.test(t);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex h-11 items-stretch overflow-hidden rounded-lg border border-input bg-card focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,children:[(0,Q.jsxs)(`span`,{title:`${e}/`,className:`flex max-w-[55%] items-center truncate bg-paper-2 px-3 font-mono text-[0.75rem] text-ink-3`,children:[`…`,qn(e),`/`]}),(0,Q.jsx)(`input`,{value:t,disabled:r,"aria-label":X(`page.address`),maxLength:ge.slug,onChange:e=>n(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,`-`)),className:z(`min-w-0 flex-1 bg-transparent px-3 outline-none`,Kn)})]}),(0,Q.jsx)(`p`,{className:z(`mt-1.5`,$,!i&&t&&`text-rose`),children:X(`page.addressRules`)})]})}function Zn({host:e,words:t,onChange:n,disabled:r}){return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-5 sm:grid-cols-[repeat(2,minmax(0,1fr))]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(i,{children:X(`page.title`)}),(0,Q.jsx)(O,{value:t.title,disabled:r,maxLength:ge.title,onChange:e=>n({title:e.target.value})}),(0,Q.jsx)(`p`,{className:z(`mt-1.5`,$),children:X(`page.titleHint`)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(i,{children:X(`page.address`)}),(0,Q.jsx)(Xn,{host:e,value:t.slug,disabled:r,onChange:e=>n({slug:e})}),(0,Q.jsx)(`p`,{className:z(`mt-1`,$),children:X(`page.addressChange`)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 sm:col-span-2`,children:[(0,Q.jsx)(i,{children:X(`page.headline`)}),(0,Q.jsx)(O,{value:t.headline??``,disabled:r,maxLength:ge.headline,onChange:e=>n({headline:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 sm:col-span-2`,children:[(0,Q.jsx)(i,{children:X(`page.words`)}),(0,Q.jsx)(we,{value:t.intro??``,disabled:r,minRows:3,maxLength:ge.intro,onChange:e=>n({intro:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(i,{children:X(`page.lang`)}),(0,Q.jsx)(ve,{value:t.voice,onChange:e=>n({voice:e}),options:Gn.map(e=>({value:e.value,label:X(e.label)}))}),(0,Q.jsx)(`p`,{className:z(`mt-1.5`,$),children:X(`page.langHint`)})]})]})}function Qn(e,t){if(!e.published)return X(`page.draftNote`);if(!e.shareEnabled)return X(`page.notSharedNote`);let n=e.description.trim();return t?[n,X(`page.first`)].filter(Boolean).join(` · `):n}function $n({wizard:e,first:t,on:n,disabled:r,onToggle:i,drag:a}){return(0,Q.jsxs)(`li`,{draggable:a?!0:void 0,onDragStart:a?.onDragStart,onDragOver:a?.onDragOver,onDrop:a?.onDrop,className:z(`flex items-center gap-3 border-border-soft border-t py-2.5 first:border-t-0`,!e.published&&`opacity-60`),children:[a?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`page.moveUp`)} / ${X(`page.moveDown`)}`,onKeyDown:a.onKeyDown,className:`grid size-7 shrink-0 cursor-grab place-items-center rounded-md text-ink-4 hover:text-ink focus:text-ink`,children:(0,Q.jsx)(S,{className:`size-4`})}):(0,Q.jsx)(`span`,{className:`size-7 shrink-0`}),(0,Q.jsx)(Vt,{kind:e.avatar,costume:e.costume,size:36,interactive:!1}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium text-[0.9375rem]`,children:e.title}),(0,Q.jsx)(`p`,{className:z(`truncate`,$),children:Qn(e,t)})]}),(0,Q.jsx)(le,{checked:n,disabled:r||!e.published,label:X(`page.showOnPage`),onChange:i})]})}function er({title:e,text:t,picked:n,disabled:r,later:i,onPick:a}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":n,disabled:r||i,onClick:a,className:z(`flex min-h-20 flex-col items-start gap-1 rounded-xl px-4 py-3 text-left transition`,n?`bg-accent ring-2 ring-primary`:i?`border border-border border-dashed opacity-60`:`ring-1 ring-border-soft hover:bg-paper-2`,(r||i)&&`cursor-not-allowed`),children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e}),(0,Q.jsx)(`span`,{className:$,children:t})]})}var tr={desktop:1280,tablet:768,mobile:390},nr=`wizards.pagePreviewDevice`,rr=`wizards.pagePreviewHeight`,ir=360,ar=e=>e?640:480,or=()=>Math.max(ir,window.innerHeight-140);function sr(){try{let e=Number(localStorage.getItem(rr));return e>=ir?e:null}catch{return null}}function cr(e){try{e===null?localStorage.removeItem(rr):localStorage.setItem(rr,String(Math.round(e)))}catch{}}function lr(){try{let e=localStorage.getItem(nr);return e&&e in tr?e:`desktop`}catch{return`desktop`}}function ur(e){try{localStorage.setItem(nr,e)}catch{}}function dr({url:e,version:t,device:n}){let r=(0,Z.useRef)(null),[i,a]=(0,Z.useState)({width:0,tall:!0});(0,Z.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>a({width:e.clientWidth,tall:e.clientWidth>=640});t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let o=tr[n],[s,c]=(0,Z.useState)(sr),[l,u]=(0,Z.useState)(!1),d=(0,Z.useRef)(null),f=Math.min(s??ar(i.tall),i.width?or():9999),p=e=>{let t=Math.round(Math.min(or(),Math.max(ir,e)));return c(t),t},m=n===`mobile`,h=m?12:0,g=i.width?Math.min(1,(i.width-2*h)/o):1,_=(0,Q.jsxs)(`div`,{className:z(`relative overflow-hidden bg-paper-2`,m?`rounded-[1.5rem]`:`rounded-lg ring-1 ring-border-soft`),style:{width:Math.round(o*g),height:f},children:[i.width?(0,Q.jsx)(`iframe`,{title:X(`page.previewTitle`),src:`${e}${e.includes(`?`)?`&`:`?`}v=${t}`,tabIndex:-1,className:z(`absolute top-0 left-0 border-0`,l&&`pointer-events-none`),style:{width:o,height:Math.ceil(f/g),transform:`scale(${g})`,transformOrigin:`top left`}},t):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":X(`page.resize`),title:X(`page.resize`),onPointerDown:e=>{e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}d.current={y:e.clientY,height:f},u(!0)},onPointerMove:e=>{d.current&&p(d.current.height+e.clientY-d.current.y)},onPointerUp:e=>{d.current&&=(cr(p(d.current.height+e.clientY-d.current.y)),null),u(!1)},onPointerCancel:()=>{d.current=null,u(!1)},onDoubleClick:()=>{c(null),cr(null)},onKeyDown:e=>{(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),cr(p(f+(e.key===`ArrowDown`?24:-24))))},className:`absolute right-1 bottom-1 z-10 grid size-7 cursor-ns-resize touch-none place-items-center rounded-md bg-card/90 text-ink-3 shadow-soft ring-1 ring-border-soft hover:text-ink coarse:size-9`,children:(0,Q.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 12 12`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`M11 1 1 11M11 5 5 11M11 9 9 11`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})})})]});return(0,Q.jsx)(`div`,{ref:r,className:`flex w-full justify-center`,children:m?(0,Q.jsx)(`div`,{className:`rounded-[2.25rem] bg-ink p-3 shadow-soft`,children:_}):_})}function fr({host:e,page:t,disabled:n,save:r,onState:i}){let o=(0,Z.useRef)(t);o.current=t;let[s,c]=(0,Z.useState)(()=>({slug:t.slug,title:t.title,headline:t.headline??``,intro:t.intro??``,voice:gt(t)})),l=N(s,async e=>{if(!(a.test(e.slug)&&e.title.trim()))return;let{lang:t,form:n}=It(e.voice);await r({...o.current,slug:e.slug,title:e.title.trim(),headline:e.headline?.trim()||void 0,intro:e.intro?.trim()||void 0,lang:t,form:n})}),{state:u,error:d}=l;return(0,Z.useEffect)(()=>i(l),[u,d]),(0,Q.jsx)(Zn,{host:e,words:s,disabled:n,onChange:e=>c(t=>({...t,...e}))})}function pr({space:e}){let t=ie(),n=Wt(),i=n.data?.tenant.pagesHost??null,a=n.data?.manageUrl??null,o=e.readOnly,s=e.page,c=!!s?.on,l=Ne({queryKey:p.spaceWizards(e.id),queryFn:()=>q.get(`/api/studio/spaces/${e.id}/wizards`)}),[u,d]=(0,Z.useState)(1),[f,m]=(0,Z.useState)(lr),h=(0,Z.useRef)(s);h.current=s;let g=async n=>{await q.patch(`/api/studio/spaces/${e.id}`,{page:n}),await t.invalidateQueries({queryKey:p.spaces()}),d(e=>e+1)},_=Be({mutationFn:e=>{let t=h.current;return t?g({...t,...e}):Promise.resolve()}}),[y,x]=(0,Z.useState)({state:`idle`,error:null}),{copied:S,copy:C}=Jn(),w=l.data??[],ee=(s?.wizards??[]).map(e=>w.find(t=>t.id===e)).filter(e=>e!==void 0),T=w.filter(e=>!s?.wizards.includes(e.id)),[E,D]=(0,Z.useState)(null),O=(e,t)=>{let n=[...s?.wizards??[]];if(t<0||t>=n.length||e===t)return;let[r]=n.splice(e,1);n.splice(t,0,r),_.mutate({wizards:n})},A=(e,t)=>_.mutate({wizards:t?[...s?.wizards??[],e]:(s?.wizards??[]).filter(t=>t!==e)}),j=e.brand.name?.trim()||e.name,M=Be({mutationFn:()=>g({on:!0,slug:k(j)||`page`,title:j,...It(Qt===`de`?`de-du`:`en`),wizards:w.filter(e=>e.published&&e.shareEnabled).map(e=>e.id),examples:{}})}),te=e=>{s?_.mutate({on:e}):e&&M.mutate()},ne=_.isPending||M.isPending,N=_.error??M.error;if(!i)return(0,Q.jsx)(W,{id:`page`,children:(0,Q.jsx)(R,{title:X(`space.page`),hint:X(`page.intro`),children:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:X(`page.cloudOnly`)})})});let re=s?.slug||k(j)||`…`,P=yt(i,re),F=Ft(i,re,a),ae=(0,Q.jsxs)(`span`,{className:z(Kn,`min-w-0 truncate`),children:[(0,Q.jsxs)(`span`,{className:`text-ink-3`,children:[i,`/`]}),(0,Q.jsx)(`b`,{className:`text-ink`,children:re})]}),I=o||!s,L=(0,Q.jsxs)(xe,{className:`flex flex-col gap-2.5 p-4`,children:[(0,Q.jsxs)(`div`,{className:`@container flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:X(`page.previewTitle`)}),c?(0,Q.jsx)(Mt,{named:!0,label:X(`editor.device`),value:f,onChange:e=>{m(e),ur(e)},options:[{id:`desktop`,label:X(`editor.deviceDesk`),icon:(0,Q.jsx)(it,{className:`size-3.5`})},{id:`tablet`,label:X(`page.deviceTablet`),icon:(0,Q.jsx)(On,{className:`size-3.5`})},{id:`mobile`,label:X(`editor.devicePhone`),icon:(0,Q.jsx)(zt,{className:`size-3.5`})}]}):null]}),c?(0,Q.jsx)(dr,{url:F,version:u,device:f}):(0,Q.jsx)(`p`,{className:$,children:X(`page.previewOff`)}),c?(0,Q.jsx)(`p`,{className:$,children:X(`page.previewHint`)}):null]}),oe=(0,Q.jsxs)(xe,{className:`flex flex-col gap-3 p-4`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:X(`page.inShare`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-paper-2 px-3 py-2.5`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium text-[0.875rem]`,children:X(`share.onPage`,{space:s?.title||j})}),(0,Q.jsx)(`span`,{className:z(`block truncate font-mono`,$),children:P})]}),(0,Q.jsx)(le,{checked:!0,disabled:!0,label:X(`page.showOnPage`),onChange:()=>{}})]}),(0,Q.jsx)(`p`,{className:$,children:X(`page.inShareHint`)})]});return(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-9`,children:[(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(W,{id:`page`,children:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`px-1`,children:[(0,Q.jsx)(`h2`,{className:`font-display font-semibold text-lg leading-tight`,children:X(`space.page`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-3 leading-snug`,children:X(`page.intro`)})]}),(0,Q.jsxs)(xe,{className:`flex flex-wrap items-center gap-3 p-3 sm:pl-4`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:z(`size-2 shrink-0 rounded-full`,c?`bg-moss`:`bg-ink-4`),"aria-hidden":!0}),ae]}),(0,Q.jsxs)(`span`,{className:`flex w-full items-center gap-2 sm:w-auto sm:shrink-0`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,className:`max-sm:flex-1`,disabled:!c,onClick:()=>C(F),children:[S?(0,Q.jsx)(r,{className:`size-3.5`}):(0,Q.jsx)(v,{className:`size-3.5`}),X(S?`share.copied`:`share.copyMain`)]}),(0,Q.jsxs)(b,{size:`sm`,className:`max-sm:flex-1`,disabled:!c,onClick:()=>window.open(F,`_blank`,`noopener`),children:[X(`page.open`),` `,(0,Q.jsx)(Ze,{className:`size-3.5`})]})]})]}),(0,Q.jsxs)(R,{title:X(`page.sectionPage`),locked:o,children:[(0,Q.jsxs)(`fieldset`,{"aria-label":X(`page.sectionPage`),className:`grid min-w-0 gap-3 sm:grid-cols-[repeat(3,minmax(0,1fr))]`,children:[(0,Q.jsx)(er,{title:X(`page.whoOff`),text:X(`page.whoOffHint`),picked:!c,disabled:o||ne,onPick:()=>te(!1)}),(0,Q.jsx)(er,{title:X(`page.whoPublic`),text:X(`page.whoPublicHint`),picked:c,disabled:o||ne,onPick:()=>te(!0)}),(0,Q.jsx)(er,{title:X(`page.whoMembers`),text:X(`page.whoMembersHint`),picked:!1,later:!0,onPick:()=>{}})]}),N?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:N.message}):null]})]})}),L,(0,Q.jsx)(W,{id:`page-words`,children:(0,Q.jsx)(R,{title:X(`page.sectionWords`),hint:s?void 0:X(`page.notYet`),save:s?y:void 0,locked:I,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[s?(0,Q.jsx)(fr,{host:i,page:s,disabled:o,save:g,onState:x},`${e.id}:${s.slug}`):(0,Q.jsx)(Zn,{host:i,disabled:!0,words:{slug:re,title:j,headline:``,intro:``,voice:Qt===`de`?`de-du`:`en`},onChange:()=>{}}),(0,Q.jsxs)(`div`,{id:`page-wizards`,className:`scroll-mt-6 border-border-soft border-t pt-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:X(`page.sectionWizards`)}),(0,Q.jsx)(`span`,{className:$,children:X(`page.wizardsHint`)})]}),(0,Q.jsxs)(`ul`,{className:`mt-2 flex flex-col`,children:[ee.map((e,t)=>(0,Q.jsx)($n,{wizard:e,first:t===0,on:!0,disabled:I,onToggle:t=>A(e.id,t),drag:{onDragStart:()=>D(t),onDragOver:e=>e.preventDefault(),onDrop:()=>{E!==null&&O(E,t),D(null)},onKeyDown:e=>{(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),O(t,e.key===`ArrowUp`?t-1:t+1))}}},e.id)),T.map(e=>(0,Q.jsx)($n,{wizard:e,first:!1,on:!1,disabled:I,onToggle:t=>A(e.id,t)},e.id))]}),w.length?null:(0,Q.jsx)(`p`,{className:z(`mt-2`,$),children:X(`page.noWizards`)}),(0,Q.jsx)(`p`,{className:z(`mt-4`,$),children:X(`page.wizardsNote`)})]}),(0,Q.jsx)(Yn,{})]})})})]}),oe]})}var mr=`results-search`,hr={q:``,mode:``,days:0};function gr(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 Ne({queryKey:[`results`,e,i],queryFn:()=>q.get(`/api/studio/spaces/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function _r({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Z.useState)(r.q);return Ue({icon:ue,label:X(`space.resultsSearch`),run:()=>{let e=document.getElementById(mr);e?.scrollIntoView({block:`center`,behavior:`smooth`}),e?.focus()}}),(0,Z.useEffect)(()=>{if(a===r.q)return;let e=setTimeout(()=>i({...r,q:a}),250);return()=>clearTimeout(e)},[a,r,i]),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(ve,{value:t??``,onChange:e=>n(e||null),options:[{value:``,label:X(`space.resultsAllWizards`)},...e.wizards.filter(e=>e.results||e.id===t).map(e=>({value:e.id,label:`${e.title} (${e.results})`}))],className:`w-56 max-sm:w-full`}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,Q.jsx)(ue,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,Q.jsx)(O,{type:`search`,value:a,onChange:e=>o(e.target.value),id:mr,placeholder:X(`space.resultsSearch`),"aria-label":X(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,Q.jsx)(ve,{value:r.mode,onChange:e=>i({...r,mode:e}),options:[{value:``,label:X(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,Q.jsx)(ve,{value:String(r.days),onChange:e=>i({...r,days:Number(e)}),options:[{value:`0`,label:X(`space.resultsAnyTime`)},{value:`1`,label:X(`space.resultsDay`)},{value:`7`,label:X(`space.resultsDays`,{n:7})},{value:`30`,label:X(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function vr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Z.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(Qt,{dateStyle:`medium`,timeStyle:`short`});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(R,{title:t?s(t):X(`space.resultsAll`),hint:X(`space.resultsHint`),plain:!0,children:[(0,Q.jsx)(_r,{data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}),e.runs.length?(0,Q.jsx)(xe,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,Q.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,X(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:X(`space.resultFiles`,{n:e.assets}),children:[(0,Q.jsx)(T,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,Q.jsx)(y,{children:X(`run.testChip`)}):(0,Q.jsxs)(y,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,Q.jsx)(xe,{children:(0,Q.jsx)(ae,{children:r.q.trim()||r.mode||r.days?X(`space.resultsNone`):X(`space.resultsEmpty`)})})]}),a?(0,Q.jsx)(At,{header:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(a.wizardId)}),a.mode===`test`?(0,Q.jsx)(y,{children:X(`run.testChip`)}):(0,Q.jsxs)(y,{tone:`live`,children:[`Live v`,a.version]})]}),onClose:()=>o(null),children:(0,Q.jsx)(Bt,{runId:a.id,compact:!0,studio:!0},a.id)}):null]})}var yr={info:`space.teaser.info`,brand:`space.teaser.brand`,knowledge:`space.teaser.knowledge`,data:`space.teaser.data`,page:`space.teaser.page`};function br({space:e,parts:t}){let n=ce(),r=P(e.id),i=Dt(e.id),a=bt(e.id);We({title:X(`space.overviewAssistantTitle`),hello:X(`space.overviewAssistantHello`),suggestions:[{label:X(`assistant.suggest.missing`)},{label:X(`assistant.suggest.readSite`),fill:!0}]});let o=r.data?.files.filter(e=>e.kind===`logo`)??[],c=o.length,l=e.brand.colors?.length??0,u=i.data?.items.length??0,d=i.data?.categories.length??0,f=a.data?.tables.length??0,p=a.data?.pages.length??0,m=t=>{let n=(...e)=>e.filter(Boolean).join(` · `);switch(t){case`info`:{let t=!!e.brand.name?.trim();return{text:n(!t&&X(`space.status.noTitle`),e.facts.length>0&&X(`space.status.facts`,{n:e.facts.length}))||X(`space.status.empty`),filled:t}}case`brand`:return r.isPending?null:{text:n(c>0&&X(`space.status.logos`,{n:c}),l>0&&X(`space.status.colors`,{n:l}))||X(`space.status.empty`),filled:c+l>0};case`knowledge`:return i.isPending?null:{text:n(u>0&&X(`space.status.entries`,{n:u}),d>0&&X(`space.status.categories`,{n:d}))||X(`space.status.empty`),filled:u>0};case`data`:return a.isPending?null:{text:n(f>0&&X(`space.status.tables`,{n:f}),p>0&&X(`space.pages`,{n:p}))||X(`space.status.empty`),filled:f+p>0};default:return null}},h=t=>{let n=`flex min-w-0 items-center gap-2 text-[0.8125rem] text-ink-2`;switch(t){case`info`:return e.brand.name?.trim()||e.facts.length?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.brand.name?.trim()?(0,Q.jsx)(`span`,{className:`truncate font-medium text-[0.875rem] text-ink`,children:e.brand.name}):null,e.facts.slice(0,3).map(e=>(0,Q.jsxs)(`span`,{className:n,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-ink-3`,children:e.label}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e.value})]},e.key))]}):null;case`brand`:return c+l||e.brand.tagline?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.brand.brandName||e.brand.tagline?(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,Q.jsx)(`span`,{className:`truncate font-medium text-[0.875rem] text-ink`,children:e.brand.brandName||e.brand.name}),e.brand.tagline?(0,Q.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-3 italic`,children:e.brand.tagline}):null]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[o.slice(0,3).map(t=>(0,Q.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center overflow-hidden rounded-lg bg-paper ring-1 ring-border-soft`,children:(0,Q.jsx)(Pn,{spaceId:e.id,file:t,small:!0})},t.id)),(0,Q.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:(e.brand.colors??[]).slice(0,8).map(e=>(0,Q.jsx)(`span`,{title:`${e.name} ${e.value}`,className:`size-5 rounded-full ring-1 ring-border-soft`,style:{background:e.value}},`${e.name}${e.value}`))})]})]}):null;case`knowledge`:return u?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[i.data?.items.slice(0,3).map(e=>{let t=e.kind===`page`?re:e.kind===`table`?G:s;return(0,Q.jsxs)(`span`,{className:n,children:[(0,Q.jsx)(t,{className:`size-3.5 shrink-0 text-ink-3`}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title})]},e.key)}),d?(0,Q.jsx)(`span`,{className:`mt-1 flex flex-wrap gap-1`,children:i.data?.categories.slice(0,4).map(e=>(0,Q.jsx)(`span`,{className:`rounded-full bg-paper-2 px-2 py-0.5 text-[0.75rem] text-ink-3`,children:e.name},e.id))}):null]}):null;case`data`:return f+p?(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:[...(a.data?.tables??[]).map(e=>({key:`t:${e.id}`,title:e.title,rows:e.rows,Icon:G})),...(a.data?.pages??[]).map(e=>({key:`p:${e.id}`,title:e.title,rows:null,Icon:re}))].slice(0,3).map(e=>(0,Q.jsxs)(`span`,{className:n,children:[(0,Q.jsx)(e.Icon,{className:`size-3.5 shrink-0 text-ink-3`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title}),e.rows===null?null:(0,Q.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:e.rows})]},e.key))}):null;default:return null}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[(0,Q.jsx)(Qe,{}),(0,Q.jsx)(R,{title:X(`nav.sources`),hint:X(`space.overviewHint`),plain:!0,children:(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:t.map(e=>{let t=m(e.id),r=yr[e.id];return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e.to),className:`group flex min-w-0 flex-col gap-2 rounded-xl bg-card p-4 text-left shadow-soft ring-1 ring-border-soft transition hover:ring-border`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`grid size-8 shrink-0 place-items-center rounded-lg bg-paper-2 text-ember-strong`,children:(0,Q.jsx)(e.icon,{className:`size-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold text-[0.9375rem]`,children:e.label}),(0,Q.jsx)(F,{className:`size-4 text-ink-4 transition group-hover:translate-x-0.5 group-hover:text-ink-3`})]}),r?(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 leading-relaxed`,children:X(r)}):null,h(e.id)?(0,Q.jsx)(`span`,{className:`block rounded-lg bg-paper-2/50 p-3`,children:h(e.id)}):null,t?(0,Q.jsx)(`span`,{className:`mt-auto pt-1`,children:(0,Q.jsx)(y,{tone:t.filled?`live`:`warn`,children:t.text})}):null]},e.id)})})})]})}var xr=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,Sr=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),Zt(e.size)].filter(Boolean).join(` · `);function Cr({spaceId:e,file:t,actions:n,onClose:r}){let i=o(e,t.id);return(0,Q.jsxs)(I,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,Q.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:Sr(t)}),(0,Q.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":X(`space.openOriginal`),title:X(`space.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Q.jsx)(g,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,Q.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:jn,children:(0,Q.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,Q.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,Q.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(Mn,{file:t,actions:n})})]})}function wr({spaceId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,Q.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`space.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,Q.jsx)(Pn,{spaceId:e,file:t,small:!0})}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:Sr(t)})]}),(0,Q.jsx)(Mn,{file:t,actions:n})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,Q.jsx)(L,{label:X(`space.preview`),onClick:i,children:(0,Q.jsx)(Rt,{className:`size-4`})}),r&&!n.readOnly?(0,Q.jsx)(oe,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:a,className:`hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]})]})}function Tr({section:e,onSave:t,onRemove:n,onClose:r}){let[a,o]=(0,Z.useState)(e?.title??``);return(0,Q.jsx)(I,{open:!0,onClose:r,title:X(e?`space.assetSectionRename`:`space.assetSectionAdd`),children:(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a.trim()&&(t(a.trim()),r())},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.assetSectionName`)}),(0,Q.jsx)(O,{autoFocus:!0,value:a,maxLength:80,placeholder:X(`space.assetSectionTitle`),onChange:e=>o(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,Q.jsx)(b,{variant:`danger`,onClick:n,children:X(`space.sectionRemove`)}):null,(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsx)(b,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,disabled:!a.trim(),children:X(e?`settings.save`:`space.add`)})]})]})})}function Er({spaceId:e,data:t,readOnly:n,sections:r,save:i}){let a=h(e,n),[o,s]=ne(`assets`,`cards`),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(r),[m,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),x=(0,Z.useRef)(null),S=N({assetSections:f},i),C=t.files.filter(e=>e.kind===`asset`),w=new Map(C.map(e=>[e.id,e])),ee=new Set(f.flatMap(e=>e.assets)),T=f.find(e=>e.id===m)??null,E=T?T.assets.map(e=>w.get(e)).filter(e=>!!e):C.filter(e=>!ee.has(e.id)),D=C.find(e=>e.id===u),O=c.trim().toLowerCase(),k=O?E.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(O)):E,j=(e,t)=>p(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),M=async e=>{let t=T?.id??null;for(let n of await a.upload(`asset`,e))j(n.id,t)},re=e=>{confirm(X(`space.removeConfirm`,{name:e.name}))&&(a.remove(e.id),j(e.id,null))},P=f.length?{options:[{value:``,label:X(`space.assetsGeneral`)},...f.map(e=>({value:e.id,label:e.title||X(`space.sectionUntitled`)}))],current:e=>f.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>j(e.id,t||null)}:void 0,ie=[{label:X(`space.assetUpload`),icon:(0,Q.jsx)(Xt,{className:`size-4 shrink-0`}),onPick:()=>x.current?.click()},{label:X(`space.assetFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>b(!0)},...f.length<H.logoSections?[{label:X(`space.assetSectionAdd`),icon:(0,Q.jsx)(bn,{className:`size-4 shrink-0`}),onPick:()=>v(`new`)}]:[]],F=f.length||C.length?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[f.length?(0,Q.jsx)(ye,{value:m,onChange:e=>{g(e),l(``)},label:X(`space.assets`),options:[{id:``,label:X(`space.assetsGeneral`)},...f.map(e=>({id:e.id,label:e.title||X(`space.sectionUntitled`)}))]}):null,T&&!n?(0,Q.jsx)(L,{label:X(`space.assetSectionRename`),onClick:()=>v(`current`),children:(0,Q.jsx)(te,{className:`size-4`})}):null]}),E.length?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,Q.jsx)(Me,{value:c,onChange:l,placeholder:X(`space.assetSearch`)})}),(0,Q.jsx)(L,{label:X(o===`list`?`space.viewCards`:`space.viewList`),onClick:s,children:o===`list`?(0,Q.jsx)(qe,{className:`size-4`}):(0,Q.jsx)(En,{className:`size-4`})})]}):null]}):null;return(0,Q.jsxs)(R,{title:X(`space.assets`),hint:X(`space.assetsHint`),save:S,tabs:F,action:n?null:(0,Q.jsx)(fe,{entries:ie}),children:[(0,Q.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:xr,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&M(t)}}),k.length?o===`cards`?(0,Q.jsx)(Ln,{spaceId:e,kind:`asset`,files:k,actions:a,moveTo:P,onRemove:re,onPreview:e=>d(e.id)}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:k.map(t=>(0,Q.jsx)(wr,{spaceId:e,file:t,actions:a,moveTo:P,onPreview:()=>d(t.id),onRemove:()=>re(t)},t.id))}):E.length?null:n?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`space.staysLocal`)}):(0,Q.jsxs)(V,{accept:xr,onFiles:e=>void M(e),className:`h-16 w-full`,children:[a.busy?(0,Q.jsx)(Se,{className:`size-4`}):(0,Q.jsx)(Xt,{className:`size-4`}),X(`space.drop`),` `,(0,Q.jsx)(`span`,{className:`underline`,children:X(`space.assetAdd`)})]}),a.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error}):null,D?(0,Q.jsx)(Cr,{spaceId:e,file:D,actions:a,onClose:()=>d(null)}):null,_?(0,Q.jsx)(Tr,{section:_===`current`?T:null,onClose:()=>v(null),onSave:e=>{if(_===`current`&&T)p(t=>t.map(t=>t.id===T.id?{...t,title:e}:t));else{let t=A();p(n=>[...n,{id:t,title:e,assets:[]}]),g(t)}},onRemove:_===`current`&&T?()=>{(!T.assets.length||confirm(X(`space.assetSectionRemoveConfirm`,{name:T.title})))&&(p(e=>e.filter(e=>e.id!==T.id)),g(``),v(null))}:void 0}):null,y?(0,Q.jsx)(Rn,{kind:`asset`,onClose:()=>b(!1),fetchUrl:e=>a.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)j(t.id,T?.id??null)}}):null]})}var Dr=/^#[0-9a-fA-F]{6}$/;async function Or(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 kr={linear:`space.gradientLinear`,radial:`space.gradientRadial`,conic:`space.gradientConic`};function Ar({spaceId:e,gradient:t,isNew:n,brand:r,onSave:a,onClose:o}){let[s,c]=(0,Z.useState)(t),[l,u]=(0,Z.useState)(d(t)),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(!n),C=e=>{c(e),u(d(e)),p(!1)},w=(e,t)=>C({...s,stops:s.stops.map((n,r)=>r===e?{...n,...t}:n)}),T=e=>{let t=[...s.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));C({...s,stops:[...s.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},E=async()=>{_(!0),y(null);try{let{gradient:t}=await q.post(`/api/studio/spaces/${e}/gradients/describe`,{text:m.trim(),...x?{gradient:{name:s.name,type:s.type,angle:s.angle,stops:s.stops}}:{}});C({...s,...t,name:s.name.trim()?s.name:t.name}),h(``),S(!0)}catch(e){y(e.message)}_(!1)};return(0,Q.jsx)(I,{open:!0,onClose:o,wide:!0,title:X(n?`space.gradientNew`:`space.gradientEdit`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m.trim()&&!g&&E()},children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(O,{"data-autofocus":n||void 0,value:m,maxLength:1e3,"aria-label":X(`space.gradientDescribe`),placeholder:X(x?`space.gradientDescribeChange`:`space.gradientDescribeNew`),onChange:e=>h(e.target.value),className:`min-w-0 flex-1`}),(0,Q.jsxs)(b,{type:`submit`,variant:`secondary`,busy:g,disabled:!m.trim(),children:[(0,Q.jsx)(se,{className:`size-4`}),X(x?`space.gradientDescribeApply`:`space.gradientDescribeMake`)]})]}),(0,Q.jsx)(`p`,{className:z(`mt-1.5 text-[0.8125rem]`,v?`text-rose`:`text-ink-3`),children:v??X(`space.gradientDescribeHint`)})]}),(0,Q.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:d(s)}}),(0,Q.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.gradientName`)}),(0,Q.jsx)(O,{value:s.name,maxLength:80,placeholder:X(`space.gradientNamePlaceholder`),onChange:e=>c({...s,name:e.target.value})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.fillUseLabel`)}),(0,Q.jsx)(O,{value:s.description??``,maxLength:400,placeholder:X(`space.gradientUse`),onChange:e=>c({...s,description:e.target.value})})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.gradientType`)}),(0,Q.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:ee.map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":s.type===e,onClick:()=>C({...s,type:e}),className:z(`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:X(kr[e])},e))})]}),s.type===`radial`?null:(0,Q.jsxs)(`div`,{className:`min-w-56`,children:[(0,Q.jsx)(i,{children:X(`space.gradientAngle`)}),(0,Q.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Q.jsx)(`input`,{type:`range`,min:0,max:360,value:s.angle,"aria-label":X(`space.gradientAngle`),onChange:e=>C({...s,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,Q.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(s.angle),`°`]})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.gradientStops`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:s.stops.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(he,{value:Dr.test(e.color)?e.color:`#888888`,onChange:e=>w(t,{color:e.target.value})}),(0,Q.jsx)(O,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();Dr.test(n)&&w(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,Q.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":X(`space.gradientAt`),onChange:e=>w(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,Q.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,Q.jsx)(L,{label:X(`space.remove`),disabled:s.stops.length<=2,onClick:()=>C({...s,stops:s.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]},t))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[s.stops.length<12?(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>T(),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.gradientStopAdd`)]}):null,r.length&&s.stops.length<12?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:X(`space.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,Q.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>T(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:`CSS`}),(0,Q.jsx)(O,{value:l,spellCheck:!1,onChange:e=>{u(e.target.value);let t=Pe(e.target.value);p(!t),t&&c({...s,...t})},className:`font-mono text-[0.8125rem]`}),(0,Q.jsx)(`p`,{className:z(`mt-1.5 text-[0.8125rem]`,f?`text-rose`:`text-ink-3`),children:X(f?`space.gradientCssError`:`space.gradientCssHint`)})]}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:o,children:X(`common.cancel`)}),(0,Q.jsx)(b,{onClick:()=>{a(s),o()},children:X(`settings.save`)})]})]})})}var jr=`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`,Mr=`size-8 bg-card shadow-soft hover:bg-card`;function Nr({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,Q.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,Q.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,Q.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,Q.jsx)(B,{value:e,label:X(`space.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,Q.jsx)(B,{value:n??``,label:X(`space.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function Pr({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=d(e),[o,s]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:t,"aria-label":X(`space.gradientEdit`),onClick:n,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,Q.jsxs)(`div`,{className:jr,children:[(0,Q.jsx)(L,{label:X(o?`space.gradientCopied`:`space.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:Mr,children:(0,Q.jsx)(v,{className:`size-4`})}),(0,Q.jsx)(L,{label:X(`space.download`),onClick:()=>void Or(e,e.name),className:Mr,children:(0,Q.jsx)(m,{className:`size-4`})}),t?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:i,className:z(Mr,`hover:text-rose`),children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),(0,Q.jsx)(Nr,{name:e.name,namePlaceholder:X(`space.gradientName`),description:e.description,usePlaceholder:X(`space.gradientUse`),readOnly:t,onChange:r})]})}function Fr(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function Ir({spaceId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:s}){let c=o(e,t.file);return(0,Q.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:r,"aria-label":X(`space.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:Fr(c,t.tile)}),(0,Q.jsxs)(`div`,{className:jr,children:[(0,Q.jsx)(`a`,{href:c,download:n,"aria-label":X(`space.download`),title:X(`space.download`),className:z(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,Mr),children:(0,Q.jsx)(m,{className:`size-4`})}),r?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:s,className:z(Mr,`hover:text-rose`),children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),(0,Q.jsx)(Nr,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:X(`space.patternUse`),readOnly:r,onChange:a})]})}function Lr({spaceId:e,pattern:t,isNew:n,fileName:r,busy:a,error:s,upload:c,removeFile:l,onSave:u,onClose:d}){let[p,m]=(0,Z.useState)(t),[h,g]=(0,Z.useState)([]),_=async e=>{let t=e[0];if(!t)return;let n=await c(t);n&&(g(e=>[...e,n.id]),m(e=>({...e,file:n.id,name:e.name||n.name.replace(/\.[^.]+$/,``)})))},v=()=>{for(let e of h)l(e);d()};return(0,Q.jsx)(I,{open:!0,onClose:v,wide:!0,title:X(n?`space.patternNew`:`space.patternEdit`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p.file?(0,Q.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:Fr(o(e,p.file),p.tile),children:(0,Q.jsxs)(V,{accept:`image/*`,multiple:!1,onFiles:e=>void _(e),className:`absolute right-2 bottom-2 h-9 border-solid bg-card px-3.5 text-ink-2 shadow-soft`,children:[a?(0,Q.jsx)(Se,{className:`size-4`}):(0,Q.jsx)(f,{className:`size-4`}),X(`space.patternReplace`)]})}):(0,Q.jsxs)(V,{accept:`image/*`,multiple:!1,onFiles:e=>void _(e),className:`h-40 flex-col`,children:[a?(0,Q.jsx)(Se,{className:`size-5`}):(0,Q.jsx)(f,{className:`size-5`}),X(`space.patternPick`)]}),(0,Q.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.patternName`)}),(0,Q.jsx)(O,{value:p.name,maxLength:80,placeholder:p.file?r(p.file):X(`space.patternNamePlaceholder`),onChange:e=>m({...p,name:e.target.value})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.fillUseLabel`)}),(0,Q.jsx)(O,{value:p.description??``,maxLength:400,placeholder:X(`space.patternUse`),onChange:e=>m({...p,description:e.target.value})})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.patternShow`)}),(0,Q.jsx)(`div`,{className:`flex w-fit gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:[!1,!0].map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":!!p.tile===e,onClick:()=>m({...p,tile:e||void 0}),className:z(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,!!p.tile===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:X(e?`space.patternTile`:`space.patternFill`)},String(e)))})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[s?(0,Q.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:s}):null,(0,Q.jsx)(b,{variant:`ghost`,onClick:v,children:X(`common.cancel`)}),(0,Q.jsx)(b,{disabled:!p.file||a,onClick:()=>{for(let e of h.filter(e=>e!==p.file))l(e);t.file&&t.file!==p.file&&l(t.file),u({...p,name:p.name.trim(),description:p.description?.trim()||void 0}),d()},children:X(n?`space.add`:`settings.save`)})]})]})})}var Rr=/^#[0-9a-fA-F]{6}$/;function zr({spaceId:e,onAdd:t,onClose:n}){let[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)([]),h=async()=>{c(!0),u(null);try{let{colors:t}=await q.post(`/api/studio/spaces/${e}/colors/scan`,{url:a.trim()});t.length?(f(t),m([])):u(X(`space.colorsNoneFound`))}catch(e){u(e.message)}c(!1)};return(0,Q.jsx)(I,{open:!0,onClose:n,wide:d?!0:void 0,title:X(d?`space.colorsFound`:`space.colorsFromUrl`),children:d?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`space.colorsFoundHint`)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:d.map(e=>{let t=p.includes(e.value);return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>m(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:z(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,Q.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,Q.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,Q.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,Q.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(r,{className:`size-3.5`})}):null]},e.value)})}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>f(null),children:X(`run.back`)}),(0,Q.jsx)(b,{disabled:!p.length,onClick:()=>{t(d.filter(e=>p.includes(e.value))),n()},children:p.length>1?X(`space.addMany`,{n:p.length}):X(`space.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.logoUrl`)}),(0,Q.jsx)(O,{autoFocus:!0,value:a,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>o(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.colorsUrlHint`)})]}),l?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,busy:s,disabled:!a.trim(),children:X(`run.next`)})]})]})})}function Br({spaceId:e,data:t,colors:n,sections:r,gradients:i,patterns:a,rules:o,sectioned:s,ruled:l,save:u,readOnly:d}){let[f,p]=(0,Z.useState)(()=>n.map(e=>({...e,id:A()}))),[m,g]=(0,Z.useState)(r),[_,v]=(0,Z.useState)(i),[b,x]=(0,Z.useState)(a),[S,C]=(0,Z.useState)(null),[w,ee]=(0,Z.useState)(null),T=h(e,d),E=c(o),[D,k]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(null),[te,ne]=(0,Z.useState)(!1),re=N({colors:f.filter(e=>Rr.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:m,gradients:_,patterns:b,colorRules:E.rules},u),P=s?m:[],ie=P.filter(e=>(e.kind??`colors`)===`colors`),F=e=>ie.some(t=>t.id===e.section),ae=f.filter(e=>!F(e)),I=(ae[0]??f[0])?.id,se=(e,t)=>p(n=>n.map(n=>n.id===e?{...n,...t}:n)),ce=e=>p(t=>[...t,...e.map(e=>({...e,id:A()}))].slice(0,H.colors)),le=[{value:``,label:X(`space.sectionStandard`)},...ie.map(e=>({value:e.id,label:e.title||X(`space.sectionUntitled`)}))],ue=(e,t)=>{let n=A();k(n),g(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},z=e=>({id:A(),name:``,section:e,type:`linear`,angle:90,stops:[{color:f[0]?.value&&Rr.test(f[0].value)?f[0].value:`#4b73ff`,at:0},{color:f[1]?.value&&Rr.test(f[1].value)?f[1].value:`#ff6d1b`,at:100}]}),de=e=>t.files.find(t=>t.id===e)?.name??`pattern`,pe=[...f.length<H.colors?[{label:X(`space.colorNew`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>me()},{label:X(`space.colorsFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>ne(!0)}]:[],...s&&m.length<H.logoSections?[{label:X(`space.colorSectionAdd`),icon:(0,Q.jsx)(bn,{className:`size-4 shrink-0`}),onPick:()=>ue(`colors`,``)},{label:X(`space.gradientSectionAdd`),icon:(0,Q.jsx)(mn,{className:`size-4 shrink-0`}),onPick:()=>ue(`gradients`,X(`space.gradientSectionTitle`))},{label:X(`space.patternSectionAdd`),icon:(0,Q.jsx)(Sn,{className:`size-4 shrink-0`}),onPick:()=>ue(`patterns`,X(`space.patternSectionTitle`))}]:[],...!l||E.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>E.add()}]],B=e=>(0,Q.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,Q.jsx)(he,{value:Rr.test(e.value)?e.value:`#888888`,onChange:t=>se(e.id,{value:t.target.value})}),(0,Q.jsx)(O,{value:e.name,autoFocus:e.id===j,placeholder:X(`space.colorName`),maxLength:120,onChange:t=>se(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,Q.jsx)(O,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>se(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,Q.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===I?(0,Q.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,Q.jsx)(y,{tone:`ember`,children:X(`space.colorAccent`)})}):d?null:(0,Q.jsx)(L,{label:X(`space.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,Q.jsx)(Ce,{className:`size-4`})}),d||!ie.length?null:(0,Q.jsx)(oe,{options:le,value:F(e)?e.section??``:``,onChange:t=>se(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),d?null:(0,Q.jsx)(L,{label:X(`space.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,Q.jsx)(K,{className:`size-4`})})]})]},e.id),me=e=>{let t=A();M(t),p(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,Q.jsxs)(R,{title:X(`space.colors`),hint:X(`space.colorsHint`),save:re,locked:d,action:d?null:(0,Q.jsx)(fe,{entries:pe}),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[ae.length?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:ae.map(B)}),d?null:(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.colorUse`)})]}):f.length?null:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`space.colorsEmpty`)}),P.map(t=>{let n=t.kind??`colors`,r=f.filter(e=>e.section===t.id),i=_.filter(e=>e.section===t.id),a=b.filter(e=>e.section===t.id),o=n===`gradients`?i.length:n===`patterns`?a.length:r.length;return(0,Q.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,Q.jsx)(Ae,{title:t.title,titlePlaceholder:X(n===`gradients`?`space.gradientSectionTitlePlaceholder`:n===`patterns`?`space.patternSectionTitlePlaceholder`:`space.colorSectionTitle`),kind:n===`gradients`?{icon:(0,Q.jsx)(mn,{}),label:X(`space.kindGradients`)}:n===`patterns`?{icon:(0,Q.jsx)(Sn,{}),label:X(`space.kindPatterns`)}:{icon:(0,Q.jsx)(Ge,{}),label:X(`space.kindColors`)},autoFocus:D===t.id,readOnly:d,onChange:e=>g(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!o||confirm(X(n===`colors`?`space.colorSectionRemoveConfirm`:`space.fillSectionRemoveConfirm`,{name:t.title||X(`space.sectionUntitled`)}))){g(e=>e.filter(e=>e.id!==t.id)),p(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),v(e=>e.filter(e=>e.section!==t.id));for(let e of a)T.remove(e.file);x(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[i.map(e=>(0,Q.jsx)(Pr,{gradient:e,readOnly:d,onEdit:()=>C(e),onChange:t=>v(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>v(t=>t.filter(t=>t.id!==e.id))},e.id)),d||_.length>=H.gradients?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>C(z(t.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-5`}),X(`space.gradientAdd`)]})]}):n===`patterns`?(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(t=>(0,Q.jsx)(Ir,{spaceId:e,pattern:t,fileName:de(t.file),readOnly:d,onEdit:()=>ee(t),onChange:e=>x(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{T.remove(t.file),x(e=>e.filter(e=>e.id!==t.id))}},t.id)),d||b.length>=H.files.pattern?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>ee({id:A(),name:``,section:t.id,file:``}),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-5`}),X(`space.patternAdd`)]})]}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(B),d||f.length>=H.colors?null:(0,Q.jsx)(be,{label:X(`space.colorAdd`),onClick:()=>me(t.id)})]})]},t.id)}),l?(0,Q.jsx)(De,{rules:E,placeholder:X(`space.colorRulePlaceholder`),readOnly:d}):null]}),T.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:T.error}):null,S?(0,Q.jsx)(Ar,{spaceId:e,gradient:S,isNew:!_.some(e=>e.id===S.id),brand:f.filter(e=>Rr.test(e.value)),onClose:()=>C(null),onSave:e=>v(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,w?(0,Q.jsx)(Lr,{spaceId:e,pattern:w,isNew:!b.some(e=>e.id===w.id),fileName:de,busy:T.busy,error:T.error,upload:async e=>(await T.upload(`pattern`,[e]))[0]??null,removeFile:e=>void T.remove(e),onClose:()=>ee(null),onSave:e=>x(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,te?(0,Q.jsx)(zr,{spaceId:e,onClose:()=>ne(!1),onAdd:ce}):null]})}var Vr=e=>/^(ja|yes|true)$/i.test(e.trim()),Hr={text:Ie,longtext:Jt,number:pt,date:mt,url:D,email:un,phone:Kt,boolean:ht};function Ur({type:e,detected:t,onChange:n}){let[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),c=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!i)return;let e=e=>{c.current?.contains(e.target)||a(!1)},t=e=>e.key===`Escape`&&a(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let l=Hr[e??t],u=`${X(`space.factType`)}: ${X(`space.type.${e??t}`)}`,d=`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`,f=e=>{n(e),a(!1)};return(0,Q.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":u,title:u,"aria-haspopup":`menu`,"aria-expanded":i,onClick:e=>{s(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),a(e=>!e)},className:z(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,i?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,Q.jsx)(l,{className:`size-4`})}),i?(0,Q.jsxs)(`div`,{role:`menu`,className:z(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,o?`bottom-12`:`top-12`),children:[(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:d,onClick:()=>f(void 0),children:[(0,Q.jsx)(Ee,{className:`size-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:X(`space.factAuto`)}),(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:X(`space.type.${t}`)}),(0,Q.jsx)(r,{className:z(`size-4 shrink-0`,e&&`invisible`)})]}),(0,Q.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),M.map(t=>{let n=Hr[t];return(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:d,onClick:()=>f(t),children:[(0,Q.jsx)(n,{className:`size-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:X(`space.type.${t}`)}),(0,Q.jsx)(r,{className:z(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Wr({facts:e,save:t,readOnly:n}){let r=(0,Z.useRef)(0),i=(0,Z.useRef)(null),[a,o]=(0,Z.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),s=N(a.filter(e=>e.key&&e.label.trim()).map(({key:e,label:t,value:n,type:r})=>({key:e,label:t.trim(),value:n,...r?{type:r}:{}})),t),c=(e,t)=>o(n=>n.map(n=>n.id===e?{...n,...t}:n)),l=(e,t,n=!1)=>{let a=`f${r.current++}`;i.current=`${a}:${t}`;let s={id:a,key:``,label:``,value:``,...e};o(e=>n?[s,...e]:[...e,s])},u=e=>t=>{t&&i.current===e&&(i.current=null,t.focus())},d=ke.filter(e=>!a.some(t=>t.key===e));return(0,Q.jsxs)(R,{title:X(`space.facts`),hint:X(`space.factsHint`),save:s,locked:n,action:a.length<H.facts&&!n?(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>l({},`label`,!0),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.factAdd`)]}):null,children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>{let t=C(e.value),r=e.type??t;return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,Q.jsx)(O,{ref:u(`${e.id}:label`),value:e.label,placeholder:X(`space.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>c(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&c(e.id,{key:w(e.label,a.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,Q.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Q.jsx)(le,{checked:Vr(e.value),label:e.label,onChange:t=>c(e.id,{value:X(t?`space.yes`:`space.no`)})}),(0,Q.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Vr(e.value)?X(`space.yes`):X(`space.no`)})]}):(0,Q.jsx)(we,{ref:u(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:X(`space.factValue`),onChange:t=>c(e.id,{value:t.target.value}),className:`min-h-11`}),(0,Q.jsx)(Ur,{type:e.type,detected:t,onChange:t=>c(e.id,{type:t})}),n?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>o(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]},e.id)})}),a.length<H.facts&&!n?(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${a.length?`mt-4`:``}`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>l({},`label`),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.factAdd`)]}),d.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l({key:e,label:X(`fact.${e}`)},`value`),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-3.5`}),` `,X(`fact.${e}`)]},e))]}):null]})}var Gr=[{label:`Website`,placeholder:`https://…`},{label:`LinkedIn`,placeholder:`linkedin.com/company/…`},{label:`Instagram`,placeholder:`instagram.com/…`},{label:`Facebook`,placeholder:`facebook.com/…`},{label:`YouTube`,placeholder:`youtube.com/@…`},{label:`TikTok`,placeholder:`tiktok.com/@…`},{label:`X`,placeholder:`x.com/…`}],Kr=e=>e===`Website`?ft:Gr.some(t=>t.label===e)?fn:D;function qr({links:e,readOnly:t,save:n}){let[r,i]=(0,Z.useState)(e),a=(0,Z.useRef)(null),o=N(r.map(e=>({...e,label:e.label.trim(),url:e.url.trim()})).filter(e=>e.url),n),s=(e,t)=>i(n=>n.map(n=>n.id===e?{...n,...t}:n)),c=e=>{let t=A();a.current=`${t}:${e?`url`:`label`}`,i(n=>[...n,{id:t,label:e,url:``}])},l=e=>t=>{t&&a.current===e&&(a.current=null,t.focus())},u=Gr.filter(e=>!r.some(t=>t.label===e.label)),d=r.length>=H.links,f=[...u.map(e=>{let t=Kr(e.label);return{label:e.label,icon:(0,Q.jsx)(t,{className:`size-4 shrink-0`}),onPick:()=>c(e.label)}}),{label:X(`space.links.own`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>c(``)}];return(0,Q.jsxs)(R,{title:X(`space.links`),hint:X(`space.linksHint`),save:o,locked:t,action:t||d?null:(0,Q.jsx)(fe,{entries:f}),children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:r.map(e=>{let n=Kr(e.label);return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-2 sm:grid-cols-[auto_minmax(0,2fr)_minmax(0,3fr)_auto]`,children:[(0,Q.jsx)(`span`,{className:`grid size-11 place-items-center text-ink-3`,children:(0,Q.jsx)(n,{className:`size-4`})}),(0,Q.jsx)(O,{ref:l(`${e.id}:label`),value:e.label,maxLength:80,readOnly:t,placeholder:X(`space.links.label`),onChange:t=>s(e.id,{label:t.target.value}),className:`max-sm:col-span-1 max-sm:font-medium`}),(0,Q.jsx)(O,{ref:l(`${e.id}:url`),value:e.url,maxLength:600,readOnly:t,inputMode:`url`,placeholder:Gr.find(t=>t.label===e.label)?.placeholder??`https://…`,onChange:t=>s(e.id,{url:t.target.value}),className:`max-sm:col-span-2 max-sm:col-start-2 max-sm:row-start-2`}),t?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>i(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose max-sm:col-start-3 max-sm:row-start-1`,children:(0,Q.jsx)(K,{className:`size-4`})})]},e.id)})}),t||d?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${r.length?`mt-4`:``}`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>c(``),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.links.own`)]}),u.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(e.label),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-3.5`}),` `,e.label]},e.label))]})]})}function Jr({onLogo:e,children:t,className:n}){let[r,i]=(0,Z.useState)(!1);return e?(0,Q.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(In);i(!1),n&&(t.preventDefault(),e(n))},className:z(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,Q.jsx)(`div`,{className:n,children:t})}function Yr({spaceId:e,data:t,readOnly:n,sections:r,rules:i,sectioned:a,ruled:o,save:s}){let l=h(e,n),[u,d]=(0,Z.useState)(r),f=c(i),[p,m]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(null),y=N({logoSections:u,logoRules:f.rules},s),b=t.files.filter(e=>e.kind===`logo`),S=new Map(b.map(e=>[e.id,e])),C=a?u:[],w=new Set(C.flatMap(e=>e.logos)),ee=b.filter(e=>!w.has(e.id)),T=x(b,u)?.id,E=(e,t)=>d(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),D=(e,t)=>d(n=>n.map(n=>n.id===e?{...n,...t}:n)),O=async(e,t)=>{let n=await l.upload(`logo`,e);for(let e of n)E(e.id,t)},k=C.length?{options:[{value:``,label:X(`space.sectionStandard`)},...C.map(e=>({value:e.id,label:e.title||X(`space.sectionUntitled`)}))],current:e=>C.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>E(e.id,t||null)}:void 0,j=(t,n,r)=>(0,Q.jsx)(Ln,{spaceId:e,kind:`logo`,files:t,actions:l,accept:`image/*`,addLabel:r?X(`space.logoAdd`):void 0,onUpload:e=>void O(e,n),mainId:T,onMakeMain:e=>{E(e.id,null),l.order(`logo`,[e.id,...b.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:k,onRemove:e=>{confirm(X(`space.removeConfirm`,{name:e.name}))&&(l.remove(e.id),E(e.id,null))}}),M=n?void 0:e=>t=>E(t,e),te=[{label:X(`space.logoUpload`),icon:(0,Q.jsx)(Xt,{className:`size-4 shrink-0`}),onPick:()=>v.current?.click()},{label:X(`space.logoFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>_(!0)},...a&&u.length<H.logoSections?[{label:X(`space.logoSectionAdd`),icon:(0,Q.jsx)(bn,{className:`size-4 shrink-0`}),onPick:()=>{let e=A();m(e),d(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!o||f.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,Q.jsxs)(R,{title:X(`space.logos`),hint:X(`space.logosHint`),save:y,action:n?null:(0,Q.jsx)(fe,{entries:te}),children:[(0,Q.jsx)(`input`,{ref:v,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&&O(t,null)}}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Q.jsx)(Jr,{onLogo:M?.(null),children:j(ee,null,!0)}),C.map(e=>(0,Q.jsx)(`div`,{className:`group/section`,children:(0,Q.jsxs)(Jr,{onLogo:M?.(e.id),className:`flex flex-col gap-3`,children:[(0,Q.jsx)(Ae,{title:e.title,description:e.description,titlePlaceholder:X(`space.logoSectionTitle`),descriptionPlaceholder:X(`space.logoSectionUse`),autoFocus:p===e.id,readOnly:n,onChange:t=>D(e.id,t),onRemove:()=>{(!e.logos.length||confirm(X(`space.logoSectionRemoveConfirm`,{name:e.title||X(`space.sectionUntitled`)})))&&d(t=>t.filter(t=>t.id!==e.id))}}),j(e.logos.map(e=>S.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),o?(0,Q.jsx)(De,{rules:f,placeholder:X(`space.logoRulePlaceholder`),readOnly:n}):null]}),l.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:l.error}):null,g?(0,Q.jsx)(Rn,{kind:`logo`,onClose:()=>_(!1),fetchUrl:e=>l.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)E(t.id,null)}}):null]})}var Xr=e=>URL.canParse(e)?new URL(e).host:e;async function Zr(e,t){let n=E({family:t,source:{url:e}});if(!n)return`down`;if(n.stylesheet)return await Qr(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 Qr(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 $r(e,t){let n=e.source;if(!n)return X(`space.fontSourceNone`);if(`file`in n){let e=t.find(e=>e.id===n.file)?.name??``;return X(`space.fontSourceFile`,{name:e})}return X(`space.fontSourceUrl`,{host:Xr(n.url)})}function ei({spaceId:e,font:t,onSave:n,onClose:r}){let a=(P(e).data?.files??[]).filter(e=>e.mime.startsWith(`font/`)),o=h(e),s=(0,Z.useRef)(null),[c,l]=(0,Z.useState)(t.source&&`url`in t.source?`url`:`file`),[u,d]=(0,Z.useState)(t.source&&`file`in t.source?t.source.file:``),[f,p]=(0,Z.useState)(t.source&&`url`in t.source?t.source.url:``),[m,g]=(0,Z.useState)(t.source&&`url`in t.source?{url:t.source.url,result:`ok`}:null),[_,v]=(0,Z.useState)(!1),[y,x]=(0,Z.useState)(t.license??``),[S,C]=(0,Z.useState)(!1),w=f.trim(),ee=async()=>{v(!0),g({url:w,result:await Zr(w,t.family.trim())}),v(!1)},T=c===`file`?u?{file:u}:null:m?.url===w&&m.result===`ok`?{url:w}:null,E=m?.url===w?m.result:null;return(0,Q.jsx)(I,{open:!0,onClose:r,title:X(`space.fontSourceTitle`,{family:t.family}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`space.fontSourceHint`)}),(0,Q.jsx)(Te,{value:c,options:[`file`,`url`],label:e=>X(`space.fontSourceKind.${e}`),onChange:e=>l(e)}),c===`file`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.fontSourceFiles`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":u===e.id,onClick:()=>d(e.id),className:z(`rounded-lg px-3 py-2 text-left text-[0.875rem] ring-1 transition`,u===e.id?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:e.name},e.id))}),(0,Q.jsx)(`input`,{ref:s,type:`file`,accept:`.woff2,.woff,.ttf,.otf`,className:`hidden`,onChange:async e=>{let t=[...e.target.files??[]];e.target.value=``;let[n]=await o.upload(`asset`,t);n&&d(n.id)}}),(0,Q.jsxs)(b,{variant:`ghost`,className:`mt-2`,busy:o.busy,onClick:()=>s.current?.click(),children:[(0,Q.jsx)(Xt,{className:`size-4`}),X(`space.fontSourceUpload`)]}),o.error?(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-rose`,children:o.error}):null]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ee()},children:[(0,Q.jsx)(i,{children:X(`space.fontSourceUrlLabel`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(O,{value:f,inputMode:`url`,placeholder:X(`space.fontSourceUrlPlaceholder`),onChange:e=>p(e.target.value)}),(0,Q.jsx)(b,{type:`submit`,variant:`ghost`,busy:_,disabled:!w.startsWith(`https://`),children:X(`space.fontSourceCheck`)})]}),E?(0,Q.jsx)(`p`,{className:z(`mt-1.5 text-[0.875rem]`,E===`ok`?`text-ink-3`:`text-rose`),children:X(`space.fontCheck.${E}`,{host:Xr(w),family:t.family})}):null,E===`ok`?(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-ink-3`,children:X(`space.fontPrivacy`,{host:Xr(w)})}):null]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{hint:X(`space.fontLicenseHint`),children:X(`space.fontLicense`)}),(0,Q.jsx)(O,{value:y,maxLength:200,placeholder:X(`space.fontLicensePlaceholder`),onChange:e=>x(e.target.value)}),(0,Q.jsxs)(`label`,{className:`mt-2 flex items-start gap-2 text-[0.875rem]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 accent-ember`,checked:S,onChange:e=>C(e.target.checked)}),X(`space.fontLicenseConfirm`,{family:t.family})]})]}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[t.source?(0,Q.jsx)(b,{variant:`ghost`,className:`mr-auto`,onClick:()=>{n({source:void 0,license:t.license}),r()},children:X(`space.fontSourceRemove`)}):null,(0,Q.jsx)(b,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Q.jsx)(b,{disabled:!(T&&S),onClick:()=>{T&&(n({source:T,license:y.trim()||void 0}),r())},children:X(`space.fontSourceSave`)})]})]})})}var ti=new Set;function ni(e){(0,Z.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||ti.has(t))return;ti.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${l.join(`,`)}&display=swap`,document.head.append(n)},[e])}var ri=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function ii({unit:e,label:t,...n}){return(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,Q.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var ai=`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`,oi={web:`space.fontUseWeb`,documents:`space.fontUseDocuments`,print:`space.fontUsePrint`,images:`space.fontUseImages`,video:`space.fontUseVideo`};function si({spaceId:e,font:t,first:n,readOnly:i,autoFocus:a,onChange:o,onRemove:s}){ni(t.family);let c=P(e).data?.files??[],[d,f]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:ri(t.family)},children:[(0,Q.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,Q.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),i?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:t.family}),t.role?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:t.role}):null]}):(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(B,{value:t.family,label:X(`space.fontFamily`),placeholder:X(`space.fontFamily`),maxLength:80,autoFocus:a,onChange:e=>o({family:e}),className:`font-medium text-[0.9375rem]`}),(0,Q.jsx)(B,{value:t.role,label:X(`space.fontRole`),placeholder:X(n?`space.fontRoleFirst`:`space.fontRole`),maxLength:200,onChange:e=>o({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:l.map(e=>{let n=t.weights.includes(e);return(0,Q.jsx)(`button`,{type:`button`,disabled:i,"aria-pressed":n,onClick:()=>o({weights:n?t.weights.filter(t=>t!==e):[...t.weights,e].sort((e,t)=>e-t)}),style:{fontFamily:ri(t.family),fontWeight:e},className:z(`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`,i&&!n&&`hidden`),children:e},e)})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[i?t.license?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:t.license}):null:(0,Q.jsx)(B,{value:t.license??``,label:X(`space.fontLicense`),placeholder:X(`space.fontLicensePlaceholder`),maxLength:200,onChange:e=>o({license:e}),className:`text-[0.8125rem] text-ink-3`}),i&&!t.uses?.length?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:X(`space.fontUses`)}),u.map(e=>{let n=!!t.uses?.includes(e);return(0,Q.jsxs)(`button`,{type:`button`,disabled:i,"aria-pressed":n,onClick:()=>{let r=n?(t.uses??[]).filter(t=>t!==e):u.filter(n=>n===e||t.uses?.includes(n));o({uses:r.length?r:void 0})},className:z(`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`,i&&!n&&`hidden`),children:[n?(0,Q.jsx)(r,{className:`size-3.5`}):null,X(oi[e])]},e)})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[0.8125rem] text-ink-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:$r(t,c)}),i||!t.family.trim()?null:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(!0),className:`text-ink underline decoration-border underline-offset-2 hover:decoration-ink`,children:X(t.source?`space.fontSourceChange`:`space.fontSourceSet`)})]}),d?(0,Q.jsx)(ei,{spaceId:e,font:t,onSave:o,onClose:()=>f(!1)}):null,i?null:(0,Q.jsx)(L,{label:X(`space.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,Q.jsx)(K,{className:`size-4`})})]})}function ci({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:ri(s?.family),fontWeight:e.weight,fontSize:`${Math.min(e.size,56)}px`,lineHeight:`${e.lineHeight}%`,letterSpacing:`${e.tracking/100}em`,textTransform:e.uppercase?`uppercase`:void 0};return(0,Q.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,Q.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,Q.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,Q.jsx)(`div`,{className:`w-40`,children:(0,Q.jsx)(B,{value:e.name,label:X(`space.styleName`),placeholder:X(`space.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,Q.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,Q.jsx)(`select`,{"aria-label":X(`space.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:z(ai,`max-w-40`),children:t.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.family||X(`space.fontFamily`)},e.id))}):null,(0,Q.jsx)(`select`,{"aria-label":X(`space.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:ai,children:[...new Set([...l,e.weight])].sort().map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))}),(0,Q.jsx)(ii,{unit:`px`,label:X(`space.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,Q.jsx)(ii,{unit:X(`space.styleLine`),label:X(`space.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,Q.jsx)(ii,{unit:X(`space.styleTracking`),label:X(`space.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:X(`space.styleUpper`),"aria-label":X(`space.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:z(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,Q.jsx)(vn,{className:`size-4`})})]}),r?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:o,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]})]})}function li({spaceId:e,onAdd:t,onClose:n}){let[r,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)([]),m=async()=>{s(!0),l(null);try{let{fonts:t}=await q.post(`/api/studio/spaces/${e}/fonts/scan`,{url:r.trim()});t.length?(d(t),p(t.slice(0,2).map(e=>e.family))):l(X(`space.fontsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,Q.jsx)(I,{open:!0,onClose:n,wide:u?!0:void 0,title:X(u?`space.fontsFound`:`space.fontsFromUrl`),children:u?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`space.fontsFoundHint`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map(e=>(0,Q.jsx)(ui,{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,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>d(null),children:X(`run.back`)}),(0,Q.jsx)(b,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.family))),n()},children:f.length>1?X(`space.addMany`,{n:f.length}):X(`space.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.logoUrl`)}),(0,Q.jsx)(O,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.fontsUrlHint`)})]}),c?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,busy:o,disabled:!r.trim(),children:X(`run.next`)})]})]})})}function ui({font:e,on:t,onToggle:n}){return ni(e.family),(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:z(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,Q.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:ri(e.family)},children:`Aa`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):X(`space.fontWeightsUnknown`)})]}),t?(0,Q.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(r,{className:`size-3.5`})}):null]})}function di({spaceId:e,fonts:t,styles:n,rules:r,ruled:i,sample:a,save:o,readOnly:s}){let[l,u]=(0,Z.useState)(t),[d,f]=(0,Z.useState)(n),p=c(r),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=N({fonts:l,textStyles:d,typeRules:p.rules},o),y=(e,t=!1)=>{let n=e.map(e=>({id:A(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&h(n[0].id),u(e=>[...e,...n].slice(0,H.fonts))},b=()=>{let e=A();h(e),f(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},x=[...l.length<H.fonts?[{label:X(`space.fontNew`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>y([{family:``,weights:[400,700]}],!0)},{label:X(`space.fontsFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>_(!0)}]:[],...d.length<H.textStyles?[{label:X(`space.styleNew`),icon:(0,Q.jsx)(Je,{className:`size-4 shrink-0`}),onPick:b}]:[],...!i||p.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>p.add()}]];return(0,Q.jsxs)(R,{title:X(`space.typography`),hint:X(`space.typographyHint`),save:v,action:s?null:(0,Q.jsx)(fe,{entries:x}),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[l.length?(0,Q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:l.map((t,n)=>(0,Q.jsx)(si,{spaceId:e,font:t,first:n===0,readOnly:s,autoFocus:m===t.id,onChange:e=>u(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>u(e=>e.filter(e=>e.id!==t.id))},t.id))}):(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`space.fontsEmpty`)}),d.length?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:X(`space.styles`)}),s?null:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:X(`space.stylesHint`)}),(0,Q.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:d.map(e=>(0,Q.jsx)(ci,{style:e,fonts:l,sample:a,readOnly:s,autoFocus:m===e.id,onChange:t=>f(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>f(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,i?(0,Q.jsx)(De,{rules:p,placeholder:X(`space.typeRulePlaceholder`),readOnly:s}):null]}),g?(0,Q.jsx)(li,{spaceId:e,onClose:()=>_(!1),onAdd:e=>y(e)}):null]})}var fi=[{title:`space.voice.tone`,hint:`space.voice.toneHint`},{title:`space.voice.audience`,hint:`space.voice.audienceHint`},{title:`space.voice.positioning`,hint:`space.voice.positioningHint`},{title:`space.voice.values`,hint:`space.voice.valuesHint`}];function pi({blocks:e,rules:t,ruled:n,readOnly:r,save:i}){let[a,o]=(0,Z.useState)(e),[s,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),f=c(t),p=N({voice:a,voiceRules:f.rules},i),m=(e,t)=>o(n=>n.map(n=>n.id===e?{...n,...t}:n)),h=a.length>=H.voiceBlocks,g=e=>{let t=A();(e?d:l)(t),o(n=>[...n,{id:t,title:e,text:``}])},_=fi.filter(e=>!a.some(t=>t.title===X(e.title))),v=e=>fi.find(t=>X(t.title)===e)?.hint,y=[...h?[]:[..._.map(e=>({label:X(e.title),icon:(0,Q.jsx)(An,{className:`size-4 shrink-0`}),onPick:()=>g(X(e.title))})),{label:X(`space.voice.own`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>g(``)}],...!n||f.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,Q.jsx)(R,{title:X(`space.voice`),hint:X(`space.voiceHint`),save:p,locked:r,action:r||!y.length?null:(0,Q.jsx)(fe,{entries:y}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[a.length?(0,Q.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:a.map(e=>{let t=v(e.title);return(0,Q.jsxs)(`div`,{className:`group/row grid gap-x-6 gap-y-2 py-4 first:pt-0 last:pb-0 sm:grid-cols-[15rem_minmax(0,1fr)]`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-1`,children:[r?(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 font-medium text-[0.9375rem]`,children:e.title}):(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(B,{value:e.title,label:X(`space.voice.title`),placeholder:X(`space.voice.title`),maxLength:80,autoFocus:s===e.id,onChange:t=>m(e.id,{title:t}),className:`font-medium text-[0.9375rem]`})}),r?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>{(!e.text.trim()||confirm(X(`space.voice.removeConfirm`,{name:e.title||X(`space.sectionUntitled`)})))&&o(t=>t.filter(t=>t.id!==e.id))},className:`-mt-1 size-8 shrink-0 rounded-lg opacity-0 transition hover:text-rose focus-visible:opacity-100 group-hover/row:opacity-100 max-sm:opacity-100`,children:(0,Q.jsx)(K,{className:`size-4`})})]}),r?(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-[0.9375rem] text-ink-2 leading-relaxed sm:pt-2`,children:e.text}):(0,Q.jsx)(we,{ref:t=>{t&&u===e.id&&(d(null),t.focus())},rows:2,minRows:2,maxRows:14,maxLength:H.voiceText,value:e.text,placeholder:X(t||`space.voice.textPlaceholder`),onChange:t=>m(e.id,{text:t.target.value})})]},e.id)})}):null,r||h?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>g(``),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.voice.own`)]}),_.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>g(X(e.title)),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-3.5`}),` `,X(e.title)]},e.title))]}),n?(0,Q.jsx)(De,{rules:f,placeholder:X(`space.voice.rulePlaceholder`),readOnly:r}):null]})})}function mi({spaceId:e,logo:t}){let n=X(t?`space.logoPeek`:`space.logoPeekAdd`);return(0,Q.jsxs)(`div`,{className:`shrink-0`,children:[(0,Q.jsx)(i,{children:X(`space.logo`)}),(0,Q.jsx)(U,{to:{pathname:`/space/brand`,hash:`logos`},title:n,"aria-label":n,className:z(`grid size-[4.5rem] place-items-center overflow-hidden rounded-xl transition`,t?`bg-card ring-1 ring-border-soft hover:ring-border`:`text-ink-4 ring-1 ring-border ring-dashed hover:text-ink-2`),children:t?(0,Q.jsx)(Pn,{spaceId:e,file:t,small:!0}):(0,Q.jsx)(_,{className:`size-5`})})]})}function hi({space:e,save:t}){let n=Wt().data,r=Ht(),i=Ke(`capabilities`)&&r&&n?.mode===`managed`,[a,o]=(0,Z.useState)(e.membersStudio);return i?(0,Q.jsxs)(`div`,{className:`flex items-start gap-3 border-border-soft border-t pt-5`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:X(`space.membersStudio`)}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:X(`space.membersStudioHint`)})]}),(0,Q.jsx)(le,{checked:a,disabled:e.readOnly,label:X(`space.membersStudio`),onChange:e=>{o(e),t({membersStudio:e}).catch(()=>o(!e))}})]}):null}function gi({space:e,save:t}){let[n,r]=(0,Z.useState)(e.brand.brandName??``),[i,a]=(0,Z.useState)(e.brand.tagline??``),o=N({brandName:n.trim(),tagline:i.trim()},e=>t({brand:e}));return(0,Q.jsx)(R,{title:X(`space.identity`),hint:X(`space.identityHint`),save:o,locked:e.readOnly,children:(0,Q.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[{id:`brand-name`,label:X(`space.brandName`),hint:X(`space.brandNameHint`),field:(0,Q.jsx)(O,{id:`brand-name`,value:n,maxLength:120,placeholder:e.brand.name??``,onChange:e=>r(e.target.value)})},{id:`brand-tagline`,label:X(`space.tagline`),hint:X(`space.taglineHint`),field:(0,Q.jsx)(O,{id:`brand-tagline`,value:i,maxLength:200,onChange:e=>a(e.target.value)})}].map(e=>(0,Q.jsxs)(`div`,{className:`grid items-start gap-x-6 gap-y-2 py-4 first:pt-0 last:pb-0 sm:grid-cols-[15rem_minmax(0,1fr)]`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{htmlFor:e.id,className:`font-medium text-[0.9375rem]`,children:e.label}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3 leading-snug`,children:e.hint})]}),e.field]},e.id))})})}function _i({space:e,logo:t,save:n}){let[r,a]=(0,Z.useState)(e.brand.name??``),[o,s]=(0,Z.useState)(e.brand.about??``),c=N({name:r.trim(),about:o.trim()},e=>n({brand:e}));return(0,Q.jsx)(R,{title:X(`space.base`),hint:X(`space.baseHint`),save:c,locked:e.readOnly,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(i,{children:X(`space.title`)}),(0,Q.jsx)(O,{value:r,maxLength:120,onChange:e=>a(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.titleHint`)})]}),(0,Q.jsx)(mi,{spaceId:e.id,logo:t})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.about`)}),(0,Q.jsx)(we,{minRows:4,value:o,onChange:e=>s(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.aboutHint`)})]}),(0,Q.jsx)(hi,{space:e,save:n})]})})}function vi({space:e,group:t,top:n=!1,children:r}){let i=ie(),a=P(e.id),[o,s]=(0,Z.useState)(0),[c,l]=(0,Z.useState)(!1),u=async t=>{await q.patch(`/api/studio/spaces/${e.id}`,t),await i.invalidateQueries({queryKey:p.spaces()})},d=Be({mutationFn:()=>q.del(`/api/studio/spaces/${e.id}`),onSuccess:()=>i.invalidateQueries({queryKey:p.spaces()})}),f=Ut(),m=Ht(),h=a.data??{files:[],embeddings:!0},g=`${e.id}:${o}`,_=e.readOnly,v=t===`knowledge`,y=Ke(`brandSections`),S=Ke(`brandRules`),C=Ke(`typography`);return We(_?{}:{title:X(v?`space.assistantTitleKnowledge`:`space.assistantTitle`),hello:X(v?`space.assistantHelloKnowledge`:`space.assistantHello`),about:X(v?`space.assistantAboutKnowledge`:`space.assistantAbout`),placeholder:X(v?`space.assistantComposerKnowledge`:`space.assistantComposer`),suggestions:v?[{label:X(`assistant.suggest.knowledgeHow`)},{label:X(`assistant.suggest.knowledgeSite`),fill:!0},{label:X(`assistant.suggest.knowledgeCategories`)}]:[{label:X(`assistant.suggest.readSite`),fill:!0},{label:X(`assistant.suggest.missing`)},...t===`info`?[{label:X(`assistant.suggest.facts`)}]:[]],summary: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:()=>s(e=>e+1)}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[_?(0,Q.jsx)(Yt,{children:qt(e)}):n?(0,Q.jsx)(Qe,{}):null,t===`info`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(W,{id:`base`,children:(0,Q.jsx)(_i,{space:e,logo:x(h.files.filter(e=>e.kind===`logo`),e.brand.logoSections),save:u},`base:${g}`)}),(0,Q.jsx)(W,{id:`facts`,children:(0,Q.jsx)(Wr,{facts:e.facts,save:e=>u({facts:e}),readOnly:_},`facts:${g}`)}),(0,Q.jsx)(W,{id:`links`,children:(0,Q.jsx)(qr,{links:e.brand.links??[],save:e=>u({brand:{links:e}}),readOnly:_},`links:${g}`)})]}):null,t===`brand`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(W,{id:`identity`,children:(0,Q.jsx)(gi,{space:e,save:u},`identity:${g}`)}),(0,Q.jsx)(W,{id:`logos`,children:(0,Q.jsx)(Yr,{spaceId:e.id,data:h,readOnly:_,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:y,ruled:S,save:e=>u({brand:e})},`logos:${g}`)}),(0,Q.jsx)(W,{id:`colors`,children:(0,Q.jsx)(Br,{spaceId: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:S,save:e=>u({brand:e}),readOnly:_},`colors:${g}`)}),C?(0,Q.jsx)(W,{id:`typography`,children:(0,Q.jsx)(di,{spaceId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:S,sample:e.brand.name||X(`space.typeSample`),save:e=>u({brand:e}),readOnly:_},`typography:${g}`)}):null,(0,Q.jsx)(W,{id:`assets`,children:(0,Q.jsx)(Er,{spaceId:e.id,data:h,readOnly:_,sections:e.brand.assetSections??[],save:e=>u({brand:e})},`assets:${g}`)}),(0,Q.jsx)(W,{id:`voice`,children:(0,Q.jsx)(pi,{blocks:e.brand.voice??[],rules:e.brand.voiceRules??[],ruled:S,save:e=>u({brand:e}),readOnly:_},`voice:${g}`)})]}):null,r,t===`info`&&f&&!_&&m?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(b,{variant:`danger`,onClick:()=>l(!0),children:X(`settings.delete`)}),(0,Q.jsxs)(I,{open:c,onClose:()=>l(!1),title:X(`settings.deleteTitle`,{name:e.name}),children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:X(`settings.deleteBody`)}),d.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:d.error.message}):null,(0,Q.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>l(!1),children:X(`common.cancel`)}),(0,Q.jsx)(b,{variant:`danger`,busy:d.isPending,onClick:()=>d.mutate(),children:X(`common.delete`)})]})]})]}):null]})}var yi=/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent);function bi(e){let t=e.join(` `),[n,r]=(0,Z.useState)(e[0]);return(0,Z.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=rt(),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 xi(){let[e,t]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{let e=rt(),n=()=>t(e.clientHeight);n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),e}function Si(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function Ci({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,Q.jsx)(cn,{icon:e.icon??ze,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,Q.jsx)(on,{label:e.label,children:r},e.plugin):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}var wi=(0,Z.lazy)(()=>Ve(()=>import(`./SkillEditor-CqQMg2MC.js`).then(e=>({default:e.SkillEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])));function Ti({place:e}){let{group:t}=Oe(),[n,r]=de(),i=ce(),a=me(),{hash:o}=a,{space:s,loading:c}=Gt(),l=Ye(),u=tn(),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),_=e??(ot(t)&&t!==`skills`?t:void 0),v=_?void 0:l.spaceParts.find(e=>e.id===t),y=_??v?.id,b=a.state?.parts===!0,x=Ke(`pages`),S=Ke(`skills`),C=Xe().filter(e=>x||e.id!==`page`),w=ct(C,l).map(e=>({...e,to:`/space/${e.id}`})),ee=w,T={id:`results`,label:X(`space.results`),icon:at,to:`/space/results`},E={id:`skills`,label:X(`space.skills`),icon:Lt,to:`/skills`},D=_===`results`||_===`skills`,O=_===`results`?T:_===`skills`?E:ee.find(e=>e.id===y),k=n.get(`show`),[A,j]=(0,Z.useState)(``),M=(0,Z.useRef)(null),te=A.trim().toLowerCase(),ne=(0,Z.useMemo)(()=>({slot:d,narrow:u,setDetail:m,filter:te}),[d,u,te]),N=s?s.brand.name?.trim()||s.name:X(`nav.space`),re=Ke(`typography`)?[]:[`typography`],P=v?l.spaceMenus[v.id]??[]:[],ie=v?[{plugin:null,label:null,sections:P}]:_&&_!==`results`?$e(_,l,re):[],F=_?$e(_,l).filter(e=>e.plugin):[],I=bi([...ie,..._===`results`?F:[]].flatMap(e=>e.sections.map(e=>e.id))),L=_===`results`&&k&&k!==`all`?k:null,[oe,se]=(0,Z.useState)(hr),le=gr(_===`results`?s?.id:void 0,L,oe),fe=le.data?.wizards.find(e=>e.id===L)?.title,B=_===`data`&&k&&k!==`all`||_===`knowledge`&&k&&/^[ptfcvs]:/.test(k)?k:null,V=B?.startsWith(`s:`)?l.spaceSections.find(e=>e.id===B.slice(2)):void 0,he=_===`knowledge`&&B&&/^[ptf]:/.test(B)?B:null,H=_===`skills`&&k?.startsWith(`k:`)?k:null,ge=dt(_===`skills`&&S?s?.id:void 0),_e=bt(_===`data`?s?.id:void 0),U=Dt(_===`knowledge`?s?.id:void 0),G=Pt(B?.startsWith(`v:`)?B.slice(2):``),ve=U.data?.categories.find(e=>e.id===(B?.startsWith(`c:`)?B.slice(2):G.data?.category.id)),ye=F.length>0||_===`knowledge`&&!!U.data?.categories.length||_===`data`&&!!(_e.data&&jt(_e.data).some(e=>e.items.length)),be=!!_&&!D&&(_!==`data`&&_!==`knowledge`||!ye),K=_===`results`?2:y?k||be?2:1:k===`overview`?2:0,q=D?1:u?Math.min(K,1):y&&!be&&h!==y&&!b?1:0,xe=an(q),Se=an(K);(0,Z.useEffect)(()=>{g(null),j(``)},[y]),(0,Z.useEffect)(()=>{if(u||q!==1)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`f`&&M.current&&(e.preventDefault(),M.current.focus(),M.current.select())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,q]);let Ce=_===`skills`?ge.data?.skills.find(e=>`k:${e.id}`===H)?.name:_===`knowledge`?V?V.label():B?.startsWith(`v:`)?G.data&&`${G.data.category.name}: ${G.data.value}`:B?.startsWith(`c:`)?ve?.name:U.data?.items.find(e=>e.key===B)?.title:_e.data?jt(_e.data).flatMap(e=>e.items).find(e=>e.key===B)?.title:void 0;et([...D?[]:[{label:X(`nav.sources`),to:`/space`}],...y?[]:[{label:X(`space.overview`)}],...O?[{label:O.label,to:O.to}]:[],...O&&(p??fe??Ce)?[{label:p??fe??Ce}]:[]]);let we={p:`page`,t:`table`,f:`file`,c:`category`,v:`category value`,s:`plugin section`};We({..._===`data`||_===`results`?{compact:!0}:{},..._===`data`?{suggestions:[{label:X(`assistant.suggest.dataWhat`)},{label:X(`assistant.suggest.dataWho`)},{label:X(`assistant.suggest.dataEdit`)}]}:_===`results`?{suggestions:[{label:X(`assistant.suggest.resultsFailed`)},{label:X(`assistant.suggest.resultsCost`)},{label:X(`assistant.suggest.resultsShare`)}]}:{},...B&&Ce?{open:{kind:we[B[0]]??`item`,id:B.slice(2),label:Ce}}:L&&fe?{open:{kind:`wizard`,id:L,label:fe}}:{}});let J=_===`results`||_===`data`||B?o.slice(1):k||o.slice(1),Te=(0,Z.useRef)(``);(0,Z.useEffect)(()=>{let e=`${y}#${J}`;J&&Te.current!==e&&document.getElementById(J)&&(Te.current=e,requestAnimationFrame(()=>Si(J,!1)))},[y,J,s?.id,l.spaceSections,P.length]),(0,Z.useEffect)(()=>{!u&&(y===`knowledge`||y===`data`||y===`skills`)&&rt().scrollTo({top:0})},[u,y,B,H]);let Ee=xi();if(t===`skills`)return(0,Q.jsx)(pe,{to:{pathname:`/skills`,search:a.search,hash:o},replace:!0});if(!y){let e=o.slice(1),n=e?nt(e,l):null;if(n===`knowledge`&&l.spaceSections.some(t=>t.id===e))return(0,Q.jsx)(pe,{to:`/space/knowledge?show=s:${e}`,replace:!0});if(n)return(0,Q.jsx)(pe,{to:u?`/space/${n}?show=${e}`:{pathname:`/space/${n}`,hash:e},replace:!0});if((e||t)&&l.status!==`ready`)return null;if(t!==void 0)return(0,Q.jsx)(pe,{to:`/space`,replace:!0})}let De=_===`info`?k??o.slice(1):``;if(De&&nt(De,l)===`brand`)return(0,Q.jsx)(pe,{to:u?`/space/brand?show=${De}`:{pathname:`/space/brand`,hash:De},replace:!0});if(_===`skills`&&!S)return(0,Q.jsx)(pe,{to:`/`,replace:!0});if(_===`knowledge`&&!k&&l.spaceSections.some(e=>e.id===o.slice(1)))return(0,Q.jsx)(pe,{to:`/space/knowledge?show=s:${o.slice(1)}`,replace:!0});let ke=e=>{if(u){i({search:`?show=${e}`});return}Te.current=`${y}#${e}`,Si(e,!0),i({search:``,hash:e},{replace:!0})},Y=e=>u?r({show:e}):r(e===`all`?{}:{show:e},{replace:!0}),Ae=e=>e.flatMap(e=>e.sections).map(e=>l.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,Q.jsx)(W,{id:e.id,children:(0,Q.jsx)(R,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,Q.jsx)(st,{of:e,children:(0,Q.jsx)(e.component,{})})})},e.serial)),je=u?void 0:I,Me=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nn,{title:N,open:q===1?O??null:null,onBack:D?void 0:()=>u?i(`/space`):g(y??null),root:{icon:He,label:X(`nav.sources`),onOpen:()=>i(u?`/space?show=overview`:`/space`),current:!y}}),u||D?(0,Q.jsx)(`div`,{className:z(ln(xe)),children:q===0?(0,Q.jsx)($t,{entries:ee,current:void 0,onPick:()=>g(null)}):(0,Q.jsx)(`div`,{ref:f})},q):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)($t,{entries:ee,current:q===0?O:void 0,hide:q===1?O?.id:void 0,onPick:()=>{g(null),be&&O&&(i(O.to),rt().scrollTo({top:0,behavior:`smooth`}))}}),q===1?(0,Q.jsxs)(`div`,{className:`fade-in-0 slide-in-from-top-1 animate-in duration-200`,children:[(0,Q.jsx)(`div`,{className:`mx-2 my-3 h-px bg-border-soft`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Q.jsx)(ue,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-4`}),(0,Q.jsx)(`input`,{ref:M,type:`search`,value:A,onChange:e=>j(e.target.value),onKeyDown:e=>e.key===`Escape`&&j(``),"aria-label":X(`space.menuSearch`),placeholder:X(`space.menuSearch`),className:`h-8 w-full rounded-lg border border-input bg-card pr-14 pl-9 text-[0.8125rem] text-ink outline-none transition placeholder:text-ink-4 focus:border-focus focus:ring-4 focus:ring-focus-glow`}),(0,Q.jsx)(`kbd`,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 right-2 rounded border border-border-soft px-1 font-sans text-[0.6875rem] text-ink-4`,children:yi?`⌘F`:`Ctrl F`})]}),(0,Q.jsx)(`div`,{ref:f})]},y):null]})]});return(0,Q.jsx)(en.Provider,{value:ne,children:(0,Q.jsx)(`div`,{className:`animate-rise`,children:(0,Q.jsxs)(`div`,{className:z(`grid gap-6`,_!==`results`&&`md:grid-cols-[10.5rem_minmax(0,1fr)] md:gap-5 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[_===`results`?null:(0,Q.jsx)(`aside`,{className:z(`menu-scroll min-w-0 md:sticky md:top-6 md:self-start md:overflow-y-auto md:overscroll-contain`,u&&K===2&&`hidden`,u&&Se===`back`&&ln(`back`)),style:!u&&Ee?{maxHeight:Ee-48,paddingBottom:`var(--assistant-dock, 0px)`}:void 0,children:Me}),y?(0,Q.jsxs)(`div`,{className:z(`min-w-0`,u&&K<2&&`hidden`,u&&Se===`deeper`&&ln(`deeper`)),children:[u&&_!==`results`?(0,Q.jsx)(`div`,{className:`mb-3`,children:(0,Q.jsx)(sn,{label:O?.label??N,onBack:()=>i(O?.to??`/space/${y}`)})}):null,_===`data`?(0,Q.jsxs)(rn,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Q.jsx)(cn,{icon:qe,label:X(`data.all`),selected:!u&&!B,onPick:()=>Y(`all`)})}),_e.data?jt(_e.data).map(e=>(0,Q.jsx)(on,{label:e.label,children:e.items.map(e=>(0,Q.jsx)(cn,{icon:vt[e.kind],label:e.title,selected:!u&&e.key===B,onPick:()=>Y(e.key)},e.key))},e.key)):null,(0,Q.jsx)(Ci,{groups:F,current:je,onPick:ke})]}):_===`knowledge`?(0,Q.jsxs)(rn,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Q.jsx)(cn,{icon:qe,label:X(`know.all`),selected:!(u||B),onPick:()=>Y(`all`)})}),U.data?.categories.length?(0,Q.jsx)(on,{label:X(`know.categories`),children:U.data.categories.map(e=>(0,Q.jsx)(cn,{icon:wt[e.type],label:e.name,badge:(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!u&&(B===`c:${e.id}`||G.data?.category.id===e.id),onPick:()=>Y(`c:${e.id}`)},e.id))}):null,(0,Q.jsx)(Ci,{groups:F,current:u?void 0:V?.id,onPick:e=>Y(`s:${e}`)})]}):_===`skills`?(0,Q.jsxs)(rn,{children:[(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsx)(cn,{icon:qe,label:X(`skills.all`),selected:!(u||H),onPick:()=>Y(`all`)}),ge.data?.skills.map(e=>(0,Q.jsx)(cn,{icon:ut[e.mode],label:e.name,selected:!u&&H===`k:${e.id}`,onPick:()=>Y(`k:${e.id}`)},e.id))]}),(0,Q.jsx)(Ci,{groups:F,current:je,onPick:ke})]}):(0,Q.jsx)(rn,{children:(0,Q.jsx)(Ci,{groups:ie,current:je,onPick:ke})}),s&&(_===`info`||_===`brand`||_===`knowledge`)?(0,Q.jsxs)(vi,{space:s,group:_,top:!B||!!V,children:[_===`knowledge`?he?he.startsWith(`p:`)?(0,Q.jsx)(Et,{pageId:he.slice(2),onGone:()=>Y(`all`),onOpen:Y},he):he.startsWith(`t:`)?(0,Q.jsx)(Tt,{tableId:he.slice(2),onGone:()=>Y(`all`)},he):(0,Q.jsx)(Un,{spaceId:s.id,fileId:he.slice(2),readOnly:s.readOnly,onGone:()=>Y(`all`)},he):U.data?V?(0,Q.jsx)(R,{title:V.label(),hint:V.hint?.(),plain:!0,children:(0,Q.jsx)(st,{of:V,children:(0,Q.jsx)(V.component,{})})},B):B?.startsWith(`c:`)?ve?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(Ct,{spaceId:s.id,category:ve,readOnly:s.readOnly,onOpen:Y,onGone:()=>Y(`all`)}),ve.type===`choice`?null:(0,Q.jsx)(Nt,{spaceId:s.id,category:ve,categories:U.data.categories,onOpen:Y})]},B):null:B?.startsWith(`v:`)?G.data?(0,Q.jsx)(_t,{value:G.data,readOnly:s.readOnly,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[G.data.items.length?(0,Q.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:G.data.items.map(e=>(0,Q.jsx)(xt,{item:e,categories:U.data.categories.filter(e=>e.id!==G.data?.category.id),onOpen:Y},e.key))}):null,G.data.rows.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Y(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:X(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},B):null:(0,Q.jsx)(W,{id:`documents`,children:(0,Q.jsx)(kt,{spaceId:s.id,data:U.data,readOnly:s.readOnly,onOpen:Y})}):null:null,_===`info`||_===`brand`?Ae(F):null]},s.id):null,s&&_===`skills`&&S?(0,Q.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:H?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(wi,{skillId:H.slice(2),onGone:()=>Y(`all`),onOpen:Y},H)}):ge.data?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(lt,{spaceId:s.id,data:ge.data,onOpen:Y}),Ae(F)]}):ge.error?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:ge.error.message}):null}):null,s&&_===`page`&&x?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[(0,Q.jsx)(pr,{space:s},s.id),Ae(F)]}):null,s&&v?(0,Q.jsx)(st,{of:v,children:(0,Q.jsx)(tt,{part:v.id,children:(0,Q.jsx)(v.component,{})},s.id)}):null,s&&_===`data`?(0,Q.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:B?.startsWith(`t:`)?(0,Q.jsx)(Tt,{tableId:B.slice(2),onGone:()=>Y(`all`)},B):B?.startsWith(`p:`)?(0,Q.jsx)(Et,{pageId:B.slice(2),onGone:()=>Y(`all`)},B):(0,Q.jsxs)(Q.Fragment,{children:[_e.data?(0,Q.jsx)(Ot,{spaceId:s.id,data:_e.data,readOnly:s.readOnly,onOpen:Y}):null,Ae(F)]})}):null,s&&_===`results`?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[le.data?(0,Q.jsx)(vr,{data:le.data,wizardId:L,onWizard:e=>Y(e??`all`),filter:oe,onFilter:se}):null,le.isError?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:le.error.message}):null,Ae(F)]}):null,s||c?null:(0,Q.jsx)(ae,{children:X(`settings.noSpace`)})]}):s&&(!u||k===`overview`)?(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[u?(0,Q.jsx)(`div`,{className:`mb-3`,children:(0,Q.jsx)(sn,{label:X(`nav.sources`),onBack:()=>i(`/space`)})}):null,(0,Q.jsx)(br,{space:s,parts:w})]}):null]})})})}export{Ti as SpacePage};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SkillEditor-BsXTqNli.js","assets/rolldown-runtime-hePW80VL.js","assets/jsx-runtime-BNakU3Ej.js","assets/ui-CktezodE.js","assets/preload-helper-DpV6A1kQ.js","assets/i18n-0fUKyVRE.js","assets/useMutation-7_FOHoEl.js","assets/Skills-C_X1ZsKg.js","assets/circle-check-jqtsKi_b.js","assets/upload-CHGCFVZK.js","assets/code-xml-q88cSTV8.js","assets/scroll-text-2BhJO_W7.js","assets/eye-CgkvVlba.js","assets/code-editor-BpCEnf8H.js","assets/dist-EBVTpvRr.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$n as r,$t as i,A as a,B as o,Bn as s,C as c,D as l,E as u,F as d,Fn as f,G as p,Gn as m,H as h,Hn as g,In as _,Jn as v,Jt as y,Kt as b,L as x,Ln as S,M as C,N as w,O as ee,On as T,P as E,Pn as D,Qt as O,R as k,S as A,Sn as j,T as M,Tn as te,U as ne,V as N,Vn as re,W as P,Wr as ie,Xn as F,Xt as ae,Yt as I,Zt as L,_ as oe,_n as se,_r as ce,an as le,b as R,bn as ue,cn as z,dr as de,f as fe,fr as pe,g as B,gr as me,h as V,in as he,j as H,k as ge,kn as _e,lr as U,m as W,mn as G,nn as ve,on as ye,p as be,pn as K,q,qt as xe,rn as Se,rr as Ce,sn as we,sr as J,tn as Te,un as Ee,v as De,vr as Oe,w as ke,wn as Y,x as Ae,xt as je,y as Me,yr as Ne,z as Pe,zn as Fe}from"./ui-CktezodE.js";import{_ as Ie,b as Le,v as Re,y as ze}from"./Marketplace-CS7JTgiv.js";import{t as Be}from"./useMutation-7_FOHoEl.js";import{t as Ve}from"./preload-helper-DpV6A1kQ.js";import{$t as He,Dt as Ue,Et as We,Kt as Ge,Nt as Ke,Qt as qe,Ut as Je,a as Ye,c as Xe,fn as Ze,j as Qe,l as $e,m as et,n as tt,o as nt,p as rt,qt as it,rn as at,s as ot,t as st,u as ct}from"./host-Bd_bon_c.js";import{a as lt,n as ut,s as dt}from"./Skills-C_X1ZsKg.js";import{r as ft}from"./volume-2-Bw5KASy8.js";import{F as pt,I as mt,N as ht,S as gt,_ as _t,a as vt,b as yt,c as bt,d as xt,f as St,g as Ct,h as wt,i as Tt,l as Et,m as Dt,o as Ot,p as kt,r as At,s as jt,t as Mt,u as Nt,v as Pt,x as Ft,y as It}from"./PreviewPane-BOk1-yO4.js";import{t as Lt}from"./scroll-text-2BhJO_W7.js";import{t as Rt}from"./eye-CgkvVlba.js";import{b as zt,f as Bt}from"./theme-Bj3wNQR0.js";import{S as Vt,d as Ht,f as Ut,h as Wt,u as Gt}from"./session-CpYa5hwd.js";import{t as Kt}from"./phone-CjPvZ0nk.js";import{n as qt,r as Jt,t as Yt}from"./ReadOnly-8DEx-ly3.js";import{t as Xt}from"./upload-CHGCFVZK.js";import{gt as Zt,n as Qt,s as X}from"./i18n-0fUKyVRE.js";import{a as $t,c as en,f as tn,i as nn,l as rn,m as an,o as on,r as sn,s as cn,u as ln}from"./UpdateCheck-D6x7MqEl.js";import{c as un}from"./index-DOgwxnto.js";var dn={name:`at-sign`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`,key:`7n84p3`}]]};dn.node;var fn=J(dn),pn={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};pn.node;var mn=J(pn),hn={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`}]]};hn.node;var gn=J(hn),_n={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`}]]};_n.node;var vn=J(_n),yn={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`}]]};yn.node;var bn=J(yn),xn={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`]};xn.node;var Sn=J(xn),Cn={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`}]]};Cn.node;var wn=J(Cn),Tn={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`}]]};Tn.node;var En=J(Tn),Dn={name:`tablet`,size:24,node:[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,ry:`2`,key:`76otgf`}],[`line`,{x1:`12`,x2:`12.01`,y1:`18`,y2:`18`,key:`1dp563`}]]};Dn.node;var On=J(Dn),kn={name:`text-quote`,size:24,node:[[`path`,{d:`M17 5H3`,key:`1cn7zz`}],[`path`,{d:`M21 12H8`,key:`scolzb`}],[`path`,{d:`M21 19H8`,key:`13qgcb`}],[`path`,{d:`M3 12v7`,key:`1ri8j3`}]]};kn.node;var An=J(kn),Z=e(t(),1),Q=e(n(),1),jn={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function Mn({file:e,actions:t}){let[n,r]=(0,Z.useState)(e.description),i=(0,Z.useRef)(e.description),a=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Z.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,Q.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:X(o?`space.describing`:`space.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function Nn(e,t){confirm(X(`space.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function Pn({spaceId:e,file:t,small:n}){let r=o(e,t.id);if(t.mime.startsWith(`image/`))return(0,Q.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:z(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,Q.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,Q.jsx)(Fn,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,Q.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,Q.jsx)(_e,{className:i}):t.mime===`application/pdf`?(0,Q.jsx)(re,{className:i}):t.mime===`application/json`?(0,Q.jsx)(se,{className:i}):t.mime.startsWith(`model/`)?(0,Q.jsx)(gn,{className:i}):(0,Q.jsx)(Fe,{className:i}),n?null:(0,Q.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function Fn({src:e,small:t}){let[n,r]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,Q.jsx)(`div`,{className:z(`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 In=`application/x-wizards-logo`;function Ln({spaceId: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):Nn(e,r);return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,Q.jsxs)(`div`,{draggable:u&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(In,n.id),className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[n.id===c?(0,Q.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,Q.jsx)(y,{tone:`ember`,children:X(`space.logoMain`)})}):null,(0,Q.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?jn:void 0,children:[s&&n.mime.startsWith(`image/`)?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`space.preview`)}: ${n.name}`,onClick:()=>s(n),className:`block size-full cursor-zoom-in`,children:(0,Q.jsx)(Pn,{spaceId:e,file:n})}):(0,Q.jsx)(Pn,{spaceId:e,file:n}),(0,Q.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,Q.jsx)(L,{label:X(`space.preview`),onClick:()=>s(n),className:`size-8 bg-card shadow-soft`,children:(0,Q.jsx)(Rt,{className:`size-4`})}):null,l&&n.id!==c&&!r.readOnly?(0,Q.jsx)(L,{label:X(`space.logoMakeMain`),onClick:()=>l(n),className:`size-8 bg-card shadow-soft`,children:(0,Q.jsx)(Re,{className:`size-4`})}):null,u&&!r.readOnly?(0,Q.jsx)(oe,{options:u.options,value:u.current(n),onChange:e=>u.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>f(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),t===`asset`?(0,Q.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,Q.jsx)(Mn,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,Q.jsxs)(V,{accept:i,multiple:!1,onFiles:e=>o?o(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,Q.jsx)(Se,{className:`size-5`}):(0,Q.jsx)(Y,{className:`size-5`}),a]}):null]})}function Rn({kind:e,fetchUrl:t,onAdded:n,onClose:a}){let[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)([]),g=async()=>{l(!0),d(null);try{let r=await t(o.trim());r.file?(n([r.file]),a()):r.candidates?.length?(p(r.candidates),h([r.candidates[0].url])):d(X(e===`logo`?`space.logoNoneFound`:`space.assetNoneFound`))}catch(e){d(e.message)}l(!1)},_=async()=>{l(!0),d(null);let e=[];try{for(let n of m){let r=await t(n);r.file&&e.push(r.file)}}catch(e){d(e.message)}l(!1),e.length&&n(e),e.length===m.length&&a()};return(0,Q.jsx)(I,{open:!0,onClose:a,wide:f?!0:void 0,title:X(f?e===`logo`?`space.logoFound`:`space.assetFound`:e===`logo`?`space.logoFromUrl`:`space.assetFromUrl`),children:f?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(e===`logo`?`space.logoFoundHint`:`space.assetFoundHint`)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:f.map(t=>{let n=m.includes(t.url);return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>h(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:z(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:jn,children:[(0,Q.jsx)(`img`,{src:t.url,alt:``,className:z(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,Q.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(r,{className:`size-3.5`})}):null]},t.url)})}),u?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>p(null),children:X(`run.back`)}),(0,Q.jsx)(b,{busy:c,disabled:!m.length,onClick:()=>void _(),children:m.length>1?X(`space.addMany`,{n:m.length}):X(`space.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.logoUrl`)}),(0,Q.jsx)(O,{autoFocus:!0,value:o,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>s(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(e===`logo`?`space.logoUrlHint`:`space.assetUrlHint`)})]}),u?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:a,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,busy:c,disabled:!o.trim(),children:X(`run.next`)})]})]})})}function zn(e,t,n){return Ne({queryKey:[`space-file-text`,t.id,t.chars,n],queryFn:()=>q.get(`/api/studio/spaces/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function Bn(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var Vn=e=>[Bn(e),e.pages?X(`space.pages`,{n:e.pages}):null,Zt(e.size)].filter(Boolean).join(` · `),Hn=2e5;function Un({spaceId:e,fileId:t,readOnly:n,onGone:r}){let i=ie(),a=P(e),s=Dt(e),c=h(e,n),l=a.data?.files.find(e=>e.id===t),u=l?l.mime===`application/pdf`||l.mime.startsWith(`image/`):!1,[d,f]=(0,Z.useState)(null);if(!l)return a.isLoading?(0,Q.jsx)(Se,{className:`mx-auto text-ink-3`}):null;let m=d??(u?`original`:`text`),_=s.data?.items.find(e=>e.key===`f:${l.id}`),v=o(e,l.id),y=(e,t)=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":m===e,onClick:()=>f(e),className:z(`rounded-full px-3 py-1 text-[0.8125rem] transition`,m===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,Q.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Q.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:l.name}),(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:Vn(l)}),(0,Q.jsx)(`a`,{href:v,target:`_blank`,rel:`noreferrer`,"aria-label":X(`space.openOriginal`),title:X(`space.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Q.jsx)(g,{className:`size-4`})}),n?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(L,{label:X(`space.reindex`),onClick:async()=>{await c.reindex(l.id),await i.invalidateQueries({queryKey:p.knowledge(e)})},children:(0,Q.jsx)(j,{className:`size-4`})}),(0,Q.jsx)(L,{label:X(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(X(`data.confirmDelete`,{title:l.name}))&&(await c.remove(l.id),await i.invalidateQueries({queryKey:p.knowledge(e)}),r())},children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),(0,Q.jsx)(St,{spaceId:e,itemKey:`f:${l.id}`,has:_?.categories??[],originLabel:_?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,Q.jsx)(`div`,{className:`px-1`,children:(0,Q.jsx)(Mn,{file:l,actions:c})}),l.status===`failed`?(0,Q.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:l.error}):null,(0,Q.jsxs)(xe,{className:`flex flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[u?y(`original`,X(`space.original`)):null,y(`text`,X(`space.readText`))]}),m===`original`?l.mime===`application/pdf`?(0,Q.jsx)(`iframe`,{src:v,title:l.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,Q.jsx)(`img`,{src:v,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,Q.jsx)(Wn,{spaceId:e,file:l})]})]})}function Wn({spaceId:e,file:t}){let n=zn(e,t,Hn);return n.isLoading||t.status===`pending`?(0,Q.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,Q.jsx)(Se,{})}):n.data?.text?(0,Q.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,Q.jsx)(je,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:X(`space.textCut`,{shown:n.data.text.length.toLocaleString(Qt),total:n.data.chars.toLocaleString(Qt)})}):null]}):(0,Q.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:X(`space.noText`)})}var Gn=[{value:`de-du`,label:`page.lang.deDu`},{value:`de-sie`,label:`page.lang.deSie`},{value:`en`,label:`page.lang.en`}],$=`text-[0.8125rem] text-ink-3 leading-snug`,Kn=`font-mono text-[0.875rem]`,qn=e=>e.slice(e.indexOf(`.`)+1);function Jn(){let[e,t]=(0,Z.useState)(!1),n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),{copied:e,copy:e=>navigator.clipboard.writeText(e).then(()=>{t(!0),clearTimeout(n.current),n.current=setTimeout(()=>t(!1),1500)}).catch(()=>t(!1))}}function Yn(){let e=X(`page.sources`).split(/(\{brand\}|\{facts\})/);return(0,Q.jsxs)(`p`,{className:$,children:[e.map((e,t)=>e===`{brand}`?(0,Q.jsx)(U,{to:`/space/brand`,className:`text-ink underline-offset-2 hover:underline`,children:X(`space.brand`)},t):e===`{facts}`?(0,Q.jsx)(U,{to:`/space/info#facts`,className:`text-ink underline-offset-2 hover:underline`,children:X(`space.facts`)},t):e),` `,X(`page.onlyShared`)]})}function Xn({host:e,value:t,onChange:n,disabled:r}){let i=a.test(t);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex h-11 items-stretch overflow-hidden rounded-lg border border-input bg-card focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,children:[(0,Q.jsxs)(`span`,{title:`${e}/`,className:`flex max-w-[55%] items-center truncate bg-paper-2 px-3 font-mono text-[0.75rem] text-ink-3`,children:[`…`,qn(e),`/`]}),(0,Q.jsx)(`input`,{value:t,disabled:r,"aria-label":X(`page.address`),maxLength:ge.slug,onChange:e=>n(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,`-`)),className:z(`min-w-0 flex-1 bg-transparent px-3 outline-none`,Kn)})]}),(0,Q.jsx)(`p`,{className:z(`mt-1.5`,$,!i&&t&&`text-rose`),children:X(`page.addressRules`)})]})}function Zn({host:e,words:t,onChange:n,disabled:r}){return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-5 sm:grid-cols-[repeat(2,minmax(0,1fr))]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(i,{children:X(`page.title`)}),(0,Q.jsx)(O,{value:t.title,disabled:r,maxLength:ge.title,onChange:e=>n({title:e.target.value})}),(0,Q.jsx)(`p`,{className:z(`mt-1.5`,$),children:X(`page.titleHint`)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(i,{children:X(`page.address`)}),(0,Q.jsx)(Xn,{host:e,value:t.slug,disabled:r,onChange:e=>n({slug:e})}),(0,Q.jsx)(`p`,{className:z(`mt-1`,$),children:X(`page.addressChange`)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 sm:col-span-2`,children:[(0,Q.jsx)(i,{children:X(`page.headline`)}),(0,Q.jsx)(O,{value:t.headline??``,disabled:r,maxLength:ge.headline,onChange:e=>n({headline:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 sm:col-span-2`,children:[(0,Q.jsx)(i,{children:X(`page.words`)}),(0,Q.jsx)(we,{value:t.intro??``,disabled:r,minRows:3,maxLength:ge.intro,onChange:e=>n({intro:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(i,{children:X(`page.lang`)}),(0,Q.jsx)(ve,{value:t.voice,onChange:e=>n({voice:e}),options:Gn.map(e=>({value:e.value,label:X(e.label)}))}),(0,Q.jsx)(`p`,{className:z(`mt-1.5`,$),children:X(`page.langHint`)})]})]})}function Qn(e,t){if(!e.published)return X(`page.draftNote`);if(!e.shareEnabled)return X(`page.notSharedNote`);let n=e.description.trim();return t?[n,X(`page.first`)].filter(Boolean).join(` · `):n}function $n({wizard:e,first:t,on:n,disabled:r,onToggle:i,drag:a}){return(0,Q.jsxs)(`li`,{draggable:a?!0:void 0,onDragStart:a?.onDragStart,onDragOver:a?.onDragOver,onDrop:a?.onDrop,className:z(`flex items-center gap-3 border-border-soft border-t py-2.5 first:border-t-0`,!e.published&&`opacity-60`),children:[a?(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`page.moveUp`)} / ${X(`page.moveDown`)}`,onKeyDown:a.onKeyDown,className:`grid size-7 shrink-0 cursor-grab place-items-center rounded-md text-ink-4 hover:text-ink focus:text-ink`,children:(0,Q.jsx)(S,{className:`size-4`})}):(0,Q.jsx)(`span`,{className:`size-7 shrink-0`}),(0,Q.jsx)(Vt,{kind:e.avatar,costume:e.costume,size:36,interactive:!1}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium text-[0.9375rem]`,children:e.title}),(0,Q.jsx)(`p`,{className:z(`truncate`,$),children:Qn(e,t)})]}),(0,Q.jsx)(le,{checked:n,disabled:r||!e.published,label:X(`page.showOnPage`),onChange:i})]})}function er({title:e,text:t,picked:n,disabled:r,later:i,onPick:a}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":n,disabled:r||i,onClick:a,className:z(`flex min-h-20 flex-col items-start gap-1 rounded-xl px-4 py-3 text-left transition`,n?`bg-accent ring-2 ring-primary`:i?`border border-border border-dashed opacity-60`:`ring-1 ring-border-soft hover:bg-paper-2`,(r||i)&&`cursor-not-allowed`),children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e}),(0,Q.jsx)(`span`,{className:$,children:t})]})}var tr={desktop:1280,tablet:768,mobile:390},nr=`wizards.pagePreviewDevice`,rr=`wizards.pagePreviewHeight`,ir=360,ar=e=>e?640:480,or=()=>Math.max(ir,window.innerHeight-140);function sr(){try{let e=Number(localStorage.getItem(rr));return e>=ir?e:null}catch{return null}}function cr(e){try{e===null?localStorage.removeItem(rr):localStorage.setItem(rr,String(Math.round(e)))}catch{}}function lr(){try{let e=localStorage.getItem(nr);return e&&e in tr?e:`desktop`}catch{return`desktop`}}function ur(e){try{localStorage.setItem(nr,e)}catch{}}function dr({url:e,version:t,device:n}){let r=(0,Z.useRef)(null),[i,a]=(0,Z.useState)({width:0,tall:!0});(0,Z.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>a({width:e.clientWidth,tall:e.clientWidth>=640});t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let o=tr[n],[s,c]=(0,Z.useState)(sr),[l,u]=(0,Z.useState)(!1),d=(0,Z.useRef)(null),f=Math.min(s??ar(i.tall),i.width?or():9999),p=e=>{let t=Math.round(Math.min(or(),Math.max(ir,e)));return c(t),t},m=n===`mobile`,h=m?12:0,g=i.width?Math.min(1,(i.width-2*h)/o):1,_=(0,Q.jsxs)(`div`,{className:z(`relative overflow-hidden bg-paper-2`,m?`rounded-[1.5rem]`:`rounded-lg ring-1 ring-border-soft`),style:{width:Math.round(o*g),height:f},children:[i.width?(0,Q.jsx)(`iframe`,{title:X(`page.previewTitle`),src:`${e}${e.includes(`?`)?`&`:`?`}v=${t}`,tabIndex:-1,className:z(`absolute top-0 left-0 border-0`,l&&`pointer-events-none`),style:{width:o,height:Math.ceil(f/g),transform:`scale(${g})`,transformOrigin:`top left`}},t):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":X(`page.resize`),title:X(`page.resize`),onPointerDown:e=>{e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}d.current={y:e.clientY,height:f},u(!0)},onPointerMove:e=>{d.current&&p(d.current.height+e.clientY-d.current.y)},onPointerUp:e=>{d.current&&=(cr(p(d.current.height+e.clientY-d.current.y)),null),u(!1)},onPointerCancel:()=>{d.current=null,u(!1)},onDoubleClick:()=>{c(null),cr(null)},onKeyDown:e=>{(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),cr(p(f+(e.key===`ArrowDown`?24:-24))))},className:`absolute right-1 bottom-1 z-10 grid size-7 cursor-ns-resize touch-none place-items-center rounded-md bg-card/90 text-ink-3 shadow-soft ring-1 ring-border-soft hover:text-ink coarse:size-9`,children:(0,Q.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 12 12`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`M11 1 1 11M11 5 5 11M11 9 9 11`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})})})]});return(0,Q.jsx)(`div`,{ref:r,className:`flex w-full justify-center`,children:m?(0,Q.jsx)(`div`,{className:`rounded-[2.25rem] bg-ink p-3 shadow-soft`,children:_}):_})}function fr({host:e,page:t,disabled:n,save:r,onState:i}){let o=(0,Z.useRef)(t);o.current=t;let[s,c]=(0,Z.useState)(()=>({slug:t.slug,title:t.title,headline:t.headline??``,intro:t.intro??``,voice:gt(t)})),l=N(s,async e=>{if(!(a.test(e.slug)&&e.title.trim()))return;let{lang:t,form:n}=It(e.voice);await r({...o.current,slug:e.slug,title:e.title.trim(),headline:e.headline?.trim()||void 0,intro:e.intro?.trim()||void 0,lang:t,form:n})}),{state:u,error:d}=l;return(0,Z.useEffect)(()=>i(l),[u,d]),(0,Q.jsx)(Zn,{host:e,words:s,disabled:n,onChange:e=>c(t=>({...t,...e}))})}function pr({space:e}){let t=ie(),n=Wt(),i=n.data?.tenant.pagesHost??null,a=n.data?.manageUrl??null,o=e.readOnly,s=e.page,c=!!s?.on,l=Ne({queryKey:p.spaceWizards(e.id),queryFn:()=>q.get(`/api/studio/spaces/${e.id}/wizards`)}),[u,d]=(0,Z.useState)(1),[f,m]=(0,Z.useState)(lr),h=(0,Z.useRef)(s);h.current=s;let g=async n=>{await q.patch(`/api/studio/spaces/${e.id}`,{page:n}),await t.invalidateQueries({queryKey:p.spaces()}),d(e=>e+1)},_=Be({mutationFn:e=>{let t=h.current;return t?g({...t,...e}):Promise.resolve()}}),[y,x]=(0,Z.useState)({state:`idle`,error:null}),{copied:S,copy:C}=Jn(),w=l.data??[],ee=(s?.wizards??[]).map(e=>w.find(t=>t.id===e)).filter(e=>e!==void 0),T=w.filter(e=>!s?.wizards.includes(e.id)),[E,D]=(0,Z.useState)(null),O=(e,t)=>{let n=[...s?.wizards??[]];if(t<0||t>=n.length||e===t)return;let[r]=n.splice(e,1);n.splice(t,0,r),_.mutate({wizards:n})},A=(e,t)=>_.mutate({wizards:t?[...s?.wizards??[],e]:(s?.wizards??[]).filter(t=>t!==e)}),j=e.brand.name?.trim()||e.name,M=Be({mutationFn:()=>g({on:!0,slug:k(j)||`page`,title:j,...It(Qt===`de`?`de-du`:`en`),wizards:w.filter(e=>e.published&&e.shareEnabled).map(e=>e.id),examples:{}})}),te=e=>{s?_.mutate({on:e}):e&&M.mutate()},ne=_.isPending||M.isPending,N=_.error??M.error;if(!i)return(0,Q.jsx)(W,{id:`page`,children:(0,Q.jsx)(R,{title:X(`space.page`),hint:X(`page.intro`),children:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:X(`page.cloudOnly`)})})});let re=s?.slug||k(j)||`…`,P=yt(i,re),F=Ft(i,re,a),ae=(0,Q.jsxs)(`span`,{className:z(Kn,`min-w-0 truncate`),children:[(0,Q.jsxs)(`span`,{className:`text-ink-3`,children:[i,`/`]}),(0,Q.jsx)(`b`,{className:`text-ink`,children:re})]}),I=o||!s,L=(0,Q.jsxs)(xe,{className:`flex flex-col gap-2.5 p-4`,children:[(0,Q.jsxs)(`div`,{className:`@container flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:X(`page.previewTitle`)}),c?(0,Q.jsx)(Mt,{named:!0,label:X(`editor.device`),value:f,onChange:e=>{m(e),ur(e)},options:[{id:`desktop`,label:X(`editor.deviceDesk`),icon:(0,Q.jsx)(it,{className:`size-3.5`})},{id:`tablet`,label:X(`page.deviceTablet`),icon:(0,Q.jsx)(On,{className:`size-3.5`})},{id:`mobile`,label:X(`editor.devicePhone`),icon:(0,Q.jsx)(zt,{className:`size-3.5`})}]}):null]}),c?(0,Q.jsx)(dr,{url:F,version:u,device:f}):(0,Q.jsx)(`p`,{className:$,children:X(`page.previewOff`)}),c?(0,Q.jsx)(`p`,{className:$,children:X(`page.previewHint`)}):null]}),oe=(0,Q.jsxs)(xe,{className:`flex flex-col gap-3 p-4`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:X(`page.inShare`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-paper-2 px-3 py-2.5`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium text-[0.875rem]`,children:X(`share.onPage`,{space:s?.title||j})}),(0,Q.jsx)(`span`,{className:z(`block truncate font-mono`,$),children:P})]}),(0,Q.jsx)(le,{checked:!0,disabled:!0,label:X(`page.showOnPage`),onChange:()=>{}})]}),(0,Q.jsx)(`p`,{className:$,children:X(`page.inShareHint`)})]});return(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-9`,children:[(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(W,{id:`page`,children:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`px-1`,children:[(0,Q.jsx)(`h2`,{className:`font-display font-semibold text-lg leading-tight`,children:X(`space.page`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-3 leading-snug`,children:X(`page.intro`)})]}),(0,Q.jsxs)(xe,{className:`flex flex-wrap items-center gap-3 p-3 sm:pl-4`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:z(`size-2 shrink-0 rounded-full`,c?`bg-moss`:`bg-ink-4`),"aria-hidden":!0}),ae]}),(0,Q.jsxs)(`span`,{className:`flex w-full items-center gap-2 sm:w-auto sm:shrink-0`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,className:`max-sm:flex-1`,disabled:!c,onClick:()=>C(F),children:[S?(0,Q.jsx)(r,{className:`size-3.5`}):(0,Q.jsx)(v,{className:`size-3.5`}),X(S?`share.copied`:`share.copyMain`)]}),(0,Q.jsxs)(b,{size:`sm`,className:`max-sm:flex-1`,disabled:!c,onClick:()=>window.open(F,`_blank`,`noopener`),children:[X(`page.open`),` `,(0,Q.jsx)(Ze,{className:`size-3.5`})]})]})]}),(0,Q.jsxs)(R,{title:X(`page.sectionPage`),locked:o,children:[(0,Q.jsxs)(`fieldset`,{"aria-label":X(`page.sectionPage`),className:`grid min-w-0 gap-3 sm:grid-cols-[repeat(3,minmax(0,1fr))]`,children:[(0,Q.jsx)(er,{title:X(`page.whoOff`),text:X(`page.whoOffHint`),picked:!c,disabled:o||ne,onPick:()=>te(!1)}),(0,Q.jsx)(er,{title:X(`page.whoPublic`),text:X(`page.whoPublicHint`),picked:c,disabled:o||ne,onPick:()=>te(!0)}),(0,Q.jsx)(er,{title:X(`page.whoMembers`),text:X(`page.whoMembersHint`),picked:!1,later:!0,onPick:()=>{}})]}),N?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:N.message}):null]})]})}),L,(0,Q.jsx)(W,{id:`page-words`,children:(0,Q.jsx)(R,{title:X(`page.sectionWords`),hint:s?void 0:X(`page.notYet`),save:s?y:void 0,locked:I,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[s?(0,Q.jsx)(fr,{host:i,page:s,disabled:o,save:g,onState:x},`${e.id}:${s.slug}`):(0,Q.jsx)(Zn,{host:i,disabled:!0,words:{slug:re,title:j,headline:``,intro:``,voice:Qt===`de`?`de-du`:`en`},onChange:()=>{}}),(0,Q.jsxs)(`div`,{id:`page-wizards`,className:`scroll-mt-6 border-border-soft border-t pt-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:X(`page.sectionWizards`)}),(0,Q.jsx)(`span`,{className:$,children:X(`page.wizardsHint`)})]}),(0,Q.jsxs)(`ul`,{className:`mt-2 flex flex-col`,children:[ee.map((e,t)=>(0,Q.jsx)($n,{wizard:e,first:t===0,on:!0,disabled:I,onToggle:t=>A(e.id,t),drag:{onDragStart:()=>D(t),onDragOver:e=>e.preventDefault(),onDrop:()=>{E!==null&&O(E,t),D(null)},onKeyDown:e=>{(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),O(t,e.key===`ArrowUp`?t-1:t+1))}}},e.id)),T.map(e=>(0,Q.jsx)($n,{wizard:e,first:!1,on:!1,disabled:I,onToggle:t=>A(e.id,t)},e.id))]}),w.length?null:(0,Q.jsx)(`p`,{className:z(`mt-2`,$),children:X(`page.noWizards`)}),(0,Q.jsx)(`p`,{className:z(`mt-4`,$),children:X(`page.wizardsNote`)})]}),(0,Q.jsx)(Yn,{})]})})})]}),oe]})}var mr=`results-search`,hr={q:``,mode:``,days:0};function gr(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 Ne({queryKey:[`results`,e,i],queryFn:()=>q.get(`/api/studio/spaces/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function _r({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Z.useState)(r.q);return Ue({icon:ue,label:X(`space.resultsSearch`),run:()=>{let e=document.getElementById(mr);e?.scrollIntoView({block:`center`,behavior:`smooth`}),e?.focus()}}),(0,Z.useEffect)(()=>{if(a===r.q)return;let e=setTimeout(()=>i({...r,q:a}),250);return()=>clearTimeout(e)},[a,r,i]),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(ve,{value:t??``,onChange:e=>n(e||null),options:[{value:``,label:X(`space.resultsAllWizards`)},...e.wizards.filter(e=>e.results||e.id===t).map(e=>({value:e.id,label:`${e.title} (${e.results})`}))],className:`w-56 max-sm:w-full`}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,Q.jsx)(ue,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,Q.jsx)(O,{type:`search`,value:a,onChange:e=>o(e.target.value),id:mr,placeholder:X(`space.resultsSearch`),"aria-label":X(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,Q.jsx)(ve,{value:r.mode,onChange:e=>i({...r,mode:e}),options:[{value:``,label:X(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,Q.jsx)(ve,{value:String(r.days),onChange:e=>i({...r,days:Number(e)}),options:[{value:`0`,label:X(`space.resultsAnyTime`)},{value:`1`,label:X(`space.resultsDay`)},{value:`7`,label:X(`space.resultsDays`,{n:7})},{value:`30`,label:X(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function vr({data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}){let[a,o]=(0,Z.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(Qt,{dateStyle:`medium`,timeStyle:`short`});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(R,{title:t?s(t):X(`space.resultsAll`),hint:X(`space.resultsHint`),plain:!0,children:[(0,Q.jsx)(_r,{data:e,wizardId:t,onWizard:n,filter:r,onFilter:i}),e.runs.length?(0,Q.jsx)(xe,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,Q.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,X(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:X(`space.resultFiles`,{n:e.assets}),children:[(0,Q.jsx)(T,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,Q.jsx)(y,{children:X(`run.testChip`)}):(0,Q.jsxs)(y,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,Q.jsx)(xe,{children:(0,Q.jsx)(ae,{children:r.q.trim()||r.mode||r.days?X(`space.resultsNone`):X(`space.resultsEmpty`)})})]}),a?(0,Q.jsx)(At,{header:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(a.wizardId)}),a.mode===`test`?(0,Q.jsx)(y,{children:X(`run.testChip`)}):(0,Q.jsxs)(y,{tone:`live`,children:[`Live v`,a.version]})]}),onClose:()=>o(null),children:(0,Q.jsx)(Bt,{runId:a.id,compact:!0,studio:!0},a.id)}):null]})}var yr={info:`space.teaser.info`,brand:`space.teaser.brand`,knowledge:`space.teaser.knowledge`,data:`space.teaser.data`,page:`space.teaser.page`};function br({space:e,parts:t}){let n=ce(),r=P(e.id),i=Dt(e.id),a=bt(e.id);We({title:X(`space.overviewAssistantTitle`),hello:X(`space.overviewAssistantHello`),suggestions:[{label:X(`assistant.suggest.missing`)},{label:X(`assistant.suggest.readSite`),fill:!0}]});let o=r.data?.files.filter(e=>e.kind===`logo`)??[],c=o.length,l=e.brand.colors?.length??0,u=i.data?.items.length??0,d=i.data?.categories.length??0,f=a.data?.tables.length??0,p=a.data?.pages.length??0,m=t=>{let n=(...e)=>e.filter(Boolean).join(` · `);switch(t){case`info`:{let t=!!e.brand.name?.trim();return{text:n(!t&&X(`space.status.noTitle`),e.facts.length>0&&X(`space.status.facts`,{n:e.facts.length}))||X(`space.status.empty`),filled:t}}case`brand`:return r.isPending?null:{text:n(c>0&&X(`space.status.logos`,{n:c}),l>0&&X(`space.status.colors`,{n:l}))||X(`space.status.empty`),filled:c+l>0};case`knowledge`:return i.isPending?null:{text:n(u>0&&X(`space.status.entries`,{n:u}),d>0&&X(`space.status.categories`,{n:d}))||X(`space.status.empty`),filled:u>0};case`data`:return a.isPending?null:{text:n(f>0&&X(`space.status.tables`,{n:f}),p>0&&X(`space.pages`,{n:p}))||X(`space.status.empty`),filled:f+p>0};default:return null}},h=t=>{let n=`flex min-w-0 items-center gap-2 text-[0.8125rem] text-ink-2`;switch(t){case`info`:return e.brand.name?.trim()||e.facts.length?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.brand.name?.trim()?(0,Q.jsx)(`span`,{className:`truncate font-medium text-[0.875rem] text-ink`,children:e.brand.name}):null,e.facts.slice(0,3).map(e=>(0,Q.jsxs)(`span`,{className:n,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-ink-3`,children:e.label}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e.value})]},e.key))]}):null;case`brand`:return c+l||e.brand.tagline?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.brand.brandName||e.brand.tagline?(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,Q.jsx)(`span`,{className:`truncate font-medium text-[0.875rem] text-ink`,children:e.brand.brandName||e.brand.name}),e.brand.tagline?(0,Q.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-3 italic`,children:e.brand.tagline}):null]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[o.slice(0,3).map(t=>(0,Q.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center overflow-hidden rounded-lg bg-paper ring-1 ring-border-soft`,children:(0,Q.jsx)(Pn,{spaceId:e.id,file:t,small:!0})},t.id)),(0,Q.jsx)(`span`,{className:`flex flex-wrap gap-1`,children:(e.brand.colors??[]).slice(0,8).map(e=>(0,Q.jsx)(`span`,{title:`${e.name} ${e.value}`,className:`size-5 rounded-full ring-1 ring-border-soft`,style:{background:e.value}},`${e.name}${e.value}`))})]})]}):null;case`knowledge`:return u?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[i.data?.items.slice(0,3).map(e=>{let t=e.kind===`page`?re:e.kind===`table`?G:s;return(0,Q.jsxs)(`span`,{className:n,children:[(0,Q.jsx)(t,{className:`size-3.5 shrink-0 text-ink-3`}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e.title})]},e.key)}),d?(0,Q.jsx)(`span`,{className:`mt-1 flex flex-wrap gap-1`,children:i.data?.categories.slice(0,4).map(e=>(0,Q.jsx)(`span`,{className:`rounded-full bg-paper-2 px-2 py-0.5 text-[0.75rem] text-ink-3`,children:e.name},e.id))}):null]}):null;case`data`:return f+p?(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:[...(a.data?.tables??[]).map(e=>({key:`t:${e.id}`,title:e.title,rows:e.rows,Icon:G})),...(a.data?.pages??[]).map(e=>({key:`p:${e.id}`,title:e.title,rows:null,Icon:re}))].slice(0,3).map(e=>(0,Q.jsxs)(`span`,{className:n,children:[(0,Q.jsx)(e.Icon,{className:`size-3.5 shrink-0 text-ink-3`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title}),e.rows===null?null:(0,Q.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:e.rows})]},e.key))}):null;default:return null}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[(0,Q.jsx)(Qe,{}),(0,Q.jsx)(R,{title:X(`nav.sources`),hint:X(`space.overviewHint`),plain:!0,children:(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:t.map(e=>{let t=m(e.id),r=yr[e.id];return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e.to),className:`group flex min-w-0 flex-col gap-2 rounded-xl bg-card p-4 text-left shadow-soft ring-1 ring-border-soft transition hover:ring-border`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`grid size-8 shrink-0 place-items-center rounded-lg bg-paper-2 text-ember-strong`,children:(0,Q.jsx)(e.icon,{className:`size-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold text-[0.9375rem]`,children:e.label}),(0,Q.jsx)(F,{className:`size-4 text-ink-4 transition group-hover:translate-x-0.5 group-hover:text-ink-3`})]}),r?(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 leading-relaxed`,children:X(r)}):null,h(e.id)?(0,Q.jsx)(`span`,{className:`block rounded-lg bg-paper-2/50 p-3`,children:h(e.id)}):null,t?(0,Q.jsx)(`span`,{className:`mt-auto pt-1`,children:(0,Q.jsx)(y,{tone:t.filled?`live`:`warn`,children:t.text})}):null]},e.id)})})})]})}var xr=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,Sr=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),Zt(e.size)].filter(Boolean).join(` · `);function Cr({spaceId:e,file:t,actions:n,onClose:r}){let i=o(e,t.id);return(0,Q.jsxs)(I,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,Q.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:Sr(t)}),(0,Q.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":X(`space.openOriginal`),title:X(`space.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Q.jsx)(g,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,Q.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:jn,children:(0,Q.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,Q.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,Q.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(Mn,{file:t,actions:n})})]})}function wr({spaceId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,Q.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":`${X(`space.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,Q.jsx)(Pn,{spaceId:e,file:t,small:!0})}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:Sr(t)})]}),(0,Q.jsx)(Mn,{file:t,actions:n})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,Q.jsx)(L,{label:X(`space.preview`),onClick:i,children:(0,Q.jsx)(Rt,{className:`size-4`})}),r&&!n.readOnly?(0,Q.jsx)(oe,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:a,className:`hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]})]})}function Tr({section:e,onSave:t,onRemove:n,onClose:r}){let[a,o]=(0,Z.useState)(e?.title??``);return(0,Q.jsx)(I,{open:!0,onClose:r,title:X(e?`space.assetSectionRename`:`space.assetSectionAdd`),children:(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a.trim()&&(t(a.trim()),r())},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.assetSectionName`)}),(0,Q.jsx)(O,{autoFocus:!0,value:a,maxLength:80,placeholder:X(`space.assetSectionTitle`),onChange:e=>o(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,Q.jsx)(b,{variant:`danger`,onClick:n,children:X(`space.sectionRemove`)}):null,(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsx)(b,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,disabled:!a.trim(),children:X(e?`settings.save`:`space.add`)})]})]})})}function Er({spaceId:e,data:t,readOnly:n,sections:r,save:i}){let a=h(e,n),[o,s]=ne(`assets`,`cards`),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(r),[m,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),x=(0,Z.useRef)(null),S=N({assetSections:f},i),C=t.files.filter(e=>e.kind===`asset`),w=new Map(C.map(e=>[e.id,e])),ee=new Set(f.flatMap(e=>e.assets)),T=f.find(e=>e.id===m)??null,E=T?T.assets.map(e=>w.get(e)).filter(e=>!!e):C.filter(e=>!ee.has(e.id)),D=C.find(e=>e.id===u),O=c.trim().toLowerCase(),k=O?E.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(O)):E,j=(e,t)=>p(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),M=async e=>{let t=T?.id??null;for(let n of await a.upload(`asset`,e))j(n.id,t)},re=e=>{confirm(X(`space.removeConfirm`,{name:e.name}))&&(a.remove(e.id),j(e.id,null))},P=f.length?{options:[{value:``,label:X(`space.assetsGeneral`)},...f.map(e=>({value:e.id,label:e.title||X(`space.sectionUntitled`)}))],current:e=>f.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>j(e.id,t||null)}:void 0,ie=[{label:X(`space.assetUpload`),icon:(0,Q.jsx)(Xt,{className:`size-4 shrink-0`}),onPick:()=>x.current?.click()},{label:X(`space.assetFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>b(!0)},...f.length<H.logoSections?[{label:X(`space.assetSectionAdd`),icon:(0,Q.jsx)(bn,{className:`size-4 shrink-0`}),onPick:()=>v(`new`)}]:[]],F=f.length||C.length?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[f.length?(0,Q.jsx)(ye,{value:m,onChange:e=>{g(e),l(``)},label:X(`space.assets`),options:[{id:``,label:X(`space.assetsGeneral`)},...f.map(e=>({id:e.id,label:e.title||X(`space.sectionUntitled`)}))]}):null,T&&!n?(0,Q.jsx)(L,{label:X(`space.assetSectionRename`),onClick:()=>v(`current`),children:(0,Q.jsx)(te,{className:`size-4`})}):null]}),E.length?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,Q.jsx)(Me,{value:c,onChange:l,placeholder:X(`space.assetSearch`)})}),(0,Q.jsx)(L,{label:X(o===`list`?`space.viewCards`:`space.viewList`),onClick:s,children:o===`list`?(0,Q.jsx)(qe,{className:`size-4`}):(0,Q.jsx)(En,{className:`size-4`})})]}):null]}):null;return(0,Q.jsxs)(R,{title:X(`space.assets`),hint:X(`space.assetsHint`),save:S,tabs:F,action:n?null:(0,Q.jsx)(fe,{entries:ie}),children:[(0,Q.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:xr,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&M(t)}}),k.length?o===`cards`?(0,Q.jsx)(Ln,{spaceId:e,kind:`asset`,files:k,actions:a,moveTo:P,onRemove:re,onPreview:e=>d(e.id)}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:k.map(t=>(0,Q.jsx)(wr,{spaceId:e,file:t,actions:a,moveTo:P,onPreview:()=>d(t.id),onRemove:()=>re(t)},t.id))}):E.length?null:n?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`space.staysLocal`)}):(0,Q.jsxs)(V,{accept:xr,onFiles:e=>void M(e),className:`h-16 w-full`,children:[a.busy?(0,Q.jsx)(Se,{className:`size-4`}):(0,Q.jsx)(Xt,{className:`size-4`}),X(`space.drop`),` `,(0,Q.jsx)(`span`,{className:`underline`,children:X(`space.assetAdd`)})]}),a.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error}):null,D?(0,Q.jsx)(Cr,{spaceId:e,file:D,actions:a,onClose:()=>d(null)}):null,_?(0,Q.jsx)(Tr,{section:_===`current`?T:null,onClose:()=>v(null),onSave:e=>{if(_===`current`&&T)p(t=>t.map(t=>t.id===T.id?{...t,title:e}:t));else{let t=A();p(n=>[...n,{id:t,title:e,assets:[]}]),g(t)}},onRemove:_===`current`&&T?()=>{(!T.assets.length||confirm(X(`space.assetSectionRemoveConfirm`,{name:T.title})))&&(p(e=>e.filter(e=>e.id!==T.id)),g(``),v(null))}:void 0}):null,y?(0,Q.jsx)(Rn,{kind:`asset`,onClose:()=>b(!1),fetchUrl:e=>a.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)j(t.id,T?.id??null)}}):null]})}var Dr=/^#[0-9a-fA-F]{6}$/;async function Or(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 kr={linear:`space.gradientLinear`,radial:`space.gradientRadial`,conic:`space.gradientConic`};function Ar({spaceId:e,gradient:t,isNew:n,brand:r,onSave:a,onClose:o}){let[s,c]=(0,Z.useState)(t),[l,u]=(0,Z.useState)(d(t)),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(!n),C=e=>{c(e),u(d(e)),p(!1)},w=(e,t)=>C({...s,stops:s.stops.map((n,r)=>r===e?{...n,...t}:n)}),T=e=>{let t=[...s.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));C({...s,stops:[...s.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},E=async()=>{_(!0),y(null);try{let{gradient:t}=await q.post(`/api/studio/spaces/${e}/gradients/describe`,{text:m.trim(),...x?{gradient:{name:s.name,type:s.type,angle:s.angle,stops:s.stops}}:{}});C({...s,...t,name:s.name.trim()?s.name:t.name}),h(``),S(!0)}catch(e){y(e.message)}_(!1)};return(0,Q.jsx)(I,{open:!0,onClose:o,wide:!0,title:X(n?`space.gradientNew`:`space.gradientEdit`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m.trim()&&!g&&E()},children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(O,{"data-autofocus":n||void 0,value:m,maxLength:1e3,"aria-label":X(`space.gradientDescribe`),placeholder:X(x?`space.gradientDescribeChange`:`space.gradientDescribeNew`),onChange:e=>h(e.target.value),className:`min-w-0 flex-1`}),(0,Q.jsxs)(b,{type:`submit`,variant:`secondary`,busy:g,disabled:!m.trim(),children:[(0,Q.jsx)(se,{className:`size-4`}),X(x?`space.gradientDescribeApply`:`space.gradientDescribeMake`)]})]}),(0,Q.jsx)(`p`,{className:z(`mt-1.5 text-[0.8125rem]`,v?`text-rose`:`text-ink-3`),children:v??X(`space.gradientDescribeHint`)})]}),(0,Q.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:d(s)}}),(0,Q.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.gradientName`)}),(0,Q.jsx)(O,{value:s.name,maxLength:80,placeholder:X(`space.gradientNamePlaceholder`),onChange:e=>c({...s,name:e.target.value})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.fillUseLabel`)}),(0,Q.jsx)(O,{value:s.description??``,maxLength:400,placeholder:X(`space.gradientUse`),onChange:e=>c({...s,description:e.target.value})})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.gradientType`)}),(0,Q.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:ee.map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":s.type===e,onClick:()=>C({...s,type:e}),className:z(`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:X(kr[e])},e))})]}),s.type===`radial`?null:(0,Q.jsxs)(`div`,{className:`min-w-56`,children:[(0,Q.jsx)(i,{children:X(`space.gradientAngle`)}),(0,Q.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Q.jsx)(`input`,{type:`range`,min:0,max:360,value:s.angle,"aria-label":X(`space.gradientAngle`),onChange:e=>C({...s,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,Q.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(s.angle),`°`]})]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.gradientStops`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:s.stops.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(he,{value:Dr.test(e.color)?e.color:`#888888`,onChange:e=>w(t,{color:e.target.value})}),(0,Q.jsx)(O,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();Dr.test(n)&&w(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,Q.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":X(`space.gradientAt`),onChange:e=>w(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,Q.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,Q.jsx)(L,{label:X(`space.remove`),disabled:s.stops.length<=2,onClick:()=>C({...s,stops:s.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]},t))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[s.stops.length<12?(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>T(),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.gradientStopAdd`)]}):null,r.length&&s.stops.length<12?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:X(`space.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,Q.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>T(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:`CSS`}),(0,Q.jsx)(O,{value:l,spellCheck:!1,onChange:e=>{u(e.target.value);let t=Pe(e.target.value);p(!t),t&&c({...s,...t})},className:`font-mono text-[0.8125rem]`}),(0,Q.jsx)(`p`,{className:z(`mt-1.5 text-[0.8125rem]`,f?`text-rose`:`text-ink-3`),children:X(f?`space.gradientCssError`:`space.gradientCssHint`)})]}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:o,children:X(`common.cancel`)}),(0,Q.jsx)(b,{onClick:()=>{a(s),o()},children:X(`settings.save`)})]})]})})}var jr=`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`,Mr=`size-8 bg-card shadow-soft hover:bg-card`;function Nr({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,Q.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,Q.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,Q.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,Q.jsx)(B,{value:e,label:X(`space.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,Q.jsx)(B,{value:n??``,label:X(`space.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function Pr({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=d(e),[o,s]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:t,"aria-label":X(`space.gradientEdit`),onClick:n,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,Q.jsxs)(`div`,{className:jr,children:[(0,Q.jsx)(L,{label:X(o?`space.gradientCopied`:`space.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:Mr,children:(0,Q.jsx)(v,{className:`size-4`})}),(0,Q.jsx)(L,{label:X(`space.download`),onClick:()=>void Or(e,e.name),className:Mr,children:(0,Q.jsx)(m,{className:`size-4`})}),t?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:i,className:z(Mr,`hover:text-rose`),children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),(0,Q.jsx)(Nr,{name:e.name,namePlaceholder:X(`space.gradientName`),description:e.description,usePlaceholder:X(`space.gradientUse`),readOnly:t,onChange:r})]})}function Fr(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function Ir({spaceId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:s}){let c=o(e,t.file);return(0,Q.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:r,"aria-label":X(`space.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:Fr(c,t.tile)}),(0,Q.jsxs)(`div`,{className:jr,children:[(0,Q.jsx)(`a`,{href:c,download:n,"aria-label":X(`space.download`),title:X(`space.download`),className:z(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,Mr),children:(0,Q.jsx)(m,{className:`size-4`})}),r?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:s,className:z(Mr,`hover:text-rose`),children:(0,Q.jsx)(K,{className:`size-4`})})]})]}),(0,Q.jsx)(Nr,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:X(`space.patternUse`),readOnly:r,onChange:a})]})}function Lr({spaceId:e,pattern:t,isNew:n,fileName:r,busy:a,error:s,upload:c,removeFile:l,onSave:u,onClose:d}){let[p,m]=(0,Z.useState)(t),[h,g]=(0,Z.useState)([]),_=async e=>{let t=e[0];if(!t)return;let n=await c(t);n&&(g(e=>[...e,n.id]),m(e=>({...e,file:n.id,name:e.name||n.name.replace(/\.[^.]+$/,``)})))},v=()=>{for(let e of h)l(e);d()};return(0,Q.jsx)(I,{open:!0,onClose:v,wide:!0,title:X(n?`space.patternNew`:`space.patternEdit`),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p.file?(0,Q.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:Fr(o(e,p.file),p.tile),children:(0,Q.jsxs)(V,{accept:`image/*`,multiple:!1,onFiles:e=>void _(e),className:`absolute right-2 bottom-2 h-9 border-solid bg-card px-3.5 text-ink-2 shadow-soft`,children:[a?(0,Q.jsx)(Se,{className:`size-4`}):(0,Q.jsx)(f,{className:`size-4`}),X(`space.patternReplace`)]})}):(0,Q.jsxs)(V,{accept:`image/*`,multiple:!1,onFiles:e=>void _(e),className:`h-40 flex-col`,children:[a?(0,Q.jsx)(Se,{className:`size-5`}):(0,Q.jsx)(f,{className:`size-5`}),X(`space.patternPick`)]}),(0,Q.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.patternName`)}),(0,Q.jsx)(O,{value:p.name,maxLength:80,placeholder:p.file?r(p.file):X(`space.patternNamePlaceholder`),onChange:e=>m({...p,name:e.target.value})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.fillUseLabel`)}),(0,Q.jsx)(O,{value:p.description??``,maxLength:400,placeholder:X(`space.patternUse`),onChange:e=>m({...p,description:e.target.value})})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.patternShow`)}),(0,Q.jsx)(`div`,{className:`flex w-fit gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:[!1,!0].map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":!!p.tile===e,onClick:()=>m({...p,tile:e||void 0}),className:z(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,!!p.tile===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:X(e?`space.patternTile`:`space.patternFill`)},String(e)))})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[s?(0,Q.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:s}):null,(0,Q.jsx)(b,{variant:`ghost`,onClick:v,children:X(`common.cancel`)}),(0,Q.jsx)(b,{disabled:!p.file||a,onClick:()=>{for(let e of h.filter(e=>e!==p.file))l(e);t.file&&t.file!==p.file&&l(t.file),u({...p,name:p.name.trim(),description:p.description?.trim()||void 0}),d()},children:X(n?`space.add`:`settings.save`)})]})]})})}var Rr=/^#[0-9a-fA-F]{6}$/;function zr({spaceId:e,onAdd:t,onClose:n}){let[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)([]),h=async()=>{c(!0),u(null);try{let{colors:t}=await q.post(`/api/studio/spaces/${e}/colors/scan`,{url:a.trim()});t.length?(f(t),m([])):u(X(`space.colorsNoneFound`))}catch(e){u(e.message)}c(!1)};return(0,Q.jsx)(I,{open:!0,onClose:n,wide:d?!0:void 0,title:X(d?`space.colorsFound`:`space.colorsFromUrl`),children:d?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`space.colorsFoundHint`)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:d.map(e=>{let t=p.includes(e.value);return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>m(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:z(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,Q.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,Q.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,Q.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,Q.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(r,{className:`size-3.5`})}):null]},e.value)})}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>f(null),children:X(`run.back`)}),(0,Q.jsx)(b,{disabled:!p.length,onClick:()=>{t(d.filter(e=>p.includes(e.value))),n()},children:p.length>1?X(`space.addMany`,{n:p.length}):X(`space.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.logoUrl`)}),(0,Q.jsx)(O,{autoFocus:!0,value:a,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>o(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.colorsUrlHint`)})]}),l?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,busy:s,disabled:!a.trim(),children:X(`run.next`)})]})]})})}function Br({spaceId:e,data:t,colors:n,sections:r,gradients:i,patterns:a,rules:o,sectioned:s,ruled:l,save:u,readOnly:d}){let[f,p]=(0,Z.useState)(()=>n.map(e=>({...e,id:A()}))),[m,g]=(0,Z.useState)(r),[_,v]=(0,Z.useState)(i),[b,x]=(0,Z.useState)(a),[S,C]=(0,Z.useState)(null),[w,ee]=(0,Z.useState)(null),T=h(e,d),E=c(o),[D,k]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(null),[te,ne]=(0,Z.useState)(!1),re=N({colors:f.filter(e=>Rr.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:m,gradients:_,patterns:b,colorRules:E.rules},u),P=s?m:[],ie=P.filter(e=>(e.kind??`colors`)===`colors`),F=e=>ie.some(t=>t.id===e.section),ae=f.filter(e=>!F(e)),I=(ae[0]??f[0])?.id,se=(e,t)=>p(n=>n.map(n=>n.id===e?{...n,...t}:n)),ce=e=>p(t=>[...t,...e.map(e=>({...e,id:A()}))].slice(0,H.colors)),le=[{value:``,label:X(`space.sectionStandard`)},...ie.map(e=>({value:e.id,label:e.title||X(`space.sectionUntitled`)}))],ue=(e,t)=>{let n=A();k(n),g(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},z=e=>({id:A(),name:``,section:e,type:`linear`,angle:90,stops:[{color:f[0]?.value&&Rr.test(f[0].value)?f[0].value:`#4b73ff`,at:0},{color:f[1]?.value&&Rr.test(f[1].value)?f[1].value:`#ff6d1b`,at:100}]}),de=e=>t.files.find(t=>t.id===e)?.name??`pattern`,pe=[...f.length<H.colors?[{label:X(`space.colorNew`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>me()},{label:X(`space.colorsFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>ne(!0)}]:[],...s&&m.length<H.logoSections?[{label:X(`space.colorSectionAdd`),icon:(0,Q.jsx)(bn,{className:`size-4 shrink-0`}),onPick:()=>ue(`colors`,``)},{label:X(`space.gradientSectionAdd`),icon:(0,Q.jsx)(mn,{className:`size-4 shrink-0`}),onPick:()=>ue(`gradients`,X(`space.gradientSectionTitle`))},{label:X(`space.patternSectionAdd`),icon:(0,Q.jsx)(Sn,{className:`size-4 shrink-0`}),onPick:()=>ue(`patterns`,X(`space.patternSectionTitle`))}]:[],...!l||E.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>E.add()}]],B=e=>(0,Q.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,Q.jsx)(he,{value:Rr.test(e.value)?e.value:`#888888`,onChange:t=>se(e.id,{value:t.target.value})}),(0,Q.jsx)(O,{value:e.name,autoFocus:e.id===j,placeholder:X(`space.colorName`),maxLength:120,onChange:t=>se(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,Q.jsx)(O,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>se(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,Q.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===I?(0,Q.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,Q.jsx)(y,{tone:`ember`,children:X(`space.colorAccent`)})}):d?null:(0,Q.jsx)(L,{label:X(`space.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,Q.jsx)(Ce,{className:`size-4`})}),d||!ie.length?null:(0,Q.jsx)(oe,{options:le,value:F(e)?e.section??``:``,onChange:t=>se(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),d?null:(0,Q.jsx)(L,{label:X(`space.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,Q.jsx)(K,{className:`size-4`})})]})]},e.id),me=e=>{let t=A();M(t),p(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,Q.jsxs)(R,{title:X(`space.colors`),hint:X(`space.colorsHint`),save:re,locked:d,action:d?null:(0,Q.jsx)(fe,{entries:pe}),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[ae.length?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:ae.map(B)}),d?null:(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.colorUse`)})]}):f.length?null:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`space.colorsEmpty`)}),P.map(t=>{let n=t.kind??`colors`,r=f.filter(e=>e.section===t.id),i=_.filter(e=>e.section===t.id),a=b.filter(e=>e.section===t.id),o=n===`gradients`?i.length:n===`patterns`?a.length:r.length;return(0,Q.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,Q.jsx)(Ae,{title:t.title,titlePlaceholder:X(n===`gradients`?`space.gradientSectionTitlePlaceholder`:n===`patterns`?`space.patternSectionTitlePlaceholder`:`space.colorSectionTitle`),kind:n===`gradients`?{icon:(0,Q.jsx)(mn,{}),label:X(`space.kindGradients`)}:n===`patterns`?{icon:(0,Q.jsx)(Sn,{}),label:X(`space.kindPatterns`)}:{icon:(0,Q.jsx)(Ge,{}),label:X(`space.kindColors`)},autoFocus:D===t.id,readOnly:d,onChange:e=>g(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!o||confirm(X(n===`colors`?`space.colorSectionRemoveConfirm`:`space.fillSectionRemoveConfirm`,{name:t.title||X(`space.sectionUntitled`)}))){g(e=>e.filter(e=>e.id!==t.id)),p(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),v(e=>e.filter(e=>e.section!==t.id));for(let e of a)T.remove(e.file);x(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[i.map(e=>(0,Q.jsx)(Pr,{gradient:e,readOnly:d,onEdit:()=>C(e),onChange:t=>v(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>v(t=>t.filter(t=>t.id!==e.id))},e.id)),d||_.length>=H.gradients?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>C(z(t.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-5`}),X(`space.gradientAdd`)]})]}):n===`patterns`?(0,Q.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(t=>(0,Q.jsx)(Ir,{spaceId:e,pattern:t,fileName:de(t.file),readOnly:d,onEdit:()=>ee(t),onChange:e=>x(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{T.remove(t.file),x(e=>e.filter(e=>e.id!==t.id))}},t.id)),d||b.length>=H.files.pattern?null:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>ee({id:A(),name:``,section:t.id,file:``}),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-5`}),X(`space.patternAdd`)]})]}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(B),d||f.length>=H.colors?null:(0,Q.jsx)(be,{label:X(`space.colorAdd`),onClick:()=>me(t.id)})]})]},t.id)}),l?(0,Q.jsx)(De,{rules:E,placeholder:X(`space.colorRulePlaceholder`),readOnly:d}):null]}),T.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:T.error}):null,S?(0,Q.jsx)(Ar,{spaceId:e,gradient:S,isNew:!_.some(e=>e.id===S.id),brand:f.filter(e=>Rr.test(e.value)),onClose:()=>C(null),onSave:e=>v(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,w?(0,Q.jsx)(Lr,{spaceId:e,pattern:w,isNew:!b.some(e=>e.id===w.id),fileName:de,busy:T.busy,error:T.error,upload:async e=>(await T.upload(`pattern`,[e]))[0]??null,removeFile:e=>void T.remove(e),onClose:()=>ee(null),onSave:e=>x(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,te?(0,Q.jsx)(zr,{spaceId:e,onClose:()=>ne(!1),onAdd:ce}):null]})}var Vr=e=>/^(ja|yes|true)$/i.test(e.trim()),Hr={text:Ie,longtext:Jt,number:pt,date:mt,url:D,email:un,phone:Kt,boolean:ht};function Ur({type:e,detected:t,onChange:n}){let[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),c=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!i)return;let e=e=>{c.current?.contains(e.target)||a(!1)},t=e=>e.key===`Escape`&&a(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let l=Hr[e??t],u=`${X(`space.factType`)}: ${X(`space.type.${e??t}`)}`,d=`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`,f=e=>{n(e),a(!1)};return(0,Q.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":u,title:u,"aria-haspopup":`menu`,"aria-expanded":i,onClick:e=>{s(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),a(e=>!e)},className:z(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,i?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,Q.jsx)(l,{className:`size-4`})}),i?(0,Q.jsxs)(`div`,{role:`menu`,className:z(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,o?`bottom-12`:`top-12`),children:[(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:d,onClick:()=>f(void 0),children:[(0,Q.jsx)(Ee,{className:`size-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:X(`space.factAuto`)}),(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:X(`space.type.${t}`)}),(0,Q.jsx)(r,{className:z(`size-4 shrink-0`,e&&`invisible`)})]}),(0,Q.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),M.map(t=>{let n=Hr[t];return(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:d,onClick:()=>f(t),children:[(0,Q.jsx)(n,{className:`size-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:X(`space.type.${t}`)}),(0,Q.jsx)(r,{className:z(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Wr({facts:e,save:t,readOnly:n}){let r=(0,Z.useRef)(0),i=(0,Z.useRef)(null),[a,o]=(0,Z.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),s=N(a.filter(e=>e.key&&e.label.trim()).map(({key:e,label:t,value:n,type:r})=>({key:e,label:t.trim(),value:n,...r?{type:r}:{}})),t),c=(e,t)=>o(n=>n.map(n=>n.id===e?{...n,...t}:n)),l=(e,t,n=!1)=>{let a=`f${r.current++}`;i.current=`${a}:${t}`;let s={id:a,key:``,label:``,value:``,...e};o(e=>n?[s,...e]:[...e,s])},u=e=>t=>{t&&i.current===e&&(i.current=null,t.focus())},d=ke.filter(e=>!a.some(t=>t.key===e));return(0,Q.jsxs)(R,{title:X(`space.facts`),hint:X(`space.factsHint`),save:s,locked:n,action:a.length<H.facts&&!n?(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>l({},`label`,!0),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.factAdd`)]}):null,children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>{let t=C(e.value),r=e.type??t;return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,Q.jsx)(O,{ref:u(`${e.id}:label`),value:e.label,placeholder:X(`space.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>c(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&c(e.id,{key:w(e.label,a.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,Q.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Q.jsx)(le,{checked:Vr(e.value),label:e.label,onChange:t=>c(e.id,{value:X(t?`space.yes`:`space.no`)})}),(0,Q.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Vr(e.value)?X(`space.yes`):X(`space.no`)})]}):(0,Q.jsx)(we,{ref:u(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:X(`space.factValue`),onChange:t=>c(e.id,{value:t.target.value}),className:`min-h-11`}),(0,Q.jsx)(Ur,{type:e.type,detected:t,onChange:t=>c(e.id,{type:t})}),n?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>o(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]},e.id)})}),a.length<H.facts&&!n?(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${a.length?`mt-4`:``}`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>l({},`label`),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.factAdd`)]}),d.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l({key:e,label:X(`fact.${e}`)},`value`),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-3.5`}),` `,X(`fact.${e}`)]},e))]}):null]})}var Gr=[{label:`Website`,placeholder:`https://…`},{label:`LinkedIn`,placeholder:`linkedin.com/company/…`},{label:`Instagram`,placeholder:`instagram.com/…`},{label:`Facebook`,placeholder:`facebook.com/…`},{label:`YouTube`,placeholder:`youtube.com/@…`},{label:`TikTok`,placeholder:`tiktok.com/@…`},{label:`X`,placeholder:`x.com/…`}],Kr=e=>e===`Website`?ft:Gr.some(t=>t.label===e)?fn:D;function qr({links:e,readOnly:t,save:n}){let[r,i]=(0,Z.useState)(e),a=(0,Z.useRef)(null),o=N(r.map(e=>({...e,label:e.label.trim(),url:e.url.trim()})).filter(e=>e.url),n),s=(e,t)=>i(n=>n.map(n=>n.id===e?{...n,...t}:n)),c=e=>{let t=A();a.current=`${t}:${e?`url`:`label`}`,i(n=>[...n,{id:t,label:e,url:``}])},l=e=>t=>{t&&a.current===e&&(a.current=null,t.focus())},u=Gr.filter(e=>!r.some(t=>t.label===e.label)),d=r.length>=H.links,f=[...u.map(e=>{let t=Kr(e.label);return{label:e.label,icon:(0,Q.jsx)(t,{className:`size-4 shrink-0`}),onPick:()=>c(e.label)}}),{label:X(`space.links.own`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>c(``)}];return(0,Q.jsxs)(R,{title:X(`space.links`),hint:X(`space.linksHint`),save:o,locked:t,action:t||d?null:(0,Q.jsx)(fe,{entries:f}),children:[(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:r.map(e=>{let n=Kr(e.label);return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 gap-y-2 sm:grid-cols-[auto_minmax(0,2fr)_minmax(0,3fr)_auto]`,children:[(0,Q.jsx)(`span`,{className:`grid size-11 place-items-center text-ink-3`,children:(0,Q.jsx)(n,{className:`size-4`})}),(0,Q.jsx)(O,{ref:l(`${e.id}:label`),value:e.label,maxLength:80,readOnly:t,placeholder:X(`space.links.label`),onChange:t=>s(e.id,{label:t.target.value}),className:`max-sm:col-span-1 max-sm:font-medium`}),(0,Q.jsx)(O,{ref:l(`${e.id}:url`),value:e.url,maxLength:600,readOnly:t,inputMode:`url`,placeholder:Gr.find(t=>t.label===e.label)?.placeholder??`https://…`,onChange:t=>s(e.id,{url:t.target.value}),className:`max-sm:col-span-2 max-sm:col-start-2 max-sm:row-start-2`}),t?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>i(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose max-sm:col-start-3 max-sm:row-start-1`,children:(0,Q.jsx)(K,{className:`size-4`})})]},e.id)})}),t||d?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${r.length?`mt-4`:``}`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>c(``),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.links.own`)]}),u.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(e.label),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-3.5`}),` `,e.label]},e.label))]})]})}function Jr({onLogo:e,children:t,className:n}){let[r,i]=(0,Z.useState)(!1);return e?(0,Q.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(In);i(!1),n&&(t.preventDefault(),e(n))},className:z(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,Q.jsx)(`div`,{className:n,children:t})}function Yr({spaceId:e,data:t,readOnly:n,sections:r,rules:i,sectioned:a,ruled:o,save:s}){let l=h(e,n),[u,d]=(0,Z.useState)(r),f=c(i),[p,m]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(null),y=N({logoSections:u,logoRules:f.rules},s),b=t.files.filter(e=>e.kind===`logo`),S=new Map(b.map(e=>[e.id,e])),C=a?u:[],w=new Set(C.flatMap(e=>e.logos)),ee=b.filter(e=>!w.has(e.id)),T=x(b,u)?.id,E=(e,t)=>d(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),D=(e,t)=>d(n=>n.map(n=>n.id===e?{...n,...t}:n)),O=async(e,t)=>{let n=await l.upload(`logo`,e);for(let e of n)E(e.id,t)},k=C.length?{options:[{value:``,label:X(`space.sectionStandard`)},...C.map(e=>({value:e.id,label:e.title||X(`space.sectionUntitled`)}))],current:e=>C.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>E(e.id,t||null)}:void 0,j=(t,n,r)=>(0,Q.jsx)(Ln,{spaceId:e,kind:`logo`,files:t,actions:l,accept:`image/*`,addLabel:r?X(`space.logoAdd`):void 0,onUpload:e=>void O(e,n),mainId:T,onMakeMain:e=>{E(e.id,null),l.order(`logo`,[e.id,...b.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:k,onRemove:e=>{confirm(X(`space.removeConfirm`,{name:e.name}))&&(l.remove(e.id),E(e.id,null))}}),M=n?void 0:e=>t=>E(t,e),te=[{label:X(`space.logoUpload`),icon:(0,Q.jsx)(Xt,{className:`size-4 shrink-0`}),onPick:()=>v.current?.click()},{label:X(`space.logoFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>_(!0)},...a&&u.length<H.logoSections?[{label:X(`space.logoSectionAdd`),icon:(0,Q.jsx)(bn,{className:`size-4 shrink-0`}),onPick:()=>{let e=A();m(e),d(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!o||f.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,Q.jsxs)(R,{title:X(`space.logos`),hint:X(`space.logosHint`),save:y,action:n?null:(0,Q.jsx)(fe,{entries:te}),children:[(0,Q.jsx)(`input`,{ref:v,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&&O(t,null)}}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Q.jsx)(Jr,{onLogo:M?.(null),children:j(ee,null,!0)}),C.map(e=>(0,Q.jsx)(`div`,{className:`group/section`,children:(0,Q.jsxs)(Jr,{onLogo:M?.(e.id),className:`flex flex-col gap-3`,children:[(0,Q.jsx)(Ae,{title:e.title,description:e.description,titlePlaceholder:X(`space.logoSectionTitle`),descriptionPlaceholder:X(`space.logoSectionUse`),autoFocus:p===e.id,readOnly:n,onChange:t=>D(e.id,t),onRemove:()=>{(!e.logos.length||confirm(X(`space.logoSectionRemoveConfirm`,{name:e.title||X(`space.sectionUntitled`)})))&&d(t=>t.filter(t=>t.id!==e.id))}}),j(e.logos.map(e=>S.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),o?(0,Q.jsx)(De,{rules:f,placeholder:X(`space.logoRulePlaceholder`),readOnly:n}):null]}),l.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:l.error}):null,g?(0,Q.jsx)(Rn,{kind:`logo`,onClose:()=>_(!1),fetchUrl:e=>l.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)E(t.id,null)}}):null]})}var Xr=e=>URL.canParse(e)?new URL(e).host:e;async function Zr(e,t){let n=E({family:t,source:{url:e}});if(!n)return`down`;if(n.stylesheet)return await Qr(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 Qr(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 $r(e,t){let n=e.source;if(!n)return X(`space.fontSourceNone`);if(`file`in n){let e=t.find(e=>e.id===n.file)?.name??``;return X(`space.fontSourceFile`,{name:e})}return X(`space.fontSourceUrl`,{host:Xr(n.url)})}function ei({spaceId:e,font:t,onSave:n,onClose:r}){let a=(P(e).data?.files??[]).filter(e=>e.mime.startsWith(`font/`)),o=h(e),s=(0,Z.useRef)(null),[c,l]=(0,Z.useState)(t.source&&`url`in t.source?`url`:`file`),[u,d]=(0,Z.useState)(t.source&&`file`in t.source?t.source.file:``),[f,p]=(0,Z.useState)(t.source&&`url`in t.source?t.source.url:``),[m,g]=(0,Z.useState)(t.source&&`url`in t.source?{url:t.source.url,result:`ok`}:null),[_,v]=(0,Z.useState)(!1),[y,x]=(0,Z.useState)(t.license??``),[S,C]=(0,Z.useState)(!1),w=f.trim(),ee=async()=>{v(!0),g({url:w,result:await Zr(w,t.family.trim())}),v(!1)},T=c===`file`?u?{file:u}:null:m?.url===w&&m.result===`ok`?{url:w}:null,E=m?.url===w?m.result:null;return(0,Q.jsx)(I,{open:!0,onClose:r,title:X(`space.fontSourceTitle`,{family:t.family}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`space.fontSourceHint`)}),(0,Q.jsx)(Te,{value:c,options:[`file`,`url`],label:e=>X(`space.fontSourceKind.${e}`),onChange:e=>l(e)}),c===`file`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.fontSourceFiles`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:a.map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":u===e.id,onClick:()=>d(e.id),className:z(`rounded-lg px-3 py-2 text-left text-[0.875rem] ring-1 transition`,u===e.id?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:e.name},e.id))}),(0,Q.jsx)(`input`,{ref:s,type:`file`,accept:`.woff2,.woff,.ttf,.otf`,className:`hidden`,onChange:async e=>{let t=[...e.target.files??[]];e.target.value=``;let[n]=await o.upload(`asset`,t);n&&d(n.id)}}),(0,Q.jsxs)(b,{variant:`ghost`,className:`mt-2`,busy:o.busy,onClick:()=>s.current?.click(),children:[(0,Q.jsx)(Xt,{className:`size-4`}),X(`space.fontSourceUpload`)]}),o.error?(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-rose`,children:o.error}):null]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),ee()},children:[(0,Q.jsx)(i,{children:X(`space.fontSourceUrlLabel`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(O,{value:f,inputMode:`url`,placeholder:X(`space.fontSourceUrlPlaceholder`),onChange:e=>p(e.target.value)}),(0,Q.jsx)(b,{type:`submit`,variant:`ghost`,busy:_,disabled:!w.startsWith(`https://`),children:X(`space.fontSourceCheck`)})]}),E?(0,Q.jsx)(`p`,{className:z(`mt-1.5 text-[0.875rem]`,E===`ok`?`text-ink-3`:`text-rose`),children:X(`space.fontCheck.${E}`,{host:Xr(w),family:t.family})}):null,E===`ok`?(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.875rem] text-ink-3`,children:X(`space.fontPrivacy`,{host:Xr(w)})}):null]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{hint:X(`space.fontLicenseHint`),children:X(`space.fontLicense`)}),(0,Q.jsx)(O,{value:y,maxLength:200,placeholder:X(`space.fontLicensePlaceholder`),onChange:e=>x(e.target.value)}),(0,Q.jsxs)(`label`,{className:`mt-2 flex items-start gap-2 text-[0.875rem]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 accent-ember`,checked:S,onChange:e=>C(e.target.checked)}),X(`space.fontLicenseConfirm`,{family:t.family})]})]}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[t.source?(0,Q.jsx)(b,{variant:`ghost`,className:`mr-auto`,onClick:()=>{n({source:void 0,license:t.license}),r()},children:X(`space.fontSourceRemove`)}):null,(0,Q.jsx)(b,{variant:`ghost`,onClick:r,children:X(`common.cancel`)}),(0,Q.jsx)(b,{disabled:!(T&&S),onClick:()=>{T&&(n({source:T,license:y.trim()||void 0}),r())},children:X(`space.fontSourceSave`)})]})]})})}var ti=new Set;function ni(e){(0,Z.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||ti.has(t))return;ti.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${l.join(`,`)}&display=swap`,document.head.append(n)},[e])}var ri=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function ii({unit:e,label:t,...n}){return(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,Q.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var ai=`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`,oi={web:`space.fontUseWeb`,documents:`space.fontUseDocuments`,print:`space.fontUsePrint`,images:`space.fontUseImages`,video:`space.fontUseVideo`};function si({spaceId:e,font:t,first:n,readOnly:i,autoFocus:a,onChange:o,onRemove:s}){ni(t.family);let c=P(e).data?.files??[],[d,f]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,Q.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:ri(t.family)},children:[(0,Q.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,Q.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),i?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:t.family}),t.role?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:t.role}):null]}):(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(B,{value:t.family,label:X(`space.fontFamily`),placeholder:X(`space.fontFamily`),maxLength:80,autoFocus:a,onChange:e=>o({family:e}),className:`font-medium text-[0.9375rem]`}),(0,Q.jsx)(B,{value:t.role,label:X(`space.fontRole`),placeholder:X(n?`space.fontRoleFirst`:`space.fontRole`),maxLength:200,onChange:e=>o({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:l.map(e=>{let n=t.weights.includes(e);return(0,Q.jsx)(`button`,{type:`button`,disabled:i,"aria-pressed":n,onClick:()=>o({weights:n?t.weights.filter(t=>t!==e):[...t.weights,e].sort((e,t)=>e-t)}),style:{fontFamily:ri(t.family),fontWeight:e},className:z(`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`,i&&!n&&`hidden`),children:e},e)})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[i?t.license?(0,Q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:t.license}):null:(0,Q.jsx)(B,{value:t.license??``,label:X(`space.fontLicense`),placeholder:X(`space.fontLicensePlaceholder`),maxLength:200,onChange:e=>o({license:e}),className:`text-[0.8125rem] text-ink-3`}),i&&!t.uses?.length?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:X(`space.fontUses`)}),u.map(e=>{let n=!!t.uses?.includes(e);return(0,Q.jsxs)(`button`,{type:`button`,disabled:i,"aria-pressed":n,onClick:()=>{let r=n?(t.uses??[]).filter(t=>t!==e):u.filter(n=>n===e||t.uses?.includes(n));o({uses:r.length?r:void 0})},className:z(`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`,i&&!n&&`hidden`),children:[n?(0,Q.jsx)(r,{className:`size-3.5`}):null,X(oi[e])]},e)})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[0.8125rem] text-ink-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:$r(t,c)}),i||!t.family.trim()?null:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(!0),className:`text-ink underline decoration-border underline-offset-2 hover:decoration-ink`,children:X(t.source?`space.fontSourceChange`:`space.fontSourceSet`)})]}),d?(0,Q.jsx)(ei,{spaceId:e,font:t,onSave:o,onClose:()=>f(!1)}):null,i?null:(0,Q.jsx)(L,{label:X(`space.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,Q.jsx)(K,{className:`size-4`})})]})}function ci({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:ri(s?.family),fontWeight:e.weight,fontSize:`${Math.min(e.size,56)}px`,lineHeight:`${e.lineHeight}%`,letterSpacing:`${e.tracking/100}em`,textTransform:e.uppercase?`uppercase`:void 0};return(0,Q.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,Q.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,Q.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,Q.jsx)(`div`,{className:`w-40`,children:(0,Q.jsx)(B,{value:e.name,label:X(`space.styleName`),placeholder:X(`space.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,Q.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,Q.jsx)(`select`,{"aria-label":X(`space.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:z(ai,`max-w-40`),children:t.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.family||X(`space.fontFamily`)},e.id))}):null,(0,Q.jsx)(`select`,{"aria-label":X(`space.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:ai,children:[...new Set([...l,e.weight])].sort().map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))}),(0,Q.jsx)(ii,{unit:`px`,label:X(`space.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,Q.jsx)(ii,{unit:X(`space.styleLine`),label:X(`space.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,Q.jsx)(ii,{unit:X(`space.styleTracking`),label:X(`space.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:X(`space.styleUpper`),"aria-label":X(`space.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:z(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,Q.jsx)(vn,{className:`size-4`})})]}),r?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:o,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,Q.jsx)(K,{className:`size-4`})})]})]})}function li({spaceId:e,onAdd:t,onClose:n}){let[r,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)([]),m=async()=>{s(!0),l(null);try{let{fonts:t}=await q.post(`/api/studio/spaces/${e}/fonts/scan`,{url:r.trim()});t.length?(d(t),p(t.slice(0,2).map(e=>e.family))):l(X(`space.fontsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,Q.jsx)(I,{open:!0,onClose:n,wide:u?!0:void 0,title:X(u?`space.fontsFound`:`space.fontsFromUrl`),children:u?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:X(`space.fontsFoundHint`)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map(e=>(0,Q.jsx)(ui,{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,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>d(null),children:X(`run.back`)}),(0,Q.jsx)(b,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.family))),n()},children:f.length>1?X(`space.addMany`,{n:f.length}):X(`space.add`)})]})]}):(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.logoUrl`)}),(0,Q.jsx)(O,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.fontsUrlHint`)})]}),c?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:n,children:X(`common.cancel`)}),(0,Q.jsx)(b,{type:`submit`,busy:o,disabled:!r.trim(),children:X(`run.next`)})]})]})})}function ui({font:e,on:t,onToggle:n}){return ni(e.family),(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:z(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,Q.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:ri(e.family)},children:`Aa`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,Q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):X(`space.fontWeightsUnknown`)})]}),t?(0,Q.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,Q.jsx)(r,{className:`size-3.5`})}):null]})}function di({spaceId:e,fonts:t,styles:n,rules:r,ruled:i,sample:a,save:o,readOnly:s}){let[l,u]=(0,Z.useState)(t),[d,f]=(0,Z.useState)(n),p=c(r),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=N({fonts:l,textStyles:d,typeRules:p.rules},o),y=(e,t=!1)=>{let n=e.map(e=>({id:A(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&h(n[0].id),u(e=>[...e,...n].slice(0,H.fonts))},b=()=>{let e=A();h(e),f(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},x=[...l.length<H.fonts?[{label:X(`space.fontNew`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>y([{family:``,weights:[400,700]}],!0)},{label:X(`space.fontsFromUrl`),icon:(0,Q.jsx)(wn,{className:`size-4 shrink-0`}),onPick:()=>_(!0)}]:[],...d.length<H.textStyles?[{label:X(`space.styleNew`),icon:(0,Q.jsx)(Je,{className:`size-4 shrink-0`}),onPick:b}]:[],...!i||p.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>p.add()}]];return(0,Q.jsxs)(R,{title:X(`space.typography`),hint:X(`space.typographyHint`),save:v,action:s?null:(0,Q.jsx)(fe,{entries:x}),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[l.length?(0,Q.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:l.map((t,n)=>(0,Q.jsx)(si,{spaceId:e,font:t,first:n===0,readOnly:s,autoFocus:m===t.id,onChange:e=>u(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>u(e=>e.filter(e=>e.id!==t.id))},t.id))}):(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:X(`space.fontsEmpty`)}),d.length?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:X(`space.styles`)}),s?null:(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:X(`space.stylesHint`)}),(0,Q.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:d.map(e=>(0,Q.jsx)(ci,{style:e,fonts:l,sample:a,readOnly:s,autoFocus:m===e.id,onChange:t=>f(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>f(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,i?(0,Q.jsx)(De,{rules:p,placeholder:X(`space.typeRulePlaceholder`),readOnly:s}):null]}),g?(0,Q.jsx)(li,{spaceId:e,onClose:()=>_(!1),onAdd:e=>y(e)}):null]})}var fi=[{title:`space.voice.tone`,hint:`space.voice.toneHint`},{title:`space.voice.audience`,hint:`space.voice.audienceHint`},{title:`space.voice.positioning`,hint:`space.voice.positioningHint`},{title:`space.voice.values`,hint:`space.voice.valuesHint`}];function pi({blocks:e,rules:t,ruled:n,readOnly:r,save:i}){let[a,o]=(0,Z.useState)(e),[s,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),f=c(t),p=N({voice:a,voiceRules:f.rules},i),m=(e,t)=>o(n=>n.map(n=>n.id===e?{...n,...t}:n)),h=a.length>=H.voiceBlocks,g=e=>{let t=A();(e?d:l)(t),o(n=>[...n,{id:t,title:e,text:``}])},_=fi.filter(e=>!a.some(t=>t.title===X(e.title))),v=e=>fi.find(t=>X(t.title)===e)?.hint,y=[...h?[]:[..._.map(e=>({label:X(e.title),icon:(0,Q.jsx)(An,{className:`size-4 shrink-0`}),onPick:()=>g(X(e.title))})),{label:X(`space.voice.own`),icon:(0,Q.jsx)(Y,{className:`size-4 shrink-0`}),onPick:()=>g(``)}],...!n||f.full?[]:[{label:X(`space.ruleNew`),icon:(0,Q.jsx)(Le,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,Q.jsx)(R,{title:X(`space.voice`),hint:X(`space.voiceHint`),save:p,locked:r,action:r||!y.length?null:(0,Q.jsx)(fe,{entries:y}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[a.length?(0,Q.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:a.map(e=>{let t=v(e.title);return(0,Q.jsxs)(`div`,{className:`group/row grid gap-x-6 gap-y-2 py-4 first:pt-0 last:pb-0 sm:grid-cols-[15rem_minmax(0,1fr)]`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-1`,children:[r?(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 font-medium text-[0.9375rem]`,children:e.title}):(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(B,{value:e.title,label:X(`space.voice.title`),placeholder:X(`space.voice.title`),maxLength:80,autoFocus:s===e.id,onChange:t=>m(e.id,{title:t}),className:`font-medium text-[0.9375rem]`})}),r?null:(0,Q.jsx)(L,{label:X(`space.remove`),onClick:()=>{(!e.text.trim()||confirm(X(`space.voice.removeConfirm`,{name:e.title||X(`space.sectionUntitled`)})))&&o(t=>t.filter(t=>t.id!==e.id))},className:`-mt-1 size-8 shrink-0 rounded-lg opacity-0 transition hover:text-rose focus-visible:opacity-100 group-hover/row:opacity-100 max-sm:opacity-100`,children:(0,Q.jsx)(K,{className:`size-4`})})]}),r?(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-[0.9375rem] text-ink-2 leading-relaxed sm:pt-2`,children:e.text}):(0,Q.jsx)(we,{ref:t=>{t&&u===e.id&&(d(null),t.focus())},rows:2,minRows:2,maxRows:14,maxLength:H.voiceText,value:e.text,placeholder:X(t||`space.voice.textPlaceholder`),onChange:t=>m(e.id,{text:t.target.value})})]},e.id)})}):null,r||h?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(b,{variant:`secondary`,size:`sm`,onClick:()=>g(``),children:[(0,Q.jsx)(Y,{className:`size-4`}),` `,X(`space.voice.own`)]}),_.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>g(X(e.title)),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,Q.jsx)(Y,{className:`size-3.5`}),` `,X(e.title)]},e.title))]}),n?(0,Q.jsx)(De,{rules:f,placeholder:X(`space.voice.rulePlaceholder`),readOnly:r}):null]})})}function mi({spaceId:e,logo:t}){let n=X(t?`space.logoPeek`:`space.logoPeekAdd`);return(0,Q.jsxs)(`div`,{className:`shrink-0`,children:[(0,Q.jsx)(i,{children:X(`space.logo`)}),(0,Q.jsx)(U,{to:{pathname:`/space/brand`,hash:`logos`},title:n,"aria-label":n,className:z(`grid size-[4.5rem] place-items-center overflow-hidden rounded-xl transition`,t?`bg-card ring-1 ring-border-soft hover:ring-border`:`text-ink-4 ring-1 ring-border ring-dashed hover:text-ink-2`),children:t?(0,Q.jsx)(Pn,{spaceId:e,file:t,small:!0}):(0,Q.jsx)(_,{className:`size-5`})})]})}function hi({space:e,save:t}){let n=Wt().data,r=Ht(),i=Ke(`capabilities`)&&r&&n?.mode===`managed`,[a,o]=(0,Z.useState)(e.membersStudio);return i?(0,Q.jsxs)(`div`,{className:`flex items-start gap-3 border-border-soft border-t pt-5`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:X(`space.membersStudio`)}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:X(`space.membersStudioHint`)})]}),(0,Q.jsx)(le,{checked:a,disabled:e.readOnly,label:X(`space.membersStudio`),onChange:e=>{o(e),t({membersStudio:e}).catch(()=>o(!e))}})]}):null}function gi({space:e,save:t}){let[n,r]=(0,Z.useState)(e.brand.brandName??``),[i,a]=(0,Z.useState)(e.brand.tagline??``),o=N({brandName:n.trim(),tagline:i.trim()},e=>t({brand:e}));return(0,Q.jsx)(R,{title:X(`space.identity`),hint:X(`space.identityHint`),save:o,locked:e.readOnly,children:(0,Q.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[{id:`brand-name`,label:X(`space.brandName`),hint:X(`space.brandNameHint`),field:(0,Q.jsx)(O,{id:`brand-name`,value:n,maxLength:120,placeholder:e.brand.name??``,onChange:e=>r(e.target.value)})},{id:`brand-tagline`,label:X(`space.tagline`),hint:X(`space.taglineHint`),field:(0,Q.jsx)(O,{id:`brand-tagline`,value:i,maxLength:200,onChange:e=>a(e.target.value)})}].map(e=>(0,Q.jsxs)(`div`,{className:`grid items-start gap-x-6 gap-y-2 py-4 first:pt-0 last:pb-0 sm:grid-cols-[15rem_minmax(0,1fr)]`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{htmlFor:e.id,className:`font-medium text-[0.9375rem]`,children:e.label}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3 leading-snug`,children:e.hint})]}),e.field]},e.id))})})}function _i({space:e,logo:t,save:n}){let[r,a]=(0,Z.useState)(e.brand.name??``),[o,s]=(0,Z.useState)(e.brand.about??``),c=N({name:r.trim(),about:o.trim()},e=>n({brand:e}));return(0,Q.jsx)(R,{title:X(`space.base`),hint:X(`space.baseHint`),save:c,locked:e.readOnly,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(i,{children:X(`space.title`)}),(0,Q.jsx)(O,{value:r,maxLength:120,onChange:e=>a(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.titleHint`)})]}),(0,Q.jsx)(mi,{spaceId:e.id,logo:t})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(i,{children:X(`space.about`)}),(0,Q.jsx)(we,{minRows:4,value:o,onChange:e=>s(e.target.value)}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:X(`space.aboutHint`)})]}),(0,Q.jsx)(hi,{space:e,save:n})]})})}function vi({space:e,group:t,top:n=!1,children:r}){let i=ie(),a=P(e.id),[o,s]=(0,Z.useState)(0),[c,l]=(0,Z.useState)(!1),u=async t=>{await q.patch(`/api/studio/spaces/${e.id}`,t),await i.invalidateQueries({queryKey:p.spaces()})},d=Be({mutationFn:()=>q.del(`/api/studio/spaces/${e.id}`),onSuccess:()=>i.invalidateQueries({queryKey:p.spaces()})}),f=Ut(),m=Ht(),h=a.data??{files:[],embeddings:!0},g=`${e.id}:${o}`,_=e.readOnly,v=t===`knowledge`,y=Ke(`brandSections`),S=Ke(`brandRules`),C=Ke(`typography`);return We(_?{}:{title:X(v?`space.assistantTitleKnowledge`:`space.assistantTitle`),hello:X(v?`space.assistantHelloKnowledge`:`space.assistantHello`),about:X(v?`space.assistantAboutKnowledge`:`space.assistantAbout`),placeholder:X(v?`space.assistantComposerKnowledge`:`space.assistantComposer`),suggestions:v?[{label:X(`assistant.suggest.knowledgeHow`)},{label:X(`assistant.suggest.knowledgeSite`),fill:!0},{label:X(`assistant.suggest.knowledgeCategories`)}]:[{label:X(`assistant.suggest.readSite`),fill:!0},{label:X(`assistant.suggest.missing`)},...t===`info`?[{label:X(`assistant.suggest.facts`)}]:[]],summary: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:()=>s(e=>e+1)}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[_?(0,Q.jsx)(Yt,{children:qt(e)}):n?(0,Q.jsx)(Qe,{}):null,t===`info`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(W,{id:`base`,children:(0,Q.jsx)(_i,{space:e,logo:x(h.files.filter(e=>e.kind===`logo`),e.brand.logoSections),save:u},`base:${g}`)}),(0,Q.jsx)(W,{id:`facts`,children:(0,Q.jsx)(Wr,{facts:e.facts,save:e=>u({facts:e}),readOnly:_},`facts:${g}`)}),(0,Q.jsx)(W,{id:`links`,children:(0,Q.jsx)(qr,{links:e.brand.links??[],save:e=>u({brand:{links:e}}),readOnly:_},`links:${g}`)})]}):null,t===`brand`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(W,{id:`identity`,children:(0,Q.jsx)(gi,{space:e,save:u},`identity:${g}`)}),(0,Q.jsx)(W,{id:`logos`,children:(0,Q.jsx)(Yr,{spaceId:e.id,data:h,readOnly:_,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:y,ruled:S,save:e=>u({brand:e})},`logos:${g}`)}),(0,Q.jsx)(W,{id:`colors`,children:(0,Q.jsx)(Br,{spaceId: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:S,save:e=>u({brand:e}),readOnly:_},`colors:${g}`)}),C?(0,Q.jsx)(W,{id:`typography`,children:(0,Q.jsx)(di,{spaceId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:S,sample:e.brand.name||X(`space.typeSample`),save:e=>u({brand:e}),readOnly:_},`typography:${g}`)}):null,(0,Q.jsx)(W,{id:`assets`,children:(0,Q.jsx)(Er,{spaceId:e.id,data:h,readOnly:_,sections:e.brand.assetSections??[],save:e=>u({brand:e})},`assets:${g}`)}),(0,Q.jsx)(W,{id:`voice`,children:(0,Q.jsx)(pi,{blocks:e.brand.voice??[],rules:e.brand.voiceRules??[],ruled:S,save:e=>u({brand:e}),readOnly:_},`voice:${g}`)})]}):null,r,t===`info`&&f&&!_&&m?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(b,{variant:`danger`,onClick:()=>l(!0),children:X(`settings.delete`)}),(0,Q.jsxs)(I,{open:c,onClose:()=>l(!1),title:X(`settings.deleteTitle`,{name:e.name}),children:[(0,Q.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:X(`settings.deleteBody`)}),d.error?(0,Q.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:d.error.message}):null,(0,Q.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Q.jsx)(b,{variant:`ghost`,onClick:()=>l(!1),children:X(`common.cancel`)}),(0,Q.jsx)(b,{variant:`danger`,busy:d.isPending,onClick:()=>d.mutate(),children:X(`common.delete`)})]})]})]}):null]})}var yi=/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent);function bi(e){let t=e.join(` `),[n,r]=(0,Z.useState)(e[0]);return(0,Z.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=rt(),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 xi(){let[e,t]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{let e=rt(),n=()=>t(e.clientHeight);n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),e}function Si(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function Ci({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,Q.jsx)(cn,{icon:e.icon??ze,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,Q.jsx)(on,{label:e.label,children:r},e.plugin):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}var wi=(0,Z.lazy)(()=>Ve(()=>import(`./SkillEditor-BsXTqNli.js`).then(e=>({default:e.SkillEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])));function Ti({place:e}){let{group:t}=Oe(),[n,r]=de(),i=ce(),a=me(),{hash:o}=a,{space:s,loading:c}=Gt(),l=Ye(),u=tn(),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),_=e??(ot(t)&&t!==`skills`?t:void 0),v=_?void 0:l.spaceParts.find(e=>e.id===t),y=_??v?.id,b=a.state?.parts===!0,x=Ke(`pages`),S=Ke(`skills`),C=Xe().filter(e=>x||e.id!==`page`),w=ct(C,l).map(e=>({...e,to:`/space/${e.id}`})),ee=w,T={id:`results`,label:X(`space.results`),icon:at,to:`/space/results`},E={id:`skills`,label:X(`space.skills`),icon:Lt,to:`/skills`},D=_===`results`||_===`skills`,O=_===`results`?T:_===`skills`?E:ee.find(e=>e.id===y),k=n.get(`show`),[A,j]=(0,Z.useState)(``),M=(0,Z.useRef)(null),te=A.trim().toLowerCase(),ne=(0,Z.useMemo)(()=>({slot:d,narrow:u,setDetail:m,filter:te}),[d,u,te]),N=s?s.brand.name?.trim()||s.name:X(`nav.space`),re=Ke(`typography`)?[]:[`typography`],P=v?l.spaceMenus[v.id]??[]:[],ie=v?[{plugin:null,label:null,sections:P}]:_&&_!==`results`?$e(_,l,re):[],F=_?$e(_,l).filter(e=>e.plugin):[],I=bi([...ie,..._===`results`?F:[]].flatMap(e=>e.sections.map(e=>e.id))),L=_===`results`&&k&&k!==`all`?k:null,[oe,se]=(0,Z.useState)(hr),le=gr(_===`results`?s?.id:void 0,L,oe),fe=le.data?.wizards.find(e=>e.id===L)?.title,B=_===`data`&&k&&k!==`all`||_===`knowledge`&&k&&/^[ptfcvs]:/.test(k)?k:null,V=B?.startsWith(`s:`)?l.spaceSections.find(e=>e.id===B.slice(2)):void 0,he=_===`knowledge`&&B&&/^[ptf]:/.test(B)?B:null,H=_===`skills`&&k?.startsWith(`k:`)?k:null,ge=dt(_===`skills`&&S?s?.id:void 0),_e=bt(_===`data`?s?.id:void 0),U=Dt(_===`knowledge`?s?.id:void 0),G=Pt(B?.startsWith(`v:`)?B.slice(2):``),ve=U.data?.categories.find(e=>e.id===(B?.startsWith(`c:`)?B.slice(2):G.data?.category.id)),ye=F.length>0||_===`knowledge`&&!!U.data?.categories.length||_===`data`&&!!(_e.data&&jt(_e.data).some(e=>e.items.length)),be=!!_&&!D&&(_!==`data`&&_!==`knowledge`||!ye),K=_===`results`?2:y?k||be?2:1:k===`overview`?2:0,q=D?1:u?Math.min(K,1):y&&!be&&h!==y&&!b?1:0,xe=an(q),Se=an(K);(0,Z.useEffect)(()=>{g(null),j(``)},[y]),(0,Z.useEffect)(()=>{if(u||q!==1)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`f`&&M.current&&(e.preventDefault(),M.current.focus(),M.current.select())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,q]);let Ce=_===`skills`?ge.data?.skills.find(e=>`k:${e.id}`===H)?.name:_===`knowledge`?V?V.label():B?.startsWith(`v:`)?G.data&&`${G.data.category.name}: ${G.data.value}`:B?.startsWith(`c:`)?ve?.name:U.data?.items.find(e=>e.key===B)?.title:_e.data?jt(_e.data).flatMap(e=>e.items).find(e=>e.key===B)?.title:void 0;et([...D?[]:[{label:X(`nav.sources`),to:`/space`}],...y?[]:[{label:X(`space.overview`)}],...O?[{label:O.label,to:O.to}]:[],...O&&(p??fe??Ce)?[{label:p??fe??Ce}]:[]]);let we={p:`page`,t:`table`,f:`file`,c:`category`,v:`category value`,s:`plugin section`};We({..._===`data`||_===`results`?{compact:!0}:{},..._===`data`?{suggestions:[{label:X(`assistant.suggest.dataWhat`)},{label:X(`assistant.suggest.dataWho`)},{label:X(`assistant.suggest.dataEdit`)}]}:_===`results`?{suggestions:[{label:X(`assistant.suggest.resultsFailed`)},{label:X(`assistant.suggest.resultsCost`)},{label:X(`assistant.suggest.resultsShare`)}]}:{},...B&&Ce?{open:{kind:we[B[0]]??`item`,id:B.slice(2),label:Ce}}:L&&fe?{open:{kind:`wizard`,id:L,label:fe}}:{}});let J=_===`results`||_===`data`||B?o.slice(1):k||o.slice(1),Te=(0,Z.useRef)(``);(0,Z.useEffect)(()=>{let e=`${y}#${J}`;J&&Te.current!==e&&document.getElementById(J)&&(Te.current=e,requestAnimationFrame(()=>Si(J,!1)))},[y,J,s?.id,l.spaceSections,P.length]),(0,Z.useEffect)(()=>{!u&&(y===`knowledge`||y===`data`||y===`skills`)&&rt().scrollTo({top:0})},[u,y,B,H]);let Ee=xi();if(t===`skills`)return(0,Q.jsx)(pe,{to:{pathname:`/skills`,search:a.search,hash:o},replace:!0});if(!y){let e=o.slice(1),n=e?nt(e,l):null;if(n===`knowledge`&&l.spaceSections.some(t=>t.id===e))return(0,Q.jsx)(pe,{to:`/space/knowledge?show=s:${e}`,replace:!0});if(n)return(0,Q.jsx)(pe,{to:u?`/space/${n}?show=${e}`:{pathname:`/space/${n}`,hash:e},replace:!0});if((e||t)&&l.status!==`ready`)return null;if(t!==void 0)return(0,Q.jsx)(pe,{to:`/space`,replace:!0})}let De=_===`info`?k??o.slice(1):``;if(De&&nt(De,l)===`brand`)return(0,Q.jsx)(pe,{to:u?`/space/brand?show=${De}`:{pathname:`/space/brand`,hash:De},replace:!0});if(_===`skills`&&!S)return(0,Q.jsx)(pe,{to:`/`,replace:!0});if(_===`knowledge`&&!k&&l.spaceSections.some(e=>e.id===o.slice(1)))return(0,Q.jsx)(pe,{to:`/space/knowledge?show=s:${o.slice(1)}`,replace:!0});let ke=e=>{if(u){i({search:`?show=${e}`});return}Te.current=`${y}#${e}`,Si(e,!0),i({search:``,hash:e},{replace:!0})},Y=e=>u?r({show:e}):r(e===`all`?{}:{show:e},{replace:!0}),Ae=e=>e.flatMap(e=>e.sections).map(e=>l.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,Q.jsx)(W,{id:e.id,children:(0,Q.jsx)(R,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,Q.jsx)(st,{of:e,children:(0,Q.jsx)(e.component,{})})})},e.serial)),je=u?void 0:I,Me=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nn,{title:N,open:q===1?O??null:null,onBack:D?void 0:()=>u?i(`/space`):g(y??null),root:{icon:He,label:X(`nav.sources`),onOpen:()=>i(u?`/space?show=overview`:`/space`),current:!y}}),u||D?(0,Q.jsx)(`div`,{className:z(ln(xe)),children:q===0?(0,Q.jsx)($t,{entries:ee,current:void 0,onPick:()=>g(null)}):(0,Q.jsx)(`div`,{ref:f})},q):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)($t,{entries:ee,current:q===0?O:void 0,hide:q===1?O?.id:void 0,onPick:()=>{g(null),be&&O&&(i(O.to),rt().scrollTo({top:0,behavior:`smooth`}))}}),q===1?(0,Q.jsxs)(`div`,{className:`fade-in-0 slide-in-from-top-1 animate-in duration-200`,children:[(0,Q.jsx)(`div`,{className:`mx-2 my-3 h-px bg-border-soft`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Q.jsx)(ue,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-4`}),(0,Q.jsx)(`input`,{ref:M,type:`search`,value:A,onChange:e=>j(e.target.value),onKeyDown:e=>e.key===`Escape`&&j(``),"aria-label":X(`space.menuSearch`),placeholder:X(`space.menuSearch`),className:`h-8 w-full rounded-lg border border-input bg-card pr-14 pl-9 text-[0.8125rem] text-ink outline-none transition placeholder:text-ink-4 focus:border-focus focus:ring-4 focus:ring-focus-glow`}),(0,Q.jsx)(`kbd`,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 right-2 rounded border border-border-soft px-1 font-sans text-[0.6875rem] text-ink-4`,children:yi?`⌘F`:`Ctrl F`})]}),(0,Q.jsx)(`div`,{ref:f})]},y):null]})]});return(0,Q.jsx)(en.Provider,{value:ne,children:(0,Q.jsx)(`div`,{className:`animate-rise`,children:(0,Q.jsxs)(`div`,{className:z(`grid gap-6`,_!==`results`&&`md:grid-cols-[10.5rem_minmax(0,1fr)] md:gap-5 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[_===`results`?null:(0,Q.jsx)(`aside`,{className:z(`menu-scroll min-w-0 md:sticky md:top-6 md:self-start md:overflow-y-auto md:overscroll-contain`,u&&K===2&&`hidden`,u&&Se===`back`&&ln(`back`)),style:!u&&Ee?{maxHeight:Ee-48,paddingBottom:`var(--assistant-dock, 0px)`}:void 0,children:Me}),y?(0,Q.jsxs)(`div`,{className:z(`min-w-0`,u&&K<2&&`hidden`,u&&Se===`deeper`&&ln(`deeper`)),children:[u&&_!==`results`?(0,Q.jsx)(`div`,{className:`mb-3`,children:(0,Q.jsx)(sn,{label:O?.label??N,onBack:()=>i(O?.to??`/space/${y}`)})}):null,_===`data`?(0,Q.jsxs)(rn,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Q.jsx)(cn,{icon:qe,label:X(`data.all`),selected:!u&&!B,onPick:()=>Y(`all`)})}),_e.data?jt(_e.data).map(e=>(0,Q.jsx)(on,{label:e.label,children:e.items.map(e=>(0,Q.jsx)(cn,{icon:vt[e.kind],label:e.title,selected:!u&&e.key===B,onPick:()=>Y(e.key)},e.key))},e.key)):null,(0,Q.jsx)(Ci,{groups:F,current:je,onPick:ke})]}):_===`knowledge`?(0,Q.jsxs)(rn,{children:[(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Q.jsx)(cn,{icon:qe,label:X(`know.all`),selected:!(u||B),onPick:()=>Y(`all`)})}),U.data?.categories.length?(0,Q.jsx)(on,{label:X(`know.categories`),children:U.data.categories.map(e=>(0,Q.jsx)(cn,{icon:wt[e.type],label:e.name,badge:(0,Q.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!u&&(B===`c:${e.id}`||G.data?.category.id===e.id),onPick:()=>Y(`c:${e.id}`)},e.id))}):null,(0,Q.jsx)(Ci,{groups:F,current:u?void 0:V?.id,onPick:e=>Y(`s:${e}`)})]}):_===`skills`?(0,Q.jsxs)(rn,{children:[(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsx)(cn,{icon:qe,label:X(`skills.all`),selected:!(u||H),onPick:()=>Y(`all`)}),ge.data?.skills.map(e=>(0,Q.jsx)(cn,{icon:ut[e.mode],label:e.name,selected:!u&&H===`k:${e.id}`,onPick:()=>Y(`k:${e.id}`)},e.id))]}),(0,Q.jsx)(Ci,{groups:F,current:je,onPick:ke})]}):(0,Q.jsx)(rn,{children:(0,Q.jsx)(Ci,{groups:ie,current:je,onPick:ke})}),s&&(_===`info`||_===`brand`||_===`knowledge`)?(0,Q.jsxs)(vi,{space:s,group:_,top:!B||!!V,children:[_===`knowledge`?he?he.startsWith(`p:`)?(0,Q.jsx)(Et,{pageId:he.slice(2),onGone:()=>Y(`all`),onOpen:Y},he):he.startsWith(`t:`)?(0,Q.jsx)(Tt,{tableId:he.slice(2),onGone:()=>Y(`all`)},he):(0,Q.jsx)(Un,{spaceId:s.id,fileId:he.slice(2),readOnly:s.readOnly,onGone:()=>Y(`all`)},he):U.data?V?(0,Q.jsx)(R,{title:V.label(),hint:V.hint?.(),plain:!0,children:(0,Q.jsx)(st,{of:V,children:(0,Q.jsx)(V.component,{})})},B):B?.startsWith(`c:`)?ve?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(Ct,{spaceId:s.id,category:ve,readOnly:s.readOnly,onOpen:Y,onGone:()=>Y(`all`)}),ve.type===`choice`?null:(0,Q.jsx)(Nt,{spaceId:s.id,category:ve,categories:U.data.categories,onOpen:Y})]},B):null:B?.startsWith(`v:`)?G.data?(0,Q.jsx)(_t,{value:G.data,readOnly:s.readOnly,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[G.data.items.length?(0,Q.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:G.data.items.map(e=>(0,Q.jsx)(xt,{item:e,categories:U.data.categories.filter(e=>e.id!==G.data?.category.id),onOpen:Y},e.key))}):null,G.data.rows.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Y(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:X(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},B):null:(0,Q.jsx)(W,{id:`documents`,children:(0,Q.jsx)(kt,{spaceId:s.id,data:U.data,readOnly:s.readOnly,onOpen:Y})}):null:null,_===`info`||_===`brand`?Ae(F):null]},s.id):null,s&&_===`skills`&&S?(0,Q.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:H?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(wi,{skillId:H.slice(2),onGone:()=>Y(`all`),onOpen:Y},H)}):ge.data?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(lt,{spaceId:s.id,data:ge.data,onOpen:Y}),Ae(F)]}):ge.error?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:ge.error.message}):null}):null,s&&_===`page`&&x?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[(0,Q.jsx)(pr,{space:s},s.id),Ae(F)]}):null,s&&v?(0,Q.jsx)(st,{of:v,children:(0,Q.jsx)(tt,{part:v.id,children:(0,Q.jsx)(v.component,{})},s.id)}):null,s&&_===`data`?(0,Q.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:B?.startsWith(`t:`)?(0,Q.jsx)(Tt,{tableId:B.slice(2),onGone:()=>Y(`all`)},B):B?.startsWith(`p:`)?(0,Q.jsx)(Et,{pageId:B.slice(2),onGone:()=>Y(`all`)},B):(0,Q.jsxs)(Q.Fragment,{children:[_e.data?(0,Q.jsx)(Ot,{spaceId:s.id,data:_e.data,readOnly:s.readOnly,onOpen:Y}):null,Ae(F)]})}):null,s&&_===`results`?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[le.data?(0,Q.jsx)(vr,{data:le.data,wizardId:L,onWizard:e=>Y(e??`all`),filter:oe,onFilter:se}):null,le.isError?(0,Q.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:le.error.message}):null,Ae(F)]}):null,s||c?null:(0,Q.jsx)(ae,{children:X(`settings.noSpace`)})]}):s&&(!u||k===`overview`)?(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[u?(0,Q.jsx)(`div`,{className:`mb-3`,children:(0,Q.jsx)(sn,{label:X(`nav.sources`),onBack:()=>i(`/space`)})}):null,(0,Q.jsx)(br,{space:s,parts:w})]}):null]})})})}export{Ti as SpacePage};
|