@gentbajko/slopify 3.7.1 → 3.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -270,7 +270,7 @@ 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)(VB,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(WB,{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)(jfe,{queue:e,onQueue:t,keyword:f,addable:O,setRow:D,titleOf:b}),k.length===0?null:(0,h.jsx)(sI,{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)(VB,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:R1({feeds:_(f)})},children:(0,h.jsx)(GB,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(z1,{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 jfe({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`,...Vb,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)(UB,{"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)(UB,{"aria-label":`Topic ${String(r+1)} ${e}`,maxLength:zK,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)(GB,{"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 Mfe=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Nfe({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`?qde(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)(()=>V1(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??MV),[re,ie]=(0,m.useState)(!1),[ae,oe]=(0,m.useState)(!1),se=(0,m.useRef)(!1),ce=(0,m.useRef)(null),le=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,ue=le.find(e=>e.id===d),de=I({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await fq(c,d);if(!e.ok)throw Error(e.message);return e.value}}),fe=de.data?.document.form,pe=fe===void 0?void 0:L1({form:fe,prompts:de.data?.document.librarySnapshot?.prompts??[],entries:de.data?.document.librarySnapshot?.entries??[]}),me=fe===void 0?[]:BK(fe),he=j!==null&&me.includes(j)?j:me.find(e=>fe?.title.includes(`{{${e}}}`))??me[0]??null,ge=Object.fromEntries(me.filter(e=>e!==he).map(e=>[e,ee[e]??fe?.values[e]??``])),_e={keywords:me,topicKeyword:he,everyRun:ge,form:fe,kept:i?.items??[],...pe===void 0?{}:{origins:pe}},ve=W1(k,_e);async function ye(e){if(e.preventDefault(),!(se.current||t)){if(!ue&&!ce.current){r(`Choose a template before saving the schedule.`);return}if(!ce.current&&ve.problems.length>0){r(`Fix the topics first. ${ve.problems.slice(0,3).join(` `)}`);return}if(ve.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(AV)} 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}se.current=!0,ie(!0),s(!0);try{if(!ce.current){if(!ue)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!SV(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Jde(_,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:ue.id,templateVersion:ue.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:ve.rows,topicKeyword:he,values:ge,brief:P.trim()===``?null:P.trim(),topicGeneration:te};ce.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=ce.current,{id:t,...a}=e,o=`mutationId`in a?await QV(c,t,a):await ZV(c,e);if(!o.ok){ce.current=null,oe(!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}ce.current=null,oe(!1),u(``),A(V1([])),n()}catch(e){oe(ce.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{se.current=!1,ie(!1),s(ce.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(sI,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{onSubmit:e=>void ye(e),children:[(0,h.jsxs)(`fieldset`,{disabled:re||ae||t,className:`m-0 grid min-w-0 gap-4 border-0 p-0 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(VB,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,children:(0,h.jsx)(UB,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(VB,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,children:(0,h.jsxs)(GB,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:le.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),le.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(VB,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(GB,{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)(VB,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,children:(0,h.jsx)(UB,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(VB,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,children:(0,h.jsx)(UB,{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`,...Vb,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:Mfe.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)(VB,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,children:(0,h.jsx)(UB,{value:C,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(VB,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(GB,{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)(VB,{label:`Spend ceiling (cents, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,children:(0,h.jsx)(UB,{inputMode:`numeric`,value:D,onChange:e=>O(e.target.value),placeholder:`1000`})}),(0,h.jsx)(Afe,{queue:k,onQueue:A,context:_e,onKeyword:M,onValue:(e,t)=>N(n=>({...n,[e]:t})),loading:d!==``&&de.isPending,exportName:l}),(0,h.jsx)(Pfe,{brief:P,onBrief:F,generation:te,onGeneration:ne,templateLlm:fe?.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||re||le.length===0&&!ae,children:re?`Saving…`:ae?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(B,{variant:`quiet`,disabled:re||ae,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Pfe({brief:e,onBrief:t,generation:n,onGeneration:r,templateLlm:i}){let{api:a}=V(),o=I({...pb(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)(VB,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,children:(0,h.jsx)(WB,{rows:3,maxLength:AV,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)(VB,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,children:(0,h.jsxs)(GB,{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)(VB,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(UB,{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`,...Vb,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)(iV,{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)(aV,{label:`Model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>r({...n,llm:{...s,model:e}})})]})]})]})}function Ffe({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 fH(t,l.id,{baseVersion:l.version,items:e});return s.ok?(d.current=s.value,n.setQueryData(JV,e=>e?.map(e=>e.id===s.value.id?s.value:e)),n.invalidateQueries({queryKey:mH}),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:JV}),!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`,...Vb,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)(IH,{label:`Topics of ${e.name}`,className:`mt-2`,children:f.map((e,t)=>(0,h.jsx)(Ife,{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)(UB,{"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 Ife({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)(LH,{lead:(0,h.jsx)(`span`,{className:`w-6 text-small text-ink-3 tabular-nums`,children:e+1}),title:(0,h.jsx)(UB,{"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 Lfe({pickedId:e,onPick:t}={}){let{api:n}=V(),r=_(),i=I(YV(n)),a=I(dq(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(ux(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=I(hH(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?O1(t):rx)===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:JV})},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)};Nx({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:ie}),cS(rS.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)(GB,{"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)(b1,{tone:te?`info`:oe?.tone??`info`,className:`mb-2`,children:te?void 0:oe?.text}),(0,h.jsx)(eq,{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)(D1,{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)(IH,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:M.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(K1,{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)(A1,{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)(IH,{label:`Deleted schedules`,children:ee.map(e=>(0,h.jsx)(K1,{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)(Nfe,{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:JV})},onError:e=>{s(e),r.invalidateQueries({queryKey:JV})}},l?.id??`new`)]}):N?(0,h.jsx)(Vfe,{schedule:N,pending:se,onAction:F,onConfirm:e=>C({kind:e,schedule:N})},N.id):null}),(0,h.jsx)(Wy,{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 eH(n,t.id,t.version):await $V(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}function Rfe(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}var zfe={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Bfe={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function G1({schedule:e}){return e.deletedAt===null?(0,h.jsx)(AS,{tone:Bfe[e.status],children:zfe[e.status]}):(0,h.jsx)(AS,{tone:`off`,children:`Deleted`})}function K1({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)(LH,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(G1,{schedule:e}),` · ${Rfe(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${s1(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${s1(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(()=>$V(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(()=>$V(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 Vfe({schedule:e,pending:t,onAction:n,onConfirm:r}){let{api:i}=V(),a=I({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await XV(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, ${s1(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`:s1(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)(Hfe,{schedule:e,paused:c,onAction:n}):null,(0,h.jsx)(W,{kicker:(0,h.jsx)(G1,{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)(Ffe,{schedule:e}):null,(0,h.jsx)(hfe,{schedule:e}),(0,h.jsx)(tq,{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)(IH,{label:`Runs of ${e.name}`,children:a.data.runs.map(t=>(0,h.jsx)(LH,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${s1(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 Hfe({schedule:e,paused:t,onAction:n}){let{api:r}=V();return Nx({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>$V(r,e.id,t?`resume`:`pause`,e.version))}),null}var q1=`https://www.youtube.com/upload`,Ufe=[`video`,`title`,`description`,`thumbnails`,`playlist`,`audience`,`altered`,`tags`,`schedule`];function Wfe(e){return e.join(`, `)}var Gfe=[.75,1,1.25,1.5,1.75,2];function J1(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 Y1(e){return`${String(e)}×`}function Kfe(e,t){return e.filter(e=>e.start<=t).at(-1)}function X1(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var Z1=(e,t,n)=>Math.min(n,Math.max(t,e));function Q1(){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=Z1(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=Z1(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 $1(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:Z1((t-n.left)/n.width,0,1)}function e0(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function t0({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 n0({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:J1(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?J1(e.duration):`-:--`}`})]})}function r0({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=Yfe(r),d=n===void 0?void 0:Jfe(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($1(r.current,t.clientX)*a))},g=t=>{let n=$1(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{e0(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:Kfe(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":`${J1(o)} of ${i?J1(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}),J1(x)]})]})}function i0({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($1(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel($1(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];e0(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 a0({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, ${Y1(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:Y1(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`){e0(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];e0(n,()=>i?.focus())},children:Gfe.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`:Y1(t)},t))}):null]})}var qfe=4;function Jfe(e,t){let n=Math.floor(t/qfe);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 Yfe(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 Xfe=2500;function o0({src:e,poster:t,label:n,portrait:r=!1,square:i=!1,captions:a,chapters:o=[],ref:s,className:c,children:l}){let u=Q1(),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),Xfe)},[]);(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:X1(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)(t0,{controls:{...u,toggle:re}}),(0,h.jsx)(n0,{controls:u}),(0,h.jsx)(r0,{controls:u,chapters:o}),(0,h.jsx)(i0,{controls:u}),(0,h.jsx)(a0,{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 Zfe={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function s0({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`,Zfe[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)(kS,{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 c0({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 l0({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)(o0,{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 u0={location:cO(`docker-host`),path:K().min(1)},d0=XD([Y({opened:cO(!0)}).strict(),Y({opened:cO(!0),...u0}).strict(),Y({opened:cO(!1),...u0}).strict()]),f0=QD(`kind`,[Y({kind:cO(`allAffected`)}).strict(),Y({kind:cO(`selected`),workKeys:J(K().min(1).max(200)).min(1).max(1e4)}).strict()]),p0=K().min(1).max(64),Qfe=Y({baseRevisionId:p0,request:f0}).strict(),$fe=Y({baseRevisionId:p0,idempotencyKey:yD(),previewId:K().min(1).max(64),acknowledgeUnknownCosts:BD(),confirmedProvidedWorkKeys:J(K().min(1).max(200)).max(1e4)}).strict(),epe=Y({stage:K(),low:q().finite().nonnegative().nullable(),high:q().finite().nonnegative().nullable(),detail:K(),onPlan:BD().optional(),apiLow:q().finite().nonnegative().nullable().optional(),apiHigh:q().finite().nonnegative().nullable().optional()}),tpe=Y({currency:cO(`USD`),rows:J(epe),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())}),m0=Y({revisionId:p0,admissionId:K().min(1).max(64),workIds:J(K().min(1).max(64)),replayed:BD()}),npe=Y({id:K().min(1).max(64),projectId:K().min(1).max(64),baseRevisionId:p0,planFingerprint:K().min(1),selection:f0,changedInputs:J(Y({path:K(),before:K().nullable(),after:K().nullable()})),work:J(Y({key:K(),stage:X(JS),kind:X([`provider`,`local`,`provided`]),disposition:X([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:K(),fingerprint:K(),dependsOn:J(K()),reason:K(),inflight:BD(),pieceIds:J(K())})),retained:J(Y({slot:K(),outputId:K(),assetId:K(),state:X([`ready`,`outdated`,`review`])})),providedReuseRequired:J(K()),costs:tpe,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()}),h0=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],g0=[`pending`,`running`,`done`,`failed`];Y({id:K(),stage_id:K(),kind:X(h0),idx:q(),state:X(g0),payload:K().nullable()});var rpe=`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(`.`),ipe=[`copying`,`staged`],ape=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:nO([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()}),ope=Y({id:K(),projectId:K(),stageKind:X(JS),role:X(rpe),path:K(),originalFilename:K().nullable(),bytes:q().nonnegative(),durationMs:q().nonnegative().nullable(),meta:ape,createdAt:K()});Y({id:K(),stageKind:X(JS),path:K(),originalFilename:K(),bytes:q().nonnegative(),state:X(ipe),createdAt:K()});var _0=K().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),v0=K().min(1).max(256),spe=iO(v0,_0),cpe=Y({id:_0,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.`}),y0=Y({articleMarkdown:K().max(5e5).optional(),articleEdited:BD().default(!1),provided:Y({research:_0.optional(),article:_0.optional(),audio:_0.optional(),thumbnail:_0.optional(),reference:_0.optional()}).strict(),imageOrder:J(_0).max(240),imageDefinitions:iO(_0,Y({source:X([`generate`,`provide`]),assetId:_0.nullable(),prompt:K().max(5e5).nullable(),templateKey:K().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:iO(v0,QD(`kind`,[Y({kind:cO(`asset`),assetId:_0}).strict(),Y({kind:cO(`text`),text:K().trim().min(1).max(5e5),direction:K().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:iO(v0,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(cpe)}).strict().optional(),regenerationTokens:spe,promptTemplates:iO(K().min(1),K().max(5e5).nullable()),shortsMusic:_0.optional(),shortsRanges:iO(K().regex(/^[1-9]\d?$/u),Y({first:q().int().positive(),last:q().int().positive(),pick:K().min(1).max(128)}).strict()).optional(),ambientBed:_0.optional()}).strict(),lpe=Y({baseRevisionId:_0,idempotencyKey:_0,edit:Y({config:gM.strict(),content:y0,regenerate:J(v0).optional(),uploads:J(Y({stagedFileId:_0,destination:QD(`kind`,[Y({kind:cO(`provided`),stage:X([`audio`,`thumbnail`,`reference`])}).strict(),Y({kind:cO(`image`),imageKey:_0}).strict(),Y({kind:cO(`narration`),key:v0}).strict(),Y({kind:cO(`shortsMusic`)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),upe=Y({baseRevisionId:_0,idempotencyKey:_0,targetRevisionId:_0}).strict(),dpe=Y({id:_0,projectId:_0,parentId:_0.nullable(),restoredFromId:_0.nullable(),config:gM,content:y0,fingerprints:iO(v0,K()),createdAt:K()}),fpe=Y({id:_0,stageId:_0,kind:X(h0),idx:q().int(),state:X(g0),payload:K().nullable()}),ppe=Y({slot:K(),workKey:v0,assetId:_0,output:ope,fingerprint:K(),state:X([`ready`,`outdated`,`review`])}),mpe=Y({key:v0,stageKind:X(JS),piece:fpe,assetId:_0.nullable(),fingerprint:K()}),b0={recordId:_0,publicationId:_0.nullable(),selected:BD(),available:BD()},x0=Y({articleMarkdown:K().nullable(),revision:dpe,outputs:J(ppe.extend(b0)),pieces:J(mpe.extend(b0)),current:BD()}),hpe=Y({id:_0,parentId:_0.nullable(),restoredFromId:_0.nullable(),title:K(),createdAt:K(),current:BD()}),S0=Y({ok:cO(!0),view:x0,duplicate:BD()}),gpe=Y({ok:cO(!0),view:x0,created:BD()}),_pe=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 C0(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=_pe.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 w0(e,t,n,r,i){return C0(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 T0(e,t){return w0(e,t,`/revisions/prepare`,gpe,{})}function E0(e,t,n){return w0(e,t,`/revisions`,S0,lpe.parse(n))}function vpe(e,t,n){return w0(e,t,`/revisions/restore`,S0,upe.parse(n))}function ype(e,t){return w0(e,t,`/revisions`,Y({revisions:J(hpe)}))}function D0(e,t,n){return w0(e,t,`/revisions/${encodeURIComponent(n)}`,Y({view:x0}))}var O0=J(K()).readonly();function bpe(e,t,n){return w0(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,Y({chunks:Y({intro:O0.optional(),body:O0.optional(),outro:O0.optional()}).nullable()}))}function xpe(e,t,n){return w0(e,t,`/rebuild/preview`,Y({ok:cO(!0),value:npe}),Qfe.parse(n))}function Spe(e,t,n){return w0(e,t,`/rebuild`,Y({ok:cO(!0),value:m0}),$fe.parse(n))}function k0(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function Cpe(e,t,n,r){let i=await C0(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),d0);if(!i.ok)throw Error(i.message);return i.value}function wpe(e,t,n){return k0(e,t,n,`images.zip`)}async function A0(e,{projectId:t,asset:n,folder:r=null}){if(r)return Cpe(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 d0.parse(await i.json())}var j0=`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 M0(e){return(0,h.jsx)(Tpe,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function Tpe(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 A0(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)(Fb,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(Lb,{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)(zb,{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:j0}),(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 Epe={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function Dpe(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function N0(){let{api:e}=V(),[t,n]=(0,m.useState)(Dpe),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)(Ub,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:Epe[e]}))}),(0,h.jsxs)(DS,{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)(KB,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(KB,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(KB,{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)(KB,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(KB,{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 Ope=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],P0=Y({day:q().int().min(0).max(6),time:K().regex(/^([01]\d|2[0-3]):[0-5]\d$/)}),kpe=Y({name:K().trim().min(1).max(20),series:K().trim().max(100).default(``),long:P0,shorts:J(P0).max(10)});Y({timeZone:K().min(1).max(100),rows:J(kpe).max(14)});var F0=[`studio`,`plan`],Ape=[`America/New_York`,`America/Los_Angeles`,`Europe/London`,`UTC`];function I0({slot:e,label:t,onChange:n}){return(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(GB,{"aria-label":`${t}: day`,className:`w-[92px]`,value:String(e.day),onChange:t=>n({...e,day:Number(t.currentTarget.value)}),options:Ope.map((e,t)=>({value:String(t),label:e}))}),(0,h.jsx)(UB,{"aria-label":`${t}: time`,type:`time`,className:`w-[132px]`,value:e.time,onChange:t=>n({...e,time:t.currentTarget.value||e.time})})]})}function jpe({autoComment:e}){let{api:t}=V(),n=_(),r=Ry(),i=I({queryKey:F0,queryFn:()=>as(t)}),[a,o]=(0,m.useState)(),s=a??i.data?.plan,c=L({mutationFn:e=>os(t,e),onSuccess:e=>{n.setQueryData(F0,e),o(void 0),r(`Saved the posting plan.`,`success`)},onError:e=>r(`The posting plan wasn't saved: ${e.message}`,`error`)}),l=L({mutationFn:e=>ss(t,e),onSuccess:e=>{n.setQueryData(F0,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`)}),u=L({mutationFn:e=>fs(t,e),onSuccess:()=>n.invalidateQueries({queryKey:[`studio`,`settings`]}),onError:e=>r(`Not saved: ${e.message}`,`error`)});if(s===void 0)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the posting plan…`});let d=e=>o(e),f=(e,t)=>d({...s,rows:s.rows.map((n,r)=>r===e?t:n)}),p=()=>{let e=new Set(s.rows.map(e=>e.name));for(let t=1;;t++)if(!e.has(String(t)))return String(t)},g=[...new Set([s.timeZone,...Ape])];return(0,h.jsxs)(`section`,{"aria-label":`Posting plan`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{as:`h3`,title:`Posting plan`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`One line per long video you post each week, with its series and its shorts. A finished project takes the next free time of a line that takes its series (from its titles, the part after "|"); each short goes out the first time its day and hour come round after its own video, never in the same hour as another release. See and move them in Calendar → Releases.`}),s.rows.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No posting plan yet, so nothing is scheduled. Press Add a long video to start.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:s.rows.map((e,t)=>(0,h.jsxs)(`li`,{className:`flex flex-col gap-2 border-b border-line pb-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold`,children:`Long video ${String(t+1)}`}),(0,h.jsx)(I0,{slot:e.long,label:`Long video ${String(t+1)}`,onChange:n=>f(t,{...e,long:n})})]}),(0,h.jsx)(GB,{"aria-label":`Long video ${String(t+1)}: series`,className:`w-[220px]`,value:e.series,onChange:n=>f(t,{...e,series:n.currentTarget.value}),options:[{value:``,label:`Any series`},...[...new Set([...i.data?.series??[],e.series])].filter(e=>e!==``).map(e=>({value:e,label:e}))]}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(Py,{label:`Remove long video ${String(t+1)}`,onClick:()=>d({...s,rows:s.rows.filter((e,n)=>n!==t)}),children:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75})})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 pl-4`,children:[e.shorts.length===0?(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`No shorts`}):null,e.shorts.map((t,n)=>({short:t,at:n,key:`${e.name}-${String(n+1)}`})).map(({short:n,at:r,key:i})=>(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`Short ${String(r+1)}`}),(0,h.jsx)(I0,{slot:n,label:`Long video ${String(t+1)}, short ${String(r+1)}`,onChange:n=>f(t,{...e,shorts:e.shorts.map((e,t)=>t===r?n:e)})}),(0,h.jsx)(Py,{label:`Remove short ${String(r+1)} of long video ${String(t+1)}`,onClick:()=>f(t,{...e,shorts:e.shorts.filter((e,t)=>t!==r)}),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]},i)),(0,h.jsxs)(B,{type:`button`,variant:`quiet`,disabled:e.shorts.length>=10,onClick:()=>f(t,{...e,shorts:[...e.shorts,e.shorts.at(-1)??{...e.long}]}),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Short`]})]})]},e.name))}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(B,{type:`button`,variant:`quiet`,disabled:s.rows.length>=14,onClick:()=>d({...s,rows:[...s.rows,{name:p(),series:s.rows.at(-1)?.series??``,long:s.rows.at(-1)?.long??{day:0,time:`20:00`},shorts:[]}]}),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add a long video`]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-2 text-small text-ink-2`,children:[`Times are in`,(0,h.jsx)(GB,{"aria-label":`The plan's time zone`,value:s.timeZone,onChange:e=>d({...s,timeZone:e.currentTarget.value}),options:g.map(e=>({value:e,label:e.replace(/_/g,` `)}))})]}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(B,{type:`button`,disabled:a===void 0||c.isPending,onClick:()=>c.mutate(s),children:`Save posting plan`})]}),(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)(UB,{"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&&l.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)(Hb,{checked:e===!0,disabled:u.isPending||e===void 0,onChange:e=>u.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 Mpe(){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)(Npe,{}),(0,h.jsx)(jpe,{autoComment:t.data?.autoComment??!1}),(0,h.jsx)(Fpe,{}),(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)(N0,{})]})]})]})}var R0=``;function Npe(){let{api:e}=V(),t=_(),n=Ry(),r=(0,m.useId)(),i=I({queryKey:L0,queryFn:()=>ts(e)}),a=I(ux(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=Ppe(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)(VB,{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)(GB,{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)(UB,{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)(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 Ppe(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 Fpe(){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)(WP,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(b1,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(DS,{href:q1,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(q1,`_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)(sI,{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)(sI,{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)(N0,{})]})}):null,u.length>1?(0,h.jsx)(Ub,{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)(sI,{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)(Lpe,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(Hb,{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`,...Vb,children:[(0,h.jsx)(GB,{"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)(IH,{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)(LH,{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)(sI,{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 Ipe(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)(DS,{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 Lpe({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)(()=>Ipe(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=Ufe.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)(M0,{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)(M0,{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)(IH,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:v.map(e=>{let{value:t,actions:n}=x(e);return(0,h.jsx)(LH,{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)(c0,{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)(s0,{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)(l0,{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 Wfe(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`}),Rpe=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`}),X0=e=>`${Y0.format(new Date(e))}, ${Rpe.format(new Date(e))}`;function zpe(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 Bpe(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:`waiting`,word:e.uploadBy===null?`No time`:`Upload by ${X0(e.uploadBy)}`}}}function Vpe(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 Hpe({item:e,projectId:t,onDone:n}){let{api:r}=V(),i=_(),a=Ry(),[o,s]=(0,m.useState)(e.at===null?``:zpe(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)(UB,{"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=Bpe(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.jsx)(`span`,{className:`text-small text-ink-3`,children:o}),e.short===0?null:(0,h.jsx)(`span`,{className:`w-full truncate text-small`,title:e.title,children:e.title}),a?(0,h.jsx)(Hpe,{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)(jS,{tone:i.tone,children:i.word})]})}function Upe({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)(GB,{"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 Wpe(){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)(D1,{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=Vpe(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)(Upe,{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 Gpe(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 Kpe(){try{return window.localStorage.getItem(n2)===`list`?`list`:`weeks`}catch{return`weeks`}}function qpe({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=V(),a=_(),o=kx(),[s]=(0,m.useState)(()=>AH(new Date,Q0)),[c,l]=(0,m.useState)(Kpe),[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(hH(i,s.from,s.to)),b=I(YV(i)),x=I(dq(i)),S=I(cb(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:kH(A),[A]),M=A?.runs??[],ee=wH(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:mH}),a.invalidateQueries({queryKey:JV})])}}),P=e=>{if(e.kind!==`none`){if(e.kind===`refused`){w({tone:`error`,text:e.message});return}e.kind===`move`?N.mutate(()=>dH(i,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to})):N.mutate(()=>pH(i,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}}))}},F=(e,t)=>{let n=MH(M,e,t);if(n===void 0){w({tone:`error`,text:t===-1?`${NH(e)} is already the next topic of ${e.scheduleName}.`:`${NH(e)} is the last topic on the calendar for ${e.scheduleName}.`});return}P(jH(e,n,e2.format(new Date(n.at))))},te=e=>{l(e),f!==`weeks`&&p(`weeks`);try{window.localStorage.setItem(n2,e)}catch{}};Nx({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),Nx({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>p(`schedules`)}),cS(rS.addToCalendar,()=>v(!0)),Nx({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>te(`weeks`)}),Nx({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=EH(new Date),ae=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(QK,{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)(Ub,{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)(T1,{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)(E1,{idPrefix:`calendar`,id:`releases`,active:f===`releases`,children:f===`releases`?(0,h.jsx)(Wpe,{}):null}),(0,h.jsx)(E1,{idPrefix:`calendar`,id:`schedules`,active:f===`schedules`,children:f===`schedules`?(0,h.jsx)(Lfe,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(E1,{idPrefix:`calendar`,id:`weeks`,active:f===`weeks`,children:[(0,h.jsx)(b1,{tone:C?.tone===`info`?`info`:re?`error`:`info`,className:`mb-3`,children:re}),(0,h.jsxs)(S1,{split:`aside`,className:`mb-6`,children:[(0,h.jsx)(C1,{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:CH(ee)}),(0,h.jsx)(IH,{label:`Needs you`,children:ee.map(e=>(0,h.jsx)(a2,{project:e},e.id))})]})}),(0,h.jsx)(C1,{as:`aside`,label:`Suggested topics`,children:(0,h.jsx)(gfe,{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+→.`}),OH(new Date(s.from),Q0).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=EH(e),n=j.get(t);return(0,h.jsx)(Jpe,{date:e,today:t===ie,day:n,dragging:T,busy:N.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(P(jH(T,t,e2.format(e))),E(null))},onStep:F},t)})},EH(e[0]??new Date)))]}):(0,h.jsx)(Xpe,{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)(IH,{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)(LH,{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)(AS,{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)(_H,{open:g,onOpenChange:v,schedules:k})]})}function Jpe({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)(Ype,{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=SH(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${PH}`,children:[(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${FH}`,children:e.title}),(0,h.jsx)(AS,{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 Ype({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=NH(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)(AS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(AS,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(AS,{tone:`off`,children:`Queued`}):(0,h.jsx)(AS,{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 oH(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:mH}),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)(TS,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}function a2({project:e}){let t=SH(e);return(0,h.jsx)(LH,{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)(AS,{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)(TS,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function Xpe({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`,...Vb,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)(IH,{label:`Planned on ${e2.format(e.date)}`,children:[e.runs.map(e=>{let n=NH(e),a=o.filter(t=>t.id!==e.scheduleId);return(0,h.jsx)(LH,{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 Zpe=yj.map(e=>({value:e,label:bj[e]}));function Qpe({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=L({mutationFn:n=>Sx(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${bj[e.aiDisclosure]}.`,`success`),n.setQueryData(sx(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:ox,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)(VB,{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)(GB,{value:i.isPending?i.variables:e.aiDisclosure,options:Zpe,disabled:i.isPending,onChange:e=>{let t=yj.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(b1,{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)(VB,{label:r,tip:o,help:$pe(s),error:i,children:(0,h.jsxs)(GB,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:PO.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,FO(n.language).name,`)`]}),NO.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function $pe(e){let t=FO(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=IO(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 eme({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`,...Vb,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)(UB,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})}),(0,h.jsx)(UB,{"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 tme(){return(0,h.jsxs)(`div`,{...Vb,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)(TS,{to:`/channels/$channelId`,params:{channelId:rx},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(Yk.levelDb),fadeIn:e?.fadeIn??String(Yk.fadeInSeconds),tail:e?.tail??String(Yk.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)(VB,{label:n,help:r,tip:a,error:i(t),children:(0,h.jsx)(UB,{"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)(VB,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(GB,{"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:Jk[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 nme({value:e,onChange:t}){let n=eA(e),r=n===void 0?[]:Zk(n);return(0,h.jsx)(s2,{value:e,inherit:`Not set`,sources:Kk,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function rme(e){return e.ambientBed===void 0?void 0:$k(e.ambientBed)}function ime(e){let t=eA(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:Zk(t).length>0}}var c2=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`];function ame(e){return Object.fromEntries(c2.map(t=>[t,e[t]??``]))}function ome({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=I({queryKey:nN,queryFn:()=>rN(t)}),a=I(gb(t)),o=I(_b(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(ame(e.brand)),[p,g]=(0,m.useState)(rme(e.brand)),v=ime(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:()=>px(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(sx(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:ox}),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)(VB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(UB,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(VB,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules.`,children:(0,h.jsx)(WB,{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)(VB,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(UB,{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)(nme,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(eme,{rows:S,onChange:x})})]}),(0,h.jsx)(x1,{status:(0,h.jsx)(b1,{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)(VB,{label:e,tip:t,children:(0,h.jsxs)(GB,{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)(VB,{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)(UB,{value:n,placeholder:`#FFFFFF`,maxLength:7,onChange:e=>r(e.target.value)})]})})}function d2(e,t){return e.languages===void 0||e.languages.includes(FO(t).code)}function sme(e,t,n,r){return n?e:e.filter(e=>d2(e,t)||e.voiceId===r)}function cme(e,t){if(e===void 0||d2(e,t))return;let n=FO(t).name,r=(e.languages??[]).map(e=>FO(e).code===e?FO(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=sme(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=cme(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`,...Vb,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 ${FO(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 lme({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:sx(e)}),o.invalidateQueries({queryKey:ox})]),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?hx(a,e,crypto.randomUUID(),n):gx(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`:ax[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)(VB,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(GB,{value:s,onChange:e=>c(ix.find(t=>t===e.target.value)??`character`),options:ix.map(e=>({value:e,label:ax[e]}))})}),(0,h.jsx)(VB,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(UB,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(VB,{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)(UB,{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)(MS,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(VB,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(WB,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(dme,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(Hb,{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)(b1,{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)(ume,{channelId:e,member:t})]}):null}function ume({channelId:e,member:t}){let{api:n}=V(),r=_(),i=I(pb(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:sx(e)}),r.invalidateQueries({queryKey:ox})]),g=L({mutationFn:e=>vx(n,t.id,e),onSettled:p}),v=L({mutationFn:()=>yx(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=L({mutationFn:e=>bx(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:Cx(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)(tq,{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)(c0,{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)(s0,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:Cx(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)(jS,{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)(fme,{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)(l0,{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)(DS,{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`,...Vb,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)(iV,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(aV,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(VB,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,children:(0,h.jsx)(WB,{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)(b1,{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 dme({channelId:e,value:t,onChange:n}){let{api:r}=V(),i=I(pb(r)),a=I(mb(r)),o=I(dx(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`,...Vb,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)(iV,{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)(aV,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(tV,{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)(tV,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:TA.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 fme({error:e,retry:t,onReword:n}){let r=l1({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)(_1,{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 pme({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=>_x(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:sx(e)}),a.invalidateQueries({queryKey:ox})])}}),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:Cx(i,t)}]:[]}),v=g.map(e=>({src:e.src,alt:e.member.name,caption:`${ax[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)(D1,{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)(c0,{label:`Cast`,children:t.map(e=>{let t=e.images.filter(e=>e.state===`ready`),n=t[0]?.sha256;return(0,h.jsx)(s0,{className:z(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...n?{src:Cx(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:`${ax[e.kind]}${e.host===!0?` · Host`:``} · ${String(t.length)} ${t.length===1?`picture`:`pictures`}`,...t.length===0?{badge:(0,h.jsx)(jS,{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)(l0,{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)(b1,{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)(lme,{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)(Wy,{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 mme(e,t){return at({queryKey:m2(t),queryFn:async()=>R(await e.fetch(`${g2(e,t)}/episodes`))})}async function hme(e,t,n){return R(await e.fetch(`${g2(e,t)}/episodes/setting`,_2(`PUT`,{enabled:n})))}async function gme(e,t,n,r){return R(await e.fetch(`${g2(e,t)}/episodes/${encodeURIComponent(n)}`,_2(`PUT`,{summary:r})))}async function _me(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 vme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos`,_2(`POST`,n)))}async function yme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos/preview`,_2(`POST`,{format:`csv`,text:n})))}async function bme(e,t,n){let r=await e.fetch(`${g2(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await R(r)}async function xme(e,t){await R(await e.fetch(`${g2(e,t)}/videos`,{method:`DELETE`}))}var Sme=e=>e.length>160?`${e.slice(0,160)}…`:e;function Cme({channelId:e}){let{api:t}=V(),n=_(),r=I(mme(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:m2(e)}),l=L({mutationFn:n=>hme(t,e,n),onSuccess:t=>n.setQueryData(m2(e),t)}),u=L({mutationFn:n=>_me(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)(Hb,{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)(b1,{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)(D1,{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)(IH,{label:`Episode summaries`,children:f.map(e=>(0,h.jsx)(LH,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,Sme(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)(wme,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(Wy,{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 wme({channelId:e,memory:t,onClose:n}){let{api:r}=V(),i=_(),[a,o]=(0,m.useState)(t.summary),s=L({mutationFn:()=>gme(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:m2(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Uy,{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)(VB,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(WB,{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 Tme({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=>vme(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=>yme(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:b2(e.titles,e.filter)})}}),x=L({mutationFn:n=>bme(t,e,n),onSuccess:d}),S=L({mutationFn:()=>xme(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)(VB,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(WB,{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)(b1,{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)(Eme,{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)(D1,{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)(IH,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(LH,{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)(Wy,{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 Eme({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`,...Vb,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)(VB,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(UB,{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)(IH,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(LH,{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,Dme=28;function Ome(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=Ome(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+Dme,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 kme(e,t){return R(await e.fetch(k2(e,t)))}async function Ame(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 jme({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)(GB,{"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)(GB,{"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)(GB,{"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 Mme({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 Nme(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:()=>kme(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)(()=>Nme(e)),S=L({mutationFn:n=>Ame(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)(jme,{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)(GB,{"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)(Mme,{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 Pme=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),V2=e=>e===null?`–`:Pme.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 Fme({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)(D1,{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)(GB,{"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`],Ime={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function Lme(e){return W2.find(t=>t===e)??`brand`}function Rme({channelId:e,tab:t,onTab:n}){let{api:r}=V(),i=_(),a=Ji(),o=I(dx(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=L({mutationFn:()=>mx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:ox}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return Nx({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)(QK,{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)(T1,{items:W2.map(e=>({id:e,label:Ime[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(b1,{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)(E1,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(Qpe,{channel:f}),(0,h.jsx)(ome,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(pme,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(bfe,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Cfe,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Cme,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(Tme,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(Fme,{channelId:f.id}):null})]}):null,(0,h.jsx)(Wy,{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 zme(){let{api:e}=V(),t=_(),n=Ji(),r=I(ux(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:()=>fx(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:ox}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=L({mutationFn:t=>px(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:ox}),a(null)}}),v=L({mutationFn:t=>mx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:ox})}}),y=()=>{p.reset(),l(``),a(`new`)};Nx({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)(QK,{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)(b1,{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)(D1,{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)(eq,{list:(0,h.jsx)(IH,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(LH,{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)(ES,{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)(Bme,{channel:f})}):null,(0,h.jsx)(Uy,{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)(b1,{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)(VB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(UB,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Wy,{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 Bme({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)(TS,{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();Nx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:iP.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)(b1,{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":Gx(iP.save),onClick:()=>{c||s()},children:`Save`})]})}var Vme=`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:`${Vme} 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 Hme=`modulepreload`,Ume=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=Ume(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`:Hme,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 Wme({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 Gme(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 Gme(e,t){let n=await Z2(()=>import(`./pdf-B6O50xdO.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}}),Kme=[{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=Jj.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 qme(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 Jme(e){let t=nM;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)(sI,{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(_b(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:_b(r).queryKey})}}),w=L({mutationFn:e=>Ys(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:_b(r).queryKey}),n()}});K2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:nM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:uC(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)(QK,{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)(VB,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(UB,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),Kme.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)(Zme,{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)(TS,{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)(Xme,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(Wy,{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 Yme={"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 Xme({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)(DS,{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)(Wme,{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 Zme({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=qme(t,e.path),o=Yme[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`,...Vb,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}=Jme(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)(UB,{...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)(UB,{...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)(UB,{...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)(UB,{...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)(GB,{...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)(GB,{...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)(GB,{"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)(UB,{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`,...Vb,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)(WB,{...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)(D1,{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)(IH,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(LH,{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)(Wy,{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 Eme({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`,...Vb,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)(VB,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(UB,{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)(IH,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(LH,{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,Dme=28;function Ome(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=Ome(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+Dme,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 kme(e,t){return R(await e.fetch(k2(e,t)))}async function Ame(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 jme({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)(GB,{"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)(GB,{"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)(GB,{"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 Mme({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 Nme(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:()=>kme(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)(()=>Nme(e)),S=L({mutationFn:n=>Ame(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)(jme,{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)(GB,{"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)(Mme,{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 Pme=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),V2=e=>e===null?`–`:Pme.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 Fme({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)(D1,{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)(GB,{"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`],Ime={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function Lme(e){return W2.find(t=>t===e)??`brand`}function Rme({channelId:e,tab:t,onTab:n}){let{api:r}=V(),i=_(),a=Ji(),o=I(dx(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=L({mutationFn:()=>mx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:ox}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return Nx({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)(QK,{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)(T1,{items:W2.map(e=>({id:e,label:Ime[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(b1,{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)(E1,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(Qpe,{channel:f}),(0,h.jsx)(ome,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(pme,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(bfe,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Cfe,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Cme,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(Tme,{channelId:f.id}):null}),(0,h.jsx)(E1,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(Fme,{channelId:f.id}):null})]}):null,(0,h.jsx)(Wy,{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 zme(){let{api:e}=V(),t=_(),n=Ji(),r=I(ux(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:()=>fx(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:ox}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=L({mutationFn:t=>px(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:ox}),a(null)}}),v=L({mutationFn:t=>mx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:ox})}}),y=()=>{p.reset(),l(``),a(`new`)};Nx({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)(QK,{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)(b1,{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)(D1,{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)(eq,{list:(0,h.jsx)(IH,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(LH,{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)(ES,{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)(Bme,{channel:f})}):null,(0,h.jsx)(Uy,{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)(b1,{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)(VB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(UB,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Wy,{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 Bme({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)(TS,{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();Nx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:iP.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)(b1,{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":Gx(iP.save),onClick:()=>{c||s()},children:`Save`})]})}var Vme=`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:`${Vme} 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 Hme=`modulepreload`,Ume=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=Ume(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`:Hme,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 Wme({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 Gme(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 Gme(e,t){let n=await Z2(()=>import(`./pdf-DduTO1_g.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}}),Kme=[{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=Jj.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 qme(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 Jme(e){let t=nM;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)(sI,{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(_b(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:_b(r).queryKey})}}),w=L({mutationFn:e=>Ys(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:_b(r).queryKey}),n()}});K2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:nM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:uC(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)(QK,{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)(VB,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(UB,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),Kme.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)(Zme,{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)(TS,{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)(Xme,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(Wy,{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 Yme={"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 Xme({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)(DS,{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)(Wme,{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 Zme({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=qme(t,e.path),o=Yme[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`,...Vb,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}=Jme(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)(UB,{...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)(UB,{...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)(UB,{...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)(UB,{...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)(GB,{...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)(GB,{...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)(GB,{"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)(UB,{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`,...Vb,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)(WB,{...d,rows:8,value:Array.isArray(a)?a.join(`
274
274
  `):``,onChange:e=>{c(e.target.value.split(`
275
275
  `))}}),u]});case`link`:{let t=a;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Vb,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)(UB,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{c({...t,text:e.target.value})}}),(0,h.jsx)(UB,{"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`,...Vb,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 Qme=4e3;function _4(e){return e.match(/\s+|[^\s]+/gu)??[]}function $me(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 the(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 ehe(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 the(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,Qme),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)(()=>$me(e,t),[e,t]),a=ehe(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:nhe(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 nhe(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 rhe(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)(WP,{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)(VB,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(GB,{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)(VB,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(GB,{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)(IH,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(LH,{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)(b1,{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)(KB,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(ihe,{item:e,id:t}),(0,h.jsx)(ahe,{item:e,id:t,name:n,onOpenHistory:c})]})}function ihe({item:e,id:t}){let n=rhe(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:ohe(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)(IH,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(LH,{title:(0,h.jsx)(fa,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(LH,{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)(LH,{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 ahe({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 ohe(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)(sI,{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 she=[{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 che(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(QK,{title:`Library`,meta:`Prompts, intros and outros, templates, document themes, narration aliases and A/B results`}),(0,h.jsx)(yfe,{items:she,label:`Library sections`,className:`mb-6`}),(0,h.jsx)(lhe,{}),(0,h.jsx)(Oa,{})]})}function lhe(){let e=Ji(),t=Ra({select:e=>e.location}),n=t.search,r=RB(t.pathname===`/prompts`?n.kind:void 0),i=FB(t.pathname===`/entries`?n.category:void 0);return Nx({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),Nx({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),Nx({id:`library.new-document-theme`,title:`New document theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),Nx({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),Nx({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),Nx({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),Nx({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 uhe(){let{api:e}=V(),t=_(),n=I(_b(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)(TS,{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)(eq,{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)(IH,{label:`Your themes`,children:c.themes.map(e=>(0,h.jsx)(LH,{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)(TS,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(TS,{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)(IH,{label:`Built-in themes`,children:c.builtIns.map(e=>(0,h.jsx)(LH,{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)(TS,{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)(TS,{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)(TS,{to:`/document-themes/$themeId`,params:{themeId:f.id},size:`small`,children:`Edit theme`})})}),s.error===null?null:(0,h.jsx)(sI,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:s.error.message}),(0,h.jsx)(Wy,{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`,...Vb,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(UB,{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)(RH,{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 dhe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=V(),a=_(),o=I(gb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=Px(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)(TS,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`}),children:[(0,h.jsx)(UB,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":Gx(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)(Ub,{label:`Entry category`,value:e,options:kB.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)(phe,{category:e}):(0,h.jsx)(eq,{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)(IH,{label:`${jB(e)}s`,children:w.map(e=>(0,h.jsx)(LH,{className:M4,title:(0,h.jsx)(W4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:fhe(e),selected:e.id===T?.id,actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(TS,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(TS,{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:`${jB(T.category)} · ${MB(T.mode)}`,meta:`Updated ${A4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(TS,{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)(sI,{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)(Wy,{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 fhe(e){return`${MB(e.mode)} · ${k4(e.slots.length,`keyword`)} · updated ${A4(e.updatedAt)}`}function phe({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(D1,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function mhe({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)(mhe,{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`,{...Vb,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 hhe(e){return X4(e.name,e.body)}function ghe(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(yM)} characters or fewer.`}),n;for(let e of PK(t).errors)n.push({field:`body`,message:_he(e,t)});return n}function _he(e,t){let n=vhe(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 vhe(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
276
276
  `),i=n.split(`