wizards 0.3.7 → 0.4.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/README.md +28 -14
- package/apps/runtime/dist/agents/studio-assistant.js +79 -7
- package/apps/runtime/dist/assistant/runs.js +24 -0
- package/apps/runtime/dist/auth/account.js +36 -4
- package/apps/runtime/dist/auth/device.js +101 -0
- package/apps/runtime/dist/auth/index.js +4 -4
- package/apps/runtime/dist/cli/account.js +289 -0
- package/apps/runtime/dist/cli/install-env.js +33 -0
- package/apps/runtime/dist/cli/main.js +17 -3
- package/apps/runtime/dist/cli/menu.js +19 -5
- package/apps/runtime/dist/cli/setup.js +9 -16
- package/apps/runtime/dist/cli/status.js +4 -1
- package/apps/runtime/dist/cli/ui.js +14 -0
- package/apps/runtime/dist/docs/user/assistant.md +25 -7
- package/apps/runtime/dist/docs/user/command-line.md +3 -2
- package/apps/runtime/dist/docs/user/create-account.md +47 -0
- package/apps/runtime/dist/docs/user/first-start.md +9 -1
- package/apps/runtime/dist/docs/user/index.md +16 -12
- package/apps/runtime/dist/docs/user/install.md +3 -1
- package/apps/runtime/dist/docs/user/local-only.md +38 -0
- package/apps/runtime/dist/docs/user/meta.json +3 -1
- package/apps/runtime/dist/docs/user/models.md +3 -2
- package/apps/runtime/dist/env.js +5 -0
- package/apps/runtime/dist/manage.js +16 -4
- package/apps/runtime/dist/models.js +6 -0
- package/apps/runtime/dist/plugins/pro.js +16 -16
- package/apps/runtime/dist/routes/studio.js +140 -40
- package/apps/runtime/dist/services/assistant-chats.js +49 -6
- package/apps/runtime/dist/services/cloud.js +10 -10
- package/apps/runtime/dist/services/onboarding.js +152 -0
- package/apps/web/dist/assets/{AboutDialog-C0dN86zd.js → AboutDialog-CPQiN7H9.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-Cv81t7tj.js → ChangelogDialog-DynvQuuR.js} +1 -1
- package/apps/web/dist/assets/ChatView-CKo_9IZD.js +10 -0
- package/apps/web/dist/assets/EditorPage-CDIJXC4T.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-D4dp1MWS.js → FlowPreview-BZLnG7GV.js} +1 -1
- package/apps/web/dist/assets/{Harness-v7r0e6vK.js → Harness-CNh3nbB_.js} +2 -2
- package/apps/web/dist/assets/{NewWizardChannels-Be-7VhBi.js → NewWizardChannels-C1Ss9UMY.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-C8hPvrK8.js → NewWizardPage-2qLAbvDL.js} +2 -2
- package/apps/web/dist/assets/OnboardingPage-C1FJwEsT.js +1 -0
- package/apps/web/dist/assets/ProjectPage-CGuLUuOs.js +1 -0
- package/apps/web/dist/assets/{PublicRunner-DeCpVfZP.js → PublicRunner-BKw1lOW4.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-B-UCgnqW.js → ReadOnly-DTjv2Jzm.js} +1 -1
- package/apps/web/dist/assets/RunDrawer-D1I5xqVf.js +4 -0
- package/apps/web/dist/assets/RunnerView-BPPmlv9z.js +1 -0
- package/apps/web/dist/assets/SettingsPage-zbomQfGy.js +1 -0
- package/apps/web/dist/assets/SetupPage-D3F7M6Pz.js +1 -0
- package/apps/web/dist/assets/{SharePage-B778xUFo.js → SharePage-BY49IJgT.js} +1 -1
- package/apps/web/dist/assets/{changelog-DCJo2mbx.js → changelog-DYZC2E6q.js} +1 -1
- package/apps/web/dist/assets/{circle-alert-DLvC9ePT.js → circle-alert-CVOH4wAv.js} +1 -1
- package/apps/web/dist/assets/{esm-BJskogLD.js → esm-BfXdeWaI.js} +1 -1
- package/apps/web/dist/assets/index-B9xVkr2X.css +1 -0
- package/apps/web/dist/assets/index-BH0PYgov.js +15 -0
- package/apps/web/dist/assets/{lock-DR7NakPn.js → lock-DHBh62LA.js} +1 -1
- package/apps/web/dist/assets/{phone-BORh3jfv.js → phone-Bt1cyWpY.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-DV5D91TD.js → settings-menu-ace1vI3i.js} +1 -1
- package/apps/web/dist/assets/{ui-BOCXzzHi.js → ui-D2SqIZeQ.js} +2 -2
- package/apps/web/dist/assets/{upload-B3yv8gsk.js → upload-CCEq88l4.js} +1 -1
- package/apps/web/dist/index.html +3 -3
- package/apps/web/dist/install.sh +17 -7
- package/apps/web/dist/mcp/flow.html +3 -3
- package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +62 -1
- package/node_modules/@engenty-wizards/shared/dist/assistant.js +10 -0
- package/package.json +1 -1
- package/apps/web/dist/assets/ChatView-uogJ3nht.js +0 -10
- package/apps/web/dist/assets/EditorPage-n8YuTh6j.js +0 -3
- package/apps/web/dist/assets/ProjectPage-B686ArYy.js +0 -1
- package/apps/web/dist/assets/RunDrawer-C6pzi8AJ.js +0 -4
- package/apps/web/dist/assets/RunnerView-Deenymq0.js +0 -1
- package/apps/web/dist/assets/SettingsPage-CK6L0yEe.js +0 -1
- package/apps/web/dist/assets/SetupPage-9CH3qXdH.js +0 -1
- package/apps/web/dist/assets/index-D6hUM8NU.css +0 -1
- package/apps/web/dist/assets/index-Df6UxElH.js +0 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i,v as a}from"./logo-C4V2_3Ar.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i,v as a}from"./logo-C4V2_3Ar.js";import{At as o,Cn as s,Et as c,Gt as l,Mt as u,Ot as d,Tt as f,Vt as p,_n as m,a as h,c as g,ct as _,ft as v,l as y,o as b,pt as x,r as S,s as ee,u as C,un as te,ut as w,xn as T,y as E}from"./ui-D2SqIZeQ.js";import{a as ne,i as re,l as D,o as O,u as ie}from"./NewWizardChannels-C1Ss9UMY.js";import{t as k}from"./upload-CCEq88l4.js";import{It as ae,Ot as A,S as j,b as oe,jt as M,vn as N,x as P,y as F}from"./index-BH0PYgov.js";var I=[[`id`,8],[`toolId`,10],[`moduleId`,7],[`pluginId`,6],[`title`,6],[`description`,4],[`tags`,3],[`path`,3],[`inputSchema`,2],[`outputSchema`,2],[`request`,1],[`response`,1]];function L(e){return e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/([a-z])([A-Z])/g,`$1 $2`).toLowerCase()}function R(e){return L(e).split(/[^a-z0-9]+/).map(e=>e.trim()).filter(e=>e.length>1)}function z(e){return e==null?``:Array.isArray(e)?e.map(z).filter(Boolean).join(` `):typeof e==`object`?Object.values(e).map(z).filter(Boolean).join(` `):String(e)}function B(e,t){let n=t.map(([t,n])=>({text:z(e[t]),weight:n})).filter(e=>e.text.length>0);return{fields:n,tokens:n.flatMap(e=>R(e.text))}}function V(e){let t=[e];if(e.length<5)return t;if(e.endsWith(`ing`)){let n=e.slice(0,-3);n.length>=3&&t.push(n,`${n}e`)}else if(e.endsWith(`ies`)&&e.length>=6)t.push(`${e.slice(0,-3)}y`);else if(e.endsWith(`es`))t.push(e.slice(0,-2),e.slice(0,-1));else if(e.endsWith(`ed`)){let n=e.slice(0,-2);t.push(n,`${n}e`)}else e.endsWith(`s`)&&!e.endsWith(`ss`)&&t.push(e.slice(0,-1));return[...new Set(t)]}function H(e,t){if(e===t)return 1;let n=0;for(let r of V(e))for(let i of V(t)){if(r===i){n=Math.max(n,r===e&&i===t?1:.75);continue}r.length>=2&&i.startsWith(r)&&(n=Math.max(n,.55*(r.length/i.length))),i.length>=4&&r.startsWith(i)&&(n=Math.max(n,.4*(i.length/r.length)))}return n}function U(e,t){return e.reduce((e,n)=>e+H(t,n),0)}function W(e,t,n=I){if(!t?.trim())return 0;let r=R(t);if(r.length===0)return 0;let i=B(e,n);return i.tokens.length===0?0:r.reduce((e,t)=>U(i.tokens,t)===0?e:e+i.fields.reduce((e,n)=>{let r=R(n.text),i=U(r,t);if(i===0)return e;let a=i*2.2/(i+1.2+r.length/16);return e+n.weight*a},0),0)}var G=new Set(R(`aber als also am an auch auf aus bei bin bitte brauche brauchen braucht das dass dem den der
|
|
2
2
|
des die dies diese dieser doch du ein eine einem einen einer eines er es etwas fuer für gerne
|
|
3
3
|
habe haben hat ich ihr im in ist kann können koennen mache machen mag mein meine meinem meinen
|
|
4
4
|
meiner mich mir mit möchte moechte nach nicht noch nur oder sich sie sind soll suche suchen
|
|
5
5
|
sucht um und uns unser unsere vom von vor was wie will wir wird wo wollen zu zum zur
|
|
6
6
|
a about an and are as at be can do for from have how i in is it like looking me my need of on
|
|
7
|
-
or our that the this to want we what which who with would you your`)),K=e=>e.replace(/ß/g,`ss`);function q(e){let t=R(K(e)),n=t.filter(e=>!G.has(e));return n.length?n:t}var J=e=>e.trim().split(/\s+/).filter(Boolean).length>=3,Y=e(t(),1),X=e(n(),1);function se({variant:e=`secondary`,label:t=
|
|
7
|
+
or our that the this to want we what which who with would you your`)),K=e=>e.replace(/ß/g,`ss`);function q(e){let t=R(K(e)),n=t.filter(e=>!G.has(e));return n.length?n:t}var J=e=>e.trim().split(/\s+/).filter(Boolean).length>=3,Y=e(t(),1),X=e(n(),1);function se({variant:e=`secondary`,label:t=o(`home.import`)}){let n=T(),i=r(),{project:a}=A(),s=M(),c=(0,Y.useRef)(null),l=N({mutationFn:e=>C.upload(`/api/studio/projects/${a.id}/wizards/import`,e),onSuccess:async({id:e})=>{await i.invalidateQueries({queryKey:[`projects`]}),await i.invalidateQueries({queryKey:[`wizards`]}),n(`/edit/${e}`)}}),u=l.error instanceof _?l.error.body?.issues??[]:[];return!s||a?.readOnly?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(w,{variant:e,busy:l.isPending,disabled:!a,onClick:()=>c.current?.click(),children:[(0,X.jsx)(k,{className:`size-4`}),` `,t]}),(0,X.jsx)(`input`,{ref:c,hidden:!0,type:`file`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&l.mutate(t)}}),(0,X.jsxs)(x,{open:l.isError,onClose:l.reset,title:o(`import.failed`),children:[(0,X.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:l.error?.message}),u.length?(0,X.jsx)(`ul`,{className:`mt-3 flex list-disc flex-col gap-1 pl-5 text-[0.8125rem] text-ink-2`,children:u.slice(0,8).map(e=>(0,X.jsx)(`li`,{children:e.message},e.message))}):null,(0,X.jsx)(`div`,{className:`mt-5 flex justify-end`,children:(0,X.jsx)(w,{variant:`secondary`,onClick:l.reset,children:o(`common.close`)})})]})]})}var Z=10,Q=3;async function ce(e,t){let n=await fetch(E(`/api/studio/wizards/${e}/files/${encodeURIComponent(t.name)}`),{method:`PUT`,credentials:`include`,headers:{"content-type":t.type||`application/octet-stream`},body:t});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??n.statusText)}}function $({over:e,onClick:t}){return(0,X.jsx)(`button`,{type:`button`,"aria-label":o(`editor.detach`),onClick:t,className:c(`inline-flex shrink-0 items-center justify-center rounded-full`,e?`-top-1.5 -right-1.5 absolute size-5 bg-ink text-paper shadow-soft coarse:size-7`:`size-5 text-ink-3 hover:bg-paper-3 hover:text-ink coarse:size-7`),children:(0,X.jsx)(u,{className:`size-3`})})}function le(e,t){let n=q(t);if(!n.length)return[];let r=e.map(e=>({w:e,score:W({title:e.title,summary:e.description},n.join(` `),[[`title`,10],[`summary`,6]])})).filter(e=>e.score>0).sort((e,t)=>t.score-e.score),i=J(t)?(r[0]?.score??0)*.4:0;return r.filter(e=>e.score>=i).slice(0,Q).map(e=>e.w)}function ue({wish:e,projectId:t,busy:n,onTake:r,onMore:s}){let c=T(),[l,u]=(0,Y.useState)(null),f=j(e.trim(),300),p=i({queryKey:[`wizards`,t,`similar`],queryFn:()=>C.get(`/api/studio/projects/${t}/wizards`)}),m=i({queryKey:[`marketplace`,d,f,`similar`],queryFn:()=>C.get(`/api/studio/marketplace?${new URLSearchParams({lang:d,limit:String(Z),offset:`0`,q:f})}`),enabled:f.length>=3,placeholderData:a});if(f.length<3)return null;let h=le(p.data??[],f),g=(m.data?.entries??[]).slice(0,Z-h.length),_=(m.data?.total??0)-g.length;if(!(h.length||g.length))return null;let y=`flex items-center gap-3 rounded-xl bg-card py-2 pr-2 pl-3.5 ring-1 ring-border-soft`;return(0,X.jsxs)(`section`,{className:`mt-5`,children:[(0,X.jsx)(`h2`,{className:`mb-2 px-1 text-[0.8125rem] text-ink-3`,children:o(`new.similar`)}),(0,X.jsxs)(`ul`,{className:`flex flex-col gap-1.5`,children:[h.map(e=>(0,X.jsxs)(`li`,{className:y,children:[(0,X.jsx)(v,{children:o(`new.yours`)}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>c(`/edit/${e.id}`),className:`min-w-0 flex-1 text-left`,children:[(0,X.jsx)(`span`,{className:`block truncate font-medium text-[0.9375rem]`,children:e.title}),(0,X.jsx)(`span`,{className:`block truncate text-[0.8125rem] text-ink-3`,children:e.description})]}),(0,X.jsx)(w,{variant:`secondary`,size:`sm`,onClick:()=>c(`/edit/${e.id}`),children:o(`new.open`)})]},e.id)),g.map(e=>(0,X.jsxs)(`li`,{className:y,children:[(0,X.jsx)(v,{children:o(`new.template`)}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),className:`min-w-0 flex-1 text-left`,children:[(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium text-[0.9375rem]`,children:e.title}),e.plan===`pro`?(0,X.jsx)(P,{}):null]}),(0,X.jsx)(`span`,{className:`block truncate text-[0.8125rem] text-ink-3`,children:e.pitch})]}),(0,X.jsx)(w,{variant:`secondary`,size:`sm`,disabled:n,onClick:()=>r(e),children:o(`new.take`)})]},e.id))]}),_>0?(0,X.jsx)(`button`,{type:`button`,onClick:()=>s(f),className:`mt-2 px-1 text-[0.875rem] text-ink-2 hover:text-ink coarse:min-h-11`,children:o(`new.more`,{n:_})}):null,(0,X.jsx)(F,{id:l,fallback:g.find(e=>e.id===l)??null,onClose:()=>u(null),onUse:r,busy:n})]})}function de(){let e=T(),t=r(),{project:n}=A(),a=M(),[u]=s(),[_,v]=(0,Y.useState)(u.get(`wish`)??``),[x,E]=(0,Y.useState)(ne),[k,j]=(0,Y.useState)([]),[P,F]=(0,Y.useState)(!1),[I,L]=(0,Y.useState)(null),R=(0,Y.useRef)(null),z=(0,Y.useRef)(null),B=(0,Y.useRef)(null),[V]=y(),H=g(_,v,{deviceId:V.deviceId}),U=i({queryKey:[`runners`],queryFn:()=>C.get(`/api/studio/runners`)}),W=e=>{let t=e.map(ee);j(e=>[...e.filter(e=>!t.some(t=>t.name===e.name)),...t])},[G,K]=(0,Y.useState)(new Map);(0,Y.useEffect)(()=>{let e=new Map(k.filter(e=>e.type.startsWith(`image/`)).map(e=>[e,URL.createObjectURL(e)]));return K(e),()=>{for(let t of e.values())URL.revokeObjectURL(t)}},[k]);let q=N({mutationFn:e=>C.post(`/api/studio/wizards`,{projectId:n.id,starterId:e,lang:d}),onSuccess:async({id:n})=>{await t.invalidateQueries({queryKey:[`projects`]}),await t.invalidateQueries({queryKey:[`wizards`]}),e(`/edit/${n}`)}}),J=N({mutationFn:async()=>{let e=B.current??(await C.post(`/api/studio/wizards`,{projectId:n.id,lang:d})).id;B.current=e,D(x)||await C.patch(`/api/studio/wizards/${e}`,{runners:ie(x)});for(let t of k)await ce(e,t);return e},onSuccess:async n=>{await t.invalidateQueries({queryKey:[`projects`]}),await t.invalidateQueries({queryKey:[`wizards`]});let r=_.trim();D(x)||(r+=`\n\n${O(x)}`),k.length&&(r+=`\n\n${o(`editor.attached`)}: ${k.map(e=>e.name).join(`, `)}`),e(`/edit/${n}?prompt=${encodeURIComponent(r)}`)}}),Z=()=>{_.trim()&&n&&!J.isPending&&(H.listening&&H.stop(),J.mutate())};if(!a||n?.readOnly)return(0,X.jsx)(m,{to:`/`,replace:!0});let Q=J.error??q.error;return(0,X.jsxs)(`div`,{className:`animate-rise pt-4`,children:[(0,X.jsxs)(`div`,{className:`mx-auto max-w-2xl`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,X.jsx)(ae,{kind:`sprout`,size:150,fluffy:!0}),(0,X.jsx)(`h1`,{className:`mt-2 font-display font-semibold text-[2rem] leading-tight tracking-tight sm:text-[2.375rem]`,children:o(`new.title`)}),(0,X.jsx)(`p`,{className:`mt-2 text-[0.9375rem] text-ink-3`,children:o(`new.hint`)})]}),(0,X.jsx)(re,{value:x,onChange:E,runners:U.data,className:`mt-8 px-1`}),(0,X.jsxs)(`div`,{className:c(`relative mt-3 rounded-2xl bg-card p-2 shadow-elevated ring-1 ring-border-soft focus-within:ring-focus`,P&&`ring-2 ring-focus`),onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),F(!0))},onDragLeave:()=>F(!1),onDrop:e=>{e.preventDefault(),F(!1),W(Array.from(e.dataTransfer.files).map(b))},children:[k.length?(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 px-2 pt-2 pb-1`,children:k.map((e,t)=>{let n=G.get(e),r=()=>j(e=>e.filter((e,n)=>n!==t));return n?(0,X.jsx)(h,{url:n,label:e.name,children:(0,X.jsx)($,{over:!!n,onClick:r})},`${e.name}-${t}`):(0,X.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-full bg-paper-2 py-1 pr-1 pl-2.5 text-[0.8125rem] text-ink-2`,children:[(0,X.jsx)(l,{className:`size-3.5 shrink-0 text-ink-4`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.name}),(0,X.jsx)($,{over:!!n,onClick:r})]},`${e.name}-${t}`)})}):null,(0,X.jsx)(f,{autoFocus:!0,minRows:4,value:_,onChange:e=>v(e.target.value),onPaste:e=>{let t=Array.from(e.clipboardData.files);t.length&&(e.preventDefault(),W(t.map(b)))},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&Z()},placeholder:H.listening?o(`editor.listening`):o(`new.placeholder`),className:`border-0 bg-transparent text-[1rem] shadow-none focus:ring-0`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-1 pb-1`,children:[(0,X.jsx)(`button`,{type:`button`,"aria-label":o(`editor.attach`),title:o(`editor.attach`),onClick:()=>z.current?.click(),className:`inline-flex size-10 shrink-0 items-center justify-center rounded-full border border-border text-ink transition hover:bg-paper-2 coarse:size-11`,children:(0,X.jsx)(p,{className:`size-4`})}),(0,X.jsx)(`input`,{ref:z,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,W(t)}}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.75rem] text-ink-4`,children:P?o(`new.dropHint`):null}),H.supported?(0,X.jsx)(S,{speech:H}):null,(0,X.jsxs)(w,{size:`md`,onClick:Z,busy:J.isPending,disabled:!_.trim()||q.isPending,children:[o(`new.build`),` `,(0,X.jsx)(te,{className:`size-4`})]})]})]}),H.error?(0,X.jsx)(`p`,{className:`mt-2 px-3 text-[0.75rem] text-rose`,children:H.error===`denied`?o(`editor.micDenied`):H.error}):null,Q?(0,X.jsx)(`p`,{className:`mt-3 text-center text-[0.875rem] text-rose`,children:Q.message}):null,n?(0,X.jsx)(ue,{wish:_,projectId:n.id,busy:q.isPending||J.isPending,onTake:e=>!q.isPending&&q.mutate(e.id),onMore:e=>{L({text:e}),R.current?.scrollIntoView({behavior:`smooth`,block:`start`})}}):null]}),(0,X.jsxs)(`section`,{ref:R,className:`mx-auto max-w-5xl scroll-mt-6`,children:[(0,X.jsx)(`h2`,{className:`mt-16 mb-5 text-center font-medium text-[0.8125rem] text-ink-3 uppercase tracking-[0.08em]`,children:o(`new.orStarter`)}),(0,X.jsx)(oe,{open:u.get(`starter`),search:I,busy:q.isPending,onUse:e=>n&&!q.isPending&&q.mutate(e.id)})]}),(0,X.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,X.jsx)(se,{variant:`ghost`,label:o(`new.import`)})})]})}export{de as NewWizardPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,t as i}from"./logo-C4V2_3Ar.js";import{At as a,Et as o,Qt as s,sn as c,u as l,un as u,xn as d}from"./ui-D2SqIZeQ.js";import{t as f}from"./upload-CCEq88l4.js";import{It as p,Mt as m,Ot as h,Rt as g,dt as _,vn as v}from"./index-BH0PYgov.js";var y=e(t(),1),b=e(n(),1),x=`oklch(50% 0.2 262)`,S=`oklch(32% 0.15 262)`,C={"--on":`white`,"--dot":`oklch(90% 0.1 80)`,"--ink-2":`oklch(96% 0.02 262)`,"--ink-3":`oklch(90% 0.035 262)`,"--moss":`oklch(90% 0.14 150)`,"--rose":`oklch(89% 0.09 45)`},w=`w-full rounded-[18px] border border-white/30 bg-white/15 px-6 py-5 text-[1.375rem] text-white outline-none placeholder:text-white/55 focus:border-white/60`;function T(){return(0,b.jsxs)(`span`,{className:`inline-flex items-center gap-2.5`,children:[(0,b.jsx)(i,{size:28}),(0,b.jsxs)(`span`,{className:`font-display font-semibold text-[1.0625rem] tracking-tight`,children:[`engenty`,(0,b.jsx)(`span`,{className:`mr-[0.09em] ml-[0.06em] text-(color:--dot)`,children:`.`}),(0,b.jsx)(`span`,{className:`font-normal text-white/70`,children:`wizards`})]})]})}function E({children:e,busy:t,onClick:n,type:r=`button`}){return(0,b.jsxs)(`button`,{type:r,disabled:t,onClick:n,className:`inline-flex h-13 cursor-pointer items-center gap-2.5 rounded-full bg-white px-7 font-semibold text-[1rem] transition hover:bg-white/90 disabled:cursor-default disabled:opacity-70`,style:{color:S},children:[e,(0,b.jsx)(u,{className:`size-[18px]`})]})}function D({children:e,onClick:t}){return(0,b.jsx)(`button`,{type:`button`,onClick:t,className:`cursor-pointer font-semibold text-[0.9375rem] text-white/85 transition hover:text-white`,children:e})}function O({step:e}){return(0,b.jsx)(`span`,{className:`ml-auto inline-flex gap-1.5`,role:`img`,"aria-label":a(`onboard.step`,{n:e}),children:[1,2,3,4].map(t=>(0,b.jsx)(`span`,{className:o(`size-2 rounded-full`,t===e?`bg-white`:`bg-white/40`)},t))})}function k(){g(x);let e=m(),t=r(),n=d(),{project:i}=h(),[u,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)([]),B=(0,y.useRef)(null),V=v({mutationFn:e=>l.put(`/api/studio/team`,{name:e}),onSuccess:()=>t.invalidateQueries({queryKey:[`team`]})}),H=v({mutationFn:e=>l.post(`/api/studio/projects/${i?.id}/website`,{url:e}),onSuccess:async e=>{L(e),await t.invalidateQueries({queryKey:[`projects`]})}}),U=v({mutationFn:e=>l.patch(`/api/studio/projects/${i?.id}`,{brand:{about:e}}),onSuccess:()=>t.invalidateQueries({queryKey:[`projects`]})}),W=v({mutationFn:()=>l.post(`/api/studio/onboarding/done`),onSuccess:async()=>{await t.invalidateQueries({queryKey:[`me`]}),n(`/new`,{replace:!0})}}),G=e.data?.user.name??``,K=G.includes(`@`)?``:G.split(` `)[0],q=async e=>{if(e&&i){for(let t of Array.from(e)){z(e=>[...e,{name:t.name,state:`uploading`}]);try{await l.upload(`/api/studio/projects/${i.id}/files?kind=document`,t),z(e=>e.map(e=>e.name===t.name?{...e,state:`done`}:e))}catch{z(e=>e.map(e=>e.name===t.name?{...e,state:`failed`}:e))}}await t.invalidateQueries({queryKey:[`projects`]})}},J=I?[I.about?a(`onboard.readAbout`):``,I.colors?a(`onboard.readColors`,{n:I.colors}):``,I.logo?a(`onboard.readLogo`):``].join(``):``;return(0,b.jsxs)(`div`,{className:`flex min-h-dvh flex-col px-6 text-white sm:px-10`,style:{...C,background:x},children:[(0,b.jsxs)(`header`,{className:`flex items-center justify-between pt-6 sm:pt-8`,children:[(0,b.jsx)(T,{}),(0,b.jsx)(_,{tone:`ground`,ink:S})]}),(0,b.jsxs)(`main`,{className:`mx-auto grid w-full max-w-6xl flex-1 items-center gap-10 py-10 lg:grid-cols-[5fr_7fr] lg:gap-12`,children:[(0,b.jsx)(`div`,{className:`flex justify-center max-lg:order-first`,children:(0,b.jsx)(p,{kind:`drop`,size:240,fluffy:!0,coat:`fur`})}),(0,b.jsxs)(`div`,{className:`flex min-w-0 max-w-2xl animate-rise flex-col gap-5`,children:[u===1?(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault();let t=A.trim();t?V.mutate(t,{onSuccess:()=>k(2)}):k(2)},children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:K?a(`onboard.kicker1`,{name:K}):a(`onboard.kicker1Anon`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:a(`onboard.team`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:a(`onboard.teamSub`)}),(0,b.jsx)(`input`,{value:A,onChange:e=>j(e.target.value),placeholder:a(`onboard.teamPlaceholder`),maxLength:80,"aria-label":a(`onboard.team`),className:w}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{type:`submit`,busy:V.isPending,children:a(`onboard.continue`)}),(0,b.jsx)(O,{step:1})]})]}):null,u===2?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:a(`onboard.kicker2`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:a(`onboard.site`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:a(`onboard.siteSub`)}),P===null?(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault(),M.trim()&&!H.isPending&&H.mutate(M.trim())},children:[(0,b.jsx)(`input`,{value:M,onChange:e=>N(e.target.value),placeholder:a(`onboard.sitePlaceholder`),inputMode:`url`,autoCapitalize:`none`,"aria-label":a(`onboard.site`),className:w}),I?(0,b.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.9375rem] text-(color:--moss)`,children:[(0,b.jsx)(c,{className:`size-4`}),a(`onboard.readDone`,{name:I.name,details:J})]}):H.isError?(0,b.jsx)(`p`,{className:`text-[0.9375rem] text-(color:--rose)`,children:a(`onboard.readFailed`)}):null,(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[I?(0,b.jsx)(E,{onClick:()=>k(3),children:a(`onboard.continue`)}):(0,b.jsx)(E,{type:`submit`,busy:H.isPending,children:H.isPending?a(`onboard.reading`):a(`onboard.read`)}),(0,b.jsx)(D,{onClick:()=>F(``),children:a(`onboard.line`)}),(0,b.jsx)(D,{onClick:()=>k(3),children:a(`onboard.skip`)}),(0,b.jsx)(O,{step:2})]})]}):(0,b.jsxs)(`form`,{className:`contents`,onSubmit:e=>{e.preventDefault();let t=P.trim();t?U.mutate(t,{onSuccess:()=>k(3)}):k(3)},children:[(0,b.jsx)(`textarea`,{value:P,onChange:e=>F(e.target.value),placeholder:a(`onboard.linePlaceholder`),rows:3,maxLength:8e3,"aria-label":a(`onboard.line`),className:o(w,`resize-none text-[1.125rem] leading-relaxed`)}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{type:`submit`,busy:U.isPending,children:a(`onboard.continue`)}),(0,b.jsx)(D,{onClick:()=>F(null),children:a(`onboard.site`)}),(0,b.jsx)(D,{onClick:()=>k(3),children:a(`onboard.skip`)}),(0,b.jsx)(O,{step:2})]})]})]}):null,u===3?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:a(`onboard.kicker3`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:a(`onboard.know`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:a(`onboard.knowSub`)}),(0,b.jsxs)(`button`,{type:`button`,onClick:()=>B.current?.click(),onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),q(e.dataTransfer.files)},className:`flex cursor-pointer flex-col items-center gap-2 rounded-[18px] border-2 border-white/45 border-dashed bg-white/10 px-6 py-7 text-center transition hover:bg-white/15`,children:[(0,b.jsx)(f,{className:`size-7`}),(0,b.jsx)(`span`,{className:`font-semibold text-[1.0625rem]`,children:a(`onboard.drop`)}),(0,b.jsx)(`span`,{className:`text-[0.875rem] text-white/80`,children:`PDF · Word · Excel · Markdown`}),(0,b.jsx)(`input`,{ref:B,type:`file`,multiple:!0,className:`sr-only`,onChange:e=>{q(e.target.files),e.target.value=``}})]}),R.length?(0,b.jsx)(`ul`,{className:`flex flex-col gap-2`,children:R.map(e=>(0,b.jsxs)(`li`,{className:`flex items-center gap-2.5 rounded-xl bg-white/15 px-3.5 py-2.5 text-[0.875rem]`,children:[(0,b.jsx)(s,{className:`size-4 shrink-0`}),(0,b.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,b.jsx)(`span`,{className:o(`text-white/80`,e.state===`failed`?`text-(color:--rose)`:``),children:e.state===`uploading`?a(`onboard.uploading`):e.state===`done`?a(`onboard.uploaded`):a(`onboard.uploadFailed`)})]},e.name))}):null,(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{busy:R.some(e=>e.state===`uploading`),onClick:()=>k(4),children:a(`onboard.continue`)}),R.length?null:(0,b.jsx)(D,{onClick:()=>k(4),children:a(`onboard.skip`)}),(0,b.jsx)(O,{step:3})]})]}):null,u===4?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`p`,{className:`font-medium text-[0.75rem] text-white/85 uppercase tracking-[0.14em]`,children:a(`onboard.kicker4`)}),(0,b.jsx)(`h1`,{className:`font-display font-bold text-[2.5rem] leading-[1.05] tracking-[-0.02em] sm:text-[3.25rem]`,children:a(`onboard.space`)}),(0,b.jsx)(`p`,{className:`text-[1.0625rem] text-white/90 leading-relaxed`,children:a(`onboard.spaceSub`,{space:i?.name??``})}),(0,b.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[[`partInfo`,`partInfoText`,!!(I||P)],[`partKnow`,`partKnowText`,R.some(e=>e.state===`done`)],[`partData`,`partDataText`,!1],[`partResults`,`partResultsText`,!1]].map(([e,t,n])=>(0,b.jsxs)(`div`,{className:`flex flex-col gap-1.5 rounded-2xl border border-white/20 bg-white/10 px-4.5 py-4`,children:[(0,b.jsxs)(`span`,{className:`flex items-center gap-2 font-semibold text-[1rem]`,children:[n?(0,b.jsx)(c,{className:`size-4 text-(color:--moss)`}):null,a(`onboard.${e}`)]}),(0,b.jsx)(`span`,{className:`text-[0.84375rem] text-white/85 leading-snug`,children:a(`onboard.${t}`)})]},e))}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5`,children:[(0,b.jsx)(E,{busy:W.isPending,onClick:()=>W.mutate(),children:a(`onboard.build`)}),(0,b.jsx)(O,{step:4})]})]}):null]},u)]}),(0,b.jsxs)(`footer`,{className:`mx-auto flex w-full max-w-6xl items-center justify-between pb-6 text-[0.75rem] text-white/55 sm:pb-8`,children:[(0,b.jsx)(`span`,{children:`engenty`}),(0,b.jsx)(`span`,{"aria-hidden":`true`,className:`size-[3px] bg-(color:--dot)`})]})]})}export{k as OnboardingPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{$t as a,At as o,Cn as s,Ct as c,E as l,Et as u,Gt as d,Ht as f,Lt as p,Ot as m,Pt as h,Qt as g,Sn as _,St as v,Tt as y,Vt as b,Yt as x,Zt as S,_n as C,_t as w,bn as ee,bt as T,dt as E,en as D,ft as O,gt as k,ht as A,ln as te,mt as j,nn as M,pn as N,pt as P,sn as F,u as I,ut as L,wt as ne,xn as re,xt as R,zt as ie}from"./ui-D2SqIZeQ.js";import{_ as ae,a as oe,b as z,c as se,d as ce,f as B,g as le,h as ue,i as de,l as fe,m as pe,n as V,o as me,p as he,s as ge,u as _e,v as ve,x as H,y as U}from"./RunDrawer-D1I5xqVf.js";import{t as W}from"./phone-Bt1cyWpY.js";import{n as ye,r as be,t as xe}from"./ReadOnly-DTjv2Jzm.js";import{t as G}from"./upload-CCEq88l4.js";import{$ as Se,At as Ce,B as we,G as K,H as Te,I as q,J as Ee,K as De,Kt as Oe,L as J,Ot as ke,Q as Ae,R as je,U as Y,V as Me,Vt as Ne,W as Pe,Wt as Fe,X as Ie,Xt as Le,Y as Re,Yt as ze,Z as X,Zt as Be,_ as Ve,an as He,at as Ue,ct as We,d as Ge,et as Ke,f as qe,g as Je,in as Ye,it as Xe,kt as Ze,l as Qe,mt as $e,nt as et,ot as tt,p as nt,q as rt,rt as it,s as at,st as ot,tt as st,u as ct,un as lt,v as ut,vn as dt,z as ft}from"./index-BH0PYgov.js";import{a as Z,c as pt,f as mt,i as ht,n as gt,o as _t,r as vt,s as yt,t as bt,u as xt}from"./settings-menu-ace1vI3i.js";import{t as St}from"./RunnerView-BPPmlv9z.js";var Ct={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Ct.node;var wt=N(Ct),Tt={name:`box`,size:24,node:[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]};Tt.node;var Et=N(Tt),Dt={name:`case-upper`,size:24,node:[[`path`,{d:`M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5`,key:`nxs35`}],[`path`,{d:`m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16`,key:`d5nyq2`}],[`path`,{d:`M3.304 13h6.392`,key:`1q3zxz`}]]};Dt.node;var Ot=N(Dt),kt={name:`folder-plus`,size:24,node:[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};kt.node;var At=N(kt),jt={name:`grid-2x2`,size:24,node:[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]],aliases:[`grid-2-x-2`]};jt.node;var Mt=N(jt),Nt={name:`layers`,size:24,node:[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]],aliases:[`layers-3`]};Nt.node;var Pt=N(Nt),Ft={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Ft.node;var It=N(Ft),Lt={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};Lt.node;var Rt=N(Lt),zt={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};zt.node;var Bt=N(zt),Vt={name:`music`,size:24,node:[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]};Vt.node;var Ht=N(Vt),Q=e(t(),1),$=e(n(),1),Ut={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function Wt({file:e,actions:t}){let[n,r]=(0,Q.useState)(e.description),i=(0,Q.useRef)(e.description),a=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Q.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let s=e.status===`pending`&&!n;return t.readOnly?n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,$.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:o(s?`project.describing`:`project.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function Gt(e,t){confirm(o(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function Kt({projectId:e,file:t,small:n}){let r=Xe(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:u(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,$.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,$.jsx)(qt,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,$.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,$.jsx)(Ht,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(g,{className:i}):t.mime===`application/json`?(0,$.jsx)(p,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(Et,{className:i}):(0,$.jsx)(S,{className:i}),n?null:(0,$.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function qt({src:e,small:t}){let[n,r]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,$.jsx)(`div`,{className:u(`flex size-full items-center justify-center text-ink`,t?`text-[1.25rem]`:`text-[2.75rem]`),style:n?{fontFamily:`"${n}"`}:void 0,children:`Aa`})}var Jt=`application/x-wizards-logo`;function Yt({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:a,onUpload:s,onPreview:c,mainId:l,onMakeMain:u,moveTo:d,onRemove:f}){let p=e=>f?f(e):Gt(e,r);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,$.jsxs)(`div`,{draggable:d&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(Jt,n.id),className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[n.id===l?(0,$.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,$.jsx)(O,{tone:`ember`,children:o(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?Ut:void 0,children:[c&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${o(`project.preview`)}: ${n.name}`,onClick:()=>c(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(Kt,{projectId:e,file:n})}):(0,$.jsx)(Kt,{projectId:e,file:n}),(0,$.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[c?(0,$.jsx)(A,{label:o(`project.preview`),onClick:()=>c(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(lt,{className:`size-4`})}):null,u&&n.id!==l&&!r.readOnly?(0,$.jsx)(A,{label:o(`project.logoMakeMain`),onClick:()=>u(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(Oe,{className:`size-4`})}):null,d&&!r.readOnly?(0,$.jsx)(we,{options:d.options,value:d.current(n),onChange:e=>d.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:()=>p(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]}),t===`asset`?(0,$.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,$.jsx)(Wt,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,$.jsxs)(je,{accept:i,multiple:!1,onFiles:e=>s?s(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,$.jsx)(R,{className:`size-5`}):(0,$.jsx)(b,{className:`size-5`}),a]}):null]})}function Xt({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,a]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),g=async()=>{c(!0),d(null);try{let a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(p(a.candidates),h([a.candidates[0].url])):d(o(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){d(e.message)}c(!1)},_=async()=>{c(!0),d(null);let e=[];try{for(let n of m){let r=await t(n);r.file&&e.push(r.file)}}catch(e){d(e.message)}c(!1),e.length&&n(e),e.length===m.length&&r()};return(0,$.jsx)(P,{open:!0,onClose:r,wide:f?!0:void 0,title:o(f?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:f?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:o(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:f.map(t=>{let n=m.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>h(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:u(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:Ut,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:u(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(F,{className:`size-3.5`})}):null]},t.url)})}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>p(null),children:o(`run.back`)}),(0,$.jsx)(L,{busy:s,disabled:!m.length,onClick:()=>void _(),children:m.length>1?o(`project.addMany`,{n:m.length}):o(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),l?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:r,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:s,disabled:!i.trim(),children:o(`run.next`)})]})]})})}function Zt(e,t,n){return i({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>I.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function Qt(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var $t=e=>[Qt(e),e.pages?o(`project.pages`,{n:e.pages}):null,it(e.size)].filter(Boolean).join(` · `),en=2e5;function tn({projectId:e,fileId:t,readOnly:n,onGone:i}){let s=r(),c=We(e),l=pe(e),d=tt(e,n),f=c.data?.files.find(e=>e.id===t),p=f?f.mime===`application/pdf`||f.mime.startsWith(`image/`):!1,[m,g]=(0,Q.useState)(null);if(!f)return c.isLoading?(0,$.jsx)(R,{className:`mx-auto text-ink-3`}):null;let _=m??(p?`original`:`text`),v=l.data?.items.find(e=>e.key===`f:${f.id}`),y=Xe(e,f.id),b=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":_===e,onClick:()=>g(e),className:u(`rounded-full px-3 py-1 text-[0.8125rem] transition`,_===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,$.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:f.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:$t(f)}),(0,$.jsx)(`a`,{href:y,target:`_blank`,rel:`noreferrer`,"aria-label":o(`project.openOriginal`),title:o(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(a,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:o(`project.reindex`),onClick:async()=>{await d.reindex(f.id),await s.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(ie,{className:`size-4`})}),(0,$.jsx)(A,{label:o(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(o(`data.confirmDelete`,{title:f.name}))&&(await d.remove(f.id),await s.invalidateQueries({queryKey:[`knowledge`,e]}),i())},children:(0,$.jsx)(h,{className:`size-4`})})]})]}),(0,$.jsx)(B,{projectId:e,itemKey:`f:${f.id}`,has:v?.categories??[],originLabel:v?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(Wt,{file:f,actions:d})}),f.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:f.error}):null,(0,$.jsxs)(E,{className:`flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[p?b(`original`,o(`project.original`)):null,b(`text`,o(`project.readText`))]}),_===`original`?f.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:y,title:f.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:y,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(nn,{projectId:e,file:f})]})]})}function nn({projectId:e,file:t}){let n=Zt(e,t,en);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(R,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(l,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:o(`project.textCut`,{shown:n.data.text.length.toLocaleString(),total:n.data.chars.toLocaleString()})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:o(`project.noText`)})}var rn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,an=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),it(e.size)].filter(Boolean).join(` · `);function on({projectId:e,file:t,actions:n,onClose:r}){let i=Xe(e,t.id);return(0,$.jsxs)(P,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,$.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:an(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":o(`project.openOriginal`),title:o(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(a,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:Ut,children:(0,$.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,$.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,$.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(Wt,{file:t,actions:n})})]})}function sn({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,$.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`${o(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(Kt,{projectId:e,file:t,small:!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:an(t)})]}),(0,$.jsx)(Wt,{file:t,actions:n})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,$.jsx)(A,{label:o(`project.preview`),onClick:i,children:(0,$.jsx)(lt,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(we,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})}function cn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,a]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(P,{open:!0,onClose:r,title:o(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.assetSectionName`)}),(0,$.jsx)(k,{autoFocus:!0,value:i,maxLength:80,placeholder:o(`project.assetSectionTitle`),onChange:e=>a(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(L,{variant:`danger`,onClick:n,children:o(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(L,{variant:`ghost`,onClick:r,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,disabled:!i.trim(),children:o(e?`settings.save`:`project.add`)})]})]})})}function ln({projectId:e,data:t,readOnly:n,sections:r,save:i}){let a=tt(e,n),[s,c]=ot(`assets`,`cards`),[l,u]=(0,Q.useState)(``),[d,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(r),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),S=(0,Q.useRef)(null),C=Ue({assetSections:m},i),w=t.files.filter(e=>e.kind===`asset`),ee=new Map(w.map(e=>[e.id,e])),T=new Set(m.flatMap(e=>e.assets)),E=m.find(e=>e.id===g)??null,D=E?E.assets.map(e=>ee.get(e)).filter(e=>!!e):w.filter(e=>!T.has(e.id)),O=w.find(e=>e.id===d),k=l.trim().toLowerCase(),te=k?D.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(k)):D,j=(e,t)=>h(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),M=async e=>{let t=E?.id??null;for(let n of await a.upload(`asset`,e))j(n.id,t)},N=e=>{confirm(o(`project.removeConfirm`,{name:e.name}))&&(a.remove(e.id),j(e.id,null))},P=m.length?{options:[{value:``,label:o(`project.assetsGeneral`)},...m.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))],current:e=>m.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>j(e.id,t||null)}:void 0,F=[{label:o(`project.assetUpload`),icon:(0,$.jsx)(G,{className:`size-4 shrink-0`}),onPick:()=>S.current?.click()},{label:o(`project.assetFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>x(!0)},...m.length<X.logoSections?[{label:o(`project.assetSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>y(`new`)}]:[]],I=m.length||w.length?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[m.length?(0,$.jsx)(ne,{value:g,onChange:e=>{_(e),u(``)},label:o(`project.assets`),options:[{id:``,label:o(`project.assetsGeneral`)},...m.map(e=>({id:e.id,label:e.title||o(`project.sectionUntitled`)}))]}):null,E&&!n?(0,$.jsx)(A,{label:o(`project.assetSectionRename`),onClick:()=>y(`current`),children:(0,$.jsx)(f,{className:`size-4`})}):null]}),D.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(Te,{value:l,onChange:u,placeholder:o(`project.assetSearch`)})}),(0,$.jsx)(A,{label:o(s===`list`?`project.viewCards`:`project.viewList`),onClick:c,children:s===`list`?(0,$.jsx)(It,{className:`size-4`}):(0,$.jsx)(Bt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(Y,{title:o(`project.assets`),hint:o(`project.assetsHint`),save:C,tabs:I,action:n?null:(0,$.jsx)(q,{entries:F}),children:[(0,$.jsx)(`input`,{ref:S,type:`file`,multiple:!0,accept:rn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&M(t)}}),te.length?s===`cards`?(0,$.jsx)(Yt,{projectId:e,kind:`asset`,files:te,actions:a,moveTo:P,onRemove:N,onPreview:e=>p(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:te.map(t=>(0,$.jsx)(sn,{projectId:e,file:t,actions:a,moveTo:P,onPreview:()=>p(t.id),onRemove:()=>N(t)},t.id))}):D.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`project.staysLocal`)}):(0,$.jsxs)(je,{accept:rn,onFiles:e=>void M(e),className:`h-16 w-full`,children:[a.busy?(0,$.jsx)(R,{className:`size-4`}):(0,$.jsx)(G,{className:`size-4`}),o(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:o(`project.assetAdd`)})]}),a.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error}):null,O?(0,$.jsx)(on,{projectId:e,file:O,actions:a,onClose:()=>p(null)}):null,v?(0,$.jsx)(cn,{section:v===`current`?E:null,onClose:()=>y(null),onSave:e=>{if(v===`current`&&E)h(t=>t.map(t=>t.id===E.id?{...t,title:e}:t));else{let t=K();h(n=>[...n,{id:t,title:e,assets:[]}]),_(t)}},onRemove:v===`current`&&E?()=>{(!E.assets.length||confirm(o(`project.assetSectionRemoveConfirm`,{name:E.title})))&&(h(e=>e.filter(e=>e.id!==E.id)),_(``),y(null))}:void 0}):null,b?(0,$.jsx)(Xt,{kind:`asset`,onClose:()=>x(!1),fetchUrl:e=>a.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)j(t.id,E?.id??null)}}):null]})}var un=/^#[0-9a-fA-F]{6}$/;async function dn(e,t){let[n,r]=[1920,1080],i=document.createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return;let o=e.angle*Math.PI/180,s;if(e.type===`radial`)s=a.createRadialGradient(n/2,r/2,0,n/2,r/2,Math.hypot(n,r)/2);else if(e.type===`conic`)s=a.createConicGradient(o-Math.PI/2,n/2,r/2);else{let e=Math.abs(n*Math.sin(o))+Math.abs(r*Math.cos(o)),[t,i]=[Math.sin(o)*e/2,-Math.cos(o)*e/2];s=a.createLinearGradient(n/2-t,r/2-i,n/2+t,r/2+i)}for(let t of[...e.stops].sort((e,t)=>e.at-t.at))s.addColorStop(Math.min(1,Math.max(0,t.at/100)),t.color);a.fillStyle=s,a.fillRect(0,0,n,r);let c=await new Promise(e=>i.toBlob(e,`image/png`));if(c){let e=document.createElement(`a`);e.href=URL.createObjectURL(c),e.download=`${t||`gradient`}.png`,e.click(),setTimeout(()=>URL.revokeObjectURL(e.href),5e3)}}var fn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function pn({gradient:e,brand:t,onSave:n,onClose:r}){let[i,a]=(0,Q.useState)(e),[s,c]=(0,Q.useState)(Ke(e)),[l,d]=(0,Q.useState)(!1),f=e=>{a(e),c(Ke(e)),d(!1)},p=(e,t)=>f({...i,stops:i.stops.map((n,r)=>r===e?{...n,...t}:n)}),m=e=>{let t=[...i.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));f({...i,stops:[...i.stops,{color:e??t[0]?.color??`#888888`,at:n}]})};return(0,$.jsx)(P,{open:!0,onClose:r,wide:!0,title:o(`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:Ke(i)}}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-48 flex-1`,children:[(0,$.jsx)(w,{children:o(`project.gradientName`)}),(0,$.jsx)(k,{value:i.name,maxLength:80,placeholder:o(`project.gradientNamePlaceholder`),onChange:e=>a({...i,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:Ie.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":i.type===e,onClick:()=>f({...i,type:e}),className:u(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,i.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:o(fn[e])},e))})]}),i.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(w,{children:o(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:i.angle,"aria-label":o(`project.gradientAngle`),onChange:e=>f({...i,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(i.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(v,{value:un.test(e.color)?e.color:`#888888`,onChange:e=>p(t,{color:e.target.value})}),(0,$.jsx)(k,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();un.test(n)&&p(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":o(`project.gradientAt`),onChange:e=>p(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,$.jsx)(A,{label:o(`project.remove`),disabled:i.stops.length<=2,onClick:()=>f({...i,stops:i.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[i.stops.length<12?(0,$.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>m(),children:[(0,$.jsx)(b,{className:`size-4`}),` `,o(`project.gradientStopAdd`)]}):null,t.length&&i.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:o(`project.gradientFromBrand`)}),t.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>m(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:`CSS`}),(0,$.jsx)(k,{value:s,spellCheck:!1,onChange:e=>{c(e.target.value);let t=et(e.target.value);d(!t),t&&a({...i,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:u(`mt-1.5 text-[0.8125rem]`,l?`text-rose`:`text-ink-3`),children:o(l?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:r,children:o(`common.cancel`)}),(0,$.jsx)(L,{onClick:()=>{n(i),r()},children:o(`settings.save`)})]})]})})}var mn=`flex shrink-0 opacity-0 transition focus-within:opacity-100 group-hover/card:opacity-100 coarse:opacity-100`;function hn({gradient:e,readOnly:t,onEdit:n,onRename:r,onRemove:i}){let a=Ke(e),[s,c]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":o(`project.gradientEdit`),onClick:n,className:`h-28 rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-0.5`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:t?(0,$.jsx)(`span`,{className:`text-[0.875rem]`,children:e.name}):(0,$.jsx)(ft,{value:e.name,label:o(`project.gradientName`),placeholder:o(`project.gradientName`),maxLength:80,onChange:r,className:`font-medium text-[0.875rem]`})}),(0,$.jsxs)(`div`,{className:mn,children:[(0,$.jsx)(A,{label:o(s?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),c(!0),setTimeout(()=>c(!1),1500)},className:`size-8`,children:(0,$.jsx)(M,{className:`size-4`})}),(0,$.jsx)(A,{label:o(`project.download`),onClick:()=>void dn(e,e.name),className:`size-8`,children:(0,$.jsx)(D,{className:`size-4`})}),t?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:i,className:`size-8 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})]})}function gn({projectId:e,pattern:t,fileName:n,readOnly:r,onChange:i,onRemove:a}){let s=Xe(e,t.file);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`div`,{className:`h-28 rounded-md ring-1 ring-border-soft`,style:{backgroundImage:`url("${s}")`,backgroundSize:t.tile?`64px`:`cover`,backgroundRepeat:t.tile?`repeat`:`no-repeat`,backgroundPosition:`center`}}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-0.5`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:r?(0,$.jsx)(`span`,{className:`text-[0.875rem]`,children:t.name||n}):(0,$.jsx)(ft,{value:t.name,label:o(`project.patternName`),placeholder:n,maxLength:80,onChange:e=>i({name:e}),className:`font-medium text-[0.875rem]`})}),(0,$.jsxs)(`div`,{className:mn,children:[r?null:(0,$.jsx)(A,{label:t.tile?o(`project.patternFill`):o(`project.patternTile`),"aria-pressed":!!t.tile,onClick:()=>i({tile:!t.tile}),className:u(`size-8`,t.tile&&`bg-paper-2 text-ink`),children:(0,$.jsx)(Mt,{className:`size-4`})}),(0,$.jsx)(`a`,{href:s,download:n,"aria-label":o(`project.download`),title:o(`project.download`),className:`inline-flex size-8 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(D,{className:`size-4`})}),r?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:a,className:`size-8 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})]})}var _n=/^#[0-9a-fA-F]{6}$/;function vn({sections:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(`#e0531b`),[a,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),u=_n.test(r);return(0,$.jsx)(P,{open:!0,onClose:n,title:o(`project.colorAddTitle`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),u&&(t({name:a.trim(),value:r.toLowerCase(),...c?{section:c}:{}}),n())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.colorValue`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(v,{value:u?r:`#888888`,onChange:e=>i(e.target.value)}),(0,$.jsx)(k,{value:r,placeholder:`#e0531b`,spellCheck:!1,onChange:e=>i(e.target.value.trim()),className:`font-mono text-[0.875rem]`})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.colorUseLabel`)}),(0,$.jsx)(k,{autoFocus:!0,value:a,maxLength:120,placeholder:o(`project.colorName`),onChange:e=>s(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.colorUse`)})]}),e.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.colorSectionLabel`)}),(0,$.jsx)(T,{value:c,onChange:l,options:[{value:``,label:o(`project.sectionStandard`)},...e.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))]})]}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:n,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,disabled:!u,children:o(`project.add`)})]})]})})}function yn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)([]),h=async()=>{s(!0),l(null);try{let{colors:t}=await I.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(f(t),m([])):l(o(`project.colorsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(P,{open:!0,onClose:n,wide:d?!0:void 0,title:o(d?`project.colorsFound`:`project.colorsFromUrl`),children:d?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:o(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:d.map(e=>{let t=p.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>m(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:u(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,$.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,$.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(F,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>f(null),children:o(`run.back`)}),(0,$.jsx)(L,{disabled:!p.length,onClick:()=>{t(d.filter(e=>p.includes(e.value))),n()},children:p.length>1?o(`project.addMany`,{n:p.length}):o(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.colorsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:n,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:a,disabled:!r.trim(),children:o(`run.next`)})]})]})})}function bn({projectId:e,data:t,colors:n,sections:r,gradients:i,patterns:a,rules:s,save:c,readOnly:l}){let[u,d]=(0,Q.useState)(()=>n.map(e=>({...e,id:K()}))),[f,p]=(0,Q.useState)(r),[m,g]=(0,Q.useState)(i),[_,y]=(0,Q.useState)(a),[x,S]=(0,Q.useState)(null),C=tt(e,l),w=De(s),[ee,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),N=Ue({colors:u.filter(e=>_n.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:f,gradients:m,patterns:_,colorRules:w.rules},c),P=f.filter(e=>(e.kind??`colors`)===`colors`),F=e=>P.some(t=>t.id===e.section),I=u.filter(e=>!F(e)),L=(I[0]??u[0])?.id,ne=(e,t)=>d(n=>n.map(n=>n.id===e?{...n,...t}:n)),re=e=>d(t=>[...t,...e.map(e=>({...e,id:K()}))].slice(0,X.colors)),ie=[{value:``,label:o(`project.sectionStandard`)},...P.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))],ae=(e,t)=>{let n=K();T(n),p(r=>[...r,{id:n,title:t,description:``,...e===`colors`?{}:{kind:e}}])},oe=e=>({id:K(),name:``,section:e,type:`linear`,angle:90,stops:[{color:u[0]?.value&&_n.test(u[0].value)?u[0].value:`#4b73ff`,at:0},{color:u[1]?.value&&_n.test(u[1].value)?u[1].value:`#ff6d1b`,at:100}]}),z=async(e,t)=>{let n=await C.upload(`pattern`,t);y(t=>[...t,...n.map(t=>({id:K(),name:t.name.replace(/\.[^.]+$/,``),section:e,file:t.id}))])},se=[...u.length<X.colors?[{label:o(`project.colorNew`),icon:(0,$.jsx)(b,{className:`size-4 shrink-0`}),onPick:()=>D(!0)},{label:o(`project.colorsFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>M(!0)}]:[],...f.length<X.logoSections?[{label:o(`project.colorSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>ae(`colors`,``)},{label:o(`project.gradientSectionAdd`),icon:(0,$.jsx)(wt,{className:`size-4 shrink-0`}),onPick:()=>ae(`gradients`,o(`project.gradientSectionTitle`))},{label:o(`project.patternSectionAdd`),icon:(0,$.jsx)(Mt,{className:`size-4 shrink-0`}),onPick:()=>ae(`patterns`,o(`project.patternSectionTitle`))}]:[],...w.full?[]:[{label:o(`project.ruleNew`),icon:(0,$.jsx)(He,{className:`size-4 shrink-0`}),onPick:()=>w.add()}]],ce=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(v,{value:_n.test(e.value)?e.value:`#888888`,onChange:t=>ne(e.id,{value:t.target.value})}),(0,$.jsx)(k,{value:e.name,placeholder:o(`project.colorName`),maxLength:120,onChange:t=>ne(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(k,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>ne(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===L?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(O,{tone:`ember`,children:o(`project.colorAccent`)})}):l?null:(0,$.jsx)(A,{label:o(`project.colorFirst`),onClick:()=>d(t=>[{...e,section:void 0},...t.filter(t=>t.id!==e.id)]),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:(0,$.jsx)(te,{className:`size-4`})}),l||!f.length?null:(0,$.jsx)(we,{options:ie,value:F(e)?e.section??``:``,onChange:t=>ne(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),l?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:()=>d(t=>t.filter(t=>t.id!==e.id)),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]},e.id);return(0,$.jsxs)(Y,{title:o(`project.colors`),hint:o(`project.colorsHint`),save:N,locked:l,action:l?null:(0,$.jsx)(q,{entries:se}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[I.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:I.map(ce)}),l?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.colorUse`)})]}):u.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`project.colorsEmpty`)}),f.map(n=>{let r=n.kind??`colors`,i=u.filter(e=>e.section===n.id),a=m.filter(e=>e.section===n.id),s=_.filter(e=>e.section===n.id),c=r===`gradients`?a.length:r===`patterns`?s.length:i.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(Pe,{title:n.title,description:n.description,titlePlaceholder:o(r===`gradients`?`project.gradientSectionTitlePlaceholder`:r===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),descriptionPlaceholder:o(`project.colorSectionUse`),autoFocus:ee===n.id,readOnly:l,onChange:e=>p(t=>t.map(t=>t.id===n.id?{...t,...e}:t)),onRemove:()=>{if(!c||confirm(o(r===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:n.title||o(`project.sectionUntitled`)}))){p(e=>e.filter(e=>e.id!==n.id)),d(e=>e.map(e=>e.section===n.id?{...e,section:void 0}:e)),g(e=>e.filter(e=>e.section!==n.id));for(let e of s)C.remove(e.file);y(e=>e.filter(e=>e.section!==n.id))}}}),r===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(e=>(0,$.jsx)(hn,{gradient:e,readOnly:l,onEdit:()=>S(e),onRename:t=>g(n=>n.map(n=>n.id===e.id?{...n,name:t}:n)),onRemove:()=>g(t=>t.filter(t=>t.id!==e.id))},e.id)),l||m.length>=X.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>S(oe(n.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(b,{className:`size-5`}),o(`project.gradientAdd`)]})]}):r===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[s.map(n=>(0,$.jsx)(gn,{projectId:e,pattern:n,fileName:t.files.find(e=>e.id===n.file)?.name??`pattern`,readOnly:l,onChange:e=>y(t=>t.map(t=>t.id===n.id?{...t,...e}:t)),onRemove:()=>{C.remove(n.file),y(e=>e.filter(e=>e.id!==n.id))}},n.id)),l?null:(0,$.jsxs)(je,{accept:`image/*`,onFiles:e=>void z(n.id,e),className:`min-h-28 flex-col p-3`,children:[C.busy?(0,$.jsx)(R,{className:`size-5`}):(0,$.jsx)(b,{className:`size-5`}),o(`project.patternAdd`)]})]}):i.length?(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.map(ce)}):null]},n.id)}),(0,$.jsx)(Me,{rules:w,placeholder:o(`project.colorRulePlaceholder`),readOnly:l})]}),C.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:C.error}):null,E?(0,$.jsx)(vn,{sections:P,onClose:()=>D(!1),onAdd:e=>re([e])}):null,x?(0,$.jsx)(pn,{gradient:x,brand:u.filter(e=>_n.test(e.value)),onClose:()=>S(null),onSave:e=>g(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,j?(0,$.jsx)(yn,{projectId:e,onClose:()=>M(!1),onAdd:re}):null]})}var xn=e=>/^(ja|yes|true)$/i.test(e.trim()),Sn={text:Fe,longtext:be,number:z,date:H,url:x,email:Ye,phone:W,boolean:U};function Cn({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{c.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let l=Sn[e??t],d=`${o(`project.factType`)}: ${o(`project.type.${e??t}`)}`,f=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,p=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":d,title:d,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{s(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:u(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,r?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,$.jsx)(l,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:u(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,a?`bottom-12`:`top-12`),children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:f,onClick:()=>p(void 0),children:[(0,$.jsx)(Ne,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:o(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:o(`project.type.${t}`)}),(0,$.jsx)(F,{className:u(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),Ee.map(t=>{let n=Sn[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:f,onClick:()=>p(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:o(`project.type.${t}`)}),(0,$.jsx)(F,{className:u(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function wn({facts:e,save:t,readOnly:n}){let r=(0,Q.useRef)(0),i=(0,Q.useRef)(null),[a,s]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),l=Ue(a.filter(e=>e.key&&e.label.trim()).map(({key:e,label:t,value:n,type:r})=>({key:e,label:t.trim(),value:n,...r?{type:r}:{}})),t),u=(e,t)=>s(n=>n.map(n=>n.id===e?{...n,...t}:n)),d=(e,t,n=!1)=>{let a=`f${r.current++}`;i.current=`${a}:${t}`;let o={id:a,key:``,label:``,value:``,...e};s(e=>n?[o,...e]:[...e,o])},f=e=>t=>{t&&i.current===e&&(i.current=null,t.focus())},p=rt.filter(e=>!a.some(t=>t.key===e.key));return(0,$.jsxs)(Y,{title:o(`project.facts`),hint:o(`project.factsHint`),save:l,locked:n,action:a.length<X.facts&&!n?(0,$.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>d({},`label`,!0),children:[(0,$.jsx)(b,{className:`size-4`}),` `,o(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>{let t=Ae(e.value),r=e.type??t;return(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,$.jsx)(k,{ref:f(`${e.id}:label`),value:e.label,placeholder:o(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>u(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&u(e.id,{key:Se(e.label,a.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(c,{checked:xn(e.value),label:e.label,onChange:t=>u(e.id,{value:o(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:xn(e.value)?o(`project.yes`):o(`project.no`)})]}):(0,$.jsx)(y,{ref:f(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:o(`project.factValue`),onChange:t=>u(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(Cn,{type:e.type,detected:t,onChange:t=>u(e.id,{type:t})}),n?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:()=>s(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]},e.id)})}),a.length<X.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${a.length?`mt-4`:``}`,children:[(0,$.jsxs)(L,{variant:`secondary`,size:`sm`,onClick:()=>d({},`label`),children:[(0,$.jsx)(b,{className:`size-4`}),` `,o(`project.factAdd`)]}),p.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d({key:e.key,label:m===`en`?e.en:e.de},`value`),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,$.jsx)(b,{className:`size-3.5`}),` `,m===`en`?e.en:e.de]},e.key))]}):null]})}function Tn({onLogo:e,children:t,className:n}){let[r,i]=(0,Q.useState)(!1);return e?(0,$.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(Jt);i(!1),n&&(t.preventDefault(),e(n))},className:u(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,$.jsx)(`div`,{className:n,children:t})}function En({projectId:e,data:t,readOnly:n,sections:r,rules:i,save:a}){let s=tt(e,n),[c,l]=(0,Q.useState)(r),u=De(i),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(!1),h=(0,Q.useRef)(null),g=Ue({logoSections:c,logoRules:u.rules},a),_=t.files.filter(e=>e.kind===`logo`),v=new Map(_.map(e=>[e.id,e])),y=new Set(c.flatMap(e=>e.logos)),b=_.filter(e=>!y.has(e.id)),x=st(_,c)?.id,S=(e,t)=>l(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),C=(e,t)=>l(n=>n.map(n=>n.id===e?{...n,...t}:n)),w=async(e,t)=>{let n=await s.upload(`logo`,e);for(let e of n)S(e.id,t)},ee=c.length?{options:[{value:``,label:o(`project.sectionStandard`)},...c.map(e=>({value:e.id,label:e.title||o(`project.sectionUntitled`)}))],current:e=>c.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>S(e.id,t||null)}:void 0,T=(t,n,r)=>(0,$.jsx)(Yt,{projectId:e,kind:`logo`,files:t,actions:s,accept:`image/*`,addLabel:r?o(`project.logoAdd`):void 0,onUpload:e=>void w(e,n),mainId:x,onMakeMain:e=>{S(e.id,null),s.order(`logo`,[e.id,..._.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:ee,onRemove:e=>{confirm(o(`project.removeConfirm`,{name:e.name}))&&(s.remove(e.id),S(e.id,null))}}),E=n?void 0:e=>t=>S(t,e),D=[{label:o(`project.logoUpload`),icon:(0,$.jsx)(G,{className:`size-4 shrink-0`}),onPick:()=>h.current?.click()},{label:o(`project.logoFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>m(!0)},...c.length<X.logoSections?[{label:o(`project.logoSectionAdd`),icon:(0,$.jsx)(At,{className:`size-4 shrink-0`}),onPick:()=>{let e=K();f(e),l(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...u.full?[]:[{label:o(`project.ruleNew`),icon:(0,$.jsx)(He,{className:`size-4 shrink-0`}),onPick:()=>u.add()}]];return(0,$.jsxs)(Y,{title:o(`project.logos`),hint:o(`project.logosHint`),save:g,action:n?null:(0,$.jsx)(q,{entries:D}),children:[(0,$.jsx)(`input`,{ref:h,type:`file`,accept:`image/*`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&w(t,null)}}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(Tn,{onLogo:E?.(null),children:T(b,null,!0)}),c.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(Tn,{onLogo:E?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(Pe,{title:e.title,description:e.description,titlePlaceholder:o(`project.logoSectionTitle`),descriptionPlaceholder:o(`project.logoSectionUse`),autoFocus:d===e.id,readOnly:n,onChange:t=>C(e.id,t),onRemove:()=>{(!e.logos.length||confirm(o(`project.logoSectionRemoveConfirm`,{name:e.title||o(`project.sectionUntitled`)})))&&l(t=>t.filter(t=>t.id!==e.id))}}),T(e.logos.map(e=>v.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),(0,$.jsx)(Me,{rules:u,placeholder:o(`project.logoRulePlaceholder`),readOnly:n})]}),s.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error}):null,p?(0,$.jsx)(Xt,{kind:`logo`,onClose:()=>m(!1),fetchUrl:e=>s.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)S(t.id,null)}}):null]})}var Dn=new Set;function On(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Dn.has(t))return;Dn.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${Re.join(`,`)}&display=swap`,document.head.append(n)},[e])}var kn=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function An({unit:e,label:t,...n}){return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,$.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var jn=`h-8 rounded-md border border-input bg-card px-1.5 text-[0.8125rem] text-ink outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`;function Mn({font:e,first:t,readOnly:n,autoFocus:r,onChange:i,onRemove:a}){return On(e.family),(0,$.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:kn(e.family)},children:[(0,$.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,$.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:e.family}),e.role?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:e.role}):null]}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ft,{value:e.family,label:o(`project.fontFamily`),placeholder:o(`project.fontFamily`),maxLength:80,autoFocus:r,onChange:e=>i({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(ft,{value:e.role,label:o(`project.fontRole`),placeholder:o(t?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>i({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Re.map(t=>{let r=e.weights.includes(t);return(0,$.jsx)(`button`,{type:`button`,disabled:n,"aria-pressed":r,onClick:()=>i({weights:r?e.weights.filter(e=>e!==t):[...e.weights,t].sort((e,t)=>e-t)}),style:{fontFamily:kn(e.family),fontWeight:t},className:u(`h-7 rounded-full px-2.5 text-[0.8125rem] tabular-nums transition`,r?`bg-ink text-paper`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!r&&`hidden`),children:t},t)})}),n?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:a,className:`absolute top-4 right-4 size-8 bg-card opacity-0 shadow-soft transition focus:opacity-100 group-hover/font:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})}function Nn({style:e,fonts:t,sample:n,readOnly:r,autoFocus:i,onChange:a,onRemove:s}){let c=t.find(t=>t.id===e.font)??t[0],l={fontFamily:kn(c?.family),fontWeight:e.weight,fontSize:`${Math.min(e.size,56)}px`,lineHeight:`${e.lineHeight}%`,letterSpacing:`${e.tracking/100}em`,textTransform:e.uppercase?`uppercase`:void 0};return(0,$.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-ink`,style:l,children:n}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,$.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,$.jsx)(`div`,{className:`w-40`,children:(0,$.jsx)(ft,{value:e.name,label:o(`project.styleName`),placeholder:o(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":o(`project.styleFont`),value:c?.id??``,onChange:e=>a({font:e.target.value}),className:u(jn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||o(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":o(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:jn,children:[...new Set([...Re,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(An,{unit:`px`,label:o(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,$.jsx)(An,{unit:o(`project.styleLine`),label:o(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(An,{unit:o(`project.styleTracking`),label:o(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:o(`project.styleUpper`),"aria-label":o(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:u(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,$.jsx)(Ot,{className:`size-4`})})]}),r?null:(0,$.jsx)(A,{label:o(`project.remove`),onClick:s,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(h,{className:`size-4`})})]})]})}function Pn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{s(!0),l(null);try{let{fonts:t}=await I.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(d(t),p(t.slice(0,2).map(e=>e.family))):l(o(`project.fontsNoneFound`))}catch(e){l(e.message)}s(!1)};return(0,$.jsx)(P,{open:!0,onClose:n,wide:u?!0:void 0,title:o(u?`project.fontsFound`:`project.fontsFromUrl`),children:u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:o(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map(e=>(0,$.jsx)(Fn,{font:e,on:f.includes(e.family),onToggle:()=>p(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>d(null),children:o(`run.back`)}),(0,$.jsx)(L,{disabled:!f.length,onClick:()=>{t(u.filter(e=>f.includes(e.family))),n()},children:f.length>1?o(`project.addMany`,{n:f.length}):o(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.logoUrl`)}),(0,$.jsx)(k,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.fontsUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:n,children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:a,disabled:!r.trim(),children:o(`run.next`)})]})]})})}function Fn({font:e,on:t,onToggle:n}){return On(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:u(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:kn(e.family)},children:`Aa`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):o(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(F,{className:`size-3.5`})}):null]})}function In({projectId:e,fonts:t,styles:n,rules:r,sample:i,save:a,readOnly:s}){let[c,l]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(n),f=De(r),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=Ue({fonts:c,textStyles:u,typeRules:f.rules},a),v=(e,t=!1)=>{let n=e.map(e=>({id:K(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&m(n[0].id),l(e=>[...e,...n].slice(0,X.fonts))},y=()=>{let e=K();m(e),d(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},x=[...c.length<X.fonts?[{label:o(`project.fontNew`),icon:(0,$.jsx)(b,{className:`size-4 shrink-0`}),onPick:()=>v([{family:``,weights:[400,700]}],!0)},{label:o(`project.fontsFromUrl`),icon:(0,$.jsx)(Rt,{className:`size-4 shrink-0`}),onPick:()=>g(!0)}]:[],...u.length<X.textStyles?[{label:o(`project.styleNew`),icon:(0,$.jsx)(Le,{className:`size-4 shrink-0`}),onPick:y}]:[],...f.full?[]:[{label:o(`project.ruleNew`),icon:(0,$.jsx)(He,{className:`size-4 shrink-0`}),onPick:()=>f.add()}]];return(0,$.jsxs)(Y,{title:o(`project.typography`),hint:o(`project.typographyHint`),save:_,action:s?null:(0,$.jsx)(q,{entries:x}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[c.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:c.map((e,t)=>(0,$.jsx)(Mn,{font:e,first:t===0,readOnly:s,autoFocus:p===e.id,onChange:t=>l(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>l(t=>t.filter(t=>t.id!==e.id))},e.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:o(`project.fontsEmpty`)}),u.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:o(`project.styles`)}),s?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:o(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:u.map(e=>(0,$.jsx)(Nn,{style:e,fonts:c,sample:i,readOnly:s,autoFocus:p===e.id,onChange:t=>d(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>d(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,(0,$.jsx)(Me,{rules:f,placeholder:o(`project.typeRulePlaceholder`),readOnly:s})]}),h?(0,$.jsx)(Pn,{projectId:e,onClose:()=>g(!1),onAdd:e=>v(e)}):null]})}function Ln({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[i,a]=(0,Q.useState)(e.brand.about??``),s=Ue({name:n.trim(),about:i.trim()},e=>t({brand:e}));return(0,$.jsx)(Y,{title:o(`project.base`),hint:o(`project.baseHint`),save:s,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.title`)}),(0,$.jsx)(k,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(w,{children:o(`project.about`)}),(0,$.jsx)(y,{minRows:4,value:i,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:o(`project.aboutHint`)})]})]})})}function Rn({project:e,group:t,children:n}){let i=r(),a=We(e.id),[s,c]=(0,Q.useState)(0),l=async t=>{await I.patch(`/api/studio/projects/${e.id}`,t),await i.invalidateQueries({queryKey:[`projects`]})},u=dt({mutationFn:()=>I.del(`/api/studio/projects/${e.id}`),onSuccess:()=>i.invalidateQueries({queryKey:[`projects`]})}),d=Ce(),f=Ze(),p=a.data??{files:[],embeddings:!0},m=`${e.id}:${s}`,h=e.readOnly,g=t===`knowledge`;return $e(h?{}:{title:o(g?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:o(g?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:o(g?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:g?[{label:o(`assistant.suggest.knowledgeHow`)},{label:o(`assistant.suggest.knowledgeSite`),fill:!0},{label:o(`assistant.suggest.knowledgeCategories`)}]:[{label:o(`assistant.suggest.readSite`),fill:!0},{label:o(`assistant.suggest.missing`)},{label:o(`assistant.suggest.facts`)}],summary:g?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${p.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>c(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[h?(0,$.jsx)(xe,{children:ye(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(J,{id:`base`,children:(0,$.jsx)(Ln,{project:e,save:l},`base:${m}`)}),(0,$.jsx)(J,{id:`facts`,children:(0,$.jsx)(wn,{facts:e.facts,save:e=>l({facts:e}),readOnly:h},`facts:${m}`)}),(0,$.jsx)(J,{id:`logos`,children:(0,$.jsx)(En,{projectId:e.id,data:p,readOnly:h,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],save:e=>l({brand:e})},`logos:${m}`)}),(0,$.jsx)(J,{id:`colors`,children:(0,$.jsx)(bn,{projectId:e.id,data:p,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],save:e=>l({brand:e}),readOnly:h},`colors:${m}`)}),(0,$.jsx)(J,{id:`typography`,children:(0,$.jsx)(In,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],sample:e.brand.name||o(`project.typeSample`),save:e=>l({brand:e}),readOnly:h},`typography:${m}`)}),(0,$.jsx)(J,{id:`assets`,children:(0,$.jsx)(ln,{projectId:e.id,data:p,readOnly:h,sections:e.brand.assetSections??[],save:e=>l({brand:e})},`assets:${m}`)})]}):null,n,t===`info`&&d&&!h&&f?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(L,{variant:`danger`,busy:u.isPending,onClick:()=>confirm(`${o(`settings.delete`)}?`)&&u.mutate(),children:o(`settings.delete`)}),u.error?(0,$.jsx)(`p`,{className:`mt-2 text-[0.875rem] text-rose`,children:u.error.message}):null]}):null]})}var zn={q:``,mode:``,days:0};function Bn(e,t,n){let r=new URLSearchParams;t&&r.set(`wizard`,t),n.q.trim()&&r.set(`q`,n.q.trim()),n.mode&&r.set(`mode`,n.mode),n.days&&r.set(`days`,String(n.days));let a=r.toString();return i({queryKey:[`results`,e,a],queryFn:()=>I.get(`/api/studio/projects/${e}/results${a&&`?${a}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function Vn({filter:e,onFilter:t}){let[n,r]=(0,Q.useState)(e.q);return(0,Q.useEffect)(()=>{if(n===e.q)return;let r=setTimeout(()=>t({...e,q:n}),250);return()=>clearTimeout(r)},[n,e,t]),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,$.jsx)(ze,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(k,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:o(`space.resultsSearch`),"aria-label":o(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(T,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:o(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(T,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:o(`space.resultsAnyTime`)},{value:`1`,label:o(`space.resultsDay`)},{value:`7`,label:o(`space.resultsDays`,{n:7})},{value:`30`,label:o(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function Hn({data:e,wizardId:t,filter:n,onFilter:r}){let[i,a]=(0,Q.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(m,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Y,{title:t?s(t):o(`space.resultsAll`),hint:o(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(Vn,{filter:n,onFilter:r}),e.runs.length?(0,$.jsx)(E,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,o(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:o(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(d,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(O,{children:`Test`}):(0,$.jsxs)(O,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(E,{children:(0,$.jsx)(j,{children:n.q.trim()||n.mode||n.days?o(`space.resultsNone`):o(`space.resultsEmpty`)})})]}),i?(0,$.jsx)(V,{header:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(i.wizardId)}),i.mode===`test`?(0,$.jsx)(O,{children:`Test`}):(0,$.jsxs)(O,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>a(null),children:(0,$.jsx)(St,{runId:i.id,compact:!0},i.id)}):null]})}function Un({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.name),s=dt({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{label:o(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,$.jsx)(f,{className:`size-4`})}),(0,$.jsx)(P,{open:n,onClose:()=>r(!1),title:o(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&s.mutate()},children:[(0,$.jsx)(k,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),s.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:s.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(L,{variant:`ghost`,onClick:()=>r(!1),children:o(`common.cancel`)}),(0,$.jsx)(L,{type:`submit`,busy:s.isPending,disabled:!i.trim(),children:o(`settings.save`)})]})]})})]})}function Wn({project:e}){let t=r();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(ut,{}),e.readOnly?null:(0,$.jsx)(Un,{project:e,save:async n=>{await I.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function Gn(e){let t=e.join(` `),[n,r]=(0,Q.useState)(e[0]);return(0,Q.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=Je(),i=t.scrollTop>0&&t.clientHeight+t.scrollTop>=t.scrollHeight-4,a=(t===document.documentElement?0:t.getBoundingClientRect().top)+Math.max(120,t.clientHeight/3),o=e[0];for(let t of e){let e=document.getElementById(t)?.getBoundingClientRect().top;e!==void 0&&e<=a&&(o=t)}r(i?e.at(-1):o)},a=()=>{n||=requestAnimationFrame(i)};return i(),window.addEventListener(`scroll`,a,{passive:!0,capture:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,a,{capture:!0}),window.removeEventListener(`resize`,a)}},[t]),n}function Kn(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function qn({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(Z,{icon:e.icon??Be,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(ht,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function Jn(){let{group:e}=_(),[t,n]=s(),r=re(),i=ee(),{hash:a}=i,{project:c,loading:l}=ke(),d=Ce(),f=Qe(),p=xt(),[m,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),x=Ge(e)?e:void 0,S=i.state?.parts===!0,w=nt().map(e=>({...e,to:`/space/${e.id}`})),T=w.find(e=>e.id===x),E=t.get(`show`),D=x?E?2:1:0,O=p?Math.min(D,1):x&&y!==x&&!S?1:0,k=mt(O),A=mt(D),te=(0,Q.useMemo)(()=>({slot:m,narrow:p,setDetail:v}),[m,p]),M=c?c.brand.name?.trim()||c.name:o(`nav.project`),N=x&&x!==`results`?qe(x,f):[],P=x?qe(x,f).filter(e=>e.plugin):[],F=Gn([...N,...x===`results`?P:[]].flatMap(e=>e.sections.map(e=>e.id))),I=x===`results`&&E&&E!==`all`?E:null,[L,ne]=(0,Q.useState)(zn),R=Bn(x===`results`?c?.id:void 0,I,L),ie=R.data?.wizards.find(e=>e.id===I)?.title,z=x===`data`&&E&&E!==`all`||x===`knowledge`&&E&&/^[ptfcvs]:/.test(E)?E:null,B=z?.startsWith(`s:`)?f.spaceSections.find(e=>e.id===z.slice(2)):void 0,V=x===`knowledge`&&z&&/^[ptf]:/.test(z)?z:null,H=se(x===`data`?c?.id:void 0),U=pe(x===`knowledge`?c?.id:void 0),W=ve(z?.startsWith(`v:`)?z.slice(2):``),ye=U.data?.categories.find(e=>e.id===(z?.startsWith(`c:`)?z.slice(2):W.data?.category.id)),be=x===`knowledge`?B?B.label():z?.startsWith(`v:`)?W.data&&`${W.data.category.name}: ${W.data.value}`:z?.startsWith(`c:`)?ye?.name:U.data?.items.find(e=>e.key===z)?.title:H.data?ge(H.data).flatMap(e=>e.items).find(e=>e.key===z)?.title:void 0;Ve([{label:o(`nav.project`),to:`/space`},...T?[{label:T.label,to:`/space/${T.id}`}]:[],...T&&(g??ie??be)?[{label:g??ie??be}]:[]]);let xe={p:`page`,t:`table`,f:`file`,c:`kategorie`,v:`kategorie value`,s:`plugin section`};$e({...x===`data`||x===`results`?{compact:!0}:{},...x===`data`?{suggestions:[{label:o(`assistant.suggest.dataWhat`)},{label:o(`assistant.suggest.dataWho`)},{label:o(`assistant.suggest.dataEdit`)}]}:x===`results`?{suggestions:[{label:o(`assistant.suggest.resultsFailed`)},{label:o(`assistant.suggest.resultsCost`)},{label:o(`assistant.suggest.resultsShare`)}]}:{},...z&&be?{open:{kind:xe[z[0]]??`item`,id:z.slice(2),label:be}}:I&&ie?{open:{kind:`wizard`,id:I,label:ie}}:{}});let G=x===`results`||x===`data`||z?a.slice(1):E||a.slice(1),Se=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${x}#${G}`;G&&Se.current!==e&&document.getElementById(G)&&(Se.current=e,requestAnimationFrame(()=>Kn(G,!1)))},[x,G,c?.id,f.spaceSections]),!x){let t=a.slice(1),n=t?ct(t,f):null;if(n===`knowledge`&&f.spaceSections.some(e=>e.id===t))return(0,$.jsx)(C,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(C,{to:p?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if(t&&f.status!==`ready`)return null;if(e!==void 0||!p)return(0,$.jsx)(C,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(x===`knowledge`&&!E&&f.spaceSections.some(e=>e.id===a.slice(1)))return(0,$.jsx)(C,{to:`/space/knowledge?show=s:${a.slice(1)}`,replace:!0});let we=e=>{if(p){r({search:`?show=${e}`});return}Se.current=`${x}#${e}`,Kn(e,!0),r({search:``,hash:e},{replace:!0})},K=e=>p?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),Te=e=>e.flatMap(e=>e.sections).map(e=>f.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(J,{id:e.id,children:(0,$.jsx)(Y,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(at,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),q=p?void 0:F;return(0,$.jsx)(_t.Provider,{value:te,children:(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`,children:[(0,$.jsxs)(`aside`,{className:u(`min-w-0 md:sticky md:top-6 md:self-start`,p&&D===2&&`hidden`,p&&A===`back`&&pt(`back`)),children:[(0,$.jsx)(gt,{title:M,open:O===1?T??null:null,onBack:()=>p?r(`/space`):b(x??null)}),(0,$.jsx)(`div`,{className:u(pt(k)),children:O===0?(0,$.jsx)(vt,{entries:w,current:p?void 0:T,onPick:()=>b(null)}):(0,$.jsx)(`div`,{ref:h})},O)]}),x?(0,$.jsxs)(`div`,{className:u(`min-w-0`,p&&D<2&&`hidden`,p&&A===`deeper`&&pt(`deeper`)),children:[p?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(bt,{label:T?.label??M,onBack:()=>r(`/space/${x}`)})}):null,d&&c?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(Wn,{project:c})}):null,x===`results`?(0,$.jsxs)(yt,{children:[(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(Z,{icon:Pt,label:o(`space.resultsAll`),selected:!p&&!I,onPick:()=>K(`all`)}),R.data?.wizards.filter(e=>e.results||e.id===I).map(e=>(0,$.jsx)(Z,{icon:Ne,label:e.title,badge:e.results?(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!p&&e.id===I,onPick:()=>K(e.id)},e.id))]}),(0,$.jsx)(qn,{groups:P,current:q,onPick:we})]}):x===`data`?(0,$.jsxs)(yt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(Z,{icon:It,label:o(`data.all`),selected:!p&&!z,onPick:()=>K(`all`)})}),H.data?ge(H.data).map(e=>(0,$.jsx)(ht,{label:e.label,children:e.items.map(e=>(0,$.jsx)(Z,{icon:oe[e.kind],label:e.title,selected:!p&&e.key===z,onPick:()=>K(e.key)},e.key))},e.key)):null,(0,$.jsx)(qn,{groups:P,current:q,onPick:we})]}):x===`knowledge`?(0,$.jsxs)(yt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(Z,{icon:It,label:o(`know.all`),selected:!(p||z),onPick:()=>K(`all`)})}),U.data?.categories.length?(0,$.jsx)(ht,{label:o(`know.categories`),children:U.data.categories.map(e=>(0,$.jsx)(Z,{icon:ue[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!p&&(z===`c:${e.id}`||W.data?.category.id===e.id),onPick:()=>K(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(qn,{groups:P,current:p?void 0:B?.id,onPick:e=>K(`s:${e}`)})]}):(0,$.jsx)(yt,{children:(0,$.jsx)(qn,{groups:N,current:q,onPick:we})}),c&&(x===`info`||x===`knowledge`)?(0,$.jsxs)(Rn,{project:c,group:x,children:[x===`knowledge`?V?V.startsWith(`p:`)?(0,$.jsx)(fe,{pageId:V.slice(2),onGone:()=>K(`all`),onOpen:K},V):V.startsWith(`t:`)?(0,$.jsx)(de,{tableId:V.slice(2),onGone:()=>K(`all`)},V):(0,$.jsx)(tn,{projectId:c.id,fileId:V.slice(2),readOnly:c.readOnly,onGone:()=>K(`all`)},V):U.data?B?(0,$.jsx)(Y,{title:B.label(),hint:B.hint?.(),plain:!0,children:(0,$.jsx)(at,{of:B,children:(0,$.jsx)(B.component,{})})},z):z?.startsWith(`c:`)?ye?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(le,{projectId:c.id,category:ye,readOnly:c.readOnly,onOpen:K,onGone:()=>K(`all`)}),ye.type===`choice`?null:(0,$.jsx)(_e,{projectId:c.id,category:ye,categories:U.data.categories,onOpen:K})]},z):null:z?.startsWith(`v:`)?W.data?(0,$.jsx)(ae,{value:W.data,readOnly:c.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[W.data.items.length?(0,$.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:W.data.items.map(e=>(0,$.jsx)(ce,{item:e,categories:U.data.categories.filter(e=>e.id!==W.data?.category.id),onOpen:K},e.key))}):null,W.data.rows.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>K(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:o(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},z):null:(0,$.jsx)(J,{id:`documents`,children:(0,$.jsx)(he,{projectId:c.id,data:U.data,readOnly:c.readOnly,onOpen:K})}):null:null,x===`info`?Te(P):null]},c.id):null,c&&x===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:z?.startsWith(`t:`)?(0,$.jsx)(de,{tableId:z.slice(2),onGone:()=>K(`all`)},z):z?.startsWith(`p:`)?(0,$.jsx)(fe,{pageId:z.slice(2),onGone:()=>K(`all`)},z):(0,$.jsxs)($.Fragment,{children:[H.data?(0,$.jsx)(me,{projectId:c.id,data:H.data,readOnly:c.readOnly,onOpen:K}):null,Te(P)]})}):null,c&&x===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[R.data?(0,$.jsx)(Hn,{data:R.data,wizardId:I,filter:L,onFilter:ne}):null,R.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:R.error.message}):null,Te(P)]}):null,c||l?null:(0,$.jsx)(j,{children:o(`settings.noProject`)})]}):null]})})})}export{Jn as ProjectPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{r}from"./logo-C4V2_3Ar.js";import{Tt as i,bn as a,bt as o,cn as s,ct as c,dn as l,hn as u,jt as d,kt as f,l as p,lt as m,mt as h,p as g,v as _,yn as v}from"./ui-BOCXzzHi.js";import{a as y,i as b,n as x,o as S,r as C,s as w,t as T}from"./ChatView-uogJ3nht.js";import{Bt as ee,Ft as E,It as D,Lt as O,a as k,n as A,o as j}from"./index-Df6UxElH.js";import{t as M}from"./RunnerView-Deenymq0.js";var N={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};N.node;var te=l(N),P={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};P.node;var F=l(P),I={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};I.node;var L=l(I),R=e(t(),1);function ne(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var z=ne(),re=z?new URLSearchParams(window.location.search).get(`page`):null,B=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),ie=()=>B(`close`);function ae(e){(0,R.useEffect)(()=>{if(z===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>B(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(z===`modal`||z===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&B(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var V=e(n(),1);function H(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function U(e,t){(0,R.useEffect)(()=>{if(!e||!t)return;let n=_(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var W=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,G=W||/Android/.test(navigator.userAgent);function K(){let[e,t]=(0,R.useState)(()=>window.wizardInstall??null),[n,r]=(0,R.useState)(!1);if((0,R.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||G&&!e&&!W)return null;let i=/Mac/.test(navigator.platform),a=f(G?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,V.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{G&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[G?(0,V.jsx)(L,{className:`size-4`}):(0,V.jsx)(te,{className:`size-4`}),f(G?`install.add`:`install.bookmark`)]}),n?(0,V.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function q({brand:e,toggle:t=!0}){return(0,V.jsx)(`header`,{className:`safe-top`,children:(0,V.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,V.jsx)(`img`,{src:_(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,V.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,V.jsx)(`div`,{className:`absolute right-3`,children:(0,V.jsx)(O,{})}):null]})})}function J({siteKey:e,onToken:t}){let n=(0,R.useRef)(null);return(0,R.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,V.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function oe({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||A||z?null:(0,V.jsxs)(`a`,{href:k(`${window.location.origin}${g}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,V.jsx)(F,{className:`size-4`}),` `,f(`install.app`)]})}var Y=e=>`wz.run.${e}`,X=A&&new URLSearchParams(window.location.search).get(`start`)===`1`,Z=z===`inline`?`min-h-80`:`min-h-dvh`;function Q(e,t){let n=v(),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),l=(()=>{try{return localStorage.getItem(Y(e.token))}catch{return null}})();return{busy:r,error:a,captcha:s,setCaptcha:c,start:async()=>{i(!0),o(null);try{let{runId:r}=await p.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:s??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(Y(e.token),r)}catch{}n(`${t}/${r}`,{replace:X})}catch(e){o(e.message),i(!1)}},resume:l?()=>n(`${t}/${l}`):null}}function se({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:i,start:a,resume:c}=Q(e,`/w/${e.token}`),l=X&&e.available&&!e.turnstileSiteKey,u=(0,R.useRef)(!1);return(0,R.useEffect)(()=>{l&&!u.current&&(u.current=!0,a())},[l]),l&&!n?(0,V.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,V.jsx)(o,{})}):(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,V.jsx)(D,{kind:e.avatar,size:190,fluffy:!0}),(0,V.jsx)(`h1`,{className:`mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,V.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(m,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:a,children:[f(`run.start`),` `,(0,V.jsx)(s,{className:`size-4`})]}),e.turnstileSiteKey?(0,V.jsx)(J,{siteKey:e.turnstileSiteKey,onToken:i}):null,c?(0,V.jsx)(`button`,{type:`button`,onClick:c,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.resume`)}):null,(0,V.jsx)(ce,{wizard:e,current:`steps`}),z||A?null:(0,V.jsx)(K,{}),(0,V.jsx)(oe,{token:e.token})]}):(0,V.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??f(`run.unavailable`)}),n?(0,V.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,V.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,V.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:f(`run.orAs`,{label:e.label})},e.id))}):null}function le({wizard:e}){let t=w();return(0,V.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,V.jsx)(`span`,{className:i(t?.speaking&&`animate-breathe`),children:(0,V.jsx)(D,{kind:e.avatar,size:38})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,V.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,V.jsx)(`img`,{src:_(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,V.jsx)(O,{}),z===`popout`?(0,V.jsx)(h,{label:f(`common.close`),onClick:ie,children:(0,V.jsx)(d,{className:`size-5`})}):null]})})}function $({door:e,wizard:t,header:n,footer:r}){let{busy:i,error:a,captcha:o,setCaptcha:c,start:l,resume:u}=Q(t,`/w/${t.token}/${e}`),d=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&d.push({key:e,who:`bot`,node:f(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||d.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??f(`run.unavailable`)}),a&&d.push({key:`error`,who:`bot`,node:a,tone:`error`}),t.available&&d.push(S(`start`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(b,{primary:!0,busy:i,disabled:!!t.turnstileSiteKey&&!o,onClick:()=>void l(),children:[f(`run.start`),` `,(0,V.jsx)(s,{className:`size-4`})]}),u?(0,V.jsx)(b,{onClick:u,children:f(`run.resume`)}):null,t.turnstileSiteKey?(0,V.jsx)(J,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,V.jsxs)(x,{header:n,footer:r,children:[(0,V.jsx)(y,{avatar:t.avatar,lines:d}),(0,V.jsx)(C,{})]})}function ue({className:e}){return(0,V.jsx)(`footer`,{className:i(`text-center text-ink-4`,e),children:(0,V.jsx)(`a`,{href:`${g}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,E.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:s=!1}){let{token:l,runId:d}=a(),h=v(),_=r({queryKey:[`public`,l],queryFn:()=>p.get(`/api/public/wizards/${l}`),retry:(e,t)=>c(t)&&e<3}),y=_.data?.runners??[],b=!_.data||y.some(e=>e.id===`talk`),x=!_.data||y.some(e=>e.id===`video`),S=!_.data||y.some(e=>e.id===`chat`)||n&&b||s&&x,C=y[0]?.id,w=e||z===`popout`||!t&&!d&&S&&(C===`chat`||C===`talk`||C===`video`),O=s&&x||!t&&!e&&!n&&C===`video`,k=!O&&(n&&b||!t&&!e&&C===`talk`),N=O?`video`:k?`talk`:`chat`;if(H(_.data?.brand.accent),ee(_.data?.avatar),U(l,_.data?.title),ae(w),(0,R.useEffect)(()=>{_.data&&(document.title=_.data.title)},[_.data]),(0,R.useEffect)(()=>{l&&d&&j(`run`,{token:l,runId:d})},[l,d]),_.isLoading)return(0,V.jsx)(`div`,{className:i(`flex items-center justify-center text-ink-4`,Z),children:(0,V.jsx)(o,{})});if(e&&_.data&&!S||n&&_.data&&!b||s&&_.data&&!x)return(0,V.jsx)(u,{to:`/w/${l}`,replace:!0});if(!_.data){let e=c(_.error);return(0,V.jsxs)(`div`,{className:i(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Z),children:[(0,V.jsx)(D,{kind:`pebble`,size:80}),(0,V.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:f(e?`common.offline`:`run.notFound`)}),e?(0,V.jsx)(m,{variant:`secondary`,onClick:()=>void _.refetch(),children:f(`common.retry`)}):null]})}if(w){let e=(0,V.jsx)(le,{wizard:_.data}),t=A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,V.jsx)(`div`,{className:`flex h-dvh flex-col`,children:d?(0,V.jsx)(T,{runId:d,talk:k,call:O?`video`:k?`audio`:!1,onRestart:()=>h(`/w/${l}/${N}`),header:O||k?void 0:e,footer:t}):(0,V.jsx)($,{wizard:_.data,header:e,footer:t,door:N})})}return(0,V.jsxs)(`div`,{className:i(`flex flex-col`,Z),children:[z===`inline`||A?null:(0,V.jsx)(q,{brand:_.data.brand,toggle:!z}),(0,V.jsx)(`div`,{className:`flex-1`,children:d?(0,V.jsx)(M,{runId:d,onRestart:()=>h(`/w/${l}`)}):(0,V.jsx)(se,{wizard:_.data})}),A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,V.jsx)(`a`,{href:`${g}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:f(`run.madeWith`).replace(`engenty wizards`,E.name)})})]})}export{q as BrandHeader,de as PublicRunner,H as useBrandAccent};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{r}from"./logo-C4V2_3Ar.js";import{At as i,Et as a,Mt as o,Sn as s,_n as c,ht as l,lt as u,m as d,pn as f,u as p,un as m,ut as h,xn as g,xt as _,y as v}from"./ui-D2SqIZeQ.js";import{a as y,i as b,n as x,o as S,r as C,s as w,t as T}from"./ChatView-CKo_9IZD.js";import{Bt as ee,Ft as E,It as D,Lt as O,a as k,n as A,o as j}from"./index-BH0PYgov.js";import{t as M}from"./RunnerView-BPPmlv9z.js";var N={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};N.node;var te=f(N),P={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};P.node;var F=f(P),I={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};I.node;var L=f(I),R=e(t(),1);function ne(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var z=ne(),re=z?new URLSearchParams(window.location.search).get(`page`):null,B=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),ie=()=>B(`close`);function ae(e){(0,R.useEffect)(()=>{if(z===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>B(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(z===`modal`||z===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&B(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var V=e(n(),1);function H(e){(0,R.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function U(e,t){(0,R.useEffect)(()=>{if(!e||!t)return;let n=v(`/api/public/wizards/${e}`),r=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),i=document.createElement(`meta`);return i.name=`apple-mobile-web-app-title`,i.content=t,document.head.appendChild(i),()=>{for(let{link:e,before:t}of r)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);i.remove()}},[e,t])}var W=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,G=W||/Android/.test(navigator.userAgent);function K(){let[e,t]=(0,R.useState)(()=>window.wizardInstall??null),[n,r]=(0,R.useState)(!1);if((0,R.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||G&&!e&&!W)return null;let a=/Mac/.test(navigator.platform),o=i(G?`install.ios`:a?`install.bookmark.mac`:`install.bookmark.pc`);return(0,V.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{G&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[G?(0,V.jsx)(L,{className:`size-4`}):(0,V.jsx)(te,{className:`size-4`}),i(G?`install.add`:`install.bookmark`)]}),n?(0,V.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:o}):null]})}function q({brand:e,toggle:t=!0}){return(0,V.jsx)(`header`,{className:`safe-top`,children:(0,V.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,V.jsx)(`img`,{src:v(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,V.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,V.jsx)(`div`,{className:`absolute right-3`,children:(0,V.jsx)(O,{})}):null]})})}function J({siteKey:e,onToken:t}){let n=(0,R.useRef)(null);return(0,R.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,V.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function oe({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||A||z?null:(0,V.jsxs)(`a`,{href:k(`${window.location.origin}${d}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,V.jsx)(F,{className:`size-4`}),` `,i(`install.app`)]})}var Y=e=>`wz.run.${e}`,X=A&&new URLSearchParams(window.location.search).get(`start`)===`1`,Z=z===`inline`?`min-h-80`:`min-h-dvh`;function Q(e,t){let n=g(),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),l=(()=>{try{return localStorage.getItem(Y(e.token))}catch{return null}})();return{busy:r,error:a,captcha:s,setCaptcha:c,start:async()=>{i(!0),o(null);try{let{runId:r}=await p.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:s??void 0,embedded:z!==null,origin:re??void 0});try{localStorage.setItem(Y(e.token),r)}catch{}n(`${t}/${r}`,{replace:X})}catch(e){o(e.message),i(!1)}},resume:l?()=>n(`${t}/${l}`):null}}function se({wizard:e}){let{busy:t,error:n,captcha:r,setCaptcha:a,start:o,resume:s}=Q(e,`/w/${e.token}`),c=X&&e.available&&!e.turnstileSiteKey,l=(0,R.useRef)(!1);return(0,R.useEffect)(()=>{c&&!l.current&&(l.current=!0,o())},[c]),c&&!n?(0,V.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,V.jsx)(_,{})}):(0,V.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,V.jsx)(D,{kind:e.avatar,size:190,fluffy:!0}),(0,V.jsx)(`h1`,{className:`mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,V.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(h,{size:`lg`,className:`mt-10 min-w-48`,busy:t,disabled:!!e.turnstileSiteKey&&!r,onClick:o,children:[i(`run.start`),` `,(0,V.jsx)(m,{className:`size-4`})]}),e.turnstileSiteKey?(0,V.jsx)(J,{siteKey:e.turnstileSiteKey,onToken:a}):null,s?(0,V.jsx)(`button`,{type:`button`,onClick:s,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:i(`run.resume`)}):null,(0,V.jsx)(ce,{wizard:e,current:`steps`}),z||A?null:(0,V.jsx)(K,{}),(0,V.jsx)(oe,{token:e.token})]}):(0,V.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??i(`run.unavailable`)}),n?(0,V.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:n}):null]})}function ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,V.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,V.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:i(`run.orAs`,{label:e.label})},e.id))}):null}function le({wizard:e}){let t=w();return(0,V.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,V.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,V.jsx)(`span`,{className:a(t?.speaking&&`animate-breathe`),children:(0,V.jsx)(D,{kind:e.avatar,size:38})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,V.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null]}),e.brand.logoUrl&&z!==`popout`?(0,V.jsx)(`img`,{src:v(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,z?null:(0,V.jsx)(O,{}),z===`popout`?(0,V.jsx)(l,{label:i(`common.close`),onClick:ie,children:(0,V.jsx)(o,{className:`size-5`})}):null]})})}function $({door:e,wizard:t,header:n,footer:r}){let{busy:a,error:o,captcha:s,setCaptcha:c,start:l,resume:u}=Q(t,`/w/${t.token}/${e}`),d=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&d.push({key:e,who:`bot`,node:i(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||d.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??i(`run.unavailable`)}),o&&d.push({key:`error`,who:`bot`,node:o,tone:`error`}),t.available&&d.push(S(`start`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(b,{primary:!0,busy:a,disabled:!!t.turnstileSiteKey&&!s,onClick:()=>void l(),children:[i(`run.start`),` `,(0,V.jsx)(m,{className:`size-4`})]}),u?(0,V.jsx)(b,{onClick:u,children:i(`run.resume`)}):null,t.turnstileSiteKey?(0,V.jsx)(J,{siteKey:t.turnstileSiteKey,onToken:c}):null]}))),(0,V.jsxs)(x,{header:n,footer:r,children:[(0,V.jsx)(y,{avatar:t.avatar,lines:d}),(0,V.jsx)(C,{})]})}function ue({className:e}){return(0,V.jsx)(`footer`,{className:a(`text-center text-ink-4`,e),children:(0,V.jsx)(`a`,{href:`${d}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:i(`run.madeWith`).replace(`engenty wizards`,E.name)})})}function de({chat:e=!1,steps:t=!1,talk:n=!1,video:o=!1}){let{token:l,runId:f}=s(),m=g(),v=r({queryKey:[`public`,l],queryFn:()=>p.get(`/api/public/wizards/${l}`),retry:(e,t)=>u(t)&&e<3}),y=v.data?.runners??[],b=!v.data||y.some(e=>e.id===`talk`),x=!v.data||y.some(e=>e.id===`video`),S=!v.data||y.some(e=>e.id===`chat`)||n&&b||o&&x,C=y[0]?.id,w=e||z===`popout`||!t&&!f&&S&&(C===`chat`||C===`talk`||C===`video`),O=o&&x||!t&&!e&&!n&&C===`video`,k=!O&&(n&&b||!t&&!e&&C===`talk`),N=O?`video`:k?`talk`:`chat`;if(H(v.data?.brand.accent),ee(v.data?.avatar),U(l,v.data?.title),ae(w),(0,R.useEffect)(()=>{v.data&&(document.title=v.data.title)},[v.data]),(0,R.useEffect)(()=>{l&&f&&j(`run`,{token:l,runId:f})},[l,f]),v.isLoading)return(0,V.jsx)(`div`,{className:a(`flex items-center justify-center text-ink-4`,Z),children:(0,V.jsx)(_,{})});if(e&&v.data&&!S||n&&v.data&&!b||o&&v.data&&!x)return(0,V.jsx)(c,{to:`/w/${l}`,replace:!0});if(!v.data){let e=u(v.error);return(0,V.jsxs)(`div`,{className:a(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Z),children:[(0,V.jsx)(D,{kind:`pebble`,size:80}),(0,V.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:i(e?`common.offline`:`run.notFound`)}),e?(0,V.jsx)(h,{variant:`secondary`,onClick:()=>void v.refetch(),children:i(`common.retry`)}):null]})}if(w){let e=(0,V.jsx)(le,{wizard:v.data}),t=A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(ue,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,V.jsx)(`div`,{className:`flex h-dvh flex-col`,children:f?(0,V.jsx)(T,{runId:f,talk:k,call:O?`video`:k?`audio`:!1,onRestart:()=>m(`/w/${l}/${N}`),header:O||k?void 0:e,footer:t}):(0,V.jsx)($,{wizard:v.data,header:e,footer:t,door:N})})}return(0,V.jsxs)(`div`,{className:a(`flex flex-col`,Z),children:[z===`inline`||A?null:(0,V.jsx)(q,{brand:v.data.brand,toggle:!z}),(0,V.jsx)(`div`,{className:`flex-1`,children:f?(0,V.jsx)(M,{runId:f,onRestart:()=>m(`/w/${l}`)}):(0,V.jsx)(se,{wizard:v.data})}),A?(0,V.jsx)(`div`,{className:`safe-bottom`}):(0,V.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,V.jsx)(`a`,{href:`${d}/`,target:z?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:i(`run.madeWith`).replace(`engenty wizards`,E.name)})})]})}export{q as BrandHeader,de as PublicRunner,H as useBrandAccent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{At as n,pn as r}from"./ui-D2SqIZeQ.js";import{t as i}from"./lock-DHBh62LA.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=r(a),s=e(t(),1);function c(e){return n(e.origin===`local`?`readonly.project`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-paper-2 px-4 py-3 text-[0.875rem] text-ink-2 leading-relaxed`,children:[(0,s.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{At as a,Ct as o,E as s,Et as c,Gt as l,Jt as u,Mt as d,Ot as f,Pt as p,Qt as m,Tt as h,Vt as g,_t as _,bt as v,ct as y,dt as b,ft as x,gt as S,ht as C,in as w,mt as T,on as E,pn as D,pt as O,sn as k,u as A,ut as j,xt as M,yt as N,zt as P}from"./ui-D2SqIZeQ.js";import{t as ee}from"./upload-CCEq88l4.js";import{Gt as te,H as ne,R as re,U as F,Wt as ie,at as ae,it as I,ot as oe,vn as L}from"./index-BH0PYgov.js";var se={name:`calendar`,size:24,node:[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]};se.node;var ce=D(se),le={name:`files`,size:24,node:[[`path`,{d:`M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8`,key:`14sh0y`}],[`path`,{d:`M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z`,key:`1970lx`}],[`path`,{d:`M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1`,key:`l4dndm`}]]};le.node;var ue=D(le),de={name:`hash`,size:24,node:[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]};de.node;var fe=D(de),R={name:`list-ordered`,size:24,node:[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]};R.node;var pe=D(R),z={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};z.node;var B=D(z),V={name:`minimize-2`,size:24,node:[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]};V.node;var me=D(V),he={name:`tags`,size:24,node:[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]};he.node;var ge=D(he),_e={name:`toggle-left`,size:24,node:[[`circle`,{cx:`9`,cy:`12`,r:`3`,key:`u3jwor`}],[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`7`,key:`g7kal2`}]]};_e.node;var H=D(_e),U=e(t(),1),W=e(n(),1),G={choice:ge,date:ce,number:fe,text:ie,boolean:H},K=e=>[`knowledge`,e];function ve(e){return e===1?a(`know.item`):a(`know.items`,{n:e})}function q(e,t){if(e.type===`boolean`||typeof t==`boolean`)return a(t?`know.yes`:`know.no`);if(e.type===`date`&&typeof t==`string`){let[e,n]=t.split(` `),r=new Date(`${e}T00:00:00`),i=Number.isNaN(r.getTime())?t:r.toLocaleDateString(f,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(f)}${e.unit?` ${e.unit}`:``}`:String(t)}function ye(e,t){return e.flatMap(e=>{let n=t.find(t=>t.categoryId===e.id);return n?e.type===`boolean`?n.values[0]===!0?[e.name]:[]:[n.values.map(t=>q(e,t)).join(`, `)]:[]}).join(` · `)}function be({trigger:e,open:t,onOpen:n,children:r}){let i=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!t)return;let e=e=>{i.current?.contains(e.target)||n(!1)},r=e=>e.key===`Escape`&&n(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,r)}},[t,n]),(0,W.jsxs)(`div`,{ref:i,className:`relative inline-flex`,children:[e,t?(0,W.jsx)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:r}):null]})}function xe({category:e,current:t,onSave:n}){let[r,i]=(0,U.useState)(t[0]===void 0?``:String(t[0]));if(e.type===`choice`){let o=t.map(String);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[e.values.length?(0,W.jsx)(N,{multi:!0,value:o,options:e.values.map(e=>e.value),onChange:t=>n(e.multiple?t:t.filter(e=>!o.includes(e)).slice(0,1))}):null,(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),r.trim()&&n(e.multiple?[...o,r.trim()]:[r.trim()])},children:[(0,W.jsx)(S,{"data-autofocus":!0,value:o.includes(r)?``:r,placeholder:a(`know.addValue`),onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(C,{label:a(`know.addValue`),type:`submit`,children:(0,W.jsx)(g,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,W.jsx)(N,{value:t[0]===!0?a(`know.yes`):t[0]===!1?a(`know.no`):``,options:[a(`know.yes`),a(`know.no`)],onChange:e=>n([e===a(`know.yes`)])}):(0,W.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(r.trim()?[e.type===`number`?Number(r.replace(`,`,`.`)):r.trim()]:[])},children:[(0,W.jsx)(S,{"data-autofocus":!0,type:e.type===`date`?`date`:e.type===`number`?`number`:`text`,step:`any`,value:e.type===`date`?r.slice(0,10):r,onChange:e=>i(e.target.value),className:`h-9`}),(0,W.jsx)(j,{type:`submit`,size:`sm`,children:`OK`})]})}function Se({projectId:e,itemKey:t,has:n,categories:i,readOnly:o}){let s=r(),[c,l]=(0,U.useState)(null),[u,f]=(0,U.useState)(n);(0,U.useEffect)(()=>f(n),[n]);let p=L({mutationFn:({categoryId:n,next:r})=>A.put(`/api/studio/projects/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>s.invalidateQueries({queryKey:K(e)})}),m=i.filter(e=>!(e.proposed||e.tableId)),h=(e,t)=>{f(n=>[...n.filter(t=>t.categoryId!==e.id),...t.length?[{categoryId:e.id,values:t,by:`person`}]:[]]),p.mutate({categoryId:e.id,next:t}),l(null)},_=m.filter(e=>u.some(t=>t.categoryId===e.id)),v=m.filter(e=>!u.some(t=>t.categoryId===e.id));return m.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[_.map(e=>{let t=u.find(t=>t.categoryId===e.id),n=G[e.type],r=(0,W.jsxs)(`button`,{type:`button`,disabled:o,title:`${e.name} · ${a(`know.by.${t.by}`)}`,onClick:()=>l(c===e.id?null:e.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink disabled:pointer-events-none`,children:[(0,W.jsx)(n,{className:`size-3.5 text-ink-3`}),(0,W.jsx)(`span`,{className:`text-ink-3`,children:e.name}),(0,W.jsx)(`span`,{className:`font-medium`,children:t.values.map(t=>q(e,t)).join(`, `)})]},e.id);return o?(0,W.jsx)(`span`,{children:r},e.id):(0,W.jsxs)(be,{trigger:r,open:c===e.id,onOpen:t=>l(t?e.id:null),children:[(0,W.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:e.name}),(0,W.jsx)(C,{label:a(`know.remove`),onClick:()=>h(e,[]),className:`size-7`,children:(0,W.jsx)(d,{className:`size-3.5`})})]}),(0,W.jsx)(xe,{category:e,current:t.values,onSave:t=>h(e,t)})]},e.id)}),o||!v.length?null:(0,W.jsx)(be,{open:c===`+`,onOpen:e=>l(e?`+`:null),trigger:(0,W.jsxs)(`button`,{type:`button`,onClick:()=>l(c===`+`?null:`+`),className:`inline-flex h-7 items-center gap-1 rounded-full px-2 text-[0.75rem] text-ink-3 ring-1 ring-border-soft transition hover:text-ink hover:ring-border`,children:[(0,W.jsx)(g,{className:`size-3.5`}),` `,a(`know.category`)]}),children:(0,W.jsx)(Ce,{categories:v,onSave:h})})]}):null}function Ce({categories:e,onSave:t}){let[n,r]=(0,U.useState)(e[0]?.id??``),i=e.find(e=>e.id===n);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,W.jsx)(v,{value:n,onChange:r,options:e.map(e=>({value:e.id,label:e.name}))}),i?(0,W.jsx)(xe,{category:i,current:[],onSave:e=>t(i,e)},i.id):null]})}function we({projectId:e,open:t,onClose:n,onMade:i}){let s=r(),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(`choice`),[f,p]=(0,U.useState)(``),[m,g]=(0,U.useState)(!1),[y,b]=(0,U.useState)(!1),[x,C]=(0,U.useState)(``),[w,T]=(0,U.useState)(``),E=L({mutationFn:()=>A.post(`/api/studio/projects/${e}/categories`,{name:c.trim(),type:u,unit:u===`number`&&f.trim()||null,multiple:u===`choice`&&m,ordered:u===`choice`&&y,hint:w.trim()||null,values:u===`choice`?x.split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await s.invalidateQueries({queryKey:K(e)}),l(``),C(``),T(``),i(t)}});return(0,W.jsx)(O,{open:t,onClose:n,title:a(`know.newCategory`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),c.trim()&&E.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`know.name`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:c,maxLength:80,onChange:e=>l(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`know.type`)}),(0,W.jsx)(v,{value:u,onChange:e=>d(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:a(`know.type.${e}`)}))})]}),u===`number`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{hint:a(`know.unitHint`),children:a(`know.unit`)}),(0,W.jsx)(S,{value:f,maxLength:20,onChange:e=>p(e.target.value)})]}):null,u===`choice`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{hint:a(`know.valuesHint`),children:a(`know.values`)}),(0,W.jsx)(h,{minRows:3,value:x,onChange:e=>C(e.target.value)})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[a(`know.multiple`),(0,W.jsx)(o,{checked:m,onChange:g})]}),(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[a(`know.ordered`),(0,W.jsx)(o,{checked:y,onChange:b})]})]}):null,(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{hint:a(`know.hintFieldHint`),children:a(`know.hintField`)}),(0,W.jsx)(S,{value:w,maxLength:120,onChange:e=>T(e.target.value)})]}),E.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:E.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(j,{variant:`ghost`,onClick:n,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:E.isPending,disabled:!c.trim(),children:a(`know.create`)})]})]})})}function Te({projectId:e,category:t,readOnly:n,onOpen:i,onGone:o}){let s=r(),c=()=>s.invalidateQueries({queryKey:K(e)}),[l,u]=(0,U.useState)(``),d=L({mutationFn:e=>e(),onSuccess:c}),f=G[t.type],m=new Map(t.values.map(e=>[e.id,e]));return(0,W.jsxs)(F,{title:t.name,hint:[a(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,W.jsx)(C,{label:a(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(a(`know.confirmCategory`,{name:t.name}))&&d.mutate(async()=>{await A.del(`/api/studio/categories/${t.id}`),o()}),children:(0,W.jsx)(p,{className:`size-4`})}),children:[t.proposed&&!n?(0,W.jsxs)(b,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(x,{tone:`ember`,children:a(`know.proposed`)}),(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:a(`know.proposedHint`)}),(0,W.jsx)(j,{size:`sm`,onClick:()=>d.mutate(()=>A.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:a(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=m.get(e),i=m.get(t);if(!(r&&i))return null;let[o,s]=r.count<i.count?[r,i]:[i,r];return(0,W.jsxs)(b,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,W.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:a(`know.alike`,{a:o.value,b:s.value})}),n?null:(0,W.jsx)(j,{size:`sm`,variant:`secondary`,busy:d.isPending,onClick:()=>d.mutate(()=>A.post(`/api/studio/values/${o.id}/merge`,{into:s.id})),children:a(`know.merge`)})]},`${e}:${t}`)}),(0,W.jsxs)(b,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(`v:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,W.jsx)(x,{children:a(`know.summary`)}):null,(0,W.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:ve(e.count)})]},e.id)):(0,W.jsx)(T,{children:a(`know.empty`)}):(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,W.jsx)(f,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?a(`know.range`,{min:q(t,t.range.min),max:q(t,t.range.max)}):a(`know.unset`)}),(0,W.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:ve(t.count)})]}),t.type===`choice`&&!n?(0,W.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=l.trim();n&&(u(``),d.mutate(()=>A.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,W.jsx)(S,{value:l,placeholder:a(`know.addValue`),onChange:e=>u(e.target.value),className:`h-9`}),(0,W.jsx)(C,{label:a(`know.addValue`),type:`submit`,children:(0,W.jsx)(g,{className:`size-4`})})]}):null]}),d.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null]})}function Ee(e){return i({queryKey:[`knowledge-value`,e],queryFn:()=>A.get(`/api/studio/values/${e}`),enabled:!!e})}function De({value:e,readOnly:t,children:n}){let i=r(),o=L({mutationFn:()=>A.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>i.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,W.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,W.jsx)(F,{title:a(`know.summary`),hint:a(`know.summaryHint`),plain:!0,action:t?null:(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,busy:o.isPending,onClick:()=>o.mutate(),children:[e.summary?(0,W.jsx)(P,{className:`size-4`}):null,e.summary?a(`know.summaryAgain`):a(`know.summaryWrite`)]}),children:(0,W.jsxs)(b,{className:`p-4 sm:p-5`,children:[o.isPending?(0,W.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,W.jsx)(M,{})}):e.summary?(0,W.jsx)(s,{text:e.summary,className:`text-[0.875rem]`}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:a(`know.summaryEmpty`)}),o.error?(0,W.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null]})}),(0,W.jsx)(F,{title:a(`know.toc`),plain:!0,children:n})]})}function Oe(e){return i({queryKey:[`knowledge`,e],queryFn:()=>A.get(`/api/studio/projects/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function ke(e){return e.kind===`table`?e.format===`faq`?B:te:e.kind===`file`?l:e.children?ue:m}function J({item:e,categories:t,onOpen:n}){let r=ke(e),i=[ye(t,e.categories),e.children?e.children===1?a(`know.oneSub`):a(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?a(`know.row`):a(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e.key),disabled:e.status===`pending`,className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,W.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,W.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,W.jsx)(M,{className:`size-3`}),` `,a(`know.reading`)]}):e.review?(0,W.jsx)(x,{tone:`warn`,title:e.review,children:a(`know.review`)}):null]})}function Y({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:o,file:s,readOnly:c,onReviewed:u}){let d=Oe(e),f=[r?a(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[d.data?(0,W.jsx)(Se,{projectId:e,itemKey:t,has:n,categories:d.data.categories,readOnly:c}):null,f.length||s||o?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.8125rem] text-ink-3`,children:[f.map(e=>(0,W.jsx)(`span`,{children:e},e)),s?(0,W.jsxs)(`a`,{href:I(e,s.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,W.jsx)(l,{className:`size-3.5`}),` `,a(`know.original`),`: `,s.name]}):null,o?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(x,{tone:`warn`,children:a(`know.review`)}),(0,W.jsx)(`span`,{children:o}),c?null:(0,W.jsx)(`button`,{type:`button`,onClick:u,className:`underline hover:text-ink`,children:a(`know.reviewed`)})]}):null]}):null]})}function Ae(e){let t=e.filter(Number.isFinite).sort((e,t)=>e-t);if(new Set(t).size<=4)return[];let n=t[0],r=t.at(-1),i=e=>e.slice(0,-1).map((t,n)=>({lo:t,hi:e[n+1]})).filter(e=>t.some(t=>t>=e.lo&&t<e.hi));if(n>0&&r/n>=30){let e=Math.floor(Math.log10(n)),t=Math.floor(Math.log10(r))+1;for(let a of[[1,2,5],[1,3],[1]]){let o=[];for(let n=e;n<=t;n++)for(let e of a)o.push(e*10**n);let s=i(o.filter((e,t)=>e<=n||o[t-1]<=r));if(s.length<=7)return s}}let a=(r-n)/5,o=10**Math.floor(Math.log10(a)),s=([1,2,2.5,5,10].map(e=>e*o).find(e=>e>=a)??a)||1,c=[];for(let e=Math.floor(n/s)*s;e<=r;e+=s)c.push(e);return c.push(c.at(-1)+s),i(c)}function je({projectId:e,category:t,categories:n,onOpen:r}){let o=i({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>A.get(`/api/studio/categories/${t.id}/items`)});if(!o.data)return o.isLoading?(0,W.jsx)(M,{className:`mx-auto size-4 text-ink-3`}):null;let s=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],c=[...o.data.items].sort((e,t)=>{let n=s(e),r=s(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),f)}),l=t.type===`number`?Ae(c.map(s).filter(e=>typeof e==`number`)):[],u=new Intl.NumberFormat(f,{notation:`compact`,maximumFractionDigits:1}),d=t.unit?` ${t.unit}`:``,p=new Map;for(let e of c){let n=s(e),r=typeof n==`number`?l.find(e=>n>=e.lo&&n<e.hi):void 0,i=n===void 0?``:t.type===`date`?new Date(`${String(n).slice(0,7)}-01T00:00:00`).toLocaleDateString(f,{month:`long`,year:`numeric`}):r?a(`know.range`,{min:`${u.format(r.lo)}${d}`,max:`${u.format(r.hi)}${d}`}):q(t,n);p.set(i,[...p.get(i)??[],e])}return(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...p].map(([e,t])=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,W.jsx)(J,{item:e,categories:n,onOpen:r},e.key))})]},e)),o.data.rows.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>r(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:a(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function Me(e,t,n){return Array.isArray(n)?t.some(e=>n.map(String).includes(String(e))):typeof n==`object`&&n?t.some(t=>{if(e.type===`number`&&typeof t==`number`)return(n.gte===void 0||t>=n.gte)&&(n.lte===void 0||t<=n.lte);if(e.type===`date`){let e=String(t).slice(0,10);return(!n.after||e>=n.after)&&(!n.before||e<=n.before)}return!n.contains||String(t).toLowerCase().includes(n.contains.toLowerCase())}):t.some(e=>e===n)}function Ne(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return a(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${a(`know.contains`)} ${t.contains}`:[n===void 0?``:`${a(`know.minimum`)} ${q(e,n)}`,r===void 0?``:`${a(`know.maximum`)} ${q(e,r)}`].filter(Boolean).join(` `)}return String(t)}function Pe({category:e,value:t,onChange:n}){let[r,i]=(0,U.useState)(!1),o=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!r)return;let e=e=>!o.current?.contains(e.target)&&i(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]);let s=G[e.type],l=typeof t==`object`&&t&&!Array.isArray(t)?t:{},u=(t,r)=>{let i={...l,[t]:r===``?void 0:e.type===`number`?Number(r):r},a=Object.fromEntries(Object.entries(i).filter(([,e])=>e!==void 0));n(Object.keys(a).length?a:void 0)};return(0,W.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:c(`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-[0.8125rem] transition`,t===void 0?`text-ink-2 ring-1 ring-border-soft hover:ring-border`:`bg-ember-tint text-ink ring-1 ring-ember/30`),children:[(0,W.jsx)(s,{className:`size-3.5 text-ink-3`}),e.name,t===void 0?null:(0,W.jsxs)(`span`,{className:`font-medium`,children:[`: `,Ne(e,t)]}),(0,W.jsx)(E,{className:`size-3.5 text-ink-3`})]}),r?(0,W.jsxs)(`div`,{className:`absolute top-full left-0 z-30 mt-1.5 w-72 max-w-[calc(100vw-32px)] rounded-xl bg-card p-3 shadow-overlay ring-1 ring-border-soft`,children:[e.type===`choice`?(0,W.jsx)(N,{multi:!0,value:Array.isArray(t)?t.map(String):[],options:e.values.map(e=>e.value),onChange:e=>n(e.length?e:void 0)}):e.type===`boolean`?(0,W.jsx)(N,{value:t===!0?a(`know.yes`):t===!1?a(`know.no`):``,options:[a(`know.yes`),a(`know.no`)],onChange:e=>n(e===a(`know.yes`))}):e.type===`text`?(0,W.jsx)(S,{"data-autofocus":!0,value:l.contains??``,placeholder:a(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:`h-9`}):(0,W.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(n===0?`know.minimum`:`know.maximum`)}),(0,W.jsx)(S,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(l[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>u(t,e.target.value),className:`h-9`})]},t))}),t===void 0?null:(0,W.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),i(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:a(`know.clear`)})]}):null]})}function Fe({found:e,onOpen:t}){return e.hits.length?(0,W.jsxs)(`div`,{className:`flex flex-col`,children:[(0,W.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:e.checked?a(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):a(`know.searchUnchecked`,{hits:e.hits.length})}),e.hits.map(e=>{let n=e.open;return(0,W.jsxs)(`button`,{type:`button`,disabled:!n,onClick:()=>n&&t(n),className:`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent disabled:pointer-events-none`,children:[(0,W.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,W.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,W.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,W.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(f,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,W.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:a(`know.searchNone`)})}function Ie({kind:e,projectId:t,onClose:n,onMade:i}){let s=r(),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(!1),f=L({mutationFn:()=>A.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:c.trim(),...e===`table`&&u?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await s.invalidateQueries({queryKey:[`knowledge`,t]}),i(`${e===`table`?`t`:`p`}:${n}`),l(``),d(!1)}});return(0,W.jsx)(O,{open:e!==null,onClose:n,title:a(e===`table`?`know.newTable`:`know.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),c.trim()&&f.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.title`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:c,maxLength:120,onChange:e=>l(e.target.value)})]}),e===`table`?(0,W.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[a(`know.asFaq`),(0,W.jsx)(o,{checked:u,onChange:d})]}):null,f.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(j,{variant:`ghost`,onClick:n,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:f.isPending,disabled:!c.trim(),children:a(`know.create`)})]})]})})}function Le({projectId:e,data:t,readOnly:n,onOpen:i}){let o=r(),s=oe(e,n),[c,l]=(0,U.useState)({}),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(!1),[_,v]=(0,U.useState)(null),y=t.categories.filter(e=>!e.proposed&&e.count>0),S=t.categories.filter(e=>e.proposed),C=t.items.filter(e=>Object.entries(c).every(([n,r])=>{let i=t.categories.find(e=>e.name===n),a=e.categories.find(e=>e.categoryId===i?.id);return i&&a?Me(i,a.values,r):!1})),w=async()=>{if(!u.trim()){p(null);return}h(!0);try{p(await A.post(`/api/studio/projects/${e}/search`,{query:u,...Object.keys(c).length?{where:c}:{}}))}catch{p({hits:[],candidates:0,checked:!1,filtered:null})}finally{h(!1)}},E=L({mutationFn:({id:e,keep:t})=>t?A.patch(`/api/studio/categories/${e}`,{proposed:!1}):A.del(`/api/studio/categories/${e}`),onSuccess:()=>o.invalidateQueries({queryKey:[`knowledge`,e]})});return(0,W.jsxs)(F,{title:a(`know.title`),hint:a(`know.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>v(`page`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.page`)]}),(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>v(`table`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.table`)]}),(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>v(`category`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.category`)]})]}),children:[S.length&&!n?(0,W.jsx)(b,{className:`flex flex-col gap-2 p-4`,children:S.map(e=>{let t=G[e.type];return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,W.jsx)(x,{tone:`ember`,children:a(`know.proposed`)}),(0,W.jsx)(t,{className:`size-4 text-ink-3`}),(0,W.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[a(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,W.jsx)(j,{size:`sm`,variant:`ghost`,onClick:()=>E.mutate({id:e.id,keep:!1}),children:a(`know.dismiss`)}),(0,W.jsx)(j,{size:`sm`,onClick:()=>E.mutate({id:e.id,keep:!0}),children:a(`know.accept`)})]},e.id)})}):null,t.items.length?(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsx)(ne,{value:u,placeholder:a(`know.search`),busy:m,onEnter:()=>void w(),onChange:e=>{d(e),e.trim()||p(null)}}),y.length?(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[y.map(e=>(0,W.jsx)(Pe,{category:e,value:c[e.name],onChange:t=>{p(null),l(n=>{let r={...n};return t===void 0?delete r[e.name]:r[e.name]=t,r})}},e.id)),Object.keys(c).length?(0,W.jsx)(`button`,{type:`button`,onClick:()=>l({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:a(`know.clear`)}):null]}):null]}):null,(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:f?(0,W.jsx)(Fe,{found:f,onOpen:i}):C.length?C.map(e=>(0,W.jsx)(J,{item:e,categories:t.categories,onOpen:i},e.key)):(0,W.jsx)(T,{children:a(`know.empty`)})}),n?null:(0,W.jsxs)(re,{accept:`.pdf,.docx,.doc,.xlsx,.csv,.tsv,.txt,.md,.json,.html,.eml,image/*`,onFiles:async t=>{await s.upload(`document`,t),await o.invalidateQueries({queryKey:[`knowledge`,e]})},className:`h-14 w-full`,children:[s.busy?(0,W.jsx)(M,{className:`size-4`}):(0,W.jsx)(ee,{className:`size-4`}),a(`know.drop`),` `,(0,W.jsx)(`span`,{className:`underline`,children:a(`know.pick`)})]}),s.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,W.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:a(`know.keywordsOnly`),t.checked?``:a(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,W.jsx)(Ie,{kind:_===`page`||_===`table`?_:null,projectId:e,onClose:()=>v(null),onMade:e=>{v(null),i(e)}}),(0,W.jsx)(we,{projectId:e,open:_===`category`,onClose:()=>v(null),onMade:e=>{v(null),i(`c:${e}`)}})]})}function Re({page:e,onGone:t,onOpen:n}){let i=r(),[o,l]=(0,U.useState)(e.title),[u,d]=(0,U.useState)(e.markdown),[f,h]=(0,U.useState)(e.markdown?`read`:`write`),_=e.knowledge,v=async()=>{await i.invalidateQueries({queryKey:[`space-data`,e.projectId]}),await i.invalidateQueries({queryKey:[`knowledge`,e.projectId]})},y=ae({title:o.trim()||e.title,markdown:u},async t=>{await A.patch(`/api/studio/pages/${e.id}`,t),i.setQueryData([`space-page`,e.id],e=>e&&{...e,...t}),t.title!==e.title&&await v()}),x=L({mutationFn:()=>A.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await v(),t()}}),S=L({mutationFn:()=>A.post(`/api/studio/projects/${e.projectId}/pages`,{title:a(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await v(),n?.(`p:${e}`)}}),T=L({mutationFn:()=>A.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>i.invalidateQueries({queryKey:[`space-page`,e.id]})}),E=async t=>{let r=t.target.closest(`a`)?.getAttribute(`href`);if(!(r?.startsWith(`pages/`)&&n))return;t.preventDefault();let i=await A.get(`/api/studio/projects/${e.projectId}/resolve?path=${encodeURIComponent(r)}`).catch(()=>null);i?.kind===`page`&&n(`p:${i.id}`)},D=e.readOnly,O=_?.file&&(_.file.mime===`application/pdf`||_.file.mime.startsWith(`image/`))?_.file:null,N=(e,t)=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>h(e),className:c(`rounded-full px-3 py-1 text-[0.8125rem] transition`,f===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[_?.parents.length&&n?(0,W.jsx)(`nav`,{className:`-mb-1.5 flex flex-wrap items-center gap-1 px-1 text-[0.8125rem] text-ink-3`,children:_.parents.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`hover:text-ink`,children:e.title}),(0,W.jsx)(w,{className:`size-3.5`})]},e.id))}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:o,disabled:D,maxLength:200,onChange:e=>l(e.target.value),"aria-label":a(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),y.state===`saving`?(0,W.jsx)(M,{className:`size-3.5 text-ink-3`}):y.state===`saved`?(0,W.jsx)(k,{className:`size-4 text-moss`,"aria-label":a(`settings.saved`)}):null,D?null:(0,W.jsx)(C,{label:a(`data.deletePage`),onClick:()=>confirm(a(`data.confirmDelete`,{title:e.title}))&&x.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(p,{className:`size-4`})})]}),_?(0,W.jsx)(Y,{projectId:e.projectId,itemKey:`p:${e.id}`,has:_.categories,originLabel:_.originLabel,kept:_.kept,review:_.review,file:O?null:_.file,readOnly:D,onReviewed:()=>T.mutate()}):null,(0,W.jsxs)(b,{className:`flex flex-col`,children:[D&&!O?null:(0,W.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[D?null:N(`write`,a(`data.write`)),N(`read`,a(`data.preview`)),O?N(`original`,a(`know.original`)):null,(0,W.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:f===`original`&&O?O.name:a(`data.markdownHint`)})]}),f===`original`&&O?O.mime===`application/pdf`?(0,W.jsx)(`iframe`,{src:I(e.projectId,O.id),title:O.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,W.jsx)(`img`,{src:I(e.projectId,O.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):f===`write`&&!D?(0,W.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),"aria-label":e.title,placeholder:a(`data.pageEmpty`),className:`field-sizing-content min-h-[50vh] w-full resize-none bg-transparent p-4 font-mono text-[0.8125rem] leading-relaxed outline-none placeholder:text-ink-4 sm:p-5`}):(0,W.jsx)(`div`,{className:`min-h-40 p-4 sm:p-5`,onClick:E,children:u.trim()?(0,W.jsx)(s,{text:u}):(0,W.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:a(`data.pageEmpty`)})})]}),y.state===`error`&&y.error?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:y.error}):null,_&&n&&(_.children.length||!D)?(0,W.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,W.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:_.children.length?a(`know.subPages`):null}),D?null:(0,W.jsxs)(j,{variant:`ghost`,size:`sm`,busy:S.isPending,onClick:()=>S.mutate(),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`know.addSub`)]})]}),_.children.length?(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:_.children.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2 text-left transition hover:bg-accent`,children:[(0,W.jsx)(m,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title})]},e.id))}):null]}):null]})}function ze({pageId:e,onGone:t,onOpen:n}){let r=i({queryKey:[`space-page`,e],queryFn:()=>A.get(`/api/studio/pages/${e}`),refetchOnWindowFocus:!1});return r.data?(0,W.jsx)(Re,{page:r.data,onGone:t,onOpen:n},r.data.id):r.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:r.error.message}):null}function Be(e){return i({queryKey:[`space-data`,e],queryFn:()=>A.get(`/api/studio/projects/${e}/data`),enabled:!!e})}function Ve(e){let t=t=>[...e.tables.filter(e=>e.wizardId===t).map(e=>({key:`t:${e.id}`,kind:`table`,title:e.title,rows:e.rows})),...e.pages.filter(e=>e.wizardId===t).map(e=>({key:`p:${e.id}`,kind:`page`,title:e.title}))];return[{key:`own`,label:a(`data.own`),items:t(null)},...e.wizards.map(e=>({key:e.id,label:e.title,items:t(e.id)}))].filter(e=>e.items.length)}var He={table:te,page:m};function Ue({kind:e,projectId:t,data:n,onClose:i,onMade:o}){let s=r(),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(``),f=L({mutationFn:()=>A.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:c.trim(),wizardId:u||null}),onSuccess:async({id:n})=>{await s.invalidateQueries({queryKey:[`space-data`,t]}),o(`${e===`table`?`t`:`p`}:${n}`),l(``),d(``)}});return(0,W.jsx)(O,{open:e!==null,onClose:i,title:a(e===`table`?`data.newTable`:`data.newPage`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),c.trim()&&f.mutate()},children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.title`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:c,maxLength:120,onChange:e=>l(e.target.value)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.owner`)}),(0,W.jsx)(v,{value:u,onChange:d,options:[{value:``,label:a(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),f.error?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error.message}):null,(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(j,{variant:`ghost`,onClick:i,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:f.isPending,disabled:!c.trim(),children:a(`data.create`)})]})]})})}function We({projectId:e,data:t,readOnly:n,onOpen:r}){let[i,o]=(0,U.useState)(null),s=Ve(t),c=new Map([...t.tables.map(e=>[`t:${e.id}`,e.updatedAt]),...t.pages.map(e=>[`p:${e.id}`,e.updatedAt])]),l=new Intl.DateTimeFormat(f,{dateStyle:`medium`});return(0,W.jsxs)(F,{title:a(`space.data`),hint:a(`data.hint`),plain:!0,action:n?null:(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>o(`table`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`data.table`)]}),(0,W.jsxs)(j,{variant:`secondary`,size:`sm`,onClick:()=>o(`page`),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`data.page`)]})]}),children:[s.length?(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:s.map(e=>(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e.label}),(0,W.jsx)(b,{className:`flex flex-col p-1.5`,children:e.items.map(e=>{let t=He[e.kind];return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(e.key),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,W.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,W.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:[e.kind===`table`?`${a(`data.rows`,{n:e.rows??0})} · `:``,l.format(new Date(c.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,W.jsx)(b,{children:(0,W.jsx)(T,{children:a(`data.empty`)})}),(0,W.jsx)(Ue,{kind:i,projectId:e,data:t,onClose:()=>o(null),onMade:e=>{o(null),r(e)}})]})}function Ge(e,t){let n=e.normalize(`NFKD`).replace(/[̀-ͯ]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/^[^a-z]+/,``).slice(0,48)||`column`,r=n,i=2;for(;t.includes(r);)r=`${n}_${i++}`;return r}var Ke={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},qe=[`text`,`number`,`date`,`duration`,`select`,`boolean`];function Je(e,t){if(t==null)return``;if(e.type===`duration`&&typeof t==`number`)return String(t/Ke[e.format.inputUnit]);if(e.type===`date`&&e.format.kind===`datetime`&&typeof t==`string`){let e=new Date(t);return new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString().slice(0,16)}return String(t)}function Ye(e,t){return t.trim()===``?null:e.type===`date`&&e.format.kind===`datetime`?new Date(t).toISOString():t}var X=`w-full min-w-0 rounded-md bg-transparent px-2 py-1.5 text-[0.875rem] outline-none transition placeholder:text-ink-4 hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`;function Xe({column:e,value:t,readOnly:n,invalid:r,onSave:i}){let o=Je(e,t),[s,l]=(0,U.useState)(o);(0,U.useEffect)(()=>l(o),[o]);let u=(t=s)=>{t!==o&&i(Ye(e,t))};if(e.type===`boolean`)return(0,W.jsx)(`div`,{className:`px-2 py-1.5`,children:(0,W.jsx)(`input`,{type:`checkbox`,checked:t===!0,disabled:n,onChange:e=>i(e.target.checked),"aria-label":e.name,className:`size-4 accent-[var(--ember)]`})});if(e.type===`select`&&e.format.multiple){let r=Array.isArray(t)?t:[],o=t=>e.format.options.find(e=>e.id===t)?.label??t;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-2 py-1`,children:[r.map(e=>(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-paper-2 py-0.5 pr-1 pl-2 text-[0.75rem]`,children:[o(e),n?null:(0,W.jsx)(`button`,{type:`button`,"aria-label":a(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,W.jsx)(d,{className:`size-3`})})]},e)),n?null:(0,W.jsxs)(`select`,{value:``,onChange:e=>e.target.value&&i([...r,e.target.value]),"aria-label":e.name,className:`h-7 rounded-md bg-transparent px-1 text-[0.75rem] text-ink-3 outline-none hover:bg-accent`,children:[(0,W.jsx)(`option`,{value:``,children:`+`}),e.format.options.filter(e=>!r.includes(e.id)).map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})}if(e.type===`select`)return(0,W.jsxs)(`select`,{value:typeof t==`string`?t:``,disabled:n,onChange:e=>i(e.target.value||null),"aria-label":e.name,className:X,children:[(0,W.jsx)(`option`,{value:``}),e.format.options.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]});if(e.type===`text`&&e.format?.style&&e.format.style!==`single`)return(0,W.jsx)(`textarea`,{value:s,rows:1,disabled:n,onChange:e=>l(e.target.value),onBlur:()=>u(),"aria-label":e.name,className:c(X,`field-sizing-content max-h-40 resize-none`)});let f=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,W.jsx)(`input`,{type:f,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:s,disabled:n,onChange:t=>{l(t.target.value),e.type===`date`&&u(t.target.value)},onBlur:()=>e.type!==`date`&&u(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&l(o)},"aria-label":e.name,className:c(X,(e.type===`number`||e.type===`duration`)&&`text-right tabular-nums`,r&&`ring-1 ring-rose`)})}function Ze(e){return e.type===`number`&&e.format.style===`currency`?e.format.currency??null:e.type===`number`&&e.format.style===`percent`?`%`:e.type===`duration`?a(`data.unit.${e.format.inputUnit}`):null}function Qe(e){return{name:e?.name??``,type:e?.type??`text`,required:e?.required??!1,textStyle:e?.type===`text`&&(e.format?.style??`single`)!==`single`?`multiline`:`single`,numberStyle:e?.type===`number`?e.format.style:`decimal`,currency:e?.type===`number`?e.format.currency??`EUR`:`EUR`,dateKind:e?.type===`date`?e.format.kind:`date`,unit:e?.type===`duration`&&[`minutes`,`hours`,`days`].includes(e.format.inputUnit)?e.format.inputUnit:`minutes`,options:e?.type===`select`?e.format.options.map(e=>e.label).join(`
|
|
3
|
+
`):``,multiple:e?.type===`select`&&!!e.format.multiple}}function $e(e,t,n){let r={id:t,name:e.name.trim(),...e.required?{required:!0}:{}};switch(e.type){case`number`:return{...r,type:`number`,format:e.numberStyle===`currency`?{style:`currency`,currency:e.currency.trim().toUpperCase()}:{style:e.numberStyle}};case`date`:return{...r,type:`date`,format:{kind:e.dateKind}};case`duration`:return{...r,type:`duration`,format:{inputUnit:e.unit,display:`hms`}};case`select`:{let t=n?.type===`select`?n.format.options:[],i=[],a=e.options.split(`
|
|
4
|
+
`).map(e=>e.trim()).filter(Boolean).map(e=>{let n=t.find(t=>t.label===e)?.id??Ge(e,i);return i.push(n),{id:n,label:e}});return{...r,type:`select`,format:{allowCustom:!1,options:a,...e.multiple?{multiple:!0}:{}}}}case`boolean`:return{...r,type:`boolean`};default:return{...r,type:`text`,...e.textStyle===`multiline`?{format:{style:`multiline`}}:{}}}}function et({open:e,column:t,columns:n,onClose:r,onSave:i}){let[s,c]=(0,U.useState)(()=>Qe(t)),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(!1);(0,U.useEffect)(()=>{e&&(c(Qe(t)),u(null))},[e,t]);let p=e=>c(t=>({...t,...e})),m=async e=>{f(!0),u(null);try{await i(e),r()}catch(e){u(e.message)}finally{f(!1)}},g=()=>{let e=t?.id??Ge(s.name,n.map(e=>e.id)),r=$e(s,e,t);return m(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,W.jsx)(O,{open:e,onClose:r,title:t?t.name:a(`data.newColumn`),children:(0,W.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),s.name.trim()&&g()},children:[(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.columnName`)}),(0,W.jsx)(S,{"data-autofocus":!0,value:s.name,maxLength:128,onChange:e=>p({name:e.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.columnType`)}),(0,W.jsx)(v,{value:s.type,onChange:e=>p({type:e}),options:qe.map(e=>({value:e,label:a(`data.type.${e}`)}))})]})]}),s.type===`text`?(0,W.jsx)(v,{value:s.textStyle,onChange:e=>p({textStyle:e}),options:[{value:`single`,label:a(`data.text.single`)},{value:`multiline`,label:a(`data.text.multiline`)}]}):null,s.type===`number`?(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsx)(v,{value:s.numberStyle,onChange:e=>p({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:a(`data.number.${e}`)}))}),s.numberStyle===`currency`?(0,W.jsx)(S,{value:s.currency,maxLength:3,"aria-label":a(`data.currency`),placeholder:`EUR`,onChange:e=>p({currency:e.target.value})}):null]}):null,s.type===`date`?(0,W.jsx)(v,{value:s.dateKind,onChange:e=>p({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:a(`data.date.${e}`)}))}):null,s.type===`duration`?(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.unit`)}),(0,W.jsx)(v,{value:s.unit,onChange:e=>p({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:a(`data.unit.${e}`)}))})]}):null,s.type===`select`?(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(_,{children:a(`data.options`)}),(0,W.jsx)(h,{minRows:3,value:s.options,onChange:e=>p({options:e.target.value})})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(o,{checked:s.multiple,onChange:e=>p({multiple:e})}),a(`data.multiple`)]})]}):null,(0,W.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,W.jsx)(o,{checked:s.required,onChange:e=>p({required:e})}),a(`data.required`)]}),l?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:l}):null,(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,W.jsx)(j,{variant:`ghost`,className:`text-rose`,disabled:d,onClick:()=>confirm(a(`data.confirmDelete`,{title:t.name}))&&void m(n.filter(e=>e.id!==t.id)),children:a(`data.deleteColumn`)}):null,(0,W.jsx)(`span`,{className:`flex-1`}),(0,W.jsx)(j,{variant:`ghost`,onClick:r,children:a(`common.cancel`)}),(0,W.jsx)(j,{type:`submit`,busy:d,disabled:!s.name.trim(),children:a(`settings.save`)})]})]})})}function tt({tableId:e,onGone:t}){let n=r(),o=[`space-table`,e],s=i({queryKey:o,queryFn:()=>A.get(`/api/studio/tables/${e}`)}),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,m]=(0,U.useState)(null),[h,_]=(0,U.useState)(``);(0,U.useEffect)(()=>_(s.data?.title??``),[s.data?.title]);let v=async()=>{await n.invalidateQueries({queryKey:[`space-data`,s.data?.projectId]}),await n.invalidateQueries({queryKey:[`knowledge`,s.data?.projectId]})},x=e=>n.setQueryData(o,t=>t&&{...t,rows:e(t.rows)}),S=e=>{d(e.message),s.refetch()},w=async t=>{await A.patch(`/api/studio/tables/${e}`,t),await s.refetch(),await v()},T=L({mutationFn:({row:t,column:n,value:r})=>A.patch(`/api/studio/tables/${e}/rows/${t}`,{cells:{[n]:r}}),onSuccess:(e,{row:t,column:n})=>{d(null),m(e=>e===`${t}:${n}`?null:e),x(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof y&&e.body?.column===n){let e=s.data?.columns.find(e=>e.id===n)?.name??n;m(`${t}:${n}`),d(a(`data.badCell`,{column:e}));return}S(e)}}),E=L({mutationFn:()=>A.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{x(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await v()},onError:S}),D=L({mutationFn:t=>A.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{x(e=>e.filter(e=>e.id!==t)),await v()},onError:S}),O=L({mutationFn:()=>A.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await v(),t()}});if(!s.data)return s.isError?(0,W.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error.message}):null;let{columns:k,rows:M,readOnly:N}=s.data,P=!!s.data.list;return(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,W.jsx)(`input`,{value:h,disabled:N,maxLength:120,onChange:e=>_(e.target.value),onBlur:()=>h.trim()&&h!==s.data?.title&&void w({title:h}).catch(S),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":a(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),N?null:(0,W.jsx)(C,{label:a(`data.deleteTable`),onClick:()=>confirm(a(`data.confirmDelete`,{title:s.data.title}))&&O.mutate(),className:`hover:text-rose`,children:(0,W.jsx)(p,{className:`size-4`})})]}),P?(0,W.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:a(`data.fromList`)}):null,s.data.knowledge?(0,W.jsx)(Y,{projectId:s.data.projectId,itemKey:`t:${s.data.id}`,has:s.data.knowledge.categories,originLabel:s.data.knowledge.originLabel,kept:s.data.knowledge.kept,review:s.data.knowledge.review,file:s.data.knowledge.file,readOnly:N,onReviewed:()=>void A.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>s.refetch()).catch(S)}):null,(0,W.jsxs)(b,{className:`overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full border-collapse text-left`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[k.map(e=>(0,W.jsx)(`th`,{className:`min-w-36 border-border-soft border-l p-1 font-medium first:border-l-0`,children:(0,W.jsxs)(`button`,{type:`button`,disabled:N||P,onClick:()=>l(e),className:`flex w-full items-center gap-1 rounded-md px-2 py-1.5 text-left text-[0.8125rem] text-ink-2 transition hover:bg-accent hover:text-ink disabled:hover:bg-transparent`,children:[(0,W.jsx)(`span`,{className:`truncate`,children:e.name}),e.required?(0,W.jsx)(`span`,{className:`text-ember`,children:`*`}):null,Ze(e)?(0,W.jsx)(`span`,{className:`font-normal text-ink-4`,children:Ze(e)}):null]})},e.id)),(0,W.jsx)(`th`,{className:`w-10 p-1`,children:N||P?null:(0,W.jsx)(C,{label:a(`data.newColumn`),onClick:()=>l(`new`),className:`size-8`,children:(0,W.jsx)(g,{className:`size-4`})})})]})}),(0,W.jsx)(`tbody`,{children:M.map(e=>(0,W.jsxs)(`tr`,{className:`group border-border-soft border-b last:border-b-0`,children:[k.map(t=>(0,W.jsx)(`td`,{className:`border-border-soft border-l p-1 align-top first:border-l-0`,children:(0,W.jsx)(Xe,{column:t,value:e.cells[t.id],readOnly:N,invalid:f===`${e.id}:${t.id}`,onSave:n=>T.mutate({row:e.id,column:t.id,value:n})})},t.id)),(0,W.jsx)(`td`,{className:`w-10 p-1 align-top`,children:N?null:(0,W.jsx)(C,{label:a(`data.deleteRow`),onClick:()=>D.mutate(e.id),className:`size-8 opacity-0 hover:text-rose focus:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:(0,W.jsx)(p,{className:`size-3.5`})})})]},e.id))})]})}),M.length?null:(0,W.jsx)(`p`,{className:`px-4 py-6 text-center text-[0.875rem] text-ink-3`,children:a(`data.noRows`)}),N?null:(0,W.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,W.jsxs)(j,{variant:`ghost`,size:`sm`,busy:E.isPending,onClick:()=>E.mutate(),children:[(0,W.jsx)(g,{className:`size-4`}),` `,a(`data.addRow`)]})})]}),u?(0,W.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:u}):null,(0,W.jsx)(et,{open:c!==null,column:c===`new`?null:c,columns:k,onClose:()=>l(null),onSave:e=>w({columns:e})})]})}var nt=`wizards.runDrawer.width`,rt=`wizards.runDrawer.wide`,it=`wizards.runDrawer.look`,at=680,Z=400,ot=()=>Math.max(Z,window.innerWidth-120);function Q(e){try{return localStorage.getItem(e)}catch{return null}}function $(e,t){try{localStorage.setItem(e,t)}catch{}}function st(){let[e,t]=(0,U.useState)(()=>{let e=Number(Q(nt));return e?Math.min(Math.max(e,Z),ot()):at}),[n,r]=(0,U.useState)(()=>Q(rt)===`1`),i=(0,U.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,Z),ot()));t(n),$(nt,String(n))},[]);return{width:e,wide:n,toggleWide:()=>{r(!n),$(rt,n?`0`:`1`)},onPointerDown:t=>{t.preventDefault();let n=t.clientX,r=e,a=e=>i(r+n-e.clientX),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)};document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)},onKeyDown:t=>{let n=t.shiftKey?64:16;t.key===`ArrowLeft`?(t.preventDefault(),i(e+n)):t.key===`ArrowRight`&&(t.preventDefault(),i(e-n))},reset:()=>i(at)}}function ct(){let[e,t]=(0,U.useState)(()=>Q(it)===`chat`?`chat`:`steps`);return[e,e=>{t(e),$(it,e)}]}function lt({look:e,onChange:t}){let n=[{id:`steps`,label:a(`chat.steps`),Icon:pe},{id:`chat`,label:a(`chat.chat`),Icon:B}];return(0,W.jsx)(`fieldset`,{"aria-label":a(`chat.view`),className:`m-0 flex min-w-0 rounded-full border-0 bg-paper-2 p-0.5`,children:n.map(({id:n,label:r,Icon:i})=>(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":e===n,title:r,onClick:()=>t(n),className:c(`inline-flex h-7 items-center gap-1.5 rounded-full px-2.5 font-medium text-[0.75rem] transition coarse:h-9`,e===n?`bg-card text-ink shadow-soft`:`text-ink-3 hover:text-ink`),children:[(0,W.jsx)(i,{className:`size-3.5`}),(0,W.jsx)(`span`,{className:`max-sm:hidden`,children:r})]},n))})}function ut({header:e,actions:t,onClose:n,children:r}){let i=st();return(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 flex justify-end bg-[oklch(20%_0.01_60/0.22)] backdrop-blur-[1px]`,onClick:n,children:(0,W.jsxs)(`div`,{className:c(`relative flex h-full w-full animate-rise flex-col bg-background shadow-overlay`,!i.wide&&`sm:w-[var(--drawer)]`),style:{"--drawer":`${i.width}px`},onClick:e=>e.stopPropagation(),children:[i.wide?null:(0,W.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":a(`editor.resize`),"aria-valuenow":i.width,tabIndex:0,title:a(`editor.resize`),onPointerDown:i.onPointerDown,onKeyDown:i.onKeyDown,onDoubleClick:i.reset,className:`group -left-2.5 absolute inset-y-0 z-10 hidden w-5 cursor-col-resize outline-none sm:block`,children:(0,W.jsx)(`span`,{className:`-translate-y-1/2 absolute top-1/2 left-[7px] h-12 w-1.5 rounded-full bg-ink-4/40 transition group-hover:bg-ember/70 group-focus-visible:bg-ember group-active:h-16 group-active:bg-ember`})}),(0,W.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4`,children:[(0,W.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:e}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t,(0,W.jsx)(C,{label:a(i.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:i.toggleWide,className:`max-sm:hidden`,children:i.wide?(0,W.jsx)(me,{className:`size-4`}):(0,W.jsx)(u,{className:`size-4`})}),(0,W.jsx)(C,{label:a(`editor.close`),onClick:n,children:(0,W.jsx)(d,{className:`size-5`})})]})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}export{De as _,He as a,fe as b,Be as c,J as d,Y as f,Te as g,G as h,tt as i,ze as l,Oe as m,ut as n,We as o,Le as p,ct as r,Ve as s,lt as t,je as u,Ee as v,ce as x,H as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{b as r,ct as i,u as a,y as o}from"./ui-D2SqIZeQ.js";import{i as s,r as c}from"./index-BH0PYgov.js";var l=e(t(),1),u=e(n(),1),d=[`classifier`,`standard`],f=12e3;function p(e){s(`think`)&&a.post(`/api/runs/${e}/device`,{think:{classes:d,maxChars:f}}).catch(()=>void 0)}async function m(e,t){if(t.kind!==`think`)return;let n;try{let e=await c(`think`,{system:t.system,prompt:t.prompt,schema:t.schema});n={text:String(e?.text??``)}}catch(e){n={error:e.message.slice(0,500)}}await a.post(`/api/runs/${e}/device/${t.id}`,n).catch(()=>void 0)}var h=45e3;function g(e){let[t,n]=(0,l.useState)(null),[r,s]=(0,l.useState)(null),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(!1),[g,_]=(0,l.useState)({});(0,l.useEffect)(()=>{if(n(null),u(!1),!e)return;let t=!1,r=0,s,c=null,l=Date.now(),d=()=>{t=!0,c?.close(),u(!0)},f=async()=>{try{let r=await a.get(`/api/runs/${e}`);t||n(r)}catch(e){e instanceof i&&e.status===404&&d()}},g=()=>{if(clearTimeout(s),c?.close(),t)return;let i=new EventSource(o(`/api/runs/${e}/stream`),{withCredentials:!0});c=i,l=Date.now(),p(e),i.addEventListener(`device`,t=>{l=Date.now(),m(e,JSON.parse(t.data))}),i.addEventListener(`view`,e=>{r=0,l=Date.now(),n(JSON.parse(e.data))}),i.addEventListener(`ping`,()=>{l=Date.now()}),i.onerror=()=>{i.close(),!(t||c!==i)&&(c=null,f(),r=Math.min(r+1,6),s=setTimeout(g,500*2**r))}},_=()=>{t||document.visibilityState!==`visible`||(!c||c.readyState===EventSource.CLOSED||Date.now()-l>h?(r=0,g()):f())},v=setInterval(()=>{!t&&c&&Date.now()-l>h&&(r=0,g())},15e3);return g(),document.addEventListener(`visibilitychange`,_),window.addEventListener(`pageshow`,_),window.addEventListener(`online`,_),()=>{t=!0,clearTimeout(s),clearInterval(v),document.removeEventListener(`visibilitychange`,_),window.removeEventListener(`pageshow`,_),window.removeEventListener(`online`,_),c?.close()}},[e]);let v=(0,l.useCallback)(async(t,n)=>{if(!e)return!1;f(!0),s(null),_({});try{return await a.post(`/api/runs/${e}/${t}`,n),!0}catch(e){return e instanceof i&&e.status===422&&Array.isArray(e.body?.fields)&&_(Object.fromEntries(e.body.fields.map(e=>[e.field,e.message]))),s(e.message),!1}finally{f(!1)}},[e]);return{view:t,notFound:c,error:r,busy:d,fieldErrors:g,submitPage:(e,t)=>v(`pages/${e}`,{values:t}),accept:(e,t)=>v(`reviews/${e}`,{type:`accept`,edits:t}),regenerate:(e,t,n,r)=>v(`reviews/${e}`,{type:`regenerate`,target:t,note:n,items:r?.length?r:void 0}),back:()=>v(`back`),retry:()=>v(`retry`)}}function _({runId:e,...t}){let n=g(e);return(0,u.jsx)(r,{run:n,...t})}export{g as n,_ as t};
|