@gentbajko/slopify 3.8.6 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -270,41 +270,41 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
270
270
  Sphinxes
271
271
  Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(LB,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(BB,{rows:10,className:`font-mono`,spellCheck:!1,value:e.yaml,onChange:n=>t({...e,yaml:n.target.value}),placeholder:`- ${f??`Topic`}: Cleopatra\n ${d.find(e=>e!==f)??`Min. Word Count`}: 12000\n- Hypatia`})}):(0,h.jsx)(Vfe,{queue:e,onQueue:t,keyword:f,addable:O,setRow:D,titleOf:b}),k.length===0?null:(0,h.jsx)(aI,{tone:`danger`,title:`These topics can't be saved yet.`,children:(0,h.jsxs)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:[k.slice(0,8).map(e=>(0,h.jsx)(`li`,{children:e},e)),k.length>8?(0,h.jsx)(`li`,{children:`And ${String(k.length-8)} more.`}):null]})}),e.mode===`yaml`&&v.rows.length>0?(0,h.jsxs)(`section`,{"aria-label":`Project titles`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-1 text-small text-ink-2`,children:`Project titles, in order:`}),(0,h.jsxs)(`ol`,{className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:[v.rows.slice(0,20).map((e,t)=>(0,h.jsx)(`li`,{children:b(e)},t)),v.rows.length>20?(0,h.jsx)(`li`,{className:`list-none text-ink-3`,children:`And ${String(v.rows.length-20)} more.`}):null]})]}):null,a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Reading the template's keywords…`}):d.length===0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`This template has no keywords such as `,`{{Topic}}`,`, so each topic becomes the project's title.`]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:(0,h.jsx)(LB,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:B1({feeds:_(f)})},children:(0,h.jsx)(VB,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(V1,{keywords:d.filter(e=>e!==f).map(t=>({name:t,value:g[t]??``,feeds:_(t),...e.columns.includes(t)?{note:`Unless a topic sets its own.`}:{}})),onChange:i,fieldPrefix:`everyRun`,label:e=>`${e} (every run)`,inputLabel:e=>`${e} for every run`,tip:`planning.schedule.every-run`,maxLength:1e4})]}),e.mode===`lines`&&S!==void 0&&x!==void 0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Next project: `,(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:S}),f===null||C?null:(0,h.jsxs)(`span`,{className:`block text-ink-3`,children:[`The template's project title does not use `,`{{${f}}}`,`, so every project gets this title. Edit the template's title to include it.`]})]}):null]})}function Vfe({queue:e,onQueue:t,keyword:n,addable:r,setRow:i,titleOf:a}){let o=n===null?`Title`:`{{${n}}}`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...zb,children:[(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table`,"aria-label":`Topics`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,children:`#`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[o,(0,h.jsx)(U,{id:`planning.schedule.topic-table`,className:`-my-1`})]})}),e.columns.map(n=>(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`{{${n}}}`,(0,h.jsx)(Py,{label:`Use the every-run ${n} for all topics`,size:`small`,onClick:()=>t({...e,columns:e.columns.filter(e=>e!==n),rows:e.rows.map(e=>({title:e.title,values:Object.fromEntries(Object.entries(e.values).filter(([e])=>e!==n))}))}),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]})},n)),(0,h.jsx)(`th`,{scope:`col`,children:`Project title`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:e.rows.map((n,r)=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`num`,children:r+1}),(0,h.jsx)(`td`,{children:(0,h.jsx)(zB,{"aria-label":`Topic ${String(r+1)} ${o}`,maxLength:200,value:n.title,onChange:e=>i(r,{...n,title:e.target.value})})}),e.columns.map(e=>(0,h.jsx)(`td`,{children:(0,h.jsx)(zB,{"aria-label":`Topic ${String(r+1)} ${e}`,maxLength:LK,placeholder:`Every-run value`,value:n.values[e]??``,onChange:t=>i(r,{...n,values:{...n.values,[e]:t.target.value}})})},e)),(0,h.jsx)(`td`,{className:`min-w-[180px] text-small text-ink-2`,children:a(n)??`—`}),(0,h.jsx)(`td`,{children:(0,h.jsx)(Py,{label:`Remove topic ${String(r+1)}`,size:`small`,onClick:()=>t({...e,rows:e.rows.filter((e,t)=>t!==r)}),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})})]},r))})]})}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(B,{size:`small`,onClick:()=>t({...e,rows:[...e.rows,{title:``,values:{}}]}),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]}),r.length===0?null:(0,h.jsxs)(VB,{"aria-label":`Set a keyword per topic`,value:``,className:`w-auto`,onChange:n=>{let r=n.target.value;r!==``&&t({...e,columns:[...e.columns,r]})},children:[(0,h.jsx)(`option`,{value:``,children:`Set a keyword per topic…`}),r.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))]})]})]})}var Hfe=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Ufe({templates:e,pending:t,onCreated:n,onError:r,editing:i,onCancel:a,error:o,onBusy:s}){let{api:c}=V(),[l,u]=(0,m.useState)(i?.name??``),[d,f]=(0,m.useState)(i?.templateId??``),[p,g]=(0,m.useState)(i?.cadence.kind??`daily`),[_,v]=(0,m.useState)(i?.cadence.kind===`once`?Zde(i.cadence.at,i.timezone):``),[y,b]=(0,m.useState)(i&&i.cadence.kind!==`once`?i.cadence.time:`09:00`),[x,S]=(0,m.useState)(i?.cadence.kind===`weekly`?i.cadence.days:[1,3,5]),[C,w]=(0,m.useState)(()=>i?.timezone??(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`)),[T,E]=(0,m.useState)(i?.missedPolicy??`skip`),[D,O]=(0,m.useState)(i?.spendLimitCents?.toString()??``),[k,A]=(0,m.useState)(()=>U1(i?.items??[])),[j,M]=(0,m.useState)(i?.topicKeyword??null),[ee,N]=(0,m.useState)(i?.values??{}),[P,F]=(0,m.useState)(i?.brief??``),[te,ne]=(0,m.useState)(i?.topicGeneration??OV),[re,ie]=(0,m.useState)((i?.releases??[]).length===0?null:i?.releases??null),[ae,oe]=(0,m.useState)(!1),[se,ce]=(0,m.useState)(!1),le=(0,m.useRef)(!1),ue=(0,m.useRef)(null),de=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,fe=de.find(e=>e.id===d),pe=I({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await uq(c,d);if(!e.ok)throw Error(e.message);return e.value}}),me=pe.data?.document.form,he=me===void 0?void 0:F1({form:me,prompts:pe.data?.document.librarySnapshot?.prompts??[],entries:pe.data?.document.librarySnapshot?.entries??[]}),ge=me===void 0?[]:RK(me),_e=j!==null&&ge.includes(j)?j:ge.find(e=>me?.title.includes(`{{${e}}}`))??ge[0]??null,ve=Object.fromEntries(ge.filter(e=>e!==_e).map(e=>[e,ee[e]??me?.values[e]??``])),ye={keywords:ge,topicKeyword:_e,everyRun:ve,form:me,kept:i?.items??[],...he===void 0?{}:{origins:he}},be=K1(k,ye),xe=p===`weekly`?x:p===`daily`?[0,1,2,3,4,5,6]:[],Se=me!==void 0&&me.sources.audio!==`off`&&me.shorts?.enabled===!0?Math.max(0,Math.min(10,Number(me.shorts.count)||0)):0;async function Ce(e){if(e.preventDefault(),!(le.current||t)){if(!fe&&!ue.current){r(`Choose a template before saving the schedule.`);return}if(!ue.current&&be.problems.length>0){r(`Fix the topics first. ${be.problems.slice(0,3).join(` `)}`);return}if(be.rows.length>500){r(`Keep the list to 500 topics or fewer.`);return}if(P.trim().length>4e3){r(`Keep the series brief to ${String(EV)} characters or fewer.`);return}if(te.llm!==null&&(te.llm.provider===``||te.llm.model===``)){r(`Pick both a provider and a model for topic generation, or choose Use the template's LLM.`);return}if(p===`weekly`&&x.length===0){r(`Choose at least one weekday for a weekly schedule.`);return}le.current=!0,oe(!0),s(!0);try{if(!ue.current){if(!fe)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!vV(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Qde(_,e)}:p===`weekly`?{kind:p,time:y,days:x}:{kind:p,time:y},n=D.trim()===``?null:Number(D);if(n!==null&&(!Number.isInteger(n)||n<0))throw Error(`Enter the spend limit as a whole number of cents, 0 or more (500 is $5.00), or leave it empty.`);let r={id:i?.id??crypto.randomUUID(),name:l.trim(),templateId:fe.id,templateVersion:fe.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:be.rows,topicKeyword:_e,values:ve,brief:P.trim()===``?null:P.trim(),topicGeneration:te,releases:re===null||p===`once`?[]:R1(re,xe,Se)};ue.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=ue.current,{id:t,...a}=e,o=`mutationId`in a?await XV(c,t,a):await YV(c,e);if(!o.ok){ue.current=null,ce(!1),r(o.reason===`conflict`?`${o.message} Your inputs are kept here. To load the latest saved version, cancel editing and press Edit again.`:o.message);return}ue.current=null,ce(!1),u(``),A(U1([])),n()}catch(e){ce(ue.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{le.current=!1,oe(!1),s(ue.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(aI,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{onSubmit:e=>void Ce(e),children:[(0,h.jsxs)(`fieldset`,{disabled:ae||se||t,className:`m-0 grid min-w-0 gap-4 border-0 p-0 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,children:(0,h.jsx)(zB,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(LB,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,children:(0,h.jsxs)(VB,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:de.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),de.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(LB,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(VB,{value:p,onChange:e=>g(e.target.value===`once`?`once`:e.target.value===`weekly`?`weekly`:`daily`),children:[(0,h.jsx)(`option`,{value:`daily`,children:`Every day`}),(0,h.jsx)(`option`,{value:`weekly`,children:`Selected weekdays`}),(0,h.jsx)(`option`,{value:`once`,children:`One time`})]})}),p===`once`?(0,h.jsx)(LB,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,children:(0,h.jsx)(zB,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(LB,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,children:(0,h.jsx)(zB,{required:!0,type:`time`,value:y,onChange:e=>b(e.target.value)})}),p===`weekly`?(0,h.jsxs)(`fieldset`,{className:`m-0 min-w-0 border-0 p-0`,...zb,children:[(0,h.jsxs)(`legend`,{className:`sl-field__label mb-2 flex items-center gap-1`,children:[`Weekdays`,(0,h.jsx)(U,{id:`planning.schedule.weekdays`,className:`-my-1`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Hfe.map(([e,t])=>(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),onChange:t=>S(n=>t.target.checked?[...n,e]:n.filter(t=>t!==e))}),t]},e))})]}):(0,h.jsx)(`div`,{}),(0,h.jsx)(LB,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,children:(0,h.jsx)(zB,{value:C,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(LB,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(VB,{value:T,onChange:e=>E(e.target.value===`run-once`?`run-once`:`skip`),children:[(0,h.jsx)(`option`,{value:`skip`,children:`Skip if Slopify was closed`}),(0,h.jsx)(`option`,{value:`run-once`,children:`Run once when Slopify reopens`})]})}),(0,h.jsx)(LB,{label:`Spend ceiling (cents, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,children:(0,h.jsx)(zB,{inputMode:`numeric`,value:D,onChange:e=>O(e.target.value),placeholder:`1000`})}),(0,h.jsx)(Bfe,{queue:k,onQueue:A,context:ye,onKeyword:M,onValue:(e,t)=>N(n=>({...n,[e]:t})),loading:d!==``&&pe.isPending,exportName:l}),(0,h.jsx)(Rfe,{releases:re,onReleases:ie,runDays:xe,shorts:Se,once:p===`once`,timezone:C}),(0,h.jsx)(Wfe,{brief:P,onBrief:F,generation:te,onGeneration:ne,templateLlm:me?.llm})]}),(0,h.jsxs)(`div`,{className:`sticky bottom-0 z-10 mt-6 flex flex-wrap gap-2 border-t border-line bg-ground py-3 max-md:bottom-[68px]`,children:[(0,h.jsx)(B,{type:`submit`,variant:`primary`,disabled:t||ae||de.length===0&&!se,children:ae?`Saving…`:se?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(B,{variant:`quiet`,disabled:ae||se,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Wfe({brief:e,onBrief:t,generation:n,onGeneration:r,templateLlm:i}){let{api:a}=V(),o=I({...db(a),enabled:n.mode!==`off`}),s=n.llm;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topic generation`,(0,h.jsx)(U,{id:`planning.schedule.generation`})]}),(0,h.jsx)(LB,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,children:(0,h.jsx)(BB,{rows:3,maxLength:EV,value:e,onChange:e=>t(e.target.value),placeholder:`Ancient history, documentary style. Famous rulers and places first.`})}),(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,children:(0,h.jsxs)(VB,{value:n.mode,onChange:e=>{let t=e.target.value;r({...n,mode:t===`queue`||t===`hold`?t:`off`})},children:[(0,h.jsx)(`option`,{value:`off`,children:`Off: add topics yourself`}),(0,h.jsx)(`option`,{value:`queue`,children:`Generate and queue directly`}),(0,h.jsx)(`option`,{value:`hold`,children:`Generate and hold for approval`})]})}),n.mode===`off`?null:(0,h.jsx)(LB,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(zB,{type:`number`,min:1,max:100,value:String(n.keepAtLeast),onChange:e=>{let t=Math.round(Number(e.target.value));r({...n,keepAtLeast:Number.isFinite(t)?Math.min(100,Math.max(1,t)):1})}})})]}),n.mode===`off`?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s===null,onChange:e=>r({...n,llm:e.target.checked?null:{provider:i?.provider??``,model:i?.model??``}})}),`Use the template's LLM`,s===null&&i!==void 0&&i.provider!==``?` (${i.provider} · ${i.model})`:``]}),(0,h.jsx)(U,{id:`planning.schedule.generation-llm`,className:`-my-1`})]}),s===null?null:(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Provider`,family:`llm`,providers:o.data?.providers??[],value:s.provider,problem:o.error?.message,onPick:e=>r({...n,llm:{provider:e,model:``}})}),(0,h.jsx)(tV,{label:`Model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>r({...n,llm:{...s,model:e}})})]})]})]})}function Gfe({schedule:e}){let{api:t}=V(),n=_(),r=Ry(),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(!1),c=(0,m.useRef)(!1),[l,u]=(0,m.useState)(``),d=(0,m.useRef)(e);e.version>d.current.version&&(d.current=e);let f=d.current.items,p=e.topicKeyword===null?`title`:`{{${e.topicKeyword}}}`,g=async(e,i,o)=>{if(c.current)return!1;c.current=!0;let l=d.current;s(!0),a(null);try{let s=await uH(t,l.id,{baseVersion:l.version,items:e});return s.ok?(d.current=s.value,n.setQueryData(KV,e=>e?.map(e=>e.id===s.value.id?s.value:e)),n.invalidateQueries({queryKey:fH}),r(i,`success`,o?{label:`Undo`,run:()=>void g(l.items,`Put the topics back as they were.`,!1)}:void 0),!0):(a(s.reason===`conflict`?`The topics weren't saved: this schedule changed since the page loaded, possibly because a run just took a topic. The list now shows the latest; make your change again.`:`The topics weren't saved: ${s.message}`),await n.invalidateQueries({queryKey:KV}),!1)}catch(e){return a(`The topics weren't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then try again.`),!1}finally{c.current=!1,s(!1)}},v=async e=>{e.preventDefault();let t=l.trim();if(t===``){a(`Write the new topic's ${p} first, then press Add topic.`);return}await g([...f,{title:t,values:{}}],`Added “${t}”.`,!0)&&u(``)},y=(e,t)=>{let n=f[e];if(n!==void 0&&t.trim()!==n.title){if(t.trim()===``){a(`Topic ${String(e+1)} needs a ${p}. Write one, or press its Remove button.`);return}g(f.map((n,r)=>r===e?{...n,title:t.trim()}:n),`Renamed to “${t.trim()}”.`,!0)}},b=(e,t)=>{let n=f[e];if(n===void 0)return;let r=[...f];r.splice(e,1),r.splice(e+t,0,n),g(r,`Moved “${n.title}” ${t===-1?`up`:`down`}.`,!0)},x=e=>{let t=f[e];t!==void 0&&g(f.filter((t,n)=>n!==e),`Removed “${t.title}”.`,!0)};return(0,h.jsxs)(`section`,{"aria-label":`Queued topics`,className:`mt-6`,...zb,children:[(0,h.jsx)(W,{as:`h3`,title:`Queued topics · ${String(f.length)}`,info:`planning.schedule.inline-topics`,meta:e.topicKeyword===null?`Each topic becomes the next project's title.`:`Each topic fills ${p}; the next run takes the first.`}),i===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:i}),f.length===0?null:(0,h.jsx)(PH,{label:`Topics of ${e.name}`,className:`mt-2`,children:f.map((e,t)=>(0,h.jsx)(Kfe,{index:t,title:e.title,count:f.length,busy:o,onRename:e=>y(t,e),onMove:e=>b(t,e),onRemove:()=>x(t)},`${String(t)}:${e.title}`))}),(0,h.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-center gap-2`,onSubmit:e=>void v(e),children:[(0,h.jsx)(zB,{"aria-label":`New topic`,placeholder:e.topicKeyword===null?`New topic`:`New ${p}`,maxLength:200,value:l,className:`min-w-0 flex-1`,onChange:e=>u(e.target.value)}),(0,h.jsxs)(B,{type:`submit`,size:`small`,disabled:o||f.length>=500,disabledReason:o?`Saving the last change`:`A queue holds at most 500 topics`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]})]})]})}function Kfe({index:e,title:t,count:n,busy:r,onRename:i,onMove:a,onRemove:o}){let[s,c]=(0,m.useState)(t);(0,m.useEffect)(()=>c(t),[t]);let l=`Topic ${String(e+1)}`;return(0,h.jsx)(FH,{lead:(0,h.jsx)(`span`,{className:`w-6 text-small text-ink-3 tabular-nums`,children:e+1}),title:(0,h.jsx)(zB,{"aria-label":l,maxLength:200,value:s,onChange:e=>c(e.target.value),onBlur:()=>i(s),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i(s)):e.key===`Escape`&&c(t)}}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Py,{size:`small`,label:`Move ${t} up`,disabled:r||e===0,onClick:()=>a(-1),children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{size:`small`,label:`Move ${t} down`,disabled:r||e===n-1,onClick:()=>a(1),children:(0,h.jsx)(mc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{size:`small`,label:`Remove ${t}`,disabled:r,onClick:o,children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function qfe({pickedId:e,onPick:t}={}){let{api:n}=V(),r=_(),i=I(qV(n)),a=I(lq(n)),[o,s]=(0,m.useState)(null),c=Ry(),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(null),b=t===void 0?v:e??null,x=e=>{t===void 0?y(e):t(e)},[S,C]=(0,m.useState)(null),w=(0,m.useRef)(!1),T=I(cx(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=I(pH(n,E.from,E.to)),O=new Map;for(let e of D.data?.runs??[])e.renderedTitle!==null&&!O.has(e.scheduleId)&&O.set(e.scheduleId,e.renderedTitle);let[k,A]=(0,m.useState)(``),j=e=>{if(k===``)return!0;let t=a.data?.find(t=>t.id===e.templateId);return(t?E1(t):tx)===k},M=i.data?.filter(e=>e.deletedAt===null&&j(e))??[],ee=i.data?.filter(e=>e.deletedAt!==null)??[],N=i.data?.find(e=>e.id===b)??M[0]??null,P=L({onError:e=>s(e.message),onSettled:async()=>{w.current=!1,await r.invalidateQueries({queryKey:KV})},mutationFn:async e=>e(),onSuccess:async e=>{if(!e.ok){s(e.message);return}s(null)}}),F=e=>{w.current||(w.current=!0,s(null),P.mutate(e))},te=d||l!==null,ne=()=>{u(null),f(!1),s(null)},re=a.data?.length===0,ie=()=>{te||re||(u(null),f(!0),s(null))},ae=e=>{f(!1),x(e.id),u(e),s(null)};jx({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:ie}),oS(tS.newSchedule,()=>{re?c(`A schedule runs a project template, and there is none yet. Open a project, choose Save as template, then run New schedule again.`,`error`):ie()},a.data!==void 0);let oe=o?{tone:`error`,text:o}:i.error?{tone:`error`,text:`The schedules couldn't be loaded: ${i.error.message} Reload the page to try again.`}:a.error?{tone:`error`,text:`The templates couldn't be loaded: ${a.error.message} Reload the page to try again.`}:void 0,se=P.isPending||p||te;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 min-w-0 text-small text-ink-2`,children:re?(0,h.jsxs)(h.Fragment,{children:[`Save a template in`,` `,(0,h.jsx)(fa,{className:`underline`,to:`/templates`,children:`Library → Templates`}),` `,`before creating a schedule.`]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Runs a saved template on this machine at a local time.`,(0,h.jsx)(U,{id:`planning.schedules`})]})}),(0,h.jsxs)(Iy,{children:[(0,h.jsxs)(VB,{"aria-label":`Filter schedules by channel`,value:k,className:`w-auto min-w-[160px]`,onChange:e=>A(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(T.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsxs)(B,{variant:`primary`,onClick:ie,disabled:te||re,disabledReason:re?`Save a template in Library → Templates first`:`Finish or cancel the open form first`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New schedule`]})]})]}),(0,h.jsx)(v1,{tone:te?`info`:oe?.tone??`info`,className:`mb-2`,children:te?void 0:oe?.text}),(0,h.jsx)(QK,{className:`min-[768px]:grid-cols-[minmax(320px,460px)_minmax(0,1fr)]`,list:(0,h.jsxs)(h.Fragment,{children:[i.data&&M.length===0?(0,h.jsx)(T1,{title:k===``?ee.length===0?`No schedules yet`:`No active schedules`:`No schedules run this channel's templates`,children:k===``?ee.length===0?`Your first one can be a one-off run or a recurring series. Press New schedule.`:`Create one with New schedule, or review deleted history below.`:`Pick All channels to see the others, or make one from this channel's templates.`}):null,M.length>0?(0,h.jsx)(PH,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:M.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(J1,{schedule:e,nextTitle:O.get(e.id),selected:!te&&N?.id===e.id,pending:se,onSelect:()=>x(e.id),onEdit:()=>ae(e),onAction:F,onConfirm:t=>C({kind:t,schedule:e})}),(0,h.jsx)(O1,{kind:`schedule`,id:e.id,name:e.name})]},e.id))}):null,ee.length>0?(0,h.jsxs)(`details`,{className:`mt-6`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-small font-semibold text-ink-2`,children:[`Deleted schedules · `,ee.length]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 mb-2 text-small text-ink-2`,children:`Deleted schedules stay in Settings → Trash for 30 days, where Restore brings one back paused. Pick one to see its run history.`}),(0,h.jsx)(PH,{label:`Deleted schedules`,children:ee.map(e=>(0,h.jsx)(J1,{schedule:e,nextTitle:void 0,selected:!te&&N?.id===e.id,pending:!1,onSelect:()=>x(e.id),onEdit:()=>void 0,onAction:F,onConfirm:()=>void 0},e.id))})]}):null]}),detail:te?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{kicker:l?l.name:void 0,title:l?`Edit schedule`:`New schedule`,className:`mb-4`}),(0,h.jsx)(Ufe,{onBusy:g,editing:l,onCancel:()=>{p||ne()},templates:a.data??[],pending:P.isPending,error:o,onCreated:()=>{c(l?`Schedule updated.`:`Schedule saved. It will run automatically while Slopify is open.`,`success`),ne(),r.invalidateQueries({queryKey:KV})},onError:e=>{s(e),r.invalidateQueries({queryKey:KV})}},l?.id??`new`)]}):N?(0,h.jsx)(Zfe,{schedule:N,pending:se,onAction:F,onConfirm:e=>C({kind:e,schedule:N})},N.id):null}),(0,h.jsx)(Hy,{open:S!==null,title:S?.kind===`delete`?`Delete schedule?`:`Cancel schedule?`,consequence:(S?.kind===`delete`?`Moves this schedule to the trash for 30 days (Settings → Trash). Its run history is kept.`:`Stops future scheduled runs. Existing projects and run history are kept.`)+(o?` ${o}`:``),confirmLabel:S?.kind===`delete`?`Delete schedule`:`Cancel schedule`,cancelLabel:`Keep schedule`,pending:P.isPending,onCancel:()=>{P.isPending||C(null)},onConfirm:()=>{if(!S)return;let{kind:e,schedule:t}=S;F(async()=>{let r=e===`delete`?await QV(n,t.id,t.version):await ZV(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}function Jfe(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}var Yfe={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Xfe={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function q1({schedule:e}){return e.deletedAt===null?(0,h.jsx)(OS,{tone:Xfe[e.status],children:Yfe[e.status]}):(0,h.jsx)(OS,{tone:`off`,children:`Deleted`})}function J1({schedule:e,nextTitle:t,selected:n,pending:r,onSelect:i,onEdit:a,onAction:o,onConfirm:s}){let{api:c}=V(),l=e.deletedAt===null,u=l&&(e.status===`active`||e.status===`paused`),d=e.status===`canceled`||e.status===`completed`;return(0,h.jsx)(FH,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(q1,{schedule:e}),` · ${Jfe(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${a1(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${a1(e.deletedAt,e.timezone)}`}${e.topics.held>0?` · ${String(e.topics.held)} waiting for you`:``}`]}),actions:l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,disabled:r||!u,disabledReason:u?`Finish or cancel the open form first`:`Only a live schedule can change`,onClick:a,children:`Edit`}),e.status===`paused`?(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Resume ${e.name}`,disabled:r,onClick:()=>o(()=>ZV(c,e.id,`resume`,e.version)),children:`Resume`}):(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Pause ${e.name}`,disabled:r||e.status!==`active`,disabledReason:`Only an active schedule can pause`,onClick:()=>o(()=>ZV(c,e.id,`pause`,e.version)),children:`Pause`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,disabled:r||!d,disabledReason:`Cancel the schedule first; a completed or canceled one can be deleted`,onClick:()=>s(`delete`),children:`Delete`})]}):void 0})}function Zfe({schedule:e,pending:t,onAction:n,onConfirm:r}){let{api:i}=V(),a=I({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await JV(i,e.id);if(!t.ok)throw Error(t.message);return t.value},refetchInterval:3e4}),o=e.deletedAt===null,s=o&&(e.status===`active`||e.status===`paused`),c=e.status===`paused`,l=[[`When`,e.cadence.kind===`once`?`Once, ${a1(e.cadence.at,e.timezone)}`:e.cadence.kind===`daily`?`Every day at ${e.cadence.time}`:`Selected weekdays at ${e.cadence.time}`],[`Timezone`,e.timezone],[`Next run`,e.deletedAt!==null||e.nextRunAt===null?`None`:a1(e.nextRunAt,e.timezone)],[`Topics`,e.items.length===0?e.topicGeneration.mode===`off`?`Template as saved`:`No topics queued`:`${String(e.items.length)} ${e.items.length===1?`topic`:`topics`} left`],[`Missed runs`,e.missedPolicy===`skip`?`Skip`:`Run once on reopening`],[`Overlap`,`Skip`],[`Spend ceiling`,e.spendLimitCents===null?`Not set`:`${String(e.spendLimitCents)} cents`]];return(0,h.jsxs)(`section`,{"aria-label":`${e.name} detail`,children:[o&&s?(0,h.jsx)(Qfe,{schedule:e,paused:c,onAction:n}):null,(0,h.jsx)(W,{kicker:(0,h.jsx)(q1,{schedule:e}),title:e.name,meta:e.topics.held>0?`${String(e.topics.held)} topics waiting for you`:void 0,children:o?(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Cancel ${e.name}`,disabled:t||!s,disabledReason:`Only an active or paused schedule can be canceled`,onClick:()=>r(`cancel`),children:`Cancel schedule`}):null}),(0,h.jsx)(`dl`,{className:`m-0 mt-4 grid grid-cols-1 gap-x-6 gap-y-3 text-small min-[600px]:grid-cols-2`,children:l.map(([e,t])=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`dt`,{className:`sl-kicker`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-words text-ink`,children:t})]},e))}),s?(0,h.jsx)(Gfe,{schedule:e}):null,(0,h.jsx)(yfe,{schedule:e}),(0,h.jsx)($K,{className:`my-6`}),(0,h.jsx)(W,{as:`h3`,title:`Run history`}),(0,h.jsx)(`div`,{className:`mt-3`,children:a.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading history…`}):a.error?(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The run history couldn't be loaded: ${a.error.message} It tries again every 30 seconds.`}):a.data.runs.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No runs yet.`}):(0,h.jsx)(PH,{label:`Runs of ${e.name}`,children:a.data.runs.map(t=>(0,h.jsx)(FH,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${a1(t.scheduledFor,e.timezone)}`}),meta:t.error?t.error:t.projectIds.length>0?(0,h.jsx)(`span`,{className:`inline-flex flex-wrap gap-x-3`,children:t.projectIds.map((e,t)=>(0,h.jsxs)(fa,{className:`underline hover:text-ink`,to:`/projects/$projectId`,params:{projectId:e},children:[`Project `,t+1]},e))}):`No projects`},t.id))})})]})}function Qfe({schedule:e,paused:t,onAction:n}){let{api:r}=V();return jx({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>ZV(r,e.id,t?`resume`:`pause`,e.version))}),null}var Y1=`https://www.youtube.com/upload`,$fe=[`video`,`title`,`description`,`thumbnails`,`playlist`,`audience`,`altered`,`tags`,`schedule`];function epe(e){return e.join(`, `)}var tpe=[.75,1,1.25,1.5,1.75,2];function X1(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0,n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function Z1(e){return`${String(e)}×`}function npe(e,t){return e.filter(e=>e.start<=t).at(-1)}function Q1(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var $1=(e,t,n)=>Math.min(n,Math.max(t,e));function e0(){let e=(0,m.useRef)(null),t=(0,m.useId)(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(0),[c,l]=(0,m.useState)(0),[u,d]=(0,m.useState)(1),[f,p]=(0,m.useState)(!1),[h,g]=(0,m.useState)(1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(null),[x,S]=(0,m.useState)(!1),C=Number.isFinite(o)&&o>0,w=()=>{let t=e.current;t!==null&&(t.paused||t.ended?t.play()?.catch(()=>void 0):t.pause())},T=t=>{let n=e.current;if(n===null||!C)return;let r=$1(t,0,o);n.currentTime=r,a(r)},E=t=>T((e.current?.currentTime??i)+t),D=t=>{let n=e.current;if(n===null)return;let r=$1(Math.round(t*100)/100,0,1);n.volume=r,n.muted=r===0,d(r),p(r===0)},O=()=>{let t=e.current;t!==null&&(t.muted=!t.muted,p(t.muted))};return{media:e,menuId:t,playing:n,current:i,duration:o,buffered:c,known:C,volume:u,muted:f,rate:h,menu:_,setMenu:v,hover:y,setHover:b,seeking:x,setSeeking:S,toggle:w,seekTo:T,jump:E,setLevel:D,toggleMute:O,pickRate:n=>{let r=e.current;r!==null&&(r.playbackRate=n),g(n),v(!1),document.getElementById(`${t}-button`)?.focus()},keyAction:e=>{let t=e.length===1?e.toLowerCase():e;if(t===` `||t===`k`)return w;if(t===`j`)return()=>E(-10);if(t===`l`)return()=>E(10);if(t===`ArrowLeft`)return()=>E(-5);if(t===`ArrowRight`)return()=>E(5);if(t===`m`)return O;if(/^[0-9]$/.test(t))return()=>T(Number(t)/10*o)},events:{onPlay:()=>r(!0),onPause:()=>r(!1),onEnded:()=>r(!1),onTimeUpdate:e=>{x||a(e.currentTarget.currentTime)},onDurationChange:e=>s(e.currentTarget.duration),onLoadedMetadata:e=>s(e.currentTarget.duration),onProgress:e=>{let t=e.currentTarget.buffered;l(t.length>0?t.end(t.length-1):0)},onVolumeChange:e=>{d(e.currentTarget.volume),p(e.currentTarget.muted)},onRateChange:e=>g(e.currentTarget.playbackRate)}}}function t0(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:$1((t-n.left)/n.width,0,1)}function n0(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function r0({controls:e,className:t}){return(0,h.jsx)(Py,{size:`small`,label:e.playing?`Pause`:`Play`,className:t,onClick:e.toggle,children:e.playing?(0,h.jsx)(Hc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})}function i0({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:X1(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?X1(e.duration):`-:--`}`})]})}function a0({controls:e,chapters:t=[],waveform:n}){let r=(0,m.useRef)(null),{known:i,duration:a,current:o,buffered:s,seeking:c,hover:l}=e,u=ape(r),d=n===void 0?void 0:ipe(n,u),f=i?t.filter(e=>e.start>0&&e.start<a):[],p=t=>{i&&(t.currentTarget.setPointerCapture?.(t.pointerId),e.setSeeking(!0),e.seekTo(t0(r.current,t.clientX)*a))},g=t=>{let n=t0(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{n0(t,{ArrowLeft:()=>e.jump(-5),ArrowDown:()=>e.jump(-5),ArrowRight:()=>e.jump(5),ArrowUp:()=>e.jump(5),PageDown:()=>e.jump(-10),PageUp:()=>e.jump(10),Home:()=>e.seekTo(0),End:()=>e.seekTo(a)}[t.key])},y=i?o/a*100:0,b=i?s/a*100:0,x=l===null||!i?void 0:l*a,S=x===void 0?void 0:npe(t,x);return(0,h.jsxs)(`div`,{ref:r,role:`slider`,tabIndex:0,"aria-label":`Seek`,"aria-valuemin":0,"aria-valuemax":i?Math.floor(a):0,"aria-valuenow":Math.floor(o),"aria-valuetext":`${X1(o)} of ${i?X1(a):`unknown length`}`,"aria-disabled":!i,className:`sl-player__track`,onPointerDown:p,onPointerMove:g,onPointerUp:_,onPointerCancel:_,onPointerLeave:()=>e.setHover(null),onKeyDown:v,children:[d===void 0||d.length===0?(0,h.jsxs)(`span`,{className:`sl-player__rail`,children:[(0,h.jsx)(`span`,{className:`sl-player__buffered`,style:{width:`${String(b)}%`}}),(0,h.jsx)(`span`,{className:`sl-player__played`,style:{width:`${String(y)}%`}})]}):(0,h.jsx)(`span`,{className:`sl-player__wave`,"data-slot":`waveform`,"aria-hidden":`true`,children:d.map((e,t)=>(0,h.jsx)(`span`,{className:`sl-player__peak`,"data-played":(t+.5)/d.length*100<=y?``:void 0,style:{height:`${String(Math.max(12,Math.round(e*100)))}%`}},t))}),f.map(e=>(0,h.jsx)(`span`,{className:`sl-player__mark`,"data-chapter":e.title,title:e.title,style:{left:`${String(e.start/a*100)}%`}},`${String(e.start)}-${e.title}`)),(0,h.jsx)(`span`,{className:`sl-player__knob`,style:{left:`${String(y)}%`}}),x===void 0||l===null?null:(0,h.jsxs)(`span`,{className:`sl-player__tip`,"aria-hidden":`true`,style:{left:`${String(l*100)}%`},children:[S===void 0?null:(0,h.jsx)(`span`,{className:`sl-player__tip-title`,children:S.title}),X1(x)]})]})}function o0({controls:e}){let t=(0,m.useRef)(null),{muted:n,volume:r}=e,i=n?0:r;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Py,{size:`small`,label:n?`Unmute`:`Mute`,"aria-pressed":n,className:`sl-player__mute`,onClick:e.toggleMute,children:n||r===0?(0,h.jsx)(il,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(rl,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(`div`,{ref:t,role:`slider`,tabIndex:0,"aria-label":`Volume`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(i*100),"aria-valuetext":n?`Muted`:`${String(Math.round(i*100))}%`,className:`sl-player__volume`,onPointerDown:n=>{n.currentTarget.setPointerCapture?.(n.pointerId),e.setLevel(t0(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel(t0(t.current,n.clientX))},onKeyDown:t=>{let n={ArrowLeft:i-.05,ArrowDown:i-.05,ArrowRight:i+.05,ArrowUp:i+.05,Home:0,End:1}[t.key];n0(t,n===void 0?void 0:()=>e.setLevel(n))},children:(0,h.jsx)(`span`,{className:`sl-player__rail`,children:(0,h.jsx)(`span`,{className:`sl-player__played`,style:{width:`${String(i*100)}%`}})})})]})}function s0({controls:e}){let{menuId:t,menu:n,rate:r}=e;return(0,h.jsxs)(`span`,{className:`sl-player__speed`,children:[(0,h.jsx)(B,{id:`${t}-button`,variant:`quiet`,size:`small`,className:`sl-player__rate`,"aria-label":`Playback speed, ${Z1(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:Z1(r)}),n?(0,h.jsx)(`div`,{id:`${t}-menu`,role:`menu`,"aria-label":`Playback speed`,className:`sl-player__menu`,onKeyDown:n=>{if(n.key===`Escape`){n0(n,()=>{e.setMenu(!1),document.getElementById(`${t}-button`)?.focus()});return}if(n.key!==`ArrowDown`&&n.key!==`ArrowUp`)return;let r=[...n.currentTarget.querySelectorAll(`[role=menuitemradio]`)],i=r[(r.indexOf(document.activeElement)+(n.key===`ArrowDown`?1:-1)+r.length)%r.length];n0(n,()=>i?.focus())},children:tpe.map(t=>(0,h.jsx)(B,{variant:`quiet`,size:`small`,role:`menuitemradio`,"aria-checked":t===r,className:z(`sl-player__option`),autoFocus:t===r,onClick:()=>e.pickRate(t),children:t===1?`Normal`:Z1(t)},t))}):null]})}var rpe=4;function ipe(e,t){let n=Math.floor(t/rpe);if(n<=0||e.length<=n)return e;let r=[];for(let t=0;t<n;t+=1){let i=Math.floor(t*e.length/n),a=Math.max(i+1,Math.floor((t+1)*e.length/n));r.push(Math.max(...e.slice(i,a)))}return r}function ape(e){let[t,n]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let t=e.current;if(t===null||(n(t.clientWidth),typeof ResizeObserver>`u`))return;let r=new ResizeObserver(()=>n(t.clientWidth));return r.observe(t),()=>r.disconnect()},[e]),t}var ope=2500;function c0({src:e,poster:t,label:n,portrait:r=!1,square:i=!1,captions:a,chapters:o=[],ref:s,className:c,children:l}){let u=e0(),d=u.media,f=(0,m.useRef)(null),p=(0,m.useRef)(void 0),[g,_]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(0),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(!1),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(!0),{playing:A,menu:j,seeking:M,hover:ee,events:N}=u,P=a!==void 0||b>0,F=typeof document<`u`&&`pictureInPictureEnabled`in document&&document.pictureInPictureEnabled===!0,te=(0,m.useCallback)(()=>{k(!0),clearTimeout(p.current),p.current=setTimeout(()=>k(!1),ope)},[]);(0,m.useEffect)(()=>()=>clearTimeout(p.current),[]);let ne=A&&!O&&!j&&!E&&!M&&ee===null;(0,m.useEffect)(()=>{let e=()=>C(document.fullscreenElement===f.current);return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,m.useEffect)(()=>{let e=d.current;if(e===null)return;let t=()=>T(!0),n=()=>T(!1);return e.addEventListener(`enterpictureinpicture`,t),e.addEventListener(`leavepictureinpicture`,n),()=>{e.removeEventListener(`enterpictureinpicture`,t),e.removeEventListener(`leavepictureinpicture`,n)}},[d]),(0,m.useEffect)(()=>{let e=d.current?.textTracks;if(e!==void 0)for(let t=0;t<e.length;t+=1){let n=e[t];n!==void 0&&(n.mode=v&&t===0?`showing`:`hidden`)}},[v,d]);let re=()=>{let e=d.current;e!==null&&(e.paused||e.ended)&&_(!0),u.toggle()},ie=()=>{let e=f.current;e!==null&&(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()?.catch(()=>void 0))},ae=()=>{let e=d.current;e!==null&&(document.pictureInPictureElement===e?document.exitPictureInPicture?.().catch(()=>void 0):e.requestPictureInPicture?.().catch(()=>void 0))};return(0,h.jsxs)(`div`,{ref:f,"data-slot":`player`,"data-state":A?`playing`:`paused`,className:z(`sl-player`,r&&`sl-player--portrait`,i&&`sl-player--square`,ne&&`sl-player--bare`,S&&`sl-player--full`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target.closest(`button`)!==null,n=e.key.length===1?e.key.toLowerCase():e.key,r=n===` `&&t?void 0:n===` `||n===`k`?re:n===`f`?ie:n===`c`?P?()=>y(e=>!e):void 0:u.keyAction(n);r!==void 0&&(e.preventDefault(),e.stopPropagation(),te(),r())},onPointerMove:te,onPointerDown:te,onFocus:()=>D(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(D(!1),u.setMenu(!1))},children:[(0,h.jsxs)(`video`,{ref:Q1(d,s),src:e,poster:t,preload:`metadata`,playsInline:!0,"aria-label":n,onClick:re,...N,onPlay:e=>{N.onPlay(e),_(!0),te()},onPause:e=>{N.onPause(e),k(!0)},onEnded:e=>{N.onEnded(e),k(!0)},onLoadedMetadata:e=>{N.onLoadedMetadata(e),x(e.currentTarget.textTracks?.length??0)},children:[a===void 0?null:(0,h.jsx)(`track`,{kind:`captions`,src:a.src,srcLang:a.lang,label:a.label}),l]}),g?null:(0,h.jsx)(Py,{label:`Play ${n}`,className:`sl-player__big`,onClick:re,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsxs)(`div`,{className:`sl-player__bar`,role:`group`,"aria-label":`${n} controls`,children:[(0,h.jsx)(r0,{controls:{...u,toggle:re}}),(0,h.jsx)(i0,{controls:u}),(0,h.jsx)(a0,{controls:u,chapters:o}),(0,h.jsx)(o0,{controls:u}),(0,h.jsx)(s0,{controls:u}),P?(0,h.jsx)(Py,{size:`small`,label:`Captions`,"aria-pressed":v,onClick:()=>y(e=>!e),children:(0,h.jsx)(xc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,F?(0,h.jsx)(Py,{size:`small`,label:`Picture in picture`,"aria-pressed":w,className:`sl-player__pip`,onClick:ae,children:(0,h.jsx)(Wc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Py,{size:`small`,label:S?`Exit full screen`:`Full screen`,"aria-pressed":S,onClick:ie,children:S?(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})]})}var spe={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function l0({src:e,alt:t,kind:n=`image`,poster:r,aspect:i=`landscape`,title:a,meta:o,badge:s,actions:c,actionsShown:l=!1,generating:u,onOpen:d,openLabel:f,className:p}){let m=u==null||u===!1;return(0,h.jsxs)(`figure`,{className:z(`sl-media m-0`,p),"data-slot":`media-frame`,children:[(0,h.jsxs)(`div`,{className:z(`sl-media__frame`,spe[i]),children:[m&&e!==void 0?n===`video`?(0,h.jsx)(`video`,{src:e,poster:r,muted:!0,preload:`metadata`,"aria-label":t}):(0,h.jsx)(`img`,{src:e,alt:t,loading:`lazy`,decoding:`async`}):null,m?null:(0,h.jsxs)(`div`,{className:`sl-media__generating`,role:`status`,children:[(0,h.jsx)(DS,{tone:`running`}),(0,h.jsx)(`span`,{children:u})]}),s===void 0?null:(0,h.jsx)(`span`,{className:`sl-media__badge`,children:s}),c===void 0?null:(0,h.jsx)(`div`,{className:z(`sl-media__actions`,l&&`sl-media__actions--shown`),children:c})]}),d!==void 0&&m&&e!==void 0?(0,h.jsx)(`button`,{type:`button`,className:`sl-media__open`,"aria-label":f??`Open ${t} full size`,onClick:d}):null,a===void 0&&o===void 0?null:(0,h.jsxs)(`figcaption`,{className:`sl-media__caption`,children:[a===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`strong`,{className:`min-w-0 truncate`,children:a}),o===void 0?null:(0,h.jsx)(`span`,{className:`shrink-0`,children:o})]})]})}function u0({shorts:e=!1,density:t=`default`,list:n=!1,className:r,children:i,label:a}){let o=z(`sl-grid`,e&&`sl-grid--shorts`,t===`compact`&&`sl-grid--compact`,n&&`m-0 list-none p-0`,r);return n?(0,h.jsx)(`ul`,{"aria-label":a,className:o,"data-slot":`media-grid`,children:i}):(0,h.jsx)(`section`,{"aria-label":a,className:o,"data-slot":`media-grid`,children:i})}function d0({items:e,index:t,onIndex:n,onClose:r,actions:i}){let a=t===null?void 0:e[t],o=e.length,s=e=>{t!==null&&o!==0&&n((t+e+o)%o)};return(0,h.jsx)(Nm,{open:a!==void 0,onOpenChange:e=>{e||r()},children:(0,h.jsx)(Lm,{children:(0,h.jsx)(Um,{className:`sl-lightbox sl-enter`,onKeyDown:e=>{e.key===`ArrowRight`?(e.preventDefault(),s(1)):e.key===`ArrowLeft`&&(e.preventDefault(),s(-1))},"aria-describedby":void 0,children:a===void 0||t===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`sl-lightbox__bar`,children:[(0,h.jsx)(Km,{className:`m-0 text-small font-semibold`,children:`${String(t+1)} of ${String(o)} · ${a.alt}`}),(0,h.jsxs)(`div`,{className:`sl-btn-row`,children:[i?.(a,t),(0,h.jsx)(Py,{label:`Previous`,onClick:()=>s(-1),disabled:o<2,children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{label:`Next`,onClick:()=>s(1),disabled:o<2,children:(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Xm,{asChild:!0,children:(0,h.jsx)(Py,{label:`Close`,children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})})]})]}),(0,h.jsx)(`div`,{className:`sl-lightbox__stage`,children:a.kind===`video`?(0,h.jsx)(c0,{src:a.src,label:a.alt,className:`sl-lightbox__player`,...a.poster===void 0?{}:{poster:a.poster}},a.src):(0,h.jsx)(`img`,{src:a.src,alt:a.alt},a.src)}),a.caption===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`p`,{className:`sl-lightbox__caption`,children:a.caption})]})})})})}var f0={location:oO(`docker-host`),path:K().min(1)},p0=JD([Y({opened:oO(!0)}).strict(),Y({opened:oO(!0),...f0}).strict(),Y({opened:oO(!1),...f0}).strict()]),m0=XD(`kind`,[Y({kind:oO(`allAffected`)}).strict(),Y({kind:oO(`selected`),workKeys:J(K().min(1).max(200)).min(1).max(1e4)}).strict()]),h0=K().min(1).max(64),cpe=Y({baseRevisionId:h0,request:m0}).strict(),lpe=Y({baseRevisionId:h0,idempotencyKey:_D(),previewId:K().min(1).max(64),acknowledgeUnknownCosts:RD(),confirmedProvidedWorkKeys:J(K().min(1).max(200)).max(1e4)}).strict(),upe=Y({stage:K(),low:q().finite().nonnegative().nullable(),high:q().finite().nonnegative().nullable(),detail:K(),onPlan:RD().optional(),apiLow:q().finite().nonnegative().nullable().optional(),apiHigh:q().finite().nonnegative().nullable().optional()}),dpe=Y({currency:oO(`USD`),rows:J(upe),low:q().finite().nonnegative(),high:q().finite().nonnegative(),unknown:q().int().nonnegative(),apiLow:q().finite().nonnegative().optional(),apiHigh:q().finite().nonnegative().optional(),apiUnknown:q().int().nonnegative().optional(),expectedWords:q().finite().nonnegative(),catalogueDate:K().nullable(),assumptions:J(K())}),g0=Y({revisionId:h0,admissionId:K().min(1).max(64),workIds:J(K().min(1).max(64)),replayed:RD()}),fpe=Y({id:K().min(1).max(64),projectId:K().min(1).max(64),baseRevisionId:h0,planFingerprint:K().min(1),selection:m0,changedInputs:J(Y({path:K(),before:K().nullable(),after:K().nullable()})),work:J(Y({key:K(),stage:X(KS),kind:X([`provider`,`local`,`provided`]),disposition:X([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:K(),fingerprint:K(),dependsOn:J(K()),reason:K(),inflight:RD(),pieceIds:J(K())})),retained:J(Y({slot:K(),outputId:K(),assetId:K(),state:X([`ready`,`outdated`,`review`])})),providedReuseRequired:J(K()),costs:dpe,wholeRequestNotice:K().nullable(),warnings:J(K()),review:Y({inputChanges:J(Y({label:K(),before:K().nullable(),after:K().nullable()})),requests:J(Y({key:K(),label:K(),text:K().nullable(),settings:K().nullable()}))}).optional()}),_0=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],v0=[`pending`,`running`,`done`,`failed`];Y({id:K(),stage_id:K(),kind:X(_0),idx:q(),state:X(v0),payload:K().nullable()});var ppe=`notes.article_md.article_txt.narration_txt.tts_script.sources.glossary.audio_body.audio_intro.audio_outro.audio_export.image.thumbnail.video.render_params.subtitles_srt.subtitles_vtt.subtitle_words.subtitle_ass.subtitle_font.instructions.document_pdf.youtube_description.youtube_tags.youtube_pinned_comment.youtube_titles.shorts.short_image.short_video.animated_image.figure_card.reference.script_md.audio_mp3.audio_m4b.audio_levelled`.split(`.`),mpe=[`copying`,`staged`],hpe=Y({segment:X([`body`,`intro`,`outro`]).optional(),subtitleOmissions:J(Y({start:q().finite().nonnegative(),text:K()})).optional(),subtitlesMode:X([`off`,`files`,`burn-in`]).optional(),promptName:K().optional(),prompt:K().optional(),index:q().optional(),short:q().optional(),format:X([`16:9`,`9:16`,`1:1`]).optional(),sentences:eO([q(),q()]).optional(),warnings:J(K()).optional(),provider:K().optional(),model:K().optional(),voice:K().optional(),loudness:Y({pieces:q(),skipped:q(),spreadBefore:q(),spreadAfter:q(),target:q()}).optional(),master:Y({target:q(),integrated:q(),truePeak:q()}).optional()}),gpe=Y({id:K(),projectId:K(),stageKind:X(KS),role:X(ppe),path:K(),originalFilename:K().nullable(),bytes:q().nonnegative(),durationMs:q().nonnegative().nullable(),meta:hpe,createdAt:K()});Y({id:K(),stageKind:X(KS),path:K(),originalFilename:K(),bytes:q().nonnegative(),state:X(mpe),createdAt:K()});var y0=K().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),b0=K().min(1).max(256),_pe=nO(b0,y0),vpe=Y({id:y0,text:K().trim().min(1).max(1e4),start:q().finite().nonnegative(),end:q().finite().positive(),speaker:K().min(1).max(60).regex(/^[a-z0-9-]+$/).optional()}).strict().refine(e=>e.end>e.start,{path:[`end`],message:`The end time must be after the start time.`}),x0=Y({articleMarkdown:K().max(5e5).optional(),articleEdited:RD().default(!1),provided:Y({research:y0.optional(),article:y0.optional(),audio:y0.optional(),thumbnail:y0.optional(),reference:y0.optional()}).strict(),imageOrder:J(y0).max(240),imageDefinitions:nO(y0,Y({source:X([`generate`,`provide`]),assetId:y0.nullable(),prompt:K().max(5e5).nullable(),templateKey:K().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:nO(b0,XD(`kind`,[Y({kind:oO(`asset`),assetId:y0}).strict(),Y({kind:oO(`text`),text:K().trim().min(1).max(5e5),direction:K().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:nO(b0,Y({text:K().min(1).max(5e5),start:q().int().nonnegative().max(5e5),bodyFingerprint:K().regex(/^[0-9a-f]{64}$/u),chunkingFingerprint:K().regex(/^[0-9a-f]{64}$/u)}).strict()).refine(e=>Object.keys(e).length<=1e4&&Object.values(e).reduce((e,t)=>e+t.text.length,0)<=5e5,`Narration source bindings exceed the article limit.`).optional(),subtitleCues:Y({audioFingerprint:K().min(1),cues:J(vpe)}).strict().optional(),regenerationTokens:_pe,promptTemplates:nO(K().min(1),K().max(5e5).nullable()),shortsMusic:y0.optional(),shortsRanges:nO(K().regex(/^[1-9]\d?$/u),Y({first:q().int().positive(),last:q().int().positive(),pick:K().min(1).max(128)}).strict()).optional(),ambientBed:y0.optional()}).strict(),ype=Y({baseRevisionId:y0,idempotencyKey:y0,edit:Y({config:mM.strict(),content:x0,regenerate:J(b0).optional(),uploads:J(Y({stagedFileId:y0,destination:XD(`kind`,[Y({kind:oO(`provided`),stage:X([`audio`,`thumbnail`,`reference`])}).strict(),Y({kind:oO(`image`),imageKey:y0}).strict(),Y({kind:oO(`narration`),key:b0}).strict(),Y({kind:oO(`shortsMusic`)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),bpe=Y({baseRevisionId:y0,idempotencyKey:y0,targetRevisionId:y0}).strict(),xpe=Y({id:y0,projectId:y0,parentId:y0.nullable(),restoredFromId:y0.nullable(),config:mM,content:x0,fingerprints:nO(b0,K()),createdAt:K()}),Spe=Y({id:y0,stageId:y0,kind:X(_0),idx:q().int(),state:X(v0),payload:K().nullable()}),Cpe=Y({slot:K(),workKey:b0,assetId:y0,output:gpe,fingerprint:K(),state:X([`ready`,`outdated`,`review`])}),wpe=Y({key:b0,stageKind:X(KS),piece:Spe,assetId:y0.nullable(),fingerprint:K()}),S0={recordId:y0,publicationId:y0.nullable(),selected:RD(),available:RD()},C0=Y({articleMarkdown:K().nullable(),revision:xpe,outputs:J(Cpe.extend(S0)),pieces:J(wpe.extend(S0)),current:RD()}),Tpe=Y({id:y0,parentId:y0.nullable(),restoredFromId:y0.nullable(),title:K(),createdAt:K(),current:RD()}),w0=Y({ok:oO(!0),view:C0,duplicate:RD()}),Epe=Y({ok:oO(!0),view:C0,created:RD()}),Dpe=Y({title:K(),status:q(),detail:K().optional(),reason:K().optional(),currentRevisionId:K().nullable().optional(),fields:J(Y({field:K(),message:K()})).optional(),errors:J(Y({path:K(),message:K()})).optional()});async function T0(e,t){let n;try{n=await e.json()}catch{throw lo(e,void 0)}if(e.ok)return{ok:!0,value:yo(t,n)};let r=Dpe.safeParse(n);if(!r.success)throw lo(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw lo(e,{title:i.title,status:i.status,...i.detail===void 0?{}:{detail:i.detail},...i.fields===void 0?{}:{fields:i.fields}});return{ok:!1,reason:i.reason??`invalid-request`,message:i.detail??i.title,currentRevisionId:i.currentRevisionId??null,fields:i.fields??i.errors?.map(e=>({field:e.path,message:e.message}))??[]}}async function E0(e,t,n,r,i){return T0(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}${n}`,i===void 0?{method:`GET`}:{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}),r)}function D0(e,t){return E0(e,t,`/revisions/prepare`,Epe,{})}function O0(e,t,n){return E0(e,t,`/revisions`,w0,ype.parse(n))}function Ope(e,t,n){return E0(e,t,`/revisions/restore`,w0,bpe.parse(n))}function kpe(e,t){return E0(e,t,`/revisions`,Y({revisions:J(Tpe)}))}function k0(e,t,n){return E0(e,t,`/revisions/${encodeURIComponent(n)}`,Y({view:C0}))}var A0=J(K()).readonly();function Ape(e,t,n){return E0(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,Y({chunks:Y({intro:A0.optional(),body:A0.optional(),outro:A0.optional()}).nullable()}))}function jpe(e,t,n){return E0(e,t,`/rebuild/preview`,Y({ok:oO(!0),value:fpe}),cpe.parse(n))}function Mpe(e,t,n){return E0(e,t,`/rebuild`,Y({ok:oO(!0),value:g0}),lpe.parse(n))}function j0(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function Npe(e,t,n,r){let i=await T0(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),p0);if(!i.ok)throw Error(i.message);return i.value}function Ppe(e,t,n){return j0(e,t,n,`images.zip`)}async function M0(e,{projectId:t,asset:n,folder:r=null}){if(r)return Npe(e,t,r.revisionId,r.recordId);let i=await e.client.projects[`:id`][`open-folder`].$post({param:{id:t},json:{asset:n}});if(!i.ok)throw lo(i,await uo(i));return p0.parse(await i.json())}var N0=`Slopify runs in Docker, which can't open windows on your desktop. Copy this path into your file manager. To have Open folder open it directly, run the Docker launcher again (npx @gentbajko/slopify@latest --docker) so it sets up the host helper.`;function P0(e){return(0,h.jsx)(Fpe,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function Fpe(e){let{api:t}=V(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(),[o,s]=(0,m.useState)();async function c(){r(!0),a(void 0),s(void 0);try{let n=await M0(t,e);n.opened||s(n.path)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Press Open folder to try again.`)}finally{r(!1)}}return(0,h.jsxs)(Nb,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(Fb,{asChild:!0,children:(0,h.jsxs)(B,{variant:`secondary`,size:e.size??`default`,disabled:n,onClick:()=>void c(),title:`Locate the saved output folder on the machine running Slopify`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),n?`Locating…`:o?`Locate folder`:`Open folder`]})}),(0,h.jsxs)(Lb,{className:`flex flex-col gap-2`,children:[o===void 0?null:(0,h.jsxs)(`div`,{role:`status`,className:`flex min-w-0 flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:N0}),(0,h.jsx)(`input`,{"aria-label":`Saved folder path`,readOnly:!0,value:o,onFocus:e=>e.currentTarget.select(),className:`sl-input w-full min-w-0 font-mono text-small`})]}),i===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i})]})]})}var Ipe={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function Lpe(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function F0(){let{api:e}=V(),[t,n]=(0,m.useState)(Lpe),r=`slopify-studio-${t}.zip`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(Vb,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:Ipe[e]}))}),(0,h.jsxs)(TS,{href:_s(e,t),download:r,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download for ${t===`chrome`?`Chrome`:`Firefox`}`]})]}),(0,h.jsxs)(`ol`,{"aria-label":`Install steps`,className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:[t===`chrome`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`li`,{children:[`Press Download for Chrome, then unzip `,(0,h.jsx)(HB,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(HB,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(HB,{children:`edge://extensions`}),`), turn on Developer mode, press Load unpacked and pick that folder.`]})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`li`,{children:`Press Download for Firefox. It needs Firefox 128 or newer; keep the zip, you pick it in the next step.`}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(HB,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(HB,{children:r}),`. Firefox removes it when it restarts; load it again then.`]})]}),(0,h.jsx)(`li`,{children:`Pair it: press Copy beside the pairing token in Settings → YouTube Studio, click the Slopify extension's toolbar button, paste the token and press Pair.`})]})]})}var I0=[`studio`,`plan`];function Rpe({autoComment:e}){let{api:t}=V(),n=_(),r=Ry(),i=I({queryKey:I0,queryFn:()=>as(t)}),a=L({mutationFn:e=>os(t,{...e,rows:[]}),onSuccess:e=>{n.setQueryData(I0,e),n.invalidateQueries({queryKey:[`studio`,`releases`]}),r(`Removed the old posting plan. Each schedule's release times apply now.`,`success`)},onError:e=>r(`The old posting plan wasn't removed: ${e.message} Try Remove the old plan again.`,`error`)}),o=L({mutationFn:e=>ss(t,e),onSuccess:e=>{n.setQueryData(I0,e),n.invalidateQueries({queryKey:[`studio`,`releases`]}),r(`Each upload is now due ${String(e.leadHours)} hours before its release.`,`success`)},onError:e=>r(`The lead time wasn't saved: ${e.message}`,`error`)}),s=L({mutationFn:e=>fs(t,e),onSuccess:()=>n.invalidateQueries({queryKey:[`studio`,`settings`]}),onError:e=>r(`Not saved: ${e.message}`,`error`)});if(i.data===void 0)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the release settings…`});let c=i.data.plan;return(0,h.jsxs)(`section`,{"aria-label":`Release times`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{as:`h3`,title:`Release times`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Each schedule sets when its videos and shorts go out, one line for each day it runs, with a time for every short its template makes:`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`},children:`Calendar → Schedules`}),` `,`→ Edit → Release times. See and move them in Calendar → Releases.`]}),c.rows.length>0?(0,h.jsx)(aI,{tone:`info`,title:`An older posting plan still applies`,actions:(0,h.jsx)(B,{variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate(c),children:`Remove the old plan`}),children:(0,h.jsx)(`p`,{className:`m-0`,children:`It has ${String(c.rows.length)} line${c.rows.length===1?``:`s`}, and gives release times to projects no schedule made, and to a schedule's projects when its own times are taken. Set release times in your schedules, then remove it. Times already given keep.`})}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[`Upload and schedule each video and short at least`,(0,h.jsx)(zB,{"aria-label":`Hours before release`,type:`number`,min:1,max:168,className:`w-[72px]`,defaultValue:i.data?.leadHours??24,onBlur:e=>{let t=Number(e.currentTarget.value);Number.isInteger(t)&&t>=1&&t<=168&&t!==i.data?.leadHours&&o.mutate(t)}},i.data?.leadHours??24),`hours before its release, so YouTube's copyright and ad checks finish while it is private.`]}),(0,h.jsx)(Bb,{checked:e===!0,disabled:s.isPending||e===void 0,onChange:e=>s.mutate(e),label:`Post and pin each video's comment once it is public (the extension posts it in your name)`})]})}var L0=[`studio`,`settings`];function zpe(){let{api:e}=V(),t=I({queryKey:L0,queryFn:()=>ts(e)});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Upload pack and extension`,info:`settings.studio.extension`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(Bpe,{}),(0,h.jsx)(Rpe,{autoComment:t.data?.autoComment??!1}),(0,h.jsx)(Hpe,{}),(0,h.jsxs)(`section`,{"aria-label":`Install the Studio extension`,children:[(0,h.jsx)(W,{as:`h3`,title:`Install the Studio extension`,className:`mb-3`}),(0,h.jsx)(F0,{})]})]})]})}var R0=``;function Bpe(){let{api:e}=V(),t=_(),n=Ry(),r=(0,m.useId)(),i=I({queryKey:L0,queryFn:()=>ts(e)}),a=I(cx(e)),o=(0,m.useId)(),[s,c]=(0,m.useState)(R0),[l,u]=(0,m.useState)(void 0),d=i.data?.playlists??[],f=s===R0?void 0:i.data?.channelPlaylists[s],p=l??(s===R0?d:f??[]),g=Vpe(p),v=L({mutationFn:t=>ns(e,t,s===R0?void 0:s),onSuccess:()=>{u(void 0),t.invalidateQueries({queryKey:L0}),n(`Playlists saved.`,`success`)}}),y=e=>{v.reset(),u(e)},b=g??v.error?.message,x=[{value:R0,label:`Every channel (default)`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(LB,{label:`Playlists`,tip:`settings.studio.playlist`,help:s===R0?`The playlists upload packs offer, for every channel without its own. Ticked ones are on for every project; Prepare upload changes them for one project.`:f===void 0&&d.length>0?`This channel uses the default list (${(e=>e.map(e=>e.name).join(`, `))(d)}) until you add its own.`:`This channel's own playlists. Ticked ones are on for every project; Prepare upload changes them for one project.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(VB,{id:o,"aria-label":`Channel`,value:s,options:x,onChange:e=>{v.reset(),u(void 0),c(e.currentTarget.value)},className:`max-w-[260px]`}),p.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{autoComplete:`off`,"aria-label":`Playlist ${String(t+1)} name`,placeholder:`The playlist's name in Studio`,className:`min-w-0 flex-1 basis-[220px]`,value:e.name,disabled:i.data===void 0,"aria-invalid":e.name.trim().length>150,"aria-describedby":b===void 0?void 0:r,onChange:e=>y(p.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,h.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.byDefault,onChange:e=>{let n=e.currentTarget.checked;y(p.map((e,r)=>r===t?{...e,byDefault:n}:e))}}),`On by default`]}),(0,h.jsx)(VB,{"aria-label":`${e.name.trim()||`Playlist ${String(t+1)}`}: takes`,className:`w-[190px]`,value:e.for??`all`,onChange:e=>{let n=e.currentTarget.value,r=n===`long`||n===`shorts`?n:`all`;y(p.map((e,n)=>n===t?{...e,for:r}:e))},options:[{value:`all`,label:`Videos and shorts`},{value:`long`,label:`Long videos only`},{value:`shorts`,label:`Shorts only`}]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name.trim()||`playlist ${String(t+1)}`}`,onClick:()=>y(p.filter((e,n)=>n!==t)),children:`Remove`})]},t)),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(B,{variant:`secondary`,disabled:i.data===void 0||p.length>=20,onClick:()=>y([...p,{name:``,byDefault:p.length===0}]),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add playlist`]}),(0,h.jsx)(B,{variant:`primary`,disabled:v.isPending||l===void 0||g!==void 0,onClick:()=>v.mutate(p),children:`Save playlists`})]})]}),b===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:b})]})}function Vpe(e){if(e.find(e=>e.name.trim().length>150)!==void 0)return`A playlist name is longer than YouTube allows (150 characters). Shorten it.`;let t=new Set;for(let n of e){let e=n.name.trim().toLowerCase();if(e!==``){if(t.has(e))return`"${n.name.trim()}" is listed twice. Remove one.`;t.add(e)}}}function Hpe(){let{api:e}=V(),t=_(),n=Ry(),r=I({queryKey:L0,queryFn:()=>ts(e)}),i=L({mutationFn:()=>bs(e),onSuccess:()=>{t.invalidateQueries({queryKey:L0}),n(`New pairing token made. Pair the extension again with it.`,`success`)}}),a=r.data?.pairing;return(0,h.jsxs)(`div`,{className:`sl-field`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Extension pairing token`}),(0,h.jsx)(U,{id:`settings.studio.pairing`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`code`,{className:`sl-code min-w-0 flex-1 basis-[220px] truncate py-2 select-all`,children:a?.token??`…`}),(0,h.jsxs)(B,{variant:`quiet`,disabled:a===void 0,onClick:()=>{if(a!==void 0){if(!navigator.clipboard){n(`Couldn't copy the token. Select it and copy it.`,`error`);return}navigator.clipboard.writeText(a.token).then(()=>n(`Pairing token copied. Paste it into the extension's options.`,`success`),()=>n(`Couldn't copy the token. Select it and copy it.`,`error`))}},children:[(0,h.jsx)(kc,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}),`Copy`]}),(0,h.jsx)(B,{variant:`quiet`,disabled:i.isPending||a===void 0,onClick:()=>i.mutate(),children:`New pairing token`})]}),(0,h.jsx)(`p`,{className:`sl-field__help m-0`,children:a?.origin==null?`No extension is paired. Paste this token into the Slopify Studio extension's options and press Pair.`:`Paired with the extension at ${a.origin}. A new token unpairs it.`}),i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.error.message})]})}var z0=[`studio`,`queue`];function B0({projectId:e,ready:t,variant:n=`secondary`,size:r=`default`}){let[i,a]=(0,m.useState)(!1);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:n,size:r,disabled:!t,disabledReason:`Available once the video has been made`,onClick:()=>a(!0),children:`Prepare upload`}),i?(0,h.jsx)(W0,{projectId:e,onClose:()=>a(!1)}):null]})}var V0={video:`Video file`,title:`Title`,description:`Description`,thumbnails:`Thumbnail`,playlist:`Playlist`,audience:`Audience`,altered:`AI use (under Show more)`,tags:`Tags (under Show more)`,schedule:`Schedule (Visibility)`};function H0(e){return new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`}).format(new Date(e))}function U0(e){return e.kind===`video`?`video`:`short-${String(e.short)}`}function W0({projectId:e,onClose:t}){let{api:n}=V(),r=_(),i=[`studio`,`pack`,e],a=I({queryKey:i,queryFn:()=>xs(n,e)}),[o,s]=(0,m.useState)(`video`),[c,l]=(0,m.useState)(),u=a.data?.items??[],d=u.find(e=>U0(e)===o)??u[0],f=I({queryKey:L0,queryFn:()=>ts(n)}),p=f.data===void 0?void 0:f.data.pairing.origin!==null,g=I({queryKey:z0,queryFn:()=>vs(n)}),v=L({mutationFn:t=>Cs(n,e,t.short),onSuccess:e=>{r.setQueryData(z0,e),l({text:e.length>1?`Added; ${String(e.length)} uploads are waiting. Studio is opening: each upload you start there is filled with the next one, in the order under Waiting for Studio. Check everything and publish yourself.`:`Studio is opening. The Slopify Studio extension puts the video into its upload dialog and fills in the details. Check everything and publish yourself.`,tone:`success`})},onError:e=>l({text:`Couldn't hand this to the extension: ${e.message}`,tone:`error`})}),y=L({mutationFn:e=>ys(n,e.projectId,e.short),onSuccess:e=>r.setQueryData(z0,e),onError:e=>l({text:`Couldn't remove it from Waiting for Studio: ${e.message} Press Remove again.`,tone:`error`})}),b=L({mutationFn:t=>Ss(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved. The AI use answer is updated.`,tone:`success`})},onError:e=>l({text:`Couldn't save whether the clips are real footage: ${e.message} Press the switch again.`,tone:`error`})}),x=L({mutationFn:t=>rs(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved this project's playlists.`,tone:`success`})},onError:e=>l({text:`Couldn't save the playlists: ${e.message} Tick the playlist again.`,tone:`error`})}),S=L({mutationFn:t=>ps(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved when this project goes out.`,tone:`success`})},onError:e=>l({text:`Couldn't change the slot: ${e.message} Choose it again.`,tone:`error`})}),C=L({mutationFn:t=>is(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved what the upload uses.`,tone:`success`})},onError:e=>l({text:`Couldn't save the choice: ${e.message} Choose it again.`,tone:`error`})});return(0,h.jsxs)(HP,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(TS,{href:Y1,target:`_blank`,rel:`noopener noreferrer`,variant:`secondary`,children:`Open YouTube Studio`}):null,(0,h.jsx)(B,{variant:`primary`,disabled:d===void 0||v.isPending||p!==!0,disabledReason:p===!1?`Install and pair the Slopify Studio extension first (steps above)`:f.error===null?`Wait for the upload pack to load`:`Couldn't check whether the extension is paired: ${f.error.message} Close Prepare upload and open it again.`,onClick:()=>{d!==void 0&&(window.open(Y1,`_blank`,`noopener`),v.mutate(d))},children:`Fill in YouTube Studio`}),(0,h.jsx)(U,{id:`project.upload.fill-studio`})]}),children:[a.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The upload pack couldn't be read.`,children:`${a.error.message} Close Prepare upload and open it again.`}),a.data===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p===!1?(0,h.jsx)(aI,{tone:`waiting`,title:`The Slopify Studio extension isn't paired.`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Without it, the steps below are the upload pack: copy each into Studio's upload dialog. To have Studio filled in for you, install the extension:`}),(0,h.jsx)(F0,{})]})}):null,u.length>1?(0,h.jsx)(Vb,{label:`What to upload`,value:d===void 0?``:U0(d),onChange:s,tip:`project.upload.item`,options:u.map(e=>({value:U0(e),label:e.kind===`video`?`Video`:`Short ${String(e.short)}`})),className:`self-start`}):null,a.data.missing.length===0?null:(0,h.jsx)(aI,{tone:`waiting`,title:`Some of it isn't made yet.`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:a.data.missing.map(e=>(0,h.jsx)(`li`,{children:e},e))})}),d===void 0?null:(0,h.jsx)(Wpe,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(Bb,{checked:b.isPending?b.variables:a.data.footage.real,disabled:b.isPending,onChange:e=>b.mutate(e),tip:`project.upload.real-footage`,label:`The ${a.data.footage.clips===1?`uploaded clip is`:`${String(a.data.footage.clips)} uploaded clips are`} real footage (filmed, not made by AI)`}):void 0,playlistPicker:a.data.playlistChoices.length>1?(0,h.jsx)(`span`,{className:`flex flex-col gap-1`,children:a.data.playlistChoices.map(e=>(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.chosen,disabled:x.isPending,onChange:t=>{let n=t.currentTarget.checked;x.mutate(a.data.playlistChoices.filter(t=>t.name===e.name?n:t.chosen).map(e=>e.name))}}),e.name]},e.name))}):void 0,copy:(e,t)=>{if(!navigator.clipboard){l({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>l({text:`Copied the ${t}.`,tone:`success`}),()=>l({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},onPick:e=>C.mutate(e),slotPicker:d.kind===`video`?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...zb,children:[(0,h.jsx)(VB,{"aria-label":`Posting plan slot`,value:a.data.schedule===void 0?``:`${a.data.schedule.row}|${a.data.schedule.longAt}`,disabled:S.isPending,onChange:e=>{let[t,n]=e.currentTarget.value.split(`|`);S.mutate(t===void 0||n===void 0?null:{row:t,longAt:n})},options:[{value:``,label:`Not scheduled (set it in Studio yourself)`},...a.data.schedule===void 0?[]:[{value:`${a.data.schedule.row}|${a.data.schedule.longAt}`,label:H0(a.data.schedule.longAt)}],...(a.data.slotChoices??[]).map(e=>({value:`${e.row}|${e.longAt}`,label:H0(e.longAt)}))]}),(0,h.jsx)(U,{id:`project.upload.slot`})]}):void 0,picking:C.isPending,doneKey:`slopify.upload.${e}.${U0(d)}`},U0(d)),(g.data??[]).length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Waiting for Studio`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:`Waiting for Studio`}),(0,h.jsx)(U,{id:`project.upload.queue`,className:`-my-1`})]}),(0,h.jsx)(PH,{label:`Waiting to be filled`,children:(g.data??[]).map((e,t)=>{let n=e.short===null?`Video`:`Short ${String(e.short)}`;return(0,h.jsx)(FH,{title:`${e.projectTitle} · ${n}`,meta:t===0?`Next: filled in the next upload dialog you open in Studio.`:`Filled after ${String(t)} more upload${t===1?``:`s`}.`,actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:y.isPending,"aria-label":`Remove ${e.projectTitle} ${n.toLowerCase()} from Waiting for Studio`,onClick:()=>y.mutate(e),children:`Remove`})},`${e.projectId}-${String(e.short)}`)})})]}),(0,h.jsx)(aI,{title:`Slopify never publishes.`,children:p===!1?`Copy each step into Studio's upload dialog (Open YouTube Studio), check it and press Publish yourself.`:`Fill in YouTube Studio hands this to the Slopify Studio extension, which puts the video into Studio's upload dialog and fills in the details. You check it and press Publish.`})]})]})}function Upe(e){try{let t=JSON.parse(localStorage.getItem(e)??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function G0({href:e,filename:t}){return(0,h.jsxs)(TS,{href:e,download:t,"aria-label":`Download ${t}`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download`]})}function Wpe({projectId:e,item:t,footageSwitch:n,playlistPicker:r,copy:i,onPick:a,picking:o,slotPicker:s,doneKey:c}){let{api:l}=V(),[u,d]=(0,m.useState)(()=>Upe(c)),[f,p]=(0,m.useState)(null),g=e=>{d(e);try{localStorage.setItem(c,JSON.stringify(e))}catch{}},_=(e,t)=>g(t?[...u,e]:u.filter(t=>t!==e)),v=$fe.filter(e=>e!==`thumbnails`||t.kind===`video`),y=v.filter(e=>u.includes(e)).length,b=e=>{let n=q0(t,e);return(0,h.jsxs)(B,{variant:`quiet`,size:`small`,disabled:n===``,disabledReason:`Nothing to copy yet`,"aria-label":`Copy ${V0[e].toLowerCase()}`,onClick:()=>i(n,V0[e].toLowerCase()),children:[(0,h.jsx)(kc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy`]})},x=c=>{switch(c){case`video`:return t.video===null?{value:(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not made yet.`})}:{value:t.video.filename,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(G0,{href:`${l.origin}${t.video.url}`,filename:t.video.filename}),(0,h.jsx)(P0,{projectId:e,asset:t.video.asset,size:`small`})]})};case`thumbnails`:return t.thumbnails.length===0?{value:(0,h.jsx)(`span`,{className:`text-ink-3`,children:`None made.`})}:{value:t.thumbnails.length>1?`${K0(t.pickable?.thumbnail??0)} under Thumbnail (choose below). The A/B test tries all ${String(t.thumbnails.length)} once the video is public.`:t.thumbnails[0]?.filename??``,actions:(0,h.jsx)(P0,{projectId:e,asset:t.thumbnails[0]?.asset??`thumbnail`,size:`small`})};case`audience`:return{value:`No, it's not made for kids`};case`altered`:return{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:t.alteredContent.altered?`Yes`:`No`}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:t.alteredContent.why}),n]})};case`description`:return{value:t.chapterNotice===void 0?q0(t,c)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}):(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:t.description}),(0,h.jsx)(`span`,{className:`text-waiting`,children:t.chapterNotice})]}),actions:b(c)};case`title`:return t.titles.length===0||t.pickable===void 0?{value:q0(t,c),actions:b(c)}:{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{role:`radiogroup`,"aria-label":`Title the upload uses`,className:`flex flex-col gap-1`,children:t.pickable.titles.map((n,r)=>(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`radio`,name:`upload-title-${e}`,className:`size-4 accent-[var(--color-accent)]`,checked:r===t.pickable?.title,disabled:o,onChange:()=>a({title:r,thumbnail:t.pickable?.thumbnail??0})}),n]},n))}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:`The upload uses the chosen title; the A/B test tries the others beside it once the video is public.`})]}),actions:(0,h.jsxs)(h.Fragment,{children:[b(c),(0,h.jsxs)(B,{variant:`quiet`,size:`small`,"aria-label":`Copy the other titles`,onClick:()=>i(t.titles.join(`
272
272
  `),`other titles`),children:[(0,h.jsx)(kc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy others`]})]})};case`schedule`:return{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[s,(0,h.jsx)(`span`,{className:`text-ink-2`,children:t.scheduleAt===void 0?`Not scheduled: Slopify has no slot for it. Set the date in Studio's Visibility step.`:`${H0(t.scheduleAt)}, your time. The extension types it into Studio's Visibility step; you press Schedule.`})]})};case`playlist`:return{value:r??(t.playlists.length>0?t.playlists.join(`, `):(0,h.jsx)(`span`,{className:`text-ink-3`,children:`None set (Settings → YouTube Studio).`})),actions:b(c)};default:return{value:q0(t,c)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}),actions:b(c)}}};return(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`In the order Studio asks`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:`In the order Studio asks`}),(0,h.jsx)(U,{id:`project.upload.steps`,className:`-my-1`}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsxs)(`label`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:y===v.length,ref:e=>{e!==null&&(e.indeterminate=y>0&&y<v.length)},onChange:e=>g(e.currentTarget.checked?[...v]:[]),className:`size-4 shrink-0 accent-[var(--color-accent)]`}),`Select all`]})]}),(0,h.jsx)(PH,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:v.map(e=>{let{value:t,actions:n}=x(e);return(0,h.jsx)(FH,{className:`items-start`,lead:(0,h.jsx)(`input`,{type:`checkbox`,checked:u.includes(e),onChange:t=>_(e,t.currentTarget.checked),className:`mt-1 size-4 shrink-0 self-start accent-[var(--color-accent)]`,"aria-label":`${V0[e]} done`}),title:V0[e],meta:(0,h.jsx)(`span`,{className:`line-clamp-4 whitespace-pre-wrap break-words text-ink`,children:t}),actions:n},e)})})]}),t.thumbnails.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Thumbnails`,children:[(0,h.jsx)(W,{as:`h3`,kicker:`Thumbnails · A/B Testing`,title:`${String(t.thumbnails.length)} ${t.thumbnails.length===1?`thumbnail`:`thumbnails`}`,className:`mb-3`}),(0,h.jsx)(u0,{label:`Thumbnails to upload`,density:`compact`,children:(t.pickable?.thumbnails??t.thumbnails).map((e,n)=>{let r=n===(t.pickable?.thumbnail??0);return(0,h.jsx)(l0,{src:`${l.origin}${e.url}`,alt:`Thumbnail ${K0(n)}`,title:r&&t.thumbnails.length>1?`${K0(n)} · upload`:K0(n),meta:e.filename,onOpen:()=>p(n),openLabel:`Open thumbnail ${K0(n)} full size`,actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[r||t.pickable===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:o,onClick:()=>a({title:t.pickable?.title??0,thumbnail:n}),children:`Use for upload`}),(0,h.jsx)(G0,{href:`${l.origin}${e.url}`,filename:e.filename})]})},e.asset)})}),(0,h.jsx)(d0,{items:(t.pickable?.thumbnails??t.thumbnails).map((e,t)=>({src:`${l.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,caption:e.filename})),index:f,onIndex:p,onClose:()=>p(null),actions:(e,n)=>{let r=(t.pickable?.thumbnails??t.thumbnails)[n];return r===void 0?null:(0,h.jsx)(G0,{href:`${l.origin}${r.url}`,filename:r.filename})}})]})]})}function K0(e){return String.fromCharCode(65+e)}function q0(e,t){switch(t){case`title`:return e.title;case`description`:return e.description;case`tags`:return epe(e.tags);case`playlist`:return e.playlists.join(`, `);default:return``}}var J0=[`studio`,`releases`],Y0=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),Gpe=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`}),X0=e=>`${Y0.format(new Date(e))}, ${Gpe.format(new Date(e))}`;function Kpe(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function qpe(e){switch(e.state){case`scheduled`:return e.checks===`ok`?{tone:`neutral`,word:`✓ Scheduled · checks clear`}:e.checks===null?{tone:`info`,word:`✓ Scheduled · checks pending`}:{tone:`failed`,word:`Scheduled · ${e.checks}`};case`filled`:return{tone:`waiting`,word:`Filled in Studio, not scheduled`};case`late`:return{tone:`failed`,word:`Late · upload now`};case`not-ready`:return{tone:`neutral`,word:`Not rendered yet`};default:return{tone:`neutral`,word:`Ready to upload`}}}function Jpe(e,t){let n=new Date(e),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-(n.getDay()+6)%7),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(t.getDay()+6)%7),a=Math.round((r.getTime()-i.getTime())/6048e5);return{key:r.toISOString(),label:a<=0?`This week`:a===1?`Next week`:`Week of ${Y0.format(r)}`}}function Ype({item:e,projectId:t,onDone:n}){let{api:r}=V(),i=_(),a=Ry(),[o,s]=(0,m.useState)(e.at===null?``:Kpe(e.at)),c=L({mutationFn:n=>ds(r,t,{short:e.short,at:n}),onSuccess:()=>{i.invalidateQueries({queryKey:J0}),n()},onError:e=>a(`The time wasn't changed: ${e.message}`,`error`)}),l=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(zB,{"aria-label":`${l}: release`,type:`datetime-local`,className:`w-[200px]`,value:o,onChange:e=>s(e.currentTarget.value)}),(0,h.jsx)(B,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(new Date(o).toISOString()),children:`Save`}),e.short===0?(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:c.isPending,onClick:()=>c.mutate(null),children:`Not scheduled`}):null,(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,onClick:n,children:`Cancel`})]})}function Z0({item:e,projectId:t,editing:n,onEdit:r}){let i=qpe(e),a=n?.projectId===t&&n.short===e.short,o=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[o,e.at===null?``:` · goes public`]}),e.short===0?null:(0,h.jsx)(`span`,{className:`w-full truncate text-small`,title:e.title,children:e.title}),a?(0,h.jsx)(Ype,{item:e,projectId:t,onDone:()=>r(void 0)}):(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,"aria-label":`${o}: move from ${e.at===null?`no time`:X0(e.at)}`,onClick:()=>r({projectId:t,short:e.short}),children:e.at===null?`Set a time`:X0(e.at)}),(0,h.jsx)(kS,{tone:i.tone,children:i.word})]})}function Xpe({entry:e,candidates:t}){let{api:n}=V(),r=_(),i=Ry(),a=t.filter(t=>e.series===``||t.series===e.series),[o,s]=(0,m.useState)(``),c=L({mutationFn:t=>ds(n,t,{short:0,at:e.at,...e.line===null?{}:{line:e.line}}),onSuccess:()=>void r.invalidateQueries({queryKey:J0}),onError:e=>i(`The project wasn't put there: ${e.message}`,`error`)});return a.length===0?(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[`Free · no finished project`,e.series===``?``:` of ${e.series}`,` waits for a time`]}):(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(VB,{"aria-label":`Project for ${X0(e.at)}`,className:`w-[260px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:``,label:`Free · pick a finished project`},...a.map(e=>({value:e.id,label:e.title}))]}),(0,h.jsx)(B,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(o),children:`Put it here`})]})}function Zpe(){let{api:e}=V(),t=I({queryKey:J0,queryFn:()=>cs(e)}),[n,r]=(0,m.useState)();if(t.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the releases…`});if(t.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The releases didn't load: `,t.error.message,` Reload the page to try again.`]});let i=t.data;if(i.entries.length===0)return(0,h.jsx)(T1,{title:`No releases in the next two weeks`,children:`Add your week in Settings → YouTube Studio → Posting plan: each finished project then takes its next free time, and its shorts the times after it. Or open a finished project's Prepare upload.`});let a=new Date,o=new Map;for(let e of i.entries){let t=Jpe(e.at,a),n=o.get(t.key)??{label:t.label,entries:[]};n.entries.push(e),o.set(t.key,n)}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Every video and short is due `,String(i.leadHours),` hours before its release, so YouTube's copyright and ad checks finish while it is private. Change that, or the weekly times, in`,` `,(0,h.jsx)(fa,{to:`/settings`,search:{section:`studio`},children:`Settings → YouTube Studio`}),`.`]}),[...o.values()].map(e=>(0,h.jsxs)(`section`,{"aria-label":e.label,className:`flex flex-col gap-3`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:e.label}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:e.entries.map(e=>{let t=e.items.find(e=>e.short===0),a=e.items.filter(e=>e.short>0);return(0,h.jsxs)(`li`,{className:`flex flex-col gap-2 border-b border-line pb-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:X0(e.at)}),e.series===``?null:(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.series}),e.project===null?null:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.project.id},children:e.project.title})]}),e.project===null?(0,h.jsx)(Xpe,{entry:e,candidates:i.candidates}):(0,h.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-x-4 gap-y-3`,children:[t===void 0?null:(0,h.jsx)(Z0,{item:t,projectId:e.project.id,editing:n,onEdit:r}),a.map(t=>(0,h.jsx)(Z0,{item:t,projectId:e.project?.id??``,editing:n,onEdit:r},t.short))]})]},`${e.at}-${e.project?.id??`free`}`)})})]},e.label))]})}var Q0=4;function Qpe(e){return e===`schedules`?`schedules`:e===`releases`?`releases`:`weeks`}var $0=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),e2=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),t2=new Intl.DateTimeFormat(void 0,{timeStyle:`short`}),n2=`slopify.calendar.view`;function $pe(){try{return window.localStorage.getItem(n2)===`list`?`list`:`weeks`}catch{return`weeks`}}function eme({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=V(),a=_(),o=Dx(),[s]=(0,m.useState)(()=>OH(new Date,Q0)),[c,l]=(0,m.useState)($pe),[u,d]=(0,m.useState)(e??`weeks`),f=n===void 0?u:e??`weeks`,p=e=>{n===void 0?d(e):n(e)},[g,v]=(0,m.useState)(!1),y=I(pH(i,s.from,s.to)),b=I(qV(i)),x=I(lq(i)),S=I(ob(i)),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),D=(0,m.useMemo)(()=>new Map((x.data??[]).map(e=>[e.id,e.channelId])),[x.data]),O=(0,m.useMemo)(()=>new Map((S.data?.projects??[]).map(e=>[e.id,e.channelId])),[S.data]),k=(b.data??[]).filter(e=>o.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>o.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>o.includes(O.get(e.id)))},j=(0,m.useMemo)(()=>A===void 0?new Map:DH(A),[A]),M=A?.runs??[],ee=SH(A?.projects??[]),N=L({mutationFn:e=>e(),onSuccess:e=>w(e.ok?{tone:`info`,text:`Moved.`}:{tone:`error`,text:e.message}),onError:e=>w({tone:`error`,text:`The topic wasn't moved: ${e.message} Reload the calendar and try again.`}),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:fH}),a.invalidateQueries({queryKey:KV})])}}),P=e=>{if(e.kind!==`none`){if(e.kind===`refused`){w({tone:`error`,text:e.message});return}e.kind===`move`?N.mutate(()=>lH(i,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to})):N.mutate(()=>dH(i,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}}))}},F=(e,t)=>{let n=AH(M,e,t);if(n===void 0){w({tone:`error`,text:t===-1?`${jH(e)} is already the next topic of ${e.scheduleName}.`:`${jH(e)} is the last topic on the calendar for ${e.scheduleName}.`});return}P(kH(e,n,e2.format(new Date(n.at))))},te=e=>{l(e),f!==`weeks`&&p(`weeks`);try{window.localStorage.setItem(n2,e)}catch{}};jx({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),jx({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>p(`schedules`)}),oS(tS.addToCalendar,()=>v(!0)),jx({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>te(`weeks`)}),jx({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>te(`list`)});let ne=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),re=C?.text??y.error?.message??b.error?.message,ie=wH(new Date),ae=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(XK,{title:`Calendar`,meta:`${o.channel?.name??`Every channel`} · ${String(M.length)} scheduled ${M.length===1?`run`:`runs`} in the next ${String(Q0)} weeks · ${String(ne)} ${ne===1?`topic`:`topics`} queued`,actions:f===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Vb,{label:`Calendar view`,tip:`planning.calendar.view`,value:c,onChange:te,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(B,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]}):void 0}),(0,h.jsx)(C1,{items:[{id:`weeks`,label:`Coming weeks`},{id:`releases`,label:`Releases`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ae)}}],value:f,onChange:p,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(w1,{idPrefix:`calendar`,id:`releases`,active:f===`releases`,children:f===`releases`?(0,h.jsx)(Zpe,{}):null}),(0,h.jsx)(w1,{idPrefix:`calendar`,id:`schedules`,active:f===`schedules`,children:f===`schedules`?(0,h.jsx)(qfe,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(w1,{idPrefix:`calendar`,id:`weeks`,active:f===`weeks`,children:[(0,h.jsx)(v1,{tone:C?.tone===`info`?`info`:re?`error`:`info`,className:`mb-3`,children:re}),(0,h.jsxs)(b1,{split:`aside`,className:`mb-6`,children:[(0,h.jsx)(x1,{label:`Needs you`,children:ee.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Nothing needs you right now.`}):(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(W,{title:`Needs you`,meta:xH(ee)}),(0,h.jsx)(PH,{label:`Needs you`,children:ee.map(e=>(0,h.jsx)(a2,{project:e},e.id))})]})}),(0,h.jsx)(x1,{as:`aside`,label:`Suggested topics`,children:(0,h.jsx)(bfe,{schedules:k})})]}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[y.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the calendar…`}):c===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic to another day to change when it runs, or onto another schedule's run to move it there. With the keyboard: focus a topic and press Alt+← or Alt+→.`}),EH(new Date(s.from),Q0).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=wH(e),n=j.get(t);return(0,h.jsx)(tme,{date:e,today:t===ie,day:n,dragging:T,busy:N.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(P(kH(T,t,e2.format(e))),E(null))},onStep:F},t)})},wH(e[0]??new Date)))]}):(0,h.jsx)(rme,{days:j,busy:N.isPending,onStep:F,schedules:k,onTransfer:(e,t)=>{e.index!==null&&P({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0})}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(W,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(PH,{label:`Batch queue`,children:A.queued.toSorted((e,t)=>e.position-t.position).map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsx)(OS,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`})},e.projectId)})})]}):null]})]}),(0,h.jsx)(hH,{open:g,onOpenChange:v,schedules:k})]})}function tme({date:e,today:t,day:n,dragging:r,busy:i,onDragStart:a,onDragEnd:o,onDrop:s,onStep:c}){let[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(!1),p=n?.runs??[],g=n?.projects??[],_=d?g:g.slice(0,r2),v=()=>p.find(e=>e.scheduleId===r?.scheduleId)??p[0];return(0,h.jsxs)(`section`,{"aria-label":e2.format(e),className:z(`sl-cal-day`,t&&`sl-cal-day--today`,l&&`sl-cal-day--over`),onDragOver:e=>{r!==null&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,u(!0))},onDragLeave:()=>u(!1),onDrop:e=>{e.preventDefault(),u(!1),s(v())},children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:t?`Today · ${$0.format(e)}`:$0.format(e)}),p.map(e=>(0,h.jsx)(nme,{run:e,busy:i,onDragStart:a,onDragEnd:o,onDrop:t=>{t.preventDefault(),t.stopPropagation(),u(!1),s(e)},onStep:c},`${e.scheduleId}-${e.at}`)),_.map(e=>{let t=bH(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${MH}`,children:[(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${NH}`,children:e.title}),(0,h.jsx)(OS,{tone:t.tone,children:t.word})]},e.id)}),g.length>r2?(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-expanded":d,className:`self-start`,onClick:()=>f(e=>!e),children:d?`Show fewer`:`+${String(g.length-r2)} more`}):null]})}var r2=3;function nme({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=jH(e);return(0,h.jsxs)(`article`,{tabIndex:e.index===null?void 0:0,"aria-label":`${s}, ${t2.format(new Date(e.at))}, ${e.scheduleName}${e.index===null?``:`. Alt+arrow keys move it.`}`,draggable:o,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,s),n(e)},onDragEnd:r,onDragOver:e=>e.preventDefault(),onDrop:i,onKeyDown:t=>{o&&t.altKey&&(t.key===`ArrowLeft`||t.key===`ArrowUp`?(t.preventDefault(),a(e,-1)):(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(t.preventDefault(),a(e,1)))},className:z(`sl-cal-item`,o&&`sl-cal-item--movable`),children:[(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:t2.format(new Date(e.at))}),(0,h.jsx)(`b`,{className:z(`text-small`,e.topic===null&&`font-normal text-ink-2`),children:s}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.scheduleName}),e.paused?(0,h.jsx)(OS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(OS,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(OS,{tone:`off`,children:`Queued`}):(0,h.jsx)(OS,{tone:`info`,children:`Prepared`}),(0,h.jsx)(i2,{run:e,compact:!0})]})}function i2({run:e,compact:t=!1}){let{api:n}=V(),r=_(),[i,a]=(0,m.useState)(),o=L({mutationFn:async()=>{if(e.topic===null)throw Error(`This run has no topic to prepare yet.`);let t=await iH(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:fH}),r.invalidateQueries({queryKey:[`projects`]})},onError:e=>a(e.message)});return e.prepared===null?e.index===null||e.topic===null||e.topicSource!==`queued`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,variant:t?`quiet`:`secondary`,disabled:o.isPending,onClick:e=>{e.stopPropagation(),o.mutate()},children:o.isPending?`Preparing…`:`Prepare`}),i===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-label text-danger`,children:i})]}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}function a2({project:e}){let t=bH(e);return(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(OS,{tone:t.tone,children:t.word}),t.action===void 0?null:t.action.kind===`upload`?(0,h.jsx)(B0,{projectId:e.id,ready:!0}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function rme({days:e,busy:t,schedules:n,onStep:r,onTransfer:i}){let a=[...e.values()].sort((e,t)=>e.key.localeCompare(t.key));if(a.length===0)return(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Nothing is planned for the next `,Q0,` weeks. Add topics with Add to calendar, or create a schedule on the`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`},children:`Schedules`}),` `,`tab.`]});let o=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,...zb,children:[(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Move a topic earlier, later or to another schedule from its row.`,(0,h.jsx)(U,{id:`planning.calendar.move`,className:`-my-1`})]}),a.map(e=>(0,h.jsxs)(`section`,{"aria-label":e2.format(e.date),children:[(0,h.jsx)(W,{title:e2.format(e.date),as:`h3`}),(0,h.jsxs)(PH,{label:`Planned on ${e2.format(e.date)}`,children:[e.runs.map(e=>{let n=jH(e),a=o.filter(t=>t.id!==e.scheduleId);return(0,h.jsx)(FH,{title:n,meta:`${t2.format(new Date(e.at))} · ${e.scheduleName}${e.templateName===null?``:` · ${e.templateName}`}${e.paused?` · Paused`:``}`,actions:e.index===null?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i2,{run:e}),(0,h.jsx)(Py,{size:`small`,label:`Move ${n} earlier`,disabled:t,onClick:()=>r(e,-1),children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{size:`small`,label:`Move ${n} later`,disabled:t,onClick:()=>r(e,1),children:(0,h.jsx)(mc,{"aria-hidden":`true`,strokeWidth:1.75})}),a.length===0?null:(0,h.jsxs)(`select`,{"aria-label":`Move ${n} to another schedule`,className:`sl-select h-8 w-auto text-small`,value:``,disabled:t,onChange:t=>{t.target.value!==``&&i(e,t.target.value)},children:[(0,h.jsx)(`option`,{value:``,children:`Move to…`}),a.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})},`${e.scheduleId}-${e.at}`)}),e.projects.map(e=>(0,h.jsx)(a2,{project:e},e.id))]})]},e.key))]})}var ime=_j.map(e=>({value:e,label:vj[e]}));function ame({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=L({mutationFn:n=>bx(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${vj[e.aiDisclosure]}.`,`success`),n.setQueryData(ax(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:ix,exact:!0})}});return(0,h.jsxs)(`section`,{"aria-label":`YouTube AI disclosure`,className:`mb-6 max-w-3xl border-b border-line pb-5`,children:[(0,h.jsx)(LB,{label:`YouTube AI disclosure`,tip:`planning.channel.ai-disclosure`,help:`Mark voices in Settings → Voices and Image prompts in Library → Prompts.`,children:(0,h.jsx)(VB,{value:i.isPending?i.variables:e.aiDisclosure,options:ime,disabled:i.isPending,onChange:e=>{let t=_j.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(v1,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}function o2({value:e,onChange:t,inherited:n,label:r=`Language`,error:i,disabled:a=!1,tip:o=`play.language`}){let s=e??n?.language;return(0,h.jsx)(LB,{label:r,tip:o,help:ome(s),error:i,children:(0,h.jsxs)(VB,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:MO.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,NO(n.language).name,`)`]}),jO.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function ome(e){let t=NO(e);if(t.code===`en`)return`Everything is written and timed in English.`;let n=`The article, narration, YouTube description and Shorts titles are written in ${t.name}; pick a voice that speaks it.`,r=PO(t.code);return r===void 0?`${n} Captions are timed word by word with a free 248 MB model, downloaded the first time a ${t.name} project makes captions.`:`${n} ${r}`}function sme({rows:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,h.jsxs)(`section`,{"aria-label":`Channel links`,...zb,children:[(0,h.jsx)(W,{title:`Channel links`,meta:`Write a link's name in braces in a description, such as {{Patreon}}.`,info:`planning.links.named`}),e.length===0?(0,h.jsx)(`p`,{className:`m-0 border-y border-line py-4 text-ink-2`,children:`No channel links yet. Add one, then write its name in braces in a description.`}):(0,h.jsx)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:e.map((r,i)=>(0,h.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,1fr)] items-center gap-2 border-b border-line py-3 md:grid-cols-[220px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(zB,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})}),(0,h.jsx)(zB,{"aria-label":`Address of link ${String(i+1)}`,type:`url`,placeholder:`https://`,value:r.url,onChange:e=>n(i,{url:e.currentTarget.value})}),(0,h.jsxs)(B,{variant:`quiet`,size:`small`,className:`justify-self-start`,"aria-label":`Remove link ${String(i+1)}`,onClick:()=>t(e.filter((e,t)=>t!==i)),children:[(0,h.jsx)($c,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(B,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function cme(){return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsx)(W,{title:`Named links`,info:`planning.links.named`}),(0,h.jsx)(`p`,{className:`m-0 max-w-[60ch] text-ink-2`,children:`Each channel keeps its own links now, on its Brand tab under Channel links. Links saved here before fill the default channel's descriptions until you save its Brand tab.`}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsx)(CS,{to:`/channels/$channelId`,params:{channelId:tx},children:`Open the default channel's links`})})]})}function s2({value:e,inherit:t,sources:n,offerNone:r,problem:i,file:a,fieldPrefix:o=`ambientBed`,onChange:s}){let c=e!==void 0&&e.source!==`none`,l={level:e?.level??String(qk.levelDb),fadeIn:e?.fadeIn??String(qk.fadeInSeconds),tail:e?.tail??String(qk.tailSeconds)},u=e=>{if(e===``)s(void 0);else if(e===`none`)s({source:`none`,...l});else{let t=n.find(t=>t===e);t!==void 0&&s({source:t,...l})}},d=(t,n,r,a)=>e===void 0||!c?null:(0,h.jsx)(LB,{label:n,help:r,tip:a,error:i(t),children:(0,h.jsx)(zB,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})})});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(LB,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(VB,{"data-play-field":`${o}.source`,value:e?.source??``,onChange:e=>u(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:t}),r?(0,h.jsx)(`option`,{value:`none`,children:`None`}):null,n.map(e=>(0,h.jsx)(`option`,{value:e,children:Kk[e]},e))]})}),e?.source===`upload`?a:null,c?(0,h.jsxs)(`div`,{className:`contents`,children:[d(`level`,`Level (dB)`,`-40 to -6; 0 is about as loud as the voice.`,`project.ambient.level`),d(`fadeIn`,`Fade in (seconds)`,`0 to 30.`,`project.ambient.fade-in`),d(`tail`,`Tail after the narration (seconds)`,`0 to 30, fading out.`,`project.ambient.tail`)]}):null]})}function lme({value:e,onChange:t}){let n=Qk(e),r=n===void 0?[]:Yk(n);return(0,h.jsx)(s2,{value:e,inherit:`Not set`,sources:Wk,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function ume(e){return e.ambientBed===void 0?void 0:Zk(e.ambientBed)}function dme(e){let t=Qk(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:Yk(t).length>0}}var c2=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`];function fme(e){return Object.fromEntries(c2.map(t=>[t,e[t]??``]))}function pme({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=I({queryKey:eN,queryFn:()=>tN(t)}),a=I(mb(t)),o=I(hb(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(fme(e.brand)),[p,g]=(0,m.useState)(ume(e.brand)),v=dme(p),y=I({queryKey:H.channelLinks,queryFn:()=>Ls(t),enabled:e.isDefault&&e.brand.links===void 0}),[b,x]=(0,m.useState)(),S=b??e.brand.links??y.data??[],C=b!==void 0||e.brand.links!==void 0||(y.data?.length??0)>0,w=L({mutationFn:()=>dx(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(c2.flatMap(e=>d[e].trim()===``?[]:[[e,d[e].trim()]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(ax(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:ix}),n.invalidateQueries({queryKey:H.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),D=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),O=[...(o.data?.builtIns??[]).map(e=>({value:e.name,label:e.label})),...(o.data?.themes??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(`form`,{"aria-label":`Brand kit`,onSubmit:e=>{e.preventDefault(),w.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-5`,children:[(0,h.jsx)(LB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(zB,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(LB,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules.`,children:(0,h.jsx)(BB,{rows:4,value:l,maxLength:1e4,onChange:e=>u(e.target.value)})}),(0,h.jsx)(W,{title:`Brand kit`,meta:`Fills what a template leaves at its default. Blank fields add nothing.`,info:`planning.channel.brand-kit`,className:`mt-2 border-t border-line pt-6`}),(0,h.jsx)(`section`,{"aria-label":`Language`,className:`max-w-md`,children:(0,h.jsx)(o2,{label:`Language of new projects`,tip:`planning.channel.language`,value:d.language===``?void 0:d.language,inherited:{label:`Not set`,language:void 0},onChange:e=>T(`language`)(e??``)})}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:E,onPick:T(`captionFontId`)}),(0,h.jsx)(u2,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(u2,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`)})]}),(0,h.jsxs)(`section`,{"aria-label":`Chapter cards and end screen`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:E,onPick:T(`titleFontId`)}),(0,h.jsx)(u2,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(LB,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(zB,{value:d.endScreenText,maxLength:200,placeholder:`Subscribe for more`,onChange:e=>T(`endScreenText`)(e.target.value)})})]}),(0,h.jsxs)(`section`,{"aria-label":`Intro, outro and document`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:D(`intro`),onPick:T(`intro`)}),(0,h.jsx)(l2,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:D(`outro`),onPick:T(`outro`)}),(0,h.jsx)(l2,{label:`Document theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:O,onPick:T(`documentTheme`)})]}),(0,h.jsx)(lme,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(sme,{rows:S,onChange:x})})]}),(0,h.jsx)(y1,{status:(0,h.jsx)(v1,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(B,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked,disabledReason:s.trim()===``?`Give the channel a name`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function l2({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(LB,{label:e,tip:t,children:(0,h.jsxs)(VB,{value:n,onChange:e=>i(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Not set`}),n!==``&&!r.some(e=>e.value===n)?(0,h.jsxs)(`option`,{value:n,children:[n,` (no longer in the library)`]}):null,r.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))]})})}function u2({label:e,tip:t,value:n,onChange:r}){let i=/^#[0-9a-fA-F]{6}$/.test(n);return(0,h.jsx)(LB,{label:e,tip:t,...n!==``&&!i?{error:`Write the colour as # and six hex digits.`}:{},children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-6 shrink-0 rounded-control border border-line-strong`,style:{background:i?n:`transparent`}}),(0,h.jsx)(zB,{value:n,placeholder:`#FFFFFF`,maxLength:7,onChange:e=>r(e.target.value)})]})})}function d2(e,t){return e.languages===void 0||e.languages.includes(NO(t).code)}function mme(e,t,n,r){return n?e:e.filter(e=>d2(e,t)||e.voiceId===r)}function hme(e,t){if(e===void 0||d2(e,t))return;let n=NO(t).name,r=(e.languages??[]).map(e=>NO(e).code===e?NO(e).name:e);return`${e.name} is listed for ${r.join(`, `)}, not ${n}, so it may read the ${n} narration with the wrong accent. Pick a ${n} voice under Narration, or correct the voice's languages in Settings → Voices.`}function f2(e,t,n){let[r,i]=(0,m.useState)(!1),a=mme(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function p2({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=hme(t,e);return n===0&&!r&&o===void 0?null:(0,h.jsxs)(`div`,{className:`col-span-full grid gap-1`,children:[n>0||r?(0,h.jsxs)(`span`,{className:`flex min-h-8 items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:a,type:`checkbox`,checked:r,onChange:e=>i(e.target.checked)}),`Show all voices`,r?``:` (${String(n)} listed for other languages than ${NO(e).name})`]}),(0,h.jsx)(U,{id:`play.show-all-voices`})]}):null,o===void 0?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:o})]})}function gme({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=V(),o=_(),[s,c]=(0,m.useState)(t?.kind??`character`),[l,u]=(0,m.useState)(t?.name??``),[d,f]=(0,m.useState)(t?.aliases??[]),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(t?.description??``),[b,x]=(0,m.useState)(t?.voice),[S,C]=(0,m.useState)(t?.host===!0),w=()=>Promise.all([o.invalidateQueries({queryKey:ax(e)}),o.invalidateQueries({queryKey:ix})]),T=L({mutationFn:async()=>{let n={kind:s,name:l.trim(),aliases:d,description:v,voice:b!==void 0&&b.provider!==``&&b.model!==``&&b.voice!==``?b:null,host:S};return t===void 0?px(a,e,crypto.randomUUID(),n):mx(a,t.id,{...n,baseVersion:t.version})},onSuccess:async e=>{await w(),t===void 0&&i(e.id)}}),E=()=>{let e=p.trim();e===``||d.some(t=>t.toLowerCase()===e.toLowerCase())||(f([...d,e]),g(``))};return n?(0,h.jsxs)(`section`,{"aria-label":t===void 0?`Add to cast`:`Edit ${t.name}`,children:[(0,h.jsx)(W,{kicker:t===void 0?`New cast member`:rx[t.kind],title:t===void 0?`Add to cast`:t.name,meta:t===void 0?`Name it first, then give it reference pictures.`:`Used whenever a title or an image brief names it or one of its aliases.`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:r,children:`Close`})}),t!==void 0&&!t.images.some(e=>e.state===`ready`)?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-waiting`,children:`No picture yet, so it is not sent with any image. Upload or generate one below.`}):null,(0,h.jsxs)(`form`,{id:`cast-member-form`,"aria-label":`Cast member`,className:`mt-4 flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),l.trim()!==``&&T.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(LB,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(VB,{value:s,onChange:e=>c(nx.find(t=>t===e.target.value)??`character`),options:nx.map(e=>({value:e,label:rx[e]}))})}),(0,h.jsx)(LB,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(zB,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(LB,{label:`Aliases`,tip:`planning.cast.aliases`,help:`Press Enter to add each one.`,children:(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(zB,{value:p,maxLength:200,placeholder:`Another name, such as the Last Pharaoh`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,h.jsxs)(B,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add alias`]})]})}),d.length>0?(0,h.jsx)(`ul`,{"aria-label":`Aliases added`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:d.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(AS,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(LB,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(BB,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(vme,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(Bb,{label:`One of the channel's hosts`,tip:`planning.cast.host`,checked:S,onChange:C}),S&&(b===void 0||b.voice===``)?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`A host joins new podcasts and interviews only with a voice. Pick one under Voice above.`}):null]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(v1,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(B,{type:`submit`,form:`cast-member-form`,variant:t===void 0?`primary`:`secondary`,disabled:T.isPending||l.trim()===``,children:t===void 0?`Add to cast`:`Save`})]})]}),t===void 0?null:(0,h.jsx)(_me,{channelId:e,member:t})]}):null}function _me({channelId:e,member:t}){let{api:n}=V(),r=_(),i=I(db(n)),a=(0,m.useRef)(null),o=(0,m.useRef)(null),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(``),[d,f]=(0,m.useState)(`${t.name}${t.description.trim()?`, ${t.description.trim()}`:``}. A clear reference picture on a plain background, the whole ${t.kind===`place`?`place`:t.kind===`object`?`object`:`figure`} in view.`),p=()=>Promise.all([r.invalidateQueries({queryKey:ax(e)}),r.invalidateQueries({queryKey:ix})]),g=L({mutationFn:e=>gx(n,t.id,e),onSettled:p}),v=L({mutationFn:()=>_x(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=L({mutationFn:e=>vx(n,t.id,e),onSettled:p}),b=g.error??v.error??y.error,x=t.images.flatMap((e,t)=>e.state===`ready`&&e.sha256!==null?[{id:e.id,number:t+1,src:xx(n,e.sha256)}]:[]),[S,C]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Reference pictures`,className:`mt-6`,children:[(0,h.jsx)($K,{className:`mb-6`}),(0,h.jsx)(W,{as:`h3`,title:`Reference pictures`,meta:`Sent with every image whose brief, or the video's title, names ${t.name}.`,info:`planning.cast.pictures`}),t.images.length>0?(0,h.jsx)(u0,{list:!0,density:`compact`,label:`Pictures of ${t.name}`,className:`mt-3`,children:t.images.map((e,r)=>(0,h.jsxs)(`li`,{className:`min-w-0`,children:[(0,h.jsx)(l0,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:xx(n,e.sha256)}:{},...e.state===`generating`?{generating:`Making the picture…`}:{},onOpen:()=>C(x.findIndex(t=>t.id===e.id)),openLabel:`Open picture ${String(r+1)} of ${t.name} full size`,...e.state===`failed`?{badge:(0,h.jsx)(kS,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Delete picture ${String(r+1)} of ${t.name}`,disabled:y.isPending||e.state===`generating`,disabledReason:`Wait until the picture is made`,onClick:()=>y.mutate(e.id),children:`Delete`})}),e.state===`failed`&&e.error?(0,h.jsx)(yme,{error:e.error,retry:s===``||l===``||d.trim()===``?void 0:{run:()=>v.mutate(),busy:v.isPending},onReword:()=>o.current?.focus()}):null]},e.id))}):(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-3`,children:`No pictures yet.`}),(0,h.jsx)(d0,{items:x.map(e=>({src:e.src,alt:`${t.name}, reference ${String(e.number)}`})),index:S,onIndex:C,onClose:()=>C(null),actions:(e,n)=>{let r=x[n];return r===void 0?null:(0,h.jsx)(TS,{href:r.src,download:!0,size:`small`,"aria-label":`Download picture ${String(r.number)} of ${t.name}`,children:`Download`})}}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg`,className:`sr-only`,tabIndex:-1,"aria-hidden":`true`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&g.mutate(t)}}),(0,h.jsx)(B,{disabled:g.isPending,onClick:()=>a.current?.click(),children:`Upload a picture`}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`PNG or JPEG, up to 10 MB.`})]}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,...zb,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(U,{id:`planning.cast.generate`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(tV,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(LB,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,children:(0,h.jsx)(BB,{ref:o,rows:3,value:d,maxLength:4e3,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(B,{disabled:v.isPending||s===``||l===``||d.trim()===``,disabledReason:`Pick an image provider and model, and describe the picture`,onClick:()=>v.mutate(),children:`Generate a picture`})})]}),(0,h.jsx)(v1,{tone:b?`error`:`info`,className:`mt-2`,children:b?.message??(g.isPending?`Uploading…`:v.isSuccess?`The picture is being made; it appears here when it is ready.`:void 0)})]})}function vme({channelId:e,value:t,onChange:n}){let{api:r}=V(),i=I(db(r)),a=I(fb(r)),o=I(lx(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=f2(c,o,s.voice||void 0),u=l.listed;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-3 border-0 border-t border-line p-0 pt-4`,...zb,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(U,{id:`planning.cast.voice`,label:`Cast voice`,className:`-my-1`})]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`For multi-voice runs: pick this member under Speakers on Play.`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Voice provider`,family:`tts`,providers:i.data?.providers??[],value:s.provider,problem:void 0,onPick:e=>n(e===``?void 0:{provider:e,model:``,voice:``})}),(0,h.jsx)(tV,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(ZB,{label:`Voice`,value:s.voice,placeholder:u.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:u.map(e=>({value:e.voiceId,label:e.name})),problem:void 0,onPick:e=>n({...s,voice:e})}),(0,h.jsx)(p2,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(ZB,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:CA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:void 0,onPick:e=>{let{pace:t,...r}=s;n(Number(e)===1?r:{...r,pace:Number(e)})}})]}),t===void 0?null:(0,h.jsx)(B,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function yme({error:e,retry:t,onReword:n}){let r=s1({stage:`images`,reason:e});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 mt-1 text-small text-danger`,children:e}),r===void 0?null:(0,h.jsx)(Iy,{className:`mt-2`,children:(0,h.jsx)(h1,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(B,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}function bme({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=V(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=L({mutationFn:e=>hx(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:ax(e)}),a.invalidateQueries({queryKey:ix})])}}),p=t.find(e=>e.id===c),g=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:xx(i,t)}]:[]}),v=g.map(e=>({src:e.src,alt:e.member.name,caption:`${rx[e.member.kind]} · ${e.member.description||`No description yet`}`})),[y,b]=(0,m.useState)(null),x=c===`new`||p!==void 0;return(0,h.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 min-[1024px]:grid-cols-[minmax(0,1fr)_440px]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:`When a video's title or an image's brief names a member, its pictures go with that image as references, so it looks the same in every video.`}),t.length===0?(0,h.jsx)(T1,{title:`No cast yet`,actions:(0,h.jsx)(B,{variant:`secondary`,onClick:()=>l(`new`),children:`Add to cast`}),children:`Add the characters, creatures, places and objects this channel keeps coming back to.`}):(0,h.jsx)(u0,{label:`Cast`,children:t.map(e=>{let t=e.images.filter(e=>e.state===`ready`),n=t[0]?.sha256;return(0,h.jsx)(l0,{className:z(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...n?{src:xx(i,n)}:{},alt:e.name,onOpen:()=>b(g.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${rx[e.kind]}${e.host===!0?` · Host`:``} · ${String(t.length)} ${t.length===1?`picture`:`pictures`}`,...t.length===0?{badge:(0,h.jsx)(kS,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`})]})},e.id)})}),(0,h.jsx)(d0,{items:v,index:y,onIndex:b,onClose:()=>b(null),actions:(e,t)=>{let n=g[t];return n===void 0?null:(0,h.jsx)(B,{size:`small`,onClick:()=>{b(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(v1,{tone:`error`,className:`mt-2`,children:u?void 0:f.error?.message})]}),(0,h.jsx)(`aside`,{"aria-label":`Cast member editor`,className:`min-w-0`,children:x?(0,h.jsx)(gme,{channelId:e,member:p,open:!0,onClose:()=>l(null),onCreated:e=>l(e)},c??`closed`):t.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Pick a member's Edit to change its names, description and pictures here.`})}),(0,h.jsx)(Hy,{open:u!==null,title:`Delete ${u?.name??`this cast member`}?`,consequence:f.error?.message??`New videos stop using its pictures. Videos already made keep the pictures they were started with.`,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var m2=e=>[`channels`,e,`episodes`],h2=e=>[`channels`,e,`videos`],g2=(e,t)=>`${e.origin}/api/channels/${t}`,_2=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function xme(e,t){return at({queryKey:m2(t),queryFn:async()=>R(await e.fetch(`${g2(e,t)}/episodes`))})}async function Sme(e,t,n){return R(await e.fetch(`${g2(e,t)}/episodes/setting`,_2(`PUT`,{enabled:n})))}async function Cme(e,t,n,r){return R(await e.fetch(`${g2(e,t)}/episodes/${encodeURIComponent(n)}`,_2(`PUT`,{summary:r})))}async function wme(e,t,n){let r=await e.fetch(`${g2(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await R(r)}function v2(e,t){return at({queryKey:h2(t),queryFn:async()=>(await R(await e.fetch(`${g2(e,t)}/videos`))).videos})}async function Tme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos`,_2(`POST`,n)))}async function Eme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos/preview`,_2(`POST`,{format:`csv`,text:n})))}async function Dme(e,t,n){let r=await e.fetch(`${g2(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await R(r)}async function Ome(e,t){await R(await e.fetch(`${g2(e,t)}/videos`,{method:`DELETE`}))}var kme=e=>e.length>160?`${e.slice(0,160)}…`:e;function Ame({channelId:e}){let{api:t}=V(),n=_(),r=I(xme(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:m2(e)}),l=L({mutationFn:n=>Sme(t,e,n),onSuccess:t=>n.setQueryData(m2(e),t)}),u=L({mutationFn:n=>wme(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(Bb,{checked:d,disabled:r.data===void 0||l.isPending,onChange:e=>l.mutate(e),label:`Episode memory`,tip:`planning.channel.episode-memory`,describedBy:`${e}-memory-help`}),(0,h.jsx)(`p`,{id:`${e}-memory-help`,className:`mt-1 mb-3 text-small text-ink-2`,children:`Finished episodes leave a short summary that new related episodes are written with.`}),(0,h.jsx)(v1,{tone:r.error||l.error||u.error?`error`:`info`,children:r.error?.message??l.error?.message??(o?void 0:u.error?.message)??(r.isPending?`Loading the episodes…`:void 0)}),r.data&&f.length===0?(0,h.jsx)(T1,{title:`No episodes remembered yet`,children:d?`When a video on this channel finishes, its summary appears here.`:`Turn on episode memory, and the next finished video's summary appears here.`}):null,f.length>0?(0,h.jsx)(PH,{label:`Episode summaries`,children:f.map(e=>(0,h.jsx)(FH,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,kme(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(B,{size:`small`,variant:`quiet`,"aria-label":`Delete the summary of ${e.title}`,onClick:()=>{u.reset(),s(e)},children:`Delete`})]})},e.id))}):null,i?(0,h.jsx)(jme,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(Hy,{open:o!==null,title:`Delete the summary of ${o?.title??`this episode`}?`,consequence:u.error?.message??`New episodes stop being reminded of it. The video itself is not changed.`,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function jme({channelId:e,memory:t,onClose:n}){let{api:r}=V(),i=_(),[a,o]=(0,m.useState)(t.summary),s=L({mutationFn:()=>Cme(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:m2(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Vy,{open:!0,onOpenChange:e=>{e||n()},title:t.title,description:t.source===`edited`?`You edited this summary; finishing the video again keeps your text.`:`Written by the text model when the video finished. An edit here is kept.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{onClick:n,children:`Close`}),(0,h.jsx)(B,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(LB,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(BB,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}var y2=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function b2(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function Mme({channelId:e}){let{api:t}=V(),n=_(),r=I(v2(t,e)),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(void 0),u=(0,m.useRef)(null),d=()=>n.invalidateQueries({queryKey:h2(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=L({mutationFn:n=>Tme(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${y2(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=L({mutationFn:n=>Eme(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:b2(e.titles,e.filter)})}}),x=L({mutationFn:n=>Dme(t,e,n),onSuccess:d}),S=L({mutationFn:()=>Ome(t,e),onSuccess:async()=>{s(!1),await d()}}),C=r.data??[],w=y.isPending||b.isPending||x.isPending||S.isPending,T=r.error??b.error??y.error??x.error;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`Topic suggestions and duplicate checks skip these titles, as they skip the videos made here.`}),(0,h.jsx)(LB,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(BB,{rows:5,value:i,onChange:e=>a(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{variant:`primary`,disabled:w||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(B,{disabled:w,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(U,{id:`planning.channel.videos-csv`}),(0,h.jsx)(`input`,{ref:u,type:`file`,accept:`.csv,text/csv`,className:`hidden`,"aria-label":`YouTube Studio CSV file`,onChange:async e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&(l(void 0),y.reset(),b.mutate(await t.text()))}}),(0,h.jsx)(B,{variant:`quiet`,disabled:w||C.length===0,onClick:()=>{S.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(v1,{tone:T?`error`:c?`success`:`info`,className:`mt-1`,children:T?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(Nme,{preview:f,filter:g,busy:w,onFilter:e=>{v(e),p({...f,ticked:b2(f.titles,e)})},onTick:e=>p({...f,ticked:e}),onSave:()=>{l(void 0);let e=f.titles.filter((e,t)=>f.ticked[t]);y.mutate({text:e.join(`
273
- `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(T1,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(PH,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(FH,{title:e.title,actions:(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(Hy,{open:o,title:`Remove all ${y2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function Nme({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...zb,children:[(0,h.jsxs)(W,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${y2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(B,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,y2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(B,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(LB,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(zB,{value:t,maxLength:200,onChange:e=>r(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(PH,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(FH,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}function x2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:z(`sl-stats m-0`,e),children:t})}function S2({value:e,label:t,children:n}){return(0,h.jsxs)(`div`,{className:`sl-stat`,children:[(0,h.jsx)(`dt`,{className:`sl-stat__label order-2`,children:t}),(0,h.jsx)(`dd`,{className:`sl-stat__value order-1 m-0`,children:e}),n===void 0?null:(0,h.jsx)(`dd`,{className:`order-3 m-0 mt-1`,children:n})]})}function C2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:z(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function w2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:z(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}var T2=56,E2=12,D2=12,Pme=28;function Fme(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=5?5:10)*r}function O2({series:e,xLabels:t,formatValue:n,label:r,height:i=260,legend:a=!0,className:o}){let s=(0,m.useRef)(null),[c,l]=(0,m.useState)(800),[u,d]=(0,m.useState)();(0,m.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([e])=>{e!==void 0&&l(Math.max(320,Math.round(e.contentRect.width)))});return t.observe(e),()=>t.disconnect()},[]);let f=t.length,p=Math.max(0,...e.flatMap(e=>e.values.filter(e=>e!==null))),g=Fme(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-T2-E2,y=e=>T2+(f<=1?0:e/(f-1)*v),b=e=>D2+i-e/_*i,x=Array.from({length:Math.round(_/g)+1},(e,t)=>t*g),S=Math.min(f,Math.max(2,Math.floor(v/90))),C=Array.from({length:S},(e,t)=>Math.round(t/Math.max(1,S-1)*(f-1))),w=e=>{let t=``,n=!1;return e.forEach((e,r)=>{if(e===null){n=!1;return}t+=`${n?`L`:`M`}${y(r).toFixed(1)},${b(e).toFixed(1)}`,n=!0}),t},T=D2+i+Pme,E=u===void 0?[]:e.map(e=>({one:e,value:e.values[u]??null})).filter(e=>e.value!==null).toSorted((e,t)=>t.value-e.value);return(0,h.jsxs)(`figure`,{className:z(`m-0 flex flex-col gap-2`,o),children:[(0,h.jsxs)(`div`,{ref:s,className:`relative w-full`,children:[(0,h.jsxs)(`svg`,{role:`img`,"aria-label":r,width:c,height:T,viewBox:`0 0 ${String(c)} ${String(T)}`,className:`block select-none`,onMouseLeave:()=>d(void 0),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=Math.round((e.clientX-t.left-T2)/v*(f-1));d(n<0||n>=f?void 0:n)},children:[x.map(e=>(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:T2,x2:c-E2,y1:b(e),y2:b(e),stroke:`currentColor`,className:`text-line`,strokeWidth:`1`}),(0,h.jsx)(`text`,{x:48,y:b(e),textAnchor:`end`,dominantBaseline:`middle`,className:`fill-ink-3 text-[11px]`,children:n(e)})]},e)),C.map(e=>(0,h.jsx)(`text`,{x:y(e),y:D2+i+18,textAnchor:e===0?`start`:e===f-1?`end`:`middle`,className:`fill-ink-3 text-[11px]`,children:t[e]},e)),e.map(e=>(0,h.jsx)(`path`,{d:w(e.values),fill:`none`,stroke:e.color,strokeWidth:`1.75`,strokeLinejoin:`round`},e.id)),u===void 0?null:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:y(u),x2:y(u),y1:D2,y2:D2+i,stroke:`currentColor`,className:`text-ink-3`,strokeDasharray:`3 3`}),E.map(({one:e,value:t})=>(0,h.jsx)(`circle`,{cx:y(u),cy:b(t),r:`3.5`,fill:e.color},e.id))]})]}),u===void 0||E.length===0?null:(0,h.jsxs)(`div`,{className:`pointer-events-none absolute top-2 z-10 w-[340px] rounded-control border border-line bg-surface p-2 text-small shadow-md`,style:y(u)>c/2?{right:c-y(u)+12}:{left:y(u)+12},children:[(0,h.jsx)(`div`,{className:`mb-1 font-semibold`,children:t[u]}),E.map(({one:e,value:t})=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 shrink-0 rounded-full`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),(0,h.jsx)(`span`,{className:`tabular-nums`,children:n(t)})]},e.id))]})]}),a?(0,h.jsx)(`figcaption`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-small text-ink-2`,children:e.map(e=>(0,h.jsxs)(`span`,{className:`flex max-w-[320px] items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-[3px] w-4 shrink-0 rounded`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))}):null]})}var k2=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function Ime(e,t){return R(await e.fetch(k2(e,t)))}async function Lme(e,t,n){return R(await e.fetch(k2(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}function A2(e,t,n){if(e===null)return`–`;if(typeof e==`string`)return e;if(t===`duration`){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=String(Math.round(e%60)).padStart(2,`0`);return t>0?`${String(t)}:${String(n).padStart(2,`0`)}:${r}`:`${String(n)}:${r}`}let r=/%|\(|rpm|revenue|hours/i.test(n)&&!Number.isInteger(e)?1:0;return e.toLocaleString(`en`,{minimumFractionDigits:r,maximumFractionDigits:r})}var j2=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],M2=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),N2=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function P2(e,t){if(t===`total`){let t=0;return e.map(e=>t+=e)}return t===`average`?e.map((t,n)=>{let r=e.slice(Math.max(0,n-6),n+1);return r.reduce((e,t)=>e+t,0)/r.length}):[...e]}function Rme({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,d=t.filter(e=>n.includes(e.videoId)),f=e.from===null?new Date:new Date(`${e.from}T00:00:00`),p=Math.max(0,...t.map(e=>e.daily.length)),m,g;if(o===`dates`){let e=c===`all`?0:Math.max(0,p-Number(c)),t=p-e>200;m=Array.from({length:p-e},(n,r)=>{let i=new Date(f);return i.setDate(i.getDate()+e+r),(t?N2:M2).format(i)}),g=d.map(t=>{let n=t.daily.findIndex(e=>e>0),a=P2(t.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:t.videoId,label:t.title,color:r(t.videoId),values:a.slice(e)}})}else{let e=Math.max(1,...d.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));m=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),g=d.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=P2(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let _=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:_}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(VB,{"aria-label":`Show`,className:`w-[200px]`,value:i,onChange:e=>a(e.currentTarget.value),options:[{value:`average`,label:`7-day average`},{value:`daily`,label:`Per day`},{value:`total`,label:`Running total`}]}),(0,h.jsx)(VB,{"aria-label":`Timeline`,className:`w-[220px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:`dates`,label:`By date`},{value:`since`,label:`Days since release`}]}),(0,h.jsx)(VB,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),d.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(O2,{series:g,xLabels:m,label:`${_} for ${String(d.length)} videos`,formatValue:F2})]})}var F2=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function zme({report:e,rows:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`);return(0,h.jsxs)(`section`,{"aria-label":`Each video`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Each video · ${a}`}),t.some(e=>!e.daily.some(e=>e>0))?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart more, tick them in Advanced mode's chart before you export.`}):null,(0,h.jsx)(`div`,{className:`grid gap-6 lg:grid-cols-2`,children:t.map(e=>{let t=e.daily.findIndex(e=>e>0);if(t<0)return null;let s=P2(e.daily.slice(t),n),c=r===`all`?0:Math.max(0,s.length-Number(r)),l=s.slice(c),u=l.map((e,n)=>{let r=new Date(o);return r.setDate(r.getDate()+t+c+n),(l.length>200?N2:M2).format(r)}),d=e.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 shrink-0 rounded-full`,style:{background:i(e.videoId)}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold`,title:e.title,children:e.title}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`${d.toLocaleString(`en`)} total`})]}),(0,h.jsx)(O2,{height:150,legend:!1,label:`${a} for ${e.title}`,xLabels:u,formatValue:F2,series:[{id:e.videoId,label:e.title,color:i(e.videoId),values:l}]})]},e.videoId)})})]})}var I2=e=>`slopify.studioReport.hidden.${e}`;function Bme(e){try{let t=window.localStorage.getItem(I2(e));return t===null?void 0:JSON.parse(t)}catch{return}}function L2({channelId:e}){let{api:t}=V(),n=_(),r=Ry(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=I({queryKey:a,queryFn:()=>Ime(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(()=>Bme(e)),S=L({mutationFn:n=>Lme(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),C=o.data?.report??null,w=C?.columns??[],T=w.filter((e,t)=>(C?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),E=b??T,D=t=>{x(t);try{window.localStorage.setItem(I2(e),JSON.stringify(t))}catch{}},O=w.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!E.includes(e.label)),k=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},A=[...C?.rows??[]].toSorted((e,t)=>k(t,s)-k(e,s)),j=[...C?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),M=l??j.slice(0,5).map(e=>e.videoId),ee=e=>{let t=(C?.rows??[]).findIndex(t=>t.videoId===e);return j2[(t<0?0:t)%j2.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(W,{as:`h3`,title:`From Studio's export`,meta:C===null?void 0:`${String(C.rows.length)} videos · ${C.from??`?`} to ${C.to??`?`} · imported ${new Date(C.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&S.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(B,{type:`button`,variant:`secondary`,disabled:S.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(tl,{"aria-hidden":`true`,strokeWidth:1.75}),S.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),C===null?null:(0,h.jsxs)(h.Fragment,{children:[C.chartMetric===null?null:(0,h.jsx)(Rme,{report:C,rows:A,picked:M,colorOf:ee,shape:d,setShape:f,timeline:p,setTimeline:g,range:v,setRange:y}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(VB,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:w.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(O.length),` of `,String(w.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:w.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!E.includes(e.label),onChange:t=>D(t.currentTarget.checked?E.filter(t=>t!==e.label):[...E,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[C.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),O.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[C.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),O.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:A2(C.totals[t]??null,e.kind,e.label)},e.label))]}),A.map(e=>{let t=o.data?.projects[e.videoId];return(0,h.jsxs)(`tr`,{children:[C.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:M.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...M,e.videoId]:M.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:M.includes(e.videoId)?ee(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),O.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:A2(e.values[n]??null,t.kind,t.label)},t.label))]},e.videoId)})]})]})}),C.chartMetric===null?null:(0,h.jsx)(zme,{report:C,rows:A,shape:d,range:v,colorOf:ee})]})]})}var R2=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),z2=e=>e==null?`–`:`${e.toFixed(1)}%`;function B2(e){if(e==null)return`–`;let t=Math.round(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}var Vme=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),V2=e=>e===null?`–`:Vme.format(new Date(e));function H2({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(x2,{children:[(0,h.jsx)(S2,{value:R2(t.views),label:`Views`}),(0,h.jsx)(S2,{value:R2(t.impressions),label:`Impressions`}),(0,h.jsx)(S2,{value:z2(t.ctr),label:`Click-through rate`}),(0,h.jsx)(S2,{value:B2(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(S2,{value:R2(t.watchHours),label:`Watch hours`})]})]})}var U2=(e,t)=>{let n=e.long?.stats??null;return t===`views`?(n?.views??0)+e.shorts.reduce((e,t)=>e+(t.stats?.views??0),0):t===`ctr`?n?.ctr??-1:t===`duration`?n?.averageViewSeconds??-1:Date.parse(e.long?.releasedAt??e.shorts[0]?.releasedAt??``)||0};function Hme({channelId:e}){let{api:t}=V(),[n,r]=(0,m.useState)(`newest`),i=I({queryKey:[`studio`,`performance`,e],queryFn:()=>hs(t,e)});if(i.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the numbers…`});if(i.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The numbers didn't load: `,i.error.message,` Reload the page to try again.`]});let a=i.data;if(a.projects.length===0)return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(L2,{channelId:e}),(0,h.jsx)(T1,{title:`No video of this channel is known on YouTube yet`,children:`Upload with the Slopify Studio extension, or open YouTube Studio's Content list once so the extension links your videos. Their numbers then arrive daily, or at once with Read Studio numbers now in the extension's popup.`})]});let o=a.projects.toSorted((e,t)=>U2(t,n)-U2(e,n)).flatMap(e=>[...e.long===null?[]:[{key:`${e.projectId}-0`,projectId:e.projectId,row:e.long,isShort:!1}],...e.shorts.map(t=>({key:`${e.projectId}-${String(t.short??0)}`,projectId:e.projectId,row:t,isShort:!0}))]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Studio's numbers as the Slopify Studio extension last read them`,a.readAt===null?``:` (newest ${V2(a.readAt)})`,`: daily while Chrome is open, or at once with Read Studio numbers now in the extension's popup. "–" is a number Studio doesn't show for that video (most shorts have no click-through rate).`]}),(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,h.jsx)(H2,{label:`Long videos`,totals:a.long}),(0,h.jsx)(H2,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(L2,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:`Every video`,children:(0,h.jsx)(VB,{"aria-label":`Order`,value:n,onChange:e=>r(e.currentTarget.value),options:[{value:`newest`,label:`Newest first`},{value:`views`,label:`Most views`},{value:`ctr`,label:`Best click-through rate`},{value:`duration`,label:`Longest average view`}]})}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{columns:[{id:`title`,header:`Video`,cell:e=>e.isShort?(0,h.jsx)(`span`,{className:`block pl-5 text-small text-ink-2`,children:`Short ${String(e.row.short??``)} · ${e.row.title}`}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>V2(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>R2(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>z2(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>R2(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>B2(e.row.stats?.averageViewSeconds)},{id:`hours`,header:`Watch hours`,numeric:!0,cell:e=>e.row.stats?.watchHours===null||e.row.stats?.watchHours===void 0?`–`:e.row.stats.watchHours.toFixed(1)}],rows:o,rowKey:e=>e.key,caption:`The channel's videos and shorts with Studio's numbers`})})]})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],Ume={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function Wme(e){return W2.find(t=>t===e)??`brand`}function Gme({channelId:e,tab:t,onTab:n}){let{api:r}=V(),i=_(),a=Ji(),o=I(lx(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=L({mutationFn:()=>fx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:ix}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return jx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(fa,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(B,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(C1,{items:W2.map(e=>({id:e,label:Ume[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(v1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(w1,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(ame,{channel:f}),(0,h.jsx)(pme,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(bme,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(wfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Dfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Ame,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(Mme,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(Hme,{channelId:f.id}):null})]}):null,(0,h.jsx)(Hy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function Kme(){let{api:e}=V(),t=_(),n=Ji(),r=I(cx(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=L({mutationFn:()=>ux(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:ix}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=L({mutationFn:t=>dx(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:ix}),a(null)}}),v=L({mutationFn:t=>fx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:ix})}}),y=()=>{p.reset(),l(``),a(`new`)};jx({id:`channels.new`,title:`New channel`,group:`Channels`,run:y});let b=i===`new`?p:g,x=()=>{c.trim()!==``&&i!==null&&(i===`new`?p.mutate():g.mutate(i))};return(0,h.jsxs)(`div`,{"data-tour":`channels`,children:[(0,h.jsx)(XK,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(U,{id:`planning.channels`})]}),actions:(0,h.jsxs)(B,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(v1,{tone:r.error||v.error?`error`:`info`,className:`mb-2`,children:r.error?`The channels couldn't be loaded: ${r.error.message} Reload the page to try again.`:o===null&&v.error?v.error.message:r.isPending?`Loading channels…`:void 0}),r.data?.length===0?(0,h.jsx)(T1,{title:`No channels yet`,actions:(0,h.jsx)(B,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(QK,{list:(0,h.jsx)(PH,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(FH,{selected:e.id===f?.id,onSelect:()=>d(e.id),title:e.name,meta:`${e.isDefault?`Default · `:``}${String(e.templates)} ${e.templates===1?`template`:`templates`} · ${String(e.cast)} in the cast`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(qme,{channel:f})}):null,(0,h.jsx)(Vy,{open:i!==null,onOpenChange:e=>{!e&&!b.isPending&&a(null)},title:i===`new`||i===null?`New channel`:`Rename ${i.name}`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(B,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(B,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(LB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(zB,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Hy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function qme({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(W,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(CS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(x2,{className:`mb-6`,children:[(0,h.jsx)(S2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(S2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(W,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(W,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var G2=2e3;function K2(e,t){let n=(0,m.useRef)(t);(0,m.useEffect)(()=>{n.current=t}),(0,m.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{n.current()},G2);return()=>{clearTimeout(t)}},[e])}function q2(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(Sc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function J2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Ry();jx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:nP.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(B,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(v1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(q2,{}):t)}),a,(0,h.jsx)(B,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Ux(nP.save),onClick:()=>{c||s()},children:`Save`})]})}var Jme=`rounded-media border border-line bg-surface p-4`;function Y2(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${Jme} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var Yme=`modulepreload`,Xme=function(e){return`/`+e},X2={},Z2=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Xme(t,n),t=s(t),t in X2)return;X2[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Yme,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Zme({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return Qme(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function Qme(e,t){let n=await Z2(()=>import(`./pdf-DlfMpxou.js`),[]),r=await Z2(()=>import(`./pdf.worker.min-zC6nfbxG.js`),[]);n.GlobalWorkerOptions.workerSrc=r.default;let i=n.getDocument({data:e.slice()}),a=await i.promise;try{let e=window.devicePixelRatio||1,n=[];for(let r=1;r<=a.numPages;r+=1){let i=await a.getPage(r),o=i.getViewport({scale:t*e/i.getViewport({scale:1}).width}),s=window.document.createElement(`canvas`);s.width=Math.floor(o.width),s.height=Math.floor(o.height),await i.render({canvas:s,viewport:o}).promise,n.push(s)}return n}finally{await i.destroy()}}var Q2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),$2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),e4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),t4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),n4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),i4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),$me=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},Q2([`page`,`margin`],`Margins`),Q2([`page`,`contentTop`],`Text starts at`,`From the top, on pages with the header.`),{kind:`choice`,path:[`background`,`image`],label:`Background`,options:[{value:`parchment`,label:`Parchment texture`},{value:null,label:`Flat colour`}]},{kind:`color`,path:[`background`,`color`],label:`Page colour`,help:`Used when the background is a flat colour.`}]},{title:`Colours`,fields:[{kind:`color`,path:[`colors`,`heading`],label:`Headings`,help:`Also drop caps, the brand name and links.`},{kind:`color`,path:[`colors`,`text`],label:`Body text`},{kind:`color`,path:[`colors`,`muted`],label:`Muted`,help:`Dates, bullets, quotes and the dots in the contents.`},{kind:`color`,path:[`colors`,`faint`],label:`Faint`,help:`Running header and page numbers.`}]},{title:`Fonts`,fields:[i4(`body`,`Body`),i4(`strong`,`Bold text`),i4(`emphasis`,`Italic text`),i4(`heading`,`Headings`),i4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),i4(`decorative`,`Tagline and title-page link`),i4(`dropCap`,`Drop caps`),i4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[$2([`sizes`,`title`],`Title`),$2([`sizes`,`brand`],`Brand`),$2([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),$2([`sizes`,`heading`],`Second-level headings`),$2([`sizes`,`subheading`],`Third-level headings`),$2([`sizes`,`body`],`Body`),$2([`sizes`,`meta`],`Date and word count`),$2([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[Q2([`spacing`,`bodyLine`],`Body line height`),Q2([`spacing`,`headingLine`],`Heading line height`),Q2([`spacing`,`subheadingLine`],`Subheading line height`),e4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),e4([`spacing`,`headingGap`],`Before a heading`,`× line`),e4([`spacing`,`itemGap`],`After a list item`,`× line`),Q2([`spacing`,`listIndent`],`List indent`),Q2([`spacing`,`quoteIndent`],`Quote indent`),Q2([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[t4([`dropCap`,`enabled`],`Drop caps`,`A large first letter after each heading.`),{kind:`choice`,path:[`dropCap`,`lines`],label:`Lines tall`,options:[{value:2,label:`2 lines`},{value:3,label:`3 lines`},{value:4,label:`4 lines`}]},e4([`dropCap`,`scale`],`Letter size`,`× lines`),Q2([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},e4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[Q2([`titlePage`,`brandY`],`Brand from top`),Q2([`titlePage`,`taglineOffset`],`Tagline below brand`),Q2([`titlePage`,`titleY`],`Title from top`),Q2([`titlePage`,`titleLine`],`Title line height`),Q2([`titlePage`,`metaOffset`],`Details below title`),Q2([`titlePage`,`metaLine`],`Details line height`),t4([`titlePage`,`showDate`],`Show the date`),t4([`titlePage`,`showWordCount`],`Show the word count`),t4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),Q2([`titlePage`,`cover`,`gap`],`Space around cover`),Q2([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[r4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),r4([`brand`,`tagline`],`Tagline`),r4([`brand`,`url`],`Website`,`Where the brand and its link go.`),r4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[t4([`contents`,`enabled`],`Contents page`),n4([`contents`,`title`],`Title`),{kind:`choice`,path:[`contents`,`depth`],label:`Lists headings down to`,options:[{value:1,label:`Top level`},{value:2,label:`Second level`},{value:3,label:`Third level`}]},Q2([`contents`,`titleOffset`],`Title from top margin`),Q2([`contents`,`firstEntryOffset`],`First entry from top margin`),Q2([`contents`,`line`],`Line height`),Q2([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[t4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),Q2([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},t4([`footer`,`enabled`],`Page numbers`),n4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),Q2([`footer`,`bottom`],`From the bottom`),Q2([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[t4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),n4([`sources`,`title`],`Title`),Q2([`sources`,`titleOffset`],`Title from top margin`),Q2([`sources`,`bodyOffset`],`List from top margin`),Q2([`sources`,`line`],`Line height`),Q2([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[t4([`endPage`,`enabled`],`Closing page`),n4([`endPage`,`title`],`Title`),{kind:`lines`,path:[`endPage`,`lines`],label:`Text`,help:`One line each. Start with "•" for a bullet, end with ":" for a bold label, leave a line empty for a gap.`},t4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},r4([`endPage`,`closing`],`Closing line`),Q2([`endPage`,`titleOffset`],`Title from top margin`),Q2([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[n4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),n4([`metadata`,`subject`],`Subject`),n4([`metadata`,`keywords`],`Keywords`),n4([`metadata`,`creator`],`Creator`)]}],a4=Kj.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function o4(e){let t={normal:`Regular`,medium:`Medium`,bold:`Bold`,black:`Black`,italic:`Italic`,bolditalic:`Bold italic`};return(e===`Cinzel`?[`normal`,`medium`,`bold`,`black`]:[`normal`,`bold`,`italic`,`bolditalic`]).map(e=>({value:e,label:t[e]}))}function ehe(e,t){let n=e;for(let e of t)n=n?.[e];return n}function s4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:s4(a,i,n)}}function the(e){let t=eM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function c4(e){return`values.${e.join(`.`)}`}var l4=`pt-1`,u4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function d4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Tc,{"aria-hidden":`true`}),e]})}function f4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(aI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function p4({themeId:e,from:t,onLeave:n}){let{api:r}=V(),i=_(),a=I(hb(r)),o=(0,m.useId)(),[s,c]=(0,m.useState)(void 0),[l,u]=(0,m.useState)([]),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),v=a.data,y=e===void 0?void 0:v?.themes.find(t=>t.id===e),b=e===void 0?v?.themes.find(e=>e.id===t)??v?.builtIns.find(e=>e.name===(t??`plain`))??v?.builtIns[0]:y,x=b===void 0?void 0:{name:e===void 0?`${`label`in b?b.label:b.name} copy`:b.name,values:b.values},S=s??x,C=L({mutationFn:t=>Js(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:hb(r).queryKey})}}),w=L({mutationFn:e=>Ys(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:hb(r).queryKey}),n()}});K2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:eM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:cC(S.name),...T===void 0||T.success?[]:T.error.issues.map(e=>({field:`values.${e.path.join(`.`)}`,message:e.message})),...l];if(a.error!==null)return(0,h.jsx)(g4,{children:a.error.message});if(v===void 0)return(0,h.jsx)(Y2,{});if(S===void 0)return(0,h.jsx)(g4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(LB,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),$me.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>m4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(ihe,{field:e,theme:S.values,problem:m4(E,e.path),onChange:t=>{D({...S,values:t},c4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(CS,{to:`/document-themes`,variant:`secondary`,children:`Cancel`}),errors:[C.error,w.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{C.mutate(S)}})]}),(0,h.jsx)(rhe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(Hy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var nhe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function m4(e,t){let n=c4(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function rhe({values:e}){let{api:t}=V(),[n,r]=(0,m.useState)(),[i,a]=(0,m.useState)(`busy`),[o,s]=(0,m.useState)(void 0),c=e===void 0?void 0:JSON.stringify(e);(0,m.useEffect)(()=>{if(c===void 0)return;let e=new AbortController,n=window.setTimeout(()=>{a(`busy`),Xs(t,JSON.parse(c),e.signal).then(async e=>({bytes:new Uint8Array(await e.arrayBuffer()),blob:e})).then(({bytes:t,blob:n})=>{e.signal.aborted||r({bytes:t,url:URL.createObjectURL(n)})},t=>{e.signal.aborted||(s(t instanceof Error?t.message:String(t)),a(`failed`))})},450);return()=>{window.clearTimeout(n),e.abort()}},[t,c]),(0,m.useEffect)(()=>()=>{n!==void 0&&URL.revokeObjectURL(n.url)},[n]);let l=(0,m.useCallback)(e=>{if(e===void 0){a(`idle`);return}s(e.message),a(`failed`)},[]),u=e===void 0?`Paused until the highlighted settings are fixed.`:i===`busy`?`Updating…`:i===`failed`?`The preview couldn't be made: ${o??`unknown error`}`:`A sample article with this theme. Your projects use their own text and thumbnail.`;return(0,h.jsxs)(`div`,{className:u4,children:[(0,h.jsx)(W,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(TS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open full size`]})}),(0,h.jsx)(`div`,{className:`max-h-[calc(100vh-220px)] min-h-[320px] overflow-y-auto rounded-media bg-sunken p-3`,children:(0,h.jsx)(Zme,{data:n?.bytes,label:`The sample article laid out with this theme`,onDrawn:l})}),(0,h.jsx)(`p`,{role:`status`,className:i===`failed`?`m-0 text-small text-danger`:`m-0 text-small text-ink-2`,children:u})]})}function ihe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=ehe(t,e.path),o=nhe[c4(e.path)],s=o===void 0?null:(0,h.jsx)(U,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(s4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=the(e.path);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(zB,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(zB,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(VB,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=o4(t.family);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(VB,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=a4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=o4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:a4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(VB,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(zB,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(BB,{...d,rows:8,value:Array.isArray(a)?a.join(`
273
+ `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(T1,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(PH,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(FH,{title:e.title,actions:(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(Hy,{open:o,title:`Remove all ${y2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function Nme({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...zb,children:[(0,h.jsxs)(W,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${y2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(B,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,y2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(B,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(LB,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(zB,{value:t,maxLength:200,onChange:e=>r(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(PH,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(FH,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}function x2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:z(`sl-stats m-0`,e),children:t})}function S2({value:e,label:t,children:n}){return(0,h.jsxs)(`div`,{className:`sl-stat`,children:[(0,h.jsx)(`dt`,{className:`sl-stat__label order-2`,children:t}),(0,h.jsx)(`dd`,{className:`sl-stat__value order-1 m-0`,children:e}),n===void 0?null:(0,h.jsx)(`dd`,{className:`order-3 m-0 mt-1`,children:n})]})}function C2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:z(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function w2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:z(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}var T2=56,E2=12,D2=12,Pme=28;function Fme(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=5?5:10)*r}function O2({series:e,xLabels:t,formatValue:n,label:r,height:i=260,legend:a=!0,className:o}){let s=(0,m.useRef)(null),[c,l]=(0,m.useState)(800),[u,d]=(0,m.useState)();(0,m.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([e])=>{e!==void 0&&l(Math.max(320,Math.round(e.contentRect.width)))});return t.observe(e),()=>t.disconnect()},[]);let f=t.length,p=Math.max(0,...e.flatMap(e=>e.values.filter(e=>e!==null))),g=Fme(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-T2-E2,y=e=>T2+(f<=1?0:e/(f-1)*v),b=e=>D2+i-e/_*i,x=Array.from({length:Math.round(_/g)+1},(e,t)=>t*g),S=Math.min(f,Math.max(2,Math.floor(v/90))),C=Array.from({length:S},(e,t)=>Math.round(t/Math.max(1,S-1)*(f-1))),w=e=>{let t=``,n=!1;return e.forEach((e,r)=>{if(e===null){n=!1;return}t+=`${n?`L`:`M`}${y(r).toFixed(1)},${b(e).toFixed(1)}`,n=!0}),t},T=D2+i+Pme,E=u===void 0?[]:e.map(e=>({one:e,value:e.values[u]??null})).filter(e=>e.value!==null).toSorted((e,t)=>t.value-e.value);return(0,h.jsxs)(`figure`,{className:z(`m-0 flex flex-col gap-2`,o),children:[(0,h.jsxs)(`div`,{ref:s,className:`relative w-full`,children:[(0,h.jsxs)(`svg`,{role:`img`,"aria-label":r,width:c,height:T,viewBox:`0 0 ${String(c)} ${String(T)}`,className:`block select-none`,onMouseLeave:()=>d(void 0),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=Math.round((e.clientX-t.left-T2)/v*(f-1));d(n<0||n>=f?void 0:n)},children:[x.map(e=>(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:T2,x2:c-E2,y1:b(e),y2:b(e),stroke:`currentColor`,className:`text-line`,strokeWidth:`1`}),(0,h.jsx)(`text`,{x:48,y:b(e),textAnchor:`end`,dominantBaseline:`middle`,className:`fill-ink-3 text-[11px]`,children:n(e)})]},e)),C.map(e=>(0,h.jsx)(`text`,{x:y(e),y:D2+i+18,textAnchor:e===0?`start`:e===f-1?`end`:`middle`,className:`fill-ink-3 text-[11px]`,children:t[e]},e)),e.map(e=>(0,h.jsx)(`path`,{d:w(e.values),fill:`none`,stroke:e.color,strokeWidth:`1.75`,strokeLinejoin:`round`},e.id)),u===void 0?null:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:y(u),x2:y(u),y1:D2,y2:D2+i,stroke:`currentColor`,className:`text-ink-3`,strokeDasharray:`3 3`}),E.map(({one:e,value:t})=>(0,h.jsx)(`circle`,{cx:y(u),cy:b(t),r:`3.5`,fill:e.color},e.id))]})]}),u===void 0||E.length===0?null:(0,h.jsxs)(`div`,{className:`pointer-events-none absolute top-2 z-10 w-[340px] rounded-control border border-line bg-surface p-2 text-small shadow-md`,style:y(u)>c/2?{right:c-y(u)+12}:{left:y(u)+12},children:[(0,h.jsx)(`div`,{className:`mb-1 font-semibold`,children:t[u]}),E.map(({one:e,value:t})=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 shrink-0 rounded-full`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),(0,h.jsx)(`span`,{className:`tabular-nums`,children:n(t)})]},e.id))]})]}),a?(0,h.jsx)(`figcaption`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-small text-ink-2`,children:e.map(e=>(0,h.jsxs)(`span`,{className:`flex max-w-[320px] items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-[3px] w-4 shrink-0 rounded`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))}):null]})}var k2=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function Ime(e,t){return R(await e.fetch(k2(e,t)))}async function Lme(e,t,n){return R(await e.fetch(k2(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}async function Rme(e,t,n){return R(await e.fetch(`${e.origin}/api/studio/channels/${t}/export-view`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:n})}))}function zme({channelId:e,saved:t}){let{api:n}=V(),r=_(),i=Ry(),[a,o]=(0,m.useState)(),s=a??t??``,c=L({mutationFn:t=>Rme(n,e,t),onSuccess:t=>{r.setQueryData([`studio`,`report`,e],t),o(void 0),i(t.exportView?`The extension exports this view every day.`:`The extension no longer exports a view for this channel.`,`success`)},onError:e=>i(`The view wasn't saved: ${e.message}`,`error`)});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{"aria-label":`Studio Analytics view to export every day`,placeholder:`https://studio.youtube.com/channel/…/analytics/…/explore?…`,className:`min-w-0 flex-1 basis-[320px]`,value:s,onChange:e=>o(e.currentTarget.value)}),(0,h.jsx)(B,{type:`button`,disabled:c.isPending||s.trim()===(t??``),onClick:()=>c.mutate(s.trim()===``?null:s.trim()),children:`Save view`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The Studio extension opens this view once a day, exports it and brings it in here: every column, and each video's numbers on its project. Paste the address of Analytics → Advanced mode as you set it up; the start date stays, the end moves to today.`})]})}function A2(e,t,n){if(e===null)return`–`;if(typeof e==`string`)return e;if(t===`duration`){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=String(Math.round(e%60)).padStart(2,`0`);return t>0?`${String(t)}:${String(n).padStart(2,`0`)}:${r}`:`${String(n)}:${r}`}let r=/%|\(|rpm|revenue|hours/i.test(n)&&!Number.isInteger(e)?1:0;return e.toLocaleString(`en`,{minimumFractionDigits:r,maximumFractionDigits:r})}var j2=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],M2=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),N2=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function P2(e,t){if(t===`total`){let t=0;return e.map(e=>t+=e)}return t===`average`?e.map((t,n)=>{let r=e.slice(Math.max(0,n-6),n+1);return r.reduce((e,t)=>e+t,0)/r.length}):[...e]}function Bme({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,[d,f]=(0,m.useState)(!1),p=t.filter(e=>n.includes(e.videoId)),g=e.from===null?new Date:new Date(`${e.from}T00:00:00`),_=Math.max(0,...t.map(e=>e.daily.length)),v,y;if(o===`dates`){let t=c===`all`?0:Math.max(0,_-Number(c)),n=_-t>200;v=Array.from({length:_-t},(e,r)=>{let i=new Date(g);return i.setDate(i.getDate()+t+r),(n?N2:M2).format(i)}),y=p.map(e=>{let n=e.daily.findIndex(e=>e>0),a=P2(e.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:e.videoId,label:e.title,color:r(e.videoId),values:a.slice(t)}}),d&&e.dailyTotals!==void 0&&(y=[{id:`channel-total`,label:`Channel total`,color:`var(--color-ink-2)`,values:P2(e.dailyTotals,i).slice(t)},...y])}else{let e=Math.max(1,...p.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));v=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),y=p.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=P2(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let b=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:b}),(0,h.jsx)(`span`,{className:`flex-1`}),e.dailyTotals===void 0||o!==`dates`?null:(0,h.jsxs)(`label`,{className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.currentTarget.checked)}),`Channel total`]}),(0,h.jsx)(VB,{"aria-label":`Show`,className:`w-[200px]`,value:i,onChange:e=>a(e.currentTarget.value),options:[{value:`average`,label:`7-day average`},{value:`daily`,label:`Per day`},{value:`total`,label:`Running total`}]}),(0,h.jsx)(VB,{"aria-label":`Timeline`,className:`w-[220px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:`dates`,label:`By date`},{value:`since`,label:`Days since release`}]}),(0,h.jsx)(VB,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),p.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(O2,{series:y,xLabels:v,label:`${b} for ${String(p.length)} videos`,formatValue:F2})]})}var F2=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function Vme({report:e,row:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`),s=t.daily.findIndex(e=>e>0);if(s<0)return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart this one, tick it in Advanced mode's chart before you export.`});let c=P2(t.daily.slice(s),n),l=r===`all`?0:Math.max(0,c.length-Number(r)),u=c.slice(l),d=u.map((e,t)=>{let n=new Date(o);return n.setDate(n.getDate()+s+l+t),(u.length>200?N2:M2).format(n)}),f=t.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`${a} · ${f.toLocaleString(`en`)} total`}),(0,h.jsx)(O2,{height:180,legend:!1,label:`${a} for ${t.title}`,xLabels:d,formatValue:F2,series:[{id:t.videoId,label:t.title,color:i(t.videoId),values:u}]})]})}var I2=e=>`slopify.studioReport.hidden.${e}`;function Hme(e){try{let t=window.localStorage.getItem(I2(e));return t===null?void 0:JSON.parse(t)}catch{return}}function L2({channelId:e}){let{api:t}=V(),n=_(),r=Ry(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=I({queryKey:a,queryFn:()=>Ime(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(()=>Hme(e)),w=L({mutationFn:n=>Lme(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),T=o.data?.report??null,E=T?.columns??[],D=E.filter((e,t)=>(T?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),O=S??D,k=t=>{C(t);try{window.localStorage.setItem(I2(e),JSON.stringify(t))}catch{}},A=E.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!O.includes(e.label)),j=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},M=[...T?.rows??[]].toSorted((e,t)=>j(t,s)-j(e,s)),ee=[...T?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),N=l??ee.slice(0,5).map(e=>e.videoId),P=e=>{let t=(T?.rows??[]).findIndex(t=>t.videoId===e);return j2[(t<0?0:t)%j2.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(W,{as:`h3`,title:`From Studio's export`,meta:T===null?void 0:`${String(T.rows.length)} videos · ${T.from??`?`} to ${T.to??`?`} · imported ${new Date(T.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&w.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(B,{type:`button`,variant:`secondary`,disabled:w.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(tl,{"aria-hidden":`true`,strokeWidth:1.75}),w.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),(0,h.jsx)(zme,{channelId:e,saved:o.data?.exportView??null}),T===null?null:(0,h.jsxs)(h.Fragment,{children:[T.chartMetric===null?null:(0,h.jsx)(Bme,{report:T,rows:M,picked:N,colorOf:P,shape:d,setShape:f,timeline:p,setTimeline:g,range:v,setRange:y}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(VB,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:E.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(A.length),` of `,String(E.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:E.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!O.includes(e.label),onChange:t=>k(t.currentTarget.checked?O.filter(t=>t!==e.label):[...O,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),A.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),A.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:A2(T.totals[t]??null,e.kind,e.label)},e.label))]}),M.map(e=>{let t=o.data?.projects[e.videoId],n=b===e.videoId;return(0,h.jsxs)(m.Fragment,{children:[(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:N.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...N,e.videoId]:N.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:N.includes(e.videoId)?P(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[T.chartMetric===null?null:(0,h.jsx)(Py,{size:`small`,"aria-expanded":n,label:`${n?`Hide`:`Show`} the chart of ${e.title}`,onClick:()=>x(n?void 0:e.videoId),children:n?(0,h.jsx)(Cc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75})}),t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title})]}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),A.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:A2(e.values[n]??null,t.kind,t.label)},t.label))]}),n?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:A.length+2,children:(0,h.jsx)(Vme,{report:T,row:e,shape:d,range:v,colorOf:P})})}):null]},e.videoId)})]})]})})]})]})}var R2=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),z2=e=>e==null?`–`:`${e.toFixed(1)}%`;function B2(e){if(e==null)return`–`;let t=Math.round(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}var Ume=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),V2=e=>e===null?`–`:Ume.format(new Date(e));function H2({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(x2,{children:[(0,h.jsx)(S2,{value:R2(t.views),label:`Views`}),(0,h.jsx)(S2,{value:R2(t.impressions),label:`Impressions`}),(0,h.jsx)(S2,{value:z2(t.ctr),label:`Click-through rate`}),(0,h.jsx)(S2,{value:B2(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(S2,{value:R2(t.watchHours),label:`Watch hours`})]})]})}var U2=(e,t)=>{let n=e.long?.stats??null;return t===`views`?(n?.views??0)+e.shorts.reduce((e,t)=>e+(t.stats?.views??0),0):t===`ctr`?n?.ctr??-1:t===`duration`?n?.averageViewSeconds??-1:Date.parse(e.long?.releasedAt??e.shorts[0]?.releasedAt??``)||0};function Wme({channelId:e}){let{api:t}=V(),[n,r]=(0,m.useState)(`newest`),i=I({queryKey:[`studio`,`performance`,e],queryFn:()=>hs(t,e)});if(i.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the numbers…`});if(i.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The numbers didn't load: `,i.error.message,` Reload the page to try again.`]});let a=i.data;if(a.projects.length===0)return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(L2,{channelId:e}),(0,h.jsx)(T1,{title:`No video of this channel is known on YouTube yet`,children:`Upload with the Slopify Studio extension, or open YouTube Studio's Content list once so the extension links your videos. Their numbers then arrive daily, or at once with Read Studio numbers now in the extension's popup.`})]});let o=a.projects.toSorted((e,t)=>U2(t,n)-U2(e,n)).flatMap(e=>[...e.long===null?[]:[{key:`${e.projectId}-0`,projectId:e.projectId,row:e.long,isShort:!1}],...e.shorts.map(t=>({key:`${e.projectId}-${String(t.short??0)}`,projectId:e.projectId,row:t,isShort:!0}))]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Studio's numbers as the Slopify Studio extension last read them`,a.readAt===null?``:` (newest ${V2(a.readAt)})`,`: daily while Chrome is open, or at once with Read Studio numbers now in the extension's popup. "–" is a number Studio doesn't show for that video (most shorts have no click-through rate).`]}),(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,h.jsx)(H2,{label:`Long videos`,totals:a.long}),(0,h.jsx)(H2,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(L2,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:`Every video`,children:(0,h.jsx)(VB,{"aria-label":`Order`,value:n,onChange:e=>r(e.currentTarget.value),options:[{value:`newest`,label:`Newest first`},{value:`views`,label:`Most views`},{value:`ctr`,label:`Best click-through rate`},{value:`duration`,label:`Longest average view`}]})}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{columns:[{id:`title`,header:`Video`,cell:e=>e.isShort?(0,h.jsx)(`span`,{className:`block pl-5 text-small text-ink-2`,children:`Short ${String(e.row.short??``)} · ${e.row.title}`}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>V2(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>R2(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>z2(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>R2(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>B2(e.row.stats?.averageViewSeconds)},{id:`hours`,header:`Watch hours`,numeric:!0,cell:e=>e.row.stats?.watchHours===null||e.row.stats?.watchHours===void 0?`–`:e.row.stats.watchHours.toFixed(1)}],rows:o,rowKey:e=>e.key,caption:`The channel's videos and shorts with Studio's numbers`})})]})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],Gme={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function Kme(e){return W2.find(t=>t===e)??`brand`}function qme({channelId:e,tab:t,onTab:n}){let{api:r}=V(),i=_(),a=Ji(),o=I(lx(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=L({mutationFn:()=>fx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:ix}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return jx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(fa,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(B,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(C1,{items:W2.map(e=>({id:e,label:Gme[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(v1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(w1,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(ame,{channel:f}),(0,h.jsx)(pme,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(bme,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(wfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Dfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Ame,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(Mme,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(Wme,{channelId:f.id}):null})]}):null,(0,h.jsx)(Hy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function Jme(){let{api:e}=V(),t=_(),n=Ji(),r=I(cx(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=L({mutationFn:()=>ux(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:ix}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=L({mutationFn:t=>dx(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:ix}),a(null)}}),v=L({mutationFn:t=>fx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:ix})}}),y=()=>{p.reset(),l(``),a(`new`)};jx({id:`channels.new`,title:`New channel`,group:`Channels`,run:y});let b=i===`new`?p:g,x=()=>{c.trim()!==``&&i!==null&&(i===`new`?p.mutate():g.mutate(i))};return(0,h.jsxs)(`div`,{"data-tour":`channels`,children:[(0,h.jsx)(XK,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(U,{id:`planning.channels`})]}),actions:(0,h.jsxs)(B,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(v1,{tone:r.error||v.error?`error`:`info`,className:`mb-2`,children:r.error?`The channels couldn't be loaded: ${r.error.message} Reload the page to try again.`:o===null&&v.error?v.error.message:r.isPending?`Loading channels…`:void 0}),r.data?.length===0?(0,h.jsx)(T1,{title:`No channels yet`,actions:(0,h.jsx)(B,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(QK,{list:(0,h.jsx)(PH,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(FH,{selected:e.id===f?.id,onSelect:()=>d(e.id),title:e.name,meta:`${e.isDefault?`Default · `:``}${String(e.templates)} ${e.templates===1?`template`:`templates`} · ${String(e.cast)} in the cast`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(Yme,{channel:f})}):null,(0,h.jsx)(Vy,{open:i!==null,onOpenChange:e=>{!e&&!b.isPending&&a(null)},title:i===`new`||i===null?`New channel`:`Rename ${i.name}`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(B,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(B,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(LB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(zB,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Hy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function Yme({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(W,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(CS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(x2,{className:`mb-6`,children:[(0,h.jsx)(S2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(S2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(W,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(W,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var G2=2e3;function K2(e,t){let n=(0,m.useRef)(t);(0,m.useEffect)(()=>{n.current=t}),(0,m.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{n.current()},G2);return()=>{clearTimeout(t)}},[e])}function q2(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(Sc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function J2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Ry();jx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:nP.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(B,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(v1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(q2,{}):t)}),a,(0,h.jsx)(B,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Ux(nP.save),onClick:()=>{c||s()},children:`Save`})]})}var Xme=`rounded-media border border-line bg-surface p-4`;function Y2(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${Xme} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var Zme=`modulepreload`,Qme=function(e){return`/`+e},X2={},Z2=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Qme(t,n),t=s(t),t in X2)return;X2[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Zme,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function $me({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return ehe(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function ehe(e,t){let n=await Z2(()=>import(`./pdf-D04vvdOD.js`),[]),r=await Z2(()=>import(`./pdf.worker.min-zC6nfbxG.js`),[]);n.GlobalWorkerOptions.workerSrc=r.default;let i=n.getDocument({data:e.slice()}),a=await i.promise;try{let e=window.devicePixelRatio||1,n=[];for(let r=1;r<=a.numPages;r+=1){let i=await a.getPage(r),o=i.getViewport({scale:t*e/i.getViewport({scale:1}).width}),s=window.document.createElement(`canvas`);s.width=Math.floor(o.width),s.height=Math.floor(o.height),await i.render({canvas:s,viewport:o}).promise,n.push(s)}return n}finally{await i.destroy()}}var Q2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),$2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),e4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),t4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),n4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),i4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),the=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},Q2([`page`,`margin`],`Margins`),Q2([`page`,`contentTop`],`Text starts at`,`From the top, on pages with the header.`),{kind:`choice`,path:[`background`,`image`],label:`Background`,options:[{value:`parchment`,label:`Parchment texture`},{value:null,label:`Flat colour`}]},{kind:`color`,path:[`background`,`color`],label:`Page colour`,help:`Used when the background is a flat colour.`}]},{title:`Colours`,fields:[{kind:`color`,path:[`colors`,`heading`],label:`Headings`,help:`Also drop caps, the brand name and links.`},{kind:`color`,path:[`colors`,`text`],label:`Body text`},{kind:`color`,path:[`colors`,`muted`],label:`Muted`,help:`Dates, bullets, quotes and the dots in the contents.`},{kind:`color`,path:[`colors`,`faint`],label:`Faint`,help:`Running header and page numbers.`}]},{title:`Fonts`,fields:[i4(`body`,`Body`),i4(`strong`,`Bold text`),i4(`emphasis`,`Italic text`),i4(`heading`,`Headings`),i4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),i4(`decorative`,`Tagline and title-page link`),i4(`dropCap`,`Drop caps`),i4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[$2([`sizes`,`title`],`Title`),$2([`sizes`,`brand`],`Brand`),$2([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),$2([`sizes`,`heading`],`Second-level headings`),$2([`sizes`,`subheading`],`Third-level headings`),$2([`sizes`,`body`],`Body`),$2([`sizes`,`meta`],`Date and word count`),$2([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[Q2([`spacing`,`bodyLine`],`Body line height`),Q2([`spacing`,`headingLine`],`Heading line height`),Q2([`spacing`,`subheadingLine`],`Subheading line height`),e4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),e4([`spacing`,`headingGap`],`Before a heading`,`× line`),e4([`spacing`,`itemGap`],`After a list item`,`× line`),Q2([`spacing`,`listIndent`],`List indent`),Q2([`spacing`,`quoteIndent`],`Quote indent`),Q2([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[t4([`dropCap`,`enabled`],`Drop caps`,`A large first letter after each heading.`),{kind:`choice`,path:[`dropCap`,`lines`],label:`Lines tall`,options:[{value:2,label:`2 lines`},{value:3,label:`3 lines`},{value:4,label:`4 lines`}]},e4([`dropCap`,`scale`],`Letter size`,`× lines`),Q2([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},e4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[Q2([`titlePage`,`brandY`],`Brand from top`),Q2([`titlePage`,`taglineOffset`],`Tagline below brand`),Q2([`titlePage`,`titleY`],`Title from top`),Q2([`titlePage`,`titleLine`],`Title line height`),Q2([`titlePage`,`metaOffset`],`Details below title`),Q2([`titlePage`,`metaLine`],`Details line height`),t4([`titlePage`,`showDate`],`Show the date`),t4([`titlePage`,`showWordCount`],`Show the word count`),t4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),Q2([`titlePage`,`cover`,`gap`],`Space around cover`),Q2([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[r4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),r4([`brand`,`tagline`],`Tagline`),r4([`brand`,`url`],`Website`,`Where the brand and its link go.`),r4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[t4([`contents`,`enabled`],`Contents page`),n4([`contents`,`title`],`Title`),{kind:`choice`,path:[`contents`,`depth`],label:`Lists headings down to`,options:[{value:1,label:`Top level`},{value:2,label:`Second level`},{value:3,label:`Third level`}]},Q2([`contents`,`titleOffset`],`Title from top margin`),Q2([`contents`,`firstEntryOffset`],`First entry from top margin`),Q2([`contents`,`line`],`Line height`),Q2([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[t4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),Q2([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},t4([`footer`,`enabled`],`Page numbers`),n4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),Q2([`footer`,`bottom`],`From the bottom`),Q2([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[t4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),n4([`sources`,`title`],`Title`),Q2([`sources`,`titleOffset`],`Title from top margin`),Q2([`sources`,`bodyOffset`],`List from top margin`),Q2([`sources`,`line`],`Line height`),Q2([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[t4([`endPage`,`enabled`],`Closing page`),n4([`endPage`,`title`],`Title`),{kind:`lines`,path:[`endPage`,`lines`],label:`Text`,help:`One line each. Start with "•" for a bullet, end with ":" for a bold label, leave a line empty for a gap.`},t4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},r4([`endPage`,`closing`],`Closing line`),Q2([`endPage`,`titleOffset`],`Title from top margin`),Q2([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[n4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),n4([`metadata`,`subject`],`Subject`),n4([`metadata`,`keywords`],`Keywords`),n4([`metadata`,`creator`],`Creator`)]}],a4=Kj.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function o4(e){let t={normal:`Regular`,medium:`Medium`,bold:`Bold`,black:`Black`,italic:`Italic`,bolditalic:`Bold italic`};return(e===`Cinzel`?[`normal`,`medium`,`bold`,`black`]:[`normal`,`bold`,`italic`,`bolditalic`]).map(e=>({value:e,label:t[e]}))}function nhe(e,t){let n=e;for(let e of t)n=n?.[e];return n}function s4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:s4(a,i,n)}}function rhe(e){let t=eM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function c4(e){return`values.${e.join(`.`)}`}var l4=`pt-1`,u4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function d4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Tc,{"aria-hidden":`true`}),e]})}function f4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(aI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function p4({themeId:e,from:t,onLeave:n}){let{api:r}=V(),i=_(),a=I(hb(r)),o=(0,m.useId)(),[s,c]=(0,m.useState)(void 0),[l,u]=(0,m.useState)([]),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),v=a.data,y=e===void 0?void 0:v?.themes.find(t=>t.id===e),b=e===void 0?v?.themes.find(e=>e.id===t)??v?.builtIns.find(e=>e.name===(t??`plain`))??v?.builtIns[0]:y,x=b===void 0?void 0:{name:e===void 0?`${`label`in b?b.label:b.name} copy`:b.name,values:b.values},S=s??x,C=L({mutationFn:t=>Js(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:hb(r).queryKey})}}),w=L({mutationFn:e=>Ys(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:hb(r).queryKey}),n()}});K2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:eM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:cC(S.name),...T===void 0||T.success?[]:T.error.issues.map(e=>({field:`values.${e.path.join(`.`)}`,message:e.message})),...l];if(a.error!==null)return(0,h.jsx)(g4,{children:a.error.message});if(v===void 0)return(0,h.jsx)(Y2,{});if(S===void 0)return(0,h.jsx)(g4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(LB,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),the.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>m4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(ohe,{field:e,theme:S.values,problem:m4(E,e.path),onChange:t=>{D({...S,values:t},c4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(CS,{to:`/document-themes`,variant:`secondary`,children:`Cancel`}),errors:[C.error,w.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{C.mutate(S)}})]}),(0,h.jsx)(ahe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(Hy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var ihe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function m4(e,t){let n=c4(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function ahe({values:e}){let{api:t}=V(),[n,r]=(0,m.useState)(),[i,a]=(0,m.useState)(`busy`),[o,s]=(0,m.useState)(void 0),c=e===void 0?void 0:JSON.stringify(e);(0,m.useEffect)(()=>{if(c===void 0)return;let e=new AbortController,n=window.setTimeout(()=>{a(`busy`),Xs(t,JSON.parse(c),e.signal).then(async e=>({bytes:new Uint8Array(await e.arrayBuffer()),blob:e})).then(({bytes:t,blob:n})=>{e.signal.aborted||r({bytes:t,url:URL.createObjectURL(n)})},t=>{e.signal.aborted||(s(t instanceof Error?t.message:String(t)),a(`failed`))})},450);return()=>{window.clearTimeout(n),e.abort()}},[t,c]),(0,m.useEffect)(()=>()=>{n!==void 0&&URL.revokeObjectURL(n.url)},[n]);let l=(0,m.useCallback)(e=>{if(e===void 0){a(`idle`);return}s(e.message),a(`failed`)},[]),u=e===void 0?`Paused until the highlighted settings are fixed.`:i===`busy`?`Updating…`:i===`failed`?`The preview couldn't be made: ${o??`unknown error`}`:`A sample article with this theme. Your projects use their own text and thumbnail.`;return(0,h.jsxs)(`div`,{className:u4,children:[(0,h.jsx)(W,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(TS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open full size`]})}),(0,h.jsx)(`div`,{className:`max-h-[calc(100vh-220px)] min-h-[320px] overflow-y-auto rounded-media bg-sunken p-3`,children:(0,h.jsx)($me,{data:n?.bytes,label:`The sample article laid out with this theme`,onDrawn:l})}),(0,h.jsx)(`p`,{role:`status`,className:i===`failed`?`m-0 text-small text-danger`:`m-0 text-small text-ink-2`,children:u})]})}function ohe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=nhe(t,e.path),o=ihe[c4(e.path)],s=o===void 0?null:(0,h.jsx)(U,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(s4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=rhe(e.path);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(zB,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(zB,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(VB,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=o4(t.family);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(VB,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=a4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=o4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:a4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(VB,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(zB,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(BB,{...d,rows:8,value:Array.isArray(a)?a.join(`
274
274
  `):``,onChange:e=>{c(e.target.value.split(`
275
- `))}}),u]});case`link`:{let t=a;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),s]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(zB,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{c({...t,text:e.target.value})}}),(0,h.jsx)(zB,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{c({...t,url:e.target.value===``?null:e.target.value})}})]}),u]})}}}function h4({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),r]}),i,n]})}function g4({children:e}){return(0,h.jsx)(f4,{back:(0,h.jsx)(fa,{to:`/document-themes`,children:`Back to Documents`}),children:e})}var ahe=4e3;function _4(e){return e.match(/\s+|[^\s]+/gu)??[]}function ohe(e,t){let n=_4(e),r=_4(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i+=1;let a=0;for(;a<n.length-i&&a<r.length-i&&n[n.length-1-a]===r[r.length-1-a];)a+=1;let o=[];y4(o,`same`,n.slice(0,i).join(``));let s=n.slice(i,n.length-a),c=r.slice(i,r.length-a);for(let e of che(s,c))y4(o,e.op,e.text);return y4(o,`same`,n.slice(n.length-a).join(``)),o}function v4(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function she(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+_4(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function y4(e,t,n){if(n===``)return;let r=e.at(-1);r!==void 0&&r.op===t?e[e.length-1]={op:t,text:r.text+n}:e.push({op:t,text:n})}function che(e,t){if(e.length===0&&t.length===0)return[];if(e.length===0)return[{op:`added`,text:t.join(``)}];if(t.length===0)return[{op:`removed`,text:e.join(``)}];let n=e.length,r=t.length,i=Math.min(n+r,ahe),a=i+1,o=new Int32Array(2*i+3),s=[],c=!1;for(let l=0;l<=i&&!c;l+=1){s.push(o.slice());let i=o.slice();for(let s=-l;s<=l;s+=2){let u=s===-l||s!==l&&(o[a+s-1]??0)<(o[a+s+1]??0)?o[a+s+1]??0:(o[a+s-1]??0)+1,d=u-s;for(;u<n&&d<r&&e[u]===t[d];)u+=1,d+=1;if(i[a+s]=u,u>=n&&d>=r){c=!0;break}}o=i}if(!c)return[{op:`removed`,text:e.join(``)},{op:`added`,text:t.join(``)}];let l=[],u=n,d=r;for(let n=s.length-1;n>=0;--n){let r=s[n]??new Int32Array,i=u-d,o=i===-n||i!==n&&(r[a+i-1]??0)<(r[a+i+1]??0),c=o?i+1:i-1,f=r[a+c]??0,p=f-c;for(;u>f&&d>p;)l.push({op:`same`,text:e[u-1]??``}),--u,--d;n>0&&(o?l.push({op:`added`,text:t[d-1]??``}):l.push({op:`removed`,text:e[u-1]??``}),u=f,d=p)}let f=[];for(let e of l.reverse())y4(f,e.op,e.text);return f}function b4({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>ohe(e,t),[e,t]),a=she(i);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:a.added===0&&a.removed===0?`The two texts are the same.`:`${String(a.added)} ${a.added===1?`word`:`words`} added, ${String(a.removed)} removed.`}),(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,h.jsx)(x4,{label:n,parts:v4(i,`before`)}),(0,h.jsx)(x4,{label:r,parts:v4(i,`after`)})]})]})}function x4({label:e,parts:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`h4`,{className:`sl-kicker m-0`,children:e}),(0,h.jsx)(`div`,{className:`min-w-0 whitespace-pre-wrap break-words border-l-2 border-line pl-3 text-small leading-relaxed text-ink`,children:lhe(t).map(({key:e,part:t})=>t.op===`removed`?(0,h.jsx)(`del`,{className:`rounded-[2px] bg-danger-tint text-danger line-through`,children:t.text},e):t.op===`added`?(0,h.jsx)(`ins`,{className:`rounded-[2px] bg-accent-tint text-accent-ink no-underline`,children:t.text},e):(0,h.jsx)(`span`,{children:t.text},e))})]})}function lhe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var S4={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function C4(e,t){let{api:n}=V();return I({queryKey:S4.versions(e,t),queryFn:()=>Hs(n,e,t)})}function uhe(e,t){let{api:n}=V();return I({queryKey:S4.usedBy(e,t),queryFn:()=>Us(n,e,t)})}function w4({item:e,id:t,name:n,onClose:r}){let{api:i}=V(),a=_(),o=C4(e,t),s=o.data?.versions??[],[c,l]=(0,m.useState)({}),u=c.after??s[0]?.version,d=c.before??s[1]?.version??u,f=s.find(e=>e.version===d),p=s.find(e=>e.version===u),[g,v]=(0,m.useState)(),y=L({mutationFn:n=>Ws(i,e,t,n),onSuccess:async(n,r)=>{v(`Restored version ${String(r)} as a new version.`),l({}),await Promise.all([a.invalidateQueries({queryKey:S4.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?H.prompts:H.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)(HP,{open:!0,title:`History of ${n}`,onClose:r,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[o.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:`The history couldn't be read: ${o.error.message}`}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(VB,{value:d===void 0?``:String(d),disabled:s.length===0,onChange:e=>l(t=>({...t,before:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:E4(e,b)},e.version))})}),(0,h.jsx)(LB,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(VB,{value:u===void 0?``:String(u),disabled:s.length===0,onChange:e=>l(t=>({...t,after:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:E4(e,b)},e.version))})})]}),f===void 0||p===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading the versions…`:`No versions to compare.`}):(0,h.jsxs)(h.Fragment,{children:[f.name===p.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${f.name}" to "${p.name}".`}),(0,h.jsx)(b4,{before:f.body,after:p.body,beforeLabel:`Version ${String(f.version)}`,afterLabel:`Version ${String(p.version)}`})]})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(PH,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(FH,{title:`Version ${String(e.version)}`,meta:T4(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(B,{size:`small`,"aria-label":`Restore version ${String(e.version)}`,disabled:y.isPending,disabledReason:`Restoring a version`,onClick:()=>{v(void 0),y.mutate(e.version)},children:`Restore`})},e.version))}),(0,h.jsx)(v1,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function T4(e){return`${e.author} · ${D4(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function E4(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${D4(e.createdAt)}`}function D4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function O4({item:e,id:t,name:n,kicker:r,meta:i,body:a,slots:o,actions:s,onOpenHistory:c}){return(0,h.jsxs)(`section`,{"aria-label":`${n} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(W,{title:n,kicker:r,meta:i,className:`pb-0`,children:s}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`div`,{className:`m-0 max-h-[420px] min-w-0 overflow-y-auto whitespace-pre-wrap break-words rounded-media bg-sunken p-4 font-mono text-small text-ink-2`,children:a}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No keywords. It runs as written.`}):(0,h.jsx)(`ul`,{"aria-label":`Keywords`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:o.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(HB,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(dhe,{item:e,id:t}),(0,h.jsx)(fhe,{item:e,id:t,name:n,onOpenHistory:c})]})}function dhe({item:e,id:t}){let n=uhe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:phe(r)}}),n.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`What uses it couldn't be read: ${n.error.message}`}),r===void 0?null:r.templates.length+r.schedules.length+r.projects.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Nothing uses it yet.`}):(0,h.jsxs)(PH,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name}),meta:e.status===`paused`?`Schedule · paused`:`Schedule`},`s-${e.id}`)),r.projects.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),meta:`Project${e.totalRevisions===0?``:` · ${String(e.revisions)} of ${String(e.totalRevisions)} ${e.totalRevisions===1?`revision`:`revisions`}${e.current?`, including the current one`:`, not the current one`}`}`},`p-${e.id}`))]})]})}function fhe({item:e,id:t,name:n,onOpenHistory:r}){let i=C4(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:`${k4(a.length,`version`)} · latest ${T4(o)}`},children:(0,h.jsx)(B,{size:`small`,"aria-label":`Compare versions of ${n}`,onClick:r,children:`Compare versions`})}),i.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The history couldn't be read: ${i.error.message}`}),o===void 0?null:s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Only one version so far.`}):(0,h.jsx)(b4,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function phe(e){return[k4(e.templates.length,`template`),k4(e.schedules.length,`schedule`),k4(e.projects.length,`project`)].join(`, `)}function k4(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function A4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}var j4=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,M4=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function N4({label:e}){return(0,h.jsx)(`ul`,{"aria-label":`${e}, loading`,"aria-busy":`true`,className:`sl-list m-0 list-none p-0`,children:[0,1,2].map(e=>(0,h.jsx)(`li`,{className:`sl-row`,"aria-hidden":`true`,children:(0,h.jsxs)(`span`,{className:`flex flex-col gap-2 py-0.5`,children:[(0,h.jsx)(`span`,{className:`h-3 w-40 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 rounded-control bg-sunken`})]})},e))})}function P4({what:e,message:t,onRetry:n}){return(0,h.jsx)(aI,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(B,{size:`small`,onClick:n,children:`Try again`}),children:t})}function F4({name:e,edit:t,duplicate:n,play:r,onHistory:i,onDelete:a,className:o}){return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`Actions for ${e}`,className:z(`flex flex-wrap items-center gap-0.5`,o),children:[t,n,r===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Use ${e} in Play`,title:r.blocked,disabled:r.run===void 0||r.blocked!==void 0,onClick:r.run,children:`Use in Play`}),i===void 0?null:(0,h.jsx)(Py,{size:`small`,label:`History of ${e}`,onClick:i,children:(0,h.jsx)(Jc,{"aria-hidden":`true`})}),(0,h.jsx)(Py,{size:`small`,label:`Delete ${e}`,onClick:a,children:(0,h.jsx)($c,{"aria-hidden":`true`})})]})}var mhe=[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & Outros`},{to:`/templates`,label:`Templates`},{to:`/document-themes`,label:`Documents`},{to:`/narration-aliases`,label:`Aliases`},{to:`/ab-results`,label:`A/B results`}];function hhe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{title:`Library`,meta:`Prompts, intros and outros, templates, document themes, narration aliases and A/B results`}),(0,h.jsx)(Cfe,{items:mhe,label:`Library sections`,className:`mb-6`}),(0,h.jsx)(ghe,{}),(0,h.jsx)(Oa,{})]})}function ghe(){let e=Ji(),t=Ra({select:e=>e.location}),n=t.search,r=PB(t.pathname===`/prompts`?n.kind:void 0),i=jB(t.pathname===`/entries`?n.category:void 0);return jx({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),jx({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),jx({id:`library.new-document-theme`,title:`New document theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),jx({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),jx({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),jx({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),jx({id:`library.open-document-themes`,title:`Open document themes`,group:`Library`,keywords:[`pdf`,`documents`],run:()=>{e({to:`/document-themes`})}}),null}function I4({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:z(`mb-5 flex min-h-9 flex-wrap items-center gap-x-4 gap-y-3`,n),children:[(0,h.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-3`,children:e}),t===void 0?null:(0,h.jsx)(Iy,{className:`ml-auto shrink-0`,children:t})]})}function _he(){let{api:e}=V(),t=_(),n=I(hb(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(void 0),s=L({mutationFn:t=>Ys(e,t),onSettled:async()=>{o(void 0),await t.invalidateQueries({queryKey:H.documentThemes})}}),c=n.data,l=r!==void 0&&`saved`in r?c?.themes.find(e=>e.id===r.saved):void 0,u=r!==void 0&&`builtIn`in r?c?.builtIns.find(e=>e.name===r.builtIn):void 0,d=l===void 0&&u===void 0?c?.themes[0]:void 0,f=l??d,p=f===void 0?u??c?.builtIns[0]:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(I4,{action:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:`plain`},variant:`primary`,children:`New theme`}),children:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`How a project's PDF looks. Pick one on the Document row in Play or in Edit project.`})}),n.error===null?null:(0,h.jsx)(P4,{what:`document themes`,message:n.error.message,onRetry:()=>void n.refetch()}),c===void 0?n.error===null?(0,h.jsx)(N4,{label:`Document themes`}):null:(0,h.jsx)(QK,{className:j4,list:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`}),c.themes.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No themes of your own yet. Copy a built-in below to start one.`}):(0,h.jsx)(PH,{label:`Your themes`,children:c.themes.map(e=>(0,h.jsx)(FH,{className:M4,lead:(0,h.jsx)(H4,{colors:e.values.colors}),title:e.name,meta:`${L4(e.values)} · updated ${A4(e.updatedAt)}`,selected:e.id===f?.id,onSelect:()=>i({saved:e.id}),actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>o(e)})},e.id))})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(PH,{label:`Built-in themes`,children:c.builtIns.map(e=>(0,h.jsx)(FH,{className:M4,lead:(0,h.jsx)(H4,{colors:e.values.colors}),title:e.label,meta:L4(e.values),selected:e.name===p?.name,onSelect:()=>i({builtIn:e.name}),actions:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:f===void 0?p===void 0?null:(0,h.jsx)(B4,{name:p.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:p.values,action:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:p.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(B4,{name:f.name,kicker:`Your theme`,meta:`Updated ${A4(f.updatedAt)}`,values:f.values,action:(0,h.jsx)(CS,{to:`/document-themes/$themeId`,params:{themeId:f.id},size:`small`,children:`Edit theme`})})}),s.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:s.error.message}),(0,h.jsx)(Hy,{open:a!==void 0,title:`Delete "${a?.name??``}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:s.isPending,onConfirm:()=>{a!==void 0&&s.mutate(a.id)},onCancel:()=>o(void 0)})]})}function L4(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${R4(e.fonts.body.family)} body`}function R4(e){return a4.find(t=>t.value===e)?.label??e}function z4(e){return e.startsWith(`#`)?e:`#${e}`}function B4({name:e,kicker:t,meta:n,values:r,action:i}){let a=[[`Headings`,r.colors.heading],[`Text`,r.colors.text],[`Muted`,r.colors.muted],[`Header and page numbers`,r.colors.faint]],o=[[`Body`,r.fonts.body],[`Headings`,r.fonts.heading],[`Drop cap`,r.fonts.dropCap]];return(0,h.jsxs)(`section`,{"aria-label":`${e} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(W,{title:e,kicker:t,meta:n,className:`pb-0`,children:i}),(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-[max-content_minmax(0,1fr)]`,children:[a.map(([e,t])=>(0,h.jsx)(V4,{label:e,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-4 rounded-full border border-line`,style:{backgroundColor:z4(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:z4(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(V4,{label:`${e} font`,children:`${R4(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(V4,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${z4(r.background.color)}`} background`})]})]})}function V4({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function H4({colors:e}){return(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`flex shrink-0 gap-1`,children:[e.heading,e.text,e.muted].map((e,t)=>(0,h.jsx)(`span`,{className:`size-3 rounded-full border border-line`,style:{backgroundColor:z4(e)}},t))})}function U4(e){let t=e.map(e=>e.message).join(` `);return`The name wasn't saved. ${t===``?`Pick another name and press Save name again.`:t}`}function W4({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Ry(),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(e),[u,d]=(0,m.useState)(null),[f,p]=(0,m.useState)(!1),g=(0,m.useRef)(!1),_=async e=>{try{return await n(e)}catch(e){return`The name wasn't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then press Save name again.`}},v=async()=>{let t=c.trim();if(t===e){s(!1),d(null);return}if(t===``){d(`Write a name first, or press Cancel to keep the old one.`);return}if(g.current)return;g.current=!0,p(!0);let n=await _(t);if(g.current=!1,p(!1),n!==null){d(n);return}s(!1),d(null),a(`Renamed “${e}” to “${t}”.`,`success`,{label:`Undo`,run:()=>void _(e).then(t=>{t===null?a(`Renamed back to “${e}”.`,`success`):a(t,`error`)})})},y=()=>{s(!1),l(e),d(null)};return o?(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(zB,{autoFocus:!0,"aria-label":`New name for ${e}`,"aria-invalid":u!==null,maxLength:i,value:c,className:`min-w-0 flex-1`,onChange:e=>{l(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v()):e.key===`Escape`&&(e.preventDefault(),y())}}),(0,h.jsx)(B,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(U,{id:r,label:`Rename`})]}),u===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small font-normal text-danger`,children:u})]}):(0,h.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[t===void 0?(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:e}):(0,h.jsx)(IH,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(Py,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function vhe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=V(),a=_(),o=I(mb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=Mx(l,`intros and outros`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=L({mutationFn:e=>ec(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:H.entries})}}),x=async(e,t)=>{let n=await Ks(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:H.entries}),n.ok?null:U4(n.fields)},S=o.data?.entries.filter(t=>t.category===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(I4,{action:(0,h.jsx)(CS,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`}),children:[(0,h.jsx)(zB,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":Ux(u),placeholder:`Search intros and outros`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsx)(Vb,{label:`Entry category`,value:e,options:TB.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`})]}),o.error===null?null:(0,h.jsx)(P4,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(N4,{label:`Intros and outros`}):null:S.length===0?(0,h.jsx)(bhe,{category:e}):(0,h.jsx)(QK,{className:j4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${e}s match "${s.trim()}".`}):(0,h.jsx)(PH,{label:`${DB(e)}s`,children:w.map(e=>(0,h.jsx)(FH,{className:M4,title:(0,h.jsx)(W4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:yhe(e),selected:e.id===T?.id,actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/entries/new`,search:{category:e.category,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(O4,{item:`entry`,id:T.id,name:T.name,kicker:`${DB(T.category)} · ${OB(T.mode)}`,meta:`Updated ${A4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(CS,{to:`/entries/$entryId`,params:{entryId:T.id},size:`small`,children:`Edit ${T.category}`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(w4,{item:`entry`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(Hy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${p?.category??e}`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function yhe(e){return`${OB(e.mode)} · ${k4(e.slots.length,`keyword`)} · updated ${A4(e.updatedAt)}`}function bhe({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(T1,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function xhe({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:z(`animate-tick-in rounded-control border border-line-strong bg-sunken px-2 py-0.5 font-mono text-label text-ink-2 motion-reduce:animate-none`,t),children:e})}function G4({slots:e,body:t,lint:n,lintId:r,noSlots:i=`No slots. This prompt runs as written.`}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Detected slots`,info:`library.slots`,size:`small`,className:`pb-0`}),e.length>0?(0,h.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.map(e=>(0,h.jsx)(xhe,{name:e,className:`px-2 py-1`},e))}):t.trim()===``?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Slots appear here as you type {{name}}.`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i}),n.length===0?null:(0,h.jsxs)(`div`,{id:r,className:`flex flex-col gap-2 border-t border-line pt-3`,children:[(0,h.jsx)(`span`,{className:`sl-kicker text-danger`,children:n.length===1?`1 slot error`:`${String(n.length)} slot errors`}),n.map(e=>(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message},e.message))]})]})}function K4({className:e,...t}){return(0,h.jsx)(uy,{"data-slot":`label`,className:z(`engraved block select-none text-ink-3`,e),...t})}function q4({className:e,...t}){return(0,h.jsx)(nte,{"data-slot":`toggle-group`,className:z(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function J4({className:e,...t}){return(0,h.jsx)(ste,{"data-slot":`toggle-group-item`,className:z(`min-h-8 shrink-0 border-r border-line-strong px-3 py-1 text-label text-ink-2 last:border-r-0`,`transition-colors duration-150 ease-out motion-reduce:transition-none hover:bg-raised hover:text-ink`,`data-[state=on]:bg-raised data-[state=on]:text-ink data-[state=on]:shadow-[inset_0_-2px_0_var(--color-accent)]`,`disabled:cursor-not-allowed disabled:opacity-40`,e),...t})}function Y4({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{id:o,children:e}),i===void 0?null:(0,h.jsx)(U,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(q4,{type:`single`,value:t,"aria-labelledby":o,"aria-describedby":r,onValueChange:e=>{let t=n.find(t=>t.value===e);t!==void 0&&a(t.value)},children:n.map(e=>(0,h.jsx)(J4,{value:e.value,children:e.label},e.value))})]})}function She(e){return X4(e.name,e.body)}function Che(e){return X4(e.name,e.body)}function X4(e,t){let n=[],r=e.trim();if(r===``?n.push({field:`name`,message:`Enter a name.`}):r.length>200&&n.push({field:`name`,message:`Keep the name to 200 characters or fewer.`}),t.trim()===``)return n.push({field:`body`,message:`Enter the text.`}),n;if(t.length>1e5)return n.push({field:`body`,message:`The text is too long. Keep it to ${String(_M)} characters or fewer.`}),n;for(let e of MK(t).errors)n.push({field:`body`,message:whe(e,t)});return n}function whe(e,t){let n=The(t,e.at);switch(e.kind){case`unclosed`:return`The \`{{\` at ${n} is never closed. Add \`}}\` after the keyword name.`;case`empty`:return`The keyword at ${n} has no name. Write a name between \`{{\` and \`}}\`.`;case`nested`:return`The keyword at ${n} contains a brace. Keywords cannot be placed inside other keywords.`}}function The(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
275
+ `))}}),u]});case`link`:{let t=a;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),s]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(zB,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{c({...t,text:e.target.value})}}),(0,h.jsx)(zB,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{c({...t,url:e.target.value===``?null:e.target.value})}})]}),u]})}}}function h4({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),r]}),i,n]})}function g4({children:e}){return(0,h.jsx)(f4,{back:(0,h.jsx)(fa,{to:`/document-themes`,children:`Back to Documents`}),children:e})}var she=4e3;function _4(e){return e.match(/\s+|[^\s]+/gu)??[]}function che(e,t){let n=_4(e),r=_4(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i+=1;let a=0;for(;a<n.length-i&&a<r.length-i&&n[n.length-1-a]===r[r.length-1-a];)a+=1;let o=[];y4(o,`same`,n.slice(0,i).join(``));let s=n.slice(i,n.length-a),c=r.slice(i,r.length-a);for(let e of uhe(s,c))y4(o,e.op,e.text);return y4(o,`same`,n.slice(n.length-a).join(``)),o}function v4(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function lhe(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+_4(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function y4(e,t,n){if(n===``)return;let r=e.at(-1);r!==void 0&&r.op===t?e[e.length-1]={op:t,text:r.text+n}:e.push({op:t,text:n})}function uhe(e,t){if(e.length===0&&t.length===0)return[];if(e.length===0)return[{op:`added`,text:t.join(``)}];if(t.length===0)return[{op:`removed`,text:e.join(``)}];let n=e.length,r=t.length,i=Math.min(n+r,she),a=i+1,o=new Int32Array(2*i+3),s=[],c=!1;for(let l=0;l<=i&&!c;l+=1){s.push(o.slice());let i=o.slice();for(let s=-l;s<=l;s+=2){let u=s===-l||s!==l&&(o[a+s-1]??0)<(o[a+s+1]??0)?o[a+s+1]??0:(o[a+s-1]??0)+1,d=u-s;for(;u<n&&d<r&&e[u]===t[d];)u+=1,d+=1;if(i[a+s]=u,u>=n&&d>=r){c=!0;break}}o=i}if(!c)return[{op:`removed`,text:e.join(``)},{op:`added`,text:t.join(``)}];let l=[],u=n,d=r;for(let n=s.length-1;n>=0;--n){let r=s[n]??new Int32Array,i=u-d,o=i===-n||i!==n&&(r[a+i-1]??0)<(r[a+i+1]??0),c=o?i+1:i-1,f=r[a+c]??0,p=f-c;for(;u>f&&d>p;)l.push({op:`same`,text:e[u-1]??``}),--u,--d;n>0&&(o?l.push({op:`added`,text:t[d-1]??``}):l.push({op:`removed`,text:e[u-1]??``}),u=f,d=p)}let f=[];for(let e of l.reverse())y4(f,e.op,e.text);return f}function b4({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>che(e,t),[e,t]),a=lhe(i);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:a.added===0&&a.removed===0?`The two texts are the same.`:`${String(a.added)} ${a.added===1?`word`:`words`} added, ${String(a.removed)} removed.`}),(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,h.jsx)(x4,{label:n,parts:v4(i,`before`)}),(0,h.jsx)(x4,{label:r,parts:v4(i,`after`)})]})]})}function x4({label:e,parts:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`h4`,{className:`sl-kicker m-0`,children:e}),(0,h.jsx)(`div`,{className:`min-w-0 whitespace-pre-wrap break-words border-l-2 border-line pl-3 text-small leading-relaxed text-ink`,children:dhe(t).map(({key:e,part:t})=>t.op===`removed`?(0,h.jsx)(`del`,{className:`rounded-[2px] bg-danger-tint text-danger line-through`,children:t.text},e):t.op===`added`?(0,h.jsx)(`ins`,{className:`rounded-[2px] bg-accent-tint text-accent-ink no-underline`,children:t.text},e):(0,h.jsx)(`span`,{children:t.text},e))})]})}function dhe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var S4={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function C4(e,t){let{api:n}=V();return I({queryKey:S4.versions(e,t),queryFn:()=>Hs(n,e,t)})}function fhe(e,t){let{api:n}=V();return I({queryKey:S4.usedBy(e,t),queryFn:()=>Us(n,e,t)})}function w4({item:e,id:t,name:n,onClose:r}){let{api:i}=V(),a=_(),o=C4(e,t),s=o.data?.versions??[],[c,l]=(0,m.useState)({}),u=c.after??s[0]?.version,d=c.before??s[1]?.version??u,f=s.find(e=>e.version===d),p=s.find(e=>e.version===u),[g,v]=(0,m.useState)(),y=L({mutationFn:n=>Ws(i,e,t,n),onSuccess:async(n,r)=>{v(`Restored version ${String(r)} as a new version.`),l({}),await Promise.all([a.invalidateQueries({queryKey:S4.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?H.prompts:H.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)(HP,{open:!0,title:`History of ${n}`,onClose:r,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[o.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:`The history couldn't be read: ${o.error.message}`}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(VB,{value:d===void 0?``:String(d),disabled:s.length===0,onChange:e=>l(t=>({...t,before:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:E4(e,b)},e.version))})}),(0,h.jsx)(LB,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(VB,{value:u===void 0?``:String(u),disabled:s.length===0,onChange:e=>l(t=>({...t,after:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:E4(e,b)},e.version))})})]}),f===void 0||p===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading the versions…`:`No versions to compare.`}):(0,h.jsxs)(h.Fragment,{children:[f.name===p.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${f.name}" to "${p.name}".`}),(0,h.jsx)(b4,{before:f.body,after:p.body,beforeLabel:`Version ${String(f.version)}`,afterLabel:`Version ${String(p.version)}`})]})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(PH,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(FH,{title:`Version ${String(e.version)}`,meta:T4(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(B,{size:`small`,"aria-label":`Restore version ${String(e.version)}`,disabled:y.isPending,disabledReason:`Restoring a version`,onClick:()=>{v(void 0),y.mutate(e.version)},children:`Restore`})},e.version))}),(0,h.jsx)(v1,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function T4(e){return`${e.author} · ${D4(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function E4(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${D4(e.createdAt)}`}function D4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function O4({item:e,id:t,name:n,kicker:r,meta:i,body:a,slots:o,actions:s,onOpenHistory:c}){return(0,h.jsxs)(`section`,{"aria-label":`${n} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(W,{title:n,kicker:r,meta:i,className:`pb-0`,children:s}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`div`,{className:`m-0 max-h-[420px] min-w-0 overflow-y-auto whitespace-pre-wrap break-words rounded-media bg-sunken p-4 font-mono text-small text-ink-2`,children:a}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No keywords. It runs as written.`}):(0,h.jsx)(`ul`,{"aria-label":`Keywords`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:o.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(HB,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(phe,{item:e,id:t}),(0,h.jsx)(mhe,{item:e,id:t,name:n,onOpenHistory:c})]})}function phe({item:e,id:t}){let n=fhe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:hhe(r)}}),n.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`What uses it couldn't be read: ${n.error.message}`}),r===void 0?null:r.templates.length+r.schedules.length+r.projects.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Nothing uses it yet.`}):(0,h.jsxs)(PH,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name}),meta:e.status===`paused`?`Schedule · paused`:`Schedule`},`s-${e.id}`)),r.projects.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),meta:`Project${e.totalRevisions===0?``:` · ${String(e.revisions)} of ${String(e.totalRevisions)} ${e.totalRevisions===1?`revision`:`revisions`}${e.current?`, including the current one`:`, not the current one`}`}`},`p-${e.id}`))]})]})}function mhe({item:e,id:t,name:n,onOpenHistory:r}){let i=C4(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:`${k4(a.length,`version`)} · latest ${T4(o)}`},children:(0,h.jsx)(B,{size:`small`,"aria-label":`Compare versions of ${n}`,onClick:r,children:`Compare versions`})}),i.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The history couldn't be read: ${i.error.message}`}),o===void 0?null:s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Only one version so far.`}):(0,h.jsx)(b4,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function hhe(e){return[k4(e.templates.length,`template`),k4(e.schedules.length,`schedule`),k4(e.projects.length,`project`)].join(`, `)}function k4(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function A4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}var j4=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,M4=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function N4({label:e}){return(0,h.jsx)(`ul`,{"aria-label":`${e}, loading`,"aria-busy":`true`,className:`sl-list m-0 list-none p-0`,children:[0,1,2].map(e=>(0,h.jsx)(`li`,{className:`sl-row`,"aria-hidden":`true`,children:(0,h.jsxs)(`span`,{className:`flex flex-col gap-2 py-0.5`,children:[(0,h.jsx)(`span`,{className:`h-3 w-40 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 rounded-control bg-sunken`})]})},e))})}function P4({what:e,message:t,onRetry:n}){return(0,h.jsx)(aI,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(B,{size:`small`,onClick:n,children:`Try again`}),children:t})}function F4({name:e,edit:t,duplicate:n,play:r,onHistory:i,onDelete:a,className:o}){return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`Actions for ${e}`,className:z(`flex flex-wrap items-center gap-0.5`,o),children:[t,n,r===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Use ${e} in Play`,title:r.blocked,disabled:r.run===void 0||r.blocked!==void 0,onClick:r.run,children:`Use in Play`}),i===void 0?null:(0,h.jsx)(Py,{size:`small`,label:`History of ${e}`,onClick:i,children:(0,h.jsx)(Jc,{"aria-hidden":`true`})}),(0,h.jsx)(Py,{size:`small`,label:`Delete ${e}`,onClick:a,children:(0,h.jsx)($c,{"aria-hidden":`true`})})]})}var ghe=[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & Outros`},{to:`/templates`,label:`Templates`},{to:`/document-themes`,label:`Documents`},{to:`/narration-aliases`,label:`Aliases`},{to:`/ab-results`,label:`A/B results`}];function _he(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{title:`Library`,meta:`Prompts, intros and outros, templates, document themes, narration aliases and A/B results`}),(0,h.jsx)(Cfe,{items:ghe,label:`Library sections`,className:`mb-6`}),(0,h.jsx)(vhe,{}),(0,h.jsx)(Oa,{})]})}function vhe(){let e=Ji(),t=Ra({select:e=>e.location}),n=t.search,r=PB(t.pathname===`/prompts`?n.kind:void 0),i=jB(t.pathname===`/entries`?n.category:void 0);return jx({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),jx({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),jx({id:`library.new-document-theme`,title:`New document theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),jx({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),jx({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),jx({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),jx({id:`library.open-document-themes`,title:`Open document themes`,group:`Library`,keywords:[`pdf`,`documents`],run:()=>{e({to:`/document-themes`})}}),null}function I4({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:z(`mb-5 flex min-h-9 flex-wrap items-center gap-x-4 gap-y-3`,n),children:[(0,h.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-3`,children:e}),t===void 0?null:(0,h.jsx)(Iy,{className:`ml-auto shrink-0`,children:t})]})}function yhe(){let{api:e}=V(),t=_(),n=I(hb(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(void 0),s=L({mutationFn:t=>Ys(e,t),onSettled:async()=>{o(void 0),await t.invalidateQueries({queryKey:H.documentThemes})}}),c=n.data,l=r!==void 0&&`saved`in r?c?.themes.find(e=>e.id===r.saved):void 0,u=r!==void 0&&`builtIn`in r?c?.builtIns.find(e=>e.name===r.builtIn):void 0,d=l===void 0&&u===void 0?c?.themes[0]:void 0,f=l??d,p=f===void 0?u??c?.builtIns[0]:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(I4,{action:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:`plain`},variant:`primary`,children:`New theme`}),children:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`How a project's PDF looks. Pick one on the Document row in Play or in Edit project.`})}),n.error===null?null:(0,h.jsx)(P4,{what:`document themes`,message:n.error.message,onRetry:()=>void n.refetch()}),c===void 0?n.error===null?(0,h.jsx)(N4,{label:`Document themes`}):null:(0,h.jsx)(QK,{className:j4,list:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`}),c.themes.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No themes of your own yet. Copy a built-in below to start one.`}):(0,h.jsx)(PH,{label:`Your themes`,children:c.themes.map(e=>(0,h.jsx)(FH,{className:M4,lead:(0,h.jsx)(H4,{colors:e.values.colors}),title:e.name,meta:`${L4(e.values)} · updated ${A4(e.updatedAt)}`,selected:e.id===f?.id,onSelect:()=>i({saved:e.id}),actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>o(e)})},e.id))})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(PH,{label:`Built-in themes`,children:c.builtIns.map(e=>(0,h.jsx)(FH,{className:M4,lead:(0,h.jsx)(H4,{colors:e.values.colors}),title:e.label,meta:L4(e.values),selected:e.name===p?.name,onSelect:()=>i({builtIn:e.name}),actions:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:f===void 0?p===void 0?null:(0,h.jsx)(B4,{name:p.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:p.values,action:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:p.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(B4,{name:f.name,kicker:`Your theme`,meta:`Updated ${A4(f.updatedAt)}`,values:f.values,action:(0,h.jsx)(CS,{to:`/document-themes/$themeId`,params:{themeId:f.id},size:`small`,children:`Edit theme`})})}),s.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:s.error.message}),(0,h.jsx)(Hy,{open:a!==void 0,title:`Delete "${a?.name??``}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:s.isPending,onConfirm:()=>{a!==void 0&&s.mutate(a.id)},onCancel:()=>o(void 0)})]})}function L4(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${R4(e.fonts.body.family)} body`}function R4(e){return a4.find(t=>t.value===e)?.label??e}function z4(e){return e.startsWith(`#`)?e:`#${e}`}function B4({name:e,kicker:t,meta:n,values:r,action:i}){let a=[[`Headings`,r.colors.heading],[`Text`,r.colors.text],[`Muted`,r.colors.muted],[`Header and page numbers`,r.colors.faint]],o=[[`Body`,r.fonts.body],[`Headings`,r.fonts.heading],[`Drop cap`,r.fonts.dropCap]];return(0,h.jsxs)(`section`,{"aria-label":`${e} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(W,{title:e,kicker:t,meta:n,className:`pb-0`,children:i}),(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-[max-content_minmax(0,1fr)]`,children:[a.map(([e,t])=>(0,h.jsx)(V4,{label:e,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-4 rounded-full border border-line`,style:{backgroundColor:z4(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:z4(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(V4,{label:`${e} font`,children:`${R4(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(V4,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${z4(r.background.color)}`} background`})]})]})}function V4({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function H4({colors:e}){return(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`flex shrink-0 gap-1`,children:[e.heading,e.text,e.muted].map((e,t)=>(0,h.jsx)(`span`,{className:`size-3 rounded-full border border-line`,style:{backgroundColor:z4(e)}},t))})}function U4(e){let t=e.map(e=>e.message).join(` `);return`The name wasn't saved. ${t===``?`Pick another name and press Save name again.`:t}`}function W4({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Ry(),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(e),[u,d]=(0,m.useState)(null),[f,p]=(0,m.useState)(!1),g=(0,m.useRef)(!1),_=async e=>{try{return await n(e)}catch(e){return`The name wasn't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then press Save name again.`}},v=async()=>{let t=c.trim();if(t===e){s(!1),d(null);return}if(t===``){d(`Write a name first, or press Cancel to keep the old one.`);return}if(g.current)return;g.current=!0,p(!0);let n=await _(t);if(g.current=!1,p(!1),n!==null){d(n);return}s(!1),d(null),a(`Renamed “${e}” to “${t}”.`,`success`,{label:`Undo`,run:()=>void _(e).then(t=>{t===null?a(`Renamed back to “${e}”.`,`success`):a(t,`error`)})})},y=()=>{s(!1),l(e),d(null)};return o?(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(zB,{autoFocus:!0,"aria-label":`New name for ${e}`,"aria-invalid":u!==null,maxLength:i,value:c,className:`min-w-0 flex-1`,onChange:e=>{l(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v()):e.key===`Escape`&&(e.preventDefault(),y())}}),(0,h.jsx)(B,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(U,{id:r,label:`Rename`})]}),u===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small font-normal text-danger`,children:u})]}):(0,h.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[t===void 0?(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:e}):(0,h.jsx)(IH,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(Py,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function bhe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=V(),a=_(),o=I(mb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=Mx(l,`intros and outros`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=L({mutationFn:e=>ec(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:H.entries})}}),x=async(e,t)=>{let n=await Ks(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:H.entries}),n.ok?null:U4(n.fields)},S=o.data?.entries.filter(t=>t.category===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(I4,{action:(0,h.jsx)(CS,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`}),children:[(0,h.jsx)(zB,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":Ux(u),placeholder:`Search intros and outros`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsx)(Vb,{label:`Entry category`,value:e,options:TB.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`})]}),o.error===null?null:(0,h.jsx)(P4,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(N4,{label:`Intros and outros`}):null:S.length===0?(0,h.jsx)(She,{category:e}):(0,h.jsx)(QK,{className:j4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${e}s match "${s.trim()}".`}):(0,h.jsx)(PH,{label:`${DB(e)}s`,children:w.map(e=>(0,h.jsx)(FH,{className:M4,title:(0,h.jsx)(W4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:xhe(e),selected:e.id===T?.id,actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/entries/new`,search:{category:e.category,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(O4,{item:`entry`,id:T.id,name:T.name,kicker:`${DB(T.category)} · ${OB(T.mode)}`,meta:`Updated ${A4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(CS,{to:`/entries/$entryId`,params:{entryId:T.id},size:`small`,children:`Edit ${T.category}`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(w4,{item:`entry`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(Hy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${p?.category??e}`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function xhe(e){return`${OB(e.mode)} · ${k4(e.slots.length,`keyword`)} · updated ${A4(e.updatedAt)}`}function She({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(T1,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function Che({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:z(`animate-tick-in rounded-control border border-line-strong bg-sunken px-2 py-0.5 font-mono text-label text-ink-2 motion-reduce:animate-none`,t),children:e})}function G4({slots:e,body:t,lint:n,lintId:r,noSlots:i=`No slots. This prompt runs as written.`}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Detected slots`,info:`library.slots`,size:`small`,className:`pb-0`}),e.length>0?(0,h.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.map(e=>(0,h.jsx)(Che,{name:e,className:`px-2 py-1`},e))}):t.trim()===``?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Slots appear here as you type {{name}}.`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i}),n.length===0?null:(0,h.jsxs)(`div`,{id:r,className:`flex flex-col gap-2 border-t border-line pt-3`,children:[(0,h.jsx)(`span`,{className:`sl-kicker text-danger`,children:n.length===1?`1 slot error`:`${String(n.length)} slot errors`}),n.map(e=>(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message},e.message))]})]})}function K4({className:e,...t}){return(0,h.jsx)(uy,{"data-slot":`label`,className:z(`engraved block select-none text-ink-3`,e),...t})}function q4({className:e,...t}){return(0,h.jsx)(nte,{"data-slot":`toggle-group`,className:z(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function J4({className:e,...t}){return(0,h.jsx)(ste,{"data-slot":`toggle-group-item`,className:z(`min-h-8 shrink-0 border-r border-line-strong px-3 py-1 text-label text-ink-2 last:border-r-0`,`transition-colors duration-150 ease-out motion-reduce:transition-none hover:bg-raised hover:text-ink`,`data-[state=on]:bg-raised data-[state=on]:text-ink data-[state=on]:shadow-[inset_0_-2px_0_var(--color-accent)]`,`disabled:cursor-not-allowed disabled:opacity-40`,e),...t})}function Y4({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{id:o,children:e}),i===void 0?null:(0,h.jsx)(U,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(q4,{type:`single`,value:t,"aria-labelledby":o,"aria-describedby":r,onValueChange:e=>{let t=n.find(t=>t.value===e);t!==void 0&&a(t.value)},children:n.map(e=>(0,h.jsx)(J4,{value:e.value,children:e.label},e.value))})]})}function whe(e){return X4(e.name,e.body)}function The(e){return X4(e.name,e.body)}function X4(e,t){let n=[],r=e.trim();if(r===``?n.push({field:`name`,message:`Enter a name.`}):r.length>200&&n.push({field:`name`,message:`Keep the name to 200 characters or fewer.`}),t.trim()===``)return n.push({field:`body`,message:`Enter the text.`}),n;if(t.length>1e5)return n.push({field:`body`,message:`The text is too long. Keep it to ${String(_M)} characters or fewer.`}),n;for(let e of MK(t).errors)n.push({field:`body`,message:Ehe(e,t)});return n}function Ehe(e,t){let n=Dhe(t,e.at);switch(e.kind){case`unclosed`:return`The \`{{\` at ${n} is never closed. Add \`}}\` after the keyword name.`;case`empty`:return`The keyword at ${n} has no name. Write a name between \`{{\` and \`}}\`.`;case`nested`:return`The keyword at ${n} contains a brace. Keywords cannot be placed inside other keywords.`}}function Dhe(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
276
276
  `),i=n.split(`
277
- `).length,a=t-r;return`line ${String(i)}, column ${String(a)}`}function Z4(e,t){return[...`kind`in e?She(e):Che(e),...t]}function Q4(e){return e[0]?.message}function $4(e){return e.filter(e=>e.field===`body`)}function e3(e){return e.filter(e=>e.field===`name`)}function t3(e){return MK(e).names}function Ehe(e){let t=[],n=0;for(let r of MK(e).errors){if(r.at<n)continue;r.at>n&&t.push({start:n,text:e.slice(n,r.at),marked:!1});let i=Math.min(r.at+2,e.length);t.push({start:r.at,text:e.slice(r.at,i),marked:!0}),n=i}return n<e.length&&t.push({start:n,text:e.slice(n),marked:!1}),t}var n3=`px-3 py-3 font-sans text-body leading-[1.5] break-words [scrollbar-gutter:stable]`;function r3({id:e,value:t,invalid:n,describedBy:r,onChange:i}){let a=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:`relative max-w-[75ch]`,children:[(0,h.jsxs)(`div`,{ref:a,"aria-hidden":`true`,"data-slot":`lint-overlay`,className:z(n3,`pointer-events-none absolute inset-0 overflow-hidden whitespace-pre-wrap`,`rounded-control border border-transparent bg-sunken text-ink`),children:[Ehe(t).map(e=>(0,h.jsx)(`span`,{"data-lint-mark":e.marked?e.start:void 0,className:e.marked?`text-danger underline decoration-danger decoration-2 underline-offset-[3px]`:void 0,children:e.text},e.start)),`
278
- `]}),(0,h.jsx)(BB,{id:e,rows:24,value:t,spellCheck:!1,"aria-invalid":n,"aria-describedby":r,className:z(n3,`relative block min-h-[520px] resize-y border-line-strong overflow-auto bg-transparent text-transparent caret-ink`),onChange:e=>{i(e.target.value)},onScroll:e=>{let t=a.current;t!==null&&(t.scrollTop=e.currentTarget.scrollTop,t.scrollLeft=e.currentTarget.scrollLeft)}})]})}function i3({entryId:e,category:t,from:n,onLeave:r}){let{api:i}=V(),a=_(),o=I(mb(i)),s=(0,m.useId)(),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),S=o.data?.entries,C=e??n,w=C===void 0?void 0:S?.find(e=>e.id===C),T=w===void 0?{category:t,mode:`text`,name:``,body:``}:{category:w.category,mode:w.mode,name:e===void 0?`${w.name} copy`:w.name,body:w.body},E=d??T,D=L({mutationFn:t=>Ks(i,t,e),onSuccess:async e=>{if(!e.ok){g(e.fields);return}y(!0),await a.invalidateQueries({queryKey:mb(i).queryKey})}}),O=L({mutationFn:e=>ec(i,e),onSuccess:async()=>{x(!1),await a.invalidateQueries({queryKey:mb(i).queryKey}),r(E.category)}});K2(v,()=>{r(E.category)});let k=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},A=Z4(E,p),j=Q4(A),M=t3(E.body),ee=E.body.trim()===``?[]:$4(A),N=E.name.trim()===``?[]:e3(A);return o.error===null?C!==void 0&&S===void 0?(0,h.jsx)(Y2,{}):C!==void 0&&w===void 0?(0,h.jsx)(a3,{category:t,children:`That entry is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/entries`,search:{category:E.category},children:`Intros & Outros`})}),title:e===void 0?`New entry`:`Edit entry`,meta:DB(E.category)}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{className:`min-w-[200px] flex-1`,children:(0,h.jsx)(LB,{label:`Name`,tip:`library.entry.name`,...N.length===0?{}:{error:N.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:E.name,onChange:e=>{k({...E,name:e.target.value},`name`)}})})}),(0,h.jsx)(Y4,{label:`Category`,value:E.category,options:TB,tip:`library.entry.category`,onPick:e=>{k({...E,category:e},`name`)}}),(0,h.jsx)(Y4,{label:`Mode`,value:E.mode,options:EB,describedBy:s,tip:`library.entry.mode`,onPick:e=>{k({...E,mode:e},`mode`)}})]}),(0,h.jsx)(`p`,{id:s,className:`-mt-2 text-right text-small text-ink-2`,children:kB(E.mode)}),(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(U,{id:`library.entry.body`,label:`Body`,className:`-my-1`})]}),(0,h.jsx)(r3,{id:c,value:E.body,invalid:ee.length>0,describedBy:ee.length===0?void 0:l,onChange:e=>{k({...E,body:e},`body`)}})]}),(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{x(!0)},blocked:j,blockedId:u,pending:D.isPending,saved:v,cancel:(0,h.jsx)(CS,{to:`/entries`,search:{category:E.category},variant:`secondary`,children:`Cancel`}),errors:[D.error,O.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{D.mutate(E)}})]}),(0,h.jsx)(`div`,{className:u4,children:(0,h.jsx)(G4,{slots:M,body:E.body,lint:ee,lintId:l,noSlots:AB(E.mode)})})]}),(0,h.jsx)(Hy,{open:b,title:`Delete "${E.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${E.category}`,pending:O.isPending,onConfirm:()=>{e!==void 0&&O.mutate(e)},onCancel:()=>{x(!1)}})]}):(0,h.jsx)(a3,{category:E.category,children:o.error.message})}function a3({category:e,children:t}){return(0,h.jsx)(f4,{back:(0,h.jsx)(fa,{to:`/entries`,search:{category:e},children:`Back to Intros & Outros`}),children:t})}var Dhe=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),Ohe=new Intl.DateTimeFormat(void 0,{timeStyle:`short`});function khe({runs:e}){return(0,h.jsx)(PH,{label:`Coming up`,children:e.map(e=>(0,h.jsx)(FH,{title:`${Dhe.format(new Date(e.at))} · ${Ohe.format(new Date(e.at))} · ${jH(e)}`,meta:[e.scheduleName,e.templateName].filter(e=>e!==null).join(` · `),actions:e.paused?(0,h.jsx)(kS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(kS,{tone:`info`,children:`Needs a topic`}):(0,h.jsx)(kS,{children:`Queued`})},`${e.scheduleId}-${e.at}`))})}var o3=Y({revisionId:K(),checkpoints:J(Wj.unwrap().extend({currentFingerprint:K().regex(/^[a-f0-9]{64}$/),dependents:J(X(KS)),workKeys:J(K())}))}),Ahe=Y({revisionId:K().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),stages:J(Uj).max(3).refine(e=>new Set(e).size===e.length).readonly()}).strict(),jhe=Y({title:K(),status:q(),detail:K().optional(),reason:X([`duplicate`,`not-found`,`conflict`,`invalid-input`]).optional()}),Mhe=Gj.unwrap().omit({projectId:!0,checkpointId:!0,approvedAt:!0}),s3=e=>[`checkpoints`,e],c3=(e,t)=>[...s3(e),t];async function l3(e,t){let n;try{n=await e.json()}catch{throw lo(e,void 0)}if(e.ok)return{ok:!0,value:yo(t,n)};let r=jhe.safeParse(n);if(!r.success)throw lo(e,void 0);if(![400,404,409].includes(e.status))throw Error(r.data.detail??r.data.title);return{ok:!1,reason:r.data.reason??`invalid-input`,message:r.data.detail??r.data.title}}async function u3(e,t){return l3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`),o3)}async function d3(e,t,n,r){return l3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints/${encodeURIComponent(n)}/approve`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(Mhe.parse(r))}),Y({checkpoint:Wj,replayed:RD()}))}async function Nhe(e,t,n){return l3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(Ahe.parse(n))}),o3)}var f3=(0,m.createContext)(void 0);function p3(e,t){if(e.state===`failed`)return s1({stage:e.kind,kind:e.failureKind,reason:e.failureReason,provider:cfe(t.config,e.kind)})}var Phe=[`home`,`week`];function Fhe(e=new Date){let t=new Date(e);t.setHours(0,0,0,0);let n=(t.getDay()+6)%7;return t.setDate(t.getDate()-n),t}function Ihe(e,t,n){return at({queryKey:[...Phe,t,n],queryFn:async()=>{let r=new URLSearchParams({since:t});return n!==null&&r.set(`channelId`,n),R(await e.fetch(`${e.origin}/api/home/week?${r.toString()}`))},staleTime:3e4})}async function Lhe(e,t,n){return R(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/set-aside`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({setAside:n})}))}async function m3(e,t,n){return R(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/uploaded`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({uploaded:n})}))}function h3({projectId:e,className:t}){let{api:n}=V(),[r,i]=(0,m.useState)(!1);return(0,h.jsx)(`div`,{className:z(`sl-media__frame`,t),"aria-hidden":`true`,children:r?(0,h.jsx)(`div`,{className:`flex size-full items-center justify-center bg-sunken text-ink-3`,children:(0,h.jsx)(Nc,{strokeWidth:1.75,className:`size-6`})}):(0,h.jsx)(`img`,{src:Wo(n,e,`thumbnail`),alt:``,loading:`lazy`,decoding:`async`,onError:()=>i(!0)})})}function g3(e){return e.status===`pending`&&e.progress>0&&e.setAside!==!0}function _3({lead:e,status:t,title:n,detail:r,action:i}){return(0,h.jsxs)(`li`,{className:z(`sl-home-item`,MH),children:[e,(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[t,(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:n}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:r})]}),(0,h.jsx)(Iy,{className:`sl-home-item__action`,children:i})]})}function v3(e){return(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}var Rhe={audio:`Approve the article and record`,images:`Approve and draw the images`,video:`Approve and render`},zhe={audio:`review before the narration`,images:`review before the images`,video:`review before the video`};function Bhe({project:e,primary:t}){let{api:n}=V(),r=_(),i=Ry(),a=Ji(),o=(0,m.useRef)(null),s=I({queryKey:s3(e.id),queryFn:async()=>{let t=await u3(n,e.id);if(!t.ok)throw Error(t.message);return t.value}}).data?.checkpoints.find(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint),c=L({mutationFn:async t=>{o.current??={revisionId:t.revisionId,fingerprint:t.fingerprint,idempotencyKey:crypto.randomUUID()};let r=await d3(n,e.id,t.checkpointId,o.current);return o.current=null,r},onSuccess:t=>{i(t.ok?`Approved: ${e.title}. The run continues.`:`${e.title} wasn't approved: ${t.message} Open the project to review it there.`,t.ok?`success`:`error`)},onError:t=>{i(`Slopify didn't confirm the approval of ${e.title}: ${t.message} Press the button again to check whether it went through.`,`error`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:s3(e.id)}),r.invalidateQueries({queryKey:H.projects})])}}),l=L({mutationFn:t=>Lhe(n,e.id,t),onSuccess:(t,n)=>{i(n?`Kept as is: ${e.title}. It is off Needs you; editing the project brings it back.`:`${e.title} is back on Needs you.`,`success`,n?{label:`Undo`,run:()=>l.mutate(!1)}:void 0)},onError:t=>{i(`${e.title} wasn't kept as is: ${t.message} Press Keep as is again.`,`error`)},onSettled:()=>r.invalidateQueries({queryKey:H.projects})}),u=s===void 0?void 0:Rhe[s.stage];return jx({id:`home.approve.${e.id}`,title:u??`Open the held run`,group:`Needs you`,context:e.title,keywords:[`approve`,`review`,`waiting`],run:()=>{s===void 0?a({to:`/projects/$projectId`,params:{projectId:e.id}}):c.mutate(s)}}),(0,h.jsx)(_3,{lead:(0,h.jsx)(h3,{projectId:e.id}),status:(0,h.jsx)(OS,{tone:`waiting`,children:s===void 0?`Waiting for you`:`Waiting for you · ${zhe[s.stage]}`}),title:v3(e),detail:s===void 0?`Its next step is held. Open the project to review it and continue the run.`:`Everything before this step is done. Approve to let the run go on, or open the project to look first.`,action:s===void 0||u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`}),(0,h.jsx)(B,{variant:`quiet`,disabled:l.isPending,disabledReason:`Saving…`,onClick:()=>l.mutate(!0),children:`Keep as is`})]}):(0,h.jsx)(B,{variant:t?`primary`:`secondary`,disabled:c.isPending,disabledReason:`Approving…`,onClick:()=>c.mutate(s),children:c.isPending?`Approving…`:u})})}function Vhe({schedule:e,primary:t}){let n=e.topics.held;return(0,h.jsx)(_3,{lead:(0,h.jsx)(`div`,{className:`sl-media__frame flex items-center justify-center bg-sunken text-info`,children:(0,h.jsx)(Lc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-7`})}),status:(0,h.jsx)(OS,{tone:`info`,children:`${String(n)} new ${n===1?`topic`:`topics`}`}),title:e.name,detail:`Slopify suggested ${n===1?`a topic`:`${String(n)} topics`} for this schedule. Queue the ones you want and reject the rest.`,action:(0,h.jsx)(CS,{to:`/calendar`,variant:t?`primary`:`secondary`,className:NH,children:`Review topics`})})}function Hhe({project:e,primary:t}){return(0,h.jsx)(_3,{lead:(0,h.jsx)(h3,{projectId:e.id}),status:(0,h.jsx)(OS,{tone:`waiting`,children:`Paused`}),title:v3(e),detail:`You paused this run. Nothing more happens until you open it and press Continue the run.`,action:(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`})})}function Uhe({project:e,primary:t}){let{api:n}=V(),r=I({queryKey:H.project(e.id),queryFn:()=>Oo(n,e.id)}),i=r.data?.stages.find(e=>e.state===`failed`),a=Ry(),o=async e=>{let t=await p1(e);a(t?`Copied ${e}. Run it in a terminal on the computer running Slopify and sign in, then open the project and press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e} in a terminal, sign in, then open the project and press Check again.`,t?`success`:`error`)},s=i===void 0||r.data===void 0?void 0:p3(i,r.data.project),c=NP(i?.failureReason)??`The run stopped with an error.`,l=i===void 0?``:` · ${YP[i.kind]}`,u=t?`primary`:`secondary`,d=s?.kind===`provider-settings`?(0,h.jsx)(CS,{to:`/settings`,search:{section:`providers`},variant:u,children:s.label}):s?.kind===`free-space`?(0,h.jsx)(CS,{to:`/settings`,search:{section:`storage`},variant:u,children:s.label}):s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:u,onClick:()=>void o(s.command),children:`Copy sign-in command`}),(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},children:`Open to retry`})]}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:u,children:s?.label??`Open to retry`});return(0,h.jsx)(_3,{lead:(0,h.jsx)(h3,{projectId:e.id}),status:(0,h.jsx)(OS,{tone:`failed`,children:`Failed${l}`}),title:v3(e),detail:s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[c,` Run `,(0,h.jsx)(`code`,{className:`sl-code`,children:s.command}),` in a terminal to sign in, then press Check again on the project to retry the step.`]}):c,action:d})}function y3(e){return(e.status===`done`||e.status===`partial`||e.status===`pending`&&e.setAside===!0)&&e.config.sources.video!==`off`&&e.uploadedAt===null}function Whe({project:e}){let{api:t}=V(),n=_(),r=Ry(),i=L({mutationFn:n=>m3(t,e.id,n),onSuccess:(t,n)=>{r(n?`Marked uploaded: ${e.title}. It is off Ready to upload; Projects still lists it.`:`${e.title} is back on Ready to upload.`,`success`)},onError:t=>{r(`${e.title} wasn't marked uploaded: ${t.message} Press Mark uploaded again.`,`error`)},onSettled:async()=>{await n.invalidateQueries({queryKey:H.projects})}});return jx({id:`home.uploaded.${e.id}`,title:`Mark uploaded`,group:`Ready to upload`,context:e.title,keywords:[`youtube`,`published`,`done`],run:()=>i.mutate(!0)}),(0,h.jsxs)(`li`,{className:`sl-home-ready ${MH}`,children:[(0,h.jsx)(h3,{projectId:e.id}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title`,children:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:`${e.format} · finished ${Wu(e.updatedAt)}${e.status===`partial`?` · a step failed`:``}`}),(0,h.jsxs)(Iy,{children:[(0,h.jsx)(B0,{projectId:e.id,ready:!0,size:`small`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:i.isPending,disabledReason:`Saving…`,onClick:()=>i.mutate(!0),children:`Mark uploaded`})]})]})]})}function b3(e){return e.status===`pending`&&e.progress===0}var Ghe=2;function Khe({running:e,queued:t}){let n=e>3;if(!n&&t.length===0)return null;let r=t.slice(0,Ghe).map(e=>e.title.trim()||`Untitled project`),i=t.length-r.length;return(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n?(0,h.jsx)(`div`,{children:(0,h.jsx)(wS,{to:`/projects`,search:{show:`running`},children:`See all ${String(e)} running`})}):null,t.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-ink`,children:`Queued, waiting to start (${String(t.length)}): `}),r.join(`, `),i>0?` and ${String(i)} more`:``]}),(0,h.jsx)(wS,{to:`/projects`,search:{show:`queued`},children:`See queued`})]})]})}function x3(e,t){if(e.state!==`running`)return;let n=e.startedAt===null?NaN:Date.parse(e.startedAt),r=Number.isFinite(n)?Math.max(0,(t-n)/1e3):void 0,i=e.progressCurrent??0,a=e.progressTotal??0;if(r!==void 0&&a>0&&i>0)return i>=a?{basis:`progress`,seconds:0}:{basis:`progress`,seconds:Math.round(r/i*(a-i))};let o=e.typicalSeconds;if(o===void 0||!Number.isFinite(o)||o<=0)return{basis:`unknown`};let s=o-(r??0);return s>0?{basis:`history`,seconds:Math.round(s)}:{basis:`overdue`}}function S3(e){if(e.basis===`unknown`)return`time left unknown`;if(e.basis===`overdue`)return`taking longer than usual`;let t=e.seconds??0;if(t<=0)return`finishing up`;if(t<60)return`under a minute left`;let n=Math.round(t/60);if(n<60)return`about ${String(n)} min left`;let r=Math.floor(n/60),i=n%60;return i===0?`about ${String(r)} h left`:`about ${String(r)} h ${String(i)} min left`}function C3(e){let t=e.role.replaceAll(`_`,`-`);return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment!==void 0?`${t}-${e.meta.segment}`:e.role===`short_video`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}`:e.role===`short_image`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}-${String(e.meta.index??1)}`:e.role===`thumbnail`&&e.meta.index!==void 0&&e.meta.index>1?`${t}-${String(e.meta.index)}`:e.role===`instructions`?`${e.stageKind}-${t}`:(e.role===`image`||e.role===`animated_image`)&&e.meta.index!==void 0?`${t}-${String(e.meta.index)}`:t}function w3({steps:e,label:t,dense:n=!1,className:r}){return(0,h.jsx)(`ol`,{"aria-label":t,className:z(`sl-steps m-0 list-none p-0`,n&&`sl-steps--dense`,r),children:e.map(e=>(0,h.jsxs)(`li`,{className:`sl-step`,"data-tone":e.tone,children:[(0,h.jsx)(DS,{tone:e.tone}),(0,h.jsxs)(`span`,{className:`sl-step__name`,children:[e.name,(0,h.jsx)(`span`,{className:`sr-only`,children:`, ${e.state}`})]}),(0,h.jsx)(`span`,{className:`sl-step__time`,children:e.time??`—`}),e.detail===void 0?null:(0,h.jsx)(`span`,{className:`sl-step__detail`,children:e.detail})]},e.id))})}function T3(e){let{api:t}=V();return I({...sb(t,e),enabled:!1,select:e=>e.revisionId??null}).data??null}var E3=(e,t=null)=>[`live-writing`,e,t];function qhe(e,t){let n=e=>e.callId===t.callId&&e.revisionId===t.revisionId&&e.workId===t.workId,r=e.find(n),i=(t.reset?t.text:`${r?.text??``}${t.text}`).slice(-65536),a={...t.revisionId===void 0?{}:{revisionId:t.revisionId},...t.workId===void 0?{}:{workId:t.workId},...t.workPieceId===void 0?{}:{workPieceId:t.workPieceId},stage:t.stage,callId:t.callId,...t.label===void 0?{}:{label:t.label},text:i};return(r?e.map(e=>n(e)?a:e):[...e,a]).slice(-24)}function D3({projectId:e,stage:t,className:n=`mx-5 mt-5`}){let r=(I({queryKey:E3(e,T3(e)),queryFn:()=>[],enabled:!1}).data??[]).filter(e=>e.stage===t),[i,a]=(0,m.useState)(),o=r.find(e=>e.callId===i)??r.at(-1),[s,c]=(0,m.useState)(!0),l=(0,m.useRef)(null);return(0,m.useEffect)(()=>{o?.text&&s&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},[s,o?.text]),r.length===0&&t!==`research`&&t!==`article`?null:(0,h.jsxs)(`div`,{className:z(`border-y border-line`,n),children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-line py-3`,...zb,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-accent-ink`,children:`Live writing`}),(0,h.jsx)(U,{id:`project.live.writing`})]}),r.length>1?(0,h.jsx)(VB,{"aria-label":`Live writing task`,value:o?.callId??``,onChange:e=>a(e.target.value),className:`max-w-[280px]`,children:r.map((e,t)=>(0,h.jsxs)(`option`,{value:e.callId,children:[e.label??`Writing`,` · `,t+1]},e.callId))}):null,(0,h.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Follow output`]})]}),(0,h.jsx)(`section`,{ref:l,"aria-label":`Live writing preview`,tabIndex:0,className:`max-h-[360px] min-h-32 overflow-auto whitespace-pre-wrap break-words py-4 font-sans text-small leading-relaxed text-ink-2`,children:o?.text||`Waiting for the provider's first text…`}),(0,h.jsx)(`p`,{className:`border-t border-line py-2 text-label text-ink-3`,children:`Live preview. The complete output is saved when this stage finishes.`})]})}var Jhe=Y({id:K(),projectId:K(),revisionId:K(),itemKey:K(),stage:X(gk),itemFingerprint:K(),reviewFingerprint:K(),passed:RD(),reasons:J(K()),outcome:X([`passed`,`flagged`,`redo`]),attempt:q(),action:X([`overruled`,`redone`]).nullable(),actionAt:K().nullable(),redoState:X([`pending`,`started`,`failed`]).nullable(),redoError:K().nullable(),createdAt:K(),current:RD(),outputId:K().nullable(),verdicts:q()}),O3=e=>[`reviews`,e],Yhe=Y({title:K(),detail:K().optional()});async function Xhe(e,t){let n=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews`);if(!n.ok)throw lo(n,void 0);return yo(Y({reviews:J(Jhe)}),await n.json()).reviews}async function Zhe(e,t,n,r,i){let a=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews/${encodeURIComponent(n)}/${r}`,{method:`POST`,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}});if(a.ok)return{ok:!0};let o;try{o=await a.json()}catch{throw lo(a,void 0)}let s=Yhe.safeParse(o);if(!s.success||![400,404,409,503].includes(a.status))throw lo(a,void 0);return{ok:!1,message:s.data.detail??s.data.title}}var Qhe=200;function k3(e,t=null){let{api:n,openEvents:r}=V(),i=_();(0,m.useEffect)(()=>{i.setQueryData(H.article(e,t),``),i.setQueryData(E3(e,t),[]);let a=()=>i.getQueryData(H.project(e))?.revisionId??null,o=Kz(()=>{i.invalidateQueries({queryKey:H.project(e)}),i.invalidateQueries({queryKey:H.projects}),i.invalidateQueries({queryKey:s3(e)}),i.invalidateQueries({queryKey:O3(e)})},Qhe),s=VS(r,tc(n,`projects/${e}`),{refetch:o.ask,accept:e=>e.type===`project.updated`||e.type===`project.state`&&e.revisionId===void 0||(e.revisionId??null)===a()||(o.ask(),!1),previewWriting:t=>{i.setQueryData(E3(e,a()),e=>qhe(e??[],t))},narrationPiece:()=>{i.invalidateQueries({queryKey:Gy(e,a())})},appendArticle:t=>{i.setQueryData(H.article(e,a()),e=>`${e??``}${t}`)},patch:t=>{if(t.type===`stage.state`&&t.state===`running`&&(i.setQueryData(E3(e,a()),e=>(e??[]).filter(e=>e.stage!==t.stage||e.workId!==t.workId||e.revisionId!==t.revisionId)),t.stage===`article`&&i.setQueryData(H.article(e,a()),``)),t.type!==`project.state`&&t.workId!==void 0){o.ask();return}i.setQueryData(H.project(e),e=>lde(e,t))}});return()=>{s(),o.stop()}},[n,r,i,e,t])}var $he={pending:`off`,running:`running`,done:`done`,provided:`done`,failed:`failed`,canceled:`off`,skipped:`off`},ege={pending:`Not started`,running:`Running`,done:`Done`,provided:`Provided`,failed:`Failed`,canceled:`Canceled`,skipped:`Skipped`};function tge(e,t,n){if(e===null)return;let r=(t===null?n:Date.parse(t))-Date.parse(e);if(!Number.isFinite(r)||r<0)return;let i=Math.round(r/1e3);if(i<60)return`${String(i)} s`;let a=Math.round(i/60);if(a<60)return`${String(a)} min`;let o=Math.floor(a/60);return`${String(o)} h ${String(a%60)} min`}function nge(e,t){let n=x3(e,t);if(n===void 0)return;let r=nF(e);return r===void 0?`${e.progressTotal!==null&&e.progressTotal>0?`${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)} · `:``}${S3(n)}`:n.basis===`unknown`?rF(r):`${rF(r)} · ${S3(n)}`}function rge({project:e,now:t}){let{api:n}=V();k3(e.id);let[r,i]=(0,m.useState)(null),a=I(sb(n,e.id)),o=(a.data?.stages??[]).filter(e=>e.source!==`off`&&e.state!==`skipped`),s=(a.data?.outputs??[]).filter(e=>e.role===`image`).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),c=o.find(e=>e.kind===`images`&&e.state===`running`),l=o.find(e=>e.state===`running`),u=gH(e.limitWaits),d=s.slice(c===void 0?-4:-3),f=o.map(n=>({id:n.kind,name:ZP(n.kind,e.config),tone:$he[n.state],state:ege[n.state],time:tge(n.startedAt,n.finishedAt,t),detail:nge(n,t)}));return(0,h.jsxs)(`li`,{className:`sl-home-run ${MH}`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),e.status===`paused`?(0,h.jsx)(OS,{tone:`waiting`,children:`Paused`}):u===void 0?(0,h.jsx)(OS,{tone:`running`,children:l===void 0?`Running`:`${ZP(l.kind,e.config)}`}):(0,h.jsx)(OS,{tone:`waiting`,children:u})]}),d.length===0&&c===void 0?null:(0,h.jsxs)(u0,{list:!0,density:`compact`,label:`Images of ${e.title}`,children:[d.map((t,r)=>(0,h.jsx)(`li`,{children:(0,h.jsx)(l0,{src:Wo(n,e.id,C3(t)),alt:`Image ${String(t.meta.index??``)}`,onOpen:()=>i(r)})},t.id)),c===void 0?null:(0,h.jsx)(`li`,{children:(0,h.jsx)(l0,{alt:`The next image`,generating:`Drawing · ${String(s.length)} so far`})})]}),(0,h.jsx)(d0,{items:d.map(t=>({src:Wo(n,e.id,C3(t)),alt:`Image ${String(t.meta.index??``)}`,...t.meta.prompt===void 0?{}:{caption:t.meta.prompt}})),index:r,onIndex:i,onClose:()=>i(null)}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Images ${String(c.progressCurrent??s.length)} of ${String(c.progressTotal??`?`)}`})]}),(0,h.jsx)(w3,{steps:f,label:`Steps of ${e.title}`})]})}var A3=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2});function ige(e){return`spent${e.apiEquivalent===null?``:` · ~${A3.format(e.apiEquivalent)} via API`}${e.unpriced===0?``:` · ${String(e.unpriced)} ${e.unpriced===1?`call`:`calls`} without a price`}`}function age({channelId:e}){let{api:t}=V(),n=I(Ihe(t,Fhe().toISOString(),e));if(n.error!==null)return(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`This week's numbers didn't load: ${n.error.message} Reload the page to try again.`});let r=n.data;return(0,h.jsxs)(x2,{className:`sl-home-stats`,children:[(0,h.jsx)(S2,{value:r===void 0?`—`:String(r.videos),label:`videos made`}),(0,h.jsx)(S2,{value:r===void 0?`—`:A3.format(r.cost),label:r===void 0?`spent`:ige(r)}),(r?.plans??[]).filter(e=>e.weeklyPercent!==null).map(e=>{let t=Math.round(e.weeklyPercent??0);return(0,h.jsx)(S2,{value:`${String(t)}%`,label:`weekly ${e.name} limit`,children:(0,h.jsx)(C2,{value:t/100,label:`Weekly ${e.name} limit`,valueText:`${String(t)}% of your weekly ${e.name} limit`,tone:t>=80?`waiting`:`accent`})},e.account)})]})}var oge=864e5,sge=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`}),j3=4,M3=!1,N3=!1;function cge(){let{api:e}=V(),t=Dx(),n=I(ob(e)),r=I(qV(e)),i=I(lq(e)),[a]=(0,m.useState)(()=>{let e=new Date;return e.setHours(0,0,0,0),{from:new Date().toISOString(),to:new Date(e.valueOf()+8*oge).toISOString()}}),o=I(pH(e,a.from,a.to)),s=I({queryKey:Uy,queryFn:()=>qy(e)}),c=Ji();(0,m.useEffect)(()=>{s.data?.show===!0&&!M3&&(M3=!0,c({to:`/welcome`}))},[s.data?.show,c]),(0,m.useEffect)(()=>{s.data?.settle===!0&&!N3&&(N3=!0,Jy(e).catch(()=>{N3=!1}))},[s.data?.settle,e]);let[l,u]=(0,m.useState)(()=>Date.now());(0,m.useEffect)(()=>{let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[]);let d=(0,m.useMemo)(()=>new Map((i.data??[]).map(e=>[e.id,e.channelId])),[i.data]),f=(n.data?.projects??[]).filter(e=>t.includes(e.channelId)),p=f.filter(e=>e.status===`running`),g=f.filter(b3),_=f.filter(e=>e.status===`paused`),v=f.filter(g3),y=f.filter(e=>e.status===`failed`),b=new Set(Object.values(s.data?.samples??{}).filter(e=>e!==null)),x=f.filter(e=>y3(e)&&!b.has(e.id)),S=(r.data??[]).filter(e=>e.deletedAt===null&&e.topicGeneration.mode===`hold`&&e.topics.held>0&&t.includes(d.get(e.templateId))),C=(o.data?.runs??[]).filter(e=>t.includes(d.get(e.templateId))),w=[...v.map(e=>({kind:`waiting`,project:e})),..._.map(e=>({kind:`paused`,project:e})),...S.map(e=>({kind:`held`,schedule:e})),...y.slice(0,j3).map(e=>({kind:`failed`,project:e}))],T=n.isPending;return(0,h.jsxs)(`div`,{"data-tour":`home`,children:[(0,h.jsx)(XK,{display:!0,crumb:sge.format(new Date),title:t.channel?.name??`Home`,meta:t.channelId===null?`Every channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(CS,{to:`/play`,variant:`secondary`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]}),(0,h.jsxs)(CS,{to:`/calendar`,variant:`quiet`,children:[(0,h.jsx)(bc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open calendar`]})]})}),(0,h.jsxs)(`div`,{className:`mb-5 flex items-end gap-1 md:hidden`,...zb,children:[(0,h.jsx)(Ox,{className:`min-w-0 flex-1`}),(0,h.jsx)(U,{id:`home.channel`,className:`mb-1`})]}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-5 text-danger`,children:`Your projects didn't load: ${n.error.message} Check that Slopify is still running, then reload the page.`}),(0,h.jsxs)(b1,{split:`main-side`,children:[(0,h.jsxs)(x1,{children:[(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(W,{title:`Needs you`,info:`home.needs-you`,meta:T?`Loading…`:w.length===0?`Nothing is waiting for a decision`:`${String(w.length)} ${w.length===1?`thing is`:`things are`} waiting for you`}),w.length===0?null:(0,h.jsx)(`ul`,{"aria-label":`Waiting for you`,className:`m-0 flex list-none flex-col gap-3 p-0`,children:w.map((e,t)=>e.kind===`waiting`?(0,h.jsx)(Bhe,{project:e.project,primary:t===0},e.project.id):e.kind===`paused`?(0,h.jsx)(Hhe,{project:e.project,primary:t===0},e.project.id):e.kind===`held`?(0,h.jsx)(Vhe,{schedule:e.schedule,primary:t===0},e.schedule.id):(0,h.jsx)(Uhe,{project:e.project,primary:t===0},e.project.id))})]}),(0,h.jsxs)(`section`,{id:`running`,"aria-label":`Running now`,children:[(0,h.jsx)(W,{title:`Running now`,info:`home.running`,meta:p.length===0?`Nothing is running`:`${String(p.length)} ${p.length===1?`video`:`videos`}`}),p.length===0?T||g.length>0?null:(0,h.jsx)(T1,{title:`Start the next video`,children:`Pick a template and a topic on Play, or let a schedule start one.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:p.slice(0,3).map(e=>(0,h.jsx)(rge,{project:e,now:l},e.id))}),(0,h.jsx)(Khe,{running:p.length,queued:g})]})]}),(0,h.jsxs)(x1,{children:[(0,h.jsxs)(`section`,{"aria-label":`Coming up`,children:[(0,h.jsx)(W,{title:`Coming up`,info:`home.coming-up`,meta:`Next 7 days`,children:(0,h.jsx)(wS,{to:`/calendar`,children:`Calendar`})}),o.error===null?C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading…`:`No scheduled runs this week. Plan some on the calendar.`}):(0,h.jsx)(khe,{runs:C.slice(0,6)}):(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The calendar didn't load: ${o.error.message} Reload the page to try again.`})]}),(0,h.jsxs)(`section`,{"aria-label":`Ready to upload`,children:[(0,h.jsx)(W,{title:`Ready to upload`,info:`home.ready`,meta:x.length===0?`Finished videos you haven't marked uploaded show here`:`${String(x.length)} finished and not marked uploaded`}),x.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:x.slice(0,j3).map(e=>(0,h.jsx)(Whe,{project:e},e.id))})]}),(0,h.jsxs)(`section`,{"aria-label":`This week`,children:[(0,h.jsx)(W,{title:`This week`,info:`home.this-week`,meta:`Since Monday`}),(0,h.jsx)(age,{channelId:t.channelId})]})]})]})]})}function P3({className:e,...t}){return(0,h.jsx)(`input`,{"data-slot":`input`,className:z(`h-8 w-full min-w-0 rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,`placeholder:text-ink-3 aria-invalid:border-danger`,e),...t})}var lge={written:``,spoken:``,wholeWord:!0,caseSensitive:!1};function uge(){let{api:e}=V(),t=_(),n=I(gb(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)({}),[s,c]=(0,m.useState)(),l=(0,m.useRef)(0),u=(0,m.useId)(),d=e=>e.map(e=>(l.current+=1,{...e,key:l.current}));(0,m.useEffect)(()=>{r===void 0&&n.data!==void 0&&i(d(n.data.aliases))});let f=r??[],p=L({mutationFn:t=>$s(e,t),onSuccess:async e=>{if(!e.ok){let t={};for(let n of e.fields){let e=/^aliases\.(\d+)/u.exec(n.field)?.[1];e!==void 0&&(t[Number(e)]=n.message)}o(t),c({text:`Not saved: ${e.fields.map(e=>e.message).join(` `)}`,tone:`error`});return}o({}),i(d(e.value.aliases)),c({text:`Saved. New projects use these aliases; a project you already started keeps its copy until you refresh it in Edit project.`,tone:`success`}),await t.invalidateQueries({queryKey:H.narrationAliases})},onError:e=>c({text:`Couldn't save the aliases: ${e.message}`,tone:`error`})});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(I4,{action:(0,h.jsxs)(B,{type:`button`,onClick:()=>{l.current+=1,i([...f,{...lge,key:l.current}]),c(void 0)},disabled:r===void 0,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add alias`]}),children:(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Words the narrator says differently, like Dr. as Doctor.`,(0,h.jsx)(U,{id:`library.aliases`})]})}),n.error===null?null:(0,h.jsxs)(aI,{tone:`danger`,title:`Couldn't load the aliases`,className:`mb-6`,children:[n.error.message,` Reload the page to try again.`]}),(0,h.jsxs)(b1,{split:`aside`,children:[(0,h.jsx)(x1,{label:`Aliases`,children:r===void 0?null:f.length===0?(0,h.jsx)(T1,{title:`No aliases yet`,children:`Use Add alias to say a word differently from how it is written.`}):(0,h.jsx)(dge,{rows:f,errors:a,idPrefix:u,update:(e,t)=>{i(f.map(n=>n.key===e?{...n,...t}:n)),c(void 0)},remove:e=>{i(f.filter(t=>t.key!==e)),o({}),c(void 0)}})}),(0,h.jsx)(x1,{as:`aside`,label:`How aliases are used`,children:(0,h.jsxs)(`section`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(W,{title:`How they are used`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`The narrator reads the alias instead of the written word. The article, the captions and the PDF keep the written word.`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`A project takes a copy of this list when it starts and uses it while Use narration aliases is on. A project you already started keeps its copy until you refresh it in Edit project.`}),(0,h.jsx)(`p`,{className:`m-0`,children:`Whole word skips matches inside longer words; Match case only matches the exact capitals.`})]})})]}),(0,h.jsx)(y1,{status:(0,h.jsx)(v1,{tone:s?.tone??`info`,children:s?.text}),children:(0,h.jsx)(B,{type:`button`,variant:`primary`,disabled:r===void 0||p.isPending,onClick:()=>p.mutate(f.map(({written:e,spoken:t,wholeWord:n,caseSensitive:r})=>({written:e,spoken:t,wholeWord:n,caseSensitive:r}))),children:p.isPending?`Saving…`:`Save aliases`})})]})}function dge({rows:e,errors:t,idPrefix:n,update:r,remove:i}){return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-4 gap-y-1 pb-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Written`,(0,h.jsx)(U,{id:`library.aliases.written`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Say it as`,(0,h.jsx)(U,{id:`library.aliases.spoken`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Whole word`,(0,h.jsx)(U,{id:`library.aliases.whole-word`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Match case`,(0,h.jsx)(U,{id:`library.aliases.match-case`})]})]}),(0,h.jsx)(PH,{label:`Narration aliases`,children:e.map((e,a)=>{let o=`${n}-${e.key}`,s=t[a],c=e.written.trim(),l=e.spoken.trim();return(0,h.jsx)(FH,{title:`Alias ${String(a+1)}`,meta:c===``||l===``?`Not filled in yet`:`Says ${c} as ${l}${e.wholeWord?` · whole word`:``}${e.caseSensitive?` · match case`:``}`,actions:(0,h.jsx)(Py,{size:`small`,label:`Remove alias ${String(a+1)}`,onClick:()=>i(e.key),children:(0,h.jsx)($c,{"aria-hidden":`true`})}),children:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto_auto] md:items-end`,children:[(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-written`,children:[`Written`,(0,h.jsx)(P3,{id:`${o}-written`,value:e.written,placeholder:`Dr.`,maxLength:200,"aria-invalid":s!==void 0,"aria-describedby":s===void 0?void 0:`${o}-error`,onChange:t=>r(e.key,{written:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-spoken`,children:[`Say it as`,(0,h.jsx)(P3,{id:`${o}-spoken`,value:e.spoken,placeholder:`Doctor`,maxLength:500,"aria-invalid":s!==void 0,onChange:t=>r(e.key,{spoken:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.wholeWord,onChange:t=>r(e.key,{wholeWord:t.target.checked})}),`Whole word`]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.caseSensitive,onChange:t=>r(e.key,{caseSensitive:t.target.checked})}),`Match case`]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${o}-error`,className:`m-0 text-small text-danger md:col-span-4`,children:s})]})},e.key)})})]})}function F3(e){return MK(e).names}function fge(e,t){let n=F3(e),r=Object.create(null);for(let[e,i]of Object.entries(t))r[e]=n.includes(e)?``:i;return r}function pge(e){return{...e,form:{...e.form,values:fge(e.form.title,e.form.values)},variants:[]}}function I3({onDefaults:e}){let{api:t}=V(),n=_(),r=I({queryKey:c1.firstRun,queryFn:()=>mfe(t),retry:!1,staleTime:1/0}),i=r.data?.defaults;(0,m.useEffect)(()=>{i!==void 0&&(dN(i),e?.(i))},[i,e]);let a=L({mutationFn:()=>hfe(t),onSuccess:()=>n.invalidateQueries({queryKey:c1.firstRun})}),o=r.data;if(o===void 0||!o.firstRun||o.message===null)return null;let s=o.detected.filter(e=>e.usable);return(0,h.jsxs)(aI,{title:o.message,actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:a.isPending,onClick:()=>a.mutate(),children:`Got it`}),children:[o.detail===null?null:(0,h.jsx)(`p`,{className:`m-0`,children:o.detail}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0`,children:[`Found:`,` `,s.map(e=>`${e.displayName}${e.version===void 0?``:` ${e.version}`}`).join(`, `)]}),a.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:a.error.message}):null]})}function L3(){let{api:e}=V(),{document:t}=XN(),n=I(lq(e)),r=t.templateSource,i=n.data?.find(e=>e.id===r?.id);return t.channelId??(i===void 0?`00000000-0000-4000-8000-000000000001`:E1(i))}function R3(){let{api:e}=V();return I(lx(e,L3())).data?.cast??[]}function mge({disabled:e=!1}){let{api:t}=V(),n=XN(),r=I(cx(t)),{document:i}=n,a=L3(),o=r.data?.find(e=>e.id===a),s=i.form.useBrandKit!==!1,c=e=>{n.edit(e),n.invalidateReview(!0)};return(0,h.jsxs)(`div`,{className:`sl-fields items-end`,children:[(0,h.jsx)(LB,{label:`Channel`,tip:`play.channel`,children:(0,h.jsxs)(VB,{"data-play-field":`channelId`,value:a,disabled:e,onChange:e=>c({...i,channelId:e.target.value}),children:[r.data===void 0?(0,h.jsx)(`option`,{value:a,children:`Loading channels…`}):null,(r.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsx)(Bb,{label:`Use the channel's brand kit`,tip:`play.brand-kit`,checked:s,disabled:e,className:`min-h-[38px]`,onChange:e=>{let{useBrandKit:t,...n}=i.form;c({...i,form:e?n:{...n,useBrandKit:!1}})}}),o?(0,h.jsxs)(`p`,{className:`sl-fields__wide m-0 text-small text-ink-3`,children:[(0,h.jsxs)(fa,{to:`/channels/$channelId`,params:{channelId:o.id},className:`underline`,children:[`Edit `,o.name]}),s?``:` · its cast is still used`]}):null]})}function z3(){let{api:e}=V(),{document:t}=XN(),n=I(cx(e)),r=L3(),i=n.data?.find(e=>e.id===r);return t.form.language??i?.brand.language??`en`}function hge({disabled:e=!1}){let{api:t}=V(),n=XN(),r=I(cx(t)),i=L3(),a=r.data?.find(e=>e.id===i),{document:o}=n;return(0,h.jsx)(`div`,{children:(0,h.jsx)(o2,{value:o.form.language,inherited:{label:`Channel's language`,language:a?.brand.language},disabled:e,onChange:e=>{let{language:t,...r}=o.form;n.edit({...o,form:e===void 0?r:{...r,language:e}}),n.invalidateReview(!0)}})})}var B3=[{stage:`audio`,label:`Audio`},{stage:`images`,label:`Images`},{stage:`video`,label:`Video / export`}];function gge(e,t){if(e===`reviews`||e.startsWith(`reviews.`))return{section:`review`,field:e};if(e!==`checkpoints`&&!e.startsWith(`checkpoints.`))return;let n=e.slice(12),r=/^\d+$/.test(n)?t.checkpoints?.[Number(n)]:n;return{section:`review`,field:B3.some(e=>e.stage===r)?`checkpoints.${r}`:`checkpoints`}}function _ge({problem:e}){let t=XN(),{document:n,review:r}=t,{form:i}=n,a=(0,m.useId)(),o=i.checkpoints??[];return(0,h.jsxs)(`fieldset`,{"data-play-field":`checkpoints`,tabIndex:-1,"aria-invalid":e(`checkpoints`)!==void 0,disabled:r.starting||r.uncertain,className:`min-w-0 rounded-media border border-line px-3 pt-1 pb-2`,...zb,children:[(0,h.jsxs)(`legend`,{className:`flex items-center gap-1 px-1 font-semibold`,children:[`Review checkpoints`,(0,h.jsx)(U,{id:`play.checkpoints`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-6`,children:B3.map(({stage:r,label:s})=>{let c=o.includes(r),l=r===`video`?i.sources.video!==`off`&&i.sources.images!==`off`||i.sources.audio!==`off`:i.sources[r]===`generate`,u=e(`checkpoints.${r}`),d=`${a}-${r}`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:d,className:`flex min-h-10 items-center gap-3 max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:d,type:`checkbox`,"data-play-field":`checkpoints.${r}`,"aria-invalid":u!==void 0,"aria-describedby":`${d}-detail`,checked:c,disabled:!l&&!c,className:`size-4 accent-accent`,onChange:e=>{let a=e.target.checked?[...o,r]:o.filter(e=>e!==r);t.edit({...n,form:{...i,checkpoints:a}}),t.invalidateReview(!0)}}),`Before `,s]}),(0,h.jsx)(`p`,{id:`${d}-detail`,className:u||c&&!l?`pl-7 text-small text-danger`:`sr-only`,children:u??(l?`Approval required before this step and its dependents run.`:c?`This step is unavailable. Remove its checkpoint or enable the step.`:r===`video`?`Enable Video or Audio to review before export.`:`Choose Generate for ${s} to add this checkpoint.`)})]},r)})}),e(`checkpoints`)?(0,h.jsx)(`p`,{className:`text-small text-danger`,children:e(`checkpoints`)}):null]})}function V3({id:e,value:t,disabled:n,className:r,field:i,onChange:a}){let{api:o}=V(),s=I(hb(o)).data?.themes??[],c=t?.custom,l=c===void 0?void 0:s.find(e=>e.id===c.id),u=c!==void 0&&(l===void 0||l.name!==c.name||JSON.stringify(l.values)!==JSON.stringify(c.values)),d=c===void 0&&aC(t)===`dicemaster`,f=c===void 0?`builtin:${aC(t)}`:u?`kept`:`custom:${c.id}`;return(0,h.jsxs)(UB,{id:e,"data-play-field":i,className:r,disabled:n,value:f,onChange:e=>{let n=e.target.value;if(n===`kept`)return;if(n.startsWith(`builtin:`)){let e=tC.find(e=>`builtin:${e}`===n);e!==void 0&&a({theme:e});return}let r=s.find(e=>`custom:${e.id}`===n);r!==void 0&&a({theme:aC(t),custom:{id:r.id,name:r.name,values:r.values}})},children:[(0,h.jsxs)(`optgroup`,{label:`Built in`,children:[tC.map(e=>(0,h.jsx)(`option`,{value:`builtin:${e}`,children:iC[e]},e)),d?(0,h.jsx)(`option`,{value:`builtin:${nC}`,children:`${iC[nC]} (retired, this project's look)`}):null]}),s.length===0&&!u?null:(0,h.jsxs)(`optgroup`,{label:`Your themes`,children:[u?(0,h.jsx)(`option`,{value:`kept`,children:`${c.name} (this project's copy)`}):null,s.map(e=>(0,h.jsx)(`option`,{value:`custom:${e.id}`,children:u&&l?.id===e.id?`${e.name} (current version)`:e.name},e.id))]})]})}function H3({label:e,field:t,hideLabel:n=!1,value:r,options:i,className:a,tip:o,onPick:s}){let c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:z(`inline-flex items-center gap-3`,a),...o===void 0?{}:zb,children:[(0,h.jsx)(K4,{id:c,className:n?`sr-only`:`shrink-0`,children:e}),(0,h.jsx)(q4,{type:`single`,value:r,"aria-labelledby":c,onValueChange:e=>{let t=i.find(t=>t.value===e);t!==void 0&&t.disabled!==!0&&s(t.value)},children:i.map(e=>(0,h.jsx)(J4,{value:e.value,"data-play-field":e.value===r?t:void 0,disabled:e.disabled===!0,children:e.label},e.value))}),o===void 0?null:(0,h.jsx)(U,{id:o,label:e,className:`-ml-1`})]})}function U3({value:e,onPick:t,rawCounts:n}){let r=e.words??500,i=e.characters??3e3,a=e.mode===`words`||e.mode===`characters`,o=e.mode===`characters`,s=o?e.characters:e.words;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H3,{field:`chunking.mode`,label:`Chunking`,tip:`play.chunking`,className:`min-w-0 max-w-full flex-wrap [&_[data-slot=toggle-group]]:max-w-full [&_[data-slot=toggle-group]]:flex-wrap`,value:e.mode,options:[{value:`whole`,label:`Whole`},{value:`paragraph`,label:`Paragraph`},{value:`words`,label:`Every ${String(n?.words??r)} words`},{value:`characters`,label:`Every ${String(n?.characters??i)} characters`}],onPick:e=>{if(n){n.onChange(e,e===`characters`?n.characters:n.words);return}t(e===`words`?{mode:e,words:r}:e===`characters`?{mode:e,characters:i}:{mode:e})}}),a?(0,h.jsx)(XB,{label:o?`Characters`:`Words`,tip:`play.chunking.count`,problem:void 0,children:({id:r})=>(0,h.jsx)(zB,{id:r,"data-play-field":o?`chunking.characters`:`chunking.words`,type:n?`text`:`number`,min:1,max:o?1e6:1e4,inputMode:`numeric`,className:`sl-input--number`,value:n?o?n.characters:n.words:s===void 0?``:String(s),onChange:r=>{if(n){n.onChange(e.mode,r.target.value);return}let i=Number.parseInt(r.target.value,10),a=Number.isFinite(i)&&i>0;t(o?a?{mode:`characters`,characters:Math.min(i,1e6)}:{mode:`characters`}:a?{mode:`words`,words:Math.min(i,1e4)}:{mode:`words`})}})}):null]})}var W3=1;function G3({prompts:e,picked:t,problem:n,onPick:r,rawNumbers:i}){let a=(0,m.useId)(),o=t.reduce((e,t)=>e+t.number,0),s=t.filter(t=>!e.some(e=>e.name===t.name)),c=[...e.map(e=>({name:e.name,missing:!1})),...s.map(e=>({name:e.name,missing:!0}))];return c.length===0?(0,h.jsx)(`p`,{className:`sl-fields__wide basis-full text-small text-ink-3`,children:`No image prompts saved. Write one on Prompts.`}):(0,h.jsxs)(`div`,{className:`sl-fields__wide flex w-full basis-full flex-col gap-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{id:a,className:`engraved text-ink-3`,children:`Image prompts`}),(0,h.jsx)(U,{id:`play.image-prompts`,className:`-my-1`})]}),(0,h.jsx)(`ul`,{"aria-labelledby":a,className:`m-0 grid w-full list-none grid-cols-[repeat(auto-fill,minmax(min(100%,15rem),1fr))] gap-x-6 gap-y-2 p-0`,children:c.map(e=>{let a=t.findIndex(t=>t.name===e.name),o=a===-1?void 0:t[a];return(0,h.jsxs)(`li`,{children:[e.missing?(0,h.jsx)(`span`,{className:`block text-label text-danger`,children:`Missing template · untick to remove`}):null,(0,h.jsx)(vge,{name:e.name,number:o?.number,rawNumber:i?{value:i.values.find(t=>t.name===e.name)?.number??``,onChange:t=>i.onChange(e.name,t)}:void 0,problem:a===-1?void 0:n(`imagePrompts.${String(a)}.number`),onTick:n=>{r(n?[...t,{name:e.name,number:W3}]:t.filter(t=>t.name!==e.name))},onNumber:n=>{r(t.map(t=>t.name===e.name?{name:t.name,number:n}:t))}})]},e.name)})}),t.length===0?null:(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:Number.isFinite(o)?`${String(o)} of 60 images`:`Complete image counts to see the total`})]})}function vge({name:e,number:t,problem:n,onTick:r,onNumber:i,rawNumber:a}){let o=(0,m.useId)(),s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex w-full min-w-0 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:o,"data-play-field":`imagePrompts`,type:`checkbox`,checked:t!==void 0,className:`size-[14px] shrink-0 accent-accent`,onChange:e=>{r(e.target.checked)}}),(0,h.jsx)(`label`,{htmlFor:o,title:e,className:z(`min-w-0 flex-1 truncate`,t===void 0?`text-ink-3`:`text-ink`),children:e}),(0,h.jsx)(K4,{htmlFor:s,className:`sr-only`,children:`Number for ${e}`}),(0,h.jsx)(zB,{id:s,"data-play-field":`imagePrompts.${e}.number`,type:a?`text`:`number`,min:W3,max:20,inputMode:`numeric`,disabled:t===void 0,"aria-invalid":n!==void 0,"aria-describedby":n===void 0?void 0:c,className:`sl-input--number`,value:a?.value??(t===void 0||t===0?``:String(t)),onChange:e=>{if(a){a.onChange(e.target.value);return}let t=Number.parseInt(e.target.value,10);i(Number.isFinite(t)?t:0)}}),n===void 0?null:(0,h.jsx)(`span`,{id:c,className:`text-label text-danger`,children:n})]})}var yge=`text-small text-ink-2 file:mr-3 file:h-8 file:rounded-control file:border file:border-line-strong file:bg-raised file:px-3 file:text-ink`;function K3({label:e,field:t,value:n,placeholder:r,problem:i,tip:a,onChange:o}){let s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`div`,{...a===void 0?{}:zb,children:[(0,h.jsxs)(`span`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:s,children:e}),a===void 0?null:(0,h.jsx)(U,{id:a,label:e,className:`-my-1`})]}),(0,h.jsx)(BB,{id:s,"data-play-field":t,rows:6,value:n,placeholder:r,"aria-invalid":i!==void 0,"aria-describedby":i===void 0?void 0:c,onChange:e=>{o(e.target.value)}}),i===void 0?null:(0,h.jsx)(`p`,{id:c,className:`mt-1 text-label text-danger`,children:i})]})}function q3({label:e,field:t,accept:n,multiple:r=!1,disabled:i=!1,uploads:a,problem:o,numbered:s=!1,onPick:c,onRemove:l,onReattach:u}){let d=(0,m.useId)(),f=(0,m.useId)();return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(K4,{htmlFor:d,className:`mb-1`,children:e}),(0,h.jsx)(`input`,{id:d,"data-play-field":t,type:`file`,accept:n,multiple:r,disabled:i,"aria-invalid":o!==void 0,"aria-describedby":o===void 0?void 0:f,className:yge,onChange:e=>{c([...e.target.files??[]]),e.target.value=``}}),o===void 0?null:(0,h.jsx)(`p`,{id:f,className:`mt-1 text-label text-danger`,children:o}),a.length===0?null:(0,h.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,children:a.map((e,t)=>(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3`,children:[s?(0,h.jsx)(`span`,{className:`engraved w-6 text-ink-3`,children:String(t+1)}):null,(0,h.jsx)(bge,{upload:e}),e.error!==void 0&&u?(0,h.jsxs)(`label`,{className:`text-small text-ink-2`,children:[`Reattach`,(0,h.jsx)(`input`,{"aria-label":`Reattach ${e.name}`,className:`max-w-full`,type:`file`,accept:n,onChange:t=>{let n=t.target.files?.[0];t.target.value=``,n&&u(e.key,n)}})]}):null,l===void 0?null:(0,h.jsx)(B,{variant:`quiet`,className:`ml-auto`,"aria-label":`Remove ${e.name}`,onClick:()=>{l(e.key)},children:`Remove`})]},e.key))})]})}function bge({upload:e}){return(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-3 text-small [overflow-wrap:anywhere]`,children:[(0,h.jsx)(`span`,{className:e.error===void 0?`text-ink`:`text-danger`,children:e.name}),e.error===void 0?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:e.file===void 0?`Copying`:`Staged`}):(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.error})]})}var J3=`col-span-3 min-w-0 sl-fields`,Y3=`col-span-3 min-w-0`;function X3({kind:e,name:t,dim:n,titled:r=!0,children:i}){return(0,h.jsxs)(`section`,{"data-tour":`play-${e}`,className:`grid grid-cols-[24px_1fr_auto] items-center gap-x-2 gap-y-4 border-b border-line py-4 [&>div:empty]:hidden`,children:[r?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(vS,{kind:e,className:n?`text-ink-3`:`text-ink-2`}),(0,h.jsx)(`h3`,{className:z(`m-0 text-title-3`,n?`text-ink-3`:void 0),children:t})]}):(0,h.jsx)(`span`,{className:`sl-field__label col-span-2`,children:`Source`}),i]})}var xge={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`};function Z3({kind:e,form:t,update:n}){return(0,h.jsx)(H3,{field:`sources.${e}`,label:`${e} source`,hideLabel:!0,tip:xge[e],className:`max-[700px]:col-span-3 max-[700px]:justify-self-start [&_[data-slot=toggle-group]]:flex-wrap`,value:t.sources[e],options:ON(e).filter(n=>e!==`thumbnail`||n.value!==`prompt_by_llm`||t.sources.article!==`off`).map(n=>({...n,disabled:e===`video`&&n.value===`generate`&&t.sources.images===`off`})),onPick:r=>{if(e===`article`&&r===`off`){n(Sge(t));return}n({sources:{...t.sources,[e]:r,...e===`images`&&r===`off`?{video:`off`}:{}}})}})}function Q3(e,t){return e.filter(e=>e.kind===t).map(e=>({value:e.name,label:e.name}))}function Sge(e){return{sources:{...e.sources,article:`off`,research:`off`,audio:`off`,document:`off`,...e.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}},subtitles:{...e.subtitles,mode:`off`},youtubeDescription:!1,...e.shorts===void 0?{}:{shorts:{...e.shorts,enabled:!1}}}}function Cge(e){let t=this;t.compiler=n;function n(n){return nue(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}var $3=jR().use(ZL).use(Cge).freeze(),e6=`[ˈˌ]?[abdefghijklmnoprstuvwxzæðŋθɑɒɔəɚɛɜɝɡɪɹʃʊʌʒʔɫɾ][\\u0303\\u031a\\u0325\\u0329\\u032a\\u032c\\u032f\\u035c\\u0361ʰʲʷ]*[ːˑ]?`,wge=RegExp(`^(?:${e6})+(?:\\.(?:${e6})+)*$`,`u`),t6=`[ˈˌ]?[a-zæçðøħŋœɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɪɫɬɭɮɯɰɱɲɳɴɵɶɸɹɺɻɽɾʀʁʂʃʄʈʉʊʋʌʍʎʏʐʑʒʔʕʙʛʜʝʟʡʢβθχ][\\u0300-\\u036fʰʱʲʷʼˠˤ˞]*[ːˑ]?`,Tge=RegExp(`^(?:${t6})+(?:\\.(?:${t6})+)*$`,`u`);function n6(e){return e.type===`break`?`
279
- `:e.value??e.children?.map(n6).join(``)??``}function r6(e){if(e.type===`heading`){let t=n6(e).trim();return/^pronunciation glossary:?\s*$/iu.test(t)?[]:[t]}return e.type===`table`?(e.children??[]).slice(1).map(e=>{let t=e.children??[];if(t.length<2)return n6(e);let[n,r]=t.slice(0,2).map(e=>n6(e).trim());return`${n}: ${r!==void 0&&r!==``&&!r.includes(`/`)?`/${r}/`:r}`}):e.type===`paragraph`?n6(e).split(/\r?\n/u):e.type===`root`||e.type===`list`||e.type===`listItem`?(e.children??[]).flatMap(r6):[`(unsupported glossary block)`]}function Ege(e){return Array.from(e,e=>{let t=e.toLowerCase(),n=t.toUpperCase().toLowerCase();if(n===e)return e;let r=RegExp(`^${e.replace(/[|\\{}()[\]^$+*?.]/gu,`\\$&`)}$`,`iu`);return r.test(n)?n:r.test(t)?t:e}).join(``)}function i6(e,t){let n=t===void 0||t===`en`,r=n?wge:Tge,i=n?`standard-English IPA`:`IPA`,a=r6($3().use(Bz).parse(e)),o=new Map,s=[];for(let[e,t]of a.entries()){let a=t=>{s.push({row:e+1,reason:t})},c=t.trim();if(c===``||/^pronunciation glossary:?\s*$/iu.test(c))continue;let l=/^([^:]+):\s*(.+)$/u.exec(c),u=l?.[1]?.trim().replace(/\s+/gu,` `),d=l?.[2];if(u===void 0||d===void 0||!/[\p{L}\p{N}]/u.test(u)||/[/[\]<>\p{Cc}]/u.test(u)){a(`use Term: /IPA/ or a Term | IPA table`);continue}let f=/^(\/[^/]+\/(?:\s+\/[^/]+\/)*)(?:\s+[^/]+)?$/u.exec(d);if(f?.[1]===void 0){a(`use slash-delimited ${i}`);continue}let p=Array.from(f[1].matchAll(/\/([^/]+)\//gu)).flatMap(e=>(e[1]??``).trim().split(/\s+/u));if(p.length===0||p.some(e=>!r.test(e))){a(n?`use standard-English IPA only, not ARPAbet, delivery tags or non-English sounds; give a foreign name an English approximation`:`use IPA, not ARPAbet or delivery tags`);continue}if(u.split(` `).length!==p.length){a(`supply one IPA word for each written word`);continue}let m=Ege(u),h=o.get(m);if(h!==void 0&&h.ipa.join(` `)!==p.join(` `)){a(`an earlier entry already gives this term a different pronunciation`);continue}h===void 0&&o.set(m,{term:u,ipa:p})}return s.length===0?{ok:!0,entries:[...o.values()]}:{ok:!0,entries:[...o.values()],skipped:s}}function Dge(e,t){return e.flatMap(e=>{if(!e.pronunciations?.trim())return[];let n=i6(e.pronunciations,t),r=n.ok?n.skipped??[]:[];return r.length===0?[]:[{speaker:e.name.trim()||`A speaker`,skipped:r}]})}function Oge(e,t){let n=t?.turns.find(t=>t.speaker===e.id)?.text??kge(e);if(n.length<=200)return n;let r=n.slice(0,200),i=Math.max(r.lastIndexOf(`. `),r.lastIndexOf(`? `),r.lastIndexOf(`! `));return i>60?r.slice(0,i+1):`${r.slice(0,r.lastIndexOf(` `))}…`}function kge(e){let t=e.name.trim()||`your speaker`;switch(e.role){case`narrator`:return`The night was quiet, and the old house held its breath. I'm ${t}, and I'll be telling this story.`;case`host`:return`Hi everyone, I'm ${t}, and welcome back to the show. Today's topic is a good one.`;case`guest`:return`Thanks for having me. I'm ${t}, and I've been looking forward to this conversation.`;case`character`:return`You really thought I wouldn't find out? My name is ${t}, and I always find out.`}}function Age(e){return e.flatMap(e=>e.host===!0&&e.voice!==void 0?[a6(e,`host`)]:[])}function jge(e){let t=e.toLowerCase();return/^[a-z0-9-]{1,55}$/.test(t)?`cast-${t}`:`cast-h${Mge(e)}`}function Mge(e){let t=3735928559,n=1103547991;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,2654435761),n=Math.imul(n^i,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(4294967296*(2097151&n)+(t>>>0)).toString(36)}function a6(e,t){let n=e.voice;return{id:jge(e.id),name:e.name.slice(0,40),role:t,voice:n===void 0?{provider:``,model:``,voice:``}:{provider:n.provider,model:n.model,voice:n.voice},...n?.pace===void 0||n.pace===1?{}:{pace:n.pace},...n?.pronunciations?.trim()?{pronunciations:n.pronunciations}:{},castId:e.id,...Nge(e)}}function Nge(e){let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null)?.sha256;return t==null?{}:{portrait:t}}var Pge=/^#{1,6}\s+(.+?)\s*#*\s*$/,Fge=/^\*{0,2}([^:*\n]{1,60}?)\*{0,2}\s*:\s*\*{0,2}\s*(.*)$/;function o6(e,t,n=!1){let r=new Map(t.map(e=>[e.name.trim().toLowerCase(),e])),i=t.map(e=>e.name.trim()).join(`, `),a=[],o=[],s=!1;for(let[t,n]of e.replace(/\r\n?/g,`
277
+ `).length,a=t-r;return`line ${String(i)}, column ${String(a)}`}function Z4(e,t){return[...`kind`in e?whe(e):The(e),...t]}function Q4(e){return e[0]?.message}function $4(e){return e.filter(e=>e.field===`body`)}function e3(e){return e.filter(e=>e.field===`name`)}function t3(e){return MK(e).names}function Ohe(e){let t=[],n=0;for(let r of MK(e).errors){if(r.at<n)continue;r.at>n&&t.push({start:n,text:e.slice(n,r.at),marked:!1});let i=Math.min(r.at+2,e.length);t.push({start:r.at,text:e.slice(r.at,i),marked:!0}),n=i}return n<e.length&&t.push({start:n,text:e.slice(n),marked:!1}),t}var n3=`px-3 py-3 font-sans text-body leading-[1.5] break-words [scrollbar-gutter:stable]`;function r3({id:e,value:t,invalid:n,describedBy:r,onChange:i}){let a=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:`relative max-w-[75ch]`,children:[(0,h.jsxs)(`div`,{ref:a,"aria-hidden":`true`,"data-slot":`lint-overlay`,className:z(n3,`pointer-events-none absolute inset-0 overflow-hidden whitespace-pre-wrap`,`rounded-control border border-transparent bg-sunken text-ink`),children:[Ohe(t).map(e=>(0,h.jsx)(`span`,{"data-lint-mark":e.marked?e.start:void 0,className:e.marked?`text-danger underline decoration-danger decoration-2 underline-offset-[3px]`:void 0,children:e.text},e.start)),`
278
+ `]}),(0,h.jsx)(BB,{id:e,rows:24,value:t,spellCheck:!1,"aria-invalid":n,"aria-describedby":r,className:z(n3,`relative block min-h-[520px] resize-y border-line-strong overflow-auto bg-transparent text-transparent caret-ink`),onChange:e=>{i(e.target.value)},onScroll:e=>{let t=a.current;t!==null&&(t.scrollTop=e.currentTarget.scrollTop,t.scrollLeft=e.currentTarget.scrollLeft)}})]})}function i3({entryId:e,category:t,from:n,onLeave:r}){let{api:i}=V(),a=_(),o=I(mb(i)),s=(0,m.useId)(),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),S=o.data?.entries,C=e??n,w=C===void 0?void 0:S?.find(e=>e.id===C),T=w===void 0?{category:t,mode:`text`,name:``,body:``}:{category:w.category,mode:w.mode,name:e===void 0?`${w.name} copy`:w.name,body:w.body},E=d??T,D=L({mutationFn:t=>Ks(i,t,e),onSuccess:async e=>{if(!e.ok){g(e.fields);return}y(!0),await a.invalidateQueries({queryKey:mb(i).queryKey})}}),O=L({mutationFn:e=>ec(i,e),onSuccess:async()=>{x(!1),await a.invalidateQueries({queryKey:mb(i).queryKey}),r(E.category)}});K2(v,()=>{r(E.category)});let k=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},A=Z4(E,p),j=Q4(A),M=t3(E.body),ee=E.body.trim()===``?[]:$4(A),N=E.name.trim()===``?[]:e3(A);return o.error===null?C!==void 0&&S===void 0?(0,h.jsx)(Y2,{}):C!==void 0&&w===void 0?(0,h.jsx)(a3,{category:t,children:`That entry is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/entries`,search:{category:E.category},children:`Intros & Outros`})}),title:e===void 0?`New entry`:`Edit entry`,meta:DB(E.category)}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{className:`min-w-[200px] flex-1`,children:(0,h.jsx)(LB,{label:`Name`,tip:`library.entry.name`,...N.length===0?{}:{error:N.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:E.name,onChange:e=>{k({...E,name:e.target.value},`name`)}})})}),(0,h.jsx)(Y4,{label:`Category`,value:E.category,options:TB,tip:`library.entry.category`,onPick:e=>{k({...E,category:e},`name`)}}),(0,h.jsx)(Y4,{label:`Mode`,value:E.mode,options:EB,describedBy:s,tip:`library.entry.mode`,onPick:e=>{k({...E,mode:e},`mode`)}})]}),(0,h.jsx)(`p`,{id:s,className:`-mt-2 text-right text-small text-ink-2`,children:kB(E.mode)}),(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(U,{id:`library.entry.body`,label:`Body`,className:`-my-1`})]}),(0,h.jsx)(r3,{id:c,value:E.body,invalid:ee.length>0,describedBy:ee.length===0?void 0:l,onChange:e=>{k({...E,body:e},`body`)}})]}),(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{x(!0)},blocked:j,blockedId:u,pending:D.isPending,saved:v,cancel:(0,h.jsx)(CS,{to:`/entries`,search:{category:E.category},variant:`secondary`,children:`Cancel`}),errors:[D.error,O.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{D.mutate(E)}})]}),(0,h.jsx)(`div`,{className:u4,children:(0,h.jsx)(G4,{slots:M,body:E.body,lint:ee,lintId:l,noSlots:AB(E.mode)})})]}),(0,h.jsx)(Hy,{open:b,title:`Delete "${E.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${E.category}`,pending:O.isPending,onConfirm:()=>{e!==void 0&&O.mutate(e)},onCancel:()=>{x(!1)}})]}):(0,h.jsx)(a3,{category:E.category,children:o.error.message})}function a3({category:e,children:t}){return(0,h.jsx)(f4,{back:(0,h.jsx)(fa,{to:`/entries`,search:{category:e},children:`Back to Intros & Outros`}),children:t})}var khe=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),Ahe=new Intl.DateTimeFormat(void 0,{timeStyle:`short`});function jhe({runs:e}){return(0,h.jsx)(PH,{label:`Coming up`,children:e.map(e=>(0,h.jsx)(FH,{title:`${khe.format(new Date(e.at))} · ${Ahe.format(new Date(e.at))} · ${jH(e)}`,meta:[e.scheduleName,e.templateName].filter(e=>e!==null).join(` · `),actions:e.paused?(0,h.jsx)(kS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(kS,{tone:`info`,children:`Needs a topic`}):(0,h.jsx)(kS,{children:`Queued`})},`${e.scheduleId}-${e.at}`))})}var o3=Y({revisionId:K(),checkpoints:J(Wj.unwrap().extend({currentFingerprint:K().regex(/^[a-f0-9]{64}$/),dependents:J(X(KS)),workKeys:J(K())}))}),Mhe=Y({revisionId:K().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),stages:J(Uj).max(3).refine(e=>new Set(e).size===e.length).readonly()}).strict(),Nhe=Y({title:K(),status:q(),detail:K().optional(),reason:X([`duplicate`,`not-found`,`conflict`,`invalid-input`]).optional()}),Phe=Gj.unwrap().omit({projectId:!0,checkpointId:!0,approvedAt:!0}),s3=e=>[`checkpoints`,e],c3=(e,t)=>[...s3(e),t];async function l3(e,t){let n;try{n=await e.json()}catch{throw lo(e,void 0)}if(e.ok)return{ok:!0,value:yo(t,n)};let r=Nhe.safeParse(n);if(!r.success)throw lo(e,void 0);if(![400,404,409].includes(e.status))throw Error(r.data.detail??r.data.title);return{ok:!1,reason:r.data.reason??`invalid-input`,message:r.data.detail??r.data.title}}async function u3(e,t){return l3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`),o3)}async function d3(e,t,n,r){return l3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints/${encodeURIComponent(n)}/approve`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(Phe.parse(r))}),Y({checkpoint:Wj,replayed:RD()}))}async function Fhe(e,t,n){return l3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(Mhe.parse(n))}),o3)}var f3=(0,m.createContext)(void 0);function p3(e,t){if(e.state===`failed`)return s1({stage:e.kind,kind:e.failureKind,reason:e.failureReason,provider:cfe(t.config,e.kind)})}var Ihe=[`home`,`week`];function Lhe(e=new Date){let t=new Date(e);t.setHours(0,0,0,0);let n=(t.getDay()+6)%7;return t.setDate(t.getDate()-n),t}function Rhe(e,t,n){return at({queryKey:[...Ihe,t,n],queryFn:async()=>{let r=new URLSearchParams({since:t});return n!==null&&r.set(`channelId`,n),R(await e.fetch(`${e.origin}/api/home/week?${r.toString()}`))},staleTime:3e4})}async function zhe(e,t,n){return R(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/set-aside`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({setAside:n})}))}async function m3(e,t,n){return R(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/uploaded`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({uploaded:n})}))}function h3({projectId:e,className:t}){let{api:n}=V(),[r,i]=(0,m.useState)(!1);return(0,h.jsx)(`div`,{className:z(`sl-media__frame`,t),"aria-hidden":`true`,children:r?(0,h.jsx)(`div`,{className:`flex size-full items-center justify-center bg-sunken text-ink-3`,children:(0,h.jsx)(Nc,{strokeWidth:1.75,className:`size-6`})}):(0,h.jsx)(`img`,{src:Wo(n,e,`thumbnail`),alt:``,loading:`lazy`,decoding:`async`,onError:()=>i(!0)})})}function g3(e){return e.status===`pending`&&e.progress>0&&e.setAside!==!0}function _3({lead:e,status:t,title:n,detail:r,action:i}){return(0,h.jsxs)(`li`,{className:z(`sl-home-item`,MH),children:[e,(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[t,(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:n}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:r})]}),(0,h.jsx)(Iy,{className:`sl-home-item__action`,children:i})]})}function v3(e){return(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}var Bhe={audio:`Approve the article and record`,images:`Approve and draw the images`,video:`Approve and render`},Vhe={audio:`review before the narration`,images:`review before the images`,video:`review before the video`};function Hhe({project:e,primary:t}){let{api:n}=V(),r=_(),i=Ry(),a=Ji(),o=(0,m.useRef)(null),s=I({queryKey:s3(e.id),queryFn:async()=>{let t=await u3(n,e.id);if(!t.ok)throw Error(t.message);return t.value}}).data?.checkpoints.find(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint),c=L({mutationFn:async t=>{o.current??={revisionId:t.revisionId,fingerprint:t.fingerprint,idempotencyKey:crypto.randomUUID()};let r=await d3(n,e.id,t.checkpointId,o.current);return o.current=null,r},onSuccess:t=>{i(t.ok?`Approved: ${e.title}. The run continues.`:`${e.title} wasn't approved: ${t.message} Open the project to review it there.`,t.ok?`success`:`error`)},onError:t=>{i(`Slopify didn't confirm the approval of ${e.title}: ${t.message} Press the button again to check whether it went through.`,`error`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:s3(e.id)}),r.invalidateQueries({queryKey:H.projects})])}}),l=L({mutationFn:t=>zhe(n,e.id,t),onSuccess:(t,n)=>{i(n?`Kept as is: ${e.title}. It is off Needs you; editing the project brings it back.`:`${e.title} is back on Needs you.`,`success`,n?{label:`Undo`,run:()=>l.mutate(!1)}:void 0)},onError:t=>{i(`${e.title} wasn't kept as is: ${t.message} Press Keep as is again.`,`error`)},onSettled:()=>r.invalidateQueries({queryKey:H.projects})}),u=s===void 0?void 0:Bhe[s.stage];return jx({id:`home.approve.${e.id}`,title:u??`Open the held run`,group:`Needs you`,context:e.title,keywords:[`approve`,`review`,`waiting`],run:()=>{s===void 0?a({to:`/projects/$projectId`,params:{projectId:e.id}}):c.mutate(s)}}),(0,h.jsx)(_3,{lead:(0,h.jsx)(h3,{projectId:e.id}),status:(0,h.jsx)(OS,{tone:`waiting`,children:s===void 0?`Waiting for you`:`Waiting for you · ${Vhe[s.stage]}`}),title:v3(e),detail:s===void 0?`Its next step is held. Open the project to review it and continue the run.`:`Everything before this step is done. Approve to let the run go on, or open the project to look first.`,action:s===void 0||u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`}),(0,h.jsx)(B,{variant:`quiet`,disabled:l.isPending,disabledReason:`Saving…`,onClick:()=>l.mutate(!0),children:`Keep as is`})]}):(0,h.jsx)(B,{variant:t?`primary`:`secondary`,disabled:c.isPending,disabledReason:`Approving…`,onClick:()=>c.mutate(s),children:c.isPending?`Approving…`:u})})}function Uhe({schedule:e,primary:t}){let n=e.topics.held;return(0,h.jsx)(_3,{lead:(0,h.jsx)(`div`,{className:`sl-media__frame flex items-center justify-center bg-sunken text-info`,children:(0,h.jsx)(Lc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-7`})}),status:(0,h.jsx)(OS,{tone:`info`,children:`${String(n)} new ${n===1?`topic`:`topics`}`}),title:e.name,detail:`Slopify suggested ${n===1?`a topic`:`${String(n)} topics`} for this schedule. Queue the ones you want and reject the rest.`,action:(0,h.jsx)(CS,{to:`/calendar`,variant:t?`primary`:`secondary`,className:NH,children:`Review topics`})})}function Whe({project:e,primary:t}){return(0,h.jsx)(_3,{lead:(0,h.jsx)(h3,{projectId:e.id}),status:(0,h.jsx)(OS,{tone:`waiting`,children:`Paused`}),title:v3(e),detail:`You paused this run. Nothing more happens until you open it and press Continue the run.`,action:(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`})})}function Ghe({project:e,primary:t}){let{api:n}=V(),r=I({queryKey:H.project(e.id),queryFn:()=>Oo(n,e.id)}),i=r.data?.stages.find(e=>e.state===`failed`),a=Ry(),o=async e=>{let t=await p1(e);a(t?`Copied ${e}. Run it in a terminal on the computer running Slopify and sign in, then open the project and press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e} in a terminal, sign in, then open the project and press Check again.`,t?`success`:`error`)},s=i===void 0||r.data===void 0?void 0:p3(i,r.data.project),c=NP(i?.failureReason)??`The run stopped with an error.`,l=i===void 0?``:` · ${YP[i.kind]}`,u=t?`primary`:`secondary`,d=s?.kind===`provider-settings`?(0,h.jsx)(CS,{to:`/settings`,search:{section:`providers`},variant:u,children:s.label}):s?.kind===`free-space`?(0,h.jsx)(CS,{to:`/settings`,search:{section:`storage`},variant:u,children:s.label}):s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:u,onClick:()=>void o(s.command),children:`Copy sign-in command`}),(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},children:`Open to retry`})]}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:u,children:s?.label??`Open to retry`});return(0,h.jsx)(_3,{lead:(0,h.jsx)(h3,{projectId:e.id}),status:(0,h.jsx)(OS,{tone:`failed`,children:`Failed${l}`}),title:v3(e),detail:s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[c,` Run `,(0,h.jsx)(`code`,{className:`sl-code`,children:s.command}),` in a terminal to sign in, then press Check again on the project to retry the step.`]}):c,action:d})}function y3(e){return(e.status===`done`||e.status===`partial`||e.status===`pending`&&e.setAside===!0)&&e.config.sources.video!==`off`&&e.uploadedAt===null}function Khe({project:e}){let{api:t}=V(),n=_(),r=Ry(),i=L({mutationFn:n=>m3(t,e.id,n),onSuccess:(t,n)=>{r(n?`Marked uploaded: ${e.title}. It is off Ready to upload; Projects still lists it.`:`${e.title} is back on Ready to upload.`,`success`)},onError:t=>{r(`${e.title} wasn't marked uploaded: ${t.message} Press Mark uploaded again.`,`error`)},onSettled:async()=>{await n.invalidateQueries({queryKey:H.projects})}});return jx({id:`home.uploaded.${e.id}`,title:`Mark uploaded`,group:`Ready to upload`,context:e.title,keywords:[`youtube`,`published`,`done`],run:()=>i.mutate(!0)}),(0,h.jsxs)(`li`,{className:`sl-home-ready ${MH}`,children:[(0,h.jsx)(h3,{projectId:e.id}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title`,children:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:`${e.format} · finished ${Wu(e.updatedAt)}${e.status===`partial`?` · a step failed`:``}`}),(0,h.jsxs)(Iy,{children:[(0,h.jsx)(B0,{projectId:e.id,ready:!0,size:`small`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:i.isPending,disabledReason:`Saving…`,onClick:()=>i.mutate(!0),children:`Mark uploaded`})]})]})]})}function b3(e){return e.status===`pending`&&e.progress===0}var qhe=2;function Jhe({running:e,queued:t}){let n=e>3;if(!n&&t.length===0)return null;let r=t.slice(0,qhe).map(e=>e.title.trim()||`Untitled project`),i=t.length-r.length;return(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n?(0,h.jsx)(`div`,{children:(0,h.jsx)(wS,{to:`/projects`,search:{show:`running`},children:`See all ${String(e)} running`})}):null,t.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-ink`,children:`Queued, waiting to start (${String(t.length)}): `}),r.join(`, `),i>0?` and ${String(i)} more`:``]}),(0,h.jsx)(wS,{to:`/projects`,search:{show:`queued`},children:`See queued`})]})]})}function x3(e,t){if(e.state!==`running`)return;let n=e.startedAt===null?NaN:Date.parse(e.startedAt),r=Number.isFinite(n)?Math.max(0,(t-n)/1e3):void 0,i=e.progressCurrent??0,a=e.progressTotal??0;if(r!==void 0&&a>0&&i>0)return i>=a?{basis:`progress`,seconds:0}:{basis:`progress`,seconds:Math.round(r/i*(a-i))};let o=e.typicalSeconds;if(o===void 0||!Number.isFinite(o)||o<=0)return{basis:`unknown`};let s=o-(r??0);return s>0?{basis:`history`,seconds:Math.round(s)}:{basis:`overdue`}}function S3(e){if(e.basis===`unknown`)return`time left unknown`;if(e.basis===`overdue`)return`taking longer than usual`;let t=e.seconds??0;if(t<=0)return`finishing up`;if(t<60)return`under a minute left`;let n=Math.round(t/60);if(n<60)return`about ${String(n)} min left`;let r=Math.floor(n/60),i=n%60;return i===0?`about ${String(r)} h left`:`about ${String(r)} h ${String(i)} min left`}function C3(e){let t=e.role.replaceAll(`_`,`-`);return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment!==void 0?`${t}-${e.meta.segment}`:e.role===`short_video`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}`:e.role===`short_image`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}-${String(e.meta.index??1)}`:e.role===`thumbnail`&&e.meta.index!==void 0&&e.meta.index>1?`${t}-${String(e.meta.index)}`:e.role===`instructions`?`${e.stageKind}-${t}`:(e.role===`image`||e.role===`animated_image`)&&e.meta.index!==void 0?`${t}-${String(e.meta.index)}`:t}function w3({steps:e,label:t,dense:n=!1,className:r}){return(0,h.jsx)(`ol`,{"aria-label":t,className:z(`sl-steps m-0 list-none p-0`,n&&`sl-steps--dense`,r),children:e.map(e=>(0,h.jsxs)(`li`,{className:`sl-step`,"data-tone":e.tone,children:[(0,h.jsx)(DS,{tone:e.tone}),(0,h.jsxs)(`span`,{className:`sl-step__name`,children:[e.name,(0,h.jsx)(`span`,{className:`sr-only`,children:`, ${e.state}`})]}),(0,h.jsx)(`span`,{className:`sl-step__time`,children:e.time??`—`}),e.detail===void 0?null:(0,h.jsx)(`span`,{className:`sl-step__detail`,children:e.detail})]},e.id))})}function T3(e){let{api:t}=V();return I({...sb(t,e),enabled:!1,select:e=>e.revisionId??null}).data??null}var E3=(e,t=null)=>[`live-writing`,e,t];function Yhe(e,t){let n=e=>e.callId===t.callId&&e.revisionId===t.revisionId&&e.workId===t.workId,r=e.find(n),i=(t.reset?t.text:`${r?.text??``}${t.text}`).slice(-65536),a={...t.revisionId===void 0?{}:{revisionId:t.revisionId},...t.workId===void 0?{}:{workId:t.workId},...t.workPieceId===void 0?{}:{workPieceId:t.workPieceId},stage:t.stage,callId:t.callId,...t.label===void 0?{}:{label:t.label},text:i};return(r?e.map(e=>n(e)?a:e):[...e,a]).slice(-24)}function D3({projectId:e,stage:t,className:n=`mx-5 mt-5`}){let r=(I({queryKey:E3(e,T3(e)),queryFn:()=>[],enabled:!1}).data??[]).filter(e=>e.stage===t),[i,a]=(0,m.useState)(),o=r.find(e=>e.callId===i)??r.at(-1),[s,c]=(0,m.useState)(!0),l=(0,m.useRef)(null);return(0,m.useEffect)(()=>{o?.text&&s&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},[s,o?.text]),r.length===0&&t!==`research`&&t!==`article`?null:(0,h.jsxs)(`div`,{className:z(`border-y border-line`,n),children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-line py-3`,...zb,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-accent-ink`,children:`Live writing`}),(0,h.jsx)(U,{id:`project.live.writing`})]}),r.length>1?(0,h.jsx)(VB,{"aria-label":`Live writing task`,value:o?.callId??``,onChange:e=>a(e.target.value),className:`max-w-[280px]`,children:r.map((e,t)=>(0,h.jsxs)(`option`,{value:e.callId,children:[e.label??`Writing`,` · `,t+1]},e.callId))}):null,(0,h.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Follow output`]})]}),(0,h.jsx)(`section`,{ref:l,"aria-label":`Live writing preview`,tabIndex:0,className:`max-h-[360px] min-h-32 overflow-auto whitespace-pre-wrap break-words py-4 font-sans text-small leading-relaxed text-ink-2`,children:o?.text||`Waiting for the provider's first text…`}),(0,h.jsx)(`p`,{className:`border-t border-line py-2 text-label text-ink-3`,children:`Live preview. The complete output is saved when this stage finishes.`})]})}var Xhe=Y({id:K(),projectId:K(),revisionId:K(),itemKey:K(),stage:X(gk),itemFingerprint:K(),reviewFingerprint:K(),passed:RD(),reasons:J(K()),outcome:X([`passed`,`flagged`,`redo`]),attempt:q(),action:X([`overruled`,`redone`]).nullable(),actionAt:K().nullable(),redoState:X([`pending`,`started`,`failed`]).nullable(),redoError:K().nullable(),createdAt:K(),current:RD(),outputId:K().nullable(),verdicts:q()}),O3=e=>[`reviews`,e],Zhe=Y({title:K(),detail:K().optional()});async function Qhe(e,t){let n=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews`);if(!n.ok)throw lo(n,void 0);return yo(Y({reviews:J(Xhe)}),await n.json()).reviews}async function $he(e,t,n,r,i){let a=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews/${encodeURIComponent(n)}/${r}`,{method:`POST`,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}});if(a.ok)return{ok:!0};let o;try{o=await a.json()}catch{throw lo(a,void 0)}let s=Zhe.safeParse(o);if(!s.success||![400,404,409,503].includes(a.status))throw lo(a,void 0);return{ok:!1,message:s.data.detail??s.data.title}}var ege=200;function k3(e,t=null){let{api:n,openEvents:r}=V(),i=_();(0,m.useEffect)(()=>{i.setQueryData(H.article(e,t),``),i.setQueryData(E3(e,t),[]);let a=()=>i.getQueryData(H.project(e))?.revisionId??null,o=Kz(()=>{i.invalidateQueries({queryKey:H.project(e)}),i.invalidateQueries({queryKey:H.projects}),i.invalidateQueries({queryKey:s3(e)}),i.invalidateQueries({queryKey:O3(e)})},ege),s=VS(r,tc(n,`projects/${e}`),{refetch:o.ask,accept:e=>e.type===`project.updated`||e.type===`project.state`&&e.revisionId===void 0||(e.revisionId??null)===a()||(o.ask(),!1),previewWriting:t=>{i.setQueryData(E3(e,a()),e=>Yhe(e??[],t))},narrationPiece:()=>{i.invalidateQueries({queryKey:Gy(e,a())})},appendArticle:t=>{i.setQueryData(H.article(e,a()),e=>`${e??``}${t}`)},patch:t=>{if(t.type===`stage.state`&&t.state===`running`&&(i.setQueryData(E3(e,a()),e=>(e??[]).filter(e=>e.stage!==t.stage||e.workId!==t.workId||e.revisionId!==t.revisionId)),t.stage===`article`&&i.setQueryData(H.article(e,a()),``)),t.type!==`project.state`&&t.workId!==void 0){o.ask();return}i.setQueryData(H.project(e),e=>lde(e,t))}});return()=>{s(),o.stop()}},[n,r,i,e,t])}var tge={pending:`off`,running:`running`,done:`done`,provided:`done`,failed:`failed`,canceled:`off`,skipped:`off`},nge={pending:`Not started`,running:`Running`,done:`Done`,provided:`Provided`,failed:`Failed`,canceled:`Canceled`,skipped:`Skipped`};function rge(e,t,n){if(e===null)return;let r=(t===null?n:Date.parse(t))-Date.parse(e);if(!Number.isFinite(r)||r<0)return;let i=Math.round(r/1e3);if(i<60)return`${String(i)} s`;let a=Math.round(i/60);if(a<60)return`${String(a)} min`;let o=Math.floor(a/60);return`${String(o)} h ${String(a%60)} min`}function ige(e,t){let n=x3(e,t);if(n===void 0)return;let r=nF(e);return r===void 0?`${e.progressTotal!==null&&e.progressTotal>0?`${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)} · `:``}${S3(n)}`:n.basis===`unknown`?rF(r):`${rF(r)} · ${S3(n)}`}function age({project:e,now:t}){let{api:n}=V();k3(e.id);let[r,i]=(0,m.useState)(null),a=I(sb(n,e.id)),o=(a.data?.stages??[]).filter(e=>e.source!==`off`&&e.state!==`skipped`),s=(a.data?.outputs??[]).filter(e=>e.role===`image`).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),c=o.find(e=>e.kind===`images`&&e.state===`running`),l=o.find(e=>e.state===`running`),u=gH(e.limitWaits),d=s.slice(c===void 0?-4:-3),f=o.map(n=>({id:n.kind,name:ZP(n.kind,e.config),tone:tge[n.state],state:nge[n.state],time:rge(n.startedAt,n.finishedAt,t),detail:ige(n,t)}));return(0,h.jsxs)(`li`,{className:`sl-home-run ${MH}`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),e.status===`paused`?(0,h.jsx)(OS,{tone:`waiting`,children:`Paused`}):u===void 0?(0,h.jsx)(OS,{tone:`running`,children:l===void 0?`Running`:`${ZP(l.kind,e.config)}`}):(0,h.jsx)(OS,{tone:`waiting`,children:u})]}),d.length===0&&c===void 0?null:(0,h.jsxs)(u0,{list:!0,density:`compact`,label:`Images of ${e.title}`,children:[d.map((t,r)=>(0,h.jsx)(`li`,{children:(0,h.jsx)(l0,{src:Wo(n,e.id,C3(t)),alt:`Image ${String(t.meta.index??``)}`,onOpen:()=>i(r)})},t.id)),c===void 0?null:(0,h.jsx)(`li`,{children:(0,h.jsx)(l0,{alt:`The next image`,generating:`Drawing · ${String(s.length)} so far`})})]}),(0,h.jsx)(d0,{items:d.map(t=>({src:Wo(n,e.id,C3(t)),alt:`Image ${String(t.meta.index??``)}`,...t.meta.prompt===void 0?{}:{caption:t.meta.prompt}})),index:r,onIndex:i,onClose:()=>i(null)}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Images ${String(c.progressCurrent??s.length)} of ${String(c.progressTotal??`?`)}`})]}),(0,h.jsx)(w3,{steps:f,label:`Steps of ${e.title}`})]})}var A3=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2});function oge(e){return`spent${e.apiEquivalent===null?``:` · ~${A3.format(e.apiEquivalent)} via API`}${e.unpriced===0?``:` · ${String(e.unpriced)} ${e.unpriced===1?`call`:`calls`} without a price`}`}function sge({channelId:e}){let{api:t}=V(),n=I(Rhe(t,Lhe().toISOString(),e));if(n.error!==null)return(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`This week's numbers didn't load: ${n.error.message} Reload the page to try again.`});let r=n.data;return(0,h.jsxs)(x2,{className:`sl-home-stats`,children:[(0,h.jsx)(S2,{value:r===void 0?`—`:String(r.videos),label:`videos made`}),(0,h.jsx)(S2,{value:r===void 0?`—`:A3.format(r.cost),label:r===void 0?`spent`:oge(r)}),(r?.plans??[]).filter(e=>e.weeklyPercent!==null).map(e=>{let t=Math.round(e.weeklyPercent??0);return(0,h.jsx)(S2,{value:`${String(t)}%`,label:`weekly ${e.name} limit`,children:(0,h.jsx)(C2,{value:t/100,label:`Weekly ${e.name} limit`,valueText:`${String(t)}% of your weekly ${e.name} limit`,tone:t>=80?`waiting`:`accent`})},e.account)})]})}var cge=864e5,lge=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`}),j3=4,M3=!1,N3=!1;function uge(){let{api:e}=V(),t=Dx(),n=I(ob(e)),r=I(qV(e)),i=I(lq(e)),[a]=(0,m.useState)(()=>{let e=new Date;return e.setHours(0,0,0,0),{from:new Date().toISOString(),to:new Date(e.valueOf()+8*cge).toISOString()}}),o=I(pH(e,a.from,a.to)),s=I({queryKey:Uy,queryFn:()=>qy(e)}),c=Ji();(0,m.useEffect)(()=>{s.data?.show===!0&&!M3&&(M3=!0,c({to:`/welcome`}))},[s.data?.show,c]),(0,m.useEffect)(()=>{s.data?.settle===!0&&!N3&&(N3=!0,Jy(e).catch(()=>{N3=!1}))},[s.data?.settle,e]);let[l,u]=(0,m.useState)(()=>Date.now());(0,m.useEffect)(()=>{let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[]);let d=(0,m.useMemo)(()=>new Map((i.data??[]).map(e=>[e.id,e.channelId])),[i.data]),f=(n.data?.projects??[]).filter(e=>t.includes(e.channelId)),p=f.filter(e=>e.status===`running`),g=f.filter(b3),_=f.filter(e=>e.status===`paused`),v=f.filter(g3),y=f.filter(e=>e.status===`failed`),b=new Set(Object.values(s.data?.samples??{}).filter(e=>e!==null)),x=f.filter(e=>y3(e)&&!b.has(e.id)),S=(r.data??[]).filter(e=>e.deletedAt===null&&e.topicGeneration.mode===`hold`&&e.topics.held>0&&t.includes(d.get(e.templateId))),C=(o.data?.runs??[]).filter(e=>t.includes(d.get(e.templateId))),w=[...v.map(e=>({kind:`waiting`,project:e})),..._.map(e=>({kind:`paused`,project:e})),...S.map(e=>({kind:`held`,schedule:e})),...y.slice(0,j3).map(e=>({kind:`failed`,project:e}))],T=n.isPending;return(0,h.jsxs)(`div`,{"data-tour":`home`,children:[(0,h.jsx)(XK,{display:!0,crumb:lge.format(new Date),title:t.channel?.name??`Home`,meta:t.channelId===null?`Every channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(CS,{to:`/play`,variant:`secondary`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]}),(0,h.jsxs)(CS,{to:`/calendar`,variant:`quiet`,children:[(0,h.jsx)(bc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open calendar`]})]})}),(0,h.jsxs)(`div`,{className:`mb-5 flex items-end gap-1 md:hidden`,...zb,children:[(0,h.jsx)(Ox,{className:`min-w-0 flex-1`}),(0,h.jsx)(U,{id:`home.channel`,className:`mb-1`})]}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-5 text-danger`,children:`Your projects didn't load: ${n.error.message} Check that Slopify is still running, then reload the page.`}),(0,h.jsxs)(b1,{split:`main-side`,children:[(0,h.jsxs)(x1,{children:[(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(W,{title:`Needs you`,info:`home.needs-you`,meta:T?`Loading…`:w.length===0?`Nothing is waiting for a decision`:`${String(w.length)} ${w.length===1?`thing is`:`things are`} waiting for you`}),w.length===0?null:(0,h.jsx)(`ul`,{"aria-label":`Waiting for you`,className:`m-0 flex list-none flex-col gap-3 p-0`,children:w.map((e,t)=>e.kind===`waiting`?(0,h.jsx)(Hhe,{project:e.project,primary:t===0},e.project.id):e.kind===`paused`?(0,h.jsx)(Whe,{project:e.project,primary:t===0},e.project.id):e.kind===`held`?(0,h.jsx)(Uhe,{schedule:e.schedule,primary:t===0},e.schedule.id):(0,h.jsx)(Ghe,{project:e.project,primary:t===0},e.project.id))})]}),(0,h.jsxs)(`section`,{id:`running`,"aria-label":`Running now`,children:[(0,h.jsx)(W,{title:`Running now`,info:`home.running`,meta:p.length===0?`Nothing is running`:`${String(p.length)} ${p.length===1?`video`:`videos`}`}),p.length===0?T||g.length>0?null:(0,h.jsx)(T1,{title:`Start the next video`,children:`Pick a template and a topic on Play, or let a schedule start one.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:p.slice(0,3).map(e=>(0,h.jsx)(age,{project:e,now:l},e.id))}),(0,h.jsx)(Jhe,{running:p.length,queued:g})]})]}),(0,h.jsxs)(x1,{children:[(0,h.jsxs)(`section`,{"aria-label":`Coming up`,children:[(0,h.jsx)(W,{title:`Coming up`,info:`home.coming-up`,meta:`Next 7 days`,children:(0,h.jsx)(wS,{to:`/calendar`,children:`Calendar`})}),o.error===null?C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading…`:`No scheduled runs this week. Plan some on the calendar.`}):(0,h.jsx)(jhe,{runs:C.slice(0,6)}):(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The calendar didn't load: ${o.error.message} Reload the page to try again.`})]}),(0,h.jsxs)(`section`,{"aria-label":`Ready to upload`,children:[(0,h.jsx)(W,{title:`Ready to upload`,info:`home.ready`,meta:x.length===0?`Finished videos you haven't marked uploaded show here`:`${String(x.length)} finished and not marked uploaded`}),x.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:x.slice(0,j3).map(e=>(0,h.jsx)(Khe,{project:e},e.id))})]}),(0,h.jsxs)(`section`,{"aria-label":`This week`,children:[(0,h.jsx)(W,{title:`This week`,info:`home.this-week`,meta:`Since Monday`}),(0,h.jsx)(sge,{channelId:t.channelId})]})]})]})]})}function P3({className:e,...t}){return(0,h.jsx)(`input`,{"data-slot":`input`,className:z(`h-8 w-full min-w-0 rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,`placeholder:text-ink-3 aria-invalid:border-danger`,e),...t})}var dge={written:``,spoken:``,wholeWord:!0,caseSensitive:!1};function fge(){let{api:e}=V(),t=_(),n=I(gb(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)({}),[s,c]=(0,m.useState)(),l=(0,m.useRef)(0),u=(0,m.useId)(),d=e=>e.map(e=>(l.current+=1,{...e,key:l.current}));(0,m.useEffect)(()=>{r===void 0&&n.data!==void 0&&i(d(n.data.aliases))});let f=r??[],p=L({mutationFn:t=>$s(e,t),onSuccess:async e=>{if(!e.ok){let t={};for(let n of e.fields){let e=/^aliases\.(\d+)/u.exec(n.field)?.[1];e!==void 0&&(t[Number(e)]=n.message)}o(t),c({text:`Not saved: ${e.fields.map(e=>e.message).join(` `)}`,tone:`error`});return}o({}),i(d(e.value.aliases)),c({text:`Saved. New projects use these aliases; a project you already started keeps its copy until you refresh it in Edit project.`,tone:`success`}),await t.invalidateQueries({queryKey:H.narrationAliases})},onError:e=>c({text:`Couldn't save the aliases: ${e.message}`,tone:`error`})});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(I4,{action:(0,h.jsxs)(B,{type:`button`,onClick:()=>{l.current+=1,i([...f,{...dge,key:l.current}]),c(void 0)},disabled:r===void 0,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add alias`]}),children:(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Words the narrator says differently, like Dr. as Doctor.`,(0,h.jsx)(U,{id:`library.aliases`})]})}),n.error===null?null:(0,h.jsxs)(aI,{tone:`danger`,title:`Couldn't load the aliases`,className:`mb-6`,children:[n.error.message,` Reload the page to try again.`]}),(0,h.jsxs)(b1,{split:`aside`,children:[(0,h.jsx)(x1,{label:`Aliases`,children:r===void 0?null:f.length===0?(0,h.jsx)(T1,{title:`No aliases yet`,children:`Use Add alias to say a word differently from how it is written.`}):(0,h.jsx)(pge,{rows:f,errors:a,idPrefix:u,update:(e,t)=>{i(f.map(n=>n.key===e?{...n,...t}:n)),c(void 0)},remove:e=>{i(f.filter(t=>t.key!==e)),o({}),c(void 0)}})}),(0,h.jsx)(x1,{as:`aside`,label:`How aliases are used`,children:(0,h.jsxs)(`section`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(W,{title:`How they are used`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`The narrator reads the alias instead of the written word. The article, the captions and the PDF keep the written word.`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`A project takes a copy of this list when it starts and uses it while Use narration aliases is on. A project you already started keeps its copy until you refresh it in Edit project.`}),(0,h.jsx)(`p`,{className:`m-0`,children:`Whole word skips matches inside longer words; Match case only matches the exact capitals.`})]})})]}),(0,h.jsx)(y1,{status:(0,h.jsx)(v1,{tone:s?.tone??`info`,children:s?.text}),children:(0,h.jsx)(B,{type:`button`,variant:`primary`,disabled:r===void 0||p.isPending,onClick:()=>p.mutate(f.map(({written:e,spoken:t,wholeWord:n,caseSensitive:r})=>({written:e,spoken:t,wholeWord:n,caseSensitive:r}))),children:p.isPending?`Saving…`:`Save aliases`})})]})}function pge({rows:e,errors:t,idPrefix:n,update:r,remove:i}){return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-4 gap-y-1 pb-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Written`,(0,h.jsx)(U,{id:`library.aliases.written`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Say it as`,(0,h.jsx)(U,{id:`library.aliases.spoken`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Whole word`,(0,h.jsx)(U,{id:`library.aliases.whole-word`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Match case`,(0,h.jsx)(U,{id:`library.aliases.match-case`})]})]}),(0,h.jsx)(PH,{label:`Narration aliases`,children:e.map((e,a)=>{let o=`${n}-${e.key}`,s=t[a],c=e.written.trim(),l=e.spoken.trim();return(0,h.jsx)(FH,{title:`Alias ${String(a+1)}`,meta:c===``||l===``?`Not filled in yet`:`Says ${c} as ${l}${e.wholeWord?` · whole word`:``}${e.caseSensitive?` · match case`:``}`,actions:(0,h.jsx)(Py,{size:`small`,label:`Remove alias ${String(a+1)}`,onClick:()=>i(e.key),children:(0,h.jsx)($c,{"aria-hidden":`true`})}),children:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto_auto] md:items-end`,children:[(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-written`,children:[`Written`,(0,h.jsx)(P3,{id:`${o}-written`,value:e.written,placeholder:`Dr.`,maxLength:200,"aria-invalid":s!==void 0,"aria-describedby":s===void 0?void 0:`${o}-error`,onChange:t=>r(e.key,{written:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-spoken`,children:[`Say it as`,(0,h.jsx)(P3,{id:`${o}-spoken`,value:e.spoken,placeholder:`Doctor`,maxLength:500,"aria-invalid":s!==void 0,onChange:t=>r(e.key,{spoken:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.wholeWord,onChange:t=>r(e.key,{wholeWord:t.target.checked})}),`Whole word`]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.caseSensitive,onChange:t=>r(e.key,{caseSensitive:t.target.checked})}),`Match case`]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${o}-error`,className:`m-0 text-small text-danger md:col-span-4`,children:s})]})},e.key)})})]})}function F3(e){return MK(e).names}function mge(e,t){let n=F3(e),r=Object.create(null);for(let[e,i]of Object.entries(t))r[e]=n.includes(e)?``:i;return r}function hge(e){return{...e,form:{...e.form,values:mge(e.form.title,e.form.values)},variants:[]}}function I3({onDefaults:e}){let{api:t}=V(),n=_(),r=I({queryKey:c1.firstRun,queryFn:()=>mfe(t),retry:!1,staleTime:1/0}),i=r.data?.defaults;(0,m.useEffect)(()=>{i!==void 0&&(dN(i),e?.(i))},[i,e]);let a=L({mutationFn:()=>hfe(t),onSuccess:()=>n.invalidateQueries({queryKey:c1.firstRun})}),o=r.data;if(o===void 0||!o.firstRun||o.message===null)return null;let s=o.detected.filter(e=>e.usable);return(0,h.jsxs)(aI,{title:o.message,actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:a.isPending,onClick:()=>a.mutate(),children:`Got it`}),children:[o.detail===null?null:(0,h.jsx)(`p`,{className:`m-0`,children:o.detail}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0`,children:[`Found:`,` `,s.map(e=>`${e.displayName}${e.version===void 0?``:` ${e.version}`}`).join(`, `)]}),a.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:a.error.message}):null]})}function L3(){let{api:e}=V(),{document:t}=XN(),n=I(lq(e)),r=t.templateSource,i=n.data?.find(e=>e.id===r?.id);return t.channelId??(i===void 0?`00000000-0000-4000-8000-000000000001`:E1(i))}function R3(){let{api:e}=V();return I(lx(e,L3())).data?.cast??[]}function gge({disabled:e=!1}){let{api:t}=V(),n=XN(),r=I(cx(t)),{document:i}=n,a=L3(),o=r.data?.find(e=>e.id===a),s=i.form.useBrandKit!==!1,c=e=>{n.edit(e),n.invalidateReview(!0)};return(0,h.jsxs)(`div`,{className:`sl-fields items-end`,children:[(0,h.jsx)(LB,{label:`Channel`,tip:`play.channel`,children:(0,h.jsxs)(VB,{"data-play-field":`channelId`,value:a,disabled:e,onChange:e=>c({...i,channelId:e.target.value}),children:[r.data===void 0?(0,h.jsx)(`option`,{value:a,children:`Loading channels…`}):null,(r.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsx)(Bb,{label:`Use the channel's brand kit`,tip:`play.brand-kit`,checked:s,disabled:e,className:`min-h-[38px]`,onChange:e=>{let{useBrandKit:t,...n}=i.form;c({...i,form:e?n:{...n,useBrandKit:!1}})}}),o?(0,h.jsxs)(`p`,{className:`sl-fields__wide m-0 text-small text-ink-3`,children:[(0,h.jsxs)(fa,{to:`/channels/$channelId`,params:{channelId:o.id},className:`underline`,children:[`Edit `,o.name]}),s?``:` · its cast is still used`]}):null]})}function z3(){let{api:e}=V(),{document:t}=XN(),n=I(cx(e)),r=L3(),i=n.data?.find(e=>e.id===r);return t.form.language??i?.brand.language??`en`}function _ge({disabled:e=!1}){let{api:t}=V(),n=XN(),r=I(cx(t)),i=L3(),a=r.data?.find(e=>e.id===i),{document:o}=n;return(0,h.jsx)(`div`,{children:(0,h.jsx)(o2,{value:o.form.language,inherited:{label:`Channel's language`,language:a?.brand.language},disabled:e,onChange:e=>{let{language:t,...r}=o.form;n.edit({...o,form:e===void 0?r:{...r,language:e}}),n.invalidateReview(!0)}})})}var B3=[{stage:`audio`,label:`Audio`},{stage:`images`,label:`Images`},{stage:`video`,label:`Video / export`}];function vge(e,t){if(e===`reviews`||e.startsWith(`reviews.`))return{section:`review`,field:e};if(e!==`checkpoints`&&!e.startsWith(`checkpoints.`))return;let n=e.slice(12),r=/^\d+$/.test(n)?t.checkpoints?.[Number(n)]:n;return{section:`review`,field:B3.some(e=>e.stage===r)?`checkpoints.${r}`:`checkpoints`}}function yge({problem:e}){let t=XN(),{document:n,review:r}=t,{form:i}=n,a=(0,m.useId)(),o=i.checkpoints??[];return(0,h.jsxs)(`fieldset`,{"data-play-field":`checkpoints`,tabIndex:-1,"aria-invalid":e(`checkpoints`)!==void 0,disabled:r.starting||r.uncertain,className:`min-w-0 rounded-media border border-line px-3 pt-1 pb-2`,...zb,children:[(0,h.jsxs)(`legend`,{className:`flex items-center gap-1 px-1 font-semibold`,children:[`Review checkpoints`,(0,h.jsx)(U,{id:`play.checkpoints`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-6`,children:B3.map(({stage:r,label:s})=>{let c=o.includes(r),l=r===`video`?i.sources.video!==`off`&&i.sources.images!==`off`||i.sources.audio!==`off`:i.sources[r]===`generate`,u=e(`checkpoints.${r}`),d=`${a}-${r}`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:d,className:`flex min-h-10 items-center gap-3 max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:d,type:`checkbox`,"data-play-field":`checkpoints.${r}`,"aria-invalid":u!==void 0,"aria-describedby":`${d}-detail`,checked:c,disabled:!l&&!c,className:`size-4 accent-accent`,onChange:e=>{let a=e.target.checked?[...o,r]:o.filter(e=>e!==r);t.edit({...n,form:{...i,checkpoints:a}}),t.invalidateReview(!0)}}),`Before `,s]}),(0,h.jsx)(`p`,{id:`${d}-detail`,className:u||c&&!l?`pl-7 text-small text-danger`:`sr-only`,children:u??(l?`Approval required before this step and its dependents run.`:c?`This step is unavailable. Remove its checkpoint or enable the step.`:r===`video`?`Enable Video or Audio to review before export.`:`Choose Generate for ${s} to add this checkpoint.`)})]},r)})}),e(`checkpoints`)?(0,h.jsx)(`p`,{className:`text-small text-danger`,children:e(`checkpoints`)}):null]})}function V3({id:e,value:t,disabled:n,className:r,field:i,onChange:a}){let{api:o}=V(),s=I(hb(o)).data?.themes??[],c=t?.custom,l=c===void 0?void 0:s.find(e=>e.id===c.id),u=c!==void 0&&(l===void 0||l.name!==c.name||JSON.stringify(l.values)!==JSON.stringify(c.values)),d=c===void 0&&aC(t)===`dicemaster`,f=c===void 0?`builtin:${aC(t)}`:u?`kept`:`custom:${c.id}`;return(0,h.jsxs)(UB,{id:e,"data-play-field":i,className:r,disabled:n,value:f,onChange:e=>{let n=e.target.value;if(n===`kept`)return;if(n.startsWith(`builtin:`)){let e=tC.find(e=>`builtin:${e}`===n);e!==void 0&&a({theme:e});return}let r=s.find(e=>`custom:${e.id}`===n);r!==void 0&&a({theme:aC(t),custom:{id:r.id,name:r.name,values:r.values}})},children:[(0,h.jsxs)(`optgroup`,{label:`Built in`,children:[tC.map(e=>(0,h.jsx)(`option`,{value:`builtin:${e}`,children:iC[e]},e)),d?(0,h.jsx)(`option`,{value:`builtin:${nC}`,children:`${iC[nC]} (retired, this project's look)`}):null]}),s.length===0&&!u?null:(0,h.jsxs)(`optgroup`,{label:`Your themes`,children:[u?(0,h.jsx)(`option`,{value:`kept`,children:`${c.name} (this project's copy)`}):null,s.map(e=>(0,h.jsx)(`option`,{value:`custom:${e.id}`,children:u&&l?.id===e.id?`${e.name} (current version)`:e.name},e.id))]})]})}function H3({label:e,field:t,hideLabel:n=!1,value:r,options:i,className:a,tip:o,onPick:s}){let c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:z(`inline-flex items-center gap-3`,a),...o===void 0?{}:zb,children:[(0,h.jsx)(K4,{id:c,className:n?`sr-only`:`shrink-0`,children:e}),(0,h.jsx)(q4,{type:`single`,value:r,"aria-labelledby":c,onValueChange:e=>{let t=i.find(t=>t.value===e);t!==void 0&&t.disabled!==!0&&s(t.value)},children:i.map(e=>(0,h.jsx)(J4,{value:e.value,"data-play-field":e.value===r?t:void 0,disabled:e.disabled===!0,children:e.label},e.value))}),o===void 0?null:(0,h.jsx)(U,{id:o,label:e,className:`-ml-1`})]})}function U3({value:e,onPick:t,rawCounts:n}){let r=e.words??500,i=e.characters??3e3,a=e.mode===`words`||e.mode===`characters`,o=e.mode===`characters`,s=o?e.characters:e.words;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H3,{field:`chunking.mode`,label:`Chunking`,tip:`play.chunking`,className:`min-w-0 max-w-full flex-wrap [&_[data-slot=toggle-group]]:max-w-full [&_[data-slot=toggle-group]]:flex-wrap`,value:e.mode,options:[{value:`whole`,label:`Whole`},{value:`paragraph`,label:`Paragraph`},{value:`words`,label:`Every ${String(n?.words??r)} words`},{value:`characters`,label:`Every ${String(n?.characters??i)} characters`}],onPick:e=>{if(n){n.onChange(e,e===`characters`?n.characters:n.words);return}t(e===`words`?{mode:e,words:r}:e===`characters`?{mode:e,characters:i}:{mode:e})}}),a?(0,h.jsx)(XB,{label:o?`Characters`:`Words`,tip:`play.chunking.count`,problem:void 0,children:({id:r})=>(0,h.jsx)(zB,{id:r,"data-play-field":o?`chunking.characters`:`chunking.words`,type:n?`text`:`number`,min:1,max:o?1e6:1e4,inputMode:`numeric`,className:`sl-input--number`,value:n?o?n.characters:n.words:s===void 0?``:String(s),onChange:r=>{if(n){n.onChange(e.mode,r.target.value);return}let i=Number.parseInt(r.target.value,10),a=Number.isFinite(i)&&i>0;t(o?a?{mode:`characters`,characters:Math.min(i,1e6)}:{mode:`characters`}:a?{mode:`words`,words:Math.min(i,1e4)}:{mode:`words`})}})}):null]})}var W3=1;function G3({prompts:e,picked:t,problem:n,onPick:r,rawNumbers:i}){let a=(0,m.useId)(),o=t.reduce((e,t)=>e+t.number,0),s=t.filter(t=>!e.some(e=>e.name===t.name)),c=[...e.map(e=>({name:e.name,missing:!1})),...s.map(e=>({name:e.name,missing:!0}))];return c.length===0?(0,h.jsx)(`p`,{className:`sl-fields__wide basis-full text-small text-ink-3`,children:`No image prompts saved. Write one on Prompts.`}):(0,h.jsxs)(`div`,{className:`sl-fields__wide flex w-full basis-full flex-col gap-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{id:a,className:`engraved text-ink-3`,children:`Image prompts`}),(0,h.jsx)(U,{id:`play.image-prompts`,className:`-my-1`})]}),(0,h.jsx)(`ul`,{"aria-labelledby":a,className:`m-0 grid w-full list-none grid-cols-[repeat(auto-fill,minmax(min(100%,15rem),1fr))] gap-x-6 gap-y-2 p-0`,children:c.map(e=>{let a=t.findIndex(t=>t.name===e.name),o=a===-1?void 0:t[a];return(0,h.jsxs)(`li`,{children:[e.missing?(0,h.jsx)(`span`,{className:`block text-label text-danger`,children:`Missing template · untick to remove`}):null,(0,h.jsx)(bge,{name:e.name,number:o?.number,rawNumber:i?{value:i.values.find(t=>t.name===e.name)?.number??``,onChange:t=>i.onChange(e.name,t)}:void 0,problem:a===-1?void 0:n(`imagePrompts.${String(a)}.number`),onTick:n=>{r(n?[...t,{name:e.name,number:W3}]:t.filter(t=>t.name!==e.name))},onNumber:n=>{r(t.map(t=>t.name===e.name?{name:t.name,number:n}:t))}})]},e.name)})}),t.length===0?null:(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:Number.isFinite(o)?`${String(o)} of 60 images`:`Complete image counts to see the total`})]})}function bge({name:e,number:t,problem:n,onTick:r,onNumber:i,rawNumber:a}){let o=(0,m.useId)(),s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex w-full min-w-0 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:o,"data-play-field":`imagePrompts`,type:`checkbox`,checked:t!==void 0,className:`size-[14px] shrink-0 accent-accent`,onChange:e=>{r(e.target.checked)}}),(0,h.jsx)(`label`,{htmlFor:o,title:e,className:z(`min-w-0 flex-1 truncate`,t===void 0?`text-ink-3`:`text-ink`),children:e}),(0,h.jsx)(K4,{htmlFor:s,className:`sr-only`,children:`Number for ${e}`}),(0,h.jsx)(zB,{id:s,"data-play-field":`imagePrompts.${e}.number`,type:a?`text`:`number`,min:W3,max:20,inputMode:`numeric`,disabled:t===void 0,"aria-invalid":n!==void 0,"aria-describedby":n===void 0?void 0:c,className:`sl-input--number`,value:a?.value??(t===void 0||t===0?``:String(t)),onChange:e=>{if(a){a.onChange(e.target.value);return}let t=Number.parseInt(e.target.value,10);i(Number.isFinite(t)?t:0)}}),n===void 0?null:(0,h.jsx)(`span`,{id:c,className:`text-label text-danger`,children:n})]})}var xge=`text-small text-ink-2 file:mr-3 file:h-8 file:rounded-control file:border file:border-line-strong file:bg-raised file:px-3 file:text-ink`;function K3({label:e,field:t,value:n,placeholder:r,problem:i,tip:a,onChange:o}){let s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`div`,{...a===void 0?{}:zb,children:[(0,h.jsxs)(`span`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:s,children:e}),a===void 0?null:(0,h.jsx)(U,{id:a,label:e,className:`-my-1`})]}),(0,h.jsx)(BB,{id:s,"data-play-field":t,rows:6,value:n,placeholder:r,"aria-invalid":i!==void 0,"aria-describedby":i===void 0?void 0:c,onChange:e=>{o(e.target.value)}}),i===void 0?null:(0,h.jsx)(`p`,{id:c,className:`mt-1 text-label text-danger`,children:i})]})}function q3({label:e,field:t,accept:n,multiple:r=!1,disabled:i=!1,uploads:a,problem:o,numbered:s=!1,onPick:c,onRemove:l,onReattach:u}){let d=(0,m.useId)(),f=(0,m.useId)();return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(K4,{htmlFor:d,className:`mb-1`,children:e}),(0,h.jsx)(`input`,{id:d,"data-play-field":t,type:`file`,accept:n,multiple:r,disabled:i,"aria-invalid":o!==void 0,"aria-describedby":o===void 0?void 0:f,className:xge,onChange:e=>{c([...e.target.files??[]]),e.target.value=``}}),o===void 0?null:(0,h.jsx)(`p`,{id:f,className:`mt-1 text-label text-danger`,children:o}),a.length===0?null:(0,h.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,children:a.map((e,t)=>(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3`,children:[s?(0,h.jsx)(`span`,{className:`engraved w-6 text-ink-3`,children:String(t+1)}):null,(0,h.jsx)(Sge,{upload:e}),e.error!==void 0&&u?(0,h.jsxs)(`label`,{className:`text-small text-ink-2`,children:[`Reattach`,(0,h.jsx)(`input`,{"aria-label":`Reattach ${e.name}`,className:`max-w-full`,type:`file`,accept:n,onChange:t=>{let n=t.target.files?.[0];t.target.value=``,n&&u(e.key,n)}})]}):null,l===void 0?null:(0,h.jsx)(B,{variant:`quiet`,className:`ml-auto`,"aria-label":`Remove ${e.name}`,onClick:()=>{l(e.key)},children:`Remove`})]},e.key))})]})}function Sge({upload:e}){return(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-3 text-small [overflow-wrap:anywhere]`,children:[(0,h.jsx)(`span`,{className:e.error===void 0?`text-ink`:`text-danger`,children:e.name}),e.error===void 0?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:e.file===void 0?`Copying`:`Staged`}):(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.error})]})}var J3=`col-span-3 min-w-0 sl-fields`,Y3=`col-span-3 min-w-0`;function X3({kind:e,name:t,dim:n,titled:r=!0,children:i}){return(0,h.jsxs)(`section`,{"data-tour":`play-${e}`,className:`grid grid-cols-[24px_1fr_auto] items-center gap-x-2 gap-y-4 border-b border-line py-4 [&>div:empty]:hidden`,children:[r?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(vS,{kind:e,className:n?`text-ink-3`:`text-ink-2`}),(0,h.jsx)(`h3`,{className:z(`m-0 text-title-3`,n?`text-ink-3`:void 0),children:t})]}):(0,h.jsx)(`span`,{className:`sl-field__label col-span-2`,children:`Source`}),i]})}var Cge={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`};function Z3({kind:e,form:t,update:n}){return(0,h.jsx)(H3,{field:`sources.${e}`,label:`${e} source`,hideLabel:!0,tip:Cge[e],className:`max-[700px]:col-span-3 max-[700px]:justify-self-start [&_[data-slot=toggle-group]]:flex-wrap`,value:t.sources[e],options:ON(e).filter(n=>e!==`thumbnail`||n.value!==`prompt_by_llm`||t.sources.article!==`off`).map(n=>({...n,disabled:e===`video`&&n.value===`generate`&&t.sources.images===`off`})),onPick:r=>{if(e===`article`&&r===`off`){n(wge(t));return}n({sources:{...t.sources,[e]:r,...e===`images`&&r===`off`?{video:`off`}:{}}})}})}function Q3(e,t){return e.filter(e=>e.kind===t).map(e=>({value:e.name,label:e.name}))}function wge(e){return{sources:{...e.sources,article:`off`,research:`off`,audio:`off`,document:`off`,...e.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}},subtitles:{...e.subtitles,mode:`off`},youtubeDescription:!1,...e.shorts===void 0?{}:{shorts:{...e.shorts,enabled:!1}}}}function Tge(e){let t=this;t.compiler=n;function n(n){return nue(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}var $3=jR().use(ZL).use(Tge).freeze(),e6=`[ˈˌ]?[abdefghijklmnoprstuvwxzæðŋθɑɒɔəɚɛɜɝɡɪɹʃʊʌʒʔɫɾ][\\u0303\\u031a\\u0325\\u0329\\u032a\\u032c\\u032f\\u035c\\u0361ʰʲʷ]*[ːˑ]?`,Ege=RegExp(`^(?:${e6})+(?:\\.(?:${e6})+)*$`,`u`),t6=`[ˈˌ]?[a-zæçðøħŋœɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɪɫɬɭɮɯɰɱɲɳɴɵɶɸɹɺɻɽɾʀʁʂʃʄʈʉʊʋʌʍʎʏʐʑʒʔʕʙʛʜʝʟʡʢβθχ][\\u0300-\\u036fʰʱʲʷʼˠˤ˞]*[ːˑ]?`,Dge=RegExp(`^(?:${t6})+(?:\\.(?:${t6})+)*$`,`u`);function n6(e){return e.type===`break`?`
279
+ `:e.value??e.children?.map(n6).join(``)??``}function r6(e){if(e.type===`heading`){let t=n6(e).trim();return/^pronunciation glossary:?\s*$/iu.test(t)?[]:[t]}return e.type===`table`?(e.children??[]).slice(1).map(e=>{let t=e.children??[];if(t.length<2)return n6(e);let[n,r]=t.slice(0,2).map(e=>n6(e).trim());return`${n}: ${r!==void 0&&r!==``&&!r.includes(`/`)?`/${r}/`:r}`}):e.type===`paragraph`?n6(e).split(/\r?\n/u):e.type===`root`||e.type===`list`||e.type===`listItem`?(e.children??[]).flatMap(r6):[`(unsupported glossary block)`]}function Oge(e){return Array.from(e,e=>{let t=e.toLowerCase(),n=t.toUpperCase().toLowerCase();if(n===e)return e;let r=RegExp(`^${e.replace(/[|\\{}()[\]^$+*?.]/gu,`\\$&`)}$`,`iu`);return r.test(n)?n:r.test(t)?t:e}).join(``)}function i6(e,t){let n=t===void 0||t===`en`,r=n?Ege:Dge,i=n?`standard-English IPA`:`IPA`,a=r6($3().use(Bz).parse(e)),o=new Map,s=[];for(let[e,t]of a.entries()){let a=t=>{s.push({row:e+1,reason:t})},c=t.trim();if(c===``||/^pronunciation glossary:?\s*$/iu.test(c))continue;let l=/^([^:]+):\s*(.+)$/u.exec(c),u=l?.[1]?.trim().replace(/\s+/gu,` `),d=l?.[2];if(u===void 0||d===void 0||!/[\p{L}\p{N}]/u.test(u)||/[/[\]<>\p{Cc}]/u.test(u)){a(`use Term: /IPA/ or a Term | IPA table`);continue}let f=/^(\/[^/]+\/(?:\s+\/[^/]+\/)*)(?:\s+[^/]+)?$/u.exec(d);if(f?.[1]===void 0){a(`use slash-delimited ${i}`);continue}let p=Array.from(f[1].matchAll(/\/([^/]+)\//gu)).flatMap(e=>(e[1]??``).trim().split(/\s+/u));if(p.length===0||p.some(e=>!r.test(e))){a(n?`use standard-English IPA only, not ARPAbet, delivery tags or non-English sounds; give a foreign name an English approximation`:`use IPA, not ARPAbet or delivery tags`);continue}if(u.split(` `).length!==p.length){a(`supply one IPA word for each written word`);continue}let m=Oge(u),h=o.get(m);if(h!==void 0&&h.ipa.join(` `)!==p.join(` `)){a(`an earlier entry already gives this term a different pronunciation`);continue}h===void 0&&o.set(m,{term:u,ipa:p})}return s.length===0?{ok:!0,entries:[...o.values()]}:{ok:!0,entries:[...o.values()],skipped:s}}function kge(e,t){return e.flatMap(e=>{if(!e.pronunciations?.trim())return[];let n=i6(e.pronunciations,t),r=n.ok?n.skipped??[]:[];return r.length===0?[]:[{speaker:e.name.trim()||`A speaker`,skipped:r}]})}function Age(e,t){let n=t?.turns.find(t=>t.speaker===e.id)?.text??jge(e);if(n.length<=200)return n;let r=n.slice(0,200),i=Math.max(r.lastIndexOf(`. `),r.lastIndexOf(`? `),r.lastIndexOf(`! `));return i>60?r.slice(0,i+1):`${r.slice(0,r.lastIndexOf(` `))}…`}function jge(e){let t=e.name.trim()||`your speaker`;switch(e.role){case`narrator`:return`The night was quiet, and the old house held its breath. I'm ${t}, and I'll be telling this story.`;case`host`:return`Hi everyone, I'm ${t}, and welcome back to the show. Today's topic is a good one.`;case`guest`:return`Thanks for having me. I'm ${t}, and I've been looking forward to this conversation.`;case`character`:return`You really thought I wouldn't find out? My name is ${t}, and I always find out.`}}function Mge(e){return e.flatMap(e=>e.host===!0&&e.voice!==void 0?[a6(e,`host`)]:[])}function Nge(e){let t=e.toLowerCase();return/^[a-z0-9-]{1,55}$/.test(t)?`cast-${t}`:`cast-h${Pge(e)}`}function Pge(e){let t=3735928559,n=1103547991;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,2654435761),n=Math.imul(n^i,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(4294967296*(2097151&n)+(t>>>0)).toString(36)}function a6(e,t){let n=e.voice;return{id:Nge(e.id),name:e.name.slice(0,40),role:t,voice:n===void 0?{provider:``,model:``,voice:``}:{provider:n.provider,model:n.model,voice:n.voice},...n?.pace===void 0||n.pace===1?{}:{pace:n.pace},...n?.pronunciations?.trim()?{pronunciations:n.pronunciations}:{},castId:e.id,...Fge(e)}}function Fge(e){let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null)?.sha256;return t==null?{}:{portrait:t}}var Ige=/^#{1,6}\s+(.+?)\s*#*\s*$/,Lge=/^\*{0,2}([^:*\n]{1,60}?)\*{0,2}\s*:\s*\*{0,2}\s*(.*)$/;function o6(e,t,n=!1){let r=new Map(t.map(e=>[e.name.trim().toLowerCase(),e])),i=t.map(e=>e.name.trim()).join(`, `),a=[],o=[],s=!1;for(let[t,n]of e.replace(/\r\n?/g,`
280
280
  `).split(`
281
- `).entries()){let e=n.trim(),c=t+1;if(e===``){s=!1;continue}let l=Pge.exec(e);if(l!==null){o.push({title:s6(l[1]??``),firstTurn:a.length+1}),s=!1;continue}if(/^([-*_=~])\1{2,}$/.test(e)){s=!1;continue}let u=Fge.exec(e),d=u===null?void 0:r.get((u[1]??``).trim().toLowerCase());if(u!==null&&d!==void 0){a.push({speaker:d.id,lines:[u[2]??``],section:o.length-1}),s=!0;continue}let f=a.at(-1);if(s&&f!==void 0){f.lines.push(e);continue}return{ok:!1,reason:u===null?`Line ${String(c)} of the script is not a turn. Start every turn with a speaker's name and a colon (${i}), one turn per paragraph.`:`Line ${String(c)} of the script is spoken by "${(u[1]??``).trim()}", who is not one of the speakers (${i}). Use only these names, or add the speaker under Speakers (Play → Narration, or Edit project → Providers).`}}let c=[];for(let e of a){let t=s6(e.lines.join(` `));t!==``&&c.push({index:c.length+1,speaker:e.speaker,text:t,section:e.section,...n?{markdown:e.lines.join(`
282
- `)}:{}})}if(c.length===0)return{ok:!1,reason:`The script has no spoken turns. Write each turn as a speaker's name, a colon and their words (${i}).`};let l=[],u=new Map;for(let[e,t]of o.entries()){let n=c.find(t=>t.section===e);n!==void 0&&t.title!==``&&(u.set(e,l.length),l.push({title:t.title,firstTurn:n.index}))}return{ok:!0,script:{turns:c.map(e=>({...e,section:u.get(e.section)??-1})),sections:l}}}function s6(e){return e.replace(/\[[^\]]*\]\([^)]*\)/g,e=>e.slice(1,e.indexOf(`]`))).replace(/\[[^\]]*\]/g,` `).replace(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g,`$2`).replace(/`/g,``).replace(/\s+/g,` `).trim()}var Ige={narrator:`Narrator`,host:`Host`,guest:`Guest`,character:`Character`};function c6({value:e,onChange:t,providers:n,voices:r,script:i,problem:a,cast:o=[],language:s}){let c=(0,m.useMemo)(()=>{if(e===void 0||i===void 0||i.trim()===``)return;let t=o6(i,e.speakers);return t.ok?t.script:void 0},[i,e]),l=n=>{if(n===``){t(void 0);return}let r=yA.find(e=>e===n);r!==void 0&&t(e===void 0?MA(r,Age(o)):{...e,format:r,source:r===`audiobook`?e.source:`script`})},u=n=>{e!==void 0&&t({...e,...n})},d=o.filter(t=>t.voice!==void 0&&!(e?.speakers??[]).some(e=>e.castId===t.id)),f=(t,n)=>{e!==void 0&&u({speakers:e.speakers.map((e,r)=>r===t?n:e)})};return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-3`,"data-play-field":`voices`,children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(ZB,{field:`voices.format`,label:`Format`,tip:`play.speakers.format`,value:e?.format??``,placeholder:`Narration (one voice)`,options:yA.map(e=>({value:e,label:bA[e]})),problem:a?.(`voices.format`),onPick:l}),e?.format===`audiobook`?(0,h.jsx)(ZB,{field:`voices.source`,label:`Script`,tip:`play.speakers.script`,value:e.source,placeholder:`Pick where the script comes from`,options:[{value:`script`,label:`Write a script (Script prompt)`},{value:`attribute`,label:`Split the article into speakers`}],problem:a?.(`voices.source`),onPick:e=>u({source:e===`attribute`?`attribute`:`script`})}):null]}),e===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`One voice reads the article. Pick a format for an audiobook, podcast, radio drama or interview with several speakers.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.source===`script`?"The article prompt must be a Script prompt: the text model writes speaker turns, one `Name: words` paragraph each.":`The article is written or pasted as usual; the text model then hands its narration and dialogue to the speakers.`}),a?.(`voices.speakers`)===void 0?null:(0,h.jsx)(`p`,{className:`text-label text-danger`,children:a(`voices.speakers`)}),(0,h.jsx)(`ol`,{"aria-label":`Speakers`,className:`divide-y divide-line border-y border-line`,children:e.speakers.map((t,i)=>(0,h.jsx)(Bge,{index:i,speaker:t,line:Oge(t,c),providers:n,voices:r,language:s,problem:a,onChange:e=>f(i,e),onRemove:e.speakers.length>1?()=>u({speakers:e.speakers.filter((e,t)=>t!==i)}):void 0},t.id))}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsx)(B,{type:`button`,disabled:e.speakers.length>=10,onClick:()=>u({speakers:[...e.speakers,zge(e.speakers)]}),children:`Add speaker`}),(0,h.jsx)(ZB,{label:`Add from the cast`,tip:`play.speakers.add-from-cast`,value:``,placeholder:d.length===0?`No cast member has a voice yet`:`Pick one of ${String(d.length)}`,options:d.map(e=>({value:e.id,label:e.name})),disabled:d.length===0||e.speakers.length>=10,problem:void 0,onPick:t=>{let n=d.find(e=>e.id===t);n!==void 0&&u({speakers:[...e.speakers,a6(n,Rge(e))]})}}),(0,h.jsx)(ZB,{field:`voices.turnGapSeconds`,label:`Gap between turns`,tip:`play.speakers.turn-gap`,value:String(e.turnGapSeconds),placeholder:`Pick a gap`,options:wA.map(e=>({value:String(e),label:`${e} s`})),problem:a?.(`voices.turnGapSeconds`),onPick:e=>u({turnGapSeconds:Number(e)})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,h.jsx)(Bb,{label:`Speaker names on captions`,tip:`play.speakers.name-tags`,checked:e.nameTags,onChange:e=>u({nameTags:e})}),(0,h.jsx)(Bb,{label:`One request for consecutive turns where the voice provider can (ElevenLabs v3, Gemini)`,tip:`play.speakers.native-dialogue`,checked:e.nativeDialogue,onChange:e=>u({nativeDialogue:e})}),(0,h.jsx)(Bb,{label:`Also make MP3 and M4B files with chapter markers`,tip:`play.speakers.audio-files`,checked:e.audioFiles,onChange:e=>u({audioFiles:e})})]}),e.format===`audiobook`?(0,h.jsx)(Lge,{value:e,onChange:t,problem:a}):null,e.format===`podcast`||e.format===`interview`?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The speaker panel (a tile per speaker, the one talking lit, their name below) is drawn with the captions: set Captions to Burn in under Style to see it in the video.`}):null]})]})}function Lge({value:e,onChange:t,problem:n}){let r=e.book,i=n=>t({...e,...n});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(Bb,{label:`A chapter of a book`,tip:`play.speakers.book`,checked:r!==void 0,onChange:n=>{if(n)i({book:{title:``,chapter:1}});else{let{book:n,...r}=e;t(r)}}}),r===void 0?null:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-[minmax(0,1fr)_160px]`,children:[(0,h.jsx)(LB,{label:`Book title`,tip:`play.speakers.book-title`,error:n?.(`voices.book.title`),children:(0,h.jsx)(zB,{value:r.title,maxLength:200,onChange:e=>i({book:{...r,title:e.target.value}})})}),(0,h.jsx)(LB,{label:`Chapter`,tip:`play.speakers.book-chapter`,error:n?.(`voices.book.chapter`),children:(0,h.jsx)(zB,{type:`number`,min:1,max:OA,step:1,value:r.chapter===0?``:String(r.chapter),onChange:e=>i({book:{...r,chapter:Number(e.target.value)||0}})})})]})]})}function Rge(e){return e.format===`podcast`?`host`:e.format===`interview`?e.speakers.some(e=>e.role===`host`)?`guest`:`host`:e.speakers.some(e=>e.role===`narrator`)?`character`:`narrator`}function zge(e){let t=e.length+1;for(;e.some(e=>e.id===`speaker-${String(t)}`);)t+=1;return{id:`speaker-${String(t)}`,name:`Speaker ${String(t)}`,role:`character`,voice:{provider:``,model:``,voice:``}}}function Bge({index:e,speaker:t,line:n,providers:r,voices:i,language:a,problem:o,onChange:s,onRemove:c}){let l=`voices.speakers.${String(e)}`,u=t.voice,d=i.filter(e=>e.provider===u.provider),f=f2(d,a,u.voice||void 0),p=a===void 0?d:f.listed,g=t.name.trim()||`this speaker`,_=(0,m.useMemo)(()=>Dge([t],a??`und`)[0]?.skipped??[],[t,a]);return(0,h.jsxs)(`li`,{className:`grid grid-cols-1 gap-3 py-3 min-[700px]:grid-cols-2`,"data-play-field":l,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-end gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`mb-2 size-3 shrink-0 rounded-full`,style:{background:`var(--color-speaker-${String(e%6+1)})`}}),(0,h.jsx)(LB,{label:`Speaker name`,tip:`play.speaker.name`,error:o?.(`${l}.name`),className:`min-w-0 flex-1`,children:(0,h.jsx)(zB,{value:t.name,maxLength:40,onChange:e=>s({...t,name:e.target.value})})})]}),(0,h.jsx)(ZB,{label:`Role`,tip:`play.speaker.role`,value:t.role,placeholder:`Pick a role`,options:xA.map(e=>({value:e,label:Ige[e]})),problem:void 0,onPick:e=>{let n=xA.find(t=>t===e);n!==void 0&&s({...t,role:n})}}),(0,h.jsx)(eV,{field:`${l}.voice`,label:`Voice provider`,tip:`play.speaker.provider`,family:`tts`,providers:r,value:u.provider,problem:o?.(`${l}.voice`),onPick:e=>s({...t,voice:{provider:e,model:``,voice:``}})}),(0,h.jsx)(tV,{label:`Voice model`,tip:`play.speaker.model`,provider:u.provider,value:u.model,problem:void 0,onPick:e=>s({...t,voice:{...u,model:e}})}),(0,h.jsx)(ZB,{field:`${l}.voice.voice`,label:`Voice`,tip:`play.speaker.voice`,value:u.voice,placeholder:p.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:p.map(e=>({value:e.voiceId,label:e.name})),problem:o?.(`${l}.voice.voice`),onPick:e=>s({...t,voice:{...u,voice:e}})}),a===void 0?null:(0,h.jsx)(p2,{language:a,voice:d.find(e=>e.voiceId===u.voice),hidden:f.hidden,showAll:f.showAll,onShowAll:f.setShowAll}),(0,h.jsx)(ZB,{field:`${l}.pace`,label:`Pace`,tip:`play.speaker.pace`,value:String(t.pace??1),placeholder:`Pick a pace`,options:CA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:o?.(`${l}.pace`),onPick:e=>{let{pace:n,...r}=t;s(Number(e)===1?r:{...r,pace:Number(e)})}}),(0,h.jsxs)(`details`,{className:`col-span-full text-small`,...zb,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-ink-2`,children:[`Pronunciations for `,t.name.trim()||`this speaker`,t.pronunciations?.trim()?` · set`:``,(0,h.jsx)(U,{id:`play.speaker.pronunciations`})]}),(0,h.jsx)(BB,{rows:3,"aria-label":`Pronunciations for ${t.name.trim()||`this speaker`}`,value:t.pronunciations??``,placeholder:`Arda: /ˈɑɹdə/`,onChange:e=>{let{pronunciations:n,...r}=t;s(e.target.value===``?r:{...r,pronunciations:e.target.value})}})]}),_.length===0?null:(0,h.jsxs)(aI,{tone:`waiting`,className:`col-span-full`,title:`${String(_.length)} ${_.length===1?`pronunciation`:`pronunciations`} for ${g} ${_.length===1?`is`:`are`} skipped`,children:[(0,h.jsx)(`ul`,{children:_.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsxs)(`p`,{children:[`Those words are read as ordinary text; the other entries are used. Fix them in Pronunciations for `,g,` above: one `,(0,h.jsx)(`code`,{children:`Term: /IPA/`}),` per line.`]})]}),(0,h.jsxs)(`div`,{className:`col-span-full flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(Hge,{speaker:t,line:n}),(0,h.jsx)(`span`,{className:`flex-1`}),c===void 0?null:(0,h.jsxs)(B,{type:`button`,variant:`quiet`,onClick:c,children:[`Remove `,t.name.trim()||`speaker`]})]})]})}var Vge=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:4});function Hge({speaker:e,line:t}){let{api:n}=V(),{provider:r,model:i,voice:a}=e.voice,o=r!==``&&i!==``&&a!==``,s=I({queryKey:[`audition-quote`,r,i,t],queryFn:()=>nc(n,[{speaker:e.name.trim()||`Speaker`,provider:r,model:i,text:t}]),enabled:o,staleTime:6e4}),[c,l]=(0,m.useState)(void 0);(0,m.useEffect)(()=>()=>{c!==void 0&&URL.revokeObjectURL(c)},[c]);let u=L({mutationFn:()=>rc(n,{provider:r,model:i,voice:a,text:t}),onSuccess:e=>{let t=URL.createObjectURL(e);l(t),new Audio(t).play().catch(()=>{})}}),d=s.data?.estimate,f=d==null?void 0:d.unknown>0?`price unknown`:`about ${Vge.format(d.high)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,disabled:!o||u.isPending,onClick:()=>u.mutate(),title:`Reads: ${t}`,children:u.isPending?`Speaking…`:`Audition${f===void 0?``:` · ${f}`}`}),(0,h.jsx)(U,{id:`play.speaker.audition`})]}),(0,h.jsx)(`span`,{className:`min-h-5 text-label text-ink-2`,"aria-live":`polite`,children:o?u.error===null?c===void 0?`Reads their first line: “${t.length>60?`${t.slice(0,60)}…`:t}”`:`Playing the audition.`:u.error.message:`Pick a provider, model and voice to audition.`})]})}function Uge(e){return e===void 0?`Narration`:bA[e]}function l6({value:e,skipCode:t,onChange:n,tip:r=`play.describe-figures`}){let i=(0,m.useId)(),a=e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.describeFigures`,checked:a,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:e.currentTarget.checked,skipCode:t===!0})}),`Describe tables and figures in the narration`]}),(0,h.jsx)(U,{id:r})]}),a?(0,h.jsxs)(`span`,{className:`flex items-center gap-1 pl-7`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-code`,className:`flex min-h-10 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-code`,type:`checkbox`,"data-play-field":`audio.skipCode`,checked:t===!0,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:!0,skipCode:e.currentTarget.checked})}),`Leave code out`]}),(0,h.jsx)(U,{id:`play.skip-code`})]}):null]})}function u6({value:e,onChange:t,tip:n=`play.show-figures`}){let r=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`showFigures`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Show tables and figures on screen`]}),(0,h.jsx)(U,{id:n})]})}function d6({value:e,onChange:t,note:n}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`audio.useNarrationAliases`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Use narration aliases`]}),(0,h.jsx)(U,{id:`play.narration-aliases`})]}),n===void 0?null:(0,h.jsx)(`div`,{className:`pl-7`,children:n})]})}function f6({value:e,prompts:t,supported:n,error:r,libraryLinks:i=!0,onChange:a}){let o=(0,m.useId)(),s=t.filter(e=>e.kind===`narration`),c=s.find(t=>t.name===e),l=r??(e!==``&&!n?`Choose Inworld TTS-2 or turn preparation Off.`:void 0);return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:o,className:`text-small font-semibold`,children:`Narration Preparation`}),(0,h.jsx)(U,{id:`play.narration-preparation`})]}),(0,h.jsxs)(UB,{id:o,"data-play-field":`narrationPrompt`,value:e,"aria-describedby":l?`${o}-error`:void 0,"aria-invalid":l!==void 0||void 0,onChange:e=>a(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),e!==``&&c===void 0?(0,h.jsxs)(`option`,{value:e,children:[e,` (saved selection)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`text-small text-danger`,children:l}):null,i?(0,h.jsxs)(`div`,{className:`flex gap-4 text-small`,children:[(0,h.jsx)(fa,{to:`/prompts/new`,search:{kind:`narration`},children:`Create prompt`}),c?(0,h.jsx)(fa,{to:`/prompts/$promptId`,params:{promptId:c.id},children:`View prompt`}):null]}):null]})}function p6({value:e,supported:t,onChange:n,shared:r}){let i=(0,m.useId)(),a=t&&e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.usePronunciationGlossary`,checked:e===!0,disabled:!t,"aria-describedby":t?void 0:`${i}-support`,className:`size-4 accent-accent`,onChange:e=>n(e.currentTarget.checked)}),`Use Pronunciation Glossary`]}),(0,h.jsx)(U,{id:`play.pronunciation-glossary`})]}),r===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-1 pl-7`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-shared`,className:`flex min-h-8 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-shared`,type:`checkbox`,"data-play-field":`audio.shareGlossary`,checked:r.value===!0,disabled:!a,className:`size-4 accent-accent`,onChange:e=>r.onChange(e.currentTarget.checked)}),`Also use pronunciations from my other projects`]}),(0,h.jsx)(U,{id:`play.share-glossary`})]}),r.note===void 0?null:r.note]}),t?null:(0,h.jsx)(`p`,{id:`${i}-support`,className:`text-label text-ink-3`,children:`Unavailable for this provider or model. Your saved preference is retained.`})]})}var m6={source:`off`,prompt:``,thumbnail:!0},Wge=[{value:`prompt`,label:`From a prompt`},{value:`provide`,label:`Upload`}];function h6({value:e,prompts:t,problem:n,upload:r,prompt:i,onChange:a}){let o=(0,m.useId)(),s=e.source===`off`,c=t.filter(e=>e.kind===`image`).map(e=>({value:e.name,label:e.name}));return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsx)(`div`,{className:`min-w-0`,children:(0,h.jsx)(ZB,{field:`reference.source`,label:`Establishing image`,tip:`play.reference`,value:s?``:e.source,placeholder:`Off`,options:Wge,problem:n?.(`reference.source`),onPick:t=>a({...e,source:t===`prompt`||t===`provide`?t:`off`})})}),e.source===`provide`?(0,h.jsx)(`div`,{className:`min-w-0`,children:r}):i??(0,h.jsx)(ZB,{field:`reference.prompt`,label:`Establishing prompt`,tip:`play.reference.prompt`,value:e.prompt,placeholder:s?`Off`:`Pick an image prompt`,options:c,disabled:s,problem:n?.(`reference.prompt`),onPick:t=>a({...e,prompt:t})}),(0,h.jsxs)(`div`,{className:`col-span-full flex min-h-9 items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:o,className:`flex cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{id:o,type:`checkbox`,"data-play-field":`reference.thumbnail`,checked:e.thumbnail,disabled:s,onChange:t=>a({...e,thumbnail:t.target.checked})}),`Draw the thumbnail from it too`]}),(0,h.jsx)(U,{id:`play.reference.thumbnail`})]})]})}function g6({choice:e,onChange:t,field:n=`llm.thinking`,label:r=`Thinking`,tip:i=`play.llm.thinking`,problem:a}){let{api:o}=V(),s=I(KB(o,e.provider)).data?.models.find(t=>t.id===e.model)?.thinkingModes??[];if(!s.length&&!e.thinking)return null;let c=r===`Thinking`?`thinking level`:r.toLowerCase();return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(ZB,{field:n,label:r,tip:i,value:e.thinking??`default`,placeholder:`Model default`,problem:e.thinking&&!s.includes(e.thinking)?`Choose a supported ${c}.`:a,options:[{value:`default`,label:`Model default`},...e.thinking&&!s.includes(e.thinking)?[{value:e.thinking,label:`${e.thinking} (saved level)`}]:[],...s.map(e=>({value:e,label:e===`off`?`Off`:e.charAt(0).toUpperCase()+e.slice(1)}))],onPick:n=>{let r=s.find(e=>e===n),{thinking:i,...a}=e;t(r===void 0?a:{...a,thinking:r})}}),r===`Thinking`&&s.length&&!s.includes(`off`)?(0,h.jsx)(`p`,{className:`mt-1 text-small text-ink-3`,children:`This model does not support turning thinking off.`}):null]})}function Gge({form:e,prompts:t,providers:n,voices:r,problem:i,update:a,onPickFiles:o,onRemoveFile:s,onReattachFile:c,rawCounts:l,advanced:u,cast:d,language:f,titled:p}){let g=r.filter(t=>t.provider===e.audio.provider),_=f2(g,f??`en`,e.audio.voice||void 0),v=f===void 0?g:_.listed,y=e.voices?.speakers.find(e=>e.voice.provider&&e.voice.model&&e.voice.voice)?.voice,b=e.intro!==``||e.outro!==``,x=e.voices!==void 0&&!b&&y!==void 0;(0,m.useEffect)(()=>{if(!x||y===void 0)return;let t=e.audio;(t.provider!==y.provider||t.model!==y.model||t.voice!==y.voice)&&a({audio:{...t,provider:y.provider,model:y.model,voice:y.voice}})},[x,y,e.audio,a]);let S=e.voices!==void 0,C=[e.chunking.mode,e.intro?`intro ${e.intro}`:void 0,e.outro?`outro ${e.outro}`:void 0,e.narrationPrompt?`preparation on`:void 0,e.audio.usePronunciationGlossary?`glossary on`:void 0].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(X3,{kind:`audio`,name:`Audio`,dim:e.sources.audio===`off`,titled:p,children:[(0,h.jsx)(Z3,{kind:`audio`,form:e,update:a}),(0,h.jsx)(`div`,{className:J3,children:e.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[x?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{field:`audio.provider`,label:S?`Intro and outro TTS`:`TTS`,tip:`play.tts.provider`,family:`tts`,providers:n,value:e.audio.provider,problem:i(`audio`),onPick:t=>{a({audio:{...e.audio,provider:t,model:``,voice:``}})}}),(0,h.jsx)(tV,{field:`audio.model`,label:`TTS model`,tip:`play.tts.model`,provider:e.audio.provider,value:e.audio.model,problem:i(`audio.model`),onPick:t=>a({audio:{...e.audio,model:t}})}),(0,h.jsx)(ZB,{field:`audio.voice`,label:S?`Intro and outro voice`:`Voice`,tip:`play.voice`,value:e.audio.voice,placeholder:v.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:v.map(e=>({value:e.voiceId,label:e.name})),problem:i(`audio.voice`),onPick:t=>{a({audio:{...e.audio,voice:t}})}}),f===void 0?null:(0,h.jsx)(p2,{language:f,voice:g.find(t=>t.voiceId===e.audio.voice),hidden:_.hidden,showAll:_.showAll,onShowAll:_.setShowAll}),S?(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`This voice reads only the intro and outro. Each speaker's voice is set under Speakers.`}):null]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Speakers ·`,` `,e.voices===void 0?`Narration, one voice`:`${Uge(e.voices.format)}, ${String(e.voices.speakers.length)} ${e.voices.speakers.length===1?`speaker`:`speakers`}`]}),(0,h.jsx)(`div`,{className:`pt-2 pb-3`,children:(0,h.jsx)(c6,{value:e.voices,providers:n,voices:r,script:e.sources.article===`provide`?e.provided.article:void 0,problem:i,cast:d,language:f,onChange:e=>a({voices:e})})})]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Audio Advanced · `,C]}),(0,h.jsxs)(`div`,{className:`sl-fields pt-2 pb-3`,children:[(0,h.jsx)(`div`,{className:`col-span-full`,children:(0,h.jsx)(U3,{...l?{rawCounts:l}:{},value:e.chunking,onPick:e=>{a({chunking:e})}})}),u,(0,h.jsx)(f6,{value:e.narrationPrompt??``,prompts:t,supported:e.audio.provider===`inworld`&&e.audio.model===`inworld-tts-2`,error:i(`narrationPrompt`),onChange:e=>a({narrationPrompt:e})}),(0,h.jsx)(p6,{value:e.audio.usePronunciationGlossary,supported:hj({sources:e.sources,audio:{...e.audio,usePronunciationGlossary:!0}}),onChange:t=>a({audio:{...e.audio,usePronunciationGlossary:t}}),shared:{value:e.audio.shareGlossary??!0,onChange:t=>a({audio:{...e.audio,shareGlossary:t}})}}),(0,h.jsx)(d6,{value:e.audio.useNarrationAliases,onChange:t=>a({audio:{...e.audio,useNarrationAliases:t}})}),(0,h.jsx)(l6,{value:e.audio.describeFigures,skipCode:e.audio.skipCode,onChange:t=>a({audio:{...e.audio,...t}})})]})]})]}):null}),e.sources.audio===`provide`?(0,h.jsxs)(`div`,{className:Y3,children:[(0,h.jsx)(q3,{field:`provided.audio`,label:`Narration file`,accept:`audio/*`,uploads:e.provided.audio===void 0?[]:[e.provided.audio],problem:i(`provided.audio`),onPick:e=>{o(`audio`,e)},onReattach:c?(e,t)=>c(`audio`,e,t):void 0,onRemove:e=>{s(`audio`,e)}}),(0,h.jsx)(`p`,{className:`mt-2 text-small text-ink-2`,children:`Uploaded narration is used as-is; include any intro and outro in that file.`})]}):null]})}function Kge({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawNumbers:c,more:l,titled:u}){return(0,h.jsxs)(X3,{kind:`images`,name:`Images`,dim:e.sources.images===`off`,titled:u,children:[(0,h.jsx)(Z3,{kind:`images`,form:e,update:i}),(0,h.jsx)(`div`,{className:J3,children:e.sources.images===`generate`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(_6,{form:e,providers:t,problem:r,update:i}),(0,h.jsx)(G3,{prompts:n.filter(e=>e.kind===`image`),...c?{rawNumbers:c}:{},picked:e.imagePrompts,problem:r,onPick:e=>{i({imagePrompts:e})}}),(0,h.jsx)(qge,{form:e,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s?{onReattachFile:s}:{}}),l]}):null}),e.sources.images===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(q3,{field:`provided.images`,label:`Slideshow images`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,numbered:!0,uploads:e.provided.images,problem:r(`provided.images`),onPick:e=>{a(`images`,e)},onReattach:s?(e,t)=>s(`images`,e,t):void 0,onRemove:e=>{o(`images`,e)}})}):null]})}function _6({form:e,providers:t,problem:n,update:r}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{field:`images.provider`,label:`Provider`,tip:`play.images.provider`,family:`image`,providers:t,value:e.images.provider,problem:n(`images`),onPick:e=>r({images:{provider:e,model:``}})}),(0,h.jsx)(tV,{field:`images.model`,label:`Model`,tip:`play.images.model`,provider:e.images.provider,value:e.images.model,problem:n(`images.model`),onPick:t=>r({images:{...e.images,model:t}})}),(0,h.jsx)(g6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:e.images,problem:n(`images.thinking`),onChange:e=>r({images:e})})]})}function qge({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsx)(h6,{value:e.reference??m6,prompts:t,problem:n,onChange:e=>r({reference:e}),upload:(0,h.jsx)(q3,{field:`provided.reference`,label:`Establishing image file`,accept:`image/png,image/jpeg`,uploads:e.provided.reference===void 0?[]:[e.provided.reference],problem:n(`provided.reference`),onPick:e=>{i(`reference`,e)},onReattach:o?(e,t)=>o(`reference`,e,t):void 0,onRemove:e=>{a(`reference`,e)}})})}var v6=5e3,Jge=[`Write a YouTube description for this video.`,``,`- Summary: a 2-3 sentence hook that says what the viewer gets from watching, in plain words, without clickbait.`,`- Chapters: split the video where the topic changes, 5-12 chapters for a long video and fewer for a short one. Chapter titles are 2-6 words, in title case, and name what that part covers.`,`- Hashtags: 3-5 hashtags about the subject, most specific last.`,`- Tags: 15-25 search terms a viewer might type to find this video, from broad to specific.`].join(`
283
- `),Yge=`Built-in`;function y6({enabled:e,prompt:t,prompts:n,narrated:r,problem:i,onChange:a}){let o=(0,m.useId)(),s=n.filter(e=>e.kind===`description`),c=t!==``&&!s.some(e=>e.name===t),l=i?.(`youtubeDescription`)??i?.(`descriptionPrompt`);return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1 self-end`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:`${o}-switch`,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${o}-switch`,type:`checkbox`,"data-play-field":`youtubeDescription`,checked:e,disabled:!r&&!e,"aria-describedby":l?`${o}-error`:void 0,className:`size-4 accent-accent`,onChange:e=>a({youtubeDescription:e.currentTarget.checked,descriptionPrompt:t})}),`YouTube description`]}),(0,h.jsx)(U,{id:`play.youtube-description`})]}),(0,h.jsx)(oV,{htmlFor:`${o}-prompt`,label:`Description prompt`,tip:`play.description-prompt`,children:(0,h.jsxs)(UB,{id:`${o}-prompt`,"data-play-field":`descriptionPrompt`,value:t,disabled:!e,onChange:t=>a({youtubeDescription:e,descriptionPrompt:t.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:Yge}),c?(0,h.jsxs)(`option`,{value:t,children:[t,` (saved choice)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`sl-fields__wide m-0 text-small text-danger`,children:l}):r?null:(0,h.jsx)(`p`,{className:`sl-fields__wide m-0 text-label text-ink-3`,children:`Needs narration.`})]})}function b6({value:e,narrated:t,imageProvider:n,problem:r,onChange:i,fieldPrefix:a=`videoEdit`,language:o}){let s=(0,m.useId)(),c=e??aA,l=e=>i({...c,...e}),{api:u}=V(),d=I(qB(u,n,c.animate!==`off`)),f=e=>r?.(`${a}.${e}`),p=[c.transition===`cut`?void 0:`${uA[c.transition]} ${String(c.transitionSeconds)} s`,c.grade===`none`?void 0:fA[c.grade],c.atmosphere===`none`?void 0:pA[c.atmosphere],c.vignette===`off`?void 0:`Vignette`,c.grain===`off`?void 0:`Grain`,c.chapterCards?`Chapter cards`:void 0,c.animate===`off`?void 0:`Animated images`].filter(e=>e!==void 0),g=[`transition`,`transitionSeconds`,`chapterCards`,`animate`,`animateEvery`,`animateModel`].map(f).filter(e=>e!==void 0),_=d.data?.models??[],v=c.animateModel!==``&&!_.some(e=>e.id===c.animateModel),y=PO(o);return{cuts:(0,h.jsxs)(x6,{id:`${s}-cuts`,label:`Cuts`,tip:`project.video.cuts`,children:[(0,h.jsx)(UB,{id:`${s}-cuts`,"data-play-field":`${a}.cuts`,className:`min-w-0`,value:y===void 0?c.cuts:`interval`,disabled:y!==void 0,"aria-describedby":y===void 0?void 0:`${s}-cuts-note`,onChange:e=>l({cuts:e.target.value}),children:$k.map(e=>(0,h.jsx)(`option`,{value:e,children:lA[e]},e))}),y===void 0?null:(0,h.jsx)(`p`,{id:`${s}-cuts-note`,className:`m-0 basis-full text-small text-ink-3`,children:y})]}),look:(0,h.jsxs)(`details`,{className:`group min-w-0 rounded-control border border-line-strong`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-10 cursor-pointer items-center gap-3 px-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Look`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-ink-3`,children:p.length===0?`Plain cuts, no effects`:p.join(` · `)})]}),(0,h.jsxs)(`div`,{className:`sl-fields border-line-strong border-t p-3`,children:[(0,h.jsxs)(x6,{id:`${s}-transition`,label:`Transition`,tip:`project.video.transition`,children:[(0,h.jsx)(UB,{id:`${s}-transition`,"data-play-field":`${a}.transition`,className:`min-w-0`,value:c.transition,onChange:e=>l({transition:e.target.value}),children:eA.map(e=>(0,h.jsx)(`option`,{value:e,children:uA[e]},e))}),(0,h.jsx)(UB,{"aria-label":`Transition length`,"data-play-field":`${a}.transitionSeconds`,"aria-invalid":f(`transitionSeconds`)!==void 0,className:`w-24 flex-none`,disabled:c.transition===`cut`,value:String(c.transitionSeconds),onChange:e=>l({transitionSeconds:Number(e.target.value)}),children:cA.map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[e,` s`]},e))})]}),(0,h.jsx)(x6,{id:`${s}-grade`,label:`Colour grade`,tip:`project.video.grade`,children:(0,h.jsx)(S6,{id:`${s}-grade`,field:`${a}.grade`,value:c.grade,options:nA,labels:fA,onChange:e=>l({grade:e})})}),(0,h.jsx)(x6,{id:`${s}-vignette`,label:`Vignette`,tip:`project.video.vignette`,children:(0,h.jsx)(S6,{id:`${s}-vignette`,field:`${a}.vignette`,value:c.vignette,options:tA,labels:dA,onChange:e=>l({vignette:e})})}),(0,h.jsx)(x6,{id:`${s}-grain`,label:`Film grain`,tip:`project.video.grain`,children:(0,h.jsx)(S6,{id:`${s}-grain`,field:`${a}.grain`,value:c.grain,options:tA,labels:dA,onChange:e=>l({grain:e})})}),(0,h.jsx)(x6,{id:`${s}-atmosphere`,label:`Atmosphere`,tip:`project.video.atmosphere`,children:(0,h.jsx)(S6,{id:`${s}-atmosphere`,field:`${a}.atmosphere`,value:c.atmosphere,options:rA,labels:pA,onChange:e=>l({atmosphere:e})})}),(0,h.jsx)(x6,{id:`${s}-cards`,label:`Chapter cards`,tip:`project.video.chapter-cards`,children:(0,h.jsx)(`input`,{id:`${s}-cards`,type:`checkbox`,"data-play-field":`${a}.chapterCards`,className:`size-4 accent-accent`,checked:c.chapterCards,disabled:!t&&!c.chapterCards,onChange:e=>l({chapterCards:e.currentTarget.checked})})}),(0,h.jsxs)(x6,{id:`${s}-animate`,label:`Animate images`,tip:`project.video.animate`,wide:!0,children:[(0,h.jsx)(UB,{id:`${s}-animate`,"data-play-field":`${a}.animate`,"aria-invalid":f(`animate`)!==void 0,className:`min-w-0`,value:c.animate,onChange:e=>l({animate:e.target.value}),children:iA.map(e=>(0,h.jsx)(`option`,{value:e,disabled:e===`chapters`&&!t,children:mA[e]},e))}),(0,h.jsx)(UB,{"aria-label":`Animate every how many images`,"data-play-field":`${a}.animateEvery`,"aria-invalid":f(`animateEvery`)!==void 0,className:`w-24 flex-none`,disabled:c.animate!==`every`,value:String(c.animateEvery),onChange:e=>l({animateEvery:Number(e.target.value)}),children:Array.from({length:9},(e,t)=>t+2).map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[`every `,e]},e))}),(0,h.jsxs)(UB,{"aria-label":`Image-to-video model`,"data-play-field":`${a}.animateModel`,"aria-invalid":f(`animateModel`)!==void 0,className:`min-w-0`,disabled:c.animate===`off`,value:c.animateModel,onChange:e=>l({animateModel:e.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a model`}),v?(0,h.jsxs)(`option`,{value:c.animateModel,children:[c.animateModel,` (saved choice)`]}):null,_.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),g.length>0?(0,h.jsx)(`p`,{className:`col-span-full text-small text-danger`,children:g[0]}):c.animate!==`off`&&d.isSuccess&&_.length===0?(0,h.jsx)(`p`,{className:`col-span-full text-label text-ink-3`,children:`This image provider has no image-to-video models. Choose fal.ai or Replicate for images to animate them.`}):null]})]})}}function x6({id:e,label:t,tip:n,wide:r=!1,children:i}){return(0,h.jsxs)(`div`,{className:z(`sl-field`,r&&`sl-fields__wide`),...zb,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),(0,h.jsx)(U,{id:n,label:t.toLowerCase()})]}),(0,h.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-start gap-2 [&>select]:min-w-0 [&>select]:flex-1`,children:i})]})}function S6({id:e,field:t,value:n,options:r,labels:i,onChange:a}){return(0,h.jsx)(UB,{id:e,"data-play-field":t,className:`min-w-0`,value:n,onChange:e=>a(e.target.value),children:r.map(e=>(0,h.jsx)(`option`,{value:e,children:i[e]},e))})}var Xge=XD(`kind`,[Y({kind:oO(`upload`),stagedFileId:K().regex(/^[A-Za-z0-9_-]{1,64}$/)}),Y({kind:oO(`output`),outputId:K().regex(/^[A-Za-z0-9_-]{1,64}$/)}),Y({kind:oO(`picture`),sha256:K().regex(/^[a-f0-9]{64}$/)})]),C6=Y({format:X(GS),subtitles:Y({mode:X(aM),fontId:K().max(160).regex(/^[A-Za-z0-9_-]+$/),fontSize:q().finite().min(16).max(120),position:X(oM)}),videoEdit:fM.optional(),previewText:K().max(200).optional(),image:Xge.optional(),shorts:Y({titleOnScreen:RD(),speed:q().finite().min(1).max(1.25).optional(),title:K().max(100).optional()}).optional(),force:RD().optional()}),Zge=Y({hash:K().regex(/^[a-f0-9]{64}$/),url:K().min(1),cached:RD(),seconds:q().positive()});async function Qge(e,t,n){let r=await e.fetch(`${e.origin}/api/style-preview`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),...n===void 0?{}:{signal:n}});if(!r.ok)throw await co(r);let i=yo(Zge,await r.json());return{...i,src:`${e.origin}${i.url}`}}var $ge=600;function w6({settings:e,label:t,drawnOn:n,poster:r}){let{api:i}=V(),a=I({queryKey:eN,queryFn:()=>tN(i),staleTime:6e4}),{format:o,subtitles:s,videoEdit:c,previewText:l,image:u,shorts:d}=e,f=r??(u?.kind===`picture`?xx(i,u.sha256):void 0),p=u===void 0?``:JSON.stringify(u),g=d===void 0?``:JSON.stringify(d),_=(0,m.useMemo)(()=>JSON.stringify({format:o,subtitles:{mode:s.mode,fontId:s.fontId,fontSize:s.fontSize,position:s.position},...c===void 0?{}:{videoEdit:c},...l===void 0||l.trim()===``?{}:{previewText:l},...p===``?{}:{image:JSON.parse(p)},...g===``?{}:{shorts:JSON.parse(g)}}),[o,s.mode,s.fontId,s.fontSize,s.position,c,l,p,g]),v=(0,m.useMemo)(()=>C6.safeParse(JSON.parse(_)).success,[_]),[y,b]=(0,m.useState)({kind:`idle`}),[x,S]=(0,m.useState)(void 0),C=(0,m.useRef)(void 0),w=(0,m.useCallback)(async e=>{C.current?.abort();let t=new AbortController;C.current=t,b({kind:`pending`});try{let n=await Qge(i,{...C6.parse(JSON.parse(_)),...e?{force:e}:{}},t.signal);if(C.current!==t)return;S(n.src),b({kind:`ready`,src:n.src})}catch(e){if(C.current!==t||t.signal.aborted)return;b({kind:`failed`,message:e instanceof Error&&e.message!==``?e.message:`The style preview couldn't render. Press Render again.`})}},[i,_]);(0,m.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>{w(!1)},$ge);return()=>clearTimeout(e)},[w,v]),(0,m.useEffect)(()=>()=>C.current?.abort(),[]);let T=a.data?.fonts.find(e=>e.id===s.fontId)?.name??(s.fontId==="default"?`Barlow`:`Chosen font`),E=d===void 0?s.mode===`burn-in`?`Captions: ${T} ${String(s.fontSize)} · ${e_e(s.position)}`:s.mode===`files`?`Captions: a separate file, which players show in their own style`:`Captions: off`:[`Captions: ${T}, word by word`,d.titleOnScreen?`Title on screen`:`No title on screen`,d.speed===void 0||d.speed===1?void 0:`${d.speed.toFixed(2)}×`].filter(e=>e!==void 0).join(` · `),D=d===void 0?`Style preview`:`Shorts preview`,O=o===`9:16`||d!==void 0;return(0,h.jsxs)(`section`,{"aria-label":D,className:`min-w-0 space-y-3`,children:[(0,h.jsx)(W,{as:`h3`,title:D,meta:d===void 0?`6 seconds of the sample, rendered with your settings`:`A few seconds of the sample as a short, rendered with your settings`,info:d===void 0?`project.video.style-preview`:`play.shorts.preview`,children:(0,h.jsxs)(B,{variant:`quiet`,size:`small`,disabled:!v||y.kind===`pending`,disabledReason:v?`Rendering the preview…`:`Fix the caption settings to render the preview.`,onClick:()=>{w(!0)},children:[(0,h.jsx)(qc,{"aria-hidden":`true`,size:16,strokeWidth:1.75}),`Render again`]})}),x===void 0?null:(0,h.jsx)(c0,{src:x,label:t??D,...f===void 0?{}:{poster:f},portrait:O,square:!O&&o===`1:1`,className:O?`max-w-[270px]`:o===`1:1`?`max-w-[360px]`:`max-w-[480px]`}),y.kind===`pending`?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Rendering the preview…`}):null,y.kind===`failed`?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:y.message}):null,v?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The preview renders again once the caption size is between 16 and 120.`}),(0,h.jsxs)(`p`,{className:`text-small text-ink-2`,children:[E,u===void 0||n===void 0?``:` · Drawn on ${n}`]})]})}function e_e(e){let t=e.replace(/-/g,` `);return`${t[0]?.toUpperCase()??``}${t.slice(1)}`}function t_e({form:e,problem:t,update:n,onPickFiles:r,onRemoveFile:i,onReattachFile:a}){let o=e.provided.ambientBed;return(0,h.jsx)(s2,{value:e.ambientBed,inherit:`The channel's (brand kit)`,sources:Gk,offerNone:!0,problem:e=>t(`ambientBed.${e}`),file:(0,h.jsx)(q3,{field:`ambientBed.file`,label:`Ambient sound file: an audio file, looped if shorter than the video`,accept:`audio/*`,uploads:o===void 0?[]:[o],problem:t(`ambientBed.file`),onPick:e=>r(`ambientBed`,e),onReattach:a?(e,t)=>a(`ambientBed`,e,t):void 0,onRemove:e=>i(`ambientBed`,e)}),onChange:e=>n({ambientBed:e})})}function T6({value:e,onChange:t,problem:n,switchTip:r=`project.loudness`,switchLabel:i=`Level the volume`}){return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[(0,h.jsx)(Bb,{checked:e.enabled,label:i,tip:r,onChange:n=>t({...e,enabled:n})}),e.enabled?(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(D6,{target:`video`,label:`Video volume`,tip:`project.loudness.video`,lufs:e.videoLufs,error:n?.(`videoLufs`),onChange:n=>t({...e,videoLufs:n})}),(0,h.jsx)(D6,{target:`audioFiles`,label:`Audio files volume`,tip:`project.loudness.audio-files`,lufs:e.audioFilesLufs,error:n?.(`audioFilesLufs`),onChange:n=>t({...e,audioFilesLufs:n})})]}):null]})}var n_e=`Enter a volume between ${O6(-10)} dB and ${O6(4)} dB (${String(tk(-10))}% to ${String(tk(4))}%).`;function E6(e,t){let n=e.trim().replace(`−`,`-`).replace(`,`,`.`);if(n===``)return;let r=Number(n.replace(/(dB|%)$/i,``).trim());if(!Number.isFinite(r)||t===`percent`&&r<=0)return;let i=t===`db`?r:nk(r);if(!(i<-10.25||i>4.25))return rk(i)}function D6({target:e,label:t,tip:n,lufs:r,error:i,onChange:a}){let o=(0,m.useId)(),s=$O(r,e),[c,l]=(0,m.useState)(),u=c===void 0||E6(c.text,c.unit)!==void 0,d=(t,n)=>{l({unit:t,text:n});let r=E6(n,t);r!==void 0&&a(ek(r,e))},f=c?.unit===`db`?c.text:O6(s),p=c?.unit===`percent`?c.text:String(tk(s));return(0,h.jsx)(LB,{label:t,tip:n,help:`0 dB is the recommended ${k6(ZO(e))} LUFS; this is ${k6(r)} LUFS. Peaks stay under ${k6(QO(e))} dBTP.`,error:u?i:n_e,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(zB,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`loudness.${e===`video`?`videoLufs`:`audioFilesLufs`}`,value:f,onChange:e=>d(`db`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`dB`}),(0,h.jsx)(zB,{id:`${o}-percent`,"aria-label":`${t} as a percentage of the recommended level`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:p,onChange:e=>d(`percent`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`%`})]})})}function O6(e){return e>0?`+${String(e)}`:k6(e)}function k6(e){return String(e).replace(`-`,`−`)}function A6({sentence:e,paragraph:t,problem:n,onChange:r}){let i=`0 to 2 in steps of ${String(fk)}`;return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(LB,{label:`Pause between sentences (seconds)`,tip:`project.pause.sentence`,help:`${i}; ${String(dk)} is the default. 0 leaves the voice's own.`,error:n(`sentencePauseSeconds`),children:(0,h.jsx)(zB,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`sentencePauseSeconds`,value:e,onChange:e=>r(`sentencePauseSeconds`,e.target.value)})}),(0,h.jsx)(LB,{label:`Pause between paragraphs (seconds)`,tip:`project.pause.paragraph`,help:`${i}; 0 (the default) keeps the sentence pause.`,error:n(`paragraphPauseSeconds`),children:(0,h.jsx)(zB,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`paragraphPauseSeconds`,value:t,onChange:e=>r(`paragraphPauseSeconds`,e.target.value)})})]})}function j6(e){let t=e.trim().replace(`,`,`.`);if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function r_e({form:e,problem:t,update:n}){let{api:r}=V(),i=I(_b(r)).data?.loudness??JO,a=e.loudness;return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[e.sources.audio===`generate`?(0,h.jsx)(A6,{sentence:e.sentencePause??`0.4`,paragraph:e.paragraphPause??`0`,problem:t,onChange:(e,t)=>n(e===`sentencePauseSeconds`?{sentencePause:t}:{paragraphPause:t})}):null,(0,h.jsx)(T6,{value:{enabled:a?.enabled??i.enabled,videoLufs:a?.videoLufs??i.videoLufs,audioFilesLufs:a?.audioFilesLufs??i.audioFilesLufs},problem:e=>t(`loudness.${e}`),onChange:e=>n({loudness:e})})]})}function M6({value:e,onPick:t,disabled:n=!1}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,...zb,children:[(0,h.jsx)(K4,{id:r,className:`shrink-0`,children:`Thumbnails`}),(0,h.jsxs)(q4,{type:`single`,value:String(e),"aria-labelledby":r,disabled:n,"data-play-field":`thumbnailCount`,onValueChange:e=>{(e===`1`||e===`3`)&&t(e===`3`?3:1)},children:[(0,h.jsx)(J4,{value:`1`,children:`1`}),(0,h.jsx)(J4,{value:`3`,children:`3`})]}),(0,h.jsx)(U,{id:`play.thumbnail-count`})]})}function i_e({form:e,problem:t,update:n}){return(0,h.jsxs)(X3,{kind:`research`,name:`Research`,dim:e.sources.research===`off`,children:[(0,h.jsx)(Z3,{kind:`research`,form:e,update:n}),(0,h.jsx)(`div`,{className:J3,children:e.sources.research===`generate`?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:`Runs through the LLM, one agent per chapter`}):null}),e.sources.research===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(K3,{field:`provided.research`,label:`Research notes`,tip:`play.provided.research`,value:e.provided.research,placeholder:`Paste the notes the article will be written from.`,problem:t(`provided.research`),onChange:t=>{n({provided:{...e.provided,research:t}})}})}):null]})}function a_e({form:e,prompts:t,problem:n,update:r,titled:i}){return(0,h.jsxs)(X3,{kind:`article`,name:`Article`,dim:!1,titled:i,children:[(0,h.jsx)(Z3,{kind:`article`,form:e,update:r}),(0,h.jsx)(`div`,{className:`${Y3} grid gap-4`,children:e.sources.article===`generate`?(0,h.jsx)(ZB,{field:`articlePrompt`,label:IA(e)?`Script prompt`:`Article prompt`,tip:`play.article-prompt`,value:e.articlePrompt,placeholder:`Pick a prompt`,options:Q3(t,k1(e)),problem:n(`articlePrompt`),onPick:e=>{r({articlePrompt:e})}}):null}),e.sources.article===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(K3,{field:`provided.article`,label:`Article text`,tip:`play.provided.article`,value:e.provided.article,placeholder:`Paste the article that will be narrated.`,problem:n(`provided.article`),onChange:t=>{r({provided:{...e.provided,article:t}})}})}):null]})}function o_e({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s}){let c=e.sources.thumbnail===`from_prompt`||e.sources.thumbnail===`prompt_by_llm`;return(0,h.jsxs)(X3,{kind:`thumbnail`,name:`Thumbnail`,dim:e.sources.thumbnail===`off`,children:[(0,h.jsx)(Z3,{kind:`thumbnail`,form:e,update:i}),(0,h.jsxs)(`div`,{className:J3,children:[c&&e.sources.images!==`generate`?(0,h.jsx)(_6,{form:e,providers:t,problem:r,update:i}):null,c?(0,h.jsx)(ZB,{field:`thumbnailPrompt`,label:`Thumbnail prompt`,tip:`play.thumbnail-prompt`,value:e.thumbnailPrompt,placeholder:`Pick a prompt`,options:Q3(n,`thumbnail`),problem:r(`thumbnailPrompt`),onPick:e=>{i({thumbnailPrompt:e})}}):null,c?(0,h.jsx)(M6,{value:e.thumbnailCount===3?3:1,onPick:e=>{i({thumbnailCount:e})}}):null]}),e.sources.thumbnail===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(q3,{field:`provided.thumbnail`,label:`Thumbnail image`,accept:`image/png,image/jpeg,image/webp`,uploads:e.provided.thumbnail===void 0?[]:[e.provided.thumbnail],problem:r(`provided.thumbnail`),onPick:e=>{a(`thumbnail`,e)},onReattach:s?(e,t)=>s(`thumbnail`,e,t):void 0,onRemove:e=>{o(`thumbnail`,e)}})}):null]})}function s_e({form:e,prompts:t,silenceGapSeconds:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawTiming:c,extras:l=!0,language:u,titled:d}){let f=e.sources.video===`generate`?e.sources.audio===`off`?`Silent video · each image shown once`:`Images and narration · ${String(n)} s segment gaps`:e.sources.audio===`off`?`Download each enabled stage separately`:`Combined WAV export with narration and segment gaps`,p=t=>({value:c?c[t]:Number.isFinite(e[t])?String(e[t]):``,onChange:e=>{c?c.onChange(t,e):i({[t]:e.trim()===``?NaN:Number(e)})}}),m=b6({value:e.videoEdit,narrated:e.sources.audio!==`off`,imageProvider:e.images.provider,problem:r,language:u??e.language,onChange:e=>i({videoEdit:e})});return(0,h.jsxs)(X3,{kind:`video`,name:`Export`,dim:e.sources.video===`off`,titled:d,children:[(0,h.jsx)(Z3,{kind:`video`,form:e,update:i}),(0,h.jsx)(`span`,{className:J3,children:(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:f})}),e.sources.video===`generate`||e.sources.audio!==`off`?(0,h.jsxs)(`div`,{className:J3,children:[e.sources.video===`generate`?(0,h.jsx)(P6,{field:`imageSeconds`,label:`Seconds per image`,tip:`play.image-seconds`,step:1,problem:r(`imageSeconds`),...p(`imageSeconds`)}):null,e.sources.video===`generate`?(0,h.jsx)(P6,{field:`zoomPercent`,label:`Zoom (%)`,tip:`play.zoom`,step:.5,problem:r(`zoomPercent`),...p(`zoomPercent`)}):null,e.sources.video===`generate`?(0,h.jsx)(XB,{label:`Motion`,tip:`play.motion`,problem:void 0,children:({id:t})=>(0,h.jsx)(UB,{id:t,"data-play-field":`motionStyle`,className:`w-full`,value:e.motionStyle,onChange:e=>i({motionStyle:e.target.value}),children:XS.map(e=>(0,h.jsx)(`option`,{value:e,children:HA[e]},e))})}):null,e.sources.video===`generate`?m.cuts:null,e.sources.audio===`off`?null:(0,h.jsx)(P6,{field:`edgeSilenceSeconds`,label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,step:.5,problem:r(`edgeSilenceSeconds`),...p(`edgeSilenceSeconds`)})]}):null,e.sources.video===`generate`?(0,h.jsx)(`div`,{className:Y3,children:m.look}):null,e.sources.video===`generate`&&e.sources.audio!==`off`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(t_e,{form:e,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s})}):null,e.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(r_e,{form:e,problem:r,update:i})}),l?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(N6,{form:e,prompts:t,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s===void 0?{}:{onReattachFile:s}})}):null,e.sources.images===`off`?(0,h.jsx)(`p`,{className:`${Y3} text-small text-ink-2`,children:`Video is Off because Images is Off. Generate or provide images to enable video.`}):null]})}function N6({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[e.sources.audio===`generate`&&e.audio.describeFigures===!0?(0,h.jsx)(u6,{value:e.showFigures,onChange:e=>r({showFigures:e})}):null,e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(y6,{enabled:e.youtubeDescription===!0,prompt:e.descriptionPrompt??``,prompts:t,narrated:e.sources.audio!==`off`,problem:n,onChange:e=>r(e)})}),e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(dV,{value:e.shorts??sV,prompts:t,narrated:e.sources.audio!==`off`,problem:n,musicName:e.provided.shortsMusic?.name,music:(0,h.jsxs)(`div`,{className:`basis-full`,children:[(0,h.jsx)(q3,{field:`shorts.music`,label:`Background music (optional): an audio file, looped if shorter than a short`,accept:`audio/*`,disabled:!wN(e),uploads:e.provided.shortsMusic===void 0?[]:[e.provided.shortsMusic],problem:n(`shorts.music`),onPick:e=>i(`shortsMusic`,e),onReattach:o?(e,t)=>o(`shortsMusic`,e,t):void 0,onRemove:e=>a(`shortsMusic`,e)}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:`Plays at the volume above under every short and dips while the narrator speaks.`})]}),preview:(0,h.jsx)(w6,{settings:cV(e.shorts??sV,e.subtitles.fontId)}),onChange:e=>r({shorts:e})})})]})}function P6({field:e,label:t,tip:n,placeholder:r,step:i,problem:a,value:o,onChange:s}){return(0,h.jsx)(XB,{label:t,tip:n,problem:a,children:({id:t,describedBy:n})=>(0,h.jsx)(zB,{id:t,"data-play-field":e,type:`text`,inputMode:i<1?`decimal`:`numeric`,className:`sl-input--number`,"aria-invalid":a!==void 0,"aria-describedby":n,placeholder:r,value:o,onChange:e=>s(e.target.value)})})}function c_e({form:e,update:t}){let n=e.sources.document===`off`;return(0,h.jsxs)(X3,{kind:`document`,name:`Document`,dim:n,children:[(0,h.jsx)(Z3,{kind:`document`,form:e,update:t}),(0,h.jsx)(`div`,{className:J3,children:(0,h.jsx)(XB,{label:`Theme`,tip:`play.document-theme`,problem:void 0,children:({id:r})=>(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(V3,{id:r,field:`document.theme`,className:`w-auto min-w-[120px]`,disabled:n,value:e.document,onChange:e=>{t({document:e})}}),(0,h.jsx)(fa,{to:`/document-themes`,className:`text-small text-accent-ink underline`,children:`Edit themes`})]})})})]})}function l_e({form:e,providers:t,problem:n,update:r,uses:i,onSettings:a}){let o=[...new Set(i.map(e=>e.label))],s=o.length<=1?o[0]??``:`${o.slice(0,-1).join(`, `)} and ${o.at(-1)??``}`;return(0,h.jsxs)(`section`,{"aria-label":`Text generation`,className:`border-y border-line py-4`,children:[(0,h.jsx)(W,{as:`h3`,title:`Text generation`,meta:`Used for ${s}.`,info:`play.text-generation`,className:`pb-3`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:a,children:`Settings`})}),(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(eV,{field:`llm.provider`,label:`LLM`,tip:`play.llm.provider`,family:`llm`,providers:t,value:e.llm.provider,problem:n(`llm.provider`)??(e.llm.provider===``?n(`llm`):void 0),onPick:e=>r({llm:{provider:e,model:``}})}),(0,h.jsx)(tV,{field:`llm.model`,label:`Text model`,tip:`play.llm.model`,provider:e.llm.provider,value:e.llm.model,problem:n(`llm.model`)??(e.llm.provider!==``&&n(`llm`)?`Pick a text model.`:void 0),onPick:t=>r({llm:{...e.llm,model:t}})}),(0,h.jsx)(g6,{choice:e.llm,onChange:e=>r({llm:e})})]})]})}function F6({section:e,entries:t,...n}){let r=kN(n.form,t);return r[0]?.section===e?(0,h.jsx)(l_e,{...n,uses:r}):null}function u_e(e){let{form:t,onLibrary:n}=e,r=e.prompts.find(e=>e.kind===k1(t)&&e.name===t.articlePrompt);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(a_e,{...e,titled:!1}),t.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3 py-3`,children:[r?(0,h.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`summary`,{"data-play-field":`articlePrompt.preview`,className:`cursor-pointer py-2 text-small text-accent-ink`,children:`View prompt`}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words py-3 font-sans text-body text-ink-2`,children:r.body})]}):(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.prompts.some(e=>e.kind===k1(t))?`Choose a saved ${k1(t)} prompt.`:`No ${k1(t)} prompts saved. Create a prompt to begin.`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>n(`/prompts`),children:`Create prompt`})]}):(0,h.jsxs)(`p`,{className:`py-3 text-small text-ink-3`,children:[t.provided.article.trim()?t.provided.article.trim().split(/\s+/).length:0,` `,`words · `,t.provided.article.length,` characters`]}),(0,h.jsx)(F6,{...e,section:`article`,onSettings:()=>n(`/settings`)}),t.sources.article===`off`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`No article: for a project of images or a thumbnail made from prompts. Narration, the PDF and anything else that reads the article stay off.`}):t.sources.article===`provide`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`Research is Off because the article is provided.`}):(0,h.jsx)(i_e,{...e})]})}function d_e(){let{api:e}=V(),t=XN(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=Ry(),u=I({queryKey:[`play-drafts`],queryFn:async()=>{let t=await WM(e);if(!t.ok)throw Error(t.message);return t.value.drafts}}),d=async()=>{if(!r||s)return;let e=r.id;c(!0),o(null);try{await t.discard({id:r.id,version:r.version}),i(null),await n.cancelQueries({queryKey:[`play-drafts`]}),n.setQueryData([`play-drafts`],t=>t?.filter(t=>t.id!==e))}catch(e){let t=e instanceof Error?e.message:`The draft wasn't discarded. Try again.`;o(t),l(t,`error`)}finally{c(!1)}};return(0,h.jsxs)(`section`,{"aria-label":`Drafts`,className:`flex min-w-0 flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(`p`,{role:`status`,className:z(`engraved min-w-[112px] text-right`,t.status===`saved`?`text-accent-ink`:t.status===`error`||t.status===`conflict`?`text-danger`:`text-ink-3`),children:{unsaved:`Unsaved`,saving:`Saving…`,saved:`Saved`,error:`Couldn't save`,conflict:`Changed elsewhere`}[t.status]}),t.status===`error`?(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{!t.view&&t.activeId&&t.edited===0?t.open(t.activeId):t.flush()},children:`Retry`}):null,t.status===`conflict`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{t.activeId&&t.open(t.activeId)},children:`Reload saved draft`}),(0,h.jsx)(B,{variant:`quiet`,onClick:()=>void t.saveAsNew(),children:`Save as a new draft`}),(0,h.jsx)(U,{id:`play.draft-conflict`})]}):null,(0,h.jsxs)(Nb,{children:[(0,h.jsx)(Pb,{asChild:!0,children:(0,h.jsxs)(B,{variant:`quiet`,children:[`Drafts`,(0,h.jsx)(Cc,{"aria-hidden":`true`,className:`size-4`})]})}),(0,h.jsxs)(Lb,{align:`end`,className:`w-[340px] p-0`,"aria-label":`Saved drafts`,children:[u.isPending?(0,h.jsx)(`p`,{role:`status`,className:`px-3 py-2`,children:`Loading drafts…`}):null,u.error?(0,h.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:[u.error.message,` `,(0,h.jsx)(B,{variant:`quiet`,onClick:()=>void u.refetch(),children:`Retry`})]}):null,u.data?.length===0?(0,h.jsx)(`p`,{className:`px-3 py-2`,children:`No saved drafts`}):null,a?(0,h.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:a}):null,u.data?.length?(0,h.jsx)(PH,{label:`Saved drafts`,className:`max-h-72 overflow-y-auto border-t-0`,children:u.data.map(e=>(0,h.jsx)(FH,{title:e.title||`Untitled draft`,onSelect:()=>void t.open(e.id),meta:(0,h.jsxs)(`time`,{dateTime:e.updatedAt,children:[`Last edited `,Wu(e.updatedAt)]}),actions:(0,h.jsx)(Py,{size:`small`,label:`Discard ${e.title||`Untitled draft`}`,onClick:()=>{i(e),o(null)},children:(0,h.jsx)($c,{"aria-hidden":`true`})}),children:e.readable?null:(0,h.jsx)(`p`,{className:`m-0 text-label text-waiting`,children:`Unsupported or corrupt draft. Try opening it to recover, or discard it.`})},e.id))}):null]})]}),(0,h.jsx)(B,{onClick:()=>void t.newDraft(),children:`New draft`}),(0,h.jsx)(U,{id:`play.drafts`}),(0,h.jsx)(Hy,{open:r!==null,title:`Discard ${r?.title||`Untitled draft`}?`,consequence:`The draft is removed. This cannot be undone.`,confirmLabel:`Discard draft`,pending:s,onConfirm:()=>void d(),onCancel:()=>{s||i(null)}})]})}function I6(e,t){let n=[...e.querySelectorAll(`[data-play-field]`)].find(e=>e.dataset.playField===t);if(!n||n.hasAttribute(`disabled`))return!1;let r=n.closest(`details`);return r!==null&&!r.open&&(r.open=!0),n.focus(),n.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`instant`}),document.activeElement===n}function f_e(e,t,n,r=[]){let i=e;if(e===`fontUpload`&&(i=`subtitles.fontUpload`),/^provided\.images\.\d+$/.test(e)&&(i=`provided.images`),e===`subtitles`&&(i=`subtitles.mode`),e===`chunking`&&(i=`chunking.mode`),[`audio`,`llm`,`images`].includes(e)&&(i=`${e}.provider`),e===`provided`){let e=[`audio`,`images`,`thumbnail`].find(e=>t.sources[e]===`provide`&&(e===`images`?t.provided.images:[t.provided[e]]).some(e=>e&&(e.error!==void 0||e.file===void 0))),n=t.provided.shortsMusic;i=e===void 0&&wN(t)&&n!==void 0&&(n.error!==void 0||n.file===void 0)?`shorts.music`:t.reference?.source===`provide`&&t.provided.reference!==void 0&&(t.provided.reference.error!==void 0||t.provided.reference.file===void 0)?`provided.reference`:`provided.${e??`audio`}`;let r=t.provided.ambientBed;e===void 0&&TN(t)&&r!==void 0&&(r.error!==void 0||r.file===void 0)&&(i=`ambientBed.file`)}let a=/^imagePrompts\.(\d+)\.(.+)$/.exec(e);if(a){let e=t.imagePrompts[Number(a[1])];e&&(i=`imagePrompts.${e.name}.${a[2]}`)}e===`imagePrompts`&&(i=t.imagePrompts[0]?`imagePrompts.${t.imagePrompts[0].name}.number`:`imagePrompts`);let o=/^variants\.(\d+)\.(.+)$/.exec(e);o&&(i=`items.${n[Number(o[1])]?.key??o[1]}.${o[2]}`);let s=/^items\.(\d+)\.(.+)$/.exec(e);s&&(i=Number(s[1])===0?s[2]??e:`items.${n[Number(s[1])-1]?.key??s[1]}.${s[2]}`);let c=t=>t.some(t=>e===t||e.startsWith(`${t}.`));return{section:c([`title`,`articlePrompt`,`provided.article`,`provided.research`,`sources.article`,`sources.research`,...(kN(t,r)[0]?.section??`article`)===`article`?[`llm`]:[],`values`])?`content`:c([`format`,`subtitles`,`fontUpload`])?`style`:c(`audio,narrationPrompt,voices,provided.audio,intro,outro,chunking,images,imagePrompts,imageScale,provided.images,thumbnailPrompt,provided.thumbnail,provided.reference,reference,provided,sources,imageSeconds,zoomPercent,motionStyle,edgeSilenceSeconds,document,youtubeDescription,descriptionPrompt,shorts,videoEdit,ambientBed,loudness,sentencePauseSeconds,paragraphPauseSeconds,llm`.split(`,`))?`outputs`:`review`,field:i}}function p_e({fields:e,values:t,origins:n,topics:r=[],hide:i=[],problem:a,onChange:o}){let s=e.filter(e=>!i.includes(e.name));return s.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-3 text-small text-ink-2`,children:`Each keyword is entered once and fills every place that names it.`}),(0,h.jsx)(V1,{keywords:s.map(e=>({name:e.name,value:Object.hasOwn(t,e.name)?t[e.name]??``:``,feeds:n?.get(e.name)??[],topic:r.includes(e.name)})),problem:a,onChange:o})]}):null}var m_e={every:`minutes`,value:`2`};function h_e({document:e,problem:t,onEdit:n}){let r=(0,m.useId)(),{form:i}=e,a=i.imageScale,o=t(`imageScale.value`)??t(`imageScale`),s=a===void 0?void 0:o===void 0?__e(e):{text:o,problem:!0},c=t=>{let{imageScale:r,...o}=i;n({...e,form:{...o,...t===void 0?{}:{imageScale:t},...t!==void 0&&a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})};return(0,h.jsxs)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:[(0,h.jsx)(Bb,{checked:a!==void 0,label:`More images for long videos`,tip:`play.image-scale`,describedBy:`${r}-line`,onChange:e=>c(e?m_e:void 0)}),a===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,...zb,children:[(0,h.jsx)(Vb,{label:`How the rate is given`,tip:`play.image-scale.rate`,value:a.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>c({every:e,value:g_e(a.value,a.every,e)})}),a.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(zB,{id:`${r}-value`,"data-play-field":`imageScale.value`,"aria-label":a.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`sl-input--number`,"aria-invalid":s?.problem===!0,"aria-describedby":`${r}-line`,value:a.value,onChange:e=>c({every:a.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:a.every===`minutes`?`minutes`:`images per hour`})]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:s.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:s.text})]})}function g_e(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function __e(e){let{form:t}=e,n=t.imageScale;if(n===void 0)return{text:``,problem:!1};let r=Number(n.value.trim()),i=n.every===`minutes`;if(!(n.value.trim()!==``&&(i?r>=.25&&r<=60:r>=1&&r<=240)))return{text:i?`Enter a number of minutes between ${String(IO)} and 60.`:`Enter a number of images per hour between 1 and 240.`,problem:!0};let a=i?HO(r):r,o=t.sources.article===`provide`,s=Number(e.expectedWords.trim()),c=o?Math.max(1,BO(t.provided.article)):Number.isInteger(s)&&s>=1&&s<=1e5?s:RO,l=t.imagePrompts.map(e=>({name:e.name,number:Math.max(0,Number.parseInt(e.number,10)||0)})),u=l.reduce((e,t)=>e+t.number,0),d={perHour:a,words:c},f=KO({imagePrompts:l,imageScale:d,sources:t.sources}).reduce((e,t)=>e+t,0),p=`about ${String(Math.max(1,Math.round(VO(c))))} minutes (${c.toLocaleString(`en-US`)} words ${o?`in the article`:`expected, set on Review`})`;if(l.length===0)return{text:`For ${p}: tick an image prompt to see the count.`,problem:!1};let m=WO(d)>=240?` That is the most a run makes (240); the images repeat after that.`:``;return{text:f>u?`For ${p}: ${String(f)} images, ${String(f-u)} more than the prompts' ${String(u)}.${m}`:`For ${p}: the prompts' ${String(u)} images already cover it.`,problem:!1}}function v_e({document:e,onEdit:t}){let{form:n}=e;return(0,h.jsx)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:(0,h.jsx)(Bb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,form:{...a,...r?{imageScenes:!0}:{}}})}})})}function y_e(e){return e.upload?(0,h.jsx)(L6,{value:e.value,onPick:e.onPick,upload:e.upload}):(0,h.jsx)(b_e,{...e})}function b_e({value:e,onPick:t,onUploading:n}){let{api:r}=V(),i=_(),a=L({mutationFn:e=>nN(r,e),onSuccess:({font:e})=>{i.setQueryData(eN,t=>({fonts:[...(t?.fonts??[]).filter(t=>t.id!==e.id),e]})),i.invalidateQueries({queryKey:eN})}}),o=a.isPending,s=(0,m.useRef)(t);s.current=t;let c=(0,m.useRef)(n);return c.current=n,(0,m.useEffect)(()=>{c.current(o)},[o]),(0,m.useEffect)(()=>()=>c.current(!1),[]),(0,h.jsx)(L6,{value:e,onPick:t,upload:{pending:o,error:a.error?.message,pick:e=>a.mutate(e,{onSuccess:({font:e})=>s.current(e.id)})}})}function L6({value:e,onPick:t,upload:n}){let{api:r}=V(),i=(0,m.useId)(),a=(0,m.useId)(),o=I({queryKey:eN,queryFn:()=>tN(r),staleTime:6e4}),s=n.pending,c=o.data?.fonts??[],l=e!=="default"&&!c.some(t=>t.id===e);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:i,children:`Subtitle font`}),(0,h.jsx)(U,{id:`project.subtitles.font`,className:`-my-1`})]}),(0,h.jsxs)(VB,{id:i,"data-play-field":`subtitles.fontId`,value:e,disabled:s,onChange:e=>t(e.target.value),className:`text-small`,children:[c.some(e=>e.id==="default")?null:(0,h.jsx)(`option`,{value:`default`,children:`Default font · bundled`}),l?(0,h.jsxs)(`option`,{value:e,children:[e,` · saved font`]}):null,c.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.source]},e.id))]})]}),(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,children:[(0,h.jsx)(K4,{htmlFor:a,className:`mb-1`,children:`Upload font (.ttf or .otf)`}),(0,h.jsx)(`input`,{id:a,"data-play-field":`subtitles.fontUpload`,type:`file`,accept:`.ttf,.otf,font/ttf,font/otf`,disabled:s,className:`w-full text-small text-ink-2 file:mr-2 file:rounded-control file:border file:border-line-strong file:bg-sunken file:px-2 file:py-1 file:text-ink`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&n.pick(t)}})]})]}),s?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Uploading font…`}):null,n.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:n.error}):null,l&&o.data?(0,h.jsx)(`p`,{role:`alert`,children:`Saved font is unavailable. Choose another font or upload it again.`}):null,o.error?(0,h.jsxs)(`p`,{role:`alert`,className:`text-small text-danger`,children:[`The font list couldn't be loaded. `,o.error.message]}):null]})}function x_e(e){return e===`9:16`?{width:1080,height:1920}:e===`1:1`?{width:1080,height:1080}:{width:1920,height:1080}}function S_e(e,t){switch(e){case`top`:return{y:60,alignment:8,translateY:0};case`upper-middle`:return{y:t/4,alignment:5,translateY:-50};case`center`:return{y:t/2,alignment:5,translateY:-50};case`lower-middle`:return{y:t*3/4,alignment:5,translateY:-50};case`bottom`:return{y:t-60,alignment:2,translateY:-100}}}function C_e({value:e,format:t,sample:n=`Every story begins with a word.`,backgroundUrl:r,showCaptions:i=!0,maxFrameHeight:a}){let{api:o}=V(),s=rN(o,e.fontId),c=`subtitle-preview-${(0,m.useId)().replace(/[^a-zA-Z0-9]/g,``)}`,[l,u]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(typeof FontFace>`u`||!document.fonts)return;let e=!0,t=new FontFace(c,`url(${JSON.stringify(s)})`);return u(!1),t.load().then(t=>{e&&document.fonts.add(t)}).catch(()=>{e&&u(!0)}),()=>{e=!1,document.fonts.delete(t)}},[c,s]);let d=x_e(t),f=S_e(e.position??`bottom`,d.height),p=Number.isFinite(e.fontSize)?Math.max(16,Math.min(120,e.fontSize)):48,g={position:`absolute`,left:`50%`,top:`${f.y/d.height*100}%`,width:`${(d.width-120)/d.width*100}%`,transform:`translate(-50%, ${f.translateY}%)`,fontFamily:`"${c}", sans-serif`,fontSize:`${p/d.width*100}cqw`,lineHeight:1.2,overflowWrap:`anywhere`,WebkitTextStroke:`${2.5/d.width*100}cqw #101010`,paintOrder:`stroke fill`,textShadow:`0 ${100/d.width}cqw ${100/d.width}cqw #000`};return(0,h.jsxs)(`figure`,{className:`min-w-0 self-start`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Style preview`}),(0,h.jsx)(`span`,{children:t})]}),(0,h.jsxs)(`div`,{role:`img`,"aria-label":`Subtitle style preview`,"data-format":t,"data-position":e.position??`bottom`,className:`sl-media__frame mx-auto w-full text-center text-white`,style:{aspectRatio:`${d.width} / ${d.height}`,maxWidth:t===`9:16`?a?`min(240px, calc((${a}) * 9 / 16))`:240:t===`1:1`?360:480,containerType:`inline-size`},children:[r?(0,h.jsx)(`img`,{src:r,alt:``,className:`absolute inset-0 h-full w-full object-cover`}):null,i?(0,h.jsx)(`span`,{role:`note`,"aria-label":`Caption sample`,style:g,children:n}):null]}),(0,h.jsxs)(`figcaption`,{className:`mt-2 text-label text-ink-3`,children:[d.width,` × `,d.height,` · Preview at reduced scale.`,l?` Font preview unavailable; showing a fallback.`:``]})]})}function R6({value:e,format:t=`16:9`,audioEnabled:n,videoEnabled:r,disabled:i=!1,onChange:a,onUploading:o,problem:s,session:c,fontUpload:l,showPreview:u=!0,illustratedPositions:d=!1,rawFontSize:f}){let p=(0,m.useId)(),g=(0,m.useId)(),_=(0,m.useId)(),v=(0,m.useId)(),[y,b]=(0,m.useState)(!1),x=s?.(`subtitles.fontId`),S=s?.(`subtitles.fontSize`),C=s?.(`subtitles.mode`)??s?.(`subtitles`);return(0,h.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":`Subtitles`,children:[(0,h.jsxs)(`fieldset`,{disabled:i||!n,className:`flex min-w-0 flex-col gap-3 disabled:opacity-60`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 flex-1`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:p,children:`Subtitles`}),(0,h.jsx)(U,{id:`project.subtitles.mode`,className:`-my-1`})]}),(0,h.jsxs)(`select`,{id:p,"data-play-field":`subtitles.mode`,value:n?e.mode:`off`,disabled:l?.pending??y,"aria-describedby":_,"aria-invalid":C!==void 0,onChange:t=>a({...e,mode:t.target.value}),className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:[(0,h.jsx)(`option`,{value:`off`,children:`Off`}),(0,h.jsx)(`option`,{value:`files`,children:`Subtitle files (.srt + .vtt)`}),(0,h.jsx)(`option`,{value:`burn-in`,disabled:!r,children:`Burn into video + files`})]})]}),(0,h.jsx)(`span`,{className:`pb-1 text-label text-ink-3`,children:`English · local · no paid API`})]}),e.mode!==`off`&&n?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Timed from your narration on this computer. First use downloads an approximately 95 MB speech model. Review the subtitles before publishing.`}),(0,h.jsxs)(`div`,{className:`grid items-start gap-5`,style:{gridTemplateColumns:`repeat(auto-fit, minmax(min(100%, 240px), 1fr))`},children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(y_e,{...l?{upload:l}:{},value:e.fontId,onPick:t=>c?c.selectFont(t):a({...e,fontId:t}),onUploading:e=>{b(e),o?.(e)}}),(0,h.jsxs)(`div`,{className:d?`w-full`:`max-w-[180px]`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:g,children:`Subtitle font size`}),(0,h.jsx)(U,{id:`project.subtitles.size`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-5`,children:[d?(0,h.jsx)(`input`,{"aria-label":`Subtitle font size slider`,type:`range`,min:16,max:120,step:1,value:Math.max(16,Math.min(120,Number.isFinite(e.fontSize)?e.fontSize:48)),className:`min-w-0 flex-1 accent-accent`,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})}):null,(0,h.jsx)(zB,{className:d?`w-20`:void 0,id:g,"data-play-field":`subtitles.fontSize`,type:`number`,min:16,max:120,step:1,value:f?.value??e.fontSize,"aria-invalid":!SN(e)||S!==void 0,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})})]}),!SN(e)||S?(0,h.jsx)(`p`,{role:`alert`,className:`mt-1 text-label text-danger`,children:S??`Choose a whole font size from 16 to 120.`}):null]}),(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:d?void 0:v,id:`${v}-label`,children:`Subtitle position`}),(0,h.jsx)(U,{id:`project.subtitles.position`,className:`-my-1`})]}),d?(0,h.jsx)(q4,{type:`single`,"aria-labelledby":`${v}-label`,value:e.position??`bottom`,onValueChange:t=>{let n=oM.find(e=>e===t);n&&a({...e,position:n})},className:`grid w-full grid-cols-5 gap-2 overflow-visible border-0`,children:oM.map((t,n)=>(0,h.jsxs)(J4,{value:t,"aria-label":t,"data-play-field":(e.position??`bottom`)===t?`subtitles.position`:void 0,className:`flex min-w-0 flex-col items-center gap-2 rounded-control border border-line-strong bg-surface px-1 py-3 text-[10px] last:border-r data-[state=on]:border-focus data-[state=on]:text-accent-ink data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`relative block h-11 w-7 rounded-[2px] border border-current`,children:(0,h.jsx)(`span`,{className:`absolute left-1 right-1 h-[3px] bg-current`,style:{top:`${8+n*20}%`}})}),(0,h.jsxs)(`span`,{children:[t[0]?.toUpperCase(),t.slice(1)]})]},t))}):(0,h.jsx)(`select`,{id:v,"data-play-field":`subtitles.position`,value:e.position??`bottom`,onChange:t=>{let n=oM.find(e=>e===t.target.value);n&&a({...e,position:n})},className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:oM.map(e=>(0,h.jsxs)(`option`,{value:e,children:[e[0]?.toUpperCase(),e.slice(1)]},e))})]})]}),u?(0,h.jsx)(C_e,{value:e,format:t,...c?{sample:c.previewText}:{}}):null]}),c?.fontUpload&&!c.fontUploading?(0,h.jsxs)(`p`,{role:`alert`,children:[`Reattach `,c.fontUpload.name,`, or select a font.`]}):null,x?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}):null,e.mode===`files`?(0,h.jsx)(`p`,{className:`text-label text-ink-3`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]}):null]}),c?.fontUpload&&(e.mode===`off`||!n)?(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:c.fontUploading?`status`:`alert`,className:`text-small text-ink-2`,children:c.fontUploading?`Uploading ${c.fontUpload.name}…`:`Unfinished font upload: ${c.fontUpload.name}`}),l?.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:l.error}):null,(0,h.jsx)(B,{"data-play-field":`subtitles.fontUpload`,disabled:i,onClick:()=>c.selectFont(e.fontId),children:`Keep current font`})]}):null,C?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:C}):null,(0,h.jsx)(`p`,{id:_,className:`text-small text-ink-2`,children:n?r?`Optional: download subtitles separately or keep them visible in the video.`:`Audio exports support separate subtitle files. Enable Video to burn captions into an MP4.`:`Turn Audio on to add subtitles.`})]})}function z6({value:e,onPick:t}){let n=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`w-full`,...zb,children:[(0,h.jsxs)(`span`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(K4,{id:n,children:`Frame format`}),(0,h.jsx)(U,{id:`play.format`,className:`-my-1`})]}),(0,h.jsx)(q4,{type:`single`,value:e,"aria-labelledby":n,className:`w-full max-w-[560px] gap-3 overflow-visible border-0`,onValueChange:e=>{let n=GS.find(t=>t===e);n!==void 0&&t(n)},children:GS.map(t=>(0,h.jsxs)(J4,{value:t,"data-play-field":e===t?`format`:void 0,"aria-label":t,className:`flex h-28 min-w-0 flex-1 items-center justify-center gap-4 rounded-control border border-line-strong bg-surface p-3 last:border-r data-[state=on]:border-focus data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{className:`flex h-12 items-center justify-center`,"aria-hidden":`true`,children:(0,h.jsx)(`span`,{"data-format-shape":t,className:`block rounded-[2px] border-2 border-current`,style:{width:t===`16:9`?64:t===`1:1`?40:27,aspectRatio:t.replace(`:`,` / `)}})}),(0,h.jsxs)(`span`,{className:`text-left`,children:[(0,h.jsx)(`span`,{className:`block text-body font-semibold`,children:t}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:t===`16:9`?`Landscape`:t===`1:1`?`Square`:`Portrait`})]})]},t))})]})}function w_e({problem:e}){let t=XN(),{document:n}=t,{form:r}=n,i=e=>t.edit({...n,form:{...r,subtitles:{...e,fontSize:r.subtitles.fontSize}}});return(0,h.jsxs)(`div`,{"data-tour":`play-subtitles`,className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`See frame and caption changes in the preview as you go.`}),(0,h.jsx)(z6,{value:r.format,onPick:e=>t.edit({...n,form:{...r,format:e}})}),(0,h.jsx)(`div`,{className:`border-t border-line pt-4`,children:(0,h.jsx)(R6,{showPreview:!1,illustratedPositions:!0,fontUpload:t.fontUpload,session:{previewText:n.previewText,fontUploading:t.fontUploading,fontUpload:n.fontUpload,selectFont:t.selectFont,uploadSubtitleFont:t.uploadSubtitleFont},value:{...r.subtitles,fontSize:Number(r.subtitles.fontSize)},rawFontSize:{value:r.subtitles.fontSize,onChange:e=>t.edit({...n,form:{...r,subtitles:{...r.subtitles,fontSize:e}}})},format:r.format,audioEnabled:r.sources.audio!==`off`,videoEnabled:r.sources.video===`generate`&&r.sources.images!==`off`,onChange:i,problem:e})}),(0,h.jsx)(LB,{label:`Preview text`,tip:`play.preview-text`,className:`border-t border-line pt-4`,children:(0,h.jsx)(zB,{value:n.previewText,onChange:e=>t.edit({...n,previewText:e.target.value})})})]})}function T_e(e){let t=XN(),n=t.document,r=R3(),i=z3(),{form:a,entries:o,problem:s,update:c}=e;return(0,h.jsx)(Gge,{...e,titled:!1,cast:r,language:i,rawCounts:{...n.form.chunking,onChange:(e,r)=>t.edit({...n,form:{...n.form,chunking:{...n.form.chunking,mode:e,...e===`words`?{words:r}:e===`characters`?{characters:r}:{}}}})},advanced:(0,h.jsxs)(h.Fragment,{children:[[`intro`,`outro`].map(e=>(0,h.jsx)(ZB,{field:e,label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,value:a[e],placeholder:`Off`,options:o.filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),problem:s(e),onPick:t=>c({[e]:t})},e)),(0,h.jsx)(`div`,{className:`col-span-full flex flex-wrap gap-2`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:e.onSettings,children:`Settings`})}),(0,h.jsx)(`div`,{className:`col-span-full empty:hidden`,children:(0,h.jsx)(F6,{...e,section:`narration`,onSettings:e.onSettings})})]})})}function E_e(e){let t=XN(),n=t.document;return(0,h.jsx)(Kge,{...e,titled:!1,more:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(h_e,{document:n,problem:e.problem,onEdit:t.edit}),n.form.sources.article===`off`?null:(0,h.jsx)(v_e,{document:n,onEdit:t.edit})]}),rawNumbers:{values:n.form.imagePrompts,onChange:(e,r)=>t.edit({...n,form:{...n.form,imagePrompts:n.form.imagePrompts.map(t=>t.name===e?{...t,number:r}:t)}})}})}function D_e(e){let t=XN(),n=t.document,r=z3();return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s_e,{...e,titled:!1,extras:!1,language:r,rawTiming:{imageSeconds:n.form.imageSeconds,zoomPercent:n.form.zoomPercent,edgeSilenceSeconds:n.form.edgeSilenceSeconds,onChange:(e,r)=>t.edit({...n,form:{...n.form,[e]:r}})}}),n.form.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:`sl-fields border-b border-line py-4`,children:(0,h.jsx)(P6,{field:`silenceGapSeconds`,label:`Silence between segments (seconds)`,tip:`play.silence-gap`,placeholder:String(e.silenceGapSeconds),step:.1,problem:e.problem(`silenceGapSeconds`),value:n.form.silenceGapSeconds??``,onChange:e=>{let{silenceGapSeconds:r,...i}=n.form;t.edit({...n,form:e.trim()===``?i:{...i,silenceGapSeconds:e}})}})}),(0,h.jsx)(w_e,{problem:e.problemOf})]})}function O_e(e){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(F6,{...e,section:`outputs`,onSettings:e.onSettings}),(0,h.jsx)(o_e,{...e}),(0,h.jsx)(`section`,{className:`border-b border-line py-4`,children:(0,h.jsx)(N6,{form:e.form,prompts:e.prompts,problem:e.problem,update:e.update,onPickFiles:e.onPickFiles,onRemoveFile:e.onRemoveFile,...e.onReattachFile===void 0?{}:{onReattachFile:e.onReattachFile}})}),e.form.sources.article===`off`?null:(0,h.jsx)(c_e,{...e})]})}function B6(e,t){if(t===void 0||t.length===0||e.trim()===``)return[];let n=[];for(let[r,i]of t.entries()){let t=1/0;for(let n of[i.name,...i.aliases]){let r=k_e(e,n);r!==void 0&&r<t&&(t=r)}Number.isFinite(t)&&n.push({member:i,at:t,order:r})}return n.sort((e,t)=>e.at-t.at||e.order-t.order).map(e=>e.member)}function k_e(e,t){let n=t.trim().split(/\s+/u).filter(Boolean);if(n.length===0)return;let r=RegExp(`(?<![\\p{L}\\p{N}])${n.map(A_e).join(`\\s+`)}(?![\\p{L}\\p{N}])`,`iu`).exec(e);return r===null?void 0:r.index}function A_e(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function j_e(e,t){let n=e.provided.reference?.file;if(e.sources.images===`generate`&&e.reference?.source===`provide`&&n!==void 0)return{image:{kind:`upload`,stagedFileId:n.id},drawnOn:`the establishing image`};let r=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),i=B6([e.title,...Object.values(e.values)].join(` `),r)[0]??r[0],a=i?.images[0];if(i!==void 0&&a!==void 0)return{image:{kind:`picture`,sha256:a},drawnOn:`${i.name}'s picture`}}function M_e({selected:e,reviewed:t}){let n=e=>B3.find(t=>t.stage===e)?.label??e;return e?.length?(0,h.jsxs)(`div`,{className:`space-y-3 text-body`,children:[t?.length?t.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`font-medium`,children:[`Run `,e.runIndex+1,` · Before `,n(e.stage)]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.dependents.length?`Also holds: ${e.dependents.map(n).join(`, `)}.`:`No dependent steps.`})]},`${e.runIndex}-${e.checkpointId}`)):(0,h.jsxs)(`p`,{children:[`Selected: `,e.map(e=>`Before ${n(e)}`).join(`, `),`. Refresh review to confirm dependent steps.`]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Approval required on the project page. Starting this run does not approve these checkpoints.`})]}):(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No review checkpoints selected.`})}function N_e({estimates:e}){let t=e.reduce((e,t)=>e+t.low,0),n=e.reduce((e,t)=>e+t.high,0),r=e.reduce((e,t)=>e+t.unknown,0),i=e[0]?.rows.map((t,n)=>({...t,low:e.some(e=>e.rows[n]?.low===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.low??0),0),high:e.some(e=>e.rows[n]?.high===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.high??0),0),apiLow:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiLow==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiLow??0),0),apiHigh:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiHigh==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiHigh??0),0)}))??[],a=e.some(e=>e.apiLow!==void 0),o=e.reduce((e,t)=>e+(t.apiLow??0),0),s=e.reduce((e,t)=>e+(t.apiHigh??0),0),c=e.reduce((e,t)=>e+(t.apiUnknown??0),0);return e.length===0?(0,h.jsx)(`div`,{}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-title-2 font-semibold`,children:[r?`Known subtotal: `:`Estimated total: `,V6(t,n)]}),r?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Plus `,r,` stage charge`,r===1?``:`s`,` with unavailable pricing.`]}):null,(0,h.jsxs)(`details`,{className:`rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Cost by stage · `,i.length,` `,i.length===1?`stage`:`stages`]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 pt-1 pb-3`,children:[a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o===0&&s===0?`CLI steps: $0 on your plan · no API price is listed for their models.`:`CLI steps: $0 on your plan · ~${V6(o,s)} via API${c?` (plus ${String(c)} with no API price)`:``}.`}):null,(0,h.jsx)(`ul`,{"aria-label":`Cost by stage`,className:`m-0 list-none divide-y divide-line p-0`,children:i.map(e=>(0,h.jsxs)(`li`,{className:`py-2`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between gap-4 text-small`,children:[(0,h.jsx)(`span`,{children:e.stage}),(0,h.jsx)(`span`,{className:`text-right tabular-nums`,children:e.onPlan===!0?e.apiLow===null||e.apiHigh===null?`$0 on your plan · API price unknown`:`$0 on your plan · ~${V6(e.apiLow,e.apiHigh)} via API`:e.low===null||e.high===null?`Unknown`:V6(e.low,e.high)})]}),(0,h.jsx)(`p`,{className:`m-0 mt-0.5 text-label text-ink-3`,children:e.detail})]},e.stage))}),[...new Set(e.flatMap(e=>e.assumptions))].map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e},e)),(0,h.jsxs)(`p`,{className:`m-0 text-label text-ink-3`,children:[`Catalogue verified `,e[0]?.catalogueDate??`date unavailable`,`. Batch rows show combined costs.`]})]})]})]})}function V6(e,t){let n=e=>e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`;return e===t?n(e):`${n(e)} – ${n(t)}`}function H6(e){let t=vA(hA(e)),n=new Map(vA(aA)),r=t.filter(([e,t])=>e!==`Cuts`&&n.get(e)!==t).map(([e,t])=>e===`Animate images`?`Animated images: ${t} (paid)`:e===`Chapter cards`?`Chapter cards`:e===`Transition`?t:`${e}: ${t}`);return r.length===0?`Plain cuts, no effects`:r.join(` · `)}function P_e(e){return e===void 0?{ok:!1,text:`Provider status unavailable`}:e.readiness.kind===`cli`?JP(e.readiness)?{ok:!0,text:e.readiness.version===void 0?`CLI ready`:`CLI ready · ${e.readiness.version}`}:{ok:!1,text:e.readiness.issue??`CLI not found`}:e.readiness.kind===`local`?e.readiness.available?{ok:!0,text:`Built-in voice · ${e.readiness.engine??`ready`}`}:{ok:!1,text:e.readiness.issue??`No speech program found`}:e.readiness.hasKey?{ok:!0,text:`API key saved`}:{ok:!1,text:`API key missing`}}function F_e(e,t){let n=e.sources.audio===`generate`,r=[`from_prompt`,`prompt_by_llm`].includes(e.sources.thumbnail);return[...(e.sources.article===`generate`||e.sources.thumbnail===`prompt_by_llm`||oj(e)||wN(e)||n&&[`intro`,`outro`].some(n=>t.some(t=>t.category===n&&t.name===e[n]&&t.mode===`llm`)))&&e.llm?[{field:`llm.provider`,family:`llm`,label:`Text generation`,provider:e.llm.provider,model:e.llm.model}]:[],...n&&e.audio?[{field:`audio.provider`,family:`tts`,label:`Narration`,provider:e.audio.provider,model:e.audio.model,voice:e.audio.voice}]:[],...(e.sources.images===`generate`||r||wN(e)||gA(e))&&e.images?[{field:`images.provider`,family:`image`,label:`Images`,provider:e.images.provider,model:e.images.model}]:[]]}function U6({name:e,children:t}){return(0,h.jsxs)(`section`,{"aria-label":`${e} summary`,className:`min-w-0 border-t border-line pt-5`,children:[(0,h.jsx)(`h3`,{className:`mb-4 font-semibold`,children:e}),t]})}function I_e({form:e,entries:t,providers:n,voices:r,textModels:i,audioModels:a,imageModels:o,onReveal:s}){let c=F_e(e,t);if(!c.length)return(0,h.jsx)(U6,{name:`Run readiness`,children:(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No generated providers required. Supplied content is ready for processing.`})});let l={llm:i,tts:a,image:o};return(0,h.jsxs)(U6,{name:`Run readiness`,children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`These checks are refreshed with Review and checked again when you start.`}),(0,h.jsx)(`ul`,{className:`divide-y divide-line`,"aria-label":`Run readiness checks`,children:c.map(e=>{let t=n?.find(t=>t.id===e.provider&&t.family===e.family),i=P_e(t),a=l[e.family],o=a?.models.find(t=>t.id===e.model),c=a===void 0?{ok:!0,text:`Model checked at Start`}:o!==void 0||a.allowsCustom?{ok:!0,text:`Model available`}:{ok:!1,text:`Model unavailable`},u=e.voice===void 0?void 0:r===void 0?{ok:!1,text:`Voice list unavailable`}:r.some(t=>t.provider===e.provider&&t.voiceId===e.voice)?{ok:!0,text:`Voice saved`}:{ok:!1,text:`Voice missing`},d=[i,c,...u?[u]:[]],f=d.every(e=>e.ok);return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-3 py-3`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,h.jsx)(`span`,{className:f?`text-lime`:`text-danger`,children:f?`Ready`:d.filter(e=>!e.ok).map(e=>e.text).join(` · `)}),f?null:(0,h.jsx)(B,{variant:`quiet`,onClick:()=>s(e.field),children:`Edit ↗`})]},`${e.family}:${e.provider}`)})})]})}function L_e({fields:e,onReveal:t,children:n}){let{document:r,review:i}=XN(),{form:a}=r,{api:o}=V(),s=_(),c=s.getQueryData(db(o).queryKey),l=s.getQueryData(mb(o).queryKey),u=s.getQueryData(fb(o).queryKey),d=s.getQueryData(eN),f=s.getQueryData(WB(a.llm.provider)),p=s.getQueryData(WB(a.audio.provider)),m=s.getQueryData(WB(a.images.provider)),g=a.sources.audio===`generate`,v=[`from_prompt`,`prompt_by_llm`].includes(a.sources.thumbnail),y=a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||oj(a)||wN(a)||g&&[`intro`,`outro`].some(e=>l?.entries.some(t=>t.category===e&&t.name===a[e]&&t.mode===`llm`)),b=e=>c?.providers.find(t=>t.id===e)?.displayName??e,x=(e,n,r)=>(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[90px_minmax(0,1fr)_auto] items-start gap-x-3 py-1 sm:grid-cols-[145px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(`dt`,{className:`break-words py-2 text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`min-w-0 whitespace-pre-wrap break-words py-2`,children:r||`Not selected`}),n?(0,h.jsx)(`dd`,{children:(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Edit ${e}`,onClick:()=>t(n),children:`Edit ↗`})}):null]},n??e),S=a.chunking.mode===`words`||a.chunking.mode===`characters`?a.chunking.mode:null;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(I_e,{form:a,entries:l?.entries??[],providers:c?.providers,voices:u?.voices,textModels:f,audioModels:p,imageModels:m,onReveal:t}),(0,h.jsxs)(U6,{name:`Content`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Project`,`title`,a.title||`Untitled run`),x(`Article`,`sources.article`,DN[a.sources.article]),a.sources.article===`generate`?x(`Article prompt`,`articlePrompt`,a.articlePrompt):x(`Article text`,`provided.article`,`Your article`),a.sources.article===`generate`?x(`Research`,`sources.research`,DN[a.sources.research]):x(`Research`,null,`Off · Article is provided`),a.sources.research===`provide`&&a.sources.article===`generate`?x(`Research text`,`provided.research`,a.provided.research):null,y?(0,h.jsxs)(h.Fragment,{children:[x(`Text provider`,`llm.provider`,b(a.llm.provider)),x(`Text model`,`llm.model`,f?.models.find(e=>e.id===a.llm.model)?.name??a.llm.model),a.llm.thinking||f?.models.find(e=>e.id===a.llm.model)?.thinkingModes?.length?x(`Thinking`,`llm.thinking`,a.llm.thinking??`Model default`):null]}):null,e.map(({name:e})=>x(e,`values.${e}`,a.values[e]??``))]}),n]}),(0,h.jsx)(U6,{name:`Outputs`,children:(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Narration`,`sources.audio`,DN[a.sources.audio]),g?(0,h.jsxs)(h.Fragment,{children:[x(`Audio provider`,`audio.provider`,b(a.audio.provider)),x(`Audio model`,`audio.model`,p?.models.find(e=>e.id===a.audio.model)?.name??a.audio.model),x(`Voice`,`audio.voice`,u?.voices.find(e=>e.provider===a.audio.provider&&e.voiceId===a.audio.voice)?.name??a.audio.voice),x(`Chunking`,S?`chunking.${S}`:`chunking.mode`,S?`Every ${a.chunking[S]||`(not entered)`} ${S}`:a.chunking.mode===`whole`?`Whole text`:`Paragraph`),x(`Intro`,`intro`,a.intro||`Off`),x(`Narration Preparation`,`narrationPrompt`,a.narrationPrompt?`${a.narrationPrompt} · One LLM call per narration chunk and entry`:`Off`),x(`Outro`,`outro`,a.outro||`Off`)]}):null,a.sources.audio===`provide`?x(`Narration file`,`provided.audio`,a.provided.audio?.name):null,x(`Images`,`sources.images`,DN[a.sources.images]),a.sources.images===`generate`||v||wN(a)?(0,h.jsxs)(h.Fragment,{children:[x(`Image provider`,`images.provider`,b(a.images.provider)),x(`Image model`,`images.model`,m?.models.find(e=>e.id===a.images.model)?.name??a.images.model),a.images.thinking===void 0?null:x(`Image effort`,`images.thinking`,a.images.thinking)]}):null,a.sources.images===`generate`&&a.reference!==void 0&&a.reference.source!==`off`?x(`Establishing image`,a.reference.source===`prompt`?`reference.prompt`:`provided.reference`,`${a.reference.source===`prompt`?a.reference.prompt||`(no prompt picked)`:a.provided.reference?.name??`(no file attached)`}${a.reference.thumbnail?` · thumbnail too`:``}`):null,a.sources.images===`generate`?a.imagePrompts.length?a.imagePrompts.map((e,t)=>x(e.name,`imagePrompts.${t}.number`,`${e.name} · ${e.number||`(not entered)`} images`)):x(`Image prompts`,`imagePrompts`,`None selected`):null,a.sources.images===`provide`?x(`Image files`,`provided.images`,a.provided.images.length?(0,h.jsx)(`ol`,{className:`list-inside list-decimal`,children:a.provided.images.map(e=>(0,h.jsx)(`li`,{children:e.name},e.attachmentId))}):`No files selected`):null,x(`Thumbnail`,`sources.thumbnail`,DN[a.sources.thumbnail]),v?x(`Thumbnail prompt`,`thumbnailPrompt`,a.thumbnailPrompt):null,a.sources.thumbnail===`provide`?x(`Thumbnail file`,`provided.thumbnail`,a.provided.thumbnail?.name):null,x(`Video`,`sources.video`,DN[a.sources.video]),a.sources.video===`generate`?x(`Seconds per image`,`imageSeconds`,a.imageSeconds||`(not entered)`):null,a.sources.video===`generate`?x(`Zoom`,`zoomPercent`,a.zoomPercent?`${a.zoomPercent}%`:`(not entered)`):null,a.sources.video===`generate`?x(`Motion`,`motionStyle`,HA[a.motionStyle]):null,a.sources.video===`generate`?x(`Cuts`,`videoEdit.cuts`,lA[hA(a).cuts]):null,a.sources.video===`generate`?x(`Look`,`videoEdit`,H6(a)):null,a.sources.audio===`off`?null:x(`Silence at start and end`,`edgeSilenceSeconds`,a.edgeSilenceSeconds?`${a.edgeSilenceSeconds} s`:`(not entered)`),a.sources.audio===`off`?null:x(`YouTube description`,`youtubeDescription`,a.youtubeDescription===!0?`${a.descriptionPrompt||`Built-in`} prompt · One LLM call after subtitle timing`:`Off`),a.sources.audio===`off`?null:x(`Shorts`,`shorts.enabled`,wN(a)&&a.shorts!==void 0?[`${a.shorts.count} shorts of ${a.shorts.minSeconds}-${a.shorts.maxSeconds} s`,`${a.shorts.prompt||`Built-in`} prompt`,`${a.shorts.imagePrompt||`Built-in`} image style`,...R_e(a.shorts,a.provided.shortsMusic?.name),`Vertical images and renders after subtitle timing`].join(` · `):`Off`),x(`Document`,`sources.document`,YS(a.sources,`document`)===`generate`?`PDF · ${sC(a.document)} theme`:DN.off)]})}),(0,h.jsxs)(U6,{name:`Checkpoints`,children:[(0,h.jsx)(M_e,{selected:a.checkpoints,reviewed:i.valid?i.receipt?.checkpointSet:void 0}),(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Edit checkpoints`,onClick:()=>t(`checkpoints`),children:`Edit checkpoints ↗`})]}),(0,h.jsxs)(U6,{name:`Style`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Frame`,`format`,a.format),a.sources.audio===`off`?x(`Subtitles`,null,`Off · Audio is Off`):x(`Subtitles`,`subtitles.mode`,a.subtitles.mode),a.sources.audio!==`off`&&a.subtitles.mode!==`off`?(0,h.jsxs)(h.Fragment,{children:[x(`Subtitle font`,`subtitles.fontId`,d?.fonts.find(e=>e.id===a.subtitles.fontId)?.name??a.subtitles.fontId),x(`Subtitle size`,`subtitles.fontSize`,`${a.subtitles.fontSize||`(not entered)`} px`),x(`Subtitle position`,`subtitles.position`,a.subtitles.position)]}):null]}),a.sources.audio!==`off`&&a.subtitles.mode===`files`?(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]})]})}function R_e(e,t){let n=Bk(e),r=n.speed,i=n.musicVolume;return[...n.titleOnScreen===!0?[`Title on screen`]:[],...r!==void 0&&r!==1?[`${r.toFixed(2)}× speed`]:[],...t===void 0?i!==void 0&&i!==15?[`Music at ${String(i)}% once added in Edit project`]:[]:[`Music: ${t} at ${String(i??15)}%`],...n.fullVideoLink===void 0?[]:[`Links ${n.fullVideoLink}`]]}function z_e({fields:e,errors:t,onReveal:n,problem:r}){let i=XN(),{document:a,review:o}=i,s=a.form;(0,m.useEffect)(()=>{i.reviewDraft()},[i.reviewDraft]);let c=o.valid?o.receipt?.runs??[]:[];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Everything this run will do, the checkpoints it stops at and the reviews it runs. The estimate and the Play key stay in the right rail.`}),t.length?(0,h.jsx)(`ul`,{"aria-label":`Setup errors`,className:`text-small text-danger`,children:t.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(B,{variant:`quiet`,onClick:()=>n(e.field),children:e.message})},`${e.field}-${e.message}`))}):null,(0,h.jsx)(_ge,{problem:r}),(0,h.jsx)(rV,{problem:r}),(0,h.jsx)(L_e,{fields:e,onReveal:n,children:(0,h.jsxs)(`details`,{className:`mt-5 border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:s.sources.article===`provide`?`Read the supplied article and resolved prompts`:`Read the resolved prompt`}),c.length?c.map((e,t)=>(0,h.jsxs)(`div`,{className:`mt-4`,children:[(0,h.jsx)(`h4`,{className:`font-medium`,children:e.draft.title}),e.draft.sources.article===`provide`?(0,h.jsx)(`p`,{className:`mt-3 whitespace-pre-wrap break-words text-body`,children:e.draft.provided.article}):null,Object.entries(e.rendered).map(([e,t])=>(0,h.jsxs)(`div`,{className:`mt-3`,children:[(0,h.jsx)(`h5`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-body`,children:t})]},e))]},a.variants[t-1]?.id??i.activeId)):(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Refresh review to read the exact resolved inputs.`})]})})]})}function B_e(e,t,n){return[...F3(e).map(e=>(t[e]??``).trim()===``?`${e} is left empty in the template.`:`${e} is left empty in the template (this video's ${e}, "${t[e]}", is not saved).`),...n>0?[`The ${n===1?`other video`:`${String(n)} other videos`} queued here ${n===1?`is`:`are`} not saved.`]:[]]}function V_e({open:e,onClose:t}){let{api:n}=V(),r=_(),i=XN(),a=Ry(),o=I(lq(n)),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),p=(0,m.useRef)(null),{document:g}=i,v=B_e(g.form.title,g.form.values,g.variants.length),y=()=>{u(null),t()},b=async()=>{let e=s.trim();if(!(e===``||d)){f(!0),u(null);try{if(!await i.flush()){u(`Your draft wasn't saved, so the template wasn't either. Press Retry beside Drafts, then Save template again.`);return}p.current?.name!==e&&(p.current={name:e,id:crypto.randomUUID()});let s=o.data?.find(e=>e.id===g.templateSource?.id),l=g.channelId??(s?E1(s):void 0),d=pge(g),f=await dq(n,{id:p.current.id,name:e,document:l===void 0?d:{...d,channelId:l}});if(!f.ok){p.current=null,u(`The template wasn't saved. ${f.message}`);return}p.current=null,c(``),a(`Template "${e}" saved.`,`success`),await r.invalidateQueries({queryKey:iq}),t()}catch(e){u(`The template wasn't saved. ${e instanceof Error?e.message:`Press Save template again.`}`)}finally{f(!1)}}};return(0,h.jsx)(Vy,{open:e,onOpenChange:e=>{e||y()},title:`Save as template`,description:`Keeps this setup's prompts, voice, images, style, outputs and reviews to start the next video from.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`secondary`,onClick:y,children:`Cancel`}),(0,h.jsx)(B,{variant:`primary`,disabled:s.trim()===``||d,disabledReason:d?`Saving the template`:`Name the template first`,onClick:()=>void b(),children:`Save template`})]}),children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,h.jsx)(LB,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(zB,{autoFocus:!0,value:s,maxLength:120,placeholder:g.form.title.replace(/\{\{[^}]*\}\}/g,``).trim()||`My setup`,onChange:e=>c(e.target.value)})}),v.length?(0,h.jsx)(`ul`,{"aria-label":`Left out of the template`,className:`m-0 flex list-none flex-col gap-1 p-0 text-small text-ink-2`,children:v.map(e=>(0,h.jsx)(`li`,{children:e},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Every keyword keeps its value: the title names none.`}),l?(0,h.jsx)(aI,{tone:`danger`,title:l}):null]})})}var H_e=new Set([`a`,`an`,`the`,`of`,`and`,`or`,`in`,`on`,`to`,`for`,`with`,`vs`,`s`]);function W6(e){return e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase().replace(/&/g,` and `).replace(/[^\p{L}\p{N}]+/gu,` `).trim()}function G6(e){let t=W6(e).split(` `).filter(e=>e!==``&&!H_e.has(e)).map(e=>e.length>3&&e.endsWith(`s`)&&!e.endsWith(`ss`)?e.slice(0,-1):e);return new Set(t)}function U_e(e,t){let n=0;for(let r of e)t.has(r)&&(n+=1);return n}function W_e(e,t){let n=W6(e);if(n===W6(t))return n!==``;let r=G6(e),i=G6(t);if(r.size===0||i.size===0)return!1;let a=U_e(r,i);if(a/(r.size+i.size-a)>=.6)return!0;let o=Math.min(r.size,i.size),s=Math.max(r.size,i.size);return a===o&&o/s>=.5}function G_e(e,t,n){let r=e.map(e=>e.trim()).filter(e=>e!==``);if(r.length===0)return;let i=e=>r.some(t=>W_e(t,e)),a=t.find(i);if(a!==void 0)return{title:a,where:`project`};let o=n.find(i);return o===void 0?void 0:{title:o,where:`video`}}function K_e({topics:e}){let{api:t}=V(),n=XN(),{document:r}=n,i=L3(),a=I(ob(t)),o=I(v2(t,i)),{form:s}=r,c=FK(s.title,s.values),l=G_e(e.length===0?[s.title]:[c,...e.map(e=>s.values[e]??``)],(a.data?.projects??[]).filter(e=>e.channelId===i).map(e=>e.title),(o.data??[]).map(e=>e.title));return l===void 0||n.review.created!==null?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.where===`project`?`This channel already has a video on this: "${l.title}" (in Projects). Start anyway if you want another take.`:`This channel already uploaded "${l.title}" (Channel → Existing videos). Start anyway if you want another take.`})}function q_e({rows:e,open:t,onChange:n}){return(0,h.jsx)(`ul`,{"aria-label":`Setup`,className:`m-0 flex list-none flex-col border-t border-line p-0`,children:e.map(e=>{let r=t.has(e.id)&&e.editor!==void 0,i=`play-row-${e.id}`;return(0,h.jsxs)(`li`,{"data-setup-row":e.id,className:`border-b border-line`,children:[(0,h.jsx)(W,{title:e.label,size:`small`,className:`items-center py-3.5`,status:e.problem?(0,h.jsx)(OS,{tone:`failed`,children:`Needs setup`}):void 0,meta:(0,h.jsx)(`span`,{"data-row-summary":!0,className:e.problem&&!r?`block break-words text-danger`:`block truncate text-ink-2`,title:e.problem&&!r?void 0:e.summary,children:r?e.summary:e.problem??e.summary}),children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-expanded":e.editor===void 0?void 0:r,"aria-controls":e.editor===void 0?void 0:i,"aria-label":`${r?`Done with`:`Change`} ${e.label.toLowerCase()}`,onClick:()=>n(e.id,!r),children:r?`Done`:`Change`})}),r?(0,h.jsx)(`section`,{id:i,"aria-label":e.label,className:`min-w-0 pb-6`,children:e.editor}):null]},e.id)})})}var K6=[{id:`title`,label:`Title and keywords`,section:`content`},{id:`article`,label:`Article`,section:`content`},{id:`narration`,label:`Narration`,section:`outputs`},{id:`images`,label:`Images`,section:`outputs`},{id:`video`,label:`Video and style`,section:`style`},{id:`outputs`,label:`Outputs`,section:`outputs`},{id:`reviews`,label:`Reviews`,section:`review`},{id:`channel`,label:`Channel`,section:`content`}],J_e=[[`title`,[`title`,`values`]],[`article`,[`sources.article`,`sources.research`,`articlePrompt`,`provided.article`,`provided.research`,`llm`]],[`narration`,[`sources.audio`,`audio`,`voices`,`provided.audio`,`narrationPrompt`,`intro`,`outro`,`chunking`]],[`images`,[`sources.images`,`images`,`imagePrompts`,`provided.images`,`reference`,`provided.reference`]],[`video`,[`sources.video`,`imageSeconds`,`zoomPercent`,`motionStyle`,`edgeSilenceSeconds`,`silenceGapSeconds`,`sentencePauseSeconds`,`paragraphPauseSeconds`,`loudness`,`videoEdit`,`format`,`subtitles`,`fontUpload`]],[`outputs`,[`sources.thumbnail`,`thumbnailPrompt`,`provided.thumbnail`,`thumbnailCount`,`youtubeDescription`,`descriptionPrompt`,`shorts`,`sources.document`,`document`]],[`reviews`,[`checkpoints`,`reviews`]],[`channel`,[`channelId`,`useBrandKit`,`language`]]],q6=(e,t)=>e.some(e=>t===e||t.startsWith(`${e}.`));function J6(e,t=`article`){return q6([`llm`],e)?t:J_e.find(([,t])=>q6(t,e))?.[0]}function Y_e(e){switch(e){case`content`:return[`title`,`article`,`channel`];case`outputs`:return[`narration`,`images`,`video`,`outputs`];case`style`:return[`video`];case`review`:return[`reviews`]}}function Y6(e,t,n,r=`article`){return t.find(t=>J6(t.field,r)===e?e===`title`?t.field===`title`?n.length>0:!n.some(e=>t.field===`values.${e}`):!0:!1)}function X_e(e,t,n){let r=e=>e===``?`no provider`:n.providers.find(t=>t.id===e)?.displayName??e,i=e=>e.filter(e=>typeof e==`string`&&e!==``).join(` · `);switch(e){case`title`:return i([n.topics.length?t.title:!1,n.keywords===0?`No keywords`:`${String(n.keywords)} keyword${n.keywords===1?``:`s`}`]);case`article`:return t.sources.article===`off`?`Off: no article`:t.sources.article===`provide`?`Your article`:i([t.articlePrompt||`No prompt picked`,t.llm.provider?`${r(t.llm.provider)} · ${t.llm.model||`no model`}`:!1,t.sources.research===`off`?`research off`:`research: ${DN[t.sources.research].toLowerCase()}`]);case`narration`:{if(t.sources.audio===`off`)return`Off, a silent video`;if(t.sources.audio===`provide`)return t.provided.audio?.name??`Your narration file`;let e=n.voices.find(e=>e.provider===t.audio.provider&&e.voiceId===t.audio.voice);return i([r(t.audio.provider),t.voices===void 0?e?.name??(t.audio.voice||`no voice`):`${bA[t.voices.format]}, ${String(t.voices.speakers.length)} speakers`,t.narrationPrompt?`prepared with ${t.narrationPrompt}`:!1,t.intro?`intro ${t.intro}`:!1,t.outro?`outro ${t.outro}`:!1])}case`images`:{if(t.sources.images===`off`)return`Off`;if(t.sources.images===`provide`)return`${String(t.provided.images.length)} of your images`;let e=t.imagePrompts.map(e=>`${e.name} × ${e.number||`?`}`);return i([e.length?e.join(`, `):`No image prompts picked`,r(t.images.provider),t.images.model,t.reference!==void 0&&t.reference.source!==`off`&&`establishing image`])}case`video`:return i([t.format,t.sources.video===`off`?`no video`:lA[hA(t).cuts].toLowerCase(),t.sources.video!==`off`&&n.look,t.sources.audio!==`off`&&t.subtitles.mode!==`off`?`captions ${n.fontName??t.subtitles.fontId} ${t.subtitles.fontSize} ${t.subtitles.position}`:`no captions`]);case`outputs`:return i([t.sources.thumbnail===`off`?!1:t.sources.thumbnail===`provide`?`your thumbnail`:t.thumbnailCount===3?`3 thumbnails`:`1 thumbnail`,wN(t)&&t.shorts?`${t.shorts.count} shorts`:!1,t.youtubeDescription===!0&&t.sources.audio!==`off`&&`YouTube description`,t.sources.document===`generate`&&`PDF (${sC(t.document)})`])||`Only the video`;case`reviews`:return i([n.checkpoints===0?`No checkpoints`:`${String(n.checkpoints)} checkpoint${n.checkpoints===1?``:`s`}`,n.reviews===0?`no automatic reviews`:`${String(n.reviews)} automatic review${n.reviews===1?``:`s`}`]);case`channel`:return i([n.channel??`Default channel`,n.brandKit?`brand kit on`:`brand kit off`,t.language===void 0?void 0:NO(t.language).name])}}function Z_e({review:e,blocker:t,errors:n,pendingUpload:r}){if(e.starting)return;if(e.uncertain)return{text:`Slopify didn't confirm the last start. Press Check Start result to find out before starting again.`};if(t)return{text:t.hint,field:t.field};let i=n[0];if(i)return{text:i.message,field:i.field};if(r)return{text:`Wait for uploads to finish before Start`,field:r};if(e.error)return{text:e.error};if(e.pending||!e.valid)return{text:`Checking your setup and the estimate…`}}function Q_e({errors:e,blocker:t,saveProblem:n,onReveal:r,onWholeSetup:i,onSaveTemplate:a,preview:o}){let s=XN(),{document:c,review:l}=s,u=HN(c,s.view),d=l.starting||l.uncertain;(0,m.useEffect)(()=>{s.reviewDraft()},[s.reviewDraft]);let f=!l.valid&&!l.pending&&!l.starting&&!l.uncertain&&l.error===null&&e.length===0&&t===void 0&&!u&&s.activeId!==null;(0,m.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>void s.reviewDraft(),800);return()=>clearTimeout(e)},[f,c,s.reviewDraft]);let p=l.valid&&l.receipt?l.receipt.runs.length:RN(c),g=Z_e({review:l,blocker:t,errors:e,pendingUpload:u}),_=l.starting||!l.uncertain&&(!l.valid||l.pending||e.length>0||!!u);return(0,h.jsxs)(h.Fragment,{children:[o,(0,h.jsxs)(`section`,{"aria-label":`Start`,className:`flex min-w-0 flex-col gap-4 border-t border-line pt-5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:p===1?`1 video`:`${String(p)} videos`}),p>1?(0,h.jsx)(Bb,{label:`Queue`,tip:`play.batch-queue`,checked:VN(c),disabled:d,onChange:e=>s.edit({...c,queue:e})}):(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`One run`})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Estimated cost`,info:`play.estimate`,size:`small`,className:`pb-0`}),l.valid&&l.receipt?(0,h.jsx)(N_e,{estimates:l.receipt.estimates}):(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.pending?`Calculating the estimate…`:`The estimate appears once the setup is complete.`}),(0,h.jsx)(LB,{label:`Expected article words per video`,tip:`play.expected-words`,className:`mt-2`,children:(0,h.jsx)(zB,{"data-play-field":`expectedWords`,type:`number`,min:1,max:1e5,value:c.expectedWords,disabled:d,onChange:e=>s.edit({...c,expectedWords:e.target.value})})})]}),n?(0,h.jsx)(aI,{tone:`danger`,title:n}):null,(0,h.jsxs)(Fy,{"data-tour":`play-start`,disabled:_,"aria-describedby":g?`play-start-reason`:void 0,onClick:()=>{s.startRun()},children:[(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75}),BN(l,c)]}),(0,h.jsx)(`div`,{id:`play-start-reason`,className:`min-h-5 text-center text-small`,children:g===void 0?(0,h.jsx)(`span`,{className:`text-ink-3`,children:p===1?`Nothing starts until you press it.`:VN(c)?`They run one after another. Nothing starts until you press it.`:`They all run at once. Nothing starts until you press it.`}):g.field===void 0?(0,h.jsx)(`span`,{role:l.error?`alert`:`status`,className:l.error?`text-danger`:`text-ink-2`,children:g.text}):(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center justify-center gap-x-1`,children:[(0,h.jsx)(`span`,{id:`play-start-field`,className:`text-waiting`,children:g.text}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-describedby":`play-start-field`,onClick:()=>r(g.field??``),children:`Go to the field`})]})}),(0,h.jsxs)(Iy,{className:`justify-center`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center`,children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:l.pending||d||!!u,onClick:()=>{s.reviewDraft()},children:`Refresh review`}),(0,h.jsx)(U,{id:`play.refresh-review`})]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-keyshortcuts":Ux(nP.reviewSetup),onClick:i,children:`Review the whole setup`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:a,children:`Save as template`})]})]})]})}function $_e(e,t,n){let r=e?.prompts??[],i=e?.entries??[];return{prompts:[...r,...t.filter(e=>!r.some(t=>t.kind===e.kind&&t.name.toLowerCase()===e.name.toLowerCase()))],entries:[...i,...n.filter(e=>!i.some(t=>t.category===e.category&&t.name.toLowerCase()===e.name.toLowerCase()))]}}function eve({topics:e,onError:t}){let{api:n}=V(),r=_(),i=XN(),a=I(lq(n)),o=I(cx(n)),[s,c]=(0,m.useState)(!1),l=i.review.starting||i.review.uncertain||i.review.created!==null,u=i.document.templateSource,d=a.data?.find(e=>e.id===u?.id),f=e=>o.data?.find(t=>t.id===e)?.name,p=async o=>{if(t(null),o===``){await i.newDraft();return}let s=a.data?.find(e=>e.id===o);if(s){c(!0);try{if(!await i.flush()){t(`Your draft wasn't saved, so the template wasn't applied. Press Retry beside Drafts, then pick the template again.`);return}let a=Object.fromEntries(e.map(e=>[e,i.document.form.values[e]??``]).filter(([,e])=>e.trim()!==``)),o=await _q(n,s,crypto.randomUUID());if(!o.ok){t(`The template "${s.name}" wasn't applied. ${o.message}`);return}if(await r.invalidateQueries({queryKey:[`play-drafts`]}),!await i.open(o.value.draft.id)){t(`The draft made from "${s.name}" didn't open. Open it from Drafts.`);return}let c=o.value.draft.document,l=Object.fromEntries(Object.entries(a).filter(([e])=>(c.form.values[e]??``)===``));Object.keys(l).length>0&&i.edit({...c,form:{...c.form,values:{...c.form.values,...l}}})}catch(e){t(e instanceof Error?`The template "${s.name}" wasn't applied. ${e.message}`:`The template "${s.name}" wasn't applied. Pick it again.`)}finally{c(!1)}}},g=a.error?`Templates didn't load. ${a.error.message}`:d?[f(E1(d)),`version ${String(d.version)}`].filter(Boolean).join(` · `):a.data?.length===0?`No templates yet. Set this video up, then Save as template.`:void 0;return(0,h.jsx)(LB,{label:`Template`,tip:`play.template`,help:g,children:(0,h.jsxs)(VB,{"data-play-field":`template`,value:d?.id??``,disabled:s||l,onChange:e=>void p(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:u&&!d?`Template no longer saved`:`No template`}),(a.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})}function tve({topics:e,problem:t}){let n=XN(),{document:r}=n,{form:i}=r,a=e=>{n.edit({...r,form:e}),n.invalidateReview(!0)};if(e.length===0)return(0,h.jsx)(LB,{label:`Title`,tip:`play.title`,error:t(`title`),children:(0,h.jsx)(zB,{"data-play-field":`title`,className:`!h-11 text-[17px]`,value:i.title,maxLength:200,placeholder:`What's the video about?`,"aria-invalid":t(`title`)!==void 0,onChange:e=>a({...i,title:e.target.value})})});let o=FK(i.title,i.values);return(0,h.jsx)(`div`,{className:`grid min-w-0 gap-4`,children:e.map((n,r)=>(0,h.jsx)(LB,{label:n,tip:`play.topic`,help:r===e.length-1?(0,h.jsxs)(h.Fragment,{children:[`Title: `,(0,h.jsx)(`b`,{className:`font-semibold text-ink`,children:o})]}):void 0,error:t(`values.${n}`)??(r===e.length-1?t(`title`):void 0),children:(0,h.jsx)(zB,{"data-play-field":`values.${n}`,className:`!h-11 text-[17px]`,value:i.values[n]??``,maxLength:200,spellCheck:!1,"aria-invalid":t(`values.${n}`)!==void 0,onChange:e=>a({...i,values:{...i.values,[n]:e.target.value}})})},n))})}function nve({topics:e,keywordNames:t,origins:n,problem:r,adding:i,onAdding:a,open:o,onOpen:s}){let c=XN(),{document:l}=c,{form:u}=l,[d,f]=(0,m.useState)(``),p=(0,m.useId)(),g=(0,m.useRef)(null),_=c.review.starting||c.review.uncertain,v=l.variants,y=e=>{c.edit({...l,variants:e})},b=e[0],x=e=>b===void 0?e.title:e.values[b]||e.title,S=()=>{let e=d.trim();e===``||v.length>=49||(y([...v,{id:crypto.randomUUID(),title:b===void 0?e:u.title,values:b===void 0?{...u.values}:{...u.values,[b]:e}}]),f(``),g.current?.focus())},C=v.findIndex(e=>e.id===o),w=C===-1?void 0:v[C];return(0,h.jsxs)(`section`,{"aria-label":`More videos from the same setup`,className:`min-w-0`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:`More videos from the same setup`}),(0,h.jsx)(U,{id:`play.more-videos`,className:`-my-1`})]}),(0,h.jsxs)(Iy,{className:`flex-wrap`,children:[v.map((e,n)=>{let i=x(e)||`Video ${String(n+2)}`,a=[`items.${String(n+1)}.title`,...t.map(e=>`items.${String(n+1)}.values.${e}`)].some(e=>r(e)!==void 0);return(0,h.jsx)(AS,{...a?{className:`border-danger`}:{},..._?{}:{onRemove:()=>y(v.filter(t=>t.id!==e.id)),removeLabel:`Remove ${i}`},children:(0,h.jsxs)(B,{variant:`quiet`,size:`small`,"data-play-field":`items.${e.id}`,className:`-my-1 -ml-1.5 h-6 px-1.5 text-ink`,"aria-label":`Change the keywords of ${i}`,onClick:()=>s(e.id),children:[i,(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75})]})},e.id)}),i?(0,h.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,h.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:b===void 0?`Title of another video`:`${b} of another video`}),(0,h.jsx)(zB,{ref:g,id:p,autoFocus:!0,className:`!h-8 w-48`,value:d,maxLength:200,placeholder:b===void 0?`Another title`:`Another ${b}`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(!1)}}),(0,h.jsx)(B,{type:`submit`,size:`small`,disabled:d.trim()===``,children:`Add`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>a(!1),children:`Done`})]}):(0,h.jsxs)(B,{variant:`quiet`,size:`small`,disabled:_||v.length>=49,disabledReason:_?`Wait for the start to finish`:`One Start queues at most 50 videos`,onClick:()=>a(!0),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add topic`]})]}),(0,h.jsx)(HP,{open:w!==void 0,title:w?`Video ${String(C+2)}: ${x(w)||`untitled`}`:``,width:`narrow`,onClose:()=>s(null),footer:(0,h.jsx)(B,{variant:`secondary`,onClick:()=>s(null),children:`Done`}),children:w?(0,h.jsxs)(`fieldset`,{disabled:_,className:`flex min-w-0 flex-col gap-5 border-0 p-0`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Everything else comes from the setup of the first video.`}),(0,h.jsx)(LB,{label:`Title`,tip:`play.title`,error:r(`items.${String(C+1)}.title`),children:(0,h.jsx)(zB,{"data-play-field":`items.${w.id}.title`,value:w.title,maxLength:200,onChange:e=>y(v.map(t=>t.id===w.id?{...t,title:e.target.value}:t))})}),(0,h.jsx)(V1,{fieldPrefix:`items.${w.id}.values`,keywords:t.map(t=>({name:t,value:w.values[t]??``,feeds:n.get(t)??[],topic:e.includes(t)})),problem:e=>r(e.replace(`items.${w.id}.`,`items.${String(C+1)}.`)),onChange:(e,t)=>y(v.map(n=>n.id===w.id?{...n,values:{...n.values,[e]:t}}:n))})]}):null})]})}function rve(){let e=Ji();return(0,h.jsx)(ive,{onCreated:t=>{e({to:`/projects/$projectId`,params:{projectId:t}})}})}function ive({onCreated:e}){let{api:t}=V(),n=$F(),r=I(db(t)),i=I(pb(t)),a=I(mb(t)),o=I(fb(t)),s=I(_b(t)),c=I(cx(t)),l=I(lq(t)),u=I({queryKey:eN,queryFn:()=>tN(t),staleTime:6e4}),[d,f]=tP(),p=R3(),g=XN(),{document:_}=g,v=$_e(_.librarySnapshot,i.data?.prompts??[],a.data?.entries??[]),y=_.variants.map(({id:e,...t})=>({...t,key:e})),b=g.fontUploading||_.fontUpload!==null,x=g.review.fields,[S,C]=(0,m.useState)(new Set),[w,T]=(0,m.useState)(new Set),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(!1),[M,ee]=(0,m.useState)(null),N=(0,m.useRef)(null),P=(0,m.useRef)(null),F=(0,m.useRef)(null),te=Ji(),ne=(0,m.useRef)(g.activeId);(0,m.useLayoutEffect)(()=>{ne.current!==g.activeId&&(ne.current=g.activeId,C(new Set),k(null))},[g.activeId]);let re=e=>{f(t=>{let n={...t,...e};return{...n,subtitles:xN(n.subtitles,n.sources)}}),g.invalidateReview(!0)},ie=s.data?.silenceGapSeconds??3,ae=_.form.silenceGapSeconds?.trim()??``,oe={form:d,prompts:v.prompts,entries:v.entries,silenceGapSeconds:ae===``?ie:Number(ae)},{fields:se,result:ce,blocker:le}=kfe(oe),ue=F1(oe),de=F3(d.title).filter(e=>se.some(t=>t.name===e)),fe=b?{field:`subtitles.fontUpload`,hint:`Wait for the subtitle font upload to finish to play`}:le;(0,m.useEffect)(()=>{if(!g.review.created)return;let t=g.takeCreated()?.projectIds[0];t&&(n({type:`project-created`,id:t}),e(t))},[g.review.created,g.takeCreated,n,e]);let pe=ce.ok?x:[...ce.fields,...x],me=(...e)=>!pe.some(t=>e.some(e=>t.field===e||t.field.startsWith(`${e}.`))),he=(e,t)=>v.prompts.some(n=>n.kind===e&&n.name===t),ge=e=>e?.file!==void 0&&e.error===void 0;QF({playArticleReady:me(`sources.article`,`articlePrompt`,`provided.article`)&&(d.sources.article===`provide`||he(`article`,d.articlePrompt)),playAudioReady:d.sources.audio===`off`||me(`sources.audio`,`audio`,`provided.audio`)&&(d.sources.audio!==`provide`||ge(d.provided.audio)),playImagesReady:d.sources.images===`off`||me(`sources.images`,`images`,`imagePrompts`,`provided.images`)&&(d.sources.images===`provide`?d.provided.images.every(ge):d.imagePrompts.every(e=>he(`image`,e.name))),playVideoReady:me(`sources.video`),playSubtitlesReady:me(`subtitles`)&&!b,playOptionsReady:me(`title`,`format`,`llm`,`intro`,`outro`),playHasKeywords:se.length>0,playKeywordsReady:me(`values`),playReady:fe===void 0&&!g.review.starting});let _e=kN(d,v.entries)[0]?.section??`article`,ve=e=>gge(e,d)??f_e(e,d,y,v.entries),ye=e=>{let t=ve(e).field;return pe.find(n=>ve(n.field).field===t&&(x.includes(n)||S.has(e)||S.has(t)))?.message},be=e=>{let t=ve(e);C(n=>new Set([...n,e,t.field])),g.navigate(t.field.startsWith(`items.`)?`content`:t.section,t.field)},xe=[r,i,a,o,s].every(e=>e.isSuccess||e.isError),Se=(0,m.useRef)(null),Ce=g.generation();(0,m.useEffect)(()=>{if(!xe)return;let e=Se.current;Se.current={generation:Ce,id:g.activeId},(e===null||e.generation!==Ce||e.id!==g.activeId&&e.id!==null)&&T(new Set(K6.map(e=>e.id).filter(e=>e!==`reviews`&&Y6(e,pe,de,_e)!==void 0)))},[xe,g.activeId,Ce]);let we=(0,m.useRef)(null);(0,m.useLayoutEffect)(()=>{let e=g.reveal;if(e||(we.current=null),!e||e.sequence===we.current||!N.current)return;let t=e.field,n=t?/^items\.([^.]+)(\.|$)/.exec(t)?.[1]:void 0;if(e.section===`review`){if(we.current=e.sequence,t&&I6(N.current,t))return;F.current?.focus();return}if(n!==void 0&&_.variants.some(e=>e.id===n)){if(O!==n){k(n);return}}else if(!(t&&de.some(e=>t===`values.${e}`))){let n=t?J6(t,_e):void 0,r=(n===void 0?Y_e(e.section):[n]).filter(e=>!w.has(e));if((t!==`title`||de.length!==0)&&r.length>0){T(e=>new Set([...e,...r]));return}}we.current=e.sequence,!(t&&I6(N.current,t))&&P.current?.focus()},[g.reveal,w,O]);let Te=async e=>{await g.flush()&&(e===`/prompts`?await te({to:`/prompts/new`,search:{kind:`article`}}):await te({to:e}))},Ee=()=>{g.navigate(`review`)},De=(e,t)=>{g.invalidateReview(!0),g.attach(e,t)},Oe=(e,t)=>{f(n=>({...n,provided:e===`images`?{...n.provided,images:n.provided.images.filter(e=>e.key!==t)}:{...n.provided,[e]:void 0}}))},ke=[r,i,a,o,s].find(e=>e.error!==null)?.error?.message,Ae=g.error?`Your draft wasn't saved. ${g.error}`:ke,je={form:d,providers:r.data?.providers??[],prompts:v.prompts,voices:o.data?.voices??[],silenceGapSeconds:s.data?.silenceGapSeconds??3,problem:ye,update:re,onPickFiles:De,onRemoveFile:Oe,onReattachFile:(e,t,n)=>{g.attach(e,[n],t)}},Me=l.data?.find(e=>e.id===_.templateSource?.id),Ne=_.channelId??(Me===void 0?`00000000-0000-4000-8000-000000000001`:E1(Me)),Pe=Object.values(_.form.reviews?.stages??{}).filter(e=>e.mode!==`off`).length,Fe={providers:r.data?.providers??[],voices:o.data?.voices??[],keywords:se.length,topics:de,channel:c.data?.find(e=>e.id===Ne)?.name,brandKit:_.form.useBrandKit!==!1,look:H6(_.form),fontName:u.data?.fonts.find(e=>e.id===d.subtitles.fontId)?.name,checkpoints:d.checkpoints?.length??0,reviews:Pe},Ie={title:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[de.length?(0,h.jsx)(LB,{label:`Title pattern`,tip:`play.title-pattern`,error:ye(`title`),children:(0,h.jsx)(zB,{"data-play-field":`title`,value:d.title,maxLength:200,"aria-invalid":ye(`title`)!==void 0,onChange:e=>re({title:e.target.value})})}):null,(0,h.jsx)(p_e,{fields:se,origins:ue,topics:de,hide:de,values:d.values,problem:ye,onChange:(e,t)=>re({values:{...d.values,[e]:t}})}),se.length===de.length?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:se.length===0?`No keywords. A prompt or the title that names {{a keyword}} adds one here.`:`The only keywords are the topic, typed at the top.`}):null]}),article:(0,h.jsx)(u_e,{...je,entries:v.entries,onLibrary:e=>{Te(e)}}),narration:(0,h.jsx)(T_e,{...je,entries:v.entries,onKeyword:be,onSettings:()=>{Te(`/settings`)}}),images:(0,h.jsx)(E_e,{...je}),video:(0,h.jsx)(D_e,{...je,problemOf:ye}),outputs:(0,h.jsx)(O_e,{...je,entries:v.entries,onSettings:()=>{Te(`/settings`)}}),reviews:void 0,channel:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(mge,{}),(0,h.jsx)(hge,{})]})},Le=K6.filter(e=>e.id!==`narration`||d.sources.article!==`off`),Re=Le.map(e=>({id:e.id,label:e.label,summary:X_e(e.id,d,Fe),problem:Y6(e.id,pe,de,_e)?.message,editor:Ie[e.id]})),ze=(e,t)=>{if(e===`reviews`){Ee();return}T(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},Be=e=>{ze(e,!0),requestAnimationFrame(()=>{N.current?.querySelector(`[data-setup-row="${e}"]`)?.scrollIntoView({block:`start`,behavior:`smooth`})})},Ve=_.variants.length+1,He=HN(_,g.view),Ue=!g.review.starting&&(g.review.uncertain||g.review.valid&&!g.review.pending&&pe.length===0&&!He);jx({id:`play.start`,title:BN(g.review,_),group:`Play`,context:d.title||`New project`,keywords:[`start`,`queue`,`run`,`play`,`go`],run:()=>{Ue?g.startRun():fe?be(fe.field):pe[0]&&be(pe[0].field)}}),jx({id:`play.add-topic`,title:`Add a topic for another video`,group:`Play`,context:`${String(Ve)} video${Ve===1?``:`s`}`,keywords:[`more videos`,`variation`,`batch`,`queue`],run:()=>D(!0)}),jx({id:`play.save-template`,title:`Save as template`,group:`Play`,keywords:[`template`,`setup`,`reuse`],run:()=>j(!0)}),jx({id:`play.review`,title:`Review the whole setup`,group:`Play`,keywords:[`summary`,`checkpoints`,`prompt`],shortcut:nP.reviewSetup,run:Ee}),jx({id:`play.template`,title:`Pick a template`,group:`Play`,keywords:[`template`,`setup`],run:()=>{N.current&&I6(N.current,`template`)}});let We=d.sources.video===`generate`&&d.sources.images!==`off`,Ge=j_e(d,p),Ke=We?(0,h.jsx)(w6,{drawnOn:Ge?.drawnOn,settings:{format:d.format,subtitles:{mode:d.sources.audio===`off`?`off`:d.subtitles.mode,fontId:d.subtitles.fontId,fontSize:Number(_.form.subtitles.fontSize)||d.subtitles.fontSize,position:d.subtitles.position},videoEdit:d.videoEdit,previewText:_.previewText,image:Ge?.image}}):null;return(0,h.jsxs)(`div`,{ref:N,onBlurCapture:e=>{let t=e.target.dataset.playField;t&&C(e=>new Set([...e,t]))},"data-play-grid":`true`,className:`min-w-0 max-[767px]:[&_button]:min-h-11 max-[767px]:[&_input:not([type=checkbox])]:min-h-11 max-[767px]:[&_select]:min-h-11 max-[767px]:[&_summary]:min-h-11`,children:[(0,h.jsx)(XK,{crumb:`New project`,title:(0,h.jsx)(`span`,{ref:P,tabIndex:-1,children:`What's the video about?`}),meta:d.title.trim()===``?`Untitled draft`:d.title,actions:(0,h.jsx)(d_e,{})}),(0,h.jsx)(I3,{onDefaults:g.adoptDefaults}),(0,h.jsxs)(ZK,{className:`sl-workspace--play`,aside:(0,h.jsx)(Q_e,{errors:pe,blocker:fe,saveProblem:Ae,onReveal:be,onWholeSetup:Ee,onSaveTemplate:()=>j(!0),preview:Ke}),asideLabel:`Review and start`,children:[(0,h.jsxs)(`div`,{"data-tour":`play-options`,className:`grid min-w-0 grid-cols-1 items-start gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(eve,{topics:de,onError:ee}),(0,h.jsx)(tve,{topics:de,problem:ye})]}),(0,h.jsx)(K_e,{topics:de}),M?(0,h.jsx)(aI,{tone:`danger`,title:M}):null,(0,h.jsx)(nve,{topics:de,keywordNames:se.map(e=>e.name),origins:ue,problem:ye,adding:E,onAdding:D,open:O,onOpen:k}),(0,h.jsx)(q_e,{rows:Re,open:w,onChange:ze})]}),(0,h.jsx)(HP,{open:g.section===`review`,title:`Review`,headingRef:F,onClose:()=>{g.navigate(`content`)},children:(0,h.jsx)(z_e,{fields:se,errors:pe,problem:ye,onReveal:be})}),(0,h.jsx)(V_e,{open:A,onClose:()=>j(!1)}),Le.map(e=>(0,h.jsx)(ave,{id:e.id,label:e.label,onOpen:Be},e.id))]})}function ave({id:e,label:t,onOpen:n}){return jx({id:`play.row.${e}`,title:`Change ${t.toLowerCase()}`,group:`Play`,keywords:[`open`,`edit`,`section`,t],run:()=>n(e)}),null}function ove(){let{api:e}=V(),t=I({queryKey:[`batch-queue`],queryFn:async()=>R(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=I(ob(e)),r=t.data?.queue.length??0;return(0,h.jsxs)(Nb,{children:[(0,h.jsx)(Pb,{asChild:!0,children:(0,h.jsxs)(B,{variant:`quiet`,disabled:r===0,"aria-label":`Video queue: ${r} remaining`,children:[(0,h.jsx)(zc,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,r]})]})}),(0,h.jsxs)(Lb,{align:`end`,className:`p-0`,children:[(0,h.jsx)(`p`,{className:`border-b border-line px-3 py-2 text-small text-ink-2`,children:wb(`play.queue`).body}),(0,h.jsx)(sve,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function sve({queue:e,projects:t}){return(0,h.jsx)(`ol`,{className:`max-h-40 overflow-y-auto px-4 py-2`,children:e.map((e,n)=>{let r=t?.find(t=>t.id===e.projectId);return(0,h.jsxs)(`li`,{className:`flex justify-between gap-3 py-1 text-small`,children:[(0,h.jsxs)(fa,{className:`truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[n+1,`. `,r?.title??`Video`]}),(0,h.jsx)(`span`,{className:`shrink-0 text-ink-2`,children:r?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`})]},e.projectId)})})}function X6({label:e,className:t,children:n}){return(0,h.jsx)(`nav`,{"aria-label":e,className:z(`sl-rail`,t),children:n})}function cve({icon:e,meta:t,children:n}){return(0,h.jsxs)(h.Fragment,{children:[e,(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:n}),t===void 0?null:(0,h.jsx)(`span`,{className:`sl-rail__meta`,children:t})]})}function Z6({icon:e,meta:t,current:n=!1,onClick:r,className:i,children:a,"data-tour":o}){return(0,h.jsx)(`button`,{type:`button`,"data-tour":o,"aria-current":n?`true`:void 0,onClick:r,className:z(`sl-rail__item w-full border-0 bg-transparent text-left font-[inherit]`,n&&`bg-accent-tint font-semibold text-ink`,i),children:(0,h.jsx)(cve,{icon:e,meta:t,children:a})})}var Q6=/^(?:[-*+]|\d+[.)])\s+/u;function lve(e){let t=e.split(/\r?\n/u).filter(e=>e.trim()!==``),n=[];for(let e of t.slice(1)){let t=e.trim().replace(Q6,``).trim(),r=n.length-1;/^\s/u.test(e)&&!Q6.test(e.trim())&&r>=0?n[r]=`${n[r]??``} ${t}`:t!==``&&n.push(t)}return n}var uve={blockquote:n8,break:hve,code:r8,definition:r8,delete:n8,emphasis:n8,footnoteReference:r8,footnoteDefinition:r8,heading:mve,html:r8,image:e8,imageReference:e8,inlineCode:t8,list:n8,listItem:n8,link:n8,linkReference:n8,strong:n8,table:r8,tableCell:r8,text:t8,thematicBreak:r8,toml:r8,yaml:r8},dve={},$6=[];function fve(e){let t={...uve},n=e||dve,r=n.keep||$6,i=n.remove||$6,a=-1;for(;++a<i.length;){let e=i[a];typeof e==`string`?t[e]=r8:t[e[0]]=e[1]}let o={};if(r.length===0)o=t;else{let e;for(e in t)r.includes(e)||(o[e]=t[e]);for(a=-1;++a<r.length;)if(e=r[a],!Object.hasOwn(t,e))throw Error("Unknown node type `"+e+"` in `keep`, use a replace tuple with a handle instead: `remove: [['"+e+"', handle]]`")}return function(e){return s(e)};function s(e){let t=e.type,n=e;if(Object.hasOwn(o,t)){let e=o[t];e&&(n=e(n)||void 0)}return n=Array.isArray(n)?c(n):n,n&&`children`in n&&(n.children=c(n.children)),n}function c(e){let t=-1,n=[];for(;++t<e.length;){let r=s(e[t]);Array.isArray(r)?n.push(...c(r)):r&&n.push(r)}return pve(n)}}function pve(e){let t=-1,n=[],r;for(;++t<e.length;){let i=e[t];r&&i.type===r.type&&`value`in i&&`value`in r?r.value+=i.value:(n.push(i),r=i)}return n}function e8(e){let t=`title`in e?e.title:``,n=e.alt||t||``;return n?{type:`text`,value:n}:void 0}function t8(e){return{type:`text`,value:e.value}}function mve(e){return{type:`paragraph`,children:e.children}}function n8(e){return e.children}function hve(){return{type:`text`,value:`
284
- `}}function r8(){}var gve=64,i8=new Map;function _ve(e){let t=i8.get(e);if(t!==void 0)return t;let n=vve(e);for(i8.set(e,n);i8.size>gve;){let e=i8.keys().next().value;if(e===void 0)break;i8.delete(e)}return n}function vve(e){let t=$3().use(Bz).use(fve),n=t.runSync(t.parse(e)).children.map(e=>{if(e.type!==`paragraph`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.children.map(e=>{if(e.type!==`text`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.value}).join(``)}).filter(e=>e.trim()!==``);return n.length===0?``:n.join(`
281
+ `).entries()){let e=n.trim(),c=t+1;if(e===``){s=!1;continue}let l=Ige.exec(e);if(l!==null){o.push({title:s6(l[1]??``),firstTurn:a.length+1}),s=!1;continue}if(/^([-*_=~])\1{2,}$/.test(e)){s=!1;continue}let u=Lge.exec(e),d=u===null?void 0:r.get((u[1]??``).trim().toLowerCase());if(u!==null&&d!==void 0){a.push({speaker:d.id,lines:[u[2]??``],section:o.length-1}),s=!0;continue}let f=a.at(-1);if(s&&f!==void 0){f.lines.push(e);continue}return{ok:!1,reason:u===null?`Line ${String(c)} of the script is not a turn. Start every turn with a speaker's name and a colon (${i}), one turn per paragraph.`:`Line ${String(c)} of the script is spoken by "${(u[1]??``).trim()}", who is not one of the speakers (${i}). Use only these names, or add the speaker under Speakers (Play → Narration, or Edit project → Providers).`}}let c=[];for(let e of a){let t=s6(e.lines.join(` `));t!==``&&c.push({index:c.length+1,speaker:e.speaker,text:t,section:e.section,...n?{markdown:e.lines.join(`
282
+ `)}:{}})}if(c.length===0)return{ok:!1,reason:`The script has no spoken turns. Write each turn as a speaker's name, a colon and their words (${i}).`};let l=[],u=new Map;for(let[e,t]of o.entries()){let n=c.find(t=>t.section===e);n!==void 0&&t.title!==``&&(u.set(e,l.length),l.push({title:t.title,firstTurn:n.index}))}return{ok:!0,script:{turns:c.map(e=>({...e,section:u.get(e.section)??-1})),sections:l}}}function s6(e){return e.replace(/\[[^\]]*\]\([^)]*\)/g,e=>e.slice(1,e.indexOf(`]`))).replace(/\[[^\]]*\]/g,` `).replace(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g,`$2`).replace(/`/g,``).replace(/\s+/g,` `).trim()}var Rge={narrator:`Narrator`,host:`Host`,guest:`Guest`,character:`Character`};function c6({value:e,onChange:t,providers:n,voices:r,script:i,problem:a,cast:o=[],language:s}){let c=(0,m.useMemo)(()=>{if(e===void 0||i===void 0||i.trim()===``)return;let t=o6(i,e.speakers);return t.ok?t.script:void 0},[i,e]),l=n=>{if(n===``){t(void 0);return}let r=yA.find(e=>e===n);r!==void 0&&t(e===void 0?MA(r,Mge(o)):{...e,format:r,source:r===`audiobook`?e.source:`script`})},u=n=>{e!==void 0&&t({...e,...n})},d=o.filter(t=>t.voice!==void 0&&!(e?.speakers??[]).some(e=>e.castId===t.id)),f=(t,n)=>{e!==void 0&&u({speakers:e.speakers.map((e,r)=>r===t?n:e)})};return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-3`,"data-play-field":`voices`,children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(ZB,{field:`voices.format`,label:`Format`,tip:`play.speakers.format`,value:e?.format??``,placeholder:`Narration (one voice)`,options:yA.map(e=>({value:e,label:bA[e]})),problem:a?.(`voices.format`),onPick:l}),e?.format===`audiobook`?(0,h.jsx)(ZB,{field:`voices.source`,label:`Script`,tip:`play.speakers.script`,value:e.source,placeholder:`Pick where the script comes from`,options:[{value:`script`,label:`Write a script (Script prompt)`},{value:`attribute`,label:`Split the article into speakers`}],problem:a?.(`voices.source`),onPick:e=>u({source:e===`attribute`?`attribute`:`script`})}):null]}),e===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`One voice reads the article. Pick a format for an audiobook, podcast, radio drama or interview with several speakers.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.source===`script`?"The article prompt must be a Script prompt: the text model writes speaker turns, one `Name: words` paragraph each.":`The article is written or pasted as usual; the text model then hands its narration and dialogue to the speakers.`}),a?.(`voices.speakers`)===void 0?null:(0,h.jsx)(`p`,{className:`text-label text-danger`,children:a(`voices.speakers`)}),(0,h.jsx)(`ol`,{"aria-label":`Speakers`,className:`divide-y divide-line border-y border-line`,children:e.speakers.map((t,i)=>(0,h.jsx)(Hge,{index:i,speaker:t,line:Age(t,c),providers:n,voices:r,language:s,problem:a,onChange:e=>f(i,e),onRemove:e.speakers.length>1?()=>u({speakers:e.speakers.filter((e,t)=>t!==i)}):void 0},t.id))}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsx)(B,{type:`button`,disabled:e.speakers.length>=10,onClick:()=>u({speakers:[...e.speakers,Vge(e.speakers)]}),children:`Add speaker`}),(0,h.jsx)(ZB,{label:`Add from the cast`,tip:`play.speakers.add-from-cast`,value:``,placeholder:d.length===0?`No cast member has a voice yet`:`Pick one of ${String(d.length)}`,options:d.map(e=>({value:e.id,label:e.name})),disabled:d.length===0||e.speakers.length>=10,problem:void 0,onPick:t=>{let n=d.find(e=>e.id===t);n!==void 0&&u({speakers:[...e.speakers,a6(n,Bge(e))]})}}),(0,h.jsx)(ZB,{field:`voices.turnGapSeconds`,label:`Gap between turns`,tip:`play.speakers.turn-gap`,value:String(e.turnGapSeconds),placeholder:`Pick a gap`,options:wA.map(e=>({value:String(e),label:`${e} s`})),problem:a?.(`voices.turnGapSeconds`),onPick:e=>u({turnGapSeconds:Number(e)})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,h.jsx)(Bb,{label:`Speaker names on captions`,tip:`play.speakers.name-tags`,checked:e.nameTags,onChange:e=>u({nameTags:e})}),(0,h.jsx)(Bb,{label:`One request for consecutive turns where the voice provider can (ElevenLabs v3, Gemini)`,tip:`play.speakers.native-dialogue`,checked:e.nativeDialogue,onChange:e=>u({nativeDialogue:e})}),(0,h.jsx)(Bb,{label:`Also make MP3 and M4B files with chapter markers`,tip:`play.speakers.audio-files`,checked:e.audioFiles,onChange:e=>u({audioFiles:e})})]}),e.format===`audiobook`?(0,h.jsx)(zge,{value:e,onChange:t,problem:a}):null,e.format===`podcast`||e.format===`interview`?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The speaker panel (a tile per speaker, the one talking lit, their name below) is drawn with the captions: set Captions to Burn in under Style to see it in the video.`}):null]})]})}function zge({value:e,onChange:t,problem:n}){let r=e.book,i=n=>t({...e,...n});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(Bb,{label:`A chapter of a book`,tip:`play.speakers.book`,checked:r!==void 0,onChange:n=>{if(n)i({book:{title:``,chapter:1}});else{let{book:n,...r}=e;t(r)}}}),r===void 0?null:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-[minmax(0,1fr)_160px]`,children:[(0,h.jsx)(LB,{label:`Book title`,tip:`play.speakers.book-title`,error:n?.(`voices.book.title`),children:(0,h.jsx)(zB,{value:r.title,maxLength:200,onChange:e=>i({book:{...r,title:e.target.value}})})}),(0,h.jsx)(LB,{label:`Chapter`,tip:`play.speakers.book-chapter`,error:n?.(`voices.book.chapter`),children:(0,h.jsx)(zB,{type:`number`,min:1,max:OA,step:1,value:r.chapter===0?``:String(r.chapter),onChange:e=>i({book:{...r,chapter:Number(e.target.value)||0}})})})]})]})}function Bge(e){return e.format===`podcast`?`host`:e.format===`interview`?e.speakers.some(e=>e.role===`host`)?`guest`:`host`:e.speakers.some(e=>e.role===`narrator`)?`character`:`narrator`}function Vge(e){let t=e.length+1;for(;e.some(e=>e.id===`speaker-${String(t)}`);)t+=1;return{id:`speaker-${String(t)}`,name:`Speaker ${String(t)}`,role:`character`,voice:{provider:``,model:``,voice:``}}}function Hge({index:e,speaker:t,line:n,providers:r,voices:i,language:a,problem:o,onChange:s,onRemove:c}){let l=`voices.speakers.${String(e)}`,u=t.voice,d=i.filter(e=>e.provider===u.provider),f=f2(d,a,u.voice||void 0),p=a===void 0?d:f.listed,g=t.name.trim()||`this speaker`,_=(0,m.useMemo)(()=>kge([t],a??`und`)[0]?.skipped??[],[t,a]);return(0,h.jsxs)(`li`,{className:`grid grid-cols-1 gap-3 py-3 min-[700px]:grid-cols-2`,"data-play-field":l,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-end gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`mb-2 size-3 shrink-0 rounded-full`,style:{background:`var(--color-speaker-${String(e%6+1)})`}}),(0,h.jsx)(LB,{label:`Speaker name`,tip:`play.speaker.name`,error:o?.(`${l}.name`),className:`min-w-0 flex-1`,children:(0,h.jsx)(zB,{value:t.name,maxLength:40,onChange:e=>s({...t,name:e.target.value})})})]}),(0,h.jsx)(ZB,{label:`Role`,tip:`play.speaker.role`,value:t.role,placeholder:`Pick a role`,options:xA.map(e=>({value:e,label:Rge[e]})),problem:void 0,onPick:e=>{let n=xA.find(t=>t===e);n!==void 0&&s({...t,role:n})}}),(0,h.jsx)(eV,{field:`${l}.voice`,label:`Voice provider`,tip:`play.speaker.provider`,family:`tts`,providers:r,value:u.provider,problem:o?.(`${l}.voice`),onPick:e=>s({...t,voice:{provider:e,model:``,voice:``}})}),(0,h.jsx)(tV,{label:`Voice model`,tip:`play.speaker.model`,provider:u.provider,value:u.model,problem:void 0,onPick:e=>s({...t,voice:{...u,model:e}})}),(0,h.jsx)(ZB,{field:`${l}.voice.voice`,label:`Voice`,tip:`play.speaker.voice`,value:u.voice,placeholder:p.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:p.map(e=>({value:e.voiceId,label:e.name})),problem:o?.(`${l}.voice.voice`),onPick:e=>s({...t,voice:{...u,voice:e}})}),a===void 0?null:(0,h.jsx)(p2,{language:a,voice:d.find(e=>e.voiceId===u.voice),hidden:f.hidden,showAll:f.showAll,onShowAll:f.setShowAll}),(0,h.jsx)(ZB,{field:`${l}.pace`,label:`Pace`,tip:`play.speaker.pace`,value:String(t.pace??1),placeholder:`Pick a pace`,options:CA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:o?.(`${l}.pace`),onPick:e=>{let{pace:n,...r}=t;s(Number(e)===1?r:{...r,pace:Number(e)})}}),(0,h.jsxs)(`details`,{className:`col-span-full text-small`,...zb,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-ink-2`,children:[`Pronunciations for `,t.name.trim()||`this speaker`,t.pronunciations?.trim()?` · set`:``,(0,h.jsx)(U,{id:`play.speaker.pronunciations`})]}),(0,h.jsx)(BB,{rows:3,"aria-label":`Pronunciations for ${t.name.trim()||`this speaker`}`,value:t.pronunciations??``,placeholder:`Arda: /ˈɑɹdə/`,onChange:e=>{let{pronunciations:n,...r}=t;s(e.target.value===``?r:{...r,pronunciations:e.target.value})}})]}),_.length===0?null:(0,h.jsxs)(aI,{tone:`waiting`,className:`col-span-full`,title:`${String(_.length)} ${_.length===1?`pronunciation`:`pronunciations`} for ${g} ${_.length===1?`is`:`are`} skipped`,children:[(0,h.jsx)(`ul`,{children:_.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsxs)(`p`,{children:[`Those words are read as ordinary text; the other entries are used. Fix them in Pronunciations for `,g,` above: one `,(0,h.jsx)(`code`,{children:`Term: /IPA/`}),` per line.`]})]}),(0,h.jsxs)(`div`,{className:`col-span-full flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(Wge,{speaker:t,line:n}),(0,h.jsx)(`span`,{className:`flex-1`}),c===void 0?null:(0,h.jsxs)(B,{type:`button`,variant:`quiet`,onClick:c,children:[`Remove `,t.name.trim()||`speaker`]})]})]})}var Uge=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:4});function Wge({speaker:e,line:t}){let{api:n}=V(),{provider:r,model:i,voice:a}=e.voice,o=r!==``&&i!==``&&a!==``,s=I({queryKey:[`audition-quote`,r,i,t],queryFn:()=>nc(n,[{speaker:e.name.trim()||`Speaker`,provider:r,model:i,text:t}]),enabled:o,staleTime:6e4}),[c,l]=(0,m.useState)(void 0);(0,m.useEffect)(()=>()=>{c!==void 0&&URL.revokeObjectURL(c)},[c]);let u=L({mutationFn:()=>rc(n,{provider:r,model:i,voice:a,text:t}),onSuccess:e=>{let t=URL.createObjectURL(e);l(t),new Audio(t).play().catch(()=>{})}}),d=s.data?.estimate,f=d==null?void 0:d.unknown>0?`price unknown`:`about ${Uge.format(d.high)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,disabled:!o||u.isPending,onClick:()=>u.mutate(),title:`Reads: ${t}`,children:u.isPending?`Speaking…`:`Audition${f===void 0?``:` · ${f}`}`}),(0,h.jsx)(U,{id:`play.speaker.audition`})]}),(0,h.jsx)(`span`,{className:`min-h-5 text-label text-ink-2`,"aria-live":`polite`,children:o?u.error===null?c===void 0?`Reads their first line: “${t.length>60?`${t.slice(0,60)}…`:t}”`:`Playing the audition.`:u.error.message:`Pick a provider, model and voice to audition.`})]})}function Gge(e){return e===void 0?`Narration`:bA[e]}function l6({value:e,skipCode:t,onChange:n,tip:r=`play.describe-figures`}){let i=(0,m.useId)(),a=e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.describeFigures`,checked:a,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:e.currentTarget.checked,skipCode:t===!0})}),`Describe tables and figures in the narration`]}),(0,h.jsx)(U,{id:r})]}),a?(0,h.jsxs)(`span`,{className:`flex items-center gap-1 pl-7`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-code`,className:`flex min-h-10 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-code`,type:`checkbox`,"data-play-field":`audio.skipCode`,checked:t===!0,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:!0,skipCode:e.currentTarget.checked})}),`Leave code out`]}),(0,h.jsx)(U,{id:`play.skip-code`})]}):null]})}function u6({value:e,onChange:t,tip:n=`play.show-figures`}){let r=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`showFigures`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Show tables and figures on screen`]}),(0,h.jsx)(U,{id:n})]})}function d6({value:e,onChange:t,note:n}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`audio.useNarrationAliases`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Use narration aliases`]}),(0,h.jsx)(U,{id:`play.narration-aliases`})]}),n===void 0?null:(0,h.jsx)(`div`,{className:`pl-7`,children:n})]})}function f6({value:e,prompts:t,supported:n,error:r,libraryLinks:i=!0,onChange:a}){let o=(0,m.useId)(),s=t.filter(e=>e.kind===`narration`),c=s.find(t=>t.name===e),l=r??(e!==``&&!n?`Choose Inworld TTS-2 or turn preparation Off.`:void 0);return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:o,className:`text-small font-semibold`,children:`Narration Preparation`}),(0,h.jsx)(U,{id:`play.narration-preparation`})]}),(0,h.jsxs)(UB,{id:o,"data-play-field":`narrationPrompt`,value:e,"aria-describedby":l?`${o}-error`:void 0,"aria-invalid":l!==void 0||void 0,onChange:e=>a(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),e!==``&&c===void 0?(0,h.jsxs)(`option`,{value:e,children:[e,` (saved selection)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`text-small text-danger`,children:l}):null,i?(0,h.jsxs)(`div`,{className:`flex gap-4 text-small`,children:[(0,h.jsx)(fa,{to:`/prompts/new`,search:{kind:`narration`},children:`Create prompt`}),c?(0,h.jsx)(fa,{to:`/prompts/$promptId`,params:{promptId:c.id},children:`View prompt`}):null]}):null]})}function p6({value:e,supported:t,onChange:n,shared:r}){let i=(0,m.useId)(),a=t&&e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.usePronunciationGlossary`,checked:e===!0,disabled:!t,"aria-describedby":t?void 0:`${i}-support`,className:`size-4 accent-accent`,onChange:e=>n(e.currentTarget.checked)}),`Use Pronunciation Glossary`]}),(0,h.jsx)(U,{id:`play.pronunciation-glossary`})]}),r===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-1 pl-7`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-shared`,className:`flex min-h-8 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-shared`,type:`checkbox`,"data-play-field":`audio.shareGlossary`,checked:r.value===!0,disabled:!a,className:`size-4 accent-accent`,onChange:e=>r.onChange(e.currentTarget.checked)}),`Also use pronunciations from my other projects`]}),(0,h.jsx)(U,{id:`play.share-glossary`})]}),r.note===void 0?null:r.note]}),t?null:(0,h.jsx)(`p`,{id:`${i}-support`,className:`text-label text-ink-3`,children:`Unavailable for this provider or model. Your saved preference is retained.`})]})}var m6={source:`off`,prompt:``,thumbnail:!0},Kge=[{value:`prompt`,label:`From a prompt`},{value:`provide`,label:`Upload`}];function h6({value:e,prompts:t,problem:n,upload:r,prompt:i,onChange:a}){let o=(0,m.useId)(),s=e.source===`off`,c=t.filter(e=>e.kind===`image`).map(e=>({value:e.name,label:e.name}));return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsx)(`div`,{className:`min-w-0`,children:(0,h.jsx)(ZB,{field:`reference.source`,label:`Establishing image`,tip:`play.reference`,value:s?``:e.source,placeholder:`Off`,options:Kge,problem:n?.(`reference.source`),onPick:t=>a({...e,source:t===`prompt`||t===`provide`?t:`off`})})}),e.source===`provide`?(0,h.jsx)(`div`,{className:`min-w-0`,children:r}):i??(0,h.jsx)(ZB,{field:`reference.prompt`,label:`Establishing prompt`,tip:`play.reference.prompt`,value:e.prompt,placeholder:s?`Off`:`Pick an image prompt`,options:c,disabled:s,problem:n?.(`reference.prompt`),onPick:t=>a({...e,prompt:t})}),(0,h.jsxs)(`div`,{className:`col-span-full flex min-h-9 items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:o,className:`flex cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{id:o,type:`checkbox`,"data-play-field":`reference.thumbnail`,checked:e.thumbnail,disabled:s,onChange:t=>a({...e,thumbnail:t.target.checked})}),`Draw the thumbnail from it too`]}),(0,h.jsx)(U,{id:`play.reference.thumbnail`})]})]})}function g6({choice:e,onChange:t,field:n=`llm.thinking`,label:r=`Thinking`,tip:i=`play.llm.thinking`,problem:a}){let{api:o}=V(),s=I(KB(o,e.provider)).data?.models.find(t=>t.id===e.model)?.thinkingModes??[];if(!s.length&&!e.thinking)return null;let c=r===`Thinking`?`thinking level`:r.toLowerCase();return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(ZB,{field:n,label:r,tip:i,value:e.thinking??`default`,placeholder:`Model default`,problem:e.thinking&&!s.includes(e.thinking)?`Choose a supported ${c}.`:a,options:[{value:`default`,label:`Model default`},...e.thinking&&!s.includes(e.thinking)?[{value:e.thinking,label:`${e.thinking} (saved level)`}]:[],...s.map(e=>({value:e,label:e===`off`?`Off`:e.charAt(0).toUpperCase()+e.slice(1)}))],onPick:n=>{let r=s.find(e=>e===n),{thinking:i,...a}=e;t(r===void 0?a:{...a,thinking:r})}}),r===`Thinking`&&s.length&&!s.includes(`off`)?(0,h.jsx)(`p`,{className:`mt-1 text-small text-ink-3`,children:`This model does not support turning thinking off.`}):null]})}function qge({form:e,prompts:t,providers:n,voices:r,problem:i,update:a,onPickFiles:o,onRemoveFile:s,onReattachFile:c,rawCounts:l,advanced:u,cast:d,language:f,titled:p}){let g=r.filter(t=>t.provider===e.audio.provider),_=f2(g,f??`en`,e.audio.voice||void 0),v=f===void 0?g:_.listed,y=e.voices?.speakers.find(e=>e.voice.provider&&e.voice.model&&e.voice.voice)?.voice,b=e.intro!==``||e.outro!==``,x=e.voices!==void 0&&!b&&y!==void 0;(0,m.useEffect)(()=>{if(!x||y===void 0)return;let t=e.audio;(t.provider!==y.provider||t.model!==y.model||t.voice!==y.voice)&&a({audio:{...t,provider:y.provider,model:y.model,voice:y.voice}})},[x,y,e.audio,a]);let S=e.voices!==void 0,C=[e.chunking.mode,e.intro?`intro ${e.intro}`:void 0,e.outro?`outro ${e.outro}`:void 0,e.narrationPrompt?`preparation on`:void 0,e.audio.usePronunciationGlossary?`glossary on`:void 0].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(X3,{kind:`audio`,name:`Audio`,dim:e.sources.audio===`off`,titled:p,children:[(0,h.jsx)(Z3,{kind:`audio`,form:e,update:a}),(0,h.jsx)(`div`,{className:J3,children:e.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[x?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{field:`audio.provider`,label:S?`Intro and outro TTS`:`TTS`,tip:`play.tts.provider`,family:`tts`,providers:n,value:e.audio.provider,problem:i(`audio`),onPick:t=>{a({audio:{...e.audio,provider:t,model:``,voice:``}})}}),(0,h.jsx)(tV,{field:`audio.model`,label:`TTS model`,tip:`play.tts.model`,provider:e.audio.provider,value:e.audio.model,problem:i(`audio.model`),onPick:t=>a({audio:{...e.audio,model:t}})}),(0,h.jsx)(ZB,{field:`audio.voice`,label:S?`Intro and outro voice`:`Voice`,tip:`play.voice`,value:e.audio.voice,placeholder:v.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:v.map(e=>({value:e.voiceId,label:e.name})),problem:i(`audio.voice`),onPick:t=>{a({audio:{...e.audio,voice:t}})}}),f===void 0?null:(0,h.jsx)(p2,{language:f,voice:g.find(t=>t.voiceId===e.audio.voice),hidden:_.hidden,showAll:_.showAll,onShowAll:_.setShowAll}),S?(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`This voice reads only the intro and outro. Each speaker's voice is set under Speakers.`}):null]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Speakers ·`,` `,e.voices===void 0?`Narration, one voice`:`${Gge(e.voices.format)}, ${String(e.voices.speakers.length)} ${e.voices.speakers.length===1?`speaker`:`speakers`}`]}),(0,h.jsx)(`div`,{className:`pt-2 pb-3`,children:(0,h.jsx)(c6,{value:e.voices,providers:n,voices:r,script:e.sources.article===`provide`?e.provided.article:void 0,problem:i,cast:d,language:f,onChange:e=>a({voices:e})})})]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Audio Advanced · `,C]}),(0,h.jsxs)(`div`,{className:`sl-fields pt-2 pb-3`,children:[(0,h.jsx)(`div`,{className:`col-span-full`,children:(0,h.jsx)(U3,{...l?{rawCounts:l}:{},value:e.chunking,onPick:e=>{a({chunking:e})}})}),u,(0,h.jsx)(f6,{value:e.narrationPrompt??``,prompts:t,supported:e.audio.provider===`inworld`&&e.audio.model===`inworld-tts-2`,error:i(`narrationPrompt`),onChange:e=>a({narrationPrompt:e})}),(0,h.jsx)(p6,{value:e.audio.usePronunciationGlossary,supported:hj({sources:e.sources,audio:{...e.audio,usePronunciationGlossary:!0}}),onChange:t=>a({audio:{...e.audio,usePronunciationGlossary:t}}),shared:{value:e.audio.shareGlossary??!0,onChange:t=>a({audio:{...e.audio,shareGlossary:t}})}}),(0,h.jsx)(d6,{value:e.audio.useNarrationAliases,onChange:t=>a({audio:{...e.audio,useNarrationAliases:t}})}),(0,h.jsx)(l6,{value:e.audio.describeFigures,skipCode:e.audio.skipCode,onChange:t=>a({audio:{...e.audio,...t}})})]})]})]}):null}),e.sources.audio===`provide`?(0,h.jsxs)(`div`,{className:Y3,children:[(0,h.jsx)(q3,{field:`provided.audio`,label:`Narration file`,accept:`audio/*`,uploads:e.provided.audio===void 0?[]:[e.provided.audio],problem:i(`provided.audio`),onPick:e=>{o(`audio`,e)},onReattach:c?(e,t)=>c(`audio`,e,t):void 0,onRemove:e=>{s(`audio`,e)}}),(0,h.jsx)(`p`,{className:`mt-2 text-small text-ink-2`,children:`Uploaded narration is used as-is; include any intro and outro in that file.`})]}):null]})}function Jge({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawNumbers:c,more:l,titled:u}){return(0,h.jsxs)(X3,{kind:`images`,name:`Images`,dim:e.sources.images===`off`,titled:u,children:[(0,h.jsx)(Z3,{kind:`images`,form:e,update:i}),(0,h.jsx)(`div`,{className:J3,children:e.sources.images===`generate`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(_6,{form:e,providers:t,problem:r,update:i}),(0,h.jsx)(G3,{prompts:n.filter(e=>e.kind===`image`),...c?{rawNumbers:c}:{},picked:e.imagePrompts,problem:r,onPick:e=>{i({imagePrompts:e})}}),(0,h.jsx)(Yge,{form:e,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s?{onReattachFile:s}:{}}),l]}):null}),e.sources.images===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(q3,{field:`provided.images`,label:`Slideshow images`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,numbered:!0,uploads:e.provided.images,problem:r(`provided.images`),onPick:e=>{a(`images`,e)},onReattach:s?(e,t)=>s(`images`,e,t):void 0,onRemove:e=>{o(`images`,e)}})}):null]})}function _6({form:e,providers:t,problem:n,update:r}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{field:`images.provider`,label:`Provider`,tip:`play.images.provider`,family:`image`,providers:t,value:e.images.provider,problem:n(`images`),onPick:e=>r({images:{provider:e,model:``}})}),(0,h.jsx)(tV,{field:`images.model`,label:`Model`,tip:`play.images.model`,provider:e.images.provider,value:e.images.model,problem:n(`images.model`),onPick:t=>r({images:{...e.images,model:t}})}),(0,h.jsx)(g6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:e.images,problem:n(`images.thinking`),onChange:e=>r({images:e})})]})}function Yge({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsx)(h6,{value:e.reference??m6,prompts:t,problem:n,onChange:e=>r({reference:e}),upload:(0,h.jsx)(q3,{field:`provided.reference`,label:`Establishing image file`,accept:`image/png,image/jpeg`,uploads:e.provided.reference===void 0?[]:[e.provided.reference],problem:n(`provided.reference`),onPick:e=>{i(`reference`,e)},onReattach:o?(e,t)=>o(`reference`,e,t):void 0,onRemove:e=>{a(`reference`,e)}})})}var v6=5e3,Xge=[`Write a YouTube description for this video.`,``,`- Summary: a 2-3 sentence hook that says what the viewer gets from watching, in plain words, without clickbait.`,`- Chapters: split the video where the topic changes, 5-12 chapters for a long video and fewer for a short one. Chapter titles are 2-6 words, in title case, and name what that part covers.`,`- Hashtags: 3-5 hashtags about the subject, most specific last.`,`- Tags: 15-25 search terms a viewer might type to find this video, from broad to specific.`].join(`
283
+ `),Zge=`Built-in`;function y6({enabled:e,prompt:t,prompts:n,narrated:r,problem:i,onChange:a}){let o=(0,m.useId)(),s=n.filter(e=>e.kind===`description`),c=t!==``&&!s.some(e=>e.name===t),l=i?.(`youtubeDescription`)??i?.(`descriptionPrompt`);return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1 self-end`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:`${o}-switch`,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${o}-switch`,type:`checkbox`,"data-play-field":`youtubeDescription`,checked:e,disabled:!r&&!e,"aria-describedby":l?`${o}-error`:void 0,className:`size-4 accent-accent`,onChange:e=>a({youtubeDescription:e.currentTarget.checked,descriptionPrompt:t})}),`YouTube description`]}),(0,h.jsx)(U,{id:`play.youtube-description`})]}),(0,h.jsx)(oV,{htmlFor:`${o}-prompt`,label:`Description prompt`,tip:`play.description-prompt`,children:(0,h.jsxs)(UB,{id:`${o}-prompt`,"data-play-field":`descriptionPrompt`,value:t,disabled:!e,onChange:t=>a({youtubeDescription:e,descriptionPrompt:t.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:Zge}),c?(0,h.jsxs)(`option`,{value:t,children:[t,` (saved choice)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`sl-fields__wide m-0 text-small text-danger`,children:l}):r?null:(0,h.jsx)(`p`,{className:`sl-fields__wide m-0 text-label text-ink-3`,children:`Needs narration.`})]})}function b6({value:e,narrated:t,imageProvider:n,problem:r,onChange:i,fieldPrefix:a=`videoEdit`,language:o}){let s=(0,m.useId)(),c=e??aA,l=e=>i({...c,...e}),{api:u}=V(),d=I(qB(u,n,c.animate!==`off`)),f=e=>r?.(`${a}.${e}`),p=[c.transition===`cut`?void 0:`${uA[c.transition]} ${String(c.transitionSeconds)} s`,c.grade===`none`?void 0:fA[c.grade],c.atmosphere===`none`?void 0:pA[c.atmosphere],c.vignette===`off`?void 0:`Vignette`,c.grain===`off`?void 0:`Grain`,c.chapterCards?`Chapter cards`:void 0,c.animate===`off`?void 0:`Animated images`].filter(e=>e!==void 0),g=[`transition`,`transitionSeconds`,`chapterCards`,`animate`,`animateEvery`,`animateModel`].map(f).filter(e=>e!==void 0),_=d.data?.models??[],v=c.animateModel!==``&&!_.some(e=>e.id===c.animateModel),y=PO(o);return{cuts:(0,h.jsxs)(x6,{id:`${s}-cuts`,label:`Cuts`,tip:`project.video.cuts`,children:[(0,h.jsx)(UB,{id:`${s}-cuts`,"data-play-field":`${a}.cuts`,className:`min-w-0`,value:y===void 0?c.cuts:`interval`,disabled:y!==void 0,"aria-describedby":y===void 0?void 0:`${s}-cuts-note`,onChange:e=>l({cuts:e.target.value}),children:$k.map(e=>(0,h.jsx)(`option`,{value:e,children:lA[e]},e))}),y===void 0?null:(0,h.jsx)(`p`,{id:`${s}-cuts-note`,className:`m-0 basis-full text-small text-ink-3`,children:y})]}),look:(0,h.jsxs)(`details`,{className:`group min-w-0 rounded-control border border-line-strong`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-10 cursor-pointer items-center gap-3 px-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Look`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-ink-3`,children:p.length===0?`Plain cuts, no effects`:p.join(` · `)})]}),(0,h.jsxs)(`div`,{className:`sl-fields border-line-strong border-t p-3`,children:[(0,h.jsxs)(x6,{id:`${s}-transition`,label:`Transition`,tip:`project.video.transition`,children:[(0,h.jsx)(UB,{id:`${s}-transition`,"data-play-field":`${a}.transition`,className:`min-w-0`,value:c.transition,onChange:e=>l({transition:e.target.value}),children:eA.map(e=>(0,h.jsx)(`option`,{value:e,children:uA[e]},e))}),(0,h.jsx)(UB,{"aria-label":`Transition length`,"data-play-field":`${a}.transitionSeconds`,"aria-invalid":f(`transitionSeconds`)!==void 0,className:`w-24 flex-none`,disabled:c.transition===`cut`,value:String(c.transitionSeconds),onChange:e=>l({transitionSeconds:Number(e.target.value)}),children:cA.map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[e,` s`]},e))})]}),(0,h.jsx)(x6,{id:`${s}-grade`,label:`Colour grade`,tip:`project.video.grade`,children:(0,h.jsx)(S6,{id:`${s}-grade`,field:`${a}.grade`,value:c.grade,options:nA,labels:fA,onChange:e=>l({grade:e})})}),(0,h.jsx)(x6,{id:`${s}-vignette`,label:`Vignette`,tip:`project.video.vignette`,children:(0,h.jsx)(S6,{id:`${s}-vignette`,field:`${a}.vignette`,value:c.vignette,options:tA,labels:dA,onChange:e=>l({vignette:e})})}),(0,h.jsx)(x6,{id:`${s}-grain`,label:`Film grain`,tip:`project.video.grain`,children:(0,h.jsx)(S6,{id:`${s}-grain`,field:`${a}.grain`,value:c.grain,options:tA,labels:dA,onChange:e=>l({grain:e})})}),(0,h.jsx)(x6,{id:`${s}-atmosphere`,label:`Atmosphere`,tip:`project.video.atmosphere`,children:(0,h.jsx)(S6,{id:`${s}-atmosphere`,field:`${a}.atmosphere`,value:c.atmosphere,options:rA,labels:pA,onChange:e=>l({atmosphere:e})})}),(0,h.jsx)(x6,{id:`${s}-cards`,label:`Chapter cards`,tip:`project.video.chapter-cards`,children:(0,h.jsx)(`input`,{id:`${s}-cards`,type:`checkbox`,"data-play-field":`${a}.chapterCards`,className:`size-4 accent-accent`,checked:c.chapterCards,disabled:!t&&!c.chapterCards,onChange:e=>l({chapterCards:e.currentTarget.checked})})}),(0,h.jsxs)(x6,{id:`${s}-animate`,label:`Animate images`,tip:`project.video.animate`,wide:!0,children:[(0,h.jsx)(UB,{id:`${s}-animate`,"data-play-field":`${a}.animate`,"aria-invalid":f(`animate`)!==void 0,className:`min-w-0`,value:c.animate,onChange:e=>l({animate:e.target.value}),children:iA.map(e=>(0,h.jsx)(`option`,{value:e,disabled:e===`chapters`&&!t,children:mA[e]},e))}),(0,h.jsx)(UB,{"aria-label":`Animate every how many images`,"data-play-field":`${a}.animateEvery`,"aria-invalid":f(`animateEvery`)!==void 0,className:`w-24 flex-none`,disabled:c.animate!==`every`,value:String(c.animateEvery),onChange:e=>l({animateEvery:Number(e.target.value)}),children:Array.from({length:9},(e,t)=>t+2).map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[`every `,e]},e))}),(0,h.jsxs)(UB,{"aria-label":`Image-to-video model`,"data-play-field":`${a}.animateModel`,"aria-invalid":f(`animateModel`)!==void 0,className:`min-w-0`,disabled:c.animate===`off`,value:c.animateModel,onChange:e=>l({animateModel:e.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a model`}),v?(0,h.jsxs)(`option`,{value:c.animateModel,children:[c.animateModel,` (saved choice)`]}):null,_.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),g.length>0?(0,h.jsx)(`p`,{className:`col-span-full text-small text-danger`,children:g[0]}):c.animate!==`off`&&d.isSuccess&&_.length===0?(0,h.jsx)(`p`,{className:`col-span-full text-label text-ink-3`,children:`This image provider has no image-to-video models. Choose fal.ai or Replicate for images to animate them.`}):null]})]})}}function x6({id:e,label:t,tip:n,wide:r=!1,children:i}){return(0,h.jsxs)(`div`,{className:z(`sl-field`,r&&`sl-fields__wide`),...zb,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),(0,h.jsx)(U,{id:n,label:t.toLowerCase()})]}),(0,h.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-start gap-2 [&>select]:min-w-0 [&>select]:flex-1`,children:i})]})}function S6({id:e,field:t,value:n,options:r,labels:i,onChange:a}){return(0,h.jsx)(UB,{id:e,"data-play-field":t,className:`min-w-0`,value:n,onChange:e=>a(e.target.value),children:r.map(e=>(0,h.jsx)(`option`,{value:e,children:i[e]},e))})}var Qge=XD(`kind`,[Y({kind:oO(`upload`),stagedFileId:K().regex(/^[A-Za-z0-9_-]{1,64}$/)}),Y({kind:oO(`output`),outputId:K().regex(/^[A-Za-z0-9_-]{1,64}$/)}),Y({kind:oO(`picture`),sha256:K().regex(/^[a-f0-9]{64}$/)})]),C6=Y({format:X(GS),subtitles:Y({mode:X(aM),fontId:K().max(160).regex(/^[A-Za-z0-9_-]+$/),fontSize:q().finite().min(16).max(120),position:X(oM)}),videoEdit:fM.optional(),previewText:K().max(200).optional(),image:Qge.optional(),shorts:Y({titleOnScreen:RD(),speed:q().finite().min(1).max(1.25).optional(),title:K().max(100).optional()}).optional(),force:RD().optional()}),$ge=Y({hash:K().regex(/^[a-f0-9]{64}$/),url:K().min(1),cached:RD(),seconds:q().positive()});async function e_e(e,t,n){let r=await e.fetch(`${e.origin}/api/style-preview`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),...n===void 0?{}:{signal:n}});if(!r.ok)throw await co(r);let i=yo($ge,await r.json());return{...i,src:`${e.origin}${i.url}`}}var t_e=600;function w6({settings:e,label:t,drawnOn:n,poster:r}){let{api:i}=V(),a=I({queryKey:eN,queryFn:()=>tN(i),staleTime:6e4}),{format:o,subtitles:s,videoEdit:c,previewText:l,image:u,shorts:d}=e,f=r??(u?.kind===`picture`?xx(i,u.sha256):void 0),p=u===void 0?``:JSON.stringify(u),g=d===void 0?``:JSON.stringify(d),_=(0,m.useMemo)(()=>JSON.stringify({format:o,subtitles:{mode:s.mode,fontId:s.fontId,fontSize:s.fontSize,position:s.position},...c===void 0?{}:{videoEdit:c},...l===void 0||l.trim()===``?{}:{previewText:l},...p===``?{}:{image:JSON.parse(p)},...g===``?{}:{shorts:JSON.parse(g)}}),[o,s.mode,s.fontId,s.fontSize,s.position,c,l,p,g]),v=(0,m.useMemo)(()=>C6.safeParse(JSON.parse(_)).success,[_]),[y,b]=(0,m.useState)({kind:`idle`}),[x,S]=(0,m.useState)(void 0),C=(0,m.useRef)(void 0),w=(0,m.useCallback)(async e=>{C.current?.abort();let t=new AbortController;C.current=t,b({kind:`pending`});try{let n=await e_e(i,{...C6.parse(JSON.parse(_)),...e?{force:e}:{}},t.signal);if(C.current!==t)return;S(n.src),b({kind:`ready`,src:n.src})}catch(e){if(C.current!==t||t.signal.aborted)return;b({kind:`failed`,message:e instanceof Error&&e.message!==``?e.message:`The style preview couldn't render. Press Render again.`})}},[i,_]);(0,m.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>{w(!1)},t_e);return()=>clearTimeout(e)},[w,v]),(0,m.useEffect)(()=>()=>C.current?.abort(),[]);let T=a.data?.fonts.find(e=>e.id===s.fontId)?.name??(s.fontId==="default"?`Barlow`:`Chosen font`),E=d===void 0?s.mode===`burn-in`?`Captions: ${T} ${String(s.fontSize)} · ${n_e(s.position)}`:s.mode===`files`?`Captions: a separate file, which players show in their own style`:`Captions: off`:[`Captions: ${T}, word by word`,d.titleOnScreen?`Title on screen`:`No title on screen`,d.speed===void 0||d.speed===1?void 0:`${d.speed.toFixed(2)}×`].filter(e=>e!==void 0).join(` · `),D=d===void 0?`Style preview`:`Shorts preview`,O=o===`9:16`||d!==void 0;return(0,h.jsxs)(`section`,{"aria-label":D,className:`min-w-0 space-y-3`,children:[(0,h.jsx)(W,{as:`h3`,title:D,meta:d===void 0?`6 seconds of the sample, rendered with your settings`:`A few seconds of the sample as a short, rendered with your settings`,info:d===void 0?`project.video.style-preview`:`play.shorts.preview`,children:(0,h.jsxs)(B,{variant:`quiet`,size:`small`,disabled:!v||y.kind===`pending`,disabledReason:v?`Rendering the preview…`:`Fix the caption settings to render the preview.`,onClick:()=>{w(!0)},children:[(0,h.jsx)(qc,{"aria-hidden":`true`,size:16,strokeWidth:1.75}),`Render again`]})}),x===void 0?null:(0,h.jsx)(c0,{src:x,label:t??D,...f===void 0?{}:{poster:f},portrait:O,square:!O&&o===`1:1`,className:O?`max-w-[270px]`:o===`1:1`?`max-w-[360px]`:`max-w-[480px]`}),y.kind===`pending`?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Rendering the preview…`}):null,y.kind===`failed`?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:y.message}):null,v?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The preview renders again once the caption size is between 16 and 120.`}),(0,h.jsxs)(`p`,{className:`text-small text-ink-2`,children:[E,u===void 0||n===void 0?``:` · Drawn on ${n}`]})]})}function n_e(e){let t=e.replace(/-/g,` `);return`${t[0]?.toUpperCase()??``}${t.slice(1)}`}function r_e({form:e,problem:t,update:n,onPickFiles:r,onRemoveFile:i,onReattachFile:a}){let o=e.provided.ambientBed;return(0,h.jsx)(s2,{value:e.ambientBed,inherit:`The channel's (brand kit)`,sources:Gk,offerNone:!0,problem:e=>t(`ambientBed.${e}`),file:(0,h.jsx)(q3,{field:`ambientBed.file`,label:`Ambient sound file: an audio file, looped if shorter than the video`,accept:`audio/*`,uploads:o===void 0?[]:[o],problem:t(`ambientBed.file`),onPick:e=>r(`ambientBed`,e),onReattach:a?(e,t)=>a(`ambientBed`,e,t):void 0,onRemove:e=>i(`ambientBed`,e)}),onChange:e=>n({ambientBed:e})})}function T6({value:e,onChange:t,problem:n,switchTip:r=`project.loudness`,switchLabel:i=`Level the volume`}){return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[(0,h.jsx)(Bb,{checked:e.enabled,label:i,tip:r,onChange:n=>t({...e,enabled:n})}),e.enabled?(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(D6,{target:`video`,label:`Video volume`,tip:`project.loudness.video`,lufs:e.videoLufs,error:n?.(`videoLufs`),onChange:n=>t({...e,videoLufs:n})}),(0,h.jsx)(D6,{target:`audioFiles`,label:`Audio files volume`,tip:`project.loudness.audio-files`,lufs:e.audioFilesLufs,error:n?.(`audioFilesLufs`),onChange:n=>t({...e,audioFilesLufs:n})})]}):null]})}var i_e=`Enter a volume between ${O6(-10)} dB and ${O6(4)} dB (${String(tk(-10))}% to ${String(tk(4))}%).`;function E6(e,t){let n=e.trim().replace(`−`,`-`).replace(`,`,`.`);if(n===``)return;let r=Number(n.replace(/(dB|%)$/i,``).trim());if(!Number.isFinite(r)||t===`percent`&&r<=0)return;let i=t===`db`?r:nk(r);if(!(i<-10.25||i>4.25))return rk(i)}function D6({target:e,label:t,tip:n,lufs:r,error:i,onChange:a}){let o=(0,m.useId)(),s=$O(r,e),[c,l]=(0,m.useState)(),u=c===void 0||E6(c.text,c.unit)!==void 0,d=(t,n)=>{l({unit:t,text:n});let r=E6(n,t);r!==void 0&&a(ek(r,e))},f=c?.unit===`db`?c.text:O6(s),p=c?.unit===`percent`?c.text:String(tk(s));return(0,h.jsx)(LB,{label:t,tip:n,help:`0 dB is the recommended ${k6(ZO(e))} LUFS; this is ${k6(r)} LUFS. Peaks stay under ${k6(QO(e))} dBTP.`,error:u?i:i_e,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(zB,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`loudness.${e===`video`?`videoLufs`:`audioFilesLufs`}`,value:f,onChange:e=>d(`db`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`dB`}),(0,h.jsx)(zB,{id:`${o}-percent`,"aria-label":`${t} as a percentage of the recommended level`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:p,onChange:e=>d(`percent`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`%`})]})})}function O6(e){return e>0?`+${String(e)}`:k6(e)}function k6(e){return String(e).replace(`-`,`−`)}function A6({sentence:e,paragraph:t,problem:n,onChange:r}){let i=`0 to 2 in steps of ${String(fk)}`;return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(LB,{label:`Pause between sentences (seconds)`,tip:`project.pause.sentence`,help:`${i}; ${String(dk)} is the default. 0 leaves the voice's own.`,error:n(`sentencePauseSeconds`),children:(0,h.jsx)(zB,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`sentencePauseSeconds`,value:e,onChange:e=>r(`sentencePauseSeconds`,e.target.value)})}),(0,h.jsx)(LB,{label:`Pause between paragraphs (seconds)`,tip:`project.pause.paragraph`,help:`${i}; 0 (the default) keeps the sentence pause.`,error:n(`paragraphPauseSeconds`),children:(0,h.jsx)(zB,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`paragraphPauseSeconds`,value:t,onChange:e=>r(`paragraphPauseSeconds`,e.target.value)})})]})}function j6(e){let t=e.trim().replace(`,`,`.`);if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function a_e({form:e,problem:t,update:n}){let{api:r}=V(),i=I(_b(r)).data?.loudness??JO,a=e.loudness;return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[e.sources.audio===`generate`?(0,h.jsx)(A6,{sentence:e.sentencePause??`0.4`,paragraph:e.paragraphPause??`0`,problem:t,onChange:(e,t)=>n(e===`sentencePauseSeconds`?{sentencePause:t}:{paragraphPause:t})}):null,(0,h.jsx)(T6,{value:{enabled:a?.enabled??i.enabled,videoLufs:a?.videoLufs??i.videoLufs,audioFilesLufs:a?.audioFilesLufs??i.audioFilesLufs},problem:e=>t(`loudness.${e}`),onChange:e=>n({loudness:e})})]})}function M6({value:e,onPick:t,disabled:n=!1}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,...zb,children:[(0,h.jsx)(K4,{id:r,className:`shrink-0`,children:`Thumbnails`}),(0,h.jsxs)(q4,{type:`single`,value:String(e),"aria-labelledby":r,disabled:n,"data-play-field":`thumbnailCount`,onValueChange:e=>{(e===`1`||e===`3`)&&t(e===`3`?3:1)},children:[(0,h.jsx)(J4,{value:`1`,children:`1`}),(0,h.jsx)(J4,{value:`3`,children:`3`})]}),(0,h.jsx)(U,{id:`play.thumbnail-count`})]})}function o_e({form:e,problem:t,update:n}){return(0,h.jsxs)(X3,{kind:`research`,name:`Research`,dim:e.sources.research===`off`,children:[(0,h.jsx)(Z3,{kind:`research`,form:e,update:n}),(0,h.jsx)(`div`,{className:J3,children:e.sources.research===`generate`?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:`Runs through the LLM, one agent per chapter`}):null}),e.sources.research===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(K3,{field:`provided.research`,label:`Research notes`,tip:`play.provided.research`,value:e.provided.research,placeholder:`Paste the notes the article will be written from.`,problem:t(`provided.research`),onChange:t=>{n({provided:{...e.provided,research:t}})}})}):null]})}function s_e({form:e,prompts:t,problem:n,update:r,titled:i}){return(0,h.jsxs)(X3,{kind:`article`,name:`Article`,dim:!1,titled:i,children:[(0,h.jsx)(Z3,{kind:`article`,form:e,update:r}),(0,h.jsx)(`div`,{className:`${Y3} grid gap-4`,children:e.sources.article===`generate`?(0,h.jsx)(ZB,{field:`articlePrompt`,label:IA(e)?`Script prompt`:`Article prompt`,tip:`play.article-prompt`,value:e.articlePrompt,placeholder:`Pick a prompt`,options:Q3(t,k1(e)),problem:n(`articlePrompt`),onPick:e=>{r({articlePrompt:e})}}):null}),e.sources.article===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(K3,{field:`provided.article`,label:`Article text`,tip:`play.provided.article`,value:e.provided.article,placeholder:`Paste the article that will be narrated.`,problem:n(`provided.article`),onChange:t=>{r({provided:{...e.provided,article:t}})}})}):null]})}function c_e({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s}){let c=e.sources.thumbnail===`from_prompt`||e.sources.thumbnail===`prompt_by_llm`;return(0,h.jsxs)(X3,{kind:`thumbnail`,name:`Thumbnail`,dim:e.sources.thumbnail===`off`,children:[(0,h.jsx)(Z3,{kind:`thumbnail`,form:e,update:i}),(0,h.jsxs)(`div`,{className:J3,children:[c&&e.sources.images!==`generate`?(0,h.jsx)(_6,{form:e,providers:t,problem:r,update:i}):null,c?(0,h.jsx)(ZB,{field:`thumbnailPrompt`,label:`Thumbnail prompt`,tip:`play.thumbnail-prompt`,value:e.thumbnailPrompt,placeholder:`Pick a prompt`,options:Q3(n,`thumbnail`),problem:r(`thumbnailPrompt`),onPick:e=>{i({thumbnailPrompt:e})}}):null,c?(0,h.jsx)(M6,{value:e.thumbnailCount===3?3:1,onPick:e=>{i({thumbnailCount:e})}}):null]}),e.sources.thumbnail===`provide`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(q3,{field:`provided.thumbnail`,label:`Thumbnail image`,accept:`image/png,image/jpeg,image/webp`,uploads:e.provided.thumbnail===void 0?[]:[e.provided.thumbnail],problem:r(`provided.thumbnail`),onPick:e=>{a(`thumbnail`,e)},onReattach:s?(e,t)=>s(`thumbnail`,e,t):void 0,onRemove:e=>{o(`thumbnail`,e)}})}):null]})}function l_e({form:e,prompts:t,silenceGapSeconds:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawTiming:c,extras:l=!0,language:u,titled:d}){let f=e.sources.video===`generate`?e.sources.audio===`off`?`Silent video · each image shown once`:`Images and narration · ${String(n)} s segment gaps`:e.sources.audio===`off`?`Download each enabled stage separately`:`Combined WAV export with narration and segment gaps`,p=t=>({value:c?c[t]:Number.isFinite(e[t])?String(e[t]):``,onChange:e=>{c?c.onChange(t,e):i({[t]:e.trim()===``?NaN:Number(e)})}}),m=b6({value:e.videoEdit,narrated:e.sources.audio!==`off`,imageProvider:e.images.provider,problem:r,language:u??e.language,onChange:e=>i({videoEdit:e})});return(0,h.jsxs)(X3,{kind:`video`,name:`Export`,dim:e.sources.video===`off`,titled:d,children:[(0,h.jsx)(Z3,{kind:`video`,form:e,update:i}),(0,h.jsx)(`span`,{className:J3,children:(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:f})}),e.sources.video===`generate`||e.sources.audio!==`off`?(0,h.jsxs)(`div`,{className:J3,children:[e.sources.video===`generate`?(0,h.jsx)(P6,{field:`imageSeconds`,label:`Seconds per image`,tip:`play.image-seconds`,step:1,problem:r(`imageSeconds`),...p(`imageSeconds`)}):null,e.sources.video===`generate`?(0,h.jsx)(P6,{field:`zoomPercent`,label:`Zoom (%)`,tip:`play.zoom`,step:.5,problem:r(`zoomPercent`),...p(`zoomPercent`)}):null,e.sources.video===`generate`?(0,h.jsx)(XB,{label:`Motion`,tip:`play.motion`,problem:void 0,children:({id:t})=>(0,h.jsx)(UB,{id:t,"data-play-field":`motionStyle`,className:`w-full`,value:e.motionStyle,onChange:e=>i({motionStyle:e.target.value}),children:XS.map(e=>(0,h.jsx)(`option`,{value:e,children:HA[e]},e))})}):null,e.sources.video===`generate`?m.cuts:null,e.sources.audio===`off`?null:(0,h.jsx)(P6,{field:`edgeSilenceSeconds`,label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,step:.5,problem:r(`edgeSilenceSeconds`),...p(`edgeSilenceSeconds`)})]}):null,e.sources.video===`generate`?(0,h.jsx)(`div`,{className:Y3,children:m.look}):null,e.sources.video===`generate`&&e.sources.audio!==`off`?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(r_e,{form:e,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s})}):null,e.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(a_e,{form:e,problem:r,update:i})}),l?(0,h.jsx)(`div`,{className:Y3,children:(0,h.jsx)(N6,{form:e,prompts:t,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s===void 0?{}:{onReattachFile:s}})}):null,e.sources.images===`off`?(0,h.jsx)(`p`,{className:`${Y3} text-small text-ink-2`,children:`Video is Off because Images is Off. Generate or provide images to enable video.`}):null]})}function N6({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[e.sources.audio===`generate`&&e.audio.describeFigures===!0?(0,h.jsx)(u6,{value:e.showFigures,onChange:e=>r({showFigures:e})}):null,e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(y6,{enabled:e.youtubeDescription===!0,prompt:e.descriptionPrompt??``,prompts:t,narrated:e.sources.audio!==`off`,problem:n,onChange:e=>r(e)})}),e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(dV,{value:e.shorts??sV,prompts:t,narrated:e.sources.audio!==`off`,problem:n,musicName:e.provided.shortsMusic?.name,music:(0,h.jsxs)(`div`,{className:`basis-full`,children:[(0,h.jsx)(q3,{field:`shorts.music`,label:`Background music (optional): an audio file, looped if shorter than a short`,accept:`audio/*`,disabled:!wN(e),uploads:e.provided.shortsMusic===void 0?[]:[e.provided.shortsMusic],problem:n(`shorts.music`),onPick:e=>i(`shortsMusic`,e),onReattach:o?(e,t)=>o(`shortsMusic`,e,t):void 0,onRemove:e=>a(`shortsMusic`,e)}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:`Plays at the volume above under every short and dips while the narrator speaks.`})]}),preview:(0,h.jsx)(w6,{settings:cV(e.shorts??sV,e.subtitles.fontId)}),onChange:e=>r({shorts:e})})})]})}function P6({field:e,label:t,tip:n,placeholder:r,step:i,problem:a,value:o,onChange:s}){return(0,h.jsx)(XB,{label:t,tip:n,problem:a,children:({id:t,describedBy:n})=>(0,h.jsx)(zB,{id:t,"data-play-field":e,type:`text`,inputMode:i<1?`decimal`:`numeric`,className:`sl-input--number`,"aria-invalid":a!==void 0,"aria-describedby":n,placeholder:r,value:o,onChange:e=>s(e.target.value)})})}function u_e({form:e,update:t}){let n=e.sources.document===`off`;return(0,h.jsxs)(X3,{kind:`document`,name:`Document`,dim:n,children:[(0,h.jsx)(Z3,{kind:`document`,form:e,update:t}),(0,h.jsx)(`div`,{className:J3,children:(0,h.jsx)(XB,{label:`Theme`,tip:`play.document-theme`,problem:void 0,children:({id:r})=>(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(V3,{id:r,field:`document.theme`,className:`w-auto min-w-[120px]`,disabled:n,value:e.document,onChange:e=>{t({document:e})}}),(0,h.jsx)(fa,{to:`/document-themes`,className:`text-small text-accent-ink underline`,children:`Edit themes`})]})})})]})}function d_e({form:e,providers:t,problem:n,update:r,uses:i,onSettings:a}){let o=[...new Set(i.map(e=>e.label))],s=o.length<=1?o[0]??``:`${o.slice(0,-1).join(`, `)} and ${o.at(-1)??``}`;return(0,h.jsxs)(`section`,{"aria-label":`Text generation`,className:`border-y border-line py-4`,children:[(0,h.jsx)(W,{as:`h3`,title:`Text generation`,meta:`Used for ${s}.`,info:`play.text-generation`,className:`pb-3`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:a,children:`Settings`})}),(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(eV,{field:`llm.provider`,label:`LLM`,tip:`play.llm.provider`,family:`llm`,providers:t,value:e.llm.provider,problem:n(`llm.provider`)??(e.llm.provider===``?n(`llm`):void 0),onPick:e=>r({llm:{provider:e,model:``}})}),(0,h.jsx)(tV,{field:`llm.model`,label:`Text model`,tip:`play.llm.model`,provider:e.llm.provider,value:e.llm.model,problem:n(`llm.model`)??(e.llm.provider!==``&&n(`llm`)?`Pick a text model.`:void 0),onPick:t=>r({llm:{...e.llm,model:t}})}),(0,h.jsx)(g6,{choice:e.llm,onChange:e=>r({llm:e})})]})]})}function F6({section:e,entries:t,...n}){let r=kN(n.form,t);return r[0]?.section===e?(0,h.jsx)(d_e,{...n,uses:r}):null}function f_e(e){let{form:t,onLibrary:n}=e,r=e.prompts.find(e=>e.kind===k1(t)&&e.name===t.articlePrompt);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s_e,{...e,titled:!1}),t.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3 py-3`,children:[r?(0,h.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`summary`,{"data-play-field":`articlePrompt.preview`,className:`cursor-pointer py-2 text-small text-accent-ink`,children:`View prompt`}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words py-3 font-sans text-body text-ink-2`,children:r.body})]}):(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.prompts.some(e=>e.kind===k1(t))?`Choose a saved ${k1(t)} prompt.`:`No ${k1(t)} prompts saved. Create a prompt to begin.`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>n(`/prompts`),children:`Create prompt`})]}):(0,h.jsxs)(`p`,{className:`py-3 text-small text-ink-3`,children:[t.provided.article.trim()?t.provided.article.trim().split(/\s+/).length:0,` `,`words · `,t.provided.article.length,` characters`]}),(0,h.jsx)(F6,{...e,section:`article`,onSettings:()=>n(`/settings`)}),t.sources.article===`off`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`No article: for a project of images or a thumbnail made from prompts. Narration, the PDF and anything else that reads the article stay off.`}):t.sources.article===`provide`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`Research is Off because the article is provided.`}):(0,h.jsx)(o_e,{...e})]})}function p_e(){let{api:e}=V(),t=XN(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=Ry(),u=I({queryKey:[`play-drafts`],queryFn:async()=>{let t=await WM(e);if(!t.ok)throw Error(t.message);return t.value.drafts}}),d=async()=>{if(!r||s)return;let e=r.id;c(!0),o(null);try{await t.discard({id:r.id,version:r.version}),i(null),await n.cancelQueries({queryKey:[`play-drafts`]}),n.setQueryData([`play-drafts`],t=>t?.filter(t=>t.id!==e))}catch(e){let t=e instanceof Error?e.message:`The draft wasn't discarded. Try again.`;o(t),l(t,`error`)}finally{c(!1)}};return(0,h.jsxs)(`section`,{"aria-label":`Drafts`,className:`flex min-w-0 flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(`p`,{role:`status`,className:z(`engraved min-w-[112px] text-right`,t.status===`saved`?`text-accent-ink`:t.status===`error`||t.status===`conflict`?`text-danger`:`text-ink-3`),children:{unsaved:`Unsaved`,saving:`Saving…`,saved:`Saved`,error:`Couldn't save`,conflict:`Changed elsewhere`}[t.status]}),t.status===`error`?(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{!t.view&&t.activeId&&t.edited===0?t.open(t.activeId):t.flush()},children:`Retry`}):null,t.status===`conflict`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{t.activeId&&t.open(t.activeId)},children:`Reload saved draft`}),(0,h.jsx)(B,{variant:`quiet`,onClick:()=>void t.saveAsNew(),children:`Save as a new draft`}),(0,h.jsx)(U,{id:`play.draft-conflict`})]}):null,(0,h.jsxs)(Nb,{children:[(0,h.jsx)(Pb,{asChild:!0,children:(0,h.jsxs)(B,{variant:`quiet`,children:[`Drafts`,(0,h.jsx)(Cc,{"aria-hidden":`true`,className:`size-4`})]})}),(0,h.jsxs)(Lb,{align:`end`,className:`w-[340px] p-0`,"aria-label":`Saved drafts`,children:[u.isPending?(0,h.jsx)(`p`,{role:`status`,className:`px-3 py-2`,children:`Loading drafts…`}):null,u.error?(0,h.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:[u.error.message,` `,(0,h.jsx)(B,{variant:`quiet`,onClick:()=>void u.refetch(),children:`Retry`})]}):null,u.data?.length===0?(0,h.jsx)(`p`,{className:`px-3 py-2`,children:`No saved drafts`}):null,a?(0,h.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:a}):null,u.data?.length?(0,h.jsx)(PH,{label:`Saved drafts`,className:`max-h-72 overflow-y-auto border-t-0`,children:u.data.map(e=>(0,h.jsx)(FH,{title:e.title||`Untitled draft`,onSelect:()=>void t.open(e.id),meta:(0,h.jsxs)(`time`,{dateTime:e.updatedAt,children:[`Last edited `,Wu(e.updatedAt)]}),actions:(0,h.jsx)(Py,{size:`small`,label:`Discard ${e.title||`Untitled draft`}`,onClick:()=>{i(e),o(null)},children:(0,h.jsx)($c,{"aria-hidden":`true`})}),children:e.readable?null:(0,h.jsx)(`p`,{className:`m-0 text-label text-waiting`,children:`Unsupported or corrupt draft. Try opening it to recover, or discard it.`})},e.id))}):null]})]}),(0,h.jsx)(B,{onClick:()=>void t.newDraft(),children:`New draft`}),(0,h.jsx)(U,{id:`play.drafts`}),(0,h.jsx)(Hy,{open:r!==null,title:`Discard ${r?.title||`Untitled draft`}?`,consequence:`The draft is removed. This cannot be undone.`,confirmLabel:`Discard draft`,pending:s,onConfirm:()=>void d(),onCancel:()=>{s||i(null)}})]})}function I6(e,t){let n=[...e.querySelectorAll(`[data-play-field]`)].find(e=>e.dataset.playField===t);if(!n||n.hasAttribute(`disabled`))return!1;let r=n.closest(`details`);return r!==null&&!r.open&&(r.open=!0),n.focus(),n.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`instant`}),document.activeElement===n}function m_e(e,t,n,r=[]){let i=e;if(e===`fontUpload`&&(i=`subtitles.fontUpload`),/^provided\.images\.\d+$/.test(e)&&(i=`provided.images`),e===`subtitles`&&(i=`subtitles.mode`),e===`chunking`&&(i=`chunking.mode`),[`audio`,`llm`,`images`].includes(e)&&(i=`${e}.provider`),e===`provided`){let e=[`audio`,`images`,`thumbnail`].find(e=>t.sources[e]===`provide`&&(e===`images`?t.provided.images:[t.provided[e]]).some(e=>e&&(e.error!==void 0||e.file===void 0))),n=t.provided.shortsMusic;i=e===void 0&&wN(t)&&n!==void 0&&(n.error!==void 0||n.file===void 0)?`shorts.music`:t.reference?.source===`provide`&&t.provided.reference!==void 0&&(t.provided.reference.error!==void 0||t.provided.reference.file===void 0)?`provided.reference`:`provided.${e??`audio`}`;let r=t.provided.ambientBed;e===void 0&&TN(t)&&r!==void 0&&(r.error!==void 0||r.file===void 0)&&(i=`ambientBed.file`)}let a=/^imagePrompts\.(\d+)\.(.+)$/.exec(e);if(a){let e=t.imagePrompts[Number(a[1])];e&&(i=`imagePrompts.${e.name}.${a[2]}`)}e===`imagePrompts`&&(i=t.imagePrompts[0]?`imagePrompts.${t.imagePrompts[0].name}.number`:`imagePrompts`);let o=/^variants\.(\d+)\.(.+)$/.exec(e);o&&(i=`items.${n[Number(o[1])]?.key??o[1]}.${o[2]}`);let s=/^items\.(\d+)\.(.+)$/.exec(e);s&&(i=Number(s[1])===0?s[2]??e:`items.${n[Number(s[1])-1]?.key??s[1]}.${s[2]}`);let c=t=>t.some(t=>e===t||e.startsWith(`${t}.`));return{section:c([`title`,`articlePrompt`,`provided.article`,`provided.research`,`sources.article`,`sources.research`,...(kN(t,r)[0]?.section??`article`)===`article`?[`llm`]:[],`values`])?`content`:c([`format`,`subtitles`,`fontUpload`])?`style`:c(`audio,narrationPrompt,voices,provided.audio,intro,outro,chunking,images,imagePrompts,imageScale,provided.images,thumbnailPrompt,provided.thumbnail,provided.reference,reference,provided,sources,imageSeconds,zoomPercent,motionStyle,edgeSilenceSeconds,document,youtubeDescription,descriptionPrompt,shorts,videoEdit,ambientBed,loudness,sentencePauseSeconds,paragraphPauseSeconds,llm`.split(`,`))?`outputs`:`review`,field:i}}function h_e({fields:e,values:t,origins:n,topics:r=[],hide:i=[],problem:a,onChange:o}){let s=e.filter(e=>!i.includes(e.name));return s.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-3 text-small text-ink-2`,children:`Each keyword is entered once and fills every place that names it.`}),(0,h.jsx)(V1,{keywords:s.map(e=>({name:e.name,value:Object.hasOwn(t,e.name)?t[e.name]??``:``,feeds:n?.get(e.name)??[],topic:r.includes(e.name)})),problem:a,onChange:o})]}):null}var g_e={every:`minutes`,value:`2`};function __e({document:e,problem:t,onEdit:n}){let r=(0,m.useId)(),{form:i}=e,a=i.imageScale,o=t(`imageScale.value`)??t(`imageScale`),s=a===void 0?void 0:o===void 0?y_e(e):{text:o,problem:!0},c=t=>{let{imageScale:r,...o}=i;n({...e,form:{...o,...t===void 0?{}:{imageScale:t},...t!==void 0&&a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})};return(0,h.jsxs)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:[(0,h.jsx)(Bb,{checked:a!==void 0,label:`More images for long videos`,tip:`play.image-scale`,describedBy:`${r}-line`,onChange:e=>c(e?g_e:void 0)}),a===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,...zb,children:[(0,h.jsx)(Vb,{label:`How the rate is given`,tip:`play.image-scale.rate`,value:a.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>c({every:e,value:v_e(a.value,a.every,e)})}),a.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(zB,{id:`${r}-value`,"data-play-field":`imageScale.value`,"aria-label":a.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`sl-input--number`,"aria-invalid":s?.problem===!0,"aria-describedby":`${r}-line`,value:a.value,onChange:e=>c({every:a.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:a.every===`minutes`?`minutes`:`images per hour`})]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:s.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:s.text})]})}function v_e(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function y_e(e){let{form:t}=e,n=t.imageScale;if(n===void 0)return{text:``,problem:!1};let r=Number(n.value.trim()),i=n.every===`minutes`;if(!(n.value.trim()!==``&&(i?r>=.25&&r<=60:r>=1&&r<=240)))return{text:i?`Enter a number of minutes between ${String(IO)} and 60.`:`Enter a number of images per hour between 1 and 240.`,problem:!0};let a=i?HO(r):r,o=t.sources.article===`provide`,s=Number(e.expectedWords.trim()),c=o?Math.max(1,BO(t.provided.article)):Number.isInteger(s)&&s>=1&&s<=1e5?s:RO,l=t.imagePrompts.map(e=>({name:e.name,number:Math.max(0,Number.parseInt(e.number,10)||0)})),u=l.reduce((e,t)=>e+t.number,0),d={perHour:a,words:c},f=KO({imagePrompts:l,imageScale:d,sources:t.sources}).reduce((e,t)=>e+t,0),p=`about ${String(Math.max(1,Math.round(VO(c))))} minutes (${c.toLocaleString(`en-US`)} words ${o?`in the article`:`expected, set on Review`})`;if(l.length===0)return{text:`For ${p}: tick an image prompt to see the count.`,problem:!1};let m=WO(d)>=240?` That is the most a run makes (240); the images repeat after that.`:``;return{text:f>u?`For ${p}: ${String(f)} images, ${String(f-u)} more than the prompts' ${String(u)}.${m}`:`For ${p}: the prompts' ${String(u)} images already cover it.`,problem:!1}}function b_e({document:e,onEdit:t}){let{form:n}=e;return(0,h.jsx)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:(0,h.jsx)(Bb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,form:{...a,...r?{imageScenes:!0}:{}}})}})})}function x_e(e){return e.upload?(0,h.jsx)(L6,{value:e.value,onPick:e.onPick,upload:e.upload}):(0,h.jsx)(S_e,{...e})}function S_e({value:e,onPick:t,onUploading:n}){let{api:r}=V(),i=_(),a=L({mutationFn:e=>nN(r,e),onSuccess:({font:e})=>{i.setQueryData(eN,t=>({fonts:[...(t?.fonts??[]).filter(t=>t.id!==e.id),e]})),i.invalidateQueries({queryKey:eN})}}),o=a.isPending,s=(0,m.useRef)(t);s.current=t;let c=(0,m.useRef)(n);return c.current=n,(0,m.useEffect)(()=>{c.current(o)},[o]),(0,m.useEffect)(()=>()=>c.current(!1),[]),(0,h.jsx)(L6,{value:e,onPick:t,upload:{pending:o,error:a.error?.message,pick:e=>a.mutate(e,{onSuccess:({font:e})=>s.current(e.id)})}})}function L6({value:e,onPick:t,upload:n}){let{api:r}=V(),i=(0,m.useId)(),a=(0,m.useId)(),o=I({queryKey:eN,queryFn:()=>tN(r),staleTime:6e4}),s=n.pending,c=o.data?.fonts??[],l=e!=="default"&&!c.some(t=>t.id===e);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:i,children:`Subtitle font`}),(0,h.jsx)(U,{id:`project.subtitles.font`,className:`-my-1`})]}),(0,h.jsxs)(VB,{id:i,"data-play-field":`subtitles.fontId`,value:e,disabled:s,onChange:e=>t(e.target.value),className:`text-small`,children:[c.some(e=>e.id==="default")?null:(0,h.jsx)(`option`,{value:`default`,children:`Default font · bundled`}),l?(0,h.jsxs)(`option`,{value:e,children:[e,` · saved font`]}):null,c.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.source]},e.id))]})]}),(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,children:[(0,h.jsx)(K4,{htmlFor:a,className:`mb-1`,children:`Upload font (.ttf or .otf)`}),(0,h.jsx)(`input`,{id:a,"data-play-field":`subtitles.fontUpload`,type:`file`,accept:`.ttf,.otf,font/ttf,font/otf`,disabled:s,className:`w-full text-small text-ink-2 file:mr-2 file:rounded-control file:border file:border-line-strong file:bg-sunken file:px-2 file:py-1 file:text-ink`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&n.pick(t)}})]})]}),s?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Uploading font…`}):null,n.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:n.error}):null,l&&o.data?(0,h.jsx)(`p`,{role:`alert`,children:`Saved font is unavailable. Choose another font or upload it again.`}):null,o.error?(0,h.jsxs)(`p`,{role:`alert`,className:`text-small text-danger`,children:[`The font list couldn't be loaded. `,o.error.message]}):null]})}function C_e(e){return e===`9:16`?{width:1080,height:1920}:e===`1:1`?{width:1080,height:1080}:{width:1920,height:1080}}function w_e(e,t){switch(e){case`top`:return{y:60,alignment:8,translateY:0};case`upper-middle`:return{y:t/4,alignment:5,translateY:-50};case`center`:return{y:t/2,alignment:5,translateY:-50};case`lower-middle`:return{y:t*3/4,alignment:5,translateY:-50};case`bottom`:return{y:t-60,alignment:2,translateY:-100}}}function T_e({value:e,format:t,sample:n=`Every story begins with a word.`,backgroundUrl:r,showCaptions:i=!0,maxFrameHeight:a}){let{api:o}=V(),s=rN(o,e.fontId),c=`subtitle-preview-${(0,m.useId)().replace(/[^a-zA-Z0-9]/g,``)}`,[l,u]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(typeof FontFace>`u`||!document.fonts)return;let e=!0,t=new FontFace(c,`url(${JSON.stringify(s)})`);return u(!1),t.load().then(t=>{e&&document.fonts.add(t)}).catch(()=>{e&&u(!0)}),()=>{e=!1,document.fonts.delete(t)}},[c,s]);let d=C_e(t),f=w_e(e.position??`bottom`,d.height),p=Number.isFinite(e.fontSize)?Math.max(16,Math.min(120,e.fontSize)):48,g={position:`absolute`,left:`50%`,top:`${f.y/d.height*100}%`,width:`${(d.width-120)/d.width*100}%`,transform:`translate(-50%, ${f.translateY}%)`,fontFamily:`"${c}", sans-serif`,fontSize:`${p/d.width*100}cqw`,lineHeight:1.2,overflowWrap:`anywhere`,WebkitTextStroke:`${2.5/d.width*100}cqw #101010`,paintOrder:`stroke fill`,textShadow:`0 ${100/d.width}cqw ${100/d.width}cqw #000`};return(0,h.jsxs)(`figure`,{className:`min-w-0 self-start`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Style preview`}),(0,h.jsx)(`span`,{children:t})]}),(0,h.jsxs)(`div`,{role:`img`,"aria-label":`Subtitle style preview`,"data-format":t,"data-position":e.position??`bottom`,className:`sl-media__frame mx-auto w-full text-center text-white`,style:{aspectRatio:`${d.width} / ${d.height}`,maxWidth:t===`9:16`?a?`min(240px, calc((${a}) * 9 / 16))`:240:t===`1:1`?360:480,containerType:`inline-size`},children:[r?(0,h.jsx)(`img`,{src:r,alt:``,className:`absolute inset-0 h-full w-full object-cover`}):null,i?(0,h.jsx)(`span`,{role:`note`,"aria-label":`Caption sample`,style:g,children:n}):null]}),(0,h.jsxs)(`figcaption`,{className:`mt-2 text-label text-ink-3`,children:[d.width,` × `,d.height,` · Preview at reduced scale.`,l?` Font preview unavailable; showing a fallback.`:``]})]})}function R6({value:e,format:t=`16:9`,audioEnabled:n,videoEnabled:r,disabled:i=!1,onChange:a,onUploading:o,problem:s,session:c,fontUpload:l,showPreview:u=!0,illustratedPositions:d=!1,rawFontSize:f}){let p=(0,m.useId)(),g=(0,m.useId)(),_=(0,m.useId)(),v=(0,m.useId)(),[y,b]=(0,m.useState)(!1),x=s?.(`subtitles.fontId`),S=s?.(`subtitles.fontSize`),C=s?.(`subtitles.mode`)??s?.(`subtitles`);return(0,h.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":`Subtitles`,children:[(0,h.jsxs)(`fieldset`,{disabled:i||!n,className:`flex min-w-0 flex-col gap-3 disabled:opacity-60`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 flex-1`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:p,children:`Subtitles`}),(0,h.jsx)(U,{id:`project.subtitles.mode`,className:`-my-1`})]}),(0,h.jsxs)(`select`,{id:p,"data-play-field":`subtitles.mode`,value:n?e.mode:`off`,disabled:l?.pending??y,"aria-describedby":_,"aria-invalid":C!==void 0,onChange:t=>a({...e,mode:t.target.value}),className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:[(0,h.jsx)(`option`,{value:`off`,children:`Off`}),(0,h.jsx)(`option`,{value:`files`,children:`Subtitle files (.srt + .vtt)`}),(0,h.jsx)(`option`,{value:`burn-in`,disabled:!r,children:`Burn into video + files`})]})]}),(0,h.jsx)(`span`,{className:`pb-1 text-label text-ink-3`,children:`English · local · no paid API`})]}),e.mode!==`off`&&n?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Timed from your narration on this computer. First use downloads an approximately 95 MB speech model. Review the subtitles before publishing.`}),(0,h.jsxs)(`div`,{className:`grid items-start gap-5`,style:{gridTemplateColumns:`repeat(auto-fit, minmax(min(100%, 240px), 1fr))`},children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(x_e,{...l?{upload:l}:{},value:e.fontId,onPick:t=>c?c.selectFont(t):a({...e,fontId:t}),onUploading:e=>{b(e),o?.(e)}}),(0,h.jsxs)(`div`,{className:d?`w-full`:`max-w-[180px]`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:g,children:`Subtitle font size`}),(0,h.jsx)(U,{id:`project.subtitles.size`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-5`,children:[d?(0,h.jsx)(`input`,{"aria-label":`Subtitle font size slider`,type:`range`,min:16,max:120,step:1,value:Math.max(16,Math.min(120,Number.isFinite(e.fontSize)?e.fontSize:48)),className:`min-w-0 flex-1 accent-accent`,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})}):null,(0,h.jsx)(zB,{className:d?`w-20`:void 0,id:g,"data-play-field":`subtitles.fontSize`,type:`number`,min:16,max:120,step:1,value:f?.value??e.fontSize,"aria-invalid":!SN(e)||S!==void 0,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})})]}),!SN(e)||S?(0,h.jsx)(`p`,{role:`alert`,className:`mt-1 text-label text-danger`,children:S??`Choose a whole font size from 16 to 120.`}):null]}),(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{htmlFor:d?void 0:v,id:`${v}-label`,children:`Subtitle position`}),(0,h.jsx)(U,{id:`project.subtitles.position`,className:`-my-1`})]}),d?(0,h.jsx)(q4,{type:`single`,"aria-labelledby":`${v}-label`,value:e.position??`bottom`,onValueChange:t=>{let n=oM.find(e=>e===t);n&&a({...e,position:n})},className:`grid w-full grid-cols-5 gap-2 overflow-visible border-0`,children:oM.map((t,n)=>(0,h.jsxs)(J4,{value:t,"aria-label":t,"data-play-field":(e.position??`bottom`)===t?`subtitles.position`:void 0,className:`flex min-w-0 flex-col items-center gap-2 rounded-control border border-line-strong bg-surface px-1 py-3 text-[10px] last:border-r data-[state=on]:border-focus data-[state=on]:text-accent-ink data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`relative block h-11 w-7 rounded-[2px] border border-current`,children:(0,h.jsx)(`span`,{className:`absolute left-1 right-1 h-[3px] bg-current`,style:{top:`${8+n*20}%`}})}),(0,h.jsxs)(`span`,{children:[t[0]?.toUpperCase(),t.slice(1)]})]},t))}):(0,h.jsx)(`select`,{id:v,"data-play-field":`subtitles.position`,value:e.position??`bottom`,onChange:t=>{let n=oM.find(e=>e===t.target.value);n&&a({...e,position:n})},className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:oM.map(e=>(0,h.jsxs)(`option`,{value:e,children:[e[0]?.toUpperCase(),e.slice(1)]},e))})]})]}),u?(0,h.jsx)(T_e,{value:e,format:t,...c?{sample:c.previewText}:{}}):null]}),c?.fontUpload&&!c.fontUploading?(0,h.jsxs)(`p`,{role:`alert`,children:[`Reattach `,c.fontUpload.name,`, or select a font.`]}):null,x?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}):null,e.mode===`files`?(0,h.jsx)(`p`,{className:`text-label text-ink-3`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]}):null]}),c?.fontUpload&&(e.mode===`off`||!n)?(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:c.fontUploading?`status`:`alert`,className:`text-small text-ink-2`,children:c.fontUploading?`Uploading ${c.fontUpload.name}…`:`Unfinished font upload: ${c.fontUpload.name}`}),l?.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:l.error}):null,(0,h.jsx)(B,{"data-play-field":`subtitles.fontUpload`,disabled:i,onClick:()=>c.selectFont(e.fontId),children:`Keep current font`})]}):null,C?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:C}):null,(0,h.jsx)(`p`,{id:_,className:`text-small text-ink-2`,children:n?r?`Optional: download subtitles separately or keep them visible in the video.`:`Audio exports support separate subtitle files. Enable Video to burn captions into an MP4.`:`Turn Audio on to add subtitles.`})]})}function z6({value:e,onPick:t}){let n=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`w-full`,...zb,children:[(0,h.jsxs)(`span`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(K4,{id:n,children:`Frame format`}),(0,h.jsx)(U,{id:`play.format`,className:`-my-1`})]}),(0,h.jsx)(q4,{type:`single`,value:e,"aria-labelledby":n,className:`w-full max-w-[560px] gap-3 overflow-visible border-0`,onValueChange:e=>{let n=GS.find(t=>t===e);n!==void 0&&t(n)},children:GS.map(t=>(0,h.jsxs)(J4,{value:t,"data-play-field":e===t?`format`:void 0,"aria-label":t,className:`flex h-28 min-w-0 flex-1 items-center justify-center gap-4 rounded-control border border-line-strong bg-surface p-3 last:border-r data-[state=on]:border-focus data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{className:`flex h-12 items-center justify-center`,"aria-hidden":`true`,children:(0,h.jsx)(`span`,{"data-format-shape":t,className:`block rounded-[2px] border-2 border-current`,style:{width:t===`16:9`?64:t===`1:1`?40:27,aspectRatio:t.replace(`:`,` / `)}})}),(0,h.jsxs)(`span`,{className:`text-left`,children:[(0,h.jsx)(`span`,{className:`block text-body font-semibold`,children:t}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:t===`16:9`?`Landscape`:t===`1:1`?`Square`:`Portrait`})]})]},t))})]})}function E_e({problem:e}){let t=XN(),{document:n}=t,{form:r}=n,i=e=>t.edit({...n,form:{...r,subtitles:{...e,fontSize:r.subtitles.fontSize}}});return(0,h.jsxs)(`div`,{"data-tour":`play-subtitles`,className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`See frame and caption changes in the preview as you go.`}),(0,h.jsx)(z6,{value:r.format,onPick:e=>t.edit({...n,form:{...r,format:e}})}),(0,h.jsx)(`div`,{className:`border-t border-line pt-4`,children:(0,h.jsx)(R6,{showPreview:!1,illustratedPositions:!0,fontUpload:t.fontUpload,session:{previewText:n.previewText,fontUploading:t.fontUploading,fontUpload:n.fontUpload,selectFont:t.selectFont,uploadSubtitleFont:t.uploadSubtitleFont},value:{...r.subtitles,fontSize:Number(r.subtitles.fontSize)},rawFontSize:{value:r.subtitles.fontSize,onChange:e=>t.edit({...n,form:{...r,subtitles:{...r.subtitles,fontSize:e}}})},format:r.format,audioEnabled:r.sources.audio!==`off`,videoEnabled:r.sources.video===`generate`&&r.sources.images!==`off`,onChange:i,problem:e})}),(0,h.jsx)(LB,{label:`Preview text`,tip:`play.preview-text`,className:`border-t border-line pt-4`,children:(0,h.jsx)(zB,{value:n.previewText,onChange:e=>t.edit({...n,previewText:e.target.value})})})]})}function D_e(e){let t=XN(),n=t.document,r=R3(),i=z3(),{form:a,entries:o,problem:s,update:c}=e;return(0,h.jsx)(qge,{...e,titled:!1,cast:r,language:i,rawCounts:{...n.form.chunking,onChange:(e,r)=>t.edit({...n,form:{...n.form,chunking:{...n.form.chunking,mode:e,...e===`words`?{words:r}:e===`characters`?{characters:r}:{}}}})},advanced:(0,h.jsxs)(h.Fragment,{children:[[`intro`,`outro`].map(e=>(0,h.jsx)(ZB,{field:e,label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,value:a[e],placeholder:`Off`,options:o.filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),problem:s(e),onPick:t=>c({[e]:t})},e)),(0,h.jsx)(`div`,{className:`col-span-full flex flex-wrap gap-2`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:e.onSettings,children:`Settings`})}),(0,h.jsx)(`div`,{className:`col-span-full empty:hidden`,children:(0,h.jsx)(F6,{...e,section:`narration`,onSettings:e.onSettings})})]})})}function O_e(e){let t=XN(),n=t.document;return(0,h.jsx)(Jge,{...e,titled:!1,more:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(__e,{document:n,problem:e.problem,onEdit:t.edit}),n.form.sources.article===`off`?null:(0,h.jsx)(b_e,{document:n,onEdit:t.edit})]}),rawNumbers:{values:n.form.imagePrompts,onChange:(e,r)=>t.edit({...n,form:{...n.form,imagePrompts:n.form.imagePrompts.map(t=>t.name===e?{...t,number:r}:t)}})}})}function k_e(e){let t=XN(),n=t.document,r=z3();return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(l_e,{...e,titled:!1,extras:!1,language:r,rawTiming:{imageSeconds:n.form.imageSeconds,zoomPercent:n.form.zoomPercent,edgeSilenceSeconds:n.form.edgeSilenceSeconds,onChange:(e,r)=>t.edit({...n,form:{...n.form,[e]:r}})}}),n.form.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:`sl-fields border-b border-line py-4`,children:(0,h.jsx)(P6,{field:`silenceGapSeconds`,label:`Silence between segments (seconds)`,tip:`play.silence-gap`,placeholder:String(e.silenceGapSeconds),step:.1,problem:e.problem(`silenceGapSeconds`),value:n.form.silenceGapSeconds??``,onChange:e=>{let{silenceGapSeconds:r,...i}=n.form;t.edit({...n,form:e.trim()===``?i:{...i,silenceGapSeconds:e}})}})}),(0,h.jsx)(E_e,{problem:e.problemOf})]})}function A_e(e){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(F6,{...e,section:`outputs`,onSettings:e.onSettings}),(0,h.jsx)(c_e,{...e}),(0,h.jsx)(`section`,{className:`border-b border-line py-4`,children:(0,h.jsx)(N6,{form:e.form,prompts:e.prompts,problem:e.problem,update:e.update,onPickFiles:e.onPickFiles,onRemoveFile:e.onRemoveFile,...e.onReattachFile===void 0?{}:{onReattachFile:e.onReattachFile}})}),e.form.sources.article===`off`?null:(0,h.jsx)(u_e,{...e})]})}function B6(e,t){if(t===void 0||t.length===0||e.trim()===``)return[];let n=[];for(let[r,i]of t.entries()){let t=1/0;for(let n of[i.name,...i.aliases]){let r=j_e(e,n);r!==void 0&&r<t&&(t=r)}Number.isFinite(t)&&n.push({member:i,at:t,order:r})}return n.sort((e,t)=>e.at-t.at||e.order-t.order).map(e=>e.member)}function j_e(e,t){let n=t.trim().split(/\s+/u).filter(Boolean);if(n.length===0)return;let r=RegExp(`(?<![\\p{L}\\p{N}])${n.map(M_e).join(`\\s+`)}(?![\\p{L}\\p{N}])`,`iu`).exec(e);return r===null?void 0:r.index}function M_e(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function N_e(e,t){let n=e.provided.reference?.file;if(e.sources.images===`generate`&&e.reference?.source===`provide`&&n!==void 0)return{image:{kind:`upload`,stagedFileId:n.id},drawnOn:`the establishing image`};let r=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),i=B6([e.title,...Object.values(e.values)].join(` `),r)[0]??r[0],a=i?.images[0];if(i!==void 0&&a!==void 0)return{image:{kind:`picture`,sha256:a},drawnOn:`${i.name}'s picture`}}function P_e({selected:e,reviewed:t}){let n=e=>B3.find(t=>t.stage===e)?.label??e;return e?.length?(0,h.jsxs)(`div`,{className:`space-y-3 text-body`,children:[t?.length?t.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`font-medium`,children:[`Run `,e.runIndex+1,` · Before `,n(e.stage)]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.dependents.length?`Also holds: ${e.dependents.map(n).join(`, `)}.`:`No dependent steps.`})]},`${e.runIndex}-${e.checkpointId}`)):(0,h.jsxs)(`p`,{children:[`Selected: `,e.map(e=>`Before ${n(e)}`).join(`, `),`. Refresh review to confirm dependent steps.`]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Approval required on the project page. Starting this run does not approve these checkpoints.`})]}):(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No review checkpoints selected.`})}function F_e({estimates:e}){let t=e.reduce((e,t)=>e+t.low,0),n=e.reduce((e,t)=>e+t.high,0),r=e.reduce((e,t)=>e+t.unknown,0),i=e[0]?.rows.map((t,n)=>({...t,low:e.some(e=>e.rows[n]?.low===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.low??0),0),high:e.some(e=>e.rows[n]?.high===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.high??0),0),apiLow:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiLow==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiLow??0),0),apiHigh:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiHigh==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiHigh??0),0)}))??[],a=e.some(e=>e.apiLow!==void 0),o=e.reduce((e,t)=>e+(t.apiLow??0),0),s=e.reduce((e,t)=>e+(t.apiHigh??0),0),c=e.reduce((e,t)=>e+(t.apiUnknown??0),0);return e.length===0?(0,h.jsx)(`div`,{}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-title-2 font-semibold`,children:[r?`Known subtotal: `:`Estimated total: `,V6(t,n)]}),r?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Plus `,r,` stage charge`,r===1?``:`s`,` with unavailable pricing.`]}):null,(0,h.jsxs)(`details`,{className:`rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Cost by stage · `,i.length,` `,i.length===1?`stage`:`stages`]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 pt-1 pb-3`,children:[a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o===0&&s===0?`CLI steps: $0 on your plan · no API price is listed for their models.`:`CLI steps: $0 on your plan · ~${V6(o,s)} via API${c?` (plus ${String(c)} with no API price)`:``}.`}):null,(0,h.jsx)(`ul`,{"aria-label":`Cost by stage`,className:`m-0 list-none divide-y divide-line p-0`,children:i.map(e=>(0,h.jsxs)(`li`,{className:`py-2`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between gap-4 text-small`,children:[(0,h.jsx)(`span`,{children:e.stage}),(0,h.jsx)(`span`,{className:`text-right tabular-nums`,children:e.onPlan===!0?e.apiLow===null||e.apiHigh===null?`$0 on your plan · API price unknown`:`$0 on your plan · ~${V6(e.apiLow,e.apiHigh)} via API`:e.low===null||e.high===null?`Unknown`:V6(e.low,e.high)})]}),(0,h.jsx)(`p`,{className:`m-0 mt-0.5 text-label text-ink-3`,children:e.detail})]},e.stage))}),[...new Set(e.flatMap(e=>e.assumptions))].map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e},e)),(0,h.jsxs)(`p`,{className:`m-0 text-label text-ink-3`,children:[`Catalogue verified `,e[0]?.catalogueDate??`date unavailable`,`. Batch rows show combined costs.`]})]})]})]})}function V6(e,t){let n=e=>e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`;return e===t?n(e):`${n(e)} – ${n(t)}`}function H6(e){let t=vA(hA(e)),n=new Map(vA(aA)),r=t.filter(([e,t])=>e!==`Cuts`&&n.get(e)!==t).map(([e,t])=>e===`Animate images`?`Animated images: ${t} (paid)`:e===`Chapter cards`?`Chapter cards`:e===`Transition`?t:`${e}: ${t}`);return r.length===0?`Plain cuts, no effects`:r.join(` · `)}function I_e(e){return e===void 0?{ok:!1,text:`Provider status unavailable`}:e.readiness.kind===`cli`?JP(e.readiness)?{ok:!0,text:e.readiness.version===void 0?`CLI ready`:`CLI ready · ${e.readiness.version}`}:{ok:!1,text:e.readiness.issue??`CLI not found`}:e.readiness.kind===`local`?e.readiness.available?{ok:!0,text:`Built-in voice · ${e.readiness.engine??`ready`}`}:{ok:!1,text:e.readiness.issue??`No speech program found`}:e.readiness.hasKey?{ok:!0,text:`API key saved`}:{ok:!1,text:`API key missing`}}function L_e(e,t){let n=e.sources.audio===`generate`,r=[`from_prompt`,`prompt_by_llm`].includes(e.sources.thumbnail);return[...(e.sources.article===`generate`||e.sources.thumbnail===`prompt_by_llm`||oj(e)||wN(e)||n&&[`intro`,`outro`].some(n=>t.some(t=>t.category===n&&t.name===e[n]&&t.mode===`llm`)))&&e.llm?[{field:`llm.provider`,family:`llm`,label:`Text generation`,provider:e.llm.provider,model:e.llm.model}]:[],...n&&e.audio?[{field:`audio.provider`,family:`tts`,label:`Narration`,provider:e.audio.provider,model:e.audio.model,voice:e.audio.voice}]:[],...(e.sources.images===`generate`||r||wN(e)||gA(e))&&e.images?[{field:`images.provider`,family:`image`,label:`Images`,provider:e.images.provider,model:e.images.model}]:[]]}function U6({name:e,children:t}){return(0,h.jsxs)(`section`,{"aria-label":`${e} summary`,className:`min-w-0 border-t border-line pt-5`,children:[(0,h.jsx)(`h3`,{className:`mb-4 font-semibold`,children:e}),t]})}function R_e({form:e,entries:t,providers:n,voices:r,textModels:i,audioModels:a,imageModels:o,onReveal:s}){let c=L_e(e,t);if(!c.length)return(0,h.jsx)(U6,{name:`Run readiness`,children:(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No generated providers required. Supplied content is ready for processing.`})});let l={llm:i,tts:a,image:o};return(0,h.jsxs)(U6,{name:`Run readiness`,children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`These checks are refreshed with Review and checked again when you start.`}),(0,h.jsx)(`ul`,{className:`divide-y divide-line`,"aria-label":`Run readiness checks`,children:c.map(e=>{let t=n?.find(t=>t.id===e.provider&&t.family===e.family),i=I_e(t),a=l[e.family],o=a?.models.find(t=>t.id===e.model),c=a===void 0?{ok:!0,text:`Model checked at Start`}:o!==void 0||a.allowsCustom?{ok:!0,text:`Model available`}:{ok:!1,text:`Model unavailable`},u=e.voice===void 0?void 0:r===void 0?{ok:!1,text:`Voice list unavailable`}:r.some(t=>t.provider===e.provider&&t.voiceId===e.voice)?{ok:!0,text:`Voice saved`}:{ok:!1,text:`Voice missing`},d=[i,c,...u?[u]:[]],f=d.every(e=>e.ok);return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-3 py-3`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,h.jsx)(`span`,{className:f?`text-lime`:`text-danger`,children:f?`Ready`:d.filter(e=>!e.ok).map(e=>e.text).join(` · `)}),f?null:(0,h.jsx)(B,{variant:`quiet`,onClick:()=>s(e.field),children:`Edit ↗`})]},`${e.family}:${e.provider}`)})})]})}function z_e({fields:e,onReveal:t,children:n}){let{document:r,review:i}=XN(),{form:a}=r,{api:o}=V(),s=_(),c=s.getQueryData(db(o).queryKey),l=s.getQueryData(mb(o).queryKey),u=s.getQueryData(fb(o).queryKey),d=s.getQueryData(eN),f=s.getQueryData(WB(a.llm.provider)),p=s.getQueryData(WB(a.audio.provider)),m=s.getQueryData(WB(a.images.provider)),g=a.sources.audio===`generate`,v=[`from_prompt`,`prompt_by_llm`].includes(a.sources.thumbnail),y=a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||oj(a)||wN(a)||g&&[`intro`,`outro`].some(e=>l?.entries.some(t=>t.category===e&&t.name===a[e]&&t.mode===`llm`)),b=e=>c?.providers.find(t=>t.id===e)?.displayName??e,x=(e,n,r)=>(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[90px_minmax(0,1fr)_auto] items-start gap-x-3 py-1 sm:grid-cols-[145px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(`dt`,{className:`break-words py-2 text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`min-w-0 whitespace-pre-wrap break-words py-2`,children:r||`Not selected`}),n?(0,h.jsx)(`dd`,{children:(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Edit ${e}`,onClick:()=>t(n),children:`Edit ↗`})}):null]},n??e),S=a.chunking.mode===`words`||a.chunking.mode===`characters`?a.chunking.mode:null;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R_e,{form:a,entries:l?.entries??[],providers:c?.providers,voices:u?.voices,textModels:f,audioModels:p,imageModels:m,onReveal:t}),(0,h.jsxs)(U6,{name:`Content`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Project`,`title`,a.title||`Untitled run`),x(`Article`,`sources.article`,DN[a.sources.article]),a.sources.article===`generate`?x(`Article prompt`,`articlePrompt`,a.articlePrompt):x(`Article text`,`provided.article`,`Your article`),a.sources.article===`generate`?x(`Research`,`sources.research`,DN[a.sources.research]):x(`Research`,null,`Off · Article is provided`),a.sources.research===`provide`&&a.sources.article===`generate`?x(`Research text`,`provided.research`,a.provided.research):null,y?(0,h.jsxs)(h.Fragment,{children:[x(`Text provider`,`llm.provider`,b(a.llm.provider)),x(`Text model`,`llm.model`,f?.models.find(e=>e.id===a.llm.model)?.name??a.llm.model),a.llm.thinking||f?.models.find(e=>e.id===a.llm.model)?.thinkingModes?.length?x(`Thinking`,`llm.thinking`,a.llm.thinking??`Model default`):null]}):null,e.map(({name:e})=>x(e,`values.${e}`,a.values[e]??``))]}),n]}),(0,h.jsx)(U6,{name:`Outputs`,children:(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Narration`,`sources.audio`,DN[a.sources.audio]),g?(0,h.jsxs)(h.Fragment,{children:[x(`Audio provider`,`audio.provider`,b(a.audio.provider)),x(`Audio model`,`audio.model`,p?.models.find(e=>e.id===a.audio.model)?.name??a.audio.model),x(`Voice`,`audio.voice`,u?.voices.find(e=>e.provider===a.audio.provider&&e.voiceId===a.audio.voice)?.name??a.audio.voice),x(`Chunking`,S?`chunking.${S}`:`chunking.mode`,S?`Every ${a.chunking[S]||`(not entered)`} ${S}`:a.chunking.mode===`whole`?`Whole text`:`Paragraph`),x(`Intro`,`intro`,a.intro||`Off`),x(`Narration Preparation`,`narrationPrompt`,a.narrationPrompt?`${a.narrationPrompt} · One LLM call per narration chunk and entry`:`Off`),x(`Outro`,`outro`,a.outro||`Off`)]}):null,a.sources.audio===`provide`?x(`Narration file`,`provided.audio`,a.provided.audio?.name):null,x(`Images`,`sources.images`,DN[a.sources.images]),a.sources.images===`generate`||v||wN(a)?(0,h.jsxs)(h.Fragment,{children:[x(`Image provider`,`images.provider`,b(a.images.provider)),x(`Image model`,`images.model`,m?.models.find(e=>e.id===a.images.model)?.name??a.images.model),a.images.thinking===void 0?null:x(`Image effort`,`images.thinking`,a.images.thinking)]}):null,a.sources.images===`generate`&&a.reference!==void 0&&a.reference.source!==`off`?x(`Establishing image`,a.reference.source===`prompt`?`reference.prompt`:`provided.reference`,`${a.reference.source===`prompt`?a.reference.prompt||`(no prompt picked)`:a.provided.reference?.name??`(no file attached)`}${a.reference.thumbnail?` · thumbnail too`:``}`):null,a.sources.images===`generate`?a.imagePrompts.length?a.imagePrompts.map((e,t)=>x(e.name,`imagePrompts.${t}.number`,`${e.name} · ${e.number||`(not entered)`} images`)):x(`Image prompts`,`imagePrompts`,`None selected`):null,a.sources.images===`provide`?x(`Image files`,`provided.images`,a.provided.images.length?(0,h.jsx)(`ol`,{className:`list-inside list-decimal`,children:a.provided.images.map(e=>(0,h.jsx)(`li`,{children:e.name},e.attachmentId))}):`No files selected`):null,x(`Thumbnail`,`sources.thumbnail`,DN[a.sources.thumbnail]),v?x(`Thumbnail prompt`,`thumbnailPrompt`,a.thumbnailPrompt):null,a.sources.thumbnail===`provide`?x(`Thumbnail file`,`provided.thumbnail`,a.provided.thumbnail?.name):null,x(`Video`,`sources.video`,DN[a.sources.video]),a.sources.video===`generate`?x(`Seconds per image`,`imageSeconds`,a.imageSeconds||`(not entered)`):null,a.sources.video===`generate`?x(`Zoom`,`zoomPercent`,a.zoomPercent?`${a.zoomPercent}%`:`(not entered)`):null,a.sources.video===`generate`?x(`Motion`,`motionStyle`,HA[a.motionStyle]):null,a.sources.video===`generate`?x(`Cuts`,`videoEdit.cuts`,lA[hA(a).cuts]):null,a.sources.video===`generate`?x(`Look`,`videoEdit`,H6(a)):null,a.sources.audio===`off`?null:x(`Silence at start and end`,`edgeSilenceSeconds`,a.edgeSilenceSeconds?`${a.edgeSilenceSeconds} s`:`(not entered)`),a.sources.audio===`off`?null:x(`YouTube description`,`youtubeDescription`,a.youtubeDescription===!0?`${a.descriptionPrompt||`Built-in`} prompt · One LLM call after subtitle timing`:`Off`),a.sources.audio===`off`?null:x(`Shorts`,`shorts.enabled`,wN(a)&&a.shorts!==void 0?[`${a.shorts.count} shorts of ${a.shorts.minSeconds}-${a.shorts.maxSeconds} s`,`${a.shorts.prompt||`Built-in`} prompt`,`${a.shorts.imagePrompt||`Built-in`} image style`,...B_e(a.shorts,a.provided.shortsMusic?.name),`Vertical images and renders after subtitle timing`].join(` · `):`Off`),x(`Document`,`sources.document`,YS(a.sources,`document`)===`generate`?`PDF · ${sC(a.document)} theme`:DN.off)]})}),(0,h.jsxs)(U6,{name:`Checkpoints`,children:[(0,h.jsx)(P_e,{selected:a.checkpoints,reviewed:i.valid?i.receipt?.checkpointSet:void 0}),(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Edit checkpoints`,onClick:()=>t(`checkpoints`),children:`Edit checkpoints ↗`})]}),(0,h.jsxs)(U6,{name:`Style`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Frame`,`format`,a.format),a.sources.audio===`off`?x(`Subtitles`,null,`Off · Audio is Off`):x(`Subtitles`,`subtitles.mode`,a.subtitles.mode),a.sources.audio!==`off`&&a.subtitles.mode!==`off`?(0,h.jsxs)(h.Fragment,{children:[x(`Subtitle font`,`subtitles.fontId`,d?.fonts.find(e=>e.id===a.subtitles.fontId)?.name??a.subtitles.fontId),x(`Subtitle size`,`subtitles.fontSize`,`${a.subtitles.fontSize||`(not entered)`} px`),x(`Subtitle position`,`subtitles.position`,a.subtitles.position)]}):null]}),a.sources.audio!==`off`&&a.subtitles.mode===`files`?(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]})]})}function B_e(e,t){let n=Bk(e),r=n.speed,i=n.musicVolume;return[...n.titleOnScreen===!0?[`Title on screen`]:[],...r!==void 0&&r!==1?[`${r.toFixed(2)}× speed`]:[],...t===void 0?i!==void 0&&i!==15?[`Music at ${String(i)}% once added in Edit project`]:[]:[`Music: ${t} at ${String(i??15)}%`],...n.fullVideoLink===void 0?[]:[`Links ${n.fullVideoLink}`]]}function V_e({fields:e,errors:t,onReveal:n,problem:r}){let i=XN(),{document:a,review:o}=i,s=a.form;(0,m.useEffect)(()=>{i.reviewDraft()},[i.reviewDraft]);let c=o.valid?o.receipt?.runs??[]:[];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Everything this run will do, the checkpoints it stops at and the reviews it runs. The estimate and the Play key stay in the right rail.`}),t.length?(0,h.jsx)(`ul`,{"aria-label":`Setup errors`,className:`text-small text-danger`,children:t.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(B,{variant:`quiet`,onClick:()=>n(e.field),children:e.message})},`${e.field}-${e.message}`))}):null,(0,h.jsx)(yge,{problem:r}),(0,h.jsx)(rV,{problem:r}),(0,h.jsx)(z_e,{fields:e,onReveal:n,children:(0,h.jsxs)(`details`,{className:`mt-5 border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:s.sources.article===`provide`?`Read the supplied article and resolved prompts`:`Read the resolved prompt`}),c.length?c.map((e,t)=>(0,h.jsxs)(`div`,{className:`mt-4`,children:[(0,h.jsx)(`h4`,{className:`font-medium`,children:e.draft.title}),e.draft.sources.article===`provide`?(0,h.jsx)(`p`,{className:`mt-3 whitespace-pre-wrap break-words text-body`,children:e.draft.provided.article}):null,Object.entries(e.rendered).map(([e,t])=>(0,h.jsxs)(`div`,{className:`mt-3`,children:[(0,h.jsx)(`h5`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-body`,children:t})]},e))]},a.variants[t-1]?.id??i.activeId)):(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Refresh review to read the exact resolved inputs.`})]})})]})}function H_e(e,t,n){return[...F3(e).map(e=>(t[e]??``).trim()===``?`${e} is left empty in the template.`:`${e} is left empty in the template (this video's ${e}, "${t[e]}", is not saved).`),...n>0?[`The ${n===1?`other video`:`${String(n)} other videos`} queued here ${n===1?`is`:`are`} not saved.`]:[]]}function U_e({open:e,onClose:t}){let{api:n}=V(),r=_(),i=XN(),a=Ry(),o=I(lq(n)),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),p=(0,m.useRef)(null),{document:g}=i,v=H_e(g.form.title,g.form.values,g.variants.length),y=()=>{u(null),t()},b=async()=>{let e=s.trim();if(!(e===``||d)){f(!0),u(null);try{if(!await i.flush()){u(`Your draft wasn't saved, so the template wasn't either. Press Retry beside Drafts, then Save template again.`);return}p.current?.name!==e&&(p.current={name:e,id:crypto.randomUUID()});let s=o.data?.find(e=>e.id===g.templateSource?.id),l=g.channelId??(s?E1(s):void 0),d=hge(g),f=await dq(n,{id:p.current.id,name:e,document:l===void 0?d:{...d,channelId:l}});if(!f.ok){p.current=null,u(`The template wasn't saved. ${f.message}`);return}p.current=null,c(``),a(`Template "${e}" saved.`,`success`),await r.invalidateQueries({queryKey:iq}),t()}catch(e){u(`The template wasn't saved. ${e instanceof Error?e.message:`Press Save template again.`}`)}finally{f(!1)}}};return(0,h.jsx)(Vy,{open:e,onOpenChange:e=>{e||y()},title:`Save as template`,description:`Keeps this setup's prompts, voice, images, style, outputs and reviews to start the next video from.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`secondary`,onClick:y,children:`Cancel`}),(0,h.jsx)(B,{variant:`primary`,disabled:s.trim()===``||d,disabledReason:d?`Saving the template`:`Name the template first`,onClick:()=>void b(),children:`Save template`})]}),children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,h.jsx)(LB,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(zB,{autoFocus:!0,value:s,maxLength:120,placeholder:g.form.title.replace(/\{\{[^}]*\}\}/g,``).trim()||`My setup`,onChange:e=>c(e.target.value)})}),v.length?(0,h.jsx)(`ul`,{"aria-label":`Left out of the template`,className:`m-0 flex list-none flex-col gap-1 p-0 text-small text-ink-2`,children:v.map(e=>(0,h.jsx)(`li`,{children:e},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Every keyword keeps its value: the title names none.`}),l?(0,h.jsx)(aI,{tone:`danger`,title:l}):null]})})}var W_e=new Set([`a`,`an`,`the`,`of`,`and`,`or`,`in`,`on`,`to`,`for`,`with`,`vs`,`s`]);function W6(e){return e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase().replace(/&/g,` and `).replace(/[^\p{L}\p{N}]+/gu,` `).trim()}function G6(e){let t=W6(e).split(` `).filter(e=>e!==``&&!W_e.has(e)).map(e=>e.length>3&&e.endsWith(`s`)&&!e.endsWith(`ss`)?e.slice(0,-1):e);return new Set(t)}function G_e(e,t){let n=0;for(let r of e)t.has(r)&&(n+=1);return n}function K_e(e,t){let n=W6(e);if(n===W6(t))return n!==``;let r=G6(e),i=G6(t);if(r.size===0||i.size===0)return!1;let a=G_e(r,i);if(a/(r.size+i.size-a)>=.6)return!0;let o=Math.min(r.size,i.size),s=Math.max(r.size,i.size);return a===o&&o/s>=.5}function q_e(e,t,n){let r=e.map(e=>e.trim()).filter(e=>e!==``);if(r.length===0)return;let i=e=>r.some(t=>K_e(t,e)),a=t.find(i);if(a!==void 0)return{title:a,where:`project`};let o=n.find(i);return o===void 0?void 0:{title:o,where:`video`}}function J_e({topics:e}){let{api:t}=V(),n=XN(),{document:r}=n,i=L3(),a=I(ob(t)),o=I(v2(t,i)),{form:s}=r,c=FK(s.title,s.values),l=q_e(e.length===0?[s.title]:[c,...e.map(e=>s.values[e]??``)],(a.data?.projects??[]).filter(e=>e.channelId===i).map(e=>e.title),(o.data??[]).map(e=>e.title));return l===void 0||n.review.created!==null?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.where===`project`?`This channel already has a video on this: "${l.title}" (in Projects). Start anyway if you want another take.`:`This channel already uploaded "${l.title}" (Channel → Existing videos). Start anyway if you want another take.`})}function Y_e({rows:e,open:t,onChange:n}){return(0,h.jsx)(`ul`,{"aria-label":`Setup`,className:`m-0 flex list-none flex-col border-t border-line p-0`,children:e.map(e=>{let r=t.has(e.id)&&e.editor!==void 0,i=`play-row-${e.id}`;return(0,h.jsxs)(`li`,{"data-setup-row":e.id,className:`border-b border-line`,children:[(0,h.jsx)(W,{title:e.label,size:`small`,className:`items-center py-3.5`,status:e.problem?(0,h.jsx)(OS,{tone:`failed`,children:`Needs setup`}):void 0,meta:(0,h.jsx)(`span`,{"data-row-summary":!0,className:e.problem&&!r?`block break-words text-danger`:`block truncate text-ink-2`,title:e.problem&&!r?void 0:e.summary,children:r?e.summary:e.problem??e.summary}),children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-expanded":e.editor===void 0?void 0:r,"aria-controls":e.editor===void 0?void 0:i,"aria-label":`${r?`Done with`:`Change`} ${e.label.toLowerCase()}`,onClick:()=>n(e.id,!r),children:r?`Done`:`Change`})}),r?(0,h.jsx)(`section`,{id:i,"aria-label":e.label,className:`min-w-0 pb-6`,children:e.editor}):null]},e.id)})})}var K6=[{id:`title`,label:`Title and keywords`,section:`content`},{id:`article`,label:`Article`,section:`content`},{id:`narration`,label:`Narration`,section:`outputs`},{id:`images`,label:`Images`,section:`outputs`},{id:`video`,label:`Video and style`,section:`style`},{id:`outputs`,label:`Outputs`,section:`outputs`},{id:`reviews`,label:`Reviews`,section:`review`},{id:`channel`,label:`Channel`,section:`content`}],X_e=[[`title`,[`title`,`values`]],[`article`,[`sources.article`,`sources.research`,`articlePrompt`,`provided.article`,`provided.research`,`llm`]],[`narration`,[`sources.audio`,`audio`,`voices`,`provided.audio`,`narrationPrompt`,`intro`,`outro`,`chunking`]],[`images`,[`sources.images`,`images`,`imagePrompts`,`provided.images`,`reference`,`provided.reference`]],[`video`,[`sources.video`,`imageSeconds`,`zoomPercent`,`motionStyle`,`edgeSilenceSeconds`,`silenceGapSeconds`,`sentencePauseSeconds`,`paragraphPauseSeconds`,`loudness`,`videoEdit`,`format`,`subtitles`,`fontUpload`]],[`outputs`,[`sources.thumbnail`,`thumbnailPrompt`,`provided.thumbnail`,`thumbnailCount`,`youtubeDescription`,`descriptionPrompt`,`shorts`,`sources.document`,`document`]],[`reviews`,[`checkpoints`,`reviews`]],[`channel`,[`channelId`,`useBrandKit`,`language`]]],q6=(e,t)=>e.some(e=>t===e||t.startsWith(`${e}.`));function J6(e,t=`article`){return q6([`llm`],e)?t:X_e.find(([,t])=>q6(t,e))?.[0]}function Z_e(e){switch(e){case`content`:return[`title`,`article`,`channel`];case`outputs`:return[`narration`,`images`,`video`,`outputs`];case`style`:return[`video`];case`review`:return[`reviews`]}}function Y6(e,t,n,r=`article`){return t.find(t=>J6(t.field,r)===e?e===`title`?t.field===`title`?n.length>0:!n.some(e=>t.field===`values.${e}`):!0:!1)}function Q_e(e,t,n){let r=e=>e===``?`no provider`:n.providers.find(t=>t.id===e)?.displayName??e,i=e=>e.filter(e=>typeof e==`string`&&e!==``).join(` · `);switch(e){case`title`:return i([n.topics.length?t.title:!1,n.keywords===0?`No keywords`:`${String(n.keywords)} keyword${n.keywords===1?``:`s`}`]);case`article`:return t.sources.article===`off`?`Off: no article`:t.sources.article===`provide`?`Your article`:i([t.articlePrompt||`No prompt picked`,t.llm.provider?`${r(t.llm.provider)} · ${t.llm.model||`no model`}`:!1,t.sources.research===`off`?`research off`:`research: ${DN[t.sources.research].toLowerCase()}`]);case`narration`:{if(t.sources.audio===`off`)return`Off, a silent video`;if(t.sources.audio===`provide`)return t.provided.audio?.name??`Your narration file`;let e=n.voices.find(e=>e.provider===t.audio.provider&&e.voiceId===t.audio.voice);return i([r(t.audio.provider),t.voices===void 0?e?.name??(t.audio.voice||`no voice`):`${bA[t.voices.format]}, ${String(t.voices.speakers.length)} speakers`,t.narrationPrompt?`prepared with ${t.narrationPrompt}`:!1,t.intro?`intro ${t.intro}`:!1,t.outro?`outro ${t.outro}`:!1])}case`images`:{if(t.sources.images===`off`)return`Off`;if(t.sources.images===`provide`)return`${String(t.provided.images.length)} of your images`;let e=t.imagePrompts.map(e=>`${e.name} × ${e.number||`?`}`);return i([e.length?e.join(`, `):`No image prompts picked`,r(t.images.provider),t.images.model,t.reference!==void 0&&t.reference.source!==`off`&&`establishing image`])}case`video`:return i([t.format,t.sources.video===`off`?`no video`:lA[hA(t).cuts].toLowerCase(),t.sources.video!==`off`&&n.look,t.sources.audio!==`off`&&t.subtitles.mode!==`off`?`captions ${n.fontName??t.subtitles.fontId} ${t.subtitles.fontSize} ${t.subtitles.position}`:`no captions`]);case`outputs`:return i([t.sources.thumbnail===`off`?!1:t.sources.thumbnail===`provide`?`your thumbnail`:t.thumbnailCount===3?`3 thumbnails`:`1 thumbnail`,wN(t)&&t.shorts?`${t.shorts.count} shorts`:!1,t.youtubeDescription===!0&&t.sources.audio!==`off`&&`YouTube description`,t.sources.document===`generate`&&`PDF (${sC(t.document)})`])||`Only the video`;case`reviews`:return i([n.checkpoints===0?`No checkpoints`:`${String(n.checkpoints)} checkpoint${n.checkpoints===1?``:`s`}`,n.reviews===0?`no automatic reviews`:`${String(n.reviews)} automatic review${n.reviews===1?``:`s`}`]);case`channel`:return i([n.channel??`Default channel`,n.brandKit?`brand kit on`:`brand kit off`,t.language===void 0?void 0:NO(t.language).name])}}function $_e({review:e,blocker:t,errors:n,pendingUpload:r}){if(e.starting)return;if(e.uncertain)return{text:`Slopify didn't confirm the last start. Press Check Start result to find out before starting again.`};if(t)return{text:t.hint,field:t.field};let i=n[0];if(i)return{text:i.message,field:i.field};if(r)return{text:`Wait for uploads to finish before Start`,field:r};if(e.error)return{text:e.error};if(e.pending||!e.valid)return{text:`Checking your setup and the estimate…`}}function eve({errors:e,blocker:t,saveProblem:n,onReveal:r,onWholeSetup:i,onSaveTemplate:a,preview:o}){let s=XN(),{document:c,review:l}=s,u=HN(c,s.view),d=l.starting||l.uncertain;(0,m.useEffect)(()=>{s.reviewDraft()},[s.reviewDraft]);let f=!l.valid&&!l.pending&&!l.starting&&!l.uncertain&&l.error===null&&e.length===0&&t===void 0&&!u&&s.activeId!==null;(0,m.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>void s.reviewDraft(),800);return()=>clearTimeout(e)},[f,c,s.reviewDraft]);let p=l.valid&&l.receipt?l.receipt.runs.length:RN(c),g=$_e({review:l,blocker:t,errors:e,pendingUpload:u}),_=l.starting||!l.uncertain&&(!l.valid||l.pending||e.length>0||!!u);return(0,h.jsxs)(h.Fragment,{children:[o,(0,h.jsxs)(`section`,{"aria-label":`Start`,className:`flex min-w-0 flex-col gap-4 border-t border-line pt-5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:p===1?`1 video`:`${String(p)} videos`}),p>1?(0,h.jsx)(Bb,{label:`Queue`,tip:`play.batch-queue`,checked:VN(c),disabled:d,onChange:e=>s.edit({...c,queue:e})}):(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`One run`})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Estimated cost`,info:`play.estimate`,size:`small`,className:`pb-0`}),l.valid&&l.receipt?(0,h.jsx)(F_e,{estimates:l.receipt.estimates}):(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.pending?`Calculating the estimate…`:`The estimate appears once the setup is complete.`}),(0,h.jsx)(LB,{label:`Expected article words per video`,tip:`play.expected-words`,className:`mt-2`,children:(0,h.jsx)(zB,{"data-play-field":`expectedWords`,type:`number`,min:1,max:1e5,value:c.expectedWords,disabled:d,onChange:e=>s.edit({...c,expectedWords:e.target.value})})})]}),n?(0,h.jsx)(aI,{tone:`danger`,title:n}):null,(0,h.jsxs)(Fy,{"data-tour":`play-start`,disabled:_,"aria-describedby":g?`play-start-reason`:void 0,onClick:()=>{s.startRun()},children:[(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75}),BN(l,c)]}),(0,h.jsx)(`div`,{id:`play-start-reason`,className:`min-h-5 text-center text-small`,children:g===void 0?(0,h.jsx)(`span`,{className:`text-ink-3`,children:p===1?`Nothing starts until you press it.`:VN(c)?`They run one after another. Nothing starts until you press it.`:`They all run at once. Nothing starts until you press it.`}):g.field===void 0?(0,h.jsx)(`span`,{role:l.error?`alert`:`status`,className:l.error?`text-danger`:`text-ink-2`,children:g.text}):(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center justify-center gap-x-1`,children:[(0,h.jsx)(`span`,{id:`play-start-field`,className:`text-waiting`,children:g.text}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-describedby":`play-start-field`,onClick:()=>r(g.field??``),children:`Go to the field`})]})}),(0,h.jsxs)(Iy,{className:`justify-center`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center`,children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:l.pending||d||!!u,onClick:()=>{s.reviewDraft()},children:`Refresh review`}),(0,h.jsx)(U,{id:`play.refresh-review`})]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-keyshortcuts":Ux(nP.reviewSetup),onClick:i,children:`Review the whole setup`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:a,children:`Save as template`})]})]})]})}function tve(e,t,n){let r=e?.prompts??[],i=e?.entries??[];return{prompts:[...r,...t.filter(e=>!r.some(t=>t.kind===e.kind&&t.name.toLowerCase()===e.name.toLowerCase()))],entries:[...i,...n.filter(e=>!i.some(t=>t.category===e.category&&t.name.toLowerCase()===e.name.toLowerCase()))]}}function nve({topics:e,onError:t}){let{api:n}=V(),r=_(),i=XN(),a=I(lq(n)),o=I(cx(n)),[s,c]=(0,m.useState)(!1),l=i.review.starting||i.review.uncertain||i.review.created!==null,u=i.document.templateSource,d=a.data?.find(e=>e.id===u?.id),f=e=>o.data?.find(t=>t.id===e)?.name,p=async o=>{if(t(null),o===``){await i.newDraft();return}let s=a.data?.find(e=>e.id===o);if(s){c(!0);try{if(!await i.flush()){t(`Your draft wasn't saved, so the template wasn't applied. Press Retry beside Drafts, then pick the template again.`);return}let a=Object.fromEntries(e.map(e=>[e,i.document.form.values[e]??``]).filter(([,e])=>e.trim()!==``)),o=await _q(n,s,crypto.randomUUID());if(!o.ok){t(`The template "${s.name}" wasn't applied. ${o.message}`);return}if(await r.invalidateQueries({queryKey:[`play-drafts`]}),!await i.open(o.value.draft.id)){t(`The draft made from "${s.name}" didn't open. Open it from Drafts.`);return}let c=o.value.draft.document,l=Object.fromEntries(Object.entries(a).filter(([e])=>(c.form.values[e]??``)===``));Object.keys(l).length>0&&i.edit({...c,form:{...c.form,values:{...c.form.values,...l}}})}catch(e){t(e instanceof Error?`The template "${s.name}" wasn't applied. ${e.message}`:`The template "${s.name}" wasn't applied. Pick it again.`)}finally{c(!1)}}},g=a.error?`Templates didn't load. ${a.error.message}`:d?[f(E1(d)),`version ${String(d.version)}`].filter(Boolean).join(` · `):a.data?.length===0?`No templates yet. Set this video up, then Save as template.`:void 0;return(0,h.jsx)(LB,{label:`Template`,tip:`play.template`,help:g,children:(0,h.jsxs)(VB,{"data-play-field":`template`,value:d?.id??``,disabled:s||l,onChange:e=>void p(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:u&&!d?`Template no longer saved`:`No template`}),(a.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})}function rve({topics:e,problem:t}){let n=XN(),{document:r}=n,{form:i}=r,a=e=>{n.edit({...r,form:e}),n.invalidateReview(!0)};if(e.length===0)return(0,h.jsx)(LB,{label:`Title`,tip:`play.title`,error:t(`title`),children:(0,h.jsx)(zB,{"data-play-field":`title`,className:`!h-11 text-[17px]`,value:i.title,maxLength:200,placeholder:`What's the video about?`,"aria-invalid":t(`title`)!==void 0,onChange:e=>a({...i,title:e.target.value})})});let o=FK(i.title,i.values);return(0,h.jsx)(`div`,{className:`grid min-w-0 gap-4`,children:e.map((n,r)=>(0,h.jsx)(LB,{label:n,tip:`play.topic`,help:r===e.length-1?(0,h.jsxs)(h.Fragment,{children:[`Title: `,(0,h.jsx)(`b`,{className:`font-semibold text-ink`,children:o})]}):void 0,error:t(`values.${n}`)??(r===e.length-1?t(`title`):void 0),children:(0,h.jsx)(zB,{"data-play-field":`values.${n}`,className:`!h-11 text-[17px]`,value:i.values[n]??``,maxLength:200,spellCheck:!1,"aria-invalid":t(`values.${n}`)!==void 0,onChange:e=>a({...i,values:{...i.values,[n]:e.target.value}})})},n))})}function ive({topics:e,keywordNames:t,origins:n,problem:r,adding:i,onAdding:a,open:o,onOpen:s}){let c=XN(),{document:l}=c,{form:u}=l,[d,f]=(0,m.useState)(``),p=(0,m.useId)(),g=(0,m.useRef)(null),_=c.review.starting||c.review.uncertain,v=l.variants,y=e=>{c.edit({...l,variants:e})},b=e[0],x=e=>b===void 0?e.title:e.values[b]||e.title,S=()=>{let e=d.trim();e===``||v.length>=49||(y([...v,{id:crypto.randomUUID(),title:b===void 0?e:u.title,values:b===void 0?{...u.values}:{...u.values,[b]:e}}]),f(``),g.current?.focus())},C=v.findIndex(e=>e.id===o),w=C===-1?void 0:v[C];return(0,h.jsxs)(`section`,{"aria-label":`More videos from the same setup`,className:`min-w-0`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:`More videos from the same setup`}),(0,h.jsx)(U,{id:`play.more-videos`,className:`-my-1`})]}),(0,h.jsxs)(Iy,{className:`flex-wrap`,children:[v.map((e,n)=>{let i=x(e)||`Video ${String(n+2)}`,a=[`items.${String(n+1)}.title`,...t.map(e=>`items.${String(n+1)}.values.${e}`)].some(e=>r(e)!==void 0);return(0,h.jsx)(AS,{...a?{className:`border-danger`}:{},..._?{}:{onRemove:()=>y(v.filter(t=>t.id!==e.id)),removeLabel:`Remove ${i}`},children:(0,h.jsxs)(B,{variant:`quiet`,size:`small`,"data-play-field":`items.${e.id}`,className:`-my-1 -ml-1.5 h-6 px-1.5 text-ink`,"aria-label":`Change the keywords of ${i}`,onClick:()=>s(e.id),children:[i,(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75})]})},e.id)}),i?(0,h.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,h.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:b===void 0?`Title of another video`:`${b} of another video`}),(0,h.jsx)(zB,{ref:g,id:p,autoFocus:!0,className:`!h-8 w-48`,value:d,maxLength:200,placeholder:b===void 0?`Another title`:`Another ${b}`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(!1)}}),(0,h.jsx)(B,{type:`submit`,size:`small`,disabled:d.trim()===``,children:`Add`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>a(!1),children:`Done`})]}):(0,h.jsxs)(B,{variant:`quiet`,size:`small`,disabled:_||v.length>=49,disabledReason:_?`Wait for the start to finish`:`One Start queues at most 50 videos`,onClick:()=>a(!0),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add topic`]})]}),(0,h.jsx)(HP,{open:w!==void 0,title:w?`Video ${String(C+2)}: ${x(w)||`untitled`}`:``,width:`narrow`,onClose:()=>s(null),footer:(0,h.jsx)(B,{variant:`secondary`,onClick:()=>s(null),children:`Done`}),children:w?(0,h.jsxs)(`fieldset`,{disabled:_,className:`flex min-w-0 flex-col gap-5 border-0 p-0`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Everything else comes from the setup of the first video.`}),(0,h.jsx)(LB,{label:`Title`,tip:`play.title`,error:r(`items.${String(C+1)}.title`),children:(0,h.jsx)(zB,{"data-play-field":`items.${w.id}.title`,value:w.title,maxLength:200,onChange:e=>y(v.map(t=>t.id===w.id?{...t,title:e.target.value}:t))})}),(0,h.jsx)(V1,{fieldPrefix:`items.${w.id}.values`,keywords:t.map(t=>({name:t,value:w.values[t]??``,feeds:n.get(t)??[],topic:e.includes(t)})),problem:e=>r(e.replace(`items.${w.id}.`,`items.${String(C+1)}.`)),onChange:(e,t)=>y(v.map(n=>n.id===w.id?{...n,values:{...n.values,[e]:t}}:n))})]}):null})]})}function ave(){let e=Ji();return(0,h.jsx)(ove,{onCreated:t=>{e({to:`/projects/$projectId`,params:{projectId:t}})}})}function ove({onCreated:e}){let{api:t}=V(),n=$F(),r=I(db(t)),i=I(pb(t)),a=I(mb(t)),o=I(fb(t)),s=I(_b(t)),c=I(cx(t)),l=I(lq(t)),u=I({queryKey:eN,queryFn:()=>tN(t),staleTime:6e4}),[d,f]=tP(),p=R3(),g=XN(),{document:_}=g,v=tve(_.librarySnapshot,i.data?.prompts??[],a.data?.entries??[]),y=_.variants.map(({id:e,...t})=>({...t,key:e})),b=g.fontUploading||_.fontUpload!==null,x=g.review.fields,[S,C]=(0,m.useState)(new Set),[w,T]=(0,m.useState)(new Set),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(!1),[M,ee]=(0,m.useState)(null),N=(0,m.useRef)(null),P=(0,m.useRef)(null),F=(0,m.useRef)(null),te=Ji(),ne=(0,m.useRef)(g.activeId);(0,m.useLayoutEffect)(()=>{ne.current!==g.activeId&&(ne.current=g.activeId,C(new Set),k(null))},[g.activeId]);let re=e=>{f(t=>{let n={...t,...e};return{...n,subtitles:xN(n.subtitles,n.sources)}}),g.invalidateReview(!0)},ie=s.data?.silenceGapSeconds??3,ae=_.form.silenceGapSeconds?.trim()??``,oe={form:d,prompts:v.prompts,entries:v.entries,silenceGapSeconds:ae===``?ie:Number(ae)},{fields:se,result:ce,blocker:le}=kfe(oe),ue=F1(oe),de=F3(d.title).filter(e=>se.some(t=>t.name===e)),fe=b?{field:`subtitles.fontUpload`,hint:`Wait for the subtitle font upload to finish to play`}:le;(0,m.useEffect)(()=>{if(!g.review.created)return;let t=g.takeCreated()?.projectIds[0];t&&(n({type:`project-created`,id:t}),e(t))},[g.review.created,g.takeCreated,n,e]);let pe=ce.ok?x:[...ce.fields,...x],me=(...e)=>!pe.some(t=>e.some(e=>t.field===e||t.field.startsWith(`${e}.`))),he=(e,t)=>v.prompts.some(n=>n.kind===e&&n.name===t),ge=e=>e?.file!==void 0&&e.error===void 0;QF({playArticleReady:me(`sources.article`,`articlePrompt`,`provided.article`)&&(d.sources.article===`provide`||he(`article`,d.articlePrompt)),playAudioReady:d.sources.audio===`off`||me(`sources.audio`,`audio`,`provided.audio`)&&(d.sources.audio!==`provide`||ge(d.provided.audio)),playImagesReady:d.sources.images===`off`||me(`sources.images`,`images`,`imagePrompts`,`provided.images`)&&(d.sources.images===`provide`?d.provided.images.every(ge):d.imagePrompts.every(e=>he(`image`,e.name))),playVideoReady:me(`sources.video`),playSubtitlesReady:me(`subtitles`)&&!b,playOptionsReady:me(`title`,`format`,`llm`,`intro`,`outro`),playHasKeywords:se.length>0,playKeywordsReady:me(`values`),playReady:fe===void 0&&!g.review.starting});let _e=kN(d,v.entries)[0]?.section??`article`,ve=e=>vge(e,d)??m_e(e,d,y,v.entries),ye=e=>{let t=ve(e).field;return pe.find(n=>ve(n.field).field===t&&(x.includes(n)||S.has(e)||S.has(t)))?.message},be=e=>{let t=ve(e);C(n=>new Set([...n,e,t.field])),g.navigate(t.field.startsWith(`items.`)?`content`:t.section,t.field)},xe=[r,i,a,o,s].every(e=>e.isSuccess||e.isError),Se=(0,m.useRef)(null),Ce=g.generation();(0,m.useEffect)(()=>{if(!xe)return;let e=Se.current;Se.current={generation:Ce,id:g.activeId},(e===null||e.generation!==Ce||e.id!==g.activeId&&e.id!==null)&&T(new Set(K6.map(e=>e.id).filter(e=>e!==`reviews`&&Y6(e,pe,de,_e)!==void 0)))},[xe,g.activeId,Ce]);let we=(0,m.useRef)(null);(0,m.useLayoutEffect)(()=>{let e=g.reveal;if(e||(we.current=null),!e||e.sequence===we.current||!N.current)return;let t=e.field,n=t?/^items\.([^.]+)(\.|$)/.exec(t)?.[1]:void 0;if(e.section===`review`){if(we.current=e.sequence,t&&I6(N.current,t))return;F.current?.focus();return}if(n!==void 0&&_.variants.some(e=>e.id===n)){if(O!==n){k(n);return}}else if(!(t&&de.some(e=>t===`values.${e}`))){let n=t?J6(t,_e):void 0,r=(n===void 0?Z_e(e.section):[n]).filter(e=>!w.has(e));if((t!==`title`||de.length!==0)&&r.length>0){T(e=>new Set([...e,...r]));return}}we.current=e.sequence,!(t&&I6(N.current,t))&&P.current?.focus()},[g.reveal,w,O]);let Te=async e=>{await g.flush()&&(e===`/prompts`?await te({to:`/prompts/new`,search:{kind:`article`}}):await te({to:e}))},Ee=()=>{g.navigate(`review`)},De=(e,t)=>{g.invalidateReview(!0),g.attach(e,t)},Oe=(e,t)=>{f(n=>({...n,provided:e===`images`?{...n.provided,images:n.provided.images.filter(e=>e.key!==t)}:{...n.provided,[e]:void 0}}))},ke=[r,i,a,o,s].find(e=>e.error!==null)?.error?.message,Ae=g.error?`Your draft wasn't saved. ${g.error}`:ke,je={form:d,providers:r.data?.providers??[],prompts:v.prompts,voices:o.data?.voices??[],silenceGapSeconds:s.data?.silenceGapSeconds??3,problem:ye,update:re,onPickFiles:De,onRemoveFile:Oe,onReattachFile:(e,t,n)=>{g.attach(e,[n],t)}},Me=l.data?.find(e=>e.id===_.templateSource?.id),Ne=_.channelId??(Me===void 0?`00000000-0000-4000-8000-000000000001`:E1(Me)),Pe=Object.values(_.form.reviews?.stages??{}).filter(e=>e.mode!==`off`).length,Fe={providers:r.data?.providers??[],voices:o.data?.voices??[],keywords:se.length,topics:de,channel:c.data?.find(e=>e.id===Ne)?.name,brandKit:_.form.useBrandKit!==!1,look:H6(_.form),fontName:u.data?.fonts.find(e=>e.id===d.subtitles.fontId)?.name,checkpoints:d.checkpoints?.length??0,reviews:Pe},Ie={title:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[de.length?(0,h.jsx)(LB,{label:`Title pattern`,tip:`play.title-pattern`,error:ye(`title`),children:(0,h.jsx)(zB,{"data-play-field":`title`,value:d.title,maxLength:200,"aria-invalid":ye(`title`)!==void 0,onChange:e=>re({title:e.target.value})})}):null,(0,h.jsx)(h_e,{fields:se,origins:ue,topics:de,hide:de,values:d.values,problem:ye,onChange:(e,t)=>re({values:{...d.values,[e]:t}})}),se.length===de.length?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:se.length===0?`No keywords. A prompt or the title that names {{a keyword}} adds one here.`:`The only keywords are the topic, typed at the top.`}):null]}),article:(0,h.jsx)(f_e,{...je,entries:v.entries,onLibrary:e=>{Te(e)}}),narration:(0,h.jsx)(D_e,{...je,entries:v.entries,onKeyword:be,onSettings:()=>{Te(`/settings`)}}),images:(0,h.jsx)(O_e,{...je}),video:(0,h.jsx)(k_e,{...je,problemOf:ye}),outputs:(0,h.jsx)(A_e,{...je,entries:v.entries,onSettings:()=>{Te(`/settings`)}}),reviews:void 0,channel:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(gge,{}),(0,h.jsx)(_ge,{})]})},Le=K6.filter(e=>e.id!==`narration`||d.sources.article!==`off`),Re=Le.map(e=>({id:e.id,label:e.label,summary:Q_e(e.id,d,Fe),problem:Y6(e.id,pe,de,_e)?.message,editor:Ie[e.id]})),ze=(e,t)=>{if(e===`reviews`){Ee();return}T(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},Be=e=>{ze(e,!0),requestAnimationFrame(()=>{N.current?.querySelector(`[data-setup-row="${e}"]`)?.scrollIntoView({block:`start`,behavior:`smooth`})})},Ve=_.variants.length+1,He=HN(_,g.view),Ue=!g.review.starting&&(g.review.uncertain||g.review.valid&&!g.review.pending&&pe.length===0&&!He);jx({id:`play.start`,title:BN(g.review,_),group:`Play`,context:d.title||`New project`,keywords:[`start`,`queue`,`run`,`play`,`go`],run:()=>{Ue?g.startRun():fe?be(fe.field):pe[0]&&be(pe[0].field)}}),jx({id:`play.add-topic`,title:`Add a topic for another video`,group:`Play`,context:`${String(Ve)} video${Ve===1?``:`s`}`,keywords:[`more videos`,`variation`,`batch`,`queue`],run:()=>D(!0)}),jx({id:`play.save-template`,title:`Save as template`,group:`Play`,keywords:[`template`,`setup`,`reuse`],run:()=>j(!0)}),jx({id:`play.review`,title:`Review the whole setup`,group:`Play`,keywords:[`summary`,`checkpoints`,`prompt`],shortcut:nP.reviewSetup,run:Ee}),jx({id:`play.template`,title:`Pick a template`,group:`Play`,keywords:[`template`,`setup`],run:()=>{N.current&&I6(N.current,`template`)}});let We=d.sources.video===`generate`&&d.sources.images!==`off`,Ge=N_e(d,p),Ke=We?(0,h.jsx)(w6,{drawnOn:Ge?.drawnOn,settings:{format:d.format,subtitles:{mode:d.sources.audio===`off`?`off`:d.subtitles.mode,fontId:d.subtitles.fontId,fontSize:Number(_.form.subtitles.fontSize)||d.subtitles.fontSize,position:d.subtitles.position},videoEdit:d.videoEdit,previewText:_.previewText,image:Ge?.image}}):null;return(0,h.jsxs)(`div`,{ref:N,onBlurCapture:e=>{let t=e.target.dataset.playField;t&&C(e=>new Set([...e,t]))},"data-play-grid":`true`,className:`min-w-0 max-[767px]:[&_button]:min-h-11 max-[767px]:[&_input:not([type=checkbox])]:min-h-11 max-[767px]:[&_select]:min-h-11 max-[767px]:[&_summary]:min-h-11`,children:[(0,h.jsx)(XK,{crumb:`New project`,title:(0,h.jsx)(`span`,{ref:P,tabIndex:-1,children:`What's the video about?`}),meta:d.title.trim()===``?`Untitled draft`:d.title,actions:(0,h.jsx)(p_e,{})}),(0,h.jsx)(I3,{onDefaults:g.adoptDefaults}),(0,h.jsxs)(ZK,{className:`sl-workspace--play`,aside:(0,h.jsx)(eve,{errors:pe,blocker:fe,saveProblem:Ae,onReveal:be,onWholeSetup:Ee,onSaveTemplate:()=>j(!0),preview:Ke}),asideLabel:`Review and start`,children:[(0,h.jsxs)(`div`,{"data-tour":`play-options`,className:`grid min-w-0 grid-cols-1 items-start gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(nve,{topics:de,onError:ee}),(0,h.jsx)(rve,{topics:de,problem:ye})]}),(0,h.jsx)(J_e,{topics:de}),M?(0,h.jsx)(aI,{tone:`danger`,title:M}):null,(0,h.jsx)(ive,{topics:de,keywordNames:se.map(e=>e.name),origins:ue,problem:ye,adding:E,onAdding:D,open:O,onOpen:k}),(0,h.jsx)(Y_e,{rows:Re,open:w,onChange:ze})]}),(0,h.jsx)(HP,{open:g.section===`review`,title:`Review`,headingRef:F,onClose:()=>{g.navigate(`content`)},children:(0,h.jsx)(V_e,{fields:se,errors:pe,problem:ye,onReveal:be})}),(0,h.jsx)(U_e,{open:A,onClose:()=>j(!1)}),Le.map(e=>(0,h.jsx)(sve,{id:e.id,label:e.label,onOpen:Be},e.id))]})}function sve({id:e,label:t,onOpen:n}){return jx({id:`play.row.${e}`,title:`Change ${t.toLowerCase()}`,group:`Play`,keywords:[`open`,`edit`,`section`,t],run:()=>n(e)}),null}function cve(){let{api:e}=V(),t=I({queryKey:[`batch-queue`],queryFn:async()=>R(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=I(ob(e)),r=t.data?.queue.length??0;return(0,h.jsxs)(Nb,{children:[(0,h.jsx)(Pb,{asChild:!0,children:(0,h.jsxs)(B,{variant:`quiet`,disabled:r===0,"aria-label":`Video queue: ${r} remaining`,children:[(0,h.jsx)(zc,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,r]})]})}),(0,h.jsxs)(Lb,{align:`end`,className:`p-0`,children:[(0,h.jsx)(`p`,{className:`border-b border-line px-3 py-2 text-small text-ink-2`,children:wb(`play.queue`).body}),(0,h.jsx)(lve,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function lve({queue:e,projects:t}){return(0,h.jsx)(`ol`,{className:`max-h-40 overflow-y-auto px-4 py-2`,children:e.map((e,n)=>{let r=t?.find(t=>t.id===e.projectId);return(0,h.jsxs)(`li`,{className:`flex justify-between gap-3 py-1 text-small`,children:[(0,h.jsxs)(fa,{className:`truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[n+1,`. `,r?.title??`Video`]}),(0,h.jsx)(`span`,{className:`shrink-0 text-ink-2`,children:r?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`})]},e.projectId)})})}function X6({label:e,className:t,children:n}){return(0,h.jsx)(`nav`,{"aria-label":e,className:z(`sl-rail`,t),children:n})}function uve({icon:e,meta:t,children:n}){return(0,h.jsxs)(h.Fragment,{children:[e,(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:n}),t===void 0?null:(0,h.jsx)(`span`,{className:`sl-rail__meta`,children:t})]})}function Z6({icon:e,meta:t,current:n=!1,onClick:r,className:i,children:a,"data-tour":o}){return(0,h.jsx)(`button`,{type:`button`,"data-tour":o,"aria-current":n?`true`:void 0,onClick:r,className:z(`sl-rail__item w-full border-0 bg-transparent text-left font-[inherit]`,n&&`bg-accent-tint font-semibold text-ink`,i),children:(0,h.jsx)(uve,{icon:e,meta:t,children:a})})}var Q6=/^(?:[-*+]|\d+[.)])\s+/u;function dve(e){let t=e.split(/\r?\n/u).filter(e=>e.trim()!==``),n=[];for(let e of t.slice(1)){let t=e.trim().replace(Q6,``).trim(),r=n.length-1;/^\s/u.test(e)&&!Q6.test(e.trim())&&r>=0?n[r]=`${n[r]??``} ${t}`:t!==``&&n.push(t)}return n}var fve={blockquote:n8,break:_ve,code:r8,definition:r8,delete:n8,emphasis:n8,footnoteReference:r8,footnoteDefinition:r8,heading:gve,html:r8,image:e8,imageReference:e8,inlineCode:t8,list:n8,listItem:n8,link:n8,linkReference:n8,strong:n8,table:r8,tableCell:r8,text:t8,thematicBreak:r8,toml:r8,yaml:r8},pve={},$6=[];function mve(e){let t={...fve},n=e||pve,r=n.keep||$6,i=n.remove||$6,a=-1;for(;++a<i.length;){let e=i[a];typeof e==`string`?t[e]=r8:t[e[0]]=e[1]}let o={};if(r.length===0)o=t;else{let e;for(e in t)r.includes(e)||(o[e]=t[e]);for(a=-1;++a<r.length;)if(e=r[a],!Object.hasOwn(t,e))throw Error("Unknown node type `"+e+"` in `keep`, use a replace tuple with a handle instead: `remove: [['"+e+"', handle]]`")}return function(e){return s(e)};function s(e){let t=e.type,n=e;if(Object.hasOwn(o,t)){let e=o[t];e&&(n=e(n)||void 0)}return n=Array.isArray(n)?c(n):n,n&&`children`in n&&(n.children=c(n.children)),n}function c(e){let t=-1,n=[];for(;++t<e.length;){let r=s(e[t]);Array.isArray(r)?n.push(...c(r)):r&&n.push(r)}return hve(n)}}function hve(e){let t=-1,n=[],r;for(;++t<e.length;){let i=e[t];r&&i.type===r.type&&`value`in i&&`value`in r?r.value+=i.value:(n.push(i),r=i)}return n}function e8(e){let t=`title`in e?e.title:``,n=e.alt||t||``;return n?{type:`text`,value:n}:void 0}function t8(e){return{type:`text`,value:e.value}}function gve(e){return{type:`paragraph`,children:e.children}}function n8(e){return e.children}function _ve(){return{type:`text`,value:`
284
+ `}}function r8(){}var vve=64,i8=new Map;function yve(e){let t=i8.get(e);if(t!==void 0)return t;let n=bve(e);for(i8.set(e,n);i8.size>vve;){let e=i8.keys().next().value;if(e===void 0)break;i8.delete(e)}return n}function bve(e){let t=$3().use(Bz).use(mve),n=t.runSync(t.parse(e)).children.map(e=>{if(e.type!==`paragraph`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.children.map(e=>{if(e.type!==`text`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.value}).join(``)}).filter(e=>e.trim()!==``);return n.length===0?``:n.join(`
285
285
 
286
286
  `)+`
287
- `}var a8={"sources consulted":`sources`,"pronunciation glossary":`glossary`},yve=16,o8=new Map;function s8(e){let t=o8.get(e);if(t!==void 0)return t;let n=bve(e);for(o8.set(e,n);o8.size>yve;){let e=o8.keys().next().value;if(e===void 0)break;o8.delete(e)}return n}function bve(e){let t=xve(e),n=t[0];if(n===void 0)return{body:e,sources:``,glossary:``};let r={sources:``,glossary:``};for(let[n,i]of t.entries())r[i.part]+=e.slice(i.at,t[n+1]?.at??e.length);return{body:e.slice(0,n.at),sources:r.sources,glossary:r.glossary}}function xve(e){let t=$3().use(Bz).parse(e),n=[];for(let r of t.children){if(r.type!==`heading`&&r.type!==`paragraph`)continue;let t=r.position?.start.offset,i=r.position?.end.offset;if(t===void 0||i===void 0)continue;let a=wve(e.slice(t,i));a!==void 0&&n.push({part:a,at:t})}return n}var Sve=Object.keys(a8).map(e=>e.replace(/[^a-z]/g,``));function Cve(e){let t=e.toLowerCase().replace(/[^a-z]/g,``);return Sve.some(e=>{let n=0;for(let r of t)r===e[n]&&(n+=1);return n>=e.length})}function wve(e){return Cve(e)?a8[_ve(e).trim().toLowerCase().replace(/:$/,``)]:void 0}function Tve({script:e,voices:t}){let n=(0,m.useMemo)(()=>o6(e,t.speakers),[e,t.speakers]);if(!n.ok)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`This script can't be narrated yet: `,n.reason,` Fix it in Edit project → Article.`]});let r=new Map(t.speakers.map((e,t)=>[e.id,t])),i=new Map(t.speakers.map(e=>[e.id,e.name.trim()]));return(0,h.jsx)(`ol`,{"aria-label":`Script`,className:`space-y-3`,children:n.script.turns.map(e=>{let t=n.script.sections.find(t=>t.firstTurn===e.index),a=`var(--color-speaker-${String((r.get(e.speaker)??0)%6+1)})`;return(0,h.jsxs)(`li`,{className:`space-y-2`,children:[t===void 0?null:(0,h.jsx)(`h3`,{className:`pt-2 text-title-3 font-semibold text-ink`,children:t.title}),(0,h.jsxs)(`div`,{className:`border-l-4 pl-3`,style:{borderColor:a},children:[(0,h.jsx)(`p`,{className:`text-label font-semibold text-ink-2`,children:i.get(e.speaker)??e.speaker}),(0,h.jsx)(`p`,{className:`text-body text-ink`,children:e.text})]})]},e.index)})})}function c8(e,t){return e.filter(e=>e.stageKind===t.kind)}function l8(e,t){return e.find(e=>e.role===t)}var u8=ry,d8=iy;function f8({className:e,sideOffset:t=4,align:n=`end`,...r}){return(0,h.jsx)(ay,{children:(0,h.jsx)(oy,{"data-slot":`menu-content`,sideOffset:t,align:n,className:z(`z-50 min-w-[180px] overflow-hidden rounded-control border border-line bg-raised p-1`,`shadow-[var(--shadow-pop)]`,e),...r})})}function p8({className:e,...t}){return(0,h.jsx)(sy,{"data-slot":`menu-item`,className:z(`flex cursor-default items-center gap-2 rounded-control px-[10px] py-[6px] text-small text-ink`,`outline-hidden select-none focus:bg-sunken data-highlighted:bg-sunken`,`data-disabled:text-ink-3`,e),...t})}function Eve({className:e}){return(0,h.jsx)(cy,{className:z(`my-1 h-px bg-line`,e)})}var m8=(0,m.createContext)(null);function Dve({projectId:e,revisionId:t,children:n}){let{api:r}=V(),i=I({queryKey:H.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved version yet. Reload the page and try again.`);let n=await k0(r,e,t);if(!n.ok)throw Error(n.message);let i=n.value.view;if(i.revision.id!==t||i.revision.projectId!==e)throw Error(`The project changed while its files were loading. Reload the page.`);return i}});return(0,h.jsxs)(m8,{value:{projectId:e,revisionId:t,view:i.data},children:[i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:i.error.message}),n]})}function h8(){return(0,m.useContext)(m8)?.view}function g8(e){let t=(0,m.useContext)(m8),{api:n}=V();return v8(n,t,e)}function _8(e){let t=(0,m.useContext)(m8),{api:n}=V(),r=new Map;for(let i of e){let e=v8(n,t,i);e!==void 0&&r.set(i.id,e)}return r}function v8(e,t,n){if(n===void 0||t!==null&&t.projectId!==n.projectId)return;if(t===null||t.revisionId===null)return{url:Wo(e,n.projectId,C3(n)),cacheKey:H.file(n.projectId,n.id),folder:null};let r=t.view?.outputs.find(e=>e.selected&&e.available&&e.output.id===n.id);return r===void 0?void 0:y8(e,t.projectId,t.revisionId,r)}function Ove(e,t){let n=(0,m.useContext)(m8),{api:r}=V();if(n!==null&&n.projectId!==e)return;if(n===null||n.revisionId===null)return{url:Wo(r,e,t),cacheKey:H.file(e,t),folder:null};let i=n.view?.outputs.find(e=>e.selected&&e.available&&(t===`images.zip`?e.output.role===`image`||e.output.role===`thumbnail`:C3(e.output)===t));if(i===void 0)return;let a=y8(r,e,n.revisionId,i);return t===`images.zip`?{...a,url:j0(r,e,n.revisionId,`images.zip`),cacheKey:H.revisionFile(e,n.revisionId,`images.zip`)}:a}function y8(e,t,n,r){return{url:j0(e,t,n,r.recordId),cacheKey:H.revisionFile(t,n,r.recordId),folder:{revisionId:n,recordId:r.recordId}}}function b8({children:e,className:t}){return(0,h.jsx)(`div`,{className:z(`flex min-w-0 flex-col gap-5`,t),children:e})}function x8({children:e}){return(0,h.jsx)(`span`,{className:`sl-kicker`,children:e})}var kve={h1:({children:e})=>(0,h.jsx)(S8,{size:`text-title-2`,children:e}),h2:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h3:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h4:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h5:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h6:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),p:({children:e})=>(0,h.jsx)(`p`,{className:`m-0`,children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),ul:({children:e})=>(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5`,children:e}),ol:({children:e})=>(0,h.jsx)(`ol`,{className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:e}),li:({children:e})=>(0,h.jsx)(`li`,{className:`m-0`,children:e}),a:({children:e,href:t})=>(0,h.jsx)(`a`,{href:t,className:`rounded-control text-accent-ink underline underline-offset-[3px]`,target:`_blank`,rel:`noreferrer`,children:e}),code:({children:e})=>(0,h.jsx)(`code`,{className:`rounded-control bg-sunken px-1 py-0.5 font-mono text-small`,children:e}),pre:({children:e})=>(0,h.jsx)(`pre`,{className:`m-0 overflow-x-auto rounded-control bg-sunken p-3 font-mono text-small`,children:e}),blockquote:({children:e})=>(0,h.jsx)(`blockquote`,{className:`m-0 flex flex-col gap-2 border-l-2 border-line-strong pl-3 text-ink-2`,children:e}),hr:()=>(0,h.jsx)(`hr`,{className:`my-2 border-line`}),table:({children:e})=>(0,h.jsx)(`table`,{className:`w-full border-collapse text-left text-small`,children:e}),th:({children:e})=>(0,h.jsx)(`th`,{className:`sl-kicker border-b border-line py-2 pr-4 text-left`,children:e}),td:({children:e})=>(0,h.jsx)(`td`,{className:`border-b border-line py-2 pr-4 align-top`,children:e})},Ave={p:({children:e})=>(0,h.jsx)(h.Fragment,{children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),a:({children:e})=>(0,h.jsx)(h.Fragment,{children:e})};function S8({size:e,children:t}){return(0,h.jsx)(`h3`,{className:z(`mt-2 font-bold tracking-[-0.01em]`,e),children:t})}function C8({markdown:e}){return(0,h.jsx)(`div`,{className:`flex max-w-[68ch] flex-col gap-2 text-pretty text-body text-ink`,children:(0,h.jsx)(BR,{remarkPlugins:[Bz],components:kve,children:e})})}function jve({markdown:e}){return(0,h.jsx)(BR,{remarkPlugins:[Bz],components:Ave,children:e})}var Mve=/^#{1,6}[ \t]+(.*?)[ \t]*#*[ \t]*(?:\r?\n|$)/;function Nve(e){let t=e.replace(/^[\s]*\n/,``),n=Mve.exec(t);return n===null?{title:void 0,body:e.trim()}:{title:n[1]??``,body:t.slice(n[0].length).trim()}}function Pve({projectId:e,asset:t,label:n=`Download`,variant:r=`primary`}){let i=Ove(e,t);return i===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(TS,{href:i.url,download:!0,variant:r,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),n]}),(0,h.jsx)(P0,{projectId:e,asset:t,folder:i.folder})]})}function Fve(e){return e.flatMap(e=>e.output===void 0?[]:[e.output])}function w8({files:e,label:t=`Download`,variant:n=`primary`}){let r=e.filter(e=>e.output!==void 0),[i]=r;return i===void 0?null:r.length===1?(0,h.jsx)(Ive,{output:i.output,label:t,file:i.label,variant:n}):(0,h.jsxs)(u8,{modal:!1,children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsxs)(B,{variant:n,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),t,(0,h.jsx)(Cc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(f8,{children:r.map(e=>(0,h.jsx)(Lve,{output:e.output,label:e.label},e.output.id))})]})}function Ive({output:e,label:t,file:n,variant:r}){let i=g8(e);return i===void 0?null:(0,h.jsxs)(TS,{href:i.url,download:!0,variant:r,title:n,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),t]})}function Lve({output:e,label:t}){let n=g8(e);return n===void 0?null:(0,h.jsx)(p8,{asChild:!0,children:(0,h.jsxs)(`a`,{href:n.url,download:!0,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),t]})})}function T8({output:e}){let t=g8(e);return e===void 0||t===void 0?null:(0,h.jsx)(P0,{projectId:e.projectId,asset:C3(e),folder:t.folder})}function E8({files:e,label:t=`Download`,variant:n=`primary`,children:r}){let i=Fve(e);return i.length===0&&r===void 0?null:(0,h.jsxs)(Iy,{children:[(0,h.jsx)(w8,{files:e,label:t,variant:n}),(0,h.jsx)(T8,{output:i[0]}),r]})}function D8({children:e}){return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:e})}function O8(e){let{api:t}=V(),n=g8(e);return I({queryKey:n?.cacheKey??H.revisionFile(``,``,`unavailable`),queryFn:async()=>n===void 0?``:oo(await t.fetch(n.url)),enabled:n!==void 0,staleTime:1/0})}function Rve({output:e,as:t=`prose`}){let n=O8(e);return n.error===null?n.data===void 0?(0,h.jsx)(`span`,{className:`h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):t===`prose`?(0,h.jsx)(C8,{markdown:n.data}):(0,h.jsx)(`pre`,{className:`m-0 max-w-[68ch] overflow-x-auto whitespace-pre-wrap font-sans text-small text-ink-2`,children:n.data}):(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:n.error.message})}function k8({output:e}){let[t,n]=(0,m.useState)(!1);return e===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-expanded":t,onClick:()=>{n(!t)},children:t?`Hide instructions`:`Show instructions`}),t?(0,h.jsx)(`div`,{className:`w-full basis-full`,children:(0,h.jsx)(Rve,{output:e,as:`plain`})}):null]})}function zve({projectId:e,stage:t,notes:n,onCopy:r}){let i=t.state===`running`,a=O8(n);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[i?(0,h.jsx)(D3,{projectId:e,stage:`research`,className:``}):null,i&&n===void 0?null:a.error===null?(0,h.jsx)(Wz,{markdown:a.data??``,label:`Research notes`,regionLabel:`Research notes`,anchorPrefix:`research-`,what:`research notes`,onCopy:r,copyAll:!1,children:n===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:Bve(t)}):(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}):(0,h.jsx)(`p`,{className:`text-body text-danger`,children:a.error.message})]})}function Bve(e){switch(e.state){case`failed`:case`canceled`:return`Research stopped before any notes were saved. Try the research again with the next action beside it.`;case`pending`:return`The research runs first; its notes appear here when it finishes.`;default:return`No notes were written.`}}var Vve=[{segment:`intro`,name:`Intro`},{segment:`body`,name:`Body`},{segment:`outro`,name:`Outro`}];function A8(e){let t=/\.([a-z0-9]+)$/i.exec(e.path);return t===null?``:` (.${(t[1]??``).toLowerCase()})`}function Hve(e,t=[],n){return[...Uve(e,t),...n===void 0?[]:[{output:n,label:`Script by speaker${A8(n)}`}]]}function Uve(e,t){return Vve.flatMap(({segment:n,name:r})=>{let i=t=>e.find(e=>e.role===t&&e.meta.segment===n),a=t.find(e=>e.segment===n)?.output,o=i(`narration_txt`),s=i(`tts_script`);return[...a===void 0?[]:[{output:a,label:`${r} narration${A8(a)}`}],...o===void 0?[]:[{output:o,label:`${r} clean narration${A8(o)}`}],...s===void 0?[]:[{output:s,label:`${r} TTS script${A8(s)}`}]]})}function Wve(e){return e.some(e=>e.role===`narration_txt`||e.role===`tts_script`)}function j8(e){let{api:t}=V();return(I({queryKey:O3(e),queryFn:()=>Xhe(t,e)}).data??[]).filter(e=>e.current)}function M8(e,t){return e.find(e=>t.itemKey===void 0?t.outputId!==void 0&&e.outputId===t.outputId:e.itemKey===t.itemKey)}function Gve(e){return e.passed?e.attempt>1?{label:`Redone after review`,tone:`info`}:{label:`Review passed`,tone:`neutral`}:e.action===`overruled`?{label:`Accepted by you`,tone:`neutral`}:e.action===`redone`?{label:`Being made again`,tone:`running`}:e.redoState===`pending`?{label:`Waiting to be made again`,tone:`running`}:e.redoState===`started`?{label:`Being made again`,tone:`running`}:{label:`Flagged by review`,tone:`info`}}function Kve({review:e}){let t=Gve(e);return(0,h.jsx)(kS,{tone:t.tone,children:t.label})}function N8({review:e}){return(0,h.jsx)(Kve,{review:e})}function P8({review:e}){return(0,h.jsxs)(h.Fragment,{children:[e.reasons.length===0?(0,h.jsx)(`p`,{className:`m-0`,children:`The reviewer found nothing to fix.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-4`,children:e.reasons.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:e.outcome===`flagged`&&!e.passed&&e.attempt>1?`Kept after ${String(e.attempt)} tries: the redo limit was reached.`:`Try ${String(e.attempt)}.`}),e.redoState===`failed`&&e.redoError?(0,h.jsx)(`p`,{className:`m-0 text-danger`,children:e.redoError}):null]})}function F8({review:e,projectId:t,busy:n}){let{api:r}=V(),i=_(),[a,o]=(0,m.useState)(null),s=L({mutationFn:async n=>{let a=i.getQueryData(H.project(t))?.revisionId;return Zhe(r,t,e.id,n,n===`redo`&&a?{baseRevisionId:a,idempotencyKey:crypto.randomUUID()}:void 0)},onSuccess:async e=>{o(e.ok?null:e.message),await i.invalidateQueries({queryKey:O3(t)}),await i.invalidateQueries({queryKey:H.project(t)})},onError:e=>o(e.message)});if(e.passed||e.action!==null)return null;let c=e.redoState===`pending`,l=c||e.redoState===`started`;return(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:n&&!c||e.redoState===`started`||s.isPending,disabledReason:e.redoState===`started`?`Slopify is already making this item again; wait for the new version`:`Wait until the work on this project is done`,onClick:()=>s.mutate(`overrule`),children:`Overrule`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:n||l||s.isPending,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.mutate(`redo`),children:`Redo`}),a?(0,h.jsx)(`span`,{role:`alert`,className:`basis-full text-small text-danger`,children:a}):null]})}function I8({review:e,projectId:t,busy:n}){return e===void 0?null:(0,h.jsxs)(`section`,{"aria-label":`${vk[e.stage]} review`,className:`flex min-w-0 flex-col gap-1 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(N8,{review:e}),(0,h.jsx)(F8,{review:e,projectId:t,busy:n})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-1 text-ink-2`,children:(0,h.jsx)(P8,{review:e})})]})}function L8({review:e}){return e===void 0||e.passed&&e.attempt<=1?null:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,h.jsx)(N8,{review:e}),(0,h.jsxs)(Nb,{children:[(0,h.jsx)(Pb,{type:`button`,"aria-label":`About this review`,className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Ic,{"aria-hidden":`true`,className:`size-[15px]`})}),(0,h.jsx)(Lb,{className:`space-y-2 leading-[1.45]`,children:(0,h.jsx)(P8,{review:e})})]})]})}function qve(e){let t=[e.stage,e.companion].filter(e=>e!==void 0);for(let e of[`failed`,`canceled`,`running`]){let n=t.find(t=>t.state===e);if(n!==void 0)return n}return e.stage.state===`skipped`&&e.companion!==void 0?e.companion:e.stage}var R8=e=>e.state!==`pending`&&e.state!==`skipped`;function Jve(e){return e.replace(/^\s*[^\n]*\n?/u,``).trim()}function Yve({stage:e,companion:t,project:n,outputs:r,busy:i}){let a=j8(n.id),o=T3(n.id),s=c8(r,e),c=t?.kind===`research`?t:void 0,l=c===void 0?[]:c8(r,c),u=l8(l,`notes`),d=O8(u),f=l8(s,`article_md`)??l8(s,`article_txt`),p=l8(s,`sources`),g=l8(s,`glossary`),_=FA(n.config)?n.config.voices:void 0,v=l8(s,`script_md`),y=O8(v),b=O8(f),x=I({queryKey:E3(n.id,o),queryFn:()=>[],enabled:!1}).data?.some(e=>e.stage===`article`)===!0,S=I({queryKey:H.article(n.id,o),queryFn:()=>``,enabled:!1}),C=b.data??``,w=e.state===`running`,T=Nve(w?S.data??``:C),E=T.title??n.title,D=(0,m.useMemo)(()=>w?{body:T.body,sources:``,glossary:``}:s8(T.body),[w,T.body]),O=(0,m.useMemo)(()=>lve(D.sources),[D.sources]),k=Jve(D.glossary),A=(0,m.useMemo)(()=>{if(D.glossary.trim()===``)return[];let e=i6(D.glossary);return e.ok?e.skipped??[]:[]},[D.glossary]),j=_===void 0||w?``:_.source===`script`?s8(C).body:y.data??``,M=[{id:`article`,label:_?.source===`script`?`Script text`:`Article`},...j.trim()===``?[]:[{id:`script`,label:`Speakers`}],...c===void 0?[]:[{id:`research`,label:`Research`}],...O.length>0?[{id:`sources`,label:`Sources`,badge:String(O.length)}]:[],...k===``?[]:[{id:`pronunciation`,label:`Pronunciation`}]],ee=c!==void 0&&qve({kind:`article`,stage:e,companion:c})===c,[N,P]=(0,m.useState)(),F=N??(ee?`research`:`article`),te=M.some(e=>e.id===F)?F:`article`,ne=(0,m.useId)().replace(/:/gu,``),[re,ie]=(0,m.useState)(),ae={article:`${T.title===void 0?``:`# ${T.title}\n\n`}${D.body.trim()}\n`,script:`${j.trim()}\n`,research:`${(d.data??``).trim()}\n`,sources:`${O.map(e=>`- ${e}`).join(`
288
- `)}\n`,pronunciation:`${k}\n`},oe={article:`article`,script:`script`,research:`research notes`,sources:`sources`,pronunciation:`pronunciation table`},se=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){ie({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>ie({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>ie({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),ce=e=>se(ae[e],oe[e]);return(0,h.jsxs)(b8,{children:[(0,h.jsx)(I8,{review:M8(a,{itemKey:`article:body`}),projectId:n.id,busy:i}),(0,h.jsxs)(E8,{files:[...f===void 0?[]:[{output:f,label:`Article${A8(f)}`}],...p===void 0?[]:[{output:p,label:`Sources${A8(p)}`}],...g===void 0?[]:[{output:g,label:`Pronunciation glossary${A8(g)}`}],...u===void 0?[]:[{output:u,label:`Research notes${A8(u)}`}],...v===void 0?[]:[{output:v,label:`Script by speaker${A8(v)}`}]],children:[(te===`research`?c?.state===`running`||d.data===void 0:w||C===``)?null:(0,h.jsxs)(B,{variant:`secondary`,onClick:()=>ce(te),children:[(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy `,oe[te]]}),te===`research`&&c!==void 0?(0,h.jsx)(k8,{output:l8(l,`instructions`)}):(0,h.jsx)(k8,{output:l8(s,`instructions`)}),(0,h.jsx)(v1,{tone:re?.tone??`info`,children:re?.text})]}),b.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:b.error.message}),M.length>1?(0,h.jsx)(C1,{items:M,value:te,onChange:e=>{P(e),ie(void 0)},label:`Article parts`,idPrefix:ne}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3 font-semibold text-ink`,children:(0,h.jsx)(jve,{markdown:E})}),D.body.trim()===``?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:Xve(D.body)})]}),(0,h.jsx)(w1,{idPrefix:ne,id:`article`,active:te===`article`,children:w?(0,h.jsx)(`section`,{"aria-label":`Article content`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:x?(0,h.jsx)(D3,{projectId:n.id,stage:`article`,className:``}):(0,h.jsx)(C8,{markdown:D.body})}):(0,h.jsx)(Wz,{markdown:D.body,label:`Article`,regionLabel:`Article content`,anchorPrefix:`article-`,what:`article`,onCopy:se,copyAll:!1,children:R8(e)&&f!==void 0&&b.data===void 0?(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:R8(e)?`No article was saved.`:c===void 0?`The article will be written when its inputs are ready.`:`The article is written once the research has finished.`})})}),_===void 0||j.trim()===``?null:(0,h.jsx)(w1,{idPrefix:ne,id:`script`,active:te===`script`,children:(0,h.jsx)(`section`,{"aria-label":`Script by speaker`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:(0,h.jsx)(Tve,{script:j,voices:_})})}),c===void 0?null:(0,h.jsx)(w1,{idPrefix:ne,id:`research`,active:te===`research`,children:(0,h.jsx)(zve,{projectId:n.id,stage:c,notes:u,onCopy:se})}),O.length===0?null:(0,h.jsx)(w1,{idPrefix:ne,id:`sources`,active:te===`sources`,children:(0,h.jsx)(Wz,{markdown:O.map((e,t)=>`${String(t+1)}. ${e}`).join(`
289
- `),label:`Sources`,regionLabel:`Sources`,anchorPrefix:`sources-`,what:`sources`,onCopy:se,copyAll:!1})}),k===``?null:(0,h.jsxs)(w1,{idPrefix:ne,id:`pronunciation`,active:te===`pronunciation`,children:[A.length===0?null:(0,h.jsxs)(aI,{className:`mb-3`,title:`${A.length===1?`1 entry is`:`${A.length} entries are`} skipped by the narration and read as ordinary text`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:A.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsx)(`p`,{className:`m-0 mt-1`,children:`The other entries are used. To fix these, edit the Pronunciation Glossary at the end of the article in Edit settings → Article.`})]}),(0,h.jsx)(`div`,{className:`sl-stage-scroll pr-3`,children:(0,h.jsx)(C8,{markdown:k})})]})]})}var z8=new Intl.NumberFormat(`en`);function Xve(e){let t=e.replace(/\]\([^)]*\)/g,`]`).replace(/[#*_>`[\]]/g,``).replace(/[ \t]+/g,` `).trim(),n=t.split(/\s+/).filter(e=>/[\p{L}\p{N}]/u.test(e)).length,r=t.replace(/\s*\n\s*/g,` `).length;return`${z8.format(n)} ${n===1?`word`:`words`} · ${z8.format(r)} characters`}function B8({className:e,label:t,children:n}){return(0,h.jsx)(`dl`,{"aria-label":t,className:z(`m-0 grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[max-content_minmax(0,1fr)] sm:gap-y-3`,e),children:n})}function V8({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2 max-sm:mt-2 max-sm:first:mt-0`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function H8({src:e,label:t,marks:n=[],waveform:r,compact:i=!1,preload:a=`metadata`,onError:o,ref:s,className:c}){let l=e0(),u=l.media;return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`${t} controls`,"data-slot":`audio-player`,"data-state":l.playing?`playing`:`paused`,className:z(`sl-audio`,i&&`sl-audio--compact`,r!==void 0&&r.length>0&&`sl-audio--wave`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.key===` `&&e.target.closest(`button`)!==null)return;let t=l.keyAction(e.key);t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||l.setMenu(!1)},children:[(0,h.jsx)(`audio`,{ref:Q1(u,s),src:e,preload:a,"aria-label":t,onError:o,...l.events}),(0,h.jsx)(r0,{controls:l,className:`sl-audio__key`}),(0,h.jsx)(i0,{controls:l}),(0,h.jsx)(a0,{controls:l,chapters:n,waveform:r}),(0,h.jsx)(o0,{controls:l}),(0,h.jsx)(s0,{controls:l})]})}function U8({projectId:e,revisionId:t}){let n=T3(e),r=t===void 0?n:t,{api:i}=V(),a=I({queryKey:H.audioPreview(e,r),queryFn:async()=>R(await i.client.projects[`:projectId`][`audio-preview`].$get({param:{projectId:e}})),refetchInterval:1e3,staleTime:0,gcTime:0,retry:!1}),o=(a.data?.revisionId??null)===r?a.data?.previews??[]:[];return(0,h.jsxs)(`section`,{"aria-label":`Live narration`,className:`grid gap-3 border-y border-line py-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-ink`,children:`Listen while it generates`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Play any part. Each preview starts from its beginning.`})]}),a.error===null?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Live preview is temporarily unavailable. Finished audio will still appear here.`}),o.length===0&&a.error===null?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Waiting for the first audio bytes…`}):null,(0,h.jsx)(`div`,{className:`grid max-h-[420px] gap-3 overflow-y-auto`,children:o.map(t=>(0,h.jsx)(Zve,{preview:t,url:`${i.origin}/api/projects/${encodeURIComponent(e)}/audio-preview/${t.id}`},t.id))})]})}function Zve({preview:e,url:t}){let[n,r]=(0,m.useState)(!1),i=(e.state===`streaming`||e.state===`ready`)&&e.bytes>0,a=e.state===`ready`?`Ready`:e.state===`streaming`?`Generating`:`Preview stopped`;return(0,h.jsxs)(`div`,{className:`grid gap-2 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:e.label}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:a})]}),i&&!n?(0,h.jsx)(Qve,{label:e.label,url:t,onError:()=>r(!0)}):(0,h.jsx)(`p`,{className:`text-ink-2`,children:e.state===`streaming`&&!n?`Waiting for audio…`:`This preview has stopped. The finished narration will be available when generation completes.`})]})}function Qve({label:e,url:t,onError:n}){let r=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=r.current;return()=>{e!==null&&(e.pause(),e.removeAttribute(`src`),e.load())}},[]),(0,h.jsx)(H8,{ref:r,compact:!0,preload:`none`,label:`Live ${e} narration`,src:t,onError:n,className:`max-w-[620px]`})}function $ve({outputs:e}){let t=(0,m.useId)(),n=t=>e.find(e=>e.role===`narration_txt`&&e.meta.segment===t),r=O8(n(`intro`)).data,i=O8(n(`body`)).data,a=O8(n(`outro`)).data,[o,s]=(0,m.useState)(),c=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>s({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),l=[[`Intro`,r],[`Body`,i],[`Outro`,a]].filter(([,e])=>e!==void 0&&e.trim()!==``);if(!e.some(e=>e.role===`narration_txt`))return null;let u=l.length===1?(l[0]?.[1]??``).trim():l.map(([e,t])=>`## ${e}\n\n${(t??``).trim()}`).join(`
287
+ `}var a8={"sources consulted":`sources`,"pronunciation glossary":`glossary`},xve=16,o8=new Map;function s8(e){let t=o8.get(e);if(t!==void 0)return t;let n=Sve(e);for(o8.set(e,n);o8.size>xve;){let e=o8.keys().next().value;if(e===void 0)break;o8.delete(e)}return n}function Sve(e){let t=Cve(e),n=t[0];if(n===void 0)return{body:e,sources:``,glossary:``};let r={sources:``,glossary:``};for(let[n,i]of t.entries())r[i.part]+=e.slice(i.at,t[n+1]?.at??e.length);return{body:e.slice(0,n.at),sources:r.sources,glossary:r.glossary}}function Cve(e){let t=$3().use(Bz).parse(e),n=[];for(let r of t.children){if(r.type!==`heading`&&r.type!==`paragraph`)continue;let t=r.position?.start.offset,i=r.position?.end.offset;if(t===void 0||i===void 0)continue;let a=Eve(e.slice(t,i));a!==void 0&&n.push({part:a,at:t})}return n}var wve=Object.keys(a8).map(e=>e.replace(/[^a-z]/g,``));function Tve(e){let t=e.toLowerCase().replace(/[^a-z]/g,``);return wve.some(e=>{let n=0;for(let r of t)r===e[n]&&(n+=1);return n>=e.length})}function Eve(e){return Tve(e)?a8[yve(e).trim().toLowerCase().replace(/:$/,``)]:void 0}function Dve({script:e,voices:t}){let n=(0,m.useMemo)(()=>o6(e,t.speakers),[e,t.speakers]);if(!n.ok)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`This script can't be narrated yet: `,n.reason,` Fix it in Edit project → Article.`]});let r=new Map(t.speakers.map((e,t)=>[e.id,t])),i=new Map(t.speakers.map(e=>[e.id,e.name.trim()]));return(0,h.jsx)(`ol`,{"aria-label":`Script`,className:`space-y-3`,children:n.script.turns.map(e=>{let t=n.script.sections.find(t=>t.firstTurn===e.index),a=`var(--color-speaker-${String((r.get(e.speaker)??0)%6+1)})`;return(0,h.jsxs)(`li`,{className:`space-y-2`,children:[t===void 0?null:(0,h.jsx)(`h3`,{className:`pt-2 text-title-3 font-semibold text-ink`,children:t.title}),(0,h.jsxs)(`div`,{className:`border-l-4 pl-3`,style:{borderColor:a},children:[(0,h.jsx)(`p`,{className:`text-label font-semibold text-ink-2`,children:i.get(e.speaker)??e.speaker}),(0,h.jsx)(`p`,{className:`text-body text-ink`,children:e.text})]})]},e.index)})})}function c8(e,t){return e.filter(e=>e.stageKind===t.kind)}function l8(e,t){return e.find(e=>e.role===t)}var u8=ry,d8=iy;function f8({className:e,sideOffset:t=4,align:n=`end`,...r}){return(0,h.jsx)(ay,{children:(0,h.jsx)(oy,{"data-slot":`menu-content`,sideOffset:t,align:n,className:z(`z-50 min-w-[180px] overflow-hidden rounded-control border border-line bg-raised p-1`,`shadow-[var(--shadow-pop)]`,e),...r})})}function p8({className:e,...t}){return(0,h.jsx)(sy,{"data-slot":`menu-item`,className:z(`flex cursor-default items-center gap-2 rounded-control px-[10px] py-[6px] text-small text-ink`,`outline-hidden select-none focus:bg-sunken data-highlighted:bg-sunken`,`data-disabled:text-ink-3`,e),...t})}function Ove({className:e}){return(0,h.jsx)(cy,{className:z(`my-1 h-px bg-line`,e)})}var m8=(0,m.createContext)(null);function kve({projectId:e,revisionId:t,children:n}){let{api:r}=V(),i=I({queryKey:H.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved version yet. Reload the page and try again.`);let n=await k0(r,e,t);if(!n.ok)throw Error(n.message);let i=n.value.view;if(i.revision.id!==t||i.revision.projectId!==e)throw Error(`The project changed while its files were loading. Reload the page.`);return i}});return(0,h.jsxs)(m8,{value:{projectId:e,revisionId:t,view:i.data},children:[i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:i.error.message}),n]})}function h8(){return(0,m.useContext)(m8)?.view}function g8(e){let t=(0,m.useContext)(m8),{api:n}=V();return v8(n,t,e)}function _8(e){let t=(0,m.useContext)(m8),{api:n}=V(),r=new Map;for(let i of e){let e=v8(n,t,i);e!==void 0&&r.set(i.id,e)}return r}function v8(e,t,n){if(n===void 0||t!==null&&t.projectId!==n.projectId)return;if(t===null||t.revisionId===null)return{url:Wo(e,n.projectId,C3(n)),cacheKey:H.file(n.projectId,n.id),folder:null};let r=t.view?.outputs.find(e=>e.selected&&e.available&&e.output.id===n.id);return r===void 0?void 0:y8(e,t.projectId,t.revisionId,r)}function Ave(e,t){let n=(0,m.useContext)(m8),{api:r}=V();if(n!==null&&n.projectId!==e)return;if(n===null||n.revisionId===null)return{url:Wo(r,e,t),cacheKey:H.file(e,t),folder:null};let i=n.view?.outputs.find(e=>e.selected&&e.available&&(t===`images.zip`?e.output.role===`image`||e.output.role===`thumbnail`:C3(e.output)===t));if(i===void 0)return;let a=y8(r,e,n.revisionId,i);return t===`images.zip`?{...a,url:j0(r,e,n.revisionId,`images.zip`),cacheKey:H.revisionFile(e,n.revisionId,`images.zip`)}:a}function y8(e,t,n,r){return{url:j0(e,t,n,r.recordId),cacheKey:H.revisionFile(t,n,r.recordId),folder:{revisionId:n,recordId:r.recordId}}}function b8({children:e,className:t}){return(0,h.jsx)(`div`,{className:z(`flex min-w-0 flex-col gap-5`,t),children:e})}function x8({children:e}){return(0,h.jsx)(`span`,{className:`sl-kicker`,children:e})}var jve={h1:({children:e})=>(0,h.jsx)(S8,{size:`text-title-2`,children:e}),h2:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h3:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h4:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h5:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),h6:({children:e})=>(0,h.jsx)(S8,{size:`text-title-3`,children:e}),p:({children:e})=>(0,h.jsx)(`p`,{className:`m-0`,children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),ul:({children:e})=>(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5`,children:e}),ol:({children:e})=>(0,h.jsx)(`ol`,{className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:e}),li:({children:e})=>(0,h.jsx)(`li`,{className:`m-0`,children:e}),a:({children:e,href:t})=>(0,h.jsx)(`a`,{href:t,className:`rounded-control text-accent-ink underline underline-offset-[3px]`,target:`_blank`,rel:`noreferrer`,children:e}),code:({children:e})=>(0,h.jsx)(`code`,{className:`rounded-control bg-sunken px-1 py-0.5 font-mono text-small`,children:e}),pre:({children:e})=>(0,h.jsx)(`pre`,{className:`m-0 overflow-x-auto rounded-control bg-sunken p-3 font-mono text-small`,children:e}),blockquote:({children:e})=>(0,h.jsx)(`blockquote`,{className:`m-0 flex flex-col gap-2 border-l-2 border-line-strong pl-3 text-ink-2`,children:e}),hr:()=>(0,h.jsx)(`hr`,{className:`my-2 border-line`}),table:({children:e})=>(0,h.jsx)(`table`,{className:`w-full border-collapse text-left text-small`,children:e}),th:({children:e})=>(0,h.jsx)(`th`,{className:`sl-kicker border-b border-line py-2 pr-4 text-left`,children:e}),td:({children:e})=>(0,h.jsx)(`td`,{className:`border-b border-line py-2 pr-4 align-top`,children:e})},Mve={p:({children:e})=>(0,h.jsx)(h.Fragment,{children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),a:({children:e})=>(0,h.jsx)(h.Fragment,{children:e})};function S8({size:e,children:t}){return(0,h.jsx)(`h3`,{className:z(`mt-2 font-bold tracking-[-0.01em]`,e),children:t})}function C8({markdown:e}){return(0,h.jsx)(`div`,{className:`flex max-w-[68ch] flex-col gap-2 text-pretty text-body text-ink`,children:(0,h.jsx)(BR,{remarkPlugins:[Bz],components:jve,children:e})})}function Nve({markdown:e}){return(0,h.jsx)(BR,{remarkPlugins:[Bz],components:Mve,children:e})}var Pve=/^#{1,6}[ \t]+(.*?)[ \t]*#*[ \t]*(?:\r?\n|$)/;function Fve(e){let t=e.replace(/^[\s]*\n/,``),n=Pve.exec(t);return n===null?{title:void 0,body:e.trim()}:{title:n[1]??``,body:t.slice(n[0].length).trim()}}function Ive({projectId:e,asset:t,label:n=`Download`,variant:r=`primary`}){let i=Ave(e,t);return i===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(TS,{href:i.url,download:!0,variant:r,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),n]}),(0,h.jsx)(P0,{projectId:e,asset:t,folder:i.folder})]})}function Lve(e){return e.flatMap(e=>e.output===void 0?[]:[e.output])}function w8({files:e,label:t=`Download`,variant:n=`primary`}){let r=e.filter(e=>e.output!==void 0),[i]=r;return i===void 0?null:r.length===1?(0,h.jsx)(Rve,{output:i.output,label:t,file:i.label,variant:n}):(0,h.jsxs)(u8,{modal:!1,children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsxs)(B,{variant:n,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),t,(0,h.jsx)(Cc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(f8,{children:r.map(e=>(0,h.jsx)(zve,{output:e.output,label:e.label},e.output.id))})]})}function Rve({output:e,label:t,file:n,variant:r}){let i=g8(e);return i===void 0?null:(0,h.jsxs)(TS,{href:i.url,download:!0,variant:r,title:n,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),t]})}function zve({output:e,label:t}){let n=g8(e);return n===void 0?null:(0,h.jsx)(p8,{asChild:!0,children:(0,h.jsxs)(`a`,{href:n.url,download:!0,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),t]})})}function T8({output:e}){let t=g8(e);return e===void 0||t===void 0?null:(0,h.jsx)(P0,{projectId:e.projectId,asset:C3(e),folder:t.folder})}function E8({files:e,label:t=`Download`,variant:n=`primary`,children:r}){let i=Lve(e);return i.length===0&&r===void 0?null:(0,h.jsxs)(Iy,{children:[(0,h.jsx)(w8,{files:e,label:t,variant:n}),(0,h.jsx)(T8,{output:i[0]}),r]})}function D8({children:e}){return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:e})}function O8(e){let{api:t}=V(),n=g8(e);return I({queryKey:n?.cacheKey??H.revisionFile(``,``,`unavailable`),queryFn:async()=>n===void 0?``:oo(await t.fetch(n.url)),enabled:n!==void 0,staleTime:1/0})}function Bve({output:e,as:t=`prose`}){let n=O8(e);return n.error===null?n.data===void 0?(0,h.jsx)(`span`,{className:`h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):t===`prose`?(0,h.jsx)(C8,{markdown:n.data}):(0,h.jsx)(`pre`,{className:`m-0 max-w-[68ch] overflow-x-auto whitespace-pre-wrap font-sans text-small text-ink-2`,children:n.data}):(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:n.error.message})}function k8({output:e}){let[t,n]=(0,m.useState)(!1);return e===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-expanded":t,onClick:()=>{n(!t)},children:t?`Hide instructions`:`Show instructions`}),t?(0,h.jsx)(`div`,{className:`w-full basis-full`,children:(0,h.jsx)(Bve,{output:e,as:`plain`})}):null]})}function Vve({projectId:e,stage:t,notes:n,onCopy:r}){let i=t.state===`running`,a=O8(n);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[i?(0,h.jsx)(D3,{projectId:e,stage:`research`,className:``}):null,i&&n===void 0?null:a.error===null?(0,h.jsx)(Wz,{markdown:a.data??``,label:`Research notes`,regionLabel:`Research notes`,anchorPrefix:`research-`,what:`research notes`,onCopy:r,copyAll:!1,children:n===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:Hve(t)}):(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}):(0,h.jsx)(`p`,{className:`text-body text-danger`,children:a.error.message})]})}function Hve(e){switch(e.state){case`failed`:case`canceled`:return`Research stopped before any notes were saved. Try the research again with the next action beside it.`;case`pending`:return`The research runs first; its notes appear here when it finishes.`;default:return`No notes were written.`}}var Uve=[{segment:`intro`,name:`Intro`},{segment:`body`,name:`Body`},{segment:`outro`,name:`Outro`}];function A8(e){let t=/\.([a-z0-9]+)$/i.exec(e.path);return t===null?``:` (.${(t[1]??``).toLowerCase()})`}function Wve(e,t=[],n){return[...Gve(e,t),...n===void 0?[]:[{output:n,label:`Script by speaker${A8(n)}`}]]}function Gve(e,t){return Uve.flatMap(({segment:n,name:r})=>{let i=t=>e.find(e=>e.role===t&&e.meta.segment===n),a=t.find(e=>e.segment===n)?.output,o=i(`narration_txt`),s=i(`tts_script`);return[...a===void 0?[]:[{output:a,label:`${r} narration${A8(a)}`}],...o===void 0?[]:[{output:o,label:`${r} clean narration${A8(o)}`}],...s===void 0?[]:[{output:s,label:`${r} TTS script${A8(s)}`}]]})}function Kve(e){return e.some(e=>e.role===`narration_txt`||e.role===`tts_script`)}function j8(e){let{api:t}=V();return(I({queryKey:O3(e),queryFn:()=>Qhe(t,e)}).data??[]).filter(e=>e.current)}function M8(e,t){return e.find(e=>t.itemKey===void 0?t.outputId!==void 0&&e.outputId===t.outputId:e.itemKey===t.itemKey)}function qve(e){return e.passed?e.attempt>1?{label:`Redone after review`,tone:`info`}:{label:`Review passed`,tone:`neutral`}:e.action===`overruled`?{label:`Accepted by you`,tone:`neutral`}:e.action===`redone`?{label:`Being made again`,tone:`running`}:e.redoState===`pending`?{label:`Waiting to be made again`,tone:`running`}:e.redoState===`started`?{label:`Being made again`,tone:`running`}:{label:`Flagged by review`,tone:`info`}}function Jve({review:e}){let t=qve(e);return(0,h.jsx)(kS,{tone:t.tone,children:t.label})}function N8({review:e}){return(0,h.jsx)(Jve,{review:e})}function P8({review:e}){return(0,h.jsxs)(h.Fragment,{children:[e.reasons.length===0?(0,h.jsx)(`p`,{className:`m-0`,children:`The reviewer found nothing to fix.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-4`,children:e.reasons.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:e.outcome===`flagged`&&!e.passed&&e.attempt>1?`Kept after ${String(e.attempt)} tries: the redo limit was reached.`:`Try ${String(e.attempt)}.`}),e.redoState===`failed`&&e.redoError?(0,h.jsx)(`p`,{className:`m-0 text-danger`,children:e.redoError}):null]})}function F8({review:e,projectId:t,busy:n}){let{api:r}=V(),i=_(),[a,o]=(0,m.useState)(null),s=L({mutationFn:async n=>{let a=i.getQueryData(H.project(t))?.revisionId;return $he(r,t,e.id,n,n===`redo`&&a?{baseRevisionId:a,idempotencyKey:crypto.randomUUID()}:void 0)},onSuccess:async e=>{o(e.ok?null:e.message),await i.invalidateQueries({queryKey:O3(t)}),await i.invalidateQueries({queryKey:H.project(t)})},onError:e=>o(e.message)});if(e.passed||e.action!==null)return null;let c=e.redoState===`pending`,l=c||e.redoState===`started`;return(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:n&&!c||e.redoState===`started`||s.isPending,disabledReason:e.redoState===`started`?`Slopify is already making this item again; wait for the new version`:`Wait until the work on this project is done`,onClick:()=>s.mutate(`overrule`),children:`Overrule`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:n||l||s.isPending,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.mutate(`redo`),children:`Redo`}),a?(0,h.jsx)(`span`,{role:`alert`,className:`basis-full text-small text-danger`,children:a}):null]})}function I8({review:e,projectId:t,busy:n}){return e===void 0?null:(0,h.jsxs)(`section`,{"aria-label":`${vk[e.stage]} review`,className:`flex min-w-0 flex-col gap-1 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(N8,{review:e}),(0,h.jsx)(F8,{review:e,projectId:t,busy:n})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-1 text-ink-2`,children:(0,h.jsx)(P8,{review:e})})]})}function L8({review:e}){return e===void 0||e.passed&&e.attempt<=1?null:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,h.jsx)(N8,{review:e}),(0,h.jsxs)(Nb,{children:[(0,h.jsx)(Pb,{type:`button`,"aria-label":`About this review`,className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Ic,{"aria-hidden":`true`,className:`size-[15px]`})}),(0,h.jsx)(Lb,{className:`space-y-2 leading-[1.45]`,children:(0,h.jsx)(P8,{review:e})})]})]})}function Yve(e){let t=[e.stage,e.companion].filter(e=>e!==void 0);for(let e of[`failed`,`canceled`,`running`]){let n=t.find(t=>t.state===e);if(n!==void 0)return n}return e.stage.state===`skipped`&&e.companion!==void 0?e.companion:e.stage}var R8=e=>e.state!==`pending`&&e.state!==`skipped`;function Xve(e){return e.replace(/^\s*[^\n]*\n?/u,``).trim()}function Zve({stage:e,companion:t,project:n,outputs:r,busy:i}){let a=j8(n.id),o=T3(n.id),s=c8(r,e),c=t?.kind===`research`?t:void 0,l=c===void 0?[]:c8(r,c),u=l8(l,`notes`),d=O8(u),f=l8(s,`article_md`)??l8(s,`article_txt`),p=l8(s,`sources`),g=l8(s,`glossary`),_=FA(n.config)?n.config.voices:void 0,v=l8(s,`script_md`),y=O8(v),b=O8(f),x=I({queryKey:E3(n.id,o),queryFn:()=>[],enabled:!1}).data?.some(e=>e.stage===`article`)===!0,S=I({queryKey:H.article(n.id,o),queryFn:()=>``,enabled:!1}),C=b.data??``,w=e.state===`running`,T=Fve(w?S.data??``:C),E=T.title??n.title,D=(0,m.useMemo)(()=>w?{body:T.body,sources:``,glossary:``}:s8(T.body),[w,T.body]),O=(0,m.useMemo)(()=>dve(D.sources),[D.sources]),k=Xve(D.glossary),A=(0,m.useMemo)(()=>{if(D.glossary.trim()===``)return[];let e=i6(D.glossary);return e.ok?e.skipped??[]:[]},[D.glossary]),j=_===void 0||w?``:_.source===`script`?s8(C).body:y.data??``,M=[{id:`article`,label:_?.source===`script`?`Script text`:`Article`},...j.trim()===``?[]:[{id:`script`,label:`Speakers`}],...c===void 0?[]:[{id:`research`,label:`Research`}],...O.length>0?[{id:`sources`,label:`Sources`,badge:String(O.length)}]:[],...k===``?[]:[{id:`pronunciation`,label:`Pronunciation`}]],ee=c!==void 0&&Yve({kind:`article`,stage:e,companion:c})===c,[N,P]=(0,m.useState)(),F=N??(ee?`research`:`article`),te=M.some(e=>e.id===F)?F:`article`,ne=(0,m.useId)().replace(/:/gu,``),[re,ie]=(0,m.useState)(),ae={article:`${T.title===void 0?``:`# ${T.title}\n\n`}${D.body.trim()}\n`,script:`${j.trim()}\n`,research:`${(d.data??``).trim()}\n`,sources:`${O.map(e=>`- ${e}`).join(`
288
+ `)}\n`,pronunciation:`${k}\n`},oe={article:`article`,script:`script`,research:`research notes`,sources:`sources`,pronunciation:`pronunciation table`},se=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){ie({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>ie({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>ie({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),ce=e=>se(ae[e],oe[e]);return(0,h.jsxs)(b8,{children:[(0,h.jsx)(I8,{review:M8(a,{itemKey:`article:body`}),projectId:n.id,busy:i}),(0,h.jsxs)(E8,{files:[...f===void 0?[]:[{output:f,label:`Article${A8(f)}`}],...p===void 0?[]:[{output:p,label:`Sources${A8(p)}`}],...g===void 0?[]:[{output:g,label:`Pronunciation glossary${A8(g)}`}],...u===void 0?[]:[{output:u,label:`Research notes${A8(u)}`}],...v===void 0?[]:[{output:v,label:`Script by speaker${A8(v)}`}]],children:[(te===`research`?c?.state===`running`||d.data===void 0:w||C===``)?null:(0,h.jsxs)(B,{variant:`secondary`,onClick:()=>ce(te),children:[(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy `,oe[te]]}),te===`research`&&c!==void 0?(0,h.jsx)(k8,{output:l8(l,`instructions`)}):(0,h.jsx)(k8,{output:l8(s,`instructions`)}),(0,h.jsx)(v1,{tone:re?.tone??`info`,children:re?.text})]}),b.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:b.error.message}),M.length>1?(0,h.jsx)(C1,{items:M,value:te,onChange:e=>{P(e),ie(void 0)},label:`Article parts`,idPrefix:ne}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3 font-semibold text-ink`,children:(0,h.jsx)(Nve,{markdown:E})}),D.body.trim()===``?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:Qve(D.body)})]}),(0,h.jsx)(w1,{idPrefix:ne,id:`article`,active:te===`article`,children:w?(0,h.jsx)(`section`,{"aria-label":`Article content`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:x?(0,h.jsx)(D3,{projectId:n.id,stage:`article`,className:``}):(0,h.jsx)(C8,{markdown:D.body})}):(0,h.jsx)(Wz,{markdown:D.body,label:`Article`,regionLabel:`Article content`,anchorPrefix:`article-`,what:`article`,onCopy:se,copyAll:!1,children:R8(e)&&f!==void 0&&b.data===void 0?(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:R8(e)?`No article was saved.`:c===void 0?`The article will be written when its inputs are ready.`:`The article is written once the research has finished.`})})}),_===void 0||j.trim()===``?null:(0,h.jsx)(w1,{idPrefix:ne,id:`script`,active:te===`script`,children:(0,h.jsx)(`section`,{"aria-label":`Script by speaker`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:(0,h.jsx)(Dve,{script:j,voices:_})})}),c===void 0?null:(0,h.jsx)(w1,{idPrefix:ne,id:`research`,active:te===`research`,children:(0,h.jsx)(Vve,{projectId:n.id,stage:c,notes:u,onCopy:se})}),O.length===0?null:(0,h.jsx)(w1,{idPrefix:ne,id:`sources`,active:te===`sources`,children:(0,h.jsx)(Wz,{markdown:O.map((e,t)=>`${String(t+1)}. ${e}`).join(`
289
+ `),label:`Sources`,regionLabel:`Sources`,anchorPrefix:`sources-`,what:`sources`,onCopy:se,copyAll:!1})}),k===``?null:(0,h.jsxs)(w1,{idPrefix:ne,id:`pronunciation`,active:te===`pronunciation`,children:[A.length===0?null:(0,h.jsxs)(aI,{className:`mb-3`,title:`${A.length===1?`1 entry is`:`${A.length} entries are`} skipped by the narration and read as ordinary text`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:A.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsx)(`p`,{className:`m-0 mt-1`,children:`The other entries are used. To fix these, edit the Pronunciation Glossary at the end of the article in Edit settings → Article.`})]}),(0,h.jsx)(`div`,{className:`sl-stage-scroll pr-3`,children:(0,h.jsx)(C8,{markdown:k})})]})]})}var z8=new Intl.NumberFormat(`en`);function Qve(e){let t=e.replace(/\]\([^)]*\)/g,`]`).replace(/[#*_>`[\]]/g,``).replace(/[ \t]+/g,` `).trim(),n=t.split(/\s+/).filter(e=>/[\p{L}\p{N}]/u.test(e)).length,r=t.replace(/\s*\n\s*/g,` `).length;return`${z8.format(n)} ${n===1?`word`:`words`} · ${z8.format(r)} characters`}function B8({className:e,label:t,children:n}){return(0,h.jsx)(`dl`,{"aria-label":t,className:z(`m-0 grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[max-content_minmax(0,1fr)] sm:gap-y-3`,e),children:n})}function V8({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2 max-sm:mt-2 max-sm:first:mt-0`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function H8({src:e,label:t,marks:n=[],waveform:r,compact:i=!1,preload:a=`metadata`,onError:o,ref:s,className:c}){let l=e0(),u=l.media;return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`${t} controls`,"data-slot":`audio-player`,"data-state":l.playing?`playing`:`paused`,className:z(`sl-audio`,i&&`sl-audio--compact`,r!==void 0&&r.length>0&&`sl-audio--wave`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.key===` `&&e.target.closest(`button`)!==null)return;let t=l.keyAction(e.key);t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||l.setMenu(!1)},children:[(0,h.jsx)(`audio`,{ref:Q1(u,s),src:e,preload:a,"aria-label":t,onError:o,...l.events}),(0,h.jsx)(r0,{controls:l,className:`sl-audio__key`}),(0,h.jsx)(i0,{controls:l}),(0,h.jsx)(a0,{controls:l,chapters:n,waveform:r}),(0,h.jsx)(o0,{controls:l}),(0,h.jsx)(s0,{controls:l})]})}function U8({projectId:e,revisionId:t}){let n=T3(e),r=t===void 0?n:t,{api:i}=V(),a=I({queryKey:H.audioPreview(e,r),queryFn:async()=>R(await i.client.projects[`:projectId`][`audio-preview`].$get({param:{projectId:e}})),refetchInterval:1e3,staleTime:0,gcTime:0,retry:!1}),o=(a.data?.revisionId??null)===r?a.data?.previews??[]:[];return(0,h.jsxs)(`section`,{"aria-label":`Live narration`,className:`grid gap-3 border-y border-line py-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-ink`,children:`Listen while it generates`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Play any part. Each preview starts from its beginning.`})]}),a.error===null?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Live preview is temporarily unavailable. Finished audio will still appear here.`}),o.length===0&&a.error===null?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Waiting for the first audio bytes…`}):null,(0,h.jsx)(`div`,{className:`grid max-h-[420px] gap-3 overflow-y-auto`,children:o.map(t=>(0,h.jsx)($ve,{preview:t,url:`${i.origin}/api/projects/${encodeURIComponent(e)}/audio-preview/${t.id}`},t.id))})]})}function $ve({preview:e,url:t}){let[n,r]=(0,m.useState)(!1),i=(e.state===`streaming`||e.state===`ready`)&&e.bytes>0,a=e.state===`ready`?`Ready`:e.state===`streaming`?`Generating`:`Preview stopped`;return(0,h.jsxs)(`div`,{className:`grid gap-2 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:e.label}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:a})]}),i&&!n?(0,h.jsx)(eye,{label:e.label,url:t,onError:()=>r(!0)}):(0,h.jsx)(`p`,{className:`text-ink-2`,children:e.state===`streaming`&&!n?`Waiting for audio…`:`This preview has stopped. The finished narration will be available when generation completes.`})]})}function eye({label:e,url:t,onError:n}){let r=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=r.current;return()=>{e!==null&&(e.pause(),e.removeAttribute(`src`),e.load())}},[]),(0,h.jsx)(H8,{ref:r,compact:!0,preload:`none`,label:`Live ${e} narration`,src:t,onError:n,className:`max-w-[620px]`})}function tye({outputs:e}){let t=(0,m.useId)(),n=t=>e.find(e=>e.role===`narration_txt`&&e.meta.segment===t),r=O8(n(`intro`)).data,i=O8(n(`body`)).data,a=O8(n(`outro`)).data,[o,s]=(0,m.useState)(),c=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>s({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),l=[[`Intro`,r],[`Body`,i],[`Outro`,a]].filter(([,e])=>e!==void 0&&e.trim()!==``);if(!e.some(e=>e.role===`narration_txt`))return null;let u=l.length===1?(l[0]?.[1]??``).trim():l.map(([e,t])=>`## ${e}\n\n${(t??``).trim()}`).join(`
290
290
 
291
- `);return(0,h.jsxs)(`section`,{"aria-labelledby":`${t}-title`,className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`h3`,{id:`${t}-title`,className:`sl-kicker text-ink-3`,children:`Narration text`}),(0,h.jsx)(Wz,{markdown:u,label:`Narration text`,regionLabel:`Narration text`,anchorPrefix:`narration-`,what:`narration text`,onCopy:c,children:(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}),(0,h.jsx)(v1,{tone:o?.tone??`info`,children:o?.text})]})}var W8=(0,m.createContext)(!1),G8=(0,m.createContext)(void 0),K8=(0,m.createContext)(void 0);function q8(e){let t=h8();return e===void 0?!1:t?.outputs.some(t=>t.output.id===e.id&&t.state===`outdated`)??!1}function J8(e,t,n){let[r,i]=(0,m.useState)(),a=(0,m.use)(W8),o=(0,m.use)(G8),s=(0,m.use)(K8),c=h8(),l=e===void 0?void 0:c?.outputs.find(t=>t.output.id===e.id)?.workKey,u=a&&l!==void 0;return{act:t=>{if(e===void 0)return;if(!u||l===void 0||t===`regenerate-image`){i(t);return}if(!l.startsWith(`image:`))return;let n=l.slice(6);o?.({section:`images`,change:e=>({...e,content:{...e.content,imageOrder:e.content.imageOrder.filter(e=>e!==n),imageDefinitions:Object.fromEntries(Object.entries(e.content.imageDefinitions).filter(([e])=>e!==n))},regenerate:(e.regenerate??[]).filter(e=>e!==l)})})},asking:r,confirm:()=>{let n=r;i(void 0),n!==void 0&&e!==void 0&&(u&&l!==void 0&&n===`regenerate-image`?s?.([l]):t.run({kind:n,outputId:e.id}))},dismiss:()=>i(void 0),unavailable:e===void 0||n||t.pending||u&&(o===void 0||s===void 0),viaEdit:u,now:u,ready:!a||c!==void 0}}function eye(e,t){let[n,r]=(0,m.useState)(!1),i=(0,m.use)(W8),a=(0,m.use)(K8),o=h8();if(!i||o===void 0)return;let s=new Set(e.map(e=>e.id)),c=o.outputs.flatMap(e=>s.has(e.output.id)&&e.workKey.startsWith(`image:`)?[e.workKey]:[]);if(c.length!==0)return{count:c.length,asking:n,act:()=>r(!0),confirm:()=>{r(!1),a?.(c)},dismiss:()=>r(!1),unavailable:t||a===void 0}}var tye=200,nye=Y({seconds:q(),peaks:J(q())});function rye(e){if(e===void 0)return;let t;try{t=new URL(e,window.location.href)}catch{return}if(t.pathname.startsWith(`/files/`))return t.searchParams.set(`waveform`,String(tye)),t.toString()}function iye(e){let{api:t}=V(),n=rye(e);return I({queryKey:[`waveform`,n],enabled:n!==void 0,staleTime:1/0,retry:!1,queryFn:async()=>{if(n===void 0)return[];let e=await t.fetch(n);if(!e.ok)throw lo(e,void 0);let{peaks:r}=yo(nye,await e.json()),i=Math.max(0,...r);return i===0?[]:r.map(e=>e/i)}}).data}function Y8(e){return(0,h.jsx)(H8,{...e,waveform:iye(e.src)})}var X8=[{role:`audio_intro`,segment:`intro`,name:`Intro`},{role:`audio_body`,segment:`body`,name:`Body`},{role:`audio_outro`,segment:`outro`,name:`Outro`}];function aye({stage:e,project:t,outputs:n,busy:r}){let{api:i}=V(),a=I(fb(i)),o=j8(t.id),s=c8(n,e),c=s.filter(e=>e.role===`audio_levelled`),l=X8.flatMap(e=>{let t=l8(s,e.role),n=c.find(t=>t.meta.segment===e.segment)??t;return n===void 0?[]:[{...e,output:n,...t===void 0||t===n?{}:{plain:t}}]}),u=X8.flatMap(e=>{let t=c.find(t=>t.meta.segment===e.segment)?.meta.loudness;return t===void 0?[]:[{name:e.name,report:t}]}),d=l.find(e=>e.output.meta.voice!==void 0)?.output.meta,f=l.length>0?d?.voice:t.config.audio?.voice,p=l.length>0?d?.provider:t.config.audio?.provider,m=a.data?.voices.find(e=>e.voiceId===f&&e.provider===p)?.name??f;return(0,h.jsxs)(b8,{children:[e.state===`running`?(0,h.jsx)(U8,{projectId:t.id}):null,l.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No narration has landed yet.`}):l.map(e=>(0,h.jsx)(oye,{name:e.name,output:e.output,...e.plain===void 0?{}:{plain:e.plain}},e.role)),(0,h.jsx)(E8,{files:Hve(s,l,n.find(e=>e.role===`script_md`))}),u.length===0?null:(0,h.jsx)(D8,{children:u.map(({name:e,report:t})=>u.length===1?sk(t):`${e}: ${sk(t)}`).join(` `)}),(0,h.jsxs)(B8,{label:`How it was recorded`,children:[m===void 0?null:(0,h.jsx)(V8,{label:`Voice`,children:m}),(0,h.jsx)(V8,{label:`Chunking`,children:sye(cye(t.config.chunking))}),Wve(s)?(0,h.jsx)(V8,{label:`Text files`,children:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Clean narration is the spoken text used for captions. The TTS script adds delivery cues, with a blank line between requests. Uploaded audio has no TTS request.`})}):null]}),(0,h.jsx)(I8,{review:M8(o,{itemKey:`narration`}),projectId:t.id,busy:r}),(0,h.jsx)($ve,{outputs:s})]})}function oye({name:e,output:t,plain:n}){let r=g8(t),i=q8(t),a=q8(n)||n===void 0?void 0:n,o=g8(i?a:void 0);return(0,h.jsxs)(`div`,{className:`grid grid-cols-[64px_minmax(0,1fr)] items-center gap-3 text-small`,children:[(0,h.jsx)(x8,{children:e}),(0,h.jsx)(Y8,{label:`${e} narration`,src:r?.url,className:`max-w-[640px]`}),i?(0,h.jsx)(`p`,{className:`col-start-2 m-0 text-small text-ink-2`,children:a===void 0?`Outdated: this is the narration from before your last change. The new one is made when the run carries on: press Continue the run, or Remake at the top of the page.`:`Outdated: this is the levelled narration from before your last change. The new narration is below as it was spoken; it is levelled when the run carries on: press Continue the run, or Remake at the top of the page.`}):null,i&&a!==void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x8,{children:`New`}),(0,h.jsx)(Y8,{label:`${e} narration, new, before levelling`,src:o?.url,className:`max-w-[640px]`})]}):null]})}function sye(e){return e.charAt(0).toUpperCase()+e.slice(1)}function cye(e){return e===void 0||e.mode===`whole`?`the whole text as one request`:e.mode===`paragraph`?`one request per paragraph`:e.mode===`characters`?`every ${String(e.characters??3e3)} characters`:`every ${String(e.words??500)} words`}function lye({stage:e,project:t,outputs:n}){let r=l8(c8(n,e),`document_pdf`),i=g8(r),a=sC(t.config.document);return(0,h.jsxs)(b8,{children:[r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The PDF will be saved when rendering finishes.`:`No PDF has been saved yet.`}):(0,h.jsx)(E8,{files:[{output:r,label:`PDF`}],label:`Download PDF`,children:i?.folder?(0,h.jsxs)(TS,{href:`${i.url}?inline=1`,target:`_blank`,rel:`noopener`,variant:`secondary`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open PDF`]}):null}),(0,h.jsx)(B8,{label:`PDF details`,children:(0,h.jsx)(V8,{label:`Theme`,children:a})})]})}var uye={research:`Generates fresh research and affected article, narration, entries, thumbnail and exports; previous outputs stay in History.`,article:`Generates a fresh article and affected narration, entries, thumbnail and exports; previous outputs stay in History.`,audio:`Regenerates narration and affected exports, keeping compatible cue preparation; previous outputs stay in History.`,images:`Regenerates generated images and affected video, keeping supplied images and narration; previous outputs stay in History.`,thumbnail:`Regenerates the thumbnail without changing the main video; previous outputs stay in History.`,video:`Rebuilds local exports from saved media without regenerating narration or images; previous outputs stay in History.`,document:`Renders the PDF again from the saved article and title without regenerating anything else; previous outputs stay in History.`};function Z8(e){switch(e.kind){case`cancel`:return{title:`Cancel this run?`,consequence:`Stops every running stage; finished outputs are kept.`,verb:`Cancel run`,dismiss:`Keep running`};case`rerun`:return{title:`Re-run this stage?`,consequence:uye[e.stage],verb:`Re-run`,dismiss:`Cancel`};case`delete-image`:return{title:`Delete this image?`,consequence:`Removes the image and re-renders video when enabled.`,verb:`Delete`,dismiss:`Cancel`};case`regenerate-image`:return e.thumbnail?{title:`Regenerate this thumbnail?`,consequence:`Makes a new thumbnail, one paid image call. The video and shorts are not touched; the PDF's cover follows the first thumbnail. The old one stays in History.`,verb:`Regenerate`,dismiss:`Cancel`}:{title:`Regenerate this image?`,consequence:e.now?`Makes a new image now, one paid image call. The video keeps the current one until you remake it; the old image stays in History.`:`Replaces the image with a new one and re-renders video when enabled.`,verb:`Regenerate`,dismiss:`Cancel`};case`save-article`:return{title:`Save the edited article?`,consequence:`Replaces the article, then updates the enabled narration and final export.`,verb:`Save & update outputs`,dismiss:`Cancel`};case`discard-article`:return{title:`Discard these edits?`,consequence:`The article goes back to the text on disk.`,verb:`Discard`,dismiss:`Keep editing`}}}function dye(e,t){let{config:n,content:r,fingerprints:i}=e.revision;switch(t){case`research`:return n.sources.research===`generate`;case`article`:return n.sources.article===`generate`&&!r.articleEdited;case`audio`:return n.sources.audio===`generate`&&Object.keys(i).some(e=>!/^audio:(body:.+|intro|outro):[0-9]+$/.test(e)&&!/^audio:(body|intro|outro):future$/.test(e)?!1:!Object.entries(r.narrationOverrides).some(([t,n])=>n.kind===`asset`&&(e===t||e.startsWith(`${t}:`))));case`images`:return n.sources.images!==`off`&&r.imageOrder.some(e=>r.imageDefinitions[e]?.source===`generate`);case`thumbnail`:return n.sources.thumbnail===`from_prompt`||n.sources.thumbnail===`prompt_by_llm`;case`video`:return n.sources.video!==`off`||n.sources.audio!==`off`;case`document`:return YS(n.sources,`document`)===`generate`}}function Q8(e){switch(e){case`research`:case`article`:return`article`;case`audio`:return`narration`;case`images`:case`thumbnail`:return`images`;case`video`:return`video`;case`document`:return`document`}}var $8={research:`Research`,article:`Article`,audio:`Narration`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`PDF`},e5=e=>/^[A-Z]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1);function fye(e){let{project:t,stages:n}=e,r=t.config,i=e=>e===`video`&&XP(r)===`audio`?`Audio export`:$8[e];if(e.sample)return{situation:`sample`,tone:`info`,status:`Sample project`,title:`This is the sample project, finished and free to explore.`,why:`It is read-only. Your own copy can be edited and made again.`,action:{label:`Make my own copy`,intent:{kind:`copy-sample`}}};if(t.status===`paused`){let t=_ye(e.outdated);return{situation:`paused`,tone:`waiting`,status:`Paused`,title:`The run is paused.`,why:t===void 0?`Everything made so far is kept. Continuing picks up where it stopped.`:`Everything made so far is kept. Still to make: ${t}. They stay outdated until you continue.`,action:{label:`Continue the run`,intent:{kind:`resume`}}}}let a=n.find(e=>e.state===`failed`&&e.retryAt===void 0);if(a!==void 0){let t=i(a.kind),n=e.fixOf(a),r={label:`Try ${e5(t5(t))} again`,intent:{kind:`retry`,stage:a.kind}},o={situation:`failed`,tone:`failed`,status:`Failed`,section:Q8(a.kind),...a.failureReason===null?{}:{detail:a.failureReason}};switch(n?.kind){case`sign-in`:return{...o,title:`${n.label.replace(/^Sign in to /,``)} is signed out, so ${e5(t5(t))} stopped.`,why:`Copy the sign-in command (${n.command}), run it in a terminal on the computer running Slopify and sign in, then press Check again. Once ${n.label.replace(/^Sign in to /,``)} is signed in, Slopify tries ${e5(t5(t))} again.`,action:{label:`Copy sign-in command`,intent:{kind:`sign-in`,stage:a.kind,fix:n}}};case`refused`:return{...o,title:`A content filter refused a prompt, so ${e5(t5(t))} stopped.`,why:n.soften?`Softening rewrites each refused prompt without what the filter flagged, then draws it again.`:`Change the prompt in the project settings, then try again.`,action:n.soften?{label:n.label,intent:{kind:`soften`,stage:a.kind}}:{label:`Edit the prompt`,intent:{kind:`edit`}}};case`switch-model`:return{...o,title:`The model for ${e5(t5(t))} is no longer offered.`,why:`Pick another model in the project settings, then try again.`,action:{label:`Switch model`,intent:{kind:`edit`}}};case`provider-settings`:return{...o,title:`The provider did not accept its key, so ${e5(t5(t))} stopped.`,why:`Check the key in Settings, then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`providers`}}};case`free-space`:return{...o,title:`The disk is full, so ${e5(t5(t))} stopped.`,why:`Storage in Settings shows what can go. Then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`storage`}}};case void 0:return{...o,title:`${t} stopped with an error.`,why:`Trying again keeps everything already made.`,action:r}}}let o=e.held[0];if(o!==void 0){let e=i(o.stage);return{situation:`held`,tone:`waiting`,status:`Waiting for you`,title:`The ${e5(e)} ${hye(e)} ready for your review.`,why:o.dependents.length===0?`Approving marks it reviewed.`:`Approving lets ${n5(o.dependents.map(e=>e5(t5(i(e)))))} run. Nothing after it runs until you do.`,action:{label:pye(o,i),intent:{kind:`approve`,gate:o}},section:Q8(o.stage)}}let s=n.find(e=>e.state===`failed`&&e.retryAt!==void 0),c=e.waits[0];if(c!==void 0||s!==void 0){if(c!==void 0){let t=_H(e.waits);return{situation:`waiting`,tone:`waiting`,status:`Waiting for limits`,title:`${gH(e.waits,e.clock)??``}.`,why:`Nothing to do: the run carries on by itself when they reset, and work that does not need ${t} keeps going.`,section:Q8(c.stage)}}if(s!==void 0)return{situation:`waiting`,tone:`waiting`,status:`Waiting to try again`,title:`${i(s.kind)} will try again by itself at ${e.clock(s.retryAt??``)}.`,why:`Nothing to do: the run carries on when it does.`,section:Q8(s.kind),...s.failureReason===null?{}:{detail:s.failureReason}}}let l=n.find(e=>e.state===`running`);if(t.status===`running`||l!==void 0)return{situation:`running`,tone:`running`,status:`Running`,title:l===void 0?`The run is starting.`:`Making the ${e5(i(l.kind))}${mye(l)}.`,why:`Pausing lets the current call finish and keeps everything made so far.`,action:{label:`Pause`,intent:{kind:`pause`}},...l===void 0?{}:{section:Q8(l.kind)}};if(t.status===`pending`&&t.setAside===!0)return e.uploadReady?{situation:`done`,tone:`done`,status:`Kept as is`,title:`The video is ready; what is left won't run.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them. Editing the project brings the rest back to Needs you.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}:{situation:`done`,tone:`done`,status:`Kept as is`,title:`Kept as is: what is left won't run.`,why:`Everything made is kept. Editing the project brings the rest back to Needs you.`};if(e.resumable||t.status===`canceled`||t.status===`failed`&&a===void 0)return{situation:`stopped`,tone:`off`,status:t.status===`canceled`?`Canceled`:`Stopped`,title:`The run stopped before it finished.`,why:`Continuing makes only what is missing; everything made so far is kept.`,action:{label:`Continue the run`,intent:{kind:`resume`}}};if(t.status===`pending`)return{situation:`queued`,tone:`off`,status:`Queued`,title:`Waiting for its turn.`,why:`It starts by itself when the videos ahead of it are done.`};let u=gye(e.outdated);if(u!==void 0)return{situation:`outdated`,tone:`info`,status:`Outdated`,title:u.count===1||u.singular?`The ${u.noun} ${u.noun.endsWith(`s`)?`are`:`is`} outdated after your edit.`:`${String(u.count)} ${u.plural} are outdated after your edit.`,why:`They keep their current version until you remake them. Nothing else is made again.`,action:{label:u.count===1||u.singular?`Remake the outdated ${u.noun}`:`Remake ${String(u.count)} outdated ${u.plural}`,intent:{kind:`remake`,workKeys:u.workKeys}},section:u.section};if(t.status===`done`&&r.mode===`short`)return{situation:`done`,tone:`done`,status:`Done`,title:`The short is ready.`,why:`Play opens set up for a long video on the same topic, with the same starter pack and providers. Nothing starts until you press Play.`,action:{label:`Make the full video on this topic`,intent:{kind:`full-video`}}};if((t.status===`done`||t.status===`partial`)&&e.uploadReady)return{situation:`done`,tone:`done`,status:`Done`,title:`The video is ready.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}}function pye(e,t){if(e.dependents.includes(`video`))return`Approve and render the video`;if(e.dependents.includes(`images`))return`Approve and make the images`;if(e.dependents.includes(`audio`))return`Approve and record the narration`;let n=e.dependents[0];return n===void 0?`Approve the ${e5(t(e.stage))}`:`Approve and make the ${e5(t(n))}`}function mye(e){let t=nF(e);return t===void 0?e.progressTotal===null||e.progressTotal<=0?``:` · ${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)}`:` · ${t}`}function t5(e){return/s$/i.test(e)?e:`the ${e5(e)}`}function hye(e){return/s$/i.test(e)?`are`:`is`}function n5(e){return e.length<=1?e[0]??``:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`}var r5=[{id:`article`,noun:`article`,plural:`article files`,singular:!0,section:`article`,roles:[`notes`,`sources`,`article_md`,`article_txt`,`script_md`],counted:[`article_md`]},{id:`narration`,noun:`narration`,plural:`narration parts`,singular:!0,section:`narration`,roles:[`narration_txt`,`tts_script`,`glossary`,`audio_body`,`audio_intro`,`audio_outro`,`audio_levelled`],counted:[`audio_body`]},{id:`reference`,noun:`establishing image`,plural:`establishing images`,singular:!0,section:`images`,roles:[`reference`],counted:[`reference`]},{id:`images`,noun:`image`,plural:`images`,singular:!1,section:`images`,roles:[`image`],counted:[`image`]},{id:`animated`,noun:`animated image`,plural:`animated images`,singular:!1,section:`images`,roles:[`animated_image`],counted:[`animated_image`]},{id:`thumbnails`,noun:`thumbnail`,plural:`thumbnails`,singular:!1,section:`images`,roles:[`thumbnail`],counted:[`thumbnail`]},{id:`video`,noun:`video`,plural:`video files`,singular:!0,section:`video`,roles:[`video`,`audio_export`,`audio_mp3`,`audio_m4b`,`render_params`,`subtitles_srt`,`subtitles_vtt`,`subtitle_words`,`subtitle_ass`,`subtitle_font`],counted:[`video`,`audio_export`]},{id:`shorts`,noun:`short`,plural:`shorts`,singular:!1,section:`shorts`,roles:[`shorts`,`short_image`,`short_video`],counted:[`short_video`]},{id:`youtube`,noun:`YouTube description`,plural:`YouTube descriptions`,singular:!0,section:`youtube`,roles:[`youtube_description`,`youtube_tags`,`youtube_pinned_comment`,`youtube_titles`],counted:[`youtube_description`]},{id:`document`,noun:`PDF`,plural:`PDFs`,singular:!0,section:`document`,roles:[`document_pdf`],counted:[`document_pdf`]}];function gye(e){for(let t of r5){let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)continue;let r=n.filter(e=>t.counted.includes(e.role)).length;return{noun:t.noun,plural:t.plural,singular:t.singular,count:Math.max(1,r),workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section}}}function _ye(e){let t=r5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[t.singular?`the ${t.noun}`:r===1?`1 ${t.noun}`:`${String(r)} ${t.plural}`]});return t.length===0?void 0:n5(t)}function vye(e){return r5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[{label:r===1||t.singular?`Remake the outdated ${t.noun}`:`Remake ${String(r)} outdated ${t.plural}`,workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section,count:r}]})}function yye({tone:e,status:t,title:n,why:r,action:i,className:a}){return(0,h.jsxs)(`section`,{"aria-label":`Next action`,className:z(`sl-next`,a),children:[(0,h.jsx)(OS,{tone:e,children:t}),(0,h.jsx)(`p`,{className:`sl-next__title`,children:n}),r===void 0?null:(0,h.jsx)(`p`,{className:`sl-next__why`,children:r}),i===void 0?null:(0,h.jsx)(`div`,{className:`flex flex-col [&>*]:w-full`,children:i})]})}function bye({project:e,stages:t,resumable:n,sample:r,gates:i,outdated:a,waits:o,uploadReady:s,actions:c,controller:l,openSection:u,openUpload:d}){let{api:f}=V(),p=_(),h=Ji(),[g,v]=(0,m.useState)(),y=(0,m.useRef)(new Map),b=fye({project:e,stages:t,resumable:n,sample:r,held:i.filter(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint).map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),outdated:a,waits:o,uploadReady:s,fixOf:t=>p3(t,e),clock:aF}),x=L({mutationFn:()=>tb(f,e.id),onSuccess:async({projectId:e})=>{await p.invalidateQueries({queryKey:H.projects}),await h({to:`/projects/$projectId`,params:{projectId:e}})},onError:e=>v(`${_o(e.message)} The copy was not made. Press Make my own copy to try again.`)}),S=(0,m.useRef)(null),C=YN(),w=L({mutationFn:async()=>{if(C===null)throw Error(`Play isn't available on this page. Reload the page`);if(C.review.starting||C.review.uncertain||C.review.created!==null)throw Error(`Play is starting a run from its open draft. Wait for it to start`);if(!await C.flush())throw Error(`The draft open in Play couldn't be saved. Open Play, save or discard it`);S.current??=crypto.randomUUID();let{draft:t}=await Zy(f,{projectId:e.id,draftId:S.current});if(await p.invalidateQueries({queryKey:[`play-drafts`]}),!await C.open(t.id))throw Error(`The full video's draft was made but didn't open. Open Play and pick it`);S.current=null,await h({to:`/play`})},onError:e=>v(`${_o(e.message)} Then press Make the full video on this topic again.`)}),T=L({mutationFn:async t=>{let n=i.find(e=>e.checkpointId===t.checkpointId);if(n===void 0)throw Error(`The review changed before it was approved. Reload the page.`);let r=`${n.checkpointId}:${n.fingerprint}`,a=y.current.get(r)??crypto.randomUUID();y.current.set(r,a);let o=await d3(f,e.id,n.checkpointId,{revisionId:n.revisionId,fingerprint:n.fingerprint,idempotencyKey:a});if(y.current.delete(r),!o.ok)throw Error(o.message)},onSettled:async()=>{await p.invalidateQueries({queryKey:s3(e.id)}),await p.invalidateQueries({queryKey:H.project(e.id)}),p.invalidateQueries({queryKey:H.projects})},onError:e=>v(`${_o(e.message)} Press the approve button again to check whether it went through.`)});return{next:b,run:e=>{switch(v(void 0),e.kind){case`copy-sample`:x.mutate();return;case`resume`:case`pause`:c.run({kind:e.kind});return;case`retry`:case`soften`:c.run({kind:e.kind,stage:e.stage});return;case`sign-in`:p1(e.fix.command).then(t=>v(t?`Copied ${e.fix.command}. Run it in a terminal on the computer running Slopify, sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.fix.command} in a terminal, sign in, then press Check again.`));return;case`approve`:T.mutate(e.gate);return;case`remake`:l.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0});return;case`edit`:u(`settings`);return;case`open-settings`:h({to:`/settings`,search:{section:e.section}});return;case`prepare-upload`:d();return;case`full-video`:w.mutate();return}},pending:x.isPending||w.isPending||T.isPending||c.pending||l.pending,message:g}}function xye(e){switch(e.kind){case`copy-sample`:return`Copying…`;case`resume`:return`Continuing…`;case`pause`:return`Pausing…`;case`approve`:return`Approving…`;case`remake`:return`Starting the remake…`;case`retry`:return`Trying again…`;case`soften`:return`Softening…`;case`full-video`:return`Opening Play…`;default:return}}function i5({state:e,variant:t,className:n}){let[r,i]=(0,m.useState)(!1),a=e.next?.action;if(a===void 0)return null;let o=a.intent;if(o.kind===`sign-in`)return(0,h.jsx)(m1,{fix:o.fix,variant:t,retry:{run:()=>e.run({kind:`retry`,stage:o.stage}),busy:e.pending}});if(o.kind===`open-settings`)return(0,h.jsx)(CS,{to:`/settings`,search:{section:o.section},variant:t,...n===void 0?{}:{className:n},children:a.label});let s=e.pending?xye(o)??a.label:a.label;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:t,className:n,disabled:e.pending,disabledReason:`Working on the last press`,"aria-keyshortcuts":t===`primary`?Ux(nP.nextAction):void 0,onClick:()=>o.kind===`soften`?i(!0):e.run(o),children:s}),o.kind===`soften`?(0,h.jsx)(Hy,{open:r,tone:`primary`,title:`Soften the refused prompt and try again?`,consequence:`Your project's AI model rewrites each refused prompt without what a content filter could flag, keeping the scene and style. The image is then drawn again from the new wording, which it keeps as its prompt. The AI call and the new image are charged like any other.`,confirmLabel:`Soften and retry`,cancelLabel:`Keep the prompt`,pending:e.pending,onConfirm:()=>{i(!1),e.run(o)},onCancel:()=>i(!1)}):null]})}function Sye({state:e,feedback:t}){let n=e.next;return n===void 0&&t===void 0&&e.message===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n===void 0?null:(0,h.jsx)(yye,{tone:n.tone,status:n.status,title:n.title,...n.why===void 0?{}:{why:n.why},...n.action===void 0?{}:{action:(0,h.jsx)(i5,{state:e,variant:`primary`})}}),e.message===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e.message}),t]})}var Cye={sample:void 0,paused:void 0,stopped:void 0,queued:void 0,running:void 0,failed:`danger`,held:`waiting`,waiting:`waiting`,outdated:`info`,done:void 0};function wye({state:e,section:t}){let n=e.next;if(n===void 0||n.section!==t)return null;let r=Cye[n.situation];return r===void 0?null:(0,h.jsx)(aI,{className:`max-[1180px]:hidden`,tone:r,title:n.title,...n.action===void 0?{}:{actions:(0,h.jsx)(i5,{state:e,variant:`secondary`})},children:n.why===void 0&&n.detail===void 0?void 0:(0,h.jsxs)(h.Fragment,{children:[n.why===void 0?null:(0,h.jsx)(`span`,{className:`block`,children:n.why}),n.detail===void 0?null:(0,h.jsxs)(`details`,{className:`mt-1`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:n.detail})]})]})})}var Tye={research:`Research again`,article:`Write the article again`,audio:`Record the narration again`,images:`Make all images again`,thumbnail:`Make the thumbnails again`,video:`Render the video again`,document:`Render the PDF again`};function a5(e,t){return e===`video`&&t.config.sources.video===`off`?`Export the audio again`:Tye[e]}function o5({id:e,title:t,kicker:n,stages:r,project:i,outputs:a,actions:o,next:s,active:c,meta:l,head:u=!0,extra:d,resumable:f=!1,children:p}){let m=r[0],g=r.some(e=>o.refusal?.stage===e.kind)?o.refusal?.message:void 0,_=r.filter(t=>t.state===`failed`&&t.retryAt===void 0&&(s.next?.situation!==`failed`||s.next.section!==e)),v=r.find(e=>e.state===`running`),y=v===void 0?void 0:iF(v),b=l??(m===void 0?void 0:r.filter(e=>e.state!==`skipped`).map(e=>e===m?tF(e,a,i,f):`${$8[e.kind]}: ${tF(e,a,i,f)}`).join(` · `));return(0,h.jsxs)(`section`,{hidden:!c,"aria-label":t,"data-tour":m===void 0?void 0:`project-${m.kind}`,className:`flex min-w-0 flex-col gap-5`,children:[u?(0,h.jsxs)(W,{row:!0,title:t,...n===void 0?{}:{kicker:n},...b===void 0||b===``?{}:{meta:b},children:[d,(0,h.jsx)(c5,{stages:r,project:i,actions:o})]}):null,y===void 0||v===void 0?null:(0,h.jsx)(C2,{value:y,label:`${$8[v.kind]} progress`,valueText:tF(v,a,i,f)}),(0,h.jsx)(wye,{state:s,section:e}),_.map(e=>(0,h.jsx)(aI,{tone:`danger`,title:`${$8[e.kind]} stopped with an error.`,children:e.failureReason===null?void 0:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.failureReason})]})},e.id)),g===void 0?null:(0,h.jsx)(aI,{tone:`danger`,title:g,actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:o.dismissRefusal,children:`Dismiss`})}),m?.state===`running`&&m.kind!==`article`&&m.kind!==`images`&&m.kind!==`video`&&m.kind!==`document`?(0,h.jsx)(D3,{projectId:i.id,stage:m.kind}):null,p]})}function s5({stage:e,project:t,name:n}){return e===void 0||e.state===`skipped`?(0,h.jsx)(T1,{title:`${n} is off for this run.`,children:`Switch it on in the project settings to make it.`}):(0,h.jsx)(T1,{title:`No ${n.toLowerCase()} yet.`,children:t.status===`paused`?`It is made once you continue the run.`:`It starts when the steps before it are done. Finished work elsewhere can be looked at meanwhile.`})}function c5({stages:e,project:t,actions:n}){let r=(0,m.useContext)(W8),i=h8(),[a,o]=(0,m.useState)(),s=e.filter(e=>e.state!==`skipped`&&e.state!==`pending`&&(!r||i!==void 0&&dye(i,e.kind)));if(s.length===0)return null;let c=n.pending||t.status===`running`||e.some(e=>e.state===`running`),l=a===void 0?void 0:Z8({kind:`rerun`,stage:a});return(0,h.jsxs)(h.Fragment,{children:[s.map(e=>(0,h.jsxs)(B,{size:`small`,disabled:c,disabledReason:`Wait until the work on this project is done`,onClick:()=>o(e.kind),children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),a5(e.kind,t)]},e.id)),(0,h.jsx)(Hy,{open:a!==void 0,title:a===void 0?``:`${a5(a,t)}?`,consequence:l?.consequence??``,confirmLabel:a===void 0?``:a5(a,t),cancelLabel:`Keep what is there`,pending:n.pending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&n.run({kind:`rerun`,stage:e})},onCancel:()=>o(void 0)})]})}function Eye({stage:e,project:t,outputs:n,actions:r,busy:i}){let a=c8(n,e),o=j8(t.id),s=QS(t.config),c=Array.from({length:s},(e,t)=>t+1).map(e=>({variant:e,output:a.find(t=>t.role===`thumbnail`&&(t.meta.index??1)===e)})),l=c.flatMap(e=>e.output===void 0?[]:[e.output]),u=_8(l),[d,f]=(0,m.useState)(null),p=l.filter(e=>u.has(e.id)),g=p.map(e=>({src:u.get(e.id)?.url??``,alt:`Thumbnail ${String(e.meta.index??1)}`})),_=t.format===`9:16`,v=({variant:n,output:a})=>(0,h.jsx)(Dye,{variant:n,count:s,output:a,review:M8(o,{outputId:a?.id}),stage:e,project:t,actions:r,busy:i,onOpen:()=>f(a===void 0?null:Oye(p,a))},n);return(0,h.jsxs)(`section`,{"aria-label":s===1?`Thumbnail`:`Thumbnails`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(W,{title:s===1?`Thumbnail`:`Thumbnails`,meta:s===1?`The picture YouTube shows before the video plays`:`${String(s)} variants for YouTube's Test & compare`,children:[(0,h.jsx)(w8,{variant:`secondary`,files:l.map(e=>({output:e,label:s===1?`Thumbnail`:`Thumbnail ${String(e.meta.index??1)}`}))}),(0,h.jsx)(T8,{output:l[0]}),(0,h.jsx)(c5,{stages:[e],project:t,actions:r})]}),c.length===1?(0,h.jsx)(`div`,{className:_?`max-w-[280px]`:`max-w-[480px]`,children:c.map(v)}):(0,h.jsx)(u0,{list:!0,label:`Thumbnail variants`,children:c.map(e=>(0,h.jsx)(`li`,{className:`min-w-0`,children:v(e)},e.variant))}),(0,h.jsx)(d0,{items:g,index:d,onIndex:f,onClose:()=>f(null),actions:(e,t)=>{let n=p[t];return n===void 0?null:(0,h.jsx)(p5,{output:n,name:s===1?`the thumbnail`:`thumbnail ${String(n.meta.index??1)}`,actions:r,busy:i},n.id)}})]})}function Dye({variant:e,count:t,output:n,review:r,stage:i,project:a,actions:o,busy:s,onOpen:c}){let l=g8(n),u=J8(n,o,s),d=t===1?`the thumbnail`:`thumbnail ${String(e)}`;jx({id:`project.thumbnail.${String(e)}`,title:t===1?`Regenerate the thumbnail`:`Regenerate thumbnail ${String(e)}`,group:`This project`,context:a.title,keywords:[`thumbnail`,`redraw`,`remake`],run:()=>u.act(`regenerate-image`)});let f=r!==void 0&&!r.passed&&r.action===null,p=String.fromCharCode(64+e),m=u.asking===void 0||n===void 0?void 0:Z8({kind:u.asking,outputId:n.id,now:u.now,thumbnail:!0});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(l0,{alt:t===1?`Thumbnail for ${a.title}`:`Thumbnail ${String(e)} for ${a.title}`,aspect:l5(a.format),...l===void 0?{}:{src:l.url},...n===void 0&&i.state===`running`?{generating:`Making the thumbnail`}:{},title:t===1?`Thumbnail`:p,...n===void 0?{meta:kye(i)}:{},onOpen:c,openLabel:`Open ${d} full size`,...r===void 0?{}:{badge:(0,h.jsx)(L8,{review:r})},actionsShown:f,...n===void 0?{}:{actions:(0,h.jsxs)(h.Fragment,{children:[f&&r!==void 0?(0,h.jsx)(F8,{review:r,projectId:a.id,busy:s}):null,(0,h.jsxs)(B,{size:`small`,disabled:u.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>u.act(`regenerate-image`),"aria-label":`Regenerate ${d}`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),l===void 0?null:(0,h.jsx)(m5,{href:l.url,label:`Download ${d}`})]})}}),(0,h.jsx)(Hy,{open:u.asking!==void 0,tone:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:`Regenerate the thumbnail`,cancelLabel:`Keep it`,pending:o.pending,onConfirm:u.confirm,onCancel:u.dismiss})]})}function Oye(e,t){let n=e.indexOf(t);return n===-1?null:n}function kye(e){switch(e.state){case`running`:return`Being made`;case`failed`:case`canceled`:return`Not made`;default:return`Not made yet`}}function Aye(e,t){let n=e.filter(e=>e.role===`image`),r=new Map;for(let e of n){let t=e.meta.promptName??`Images`;r.set(t,[...r.get(t)??[],e])}let i=t.filter(e=>r.has(e)),a=[...r.keys()].filter(e=>!i.includes(e)).sort();return[...i,...a].flatMap(e=>{let t=r.get(e);return t===void 0?[]:[{name:e,images:[...t].sort(jye)}]})}function jye(e,t){return(e.meta.index??0)-(t.meta.index??0)}function Mye(e,t,n,r,i){let a=Ry(),[o,s]=(0,m.useState)(),c=(r,i)=>{let o=r===`image`?t:n,c=r===`image`?`image`:`on-screen card`;if(i===void 0){a(`Type the ${c}'s number with the command, for example "regenerate ${c} 3".`);return}let l=o.find(e=>e.meta.index===i);if(l===void 0){let t=o.flatMap(e=>e.meta.index===void 0?[]:[e.meta.index]);a(t.length===0?`${e.title} has no ${c}s yet, so there is no ${c} ${String(i)} to regenerate. They appear under Images once the run makes them.`:`${e.title} has no ${c} ${String(i)}: its ${c}s are numbered ${String(Math.min(...t))} to ${String(Math.max(...t))}. Type one of those, or press Regenerate on the ${c} in Images.`,`error`);return}s(e=>({image:l,name:`${c[0]?.toUpperCase()??``}${c.slice(1)} ${String(i)}`,nonce:(e?.nonce??0)+1}))};return jx({id:`project.image.regenerate`,title:`Regenerate an image`,numbered:e=>`Regenerate image ${String(e)}`,group:`This project`,context:e.title,keywords:[`image`,`picture`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`image`,e)}),jx({id:`project.card.regenerate`,title:`Regenerate an on-screen card`,numbered:e=>`Regenerate on-screen card ${String(e)}`,group:`This project`,context:e.title,keywords:[`card`,`figure`,`table`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`card`,e)}),oS(tS.regenerateImage(e.id),e=>c(`image`,e)),o===void 0?null:(0,h.jsx)(Nye,{request:o,actions:r,busy:i},o.nonce)}function Nye({request:e,actions:t,busy:n}){let r=Ry(),i=J8(e.image,t,n),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a.current&&i.ready&&(a.current=!0,i.unavailable?r(`${e.name} can't be regenerated while work on this project is running. Wait until it finishes, then run the command again or press Regenerate on it in Images.`,`error`):i.act(`regenerate-image`))},[i,r,e.name]);let o=i.asking===void 0?void 0:Z8({kind:i.asking,outputId:e.image.id,now:i.now});return(0,h.jsx)(Hy,{open:i.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate the image`,cancelLabel:`Keep it`,pending:t.pending,onConfirm:i.confirm,onCancel:i.dismiss})}function l5(e){return e===`9:16`?`portrait`:e===`1:1`?`square`:`landscape`}function Pye({stage:e,companion:t,project:n,outputs:r,actions:i,busy:a}){let o=j8(n.id),s=c8(r,e),c=Aye(s,n.config.imagePrompts?.map(e=>e.name)??[]),l=c.flatMap(e=>e.images),u=s.filter(e=>e.role===`figure_card`&&(e.meta.format??n.format)===n.format).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),d=[...l,...u],f=Mye(n,l,u,i,a),p=eye(l,a),g=_8(d),[_,v]=(0,m.useState)(null),y=d.filter(e=>g.has(e.id)),b=y.map(e=>({src:g.get(e.id)?.url??``,alt:e.role===`figure_card`?`On-screen card ${String(e.meta.index??``)}`:e.meta.prompt??`Image ${String(e.meta.index??``)}`,...u5(e)?{kind:`video`}:{},caption:e.role===`figure_card`?`Shown while the narration describes it`:e.meta.prompt??e.meta.promptName??`Slideshow image`})),x=n.config.reference===void 0?null:(0,h.jsx)(Fye,{image:l8(s,`reference`),format:n.format,generated:n.config.reference.source===`prompt`,affected:l.length,actions:i,busy:a}),S=t?.kind===`thumbnail`?(0,h.jsx)(Eye,{stage:t,project:n,outputs:r,actions:i,busy:a}):null,C=e.state===`running`&&e.progressTotal!==null?Math.max(0,e.progressTotal-l.length):0,w=o.filter(e=>l.some(t=>t.id===e.outputId)),T=w.filter(e=>e.passed&&e.attempt>1).length,E=w.filter(e=>!e.passed&&e.action===null).length,D=[l.length===0?void 0:`${String(l.length)} in the video`,w.length===0?void 0:`reviewed`,T===0?void 0:`${String(T)} redone after review`,E===0?void 0:`${String(E)} flagged`].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(h.Fragment,{children:[f,x,x===null||S===null&&e.state===`skipped`?null:(0,h.jsx)($K,{className:`m-0`}),S,S===null||e.state===`skipped`?null:(0,h.jsx)($K,{className:`m-0`}),e.state===`skipped`?null:(0,h.jsxs)(`section`,{"aria-label":`Slideshow images`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(W,{title:`Images`,...D===``?{}:{meta:D},children:[p===void 0?null:(0,h.jsxs)(B,{size:`small`,disabled:p.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:p.act,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate all`]}),p===void 0?null:(0,h.jsx)(Hy,{open:p.asking,tone:`primary`,title:`Regenerate all ${String(p.count)} images?`,consequence:`Makes ${String(p.count)} new images now, one paid image call each. The video keeps the current ones until you remake it; the old images stay in History.`,confirmLabel:`Regenerate them`,cancelLabel:`Keep them`,pending:i.pending,onConfirm:p.confirm,onCancel:p.dismiss}),(0,h.jsx)(Pve,{projectId:n.id,asset:`images.zip`,label:`Download all`}),(0,h.jsx)(c5,{stages:[e],project:n,actions:i})]}),c.length===0&&C===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`pending`?`The images are made once the narration is timed.`:`No images have landed yet.`}):null,c.map((e,t)=>(0,h.jsx)(h5,{name:e.name,count:e.images.length,showName:c.length>1,trailing:t===c.length-1&&C>0?Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(l0,{alt:`An image being made`,aspect:l5(n.format),generating:t===0?`Drawing the next image`:`Waiting its turn`},t)):null,children:t=>e.images.slice(0,t).map(e=>(0,h.jsx)(g5,{image:e,projectId:n.id,review:M8(o,{outputId:e.id}),format:n.format,actions:i,busy:a,onOpen:()=>v(f5(y,e))},e.id))},e.name)),u.length===0?null:(0,h.jsx)(h5,{name:`From the article`,count:u.length,showName:!0,children:e=>u.slice(0,e).map(e=>(0,h.jsx)(g5,{image:e,projectId:n.id,review:void 0,format:n.format,actions:i,busy:a,card:!0,onOpen:()=>v(f5(y,e))},e.id))}),c.length===0&&C>0?(0,h.jsx)(u0,{label:`Images being made`,children:Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(l0,{alt:`An image being made`,aspect:l5(n.format),generating:t===0?`Drawing the first image`:`Waiting its turn`},t))}):null,(0,h.jsx)(d0,{items:b,index:_,onIndex:v,onClose:()=>v(null),actions:(e,t)=>{let n=y[t];return n===void 0?null:(0,h.jsx)(p5,{output:n,name:n.role===`figure_card`?`on-screen card${d5(n)}`:`image${d5(n)}`,actions:i,busy:a},n.id)}})]})]})}var u5=e=>/\.(mp4|mov|m4v|webm|mkv)$/i.test(e.path),d5=e=>e.meta.index===void 0?``:` ${String(e.meta.index)}`;function f5(e,t){let n=e.indexOf(t);return n===-1?null:n}function p5({output:e,name:t,actions:n,busy:r}){let i=g8(e),a=J8(e,n,r),o=a.asking===void 0?void 0:Z8({kind:a.asking,outputId:e.id,now:a.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(B,{size:`small`,disabled:a.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>a.act(`regenerate-image`),"aria-label":`Regenerate ${t}`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),i===void 0?null:(0,h.jsx)(m5,{href:i.url,label:`Download ${t}`}),(0,h.jsx)(Hy,{open:a.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate it`,cancelLabel:`Keep it`,pending:n.pending,onConfirm:a.confirm,onCancel:a.dismiss})]})}function m5({href:e,label:t,text:n}){return(0,h.jsxs)(TS,{href:e,download:!0,"aria-label":t,title:t,size:`small`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),n]})}function Fye({image:e,format:t,generated:n,affected:r,actions:i,busy:a}){let o=g8(e),s=J8(e,i,a),[c,l]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Establishing image`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(W,{kicker:`Reference · not in the video`,title:`Establishing image`,meta:`Every image follows it for the look, palette and style`,children:e!==void 0&&n?(0,h.jsx)(B,{disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.act(`regenerate-image`),children:`Make the establishing image again`}):null}),(0,h.jsx)(l0,{className:`w-full max-w-[360px]`,alt:e?.meta.prompt??`Establishing image`,aspect:l5(t),...o===void 0?{}:{src:o.url},title:`Establishing image`,...e===void 0?{meta:`Not made yet`}:{},onOpen:()=>l(0),openLabel:`Open the establishing image full size`,...e===void 0||o===void 0?{}:{actions:(0,h.jsx)(m5,{href:o.url,label:`Download the establishing image`,text:`Download`})}}),n&&r>0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Making it again marks ${String(r)} image${r===1?``:`s`} outdated. They keep their current version until you remake them.`}):null,(0,h.jsx)(d0,{items:o===void 0?[]:[{src:o.url,alt:`Establishing image`,caption:e?.meta.prompt??`The reference every image follows`}],index:c,onIndex:l,onClose:()=>l(null),actions:()=>o===void 0?null:(0,h.jsxs)(h.Fragment,{children:[n?(0,h.jsxs)(B,{size:`small`,disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>{l(null),s.act(`regenerate-image`)},"aria-label":`Make the establishing image again`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}):null,(0,h.jsx)(m5,{href:o.url,label:`Download the establishing image`})]})}),(0,h.jsx)(Hy,{open:s.asking!==void 0,tone:`primary`,title:`Make the establishing image again?`,consequence:`A new establishing image replaces this one${r>0?`, and the ${String(r)} images drawn from it become outdated until you remake them`:``}. The old one stays in History.`,confirmLabel:`Make it again`,cancelLabel:`Keep this one`,pending:i.pending,onConfirm:s.confirm,onCancel:s.dismiss})]})}function h5({name:e,count:t,showName:n,trailing:r,children:i}){let[a,o]=(0,m.useState)(!1),s=t>12&&!a;return(0,h.jsxs)(`section`,{"aria-label":`${e} × ${String(t)}`,className:`flex flex-col gap-3`,children:[n?(0,h.jsx)(`h3`,{className:`sl-kicker m-0`,children:`${e} × ${String(t)}`}):null,(0,h.jsxs)(u0,{children:[i(s?12:t),r]}),t>12?(0,h.jsx)(B,{variant:`quiet`,"aria-expanded":a,className:`self-start`,onClick:()=>o(e=>!e),children:a?`Show fewer`:`Show all ${String(t)} images`}):null]})}function g5({image:e,projectId:t,review:n,format:r,actions:i,busy:a,card:o=!1,onOpen:s}){let c=g8(e),l=d5(e),u=o?`on-screen card${l}`:`image${l}`,d=J8(e,i,a),f=q8(e),p=n!==void 0&&!n.passed&&n.action===null,m=d.asking===void 0?void 0:Z8({kind:d.asking,outputId:e.id,now:d.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(l0,{alt:o?`On-screen card${l}`:e.meta.prompt??`Slideshow ${u}`,kind:u5(e)?`video`:`image`,aspect:l5(r),...c===void 0?{}:{src:c.url},title:o?`Card${l}`:e.meta.prompt??`Image${l}`,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`},onOpen:s,openLabel:`Open ${u} full size`,...n===void 0&&!f?{}:{badge:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap gap-1`,children:[f?(0,h.jsx)(kS,{tone:`info`,children:`Outdated`}):null,n===void 0?null:(0,h.jsx)(L8,{review:n})]})},actionsShown:p,actions:(0,h.jsxs)(h.Fragment,{children:[p&&n!==void 0?(0,h.jsx)(F8,{review:n,projectId:t,busy:a}):null,(0,h.jsxs)(B,{size:`small`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`regenerate-image`),"aria-label":`Regenerate ${u}`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),c===void 0?null:(0,h.jsx)(m5,{href:c.url,label:`Download ${u}`}),o?null:(0,h.jsx)(B,{size:`small`,variant:`destructive`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`delete-image`),"aria-label":`Delete ${u}`,title:`Delete ${u}`,children:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75})})]})}),(0,h.jsx)(Hy,{open:d.asking!==void 0,tone:d.asking===`delete-image`?`destructive`:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:d.asking===`delete-image`?`Delete the image`:`Regenerate the image`,cancelLabel:`Keep it`,pending:i.pending,onConfirm:d.confirm,onCancel:d.dismiss})]})}function _5(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function v5(e){let t=/^(?:(\d+):)?(\d{1,2}):(\d{2})$/.exec(e.trim());if(t===null)return;let n=Number(t[1]??`0`),r=Number(t[2]),i=Number(t[3]);if(!(i>59||t[1]!==void 0&&r>59))return n*3600+r*60+i}function Iye(e){let t=e.trim(),n=/^(\S+)\s+(.+)$/u.exec(t);if(n===null)return;let r=v5(n[1]??``),i=(n[2]??``).trim();return r===void 0||i===``?void 0:{start:r,title:i}}function y5(e,t){let n=e.replace(/\r\n?/gu,`
291
+ `);return(0,h.jsxs)(`section`,{"aria-labelledby":`${t}-title`,className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`h3`,{id:`${t}-title`,className:`sl-kicker text-ink-3`,children:`Narration text`}),(0,h.jsx)(Wz,{markdown:u,label:`Narration text`,regionLabel:`Narration text`,anchorPrefix:`narration-`,what:`narration text`,onCopy:c,children:(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}),(0,h.jsx)(v1,{tone:o?.tone??`info`,children:o?.text})]})}var W8=(0,m.createContext)(!1),G8=(0,m.createContext)(void 0),K8=(0,m.createContext)(void 0);function q8(e){let t=h8();return e===void 0?!1:t?.outputs.some(t=>t.output.id===e.id&&t.state===`outdated`)??!1}function J8(e,t,n){let[r,i]=(0,m.useState)(),a=(0,m.use)(W8),o=(0,m.use)(G8),s=(0,m.use)(K8),c=h8(),l=e===void 0?void 0:c?.outputs.find(t=>t.output.id===e.id)?.workKey,u=a&&l!==void 0;return{act:t=>{if(e===void 0)return;if(!u||l===void 0||t===`regenerate-image`){i(t);return}if(!l.startsWith(`image:`))return;let n=l.slice(6);o?.({section:`images`,change:e=>({...e,content:{...e.content,imageOrder:e.content.imageOrder.filter(e=>e!==n),imageDefinitions:Object.fromEntries(Object.entries(e.content.imageDefinitions).filter(([e])=>e!==n))},regenerate:(e.regenerate??[]).filter(e=>e!==l)})})},asking:r,confirm:()=>{let n=r;i(void 0),n!==void 0&&e!==void 0&&(u&&l!==void 0&&n===`regenerate-image`?s?.([l]):t.run({kind:n,outputId:e.id}))},dismiss:()=>i(void 0),unavailable:e===void 0||n||t.pending||u&&(o===void 0||s===void 0),viaEdit:u,now:u,ready:!a||c!==void 0}}function nye(e,t){let[n,r]=(0,m.useState)(!1),i=(0,m.use)(W8),a=(0,m.use)(K8),o=h8();if(!i||o===void 0)return;let s=new Set(e.map(e=>e.id)),c=o.outputs.flatMap(e=>s.has(e.output.id)&&e.workKey.startsWith(`image:`)?[e.workKey]:[]);if(c.length!==0)return{count:c.length,asking:n,act:()=>r(!0),confirm:()=>{r(!1),a?.(c)},dismiss:()=>r(!1),unavailable:t||a===void 0}}var rye=200,iye=Y({seconds:q(),peaks:J(q())});function aye(e){if(e===void 0)return;let t;try{t=new URL(e,window.location.href)}catch{return}if(t.pathname.startsWith(`/files/`))return t.searchParams.set(`waveform`,String(rye)),t.toString()}function oye(e){let{api:t}=V(),n=aye(e);return I({queryKey:[`waveform`,n],enabled:n!==void 0,staleTime:1/0,retry:!1,queryFn:async()=>{if(n===void 0)return[];let e=await t.fetch(n);if(!e.ok)throw lo(e,void 0);let{peaks:r}=yo(iye,await e.json()),i=Math.max(0,...r);return i===0?[]:r.map(e=>e/i)}}).data}function Y8(e){return(0,h.jsx)(H8,{...e,waveform:oye(e.src)})}var X8=[{role:`audio_intro`,segment:`intro`,name:`Intro`},{role:`audio_body`,segment:`body`,name:`Body`},{role:`audio_outro`,segment:`outro`,name:`Outro`}];function sye({stage:e,project:t,outputs:n,busy:r}){let{api:i}=V(),a=I(fb(i)),o=j8(t.id),s=c8(n,e),c=s.filter(e=>e.role===`audio_levelled`),l=X8.flatMap(e=>{let t=l8(s,e.role),n=c.find(t=>t.meta.segment===e.segment)??t;return n===void 0?[]:[{...e,output:n,...t===void 0||t===n?{}:{plain:t}}]}),u=X8.flatMap(e=>{let t=c.find(t=>t.meta.segment===e.segment)?.meta.loudness;return t===void 0?[]:[{name:e.name,report:t}]}),d=l.find(e=>e.output.meta.voice!==void 0)?.output.meta,f=l.length>0?d?.voice:t.config.audio?.voice,p=l.length>0?d?.provider:t.config.audio?.provider,m=a.data?.voices.find(e=>e.voiceId===f&&e.provider===p)?.name??f;return(0,h.jsxs)(b8,{children:[e.state===`running`?(0,h.jsx)(U8,{projectId:t.id}):null,l.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No narration has landed yet.`}):l.map(e=>(0,h.jsx)(cye,{name:e.name,output:e.output,...e.plain===void 0?{}:{plain:e.plain}},e.role)),(0,h.jsx)(E8,{files:Wve(s,l,n.find(e=>e.role===`script_md`))}),u.length===0?null:(0,h.jsx)(D8,{children:u.map(({name:e,report:t})=>u.length===1?sk(t):`${e}: ${sk(t)}`).join(` `)}),(0,h.jsxs)(B8,{label:`How it was recorded`,children:[m===void 0?null:(0,h.jsx)(V8,{label:`Voice`,children:m}),(0,h.jsx)(V8,{label:`Chunking`,children:lye(uye(t.config.chunking))}),Kve(s)?(0,h.jsx)(V8,{label:`Text files`,children:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Clean narration is the spoken text used for captions. The TTS script adds delivery cues, with a blank line between requests. Uploaded audio has no TTS request.`})}):null]}),(0,h.jsx)(I8,{review:M8(o,{itemKey:`narration`}),projectId:t.id,busy:r}),(0,h.jsx)(tye,{outputs:s})]})}function cye({name:e,output:t,plain:n}){let r=g8(t),i=q8(t),a=q8(n)||n===void 0?void 0:n,o=g8(i?a:void 0);return(0,h.jsxs)(`div`,{className:`grid grid-cols-[64px_minmax(0,1fr)] items-center gap-3 text-small`,children:[(0,h.jsx)(x8,{children:e}),(0,h.jsx)(Y8,{label:`${e} narration`,src:r?.url,className:`max-w-[640px]`}),i?(0,h.jsx)(`p`,{className:`col-start-2 m-0 text-small text-ink-2`,children:a===void 0?`Outdated: this is the narration from before your last change. The new one is made when the run carries on: press Continue the run, or Remake at the top of the page.`:`Outdated: this is the levelled narration from before your last change. The new narration is below as it was spoken; it is levelled when the run carries on: press Continue the run, or Remake at the top of the page.`}):null,i&&a!==void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x8,{children:`New`}),(0,h.jsx)(Y8,{label:`${e} narration, new, before levelling`,src:o?.url,className:`max-w-[640px]`})]}):null]})}function lye(e){return e.charAt(0).toUpperCase()+e.slice(1)}function uye(e){return e===void 0||e.mode===`whole`?`the whole text as one request`:e.mode===`paragraph`?`one request per paragraph`:e.mode===`characters`?`every ${String(e.characters??3e3)} characters`:`every ${String(e.words??500)} words`}function dye({stage:e,project:t,outputs:n}){let r=l8(c8(n,e),`document_pdf`),i=g8(r),a=sC(t.config.document);return(0,h.jsxs)(b8,{children:[r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The PDF will be saved when rendering finishes.`:`No PDF has been saved yet.`}):(0,h.jsx)(E8,{files:[{output:r,label:`PDF`}],label:`Download PDF`,children:i?.folder?(0,h.jsxs)(TS,{href:`${i.url}?inline=1`,target:`_blank`,rel:`noopener`,variant:`secondary`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open PDF`]}):null}),(0,h.jsx)(B8,{label:`PDF details`,children:(0,h.jsx)(V8,{label:`Theme`,children:a})})]})}var fye={research:`Generates fresh research and affected article, narration, entries, thumbnail and exports; previous outputs stay in History.`,article:`Generates a fresh article and affected narration, entries, thumbnail and exports; previous outputs stay in History.`,audio:`Regenerates narration and affected exports, keeping compatible cue preparation; previous outputs stay in History.`,images:`Regenerates generated images and affected video, keeping supplied images and narration; previous outputs stay in History.`,thumbnail:`Regenerates the thumbnail without changing the main video; previous outputs stay in History.`,video:`Rebuilds local exports from saved media without regenerating narration or images; previous outputs stay in History.`,document:`Renders the PDF again from the saved article and title without regenerating anything else; previous outputs stay in History.`};function Z8(e){switch(e.kind){case`cancel`:return{title:`Cancel this run?`,consequence:`Stops every running stage; finished outputs are kept.`,verb:`Cancel run`,dismiss:`Keep running`};case`rerun`:return{title:`Re-run this stage?`,consequence:fye[e.stage],verb:`Re-run`,dismiss:`Cancel`};case`delete-image`:return{title:`Delete this image?`,consequence:`Removes the image and re-renders video when enabled.`,verb:`Delete`,dismiss:`Cancel`};case`regenerate-image`:return e.thumbnail?{title:`Regenerate this thumbnail?`,consequence:`Makes a new thumbnail, one paid image call. The video and shorts are not touched; the PDF's cover follows the first thumbnail. The old one stays in History.`,verb:`Regenerate`,dismiss:`Cancel`}:{title:`Regenerate this image?`,consequence:e.now?`Makes a new image now, one paid image call. The video keeps the current one until you remake it; the old image stays in History.`:`Replaces the image with a new one and re-renders video when enabled.`,verb:`Regenerate`,dismiss:`Cancel`};case`save-article`:return{title:`Save the edited article?`,consequence:`Replaces the article, then updates the enabled narration and final export.`,verb:`Save & update outputs`,dismiss:`Cancel`};case`discard-article`:return{title:`Discard these edits?`,consequence:`The article goes back to the text on disk.`,verb:`Discard`,dismiss:`Keep editing`}}}function pye(e,t){let{config:n,content:r,fingerprints:i}=e.revision;switch(t){case`research`:return n.sources.research===`generate`;case`article`:return n.sources.article===`generate`&&!r.articleEdited;case`audio`:return n.sources.audio===`generate`&&Object.keys(i).some(e=>!/^audio:(body:.+|intro|outro):[0-9]+$/.test(e)&&!/^audio:(body|intro|outro):future$/.test(e)?!1:!Object.entries(r.narrationOverrides).some(([t,n])=>n.kind===`asset`&&(e===t||e.startsWith(`${t}:`))));case`images`:return n.sources.images!==`off`&&r.imageOrder.some(e=>r.imageDefinitions[e]?.source===`generate`);case`thumbnail`:return n.sources.thumbnail===`from_prompt`||n.sources.thumbnail===`prompt_by_llm`;case`video`:return n.sources.video!==`off`||n.sources.audio!==`off`;case`document`:return YS(n.sources,`document`)===`generate`}}function Q8(e){switch(e){case`research`:case`article`:return`article`;case`audio`:return`narration`;case`images`:case`thumbnail`:return`images`;case`video`:return`video`;case`document`:return`document`}}var $8={research:`Research`,article:`Article`,audio:`Narration`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`PDF`},e5=e=>/^[A-Z]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1);function mye(e){let{project:t,stages:n}=e,r=t.config,i=e=>e===`video`&&XP(r)===`audio`?`Audio export`:$8[e];if(e.sample)return{situation:`sample`,tone:`info`,status:`Sample project`,title:`This is the sample project, finished and free to explore.`,why:`It is read-only. Your own copy can be edited and made again.`,action:{label:`Make my own copy`,intent:{kind:`copy-sample`}}};if(t.status===`paused`){let t=yye(e.outdated);return{situation:`paused`,tone:`waiting`,status:`Paused`,title:`The run is paused.`,why:t===void 0?`Everything made so far is kept. Continuing picks up where it stopped.`:`Everything made so far is kept. Still to make: ${t}. They stay outdated until you continue.`,action:{label:`Continue the run`,intent:{kind:`resume`}}}}let a=n.find(e=>e.state===`failed`&&e.retryAt===void 0);if(a!==void 0){let t=i(a.kind),n=e.fixOf(a),r={label:`Try ${e5(t5(t))} again`,intent:{kind:`retry`,stage:a.kind}},o={situation:`failed`,tone:`failed`,status:`Failed`,section:Q8(a.kind),...a.failureReason===null?{}:{detail:a.failureReason}};switch(n?.kind){case`sign-in`:return{...o,title:`${n.label.replace(/^Sign in to /,``)} is signed out, so ${e5(t5(t))} stopped.`,why:`Copy the sign-in command (${n.command}), run it in a terminal on the computer running Slopify and sign in, then press Check again. Once ${n.label.replace(/^Sign in to /,``)} is signed in, Slopify tries ${e5(t5(t))} again.`,action:{label:`Copy sign-in command`,intent:{kind:`sign-in`,stage:a.kind,fix:n}}};case`refused`:return{...o,title:`A content filter refused a prompt, so ${e5(t5(t))} stopped.`,why:n.soften?`Softening rewrites each refused prompt without what the filter flagged, then draws it again.`:`Change the prompt in the project settings, then try again.`,action:n.soften?{label:n.label,intent:{kind:`soften`,stage:a.kind}}:{label:`Edit the prompt`,intent:{kind:`edit`}}};case`switch-model`:return{...o,title:`The model for ${e5(t5(t))} is no longer offered.`,why:`Pick another model in the project settings, then try again.`,action:{label:`Switch model`,intent:{kind:`edit`}}};case`provider-settings`:return{...o,title:`The provider did not accept its key, so ${e5(t5(t))} stopped.`,why:`Check the key in Settings, then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`providers`}}};case`free-space`:return{...o,title:`The disk is full, so ${e5(t5(t))} stopped.`,why:`Storage in Settings shows what can go. Then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`storage`}}};case void 0:return{...o,title:`${t} stopped with an error.`,why:`Trying again keeps everything already made.`,action:r}}}let o=e.held[0];if(o!==void 0){let e=i(o.stage);return{situation:`held`,tone:`waiting`,status:`Waiting for you`,title:`The ${e5(e)} ${_ye(e)} ready for your review.`,why:o.dependents.length===0?`Approving marks it reviewed.`:`Approving lets ${n5(o.dependents.map(e=>e5(t5(i(e)))))} run. Nothing after it runs until you do.`,action:{label:hye(o,i),intent:{kind:`approve`,gate:o}},section:Q8(o.stage)}}let s=n.find(e=>e.state===`failed`&&e.retryAt!==void 0),c=e.waits[0];if(c!==void 0||s!==void 0){if(c!==void 0){let t=_H(e.waits);return{situation:`waiting`,tone:`waiting`,status:`Waiting for limits`,title:`${gH(e.waits,e.clock)??``}.`,why:`Nothing to do: the run carries on by itself when they reset, and work that does not need ${t} keeps going.`,section:Q8(c.stage)}}if(s!==void 0)return{situation:`waiting`,tone:`waiting`,status:`Waiting to try again`,title:`${i(s.kind)} will try again by itself at ${e.clock(s.retryAt??``)}.`,why:`Nothing to do: the run carries on when it does.`,section:Q8(s.kind),...s.failureReason===null?{}:{detail:s.failureReason}}}let l=n.find(e=>e.state===`running`);if(t.status===`running`||l!==void 0)return{situation:`running`,tone:`running`,status:`Running`,title:l===void 0?`The run is starting.`:`Making the ${e5(i(l.kind))}${gye(l)}.`,why:`Pausing lets the current call finish and keeps everything made so far.`,action:{label:`Pause`,intent:{kind:`pause`}},...l===void 0?{}:{section:Q8(l.kind)}};if(t.status===`pending`&&t.setAside===!0)return e.uploadReady?{situation:`done`,tone:`done`,status:`Kept as is`,title:`The video is ready; what is left won't run.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them. Editing the project brings the rest back to Needs you.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}:{situation:`done`,tone:`done`,status:`Kept as is`,title:`Kept as is: what is left won't run.`,why:`Everything made is kept. Editing the project brings the rest back to Needs you.`};if(e.resumable||t.status===`canceled`||t.status===`failed`&&a===void 0)return{situation:`stopped`,tone:`off`,status:t.status===`canceled`?`Canceled`:`Stopped`,title:`The run stopped before it finished.`,why:`Continuing makes only what is missing; everything made so far is kept.`,action:{label:`Continue the run`,intent:{kind:`resume`}}};if(t.status===`pending`)return{situation:`queued`,tone:`off`,status:`Queued`,title:`Waiting for its turn.`,why:`It starts by itself when the videos ahead of it are done.`};let u=vye(e.outdated);if(u!==void 0)return{situation:`outdated`,tone:`info`,status:`Outdated`,title:u.count===1||u.singular?`The ${u.noun} ${u.noun.endsWith(`s`)?`are`:`is`} outdated after your edit.`:`${String(u.count)} ${u.plural} are outdated after your edit.`,why:`They keep their current version until you remake them. Nothing else is made again.`,action:{label:u.count===1||u.singular?`Remake the outdated ${u.noun}`:`Remake ${String(u.count)} outdated ${u.plural}`,intent:{kind:`remake`,workKeys:u.workKeys}},section:u.section};if(t.status===`done`&&r.mode===`short`)return{situation:`done`,tone:`done`,status:`Done`,title:`The short is ready.`,why:`Play opens set up for a long video on the same topic, with the same starter pack and providers. Nothing starts until you press Play.`,action:{label:`Make the full video on this topic`,intent:{kind:`full-video`}}};if((t.status===`done`||t.status===`partial`)&&e.uploadReady)return{situation:`done`,tone:`done`,status:`Done`,title:`The video is ready.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}}function hye(e,t){if(e.dependents.includes(`video`))return`Approve and render the video`;if(e.dependents.includes(`images`))return`Approve and make the images`;if(e.dependents.includes(`audio`))return`Approve and record the narration`;let n=e.dependents[0];return n===void 0?`Approve the ${e5(t(e.stage))}`:`Approve and make the ${e5(t(n))}`}function gye(e){let t=nF(e);return t===void 0?e.progressTotal===null||e.progressTotal<=0?``:` · ${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)}`:` · ${t}`}function t5(e){return/s$/i.test(e)?e:`the ${e5(e)}`}function _ye(e){return/s$/i.test(e)?`are`:`is`}function n5(e){return e.length<=1?e[0]??``:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`}var r5=[{id:`article`,noun:`article`,plural:`article files`,singular:!0,section:`article`,roles:[`notes`,`sources`,`article_md`,`article_txt`,`script_md`],counted:[`article_md`]},{id:`narration`,noun:`narration`,plural:`narration parts`,singular:!0,section:`narration`,roles:[`narration_txt`,`tts_script`,`glossary`,`audio_body`,`audio_intro`,`audio_outro`,`audio_levelled`],counted:[`audio_body`]},{id:`reference`,noun:`establishing image`,plural:`establishing images`,singular:!0,section:`images`,roles:[`reference`],counted:[`reference`]},{id:`images`,noun:`image`,plural:`images`,singular:!1,section:`images`,roles:[`image`],counted:[`image`]},{id:`animated`,noun:`animated image`,plural:`animated images`,singular:!1,section:`images`,roles:[`animated_image`],counted:[`animated_image`]},{id:`thumbnails`,noun:`thumbnail`,plural:`thumbnails`,singular:!1,section:`images`,roles:[`thumbnail`],counted:[`thumbnail`]},{id:`video`,noun:`video`,plural:`video files`,singular:!0,section:`video`,roles:[`video`,`audio_export`,`audio_mp3`,`audio_m4b`,`render_params`,`subtitles_srt`,`subtitles_vtt`,`subtitle_words`,`subtitle_ass`,`subtitle_font`],counted:[`video`,`audio_export`]},{id:`shorts`,noun:`short`,plural:`shorts`,singular:!1,section:`shorts`,roles:[`shorts`,`short_image`,`short_video`],counted:[`short_video`]},{id:`youtube`,noun:`YouTube description`,plural:`YouTube descriptions`,singular:!0,section:`youtube`,roles:[`youtube_description`,`youtube_tags`,`youtube_pinned_comment`,`youtube_titles`],counted:[`youtube_description`]},{id:`document`,noun:`PDF`,plural:`PDFs`,singular:!0,section:`document`,roles:[`document_pdf`],counted:[`document_pdf`]}];function vye(e){for(let t of r5){let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)continue;let r=n.filter(e=>t.counted.includes(e.role)).length;return{noun:t.noun,plural:t.plural,singular:t.singular,count:Math.max(1,r),workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section}}}function yye(e){let t=r5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[t.singular?`the ${t.noun}`:r===1?`1 ${t.noun}`:`${String(r)} ${t.plural}`]});return t.length===0?void 0:n5(t)}function bye(e){return r5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[{label:r===1||t.singular?`Remake the outdated ${t.noun}`:`Remake ${String(r)} outdated ${t.plural}`,workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section,count:r}]})}function xye({tone:e,status:t,title:n,why:r,action:i,className:a}){return(0,h.jsxs)(`section`,{"aria-label":`Next action`,className:z(`sl-next`,a),children:[(0,h.jsx)(OS,{tone:e,children:t}),(0,h.jsx)(`p`,{className:`sl-next__title`,children:n}),r===void 0?null:(0,h.jsx)(`p`,{className:`sl-next__why`,children:r}),i===void 0?null:(0,h.jsx)(`div`,{className:`flex flex-col [&>*]:w-full`,children:i})]})}function Sye({project:e,stages:t,resumable:n,sample:r,gates:i,outdated:a,waits:o,uploadReady:s,actions:c,controller:l,openSection:u,openUpload:d}){let{api:f}=V(),p=_(),h=Ji(),[g,v]=(0,m.useState)(),y=(0,m.useRef)(new Map),b=mye({project:e,stages:t,resumable:n,sample:r,held:i.filter(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint).map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),outdated:a,waits:o,uploadReady:s,fixOf:t=>p3(t,e),clock:aF}),x=L({mutationFn:()=>tb(f,e.id),onSuccess:async({projectId:e})=>{await p.invalidateQueries({queryKey:H.projects}),await h({to:`/projects/$projectId`,params:{projectId:e}})},onError:e=>v(`${_o(e.message)} The copy was not made. Press Make my own copy to try again.`)}),S=(0,m.useRef)(null),C=YN(),w=L({mutationFn:async()=>{if(C===null)throw Error(`Play isn't available on this page. Reload the page`);if(C.review.starting||C.review.uncertain||C.review.created!==null)throw Error(`Play is starting a run from its open draft. Wait for it to start`);if(!await C.flush())throw Error(`The draft open in Play couldn't be saved. Open Play, save or discard it`);S.current??=crypto.randomUUID();let{draft:t}=await Zy(f,{projectId:e.id,draftId:S.current});if(await p.invalidateQueries({queryKey:[`play-drafts`]}),!await C.open(t.id))throw Error(`The full video's draft was made but didn't open. Open Play and pick it`);S.current=null,await h({to:`/play`})},onError:e=>v(`${_o(e.message)} Then press Make the full video on this topic again.`)}),T=L({mutationFn:async t=>{let n=i.find(e=>e.checkpointId===t.checkpointId);if(n===void 0)throw Error(`The review changed before it was approved. Reload the page.`);let r=`${n.checkpointId}:${n.fingerprint}`,a=y.current.get(r)??crypto.randomUUID();y.current.set(r,a);let o=await d3(f,e.id,n.checkpointId,{revisionId:n.revisionId,fingerprint:n.fingerprint,idempotencyKey:a});if(y.current.delete(r),!o.ok)throw Error(o.message)},onSettled:async()=>{await p.invalidateQueries({queryKey:s3(e.id)}),await p.invalidateQueries({queryKey:H.project(e.id)}),p.invalidateQueries({queryKey:H.projects})},onError:e=>v(`${_o(e.message)} Press the approve button again to check whether it went through.`)});return{next:b,run:e=>{switch(v(void 0),e.kind){case`copy-sample`:x.mutate();return;case`resume`:case`pause`:c.run({kind:e.kind});return;case`retry`:case`soften`:c.run({kind:e.kind,stage:e.stage});return;case`sign-in`:p1(e.fix.command).then(t=>v(t?`Copied ${e.fix.command}. Run it in a terminal on the computer running Slopify, sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.fix.command} in a terminal, sign in, then press Check again.`));return;case`approve`:T.mutate(e.gate);return;case`remake`:l.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0});return;case`edit`:u(`settings`);return;case`open-settings`:h({to:`/settings`,search:{section:e.section}});return;case`prepare-upload`:d();return;case`full-video`:w.mutate();return}},pending:x.isPending||w.isPending||T.isPending||c.pending||l.pending,message:g}}function Cye(e){switch(e.kind){case`copy-sample`:return`Copying…`;case`resume`:return`Continuing…`;case`pause`:return`Pausing…`;case`approve`:return`Approving…`;case`remake`:return`Starting the remake…`;case`retry`:return`Trying again…`;case`soften`:return`Softening…`;case`full-video`:return`Opening Play…`;default:return}}function i5({state:e,variant:t,className:n}){let[r,i]=(0,m.useState)(!1),a=e.next?.action;if(a===void 0)return null;let o=a.intent;if(o.kind===`sign-in`)return(0,h.jsx)(m1,{fix:o.fix,variant:t,retry:{run:()=>e.run({kind:`retry`,stage:o.stage}),busy:e.pending}});if(o.kind===`open-settings`)return(0,h.jsx)(CS,{to:`/settings`,search:{section:o.section},variant:t,...n===void 0?{}:{className:n},children:a.label});let s=e.pending?Cye(o)??a.label:a.label;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:t,className:n,disabled:e.pending,disabledReason:`Working on the last press`,"aria-keyshortcuts":t===`primary`?Ux(nP.nextAction):void 0,onClick:()=>o.kind===`soften`?i(!0):e.run(o),children:s}),o.kind===`soften`?(0,h.jsx)(Hy,{open:r,tone:`primary`,title:`Soften the refused prompt and try again?`,consequence:`Your project's AI model rewrites each refused prompt without what a content filter could flag, keeping the scene and style. The image is then drawn again from the new wording, which it keeps as its prompt. The AI call and the new image are charged like any other.`,confirmLabel:`Soften and retry`,cancelLabel:`Keep the prompt`,pending:e.pending,onConfirm:()=>{i(!1),e.run(o)},onCancel:()=>i(!1)}):null]})}function wye({state:e,feedback:t}){let n=e.next;return n===void 0&&t===void 0&&e.message===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n===void 0?null:(0,h.jsx)(xye,{tone:n.tone,status:n.status,title:n.title,...n.why===void 0?{}:{why:n.why},...n.action===void 0?{}:{action:(0,h.jsx)(i5,{state:e,variant:`primary`})}}),e.message===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e.message}),t]})}var Tye={sample:void 0,paused:void 0,stopped:void 0,queued:void 0,running:void 0,failed:`danger`,held:`waiting`,waiting:`waiting`,outdated:`info`,done:void 0};function Eye({state:e,section:t}){let n=e.next;if(n===void 0||n.section!==t)return null;let r=Tye[n.situation];return r===void 0?null:(0,h.jsx)(aI,{className:`max-[1180px]:hidden`,tone:r,title:n.title,...n.action===void 0?{}:{actions:(0,h.jsx)(i5,{state:e,variant:`secondary`})},children:n.why===void 0&&n.detail===void 0?void 0:(0,h.jsxs)(h.Fragment,{children:[n.why===void 0?null:(0,h.jsx)(`span`,{className:`block`,children:n.why}),n.detail===void 0?null:(0,h.jsxs)(`details`,{className:`mt-1`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:n.detail})]})]})})}var Dye={research:`Research again`,article:`Write the article again`,audio:`Record the narration again`,images:`Make all images again`,thumbnail:`Make the thumbnails again`,video:`Render the video again`,document:`Render the PDF again`};function a5(e,t){return e===`video`&&t.config.sources.video===`off`?`Export the audio again`:Dye[e]}function o5({id:e,title:t,kicker:n,stages:r,project:i,outputs:a,actions:o,next:s,active:c,meta:l,head:u=!0,extra:d,resumable:f=!1,children:p}){let m=r[0],g=r.some(e=>o.refusal?.stage===e.kind)?o.refusal?.message:void 0,_=r.filter(t=>t.state===`failed`&&t.retryAt===void 0&&(s.next?.situation!==`failed`||s.next.section!==e)),v=r.find(e=>e.state===`running`),y=v===void 0?void 0:iF(v),b=l??(m===void 0?void 0:r.filter(e=>e.state!==`skipped`).map(e=>e===m?tF(e,a,i,f):`${$8[e.kind]}: ${tF(e,a,i,f)}`).join(` · `));return(0,h.jsxs)(`section`,{hidden:!c,"aria-label":t,"data-tour":m===void 0?void 0:`project-${m.kind}`,className:`flex min-w-0 flex-col gap-5`,children:[u?(0,h.jsxs)(W,{row:!0,title:t,...n===void 0?{}:{kicker:n},...b===void 0||b===``?{}:{meta:b},children:[d,(0,h.jsx)(c5,{stages:r,project:i,actions:o})]}):null,y===void 0||v===void 0?null:(0,h.jsx)(C2,{value:y,label:`${$8[v.kind]} progress`,valueText:tF(v,a,i,f)}),(0,h.jsx)(Eye,{state:s,section:e}),_.map(e=>(0,h.jsx)(aI,{tone:`danger`,title:`${$8[e.kind]} stopped with an error.`,children:e.failureReason===null?void 0:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.failureReason})]})},e.id)),g===void 0?null:(0,h.jsx)(aI,{tone:`danger`,title:g,actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:o.dismissRefusal,children:`Dismiss`})}),m?.state===`running`&&m.kind!==`article`&&m.kind!==`images`&&m.kind!==`video`&&m.kind!==`document`?(0,h.jsx)(D3,{projectId:i.id,stage:m.kind}):null,p]})}function s5({stage:e,project:t,name:n}){return e===void 0||e.state===`skipped`?(0,h.jsx)(T1,{title:`${n} is off for this run.`,children:`Switch it on in the project settings to make it.`}):(0,h.jsx)(T1,{title:`No ${n.toLowerCase()} yet.`,children:t.status===`paused`?`It is made once you continue the run.`:`It starts when the steps before it are done. Finished work elsewhere can be looked at meanwhile.`})}function c5({stages:e,project:t,actions:n}){let r=(0,m.useContext)(W8),i=h8(),[a,o]=(0,m.useState)(),s=e.filter(e=>e.state!==`skipped`&&e.state!==`pending`&&(!r||i!==void 0&&pye(i,e.kind)));if(s.length===0)return null;let c=n.pending||t.status===`running`||e.some(e=>e.state===`running`),l=a===void 0?void 0:Z8({kind:`rerun`,stage:a});return(0,h.jsxs)(h.Fragment,{children:[s.map(e=>(0,h.jsxs)(B,{size:`small`,disabled:c,disabledReason:`Wait until the work on this project is done`,onClick:()=>o(e.kind),children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),a5(e.kind,t)]},e.id)),(0,h.jsx)(Hy,{open:a!==void 0,title:a===void 0?``:`${a5(a,t)}?`,consequence:l?.consequence??``,confirmLabel:a===void 0?``:a5(a,t),cancelLabel:`Keep what is there`,pending:n.pending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&n.run({kind:`rerun`,stage:e})},onCancel:()=>o(void 0)})]})}function Oye({stage:e,project:t,outputs:n,actions:r,busy:i}){let a=c8(n,e),o=j8(t.id),s=QS(t.config),c=Array.from({length:s},(e,t)=>t+1).map(e=>({variant:e,output:a.find(t=>t.role===`thumbnail`&&(t.meta.index??1)===e)})),l=c.flatMap(e=>e.output===void 0?[]:[e.output]),u=_8(l),[d,f]=(0,m.useState)(null),p=l.filter(e=>u.has(e.id)),g=p.map(e=>({src:u.get(e.id)?.url??``,alt:`Thumbnail ${String(e.meta.index??1)}`})),_=t.format===`9:16`,v=({variant:n,output:a})=>(0,h.jsx)(kye,{variant:n,count:s,output:a,review:M8(o,{outputId:a?.id}),stage:e,project:t,actions:r,busy:i,onOpen:()=>f(a===void 0?null:Aye(p,a))},n);return(0,h.jsxs)(`section`,{"aria-label":s===1?`Thumbnail`:`Thumbnails`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(W,{title:s===1?`Thumbnail`:`Thumbnails`,meta:s===1?`The picture YouTube shows before the video plays`:`${String(s)} variants for YouTube's Test & compare`,children:[(0,h.jsx)(w8,{variant:`secondary`,files:l.map(e=>({output:e,label:s===1?`Thumbnail`:`Thumbnail ${String(e.meta.index??1)}`}))}),(0,h.jsx)(T8,{output:l[0]}),(0,h.jsx)(c5,{stages:[e],project:t,actions:r})]}),c.length===1?(0,h.jsx)(`div`,{className:_?`max-w-[280px]`:`max-w-[480px]`,children:c.map(v)}):(0,h.jsx)(u0,{list:!0,label:`Thumbnail variants`,children:c.map(e=>(0,h.jsx)(`li`,{className:`min-w-0`,children:v(e)},e.variant))}),(0,h.jsx)(d0,{items:g,index:d,onIndex:f,onClose:()=>f(null),actions:(e,t)=>{let n=p[t];return n===void 0?null:(0,h.jsx)(p5,{output:n,name:s===1?`the thumbnail`:`thumbnail ${String(n.meta.index??1)}`,actions:r,busy:i},n.id)}})]})}function kye({variant:e,count:t,output:n,review:r,stage:i,project:a,actions:o,busy:s,onOpen:c}){let l=g8(n),u=J8(n,o,s),d=t===1?`the thumbnail`:`thumbnail ${String(e)}`;jx({id:`project.thumbnail.${String(e)}`,title:t===1?`Regenerate the thumbnail`:`Regenerate thumbnail ${String(e)}`,group:`This project`,context:a.title,keywords:[`thumbnail`,`redraw`,`remake`],run:()=>u.act(`regenerate-image`)});let f=r!==void 0&&!r.passed&&r.action===null,p=String.fromCharCode(64+e),m=u.asking===void 0||n===void 0?void 0:Z8({kind:u.asking,outputId:n.id,now:u.now,thumbnail:!0});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(l0,{alt:t===1?`Thumbnail for ${a.title}`:`Thumbnail ${String(e)} for ${a.title}`,aspect:l5(a.format),...l===void 0?{}:{src:l.url},...n===void 0&&i.state===`running`?{generating:`Making the thumbnail`}:{},title:t===1?`Thumbnail`:p,...n===void 0?{meta:jye(i)}:{},onOpen:c,openLabel:`Open ${d} full size`,...r===void 0?{}:{badge:(0,h.jsx)(L8,{review:r})},actionsShown:f,...n===void 0?{}:{actions:(0,h.jsxs)(h.Fragment,{children:[f&&r!==void 0?(0,h.jsx)(F8,{review:r,projectId:a.id,busy:s}):null,(0,h.jsxs)(B,{size:`small`,disabled:u.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>u.act(`regenerate-image`),"aria-label":`Regenerate ${d}`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),l===void 0?null:(0,h.jsx)(m5,{href:l.url,label:`Download ${d}`})]})}}),(0,h.jsx)(Hy,{open:u.asking!==void 0,tone:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:`Regenerate the thumbnail`,cancelLabel:`Keep it`,pending:o.pending,onConfirm:u.confirm,onCancel:u.dismiss})]})}function Aye(e,t){let n=e.indexOf(t);return n===-1?null:n}function jye(e){switch(e.state){case`running`:return`Being made`;case`failed`:case`canceled`:return`Not made`;default:return`Not made yet`}}function Mye(e,t){let n=e.filter(e=>e.role===`image`),r=new Map;for(let e of n){let t=e.meta.promptName??`Images`;r.set(t,[...r.get(t)??[],e])}let i=t.filter(e=>r.has(e)),a=[...r.keys()].filter(e=>!i.includes(e)).sort();return[...i,...a].flatMap(e=>{let t=r.get(e);return t===void 0?[]:[{name:e,images:[...t].sort(Nye)}]})}function Nye(e,t){return(e.meta.index??0)-(t.meta.index??0)}function Pye(e,t,n,r,i){let a=Ry(),[o,s]=(0,m.useState)(),c=(r,i)=>{let o=r===`image`?t:n,c=r===`image`?`image`:`on-screen card`;if(i===void 0){a(`Type the ${c}'s number with the command, for example "regenerate ${c} 3".`);return}let l=o.find(e=>e.meta.index===i);if(l===void 0){let t=o.flatMap(e=>e.meta.index===void 0?[]:[e.meta.index]);a(t.length===0?`${e.title} has no ${c}s yet, so there is no ${c} ${String(i)} to regenerate. They appear under Images once the run makes them.`:`${e.title} has no ${c} ${String(i)}: its ${c}s are numbered ${String(Math.min(...t))} to ${String(Math.max(...t))}. Type one of those, or press Regenerate on the ${c} in Images.`,`error`);return}s(e=>({image:l,name:`${c[0]?.toUpperCase()??``}${c.slice(1)} ${String(i)}`,nonce:(e?.nonce??0)+1}))};return jx({id:`project.image.regenerate`,title:`Regenerate an image`,numbered:e=>`Regenerate image ${String(e)}`,group:`This project`,context:e.title,keywords:[`image`,`picture`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`image`,e)}),jx({id:`project.card.regenerate`,title:`Regenerate an on-screen card`,numbered:e=>`Regenerate on-screen card ${String(e)}`,group:`This project`,context:e.title,keywords:[`card`,`figure`,`table`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`card`,e)}),oS(tS.regenerateImage(e.id),e=>c(`image`,e)),o===void 0?null:(0,h.jsx)(Fye,{request:o,actions:r,busy:i},o.nonce)}function Fye({request:e,actions:t,busy:n}){let r=Ry(),i=J8(e.image,t,n),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a.current&&i.ready&&(a.current=!0,i.unavailable?r(`${e.name} can't be regenerated while work on this project is running. Wait until it finishes, then run the command again or press Regenerate on it in Images.`,`error`):i.act(`regenerate-image`))},[i,r,e.name]);let o=i.asking===void 0?void 0:Z8({kind:i.asking,outputId:e.image.id,now:i.now});return(0,h.jsx)(Hy,{open:i.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate the image`,cancelLabel:`Keep it`,pending:t.pending,onConfirm:i.confirm,onCancel:i.dismiss})}function l5(e){return e===`9:16`?`portrait`:e===`1:1`?`square`:`landscape`}function Iye({stage:e,companion:t,project:n,outputs:r,actions:i,busy:a}){let o=j8(n.id),s=c8(r,e),c=Mye(s,n.config.imagePrompts?.map(e=>e.name)??[]),l=c.flatMap(e=>e.images),u=s.filter(e=>e.role===`figure_card`&&(e.meta.format??n.format)===n.format).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),d=[...l,...u],f=Pye(n,l,u,i,a),p=nye(l,a),g=_8(d),[_,v]=(0,m.useState)(null),y=d.filter(e=>g.has(e.id)),b=y.map(e=>({src:g.get(e.id)?.url??``,alt:e.role===`figure_card`?`On-screen card ${String(e.meta.index??``)}`:e.meta.prompt??`Image ${String(e.meta.index??``)}`,...u5(e)?{kind:`video`}:{},caption:e.role===`figure_card`?`Shown while the narration describes it`:e.meta.prompt??e.meta.promptName??`Slideshow image`})),x=n.config.reference===void 0?null:(0,h.jsx)(Lye,{image:l8(s,`reference`),format:n.format,generated:n.config.reference.source===`prompt`,affected:l.length,actions:i,busy:a}),S=t?.kind===`thumbnail`?(0,h.jsx)(Oye,{stage:t,project:n,outputs:r,actions:i,busy:a}):null,C=e.state===`running`&&e.progressTotal!==null?Math.max(0,e.progressTotal-l.length):0,w=o.filter(e=>l.some(t=>t.id===e.outputId)),T=w.filter(e=>e.passed&&e.attempt>1).length,E=w.filter(e=>!e.passed&&e.action===null).length,D=[l.length===0?void 0:`${String(l.length)} in the video`,w.length===0?void 0:`reviewed`,T===0?void 0:`${String(T)} redone after review`,E===0?void 0:`${String(E)} flagged`].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(h.Fragment,{children:[f,x,x===null||S===null&&e.state===`skipped`?null:(0,h.jsx)($K,{className:`m-0`}),S,S===null||e.state===`skipped`?null:(0,h.jsx)($K,{className:`m-0`}),e.state===`skipped`?null:(0,h.jsxs)(`section`,{"aria-label":`Slideshow images`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(W,{title:`Images`,...D===``?{}:{meta:D},children:[p===void 0?null:(0,h.jsxs)(B,{size:`small`,disabled:p.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:p.act,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate all`]}),p===void 0?null:(0,h.jsx)(Hy,{open:p.asking,tone:`primary`,title:`Regenerate all ${String(p.count)} images?`,consequence:`Makes ${String(p.count)} new images now, one paid image call each. The video keeps the current ones until you remake it; the old images stay in History.`,confirmLabel:`Regenerate them`,cancelLabel:`Keep them`,pending:i.pending,onConfirm:p.confirm,onCancel:p.dismiss}),(0,h.jsx)(Ive,{projectId:n.id,asset:`images.zip`,label:`Download all`}),(0,h.jsx)(c5,{stages:[e],project:n,actions:i})]}),c.length===0&&C===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`pending`?`The images are made once the narration is timed.`:`No images have landed yet.`}):null,c.map((e,t)=>(0,h.jsx)(h5,{name:e.name,count:e.images.length,showName:c.length>1,trailing:t===c.length-1&&C>0?Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(l0,{alt:`An image being made`,aspect:l5(n.format),generating:t===0?`Drawing the next image`:`Waiting its turn`},t)):null,children:t=>e.images.slice(0,t).map(e=>(0,h.jsx)(g5,{image:e,projectId:n.id,review:M8(o,{outputId:e.id}),format:n.format,actions:i,busy:a,onOpen:()=>v(f5(y,e))},e.id))},e.name)),u.length===0?null:(0,h.jsx)(h5,{name:`From the article`,count:u.length,showName:!0,children:e=>u.slice(0,e).map(e=>(0,h.jsx)(g5,{image:e,projectId:n.id,review:void 0,format:n.format,actions:i,busy:a,card:!0,onOpen:()=>v(f5(y,e))},e.id))}),c.length===0&&C>0?(0,h.jsx)(u0,{label:`Images being made`,children:Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(l0,{alt:`An image being made`,aspect:l5(n.format),generating:t===0?`Drawing the first image`:`Waiting its turn`},t))}):null,(0,h.jsx)(d0,{items:b,index:_,onIndex:v,onClose:()=>v(null),actions:(e,t)=>{let n=y[t];return n===void 0?null:(0,h.jsx)(p5,{output:n,name:n.role===`figure_card`?`on-screen card${d5(n)}`:`image${d5(n)}`,actions:i,busy:a},n.id)}})]})]})}var u5=e=>/\.(mp4|mov|m4v|webm|mkv)$/i.test(e.path),d5=e=>e.meta.index===void 0?``:` ${String(e.meta.index)}`;function f5(e,t){let n=e.indexOf(t);return n===-1?null:n}function p5({output:e,name:t,actions:n,busy:r}){let i=g8(e),a=J8(e,n,r),o=a.asking===void 0?void 0:Z8({kind:a.asking,outputId:e.id,now:a.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(B,{size:`small`,disabled:a.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>a.act(`regenerate-image`),"aria-label":`Regenerate ${t}`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),i===void 0?null:(0,h.jsx)(m5,{href:i.url,label:`Download ${t}`}),(0,h.jsx)(Hy,{open:a.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate it`,cancelLabel:`Keep it`,pending:n.pending,onConfirm:a.confirm,onCancel:a.dismiss})]})}function m5({href:e,label:t,text:n}){return(0,h.jsxs)(TS,{href:e,download:!0,"aria-label":t,title:t,size:`small`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),n]})}function Lye({image:e,format:t,generated:n,affected:r,actions:i,busy:a}){let o=g8(e),s=J8(e,i,a),[c,l]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Establishing image`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(W,{kicker:`Reference · not in the video`,title:`Establishing image`,meta:`Every image follows it for the look, palette and style`,children:e!==void 0&&n?(0,h.jsx)(B,{disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.act(`regenerate-image`),children:`Make the establishing image again`}):null}),(0,h.jsx)(l0,{className:`w-full max-w-[360px]`,alt:e?.meta.prompt??`Establishing image`,aspect:l5(t),...o===void 0?{}:{src:o.url},title:`Establishing image`,...e===void 0?{meta:`Not made yet`}:{},onOpen:()=>l(0),openLabel:`Open the establishing image full size`,...e===void 0||o===void 0?{}:{actions:(0,h.jsx)(m5,{href:o.url,label:`Download the establishing image`,text:`Download`})}}),n&&r>0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Making it again marks ${String(r)} image${r===1?``:`s`} outdated. They keep their current version until you remake them.`}):null,(0,h.jsx)(d0,{items:o===void 0?[]:[{src:o.url,alt:`Establishing image`,caption:e?.meta.prompt??`The reference every image follows`}],index:c,onIndex:l,onClose:()=>l(null),actions:()=>o===void 0?null:(0,h.jsxs)(h.Fragment,{children:[n?(0,h.jsxs)(B,{size:`small`,disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>{l(null),s.act(`regenerate-image`)},"aria-label":`Make the establishing image again`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}):null,(0,h.jsx)(m5,{href:o.url,label:`Download the establishing image`})]})}),(0,h.jsx)(Hy,{open:s.asking!==void 0,tone:`primary`,title:`Make the establishing image again?`,consequence:`A new establishing image replaces this one${r>0?`, and the ${String(r)} images drawn from it become outdated until you remake them`:``}. The old one stays in History.`,confirmLabel:`Make it again`,cancelLabel:`Keep this one`,pending:i.pending,onConfirm:s.confirm,onCancel:s.dismiss})]})}function h5({name:e,count:t,showName:n,trailing:r,children:i}){let[a,o]=(0,m.useState)(!1),s=t>12&&!a;return(0,h.jsxs)(`section`,{"aria-label":`${e} × ${String(t)}`,className:`flex flex-col gap-3`,children:[n?(0,h.jsx)(`h3`,{className:`sl-kicker m-0`,children:`${e} × ${String(t)}`}):null,(0,h.jsxs)(u0,{children:[i(s?12:t),r]}),t>12?(0,h.jsx)(B,{variant:`quiet`,"aria-expanded":a,className:`self-start`,onClick:()=>o(e=>!e),children:a?`Show fewer`:`Show all ${String(t)} images`}):null]})}function g5({image:e,projectId:t,review:n,format:r,actions:i,busy:a,card:o=!1,onOpen:s}){let c=g8(e),l=d5(e),u=o?`on-screen card${l}`:`image${l}`,d=J8(e,i,a),f=q8(e),p=n!==void 0&&!n.passed&&n.action===null,m=d.asking===void 0?void 0:Z8({kind:d.asking,outputId:e.id,now:d.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(l0,{alt:o?`On-screen card${l}`:e.meta.prompt??`Slideshow ${u}`,kind:u5(e)?`video`:`image`,aspect:l5(r),...c===void 0?{}:{src:c.url},title:o?`Card${l}`:e.meta.prompt??`Image${l}`,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`},onOpen:s,openLabel:`Open ${u} full size`,...n===void 0&&!f?{}:{badge:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap gap-1`,children:[f?(0,h.jsx)(kS,{tone:`info`,children:`Outdated`}):null,n===void 0?null:(0,h.jsx)(L8,{review:n})]})},actionsShown:p,actions:(0,h.jsxs)(h.Fragment,{children:[p&&n!==void 0?(0,h.jsx)(F8,{review:n,projectId:t,busy:a}):null,(0,h.jsxs)(B,{size:`small`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`regenerate-image`),"aria-label":`Regenerate ${u}`,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),c===void 0?null:(0,h.jsx)(m5,{href:c.url,label:`Download ${u}`}),o?null:(0,h.jsx)(B,{size:`small`,variant:`destructive`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`delete-image`),"aria-label":`Delete ${u}`,title:`Delete ${u}`,children:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75})})]})}),(0,h.jsx)(Hy,{open:d.asking!==void 0,tone:d.asking===`delete-image`?`destructive`:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:d.asking===`delete-image`?`Delete the image`:`Regenerate the image`,cancelLabel:`Keep it`,pending:i.pending,onConfirm:d.confirm,onCancel:d.dismiss})]})}function _5(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function v5(e){let t=/^(?:(\d+):)?(\d{1,2}):(\d{2})$/.exec(e.trim());if(t===null)return;let n=Number(t[1]??`0`),r=Number(t[2]),i=Number(t[3]);if(!(i>59||t[1]!==void 0&&r>59))return n*3600+r*60+i}function Rye(e){let t=e.trim(),n=/^(\S+)\s+(.+)$/u.exec(t);if(n===null)return;let r=v5(n[1]??``),i=(n[2]??``).trim();return r===void 0||i===``?void 0:{start:r,title:i}}function y5(e,t){let n=e.replace(/\r\n?/gu,`
292
292
  `).split(`
293
- `),r=[],i=[];for(let[e,t]of n.entries()){let n=Iye(t);n!==void 0&&(r.push(e),i.push(n))}if(i.length===0)return{text:e,adjustments:[]};let a=[],o=e=>`"${e.title}"`,s=[...i].sort((e,t)=>e.start-t.start);s.some((e,t)=>e!==i[t])&&a.push(`put the chapters in time order`);let c=[];for(let e of s){let t=c.at(-1);t!==void 0&&t.start===e.start?a.push(`merged ${o(e)} (0 s) into ${o(t)}`):c.push(e)}s=c;let l=t!==void 0&&Number.isFinite(t)&&t>0?t:void 0;if(l!==void 0){let e=s.filter((e,t)=>t>0&&e.start>=l);for(let t of e)a.push(`removed ${o(t)} (${_5(t.start)}), which starts after the video ends at ${_5(l)}`);s=s.filter(t=>!e.includes(t))}let u=s[0];u!==void 0&&u.start!==0&&(a.push(`moved the first, ${o(u)}, from ${_5(u.start)} to 0:00`),s=[{start:0,title:u.title},...s.slice(1)]);let d=e=>{let t=s[e+1],n=s[e]?.start??0;return t===void 0?l===void 0?1/0:l-n:t.start-n},f=e=>`${String(Math.max(0,Math.floor(e)))} s`;for(;s.length>1;){let e=s.findIndex((e,t)=>d(t)<10);if(e===-1)break;let t=s[e];if(t===void 0)break;let n=f(d(e));if(e===0){let e=s[1];if(e===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(e)}`),s=[{start:0,title:e.title},...s.slice(2)]}else{let r=s[e-1];if(r===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(r)}`),s=s.filter((t,n)=>n!==e)}}if(s.length<3&&(a.push(`left the chapter list out, since YouTube needs at least 3 chapters of 10 s or more and only ${String(s.length)} ${s.length===1?`is`:`are`} left`),s=[]),a.length===0)return{text:e,adjustments:a};let p=new Map(r.map((e,t)=>[e,s[t]]));return{text:n.flatMap((e,t)=>{if(!p.has(t))return[e];let n=p.get(t);return n===void 0?[]:[`${_5(n.start)} ${n.title}`]}).join(`
294
- `).trim(),adjustments:a}}function Lye(e){return e.length===0?void 0:`Chapters adjusted for YouTube: ${e.join(`; `)}.`}function b5(e,t,n={}){let r=e.replace(/\r\n?/gu,`
293
+ `),r=[],i=[];for(let[e,t]of n.entries()){let n=Rye(t);n!==void 0&&(r.push(e),i.push(n))}if(i.length===0)return{text:e,adjustments:[]};let a=[],o=e=>`"${e.title}"`,s=[...i].sort((e,t)=>e.start-t.start);s.some((e,t)=>e!==i[t])&&a.push(`put the chapters in time order`);let c=[];for(let e of s){let t=c.at(-1);t!==void 0&&t.start===e.start?a.push(`merged ${o(e)} (0 s) into ${o(t)}`):c.push(e)}s=c;let l=t!==void 0&&Number.isFinite(t)&&t>0?t:void 0;if(l!==void 0){let e=s.filter((e,t)=>t>0&&e.start>=l);for(let t of e)a.push(`removed ${o(t)} (${_5(t.start)}), which starts after the video ends at ${_5(l)}`);s=s.filter(t=>!e.includes(t))}let u=s[0];u!==void 0&&u.start!==0&&(a.push(`moved the first, ${o(u)}, from ${_5(u.start)} to 0:00`),s=[{start:0,title:u.title},...s.slice(1)]);let d=e=>{let t=s[e+1],n=s[e]?.start??0;return t===void 0?l===void 0?1/0:l-n:t.start-n},f=e=>`${String(Math.max(0,Math.floor(e)))} s`;for(;s.length>1;){let e=s.findIndex((e,t)=>d(t)<10);if(e===-1)break;let t=s[e];if(t===void 0)break;let n=f(d(e));if(e===0){let e=s[1];if(e===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(e)}`),s=[{start:0,title:e.title},...s.slice(2)]}else{let r=s[e-1];if(r===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(r)}`),s=s.filter((t,n)=>n!==e)}}if(s.length<3&&(a.push(`left the chapter list out, since YouTube needs at least 3 chapters of 10 s or more and only ${String(s.length)} ${s.length===1?`is`:`are`} left`),s=[]),a.length===0)return{text:e,adjustments:a};let p=new Map(r.map((e,t)=>[e,s[t]]));return{text:n.flatMap((e,t)=>{if(!p.has(t))return[e];let n=p.get(t);return n===void 0?[]:[`${_5(n.start)} ${n.title}`]}).join(`
294
+ `).trim(),adjustments:a}}function zye(e){return e.length===0?void 0:`Chapters adjusted for YouTube: ${e.join(`; `)}.`}function b5(e,t,n={}){let r=e.replace(/\r\n?/gu,`
295
295
  `).split(`
296
- `);for(;r.length>0&&r.at(-1)?.trim()===``;)r.pop();let i=``,a=r.at(-1)?.trim()??``;for(a!==``&&a.split(/\s+/u).every(e=>/^#[\p{L}\p{N}_]+$/u.test(e))&&(i=a,r.pop());r.length>0&&r.at(-1)?.trim()===``;)r.pop();let o=[];for(;r.length>0&&Rye(r.at(-1)??``);)o.unshift((r.pop()??``).trim());return{summary:r.join(`
296
+ `);for(;r.length>0&&r.at(-1)?.trim()===``;)r.pop();let i=``,a=r.at(-1)?.trim()??``;for(a!==``&&a.split(/\s+/u).every(e=>/^#[\p{L}\p{N}_]+$/u.test(e))&&(i=a,r.pop());r.length>0&&r.at(-1)?.trim()===``;)r.pop();let o=[];for(;r.length>0&&Bye(r.at(-1)??``);)o.unshift((r.pop()??``).trim());return{summary:r.join(`
297
297
  `).trim(),chapters:o.join(`
298
- `),hashtags:i,tags:t.trim(),pinnedComment:(n.pinnedComment??``).trim(),titles:(n.titles??``).trim()}}function Rye(e){let[t=``,...n]=e.trim().split(/\s+/u);return v5(t)!==void 0&&n.length>0}function zye(e){return[e.summary.trim(),e.chapters.trim(),e.hashtags.trim()].filter(e=>e!==``).join(`
298
+ `),hashtags:i,tags:t.trim(),pinnedComment:(n.pinnedComment??``).trim(),titles:(n.titles??``).trim()}}function Bye(e){let[t=``,...n]=e.trim().split(/\s+/u);return v5(t)!==void 0&&n.length>0}function Vye(e){return[e.summary.trim(),e.chapters.trim(),e.hashtags.trim()].filter(e=>e!==``).join(`
299
299
 
300
- `)}function Bye(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function x5(e,t){let n=n=>Bye(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function S5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}function Vye(e,t,n,r){return`https://studio.youtube.com/video/${e}/edit#slopify-ab=${t}&p=${encodeURIComponent(n)}&s=${String(r??0)}`}var C5=e=>[`project`,e,`youtube-videos`];function w5(e){let{api:t}=V();return I({queryKey:C5(e),queryFn:()=>ws(t,e)})}function Hye(e){let t=e?.find(e=>e.short===null&&e.uploadState===`done`);return t===void 0?void 0:`https://youtu.be/${t.videoId}`}function Uye(e){return e===null?`Video`:`Short ${String(e)}`}function Wye(e){if(e.uploadState===`filled`)return`Filled in Studio, but not scheduled or published yet (cancelled, or left as a draft). Upload it again from the extension, or paste its link once it is up.`;let t=[`On YouTube.`];return e.finishState===`waiting`&&t.push(`Related video, end screen and captions are being set.`),e.finishState===`failed`&&t.push(`Details touches failed: ${e.finishMessage??`no reason given`}`),e.commentState===`waiting`&&t.push(`The comment is pinned once it is public.`),e.commentState===`done`&&t.push(`Comment pinned.`),e.commentState===`failed`&&t.push(`Pinning the comment failed: ${e.commentMessage??`no reason given`}`),t.join(` `)}function Gye({projectId:e,shorts:t}){let n=w5(e),{api:r}=V(),i=I({queryKey:[`project`,e,`youtube-stats`],queryFn:()=>ms(r,e)}),a=[null,...Array.from({length:t},(e,t)=>t+1)];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-field__label`,children:`On YouTube`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The extension keeps each upload's link when Studio confirms it. Paste a link for an upload made by hand. A/B test opens the video in Studio with A/B Testing set up; press Set test and Save there.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:a.map(t=>(0,h.jsx)(Kye,{projectId:e,short:t,video:n.data?.find(e=>e.short===t),stats:i.data?.find(e=>e.short===t)},t??0))})]})}function Kye({projectId:e,short:t,video:n,stats:r}){let{api:i}=V(),a=_(),o=(0,m.useId)(),s=n===void 0?``:`https://youtu.be/${n.videoId}`,[c,l]=(0,m.useState)(),u=c??s,[d,f]=(0,m.useState)(),p=t=>{a.setQueryData(C5(e),t),l(void 0),f(void 0)},g=L({mutationFn:()=>Ts(i,e,t,u),onSuccess:p,onError:e=>f(e.message)}),v=L({mutationFn:()=>Ts(i,e,t,``),onSuccess:p,onError:e=>f(`${e.message} Press Deleted on YouTube again, or clear the link and save.`)});return(0,h.jsxs)(`li`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`label`,{className:`w-[64px] shrink-0 text-small text-ink-2`,htmlFor:o,children:Uye(t)}),(0,h.jsx)(zB,{id:o,type:`url`,className:`min-w-[220px] flex-1 sm:max-w-[360px]`,placeholder:`https://youtu.be/…`,value:u,onChange:e=>l(e.currentTarget.value)}),u.trim()===s?null:(0,h.jsx)(B,{type:`button`,size:`small`,disabled:g.isPending,onClick:()=>g.mutate(),children:`Save link`}),n===void 0||u.trim()!==s?null:(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:v.isPending,onClick:()=>v.mutate(),children:`Deleted on YouTube`}),n===void 0||n.uploadState!==`done`||t!==null?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,children:`A/B test`})}),(0,h.jsx)(f8,{children:[[`both`,`Titles and thumbnails`],[`titles`,`Titles`],[`thumbnails`,`Thumbnails`]].map(([r,i])=>(0,h.jsx)(p8,{onSelect:()=>window.open(Vye(n.videoId,r,e,t),`_blank`,`noopener`),children:i},r))})]})]}),n===void 0&&d===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small ${d!==void 0||n?.finishState===`failed`||n?.commentState===`failed`?`text-danger`:`text-ink-3`}`,children:d??(n===void 0?``:Wye(n))}),r===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small tabular-nums text-ink-2`,children:qye(r)})]})}function qye(e){let t=[];if(e.views!==null&&t.push(`${e.views.toLocaleString()} views`),e.ctr!==null&&t.push(`${String(e.ctr)}% CTR${e.impressions===null?``:` of ${e.impressions.toLocaleString()} impressions`}`),e.averageViewSeconds!==null){let n=Math.round(e.averageViewSeconds),r=n>=3600?`${String(Math.floor(n/3600))}:${String(Math.floor(n%3600/60)).padStart(2,`0`)}:${String(n%60).padStart(2,`0`)}`:`${String(Math.floor(n/60))}:${String(n%60).padStart(2,`0`)}`;t.push(`${r} average view`)}return t.push(`read ${new Date(e.readAt).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}`),t.join(` · `)}var Jye=Y({number:q().int().positive(),first:q().int().positive(),last:q().int().positive(),start:q().finite().nonnegative(),end:q().finite().positive(),title:K(),description:K(),hashtags:J(K()),why:K(),text:K(),seed:K().nullable().optional()}),Yye=.25,Xye=.4;function T5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(Yye,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(Xye,(s-a.end)/2)));return{start:E5(c),end:E5(l)}}Y({first:JD([q(),K()]),last:JD([q(),K()]),title:K(),description:K(),hashtags:J(K()),why:K().optional()});function E5(e){return Math.round(e*1e3)/1e3}var Zye=Y({shorts:J(Jye),durationSeconds:q().finite().nonnegative().optional(),sentences:J(Y({start:q().finite().nonnegative(),end:q().finite().nonnegative(),text:K()})).optional()});function Qye(e){if(e!=null)try{let t=Zye.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function $ye(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=T5(o,n,r,ebe(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function ebe(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function D5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:FK(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:FK(n,e.config.values)]))}}}}function tbe(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:xN(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function O5(e,t,n){return D5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function nbe(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function k5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=V(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await zo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await nbe(r.signal);let e=(await Mo(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Bo(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(LB,{label:e,id:s,children:(0,h.jsx)(zB,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(B,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var A5=`shorts:pick`,j5=e=>`shorts:${String(e)}`;function M5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],A5])]}}function N5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],j5(t)])]}}function rbe(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=Qye(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function ibe({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Ak,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Vk(o)}),l=[...n,...P5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...P5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(A5)===!0,f=rbe(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(dV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(abe,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(w6,{settings:cV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?cbe(n,e):O5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=Bk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(obe,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function abe({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(k5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function obe({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:T5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(U,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==A5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:()=>o(M5(e)),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(sbe,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(j5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):$ye(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?N5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==j5(t.number))})},t.number))})]})}function sbe({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(B,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(LB,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(VB,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(U,{id:`project.shorts.remake`})]})]})]})}function P5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function cbe(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return D5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var lbe=Y({shorts:J(Y({number:q(),first:q().optional(),last:q().optional(),start:q(),end:q(),title:K(),description:K(),hashtags:J(K())}))});function ube({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=c8(n,e),a=l8(i,`shorts`),o=L5(i),s=j8(t.id),[c,l]=(0,m.useState)(),u=F5(i,`short_video`,o),d=t.config.shorts,f=w5(t.id),p=d?.fullVideoLink??Hye(f.data),g=(0,m.use)(W8),_=(0,m.use)(G8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let v=g&&_!==void 0&&d?.enabled===!0,y=e=>{let t=Ik(e,p),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(E8,{files:o.map(e=>({output:u.find(t=>I5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:v&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...zb,children:[(0,h.jsx)(B,{onClick:()=>_({section:`shorts`,change:M5}),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(u0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(dbe,{clip:n,projectId:t.id,review:M8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>I5(e,n)),stills:F5(i,`short_image`,o).filter(e=>I5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:p,wanted:zk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:mbe(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>y(n),...v?{onRemake:()=>_({section:`shorts`,change:e=>N5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(v1,{tone:c?.tone??`info`,children:c?.text})]})}function dbe({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=g8(r),g=g8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(c0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(l0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:uF(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(fbe,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(I8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Iy,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(ES,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Py,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(Py,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(f8,{align:`start`,children:(0,h.jsxs)(p8,{onSelect:d,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function fbe({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(kS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function F5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>I5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function I5(e,t){return e.meta.short===t.number}function L5(e){return pbe(O8(l8(e,`shorts`)).data)}function pbe(e){if(e===void 0)return[];try{let t=lbe.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function mbe(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function hbe({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=V(),a=Ry(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=l8(c8(n,e),o?`audio_export`:`video`),c=c8(n,e),l=l8(c,`subtitles_srt`),u=l8(c,`subtitles_vtt`),d=l8(c,`youtube_description`),f=l8(c,`youtube_tags`),p=l8(c,`audio_mp3`),m=l8(c,`audio_m4b`),g=F5(c,`short_video`,L5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=g8(s),v=g8(gbe(n)),y=_be(t.id,d,f,s?.durationMs??null),b=g8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=dF(e.progressCurrent??0,e.progressTotal??0);return jx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await M0(i,{projectId:t.id,asset:C3(s),folder:_?.folder??null});e.opened||a(`${N0} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(b8,{children:r}):(0,h.jsxs)(b8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:QP(e,t.config)?`Preparing subtitles · ${String(dF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:rF(nF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)(Y8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(c0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,square:t.format===`1:1`,className:t.format===`9:16`?`max-w-[360px]`:t.format===`1:1`?`max-w-[640px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(E8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(D8,{children:[uF(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:ck(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||PO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:PO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function gbe(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function _be(e,t,n,r){let{api:i}=V(),a=O8(t).data,o=O8(n).data,s=I({queryKey:H.youtubeEdits(e),queryFn:()=>zs(i,e),enabled:t!==void 0});return a===void 0?[]:vbe(S5(x5(b5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function vbe(e,t){return y5(e,t).text.split(`
301
- `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:v5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function ybe(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(Yve,{...e});case`audio`:return(0,h.jsx)(aye,{...e});case`images`:return(0,h.jsx)(Pye,{...e});case`video`:return(0,h.jsx)(hbe,{...e});case`document`:return(0,h.jsx)(lye,{...e});case`research`:case`thumbnail`:return null}}Y({summary:K(),chapters:J(Y({start:JD([K(),q()]),title:K()})),hashtags:J(K()),tags:J(K()),pinnedComment:K(),titles:J(K())});function R5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var z5=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`});function B5(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function bbe({projectId:e}){let{api:t}=V(),n=_(),r=Ry(),i=[`studio`,`project-releases`,e],a=I({queryKey:i,queryFn:()=>us(t,e)}),[o,s]=(0,m.useState)({}),c=(I({queryKey:[`studio`,`releases`,`swap`,8],queryFn:()=>cs(t,8)}).data?.entries??[]).flatMap(t=>t.project===null||t.project.id===e?[]:[{id:t.project.id,title:t.project.title,at:t.at}]),l=L({mutationFn:n=>ls(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),n.invalidateQueries({queryKey:[`studio`,`project-releases`,t]}),r(`Swapped release times with ${c.find(e=>e.id===t)?.title??`the other video`}; each one's shorts moved with it.`,`success`)},onError:e=>r(`The times weren't swapped: ${e.message}`,`error`)}),u=L({mutationFn:n=>ds(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),s(e=>{let{[t.short]:n,...r}=e;return r}),r(t.at===null?`Not scheduled: set its time in Studio yourself, or pick one here.`:`Saved the release time.`,`success`)},onError:e=>r(`The time wasn't saved: ${e.message}`,`error`)});if(a.data===void 0)return null;let{items:d,free:f,leadHours:p}=a.data;return d.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Release`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{as:`h3`,size:`small`,title:`Release`,meta:`Upload and schedule each one at least ${String(p)} hours before it goes out.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:d.map(e=>{let t=e.short===0?`Long video`:`Short ${String(e.short)}`,n=o[e.short]??(e.at===null?``:B5(e.at)),r=n!==(e.at===null?``:B5(e.at)),i=!e.onYoutube&&e.uploadBy!==null&&Date.parse(e.uploadBy)<Date.now();return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,h.jsx)(`span`,{className:`w-[86px] shrink-0 text-small font-semibold`,children:t}),(0,h.jsx)(zB,{"aria-label":`${t}: release`,type:`datetime-local`,className:`w-[210px]`,value:n,onChange:t=>{let n=t.currentTarget.value;s(t=>({...t,[e.short]:n}))}}),r?(0,h.jsx)(B,{type:`button`,size:`small`,disabled:n===``||u.isPending,onClick:()=>u.mutate({short:e.short,at:new Date(n).toISOString()}),children:`Save`}):null,e.short===0&&f.length>0?(0,h.jsx)(VB,{"aria-label":`Take a free time of the posting plan`,className:`w-[230px]`,value:``,onChange:e=>{let t=f.find(t=>t.longAt===e.currentTarget.value);t!==void 0&&u.mutate({short:0,at:t.longAt,line:t.row})},options:[{value:``,label:`Free plan times…`},...f.map(e=>({value:e.longAt,label:z5.format(new Date(e.longAt))}))]}):null,e.at!==null&&e.short===0&&c.length>0?(0,h.jsx)(VB,{"aria-label":`Swap release times with another video`,className:`w-[260px]`,value:``,disabled:l.isPending,onChange:e=>{e.currentTarget.value!==``&&l.mutate(e.currentTarget.value)},options:[{value:``,label:`Swap with…`},...c.map(e=>({value:e.id,label:`${e.title.split(` | `)[0]??e.title} · ${z5.format(new Date(e.at))}`}))]}):null,e.at!==null&&e.short===0?(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:u.isPending,onClick:()=>u.mutate({short:0,at:null}),children:`Not scheduled`}):null,(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.onYoutube?(0,h.jsx)(kS,{children:`✓ on YouTube`}):e.uploadBy===null?`No time yet`:i?(0,h.jsx)(kS,{tone:`failed`,children:`Late · upload now`}):`Ready to upload`})]},e.short)})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Every video's times are together in`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`releases`},children:`Calendar → Releases`}),`.`]})]})}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function xbe({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=V(),a=_(),o=c8(n,e),s=l8(o,`youtube_description`),c=l8(o,`youtube_tags`),l=l8(o,`youtube_pinned_comment`),u=l8(o,`youtube_titles`),d=O8(s).data,f=O8(c).data,p=O8(l).data,g=O8(u).data,v=(0,m.use)(K8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=I({queryKey:H.youtubeEdits(t.id),queryFn:()=>zs(i,t.id)}),T=I({queryKey:H.projectChannelLinks(t.id),queryFn:()=>Rs(i,t.id)}),[E,D]=(0,m.useState)(),O=Ry(),k=e=>a.setQueryData(H.youtubeEdits(t.id),e),A=L({mutationFn:e=>Bs(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),j=(0,m.useRef)({});if(jx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:nP.copyDescription,run:()=>j.current.description===void 0?O(`The description has not been written yet.`,`info`):j.current.description()}),jx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>j.current.tags===void 0?O(`The tags have not been written yet.`,`info`):j.current.tags()}),jx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>j.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):j.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let M=d===void 0?void 0:b5(d,f??``,{pinnedComment:p,titles:g}),ee=x5(M,w.data?.fields??{}),N=S5(ee),P=Ej(T.data?.links??[],w.data?.links??[]),F=l8(o,`video`),te=y5(N.chapters,F?.durationMs===null||F?.durationMs===void 0?void 0:F.durationMs/1e3),ne=Lye(te.adjustments),re=Oj(zye({...N,chapters:te.text}),P),ie=Oj(N.tags,P),ae=Oj(N.pinnedComment,P),oe=[...re.unknown,...ie.unknown,...ae.unknown].filter((e,t,n)=>n.findIndex(t=>Tj(t)===Tj(e))===t),se=G5(ie.text),ce=M!==void 0,le=ae.text.trim()!==``,ue=N.titles.split(`
302
- `).map(e=>e.trim()).filter(e=>e!==``),de=ce&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0,fe=(e,t)=>{let n=`Couldn't copy the ${t}. Select the text in the YouTube section and copy it.`;if(!navigator.clipboard){D({text:n,tone:`error`}),O(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),O(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),O(n,`error`)})};j.current=ce?{description:()=>fe(re.text,`description`),tags:()=>fe(ie.text,`tags`),...le?{pinnedComment:()=>fe(ae.text,`pinned comment`)}:{}}:{};let pe=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,me=(e,t)=>(0,h.jsx)(Sbe,{label:V5[e],value:ee[e],links:P,disabled:!ce||A.isPending,multiline:e!==`hashtags`,placeholder:ce&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again to have one written, or Edit to write your own.`:ce&&e===`titles`?`Written before other titles existed. Use Write again to have two written, or Edit to write your own, one per line.`:pe,render:t,onSave:t=>A.mutate({field:e,edit:{text:t,base:M?.[e]??``},done:`Saved your ${V5[e].toLowerCase()}.`}),onUseGenerated:()=>A.mutate({field:e,edit:null,done:`The ${V5[e].toLowerCase()} follows the generated text again.`}),onKeepMine:(t,n)=>A.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${V5[e].toLowerCase()}.`})},e);return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`@container flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sr-only`,children:`YouTube`}),(0,h.jsxs)(`div`,{className:`flex min-w-0 max-w-[80ch] flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:ce?()=>fe(re.text,`description`):void 0,keyshortcuts:Ux(nP.copyDescription),count:ce?`${String(re.text.length)} / ${String(v6)} characters`:void 0,over:re.text.length>v6,main:!0,again:de}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[me(`summary`),me(`chapters`,()=>te.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(W5,{text:te.text,links:P})),ne===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:ne}),me(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:ce?()=>fe(ie.text,`tags`):void 0,count:ce?`${String(R5(se))} / 500 characters`:void 0,over:R5(se)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:me(`tags`,e=>(0,h.jsx)(Cbe,{text:e,links:P}))}),(0,h.jsx)(U5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:ce&&le?()=>fe(ae.text,`pinned comment`):void 0,count:ce&&le?`${String(ae.text.length)} / 500 characters`:void 0,over:ae.text.length>500,again:de}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[me(`pinnedComment`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Post it under the video once it is published, then choose Pin in the comment's menu.`})]}),(0,h.jsx)(U5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:ce&&ue.length>0?()=>fe(ue.join(`
303
- `),`other titles`):void 0,count:ce&&ue.length>0?`${String(ue.length+1)} titles to test`:void 0,over:ue.some(e=>e.length>100),again:de}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[me(`titles`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`For YouTube's A/B Testing beside the title, with this project's own title "${t.title}". One per line.`})]})]})]}),oe.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${oe.map(e=>`{{${e}}}`).join(`, `)}, so it stays as typed. Add it under Channel links on `,T.data===void 0?`the channel's Brand tab`:(0,h.jsx)(fa,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${oe.some(e=>Tj(e)===Tj(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(bbe,{projectId:t.id}),(0,h.jsx)(Gye,{projectId:t.id,shorts:n.filter(e=>e.role===`short_video`).length}),(0,h.jsx)(wbe,{projectId:t.id,edits:w.data,onSaved:e=>{k(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(v1,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(Hy,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags, pinned comment and other titles. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function U5({id:e,label:t,copy:n,count:r,over:i,keyshortcuts:a,main:o=!1,again:s,open:c,onToggle:l}){return(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-3 border-b border-line pb-2`,children:[(0,h.jsx)(`h4`,{id:e,className:`m-0 text-title-3 font-semibold text-ink`,children:l===void 0?t:(0,h.jsxs)(B,{type:`button`,variant:`quiet`,"aria-expanded":c===!0,onClick:l,className:`-ml-2 h-auto px-2 py-1 text-title-3 font-semibold text-ink`,children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75,className:z(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:z(`text-small tabular-nums`,i?`text-danger`:`text-ink-3`),children:i?`${r}, over YouTube's limit`:r}),(0,h.jsx)(`span`,{className:`flex-1`}),s===void 0?null:(0,h.jsxs)(B,{type:`button`,variant:`secondary`,"aria-label":`Write the ${t.toLowerCase()} again`,onClick:s,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(B,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function Sbe({label:e,value:t,links:n,disabled:r,multiline:i,placeholder:a,render:o,onSave:s,onUseGenerated:c,onKeepMine:l}){let u=(0,m.useId)(),[d,f]=(0,m.useState)(),[p,g]=(0,m.useState)(!1),_=d!==void 0,v=e.toLowerCase(),y=e in H5?H5[e]:void 0;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h5`,{id:`${u}-label`,className:`sl-kicker text-ink-3`,children:e}),y===void 0?null:(0,h.jsx)(U,{id:y,label:v,className:`-my-1`})]}),t.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),t.edited&&!_?(0,h.jsx)(B,{type:`button`,variant:`quiet`,size:`small`,disabled:r,"aria-label":`Use the generated ${v}`,onClick:c,children:`Use generated`}):null,(0,h.jsxs)(B,{type:`button`,variant:`quiet`,size:`small`,disabled:r||_,"aria-label":`Edit ${v}`,onClick:()=>f(t.text),children:[(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),t.pending===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-l-2 border-waiting pl-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`p`,{className:`text-small text-ink`,children:`New generated version available.`}),(0,h.jsx)(B,{type:`button`,disabled:r,"aria-label":`Use the new generated ${v}`,onClick:c,children:`Use it`}),(0,h.jsx)(B,{type:`button`,disabled:r,"aria-label":`Keep my ${v}`,onClick:()=>l(t.text,t.pending??``),children:`Keep mine`}),(0,h.jsx)(B,{type:`button`,variant:`quiet`,"aria-expanded":p,"aria-label":`${p?`Hide`:`View`} the ${v} diff`,onClick:()=>g(e=>!e),children:p?`Hide diff`:`View diff`})]}),p?(0,h.jsx)(b4,{before:t.text,after:t.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),_?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${u}-edit`,className:`sr-only`,children:e}),i?(0,h.jsx)(BB,{id:`${u}-edit`,rows:e===`Chapters`?8:5,value:d,onChange:e=>f(e.currentTarget.value)}):(0,h.jsx)(zB,{id:`${u}-edit`,value:d,onChange:e=>f(e.currentTarget.value)}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(B,{type:`button`,variant:`primary`,disabled:r,onClick:()=>{s(d),f(void 0)},children:[`Save `,v]}),(0,h.jsx)(B,{type:`button`,variant:`secondary`,onClick:()=>f(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${u}-label`,className:z(`min-w-0 whitespace-pre-wrap break-words text-small`,t.text===``?`text-ink-3`:`text-ink`),children:t.text===``?a:o===void 0?(0,h.jsx)(W5,{text:t.text,links:n}):o(t.text)})]})}function W5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:Dj(e,t).map(e=>{let t=String(n);return n+=e.kind===`text`?e.text.length:e.raw.length,e.kind===`text`?(0,h.jsx)(`span`,{children:e.text},t):e.url===void 0?(0,h.jsx)(`mark`,{title:`No link named ${e.name}`,className:`rounded-[2px] bg-waiting/25 px-0.5 text-ink`,children:e.raw},t):(0,h.jsx)(`span`,{title:e.raw,className:`underline decoration-dotted underline-offset-[3px]`,children:e.url},t)})})}function G5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function Cbe({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:G5(e).map((e,n)=>(0,h.jsx)(`li`,{className:`rounded-full border border-line bg-raised px-2 py-0.5 text-small text-ink`,children:(0,h.jsx)(W5,{text:e,links:t})},n))})}function wbe({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=V(),a=(0,m.useId)(),o=t?.links.find(e=>Tj(e.name)===Tj(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=L({mutationFn:()=>{let n=(t?.links??[]).filter(e=>Tj(e.name)!==Tj(Sj));return Vs(i,e,l.trim()===``?n:[...n,{name:Sj,url:l.trim()}])},onSuccess:e=>{c(void 0),n(e)},onError:e=>r(e.message)});return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[260px] flex-1 flex-col gap-1 sm:max-w-[520px]`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{className:`sl-field__label`,htmlFor:a,children:`Previous video for this project`}),(0,h.jsx)(U,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(zB,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(B,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var K5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function Tbe({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=V(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(!1),g=(0,m.useRef)(!0),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=JSON.stringify([t,n.map(e=>[e.stage,e.checkpointId]).toSorted()]),b=s!==null&&s.baseIdentity!==y,x=s?.stages??n.map(e=>e.stage),S=K5.some(({stage:e})=>x.includes(e)!==n.some(t=>t.stage===e)),C=b||d!==null&&d.kind!==`success`,w=b?{kind:`refused`,message:`Checkpoint choices changed elsewhere. Press Reload checkpoint choices before saving, then make your change again.`}:d;(0,m.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,m.useEffect)(()=>{(d||b)&&_.current?.focus()},[d,b]);async function T(){if(!(p.current||!S||C)){p.current=!0,u(!0);try{let n=await Nhe(o,e,{revisionId:t,stages:x});if(!g.current)return;n.ok?n.value.revisionId===t?(a(n.value),c(null),f({kind:`success`,message:`Checkpoint choices saved.`})):f({kind:`refused`,message:`The project was edited elsewhere. Press Reload checkpoint choices to see its current choices.`}):f({kind:`refused`,message:n.message})}catch(e){g.current&&f({kind:`transport`,message:`${_o(e instanceof Error?e.message:`Slopify didn't confirm the change`)} It may or may not have saved. Press Reload checkpoint choices before changing anything else.`})}finally{p.current=!1,g.current&&u(!1)}}}async function E(){if(!p.current){p.current=!0,u(!0);try{let e=await i();g.current&&e&&(c(null),f(null),v.current?.focus())}finally{p.current=!1,g.current&&u(!1)}}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(`fieldset`,{ref:v,tabIndex:-1,className:`space-y-2`,...zb,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(U,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),K5.map(({stage:e,name:t})=>{let n=r.find(t=>t.kind===e),i=n?.state===`pending`&&(e===`video`?n.source!==`off`||r.some(e=>e.kind===`audio`&&e.source!==`off`&&e.state!==`skipped`):(n.source??`generate`)===`generate`);return(0,h.jsxs)(`label`,{className:`flex min-h-10 items-center gap-3`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),disabled:!i||l||C,onChange:t=>{c({baseIdentity:s?.baseIdentity??y,stages:t.target.checked?[...x,e]:x.filter(t=>t!==e)}),f(null)}}),`Before `,t]},e)})]}),w?(0,h.jsx)(`p`,{ref:_,tabIndex:-1,role:w.kind===`success`?`status`:`alert`,children:w.message}):null,(0,h.jsx)(B,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(B,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var q5=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ebe(e){return e.revisionId===null?null:(0,h.jsx)(Dbe,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function Dbe({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=V(),o=_(),s=I({queryKey:c3(e,t),queryFn:()=>u3(a,e),retry:!1}),c=s.data,l=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t?e.data.value:void 0},u=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t};return s.isPending?null:s.error||c?.ok===!1?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:s.error?.message??(c?.ok===!1?c.message:`Checkpoints couldn't be loaded. Press Reload checkpoints.`)}),(0,h.jsx)(B,{onClick:()=>void u(),children:`Reload checkpoints`})]}):c?.ok?c.value.revisionId===t?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col gap-5`,children:[(0,h.jsx)(W,{title:`Review checkpoints`,size:`small`,className:`pb-0`}),n?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`The project is paused. Continue the run before approving held work.`}):null,(0,h.jsx)(Tbe,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(c3(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:H.project(e)}),o.invalidateQueries({queryKey:H.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(Obe,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,...a.checkpointId===i?{inRail:!0}:{}},`${a.checkpointId}:${a.fingerprint}`))]}):(0,h.jsx)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The project was edited after these checkpoints loaded. Press Reload checkpoints before approving.`})}):null}function Obe({gate:e,disabled:t,reload:n,inRail:r=!1}){let{api:i}=V(),a=_(),o=(0,m.useRef)(null),s=(0,m.useRef)(!1),c=(0,m.useRef)(!0),l=(0,m.useRef)(null),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(null);(0,m.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,m.useEffect)(()=>{f!==null&&l.current?.focus()},[f]);let g=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function v(){if(!(s.current||t||!g||f?.kind===`refused`||f?.kind===`success`)){s.current=!0,d(!0),o.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await d3(i,e.projectId,e.checkpointId,o.current);o.current=null,c.current&&p(t.ok?{kind:`success`,message:t.value.replayed?`Checkpoint already approved.`:`Checkpoint approved. Work will run when its dependencies are ready.`}:{kind:`refused`,message:t.message}),a.invalidateQueries({queryKey:s3(e.projectId)}),a.invalidateQueries({queryKey:H.project(e.projectId)}),a.invalidateQueries({queryKey:H.projects})}catch(e){c.current&&p({kind:`transport`,message:`${_o(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{s.current=!1,c.current&&d(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(W,{as:`h3`,title:`${q5(e.stage)} checkpoint`,className:`pb-0`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`released`&&e.approvedAt!==null?`Authorized for this revision. Work can run when dependencies are ready and the project is resumed.`:e.state===`satisfied`?`Checkpoint satisfied. Its reviewed work is complete.`:e.state===`invalidated`||e.fingerprint!==e.currentFingerprint?`Inputs changed. Review the current revision before approving.`:g?`${q5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Reviewed revision: `,e.revisionId]}),e.dependents.length?(0,h.jsx)(`ul`,{"aria-label":`Dependent work`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:e.dependents.map(e=>(0,h.jsx)(`li`,{className:`sl-chip`,children:q5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),f?(0,h.jsx)(`p`,{ref:l,tabIndex:-1,role:f.kind===`success`?`status`:`alert`,className:f.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:f.message}):null,g&&r&&f===null?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Its approval is the project's next action, in the right rail.`}):g?(0,h.jsx)(B,{className:`self-start`,disabled:t||u||f?.kind===`refused`||f?.kind===`success`,onClick:()=>void v(),children:u?`Approving…`:f?.kind===`transport`?`Retry approval`:`Approve ${q5(e.stage)} checkpoint`}):null,f?.kind===`refused`?(0,h.jsx)(B,{className:`self-start`,onClick:async()=>{await n()&&p(null)},children:`Reload checkpoints`}):null]})}function kbe({projects:e,queryKey:t}){let{api:n}=V(),r=_(),i=Ry(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=L({mutationFn:e=>Ro(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t.title}" (${String(e.files)} working file${e.files===1?``:`s`}).`,`success`)},onError:e=>c(e.message),onSettled:()=>r.invalidateQueries({queryKey:t})}),u=e.toSorted((e,t)=>t.bytes-e.bytes);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-2 flex items-center gap-1 text-small text-ink-2`,children:[`Keep outputs only frees a finished project's working files.`,(0,h.jsx)(U,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(PH,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(FH,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[Y5(e.bytes),` · outputs `,Y5(e.outputsBytes),` · working files `,Y5(e.workingBytes)]}),actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:!e.finished||e.removableBytes===0||l.isPending,title:e.finished?e.removableBytes===0?`No working files left to remove.`:`Frees ${Y5(e.removableBytes)}.`:`Available once the project has finished.`,onClick:()=>o(e),children:l.isPending&&l.variables?.id===e.id?`Removing…`:`Keep outputs only`})},e.id))}),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:s}),(0,h.jsx)(Hy,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:J5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function J5(e,t){return`This removes ${String(e)} working file(s) and frees ${Y5(t)}: the images, narration parts, subtitle timing and render settings the project was made from. The video, shorts, thumbnail, article, description and document stay, and so does anything you uploaded. If you change this project later (edit an image, a caption style or the narration, or re-render), Slopify has to make those files again first, which takes time and uses provider credits.`}function Y5(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var X5=e=>[`storage`,`project`,e];function Abe({projectId:e,title:t,status:n,sample:r}){let{api:i}=V(),a=_(),o=Ry(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=I({queryKey:[...X5(e),n],queryFn:()=>Lo(i,e),enabled:l&&!r}),d=L({mutationFn:()=>Ro(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t}". The outputs are all still here.`,`success`),onError:e=>o(`The working files of "${t}" weren't removed: ${e.message}`,`error`),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:X5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:H.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=Y5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:`Free space`,meta:`Outputs ${Y5(f.outputsBytes)} · working files ${Y5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Free ${p}: keep the outputs, drop the working files`,disabled:d.isPending,disabledReason:`Removing the working files…`,onClick:()=>c(!0),children:d.isPending?`Removing…`:`Free ${p}`})}),(0,h.jsx)(Hy,{open:s,title:`Free ${p} from "${t}"?`,consequence:J5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function jbe({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=e.status===`pending`&&e.setAside===!0?{tone:`done`,word:`Kept as is`}:Pbe(e.status);return(0,h.jsx)(XK,{crumb:(0,h.jsxs)(fa,{to:`/projects`,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75}),`Projects`]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[Fbe(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(OS,{tone:s.tone,children:[s.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`Project: ${s.word}`})]}),a!==void 0&&Mbe(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(U,{id:`project.next-chapter`}),a.error===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`max-w-[320px] text-small text-danger`,children:a.error})]}):null,(0,h.jsxs)(B,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(Zc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(u8,{modal:!1,children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(Py,{label:`More project actions`,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(f8,{children:i.map(e=>(0,h.jsx)(Nbe,{item:e},e.id))})]})]})})}function Mbe(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function Nbe({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(Eve,{}):null,(0,h.jsx)(p8,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function Pbe(e){switch(e){case`running`:return{tone:`running`,word:`Running`};case`paused`:return{tone:`waiting`,word:`Paused`};case`failed`:return{tone:`failed`,word:`Failed`};case`partial`:return{tone:`waiting`,word:`Done with problems`};case`done`:return{tone:`done`,word:`Done`};case`canceled`:return{tone:`off`,word:`Canceled`};case`pending`:return{tone:`off`,word:`Queued`}}}function Fbe(e,t){let n=e.config.articlePrompt,r=t===void 0||t.some(e=>e.name===n),i=n===void 0||n===``?void 0:r?n:`${n} (deleted)`,a=e.config.voices?.book;return[a===void 0?void 0:AA(a),i,e.format,`started ${Wu(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function Ibe({projectId:e}){let{api:t}=V(),n=I(cb(t,e));return n.error===null?n.data===void 0?(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading run cost`,className:`flex flex-col gap-8`,children:[(0,h.jsx)(`span`,{className:`h-16 max-w-3xl rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`})]}):(0,h.jsx)(Vbe,{cost:n.data}):(0,h.jsx)(aI,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var Lbe=new Set([`done`,`partial`,`failed`,`canceled`]);function Rbe({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=t===`running`,a=r?.current===!0&&!Lbe.has(t),[o,s]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[i]),!a||r===null)return null;let c=r.workingMs+(i?Math.max(0,o-n):0),l=i?Kbe(c):o7(c);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:i?`inline-flex items-center gap-1.5 rounded-full bg-accent/15 px-2.5 py-0.5 font-semibold text-ink tabular-nums`:`inline-flex items-center gap-1.5 rounded-full bg-surface-2 px-2.5 py-0.5 font-semibold text-ink-2 tabular-nums`,children:[(0,h.jsx)(Qc,{"aria-hidden":`true`,strokeWidth:2,className:`size-3.5 shrink-0`}),i?`Working · ${l}`:`${l} of work so far`]})]})}var zbe=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:YP[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:o7(e.wallMs)}],Bbe=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:Wbe(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>t7.format(e.calls)}];function Z5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function Vbe({cost:e}){if(e.calls===0&&e.byStage.length===0)return(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Nothing has been spent yet. The cost of each provider call appears here as the run makes it.`});let t=e.byModel.some(e=>e.onPlan),n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({plan:e,window:t})):[]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{"aria-label":`Run cost summary`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(x2,{children:[(0,h.jsx)(S2,{value:a7(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(S2,{value:`~${a7(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${Z5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${n7.format(t.usedPercent)}%`;return(0,h.jsx)(S2,{value:r,label:`of ${n}`,children:(0,h.jsx)(C2,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${n7.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(S2,{value:o7(e.run.workingMs),label:`this run's working time`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 text-small text-ink-2`,children:[e.unpriced>0?(0,h.jsx)(`p`,{className:`m-0`,children:`Plus ${i7(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:Hbe(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:Ube(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(W,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Run cost by stage`,columns:zbe,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(W,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Run cost by model`,columns:Bbe,rows:e.byModel,rowKey:e=>`${e.provider}/${e.model}/${e.kind}`})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In total: ${e7(e.totals)||`no reported usage`} · ${o7(e.totals.wallMs)} working, over every run.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Priced from the model catalogue${e.catalogueDate===null?``:` of ${e.catalogueDate}`} when each call finished. Retries that failed are not charged here; taxes and included credits are not counted.`})]})]})}function Hbe(e){let t=e.apiEquivalent??0;if(t===0&&e.apiUnpriced>0)return`CLI calls: $0 on your plan · no API price is listed for their models.`;let n=e.apiUnpriced>0?` (plus ${i7(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${a7(t)} via API${n}.`}function Ube(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=Z5(t.kind),r=t.usedPercent<1?`under 1%`:`~${n7.format(t.usedPercent)}%`,i=`now at ${n7.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${qbe(t.resetsAt)}`}`;return`This run used ${r} of your ${n} ${e.name} limit (${i}).`}).join(` `):`${e.name} did not report its plan limits for this run, so the share it used is not known.`}function Q5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${a7(e.cost)} + unknown`:a7(e.cost)}function $5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${a7(e.apiEquivalent)}`}function Wbe(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function e7(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${r7(e.tokensIn)} in / ${r7(e.tokensOut)} out tokens${e.cachedTokens>0?` (${r7(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${r7(e.characters)} characters`),e.images>0&&t.push(i7(e.images,`image`)),e.seconds>0&&t.push(`${t7.format(e.seconds)} s of video`),t.join(` · `)}var t7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),n7=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),Gbe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function r7(e){return e<1e4?t7.format(e):Gbe.format(e)}function i7(e,t){return`${t7.format(e)} ${t}${e===1?``:`s`}`}function a7(e){return e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function Kbe(e){let t=Math.max(0,Math.floor(e/1e3)),n=e=>String(e).padStart(2,`0`);return`${String(Math.floor(t/3600))}:${n(Math.floor(t%3600/60))}:${n(t%60)}`}function o7(e){let t=Math.round(e/1e3);if(t<60)return`${t} s`;let n=Math.floor(t/60);return n<60?`${n} min ${t%60} s`:`${Math.floor(n/60)} h ${n%60} min`}function qbe(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function Jbe({project:e,revisionId:t,stages:n,outputs:r}){let i=r.filter(e=>e.role===`image`).sort((e,t)=>(e.meta.index??0)-(t.meta.index??0)),a=n.find(e=>e.kind===`article`),o=(0,m.use)(f3);return(0,h.jsx)(`div`,{className:`flex min-w-0 flex-col`,children:(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(W,{title:`Article`}),a?.state===`running`?(0,h.jsx)(D3,{projectId:e.id,stage:`article`,className:`mb-6`}):a?.state===`done`?(0,h.jsxs)(`p`,{className:`mb-6 flex flex-wrap items-center gap-3 text-small text-ink-2`,children:[`The article is written.`,o===void 0?null:(0,h.jsx)(B,{variant:`secondary`,size:`small`,onClick:()=>o(`output`),children:`Read it`})]}):(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:a===void 0||a.state===`skipped`?`This project has no article.`:`The article appears here as it is written.`}),(0,h.jsx)(W,{title:`Narration`}),(0,h.jsx)(Xbe,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(W,{title:`Images`}),i.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The images appear here as each one is drawn.`}):(0,h.jsx)(u0,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(Ybe,{output:t,aspect:l5(e.format)},t.id))})]})})}function Ybe({output:e,aspect:t}){let n=g8(e);if(n===void 0)return null;let r=e.meta.index===void 0?``:` ${String(e.meta.index)}`;return(0,h.jsx)(`li`,{className:`min-w-0`,children:(0,h.jsx)(l0,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function Xbe({projectId:e,revisionId:t,audio:n,outputs:r}){let i=r.find(e=>e.role===`audio_levelled`&&e.meta.segment===`body`)??r.find(e=>e.role===`audio_body`),a=g8(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s7,{projectId:e,revisionId:t}),(0,h.jsx)(U8,{projectId:e})]}):a===void 0?(0,h.jsx)(s7,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)(Y8,{label:`Body narration`,src:a.url})})}var Zbe=240;function s7({projectId:e,revisionId:t}){let{api:n}=V(),r=I({queryKey:Gy(e,t),queryFn:()=>rb(n,e),enabled:t!==null}),i=(r.data?.pieces??[]).flatMap(e=>e.peaks),a=(r.data?.pieces??[]).reduce((e,t)=>e+t.seconds,0),o=Math.max(1,Math.ceil(i.length/Zbe)),s=[];for(let e=0;e<i.length;e+=o)s.push(Math.max(...i.slice(e,e+o)));return(0,h.jsxs)(`div`,{className:`mb-6`,children:[(0,h.jsx)(`div`,{role:`img`,"aria-label":s.length===0?`No narration yet`:`Narration so far: ${o7(a*1e3)}`,className:`flex h-16 items-center gap-px overflow-hidden rounded-control border border-line bg-raised px-2`,children:s.map((e,t)=>(0,h.jsx)(`span`,{className:`w-[3px] shrink-0 rounded-full bg-accent`,style:{height:`${String(Math.max(4,Math.round(e*100)))}%`}},t))}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:r.error?r.error.message:s.length===0?`The waveform grows as each part of the narration is spoken.`:`${o7(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function Qbe({projectId:e,title:t,open:n,onClose:r}){let{api:i}=V(),a=_(),o=Ry(),s=Dx(),[c,l]=(0,m.useState)(``),u=L({mutationFn:()=>Ao(i,[e],c),onSuccess:()=>{a.invalidateQueries({queryKey:H.projects}),o(`Moved "${t}" to ${s.channels.find(e=>e.id===c)?.name??`the channel`}.`,`success`),r()},onError:e=>o(`The project wasn't moved: ${e.message}`,`error`)});return(0,h.jsx)(Vy,{open:n,onOpenChange:e=>{e||r()},title:`Move to channel`,description:`The project shows in that channel's list and uses its brand and playlists. Nothing it made changes.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:r,children:`Cancel`}),(0,h.jsx)(B,{type:`button`,disabled:c===``||u.isPending,onClick:()=>u.mutate(),children:`Move`})]}),children:(0,h.jsx)(LB,{label:`Channel`,children:(0,h.jsx)(VB,{value:c,onChange:e=>l(e.currentTarget.value),options:[{value:``,label:`Choose a channel`},...s.channels.map(e=>({value:e.id,label:e.name}))]})})})}function $be(e){let t=[],n=[],r=0,i=()=>{let e=n[0],r=n.at(-1);e!==void 0&&r!==void 0&&t.push({start:e.start,end:r.end,text:c7(n.map(e=>e.text)),...e.speaker===void 0?{}:{speaker:e.speaker}}),n=[]};for(let t of e){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<r-.001||t.end<=t.start)throw Error(`The saved caption timing is damaged. Use More → Render the video again in the Video section to time them again, then Try again.`);let e=n[0];e!==void 0&&(t.start-r>.7||t.speaker!==e.speaker||t.end-e.start>5||c7([...n.map(e=>e.text),t.text]).split(`
300
+ `)}function Hye(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function x5(e,t){let n=n=>Hye(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function S5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}function Uye(e,t,n,r){return`https://studio.youtube.com/video/${e}/edit#slopify-ab=${t}&p=${encodeURIComponent(n)}&s=${String(r??0)}`}var C5=e=>[`project`,e,`youtube-videos`];function w5(e){let{api:t}=V();return I({queryKey:C5(e),queryFn:()=>ws(t,e)})}function Wye(e){let t=e?.find(e=>e.short===null&&e.uploadState===`done`);return t===void 0?void 0:`https://youtu.be/${t.videoId}`}function Gye(e){return e===null?`Video`:`Short ${String(e)}`}function Kye(e){if(e.uploadState===`filled`)return`Filled in Studio, but not scheduled or published yet (cancelled, or left as a draft). Upload it again from the extension, or paste its link once it is up.`;let t=[`On YouTube.`];return e.finishState===`waiting`&&t.push(`Related video, end screen and captions are being set.`),e.finishState===`failed`&&t.push(`Details touches failed: ${e.finishMessage??`no reason given`}`),e.commentState===`waiting`&&t.push(`The comment is pinned once it is public.`),e.commentState===`done`&&t.push(`Comment pinned.`),e.commentState===`failed`&&t.push(`Pinning the comment failed: ${e.commentMessage??`no reason given`}`),t.join(` `)}function qye({projectId:e,shorts:t}){let n=w5(e),{api:r}=V(),i=I({queryKey:[`project`,e,`youtube-stats`],queryFn:()=>ms(r,e)}),a=[null,...Array.from({length:t},(e,t)=>t+1)];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-field__label`,children:`On YouTube`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The extension keeps each upload's link when Studio confirms it. Paste a link for an upload made by hand. A/B test opens the video in Studio with A/B Testing set up; press Set test and Save there.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:a.map(t=>(0,h.jsx)(Jye,{projectId:e,short:t,video:n.data?.find(e=>e.short===t),stats:i.data?.find(e=>e.short===t)},t??0))})]})}function Jye({projectId:e,short:t,video:n,stats:r}){let{api:i}=V(),a=_(),o=(0,m.useId)(),s=n===void 0?``:`https://youtu.be/${n.videoId}`,[c,l]=(0,m.useState)(),u=c??s,[d,f]=(0,m.useState)(),p=t=>{a.setQueryData(C5(e),t),l(void 0),f(void 0)},g=L({mutationFn:()=>Ts(i,e,t,u),onSuccess:p,onError:e=>f(e.message)}),v=L({mutationFn:()=>Ts(i,e,t,``),onSuccess:p,onError:e=>f(`${e.message} Press Deleted on YouTube again, or clear the link and save.`)});return(0,h.jsxs)(`li`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`label`,{className:`w-[64px] shrink-0 text-small text-ink-2`,htmlFor:o,children:Gye(t)}),(0,h.jsx)(zB,{id:o,type:`url`,className:`min-w-[220px] flex-1 sm:max-w-[360px]`,placeholder:`https://youtu.be/…`,value:u,onChange:e=>l(e.currentTarget.value)}),u.trim()===s?null:(0,h.jsx)(B,{type:`button`,size:`small`,disabled:g.isPending,onClick:()=>g.mutate(),children:`Save link`}),n===void 0||u.trim()!==s?null:(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:v.isPending,onClick:()=>v.mutate(),children:`Deleted on YouTube`}),n===void 0||n.uploadState!==`done`||t!==null?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,children:`A/B test`})}),(0,h.jsx)(f8,{children:[[`both`,`Titles and thumbnails`],[`titles`,`Titles`],[`thumbnails`,`Thumbnails`]].map(([r,i])=>(0,h.jsx)(p8,{onSelect:()=>window.open(Uye(n.videoId,r,e,t),`_blank`,`noopener`),children:i},r))})]})]}),n===void 0&&d===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small ${d!==void 0||n?.finishState===`failed`||n?.commentState===`failed`?`text-danger`:`text-ink-3`}`,children:d??(n===void 0?``:Kye(n))}),r===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small tabular-nums text-ink-2`,children:Yye(r)})]})}function Yye(e){let t=[];if(e.views!==null&&t.push(`${e.views.toLocaleString()} views`),e.ctr!==null&&t.push(`${String(e.ctr)}% CTR${e.impressions===null?``:` of ${e.impressions.toLocaleString()} impressions`}`),e.averageViewSeconds!==null){let n=Math.round(e.averageViewSeconds),r=n>=3600?`${String(Math.floor(n/3600))}:${String(Math.floor(n%3600/60)).padStart(2,`0`)}:${String(n%60).padStart(2,`0`)}`:`${String(Math.floor(n/60))}:${String(n%60).padStart(2,`0`)}`;t.push(`${r} average view`)}return t.push(`read ${new Date(e.readAt).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}`),t.join(` · `)}var Xye=Y({number:q().int().positive(),first:q().int().positive(),last:q().int().positive(),start:q().finite().nonnegative(),end:q().finite().positive(),title:K(),description:K(),hashtags:J(K()),why:K(),text:K(),seed:K().nullable().optional()}),Zye=.25,Qye=.4;function T5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(Zye,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(Qye,(s-a.end)/2)));return{start:E5(c),end:E5(l)}}Y({first:JD([q(),K()]),last:JD([q(),K()]),title:K(),description:K(),hashtags:J(K()),why:K().optional()});function E5(e){return Math.round(e*1e3)/1e3}var $ye=Y({shorts:J(Xye),durationSeconds:q().finite().nonnegative().optional(),sentences:J(Y({start:q().finite().nonnegative(),end:q().finite().nonnegative(),text:K()})).optional()});function ebe(e){if(e!=null)try{let t=$ye.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function tbe(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=T5(o,n,r,nbe(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function nbe(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function D5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:FK(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:FK(n,e.config.values)]))}}}}function rbe(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:xN(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function O5(e,t,n){return D5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function ibe(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function k5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=V(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await zo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await ibe(r.signal);let e=(await Mo(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Bo(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(LB,{label:e,id:s,children:(0,h.jsx)(zB,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(B,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var A5=`shorts:pick`,j5=e=>`shorts:${String(e)}`;function M5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],A5])]}}function N5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],j5(t)])]}}function abe(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=ebe(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function obe({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Ak,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Vk(o)}),l=[...n,...P5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...P5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(A5)===!0,f=abe(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(dV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(sbe,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(w6,{settings:cV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?ube(n,e):O5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=Bk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(cbe,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function sbe({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(k5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function cbe({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:T5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(U,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==A5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:()=>o(M5(e)),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(lbe,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(j5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):tbe(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?N5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==j5(t.number))})},t.number))})]})}function lbe({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(B,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(LB,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(VB,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(U,{id:`project.shorts.remake`})]})]})]})}function P5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function ube(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return D5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var dbe=Y({shorts:J(Y({number:q(),first:q().optional(),last:q().optional(),start:q(),end:q(),title:K(),description:K(),hashtags:J(K())}))});function fbe({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=c8(n,e),a=l8(i,`shorts`),o=L5(i),s=j8(t.id),[c,l]=(0,m.useState)(),u=F5(i,`short_video`,o),d=t.config.shorts,f=w5(t.id),p=d?.fullVideoLink??Wye(f.data),g=(0,m.use)(W8),_=(0,m.use)(G8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let v=g&&_!==void 0&&d?.enabled===!0,y=e=>{let t=Ik(e,p),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(E8,{files:o.map(e=>({output:u.find(t=>I5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:v&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...zb,children:[(0,h.jsx)(B,{onClick:()=>_({section:`shorts`,change:M5}),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(u0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(pbe,{clip:n,projectId:t.id,review:M8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>I5(e,n)),stills:F5(i,`short_image`,o).filter(e=>I5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:p,wanted:zk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:gbe(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>y(n),...v?{onRemake:()=>_({section:`shorts`,change:e=>N5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(v1,{tone:c?.tone??`info`,children:c?.text})]})}function pbe({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=g8(r),g=g8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(c0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(l0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:uF(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(mbe,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(I8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Iy,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(ES,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Py,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(Py,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(f8,{align:`start`,children:(0,h.jsxs)(p8,{onSelect:d,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function mbe({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(kS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function F5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>I5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function I5(e,t){return e.meta.short===t.number}function L5(e){return hbe(O8(l8(e,`shorts`)).data)}function hbe(e){if(e===void 0)return[];try{let t=dbe.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function gbe(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function _be({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=V(),a=Ry(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=l8(c8(n,e),o?`audio_export`:`video`),c=c8(n,e),l=l8(c,`subtitles_srt`),u=l8(c,`subtitles_vtt`),d=l8(c,`youtube_description`),f=l8(c,`youtube_tags`),p=l8(c,`audio_mp3`),m=l8(c,`audio_m4b`),g=F5(c,`short_video`,L5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=g8(s),v=g8(vbe(n)),y=ybe(t.id,d,f,s?.durationMs??null),b=g8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=dF(e.progressCurrent??0,e.progressTotal??0);return jx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await M0(i,{projectId:t.id,asset:C3(s),folder:_?.folder??null});e.opened||a(`${N0} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(b8,{children:r}):(0,h.jsxs)(b8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:QP(e,t.config)?`Preparing subtitles · ${String(dF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:rF(nF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)(Y8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(c0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,square:t.format===`1:1`,className:t.format===`9:16`?`max-w-[360px]`:t.format===`1:1`?`max-w-[640px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(E8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(D8,{children:[uF(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:ck(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||PO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:PO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function vbe(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function ybe(e,t,n,r){let{api:i}=V(),a=O8(t).data,o=O8(n).data,s=I({queryKey:H.youtubeEdits(e),queryFn:()=>zs(i,e),enabled:t!==void 0});return a===void 0?[]:bbe(S5(x5(b5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function bbe(e,t){return y5(e,t).text.split(`
301
+ `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:v5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function xbe(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(Zve,{...e});case`audio`:return(0,h.jsx)(sye,{...e});case`images`:return(0,h.jsx)(Iye,{...e});case`video`:return(0,h.jsx)(_be,{...e});case`document`:return(0,h.jsx)(dye,{...e});case`research`:case`thumbnail`:return null}}Y({summary:K(),chapters:J(Y({start:JD([K(),q()]),title:K()})),hashtags:J(K()),tags:J(K()),pinnedComment:K(),titles:J(K())});function R5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var z5=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`});function B5(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function Sbe({projectId:e}){let{api:t}=V(),n=_(),r=Ry(),i=[`studio`,`project-releases`,e],a=I({queryKey:i,queryFn:()=>us(t,e)}),[o,s]=(0,m.useState)({}),c=(I({queryKey:[`studio`,`releases`,`swap`,8],queryFn:()=>cs(t,8)}).data?.entries??[]).flatMap(t=>t.project===null||t.project.id===e?[]:[{id:t.project.id,title:t.project.title,at:t.at}]),l=L({mutationFn:n=>ls(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),n.invalidateQueries({queryKey:[`studio`,`project-releases`,t]}),r(`Swapped release times with ${c.find(e=>e.id===t)?.title??`the other video`}; each one's shorts moved with it.`,`success`)},onError:e=>r(`The times weren't swapped: ${e.message}`,`error`)}),u=L({mutationFn:n=>ds(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),s(e=>{let{[t.short]:n,...r}=e;return r}),r(t.at===null?`Not scheduled: set its time in Studio yourself, or pick one here.`:`Saved the release time.`,`success`)},onError:e=>r(`The time wasn't saved: ${e.message}`,`error`)});if(a.data===void 0)return null;let{items:d,free:f,leadHours:p}=a.data;return d.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Release`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{as:`h3`,size:`small`,title:`Release`,meta:`Upload and schedule each one at least ${String(p)} hours before it goes out.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:d.map(e=>{let t=e.short===0?`Long video`:`Short ${String(e.short)}`,n=o[e.short]??(e.at===null?``:B5(e.at)),r=n!==(e.at===null?``:B5(e.at)),i=!e.onYoutube&&e.uploadBy!==null&&Date.parse(e.uploadBy)<Date.now();return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,h.jsx)(`span`,{className:`w-[86px] shrink-0 text-small font-semibold`,children:t}),(0,h.jsx)(zB,{"aria-label":`${t}: release`,type:`datetime-local`,className:`w-[210px]`,value:n,onChange:t=>{let n=t.currentTarget.value;s(t=>({...t,[e.short]:n}))}}),r?(0,h.jsx)(B,{type:`button`,size:`small`,disabled:n===``||u.isPending,onClick:()=>u.mutate({short:e.short,at:new Date(n).toISOString()}),children:`Save`}):null,e.short===0&&f.length>0?(0,h.jsx)(VB,{"aria-label":`Take a free time of the posting plan`,className:`w-[230px]`,value:``,onChange:e=>{let t=f.find(t=>t.longAt===e.currentTarget.value);t!==void 0&&u.mutate({short:0,at:t.longAt,line:t.row})},options:[{value:``,label:`Free plan times…`},...f.map(e=>({value:e.longAt,label:z5.format(new Date(e.longAt))}))]}):null,e.at!==null&&e.short===0&&c.length>0?(0,h.jsx)(VB,{"aria-label":`Swap release times with another video`,className:`w-[260px]`,value:``,disabled:l.isPending,onChange:e=>{e.currentTarget.value!==``&&l.mutate(e.currentTarget.value)},options:[{value:``,label:`Swap with…`},...c.map(e=>({value:e.id,label:`${e.title.split(` | `)[0]??e.title} · ${z5.format(new Date(e.at))}`}))]}):null,e.at!==null&&e.short===0?(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:u.isPending,onClick:()=>u.mutate({short:0,at:null}),children:`Not scheduled`}):null,(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.onYoutube?(0,h.jsx)(kS,{children:`✓ on YouTube`}):e.uploadBy===null?`No time yet`:i?(0,h.jsx)(kS,{tone:`failed`,children:`Late · upload now`}):`Ready to upload`})]},e.short)})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Every video's times are together in`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`releases`},children:`Calendar → Releases`}),`.`]})]})}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function Cbe({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=V(),a=_(),o=c8(n,e),s=l8(o,`youtube_description`),c=l8(o,`youtube_tags`),l=l8(o,`youtube_pinned_comment`),u=l8(o,`youtube_titles`),d=O8(s).data,f=O8(c).data,p=O8(l).data,g=O8(u).data,v=(0,m.use)(K8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=I({queryKey:H.youtubeEdits(t.id),queryFn:()=>zs(i,t.id)}),T=I({queryKey:H.projectChannelLinks(t.id),queryFn:()=>Rs(i,t.id)}),[E,D]=(0,m.useState)(),O=Ry(),k=e=>a.setQueryData(H.youtubeEdits(t.id),e),A=L({mutationFn:e=>Bs(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),j=(0,m.useRef)({});if(jx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:nP.copyDescription,run:()=>j.current.description===void 0?O(`The description has not been written yet.`,`info`):j.current.description()}),jx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>j.current.tags===void 0?O(`The tags have not been written yet.`,`info`):j.current.tags()}),jx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>j.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):j.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let M=d===void 0?void 0:b5(d,f??``,{pinnedComment:p,titles:g}),ee=x5(M,w.data?.fields??{}),N=S5(ee),P=Ej(T.data?.links??[],w.data?.links??[]),F=l8(o,`video`),te=y5(N.chapters,F?.durationMs===null||F?.durationMs===void 0?void 0:F.durationMs/1e3),ne=zye(te.adjustments),re=Oj(Vye({...N,chapters:te.text}),P),ie=Oj(N.tags,P),ae=Oj(N.pinnedComment,P),oe=[...re.unknown,...ie.unknown,...ae.unknown].filter((e,t,n)=>n.findIndex(t=>Tj(t)===Tj(e))===t),se=G5(ie.text),ce=M!==void 0,le=ae.text.trim()!==``,ue=N.titles.split(`
302
+ `).map(e=>e.trim()).filter(e=>e!==``),de=ce&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0,fe=(e,t)=>{let n=`Couldn't copy the ${t}. Select the text in the YouTube section and copy it.`;if(!navigator.clipboard){D({text:n,tone:`error`}),O(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),O(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),O(n,`error`)})};j.current=ce?{description:()=>fe(re.text,`description`),tags:()=>fe(ie.text,`tags`),...le?{pinnedComment:()=>fe(ae.text,`pinned comment`)}:{}}:{};let pe=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,me=(e,t)=>(0,h.jsx)(wbe,{label:V5[e],value:ee[e],links:P,disabled:!ce||A.isPending,multiline:e!==`hashtags`,placeholder:ce&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again to have one written, or Edit to write your own.`:ce&&e===`titles`?`Written before other titles existed. Use Write again to have two written, or Edit to write your own, one per line.`:pe,render:t,onSave:t=>A.mutate({field:e,edit:{text:t,base:M?.[e]??``},done:`Saved your ${V5[e].toLowerCase()}.`}),onUseGenerated:()=>A.mutate({field:e,edit:null,done:`The ${V5[e].toLowerCase()} follows the generated text again.`}),onKeepMine:(t,n)=>A.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${V5[e].toLowerCase()}.`})},e);return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`@container flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sr-only`,children:`YouTube`}),(0,h.jsxs)(`div`,{className:`flex min-w-0 max-w-[80ch] flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:ce?()=>fe(re.text,`description`):void 0,keyshortcuts:Ux(nP.copyDescription),count:ce?`${String(re.text.length)} / ${String(v6)} characters`:void 0,over:re.text.length>v6,main:!0,again:de}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[me(`summary`),me(`chapters`,()=>te.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(W5,{text:te.text,links:P})),ne===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:ne}),me(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:ce?()=>fe(ie.text,`tags`):void 0,count:ce?`${String(R5(se))} / 500 characters`:void 0,over:R5(se)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:me(`tags`,e=>(0,h.jsx)(Tbe,{text:e,links:P}))}),(0,h.jsx)(U5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:ce&&le?()=>fe(ae.text,`pinned comment`):void 0,count:ce&&le?`${String(ae.text.length)} / 500 characters`:void 0,over:ae.text.length>500,again:de}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[me(`pinnedComment`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Post it under the video once it is published, then choose Pin in the comment's menu.`})]}),(0,h.jsx)(U5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:ce&&ue.length>0?()=>fe(ue.join(`
303
+ `),`other titles`):void 0,count:ce&&ue.length>0?`${String(ue.length+1)} titles to test`:void 0,over:ue.some(e=>e.length>100),again:de}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[me(`titles`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`For YouTube's A/B Testing beside the title, with this project's own title "${t.title}". One per line.`})]})]})]}),oe.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${oe.map(e=>`{{${e}}}`).join(`, `)}, so it stays as typed. Add it under Channel links on `,T.data===void 0?`the channel's Brand tab`:(0,h.jsx)(fa,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${oe.some(e=>Tj(e)===Tj(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(Sbe,{projectId:t.id}),(0,h.jsx)(qye,{projectId:t.id,shorts:n.filter(e=>e.role===`short_video`).length}),(0,h.jsx)(Ebe,{projectId:t.id,edits:w.data,onSaved:e=>{k(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(v1,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(Hy,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags, pinned comment and other titles. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function U5({id:e,label:t,copy:n,count:r,over:i,keyshortcuts:a,main:o=!1,again:s,open:c,onToggle:l}){return(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-3 border-b border-line pb-2`,children:[(0,h.jsx)(`h4`,{id:e,className:`m-0 text-title-3 font-semibold text-ink`,children:l===void 0?t:(0,h.jsxs)(B,{type:`button`,variant:`quiet`,"aria-expanded":c===!0,onClick:l,className:`-ml-2 h-auto px-2 py-1 text-title-3 font-semibold text-ink`,children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75,className:z(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:z(`text-small tabular-nums`,i?`text-danger`:`text-ink-3`),children:i?`${r}, over YouTube's limit`:r}),(0,h.jsx)(`span`,{className:`flex-1`}),s===void 0?null:(0,h.jsxs)(B,{type:`button`,variant:`secondary`,"aria-label":`Write the ${t.toLowerCase()} again`,onClick:s,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(B,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function wbe({label:e,value:t,links:n,disabled:r,multiline:i,placeholder:a,render:o,onSave:s,onUseGenerated:c,onKeepMine:l}){let u=(0,m.useId)(),[d,f]=(0,m.useState)(),[p,g]=(0,m.useState)(!1),_=d!==void 0,v=e.toLowerCase(),y=e in H5?H5[e]:void 0;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h5`,{id:`${u}-label`,className:`sl-kicker text-ink-3`,children:e}),y===void 0?null:(0,h.jsx)(U,{id:y,label:v,className:`-my-1`})]}),t.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),t.edited&&!_?(0,h.jsx)(B,{type:`button`,variant:`quiet`,size:`small`,disabled:r,"aria-label":`Use the generated ${v}`,onClick:c,children:`Use generated`}):null,(0,h.jsxs)(B,{type:`button`,variant:`quiet`,size:`small`,disabled:r||_,"aria-label":`Edit ${v}`,onClick:()=>f(t.text),children:[(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),t.pending===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-l-2 border-waiting pl-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`p`,{className:`text-small text-ink`,children:`New generated version available.`}),(0,h.jsx)(B,{type:`button`,disabled:r,"aria-label":`Use the new generated ${v}`,onClick:c,children:`Use it`}),(0,h.jsx)(B,{type:`button`,disabled:r,"aria-label":`Keep my ${v}`,onClick:()=>l(t.text,t.pending??``),children:`Keep mine`}),(0,h.jsx)(B,{type:`button`,variant:`quiet`,"aria-expanded":p,"aria-label":`${p?`Hide`:`View`} the ${v} diff`,onClick:()=>g(e=>!e),children:p?`Hide diff`:`View diff`})]}),p?(0,h.jsx)(b4,{before:t.text,after:t.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),_?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${u}-edit`,className:`sr-only`,children:e}),i?(0,h.jsx)(BB,{id:`${u}-edit`,rows:e===`Chapters`?8:5,value:d,onChange:e=>f(e.currentTarget.value)}):(0,h.jsx)(zB,{id:`${u}-edit`,value:d,onChange:e=>f(e.currentTarget.value)}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(B,{type:`button`,variant:`primary`,disabled:r,onClick:()=>{s(d),f(void 0)},children:[`Save `,v]}),(0,h.jsx)(B,{type:`button`,variant:`secondary`,onClick:()=>f(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${u}-label`,className:z(`min-w-0 whitespace-pre-wrap break-words text-small`,t.text===``?`text-ink-3`:`text-ink`),children:t.text===``?a:o===void 0?(0,h.jsx)(W5,{text:t.text,links:n}):o(t.text)})]})}function W5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:Dj(e,t).map(e=>{let t=String(n);return n+=e.kind===`text`?e.text.length:e.raw.length,e.kind===`text`?(0,h.jsx)(`span`,{children:e.text},t):e.url===void 0?(0,h.jsx)(`mark`,{title:`No link named ${e.name}`,className:`rounded-[2px] bg-waiting/25 px-0.5 text-ink`,children:e.raw},t):(0,h.jsx)(`span`,{title:e.raw,className:`underline decoration-dotted underline-offset-[3px]`,children:e.url},t)})})}function G5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function Tbe({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:G5(e).map((e,n)=>(0,h.jsx)(`li`,{className:`rounded-full border border-line bg-raised px-2 py-0.5 text-small text-ink`,children:(0,h.jsx)(W5,{text:e,links:t})},n))})}function Ebe({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=V(),a=(0,m.useId)(),o=t?.links.find(e=>Tj(e.name)===Tj(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=L({mutationFn:()=>{let n=(t?.links??[]).filter(e=>Tj(e.name)!==Tj(Sj));return Vs(i,e,l.trim()===``?n:[...n,{name:Sj,url:l.trim()}])},onSuccess:e=>{c(void 0),n(e)},onError:e=>r(e.message)});return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[260px] flex-1 flex-col gap-1 sm:max-w-[520px]`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{className:`sl-field__label`,htmlFor:a,children:`Previous video for this project`}),(0,h.jsx)(U,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(zB,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(B,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var K5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function Dbe({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=V(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(!1),g=(0,m.useRef)(!0),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=JSON.stringify([t,n.map(e=>[e.stage,e.checkpointId]).toSorted()]),b=s!==null&&s.baseIdentity!==y,x=s?.stages??n.map(e=>e.stage),S=K5.some(({stage:e})=>x.includes(e)!==n.some(t=>t.stage===e)),C=b||d!==null&&d.kind!==`success`,w=b?{kind:`refused`,message:`Checkpoint choices changed elsewhere. Press Reload checkpoint choices before saving, then make your change again.`}:d;(0,m.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,m.useEffect)(()=>{(d||b)&&_.current?.focus()},[d,b]);async function T(){if(!(p.current||!S||C)){p.current=!0,u(!0);try{let n=await Fhe(o,e,{revisionId:t,stages:x});if(!g.current)return;n.ok?n.value.revisionId===t?(a(n.value),c(null),f({kind:`success`,message:`Checkpoint choices saved.`})):f({kind:`refused`,message:`The project was edited elsewhere. Press Reload checkpoint choices to see its current choices.`}):f({kind:`refused`,message:n.message})}catch(e){g.current&&f({kind:`transport`,message:`${_o(e instanceof Error?e.message:`Slopify didn't confirm the change`)} It may or may not have saved. Press Reload checkpoint choices before changing anything else.`})}finally{p.current=!1,g.current&&u(!1)}}}async function E(){if(!p.current){p.current=!0,u(!0);try{let e=await i();g.current&&e&&(c(null),f(null),v.current?.focus())}finally{p.current=!1,g.current&&u(!1)}}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(`fieldset`,{ref:v,tabIndex:-1,className:`space-y-2`,...zb,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(U,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),K5.map(({stage:e,name:t})=>{let n=r.find(t=>t.kind===e),i=n?.state===`pending`&&(e===`video`?n.source!==`off`||r.some(e=>e.kind===`audio`&&e.source!==`off`&&e.state!==`skipped`):(n.source??`generate`)===`generate`);return(0,h.jsxs)(`label`,{className:`flex min-h-10 items-center gap-3`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),disabled:!i||l||C,onChange:t=>{c({baseIdentity:s?.baseIdentity??y,stages:t.target.checked?[...x,e]:x.filter(t=>t!==e)}),f(null)}}),`Before `,t]},e)})]}),w?(0,h.jsx)(`p`,{ref:_,tabIndex:-1,role:w.kind===`success`?`status`:`alert`,children:w.message}):null,(0,h.jsx)(B,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(B,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var q5=e=>e.charAt(0).toUpperCase()+e.slice(1);function Obe(e){return e.revisionId===null?null:(0,h.jsx)(kbe,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function kbe({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=V(),o=_(),s=I({queryKey:c3(e,t),queryFn:()=>u3(a,e),retry:!1}),c=s.data,l=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t?e.data.value:void 0},u=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t};return s.isPending?null:s.error||c?.ok===!1?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:s.error?.message??(c?.ok===!1?c.message:`Checkpoints couldn't be loaded. Press Reload checkpoints.`)}),(0,h.jsx)(B,{onClick:()=>void u(),children:`Reload checkpoints`})]}):c?.ok?c.value.revisionId===t?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col gap-5`,children:[(0,h.jsx)(W,{title:`Review checkpoints`,size:`small`,className:`pb-0`}),n?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`The project is paused. Continue the run before approving held work.`}):null,(0,h.jsx)(Dbe,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(c3(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:H.project(e)}),o.invalidateQueries({queryKey:H.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(Abe,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,...a.checkpointId===i?{inRail:!0}:{}},`${a.checkpointId}:${a.fingerprint}`))]}):(0,h.jsx)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The project was edited after these checkpoints loaded. Press Reload checkpoints before approving.`})}):null}function Abe({gate:e,disabled:t,reload:n,inRail:r=!1}){let{api:i}=V(),a=_(),o=(0,m.useRef)(null),s=(0,m.useRef)(!1),c=(0,m.useRef)(!0),l=(0,m.useRef)(null),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(null);(0,m.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,m.useEffect)(()=>{f!==null&&l.current?.focus()},[f]);let g=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function v(){if(!(s.current||t||!g||f?.kind===`refused`||f?.kind===`success`)){s.current=!0,d(!0),o.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await d3(i,e.projectId,e.checkpointId,o.current);o.current=null,c.current&&p(t.ok?{kind:`success`,message:t.value.replayed?`Checkpoint already approved.`:`Checkpoint approved. Work will run when its dependencies are ready.`}:{kind:`refused`,message:t.message}),a.invalidateQueries({queryKey:s3(e.projectId)}),a.invalidateQueries({queryKey:H.project(e.projectId)}),a.invalidateQueries({queryKey:H.projects})}catch(e){c.current&&p({kind:`transport`,message:`${_o(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{s.current=!1,c.current&&d(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(W,{as:`h3`,title:`${q5(e.stage)} checkpoint`,className:`pb-0`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`released`&&e.approvedAt!==null?`Authorized for this revision. Work can run when dependencies are ready and the project is resumed.`:e.state===`satisfied`?`Checkpoint satisfied. Its reviewed work is complete.`:e.state===`invalidated`||e.fingerprint!==e.currentFingerprint?`Inputs changed. Review the current revision before approving.`:g?`${q5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Reviewed revision: `,e.revisionId]}),e.dependents.length?(0,h.jsx)(`ul`,{"aria-label":`Dependent work`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:e.dependents.map(e=>(0,h.jsx)(`li`,{className:`sl-chip`,children:q5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),f?(0,h.jsx)(`p`,{ref:l,tabIndex:-1,role:f.kind===`success`?`status`:`alert`,className:f.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:f.message}):null,g&&r&&f===null?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Its approval is the project's next action, in the right rail.`}):g?(0,h.jsx)(B,{className:`self-start`,disabled:t||u||f?.kind===`refused`||f?.kind===`success`,onClick:()=>void v(),children:u?`Approving…`:f?.kind===`transport`?`Retry approval`:`Approve ${q5(e.stage)} checkpoint`}):null,f?.kind===`refused`?(0,h.jsx)(B,{className:`self-start`,onClick:async()=>{await n()&&p(null)},children:`Reload checkpoints`}):null]})}function jbe({projects:e,queryKey:t}){let{api:n}=V(),r=_(),i=Ry(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=L({mutationFn:e=>Ro(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t.title}" (${String(e.files)} working file${e.files===1?``:`s`}).`,`success`)},onError:e=>c(e.message),onSettled:()=>r.invalidateQueries({queryKey:t})}),u=e.toSorted((e,t)=>t.bytes-e.bytes);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-2 flex items-center gap-1 text-small text-ink-2`,children:[`Keep outputs only frees a finished project's working files.`,(0,h.jsx)(U,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(PH,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(FH,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[Y5(e.bytes),` · outputs `,Y5(e.outputsBytes),` · working files `,Y5(e.workingBytes)]}),actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:!e.finished||e.removableBytes===0||l.isPending,title:e.finished?e.removableBytes===0?`No working files left to remove.`:`Frees ${Y5(e.removableBytes)}.`:`Available once the project has finished.`,onClick:()=>o(e),children:l.isPending&&l.variables?.id===e.id?`Removing…`:`Keep outputs only`})},e.id))}),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:s}),(0,h.jsx)(Hy,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:J5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function J5(e,t){return`This removes ${String(e)} working file(s) and frees ${Y5(t)}: the images, narration parts, subtitle timing and render settings the project was made from. The video, shorts, thumbnail, article, description and document stay, and so does anything you uploaded. If you change this project later (edit an image, a caption style or the narration, or re-render), Slopify has to make those files again first, which takes time and uses provider credits.`}function Y5(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var X5=e=>[`storage`,`project`,e];function Mbe({projectId:e,title:t,status:n,sample:r}){let{api:i}=V(),a=_(),o=Ry(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=I({queryKey:[...X5(e),n],queryFn:()=>Lo(i,e),enabled:l&&!r}),d=L({mutationFn:()=>Ro(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t}". The outputs are all still here.`,`success`),onError:e=>o(`The working files of "${t}" weren't removed: ${e.message}`,`error`),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:X5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:H.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=Y5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:`Free space`,meta:`Outputs ${Y5(f.outputsBytes)} · working files ${Y5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Free ${p}: keep the outputs, drop the working files`,disabled:d.isPending,disabledReason:`Removing the working files…`,onClick:()=>c(!0),children:d.isPending?`Removing…`:`Free ${p}`})}),(0,h.jsx)(Hy,{open:s,title:`Free ${p} from "${t}"?`,consequence:J5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function Nbe({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=e.status===`pending`&&e.setAside===!0?{tone:`done`,word:`Kept as is`}:Ibe(e.status);return(0,h.jsx)(XK,{crumb:(0,h.jsxs)(fa,{to:`/projects`,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75}),`Projects`]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[Lbe(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(OS,{tone:s.tone,children:[s.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`Project: ${s.word}`})]}),a!==void 0&&Pbe(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(U,{id:`project.next-chapter`}),a.error===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`max-w-[320px] text-small text-danger`,children:a.error})]}):null,(0,h.jsxs)(B,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(Zc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(u8,{modal:!1,children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(Py,{label:`More project actions`,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(f8,{children:i.map(e=>(0,h.jsx)(Fbe,{item:e},e.id))})]})]})})}function Pbe(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function Fbe({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(Ove,{}):null,(0,h.jsx)(p8,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function Ibe(e){switch(e){case`running`:return{tone:`running`,word:`Running`};case`paused`:return{tone:`waiting`,word:`Paused`};case`failed`:return{tone:`failed`,word:`Failed`};case`partial`:return{tone:`waiting`,word:`Done with problems`};case`done`:return{tone:`done`,word:`Done`};case`canceled`:return{tone:`off`,word:`Canceled`};case`pending`:return{tone:`off`,word:`Queued`}}}function Lbe(e,t){let n=e.config.articlePrompt,r=t===void 0||t.some(e=>e.name===n),i=n===void 0||n===``?void 0:r?n:`${n} (deleted)`,a=e.config.voices?.book;return[a===void 0?void 0:AA(a),i,e.format,`started ${Wu(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function Rbe({projectId:e}){let{api:t}=V(),n=I(cb(t,e));return n.error===null?n.data===void 0?(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading run cost`,className:`flex flex-col gap-8`,children:[(0,h.jsx)(`span`,{className:`h-16 max-w-3xl rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`})]}):(0,h.jsx)(Ube,{cost:n.data}):(0,h.jsx)(aI,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var zbe=new Set([`done`,`partial`,`failed`,`canceled`]);function Bbe({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=t===`running`,a=r?.current===!0&&!zbe.has(t),[o,s]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[i]),!a||r===null)return null;let c=r.workingMs+(i?Math.max(0,o-n):0),l=i?Jbe(c):o7(c);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:i?`inline-flex items-center gap-1.5 rounded-full bg-accent/15 px-2.5 py-0.5 font-semibold text-ink tabular-nums`:`inline-flex items-center gap-1.5 rounded-full bg-surface-2 px-2.5 py-0.5 font-semibold text-ink-2 tabular-nums`,children:[(0,h.jsx)(Qc,{"aria-hidden":`true`,strokeWidth:2,className:`size-3.5 shrink-0`}),i?`Working · ${l}`:`${l} of work so far`]})]})}var Vbe=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:YP[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:o7(e.wallMs)}],Hbe=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:Kbe(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>t7.format(e.calls)}];function Z5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function Ube({cost:e}){if(e.calls===0&&e.byStage.length===0)return(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Nothing has been spent yet. The cost of each provider call appears here as the run makes it.`});let t=e.byModel.some(e=>e.onPlan),n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({plan:e,window:t})):[]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{"aria-label":`Run cost summary`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(x2,{children:[(0,h.jsx)(S2,{value:a7(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(S2,{value:`~${a7(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${Z5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${n7.format(t.usedPercent)}%`;return(0,h.jsx)(S2,{value:r,label:`of ${n}`,children:(0,h.jsx)(C2,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${n7.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(S2,{value:o7(e.run.workingMs),label:`this run's working time`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 text-small text-ink-2`,children:[e.unpriced>0?(0,h.jsx)(`p`,{className:`m-0`,children:`Plus ${i7(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:Wbe(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:Gbe(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(W,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Run cost by stage`,columns:Vbe,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(W,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Run cost by model`,columns:Hbe,rows:e.byModel,rowKey:e=>`${e.provider}/${e.model}/${e.kind}`})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In total: ${e7(e.totals)||`no reported usage`} · ${o7(e.totals.wallMs)} working, over every run.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Priced from the model catalogue${e.catalogueDate===null?``:` of ${e.catalogueDate}`} when each call finished. Retries that failed are not charged here; taxes and included credits are not counted.`})]})]})}function Wbe(e){let t=e.apiEquivalent??0;if(t===0&&e.apiUnpriced>0)return`CLI calls: $0 on your plan · no API price is listed for their models.`;let n=e.apiUnpriced>0?` (plus ${i7(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${a7(t)} via API${n}.`}function Gbe(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=Z5(t.kind),r=t.usedPercent<1?`under 1%`:`~${n7.format(t.usedPercent)}%`,i=`now at ${n7.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${Ybe(t.resetsAt)}`}`;return`This run used ${r} of your ${n} ${e.name} limit (${i}).`}).join(` `):`${e.name} did not report its plan limits for this run, so the share it used is not known.`}function Q5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${a7(e.cost)} + unknown`:a7(e.cost)}function $5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${a7(e.apiEquivalent)}`}function Kbe(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function e7(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${r7(e.tokensIn)} in / ${r7(e.tokensOut)} out tokens${e.cachedTokens>0?` (${r7(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${r7(e.characters)} characters`),e.images>0&&t.push(i7(e.images,`image`)),e.seconds>0&&t.push(`${t7.format(e.seconds)} s of video`),t.join(` · `)}var t7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),n7=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),qbe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function r7(e){return e<1e4?t7.format(e):qbe.format(e)}function i7(e,t){return`${t7.format(e)} ${t}${e===1?``:`s`}`}function a7(e){return e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function Jbe(e){let t=Math.max(0,Math.floor(e/1e3)),n=e=>String(e).padStart(2,`0`);return`${String(Math.floor(t/3600))}:${n(Math.floor(t%3600/60))}:${n(t%60)}`}function o7(e){let t=Math.round(e/1e3);if(t<60)return`${t} s`;let n=Math.floor(t/60);return n<60?`${n} min ${t%60} s`:`${Math.floor(n/60)} h ${n%60} min`}function Ybe(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function Xbe({project:e,revisionId:t,stages:n,outputs:r}){let i=r.filter(e=>e.role===`image`).sort((e,t)=>(e.meta.index??0)-(t.meta.index??0)),a=n.find(e=>e.kind===`article`),o=(0,m.use)(f3);return(0,h.jsx)(`div`,{className:`flex min-w-0 flex-col`,children:(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(W,{title:`Article`}),a?.state===`running`?(0,h.jsx)(D3,{projectId:e.id,stage:`article`,className:`mb-6`}):a?.state===`done`?(0,h.jsxs)(`p`,{className:`mb-6 flex flex-wrap items-center gap-3 text-small text-ink-2`,children:[`The article is written.`,o===void 0?null:(0,h.jsx)(B,{variant:`secondary`,size:`small`,onClick:()=>o(`output`),children:`Read it`})]}):(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:a===void 0||a.state===`skipped`?`This project has no article.`:`The article appears here as it is written.`}),(0,h.jsx)(W,{title:`Narration`}),(0,h.jsx)(Qbe,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(W,{title:`Images`}),i.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The images appear here as each one is drawn.`}):(0,h.jsx)(u0,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(Zbe,{output:t,aspect:l5(e.format)},t.id))})]})})}function Zbe({output:e,aspect:t}){let n=g8(e);if(n===void 0)return null;let r=e.meta.index===void 0?``:` ${String(e.meta.index)}`;return(0,h.jsx)(`li`,{className:`min-w-0`,children:(0,h.jsx)(l0,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function Qbe({projectId:e,revisionId:t,audio:n,outputs:r}){let i=r.find(e=>e.role===`audio_levelled`&&e.meta.segment===`body`)??r.find(e=>e.role===`audio_body`),a=g8(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s7,{projectId:e,revisionId:t}),(0,h.jsx)(U8,{projectId:e})]}):a===void 0?(0,h.jsx)(s7,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)(Y8,{label:`Body narration`,src:a.url})})}var $be=240;function s7({projectId:e,revisionId:t}){let{api:n}=V(),r=I({queryKey:Gy(e,t),queryFn:()=>rb(n,e),enabled:t!==null}),i=(r.data?.pieces??[]).flatMap(e=>e.peaks),a=(r.data?.pieces??[]).reduce((e,t)=>e+t.seconds,0),o=Math.max(1,Math.ceil(i.length/$be)),s=[];for(let e=0;e<i.length;e+=o)s.push(Math.max(...i.slice(e,e+o)));return(0,h.jsxs)(`div`,{className:`mb-6`,children:[(0,h.jsx)(`div`,{role:`img`,"aria-label":s.length===0?`No narration yet`:`Narration so far: ${o7(a*1e3)}`,className:`flex h-16 items-center gap-px overflow-hidden rounded-control border border-line bg-raised px-2`,children:s.map((e,t)=>(0,h.jsx)(`span`,{className:`w-[3px] shrink-0 rounded-full bg-accent`,style:{height:`${String(Math.max(4,Math.round(e*100)))}%`}},t))}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:r.error?r.error.message:s.length===0?`The waveform grows as each part of the narration is spoken.`:`${o7(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function exe({projectId:e,title:t,open:n,onClose:r}){let{api:i}=V(),a=_(),o=Ry(),s=Dx(),[c,l]=(0,m.useState)(``),u=L({mutationFn:()=>Ao(i,[e],c),onSuccess:()=>{a.invalidateQueries({queryKey:H.projects}),o(`Moved "${t}" to ${s.channels.find(e=>e.id===c)?.name??`the channel`}.`,`success`),r()},onError:e=>o(`The project wasn't moved: ${e.message}`,`error`)});return(0,h.jsx)(Vy,{open:n,onOpenChange:e=>{e||r()},title:`Move to channel`,description:`The project shows in that channel's list and uses its brand and playlists. Nothing it made changes.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:r,children:`Cancel`}),(0,h.jsx)(B,{type:`button`,disabled:c===``||u.isPending,onClick:()=>u.mutate(),children:`Move`})]}),children:(0,h.jsx)(LB,{label:`Channel`,children:(0,h.jsx)(VB,{value:c,onChange:e=>l(e.currentTarget.value),options:[{value:``,label:`Choose a channel`},...s.channels.map(e=>({value:e.id,label:e.name}))]})})})}function txe(e){let t=[],n=[],r=0,i=()=>{let e=n[0],r=n.at(-1);e!==void 0&&r!==void 0&&t.push({start:e.start,end:r.end,text:c7(n.map(e=>e.text)),...e.speaker===void 0?{}:{speaker:e.speaker}}),n=[]};for(let t of e){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<r-.001||t.end<=t.start)throw Error(`The saved caption timing is damaged. Use More → Render the video again in the Video section to time them again, then Try again.`);let e=n[0];e!==void 0&&(t.start-r>.7||t.speaker!==e.speaker||t.end-e.start>5||c7([...n.map(e=>e.text),t.text]).split(`
304
304
  `).length>2)&&i(),n.push({...t,text:t.text.replace(/\s+/g,` `).trim()}),r=t.end,/[.!?]["'’”)]*$/.test(t.text)&&i()}return i(),t}function c7(e){let t=[],n=``;for(let r of e)n!==``&&n.length+r.length+1>42&&(t.push(n),n=``),n=n===``?r:`${n} ${r}`;return n!==``&&t.push(n),t.join(`
305
- `)}function exe({cues:e,duration:t,onChange:n,onPending:r}){let i=(0,m.useId)(),[a,o]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[s,c]=(0,m.useState)(),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(r);d.current=r,(0,m.useEffect)(()=>{d.current(l)},[l]),(0,m.useEffect)(()=>()=>d.current(!1),[]);function f(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){c(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,o]of a.entries()){let a=o.start.trim()===``?NaN:Number(o.start),s=o.end.trim()===``?NaN:Number(o.end);if(r.has(o.id)){c(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(o.id),!Number.isFinite(a)||a<0||a<i){c(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=a||s>t){c(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(o.text.trim()===``){c(`Caption ${n+1}: enter caption text.`);return}e.push({id:o.id,text:o.text,start:a,end:s,...o.speaker===void 0?{}:{speaker:o.speaker}}),i=s}n(e),c(void 0),u(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(U,{id:`project.captions.editor`})]}),a.map((e,t)=>(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Caption `,t+1]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(BB,{id:`${i}-${e.id}-text`,value:e.text,onChange:n=>{u(!0),o(a.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(zB,{id:`${i}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{u(!0),o(a.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(zB,{id:`${i}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{u(!0),o(a.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:s}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:f,children:`Apply caption edits to draft`}),(0,h.jsx)(U,{id:`project.captions.apply`})]}),l?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function l7(e){return`imagePrompts.${String(e)}`}function u7(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function txe(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function nxe(e){let{from:t,to:n,content:r}=e,i=n.map(e=>t.findIndex(t=>t.name===e.name)),a=[],o={},s={};for(let[e,t]of Object.entries(r.promptTemplates))u7(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))u7(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=l7(t),l=i[t]??-1;if(l>=0){let t=l7(l);Object.hasOwn(r.promptTemplates,t)&&(o[n]=r.promptTemplates[t]??null);let i=e.rendered[t];i!==void 0&&(s[n]=i);continue}let u=e.body(c.name);if(u===void 0){a.push({field:`imagePrompts.${String(t)}.name`,message:`The image prompt "${c.name}" is not in the Library any more. Untick it under Images, or add it back on Library → Prompts.`});continue}o[n]=u,s[n]=FK(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=u7(r.imageDefinitions[e]?.templateKey);n===void 0||n>=t.length||c.set(n,[...c.get(n)??[],e])}let l={},u=[],d=[],f=(e,t)=>{let n=l7(e),r=o[n];return t===void 0?{source:`generate`,assetId:null,prompt:s[n]??null,templateKey:r==null?null:n}:{...t,source:`generate`,assetId:null,templateKey:t.templateKey??null}},p=(t,n,r)=>Array.from({length:Math.max(0,n)},()=>{let n=e.key();return l[n]=f(t,r),u.push(n),n}),m=[];for(let e of r.imageOrder){let a=r.imageDefinitions[e];if(a===void 0)continue;let o=u7(a.templateKey);if(o===void 0||o>=t.length){l[e]=a,m.push(e);continue}let s=i.indexOf(o);if(s===-1){d.push(e);continue}let u=c.get(o)??[],f=t[o]?.number!==n[s]?.number,h=f?n[s]?.number??0:u.length,g=u.indexOf(e);if(g>=h){d.push(e);continue}let _=a.templateKey===l7(s)?a:{...a,templateKey:l7(s)};l[e]=_,m.push(e),f&&g===Math.min(u.length,h)-1&&m.push(...p(s,h-u.length,_))}for(let[e,r]of n.entries()){let n=i[e]??-1,a=n>=0?c.get(n)??[]:[];n>=0&&(a.length>0||t[n]?.number===r.number)||m.push(...p(e,r.number,void 0))}return{ok:!0,content:{...r,imageOrder:m,imageDefinitions:l,promptTemplates:o},rendered:s,added:u,removed:d}}function rxe({edit:e,saved:t,prompts:n,problem:r,onChange:i}){let{config:a}=e;if(a.sources.images!==`generate`)return null;let o=n.filter(e=>e.kind===`image`);return(0,h.jsxs)(`section`,{"aria-label":`Image prompts`,className:`space-y-3`,children:[(0,h.jsx)(G3,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(ixe,{edit:e,saved:t,prompts:o,problem:r})]})}function ixe({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(txe(t,i))return a===void 0?null:(0,h.jsx)(d7,{children:a});let o=0,s=nxe({from:t,to:i,content:e.content,rendered:e.config.rendered,values:e.config.values,body:e=>n.find(t=>t.name===e)?.body,key:()=>`planned-${String(++o)}`});if(!s.ok)return(0,h.jsx)(d7,{children:s.fields.map(e=>e.message).join(` `)});let c=e=>`${String(e)} ${e===1?`image`:`images`}`,l=[...s.added.length>0?[`adds ${c(s.added.length)} to make`]:[],...s.removed.length>0?[`removes ${c(s.removed.length)}`]:[]];return(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsx)(d7,{children:a}),(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.length===0?`Saving keeps every image as it is.`:`Saving ${l.join(` and `)}. The other images are kept; the new ones are made when you remake outdated outputs.`})]})}function d7({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function axe({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:Zk(r)),o=r?.source===`upload`?[...Wk,`upload`]:Wk,s=i===void 0?[]:[...cxe(i)];return(0,h.jsx)(s2,{value:i,inherit:`None`,sources:o,offerNone:!1,problem:e=>t(`ambientBed.${e}`)??s.find(t=>t.field===e)?.message,onChange:t=>{a(t);let r=Qk(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function oxe({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...JO,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(T6,{value:i,problem:e=>t(`loudness.${e}`),onChange:t=>{a(t);let{loudness:r,...i}=e.config;n({...e,config:t.enabled?{...i,loudness:{videoLufs:t.videoLufs,audioFilesLufs:t.audioFilesLufs}}:i})}})}function sxe({edit:e,problem:t,onChange:n}){let[r,i]=(0,m.useState)(()=>({sentencePauseSeconds:String(e.config.sentencePauseSeconds??0),paragraphPauseSeconds:String(e.config.paragraphPauseSeconds??0)}));if(e.config.sources.audio!==`generate`)return null;let a=e=>{let t=j6(r[e]);return t===void 0?`Enter a number of seconds.`:pk(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(A6,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=j6(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function cxe(e){let t=Qk(e);return t===void 0?[]:Yk(t)}function lxe({edit:e,problem:t,onChange:n}){let r=(0,m.useId)(),{config:i}=e,a=i.imageScale,[o,s]=(0,m.useState)(()=>a===void 0?void 0:UO(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(BO(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=f7(t);l!==void 0&&n({...e,config:{...o,imageScale:{perHour:l,words:c},...a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})},u=i.imagePrompts.reduce((e,t)=>e+t.number,0),d=a===void 0?u:KO(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:f7(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(IO)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(VO(c))))} minutes of narration: ${String(d)} images${d>u?`, ${String(d-u)} more than the prompts' ${String(u)}`:`, which the prompts' Numbers already cover`}.`},g=t(`imageScale`)??void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,...zb,children:[(0,h.jsx)(Bb,{checked:o!==void 0,label:`More images for long videos`,describedBy:`${r}-line`,tip:`play.image-scale`,onChange:e=>l(e?{every:`minutes`,value:`2`}:void 0)}),o===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(Vb,{label:`How the rate is given`,value:o.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>l({every:e,value:uxe(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(zB,{"aria-label":o.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`w-[72px] tabular-nums`,"aria-invalid":p?.problem===!0,"aria-describedby":`${r}-line`,value:o.value,onChange:e=>l({every:o.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:o.every===`minutes`?`minutes`:`images per hour`})]}),g===void 0&&p===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:g!==void 0||p?.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:g??p?.text})]})}function f7(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?HO(t):void 0:t>=1&&t<=240?t:void 0}function uxe(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function dxe({edit:e,onChange:t}){let{config:n}=e;return n.sources.images!==`generate`||n.sources.article===`off`?null:(0,h.jsx)(`div`,{className:`flex flex-col items-start gap-2`,...zb,children:(0,h.jsx)(Bb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,config:{...a,...r?{imageScenes:!0}:{}}})}})})}function fxe({edit:e,view:t,imageKey:n,index:r}){let{api:i}=V(),a=e.content.imageDefinitions[n];if(a===void 0)return null;let o=t?.outputs.filter(e=>e.output.stageKind===`images`&&e.output.role===`image`)??[],s=o.find(e=>e.selected&&e.workKey===`image:${n}`),c=e.uploads?.some(e=>e.destination.kind===`image`&&e.destination.imageKey===n)??!1,l=a.source===`generate`||c||s?.assetId===a.assetId?s:o.find(e=>e.assetId===a.assetId&&e.available),u=l?.available===!0,d=!u&&(l!==void 0||a.source===`provide`&&a.assetId!==null),f=e.regenerate?.includes(`image:${n}`)===!0,p=c?u?`Replacement ready to save; previous image shown until Save`:`Replacement ready to save; preview available after Save`:f?`Made again after you press Save changes; the current image stays until then`:d?`Image file unavailable`:u?a.source===`provide`&&l!==s?`Provided image selected`:l.state===`review`?`Image retained; review required`:l.state===`outdated`?`Outdated image retained until rebuilt`:`Current image retained`:`No completed image yet`,m=u&&/\.(mp4|mov|m4v|webm|mkv)$/i.test(l.output.path);return(0,h.jsxs)(h.Fragment,{children:[!u||t===void 0?null:m?(0,h.jsx)(c0,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:j0(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(l0,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:j0(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}function p7(e,t,n){let r=t+n,i=e[t],a=e[r];if(i===void 0||a===void 0)return e;let o=[...e];return o[t]=a,o[r]=i,o}function pxe({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),{content:c}=e,l=zO(e.config),u=(0,m.useRef)(e);u.current=e;function d(e){let n=e.content.imageOrder.flatMap(t=>{let n=e.content.imageDefinitions[t];return n===void 0?[]:[n]}),r=e.content.imageOrder.length===0||e.config.sources.images===`off`?`off`:n.some(e=>e.source===`generate`)?`generate`:`provide`,i={...e,config:{...e.config,sources:{...e.config.sources,images:r,...r===`off`?{video:`off`}:{}}}};u.current=i,t(i)}function f(e,t){let n=i?.()??u.current,r=n.content.imageDefinitions[e];if(r===void 0)return;let a=r.templateKey??`image:${e}`;s(t=>({...t,[e]:(t[e]??0)+1})),d(O5({...n,...n.uploads===void 0?{}:{uploads:n.uploads.filter(t=>t.destination.kind!==`image`||t.destination.imageKey!==e)},content:{...n.content,imageDefinitions:{...n.content.imageDefinitions,[e]:{...r,templateKey:a}}}},a,t))}function p(e){let t=i?.()??u.current,n=t.content,r=crypto.randomUUID();d({...t,config:{...t.config,sources:{...t.config.sources,images:t.config.sources.images===`off`?`provide`:t.config.sources.images}},content:{...n,imageOrder:[...n.imageOrder,r],imageDefinitions:{...n.imageDefinitions,[r]:{source:`provide`,assetId:null,prompt:null}}},uploads:[...t.uploads??[],{stagedFileId:e.id,destination:{kind:`image`,imageKey:r}}]})}return(0,h.jsxs)(`section`,{"aria-label":`Edit images`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Images`}),(0,h.jsx)(U,{id:`project.images.editor`})]}),c.imageOrder.map((t,s)=>{let l=c.imageDefinitions[t];return l===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(fxe,{edit:e,view:r,imageKey:t,index:s}),l.source===`generate`?(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${t}-prompt`,children:[`Prompt for image `,s+1]}),(0,h.jsx)(U,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(BB,{id:`${a}-${t}-prompt`,value:l.templateKey===void 0||l.templateKey===null?l.prompt??``:c.promptTemplates[l.templateKey]??l.prompt??``,onChange:e=>f(t,e.target.value)})]}):null,l.source===`generate`&&l.templateKey==null?(0,h.jsxs)(B,{type:`button`,onClick:()=>f(t,l.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(k5,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??u.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&d({...n,regenerate:(n.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:[...(n.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t),{stagedFileId:e.id,destination:{kind:`image`,imageKey:t}}],content:{...r,imageDefinitions:{...r.imageDefinitions,[t]:{...a,source:`provide`,prompt:null,templateKey:null}}}})}},`${t}:${o[t]??0}:${e.config.sources.images===`off`}`),(0,h.jsxs)(B,{type:`button`,disabled:s===0,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(B,{type:`button`,disabled:s===c.imageOrder.length-1,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(B,{type:`button`,onClick:()=>{let n=c.imageOrder.filter(e=>e!==t);d({...e,config:n.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...c,imageOrder:n,imageDefinitions:Object.fromEntries(Object.entries(c.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t)})},children:[`Delete image `,s+1,c.imageOrder.length===1?` and turn Images and Video Off`:``]}),l.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(B,{type:`button`,onClick:()=>d({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(B,{type:`button`,onClick:()=>d({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(U,{id:`project.images.regenerate`})]}):null]},t)}),(0,h.jsx)(B,{type:`button`,disabled:c.imageOrder.length>=l,onClick:()=>{if(c.imageOrder.length>=l)return;let t=crypto.randomUUID();d({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...c,imageOrder:[...c.imageOrder,t],promptTemplates:{...c.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...c.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),c.imageOrder.length>=l?(0,h.jsxs)(`p`,{children:[`At most `,l,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(k5,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:p},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(k5,{label:`Add a video clip`,kind:`images`,accept:`video/mp4,video/quicktime,video/webm,video/x-matroska,.mp4,.mov,.m4v,.webm,.mkv`,onPending:e=>n(`clip:new`,e),onReady:p},`new-clip:${e.config.sources.images===`off`}`)]})]})}var mxe=Y({logicalKey:K().min(1),logicalText:K(),segment:X([`body`,`intro`,`outro`]),text:K()});function hxe(e,t){if(t==null)return e;let n=[...t.intro??[],...t.body??[],...t.outro??[]];return n.length===0?e:n.flatMap(t=>e.filter(e=>e.key===t))}function gxe(e){let t=new Map,n=new Set,r=0;for(let i of e.pieces){if(!i.selected||i.stageKind!==`audio`||i.piece.kind!==`chunk`)continue;let e;try{e=i.piece.payload===null?null:JSON.parse(i.piece.payload)}catch{r++;continue}let a=mxe.safeParse(e);if(!a.success){r++;continue}let{logicalKey:o,logicalText:s}=a.data;if(n.has(o)){r++;continue}let c=t.get(o);if(c!==void 0&&c.text!==s){r+=c.parts+1,t.delete(o),n.add(o);continue}t.set(o,{key:o,text:s,parts:(c?.parts??0)+1})}return{groups:[...t.values()],unmapped:r}}function _xe({view:e,edit:t,onChange:n,onPending:r,getEdit:i}){let a=(0,m.useId)(),{api:o}=V(),s=I({queryKey:[`narration-chunks`,e.revision.projectId,e.revision.id],queryFn:async()=>{let t=await Ape(o,e.revision.projectId,e.revision.id);return t.ok?t.value.chunks:null},staleTime:1/0}),c=gxe(e),l=hxe(c.groups,s.data),u=c.unmapped,d=(0,m.useRef)(t);d.current=t;let[f,p]=(0,m.useState)({});function g(e){d.current=e,n(e)}return(0,h.jsxs)(`section`,{"aria-label":`Edit narration`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Narration`}),(0,h.jsx)(U,{id:`project.narration.editor`})]}),t.config.chunking?.mode===`whole`||t.config.chunking===void 0?(0,h.jsx)(`p`,{children:`This narration uses one whole request. Editing its text rebuilds the whole narration request.`}):null,u===0?null:(0,h.jsx)(`p`,{children:`Some older audio cannot be matched reliably to its narration text. Replace the provided narration or rebuild from the article to edit those chunks.`}),l.map((e,n)=>{let o=t.content.narrationOverrides[e.key];return(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Narration chunk `,n+1]}),(0,h.jsxs)(`p`,{children:[e.parts,` audio `,e.parts===1?`part`:`parts`,` in this narration chunk.`]}),(0,h.jsxs)(`div`,{className:`text-small`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.key}-text`,children:[`Text for narration chunk `,n+1]}),(0,h.jsx)(U,{id:`project.narration.chunk-text`,label:`text for narration chunk ${String(n+1)}`})]}),(0,h.jsx)(BB,{id:`${a}-${e.key}-text`,value:o?.kind===`text`?o.text:e.text,onChange:n=>{p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,...t.uploads===void 0?{}:{uploads:t.uploads.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key)},content:{...t.content,narrationOverrides:{...t.content.narrationOverrides,[e.key]:{kind:`text`,text:n.target.value}}}})}})]}),(0,h.jsx)(k5,{label:`Replace narration chunk ${n+1}`,kind:`audio`,onPending:t=>r(`narration:${e.key}`,t),onReady:t=>{let n=i?.()??d.current;g({...n,regenerate:(n.regenerate??[]).filter(t=>t!==e.key),uploads:[...(n.uploads??[]).filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),{stagedFileId:t.id,destination:{kind:`narration`,key:e.key}}]})}},`${e.key}:${f[e.key]??0}`),t.regenerate?.includes(e.key)?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Narration chunk `,n+1,` will be regenerated after you save and press Remake.`,(0,h.jsxs)(B,{type:`button`,variant:`quiet`,onClick:()=>{let t=i?.()??d.current;g({...t,regenerate:(t.regenerate??[]).filter(t=>t!==e.key)})},children:[`Keep narration chunk `,n+1]})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(B,{type:`button`,onClick:()=>{let t=i?.()??d.current,n={...t.content.narrationOverrides};n[e.key]?.kind===`asset`&&delete n[e.key],p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,content:{...t.content,narrationOverrides:n},uploads:t.uploads?.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),regenerate:[...new Set([...t.regenerate??[],e.key])]})},children:[`Regenerate narration chunk `,n+1,` after review`]}),(0,h.jsx)(U,{id:`project.narration.regenerate`})]})]},e.key)})]})}function vxe(e){let{config:t,fingerprints:n}=e.revision;if(t.sources.audio===`off`)return;let r=t.sources.audio===`provide`?[{key:`audio:provided`,role:`audio_body`}]:[...t.intro===void 0?[]:[{key:`audio:intro`,role:`audio_intro`}],{key:`audio:body:concat`,role:`audio_body`},...t.outro===void 0?[]:[{key:`audio:outro`,role:`audio_outro`}]],i=e.outputs.filter(e=>e.selected&&e.state===`ready`&&e.available&&e.fingerprint===n[e.workKey]),a=r.map(({key:e,role:t})=>i.find(n=>n.workKey===e&&n.output.role===t));if(a.some(e=>e===void 0))return;let o=a.map(e=>e?.output.durationMs);if(o.every(m7))return o.reduce((e,t)=>e+t,0)/1e3+Math.max(0,r.length-1)*t.silenceGapSeconds+2*t.edgeSilenceSeconds;let s=i.find(e=>(e.output.role===`audio_export`||e.output.role===`video`)&&m7(e.output.durationMs))?.output.durationMs;return m7(s)?s/1e3:void 0}function m7(e){return e!=null&&Number.isFinite(e)&&e>0}function yxe({edit:e,prompts:t,problem:n,onChange:r,onPending:i,getEdit:a}){let{config:o}=e;if(o.sources.images!==`generate`)return null;let s=o.reference,c=s===void 0?m6:{source:s.source,prompt:s.prompt??``,thumbnail:s.thumbnail!==!1},l=e=>({...e,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`provided`||e.destination.stage!==`reference`)});return(0,h.jsx)(`section`,{"aria-label":`Establishing image`,className:`space-y-3`,children:(0,h.jsx)(h6,{value:c,prompts:t,problem:n,onChange:n=>{let{reference:i,...a}=o;if(n.source===`off`){r(l({...e,config:a}));return}let s={source:n.source,...n.source===`prompt`?{prompt:n.prompt}:{},...n.thumbnail?{}:{thumbnail:!1}},u=n.source===`prompt`&&n.prompt!==c.prompt?t.find(e=>e.kind===`image`&&e.name===n.prompt):void 0,d={...e,config:{...a,reference:s}},f=u===void 0?d:O5(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(k5,{label:e.content.provided.reference===void 0?`Upload the establishing image`:`Replace the establishing image`,kind:`images`,accept:`image/png,image/jpeg`,onPending:i,onReady:t=>{let n=l(a?.()??e);n.config.reference?.source===`provide`&&r({...n,uploads:[...n.uploads??[],{stagedFileId:t.id,destination:{kind:`provided`,stage:`reference`}}]})}})})})}var bxe=Y({words:J(Y({text:K().trim().min(1),start:q().finite().nonnegative(),end:q().finite().positive(),confidence:q().optional(),speaker:K().min(1).optional()})).min(1)});function h7(e){let{config:t,content:n}=e;return JSON.stringify({source:t.sources.audio,audio:n.provided.audio,uploads:e.uploads?.filter(e=>e.destination.kind===`narration`||e.destination.kind===`provided`&&e.destination.stage===`audio`)??[],edge:t.edgeSilenceSeconds,...t.sources.audio===`generate`?{choice:t.audio,chunking:t.chunking,article:n.articleMarkdown??t.provided.article,articleSource:t.sources.article,renderedArticle:t.rendered.article,intro:t.intro,outro:t.outro,renderedIntro:t.rendered.intro,renderedOutro:t.rendered.outro,gap:t.silenceGapSeconds,overrides:n.narrationOverrides,regenerate:e.regenerate?.filter(e=>/^(audio:|article:|entry:)/.test(e))??[]}:{}})}function xxe({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=V(),s=I(pb(o)).data?.prompts??[],c=h7(t),l=t.config.sources.audio!==`off`&&c===h7({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?vxe(e):void 0,f=d!==void 0&&u!==void 0&&u!==``,p=(0,m.useRef)({edit:t,onChange:r,revisionId:e.revision.id,identity:c});p.current={edit:t,onChange:r,revisionId:e.revision.id,identity:c};let g=(0,m.useRef)(i);g.current=i;let[_,v]=(0,m.useState)(new Set),[y,b]=(0,m.useState)(),x=(0,m.useRef)(void 0),S=(0,m.useRef)(!0),C=(0,m.useCallback)((e,t)=>{S.current&&v(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,m.useEffect)(()=>{g.current(_.size>0)},[_]),(0,m.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&x.current?.abort()}},[e.revision.id,c]);function w(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:h7(e)},t(e)}async function T(){if(x.current!==void 0)return;let t=new AbortController;x.current=t;let n=p.current;C(`captions:load`,!0),b(void 0);try{let r=e.outputs.find(e=>e.selected&&e.state===`ready`&&e.output.role===`subtitle_words`&&e.available);if(!f||d===void 0||u===void 0||r===void 0)throw Error(`Captions can't be edited until the current narration has finished and its subtitle timing is ready.`);let i=await o.fetch(j0(o,e.revision.projectId,e.revision.id,r.recordId),{signal:t.signal});if(!i.ok)throw Error(`The subtitle timing file couldn't be read. Reload the page and try again; if it still fails, use More → make it again in its section on Audio.`);let a=bxe.parse(await i.json()),s=0;for(let e of a.words){if(e.start<s||e.end<=e.start||e.end>d)throw Error(`The saved subtitle timing doesn't match the current narration. Use More → make it again in its section on Audio to rebuild it.`);s=e.end}let c=$be(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!S.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;w({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){S.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{x.current===t&&(x.current=void 0),C(`captions:load`,!1)}}let E=t.content.subtitleCues,D=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!D(`images`),className:`space-y-6`,children:[(0,h.jsx)(rxe,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(lxe,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(dxe,{edit:t,onChange:w}),(0,h.jsx)(yxe,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:w,onPending:e=>C(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(M6,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;w({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(k5,{label:`Replace provided ${e}`,kind:e,onPending:t=>C(`provided:${e}`,t),onReady:t=>{let n=p.current;n.edit.config.sources[e]===`provide`&&w({...n.edit,uploads:[...(n.edit.uploads??[]).filter(t=>t.destination.kind!==`provided`||t.destination.stage!==e),{stagedFileId:t.id,destination:{kind:`provided`,stage:e}}]})}},e):null),(0,h.jsx)(pxe,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!D(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(_xe,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!D(`captions`),className:`space-y-5`,children:[f?null:(0,h.jsx)(`p`,{children:`Captions can be edited once the current narration has finished and its subtitle timing is ready.`}),E===void 0?(0,h.jsx)(B,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void T(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[E.audioFingerprint===u?null:(0,h.jsx)(`p`,{children:`These caption edits belong to an earlier narration. Review their text and timing against the current narration, then apply your corrections and save the project.`}),f&&d!==void 0?(0,h.jsx)(exe,{cues:E.cues,duration:d,onPending:e=>C(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&w({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(B,{type:`button`,onClick:()=>w({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function Sxe({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(o2,{value:e.config.language,error:t,onChange:t=>{let{language:r,...i}=e.config;n({...e,config:t===void 0||t===`en`?i:{...i,language:t}})}})})}function Cxe({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=V(),a=I(cx(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:tx,c=s(o.channelId),l=a.data?.find(e=>e.id===c),u=o.useBrandKit!==!1,d=c!==s(t.channelId),f=u!==(t.useBrandKit!==!1);return(0,h.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(fa,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(VB,{value:c,onChange:t=>r({...e,config:{...o,channelId:t.target.value}}),children:[a.data===void 0?(0,h.jsx)(`option`,{value:c,children:`Loading channels…`}):null,(a.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col justify-end gap-1`,children:[(0,h.jsx)(Bb,{checked:u,label:`Use the channel's brand kit`,tip:`play.brand-kit`,onChange:t=>{let{useBrandKit:n,...i}=o;r({...e,config:t?i:{...i,useBrandKit:!1}})}}),u?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Its cast is still used.`})]}),a.error===null?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-danger md:col-span-2`,children:[`The channels couldn't be loaded: `,a.error.message,`. Reload the page to pick a channel.`]}),d||f?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:[d?`Saving moves the project to this channel and takes its cast as it is now. `:``,u?`The brand kit fills the caption font and colours, title style, end screen, intro, outro and document theme where they are at their default or were set by the old kit.`:`What the old brand kit had set is taken off.`]}):null]})}function wxe(e,t,n){let r=e.outputs.find(e=>e.selected&&e.available&&e.output.role===`reference`);if(t.config.reference!==void 0&&r!==void 0)return{image:{kind:`output`,outputId:r.output.id},drawnOn:`the establishing image`};let i=n.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),a=B6([t.config.title,...Object.values(t.config.values??{})].join(` `),i)[0]??i[0],o=a?.images[0];if(a!==void 0&&o!==void 0)return{image:{kind:`picture`,sha256:o},drawnOn:`${a.name}'s picture`}}function Txe({edit:e,view:t,prompts:n,error:r,onChange:i}){let a=(0,m.useRef)(e.config.narrationPrompt);if(e.config.sources.audio!==`generate`)return null;let o=t.revision.config.narrationPrompt,s=t.revision.content.promptTemplates.narration??t.revision.config.rendered.narration,c=o&&s!==void 0&&!n.some(e=>e.kind===`narration`&&e.name===o)?[...n,{id:`saved-narration`,kind:`narration`,name:o,body:s,slots:[],updatedAt:t.revision.createdAt}]:n;return(0,h.jsx)(f6,{value:e.config.narrationPrompt??``,prompts:c,libraryLinks:!1,supported:e.config.audio?.provider===`inworld`&&e.config.audio.model===`inworld-tts-2`,error:r,onChange:t=>{let n=e.config.narrationPrompt||a.current;t===``&&(a.current=e.config.narrationPrompt);let r=c.find(e=>e.kind===`narration`&&e.name===t),o=r===void 0||t===n?e:O5(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function Exe({edit:e,saved:t=e.config.imagePrompts,prompts:n,entries:r,onChange:i}){let a=(0,m.useId)(),o=[...new Set([...Object.keys(e.config.rendered),...Object.keys(e.content.promptTemplates),...e.config.sources.article===`generate`?[`article`]:[],...rj(e.config)?[`narration`]:[],...oj(e.config)&&e.config.descriptionPrompt?[`description`]:[],...uj(e.config)&&e.config.shorts?.prompt?[`shorts`]:[],...uj(e.config)&&e.config.shorts?.imagePrompt?[`shortsImage`]:[],...[`from_prompt`,`prompt_by_llm`].includes(e.config.sources.thumbnail)?[`thumbnailPrompt`]:[],...cj(e.config)&&e.config.reference?.source===`prompt`?[`referencePrompt`]:[],...e.config.intro===void 0?[]:[`intro`],...e.config.outro===void 0?[]:[`outro`]])].filter(n=>{let r=y7(n);if(r===void 0)return!0;let i=t[r]?.name;return i===void 0||e.config.imagePrompts.some(e=>e.name===i)}),s=e.config.imagePrompts.filter(e=>!t.some(t=>t.name===e.name)),c=e=>kxe(e,t),l=[...new Set([...Object.keys(e.config.values),...Object.values(e.content.promptTemplates).flatMap(e=>e===null?[]:MK(e).names)])].filter(e=>!NK.includes(e)),u=t=>[...MK(e.config.title).names.includes(t)?[`Project title`]:[],...Object.entries(e.content.promptTemplates).flatMap(([e,n])=>n!==null&&MK(n).names.includes(t)?[c(e)]:[])],d=MK(e.config.title).names;return(0,h.jsxs)(`section`,{"aria-label":`Prompt snapshots`,className:`space-y-6`,children:[o.map(o=>{let s=c(o),l=e.content.promptTemplates[o]??null,u=o===`intro`||o===`outro`?r.filter(e=>e.category===o):n.filter(t=>t.kind===(o===`article`?IA(e.config)?`script`:`article`:o===`narration`?`narration`:o===`description`?`description`:o===`shorts`?`shorts`:o===`thumbnailPrompt`?`thumbnail`:`image`));return(0,h.jsxs)(`div`,{className:`min-w-0 space-y-4 border-t border-line pt-6 first:border-t-0 first:pt-0`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:s}),l===null?(0,h.jsx)(aI,{tone:`info`,title:`Original template unavailable`,actions:(0,h.jsx)(B,{"aria-label":`Use saved wording as template for ${s}`,onClick:()=>i(O5(e,o,e.config.rendered[o]??``)),children:`Use saved wording as template`}),children:`The saved prompt below stays as it is until you choose or write a template.`}):null,(0,h.jsx)(Oxe,{label:s,raw:l,library:Dxe(e,o,u,t),onUse:t=>i(O5(e,o,t))}),(0,h.jsx)(LB,{label:`Use saved template for ${s}`,id:`${a}-library-${o}`,tip:`project.prompts.template`,children:(0,h.jsxs)(VB,{value:``,onChange:t=>{let n=u.find(e=>e.id===t.target.value);if(n===void 0)return;let r=O5(e,o,n.body),a=`category`in n?{...r.config,[n.category]:{name:n.name,mode:n.mode}}:o===`article`?{...r.config,articlePrompt:n.name}:o===`narration`?{...r.config,narrationPrompt:n.name}:o===`description`?{...r.config,descriptionPrompt:n.name}:(o===`shorts`||o===`shortsImage`)&&r.config.shorts!==void 0?{...r.config,shorts:{...r.config.shorts,[o===`shorts`?`prompt`:`imagePrompt`]:n.name}}:o===`thumbnailPrompt`?{...r.config,thumbnailPrompt:n.name}:o===`referencePrompt`&&r.config.reference!==void 0?{...r.config,reference:{...r.config.reference,prompt:n.name}}:r.config;i({...r,config:a})},children:[(0,h.jsx)(`option`,{value:``,children:`Choose a saved template`}),u.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,h.jsx)(LB,{label:`Raw prompt for ${s}`,id:`${a}-raw-${o}`,tip:`project.prompts.raw`,children:(0,h.jsx)(BB,{rows:4,value:l??``,onChange:t=>i(O5(e,o,t.target.value))})}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`text-small text-ink-2`,children:`Saved rendered prompt`}),(0,h.jsx)(`pre`,{className:`m-0 mt-2 whitespace-pre-wrap break-words text-small`,children:e.config.rendered[o]??``})]})]},o)}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s.map(e=>`"${e.name}"`).join(`, `),` `,s.length===1?`uses its`:`use their`,` Library wording. Save, then change it here.`]}),l.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`space-y-3 pt-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:`Keywords`}),(0,h.jsx)(V1,{fieldPrefix:`config.values`,keywords:l.map(t=>({name:t,value:e.config.values[t]??``,feeds:u(t),topic:d.includes(t)})),onChange:(t,n)=>i(D5({...e,config:{...e.config,values:{...e.config.values,[t]:n}}}))})]}):null]})}function Dxe(e,t,n,r){let{config:i}=e,a=y7(t);if(t===`intro`||t===`outro`){let e=i[t]?.name;return e===void 0||e===``?void 0:n.find(t=>`category`in t&&t.name===e)}let o=t===`article`?i.articlePrompt:t===`narration`?i.narrationPrompt:t===`description`?i.descriptionPrompt:t===`shorts`?i.shorts?.prompt:t===`shortsImage`?i.shorts?.imagePrompt:t===`thumbnailPrompt`?i.thumbnailPrompt:t===`referencePrompt`?i.reference?.prompt:a===void 0?void 0:r[a]?.name;if(o!==void 0&&o!==``)return n.find(e=>!(`category`in e)&&e.name===o)}var g7=`slopify.library-kept`;function _7(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t*33^e.charCodeAt(n))>>>0;return t.toString(36)}function v7(){try{let e=window.localStorage.getItem(g7),t=e===null?[]:JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Oxe({label:e,raw:t,library:n,onUse:r}){let i=n===void 0||t===null?``:`${e}:${_7(t)}:${_7(n.body)}`,[a,o]=(0,m.useState)(()=>v7().includes(i));return n===void 0||t===null||n.body===t||a?null:(0,h.jsx)(aI,{tone:`info`,title:`The Library's "${n.name}" has changed since this project copied it`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{"aria-label":`Use the Library version for ${e}`,onClick:()=>{r(n.body)},children:`Use the Library version`}),(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Keep this project's version for ${e}`,onClick:()=>{try{window.localStorage.setItem(g7,JSON.stringify([...v7().filter(e=>e!==i),i].slice(-200)))}catch{}o(!0)},children:`Keep this project's version`})]}),children:`The project uses its own copy below until you choose. Using the Library version marks what it wrote as outdated, to remake when you are ready.`})}function y7(e){let t=/^imagePrompts\.(\d+)$/.exec(e);return t?.[1]===void 0?void 0:Number(t[1])}function kxe(e,t){if(e===`article`)return`Article`;if(e===`narration`)return`Narration Preparation`;if(e===`description`)return`YouTube description`;if(e===`shorts`)return`Shorts`;if(e===`shortsImage`)return`Shorts image style`;if(e===`thumbnailPrompt`)return`Thumbnail`;if(e===`referencePrompt`)return`Establishing image`;if(e===`intro`)return`Intro`;if(e===`outro`)return`Outro`;let n=y7(e);if(n!==void 0){let e=t[n]?.name;return e===void 0||e===``?`Image prompt ${String(n+1)}`:`Image prompt "${e}"`}return e.replace(/[._-]/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`)}function Axe(e,t,n){let{api:r}=V(),[i,a]=(0,m.useState)({busy:!1}),{config:o}=t,s=o.audio,c=async()=>{if(s!==void 0){a({busy:!0});try{let i=await Zs(r,e),{sharedGlossary:c,...l}=o;n({...t,config:{...l,audio:{...s,shareGlossary:!0},...i.entries.length===0?{}:{sharedGlossary:i.entries}}}),a({busy:!1,projects:i.projects})}catch(e){a({busy:!1,error:e instanceof Error?e.message:String(e)})}}},l=()=>{if(s===void 0)return;let{sharedGlossary:e,...r}=o;n({...t,config:{...r,audio:{...s,shareGlossary:!1}}})},u=o.sharedGlossary?.length??0,d=s?.shareGlossary===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[i.error===void 0?u===0?`No pronunciations from other projects are copied yet.`:`${String(u)} ${u===1?`term`:`terms`} copied from ${i.projects===void 0?`your other projects`:`${String(i.projects)} other ${i.projects===1?`project`:`projects`}`}.`:`Couldn't read your other projects' pronunciations: ${i.error}`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:i.busy,onClick:()=>void c(),children:i.busy?`Copying…`:`Update from other projects`}),(0,h.jsx)(U,{id:`project.edit.update-glossary`})]}):void 0;return{value:s?.shareGlossary===!0,onChange:e=>{e?c():l()},note:d}}function jxe(e,t){let{api:n}=V(),[r,i]=(0,m.useState)({busy:!1}),{config:a}=e,o=a.audio,s=async()=>{if(o!==void 0){i({busy:!0});try{let{aliases:r}=await Qs(n),{narrationAliases:s,...c}=a;t({...e,config:{...c,audio:{...o,useNarrationAliases:!0},...r.length===0?{}:{narrationAliases:r}}}),i({busy:!1})}catch(e){i({busy:!1,error:e instanceof Error?e.message:String(e)})}}},c=a.narrationAliases?.length??0;return{value:o?.useNarrationAliases===!0,onChange:n=>{if(o!==void 0){if(n)s();else{let{narrationAliases:n,...r}=a;t({...e,config:{...r,audio:{...o,useNarrationAliases:!1}}})}}},note:o?.useNarrationAliases===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[r.error===void 0?c===0?`No aliases are copied yet. Add some in Library → Aliases.`:`${String(c)} ${c===1?`alias`:`aliases`} copied from Library → Aliases.`:`Couldn't read Library → Aliases: ${r.error} Try Update from Library again.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r.busy,onClick:()=>void s(),children:r.busy?`Copying…`:`Update from Library`}),(0,h.jsx)(U,{id:`project.edit.update-aliases`})]}):void 0}}function Mxe({projectId:e,edit:t,providers:n,voices:r,onChange:i}){let{config:a}=t,o=a.llm??{provider:``,model:``},s=a.audio??{provider:``,model:``,voice:``},c=Axe(e,t,i),l=jxe(t,i),{api:u}=V(),d=I(lx(u,a.channelId??`00000000-0000-4000-8000-000000000001`)),f=a.images??{provider:``,model:``},p=rj(a)||a.sources.audio===`generate`&&a.audio?.describeFigures===!0||a.sources.research===`generate`||a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||FA(a)&&a.voices?.source===`attribute`||a.sources.audio===`generate`&&(a.intro?.mode===`llm`||a.outro?.mode===`llm`),m=a.sources.images===`generate`||a.sources.thumbnail===`from_prompt`||a.sources.thumbnail===`prompt_by_llm`,g=r.filter(e=>e.provider===s.provider).map(e=>({value:e.voiceId,label:e.name}));return(0,h.jsxs)(`section`,{"aria-label":`Generation providers`,className:`grid min-w-0 gap-3 sm:grid-cols-2`,children:[p?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{label:`Text provider`,tip:`play.llm.provider`,family:`llm`,providers:n,value:o.provider,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{provider:e,model:``}}})}),(0,h.jsx)(tV,{label:`Text model`,tip:`play.llm.model`,provider:o.provider,value:o.model,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{...o,model:e}}})}),(0,h.jsx)(g6,{choice:o,onChange:e=>i({...t,config:{...a,llm:e}})})]}):null,a.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[a.voices!==void 0&&a.intro===void 0&&a.outro===void 0?null:(0,h.jsxs)(h.Fragment,{children:[a.voices===void 0?null:(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`The voice below reads only the intro and outro. Each speaker's voice is set under Speakers.`}),(0,h.jsx)(eV,{label:a.voices===void 0?`Narration provider`:`Intro and outro provider`,tip:`play.tts.provider`,family:`tts`,providers:n,value:s.provider,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,provider:e,model:``,voice:``}}})}),(0,h.jsx)(tV,{label:a.voices===void 0?`Narration model`:`Intro and outro model`,tip:`play.tts.model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,model:e}}})}),(0,h.jsx)(ZB,{label:a.voices===void 0?`Narration voice`:`Intro and outro voice`,tip:`play.voice`,value:s.voice,problem:void 0,placeholder:`Choose a saved voice`,options:s.voice!==``&&!g.some(e=>e.value===s.voice)?[{value:s.voice,label:`${s.voice} (saved voice)`},...g]:g,onPick:e=>i({...t,config:{...a,audio:{...s,voice:e}}})})]}),(0,h.jsx)(U3,{value:a.chunking??{mode:`whole`},onPick:e=>i({...t,config:{...a,chunking:e}})}),(0,h.jsx)(p6,{shared:c,value:s.usePronunciationGlossary,supported:hj({sources:a.sources,audio:{...s,usePronunciationGlossary:!0}}),onChange:e=>i({...t,config:{...a,audio:{...s,usePronunciationGlossary:e}}})}),(0,h.jsx)(d6,{...l}),(0,h.jsx)(l6,{tip:`project.edit.describe-figures`,value:s.describeFigures,skipCode:s.skipCode,onChange:({describeFigures:e,skipCode:n})=>{let{describeFigures:r,skipCode:o,...c}=s;i({...t,config:{...a,audio:{...c,...e?{describeFigures:e}:{},...e&&n?{skipCode:n}:{}}}})}}),(0,h.jsxs)(`section`,{"aria-label":`Speakers`,className:`col-span-full border-t border-line pt-3`,children:[(0,h.jsx)(`h3`,{className:`mb-2 text-small font-semibold`,children:`Speakers`}),(0,h.jsx)(c6,{value:a.voices,cast:d.data?.cast??[],language:a.language,providers:n,voices:r,script:t.content.articleMarkdown??void 0,onChange:e=>{let{voices:n,...r}=a;i({...t,config:e===void 0?r:{...r,voices:e}})}})]})]}):null,m?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{label:`Image provider`,tip:`play.images.provider`,family:`image`,providers:n,value:f.provider,problem:void 0,onPick:e=>i({...t,config:{...a,images:{provider:e,model:``}}})}),(0,h.jsx)(tV,{label:`Image model`,tip:`play.images.model`,provider:f.provider,value:f.model,problem:void 0,onPick:e=>i({...t,config:{...a,images:{...f,model:e}}})}),(0,h.jsx)(g6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:f,onChange:e=>i({...t,config:{...a,images:e}})})]}):null]})}function Nxe({edit:e,providers:t,prompts:n,problem:r,onChange:i}){let{config:a}=e,o=a.reviews===void 0?iV:wk(a.reviews),[s,c]=(0,m.useState)(o),l=a.shorts?.enabled===!0&&a.sources.audio!==`off`,u=e=>Ek({sources:a.sources,shorts:l?{enabled:!0}:void 0},e),d=Tk(s,u).retriesProblem;return(0,h.jsx)(aV,{value:s,providers:t,prompts:n,makes:u,problem:e=>e===`reviews.retries`&&d!==void 0?d:r(e),onChange:t=>{c(t);let{settings:r}=Tk(t,u),o={...e.content.promptTemplates},s={...a.rendered};for(let e of gk){let t=Ck(e),i=r?.stages[e]?.prompt??``,c=n.find(e=>e.kind===`review`&&e.name===i);if(i===``){let{[t]:e,...n}=o,{[t]:r,...i}=s;o=n,s=i}else c!==void 0&&i!==(a.reviews?.stages[e]?.prompt??``)&&(o={...o,[t]:c.body})}let{reviews:l,...d}=a;i(D5({...e,config:{...d,rendered:s,...r===void 0?{}:{reviews:r}},content:{...e.content,promptTemplates:o}}))}})}function Pxe({edit:e,view:t,prompts:n,problem:r,onChange:i}){let a=t.revision.config.descriptionPrompt,o=t.revision.content.promptTemplates.description??t.revision.config.rendered.description,s=a&&o!==void 0&&!n.some(e=>e.kind===`description`&&e.name===a)?[...n,{id:`saved-description`,kind:`description`,name:a,body:o,slots:[],updatedAt:t.revision.createdAt}]:n,c=t.outputs.some(e=>e.selected&&e.workKey===b7&&e.state===`ready`),l=e.regenerate?.includes(b7)===!0;return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(y6,{enabled:e.config.youtubeDescription===!0,prompt:e.config.descriptionPrompt??``,prompts:s,narrated:e.config.sources.audio!==`off`,problem:r,onChange:({youtubeDescription:t,descriptionPrompt:n})=>{let r=s.find(e=>e.kind===`description`&&e.name===n),a=n===(e.config.descriptionPrompt??``)?e:r===void 0?Fxe(e):O5(e,`description`,r.body),{descriptionPrompt:o,...c}=a.config;i({...a,config:{...c,youtubeDescription:t,...n===``?{}:{descriptionPrompt:n}}})}}),c&&e.config.youtubeDescription===!0?l?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The YouTube description will be written again after you save and press Remake.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>{i({...e,regenerate:(e.regenerate??[]).filter(e=>e!==b7)})},children:`Keep the current description`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:()=>{i({...e,regenerate:[...new Set([...e.regenerate??[],b7])]})},children:`Write the description again after review`}),(0,h.jsx)(U,{id:`project.edit.rewrite-description`})]}):null]})}var b7=`youtube:description`;function Fxe(e){let{description:t,...n}=e.content.promptTemplates,{description:r,...i}=e.config.rendered;return D5({config:{...e.config,rendered:i},content:{...e.content,promptTemplates:n}})}var Ixe={research:`Research source`,article:`Article source`,audio:`Audio source`,images:`Images source`,thumbnail:`Thumbnail source`,video:`Video source`,document:`Document source`},Lxe={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`},Rxe=`\0kept:`;function x7({title:e,children:t,columns:n=!0}){return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:e}),(0,h.jsx)(`div`,{className:z(`grid min-w-0 gap-4`,n&&`md:grid-cols-2`),children:t})]})}function zxe(e){let{view:t,edit:n,onChange:r,onPending:i,fields:a}=e,o=(0,m.useId)(),[s,c]=(0,m.useState)(e.focus?.section??`inputs`);(0,m.useEffect)(()=>{e.focus!==void 0&&c(e.focus.section)},[e.focus]);let[l,u]=(0,m.useState)({font:!1,content:!1,music:!1});(0,m.useEffect)(()=>{i(l.font||l.content||l.music)},[i,l]);let d=(0,m.useCallback)(e=>{u(t=>t.font===e?t:{...t,font:e})},[]),f=(0,m.useCallback)(e=>{u(t=>t.content===e?t:{...t,content:e})},[]),p=(0,m.useCallback)(e=>{u(t=>t.music===e?t:{...t,music:e})},[]),{api:g}=V(),_=I(db(g)),v=I(fb(g)),y=I(pb(g)),b=I(mb(g)),{config:x}=n,S=wxe(t,n,I(lx(g,x.channelId??`00000000-0000-4000-8000-000000000001`)).data?.cast??[]),C=S?.image.kind===`output`?t.outputs.find(e=>e.selected&&e.available&&S.image.kind===`output`&&e.output.id===S.image.outputId):void 0,w=C===void 0?void 0:j0(g,t.revision.projectId,t.revision.id,C.recordId),T=e=>a.find(t=>t.field===e||t.field===`config.${e}`||t.field===`edit.config.${e}`)?.message,E=b6({value:x.videoEdit,narrated:x.sources.audio!==`off`,imageProvider:x.images?.provider??``,problem:T,language:x.language,onChange:e=>r({...n,config:{...x,videoEdit:e}})}),D=[{id:`inputs`,label:`Inputs`},...x.sources.article===`off`?[]:[{id:`article`,label:`Article`,...n.content.articleEdited?{badge:`edited`}:{}}],{id:`providers`,label:`Providers`},{id:`prompts`,label:`Prompts`},{id:`reviews`,label:`Reviews`,...x.reviews===void 0?{}:{badge:`on`}},...x.sources.audio!==`off`||x.shorts?.enabled===!0?[{id:`shorts`,label:`Shorts`,...x.shorts?.enabled?{badge:`on`}:{}}]:[],...x.sources.article===`off`?[]:[{id:`subtitles`,label:`Subtitles`}],{id:`images`,label:`Images`,badge:String(n.content.imageOrder.length)},...x.sources.audio===`generate`?[{id:`narration`,label:`Narration`}]:[],...x.sources.article===`off`?[]:[{id:`captions`,label:`Captions`,...n.content.subtitleCues===void 0?{}:{badge:String(n.content.subtitleCues.cues.length)}}]],O=D.some(e=>e.id===s)?s:`inputs`,k=e=>z(`min-w-0 space-y-6`,O===e?void 0:`hidden`),A=e=>Number.isFinite(e)?e:``,j=x.sources.video!==`off`;return(0,h.jsxs)(`div`,{className:`grid min-w-0 gap-8 md:grid-cols-[180px_minmax(0,1fr)]`,children:[(0,h.jsx)(`nav`,{"aria-label":`Edit sections`,className:`min-w-0 md:sticky md:top-16 md:self-start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none gap-1 overflow-x-auto p-0 [scrollbar-width:none] md:flex-col`,children:D.map(e=>(0,h.jsx)(`li`,{className:`shrink-0`,children:(0,h.jsx)(Z6,{current:e.id===O,onClick:()=>c(e.id),meta:e.badge,className:`whitespace-nowrap`,children:e.label})},e.id))})}),(0,h.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[Object.entries({providers:_.error,voices:v.error,prompts:y.error,entries:b.error}).flatMap(([e,t])=>t===null?[]:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:t.message},e)]),a.length===0?null:(0,h.jsx)(`ul`,{role:`alert`,className:`m-0 space-y-1 pl-5 text-small text-danger`,children:a.map(e=>(0,h.jsx)(`li`,{children:e.message},`${e.field}-${e.message}`))}),(0,h.jsxs)(`section`,{"aria-label":`Inputs`,hidden:O!==`inputs`,className:k(`inputs`),children:[(0,h.jsxs)(x7,{title:`Project`,children:[(0,h.jsx)(LB,{label:`Project title`,error:T(`title`),className:`md:col-span-2`,children:(0,h.jsx)(zB,{value:x.title,maxLength:200,onChange:e=>r({...n,config:{...x,title:e.target.value}})})}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(z6,{value:x.format,onPick:e=>r({...n,config:{...x,format:e}})})})]}),(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Channel`,columns:!1,children:(0,h.jsx)(Cxe,{edit:n,saved:t.revision.config,problem:T,onChange:r})}),(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Stages`,children:[KS.filter(e=>x.sources.article!==`off`||e!==`research`&&e!==`audio`&&e!==`document`).map(e=>(0,h.jsx)(LB,{label:Ixe[e],tip:Lxe[e],error:T(`sources.${e}`),children:(0,h.jsx)(VB,{value:YS(x.sources,e),onChange:i=>{let a=ON(e).find(e=>e.value===i.target.value);if(a===void 0)return;let o=tbe(n,e,a.value);r(e===`article`&&a.value===`provide`&&!n.content.articleEdited?{...o,content:{...o.content,articleMarkdown:t.articleMarkdown??n.content.articleMarkdown}}:o)},children:ON(e).filter(t=>e!==`thumbnail`||t.value!==`prompt_by_llm`||x.sources.article!==`off`).map(t=>(0,h.jsx)(`option`,{value:t.value,disabled:e===`video`&&t.value===`generate`&&x.sources.images===`off`,children:t.label},t.value))})},e)),x.sources.images===`off`?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:`Images are Off. Video is also Off in these changes.`}):null,(0,h.jsx)(LB,{label:`Document theme`,id:`${o}-document-theme`,tip:`play.document-theme`,children:(0,h.jsx)(V3,{id:`${o}-document-theme`,disabled:YS(x.sources,`document`)===`off`,value:x.document,onChange:e=>{r({...n,config:{...x,document:e}})}})})]}),(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Timing`,children:[(0,h.jsx)(LB,{label:`Silence gap (seconds)`,tip:`play.silence-gap`,error:T(`silenceGapSeconds`),children:(0,h.jsx)(zB,{type:`number`,min:0,max:30,step:.1,value:A(x.silenceGapSeconds),onChange:e=>r({...n,config:{...x,silenceGapSeconds:Number(e.target.value)}})})}),x.sources.audio===`off`?null:(0,h.jsx)(LB,{label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,error:T(`edgeSilenceSeconds`),children:(0,h.jsx)(zB,{type:`number`,min:0,max:30,step:.5,value:A(x.edgeSilenceSeconds),onChange:e=>r({...n,config:{...x,edgeSilenceSeconds:Number(e.target.value)}})})}),j?(0,h.jsx)(LB,{label:`Seconds per image`,tip:`play.image-seconds`,error:T(`imageSeconds`),children:(0,h.jsx)(zB,{type:`number`,min:1,max:600,step:1,value:A(x.imageSeconds),onChange:e=>r({...n,config:{...x,imageSeconds:Number(e.target.value)}})})}):null,j?(0,h.jsx)(LB,{label:`Zoom (%)`,tip:`play.zoom`,error:T(`zoomPercent`),children:(0,h.jsx)(zB,{type:`number`,min:0,max:50,step:.5,value:A(x.zoomPercent),onChange:e=>r({...n,config:{...x,zoomPercent:Number(e.target.value)}})})}):null,j?(0,h.jsx)(LB,{label:`Motion`,tip:`play.motion`,children:(0,h.jsx)(VB,{value:x.motionStyle,onChange:e=>r({...n,config:{...x,motionStyle:e.target.value}}),children:XS.map(e=>(0,h.jsx)(`option`,{value:e,children:HA[e]},e))})}):null]}),j?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Cuts and look`,columns:!1,children:[E.cuts,E.look,x.sources.audio===`generate`&&x.audio?.describeFigures===!0?(0,h.jsx)(u6,{tip:`project.edit.show-figures`,value:x.showFigures,onChange:e=>{let{showFigures:t,...i}=x;r({...n,config:e?{...i,showFigures:!0}:i})}}):null]}),x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Ambient sound`,columns:!1,children:(0,h.jsx)(axe,{edit:n,problem:T,onChange:r})})]})]}):null,x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Pauses and volume`,columns:!1,children:[(0,h.jsx)(sxe,{edit:n,problem:T,onChange:r}),(0,h.jsx)(oxe,{edit:n,problem:T,onChange:r})]})]}),(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Intro and outro`,children:[`intro`,`outro`].map(e=>{let i=x[e]?.name,a=t.revision.content.promptTemplates[e],o=b.data?.entries.find(t=>t.category===e&&t.name===i),s=i!==void 0&&o!==void 0&&typeof a==`string`&&t.revision.config[e]?.name===i&&a!==o.body,c=n.content.promptTemplates[e],l=`${Rxe}${i??``}`,u=i===void 0?``:s&&c!==o?.body?l:i;return(0,h.jsx)(LB,{label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,children:(0,h.jsxs)(VB,{value:u,onChange:i=>{if(i.target.value===l&&typeof a==`string`){r(D5({...n,config:{...x,[e]:t.revision.config[e]},content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:a}}}));return}let o=b.data?.entries.find(t=>t.category===e&&t.name===i.target.value),s={...x};o===void 0?delete s[e]:s[e]={name:o.name,mode:o.mode},r(D5({...n,config:s,content:o===void 0?n.content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:o.body}}}))},children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),i!==void 0&&!b.data?.entries.some(t=>t.category===e&&t.name===i)?(0,h.jsxs)(`option`,{value:i,children:[i,` (saved entry)`]}):null,s?(0,h.jsxs)(`option`,{value:l,children:[i,` · this project's version`]}):null,b.data?.entries.filter(t=>t.category===e).map(e=>(0,h.jsx)(`option`,{value:e.name,children:s&&e.name===i?`${e.name} · Library version (newer)`:e.name},e.id))]})},e)})}),x.sources.research===`provide`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Research`,columns:!1,children:(0,h.jsx)(LB,{label:`Research notes`,tip:`play.provided.research`,error:T(`provided.research`),children:(0,h.jsx)(BB,{rows:6,value:x.provided.research??``,onChange:e=>r({...n,config:{...x,provided:{...x.provided,research:e.target.value}}})})})})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Article`,hidden:O!==`article`,className:k(`article`),children:[(0,h.jsx)(LB,{label:`Article text`,tip:`project.edit.article-text`,error:T(`content.articleMarkdown`)??T(`provided.article`),help:n.content.articleEdited?`Your edited article is kept when other settings change. Regenerating it replaces it after the rebuild review.`:void 0,children:(0,h.jsx)(BB,{rows:12,maxLength:5e5,value:(n.content.articleEdited?n.content.articleMarkdown:t.articleMarkdown)??n.content.articleMarkdown??x.provided.article??``,onChange:e=>r({...n,content:{...n.content,articleMarkdown:e.target.value,articleEdited:!0}})})}),x.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{onClick:()=>r({...n,regenerate:[...new Set([...n.regenerate??[],`article:body`])]}),children:`Regenerate article after review`}),(0,h.jsx)(U,{id:`project.edit.regenerate-article`})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Providers`,hidden:O!==`providers`,className:k(`providers`),children:[(0,h.jsx)(Sxe,{edit:n,error:T(`language`),onChange:r}),(0,h.jsx)(Mxe,{projectId:t.revision.projectId,edit:n,providers:_.data?.providers??[],voices:v.data?.voices??[],onChange:r}),(0,h.jsx)(Txe,{edit:n,view:t,prompts:y.data?.prompts??[],error:T(`narrationPrompt`),onChange:r})]}),(0,h.jsxs)(`section`,{"aria-label":`Prompts`,hidden:O!==`prompts`,className:k(`prompts`),children:[(0,h.jsx)(Pxe,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r}),(0,h.jsx)(Exe,{edit:n,saved:t.revision.config.imagePrompts,prompts:y.data?.prompts??[],entries:b.data?.entries??[],onChange:r})]}),(0,h.jsx)(`section`,{"aria-label":`Reviews`,hidden:O!==`reviews`,className:k(`reviews`),children:(0,h.jsx)(Nxe,{edit:n,providers:_.data?.providers??[],prompts:y.data?.prompts??[],problem:T,onChange:r})}),(0,h.jsx)(`section`,{"aria-label":`Shorts`,hidden:O!==`shorts`,className:k(`shorts`),children:(0,h.jsx)(ibe,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r,onPending:p})}),(0,h.jsxs)(`section`,{"aria-label":`Subtitles`,hidden:O!==`subtitles`,className:k(`subtitles`),children:[(0,h.jsx)(`div`,{"data-tour":`project-subtitles`,children:(0,h.jsx)(R6,{value:x.subtitles??cM,format:x.format,audioEnabled:x.sources.audio!==`off`,videoEnabled:j,onChange:e=>r({...n,config:{...x,subtitles:xN(e,x.sources)}}),onUploading:d,problem:T})}),O!==`subtitles`||!j?null:(0,h.jsx)(w6,{drawnOn:S?.drawnOn,poster:w,settings:{format:x.format,subtitles:{mode:(x.subtitles??cM).mode,fontId:(x.subtitles??cM).fontId,fontSize:(x.subtitles??cM).fontSize,position:(x.subtitles??cM).position??`bottom`},videoEdit:x.videoEdit,image:S?.image}})]}),e.renderContent?.({view:t,edit:n,fields:a,onChange:r,onPending:f,section:O})]})]})}var S7={notes:`Research notes`,article_md:`Article (Markdown)`,article_txt:`Article text`,narration_txt:`Clean Narration`,tts_script:`TTS Script`,sources:`Research sources`,glossary:`Glossary`,audio_body:`Narration`,audio_intro:`Intro narration`,audio_outro:`Outro narration`,audio_export:`Audio export`,image:`Image`,thumbnail:`Thumbnail`,video:`Video`,render_params:`Export settings`,subtitles_srt:`Subtitles (SRT)`,subtitles_vtt:`Subtitles (VTT)`,subtitle_words:`Subtitle timing`,subtitle_ass:`Styled subtitles`,subtitle_font:`Subtitle font`,instructions:`Generation instructions`,document_pdf:`Document (PDF)`,youtube_description:`YouTube description`,youtube_tags:`YouTube tags`,youtube_pinned_comment:`Pinned comment`,youtube_titles:`Other titles`,shorts:`Shorts list`,short_image:`Short image`,short_video:`Short`,animated_image:`Animated image`,figure_card:`On-screen card`,reference:`Establishing image (reference)`,script_md:`Script (speaker split)`,audio_mp3:`Audio (MP3 with chapters)`,audio_m4b:`Audiobook (M4B with chapters)`,audio_levelled:`Levelled narration`};function C7(e){return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment?`${e.meta.segment===`body`?`Body`:e.meta.segment===`intro`?`Intro`:`Outro`} ${S7[e.role]}`:e.role===`short_video`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)}`:e.role===`short_image`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)} image ${String(e.meta.index??1)}`:e.role===`figure_card`&&typeof e.meta.index==`number`?`On-screen card ${String(e.meta.index)}`:e.role===`animated_image`&&typeof e.meta.index==`number`?`Animated image ${String(e.meta.index)}`:e.role===`image`&&typeof e.meta.index==`number`?`Image ${e.meta.index}`:S7[e.role]}function Bxe(e){if(e.startsWith(`image:`))return`Image`;if(e.startsWith(`animate:`))return S7.animated_image;if(/^shorts:\d+:render$/.test(e))return S7.short_video;if(/^shorts:\d+:image:\d+$/.test(e))return S7.short_image;if(e===`document:pdf`)return S7.document_pdf;let t=e.split(`:`).at(-1);return Object.entries(S7).find(([e])=>e===t)?.[1]??`Saved output`}function Vxe({preview:e,pending:t,feedback:n,onStart:r,onCancel:i}){let a=qxe(e),[o,s]=(0,m.useState)([]),[c,l]=(0,m.useState)(!1),u=(0,m.useId)(),d=e.work.filter(e=>e.disposition===`blocked`),f=e.providedReuseRequired.filter(e=>!o.includes(e)),p=e.work.filter(e=>e.disposition===`generate`||e.disposition===`local`||e.disposition===`review`).length,g=p===1?`Remake 1 output`:`Remake ${String(p)} outputs`,_=[...d.length===0?[]:[`${d.length===1?`1 item is`:`${d.length} items are`} unavailable (reasons above)`],...f.map(e=>`tick “Keep the provided content for ${a(e)}”`),...e.costs.unknown===0||c?[]:[`tick “I understand that ${e.costs.unknown} cost estimates are unknown”`]],v=_.length===0,y=Uxe.map(t=>({disposition:t,count:e.work.filter(e=>e.disposition===t).length})).filter(e=>e.count>0),b=e.costs.rows.some(e=>e.onPlan===!0),x=e.costs.apiLow,S=e.costs.apiHigh;return(0,h.jsxs)(`section`,{"aria-label":`Review affected rebuild`,className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-6 gap-y-3 sm:grid-cols-3`,children:[y.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:O7[e.disposition]}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:e.count})]},e.disposition)),(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:e.costs.unknown>0?`known cost`:`cost`}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:D7(e.costs.low,e.costs.high)})]})]}),b?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`CLI work: $0 on your plan${x===void 0||S===void 0?``:` · ~${D7(x,S)} via API`}.`}):null,d.length===0?null:(0,h.jsx)(aI,{tone:`danger`,title:`${d.length===1?`1 item can’t`:`${d.length} items can’t`} run, so this rebuild can’t start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:Wxe(d,a).map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.what,`:`]}),` `,e.reason]},e.reason))})}),e.wholeRequestNotice===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.wholeRequestNotice}),e.warnings.map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e},e)),(0,h.jsxs)(`div`,{className:`flex flex-col divide-y divide-line border-y border-line`,children:[e.review?.inputChanges.length?(0,h.jsx)(w7,{summary:`Changed inputs (${String(e.review.inputChanges.length)})`,children:(0,h.jsx)(`dl`,{className:`m-0 flex flex-col gap-3`,children:e.review.inputChanges.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`dt`,{className:`font-semibold`,children:e.label}),(0,h.jsxs)(`dd`,{className:`m-0 grid gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(T7,{label:`Before`,text:e.before}),(0,h.jsx)(T7,{label:`After`,text:e.after})]})]},e.label))})}):null,(0,h.jsxs)(w7,{summary:`Work items (${e.work.length}): ${y.map(e=>`${e.count} ${O7[e.disposition]}`).join(`, `)||`none`}`,children:[e.changedInputs.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 mb-3 flex flex-col gap-1 pl-5`,children:e.changedInputs.map(e=>(0,h.jsxs)(`li`,{children:[a(e.path),`:`,` `,e.after===null?`Removed`:e.before===null?`New output`:`Inputs changed`]},e.path))}),(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-2 pl-5`,children:e.work.map(t=>(0,h.jsxs)(`li`,{children:[a(t.key),`: `,O7[t.disposition],`. `,t.reason,t.inflight?` An already submitted request may still be billed.`:``,e.review?.requests.filter(e=>e.key===t.key).map(e=>(0,h.jsxs)(`div`,{children:[e.settings===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.settings}),e.text===null?null:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:`View request text`}),(0,h.jsx)(`pre`,{className:`m-0 max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.text})]})]},e.key))]},t.key))}),(0,h.jsxs)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:[`Retained outputs:`,` `,e.retained.map(e=>Bxe(e.slot)).join(`, `)||`None`]})]}),e.costs.rows.length===0?null:(0,h.jsx)(w7,{summary:`Cost by step`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:e.costs.rows.map(e=>(0,h.jsxs)(`li`,{children:[a(e.stage),`: `,Hxe(e),`. `,e.detail]},`${e.stage}-${e.detail}`))})})]}),n,(0,h.jsxs)(`div`,{className:`sticky bottom-[-16px] -mx-4 flex flex-col gap-3 border-t border-line bg-raised px-4 py-3`,children:[e.providedReuseRequired.length===0&&e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small`,children:[e.providedReuseRequired.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...zb,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:o.includes(e),onChange:t=>s(t.target.checked?[...o,e]:o.filter(t=>t!==e))}),(0,h.jsxs)(`span`,{children:[`Keep the provided content for `,a(e)]})]}),(0,h.jsx)(U,{id:`project.rebuild.keep-provided`,className:`-my-1`})]},e)),e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...zb,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:c,onChange:e=>l(e.target.checked)}),(0,h.jsxs)(`span`,{children:[`I understand that `,e.costs.unknown,` cost estimates are unknown.`]})]}),(0,h.jsx)(U,{id:`project.rebuild.unknown-costs`,className:`-my-1`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(B,{variant:`primary`,disabled:t||!v,"aria-describedby":v?void 0:u,onClick:()=>r({acknowledgeUnknownCosts:c,confirmedProvidedWorkKeys:o}),children:t?`Starting the remake…`:g}),(0,h.jsx)(B,{disabled:t,onClick:i,children:`Keep things as they are`}),v||t?null:(0,h.jsx)(`p`,{id:u,className:`m-0 min-w-0 text-small text-ink-2`,children:`${g} is off until: ${_.join(`; `)}.`})]})]})]})}function w7({summary:e,children:t}){return(0,h.jsxs)(`details`,{className:`py-3 text-small`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold text-ink`,children:e}),(0,h.jsx)(`div`,{className:`mt-3`,children:t})]})}function T7({label:e,text:t}){return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`pre`,{className:`m-0 max-h-40 overflow-auto whitespace-pre-wrap break-words text-small`,children:t??`Not set`})]})}var E7=e=>e===null?`Unknown`:e===0?`$0`:new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:e>0&&e<.01?4:2}).format(e);function D7(e,t){return e===t?E7(e):`${E7(e)}–${E7(t)}`}function Hxe(e){return e.onPlan===!0?`$0 on plan${e.apiLow===void 0||e.apiLow===null||e.apiHigh===void 0?``:` · ~${D7(e.apiLow,e.apiHigh??null)} via API`}`:D7(e.low,e.high)}var Uxe=[`generate`,`local`,`review`,`reuse`,`blocked`];function Wxe(e,t){let n=new Map;for(let t of e){let e=t.reason.trim()||`No reason was given.`;n.set(e,[...n.get(e)??[],t.key])}return[...n].map(([e,n])=>({reason:e,what:n.length===1?t(n[0]??``):`${n.length} ${new Set(n.map(k7)).size===1?Gxe(k7(n[0]??``)):`items`}`}))}function Gxe(e){return/s$/u.test(e)?e:`${e.charAt(0).toLowerCase()}${e.slice(1)}s`}var O7={reuse:`kept as they are`,generate:`to make`,local:`built on this computer`,review:`to confirm`,blocked:`can't run`},Kxe={"export:wav":`Audio export (WAV)`,"export:video":`Video export`,"subtitles:timing":`Subtitle timing`,"subtitles:cues":`Caption text and timing`,"subtitles:files":`Subtitle files`,"article:body":`Article`,"audio:provided":`Provided narration`,"audio:body:concat":`Combined narration`,"audio:intro":`Combined intro narration`,"audio:outro":`Combined outro narration`,"research:planner":`Research plan`,"research:notes":`Research notes`,"entry:intro:text":`Intro text`,"entry:outro:text":`Outro text`};function k7(e){let t=Kxe[e];return t===void 0?{image:`Image request`,images:`Images`,audio:`Narration request`,article:`Article`,research:`Research`,thumbnail:`Thumbnail`,subtitles:`Subtitles`,video:`Video export`,export:`Export`,entry:`Intro or outro`}[e.split(`:`)[0]??``]??`Output`:t}function qxe(e){let t=new Map,n=new Map;for(let t of e.work){let e=k7(t.key);n.set(e,(n.get(e)??0)+1)}let r=new Map;for(let i of e.work){let e=k7(i.key),a=(r.get(e)??0)+1;r.set(e,a),t.set(i.key,(n.get(e)??0)>1?`${e} ${a}`:e)}for(let n of e.review?.requests??[])t.set(n.key,n.label);return e=>t.get(e)??k7(e)}var Jxe={llm:`Text generation`,image:`Images`,images:`Images`,tts:`Audio`,audio:`Audio`};function A7({error:e,refusal:t}){let n=(0,m.useRef)(null);return(0,m.useEffect)(()=>{(e!==void 0||t!==void 0)&&n.current?.focus()},[e,t]),e===void 0&&t===void 0?null:(0,h.jsxs)(`div`,{ref:n,role:`alert`,tabIndex:-1,"data-tone":`danger`,className:`sl-callout sl-callout--danger outline-none`,children:[(0,h.jsx)(el,{"aria-hidden":`true`,strokeWidth:1.75}),(0,h.jsx)(`p`,{className:`sl-callout__title m-0`,children:e??(t?.reason===`readiness`?t.fields.length>0?`This can't start yet. Fix the items below, then try again.`:`Slopify couldn't check your providers. Open Settings → Providers, make sure each one you use is set up, then try again.`:t?.message)}),t?.fields.length?(0,h.jsx)(`ul`,{className:`sl-callout__body m-0 list-disc pl-5`,children:t.fields.map(({field:e,message:t})=>(0,h.jsxs)(`li`,{children:[Jxe[e.split(`.`)[0]??``]??`Project`,`: `,t]},`${e}:${t}`))}):null]})}var Yxe=Y({text:K().optional(),logicalText:K().optional(),title:K().optional(),notes:K().optional(),outline:J(K()).optional(),prompt:K().optional()});function Xxe(e){if(e===null)return`No text was recorded for this part.`;try{let t=Yxe.safeParse(JSON.parse(e));if(!t.success)return`Recorded text cannot be decoded.`;let{logicalText:n,text:r,title:i,notes:a,outline:o,prompt:s}=t.data;return[n,r,a?.trim()?[i,a].filter(e=>e?.trim()).join(`
305
+ `)}function nxe({cues:e,duration:t,onChange:n,onPending:r}){let i=(0,m.useId)(),[a,o]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[s,c]=(0,m.useState)(),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(r);d.current=r,(0,m.useEffect)(()=>{d.current(l)},[l]),(0,m.useEffect)(()=>()=>d.current(!1),[]);function f(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){c(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,o]of a.entries()){let a=o.start.trim()===``?NaN:Number(o.start),s=o.end.trim()===``?NaN:Number(o.end);if(r.has(o.id)){c(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(o.id),!Number.isFinite(a)||a<0||a<i){c(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=a||s>t){c(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(o.text.trim()===``){c(`Caption ${n+1}: enter caption text.`);return}e.push({id:o.id,text:o.text,start:a,end:s,...o.speaker===void 0?{}:{speaker:o.speaker}}),i=s}n(e),c(void 0),u(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(U,{id:`project.captions.editor`})]}),a.map((e,t)=>(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Caption `,t+1]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(BB,{id:`${i}-${e.id}-text`,value:e.text,onChange:n=>{u(!0),o(a.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(zB,{id:`${i}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{u(!0),o(a.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(zB,{id:`${i}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{u(!0),o(a.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:s}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:f,children:`Apply caption edits to draft`}),(0,h.jsx)(U,{id:`project.captions.apply`})]}),l?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function l7(e){return`imagePrompts.${String(e)}`}function u7(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function rxe(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function ixe(e){let{from:t,to:n,content:r}=e,i=n.map(e=>t.findIndex(t=>t.name===e.name)),a=[],o={},s={};for(let[e,t]of Object.entries(r.promptTemplates))u7(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))u7(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=l7(t),l=i[t]??-1;if(l>=0){let t=l7(l);Object.hasOwn(r.promptTemplates,t)&&(o[n]=r.promptTemplates[t]??null);let i=e.rendered[t];i!==void 0&&(s[n]=i);continue}let u=e.body(c.name);if(u===void 0){a.push({field:`imagePrompts.${String(t)}.name`,message:`The image prompt "${c.name}" is not in the Library any more. Untick it under Images, or add it back on Library → Prompts.`});continue}o[n]=u,s[n]=FK(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=u7(r.imageDefinitions[e]?.templateKey);n===void 0||n>=t.length||c.set(n,[...c.get(n)??[],e])}let l={},u=[],d=[],f=(e,t)=>{let n=l7(e),r=o[n];return t===void 0?{source:`generate`,assetId:null,prompt:s[n]??null,templateKey:r==null?null:n}:{...t,source:`generate`,assetId:null,templateKey:t.templateKey??null}},p=(t,n,r)=>Array.from({length:Math.max(0,n)},()=>{let n=e.key();return l[n]=f(t,r),u.push(n),n}),m=[];for(let e of r.imageOrder){let a=r.imageDefinitions[e];if(a===void 0)continue;let o=u7(a.templateKey);if(o===void 0||o>=t.length){l[e]=a,m.push(e);continue}let s=i.indexOf(o);if(s===-1){d.push(e);continue}let u=c.get(o)??[],f=t[o]?.number!==n[s]?.number,h=f?n[s]?.number??0:u.length,g=u.indexOf(e);if(g>=h){d.push(e);continue}let _=a.templateKey===l7(s)?a:{...a,templateKey:l7(s)};l[e]=_,m.push(e),f&&g===Math.min(u.length,h)-1&&m.push(...p(s,h-u.length,_))}for(let[e,r]of n.entries()){let n=i[e]??-1,a=n>=0?c.get(n)??[]:[];n>=0&&(a.length>0||t[n]?.number===r.number)||m.push(...p(e,r.number,void 0))}return{ok:!0,content:{...r,imageOrder:m,imageDefinitions:l,promptTemplates:o},rendered:s,added:u,removed:d}}function axe({edit:e,saved:t,prompts:n,problem:r,onChange:i}){let{config:a}=e;if(a.sources.images!==`generate`)return null;let o=n.filter(e=>e.kind===`image`);return(0,h.jsxs)(`section`,{"aria-label":`Image prompts`,className:`space-y-3`,children:[(0,h.jsx)(G3,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(oxe,{edit:e,saved:t,prompts:o,problem:r})]})}function oxe({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(rxe(t,i))return a===void 0?null:(0,h.jsx)(d7,{children:a});let o=0,s=ixe({from:t,to:i,content:e.content,rendered:e.config.rendered,values:e.config.values,body:e=>n.find(t=>t.name===e)?.body,key:()=>`planned-${String(++o)}`});if(!s.ok)return(0,h.jsx)(d7,{children:s.fields.map(e=>e.message).join(` `)});let c=e=>`${String(e)} ${e===1?`image`:`images`}`,l=[...s.added.length>0?[`adds ${c(s.added.length)} to make`]:[],...s.removed.length>0?[`removes ${c(s.removed.length)}`]:[]];return(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsx)(d7,{children:a}),(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.length===0?`Saving keeps every image as it is.`:`Saving ${l.join(` and `)}. The other images are kept; the new ones are made when you remake outdated outputs.`})]})}function d7({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function sxe({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:Zk(r)),o=r?.source===`upload`?[...Wk,`upload`]:Wk,s=i===void 0?[]:[...uxe(i)];return(0,h.jsx)(s2,{value:i,inherit:`None`,sources:o,offerNone:!1,problem:e=>t(`ambientBed.${e}`)??s.find(t=>t.field===e)?.message,onChange:t=>{a(t);let r=Qk(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function cxe({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...JO,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(T6,{value:i,problem:e=>t(`loudness.${e}`),onChange:t=>{a(t);let{loudness:r,...i}=e.config;n({...e,config:t.enabled?{...i,loudness:{videoLufs:t.videoLufs,audioFilesLufs:t.audioFilesLufs}}:i})}})}function lxe({edit:e,problem:t,onChange:n}){let[r,i]=(0,m.useState)(()=>({sentencePauseSeconds:String(e.config.sentencePauseSeconds??0),paragraphPauseSeconds:String(e.config.paragraphPauseSeconds??0)}));if(e.config.sources.audio!==`generate`)return null;let a=e=>{let t=j6(r[e]);return t===void 0?`Enter a number of seconds.`:pk(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(A6,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=j6(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function uxe(e){let t=Qk(e);return t===void 0?[]:Yk(t)}function dxe({edit:e,problem:t,onChange:n}){let r=(0,m.useId)(),{config:i}=e,a=i.imageScale,[o,s]=(0,m.useState)(()=>a===void 0?void 0:UO(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(BO(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=f7(t);l!==void 0&&n({...e,config:{...o,imageScale:{perHour:l,words:c},...a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})},u=i.imagePrompts.reduce((e,t)=>e+t.number,0),d=a===void 0?u:KO(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:f7(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(IO)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(VO(c))))} minutes of narration: ${String(d)} images${d>u?`, ${String(d-u)} more than the prompts' ${String(u)}`:`, which the prompts' Numbers already cover`}.`},g=t(`imageScale`)??void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,...zb,children:[(0,h.jsx)(Bb,{checked:o!==void 0,label:`More images for long videos`,describedBy:`${r}-line`,tip:`play.image-scale`,onChange:e=>l(e?{every:`minutes`,value:`2`}:void 0)}),o===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(Vb,{label:`How the rate is given`,value:o.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>l({every:e,value:fxe(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(zB,{"aria-label":o.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`w-[72px] tabular-nums`,"aria-invalid":p?.problem===!0,"aria-describedby":`${r}-line`,value:o.value,onChange:e=>l({every:o.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:o.every===`minutes`?`minutes`:`images per hour`})]}),g===void 0&&p===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:g!==void 0||p?.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:g??p?.text})]})}function f7(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?HO(t):void 0:t>=1&&t<=240?t:void 0}function fxe(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function pxe({edit:e,onChange:t}){let{config:n}=e;return n.sources.images!==`generate`||n.sources.article===`off`?null:(0,h.jsx)(`div`,{className:`flex flex-col items-start gap-2`,...zb,children:(0,h.jsx)(Bb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,config:{...a,...r?{imageScenes:!0}:{}}})}})})}function mxe({edit:e,view:t,imageKey:n,index:r}){let{api:i}=V(),a=e.content.imageDefinitions[n];if(a===void 0)return null;let o=t?.outputs.filter(e=>e.output.stageKind===`images`&&e.output.role===`image`)??[],s=o.find(e=>e.selected&&e.workKey===`image:${n}`),c=e.uploads?.some(e=>e.destination.kind===`image`&&e.destination.imageKey===n)??!1,l=a.source===`generate`||c||s?.assetId===a.assetId?s:o.find(e=>e.assetId===a.assetId&&e.available),u=l?.available===!0,d=!u&&(l!==void 0||a.source===`provide`&&a.assetId!==null),f=e.regenerate?.includes(`image:${n}`)===!0,p=c?u?`Replacement ready to save; previous image shown until Save`:`Replacement ready to save; preview available after Save`:f?`Made again after you press Save changes; the current image stays until then`:d?`Image file unavailable`:u?a.source===`provide`&&l!==s?`Provided image selected`:l.state===`review`?`Image retained; review required`:l.state===`outdated`?`Outdated image retained until rebuilt`:`Current image retained`:`No completed image yet`,m=u&&/\.(mp4|mov|m4v|webm|mkv)$/i.test(l.output.path);return(0,h.jsxs)(h.Fragment,{children:[!u||t===void 0?null:m?(0,h.jsx)(c0,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:j0(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(l0,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:j0(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}function p7(e,t,n){let r=t+n,i=e[t],a=e[r];if(i===void 0||a===void 0)return e;let o=[...e];return o[t]=a,o[r]=i,o}function hxe({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),{content:c}=e,l=zO(e.config),u=(0,m.useRef)(e);u.current=e;function d(e){let n=e.content.imageOrder.flatMap(t=>{let n=e.content.imageDefinitions[t];return n===void 0?[]:[n]}),r=e.content.imageOrder.length===0||e.config.sources.images===`off`?`off`:n.some(e=>e.source===`generate`)?`generate`:`provide`,i={...e,config:{...e.config,sources:{...e.config.sources,images:r,...r===`off`?{video:`off`}:{}}}};u.current=i,t(i)}function f(e,t){let n=i?.()??u.current,r=n.content.imageDefinitions[e];if(r===void 0)return;let a=r.templateKey??`image:${e}`;s(t=>({...t,[e]:(t[e]??0)+1})),d(O5({...n,...n.uploads===void 0?{}:{uploads:n.uploads.filter(t=>t.destination.kind!==`image`||t.destination.imageKey!==e)},content:{...n.content,imageDefinitions:{...n.content.imageDefinitions,[e]:{...r,templateKey:a}}}},a,t))}function p(e){let t=i?.()??u.current,n=t.content,r=crypto.randomUUID();d({...t,config:{...t.config,sources:{...t.config.sources,images:t.config.sources.images===`off`?`provide`:t.config.sources.images}},content:{...n,imageOrder:[...n.imageOrder,r],imageDefinitions:{...n.imageDefinitions,[r]:{source:`provide`,assetId:null,prompt:null}}},uploads:[...t.uploads??[],{stagedFileId:e.id,destination:{kind:`image`,imageKey:r}}]})}return(0,h.jsxs)(`section`,{"aria-label":`Edit images`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Images`}),(0,h.jsx)(U,{id:`project.images.editor`})]}),c.imageOrder.map((t,s)=>{let l=c.imageDefinitions[t];return l===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(mxe,{edit:e,view:r,imageKey:t,index:s}),l.source===`generate`?(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${t}-prompt`,children:[`Prompt for image `,s+1]}),(0,h.jsx)(U,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(BB,{id:`${a}-${t}-prompt`,value:l.templateKey===void 0||l.templateKey===null?l.prompt??``:c.promptTemplates[l.templateKey]??l.prompt??``,onChange:e=>f(t,e.target.value)})]}):null,l.source===`generate`&&l.templateKey==null?(0,h.jsxs)(B,{type:`button`,onClick:()=>f(t,l.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(k5,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??u.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&d({...n,regenerate:(n.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:[...(n.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t),{stagedFileId:e.id,destination:{kind:`image`,imageKey:t}}],content:{...r,imageDefinitions:{...r.imageDefinitions,[t]:{...a,source:`provide`,prompt:null,templateKey:null}}}})}},`${t}:${o[t]??0}:${e.config.sources.images===`off`}`),(0,h.jsxs)(B,{type:`button`,disabled:s===0,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(B,{type:`button`,disabled:s===c.imageOrder.length-1,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(B,{type:`button`,onClick:()=>{let n=c.imageOrder.filter(e=>e!==t);d({...e,config:n.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...c,imageOrder:n,imageDefinitions:Object.fromEntries(Object.entries(c.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t)})},children:[`Delete image `,s+1,c.imageOrder.length===1?` and turn Images and Video Off`:``]}),l.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(B,{type:`button`,onClick:()=>d({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(B,{type:`button`,onClick:()=>d({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(U,{id:`project.images.regenerate`})]}):null]},t)}),(0,h.jsx)(B,{type:`button`,disabled:c.imageOrder.length>=l,onClick:()=>{if(c.imageOrder.length>=l)return;let t=crypto.randomUUID();d({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...c,imageOrder:[...c.imageOrder,t],promptTemplates:{...c.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...c.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),c.imageOrder.length>=l?(0,h.jsxs)(`p`,{children:[`At most `,l,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(k5,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:p},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(k5,{label:`Add a video clip`,kind:`images`,accept:`video/mp4,video/quicktime,video/webm,video/x-matroska,.mp4,.mov,.m4v,.webm,.mkv`,onPending:e=>n(`clip:new`,e),onReady:p},`new-clip:${e.config.sources.images===`off`}`)]})]})}var gxe=Y({logicalKey:K().min(1),logicalText:K(),segment:X([`body`,`intro`,`outro`]),text:K()});function _xe(e,t){if(t==null)return e;let n=[...t.intro??[],...t.body??[],...t.outro??[]];return n.length===0?e:n.flatMap(t=>e.filter(e=>e.key===t))}function vxe(e){let t=new Map,n=new Set,r=0;for(let i of e.pieces){if(!i.selected||i.stageKind!==`audio`||i.piece.kind!==`chunk`)continue;let e;try{e=i.piece.payload===null?null:JSON.parse(i.piece.payload)}catch{r++;continue}let a=gxe.safeParse(e);if(!a.success){r++;continue}let{logicalKey:o,logicalText:s}=a.data;if(n.has(o)){r++;continue}let c=t.get(o);if(c!==void 0&&c.text!==s){r+=c.parts+1,t.delete(o),n.add(o);continue}t.set(o,{key:o,text:s,parts:(c?.parts??0)+1})}return{groups:[...t.values()],unmapped:r}}function yxe({view:e,edit:t,onChange:n,onPending:r,getEdit:i}){let a=(0,m.useId)(),{api:o}=V(),s=I({queryKey:[`narration-chunks`,e.revision.projectId,e.revision.id],queryFn:async()=>{let t=await Ape(o,e.revision.projectId,e.revision.id);return t.ok?t.value.chunks:null},staleTime:1/0}),c=vxe(e),l=_xe(c.groups,s.data),u=c.unmapped,d=(0,m.useRef)(t);d.current=t;let[f,p]=(0,m.useState)({});function g(e){d.current=e,n(e)}return(0,h.jsxs)(`section`,{"aria-label":`Edit narration`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Narration`}),(0,h.jsx)(U,{id:`project.narration.editor`})]}),t.config.chunking?.mode===`whole`||t.config.chunking===void 0?(0,h.jsx)(`p`,{children:`This narration uses one whole request. Editing its text rebuilds the whole narration request.`}):null,u===0?null:(0,h.jsx)(`p`,{children:`Some older audio cannot be matched reliably to its narration text. Replace the provided narration or rebuild from the article to edit those chunks.`}),l.map((e,n)=>{let o=t.content.narrationOverrides[e.key];return(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Narration chunk `,n+1]}),(0,h.jsxs)(`p`,{children:[e.parts,` audio `,e.parts===1?`part`:`parts`,` in this narration chunk.`]}),(0,h.jsxs)(`div`,{className:`text-small`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.key}-text`,children:[`Text for narration chunk `,n+1]}),(0,h.jsx)(U,{id:`project.narration.chunk-text`,label:`text for narration chunk ${String(n+1)}`})]}),(0,h.jsx)(BB,{id:`${a}-${e.key}-text`,value:o?.kind===`text`?o.text:e.text,onChange:n=>{p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,...t.uploads===void 0?{}:{uploads:t.uploads.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key)},content:{...t.content,narrationOverrides:{...t.content.narrationOverrides,[e.key]:{kind:`text`,text:n.target.value}}}})}})]}),(0,h.jsx)(k5,{label:`Replace narration chunk ${n+1}`,kind:`audio`,onPending:t=>r(`narration:${e.key}`,t),onReady:t=>{let n=i?.()??d.current;g({...n,regenerate:(n.regenerate??[]).filter(t=>t!==e.key),uploads:[...(n.uploads??[]).filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),{stagedFileId:t.id,destination:{kind:`narration`,key:e.key}}]})}},`${e.key}:${f[e.key]??0}`),t.regenerate?.includes(e.key)?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Narration chunk `,n+1,` will be regenerated after you save and press Remake.`,(0,h.jsxs)(B,{type:`button`,variant:`quiet`,onClick:()=>{let t=i?.()??d.current;g({...t,regenerate:(t.regenerate??[]).filter(t=>t!==e.key)})},children:[`Keep narration chunk `,n+1]})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(B,{type:`button`,onClick:()=>{let t=i?.()??d.current,n={...t.content.narrationOverrides};n[e.key]?.kind===`asset`&&delete n[e.key],p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,content:{...t.content,narrationOverrides:n},uploads:t.uploads?.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),regenerate:[...new Set([...t.regenerate??[],e.key])]})},children:[`Regenerate narration chunk `,n+1,` after review`]}),(0,h.jsx)(U,{id:`project.narration.regenerate`})]})]},e.key)})]})}function bxe(e){let{config:t,fingerprints:n}=e.revision;if(t.sources.audio===`off`)return;let r=t.sources.audio===`provide`?[{key:`audio:provided`,role:`audio_body`}]:[...t.intro===void 0?[]:[{key:`audio:intro`,role:`audio_intro`}],{key:`audio:body:concat`,role:`audio_body`},...t.outro===void 0?[]:[{key:`audio:outro`,role:`audio_outro`}]],i=e.outputs.filter(e=>e.selected&&e.state===`ready`&&e.available&&e.fingerprint===n[e.workKey]),a=r.map(({key:e,role:t})=>i.find(n=>n.workKey===e&&n.output.role===t));if(a.some(e=>e===void 0))return;let o=a.map(e=>e?.output.durationMs);if(o.every(m7))return o.reduce((e,t)=>e+t,0)/1e3+Math.max(0,r.length-1)*t.silenceGapSeconds+2*t.edgeSilenceSeconds;let s=i.find(e=>(e.output.role===`audio_export`||e.output.role===`video`)&&m7(e.output.durationMs))?.output.durationMs;return m7(s)?s/1e3:void 0}function m7(e){return e!=null&&Number.isFinite(e)&&e>0}function xxe({edit:e,prompts:t,problem:n,onChange:r,onPending:i,getEdit:a}){let{config:o}=e;if(o.sources.images!==`generate`)return null;let s=o.reference,c=s===void 0?m6:{source:s.source,prompt:s.prompt??``,thumbnail:s.thumbnail!==!1},l=e=>({...e,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`provided`||e.destination.stage!==`reference`)});return(0,h.jsx)(`section`,{"aria-label":`Establishing image`,className:`space-y-3`,children:(0,h.jsx)(h6,{value:c,prompts:t,problem:n,onChange:n=>{let{reference:i,...a}=o;if(n.source===`off`){r(l({...e,config:a}));return}let s={source:n.source,...n.source===`prompt`?{prompt:n.prompt}:{},...n.thumbnail?{}:{thumbnail:!1}},u=n.source===`prompt`&&n.prompt!==c.prompt?t.find(e=>e.kind===`image`&&e.name===n.prompt):void 0,d={...e,config:{...a,reference:s}},f=u===void 0?d:O5(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(k5,{label:e.content.provided.reference===void 0?`Upload the establishing image`:`Replace the establishing image`,kind:`images`,accept:`image/png,image/jpeg`,onPending:i,onReady:t=>{let n=l(a?.()??e);n.config.reference?.source===`provide`&&r({...n,uploads:[...n.uploads??[],{stagedFileId:t.id,destination:{kind:`provided`,stage:`reference`}}]})}})})})}var Sxe=Y({words:J(Y({text:K().trim().min(1),start:q().finite().nonnegative(),end:q().finite().positive(),confidence:q().optional(),speaker:K().min(1).optional()})).min(1)});function h7(e){let{config:t,content:n}=e;return JSON.stringify({source:t.sources.audio,audio:n.provided.audio,uploads:e.uploads?.filter(e=>e.destination.kind===`narration`||e.destination.kind===`provided`&&e.destination.stage===`audio`)??[],edge:t.edgeSilenceSeconds,...t.sources.audio===`generate`?{choice:t.audio,chunking:t.chunking,article:n.articleMarkdown??t.provided.article,articleSource:t.sources.article,renderedArticle:t.rendered.article,intro:t.intro,outro:t.outro,renderedIntro:t.rendered.intro,renderedOutro:t.rendered.outro,gap:t.silenceGapSeconds,overrides:n.narrationOverrides,regenerate:e.regenerate?.filter(e=>/^(audio:|article:|entry:)/.test(e))??[]}:{}})}function Cxe({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=V(),s=I(pb(o)).data?.prompts??[],c=h7(t),l=t.config.sources.audio!==`off`&&c===h7({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?bxe(e):void 0,f=d!==void 0&&u!==void 0&&u!==``,p=(0,m.useRef)({edit:t,onChange:r,revisionId:e.revision.id,identity:c});p.current={edit:t,onChange:r,revisionId:e.revision.id,identity:c};let g=(0,m.useRef)(i);g.current=i;let[_,v]=(0,m.useState)(new Set),[y,b]=(0,m.useState)(),x=(0,m.useRef)(void 0),S=(0,m.useRef)(!0),C=(0,m.useCallback)((e,t)=>{S.current&&v(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,m.useEffect)(()=>{g.current(_.size>0)},[_]),(0,m.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&x.current?.abort()}},[e.revision.id,c]);function w(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:h7(e)},t(e)}async function T(){if(x.current!==void 0)return;let t=new AbortController;x.current=t;let n=p.current;C(`captions:load`,!0),b(void 0);try{let r=e.outputs.find(e=>e.selected&&e.state===`ready`&&e.output.role===`subtitle_words`&&e.available);if(!f||d===void 0||u===void 0||r===void 0)throw Error(`Captions can't be edited until the current narration has finished and its subtitle timing is ready.`);let i=await o.fetch(j0(o,e.revision.projectId,e.revision.id,r.recordId),{signal:t.signal});if(!i.ok)throw Error(`The subtitle timing file couldn't be read. Reload the page and try again; if it still fails, use More → make it again in its section on Audio.`);let a=Sxe.parse(await i.json()),s=0;for(let e of a.words){if(e.start<s||e.end<=e.start||e.end>d)throw Error(`The saved subtitle timing doesn't match the current narration. Use More → make it again in its section on Audio to rebuild it.`);s=e.end}let c=txe(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!S.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;w({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){S.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{x.current===t&&(x.current=void 0),C(`captions:load`,!1)}}let E=t.content.subtitleCues,D=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!D(`images`),className:`space-y-6`,children:[(0,h.jsx)(axe,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(dxe,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(pxe,{edit:t,onChange:w}),(0,h.jsx)(xxe,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:w,onPending:e=>C(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(M6,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;w({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(k5,{label:`Replace provided ${e}`,kind:e,onPending:t=>C(`provided:${e}`,t),onReady:t=>{let n=p.current;n.edit.config.sources[e]===`provide`&&w({...n.edit,uploads:[...(n.edit.uploads??[]).filter(t=>t.destination.kind!==`provided`||t.destination.stage!==e),{stagedFileId:t.id,destination:{kind:`provided`,stage:e}}]})}},e):null),(0,h.jsx)(hxe,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!D(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(yxe,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!D(`captions`),className:`space-y-5`,children:[f?null:(0,h.jsx)(`p`,{children:`Captions can be edited once the current narration has finished and its subtitle timing is ready.`}),E===void 0?(0,h.jsx)(B,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void T(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[E.audioFingerprint===u?null:(0,h.jsx)(`p`,{children:`These caption edits belong to an earlier narration. Review their text and timing against the current narration, then apply your corrections and save the project.`}),f&&d!==void 0?(0,h.jsx)(nxe,{cues:E.cues,duration:d,onPending:e=>C(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&w({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(B,{type:`button`,onClick:()=>w({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function wxe({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(o2,{value:e.config.language,error:t,onChange:t=>{let{language:r,...i}=e.config;n({...e,config:t===void 0||t===`en`?i:{...i,language:t}})}})})}function Txe({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=V(),a=I(cx(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:tx,c=s(o.channelId),l=a.data?.find(e=>e.id===c),u=o.useBrandKit!==!1,d=c!==s(t.channelId),f=u!==(t.useBrandKit!==!1);return(0,h.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(fa,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(VB,{value:c,onChange:t=>r({...e,config:{...o,channelId:t.target.value}}),children:[a.data===void 0?(0,h.jsx)(`option`,{value:c,children:`Loading channels…`}):null,(a.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col justify-end gap-1`,children:[(0,h.jsx)(Bb,{checked:u,label:`Use the channel's brand kit`,tip:`play.brand-kit`,onChange:t=>{let{useBrandKit:n,...i}=o;r({...e,config:t?i:{...i,useBrandKit:!1}})}}),u?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Its cast is still used.`})]}),a.error===null?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-danger md:col-span-2`,children:[`The channels couldn't be loaded: `,a.error.message,`. Reload the page to pick a channel.`]}),d||f?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:[d?`Saving moves the project to this channel and takes its cast as it is now. `:``,u?`The brand kit fills the caption font and colours, title style, end screen, intro, outro and document theme where they are at their default or were set by the old kit.`:`What the old brand kit had set is taken off.`]}):null]})}function Exe(e,t,n){let r=e.outputs.find(e=>e.selected&&e.available&&e.output.role===`reference`);if(t.config.reference!==void 0&&r!==void 0)return{image:{kind:`output`,outputId:r.output.id},drawnOn:`the establishing image`};let i=n.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),a=B6([t.config.title,...Object.values(t.config.values??{})].join(` `),i)[0]??i[0],o=a?.images[0];if(a!==void 0&&o!==void 0)return{image:{kind:`picture`,sha256:o},drawnOn:`${a.name}'s picture`}}function Dxe({edit:e,view:t,prompts:n,error:r,onChange:i}){let a=(0,m.useRef)(e.config.narrationPrompt);if(e.config.sources.audio!==`generate`)return null;let o=t.revision.config.narrationPrompt,s=t.revision.content.promptTemplates.narration??t.revision.config.rendered.narration,c=o&&s!==void 0&&!n.some(e=>e.kind===`narration`&&e.name===o)?[...n,{id:`saved-narration`,kind:`narration`,name:o,body:s,slots:[],updatedAt:t.revision.createdAt}]:n;return(0,h.jsx)(f6,{value:e.config.narrationPrompt??``,prompts:c,libraryLinks:!1,supported:e.config.audio?.provider===`inworld`&&e.config.audio.model===`inworld-tts-2`,error:r,onChange:t=>{let n=e.config.narrationPrompt||a.current;t===``&&(a.current=e.config.narrationPrompt);let r=c.find(e=>e.kind===`narration`&&e.name===t),o=r===void 0||t===n?e:O5(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function Oxe({edit:e,saved:t=e.config.imagePrompts,prompts:n,entries:r,onChange:i}){let a=(0,m.useId)(),o=[...new Set([...Object.keys(e.config.rendered),...Object.keys(e.content.promptTemplates),...e.config.sources.article===`generate`?[`article`]:[],...rj(e.config)?[`narration`]:[],...oj(e.config)&&e.config.descriptionPrompt?[`description`]:[],...uj(e.config)&&e.config.shorts?.prompt?[`shorts`]:[],...uj(e.config)&&e.config.shorts?.imagePrompt?[`shortsImage`]:[],...[`from_prompt`,`prompt_by_llm`].includes(e.config.sources.thumbnail)?[`thumbnailPrompt`]:[],...cj(e.config)&&e.config.reference?.source===`prompt`?[`referencePrompt`]:[],...e.config.intro===void 0?[]:[`intro`],...e.config.outro===void 0?[]:[`outro`]])].filter(n=>{let r=y7(n);if(r===void 0)return!0;let i=t[r]?.name;return i===void 0||e.config.imagePrompts.some(e=>e.name===i)}),s=e.config.imagePrompts.filter(e=>!t.some(t=>t.name===e.name)),c=e=>jxe(e,t),l=[...new Set([...Object.keys(e.config.values),...Object.values(e.content.promptTemplates).flatMap(e=>e===null?[]:MK(e).names)])].filter(e=>!NK.includes(e)),u=t=>[...MK(e.config.title).names.includes(t)?[`Project title`]:[],...Object.entries(e.content.promptTemplates).flatMap(([e,n])=>n!==null&&MK(n).names.includes(t)?[c(e)]:[])],d=MK(e.config.title).names;return(0,h.jsxs)(`section`,{"aria-label":`Prompt snapshots`,className:`space-y-6`,children:[o.map(o=>{let s=c(o),l=e.content.promptTemplates[o]??null,u=o===`intro`||o===`outro`?r.filter(e=>e.category===o):n.filter(t=>t.kind===(o===`article`?IA(e.config)?`script`:`article`:o===`narration`?`narration`:o===`description`?`description`:o===`shorts`?`shorts`:o===`thumbnailPrompt`?`thumbnail`:`image`));return(0,h.jsxs)(`div`,{className:`min-w-0 space-y-4 border-t border-line pt-6 first:border-t-0 first:pt-0`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:s}),l===null?(0,h.jsx)(aI,{tone:`info`,title:`Original template unavailable`,actions:(0,h.jsx)(B,{"aria-label":`Use saved wording as template for ${s}`,onClick:()=>i(O5(e,o,e.config.rendered[o]??``)),children:`Use saved wording as template`}),children:`The saved prompt below stays as it is until you choose or write a template.`}):null,(0,h.jsx)(Axe,{label:s,raw:l,library:kxe(e,o,u,t),onUse:t=>i(O5(e,o,t))}),(0,h.jsx)(LB,{label:`Use saved template for ${s}`,id:`${a}-library-${o}`,tip:`project.prompts.template`,children:(0,h.jsxs)(VB,{value:``,onChange:t=>{let n=u.find(e=>e.id===t.target.value);if(n===void 0)return;let r=O5(e,o,n.body),a=`category`in n?{...r.config,[n.category]:{name:n.name,mode:n.mode}}:o===`article`?{...r.config,articlePrompt:n.name}:o===`narration`?{...r.config,narrationPrompt:n.name}:o===`description`?{...r.config,descriptionPrompt:n.name}:(o===`shorts`||o===`shortsImage`)&&r.config.shorts!==void 0?{...r.config,shorts:{...r.config.shorts,[o===`shorts`?`prompt`:`imagePrompt`]:n.name}}:o===`thumbnailPrompt`?{...r.config,thumbnailPrompt:n.name}:o===`referencePrompt`&&r.config.reference!==void 0?{...r.config,reference:{...r.config.reference,prompt:n.name}}:r.config;i({...r,config:a})},children:[(0,h.jsx)(`option`,{value:``,children:`Choose a saved template`}),u.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,h.jsx)(LB,{label:`Raw prompt for ${s}`,id:`${a}-raw-${o}`,tip:`project.prompts.raw`,children:(0,h.jsx)(BB,{rows:4,value:l??``,onChange:t=>i(O5(e,o,t.target.value))})}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`text-small text-ink-2`,children:`Saved rendered prompt`}),(0,h.jsx)(`pre`,{className:`m-0 mt-2 whitespace-pre-wrap break-words text-small`,children:e.config.rendered[o]??``})]})]},o)}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s.map(e=>`"${e.name}"`).join(`, `),` `,s.length===1?`uses its`:`use their`,` Library wording. Save, then change it here.`]}),l.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`space-y-3 pt-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:`Keywords`}),(0,h.jsx)(V1,{fieldPrefix:`config.values`,keywords:l.map(t=>({name:t,value:e.config.values[t]??``,feeds:u(t),topic:d.includes(t)})),onChange:(t,n)=>i(D5({...e,config:{...e.config,values:{...e.config.values,[t]:n}}}))})]}):null]})}function kxe(e,t,n,r){let{config:i}=e,a=y7(t);if(t===`intro`||t===`outro`){let e=i[t]?.name;return e===void 0||e===``?void 0:n.find(t=>`category`in t&&t.name===e)}let o=t===`article`?i.articlePrompt:t===`narration`?i.narrationPrompt:t===`description`?i.descriptionPrompt:t===`shorts`?i.shorts?.prompt:t===`shortsImage`?i.shorts?.imagePrompt:t===`thumbnailPrompt`?i.thumbnailPrompt:t===`referencePrompt`?i.reference?.prompt:a===void 0?void 0:r[a]?.name;if(o!==void 0&&o!==``)return n.find(e=>!(`category`in e)&&e.name===o)}var g7=`slopify.library-kept`;function _7(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t*33^e.charCodeAt(n))>>>0;return t.toString(36)}function v7(){try{let e=window.localStorage.getItem(g7),t=e===null?[]:JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Axe({label:e,raw:t,library:n,onUse:r}){let i=n===void 0||t===null?``:`${e}:${_7(t)}:${_7(n.body)}`,[a,o]=(0,m.useState)(()=>v7().includes(i));return n===void 0||t===null||n.body===t||a?null:(0,h.jsx)(aI,{tone:`info`,title:`The Library's "${n.name}" has changed since this project copied it`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{"aria-label":`Use the Library version for ${e}`,onClick:()=>{r(n.body)},children:`Use the Library version`}),(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Keep this project's version for ${e}`,onClick:()=>{try{window.localStorage.setItem(g7,JSON.stringify([...v7().filter(e=>e!==i),i].slice(-200)))}catch{}o(!0)},children:`Keep this project's version`})]}),children:`The project uses its own copy below until you choose. Using the Library version marks what it wrote as outdated, to remake when you are ready.`})}function y7(e){let t=/^imagePrompts\.(\d+)$/.exec(e);return t?.[1]===void 0?void 0:Number(t[1])}function jxe(e,t){if(e===`article`)return`Article`;if(e===`narration`)return`Narration Preparation`;if(e===`description`)return`YouTube description`;if(e===`shorts`)return`Shorts`;if(e===`shortsImage`)return`Shorts image style`;if(e===`thumbnailPrompt`)return`Thumbnail`;if(e===`referencePrompt`)return`Establishing image`;if(e===`intro`)return`Intro`;if(e===`outro`)return`Outro`;let n=y7(e);if(n!==void 0){let e=t[n]?.name;return e===void 0||e===``?`Image prompt ${String(n+1)}`:`Image prompt "${e}"`}return e.replace(/[._-]/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`)}function Mxe(e,t,n){let{api:r}=V(),[i,a]=(0,m.useState)({busy:!1}),{config:o}=t,s=o.audio,c=async()=>{if(s!==void 0){a({busy:!0});try{let i=await Zs(r,e),{sharedGlossary:c,...l}=o;n({...t,config:{...l,audio:{...s,shareGlossary:!0},...i.entries.length===0?{}:{sharedGlossary:i.entries}}}),a({busy:!1,projects:i.projects})}catch(e){a({busy:!1,error:e instanceof Error?e.message:String(e)})}}},l=()=>{if(s===void 0)return;let{sharedGlossary:e,...r}=o;n({...t,config:{...r,audio:{...s,shareGlossary:!1}}})},u=o.sharedGlossary?.length??0,d=s?.shareGlossary===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[i.error===void 0?u===0?`No pronunciations from other projects are copied yet.`:`${String(u)} ${u===1?`term`:`terms`} copied from ${i.projects===void 0?`your other projects`:`${String(i.projects)} other ${i.projects===1?`project`:`projects`}`}.`:`Couldn't read your other projects' pronunciations: ${i.error}`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:i.busy,onClick:()=>void c(),children:i.busy?`Copying…`:`Update from other projects`}),(0,h.jsx)(U,{id:`project.edit.update-glossary`})]}):void 0;return{value:s?.shareGlossary===!0,onChange:e=>{e?c():l()},note:d}}function Nxe(e,t){let{api:n}=V(),[r,i]=(0,m.useState)({busy:!1}),{config:a}=e,o=a.audio,s=async()=>{if(o!==void 0){i({busy:!0});try{let{aliases:r}=await Qs(n),{narrationAliases:s,...c}=a;t({...e,config:{...c,audio:{...o,useNarrationAliases:!0},...r.length===0?{}:{narrationAliases:r}}}),i({busy:!1})}catch(e){i({busy:!1,error:e instanceof Error?e.message:String(e)})}}},c=a.narrationAliases?.length??0;return{value:o?.useNarrationAliases===!0,onChange:n=>{if(o!==void 0){if(n)s();else{let{narrationAliases:n,...r}=a;t({...e,config:{...r,audio:{...o,useNarrationAliases:!1}}})}}},note:o?.useNarrationAliases===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[r.error===void 0?c===0?`No aliases are copied yet. Add some in Library → Aliases.`:`${String(c)} ${c===1?`alias`:`aliases`} copied from Library → Aliases.`:`Couldn't read Library → Aliases: ${r.error} Try Update from Library again.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r.busy,onClick:()=>void s(),children:r.busy?`Copying…`:`Update from Library`}),(0,h.jsx)(U,{id:`project.edit.update-aliases`})]}):void 0}}function Pxe({projectId:e,edit:t,providers:n,voices:r,onChange:i}){let{config:a}=t,o=a.llm??{provider:``,model:``},s=a.audio??{provider:``,model:``,voice:``},c=Mxe(e,t,i),l=Nxe(t,i),{api:u}=V(),d=I(lx(u,a.channelId??`00000000-0000-4000-8000-000000000001`)),f=a.images??{provider:``,model:``},p=rj(a)||a.sources.audio===`generate`&&a.audio?.describeFigures===!0||a.sources.research===`generate`||a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||FA(a)&&a.voices?.source===`attribute`||a.sources.audio===`generate`&&(a.intro?.mode===`llm`||a.outro?.mode===`llm`),m=a.sources.images===`generate`||a.sources.thumbnail===`from_prompt`||a.sources.thumbnail===`prompt_by_llm`,g=r.filter(e=>e.provider===s.provider).map(e=>({value:e.voiceId,label:e.name}));return(0,h.jsxs)(`section`,{"aria-label":`Generation providers`,className:`grid min-w-0 gap-3 sm:grid-cols-2`,children:[p?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{label:`Text provider`,tip:`play.llm.provider`,family:`llm`,providers:n,value:o.provider,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{provider:e,model:``}}})}),(0,h.jsx)(tV,{label:`Text model`,tip:`play.llm.model`,provider:o.provider,value:o.model,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{...o,model:e}}})}),(0,h.jsx)(g6,{choice:o,onChange:e=>i({...t,config:{...a,llm:e}})})]}):null,a.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[a.voices!==void 0&&a.intro===void 0&&a.outro===void 0?null:(0,h.jsxs)(h.Fragment,{children:[a.voices===void 0?null:(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`The voice below reads only the intro and outro. Each speaker's voice is set under Speakers.`}),(0,h.jsx)(eV,{label:a.voices===void 0?`Narration provider`:`Intro and outro provider`,tip:`play.tts.provider`,family:`tts`,providers:n,value:s.provider,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,provider:e,model:``,voice:``}}})}),(0,h.jsx)(tV,{label:a.voices===void 0?`Narration model`:`Intro and outro model`,tip:`play.tts.model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,model:e}}})}),(0,h.jsx)(ZB,{label:a.voices===void 0?`Narration voice`:`Intro and outro voice`,tip:`play.voice`,value:s.voice,problem:void 0,placeholder:`Choose a saved voice`,options:s.voice!==``&&!g.some(e=>e.value===s.voice)?[{value:s.voice,label:`${s.voice} (saved voice)`},...g]:g,onPick:e=>i({...t,config:{...a,audio:{...s,voice:e}}})})]}),(0,h.jsx)(U3,{value:a.chunking??{mode:`whole`},onPick:e=>i({...t,config:{...a,chunking:e}})}),(0,h.jsx)(p6,{shared:c,value:s.usePronunciationGlossary,supported:hj({sources:a.sources,audio:{...s,usePronunciationGlossary:!0}}),onChange:e=>i({...t,config:{...a,audio:{...s,usePronunciationGlossary:e}}})}),(0,h.jsx)(d6,{...l}),(0,h.jsx)(l6,{tip:`project.edit.describe-figures`,value:s.describeFigures,skipCode:s.skipCode,onChange:({describeFigures:e,skipCode:n})=>{let{describeFigures:r,skipCode:o,...c}=s;i({...t,config:{...a,audio:{...c,...e?{describeFigures:e}:{},...e&&n?{skipCode:n}:{}}}})}}),(0,h.jsxs)(`section`,{"aria-label":`Speakers`,className:`col-span-full border-t border-line pt-3`,children:[(0,h.jsx)(`h3`,{className:`mb-2 text-small font-semibold`,children:`Speakers`}),(0,h.jsx)(c6,{value:a.voices,cast:d.data?.cast??[],language:a.language,providers:n,voices:r,script:t.content.articleMarkdown??void 0,onChange:e=>{let{voices:n,...r}=a;i({...t,config:e===void 0?r:{...r,voices:e}})}})]})]}):null,m?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(eV,{label:`Image provider`,tip:`play.images.provider`,family:`image`,providers:n,value:f.provider,problem:void 0,onPick:e=>i({...t,config:{...a,images:{provider:e,model:``}}})}),(0,h.jsx)(tV,{label:`Image model`,tip:`play.images.model`,provider:f.provider,value:f.model,problem:void 0,onPick:e=>i({...t,config:{...a,images:{...f,model:e}}})}),(0,h.jsx)(g6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:f,onChange:e=>i({...t,config:{...a,images:e}})})]}):null]})}function Fxe({edit:e,providers:t,prompts:n,problem:r,onChange:i}){let{config:a}=e,o=a.reviews===void 0?iV:wk(a.reviews),[s,c]=(0,m.useState)(o),l=a.shorts?.enabled===!0&&a.sources.audio!==`off`,u=e=>Ek({sources:a.sources,shorts:l?{enabled:!0}:void 0},e),d=Tk(s,u).retriesProblem;return(0,h.jsx)(aV,{value:s,providers:t,prompts:n,makes:u,problem:e=>e===`reviews.retries`&&d!==void 0?d:r(e),onChange:t=>{c(t);let{settings:r}=Tk(t,u),o={...e.content.promptTemplates},s={...a.rendered};for(let e of gk){let t=Ck(e),i=r?.stages[e]?.prompt??``,c=n.find(e=>e.kind===`review`&&e.name===i);if(i===``){let{[t]:e,...n}=o,{[t]:r,...i}=s;o=n,s=i}else c!==void 0&&i!==(a.reviews?.stages[e]?.prompt??``)&&(o={...o,[t]:c.body})}let{reviews:l,...d}=a;i(D5({...e,config:{...d,rendered:s,...r===void 0?{}:{reviews:r}},content:{...e.content,promptTemplates:o}}))}})}function Ixe({edit:e,view:t,prompts:n,problem:r,onChange:i}){let a=t.revision.config.descriptionPrompt,o=t.revision.content.promptTemplates.description??t.revision.config.rendered.description,s=a&&o!==void 0&&!n.some(e=>e.kind===`description`&&e.name===a)?[...n,{id:`saved-description`,kind:`description`,name:a,body:o,slots:[],updatedAt:t.revision.createdAt}]:n,c=t.outputs.some(e=>e.selected&&e.workKey===b7&&e.state===`ready`),l=e.regenerate?.includes(b7)===!0;return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(y6,{enabled:e.config.youtubeDescription===!0,prompt:e.config.descriptionPrompt??``,prompts:s,narrated:e.config.sources.audio!==`off`,problem:r,onChange:({youtubeDescription:t,descriptionPrompt:n})=>{let r=s.find(e=>e.kind===`description`&&e.name===n),a=n===(e.config.descriptionPrompt??``)?e:r===void 0?Lxe(e):O5(e,`description`,r.body),{descriptionPrompt:o,...c}=a.config;i({...a,config:{...c,youtubeDescription:t,...n===``?{}:{descriptionPrompt:n}}})}}),c&&e.config.youtubeDescription===!0?l?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The YouTube description will be written again after you save and press Remake.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>{i({...e,regenerate:(e.regenerate??[]).filter(e=>e!==b7)})},children:`Keep the current description`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:()=>{i({...e,regenerate:[...new Set([...e.regenerate??[],b7])]})},children:`Write the description again after review`}),(0,h.jsx)(U,{id:`project.edit.rewrite-description`})]}):null]})}var b7=`youtube:description`;function Lxe(e){let{description:t,...n}=e.content.promptTemplates,{description:r,...i}=e.config.rendered;return D5({config:{...e.config,rendered:i},content:{...e.content,promptTemplates:n}})}var Rxe={research:`Research source`,article:`Article source`,audio:`Audio source`,images:`Images source`,thumbnail:`Thumbnail source`,video:`Video source`,document:`Document source`},zxe={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`},Bxe=`\0kept:`;function x7({title:e,children:t,columns:n=!0}){return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:e}),(0,h.jsx)(`div`,{className:z(`grid min-w-0 gap-4`,n&&`md:grid-cols-2`),children:t})]})}function Vxe(e){let{view:t,edit:n,onChange:r,onPending:i,fields:a}=e,o=(0,m.useId)(),[s,c]=(0,m.useState)(e.focus?.section??`inputs`);(0,m.useEffect)(()=>{e.focus!==void 0&&c(e.focus.section)},[e.focus]);let[l,u]=(0,m.useState)({font:!1,content:!1,music:!1});(0,m.useEffect)(()=>{i(l.font||l.content||l.music)},[i,l]);let d=(0,m.useCallback)(e=>{u(t=>t.font===e?t:{...t,font:e})},[]),f=(0,m.useCallback)(e=>{u(t=>t.content===e?t:{...t,content:e})},[]),p=(0,m.useCallback)(e=>{u(t=>t.music===e?t:{...t,music:e})},[]),{api:g}=V(),_=I(db(g)),v=I(fb(g)),y=I(pb(g)),b=I(mb(g)),{config:x}=n,S=Exe(t,n,I(lx(g,x.channelId??`00000000-0000-4000-8000-000000000001`)).data?.cast??[]),C=S?.image.kind===`output`?t.outputs.find(e=>e.selected&&e.available&&S.image.kind===`output`&&e.output.id===S.image.outputId):void 0,w=C===void 0?void 0:j0(g,t.revision.projectId,t.revision.id,C.recordId),T=e=>a.find(t=>t.field===e||t.field===`config.${e}`||t.field===`edit.config.${e}`)?.message,E=b6({value:x.videoEdit,narrated:x.sources.audio!==`off`,imageProvider:x.images?.provider??``,problem:T,language:x.language,onChange:e=>r({...n,config:{...x,videoEdit:e}})}),D=[{id:`inputs`,label:`Inputs`},...x.sources.article===`off`?[]:[{id:`article`,label:`Article`,...n.content.articleEdited?{badge:`edited`}:{}}],{id:`providers`,label:`Providers`},{id:`prompts`,label:`Prompts`},{id:`reviews`,label:`Reviews`,...x.reviews===void 0?{}:{badge:`on`}},...x.sources.audio!==`off`||x.shorts?.enabled===!0?[{id:`shorts`,label:`Shorts`,...x.shorts?.enabled?{badge:`on`}:{}}]:[],...x.sources.article===`off`?[]:[{id:`subtitles`,label:`Subtitles`}],{id:`images`,label:`Images`,badge:String(n.content.imageOrder.length)},...x.sources.audio===`generate`?[{id:`narration`,label:`Narration`}]:[],...x.sources.article===`off`?[]:[{id:`captions`,label:`Captions`,...n.content.subtitleCues===void 0?{}:{badge:String(n.content.subtitleCues.cues.length)}}]],O=D.some(e=>e.id===s)?s:`inputs`,k=e=>z(`min-w-0 space-y-6`,O===e?void 0:`hidden`),A=e=>Number.isFinite(e)?e:``,j=x.sources.video!==`off`;return(0,h.jsxs)(`div`,{className:`grid min-w-0 gap-8 md:grid-cols-[180px_minmax(0,1fr)]`,children:[(0,h.jsx)(`nav`,{"aria-label":`Edit sections`,className:`min-w-0 md:sticky md:top-16 md:self-start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none gap-1 overflow-x-auto p-0 [scrollbar-width:none] md:flex-col`,children:D.map(e=>(0,h.jsx)(`li`,{className:`shrink-0`,children:(0,h.jsx)(Z6,{current:e.id===O,onClick:()=>c(e.id),meta:e.badge,className:`whitespace-nowrap`,children:e.label})},e.id))})}),(0,h.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[Object.entries({providers:_.error,voices:v.error,prompts:y.error,entries:b.error}).flatMap(([e,t])=>t===null?[]:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:t.message},e)]),a.length===0?null:(0,h.jsx)(`ul`,{role:`alert`,className:`m-0 space-y-1 pl-5 text-small text-danger`,children:a.map(e=>(0,h.jsx)(`li`,{children:e.message},`${e.field}-${e.message}`))}),(0,h.jsxs)(`section`,{"aria-label":`Inputs`,hidden:O!==`inputs`,className:k(`inputs`),children:[(0,h.jsxs)(x7,{title:`Project`,children:[(0,h.jsx)(LB,{label:`Project title`,error:T(`title`),className:`md:col-span-2`,children:(0,h.jsx)(zB,{value:x.title,maxLength:200,onChange:e=>r({...n,config:{...x,title:e.target.value}})})}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(z6,{value:x.format,onPick:e=>r({...n,config:{...x,format:e}})})})]}),(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Channel`,columns:!1,children:(0,h.jsx)(Txe,{edit:n,saved:t.revision.config,problem:T,onChange:r})}),(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Stages`,children:[KS.filter(e=>x.sources.article!==`off`||e!==`research`&&e!==`audio`&&e!==`document`).map(e=>(0,h.jsx)(LB,{label:Rxe[e],tip:zxe[e],error:T(`sources.${e}`),children:(0,h.jsx)(VB,{value:YS(x.sources,e),onChange:i=>{let a=ON(e).find(e=>e.value===i.target.value);if(a===void 0)return;let o=rbe(n,e,a.value);r(e===`article`&&a.value===`provide`&&!n.content.articleEdited?{...o,content:{...o.content,articleMarkdown:t.articleMarkdown??n.content.articleMarkdown}}:o)},children:ON(e).filter(t=>e!==`thumbnail`||t.value!==`prompt_by_llm`||x.sources.article!==`off`).map(t=>(0,h.jsx)(`option`,{value:t.value,disabled:e===`video`&&t.value===`generate`&&x.sources.images===`off`,children:t.label},t.value))})},e)),x.sources.images===`off`?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:`Images are Off. Video is also Off in these changes.`}):null,(0,h.jsx)(LB,{label:`Document theme`,id:`${o}-document-theme`,tip:`play.document-theme`,children:(0,h.jsx)(V3,{id:`${o}-document-theme`,disabled:YS(x.sources,`document`)===`off`,value:x.document,onChange:e=>{r({...n,config:{...x,document:e}})}})})]}),(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Timing`,children:[(0,h.jsx)(LB,{label:`Silence gap (seconds)`,tip:`play.silence-gap`,error:T(`silenceGapSeconds`),children:(0,h.jsx)(zB,{type:`number`,min:0,max:30,step:.1,value:A(x.silenceGapSeconds),onChange:e=>r({...n,config:{...x,silenceGapSeconds:Number(e.target.value)}})})}),x.sources.audio===`off`?null:(0,h.jsx)(LB,{label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,error:T(`edgeSilenceSeconds`),children:(0,h.jsx)(zB,{type:`number`,min:0,max:30,step:.5,value:A(x.edgeSilenceSeconds),onChange:e=>r({...n,config:{...x,edgeSilenceSeconds:Number(e.target.value)}})})}),j?(0,h.jsx)(LB,{label:`Seconds per image`,tip:`play.image-seconds`,error:T(`imageSeconds`),children:(0,h.jsx)(zB,{type:`number`,min:1,max:600,step:1,value:A(x.imageSeconds),onChange:e=>r({...n,config:{...x,imageSeconds:Number(e.target.value)}})})}):null,j?(0,h.jsx)(LB,{label:`Zoom (%)`,tip:`play.zoom`,error:T(`zoomPercent`),children:(0,h.jsx)(zB,{type:`number`,min:0,max:50,step:.5,value:A(x.zoomPercent),onChange:e=>r({...n,config:{...x,zoomPercent:Number(e.target.value)}})})}):null,j?(0,h.jsx)(LB,{label:`Motion`,tip:`play.motion`,children:(0,h.jsx)(VB,{value:x.motionStyle,onChange:e=>r({...n,config:{...x,motionStyle:e.target.value}}),children:XS.map(e=>(0,h.jsx)(`option`,{value:e,children:HA[e]},e))})}):null]}),j?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Cuts and look`,columns:!1,children:[E.cuts,E.look,x.sources.audio===`generate`&&x.audio?.describeFigures===!0?(0,h.jsx)(u6,{tip:`project.edit.show-figures`,value:x.showFigures,onChange:e=>{let{showFigures:t,...i}=x;r({...n,config:e?{...i,showFigures:!0}:i})}}):null]}),x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Ambient sound`,columns:!1,children:(0,h.jsx)(sxe,{edit:n,problem:T,onChange:r})})]})]}):null,x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsxs)(x7,{title:`Pauses and volume`,columns:!1,children:[(0,h.jsx)(lxe,{edit:n,problem:T,onChange:r}),(0,h.jsx)(cxe,{edit:n,problem:T,onChange:r})]})]}),(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Intro and outro`,children:[`intro`,`outro`].map(e=>{let i=x[e]?.name,a=t.revision.content.promptTemplates[e],o=b.data?.entries.find(t=>t.category===e&&t.name===i),s=i!==void 0&&o!==void 0&&typeof a==`string`&&t.revision.config[e]?.name===i&&a!==o.body,c=n.content.promptTemplates[e],l=`${Bxe}${i??``}`,u=i===void 0?``:s&&c!==o?.body?l:i;return(0,h.jsx)(LB,{label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,children:(0,h.jsxs)(VB,{value:u,onChange:i=>{if(i.target.value===l&&typeof a==`string`){r(D5({...n,config:{...x,[e]:t.revision.config[e]},content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:a}}}));return}let o=b.data?.entries.find(t=>t.category===e&&t.name===i.target.value),s={...x};o===void 0?delete s[e]:s[e]={name:o.name,mode:o.mode},r(D5({...n,config:s,content:o===void 0?n.content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:o.body}}}))},children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),i!==void 0&&!b.data?.entries.some(t=>t.category===e&&t.name===i)?(0,h.jsxs)(`option`,{value:i,children:[i,` (saved entry)`]}):null,s?(0,h.jsxs)(`option`,{value:l,children:[i,` · this project's version`]}):null,b.data?.entries.filter(t=>t.category===e).map(e=>(0,h.jsx)(`option`,{value:e.name,children:s&&e.name===i?`${e.name} · Library version (newer)`:e.name},e.id))]})},e)})}),x.sources.research===`provide`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)($K,{}),(0,h.jsx)(x7,{title:`Research`,columns:!1,children:(0,h.jsx)(LB,{label:`Research notes`,tip:`play.provided.research`,error:T(`provided.research`),children:(0,h.jsx)(BB,{rows:6,value:x.provided.research??``,onChange:e=>r({...n,config:{...x,provided:{...x.provided,research:e.target.value}}})})})})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Article`,hidden:O!==`article`,className:k(`article`),children:[(0,h.jsx)(LB,{label:`Article text`,tip:`project.edit.article-text`,error:T(`content.articleMarkdown`)??T(`provided.article`),help:n.content.articleEdited?`Your edited article is kept when other settings change. Regenerating it replaces it after the rebuild review.`:void 0,children:(0,h.jsx)(BB,{rows:12,maxLength:5e5,value:(n.content.articleEdited?n.content.articleMarkdown:t.articleMarkdown)??n.content.articleMarkdown??x.provided.article??``,onChange:e=>r({...n,content:{...n.content,articleMarkdown:e.target.value,articleEdited:!0}})})}),x.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{onClick:()=>r({...n,regenerate:[...new Set([...n.regenerate??[],`article:body`])]}),children:`Regenerate article after review`}),(0,h.jsx)(U,{id:`project.edit.regenerate-article`})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Providers`,hidden:O!==`providers`,className:k(`providers`),children:[(0,h.jsx)(wxe,{edit:n,error:T(`language`),onChange:r}),(0,h.jsx)(Pxe,{projectId:t.revision.projectId,edit:n,providers:_.data?.providers??[],voices:v.data?.voices??[],onChange:r}),(0,h.jsx)(Dxe,{edit:n,view:t,prompts:y.data?.prompts??[],error:T(`narrationPrompt`),onChange:r})]}),(0,h.jsxs)(`section`,{"aria-label":`Prompts`,hidden:O!==`prompts`,className:k(`prompts`),children:[(0,h.jsx)(Ixe,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r}),(0,h.jsx)(Oxe,{edit:n,saved:t.revision.config.imagePrompts,prompts:y.data?.prompts??[],entries:b.data?.entries??[],onChange:r})]}),(0,h.jsx)(`section`,{"aria-label":`Reviews`,hidden:O!==`reviews`,className:k(`reviews`),children:(0,h.jsx)(Fxe,{edit:n,providers:_.data?.providers??[],prompts:y.data?.prompts??[],problem:T,onChange:r})}),(0,h.jsx)(`section`,{"aria-label":`Shorts`,hidden:O!==`shorts`,className:k(`shorts`),children:(0,h.jsx)(obe,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r,onPending:p})}),(0,h.jsxs)(`section`,{"aria-label":`Subtitles`,hidden:O!==`subtitles`,className:k(`subtitles`),children:[(0,h.jsx)(`div`,{"data-tour":`project-subtitles`,children:(0,h.jsx)(R6,{value:x.subtitles??cM,format:x.format,audioEnabled:x.sources.audio!==`off`,videoEnabled:j,onChange:e=>r({...n,config:{...x,subtitles:xN(e,x.sources)}}),onUploading:d,problem:T})}),O!==`subtitles`||!j?null:(0,h.jsx)(w6,{drawnOn:S?.drawnOn,poster:w,settings:{format:x.format,subtitles:{mode:(x.subtitles??cM).mode,fontId:(x.subtitles??cM).fontId,fontSize:(x.subtitles??cM).fontSize,position:(x.subtitles??cM).position??`bottom`},videoEdit:x.videoEdit,image:S?.image}})]}),e.renderContent?.({view:t,edit:n,fields:a,onChange:r,onPending:f,section:O})]})]})}var S7={notes:`Research notes`,article_md:`Article (Markdown)`,article_txt:`Article text`,narration_txt:`Clean Narration`,tts_script:`TTS Script`,sources:`Research sources`,glossary:`Glossary`,audio_body:`Narration`,audio_intro:`Intro narration`,audio_outro:`Outro narration`,audio_export:`Audio export`,image:`Image`,thumbnail:`Thumbnail`,video:`Video`,render_params:`Export settings`,subtitles_srt:`Subtitles (SRT)`,subtitles_vtt:`Subtitles (VTT)`,subtitle_words:`Subtitle timing`,subtitle_ass:`Styled subtitles`,subtitle_font:`Subtitle font`,instructions:`Generation instructions`,document_pdf:`Document (PDF)`,youtube_description:`YouTube description`,youtube_tags:`YouTube tags`,youtube_pinned_comment:`Pinned comment`,youtube_titles:`Other titles`,shorts:`Shorts list`,short_image:`Short image`,short_video:`Short`,animated_image:`Animated image`,figure_card:`On-screen card`,reference:`Establishing image (reference)`,script_md:`Script (speaker split)`,audio_mp3:`Audio (MP3 with chapters)`,audio_m4b:`Audiobook (M4B with chapters)`,audio_levelled:`Levelled narration`};function C7(e){return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment?`${e.meta.segment===`body`?`Body`:e.meta.segment===`intro`?`Intro`:`Outro`} ${S7[e.role]}`:e.role===`short_video`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)}`:e.role===`short_image`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)} image ${String(e.meta.index??1)}`:e.role===`figure_card`&&typeof e.meta.index==`number`?`On-screen card ${String(e.meta.index)}`:e.role===`animated_image`&&typeof e.meta.index==`number`?`Animated image ${String(e.meta.index)}`:e.role===`image`&&typeof e.meta.index==`number`?`Image ${e.meta.index}`:S7[e.role]}function Hxe(e){if(e.startsWith(`image:`))return`Image`;if(e.startsWith(`animate:`))return S7.animated_image;if(/^shorts:\d+:render$/.test(e))return S7.short_video;if(/^shorts:\d+:image:\d+$/.test(e))return S7.short_image;if(e===`document:pdf`)return S7.document_pdf;let t=e.split(`:`).at(-1);return Object.entries(S7).find(([e])=>e===t)?.[1]??`Saved output`}function w7({preview:e,pending:t,feedback:n,onStart:r,onCancel:i}){let a=Jxe(e),[o,s]=(0,m.useState)([]),[c,l]=(0,m.useState)(!1),u=(0,m.useId)(),d=e.work.filter(e=>e.disposition===`blocked`),f=e.providedReuseRequired.filter(e=>!o.includes(e)),p=e.work.filter(e=>e.disposition===`generate`||e.disposition===`local`||e.disposition===`review`).length,g=p===1?`Remake 1 output`:`Remake ${String(p)} outputs`,_=[...d.length===0?[]:[`${d.length===1?`1 item is`:`${d.length} items are`} unavailable (reasons above)`],...f.map(e=>`tick “Keep the provided content for ${a(e)}”`),...e.costs.unknown===0||c?[]:[`tick “I understand that ${e.costs.unknown} cost estimates are unknown”`]],v=_.length===0,y=Wxe.map(t=>({disposition:t,count:e.work.filter(e=>e.disposition===t).length})).filter(e=>e.count>0),b=e.costs.rows.some(e=>e.onPlan===!0),x=e.costs.apiLow,S=e.costs.apiHigh;return(0,h.jsxs)(`section`,{"aria-label":`Review affected rebuild`,className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-6 gap-y-3 sm:grid-cols-3`,children:[y.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:k7[e.disposition]}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:e.count})]},e.disposition)),(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:e.costs.unknown>0?`known cost`:`cost`}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:O7(e.costs.low,e.costs.high)})]})]}),b?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`CLI work: $0 on your plan${x===void 0||S===void 0?``:` · ~${O7(x,S)} via API`}.`}):null,d.length===0?null:(0,h.jsx)(aI,{tone:`danger`,title:`${d.length===1?`1 item can’t`:`${d.length} items can’t`} run, so this rebuild can’t start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:Gxe(d,a).map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.what,`:`]}),` `,e.reason]},e.reason))})}),e.wholeRequestNotice===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.wholeRequestNotice}),e.warnings.map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e},e)),(0,h.jsxs)(`div`,{className:`flex flex-col divide-y divide-line border-y border-line`,children:[e.review?.inputChanges.length?(0,h.jsx)(T7,{summary:`Changed inputs (${String(e.review.inputChanges.length)})`,children:(0,h.jsx)(`dl`,{className:`m-0 flex flex-col gap-3`,children:e.review.inputChanges.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`dt`,{className:`font-semibold`,children:e.label}),(0,h.jsxs)(`dd`,{className:`m-0 grid gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(E7,{label:`Before`,text:e.before}),(0,h.jsx)(E7,{label:`After`,text:e.after})]})]},e.label))})}):null,(0,h.jsxs)(T7,{summary:`Work items (${e.work.length}): ${y.map(e=>`${e.count} ${k7[e.disposition]}`).join(`, `)||`none`}`,children:[e.changedInputs.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 mb-3 flex flex-col gap-1 pl-5`,children:e.changedInputs.map(e=>(0,h.jsxs)(`li`,{children:[a(e.path),`:`,` `,e.after===null?`Removed`:e.before===null?`New output`:`Inputs changed`]},e.path))}),(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-2 pl-5`,children:e.work.map(t=>(0,h.jsxs)(`li`,{children:[a(t.key),`: `,k7[t.disposition],`. `,t.reason,t.inflight?` An already submitted request may still be billed.`:``,e.review?.requests.filter(e=>e.key===t.key).map(e=>(0,h.jsxs)(`div`,{children:[e.settings===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.settings}),e.text===null?null:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:`View request text`}),(0,h.jsx)(`pre`,{className:`m-0 max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.text})]})]},e.key))]},t.key))}),(0,h.jsxs)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:[`Retained outputs:`,` `,e.retained.map(e=>Hxe(e.slot)).join(`, `)||`None`]})]}),e.costs.rows.length===0?null:(0,h.jsx)(T7,{summary:`Cost by step`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:e.costs.rows.map(e=>(0,h.jsxs)(`li`,{children:[a(e.stage),`: `,Uxe(e),`. `,e.detail]},`${e.stage}-${e.detail}`))})})]}),n,(0,h.jsxs)(`div`,{className:`sticky bottom-[-16px] -mx-4 flex flex-col gap-3 border-t border-line bg-raised px-4 py-3`,children:[e.providedReuseRequired.length===0&&e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small`,children:[e.providedReuseRequired.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...zb,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:o.includes(e),onChange:t=>s(t.target.checked?[...o,e]:o.filter(t=>t!==e))}),(0,h.jsxs)(`span`,{children:[`Keep the provided content for `,a(e)]})]}),(0,h.jsx)(U,{id:`project.rebuild.keep-provided`,className:`-my-1`})]},e)),e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...zb,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:c,onChange:e=>l(e.target.checked)}),(0,h.jsxs)(`span`,{children:[`I understand that `,e.costs.unknown,` cost estimates are unknown.`]})]}),(0,h.jsx)(U,{id:`project.rebuild.unknown-costs`,className:`-my-1`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(B,{variant:`primary`,disabled:t||!v,"aria-describedby":v?void 0:u,onClick:()=>r({acknowledgeUnknownCosts:c,confirmedProvidedWorkKeys:o}),children:t?`Starting the remake…`:g}),(0,h.jsx)(B,{disabled:t,onClick:i,children:`Keep things as they are`}),v||t?null:(0,h.jsx)(`p`,{id:u,className:`m-0 min-w-0 text-small text-ink-2`,children:`${g} is off until: ${_.join(`; `)}.`})]})]})]})}function T7({summary:e,children:t}){return(0,h.jsxs)(`details`,{className:`py-3 text-small`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold text-ink`,children:e}),(0,h.jsx)(`div`,{className:`mt-3`,children:t})]})}function E7({label:e,text:t}){return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`pre`,{className:`m-0 max-h-40 overflow-auto whitespace-pre-wrap break-words text-small`,children:t??`Not set`})]})}var D7=e=>e===null?`Unknown`:e===0?`$0`:new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:e>0&&e<.01?4:2}).format(e);function O7(e,t){return e===t?D7(e):`${D7(e)}–${D7(t)}`}function Uxe(e){return e.onPlan===!0?`$0 on plan${e.apiLow===void 0||e.apiLow===null||e.apiHigh===void 0?``:` · ~${O7(e.apiLow,e.apiHigh??null)} via API`}`:O7(e.low,e.high)}var Wxe=[`generate`,`local`,`review`,`reuse`,`blocked`];function Gxe(e,t){let n=new Map;for(let t of e){let e=t.reason.trim()||`No reason was given.`;n.set(e,[...n.get(e)??[],t.key])}return[...n].map(([e,n])=>({reason:e,what:n.length===1?t(n[0]??``):`${n.length} ${new Set(n.map(A7)).size===1?Kxe(A7(n[0]??``)):`items`}`}))}function Kxe(e){return/s$/u.test(e)?e:`${e.charAt(0).toLowerCase()}${e.slice(1)}s`}var k7={reuse:`kept as they are`,generate:`to make`,local:`built on this computer`,review:`to confirm`,blocked:`can't run`},qxe={"export:wav":`Audio export (WAV)`,"export:video":`Video export`,"subtitles:timing":`Subtitle timing`,"subtitles:cues":`Caption text and timing`,"subtitles:files":`Subtitle files`,"article:body":`Article`,"audio:provided":`Provided narration`,"audio:body:concat":`Combined narration`,"audio:intro":`Combined intro narration`,"audio:outro":`Combined outro narration`,"research:planner":`Research plan`,"research:notes":`Research notes`,"entry:intro:text":`Intro text`,"entry:outro:text":`Outro text`};function A7(e){let t=qxe[e];return t===void 0?{image:`Image request`,images:`Images`,audio:`Narration request`,article:`Article`,research:`Research`,thumbnail:`Thumbnail`,subtitles:`Subtitles`,video:`Video export`,export:`Export`,entry:`Intro or outro`}[e.split(`:`)[0]??``]??`Output`:t}function Jxe(e){let t=new Map,n=new Map;for(let t of e.work){let e=A7(t.key);n.set(e,(n.get(e)??0)+1)}let r=new Map;for(let i of e.work){let e=A7(i.key),a=(r.get(e)??0)+1;r.set(e,a),t.set(i.key,(n.get(e)??0)>1?`${e} ${a}`:e)}for(let n of e.review?.requests??[])t.set(n.key,n.label);return e=>t.get(e)??A7(e)}var Yxe={llm:`Text generation`,image:`Images`,images:`Images`,tts:`Audio`,audio:`Audio`};function j7({error:e,refusal:t}){let n=(0,m.useRef)(null);return(0,m.useEffect)(()=>{(e!==void 0||t!==void 0)&&n.current?.focus()},[e,t]),e===void 0&&t===void 0?null:(0,h.jsxs)(`div`,{ref:n,role:`alert`,tabIndex:-1,"data-tone":`danger`,className:`sl-callout sl-callout--danger outline-none`,children:[(0,h.jsx)(el,{"aria-hidden":`true`,strokeWidth:1.75}),(0,h.jsx)(`p`,{className:`sl-callout__title m-0`,children:e??(t?.reason===`readiness`?t.fields.length>0?`This can't start yet. Fix the items below, then try again.`:`Slopify couldn't check your providers. Open Settings → Providers, make sure each one you use is set up, then try again.`:t?.message)}),t?.fields.length?(0,h.jsx)(`ul`,{className:`sl-callout__body m-0 list-disc pl-5`,children:t.fields.map(({field:e,message:t})=>(0,h.jsxs)(`li`,{children:[Yxe[e.split(`.`)[0]??``]??`Project`,`: `,t]},`${e}:${t}`))}):null]})}var Xxe=Y({text:K().optional(),logicalText:K().optional(),title:K().optional(),notes:K().optional(),outline:J(K()).optional(),prompt:K().optional()});function Zxe(e){if(e===null)return`No text was recorded for this part.`;try{let t=Xxe.safeParse(JSON.parse(e));if(!t.success)return`Recorded text cannot be decoded.`;let{logicalText:n,text:r,title:i,notes:a,outline:o,prompt:s}=t.data;return[n,r,a?.trim()?[i,a].filter(e=>e?.trim()).join(`
306
306
 
307
307
  `):void 0,o?.filter(e=>e.trim()).map((e,t)=>`${t+1}. ${e}`).join(`
308
- `),s].find(e=>e?.trim())??`No text was recorded for this part.`}catch{return`Recorded text cannot be decoded.`}}function Zxe({projectId:e,pending:t,onRestore:n}){let{api:r}=V(),[i,a]=(0,m.useState)(),o=I({queryKey:H.revisions(e),queryFn:async()=>{let t=await kpe(r,e);if(!t.ok)throw Error(t.message);return t.value.revisions}}),s=I({queryKey:H.revision(e,i??``),enabled:i!==void 0,queryFn:async()=>{if(i===void 0)throw Error(`Choose a version from History first.`);let t=await k0(r,e,i);if(!t.ok)throw Error(t.message);return t.value.view}}),c=s.data,l=c?.outputs.find(e=>e.selected&&e.available&&(e.output.role===`image`||e.output.role===`thumbnail`)),u=l??c?.outputs.find(e=>e.available);return(0,h.jsxs)(`section`,{"aria-label":`Project history`,className:`space-y-3`,children:[(0,h.jsx)(W,{title:`Project history`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:o.error.message}),(0,h.jsx)(`ol`,{className:`space-y-2`,children:o.data?.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(B,{type:`button`,onClick:()=>a(e.id),children:[e.title,` · `,e.createdAt,e.current?` · Current`:``]})},e.id))}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:s.error.message}),c===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:c.revision.config.title}),(0,h.jsxs)(Iy,{children:[(0,h.jsx)(B,{variant:`primary`,disabled:t,onClick:()=>n(c.revision.id),children:`Restore this revision`}),l===void 0?null:(0,h.jsxs)(TS,{href:Ppe(r,e,c.revision.id),download:!0,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download all images`]}),u===void 0?null:(0,h.jsx)(P0,{projectId:e,asset:``,folder:{revisionId:c.revision.id,recordId:u.recordId}})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-3 p-0`,children:c.outputs.map(t=>(0,h.jsxs)(`li`,{className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:C7(t.output)}),(0,h.jsxs)(`span`,{className:`text-small text-ink-2`,children:[` · ${t.state}${t.selected?``:` · Earlier result`}`,t.available?``:` · File missing`]})]}),t.available?(0,h.jsxs)(TS,{href:j0(r,e,c.revision.id,t.recordId),download:!0,size:`small`,"aria-label":`Download ${C7(t.output)}`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download`]}):null]}),t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained output`}),t.output.role===`video`?(0,h.jsx)(c0,{className:`max-w-[640px]`,label:C7(t.output),src:j0(r,e,c.revision.id,t.recordId)}):[`audio_export`,`audio_body`,`audio_intro`,`audio_outro`].includes(t.output.role)?(0,h.jsx)(Y8,{label:C7(t.output),src:j0(r,e,c.revision.id,t.recordId)}):t.output.role===`image`||t.output.role===`thumbnail`?(0,h.jsx)(l0,{className:`max-w-[480px]`,alt:C7(t.output),title:C7(t.output),meta:t.selected?`Current`:`Earlier result`,src:j0(r,e,c.revision.id,t.recordId)}):(0,h.jsx)(`p`,{children:`Use Download to inspect this retained file.`})]}):null]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained narration parts`,children:c.pieces.filter(e=>e.stageKind===`audio`&&e.assetId!==null).map(t=>(0,h.jsxs)(`li`,{children:[`Narration part `,t.piece.idx,t.selected?``:` · Earlier result`,t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained audio part`}),(0,h.jsx)(Y8,{label:`Narration part ${String(t.piece.idx)}`,src:j0(r,e,c.revision.id,t.recordId)}),(0,h.jsxs)(TS,{href:j0(r,e,c.revision.id,t.recordId),download:!0,size:`small`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download narration part`]})]}):(0,h.jsx)(`span`,{children:` · File missing`})]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained text parts`,children:c.pieces.filter(e=>e.assetId===null).map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(`details`,{children:[(0,h.jsxs)(`summary`,{children:[e.stageKind,` part `,e.piece.idx]}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words`,children:Xxe(e.piece.payload)})]})},e.recordId))})]})]})}function j7(e,t,n){let r=JSON.stringify(t);return e?.payload===r?e:{payload:r,idempotencyKey:n()}}function Qxe(e,t,n={}){let{api:r}=V(),i=_(),a=I({queryKey:H.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved settings to show yet. Reload the page and try again.`);let n=await k0(r,e,t);if(!n.ok)throw Error(n.message);return n.value.view}}),[o,s]=(0,m.useState)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(),[f,p]=(0,m.useState)(),[h,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(),w=(0,m.useRef)(void 0),T=(0,m.useRef)(void 0),E=(0,m.useRef)(void 0),D=(0,m.useRef)(n.onOpenEdit);D.current=n.onOpenEdit;let O=(0,m.useMemo)(()=>c!==void 0&&(o===void 0||(c.regenerate?.length??0)>0||(c.uploads?.length??0)>0||JSON.stringify(c.config)!==JSON.stringify(o.revision.config)||JSON.stringify(c.content)!==JSON.stringify(o.revision.content)),[c,o]),k=c!==void 0&&o!==void 0&&t!==null&&t!==o.revision.id,A=(0,m.useRef)(!1);async function j(e){if(!A.current){A.current=!0,g(!0),x(void 0),C(void 0);try{await e()}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1,g(!1)}}}async function M(t){let n=await D0(r,e);if(!n.ok){C(n);return}return C(void 0),s(n.value.view),t&&l({config:structuredClone(n.value.view.revision.config),content:structuredClone(n.value.view.revision.content)}),n.value.view}async function ee(t){let n=await Oo(r,e);return i.setQueryData(H.project(e),n),await i.invalidateQueries({queryKey:H.revisions(e)}),!t.current||n.revisionId!==t.revision.id?(C({ok:!1,reason:`conflict`,message:`The project changed again. Your draft is preserved.`,currentRevisionId:n.revisionId,fields:[]}),!1):(s(t),l(void 0),C(void 0),d(void 0),!0)}async function N(){if(v||o===void 0||c===void 0)return;let t={baseRevisionId:o.revision.id,edit:c},n=j7(w.current,t,()=>crypto.randomUUID());w.current=n;let i=await O0(r,e,{...t,idempotencyKey:n.idempotencyKey});if(!i.ok){C(i);return}await ee(i.value.view),w.current=void 0}async function P(t,n=u){if(n===void 0)return;let a={baseRevisionId:n.baseRevisionId,previewId:n.id,...t},o=j7(E.current,a,()=>crypto.randomUUID());E.current=o;let s=await Mpe(r,e,{...a,idempotencyKey:o.idempotencyKey});if(!s.ok){C(s),(s.reason===`stale-preview`||s.reason===`conflict`)&&d(void 0);return}E.current=void 0,d(void 0),await i.invalidateQueries({queryKey:H.project(e)})}async function F(t,n){let i=await M(!1);if(i===void 0)return;let a=await jpe(r,e,{baseRevisionId:i.revision.id,request:t});if(!a.ok){C(a);return}let o=a.value.value;if(E.current=void 0,n&&$xe(o)){await P({acknowledgeUnknownCosts:!1,confirmedProvidedWorkKeys:[]},o);return}d(o)}async function te(t){let n=o??a.data??await M(!1);if(n===void 0)return;let i={baseRevisionId:n.revision.id,targetRevisionId:t},s=j7(T.current,i,()=>crypto.randomUUID());T.current=s;let c=await Ope(r,e,{...i,idempotencyKey:s.idempotencyKey});if(!c.ok){C(c);return}await ee(c.value.view),T.current=void 0}return{saved:a,view:o,edit:c,preview:u,focus:f,pending:h,uploading:v,error:b,refusal:S,unsaved:O,remoteChanged:k,busy:h||v||c!==void 0||u!==void 0,setEdit:l,setUploading:y,openEditor:()=>void j(async()=>{await M(!0)}),discard:()=>{l(void 0),C(void 0),y(!1),w.current=void 0},save:()=>void j(N),reloadDraft:()=>void j(async()=>{w.current=void 0,y(!1),await M(!0),C(void 0)}),reloadCurrent:()=>void j(async()=>{T.current=void 0,E.current=void 0,d(void 0),await M(!1),await i.invalidateQueries({queryKey:H.project(e)})}),requestEdit:e=>void j(async()=>{let t=o,n=c;if(t===void 0||n===void 0){if(t=await M(!1),t===void 0)return;n={config:structuredClone(t.revision.config),content:structuredClone(t.revision.content)}}l(e.change(n,t)),p({section:e.section}),D.current?.()}),regenerateNow:t=>void j(async()=>{let n=e=>({...e,regenerate:[...new Set([...e.regenerate??[],...t])]});if(c!==void 0&&O){l(n(c)),p({section:`images`}),D.current?.();return}let i=await M(!1);if(i===void 0)return;let a=await O0(r,e,{baseRevisionId:i.revision.id,edit:n({config:structuredClone(i.revision.config),content:structuredClone(i.revision.content)}),idempotencyKey:crypto.randomUUID()});if(!a.ok){C(a);return}await ee(a.value.view)&&await F({kind:`selected`,workKeys:t},!0)}),review:(e,t)=>void j(()=>F(e,t?.autoStart===!0)),start:e=>void j(()=>P(e)),closePreview:()=>{h||(d(void 0),E.current=void 0)},restore:e=>void j(()=>te(e))}}function $xe(e){return!e.work.some(e=>e.disposition===`blocked`)&&e.providedReuseRequired.length===0&&e.costs.unknown===0}function eSe({controller:e,renderEditor:t,active:n=!0,intro:r}){let i=e;return i.view===void 0||i.edit===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r??(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Saved revision`,info:`project.saved-revision`}),i.saved.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.saved.error.message}),i.saved.data===void 0?null:(0,h.jsx)(`ul`,{"aria-label":`Saved output status`,className:`sl-list m-0 list-none p-0`,children:i.saved.data.outputs.filter(e=>e.selected).map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:C7(e.output)}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.available?e.state===`ready`?`Ready`:e.state===`outdated`?`Outdated; the retained version stays until it is remade`:`Provided content needs review`:`Retained file missing`})]},e.recordId))})]}),i.preview===void 0&&n?(0,h.jsx)(A7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)(y1,{children:[i.refusal?.reason===`conflict`&&n?(0,h.jsx)(B,{disabled:i.pending,onClick:i.reloadCurrent,children:`Reload current revision`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{disabled:i.busy,onClick:()=>i.review({kind:`allAffected`}),variant:`secondary`,children:`Choose what to remake`}),(0,h.jsx)(U,{id:`project.choose-remake`})]}),(0,h.jsx)(B,{variant:`primary`,disabled:i.busy,onClick:i.openEditor,children:`Edit project`})]})]}):(0,h.jsxs)(`form`,{"aria-label":`Edit project`,onSubmit:e=>{e.preventDefault(),i.save()},children:[(0,h.jsx)(`fieldset`,{disabled:i.pending,className:`m-0 min-w-0 border-0 p-0`,children:t({view:i.view,edit:i.edit,fields:i.refusal?.fields??[],onChange:i.setEdit,onPending:i.setUploading,...i.focus===void 0?{}:{focus:i.focus}})}),i.preview===void 0?(0,h.jsx)(A7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)(y1,{status:(0,h.jsx)(v1,{tone:i.remoteChanged?`warning`:`info`,children:i.remoteChanged?`A newer revision is available. Your unsaved changes are kept below.`:i.uploading?`Waiting for uploads to finish…`:void 0}),children:[i.remoteChanged||i.refusal?.reason===`conflict`?(0,h.jsx)(B,{disabled:i.pending||i.uploading,onClick:i.reloadDraft,children:`Reload current revision and discard my draft`}):null,(0,h.jsx)(B,{variant:`quiet`,disabled:i.pending||i.uploading,onClick:i.discard,children:`Discard changes`}),(0,h.jsx)(B,{variant:`primary`,type:`submit`,disabled:i.pending||i.uploading,children:`Save changes`})]})]})}function tSe({controller:e,projectId:t,active:n}){let r=e;return n?(0,h.jsxs)(h.Fragment,{children:[r.preview===void 0&&(r.error||r.refusal)?(0,h.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3`,children:[(0,h.jsx)(A7,{error:r.error,refusal:r.refusal}),r.edit===void 0&&r.refusal?.reason===`conflict`?(0,h.jsx)(B,{disabled:r.pending,onClick:r.reloadCurrent,className:`self-start`,children:`Reload current revision`}):null]}):null,(0,h.jsx)(Zxe,{projectId:t,pending:r.busy,onRestore:r.restore})]}):null}function nSe({controller:e}){let t=e;return(0,h.jsx)(HP,{open:t.preview!==void 0,title:`Choose what to remake`,onClose:t.closePreview,children:t.preview===void 0?null:(0,h.jsx)(Vxe,{preview:t.preview,feedback:(0,h.jsx)(A7,{error:t.error,refusal:t.refusal}),pending:t.pending,onStart:t.start,onCancel:t.closePreview},t.preview.id)})}var rSe=(e,t)=>{if(t)return`waiting`;switch(e.state){case`running`:return`running`;case`done`:case`provided`:return`done`;case`failed`:return e.retryAt===void 0?`failed`:`waiting`;default:return`off`}},iSe=(e,t)=>{if(t)return`Held for you`;switch(e.state){case`running`:return`Running`;case`done`:return`Done`;case`provided`:return`Provided`;case`failed`:return e.retryAt===void 0?`Failed`:`Waiting to try again`;case`canceled`:return`Canceled`;case`skipped`:return`Off`;case`pending`:return`Not started`}};function aSe(e,t){if(e.startedAt===null)return;let n=Date.parse(e.startedAt),r=e.finishedAt===null?t:Date.parse(e.finishedAt);if(!Number.isFinite(n)||!Number.isFinite(r)||r<n)return;let i=Math.round((r-n)/1e3);if(i<1)return;if(i<60)return`${String(i)} s`;let a=Math.round(i/60);return a<60?`${String(a)} min`:`${String(Math.floor(a/60))} h ${String(a%60)} min`}function oSe(e,t,n){let r=x3(t,n);return r===void 0?e:e===void 0||e===``?S3(r):`${e} · ${S3(r)}`}function sSe({stages:e,outputs:t,project:n,resumable:r,held:i,now:a}){return e.filter(e=>e.state!==`skipped`).map(e=>{let o=i.some(t=>t.stage===e.kind),s=aSe(e,a);return{id:e.id,name:e.kind===`video`&&XP(n.config)===`audio`?`Audio export`:$8[e.kind],tone:rSe(e,o),state:iSe(e,o),...s===void 0?{}:{time:s},detail:o?`Held for your review`:oSe(tF(e,t,n,r),e,a)}})}function M7({stages:e}){return(0,h.jsx)(`div`,{className:`sr-only`,children:e.filter(e=>e.state!==`skipped`).map(e=>(0,h.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:`${$8[e.kind]}: ${e.state}`},e.id))})}function cSe({steps:e}){return(0,h.jsxs)(`section`,{"aria-labelledby":`run-steps-title`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{id:`run-steps-title`,title:`Run`,size:`small`,className:`pb-0`}),(0,h.jsx)(w3,{steps:e,label:`Run steps`,dense:!0})]})}var N7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});function lSe({cost:e,onOpen:t}){if(e===void 0||e.calls===0&&e.byStage.length===0)return null;let n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({key:`${e.account}/${t.kind}`,name:e.name,window:t.kind===`five_hour`?`5-hour`:t.kind===`weekly`?`weekly`:`current`,used:t.usedPercent,now:t.nowPercent})):[]);return(0,h.jsxs)(`section`,{"aria-labelledby":`cost-so-far-title`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{id:`cost-so-far-title`,title:`Cost so far`,size:`small`,className:`pb-0`,children:t===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:t,children:`By stage`})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[(0,h.jsx)(`strong`,{className:`text-ink`,children:a7(e.cost)}),e.unpriced>0?` known, spent`:` spent`,e.apiEquivalent===null?null:` · ~${a7(e.apiEquivalent)} via API`,e.run===null||e.run.running?null:` · ${o7(e.run.workingMs)} of work`]}),n.map(e=>{let t=e.used<1?`under 1%`:`${N7.format(e.used)}%`,n=`${e.window} ${e.name} limit`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`${e.name}: ${t} of your ${e.window} limit`}),(0,h.jsx)(C2,{value:e.used/100,label:`Share of the ${n} this run used`,valueText:`${t} of your ${n}; now at ${N7.format(e.now)}%`,tone:e.now>=80?`waiting`:`accent`})]},e.key)})]})}function uSe({projectId:e,revisionId:t,title:n,open:r,onClose:i}){let{api:a}=V(),o=_(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=Ry(),g=(0,m.useRef)(!1),v=(0,m.useRef)(null);(0,m.useEffect)(()=>{r&&t!==null&&(c({revisionId:t,name:n}),f(null)),r||c(null)},[r,t,n]);async function y(){if(!s||g.current||!s.name.trim())return;g.current=!0,u(!0),f(null);let t=JSON.stringify([e,s.revisionId,s.name.trim()]);v.current?.key!==t&&(v.current={key:t,id:crypto.randomUUID()});try{let t=await mq(a,e,{id:v.current.id,name:s.name.trim(),revisionId:s.revisionId});if(!t.ok){v.current=null,f(t.message);return}v.current=null,i(),p(`Template saved.`,`success`),await o.invalidateQueries({queryKey:iq})}catch(e){f(e instanceof Error?e.message:`The template wasn't saved. Press Save template to try again.`)}finally{g.current=!1,u(!1)}}return(0,h.jsx)(Vy,{open:r&&s!==null,onOpenChange:e=>{!e&&!g.current&&i()},title:`Save as template`,description:`Save this revision’s setup for a fresh Play draft. This does not rebuild the project.`,children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,h.jsx)(LB,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(zB,{autoFocus:!0,required:!0,maxLength:200,disabled:l,value:s?.name??``,onChange:e=>{let t=e.target.value;c(e=>e&&{...e,name:t})}})}),d?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:d}):null,(0,h.jsxs)(`div`,{className:`sl-dialog__foot`,children:[(0,h.jsx)(B,{disabled:l,onClick:i,children:`Cancel`}),(0,h.jsx)(B,{variant:`primary`,type:`submit`,disabled:l||!s?.name.trim(),children:`Save template`})]})]})})}var P7=Y({baseRevisionId:K().min(1).max(64),idempotencyKey:_D()}).strict(),dSe=XD(`kind`,[Y({kind:oO(`resume`)}).strict(),Y({kind:oO(`retry`),stage:X(KS)}).strict(),Y({kind:oO(`rerun`),stage:X(KS)}).strict(),Y({kind:oO(`redo`),item:K().min(1).max(200)}).strict()]);P7.extend({action:dSe}).strict();var fSe=XD(`ok`,[Y({ok:oO(!0),value:g0.and(Y({warnings:J(K()).readonly()}))}),Y({ok:oO(!1),reason:X([`no-project`,`no-revision`,`conflict`,`idempotency-conflict`,`invalid-edit`,`stale-preview`,`invalid-selection`,`review-required`,`cost-ack-required`,`readiness`,`running`,`accepted-job`,`control-changed`]),fields:J(Y({field:K(),message:K()})).readonly().optional(),intentRevisionId:K().optional(),currentRevisionId:K().nullable().optional()})]),F7=new Set([400,404,409]);async function pSe(e,t,n){return L7(e,t,`cancel`,n)}async function mSe(e,t,n){return L7(e,t,`pause`,n)}function hSe(e,t,n){return R7(e,t,`resume`,n)}function gSe(e,t,n,r){return R7(e,t,`stages/${n}/retry`,r)}function _Se(e,t,n,r){return R7(e,t,`stages/${n}/soften`,r)}function vSe(e,t,n,r){return R7(e,t,`stages/${n}/rerun`,r)}async function ySe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/providers`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function bSe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/subtitles`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function xSe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/article`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({markdown:n})}))}async function SSe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].$delete({param:{id:t,outputId:n}}))}async function CSe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].regenerate.$post({param:{id:t,outputId:n}}))}async function I7(e){if(e.ok)return{ok:!0,value:await e.json()};let t=await uo(e);if(t!==void 0&&F7.has(e.status))return{ok:!1,message:lo(e,t).message};throw lo(e,t)}async function L7(e,t,n,r){let i=P7.parse(r);return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}))}async function R7(e,t,n,r){let i=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(P7.parse(r))});if(i.ok){let e=fSe.parse(await i.json());if(!e.ok)throw Error(vo);return{ok:!0,value:e.value,warnings:e.value.warnings}}let a=await uo(i);if(a!==void 0&&F7.has(i.status))return{ok:!1,message:lo(i,a).message};throw lo(i,a)}function wSe(e){let{api:t}=V(),n=_(),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(),s=(0,m.useRef)(new Map),c=(0,m.useRef)(!1),l=L({mutationFn:async e=>{let r=e.action;if(![`pause`,`cancel`,`resume`,`retry`,`soften`,`rerun`].includes(r.kind))return B7(t,e.projectId,r);let i=r.kind===`retry`||r.kind===`soften`||r.kind===`rerun`?r.stage:``,a=`${e.projectId}:${r.kind}:${i}`,o=s.current.get(a);if(!o){let r=n.getQueryData(H.project(e.projectId))?.revisionId;if(!r){let n=await D0(t,e.projectId);if(!n.ok)return{ok:!1,message:n.message};r=n.value.view.revision.id}o={baseRevisionId:r,idempotencyKey:crypto.randomUUID()},s.current.set(a,o)}let c=await B7(t,e.projectId,r,o);return s.current.delete(a),c.ok&&await Oo(t,e.projectId).then(t=>n.setQueryData(H.project(e.projectId),t),e=>console.warn(`Project refresh after an accepted action failed`,e)),c},onMutate:()=>{i(void 0),o(void 0)},onSuccess:async(e,t)=>{e.ok?(o(`warnings`in e&&e.warnings.length>0?e.warnings.join(` `):void 0),n.invalidateQueries({queryKey:H.projects})):i({message:e.message,stage:z7(t.action)}),await n.invalidateQueries({queryKey:H.project(t.projectId)})},onSettled:()=>{c.current=!1},onError:(e,t)=>{i({message:e.message,stage:z7(t.action)})}});return{run:(t,n)=>{c.current||(c.current=!0,l.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok&&n?.()}}))},pending:l.isPending,performing:l.isPending?l.variables?.action:void 0,refusal:r,dismissRefusal:()=>{i(void 0)},notice:a}}function z7(e){switch(e.kind){case`cancel`:case`pause`:case`resume`:case`providers`:return;case`retry`:case`soften`:case`rerun`:return e.stage;case`subtitles`:return`video`;case`save-article`:return`article`;case`delete-image`:case`regenerate-image`:return`images`}}function B7(e,t,n,r){let i=()=>{if(!r)throw Error(`A saved revision and request identity are required.`);return r};switch(n.kind){case`pause`:return mSe(e,t,i());case`cancel`:return pSe(e,t,i());case`resume`:return hSe(e,t,i());case`retry`:return gSe(e,t,n.stage,i());case`soften`:return _Se(e,t,n.stage,i());case`rerun`:return vSe(e,t,n.stage,i());case`providers`:return ySe(e,t,n.choices);case`subtitles`:return bSe(e,t,n.subtitles);case`save-article`:return xSe(e,t,n.markdown);case`delete-image`:return SSe(e,t,n.outputId);case`regenerate-image`:return CSe(e,t,n.outputId)}}var V7=e=>e.state===`done`||e.state===`provided`;function TSe(e){let t=e.find(e=>e.state===`failed`)??e.find(e=>e.state===`running`);if(t)return t.kind;let n=e.find(e=>e.kind===`video`&&V7(e));if(n)return n.kind;let r=e.find(e=>e.state===`pending`);return r?r.kind:e.find(e=>e.kind===`article`&&V7(e))?.kind??e.find(e=>e.state!==`skipped`)?.kind??`article`}function ESe({projectId:e,openDraft:t}){return(0,h.jsx)(DSe,{projectId:e,openDraft:t},e)}var H7=e=>{let t=e.filter(e=>e!==void 0);if(!(t.length===0||t.every(e=>e.state===`skipped`)))return t.some(e=>e.state===`failed`&&e.retryAt===void 0)?`failed`:t.some(e=>e.state===`running`)?`running`:t.some(e=>e.state===`failed`)?`waiting`:t.every(e=>e.state===`done`||e.state===`provided`||e.state===`skipped`)?`done`:`off`};function DSe({projectId:e,openDraft:t}){let{api:n}=V(),r=Ry(),i=ASe(e,t),a=I(sb(n,e)),o=I(pb(n)),s=I({...cb(n,e),refetchInterval:e=>a.data?.project.status===`running`&&e.state.status===`success`&&2e4}),c=wSe(e),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),x=a.data?.revisionId??null,S=Qxe(e,x,{onOpenEdit:()=>u(`settings`)}),C=die(e),w=(0,m.useRef)(void 0);(0,m.useEffect)(()=>{if(C===void 0){w.current=void 0;return}a.data!==void 0&&w.current!==C&&(w.current=C,C===`download`&&u(XP(a.data.project.config)===`article`?`article`:`video`))},[C,a.data]),k3(e,x);let T=I({queryKey:Wy,queryFn:()=>Qy(n)}),E=$y(T.data,e),D=I({queryKey:c3(e,x??``),queryFn:()=>u3(n,e),enabled:x!==null,retry:!1}),O=D.data?.ok===!0?D.data.value.checkpoints:[],k=S.saved.data?.outputs.filter(e=>e.selected&&e.state===`outdated`).map(e=>({workKey:e.workKey,role:e.output.role}))??[],A=a.data?.project,j=a.data?.stages??[],M=a.data?.outputs??[],ee=M.some(e=>e.role===`video`),N=e=>u(e),P=bye({project:A??OSe,stages:j,resumable:a.data?.resumable??!1,sample:E,gates:O,outdated:k,waits:s.data?.waits??[],uploadReady:ee,actions:c,controller:S,openSection:N,openUpload:()=>f(!0)}),F=l===`settings`,te=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!F){te.current=!1;return}S.edit!==void 0&&(te.current=!0),!(te.current||S.busy)&&(te.current=!0,S.openEditor())},[F,S]);let ne=j.some(e=>e.state===`running`),re=A?.status===`running`,ie=A?.title??``,ae=P.next?.action;jx({id:`project.next`,title:ae?.label??`Show the project's next action`,group:`This project`,context:ie,keywords:[`next`,`continue`,`resume`,`approve`,`retry`],shortcut:nP.nextAction,run:()=>{ae===void 0?r(`This project has no next action right now: nothing waits on you.`,`info`):ae.intent.kind===`soften`?r(`Soften and retry asks first: press it in the Next action panel on the right.`):P.run(ae.intent)}}),oS(tS.showImages(e),()=>{let e=a.data?.stages.find(e=>e.kind===`images`);e===void 0||e.state===`skipped`?r(`${ie} makes no slideshow images, so there is no image to regenerate. To add them, open Settings in this project and choose how its images are made.`,`error`):u(`images`)},a.data!==void 0),jx({id:`project.pause`,title:A?.status===`paused`?`Continue the run`:`Pause the run`,group:`This project`,context:ie,keywords:[`pause`,`resume`,`continue`,`stop`],run:()=>c.run({kind:A?.status===`paused`?`resume`:`pause`})}),jx({id:`project.prepare-upload`,title:`Prepare upload`,group:`This project`,context:ie,keywords:[`youtube`,`studio`,`upload`,`publish`],run:()=>{ee?f(!0):r(`Prepare upload opens once the video has been made.`,`info`)}}),jx({id:`project.settings`,title:`Edit project settings`,group:`This project`,context:ie,keywords:[`edit`,`settings`,`prompts`,`providers`,`channel`],run:()=>u(`settings`)}),jx({id:`project.rebuild-review`,title:`Choose what to remake`,group:`This project`,context:ie,keywords:[`rebuild`,`review`,`remake`,`outdated`,`affected`],run:()=>S.review({kind:`allAffected`})}),jx({id:`project.template`,title:`Save as template`,group:`This project`,context:ie,keywords:[`template`,`reuse`],run:()=>g(!0)}),jx({id:`project.cancel`,title:`Cancel the run`,group:`This project`,context:ie,keywords:[`cancel`,`stop`],run:()=>b(!0)});let oe=vye(k);if(jx({id:`project.remake-1`,title:oe[0]?.label??`Remake outdated outputs`,group:`This project`,context:ie,keywords:[`remake`,`outdated`,`rebuild`],run:()=>{let e=oe[0];e===void 0?r(`Nothing is outdated in this project.`,`info`):S.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0})}}),jx({id:`project.remake-all`,title:`Remake everything outdated`,group:`This project`,context:ie,keywords:[`remake`,`outdated`,`rebuild`,`all`],run:()=>{let e=[...new Set(oe.flatMap(e=>e.workKeys))];e.length===0?r(`Nothing is outdated in this project.`,`info`):S.review({kind:`selected`,workKeys:e},{autoStart:!0})}}),jx({id:`project.copy`,title:`Make my own copy`,group:`This project`,context:ie,keywords:[`sample`,`copy`,`duplicate`],run:()=>E?P.run({kind:`copy-sample`}):r(`Only the sample project is copied this way.`,`info`)}),a.error!==null)return(0,h.jsx)(aI,{tone:`danger`,title:`The project could not be loaded.`,children:`${a.error.message} Reload the page to try again, or go back to Projects.`});if(a.data===void 0||A===void 0)return(0,h.jsx)(kSe,{});let se=e=>j.find(t=>t.kind===e),ce=se(`article`),le=se(`research`),ue=se(`audio`),de=se(`images`),fe=se(`thumbnail`),pe=se(`video`),me=se(`document`),he=A.config,ge=e=>e!==void 0&&e.state!==`skipped`,_e=he.shorts?.enabled===!0||M.some(e=>e.role===`short_video`||e.role===`shorts`),ve=he.youtubeDescription===!0||M.some(e=>e.role===`youtube_description`),ye=O.filter(e=>e.state===`held`||e.state===`pending-review`),be=[...ge(ce)||ge(le)?[{id:`article`,label:`Article`,tone:H7([ce,le])}]:[],...ge(ue)?[{id:`narration`,label:`Narration`,tone:H7([ue])}]:[],...ge(de)||ge(fe)||he.reference!==void 0?[{id:`images`,label:`Images`,tone:H7([de,fe])}]:[],...ge(pe)?[{id:`video`,label:XP(he)===`audio`?`Audio export`:`Video`,tone:H7([pe])}]:[],...ge(me)?[{id:`document`,label:`PDF`,tone:H7([me])}]:[],{id:`cost`,label:`Cost`},{id:`live`,label:`Live`}].map(e=>{let t=oe.filter(t=>t.section===e.id).reduce((e,t)=>e+t.count,0);return t===0?e:{...e,meta:`${String(t)} outdated`}}),xe=[{id:`settings`,label:`Settings`,...S.unsaved?{meta:`unsaved`}:{}},...x===null?[]:[{id:`checkpoints`,label:`Checkpoints`,...ye.length===0?{}:{meta:`${String(ye.length)} held`}}],{id:`history`,label:`History`}],Se=[...be,...xe],Ce=P.next?.situation,we=P.next?.section!==void 0&&Ce!==`done`&&Ce!==`running`?P.next.section:Ce===`done`&&M.some(e=>e.role===`youtube_description`)?`youtube`:Q8(TSe(j)),Te=e=>e===`shorts`||e===`youtube`?`video`:e,Ee=l!==void 0&&Se.some(e=>e.id===Te(l))?Te(l)??`video`:Se.find(e=>e.id===Te(we))?.id??be[0]?.id??`cost`,De=(...e)=>x===null?A.status===`running`||A.status===`paused`||ne||c.pending:c.pending||e.some(e=>e?.state===`running`),Oe={project:A,outputs:M,actions:c,next:P,resumable:a.data.resumable},ke=(e,t)=>e===void 0?null:(0,h.jsx)(ybe,{stage:e,...t===void 0||t.state===`skipped`?{}:{companion:t},project:A,outputs:M,actions:c,busy:De(e,t)}),Ae=(...e)=>M.some(t=>e.some(e=>e!==void 0&&t.stageKind===e.kind)),je=(...e)=>Ae(...e)||e.some(e=>e!==void 0&&[`running`,`done`,`provided`,`failed`,`canceled`].includes(e.state)),Me=[{id:`rebuild`,label:`Choose what to remake…`,run:()=>S.review({kind:`allAffected`}),disabled:S.busy},{id:`template`,label:`Save as template…`,run:()=>g(!0),disabled:x===null||E},{id:`channel`,label:`Move to channel…`,run:()=>v(!0),disabled:E},{id:`cancel`,label:`Cancel the run…`,run:()=>b(!0),disabled:!re||c.pending,apart:!0}],Ne=Z8({kind:`cancel`}),Pe=c.refusal?.stage===void 0?c.refusal:void 0,Fe=Pe===void 0?c.notice===void 0?S.preview===void 0&&(S.error||S.refusal)&&Ee!==`settings`&&Ee!==`history`?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:S.error??S.refusal?.message}):void 0:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:c.notice}):(0,h.jsx)(aI,{tone:`danger`,title:Pe.message,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,className:`mt-1`,onClick:c.dismissRefusal,children:`Dismiss`})}),Ie=sSe({stages:j,outputs:M,project:A,resumable:a.data.resumable,held:ye.map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),now:Date.now()});return(0,h.jsx)(Dve,{projectId:e,revisionId:x,children:(0,h.jsx)(W8,{value:x!==null,children:(0,h.jsx)(f3,{value:e=>u(e===`edit`?`settings`:`article`),children:(0,h.jsx)(G8,{value:S.pending||S.preview!==void 0?void 0:S.requestEdit,children:(0,h.jsxs)(K8,{value:S.pending||S.preview!==void 0?void 0:S.regenerateNow,children:[(0,h.jsxs)(`div`,{className:`sl-project`,children:[(0,h.jsx)(`div`,{"data-tour":`project-controls`,children:(0,h.jsx)(jbe,{project:A,prompts:o.data?.prompts,editing:Ee===`settings`,onEdit:()=>u(`settings`),more:Me,nextChapter:i,clock:(0,h.jsx)(Rbe,{cost:s.data,status:A.status,measuredAt:s.dataUpdatedAt})})}),(0,h.jsx)(M7,{stages:j}),(0,h.jsxs)(ZK,{sections:(0,h.jsxs)(X6,{label:`Project sections`,children:[be.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:N},e.id)),(0,h.jsx)(`hr`,{className:`sl-rule my-2`}),xe.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:N},e.id))]}),aside:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Sye,{state:P,feedback:Fe}),A===void 0?null:(0,h.jsx)(Abe,{projectId:e,title:A.title,status:A.status,sample:E||T.isPending}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-6 max-[1180px]:hidden`,children:[(0,h.jsx)(cSe,{steps:Ie}),(0,h.jsx)(lSe,{cost:s.data,onOpen:()=>N(`cost`)}),(0,h.jsx)(ove,{})]})]}),children:[(0,h.jsx)(o5,{id:`article`,title:`Article`,stages:[ce,le].filter(U7),active:Ee===`article`,...Oe,children:ge(ce)||ge(le)?ke(ce,le):(0,h.jsx)(s5,{stage:ce,project:A,name:`Article`})}),(0,h.jsx)(o5,{id:`narration`,title:`Narration`,stages:[ue].filter(U7),active:Ee===`narration`,...Oe,children:je(ue)?ke(ue):(0,h.jsx)(s5,{stage:ue,project:A,name:`Narration`})}),(0,h.jsx)(o5,{id:`images`,title:`Images`,head:!1,stages:[de,fe].filter(U7),active:Ee===`images`,...Oe,children:ke(de,fe)}),(0,h.jsxs)(o5,{id:`video`,title:XP(he)===`audio`?`Audio export`:`Video`,stages:[pe].filter(U7),active:Ee===`video`,...Oe,...ee&&P.next?.action?.intent.kind!==`prepare-upload`?{extra:(0,h.jsx)(B,{variant:`secondary`,onClick:()=>f(!0),children:`Prepare upload`})}:{},children:[ke(pe),pe!==void 0&&_e?(0,h.jsx)(ube,{stage:pe,project:A,outputs:M}):null,pe!==void 0&&ve?(0,h.jsx)(xbe,{stage:pe,project:A,outputs:M}):null]}),me===void 0?null:(0,h.jsx)(o5,{id:`document`,title:`PDF`,stages:[me],active:Ee===`document`,...Oe,children:je(me)?ke(me):(0,h.jsx)(s5,{stage:me,project:A,name:`PDF`})}),(0,h.jsx)(G7,{id:`cost`,title:`Run cost`,selected:Ee,children:(0,h.jsx)(Ibe,{projectId:e})}),(0,h.jsx)(G7,{id:`live`,title:`Live`,selected:Ee,children:Ee===`live`?(0,h.jsx)(Jbe,{project:A,revisionId:x,stages:j,outputs:M}):null}),(0,h.jsx)(G7,{id:`settings`,title:`Settings`,selected:Ee,children:(0,h.jsx)(eSe,{controller:S,active:Ee===`settings`,renderEditor:e=>(0,h.jsx)(zxe,{...e,renderContent:e=>(0,h.jsx)(xxe,{...e},e.view.revision.id)})})}),x===null?null:(0,h.jsx)(G7,{id:`checkpoints`,title:`Checkpoints`,selected:Ee,children:(0,h.jsx)(Ebe,{projectId:e,revisionId:x,paused:A.status===`paused`,stages:j,approvedInRail:P.next?.action?.intent.kind===`approve`?P.next.action.intent.gate.checkpointId:void 0})}),(0,h.jsx)(G7,{id:`history`,title:`History`,selected:Ee,children:(0,h.jsx)(tSe,{controller:S,projectId:e,active:Ee===`history`})})]})]}),(0,h.jsx)(nSe,{controller:S}),d?(0,h.jsx)(W0,{projectId:e,onClose:()=>f(!1)}):null,(0,h.jsx)(Qbe,{projectId:e,title:A.title,open:_,onClose:()=>v(!1)}),(0,h.jsx)(uSe,{projectId:e,revisionId:x,title:A.title,open:p,onClose:()=>g(!1)}),(0,h.jsx)(Hy,{open:y,title:Ne.title,consequence:Ne.consequence,confirmLabel:Ne.verb,cancelLabel:Ne.dismiss,pending:c.pending,onConfirm:()=>{b(!1),c.run({kind:`cancel`})},onCancel:()=>b(!1)})]})})})})})}var U7=e=>e!==void 0;function W7({item:e,selected:t,onSelect:n}){return(0,h.jsx)(Z6,{className:`max-md:w-auto`,"data-tour":`project-rail-${e.id}`,current:e.id===t,onClick:()=>n(e.id),...e.tone===void 0?{}:{icon:(0,h.jsx)(DS,{tone:e.tone})},...e.meta===void 0?{}:{meta:e.meta},children:e.label})}function G7({id:e,title:t,selected:n,children:r}){return(0,h.jsxs)(`section`,{hidden:n!==e,"aria-label":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:t}),r]})}var OSe={id:``,title:``,format:`16:9`,status:`pending`,createdAt:``,config:{sources:{}}};function kSe(){return(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading project`,children:[(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-8 w-80 max-w-full rounded-control bg-sunken`})]}),(0,h.jsx)(ZK,{sections:(0,h.jsx)(`div`,{className:`flex flex-col gap-2`,children:[`a`,`b`,`c`,`d`,`e`].map(e=>(0,h.jsx)(`span`,{className:`h-8 rounded-control bg-sunken`},e))}),aside:(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`}),children:(0,h.jsx)(`span`,{className:`h-[480px] rounded-control bg-sunken`})})]})}function ASe(e,t){let{api:n}=V(),r=(0,m.useRef)(void 0),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0);if(t!==void 0)return{pending:i,error:o,run:()=>{i||(r.current??=crypto.randomUUID(),a(!0),s(void 0),gq(n,e,r.current).then(async e=>{if(!e.ok){s(e.message);return}await t(e.value.draft.id)?r.current=void 0:s(`The next chapter's draft was made, but Play could not open it because the draft open there is not saved yet. Open Play, let it save, then press Make the next chapter again.`)}).catch(e=>s(`The next chapter could not be made (${e instanceof Error?e.message:`the connection dropped`}). Press Make the next chapter again.`)).finally(()=>a(!1)))}}}var jSe=[`all`,`running`,`queued`,`waiting`,`ready`,`failed`];function MSe(e){return jSe.find(t=>t===e)}var K7=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`queued`,label:`Queued`},{value:`waiting`,label:`Needs you`},{value:`ready`,label:`Ready to upload`},{value:`failed`,label:`Failed`}];function q7(e,t){switch(t){case`all`:return!0;case`running`:return e.status===`running`||e.status===`paused`;case`queued`:return b3(e);case`waiting`:return g3(e);case`ready`:return y3(e);case`failed`:return e.status===`failed`||e.status===`partial`}}function NSe(e){let t={running:{tone:`running`,word:`Running`},paused:{tone:`waiting`,word:`Paused`},pending:{tone:`off`,word:`Queued`},failed:{tone:`failed`,word:`Failed`},partial:{tone:`info`,word:`Done with problems`},done:{tone:`done`,word:`Done`},canceled:{tone:`off`,word:`Canceled`}};if(g3(e))return{tone:`waiting`,word:`Waiting for you`};if(e.status===`pending`&&e.setAside===!0)return{tone:`done`,word:`Kept as is`};let n=e.status===`running`?gH(e.limitWaits):void 0;return n===void 0?t[e.status]:{tone:`waiting`,word:n}}function PSe(e){let t=e.config.articlePrompt,n=e.config.voices?.book;return[n===void 0?void 0:AA(n),t===void 0||t===``?void 0:t,e.format].filter(e=>e!==void 0).join(` · `)}function FSe({initialFilter:e=`all`}={}){let{api:t}=V(),n=_(),r=Ry(),i=Dx(),a=I(ob(t)),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(e),u=I({queryKey:Uy,queryFn:()=>qy(t)}),d=new Set(Object.values(u.data?.samples??{}).filter(e=>e!==null)),[f,p]=(0,m.useState)(``),g=(0,m.useRef)(null),v=Mx(g,`projects`),y=L({mutationFn:e=>jo(t,e),onSettled:async()=>{s(void 0),await n.invalidateQueries({queryKey:H.projects})}}),b=L({mutationFn:e=>m3(t,e.project.id,e.uploaded),onError:(e,t)=>r(`${t.project.title} wasn't changed: ${e.message} Press the button again.`,`error`),onSettled:async()=>{await n.invalidateQueries({queryKey:H.projects})}});jx({id:`projects.show.waiting`,title:`Show projects that need you`,group:`Projects`,keywords:[`waiting`,`filter`],run:()=>l(`waiting`)}),jx({id:`projects.show.ready`,title:`Show videos ready to upload`,group:`Projects`,keywords:[`upload`,`finished`,`filter`],run:()=>l(`ready`)}),jx({id:`projects.show.failed`,title:`Show failed projects`,group:`Projects`,keywords:[`error`,`filter`],run:()=>l(`failed`)});let x=(a.data?.projects??[]).filter(e=>i.includes(e.channelId)),S=f.trim().toLowerCase(),C=x.filter(e=>q7(e,c)&&(S===``||e.title.toLowerCase().includes(S)));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{title:`Projects`,meta:a.data===void 0?void 0:`${String(x.length)} ${x.length===1?`project`:`projects`} · ${i.channel?.name??`every channel`}`,actions:(0,h.jsxs)(CS,{to:`/play`,variant:`primary`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]})}),a.data?.projects.length===0?(0,h.jsx)(dde,{}):null,a.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-4 text-danger`,children:a.error.message}),a.data===void 0?a.error===null?(0,h.jsx)(LSe,{}):null:a.data.projects.length===0?(0,h.jsx)(T1,{title:`No projects yet`,actions:(0,h.jsx)(CS,{to:`/play`,variant:`primary`,children:`Make your first video`}),children:`Set up a run on Play: pick a template, type a topic and start.`}):(0,h.jsxs)(b1,{split:`aside`,children:[(0,h.jsxs)(x1,{label:`Project list`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`div`,{className:`relative w-full max-w-[320px]`,children:[(0,h.jsx)(Yc,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{type:`search`,ref:g,"aria-label":`Search projects`,"aria-keyshortcuts":Ux(v),placeholder:`Search projects`,value:f,onChange:e=>p(e.target.value),className:`sl-input pl-9`})]}),(0,h.jsx)(Vb,{label:`Show`,value:c,options:K7,onChange:l,className:`max-w-full overflow-x-auto`})]}),C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:x.length===0?`No projects in ${i.channel?.name??`this channel`} yet. Pick All channels in the rail to see the others.`:`No project matches. Clear the search or pick All.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RSe,{projects:C}),(i.channel===void 0&&i.channels.length>1?i.channels.map(e=>({channel:e,projects:C.filter(t=>(t.channelId??i.channels[0]?.id)===e.id)})).filter(e=>e.projects.length>0):[{channel:void 0,projects:C}]).map(e=>(0,h.jsxs)(`section`,{"aria-label":e.channel?.name??`Projects`,className:`flex flex-col gap-2`,children:[e.channel===void 0?null:(0,h.jsx)(W,{as:`h3`,size:`small`,title:e.channel.name,meta:`${String(e.projects.length)} ${e.projects.length===1?`project`:`projects`}`}),(0,h.jsx)(PH,{label:e.channel?.name??`Projects`,children:e.projects.map(e=>(0,h.jsx)(ISe,{project:e,sample:d.has(e.id),onDelete:()=>s(e),onUploaded:t=>b.mutate({project:e,uploaded:t}),busy:b.isPending},e.id))})]},e.channel?.id??`all`))]})]}),(0,h.jsxs)(x1,{as:`aside`,label:`Projects at a glance`,children:[(0,h.jsxs)(`section`,{children:[(0,h.jsx)(W,{title:`At a glance`}),(0,h.jsx)(x2,{children:K7.filter(e=>e.value!==`all`).map(e=>(0,h.jsx)(S2,{label:e.label,value:String(x.filter(t=>q7(t,e.value)).length)},e.value))})]}),(0,h.jsxs)(`section`,{"aria-label":`Video queue`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Video queue`,info:`play.queue`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Videos started together, in the order they run, are on the calendar.`}),(0,h.jsx)(`div`,{children:(0,h.jsx)(wS,{to:`/calendar`,children:`Open calendar`})})]})]})]}),y.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`mt-3 text-small text-danger`,children:y.error.message}),(0,h.jsx)(Hy,{open:o!==void 0,title:o===void 0?``:`Delete "${o.title}"?`,consequence:`Moves the project to the trash for 30 days. Restore it or delete it for good in Settings → Trash.`,confirmLabel:`Delete project`,cancelLabel:`Keep it`,pending:y.isPending,onConfirm:()=>{o!==void 0&&y.mutate(o.id)},onCancel:()=>s(void 0)})]})}function ISe({project:e,sample:t,onDelete:n,onUploaded:r,busy:i}){let a=NSe(e),o=e.status===`running`;return(0,h.jsx)(FH,{title:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),t?(0,h.jsx)(kS,{children:`Sample`}):null]}),meta:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`span`,{children:[`${PSe(e)} · started ${Wu(e.createdAt)}`,e.views===void 0?``:` · ${e.views.toLocaleString()} views${e.ctr===void 0?``:` · ${String(e.ctr)}% CTR`}`]}),o?(0,h.jsx)(C2,{value:e.progress,label:`${e.title} progress`,valueText:`${String(Math.round(e.progress*100))}% done`,className:`max-w-[240px]`}):null]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(OS,{tone:a.tone,children:[a.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`${e.title}: ${a.word}`})]}),y3(e)?(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!0),children:`Mark uploaded`}):null,y3(e)?(0,h.jsx)(U,{id:`project.mark-uploaded`}):e.uploadedAt===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(kS,{children:`Uploaded`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Mark ${e.title} not uploaded`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!1),children:`Undo`})]}),(0,h.jsx)(Py,{label:`Delete ${e.title}`,size:`small`,disabled:o,disabledReason:`Cancel the run first, then delete it.`,onClick:n,children:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function LSe(){return(0,h.jsx)(`ul`,{"aria-label":`Loading projects`,className:`sl-list m-0 list-none p-0`,children:[0,1,2,3,4,5].map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,"data-slot":`skeleton-row`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-2/5 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[10px] w-1/4 rounded-control bg-sunken`})]}),(0,h.jsx)(`span`,{className:`h-[10px] w-16 rounded-control bg-sunken`})]},e))})}function RSe({projects:e}){let{api:t}=V(),n=_(),r=Ry(),i=Dx(),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(!1),l=L({mutationFn:()=>Ao(t,e.map(e=>e.id),a),onSuccess:e=>{n.invalidateQueries({queryKey:H.projects});let t=i.channels.find(e=>e.id===a)?.name??`the channel`;r(`Moved ${String(e.moved)} projects to ${t}.`,`success`),o(``)},onError:e=>r(`The projects weren't moved: ${e.message}`,`error`)});if(i.channels.length<2||e.length===0)return null;let u=i.channels.find(e=>e.id===a)?.name??``;return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Move the ${String(e.length)} shown to`}),(0,h.jsx)(VB,{"aria-label":`Channel to move the shown projects to`,className:`w-[220px]`,value:a,onChange:e=>o(e.currentTarget.value),options:[{value:``,label:`Choose a channel`},...i.channels.map(e=>({value:e.id,label:e.name}))]}),(0,h.jsx)(B,{type:`button`,variant:`secondary`,size:`small`,disabled:a===``||l.isPending,onClick:()=>e.length>1?c(!0):l.mutate(),children:`Move`}),(0,h.jsx)(Hy,{open:s,title:`Move ${String(e.length)} projects to ${u}?`,confirmLabel:`Move them`,tone:`primary`,consequence:`Every project the list shows now goes to ${u}, from ${e[0]?.title??``} to ${e.at(-1)?.title??``}. You can move them back the same way.`,onConfirm:()=>{c(!1),l.mutate()},onCancel:()=>c(!1)})]})}var zSe=`Prepare restrained delivery cues for a documentary narrator. Let the facts carry the scene. Use a measured pace and make only occasional changes where the supplied wording clearly calls for emphasis, reflection or tension. Prefer no cue to an unnecessary cue. Avoid theatrical emotion, invented reactions and routine laughter or sighs. Never rewrite, summarize, translate or add spoken words. Return only the cue annotations required by the supplied format contract.`;function J7({promptId:e,kind:t,from:n,onLeave:r}){let{api:i}=V(),a=_(),o=$F(),s=I(pb(i)),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=$N(JSON.stringify(e===void 0?[`new`,t,n??null]:[`prompt`,e])),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(void 0),b=v!==void 0,[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),T=s.data?.prompts,E=e??n,D=E===void 0?void 0:T?.find(e=>e.id===E),O=D===void 0?{kind:t,name:``,body:``}:e===void 0?{kind:D.kind,name:`${D.name} copy`,body:D.body}:{kind:D.kind,name:D.name,body:D.body},k=d??v??O,A=L({mutationFn:t=>Ps(i,t,e),onSuccess:async(e,t)=>{if(!e.ok){g(e.fields);return}y(e.value),f(e=>e===t?void 0:e),o({type:`prompt-saved`,id:e.value.id,kind:e.value.kind}),await a.invalidateQueries({queryKey:pb(i).queryKey})}}),j=L({mutationFn:e=>Is(i,e),onSuccess:async()=>{S(!1),f(void 0),await a.invalidateQueries({queryKey:pb(i).queryKey}),r(k.kind)}}),M=L({mutationFn:({id:e,on:t})=>Fs(i,e,t),onSettled:async()=>{await a.invalidateQueries({queryKey:pb(i).queryKey})}});K2(b,()=>{r(k.kind)});let ee=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},N=Z4(k,p),P=Q4(N),F=t3(k.body),te=k.body.trim()===``?[]:$4(N),ne=k.name.trim()===``?[]:e3(N);return QF({promptNamed:k.name.trim()!==``&&ne.length===0,promptBodyReady:k.body.trim()!==``&&te.length===0,promptHasKeywords:F.length>0&&te.length===0,promptSaveReady:P===void 0&&!A.isPending&&!b,promptSaving:A.isPending||b,promptIsArticle:k.kind===`article`,promptIsImage:k.kind===`image`}),s.error===null?E!==void 0&&T===void 0?(0,h.jsx)(Y2,{}):E!==void 0&&D===void 0?(0,h.jsx)(X7,{kind:t,children:`That prompt is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/prompts`,search:{kind:k.kind},children:`Prompts`})}),title:e===void 0?`New prompt`:`Edit prompt`,meta:`${NB(k.kind)} prompt`}),(0,h.jsxs)(`div`,{"data-tour":`prompt-editor`,className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{"data-tour":`prompt-name`,className:`min-w-[min(100%,240px)] flex-1`,children:(0,h.jsx)(LB,{label:`Name`,tip:`library.prompt.name`,...ne.length===0?{}:{error:ne.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:k.name,onChange:e=>{ee({...k,name:e.target.value},`name`)}})})}),(0,h.jsx)(Y4,{label:`Kind`,value:k.kind,options:MB,tip:`library.prompt.kind`,onPick:e=>{ee({...k,kind:e},`name`)}})]}),(0,h.jsxs)(`div`,{"data-tour":`prompt-body`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex min-h-8 items-end justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(U,{id:BSe[k.kind],label:`${NB(k.kind)} prompt body`,className:`-my-1`})]}),Y7(k.kind)?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>{let e=Y7(k.kind);e!==void 0&&(k.body.trim()===``?ee({...k,body:e.body},`body`):w(!0))},children:Y7(k.kind)?.label}),(0,h.jsx)(U,{id:`library.prompt.starter`,label:Y7(k.kind)?.label})]}):null]}),(0,h.jsx)(r3,{id:c,value:k.body,invalid:te.length>0,describedBy:te.length===0?void 0:l,onChange:e=>{ee({...k,body:e},`body`)}})]}),k.kind===`image`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e!==void 0&&D?.kind===`image`?(0,h.jsx)(Bb,{checked:M.isPending?M.variables.on:D.photorealistic===!0,disabled:M.isPending,onChange:t=>M.mutate({id:e,on:t}),label:`Draws photorealistic pictures`,tip:`library.prompt.photorealistic`}):(0,h.jsxs)(`span`,{className:`flex items-center gap-1 text-small text-ink-2`,children:[`Save this Image prompt first, then choose whether it draws photorealistic pictures.`,(0,h.jsx)(U,{id:`library.prompt.photorealistic`})]}),M.error===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small text-danger`,children:`Couldn't change Draws photorealistic pictures: ${M.error.message} Press the switch again.`})]}):null,(0,h.jsx)(`div`,{"data-tour":`prompt-save`,children:(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{S(!0)},blocked:P,blockedId:u,pending:A.isPending,saved:b,cancel:(0,h.jsx)(CS,{to:`/prompts`,search:{kind:k.kind},onClick:()=>{f(void 0)},variant:`secondary`,children:`Cancel`}),errors:[A.error,j.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{A.mutate(k)}})})]}),(0,h.jsx)(`div`,{"data-tour":`prompt-slots`,className:u4,children:(0,h.jsx)(G4,{slots:F,body:k.body,lint:te,lintId:l})})]}),(0,h.jsx)(Hy,{open:C,title:`Replace this prompt body?`,consequence:`The starter replaces the text in this editor. Nothing is saved until you choose Save.`,confirmLabel:`Use starter`,tone:`primary`,onConfirm:()=>{let e=Y7(k.kind);e!==void 0&&ee({...k,body:e.body},`body`),w(!1)},onCancel:()=>w(!1)}),(0,h.jsx)(Hy,{open:x,title:`Delete "${k.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:j.isPending,onConfirm:()=>{e!==void 0&&j.mutate(e)},onCancel:()=>{S(!1)}})]}):(0,h.jsx)(X7,{kind:k.kind,children:s.error.message})}var BSe={article:`library.prompt.body.article`,image:`library.prompt.body.image`,thumbnail:`library.prompt.body.thumbnail`,narration:`library.prompt.body.narration`,description:`library.prompt.body.description`,shorts:`library.prompt.body.shorts`,review:`library.prompt.body.review`,script:`library.prompt.body.script`};function Y7(e){if(e===`narration`)return{label:`Use Documentary Starter`,body:zSe};if(e===`description`)return{label:`Use Built-in Starter`,body:Jge};if(e===`shorts`)return{label:`Use Built-in Starter`,body:Rk}}function X7({kind:e,children:t}){return(0,h.jsx)(f4,{back:(0,h.jsx)(fa,{to:`/prompts`,search:{kind:e},children:`Back to Prompts`}),children:t})}function VSe({kind:e,onKind:t,onUseInPlay:n,playBlocked:r}){let{api:i}=V(),a=_(),o=I(pb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=Mx(l,`prompts`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=L({mutationFn:e=>Is(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:H.prompts})}}),x=async(e,t)=>{let n=await Ps(i,{kind:e.kind,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:H.prompts}),n.ok?null:U4(n.fields)},S=o.data?.prompts.filter(t=>t.kind===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(I4,{action:(0,h.jsx)(USe,{kind:e}),children:[(0,h.jsx)(zB,{type:`search`,ref:l,"aria-label":`Search prompts`,"aria-keyshortcuts":Ux(u),placeholder:`Search prompts`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...zb,children:[(0,h.jsx)(VB,{"aria-label":`Prompt kind`,value:e,className:`w-full sm:w-56`,options:MB,onChange:e=>{let n=MB.find(t=>t.value===e.target.value);n!==void 0&&t(n.value)}}),(0,h.jsx)(U,{id:`library.prompt.kind`})]})]}),o.error===null?null:(0,h.jsx)(P4,{what:`prompts`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(N4,{label:`Prompts`}):null:S.length===0?(0,h.jsxs)(T1,{title:`No ${NB(e).toLowerCase()} prompts yet`,children:[`A prompt is text with `,`{{keywords}}`,`; each keyword becomes a field on Play.`]}):(0,h.jsx)(QK,{className:j4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${NB(e).toLowerCase()} prompts match "${s.trim()}".`}):(0,h.jsx)(PH,{label:`Prompts`,children:w.map(e=>(0,h.jsx)(FH,{className:M4,title:(0,h.jsx)(W4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:HSe(e),selected:e.id===T?.id,actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/prompts/$promptId`,params:{promptId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/prompts/new`,search:{kind:e.kind,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(O4,{item:`prompt`,id:T.id,name:T.name,kicker:`${NB(T.kind)} prompt`,meta:`Updated ${A4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(CS,{to:`/prompts/$promptId`,params:{promptId:T.id},size:`small`,children:`Edit prompt`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The prompt wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(w4,{item:`prompt`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(Hy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function HSe(e){return`${NB(e.kind)} · ${k4(e.slots.length,`keyword`)} · updated ${A4(e.updatedAt)}`}function USe({kind:e}){return(0,h.jsx)(CS,{to:`/prompts/new`,search:{kind:e},variant:`primary`,children:`New prompt`})}var WSe={template:`Template`,schedule:`Schedule`,draft:`Draft`,project:`Project`};function Z7(e){let t=[e.added.length>0?`${e.added.length} new`:null,e.priced.length>0?`${e.priced.length} repriced`:null,e.retired.length>0?`${e.retired.length} retired`:null].filter(e=>e!==null);return t.length===0?`No changes`:t.join(`, `)}function GSe(){let{api:e}=V(),t=_(),n=Ry(),r=I({queryKey:c1.catalogue,queryFn:()=>ufe(e),refetchInterval:3e4}),i=I({queryKey:c1.retired,queryFn:()=>d1(e)}),a=async()=>{await Promise.all([t.invalidateQueries({queryKey:[`provider-models`]}),t.invalidateQueries({queryKey:c1.retired})])},o=L({mutationFn:()=>dfe(e),onSuccess:async e=>{t.setQueryData(c1.catalogue,e),n(e.sync?.warning??`Model list checked: ${Z7(e.sync?.changes??KSe)}.`,e.sync?.warning?`error`:`success`),await a()}}),s=L({mutationFn:()=>ffe(e),onSuccess:async e=>{n(`Catalogue replaced with the published file.`,`success`),t.setQueryData(c1.catalogue,e),await a()}}),c=async()=>{await Promise.all([t.invalidateQueries({queryKey:c1.retired}),t.invalidateQueries({queryKey:iq}),t.invalidateQueries({queryKey:KV}),t.invalidateQueries({queryKey:[`play-drafts`]}),t.invalidateQueries({queryKey:[`projects`]}),t.invalidateQueries({queryKey:[`project`]})])},l=L({mutationFn:t=>f1(e,t),onSuccess:c}),u=L({mutationFn:()=>pfe(e),onSuccess:async e=>{n(e.failed.length===0?`Switched ${e.switched} ${e.switched===1?`use`:`uses`}.`:`Switched ${e.switched}; ${e.failed.length} could not be switched: ${e.failed[0]?.message??``}`,e.failed.length===0?`success`:`error`),await c()}}),d=r.data?.sync,f=i.data??[],p=f.filter(e=>e.blocked===null&&e.replacement!==null),m=o.error?.message??s.error?.message??r.error?.message??r.data?.warning??d?.warning??null;return jx({id:`settings.check-models`,title:`Check for new models`,group:`Settings`,context:`Models`,keywords:[`catalogue`,`prices`,`retired`],run:()=>{!o.isPending&&r.data?.path&&o.mutate()}}),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(W,{title:`Model catalogue`,info:`settings.models.catalogue`,children:[(0,h.jsx)(B,{disabled:o.isPending||!r.data?.path,onClick:()=>o.mutate(),children:o.isPending?`Checking…`:`Check now`}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,disabled:s.isPending||!r.data?.path,onClick:()=>s.mutate(),children:s.isPending?`Replacing…`:`Replace with published file`}),(0,h.jsx)(U,{id:`settings.models.replace`})]})]}),(0,h.jsxs)(`dl`,{className:`m-0 grid gap-x-6 border-t border-line text-small sm:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Catalogue file`}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 border-b border-line pb-3 break-all font-mono text-ink-2 sm:pt-3`,children:r.data?.path??`Not available`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Verified`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:r.data?.updatedAt??`date unavailable`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Last checked`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:d?.checkedAt?`${new Date(d.checkedAt).toLocaleString()} · ${Z7(d.changes)}`:`Not checked yet`})]}),d!==void 0&&d.changes.retired.length+d.changes.added.length>0?(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1 text-small text-ink-2`,children:[d.changes.added.length>0?(0,h.jsxs)(`span`,{children:[`New: `,d.changes.added.map(e=>e.name).join(`, `)]}):null,d.changes.retired.length>0?(0,h.jsxs)(`span`,{children:[`Retired: `,d.changes.retired.map(e=>e.name).join(`, `)]}):null]}):null,m===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-3 text-body text-danger`,children:m})]}),(0,h.jsxs)(`section`,{"aria-label":`Retired models in use`,children:[(0,h.jsx)(W,{title:`Retired models in use`,info:`settings.models.retired`,children:(0,h.jsx)(B,{variant:`primary`,disabled:u.isPending||p.length===0,onClick:()=>u.mutate(),children:u.isPending?`Switching…`:`Switch all`})}),i.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:i.error.message}):null,l.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:l.error.message}):null,f.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i.isPending?`Looking…`:`Nothing uses a retired model.`}):(0,h.jsx)(`ul`,{"aria-label":`Retired models in use`,className:`sl-list m-0 list-none p-0`,children:f.map(e=>(0,h.jsxs)(`li`,{className:`sl-row max-sm:grid-cols-1`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:WSe[e.kind]}),` `,(0,h.jsx)(`span`,{className:`font-semibold`,children:e.name})]}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[D1[e.slot],`: `,e.model,` (`,e.why===`retired`?`retired`:`no longer listed`,`)`]}),e.blocked===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e.blocked})]}),(0,h.jsx)(Iy,{children:(0,h.jsx)(B,{size:`small`,disabled:e.blocked!==null||e.replacement===null||l.isPending,onClick:()=>l.mutate(e),children:e.replacement===null?`No replacement`:`Switch to ${e.replacement.name}`})})]},e.key))})]})]})}var KSe={added:[],retired:[],priced:[]},qSe={ok:`Ready`,warning:`Check`,problem:`Needs fixing`,unused:`Not set up`},JSe={ok:`done`,warning:`waiting`,problem:`failed`,unused:`off`},YSe={ok:`text-ink-2`,warning:`text-waiting`,problem:`text-danger`,skipped:`text-ink-3`};function Q7(){let{api:e}=V();return L({mutationFn:()=>u1(e)})}function XSe(e){let{api:t}=V(),[n,r]=(0,m.useState)({byId:new Map});return{one:L({mutationFn:e=>u1(t,e),onSuccess:t=>{r(n=>{let r=new Map(n.after===e?n.byId:[]);for(let e of t.providers)r.set(e.id,e);return{after:e,byId:r}})}}),latest:t=>n.after===e?n.byId.get(t.id)??t:t}}function ZSe({run:e}={}){let t=Q7(),n=e??t,r=n.data,i=XSe(r?.checkedAt),a=r?.providers.filter(e=>e.state!==`unused`).map(i.latest)??[],o=r?.providers.filter(e=>e.state===`unused`)??[];return(0,h.jsxs)(`section`,{"aria-label":`Health check`,children:[(0,h.jsx)(W,{title:`Health check`,info:`settings.health`,children:e===void 0?(0,h.jsx)(B,{disabled:n.isPending,onClick:()=>{n.mutate()},children:n.isPending?`Checking…`:`Check all`}):void 0}),n.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:[`The health check didn't finish: `,n.error.message,` Press Check all to try again.`]}),i.one.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:`The check didn't finish: ${i.one.error.message} Press Check again on the provider to try again.`}),r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:n.isPending?`Checking every provider…`:`Not checked yet.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ul`,{"aria-label":`Health by provider`,className:`sl-list m-0 list-none p-0`,children:a.map(e=>(0,h.jsxs)(`li`,{className:`sl-row grid-cols-1 gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:e.displayName}),(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(OS,{tone:JSe[e.state],children:qSe[e.state]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Check ${e.displayName} again`,disabled:i.one.isPending,onClick:()=>{i.one.mutate(e.id)},children:i.one.isPending&&i.one.variables===e.id?`Checking…`:`Check again`})]})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-1 p-0`,children:e.checks.map(e=>(0,h.jsxs)(`li`,{className:z(`text-small`,YSe[e.state]),children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.label,`:`]}),` `,e.detail]},e.label))})]},e.id))}),(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:o.length===0?`Checked at ${new Date(r.checkedAt).toLocaleTimeString()}.`:`Not set up and not used anywhere: ${o.map(e=>e.displayName).join(`, `)}.`})]})]})}var $7={openrouter:`settings.provider.openrouter`,"claude-code":`settings.provider.claude-code`,codex:`settings.provider.codex`,gemini:`settings.provider.gemini`,elevenlabs:`settings.provider.elevenlabs`,"openai-tts":`settings.provider.openai-tts`,cartesia:`settings.provider.cartesia`,inworld:`settings.provider.inworld`,"system-voice":`settings.provider.system-voice`,"google-tts":`settings.provider.google-tts`,fal:`settings.provider.fal`,replicate:`settings.provider.replicate`,"openai-image":`settings.provider.openai-image`,"google-image":`settings.provider.google-image`,"codex-image":`settings.provider.codex-image`};function e9(e){return JP(e)?{tone:`done`,word:`Ready`}:e.installed?{tone:`waiting`,word:`Needs attention`}:{tone:`off`,word:`Not found`}}function QSe({provider:e,readiness:t,kind:n}){let{api:r}=V(),i=_(),a=(0,m.useId)(),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(!1),u=e.cliPath?.configured??null,d=e.cliPath?.managedOnHost===!0,f=e.id===`claude-code`?`claude`:e.id===`codex-image`?`codex`:e.id,p=e.cliPath?.command??f,g=o??u??``,v=JP(t),y=L({mutationFn:t=>qo(r,e.id,t),onMutate:()=>l(!1),onSuccess:async e=>{i.setQueryData(H.providers,t=>t?{...t,providers:t.providers.map(t=>t.id===e.id?e:t)}:void 0),s(void 0),l(!0),await i.invalidateQueries({queryKey:H.providers})}});(0,m.useEffect)(()=>{if(!c)return;let e=setTimeout(()=>l(!1),G2);return()=>clearTimeout(e)},[c]);let[b,x]=(0,m.useState)(!1),S=(0,m.useId)();return(0,h.jsxs)(`section`,{"aria-labelledby":a,"data-ready":v,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:a,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(U,{id:$7[e.id],label:e.displayName})]}),(0,h.jsxs)(`p`,{className:`sl-section-head__meta`,children:[n,` · command line, no key needed`]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(DS,{tone:e9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:$Se(t,u)})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Command`}),(0,h.jsx)(HB,{className:`min-w-0 truncate`,title:p,children:p})]})]}),(0,h.jsxs)(Iy,{children:[d?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-small text-ink-2`,children:[`Managed on host`,(0,h.jsx)(U,{id:`settings.cli.managed-on-host`})]}):(0,h.jsx)(B,{"aria-expanded":b,"aria-controls":S,onClick:()=>x(e=>!e),children:b?`Close path`:`Change path`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:c?(0,h.jsx)(q2,{}):null})]}),d||!b?null:(0,h.jsx)(`form`,{id:S,onSubmit:e=>{e.preventDefault(),y.isPending||y.mutate(g)},children:(0,h.jsx)(LB,{label:`Executable path`,tip:`settings.cli.path`,help:(0,h.jsxs)(h.Fragment,{children:[`Leave blank to find `,(0,h.jsx)(HB,{children:f}),` on PATH. Use an absolute path without quotes or arguments.`]}),error:y.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{autoComplete:`off`,spellCheck:!1,maxLength:4096,"aria-label":`${e.displayName} Executable path`,className:`min-w-0 flex-1 basis-[220px]`,placeholder:f,value:g,disabled:y.isPending,onChange:e=>{s(e.target.value),l(!1),y.reset()}}),(0,h.jsx)(B,{type:`submit`,variant:`primary`,"aria-label":`Save ${e.displayName} path`,disabled:y.isPending,children:y.isPending?`Checking…`:`Save path`})]})})})]})}function $Se(e,t){return e.issue===void 0?e.installed?e.version===void 0?`Installed`:`Installed, version ${e.version}`:t===null?`Not found on PATH`:`Not found at saved path`:e.issue}var eCe=[`providers`,`system-voice`,`voices`];async function tCe(e){return R(await e.fetch(`${e.origin}/api/providers/system-voice/voices`))}function t9(e=!0){let{api:t}=V();return I({queryKey:eCe,queryFn:()=>tCe(t),enabled:e})}function n9(e){return e.available?{tone:`done`,word:`Ready`}:{tone:`off`,word:`Not found`}}function nCe({provider:e,readiness:t}){let n=(0,m.useId)(),r=t9(t.available).data?.engines??[];return(0,h.jsxs)(`section`,{"aria-labelledby":n,"data-ready":t.available,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:n,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(U,{id:$7[e.id],label:e.displayName})]}),(0,h.jsx)(`p`,{className:`sl-section-head__meta`,children:`Speech · built into this computer, no key needed`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(DS,{tone:n9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:t.available?`Found ${t.engine??`a speech program`}. Narration with it is free; a keyed voice (ElevenLabs, OpenAI) sounds better.`:t.issue??`No speech program was found on this computer.`})]}),r.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 list-none p-0 text-small text-ink-2`,children:r.map(e=>{let t=e.voices.length;return(0,h.jsx)(`li`,{children:`${e.name}: ${t} voice${t===1?``:`s`}`},e.id)})}),t.available?(0,h.jsx)(Iy,{children:(0,h.jsx)(CS,{to:`/settings`,search:{section:`voices`},children:`Add a system voice`})}):null]})}function rCe({value:e,onPick:t}){let n=t9(),r=n.data?.engines??[];return n.data!==void 0&&r.length===0?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:n.data.issue??`No speech program was found on this computer.`}):(0,h.jsxs)(VB,{value:e,onChange:e=>{for(let n of r){let r=n.voices.find(t=>t.id===e.target.value);if(r!==void 0)return t(r)}},children:[(0,h.jsx)(`option`,{value:``,children:n.data===void 0?`Looking for voices…`:`Pick a voice`}),r.map(e=>(0,h.jsx)(`optgroup`,{label:e.name,children:e.voices.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.language===void 0?e.name:`${e.name} (${e.language})`},e.id))},e.id))]})}var r9=[`llm`,`tts`,`image`],i9={llm:`Text`,tts:`Speech`,image:`Images`},iCe=`••••••••••••`;function aCe(e){return JP(e.readiness)}function oCe(e){return e.readiness.kind===`cli`?e9(e.readiness):e.readiness.kind===`local`?n9(e.readiness):e.readiness.hasKey?{tone:`done`,word:`Key saved`}:{tone:`off`,word:`No key`}}function sCe(){let{api:e}=V(),t=I(db(e)),[n,r]=(0,m.useState)(void 0),i=(0,m.useRef)(null),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{n!==void 0&&a.current&&(a.current=!1,typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&i.current?.scrollIntoView?.({block:`start`,behavior:`smooth`}))},[n]);let o=r9.flatMap(e=>(t.data?.providers??[]).filter(t=>t.family===e)),s=o.find(e=>!aCe(e))??o[0];if(n===void 0&&s!==void 0&&r(s.id),t.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message});if(t.data===void 0)return(0,h.jsx)(lCe,{});let c=o.find(e=>e.id===n)??s,l=o.every(e=>e.readiness.kind!==`keyed`||!e.readiness.hasKey),u=e=>{a.current=!0,r(e)};return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:[l?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Paste a key to make its provider selectable on Play.`}):null,r9.map(e=>(0,h.jsxs)(`section`,{"data-tour":`keys-${e}`,"aria-labelledby":`keys-${e}-title`,className:`grid items-start gap-x-8 gap-y-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(W,{id:`keys-${e}-title`,title:i9[e],size:`small`,className:`pb-2`}),(0,h.jsx)(PH,{label:`${i9[e]} providers`,children:o.filter(t=>t.family===e).map(e=>{let t=oCe(e);return(0,h.jsx)(FH,{title:e.displayName,meta:e.readiness.kind===`cli`?`Command line`:e.readiness.kind===`local`?`Built in, no key`:`API key`,selected:e.id===c?.id,onSelect:()=>u(e.id),actions:(0,h.jsx)(OS,{tone:t.tone,children:t.word})},e.id)})})]}),c===void 0||c.family!==e?null:(0,h.jsx)(`div`,{ref:i,className:`min-w-0 scroll-mt-4`,children:c.readiness.kind===`cli`?(0,h.jsx)(QSe,{provider:c,readiness:c.readiness,kind:i9[c.family]},c.id):c.readiness.kind===`local`?(0,h.jsx)(nCe,{provider:c,readiness:c.readiness},c.id):(0,h.jsx)(cCe,{provider:c,hasKey:c.readiness.hasKey},c.id)})]},e))]})}function cCe({provider:e,hasKey:t}){let{api:n}=V(),r=_(),i=(0,m.useId)(),a=(0,m.useId)(),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(void 0),C=(0,m.useId)(),w=PF[e.id],T=o.trim(),E=async()=>{b(!0),S(void 0);try{S(await lfe(n,e.id,T===``?void 0:T))}catch(e){p(e instanceof Error?e.message:String(e))}finally{b(!1)}},D=async()=>{l(!0),p(void 0);try{await Ko(n,e.id,o),s(``),d(!0),S(void 0),await r.invalidateQueries({queryKey:H.providers})}catch(e){p(e instanceof Error?e.message:String(e))}finally{l(!1)}},O=L({mutationFn:()=>Jo(n,e.id),onSuccess:async()=>{v(!1),p(void 0),await r.invalidateQueries({queryKey:H.providers})},onError:e=>{v(!1),p(e.message)}});(0,m.useEffect)(()=>{if(!u)return;let e=setTimeout(()=>{d(!1)},G2);return()=>{clearTimeout(e)}},[u]);let k=[t?a:void 0,x===void 0?void 0:C].filter(e=>e!==void 0).join(` `);return(0,h.jsxs)(`section`,{"aria-labelledby":i,"data-ready":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(W,{as:`h3`,size:`default`,id:i,title:t?e.displayName:`Set up ${e.displayName}`,info:$7[e.id],infoLabel:e.displayName,meta:`${i9[e.family]} · ${t?`a key is saved`:`needs an API key`}`,className:`pb-0`}),w===void 0?null:t?(0,h.jsxs)(`details`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Where to get a key`}),(0,h.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:(0,h.jsx)(a9,{guide:w})})]}):(0,h.jsx)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:(0,h.jsx)(a9,{guide:w})}),(0,h.jsx)(LB,{label:`${e.displayName} API key`,tip:`settings.providers.api-key`,help:`Stored on this computer only. Never in backups or exports.`,error:f,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{type:`password`,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 basis-[200px]`,"aria-describedby":k===``?void 0:k,placeholder:t?iCe:`Paste API key`,value:o,onChange:e=>{s(e.target.value)}}),(0,h.jsx)(B,{variant:`primary`,"aria-label":`Save ${e.displayName} key`,disabled:o.trim()===``||c,onClick:()=>{D()},children:`Save`})]})}),t?(0,h.jsx)(`span`,{id:a,className:`sr-only`,children:`A key is stored for this provider.`}):null,x===void 0?null:(0,h.jsx)(`p`,{id:C,role:x.ok?`status`:`alert`,className:z(`m-0 text-small`,x.ok?`text-accent-ink`:`text-danger`),children:x.message}),(0,h.jsxs)(Iy,{children:[(0,h.jsx)(B,{"aria-label":`Test ${e.displayName} key`,disabled:!t&&T===``||y,disabledReason:`Paste a key first.`,onClick:()=>{E()},children:y?`Testing…`:`Test`}),(0,h.jsx)(U,{id:`settings.providers.test-key`,label:`Test`}),(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Remove ${e.displayName} key`,disabled:!t,onClick:()=>{v(!0)},children:`Remove`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:u?(0,h.jsx)(q2,{}):null})]}),(0,h.jsx)(Hy,{open:g,title:`Remove the ${e.displayName} key?`,consequence:`Projects that used this provider cannot retry until a key is saved.`,confirmLabel:`Remove key`,pending:O.isPending,onConfirm:()=>{O.mutate()},onCancel:()=>{v(!1)}})]})}function a9({guide:e}){let t=(e,t)=>(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`underline`,children:t});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ol`,{className:`m-0 list-decimal space-y-1 pl-5`,children:e.steps.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`Sign up: `,t(e.signUp.url,e.signUp.label),`. Make the key:`,` `,t(e.keyPage.url,e.keyPage.label),`.`,e.billing===void 0?null:(0,h.jsxs)(h.Fragment,{children:[` Credit: `,t(e.billing.url,e.billing.label),`.`]})]}),(0,h.jsx)(`p`,{className:`m-0`,children:e.permissions}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`More in the provider's `,t(e.docs.url,e.docs.label),`. After saving, choose Test.`]})]})}function lCe(){return(0,h.jsxs)(`div`,{className:`grid items-start gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,role:`status`,"aria-label":`Loading providers`,children:[(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:[[`llm`,4],[`tts`,5],[`image`,5]].map(([e,t])=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`span`,{className:`mb-2 block h-3 w-16 rounded-control bg-raised`}),(0,h.jsx)(`div`,{className:`sl-list`,children:Array.from({length:t},(t,n)=>`${e}-${n}`).map(e=>(0,h.jsxs)(`div`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`h-4 w-32 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-4 w-20 rounded-control bg-raised`})]},e))})]},e))}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-6 w-48 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-10 rounded-control bg-raised`})]})]})}function o9(e){return e.split(/[\s,;]+/).map(e=>e.trim().toLowerCase()).filter(e=>e!==``)}function uCe(e){return e.languages===void 0?`Any (not known)`:e.languages.map(e=>NO(e).code===e?NO(e).name:e).join(`, `)}function dCe({voice:e}){let{api:t}=V(),n=_(),r=(0,m.useId)(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)((e.languages??[]).join(`, `)),[c,l]=(0,m.useState)(void 0),u=L({mutationFn:()=>Os(t,e.id,o9(o)),onSuccess:async e=>{if(e!==void 0){l(e.message);return}a(!1),l(void 0),await n.invalidateQueries({queryKey:H.voices})}});return i?(0,h.jsxs)(`div`,{className:`grid gap-1`,children:[(0,h.jsx)(zB,{id:r,"aria-label":`Languages of ${e.name}`,value:o,placeholder:`es, de`,"aria-invalid":c!==void 0,onChange:e=>{s(e.target.value),l(void 0)}}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:c}),u.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:u.error.message}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(B,{size:`small`,disabled:u.isPending,onClick:()=>u.mutate(),children:`Save`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>{a(!1),l(void 0),s((e.languages??[]).join(`, `))},children:`Cancel`})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:uCe(e)}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Edit the languages of ${e.name}`,onClick:()=>a(!0),children:`Edit`})]})}function fCe(){let{api:e}=V(),t=_(),n=I(fb(e)),r=I(db(e)),[i,a]=(0,m.useState)(void 0),o=L({mutationFn:t=>As(e,t),onSettled:async()=>{a(void 0),await t.invalidateQueries({queryKey:H.voices})}}),s=L({mutationFn:({id:t,on:n})=>ks(e,t,n),onSettled:async()=>{await t.invalidateQueries({queryKey:H.voices})}}),c=(r.data?.providers??[]).filter(e=>e.family===`tts`);if(n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});let l=n.data?.voices;return(0,h.jsxs)(`div`,{"data-tour":`voices`,className:`flex min-w-0 flex-col gap-10`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 overflow-x-auto`,children:[(0,h.jsxs)(`table`,{className:`sl-table min-w-[640px] table-fixed`,...zb,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Voices`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:`Name`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[18%] pr-4`,children:`Provider`}),(0,h.jsx)(`th`,{scope:`col`,className:`pr-4`,children:`Voice ID`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Languages`,(0,h.jsx)(U,{id:`play.voices.languages`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[20%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Real person`,(0,h.jsx)(U,{id:`play.voices.real-person`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[96px]`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:l===void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,children:(0,h.jsx)(`span`,{className:`block h-4 w-64 rounded-control bg-raised`})})}):l.length===0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,className:`text-ink-2`,children:`Add a voice ID from your text-to-speech provider. Audio needs one to narrate.`})}):l.map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`truncate pr-4 font-semibold`,children:e.name}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:mCe(c,e.provider)}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:e.voiceId}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(dCe,{voice:e})}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(Bb,{checked:s.isPending&&s.variables.id===e.id?s.variables.on:e.imitatesRealPerson===!0,disabled:s.isPending,onChange:t=>s.mutate({id:e.id,on:t}),label:(0,h.jsx)(`span`,{className:`sr-only`,children:`${e.name} imitates a real person`}),className:`text-small`})}),(0,h.jsx)(`td`,{className:`text-right`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name}`,onClick:()=>{a(e)},children:`Remove`})})]},e.id))})]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:`Couldn't change Real person: ${s.error.message} Press the switch again.`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:o.error.message})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Add a voice`}),(0,h.jsx)(pCe,{tts:c})]}),(0,h.jsx)(Hy,{open:i!==void 0,title:i===void 0?``:`Remove ${i.name}?`,consequence:`Projects that used this voice keep the audio they made with it.`,confirmLabel:`Remove voice`,pending:o.isPending,onConfirm:()=>{i!==void 0&&o.mutate(i.id)},onCancel:()=>{a(void 0)}})]})}function pCe({tts:e}){let{api:t}=V(),n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(void 0),[d,f]=(0,m.useState)(void 0),p=l??e[0]?.id,g=L({mutationFn:e=>Ds(t,e),onSuccess:async e=>{if(!e.ok){f(e.refusal);return}i(``),o(``),c(``),f(void 0),await n.invalidateQueries({queryKey:H.voices})}}),v=(e,t)=>{t(),d?.field===e&&f(void 0)},y=e=>d?.field===e?d.message:void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`grid items-start gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(LB,{label:`Voice name`,tip:`play.voices.name`,error:y(`name`),children:(0,h.jsx)(zB,{value:r,onChange:e=>{let t=e.target.value;v(`name`,()=>{i(t)})}})}),(0,h.jsx)(LB,{label:`Provider`,tip:`play.voices.provider`,error:y(`provider`),children:(0,h.jsxs)(VB,{value:p??``,onChange:t=>{let n=e.find(e=>e.id===t.target.value);n!==void 0&&v(`provider`,()=>{u(n.id)})},children:[e.length===0?(0,h.jsx)(`option`,{value:``,children:`No speech provider`}):null,e.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.displayName},e.id))]})}),(0,h.jsx)(LB,{label:`Voice ID`,tip:`play.voices.voice-id`,error:y(`voiceId`),...p===`inworld`?{help:`Use an Inworld voice ID, such as Dennis, or one from your workspace.`}:{},children:p===`system-voice`?(0,h.jsx)(rCe,{value:a,onPick:e=>{v(`voiceId`,()=>{o(e.id)}),r.trim()===``&&i(e.name);let t=/^([a-z]{2,3})(?:[-_]|$)/i.exec(e.language??``)?.[1];s.trim()===``&&t!==void 0&&c(t.toLowerCase())}}):p===`google-tts`?(0,h.jsx)(VB,{value:a,options:[{value:``,label:`Pick a Gemini voice`},...IF.map(e=>({value:e.name,label:`${e.name} (${e.style})`}))],onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t),r.trim()===``&&i(t)})}}):(0,h.jsx)(zB,{className:`tabular-nums`,value:a,onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t)})}})}),(0,h.jsx)(LB,{label:`Languages`,tip:`play.voices.languages`,help:`Codes such as es, de.`,error:y(`languages`),children:(0,h.jsx)(zB,{value:s,placeholder:`es, de`,onChange:e=>{let t=e.target.value;v(`languages`,()=>{c(t)})}})}),(0,h.jsx)(B,{variant:`primary`,className:`md:mt-6`,disabled:p===void 0||d!==void 0||g.isPending,onClick:()=>{if(p!==void 0){let e=o9(s);g.mutate({provider:p,name:r,voiceId:a,...e.length===0?{}:{languages:e}})}},children:`Add voice`})]}),g.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:g.error.message})]})}function mCe(e,t){return e.find(e=>e.id===t)?.displayName??t}var s9=[`settings`,`notifications`],hCe=`The test notification couldn't be shown: this browser only allows notifications from installed apps. Set a Notification URL below instead.`;function gCe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Browser and phone`,info:`settings.notifications`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(_Ce,{}),(0,h.jsx)(vCe,{}),(0,h.jsx)(yCe,{})]})]})}function _Ce(){let e=(0,m.useSyncExternalStore)(dP,lP,()=>!1),[t,n]=(0,m.useState)(cP),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=Ry(),c=e&&t===`granted`;async function l(e){if(i(void 0),!e){uP(!1);return}o(!0);try{let e=await mP();n(e);let t=pP(e);e===`granted`?(uP(!0),lP()||i(`Browser notifications couldn't be turned on because this browser blocks site storage for Slopify. Allow site data for this address in your browser's settings, then turn Browser notifications on again.`)):i(t??`Browser notifications weren't turned on because the permission prompt was dismissed. Turn Browser notifications on again and choose Allow.`)}finally{o(!1)}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(Bb,{label:`Browser notifications`,tip:`settings.notifications.browser`,checked:c,disabled:a,onChange:e=>void l(e)}),(0,h.jsx)(B,{variant:`quiet`,disabled:!c,disabledReason:`Turn Browser notifications on first.`,onClick:()=>{i(void 0);try{gP({projectId:`test`,text:IP},()=>{}),s(`Test notification sent to this browser.`,`success`)}catch{i(hCe)}},children:`Send test notification`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Works while any Slopify tab is open.`}),r===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:r})]})}function vCe(){let e=(0,m.useSyncExternalStore)(CP,xP,()=>!0);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(Bb,{label:`Run sounds`,tip:`settings.notifications.sounds`,checked:e,onChange:SP}),(0,h.jsx)(B,{variant:`quiet`,onClick:()=>DP(`start`),children:`Play start`}),(0,h.jsx)(B,{variant:`quiet`,onClick:()=>DP(`end`),children:`Play end`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`A chime when a run starts and a different one when it finishes, fails or waits for you. Works while any Slopify tab is open; set your computer's volume for how loud.`})]})}function yCe(){let{api:e}=V(),t=_(),n=Ry(),r=(0,m.useId)(),i=I({queryKey:s9,queryFn:()=>Zo(e)}),[a,o]=(0,m.useState)(void 0),s=a??i.data?.url??``,c=RP(s),l=L({mutationFn:t=>$o(e,t),onSuccess:e=>{t.setQueryData(s9,e),o(void 0),n(e.url===null?`Notification URL removed.`:`Notification URL saved.`,`success`)}}),u=L({mutationFn:t=>es(e,t),onSuccess:()=>{n(`Test notification sent. Check the app or page behind your Notification URL.`,`success`)}}),d=c??l.error?.message??u.error?.message,f=l.isPending||u.isPending||i.data===void 0;return(0,h.jsxs)(LB,{label:`Notification URL`,tip:`settings.notifications.url`,help:`Works with no tab open, for example an ntfy topic on your phone.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{type:`url`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:`https://ntfy.sh/your-topic`,className:`min-w-0 flex-1 basis-[220px]`,value:s,disabled:i.data===void 0,"aria-invalid":c!==void 0,"aria-describedby":d===void 0?void 0:r,onChange:e=>{l.reset(),u.reset(),o(e.target.value)}}),(0,h.jsx)(B,{variant:`primary`,disabled:f||c!==void 0||a===void 0,onClick:()=>l.mutate(s),children:`Save`}),(0,h.jsx)(B,{variant:`quiet`,disabled:f||c!==void 0||s.trim()===``,onClick:()=>u.mutate(s),children:`Send test notification`})]}),i.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The saved Notification URL couldn't be read: `,i.error.message]}),d===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:d})]})}var c9={library:`The Library of Alexandria`,audiobook:`The Wind in the Willows (audiobook)`,podcast:`The Antikythera Mechanism (podcast)`};function bCe(){let{api:e}=V(),t=_(),n=I({queryKey:Wy,queryFn:()=>Qy(e)}),r=L({mutationFn:()=>eb(e),onSettled:async()=>{await t.invalidateQueries({queryKey:Wy}),await t.invalidateQueries({queryKey:Uy}),await t.invalidateQueries({queryKey:H.projects})}}),i=r.data?.samples??n.data?.samples;return(0,h.jsxs)(`div`,{className:`mt-8`,children:[(0,h.jsx)(W,{title:`Sample projects`,info:`settings.sample.restore`}),(0,h.jsx)(PH,{label:`Sample projects`,children:Object.keys(c9).map(e=>{let t=i?.[e]??null;return(0,h.jsx)(FH,{title:c9[e],meta:t===null?`Not in your projects`:`In your projects`,actions:t===null?void 0:(0,h.jsx)(wS,{to:`/projects/$projectId`,params:{projectId:t},className:NH,children:`Open`})},e)})}),(0,h.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(B,{disabled:r.isPending,onClick:()=>r.mutate(),children:r.isPending?`Restoring…`:`Restore samples`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Puts all three back as they shipped.`})]}),(0,h.jsx)(v1,{tone:r.error?`error`:`success`,children:r.error?.message??(r.isSuccess?`The samples are back in Projects.`:void 0)})]})}var xCe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function SCe(e){let[t,n,r]=e.split(`-`).map(Number),i=xCe[(n??0)-1];return i===void 0||r===void 0?e:`${String(r)} ${i} ${String(t)}`}function l9(e,t){let n=[e.range===void 0?e.version:`Versions ${e.range}`,`released ${SCe(e.date)}`].filter(e=>e!==void 0).join(`, `),r=n.charAt(0).toUpperCase()+n.slice(1);return e.version===t?`${r}. The version you are running.`:`${r}.`}function CCe({note:e,onNote:t}){let{api:n}=V(),r=I(tI(n));if(r.error!==null)return(0,h.jsx)(aI,{tone:`danger`,title:`The patch notes did not load`,actions:(0,h.jsx)(B,{onClick:()=>void r.refetch(),children:`Try again`}),children:`${r.error.message} Press Try again, or reload the page.`});if(r.data===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the patch notes…`});let{notes:i,version:a}=r.data,[o,...s]=i;if(o===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:`This version of Slopify has no patch notes.`});let c=e===void 0?void 0:i.find(t=>t.id===e),l=c!==void 0&&c.id!==o.id?c:void 0;return l===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e!==void 0&&c===void 0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`There are no patch notes called "${e}" in this version. The latest are below; older ones are under Earlier versions.`}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(W,{title:`Latest version`,meta:l9(o,a),info:`settings.patch-notes`}),(0,h.jsx)(Gz,{id:o.id})]}),s.length===0?null:(0,h.jsxs)(`details`,{className:`max-w-prose border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`Earlier versions (${String(s.length)})`}),(0,h.jsx)(PH,{label:`Earlier versions`,className:`mt-2`,children:s.map(e=>(0,h.jsx)(FH,{title:e.title,meta:l9(e,a),onSelect:()=>t(e.id),actions:(0,h.jsx)(B,{"aria-label":`Read ${e.title}`,onClick:()=>t(e.id),children:`Read`})},e.id))})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{children:(0,h.jsxs)(B,{variant:`quiet`,onClick:()=>t(void 0),children:[(0,h.jsx)(hc,{"aria-hidden":`true`,strokeWidth:1.75}),`Back to the latest patch notes`]})}),(0,h.jsx)(W,{title:`Earlier version`,meta:l9(l,a)}),(0,h.jsx)(Gz,{id:l.id})]})}var u9=[`trash`];async function wCe(e){return(await R(await e.client.trash.$get())).items}async function TCe(e,t,n){return(await R(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function ECe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await co(r)}var DCe={project:`Project`,prompt:`Prompt`,entry:`Intro/outro`,template:`Template`,schedule:`Schedule`};function OCe(e){return e.kind===`entry`&&e.detail!==null?e.detail===`intro`?`Intro`:`Outro`:e.kind===`prompt`&&e.detail!==null?`Prompt · ${e.detail}`:DCe[e.kind]}function kCe(e){return e<=0?`removed for good today`:e===1?`1 day left`:`${String(e)} days left`}var ACe=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}),jCe={project:[H.projects,[`calendar`]],prompt:[H.prompts],entry:[H.entries],template:[iq],schedule:[KV,[`calendar`]]};function MCe(){let{api:e}=V(),t=_(),n=Ry(),r=I({queryKey:u9,queryFn:()=>wCe(e)}),[i,a]=(0,m.useState)(void 0),o=async e=>{await Promise.all([u9,...jCe[e.kind]].map(e=>t.invalidateQueries({queryKey:e})))},s=L({mutationFn:t=>TCe(e,t.kind,t.id),onSuccess:async(e,t)=>{await o(t),n(e.renamedFrom===null?`Restored "${e.name}".`:`Restored as "${e.name}": another item is now called "${e.renamedFrom}".`,`success`),e.kind===`schedule`&&n(`The schedule is paused. Press Resume on Schedules to run it again.`,`info`)},onError:e=>n(e.message,`error`)}),c=L({mutationFn:t=>ECe(e,t.kind,t.id),onSuccess:async(e,t)=>{a(void 0),await o(t),n(`Deleted "${t.name}" for good.`,`success`)},onError:e=>{a(void 0),n(e.message,`error`)}}),l=r.data??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Trash`,info:`settings.trash`}),r.isPending?(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the trash…`}):r.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:r.error.message}):l.length===0?(0,h.jsx)(T1,{title:`The trash is empty`,children:`Anything you delete stays here for 30 days before it is removed for good.`}):(0,h.jsx)(PH,{label:`Deleted items`,children:l.map(e=>(0,h.jsx)(FH,{title:e.name,meta:`${OCe(e)} · deleted ${ACe.format(new Date(e.deletedAt))} · ${kCe(e.daysLeft)}`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>s.mutate(e),children:`Restore`}),(0,h.jsx)(B,{size:`small`,variant:`destructive`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>a(e),children:`Delete now`})]})},`${e.kind}:${e.id}`))}),(0,h.jsx)(Hy,{open:i!==void 0,title:i===void 0?``:`Delete "${i.name}" for good?`,consequence:i?.kind===`project`?`The project and every file it produced are removed from disk. This cannot be undone.`:i?.kind===`schedule`?`The schedule leaves the trash and cannot be restored. Its run history stays on Schedules.`:`It is removed for good. This cannot be undone.`,confirmLabel:`Delete for good`,cancelLabel:`Keep it`,pending:c.isPending,onConfirm:()=>{i!==void 0&&c.mutate(i)},onCancel:()=>{c.isPending||a(void 0)}})]})}var NCe=`https://github.com/GentBajko/slopify`,PCe=`https://www.patreon.com/cw/GentBajko`,FCe=`https://buymeacoffee.com/gentbajko`;function ICe(){return[{href:NCe,label:`GitHub`,detail:`The code, issues and releases.`,glyph:`github`},{href:PCe,label:`Patreon`,detail:`Monthly support for the project.`,glyph:`patreon`},{href:FCe,label:`Buy Me a Coffee`,detail:`A one-off thank you.`,glyph:`coffee`},{href:`https://slopify.stream/channel.html`,label:`How I run a channel with it`,detail:`A lore channel run on Slopify, start to finish.`}]}function LCe({onWhatsNew:e}){return(0,h.jsxs)(`div`,{className:`max-w-prose`,children:[(0,h.jsx)(W,{title:`About`}),(0,h.jsx)(`p`,{className:`m-0 mb-3 text-ink-2`,children:`Slopify is free and open source, and runs on your machine with your own keys. If it saves you time, you can support it here.`}),(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1 text-small text-ink-2`,children:[`Updates: the circular-arrows button at the foot of the sidebar (at the top on a phone).`,(0,h.jsx)(U,{id:`settings.updates`})]}),e===void 0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1`,children:[(0,h.jsx)(B,{onClick:e,children:`What's new in this version`}),(0,h.jsx)(U,{id:`settings.whats-new`})]}),(0,h.jsx)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:`Made by Gent Bajko. Apache License 2.0: anyone who redistributes Slopify or builds on it keeps this credit.`}),(0,h.jsx)(`ul`,{"aria-label":`Links`,className:`sl-list m-0 list-none p-0`,children:ICe().map(e=>(0,h.jsx)(`li`,{className:`sl-row`,children:(0,h.jsxs)(`div`,{className:`sl-row__lead`,children:[e.glyph===void 0?(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}):(0,h.jsx)(bS,{name:e.glyph,className:`shrink-0 text-ink-2`}),(0,h.jsxs)(`div`,{className:`sl-row__text`,children:[(0,h.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,className:`font-semibold text-ink underline underline-offset-3`,children:e.label}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.detail})]})]})},e.label))})]})}var d9=[`backups`],f9=1,p9=30;function m9(){return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}function RCe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=f9&&Number(t)<=p9?void 0:`Keep between ${f9} and ${p9} backups.`}function zCe(e){return{enabled:e.config.enabled,time:e.config.time,keep:String(e.config.keep),folder:e.config.folder??``}}function h9(){let{api:e}=V(),t=_(),n=Ry();return L({mutationFn:()=>Eo(e),onSuccess:e=>{t.setQueryData(d9,e),n(`Backup started. Its result shows here when it finishes.`,`success`)}})}function BCe(){let{api:e}=V(),t=_(),n=I({queryKey:d9,queryFn:()=>wo(e),refetchInterval:e=>e.state.data?.running===!0&&2e3}),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=L({mutationFn:t=>To(e,t),onSuccess:e=>{t.setQueryData(d9,e),i(void 0),o(!0)}}),c=h9();(0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>o(!1),G2);return()=>clearTimeout(e)},[a]);let l=n.data,u=r??(l===void 0?void 0:zCe(l)),d=u===void 0?void 0:RCe(u.keep),f=e=>{u!==void 0&&i({...u,...e})};return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Daily backup`,info:`settings.backups`,children:(0,h.jsx)(B,{variant:`primary`,disabled:l===void 0||l.running||c.isPending,onClick:()=>c.mutate(),children:`Back up now`})}),(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-x-4 gap-y-1 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{role:`status`,children:l===void 0?(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`}):VCe(l)}),(0,h.jsx)(`span`,{children:l===void 0?null:HCe(l)})]}),l?.status.detail?l.status.lastResult===`failed`?(0,h.jsx)(aI,{tone:`danger`,title:`Why the last backup stopped`,children:l.status.detail}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:l.status.detail}):null,c.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:c.error.message}):null]}),n.error?(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The backup settings couldn't be read: `,n.error.message]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(Bb,{label:`Back up automatically`,tip:`settings.backups.auto`,checked:u?.enabled===!0,disabled:u===void 0,className:`self-start`,onChange:e=>f({enabled:e})}),(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Time of day`,tip:`settings.backups.time`,help:`${m9()} time`,children:(0,h.jsx)(zB,{type:`time`,className:`w-[140px] tabular-nums`,value:u?.time??`03:00`,disabled:u===void 0,onChange:e=>f({time:e.target.value})})}),(0,h.jsx)(LB,{label:`Keep last`,tip:`settings.backups.keep`,help:`Backups kept in the folder.`,error:d,children:(0,h.jsx)(zB,{type:`number`,inputMode:`numeric`,min:f9,max:p9,step:1,className:`w-[88px] tabular-nums`,value:u?.keep??`5`,disabled:u===void 0,onChange:e=>f({keep:e.target.value})})}),(0,h.jsx)(LB,{label:`Folder`,tip:`settings.backups.folder`,className:`md:col-span-2`,...l===void 0?{}:{help:UCe(l)},children:(0,h.jsx)(zB,{value:u?.folder??``,placeholder:l?.defaultFolder??``,disabled:u===void 0,onChange:e=>f({folder:e.target.value})})})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{variant:`primary`,disabled:u===void 0||d!==void 0||s.isPending,onClick:()=>{u!==void 0&&(o(!1),s.mutate({enabled:u.enabled,time:u.time,timeZone:m9(),keep:Number(u.keep.trim()),folder:u.folder.trim()===``?null:u.folder.trim()}))},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(q2,{}):null}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 basis-full text-small text-danger`,children:s.error.message})]})]})]})}function g9(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function VCe(e){if(e.running)return`Backing up now…`;let{status:t}=e,n=t.lastSuccessAt===null?`No backup yet.`:`Last backup ${g9(t.lastSuccessAt)}${t.lastSuccessBytes===null?``:`, ${_9(t.lastSuccessBytes)}`}.`;return t.lastResult===`failed`&&t.lastAttemptAt!==null?`${n} The backup at ${g9(t.lastAttemptAt)} failed.`:t.lastResult===`waiting`?`${n} Waiting for projects to finish.`:n}function HCe(e){return e.config.enabled?e.overdue?`Next: shortly.`:e.nextRunAt===null?``:`Next: ${g9(e.nextRunAt)}.`:`Automatic backups are off.`}function UCe(e){let t=`${e.files.length} backup${e.files.length===1?``:`s`} here (${_9(e.files.reduce((e,t)=>e+t.bytes,0))}).`;return e.hostFolder===null?`Inside Slopify's Docker volume, not on your computer. Leave Folder empty to save backups in the Backups folder on your computer. ${t}`:`${e.config.folder===null?`Empty uses the default: `:`On your computer: `}${e.hostFolder}. ${t}`}function _9(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var v9=[`storage-files`];function WCe({usageQueryKey:e}){let{api:t}=V(),n=_(),r=Ry(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(),u=I({queryKey:v9,queryFn:()=>Po(t),refetchInterval:e=>b9(e.state.data)?1e3:!1}),d=L({mutationFn:e=>Fo(t,e),onMutate:()=>l(void 0),onSuccess:e=>{n.setQueryData(v9,e),a(!1)},onError:e=>l(e.message)}),f=L({mutationFn:()=>Io(t),onSuccess:e=>{e.opened||r(`Your files are in ${e.path}.`,`info`)},onError:e=>r(e.message,`error`)}),p=u.data,g=b9(p),v=p?.move?.phase;if((0,m.useEffect)(()=>{v===`done`&&n.invalidateQueries({queryKey:e})},[v,n,e]),p===void 0)return(0,h.jsx)(`div`,{children:(0,h.jsx)(W,{title:`Your files`,meta:u.error?`Where your files are is unavailable. Reload the page to try again.`:`Loading…`})});if(p.docker)return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Your files`,meta:p.folder??`The Docker project folder isn't set up.`,info:`settings.files.docker`,children:(0,h.jsx)(B,{disabled:p.folder===null||f.isPending,onClick:()=>f.mutate(),children:`Open folder`})}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),p.dockerCommand===null?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[`To move your projects to Documents/Slopify, run this on the computer running Docker (or use `,(0,h.jsx)(HB,{children:`--projects-dir <folder>`}),` for another folder):`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(HB,{className:`min-w-0 break-all`,children:p.dockerCommand}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>{let e=p.dockerCommand??``;navigator.clipboard.writeText(e).then(()=>r(`Command copied.`,`success`)).catch(()=>r(`Copying failed: this browser doesn't allow it here. Select the command and copy it yourself.`,`error`))},children:`Copy command`})]})]})]})]});let y=v===`failed`||v===`interrupted`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(W,{title:`Your files`,meta:p.folder,info:`settings.files`,children:[p.inDocuments||p.documentsRoot===null?null:(0,h.jsx)(B,{variant:`primary`,disabled:g||d.isPending,onClick:()=>d.mutate(`documents`),children:`Move to Documents/Slopify`}),(0,h.jsx)(B,{disabled:f.isPending,onClick:()=>f.mutate(),children:`Open folder`}),(0,h.jsx)(B,{variant:`quiet`,disabled:g||d.isPending,onClick:()=>{a(e=>!e),l(void 0)},children:`Choose another folder`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),i?(0,h.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),d.mutate(o)},children:[(0,h.jsx)(LB,{label:`New folder`,tip:`settings.files.new-folder`,help:`The full path; it must be empty or new.`,error:c,className:`min-w-0 flex-1 basis-80`,children:(0,h.jsx)(zB,{value:o,placeholder:p.documentsRoot??`/home/you/Videos/Slopify`,onChange:e=>s(e.target.value)})}),(0,h.jsx)(B,{type:`submit`,disabled:o.trim()===``||d.isPending,children:`Move here`})]}):c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:c}),p.move===null?null:g?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[p.move.phase===`copying`?`Copying`:`Checking the copy of`,` your files to`,` `,p.move.target,`: `,p.move.files,` of `,p.move.totalFiles,` files (`,Y5(p.move.bytes),` of `,Y5(p.move.totalBytes),`). Keep Slopify running until it finishes.`]}),(0,h.jsx)(C2,{label:p.move.phase===`copying`?`Files copied`:`Files checked`,value:p.move.totalBytes===0?0:p.move.bytes/p.move.totalBytes})]}):y?(0,h.jsx)(aI,{tone:v===`failed`?`danger`:`waiting`,title:v===`failed`?`Moving your files to ${p.move.target} stopped`:`Moving your files to ${p.move.target} didn't finish`,actions:(0,h.jsx)(B,{disabled:d.isPending,onClick:()=>d.mutate(p.move?.target??``),children:`Continue moving`}),children:p.move.error??`Slopify was stopped before the copy was checked, so it still uses the old folder. Continue moving picks up where it left off.`}):v===`done`&&p.move.oldFolder!==null?(0,h.jsxs)(aI,{tone:`info`,title:`Your files are now in ${p.move.target}`,children:[`Every file was copied and checked. The old folder `,p.move.oldFolder,` still has a copy; once your projects open fine, you can delete it to free the space.`]}):null]})]})}function y9({view:e}){let t=[[`Projects`,e.projects],[`Automatic backups`,e.backups],[`Exports`,e.exports]].filter(e=>e[1]!==null);return(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1`,children:t.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-3`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-all`,children:t})]},e))})}function b9(e){return e?.move?.phase===`copying`||e?.move?.phase===`verifying`}function GCe(){let{api:e}=V(),t=I(ub(e));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[t.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message}),t.data===void 0?t.error===null?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(QCe,{cells:5}),(0,h.jsx)($Ce,{})]}):null:(0,h.jsx)(qCe,{usage:t.data})]})}var KCe=[{id:`stage`,header:`Stage`,cell:e=>YP[e.stage]},{id:`model`,header:`Provider · model`,cell:e=>JCe(e)},{id:`in`,header:`Tokens in`,numeric:!0,cell:e=>x9.format(e.tokensIn)},{id:`out`,header:`Tokens out`,numeric:!0,cell:e=>x9.format(e.tokensOut)}];function qCe({usage:e}){let t=Object.values(e.counters).every(e=>e===0);return(0,h.jsxs)(b1,{split:`even`,children:[(0,h.jsxs)(x1,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(x2,{children:ZCe(e).map(e=>(0,h.jsx)(S2,{label:e.label,value:e.value},e.label))}),t?(0,h.jsx)(`p`,{className:`m-0 mt-3 text-body text-ink-2`,children:`Numbers appear after your first run.`}):null]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Machine ID ${e.machineId??`not made yet`} · Slopify ${e.appVersion}`})]}),(0,h.jsx)(x1,{children:(0,h.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Tokens by stage`,columns:KCe,rows:e.byStage,rowKey:e=>`${e.stage}/${e.provider}/${e.model??``}`,empty:`No stages have run yet.`,className:`min-w-[480px] [&_td]:pr-4 [&_th]:pr-4`})})})]})}function JCe(e){return e.model===null?e.provider:`${e.provider} · ${e.model}`}var x9=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),YCe=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),XCe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function ZCe(e){let t=e.counters;return[{label:`Videos made`,value:x9.format(t.videosMade)},{label:`Hours of audio`,value:YCe.format(t.audioSeconds/3600)},{label:`Images made`,value:x9.format(t.imagesMade)},{label:`Tokens used`,value:t.tokensUsed<1e6?x9.format(t.tokensUsed):XCe.format(t.tokensUsed)},{label:`Projects`,value:x9.format(t.projects)}]}function QCe({cells:e}){return(0,h.jsx)(`div`,{className:`sl-stats`,children:Array.from({length:e},(e,t)=>t).map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-8 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`})]},e))})}function $Ce(){return(0,h.jsx)(`div`,{className:`border-t border-line`,children:[0,1,2,3].map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-4 border-b border-line py-3`,children:[(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 max-w-[40%] rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`ml-auto h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`})]},e))})}var S9=[`storage-usage`],ewe=[S9,H.projects,[`project`],H.usage,H.documentThemes,KV,[`play-drafts`],H.settings,H.providers,H.voices,H.prompts,H.entries,H.staging,iq,eN,[`provider-models`]];async function twe(e){await Promise.all(ewe.map(t=>e.invalidateQueries({queryKey:t})))}var C9=30,nwe=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function rwe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=0&&Number(t)<=C9?void 0:`The silence gap is a whole number of seconds between 0 and ${String(C9)}.`}var w9=[{id:`general`,label:`General`,meta:`How Slopify starts on this computer.`},{id:`providers`,label:`Providers`,meta:`Keys stay on this machine and go only to their provider. Readiness is checked again before each run.`},{id:`voices`,label:`Voices`,meta:`A wrong voice ID shows up when the audio stage uses it.`},{id:`models`,label:`Models`,meta:`New models, prices and retirements, checked once a day.`},{id:`playback`,label:`Playback & appearance`,meta:`How narration is paced and how Slopify looks.`},{id:`notifications`,label:`Notifications`,meta:`When a run finishes, fails, waits for you, or a review needs a decision.`},{id:`channel-links`,label:`Channel links`,meta:`The links a YouTube description's {{Name}} placeholders fill from.`},{id:`studio`,label:`YouTube Studio`,meta:`The playlist upload packs name, and the Studio extension's pairing.`},{id:`storage`,label:`Backup & storage`,meta:`Export everything, import a backup, and see what uses disk space.`},{id:`backups`,label:`Backups`,meta:`A daily copy of everything, in a folder you choose.`},{id:`trash`,label:`Trash`,meta:`Deleted projects, prompts, templates and schedules, kept for 30 days.`},{id:`usage`,label:`Usage`,meta:`This machine only. The same counters, anonymised, feed slopify.stream.`},{id:`patch-notes`,label:`Patch notes`,meta:`What changed in each version of Slopify.`},{id:`about`,label:`About`,meta:`Free and open source, running on your machine with your own keys.`}];function iwe(e){return w9.find(t=>t.id===e)?.id??`providers`}function awe(e){let t=document.createElement(`a`);t.href=`${e}/api/diagnostics`,t.download=`slopify-diagnostics.json`,document.body.append(t),t.click(),t.remove()}function owe({section:e=`providers`,note:t,onSection:n=()=>{},onNote:r=()=>{}}){let{api:i}=V(),a=_(),o=Ry(),s=Q7(),c=h9(),l=w9.find(t=>t.id===e)??w9[0];return jx({id:`settings.check-providers`,title:`Check all providers`,group:`Settings`,keywords:[`health`,`keys`,`signed in`],run:()=>{n(`providers`),s.mutate()}}),jx({id:`settings.back-up-now`,title:`Back up now`,group:`Settings`,keywords:[`backup`],run:()=>{n(`backups`),c.mutate(void 0,{onError:e=>{o(`The backup didn't start: ${e.message} Open Settings → Backups to see its state.`,`error`)}})}}),jx({id:`settings.download-diagnostics`,title:`Download diagnostics`,group:`Settings`,keywords:[`support`,`bug report`],run:()=>{awe(i.origin)}}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:`Settings`,title:l.label,meta:l.meta,actions:(0,h.jsxs)(h.Fragment,{children:[e===`providers`?(0,h.jsx)(B,{disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check all`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(TS,{variant:`secondary`,href:`${i.origin}/api/diagnostics`,download:`slopify-diagnostics.json`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download diagnostics`]}),(0,h.jsx)(U,{id:`settings.diagnostics`})]})]})}),(0,h.jsx)(ZK,{sections:(0,h.jsx)(X6,{label:`Settings sections`,children:w9.map(t=>(0,h.jsx)(Z6,{current:t.id===e,onClick:()=>n(t.id),className:`whitespace-nowrap max-md:w-auto`,children:t.label},t.id))}),children:(0,h.jsxs)(`section`,{"aria-label":l.label,className:`flex min-w-0 flex-col gap-10`,children:[e===`providers`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(I3,{}),(0,h.jsx)(sCe,{}),(0,h.jsx)(ZSe,{run:s})]}):null,e===`general`?(0,h.jsx)(Xb,{}):null,e===`voices`?(0,h.jsx)(fCe,{}):null,e===`models`?(0,h.jsx)(GSe,{}):null,e===`playback`?(0,h.jsx)(uwe,{}):null,e===`notifications`?(0,h.jsx)(gCe,{}):null,e===`channel-links`?(0,h.jsx)(cme,{}):null,e===`studio`?(0,h.jsx)(zpe,{}):null,e===`storage`?(0,h.jsx)(WCe,{usageQueryKey:S9}):null,e===`storage`?(0,h.jsx)(swe,{}):null,e===`storage`?(0,h.jsx)(bCe,{}):null,e===`backups`?(0,h.jsx)(BCe,{}):null,e===`trash`?(0,h.jsx)(MCe,{}):null,e===`usage`?(0,h.jsx)(GCe,{}):null,e===`patch-notes`?(0,h.jsx)(CCe,{note:t,onNote:r}):null,e===`about`?(0,h.jsx)(LCe,{onWhatsNew:()=>{a.fetchQuery(tI(i)).then(e=>r(e.current??void 0),e=>{o(`The patch notes did not open: ${e instanceof Error?e.message:String(e)} Open Settings → Patch notes to try again.`,`error`)})}}):null]})})]})}var T9=`The backup wasn't imported. Check it is a file made with Export everything (.tar) or Export backup (.zip), then try again.`;function swe(){let{api:e}=V(),t=_(),n=I({queryKey:S9,queryFn:()=>No(e),staleTime:3e4}),[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)({phase:`idle`}),[s,c]=(0,m.useState)({phase:`idle`}),[l,u]=(0,m.useState)(null),d=Ry(),[f,p]=(0,m.useState)(null);async function g(){p(null),o({phase:`preparing`});try{let t=await Co(e);if(!t.ready){o({phase:`idle`}),p(t.detail??`The backup can't be made right now. Try again in a moment.`);return}o({phase:`downloading`,bytes:t.bytes??0,projects:t.projects??0});let n=document.createElement(`a`);n.href=`${e.origin}/api/storage/export`,n.download=``,document.body.append(n),n.click(),n.remove()}catch(e){o({phase:`idle`}),p(e instanceof Error?e.message:`The backup couldn't be prepared. Try again in a moment.`)}}async function v(n){let r=n.name.toLowerCase().endsWith(`.zip`)||n.type===`application/zip`;if(n.size===0||r&&n.size>104857600){p(r?`This file is empty or larger than 100 MB. Choose a .zip made with Export backup, or a .tar made with Export everything.`:`This file is empty. Choose the .tar made with Export everything.`);return}i(!0),p(null),u(null),c({phase:`uploading`,sent:0,total:n.size});try{let i=await e.upload(`${e.origin}/api/storage/import`,n,r?`application/zip`:`application/x-tar`,(e,t)=>{c(e>=t?{phase:`importing`}:{phase:`uploading`,sent:e,total:t})}),a=await i.json();if(!i.ok)throw Error(a.detail??T9);a.projects===void 0?d(`Imported ${a.templates??0} template(s), ${a.fonts??0} uploaded font(s), and ${a.stagedFiles??0} staged file(s).${a.fontFallbacks?` ${a.fontFallbacks} missing legacy font reference(s) now use the default font.`:``}`,`success`):(u(a),d(`Backup imported.`,`success`)),await twe(t)}catch(e){p(e instanceof Error?e.message:T9)}finally{c({phase:`idle`}),i(!1)}}async function y(){i(!0),p(null);try{let n=await e.fetch(`${e.origin}/api/storage/cleanup`,{method:`POST`}),r=await n.json();if(!n.ok)throw Error(`Clean orphan files didn't finish. Try again in a moment.`);d(`Removed ${r.orphanFiles??0} orphan project file(s) and ${r.stagedFiles??0} stale staged file(s).`,`success`),await t.invalidateQueries({queryKey:S9})}catch(e){p(e instanceof Error?e.message:`Clean orphan files didn't finish. Try again in a moment.`)}finally{i(!1)}}jx({id:`settings.export-everything`,title:`Export everything`,group:`Settings`,context:`Backup & storage`,keywords:[`backup`,`download`],run:()=>{!r&&a.phase!==`preparing`&&g()}});let b=r||a.phase===`preparing`,x=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(W,{title:`Export and import`,info:`settings.storage.export`,children:[(0,h.jsx)(B,{disabled:b,onClick:()=>void g(),children:`Export everything`}),(0,h.jsx)(B,{disabled:b,onClick:()=>x.current?.click(),children:`Import a backup`}),(0,h.jsx)(`input`,{ref:x,className:`sr-only`,type:`file`,tabIndex:-1,"aria-label":`Import a backup`,accept:`.tar,application/x-tar,.zip,application/zip`,disabled:b,onChange:e=>{let t=e.target.files?.[0];t&&v(t),e.target.value=``}}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,disabled:b,onClick:()=>void y(),children:`Clean orphan files`}),(0,h.jsx)(U,{id:`settings.storage.clean`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Provider keys are never included in a backup. After importing, enter them again in Settings → Providers.`}),a.phase===`preparing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Preparing the backup…`}):null,a.phase===`downloading`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 min-w-0 flex-1 text-ink`,children:[`Downloading `,Y5(a.bytes),` (`,a.projects,` project`,a.projects===1?``:`s`,`). Your browser's downloads show its progress; keep Slopify running until it finishes.`]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>o({phase:`idle`}),children:`Dismiss`})]}):null,s.phase===`uploading`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[`Uploading the backup: `,Y5(s.sent),` of`,` `,Y5(s.total)]}),(0,h.jsx)(C2,{label:`Backup upload`,value:s.total===0?0:s.sent/s.total})]}):null,s.phase===`importing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Checking and importing the backup… large projects can take a minute.`}):null,f?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:f}):null]})]}),l?(0,h.jsx)(lwe,{result:l,onDismiss:()=>u(null)}):null,(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Disk space`,info:`settings.storage.disk`,meta:n.data?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`font-semibold text-ink`,children:[Y5(n.data.data),` stored`]}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[` `,`· `,Y5(Math.max(0,n.data.projects-n.data.trash.bytes)),` project files · `,Y5(n.data.staging),` staged files`,n.data.trash.projects>0?` · ${Y5(n.data.trash.bytes)} in the trash (${cwe(n.data.trash.projects)}), freed when removed for good`:null]})]}):n.error?`Storage usage is unavailable. Reload the page to try again.`:(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`})}),n.data&&n.data.byProject.length>0?(0,h.jsx)(kbe,{projects:n.data.byProject,queryKey:[...S9]}):null]})]})}function cwe(e){return e===1?`1 deleted project`:`${String(e)} deleted projects`}function E9(e,t){if(t===void 0)return null;let n=[t.added>0?`${t.added} added`:null,t.renamed>0?`${t.renamed} added as “(imported)” because the name was taken`:null,t.skipped>0?`${t.skipped} already here`:null].filter(e=>e!==null);return n.length===0?null:`${e}: ${n.join(`, `)}.`}function lwe({result:e,onDismiss:t}){let n=[e.projects.imported.length>0?`Projects: ${e.projects.imported.length} added (${Y5(e.files.bytes)} of files).`:`Projects: none added.`,E9(`Prompts`,e.prompts),E9(`Intros and outros`,e.entries),E9(`Channels`,e.channels),E9(`Cast members`,e.cast),E9(`Episode memories`,e.episodeMemories),E9(`Existing videos`,e.channelVideos),E9(`Document themes`,e.documentThemes),E9(`Templates`,e.templates),E9(`Schedules`,e.schedules),e.schedules.paused>0?`${e.schedules.paused} schedule(s) arrived paused so two installs never run them both; resume them on the Schedules screen.`:null,E9(`Voices`,e.voices),E9(`Play drafts`,e.drafts),e.settings.added+e.settings.kept>0?`Settings: ${e.settings.added} filled in${e.settings.kept>0?`, ${e.settings.kept} kept as this install has them`:``}.`:null,e.fonts>0?`Uploaded fonts: ${e.fonts} added.`:null,e.usage.alreadyImported?`Usage: this backup's history was already added before, so it wasn't counted twice.`:`Usage: ${e.usage.events} recorded event(s) added to the totals.`,`Provider keys are not in backups: enter them in Settings → Providers.`].filter(e=>e!==null);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{as:`h3`,title:`Imported the backup from ${e.backup.createdAt.slice(0,10)}`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:t,children:`Dismiss`})}),(0,h.jsxs)(`ul`,{"aria-label":`Import result`,className:`m-0 list-disc pl-5 text-small text-ink-2`,children:[n.map(e=>(0,h.jsx)(`li`,{className:`py-0.5`,children:e},e)),e.projects.skipped.map(e=>(0,h.jsxs)(`li`,{className:`py-0.5`,children:[`Skipped “`,e.title,`”: `,e.reason]},e.id))]})]})}function uwe(){let{api:e}=V(),t=_(),n=I(_b(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=L({mutationFn:t=>Xo(e,t),onMutate:e=>{let n=t.getQueryData(H.settings);return t.setQueryData(H.settings,e),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(H.settings,r.previous)},onSuccess:e=>{t.setQueryData(H.settings,e)}});if((0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>{o(!1)},G2);return()=>{clearTimeout(e)}},[a]),n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});if(n.data===void 0)return(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,role:`status`,"aria-label":`Loading settings`,children:[(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`})]});let c=n.data,l=r??String(c.silenceGapSeconds),u=rwe(l);return(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Silence between segments`,tip:`settings.playback.silence-gap`,help:`Seconds of quiet between narrated segments.`,error:u??s.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{type:`number`,inputMode:`numeric`,min:0,max:C9,step:1,className:`w-[88px] tabular-nums`,value:l,"aria-invalid":u!==void 0,onChange:e=>{i(e.target.value)}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`seconds`}),(0,h.jsx)(B,{variant:`primary`,disabled:u!==void 0||s.isPending,onClick:()=>{o(!1),s.mutate({...c,silenceGapSeconds:Number(l.trim())},{onSuccess:()=>{i(void 0),o(!0)}})},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(q2,{}):null})]})}),(0,h.jsxs)(`div`,{className:`sl-field`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Appearance`}),(0,h.jsx)(U,{id:`settings.appearance`,className:`-my-1`})]}),(0,h.jsx)(Vb,{label:`Appearance`,value:c.appearance,options:nwe,className:`self-start`,onChange:e=>{s.mutate({...c,appearance:e})}})]}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(T6,{value:c.loudness??JO,switchLabel:`Level the volume for new runs`,switchTip:`settings.loudness`,onChange:e=>{s.mutate({...c,loudness:e})}})})]})}function dwe({open:e,onClose:t,onInstalled:n}){let{api:r}=V(),i=_(),a=I({queryKey:Uy,queryFn:()=>qy(r),enabled:e}),o=L({mutationFn:e=>Yy(r,e),onSuccess:()=>n(),onSettled:()=>i.invalidateQueries({queryKey:Uy})});return(0,h.jsxs)(HP,{open:e,title:`Add a starter pack`,onClose:t,footer:(0,h.jsx)(v1,{tone:o.error||a.error?`error`:`success`,children:o.error?.message??a.error?.message??(o.data===void 0?void 0:o.data.added?`Added: its prompts are in Prompts and its template is in this list.`:`That pack was already added.`)}),children:[(0,h.jsxs)(`p`,{className:`mb-4 flex items-center gap-1 text-small text-ink-2`,children:[`Prompts, a suggested voice and a template for one kind of channel.`,(0,h.jsx)(U,{id:`welcome.packs`})]}),(0,h.jsxs)(PH,{label:`Starter packs`,className:`[&_.sl-row__meta]:whitespace-normal`,children:[(a.data?.packs??[]).map(e=>(0,h.jsx)(FH,{title:e.name,meta:e.summary,actions:(0,h.jsx)(B,{disabled:e.installed||o.isPending,onClick:()=>o.mutate(e.id),children:e.installed?`Added`:`Add pack`})},e.id)),a.data===void 0?(0,h.jsx)(FH,{title:`Loading packs…`}):null]})]})}function fwe({template:e}){let{api:t}=V(),n=I({queryKey:[...iq,e.id,e.version],queryFn:async()=>{let n=await uq(t,e.id);if(!n.ok)throw Error(n.message);return n.value}});if(n.error)return(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The keywords of `,e.name,` didn't load. `,n.error.message,` Press Keywords again.`]});if(!n.data)return(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`Reading the keywords…`});let{form:r,librarySnapshot:i}=n.data.document,a=F1({form:r,prompts:i?.prompts??[],entries:i?.entries??[]}),o=F3(r.title),s=[...new Set([...a.keys(),...Object.keys(r.values)])];return(0,h.jsx)(V1,{keywords:s.map(e=>({name:e,value:r.values[e]??``,feeds:a.get(e)??[],topic:o.includes(e)})),empty:`No keywords: the prompts and the title name none.`})}async function pwe(e,t,n,r){let i=await fq(e,t.id,{baseVersion:t.version,mutationId:r,...n});if(!i.ok)throw Error(i.message);return i.value}function mwe({template:e}){return e===void 0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`Pick a template to see the keywords it fills.`}):(0,h.jsxs)(`section`,{"aria-label":`Keywords of ${e.name}`,className:`flex flex-col gap-4`,children:[(0,h.jsx)(W,{title:e.name,as:`h3`,info:`templates.edit`,className:`pb-0`}),(0,h.jsx)(fwe,{template:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`To change the settings, press Use in Play, change the draft, then Save a setup.`})]})}function hwe({template:e,onClose:t}){let{api:n}=V(),r=_(),i=Array.from({length:e.version},(t,n)=>e.version-n),a=rt({queries:i.map(t=>({queryKey:[...iq,e.id,`version`,t],queryFn:async()=>{let r=await uq(n,e.id,t);if(!r.ok)throw Error(r.message);return r.value},staleTime:1/0}))}),o=a[0]?.data,[s,c]=(0,m.useState)(i[1]??e.version),l=a[i.indexOf(s)]?.data,u=(0,m.useRef)(crypto.randomUUID()),d=Ry(),f=L({mutationFn:t=>pwe(n,e,{name:t.name,document:t.document},u.current),onSuccess:async(n,i)=>{u.current=crypto.randomUUID(),d(`Restored version ${String(i.version)} of ${e.name} as version ${String(n.version)}.`,`success`),await r.invalidateQueries({queryKey:iq}),t()}}),p=a.find(e=>e.error!==null)?.error;return(0,h.jsx)(HP,{open:!0,title:`History of ${e.name}`,onClose:t,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[p?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:`A version couldn't be read: ${p.message} Close History and open it again.`}):null,(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Versions`,as:`h3`,info:`templates.history`}),(0,h.jsx)(PH,{label:`Versions of ${e.name}`,children:i.map((t,n)=>{let r=a[n]?.data;return(0,h.jsx)(FH,{title:`Version ${String(t)}`,selected:t===s,onSelect:()=>c(t),meta:r===void 0?`Loading…`:`${r.name} · ${D4(r.updatedAt)}`,actions:t===e.version?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(B,{size:`small`,"aria-label":`Restore version ${String(t)}`,disabled:r===void 0||f.isPending,disabledReason:r===void 0?`Reading the version`:`Restoring`,onClick:()=>{r!==void 0&&f.mutate(r)},children:`Restore`})},t)})}),(0,h.jsx)(v1,{tone:`error`,children:f.error===null?void 0:`The version wasn't restored: ${f.error.message}`})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`Compare with the current version`,as:`h3`}),o===void 0||l===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Loading the versions…`}):l.version===o.version?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.version===1?`This is the only version so far.`:`Pick an older version in the list to compare it.`}):(0,h.jsxs)(h.Fragment,{children:[l.name===o.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${l.name}" to "${o.name}".`}),(0,h.jsx)(b4,{before:D9(l),after:D9(o),beforeLabel:`Version ${String(l.version)}`,afterLabel:`Version ${String(o.version)} (current)`})]})]})]})})}function D9(e){return JSON.stringify(e.document,null,1).split(`
308
+ `),s].find(e=>e?.trim())??`No text was recorded for this part.`}catch{return`Recorded text cannot be decoded.`}}function Qxe({projectId:e,pending:t,onRestore:n}){let{api:r}=V(),[i,a]=(0,m.useState)(),o=I({queryKey:H.revisions(e),queryFn:async()=>{let t=await kpe(r,e);if(!t.ok)throw Error(t.message);return t.value.revisions}}),s=I({queryKey:H.revision(e,i??``),enabled:i!==void 0,queryFn:async()=>{if(i===void 0)throw Error(`Choose a version from History first.`);let t=await k0(r,e,i);if(!t.ok)throw Error(t.message);return t.value.view}}),c=s.data,l=c?.outputs.find(e=>e.selected&&e.available&&(e.output.role===`image`||e.output.role===`thumbnail`)),u=l??c?.outputs.find(e=>e.available);return(0,h.jsxs)(`section`,{"aria-label":`Project history`,className:`space-y-3`,children:[(0,h.jsx)(W,{title:`Project history`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:o.error.message}),(0,h.jsx)(`ol`,{className:`space-y-2`,children:o.data?.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(B,{type:`button`,onClick:()=>a(e.id),children:[e.title,` · `,e.createdAt,e.current?` · Current`:``]})},e.id))}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:s.error.message}),c===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:c.revision.config.title}),(0,h.jsxs)(Iy,{children:[(0,h.jsx)(B,{variant:`primary`,disabled:t,onClick:()=>n(c.revision.id),children:`Restore this revision`}),l===void 0?null:(0,h.jsxs)(TS,{href:Ppe(r,e,c.revision.id),download:!0,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download all images`]}),u===void 0?null:(0,h.jsx)(P0,{projectId:e,asset:``,folder:{revisionId:c.revision.id,recordId:u.recordId}})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-3 p-0`,children:c.outputs.map(t=>(0,h.jsxs)(`li`,{className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:C7(t.output)}),(0,h.jsxs)(`span`,{className:`text-small text-ink-2`,children:[` · ${t.state}${t.selected?``:` · Earlier result`}`,t.available?``:` · File missing`]})]}),t.available?(0,h.jsxs)(TS,{href:j0(r,e,c.revision.id,t.recordId),download:!0,size:`small`,"aria-label":`Download ${C7(t.output)}`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download`]}):null]}),t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained output`}),t.output.role===`video`?(0,h.jsx)(c0,{className:`max-w-[640px]`,label:C7(t.output),src:j0(r,e,c.revision.id,t.recordId)}):[`audio_export`,`audio_body`,`audio_intro`,`audio_outro`].includes(t.output.role)?(0,h.jsx)(Y8,{label:C7(t.output),src:j0(r,e,c.revision.id,t.recordId)}):t.output.role===`image`||t.output.role===`thumbnail`?(0,h.jsx)(l0,{className:`max-w-[480px]`,alt:C7(t.output),title:C7(t.output),meta:t.selected?`Current`:`Earlier result`,src:j0(r,e,c.revision.id,t.recordId)}):(0,h.jsx)(`p`,{children:`Use Download to inspect this retained file.`})]}):null]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained narration parts`,children:c.pieces.filter(e=>e.stageKind===`audio`&&e.assetId!==null).map(t=>(0,h.jsxs)(`li`,{children:[`Narration part `,t.piece.idx,t.selected?``:` · Earlier result`,t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained audio part`}),(0,h.jsx)(Y8,{label:`Narration part ${String(t.piece.idx)}`,src:j0(r,e,c.revision.id,t.recordId)}),(0,h.jsxs)(TS,{href:j0(r,e,c.revision.id,t.recordId),download:!0,size:`small`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download narration part`]})]}):(0,h.jsx)(`span`,{children:` · File missing`})]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained text parts`,children:c.pieces.filter(e=>e.assetId===null).map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(`details`,{children:[(0,h.jsxs)(`summary`,{children:[e.stageKind,` part `,e.piece.idx]}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words`,children:Zxe(e.piece.payload)})]})},e.recordId))})]})]})}function M7(e,t,n){let r=JSON.stringify(t);return e?.payload===r?e:{payload:r,idempotencyKey:n()}}function $xe(e,t,n={}){let{api:r}=V(),i=_(),a=I({queryKey:H.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved settings to show yet. Reload the page and try again.`);let n=await k0(r,e,t);if(!n.ok)throw Error(n.message);return n.value.view}}),[o,s]=(0,m.useState)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(),[f,p]=(0,m.useState)(),[h,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(),w=(0,m.useRef)(void 0),T=(0,m.useRef)(void 0),E=(0,m.useRef)(void 0),D=(0,m.useRef)(n.onOpenEdit);D.current=n.onOpenEdit;let O=(0,m.useMemo)(()=>c!==void 0&&(o===void 0||(c.regenerate?.length??0)>0||(c.uploads?.length??0)>0||JSON.stringify(c.config)!==JSON.stringify(o.revision.config)||JSON.stringify(c.content)!==JSON.stringify(o.revision.content)),[c,o]),k=c!==void 0&&o!==void 0&&t!==null&&t!==o.revision.id,A=(0,m.useRef)(!1);async function j(e){if(!A.current){A.current=!0,g(!0),x(void 0),C(void 0);try{await e()}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1,g(!1)}}}async function M(t){let n=await D0(r,e);if(!n.ok){C(n);return}return C(void 0),s(n.value.view),t&&l({config:structuredClone(n.value.view.revision.config),content:structuredClone(n.value.view.revision.content)}),n.value.view}async function ee(t){let n=await Oo(r,e);return i.setQueryData(H.project(e),n),await i.invalidateQueries({queryKey:H.revisions(e)}),!t.current||n.revisionId!==t.revision.id?(C({ok:!1,reason:`conflict`,message:`The project changed again. Your draft is preserved.`,currentRevisionId:n.revisionId,fields:[]}),!1):(s(t),l(void 0),C(void 0),d(void 0),!0)}async function N(){if(v||o===void 0||c===void 0)return;let t={baseRevisionId:o.revision.id,edit:c},n=M7(w.current,t,()=>crypto.randomUUID());w.current=n;let i=await O0(r,e,{...t,idempotencyKey:n.idempotencyKey});if(!i.ok){C(i);return}await ee(i.value.view),w.current=void 0}async function P(t,n=u){if(n===void 0)return;let a={baseRevisionId:n.baseRevisionId,previewId:n.id,...t},o=M7(E.current,a,()=>crypto.randomUUID());E.current=o;let s=await Mpe(r,e,{...a,idempotencyKey:o.idempotencyKey});if(!s.ok){C(s),(s.reason===`stale-preview`||s.reason===`conflict`)&&d(void 0);return}E.current=void 0,d(void 0),await i.invalidateQueries({queryKey:H.project(e)})}async function F(t,n){let i=await M(!1);if(i===void 0)return;let a=await jpe(r,e,{baseRevisionId:i.revision.id,request:t});if(!a.ok){C(a);return}let o=a.value.value;if(E.current=void 0,n&&eSe(o)){await P({acknowledgeUnknownCosts:!1,confirmedProvidedWorkKeys:[]},o);return}d(o)}async function te(t){let n=o??a.data??await M(!1);if(n===void 0)return;let i={baseRevisionId:n.revision.id,targetRevisionId:t},s=M7(T.current,i,()=>crypto.randomUUID());T.current=s;let c=await Ope(r,e,{...i,idempotencyKey:s.idempotencyKey});if(!c.ok){C(c);return}await ee(c.value.view),T.current=void 0}return{saved:a,view:o,edit:c,preview:u,focus:f,pending:h,uploading:v,error:b,refusal:S,unsaved:O,remoteChanged:k,busy:h||v||c!==void 0||u!==void 0,setEdit:l,setUploading:y,openEditor:()=>void j(async()=>{await M(!0)}),discard:()=>{l(void 0),C(void 0),y(!1),w.current=void 0},save:()=>void j(N),reloadDraft:()=>void j(async()=>{w.current=void 0,y(!1),await M(!0),C(void 0)}),reloadCurrent:()=>void j(async()=>{T.current=void 0,E.current=void 0,d(void 0),await M(!1),await i.invalidateQueries({queryKey:H.project(e)})}),requestEdit:e=>void j(async()=>{let t=o,n=c;if(t===void 0||n===void 0){if(t=await M(!1),t===void 0)return;n={config:structuredClone(t.revision.config),content:structuredClone(t.revision.content)}}l(e.change(n,t)),p({section:e.section}),D.current?.()}),regenerateNow:t=>void j(async()=>{let n=e=>({...e,regenerate:[...new Set([...e.regenerate??[],...t])]});if(c!==void 0&&O){l(n(c)),p({section:`images`}),D.current?.();return}let i=await M(!1);if(i===void 0)return;let a=await O0(r,e,{baseRevisionId:i.revision.id,edit:n({config:structuredClone(i.revision.config),content:structuredClone(i.revision.content)}),idempotencyKey:crypto.randomUUID()});if(!a.ok){C(a);return}await ee(a.value.view)&&await F({kind:`selected`,workKeys:t},!0)}),review:(e,t)=>void j(()=>F(e,t?.autoStart===!0)),start:e=>void j(()=>P(e)),closePreview:()=>{h||(d(void 0),E.current=void 0)},restore:e=>void j(()=>te(e))}}function eSe(e){return!e.work.some(e=>e.disposition===`blocked`)&&e.providedReuseRequired.length===0&&e.costs.unknown===0}function tSe({controller:e,renderEditor:t,active:n=!0,intro:r}){let i=e;return i.view===void 0||i.edit===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r??(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Saved revision`,info:`project.saved-revision`}),i.saved.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.saved.error.message}),i.saved.data===void 0?null:(0,h.jsx)(`ul`,{"aria-label":`Saved output status`,className:`sl-list m-0 list-none p-0`,children:i.saved.data.outputs.filter(e=>e.selected).map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:C7(e.output)}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.available?e.state===`ready`?`Ready`:e.state===`outdated`?`Outdated; the retained version stays until it is remade`:`Provided content needs review`:`Retained file missing`})]},e.recordId))})]}),i.preview===void 0&&n?(0,h.jsx)(j7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)(y1,{children:[i.refusal?.reason===`conflict`&&n?(0,h.jsx)(B,{disabled:i.pending,onClick:i.reloadCurrent,children:`Reload current revision`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{disabled:i.busy,onClick:()=>i.review({kind:`allAffected`}),variant:`secondary`,children:`Choose what to remake`}),(0,h.jsx)(U,{id:`project.choose-remake`})]}),(0,h.jsx)(B,{variant:`primary`,disabled:i.busy,onClick:i.openEditor,children:`Edit project`})]})]}):(0,h.jsxs)(`form`,{"aria-label":`Edit project`,onSubmit:e=>{e.preventDefault(),i.save()},children:[(0,h.jsx)(`fieldset`,{disabled:i.pending,className:`m-0 min-w-0 border-0 p-0`,children:t({view:i.view,edit:i.edit,fields:i.refusal?.fields??[],onChange:i.setEdit,onPending:i.setUploading,...i.focus===void 0?{}:{focus:i.focus}})}),i.preview===void 0?(0,h.jsx)(j7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)(y1,{status:(0,h.jsx)(v1,{tone:i.remoteChanged?`warning`:`info`,children:i.remoteChanged?`A newer revision is available. Your unsaved changes are kept below.`:i.uploading?`Waiting for uploads to finish…`:void 0}),children:[i.remoteChanged||i.refusal?.reason===`conflict`?(0,h.jsx)(B,{disabled:i.pending||i.uploading,onClick:i.reloadDraft,children:`Reload current revision and discard my draft`}):null,(0,h.jsx)(B,{variant:`quiet`,disabled:i.pending||i.uploading,onClick:i.discard,children:`Discard changes`}),(0,h.jsx)(B,{variant:`primary`,type:`submit`,disabled:i.pending||i.uploading,children:`Save changes`})]})]})}function nSe({controller:e,projectId:t,active:n}){let r=e;return n?(0,h.jsxs)(h.Fragment,{children:[r.preview===void 0&&(r.error||r.refusal)?(0,h.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3`,children:[(0,h.jsx)(j7,{error:r.error,refusal:r.refusal}),r.edit===void 0&&r.refusal?.reason===`conflict`?(0,h.jsx)(B,{disabled:r.pending,onClick:r.reloadCurrent,className:`self-start`,children:`Reload current revision`}):null]}):null,(0,h.jsx)(Qxe,{projectId:t,pending:r.busy,onRestore:r.restore})]}):null}function rSe({controller:e}){let t=e;return(0,h.jsx)(HP,{open:t.preview!==void 0,title:`Choose what to remake`,onClose:t.closePreview,children:t.preview===void 0?null:(0,h.jsx)(w7,{preview:t.preview,feedback:(0,h.jsx)(j7,{error:t.error,refusal:t.refusal}),pending:t.pending,onStart:t.start,onCancel:t.closePreview},t.preview.id)})}var iSe=(e,t)=>{if(t)return`waiting`;switch(e.state){case`running`:return`running`;case`done`:case`provided`:return`done`;case`failed`:return e.retryAt===void 0?`failed`:`waiting`;default:return`off`}},aSe=(e,t)=>{if(t)return`Held for you`;switch(e.state){case`running`:return`Running`;case`done`:return`Done`;case`provided`:return`Provided`;case`failed`:return e.retryAt===void 0?`Failed`:`Waiting to try again`;case`canceled`:return`Canceled`;case`skipped`:return`Off`;case`pending`:return`Not started`}};function oSe(e,t){if(e.startedAt===null)return;let n=Date.parse(e.startedAt),r=e.finishedAt===null?t:Date.parse(e.finishedAt);if(!Number.isFinite(n)||!Number.isFinite(r)||r<n)return;let i=Math.round((r-n)/1e3);if(i<1)return;if(i<60)return`${String(i)} s`;let a=Math.round(i/60);return a<60?`${String(a)} min`:`${String(Math.floor(a/60))} h ${String(a%60)} min`}function sSe(e,t,n){let r=x3(t,n);return r===void 0?e:e===void 0||e===``?S3(r):`${e} · ${S3(r)}`}function cSe({stages:e,outputs:t,project:n,resumable:r,held:i,now:a}){return e.filter(e=>e.state!==`skipped`).map(e=>{let o=i.some(t=>t.stage===e.kind),s=oSe(e,a);return{id:e.id,name:e.kind===`video`&&XP(n.config)===`audio`?`Audio export`:$8[e.kind],tone:iSe(e,o),state:aSe(e,o),...s===void 0?{}:{time:s},detail:o?`Held for your review`:sSe(tF(e,t,n,r),e,a)}})}function lSe({stages:e}){return(0,h.jsx)(`div`,{className:`sr-only`,children:e.filter(e=>e.state!==`skipped`).map(e=>(0,h.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:`${$8[e.kind]}: ${e.state}`},e.id))})}function uSe({steps:e}){return(0,h.jsxs)(`section`,{"aria-labelledby":`run-steps-title`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{id:`run-steps-title`,title:`Run`,size:`small`,className:`pb-0`}),(0,h.jsx)(w3,{steps:e,label:`Run steps`,dense:!0})]})}var N7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});function dSe({cost:e,onOpen:t}){if(e===void 0||e.calls===0&&e.byStage.length===0)return null;let n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({key:`${e.account}/${t.kind}`,name:e.name,window:t.kind===`five_hour`?`5-hour`:t.kind===`weekly`?`weekly`:`current`,used:t.usedPercent,now:t.nowPercent})):[]);return(0,h.jsxs)(`section`,{"aria-labelledby":`cost-so-far-title`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{id:`cost-so-far-title`,title:`Cost so far`,size:`small`,className:`pb-0`,children:t===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:t,children:`By stage`})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[(0,h.jsx)(`strong`,{className:`text-ink`,children:a7(e.cost)}),e.unpriced>0?` known, spent`:` spent`,e.apiEquivalent===null?null:` · ~${a7(e.apiEquivalent)} via API`,e.run===null||e.run.running?null:` · ${o7(e.run.workingMs)} of work`]}),n.map(e=>{let t=e.used<1?`under 1%`:`${N7.format(e.used)}%`,n=`${e.window} ${e.name} limit`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`${e.name}: ${t} of your ${e.window} limit`}),(0,h.jsx)(C2,{value:e.used/100,label:`Share of the ${n} this run used`,valueText:`${t} of your ${n}; now at ${N7.format(e.now)}%`,tone:e.now>=80?`waiting`:`accent`})]},e.key)})]})}function fSe({projectId:e,revisionId:t,title:n,open:r,onClose:i}){let{api:a}=V(),o=_(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=Ry(),g=(0,m.useRef)(!1),v=(0,m.useRef)(null);(0,m.useEffect)(()=>{r&&t!==null&&(c({revisionId:t,name:n}),f(null)),r||c(null)},[r,t,n]);async function y(){if(!s||g.current||!s.name.trim())return;g.current=!0,u(!0),f(null);let t=JSON.stringify([e,s.revisionId,s.name.trim()]);v.current?.key!==t&&(v.current={key:t,id:crypto.randomUUID()});try{let t=await mq(a,e,{id:v.current.id,name:s.name.trim(),revisionId:s.revisionId});if(!t.ok){v.current=null,f(t.message);return}v.current=null,i(),p(`Template saved.`,`success`),await o.invalidateQueries({queryKey:iq})}catch(e){f(e instanceof Error?e.message:`The template wasn't saved. Press Save template to try again.`)}finally{g.current=!1,u(!1)}}return(0,h.jsx)(Vy,{open:r&&s!==null,onOpenChange:e=>{!e&&!g.current&&i()},title:`Save as template`,description:`Save this revision’s setup for a fresh Play draft. This does not rebuild the project.`,children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,h.jsx)(LB,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(zB,{autoFocus:!0,required:!0,maxLength:200,disabled:l,value:s?.name??``,onChange:e=>{let t=e.target.value;c(e=>e&&{...e,name:t})}})}),d?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:d}):null,(0,h.jsxs)(`div`,{className:`sl-dialog__foot`,children:[(0,h.jsx)(B,{disabled:l,onClick:i,children:`Cancel`}),(0,h.jsx)(B,{variant:`primary`,type:`submit`,disabled:l||!s?.name.trim(),children:`Save template`})]})]})})}var P7=Y({baseRevisionId:K().min(1).max(64),idempotencyKey:_D()}).strict(),pSe=XD(`kind`,[Y({kind:oO(`resume`)}).strict(),Y({kind:oO(`retry`),stage:X(KS)}).strict(),Y({kind:oO(`rerun`),stage:X(KS)}).strict(),Y({kind:oO(`redo`),item:K().min(1).max(200)}).strict()]);P7.extend({action:pSe}).strict();var mSe=XD(`ok`,[Y({ok:oO(!0),value:g0.and(Y({warnings:J(K()).readonly()}))}),Y({ok:oO(!1),reason:X([`no-project`,`no-revision`,`conflict`,`idempotency-conflict`,`invalid-edit`,`stale-preview`,`invalid-selection`,`review-required`,`cost-ack-required`,`readiness`,`running`,`accepted-job`,`control-changed`]),fields:J(Y({field:K(),message:K()})).readonly().optional(),intentRevisionId:K().optional(),currentRevisionId:K().nullable().optional()})]),F7=new Set([400,404,409]);async function hSe(e,t,n){return L7(e,t,`cancel`,n)}async function gSe(e,t,n){return L7(e,t,`pause`,n)}function _Se(e,t,n){return R7(e,t,`resume`,n)}function vSe(e,t,n,r){return R7(e,t,`stages/${n}/retry`,r)}function ySe(e,t,n,r){return R7(e,t,`stages/${n}/soften`,r)}function bSe(e,t,n,r){return R7(e,t,`stages/${n}/rerun`,r)}async function xSe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/providers`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function SSe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/subtitles`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function CSe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/article`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({markdown:n})}))}async function wSe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].$delete({param:{id:t,outputId:n}}))}async function TSe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].regenerate.$post({param:{id:t,outputId:n}}))}async function I7(e){if(e.ok)return{ok:!0,value:await e.json()};let t=await uo(e);if(t!==void 0&&F7.has(e.status))return{ok:!1,message:lo(e,t).message};throw lo(e,t)}async function L7(e,t,n,r){let i=P7.parse(r);return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}))}async function R7(e,t,n,r){let i=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(P7.parse(r))});if(i.ok){let e=mSe.parse(await i.json());if(!e.ok)throw Error(vo);return{ok:!0,value:e.value,warnings:e.value.warnings}}let a=await uo(i);if(a!==void 0&&F7.has(i.status))return{ok:!1,message:lo(i,a).message};throw lo(i,a)}function ESe(e){let{api:t}=V(),n=_(),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(),s=(0,m.useRef)(new Map),c=(0,m.useRef)(!1),l=L({mutationFn:async e=>{let r=e.action;if(![`pause`,`cancel`,`resume`,`retry`,`soften`,`rerun`].includes(r.kind))return B7(t,e.projectId,r);let i=r.kind===`retry`||r.kind===`soften`||r.kind===`rerun`?r.stage:``,a=`${e.projectId}:${r.kind}:${i}`,o=s.current.get(a);if(!o){let r=n.getQueryData(H.project(e.projectId))?.revisionId;if(!r){let n=await D0(t,e.projectId);if(!n.ok)return{ok:!1,message:n.message};r=n.value.view.revision.id}o={baseRevisionId:r,idempotencyKey:crypto.randomUUID()},s.current.set(a,o)}let c=await B7(t,e.projectId,r,o);return s.current.delete(a),c.ok&&await Oo(t,e.projectId).then(t=>n.setQueryData(H.project(e.projectId),t),e=>console.warn(`Project refresh after an accepted action failed`,e)),c},onMutate:()=>{i(void 0),o(void 0)},onSuccess:async(e,t)=>{e.ok?(o(`warnings`in e&&e.warnings.length>0?e.warnings.join(` `):void 0),n.invalidateQueries({queryKey:H.projects})):i({message:e.message,stage:z7(t.action)}),await n.invalidateQueries({queryKey:H.project(t.projectId)})},onSettled:()=>{c.current=!1},onError:(e,t)=>{i({message:e.message,stage:z7(t.action)})}});return{run:(t,n)=>{c.current||(c.current=!0,l.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok&&n?.()}}))},pending:l.isPending,performing:l.isPending?l.variables?.action:void 0,refusal:r,dismissRefusal:()=>{i(void 0)},notice:a}}function z7(e){switch(e.kind){case`cancel`:case`pause`:case`resume`:case`providers`:return;case`retry`:case`soften`:case`rerun`:return e.stage;case`subtitles`:return`video`;case`save-article`:return`article`;case`delete-image`:case`regenerate-image`:return`images`}}function B7(e,t,n,r){let i=()=>{if(!r)throw Error(`A saved revision and request identity are required.`);return r};switch(n.kind){case`pause`:return gSe(e,t,i());case`cancel`:return hSe(e,t,i());case`resume`:return _Se(e,t,i());case`retry`:return vSe(e,t,n.stage,i());case`soften`:return ySe(e,t,n.stage,i());case`rerun`:return bSe(e,t,n.stage,i());case`providers`:return xSe(e,t,n.choices);case`subtitles`:return SSe(e,t,n.subtitles);case`save-article`:return CSe(e,t,n.markdown);case`delete-image`:return wSe(e,t,n.outputId);case`regenerate-image`:return TSe(e,t,n.outputId)}}var V7=e=>e.state===`done`||e.state===`provided`;function DSe(e){let t=e.find(e=>e.state===`failed`)??e.find(e=>e.state===`running`);if(t)return t.kind;let n=e.find(e=>e.kind===`video`&&V7(e));if(n)return n.kind;let r=e.find(e=>e.state===`pending`);return r?r.kind:e.find(e=>e.kind===`article`&&V7(e))?.kind??e.find(e=>e.state!==`skipped`)?.kind??`article`}function OSe({projectId:e,openDraft:t}){return(0,h.jsx)(kSe,{projectId:e,openDraft:t},e)}var H7=e=>{let t=e.filter(e=>e!==void 0);if(!(t.length===0||t.every(e=>e.state===`skipped`)))return t.some(e=>e.state===`failed`&&e.retryAt===void 0)?`failed`:t.some(e=>e.state===`running`)?`running`:t.some(e=>e.state===`failed`)?`waiting`:t.every(e=>e.state===`done`||e.state===`provided`||e.state===`skipped`)?`done`:`off`};function kSe({projectId:e,openDraft:t}){let{api:n}=V(),r=Ry(),i=MSe(e,t),a=I(sb(n,e)),o=I(pb(n)),s=I({...cb(n,e),refetchInterval:e=>a.data?.project.status===`running`&&e.state.status===`success`&&2e4}),c=ESe(e),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),x=a.data?.revisionId??null,S=$xe(e,x,{onOpenEdit:()=>u(`settings`)}),C=die(e),w=(0,m.useRef)(void 0);(0,m.useEffect)(()=>{if(C===void 0){w.current=void 0;return}a.data!==void 0&&w.current!==C&&(w.current=C,C===`download`&&u(XP(a.data.project.config)===`article`?`article`:`video`))},[C,a.data]),k3(e,x);let T=I({queryKey:Wy,queryFn:()=>Qy(n)}),E=$y(T.data,e),D=I({queryKey:c3(e,x??``),queryFn:()=>u3(n,e),enabled:x!==null,retry:!1}),O=D.data?.ok===!0?D.data.value.checkpoints:[],k=S.saved.data?.outputs.filter(e=>e.selected&&e.state===`outdated`).map(e=>({workKey:e.workKey,role:e.output.role}))??[],A=a.data?.project,j=a.data?.stages??[],M=a.data?.outputs??[],ee=M.some(e=>e.role===`video`),N=e=>u(e),P=Sye({project:A??ASe,stages:j,resumable:a.data?.resumable??!1,sample:E,gates:O,outdated:k,waits:s.data?.waits??[],uploadReady:ee,actions:c,controller:S,openSection:N,openUpload:()=>f(!0)}),F=l===`settings`,te=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!F){te.current=!1;return}S.edit!==void 0&&(te.current=!0),!(te.current||S.busy)&&(te.current=!0,S.openEditor())},[F,S]);let ne=j.some(e=>e.state===`running`),re=A?.status===`running`,ie=A?.title??``,ae=P.next?.action;jx({id:`project.next`,title:ae?.label??`Show the project's next action`,group:`This project`,context:ie,keywords:[`next`,`continue`,`resume`,`approve`,`retry`],shortcut:nP.nextAction,run:()=>{ae===void 0?r(`This project has no next action right now: nothing waits on you.`,`info`):ae.intent.kind===`soften`?r(`Soften and retry asks first: press it in the Next action panel on the right.`):P.run(ae.intent)}}),oS(tS.showImages(e),()=>{let e=a.data?.stages.find(e=>e.kind===`images`);e===void 0||e.state===`skipped`?r(`${ie} makes no slideshow images, so there is no image to regenerate. To add them, open Settings in this project and choose how its images are made.`,`error`):u(`images`)},a.data!==void 0),jx({id:`project.pause`,title:A?.status===`paused`?`Continue the run`:`Pause the run`,group:`This project`,context:ie,keywords:[`pause`,`resume`,`continue`,`stop`],run:()=>c.run({kind:A?.status===`paused`?`resume`:`pause`})}),jx({id:`project.prepare-upload`,title:`Prepare upload`,group:`This project`,context:ie,keywords:[`youtube`,`studio`,`upload`,`publish`],run:()=>{ee?f(!0):r(`Prepare upload opens once the video has been made.`,`info`)}}),jx({id:`project.settings`,title:`Edit project settings`,group:`This project`,context:ie,keywords:[`edit`,`settings`,`prompts`,`providers`,`channel`],run:()=>u(`settings`)}),jx({id:`project.rebuild-review`,title:`Choose what to remake`,group:`This project`,context:ie,keywords:[`rebuild`,`review`,`remake`,`outdated`,`affected`],run:()=>S.review({kind:`allAffected`})}),jx({id:`project.template`,title:`Save as template`,group:`This project`,context:ie,keywords:[`template`,`reuse`],run:()=>g(!0)}),jx({id:`project.cancel`,title:`Cancel the run`,group:`This project`,context:ie,keywords:[`cancel`,`stop`],run:()=>b(!0)});let oe=bye(k);if(jx({id:`project.remake-1`,title:oe[0]?.label??`Remake outdated outputs`,group:`This project`,context:ie,keywords:[`remake`,`outdated`,`rebuild`],run:()=>{let e=oe[0];e===void 0?r(`Nothing is outdated in this project.`,`info`):S.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0})}}),jx({id:`project.remake-all`,title:`Remake everything outdated`,group:`This project`,context:ie,keywords:[`remake`,`outdated`,`rebuild`,`all`],run:()=>{let e=[...new Set(oe.flatMap(e=>e.workKeys))];e.length===0?r(`Nothing is outdated in this project.`,`info`):S.review({kind:`selected`,workKeys:e},{autoStart:!0})}}),jx({id:`project.copy`,title:`Make my own copy`,group:`This project`,context:ie,keywords:[`sample`,`copy`,`duplicate`],run:()=>E?P.run({kind:`copy-sample`}):r(`Only the sample project is copied this way.`,`info`)}),a.error!==null)return(0,h.jsx)(aI,{tone:`danger`,title:`The project could not be loaded.`,children:`${a.error.message} Reload the page to try again, or go back to Projects.`});if(a.data===void 0||A===void 0)return(0,h.jsx)(jSe,{});let se=e=>j.find(t=>t.kind===e),ce=se(`article`),le=se(`research`),ue=se(`audio`),de=se(`images`),fe=se(`thumbnail`),pe=se(`video`),me=se(`document`),he=A.config,ge=e=>e!==void 0&&e.state!==`skipped`,_e=he.shorts?.enabled===!0||M.some(e=>e.role===`short_video`||e.role===`shorts`),ve=he.youtubeDescription===!0||M.some(e=>e.role===`youtube_description`),ye=O.filter(e=>e.state===`held`||e.state===`pending-review`),be=[...ge(ce)||ge(le)?[{id:`article`,label:`Article`,tone:H7([ce,le])}]:[],...ge(ue)?[{id:`narration`,label:`Narration`,tone:H7([ue])}]:[],...ge(de)||ge(fe)||he.reference!==void 0?[{id:`images`,label:`Images`,tone:H7([de,fe])}]:[],...ge(pe)?[{id:`video`,label:XP(he)===`audio`?`Audio export`:`Video`,tone:H7([pe])}]:[],...ge(me)?[{id:`document`,label:`PDF`,tone:H7([me])}]:[],{id:`cost`,label:`Cost`},{id:`live`,label:`Live`}].map(e=>{let t=oe.filter(t=>t.section===e.id).reduce((e,t)=>e+t.count,0);return t===0?e:{...e,meta:`${String(t)} outdated`}}),xe=[{id:`settings`,label:`Settings`,...S.unsaved?{meta:`unsaved`}:{}},...x===null?[]:[{id:`checkpoints`,label:`Checkpoints`,...ye.length===0?{}:{meta:`${String(ye.length)} held`}}],{id:`history`,label:`History`}],Se=[...be,...xe],Ce=P.next?.situation,we=P.next?.section!==void 0&&Ce!==`done`&&Ce!==`running`?P.next.section:Ce===`done`&&M.some(e=>e.role===`youtube_description`)?`youtube`:Q8(DSe(j)),Te=e=>e===`shorts`||e===`youtube`?`video`:e,Ee=l!==void 0&&Se.some(e=>e.id===Te(l))?Te(l)??`video`:Se.find(e=>e.id===Te(we))?.id??be[0]?.id??`cost`,De=(...e)=>x===null?A.status===`running`||A.status===`paused`||ne||c.pending:c.pending||e.some(e=>e?.state===`running`),Oe={project:A,outputs:M,actions:c,next:P,resumable:a.data.resumable},ke=(e,t)=>e===void 0?null:(0,h.jsx)(xbe,{stage:e,...t===void 0||t.state===`skipped`?{}:{companion:t},project:A,outputs:M,actions:c,busy:De(e,t)}),Ae=(...e)=>M.some(t=>e.some(e=>e!==void 0&&t.stageKind===e.kind)),je=(...e)=>Ae(...e)||e.some(e=>e!==void 0&&[`running`,`done`,`provided`,`failed`,`canceled`].includes(e.state)),Me=[{id:`rebuild`,label:`Choose what to remake…`,run:()=>S.review({kind:`allAffected`}),disabled:S.busy},{id:`template`,label:`Save as template…`,run:()=>g(!0),disabled:x===null||E},{id:`channel`,label:`Move to channel…`,run:()=>v(!0),disabled:E},{id:`cancel`,label:`Cancel the run…`,run:()=>b(!0),disabled:!re||c.pending,apart:!0}],Ne=Z8({kind:`cancel`}),Pe=c.refusal?.stage===void 0?c.refusal:void 0,Fe=Pe===void 0?c.notice===void 0?S.preview===void 0&&(S.error||S.refusal)&&Ee!==`settings`&&Ee!==`history`?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:S.error??S.refusal?.message}):void 0:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:c.notice}):(0,h.jsx)(aI,{tone:`danger`,title:Pe.message,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,className:`mt-1`,onClick:c.dismissRefusal,children:`Dismiss`})}),Ie=cSe({stages:j,outputs:M,project:A,resumable:a.data.resumable,held:ye.map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),now:Date.now()});return(0,h.jsx)(kve,{projectId:e,revisionId:x,children:(0,h.jsx)(W8,{value:x!==null,children:(0,h.jsx)(f3,{value:e=>u(e===`edit`?`settings`:`article`),children:(0,h.jsx)(G8,{value:S.pending||S.preview!==void 0?void 0:S.requestEdit,children:(0,h.jsxs)(K8,{value:S.pending||S.preview!==void 0?void 0:S.regenerateNow,children:[(0,h.jsxs)(`div`,{className:`sl-project`,children:[(0,h.jsx)(`div`,{"data-tour":`project-controls`,children:(0,h.jsx)(Nbe,{project:A,prompts:o.data?.prompts,editing:Ee===`settings`,onEdit:()=>u(`settings`),more:Me,nextChapter:i,clock:(0,h.jsx)(Bbe,{cost:s.data,status:A.status,measuredAt:s.dataUpdatedAt})})}),(0,h.jsx)(lSe,{stages:j}),(0,h.jsxs)(ZK,{sections:(0,h.jsxs)(X6,{label:`Project sections`,children:[be.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:N},e.id)),(0,h.jsx)(`hr`,{className:`sl-rule my-2`}),xe.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:N},e.id))]}),aside:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wye,{state:P,feedback:Fe}),A===void 0?null:(0,h.jsx)(Mbe,{projectId:e,title:A.title,status:A.status,sample:E||T.isPending}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-6 max-[1180px]:hidden`,children:[(0,h.jsx)(uSe,{steps:Ie}),(0,h.jsx)(dSe,{cost:s.data,onOpen:()=>N(`cost`)}),(0,h.jsx)(cve,{})]})]}),children:[(0,h.jsx)(o5,{id:`article`,title:`Article`,stages:[ce,le].filter(U7),active:Ee===`article`,...Oe,children:ge(ce)||ge(le)?ke(ce,le):(0,h.jsx)(s5,{stage:ce,project:A,name:`Article`})}),(0,h.jsx)(o5,{id:`narration`,title:`Narration`,stages:[ue].filter(U7),active:Ee===`narration`,...Oe,children:je(ue)?ke(ue):(0,h.jsx)(s5,{stage:ue,project:A,name:`Narration`})}),(0,h.jsx)(o5,{id:`images`,title:`Images`,head:!1,stages:[de,fe].filter(U7),active:Ee===`images`,...Oe,children:ke(de,fe)}),(0,h.jsxs)(o5,{id:`video`,title:XP(he)===`audio`?`Audio export`:`Video`,stages:[pe].filter(U7),active:Ee===`video`,...Oe,...ee&&P.next?.action?.intent.kind!==`prepare-upload`?{extra:(0,h.jsx)(B,{variant:`secondary`,onClick:()=>f(!0),children:`Prepare upload`})}:{},children:[ke(pe),pe!==void 0&&_e?(0,h.jsx)(fbe,{stage:pe,project:A,outputs:M}):null,pe!==void 0&&ve?(0,h.jsx)(Cbe,{stage:pe,project:A,outputs:M}):null]}),me===void 0?null:(0,h.jsx)(o5,{id:`document`,title:`PDF`,stages:[me],active:Ee===`document`,...Oe,children:je(me)?ke(me):(0,h.jsx)(s5,{stage:me,project:A,name:`PDF`})}),(0,h.jsx)(G7,{id:`cost`,title:`Run cost`,selected:Ee,children:(0,h.jsx)(Rbe,{projectId:e})}),(0,h.jsx)(G7,{id:`live`,title:`Live`,selected:Ee,children:Ee===`live`?(0,h.jsx)(Xbe,{project:A,revisionId:x,stages:j,outputs:M}):null}),(0,h.jsx)(G7,{id:`settings`,title:`Settings`,selected:Ee,children:(0,h.jsx)(tSe,{controller:S,active:Ee===`settings`,renderEditor:e=>(0,h.jsx)(Vxe,{...e,renderContent:e=>(0,h.jsx)(Cxe,{...e},e.view.revision.id)})})}),x===null?null:(0,h.jsx)(G7,{id:`checkpoints`,title:`Checkpoints`,selected:Ee,children:(0,h.jsx)(Obe,{projectId:e,revisionId:x,paused:A.status===`paused`,stages:j,approvedInRail:P.next?.action?.intent.kind===`approve`?P.next.action.intent.gate.checkpointId:void 0})}),(0,h.jsx)(G7,{id:`history`,title:`History`,selected:Ee,children:(0,h.jsx)(nSe,{controller:S,projectId:e,active:Ee===`history`})})]})]}),(0,h.jsx)(rSe,{controller:S}),d?(0,h.jsx)(W0,{projectId:e,onClose:()=>f(!1)}):null,(0,h.jsx)(exe,{projectId:e,title:A.title,open:_,onClose:()=>v(!1)}),(0,h.jsx)(fSe,{projectId:e,revisionId:x,title:A.title,open:p,onClose:()=>g(!1)}),(0,h.jsx)(Hy,{open:y,title:Ne.title,consequence:Ne.consequence,confirmLabel:Ne.verb,cancelLabel:Ne.dismiss,pending:c.pending,onConfirm:()=>{b(!1),c.run({kind:`cancel`})},onCancel:()=>b(!1)})]})})})})})}var U7=e=>e!==void 0;function W7({item:e,selected:t,onSelect:n}){return(0,h.jsx)(Z6,{className:`max-md:w-auto`,"data-tour":`project-rail-${e.id}`,current:e.id===t,onClick:()=>n(e.id),...e.tone===void 0?{}:{icon:(0,h.jsx)(DS,{tone:e.tone})},...e.meta===void 0?{}:{meta:e.meta},children:e.label})}function G7({id:e,title:t,selected:n,children:r}){return(0,h.jsxs)(`section`,{hidden:n!==e,"aria-label":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:t}),r]})}var ASe={id:``,title:``,format:`16:9`,status:`pending`,createdAt:``,config:{sources:{}}};function jSe(){return(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading project`,children:[(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-8 w-80 max-w-full rounded-control bg-sunken`})]}),(0,h.jsx)(ZK,{sections:(0,h.jsx)(`div`,{className:`flex flex-col gap-2`,children:[`a`,`b`,`c`,`d`,`e`].map(e=>(0,h.jsx)(`span`,{className:`h-8 rounded-control bg-sunken`},e))}),aside:(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`}),children:(0,h.jsx)(`span`,{className:`h-[480px] rounded-control bg-sunken`})})]})}function MSe(e,t){let{api:n}=V(),r=(0,m.useRef)(void 0),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0);if(t!==void 0)return{pending:i,error:o,run:()=>{i||(r.current??=crypto.randomUUID(),a(!0),s(void 0),gq(n,e,r.current).then(async e=>{if(!e.ok){s(e.message);return}await t(e.value.draft.id)?r.current=void 0:s(`The next chapter's draft was made, but Play could not open it because the draft open there is not saved yet. Open Play, let it save, then press Make the next chapter again.`)}).catch(e=>s(`The next chapter could not be made (${e instanceof Error?e.message:`the connection dropped`}). Press Make the next chapter again.`)).finally(()=>a(!1)))}}}var NSe=[`all`,`running`,`queued`,`waiting`,`ready`,`failed`];function PSe(e){return NSe.find(t=>t===e)}var K7=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`queued`,label:`Queued`},{value:`waiting`,label:`Needs you`},{value:`ready`,label:`Ready to upload`},{value:`failed`,label:`Failed`}];function q7(e,t){switch(t){case`all`:return!0;case`running`:return e.status===`running`||e.status===`paused`;case`queued`:return b3(e);case`waiting`:return g3(e);case`ready`:return y3(e);case`failed`:return e.status===`failed`||e.status===`partial`}}function FSe(e){let t={running:{tone:`running`,word:`Running`},paused:{tone:`waiting`,word:`Paused`},pending:{tone:`off`,word:`Queued`},failed:{tone:`failed`,word:`Failed`},partial:{tone:`info`,word:`Done with problems`},done:{tone:`done`,word:`Done`},canceled:{tone:`off`,word:`Canceled`}};if(g3(e))return{tone:`waiting`,word:`Waiting for you`};if(e.status===`pending`&&e.setAside===!0)return{tone:`done`,word:`Kept as is`};let n=e.status===`running`?gH(e.limitWaits):void 0;return n===void 0?t[e.status]:{tone:`waiting`,word:n}}function ISe(e){let t=e.config.articlePrompt,n=e.config.voices?.book;return[n===void 0?void 0:AA(n),t===void 0||t===``?void 0:t,e.format].filter(e=>e!==void 0).join(` · `)}function LSe({initialFilter:e=`all`}={}){let{api:t}=V(),n=_(),r=Ry(),i=Dx(),a=I(ob(t)),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(e),u=I({queryKey:Uy,queryFn:()=>qy(t)}),d=new Set(Object.values(u.data?.samples??{}).filter(e=>e!==null)),[f,p]=(0,m.useState)(``),g=(0,m.useRef)(null),v=Mx(g,`projects`),y=L({mutationFn:e=>jo(t,e),onSettled:async()=>{s(void 0),await n.invalidateQueries({queryKey:H.projects})}}),b=L({mutationFn:e=>m3(t,e.project.id,e.uploaded),onError:(e,t)=>r(`${t.project.title} wasn't changed: ${e.message} Press the button again.`,`error`),onSettled:async()=>{await n.invalidateQueries({queryKey:H.projects})}});jx({id:`projects.show.waiting`,title:`Show projects that need you`,group:`Projects`,keywords:[`waiting`,`filter`],run:()=>l(`waiting`)}),jx({id:`projects.show.ready`,title:`Show videos ready to upload`,group:`Projects`,keywords:[`upload`,`finished`,`filter`],run:()=>l(`ready`)}),jx({id:`projects.show.failed`,title:`Show failed projects`,group:`Projects`,keywords:[`error`,`filter`],run:()=>l(`failed`)});let x=(a.data?.projects??[]).filter(e=>i.includes(e.channelId)),S=f.trim().toLowerCase(),C=x.filter(e=>q7(e,c)&&(S===``||e.title.toLowerCase().includes(S)));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{title:`Projects`,meta:a.data===void 0?void 0:`${String(x.length)} ${x.length===1?`project`:`projects`} · ${i.channel?.name??`every channel`}`,actions:(0,h.jsxs)(CS,{to:`/play`,variant:`primary`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]})}),a.data?.projects.length===0?(0,h.jsx)(dde,{}):null,a.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-4 text-danger`,children:a.error.message}),a.data===void 0?a.error===null?(0,h.jsx)(zSe,{}):null:a.data.projects.length===0?(0,h.jsx)(T1,{title:`No projects yet`,actions:(0,h.jsx)(CS,{to:`/play`,variant:`primary`,children:`Make your first video`}),children:`Set up a run on Play: pick a template, type a topic and start.`}):(0,h.jsxs)(b1,{split:`aside`,children:[(0,h.jsxs)(x1,{label:`Project list`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`div`,{className:`relative w-full max-w-[320px]`,children:[(0,h.jsx)(Yc,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{type:`search`,ref:g,"aria-label":`Search projects`,"aria-keyshortcuts":Ux(v),placeholder:`Search projects`,value:f,onChange:e=>p(e.target.value),className:`sl-input pl-9`})]}),(0,h.jsx)(Vb,{label:`Show`,value:c,options:K7,onChange:l,className:`max-w-full overflow-x-auto`})]}),C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:x.length===0?`No projects in ${i.channel?.name??`this channel`} yet. Pick All channels in the rail to see the others.`:`No project matches. Clear the search or pick All.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(BSe,{projects:C}),(i.channel===void 0&&i.channels.length>1?i.channels.map(e=>({channel:e,projects:C.filter(t=>(t.channelId??i.channels[0]?.id)===e.id)})).filter(e=>e.projects.length>0):[{channel:void 0,projects:C}]).map(e=>(0,h.jsxs)(`section`,{"aria-label":e.channel?.name??`Projects`,className:`flex flex-col gap-2`,children:[e.channel===void 0?null:(0,h.jsx)(W,{as:`h3`,size:`small`,title:e.channel.name,meta:`${String(e.projects.length)} ${e.projects.length===1?`project`:`projects`}`}),(0,h.jsx)(PH,{label:e.channel?.name??`Projects`,children:e.projects.map(e=>(0,h.jsx)(RSe,{project:e,sample:d.has(e.id),onDelete:()=>s(e),onUploaded:t=>b.mutate({project:e,uploaded:t}),busy:b.isPending},e.id))})]},e.channel?.id??`all`))]})]}),(0,h.jsxs)(x1,{as:`aside`,label:`Projects at a glance`,children:[(0,h.jsxs)(`section`,{children:[(0,h.jsx)(W,{title:`At a glance`}),(0,h.jsx)(x2,{children:K7.filter(e=>e.value!==`all`).map(e=>(0,h.jsx)(S2,{label:e.label,value:String(x.filter(t=>q7(t,e.value)).length)},e.value))})]}),(0,h.jsxs)(`section`,{"aria-label":`Video queue`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Video queue`,info:`play.queue`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Videos started together, in the order they run, are on the calendar.`}),(0,h.jsx)(`div`,{children:(0,h.jsx)(wS,{to:`/calendar`,children:`Open calendar`})})]})]})]}),y.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`mt-3 text-small text-danger`,children:y.error.message}),(0,h.jsx)(Hy,{open:o!==void 0,title:o===void 0?``:`Delete "${o.title}"?`,consequence:`Moves the project to the trash for 30 days. Restore it or delete it for good in Settings → Trash.`,confirmLabel:`Delete project`,cancelLabel:`Keep it`,pending:y.isPending,onConfirm:()=>{o!==void 0&&y.mutate(o.id)},onCancel:()=>s(void 0)})]})}function RSe({project:e,sample:t,onDelete:n,onUploaded:r,busy:i}){let a=FSe(e),o=e.status===`running`;return(0,h.jsx)(FH,{title:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),t?(0,h.jsx)(kS,{children:`Sample`}):null]}),meta:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`span`,{children:[`${ISe(e)} · started ${Wu(e.createdAt)}`,e.views===void 0?``:` · ${e.views.toLocaleString()} views${e.ctr===void 0?``:` · ${String(e.ctr)}% CTR`}`]}),o?(0,h.jsx)(C2,{value:e.progress,label:`${e.title} progress`,valueText:`${String(Math.round(e.progress*100))}% done`,className:`max-w-[240px]`}):null]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(OS,{tone:a.tone,children:[a.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`${e.title}: ${a.word}`})]}),y3(e)?(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!0),children:`Mark uploaded`}):null,y3(e)?(0,h.jsx)(U,{id:`project.mark-uploaded`}):e.uploadedAt===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(kS,{children:`Uploaded`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Mark ${e.title} not uploaded`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!1),children:`Undo`})]}),(0,h.jsx)(Py,{label:`Delete ${e.title}`,size:`small`,disabled:o,disabledReason:`Cancel the run first, then delete it.`,onClick:n,children:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function zSe(){return(0,h.jsx)(`ul`,{"aria-label":`Loading projects`,className:`sl-list m-0 list-none p-0`,children:[0,1,2,3,4,5].map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,"data-slot":`skeleton-row`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-2/5 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[10px] w-1/4 rounded-control bg-sunken`})]}),(0,h.jsx)(`span`,{className:`h-[10px] w-16 rounded-control bg-sunken`})]},e))})}function BSe({projects:e}){let{api:t}=V(),n=_(),r=Ry(),i=Dx(),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(!1),l=L({mutationFn:()=>Ao(t,e.map(e=>e.id),a),onSuccess:e=>{n.invalidateQueries({queryKey:H.projects});let t=i.channels.find(e=>e.id===a)?.name??`the channel`;r(`Moved ${String(e.moved)} projects to ${t}.`,`success`),o(``)},onError:e=>r(`The projects weren't moved: ${e.message}`,`error`)});if(i.channels.length<2||e.length===0)return null;let u=i.channels.find(e=>e.id===a)?.name??``;return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Move the ${String(e.length)} shown to`}),(0,h.jsx)(VB,{"aria-label":`Channel to move the shown projects to`,className:`w-[220px]`,value:a,onChange:e=>o(e.currentTarget.value),options:[{value:``,label:`Choose a channel`},...i.channels.map(e=>({value:e.id,label:e.name}))]}),(0,h.jsx)(B,{type:`button`,variant:`secondary`,size:`small`,disabled:a===``||l.isPending,onClick:()=>e.length>1?c(!0):l.mutate(),children:`Move`}),(0,h.jsx)(Hy,{open:s,title:`Move ${String(e.length)} projects to ${u}?`,confirmLabel:`Move them`,tone:`primary`,consequence:`Every project the list shows now goes to ${u}, from ${e[0]?.title??``} to ${e.at(-1)?.title??``}. You can move them back the same way.`,onConfirm:()=>{c(!1),l.mutate()},onCancel:()=>c(!1)})]})}var VSe=`Prepare restrained delivery cues for a documentary narrator. Let the facts carry the scene. Use a measured pace and make only occasional changes where the supplied wording clearly calls for emphasis, reflection or tension. Prefer no cue to an unnecessary cue. Avoid theatrical emotion, invented reactions and routine laughter or sighs. Never rewrite, summarize, translate or add spoken words. Return only the cue annotations required by the supplied format contract.`;function J7({promptId:e,kind:t,from:n,onLeave:r}){let{api:i}=V(),a=_(),o=$F(),s=I(pb(i)),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=$N(JSON.stringify(e===void 0?[`new`,t,n??null]:[`prompt`,e])),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(void 0),b=v!==void 0,[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),T=s.data?.prompts,E=e??n,D=E===void 0?void 0:T?.find(e=>e.id===E),O=D===void 0?{kind:t,name:``,body:``}:e===void 0?{kind:D.kind,name:`${D.name} copy`,body:D.body}:{kind:D.kind,name:D.name,body:D.body},k=d??v??O,A=L({mutationFn:t=>Ps(i,t,e),onSuccess:async(e,t)=>{if(!e.ok){g(e.fields);return}y(e.value),f(e=>e===t?void 0:e),o({type:`prompt-saved`,id:e.value.id,kind:e.value.kind}),await a.invalidateQueries({queryKey:pb(i).queryKey})}}),j=L({mutationFn:e=>Is(i,e),onSuccess:async()=>{S(!1),f(void 0),await a.invalidateQueries({queryKey:pb(i).queryKey}),r(k.kind)}}),M=L({mutationFn:({id:e,on:t})=>Fs(i,e,t),onSettled:async()=>{await a.invalidateQueries({queryKey:pb(i).queryKey})}});K2(b,()=>{r(k.kind)});let ee=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},N=Z4(k,p),P=Q4(N),F=t3(k.body),te=k.body.trim()===``?[]:$4(N),ne=k.name.trim()===``?[]:e3(N);return QF({promptNamed:k.name.trim()!==``&&ne.length===0,promptBodyReady:k.body.trim()!==``&&te.length===0,promptHasKeywords:F.length>0&&te.length===0,promptSaveReady:P===void 0&&!A.isPending&&!b,promptSaving:A.isPending||b,promptIsArticle:k.kind===`article`,promptIsImage:k.kind===`image`}),s.error===null?E!==void 0&&T===void 0?(0,h.jsx)(Y2,{}):E!==void 0&&D===void 0?(0,h.jsx)(X7,{kind:t,children:`That prompt is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/prompts`,search:{kind:k.kind},children:`Prompts`})}),title:e===void 0?`New prompt`:`Edit prompt`,meta:`${NB(k.kind)} prompt`}),(0,h.jsxs)(`div`,{"data-tour":`prompt-editor`,className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{"data-tour":`prompt-name`,className:`min-w-[min(100%,240px)] flex-1`,children:(0,h.jsx)(LB,{label:`Name`,tip:`library.prompt.name`,...ne.length===0?{}:{error:ne.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:k.name,onChange:e=>{ee({...k,name:e.target.value},`name`)}})})}),(0,h.jsx)(Y4,{label:`Kind`,value:k.kind,options:MB,tip:`library.prompt.kind`,onPick:e=>{ee({...k,kind:e},`name`)}})]}),(0,h.jsxs)(`div`,{"data-tour":`prompt-body`,...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex min-h-8 items-end justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(U,{id:HSe[k.kind],label:`${NB(k.kind)} prompt body`,className:`-my-1`})]}),Y7(k.kind)?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>{let e=Y7(k.kind);e!==void 0&&(k.body.trim()===``?ee({...k,body:e.body},`body`):w(!0))},children:Y7(k.kind)?.label}),(0,h.jsx)(U,{id:`library.prompt.starter`,label:Y7(k.kind)?.label})]}):null]}),(0,h.jsx)(r3,{id:c,value:k.body,invalid:te.length>0,describedBy:te.length===0?void 0:l,onChange:e=>{ee({...k,body:e},`body`)}})]}),k.kind===`image`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e!==void 0&&D?.kind===`image`?(0,h.jsx)(Bb,{checked:M.isPending?M.variables.on:D.photorealistic===!0,disabled:M.isPending,onChange:t=>M.mutate({id:e,on:t}),label:`Draws photorealistic pictures`,tip:`library.prompt.photorealistic`}):(0,h.jsxs)(`span`,{className:`flex items-center gap-1 text-small text-ink-2`,children:[`Save this Image prompt first, then choose whether it draws photorealistic pictures.`,(0,h.jsx)(U,{id:`library.prompt.photorealistic`})]}),M.error===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small text-danger`,children:`Couldn't change Draws photorealistic pictures: ${M.error.message} Press the switch again.`})]}):null,(0,h.jsx)(`div`,{"data-tour":`prompt-save`,children:(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{S(!0)},blocked:P,blockedId:u,pending:A.isPending,saved:b,cancel:(0,h.jsx)(CS,{to:`/prompts`,search:{kind:k.kind},onClick:()=>{f(void 0)},variant:`secondary`,children:`Cancel`}),errors:[A.error,j.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{A.mutate(k)}})})]}),(0,h.jsx)(`div`,{"data-tour":`prompt-slots`,className:u4,children:(0,h.jsx)(G4,{slots:F,body:k.body,lint:te,lintId:l})})]}),(0,h.jsx)(Hy,{open:C,title:`Replace this prompt body?`,consequence:`The starter replaces the text in this editor. Nothing is saved until you choose Save.`,confirmLabel:`Use starter`,tone:`primary`,onConfirm:()=>{let e=Y7(k.kind);e!==void 0&&ee({...k,body:e.body},`body`),w(!1)},onCancel:()=>w(!1)}),(0,h.jsx)(Hy,{open:x,title:`Delete "${k.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:j.isPending,onConfirm:()=>{e!==void 0&&j.mutate(e)},onCancel:()=>{S(!1)}})]}):(0,h.jsx)(X7,{kind:k.kind,children:s.error.message})}var HSe={article:`library.prompt.body.article`,image:`library.prompt.body.image`,thumbnail:`library.prompt.body.thumbnail`,narration:`library.prompt.body.narration`,description:`library.prompt.body.description`,shorts:`library.prompt.body.shorts`,review:`library.prompt.body.review`,script:`library.prompt.body.script`};function Y7(e){if(e===`narration`)return{label:`Use Documentary Starter`,body:VSe};if(e===`description`)return{label:`Use Built-in Starter`,body:Xge};if(e===`shorts`)return{label:`Use Built-in Starter`,body:Rk}}function X7({kind:e,children:t}){return(0,h.jsx)(f4,{back:(0,h.jsx)(fa,{to:`/prompts`,search:{kind:e},children:`Back to Prompts`}),children:t})}function USe({kind:e,onKind:t,onUseInPlay:n,playBlocked:r}){let{api:i}=V(),a=_(),o=I(pb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=Mx(l,`prompts`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=L({mutationFn:e=>Is(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:H.prompts})}}),x=async(e,t)=>{let n=await Ps(i,{kind:e.kind,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:H.prompts}),n.ok?null:U4(n.fields)},S=o.data?.prompts.filter(t=>t.kind===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(I4,{action:(0,h.jsx)(GSe,{kind:e}),children:[(0,h.jsx)(zB,{type:`search`,ref:l,"aria-label":`Search prompts`,"aria-keyshortcuts":Ux(u),placeholder:`Search prompts`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...zb,children:[(0,h.jsx)(VB,{"aria-label":`Prompt kind`,value:e,className:`w-full sm:w-56`,options:MB,onChange:e=>{let n=MB.find(t=>t.value===e.target.value);n!==void 0&&t(n.value)}}),(0,h.jsx)(U,{id:`library.prompt.kind`})]})]}),o.error===null?null:(0,h.jsx)(P4,{what:`prompts`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(N4,{label:`Prompts`}):null:S.length===0?(0,h.jsxs)(T1,{title:`No ${NB(e).toLowerCase()} prompts yet`,children:[`A prompt is text with `,`{{keywords}}`,`; each keyword becomes a field on Play.`]}):(0,h.jsx)(QK,{className:j4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${NB(e).toLowerCase()} prompts match "${s.trim()}".`}):(0,h.jsx)(PH,{label:`Prompts`,children:w.map(e=>(0,h.jsx)(FH,{className:M4,title:(0,h.jsx)(W4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:WSe(e),selected:e.id===T?.id,actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/prompts/$promptId`,params:{promptId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/prompts/new`,search:{kind:e.kind,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(O4,{item:`prompt`,id:T.id,name:T.name,kicker:`${NB(T.kind)} prompt`,meta:`Updated ${A4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(CS,{to:`/prompts/$promptId`,params:{promptId:T.id},size:`small`,children:`Edit prompt`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The prompt wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(w4,{item:`prompt`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(Hy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function WSe(e){return`${NB(e.kind)} · ${k4(e.slots.length,`keyword`)} · updated ${A4(e.updatedAt)}`}function GSe({kind:e}){return(0,h.jsx)(CS,{to:`/prompts/new`,search:{kind:e},variant:`primary`,children:`New prompt`})}var KSe={template:`Template`,schedule:`Schedule`,draft:`Draft`,project:`Project`};function Z7(e){let t=[e.added.length>0?`${e.added.length} new`:null,e.priced.length>0?`${e.priced.length} repriced`:null,e.retired.length>0?`${e.retired.length} retired`:null].filter(e=>e!==null);return t.length===0?`No changes`:t.join(`, `)}function qSe(){let{api:e}=V(),t=_(),n=Ry(),r=I({queryKey:c1.catalogue,queryFn:()=>ufe(e),refetchInterval:3e4}),i=I({queryKey:c1.retired,queryFn:()=>d1(e)}),a=async()=>{await Promise.all([t.invalidateQueries({queryKey:[`provider-models`]}),t.invalidateQueries({queryKey:c1.retired})])},o=L({mutationFn:()=>dfe(e),onSuccess:async e=>{t.setQueryData(c1.catalogue,e),n(e.sync?.warning??`Model list checked: ${Z7(e.sync?.changes??JSe)}.`,e.sync?.warning?`error`:`success`),await a()}}),s=L({mutationFn:()=>ffe(e),onSuccess:async e=>{n(`Catalogue replaced with the published file.`,`success`),t.setQueryData(c1.catalogue,e),await a()}}),c=async()=>{await Promise.all([t.invalidateQueries({queryKey:c1.retired}),t.invalidateQueries({queryKey:iq}),t.invalidateQueries({queryKey:KV}),t.invalidateQueries({queryKey:[`play-drafts`]}),t.invalidateQueries({queryKey:[`projects`]}),t.invalidateQueries({queryKey:[`project`]})])},l=L({mutationFn:t=>f1(e,t),onSuccess:c}),u=L({mutationFn:()=>pfe(e),onSuccess:async e=>{n(e.failed.length===0?`Switched ${e.switched} ${e.switched===1?`use`:`uses`}.`:`Switched ${e.switched}; ${e.failed.length} could not be switched: ${e.failed[0]?.message??``}`,e.failed.length===0?`success`:`error`),await c()}}),d=r.data?.sync,f=i.data??[],p=f.filter(e=>e.blocked===null&&e.replacement!==null),m=o.error?.message??s.error?.message??r.error?.message??r.data?.warning??d?.warning??null;return jx({id:`settings.check-models`,title:`Check for new models`,group:`Settings`,context:`Models`,keywords:[`catalogue`,`prices`,`retired`],run:()=>{!o.isPending&&r.data?.path&&o.mutate()}}),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(W,{title:`Model catalogue`,info:`settings.models.catalogue`,children:[(0,h.jsx)(B,{disabled:o.isPending||!r.data?.path,onClick:()=>o.mutate(),children:o.isPending?`Checking…`:`Check now`}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,disabled:s.isPending||!r.data?.path,onClick:()=>s.mutate(),children:s.isPending?`Replacing…`:`Replace with published file`}),(0,h.jsx)(U,{id:`settings.models.replace`})]})]}),(0,h.jsxs)(`dl`,{className:`m-0 grid gap-x-6 border-t border-line text-small sm:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Catalogue file`}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 border-b border-line pb-3 break-all font-mono text-ink-2 sm:pt-3`,children:r.data?.path??`Not available`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Verified`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:r.data?.updatedAt??`date unavailable`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Last checked`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:d?.checkedAt?`${new Date(d.checkedAt).toLocaleString()} · ${Z7(d.changes)}`:`Not checked yet`})]}),d!==void 0&&d.changes.retired.length+d.changes.added.length>0?(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1 text-small text-ink-2`,children:[d.changes.added.length>0?(0,h.jsxs)(`span`,{children:[`New: `,d.changes.added.map(e=>e.name).join(`, `)]}):null,d.changes.retired.length>0?(0,h.jsxs)(`span`,{children:[`Retired: `,d.changes.retired.map(e=>e.name).join(`, `)]}):null]}):null,m===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-3 text-body text-danger`,children:m})]}),(0,h.jsxs)(`section`,{"aria-label":`Retired models in use`,children:[(0,h.jsx)(W,{title:`Retired models in use`,info:`settings.models.retired`,children:(0,h.jsx)(B,{variant:`primary`,disabled:u.isPending||p.length===0,onClick:()=>u.mutate(),children:u.isPending?`Switching…`:`Switch all`})}),i.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:i.error.message}):null,l.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:l.error.message}):null,f.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i.isPending?`Looking…`:`Nothing uses a retired model.`}):(0,h.jsx)(`ul`,{"aria-label":`Retired models in use`,className:`sl-list m-0 list-none p-0`,children:f.map(e=>(0,h.jsxs)(`li`,{className:`sl-row max-sm:grid-cols-1`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:KSe[e.kind]}),` `,(0,h.jsx)(`span`,{className:`font-semibold`,children:e.name})]}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[D1[e.slot],`: `,e.model,` (`,e.why===`retired`?`retired`:`no longer listed`,`)`]}),e.blocked===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e.blocked})]}),(0,h.jsx)(Iy,{children:(0,h.jsx)(B,{size:`small`,disabled:e.blocked!==null||e.replacement===null||l.isPending,onClick:()=>l.mutate(e),children:e.replacement===null?`No replacement`:`Switch to ${e.replacement.name}`})})]},e.key))})]})]})}var JSe={added:[],retired:[],priced:[]},YSe={ok:`Ready`,warning:`Check`,problem:`Needs fixing`,unused:`Not set up`},XSe={ok:`done`,warning:`waiting`,problem:`failed`,unused:`off`},ZSe={ok:`text-ink-2`,warning:`text-waiting`,problem:`text-danger`,skipped:`text-ink-3`};function Q7(){let{api:e}=V();return L({mutationFn:()=>u1(e)})}function QSe(e){let{api:t}=V(),[n,r]=(0,m.useState)({byId:new Map});return{one:L({mutationFn:e=>u1(t,e),onSuccess:t=>{r(n=>{let r=new Map(n.after===e?n.byId:[]);for(let e of t.providers)r.set(e.id,e);return{after:e,byId:r}})}}),latest:t=>n.after===e?n.byId.get(t.id)??t:t}}function $Se({run:e}={}){let t=Q7(),n=e??t,r=n.data,i=QSe(r?.checkedAt),a=r?.providers.filter(e=>e.state!==`unused`).map(i.latest)??[],o=r?.providers.filter(e=>e.state===`unused`)??[];return(0,h.jsxs)(`section`,{"aria-label":`Health check`,children:[(0,h.jsx)(W,{title:`Health check`,info:`settings.health`,children:e===void 0?(0,h.jsx)(B,{disabled:n.isPending,onClick:()=>{n.mutate()},children:n.isPending?`Checking…`:`Check all`}):void 0}),n.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:[`The health check didn't finish: `,n.error.message,` Press Check all to try again.`]}),i.one.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:`The check didn't finish: ${i.one.error.message} Press Check again on the provider to try again.`}),r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:n.isPending?`Checking every provider…`:`Not checked yet.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ul`,{"aria-label":`Health by provider`,className:`sl-list m-0 list-none p-0`,children:a.map(e=>(0,h.jsxs)(`li`,{className:`sl-row grid-cols-1 gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:e.displayName}),(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(OS,{tone:XSe[e.state],children:YSe[e.state]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Check ${e.displayName} again`,disabled:i.one.isPending,onClick:()=>{i.one.mutate(e.id)},children:i.one.isPending&&i.one.variables===e.id?`Checking…`:`Check again`})]})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-1 p-0`,children:e.checks.map(e=>(0,h.jsxs)(`li`,{className:z(`text-small`,ZSe[e.state]),children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.label,`:`]}),` `,e.detail]},e.label))})]},e.id))}),(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:o.length===0?`Checked at ${new Date(r.checkedAt).toLocaleTimeString()}.`:`Not set up and not used anywhere: ${o.map(e=>e.displayName).join(`, `)}.`})]})]})}var $7={openrouter:`settings.provider.openrouter`,"claude-code":`settings.provider.claude-code`,codex:`settings.provider.codex`,gemini:`settings.provider.gemini`,elevenlabs:`settings.provider.elevenlabs`,"openai-tts":`settings.provider.openai-tts`,cartesia:`settings.provider.cartesia`,inworld:`settings.provider.inworld`,"system-voice":`settings.provider.system-voice`,"google-tts":`settings.provider.google-tts`,fal:`settings.provider.fal`,replicate:`settings.provider.replicate`,"openai-image":`settings.provider.openai-image`,"google-image":`settings.provider.google-image`,"codex-image":`settings.provider.codex-image`};function e9(e){return JP(e)?{tone:`done`,word:`Ready`}:e.installed?{tone:`waiting`,word:`Needs attention`}:{tone:`off`,word:`Not found`}}function eCe({provider:e,readiness:t,kind:n}){let{api:r}=V(),i=_(),a=(0,m.useId)(),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(!1),u=e.cliPath?.configured??null,d=e.cliPath?.managedOnHost===!0,f=e.id===`claude-code`?`claude`:e.id===`codex-image`?`codex`:e.id,p=e.cliPath?.command??f,g=o??u??``,v=JP(t),y=L({mutationFn:t=>qo(r,e.id,t),onMutate:()=>l(!1),onSuccess:async e=>{i.setQueryData(H.providers,t=>t?{...t,providers:t.providers.map(t=>t.id===e.id?e:t)}:void 0),s(void 0),l(!0),await i.invalidateQueries({queryKey:H.providers})}});(0,m.useEffect)(()=>{if(!c)return;let e=setTimeout(()=>l(!1),G2);return()=>clearTimeout(e)},[c]);let[b,x]=(0,m.useState)(!1),S=(0,m.useId)();return(0,h.jsxs)(`section`,{"aria-labelledby":a,"data-ready":v,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:a,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(U,{id:$7[e.id],label:e.displayName})]}),(0,h.jsxs)(`p`,{className:`sl-section-head__meta`,children:[n,` · command line, no key needed`]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(DS,{tone:e9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:tCe(t,u)})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Command`}),(0,h.jsx)(HB,{className:`min-w-0 truncate`,title:p,children:p})]})]}),(0,h.jsxs)(Iy,{children:[d?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-small text-ink-2`,children:[`Managed on host`,(0,h.jsx)(U,{id:`settings.cli.managed-on-host`})]}):(0,h.jsx)(B,{"aria-expanded":b,"aria-controls":S,onClick:()=>x(e=>!e),children:b?`Close path`:`Change path`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:c?(0,h.jsx)(q2,{}):null})]}),d||!b?null:(0,h.jsx)(`form`,{id:S,onSubmit:e=>{e.preventDefault(),y.isPending||y.mutate(g)},children:(0,h.jsx)(LB,{label:`Executable path`,tip:`settings.cli.path`,help:(0,h.jsxs)(h.Fragment,{children:[`Leave blank to find `,(0,h.jsx)(HB,{children:f}),` on PATH. Use an absolute path without quotes or arguments.`]}),error:y.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{autoComplete:`off`,spellCheck:!1,maxLength:4096,"aria-label":`${e.displayName} Executable path`,className:`min-w-0 flex-1 basis-[220px]`,placeholder:f,value:g,disabled:y.isPending,onChange:e=>{s(e.target.value),l(!1),y.reset()}}),(0,h.jsx)(B,{type:`submit`,variant:`primary`,"aria-label":`Save ${e.displayName} path`,disabled:y.isPending,children:y.isPending?`Checking…`:`Save path`})]})})})]})}function tCe(e,t){return e.issue===void 0?e.installed?e.version===void 0?`Installed`:`Installed, version ${e.version}`:t===null?`Not found on PATH`:`Not found at saved path`:e.issue}var nCe=[`providers`,`system-voice`,`voices`];async function rCe(e){return R(await e.fetch(`${e.origin}/api/providers/system-voice/voices`))}function t9(e=!0){let{api:t}=V();return I({queryKey:nCe,queryFn:()=>rCe(t),enabled:e})}function n9(e){return e.available?{tone:`done`,word:`Ready`}:{tone:`off`,word:`Not found`}}function iCe({provider:e,readiness:t}){let n=(0,m.useId)(),r=t9(t.available).data?.engines??[];return(0,h.jsxs)(`section`,{"aria-labelledby":n,"data-ready":t.available,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:n,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(U,{id:$7[e.id],label:e.displayName})]}),(0,h.jsx)(`p`,{className:`sl-section-head__meta`,children:`Speech · built into this computer, no key needed`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(DS,{tone:n9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:t.available?`Found ${t.engine??`a speech program`}. Narration with it is free; a keyed voice (ElevenLabs, OpenAI) sounds better.`:t.issue??`No speech program was found on this computer.`})]}),r.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 list-none p-0 text-small text-ink-2`,children:r.map(e=>{let t=e.voices.length;return(0,h.jsx)(`li`,{children:`${e.name}: ${t} voice${t===1?``:`s`}`},e.id)})}),t.available?(0,h.jsx)(Iy,{children:(0,h.jsx)(CS,{to:`/settings`,search:{section:`voices`},children:`Add a system voice`})}):null]})}function aCe({value:e,onPick:t}){let n=t9(),r=n.data?.engines??[];return n.data!==void 0&&r.length===0?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:n.data.issue??`No speech program was found on this computer.`}):(0,h.jsxs)(VB,{value:e,onChange:e=>{for(let n of r){let r=n.voices.find(t=>t.id===e.target.value);if(r!==void 0)return t(r)}},children:[(0,h.jsx)(`option`,{value:``,children:n.data===void 0?`Looking for voices…`:`Pick a voice`}),r.map(e=>(0,h.jsx)(`optgroup`,{label:e.name,children:e.voices.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.language===void 0?e.name:`${e.name} (${e.language})`},e.id))},e.id))]})}var r9=[`llm`,`tts`,`image`],i9={llm:`Text`,tts:`Speech`,image:`Images`},oCe=`••••••••••••`;function sCe(e){return JP(e.readiness)}function cCe(e){return e.readiness.kind===`cli`?e9(e.readiness):e.readiness.kind===`local`?n9(e.readiness):e.readiness.hasKey?{tone:`done`,word:`Key saved`}:{tone:`off`,word:`No key`}}function lCe(){let{api:e}=V(),t=I(db(e)),[n,r]=(0,m.useState)(void 0),i=(0,m.useRef)(null),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{n!==void 0&&a.current&&(a.current=!1,typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&i.current?.scrollIntoView?.({block:`start`,behavior:`smooth`}))},[n]);let o=r9.flatMap(e=>(t.data?.providers??[]).filter(t=>t.family===e)),s=o.find(e=>!sCe(e))??o[0];if(n===void 0&&s!==void 0&&r(s.id),t.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message});if(t.data===void 0)return(0,h.jsx)(dCe,{});let c=o.find(e=>e.id===n)??s,l=o.every(e=>e.readiness.kind!==`keyed`||!e.readiness.hasKey),u=e=>{a.current=!0,r(e)};return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:[l?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Paste a key to make its provider selectable on Play.`}):null,r9.map(e=>(0,h.jsxs)(`section`,{"data-tour":`keys-${e}`,"aria-labelledby":`keys-${e}-title`,className:`grid items-start gap-x-8 gap-y-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(W,{id:`keys-${e}-title`,title:i9[e],size:`small`,className:`pb-2`}),(0,h.jsx)(PH,{label:`${i9[e]} providers`,children:o.filter(t=>t.family===e).map(e=>{let t=cCe(e);return(0,h.jsx)(FH,{title:e.displayName,meta:e.readiness.kind===`cli`?`Command line`:e.readiness.kind===`local`?`Built in, no key`:`API key`,selected:e.id===c?.id,onSelect:()=>u(e.id),actions:(0,h.jsx)(OS,{tone:t.tone,children:t.word})},e.id)})})]}),c===void 0||c.family!==e?null:(0,h.jsx)(`div`,{ref:i,className:`min-w-0 scroll-mt-4`,children:c.readiness.kind===`cli`?(0,h.jsx)(eCe,{provider:c,readiness:c.readiness,kind:i9[c.family]},c.id):c.readiness.kind===`local`?(0,h.jsx)(iCe,{provider:c,readiness:c.readiness},c.id):(0,h.jsx)(uCe,{provider:c,hasKey:c.readiness.hasKey},c.id)})]},e))]})}function uCe({provider:e,hasKey:t}){let{api:n}=V(),r=_(),i=(0,m.useId)(),a=(0,m.useId)(),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(void 0),C=(0,m.useId)(),w=PF[e.id],T=o.trim(),E=async()=>{b(!0),S(void 0);try{S(await lfe(n,e.id,T===``?void 0:T))}catch(e){p(e instanceof Error?e.message:String(e))}finally{b(!1)}},D=async()=>{l(!0),p(void 0);try{await Ko(n,e.id,o),s(``),d(!0),S(void 0),await r.invalidateQueries({queryKey:H.providers})}catch(e){p(e instanceof Error?e.message:String(e))}finally{l(!1)}},O=L({mutationFn:()=>Jo(n,e.id),onSuccess:async()=>{v(!1),p(void 0),await r.invalidateQueries({queryKey:H.providers})},onError:e=>{v(!1),p(e.message)}});(0,m.useEffect)(()=>{if(!u)return;let e=setTimeout(()=>{d(!1)},G2);return()=>{clearTimeout(e)}},[u]);let k=[t?a:void 0,x===void 0?void 0:C].filter(e=>e!==void 0).join(` `);return(0,h.jsxs)(`section`,{"aria-labelledby":i,"data-ready":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(W,{as:`h3`,size:`default`,id:i,title:t?e.displayName:`Set up ${e.displayName}`,info:$7[e.id],infoLabel:e.displayName,meta:`${i9[e.family]} · ${t?`a key is saved`:`needs an API key`}`,className:`pb-0`}),w===void 0?null:t?(0,h.jsxs)(`details`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Where to get a key`}),(0,h.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:(0,h.jsx)(a9,{guide:w})})]}):(0,h.jsx)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:(0,h.jsx)(a9,{guide:w})}),(0,h.jsx)(LB,{label:`${e.displayName} API key`,tip:`settings.providers.api-key`,help:`Stored on this computer only. Never in backups or exports.`,error:f,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{type:`password`,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 basis-[200px]`,"aria-describedby":k===``?void 0:k,placeholder:t?oCe:`Paste API key`,value:o,onChange:e=>{s(e.target.value)}}),(0,h.jsx)(B,{variant:`primary`,"aria-label":`Save ${e.displayName} key`,disabled:o.trim()===``||c,onClick:()=>{D()},children:`Save`})]})}),t?(0,h.jsx)(`span`,{id:a,className:`sr-only`,children:`A key is stored for this provider.`}):null,x===void 0?null:(0,h.jsx)(`p`,{id:C,role:x.ok?`status`:`alert`,className:z(`m-0 text-small`,x.ok?`text-accent-ink`:`text-danger`),children:x.message}),(0,h.jsxs)(Iy,{children:[(0,h.jsx)(B,{"aria-label":`Test ${e.displayName} key`,disabled:!t&&T===``||y,disabledReason:`Paste a key first.`,onClick:()=>{E()},children:y?`Testing…`:`Test`}),(0,h.jsx)(U,{id:`settings.providers.test-key`,label:`Test`}),(0,h.jsx)(B,{variant:`quiet`,"aria-label":`Remove ${e.displayName} key`,disabled:!t,onClick:()=>{v(!0)},children:`Remove`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:u?(0,h.jsx)(q2,{}):null})]}),(0,h.jsx)(Hy,{open:g,title:`Remove the ${e.displayName} key?`,consequence:`Projects that used this provider cannot retry until a key is saved.`,confirmLabel:`Remove key`,pending:O.isPending,onConfirm:()=>{O.mutate()},onCancel:()=>{v(!1)}})]})}function a9({guide:e}){let t=(e,t)=>(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`underline`,children:t});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ol`,{className:`m-0 list-decimal space-y-1 pl-5`,children:e.steps.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`Sign up: `,t(e.signUp.url,e.signUp.label),`. Make the key:`,` `,t(e.keyPage.url,e.keyPage.label),`.`,e.billing===void 0?null:(0,h.jsxs)(h.Fragment,{children:[` Credit: `,t(e.billing.url,e.billing.label),`.`]})]}),(0,h.jsx)(`p`,{className:`m-0`,children:e.permissions}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`More in the provider's `,t(e.docs.url,e.docs.label),`. After saving, choose Test.`]})]})}function dCe(){return(0,h.jsxs)(`div`,{className:`grid items-start gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,role:`status`,"aria-label":`Loading providers`,children:[(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:[[`llm`,4],[`tts`,5],[`image`,5]].map(([e,t])=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`span`,{className:`mb-2 block h-3 w-16 rounded-control bg-raised`}),(0,h.jsx)(`div`,{className:`sl-list`,children:Array.from({length:t},(t,n)=>`${e}-${n}`).map(e=>(0,h.jsxs)(`div`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`h-4 w-32 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-4 w-20 rounded-control bg-raised`})]},e))})]},e))}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-6 w-48 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-10 rounded-control bg-raised`})]})]})}function o9(e){return e.split(/[\s,;]+/).map(e=>e.trim().toLowerCase()).filter(e=>e!==``)}function fCe(e){return e.languages===void 0?`Any (not known)`:e.languages.map(e=>NO(e).code===e?NO(e).name:e).join(`, `)}function pCe({voice:e}){let{api:t}=V(),n=_(),r=(0,m.useId)(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)((e.languages??[]).join(`, `)),[c,l]=(0,m.useState)(void 0),u=L({mutationFn:()=>Os(t,e.id,o9(o)),onSuccess:async e=>{if(e!==void 0){l(e.message);return}a(!1),l(void 0),await n.invalidateQueries({queryKey:H.voices})}});return i?(0,h.jsxs)(`div`,{className:`grid gap-1`,children:[(0,h.jsx)(zB,{id:r,"aria-label":`Languages of ${e.name}`,value:o,placeholder:`es, de`,"aria-invalid":c!==void 0,onChange:e=>{s(e.target.value),l(void 0)}}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:c}),u.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:u.error.message}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(B,{size:`small`,disabled:u.isPending,onClick:()=>u.mutate(),children:`Save`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>{a(!1),l(void 0),s((e.languages??[]).join(`, `))},children:`Cancel`})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:fCe(e)}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Edit the languages of ${e.name}`,onClick:()=>a(!0),children:`Edit`})]})}function mCe(){let{api:e}=V(),t=_(),n=I(fb(e)),r=I(db(e)),[i,a]=(0,m.useState)(void 0),o=L({mutationFn:t=>As(e,t),onSettled:async()=>{a(void 0),await t.invalidateQueries({queryKey:H.voices})}}),s=L({mutationFn:({id:t,on:n})=>ks(e,t,n),onSettled:async()=>{await t.invalidateQueries({queryKey:H.voices})}}),c=(r.data?.providers??[]).filter(e=>e.family===`tts`);if(n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});let l=n.data?.voices;return(0,h.jsxs)(`div`,{"data-tour":`voices`,className:`flex min-w-0 flex-col gap-10`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 overflow-x-auto`,children:[(0,h.jsxs)(`table`,{className:`sl-table min-w-[640px] table-fixed`,...zb,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Voices`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:`Name`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[18%] pr-4`,children:`Provider`}),(0,h.jsx)(`th`,{scope:`col`,className:`pr-4`,children:`Voice ID`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Languages`,(0,h.jsx)(U,{id:`play.voices.languages`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[20%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Real person`,(0,h.jsx)(U,{id:`play.voices.real-person`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[96px]`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:l===void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,children:(0,h.jsx)(`span`,{className:`block h-4 w-64 rounded-control bg-raised`})})}):l.length===0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,className:`text-ink-2`,children:`Add a voice ID from your text-to-speech provider. Audio needs one to narrate.`})}):l.map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`truncate pr-4 font-semibold`,children:e.name}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:gCe(c,e.provider)}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:e.voiceId}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(pCe,{voice:e})}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(Bb,{checked:s.isPending&&s.variables.id===e.id?s.variables.on:e.imitatesRealPerson===!0,disabled:s.isPending,onChange:t=>s.mutate({id:e.id,on:t}),label:(0,h.jsx)(`span`,{className:`sr-only`,children:`${e.name} imitates a real person`}),className:`text-small`})}),(0,h.jsx)(`td`,{className:`text-right`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name}`,onClick:()=>{a(e)},children:`Remove`})})]},e.id))})]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:`Couldn't change Real person: ${s.error.message} Press the switch again.`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:o.error.message})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Add a voice`}),(0,h.jsx)(hCe,{tts:c})]}),(0,h.jsx)(Hy,{open:i!==void 0,title:i===void 0?``:`Remove ${i.name}?`,consequence:`Projects that used this voice keep the audio they made with it.`,confirmLabel:`Remove voice`,pending:o.isPending,onConfirm:()=>{i!==void 0&&o.mutate(i.id)},onCancel:()=>{a(void 0)}})]})}function hCe({tts:e}){let{api:t}=V(),n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(void 0),[d,f]=(0,m.useState)(void 0),p=l??e[0]?.id,g=L({mutationFn:e=>Ds(t,e),onSuccess:async e=>{if(!e.ok){f(e.refusal);return}i(``),o(``),c(``),f(void 0),await n.invalidateQueries({queryKey:H.voices})}}),v=(e,t)=>{t(),d?.field===e&&f(void 0)},y=e=>d?.field===e?d.message:void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`grid items-start gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(LB,{label:`Voice name`,tip:`play.voices.name`,error:y(`name`),children:(0,h.jsx)(zB,{value:r,onChange:e=>{let t=e.target.value;v(`name`,()=>{i(t)})}})}),(0,h.jsx)(LB,{label:`Provider`,tip:`play.voices.provider`,error:y(`provider`),children:(0,h.jsxs)(VB,{value:p??``,onChange:t=>{let n=e.find(e=>e.id===t.target.value);n!==void 0&&v(`provider`,()=>{u(n.id)})},children:[e.length===0?(0,h.jsx)(`option`,{value:``,children:`No speech provider`}):null,e.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.displayName},e.id))]})}),(0,h.jsx)(LB,{label:`Voice ID`,tip:`play.voices.voice-id`,error:y(`voiceId`),...p===`inworld`?{help:`Use an Inworld voice ID, such as Dennis, or one from your workspace.`}:{},children:p===`system-voice`?(0,h.jsx)(aCe,{value:a,onPick:e=>{v(`voiceId`,()=>{o(e.id)}),r.trim()===``&&i(e.name);let t=/^([a-z]{2,3})(?:[-_]|$)/i.exec(e.language??``)?.[1];s.trim()===``&&t!==void 0&&c(t.toLowerCase())}}):p===`google-tts`?(0,h.jsx)(VB,{value:a,options:[{value:``,label:`Pick a Gemini voice`},...IF.map(e=>({value:e.name,label:`${e.name} (${e.style})`}))],onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t),r.trim()===``&&i(t)})}}):(0,h.jsx)(zB,{className:`tabular-nums`,value:a,onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t)})}})}),(0,h.jsx)(LB,{label:`Languages`,tip:`play.voices.languages`,help:`Codes such as es, de.`,error:y(`languages`),children:(0,h.jsx)(zB,{value:s,placeholder:`es, de`,onChange:e=>{let t=e.target.value;v(`languages`,()=>{c(t)})}})}),(0,h.jsx)(B,{variant:`primary`,className:`md:mt-6`,disabled:p===void 0||d!==void 0||g.isPending,onClick:()=>{if(p!==void 0){let e=o9(s);g.mutate({provider:p,name:r,voiceId:a,...e.length===0?{}:{languages:e}})}},children:`Add voice`})]}),g.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:g.error.message})]})}function gCe(e,t){return e.find(e=>e.id===t)?.displayName??t}var s9=[`settings`,`notifications`],_Ce=`The test notification couldn't be shown: this browser only allows notifications from installed apps. Set a Notification URL below instead.`;function vCe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Browser and phone`,info:`settings.notifications`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(yCe,{}),(0,h.jsx)(bCe,{}),(0,h.jsx)(xCe,{})]})]})}function yCe(){let e=(0,m.useSyncExternalStore)(dP,lP,()=>!1),[t,n]=(0,m.useState)(cP),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=Ry(),c=e&&t===`granted`;async function l(e){if(i(void 0),!e){uP(!1);return}o(!0);try{let e=await mP();n(e);let t=pP(e);e===`granted`?(uP(!0),lP()||i(`Browser notifications couldn't be turned on because this browser blocks site storage for Slopify. Allow site data for this address in your browser's settings, then turn Browser notifications on again.`)):i(t??`Browser notifications weren't turned on because the permission prompt was dismissed. Turn Browser notifications on again and choose Allow.`)}finally{o(!1)}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(Bb,{label:`Browser notifications`,tip:`settings.notifications.browser`,checked:c,disabled:a,onChange:e=>void l(e)}),(0,h.jsx)(B,{variant:`quiet`,disabled:!c,disabledReason:`Turn Browser notifications on first.`,onClick:()=>{i(void 0);try{gP({projectId:`test`,text:IP},()=>{}),s(`Test notification sent to this browser.`,`success`)}catch{i(_Ce)}},children:`Send test notification`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Works while any Slopify tab is open.`}),r===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:r})]})}function bCe(){let e=(0,m.useSyncExternalStore)(CP,xP,()=>!0);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(Bb,{label:`Run sounds`,tip:`settings.notifications.sounds`,checked:e,onChange:SP}),(0,h.jsx)(B,{variant:`quiet`,onClick:()=>DP(`start`),children:`Play start`}),(0,h.jsx)(B,{variant:`quiet`,onClick:()=>DP(`end`),children:`Play end`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`A chime when a run starts and a different one when it finishes, fails or waits for you. Works while any Slopify tab is open; set your computer's volume for how loud.`})]})}function xCe(){let{api:e}=V(),t=_(),n=Ry(),r=(0,m.useId)(),i=I({queryKey:s9,queryFn:()=>Zo(e)}),[a,o]=(0,m.useState)(void 0),s=a??i.data?.url??``,c=RP(s),l=L({mutationFn:t=>$o(e,t),onSuccess:e=>{t.setQueryData(s9,e),o(void 0),n(e.url===null?`Notification URL removed.`:`Notification URL saved.`,`success`)}}),u=L({mutationFn:t=>es(e,t),onSuccess:()=>{n(`Test notification sent. Check the app or page behind your Notification URL.`,`success`)}}),d=c??l.error?.message??u.error?.message,f=l.isPending||u.isPending||i.data===void 0;return(0,h.jsxs)(LB,{label:`Notification URL`,tip:`settings.notifications.url`,help:`Works with no tab open, for example an ntfy topic on your phone.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{type:`url`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:`https://ntfy.sh/your-topic`,className:`min-w-0 flex-1 basis-[220px]`,value:s,disabled:i.data===void 0,"aria-invalid":c!==void 0,"aria-describedby":d===void 0?void 0:r,onChange:e=>{l.reset(),u.reset(),o(e.target.value)}}),(0,h.jsx)(B,{variant:`primary`,disabled:f||c!==void 0||a===void 0,onClick:()=>l.mutate(s),children:`Save`}),(0,h.jsx)(B,{variant:`quiet`,disabled:f||c!==void 0||s.trim()===``,onClick:()=>u.mutate(s),children:`Send test notification`})]}),i.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The saved Notification URL couldn't be read: `,i.error.message]}),d===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:d})]})}var c9={library:`The Library of Alexandria`,audiobook:`The Wind in the Willows (audiobook)`,podcast:`The Antikythera Mechanism (podcast)`};function SCe(){let{api:e}=V(),t=_(),n=I({queryKey:Wy,queryFn:()=>Qy(e)}),r=L({mutationFn:()=>eb(e),onSettled:async()=>{await t.invalidateQueries({queryKey:Wy}),await t.invalidateQueries({queryKey:Uy}),await t.invalidateQueries({queryKey:H.projects})}}),i=r.data?.samples??n.data?.samples;return(0,h.jsxs)(`div`,{className:`mt-8`,children:[(0,h.jsx)(W,{title:`Sample projects`,info:`settings.sample.restore`}),(0,h.jsx)(PH,{label:`Sample projects`,children:Object.keys(c9).map(e=>{let t=i?.[e]??null;return(0,h.jsx)(FH,{title:c9[e],meta:t===null?`Not in your projects`:`In your projects`,actions:t===null?void 0:(0,h.jsx)(wS,{to:`/projects/$projectId`,params:{projectId:t},className:NH,children:`Open`})},e)})}),(0,h.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(B,{disabled:r.isPending,onClick:()=>r.mutate(),children:r.isPending?`Restoring…`:`Restore samples`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Puts all three back as they shipped.`})]}),(0,h.jsx)(v1,{tone:r.error?`error`:`success`,children:r.error?.message??(r.isSuccess?`The samples are back in Projects.`:void 0)})]})}var CCe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function wCe(e){let[t,n,r]=e.split(`-`).map(Number),i=CCe[(n??0)-1];return i===void 0||r===void 0?e:`${String(r)} ${i} ${String(t)}`}function l9(e,t){let n=[e.range===void 0?e.version:`Versions ${e.range}`,`released ${wCe(e.date)}`].filter(e=>e!==void 0).join(`, `),r=n.charAt(0).toUpperCase()+n.slice(1);return e.version===t?`${r}. The version you are running.`:`${r}.`}function TCe({note:e,onNote:t}){let{api:n}=V(),r=I(tI(n));if(r.error!==null)return(0,h.jsx)(aI,{tone:`danger`,title:`The patch notes did not load`,actions:(0,h.jsx)(B,{onClick:()=>void r.refetch(),children:`Try again`}),children:`${r.error.message} Press Try again, or reload the page.`});if(r.data===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the patch notes…`});let{notes:i,version:a}=r.data,[o,...s]=i;if(o===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:`This version of Slopify has no patch notes.`});let c=e===void 0?void 0:i.find(t=>t.id===e),l=c!==void 0&&c.id!==o.id?c:void 0;return l===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e!==void 0&&c===void 0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`There are no patch notes called "${e}" in this version. The latest are below; older ones are under Earlier versions.`}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(W,{title:`Latest version`,meta:l9(o,a),info:`settings.patch-notes`}),(0,h.jsx)(Gz,{id:o.id})]}),s.length===0?null:(0,h.jsxs)(`details`,{className:`max-w-prose border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`Earlier versions (${String(s.length)})`}),(0,h.jsx)(PH,{label:`Earlier versions`,className:`mt-2`,children:s.map(e=>(0,h.jsx)(FH,{title:e.title,meta:l9(e,a),onSelect:()=>t(e.id),actions:(0,h.jsx)(B,{"aria-label":`Read ${e.title}`,onClick:()=>t(e.id),children:`Read`})},e.id))})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{children:(0,h.jsxs)(B,{variant:`quiet`,onClick:()=>t(void 0),children:[(0,h.jsx)(hc,{"aria-hidden":`true`,strokeWidth:1.75}),`Back to the latest patch notes`]})}),(0,h.jsx)(W,{title:`Earlier version`,meta:l9(l,a)}),(0,h.jsx)(Gz,{id:l.id})]})}var u9=[`trash`];async function ECe(e){return(await R(await e.client.trash.$get())).items}async function DCe(e,t,n){return(await R(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function OCe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await co(r)}var kCe={project:`Project`,prompt:`Prompt`,entry:`Intro/outro`,template:`Template`,schedule:`Schedule`};function ACe(e){return e.kind===`entry`&&e.detail!==null?e.detail===`intro`?`Intro`:`Outro`:e.kind===`prompt`&&e.detail!==null?`Prompt · ${e.detail}`:kCe[e.kind]}function jCe(e){return e<=0?`removed for good today`:e===1?`1 day left`:`${String(e)} days left`}var MCe=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}),NCe={project:[H.projects,[`calendar`]],prompt:[H.prompts],entry:[H.entries],template:[iq],schedule:[KV,[`calendar`]]};function PCe(){let{api:e}=V(),t=_(),n=Ry(),r=I({queryKey:u9,queryFn:()=>ECe(e)}),[i,a]=(0,m.useState)(void 0),o=async e=>{await Promise.all([u9,...NCe[e.kind]].map(e=>t.invalidateQueries({queryKey:e})))},s=L({mutationFn:t=>DCe(e,t.kind,t.id),onSuccess:async(e,t)=>{await o(t),n(e.renamedFrom===null?`Restored "${e.name}".`:`Restored as "${e.name}": another item is now called "${e.renamedFrom}".`,`success`),e.kind===`schedule`&&n(`The schedule is paused. Press Resume on Schedules to run it again.`,`info`)},onError:e=>n(e.message,`error`)}),c=L({mutationFn:t=>OCe(e,t.kind,t.id),onSuccess:async(e,t)=>{a(void 0),await o(t),n(`Deleted "${t.name}" for good.`,`success`)},onError:e=>{a(void 0),n(e.message,`error`)}}),l=r.data??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Trash`,info:`settings.trash`}),r.isPending?(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the trash…`}):r.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:r.error.message}):l.length===0?(0,h.jsx)(T1,{title:`The trash is empty`,children:`Anything you delete stays here for 30 days before it is removed for good.`}):(0,h.jsx)(PH,{label:`Deleted items`,children:l.map(e=>(0,h.jsx)(FH,{title:e.name,meta:`${ACe(e)} · deleted ${MCe.format(new Date(e.deletedAt))} · ${jCe(e.daysLeft)}`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>s.mutate(e),children:`Restore`}),(0,h.jsx)(B,{size:`small`,variant:`destructive`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>a(e),children:`Delete now`})]})},`${e.kind}:${e.id}`))}),(0,h.jsx)(Hy,{open:i!==void 0,title:i===void 0?``:`Delete "${i.name}" for good?`,consequence:i?.kind===`project`?`The project and every file it produced are removed from disk. This cannot be undone.`:i?.kind===`schedule`?`The schedule leaves the trash and cannot be restored. Its run history stays on Schedules.`:`It is removed for good. This cannot be undone.`,confirmLabel:`Delete for good`,cancelLabel:`Keep it`,pending:c.isPending,onConfirm:()=>{i!==void 0&&c.mutate(i)},onCancel:()=>{c.isPending||a(void 0)}})]})}var FCe=`https://github.com/GentBajko/slopify`,ICe=`https://www.patreon.com/cw/GentBajko`,LCe=`https://buymeacoffee.com/gentbajko`;function RCe(){return[{href:FCe,label:`GitHub`,detail:`The code, issues and releases.`,glyph:`github`},{href:ICe,label:`Patreon`,detail:`Monthly support for the project.`,glyph:`patreon`},{href:LCe,label:`Buy Me a Coffee`,detail:`A one-off thank you.`,glyph:`coffee`},{href:`https://slopify.stream/channel.html`,label:`How I run a channel with it`,detail:`A lore channel run on Slopify, start to finish.`}]}function zCe({onWhatsNew:e}){return(0,h.jsxs)(`div`,{className:`max-w-prose`,children:[(0,h.jsx)(W,{title:`About`}),(0,h.jsx)(`p`,{className:`m-0 mb-3 text-ink-2`,children:`Slopify is free and open source, and runs on your machine with your own keys. If it saves you time, you can support it here.`}),(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1 text-small text-ink-2`,children:[`Updates: the circular-arrows button at the foot of the sidebar (at the top on a phone).`,(0,h.jsx)(U,{id:`settings.updates`})]}),e===void 0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1`,children:[(0,h.jsx)(B,{onClick:e,children:`What's new in this version`}),(0,h.jsx)(U,{id:`settings.whats-new`})]}),(0,h.jsx)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:`Made by Gent Bajko. Apache License 2.0: anyone who redistributes Slopify or builds on it keeps this credit.`}),(0,h.jsx)(`ul`,{"aria-label":`Links`,className:`sl-list m-0 list-none p-0`,children:RCe().map(e=>(0,h.jsx)(`li`,{className:`sl-row`,children:(0,h.jsxs)(`div`,{className:`sl-row__lead`,children:[e.glyph===void 0?(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}):(0,h.jsx)(bS,{name:e.glyph,className:`shrink-0 text-ink-2`}),(0,h.jsxs)(`div`,{className:`sl-row__text`,children:[(0,h.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,className:`font-semibold text-ink underline underline-offset-3`,children:e.label}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.detail})]})]})},e.label))})]})}var d9=[`backups`],f9=1,p9=30;function m9(){return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}function BCe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=f9&&Number(t)<=p9?void 0:`Keep between ${f9} and ${p9} backups.`}function VCe(e){return{enabled:e.config.enabled,time:e.config.time,keep:String(e.config.keep),folder:e.config.folder??``}}function h9(){let{api:e}=V(),t=_(),n=Ry();return L({mutationFn:()=>Eo(e),onSuccess:e=>{t.setQueryData(d9,e),n(`Backup started. Its result shows here when it finishes.`,`success`)}})}function HCe(){let{api:e}=V(),t=_(),n=I({queryKey:d9,queryFn:()=>wo(e),refetchInterval:e=>e.state.data?.running===!0&&2e3}),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=L({mutationFn:t=>To(e,t),onSuccess:e=>{t.setQueryData(d9,e),i(void 0),o(!0)}}),c=h9();(0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>o(!1),G2);return()=>clearTimeout(e)},[a]);let l=n.data,u=r??(l===void 0?void 0:VCe(l)),d=u===void 0?void 0:BCe(u.keep),f=e=>{u!==void 0&&i({...u,...e})};return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Daily backup`,info:`settings.backups`,children:(0,h.jsx)(B,{variant:`primary`,disabled:l===void 0||l.running||c.isPending,onClick:()=>c.mutate(),children:`Back up now`})}),(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-x-4 gap-y-1 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{role:`status`,children:l===void 0?(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`}):UCe(l)}),(0,h.jsx)(`span`,{children:l===void 0?null:WCe(l)})]}),l?.status.detail?l.status.lastResult===`failed`?(0,h.jsx)(aI,{tone:`danger`,title:`Why the last backup stopped`,children:l.status.detail}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:l.status.detail}):null,c.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:c.error.message}):null]}),n.error?(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The backup settings couldn't be read: `,n.error.message]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(Bb,{label:`Back up automatically`,tip:`settings.backups.auto`,checked:u?.enabled===!0,disabled:u===void 0,className:`self-start`,onChange:e=>f({enabled:e})}),(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Time of day`,tip:`settings.backups.time`,help:`${m9()} time`,children:(0,h.jsx)(zB,{type:`time`,className:`w-[140px] tabular-nums`,value:u?.time??`03:00`,disabled:u===void 0,onChange:e=>f({time:e.target.value})})}),(0,h.jsx)(LB,{label:`Keep last`,tip:`settings.backups.keep`,help:`Backups kept in the folder.`,error:d,children:(0,h.jsx)(zB,{type:`number`,inputMode:`numeric`,min:f9,max:p9,step:1,className:`w-[88px] tabular-nums`,value:u?.keep??`5`,disabled:u===void 0,onChange:e=>f({keep:e.target.value})})}),(0,h.jsx)(LB,{label:`Folder`,tip:`settings.backups.folder`,className:`md:col-span-2`,...l===void 0?{}:{help:GCe(l)},children:(0,h.jsx)(zB,{value:u?.folder??``,placeholder:l?.defaultFolder??``,disabled:u===void 0,onChange:e=>f({folder:e.target.value})})})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{variant:`primary`,disabled:u===void 0||d!==void 0||s.isPending,onClick:()=>{u!==void 0&&(o(!1),s.mutate({enabled:u.enabled,time:u.time,timeZone:m9(),keep:Number(u.keep.trim()),folder:u.folder.trim()===``?null:u.folder.trim()}))},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(q2,{}):null}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 basis-full text-small text-danger`,children:s.error.message})]})]})]})}function g9(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function UCe(e){if(e.running)return`Backing up now…`;let{status:t}=e,n=t.lastSuccessAt===null?`No backup yet.`:`Last backup ${g9(t.lastSuccessAt)}${t.lastSuccessBytes===null?``:`, ${_9(t.lastSuccessBytes)}`}.`;return t.lastResult===`failed`&&t.lastAttemptAt!==null?`${n} The backup at ${g9(t.lastAttemptAt)} failed.`:t.lastResult===`waiting`?`${n} Waiting for projects to finish.`:n}function WCe(e){return e.config.enabled?e.overdue?`Next: shortly.`:e.nextRunAt===null?``:`Next: ${g9(e.nextRunAt)}.`:`Automatic backups are off.`}function GCe(e){let t=`${e.files.length} backup${e.files.length===1?``:`s`} here (${_9(e.files.reduce((e,t)=>e+t.bytes,0))}).`;return e.hostFolder===null?`Inside Slopify's Docker volume, not on your computer. Leave Folder empty to save backups in the Backups folder on your computer. ${t}`:`${e.config.folder===null?`Empty uses the default: `:`On your computer: `}${e.hostFolder}. ${t}`}function _9(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var v9=[`storage-files`];function KCe({usageQueryKey:e}){let{api:t}=V(),n=_(),r=Ry(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(),u=I({queryKey:v9,queryFn:()=>Po(t),refetchInterval:e=>b9(e.state.data)?1e3:!1}),d=L({mutationFn:e=>Fo(t,e),onMutate:()=>l(void 0),onSuccess:e=>{n.setQueryData(v9,e),a(!1)},onError:e=>l(e.message)}),f=L({mutationFn:()=>Io(t),onSuccess:e=>{e.opened||r(`Your files are in ${e.path}.`,`info`)},onError:e=>r(e.message,`error`)}),p=u.data,g=b9(p),v=p?.move?.phase;if((0,m.useEffect)(()=>{v===`done`&&n.invalidateQueries({queryKey:e})},[v,n,e]),p===void 0)return(0,h.jsx)(`div`,{children:(0,h.jsx)(W,{title:`Your files`,meta:u.error?`Where your files are is unavailable. Reload the page to try again.`:`Loading…`})});if(p.docker)return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Your files`,meta:p.folder??`The Docker project folder isn't set up.`,info:`settings.files.docker`,children:(0,h.jsx)(B,{disabled:p.folder===null||f.isPending,onClick:()=>f.mutate(),children:`Open folder`})}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),p.dockerCommand===null?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[`To move your projects to Documents/Slopify, run this on the computer running Docker (or use `,(0,h.jsx)(HB,{children:`--projects-dir <folder>`}),` for another folder):`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(HB,{className:`min-w-0 break-all`,children:p.dockerCommand}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>{let e=p.dockerCommand??``;navigator.clipboard.writeText(e).then(()=>r(`Command copied.`,`success`)).catch(()=>r(`Copying failed: this browser doesn't allow it here. Select the command and copy it yourself.`,`error`))},children:`Copy command`})]})]})]})]});let y=v===`failed`||v===`interrupted`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(W,{title:`Your files`,meta:p.folder,info:`settings.files`,children:[p.inDocuments||p.documentsRoot===null?null:(0,h.jsx)(B,{variant:`primary`,disabled:g||d.isPending,onClick:()=>d.mutate(`documents`),children:`Move to Documents/Slopify`}),(0,h.jsx)(B,{disabled:f.isPending,onClick:()=>f.mutate(),children:`Open folder`}),(0,h.jsx)(B,{variant:`quiet`,disabled:g||d.isPending,onClick:()=>{a(e=>!e),l(void 0)},children:`Choose another folder`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),i?(0,h.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),d.mutate(o)},children:[(0,h.jsx)(LB,{label:`New folder`,tip:`settings.files.new-folder`,help:`The full path; it must be empty or new.`,error:c,className:`min-w-0 flex-1 basis-80`,children:(0,h.jsx)(zB,{value:o,placeholder:p.documentsRoot??`/home/you/Videos/Slopify`,onChange:e=>s(e.target.value)})}),(0,h.jsx)(B,{type:`submit`,disabled:o.trim()===``||d.isPending,children:`Move here`})]}):c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:c}),p.move===null?null:g?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[p.move.phase===`copying`?`Copying`:`Checking the copy of`,` your files to`,` `,p.move.target,`: `,p.move.files,` of `,p.move.totalFiles,` files (`,Y5(p.move.bytes),` of `,Y5(p.move.totalBytes),`). Keep Slopify running until it finishes.`]}),(0,h.jsx)(C2,{label:p.move.phase===`copying`?`Files copied`:`Files checked`,value:p.move.totalBytes===0?0:p.move.bytes/p.move.totalBytes})]}):y?(0,h.jsx)(aI,{tone:v===`failed`?`danger`:`waiting`,title:v===`failed`?`Moving your files to ${p.move.target} stopped`:`Moving your files to ${p.move.target} didn't finish`,actions:(0,h.jsx)(B,{disabled:d.isPending,onClick:()=>d.mutate(p.move?.target??``),children:`Continue moving`}),children:p.move.error??`Slopify was stopped before the copy was checked, so it still uses the old folder. Continue moving picks up where it left off.`}):v===`done`&&p.move.oldFolder!==null?(0,h.jsxs)(aI,{tone:`info`,title:`Your files are now in ${p.move.target}`,children:[`Every file was copied and checked. The old folder `,p.move.oldFolder,` still has a copy; once your projects open fine, you can delete it to free the space.`]}):null]})]})}function y9({view:e}){let t=[[`Projects`,e.projects],[`Automatic backups`,e.backups],[`Exports`,e.exports]].filter(e=>e[1]!==null);return(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1`,children:t.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-3`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-all`,children:t})]},e))})}function b9(e){return e?.move?.phase===`copying`||e?.move?.phase===`verifying`}function qCe(){let{api:e}=V(),t=I(ub(e));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[t.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message}),t.data===void 0?t.error===null?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ewe,{cells:5}),(0,h.jsx)(twe,{})]}):null:(0,h.jsx)(YCe,{usage:t.data})]})}var JCe=[{id:`stage`,header:`Stage`,cell:e=>YP[e.stage]},{id:`model`,header:`Provider · model`,cell:e=>XCe(e)},{id:`in`,header:`Tokens in`,numeric:!0,cell:e=>x9.format(e.tokensIn)},{id:`out`,header:`Tokens out`,numeric:!0,cell:e=>x9.format(e.tokensOut)}];function YCe({usage:e}){let t=Object.values(e.counters).every(e=>e===0);return(0,h.jsxs)(b1,{split:`even`,children:[(0,h.jsxs)(x1,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(x2,{children:$Ce(e).map(e=>(0,h.jsx)(S2,{label:e.label,value:e.value},e.label))}),t?(0,h.jsx)(`p`,{className:`m-0 mt-3 text-body text-ink-2`,children:`Numbers appear after your first run.`}):null]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Machine ID ${e.machineId??`not made yet`} · Slopify ${e.appVersion}`})]}),(0,h.jsx)(x1,{children:(0,h.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Tokens by stage`,columns:JCe,rows:e.byStage,rowKey:e=>`${e.stage}/${e.provider}/${e.model??``}`,empty:`No stages have run yet.`,className:`min-w-[480px] [&_td]:pr-4 [&_th]:pr-4`})})})]})}function XCe(e){return e.model===null?e.provider:`${e.provider} · ${e.model}`}var x9=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),ZCe=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),QCe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function $Ce(e){let t=e.counters;return[{label:`Videos made`,value:x9.format(t.videosMade)},{label:`Hours of audio`,value:ZCe.format(t.audioSeconds/3600)},{label:`Images made`,value:x9.format(t.imagesMade)},{label:`Tokens used`,value:t.tokensUsed<1e6?x9.format(t.tokensUsed):QCe.format(t.tokensUsed)},{label:`Projects`,value:x9.format(t.projects)}]}function ewe({cells:e}){return(0,h.jsx)(`div`,{className:`sl-stats`,children:Array.from({length:e},(e,t)=>t).map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-8 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`})]},e))})}function twe(){return(0,h.jsx)(`div`,{className:`border-t border-line`,children:[0,1,2,3].map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-4 border-b border-line py-3`,children:[(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 max-w-[40%] rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`ml-auto h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`})]},e))})}var S9=[`storage-usage`],nwe=[S9,H.projects,[`project`],H.usage,H.documentThemes,KV,[`play-drafts`],H.settings,H.providers,H.voices,H.prompts,H.entries,H.staging,iq,eN,[`provider-models`]];async function rwe(e){await Promise.all(nwe.map(t=>e.invalidateQueries({queryKey:t})))}var C9=30,iwe=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function awe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=0&&Number(t)<=C9?void 0:`The silence gap is a whole number of seconds between 0 and ${String(C9)}.`}var w9=[{id:`general`,label:`General`,meta:`How Slopify starts on this computer.`},{id:`providers`,label:`Providers`,meta:`Keys stay on this machine and go only to their provider. Readiness is checked again before each run.`},{id:`voices`,label:`Voices`,meta:`A wrong voice ID shows up when the audio stage uses it.`},{id:`models`,label:`Models`,meta:`New models, prices and retirements, checked once a day.`},{id:`playback`,label:`Playback & appearance`,meta:`How narration is paced and how Slopify looks.`},{id:`notifications`,label:`Notifications`,meta:`When a run finishes, fails, waits for you, or a review needs a decision.`},{id:`channel-links`,label:`Channel links`,meta:`The links a YouTube description's {{Name}} placeholders fill from.`},{id:`studio`,label:`YouTube Studio`,meta:`The playlist upload packs name, and the Studio extension's pairing.`},{id:`storage`,label:`Backup & storage`,meta:`Export everything, import a backup, and see what uses disk space.`},{id:`backups`,label:`Backups`,meta:`A daily copy of everything, in a folder you choose.`},{id:`trash`,label:`Trash`,meta:`Deleted projects, prompts, templates and schedules, kept for 30 days.`},{id:`usage`,label:`Usage`,meta:`This machine only. The same counters, anonymised, feed slopify.stream.`},{id:`patch-notes`,label:`Patch notes`,meta:`What changed in each version of Slopify.`},{id:`about`,label:`About`,meta:`Free and open source, running on your machine with your own keys.`}];function owe(e){return w9.find(t=>t.id===e)?.id??`providers`}function swe(e){let t=document.createElement(`a`);t.href=`${e}/api/diagnostics`,t.download=`slopify-diagnostics.json`,document.body.append(t),t.click(),t.remove()}function cwe({section:e=`providers`,note:t,onSection:n=()=>{},onNote:r=()=>{}}){let{api:i}=V(),a=_(),o=Ry(),s=Q7(),c=h9(),l=w9.find(t=>t.id===e)??w9[0];return jx({id:`settings.check-providers`,title:`Check all providers`,group:`Settings`,keywords:[`health`,`keys`,`signed in`],run:()=>{n(`providers`),s.mutate()}}),jx({id:`settings.back-up-now`,title:`Back up now`,group:`Settings`,keywords:[`backup`],run:()=>{n(`backups`),c.mutate(void 0,{onError:e=>{o(`The backup didn't start: ${e.message} Open Settings → Backups to see its state.`,`error`)}})}}),jx({id:`settings.download-diagnostics`,title:`Download diagnostics`,group:`Settings`,keywords:[`support`,`bug report`],run:()=>{swe(i.origin)}}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:`Settings`,title:l.label,meta:l.meta,actions:(0,h.jsxs)(h.Fragment,{children:[e===`providers`?(0,h.jsx)(B,{disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check all`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(TS,{variant:`secondary`,href:`${i.origin}/api/diagnostics`,download:`slopify-diagnostics.json`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Download diagnostics`]}),(0,h.jsx)(U,{id:`settings.diagnostics`})]})]})}),(0,h.jsx)(ZK,{sections:(0,h.jsx)(X6,{label:`Settings sections`,children:w9.map(t=>(0,h.jsx)(Z6,{current:t.id===e,onClick:()=>n(t.id),className:`whitespace-nowrap max-md:w-auto`,children:t.label},t.id))}),children:(0,h.jsxs)(`section`,{"aria-label":l.label,className:`flex min-w-0 flex-col gap-10`,children:[e===`providers`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(I3,{}),(0,h.jsx)(lCe,{}),(0,h.jsx)($Se,{run:s})]}):null,e===`general`?(0,h.jsx)(Xb,{}):null,e===`voices`?(0,h.jsx)(mCe,{}):null,e===`models`?(0,h.jsx)(qSe,{}):null,e===`playback`?(0,h.jsx)(fwe,{}):null,e===`notifications`?(0,h.jsx)(vCe,{}):null,e===`channel-links`?(0,h.jsx)(cme,{}):null,e===`studio`?(0,h.jsx)(zpe,{}):null,e===`storage`?(0,h.jsx)(KCe,{usageQueryKey:S9}):null,e===`storage`?(0,h.jsx)(lwe,{}):null,e===`storage`?(0,h.jsx)(SCe,{}):null,e===`backups`?(0,h.jsx)(HCe,{}):null,e===`trash`?(0,h.jsx)(PCe,{}):null,e===`usage`?(0,h.jsx)(qCe,{}):null,e===`patch-notes`?(0,h.jsx)(TCe,{note:t,onNote:r}):null,e===`about`?(0,h.jsx)(zCe,{onWhatsNew:()=>{a.fetchQuery(tI(i)).then(e=>r(e.current??void 0),e=>{o(`The patch notes did not open: ${e instanceof Error?e.message:String(e)} Open Settings → Patch notes to try again.`,`error`)})}}):null]})})]})}var T9=`The backup wasn't imported. Check it is a file made with Export everything (.tar) or Export backup (.zip), then try again.`;function lwe(){let{api:e}=V(),t=_(),n=I({queryKey:S9,queryFn:()=>No(e),staleTime:3e4}),[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)({phase:`idle`}),[s,c]=(0,m.useState)({phase:`idle`}),[l,u]=(0,m.useState)(null),d=Ry(),[f,p]=(0,m.useState)(null);async function g(){p(null),o({phase:`preparing`});try{let t=await Co(e);if(!t.ready){o({phase:`idle`}),p(t.detail??`The backup can't be made right now. Try again in a moment.`);return}o({phase:`downloading`,bytes:t.bytes??0,projects:t.projects??0});let n=document.createElement(`a`);n.href=`${e.origin}/api/storage/export`,n.download=``,document.body.append(n),n.click(),n.remove()}catch(e){o({phase:`idle`}),p(e instanceof Error?e.message:`The backup couldn't be prepared. Try again in a moment.`)}}async function v(n){let r=n.name.toLowerCase().endsWith(`.zip`)||n.type===`application/zip`;if(n.size===0||r&&n.size>104857600){p(r?`This file is empty or larger than 100 MB. Choose a .zip made with Export backup, or a .tar made with Export everything.`:`This file is empty. Choose the .tar made with Export everything.`);return}i(!0),p(null),u(null),c({phase:`uploading`,sent:0,total:n.size});try{let i=await e.upload(`${e.origin}/api/storage/import`,n,r?`application/zip`:`application/x-tar`,(e,t)=>{c(e>=t?{phase:`importing`}:{phase:`uploading`,sent:e,total:t})}),a=await i.json();if(!i.ok)throw Error(a.detail??T9);a.projects===void 0?d(`Imported ${a.templates??0} template(s), ${a.fonts??0} uploaded font(s), and ${a.stagedFiles??0} staged file(s).${a.fontFallbacks?` ${a.fontFallbacks} missing legacy font reference(s) now use the default font.`:``}`,`success`):(u(a),d(`Backup imported.`,`success`)),await rwe(t)}catch(e){p(e instanceof Error?e.message:T9)}finally{c({phase:`idle`}),i(!1)}}async function y(){i(!0),p(null);try{let n=await e.fetch(`${e.origin}/api/storage/cleanup`,{method:`POST`}),r=await n.json();if(!n.ok)throw Error(`Clean orphan files didn't finish. Try again in a moment.`);d(`Removed ${r.orphanFiles??0} orphan project file(s) and ${r.stagedFiles??0} stale staged file(s).`,`success`),await t.invalidateQueries({queryKey:S9})}catch(e){p(e instanceof Error?e.message:`Clean orphan files didn't finish. Try again in a moment.`)}finally{i(!1)}}jx({id:`settings.export-everything`,title:`Export everything`,group:`Settings`,context:`Backup & storage`,keywords:[`backup`,`download`],run:()=>{!r&&a.phase!==`preparing`&&g()}});let b=r||a.phase===`preparing`,x=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(W,{title:`Export and import`,info:`settings.storage.export`,children:[(0,h.jsx)(B,{disabled:b,onClick:()=>void g(),children:`Export everything`}),(0,h.jsx)(B,{disabled:b,onClick:()=>x.current?.click(),children:`Import a backup`}),(0,h.jsx)(`input`,{ref:x,className:`sr-only`,type:`file`,tabIndex:-1,"aria-label":`Import a backup`,accept:`.tar,application/x-tar,.zip,application/zip`,disabled:b,onChange:e=>{let t=e.target.files?.[0];t&&v(t),e.target.value=``}}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`quiet`,disabled:b,onClick:()=>void y(),children:`Clean orphan files`}),(0,h.jsx)(U,{id:`settings.storage.clean`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Provider keys are never included in a backup. After importing, enter them again in Settings → Providers.`}),a.phase===`preparing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Preparing the backup…`}):null,a.phase===`downloading`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 min-w-0 flex-1 text-ink`,children:[`Downloading `,Y5(a.bytes),` (`,a.projects,` project`,a.projects===1?``:`s`,`). Your browser's downloads show its progress; keep Slopify running until it finishes.`]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>o({phase:`idle`}),children:`Dismiss`})]}):null,s.phase===`uploading`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[`Uploading the backup: `,Y5(s.sent),` of`,` `,Y5(s.total)]}),(0,h.jsx)(C2,{label:`Backup upload`,value:s.total===0?0:s.sent/s.total})]}):null,s.phase===`importing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Checking and importing the backup… large projects can take a minute.`}):null,f?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:f}):null]})]}),l?(0,h.jsx)(dwe,{result:l,onDismiss:()=>u(null)}):null,(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Disk space`,info:`settings.storage.disk`,meta:n.data?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`font-semibold text-ink`,children:[Y5(n.data.data),` stored`]}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[` `,`· `,Y5(Math.max(0,n.data.projects-n.data.trash.bytes)),` project files · `,Y5(n.data.staging),` staged files`,n.data.trash.projects>0?` · ${Y5(n.data.trash.bytes)} in the trash (${uwe(n.data.trash.projects)}), freed when removed for good`:null]})]}):n.error?`Storage usage is unavailable. Reload the page to try again.`:(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`})}),n.data&&n.data.byProject.length>0?(0,h.jsx)(jbe,{projects:n.data.byProject,queryKey:[...S9]}):null]})]})}function uwe(e){return e===1?`1 deleted project`:`${String(e)} deleted projects`}function E9(e,t){if(t===void 0)return null;let n=[t.added>0?`${t.added} added`:null,t.renamed>0?`${t.renamed} added as “(imported)” because the name was taken`:null,t.skipped>0?`${t.skipped} already here`:null].filter(e=>e!==null);return n.length===0?null:`${e}: ${n.join(`, `)}.`}function dwe({result:e,onDismiss:t}){let n=[e.projects.imported.length>0?`Projects: ${e.projects.imported.length} added (${Y5(e.files.bytes)} of files).`:`Projects: none added.`,E9(`Prompts`,e.prompts),E9(`Intros and outros`,e.entries),E9(`Channels`,e.channels),E9(`Cast members`,e.cast),E9(`Episode memories`,e.episodeMemories),E9(`Existing videos`,e.channelVideos),E9(`Document themes`,e.documentThemes),E9(`Templates`,e.templates),E9(`Schedules`,e.schedules),e.schedules.paused>0?`${e.schedules.paused} schedule(s) arrived paused so two installs never run them both; resume them on the Schedules screen.`:null,E9(`Voices`,e.voices),E9(`Play drafts`,e.drafts),e.settings.added+e.settings.kept>0?`Settings: ${e.settings.added} filled in${e.settings.kept>0?`, ${e.settings.kept} kept as this install has them`:``}.`:null,e.fonts>0?`Uploaded fonts: ${e.fonts} added.`:null,e.usage.alreadyImported?`Usage: this backup's history was already added before, so it wasn't counted twice.`:`Usage: ${e.usage.events} recorded event(s) added to the totals.`,`Provider keys are not in backups: enter them in Settings → Providers.`].filter(e=>e!==null);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{as:`h3`,title:`Imported the backup from ${e.backup.createdAt.slice(0,10)}`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:t,children:`Dismiss`})}),(0,h.jsxs)(`ul`,{"aria-label":`Import result`,className:`m-0 list-disc pl-5 text-small text-ink-2`,children:[n.map(e=>(0,h.jsx)(`li`,{className:`py-0.5`,children:e},e)),e.projects.skipped.map(e=>(0,h.jsxs)(`li`,{className:`py-0.5`,children:[`Skipped “`,e.title,`”: `,e.reason]},e.id))]})]})}function fwe(){let{api:e}=V(),t=_(),n=I(_b(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=L({mutationFn:t=>Xo(e,t),onMutate:e=>{let n=t.getQueryData(H.settings);return t.setQueryData(H.settings,e),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(H.settings,r.previous)},onSuccess:e=>{t.setQueryData(H.settings,e)}});if((0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>{o(!1)},G2);return()=>{clearTimeout(e)}},[a]),n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});if(n.data===void 0)return(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,role:`status`,"aria-label":`Loading settings`,children:[(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`})]});let c=n.data,l=r??String(c.silenceGapSeconds),u=awe(l);return(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Silence between segments`,tip:`settings.playback.silence-gap`,help:`Seconds of quiet between narrated segments.`,error:u??s.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{type:`number`,inputMode:`numeric`,min:0,max:C9,step:1,className:`w-[88px] tabular-nums`,value:l,"aria-invalid":u!==void 0,onChange:e=>{i(e.target.value)}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`seconds`}),(0,h.jsx)(B,{variant:`primary`,disabled:u!==void 0||s.isPending,onClick:()=>{o(!1),s.mutate({...c,silenceGapSeconds:Number(l.trim())},{onSuccess:()=>{i(void 0),o(!0)}})},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(q2,{}):null})]})}),(0,h.jsxs)(`div`,{className:`sl-field`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Appearance`}),(0,h.jsx)(U,{id:`settings.appearance`,className:`-my-1`})]}),(0,h.jsx)(Vb,{label:`Appearance`,value:c.appearance,options:iwe,className:`self-start`,onChange:e=>{s.mutate({...c,appearance:e})}})]}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(T6,{value:c.loudness??JO,switchLabel:`Level the volume for new runs`,switchTip:`settings.loudness`,onChange:e=>{s.mutate({...c,loudness:e})}})})]})}function pwe({open:e,onClose:t,onInstalled:n}){let{api:r}=V(),i=_(),a=I({queryKey:Uy,queryFn:()=>qy(r),enabled:e}),o=L({mutationFn:e=>Yy(r,e),onSuccess:()=>n(),onSettled:()=>i.invalidateQueries({queryKey:Uy})});return(0,h.jsxs)(HP,{open:e,title:`Add a starter pack`,onClose:t,footer:(0,h.jsx)(v1,{tone:o.error||a.error?`error`:`success`,children:o.error?.message??a.error?.message??(o.data===void 0?void 0:o.data.added?`Added: its prompts are in Prompts and its template is in this list.`:`That pack was already added.`)}),children:[(0,h.jsxs)(`p`,{className:`mb-4 flex items-center gap-1 text-small text-ink-2`,children:[`Prompts, a suggested voice and a template for one kind of channel.`,(0,h.jsx)(U,{id:`welcome.packs`})]}),(0,h.jsxs)(PH,{label:`Starter packs`,className:`[&_.sl-row__meta]:whitespace-normal`,children:[(a.data?.packs??[]).map(e=>(0,h.jsx)(FH,{title:e.name,meta:e.summary,actions:(0,h.jsx)(B,{disabled:e.installed||o.isPending,onClick:()=>o.mutate(e.id),children:e.installed?`Added`:`Add pack`})},e.id)),a.data===void 0?(0,h.jsx)(FH,{title:`Loading packs…`}):null]})]})}function mwe({template:e}){let{api:t}=V(),n=I({queryKey:[...iq,e.id,e.version],queryFn:async()=>{let n=await uq(t,e.id);if(!n.ok)throw Error(n.message);return n.value}});if(n.error)return(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The keywords of `,e.name,` didn't load. `,n.error.message,` Press Keywords again.`]});if(!n.data)return(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`Reading the keywords…`});let{form:r,librarySnapshot:i}=n.data.document,a=F1({form:r,prompts:i?.prompts??[],entries:i?.entries??[]}),o=F3(r.title),s=[...new Set([...a.keys(),...Object.keys(r.values)])];return(0,h.jsx)(V1,{keywords:s.map(e=>({name:e,value:r.values[e]??``,feeds:a.get(e)??[],topic:o.includes(e)})),empty:`No keywords: the prompts and the title name none.`})}async function hwe(e,t,n,r){let i=await fq(e,t.id,{baseVersion:t.version,mutationId:r,...n});if(!i.ok)throw Error(i.message);return i.value}function gwe({template:e}){return e===void 0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`Pick a template to see the keywords it fills.`}):(0,h.jsxs)(`section`,{"aria-label":`Keywords of ${e.name}`,className:`flex flex-col gap-4`,children:[(0,h.jsx)(W,{title:e.name,as:`h3`,info:`templates.edit`,className:`pb-0`}),(0,h.jsx)(mwe,{template:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`To change the settings, press Use in Play, change the draft, then Save a setup.`})]})}function _we({template:e,onClose:t}){let{api:n}=V(),r=_(),i=Array.from({length:e.version},(t,n)=>e.version-n),a=rt({queries:i.map(t=>({queryKey:[...iq,e.id,`version`,t],queryFn:async()=>{let r=await uq(n,e.id,t);if(!r.ok)throw Error(r.message);return r.value},staleTime:1/0}))}),o=a[0]?.data,[s,c]=(0,m.useState)(i[1]??e.version),l=a[i.indexOf(s)]?.data,u=(0,m.useRef)(crypto.randomUUID()),d=Ry(),f=L({mutationFn:t=>hwe(n,e,{name:t.name,document:t.document},u.current),onSuccess:async(n,i)=>{u.current=crypto.randomUUID(),d(`Restored version ${String(i.version)} of ${e.name} as version ${String(n.version)}.`,`success`),await r.invalidateQueries({queryKey:iq}),t()}}),p=a.find(e=>e.error!==null)?.error;return(0,h.jsx)(HP,{open:!0,title:`History of ${e.name}`,onClose:t,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[p?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:`A version couldn't be read: ${p.message} Close History and open it again.`}):null,(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Versions`,as:`h3`,info:`templates.history`}),(0,h.jsx)(PH,{label:`Versions of ${e.name}`,children:i.map((t,n)=>{let r=a[n]?.data;return(0,h.jsx)(FH,{title:`Version ${String(t)}`,selected:t===s,onSelect:()=>c(t),meta:r===void 0?`Loading…`:`${r.name} · ${D4(r.updatedAt)}`,actions:t===e.version?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(B,{size:`small`,"aria-label":`Restore version ${String(t)}`,disabled:r===void 0||f.isPending,disabledReason:r===void 0?`Reading the version`:`Restoring`,onClick:()=>{r!==void 0&&f.mutate(r)},children:`Restore`})},t)})}),(0,h.jsx)(v1,{tone:`error`,children:f.error===null?void 0:`The version wasn't restored: ${f.error.message}`})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`Compare with the current version`,as:`h3`}),o===void 0||l===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Loading the versions…`}):l.version===o.version?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.version===1?`This is the only version so far.`:`Pick an older version in the list to compare it.`}):(0,h.jsxs)(h.Fragment,{children:[l.name===o.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${l.name}" to "${o.name}".`}),(0,h.jsx)(b4,{before:D9(l),after:D9(o),beforeLabel:`Version ${String(l.version)}`,afterLabel:`Version ${String(o.version)} (current)`})]})]})]})})}function D9(e){return JSON.stringify(e.document,null,1).split(`
309
309
  `).map(e=>e.trim()).filter(e=>!/^[[\]{}],?$/u.test(e)).join(`
310
- `)}function gwe({onApplied:e,beforeApply:t,getGeneration:n,blocked:r=!1}){let{api:i}=V(),a=_(),o=I(lq(i)),s=I(cx(i)),[c,l]=(0,m.useState)(``),u=o.data?.filter(e=>c===``||E1(e)===c),d=e=>s.data?.find(t=>t.id===E1(e))?.name,f=I({queryKey:[`play-drafts`],queryFn:async()=>{let e=await WM(i);if(!e.ok)throw Error(e.message);return e.value.drafts}}),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),E=Ry(),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!1),[j,M]=(0,m.useState)(null),[ee,N]=(0,m.useState)(null),[P,F]=(0,m.useState)(null),te=(0,m.useRef)(new Map),ne=(0,m.useRef)(!1),re=(0,m.useRef)(null),ie=(0,m.useRef)(new Map),ae=(0,m.useRef)(!0);(0,m.useEffect)(()=>(ae.current=!0,()=>{ae.current=!1}),[]);async function oe(e){if(!ne.current){ne.current=!0,C(!0),T(null);try{await e()}catch(e){T(e instanceof Error?e.message:`That didn't finish. Try again.`)}finally{ne.current=!1,C(!1)}}}async function se(){let e=await KM(i,p);if(!e.ok)throw Error(e.message);let t=JSON.stringify([p,e.value.draft.version,v.trim(),b]);re.current?.key!==t&&(re.current={key:t,id:crypto.randomUUID()});let n=e.value.draft.document,r=o.data?.find(e=>e.id===n.templateSource?.id),s=b||n.channelId||(r?E1(r):void 0),c=await dq(i,{id:re.current.id,name:v.trim(),document:s===void 0?n:{...n,channelId:s}});if(!c.ok)throw re.current=null,Error(c.message);re.current=null,y(``),O(!1),E(`Template saved.`,`success`),await a.invalidateQueries({queryKey:iq})}async function ce(o){let s=n?.();if(r||t&&!await t())throw Error(`Save or discard the draft open in Play first, then apply the template again.`);if(!ae.current||s!==void 0&&s!==n?.())return;let c=`${o.id}:${o.version}`,l=ie.current.get(c);l||(l=crypto.randomUUID(),ie.current.set(c,l));let u=await _q(i,o,l);if(!u.ok)throw ie.current.delete(c),Error(u.message);if(!(!ae.current||s!==void 0&&s!==n?.())&&(await a.invalidateQueries({queryKey:[`play-drafts`]}),!(!ae.current||s!==void 0&&s!==n?.()))){if(await e(u.value.draft.id,()=>ae.current)!==!1)ie.current.delete(c);else throw Error(`The template's draft was created but didn't open. Press Use in Play again to open it.`)}}async function le(e){let t=`${e.id}:${e.version}`,n=te.current.get(t);n||(n=crypto.randomUUID(),te.current.set(t,n));let r=await uq(i,e.id);if(!r.ok)throw Error(r.message);let o=await dq(i,{id:n,name:`${e.name} copy`,document:r.value.document});if(!o.ok)throw Error(o.message);te.current.delete(t),E(`Duplicated as ${o.value.name}.`,`success`),await a.invalidateQueries({queryKey:iq})}async function ue(){if(!j)return;let e=j.id,t=await hq(i,j);if(!t.ok)throw Error(t.message);M(null),await a.cancelQueries({queryKey:iq}),a.setQueryData(iq,t=>t?.filter(t=>t.id!==e)),E(`Template moved to the trash. Restore it in Settings → Trash within 30 days.`,`success`),await a.invalidateQueries({queryKey:iq})}jx({id:`library.save-template`,title:`Save a setup as a template`,group:`Library`,keywords:[`template`,`new template`,`play draft`],run:()=>O(!0)});let de=w&&!j?{tone:`error`,text:w}:r?{tone:`warning`,text:`A run is still starting in Play. Wait for it to finish (or press Check Start result there), then apply a template.`}:o.error?{tone:`error`,text:o.error.message}:o.isPending?{tone:`info`,text:`Loading templates…`}:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(dwe,{open:k,onClose:()=>A(!1),onInstalled:()=>void a.invalidateQueries({queryKey:lq(i).queryKey})}),(0,h.jsxs)(I4,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`secondary`,onClick:()=>A(!0),"aria-expanded":k,children:`Add pack`}),(0,h.jsx)(U,{id:`welcome.packs`,label:`Add pack`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`primary`,onClick:()=>O(!0),"aria-expanded":D,children:`Save a setup`}),(0,h.jsx)(U,{id:`templates.save`,label:`Save a setup`})]})]}),children:[(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...zb,children:[(0,h.jsxs)(VB,{"aria-label":`Show templates of`,value:c,className:`w-full sm:w-56`,onChange:e=>l(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsx)(U,{id:`templates.show-channel`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Reuse a Play setup and its checkpoint choices. Use in Play creates a fresh draft to review.`,(0,h.jsx)(U,{id:`templates.apply`,label:`Use in Play`})]})]}),(0,h.jsxs)(`div`,{className:`mb-2 flex min-h-8 flex-wrap items-center gap-3`,children:[(0,h.jsx)(v1,{tone:de?.tone??`info`,children:de?.text}),o.error?(0,h.jsx)(B,{size:`small`,onClick:()=>void o.refetch(),children:`Reload templates`}):null,(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:S||o.isFetching,onClick:()=>void o.refetch(),children:`Refresh templates`})]}),o.data?.length===0?(0,h.jsx)(T1,{title:`No templates yet`,children:`Use Save a setup to keep a Play draft for reuse.`}):null,o.data?.length&&u?.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No templates in this channel.`}):null,o.isPending&&!o.error?(0,h.jsx)(N4,{label:`Project templates`}):null,u?.length?(0,h.jsx)(QK,{className:j4,list:(0,h.jsx)(PH,{label:`Project templates`,children:u.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(FH,{className:`max-md:grid-cols-1`,title:(0,h.jsx)(W4,{name:e.name,maxLength:120,onSelect:()=>N(e.id),onRename:async t=>{let n=await pq(i,e.id,t);return await a.invalidateQueries({queryKey:iq}),n}}),selected:e.id===ee,meta:(0,h.jsxs)(h.Fragment,{children:[d(e)===void 0?``:`${d(e)} · `,`Version `,e.version,` · updated`,` `,(0,h.jsx)(`time`,{dateTime:e.updatedAt,children:e.updatedAt.slice(0,10)})]}),actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,onClick:()=>N(e.id),children:`Edit`}),duplicate:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:S,disabledReason:`Working on the last press`,onClick:()=>void oe(()=>le(e)),children:`Duplicate`}),play:{run:()=>void oe(()=>ce(e)),blocked:r?`A run is still starting in Play. Wait for it, then use the template.`:S?`Working on the last press`:void 0},onHistory:()=>F(e),onDelete:()=>{M(e),T(null)}})}),(0,h.jsx)(O1,{kind:`template`,id:e.id,name:e.name})]},e.id))}),detail:(0,h.jsx)(mwe,{template:u.find(e=>e.id===ee)})}):null,(0,h.jsxs)(HP,{open:D,title:`Save a setup`,width:`narrow`,onClose:()=>O(!1),footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:w?`error`:`info`,children:w??(S?`Saving…`:void 0)}),(0,h.jsx)(B,{type:`submit`,form:`save-template-form`,variant:`primary`,disabled:S||!p||!v.trim(),children:`Save template`})]}),children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[`Choose a saved Play draft, or`,` `,(0,h.jsx)(fa,{to:`/play`,className:`text-accent-ink underline`,children:`open Play`}),` `,`to prepare one.`]}),(0,h.jsx)(`p`,{className:`mb-4 text-small text-ink-2`,children:`A template keeps the settings, not one video's topic.`}),(0,h.jsxs)(`form`,{id:`save-template-form`,"aria-label":`Save a setup`,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),p&&v.trim()&&oe(se)},children:[(0,h.jsx)(LB,{label:`Saved Play draft`,tip:`templates.save.draft`,help:f.isPending?`Loading saved drafts…`:f.data?.length===0?`No saved drafts yet.`:void 0,children:(0,h.jsxs)(VB,{value:p,required:!0,disabled:S,onChange:e=>g(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a draft`}),f.data?.filter(e=>e.readable).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.title||`Untitled draft`},e.id))]})}),f.error?(0,h.jsx)(aI,{tone:`danger`,title:`The saved drafts couldn't be loaded.`,actions:(0,h.jsx)(B,{size:`small`,onClick:()=>void f.refetch(),children:`Reload drafts`}),children:f.error.message}):null,(0,h.jsx)(LB,{label:`Template name`,id:`template-name`,tip:`templates.save.name`,children:(0,h.jsx)(zB,{value:v,required:!0,maxLength:120,disabled:S,onChange:e=>y(e.target.value)})}),(0,h.jsx)(LB,{label:`Channel`,id:`template-channel`,tip:`templates.save.channel`,children:(0,h.jsxs)(VB,{value:b,disabled:S,onChange:e=>x(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`The draft's channel`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]})]}),P===null?null:(0,h.jsx)(hwe,{template:P,onClose:()=>F(null)},`${P.id}:${String(P.version)}`),(0,h.jsx)(Hy,{open:j!==null,title:`Delete ${j?.name??`template`}?`,consequence:w??`Moves it to the trash for 30 days (Settings → Trash). Existing projects and drafts keep their setup.`,confirmLabel:`Delete template`,pending:S,onConfirm:()=>void oe(ue),onCancel:()=>{S||M(null)}})]})}function _we({page:e,anchor:t,words:n}){let{api:r}=V(),i=I(Yz(r)),a=I(Xz(r,e)),o=Ji(),[s,c]=(0,m.useState)(n??``);(0,m.useEffect)(()=>{c(n??``)},[n]);let l=(0,m.useRef)(null),u=(0,m.useMemo)(()=>new Set((i.data?.pages??[]).map(e=>e.id)),[i.data]),d=i.data?.pages.find(t=>t.id===e)?.title??e.replace(/-/g,` `),f=(0,m.useMemo)(()=>Ab(a.data??``),[a.data]),p=(0,m.useMemo)(()=>a.data===void 0?``:kb(f.body,u,e),[a.data,f.body,u,e]);(0,m.useEffect)(()=>{if(p===``)return;let e=l.current;if(e===null)return;let n=t===void 0?void 0:Mb(e,t,f.title===void 0?[]:[f.title]);n===void 0?window.scrollTo?.({top:0}):n.scrollIntoView?.({block:`start`})},[p,t,f.title]);let g=i.data?.groups.find(t=>t.pages.some(t=>t.id===e));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Help`}),(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`›`}),(0,h.jsx)(fa,{to:`/help/tutorials/$page`,params:{page:i.data?.home.id??`Home`},children:`Tutorials`})]}),title:d,meta:g===void 0?`Guides to every screen of Slopify, for the version you are running.`:g.title}),(0,h.jsx)(ZK,{className:`sl-workspace--tutorials`,sections:(0,h.jsx)(vwe,{index:i.data,page:e,onOpenHit:(e,t)=>{o({to:`/help/tutorials/$page`,params:{page:e.page},search:{q:t},...e.anchor===``?{}:{hash:e.anchor}})}}),children:a.error===null?(0,h.jsxs)(`div`,{ref:l,onClick:e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey)return;let t=e.target.closest(`a`),n=t?.getAttribute(`href`);if(t===null||n==null)return;let r=jb(n);if(r!==void 0){e.preventDefault(),o({to:`/help/tutorials/$page`,params:{page:r.page},...r.anchor===void 0?{}:{hash:r.anchor}});return}/^https?:/.test(n)&&(e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`))},children:[(0,h.jsx)(Wz,{markdown:p,label:`Tutorial`,what:`tutorial`,query:s,onQuery:c,anchorPrefix:`tutorial-`,children:(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the tutorial…`})}),i.data?.footer?(0,h.jsx)(`p`,{className:`mt-8 border-t border-line pt-4 text-small text-ink-3`,children:i.data.footer.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`)}):null]}):(0,h.jsx)(aI,{tone:`danger`,title:`This tutorial did not load`,actions:(0,h.jsx)(B,{onClick:()=>void a.refetch(),variant:`secondary`,children:`Try again`}),children:`${a.error.message} Press Try again, or pick another page on the left.`})})]})}function vwe({index:e,page:t,onOpenHit:n}){let{api:r}=V(),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),c=(0,m.useRef)(null),l=(0,m.useId)();Mx(c,`the tutorials`),(0,m.useEffect)(()=>{let e=setTimeout(()=>s(i.trim()),200);return()=>clearTimeout(e)},[i]);let u=I(Zz(r,o));return(0,h.jsxs)(`nav`,{"aria-label":`Tutorials`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(`label`,{htmlFor:l,className:`sr-only`,children:`Search all tutorials`}),(0,h.jsx)(Yc,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{ref:c,id:l,type:`search`,value:i,placeholder:`Search all tutorials`,onChange:e=>a(e.target.value),onKeyDown:e=>{let t=u.data?.hits[0];e.key===`Enter`&&t!==void 0&&(e.preventDefault(),n(t,o))},className:`sl-input pl-9`})]}),o===``?e===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the tutorials…`}):(0,h.jsxs)(`div`,{className:`sl-tutorials-nav flex flex-col gap-4`,children:[(0,h.jsx)(O9,{id:e.home.id,title:e.home.title,current:t}),e.groups.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,h.jsx)(`div`,{className:`sl-kicker px-2.5 pb-1`,children:e.title}),e.pages.map(e=>(0,h.jsx)(O9,{id:e.id,title:e.title,current:t},e.id))]},e.title))]}):(0,h.jsx)(ywe,{query:o,hits:u.data?.hits,error:u.error?.message})]})}function O9({id:e,title:t,current:n}){return(0,h.jsx)(fa,{to:`/help/tutorials/$page`,params:{page:e},"aria-current":e===n?`page`:void 0,className:`sl-tutorials-nav__link`,children:t})}function ywe({query:e,hits:t,error:n}){return n===void 0?t===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Searching…`}):t.length===0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`No tutorial mentions "${e}". Try fewer or other words.`}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{role:`status`,className:`m-0 px-2.5 text-small text-ink-3`,children:t.length===1?`1 section`:`${String(t.length)} sections`}),(0,h.jsx)(`ul`,{"aria-label":`Search results`,className:`m-0 flex list-none flex-col gap-1 p-0`,children:t.map(t=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(fa,{to:`/help/tutorials/$page`,params:{page:t.page},search:{q:e},...t.anchor===``?{}:{hash:t.anchor},className:`sl-tutorials-hit`,children:[(0,h.jsx)(`span`,{className:`block font-semibold text-ink`,children:t.heading===void 0?t.pageTitle:t.heading}),t.heading===void 0?null:(0,h.jsx)(`span`,{className:`block text-label text-ink-3`,children:t.pageTitle}),(0,h.jsx)(`span`,{className:`mt-0.5 block text-small text-ink-2`,children:t.snippet})]})},`${t.page}#${t.anchor}`))})]}):(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The search didn't run: ${n} Change the words or reload the page.`})}var bwe=[{id:`library`,name:`The Library of Alexandria`,summary:`A narrated video with its two shorts, article, PDF, description and images.`,action:`Explore the sample`},{id:`audiobook`,name:`The Wind in the Willows`,summary:`An audiobook: a narrator and two character voices, captions tagged with who speaks, MP3 and M4B with chapters.`,action:`See an audiobook`},{id:`podcast`,name:`The Antikythera Mechanism`,summary:`A two-host podcast with the speaker panel, name tags and portraits, and its MP3 and M4B.`,action:`Hear a podcast`}],k9=[{id:`found`,label:`1 · What you have`},{id:`style`,label:`2 · Pick a style`},{id:`make`,label:`3 · Make your first short`}];function xwe(e){return e.length<=2?e.join(` or `):`${e.slice(0,-1).join(`, `)} or ${e.at(-1)??``}`}function Swe(e){return e===void 0?{ready:!1,text:`Looking for a voice…`}:e.keyed===null?e.system.available?{ready:!0,text:`Narration uses your computer's built-in voice${e.system.engine===null?``:` (${e.system.engine})`}; add an ElevenLabs or OpenAI key later for a better one.`}:{ready:!1,text:e.system.issue??`No voice can narrate yet. Add an ElevenLabs or OpenAI key in Settings → Providers.`}:{ready:!0,text:`Narration uses your ${e.keyed} voice key.`}}function Cwe(){let{api:e}=V(),t=_(),n=Ji(),r=I({queryKey:Uy,queryFn:()=>qy(e)}),[i,a]=(0,m.useState)(`found`),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(void 0),f=(0,m.useRef)(void 0),p=L({mutationFn:()=>Jy(e),onSuccess:async()=>{await t.invalidateQueries({queryKey:Uy}),await n({to:`/`})}}),g=L({mutationFn:t=>Yy(e,t),onSettled:()=>t.invalidateQueries({queryKey:Uy})}),v=L({mutationFn:()=>(f.current??=crypto.randomUUID(),Xy(e,{topic:o,requestId:f.current,...c===``?{}:{packId:c}})),onSuccess:async({projectId:e})=>{f.current=void 0,d(e),await t.invalidateQueries({queryKey:H.projects}),await t.invalidateQueries({queryKey:H.voices})}}),y=e=>{e.preventDefault(),o.trim()!==``&&v.mutate()},b=r.data,x=b?.clis.filter(e=>e.ready)??[],S=Swe(b?.voice),C=c===``?`General`:b?.packs.find(e=>e.id===c)?.name??c,w=v.error?{tone:`error`,text:v.error.message}:g.error?{tone:`error`,text:g.error.message}:p.error?{tone:`error`,text:p.error.message}:v.isPending?{tone:`info`,text:`Starting your short…`}:void 0,T=k9.findIndex(e=>e.id===i),E=k9[T+1],D=k9[T-1];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{title:`Welcome to Slopify`,meta:`Make a video from a topic, with the tools already on this computer.`,actions:(0,h.jsx)(B,{variant:`quiet`,disabled:p.isPending,onClick:()=>p.mutate(),children:u===void 0?`Skip`:`Done`})}),r.error?(0,h.jsx)(aI,{tone:`danger`,title:`Could not read what this computer has`,className:`mb-6`,children:r.error.message}):null,(0,h.jsx)(C1,{items:k9.map(e=>({id:e.id,label:e.label})),value:i,onChange:a,label:`First-run steps`,idPrefix:`welcome`,className:`mb-6`}),(0,h.jsxs)(w1,{idPrefix:`welcome`,id:`found`,active:i===`found`,children:[(0,h.jsx)(W,{title:`Found on this computer`,info:`welcome.found`}),(0,h.jsxs)(PH,{label:`Tools found on this computer`,className:`mb-4`,children:[(b?.clis??[]).map(e=>(0,h.jsx)(FH,{title:e.name,actions:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.ready?`Ready${e.version===null?``:` · ${e.version}`}${e.draws?` · writes and draws`:` · writes`}`:e.installed?e.issue??`Installed, not usable yet`:`Not found`})},e.id)),b===void 0?(0,h.jsx)(FH,{title:`Looking for installed tools…`}):null]}),b!==void 0&&x.length>0?(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:`You can make a video now: no API keys are needed for ${xwe([`the text`,...x.some(e=>e.draws)?[`the images`]:[],...S.ready&&b.voice.keyed===null?[`the narration`]:[]])}.`}):null,b!==void 0&&x.length===0?(0,h.jsx)(aI,{tone:`waiting`,className:`mb-6`,title:`Nothing on this computer can write the script yet.`,actions:(0,h.jsx)(CS,{to:`/settings`,search:{section:`providers`},children:`Open Settings → Providers`}),children:`Install Claude Code, Codex or Gemini CLI and sign in to it, then press Check again; or add an OpenRouter key in Settings → Providers.`}):null,(0,h.jsx)(W,{title:`Narration voice`,info:`welcome.voice`}),b===void 0?(0,h.jsx)(PH,{label:`Narration voice`,className:`mb-6`,children:(0,h.jsx)(FH,{title:`Looking for a voice…`})}):(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})]}),(0,h.jsxs)(w1,{idPrefix:`welcome`,id:`style`,active:i===`style`,children:[(0,h.jsx)(W,{title:`Pick a style`,info:`welcome.pack`}),(0,h.jsx)(PH,{label:`Styles`,className:`mb-3 [&_.sl-row__meta]:whitespace-normal`,children:[{id:``,name:`General`,summary:`A neutral explainer style.`,installed:!1,library:!1},...(b?.packs??[]).map(e=>({...e,library:!0}))].map(e=>(0,h.jsx)(FH,{title:e.name,meta:e.summary,selected:c===e.id,actions:(0,h.jsxs)(h.Fragment,{children:[e.library?(0,h.jsx)(B,{variant:`quiet`,disabled:e.installed||g.isPending,"aria-label":e.installed?`${e.name} is in your library`:`Add ${e.name} to library`,onClick:()=>g.mutate(e.id),children:e.installed?`In your library`:`Add to library`}):null,(0,h.jsx)(B,{variant:c===e.id?`primary`:`secondary`,"aria-pressed":c===e.id,"aria-label":`Use ${e.name}`,onClick:()=>l(e.id),children:c===e.id?`Picked`:`Use this style`})]})},e.id===``?`general`:e.id))}),(0,h.jsxs)(`p`,{className:`mb-6 flex items-center gap-1 text-small text-ink-2`,...zb,children:[`Add to library keeps a pack's prompts and Play template for later videos.`,(0,h.jsx)(U,{id:`welcome.packs`,className:`-my-1`})]})]}),(0,h.jsxs)(w1,{idPrefix:`welcome`,id:`make`,active:i===`make`,children:[u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Make a 60-second short`,info:`welcome.short`}),(0,h.jsxs)(`p`,{className:`mb-3 text-small text-ink-2`,children:[`Style: ${C}. `,S.text]}),S.ready||b===void 0?null:(0,h.jsx)(`div`,{className:`mb-4`,children:(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})}),(0,h.jsxs)(`form`,{onSubmit:y,className:`mb-6 flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[240px] flex-1 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:`welcome-topic`,className:`text-label text-ink-2`,children:`Topic`}),(0,h.jsx)(U,{id:`welcome.topic`,className:`-my-1`})]}),(0,h.jsx)(P3,{id:`welcome-topic`,value:o,maxLength:200,placeholder:`Why the sea glows at night`,onChange:e=>s(e.target.value)})]}),(0,h.jsx)(B,{type:`submit`,variant:`primary`,disabled:o.trim()===``||v.isPending,disabledReason:`Type a topic first.`,children:`Make a 60-second short`})]})]}):(0,h.jsx)(aI,{tone:`info`,className:`mb-6`,title:`Your short is being made.`,actions:(0,h.jsx)(CS,{variant:`primary`,to:`/projects/$projectId`,params:{projectId:u},children:`Watch it being made`}),children:`It usually takes about five minutes. The live view shows each step as it runs; while you wait, look at a sample or set Slopify to start when you log in.`}),(0,h.jsx)(W,{title:`While you wait: the samples`,info:`welcome.samples`}),(0,h.jsx)(PH,{label:`Samples`,className:`mb-6 [&_.sl-row__meta]:whitespace-normal`,children:bwe.map(e=>{let t=b?.samples[e.id]??null;return(0,h.jsx)(FH,{title:e.name,meta:e.summary,actions:t===null?(0,h.jsx)(wS,{to:`/settings`,search:{section:`storage`},children:`Restore samples in Settings`}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:t},className:NH,children:e.action})},e.id)})}),(0,h.jsx)(Qb,{})]}),(0,h.jsxs)(y1,{status:(0,h.jsx)(v1,{tone:w?.tone??`info`,children:w?.text}),children:[(0,h.jsx)(wS,{to:`/play`,children:`Set up a long video instead`}),D===void 0?null:(0,h.jsx)(B,{onClick:()=>a(D.id),children:`Back`}),E===void 0?null:(0,h.jsx)(B,{variant:`primary`,onClick:()=>a(E.id),children:`Next: ${E.label.replace(/^\d · /,``)}`})]})]})}function A9({voice:e,checking:t,onCheck:n}){return e.ready?(0,h.jsx)(PH,{label:`Narration voice`,className:`mb-6 [&_.sl-row__title]:whitespace-normal`,children:(0,h.jsx)(FH,{lead:(0,h.jsx)(DS,{tone:`done`}),title:e.text,actions:(0,h.jsx)(CS,{variant:`quiet`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`})})}):(0,h.jsx)(aI,{tone:`waiting`,className:`mb-6`,title:`No voice can narrate the short yet.`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(CS,{variant:`primary`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`}),(0,h.jsx)(B,{disabled:t,onClick:n,children:t?`Checking…`:`Check again`})]}),children:e.text})}var j9=_a({component:gB}),wwe=ha({getParentRoute:()=>j9,path:`/`,component:cge}),M9=ha({getParentRoute:()=>j9,path:`projects`,validateSearch:e=>{let t=MSe(e.show);return t===void 0?{}:{show:t}},component:Twe});function Twe(){let{show:e}=M9.useSearch();return(0,h.jsx)(FSe,{initialFilter:e??`all`},e??`all`)}var Ewe=ha({getParentRoute:()=>j9,path:`welcome`,component:Cwe}),Dwe=ha({getParentRoute:()=>j9,path:`play`,component:rve}),N9=ha({getParentRoute:()=>j9,id:`_library`,component:hhe}),Owe=ha({getParentRoute:()=>j9,path:`library`,beforeLoad:()=>{throw cn({to:`/prompts`,search:{kind:`article`}})}}),kwe=ha({getParentRoute:()=>j9,path:`channels`,component:Kme}),P9=ha({getParentRoute:()=>j9,path:`channels/$channelId`,validateSearch:e=>e.tab===void 0?{}:{tab:Wme(e.tab)},component:Awe});function Awe(){let{channelId:e}=P9.useParams(),{tab:t}=P9.useSearch(),n=Ji();return(0,h.jsx)(Gme,{channelId:e,tab:t??`brand`,onTab:t=>{n({to:`/channels/$channelId`,params:{channelId:e},search:{tab:t},replace:!0})}},e)}var jwe=ha({getParentRoute:()=>N9,path:`templates`,component:Iwe}),Mwe=/^[0-9A-Za-z-]{1,64}$/;function F9(e){let t=Qpe(e.tab);return t===`releases`?{tab:t}:t===`schedules`?typeof e.schedule==`string`&&Mwe.test(e.schedule)?{tab:`schedules`,schedule:e.schedule}:{tab:`schedules`}:{}}var I9=ha({getParentRoute:()=>j9,path:`calendar`,validateSearch:F9,component:Fwe}),Nwe=ha({getParentRoute:()=>j9,path:`schedules`,beforeLoad:()=>{throw cn({to:`/calendar`,search:{tab:`schedules`},replace:!0})}}),Pwe=ha({getParentRoute:()=>j9,path:`schedules/$scheduleId`,beforeLoad:({params:e})=>{throw cn({to:`/calendar`,search:F9({tab:`schedules`,schedule:e.scheduleId}),replace:!0})}});function Fwe(){let e=F9(I9.useSearch()),t=Ji();return(0,h.jsx)(eme,{tab:e.tab??`weeks`,schedule:e.schedule,onTab:e=>{t({to:`/calendar`,search:e===`weeks`?{}:{tab:e},replace:!0})},onSchedule:e=>{t({to:`/calendar`,search:{tab:`schedules`,schedule:e},replace:!0})}})}function Iwe(){let e=XN(),t=Ji();return(0,h.jsx)(gwe,{getGeneration:e.generation,blocked:e.review.starting||e.review.uncertain||e.review.created!==null,beforeApply:e.flush,onApplied:async(n,r)=>!r()||!await e.open(n,r)||!r()?!1:(await t({to:`/play`}),r())})}var L9=ha({getParentRoute:()=>j9,path:`projects/$projectId`,component:Kwe}),R9=ha({getParentRoute:()=>N9,path:`prompts`,validateSearch:e=>({kind:PB(e.kind)}),component:qwe}),z9=ha({getParentRoute:()=>j9,path:`prompts/new`,validateSearch:e=>{let t=PB(e.kind);return typeof e.from==`string`?{kind:t,from:e.from}:{kind:t}},component:Jwe}),B9=ha({getParentRoute:()=>j9,path:`prompts/$promptId`,component:Ywe}),V9=ha({getParentRoute:()=>N9,path:`entries`,validateSearch:e=>({category:jB(e.category)}),component:Xwe}),H9=ha({getParentRoute:()=>j9,path:`entries/new`,validateSearch:e=>{let t=jB(e.category);return typeof e.from==`string`?{category:t,from:e.from}:{category:t}},component:Zwe}),U9=ha({getParentRoute:()=>j9,path:`entries/$entryId`,component:Qwe}),Lwe=ha({getParentRoute:()=>N9,path:`narration-aliases`,component:uge}),Rwe=ha({getParentRoute:()=>N9,path:`ab-results`,component:gV}),zwe=ha({getParentRoute:()=>N9,path:`document-themes`,component:_he}),W9=ha({getParentRoute:()=>j9,path:`document-themes/new`,validateSearch:e=>typeof e.from==`string`?{from:e.from}:{},component:$we}),G9=ha({getParentRoute:()=>j9,path:`document-themes/$themeId`,component:eTe});function Bwe(e){let t=e.section===void 0?void 0:iwe(e.section),n=t===`patch-notes`&&typeof e.note==`string`&&/^[0-9A-Za-z][0-9A-Za-z.-]{0,63}$/.test(e.note)?e.note:void 0;return{...t===void 0?{}:{section:t},...n===void 0?{}:{note:n}}}var K9=ha({getParentRoute:()=>j9,path:`settings`,validateSearch:Bwe,component:Gwe}),q9=ha({getParentRoute:()=>j9,path:`help/tutorials/$page`,validateSearch:e=>typeof e.q==`string`&&e.q.trim()!==``?{q:e.q.slice(0,200)}:{},component:Vwe});function Vwe(){let{page:e}=q9.useParams(),{q:t}=q9.useSearch(),n=za({select:e=>e.hash});return(0,h.jsx)(_we,{page:e,anchor:n===``?void 0:n,words:t})}var Hwe=ha({getParentRoute:()=>j9,path:`help`,beforeLoad:()=>{throw cn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),Uwe=ha({getParentRoute:()=>j9,path:`help/tutorials`,beforeLoad:()=>{throw cn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),Wwe=ha({getParentRoute:()=>j9,path:`usage`,beforeLoad:()=>{throw cn({to:`/settings`,search:{section:`usage`}})}});function Gwe(){let{section:e,note:t}=K9.useSearch(),n=Ji();return(0,h.jsx)(owe,{section:e??`providers`,note:t,onSection:e=>{n({to:`/settings`,search:{section:e},replace:!0})},onNote:e=>{n({to:`/settings`,search:{section:`patch-notes`,...e===void 0?{}:{note:e}}})}})}function Kwe(){let{projectId:e}=L9.useParams(),t=XN(),n=Ji();return(0,h.jsx)(ESe,{projectId:e,openDraft:async e=>!await t.flush()||!await t.open(e)?!1:(await n({to:`/play`}),!0)},e)}function qwe(){let{kind:e}=R9.useSearch(),t=Ji(),n=J9();return(0,h.jsx)(VSe,{kind:e,onKind:e=>{t({to:`/prompts`,search:{kind:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function J9(){let e=XN(),t=Ji();return{blocked:e.review.starting||e.review.uncertain||e.review.created!==null?`Play is starting a run from its draft. Wait for it to start, then try again.`:void 0,use:n=>{let r=pV(e.document,n);e.edit(r.document),t({to:`/play`}).then(()=>e.navigate(r.section,r.field))}}}function Jwe(){let{kind:e,from:t}=z9.useSearch(),n=Y9();return(0,h.jsx)(J7,{promptId:void 0,kind:e,from:t,onLeave:n},`${e}:${t??`new`}`)}function Ywe(){let{promptId:e}=B9.useParams(),t=Y9();return(0,h.jsx)(J7,{promptId:e,kind:`article`,from:void 0,onLeave:t},e)}function Y9(){let e=Ji();return t=>{e({to:`/prompts`,search:{kind:t}})}}function Xwe(){let{category:e}=V9.useSearch(),t=Ji(),n=J9();return(0,h.jsx)(vhe,{category:e,onCategory:e=>{t({to:`/entries`,search:{category:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function Zwe(){let{category:e,from:t}=H9.useSearch(),n=Z9();return(0,h.jsx)(i3,{entryId:void 0,category:e,from:t,onLeave:n})}function Qwe(){let{entryId:e}=U9.useParams(),t=Z9();return(0,h.jsx)(i3,{entryId:e,category:`intro`,from:void 0,onLeave:t})}function $we(){let{from:e}=W9.useSearch(),t=X9();return(0,h.jsx)(p4,{themeId:void 0,from:e,onLeave:t})}function eTe(){let{themeId:e}=G9.useParams(),t=X9();return(0,h.jsx)(p4,{themeId:e,from:void 0,onLeave:t})}function X9(){let e=Ji();return()=>{e({to:`/document-themes`})}}function Z9(){let e=Ji();return t=>{e({to:`/entries`,search:{category:t}})}}var tTe=j9.addChildren({homeRoute:wwe,projectsRoute:M9,welcomeRoute:Ewe,playRoute:Dwe,libraryRoute:N9.addChildren({promptsRoute:R9,entriesRoute:V9,templatesRoute:jwe,documentThemesRoute:zwe,narrationAliasesRoute:Lwe,abResultsRoute:Rwe}),schedulesRoute:Nwe,scheduleRoute:Pwe,calendarRoute:I9,libraryIndexRoute:Owe,channelsRoute:kwe,channelRoute:P9,projectRoute:L9,newPromptRoute:z9,promptRoute:B9,newEntryRoute:H9,entryRoute:U9,newDocumentThemeRoute:W9,documentThemeRoute:G9,settingsRoute:K9,usageRoute:Wwe,helpRoute:Hwe,tutorialsIndexRoute:Uwe,tutorialsRoute:q9});function nTe(){return Pa({routeTree:tTe})}function rTe(){let e,t,n=new Set;return{observe:r=>{if(e===void 0){e=r;for(let e of n)e();return}if(r!==e&&r!==t){t=r;for(let e of n)e()}},staleAt:()=>t,loadedAt:()=>e,subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function iTe(e,t){return async(n,r)=>{let i=await e(n,r),a=i.headers.get(`X-Slopify-Version`);return a!==null&&t.observe(a),i}}function aTe(){let e=new Map;return{observe:t=>{if(t.type===`stage.state`){let n=e.get(t.projectId);if(n){for(let[e,r]of n)r.stage===t.stage&&r.revisionId===t.revisionId&&r.workId===t.workId&&n.delete(e);n.size===0&&e.delete(t.projectId)}return}if(t.type!==`llm.preview`)return;let n=e.get(t.projectId)??new Map,r=JSON.stringify([t.revisionId,t.workId,t.callId]),i=n.get(r),a=(t.reset?t.text:`${i?.text??``}${t.text}`).slice(-65536);for(n.delete(r),n.set(r,{...t,text:a,reset:!0});n.size>8;){let e=n.keys().next().value;e!==void 0&&n.delete(e)}for(e.delete(t.projectId),e.set(t.projectId,n);e.size>16;){let t=e.keys().next().value;t!==void 0&&e.delete(t)}},snapshot:t=>[...e.get(t)?.values()??[]],snapshotAll:()=>[...e.values()].flatMap(e=>[...e.values()])}}var Q9=/\/events\/projects\/([^/?#]+)/,oTe=/\/events\/global(?:[?#]|$)/,sTe=[`running.count`,`staging.progress`,`staging.failed`,`schedule.topics`,`stage.state`,`stage.progress`,`article.delta`,`llm.preview`,`image.landed`,`narration.piece`,`project.state`,`project.updated`,`review.flagged`];function cTe(e){let t=new Set,n=aTe(),r,i=!1,a=(e,t,n)=>{for(let r of e.listeners.get(t)??[])r({data:n})},o=o=>{if(r!==void 0)return;let s=e(o);r=s,s.addEventListener(`open`,()=>{i=!0;for(let e of[...t])for(let t of e.opens)t()});for(let e of sTe)s.addEventListener(e,r=>{let i;try{let t=JSON.parse(r.data);typeof t.projectId==`string`&&(i=t.projectId),(e===`llm.preview`||e===`stage.state`)&&n.observe(t)}catch{return}for(let n of[...t])(n.projectId===void 0||n.projectId===i)&&a(n,e,r.data)})};return s=>{let c=Q9.exec(s)?.[1];if(c===void 0&&!oTe.test(s))return e(s);o(c===void 0?s:s.replace(Q9,`/events/global`));let l={projectId:c===void 0?void 0:decodeURIComponent(c),listeners:new Map,opens:new Set};return t.add(l),i&&queueMicrotask(()=>{if(t.has(l)){for(let e of l.opens)e();if(l.projectId!==void 0)for(let e of n.snapshot(l.projectId))a(l,`llm.preview`,JSON.stringify(e))}}),{addEventListener:(e,t)=>{if(e===`open`){l.opens.add(t);return}let n=l.listeners.get(e)??new Set;n.add(t),l.listeners.set(e,n)},close:()=>{t.delete(l),t.size===0&&r!==void 0&&(r.close(),r=void 0,i=!1)}}}}function lTe(e){let t=rTe(),n={api:bo(window.location.origin,iTe(window.fetch.bind(window),t),So(e=>{let n=e.headers.get(`X-Slopify-Version`);n!==null&&t.observe(n)})),openEvents:cTe(e=>new EventSource(e)),version:t};(0,ao.createRoot)(e).render((0,h.jsx)(m.StrictMode,{children:(0,h.jsx)(v,{client:new Ge,children:(0,h.jsx)(fte,{deps:n,children:(0,h.jsx)(La,{router:nTe()})})})}))}var $9=document.getElementById(`root`);if($9===null)throw Error(`index.html carries no #root element for the app to mount on`);lTe($9);export{Z2 as t};
310
+ `)}function vwe({onApplied:e,beforeApply:t,getGeneration:n,blocked:r=!1}){let{api:i}=V(),a=_(),o=I(lq(i)),s=I(cx(i)),[c,l]=(0,m.useState)(``),u=o.data?.filter(e=>c===``||E1(e)===c),d=e=>s.data?.find(t=>t.id===E1(e))?.name,f=I({queryKey:[`play-drafts`],queryFn:async()=>{let e=await WM(i);if(!e.ok)throw Error(e.message);return e.value.drafts}}),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),E=Ry(),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!1),[j,M]=(0,m.useState)(null),[ee,N]=(0,m.useState)(null),[P,F]=(0,m.useState)(null),te=(0,m.useRef)(new Map),ne=(0,m.useRef)(!1),re=(0,m.useRef)(null),ie=(0,m.useRef)(new Map),ae=(0,m.useRef)(!0);(0,m.useEffect)(()=>(ae.current=!0,()=>{ae.current=!1}),[]);async function oe(e){if(!ne.current){ne.current=!0,C(!0),T(null);try{await e()}catch(e){T(e instanceof Error?e.message:`That didn't finish. Try again.`)}finally{ne.current=!1,C(!1)}}}async function se(){let e=await KM(i,p);if(!e.ok)throw Error(e.message);let t=JSON.stringify([p,e.value.draft.version,v.trim(),b]);re.current?.key!==t&&(re.current={key:t,id:crypto.randomUUID()});let n=e.value.draft.document,r=o.data?.find(e=>e.id===n.templateSource?.id),s=b||n.channelId||(r?E1(r):void 0),c=await dq(i,{id:re.current.id,name:v.trim(),document:s===void 0?n:{...n,channelId:s}});if(!c.ok)throw re.current=null,Error(c.message);re.current=null,y(``),O(!1),E(`Template saved.`,`success`),await a.invalidateQueries({queryKey:iq})}async function ce(o){let s=n?.();if(r||t&&!await t())throw Error(`Save or discard the draft open in Play first, then apply the template again.`);if(!ae.current||s!==void 0&&s!==n?.())return;let c=`${o.id}:${o.version}`,l=ie.current.get(c);l||(l=crypto.randomUUID(),ie.current.set(c,l));let u=await _q(i,o,l);if(!u.ok)throw ie.current.delete(c),Error(u.message);if(!(!ae.current||s!==void 0&&s!==n?.())&&(await a.invalidateQueries({queryKey:[`play-drafts`]}),!(!ae.current||s!==void 0&&s!==n?.()))){if(await e(u.value.draft.id,()=>ae.current)!==!1)ie.current.delete(c);else throw Error(`The template's draft was created but didn't open. Press Use in Play again to open it.`)}}async function le(e){let t=`${e.id}:${e.version}`,n=te.current.get(t);n||(n=crypto.randomUUID(),te.current.set(t,n));let r=await uq(i,e.id);if(!r.ok)throw Error(r.message);let o=await dq(i,{id:n,name:`${e.name} copy`,document:r.value.document});if(!o.ok)throw Error(o.message);te.current.delete(t),E(`Duplicated as ${o.value.name}.`,`success`),await a.invalidateQueries({queryKey:iq})}async function ue(){if(!j)return;let e=j.id,t=await hq(i,j);if(!t.ok)throw Error(t.message);M(null),await a.cancelQueries({queryKey:iq}),a.setQueryData(iq,t=>t?.filter(t=>t.id!==e)),E(`Template moved to the trash. Restore it in Settings → Trash within 30 days.`,`success`),await a.invalidateQueries({queryKey:iq})}jx({id:`library.save-template`,title:`Save a setup as a template`,group:`Library`,keywords:[`template`,`new template`,`play draft`],run:()=>O(!0)});let de=w&&!j?{tone:`error`,text:w}:r?{tone:`warning`,text:`A run is still starting in Play. Wait for it to finish (or press Check Start result there), then apply a template.`}:o.error?{tone:`error`,text:o.error.message}:o.isPending?{tone:`info`,text:`Loading templates…`}:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(pwe,{open:k,onClose:()=>A(!1),onInstalled:()=>void a.invalidateQueries({queryKey:lq(i).queryKey})}),(0,h.jsxs)(I4,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`secondary`,onClick:()=>A(!0),"aria-expanded":k,children:`Add pack`}),(0,h.jsx)(U,{id:`welcome.packs`,label:`Add pack`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`primary`,onClick:()=>O(!0),"aria-expanded":D,children:`Save a setup`}),(0,h.jsx)(U,{id:`templates.save`,label:`Save a setup`})]})]}),children:[(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...zb,children:[(0,h.jsxs)(VB,{"aria-label":`Show templates of`,value:c,className:`w-full sm:w-56`,onChange:e=>l(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsx)(U,{id:`templates.show-channel`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Reuse a Play setup and its checkpoint choices. Use in Play creates a fresh draft to review.`,(0,h.jsx)(U,{id:`templates.apply`,label:`Use in Play`})]})]}),(0,h.jsxs)(`div`,{className:`mb-2 flex min-h-8 flex-wrap items-center gap-3`,children:[(0,h.jsx)(v1,{tone:de?.tone??`info`,children:de?.text}),o.error?(0,h.jsx)(B,{size:`small`,onClick:()=>void o.refetch(),children:`Reload templates`}):null,(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:S||o.isFetching,onClick:()=>void o.refetch(),children:`Refresh templates`})]}),o.data?.length===0?(0,h.jsx)(T1,{title:`No templates yet`,children:`Use Save a setup to keep a Play draft for reuse.`}):null,o.data?.length&&u?.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No templates in this channel.`}):null,o.isPending&&!o.error?(0,h.jsx)(N4,{label:`Project templates`}):null,u?.length?(0,h.jsx)(QK,{className:j4,list:(0,h.jsx)(PH,{label:`Project templates`,children:u.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(FH,{className:`max-md:grid-cols-1`,title:(0,h.jsx)(W4,{name:e.name,maxLength:120,onSelect:()=>N(e.id),onRename:async t=>{let n=await pq(i,e.id,t);return await a.invalidateQueries({queryKey:iq}),n}}),selected:e.id===ee,meta:(0,h.jsxs)(h.Fragment,{children:[d(e)===void 0?``:`${d(e)} · `,`Version `,e.version,` · updated`,` `,(0,h.jsx)(`time`,{dateTime:e.updatedAt,children:e.updatedAt.slice(0,10)})]}),actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,onClick:()=>N(e.id),children:`Edit`}),duplicate:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:S,disabledReason:`Working on the last press`,onClick:()=>void oe(()=>le(e)),children:`Duplicate`}),play:{run:()=>void oe(()=>ce(e)),blocked:r?`A run is still starting in Play. Wait for it, then use the template.`:S?`Working on the last press`:void 0},onHistory:()=>F(e),onDelete:()=>{M(e),T(null)}})}),(0,h.jsx)(O1,{kind:`template`,id:e.id,name:e.name})]},e.id))}),detail:(0,h.jsx)(gwe,{template:u.find(e=>e.id===ee)})}):null,(0,h.jsxs)(HP,{open:D,title:`Save a setup`,width:`narrow`,onClose:()=>O(!1),footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:w?`error`:`info`,children:w??(S?`Saving…`:void 0)}),(0,h.jsx)(B,{type:`submit`,form:`save-template-form`,variant:`primary`,disabled:S||!p||!v.trim(),children:`Save template`})]}),children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[`Choose a saved Play draft, or`,` `,(0,h.jsx)(fa,{to:`/play`,className:`text-accent-ink underline`,children:`open Play`}),` `,`to prepare one.`]}),(0,h.jsx)(`p`,{className:`mb-4 text-small text-ink-2`,children:`A template keeps the settings, not one video's topic.`}),(0,h.jsxs)(`form`,{id:`save-template-form`,"aria-label":`Save a setup`,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),p&&v.trim()&&oe(se)},children:[(0,h.jsx)(LB,{label:`Saved Play draft`,tip:`templates.save.draft`,help:f.isPending?`Loading saved drafts…`:f.data?.length===0?`No saved drafts yet.`:void 0,children:(0,h.jsxs)(VB,{value:p,required:!0,disabled:S,onChange:e=>g(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a draft`}),f.data?.filter(e=>e.readable).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.title||`Untitled draft`},e.id))]})}),f.error?(0,h.jsx)(aI,{tone:`danger`,title:`The saved drafts couldn't be loaded.`,actions:(0,h.jsx)(B,{size:`small`,onClick:()=>void f.refetch(),children:`Reload drafts`}),children:f.error.message}):null,(0,h.jsx)(LB,{label:`Template name`,id:`template-name`,tip:`templates.save.name`,children:(0,h.jsx)(zB,{value:v,required:!0,maxLength:120,disabled:S,onChange:e=>y(e.target.value)})}),(0,h.jsx)(LB,{label:`Channel`,id:`template-channel`,tip:`templates.save.channel`,children:(0,h.jsxs)(VB,{value:b,disabled:S,onChange:e=>x(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`The draft's channel`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]})]}),P===null?null:(0,h.jsx)(_we,{template:P,onClose:()=>F(null)},`${P.id}:${String(P.version)}`),(0,h.jsx)(Hy,{open:j!==null,title:`Delete ${j?.name??`template`}?`,consequence:w??`Moves it to the trash for 30 days (Settings → Trash). Existing projects and drafts keep their setup.`,confirmLabel:`Delete template`,pending:S,onConfirm:()=>void oe(ue),onCancel:()=>{S||M(null)}})]})}function ywe({page:e,anchor:t,words:n}){let{api:r}=V(),i=I(Yz(r)),a=I(Xz(r,e)),o=Ji(),[s,c]=(0,m.useState)(n??``);(0,m.useEffect)(()=>{c(n??``)},[n]);let l=(0,m.useRef)(null),u=(0,m.useMemo)(()=>new Set((i.data?.pages??[]).map(e=>e.id)),[i.data]),d=i.data?.pages.find(t=>t.id===e)?.title??e.replace(/-/g,` `),f=(0,m.useMemo)(()=>Ab(a.data??``),[a.data]),p=(0,m.useMemo)(()=>a.data===void 0?``:kb(f.body,u,e),[a.data,f.body,u,e]);(0,m.useEffect)(()=>{if(p===``)return;let e=l.current;if(e===null)return;let n=t===void 0?void 0:Mb(e,t,f.title===void 0?[]:[f.title]);n===void 0?window.scrollTo?.({top:0}):n.scrollIntoView?.({block:`start`})},[p,t,f.title]);let g=i.data?.groups.find(t=>t.pages.some(t=>t.id===e));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Help`}),(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`›`}),(0,h.jsx)(fa,{to:`/help/tutorials/$page`,params:{page:i.data?.home.id??`Home`},children:`Tutorials`})]}),title:d,meta:g===void 0?`Guides to every screen of Slopify, for the version you are running.`:g.title}),(0,h.jsx)(ZK,{className:`sl-workspace--tutorials`,sections:(0,h.jsx)(bwe,{index:i.data,page:e,onOpenHit:(e,t)=>{o({to:`/help/tutorials/$page`,params:{page:e.page},search:{q:t},...e.anchor===``?{}:{hash:e.anchor}})}}),children:a.error===null?(0,h.jsxs)(`div`,{ref:l,onClick:e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey)return;let t=e.target.closest(`a`),n=t?.getAttribute(`href`);if(t===null||n==null)return;let r=jb(n);if(r!==void 0){e.preventDefault(),o({to:`/help/tutorials/$page`,params:{page:r.page},...r.anchor===void 0?{}:{hash:r.anchor}});return}/^https?:/.test(n)&&(e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`))},children:[(0,h.jsx)(Wz,{markdown:p,label:`Tutorial`,what:`tutorial`,query:s,onQuery:c,anchorPrefix:`tutorial-`,children:(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the tutorial…`})}),i.data?.footer?(0,h.jsx)(`p`,{className:`mt-8 border-t border-line pt-4 text-small text-ink-3`,children:i.data.footer.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`)}):null]}):(0,h.jsx)(aI,{tone:`danger`,title:`This tutorial did not load`,actions:(0,h.jsx)(B,{onClick:()=>void a.refetch(),variant:`secondary`,children:`Try again`}),children:`${a.error.message} Press Try again, or pick another page on the left.`})})]})}function bwe({index:e,page:t,onOpenHit:n}){let{api:r}=V(),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),c=(0,m.useRef)(null),l=(0,m.useId)();Mx(c,`the tutorials`),(0,m.useEffect)(()=>{let e=setTimeout(()=>s(i.trim()),200);return()=>clearTimeout(e)},[i]);let u=I(Zz(r,o));return(0,h.jsxs)(`nav`,{"aria-label":`Tutorials`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(`label`,{htmlFor:l,className:`sr-only`,children:`Search all tutorials`}),(0,h.jsx)(Yc,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{ref:c,id:l,type:`search`,value:i,placeholder:`Search all tutorials`,onChange:e=>a(e.target.value),onKeyDown:e=>{let t=u.data?.hits[0];e.key===`Enter`&&t!==void 0&&(e.preventDefault(),n(t,o))},className:`sl-input pl-9`})]}),o===``?e===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the tutorials…`}):(0,h.jsxs)(`div`,{className:`sl-tutorials-nav flex flex-col gap-4`,children:[(0,h.jsx)(O9,{id:e.home.id,title:e.home.title,current:t}),e.groups.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,h.jsx)(`div`,{className:`sl-kicker px-2.5 pb-1`,children:e.title}),e.pages.map(e=>(0,h.jsx)(O9,{id:e.id,title:e.title,current:t},e.id))]},e.title))]}):(0,h.jsx)(xwe,{query:o,hits:u.data?.hits,error:u.error?.message})]})}function O9({id:e,title:t,current:n}){return(0,h.jsx)(fa,{to:`/help/tutorials/$page`,params:{page:e},"aria-current":e===n?`page`:void 0,className:`sl-tutorials-nav__link`,children:t})}function xwe({query:e,hits:t,error:n}){return n===void 0?t===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Searching…`}):t.length===0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`No tutorial mentions "${e}". Try fewer or other words.`}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{role:`status`,className:`m-0 px-2.5 text-small text-ink-3`,children:t.length===1?`1 section`:`${String(t.length)} sections`}),(0,h.jsx)(`ul`,{"aria-label":`Search results`,className:`m-0 flex list-none flex-col gap-1 p-0`,children:t.map(t=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(fa,{to:`/help/tutorials/$page`,params:{page:t.page},search:{q:e},...t.anchor===``?{}:{hash:t.anchor},className:`sl-tutorials-hit`,children:[(0,h.jsx)(`span`,{className:`block font-semibold text-ink`,children:t.heading===void 0?t.pageTitle:t.heading}),t.heading===void 0?null:(0,h.jsx)(`span`,{className:`block text-label text-ink-3`,children:t.pageTitle}),(0,h.jsx)(`span`,{className:`mt-0.5 block text-small text-ink-2`,children:t.snippet})]})},`${t.page}#${t.anchor}`))})]}):(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The search didn't run: ${n} Change the words or reload the page.`})}var Swe=[{id:`library`,name:`The Library of Alexandria`,summary:`A narrated video with its two shorts, article, PDF, description and images.`,action:`Explore the sample`},{id:`audiobook`,name:`The Wind in the Willows`,summary:`An audiobook: a narrator and two character voices, captions tagged with who speaks, MP3 and M4B with chapters.`,action:`See an audiobook`},{id:`podcast`,name:`The Antikythera Mechanism`,summary:`A two-host podcast with the speaker panel, name tags and portraits, and its MP3 and M4B.`,action:`Hear a podcast`}],k9=[{id:`found`,label:`1 · What you have`},{id:`style`,label:`2 · Pick a style`},{id:`make`,label:`3 · Make your first short`}];function Cwe(e){return e.length<=2?e.join(` or `):`${e.slice(0,-1).join(`, `)} or ${e.at(-1)??``}`}function wwe(e){return e===void 0?{ready:!1,text:`Looking for a voice…`}:e.keyed===null?e.system.available?{ready:!0,text:`Narration uses your computer's built-in voice${e.system.engine===null?``:` (${e.system.engine})`}; add an ElevenLabs or OpenAI key later for a better one.`}:{ready:!1,text:e.system.issue??`No voice can narrate yet. Add an ElevenLabs or OpenAI key in Settings → Providers.`}:{ready:!0,text:`Narration uses your ${e.keyed} voice key.`}}function Twe(){let{api:e}=V(),t=_(),n=Ji(),r=I({queryKey:Uy,queryFn:()=>qy(e)}),[i,a]=(0,m.useState)(`found`),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(void 0),f=(0,m.useRef)(void 0),p=L({mutationFn:()=>Jy(e),onSuccess:async()=>{await t.invalidateQueries({queryKey:Uy}),await n({to:`/`})}}),g=L({mutationFn:t=>Yy(e,t),onSettled:()=>t.invalidateQueries({queryKey:Uy})}),v=L({mutationFn:()=>(f.current??=crypto.randomUUID(),Xy(e,{topic:o,requestId:f.current,...c===``?{}:{packId:c}})),onSuccess:async({projectId:e})=>{f.current=void 0,d(e),await t.invalidateQueries({queryKey:H.projects}),await t.invalidateQueries({queryKey:H.voices})}}),y=e=>{e.preventDefault(),o.trim()!==``&&v.mutate()},b=r.data,x=b?.clis.filter(e=>e.ready)??[],S=wwe(b?.voice),C=c===``?`General`:b?.packs.find(e=>e.id===c)?.name??c,w=v.error?{tone:`error`,text:v.error.message}:g.error?{tone:`error`,text:g.error.message}:p.error?{tone:`error`,text:p.error.message}:v.isPending?{tone:`info`,text:`Starting your short…`}:void 0,T=k9.findIndex(e=>e.id===i),E=k9[T+1],D=k9[T-1];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{title:`Welcome to Slopify`,meta:`Make a video from a topic, with the tools already on this computer.`,actions:(0,h.jsx)(B,{variant:`quiet`,disabled:p.isPending,onClick:()=>p.mutate(),children:u===void 0?`Skip`:`Done`})}),r.error?(0,h.jsx)(aI,{tone:`danger`,title:`Could not read what this computer has`,className:`mb-6`,children:r.error.message}):null,(0,h.jsx)(C1,{items:k9.map(e=>({id:e.id,label:e.label})),value:i,onChange:a,label:`First-run steps`,idPrefix:`welcome`,className:`mb-6`}),(0,h.jsxs)(w1,{idPrefix:`welcome`,id:`found`,active:i===`found`,children:[(0,h.jsx)(W,{title:`Found on this computer`,info:`welcome.found`}),(0,h.jsxs)(PH,{label:`Tools found on this computer`,className:`mb-4`,children:[(b?.clis??[]).map(e=>(0,h.jsx)(FH,{title:e.name,actions:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.ready?`Ready${e.version===null?``:` · ${e.version}`}${e.draws?` · writes and draws`:` · writes`}`:e.installed?e.issue??`Installed, not usable yet`:`Not found`})},e.id)),b===void 0?(0,h.jsx)(FH,{title:`Looking for installed tools…`}):null]}),b!==void 0&&x.length>0?(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:`You can make a video now: no API keys are needed for ${Cwe([`the text`,...x.some(e=>e.draws)?[`the images`]:[],...S.ready&&b.voice.keyed===null?[`the narration`]:[]])}.`}):null,b!==void 0&&x.length===0?(0,h.jsx)(aI,{tone:`waiting`,className:`mb-6`,title:`Nothing on this computer can write the script yet.`,actions:(0,h.jsx)(CS,{to:`/settings`,search:{section:`providers`},children:`Open Settings → Providers`}),children:`Install Claude Code, Codex or Gemini CLI and sign in to it, then press Check again; or add an OpenRouter key in Settings → Providers.`}):null,(0,h.jsx)(W,{title:`Narration voice`,info:`welcome.voice`}),b===void 0?(0,h.jsx)(PH,{label:`Narration voice`,className:`mb-6`,children:(0,h.jsx)(FH,{title:`Looking for a voice…`})}):(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})]}),(0,h.jsxs)(w1,{idPrefix:`welcome`,id:`style`,active:i===`style`,children:[(0,h.jsx)(W,{title:`Pick a style`,info:`welcome.pack`}),(0,h.jsx)(PH,{label:`Styles`,className:`mb-3 [&_.sl-row__meta]:whitespace-normal`,children:[{id:``,name:`General`,summary:`A neutral explainer style.`,installed:!1,library:!1},...(b?.packs??[]).map(e=>({...e,library:!0}))].map(e=>(0,h.jsx)(FH,{title:e.name,meta:e.summary,selected:c===e.id,actions:(0,h.jsxs)(h.Fragment,{children:[e.library?(0,h.jsx)(B,{variant:`quiet`,disabled:e.installed||g.isPending,"aria-label":e.installed?`${e.name} is in your library`:`Add ${e.name} to library`,onClick:()=>g.mutate(e.id),children:e.installed?`In your library`:`Add to library`}):null,(0,h.jsx)(B,{variant:c===e.id?`primary`:`secondary`,"aria-pressed":c===e.id,"aria-label":`Use ${e.name}`,onClick:()=>l(e.id),children:c===e.id?`Picked`:`Use this style`})]})},e.id===``?`general`:e.id))}),(0,h.jsxs)(`p`,{className:`mb-6 flex items-center gap-1 text-small text-ink-2`,...zb,children:[`Add to library keeps a pack's prompts and Play template for later videos.`,(0,h.jsx)(U,{id:`welcome.packs`,className:`-my-1`})]})]}),(0,h.jsxs)(w1,{idPrefix:`welcome`,id:`make`,active:i===`make`,children:[u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Make a 60-second short`,info:`welcome.short`}),(0,h.jsxs)(`p`,{className:`mb-3 text-small text-ink-2`,children:[`Style: ${C}. `,S.text]}),S.ready||b===void 0?null:(0,h.jsx)(`div`,{className:`mb-4`,children:(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})}),(0,h.jsxs)(`form`,{onSubmit:y,className:`mb-6 flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[240px] flex-1 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:`welcome-topic`,className:`text-label text-ink-2`,children:`Topic`}),(0,h.jsx)(U,{id:`welcome.topic`,className:`-my-1`})]}),(0,h.jsx)(P3,{id:`welcome-topic`,value:o,maxLength:200,placeholder:`Why the sea glows at night`,onChange:e=>s(e.target.value)})]}),(0,h.jsx)(B,{type:`submit`,variant:`primary`,disabled:o.trim()===``||v.isPending,disabledReason:`Type a topic first.`,children:`Make a 60-second short`})]})]}):(0,h.jsx)(aI,{tone:`info`,className:`mb-6`,title:`Your short is being made.`,actions:(0,h.jsx)(CS,{variant:`primary`,to:`/projects/$projectId`,params:{projectId:u},children:`Watch it being made`}),children:`It usually takes about five minutes. The live view shows each step as it runs; while you wait, look at a sample or set Slopify to start when you log in.`}),(0,h.jsx)(W,{title:`While you wait: the samples`,info:`welcome.samples`}),(0,h.jsx)(PH,{label:`Samples`,className:`mb-6 [&_.sl-row__meta]:whitespace-normal`,children:Swe.map(e=>{let t=b?.samples[e.id]??null;return(0,h.jsx)(FH,{title:e.name,meta:e.summary,actions:t===null?(0,h.jsx)(wS,{to:`/settings`,search:{section:`storage`},children:`Restore samples in Settings`}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:t},className:NH,children:e.action})},e.id)})}),(0,h.jsx)(Qb,{})]}),(0,h.jsxs)(y1,{status:(0,h.jsx)(v1,{tone:w?.tone??`info`,children:w?.text}),children:[(0,h.jsx)(wS,{to:`/play`,children:`Set up a long video instead`}),D===void 0?null:(0,h.jsx)(B,{onClick:()=>a(D.id),children:`Back`}),E===void 0?null:(0,h.jsx)(B,{variant:`primary`,onClick:()=>a(E.id),children:`Next: ${E.label.replace(/^\d · /,``)}`})]})]})}function A9({voice:e,checking:t,onCheck:n}){return e.ready?(0,h.jsx)(PH,{label:`Narration voice`,className:`mb-6 [&_.sl-row__title]:whitespace-normal`,children:(0,h.jsx)(FH,{lead:(0,h.jsx)(DS,{tone:`done`}),title:e.text,actions:(0,h.jsx)(CS,{variant:`quiet`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`})})}):(0,h.jsx)(aI,{tone:`waiting`,className:`mb-6`,title:`No voice can narrate the short yet.`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(CS,{variant:`primary`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`}),(0,h.jsx)(B,{disabled:t,onClick:n,children:t?`Checking…`:`Check again`})]}),children:e.text})}var j9=_a({component:gB}),Ewe=ha({getParentRoute:()=>j9,path:`/`,component:uge}),M9=ha({getParentRoute:()=>j9,path:`projects`,validateSearch:e=>{let t=PSe(e.show);return t===void 0?{}:{show:t}},component:Dwe});function Dwe(){let{show:e}=M9.useSearch();return(0,h.jsx)(LSe,{initialFilter:e??`all`},e??`all`)}var Owe=ha({getParentRoute:()=>j9,path:`welcome`,component:Twe}),kwe=ha({getParentRoute:()=>j9,path:`play`,component:ave}),N9=ha({getParentRoute:()=>j9,id:`_library`,component:_he}),Awe=ha({getParentRoute:()=>j9,path:`library`,beforeLoad:()=>{throw cn({to:`/prompts`,search:{kind:`article`}})}}),jwe=ha({getParentRoute:()=>j9,path:`channels`,component:Jme}),P9=ha({getParentRoute:()=>j9,path:`channels/$channelId`,validateSearch:e=>e.tab===void 0?{}:{tab:Kme(e.tab)},component:Mwe});function Mwe(){let{channelId:e}=P9.useParams(),{tab:t}=P9.useSearch(),n=Ji();return(0,h.jsx)(qme,{channelId:e,tab:t??`brand`,onTab:t=>{n({to:`/channels/$channelId`,params:{channelId:e},search:{tab:t},replace:!0})}},e)}var Nwe=ha({getParentRoute:()=>N9,path:`templates`,component:Rwe}),Pwe=/^[0-9A-Za-z-]{1,64}$/;function F9(e){let t=Qpe(e.tab);return t===`releases`?{tab:t}:t===`schedules`?typeof e.schedule==`string`&&Pwe.test(e.schedule)?{tab:`schedules`,schedule:e.schedule}:{tab:`schedules`}:{}}var I9=ha({getParentRoute:()=>j9,path:`calendar`,validateSearch:F9,component:Lwe}),Fwe=ha({getParentRoute:()=>j9,path:`schedules`,beforeLoad:()=>{throw cn({to:`/calendar`,search:{tab:`schedules`},replace:!0})}}),Iwe=ha({getParentRoute:()=>j9,path:`schedules/$scheduleId`,beforeLoad:({params:e})=>{throw cn({to:`/calendar`,search:F9({tab:`schedules`,schedule:e.scheduleId}),replace:!0})}});function Lwe(){let e=F9(I9.useSearch()),t=Ji();return(0,h.jsx)(eme,{tab:e.tab??`weeks`,schedule:e.schedule,onTab:e=>{t({to:`/calendar`,search:e===`weeks`?{}:{tab:e},replace:!0})},onSchedule:e=>{t({to:`/calendar`,search:{tab:`schedules`,schedule:e},replace:!0})}})}function Rwe(){let e=XN(),t=Ji();return(0,h.jsx)(vwe,{getGeneration:e.generation,blocked:e.review.starting||e.review.uncertain||e.review.created!==null,beforeApply:e.flush,onApplied:async(n,r)=>!r()||!await e.open(n,r)||!r()?!1:(await t({to:`/play`}),r())})}var L9=ha({getParentRoute:()=>j9,path:`projects/$projectId`,component:Jwe}),R9=ha({getParentRoute:()=>N9,path:`prompts`,validateSearch:e=>({kind:PB(e.kind)}),component:Ywe}),z9=ha({getParentRoute:()=>j9,path:`prompts/new`,validateSearch:e=>{let t=PB(e.kind);return typeof e.from==`string`?{kind:t,from:e.from}:{kind:t}},component:Xwe}),B9=ha({getParentRoute:()=>j9,path:`prompts/$promptId`,component:Zwe}),V9=ha({getParentRoute:()=>N9,path:`entries`,validateSearch:e=>({category:jB(e.category)}),component:Qwe}),H9=ha({getParentRoute:()=>j9,path:`entries/new`,validateSearch:e=>{let t=jB(e.category);return typeof e.from==`string`?{category:t,from:e.from}:{category:t}},component:$we}),U9=ha({getParentRoute:()=>j9,path:`entries/$entryId`,component:eTe}),zwe=ha({getParentRoute:()=>N9,path:`narration-aliases`,component:fge}),Bwe=ha({getParentRoute:()=>N9,path:`ab-results`,component:gV}),Vwe=ha({getParentRoute:()=>N9,path:`document-themes`,component:yhe}),W9=ha({getParentRoute:()=>j9,path:`document-themes/new`,validateSearch:e=>typeof e.from==`string`?{from:e.from}:{},component:tTe}),G9=ha({getParentRoute:()=>j9,path:`document-themes/$themeId`,component:nTe});function Hwe(e){let t=e.section===void 0?void 0:owe(e.section),n=t===`patch-notes`&&typeof e.note==`string`&&/^[0-9A-Za-z][0-9A-Za-z.-]{0,63}$/.test(e.note)?e.note:void 0;return{...t===void 0?{}:{section:t},...n===void 0?{}:{note:n}}}var K9=ha({getParentRoute:()=>j9,path:`settings`,validateSearch:Hwe,component:qwe}),q9=ha({getParentRoute:()=>j9,path:`help/tutorials/$page`,validateSearch:e=>typeof e.q==`string`&&e.q.trim()!==``?{q:e.q.slice(0,200)}:{},component:Uwe});function Uwe(){let{page:e}=q9.useParams(),{q:t}=q9.useSearch(),n=za({select:e=>e.hash});return(0,h.jsx)(ywe,{page:e,anchor:n===``?void 0:n,words:t})}var Wwe=ha({getParentRoute:()=>j9,path:`help`,beforeLoad:()=>{throw cn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),Gwe=ha({getParentRoute:()=>j9,path:`help/tutorials`,beforeLoad:()=>{throw cn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),Kwe=ha({getParentRoute:()=>j9,path:`usage`,beforeLoad:()=>{throw cn({to:`/settings`,search:{section:`usage`}})}});function qwe(){let{section:e,note:t}=K9.useSearch(),n=Ji();return(0,h.jsx)(cwe,{section:e??`providers`,note:t,onSection:e=>{n({to:`/settings`,search:{section:e},replace:!0})},onNote:e=>{n({to:`/settings`,search:{section:`patch-notes`,...e===void 0?{}:{note:e}}})}})}function Jwe(){let{projectId:e}=L9.useParams(),t=XN(),n=Ji();return(0,h.jsx)(OSe,{projectId:e,openDraft:async e=>!await t.flush()||!await t.open(e)?!1:(await n({to:`/play`}),!0)},e)}function Ywe(){let{kind:e}=R9.useSearch(),t=Ji(),n=J9();return(0,h.jsx)(USe,{kind:e,onKind:e=>{t({to:`/prompts`,search:{kind:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function J9(){let e=XN(),t=Ji();return{blocked:e.review.starting||e.review.uncertain||e.review.created!==null?`Play is starting a run from its draft. Wait for it to start, then try again.`:void 0,use:n=>{let r=pV(e.document,n);e.edit(r.document),t({to:`/play`}).then(()=>e.navigate(r.section,r.field))}}}function Xwe(){let{kind:e,from:t}=z9.useSearch(),n=Y9();return(0,h.jsx)(J7,{promptId:void 0,kind:e,from:t,onLeave:n},`${e}:${t??`new`}`)}function Zwe(){let{promptId:e}=B9.useParams(),t=Y9();return(0,h.jsx)(J7,{promptId:e,kind:`article`,from:void 0,onLeave:t},e)}function Y9(){let e=Ji();return t=>{e({to:`/prompts`,search:{kind:t}})}}function Qwe(){let{category:e}=V9.useSearch(),t=Ji(),n=J9();return(0,h.jsx)(bhe,{category:e,onCategory:e=>{t({to:`/entries`,search:{category:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function $we(){let{category:e,from:t}=H9.useSearch(),n=Z9();return(0,h.jsx)(i3,{entryId:void 0,category:e,from:t,onLeave:n})}function eTe(){let{entryId:e}=U9.useParams(),t=Z9();return(0,h.jsx)(i3,{entryId:e,category:`intro`,from:void 0,onLeave:t})}function tTe(){let{from:e}=W9.useSearch(),t=X9();return(0,h.jsx)(p4,{themeId:void 0,from:e,onLeave:t})}function nTe(){let{themeId:e}=G9.useParams(),t=X9();return(0,h.jsx)(p4,{themeId:e,from:void 0,onLeave:t})}function X9(){let e=Ji();return()=>{e({to:`/document-themes`})}}function Z9(){let e=Ji();return t=>{e({to:`/entries`,search:{category:t}})}}var rTe=j9.addChildren({homeRoute:Ewe,projectsRoute:M9,welcomeRoute:Owe,playRoute:kwe,libraryRoute:N9.addChildren({promptsRoute:R9,entriesRoute:V9,templatesRoute:Nwe,documentThemesRoute:Vwe,narrationAliasesRoute:zwe,abResultsRoute:Bwe}),schedulesRoute:Fwe,scheduleRoute:Iwe,calendarRoute:I9,libraryIndexRoute:Awe,channelsRoute:jwe,channelRoute:P9,projectRoute:L9,newPromptRoute:z9,promptRoute:B9,newEntryRoute:H9,entryRoute:U9,newDocumentThemeRoute:W9,documentThemeRoute:G9,settingsRoute:K9,usageRoute:Kwe,helpRoute:Wwe,tutorialsIndexRoute:Gwe,tutorialsRoute:q9});function iTe(){return Pa({routeTree:rTe})}function aTe(){let e,t,n=new Set;return{observe:r=>{if(e===void 0){e=r;for(let e of n)e();return}if(r!==e&&r!==t){t=r;for(let e of n)e()}},staleAt:()=>t,loadedAt:()=>e,subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function oTe(e,t){return async(n,r)=>{let i=await e(n,r),a=i.headers.get(`X-Slopify-Version`);return a!==null&&t.observe(a),i}}function sTe(){let e=new Map;return{observe:t=>{if(t.type===`stage.state`){let n=e.get(t.projectId);if(n){for(let[e,r]of n)r.stage===t.stage&&r.revisionId===t.revisionId&&r.workId===t.workId&&n.delete(e);n.size===0&&e.delete(t.projectId)}return}if(t.type!==`llm.preview`)return;let n=e.get(t.projectId)??new Map,r=JSON.stringify([t.revisionId,t.workId,t.callId]),i=n.get(r),a=(t.reset?t.text:`${i?.text??``}${t.text}`).slice(-65536);for(n.delete(r),n.set(r,{...t,text:a,reset:!0});n.size>8;){let e=n.keys().next().value;e!==void 0&&n.delete(e)}for(e.delete(t.projectId),e.set(t.projectId,n);e.size>16;){let t=e.keys().next().value;t!==void 0&&e.delete(t)}},snapshot:t=>[...e.get(t)?.values()??[]],snapshotAll:()=>[...e.values()].flatMap(e=>[...e.values()])}}var Q9=/\/events\/projects\/([^/?#]+)/,cTe=/\/events\/global(?:[?#]|$)/,lTe=[`running.count`,`staging.progress`,`staging.failed`,`schedule.topics`,`stage.state`,`stage.progress`,`article.delta`,`llm.preview`,`image.landed`,`narration.piece`,`project.state`,`project.updated`,`review.flagged`];function uTe(e){let t=new Set,n=sTe(),r,i=!1,a=(e,t,n)=>{for(let r of e.listeners.get(t)??[])r({data:n})},o=o=>{if(r!==void 0)return;let s=e(o);r=s,s.addEventListener(`open`,()=>{i=!0;for(let e of[...t])for(let t of e.opens)t()});for(let e of lTe)s.addEventListener(e,r=>{let i;try{let t=JSON.parse(r.data);typeof t.projectId==`string`&&(i=t.projectId),(e===`llm.preview`||e===`stage.state`)&&n.observe(t)}catch{return}for(let n of[...t])(n.projectId===void 0||n.projectId===i)&&a(n,e,r.data)})};return s=>{let c=Q9.exec(s)?.[1];if(c===void 0&&!cTe.test(s))return e(s);o(c===void 0?s:s.replace(Q9,`/events/global`));let l={projectId:c===void 0?void 0:decodeURIComponent(c),listeners:new Map,opens:new Set};return t.add(l),i&&queueMicrotask(()=>{if(t.has(l)){for(let e of l.opens)e();if(l.projectId!==void 0)for(let e of n.snapshot(l.projectId))a(l,`llm.preview`,JSON.stringify(e))}}),{addEventListener:(e,t)=>{if(e===`open`){l.opens.add(t);return}let n=l.listeners.get(e)??new Set;n.add(t),l.listeners.set(e,n)},close:()=>{t.delete(l),t.size===0&&r!==void 0&&(r.close(),r=void 0,i=!1)}}}}function dTe(e){let t=aTe(),n={api:bo(window.location.origin,oTe(window.fetch.bind(window),t),So(e=>{let n=e.headers.get(`X-Slopify-Version`);n!==null&&t.observe(n)})),openEvents:uTe(e=>new EventSource(e)),version:t};(0,ao.createRoot)(e).render((0,h.jsx)(m.StrictMode,{children:(0,h.jsx)(v,{client:new Ge,children:(0,h.jsx)(fte,{deps:n,children:(0,h.jsx)(La,{router:iTe()})})})}))}var $9=document.getElementById(`root`);if($9===null)throw Error(`index.html carries no #root element for the app to mount on`);dTe($9);export{Z2 as t};