wizards 0.2.27 → 0.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/authoring/guide.js +8 -2
- package/apps/runtime/dist/credits/estimate.js +4 -0
- package/apps/runtime/dist/engine/requirements.js +4 -0
- package/apps/runtime/dist/engine/steps.js +42 -1
- package/apps/runtime/dist/mcp/tools.js +2 -0
- package/apps/runtime/dist/routes/marketplace.js +2 -1
- package/apps/runtime/dist/services/marketplace.js +35 -4
- package/apps/runtime/dist/tools/plugin.js +49 -25
- package/apps/web/dist/assets/Account-BaOouMw9.js +1 -0
- package/apps/web/dist/assets/{ChangelogDialog-BdZ1SmEd.js → ChangelogDialog-3t_EKUPH.js} +1 -1
- package/apps/web/dist/assets/{CreditsDialog-fOYdoev3.js → CreditsDialog-BW-RETl-.js} +1 -1
- package/apps/web/dist/assets/EditorPage-DrJhgEHO.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-U2AEnKlX.js → FlowPreview-Wu5ovKrU.js} +1 -1
- package/apps/web/dist/assets/{Harness-CtDlm_2b.js → Harness-Oh4MEjiK.js} +1 -1
- package/apps/web/dist/assets/HomePage-eYqUUwzG.js +1 -0
- package/apps/web/dist/assets/{ImportWizard-BMPGjd_t.js → ImportWizard-BSjp83g0.js} +1 -1
- package/apps/web/dist/assets/LocalRuntime-CqBfKp8q.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-Bpqk-BwW.js +2 -0
- package/apps/web/dist/assets/{ProjectPage-_LAtG3tn.js → ProjectPage-SK7e8kxV.js} +2 -2
- package/apps/web/dist/assets/PublicRunner-Cu056QMy.js +1 -0
- package/apps/web/dist/assets/{RunDrawer-CtQoY3Ha.js → RunDrawer-BdcgNjPZ.js} +3 -3
- package/apps/web/dist/assets/RunnerView-JOMD-e27.js +2 -0
- package/apps/web/dist/assets/SettingsPage-BSu-2gL5.js +1 -0
- package/apps/web/dist/assets/SetupPage-DdWIlUCF.js +1 -0
- package/apps/web/dist/assets/SharePage-C5JlCg9u.js +1 -0
- package/apps/web/dist/assets/arrow-right-hy38IBRU.js +1 -0
- package/apps/web/dist/assets/changelog-C2q3P5lJ.js +1 -0
- package/apps/web/dist/assets/{circle-alert-BC6xmJ9r.js → circle-alert-BG9P3ewL.js} +1 -1
- package/apps/web/dist/assets/definition-CwX2olVF.js +1 -0
- package/apps/web/dist/assets/{esm-FEWi61F_.js → esm-MDvpTvd_.js} +1 -1
- package/apps/web/dist/assets/{external-link-wKL1HE6G.js → external-link-BwCtn1nW.js} +1 -1
- package/apps/web/dist/assets/{image-BMdSChOR.js → image-DG4q2P1H.js} +1 -1
- package/apps/web/dist/assets/index-knnf98Fv.js +78 -0
- package/apps/web/dist/assets/{lock-BpqzLMuv.js → lock-DH_BntP_.js} +1 -1
- package/apps/web/dist/assets/{meta-BqZ7SlZz.js → meta-cFJejpIa.js} +1 -1
- package/apps/web/dist/assets/{pen-line-DM-u0dES.js → pen-line-B1dsy3Sr.js} +1 -1
- package/apps/web/dist/assets/{refresh-cw-Bk7HkOIM.js → refresh-cw-B9M1g3SH.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-BM_NfZfn.js → settings-menu-DC825gd1.js} +1 -1
- package/apps/web/dist/assets/{star-JHzYYl5R.js → star-axQV_3EC.js} +1 -1
- package/apps/web/dist/assets/surface-D7bnQtqR.js +56 -0
- package/apps/web/dist/assets/{trash-CdLg-Ela.js → trash-3S1_XpVa.js} +1 -1
- package/apps/web/dist/assets/{ui-8QmvuC9u.js → ui-BZ01zr3i.js} +1 -1
- package/apps/web/dist/assets/{upload-CL1R6shM.js → upload-U0i8fAW3.js} +1 -1
- package/apps/web/dist/assets/{video-BioLmXNO.js → video-Db4o719f.js} +1 -1
- package/apps/web/dist/assets/{volume-2-_IOfPNCv.js → volume-2-6f7qN_LM.js} +1 -1
- package/apps/web/dist/assets/{wand-sparkles-DYtDQSJZ.js → wand-sparkles-MelvBtiK.js} +1 -1
- package/apps/web/dist/index.html +3 -3
- package/apps/web/dist/mcp/flow.html +49 -49
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +15 -3
- package/node_modules/@engenty-wizards/shared/dist/definition.js +38 -9
- package/node_modules/@engenty-wizards/shared/dist/marketplace-search.js +4 -1
- package/node_modules/@engenty-wizards/shared/dist/marketplace.d.ts +38 -1
- package/node_modules/@engenty-wizards/shared/dist/marketplace.js +34 -0
- package/package.json +1 -1
- package/apps/web/dist/assets/Account-DW396ig5.js +0 -1
- package/apps/web/dist/assets/EditorPage-CAARFsaI.js +0 -3
- package/apps/web/dist/assets/HomePage-Bd-mkLxW.js +0 -1
- package/apps/web/dist/assets/LocalRuntime-DjSNCRnV.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-DZPcDR9i.js +0 -2
- package/apps/web/dist/assets/PublicRunner-6Iqp0DmU.js +0 -1
- package/apps/web/dist/assets/RunnerView-BLOCNZaZ.js +0 -2
- package/apps/web/dist/assets/SettingsPage-Z6skBf6I.js +0 -1
- package/apps/web/dist/assets/SetupPage-4-Lic4pT.js +0 -1
- package/apps/web/dist/assets/SharePage-DfdhXxZm.js +0 -1
- package/apps/web/dist/assets/arrow-right-BOtqnsA1.js +0 -1
- package/apps/web/dist/assets/brand-CCAI9p0f.js +0 -2
- package/apps/web/dist/assets/changelog-DQM0oz9S.js +0 -1
- package/apps/web/dist/assets/definition-D5V79jHA.js +0 -1
- package/apps/web/dist/assets/index-YJMooz0J.js +0 -132
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FlowPreview-Wu5ovKrU.js","assets/jsx-runtime-D3jfb0Ew.js","assets/ui-BZ01zr3i.js","assets/preload-helper-CNEI7N0N.js","assets/esm-MDvpTvd_.js","assets/index-knnf98Fv.js","assets/surface-D7bnQtqR.js","assets/engenty-Cm8yZLON.js","assets/index-BOp2fz-2.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{D as r,H as i,M as a,O as o,Q as s,S as c,_ as l,j as u,k as d}from"./surface-D7bnQtqR.js";import{t as f}from"./preload-helper-CNEI7N0N.js";import{$ as p,G as m,H as h,L as g,N as _,R as v,V as y,Y as b,f as x,g as S,h as ee,i as te,j as C,k as w,n as T,r as E,t as D,tt as O,x as k}from"./ui-BZ01zr3i.js";import{t as ne}from"./arrow-right-hy38IBRU.js";import{c as A,s as re,t as ie}from"./meta-cFJejpIa.js";import{n as j,t as M}from"./image-DG4q2P1H.js";import{n as ae,r as oe}from"./upload-U0i8fAW3.js";import{n as se,r as ce,t as le}from"./wand-sparkles-MelvBtiK.js";import{n as ue,t as de}from"./volume-2-6f7qN_LM.js";import{t as fe}from"./pen-line-B1dsy3Sr.js";import{n as pe,t as N}from"./star-axQV_3EC.js";import{t as P}from"./video-Db4o719f.js";import{l as me,u as he}from"./engenty-Cm8yZLON.js";import{Z as ge,_t as F,ct as I,ht as L,ot as _e,pt as ve,q as ye,rt as be,tt as xe}from"./index-knnf98Fv.js";import"./definition-CwX2olVF.js";import{t as Se}from"./ImportWizard-BSjp83g0.js";var Ce=class extends d{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:o,isError:s,isRefetchError:c}=r,l=n.fetchMeta?.fetchMore?.direction,d=s&&l===`forward`,f=i&&l===`forward`,p=s&&l===`backward`,m=i&&l===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:u(t,n.data),hasPreviousPage:a(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:c&&!d&&!p,isRefetching:o&&!f&&!m}}};function we(e,t){return o(e,Ce,t)}var R={name:`audio-lines`,size:24,node:[[`path`,{d:`M2 10v3`,key:`1fnikh`}],[`path`,{d:`M6 6v11`,key:`11sgs0`}],[`path`,{d:`M10 3v18`,key:`yhl04a`}],[`path`,{d:`M14 8v7`,key:`3a1oy3`}],[`path`,{d:`M18 5v13`,key:`123xd1`}],[`path`,{d:`M22 10v3`,key:`154ddg`}]]};R.node;var Te=m(R),z={name:`chart-column`,size:24,node:[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]],aliases:[`bar-chart-3`]};z.node;var B=m(z),Ee={name:`circle-dollar-sign`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8`,key:`1h4pet`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}]]};Ee.node;var De=m(Ee),Oe={name:`circle-euro`,size:24,node:[[`path`,{d:`M15 9.4a4 4 0 1 0 0 5.2`,key:`1makmb`}],[`path`,{d:`M7 12h5`,key:`gblrwe`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Oe.node;var ke=m(Oe),Ae={name:`mouse-pointer-click`,size:24,node:[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]};Ae.node;var je=m(Ae),Me={name:`scan-text`,size:24,node:[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`path`,{d:`M7 8h8`,key:`1jbsf9`}],[`path`,{d:`M7 12h10`,key:`b7w52i`}],[`path`,{d:`M7 16h6`,key:`1vyc9m`}]]};Me.node;var Ne=m(Me),Pe={name:`terminal`,size:24,node:[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]};Pe.node;var Fe=m(Pe),V=e(t(),1),H={text:{de:`Text`,en:`Text`},document:{de:`Dokument (PDF, Word)`,en:`Document (PDF, Word)`},table:{de:`Tabelle`,en:`Table`},image:{de:`Bild`,en:`Image`},video:{de:`Video`,en:`Video`},audio:{de:`Audio`,en:`Audio`},dashboard:{de:`Dashboard`,en:`Dashboard`}},Ie={any:{de:`Jede Branche`,en:`Any industry`},trades:{de:`Handwerk`,en:`Trades`},gastronomy:{de:`Gastronomie`,en:`Food service`},hospitality:{de:`Hotel & Tourismus`,en:`Hotels & tourism`},realEstate:{de:`Immobilien`,en:`Real estate`},retail:{de:`Handel`,en:`Retail`},health:{de:`Gesundheit`,en:`Health`},professional:{de:`Kanzlei & Beratung`,en:`Professional services`},agency:{de:`Agentur & Marketing`,en:`Agency & marketing`},events:{de:`Veranstaltungen`,en:`Events`},publicSector:{de:`Vereine & Öffentliches`,en:`Associations & public sector`}},Le={marketing:{de:`Marketing & Social Media`,en:`Marketing & social media`},sales:{de:`Angebote & Verkauf`,en:`Offers & sales`},accounting:{de:`Buchhaltung & Belege`,en:`Accounting & receipts`},service:{de:`Kundenservice`,en:`Customer service`},research:{de:`Recherche & Analyse`,en:`Research & analysis`},hr:{de:`Personal & Bewerbungen`,en:`HR & applications`},operations:{de:`Planung & Abläufe`,en:`Planning & operations`},website:{de:`Helfer für die Website`,en:`Website helpers`},visuals:{de:`Bilder & Video`,en:`Images & video`},inquiries:{de:`Anfragen & Termine`,en:`Inquiries & bookings`},advice:{de:`Beratung & Preise`,en:`Advice & pricing`}},U={text:{de:`Text schreiben`,en:`Writes text`},web:{de:`Websuche`,en:`Web search`},browser:{de:`Browser bedienen`,en:`Drives a browser`},documents:{de:`Dokumente & Fotos lesen`,en:`Reads documents & photos`},image:{de:`Bilder erzeugen`,en:`Makes images`},video:{de:`Videos erzeugen`,en:`Makes video`},speech:{de:`Sprachausgabe`,en:`Speech output`},listening:{de:`Sprachnotizen verstehen`,en:`Understands voice notes`},code:{de:`Code ausführen`,en:`Runs code`},connectors:{de:`Verbundene Konten & Systeme`,en:`Connected accounts & systems`},film:{de:`Filme mit Claude Code (auf deinem Abo)`,en:`Films with Claude Code (on your subscription)`}},Re={low:{de:`günstig`,en:`low cost`},medium:{de:`mittel`,en:`medium cost`},high:{de:`teuer`,en:`high cost`}},ze={free:{de:`Kostenlos`,en:`Free`},pro:{de:`Pro`,en:`Pro`}},W=e=>Object.keys(e);W(H),W(Ie),W(Le),W(U),W(ze);var G=e(n(),1),Be=(0,V.lazy)(()=>f(()=>import(`./FlowPreview-Wu5ovKrU.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),Ve={useCase:``,industry:``,format:``,capability:``,plan:``},K=(e,t)=>e[t]?.[w]??t;function He(e){if(e<1)return 1;let t=10**Math.floor(Math.log10(e));return Math.round(e/t)*t}function Ue(e){return e.credits?C(`market.credits`,{n:He(e.credits.credits)}):Re[e.costTier][w]}var We={text:xe,document:I,table:se,image:M,video:P,audio:Te,dashboard:B};function q({format:e,className:t}){let n=We[e],r=K(H,e);return(0,G.jsx)(`span`,{title:r,className:`inline-flex`,children:(0,G.jsx)(n,{className:t,"aria-label":r,role:`img`})})}var Ge=[`low`,`medium`,`high`];function J({entry:e}){let t=Ge.indexOf(e.costTier)+1,n=w===`de`?ke:De;return(0,G.jsxs)(`span`,{title:Ue(e),className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,className:`inline-flex shrink-0`,children:Ge.slice(0,t).map((e,t)=>(0,G.jsx)(`span`,{className:S(`rounded-full bg-(--coin-bg,var(--color-card))`,t>0&&`-ml-1.5`),children:(0,G.jsx)(n,{className:`size-4`})},e))}),Re[e.costTier][w]]})}function Ke(){return(0,G.jsx)(E,{tone:`ember`,title:C(`market.proHint`),children:C(`market.pro`)})}function qe({plugin:e}){return(0,G.jsx)(E,{icon:(0,G.jsx)(pe,{className:`size-3.5`}),title:C(`market.fromPlugin`,{name:e.name}),children:e.name})}function Je({entry:e,onOpen:t}){return(0,G.jsxs)(T,{role:`button`,tabIndex:0,onClick:t,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())},className:S(`relative flex min-h-[124px] cursor-pointer flex-col gap-5 p-4 text-left transition sm:min-h-[136px] sm:p-5 hover:shadow-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus`,(!e.usable||e.missing.length>0||!!e.needs?.length)&&`opacity-60`),children:[(0,G.jsx)(`span`,{className:`-top-4 pointer-events-none absolute right-4`,children:(0,G.jsx)(l,{kind:e.avatar,size:68,interactive:!1})}),(0,G.jsxs)(`div`,{className:`min-w-0 pr-20`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 font-display font-semibold text-[0.9375rem]`,children:[e.title,e.plan===`pro`?(0,G.jsx)(Ke,{}):null,e.starred?(0,G.jsx)(N,{className:`size-3.5 shrink-0 fill-amber text-amber`,"aria-label":C(`market.starred`)}):null]}),(0,G.jsx)(`div`,{className:`mt-0.5 text-[0.8125rem] text-ink-3 leading-snug`,children:e.pitch})]}),(0,G.jsxs)(`div`,{className:`mt-auto flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[0.75rem] text-ink-3`,children:[e.plugin?(0,G.jsx)(qe,{plugin:e.plugin}):null,e.needs?.length?(0,G.jsx)(E,{tone:`warn`,children:C(`market.needsPro`,{list:e.needs.join(`, `)})}):e.usable&&e.missing.length?(0,G.jsx)(E,{tone:`warn`,children:C(`market.missing`,{list:X(e.missing)})}):e.usable?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(v,{className:`size-3.5`}),` `,C(`market.minutes`,{n:e.effort.minutes})]}),(0,G.jsx)(J,{entry:e}),e.optional?.length?(0,G.jsx)(E,{title:C(`market.optionalHint`,{list:X(e.optional)}),children:C(`market.without`,{list:X(e.optional)})}):null,(0,G.jsx)(`span`,{className:`ml-auto inline-flex items-center gap-1.5`,children:e.formats.map(e=>(0,G.jsx)(q,{format:e,className:`size-4`},e))})]}):(0,G.jsx)(E,{tone:`warn`,children:C(`market.needsUpdate`)})]})]})}function Y({title:e,children:t}){return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`mb-1.5 font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.06em]`,children:e}),t]})}var X=e=>e.map(e=>K(U,e)).join(`, `),Z={text:fe,web:ue,browser:je,documents:Ne,image:M,video:P,speech:de,listening:g,code:Fe,connectors:be,film:j};function Ye(e){switch(e.type){case`page`:return _e;case`agent`:return A;case`generate`:return e.asset===`image`?M:e.asset===`video`?P:e.asset===`voice`?de:e.asset===`dashboard`?B:I;case`widget`:return e.video?j:L;case`surface`:return L;case`film`:return j;case`review`:return ce;case`result`:return re}return le}function Xe(e){let t=new Set;for(let[n,r]of e.entries())for(let i of r.branches??[]){let r=i.to===`end`?e.length:e.findIndex(e=>e.id===i.to);for(let i=n+1;i<r;i++)t.add(e[i].id)}return t}function Ze(e){let t=Xe(e);return e.map(e=>({id:e.id,title:e.title,icon:Ye(e),tone:ie[e.type]??`bg-paper-2 text-ink-2`,optional:t.has(e.id),branches:e.branches}))}function Q({title:e,children:t}){return(0,G.jsx)(`span`,{title:e,className:`inline-flex items-center gap-2 border-border border-l px-4 first:border-l-0 first:pl-0`,children:t})}function $({icon:e,children:t,more:n}){return(0,G.jsxs)(`div`,{className:`flex gap-2.5`,children:[(0,G.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:e}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-[0.875rem] text-ink leading-snug`,children:t}),n?(0,G.jsx)(`div`,{className:`text-[0.75rem] text-ink-3 leading-snug`,children:n}):null]})]})}function Qe({className:e,children:t}){let n=(0,V.useRef)(null),[r,i]=(0,V.useState)({above:!1,below:!1});(0,V.useEffect)(()=>{let e=n.current;if(!e)return;let t=()=>{let t=e.scrollTop>1,n=e.scrollTop+e.clientHeight<e.scrollHeight-1;i(e=>e.above===t&&e.below===n?e:{above:t,below:n})};t(),e.addEventListener(`scroll`,t,{passive:!0});let r=new ResizeObserver(t);return r.observe(e),e.firstElementChild&&r.observe(e.firstElementChild),()=>{e.removeEventListener(`scroll`,t),r.disconnect()}},[]);let a=`linear-gradient(to bottom, ${r.above?`transparent`:`black`} 0, black 28px, black calc(100% - 44px), ${r.below?`transparent`:`black`} 100%)`;return(0,G.jsx)(`div`,{ref:n,className:e,style:{maskImage:a,WebkitMaskImage:a},children:(0,G.jsx)(`div`,{children:t})})}function $e({id:e,fallback:t,onClose:n,onUse:i,busy:a}){let o=s(),u=p(),d=r({queryKey:[`marketplace-entry`,e,w],queryFn:()=>k.get(`/api/studio/marketplace/${encodeURIComponent(e)}?lang=${w}`),enabled:!!e,retry:!1}),f=d.data??t,m=F({mutationFn:t=>{let n=`/api/studio/marketplace/${encodeURIComponent(e)}/star`;return t?k.put(n):k.del(n)},onSuccess:()=>Promise.all([o.invalidateQueries({queryKey:[`marketplace`]}),o.invalidateQueries({queryKey:[`marketplace-entry`,e]})])}),h=c()===`dark`,g=me[he[f?.avatar||`round`]],y=h?`var(--card)`:`color-mix(in oklch, ${g??`var(--ink-4)`} 14%, var(--paper-2))`;return(0,G.jsx)(te,{open:!!e,onClose:n,wide:!0,bare:!0,children:f?(0,G.jsxs)(`div`,{className:`relative flex max-h-[calc(100dvh-48px)] flex-col rounded-2xl bg-card shadow-overlay max-sm:h-dvh max-sm:max-h-none max-sm:rounded-none`,children:[(0,G.jsx)(`button`,{type:`button`,"aria-label":C(`common.close`),onClick:n,className:`sm:-top-3.5 sm:-right-3.5 absolute top-3 right-3 z-20 flex size-9 items-center justify-center rounded-full bg-card text-ink-2 shadow-elevated ring-1 ring-border-soft transition hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus`,children:(0,G.jsx)(_,{className:`size-4`})}),(0,G.jsxs)(`header`,{className:`relative shrink-0 border-border-soft border-b px-5 pt-5 pb-4 text-ink sm:rounded-t-2xl sm:px-7`,style:{background:y,"--coin-bg":y},children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 overflow-hidden sm:rounded-t-2xl`,children:(0,G.jsx)(`span`,{className:S(`-top-28 -right-10 absolute size-80 rounded-full bg-white blur-3xl`,h?`opacity-[0.14]`:`opacity-80`)})}),(0,G.jsx)(`div`,{className:`-bottom-5 absolute right-9 z-10 max-sm:hidden`,children:(0,G.jsx)(l,{kind:f.avatar,size:104})}),(0,G.jsxs)(`div`,{className:`relative sm:pr-36`,children:[(0,G.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight max-sm:pr-10`,children:f.title}),(0,G.jsx)(`p`,{className:`mt-1 text-[0.875rem] text-ink-2 leading-snug`,children:d.data?.description||f.pitch})]}),f.usable?(0,G.jsxs)(`div`,{className:`-mx-5 sm:-mx-7 relative mt-3.5 flex flex-wrap items-center gap-y-2 border-border-soft border-t px-5 pt-3 font-medium text-[0.875rem] sm:px-7 sm:pr-40`,children:[(0,G.jsxs)(Q,{title:C(`market.duration`),children:[(0,G.jsx)(v,{className:`size-4 text-ink-3`}),C(`market.minutes`,{n:f.effort.minutes})]}),(0,G.jsx)(Q,{title:C(`market.cost`),children:(0,G.jsx)(J,{entry:f})}),(0,G.jsx)(Q,{title:C(`market.result`),children:f.formats.map(e=>(0,G.jsx)(q,{format:e,className:`size-4`},e))})]}):null]}),f.usable?(0,G.jsxs)(`div`,{className:`grid min-h-0 flex-1 gap-x-7 gap-y-6 px-5 pt-6 max-sm:overflow-y-auto max-sm:pb-4 sm:grid-cols-[230px_minmax(0,1fr)] sm:grid-rows-[minmax(0,1fr)] sm:px-7`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-5 sm:min-h-0 sm:overflow-y-auto`,children:[(0,G.jsx)(Y,{title:C(`market.duration`),children:(0,G.jsx)($,{icon:(0,G.jsx)(v,{className:`size-4 text-moss`}),more:C(`market.durationHint`,{n:f.effort.fields}),children:C(`market.minutes`,{n:f.effort.minutes})})}),(0,G.jsx)(Y,{title:C(`market.cost`),children:(0,G.jsx)($,{icon:(0,G.jsx)(oe,{className:`size-4 text-amber`}),more:f.credits?C(`market.creditsHint`):void 0,children:(0,G.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,G.jsx)(J,{entry:f}),f.credits?(0,G.jsx)(`span`,{className:`text-ink-2`,children:C(`market.creditsRange`,{n:He(f.credits.credits)})}):null]})})}),(0,G.jsx)(Y,{title:C(`market.result`),children:(0,G.jsx)(`div`,{className:`flex flex-col gap-2`,children:(d.data?.results??[]).map(e=>(0,G.jsx)($,{icon:(0,G.jsx)(q,{format:e.kind,className:`size-4 text-ember-strong`}),more:e.formats.map(e=>e.toUpperCase()).join(` · `),children:e.title},e.title))})}),(0,G.jsx)(Y,{title:C(`market.needs`),children:(0,G.jsx)(`ul`,{className:`flex flex-col gap-2`,children:f.capabilities.map(e=>{let t=Z[e],n=f.missing.includes(e),r=f.optional?.includes(e);return(0,G.jsxs)(`li`,{className:S(`flex items-center gap-2.5 text-[0.875rem]`,n?`text-ink-3`:`text-ink-2`),children:[(0,G.jsx)(t,{className:S(`size-4 shrink-0`,n?`text-rose`:r?`text-amber`:`text-cobalt`)}),K(U,e),n?(0,G.jsx)(`span`,{className:`text-[0.75rem] text-rose`,children:C(`market.unavailable`)}):r?(0,G.jsx)(`span`,{className:`text-[0.75rem] text-amber`,children:C(`market.optional`)}):null]},e)})})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:min-h-0`,children:[(0,G.jsx)(`div`,{className:`mb-1.5 shrink-0 font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.06em]`,children:C(`market.steps`)}),(0,G.jsx)(Qe,{className:`-mr-2 overscroll-contain pt-1 pr-2 pl-1 sm:min-h-0 sm:flex-1 sm:overflow-y-auto`,children:d.isLoading?(0,G.jsx)(x,{className:`size-5 text-ink-3`}):(0,G.jsx)(V.Suspense,{fallback:(0,G.jsx)(x,{className:`size-5 text-ink-3`}),children:(0,G.jsx)(Be,{steps:Ze(d.data?.outline??[])})})})]})]}):(0,G.jsx)(`div`,{className:`flex-1 px-5 pt-6 sm:px-7`,children:(0,G.jsx)(`p`,{className:`rounded-lg bg-amber-tint p-3 text-[0.875rem] text-ink-2`,children:C(`market.needsUpdateHint`)})}),(0,G.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 px-5 pt-4 pb-5 max-sm:border-border-soft max-sm:border-t sm:px-7 sm:pb-6`,children:[f.plugin?(0,G.jsx)(`span`,{className:`mr-auto flex items-center`,children:(0,G.jsx)(qe,{plugin:f.plugin})}):(0,G.jsxs)(D,{variant:`ghost`,className:`mr-auto`,title:C(`market.starHint`),"aria-pressed":f.starred,busy:m.isPending,onClick:()=>m.mutate(!f.starred),children:[(0,G.jsx)(N,{className:S(`size-4`,f.starred&&`fill-amber text-amber`)}),(0,G.jsx)(`span`,{className:`max-sm:sr-only`,children:C(f.starred?`market.starred`:`market.star`)})]}),(0,G.jsx)(D,{variant:`secondary`,onClick:n,children:C(`common.close`)}),f.usable&&f.missing.length?(0,G.jsx)(D,{variant:`secondary`,onClick:()=>u(`/settings/models`),children:C(`editor.models.settings`)}):null,i?(0,G.jsx)(D,{disabled:!f.usable||f.missing.length>0||!!f.needs?.length,title:f.needs?.length?C(`market.needsProHint`,{list:f.needs.join(`, `)}):f.missing.length?C(`market.missingHint`,{list:X(f.missing)}):f.optional?.length?C(`market.optionalHint`,{list:X(f.optional)}):void 0,busy:a,onClick:()=>i(f),children:C(`market.use`)}):null]})]}):(0,G.jsx)(`div`,{className:`flex min-h-48 flex-col items-center justify-center gap-3 rounded-2xl bg-card p-8 text-[0.875rem] text-ink-2 shadow-overlay`,children:d.isLoading?(0,G.jsx)(x,{className:`size-6 text-ink-3`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{children:C(`market.notFound`)}),(0,G.jsx)(D,{variant:`secondary`,onClick:n,children:C(`common.close`)})]})})})}function et({name:e,value:t,options:n,onChange:r}){let[i,a]=(0,V.useState)(!1),o=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=n.find(e=>e.value===t);return(0,G.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,G.jsxs)(`div`,{className:S(`flex h-8 items-center rounded-full text-[0.8125rem] transition`,s?`bg-ember-tint text-ink`:`text-ink-2 hover:bg-paper-2 hover:text-ink`,i&&!s&&`bg-paper-2 text-ink`),children:[(0,G.jsx)(`button`,{type:`button`,"aria-haspopup":`listbox`,"aria-expanded":i,onClick:()=>a(!i),className:S(`flex h-full items-center gap-1.5 rounded-full pl-3 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus`,s?`pr-1`:`pr-2.5`),children:s?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-ink-3`,children:e}),(0,G.jsx)(`span`,{className:`font-medium`,children:s.label})]}):(0,G.jsxs)(G.Fragment,{children:[e,(0,G.jsx)(y,{className:S(`size-3.5 transition`,i&&`rotate-180`)})]})}),s?(0,G.jsx)(`button`,{type:`button`,"aria-label":`${e}: ${C(`market.reset`)}`,onClick:()=>r(``),className:`mr-1 flex size-6 items-center justify-center rounded-full text-ink-3 hover:bg-card hover:text-ink`,children:(0,G.jsx)(_,{className:`size-3.5`})}):null]}),i?(0,G.jsx)(`div`,{role:`listbox`,"aria-label":e,className:`absolute top-full left-0 z-30 mt-1.5 max-h-80 min-w-60 overflow-y-auto rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:n.map(e=>(0,G.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":e.value===t,disabled:!e.count||e.unavailable,onClick:()=>{r(e.value===t?``:e.value),a(!1)},className:S(`flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[0.875rem] transition coarse:py-2.5`,e.count&&!e.unavailable?`text-ink-2 hover:bg-paper-2 hover:text-ink`:`text-ink-4`,e.value===t&&`font-medium text-ink`),children:[e.icon,(0,G.jsx)(`span`,{className:`flex-1 whitespace-nowrap`,children:e.label}),e.value===t?(0,G.jsx)(h,{className:`size-4 text-ember`}):e.unavailable?(0,G.jsx)(`span`,{className:`whitespace-nowrap text-[0.75rem] text-ink-4`,children:C(`market.unavailable`)}):(0,G.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:e.count})]},e.value))}):null]})}function tt(e,t){let[n,r]=(0,V.useState)(e);return(0,V.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}var nt=60;function rt({onUse:e,busy:t,open:n}){let[r,a]=(0,V.useState)(``),[o,s]=(0,V.useState)(Ve),[c,l]=(0,V.useState)(!1),[u,d]=(0,V.useState)(n??null),f=tt(r.trim(),250),p=we({queryKey:[`marketplace`,w,f,o,c],queryFn:({pageParam:e})=>{let t=new URLSearchParams({lang:w,limit:String(nt),offset:String(e)});f&&t.set(`q`,f);for(let[e,n]of Object.entries(o))n&&t.set(e,n);return c&&t.set(`starred`,`1`),k.get(`/api/studio/marketplace?${t}`)},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.entries.length,0);return n<e.total?n:void 0},placeholderData:i}),m=p.data?.pages[0],h=p.data?.pages.flatMap(e=>e.entries)??[],g=m?.all??0,v=r.trim()!==f||p.isFetching&&!p.isFetchingNextPage,y=(e,t,n)=>Object.keys(t).filter(t=>m?.facets[e]?.[t]!==void 0).map(r=>({value:r,label:K(t,r),icon:n?.(r),count:(m?.facets[e])[r]??0,unavailable:e===`capability`&&b.has(r)})),b=new Set(m?.unavailable??[]),ee=y(`useCase`,Le),te=[{key:`industry`,name:C(`market.industry`),options:y(`industry`,Ie)},{key:`format`,name:C(`market.format`),options:y(`format`,H,e=>(0,G.jsx)(q,{format:e,className:`size-4 text-ink-3`}))},{key:`plan`,name:C(`market.plan`),options:y(`plan`,ze)},{key:`capability`,name:C(`market.capability`),options:y(`capability`,U,e=>{let t=Z[e];return(0,G.jsx)(t,{className:`size-4 text-ink-3`})})}],T=!!r.trim()||c||Object.values(o).some(Boolean),E=()=>{s(Ve),a(``),l(!1)};if(p.isLoading)return(0,G.jsx)(`div`,{className:`flex justify-center py-10`,children:(0,G.jsx)(x,{className:`size-6 text-ink-3`})});let O=m?.offline?(0,G.jsxs)(`p`,{className:`mt-4 flex items-center justify-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,G.jsx)(ve,{className:`size-4 shrink-0`}),C(`market.offline`)]}):null;if(!g&&!T)return O;let ne=r?(0,G.jsx)(`button`,{type:`button`,"aria-label":C(`market.reset`),onClick:()=>a(``),className:`-mr-1.5 flex size-7 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-paper-2 hover:text-ink`,children:(0,G.jsx)(_,{className:`size-4`})}):null,A=e=>S(`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-full px-2.5 text-[0.78125rem] transition`,e?`bg-card font-medium text-ink shadow-soft ring-1 ring-border-soft`:`text-ink-3 hover:bg-card/60 hover:text-ink`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`relative mx-auto flex h-10 max-w-md items-center gap-2.5 rounded-full bg-card px-4 shadow-soft ring-1 ring-border-soft transition focus-within:ring-2 focus-within:ring-focus sm:h-11`,children:[v?(0,G.jsx)(x,{className:`size-4 shrink-0 text-ink-3`}):(0,G.jsx)(ae,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`input`,{type:`search`,value:r,onChange:e=>a(e.target.value),placeholder:C(`market.search`),"aria-label":C(`market.search`),className:`min-w-0 flex-1 bg-transparent text-[0.9375rem] outline-none placeholder:text-ink-4 [&::-webkit-search-cancel-button]:hidden`}),ne]}),O,(0,G.jsxs)(`div`,{className:`max-sm:-mx-3 mt-4 flex gap-1 max-sm:overflow-x-auto max-sm:px-3 max-sm:[scrollbar-width:none] sm:flex-wrap sm:justify-center max-sm:[&::-webkit-scrollbar]:hidden`,children:[[{value:``,label:C(`market.all`)},...ee].map(e=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":!c&&o.useCase===e.value,onClick:()=>{l(!1),s({...o,useCase:e.value})},className:A(!c&&o.useCase===e.value),children:e.label},e.value)),(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":c,onClick:()=>l(!c),className:A(c),children:[(0,G.jsx)(N,{className:S(`size-3.5`,c&&`fill-amber text-amber`)}),C(`market.starred`)]})]}),(0,G.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-1 gap-y-2 sm:mt-6`,children:[c?null:te.map(e=>(0,G.jsx)(et,{name:e.name,value:o[e.key],options:e.options,onChange:t=>s({...o,[e.key]:t})},e.key)),(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-3 whitespace-nowrap pl-2 text-[0.8125rem] text-ink-3`,children:[T?(0,G.jsxs)(`button`,{type:`button`,onClick:E,className:`inline-flex items-center gap-1 text-ember-strong underline-offset-2 hover:underline`,children:[(0,G.jsx)(_,{className:`size-3.5 max-sm:size-4`}),(0,G.jsx)(`span`,{className:`max-sm:sr-only`,children:C(`market.resetShort`)})]}):null,T?(0,G.jsx)(`span`,{className:`tabular-nums sm:hidden`,children:C(`market.countOfShort`,{n:m?.total??0,all:g})}):null,(0,G.jsx)(`span`,{className:S(`tabular-nums`,T&&`max-sm:hidden`),children:T?C(`market.countOf`,{n:m?.total??0,all:g}):C(`market.count`,{n:g})})]})]}),h.length?(0,G.jsx)(`div`,{className:`mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:h.map(e=>(0,G.jsx)(Je,{entry:e,onOpen:()=>d(e.id)},e.id))}):(0,G.jsxs)(`div`,{className:`py-10 text-center text-[0.875rem] text-ink-3`,children:[(0,G.jsx)(`p`,{children:C(c?`market.noneStarred`:`market.none`)}),(0,G.jsx)(D,{variant:`ghost`,className:`mt-2`,onClick:E,children:C(`market.reset`)})]}),p.hasNextPage?(0,G.jsx)(`div`,{className:`mt-6 flex justify-center`,children:(0,G.jsx)(D,{variant:`secondary`,busy:p.isFetchingNextPage,onClick:()=>void p.fetchNextPage(),children:C(`market.more`)})}):null,(0,G.jsx)($e,{id:u,fallback:h.find(e=>e.id===u)??null,onClose:()=>d(null),onUse:e,busy:t})]})}var it={de:[`Stellenanzeige aus ein paar Stichworten, als PDF und LinkedIn-Post`,`Produktbeschreibung für den Onlineshop mit drei Bildvarianten`,`Wettbewerbsanalyse zu einer Firma mit Quellen`,`Lead aus einem Formular in unser CRM eintragen`],en:[`A job ad from a few keywords, as PDF and LinkedIn post`,`A shop product description with three image variants`,`A competitor analysis for a company, with sources`,`Put a lead from a form into our CRM`]};function at(){let e=p(),t=s(),{project:n}=ye(),r=ge(),[i,a]=(0,V.useState)(``),[o]=O(),c=F({mutationFn:e=>k.post(`/api/studio/wizards`,{projectId:n.id,starterId:e,lang:w}),onSuccess:async({id:n},r)=>{await t.invalidateQueries({queryKey:[`projects`]}),await t.invalidateQueries({queryKey:[`wizards`]}),e(r?`/edit/${n}`:`/edit/${n}?prompt=${encodeURIComponent(i.trim())}`)}}),u=()=>{i.trim()&&n&&c.mutate(void 0)};return!r||n?.readOnly?(0,G.jsx)(b,{to:`/`,replace:!0}):(0,G.jsxs)(`div`,{className:`animate-rise pt-4`,children:[(0,G.jsxs)(`div`,{className:`mx-auto max-w-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsx)(l,{kind:`sprout`,size:150,fluffy:!0}),(0,G.jsx)(`h1`,{className:`mt-2 font-display font-semibold text-[2rem] leading-tight tracking-tight sm:text-[2.375rem]`,children:C(`new.title`)})]}),(0,G.jsxs)(`div`,{className:`mt-8 rounded-2xl bg-card p-2 shadow-elevated ring-1 ring-border-soft focus-within:ring-focus`,children:[(0,G.jsx)(ee,{autoFocus:!0,minRows:4,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&u()},placeholder:C(`new.placeholder`),className:`border-0 bg-transparent text-[1rem] shadow-none focus:ring-0`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-2 pb-1`,children:[(0,G.jsx)(`span`,{className:`hidden text-[0.75rem] text-ink-4 sm:block`,children:C(`new.hint`)}),(0,G.jsxs)(D,{size:`md`,onClick:u,busy:c.isPending&&!c.variables,disabled:!i.trim(),children:[C(`new.build`),` `,(0,G.jsx)(ne,{className:`size-4`})]})]})]}),(0,G.jsx)(`div`,{className:`mt-4 flex flex-wrap justify-center gap-2`,children:it[w].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:`rounded-full bg-paper-2 px-3.5 py-1.5 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:e},e))})]}),(0,G.jsxs)(`section`,{className:`mx-auto max-w-5xl`,children:[(0,G.jsx)(`h2`,{className:`mt-16 mb-5 text-center font-medium text-[0.8125rem] text-ink-3 uppercase tracking-[0.08em]`,children:C(`new.orStarter`)}),(0,G.jsx)(rt,{open:o.get(`starter`),busy:c.isPending&&!!c.variables,onUse:e=>n&&!c.isPending&&c.mutate(e.id)}),c.error?(0,G.jsx)(`p`,{className:`mt-3 text-center text-[0.875rem] text-rose`,children:c.error.message}):null]}),(0,G.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,G.jsx)(Se,{variant:`ghost`,label:C(`new.import`)})})]})}export{at as NewWizardPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{R as r,p as i}from"./brand-CCAI9p0f.js";import{$ as a,F as o,G as s,H as c,I as l,Q as u,U as d,Y as f,a as p,c as m,d as h,et as ee,f as g,g as _,h as v,i as y,j as b,k as x,m as te,n as S,o as C,p as w,r as T,s as E,t as D,tt as ne,x as O}from"./ui-8QmvuC9u.js";import{a as re,i as ie,r as ae,t as k}from"./RunnerView-BLOCNZaZ.js";import{n as oe}from"./HomePage-Bd-mkLxW.js";import{_ as A,a as se,c as ce,d as le,f as ue,g as de,h as fe,i as pe,l as me,m as he,n as ge,o as _e,p as ve,r as ye,s as be,t as xe,u as j,v as Se,y as Ce}from"./RunDrawer-CtQoY3Ha.js";import{n as M,t as we}from"./upload-CL1R6shM.js";import{t as N}from"./external-link-wKL1HE6G.js";import{r as P,t as Te}from"./wand-sparkles-DYtDQSJZ.js";import{a as F,c as I,d as L,f as R,h as Ee,i as z,l as B,m as V,o as De,p as H,s as U,u as W}from"./Account-DW396ig5.js";import{n as G,t as K}from"./trash-CdLg-Ela.js";import{n as q,t as Oe}from"./star-JHzYYl5R.js";import{t as ke}from"./refresh-cw-Bk7HkOIM.js";import{K as Ae,a as je,at as Me,c as Ne,i as Pe,kt as Fe,m as Ie,o as Le,ot as Re,pt as ze,r as Be,s as Ve,st as He,t as Ue}from"./index-YJMooz0J.js";import{a as J,c as We,f as Ge,i as Ke,m as qe,n as Je,o as Ye,p as Xe,r as Ze,s as Y,t as Qe,u as $e}from"./settings-menu-BM_NfZfn.js";var et={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`]};et.node;var tt=s(et),nt={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`}]]};nt.node;var rt=s(nt),it={name:`phone`,size:24,node:[[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]};it.node;var at=s(it),ot={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`]};ot.node;var st=s(ot),X=e(t(),1),Z=e(n(),1),ct={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function Q({file:e,actions:t}){let[n,r]=(0,X.useState)(e.description),i=(0,X.useRef)(e.description),a=(0,X.useRef)(null);(0,X.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,X.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,Z.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,Z.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:b(o?`project.describing`:`project.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function lt(e,t){confirm(b(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function ut({projectId:e,file:t,small:n}){let r=W(e,t.id);return t.mime.startsWith(`image/`)?(0,Z.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:_(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)}):t.mime.startsWith(`video/`)?(0,Z.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`}):(0,Z.jsx)(`div`,{className:`flex size-full items-center justify-center text-ink-3`,children:t.mime.startsWith(`audio/`)?(0,Z.jsx)(rt,{className:n?`size-5`:`size-7`}):(0,Z.jsx)(re,{className:n?`size-5`:`size-7`})})}function dt({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:a,onPreview:s}){return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map((i,a)=>(0,Z.jsxs)(`div`,{className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[t===`logo`&&a===0?(0,Z.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,Z.jsx)(T,{tone:`ember`,children:b(`project.logoMain`)})}):null,(0,Z.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?ct:void 0,children:[s&&i.mime.startsWith(`image/`)?(0,Z.jsx)(`button`,{type:`button`,"aria-label":`${b(`project.preview`)}: ${i.name}`,onClick:()=>s(i),className:`block size-full cursor-zoom-in`,children:(0,Z.jsx)(ut,{projectId:e,file:i})}):(0,Z.jsx)(ut,{projectId:e,file:i}),(0,Z.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,Z.jsx)(C,{label:b(`project.preview`),onClick:()=>s(i),className:`size-8 bg-card shadow-soft`,children:(0,Z.jsx)(P,{className:`size-4`})}):null,t===`logo`&&a>0&&!r.readOnly?(0,Z.jsx)(C,{label:b(`project.logoMakeMain`),onClick:()=>r.order(`logo`,[i.id,...n.filter(e=>e.id!==i.id).map(e=>e.id)]),className:`size-8 bg-card shadow-soft`,children:(0,Z.jsx)(Oe,{className:`size-4`})}):null,r.readOnly?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>lt(i,r),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]})]}),t===`asset`?(0,Z.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:i.name,children:i.name}):null,(0,Z.jsx)(Q,{file:i,actions:r})]},i.id)),a&&!r.readOnly?(0,Z.jsxs)(F,{accept:i,multiple:!1,onFiles:e=>r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,Z.jsx)(g,{className:`size-5`}):(0,Z.jsx)(o,{className:`size-5`}),a]}):null]})}function ft({projectId:e,data:t,readOnly:n}){let r=R(e,n);return(0,Z.jsxs)(I,{title:b(`project.logos`),hint:b(`project.logosHint`),children:[(0,Z.jsx)(dt,{projectId:e,kind:`logo`,files:t.files.filter(e=>e.kind===`logo`),actions:r,accept:`image/*`,addLabel:b(`project.logoAdd`)}),r.error?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:r.error}):null]})}var pt=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),B(e.size)].filter(Boolean).join(` · `);function mt({projectId:e,file:t,actions:n,onClose:r}){let i=W(e,t.id);return(0,Z.jsxs)(y,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,Z.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:pt(t)}),(0,Z.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":b(`project.openOriginal`),title:b(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Z.jsx)(N,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,Z.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:ct,children:(0,Z.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,Z.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,Z.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(Q,{file:t,actions:n})})]})}function ht({projectId:e,file:t,actions:n,onPreview:r}){return(0,Z.jsxs)(`li`,{className:`flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`${b(`project.preview`)}: ${t.name}`,onClick:r,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,Z.jsx)(ut,{projectId:e,file:t,small:!0})}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:r,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:pt(t)})]}),(0,Z.jsx)(Q,{file:t,actions:n})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-start`,children:[(0,Z.jsx)(C,{label:b(`project.preview`),onClick:r,children:(0,Z.jsx)(P,{className:`size-4`})}),n.readOnly?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>lt(t,n),className:`hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]})]})}function gt({projectId:e,data:t,readOnly:n}){let r=R(e,n),[i,a]=H(`assets`,`cards`),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(null),u=t.files.filter(e=>e.kind===`asset`),d=u.find(e=>e.id===c),f=o.trim().toLowerCase(),p=f?u.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(f)):u;return(0,Z.jsxs)(I,{title:b(`project.assets`),hint:b(`project.assetsHint`),children:[u.length?(0,Z.jsx)(De,{layout:i,onToggle:a,children:(0,Z.jsx)(U,{value:o,onChange:s,placeholder:b(`project.assetSearch`)})}):null,p.length?(0,Z.jsx)(`div`,{className:`mb-3`,children:i===`cards`?(0,Z.jsx)(dt,{projectId:e,kind:`asset`,files:p,actions:r,onPreview:e=>l(e.id)}):(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2`,children:p.map(t=>(0,Z.jsx)(ht,{projectId:e,file:t,actions:r,onPreview:()=>l(t.id)},t.id))})}):null,n?u.length?null:(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:b(`project.staysLocal`)}):(0,Z.jsxs)(F,{accept:`image/*,video/*,audio/*`,onFiles:e=>r.upload(`asset`,e),className:`h-16 w-full`,children:[r.busy?(0,Z.jsx)(g,{className:`size-4`}):(0,Z.jsx)(we,{className:`size-4`}),b(`project.drop`),` `,(0,Z.jsx)(`span`,{className:`underline`,children:b(`project.assetAdd`)})]}),r.error?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:r.error}):null,d?(0,Z.jsx)(mt,{projectId:e,file:d,actions:r,onClose:()=>l(null)}):null]})}function _t(e,t,n){return i({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>O.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function vt(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var yt=e=>[vt(e),e.pages?b(`project.pages`,{n:e.pages}):null,B(e.size)].filter(Boolean).join(` · `),bt=2e5;function xt({projectId:e,fileId:t,readOnly:n,onGone:i}){let a=r(),o=V(e),s=ue(e),c=R(e,n),l=o.data?.files.find(e=>e.id===t),u=l?l.mime===`application/pdf`||l.mime.startsWith(`image/`):!1,[d,f]=(0,X.useState)(null);if(!l)return o.isLoading?(0,Z.jsx)(g,{className:`mx-auto text-ink-3`}):null;let p=d??(u?`original`:`text`),m=s.data?.items.find(e=>e.key===`f:${l.id}`),h=W(e,l.id),ee=(e,t)=>(0,Z.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>f(e),className:_(`rounded-full px-3 py-1 text-[0.8125rem] transition`,p===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,Z.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Z.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:l.name}),(0,Z.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:yt(l)}),(0,Z.jsx)(`a`,{href:h,target:`_blank`,rel:`noreferrer`,"aria-label":b(`project.openOriginal`),title:b(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Z.jsx)(N,{className:`size-4`})}),n?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{label:b(`project.reindex`),onClick:async()=>{await c.reindex(l.id),await a.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,Z.jsx)(ke,{className:`size-4`})}),(0,Z.jsx)(C,{label:b(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(b(`data.confirmDelete`,{title:l.name}))&&(await c.remove(l.id),await a.invalidateQueries({queryKey:[`knowledge`,e]}),i())},children:(0,Z.jsx)(K,{className:`size-4`})})]})]}),(0,Z.jsx)(j,{projectId:e,itemKey:`f:${l.id}`,has:m?.categories??[],originLabel:m?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,Z.jsx)(`div`,{className:`px-1`,children:(0,Z.jsx)(Q,{file:l,actions:c})}),l.status===`failed`?(0,Z.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:l.error}):null,(0,Z.jsxs)(S,{className:`flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[u?ee(`original`,b(`project.original`)):null,ee(`text`,b(`project.readText`))]}),p===`original`?l.mime===`application/pdf`?(0,Z.jsx)(`iframe`,{src:h,title:l.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,Z.jsx)(`img`,{src:h,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,Z.jsx)(St,{projectId:e,file:l})]})]})}function St({projectId:e,file:t}){let n=_t(e,t,bt);return n.isLoading||t.status===`pending`?(0,Z.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,Z.jsx)(g,{})}):n.data?.text?(0,Z.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,Z.jsx)(Ie,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:b(`project.textCut`,{shown:n.data.text.length.toLocaleString(),total:n.data.chars.toLocaleString()})}):null]}):(0,Z.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:b(`project.noText`)})}var Ct=[`text`,`longtext`,`number`,`date`,`url`,`email`,`phone`,`boolean`],wt=/^(\d{4}-\d{2}-\d{2}|\d{1,2}\.\s?\d{1,2}\.\s?\d{4})$/,Tt=/^[+-]?\d{1,3}([.,\s']?\d{3})*([.,]\d+)?$/,Et=/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/,Dt=/^(https?:\/\/|www\.)\S+$/i,Ot=/^\+?[\d\s()/.-]{7,20}$/,kt=/^(ja|nein|yes|no|true|false)$/i;function At(e){let t=e.trim();return t?t.includes(`
|
|
2
|
-
`)||t.length>140?`longtext`:kt.test(t)?`boolean`:Et.test(t)?`email`:Dt.test(t)?`url`:wt.test(t)?`date`:Tt.test(t)&&!/^(\+|0\d)/.test(t)?`number`:Ot.test(t)&&t.replace(/\D/g,``).length>=7?`phone`:`text`:`text`}function jt(e,t=[]){let n=e.toLowerCase().replace(/ä/g,`ae`).replace(/ö/g,`oe`).replace(/ü/g,`ue`).replace(/ß/g,`ss`).normalize(`NFD`).replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).slice(0,40)||`fakt`,r=n;for(let e=2;t.includes(r);e++)r=`${n}_${e}`;return r}var Mt=[{key:`adresse`,de:`Adresse`,en:`Address`},{key:`plz`,de:`PLZ`,en:`Postcode`},{key:`ort`,de:`Ort`,en:`City`},{key:`uid`,de:`UID`,en:`VAT id`},{key:`telefon`,de:`Telefon`,en:`Phone`},{key:`e_mail`,de:`E-Mail`,en:`Email`},{key:`website`,de:`Website`,en:`Website`},{key:`iban`,de:`IBAN`,en:`IBAN`}],Nt={facts:100,colors:12,files:{logo:8,asset:100,document:2e3},bytes:{logo:5e6,asset:15e6,video:8e7,document:3e7}},Pt=/^#[0-9a-fA-F]{6}$/;function Ft({onAdd:e,onClose:t}){let[n,r]=(0,X.useState)(`#e0531b`),[i,a]=(0,X.useState)(``),o=Pt.test(n);return(0,Z.jsx)(y,{open:!0,onClose:t,title:b(`project.colorAddTitle`),children:(0,Z.jsxs)(`form`,{onSubmit:r=>{r.preventDefault(),o&&(e({name:i.trim(),value:n.toLowerCase()}),t())},className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.colorValue`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(w,{value:o?n:`#888888`,onChange:e=>r(e.target.value)}),(0,Z.jsx)(E,{value:n,placeholder:`#e0531b`,spellCheck:!1,onChange:e=>r(e.target.value.trim()),className:`font-mono text-[0.875rem]`})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.colorUseLabel`)}),(0,Z.jsx)(E,{autoFocus:!0,value:i,maxLength:120,placeholder:b(`project.colorName`),onChange:e=>a(e.target.value)}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.colorUse`)})]}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(D,{variant:`ghost`,onClick:t,children:b(`common.cancel`)}),(0,Z.jsx)(D,{type:`submit`,disabled:!o,children:b(`project.add`)})]})]})})}function It({colors:e,save:t,readOnly:n}){let r=(0,X.useRef)(0),[i,a]=(0,X.useState)(()=>e.map(e=>({...e,id:`c${r.current++}`}))),[s,c]=(0,X.useState)(!1),l=L(i.filter(e=>Pt.test(e.value)).map(({name:e,value:t})=>({name:e.trim(),value:t})),t),u=(e,t)=>a(n=>n.map(n=>n.id===e?{...n,...t}:n));return(0,Z.jsxs)(I,{title:b(`project.colors`),hint:b(`project.colorsHint`),save:l,locked:n,children:[(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(w,{value:Pt.test(e.value)?e.value:`#888888`,onChange:t=>u(e.id,{value:t.target.value})}),(0,Z.jsx)(E,{value:e.name,placeholder:b(`project.colorName`),maxLength:120,onChange:t=>u(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,Z.jsx)(E,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>u(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,Z.jsxs)(`div`,{className:`flex w-24 shrink-0 items-center justify-end max-sm:w-auto`,children:[t===0?(0,Z.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,Z.jsx)(T,{tone:`ember`,children:b(`project.colorAccent`)})}):n?null:(0,Z.jsx)(C,{label:b(`project.colorFirst`),onClick:()=>a(t=>[e,...t.filter(t=>t.id!==e.id)]),children:(0,Z.jsx)(d,{className:`size-4`})}),n?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>a(t=>t.filter(t=>t.id!==e.id)),className:`hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]})]},e.id))}),i.length&&!n?(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.colorUse`)}):null,i.length<Nt.colors&&!n?(0,Z.jsxs)(D,{variant:`secondary`,size:`sm`,className:i.length?`mt-3`:void 0,onClick:()=>c(!0),children:[(0,Z.jsx)(o,{className:`size-4`}),` `,b(`project.colorAdd`)]}):null,s?(0,Z.jsx)(Ft,{onClose:()=>c(!1),onAdd:e=>a(t=>[...t,{...e,id:`c${r.current++}`}])}):null]})}var Lt=e=>/^(ja|yes|true)$/i.test(e.trim()),Rt={text:ze,longtext:st,number:Se,date:Ce,url:G,email:ie,phone:at,boolean:A};function zt({type:e,detected:t,onChange:n}){let[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!1),s=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let l=Rt[e??t],u=`${b(`project.factType`)}: ${b(`project.type.${e??t}`)}`,d=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,f=e=>{n(e),i(!1)};return(0,Z.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":u,title:u,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:_(`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,Z.jsx)(l,{className:`size-4`})}),r?(0,Z.jsxs)(`div`,{role:`menu`,className:_(`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,Z.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:d,onClick:()=>f(void 0),children:[(0,Z.jsx)(Te,{className:`size-4 shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:b(`project.factAuto`)}),(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:b(`project.type.${t}`)}),(0,Z.jsx)(c,{className:_(`size-4 shrink-0`,e&&`invisible`)})]}),(0,Z.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),Ct.map(t=>{let n=Rt[t];return(0,Z.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:d,onClick:()=>f(t),children:[(0,Z.jsx)(n,{className:`size-4 shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:b(`project.type.${t}`)}),(0,Z.jsx)(c,{className:_(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Bt({facts:e,save:t,readOnly:n}){let r=(0,X.useRef)(0),i=(0,X.useRef)(null),[a,s]=(0,X.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),c=L(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),l=(e,t)=>s(n=>n.map(n=>n.id===e?{...n,...t}:n)),u=(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])},d=e=>t=>{t&&i.current===e&&(i.current=null,t.focus())},f=Mt.filter(e=>!a.some(t=>t.key===e.key));return(0,Z.jsxs)(I,{title:b(`project.facts`),hint:b(`project.factsHint`),save:c,locked:n,action:a.length<Nt.facts&&!n?(0,Z.jsxs)(D,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`,!0),children:[(0,Z.jsx)(o,{className:`size-4`}),` `,b(`project.factAdd`)]}):null,children:[(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>{let t=At(e.value),r=e.type??t;return(0,Z.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,Z.jsx)(E,{ref:d(`${e.id}:label`),value:e.label,placeholder:b(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>l(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&l(e.id,{key:jt(e.label,a.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,Z.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Z.jsx)(te,{checked:Lt(e.value),label:e.label,onChange:t=>l(e.id,{value:b(t?`project.yes`:`project.no`)})}),(0,Z.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Lt(e.value)?b(`project.yes`):b(`project.no`)})]}):(0,Z.jsx)(v,{ref:d(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:b(`project.factValue`),onChange:t=>l(e.id,{value:t.target.value}),className:`min-h-11`}),(0,Z.jsx)(zt,{type:e.type,detected:t,onChange:t=>l(e.id,{type:t})}),n?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>s(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]},e.id)})}),a.length<Nt.facts&&!n?(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${a.length?`mt-4`:``}`,children:[(0,Z.jsxs)(D,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`),children:[(0,Z.jsx)(o,{className:`size-4`}),` `,b(`project.factAdd`)]}),f.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>u({key:e.key,label:x===`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,Z.jsx)(o,{className:`size-3.5`}),` `,x===`en`?e.en:e.de]},e.key))]}):null]})}function Vt({project:e,save:t}){let[n,r]=(0,X.useState)(e.brand.name??``),[i,a]=(0,X.useState)(e.brand.about??``),o=L({name:n.trim(),about:i.trim()},e=>t({brand:e}));return(0,Z.jsx)(I,{title:b(`project.base`),hint:b(`project.baseHint`),save:o,locked:e.readOnly,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.title`)}),(0,Z.jsx)(E,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.titleHint`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.about`)}),(0,Z.jsx)(v,{minRows:4,value:i,onChange:e=>a(e.target.value)}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.aboutHint`)})]})]})})}function Ht({project:e,group:t,docked:n=!1,children:i}){let a=r(),o=V(e.id),[s,c]=(0,X.useState)(0),l=async t=>{await O.patch(`/api/studio/projects/${e.id}`,t),await a.invalidateQueries({queryKey:[`projects`]})},u=Fe({mutationFn:()=>O.del(`/api/studio/projects/${e.id}`),onSuccess:()=>a.invalidateQueries({queryKey:[`projects`]})}),d=He(),f=Re(),p=o.data??{files:[],embeddings:!0},m=`${e.id}:${s}`,h=e.readOnly;return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-9 pb-32`,children:[h?(0,Z.jsx)(Xe,{children:qe(e)}):(0,Z.jsx)(Ne,{projectId:e.id,part:t,docked:n,onChanged:()=>c(e=>e+1)},e.id),t===`info`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(z,{id:`base`,children:(0,Z.jsx)(Vt,{project:e,save:l},`base:${m}`)}),(0,Z.jsx)(z,{id:`logos`,children:(0,Z.jsx)(ft,{projectId:e.id,data:p,readOnly:h})}),(0,Z.jsx)(z,{id:`colors`,children:(0,Z.jsx)(It,{colors:e.brand.colors??[],save:e=>l({brand:{colors:e}}),readOnly:h},`colors:${m}`)}),(0,Z.jsx)(z,{id:`assets`,children:(0,Z.jsx)(gt,{projectId:e.id,data:p,readOnly:h})}),(0,Z.jsx)(z,{id:`facts`,children:(0,Z.jsx)(Bt,{facts:e.facts,save:e=>l({facts:e}),readOnly:h},`facts:${m}`)})]}):null,i,t===`info`&&d&&!h&&f?(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(D,{variant:`danger`,busy:u.isPending,onClick:()=>confirm(`${b(`settings.delete`)}?`)&&u.mutate(),children:b(`settings.delete`)}),u.error?(0,Z.jsx)(`p`,{className:`mt-2 text-[0.875rem] text-rose`,children:u.error.message}):null]}):null]})}var Ut={q:``,mode:``,days:0};function Wt(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:()=>O.get(`/api/studio/projects/${e}/results${a&&`?${a}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function Gt({filter:e,onFilter:t}){let[n,r]=(0,X.useState)(e.q);return(0,X.useEffect)(()=>{if(n===e.q)return;let r=setTimeout(()=>t({...e,q:n}),250);return()=>clearTimeout(r)},[n,e,t]),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,Z.jsx)(M,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,Z.jsx)(E,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:b(`space.resultsSearch`),"aria-label":b(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,Z.jsx)(h,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:b(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,Z.jsx)(h,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:b(`space.resultsAnyTime`)},{value:`1`,label:b(`space.resultsDay`)},{value:`7`,label:b(`space.resultsDays`,{n:7})},{value:`30`,label:b(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function Kt({data:e,wizardId:t,filter:n,onFilter:r}){let[i,a]=(0,X.useState)(null),o=t=>e.wizards.find(e=>e.id===t)?.title??``,s=new Intl.DateTimeFormat(x,{dateStyle:`medium`,timeStyle:`short`});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(I,{title:t?o(t):b(`space.resultsAll`),hint:b(`space.resultsHint`),plain:!0,children:[(0,Z.jsx)(Gt,{filter:n,onFilter:r}),e.runs.length?(0,Z.jsx)(S,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,Z.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,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?s.format(new Date(e.doneAt)):o(e.wizardId)}),(0,Z.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${s.format(new Date(e.doneAt))} · `,b(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:b(`space.resultFiles`,{n:e.assets}),children:[(0,Z.jsx)(l,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,Z.jsx)(T,{children:`Test`}):(0,Z.jsxs)(T,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,Z.jsx)(S,{children:(0,Z.jsx)(p,{children:n.q.trim()||n.mode||n.days?b(`space.resultsNone`):b(`space.resultsEmpty`)})})]}),i?(0,Z.jsx)(xe,{header:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:o(i.wizardId)}),i.mode===`test`?(0,Z.jsx)(T,{children:`Test`}):(0,Z.jsxs)(T,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>a(null),children:(0,Z.jsx)(k,{runId:i.id,compact:!0},i.id)}):null]})}function qt({project:e,save:t}){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(e.name),o=Fe({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{label:b(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,Z.jsx)(ae,{className:`size-4`})}),(0,Z.jsx)(y,{open:n,onClose:()=>r(!1),title:b(`project.rename`),children:(0,Z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&o.mutate()},children:[(0,Z.jsx)(E,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),o.error?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null,(0,Z.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Z.jsx)(D,{variant:`ghost`,onClick:()=>r(!1),children:b(`common.cancel`)}),(0,Z.jsx)(D,{type:`submit`,busy:o.isPending,disabled:!i.trim(),children:b(`settings.save`)})]})]})})]})}function Jt({project:e}){let t=r();return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(oe,{}),e.readOnly?null:(0,Z.jsx)(qt,{project:e,save:async n=>{await O.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function Yt(e){let t=e.join(` `),[n,r]=(0,X.useState)(e[0]);return(0,X.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=window.scrollY>0&&window.innerHeight+window.scrollY>=document.documentElement.scrollHeight-4,i=Math.max(160,window.innerHeight/3),a=e[0];for(let t of e){let e=document.getElementById(t)?.getBoundingClientRect().top;e!==void 0&&e<=i&&(a=t)}r(t?e.at(-1):a)},a=()=>{n||=requestAnimationFrame(i)};return i(),window.addEventListener(`scroll`,a,{passive:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,a),window.removeEventListener(`resize`,a)}},[t]),n}function Xt(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function $({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,Z.jsx)(J,{icon:e.icon??q,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,Z.jsx)(Ke,{label:e.label,children:r},e.plugin):(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function Zt(){let{group:e}=ee(),[t,n]=ne(),r=a(),i=u(),{hash:o}=i,{project:s,loading:c}=Me(),l=He(),d=Be(),m=$e(),[h,g]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),[x,te]=(0,X.useState)(null),S=je(e)?e:void 0,C=i.state?.parts===!0,w=Ve().map(e=>({...e,to:`/space/${e.id}`})),T=w.find(e=>e.id===S),E=t.get(`show`),D=S?E?2:1:0,O=m?Math.min(D,1):S&&x!==S&&!C?1:0,re=Ge(O),ie=Ge(D),ae=(0,X.useMemo)(()=>({slot:h,narrow:m,setDetail:y}),[h,m]),k=s?s.brand.name?.trim()||s.name:b(`nav.project`),oe=S&&S!==`results`?Le(S,d):[],A=S?Le(S,d).filter(e=>e.plugin):[],xe=Yt([...oe,...S===`results`?A:[]].flatMap(e=>e.sections.map(e=>e.id))),j=S===`results`&&E&&E!==`all`?E:null,[Se,Ce]=(0,X.useState)(Ut),M=Wt(S===`results`?s?.id:void 0,j,Se),we=M.data?.wizards.find(e=>e.id===j)?.title,N=S===`data`&&E&&E!==`all`||S===`knowledge`&&E&&/^[ptfcvs]:/.test(E)?E:null,P=N?.startsWith(`s:`)?d.spaceSections.find(e=>e.id===N.slice(2)):void 0,F=S===`knowledge`&&N&&/^[ptf]:/.test(N)?N:null,L=_e(S===`data`?s?.id:void 0),R=ue(S===`knowledge`?s?.id:void 0),B=de(N?.startsWith(`v:`)?N.slice(2):``),V=R.data?.categories.find(e=>e.id===(N?.startsWith(`c:`)?N.slice(2):B.data?.category.id)),De=S===`knowledge`?P?P.label():N?.startsWith(`v:`)?B.data&&`${B.data.category.name}: ${B.data.value}`:N?.startsWith(`c:`)?V?.name:R.data?.items.find(e=>e.key===N)?.title:L.data?se(L.data).flatMap(e=>e.items).find(e=>e.key===N)?.title:void 0;Ae([{label:k,to:`/space`},...T?[{label:T.label,to:`/space/${T.id}`}]:[],...T&&(v??we??De)?[{label:v??we??De}]:[]]);let H=S===`results`||S===`data`||N?o.slice(1):E||o.slice(1),U=(0,X.useRef)(``);if((0,X.useEffect)(()=>{let e=`${S}#${H}`;H&&U.current!==e&&document.getElementById(H)&&(U.current=e,requestAnimationFrame(()=>Xt(H,!1)))},[S,H,s?.id,d.spaceSections]),!S){let t=o.slice(1),n=t?Pe(t,d):null;if(n===`knowledge`&&d.spaceSections.some(e=>e.id===t))return(0,Z.jsx)(f,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,Z.jsx)(f,{to:m?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if(t&&d.status!==`ready`)return null;if(e!==void 0||!m)return(0,Z.jsx)(f,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(S===`knowledge`&&!E&&d.spaceSections.some(e=>e.id===o.slice(1)))return(0,Z.jsx)(f,{to:`/space/knowledge?show=s:${o.slice(1)}`,replace:!0});let W=e=>{if(m){r({search:`?show=${e}`});return}U.current=`${S}#${e}`,Xt(e,!0),r({search:``,hash:e},{replace:!0})},G=e=>m?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),K=e=>e.flatMap(e=>e.sections).map(e=>d.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,Z.jsx)(z,{id:e.id,children:(0,Z.jsx)(I,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,Z.jsx)(Ue,{of:e,children:(0,Z.jsx)(e.component,{})})})},e.serial)),q=m?void 0:xe;return(0,Z.jsx)(Ye.Provider,{value:ae,children:(0,Z.jsx)(`div`,{className:`animate-rise`,children:(0,Z.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,Z.jsxs)(`aside`,{className:_(`min-w-0 md:sticky md:top-20 md:self-start`,m&&D===2&&`hidden`,m&&ie===`back`&&We(`back`)),children:[(0,Z.jsx)(Je,{title:k,open:O===1?T??null:null,onBack:()=>m?r(`/space`):te(S??null)}),(0,Z.jsx)(`div`,{className:_(We(re)),children:O===0?(0,Z.jsx)(Ze,{entries:w,current:m?void 0:T,onPick:()=>te(null)}):(0,Z.jsx)(`div`,{ref:g})},O)]}),S?(0,Z.jsxs)(`div`,{className:_(`min-w-0`,m&&D<2&&`hidden`,m&&ie===`deeper`&&We(`deeper`)),children:[m?(0,Z.jsx)(`div`,{className:`mb-3`,children:(0,Z.jsx)(Qe,{label:T?.label??k,onBack:()=>r(`/space/${S}`)})}):null,l&&s?(0,Z.jsx)(`div`,{className:`mb-6`,children:(0,Z.jsx)(Jt,{project:s})}):null,S===`results`?(0,Z.jsxs)(Y,{children:[(0,Z.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,Z.jsx)(J,{icon:tt,label:b(`space.resultsAll`),selected:!m&&!j,onPick:()=>G(`all`)}),M.data?.wizards.filter(e=>e.results||e.id===j).map(e=>(0,Z.jsx)(J,{icon:Te,label:e.title,badge:e.results?(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!m&&e.id===j,onPick:()=>G(e.id)},e.id))]}),(0,Z.jsx)($,{groups:A,current:q,onPick:W})]}):S===`data`?(0,Z.jsxs)(Y,{children:[(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Z.jsx)(J,{icon:Ee,label:b(`data.all`),selected:!m&&!N,onPick:()=>G(`all`)})}),L.data?se(L.data).map(e=>(0,Z.jsx)(Ke,{label:e.label,children:e.items.map(e=>(0,Z.jsx)(J,{icon:ye[e.kind],label:e.title,selected:!m&&e.key===N,onPick:()=>G(e.key)},e.key))},e.key)):null,(0,Z.jsx)($,{groups:A,current:q,onPick:W})]}):S===`knowledge`?(0,Z.jsxs)(Y,{children:[(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Z.jsx)(J,{icon:Ee,label:b(`know.all`),selected:!(m||N),onPick:()=>G(`all`)})}),R.data?.categories.length?(0,Z.jsx)(Ke,{label:b(`know.categories`),children:R.data.categories.map(e=>(0,Z.jsx)(J,{icon:ve[e.type],label:e.name,badge:(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!m&&(N===`c:${e.id}`||B.data?.category.id===e.id),onPick:()=>G(`c:${e.id}`)},e.id))}):null,(0,Z.jsx)($,{groups:A,current:m?void 0:P?.id,onPick:e=>G(`s:${e}`)})]}):(0,Z.jsx)(Y,{children:(0,Z.jsx)($,{groups:oe,current:q,onPick:W})}),s&&(S===`info`||S===`knowledge`)?(0,Z.jsxs)(Ht,{project:s,group:S,docked:S===`knowledge`&&!!N&&!P,children:[S===`knowledge`?F?F.startsWith(`p:`)?(0,Z.jsx)(be,{pageId:F.slice(2),onGone:()=>G(`all`),onOpen:G},F):F.startsWith(`t:`)?(0,Z.jsx)(ge,{tableId:F.slice(2),onGone:()=>G(`all`)},F):(0,Z.jsx)(xt,{projectId:s.id,fileId:F.slice(2),readOnly:s.readOnly,onGone:()=>G(`all`)},F):R.data?P?(0,Z.jsx)(I,{title:P.label(),hint:P.hint?.(),plain:!0,children:(0,Z.jsx)(Ue,{of:P,children:(0,Z.jsx)(P.component,{})})},N):N?.startsWith(`c:`)?V?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Z.jsx)(he,{projectId:s.id,category:V,readOnly:s.readOnly,onOpen:G,onGone:()=>G(`all`)}),V.type===`choice`?null:(0,Z.jsx)(ce,{projectId:s.id,category:V,categories:R.data.categories,onOpen:G})]},N):null:N?.startsWith(`v:`)?B.data?(0,Z.jsx)(fe,{value:B.data,readOnly:s.readOnly,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[B.data.items.length?(0,Z.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:B.data.items.map(e=>(0,Z.jsx)(me,{item:e,categories:R.data.categories.filter(e=>e.id!==B.data?.category.id),onOpen:G},e.key))}):null,B.data.rows.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>G(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:b(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},N):null:(0,Z.jsx)(z,{id:`documents`,children:(0,Z.jsx)(le,{projectId:s.id,data:R.data,readOnly:s.readOnly,onOpen:G})}):null:null,S===`info`?K(A):null]},s.id):null,s&&S===`data`?(0,Z.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:N?.startsWith(`t:`)?(0,Z.jsx)(ge,{tableId:N.slice(2),onGone:()=>G(`all`)},N):N?.startsWith(`p:`)?(0,Z.jsx)(be,{pageId:N.slice(2),onGone:()=>G(`all`)},N):(0,Z.jsxs)(Z.Fragment,{children:[L.data?(0,Z.jsx)(pe,{projectId:s.id,data:L.data,readOnly:s.readOnly,onOpen:G}):null,K(A)]})}):null,s&&S===`results`?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[M.data?(0,Z.jsx)(Kt,{data:M.data,wizardId:j,filter:Se,onFilter:Ce}):null,M.isError?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:M.error.message}):null,K(A)]}):null,s||c?null:(0,Z.jsx)(p,{children:b(`settings.noProject`)})]}):null]})})})}export{Zt as ProjectPage};
|
|
1
|
+
import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{D as r,Q as i}from"./surface-D7bnQtqR.js";import{$ as a,F as o,G as s,H as c,I as l,Q as u,U as d,Y as f,a as p,c as m,d as h,et as ee,f as g,g as _,h as v,i as y,j as b,k as x,m as te,n as S,o as C,p as w,r as T,s as E,t as D,tt as ne,x as O}from"./ui-BZ01zr3i.js";import{a as re,i as ie,r as ae,t as k}from"./RunnerView-JOMD-e27.js";import{n as oe}from"./HomePage-eYqUUwzG.js";import{_ as A,a as se,c as ce,d as le,f as ue,g as de,h as fe,i as pe,l as me,m as he,n as ge,o as _e,p as ve,r as ye,s as be,t as xe,u as j,v as Se,y as Ce}from"./RunDrawer-BdcgNjPZ.js";import{n as M,t as we}from"./upload-U0i8fAW3.js";import{t as N}from"./external-link-BwCtn1nW.js";import{r as P,t as Te}from"./wand-sparkles-MelvBtiK.js";import{a as F,c as I,d as L,f as R,h as Ee,i as z,l as B,m as V,o as De,p as H,s as U,u as W}from"./Account-BaOouMw9.js";import{n as G,t as K}from"./trash-3S1_XpVa.js";import{n as q,t as Oe}from"./star-axQV_3EC.js";import{t as ke}from"./refresh-cw-B9M1g3SH.js";import{J as Ae,P as je,Y as Me,_t as Ne,a as Pe,c as Fe,i as Ie,m as Le,o as Re,q as ze,r as Be,s as Ve,t as He,tt as Ue}from"./index-knnf98Fv.js";import{a as J,c as We,f as Ge,i as Ke,m as qe,n as Je,o as Ye,p as Xe,r as Ze,s as Y,t as Qe,u as $e}from"./settings-menu-DC825gd1.js";var et={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`]};et.node;var tt=s(et),nt={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`}]]};nt.node;var rt=s(nt),it={name:`phone`,size:24,node:[[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]};it.node;var at=s(it),ot={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`]};ot.node;var st=s(ot),X=e(t(),1),Z=e(n(),1),ct={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function Q({file:e,actions:t}){let[n,r]=(0,X.useState)(e.description),i=(0,X.useRef)(e.description),a=(0,X.useRef)(null);(0,X.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,X.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,Z.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,Z.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:b(o?`project.describing`:`project.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function lt(e,t){confirm(b(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function ut({projectId:e,file:t,small:n}){let r=W(e,t.id);return t.mime.startsWith(`image/`)?(0,Z.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:_(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)}):t.mime.startsWith(`video/`)?(0,Z.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`}):(0,Z.jsx)(`div`,{className:`flex size-full items-center justify-center text-ink-3`,children:t.mime.startsWith(`audio/`)?(0,Z.jsx)(rt,{className:n?`size-5`:`size-7`}):(0,Z.jsx)(re,{className:n?`size-5`:`size-7`})})}function dt({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:a,onPreview:s}){return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map((i,a)=>(0,Z.jsxs)(`div`,{className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[t===`logo`&&a===0?(0,Z.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,Z.jsx)(T,{tone:`ember`,children:b(`project.logoMain`)})}):null,(0,Z.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?ct:void 0,children:[s&&i.mime.startsWith(`image/`)?(0,Z.jsx)(`button`,{type:`button`,"aria-label":`${b(`project.preview`)}: ${i.name}`,onClick:()=>s(i),className:`block size-full cursor-zoom-in`,children:(0,Z.jsx)(ut,{projectId:e,file:i})}):(0,Z.jsx)(ut,{projectId:e,file:i}),(0,Z.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,Z.jsx)(C,{label:b(`project.preview`),onClick:()=>s(i),className:`size-8 bg-card shadow-soft`,children:(0,Z.jsx)(P,{className:`size-4`})}):null,t===`logo`&&a>0&&!r.readOnly?(0,Z.jsx)(C,{label:b(`project.logoMakeMain`),onClick:()=>r.order(`logo`,[i.id,...n.filter(e=>e.id!==i.id).map(e=>e.id)]),className:`size-8 bg-card shadow-soft`,children:(0,Z.jsx)(Oe,{className:`size-4`})}):null,r.readOnly?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>lt(i,r),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]})]}),t===`asset`?(0,Z.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:i.name,children:i.name}):null,(0,Z.jsx)(Q,{file:i,actions:r})]},i.id)),a&&!r.readOnly?(0,Z.jsxs)(F,{accept:i,multiple:!1,onFiles:e=>r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,Z.jsx)(g,{className:`size-5`}):(0,Z.jsx)(o,{className:`size-5`}),a]}):null]})}function ft({projectId:e,data:t,readOnly:n}){let r=R(e,n);return(0,Z.jsxs)(I,{title:b(`project.logos`),hint:b(`project.logosHint`),children:[(0,Z.jsx)(dt,{projectId:e,kind:`logo`,files:t.files.filter(e=>e.kind===`logo`),actions:r,accept:`image/*`,addLabel:b(`project.logoAdd`)}),r.error?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:r.error}):null]})}var pt=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),B(e.size)].filter(Boolean).join(` · `);function mt({projectId:e,file:t,actions:n,onClose:r}){let i=W(e,t.id);return(0,Z.jsxs)(y,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,Z.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:pt(t)}),(0,Z.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":b(`project.openOriginal`),title:b(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Z.jsx)(N,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,Z.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:ct,children:(0,Z.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,Z.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,Z.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,Z.jsx)(`div`,{className:`mt-4`,children:(0,Z.jsx)(Q,{file:t,actions:n})})]})}function ht({projectId:e,file:t,actions:n,onPreview:r}){return(0,Z.jsxs)(`li`,{className:`flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`${b(`project.preview`)}: ${t.name}`,onClick:r,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,Z.jsx)(ut,{projectId:e,file:t,small:!0})}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:r,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:pt(t)})]}),(0,Z.jsx)(Q,{file:t,actions:n})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-start`,children:[(0,Z.jsx)(C,{label:b(`project.preview`),onClick:r,children:(0,Z.jsx)(P,{className:`size-4`})}),n.readOnly?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>lt(t,n),className:`hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]})]})}function gt({projectId:e,data:t,readOnly:n}){let r=R(e,n),[i,a]=H(`assets`,`cards`),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(null),u=t.files.filter(e=>e.kind===`asset`),d=u.find(e=>e.id===c),f=o.trim().toLowerCase(),p=f?u.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(f)):u;return(0,Z.jsxs)(I,{title:b(`project.assets`),hint:b(`project.assetsHint`),children:[u.length?(0,Z.jsx)(De,{layout:i,onToggle:a,children:(0,Z.jsx)(U,{value:o,onChange:s,placeholder:b(`project.assetSearch`)})}):null,p.length?(0,Z.jsx)(`div`,{className:`mb-3`,children:i===`cards`?(0,Z.jsx)(dt,{projectId:e,kind:`asset`,files:p,actions:r,onPreview:e=>l(e.id)}):(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2`,children:p.map(t=>(0,Z.jsx)(ht,{projectId:e,file:t,actions:r,onPreview:()=>l(t.id)},t.id))})}):null,n?u.length?null:(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:b(`project.staysLocal`)}):(0,Z.jsxs)(F,{accept:`image/*,video/*,audio/*`,onFiles:e=>r.upload(`asset`,e),className:`h-16 w-full`,children:[r.busy?(0,Z.jsx)(g,{className:`size-4`}):(0,Z.jsx)(we,{className:`size-4`}),b(`project.drop`),` `,(0,Z.jsx)(`span`,{className:`underline`,children:b(`project.assetAdd`)})]}),r.error?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:r.error}):null,d?(0,Z.jsx)(mt,{projectId:e,file:d,actions:r,onClose:()=>l(null)}):null]})}function _t(e,t,n){return r({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>O.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function vt(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var yt=e=>[vt(e),e.pages?b(`project.pages`,{n:e.pages}):null,B(e.size)].filter(Boolean).join(` · `),bt=2e5;function xt({projectId:e,fileId:t,readOnly:n,onGone:r}){let a=i(),o=V(e),s=ue(e),c=R(e,n),l=o.data?.files.find(e=>e.id===t),u=l?l.mime===`application/pdf`||l.mime.startsWith(`image/`):!1,[d,f]=(0,X.useState)(null);if(!l)return o.isLoading?(0,Z.jsx)(g,{className:`mx-auto text-ink-3`}):null;let p=d??(u?`original`:`text`),m=s.data?.items.find(e=>e.key===`f:${l.id}`),h=W(e,l.id),ee=(e,t)=>(0,Z.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>f(e),className:_(`rounded-full px-3 py-1 text-[0.8125rem] transition`,p===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,Z.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Z.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:l.name}),(0,Z.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:yt(l)}),(0,Z.jsx)(`a`,{href:h,target:`_blank`,rel:`noreferrer`,"aria-label":b(`project.openOriginal`),title:b(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,Z.jsx)(N,{className:`size-4`})}),n?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{label:b(`project.reindex`),onClick:async()=>{await c.reindex(l.id),await a.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,Z.jsx)(ke,{className:`size-4`})}),(0,Z.jsx)(C,{label:b(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(b(`data.confirmDelete`,{title:l.name}))&&(await c.remove(l.id),await a.invalidateQueries({queryKey:[`knowledge`,e]}),r())},children:(0,Z.jsx)(K,{className:`size-4`})})]})]}),(0,Z.jsx)(j,{projectId:e,itemKey:`f:${l.id}`,has:m?.categories??[],originLabel:m?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,Z.jsx)(`div`,{className:`px-1`,children:(0,Z.jsx)(Q,{file:l,actions:c})}),l.status===`failed`?(0,Z.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:l.error}):null,(0,Z.jsxs)(S,{className:`flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[u?ee(`original`,b(`project.original`)):null,ee(`text`,b(`project.readText`))]}),p===`original`?l.mime===`application/pdf`?(0,Z.jsx)(`iframe`,{src:h,title:l.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,Z.jsx)(`img`,{src:h,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,Z.jsx)(St,{projectId:e,file:l})]})]})}function St({projectId:e,file:t}){let n=_t(e,t,bt);return n.isLoading||t.status===`pending`?(0,Z.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,Z.jsx)(g,{})}):n.data?.text?(0,Z.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,Z.jsx)(Le,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:b(`project.textCut`,{shown:n.data.text.length.toLocaleString(),total:n.data.chars.toLocaleString()})}):null]}):(0,Z.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:b(`project.noText`)})}var Ct=[`text`,`longtext`,`number`,`date`,`url`,`email`,`phone`,`boolean`],wt=/^(\d{4}-\d{2}-\d{2}|\d{1,2}\.\s?\d{1,2}\.\s?\d{4})$/,Tt=/^[+-]?\d{1,3}([.,\s']?\d{3})*([.,]\d+)?$/,Et=/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/,Dt=/^(https?:\/\/|www\.)\S+$/i,Ot=/^\+?[\d\s()/.-]{7,20}$/,kt=/^(ja|nein|yes|no|true|false)$/i;function At(e){let t=e.trim();return t?t.includes(`
|
|
2
|
+
`)||t.length>140?`longtext`:kt.test(t)?`boolean`:Et.test(t)?`email`:Dt.test(t)?`url`:wt.test(t)?`date`:Tt.test(t)&&!/^(\+|0\d)/.test(t)?`number`:Ot.test(t)&&t.replace(/\D/g,``).length>=7?`phone`:`text`:`text`}function jt(e,t=[]){let n=e.toLowerCase().replace(/ä/g,`ae`).replace(/ö/g,`oe`).replace(/ü/g,`ue`).replace(/ß/g,`ss`).normalize(`NFD`).replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).slice(0,40)||`fakt`,r=n;for(let e=2;t.includes(r);e++)r=`${n}_${e}`;return r}var Mt=[{key:`adresse`,de:`Adresse`,en:`Address`},{key:`plz`,de:`PLZ`,en:`Postcode`},{key:`ort`,de:`Ort`,en:`City`},{key:`uid`,de:`UID`,en:`VAT id`},{key:`telefon`,de:`Telefon`,en:`Phone`},{key:`e_mail`,de:`E-Mail`,en:`Email`},{key:`website`,de:`Website`,en:`Website`},{key:`iban`,de:`IBAN`,en:`IBAN`}],Nt={facts:100,colors:12,files:{logo:8,asset:100,document:2e3},bytes:{logo:5e6,asset:15e6,video:8e7,document:3e7}},Pt=/^#[0-9a-fA-F]{6}$/;function Ft({onAdd:e,onClose:t}){let[n,r]=(0,X.useState)(`#e0531b`),[i,a]=(0,X.useState)(``),o=Pt.test(n);return(0,Z.jsx)(y,{open:!0,onClose:t,title:b(`project.colorAddTitle`),children:(0,Z.jsxs)(`form`,{onSubmit:r=>{r.preventDefault(),o&&(e({name:i.trim(),value:n.toLowerCase()}),t())},className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.colorValue`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(w,{value:o?n:`#888888`,onChange:e=>r(e.target.value)}),(0,Z.jsx)(E,{value:n,placeholder:`#e0531b`,spellCheck:!1,onChange:e=>r(e.target.value.trim()),className:`font-mono text-[0.875rem]`})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.colorUseLabel`)}),(0,Z.jsx)(E,{autoFocus:!0,value:i,maxLength:120,placeholder:b(`project.colorName`),onChange:e=>a(e.target.value)}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.colorUse`)})]}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(D,{variant:`ghost`,onClick:t,children:b(`common.cancel`)}),(0,Z.jsx)(D,{type:`submit`,disabled:!o,children:b(`project.add`)})]})]})})}function It({colors:e,save:t,readOnly:n}){let r=(0,X.useRef)(0),[i,a]=(0,X.useState)(()=>e.map(e=>({...e,id:`c${r.current++}`}))),[s,c]=(0,X.useState)(!1),l=L(i.filter(e=>Pt.test(e.value)).map(({name:e,value:t})=>({name:e.trim(),value:t})),t),u=(e,t)=>a(n=>n.map(n=>n.id===e?{...n,...t}:n));return(0,Z.jsxs)(I,{title:b(`project.colors`),hint:b(`project.colorsHint`),save:l,locked:n,children:[(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(w,{value:Pt.test(e.value)?e.value:`#888888`,onChange:t=>u(e.id,{value:t.target.value})}),(0,Z.jsx)(E,{value:e.name,placeholder:b(`project.colorName`),maxLength:120,onChange:t=>u(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,Z.jsx)(E,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>u(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,Z.jsxs)(`div`,{className:`flex w-24 shrink-0 items-center justify-end max-sm:w-auto`,children:[t===0?(0,Z.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,Z.jsx)(T,{tone:`ember`,children:b(`project.colorAccent`)})}):n?null:(0,Z.jsx)(C,{label:b(`project.colorFirst`),onClick:()=>a(t=>[e,...t.filter(t=>t.id!==e.id)]),children:(0,Z.jsx)(d,{className:`size-4`})}),n?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>a(t=>t.filter(t=>t.id!==e.id)),className:`hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]})]},e.id))}),i.length&&!n?(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.colorUse`)}):null,i.length<Nt.colors&&!n?(0,Z.jsxs)(D,{variant:`secondary`,size:`sm`,className:i.length?`mt-3`:void 0,onClick:()=>c(!0),children:[(0,Z.jsx)(o,{className:`size-4`}),` `,b(`project.colorAdd`)]}):null,s?(0,Z.jsx)(Ft,{onClose:()=>c(!1),onAdd:e=>a(t=>[...t,{...e,id:`c${r.current++}`}])}):null]})}var Lt=e=>/^(ja|yes|true)$/i.test(e.trim()),Rt={text:Ue,longtext:st,number:Se,date:Ce,url:G,email:ie,phone:at,boolean:A};function zt({type:e,detected:t,onChange:n}){let[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!1),s=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let l=Rt[e??t],u=`${b(`project.factType`)}: ${b(`project.type.${e??t}`)}`,d=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,f=e=>{n(e),i(!1)};return(0,Z.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":u,title:u,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:_(`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,Z.jsx)(l,{className:`size-4`})}),r?(0,Z.jsxs)(`div`,{role:`menu`,className:_(`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,Z.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:d,onClick:()=>f(void 0),children:[(0,Z.jsx)(Te,{className:`size-4 shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:b(`project.factAuto`)}),(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:b(`project.type.${t}`)}),(0,Z.jsx)(c,{className:_(`size-4 shrink-0`,e&&`invisible`)})]}),(0,Z.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),Ct.map(t=>{let n=Rt[t];return(0,Z.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:d,onClick:()=>f(t),children:[(0,Z.jsx)(n,{className:`size-4 shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1`,children:b(`project.type.${t}`)}),(0,Z.jsx)(c,{className:_(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Bt({facts:e,save:t,readOnly:n}){let r=(0,X.useRef)(0),i=(0,X.useRef)(null),[a,s]=(0,X.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),c=L(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),l=(e,t)=>s(n=>n.map(n=>n.id===e?{...n,...t}:n)),u=(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])},d=e=>t=>{t&&i.current===e&&(i.current=null,t.focus())},f=Mt.filter(e=>!a.some(t=>t.key===e.key));return(0,Z.jsxs)(I,{title:b(`project.facts`),hint:b(`project.factsHint`),save:c,locked:n,action:a.length<Nt.facts&&!n?(0,Z.jsxs)(D,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`,!0),children:[(0,Z.jsx)(o,{className:`size-4`}),` `,b(`project.factAdd`)]}):null,children:[(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>{let t=At(e.value),r=e.type??t;return(0,Z.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,Z.jsx)(E,{ref:d(`${e.id}:label`),value:e.label,placeholder:b(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>l(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&l(e.id,{key:jt(e.label,a.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,Z.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,Z.jsx)(te,{checked:Lt(e.value),label:e.label,onChange:t=>l(e.id,{value:b(t?`project.yes`:`project.no`)})}),(0,Z.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Lt(e.value)?b(`project.yes`):b(`project.no`)})]}):(0,Z.jsx)(v,{ref:d(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:b(`project.factValue`),onChange:t=>l(e.id,{value:t.target.value}),className:`min-h-11`}),(0,Z.jsx)(zt,{type:e.type,detected:t,onChange:t=>l(e.id,{type:t})}),n?null:(0,Z.jsx)(C,{label:b(`project.remove`),onClick:()=>s(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,Z.jsx)(K,{className:`size-4`})})]},e.id)})}),a.length<Nt.facts&&!n?(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${a.length?`mt-4`:``}`,children:[(0,Z.jsxs)(D,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`),children:[(0,Z.jsx)(o,{className:`size-4`}),` `,b(`project.factAdd`)]}),f.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>u({key:e.key,label:x===`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,Z.jsx)(o,{className:`size-3.5`}),` `,x===`en`?e.en:e.de]},e.key))]}):null]})}function Vt({project:e,save:t}){let[n,r]=(0,X.useState)(e.brand.name??``),[i,a]=(0,X.useState)(e.brand.about??``),o=L({name:n.trim(),about:i.trim()},e=>t({brand:e}));return(0,Z.jsx)(I,{title:b(`project.base`),hint:b(`project.baseHint`),save:o,locked:e.readOnly,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.title`)}),(0,Z.jsx)(E,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.titleHint`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(m,{children:b(`project.about`)}),(0,Z.jsx)(v,{minRows:4,value:i,onChange:e=>a(e.target.value)}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:b(`project.aboutHint`)})]})]})})}function Ht({project:e,group:t,docked:n=!1,children:r}){let a=i(),o=V(e.id),[s,c]=(0,X.useState)(0),l=async t=>{await O.patch(`/api/studio/projects/${e.id}`,t),await a.invalidateQueries({queryKey:[`projects`]})},u=Ne({mutationFn:()=>O.del(`/api/studio/projects/${e.id}`),onSuccess:()=>a.invalidateQueries({queryKey:[`projects`]})}),d=Me(),f=Ae(),p=o.data??{files:[],embeddings:!0},m=`${e.id}:${s}`,h=e.readOnly;return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-9 pb-32`,children:[h?(0,Z.jsx)(Xe,{children:qe(e)}):(0,Z.jsx)(Fe,{projectId:e.id,part:t,docked:n,onChanged:()=>c(e=>e+1)},e.id),t===`info`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(z,{id:`base`,children:(0,Z.jsx)(Vt,{project:e,save:l},`base:${m}`)}),(0,Z.jsx)(z,{id:`logos`,children:(0,Z.jsx)(ft,{projectId:e.id,data:p,readOnly:h})}),(0,Z.jsx)(z,{id:`colors`,children:(0,Z.jsx)(It,{colors:e.brand.colors??[],save:e=>l({brand:{colors:e}}),readOnly:h},`colors:${m}`)}),(0,Z.jsx)(z,{id:`assets`,children:(0,Z.jsx)(gt,{projectId:e.id,data:p,readOnly:h})}),(0,Z.jsx)(z,{id:`facts`,children:(0,Z.jsx)(Bt,{facts:e.facts,save:e=>l({facts:e}),readOnly:h},`facts:${m}`)})]}):null,r,t===`info`&&d&&!h&&f?(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(D,{variant:`danger`,busy:u.isPending,onClick:()=>confirm(`${b(`settings.delete`)}?`)&&u.mutate(),children:b(`settings.delete`)}),u.error?(0,Z.jsx)(`p`,{className:`mt-2 text-[0.875rem] text-rose`,children:u.error.message}):null]}):null]})}var Ut={q:``,mode:``,days:0};function Wt(e,t,n){let i=new URLSearchParams;t&&i.set(`wizard`,t),n.q.trim()&&i.set(`q`,n.q.trim()),n.mode&&i.set(`mode`,n.mode),n.days&&i.set(`days`,String(n.days));let a=i.toString();return r({queryKey:[`results`,e,a],queryFn:()=>O.get(`/api/studio/projects/${e}/results${a&&`?${a}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function Gt({filter:e,onFilter:t}){let[n,r]=(0,X.useState)(e.q);return(0,X.useEffect)(()=>{if(n===e.q)return;let r=setTimeout(()=>t({...e,q:n}),250);return()=>clearTimeout(r)},[n,e,t]),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,Z.jsx)(M,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,Z.jsx)(E,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:b(`space.resultsSearch`),"aria-label":b(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,Z.jsx)(h,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:b(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,Z.jsx)(h,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:b(`space.resultsAnyTime`)},{value:`1`,label:b(`space.resultsDay`)},{value:`7`,label:b(`space.resultsDays`,{n:7})},{value:`30`,label:b(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function Kt({data:e,wizardId:t,filter:n,onFilter:r}){let[i,a]=(0,X.useState)(null),o=t=>e.wizards.find(e=>e.id===t)?.title??``,s=new Intl.DateTimeFormat(x,{dateStyle:`medium`,timeStyle:`short`});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(I,{title:t?o(t):b(`space.resultsAll`),hint:b(`space.resultsHint`),plain:!0,children:[(0,Z.jsx)(Gt,{filter:n,onFilter:r}),e.runs.length?(0,Z.jsx)(S,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,Z.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,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?s.format(new Date(e.doneAt)):o(e.wizardId)}),(0,Z.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${s.format(new Date(e.doneAt))} · `,b(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:b(`space.resultFiles`,{n:e.assets}),children:[(0,Z.jsx)(l,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,Z.jsx)(T,{children:`Test`}):(0,Z.jsxs)(T,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,Z.jsx)(S,{children:(0,Z.jsx)(p,{children:n.q.trim()||n.mode||n.days?b(`space.resultsNone`):b(`space.resultsEmpty`)})})]}),i?(0,Z.jsx)(xe,{header:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:o(i.wizardId)}),i.mode===`test`?(0,Z.jsx)(T,{children:`Test`}):(0,Z.jsxs)(T,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>a(null),children:(0,Z.jsx)(k,{runId:i.id,compact:!0},i.id)}):null]})}function qt({project:e,save:t}){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(e.name),o=Ne({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(C,{label:b(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,Z.jsx)(ae,{className:`size-4`})}),(0,Z.jsx)(y,{open:n,onClose:()=>r(!1),title:b(`project.rename`),children:(0,Z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&o.mutate()},children:[(0,Z.jsx)(E,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),o.error?(0,Z.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null,(0,Z.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Z.jsx)(D,{variant:`ghost`,onClick:()=>r(!1),children:b(`common.cancel`)}),(0,Z.jsx)(D,{type:`submit`,busy:o.isPending,disabled:!i.trim(),children:b(`settings.save`)})]})]})})]})}function Jt({project:e}){let t=i();return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(oe,{}),e.readOnly?null:(0,Z.jsx)(qt,{project:e,save:async n=>{await O.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function Yt(e){let t=e.join(` `),[n,r]=(0,X.useState)(e[0]);return(0,X.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=window.scrollY>0&&window.innerHeight+window.scrollY>=document.documentElement.scrollHeight-4,i=Math.max(160,window.innerHeight/3),a=e[0];for(let t of e){let e=document.getElementById(t)?.getBoundingClientRect().top;e!==void 0&&e<=i&&(a=t)}r(t?e.at(-1):a)},a=()=>{n||=requestAnimationFrame(i)};return i(),window.addEventListener(`scroll`,a,{passive:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,a),window.removeEventListener(`resize`,a)}},[t]),n}function Xt(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function $({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,Z.jsx)(J,{icon:e.icon??q,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,Z.jsx)(Ke,{label:e.label,children:r},e.plugin):(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function Zt(){let{group:e}=ee(),[t,n]=ne(),r=a(),i=u(),{hash:o}=i,{project:s,loading:c}=ze(),l=Me(),d=Be(),m=$e(),[h,g]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),[x,te]=(0,X.useState)(null),S=Pe(e)?e:void 0,C=i.state?.parts===!0,w=Ve().map(e=>({...e,to:`/space/${e.id}`})),T=w.find(e=>e.id===S),E=t.get(`show`),D=S?E?2:1:0,O=m?Math.min(D,1):S&&x!==S&&!C?1:0,re=Ge(O),ie=Ge(D),ae=(0,X.useMemo)(()=>({slot:h,narrow:m,setDetail:y}),[h,m]),k=s?s.brand.name?.trim()||s.name:b(`nav.project`),oe=S&&S!==`results`?Re(S,d):[],A=S?Re(S,d).filter(e=>e.plugin):[],xe=Yt([...oe,...S===`results`?A:[]].flatMap(e=>e.sections.map(e=>e.id))),j=S===`results`&&E&&E!==`all`?E:null,[Se,Ce]=(0,X.useState)(Ut),M=Wt(S===`results`?s?.id:void 0,j,Se),we=M.data?.wizards.find(e=>e.id===j)?.title,N=S===`data`&&E&&E!==`all`||S===`knowledge`&&E&&/^[ptfcvs]:/.test(E)?E:null,P=N?.startsWith(`s:`)?d.spaceSections.find(e=>e.id===N.slice(2)):void 0,F=S===`knowledge`&&N&&/^[ptf]:/.test(N)?N:null,L=_e(S===`data`?s?.id:void 0),R=ue(S===`knowledge`?s?.id:void 0),B=de(N?.startsWith(`v:`)?N.slice(2):``),V=R.data?.categories.find(e=>e.id===(N?.startsWith(`c:`)?N.slice(2):B.data?.category.id)),De=S===`knowledge`?P?P.label():N?.startsWith(`v:`)?B.data&&`${B.data.category.name}: ${B.data.value}`:N?.startsWith(`c:`)?V?.name:R.data?.items.find(e=>e.key===N)?.title:L.data?se(L.data).flatMap(e=>e.items).find(e=>e.key===N)?.title:void 0;je([{label:k,to:`/space`},...T?[{label:T.label,to:`/space/${T.id}`}]:[],...T&&(v??we??De)?[{label:v??we??De}]:[]]);let H=S===`results`||S===`data`||N?o.slice(1):E||o.slice(1),U=(0,X.useRef)(``);if((0,X.useEffect)(()=>{let e=`${S}#${H}`;H&&U.current!==e&&document.getElementById(H)&&(U.current=e,requestAnimationFrame(()=>Xt(H,!1)))},[S,H,s?.id,d.spaceSections]),!S){let t=o.slice(1),n=t?Ie(t,d):null;if(n===`knowledge`&&d.spaceSections.some(e=>e.id===t))return(0,Z.jsx)(f,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,Z.jsx)(f,{to:m?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if(t&&d.status!==`ready`)return null;if(e!==void 0||!m)return(0,Z.jsx)(f,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(S===`knowledge`&&!E&&d.spaceSections.some(e=>e.id===o.slice(1)))return(0,Z.jsx)(f,{to:`/space/knowledge?show=s:${o.slice(1)}`,replace:!0});let W=e=>{if(m){r({search:`?show=${e}`});return}U.current=`${S}#${e}`,Xt(e,!0),r({search:``,hash:e},{replace:!0})},G=e=>m?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),K=e=>e.flatMap(e=>e.sections).map(e=>d.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,Z.jsx)(z,{id:e.id,children:(0,Z.jsx)(I,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,Z.jsx)(He,{of:e,children:(0,Z.jsx)(e.component,{})})})},e.serial)),q=m?void 0:xe;return(0,Z.jsx)(Ye.Provider,{value:ae,children:(0,Z.jsx)(`div`,{className:`animate-rise`,children:(0,Z.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,Z.jsxs)(`aside`,{className:_(`min-w-0 md:sticky md:top-20 md:self-start`,m&&D===2&&`hidden`,m&&ie===`back`&&We(`back`)),children:[(0,Z.jsx)(Je,{title:k,open:O===1?T??null:null,onBack:()=>m?r(`/space`):te(S??null)}),(0,Z.jsx)(`div`,{className:_(We(re)),children:O===0?(0,Z.jsx)(Ze,{entries:w,current:m?void 0:T,onPick:()=>te(null)}):(0,Z.jsx)(`div`,{ref:g})},O)]}),S?(0,Z.jsxs)(`div`,{className:_(`min-w-0`,m&&D<2&&`hidden`,m&&ie===`deeper`&&We(`deeper`)),children:[m?(0,Z.jsx)(`div`,{className:`mb-3`,children:(0,Z.jsx)(Qe,{label:T?.label??k,onBack:()=>r(`/space/${S}`)})}):null,l&&s?(0,Z.jsx)(`div`,{className:`mb-6`,children:(0,Z.jsx)(Jt,{project:s})}):null,S===`results`?(0,Z.jsxs)(Y,{children:[(0,Z.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,Z.jsx)(J,{icon:tt,label:b(`space.resultsAll`),selected:!m&&!j,onPick:()=>G(`all`)}),M.data?.wizards.filter(e=>e.results||e.id===j).map(e=>(0,Z.jsx)(J,{icon:Te,label:e.title,badge:e.results?(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!m&&e.id===j,onPick:()=>G(e.id)},e.id))]}),(0,Z.jsx)($,{groups:A,current:q,onPick:W})]}):S===`data`?(0,Z.jsxs)(Y,{children:[(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Z.jsx)(J,{icon:Ee,label:b(`data.all`),selected:!m&&!N,onPick:()=>G(`all`)})}),L.data?se(L.data).map(e=>(0,Z.jsx)(Ke,{label:e.label,children:e.items.map(e=>(0,Z.jsx)(J,{icon:ye[e.kind],label:e.title,selected:!m&&e.key===N,onPick:()=>G(e.key)},e.key))},e.key)):null,(0,Z.jsx)($,{groups:A,current:q,onPick:W})]}):S===`knowledge`?(0,Z.jsxs)(Y,{children:[(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,Z.jsx)(J,{icon:Ee,label:b(`know.all`),selected:!(m||N),onPick:()=>G(`all`)})}),R.data?.categories.length?(0,Z.jsx)(Ke,{label:b(`know.categories`),children:R.data.categories.map(e=>(0,Z.jsx)(J,{icon:ve[e.type],label:e.name,badge:(0,Z.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!m&&(N===`c:${e.id}`||B.data?.category.id===e.id),onPick:()=>G(`c:${e.id}`)},e.id))}):null,(0,Z.jsx)($,{groups:A,current:m?void 0:P?.id,onPick:e=>G(`s:${e}`)})]}):(0,Z.jsx)(Y,{children:(0,Z.jsx)($,{groups:oe,current:q,onPick:W})}),s&&(S===`info`||S===`knowledge`)?(0,Z.jsxs)(Ht,{project:s,group:S,docked:S===`knowledge`&&!!N&&!P,children:[S===`knowledge`?F?F.startsWith(`p:`)?(0,Z.jsx)(be,{pageId:F.slice(2),onGone:()=>G(`all`),onOpen:G},F):F.startsWith(`t:`)?(0,Z.jsx)(ge,{tableId:F.slice(2),onGone:()=>G(`all`)},F):(0,Z.jsx)(xt,{projectId:s.id,fileId:F.slice(2),readOnly:s.readOnly,onGone:()=>G(`all`)},F):R.data?P?(0,Z.jsx)(I,{title:P.label(),hint:P.hint?.(),plain:!0,children:(0,Z.jsx)(He,{of:P,children:(0,Z.jsx)(P.component,{})})},N):N?.startsWith(`c:`)?V?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Z.jsx)(he,{projectId:s.id,category:V,readOnly:s.readOnly,onOpen:G,onGone:()=>G(`all`)}),V.type===`choice`?null:(0,Z.jsx)(ce,{projectId:s.id,category:V,categories:R.data.categories,onOpen:G})]},N):null:N?.startsWith(`v:`)?B.data?(0,Z.jsx)(fe,{value:B.data,readOnly:s.readOnly,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[B.data.items.length?(0,Z.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:B.data.items.map(e=>(0,Z.jsx)(me,{item:e,categories:R.data.categories.filter(e=>e.id!==B.data?.category.id),onOpen:G},e.key))}):null,B.data.rows.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>G(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:b(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},N):null:(0,Z.jsx)(z,{id:`documents`,children:(0,Z.jsx)(le,{projectId:s.id,data:R.data,readOnly:s.readOnly,onOpen:G})}):null:null,S===`info`?K(A):null]},s.id):null,s&&S===`data`?(0,Z.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:N?.startsWith(`t:`)?(0,Z.jsx)(ge,{tableId:N.slice(2),onGone:()=>G(`all`)},N):N?.startsWith(`p:`)?(0,Z.jsx)(be,{pageId:N.slice(2),onGone:()=>G(`all`)},N):(0,Z.jsxs)(Z.Fragment,{children:[L.data?(0,Z.jsx)(pe,{projectId:s.id,data:L.data,readOnly:s.readOnly,onOpen:G}):null,K(A)]})}):null,s&&S===`results`?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[M.data?(0,Z.jsx)(Kt,{data:M.data,wizardId:j,filter:Se,onFilter:Ce}):null,M.isError?(0,Z.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:M.error.message}):null,K(A)]}):null,s||c?null:(0,Z.jsx)(p,{children:b(`settings.noProject`)})]}):null]})})})}export{Zt as ProjectPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{D as r,_ as i,h as a,v as o,x as s}from"./surface-D7bnQtqR.js";import{$ as c,D as l,G as u,S as d,et as f,f as p,g as m,j as h,t as g,w as _,x as v}from"./ui-BZ01zr3i.js";import{t as y}from"./RunnerView-JOMD-e27.js";import{t as b}from"./arrow-right-hy38IBRU.js";import{A as x,E as S,k as C}from"./index-knnf98Fv.js";var w={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`}]]};w.node;var T=u(w),E={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`}]]};E.node;var D=u(E),O={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`]};O.node;var k=u(O),A=e(t(),1);function j(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`?e:null}var M=j(),N=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`);function P(){(0,A.useEffect)(()=>{if(M===`inline`){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>N(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(M===`modal`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&N(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[])}var F=e(n(),1);function I(e){(0,A.useEffect)(()=>{if(!e)return;let t=document.documentElement;return t.style.setProperty(`--raw-primary`,e),()=>{t.style.removeProperty(`--raw-primary`)}},[e])}function L(e,t){(0,A.useEffect)(()=>{if(!e||!t)return;let n=l(`/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 R=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,z=R||/Android/.test(navigator.userAgent);function B(){let[e,t]=(0,A.useState)(()=>window.wizardInstall??null),[n,r]=(0,A.useState)(!1);if((0,A.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||z&&!e&&!R)return null;let i=/Mac/.test(navigator.platform),a=h(z?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,F.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,F.jsxs)(`button`,{type:`button`,onClick:()=>{z&&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:[z?(0,F.jsx)(k,{className:`size-4`}):(0,F.jsx)(T,{className:`size-4`}),h(z?`install.add`:`install.bookmark`)]}),n?(0,F.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function V({brand:e,toggle:t=!0}){return(0,F.jsx)(`header`,{className:`safe-top`,children:(0,F.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[e.logoUrl?(0,F.jsx)(`img`,{src:l(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,F.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,F.jsx)(`div`,{className:`absolute right-3`,children:(0,F.jsx)(o,{})}):null]})})}function H({siteKey:e,onToken:t}){let n=(0,A.useRef)(null);return(0,A.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,F.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function U({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||S||M?null:(0,F.jsxs)(`a`,{href:C(`${window.location.origin}${_}/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,F.jsx)(D,{className:`size-4`}),` `,h(`install.app`)]})}var W=e=>`wz.run.${e}`,G=S&&new URLSearchParams(window.location.search).get(`start`)===`1`,K=M===`inline`?`min-h-80`:`min-h-dvh`;function q({wizard:e}){let t=c(),[n,r]=(0,A.useState)(!1),[a,o]=(0,A.useState)(null),[s,l]=(0,A.useState)(null),u=(()=>{try{return localStorage.getItem(W(e.token))}catch{return null}})(),d=async()=>{r(!0),o(null);try{let{runId:n}=await v.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:s??void 0,embedded:M!==null});try{localStorage.setItem(W(e.token),n)}catch{}t(`/w/${e.token}/${n}`,{replace:G})}catch(e){o(e.message),r(!1)}},f=G&&e.available&&!e.turnstileSiteKey,m=(0,A.useRef)(!1);return(0,A.useEffect)(()=>{f&&!m.current&&(m.current=!0,d())},[f]),f&&!a?(0,F.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,F.jsx)(p,{})}):(0,F.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,F.jsx)(i,{kind:e.avatar,size:190,fluffy:!0}),(0,F.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,F.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,e.available?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(g,{size:`lg`,className:`mt-10 min-w-48`,busy:n,disabled:!!e.turnstileSiteKey&&!s,onClick:d,children:[h(`run.start`),` `,(0,F.jsx)(b,{className:`size-4`})]}),e.turnstileSiteKey?(0,F.jsx)(H,{siteKey:e.turnstileSiteKey,onToken:l}):null,u?(0,F.jsx)(`button`,{type:`button`,onClick:()=>t(`/w/${e.token}/${u}`),className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:h(`run.resume`)}):null,M||S?null:(0,F.jsx)(B,{}),(0,F.jsx)(U,{token:e.token})]}):(0,F.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??h(`run.unavailable`)}),a?(0,F.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:a}):null]})}function J(){let{token:e,runId:t}=f(),n=c(),o=r({queryKey:[`public`,e],queryFn:()=>v.get(`/api/public/wizards/${e}`),retry:(e,t)=>d(t)&&e<3});if(I(o.data?.brand.accent),s(o.data?.avatar),L(e,o.data?.title),P(),(0,A.useEffect)(()=>{o.data&&(document.title=o.data.title)},[o.data]),(0,A.useEffect)(()=>{e&&t&&x(`run`,{token:e,runId:t})},[e,t]),o.isLoading)return(0,F.jsx)(`div`,{className:m(`flex items-center justify-center text-ink-4`,K),children:(0,F.jsx)(p,{})});if(!o.data){let e=d(o.error);return(0,F.jsxs)(`div`,{className:m(`flex flex-col items-center justify-center gap-4 px-6 text-center`,K),children:[(0,F.jsx)(i,{kind:`pebble`,size:80}),(0,F.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:h(e?`common.offline`:`run.notFound`)}),e?(0,F.jsx)(g,{variant:`secondary`,onClick:()=>void o.refetch(),children:h(`common.retry`)}):null]})}return(0,F.jsxs)(`div`,{className:m(`flex flex-col`,K),children:[M===`inline`||S?null:(0,F.jsx)(V,{brand:o.data.brand,toggle:!M}),(0,F.jsx)(`div`,{className:`flex-1`,children:t?(0,F.jsx)(y,{runId:t,onRestart:()=>n(`/w/${e}`)}):(0,F.jsx)(q,{wizard:o.data})}),S?(0,F.jsx)(`div`,{className:`safe-bottom`}):(0,F.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,F.jsx)(`a`,{href:`${_}/`,target:M?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:h(`run.madeWith`).replace(`engenty wizards`,a.name)})})]})}export{V as BrandHeader,J as PublicRunner,I as useBrandAccent};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{
|
|
2
|
-
`).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await a.invalidateQueries({queryKey:q(e)}),s(``),C(``),D(``),i(t)}});return(0,G.jsx)(v,{open:t,onClose:n,title:y(`know.newCategory`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&k.mutate()},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`know.name`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:o,maxLength:80,onChange:e=>s(e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`know.type`)}),(0,G.jsx)(m,{value:c,onChange:e=>l(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:y(`know.type.${e}`)}))})]}),c===`number`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{hint:y(`know.unitHint`),children:y(`know.unit`)}),(0,G.jsx)(T,{value:u,maxLength:20,onChange:e=>d(e.target.value)})]}):null,c===`choice`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{hint:y(`know.valuesHint`),children:y(`know.values`)}),(0,G.jsx)(_,{minRows:3,value:S,onChange:e=>C(e.target.value)})]}),(0,G.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[y(`know.multiple`),(0,G.jsx)(x,{checked:f,onChange:h})]}),(0,G.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[y(`know.ordered`),(0,G.jsx)(x,{checked:g,onChange:b})]})]}):null,(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{hint:y(`know.hintFieldHint`),children:y(`know.hintField`)}),(0,G.jsx)(T,{value:w,maxLength:120,onChange:e=>D(e.target.value)})]}),k.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:k.error.message}):null,(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(E,{variant:`ghost`,onClick:n,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:k.isPending,disabled:!o.trim(),children:y(`know.create`)})]})]})})}function Se({projectId:e,category:t,readOnly:n,onOpen:i,onGone:o}){let s=r(),c=()=>s.invalidateQueries({queryKey:q(e)}),[l,u]=(0,W.useState)(``),f=L({mutationFn:e=>e(),onSuccess:c}),p=K[t.type],m=new Map(t.values.map(e=>[e.id,e]));return(0,G.jsxs)(N,{title:t.name,hint:[y(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,G.jsx)(C,{label:y(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(y(`know.confirmCategory`,{name:t.name}))&&f.mutate(async()=>{await O.del(`/api/studio/categories/${t.id}`),o()}),children:(0,G.jsx)(F,{className:`size-4`})}),children:[t.proposed&&!n?(0,G.jsxs)(S,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,G.jsx)(w,{tone:`ember`,children:y(`know.proposed`)}),(0,G.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:y(`know.proposedHint`)}),(0,G.jsx)(E,{size:`sm`,onClick:()=>f.mutate(()=>O.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:y(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=m.get(e),i=m.get(t);if(!(r&&i))return null;let[a,o]=r.count<i.count?[r,i]:[i,r];return(0,G.jsxs)(S,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,G.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:y(`know.alike`,{a:a.value,b:o.value})}),n?null:(0,G.jsx)(E,{size:`sm`,variant:`secondary`,busy:f.isPending,onClick:()=>f.mutate(()=>O.post(`/api/studio/values/${a.id}/merge`,{into:o.id})),children:y(`know.merge`)})]},`${e}:${t}`)}),(0,G.jsxs)(S,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,G.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,G.jsx)(p,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,G.jsx)(w,{children:y(`know.summary`)}):null,(0,G.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:he(e.count)})]},e.id)):(0,G.jsx)(d,{children:y(`know.empty`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,G.jsx)(p,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?y(`know.range`,{min:J(t,t.range.min),max:J(t,t.range.max)}):y(`know.unset`)}),(0,G.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:he(t.count)})]}),t.type===`choice`&&!n?(0,G.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=l.trim();n&&(u(``),f.mutate(()=>O.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,G.jsx)(T,{value:l,placeholder:y(`know.addValue`),onChange:e=>u(e.target.value),className:`h-9`}),(0,G.jsx)(C,{label:y(`know.addValue`),type:`submit`,children:(0,G.jsx)(a,{className:`size-4`})})]}):null]}),f.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error.message}):null]})}function Ce(e){return i({queryKey:[`knowledge-value`,e],queryFn:()=>O.get(`/api/studio/values/${e}`),enabled:!!e})}function we({value:e,readOnly:t,children:n}){let i=r(),a=L({mutationFn:()=>O.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>i.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,G.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,G.jsx)(N,{title:y(`know.summary`),hint:y(`know.summaryHint`),plain:!0,action:t?null:(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,busy:a.isPending,onClick:()=>a.mutate(),children:[e.summary?(0,G.jsx)(re,{className:`size-4`}):null,e.summary?y(`know.summaryAgain`):y(`know.summaryWrite`)]}),children:(0,G.jsxs)(S,{className:`p-4 sm:p-5`,children:[a.isPending?(0,G.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,G.jsx)(h,{})}):e.summary?(0,G.jsx)(ae,{text:e.summary,className:`text-[0.875rem]`}):(0,G.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:y(`know.summaryEmpty`)}),a.error?(0,G.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error.message}):null]})}),(0,G.jsx)(N,{title:y(`know.toc`),plain:!0,children:n})]})}function Te(e){return i({queryKey:[`knowledge`,e],queryFn:()=>O.get(`/api/studio/projects/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function Ee(e){return e.kind===`table`?e.format===`faq`?de:j:e.kind===`file`?c:e.children?ue:I}function Y({item:e,categories:t,onOpen:n}){let r=Ee(e),i=[ge(t,e.categories),e.children?e.children===1?y(`know.oneSub`):y(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?y(`know.row`):y(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,G.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,G.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,G.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,G.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,G.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,G.jsx)(h,{className:`size-3`}),` `,y(`know.reading`)]}):e.review?(0,G.jsx)(w,{tone:`warn`,title:e.review,children:y(`know.review`)}):null]})}function X({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:a,file:o,readOnly:s,onReviewed:l}){let u=Te(e),d=[r?y(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[u.data?(0,G.jsx)(ye,{projectId:e,itemKey:t,has:n,categories:u.data.categories,readOnly:s}):null,d.length||o||a?(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.8125rem] text-ink-3`,children:[d.map(e=>(0,G.jsx)(`span`,{children:e},e)),o?(0,G.jsxs)(`a`,{href:P(e,o.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,G.jsx)(c,{className:`size-3.5`}),` `,y(`know.original`),`: `,o.name]}):null,a?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(w,{tone:`warn`,children:y(`know.review`)}),(0,G.jsx)(`span`,{children:a}),s?null:(0,G.jsx)(`button`,{type:`button`,onClick:l,className:`underline hover:text-ink`,children:y(`know.reviewed`)})]}):null]}):null]})}function De(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 Oe({projectId:e,category:t,categories:n,onOpen:r}){let a=i({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>O.get(`/api/studio/categories/${t.id}/items`)});if(!a.data)return a.isLoading?(0,G.jsx)(h,{className:`mx-auto size-4 text-ink-3`}):null;let o=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],s=[...a.data.items].sort((e,t)=>{let n=o(e),r=o(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),b)}),c=t.type===`number`?De(s.map(o).filter(e=>typeof e==`number`)):[],l=new Intl.NumberFormat(b,{notation:`compact`,maximumFractionDigits:1}),u=t.unit?` ${t.unit}`:``,d=new Map;for(let e of s){let n=o(e),r=typeof n==`number`?c.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(b,{month:`long`,year:`numeric`}):r?y(`know.range`,{min:`${l.format(r.lo)}${u}`,max:`${l.format(r.hi)}${u}`}):J(t,n);d.set(i,[...d.get(i)??[],e])}return(0,G.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...d].map(([e,t])=>(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,G.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,G.jsx)(Y,{item:e,categories:n,onOpen:r},e.key))})]},e)),a.data.rows.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:y(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function ke(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 Ae(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return y(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${y(`know.contains`)} ${t.contains}`:[n===void 0?``:`${y(`know.minimum`)} ${J(e,n)}`,r===void 0?``:`${y(`know.maximum`)} ${J(e,r)}`].filter(Boolean).join(` `)}return String(t)}function je({category:e,value:t,onChange:n}){let[r,i]=(0,W.useState)(!1),a=(0,W.useRef)(null);(0,W.useEffect)(()=>{if(!r)return;let e=e=>!a.current?.contains(e.target)&&i(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]);let o=K[e.type],s=typeof t==`object`&&t&&!Array.isArray(t)?t:{},c=(t,r)=>{let i={...s,[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,G.jsxs)(`div`,{ref:a,className:`relative`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:g(`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,G.jsx)(o,{className:`size-3.5 text-ink-3`}),e.name,t===void 0?null:(0,G.jsxs)(`span`,{className:`font-medium`,children:[`: `,Ae(e,t)]}),(0,G.jsx)(u,{className:`size-3.5 text-ink-3`})]}),r?(0,G.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,G.jsx)(D,{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,G.jsx)(D,{value:t===!0?y(`know.yes`):t===!1?y(`know.no`):``,options:[y(`know.yes`),y(`know.no`)],onChange:e=>n(e===y(`know.yes`))}):e.type===`text`?(0,G.jsx)(T,{"data-autofocus":!0,value:s.contains??``,placeholder:y(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:`h-9`}):(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(n===0?`know.minimum`:`know.maximum`)}),(0,G.jsx)(T,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(s[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>c(t,e.target.value),className:`h-9`})]},t))}),t===void 0?null:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),i(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:y(`know.clear`)})]}):null]})}function Me({found:e,onOpen:t}){return e.hits.length?(0,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:e.checked?y(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):y(`know.searchUnchecked`,{hits:e.hits.length})}),e.hits.map(e=>{let n=e.open;return(0,G.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,G.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,G.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,G.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,G.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(b,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,G.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:y(`know.searchNone`)})}function Ne({kind:e,projectId:t,onClose:n,onMade:i}){let a=r(),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),u=L({mutationFn:()=>O.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:o.trim(),...e===`table`&&c?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await a.invalidateQueries({queryKey:[`knowledge`,t]}),i(`${e===`table`?`t`:`p`}:${n}`),s(``),l(!1)}});return(0,G.jsx)(v,{open:e!==null,onClose:n,title:y(e===`table`?`know.newTable`:`know.newPage`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&u.mutate()},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.title`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:o,maxLength:120,onChange:e=>s(e.target.value)})]}),e===`table`?(0,G.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[y(`know.asFaq`),(0,G.jsx)(x,{checked:c,onChange:l})]}):null,u.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u.error.message}):null,(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(E,{variant:`ghost`,onClick:n,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:u.isPending,disabled:!o.trim(),children:y(`know.create`)})]})]})})}function Pe({projectId:e,data:t,readOnly:n,onOpen:i}){let o=r(),s=te(e,n),[c,l]=(0,W.useState)({}),[u,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,b]=(0,W.useState)(null),x=t.categories.filter(e=>!e.proposed&&e.count>0),C=t.categories.filter(e=>e.proposed),T=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?ke(i,a.values,r):!1})),D=async()=>{if(!u.trim()){m(null);return}_(!0);try{m(await O.post(`/api/studio/projects/${e}/search`,{query:u,...Object.keys(c).length?{where:c}:{}}))}catch{m({hits:[],candidates:0,checked:!1,filtered:null})}finally{_(!1)}},k=L({mutationFn:({id:e,keep:t})=>t?O.patch(`/api/studio/categories/${e}`,{proposed:!1}):O.del(`/api/studio/categories/${e}`),onSuccess:()=>o.invalidateQueries({queryKey:[`knowledge`,e]})});return(0,G.jsxs)(N,{title:y(`know.title`),hint:y(`know.hint`),plain:!0,action:n?null:(0,G.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>b(`page`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.page`)]}),(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>b(`table`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.table`)]}),(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>b(`category`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.category`)]})]}),children:[C.length&&!n?(0,G.jsx)(S,{className:`flex flex-col gap-2 p-4`,children:C.map(e=>{let t=K[e.type];return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,G.jsx)(w,{tone:`ember`,children:y(`know.proposed`)}),(0,G.jsx)(t,{className:`size-4 text-ink-3`}),(0,G.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[y(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,G.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>k.mutate({id:e.id,keep:!1}),children:y(`know.dismiss`)}),(0,G.jsx)(E,{size:`sm`,onClick:()=>k.mutate({id:e.id,keep:!0}),children:y(`know.accept`)})]},e.id)})}):null,t.items.length?(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(ne,{value:u,placeholder:y(`know.search`),busy:g,onEnter:()=>void D(),onChange:e=>{f(e),e.trim()||m(null)}}),x.length?(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[x.map(e=>(0,G.jsx)(je,{category:e,value:c[e.name],onChange:t=>{m(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,G.jsx)(`button`,{type:`button`,onClick:()=>l({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:y(`know.clear`)}):null]}):null]}):null,(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:p?(0,G.jsx)(Me,{found:p,onOpen:i}):T.length?T.map(e=>(0,G.jsx)(Y,{item:e,categories:t.categories,onOpen:i},e.key)):(0,G.jsx)(d,{children:y(`know.empty`)})}),n?null:(0,G.jsxs)(M,{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,G.jsx)(h,{className:`size-4`}):(0,G.jsx)(A,{className:`size-4`}),y(`know.drop`),` `,(0,G.jsx)(`span`,{className:`underline`,children:y(`know.pick`)})]}),s.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,G.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:y(`know.keywordsOnly`),t.checked?``:y(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,G.jsx)(Ne,{kind:v===`page`||v===`table`?v:null,projectId:e,onClose:()=>b(null),onMade:e=>{b(null),i(e)}}),(0,G.jsx)(xe,{projectId:e,open:v===`category`,onClose:()=>b(null),onMade:e=>{b(null),i(`c:${e}`)}})]})}function Fe({page:e,onGone:t,onOpen:n}){let i=r(),[o,c]=(0,W.useState)(e.title),[l,u]=(0,W.useState)(e.markdown),[d,f]=(0,W.useState)(e.markdown?`read`:`write`),p=e.knowledge,m=async()=>{await i.invalidateQueries({queryKey:[`space-data`,e.projectId]}),await i.invalidateQueries({queryKey:[`knowledge`,e.projectId]})},_=ee({title:o.trim()||e.title,markdown:l},async t=>{await O.patch(`/api/studio/pages/${e.id}`,t),i.setQueryData([`space-page`,e.id],e=>e&&{...e,...t}),t.title!==e.title&&await m()}),v=L({mutationFn:()=>O.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await m(),t()}}),b=L({mutationFn:()=>O.post(`/api/studio/projects/${e.projectId}/pages`,{title:y(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await m(),n?.(`p:${e}`)}}),x=L({mutationFn:()=>O.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>i.invalidateQueries({queryKey:[`space-page`,e.id]})}),w=async t=>{let r=t.target.closest(`a`)?.getAttribute(`href`);if(!(r?.startsWith(`pages/`)&&n))return;t.preventDefault();let i=await O.get(`/api/studio/projects/${e.projectId}/resolve?path=${encodeURIComponent(r)}`).catch(()=>null);i?.kind===`page`&&n(`p:${i.id}`)},T=e.readOnly,D=p?.file&&(p.file.mime===`application/pdf`||p.file.mime.startsWith(`image/`))?p.file:null,A=(e,t)=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":d===e,onClick:()=>f(e),className:g(`rounded-full px-3 py-1 text-[0.8125rem] transition`,d===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,G.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[p?.parents.length&&n?(0,G.jsx)(`nav`,{className:`-mb-1.5 flex flex-wrap items-center gap-1 px-1 text-[0.8125rem] text-ink-3`,children:p.parents.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`hover:text-ink`,children:e.title}),(0,G.jsx)(k,{className:`size-3.5`})]},e.id))}):null,(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,G.jsx)(`input`,{value:o,disabled:T,maxLength:200,onChange:e=>c(e.target.value),"aria-label":y(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),_.state===`saving`?(0,G.jsx)(h,{className:`size-3.5 text-ink-3`}):_.state===`saved`?(0,G.jsx)(s,{className:`size-4 text-moss`,"aria-label":y(`settings.saved`)}):null,T?null:(0,G.jsx)(C,{label:y(`data.deletePage`),onClick:()=>confirm(y(`data.confirmDelete`,{title:e.title}))&&v.mutate(),className:`hover:text-rose`,children:(0,G.jsx)(F,{className:`size-4`})})]}),p?(0,G.jsx)(X,{projectId:e.projectId,itemKey:`p:${e.id}`,has:p.categories,originLabel:p.originLabel,kept:p.kept,review:p.review,file:D?null:p.file,readOnly:T,onReviewed:()=>x.mutate()}):null,(0,G.jsxs)(S,{className:`flex flex-col`,children:[T&&!D?null:(0,G.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[T?null:A(`write`,y(`data.write`)),A(`read`,y(`data.preview`)),D?A(`original`,y(`know.original`)):null,(0,G.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:d===`original`&&D?D.name:y(`data.markdownHint`)})]}),d===`original`&&D?D.mime===`application/pdf`?(0,G.jsx)(`iframe`,{src:P(e.projectId,D.id),title:D.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,G.jsx)(`img`,{src:P(e.projectId,D.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):d===`write`&&!T?(0,G.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),"aria-label":e.title,placeholder:y(`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,G.jsx)(`div`,{className:`min-h-40 p-4 sm:p-5`,onClick:w,children:l.trim()?(0,G.jsx)(ae,{text:l}):(0,G.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:y(`data.pageEmpty`)})})]}),_.state===`error`&&_.error?(0,G.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:_.error}):null,p&&n&&(p.children.length||!T)?(0,G.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,G.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:p.children.length?y(`know.subPages`):null}),T?null:(0,G.jsxs)(E,{variant:`ghost`,size:`sm`,busy:b.isPending,onClick:()=>b.mutate(),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.addSub`)]})]}),p.children.length?(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:p.children.map(e=>(0,G.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,G.jsx)(I,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title})]},e.id))}):null]}):null]})}function Ie({pageId:e,onGone:t,onOpen:n}){let r=i({queryKey:[`space-page`,e],queryFn:()=>O.get(`/api/studio/pages/${e}`),refetchOnWindowFocus:!1});return r.data?(0,G.jsx)(Fe,{page:r.data,onGone:t,onOpen:n},r.data.id):r.isError?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:r.error.message}):null}function Le(e){return i({queryKey:[`space-data`,e],queryFn:()=>O.get(`/api/studio/projects/${e}/data`),enabled:!!e})}function Re(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:y(`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 ze={table:j,page:I};function Be({kind:e,projectId:t,data:n,onClose:i,onMade:a}){let o=r(),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``),d=L({mutationFn:()=>O.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:s.trim(),wizardId:l||null}),onSuccess:async({id:n})=>{await o.invalidateQueries({queryKey:[`space-data`,t]}),a(`${e===`table`?`t`:`p`}:${n}`),c(``),u(``)}});return(0,G.jsx)(v,{open:e!==null,onClose:i,title:y(e===`table`?`data.newTable`:`data.newPage`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),s.trim()&&d.mutate()},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.title`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:s,maxLength:120,onChange:e=>c(e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.owner`)}),(0,G.jsx)(m,{value:l,onChange:u,options:[{value:``,label:y(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),d.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null,(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(E,{variant:`ghost`,onClick:i,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:d.isPending,disabled:!s.trim(),children:y(`data.create`)})]})]})})}function Ve({projectId:e,data:t,readOnly:n,onOpen:r}){let[i,o]=(0,W.useState)(null),s=Re(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(b,{dateStyle:`medium`});return(0,G.jsxs)(N,{title:y(`space.data`),hint:y(`data.hint`),plain:!0,action:n?null:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>o(`table`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`data.table`)]}),(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>o(`page`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`data.page`)]})]}),children:[s.length?(0,G.jsx)(`div`,{className:`flex flex-col gap-5`,children:s.map(e=>(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e.label}),(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:e.items.map(e=>{let t=ze[e.kind];return(0,G.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,G.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,G.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:[e.kind===`table`?`${y(`data.rows`,{n:e.rows??0})} · `:``,l.format(new Date(c.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,G.jsx)(S,{children:(0,G.jsx)(d,{children:y(`data.empty`)})}),(0,G.jsx)(Be,{kind:i,projectId:e,data:t,onClose:()=>o(null),onMade:e=>{o(null),r(e)}})]})}function He(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 Ue={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},We=[`text`,`number`,`date`,`duration`,`select`,`boolean`];function Ge(e,t){if(t==null)return``;if(e.type===`duration`&&typeof t==`number`)return String(t/Ue[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 Ke(e,t){return t.trim()===``?null:e.type===`date`&&e.format.kind===`datetime`?new Date(t).toISOString():t}var Z=`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 qe({column:e,value:t,readOnly:n,invalid:r,onSave:i}){let a=Ge(e,t),[o,s]=(0,W.useState)(a);(0,W.useEffect)(()=>s(a),[a]);let c=(t=o)=>{t!==a&&i(Ke(e,t))};if(e.type===`boolean`)return(0,G.jsx)(`div`,{className:`px-2 py-1.5`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:t===!0,disabled:n,onChange:e=>i(e.target.checked),"aria-label":e.name,className:`size-4 accent-[var(--ember)]`})});if(e.type===`select`&&e.format.multiple){let r=Array.isArray(t)?t:[],a=t=>e.format.options.find(e=>e.id===t)?.label??t;return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-2 py-1`,children:[r.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-paper-2 py-0.5 pr-1 pl-2 text-[0.75rem]`,children:[a(e),n?null:(0,G.jsx)(`button`,{type:`button`,"aria-label":y(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,G.jsx)(l,{className:`size-3`})})]},e)),n?null:(0,G.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,G.jsx)(`option`,{value:``,children:`+`}),e.format.options.filter(e=>!r.includes(e.id)).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})}if(e.type===`select`)return(0,G.jsxs)(`select`,{value:typeof t==`string`?t:``,disabled:n,onChange:e=>i(e.target.value||null),"aria-label":e.name,className:Z,children:[(0,G.jsx)(`option`,{value:``}),e.format.options.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]});if(e.type===`text`&&e.format?.style&&e.format.style!==`single`)return(0,G.jsx)(`textarea`,{value:o,rows:1,disabled:n,onChange:e=>s(e.target.value),onBlur:()=>c(),"aria-label":e.name,className:g(Z,`field-sizing-content max-h-40 resize-none`)});let u=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,G.jsx)(`input`,{type:u,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:o,disabled:n,onChange:t=>{s(t.target.value),e.type===`date`&&c(t.target.value)},onBlur:()=>e.type!==`date`&&c(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&s(a)},"aria-label":e.name,className:g(Z,(e.type===`number`||e.type===`duration`)&&`text-right tabular-nums`,r&&`ring-1 ring-rose`)})}function Je(e){return e.type===`number`&&e.format.style===`currency`?e.format.currency??null:e.type===`number`&&e.format.style===`percent`?`%`:e.type===`duration`?y(`data.unit.${e.format.inputUnit}`):null}function Ye(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(`
|
|
1
|
+
import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{D as r,Q as i}from"./surface-D7bnQtqR.js";import{F as a,G as o,H as s,I as c,N as l,V as u,a as d,b as f,c as p,d as m,f as h,g,h as _,i as v,j as y,k as b,m as x,n as S,o as C,r as w,s as T,t as E,u as D,x as O,z as k}from"./ui-BZ01zr3i.js";import{t as A}from"./upload-U0i8fAW3.js";import{n as j}from"./wand-sparkles-MelvBtiK.js";import{a as M,c as N,d as ee,f as te,s as ne,u as P}from"./Account-BaOouMw9.js";import{t as F}from"./trash-3S1_XpVa.js";import{t as re}from"./refresh-cw-B9M1g3SH.js";import{_t as I,ct as L,it as ie,m as ae,tt as oe}from"./index-knnf98Fv.js";import"./definition-CwX2olVF.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=o(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=o(le),R={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`}]]};R.node;var z=o(R),B={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};B.node;var de=o(B),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 fe=o(V),H={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`}]]};H.node;var pe=o(H),U={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`}]]};U.node;var me=o(U),W=e(t(),1),G=e(n(),1),K={choice:pe,date:ce,number:z,text:oe,boolean:me},q=e=>[`knowledge`,e];function he(e){return e===1?y(`know.item`):y(`know.items`,{n:e})}function J(e,t){if(e.type===`boolean`||typeof t==`boolean`)return y(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(b,{day:`2-digit`,month:`2-digit`,year:`numeric`});return n?`${i} ${n}`:i}return e.type===`number`&&typeof t==`number`?`${t.toLocaleString(b)}${e.unit?` ${e.unit}`:``}`:String(t)}function ge(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=>J(e,t)).join(`, `)]:[]}).join(` · `)}function _e({trigger:e,open:t,onOpen:n,children:r}){let i=(0,W.useRef)(null);return(0,W.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,G.jsxs)(`div`,{ref:i,className:`relative inline-flex`,children:[e,t?(0,G.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 ve({category:e,current:t,onSave:n}){let[r,i]=(0,W.useState)(t[0]===void 0?``:String(t[0]));if(e.type===`choice`){let o=t.map(String);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[e.values.length?(0,G.jsx)(D,{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,G.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),r.trim()&&n(e.multiple?[...o,r.trim()]:[r.trim()])},children:[(0,G.jsx)(T,{"data-autofocus":!0,value:o.includes(r)?``:r,placeholder:y(`know.addValue`),onChange:e=>i(e.target.value),className:`h-9`}),(0,G.jsx)(C,{label:y(`know.addValue`),type:`submit`,children:(0,G.jsx)(a,{className:`size-4`})})]})]})}return e.type===`boolean`?(0,G.jsx)(D,{value:t[0]===!0?y(`know.yes`):t[0]===!1?y(`know.no`):``,options:[y(`know.yes`),y(`know.no`)],onChange:e=>n([e===y(`know.yes`)])}):(0,G.jsxs)(`form`,{className:`flex gap-2`,onSubmit:t=>{t.preventDefault(),n(r.trim()?[e.type===`number`?Number(r.replace(`,`,`.`)):r.trim()]:[])},children:[(0,G.jsx)(T,{"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,G.jsx)(E,{type:`submit`,size:`sm`,children:`OK`})]})}function ye({projectId:e,itemKey:t,has:n,categories:r,readOnly:o}){let s=i(),[c,u]=(0,W.useState)(null),[d,f]=(0,W.useState)(n);(0,W.useEffect)(()=>f(n),[n]);let p=I({mutationFn:({categoryId:n,next:r})=>O.put(`/api/studio/projects/${e}/items/${t}/categories/${n}`,{values:r}),onSuccess:()=>s.invalidateQueries({queryKey:q(e)})}),m=r.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}),u(null)},g=m.filter(e=>d.some(t=>t.categoryId===e.id)),_=m.filter(e=>!d.some(t=>t.categoryId===e.id));return m.length?(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[g.map(e=>{let t=d.find(t=>t.categoryId===e.id),n=K[e.type],r=(0,G.jsxs)(`button`,{type:`button`,disabled:o,title:`${e.name} · ${y(`know.by.${t.by}`)}`,onClick:()=>u(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,G.jsx)(n,{className:`size-3.5 text-ink-3`}),(0,G.jsx)(`span`,{className:`text-ink-3`,children:e.name}),(0,G.jsx)(`span`,{className:`font-medium`,children:t.values.map(t=>J(e,t)).join(`, `)})]},e.id);return o?(0,G.jsx)(`span`,{children:r},e.id):(0,G.jsxs)(_e,{trigger:r,open:c===e.id,onOpen:t=>u(t?e.id:null),children:[(0,G.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:e.name}),(0,G.jsx)(C,{label:y(`know.remove`),onClick:()=>h(e,[]),className:`size-7`,children:(0,G.jsx)(l,{className:`size-3.5`})})]}),(0,G.jsx)(ve,{category:e,current:t.values,onSave:t=>h(e,t)})]},e.id)}),o||!_.length?null:(0,G.jsx)(_e,{open:c===`+`,onOpen:e=>u(e?`+`:null),trigger:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>u(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,G.jsx)(a,{className:`size-3.5`}),` `,y(`know.category`)]}),children:(0,G.jsx)(be,{categories:_,onSave:h})})]}):null}function be({categories:e,onSave:t}){let[n,r]=(0,W.useState)(e[0]?.id??``),i=e.find(e=>e.id===n);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,G.jsx)(m,{value:n,onChange:r,options:e.map(e=>({value:e.id,label:e.name}))}),i?(0,G.jsx)(ve,{category:i,current:[],onSave:e=>t(i,e)},i.id):null]})}function xe({projectId:e,open:t,onClose:n,onMade:r}){let a=i(),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(`choice`),[u,d]=(0,W.useState)(``),[f,h]=(0,W.useState)(!1),[g,b]=(0,W.useState)(!1),[S,C]=(0,W.useState)(``),[w,D]=(0,W.useState)(``),k=I({mutationFn:()=>O.post(`/api/studio/projects/${e}/categories`,{name:o.trim(),type:c,unit:c===`number`&&u.trim()||null,multiple:c===`choice`&&f,ordered:c===`choice`&&g,hint:w.trim()||null,values:c===`choice`?S.split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(Boolean):void 0}),onSuccess:async({id:t})=>{await a.invalidateQueries({queryKey:q(e)}),s(``),C(``),D(``),r(t)}});return(0,G.jsx)(v,{open:t,onClose:n,title:y(`know.newCategory`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&k.mutate()},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`know.name`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:o,maxLength:80,onChange:e=>s(e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`know.type`)}),(0,G.jsx)(m,{value:c,onChange:e=>l(e),options:[`choice`,`date`,`number`,`text`,`boolean`].map(e=>({value:e,label:y(`know.type.${e}`)}))})]}),c===`number`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{hint:y(`know.unitHint`),children:y(`know.unit`)}),(0,G.jsx)(T,{value:u,maxLength:20,onChange:e=>d(e.target.value)})]}):null,c===`choice`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{hint:y(`know.valuesHint`),children:y(`know.values`)}),(0,G.jsx)(_,{minRows:3,value:S,onChange:e=>C(e.target.value)})]}),(0,G.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[y(`know.multiple`),(0,G.jsx)(x,{checked:f,onChange:h})]}),(0,G.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[y(`know.ordered`),(0,G.jsx)(x,{checked:g,onChange:b})]})]}):null,(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{hint:y(`know.hintFieldHint`),children:y(`know.hintField`)}),(0,G.jsx)(T,{value:w,maxLength:120,onChange:e=>D(e.target.value)})]}),k.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:k.error.message}):null,(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(E,{variant:`ghost`,onClick:n,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:k.isPending,disabled:!o.trim(),children:y(`know.create`)})]})]})})}function Se({projectId:e,category:t,readOnly:n,onOpen:r,onGone:o}){let s=i(),c=()=>s.invalidateQueries({queryKey:q(e)}),[l,u]=(0,W.useState)(``),f=I({mutationFn:e=>e(),onSuccess:c}),p=K[t.type],m=new Map(t.values.map(e=>[e.id,e]));return(0,G.jsxs)(N,{title:t.name,hint:[y(`know.type.${t.type}`),t.unit,t.hint].filter(Boolean).join(` · `),plain:!0,action:n?null:(0,G.jsx)(C,{label:y(`know.deleteCategory`),className:`hover:text-rose`,onClick:()=>confirm(y(`know.confirmCategory`,{name:t.name}))&&f.mutate(async()=>{await O.del(`/api/studio/categories/${t.id}`),o()}),children:(0,G.jsx)(F,{className:`size-4`})}),children:[t.proposed&&!n?(0,G.jsxs)(S,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,G.jsx)(w,{tone:`ember`,children:y(`know.proposed`)}),(0,G.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:y(`know.proposedHint`)}),(0,G.jsx)(E,{size:`sm`,onClick:()=>f.mutate(()=>O.patch(`/api/studio/categories/${t.id}`,{proposed:!1})),children:y(`know.accept`)})]}):null,t.alike.map(([e,t])=>{let r=m.get(e),i=m.get(t);if(!(r&&i))return null;let[a,o]=r.count<i.count?[r,i]:[i,r];return(0,G.jsxs)(S,{className:`flex flex-wrap items-center gap-3 p-4`,children:[(0,G.jsx)(`span`,{className:`flex-1 text-[0.875rem] text-ink-2`,children:y(`know.alike`,{a:a.value,b:o.value})}),n?null:(0,G.jsx)(E,{size:`sm`,variant:`secondary`,busy:f.isPending,onClick:()=>f.mutate(()=>O.post(`/api/studio/values/${a.id}/merge`,{into:o.id})),children:y(`know.merge`)})]},`${e}:${t}`)}),(0,G.jsxs)(S,{className:`flex flex-col p-1.5`,children:[t.type===`choice`?t.values.length?t.values.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(`v:${e.id}`),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,G.jsx)(p,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.value}),e.summary?(0,G.jsx)(w,{children:y(`know.summary`)}):null,(0,G.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:he(e.count)})]},e.id)):(0,G.jsx)(d,{children:y(`know.empty`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2.5 text-[0.875rem]`,children:[(0,G.jsx)(p,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`flex-1 text-ink-2`,children:t.range?y(`know.range`,{min:J(t,t.range.min),max:J(t,t.range.max)}):y(`know.unset`)}),(0,G.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:he(t.count)})]}),t.type===`choice`&&!n?(0,G.jsxs)(`form`,{className:`flex gap-2 border-border-soft border-t p-2`,onSubmit:e=>{e.preventDefault();let n=l.trim();n&&(u(``),f.mutate(()=>O.post(`/api/studio/categories/${t.id}/values`,{value:n})))},children:[(0,G.jsx)(T,{value:l,placeholder:y(`know.addValue`),onChange:e=>u(e.target.value),className:`h-9`}),(0,G.jsx)(C,{label:y(`know.addValue`),type:`submit`,children:(0,G.jsx)(a,{className:`size-4`})})]}):null]}),f.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:f.error.message}):null]})}function Ce(e){return r({queryKey:[`knowledge-value`,e],queryFn:()=>O.get(`/api/studio/values/${e}`),enabled:!!e})}function we({value:e,readOnly:t,children:n}){let r=i(),a=I({mutationFn:()=>O.post(`/api/studio/values/${e.id}/summary`),onSuccess:()=>r.invalidateQueries({queryKey:[`knowledge-value`,e.id]})});return(0,G.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,G.jsx)(N,{title:y(`know.summary`),hint:y(`know.summaryHint`),plain:!0,action:t?null:(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,busy:a.isPending,onClick:()=>a.mutate(),children:[e.summary?(0,G.jsx)(re,{className:`size-4`}):null,e.summary?y(`know.summaryAgain`):y(`know.summaryWrite`)]}),children:(0,G.jsxs)(S,{className:`p-4 sm:p-5`,children:[a.isPending?(0,G.jsx)(`div`,{className:`flex h-24 items-center justify-center text-ink-3`,children:(0,G.jsx)(h,{})}):e.summary?(0,G.jsx)(ae,{text:e.summary,className:`text-[0.875rem]`}):(0,G.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:y(`know.summaryEmpty`)}),a.error?(0,G.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:a.error.message}):null]})}),(0,G.jsx)(N,{title:y(`know.toc`),plain:!0,children:n})]})}function Te(e){return r({queryKey:[`knowledge`,e],queryFn:()=>O.get(`/api/studio/projects/${e}/knowledge`),enabled:!!e,refetchInterval:e=>e.state.data?.items.some(e=>e.status===`pending`)?2e3:!1})}function Ee(e){return e.kind===`table`?e.format===`faq`?de:j:e.kind===`file`?c:e.children?ue:L}function Y({item:e,categories:t,onOpen:n}){let r=Ee(e),i=[ge(t,e.categories),e.children?e.children===1?y(`know.oneSub`):y(`know.sub`,{n:e.children}):``,e.rows===null?``:e.rows===1?y(`know.row`):y(`know.rows`,{n:e.rows}),e.originLabel??``].filter(Boolean).join(` · `);return(0,G.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,G.jsx)(r,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,G.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),i?(0,G.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:i}):null]}),e.status===`pending`?(0,G.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,G.jsx)(h,{className:`size-3`}),` `,y(`know.reading`)]}):e.review?(0,G.jsx)(w,{tone:`warn`,title:e.review,children:y(`know.review`)}):null]})}function X({projectId:e,itemKey:t,has:n,originLabel:r,kept:i,review:a,file:o,readOnly:s,onReviewed:l}){let u=Te(e),d=[r?y(i?`know.kept`:`know.from`,{label:r}):``].filter(Boolean);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[u.data?(0,G.jsx)(ye,{projectId:e,itemKey:t,has:n,categories:u.data.categories,readOnly:s}):null,d.length||o||a?(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.8125rem] text-ink-3`,children:[d.map(e=>(0,G.jsx)(`span`,{children:e},e)),o?(0,G.jsxs)(`a`,{href:P(e,o.id),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 underline-offset-2 hover:text-ink hover:underline`,children:[(0,G.jsx)(c,{className:`size-3.5`}),` `,y(`know.original`),`: `,o.name]}):null,a?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(w,{tone:`warn`,children:y(`know.review`)}),(0,G.jsx)(`span`,{children:a}),s?null:(0,G.jsx)(`button`,{type:`button`,onClick:l,className:`underline hover:text-ink`,children:y(`know.reviewed`)})]}):null]}):null]})}function De(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 Oe({projectId:e,category:t,categories:n,onOpen:i}){let a=r({queryKey:[`knowledge`,e,`category`,t.id],queryFn:()=>O.get(`/api/studio/categories/${t.id}/items`)});if(!a.data)return a.isLoading?(0,G.jsx)(h,{className:`mx-auto size-4 text-ink-3`}):null;let o=e=>e.categories.find(e=>e.categoryId===t.id)?.values[0],s=[...a.data.items].sort((e,t)=>{let n=o(e),r=o(t);return typeof n==`number`&&typeof r==`number`?n-r:String(r??``).localeCompare(String(n??``),b)}),c=t.type===`number`?De(s.map(o).filter(e=>typeof e==`number`)):[],l=new Intl.NumberFormat(b,{notation:`compact`,maximumFractionDigits:1}),u=t.unit?` ${t.unit}`:``,d=new Map;for(let e of s){let n=o(e),r=typeof n==`number`?c.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(b,{month:`long`,year:`numeric`}):r?y(`know.range`,{min:`${l.format(r.lo)}${u}`,max:`${l.format(r.hi)}${u}`}):J(t,n);d.set(i,[...d.get(i)??[],e])}return(0,G.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[[...d].map(([e,t])=>(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e?(0,G.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e}):null,(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:t.map(e=>(0,G.jsx)(Y,{item:e,categories:n,onOpen:i},e.key))})]},e)),a.data.rows.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:y(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})}function ke(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 Ae(e,t){if(Array.isArray(t))return t.map(String).join(`, `);if(typeof t==`boolean`)return y(t?`know.yes`:`know.no`);if(typeof t==`object`&&t){let n=t.gte??t.after,r=t.lte??t.before;return t.contains?`${y(`know.contains`)} ${t.contains}`:[n===void 0?``:`${y(`know.minimum`)} ${J(e,n)}`,r===void 0?``:`${y(`know.maximum`)} ${J(e,r)}`].filter(Boolean).join(` `)}return String(t)}function je({category:e,value:t,onChange:n}){let[r,i]=(0,W.useState)(!1),a=(0,W.useRef)(null);(0,W.useEffect)(()=>{if(!r)return;let e=e=>!a.current?.contains(e.target)&&i(!1);return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]);let o=K[e.type],s=typeof t==`object`&&t&&!Array.isArray(t)?t:{},c=(t,r)=>{let i={...s,[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,G.jsxs)(`div`,{ref:a,className:`relative`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:g(`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,G.jsx)(o,{className:`size-3.5 text-ink-3`}),e.name,t===void 0?null:(0,G.jsxs)(`span`,{className:`font-medium`,children:[`: `,Ae(e,t)]}),(0,G.jsx)(u,{className:`size-3.5 text-ink-3`})]}),r?(0,G.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,G.jsx)(D,{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,G.jsx)(D,{value:t===!0?y(`know.yes`):t===!1?y(`know.no`):``,options:[y(`know.yes`),y(`know.no`)],onChange:e=>n(e===y(`know.yes`))}):e.type===`text`?(0,G.jsx)(T,{"data-autofocus":!0,value:s.contains??``,placeholder:y(`know.contains`),onChange:e=>n(e.target.value?{contains:e.target.value}:void 0),className:`h-9`}):(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(e.type===`number`?[`gte`,`lte`]:[`after`,`before`]).map((t,n)=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(n===0?`know.minimum`:`know.maximum`)}),(0,G.jsx)(T,{type:e.type===`number`?`number`:`date`,step:`any`,value:String(s[t]??``),placeholder:e.range?String(n===0?e.range.min:e.range.max):``,onChange:e=>c(t,e.target.value),className:`h-9`})]},t))}),t===void 0?null:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{n(void 0),i(!1)},className:`mt-3 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:y(`know.clear`)})]}):null]})}function Me({found:e,onOpen:t}){return e.hits.length?(0,G.jsxs)(`div`,{className:`flex flex-col`,children:[(0,G.jsx)(`p`,{className:`px-3 pt-1 pb-2 text-[0.75rem] text-ink-3`,children:e.checked?y(`know.searchStats`,{candidates:e.candidates,hits:e.hits.length}):y(`know.searchUnchecked`,{hits:e.hits.length})}),e.hits.map(e=>{let n=e.open;return(0,G.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,G.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`span`,{className:`block truncate text-[0.875rem]`,children:[e.title,e.heading&&e.heading!==e.title?(0,G.jsxs)(`span`,{className:`text-ink-3`,children:[` › `,e.heading]}):null]}),(0,G.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-3`,children:e.text})]}),e.relevance===null?null:(0,G.jsx)(`span`,{className:`shrink-0 font-medium text-[0.75rem] text-moss tabular-nums`,children:e.relevance.toLocaleString(b,{minimumFractionDigits:2})})]},`${e.key}:${e.heading}`)})]}):(0,G.jsx)(`p`,{className:`px-3 py-4 text-[0.875rem] text-ink-3`,children:y(`know.searchNone`)})}function Ne({kind:e,projectId:t,onClose:n,onMade:r}){let a=i(),[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(!1),u=I({mutationFn:()=>O.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:o.trim(),...e===`table`&&c?{format:`faq`}:{}}),onSuccess:async({id:n})=>{await a.invalidateQueries({queryKey:[`knowledge`,t]}),r(`${e===`table`?`t`:`p`}:${n}`),s(``),l(!1)}});return(0,G.jsx)(v,{open:e!==null,onClose:n,title:y(e===`table`?`know.newTable`:`know.newPage`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),o.trim()&&u.mutate()},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.title`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:o,maxLength:120,onChange:e=>s(e.target.value)})]}),e===`table`?(0,G.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-[0.875rem]`,children:[y(`know.asFaq`),(0,G.jsx)(x,{checked:c,onChange:l})]}):null,u.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:u.error.message}):null,(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(E,{variant:`ghost`,onClick:n,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:u.isPending,disabled:!o.trim(),children:y(`know.create`)})]})]})})}function Pe({projectId:e,data:t,readOnly:n,onOpen:r}){let o=i(),s=te(e,n),[c,l]=(0,W.useState)({}),[u,f]=(0,W.useState)(``),[p,m]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,b]=(0,W.useState)(null),x=t.categories.filter(e=>!e.proposed&&e.count>0),C=t.categories.filter(e=>e.proposed),T=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?ke(i,a.values,r):!1})),D=async()=>{if(!u.trim()){m(null);return}_(!0);try{m(await O.post(`/api/studio/projects/${e}/search`,{query:u,...Object.keys(c).length?{where:c}:{}}))}catch{m({hits:[],candidates:0,checked:!1,filtered:null})}finally{_(!1)}},k=I({mutationFn:({id:e,keep:t})=>t?O.patch(`/api/studio/categories/${e}`,{proposed:!1}):O.del(`/api/studio/categories/${e}`),onSuccess:()=>o.invalidateQueries({queryKey:[`knowledge`,e]})});return(0,G.jsxs)(N,{title:y(`know.title`),hint:y(`know.hint`),plain:!0,action:n?null:(0,G.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>b(`page`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.page`)]}),(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>b(`table`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.table`)]}),(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>b(`category`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.category`)]})]}),children:[C.length&&!n?(0,G.jsx)(S,{className:`flex flex-col gap-2 p-4`,children:C.map(e=>{let t=K[e.type];return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,G.jsx)(w,{tone:`ember`,children:y(`know.proposed`)}),(0,G.jsx)(t,{className:`size-4 text-ink-3`}),(0,G.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:e.name}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink-3`,children:[y(`know.type.${e.type}`),e.hint].filter(Boolean).join(` · `)}),(0,G.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>k.mutate({id:e.id,keep:!1}),children:y(`know.dismiss`)}),(0,G.jsx)(E,{size:`sm`,onClick:()=>k.mutate({id:e.id,keep:!0}),children:y(`know.accept`)})]},e.id)})}):null,t.items.length?(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(ne,{value:u,placeholder:y(`know.search`),busy:g,onEnter:()=>void D(),onChange:e=>{f(e),e.trim()||m(null)}}),x.length?(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[x.map(e=>(0,G.jsx)(je,{category:e,value:c[e.name],onChange:t=>{m(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,G.jsx)(`button`,{type:`button`,onClick:()=>l({}),className:`px-2 text-[0.8125rem] text-ink-3 underline hover:text-ink`,children:y(`know.clear`)}):null]}):null]}):null,(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:p?(0,G.jsx)(Me,{found:p,onOpen:r}):T.length?T.map(e=>(0,G.jsx)(Y,{item:e,categories:t.categories,onOpen:r},e.key)):(0,G.jsx)(d,{children:y(`know.empty`)})}),n?null:(0,G.jsxs)(M,{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,G.jsx)(h,{className:`size-4`}):(0,G.jsx)(A,{className:`size-4`}),y(`know.drop`),` `,(0,G.jsx)(`span`,{className:`underline`,children:y(`know.pick`)})]}),s.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error}):null,t.items.length&&!(t.checked&&t.embeddings)?(0,G.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[t.embeddings?``:y(`know.keywordsOnly`),t.checked?``:y(`know.unchecked`)].filter(Boolean).join(` `)}):null,(0,G.jsx)(Ne,{kind:v===`page`||v===`table`?v:null,projectId:e,onClose:()=>b(null),onMade:e=>{b(null),r(e)}}),(0,G.jsx)(xe,{projectId:e,open:v===`category`,onClose:()=>b(null),onMade:e=>{b(null),r(`c:${e}`)}})]})}function Fe({page:e,onGone:t,onOpen:n}){let r=i(),[o,c]=(0,W.useState)(e.title),[l,u]=(0,W.useState)(e.markdown),[d,f]=(0,W.useState)(e.markdown?`read`:`write`),p=e.knowledge,m=async()=>{await r.invalidateQueries({queryKey:[`space-data`,e.projectId]}),await r.invalidateQueries({queryKey:[`knowledge`,e.projectId]})},_=ee({title:o.trim()||e.title,markdown:l},async t=>{await O.patch(`/api/studio/pages/${e.id}`,t),r.setQueryData([`space-page`,e.id],e=>e&&{...e,...t}),t.title!==e.title&&await m()}),v=I({mutationFn:()=>O.del(`/api/studio/pages/${e.id}`),onSuccess:async()=>{await m(),t()}}),b=I({mutationFn:()=>O.post(`/api/studio/projects/${e.projectId}/pages`,{title:y(`know.addSub`),parentId:e.id}),onSuccess:async({id:e})=>{await m(),n?.(`p:${e}`)}}),x=I({mutationFn:()=>O.patch(`/api/studio/pages/${e.id}`,{review:null}),onSuccess:()=>r.invalidateQueries({queryKey:[`space-page`,e.id]})}),w=async t=>{let r=t.target.closest(`a`)?.getAttribute(`href`);if(!(r?.startsWith(`pages/`)&&n))return;t.preventDefault();let i=await O.get(`/api/studio/projects/${e.projectId}/resolve?path=${encodeURIComponent(r)}`).catch(()=>null);i?.kind===`page`&&n(`p:${i.id}`)},T=e.readOnly,D=p?.file&&(p.file.mime===`application/pdf`||p.file.mime.startsWith(`image/`))?p.file:null,A=(e,t)=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":d===e,onClick:()=>f(e),className:g(`rounded-full px-3 py-1 text-[0.8125rem] transition`,d===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,G.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[p?.parents.length&&n?(0,G.jsx)(`nav`,{className:`-mb-1.5 flex flex-wrap items-center gap-1 px-1 text-[0.8125rem] text-ink-3`,children:p.parents.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>n(`p:${e.id}`),className:`hover:text-ink`,children:e.title}),(0,G.jsx)(k,{className:`size-3.5`})]},e.id))}):null,(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,G.jsx)(`input`,{value:o,disabled:T,maxLength:200,onChange:e=>c(e.target.value),"aria-label":y(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),_.state===`saving`?(0,G.jsx)(h,{className:`size-3.5 text-ink-3`}):_.state===`saved`?(0,G.jsx)(s,{className:`size-4 text-moss`,"aria-label":y(`settings.saved`)}):null,T?null:(0,G.jsx)(C,{label:y(`data.deletePage`),onClick:()=>confirm(y(`data.confirmDelete`,{title:e.title}))&&v.mutate(),className:`hover:text-rose`,children:(0,G.jsx)(F,{className:`size-4`})})]}),p?(0,G.jsx)(X,{projectId:e.projectId,itemKey:`p:${e.id}`,has:p.categories,originLabel:p.originLabel,kept:p.kept,review:p.review,file:D?null:p.file,readOnly:T,onReviewed:()=>x.mutate()}):null,(0,G.jsxs)(S,{className:`flex flex-col`,children:[T&&!D?null:(0,G.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[T?null:A(`write`,y(`data.write`)),A(`read`,y(`data.preview`)),D?A(`original`,y(`know.original`)):null,(0,G.jsx)(`span`,{className:`ml-auto truncate px-2 text-[0.75rem] text-ink-4 max-sm:hidden`,children:d===`original`&&D?D.name:y(`data.markdownHint`)})]}),d===`original`&&D?D.mime===`application/pdf`?(0,G.jsx)(`iframe`,{src:P(e.projectId,D.id),title:D.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,G.jsx)(`img`,{src:P(e.projectId,D.id),alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):d===`write`&&!T?(0,G.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),"aria-label":e.title,placeholder:y(`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,G.jsx)(`div`,{className:`min-h-40 p-4 sm:p-5`,onClick:w,children:l.trim()?(0,G.jsx)(ae,{text:l}):(0,G.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:y(`data.pageEmpty`)})})]}),_.state===`error`&&_.error?(0,G.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:_.error}):null,p&&n&&(p.children.length||!T)?(0,G.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,G.jsx)(`p`,{className:`font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:p.children.length?y(`know.subPages`):null}),T?null:(0,G.jsxs)(E,{variant:`ghost`,size:`sm`,busy:b.isPending,onClick:()=>b.mutate(),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`know.addSub`)]})]}),p.children.length?(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:p.children.map(e=>(0,G.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,G.jsx)(L,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title})]},e.id))}):null]}):null]})}function Ie({pageId:e,onGone:t,onOpen:n}){let i=r({queryKey:[`space-page`,e],queryFn:()=>O.get(`/api/studio/pages/${e}`),refetchOnWindowFocus:!1});return i.data?(0,G.jsx)(Fe,{page:i.data,onGone:t,onOpen:n},i.data.id):i.isError?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:i.error.message}):null}function Le(e){return r({queryKey:[`space-data`,e],queryFn:()=>O.get(`/api/studio/projects/${e}/data`),enabled:!!e})}function Re(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:y(`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 ze={table:j,page:L};function Be({kind:e,projectId:t,data:n,onClose:r,onMade:a}){let o=i(),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(``),d=I({mutationFn:()=>O.post(`/api/studio/projects/${t}/${e===`table`?`tables`:`pages`}`,{title:s.trim(),wizardId:l||null}),onSuccess:async({id:n})=>{await o.invalidateQueries({queryKey:[`space-data`,t]}),a(`${e===`table`?`t`:`p`}:${n}`),c(``),u(``)}});return(0,G.jsx)(v,{open:e!==null,onClose:r,title:y(e===`table`?`data.newTable`:`data.newPage`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),s.trim()&&d.mutate()},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.title`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:s,maxLength:120,onChange:e=>c(e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.owner`)}),(0,G.jsx)(m,{value:l,onChange:u,options:[{value:``,label:y(`data.own`)},...n.wizards.map(e=>({value:e.id,label:e.title}))]})]}),d.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null,(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(E,{variant:`ghost`,onClick:r,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:d.isPending,disabled:!s.trim(),children:y(`data.create`)})]})]})})}function Ve({projectId:e,data:t,readOnly:n,onOpen:r}){let[i,o]=(0,W.useState)(null),s=Re(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(b,{dateStyle:`medium`});return(0,G.jsxs)(N,{title:y(`space.data`),hint:y(`data.hint`),plain:!0,action:n?null:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>o(`table`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`data.table`)]}),(0,G.jsxs)(E,{variant:`secondary`,size:`sm`,onClick:()=>o(`page`),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`data.page`)]})]}),children:[s.length?(0,G.jsx)(`div`,{className:`flex flex-col gap-5`,children:s.map(e=>(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`p`,{className:`px-1 font-medium text-[0.6875rem] text-ink-4 uppercase tracking-[0.12em]`,children:e.label}),(0,G.jsx)(S,{className:`flex flex-col p-1.5`,children:e.items.map(e=>{let t=ze[e.kind];return(0,G.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,G.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,G.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3 tabular-nums`,children:[e.kind===`table`?`${y(`data.rows`,{n:e.rows??0})} · `:``,l.format(new Date(c.get(e.key)??Date.now()))]})]},e.key)})})]},e.key))}):(0,G.jsx)(S,{children:(0,G.jsx)(d,{children:y(`data.empty`)})}),(0,G.jsx)(Be,{kind:i,projectId:e,data:t,onClose:()=>o(null),onMade:e=>{o(null),r(e)}})]})}function He(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 Ue={milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5},We=[`text`,`number`,`date`,`duration`,`select`,`boolean`];function Ge(e,t){if(t==null)return``;if(e.type===`duration`&&typeof t==`number`)return String(t/Ue[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 Ke(e,t){return t.trim()===``?null:e.type===`date`&&e.format.kind===`datetime`?new Date(t).toISOString():t}var Z=`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 qe({column:e,value:t,readOnly:n,invalid:r,onSave:i}){let a=Ge(e,t),[o,s]=(0,W.useState)(a);(0,W.useEffect)(()=>s(a),[a]);let c=(t=o)=>{t!==a&&i(Ke(e,t))};if(e.type===`boolean`)return(0,G.jsx)(`div`,{className:`px-2 py-1.5`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:t===!0,disabled:n,onChange:e=>i(e.target.checked),"aria-label":e.name,className:`size-4 accent-[var(--ember)]`})});if(e.type===`select`&&e.format.multiple){let r=Array.isArray(t)?t:[],a=t=>e.format.options.find(e=>e.id===t)?.label??t;return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-2 py-1`,children:[r.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-paper-2 py-0.5 pr-1 pl-2 text-[0.75rem]`,children:[a(e),n?null:(0,G.jsx)(`button`,{type:`button`,"aria-label":y(`data.removeOption`),onClick:()=>i(r.filter(t=>t!==e)),className:`rounded-full text-ink-3 hover:text-ink`,children:(0,G.jsx)(l,{className:`size-3`})})]},e)),n?null:(0,G.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,G.jsx)(`option`,{value:``,children:`+`}),e.format.options.filter(e=>!r.includes(e.id)).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})}if(e.type===`select`)return(0,G.jsxs)(`select`,{value:typeof t==`string`?t:``,disabled:n,onChange:e=>i(e.target.value||null),"aria-label":e.name,className:Z,children:[(0,G.jsx)(`option`,{value:``}),e.format.options.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.label},e.id))]});if(e.type===`text`&&e.format?.style&&e.format.style!==`single`)return(0,G.jsx)(`textarea`,{value:o,rows:1,disabled:n,onChange:e=>s(e.target.value),onBlur:()=>c(),"aria-label":e.name,className:g(Z,`field-sizing-content max-h-40 resize-none`)});let u=e.type===`date`?{date:`date`,datetime:`datetime-local`,time:`time`}[e.format.kind]:`text`;return(0,G.jsx)(`input`,{type:u,inputMode:e.type===`number`||e.type===`duration`?`decimal`:void 0,value:o,disabled:n,onChange:t=>{s(t.target.value),e.type===`date`&&c(t.target.value)},onBlur:()=>e.type!==`date`&&c(),onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&s(a)},"aria-label":e.name,className:g(Z,(e.type===`number`||e.type===`duration`)&&`text-right tabular-nums`,r&&`ring-1 ring-rose`)})}function Je(e){return e.type===`number`&&e.format.style===`currency`?e.format.currency??null:e.type===`number`&&e.format.style===`percent`?`%`:e.type===`duration`?y(`data.unit.${e.format.inputUnit}`):null}function Ye(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
3
|
`):``,multiple:e?.type===`select`&&!!e.format.multiple}}function Xe(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??He(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 Ze({open:e,column:t,columns:n,onClose:r,onSave:i}){let[a,o]=(0,W.useState)(()=>Ye(t)),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!1);(0,W.useEffect)(()=>{e&&(o(Ye(t)),c(null))},[e,t]);let d=e=>o(t=>({...t,...e})),f=async e=>{u(!0),c(null);try{await i(e),r()}catch(e){c(e.message)}finally{u(!1)}},h=()=>{let e=t?.id??He(a.name,n.map(e=>e.id)),r=Xe(a,e,t);return f(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,G.jsx)(v,{open:e,onClose:r,title:t?t.name:y(`data.newColumn`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.name.trim()&&h()},children:[(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.columnName`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:a.name,maxLength:128,onChange:e=>d({name:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.columnType`)}),(0,G.jsx)(m,{value:a.type,onChange:e=>d({type:e}),options:We.map(e=>({value:e,label:y(`data.type.${e}`)}))})]})]}),a.type===`text`?(0,G.jsx)(m,{value:a.textStyle,onChange:e=>d({textStyle:e}),options:[{value:`single`,label:y(`data.text.single`)},{value:`multiline`,label:y(`data.text.multiline`)}]}):null,a.type===`number`?(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsx)(m,{value:a.numberStyle,onChange:e=>d({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:y(`data.number.${e}`)}))}),a.numberStyle===`currency`?(0,G.jsx)(T,{value:a.currency,maxLength:3,"aria-label":y(`data.currency`),placeholder:`EUR`,onChange:e=>d({currency:e.target.value})}):null]}):null,a.type===`date`?(0,G.jsx)(m,{value:a.dateKind,onChange:e=>d({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:y(`data.date.${e}`)}))}):null,a.type===`duration`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.unit`)}),(0,G.jsx)(m,{value:a.unit,onChange:e=>d({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:y(`data.unit.${e}`)}))})]}):null,a.type===`select`?(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.options`)}),(0,G.jsx)(_,{minRows:3,value:a.options,onChange:e=>d({options:e.target.value})})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,G.jsx)(x,{checked:a.multiple,onChange:e=>d({multiple:e})}),y(`data.multiple`)]})]}):null,(0,G.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,G.jsx)(x,{checked:a.required,onChange:e=>d({required:e})}),y(`data.required`)]}),s?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,G.jsx)(E,{variant:`ghost`,className:`text-rose`,disabled:l,onClick:()=>confirm(y(`data.confirmDelete`,{title:t.name}))&&void f(n.filter(e=>e.id!==t.id)),children:y(`data.deleteColumn`)}):null,(0,G.jsx)(`span`,{className:`flex-1`}),(0,G.jsx)(E,{variant:`ghost`,onClick:r,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:l,disabled:!a.name.trim(),children:y(`settings.save`)})]})]})})}function Qe({tableId:e,onGone:t}){let n=r(),o=[`space-table`,e],s=i({queryKey:o,queryFn:()=>O.get(`/api/studio/tables/${e}`)}),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[p,m]=(0,W.useState)(null),[h,g]=(0,W.useState)(``);(0,W.useEffect)(()=>g(s.data?.title??``),[s.data?.title]);let _=async()=>{await n.invalidateQueries({queryKey:[`space-data`,s.data?.projectId]}),await n.invalidateQueries({queryKey:[`knowledge`,s.data?.projectId]})},v=e=>n.setQueryData(o,t=>t&&{...t,rows:e(t.rows)}),b=e=>{d(e.message),s.refetch()},x=async t=>{await O.patch(`/api/studio/tables/${e}`,t),await s.refetch(),await _()},w=L({mutationFn:({row:t,column:n,value:r})=>O.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),v(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof f&&e.body?.column===n){let e=s.data?.columns.find(e=>e.id===n)?.name??n;m(`${t}:${n}`),d(y(`data.badCell`,{column:e}));return}b(e)}}),T=L({mutationFn:()=>O.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{v(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await _()},onError:b}),D=L({mutationFn:t=>O.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{v(e=>e.filter(e=>e.id!==t)),await _()},onError:b}),k=L({mutationFn:()=>O.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await _(),t()}});if(!s.data)return s.isError?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error.message}):null;let{columns:A,rows:j,readOnly:M}=s.data,N=!!s.data.list;return(0,G.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,G.jsx)(`input`,{value:h,disabled:M,maxLength:120,onChange:e=>g(e.target.value),onBlur:()=>h.trim()&&h!==s.data?.title&&void x({title:h}).catch(b),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":y(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),M?null:(0,G.jsx)(C,{label:y(`data.deleteTable`),onClick:()=>confirm(y(`data.confirmDelete`,{title:s.data.title}))&&k.mutate(),className:`hover:text-rose`,children:(0,G.jsx)(F,{className:`size-4`})})]}),N?(0,G.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:y(`data.fromList`)}):null,s.data.knowledge?(0,G.jsx)(X,{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:M,onReviewed:()=>void O.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>s.refetch()).catch(b)}):null,(0,G.jsxs)(S,{className:`overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full border-collapse text-left`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[A.map(e=>(0,G.jsx)(`th`,{className:`min-w-36 border-border-soft border-l p-1 font-medium first:border-l-0`,children:(0,G.jsxs)(`button`,{type:`button`,disabled:M||N,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,G.jsx)(`span`,{className:`truncate`,children:e.name}),e.required?(0,G.jsx)(`span`,{className:`text-ember`,children:`*`}):null,Je(e)?(0,G.jsx)(`span`,{className:`font-normal text-ink-4`,children:Je(e)}):null]})},e.id)),(0,G.jsx)(`th`,{className:`w-10 p-1`,children:M||N?null:(0,G.jsx)(C,{label:y(`data.newColumn`),onClick:()=>l(`new`),className:`size-8`,children:(0,G.jsx)(a,{className:`size-4`})})})]})}),(0,G.jsx)(`tbody`,{children:j.map(e=>(0,G.jsxs)(`tr`,{className:`group border-border-soft border-b last:border-b-0`,children:[A.map(t=>(0,G.jsx)(`td`,{className:`border-border-soft border-l p-1 align-top first:border-l-0`,children:(0,G.jsx)(qe,{column:t,value:e.cells[t.id],readOnly:M,invalid:p===`${e.id}:${t.id}`,onSave:n=>w.mutate({row:e.id,column:t.id,value:n})})},t.id)),(0,G.jsx)(`td`,{className:`w-10 p-1 align-top`,children:M?null:(0,G.jsx)(C,{label:y(`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,G.jsx)(F,{className:`size-3.5`})})})]},e.id))})]})}),j.length?null:(0,G.jsx)(`p`,{className:`px-4 py-6 text-center text-[0.875rem] text-ink-3`,children:y(`data.noRows`)}),M?null:(0,G.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,G.jsxs)(E,{variant:`ghost`,size:`sm`,busy:T.isPending,onClick:()=>T.mutate(),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`data.addRow`)]})})]}),u?(0,G.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:u}):null,(0,G.jsx)(Ze,{open:c!==null,column:c===`new`?null:c,columns:A,onClose:()=>l(null),onSave:e=>x({columns:e})})]})}var Q=`wizards.runDrawer.width`,$e=`wizards.runDrawer.wide`,et=680,$=400,tt=()=>Math.max($,window.innerWidth-120);function nt(e){try{return localStorage.getItem(e)}catch{return null}}function rt(e,t){try{localStorage.setItem(e,t)}catch{}}function it(){let[e,t]=(0,W.useState)(()=>{let e=Number(nt(Q));return e?Math.min(Math.max(e,$),tt()):et}),[n,r]=(0,W.useState)(()=>nt($e)===`1`),i=(0,W.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,$),tt()));t(n),rt(Q,String(n))},[]);return{width:e,wide:n,toggleWide:()=>{r(!n),rt($e,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(et)}}function at({header:e,actions:t,onClose:n,children:r}){let i=it();return(0,G.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,G.jsxs)(`div`,{className:g(`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,G.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":y(`editor.resize`),"aria-valuenow":i.width,tabIndex:0,title:y(`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,G.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,G.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4`,children:[(0,G.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:e}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t,(0,G.jsx)(C,{label:y(i.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:i.toggleWide,className:`max-sm:hidden`,children:i.wide?(0,G.jsx)(fe,{className:`size-4`}):(0,G.jsx)(ie,{className:`size-4`})}),(0,G.jsx)(C,{label:y(`editor.close`),onClick:n,children:(0,G.jsx)(l,{className:`size-5`})})]})]}),(0,G.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}export{me as _,Re as a,Oe as c,Pe as d,Te as f,Ce as g,we as h,Ve as i,Y as l,Se as m,Qe as n,Le as o,K as p,ze as r,Ie as s,at as t,X as u,z as v,ce as y};
|
|
4
|
+
`).map(e=>e.trim()).filter(Boolean).map(e=>{let n=t.find(t=>t.label===e)?.id??He(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 Ze({open:e,column:t,columns:n,onClose:r,onSave:i}){let[a,o]=(0,W.useState)(()=>Ye(t)),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!1);(0,W.useEffect)(()=>{e&&(o(Ye(t)),c(null))},[e,t]);let d=e=>o(t=>({...t,...e})),f=async e=>{u(!0),c(null);try{await i(e),r()}catch(e){c(e.message)}finally{u(!1)}},h=()=>{let e=t?.id??He(a.name,n.map(e=>e.id)),r=Xe(a,e,t);return f(t?n.map(e=>e.id===t.id?r:e):[...n,r])};return(0,G.jsx)(v,{open:e,onClose:r,title:t?t.name:y(`data.newColumn`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),a.name.trim()&&h()},children:[(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.columnName`)}),(0,G.jsx)(T,{"data-autofocus":!0,value:a.name,maxLength:128,onChange:e=>d({name:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.columnType`)}),(0,G.jsx)(m,{value:a.type,onChange:e=>d({type:e}),options:We.map(e=>({value:e,label:y(`data.type.${e}`)}))})]})]}),a.type===`text`?(0,G.jsx)(m,{value:a.textStyle,onChange:e=>d({textStyle:e}),options:[{value:`single`,label:y(`data.text.single`)},{value:`multiline`,label:y(`data.text.multiline`)}]}):null,a.type===`number`?(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,G.jsx)(m,{value:a.numberStyle,onChange:e=>d({numberStyle:e}),options:[`integer`,`decimal`,`percent`,`currency`].map(e=>({value:e,label:y(`data.number.${e}`)}))}),a.numberStyle===`currency`?(0,G.jsx)(T,{value:a.currency,maxLength:3,"aria-label":y(`data.currency`),placeholder:`EUR`,onChange:e=>d({currency:e.target.value})}):null]}):null,a.type===`date`?(0,G.jsx)(m,{value:a.dateKind,onChange:e=>d({dateKind:e}),options:[`date`,`datetime`,`time`].map(e=>({value:e,label:y(`data.date.${e}`)}))}):null,a.type===`duration`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.unit`)}),(0,G.jsx)(m,{value:a.unit,onChange:e=>d({unit:e}),options:[`minutes`,`hours`,`days`].map(e=>({value:e,label:y(`data.unit.${e}`)}))})]}):null,a.type===`select`?(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(p,{children:y(`data.options`)}),(0,G.jsx)(_,{minRows:3,value:a.options,onChange:e=>d({options:e.target.value})})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,G.jsx)(x,{checked:a.multiple,onChange:e=>d({multiple:e})}),y(`data.multiple`)]})]}):null,(0,G.jsxs)(`label`,{className:`flex items-center gap-3 text-[0.875rem]`,children:[(0,G.jsx)(x,{checked:a.required,onChange:e=>d({required:e})}),y(`data.required`)]}),s?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&n.length>1?(0,G.jsx)(E,{variant:`ghost`,className:`text-rose`,disabled:l,onClick:()=>confirm(y(`data.confirmDelete`,{title:t.name}))&&void f(n.filter(e=>e.id!==t.id)),children:y(`data.deleteColumn`)}):null,(0,G.jsx)(`span`,{className:`flex-1`}),(0,G.jsx)(E,{variant:`ghost`,onClick:r,children:y(`common.cancel`)}),(0,G.jsx)(E,{type:`submit`,busy:l,disabled:!a.name.trim(),children:y(`settings.save`)})]})]})})}function Qe({tableId:e,onGone:t}){let n=i(),o=[`space-table`,e],s=r({queryKey:o,queryFn:()=>O.get(`/api/studio/tables/${e}`)}),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[p,m]=(0,W.useState)(null),[h,g]=(0,W.useState)(``);(0,W.useEffect)(()=>g(s.data?.title??``),[s.data?.title]);let _=async()=>{await n.invalidateQueries({queryKey:[`space-data`,s.data?.projectId]}),await n.invalidateQueries({queryKey:[`knowledge`,s.data?.projectId]})},v=e=>n.setQueryData(o,t=>t&&{...t,rows:e(t.rows)}),b=e=>{d(e.message),s.refetch()},x=async t=>{await O.patch(`/api/studio/tables/${e}`,t),await s.refetch(),await _()},w=I({mutationFn:({row:t,column:n,value:r})=>O.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),v(t=>t.map(t=>t.id===e.id?{...t,cells:e.cells}:t))},onError:(e,{row:t,column:n})=>{if(e instanceof f&&e.body?.column===n){let e=s.data?.columns.find(e=>e.id===n)?.name??n;m(`${t}:${n}`),d(y(`data.badCell`,{column:e}));return}b(e)}}),T=I({mutationFn:()=>O.post(`/api/studio/tables/${e}/rows`,{}),onSuccess:async e=>{v(t=>[...t,{...e,updatedAt:new Date().toISOString()}]),await _()},onError:b}),D=I({mutationFn:t=>O.post(`/api/studio/tables/${e}/rows/delete`,{ids:[t]}),onSuccess:async(e,t)=>{v(e=>e.filter(e=>e.id!==t)),await _()},onError:b}),k=I({mutationFn:()=>O.del(`/api/studio/tables/${e}`),onSuccess:async()=>{await _(),t()}});if(!s.data)return s.isError?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s.error.message}):null;let{columns:A,rows:j,readOnly:M}=s.data,N=!!s.data.list;return(0,G.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,G.jsx)(`input`,{value:h,disabled:M,maxLength:120,onChange:e=>g(e.target.value),onBlur:()=>h.trim()&&h!==s.data?.title&&void x({title:h}).catch(b),onKeyDown:e=>e.key===`Enter`&&e.target.blur(),"aria-label":y(`data.title`),className:`-ml-1 min-w-0 flex-1 rounded-md bg-transparent px-1 font-display font-semibold text-lg outline-none hover:bg-accent focus:bg-paper focus:ring-1 focus:ring-ring disabled:hover:bg-transparent`}),M?null:(0,G.jsx)(C,{label:y(`data.deleteTable`),onClick:()=>confirm(y(`data.confirmDelete`,{title:s.data.title}))&&k.mutate(),className:`hover:text-rose`,children:(0,G.jsx)(F,{className:`size-4`})})]}),N?(0,G.jsx)(`p`,{className:`-mt-1.5 px-1 text-[0.8125rem] text-ink-3`,children:y(`data.fromList`)}):null,s.data.knowledge?(0,G.jsx)(X,{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:M,onReviewed:()=>void O.patch(`/api/studio/tables/${e}`,{review:null}).then(()=>s.refetch()).catch(b)}):null,(0,G.jsxs)(S,{className:`overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full border-collapse text-left`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[A.map(e=>(0,G.jsx)(`th`,{className:`min-w-36 border-border-soft border-l p-1 font-medium first:border-l-0`,children:(0,G.jsxs)(`button`,{type:`button`,disabled:M||N,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,G.jsx)(`span`,{className:`truncate`,children:e.name}),e.required?(0,G.jsx)(`span`,{className:`text-ember`,children:`*`}):null,Je(e)?(0,G.jsx)(`span`,{className:`font-normal text-ink-4`,children:Je(e)}):null]})},e.id)),(0,G.jsx)(`th`,{className:`w-10 p-1`,children:M||N?null:(0,G.jsx)(C,{label:y(`data.newColumn`),onClick:()=>l(`new`),className:`size-8`,children:(0,G.jsx)(a,{className:`size-4`})})})]})}),(0,G.jsx)(`tbody`,{children:j.map(e=>(0,G.jsxs)(`tr`,{className:`group border-border-soft border-b last:border-b-0`,children:[A.map(t=>(0,G.jsx)(`td`,{className:`border-border-soft border-l p-1 align-top first:border-l-0`,children:(0,G.jsx)(qe,{column:t,value:e.cells[t.id],readOnly:M,invalid:p===`${e.id}:${t.id}`,onSave:n=>w.mutate({row:e.id,column:t.id,value:n})})},t.id)),(0,G.jsx)(`td`,{className:`w-10 p-1 align-top`,children:M?null:(0,G.jsx)(C,{label:y(`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,G.jsx)(F,{className:`size-3.5`})})})]},e.id))})]})}),j.length?null:(0,G.jsx)(`p`,{className:`px-4 py-6 text-center text-[0.875rem] text-ink-3`,children:y(`data.noRows`)}),M?null:(0,G.jsx)(`div`,{className:`border-border-soft border-t p-1.5`,children:(0,G.jsxs)(E,{variant:`ghost`,size:`sm`,busy:T.isPending,onClick:()=>T.mutate(),children:[(0,G.jsx)(a,{className:`size-4`}),` `,y(`data.addRow`)]})})]}),u?(0,G.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:u}):null,(0,G.jsx)(Ze,{open:c!==null,column:c===`new`?null:c,columns:A,onClose:()=>l(null),onSave:e=>x({columns:e})})]})}var Q=`wizards.runDrawer.width`,$e=`wizards.runDrawer.wide`,et=680,$=400,tt=()=>Math.max($,window.innerWidth-120);function nt(e){try{return localStorage.getItem(e)}catch{return null}}function rt(e,t){try{localStorage.setItem(e,t)}catch{}}function it(){let[e,t]=(0,W.useState)(()=>{let e=Number(nt(Q));return e?Math.min(Math.max(e,$),tt()):et}),[n,r]=(0,W.useState)(()=>nt($e)===`1`),i=(0,W.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,$),tt()));t(n),rt(Q,String(n))},[]);return{width:e,wide:n,toggleWide:()=>{r(!n),rt($e,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(et)}}function at({header:e,actions:t,onClose:n,children:r}){let i=it();return(0,G.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,G.jsxs)(`div`,{className:g(`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,G.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":y(`editor.resize`),"aria-valuenow":i.width,tabIndex:0,title:y(`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,G.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,G.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4`,children:[(0,G.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:e}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t,(0,G.jsx)(C,{label:y(i.wide?`runDrawer.shrink`:`runDrawer.expand`),onClick:i.toggleWide,className:`max-sm:hidden`,children:i.wide?(0,G.jsx)(fe,{className:`size-4`}):(0,G.jsx)(ie,{className:`size-4`})}),(0,G.jsx)(C,{label:y(`editor.close`),onClick:n,children:(0,G.jsx)(l,{className:`size-5`})})]})]}),(0,G.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r})]})})}export{me as _,Re as a,Oe as c,Pe as d,Te as f,Ce as g,we as h,Ve as i,Y as l,Se as m,Qe as n,Le as o,K as p,ze as r,Ie as s,at as t,X as u,z as v,ce as y};
|