@gentbajko/slopify 3.12.1 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,7 +157,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
157
157
  `)}function bve({results:e}){return(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:e.map(e=>{let t=[...e.variants].sort((e,t)=>(t.share??0)-(e.share??0));return(0,h.jsxs)(`li`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-row__title`,children:e.projectTitle}),(0,h.jsx)(`ol`,{className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:t.map((e,t)=>(0,h.jsxs)(`li`,{className:t===0?`text-ink`:`text-ink-2`,children:[FL(e,t),e.share===null?``:` · ${String(e.share)}% of watch time`,t===0?` · winner`:``]},FL(e,t)))})]},`${e.projectId}-${String(e.short??0)}`)})})}function xve(){let{api:e}=B(),t=Lv(),n=F({queryKey:[`studio`,`ab-results`],queryFn:()=>bs(e)}),r=n.data??[];return(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 flex-1 text-small text-ink-2`,children:`Finished A/B tests, as the Slopify Studio extension read them from YouTube Studio once a day. The winner is listed first.`}),(0,h.jsxs)(z,{type:`button`,variant:`secondary`,disabled:r.length===0,disabledReason:n.data===void 0?`The A/B results haven't loaded`:`No finished A/B tests yet`,onClick:()=>void navigator.clipboard?.writeText(yve(r)).then(()=>t(`Copied the notes. Paste them into the prompt that writes titles.`,`success`),()=>t(`Couldn't copy the notes. Select them and copy by hand.`,`error`)),children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy as prompt notes`]})]}),(0,h.jsx)(PL,{query:n,what:`The A/B results`,loading:(0,h.jsx)(jL,{label:`Loading the A/B results…`,rows:3,rowClassName:`h-14`}),children:e=>e.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No finished A/B tests yet. Start one from a project's Video section (On YouTube → A/B test) or the extension; its result shows here once Studio has one.`}):(0,h.jsx)(bve,{results:e})})]})}function Sve(e){return e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``)}function Cve({open:e,onOpenChange:t,schedules:n}){let{api:r}=B(),i=_(),a=Lv(),o=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`)),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(``),[d,f]=(0,m.useState)(void 0),p=o.find(e=>e.id===s)??o[0],g=Sve(l),v=I({mutationFn:async e=>{let{id:t,...n}=e;return jT(r,t,{name:n.name,templateId:n.templateId,templateVersion:n.templateVersion,cadence:n.cadence,timezone:n.timezone,missedPolicy:n.missedPolicy,overlapPolicy:n.overlapPolicy,spendLimitCents:n.spendLimitCents,items:[...n.items,...g.map(e=>({title:e,values:{}}))],topicKeyword:n.topicKeyword,values:n.values,brief:n.brief,topicGeneration:n.topicGeneration,releases:n.releases,baseVersion:n.version,mutationId:crypto.randomUUID()})},onSuccess:(e,n)=>{if(!e.ok){f(e.reason===`conflict`?`${n.name} changed while you were typing. Your topics are kept: press Add to calendar again.`:e.message);return}a(`Added ${String(g.length)} ${g.length===1?`topic`:`topics`} to ${n.name}.`,`success`),u(``),f(void 0),t(!1)},onError:e=>f(`The topics weren't added: ${e.message} Your text is kept; try again.`),onSettled:async()=>{await Promise.all([i.invalidateQueries({queryKey:OT}),i.invalidateQueries({queryKey:VT})])}});return(0,h.jsx)(Qv,{open:e,onOpenChange:t,title:`Add to calendar`,description:`Each line becomes a topic at the end of the schedule's queue, so it takes that schedule's next free run.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{variant:`secondary`,onClick:()=>t(!1),children:`Keep the calendar as it is`}),(0,h.jsx)(z,{variant:`primary`,disabled:p===void 0||g.length===0||v.isPending,disabledReason:p===void 0?`Create a schedule first.`:g.length===0?`Type at least one topic.`:`Adding…`,onClick:()=>{p!==void 0&&v.mutate(p)},children:g.length===0?`Add to calendar`:`Add ${String(g.length)} ${g.length===1?`topic`:`topics`}`})]}),children:o.length===0?(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Topics go on a schedule, and there is none yet.`,` `,(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`schedules`},onClick:()=>{BO(LO.newSchedule),t(!1)},children:`Create a schedule`}),` `,`first.`]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(aL,{label:`Schedule`,tip:`planning.calendar.add-schedule`,help:p===void 0?void 0:(0,h.jsxs)(KO,{to:`/calendar`,search:{tab:`schedules`,schedule:p.id},onClick:()=>t(!1),children:[`Open `,p.name,` and its queue`]}),children:(0,h.jsx)(cL,{value:p?.id??``,onChange:e=>c(e.target.value),children:o.map(e=>(0,h.jsx)(`option`,{value:e.id,children:`${e.name} · ${String(e.items.length)} queued`},e.id))})}),(0,h.jsx)(aL,{label:`Topics, one per line`,error:d,tip:`planning.calendar.add-topics`,children:(0,h.jsx)(sL,{rows:8,value:l,placeholder:`Nefertiti
158
158
  The Library of Alexandria
159
159
  The Old Kingdom`,onChange:e=>u(e.target.value)})})]})})}var IL={running:{tone:`running`,word:`Running`},paused:{tone:`waiting`,word:`Paused`},pending:{tone:`off`,word:`Queued`},failed:{tone:`failed`,word:`Failed`},partial:{tone:`waiting`,word:`Done with problems`},done:{tone:`done`,word:`Done`},canceled:{tone:`off`,word:`Canceled`}},LL={tone:`done`,word:`Kept as is`},RL={pending:`Not started`,running:`Running`,done:`Done`,provided:`Provided`,failed:`Failed`,canceled:`Canceled`,skipped:`Off`},zL=`Waiting for your review`,BL=`Waiting to try again`,VL={active:{tone:`running`,word:`Active`},paused:{tone:`waiting`,word:`Paused`},completed:{tone:`done`,word:`Completed`},canceled:{tone:`off`,word:`Canceled`}};function HL(e,t=wve){let n=e?.[0];if(e===void 0||n===void 0)return;let r=n.resetsAt===null?`checking again at ${t(n.retryAt)}`:`resets at ${t(n.resetsAt)}`;return`Waiting for ${UL(e)} limits (${r})`}function UL(e){let t=[...new Set(e.map(e=>e.name))];return t.length<=1?t[0]??``:`${t.slice(0,-1).join(`, `)} and ${t.at(-1)??``}`}function wve(e){let t=new Date(e),n=t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`});return t.toDateString()===new Date().toDateString()?n:`${t.toLocaleDateString(void 0,{weekday:`short`})} ${n}`}function WL(e,t){switch(e.needs){case`failed`:return{tone:`failed`,word:`Failed`,action:{kind:`open`,label:`Open to fix`}};case`paused`:return{tone:`waiting`,word:`Paused`,action:{kind:`open`,label:`Open to continue`}};case`review`:return{tone:`waiting`,word:zL,action:{kind:`open`,label:`Open to review`}};case void 0:}let n=HL(e.limitWaits,t);return n===void 0?e.readyToUpload===!0?{tone:`done`,word:`Ready to upload`,action:{kind:`upload`}}:IL[e.state]:{tone:`waiting`,word:n}}function Tve(e){let t=e.filter(e=>e.needs!==void 0).length,n=e.length-t;return[t===0?void 0:`${String(t)} waiting for you`,n===0?void 0:`${String(n)} ready to upload`].filter(e=>e!==void 0).join(` · `)}function Eve(e){return[...e.filter(e=>e.needs!==void 0),...e.filter(e=>e.needs===void 0&&e.readyToUpload===!0)]}var GL=`sl-hit`,KL=`sl-hit__target`;function qL({label:e,className:t,children:n}){return(0,h.jsx)(`ul`,{"aria-label":e,className:R(`sl-list m-0 list-none p-0`,t),children:n})}function JL({title:e,meta:t,lead:n,actions:r,selected:i=!1,onSelect:a,className:o,children:s}){return(0,h.jsxs)(`li`,{"data-selected":i?`true`:void 0,"aria-current":i?`true`:void 0,className:R(`sl-row`,GL,o),children:[(0,h.jsxs)(`div`,{className:`sl-row__lead`,children:[n,(0,h.jsxs)(`div`,{className:`sl-row__text`,children:[a===void 0?(0,h.jsx)(`span`,{className:`sl-row__title`,children:e}):(0,h.jsx)(YL,{onSelect:a,children:e}),t===void 0?null:(0,h.jsx)(`span`,{className:`sl-row__meta`,children:t})]})]}),r===void 0?null:(0,h.jsx)(`div`,{className:`sl-row__actions`,children:r}),s==null||s===!1?null:(0,h.jsx)(`div`,{className:`sl-row__body`,children:s})]})}function YL({onSelect:e,className:t,children:n}){return(0,h.jsx)(`button`,{type:`button`,onClick:e,className:R(`sl-row__title border-0 bg-transparent p-0 text-left font-[inherit] text-ink`,KL,t),children:n})}var XL=864e5;function ZL(e){return`${String(e.getFullYear())}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function QL(e){let t=new Date(e);return t.setHours(0,0,0,0),t.setDate(t.getDate()-(t.getDay()+6)%7),t}function $L(e,t){let n=QL(e);return Array.from({length:t},(e,t)=>Array.from({length:7},(e,r)=>{let i=new Date(n);return i.setDate(n.getDate()+t*7+r),i}))}function eR(e,t=new Date){let n=new Map,r=e=>{let t=new Date(e),r=ZL(t),i=n.get(r);if(i===void 0){let e=new Date(t);e.setHours(0,0,0,0),i={key:r,date:e,runs:[],projects:[]},n.set(r,i)}return i},i=new Set(e.queued.map(e=>e.projectId));for(let n of e.projects)i.has(n.id)||r(n.finishedAt??t.toISOString()).projects.push(n);for(let t of e.runs)r(t.at).runs.push(t);return n}function tR(e,t){let n=QL(e);return{from:n.toISOString(),to:new Date(n.valueOf()+t*7*XL+XL).toISOString()}}function nR(e,t,n){return e.index===null?{kind:`refused`,message:`This run has no queued topic to move: it will use ${e.topicSource===`held`?`a topic waiting for your approval`:e.topicSource===`generated`?`a topic Slopify suggests`:`the template as saved`}.`}:t===void 0?{kind:`refused`,message:`No run is planned on ${n}. Drop the topic on a day that has one, or change the schedule's days under Schedules.`}:t.scheduleId===e.scheduleId?t.index===null?{kind:`refused`,message:`The run on ${n} is past the end of ${e.scheduleName}'s queue. Drop the topic on a run that has one.`}:t.index===e.index?{kind:`none`}:{kind:`move`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,from:e.index,to:t.index}:{kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t.scheduleId,position:t.index??void 0}}function rR(e,t,n){if(t.index===null)return;let r=t.index+n;return e.find(e=>e.scheduleId===t.scheduleId&&e.index===r)}function iR(e){return e.renderedTitle!==null&&e.renderedTitle.trim()!==``?e.renderedTitle:e.topic??(e.topicSource===`held`?`A topic waiting for your approval`:e.topicSource===`generated`?`A topic Slopify will suggest`:`The template as saved`)}var aR=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),oR=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),sR=new Intl.DateTimeFormat(void 0,{timeStyle:`short`});function cR({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,lR),v=()=>p.find(e=>e.scheduleId===r?.scheduleId)??p[0];return(0,h.jsxs)(`section`,{"aria-label":oR.format(e),className:R(`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 · ${aR.format(e)}`:aR.format(e)}),p.map(e=>(0,h.jsx)(uR,{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=WL(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${GL}`,children:[(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${KL}`,children:e.title}),(0,h.jsx)(tk,{tone:t.tone,children:t.word})]},e.id)}),g.length>lR?(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-expanded":d,className:`self-start`,onClick:()=>f(e=>!e),children:d?`Show fewer`:`+${String(g.length-lR)} more`}):null]})}var lR=3;function uR({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=iR(e);return(0,h.jsxs)(`article`,{tabIndex:e.index===null?void 0:0,"aria-label":`${s}, ${sR.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)))},title:o?`Drag to another day, or press Alt+arrow keys`:void 0,className:R(`sl-cal-item`,o&&`sl-cal-item--movable`),children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1 text-label text-ink-3 tabular-nums`,children:[e.index===null?null:(0,h.jsx)(Yc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3 shrink-0 text-ink-3`}),sR.format(new Date(e.at))]}),(0,h.jsx)(`b`,{className:R(`text-small`,e.topic===null&&`font-normal text-ink-2`),children:s}),(0,h.jsx)(KO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.scheduleId},className:`self-start text-label`,draggable:!1,children:e.scheduleName}),e.paused?(0,h.jsx)(tk,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(tk,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(tk,{tone:`off`,children:`Queued`}):(0,h.jsx)(tk,{tone:`info`,children:`Prepared`}),(0,h.jsx)(dR,{run:e,compact:!0})]})}function dR({run:e,compact:t=!1}){let{api:n}=B(),r=_(),[i,a]=(0,m.useState)(),o=I({mutationFn:async()=>{if(e.topic===null)throw Error(`This run has no topic to prepare yet.`);let t=await ice(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:VT}),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)(z,{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)(GO,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}var fR=`https://www.youtube.com/upload`,pR=[`video`,`title`,`description`,`thumbnails`,`playlist`,`audience`,`altered`,`tags`,`schedule`];function mR(e){return e.join(`, `)}var hR=5e3,gR=[`Write a YouTube description for this video.`,``,`- Summary: a 2-3 sentence hook that says what the viewer gets from watching, in plain words, without clickbait.`,`- Chapters: split the video where the topic changes, 5-12 chapters for a long video and fewer for a short one. Chapter titles are 2-6 words, in title case, and name what that part covers.`,`- Hashtags: 3-5 hashtags about the subject, most specific last.`,`- Tags: 15-25 search terms a viewer might type to find this video, from broad to specific.`].join(`
160
- `),_R=`Built-in`,vR=/[<>]/;function yR(e){let t=e.trim();if(t.length>100)return`YouTube takes titles of up to 100 characters; this one has ${String(t.length)}. Shorten it.`;if(vR.test(t))return`YouTube doesn't allow < or > in a title. Remove them.`}function bR(e){if(e.length>5e3)return`YouTube takes descriptions of up to ${hR.toLocaleString(`en-US`)} characters; this one has ${e.length.toLocaleString(`en-US`)}. Shorten it.`;if(vR.test(e))return`YouTube doesn't allow < or > in a description. Remove them.`}function xR(e){let t=e.split(/\s+/u).filter(e=>e.startsWith(`#`)&&e.length>1).length;if(t!==0)return t>60?`${String(t)} hashtags: YouTube ignores every hashtag when there are more than 60. Remove ${String(t-60)}.`:`${String(t)} hashtag${t===1?``:`s`}; the first ${String(Math.min(t,3))} show above the title.`}var SR={info:`text-ink-2`,error:`text-danger`,warning:`text-waiting`,success:`text-accent-ink`};function CR({children:e,tone:t=`info`,className:n,id:r}){let i=typeof e==`string`?e:void 0;return(0,h.jsx)(`div`,{id:r,"data-slot":`status-slot`,role:t===`error`?`alert`:`status`,title:i,className:R(`flex min-h-8 min-w-0 flex-1 items-center gap-2 overflow-hidden text-small`,SR[t],n),children:e==null||e===!1?null:i===void 0?e:(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:i})})}function wR({status:e,children:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`action-bar`,className:R(`sticky bottom-0 z-20 -mx-4 mt-6 flex min-h-14 flex-wrap items-center gap-x-3 gap-y-2 border-t border-line bg-surface px-4 py-2 pb-[max(8px,env(safe-area-inset-bottom))] max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))] md:-mx-10 md:px-10`,n),children:[(0,h.jsx)(`div`,{className:`flex w-full min-w-0 sm:w-auto sm:flex-1`,children:e??(0,h.jsx)(CR,{})}),(0,h.jsx)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:t})]})}var TR=[.75,1,1.25,1.5,1.75,2],ER=`slopify.playback`,DR={volume:1,muted:!1,rate:1};function OR(){try{let e=window.localStorage.getItem(ER);if(e===null)return DR;let t=JSON.parse(e);if(typeof t!=`object`||!t)return DR;let{volume:n,muted:r,rate:i}=t;return{volume:typeof n==`number`&&n>=0&&n<=1?n:1,muted:r===!0,rate:typeof i==`number`&&TR.some(e=>e===i)?i:1}}catch{return DR}}function kR(e){try{window.localStorage.setItem(ER,JSON.stringify({...OR(),...e}))}catch{}}var AR=null;function jR(e){AR!==null&&AR!==e&&!AR.paused&&AR.pause(),AR=e}function MR(e){AR===e&&(AR=null)}function NR(e,t){e.volume=t.volume,e.muted=t.muted,e.playbackRate=t.rate}function PR(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 FR(e){return`${String(e)}×`}function IR(e,t){return e.filter(e=>e.start<=t).at(-1)}function LR(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var RR=(e,t,n)=>Math.min(n,Math.max(t,e));function zR(){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]=(0,m.useState)(OR),[d,f]=(0,m.useState)(u.volume),[p,h]=(0,m.useState)(u.muted),[g,_]=(0,m.useState)(u.rate);(0,m.useEffect)(()=>{let t=e.current;return t!==null&&NR(t,u),()=>{t!==null&&MR(t)}},[u]);let[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(null),[S,C]=(0,m.useState)(!1),w=Number.isFinite(o)&&o>0,T=()=>{let t=e.current;t!==null&&(t.paused||t.ended?t.play()?.catch(()=>void 0):t.pause())},E=t=>{let n=e.current;if(n===null||!w)return;let r=RR(t,0,o);n.currentTime=r,a(r)},D=t=>E((e.current?.currentTime??i)+t),O=t=>{let n=e.current;if(n===null)return;let r=RR(Math.round(t*100)/100,0,1);n.volume=r,n.muted=r===0,f(r),h(r===0),kR({volume:r,muted:r===0})},k=()=>{let t=e.current;t!==null&&(t.muted=!t.muted,h(t.muted),kR({muted:t.muted}))};return{media:e,menuId:t,playing:n,current:i,duration:o,buffered:c,known:w,volume:d,muted:p,rate:g,menu:v,setMenu:y,hover:b,setHover:x,seeking:S,setSeeking:C,toggle:T,seekTo:E,jump:D,setLevel:O,toggleMute:k,pickRate:n=>{let r=e.current;r!==null&&(r.playbackRate=n),_(n),kR({rate:n}),y(!1),document.getElementById(`${t}-button`)?.focus()},keyAction:e=>{let t=e.length===1?e.toLowerCase():e;if(t===` `||t===`k`)return T;if(t===`j`)return()=>D(-10);if(t===`l`)return()=>D(10);if(t===`ArrowLeft`)return()=>D(-5);if(t===`ArrowRight`)return()=>D(5);if(t===`m`)return k;if(/^[0-9]$/.test(t))return()=>E(Number(t)/10*o)},events:{onPlay:e=>{jR(e.currentTarget),r(!0)},onPause:()=>r(!1),onEnded:()=>r(!1),onTimeUpdate:e=>{S||a(e.currentTarget.currentTime)},onDurationChange:e=>s(e.currentTarget.duration),onLoadedMetadata:e=>{s(e.currentTarget.duration),e.currentTarget.playbackRate=g},onProgress:e=>{let t=e.currentTarget.buffered;l(t.length>0?t.end(t.length-1):0)},onVolumeChange:e=>{f(e.currentTarget.volume),h(e.currentTarget.muted)},onRateChange:e=>_(e.currentTarget.playbackRate)}}}function BR(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:RR((t-n.left)/n.width,0,1)}function VR(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function HR({controls:e,className:t}){return(0,h.jsx)(Nv,{size:`small`,label:e.playing?`Pause`:`Play`,className:t,onClick:e.toggle,children:e.playing?(0,h.jsx)(ll,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(fl,{"aria-hidden":`true`,strokeWidth:1.75})})}function UR({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:PR(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?PR(e.duration):`-:--`}`})]})}function WR({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=YR(r),d=n===void 0?void 0:JR(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(BR(r.current,t.clientX)*a))},g=t=>{let n=BR(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{VR(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:IR(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":`${PR(o)} of ${i?PR(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}),PR(x)]})]})}function GR({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)(Nv,{size:`small`,label:n?`Unmute`:`Mute`,"aria-pressed":n,className:`sl-player__mute`,onClick:e.toggleMute,children:n||r===0?(0,h.jsx)(Dl,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(El,{"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(BR(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel(BR(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];VR(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 KR({controls:e}){let{menuId:t,menu:n,rate:r}=e;return(0,h.jsxs)(`span`,{className:`sl-player__speed`,children:[(0,h.jsx)(z,{id:`${t}-button`,variant:`quiet`,size:`small`,className:`sl-player__rate`,"aria-label":`Playback speed, ${FR(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:FR(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`){VR(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];VR(n,()=>i?.focus())},children:TR.map(t=>(0,h.jsx)(z,{variant:`quiet`,size:`small`,role:`menuitemradio`,"aria-checked":t===r,className:R(`sl-player__option`),autoFocus:t===r,onClick:()=>e.pickRate(t),children:t===1?`Normal`:FR(t)},t))}):null]})}var qR=4;function JR(e,t){let n=Math.floor(t/qR);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 YR(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 XR=2500;function ZR({src:e,poster:t,label:n,portrait:r=!1,square:i=!1,captions:a,chapters:o=[],ref:s,className:c,children:l}){let u=zR(),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,te=a!==void 0||b>0,P=typeof document<`u`&&`pictureInPictureEnabled`in document&&document.pictureInPictureEnabled===!0,ne=(0,m.useCallback)(()=>{k(!0),clearTimeout(p.current),p.current=setTimeout(()=>k(!1),XR)},[]);(0,m.useEffect)(()=>()=>clearTimeout(p.current),[]);let re=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 ie=()=>{let e=d.current;e!==null&&(e.paused||e.ended)&&_(!0),u.toggle()},ae=()=>{let e=f.current;e!==null&&(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()?.catch(()=>void 0))},oe=()=>{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:R(`sl-player`,r&&`sl-player--portrait`,i&&`sl-player--square`,re&&`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`?ie:n===`f`?ae:n===`c`?te?()=>y(e=>!e):void 0:u.keyAction(n);r!==void 0&&(e.preventDefault(),e.stopPropagation(),ne(),r())},onPointerMove:ne,onPointerDown:ne,onFocus:()=>D(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(D(!1),u.setMenu(!1))},children:[(0,h.jsxs)(`video`,{ref:LR(d,s),src:e,poster:t,preload:`metadata`,playsInline:!0,"aria-label":n,onClick:ie,...N,onPlay:e=>{N.onPlay(e),_(!0),ne()},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)(Nv,{label:`Play ${n}`,tip:!1,className:`sl-player__big`,onClick:ie,children:(0,h.jsx)(fl,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsxs)(`div`,{className:`sl-player__bar`,role:`group`,"aria-label":`${n} controls`,children:[(0,h.jsx)(HR,{controls:{...u,toggle:ie}}),(0,h.jsx)(UR,{controls:u}),(0,h.jsx)(WR,{controls:u,chapters:o}),(0,h.jsx)(GR,{controls:u}),(0,h.jsx)(KR,{controls:u}),te?(0,h.jsx)(Nv,{size:`small`,label:`Captions`,"aria-pressed":v,onClick:()=>y(e=>!e),children:(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,P?(0,h.jsx)(Nv,{size:`small`,label:`Picture in picture`,"aria-pressed":w,className:`sl-player__pip`,onClick:oe,children:(0,h.jsx)(dl,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Nv,{size:`small`,label:S?`Exit full screen`:`Full screen`,"aria-pressed":S,onClick:ae,children:S?(0,h.jsx)(cl,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(ol,{"aria-hidden":`true`,strokeWidth:1.75})})]})]})}var QR=[1,2,4];function $R(e,t){let n=QR.indexOf(e);return QR[Math.min(QR.length-1,Math.max(0,n+t))]??1}function ez({src:e,alt:t,zoom:n,onZoom:r}){let[i,a]=(0,m.useState)({x:0,y:0}),o=(0,m.useRef)(null),s=n===1?{x:0,y:0}:i,c=e=>{n!==1&&(e.currentTarget.setPointerCapture?.(e.pointerId),o.current={x:e.clientX,y:e.clientY,from:s})},l=e=>{let t=o.current;t!==null&&a({x:t.from.x+(e.clientX-t.x)/n,y:t.from.y+(e.clientY-t.y)/n})},u=()=>{o.current=null};return(0,h.jsx)(`img`,{src:e,alt:t,draggable:!1,"data-zoom":n,className:n===1?`cursor-zoom-in`:`cursor-grab touch-none active:cursor-grabbing`,style:{transform:`scale(${String(n)}) translate(${String(s.x)}px, ${String(s.y)}px)`,transition:o.current===null?`transform 120ms ease-out`:`none`},onDoubleClick:()=>{a({x:0,y:0}),r(n===1?2:1)},onPointerDown:c,onPointerMove:l,onPointerUp:u,onPointerCancel:u})}var tz={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function nz({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:R(`sl-media m-0`,p),"data-slot":`media-frame`,children:[(0,h.jsxs)(`div`,{className:R(`sl-media__frame`,tz[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)(ek,{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:R(`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 rz({shorts:e=!1,density:t=`default`,list:n=!1,className:r,children:i,label:a}){let o=R(`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 iz({items:e,index:t,onIndex:n,onClose:r,actions:i}){let a=t===null?void 0:e[t],o=e.length,[s,c]=(0,m.useState)(1),l=a!==void 0&&a.kind!==`video`,u=e=>{t!==null&&o!==0&&(c(1),n((t+e+o)%o))};return(0,h.jsx)(Gm,{open:a!==void 0,onOpenChange:e=>{e||(c(1),r())},children:(0,h.jsx)(Ym,{children:(0,h.jsx)(th,{className:`sl-lightbox sl-enter`,onKeyDown:e=>{let t=e.key===`+`||e.key===`=`?1:e.key===`-`?-1:void 0;l&&t!==void 0?(e.preventDefault(),c(e=>$R(e,t))):l&&e.key===`0`?(e.preventDefault(),c(1)):e.key===`ArrowRight`?(e.preventDefault(),u(1)):e.key===`ArrowLeft`&&(e.preventDefault(),u(-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)(oh,{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),l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Nv,{label:`Zoom out`,disabled:s===1,onClick:()=>c(e=>$R(e,-1)),children:(0,h.jsx)(jl,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{label:`Zoom in${s===1?``:`, now ${String(s)}×`}`,disabled:s===4,onClick:()=>c(e=>$R(e,1)),children:(0,h.jsx)(Al,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{label:`Fit`,disabled:s===1,onClick:()=>c(1),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]}):null,(0,h.jsx)(Nv,{label:`Previous`,onClick:()=>u(-1),disabled:o<2,children:(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{label:`Next`,onClick:()=>u(1),disabled:o<2,children:(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Cee,{asChild:!0,children:(0,h.jsx)(Nv,{label:`Close`,children:(0,h.jsx)(kl,{"aria-hidden":`true`,strokeWidth:1.75})})})]})]}),(0,h.jsx)(`div`,{className:`sl-lightbox__stage`,children:a.kind===`video`?(0,h.jsx)(ZR,{src:a.src,label:a.alt,className:`sl-lightbox__player`,...a.poster===void 0?{}:{poster:a.poster}},a.src):(0,h.jsx)(ez,{src:a.src,alt:a.alt,zoom:s,onZoom:c},a.src)}),a.caption===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`p`,{className:`sl-lightbox__caption`,children:a.caption})]})})})})}var az={location:nT(`docker-host`),path:G().min(1)},oz=Xw([J({opened:nT(!0)}).strict(),J({opened:nT(!0),...az}).strict(),J({opened:nT(!1),...az}).strict()]),sz={catalogue:[`catalogue`],retired:[`catalogue`,`retired`],firstRun:[`first-run`]},cz={method:`POST`};async function lz(e,t,n){return L(await e.fetch(`${e.origin}/api/providers/${t}/key/test`,n===void 0?cz:{...cz,headers:{"content-type":`application/json`},body:JSON.stringify({key:n})}))}async function uz(e,t){let n=t===void 0?``:`?provider=${encodeURIComponent(t)}`;return L(await e.fetch(`${e.origin}/api/providers/health${n}`,cz))}async function dz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue`))}async function fz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue/check`,cz))}async function pz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue/refresh`,cz))}async function mz(e){return(await L(await e.fetch(`${e.origin}/api/providers/catalogue/retired`))).usages}async function hz(e,t){await L(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:t.kind,id:t.id,slot:t.slot,from:{provider:t.provider,model:t.model},to:t.replacement?.id??``})}))}async function gz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch-all`,cz))}async function _z(e){return L(await e.fetch(`${e.origin}/api/providers/first-run`))}async function vz(e){let t=await e.fetch(`${e.origin}/api/providers/first-run/dismiss`,cz);t.ok||await L(t)}function yz(e,t){let n=e.providers.find(e=>e.id===t.cli)?.checks.find(e=>e.label===`Signed in`);return n?.state===`ok`?`signed-in`:n?.state===`problem`?`signed-out`:`unknown`}function bz(e){return e.label.replace(/^Sign in to /,``)}async function xz(e){if(!navigator.clipboard)return!1;try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function Sz({fix:e,retry:t,variant:n=`primary`,size:r=`default`}){let{api:i}=B(),a=Lv(),o=bz(e),s=I({mutationFn:async()=>yz(await uz(i,e.cli),e),onSuccess:n=>{if(n===`signed-out`){a(`${o} is still signed out. Run ${e.command} in a terminal on the computer running Slopify, sign in, then press Check again.`,`error`);return}if(t===void 0){a(n===`signed-in`?`${o} is signed in.`:`Slopify couldn't tell whether ${o} is signed in. If ${e.command} finished without an error, try the step again.`,n===`signed-in`?`success`:`info`);return}a(`${o} is signed in. Trying again.`,`success`),t.run()},onError:e=>a(`Slopify couldn't check ${o}'s sign-in: ${e.message} Press Check again in a moment, or use Check all in Settings → Providers.`,`error`)}),c=async()=>{let t=await xz(e.command);a(t?`Copied ${e.command}. Paste it in a terminal on the computer running Slopify and sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.command} in a terminal on the computer running Slopify, sign in, then press Check again.`,t?`success`:`error`)};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{variant:n,size:r,onClick:()=>void c(),children:`Copy sign-in command`}),(0,h.jsx)(z,{variant:`secondary`,size:r,disabled:s.isPending||t?.busy===!0,disabledReason:`Checking the sign-in…`,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check again`})]})}function Cz({fix:e,retry:t,edit:n,variant:r=`primary`,size:i=`default`}){switch(e.kind){case`sign-in`:return(0,h.jsx)(Sz,{fix:e,retry:t,variant:r,size:i});case`provider-settings`:return(0,h.jsx)(GO,{to:`/settings`,search:{section:`providers`},variant:r,size:i,children:e.label});case`free-space`:return(0,h.jsx)(GO,{to:`/settings`,search:{section:`storage`},variant:r,size:i,children:e.label});case`refused`:case`switch-model`:return n??null}}var wz=Zw(`kind`,[J({kind:nT(`allAffected`)}).strict(),J({kind:nT(`selected`),workKeys:q(G().min(1).max(200)).min(1).max(1e4)}).strict()]),Tz=G().min(1).max(64),Ez=J({baseRevisionId:Tz,request:wz}).strict(),Dz=J({baseRevisionId:Tz,idempotencyKey:Uw(),previewId:G().min(1).max(64),acknowledgeUnknownCosts:Kw(),confirmedProvidedWorkKeys:q(G().min(1).max(200)).max(1e4)}).strict(),Oz=J({stage:G(),low:K().finite().nonnegative().nullable(),high:K().finite().nonnegative().nullable(),detail:G(),onPlan:Kw().optional(),apiLow:K().finite().nonnegative().nullable().optional(),apiHigh:K().finite().nonnegative().nullable().optional()}),kz=J({currency:nT(`USD`),rows:q(Oz),low:K().finite().nonnegative(),high:K().finite().nonnegative(),unknown:K().int().nonnegative(),apiLow:K().finite().nonnegative().optional(),apiHigh:K().finite().nonnegative().optional(),apiUnknown:K().int().nonnegative().optional(),expectedWords:K().finite().nonnegative(),catalogueDate:G().nullable(),assumptions:q(G())}),Az=J({revisionId:Tz,admissionId:G().min(1).max(64),workIds:q(G().min(1).max(64)),replayed:Kw()}),jz=J({id:G().min(1).max(64),projectId:G().min(1).max(64),baseRevisionId:Tz,planFingerprint:G().min(1),selection:wz,changedInputs:q(J({path:G(),before:G().nullable(),after:G().nullable()})),work:q(J({key:G(),stage:Y(Db),kind:Y([`provider`,`local`,`provided`]),disposition:Y([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:G(),fingerprint:G(),dependsOn:q(G()),reason:G(),inflight:Kw(),pieceIds:q(G())})),retained:q(J({slot:G(),outputId:G(),assetId:G(),state:Y([`ready`,`outdated`,`review`])})),providedReuseRequired:q(G()),costs:kz,wholeRequestNotice:G().nullable(),warnings:q(G()),review:J({inputChanges:q(J({label:G(),before:G().nullable(),after:G().nullable()})),requests:q(J({key:G(),label:G(),text:G().nullable(),settings:G().nullable()}))}).optional()}),Mz=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],Nz=[`pending`,`running`,`done`,`failed`];J({id:G(),stage_id:G(),kind:Y(Mz),idx:K(),state:Y(Nz),payload:G().nullable()});var Pz=`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(`.`),Fz=[`copying`,`staged`],Iz=J({segment:Y([`body`,`intro`,`outro`]).optional(),subtitleOmissions:q(J({start:K().finite().nonnegative(),text:G()})).optional(),subtitlesMode:Y([`off`,`files`,`burn-in`]).optional(),promptName:G().optional(),prompt:G().optional(),index:K().optional(),short:K().optional(),format:Y([`16:9`,`9:16`,`1:1`]).optional(),sentences:wse([K(),K()]).optional(),warnings:q(G()).optional(),provider:G().optional(),model:G().optional(),voice:G().optional(),loudness:J({pieces:K(),skipped:K(),spreadBefore:K(),spreadAfter:K(),target:K()}).optional(),master:J({target:K(),integrated:K(),truePeak:K()}).optional()}),Lz=J({id:G(),projectId:G(),stageKind:Y(Db),role:Y(Pz),path:G(),originalFilename:G().nullable(),bytes:K().nonnegative(),durationMs:K().nonnegative().nullable(),meta:Iz,createdAt:G()});J({id:G(),stageKind:Y(Db),path:G(),originalFilename:G(),bytes:K().nonnegative(),state:Y(Fz),createdAt:G()});var Rz=G().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),zz=G().min(1).max(256),Bz=$w(zz,Rz),Vz=J({id:Rz,text:G().trim().min(1).max(1e4),start:K().finite().nonnegative(),end:K().finite().positive(),speaker:G().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.`}),Hz=J({from:K().int().positive().max(99),opening:G().min(1).max(2e4),closing:G().min(1).max(2e4),sentences:K().int().positive().max(1e4),title:G().max(200),description:G().max(5e3),hashtags:q(G().max(100)).max(30),why:G().max(2e3),seed:G().max(128).nullable().optional()}).strict(),Uz=J({articleMarkdown:G().max(5e5).optional(),articleEdited:Kw().default(!1),picturesArticle:G().max(5e5).optional(),provided:J({research:Rz.optional(),article:Rz.optional(),audio:Rz.optional(),thumbnail:Rz.optional(),reference:Rz.optional()}).strict(),imageOrder:q(Rz).max(240),imageDefinitions:$w(Rz,J({source:Y([`generate`,`provide`]),assetId:Rz.nullable(),prompt:G().max(5e5).nullable(),templateKey:G().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:$w(zz,Zw(`kind`,[J({kind:nT(`asset`),assetId:Rz}).strict(),J({kind:nT(`text`),text:G().trim().min(1).max(5e5),direction:G().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:$w(zz,J({text:G().min(1).max(5e5),start:K().int().nonnegative().max(5e5),bodyFingerprint:G().regex(/^[0-9a-f]{64}$/u),chunkingFingerprint:G().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:J({audioFingerprint:G().min(1),cues:q(Vz)}).strict().optional(),regenerationTokens:Bz,promptTemplates:$w(G().min(1),G().max(5e5).nullable()),shortsMusic:Rz.optional(),shortsRanges:$w(G().regex(/^[1-9]\d?$/u),J({first:K().int().positive(),last:K().int().positive(),pick:G().min(1).max(128)}).strict()).optional(),shortsKeep:q(Hz).max(20).optional(),ambientBed:Rz.optional(),thumbnailOverrides:eT(Y([`1`,`2`,`3`]),Rz).optional()}).strict(),Wz=J({baseRevisionId:Rz,idempotencyKey:Rz,edit:J({config:oO.strict(),content:Uz,regenerate:q(zz).optional(),uploads:q(J({stagedFileId:Rz,destination:Zw(`kind`,[J({kind:nT(`provided`),stage:Y([`audio`,`thumbnail`,`reference`])}).strict(),J({kind:nT(`image`),imageKey:Rz}).strict(),J({kind:nT(`narration`),key:zz}).strict(),J({kind:nT(`shortsMusic`)}).strict(),J({kind:nT(`thumbnail`),variant:K().int().min(1).max(3)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),Gz=J({baseRevisionId:Rz,idempotencyKey:Rz,targetRevisionId:Rz}).strict(),Kz=J({id:Rz,projectId:Rz,parentId:Rz.nullable(),restoredFromId:Rz.nullable(),config:oO,content:Uz,fingerprints:$w(zz,G()),createdAt:G()}),qz=J({id:Rz,stageId:Rz,kind:Y(Mz),idx:K().int(),state:Y(Nz),payload:G().nullable()}),Jz=J({slot:G(),workKey:zz,assetId:Rz,output:Lz,fingerprint:G(),state:Y([`ready`,`outdated`,`review`])}),Yz=J({key:zz,stageKind:Y(Db),piece:qz,assetId:Rz.nullable(),fingerprint:G()}),Xz={recordId:Rz,publicationId:Rz.nullable(),selected:Kw(),available:Kw()},Zz=J({articleMarkdown:G().nullable(),revision:Kz,outputs:q(Jz.extend(Xz)),pieces:q(Yz.extend(Xz)),current:Kw()}),Qz=J({id:Rz,parentId:Rz.nullable(),restoredFromId:Rz.nullable(),title:G(),createdAt:G(),current:Kw()}),$z=J({ok:nT(!0),view:Zz,duplicate:Kw()}),eB=J({ok:nT(!0),view:Zz,created:Kw()}),tB=J({title:G(),status:K(),detail:G().optional(),reason:G().optional(),currentRevisionId:G().nullable().optional(),fields:q(J({field:G(),message:G()})).optional(),errors:q(J({path:G(),message:G()})).optional()});async function nB(e,t){let n;try{n=await e.json()}catch{throw mo(e,void 0)}if(e.ok)return{ok:!0,value:Co(t,n)};let r=tB.safeParse(n);if(!r.success)throw mo(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw mo(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 rB(e,t,n,r,i){return nB(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 iB(e,t){return rB(e,t,`/revisions/prepare`,eB,{})}function aB(e,t,n){return rB(e,t,`/revisions`,$z,Wz.parse(n))}function oB(e,t,n){return rB(e,t,`/revisions/restore`,$z,Gz.parse(n))}function sB(e,t){return rB(e,t,`/revisions`,J({revisions:q(Qz)}))}function cB(e,t,n){return rB(e,t,`/revisions/${encodeURIComponent(n)}`,J({view:Zz}))}var lB=q(G()).readonly();function uB(e,t,n){return rB(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,J({chunks:J({intro:lB.optional(),body:lB.optional(),outro:lB.optional()}).nullable()}))}function dB(e,t,n){return rB(e,t,`/rebuild/preview`,J({ok:nT(!0),value:jz}),Ez.parse(n))}function fB(e,t,n){return rB(e,t,`/rebuild`,J({ok:nT(!0),value:Az}),Dz.parse(n))}function pB(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function mB(e,t,n,r){let i=await nB(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),oz);if(!i.ok)throw Error(i.message);return i.value}function hB(e,t,n){return pB(e,t,n,`images.zip`)}async function gB(e,{projectId:t,asset:n,folder:r=null}){if(r)return mB(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 mo(i,await ho(i));return oz.parse(await i.json())}var _B=`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 vB(e){return(0,h.jsx)(yB,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function yB(e){let{api:t}=B(),[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 gB(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)(jy,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(ire,{asChild:!0,children:(0,h.jsxs)(z,{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)(Jc,{"aria-hidden":`true`,strokeWidth:1.75}),n?`Locating…`:o?`Locate folder`:`Open folder`]})}),(0,h.jsxs)(Ny,{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:_B}),(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`}),(0,h.jsx)(bB,{path:o})]}),i===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i})]})]})}function bB({path:e}){let[t,n]=(0,m.useState)();return(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(z,{variant:`secondary`,size:`small`,onClick:()=>void xz(e).then(n),children:`Copy path`}),t===void 0?null:(0,h.jsx)(`span`,{role:`status`,className:`text-small text-ink-2`,children:t?`Copied.`:`The browser blocked copying. Select the path and copy it.`})]})}var xB={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function SB(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function CB(){let{api:e}=B(),[t,n]=(0,m.useState)(SB),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)(Iy,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:xB[e]}))}),(0,h.jsxs)(qO,{href:xs(e,t),download:r,children:[(0,h.jsx)(Vc,{"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)(lL,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(lL,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(lL,{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)(lL,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(lL,{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.`})]})]})}function wB({dirty:e,onDiscard:t,saveLabel:n=`Save`,className:r}){return(0,h.jsx)(CR,{tone:e?`warning`:`info`,...r===void 0?{}:{className:r},children:e?(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{children:`Unsaved changes. Press ${n} or Enter to keep them.`}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,onClick:t,children:`Discard`})]}):null})}function TB({className:e,revealLabel:t=`key`,...n}){let[r,i]=(0,m.useState)(!1);return(0,h.jsxs)(`span`,{className:R(`flex min-w-0 items-center gap-1`,e),children:[(0,h.jsx)(X,{...n,type:r?`text`:`password`,className:`min-w-0 flex-1`}),(0,h.jsx)(Nv,{label:r?`Hide ${t}`:`Show ${t}`,"aria-pressed":r,onClick:()=>i(e=>!e),children:r?(0,h.jsx)(Wc,{"aria-hidden":`true`}):(0,h.jsx)(Gc,{"aria-hidden":`true`})})]})}function EB({value:e,revealLabel:t=`token`,className:n}){let[r,i]=(0,m.useState)(!1);return(0,h.jsxs)(`span`,{className:R(`flex min-w-0 items-center gap-1`,n),children:[(0,h.jsx)(`code`,{className:`sl-code min-w-0 flex-1 truncate py-2 select-all`,children:e===void 0?`…`:r?e:`•`.repeat(Math.min(e.length,24))}),(0,h.jsx)(Nv,{label:r?`Hide ${t}`:`Show ${t}`,"aria-pressed":r,disabled:e===void 0,onClick:()=>i(e=>!e),children:r?(0,h.jsx)(Wc,{"aria-hidden":`true`}):(0,h.jsx)(Gc,{"aria-hidden":`true`})})]})}var DB=[`studio`,`plan`];function OB({autoComment:e}){let{api:t}=B(),n=_(),r=Lv(),i=F({queryKey:DB,queryFn:()=>ls(t)}),a=F(kT(t)),o=I({mutationFn:e=>us(t,{...e,rows:[]}),onSuccess:e=>{n.setQueryData(DB,e),n.invalidateQueries({queryKey:[`studio`,`releases`]}),r(`Removed the old posting plan. Each schedule's release times apply now.`,`success`)},onError:e=>r(`The old posting plan wasn't removed: ${e.message} Try Remove the old plan again.`,`error`)}),s=I({mutationFn:e=>ds(t,e),onSuccess:e=>{n.setQueryData(DB,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`)}),c=I({mutationFn:e=>gs(t,e),onSuccess:()=>n.invalidateQueries({queryKey:[`studio`,`settings`]}),onError:e=>r(`Not saved: ${e.message}`,`error`)});if(i.data===void 0)return(0,h.jsxs)(`section`,{"aria-label":`Release times`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{as:`h3`,title:`Release times`}),i.error===null?(0,h.jsx)(jL,{label:`Loading the release settings…`,rows:2,rowClassName:`h-10`}):(0,h.jsx)(ML,{what:`The release settings`,error:i.error,onRetry:()=>void i.refetch(),retrying:i.isFetching})]});let l=i.data.plan,u=(a.data??[]).filter(e=>e.deletedAt===null);return(0,h.jsxs)(`section`,{"aria-label":`Release times`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{as:`h3`,title:`Release times`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Each schedule sets when its videos and shorts go out, one line for each day it runs, with a time for every short its template makes:`,` `,(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`schedules`},children:`Calendar → Schedules`}),` `,`→ Edit → Release times. See and move them in Calendar → Releases.`]}),u.length===0?null:(0,h.jsx)(`p`,{className:`m-0 flex flex-wrap gap-x-3 gap-y-1 text-small`,children:u.map(e=>(0,h.jsx)(KO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name},e.id))}),l.rows.length>0?(0,h.jsx)(fM,{tone:`info`,title:`An older posting plan still applies`,actions:(0,h.jsx)(z,{variant:`secondary`,disabled:o.isPending,onClick:()=>o.mutate(l),children:`Remove the old plan`}),children:(0,h.jsx)(`p`,{className:`m-0`,children:`It has ${String(l.rows.length)} line${l.rows.length===1?``:`s`}, and gives release times to projects no schedule made, and to a schedule's projects when its own times are taken. Set release times in your schedules, then remove it. Times already given keep.`})}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[`Upload and schedule each video and short at least`,(0,h.jsx)(X,{"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&&s.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)(Fy,{checked:e===!0,disabled:c.isPending||e===void 0,onChange:e=>c.mutate(e),label:`Post and pin each video's comment once it is public (the extension posts it in your name)`})]})}var kB=[`studio`,`settings`];function AB(){let{api:e}=B(),t=F({queryKey:kB,queryFn:()=>as(e)});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(U,{title:`Upload pack and extension`,info:`settings.studio.extension`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(MB,{}),(0,h.jsx)(OB,{autoComment:t.data?.autoComment??!1}),(0,h.jsx)(FB,{}),(0,h.jsxs)(`section`,{"aria-label":`Install the Studio extension`,children:[(0,h.jsx)(U,{as:`h3`,title:`Install the Studio extension`,className:`mb-3`}),(0,h.jsx)(CB,{})]})]})]})}var jB=``;function MB(){let{api:e}=B(),t=_(),n=Lv(),r=(0,m.useId)(),i=F({queryKey:kB,queryFn:()=>as(e)}),a=F(Xy(e)),o=(0,m.useId)(),[s,c]=(0,m.useState)(jB),[l,u]=(0,m.useState)({}),d=l[s],f=e=>{u(t=>{let{[s]:n,...r}=t;return e===void 0?r:{...r,[s]:e}})},p=i.data?.playlists??[],g=s===jB?void 0:i.data?.channelPlaylists[s],v=d??(s===jB?p:g??[]),y=PB(v),b=I({mutationFn:t=>os(e,t,s===jB?void 0:s),onSuccess:()=>{f(void 0),t.invalidateQueries({queryKey:kB}),n(`Playlists saved.`,`success`)}}),x=e=>{b.reset(),f(e)},S=y??b.error?.message,C=[{value:jB,label:`Every channel (default)`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(aL,{label:`Playlists`,tip:`settings.studio.playlist`,help:s===jB?`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.`:g===void 0&&p.length>0?`This channel uses the default list (${(e=>e.map(e=>e.name).join(`, `))(p)}) 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)(`form`,{className:`flex flex-col gap-2`,onSubmit:e=>{e.preventDefault(),!b.isPending&&d!==void 0&&y===void 0&&b.mutate(v)},children:[(0,h.jsx)(cL,{id:o,"aria-label":`Channel`,value:s,options:C,onChange:e=>{b.reset(),c(e.currentTarget.value)},className:`max-w-[260px]`}),v.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Type each name exactly as the playlist is called in YouTube Studio.`}),v.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(X,{autoComplete:`off`,"aria-label":`Playlist ${String(t+1)} name`,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":S===void 0?void 0:r,onChange:e=>x(v.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;x(v.map((e,r)=>r===t?{...e,byDefault:n}:e))}}),`On by default`]}),(0,h.jsx)(cL,{"aria-label":`${e.name.trim()||`Playlist ${String(t+1)}`}: takes`,className:`w-[190px]`,value:e.for??`all`,onChange:e=>{let n=e.currentTarget.value,r=n===`long`||n===`shorts`?n:`all`;x(v.map((e,n)=>n===t?{...e,for:r}:e))},options:[{value:`all`,label:`Videos and shorts`},{value:`long`,label:`Long videos only`},{value:`shorts`,label:`Shorts only`}]}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name.trim()||`playlist ${String(t+1)}`}`,onClick:()=>x(v.filter((e,n)=>n!==t)),children:`Remove`})]},t)),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(z,{variant:`secondary`,disabled:i.data===void 0||v.length>=20,onClick:()=>x([...v,{name:``,byDefault:v.length===0}]),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,strokeWidth:1.75}),`Add playlist`]}),(0,h.jsx)(z,{type:`submit`,variant:`primary`,disabled:b.isPending||d===void 0||y!==void 0,disabledReason:y??`Nothing changed since the last save.`,children:`Save playlists`})]}),NB(v)===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:NB(v)}),(0,h.jsx)(wB,{dirty:d!==void 0,saveLabel:`Save playlists`,onDiscard:()=>{b.reset(),f(void 0)}})]}),S===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:S})]})}function NB(e){let t=e.find(e=>/\bshorts?\b/i.test(e.name)&&(e.for??`all`)===`all`);if(t!==void 0)return`"${t.name.trim()}" takes long videos too, and shorts also go into every playlist set to Videos and shorts. Set it to Shorts only, and your long-video playlists to Long videos only.`}function PB(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 FB(){let{api:e}=B(),t=_(),n=Lv(),r=F({queryKey:kB,queryFn:()=>as(e)}),i=I({mutationFn:()=>ws(e),onSuccess:()=>{t.invalidateQueries({queryKey:kB}),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)(H,{id:`settings.studio.pairing`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(EB,{value:a?.token,revealLabel:`pairing token`,className:`flex-1 basis-[220px]`}),(0,h.jsxs)(z,{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)(Bc,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}),`Copy`]}),(0,h.jsx)(z,{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 IB=[`studio`,`queue`];function LB({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)(z,{variant:n,size:r,disabled:!t,disabledReason:`Available once the video has been made`,onClick:()=>a(!0),children:`Prepare upload`}),i?(0,h.jsx)(VB,{projectId:e,onClose:()=>a(!1)}):null]})}var RB={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 zB(e){return new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`}).format(new Date(e))}function BB(e){return e.kind===`video`?`video`:`short-${String(e.short)}`}function VB({projectId:e,onClose:t}){let{api:n}=B(),r=_(),i=[`studio`,`pack`,e],a=F({queryKey:i,queryFn:()=>Ts(n,e)}),[o,s]=(0,m.useState)(`video`),[c,l]=(0,m.useState)(),u=a.data?.items??[],d=u.find(e=>BB(e)===o)??u[0],f=F({queryKey:kB,queryFn:()=>as(n)}),p=f.data===void 0?void 0:f.data.pairing.origin!==null,g=F({queryKey:IB,queryFn:()=>Ss(n)}),v=I({mutationFn:t=>Ds(n,e,t.short),onSuccess:e=>{r.setQueryData(IB,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=I({mutationFn:e=>Cs(n,e.projectId,e.short),onSuccess:e=>r.setQueryData(IB,e),onError:e=>l({text:`Couldn't remove it from Waiting for Studio: ${e.message} Press Remove again.`,tone:`error`})}),b=I({mutationFn:t=>Es(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=I({mutationFn:t=>ss(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=I({mutationFn:t=>_s(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=I({mutationFn:t=>cs(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)(eM,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(CR,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(qO,{href:fR,target:`_blank`,rel:`noopener noreferrer`,variant:`secondary`,children:`Open YouTube Studio`}):null,(0,h.jsx)(z,{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(fR,`_blank`,`noopener`),v.mutate(d))},children:`Fill in YouTube Studio`}),(0,h.jsx)(H,{id:`project.upload.fill-studio`})]}),children:[a.error===null?null:(0,h.jsx)(fM,{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)(fM,{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)(CB,{})]})}):null,u.length>1?(0,h.jsx)(Iy,{label:`What to upload`,value:d===void 0?``:BB(d),onChange:s,tip:`project.upload.item`,options:u.map(e=>({value:BB(e),label:e.kind===`video`?`Video`:`Short ${String(e.short)}`})),className:`self-start`}):null,a.data.missing.length===0?null:(0,h.jsx)(fM,{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)(WB,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(Fy,{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`,...Py,children:[(0,h.jsx)(cL,{"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:zB(a.data.schedule.longAt)}],...(a.data.slotChoices??[]).map(e=>({value:`${e.row}|${e.longAt}`,label:zB(e.longAt)}))]}),(0,h.jsx)(H,{id:`project.upload.slot`})]}):void 0,picking:C.isPending,doneKey:`slopify.upload.${e}.${BB(d)}`},BB(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)(H,{id:`project.upload.queue`,className:`-my-1`})]}),(0,h.jsx)(qL,{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)(JL,{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)(z,{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)(fM,{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 HB(e){try{let t=JSON.parse(localStorage.getItem(e)??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function UB({href:e,filename:t}){return(0,h.jsxs)(qO,{href:e,download:t,"aria-label":`Download ${t}`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download`]})}function WB({projectId:e,item:t,footageSwitch:n,playlistPicker:r,copy:i,onPick:a,picking:o,slotPicker:s,doneKey:c}){let{api:l}=B(),[u,d]=(0,m.useState)(()=>HB(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=pR.filter(e=>e!==`thumbnails`||t.kind===`video`),y=v.filter(e=>u.includes(e)).length,b=e=>{let n=KB(t,e);return(0,h.jsxs)(z,{variant:`quiet`,size:`small`,disabled:n===``,disabledReason:`Nothing to copy yet`,"aria-label":`Copy ${RB[e].toLowerCase()}`,onClick:()=>i(n,RB[e].toLowerCase()),children:[(0,h.jsx)(Bc,{"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)(UB,{href:`${l.origin}${t.video.url}`,filename:t.video.filename}),(0,h.jsx)(vB,{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?`${GB(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)(vB,{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?KB(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:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:KB(t,c)}),(0,h.jsx)(qB,{title:t.title})]}),actions:b(c)}:{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(qB,{title:t.title}),(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)(z,{variant:`quiet`,size:`small`,"aria-label":`Copy the other titles`,onClick:()=>i(t.titles.join(`
160
+ `),_R=`Built-in`,vR=/[<>]/;function yR(e){let t=e.trim();if(t.length>100)return`YouTube takes titles of up to 100 characters; this one has ${String(t.length)}. Shorten it.`;if(vR.test(t))return`YouTube doesn't allow < or > in a title. Remove them.`}function bR(e){if(e.length>5e3)return`YouTube takes descriptions of up to ${hR.toLocaleString(`en-US`)} characters; this one has ${e.length.toLocaleString(`en-US`)}. Shorten it.`;if(vR.test(e))return`YouTube doesn't allow < or > in a description. Remove them.`}function xR(e){let t=e.split(/\s+/u).filter(e=>e.startsWith(`#`)&&e.length>1).length;if(t!==0)return t>60?`${String(t)} hashtags: YouTube ignores every hashtag when there are more than 60. Remove ${String(t-60)}.`:`${String(t)} hashtag${t===1?``:`s`}; the first ${String(Math.min(t,3))} show above the title.`}var SR={info:`text-ink-2`,error:`text-danger`,warning:`text-waiting`,success:`text-accent-ink`};function CR({children:e,tone:t=`info`,className:n,id:r}){let i=typeof e==`string`?e:void 0;return(0,h.jsx)(`div`,{id:r,"data-slot":`status-slot`,role:t===`error`?`alert`:`status`,title:i,className:R(`flex min-h-8 min-w-0 flex-1 items-center gap-2 overflow-hidden text-small`,SR[t],n),children:e==null||e===!1?null:i===void 0?e:(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:i})})}function wR({status:e,children:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`action-bar`,className:R(`sticky bottom-0 z-20 -mx-4 mt-6 flex min-h-14 flex-wrap items-center gap-x-3 gap-y-2 border-t border-line bg-surface px-4 py-2 pb-[max(8px,env(safe-area-inset-bottom))] max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))] md:-mx-10 md:px-10`,n),children:[(0,h.jsx)(`div`,{className:`flex w-full min-w-0 sm:w-auto sm:flex-1`,children:e??(0,h.jsx)(CR,{})}),(0,h.jsx)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:t})]})}var TR=[.75,1,1.25,1.5,1.75,2],ER=`slopify.playback`,DR={volume:1,muted:!1,rate:1};function OR(){try{let e=window.localStorage.getItem(ER);if(e===null)return DR;let t=JSON.parse(e);if(typeof t!=`object`||!t)return DR;let{volume:n,muted:r,rate:i}=t;return{volume:typeof n==`number`&&n>=0&&n<=1?n:1,muted:r===!0,rate:typeof i==`number`&&TR.some(e=>e===i)?i:1}}catch{return DR}}function kR(e){try{window.localStorage.setItem(ER,JSON.stringify({...OR(),...e}))}catch{}}var AR=null;function jR(e){AR!==null&&AR!==e&&!AR.paused&&AR.pause(),AR=e}function MR(e){AR===e&&(AR=null)}function NR(e,t){e.volume=t.volume,e.muted=t.muted,e.playbackRate=t.rate}function PR(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 FR(e){return`${String(e)}×`}function IR(e,t){return e.filter(e=>e.start<=t).at(-1)}function LR(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var RR=(e,t,n)=>Math.min(n,Math.max(t,e));function zR(){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]=(0,m.useState)(OR),[d,f]=(0,m.useState)(u.volume),[p,h]=(0,m.useState)(u.muted),[g,_]=(0,m.useState)(u.rate);(0,m.useEffect)(()=>{let t=e.current;return t!==null&&NR(t,u),()=>{t!==null&&MR(t)}},[u]);let[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(null),[S,C]=(0,m.useState)(!1),w=Number.isFinite(o)&&o>0,T=()=>{let t=e.current;t!==null&&(t.paused||t.ended?t.play()?.catch(()=>void 0):t.pause())},E=t=>{let n=e.current;if(n===null||!w)return;let r=RR(t,0,o);n.currentTime=r,a(r)},D=t=>E((e.current?.currentTime??i)+t),O=t=>{let n=e.current;if(n===null)return;let r=RR(Math.round(t*100)/100,0,1);n.volume=r,n.muted=r===0,f(r),h(r===0),kR({volume:r,muted:r===0})},k=()=>{let t=e.current;t!==null&&(t.muted=!t.muted,h(t.muted),kR({muted:t.muted}))};return{media:e,menuId:t,playing:n,current:i,duration:o,buffered:c,known:w,volume:d,muted:p,rate:g,menu:v,setMenu:y,hover:b,setHover:x,seeking:S,setSeeking:C,toggle:T,seekTo:E,jump:D,setLevel:O,toggleMute:k,pickRate:n=>{let r=e.current;r!==null&&(r.playbackRate=n),_(n),kR({rate:n}),y(!1),document.getElementById(`${t}-button`)?.focus()},keyAction:e=>{let t=e.length===1?e.toLowerCase():e;if(t===` `||t===`k`)return T;if(t===`j`)return()=>D(-10);if(t===`l`)return()=>D(10);if(t===`ArrowLeft`)return()=>D(-5);if(t===`ArrowRight`)return()=>D(5);if(t===`m`)return k;if(/^[0-9]$/.test(t))return()=>E(Number(t)/10*o)},events:{onPlay:e=>{jR(e.currentTarget),r(!0)},onPause:()=>r(!1),onEnded:()=>r(!1),onTimeUpdate:e=>{S||a(e.currentTarget.currentTime)},onDurationChange:e=>s(e.currentTarget.duration),onLoadedMetadata:e=>{s(e.currentTarget.duration),e.currentTarget.playbackRate=g},onProgress:e=>{let t=e.currentTarget.buffered;l(t.length>0?t.end(t.length-1):0)},onVolumeChange:e=>{f(e.currentTarget.volume),h(e.currentTarget.muted)},onRateChange:e=>_(e.currentTarget.playbackRate)}}}function BR(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:RR((t-n.left)/n.width,0,1)}function VR(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function HR({controls:e,className:t}){return(0,h.jsx)(Nv,{size:`small`,label:e.playing?`Pause`:`Play`,className:t,onClick:e.toggle,children:e.playing?(0,h.jsx)(ll,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(fl,{"aria-hidden":`true`,strokeWidth:1.75})})}function UR({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:PR(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?PR(e.duration):`-:--`}`})]})}function WR({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=YR(r),d=n===void 0?void 0:JR(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(BR(r.current,t.clientX)*a))},g=t=>{let n=BR(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{VR(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:IR(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":`${PR(o)} of ${i?PR(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}),PR(x)]})]})}function GR({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)(Nv,{size:`small`,label:n?`Unmute`:`Mute`,"aria-pressed":n,className:`sl-player__mute`,onClick:e.toggleMute,children:n||r===0?(0,h.jsx)(Dl,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(El,{"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(BR(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel(BR(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];VR(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 KR({controls:e}){let{menuId:t,menu:n,rate:r}=e;return(0,h.jsxs)(`span`,{className:`sl-player__speed`,children:[(0,h.jsx)(z,{id:`${t}-button`,variant:`quiet`,size:`small`,className:`sl-player__rate`,"aria-label":`Playback speed, ${FR(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:FR(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`){VR(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];VR(n,()=>i?.focus())},children:TR.map(t=>(0,h.jsx)(z,{variant:`quiet`,size:`small`,role:`menuitemradio`,"aria-checked":t===r,className:R(`sl-player__option`),autoFocus:t===r,onClick:()=>e.pickRate(t),children:t===1?`Normal`:FR(t)},t))}):null]})}var qR=4;function JR(e,t){let n=Math.floor(t/qR);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 YR(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 XR=2500;function ZR({src:e,poster:t,label:n,portrait:r=!1,square:i=!1,captions:a,chapters:o=[],ref:s,className:c,children:l}){let u=zR(),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,te=a!==void 0||b>0,P=typeof document<`u`&&`pictureInPictureEnabled`in document&&document.pictureInPictureEnabled===!0,ne=(0,m.useCallback)(()=>{k(!0),clearTimeout(p.current),p.current=setTimeout(()=>k(!1),XR)},[]);(0,m.useEffect)(()=>()=>clearTimeout(p.current),[]);let re=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 ie=()=>{let e=d.current;e!==null&&(e.paused||e.ended)&&_(!0),u.toggle()},ae=()=>{let e=f.current;e!==null&&(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()?.catch(()=>void 0))},oe=()=>{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:R(`sl-player`,r&&`sl-player--portrait`,i&&`sl-player--square`,re&&`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`?ie:n===`f`?ae:n===`c`?te?()=>y(e=>!e):void 0:u.keyAction(n);r!==void 0&&(e.preventDefault(),e.stopPropagation(),ne(),r())},onPointerMove:ne,onPointerDown:ne,onFocus:()=>D(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(D(!1),u.setMenu(!1))},children:[(0,h.jsxs)(`video`,{ref:LR(d,s),src:e,poster:t,preload:`metadata`,playsInline:!0,"aria-label":n,onClick:ie,...N,onPlay:e=>{N.onPlay(e),_(!0),ne()},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)(Nv,{label:`Play ${n}`,tip:!1,className:`sl-player__big`,onClick:ie,children:(0,h.jsx)(fl,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsxs)(`div`,{className:`sl-player__bar`,role:`group`,"aria-label":`${n} controls`,children:[(0,h.jsx)(HR,{controls:{...u,toggle:ie}}),(0,h.jsx)(UR,{controls:u}),(0,h.jsx)(WR,{controls:u,chapters:o}),(0,h.jsx)(GR,{controls:u}),(0,h.jsx)(KR,{controls:u}),te?(0,h.jsx)(Nv,{size:`small`,label:`Captions`,"aria-pressed":v,onClick:()=>y(e=>!e),children:(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,P?(0,h.jsx)(Nv,{size:`small`,label:`Picture in picture`,"aria-pressed":w,className:`sl-player__pip`,onClick:oe,children:(0,h.jsx)(dl,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Nv,{size:`small`,label:S?`Exit full screen`:`Full screen`,"aria-pressed":S,onClick:ae,children:S?(0,h.jsx)(cl,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(ol,{"aria-hidden":`true`,strokeWidth:1.75})})]})]})}var QR=[1,2,4];function $R(e,t){let n=QR.indexOf(e);return QR[Math.min(QR.length-1,Math.max(0,n+t))]??1}function ez({src:e,alt:t,zoom:n,onZoom:r}){let[i,a]=(0,m.useState)({x:0,y:0}),o=(0,m.useRef)(null),s=n===1?{x:0,y:0}:i,c=e=>{n!==1&&(e.currentTarget.setPointerCapture?.(e.pointerId),o.current={x:e.clientX,y:e.clientY,from:s})},l=e=>{let t=o.current;t!==null&&a({x:t.from.x+(e.clientX-t.x)/n,y:t.from.y+(e.clientY-t.y)/n})},u=()=>{o.current=null};return(0,h.jsx)(`img`,{src:e,alt:t,draggable:!1,"data-zoom":n,className:n===1?`cursor-zoom-in`:`cursor-grab touch-none active:cursor-grabbing`,style:{transform:`scale(${String(n)}) translate(${String(s.x)}px, ${String(s.y)}px)`,transition:o.current===null?`transform 120ms ease-out`:`none`},onDoubleClick:()=>{a({x:0,y:0}),r(n===1?2:1)},onPointerDown:c,onPointerMove:l,onPointerUp:u,onPointerCancel:u})}var tz={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function nz({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:R(`sl-media m-0`,p),"data-slot":`media-frame`,children:[(0,h.jsxs)(`div`,{className:R(`sl-media__frame`,tz[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)(ek,{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:R(`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 rz({shorts:e=!1,density:t=`default`,list:n=!1,className:r,children:i,label:a}){let o=R(`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 iz({items:e,index:t,onIndex:n,onClose:r,actions:i}){let a=t===null?void 0:e[t],o=e.length,[s,c]=(0,m.useState)(1),l=a!==void 0&&a.kind!==`video`,u=e=>{t!==null&&o!==0&&(c(1),n((t+e+o)%o))};return(0,h.jsx)(Gm,{open:a!==void 0,onOpenChange:e=>{e||(c(1),r())},children:(0,h.jsx)(Ym,{children:(0,h.jsx)(th,{className:`sl-lightbox sl-enter`,onKeyDown:e=>{let t=e.key===`+`||e.key===`=`?1:e.key===`-`?-1:void 0;l&&t!==void 0?(e.preventDefault(),c(e=>$R(e,t))):l&&e.key===`0`?(e.preventDefault(),c(1)):e.key===`ArrowRight`?(e.preventDefault(),u(1)):e.key===`ArrowLeft`&&(e.preventDefault(),u(-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)(oh,{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),l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Nv,{label:`Zoom out`,disabled:s===1,onClick:()=>c(e=>$R(e,-1)),children:(0,h.jsx)(jl,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{label:`Zoom in${s===1?``:`, now ${String(s)}×`}`,disabled:s===4,onClick:()=>c(e=>$R(e,1)),children:(0,h.jsx)(Al,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{label:`Fit`,disabled:s===1,onClick:()=>c(1),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]}):null,(0,h.jsx)(Nv,{label:`Previous`,onClick:()=>u(-1),disabled:o<2,children:(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{label:`Next`,onClick:()=>u(1),disabled:o<2,children:(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Cee,{asChild:!0,children:(0,h.jsx)(Nv,{label:`Close`,children:(0,h.jsx)(kl,{"aria-hidden":`true`,strokeWidth:1.75})})})]})]}),(0,h.jsx)(`div`,{className:`sl-lightbox__stage`,children:a.kind===`video`?(0,h.jsx)(ZR,{src:a.src,label:a.alt,className:`sl-lightbox__player`,...a.poster===void 0?{}:{poster:a.poster}},a.src):(0,h.jsx)(ez,{src:a.src,alt:a.alt,zoom:s,onZoom:c},a.src)}),a.caption===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`p`,{className:`sl-lightbox__caption`,children:a.caption})]})})})})}var az={location:nT(`docker-host`),path:G().min(1)},oz=Xw([J({opened:nT(!0)}).strict(),J({opened:nT(!0),...az}).strict(),J({opened:nT(!1),...az}).strict()]),sz={catalogue:[`catalogue`],retired:[`catalogue`,`retired`],firstRun:[`first-run`]},cz={method:`POST`};async function lz(e,t,n){return L(await e.fetch(`${e.origin}/api/providers/${t}/key/test`,n===void 0?cz:{...cz,headers:{"content-type":`application/json`},body:JSON.stringify({key:n})}))}async function uz(e,t){let n=t===void 0?``:`?provider=${encodeURIComponent(t)}`;return L(await e.fetch(`${e.origin}/api/providers/health${n}`,cz))}async function dz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue`))}async function fz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue/check`,cz))}async function pz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue/refresh`,cz))}async function mz(e){return(await L(await e.fetch(`${e.origin}/api/providers/catalogue/retired`))).usages}async function hz(e,t){await L(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:t.kind,id:t.id,slot:t.slot,from:{provider:t.provider,model:t.model},to:t.replacement?.id??``})}))}async function gz(e){return L(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch-all`,cz))}async function _z(e){return L(await e.fetch(`${e.origin}/api/providers/first-run`))}async function vz(e){let t=await e.fetch(`${e.origin}/api/providers/first-run/dismiss`,cz);t.ok||await L(t)}function yz(e,t){let n=e.providers.find(e=>e.id===t.cli)?.checks.find(e=>e.label===`Signed in`);return n?.state===`ok`?`signed-in`:n?.state===`problem`?`signed-out`:`unknown`}function bz(e){return e.label.replace(/^Sign in to /,``)}async function xz(e){if(!navigator.clipboard)return!1;try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function Sz({fix:e,retry:t,variant:n=`primary`,size:r=`default`}){let{api:i}=B(),a=Lv(),o=bz(e),s=I({mutationFn:async()=>yz(await uz(i,e.cli),e),onSuccess:n=>{if(n===`signed-out`){a(`${o} is still signed out. Run ${e.command} in a terminal on the computer running Slopify, sign in, then press Check again.`,`error`);return}if(t===void 0){a(n===`signed-in`?`${o} is signed in.`:`Slopify couldn't tell whether ${o} is signed in. If ${e.command} finished without an error, try the step again.`,n===`signed-in`?`success`:`info`);return}a(`${o} is signed in. Trying again.`,`success`),t.run()},onError:e=>a(`Slopify couldn't check ${o}'s sign-in: ${e.message} Press Check again in a moment, or use Check all in Settings → Providers.`,`error`)}),c=async()=>{let t=await xz(e.command);a(t?`Copied ${e.command}. Paste it in a terminal on the computer running Slopify and sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.command} in a terminal on the computer running Slopify, sign in, then press Check again.`,t?`success`:`error`)};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{variant:n,size:r,onClick:()=>void c(),children:`Copy sign-in command`}),(0,h.jsx)(z,{variant:`secondary`,size:r,disabled:s.isPending||t?.busy===!0,disabledReason:`Checking the sign-in…`,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check again`})]})}function Cz({fix:e,retry:t,edit:n,variant:r=`primary`,size:i=`default`}){switch(e.kind){case`sign-in`:return(0,h.jsx)(Sz,{fix:e,retry:t,variant:r,size:i});case`provider-settings`:return(0,h.jsx)(GO,{to:`/settings`,search:{section:`providers`},variant:r,size:i,children:e.label});case`free-space`:return(0,h.jsx)(GO,{to:`/settings`,search:{section:`storage`},variant:r,size:i,children:e.label});case`refused`:case`switch-model`:return n??null}}var wz=Zw(`kind`,[J({kind:nT(`allAffected`)}).strict(),J({kind:nT(`selected`),workKeys:q(G().min(1).max(200)).min(1).max(1e4)}).strict()]),Tz=G().min(1).max(64),Ez=J({baseRevisionId:Tz,request:wz}).strict(),Dz=J({baseRevisionId:Tz,idempotencyKey:Uw(),previewId:G().min(1).max(64),acknowledgeUnknownCosts:Kw(),confirmedProvidedWorkKeys:q(G().min(1).max(200)).max(1e4)}).strict(),Oz=J({stage:G(),low:K().finite().nonnegative().nullable(),high:K().finite().nonnegative().nullable(),detail:G(),onPlan:Kw().optional(),apiLow:K().finite().nonnegative().nullable().optional(),apiHigh:K().finite().nonnegative().nullable().optional()}),kz=J({currency:nT(`USD`),rows:q(Oz),low:K().finite().nonnegative(),high:K().finite().nonnegative(),unknown:K().int().nonnegative(),apiLow:K().finite().nonnegative().optional(),apiHigh:K().finite().nonnegative().optional(),apiUnknown:K().int().nonnegative().optional(),expectedWords:K().finite().nonnegative(),catalogueDate:G().nullable(),assumptions:q(G())}),Az=J({revisionId:Tz,admissionId:G().min(1).max(64),workIds:q(G().min(1).max(64)),replayed:Kw()}),jz=J({id:G().min(1).max(64),projectId:G().min(1).max(64),baseRevisionId:Tz,planFingerprint:G().min(1),selection:wz,changedInputs:q(J({path:G(),before:G().nullable(),after:G().nullable()})),work:q(J({key:G(),stage:Y(Db),kind:Y([`provider`,`local`,`provided`]),disposition:Y([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:G(),fingerprint:G(),dependsOn:q(G()),reason:G(),inflight:Kw(),pieceIds:q(G())})),retained:q(J({slot:G(),outputId:G(),assetId:G(),state:Y([`ready`,`outdated`,`review`])})),providedReuseRequired:q(G()),costs:kz,wholeRequestNotice:G().nullable(),warnings:q(G()),review:J({inputChanges:q(J({label:G(),before:G().nullable(),after:G().nullable()})),requests:q(J({key:G(),label:G(),text:G().nullable(),settings:G().nullable()}))}).optional()}),Mz=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],Nz=[`pending`,`running`,`done`,`failed`];J({id:G(),stage_id:G(),kind:Y(Mz),idx:K(),state:Y(Nz),payload:G().nullable()});var Pz=`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(`.`),Fz=[`copying`,`staged`],Iz=J({segment:Y([`body`,`intro`,`outro`]).optional(),subtitleOmissions:q(J({start:K().finite().nonnegative(),text:G()})).optional(),subtitlesMode:Y([`off`,`files`,`burn-in`]).optional(),promptName:G().optional(),prompt:G().optional(),index:K().optional(),short:K().optional(),format:Y([`16:9`,`9:16`,`1:1`]).optional(),sentences:wse([K(),K()]).optional(),warnings:q(G()).optional(),provider:G().optional(),model:G().optional(),voice:G().optional(),loudness:J({pieces:K(),skipped:K(),spreadBefore:K(),spreadAfter:K(),target:K()}).optional(),master:J({target:K(),integrated:K(),truePeak:K()}).optional()}),Lz=J({id:G(),projectId:G(),stageKind:Y(Db),role:Y(Pz),path:G(),originalFilename:G().nullable(),bytes:K().nonnegative(),durationMs:K().nonnegative().nullable(),meta:Iz,createdAt:G()});J({id:G(),stageKind:Y(Db),path:G(),originalFilename:G(),bytes:K().nonnegative(),state:Y(Fz),createdAt:G()});var Rz=G().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),zz=G().min(1).max(256),Bz=$w(zz,Rz),Vz=J({id:Rz,text:G().trim().min(1).max(1e4),start:K().finite().nonnegative(),end:K().finite().positive(),speaker:G().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.`}),Hz=J({from:K().int().positive().max(99),opening:G().min(1).max(2e4),closing:G().min(1).max(2e4),sentences:K().int().positive().max(1e4),title:G().max(200),description:G().max(5e3),hashtags:q(G().max(100)).max(30),why:G().max(2e3),seed:G().max(128).nullable().optional()}).strict(),Uz=J({articleMarkdown:G().max(5e5).optional(),articleEdited:Kw().default(!1),picturesArticle:G().max(5e5).optional(),provided:J({research:Rz.optional(),article:Rz.optional(),audio:Rz.optional(),thumbnail:Rz.optional(),reference:Rz.optional()}).strict(),imageOrder:q(Rz).max(240),imageDefinitions:$w(Rz,J({source:Y([`generate`,`provide`]),assetId:Rz.nullable(),prompt:G().max(5e5).nullable(),templateKey:G().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:$w(zz,Zw(`kind`,[J({kind:nT(`asset`),assetId:Rz}).strict(),J({kind:nT(`text`),text:G().trim().min(1).max(5e5),direction:G().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:$w(zz,J({text:G().min(1).max(5e5),start:K().int().nonnegative().max(5e5),bodyFingerprint:G().regex(/^[0-9a-f]{64}$/u),chunkingFingerprint:G().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(),narrationAnchors:J({chunkingFingerprint:G().regex(/^[0-9a-f]{64}$/u),texts:q(G().min(1).max(5e5)).max(1e4)}).strict().refine(e=>e.texts.reduce((e,t)=>e+t.length,0)<=5e5,`Narration anchors exceed the article limit.`).optional(),subtitleCues:J({audioFingerprint:G().min(1),cues:q(Vz)}).strict().optional(),regenerationTokens:Bz,promptTemplates:$w(G().min(1),G().max(5e5).nullable()),shortsMusic:Rz.optional(),shortsRanges:$w(G().regex(/^[1-9]\d?$/u),J({first:K().int().positive(),last:K().int().positive(),pick:G().min(1).max(128)}).strict()).optional(),shortsKeep:q(Hz).max(20).optional(),ambientBed:Rz.optional(),thumbnailOverrides:eT(Y([`1`,`2`,`3`]),Rz).optional()}).strict(),Wz=J({baseRevisionId:Rz,idempotencyKey:Rz,edit:J({config:oO.strict(),content:Uz,regenerate:q(zz).optional(),uploads:q(J({stagedFileId:Rz,destination:Zw(`kind`,[J({kind:nT(`provided`),stage:Y([`audio`,`thumbnail`,`reference`])}).strict(),J({kind:nT(`image`),imageKey:Rz}).strict(),J({kind:nT(`narration`),key:zz}).strict(),J({kind:nT(`shortsMusic`)}).strict(),J({kind:nT(`thumbnail`),variant:K().int().min(1).max(3)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),Gz=J({baseRevisionId:Rz,idempotencyKey:Rz,targetRevisionId:Rz}).strict(),Kz=J({id:Rz,projectId:Rz,parentId:Rz.nullable(),restoredFromId:Rz.nullable(),config:oO,content:Uz,fingerprints:$w(zz,G()),createdAt:G()}),qz=J({id:Rz,stageId:Rz,kind:Y(Mz),idx:K().int(),state:Y(Nz),payload:G().nullable()}),Jz=J({slot:G(),workKey:zz,assetId:Rz,output:Lz,fingerprint:G(),state:Y([`ready`,`outdated`,`review`])}),Yz=J({key:zz,stageKind:Y(Db),piece:qz,assetId:Rz.nullable(),fingerprint:G()}),Xz={recordId:Rz,publicationId:Rz.nullable(),selected:Kw(),available:Kw()},Zz=J({articleMarkdown:G().nullable(),revision:Kz,outputs:q(Jz.extend(Xz)),pieces:q(Yz.extend(Xz)),current:Kw()}),Qz=J({id:Rz,parentId:Rz.nullable(),restoredFromId:Rz.nullable(),title:G(),createdAt:G(),current:Kw()}),$z=J({ok:nT(!0),view:Zz,duplicate:Kw()}),eB=J({ok:nT(!0),view:Zz,created:Kw()}),tB=J({title:G(),status:K(),detail:G().optional(),reason:G().optional(),currentRevisionId:G().nullable().optional(),fields:q(J({field:G(),message:G()})).optional(),errors:q(J({path:G(),message:G()})).optional()});async function nB(e,t){let n;try{n=await e.json()}catch{throw mo(e,void 0)}if(e.ok)return{ok:!0,value:Co(t,n)};let r=tB.safeParse(n);if(!r.success)throw mo(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw mo(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 rB(e,t,n,r,i){return nB(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 iB(e,t){return rB(e,t,`/revisions/prepare`,eB,{})}function aB(e,t,n){return rB(e,t,`/revisions`,$z,Wz.parse(n))}function oB(e,t,n){return rB(e,t,`/revisions/restore`,$z,Gz.parse(n))}function sB(e,t){return rB(e,t,`/revisions`,J({revisions:q(Qz)}))}function cB(e,t,n){return rB(e,t,`/revisions/${encodeURIComponent(n)}`,J({view:Zz}))}var lB=q(G()).readonly();function uB(e,t,n){return rB(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,J({chunks:J({intro:lB.optional(),body:lB.optional(),outro:lB.optional()}).nullable()}))}function dB(e,t,n){return rB(e,t,`/rebuild/preview`,J({ok:nT(!0),value:jz}),Ez.parse(n))}function fB(e,t,n){return rB(e,t,`/rebuild`,J({ok:nT(!0),value:Az}),Dz.parse(n))}function pB(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function mB(e,t,n,r){let i=await nB(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),oz);if(!i.ok)throw Error(i.message);return i.value}function hB(e,t,n){return pB(e,t,n,`images.zip`)}async function gB(e,{projectId:t,asset:n,folder:r=null}){if(r)return mB(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 mo(i,await ho(i));return oz.parse(await i.json())}var _B=`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 vB(e){return(0,h.jsx)(yB,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function yB(e){let{api:t}=B(),[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 gB(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)(jy,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(ire,{asChild:!0,children:(0,h.jsxs)(z,{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)(Jc,{"aria-hidden":`true`,strokeWidth:1.75}),n?`Locating…`:o?`Locate folder`:`Open folder`]})}),(0,h.jsxs)(Ny,{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:_B}),(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`}),(0,h.jsx)(bB,{path:o})]}),i===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i})]})]})}function bB({path:e}){let[t,n]=(0,m.useState)();return(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(z,{variant:`secondary`,size:`small`,onClick:()=>void xz(e).then(n),children:`Copy path`}),t===void 0?null:(0,h.jsx)(`span`,{role:`status`,className:`text-small text-ink-2`,children:t?`Copied.`:`The browser blocked copying. Select the path and copy it.`})]})}var xB={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function SB(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function CB(){let{api:e}=B(),[t,n]=(0,m.useState)(SB),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)(Iy,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:xB[e]}))}),(0,h.jsxs)(qO,{href:xs(e,t),download:r,children:[(0,h.jsx)(Vc,{"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)(lL,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(lL,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(lL,{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)(lL,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(lL,{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.`})]})]})}function wB({dirty:e,onDiscard:t,saveLabel:n=`Save`,className:r}){return(0,h.jsx)(CR,{tone:e?`warning`:`info`,...r===void 0?{}:{className:r},children:e?(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{children:`Unsaved changes. Press ${n} or Enter to keep them.`}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,onClick:t,children:`Discard`})]}):null})}function TB({className:e,revealLabel:t=`key`,...n}){let[r,i]=(0,m.useState)(!1);return(0,h.jsxs)(`span`,{className:R(`flex min-w-0 items-center gap-1`,e),children:[(0,h.jsx)(X,{...n,type:r?`text`:`password`,className:`min-w-0 flex-1`}),(0,h.jsx)(Nv,{label:r?`Hide ${t}`:`Show ${t}`,"aria-pressed":r,onClick:()=>i(e=>!e),children:r?(0,h.jsx)(Wc,{"aria-hidden":`true`}):(0,h.jsx)(Gc,{"aria-hidden":`true`})})]})}function EB({value:e,revealLabel:t=`token`,className:n}){let[r,i]=(0,m.useState)(!1);return(0,h.jsxs)(`span`,{className:R(`flex min-w-0 items-center gap-1`,n),children:[(0,h.jsx)(`code`,{className:`sl-code min-w-0 flex-1 truncate py-2 select-all`,children:e===void 0?`…`:r?e:`•`.repeat(Math.min(e.length,24))}),(0,h.jsx)(Nv,{label:r?`Hide ${t}`:`Show ${t}`,"aria-pressed":r,disabled:e===void 0,onClick:()=>i(e=>!e),children:r?(0,h.jsx)(Wc,{"aria-hidden":`true`}):(0,h.jsx)(Gc,{"aria-hidden":`true`})})]})}var DB=[`studio`,`plan`];function OB({autoComment:e}){let{api:t}=B(),n=_(),r=Lv(),i=F({queryKey:DB,queryFn:()=>ls(t)}),a=F(kT(t)),o=I({mutationFn:e=>us(t,{...e,rows:[]}),onSuccess:e=>{n.setQueryData(DB,e),n.invalidateQueries({queryKey:[`studio`,`releases`]}),r(`Removed the old posting plan. Each schedule's release times apply now.`,`success`)},onError:e=>r(`The old posting plan wasn't removed: ${e.message} Try Remove the old plan again.`,`error`)}),s=I({mutationFn:e=>ds(t,e),onSuccess:e=>{n.setQueryData(DB,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`)}),c=I({mutationFn:e=>gs(t,e),onSuccess:()=>n.invalidateQueries({queryKey:[`studio`,`settings`]}),onError:e=>r(`Not saved: ${e.message}`,`error`)});if(i.data===void 0)return(0,h.jsxs)(`section`,{"aria-label":`Release times`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{as:`h3`,title:`Release times`}),i.error===null?(0,h.jsx)(jL,{label:`Loading the release settings…`,rows:2,rowClassName:`h-10`}):(0,h.jsx)(ML,{what:`The release settings`,error:i.error,onRetry:()=>void i.refetch(),retrying:i.isFetching})]});let l=i.data.plan,u=(a.data??[]).filter(e=>e.deletedAt===null);return(0,h.jsxs)(`section`,{"aria-label":`Release times`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{as:`h3`,title:`Release times`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Each schedule sets when its videos and shorts go out, one line for each day it runs, with a time for every short its template makes:`,` `,(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`schedules`},children:`Calendar → Schedules`}),` `,`→ Edit → Release times. See and move them in Calendar → Releases.`]}),u.length===0?null:(0,h.jsx)(`p`,{className:`m-0 flex flex-wrap gap-x-3 gap-y-1 text-small`,children:u.map(e=>(0,h.jsx)(KO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name},e.id))}),l.rows.length>0?(0,h.jsx)(fM,{tone:`info`,title:`An older posting plan still applies`,actions:(0,h.jsx)(z,{variant:`secondary`,disabled:o.isPending,onClick:()=>o.mutate(l),children:`Remove the old plan`}),children:(0,h.jsx)(`p`,{className:`m-0`,children:`It has ${String(l.rows.length)} line${l.rows.length===1?``:`s`}, and gives release times to projects no schedule made, and to a schedule's projects when its own times are taken. Set release times in your schedules, then remove it. Times already given keep.`})}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[`Upload and schedule each video and short at least`,(0,h.jsx)(X,{"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&&s.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)(Fy,{checked:e===!0,disabled:c.isPending||e===void 0,onChange:e=>c.mutate(e),label:`Post and pin each video's comment once it is public (the extension posts it in your name)`})]})}var kB=[`studio`,`settings`];function AB(){let{api:e}=B(),t=F({queryKey:kB,queryFn:()=>as(e)});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(U,{title:`Upload pack and extension`,info:`settings.studio.extension`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(MB,{}),(0,h.jsx)(OB,{autoComment:t.data?.autoComment??!1}),(0,h.jsx)(FB,{}),(0,h.jsxs)(`section`,{"aria-label":`Install the Studio extension`,children:[(0,h.jsx)(U,{as:`h3`,title:`Install the Studio extension`,className:`mb-3`}),(0,h.jsx)(CB,{})]})]})]})}var jB=``;function MB(){let{api:e}=B(),t=_(),n=Lv(),r=(0,m.useId)(),i=F({queryKey:kB,queryFn:()=>as(e)}),a=F(Xy(e)),o=(0,m.useId)(),[s,c]=(0,m.useState)(jB),[l,u]=(0,m.useState)({}),d=l[s],f=e=>{u(t=>{let{[s]:n,...r}=t;return e===void 0?r:{...r,[s]:e}})},p=i.data?.playlists??[],g=s===jB?void 0:i.data?.channelPlaylists[s],v=d??(s===jB?p:g??[]),y=PB(v),b=I({mutationFn:t=>os(e,t,s===jB?void 0:s),onSuccess:()=>{f(void 0),t.invalidateQueries({queryKey:kB}),n(`Playlists saved.`,`success`)}}),x=e=>{b.reset(),f(e)},S=y??b.error?.message,C=[{value:jB,label:`Every channel (default)`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(aL,{label:`Playlists`,tip:`settings.studio.playlist`,help:s===jB?`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.`:g===void 0&&p.length>0?`This channel uses the default list (${(e=>e.map(e=>e.name).join(`, `))(p)}) 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)(`form`,{className:`flex flex-col gap-2`,onSubmit:e=>{e.preventDefault(),!b.isPending&&d!==void 0&&y===void 0&&b.mutate(v)},children:[(0,h.jsx)(cL,{id:o,"aria-label":`Channel`,value:s,options:C,onChange:e=>{b.reset(),c(e.currentTarget.value)},className:`max-w-[260px]`}),v.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Type each name exactly as the playlist is called in YouTube Studio.`}),v.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(X,{autoComplete:`off`,"aria-label":`Playlist ${String(t+1)} name`,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":S===void 0?void 0:r,onChange:e=>x(v.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;x(v.map((e,r)=>r===t?{...e,byDefault:n}:e))}}),`On by default`]}),(0,h.jsx)(cL,{"aria-label":`${e.name.trim()||`Playlist ${String(t+1)}`}: takes`,className:`w-[190px]`,value:e.for??`all`,onChange:e=>{let n=e.currentTarget.value,r=n===`long`||n===`shorts`?n:`all`;x(v.map((e,n)=>n===t?{...e,for:r}:e))},options:[{value:`all`,label:`Videos and shorts`},{value:`long`,label:`Long videos only`},{value:`shorts`,label:`Shorts only`}]}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name.trim()||`playlist ${String(t+1)}`}`,onClick:()=>x(v.filter((e,n)=>n!==t)),children:`Remove`})]},t)),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(z,{variant:`secondary`,disabled:i.data===void 0||v.length>=20,onClick:()=>x([...v,{name:``,byDefault:v.length===0}]),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,strokeWidth:1.75}),`Add playlist`]}),(0,h.jsx)(z,{type:`submit`,variant:`primary`,disabled:b.isPending||d===void 0||y!==void 0,disabledReason:y??`Nothing changed since the last save.`,children:`Save playlists`})]}),NB(v)===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:NB(v)}),(0,h.jsx)(wB,{dirty:d!==void 0,saveLabel:`Save playlists`,onDiscard:()=>{b.reset(),f(void 0)}})]}),S===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:S})]})}function NB(e){let t=e.find(e=>/\bshorts?\b/i.test(e.name)&&(e.for??`all`)===`all`);if(t!==void 0)return`"${t.name.trim()}" takes long videos too, and shorts also go into every playlist set to Videos and shorts. Set it to Shorts only, and your long-video playlists to Long videos only.`}function PB(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 FB(){let{api:e}=B(),t=_(),n=Lv(),r=F({queryKey:kB,queryFn:()=>as(e)}),i=I({mutationFn:()=>ws(e),onSuccess:()=>{t.invalidateQueries({queryKey:kB}),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)(H,{id:`settings.studio.pairing`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(EB,{value:a?.token,revealLabel:`pairing token`,className:`flex-1 basis-[220px]`}),(0,h.jsxs)(z,{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)(Bc,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}),`Copy`]}),(0,h.jsx)(z,{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 IB=[`studio`,`queue`];function LB({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)(z,{variant:n,size:r,disabled:!t,disabledReason:`Available once the video has been made`,onClick:()=>a(!0),children:`Prepare upload`}),i?(0,h.jsx)(VB,{projectId:e,onClose:()=>a(!1)}):null]})}var RB={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 zB(e){return new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`}).format(new Date(e))}function BB(e){return e.kind===`video`?`video`:`short-${String(e.short)}`}function VB({projectId:e,onClose:t}){let{api:n}=B(),r=_(),i=[`studio`,`pack`,e],a=F({queryKey:i,queryFn:()=>Ts(n,e)}),[o,s]=(0,m.useState)(`video`),[c,l]=(0,m.useState)(),u=a.data?.items??[],d=u.find(e=>BB(e)===o)??u[0],f=F({queryKey:kB,queryFn:()=>as(n)}),p=f.data===void 0?void 0:f.data.pairing.origin!==null,g=F({queryKey:IB,queryFn:()=>Ss(n)}),v=I({mutationFn:t=>Ds(n,e,t.short),onSuccess:e=>{r.setQueryData(IB,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=I({mutationFn:e=>Cs(n,e.projectId,e.short),onSuccess:e=>r.setQueryData(IB,e),onError:e=>l({text:`Couldn't remove it from Waiting for Studio: ${e.message} Press Remove again.`,tone:`error`})}),b=I({mutationFn:t=>Es(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=I({mutationFn:t=>ss(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=I({mutationFn:t=>_s(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=I({mutationFn:t=>cs(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)(eM,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(CR,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(qO,{href:fR,target:`_blank`,rel:`noopener noreferrer`,variant:`secondary`,children:`Open YouTube Studio`}):null,(0,h.jsx)(z,{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(fR,`_blank`,`noopener`),v.mutate(d))},children:`Fill in YouTube Studio`}),(0,h.jsx)(H,{id:`project.upload.fill-studio`})]}),children:[a.error===null?null:(0,h.jsx)(fM,{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)(fM,{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)(CB,{})]})}):null,u.length>1?(0,h.jsx)(Iy,{label:`What to upload`,value:d===void 0?``:BB(d),onChange:s,tip:`project.upload.item`,options:u.map(e=>({value:BB(e),label:e.kind===`video`?`Video`:`Short ${String(e.short)}`})),className:`self-start`}):null,a.data.missing.length===0?null:(0,h.jsx)(fM,{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)(WB,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(Fy,{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`,...Py,children:[(0,h.jsx)(cL,{"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:zB(a.data.schedule.longAt)}],...(a.data.slotChoices??[]).map(e=>({value:`${e.row}|${e.longAt}`,label:zB(e.longAt)}))]}),(0,h.jsx)(H,{id:`project.upload.slot`})]}):void 0,picking:C.isPending,doneKey:`slopify.upload.${e}.${BB(d)}`},BB(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)(H,{id:`project.upload.queue`,className:`-my-1`})]}),(0,h.jsx)(qL,{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)(JL,{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)(z,{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)(fM,{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 HB(e){try{let t=JSON.parse(localStorage.getItem(e)??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function UB({href:e,filename:t}){return(0,h.jsxs)(qO,{href:e,download:t,"aria-label":`Download ${t}`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download`]})}function WB({projectId:e,item:t,footageSwitch:n,playlistPicker:r,copy:i,onPick:a,picking:o,slotPicker:s,doneKey:c}){let{api:l}=B(),[u,d]=(0,m.useState)(()=>HB(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=pR.filter(e=>e!==`thumbnails`||t.kind===`video`),y=v.filter(e=>u.includes(e)).length,b=e=>{let n=KB(t,e);return(0,h.jsxs)(z,{variant:`quiet`,size:`small`,disabled:n===``,disabledReason:`Nothing to copy yet`,"aria-label":`Copy ${RB[e].toLowerCase()}`,onClick:()=>i(n,RB[e].toLowerCase()),children:[(0,h.jsx)(Bc,{"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)(UB,{href:`${l.origin}${t.video.url}`,filename:t.video.filename}),(0,h.jsx)(vB,{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?`${GB(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)(vB,{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?KB(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:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:KB(t,c)}),(0,h.jsx)(qB,{title:t.title})]}),actions:b(c)}:{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(qB,{title:t.title}),(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)(z,{variant:`quiet`,size:`small`,"aria-label":`Copy the other titles`,onClick:()=>i(t.titles.join(`
161
161
  `),`other titles`),children:[(0,h.jsx)(Bc,{"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.`:`${zB(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:KB(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)(H,{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)(qL,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:v.map(e=>{let{value:t,actions:n}=x(e);return(0,h.jsx)(JL,{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":`${RB[e]} done`}),title:RB[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)(U,{as:`h3`,kicker:`Thumbnails · A/B Testing`,title:`${String(t.thumbnails.length)} ${t.thumbnails.length===1?`thumbnail`:`thumbnails`}`,className:`mb-3`}),(0,h.jsx)(rz,{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)(nz,{src:`${l.origin}${e.url}`,alt:`Thumbnail ${GB(n)}`,title:r&&t.thumbnails.length>1?`${GB(n)} · upload`:GB(n),meta:e.filename,onOpen:()=>p(n),openLabel:`Open thumbnail ${GB(n)} full size`,actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[r||t.pickable===void 0?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,disabled:o,onClick:()=>a({title:t.pickable?.title??0,thumbnail:n}),children:`Use for upload`}),(0,h.jsx)(UB,{href:`${l.origin}${e.url}`,filename:e.filename})]})},e.asset)})}),(0,h.jsx)(iz,{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)(UB,{href:`${l.origin}${r.url}`,filename:r.filename})}})]})]})}function GB(e){return String.fromCharCode(65+e)}function KB(e,t){switch(t){case`title`:return e.title;case`description`:return e.description;case`tags`:return mR(e.tags);case`playlist`:return e.playlists.join(`, `);default:return``}}function qB({title:e}){let t=yR(e);return t===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-danger`,children:`${t} Change it in the project's YouTube section (Video), then open Prepare upload again.`})}var JB=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),YB=new Intl.DateTimeFormat(void 0,{timeStyle:`short`}),XB=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`});function ZB({project:e}){let t=WL(e);return(0,h.jsx)(JL,{title:(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(tk,{tone:t.tone,children:t.word}),t.action===void 0?null:t.action.kind===`upload`?(0,h.jsx)(LB,{projectId:e.id,ready:!0}):(0,h.jsx)(GO,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function QB({days:e,busy:t,schedules:n,onStep:r,onMove:i,onTransfer:a}){let o=[...e.values()].sort((e,t)=>e.key.localeCompare(t.key));if(o.length===0)return(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Nothing is planned in these weeks. Add topics with Add to calendar, or create a schedule on the`,` `,(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`schedules`},children:`Schedules`}),` `,`tab.`]});let s=o.flatMap(e=>e.runs),c=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,...Py,children:[(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Move a topic earlier, later, to another day or to another schedule from its row.`,(0,h.jsx)(H,{id:`planning.calendar.move`,className:`-my-1`})]}),o.map(e=>(0,h.jsxs)(`section`,{"aria-label":JB.format(e.date),children:[(0,h.jsx)(U,{title:JB.format(e.date),as:`h3`}),(0,h.jsxs)(qL,{label:`Planned on ${JB.format(e.date)}`,children:[e.runs.map(e=>{let n=iR(e),o=c.filter(t=>t.id!==e.scheduleId),l=s.filter(t=>t.scheduleId===e.scheduleId&&t.index!==null&&t.index!==e.index);return(0,h.jsx)(JL,{title:n,meta:(0,h.jsxs)(h.Fragment,{children:[YB.format(new Date(e.at)),` ·`,` `,(0,h.jsx)(KO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.scheduleId},children:e.scheduleName}),e.templateName===null?null:(0,h.jsxs)(h.Fragment,{children:[` · `,(0,h.jsx)(KO,{to:`/templates`,search:{item:e.templateId},children:e.templateName})]}),e.paused?` · Paused`:``]}),actions:e.index===null?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(dR,{run:e}),(0,h.jsx)(Nv,{size:`small`,label:`Move ${n} earlier`,disabled:t,onClick:()=>r(e,-1),children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{size:`small`,label:`Move ${n} later`,disabled:t,onClick:()=>r(e,1),children:(0,h.jsx)(bc,{"aria-hidden":`true`,strokeWidth:1.75})}),o.length===0&&l.length===0?null:(0,h.jsx)($B,{title:n,busy:t,days:l,schedules:o,onDay:t=>i(e,t),onSchedule:t=>a(e,t)})]})},`${e.scheduleId}-${e.at}`)}),e.projects.map(e=>(0,h.jsx)(ZB,{project:e},e.id))]})]},e.key))]})}function $B({title:e,busy:t,days:n,schedules:r,onDay:i,onSchedule:a}){let[o,s]=(0,m.useState)(``);return(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`select`,{"aria-label":`Move ${e} to…`,className:`sl-select h-8 w-auto text-small`,value:o,disabled:t,onChange:e=>s(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Move to…`}),n.length===0?null:(0,h.jsx)(`optgroup`,{label:`Another day`,children:n.map(e=>(0,h.jsx)(`option`,{value:`day:${String(e.index)}`,children:XB.format(new Date(e.at))},e.at))}),r.length===0?null:(0,h.jsx)(`optgroup`,{label:`End of another schedule`,children:r.map(e=>(0,h.jsx)(`option`,{value:`schedule:${e.id}`,children:e.name},e.id))})]}),(0,h.jsx)(z,{size:`small`,variant:`secondary`,disabled:t||o===``,onClick:()=>{let[e,t]=o.split(`:`),r=n.find(e=>String(e.index)===t);e===`day`&&r!==void 0&&i(r),e===`schedule`&&t!==void 0&&a(t),s(``)},children:`Move`})]})}var eV=Symbol.for(`yaml.alias`),tV=Symbol.for(`yaml.document`),nV=Symbol.for(`yaml.map`),rV=Symbol.for(`yaml.pair`),iV=Symbol.for(`yaml.scalar`),aV=Symbol.for(`yaml.seq`),oV=Symbol.for(`yaml.node.type`),sV=e=>!!e&&typeof e==`object`&&e[oV]===eV,cV=e=>!!e&&typeof e==`object`&&e[oV]===tV,lV=e=>!!e&&typeof e==`object`&&e[oV]===nV,uV=e=>!!e&&typeof e==`object`&&e[oV]===rV,dV=e=>!!e&&typeof e==`object`&&e[oV]===iV,fV=e=>!!e&&typeof e==`object`&&e[oV]===aV;function pV(e){if(e&&typeof e==`object`)switch(e[oV]){case nV:case aV:return!0}return!1}function mV(e){if(e&&typeof e==`object`)switch(e[oV]){case eV:case nV:case iV:case aV:return!0}return!1}var hV=e=>(dV(e)||pV(e))&&!!e.anchor,gV=Symbol(`break visit`),_V=Symbol(`skip children`),vV=Symbol(`remove node`);function yV(e,t){let n=xV(t);cV(e)?bV(null,e.contents,n,Object.freeze([e]))===vV&&(e.contents=null):bV(null,e,n,Object.freeze([]))}yV.BREAK=gV,yV.SKIP=_V,yV.REMOVE=vV;function bV(e,t,n,r){let i=SV(e,t,n,r);if(mV(i)||uV(i))return CV(e,r,i),bV(e,i,n,r);if(typeof i!=`symbol`){if(pV(t)){r=Object.freeze(r.concat(t));for(let e=0;e<t.items.length;++e){let i=bV(e,t.items[e],n,r);if(typeof i==`number`)e=i-1;else if(i===gV)return gV;else i===vV&&(t.items.splice(e,1),--e)}}else if(uV(t)){r=Object.freeze(r.concat(t));let e=bV(`key`,t.key,n,r);if(e===gV)return gV;e===vV&&(t.key=null);let i=bV(`value`,t.value,n,r);if(i===gV)return gV;i===vV&&(t.value=null)}}return i}function xV(e){return typeof e==`object`&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function SV(e,t,n,r){if(typeof n==`function`)return n(e,t,r);if(lV(t))return n.Map?.(e,t,r);if(fV(t))return n.Seq?.(e,t,r);if(uV(t))return n.Pair?.(e,t,r);if(dV(t))return n.Scalar?.(e,t,r);if(sV(t))return n.Alias?.(e,t,r)}function CV(e,t,n){let r=t[t.length-1];if(pV(r))r.items[e]=n;else if(uV(r))e===`key`?r.key=n:r.value=n;else if(cV(r))r.contents=n;else{let e=sV(r)?`alias`:`scalar`;throw Error(`Cannot replace node with ${e} parent`)}}var wV={"!":`%21`,",":`%2C`,"[":`%5B`,"]":`%5D`,"{":`%7B`,"}":`%7D`},TV=e=>e.replace(/[!,[\]{}]/g,e=>wV[e]),EV=class e{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},e.defaultYaml,t),this.tags=Object.assign({},e.defaultTags,n)}clone(){let t=new e(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){let t=new e(this.yaml,this.tags);switch(this.yaml.version){case`1.1`:this.atNextDocument=!0;break;case`1.2`:this.atNextDocument=!1,this.yaml={explicit:e.defaultYaml.explicit,version:`1.2`},this.tags=Object.assign({},e.defaultTags)}return t}add(t,n){this.atNextDocument&&=(this.yaml={explicit:e.defaultYaml.explicit,version:`1.1`},this.tags=Object.assign({},e.defaultTags),!1);let r=t.trim().split(/[ \t]+/),i=r.shift();switch(i){case`%TAG`:{if(r.length!==2&&(n(0,`%TAG directive should contain exactly two parts`),r.length<2))return!1;let[e,t]=r;return this.tags[e]=t,!0}case`%YAML`:{if(this.yaml.explicit=!0,r.length!==1)return n(0,`%YAML directive should contain exactly one part`),!1;let[e]=r;if(e===`1.1`||e===`1.2`)return this.yaml.version=e,!0;{let t=/^\d+\.\d+$/.test(e);return n(6,`Unsupported YAML version ${e}`,t),!1}}default:return n(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e===`!`)return`!`;if(e[0]!==`!`)return t(`Not a valid tag: ${e}`),null;if(e[1]===`<`){let n=e.slice(2,-1);return n===`!`||n===`!!`?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==`>`&&t(`Verbatim tags must end with a >`),n)}let[,n,r]=e.match(/^(.*!)([^!]*)$/s);r||t(`The ${e} tag has no suffix`);let i=this.tags[n];if(i)try{return i+decodeURIComponent(r)}catch(e){return t(String(e)),null}return n===`!`?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+TV(e.substring(n.length));return e[0]===`!`?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||`1.2`}`]:[],n=Object.entries(this.tags),r;if(e&&n.length>0&&mV(e.contents)){let t={};yV(e.contents,(e,n)=>{mV(n)&&n.tag&&(t[n.tag]=!0)}),r=Object.keys(t)}else r=[];for(let[i,a]of n)(i!==`!!`||a!==`tag:yaml.org,2002:`)&&(!e||r.some(e=>e.startsWith(a)))&&t.push(`%TAG ${i} ${a}`);return t.join(`
162
162
  `)}};EV.defaultYaml={explicit:!1,version:`1.2`},EV.defaultTags={"!!":`tag:yaml.org,2002:`};function DV(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw Error(t)}return!0}function OV(e){let t=new Set;return yV(e,{Value(e,n){n.anchor&&t.add(n.anchor)}}),t}function kV(e,t){for(let n=1;;++n){let r=`${e}${n}`;if(!t.has(r))return r}}function AV(e,t){let n=[],r=new Map,i=null;return{onAnchor:r=>{n.push(r),i??=OV(e);let a=kV(t,i);return i.add(a),a},setAnchors:()=>{for(let e of n){let t=r.get(e);if(typeof t==`object`&&t.anchor&&(dV(t.node)||pV(t.node)))t.node.anchor=t.anchor;else{let t=Error(`Failed to resolve repeated object (this should not happen)`);throw t.source=e,t}}},sourceObjects:r}}function jV(e,t,n,r){if(r&&typeof r==`object`){if(Array.isArray(r))for(let t=0,n=r.length;t<n;++t){let n=r[t],i=jV(e,r,String(t),n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}else if(r instanceof Map)for(let t of Array.from(r.keys())){let n=r.get(t),i=jV(e,r,t,n);i===void 0?r.delete(t):i!==n&&r.set(t,i)}else if(r instanceof Set)for(let t of Array.from(r)){let n=jV(e,r,t,t);n===void 0?r.delete(t):n!==t&&(r.delete(t),r.add(n))}else for(let[t,n]of Object.entries(r)){let i=jV(e,r,t,n);i===void 0?delete r[t]:i!==n&&(r[t]=i)}}return e.call(t,n,r)}function MV(e,t,n){if(Array.isArray(e))return e.map((e,t)=>MV(e,String(t),n));if(e&&typeof e.toJSON==`function`){if(!n||!hV(e))return e.toJSON(t,n);let r={aliasCount:0,count:1,res:void 0};n.anchors.set(e,r),n.onCreate=e=>{r.res=e,delete n.onCreate};let i=e.toJSON(t,n);return n.onCreate&&n.onCreate(i),i}return typeof e==`bigint`&&!n?.keep?Number(e):e}var NV=class{constructor(e){Object.defineProperty(this,oV,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:r,reviver:i}={}){if(!cV(e))throw TypeError(`A document argument is required`);let a={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n==`number`?n:100},o=MV(this,``,a);if(typeof r==`function`)for(let{count:e,res:t}of a.anchors.values())r(t,e);return typeof i==`function`?jV(i,{"":o},``,o):o}},PV=class extends NV{constructor(e){super(eV),this.source=e,Object.defineProperty(this,"tag",{set(){throw Error(`Alias nodes cannot have tags`)}})}resolve(e,t){if(t?.maxAliasCount===0)throw ReferenceError(`Alias resolution is disabled`);let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],yV(e,{Node:(e,t)=>{(sV(t)||hV(t))&&n.push(t)}}),t&&(t.aliasResolveCache=n));let r;for(let e of n){if(e===this)break;e.anchor===this.source&&(r=e)}if(r&&t){let{anchors:e,doc:n,maxAliasCount:i}=t,a=e.get(r);if(a||=(MV(r,null,t),e.get(r)),a?.res===void 0)throw ReferenceError(`This should not happen: Alias anchor was not resolved?`);if(i>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=FV(n,r,e)),a.count*a.aliasCount>i))throw ReferenceError(`Excessive alias count indicates a resource exhaustion attack`)}return r}toJSON(e,t){if(!t)return{source:this.source};let n=this.resolve(t.doc,t);if(!n){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw ReferenceError(e)}return t.anchors.get(n).res}toString(e,t,n){let r=`*${this.source}`;if(e){if(DV(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let e=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw Error(e)}if(e.implicitKey)return`${r} `}return r}};function FV(e,t,n){if(sV(t)){let r=t.resolve(e),i=n&&r&&n.get(r);return i?i.count*i.aliasCount:0}if(pV(t)){let r=0;for(let i of t.items){let t=FV(e,i,n);t>r&&(r=t)}return r}if(uV(t)){let r=FV(e,t.key,n),i=FV(e,t.value,n);return Math.max(r,i)}return 1}var IV=e=>!e||typeof e!=`function`&&typeof e!=`object`,LV=class extends NV{constructor(e){super(iV),this.value=e}toJSON(e,t){return t?.keep?this.value:MV(this.value,e,t)}toString(){return String(this.value)}};LV.BLOCK_FOLDED=`BLOCK_FOLDED`,LV.BLOCK_LITERAL=`BLOCK_LITERAL`,LV.PLAIN=`PLAIN`,LV.QUOTE_DOUBLE=`QUOTE_DOUBLE`,LV.QUOTE_SINGLE=`QUOTE_SINGLE`;var RV=`tag:yaml.org,2002:`;function zV(e,t,n){if(t){let e=n.filter(e=>e.tag===t),r=e.find(e=>!e.format)??e[0];if(!r)throw Error(`Tag ${t} not found`);return r}return n.find(t=>t.identify?.(e)&&!t.format)}function BV(e,t,n){if(cV(e)&&(e=e.contents),mV(e))return e;if(uV(e)){let t=n.schema[nV].createNode?.(n.schema,null,n);return t.items.push(e),t}(e instanceof String||e instanceof Number||e instanceof Boolean||typeof BigInt<`u`&&e instanceof BigInt)&&(e=e.valueOf());let{aliasDuplicateObjects:r,onAnchor:i,onTagObj:a,schema:o,sourceObjects:s}=n,c;if(r&&e&&typeof e==`object`){if(c=s.get(e),c)return c.anchor??(c.anchor=i(e)),new PV(c.anchor);c={anchor:null,node:null},s.set(e,c)}t?.startsWith(`!!`)&&(t=RV+t.slice(2));let l=zV(e,t,o.tags);if(!l){if(e&&typeof e.toJSON==`function`&&(e=e.toJSON()),!e||typeof e!=`object`){let t=new LV(e);return c&&(c.node=t),t}l=e instanceof Map?o[nV]:Symbol.iterator in Object(e)?o[aV]:o[nV]}a&&(a(l),delete n.onTagObj);let u=l?.createNode?l.createNode(n.schema,e,n):typeof l?.nodeClass?.from==`function`?l.nodeClass.from(n.schema,e,n):new LV(e);return t?u.tag=t:l.default||(u.tag=l.tag),c&&(c.node=u),u}function VV(e,t,n){let r=n;for(let e=t.length-1;e>=0;--e){let n=t[e];if(typeof n==`number`&&Number.isInteger(n)&&n>=0){let e=[];e[n]=r,r=e}else r=new Map([[n,r]])}return BV(r,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw Error(`This should not happen, please report a bug.`)},schema:e,sourceObjects:new Map})}var HV=e=>e==null||typeof e==`object`&&!!e[Symbol.iterator]().next().done,UV=class extends NV{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(t=>mV(t)||uV(t)?t.clone(e):t),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(HV(e))this.add(t);else{let[n,...r]=e,i=this.get(n,!0);if(pV(i))i.addIn(r,t);else if(i===void 0&&this.schema)this.set(n,VV(this.schema,r,t));else throw Error(`Expected YAML collection at ${n}. Remaining path: ${r}`)}}deleteIn(e){let[t,...n]=e;if(n.length===0)return this.delete(t);let r=this.get(t,!0);if(pV(r))return r.deleteIn(n);throw Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){let[n,...r]=e,i=this.get(n,!0);return r.length===0?!t&&dV(i)?i.value:i:pV(i)?i.getIn(r,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!uV(t))return!1;let n=t.value;return n==null||e&&dV(n)&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn(e){let[t,...n]=e;if(n.length===0)return this.has(t);let r=this.get(t,!0);return pV(r)?r.hasIn(n):!1}setIn(e,t){let[n,...r]=e;if(r.length===0)this.set(n,t);else{let e=this.get(n,!0);if(pV(e))e.setIn(r,t);else if(e===void 0&&this.schema)this.set(n,VV(this.schema,r,t));else throw Error(`Expected YAML collection at ${n}. Remaining path: ${r}`)}}},WV=e=>e.replace(/^(?!$)(?: $)?/gm,`#`);function GV(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}var KV=(e,t,n)=>e.endsWith(`
163
163
  `)?GV(n,t):n.includes(`
@@ -271,7 +271,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
271
271
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _(e,t){if(t&&(typeof t==`object`||typeof t==`function`))return t;if(t!==void 0)throw TypeError(`Derived constructors may only return object or undefined`);return i(e)}function v(e,t){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},v(e,t)}function y(e,t){return r(e)||h(e,t)||C(e,t)||g()}function b(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function x(e){var t=b(e,`string`);return typeof t==`symbol`?t:t+``}function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function C(e,t){if(e){if(typeof e==`string`)return n(e,t);var r={}.toString.call(e).slice(8,-1);return r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`?Array.from(e):r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function w(e){var t=typeof Map==`function`?new Map:void 0;return w=function(e){function n(){return s(e,arguments,d(this).constructor)}if(e===null||!p(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,n)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),v(n,e)},w(e)}var T=function(e){var t=Math.abs,n=Math.max,r=Math.floor;function i(e,t){var n;if(o(this,i),n=a(this,i,[e]),n.sign=t,Object.setPrototypeOf(n,i.prototype),e>i.__kMaxLength)throw RangeError(`Maximum BigInt size exceeded`);return n}return f(i,e),l(i,[{key:`toDebugString`,value:function(){var e,t=[`BigInt[`],n=u(this);try{for(n.s();!(e=n.n()).done;){var r=e.value;t.push((r&&(r>>>0).toString(16))+`, `)}}catch(e){n.e(e)}finally{n.f()}return t.push(`]`),t.join(``)}},{key:`toString`,value:function(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:10;if(2>e||36<e)throw RangeError(`toString() radix argument must be between 2 and 36`);return this.length===0?`0`:e&e-1?i.__toStringGeneric(this,e,!1):i.__toStringBasePowerOfTwo(this,e)}},{key:`valueOf`,value:function(){throw Error("Convert JSBI instances to native numbers using `toNumber`.")}},{key:`__copy`,value:function(){for(var e=new i(this.length,this.sign),t=0;t<this.length;t++)e[t]=this[t];return e}},{key:`__trim`,value:function(){for(var e=this.length,t=this[e-1];t===0;)e--,t=this[e-1],this.pop();return e===0&&(this.sign=!1),this}},{key:`__initializeDigits`,value:function(){for(var e=0;e<this.length;e++)this[e]=0}},{key:`__clzmsd`,value:function(){return i.__clz30(this.__digit(this.length-1))}},{key:`__inplaceMultiplyAdd`,value:function(e,t,n){n>this.length&&(n=this.length);for(var r=32767&e,a=e>>>15,o=0,s=t,c=0;c<n;c++){var l=this.__digit(c),u=32767&l,d=l>>>15,f=i.__imul(u,r),p=i.__imul(u,a),m=i.__imul(d,r),h=i.__imul(d,a),g=s+f+o;o=g>>>30,g&=1073741823,g+=((32767&p)<<15)+((32767&m)<<15),o+=g>>>30,s=h+(p>>>15)+(m>>>15),this.__setDigit(c,1073741823&g)}if(o!==0||s!==0)throw Error(`implementation bug`)}},{key:`__inplaceAdd`,value:function(e,t,n){for(var r,i=0,a=0;a<n;a++)r=this.__halfDigit(t+a)+e.__halfDigit(a)+i,i=r>>>15,this.__setHalfDigit(t+a,32767&r);return i}},{key:`__inplaceSub`,value:function(e,t,n){var r=n-1>>>1,i=0;if(1&t){t>>=1;for(var a=this.__digit(t),o=32767&a,s=0;s<r;s++){var c=e.__digit(s),l=(a>>>15)-(32767&c)-i;i=1&l>>>15,this.__setDigit(t+s,(32767&l)<<15|32767&o),a=this.__digit(t+s+1),o=(32767&a)-(c>>>15)-i,i=1&o>>>15}var u=e.__digit(s),d=(a>>>15)-(32767&u)-i;i=1&d>>>15,this.__setDigit(t+s,(32767&d)<<15|32767&o);var f=u>>>15;if(t+s+1>=this.length)throw RangeError(`out of bounds`);!(1&n)&&(a=this.__digit(t+s+1),o=(32767&a)-f-i,i=1&o>>>15,this.__setDigit(t+e.length,1073709056&a|32767&o))}else{t>>=1;for(var p=0;p<e.length-1;p++){var m=this.__digit(t+p),h=e.__digit(p),g=(32767&m)-(32767&h)-i;i=1&g>>>15;var _=(m>>>15)-(h>>>15)-i;i=1&_>>>15,this.__setDigit(t+p,(32767&_)<<15|32767&g)}var v=this.__digit(t+p),y=e.__digit(p),b=(32767&v)-(32767&y)-i;i=1&b>>>15;var x=0;!(1&n)&&(x=(v>>>15)-(y>>>15)-i,i=1&x>>>15),this.__setDigit(t+p,(32767&x)<<15|32767&b)}return i}},{key:`__inplaceRightShift`,value:function(e){if(e!==0){for(var t,n=this.__digit(0)>>>e,r=this.length-1,i=0;i<r;i++)t=this.__digit(i+1),this.__setDigit(i,1073741823&t<<30-e|n),n=t>>>e;this.__setDigit(r,n)}}},{key:`__digit`,value:function(e){return this[e]}},{key:`__unsignedDigit`,value:function(e){return this[e]>>>0}},{key:`__setDigit`,value:function(e,t){this[e]=0|t}},{key:`__setDigitGrow`,value:function(e,t){this[e]=0|t}},{key:`__halfDigitLength`,value:function(){var e=this.length;return 32767>=this.__unsignedDigit(e-1)?2*e-1:2*e}},{key:`__halfDigit`,value:function(e){return 32767&this[e>>>1]>>>15*(1&e)}},{key:`__setHalfDigit`,value:function(e,t){var n=e>>>1,r=this.__digit(n),i=1&e?32767&r|t<<15:1073709056&r|32767&t;this.__setDigit(n,i)}}],[{key:`BigInt`,value:function(e){var t=Number.isFinite;if(typeof e==`number`){if(e===0)return i.__zero();if(i.__isOneDigitInt(e))return 0>e?i.__oneDigit(-e,!0):i.__oneDigit(e,!1);if(!t(e)||r(e)!==e)throw RangeError(`The number `+e+` cannot be converted to BigInt because it is not an integer`);return i.__fromDouble(e)}if(typeof e==`string`){var n=i.__fromString(e);if(n===null)throw SyntaxError(`Cannot convert `+e+` to a BigInt`);return n}if(typeof e==`boolean`)return!0===e?i.__oneDigit(1,!1):i.__zero();if(S(e)===`object`){if(e.constructor===i)return e;var a=i.__toPrimitive(e);return i.BigInt(a)}throw TypeError(`Cannot convert `+e+` to a BigInt`)}},{key:`toNumber`,value:function(e){var t=e.length;if(t===0)return 0;if(t===1){var n=e.__unsignedDigit(0);return e.sign?-n:n}var r=e.__digit(t-1),a=i.__clz30(r),o=30*t-a;if(1024<o)return e.sign?-1/0:1/0;var s=o-1,c=r,l=t-1,u=a+3,d=u===32?0:c<<u;d>>>=12;var f=u-12,p=12<=u?0:c<<20+u,m=20+u;for(0<f&&0<l&&(l--,c=e.__digit(l),d|=c>>>30-f,p=c<<f+2,m=f+2);0<m&&0<l;)l--,c=e.__digit(l),p|=30<=m?c<<m-30:c>>>30-m,m-=30;var h=i.__decideRounding(e,m,l,c);if((h===1||h===0&&(1&p)==1)&&(p=p+1>>>0,p===0&&(d++,d>>>20&&(d=0,s++,1023<s))))return e.sign?-1/0:1/0;var g=e.sign?-2147483648:0;return s=s+1023<<20,i.__kBitConversionInts[i.__kBitConversionIntHigh]=g|s|d,i.__kBitConversionInts[i.__kBitConversionIntLow]=p,i.__kBitConversionDouble[0]}},{key:`unaryMinus`,value:function(e){if(e.length===0)return e;var t=e.__copy();return t.sign=!e.sign,t}},{key:`bitwiseNot`,value:function(e){return e.sign?i.__absoluteSubOne(e).__trim():i.__absoluteAddOne(e,!0)}},{key:`exponentiate`,value:function(e,t){if(t.sign)throw RangeError(`Exponent must be positive`);if(t.length===0)return i.__oneDigit(1,!1);if(e.length===0)return e;if(e.length===1&&e.__digit(0)===1)return e.sign&&!(1&t.__digit(0))?i.unaryMinus(e):e;if(1<t.length)throw RangeError(`BigInt too big`);var n=t.__unsignedDigit(0);if(n===1)return e;if(n>=i.__kMaxLengthBits)throw RangeError(`BigInt too big`);if(e.length===1&&e.__digit(0)===2){var r=1+(0|n/30),a=new i(r,e.sign&&!!(1&n));a.__initializeDigits();var o=1<<n%30;return a.__setDigit(r-1,o),a}var s=null,c=e;for(1&n&&(s=e),n>>=1;n!==0;n>>=1)c=i.multiply(c,c),1&n&&(s=s===null?c:i.multiply(s,c));return s}},{key:`multiply`,value:function(e,t){if(e.length===0)return e;if(t.length===0)return t;var n=e.length+t.length;30<=e.__clzmsd()+t.__clzmsd()&&n--;var r=new i(n,e.sign!==t.sign);r.__initializeDigits();for(var a=0;a<e.length;a++)i.__multiplyAccumulate(t,e.__digit(a),r,a);return r.__trim()}},{key:`divide`,value:function(e,t){if(t.length===0)throw RangeError(`Division by zero`);if(0>i.__absoluteCompare(e,t))return i.__zero();var n,r=e.sign!==t.sign,a=t.__unsignedDigit(0);if(t.length===1&&32767>=a){if(a===1)return r===e.sign?e:i.unaryMinus(e);n=i.__absoluteDivSmall(e,a,null)}else n=i.__absoluteDivLarge(e,t,!0,!1);return n.sign=r,n.__trim()}},{key:`remainder`,value:function(e,t){if(t.length===0)throw RangeError(`Division by zero`);if(0>i.__absoluteCompare(e,t))return e;var n=t.__unsignedDigit(0);if(t.length===1&&32767>=n){if(n===1)return i.__zero();var r=i.__absoluteModSmall(e,n);return r===0?i.__zero():i.__oneDigit(r,e.sign)}var a=i.__absoluteDivLarge(e,t,!1,!0);return a.sign=e.sign,a.__trim()}},{key:`add`,value:function(e,t){var n=e.sign;return n===t.sign?i.__absoluteAdd(e,t,n):0<=i.__absoluteCompare(e,t)?i.__absoluteSub(e,t,n):i.__absoluteSub(t,e,!n)}},{key:`subtract`,value:function(e,t){var n=e.sign;return n===t.sign?0<=i.__absoluteCompare(e,t)?i.__absoluteSub(e,t,n):i.__absoluteSub(t,e,!n):i.__absoluteAdd(e,t,n)}},{key:`leftShift`,value:function(e,t){return t.length===0||e.length===0?e:t.sign?i.__rightShiftByAbsolute(e,t):i.__leftShiftByAbsolute(e,t)}},{key:`signedRightShift`,value:function(e,t){return t.length===0||e.length===0?e:t.sign?i.__leftShiftByAbsolute(e,t):i.__rightShiftByAbsolute(e,t)}},{key:`unsignedRightShift`,value:function(){throw TypeError(`BigInts have no unsigned right shift; use >> instead`)}},{key:`lessThan`,value:function(e,t){return 0>i.__compareToBigInt(e,t)}},{key:`lessThanOrEqual`,value:function(e,t){return 0>=i.__compareToBigInt(e,t)}},{key:`greaterThan`,value:function(e,t){return 0<i.__compareToBigInt(e,t)}},{key:`greaterThanOrEqual`,value:function(e,t){return 0<=i.__compareToBigInt(e,t)}},{key:`equal`,value:function(e,t){if(e.sign!==t.sign||e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e.__digit(n)!==t.__digit(n))return!1;return!0}},{key:`notEqual`,value:function(e,t){return!i.equal(e,t)}},{key:`bitwiseAnd`,value:function(e,t){if(!e.sign&&!t.sign)return i.__absoluteAnd(e,t).__trim();if(e.sign&&t.sign){var r=n(e.length,t.length)+1,a=i.__absoluteSubOne(e,r),o=i.__absoluteSubOne(t);return a=i.__absoluteOr(a,o,a),i.__absoluteAddOne(a,!0,a).__trim()}if(e.sign){var s=[t,e];e=s[0],t=s[1]}return i.__absoluteAndNot(e,i.__absoluteSubOne(t)).__trim()}},{key:`bitwiseXor`,value:function(e,t){if(!e.sign&&!t.sign)return i.__absoluteXor(e,t).__trim();if(e.sign&&t.sign){var r=n(e.length,t.length),a=i.__absoluteSubOne(e,r),o=i.__absoluteSubOne(t);return i.__absoluteXor(a,o,a).__trim()}var s=n(e.length,t.length)+1;if(e.sign){var c=[t,e];e=c[0],t=c[1]}var l=i.__absoluteSubOne(t,s);return l=i.__absoluteXor(l,e,l),i.__absoluteAddOne(l,!0,l).__trim()}},{key:`bitwiseOr`,value:function(e,t){var r=n(e.length,t.length);if(!e.sign&&!t.sign)return i.__absoluteOr(e,t).__trim();if(e.sign&&t.sign){var a=i.__absoluteSubOne(e,r),o=i.__absoluteSubOne(t);return a=i.__absoluteAnd(a,o,a),i.__absoluteAddOne(a,!0,a).__trim()}if(e.sign){var s=[t,e];e=s[0],t=s[1]}var c=i.__absoluteSubOne(t,r);return c=i.__absoluteAndNot(c,e,c),i.__absoluteAddOne(c,!0,c).__trim()}},{key:`asIntN`,value:function(e,t){if(t.length===0)return t;if(e=r(e),0>e)throw RangeError(`Invalid value: not (convertible to) a safe integer`);if(e===0)return i.__zero();if(e>=i.__kMaxLengthBits)return t;var n=0|(e+29)/30;if(t.length<n)return t;var a=t.__unsignedDigit(n-1),o=1<<(e-1)%30;if(t.length===n&&a<o)return t;if((a&o)!==o)return i.__truncateToNBits(e,t);if(!t.sign)return i.__truncateAndSubFromPowerOfTwo(e,t,!0);if(!(a&o-1)){for(var s=n-2;0<=s;s--)if(t.__digit(s)!==0)return i.__truncateAndSubFromPowerOfTwo(e,t,!1);return t.length===n&&a===o?t:i.__truncateToNBits(e,t)}return i.__truncateAndSubFromPowerOfTwo(e,t,!1)}},{key:`asUintN`,value:function(e,t){if(t.length===0)return t;if(e=r(e),0>e)throw RangeError(`Invalid value: not (convertible to) a safe integer`);if(e===0)return i.__zero();if(t.sign){if(e>i.__kMaxLengthBits)throw RangeError(`BigInt too big`);return i.__truncateAndSubFromPowerOfTwo(e,t,!1)}if(e>=i.__kMaxLengthBits)return t;var n=0|(e+29)/30;if(t.length<n)return t;var a=e%30;return t.length==n&&(a===0||!(t.__digit(n-1)>>>a))?t:i.__truncateToNBits(e,t)}},{key:`ADD`,value:function(e,t){if(e=i.__toPrimitive(e),t=i.__toPrimitive(t),typeof e==`string`)return typeof t!=`string`&&(t=t.toString()),e+t;if(typeof t==`string`)return e.toString()+t;if(e=i.__toNumeric(e),t=i.__toNumeric(t),i.__isBigInt(e)&&i.__isBigInt(t))return i.add(e,t);if(typeof e==`number`&&typeof t==`number`)return e+t;throw TypeError(`Cannot mix BigInt and other types, use explicit conversions`)}},{key:`LT`,value:function(e,t){return i.__compare(e,t,0)}},{key:`LE`,value:function(e,t){return i.__compare(e,t,1)}},{key:`GT`,value:function(e,t){return i.__compare(e,t,2)}},{key:`GE`,value:function(e,t){return i.__compare(e,t,3)}},{key:`EQ`,value:function(e,t){for(;;){if(i.__isBigInt(e))return i.__isBigInt(t)?i.equal(e,t):i.EQ(t,e);if(typeof e==`number`){if(i.__isBigInt(t))return i.__equalToNumber(t,e);if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(typeof e==`string`){if(i.__isBigInt(t))return e=i.__fromString(e),e!==null&&i.equal(e,t);if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(typeof e==`boolean`){if(i.__isBigInt(t))return i.__equalToNumber(t,+e);if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(S(e)===`symbol`){if(i.__isBigInt(t))return!1;if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(S(e)===`object`){if(S(t)===`object`&&t.constructor!==i)return e==t;e=i.__toPrimitive(e)}else return e==t}}},{key:`NE`,value:function(e,t){return!i.EQ(e,t)}},{key:`DataViewGetBigInt64`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0&&arguments[2];return i.asIntN(64,i.DataViewGetBigUint64(e,t,n))}},{key:`DataViewGetBigUint64`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0&&arguments[2],r=y(n?[4,0]:[0,4],2),a=r[0],o=r[1],s=e.getUint32(t+a,n),c=e.getUint32(t+o,n),l=new i(3,!1);return l.__setDigit(0,1073741823&c),l.__setDigit(1,(268435455&s)<<2|c>>>30),l.__setDigit(2,s>>>28),l.__trim()}},{key:`DataViewSetBigInt64`,value:function(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0&&arguments[3];i.DataViewSetBigUint64(e,t,n,r)}},{key:`DataViewSetBigUint64`,value:function(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0&&arguments[3];n=i.asUintN(64,n);var a=0,o=0;if(0<n.length&&(o=n.__digit(0),1<n.length)){var s=n.__digit(1);o|=s<<30,a=s>>>2,2<n.length&&(a|=n.__digit(2)<<28)}var c=y(r?[4,0]:[0,4],2),l=c[0],u=c[1];e.setUint32(t+l,a,r),e.setUint32(t+u,o,r)}},{key:`__zero`,value:function(){return new i(0,!1)}},{key:`__oneDigit`,value:function(e,t){var n=new i(1,t);return n.__setDigit(0,e),n}},{key:`__decideRounding`,value:function(e,t,n,r){if(0<t)return-1;var i;if(0>t)i=-t-1;else{if(n===0)return-1;n--,r=e.__digit(n),i=29}var a=1<<i;if((r&a)==0)return-1;if(--a,(r&a)!=0)return 1;for(;0<n;)if(n--,e.__digit(n)!==0)return 1;return 0}},{key:`__fromDouble`,value:function(e){var t=0>e;i.__kBitConversionDouble[0]=e;var n,r=(2047&i.__kBitConversionInts[i.__kBitConversionIntHigh]>>>20)-1023,a=(0|r/30)+1,o=new i(a,t),s=1048575&i.__kBitConversionInts[i.__kBitConversionIntHigh]|1048576,c=i.__kBitConversionInts[i.__kBitConversionIntLow],l=20,u=r%30,d=0;if(u<l){var f=l-u;d=f+32,n=s>>>f,s=s<<32-f|c>>>f,c<<=32-f}else if(u===l)d=32,n=s,s=c,c=0;else{var p=u-l;d=32-p,n=s<<p|c>>>32-p,s=c<<p,c=0}o.__setDigit(a-1,n);for(var m=a-2;0<=m;m--)0<d?(d-=30,n=s>>>2,s=s<<30|c>>>2,c<<=30):n=0,o.__setDigit(m,n);return o.__trim()}},{key:`__isWhitespace`,value:function(e){return 13>=e&&9<=e||(159>=e?e==32:131071>=e?e==160||e==5760:196607>=e?(e&=131071,10>=e||e==40||e==41||e==47||e==95||e==4096):e==65279)}},{key:`__fromString`,value:function(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0,n=0,r=e.length,a=0;if(a===r)return i.__zero();for(var o=e.charCodeAt(a);i.__isWhitespace(o);){if(++a===r)return i.__zero();o=e.charCodeAt(a)}if(o===43){if(++a===r)return null;o=e.charCodeAt(a),n=1}else if(o===45){if(++a===r)return null;o=e.charCodeAt(a),n=-1}if(t===0){if(t=10,o===48){if(++a===r)return i.__zero();if(o=e.charCodeAt(a),o===88||o===120){if(t=16,++a===r)return null;o=e.charCodeAt(a)}else if(o===79||o===111){if(t=8,++a===r)return null;o=e.charCodeAt(a)}else if(o===66||o===98){if(t=2,++a===r)return null;o=e.charCodeAt(a)}}}else if(t===16&&o===48){if(++a===r)return i.__zero();if(o=e.charCodeAt(a),o===88||o===120){if(++a===r)return null;o=e.charCodeAt(a)}}if(n!==0&&t!==10)return null;for(;o===48;){if(++a===r)return i.__zero();o=e.charCodeAt(a)}var s=r-a,c=i.__kMaxBitsPerChar[t],l=i.__kBitsPerCharTableMultiplier-1;if(s>1073741824/c)return null;var u=new i(0|((c*s+l>>>i.__kBitsPerCharTableShift)+29)/30,!1),d=10>t?t:10,f=10<t?t-10:0;if(t&t-1){u.__initializeDigits();var p=!1,m=0;do{for(var h,g=0,_=1;;){if(h=void 0,o-48>>>0<d)h=o-48;else if((32|o)-97>>>0<f)h=(32|o)-87;else{p=!0;break}var v=_*t;if(1073741823<v)break;if(_=v,g=g*t+h,m++,++a===r){p=!0;break}o=e.charCodeAt(a)}l=30*i.__kBitsPerCharTableMultiplier-1;var y=0|(c*m+l>>>i.__kBitsPerCharTableShift)/30;u.__inplaceMultiplyAdd(_,g,y)}while(!p)}else{c>>=i.__kBitsPerCharTableShift;var b=[],x=[],S=!1;do{for(var C,w=0,T=0;;){if(C=void 0,o-48>>>0<d)C=o-48;else if((32|o)-97>>>0<f)C=(32|o)-87;else{S=!0;break}if(T+=c,w=w<<c|C,++a===r){S=!0;break}if(o=e.charCodeAt(a),30<T+c)break}b.push(w),x.push(T)}while(!S);i.__fillFromParts(u,b,x)}if(a!==r){if(!i.__isWhitespace(o))return null;for(a++;a<r;a++)if(o=e.charCodeAt(a),!i.__isWhitespace(o))return null}return u.sign=n===-1,u.__trim()}},{key:`__fillFromParts`,value:function(e,t,n){for(var r=0,i=0,a=0,o=t.length-1;0<=o;o--){var s=t[o],c=n[o];i|=s<<a,a+=c,a===30?(e.__setDigit(r++,i),a=0,i=0):30<a&&(e.__setDigit(r++,1073741823&i),a-=30,i=s>>>c-a)}if(i!==0){if(r>=e.length)throw Error(`implementation bug`);e.__setDigit(r++,i)}for(;r<e.length;r++)e.__setDigit(r,0)}},{key:`__toStringBasePowerOfTwo`,value:function(e,t){var n=e.length,r=t-1;r=(85&r>>>1)+(85&r),r=(51&r>>>2)+(51&r),r=(15&r>>>4)+(15&r);var a=r,o=t-1,s=e.__digit(n-1),c=i.__clz30(s),l=0|(30*n-c+a-1)/a;if(e.sign&&l++,268435456<l)throw Error(`string too long`);for(var u=Array(l),d=l-1,f=0,p=0,m=0;m<n-1;m++){var h=e.__digit(m),g=(f|h<<p)&o;u[d--]=i.__kConversionChars[g];var _=a-p;for(f=h>>>_,p=30-_;p>=a;)u[d--]=i.__kConversionChars[f&o],f>>>=a,p-=a}var v=(f|s<<p)&o;for(u[d--]=i.__kConversionChars[v],f=s>>>a-p;f!==0;)u[d--]=i.__kConversionChars[f&o],f>>>=a;if(e.sign&&(u[d--]=`-`),d!==-1)throw Error(`implementation bug`);return u.join(``)}},{key:`__toStringGeneric`,value:function(e,t,n){var r=e.length;if(r===0)return``;if(r===1){var a=e.__unsignedDigit(0).toString(t);return!1===n&&e.sign&&(a=`-`+a),a}var o=30*r-i.__clz30(e.__digit(r-1)),s=i.__kMaxBitsPerChar[t]-1,c=o*i.__kBitsPerCharTableMultiplier;c+=s-1,c=0|c/s;var l,u,d=c+1>>1,f=i.exponentiate(i.__oneDigit(t,!1),i.__oneDigit(d,!1)),p=f.__unsignedDigit(0);if(f.length===1&&32767>=p){l=new i(e.length,!1),l.__initializeDigits();for(var m,h=0,g=2*e.length-1;0<=g;g--)m=h<<15|e.__halfDigit(g),l.__setHalfDigit(g,0|m/p),h=0|m%p;u=h.toString(t)}else{var _=i.__absoluteDivLarge(e,f,!0,!0);l=_.quotient;var v=_.remainder.__trim();u=i.__toStringGeneric(v,t,!0)}l.__trim();for(var y=i.__toStringGeneric(l,t,!0);u.length<d;)u=`0`+u;return!1===n&&e.sign&&(y=`-`+y),y+u}},{key:`__unequalSign`,value:function(e){return e?-1:1}},{key:`__absoluteGreater`,value:function(e){return e?-1:1}},{key:`__absoluteLess`,value:function(e){return e?1:-1}},{key:`__compareToBigInt`,value:function(e,t){var n=e.sign;if(n!==t.sign)return i.__unequalSign(n);var r=i.__absoluteCompare(e,t);return 0<r?i.__absoluteGreater(n):0>r?i.__absoluteLess(n):0}},{key:`__compareToNumber`,value:function(e,n){if(i.__isOneDigitInt(n)){var r=e.sign,a=0>n;if(r!==a)return i.__unequalSign(r);if(e.length===0){if(a)throw Error(`implementation bug`);return n===0?0:-1}if(1<e.length)return i.__absoluteGreater(r);var o=t(n),s=e.__unsignedDigit(0);return s>o?i.__absoluteGreater(r):s<o?i.__absoluteLess(r):0}return i.__compareToDouble(e,n)}},{key:`__compareToDouble`,value:function(e,t){if(t!==t)return t;if(t===1/0)return-1;if(t===-1/0)return 1;var n=e.sign;if(n!==0>t)return i.__unequalSign(n);if(t===0)throw Error(`implementation bug: should be handled elsewhere`);if(e.length===0)return-1;i.__kBitConversionDouble[0]=t;var r=2047&i.__kBitConversionInts[i.__kBitConversionIntHigh]>>>20;if(r==2047)throw Error(`implementation bug: handled elsewhere`);var a=r-1023;if(0>a)return i.__absoluteGreater(n);var o=e.length,s=e.__digit(o-1),c=i.__clz30(s),l=30*o-c,u=a+1;if(l<u)return i.__absoluteLess(n);if(l>u)return i.__absoluteGreater(n);var d=1048576|1048575&i.__kBitConversionInts[i.__kBitConversionIntHigh],f=i.__kBitConversionInts[i.__kBitConversionIntLow],p=20,m=29-c;if(m!==(0|(l-1)%30))throw Error(`implementation bug`);var h,g=0;if(m<p){var _=p-m;g=_+32,h=d>>>_,d=d<<32-_|f>>>_,f<<=32-_}else if(m===p)g=32,h=d,d=f,f=0;else{var v=m-p;g=32-v,h=d<<v|f>>>32-v,d=f<<v,f=0}if(s>>>=0,h>>>=0,s>h)return i.__absoluteGreater(n);if(s<h)return i.__absoluteLess(n);for(var y=o-2;0<=y;y--){0<g?(g-=30,h=d>>>2,d=d<<30|f>>>2,f<<=30):h=0;var b=e.__unsignedDigit(y);if(b>h)return i.__absoluteGreater(n);if(b<h)return i.__absoluteLess(n)}if(d!==0||f!==0){if(g===0)throw Error(`implementation bug`);return i.__absoluteLess(n)}return 0}},{key:`__equalToNumber`,value:function(e,n){return i.__isOneDigitInt(n)?n===0?e.length===0:e.length===1&&e.sign===0>n&&e.__unsignedDigit(0)===t(n):i.__compareToDouble(e,n)===0}},{key:`__comparisonResultToBool`,value:function(e,t){return t===0?0>e:t===1?0>=e:t===2?0<e:t===3?0<=e:void 0}},{key:`__compare`,value:function(e,t,n){if(e=i.__toPrimitive(e),t=i.__toPrimitive(t),typeof e==`string`&&typeof t==`string`)switch(n){case 0:return e<t;case 1:return e<=t;case 2:return e>t;case 3:return e>=t}if(i.__isBigInt(e)&&typeof t==`string`)return t=i.__fromString(t),t!==null&&i.__comparisonResultToBool(i.__compareToBigInt(e,t),n);if(typeof e==`string`&&i.__isBigInt(t))return e=i.__fromString(e),e!==null&&i.__comparisonResultToBool(i.__compareToBigInt(e,t),n);if(e=i.__toNumeric(e),t=i.__toNumeric(t),i.__isBigInt(e)){if(i.__isBigInt(t))return i.__comparisonResultToBool(i.__compareToBigInt(e,t),n);if(typeof t!=`number`)throw Error(`implementation bug`);return i.__comparisonResultToBool(i.__compareToNumber(e,t),n)}if(typeof e!=`number`)throw Error(`implementation bug`);if(i.__isBigInt(t))return i.__comparisonResultToBool(i.__compareToNumber(t,e),2^n);if(typeof t!=`number`)throw Error(`implementation bug`);return n===0?e<t:n===1?e<=t:n===2?e>t:n===3?e>=t:void 0}},{key:`__absoluteAdd`,value:function(e,t,n){if(e.length<t.length)return i.__absoluteAdd(t,e,n);if(e.length===0)return e;if(t.length===0)return e.sign===n?e:i.unaryMinus(e);var r=e.length;(e.__clzmsd()===0||t.length===e.length&&t.__clzmsd()===0)&&r++;for(var a,o=new i(r,n),s=0,c=0;c<t.length;c++)a=e.__digit(c)+t.__digit(c)+s,s=a>>>30,o.__setDigit(c,1073741823&a);for(;c<e.length;c++){var l=e.__digit(c)+s;s=l>>>30,o.__setDigit(c,1073741823&l)}return c<o.length&&o.__setDigit(c,s),o.__trim()}},{key:`__absoluteSub`,value:function(e,t,n){if(e.length===0)return e;if(t.length===0)return e.sign===n?e:i.unaryMinus(e);for(var r,a=new i(e.length,n),o=0,s=0;s<t.length;s++)r=e.__digit(s)-t.__digit(s)-o,o=1&r>>>30,a.__setDigit(s,1073741823&r);for(;s<e.length;s++){var c=e.__digit(s)-o;o=1&c>>>30,a.__setDigit(s,1073741823&c)}return a.__trim()}},{key:`__absoluteAddOne`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length;n===null?n=new i(r,t):n.sign=t;for(var a,o=1,s=0;s<r;s++)a=e.__digit(s)+o,o=a>>>30,n.__setDigit(s,1073741823&a);return o!==0&&n.__setDigitGrow(r,1),n}},{key:`__absoluteSubOne`,value:function(e,t){var n=e.length;t||=n;for(var r,a=new i(t,!1),o=1,s=0;s<n;s++)r=e.__digit(s)-o,o=1&r>>>30,a.__setDigit(s,1073741823&r);if(o!==0)throw Error(`implementation bug`);for(var c=n;c<t;c++)a.__setDigit(c,0);return a}},{key:`__absoluteAnd`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;if(r<a){o=r;var s=e,c=r;e=t,r=a,t=s,a=c}var l=o;n===null?n=new i(l,!1):l=n.length;for(var u=0;u<o;u++)n.__setDigit(u,e.__digit(u)&t.__digit(u));for(;u<l;u++)n.__setDigit(u,0);return n}},{key:`__absoluteAndNot`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;r<a&&(o=r);var s=r;n===null?n=new i(s,!1):s=n.length;for(var c=0;c<o;c++)n.__setDigit(c,e.__digit(c)&~t.__digit(c));for(;c<r;c++)n.__setDigit(c,e.__digit(c));for(;c<s;c++)n.__setDigit(c,0);return n}},{key:`__absoluteOr`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;if(r<a){o=r;var s=e,c=r;e=t,r=a,t=s,a=c}var l=r;n===null?n=new i(l,!1):l=n.length;for(var u=0;u<o;u++)n.__setDigit(u,e.__digit(u)|t.__digit(u));for(;u<r;u++)n.__setDigit(u,e.__digit(u));for(;u<l;u++)n.__setDigit(u,0);return n}},{key:`__absoluteXor`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;if(r<a){o=r;var s=e,c=r;e=t,r=a,t=s,a=c}var l=r;n===null?n=new i(l,!1):l=n.length;for(var u=0;u<o;u++)n.__setDigit(u,e.__digit(u)^t.__digit(u));for(;u<r;u++)n.__setDigit(u,e.__digit(u));for(;u<l;u++)n.__setDigit(u,0);return n}},{key:`__absoluteCompare`,value:function(e,t){var n=e.length-t.length;if(n!=0)return n;for(var r=e.length-1;0<=r&&e.__digit(r)===t.__digit(r);)r--;return 0>r?0:e.__unsignedDigit(r)>t.__unsignedDigit(r)?1:-1}},{key:`__multiplyAccumulate`,value:function(e,t,n,r){if(t!==0){for(var a=32767&t,o=t>>>15,s=0,c=0,l=0;l<e.length;l++,r++){var u=n.__digit(r),d=e.__digit(l),f=32767&d,p=d>>>15,m=i.__imul(f,a),h=i.__imul(f,o),g=i.__imul(p,a),_=i.__imul(p,o);u+=c+m+s,s=u>>>30,u&=1073741823,u+=((32767&h)<<15)+((32767&g)<<15),s+=u>>>30,c=_+(h>>>15)+(g>>>15),n.__setDigit(r,1073741823&u)}for(;s!==0||c!==0;r++){var v=n.__digit(r);v+=s+c,c=0,s=v>>>30,n.__setDigit(r,1073741823&v)}}}},{key:`__internalMultiplyAdd`,value:function(e,t,n,r,a){for(var o=n,s=0,c=0;c<r;c++){var l=e.__digit(c),u=i.__imul(32767&l,t),d=i.__imul(l>>>15,t),f=u+((32767&d)<<15)+s+o;o=f>>>30,s=d>>>15,a.__setDigit(c,1073741823&f)}if(a.length>r)for(a.__setDigit(r++,o+s);r<a.length;)a.__setDigit(r++,0);else if(o+s!==0)throw Error(`implementation bug`)}},{key:`__absoluteDivSmall`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;n===null&&(n=new i(e.length,!1));for(var r=0,a=2*e.length-1;0<=a;a-=2){var o=(r<<15|e.__halfDigit(a))>>>0,s=0|o/t;r=0|o%t,o=(r<<15|e.__halfDigit(a-1))>>>0;var c=0|o/t;r=0|o%t,n.__setDigit(a>>>1,s<<15|c)}return n}},{key:`__absoluteModSmall`,value:function(e,t){for(var n,r=0,i=2*e.length-1;0<=i;i--)n=(r<<15|e.__halfDigit(i))>>>0,r=0|n%t;return r}},{key:`__absoluteDivLarge`,value:function(e,t,n,r){var a=t.__halfDigitLength(),o=t.length,s=e.__halfDigitLength()-a,c=null;n&&(c=new i(s+2>>>1,!1),c.__initializeDigits());var l=new i(a+2>>>1,!1);l.__initializeDigits();var u=i.__clz15(t.__halfDigit(a-1));0<u&&(t=i.__specialLeftShift(t,u,0));for(var d=i.__specialLeftShift(e,u,1),f=t.__halfDigit(a-1),p=0,m=s;0<=m;m--){var h=32767,g=d.__halfDigit(m+a);if(g!==f){var _=(g<<15|d.__halfDigit(m+a-1))>>>0;h=0|_/f;for(var v=0|_%f,y=t.__halfDigit(a-2),b=d.__halfDigit(m+a-2);i.__imul(h,y)>>>0>(v<<16|b)>>>0&&(h--,v+=f,!(32767<v)););}i.__internalMultiplyAdd(t,h,0,o,l);var x=d.__inplaceSub(l,m,a+1);x!==0&&(x=d.__inplaceAdd(t,m,a),d.__setHalfDigit(m+a,32767&d.__halfDigit(m+a)+x),h--),n&&(1&m?p=h<<15:c.__setDigit(m>>>1,p|h))}if(r)return d.__inplaceRightShift(u),n?{quotient:c,remainder:d}:d;if(n)return c;throw Error(`unreachable`)}},{key:`__clz15`,value:function(e){return i.__clz30(e)-15}},{key:`__specialLeftShift`,value:function(e,t,n){var r=e.length,a=new i(r+n,!1);if(t===0){for(var o=0;o<r;o++)a.__setDigit(o,e.__digit(o));return 0<n&&a.__setDigit(r,0),a}for(var s,c=0,l=0;l<r;l++)s=e.__digit(l),a.__setDigit(l,1073741823&s<<t|c),c=s>>>30-t;return 0<n&&a.__setDigit(r,c),a}},{key:`__leftShiftByAbsolute`,value:function(e,t){var n=i.__toShiftAmount(t);if(0>n)throw RangeError(`BigInt too big`);var r=0|n/30,a=n%30,o=e.length,s=a!==0&&!!(e.__digit(o-1)>>>30-a),c=o+r+ +!!s,l=new i(c,e.sign);if(a===0){for(var u=0;u<r;u++)l.__setDigit(u,0);for(;u<c;u++)l.__setDigit(u,e.__digit(u-r))}else{for(var d=0,f=0;f<r;f++)l.__setDigit(f,0);for(var p,m=0;m<o;m++)p=e.__digit(m),l.__setDigit(m+r,1073741823&p<<a|d),d=p>>>30-a;if(s)l.__setDigit(o+r,d);else if(d!==0)throw Error(`implementation bug`)}return l.__trim()}},{key:`__rightShiftByAbsolute`,value:function(e,t){var n=e.length,r=e.sign,a=i.__toShiftAmount(t);if(0>a)return i.__rightShiftByMaximum(r);var o=0|a/30,s=a%30,c=n-o;if(0>=c)return i.__rightShiftByMaximum(r);var l=!1;if(r){var u=(1<<s)-1;if((e.__digit(o)&u)!=0)l=!0;else for(var d=0;d<o;d++)if(e.__digit(d)!==0){l=!0;break}}l&&s===0&&~e.__digit(n-1)==0&&c++;var f=new i(c,r);if(s===0){f.__setDigit(c-1,0);for(var p=o;p<n;p++)f.__setDigit(p-o,e.__digit(p))}else{for(var m,h=e.__digit(o)>>>s,g=n-o-1,_=0;_<g;_++)m=e.__digit(_+o+1),f.__setDigit(_,1073741823&m<<30-s|h),h=m>>>s;f.__setDigit(g,h)}return l&&(f=i.__absoluteAddOne(f,!0,f)),f.__trim()}},{key:`__rightShiftByMaximum`,value:function(e){return e?i.__oneDigit(1,!0):i.__zero()}},{key:`__toShiftAmount`,value:function(e){if(1<e.length)return-1;var t=e.__unsignedDigit(0);return t>i.__kMaxLengthBits?-1:t}},{key:`__toPrimitive`,value:function(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:`default`;if(S(e)!==`object`||e.constructor===i)return e;if(typeof Symbol<`u`&&S(Symbol.toPrimitive)===`symbol`&&e[Symbol.toPrimitive]){var n=e[Symbol.toPrimitive](t);if(S(n)!==`object`)return n;throw TypeError(`Cannot convert object to primitive value`)}var r=e.valueOf;if(r){var a=r.call(e);if(S(a)!==`object`)return a}var o=e.toString;if(o){var s=o.call(e);if(S(s)!==`object`)return s}throw TypeError(`Cannot convert object to primitive value`)}},{key:`__toNumeric`,value:function(e){return i.__isBigInt(e)?e:+e}},{key:`__isBigInt`,value:function(e){return S(e)===`object`&&e!==null&&e.constructor===i}},{key:`__truncateToNBits`,value:function(e,t){for(var n=0|(e+29)/30,r=new i(n,t.sign),a=n-1,o=0;o<a;o++)r.__setDigit(o,t.__digit(o));var s=t.__digit(a);if(e%30!=0){var c=32-e%30;s=s<<c>>>c}return r.__setDigit(a,s),r.__trim()}},{key:`__truncateAndSubFromPowerOfTwo`,value:function(e,t,n){for(var r=Math.min,a,o=0|(e+29)/30,s=new i(o,n),c=0,l=o-1,u=0,d=r(l,t.length);c<d;c++)a=0-t.__digit(c)-u,u=1&a>>>30,s.__setDigit(c,1073741823&a);for(;c<l;c++)s.__setDigit(c,0|1073741823&-u);var f,p=l<t.length?t.__digit(l):0,m=e%30;if(m===0)f=0-p-u,f&=1073741823;else{var h=32-m;p=p<<h>>>h;var g=1<<32-h;f=g-p-u,f&=g-1}return s.__setDigit(l,f),s.__trim()}},{key:`__digitPow`,value:function(e,t){for(var n=1;0<t;)1&t&&(n*=e),t>>>=1,e*=e;return n}},{key:`__detectBigEndian`,value:function(){return i.__kBitConversionDouble[0]=-0,i.__kBitConversionInts[0]!==0}},{key:`__isOneDigitInt`,value:function(e){return(1073741823&e)===e}}])}(w(Array));return T.__kMaxLength=33554432,T.__kMaxLengthBits=T.__kMaxLength<<5,T.__kMaxBitsPerChar=[0,0,32,51,64,75,83,90,96,102,107,111,115,119,122,126,128,131,134,136,139,141,143,145,147,149,151,153,154,156,158,159,160,162,163,165,166],T.__kBitsPerCharTableShift=5,T.__kBitsPerCharTableMultiplier=1<<T.__kBitsPerCharTableShift,T.__kConversionChars=`0123456789abcdefghijklmnopqrstuvwxyz`.split(``),T.__kBitConversionBuffer=new ArrayBuffer(8),T.__kBitConversionDouble=new Float64Array(T.__kBitConversionBuffer),T.__kBitConversionInts=new Int32Array(T.__kBitConversionBuffer),T.__kBitConversionIntHigh=+!T.__detectBigEndian(),T.__kBitConversionIntLow=+!!T.__detectBigEndian(),T.__clz30=t?function(e){return t(e)-2}:function(e){var t=Math.LN2,n=Math.log;return e===0?30:0|29-(0|n(e>>>0)/t)},T.__imul=e||function(e,t){return 0|e*t},T})}))(),1),DG=Z.default.BigInt(0),OG=Z.default.BigInt(1),kG=Z.default.BigInt(2),Dve=Z.default.BigInt(10),Ove=Z.default.BigInt(24),kve=Z.default.BigInt(60),Ave=Z.default.BigInt(1e3),AG=Z.default.BigInt(1e6),jG=Z.default.BigInt(1e9),MG=Z.default.multiply(Z.default.BigInt(3600),jG),jve=Z.default.multiply(kve,jG),NG=Z.default.multiply(MG,Ove);function PG(e){return typeof e==`bigint`?Z.default.BigInt(e.toString(10)):e}function FG(e){return Z.default.equal(Z.default.remainder(e,kG),DG)}function IG(e){return Z.default.lessThan(e,DG)?Z.default.unaryMinus(e):e}function LG(e,t){return Z.default.lessThan(e,t)?-1:+!!Z.default.greaterThan(e,t)}function RG(e,t){return{quotient:Z.default.divide(e,t),remainder:Z.default.remainder(e,t)}}var zG,BG,VG=`slot-epochNanoSeconds`,HG=`slot-iso-date`,UG=`slot-iso-date-time`,WG=`slot-time`,GG=`slot-calendar`,KG=`slot-date-brand`,qG=`slot-year-month-brand`,JG=`slot-month-day-brand`,YG=`slot-time-zone`,XG=`slot-years`,ZG=`slot-months`,QG=`slot-weeks`,$G=`slot-days`,eK=`slot-hours`,tK=`slot-minutes`,nK=`slot-seconds`,rK=`slot-milliseconds`,iK=`slot-microseconds`,aK=`slot-nanoseconds`,oK=`date`,sK=`ym`,cK=`md`,lK=`time`,uK=`datetime`,dK=`instant`,fK=`original`,pK=`timezone-canonical`,mK=`timezone-original`,hK=`calendar-id`,gK=`locale`,_K=`options`,vK=new WeakMap,yK=Symbol.for(`@@Temporal__GetSlots`);(zG=globalThis)[yK]||(zG[yK]=function(e){return vK.get(e)});var bK=globalThis[yK],xK=Symbol.for(`@@Temporal__CreateSlots`);(BG=globalThis)[xK]||(BG[xK]=function(e){vK.set(e,Object.create(null))});var SK=globalThis[xK];function CK(e,...t){if(!e||typeof e!=`object`)return!1;let n=bK(e);return!!n&&t.every((e=>e in n))}function Q(e,t){let n=bK(e)?.[t];if(n===void 0)throw TypeError(`Missing internal slot ${t}`);return n}function wK(e,t,n){let r=bK(e);if(r===void 0)throw TypeError(`Missing slots for the given container`);if(r[t])throw TypeError(`${t} already has set`);r[t]=n}var TK={};function EK(e,t){Object.defineProperty(e.prototype,Symbol.toStringTag,{value:t,writable:!1,enumerable:!1,configurable:!0});let n=Object.getOwnPropertyNames(e);for(let t=0;t<n.length;t++){let r=n[t],i=Object.getOwnPropertyDescriptor(e,r);i.configurable&&i.enumerable&&(i.enumerable=!1,Object.defineProperty(e,r,i))}let r=Object.getOwnPropertyNames(e.prototype);for(let t=0;t<r.length;t++){let n=r[t],i=Object.getOwnPropertyDescriptor(e.prototype,n);i.configurable&&i.enumerable&&(i.enumerable=!1,Object.defineProperty(e.prototype,n,i))}DK(t,e),DK(`${t}.prototype`,e.prototype)}function DK(e,t){let n=`%${e}%`;if(TK[n]!==void 0)throw Error(`intrinsic ${e} already exists`);TK[n]=t}function OK(e){return TK[e]}function kK(e,t){let n=e;if(n===0)return{div:n,mod:n};let r=Math.sign(n);n=Math.abs(n);let i=Math.trunc(1+Math.log10(n));if(t>=i)return{div:0*r,mod:r*n};if(t===0)return{div:r*n,mod:0*r};let a=n.toPrecision(i);return{div:r*Number.parseInt(a.slice(0,i-t),10),mod:r*Number.parseInt(a.slice(i-t),10)}}function AK(e,t,n){let r=e,i=n;if(r===0)return i;let a=Math.sign(r)||Math.sign(i);r=Math.abs(r),i=Math.abs(i);let o=r.toPrecision(Math.trunc(1+Math.log10(r)));if(i===0)return a*Number.parseInt(o+`0`.repeat(t),10);let s=o+i.toPrecision(Math.trunc(1+Math.log10(i))).padStart(t,`0`);return a*Number.parseInt(s,10)}function jK(e,t){let n=t===`negative`;switch(e){case`ceil`:return n?`zero`:`infinity`;case`floor`:return n?`infinity`:`zero`;case`expand`:return`infinity`;case`trunc`:return`zero`;case`halfCeil`:return n?`half-zero`:`half-infinity`;case`halfFloor`:return n?`half-infinity`:`half-zero`;case`halfExpand`:return`half-infinity`;case`halfTrunc`:return`half-zero`;case`halfEven`:return`half-even`}}function MK(e,t,n,r,i){return i===`zero`?e:i===`infinity`?t:n<0?e:n>0?t:i===`half-zero`?e:i===`half-infinity`?t:r?e:t}var NK=class e{constructor(e){this.totalNs=PG(e),this.sec=Z.default.toNumber(Z.default.divide(this.totalNs,jG)),this.subsec=Z.default.toNumber(Z.default.remainder(this.totalNs,jG))}static validateNew(t,n){if(Z.default.greaterThan(IG(t),e.MAX))throw RangeError(`${n} of duration time units cannot exceed ${e.MAX} s`);return new e(t)}static fromEpochNsDiff(t,n){let r=Z.default.subtract(PG(t),PG(n));return new e(r)}static fromComponents(t,n,r,i,a,o){let s=Z.default.add(Z.default.add(Z.default.add(Z.default.add(Z.default.add(Z.default.BigInt(o),Z.default.multiply(Z.default.BigInt(a),Ave)),Z.default.multiply(Z.default.BigInt(i),AG)),Z.default.multiply(Z.default.BigInt(r),jG)),Z.default.multiply(Z.default.BigInt(n),jve)),Z.default.multiply(Z.default.BigInt(t),MG));return e.validateNew(s,`total`)}abs(){return new e(IG(this.totalNs))}add(t){return e.validateNew(Z.default.add(this.totalNs,t.totalNs),`sum`)}add24HourDays(t){return e.validateNew(Z.default.add(this.totalNs,Z.default.multiply(Z.default.BigInt(t),NG)),`sum`)}addToEpochNs(e){return Z.default.add(PG(e),this.totalNs)}cmp(e){return LG(this.totalNs,e.totalNs)}divmod(t){let{quotient:n,remainder:r}=RG(this.totalNs,Z.default.BigInt(t));return{quotient:Z.default.toNumber(n),remainder:new e(r)}}fdiv(e){let t=PG(e),n=Z.default.BigInt(t),{quotient:r,remainder:i}=RG(this.totalNs,n),a=[],o,s=(Z.default.lessThan(this.totalNs,DG)?-1:1)*Math.sign(Z.default.toNumber(t));for(;!Z.default.equal(i,DG)&&a.length<50;)i=Z.default.multiply(i,Dve),{quotient:o,remainder:i}=RG(i,n),a.push(Math.abs(Z.default.toNumber(o)));return s*Number(IG(r).toString()+`.`+a.join(``))}isZero(){return Z.default.equal(this.totalNs,DG)}round(t,n){let r=PG(t);if(Z.default.equal(r,OG))return this;let{quotient:i,remainder:a}=RG(this.totalNs,r),o=Z.default.lessThan(this.totalNs,DG)?`negative`:`positive`,s=Z.default.multiply(IG(i),r),c=Z.default.add(s,r),l=LG(IG(Z.default.multiply(a,kG)),r),u=jK(n,o),d=Z.default.equal(IG(this.totalNs),s)?s:MK(s,c,l,FG(i),u),f=o===`positive`?d:Z.default.unaryMinus(d);return e.validateNew(f,`rounding`)}sign(){return this.cmp(new e(DG))}subtract(t){return e.validateNew(Z.default.subtract(this.totalNs,t.totalNs),`difference`)}};NK.MAX=Z.default.BigInt(`9007199254740991999999999`),NK.ZERO=new NK(DG);var PK=/[A-Za-z._][A-Za-z._0-9+-]*/,FK=RegExp(`(?:(?:[+-](?:[01][0-9]|2[0-3])(?::?[0-5][0-9])?)|(?:${PK.source})(?:\\/(?:${PK.source}))*)`),IK=/(?:[+-]\d{6}|\d{4})/,LK=/(?:0[1-9]|1[0-2])/,RK=/(?:0[1-9]|[12]\d|3[01])/,Mve=RegExp(`(${IK.source})(?:-(${LK.source})-(${RK.source})|(${LK.source})(${RK.source}))`),zK=/(\d{2})(?::(\d{2})(?::(\d{2})(?:[.,](\d{1,9}))?)?|(\d{2})(?:(\d{2})(?:[.,](\d{1,9}))?)?)?/,BK=/((?:[+-])(?:[01][0-9]|2[0-3])(?::?(?:[0-5][0-9])(?::?(?:[0-5][0-9])(?:[.,](?:\d{1,9}))?)?)?)/,VK=RegExp(`([zZ])|${BK.source}?`),HK=/\[(!)?([a-z_][a-z0-9_-]*)=([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)\]/g,Nve=new RegExp([`^${Mve.source}`,`(?:(?:[tT]|\\s+)${zK.source}(?:${VK.source})?)?`,`(?:\\[!?(${FK.source})\\])?`,`((?:${HK.source})*)$`].join(``)),Pve=new RegExp([`^[tT]?${zK.source}`,`(?:${VK.source})?`,`(?:\\[!?${FK.source}\\])?`,`((?:${HK.source})*)$`].join(``)),Fve=RegExp(`^(${IK.source})-?(${LK.source})(?:\\[!?${FK.source}\\])?((?:${HK.source})*)$`),Ive=RegExp(`^(?:--)?(${LK.source})-?(${RK.source})(?:\\[!?${FK.source}\\])?((?:${HK.source})*)$`),UK=/(\d+)(?:[.,](\d{1,9}))?/,Lve=RegExp(`(?:${UK.source}H)?(?:${UK.source}M)?(?:${UK.source}S)?`),Rve=RegExp(`^([+-])?P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?!$)${Lve.source})?$`,`i`),WK=864e5,GK=1e6*WK,zve=6e10,KK=1e8*WK,qK=FX(KK),JK=Z.default.unaryMinus(qK),Bve=Z.default.add(Z.default.subtract(JK,NG),OG),Vve=Z.default.subtract(Z.default.add(qK,NG),OG),Hve=146097*WK,YK=-271821,XK=275760,ZK=Date.UTC(1847,0,1),Uve=[`iso8601`,`hebrew`,`islamic`,`islamic-umalqura`,`islamic-tbla`,`islamic-civil`,`islamic-rgsa`,`islamicc`,`persian`,`ethiopic`,`ethioaa`,`ethiopic-amete-alem`,`coptic`,`chinese`,`dangi`,`roc`,`indian`,`buddhist`,`japanese`,`gregory`],Wve=new Set([`ACT`,`AET`,`AGT`,`ART`,`AST`,`BET`,`BST`,`CAT`,`CNT`,`CST`,`CTT`,`EAT`,`ECT`,`IET`,`IST`,`JST`,`MIT`,`NET`,`NST`,`PLT`,`PNT`,`PRT`,`PST`,`SST`,`VST`]);function QK(e){return typeof e==`object`&&!!e||typeof e==`function`}function $K(e){if(typeof e==`bigint`)throw TypeError(`Cannot convert BigInt to number`);return Number(e)}function eq(e){if(typeof e==`symbol`)throw TypeError(`Cannot convert a Symbol value to a String`);return String(e)}function tq(e){let t=$K(e);if(t===0)return 0;if(Number.isNaN(t)||t===1/0||t===-1/0)throw RangeError(`invalid number value`);let n=Math.trunc(t);return n===0?0:n}function nq(e,t){let n=tq(e);if(n<=0)throw RangeError(t===void 0?`Cannot convert a number less than one to a positive integer`:`property '${t}' cannot be a a number less than one`);return n}function rq(e){let t=$K(e);if(Number.isNaN(t))throw RangeError(`not a number`);if(t===1/0||t===-1/0)throw RangeError(`infinity is out of range`);if(!function(e){if(typeof e!=`number`||Number.isNaN(e)||e===1/0||e===-1/0)return!1;let t=Math.abs(e);return Math.floor(t)===t}(t))throw RangeError(`unsupported fractional value ${e}`);return t===0?0:t}function iq(e,t){return String(e).padStart(t,`0`)}function aq(e){if(typeof e!=`string`)throw TypeError(`expected a string, not ${String(e)}`);return e}function oq(e,t){if(QK(e)){let t=e?.toString();if(typeof t==`string`||typeof t==`number`)return t;throw TypeError(`Cannot convert object to primitive value`)}return e}var sq=[`era`,`eraYear`,`year`,`month`,`monthCode`,`day`,`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],Gve={era:eq,eraYear:tq,year:tq,month:nq,monthCode:function(e){let t=aq(oq(e));if(t.length<3||t.length>4||t[0]!==`M`||`0123456789`.indexOf(t[1])===-1||`0123456789`.indexOf(t[2])===-1||t[1]+t[2]===`00`&&t[3]!==`L`||t[3]!==`L`&&t[3]!==void 0)throw RangeError(`bad month code ${t}; must match M01-M99 or M00L-M99L`);return t},day:nq,hour:tq,minute:tq,second:tq,millisecond:tq,microsecond:tq,nanosecond:tq,offset:function(e){let t=aq(oq(e));return lY(t),t},timeZone:VJ},Kve={hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},cq=[[`years`,`year`,`date`],[`months`,`month`,`date`],[`weeks`,`week`,`date`],[`days`,`day`,`date`],[`hours`,`hour`,`time`],[`minutes`,`minute`,`time`],[`seconds`,`second`,`time`],[`milliseconds`,`millisecond`,`time`],[`microseconds`,`microsecond`,`time`],[`nanoseconds`,`nanosecond`,`time`]],lq=Object.fromEntries(cq.map((e=>[e[0],e[1]]))),qve=Object.fromEntries(cq.map((([e,t])=>[t,e]))),uq=cq.map((([,e])=>e)),dq={day:GK,hour:36e11,minute:6e10,second:1e9,millisecond:1e6,microsecond:1e3,nanosecond:1},fq=[`days`,`hours`,`microseconds`,`milliseconds`,`minutes`,`months`,`nanoseconds`,`seconds`,`weeks`,`years`],Jve=Intl.DateTimeFormat,pq=new Map;function mq(e){let t=WX(e),n=pq.get(t);return n===void 0&&(n=new Jve(`en-us`,{timeZone:t,hour12:!1,era:`short`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`}),pq.set(t,n)),n}function hq(e){return CK(e,VG)&&!CK(e,YG,GG)}function gq(e){return CK(e,XG,ZG,$G,eK,tK,nK,rK,iK,aK)}function _q(e){return CK(e,KG)}function vq(e){return CK(e,WG)}function yq(e){return CK(e,UG)}function bq(e){return CK(e,qG)}function xq(e){return CK(e,JG)}function Sq(e){return CK(e,VG,YG,GG)}function $(e,t){if(!t(e))throw TypeError(`invalid receiver: method called with the wrong type of this-object`)}function Cq(e){if(CK(e,GG)||CK(e,YG))throw TypeError(`with() does not support a calendar or timeZone property`);if(vq(e))throw TypeError(`with() does not accept Temporal.PlainTime, use withPlainTime() instead`);if(e.calendar!==void 0)throw TypeError(`with() does not support a calendar property`);if(e.timeZone!==void 0)throw TypeError(`with() does not support a timeZone property`)}function wq(e,t){return t===`never`||t===`auto`&&e===`iso8601`?``:`[${t===`critical`?`!`:``}u-ca=${e}]`}function Tq(e){let t,n,r=!1;for(HK.lastIndex=0;n=HK.exec(e);){let{1:i,2:a,3:o}=n;if(a===`u-ca`){if(t===void 0)t=o,r=i===`!`;else if(i===`!`||r)throw RangeError(`Invalid annotations in ${e}: more than one u-ca present with critical flag`)}else if(i===`!`)throw RangeError(`Unrecognized annotation: !${a}=${o}`)}return t}function Eq(e){let t=Nve.exec(e);if(!t)throw RangeError(`invalid RFC 9557 string: ${e}`);let n=Tq(t[16]),r=t[1];if(r===`-000000`)throw RangeError(`invalid RFC 9557 string: ${e}`);let i=+r,a=+(t[2]??t[4]??1),o=+(t[3]??t[5]??1),s=t[6]!==void 0,c=+(t[6]??0),l=+(t[7]??t[10]??0),u=+(t[8]??t[11]??0);u===60&&(u=59);let d=(t[9]??t[12]??``)+`000000000`,f=+d.slice(0,3),p=+d.slice(3,6),m=+d.slice(6,9),h,g=!1;t[13]?(h=void 0,g=!0):t[14]&&(h=t[14]);let _=t[15];return zY(i,a,o,c,l,u,f,p,m),{year:i,month:a,day:o,time:s?{hour:c,minute:l,second:u,millisecond:f,microsecond:p,nanosecond:m}:`start-of-day`,tzAnnotation:_,offset:h,z:g,calendar:n}}function Dq(e){let t=Pve.exec(e),n,r,i,a,o,s,c;if(t){c=Tq(t[10]),n=+(t[1]??0),r=+(t[2]??t[5]??0),i=+(t[3]??t[6]??0),i===60&&(i=59);let e=(t[4]??t[7]??``)+`000000000`;if(a=+e.slice(0,3),o=+e.slice(3,6),s=+e.slice(6,9),t[8])throw RangeError(`Z designator not supported for PlainTime`)}else{let t,l;if({time:t,z:l,calendar:c}=Eq(e),t===`start-of-day`)throw RangeError(`time is missing in string: ${e}`);if(l)throw RangeError(`Z designator not supported for PlainTime`);({hour:n,minute:r,second:i,millisecond:a,microsecond:o,nanosecond:s}=t)}if(RY(n,r,i,a,o,s),/[tT ][0-9][0-9]/.test(e))return{hour:n,minute:r,second:i,millisecond:a,microsecond:o,nanosecond:s,calendar:c};try{let{month:t,day:n}=kq(e);IY(1972,t,n)}catch{try{let{year:t,month:n}=Oq(e);IY(t,n,1)}catch{return{hour:n,minute:r,second:i,millisecond:a,microsecond:o,nanosecond:s,calendar:c}}}throw RangeError(`invalid RFC 9557 time-only string ${e}; may need a T prefix`)}function Oq(e){let t=Fve.exec(e),n,r,i,a;if(t){i=Tq(t[3]);let o=t[1];if(o===`-000000`)throw RangeError(`invalid RFC 9557 string: ${e}`);if(n=+o,r=+t[2],a=1,i!==void 0&&i!==`iso8601`)throw RangeError(`YYYY-MM format is only valid with iso8601 calendar`)}else{let t;if({year:n,month:r,calendar:i,day:a,z:t}=Eq(e),t)throw RangeError(`Z designator not supported for PlainYearMonth`)}return{year:n,month:r,calendar:i,referenceISODay:a}}function kq(e){let t=Ive.exec(e),n,r,i,a;if(t){if(i=Tq(t[3]),n=+t[1],r=+t[2],i!==void 0&&i!==`iso8601`)throw RangeError(`MM-DD format is only valid with iso8601 calendar`)}else{let t;if({month:n,day:r,calendar:i,year:a,z:t}=Eq(e),t)throw RangeError(`Z designator not supported for PlainMonthDay`)}return{month:n,day:r,calendar:i,referenceISOYear:a}}var Aq=RegExp(`^${FK.source}$`,`i`),jq=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])?)?$`);function Mq(e){let t=Xve.test(e)?`Seconds not allowed in offset time zone`:`Invalid time zone`;throw RangeError(`${t}: ${e}`)}function Nq(e){return Aq.test(e)||Mq(e),jq.test(e)?{offsetMinutes:lY(e)/6e10}:{tzName:e}}function Pq(e,t,n,r){let i=e,a=t,o=n;switch(r){case`reject`:IY(i,a,o);break;case`constrain`:({year:i,month:a,day:o}=PY(i,a,o))}return{year:i,month:a,day:o}}function Fq(e,t,n,r,i,a,o){let s=e,c=t,l=n,u=r,d=i,f=a;switch(o){case`reject`:RY(s,c,l,u,d,f);break;case`constrain`:s=NY(s,0,23),c=NY(c,0,59),l=NY(l,0,59),u=NY(u,0,999),d=NY(d,0,999),f=NY(f,0,999)}return{hour:s,minute:c,second:l,millisecond:u,microsecond:d,nanosecond:f}}function Iq(e){if(!QK(e))throw TypeError(`invalid duration-like`);let t={years:void 0,months:void 0,weeks:void 0,days:void 0,hours:void 0,minutes:void 0,seconds:void 0,milliseconds:void 0,microseconds:void 0,nanoseconds:void 0},n=!1;for(let r=0;r<fq.length;r++){let i=fq[r],a=e[i];a!==void 0&&(n=!0,t[i]=rq(a))}if(!n)throw TypeError(`invalid duration-like`);return t}function Lq({years:e,months:t,weeks:n,days:r},i,a,o){return{years:e,months:o??t,weeks:a??n,days:i??r}}function Rq(e,t){return{isoDate:e,time:t}}function zq(e){return HX(e,`overflow`,[`constrain`,`reject`],`constrain`)}function Bq(e){return HX(e,`disambiguation`,[`compatible`,`earlier`,`later`,`reject`],`compatible`)}function Vq(e,t){return HX(e,`roundingMode`,[`ceil`,`floor`,`expand`,`trunc`,`halfCeil`,`halfFloor`,`halfExpand`,`halfTrunc`,`halfEven`],t)}function Hq(e,t){return HX(e,`offset`,[`prefer`,`use`,`ignore`,`reject`],t)}function Uq(e){return HX(e,`calendarName`,[`auto`,`always`,`never`,`critical`],`auto`)}function Wq(e){let t=e.roundingIncrement;if(t===void 0)return 1;let n=tq(t);if(n<1||n>1e9)throw RangeError(`roundingIncrement must be at least 1 and at most 1e9, not ${t}`);return n}function Gq(e,t,n){let r=n?t:t-1;if(e>r)throw RangeError(`roundingIncrement must be at least 1 and less than ${r}, not ${e}`);if(t%e!=0)throw RangeError(`Rounding increment must divide evenly into ${t}`)}function Kq(e){let t=e.fractionalSecondDigits;if(t===void 0)return`auto`;if(typeof t!=`number`){if(eq(t)!==`auto`)throw RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${t}`);return`auto`}let n=Math.floor(t);if(!Number.isFinite(n)||n<0||n>9)throw RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${t}`);return n}function qq(e,t){switch(e){case`minute`:return{precision:`minute`,unit:`minute`,increment:1};case`second`:return{precision:0,unit:`second`,increment:1};case`millisecond`:return{precision:3,unit:`millisecond`,increment:1};case`microsecond`:return{precision:6,unit:`microsecond`,increment:1};case`nanosecond`:return{precision:9,unit:`nanosecond`,increment:1}}switch(t){case`auto`:return{precision:t,unit:`nanosecond`,increment:1};case 0:return{precision:t,unit:`second`,increment:1};case 1:case 2:case 3:return{precision:t,unit:`millisecond`,increment:10**(3-t)};case 4:case 5:case 6:return{precision:t,unit:`microsecond`,increment:10**(6-t)};case 7:case 8:case 9:return{precision:t,unit:`nanosecond`,increment:10**(9-t)};default:throw RangeError(`fractionalSecondDigits must be 'auto' or 0 through 9, not ${t}`)}}var Jq=Symbol(`~required~`);function Yq(e,t,n,r,i=[]){let a=[];for(let e=0;e<cq.length;e++){let t=cq[e],r=t[1],i=t[2];n!==`datetime`&&n!==i||a.push(r)}a=a.concat(i);let o=r;o===Jq?o=void 0:o!==void 0&&a.push(o);let s=[];s=s.concat(a);for(let e=0;e<a.length;e++){let t=qve[a[e]];t!==void 0&&s.push(t)}let c=HX(e,t,s,o);if(c===void 0&&r===Jq)throw RangeError(`${t} is required`);return c&&c in lq?lq[c]:c}function Xq(e){let t=e.relativeTo;if(t===void 0)return{};let n,r,i,a,o,s=`option`,c=!1;if(QK(t)){if(Sq(t))return{zonedRelativeTo:t};if(_q(t))return{plainRelativeTo:t};if(yq(t))return{plainRelativeTo:vJ(Q(t,UG).isoDate,Q(t,GG))};i=IJ(t);let e=iJ(i,t,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],[]);({isoDate:n,time:r}=sJ(i,e,`constrain`)),{offset:o,timeZone:a}=e,o===void 0&&(s=`wall`)}else{let e,l,u,d,f;if({year:u,month:d,day:f,time:r,calendar:i,tzAnnotation:e,offset:o,z:l}=Eq(aq(t)),e)a=VJ(e),l?s=`exact`:o||(s=`wall`),c=!0;else if(l)throw RangeError(`Z designator not supported for PlainDate relativeTo; either remove the Z or add a bracketed time zone`);i||=`iso8601`,i=UX(i),n={year:u,month:d,day:f}}return a===void 0?{plainRelativeTo:vJ(n,i)}:{zonedRelativeTo:AJ(hJ(n,r,s,s===`option`?lY(o):0,a,`compatible`,`reject`,c),a,i)}}function Zq(e){return Q(e,XG)===0?Q(e,ZG)===0?Q(e,QG)===0?Q(e,$G)===0?Q(e,eK)===0?Q(e,tK)===0?Q(e,nK)===0?Q(e,rK)===0?Q(e,iK)===0?`nanosecond`:`microsecond`:`millisecond`:`second`:`minute`:`hour`:`day`:`week`:`month`:`year`}function Qq(e,t){return uq.indexOf(e)>uq.indexOf(t)?t:e}function $q(e){return e===`year`||e===`month`||e===`week`}function eJ(e){return $q(e)||e===`day`?`date`:`time`}function tJ(e){return OK(`%calendarImpl%`)(e)}function nJ(e){return OK(`%calendarImpl%`)(Q(e,GG))}function rJ(e,t,n=`date`){let r=Object.create(null),i=tJ(e).isoToDate(t,{year:!0,monthCode:!0,day:!0});return r.monthCode=i.monthCode,n!==`month-day`&&n!==`date`||(r.day=i.day),n!==`year-month`&&n!==`date`||(r.year=i.year),r}function iJ(e,t,n,r,i){let a=tJ(e).extraFields(n),o=n.concat(r,a),s=Object.create(null),c=!1;o.sort();for(let e=0;e<o.length;e++){let n=o[e],r=t[n];if(r!==void 0)c=!0,s[n]=(0,Gve[n])(r);else if(i!==`partial`){if(i.includes(n))throw TypeError(`required property '${n}' missing or undefined`);s[n]=Kve[n]}}if(i===`partial`&&!c)throw TypeError(`no supported properties found`);return s}function aJ(e,t=`complete`){let n=[`hour`,`microsecond`,`millisecond`,`minute`,`nanosecond`,`second`],r=!1,i=Object.create(null);for(let a=0;a<n.length;a++){let o=n[a],s=e[o];s===void 0?t===`complete`&&(i[o]=0):(i[o]=tq(s),r=!0)}if(!r)throw TypeError(`invalid time-like`);return i}function oJ(e,t){if(QK(e)){if(_q(e))return zq(BX(t)),vJ(Q(e,HG),Q(e,GG));if(Sq(e)){let n=GJ(Q(e,YG),Q(e,VG));return zq(BX(t)),vJ(n.isoDate,Q(e,GG))}if(yq(e))return zq(BX(t)),vJ(Q(e,UG).isoDate,Q(e,GG));let n=IJ(e);return vJ(RJ(n,iJ(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),zq(BX(t))),n)}let{year:n,month:r,day:i,calendar:a,z:o}=Eq(aq(e));if(o)throw RangeError(`Z designator not supported for PlainDate`);return a||=`iso8601`,a=UX(a),zq(BX(t)),vJ({year:n,month:r,day:i},a)}function sJ(e,t,n){return Rq(RJ(e,t,n),Fq(t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond,n))}function cJ(e,t){let n,r,i;if(QK(e)){if(yq(e))return zq(BX(t)),bJ(Q(e,UG),Q(e,GG));if(Sq(e)){let n=GJ(Q(e,YG),Q(e,VG));return zq(BX(t)),bJ(n,Q(e,GG))}if(_q(e))return zq(BX(t)),bJ(Rq(Q(e,HG),{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Q(e,GG));i=IJ(e);let a=iJ(i,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],[]),o=zq(BX(t));({isoDate:n,time:r}=sJ(i,a,o))}else{let a,o,s,c;if({year:o,month:s,day:c,time:r,calendar:i,z:a}=Eq(aq(e)),a)throw RangeError(`Z designator not supported for PlainDateTime`);r===`start-of-day`&&(r={deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),zY(o,s,c,r.hour,r.minute,r.second,r.millisecond,r.microsecond,r.nanosecond),i||=`iso8601`,i=UX(i),zq(BX(t)),n={year:o,month:s,day:c}}return bJ(Rq(n,r),i)}function lJ(e){let t=OK(`%Temporal.Duration%`);if(gq(e))return new t(Q(e,XG),Q(e,ZG),Q(e,QG),Q(e,$G),Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK),Q(e,aK));if(!QK(e))return function(e){let{years:t,months:n,weeks:r,days:i,hours:a,minutes:o,seconds:s,milliseconds:c,microseconds:l,nanoseconds:u}=function(e){let t=Rve.exec(e);if(!t||t.every(((e,t)=>t<2||e===void 0)))throw RangeError(`invalid duration: ${e}`);let n=t[1]===`-`?-1:1,r=t[2]===void 0?0:tq(t[2])*n,i=t[3]===void 0?0:tq(t[3])*n,a=t[4]===void 0?0:tq(t[4])*n,o=t[5]===void 0?0:tq(t[5])*n,s=t[6]===void 0?0:tq(t[6])*n,c=t[7],l=t[8],u=t[9],d=t[10],f=t[11],p=0,m=0,h=0;if(c!==void 0){if(l??u??d??f)throw RangeError(`only the smallest unit can be fractional`);h=3600*tq((c+`000000000`).slice(0,9))*n}else if(p=l===void 0?0:tq(l)*n,u!==void 0){if(d??f)throw RangeError(`only the smallest unit can be fractional`);h=60*tq((u+`000000000`).slice(0,9))*n}else m=d===void 0?0:tq(d)*n,f!==void 0&&(h=tq((f+`000000000`).slice(0,9))*n);let g=h%1e3,_=Math.trunc(h/1e3)%1e3,v=Math.trunc(h/1e6)%1e3;return m+=Math.trunc(h/1e9)%60,p+=Math.trunc(h/6e10),WY(r,i,a,o,s,p,m,v,_,g),{years:r,months:i,weeks:a,days:o,hours:s,minutes:p,seconds:m,milliseconds:v,microseconds:_,nanoseconds:g}}(e);return new(OK(`%Temporal.Duration%`))(t,n,r,i,a,o,s,c,l,u)}(aq(e));let n={years:0,months:0,weeks:0,days:0,hours:0,minutes:0,seconds:0,milliseconds:0,microseconds:0,nanoseconds:0},r=Iq(e);for(let e=0;e<fq.length;e++){let t=fq[e],i=r[t];i!==void 0&&(n[t]=i)}return new t(n.years,n.months,n.weeks,n.days,n.hours,n.minutes,n.seconds,n.milliseconds,n.microseconds,n.nanoseconds)}function uJ(e){let t;if(QK(e)){if(hq(e)||Sq(e))return OJ(Q(e,VG));t=oq(e)}else t=e;let{year:n,month:r,day:i,time:a,offset:o,z:s}=function(e){let t=Eq(e);if(!t.z&&!t.offset)throw RangeError(`Temporal.Instant requires a time zone offset`);return t}(aq(t)),{hour:c=0,minute:l=0,second:u=0,millisecond:d=0,microsecond:f=0,nanosecond:p=0}=a===`start-of-day`?{}:a,m=kY(n,r,i,c,l,u,d,f,p-(s?0:lY(o)));return ZY(m.isoDate),OJ(_Y(m))}function dJ(e,t){if(QK(e)){if(xq(e))return zq(BX(t)),SJ(Q(e,HG),Q(e,GG));let n;return CK(e,GG)?n=Q(e,GG):(n=e.calendar,n===void 0&&(n=`iso8601`),n=FJ(n)),SJ(BJ(n,iJ(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),zq(BX(t))),n)}let{month:n,day:r,referenceISOYear:i,calendar:a}=kq(aq(e));if(a===void 0&&(a=`iso8601`),a=UX(a),zq(BX(t)),a===`iso8601`)return SJ({year:1972,month:n,day:r},a);let o={year:i,month:n,day:r};return LY(o),o=BJ(a,rJ(a,o,`month-day`),`constrain`),SJ(o,a)}function fJ(e,t){let n;if(QK(e)){if(vq(e))return zq(BX(t)),wJ(Q(e,WG));if(yq(e))return zq(BX(t)),wJ(Q(e,UG).time);if(Sq(e)){let n=GJ(Q(e,YG),Q(e,VG));return zq(BX(t)),wJ(n.time)}let{hour:r,minute:i,second:a,millisecond:o,microsecond:s,nanosecond:c}=aJ(e);n=Fq(r,i,a,o,s,c,zq(BX(t)))}else n=Dq(aq(e)),zq(BX(t));return wJ(n)}function pJ(e){return e===void 0?{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}:Q(fJ(e),WG)}function mJ(e,t){if(QK(e)){if(bq(e))return zq(BX(t)),EJ(Q(e,HG),Q(e,GG));let n=IJ(e);return EJ(zJ(n,iJ(n,e,[`year`,`month`,`monthCode`],[],[]),zq(BX(t))),n)}let{year:n,month:r,referenceISODay:i,calendar:a}=Oq(aq(e));a===void 0&&(a=`iso8601`),a=UX(a),zq(BX(t));let o={year:n,month:r,day:i};return UY(o),o=zJ(a,rJ(a,o,`year-month`),`constrain`),EJ(o,a)}function hJ(e,t,n,r,i,a,o,s){if(t===`start-of-day`)return YJ(i,e);let c=Rq(e,t);if(n===`wall`||o===`ignore`)return KJ(i,c,a);if(n===`exact`||o===`use`){let n=kY(e.year,e.month,e.day,t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond-r);ZY(n.isoDate);let i=_Y(n);return HY(i),i}ZY(e);let l=_Y(c),u=JJ(i,c);for(let e=0;e<u.length;e++){let t=u[e],n=Z.default.toNumber(Z.default.subtract(l,t)),i=wX(n,6e10,`halfExpand`);if(n===r||s&&i===r)return t}if(o===`reject`){let e=WJ(r),t=iY(c,`iso8601`,`auto`);throw RangeError(`Offset ${e} is invalid for ${t} in ${i}`)}return qJ(u,i,c,a)}function gJ(e,t){let n,r,i,a,o,s,c,l=!1,u=`option`;if(QK(e)){if(Sq(e)){let n=BX(t);return Bq(n),Hq(n,`reject`),zq(n),AJ(Q(e,VG),Q(e,YG),Q(e,GG))}o=IJ(e);let l=iJ(o,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],[`timeZone`]);({offset:a,timeZone:i}=l),a===void 0&&(u=`wall`);let d=BX(t);s=Bq(d),c=Hq(d,`reject`);let f=zq(d);({isoDate:n,time:r}=sJ(o,l,f))}else{let d,f,p,m,h;({year:p,month:m,day:h,time:r,tzAnnotation:d,offset:a,z:f,calendar:o}=function(e){let t=Eq(e);if(!t.tzAnnotation)throw RangeError(`Temporal.ZonedDateTime requires a time zone ID in brackets`);return t}(aq(e))),i=VJ(d),f?u=`exact`:a||(u=`wall`),o||=`iso8601`,o=UX(o),l=!0;let g=BX(t);s=Bq(g),c=Hq(g,`reject`),zq(g),n={year:p,month:m,day:h}}let d=0;return u===`option`&&(d=lY(a)),AJ(hJ(n,r,u,d,i,s,c,l),i,o)}function _J(e,t,n){LY(t),SK(e),wK(e,HG,t),wK(e,GG,n),wK(e,KG,!0)}function vJ(e,t){let n=OK(`%Temporal.PlainDate%`),r=Object.create(n.prototype);return _J(r,e,t),r}function yJ(e,t,n){BY(t),SK(e),wK(e,UG,t),wK(e,GG,n)}function bJ(e,t){let n=OK(`%Temporal.PlainDateTime%`),r=Object.create(n.prototype);return yJ(r,e,t),r}function xJ(e,t,n){LY(t),SK(e),wK(e,HG,t),wK(e,GG,n),wK(e,JG,!0)}function SJ(e,t){let n=OK(`%Temporal.PlainMonthDay%`),r=Object.create(n.prototype);return xJ(r,e,t),r}function CJ(e,t){SK(e),wK(e,WG,t)}function wJ(e){let t=OK(`%Temporal.PlainTime%`),n=Object.create(t.prototype);return CJ(n,e),n}function TJ(e,t,n){UY(t),SK(e),wK(e,HG,t),wK(e,GG,n),wK(e,qG,!0)}function EJ(e,t){let n=OK(`%Temporal.PlainYearMonth%`),r=Object.create(n.prototype);return TJ(r,e,t),r}function DJ(e,t){HY(t),SK(e),wK(e,VG,t)}function OJ(e){let t=OK(`%Temporal.Instant%`),n=Object.create(t.prototype);return DJ(n,e),n}function kJ(e,t,n,r){HY(t),SK(e),wK(e,VG,t),wK(e,YG,n),wK(e,GG,r)}function AJ(e,t,n=`iso8601`){let r=OK(`%Temporal.ZonedDateTime%`),i=Object.create(r.prototype);return kJ(i,e,t,n),i}function jJ(e){return sq.filter((t=>e[t]!==void 0))}function MJ(e,t,n){let r=jJ(n),i=tJ(e).fieldKeysToIgnore(r),a=Object.create(null),o=jJ(t);for(let e=0;e<sq.length;e++){let s,c=sq[e];o.includes(c)&&!i.includes(c)&&(s=t[c]),r.includes(c)&&(s=n[c]),s!==void 0&&(a[c]=s)}return a}function NJ(e,t,n,r){let i=tJ(e).dateAdd(t,n,r);return LY(i),i}function PJ(e,t,n,r){return tJ(e).dateUntil(t,n,r)}function FJ(e){if(QK(e)&&CK(e,GG))return Q(e,GG);let t=aq(e);try{return UX(t)}catch{}let n;try{({calendar:n}=Eq(t))}catch{try{({calendar:n}=Dq(t))}catch{try{({calendar:n}=Oq(t))}catch{({calendar:n}=kq(t))}}}return n||=`iso8601`,UX(n)}function IJ(e){if(CK(e,GG))return Q(e,GG);let{calendar:t}=e;return t===void 0?`iso8601`:FJ(t)}function LJ(e,t){return UX(e)===UX(t)}function RJ(e,t,n){let r=tJ(e);r.resolveFields(t,`date`);let i=r.dateToISO(t,n);return LY(i),i}function zJ(e,t,n){let r=tJ(e);r.resolveFields(t,`year-month`),t.day=1;let i=r.dateToISO(t,n);return UY(i),i}function BJ(e,t,n){let r=tJ(e);r.resolveFields(t,`month-day`);let i=r.monthDayToISOReferenceDate(t,n);return LY(i),i}function VJ(e){if(QK(e)&&Sq(e))return Q(e,YG);let t=aq(e);if(t===`UTC`)return`UTC`;let{tzName:n,offsetMinutes:r}=function(e){let{tzAnnotation:t,offset:n,z:r}=function(e){if(Aq.test(e))return{tzAnnotation:e,offset:void 0,z:!1};try{let{tzAnnotation:t,offset:n,z:r}=Eq(e);if(r||t||n)return{tzAnnotation:t,offset:n,z:r}}catch{}Mq(e)}(e);return t?Nq(t):r?Nq(`UTC`):n?Nq(n):void 0}(t);if(r!==void 0)return mY(r);let i=dY(n);if(!i)throw RangeError(`Unrecognized time zone ${n}`);return i.identifier}function HJ(e,t){if(e===t)return!0;let n=Nq(e).offsetMinutes,r=Nq(t).offsetMinutes;if(n===void 0&&r===void 0){let n=dY(t);if(!n)return!1;let r=dY(e);return!!r&&r.primaryIdentifier===n.primaryIdentifier}return n===r}function UJ(e,t){let n=Nq(e).offsetMinutes;return n===void 0?pY(e,t):6e10*n}function WJ(e){let t=e<0?`-`:`+`,n=Math.abs(e),r=Math.floor(n/36e11),i=Math.floor(n/6e10)%60,a=Math.floor(n/1e9)%60,o=n%1e9;return`${t}${$J(r,i,a,o,a===0&&o===0?`minute`:`auto`)}`}function GJ(e,t){let n=UJ(e,t),{isoDate:{year:r,month:i,day:a},time:{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d}}=vY(t);return kY(r,i,a,o,s,c,l,u,d+n)}function KJ(e,t,n){return qJ(JJ(e,t),e,t,n)}function qJ(e,t,n,r){let i=e.length;if(i===1)return e[0];if(i)switch(r){case`compatible`:case`earlier`:return e[0];case`later`:return e[i-1];case`reject`:throw RangeError(`multiple instants found`)}if(r===`reject`)throw RangeError(`multiple instants found`);let a=_Y(n),o=Z.default.subtract(a,NG);HY(o);let s=UJ(t,o),c=Z.default.add(a,NG);HY(c);let l=UJ(t,c)-s;switch(r){case`earlier`:{let e=NK.fromComponents(0,0,0,0,0,-l),r=mX(n.time,e);return JJ(t,Rq(OY(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r))[0]}case`compatible`:case`later`:{let e=NK.fromComponents(0,0,0,0,0,l),r=mX(n.time,e),i=JJ(t,Rq(OY(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r));return i[i.length-1]}}}function JJ(e,t){if(e===`UTC`)return ZY(t.isoDate),[_Y(t)];let n=Nq(e).offsetMinutes;if(n!==void 0){let e=kY(t.isoDate.year,t.isoDate.month,t.isoDate.day,t.time.hour,t.time.minute-n,t.time.second,t.time.millisecond,t.time.microsecond,t.time.nanosecond);ZY(e.isoDate);let r=_Y(e);return HY(r),[r]}return ZY(t.isoDate),function(e,t){let n=_Y(t),r=Z.default.subtract(n,NG);Z.default.lessThan(r,JK)&&(r=n);let i=Z.default.add(n,NG);Z.default.greaterThan(i,qK)&&(i=n);let a=pY(e,r),o=pY(e,i);return(a===o?[a]:[a,o]).map((r=>{let i=Z.default.subtract(n,Z.default.BigInt(r));if(MX(t,function(e,t){let{epochMilliseconds:n,time:{millisecond:r,microsecond:i,nanosecond:a}}=vY(t),{year:o,month:s,day:c,hour:l,minute:u,second:d}=xY(e,n);return kY(o,s,c,l,u,d,r,i,a)}(e,i))===0)return HY(i),i})).filter((e=>e!==void 0))}(e,t)}function YJ(e,t){let n=Rq(t,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),r=JJ(e,n);if(r.length)return r[0];let i=_Y(n),a=Z.default.subtract(i,NG);return HY(a),yY(e,a)}function XJ(e){let t;return t=e<0||e>9999?(e<0?`-`:`+`)+iq(Math.abs(e),6):iq(e,4),t}function ZJ(e){return iq(e,2)}function QJ(e,t){let n;if(t===`auto`){if(e===0)return``;n=iq(e,9).replace(/0+$/,``)}else{if(t===0)return``;n=iq(e,9).slice(0,t)}return`.${n}`}function $J(e,t,n,r,i){let a=`${ZJ(e)}:${ZJ(t)}`;return i===`minute`||(a+=`:${ZJ(n)}`,a+=QJ(r,i)),a}function eY(e,t,n){let r=t;r===void 0&&(r=`UTC`);let i=Q(e,VG),a=iY(GJ(r,i),`iso8601`,n,`never`),o=`Z`;return t!==void 0&&(o=hY(UJ(r,i))),`${a}${o}`}function tY(e,t){let n=Q(e,XG),r=Q(e,ZG),i=Q(e,QG),a=Q(e,$G),o=Q(e,eK),s=Q(e,tK),c=wY(e),l=``;n!==0&&(l+=`${Math.abs(n)}Y`),r!==0&&(l+=`${Math.abs(r)}M`),i!==0&&(l+=`${Math.abs(i)}W`),a!==0&&(l+=`${Math.abs(a)}D`);let u=``;o!==0&&(u+=`${Math.abs(o)}H`),s!==0&&(u+=`${Math.abs(s)}M`);let d=NK.fromComponents(0,0,Q(e,nK),Q(e,rK),Q(e,iK),Q(e,aK));d.isZero()&&![`second`,`millisecond`,`microsecond`,`nanosecond`].includes(Zq(e))&&t===`auto`||(u+=`${Math.abs(d.sec)}${QJ(Math.abs(d.subsec),t)}S`);let f=`${c<0?`-`:``}P${l}`;return u&&(f=`${f}T${u}`),f}function nY(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,HG);return`${XJ(n)}-${ZJ(r)}-${ZJ(i)}${wq(Q(e,GG),t)}`}function rY({hour:e,minute:t,second:n,millisecond:r,microsecond:i,nanosecond:a},o){return $J(e,t,n,1e6*r+1e3*i+a,o)}function iY(e,t,n,r=`auto`){let{isoDate:{year:i,month:a,day:o},time:{hour:s,minute:c,second:l,millisecond:u,microsecond:d,nanosecond:f}}=e;return`${XJ(i)}-${ZJ(a)}-${ZJ(o)}T${$J(s,c,l,1e6*u+1e3*d+f,n)}${wq(t,r)}`}function aY(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,HG),a=`${ZJ(r)}-${ZJ(i)}`,o=Q(e,GG);t!==`always`&&t!==`critical`&&o===`iso8601`||(a=`${XJ(n)}-${a}`);let s=wq(o,t);return s&&(a+=s),a}function oY(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,HG),a=`${XJ(n)}-${ZJ(r)}`,o=Q(e,GG);t!==`always`&&t!==`critical`&&o===`iso8601`||(a+=`-${ZJ(i)}`);let s=wq(o,t);return s&&(a+=s),a}function sY(e,t,n=`auto`,r=`auto`,i=`auto`,a=void 0){let o=Q(e,VG);if(a){let{unit:e,increment:t,roundingMode:n}=a;o=TX(o,t,e,n)}let s=Q(e,YG),c=UJ(s,o),l=iY(GJ(s,o),`iso8601`,t,`never`);return i!==`never`&&(l+=hY(c)),r!==`never`&&(l+=`[${r===`critical`?`!`:``}${s}]`),l+=wq(Q(e,GG),n),l}function cY(e){return jq.test(e)}function lY(e){let t=Zve.exec(e);if(!t)throw RangeError(`invalid time zone offset: ${e}; must match ±HH:MM[:SS.SSSSSSSSS]`);return(t[1]===`-`?-1:1)*(1e9*(60*(60*t[2]+ +(t[3]||0))+ +(t[4]||0))+ +((t[5]||0)+`000000000`).slice(0,9))}var uY,Yve=Object.assign(Object.create(null),{"/":!0,"-":!0,_:!0});function dY(e){if(uY===void 0){let e=Intl.supportedValuesOf?.(`timeZone`);if(e){uY=new Map;for(let t=0;t<e.length;t++){let n=e[t];uY.set(WX(n),n)}}else uY=null}let t=WX(e),n=uY?.get(t);if(n)return{identifier:n,primaryIdentifier:n};try{n=mq(e).resolvedOptions().timeZone}catch{return}if(t===`antarctica/south_pole`&&(n=`Antarctica/McMurdo`),Wve.has(e))throw RangeError(`${e} is a legacy time zone identifier from ICU. Use ${n} instead`);let r=[...t].map(((e,n)=>n===0||Yve[t[n-1]]?e.toUpperCase():e)).join(``).split(`/`);if(r.length===1)return t===`gb-eire`?{identifier:`GB-Eire`,primaryIdentifier:n}:{identifier:t.length<=3||/[-0-9]/.test(t)?t.toUpperCase():r[0],primaryIdentifier:n};if(r[0]===`Etc`)return{identifier:`Etc/${[`Zulu`,`Greenwich`,`Universal`].includes(r[1])?r[1]:r[1].toUpperCase()}`,primaryIdentifier:n};if(r[0]===`Us`)return{identifier:`US/${r[1]}`,primaryIdentifier:n};let i=new Map([[`Act`,`ACT`],[`Lhi`,`LHI`],[`Nsw`,`NSW`],[`Dar_Es_Salaam`,`Dar_es_Salaam`],[`Port_Of_Spain`,`Port_of_Spain`],[`Port-Au-Prince`,`Port-au-Prince`],[`Isle_Of_Man`,`Isle_of_Man`],[`Comodrivadavia`,`ComodRivadavia`],[`Knox_In`,`Knox_IN`],[`Dumontdurville`,`DumontDUrville`],[`Mcmurdo`,`McMurdo`],[`Denoronha`,`DeNoronha`],[`Easterisland`,`EasterIsland`],[`Bajanorte`,`BajaNorte`],[`Bajasur`,`BajaSur`]]);return r[1]=i.get(r[1])??r[1],r.length>2&&(r[2]=i.get(r[2])??r[2]),{identifier:r.join(`/`),primaryIdentifier:n}}function fY(e,t){let{year:n,month:r,day:i,hour:a,minute:o,second:s}=xY(e,t),c=t%1e3;return c<0&&(c+=1e3),1e6*(gY({isoDate:{year:n,month:r,day:i},time:{hour:a,minute:o,second:s,millisecond:c}})-t)}function pY(e,t){return fY(e,PX(t,`floor`))}function mY(e){let t=e<0?`-`:`+`,n=Math.abs(e);return`${t}${$J(Math.floor(n/60),n%60,0,0,`minute`)}`}function hY(e){return mY(wX(e,zve,`halfExpand`)/6e10)}function gY({isoDate:{year:e,month:t,day:n},time:{hour:r,minute:i,second:a,millisecond:o}}){let s=e%400,c=(e-s)/400,l=new Date;return l.setUTCHours(r,i,a,o),l.setUTCFullYear(s,t-1,n),l.getTime()+Hve*c}function _Y(e){let t=gY(e),n=1e3*e.time.microsecond+e.time.nanosecond;return Z.default.add(FX(t),Z.default.BigInt(n))}function vY(e){let t=PX(e,`trunc`),n=Z.default.toNumber(Z.default.remainder(e,AG));n<0&&(n+=1e6,--t);let r=Math.floor(n/1e3)%1e3,i=n%1e3,a=new Date(t);return{epochMilliseconds:t,isoDate:{year:a.getUTCFullYear(),month:a.getUTCMonth()+1,day:a.getUTCDate()},time:{hour:a.getUTCHours(),minute:a.getUTCMinutes(),second:a.getUTCSeconds(),millisecond:a.getUTCMilliseconds(),microsecond:r,nanosecond:i}}}function yY(e,t){if(e===`UTC`)return null;let n=PX(t,`floor`);if(n<ZK)return yY(e,FX(ZK));let r=Math.max(n,Date.now())+366*WK*3,i=n,a=fY(e,i),o=i,s=a;for(;a===s&&i<r;){if(o=i+2*WK*7,o>KK)return null;s=fY(e,o),a===s&&(i=o)}return a===s?null:FX(KX((t=>fY(e,t)),i,o,a,s))}function bY(e,t){if(e===`UTC`)return null;let n=PX(t,`ceil`),r=Date.now(),i=r+366*WK*3;if(n>i){let t=bY(e,FX(i));if(t===null||Z.default.lessThan(t,FX(r)))return t}if(e===`Africa/Casablanca`||e===`Africa/El_Aaiun`){let t=Date.UTC(2088,0,1);if(t<n)return bY(e,FX(t))}let a=n-1;if(a<ZK)return null;let o=fY(e,a),s=a,c=o;for(;o===c&&a>ZK;){if(s=a-2*WK*7,s<ZK)return null;c=fY(e,s),o===c&&(a=s)}return o===c?null:FX(KX((t=>fY(e,t)),s,a,c,o))}function xY(e,t){return function(e){let t=e.split(/[^\w]+/);if(t.length!==7)throw RangeError(`expected 7 parts in "${e}`);let n=+t[0],r=+t[1],i=+t[2],a=t[3];if(a[0]===`b`||a[0]===`B`)i=1-i;else if(a[0]!==`a`&&a[0]!==`A`)throw RangeError(`Unknown era ${a} in "${e}`);let o=t[4]===`24`?0:+t[4],s=+t[5],c=+t[6];if(!(Number.isFinite(i)&&Number.isFinite(n)&&Number.isFinite(r)&&Number.isFinite(o)&&Number.isFinite(s)&&Number.isFinite(c)))throw RangeError(`Invalid number in "${e}`);return{year:i,month:n,day:r,hour:o,minute:s,second:c}}(mq(e).format(t))}function SY(e){return e!==void 0&&!(e%4!=0||e%100==0&&e%400!=0)}function CY(e,t){return{standard:[31,28,31,30,31,30,31,31,30,31,30,31],leapyear:[31,29,31,30,31,30,31,31,30,31,30,31]}[SY(e)?`leapyear`:`standard`][t-1]}function wY(e){let t=[Q(e,XG),Q(e,ZG),Q(e,QG),Q(e,$G),Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK),Q(e,aK)];for(let e=0;e<t.length;e++){let n=t[e];if(n!==0)return n<0?-1:1}return 0}function TY(e){let t=[`years`,`months`,`weeks`,`days`];for(let n=0;n<t.length;n++){let r=e[t[n]];if(r!==0)return r<0?-1:1}return 0}function EY(e){let t=TY(e.date);return t===0?e.time.sign():t}function DY(e,t){let n=e,r=t;if(!Number.isFinite(n)||!Number.isFinite(r))throw RangeError(`infinity is out of range`);return--r,n+=Math.floor(r/12),r%=12,r<0&&(r+=12),r+=1,{year:n,month:r}}function OY(e,t,n){let r=e,i=t,a=n;if(!Number.isFinite(a))throw RangeError(`infinity is out of range`);({year:r,month:i}=DY(r,i));let o=146097;if(Math.abs(a)>o){let e=Math.trunc(a/o);r+=400*e,a-=e*o}let s=0,c=i>2?r:r-1;for(;s=SY(c)?366:365,a<-s;)--r,--c,a+=s;for(c+=1;s=SY(c)?366:365,a>s;)r+=1,c+=1,a-=s;for(;a<1;)({year:r,month:i}=DY(r,i-1)),a+=CY(r,i);for(;a>CY(r,i);)a-=CY(r,i),{year:r,month:i}=DY(r,i+1);return{year:r,month:i,day:a}}function kY(e,t,n,r,i,a,o,s,c){let l=AY(r,i,a,o,s,c);return Rq(OY(e,t,n+l.deltaDays),l)}function AY(e,t,n,r,i,a){let o,s=e,c=t,l=n,u=r,d=i,f=a;({div:o,mod:f}=kK(f,3)),d+=o,f<0&&(--d,f+=1e3),{div:o,mod:d}=kK(d,3),u+=o,d<0&&(--u,d+=1e3),l+=Math.trunc(u/1e3),u%=1e3,u<0&&(--l,u+=1e3),c+=Math.trunc(l/60),l%=60,l<0&&(--c,l+=60),s+=Math.trunc(c/60),c%=60,c<0&&(--s,c+=60);let p=Math.trunc(s/24);return s%=24,s<0&&(--p,s+=24),p+=0,s+=0,c+=0,l+=0,u+=0,d+=0,f+=0,{deltaDays:p,hour:s,minute:c,second:l,millisecond:u,microsecond:d,nanosecond:f}}function jY(e,t){let n=Lq(e,0);if(TY(n)===0)return e.days;let r=Q(t,HG),i=NJ(Q(t,GG),r,n,`constrain`),a=XY(r.year,r.month-1,r.day),o=XY(i.year,i.month-1,i.day)-a;return e.days+o}function MY(e){return new(OK(`%Temporal.Duration%`))(-Q(e,XG),-Q(e,ZG),-Q(e,QG),-Q(e,$G),-Q(e,eK),-Q(e,tK),-Q(e,nK),-Q(e,rK),-Q(e,iK),-Q(e,aK))}function NY(e,t,n){return Math.min(n,Math.max(t,e))}function PY(e,t,n){let r=NY(t,1,12);return{year:e,month:r,day:NY(n,1,CY(e,r))}}function FY(e,t,n){if(e<t||e>n)throw RangeError(`value out of range: ${t} <= ${e} <= ${n}`)}function IY(e,t,n){FY(t,1,12),FY(n,1,CY(e,t))}function LY(e){BY(Rq(e,{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}))}function RY(e,t,n,r,i,a){FY(e,0,23),FY(t,0,59),FY(n,0,59),FY(r,0,999),FY(i,0,999),FY(a,0,999)}function zY(e,t,n,r,i,a,o,s,c){IY(e,t,n),RY(r,i,a,o,s,c)}function BY(e){let t=_Y(e);(Z.default.lessThan(t,Bve)||Z.default.greaterThan(t,Vve))&&HY(t)}function VY(e){_Y(e)}function HY(e){if(Z.default.lessThan(e,JK)||Z.default.greaterThan(e,qK))throw RangeError(`date/time value is outside of supported range`)}function UY({year:e,month:t}){FY(e,YK,XK),e===YK?FY(t,4,12):e===XK&&FY(t,1,9)}function WY(e,t,n,r,i,a,o,s,c,l){let u=0,d=[e,t,n,r,i,a,o,s,c,l];for(let e=0;e<d.length;e++){let t=d[e];if(t===1/0||t===-1/0)throw RangeError(`infinite values not allowed as duration fields`);if(t!==0){let e=t<0?-1:1;if(u!==0&&e!==u)throw RangeError(`mixed-sign values not allowed as duration fields`);u=e}}if(Math.abs(e)>=2**32||Math.abs(t)>=2**32||Math.abs(n)>=2**32)throw RangeError(`years, months, and weeks must be < 2³²`);let f=kK(s,3),p=kK(c,6),m=kK(l,9),h=kK(1e6*f.mod+1e3*p.mod+m.mod,9).div,g=86400*r+3600*i+60*a+o+f.div+p.div+m.div+h;if(!Number.isSafeInteger(g))throw RangeError(`total of duration time units cannot exceed 9007199254740991.999999999 s`)}function GY(e){return{date:{years:Q(e,XG),months:Q(e,ZG),weeks:Q(e,QG),days:Q(e,$G)},time:NK.fromComponents(Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK),Q(e,aK))}}function KY(e){let t=NK.fromComponents(Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK),Q(e,aK)).add24HourDays(Q(e,$G));return{date:{years:Q(e,XG),months:Q(e,ZG),weeks:Q(e,QG),days:0},time:t}}function qY(e){let t=KY(e),n=Math.trunc(t.time.sec/86400);return WY(t.date.years,t.date.months,t.date.weeks,n,0,0,0,0,0,0),{...t.date,days:n}}function JY(e,t){let n=e.time.sign(),r=e.time.abs().subsec,i=0,a=0,o=e.time.abs().sec,s=0,c=0,l=0;switch(t){case`year`:case`month`:case`week`:case`day`:i=Math.trunc(r/1e3),r%=1e3,a=Math.trunc(i/1e3),i%=1e3,o+=Math.trunc(a/1e3),a%=1e3,s=Math.trunc(o/60),o%=60,c=Math.trunc(s/60),s%=60,l=Math.trunc(c/24),c%=24;break;case`hour`:i=Math.trunc(r/1e3),r%=1e3,a=Math.trunc(i/1e3),i%=1e3,o+=Math.trunc(a/1e3),a%=1e3,s=Math.trunc(o/60),o%=60,c=Math.trunc(s/60),s%=60;break;case`minute`:i=Math.trunc(r/1e3),r%=1e3,a=Math.trunc(i/1e3),i%=1e3,o+=Math.trunc(a/1e3),a%=1e3,s=Math.trunc(o/60),o%=60;break;case`second`:i=Math.trunc(r/1e3),r%=1e3,a=Math.trunc(i/1e3),i%=1e3,o+=Math.trunc(a/1e3),a%=1e3;break;case`millisecond`:i=Math.trunc(r/1e3),r%=1e3,a=AK(o,3,Math.trunc(i/1e3)),i%=1e3,o=0;break;case`microsecond`:i=AK(o,6,Math.trunc(r/1e3)),r%=1e3,o=0;break;case`nanosecond`:r=AK(o,9,r),o=0}return new(OK(`%Temporal.Duration%`))(e.date.years,e.date.months,e.date.weeks,e.date.days+n*l,n*c,n*s,n*o,n*a,n*i,n*r)}function YY(e,t){return TY(e),t.sign(),{date:e,time:t}}function XY(e,t,n){return gY({isoDate:{year:e,month:t+1,day:n},time:{hour:0,minute:0,second:0,millisecond:0}})/WK}function ZY({year:e,month:t,day:n}){if(Math.abs(XY(e,t-1,n))>1e8)throw RangeError(`date/time value is outside the supported range`)}function QY(e,t){let n=t.hour-e.hour,r=t.minute-e.minute,i=t.second-e.second,a=t.millisecond-e.millisecond,o=t.microsecond-e.microsecond,s=t.nanosecond-e.nanosecond;return NK.fromComponents(n,r,i,a,o,s)}function $Y(e,t,n,r,i){let a=NK.fromEpochNsDiff(t,e);return a=OX(a,n,r,i),YY({years:0,months:0,weeks:0,days:0},a)}function eX(e,t,n,r){VY(e),VY(t);let i=QY(e.time,t.time),a=i.sign(),o=AX(e.isoDate,t.isoDate),s=t.isoDate;o===a&&(s=OY(s.year,s.month,s.day+a),i=i.add24HourDays(-a));let c=Qq(`day`,r),l=PJ(n,e.isoDate,s,c);return r!==c&&(i=i.add24HourDays(l.days),l.days=0),YY(l,i)}function tX(e,t,n,r,i){let a=Z.default.subtract(t,e);if(Z.default.equal(a,DG))return{date:{years:0,months:0,weeks:0,days:0},time:NK.ZERO};let o=Z.default.lessThan(a,DG)?-1:1,s=GJ(n,e),c=GJ(n,t),l,u=0,d=o===1?2:1,f=QY(s.time,c.time);for(f.sign()===-o&&u++;u<=d;u++){l=Rq(OY(c.isoDate.year,c.isoDate.month,c.isoDate.day-u*o),s.time);let e=KJ(n,l,`compatible`);if(f=NK.fromEpochNsDiff(t,e),f.sign()!==-o)break}let p=Qq(`day`,i);return YY(PJ(r,s.isoDate,l.isoDate,p),f)}function nX(e,t,n,r,i,a,o,s,c){let l,u,d,f,p=t;switch(s){case`year`:{let t=wX(p.date.years,o,`trunc`);l=t,u=t+o*e,d={years:l,months:0,weeks:0,days:0},f={...d,years:u};break}case`month`:{let t=wX(p.date.months,o,`trunc`);l=t,u=t+o*e,d=Lq(p.date,0,0,l),f=Lq(p.date,0,0,u);break}case`week`:{let t=Lq(p.date,0,0),n=NJ(a,r.isoDate,t,`constrain`),i=PJ(a,n,OY(n.year,n.month,n.day+p.date.days),`week`),s=wX(p.date.weeks+i.weeks,o,`trunc`);l=s,u=s+o*e,d=Lq(p.date,0,l),f=Lq(p.date,0,u);break}case`day`:{let t=wX(p.date.days,o,`trunc`);l=t,u=t+o*e,d=Lq(p.date,l),f=Lq(p.date,u);break}}let m=NJ(a,r.isoDate,d,`constrain`),h=NJ(a,r.isoDate,f,`constrain`),g,_,v=Rq(m,r.time),y=Rq(h,r.time);i?(g=KJ(i,v,`compatible`),_=KJ(i,y,`compatible`)):(g=_Y(v),_=_Y(y));let b=NK.fromEpochNsDiff(n,g),x=NK.fromEpochNsDiff(_,g),S=jK(c,e<0?`negative`:`positive`),C=b.add(b).abs().subtract(x.abs()).sign(),w=Math.abs(l)/o%2==0,T=b.isZero()?Math.abs(l):b.cmp(x)?MK(Math.abs(l),Math.abs(u),C,w,S):Math.abs(u),E=new NK(Z.default.add(Z.default.multiply(x.totalNs,Z.default.BigInt(l)),Z.default.multiply(b.totalNs,Z.default.BigInt(o*e)))).fdiv(x.totalNs),D=T===Math.abs(u);return p={date:D?f:d,time:NK.ZERO},{nudgeResult:{duration:p,nudgedEpochNs:D?_:g,didExpandCalendarUnit:D},total:E}}function rX(e,t,n,r,i,a,o,s,c){let l=e,u=$q(s)||r&&s===`day`,d=EY(l)<0?-1:1,f;return u?{nudgeResult:f}=nX(d,l,t,n,r,i,o,s,c):f=r?function(e,t,n,r,i,a,o,s){let c=t,l=NJ(i,n.isoDate,c.date,`constrain`),u=Rq(l,n.time),d=Rq(OY(l.year,l.month,l.day+e),n.time),f=KJ(r,u,`compatible`),p=KJ(r,d,`compatible`),m=NK.fromEpochNsDiff(p,f);if(m.sign()!==e)throw RangeError(`time zone returned inconsistent Instants`);let h=Z.default.BigInt(dq[o]*a),g=c.time.round(h,s),_=g.subtract(m),v=_.sign()!==-e,y,b;return v?(y=e,g=_.round(h,s),b=g.addToEpochNs(p)):(y=0,b=g.addToEpochNs(f)),{duration:YY(Lq(c.date,c.date.days+y),g),nudgedEpochNs:b,didExpandCalendarUnit:v}}(d,l,n,r,i,o,s,c):function(e,t,n,r,i,a){let o=e,s=o.time.add24HourDays(o.date.days),c=s.round(Z.default.BigInt(r*dq[i]),a),l=c.subtract(s),{quotient:u}=s.divmod(GK),{quotient:d}=c.divmod(GK),f=Math.sign(d-u)===s.sign(),p=l.addToEpochNs(t),m=0,h=c;return eJ(n)===`date`&&(m=d,h=c.add(NK.fromComponents(24*-d,0,0,0,0,0))),{duration:{date:Lq(o.date,m),time:h},nudgedEpochNs:p,didExpandCalendarUnit:f}}(l,t,a,o,s,c),l=f.duration,f.didExpandCalendarUnit&&s!==`week`&&(l=function(e,t,n,r,i,a,o,s){let c=t;if(s===o)return c;let l=uq.indexOf(o);for(let t=uq.indexOf(s)-1;t>=l;t--){let s=uq[t];if(s===`week`&&o!==`week`)continue;let l;switch(s){case`year`:l={years:c.date.years+e,months:0,weeks:0,days:0};break;case`month`:{let t=c.date.months+e;l=Lq(c.date,0,0,t);break}case`week`:{let t=c.date.weeks+e;l=Lq(c.date,0,t);break}}let u=Rq(NJ(a,r.isoDate,l,`constrain`),r.time),d;if(d=i?KJ(i,u,`compatible`):_Y(u),LG(n,d)===-e)break;c={date:l,time:NK.ZERO}}return c}(d,l,f.nudgedEpochNs,n,r,i,a,Qq(s,`day`))),l}function iX(e,t,n,r,i,a){return $q(a)||r&&a===`day`?nX(EY(e)<0?-1:1,e,t,n,r,i,1,a,`trunc`).total:kX(e.time.add24HourDays(e.date.days),a)}function aX(e,t,n,r,i,a,o){if(MX(e,t)==0)return{date:{years:0,months:0,weeks:0,days:0},time:NK.ZERO};BY(e),BY(t);let s=eX(e,t,n,r);return a===`nanosecond`&&i===1?s:rX(s,_Y(t),e,null,n,r,i,a,o)}function oX(e,t,n,r,i,a,o,s){if(eJ(i)===`time`)return $Y(e,t,a,o,s);let c=tX(e,t,n,r,i);return o===`nanosecond`&&a===1?c:rX(c,t,GJ(n,e),n,r,i,a,o,s)}function sX(e,t,n,r,i,a){let o=cq.reduce(((e,t)=>{let i=t[0],a=t[1],o=t[2];return n!==`datetime`&&o!==n||r.includes(a)||e.push(a,i),e}),[]),s=Yq(t,`largestUnit`,n,`auto`);if(r.includes(s))throw RangeError(`largestUnit must be one of ${o.join(`, `)}, not ${s}`);let c=Wq(t),l=Vq(t,`trunc`);e===`since`&&(l=function(e){switch(e){case`ceil`:return`floor`;case`floor`:return`ceil`;case`halfCeil`:return`halfFloor`;case`halfFloor`:return`halfCeil`;default:return e}}(l));let u=Yq(t,`smallestUnit`,n,i);if(r.includes(u))throw RangeError(`smallestUnit must be one of ${o.join(`, `)}, not ${u}`);let d=Qq(a,u);if(s===`auto`&&(s=d),Qq(s,u)!==s)throw RangeError(`largestUnit ${s} cannot be smaller than smallestUnit ${u}`);let f={hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[u];return f!==void 0&&Gq(c,f,!1),{largestUnit:s,roundingIncrement:c,roundingMode:l,smallestUnit:u}}function cX(e,t,n,r){let i=uJ(n),a=sX(e,BX(r),`time`,[],`nanosecond`,`second`),o=JY($Y(Q(t,VG),Q(i,VG),a.roundingIncrement,a.smallestUnit,a.roundingMode),a.largestUnit);return e===`since`&&(o=MY(o)),o}function lX(e,t,n,r){let i=oJ(n),a=Q(t,GG),o=Q(i,GG);if(!LJ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=sX(e,BX(r),`date`,[],`day`,`day`),c=OK(`%Temporal.Duration%`),l=Q(t,HG),u=Q(i,HG);if(AX(l,u)===0)return new c;let d={date:PJ(a,l,u,s.largestUnit),time:NK.ZERO};if(s.smallestUnit!==`day`||s.roundingIncrement!==1){let e=Rq(l,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});d=rX(d,_Y(Rq(u,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0})),e,null,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode)}let f=JY(d,`day`);return e===`since`&&(f=MY(f)),f}function uX(e,t,n,r){let i=cJ(n),a=Q(t,GG),o=Q(i,GG);if(!LJ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=sX(e,BX(r),`datetime`,[],`nanosecond`,`day`),c=OK(`%Temporal.Duration%`),l=Q(t,UG),u=Q(i,UG);if(MX(l,u)===0)return new c;let d=JY(aX(l,u,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);return e===`since`&&(d=MY(d)),d}function dX(e,t,n,r){let i=fJ(n),a=sX(e,BX(r),`time`,[],`nanosecond`,`hour`),o=QY(Q(t,WG),Q(i,WG));o=OX(o,a.roundingIncrement,a.smallestUnit,a.roundingMode);let s=JY(YY({years:0,months:0,weeks:0,days:0},o),a.largestUnit);return e===`since`&&(s=MY(s)),s}function fX(e,t,n,r){let i=mJ(n),a=Q(t,GG),o=Q(i,GG);if(!LJ(a,o))throw RangeError(`cannot compute difference between months of ${a} and ${o} calendars`);let s=sX(e,BX(r),`date`,[`week`,`day`],`month`,`year`),c=OK(`%Temporal.Duration%`);if(AX(Q(t,HG),Q(i,HG))==0)return new c;let l=rJ(a,Q(t,HG),`year-month`);l.day=1;let u=RJ(a,l,`constrain`),d=rJ(a,Q(i,HG),`year-month`);d.day=1;let f=RJ(a,d,`constrain`),p={date:Lq(PJ(a,u,f,s.largestUnit),0,0),time:NK.ZERO};if(s.smallestUnit!==`month`||s.roundingIncrement!==1){let e=Rq(u,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});p=rX(p,_Y(Rq(f,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0})),e,null,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode)}let m=JY(p,`day`);return e===`since`&&(m=MY(m)),m}function pX(e,t,n,r){let i=gJ(n),a=Q(t,GG),o=Q(i,GG);if(!LJ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=sX(e,BX(r),`datetime`,[],`nanosecond`,`hour`),c=Q(t,VG),l=Q(i,VG),u=OK(`%Temporal.Duration%`),d;if(eJ(s.largestUnit)!==`date`)d=JY($Y(c,l,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);else{let e=Q(t,YG);if(!HJ(e,Q(i,YG)))throw RangeError(`When calculating difference between time zones, largestUnit must be 'hours' or smaller because day lengths can vary between time zones due to DST or time zone offset changes.`);if(Z.default.equal(c,l))return new u;d=JY(oX(c,l,e,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),`hour`)}return e===`since`&&(d=MY(d)),d}function mX({hour:e,minute:t,second:n,millisecond:r,microsecond:i,nanosecond:a},o){let s=n,c=a;return s+=o.sec,c+=o.subsec,AY(e,t,s,r,i,c)}function hX(e,t){let n=t.addToEpochNs(e);return HY(n),n}function gX(e,t,n,r,i=`constrain`){if(TY(r.date)===0)return hX(e,r.time);let a=GJ(t,e);return hX(KJ(t,Rq(NJ(n,a.isoDate,r.date,i),a.time),`compatible`),r.time)}function _X(e,t,n){let r=lJ(n);e===`subtract`&&(r=MY(r));let i=Qq(Zq(t),Zq(r));if($q(i))throw RangeError(`For years, months, or weeks arithmetic, use date arithmetic relative to a starting point`);let a=KY(t),o=KY(r);return JY(YY({years:0,months:0,weeks:0,days:0},a.time.add(o.time)),i)}function vX(e,t,n){let r=lJ(n);e===`subtract`&&(r=MY(r));let i=Zq(r);if(eJ(i)===`date`)throw RangeError(`Duration field ${i} not supported by Temporal.Instant. Try Temporal.ZonedDateTime instead.`);let a=KY(r);return OJ(hX(Q(t,VG),a.time))}function yX(e,t,n,r){let i=Q(t,GG),a=lJ(n);e===`subtract`&&(a=MY(a));let o=qY(a),s=zq(BX(r));return vJ(NJ(i,Q(t,HG),o,s),i)}function bX(e,t,n,r){let i=lJ(n);e===`subtract`&&(i=MY(i));let a=zq(BX(r)),o=Q(t,GG),s=KY(i),c=Q(t,UG),l=mX(c.time,s.time),u=Lq(s.date,l.deltaDays);return WY(u.years,u.months,u.weeks,u.days,0,0,0,0,0,0),bJ(Rq(NJ(o,c.isoDate,u,a),l),o)}function xX(e,t,n){let r=lJ(n);e===`subtract`&&(r=MY(r));let i=KY(r),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=mX(Q(t,WG),i.time);return wJ(Fq(a,o,s,c,l,u,`reject`))}function SX(e,t,n,r){let i=lJ(n);e===`subtract`&&(i=MY(i));let a=zq(BX(r)),o=wY(i),s=Q(t,GG),c=rJ(s,Q(t,HG),`year-month`);c.day=1;let l=RJ(s,c,`constrain`);if(o<0){let e=NJ(s,l,{months:1},`constrain`);l=OY(e.year,e.month,e.day-1)}let u=qY(i);return LY(l),EJ(zJ(s,rJ(s,NJ(s,l,u,a),`year-month`),a),s)}function CX(e,t,n,r){let i=lJ(n);e===`subtract`&&(i=MY(i));let a=zq(BX(r)),o=Q(t,YG),s=Q(t,GG),c=GY(i);return AJ(gX(Q(t,VG),o,s,c,a),o,s)}function wX(e,t,n){let r=Math.trunc(e/t),i=e%t,a=e<0?`negative`:`positive`,o=Math.abs(r),s=o+1,c=zX(Math.abs(2*i)-t),l=o%2==0,u=jK(n,a),d=i===0?o:MK(o,s,c,l,u);return t*(a===`positive`?d:-d)}function TX(e,t,n,r){let i=dq[n]*t;return function(e,t,n){let r=PG(e),i=PG(t),a=Z.default.divide(r,i),o=Z.default.remainder(r,i),s=jK(n,`positive`),c,l;Z.default.lessThan(r,DG)?(c=Z.default.subtract(a,OG),l=a):(c=a,l=Z.default.add(a,OG));let u=LG(IG(Z.default.multiply(o,kG)),i)*(Z.default.lessThan(r,DG)?-1:1)+0,d=Z.default.equal(o,DG)?a:MK(c,l,u,FG(c),s);return Z.default.multiply(d,i)}(e,Z.default.BigInt(i),r)}function EX(e,t,n,r){VY(e);let{year:i,month:a,day:o}=e.isoDate,s=DX(e.time,t,n,r);return Rq(OY(i,a,o+s.deltaDays),s)}function DX({hour:e,minute:t,second:n,millisecond:r,microsecond:i,nanosecond:a},o,s,c){let l;switch(s){case`day`:case`hour`:l=1e3*(1e3*(1e3*(60*(60*e+t)+n)+r)+i)+a;break;case`minute`:l=1e3*(1e3*(1e3*(60*t+n)+r)+i)+a;break;case`second`:l=1e3*(1e3*(1e3*n+r)+i)+a;break;case`millisecond`:l=1e3*(1e3*r+i)+a;break;case`microsecond`:l=1e3*i+a;break;case`nanosecond`:l=a}let u=dq[s],d=wX(l,u*o,c)/u;switch(s){case`day`:return{deltaDays:d,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0};case`hour`:return AY(d,0,0,0,0,0);case`minute`:return AY(e,d,0,0,0,0);case`second`:return AY(e,t,d,0,0,0);case`millisecond`:return AY(e,t,n,d,0,0);case`microsecond`:return AY(e,t,n,r,d,0);case`nanosecond`:return AY(e,t,n,r,i,d);default:throw Error(`Invalid unit ${s}`)}}function OX(e,t,n,r){let i=dq[n];return e.round(Z.default.BigInt(i*t),r)}function kX(e,t){let n=dq[t];return e.fdiv(Z.default.BigInt(n))}function AX(e,t){return e.year===t.year?e.month===t.month?e.day===t.day?0:zX(e.day-t.day):zX(e.month-t.month):zX(e.year-t.year)}function jX(e,t){return e.hour===t.hour?e.minute===t.minute?e.second===t.second?e.millisecond===t.millisecond?e.microsecond===t.microsecond?e.nanosecond===t.nanosecond?0:zX(e.nanosecond-t.nanosecond):zX(e.microsecond-t.microsecond):zX(e.millisecond-t.millisecond):zX(e.second-t.second):zX(e.minute-t.minute):zX(e.hour-t.hour)}function MX(e,t){let n=AX(e.isoDate,t.isoDate);return n===0?jX(e.time,t.time):n}function NX(e){let t=IX(e);return globalThis.BigInt===void 0?t:globalThis.BigInt(t.toString(10))}function PX(e,t){let{quotient:n,remainder:r}=RG(PG(e),AG),i=Z.default.toNumber(n);return t===`floor`&&Z.default.toNumber(r)<0&&--i,t===`ceil`&&Z.default.toNumber(r)>0&&(i+=1),i}function FX(e){if(!Number.isInteger(e))throw RangeError(`epoch milliseconds must be an integer`);return Z.default.multiply(Z.default.BigInt(e),AG)}function IX(e){let t=e;if(typeof e==`object`){let n=e[Symbol.toPrimitive];n&&typeof n==`function`&&(t=n.call(e,`number`))}if(typeof t==`number`)throw TypeError(`cannot convert number to bigint`);return typeof t==`bigint`?Z.default.BigInt(t.toString(10)):Z.default.BigInt(t)}var LX=(()=>{let e=Z.default.BigInt(Date.now()%1e6);return()=>{let t=Date.now(),n=Z.default.BigInt(t),r=Z.default.add(FX(t),e);return e=Z.default.remainder(n,AG),Z.default.greaterThan(r,qK)?qK:Z.default.lessThan(r,JK)?JK:r}})();function RX(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}function zX(e){return e<0?-1:e>0?1:e}function BX(e){if(e===void 0)return Object.create(null);if(QK(e)&&e!==null)return e;throw TypeError(`Options parameter must be an object, not `+(e===null?`null`:typeof e))}function VX(e,t){let n=Object.create(null);return n[e]=t,n}function HX(e,t,n,r){let i=e[t];if(i!==void 0){if(i=eq(i),!n.includes(i))throw RangeError(`${t} must be one of ${n.join(`, `)}, not ${i}`);return i}if(r===Jq)throw RangeError(`${t} option is required`);return r}function UX(e){let t=WX(e);if(!Uve.includes(WX(t)))throw RangeError(`invalid calendar identifier ${t}`);switch(t){case`ethiopic-amete-alem`:return`ethioaa`;case`islamicc`:return`islamic-civil`}return t}function WX(e){let t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t+=r>=65&&r<=90?String.fromCharCode(r+32):String.fromCharCode(r)}return t}function GX(e){throw TypeError(`Do not use built-in arithmetic operators with Temporal objects. When comparing, use ${e===`PlainMonthDay`?`Temporal.PlainDate.compare(obj1.toPlainDate(year), obj2.toPlainDate(year))`:`Temporal.${e}.compare(obj1, obj2)`}, not obj1 > obj2. When coercing to strings, use \`\${obj}\` or String(obj), not '' + obj. When coercing to numbers, use properties or methods of the object, not \`+obj\`. When concatenating with strings, use \`\${str}\${obj}\` or str.concat(obj), not str + obj. In React, coerce to a string before rendering a Temporal object.`)}var Xve=RegExp(`^${BK.source}$`),Zve=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])(?::?([0-5][0-9])(?:[.,](\\d{1,9}))?)?)?$`);function KX(e,t,n,r=e(t),i=e(n)){let a=t,o=n,s=r,c=i;for(;o-a>1;){let t=Math.trunc((a+o)/2),n=e(t);n===s?(a=t,s=n):n===c&&(o=t,c=n)}return o}function qX(e){return[...e]}function JX(e,t){if(e!==`gregory`&&e!==`iso8601`)return;let n=XX[e],r=t.year,{dayOfWeek:i,dayOfYear:a,daysInYear:o}=n.isoToDate(t,{dayOfWeek:!0,dayOfYear:!0,daysInYear:!0}),s=n.getFirstDayOfWeek(),c=n.getMinimalDaysInFirstWeek(),l=(i+7-s)%7,u=(i-a+7001-s)%7,d=Math.floor((a-1+u)/7);if(7-u>=c&&++d,d==0)d=function(e,t,n,r){let i=(r-e-n+1)%7;i<0&&(i+=7);let a=Math.floor((n+i-1)/7);return 7-i>=t&&++a,a}(s,c,a+n.isoToDate(n.dateAdd(t,{years:-1},`constrain`),{daysInYear:!0}).daysInYear,i),r--;else if(a>=o-5){let e=(l+o-a)%7;e<0&&(e+=7),6-e>=c&&a+7-l>o&&(d=1,r++)}return{week:d,year:r}}function YX(e,t,n,r,i){if(t!==i.year){if(e*(t-i.year)>0)return!0}else if(n!==i.month){if(e*(n-i.month)>0)return!0}else if(r!==i.day&&e*(r-i.day)>0)return!0;return!1}var XX={};function ZX(e){if(!e.startsWith(`M`))throw RangeError(`Invalid month code: ${e}. Month codes must start with M.`);let t=+e.slice(1);if(Number.isNaN(t))throw RangeError(`Invalid month code: ${e}`);return t}function QX(e,t=!1){return`M${`${e}`.padStart(2,`0`)}${t?`L`:``}`}function $X(e,t=void 0,n=12){let{month:r,monthCode:i}=e;if(i===void 0){if(r===void 0)throw TypeError(`Either month or monthCode are required`);t===`reject`&&FY(r,1,n),t===`constrain`&&(r=NY(r,1,n)),i=QX(r)}else{let e=ZX(i);if(i!==QX(e))throw RangeError(`Invalid month code: ${i}`);if(r!==void 0&&r!==e)throw RangeError(`monthCode ${i} and month ${r} must match if both are present`);if(r=e,r<1||r>n)throw RangeError(`Invalid monthCode: ${i}`)}return{...e,month:r,monthCode:i}}XX.iso8601={resolveFields(e,t){if((t===`date`||t===`year-month`)&&e.year===void 0)throw TypeError(`year is required`);if((t===`date`||t===`month-day`)&&e.day===void 0)throw TypeError(`day is required`);Object.assign(e,$X(e))},dateToISO:(e,t)=>Pq(e.year,e.month,e.day,t),monthDayToISOReferenceDate(e,t){let{month:n,day:r}=Pq(e.year??1972,e.month,e.day,t);return{month:n,day:r,year:1972}},extraFields:()=>[],fieldKeysToIgnore(e){let t=new Set;for(let n=0;n<e.length;n++){let r=e[n];t.add(r),r===`month`?t.add(`monthCode`):r===`monthCode`&&t.add(`month`)}return qX(t)},dateAdd(e,{years:t=0,months:n=0,weeks:r=0,days:i=0},a){let{year:o,month:s,day:c}=e;return o+=t,s+=n,{year:o,month:s}=DY(o,s),{year:o,month:s,day:c}=Pq(o,s,c,a),c+=i+7*r,OY(o,s,c)},dateUntil(e,t,n){let r=-AX(e,t);if(r===0)return{years:0,months:0,weeks:0,days:0};let i,a=0,o=0;if(n===`year`||n===`month`){let s=t.year-e.year;for(s!==0&&(s-=r);!YX(r,e.year+s,e.month,e.day,t);)a=s,s+=r;let c=r;for(i=DY(e.year+a,e.month+c);!YX(r,i.year,i.month,e.day,t);)o=c,c+=r,i=DY(i.year,i.month+r);n===`month`&&(o+=12*a,a=0)}i=DY(e.year+a,e.month+o);let s=PY(i.year,i.month,e.day),c=0,l=XY(t.year,t.month-1,t.day)-XY(s.year,s.month-1,s.day);return n===`week`&&(c=Math.trunc(l/7),l%=7),{years:a,months:o,weeks:c,days:l}},isoToDate({year:e,month:t,day:n},r){let i={era:void 0,eraYear:void 0,year:e,month:t,day:n,daysInWeek:7,monthsInYear:12};if(r.monthCode&&(i.monthCode=QX(t)),r.dayOfWeek){let r=t+(t<3?10:-2),a=e-+(t<3),o=Math.floor(a/100),s=a-100*o,c=(n+Math.floor(2.6*r-.2)+(s+Math.floor(s/4))+(Math.floor(o/4)-2*o))%7;i.dayOfWeek=c+(c<=0?7:0)}if(r.dayOfYear){let r=n;for(let n=t-1;n>0;n--)r+=CY(e,n);i.dayOfYear=r}return r.weekOfYear&&(i.weekOfYear=JX(`iso8601`,{year:e,month:t,day:n})),r.daysInMonth&&(i.daysInMonth=CY(e,t)),(r.daysInYear||r.inLeapYear)&&(i.inLeapYear=SY(e),i.daysInYear=i.inLeapYear?366:365),i},getFirstDayOfWeek:()=>1,getMinimalDaysInFirstWeek:()=>4};var eZ=class e{constructor(t){if(this.map=new Map,this.calls=0,this.hits=0,this.misses=0,t!==void 0){let n=0;for(let r of t.map.entries()){if(++n>e.MAX_CACHE_ENTRIES)break;this.map.set(...r)}}}get(e){let t=this.map.get(e);return t&&(this.hits++,this.report()),this.calls++,t}set(e,t){this.map.set(e,t),this.misses++,this.report()}report(){}setObject(t){if(e.objectMap.get(t))throw RangeError(`object already cached`);e.objectMap.set(t,this),this.report()}static getCacheForObject(t){let n=e.objectMap.get(t);return n||(n=new e,e.objectMap.set(t,n)),n}};function tZ({isoYear:e,isoMonth:t,isoDay:n}){return`${XJ(e)}-${ZJ(t)}-${ZJ(n)}T00:00Z`}function nZ(e,t){return{years:e.year-t.year,months:e.month-t.month,days:e.day-t.day}}eZ.objectMap=new WeakMap,eZ.MAX_CACHE_ENTRIES=1e3;var rZ=class{constructor(){this.eras=[],this.hasEra=!1,this.erasBeginMidYear=!1}getFormatter(){return this.formatter===void 0&&(this.formatter=new Intl.DateTimeFormat(`en-US-u-ca-${this.id}`,{day:`numeric`,month:`numeric`,year:`numeric`,era:`short`,timeZone:`UTC`})),this.formatter}getCalendarParts(e){let t=this.getFormatter(),n=new Date(e);if(e===`-271821-04-19T00:00Z`){let e=t.resolvedOptions();t=new Intl.DateTimeFormat(e.locale,{...e,timeZone:`Etc/GMT+1`}),n=new Date(`-271821-04-20T00:00Z`)}try{return t.formatToParts(n)}catch{throw RangeError(`Invalid ISO date: ${e}`)}}isoToCalendarDate(e,t){let{year:n,month:r,day:i}=e,a=JSON.stringify({func:`isoToCalendarDate`,isoYear:n,isoMonth:r,isoDay:i,id:this.id}),o=t.get(a);if(o)return o;let s=tZ({isoYear:n,isoMonth:r,isoDay:i}),c=this.getCalendarParts(s),l={};for(let e=0;e<c.length;e++){let{type:t,value:n}=c[e];if(t!==`year`&&t!==`relatedYear`||(this.hasEra?l.eraYear=+n:l.year=+n),t===`month`){let e=/^([0-9]*)(.*?)$/.exec(n);if(!e||e.length!=3||!e[1]&&!e[2])throw RangeError(`Unexpected month: ${n}`);if(l.month=e[1]?+e[1]:1,l.month<1)throw RangeError(`Invalid month ${n} from ${s}[u-ca-${this.id}] (probably due to https://bugs.chromium.org/p/v8/issues/detail?id=10527)`);if(l.month>13)throw RangeError(`Invalid month ${n} from ${s}[u-ca-${this.id}] (probably due to https://bugs.chromium.org/p/v8/issues/detail?id=10529)`);e[2]&&(l.monthExtra=e[2])}t===`day`&&(l.day=+n),this.hasEra&&t===`era`&&n!=null&&n!==``&&(l.era=n.split(` (`)[0].normalize(`NFD`).replace(/[^-0-9 \p{L}]/gu,``).replace(/ /g,`-`).toLowerCase())}if(this.hasEra&&l.eraYear===void 0)throw RangeError(`Intl.DateTimeFormat.formatToParts lacks relatedYear in ${this.id} calendar. Try Node 14+ or modern browsers.`);if(this.hasEra){let e=this.eras.find((e=>l.era===e.genericName));e&&(l.era=e.code)}if(this.reviseIntlEra){let{era:t,eraYear:n}=this.reviseIntlEra(l,e);l.era=t,l.eraYear=n}this.checkIcuBugs&&this.checkIcuBugs(e);let u=this.adjustCalendarDate(l,t,`constrain`,!0);if(u.year===void 0)throw RangeError(`Missing year converting ${JSON.stringify(e)}`);if(u.month===void 0)throw RangeError(`Missing month converting ${JSON.stringify(e)}`);if(u.day===void 0)throw RangeError(`Missing day converting ${JSON.stringify(e)}`);return t.set(a,u),[`constrain`,`reject`].forEach((n=>{let r=JSON.stringify({func:`calendarToIsoDate`,year:u.year,month:u.month,day:u.day,overflow:n,id:this.id});t.set(r,e)})),u}validateCalendarDate(e){let{month:t,year:n,day:r,eraYear:i,monthCode:a,monthExtra:o}=e;if(o!==void 0)throw RangeError("Unexpected `monthExtra` value");if(n===void 0&&i===void 0)throw TypeError(`year or eraYear is required`);if(t===void 0&&a===void 0)throw TypeError(`month or monthCode is required`);if(r===void 0)throw RangeError(`Missing day`);if(a!==void 0){if(typeof a!=`string`)throw RangeError(`monthCode must be a string, not `+typeof a);if(!/^M([01]?\d)(L?)$/.test(a))throw RangeError(`Invalid monthCode: ${a}`)}if(this.hasEra&&e.era===void 0!=(e.eraYear===void 0))throw TypeError(`properties era and eraYear must be provided together`)}adjustCalendarDate(e,t=void 0,n=`constrain`,r=!1){if(this.calendarType===`lunisolar`)throw RangeError(`Override required for lunisolar calendars`);let i=e;this.validateCalendarDate(i);let a=this.monthsInYear(i,t),{month:o,monthCode:s}=i;return{month:o,monthCode:s}=$X(i,n,a),{...i,month:o,monthCode:s}}regulateMonthDayNaive(e,t,n){let r=this.monthsInYear(e,n),{month:i,day:a}=e;return t===`reject`?(FY(i,1,r),FY(a,1,this.maximumMonthLength(e))):(i=NY(i,1,r),a=NY(a,1,this.maximumMonthLength({...e,month:i}))),{...e,month:i,day:a}}calendarToIsoDate(e,t=`constrain`,n){let r=e,i=this.adjustCalendarDate(e,n,t,!1);i=this.regulateMonthDayNaive(i,t,n);let{year:a,month:o,day:s}=i,c=JSON.stringify({func:`calendarToIsoDate`,year:a,month:o,day:s,overflow:t,id:this.id}),l,u=n.get(c);if(u||r.year!==void 0&&r.month!==void 0&&r.day!==void 0&&(r.year!==i.year||r.month!==i.month||r.day!==i.day)&&(l=JSON.stringify({func:`calendarToIsoDate`,year:r.year,month:r.month,day:r.day,overflow:t,id:this.id}),u=n.get(l),u))return u;let d=this.estimateIsoDate({year:a,month:o,day:s}),f=e=>{let r=this.addDaysIso(d,e);if(i.day>this.minimumMonthLength(i)){let e=this.isoToCalendarDate(r,n);for(;e.month!==o||e.year!==a;){if(t===`reject`)throw RangeError(`day ${s} does not exist in month ${o} of year ${a}`);r=this.addDaysIso(r,-1),e=this.isoToCalendarDate(r,n)}}return r},p=0,m=this.isoToCalendarDate(d,n),h=nZ(i,m);if(h.years!==0||h.months!==0||h.days!==0){let e=365*h.years+30*h.months+h.days;d=this.addDaysIso(d,e),m=this.isoToCalendarDate(d,n),h=nZ(i,m),h.years===0&&h.months===0?d=f(h.days):p=this.compareCalendarDates(i,m)}let g=8;for(;p;){d=this.addDaysIso(d,p*g);let e=m;m=this.isoToCalendarDate(d,n);let a=p;if(p=this.compareCalendarDates(i,m),p){if(h=nZ(i,m),h.years===0&&h.months===0)d=f(h.days),p=0;else if(a&&p!==a){if(g>1)g/=2;else{if(t===`reject`)throw RangeError(`Can't find ISO date from calendar date: ${JSON.stringify({...r})}`);this.compareCalendarDates(m,e)>0&&(d=this.addDaysIso(d,-1)),p=0}}}}if(n.set(c,d),l&&n.set(l,d),i.year===void 0||i.month===void 0||i.day===void 0||i.monthCode===void 0||this.hasEra&&(i.era===void 0||i.eraYear===void 0))throw RangeError(`Unexpected missing property`);return d}compareCalendarDates(e,t){return e.year===t.year?e.month===t.month?e.day===t.day?0:zX(e.day-t.day):zX(e.month-t.month):zX(e.year-t.year)}regulateDate(e,t=`constrain`,n){let r=this.calendarToIsoDate(e,t,n);return this.isoToCalendarDate(r,n)}addDaysIso(e,t){return OY(e.year,e.month,e.day+t)}addDaysCalendar(e,t,n){let r=this.calendarToIsoDate(e,`constrain`,n),i=this.addDaysIso(r,t);return this.isoToCalendarDate(i,n)}addMonthsCalendar(e,t,n,r){let i=e,{day:a}=i;for(let e=0,n=Math.abs(t);e<n;e++){let{month:e}=i,n=i,o=t<0?-Math.max(a,this.daysInPreviousMonth(i,r)):this.daysInMonth(i,r),s=this.calendarToIsoDate(i,`constrain`,r),c=this.addDaysIso(s,o);if(i=this.isoToCalendarDate(c,r),t>0){let t=this.monthsInYear(n,r);for(;i.month-1!=e%t;)c=this.addDaysIso(c,-1),i=this.isoToCalendarDate(c,r)}i.day!==a&&(i=this.regulateDate({...i,day:a},`constrain`,r))}if(n===`reject`&&i.day!==a)throw RangeError(`Day ${a} does not exist in resulting calendar month`);return i}addCalendar(e,{years:t=0,months:n=0,weeks:r=0,days:i=0},a,o){let{year:s,day:c,monthCode:l}=e,u=this.adjustCalendarDate({year:s+t,monthCode:l,day:c},o),d=this.addMonthsCalendar(u,n,a,o),f=i+7*r;return this.addDaysCalendar(d,f,o)}untilCalendar(e,t,n,r){let i=0,a=0,o=0,s=0;switch(n){case`day`:i=this.calendarDaysUntil(e,t,r);break;case`week`:{let n=this.calendarDaysUntil(e,t,r);i=n%7,a=(n-i)/7;break}case`month`:case`year`:{let a=this.compareCalendarDates(t,e);if(!a)return{years:0,months:0,weeks:0,days:0};let c=t.year-e.year,l=t.day-e.day;if(n===`year`&&c){let n=0;t.monthCode>e.monthCode&&(n=1),t.monthCode<e.monthCode&&(n=-1),n||=Math.sign(l),s=n*a<0?c-a:c}let u,d=s?this.addCalendar(e,{years:s},`constrain`,r):e;do o+=a,u=d,d=this.addMonthsCalendar(u,a,`constrain`,r),d.day!==e.day&&(d=this.regulateDate({...d,day:e.day},`constrain`,r));while(this.compareCalendarDates(t,d)*a>=0);o-=a,i=this.calendarDaysUntil(u,t,r);break}}return{years:s,months:o,weeks:a,days:i}}daysInMonth(e,t){let{day:n}=e,r=this.maximumMonthLength(e),i=this.minimumMonthLength(e);if(i===r)return i;let a=n<=r-i?r:i,o=this.calendarToIsoDate(e,`constrain`,t),s=this.addDaysIso(o,a),c=this.isoToCalendarDate(s,t),l=this.addDaysIso(s,-c.day);return this.isoToCalendarDate(l,t).day}daysInPreviousMonth(e,t){let{day:n,month:r,year:i}=e,a={year:r>1?i:i-1,month:r,day:1},o=r>1?r-1:this.monthsInYear(a,t);a={...a,month:o};let s=this.minimumMonthLength(a),c=this.maximumMonthLength(a);if(s===c)return c;let l=this.calendarToIsoDate(e,`constrain`,t),u=this.addDaysIso(l,-n);return this.isoToCalendarDate(u,t).day}startOfCalendarYear(e){return{year:e.year,month:1,monthCode:`M01`,day:1}}startOfCalendarMonth(e){return{year:e.year,month:e.month,day:1}}calendarDaysUntil(e,t,n){let r=this.calendarToIsoDate(e,`constrain`,n),i=this.calendarToIsoDate(t,`constrain`,n);return XY(i.year,i.month-1,i.day)-XY(r.year,r.month-1,r.day)}monthDaySearchStartYear(e,t){return 1972}monthDayFromFields(e,t,n){let r,i,a,o,s,{era:c,eraYear:l,year:u,month:d,monthCode:f,day:p}=e;if(d!==void 0&&u===void 0&&(!this.hasEra||c===void 0||l===void 0))throw TypeError(`when month is present, year (or era and eraYear) are required`);(f===void 0||u!==void 0||this.hasEra&&l!==void 0)&&({monthCode:f,day:p}=this.isoToCalendarDate(this.calendarToIsoDate(e,t,n),n));let m={year:this.monthDaySearchStartYear(f,p),month:12,day:31},h=this.isoToCalendarDate(m,n),g=h.monthCode>f||h.monthCode===f&&h.day>=p?h.year:h.year-1;for(let e=0;e<20;e++){let c=this.adjustCalendarDate({day:p,monthCode:f,year:g-e},n),l=this.calendarToIsoDate(c,`constrain`,n),u=this.isoToCalendarDate(l,n);if({year:r,month:i,day:a}=l,u.monthCode===f&&u.day===p)return{month:i,day:a,year:r};if(t===`constrain`){let e=this.maxLengthOfMonthCodeInAnyYear(u.monthCode);if(u.monthCode===f&&u.day===e&&p>e)return{month:i,day:a,year:r};(o===void 0||u.monthCode===o.monthCode&&u.day>o.day)&&(o=u,s=l)}}if(t===`constrain`&&s!==void 0)return s;throw RangeError(`No recent ${this.id} year with monthCode ${f} and day ${p}`)}getFirstDayOfWeek(){}getMinimalDaysInFirstWeek(){}},Qve=class extends rZ{constructor(){super(...arguments),this.id=`hebrew`,this.calendarType=`lunisolar`,this.months={Tishri:{leap:1,regular:1,monthCode:`M01`,days:30},Heshvan:{leap:2,regular:2,monthCode:`M02`,days:{min:29,max:30}},Kislev:{leap:3,regular:3,monthCode:`M03`,days:{min:29,max:30}},Tevet:{leap:4,regular:4,monthCode:`M04`,days:29},Shevat:{leap:5,regular:5,monthCode:`M05`,days:30},Adar:{leap:void 0,regular:6,monthCode:`M06`,days:29},"Adar I":{leap:6,regular:void 0,monthCode:`M05L`,days:30},"Adar II":{leap:7,regular:void 0,monthCode:`M06`,days:29},Nisan:{leap:8,regular:7,monthCode:`M07`,days:30},Iyar:{leap:9,regular:8,monthCode:`M08`,days:29},Sivan:{leap:10,regular:9,monthCode:`M09`,days:30},Tamuz:{leap:11,regular:10,monthCode:`M10`,days:29},Av:{leap:12,regular:11,monthCode:`M11`,days:30},Elul:{leap:13,regular:12,monthCode:`M12`,days:29}}}inLeapYear(e){let{year:t}=e;return(7*t+1)%19<7}monthsInYear(e){return this.inLeapYear(e)?13:12}minimumMonthLength(e){return this.minMaxMonthLength(e,`min`)}maximumMonthLength(e){return this.minMaxMonthLength(e,`max`)}minMaxMonthLength(e,t){let{month:n,year:r}=e,i=this.getMonthCode(r,n),a=Object.entries(this.months).find((e=>e[1].monthCode===i));if(a===void 0)throw RangeError(`unmatched Hebrew month: ${n}`);let o=a[1].days;return typeof o==`number`?o:o[t]}maxLengthOfMonthCodeInAnyYear(e){return[`M04`,`M06`,`M08`,`M10`,`M12`].includes(e)?29:30}estimateIsoDate(e){let{year:t}=e;return{year:t-3760,month:1,day:1}}getMonthCode(e,t){return this.inLeapYear({year:e})?t===6?QX(5,!0):QX(t<6?t:t-1):QX(t)}adjustCalendarDate(e,t,n=`constrain`,r=!1){let{year:i,month:a,monthCode:o,day:s,monthExtra:c}=e;if(i===void 0)throw TypeError(`Missing property: year`);if(r){if(c){let e=this.months[c];if(!e)throw RangeError(`Unrecognized month from formatToParts: ${c}`);a=this.inLeapYear({year:i})?e.leap:e.regular}return o=this.getMonthCode(i,a),{year:i,month:a,day:s,monthCode:o}}if(this.validateCalendarDate(e),a===void 0){if(o.endsWith(`L`)){if(o!==`M05L`)throw RangeError(`Hebrew leap month must have monthCode M05L, not ${o}`);if(a=6,!this.inLeapYear({year:i})){if(n===`reject`)throw RangeError(`Hebrew monthCode M05L is invalid in year ${i} which is not a leap year`);a=6,o=`M06`}}else{a=ZX(o),this.inLeapYear({year:i})&&a>=6&&a++;let e=this.monthsInYear({year:i});if(a<1||a>e)throw RangeError(`Invalid monthCode: ${o}`)}}else if(n===`reject`?(FY(a,1,this.monthsInYear({year:i})),FY(s,1,this.maximumMonthLength({year:i,month:a}))):(a=NY(a,1,this.monthsInYear({year:i})),s=NY(s,1,this.maximumMonthLength({year:i,month:a}))),o===void 0)o=this.getMonthCode(i,a);else if(this.getMonthCode(i,a)!==o)throw RangeError(`monthCode ${o} doesn't correspond to month ${a} in Hebrew year ${i}`);return{...e,day:s,month:a,monthCode:o,year:i}}},iZ=class extends rZ{constructor(){super(...arguments),this.calendarType=`lunar`,this.DAYS_PER_ISLAMIC_YEAR=354+11/30,this.DAYS_PER_ISO_YEAR=365.2425}inLeapYear(e,t){let n={year:e.year,month:1,monthCode:`M01`,day:1},r={year:e.year+1,month:1,monthCode:`M01`,day:1};return this.calendarDaysUntil(n,r,t)===355}monthsInYear(){return 12}minimumMonthLength(){return 29}maximumMonthLength(){return 30}maxLengthOfMonthCodeInAnyYear(){return 30}estimateIsoDate(e){let{year:t}=this.adjustCalendarDate(e);return{year:Math.floor(t*this.DAYS_PER_ISLAMIC_YEAR/this.DAYS_PER_ISO_YEAR)+622,month:1,day:1}}},$ve=class extends iZ{constructor(){super(...arguments),this.id=`islamic`}},eye=class extends iZ{constructor(){super(...arguments),this.id=`islamic-umalqura`}},tye=class extends iZ{constructor(){super(...arguments),this.id=`islamic-tbla`}},nye=class extends iZ{constructor(){super(...arguments),this.id=`islamic-civil`}},rye=class extends iZ{constructor(){super(...arguments),this.id=`islamic-rgsa`}},iye=class extends iZ{constructor(){super(...arguments),this.id=`islamicc`}},aye=class extends rZ{constructor(){super(...arguments),this.id=`persian`,this.calendarType=`solar`}inLeapYear(e,t){return this.daysInMonth({year:e.year,month:12,day:1},t)===30}monthsInYear(){return 12}minimumMonthLength(e){let{month:t}=e;return t===12?29:t<=6?31:30}maximumMonthLength(e){let{month:t}=e;return t===12?30:t<=6?31:30}maxLengthOfMonthCodeInAnyYear(e){return ZX(e)<=6?31:30}estimateIsoDate(e){let{year:t}=this.adjustCalendarDate(e);return{year:t+621,month:1,day:1}}},oye=class extends rZ{constructor(){super(...arguments),this.id=`indian`,this.calendarType=`solar`,this.months={1:{length:30,month:3,day:22,leap:{length:31,month:3,day:21}},2:{length:31,month:4,day:21},3:{length:31,month:5,day:22},4:{length:31,month:6,day:22},5:{length:31,month:7,day:23},6:{length:31,month:8,day:23},7:{length:30,month:9,day:23},8:{length:30,month:10,day:23},9:{length:30,month:11,day:22},10:{length:30,month:12,day:22},11:{length:30,month:1,nextYear:!0,day:21},12:{length:30,month:2,nextYear:!0,day:20}},this.vulnerableToBceBug=new Date(`0000-01-01T00:00Z`).toLocaleDateString(`en-US-u-ca-indian`,{timeZone:`UTC`})!==`10/11/-79 Saka`}inLeapYear(e){return aZ(e.year+78)}monthsInYear(){return 12}minimumMonthLength(e){return this.getMonthInfo(e).length}maximumMonthLength(e){return this.getMonthInfo(e).length}maxLengthOfMonthCodeInAnyYear(e){let t=ZX(e),n=this.months[t];return n=n.leap??n,n.length}getMonthInfo(e){let{month:t}=e,n=this.months[t];if(n===void 0)throw RangeError(`Invalid month: ${t}`);return this.inLeapYear(e)&&n.leap&&(n=n.leap),n}estimateIsoDate(e){let t=this.adjustCalendarDate(e),n=this.getMonthInfo(t);return OY(t.year+78+ +!!n.nextYear,n.month,n.day+t.day-1)}checkIcuBugs(e){if(this.vulnerableToBceBug&&e.year<1)throw RangeError(`calendar '${this.id}' is broken for ISO dates before 0001-01-01 (see https://bugs.chromium.org/p/v8/issues/detail?id=10529)`)}};function aZ(e){return e%4==0&&(e%100!=0||e%400==0)}var oZ=class extends rZ{constructor(e,t){super(),this.calendarType=`solar`,this.id=e,this.isoEpoch=t}inLeapYear(e){let{year:t}=this.estimateIsoDate({month:1,day:1,year:e.year});return aZ(t)}monthsInYear(){return 12}minimumMonthLength(e){let{month:t}=e;return t===2?this.inLeapYear(e)?29:28:[4,6,9,11].indexOf(t)>=0?30:31}maximumMonthLength(e){return this.minimumMonthLength(e)}maxLengthOfMonthCodeInAnyYear(e){return[31,29,31,30,31,30,31,31,30,31,30,31][ZX(e)-1]}estimateIsoDate(e){let t=this.adjustCalendarDate(e);return Pq(t.year+this.isoEpoch.year,t.month+this.isoEpoch.month,t.day+this.isoEpoch.day,`constrain`)}},sZ=class extends rZ{constructor(e,t){super(),this.hasEra=!0,this.calendarType=`solar`,this.id=e;let{eras:n,anchorEra:r}=function(e){let t,n=e;if(n.length===0)throw RangeError(`Invalid era data: eras are required`);if(n.length===1&&n[0].reverseOf)throw RangeError(`Invalid era data: anchor era cannot count years backwards`);if(n.length===1&&!n[0].code)throw RangeError(`Invalid era data: at least one named era is required`);if(n.filter((e=>e.reverseOf!=null)).length>1)throw RangeError(`Invalid era data: only one era can count years backwards`);n.forEach((e=>{if(e.isAnchor||!e.anchorEpoch&&!e.reverseOf){if(t)throw RangeError(`Invalid era data: cannot have multiple anchor eras`);t=e,e.anchorEpoch={year:+!e.hasYearZero}}else if(!e.code)throw RangeError(`If era name is blank, it must be the anchor era`)})),n=n.filter((e=>e.code)),n.forEach((e=>{let{reverseOf:t}=e;if(t){let r=n.find((e=>e.code===t));if(r===void 0)throw RangeError(`Invalid era data: unmatched reverseOf era: ${t}`);e.reverseOf=r,e.anchorEpoch=r.anchorEpoch,e.isoEpoch=r.isoEpoch}e.anchorEpoch.month===void 0&&(e.anchorEpoch.month=1),e.anchorEpoch.day===void 0&&(e.anchorEpoch.day=1)})),n.sort(((e,t)=>{if(e.reverseOf)return 1;if(t.reverseOf)return-1;if(!e.isoEpoch||!t.isoEpoch)throw RangeError(`Invalid era data: missing ISO epoch`);return t.isoEpoch.year-e.isoEpoch.year}));let r=n[n.length-1].reverseOf;if(r&&r!==n[n.length-2])throw RangeError(`Invalid era data: invalid reverse-sign era`);return n.forEach(((e,t)=>{e.genericName=`era`+(n.length-1-t)})),{eras:n,anchorEra:t||n[0]}}(t);this.anchorEra=r,this.eras=n}inLeapYear(e){let{year:t}=this.estimateIsoDate({month:1,day:1,year:e.year});return aZ(t)}monthsInYear(){return 12}minimumMonthLength(e){let{month:t}=e;return t===2?this.inLeapYear(e)?29:28:[4,6,9,11].indexOf(t)>=0?30:31}maximumMonthLength(e){return this.minimumMonthLength(e)}maxLengthOfMonthCodeInAnyYear(e){return[31,29,31,30,31,30,31,31,30,31,30,31][ZX(e)-1]}completeEraYear(e){let t=(t,n,r)=>{let i=e[t];if(i!=null&&i!=n&&!(r||[]).includes(i)){let e=r?.[0];throw RangeError(`Input ${t} ${i} doesn't match calculated value ${e?`${n} (also called ${e})`:n}`)}},n=t=>{let n,r={...e,year:t},i=this.eras.find(((e,i)=>{if(i===this.eras.length-1){if(e.reverseOf){if(t>0)throw RangeError(`Signed year ${t} is invalid for era ${e.code}`);return n=e.anchorEpoch.year-t,!0}return n=t-e.anchorEpoch.year+ +!e.hasYearZero,!0}return this.compareCalendarDates(r,e.anchorEpoch)>=0&&(n=t-e.anchorEpoch.year+ +!e.hasYearZero,!0)}));if(!i)throw RangeError(`Year ${t} was not matched by any era`);return{eraYear:n,era:i.code,eraNames:i.names}},{year:r,eraYear:i,era:a}=e;if(r!=null){let e=n(r);({eraYear:i,era:a}=e),t(`era`,a,e?.eraNames),t(`eraYear`,i)}else{if(i==null)throw RangeError(`Either year or eraYear and era are required`);{if(a===void 0)throw RangeError(`era and eraYear must be provided together`);let e=this.eras.find((({code:e,names:t=[]})=>e===a||t.includes(a)));if(!e)throw RangeError(`Era ${a} (ISO year ${i}) was not matched by any era`);r=e.reverseOf?e.anchorEpoch.year-i:i+e.anchorEpoch.year-+!e.hasYearZero,t(`year`,r),{eraYear:i,era:a}=n(r)}}return{...e,year:r,eraYear:i,era:a}}adjustCalendarDate(e,t,n=`constrain`){let r=e,{month:i,monthCode:a}=r;return i===void 0&&(r={...r,month:ZX(a)}),this.validateCalendarDate(r),r=this.completeEraYear(r),super.adjustCalendarDate(r,t,n)}estimateIsoDate(e){let{year:t,month:n,day:r}=this.adjustCalendarDate(e),{anchorEra:i}=this;return Pq(t+i.isoEpoch.year-+!i.hasYearZero,n,r,`constrain`)}},cZ=class extends sZ{constructor(e,t){super(e,t)}isoToCalendarDate(e){let{year:t,month:n,day:r}=e,i=QX(n),a=t-this.anchorEra.isoEpoch.year+1;return this.completeEraYear({year:a,month:n,monthCode:i,day:r})}},lZ={inLeapYear(e){let{year:t}=e;return(t+1)%4==0},monthsInYear:()=>13,minimumMonthLength(e){let{month:t}=e;return t===13?this.inLeapYear(e)?6:5:30},maximumMonthLength(e){return this.minimumMonthLength(e)},maxLengthOfMonthCodeInAnyYear:e=>e===`M13`?6:30},sye=class extends oZ{constructor(e,t){super(e,t),this.inLeapYear=lZ.inLeapYear,this.monthsInYear=lZ.monthsInYear,this.minimumMonthLength=lZ.minimumMonthLength,this.maximumMonthLength=lZ.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=lZ.maxLengthOfMonthCodeInAnyYear}},uZ=class extends sZ{constructor(e,t){super(e,t),this.inLeapYear=lZ.inLeapYear,this.monthsInYear=lZ.monthsInYear,this.minimumMonthLength=lZ.minimumMonthLength,this.maximumMonthLength=lZ.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=lZ.maxLengthOfMonthCodeInAnyYear}},cye=class extends sye{constructor(){super(`ethioaa`,{year:-5492,month:7,day:17})}},lye=class extends uZ{constructor(){super(`coptic`,[{code:`coptic`,isoEpoch:{year:284,month:8,day:29}},{code:`coptic-inverse`,reverseOf:`coptic`}])}},uye=class extends uZ{constructor(){super(`ethiopic`,[{code:`ethioaa`,names:[`ethiopic-amete-alem`,`mundi`],isoEpoch:{year:-5492,month:7,day:17}},{code:`ethiopic`,names:[`incar`],isoEpoch:{year:8,month:8,day:27},anchorEpoch:{year:5501}}])}},dye=class extends cZ{constructor(){super(`roc`,[{code:`roc`,names:[`minguo`],isoEpoch:{year:1912,month:1,day:1}},{code:`roc-inverse`,names:[`before-roc`],reverseOf:`roc`}])}},fye=class extends oZ{constructor(){super(`buddhist`,{year:-543,month:1,day:1})}},pye=class extends cZ{constructor(){super(`gregory`,[{code:`gregory`,names:[`ad`,`ce`],isoEpoch:{year:1,month:1,day:1}},{code:`gregory-inverse`,names:[`be`,`bce`],reverseOf:`gregory`}])}reviseIntlEra(e){let{era:t,eraYear:n}=e;return t===`b`&&(t=`gregory-inverse`),t===`a`&&(t=`gregory`),{era:t,eraYear:n}}getFirstDayOfWeek(){return 1}getMinimalDaysInFirstWeek(){return 1}},mye=class extends cZ{constructor(){super(`japanese`,[{code:`reiwa`,isoEpoch:{year:2019,month:5,day:1},anchorEpoch:{year:2019,month:5,day:1}},{code:`heisei`,isoEpoch:{year:1989,month:1,day:8},anchorEpoch:{year:1989,month:1,day:8}},{code:`showa`,isoEpoch:{year:1926,month:12,day:25},anchorEpoch:{year:1926,month:12,day:25}},{code:`taisho`,isoEpoch:{year:1912,month:7,day:30},anchorEpoch:{year:1912,month:7,day:30}},{code:`meiji`,isoEpoch:{year:1868,month:9,day:8},anchorEpoch:{year:1868,month:9,day:8}},{code:`japanese`,names:[`japanese`,`gregory`,`ad`,`ce`],isoEpoch:{year:1,month:1,day:1}},{code:`japanese-inverse`,names:[`japanese-inverse`,`gregory-inverse`,`bc`,`bce`],reverseOf:`japanese`}]),this.erasBeginMidYear=!0}reviseIntlEra(e,t){let{era:n,eraYear:r}=e,{year:i}=t;return this.eras.find((e=>e.code===n))?{era:n,eraYear:r}:i<1?{era:`japanese-inverse`,eraYear:1-i}:{era:`japanese`,eraYear:i}}},dZ=class extends rZ{constructor(){super(...arguments),this.calendarType=`lunisolar`}inLeapYear(e,t){let n=this.getMonthList(e.year,t);return Object.entries(n).length===13}monthsInYear(e,t){return this.inLeapYear(e,t)?13:12}minimumMonthLength(){return 29}maximumMonthLength(){return 30}maxLengthOfMonthCodeInAnyYear(e){return[`M01L`,`M09L`,`M10L`,`M11L`,`M12L`].includes(e)?29:30}monthDaySearchStartYear(e,t){let n={M01L:[1651,1651],M02L:[1947,1765],M03L:[1966,1955],M04L:[1963,1944],M05L:[1971,1952],M06L:[1960,1941],M07L:[1968,1938],M08L:[1957,1718],M09L:[1832,1832],M10L:[1870,1870],M11L:[1814,1814],M12L:[1890,1890]}[e]??[1972,1972];return t<30?n[0]:n[1]}getMonthList(e,t){if(e===void 0)throw TypeError(`Missing year`);let n=JSON.stringify({func:`getMonthList`,calendarYear:e,id:this.id}),r=t.get(n);if(r)return r;let i=this.getFormatter(),a=(e,t)=>{let n=tZ({isoYear:e,isoMonth:2,isoDay:1}),r=new Date(n);r.setUTCDate(t+1);let a=i.formatToParts(r),o=a.find((e=>e.type===`month`)).value,s=+a.find((e=>e.type===`day`)).value,c=a.find((e=>e.type===`relatedYear`)),l;if(c===void 0)throw RangeError(`Intl.DateTimeFormat.formatToParts lacks relatedYear in ${this.id} calendar. Try Node 14+ or modern browsers.`);return l=+c.value,{calendarMonthString:o,calendarDay:s,calendarYearToVerify:l}},o=17,{calendarMonthString:s,calendarDay:c,calendarYearToVerify:l}=a(e,o);s!==`1`&&(o+=29,{calendarMonthString:s,calendarDay:c}=a(e,o)),o-=c-5;let u={},d,f,p=1,m=!1;do({calendarMonthString:s,calendarDay:c,calendarYearToVerify:l}=a(e,o)),d&&(u[f].daysInMonth=d+30-c),l===e?(u[s]={monthIndex:p++},o+=30):m=!0,d=c,f=s;while(!m);return u[f].daysInMonth=d+30-c,t.set(n,u),u}estimateIsoDate(e){let{year:t,month:n}=e;return{year:t,month:n>=12?12:n+1,day:1}}adjustCalendarDate(e,t,n=`constrain`,r=!1){let{year:i,month:a,monthExtra:o,day:s,monthCode:c}=e;if(i===void 0)throw TypeError(`Missing property: year`);if(r){if(o&&o!==`bis`)throw RangeError(`Unexpected leap month suffix: ${o}`);let e=QX(a,o!==void 0),n=`${a}${o||``}`,r=this.getMonthList(i,t)[n];if(r===void 0)throw RangeError(`Unmatched month ${n} in Chinese year ${i}`);return a=r.monthIndex,{year:i,month:a,day:s,monthCode:e}}if(this.validateCalendarDate(e),a===void 0){let e=this.getMonthList(i,t),r=c.replace(/^M|L$/g,(e=>e===`L`?`bis`:``));r[0]===`0`&&(r=r.slice(1));let o=e[r];if(a=o&&o.monthIndex,a===void 0&&c.endsWith(`L`)&&c!=`M13L`&&n===`constrain`){let t=+c.replace(/^M0?|L$/g,``);o=e[t],o&&(a=o.monthIndex,c=QX(t))}if(a===void 0)throw RangeError(`Unmatched month ${c} in Chinese year ${i}`)}else if(c===void 0){let e=this.getMonthList(i,t),r=Object.entries(e),o=r.length;n===`reject`?(FY(a,1,o),FY(s,1,this.maximumMonthLength())):(a=NY(a,1,o),s=NY(s,1,this.maximumMonthLength()));let l=r.find((e=>e[1].monthIndex===a));if(l===void 0)throw RangeError(`Invalid month ${a} in Chinese year ${i}`);c=QX(+l[0].replace(`bis`,``),l[0].indexOf(`bis`)!==-1)}else{let e=this.getMonthList(i,t),n=c.replace(/^M|L$/g,(e=>e===`L`?`bis`:``));n[0]===`0`&&(n=n.slice(1));let r=e[n];if(!r)throw RangeError(`Unmatched monthCode ${c} in Chinese year ${i}`);if(a!==r.monthIndex)throw RangeError(`monthCode ${c} doesn't correspond to month ${a} in Chinese year ${i}`)}return{...e,year:i,month:a,monthCode:c,day:s}}},hye=class extends dZ{constructor(){super(...arguments),this.id=`chinese`}},gye=class extends dZ{constructor(){super(...arguments),this.id=`dangi`}},_ye=class{constructor(e){this.helper=e}extraFields(e){return this.helper.hasEra&&e.includes(`year`)?[`era`,`eraYear`]:[]}resolveFields(e){if(this.helper.calendarType!==`lunisolar`){let t=new eZ;$X(e,void 0,this.helper.monthsInYear({year:e.year??1972},t))}}dateToISO(e,t){let n=new eZ,r=this.helper.calendarToIsoDate(e,t,n);return n.setObject(r),r}monthDayToISOReferenceDate(e,t){let n=new eZ,r=this.helper.monthDayFromFields(e,t,n);return n.setObject(r),r}fieldKeysToIgnore(e){let t=new Set;for(let n=0;n<e.length;n++){let r=e[n];switch(t.add(r),r){case`era`:t.add(`eraYear`),t.add(`year`);break;case`eraYear`:t.add(`era`),t.add(`year`);break;case`year`:t.add(`era`),t.add(`eraYear`);break;case`month`:t.add(`monthCode`),this.helper.erasBeginMidYear&&(t.add(`era`),t.add(`eraYear`));break;case`monthCode`:t.add(`month`),this.helper.erasBeginMidYear&&(t.add(`era`),t.add(`eraYear`));break;case`day`:this.helper.erasBeginMidYear&&(t.add(`era`),t.add(`eraYear`))}}return qX(t)}dateAdd(e,{years:t,months:n,weeks:r,days:i},a){let o=eZ.getCacheForObject(e),s=this.helper.isoToCalendarDate(e,o),c=this.helper.addCalendar(s,{years:t,months:n,weeks:r,days:i},a,o),l=this.helper.calendarToIsoDate(c,`constrain`,o);return eZ.getCacheForObject(l)||new eZ(o).setObject(l),l}dateUntil(e,t,n){let r=eZ.getCacheForObject(e),i=eZ.getCacheForObject(t),a=this.helper.isoToCalendarDate(e,r),o=this.helper.isoToCalendarDate(t,i);return this.helper.untilCalendar(a,o,n,r)}isoToDate(e,t){let n=eZ.getCacheForObject(e),r=this.helper.isoToCalendarDate(e,n);if(t.dayOfWeek&&(r.dayOfWeek=XX.iso8601.isoToDate(e,{dayOfWeek:!0}).dayOfWeek),t.dayOfYear){let e=this.helper.startOfCalendarYear(r);r.dayOfYear=this.helper.calendarDaysUntil(e,r,n)+1}if(t.weekOfYear&&(r.weekOfYear=JX(this.helper.id,e)),r.daysInWeek=7,t.daysInMonth&&(r.daysInMonth=this.helper.daysInMonth(r,n)),t.daysInYear){let e=this.helper.startOfCalendarYear(r),t=this.helper.addCalendar(e,{years:1},`constrain`,n);r.daysInYear=this.helper.calendarDaysUntil(e,t,n)}return t.monthsInYear&&(r.monthsInYear=this.helper.monthsInYear(r,n)),t.inLeapYear&&(r.inLeapYear=this.helper.inLeapYear(r,n)),r}getFirstDayOfWeek(){return this.helper.getFirstDayOfWeek()}getMinimalDaysInFirstWeek(){return this.helper.getMinimalDaysInFirstWeek()}};for(let e of[Qve,aye,uye,cye,lye,hye,gye,dye,oye,fye,pye,mye,$ve,eye,tye,nye,rye,iye]){let t=new e;XX[t.id]=new _ye(t)}DK(`calendarImpl`,(function(e){return XX[e]}));var fZ=Intl.DateTimeFormat;function pZ(e,t){let n=Q(e,t);return typeof n==`function`&&(n=new fZ(Q(e,gK),n(Q(e,_K))),function(e,t,n){let r=bK(e);if(r===void 0)throw TypeError(`Missing slots for the given container`);if(r[t]===void 0)throw TypeError(`tried to reset ${t} which was not set`);r[t]=n}(e,t,n)),n}function mZ(e){return CK(e,fK)}var hZ=class{constructor(e=void 0,t=void 0){(function(e,t,n){let r=n!==void 0,i;if(r){let e=[`localeMatcher`,`calendar`,`numberingSystem`,`hour12`,`hourCycle`,`timeZone`,`weekday`,`era`,`year`,`month`,`day`,`dayPeriod`,`hour`,`minute`,`second`,`fractionalSecondDigits`,`timeZoneName`,`formatMatcher`,`dateStyle`,`timeStyle`];i=function(e){if(e==null)throw TypeError(`Expected object not ${e}`);return Object(e)}(n);let t=Object.create(null);for(let n=0;n<e.length;n++){let r=e[n];Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}i=t}else i=Object.create(null);let a=new fZ(t,i),o=a.resolvedOptions();if(SK(e),r){let t=Object.assign(Object.create(null),o);for(let e in t)Object.prototype.hasOwnProperty.call(i,e)||delete t[e];t.hour12=i.hour12,t.hourCycle=i.hourCycle,wK(e,_K,t)}else wK(e,_K,i);wK(e,gK,o.locale),wK(e,fK,a),wK(e,pK,o.timeZone),wK(e,hK,o.calendar),wK(e,oK,Eye),wK(e,sK,wye),wK(e,cK,Tye),wK(e,lK,Cye),wK(e,uK,Dye),wK(e,dK,Oye);let s=r?i.timeZone:void 0;if(s===void 0)wK(e,mK,o.timeZone);else{let t=eq(s);if(t.startsWith(`−`))throw RangeError(`Unicode minus (U+2212) is not supported in time zone offsets`);wK(e,mK,VJ(t))}})(this,e,t)}get format(){$(this,mZ);let e=yye.bind(this);return Object.defineProperties(e,{length:{value:1,enumerable:!1,writable:!1,configurable:!0},name:{value:``,enumerable:!1,writable:!1,configurable:!0}}),e}formatRange(e,t){return $(this,mZ),xye.call(this,e,t)}formatToParts(e,...t){return $(this,mZ),bye.call(this,e,...t)}formatRangeToParts(e,t){return $(this,mZ),Sye.call(this,e,t)}resolvedOptions(){return $(this,mZ),vye.call(this)}};`formatToParts`in fZ.prototype||delete hZ.prototype.formatToParts,`formatRangeToParts`in fZ.prototype||delete hZ.prototype.formatRangeToParts;var gZ=function(e=void 0,t=void 0){return new hZ(e,t)};function vye(){let e=Q(this,fK).resolvedOptions();return e.timeZone=Q(this,mK),e}function yye(e,...t){let n,r,i=wZ(e,this);return i.formatter?(n=i.formatter,r=[PX(i.epochNs,`floor`)]):(n=Q(this,fK),r=[e,...t]),n.format(...r)}function bye(e,...t){let n,r,i=wZ(e,this);return i.formatter?(n=i.formatter,r=[PX(i.epochNs,`floor`)]):(n=Q(this,fK),r=[e,...t]),n.formatToParts(...r)}function xye(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=SZ(e),r=SZ(t),i,a=[n,r];if(xZ(n)!==xZ(r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);if(xZ(n)){if(!CZ(n,r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);let{epochNs:e,formatter:t}=wZ(n,this),{epochNs:o,formatter:s}=wZ(r,this);t&&(i=t,a=[PX(e,`floor`),PX(o,`floor`)])}return i||=Q(this,fK),i.formatRange(...a)}function Sye(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=SZ(e),r=SZ(t),i,a=[n,r];if(xZ(n)!==xZ(r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);if(xZ(n)){if(!CZ(n,r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);let{epochNs:e,formatter:t}=wZ(n,this),{epochNs:o,formatter:s}=wZ(r,this);t&&(i=t,a=[PX(e,`floor`),PX(o,`floor`)])}return i||=Q(this,fK),i.formatRangeToParts(...a)}function _Z(e={},t={}){let n=Object.assign({},e),r=[`year`,`month`,`day`,`hour`,`minute`,`second`,`weekday`,`dayPeriod`,`timeZoneName`,`dateStyle`,`timeStyle`];for(let e=0;e<r.length;e++){let i=r[e];n[i]=i in t?t[i]:n[i],!1!==n[i]&&n[i]!==void 0||delete n[i]}return n}function Cye(e){let t=_Z(e,{year:!1,month:!1,day:!1,weekday:!1,timeZoneName:!1,dateStyle:!1});if(t.timeStyle!==`long`&&t.timeStyle!==`full`||(delete t.timeStyle,Object.assign(t,{hour:`numeric`,minute:`2-digit`,second:`2-digit`})),!yZ(t)){if(bZ(e))throw TypeError(`cannot format Temporal.PlainTime with options [${Object.keys(e)}]`);Object.assign(t,{hour:`numeric`,minute:`numeric`,second:`numeric`})}return t}function wye(e){let t={short:{year:`2-digit`,month:`numeric`},medium:{year:`numeric`,month:`short`},long:{year:`numeric`,month:`long`},full:{year:`numeric`,month:`long`}},n=_Z(e,{day:!1,hour:!1,minute:!1,second:!1,weekday:!1,dayPeriod:!1,timeZoneName:!1,timeStyle:!1});if(`dateStyle`in n&&n.dateStyle){let e=n.dateStyle;delete n.dateStyle,Object.assign(n,t[e])}if(!(`year`in n||`month`in n||`era`in n)){if(bZ(e))throw TypeError(`cannot format PlainYearMonth with options [${Object.keys(e)}]`);Object.assign(n,{year:`numeric`,month:`numeric`})}return n}function Tye(e){let t={short:{month:`numeric`,day:`numeric`},medium:{month:`short`,day:`numeric`},long:{month:`long`,day:`numeric`},full:{month:`long`,day:`numeric`}},n=_Z(e,{year:!1,hour:!1,minute:!1,second:!1,weekday:!1,dayPeriod:!1,timeZoneName:!1,timeStyle:!1});if(`dateStyle`in n&&n.dateStyle){let e=n.dateStyle;delete n.dateStyle,Object.assign(n,t[e])}if(!(`month`in n)&&!(`day`in n)){if(bZ(e))throw TypeError(`cannot format PlainMonthDay with options [${Object.keys(e)}]`);Object.assign(n,{month:`numeric`,day:`numeric`})}return n}function Eye(e){let t=_Z(e,{hour:!1,minute:!1,second:!1,dayPeriod:!1,timeZoneName:!1,timeStyle:!1});if(!vZ(t)){if(bZ(e))throw TypeError(`cannot format PlainDate with options [${Object.keys(e)}]`);Object.assign(t,{year:`numeric`,month:`numeric`,day:`numeric`})}return t}function Dye(e){let t=_Z(e,{timeZoneName:!1});if((t.timeStyle===`long`||t.timeStyle===`full`)&&(delete t.timeStyle,Object.assign(t,{hour:`numeric`,minute:`2-digit`,second:`2-digit`}),t.dateStyle)&&(Object.assign(t,{short:{year:`numeric`,month:`numeric`,day:`numeric`},medium:{year:`numeric`,month:`short`,day:`numeric`},long:{year:`numeric`,month:`long`,day:`numeric`},full:{year:`numeric`,month:`long`,day:`numeric`,weekday:`long`}}[t.dateStyle]),delete t.dateStyle),!yZ(t)&&!vZ(t)){if(bZ(e))throw TypeError(`cannot format PlainDateTime with options [${Object.keys(e)}]`);Object.assign(t,{year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})}return t}function Oye(e){let t=e;return yZ(t)||vZ(t)||(t=Object.assign({},t,{year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})),t}function vZ(e){return`year`in e||`month`in e||`day`in e||`weekday`in e||`dateStyle`in e||`era`in e}function yZ(e){return`hour`in e||`minute`in e||`second`in e||`timeStyle`in e||`dayPeriod`in e||`fractionalSecondDigits`in e}function bZ(e){return vZ(e)||yZ(e)||`dateStyle`in e||`timeStyle`in e||`timeZoneName`in e}function xZ(e){return _q(e)||vq(e)||yq(e)||Sq(e)||bq(e)||xq(e)||hq(e)}function SZ(e){return xZ(e)?e:$K(e)}function CZ(e,t){return!(!xZ(e)||!xZ(t)||vq(e)&&!vq(t)||_q(e)&&!_q(t)||yq(e)&&!yq(t)||Sq(e)&&!Sq(t)||bq(e)&&!bq(t)||xq(e)&&!xq(t)||hq(e)&&!hq(t))}function wZ(e,t){if(vq(e)){let n={isoDate:{year:1970,month:1,day:1},time:Q(e,WG)};return{epochNs:KJ(Q(t,pK),n,`compatible`),formatter:pZ(t,lK)}}if(bq(e)){let n=Q(e,GG),r=Q(t,hK);if(n!==r)throw RangeError(`cannot format PlainYearMonth with calendar ${n} in locale with calendar ${r}`);let i=Rq(Q(e,HG),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:KJ(Q(t,pK),i,`compatible`),formatter:pZ(t,sK)}}if(xq(e)){let n=Q(e,GG),r=Q(t,hK);if(n!==r)throw RangeError(`cannot format PlainMonthDay with calendar ${n} in locale with calendar ${r}`);let i=Rq(Q(e,HG),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:KJ(Q(t,pK),i,`compatible`),formatter:pZ(t,cK)}}if(_q(e)){let n=Q(e,GG),r=Q(t,hK);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDate with calendar ${n} in locale with calendar ${r}`);let i=Rq(Q(e,HG),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:KJ(Q(t,pK),i,`compatible`),formatter:pZ(t,oK)}}if(yq(e)){let n=Q(e,GG),r=Q(t,hK);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDateTime with calendar ${n} in locale with calendar ${r}`);let i=Q(e,UG);return{epochNs:KJ(Q(t,pK),i,`compatible`),formatter:pZ(t,uK)}}if(Sq(e))throw TypeError(`Temporal.ZonedDateTime not supported in DateTimeFormat methods. Use toLocaleString() instead.`);return hq(e)?{epochNs:Q(e,VG),formatter:pZ(t,dK)}:{}}function TZ(e){let t=Object.create(null);return t.years=Q(e,XG),t.months=Q(e,ZG),t.weeks=Q(e,QG),t.days=Q(e,$G),t.hours=Q(e,eK),t.minutes=Q(e,tK),t.seconds=Q(e,nK),t.milliseconds=Q(e,rK),t.microseconds=Q(e,iK),t.nanoseconds=Q(e,aK),t}hZ.prototype.constructor=gZ,Object.defineProperty(gZ,"prototype",{value:hZ.prototype,writable:!1,enumerable:!1,configurable:!1}),gZ.supportedLocalesOf=fZ.supportedLocalesOf,EK(gZ,`Intl.DateTimeFormat`);var{format:kye,formatToParts:Aye}=Intl.DurationFormat?.prototype??Object.create(null);function EZ(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=TZ(lJ(e));return kye.call(this,t)}Intl.DurationFormat?.prototype&&(Intl.DurationFormat.prototype.format=EZ,Intl.DurationFormat.prototype.formatToParts=function(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=TZ(lJ(e));return Aye.call(this,t)}),Object.freeze({__proto__:null,DateTimeFormat:gZ,ModifiedIntlDurationFormatPrototypeFormat:EZ});var DZ=class{constructor(e){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);DJ(this,IX(e))}get epochMilliseconds(){return $(this,hq),PX(Q(this,VG),`floor`)}get epochNanoseconds(){return $(this,hq),NX(Z.default.BigInt(Q(this,VG)))}add(e){return $(this,hq),vX(`add`,this,e)}subtract(e){return $(this,hq),vX(`subtract`,this,e)}until(e,t=void 0){return $(this,hq),cX(`until`,this,e,t)}since(e,t=void 0){return $(this,hq),cX(`since`,this,e,t)}round(e){if($(this,hq),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?VX(`smallestUnit`,e):BX(e),n=Wq(t),r=Vq(t,`halfExpand`),i=Yq(t,`smallestUnit`,`time`,Jq);return Gq(n,{hour:24,minute:1440,second:86400,millisecond:864e5,microsecond:864e8,nanosecond:864e11}[i],!0),OJ(TX(Q(this,VG),n,i,r))}equals(e){$(this,hq);let t=uJ(e),n=Q(this,VG),r=Q(t,VG);return Z.default.equal(Z.default.BigInt(n),Z.default.BigInt(r))}toString(e=void 0){$(this,hq);let t=BX(e),n=Kq(t),r=Vq(t,`trunc`),i=Yq(t,`smallestUnit`,`time`,void 0);if(i===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let a=t.timeZone;a!==void 0&&(a=VJ(a));let{precision:o,unit:s,increment:c}=qq(i,n);return eY(OJ(TX(Q(this,VG),c,s,r)),a,o)}toJSON(){return $(this,hq),eY(this,void 0,`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,hq),new gZ(e,t).format(this)}valueOf(){GX(`Instant`)}toZonedDateTimeISO(e){$(this,hq);let t=VJ(e);return AJ(Q(this,VG),t,`iso8601`)}static fromEpochMilliseconds(e){return OJ(FX($K(e)))}static fromEpochNanoseconds(e){return OJ(IX(e))}static from(e){return uJ(e)}static compare(e,t){let n=uJ(e),r=uJ(t),i=Q(n,VG),a=Q(r,VG);return Z.default.lessThan(i,a)?-1:+!!Z.default.greaterThan(i,a)}};EK(DZ,`Temporal.Instant`);var OZ=class{constructor(e,t,n,r=`iso8601`){let i=tq(e),a=tq(t),o=tq(n),s=UX(r===void 0?`iso8601`:aq(r));IY(i,a,o),_J(this,{year:i,month:a,day:o},s)}get calendarId(){return $(this,_q),Q(this,GG)}get era(){return kZ(this,`era`)}get eraYear(){return kZ(this,`eraYear`)}get year(){return kZ(this,`year`)}get month(){return kZ(this,`month`)}get monthCode(){return kZ(this,`monthCode`)}get day(){return kZ(this,`day`)}get dayOfWeek(){return kZ(this,`dayOfWeek`)}get dayOfYear(){return kZ(this,`dayOfYear`)}get weekOfYear(){return kZ(this,`weekOfYear`)?.week}get yearOfWeek(){return kZ(this,`weekOfYear`)?.year}get daysInWeek(){return kZ(this,`daysInWeek`)}get daysInMonth(){return kZ(this,`daysInMonth`)}get daysInYear(){return kZ(this,`daysInYear`)}get monthsInYear(){return kZ(this,`monthsInYear`)}get inLeapYear(){return kZ(this,`inLeapYear`)}with(e,t=void 0){if($(this,_q),!QK(e))throw TypeError(`invalid argument`);Cq(e);let n=Q(this,GG),r=rJ(n,Q(this,HG));return r=MJ(n,r,iJ(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),vJ(RJ(n,r,zq(BX(t))),n)}withCalendar(e){$(this,_q);let t=FJ(e);return vJ(Q(this,HG),t)}add(e,t=void 0){return $(this,_q),yX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,_q),yX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,_q),lX(`until`,this,e,t)}since(e,t=void 0){return $(this,_q),lX(`since`,this,e,t)}equals(e){$(this,_q);let t=oJ(e);return AX(Q(this,HG),Q(t,HG))===0&&LJ(Q(this,GG),Q(t,GG))}toString(e=void 0){return $(this,_q),nY(this,Uq(BX(e)))}toJSON(){return $(this,_q),nY(this)}toLocaleString(e=void 0,t=void 0){return $(this,_q),new gZ(e,t).format(this)}valueOf(){GX(`PlainDate`)}toPlainDateTime(e=void 0){$(this,_q);let t=pJ(e);return bJ(Rq(Q(this,HG),t),Q(this,GG))}toZonedDateTime(e){let t,n;if($(this,_q),QK(e)){let r=e.timeZone;r===void 0?t=VJ(e):(t=VJ(r),n=e.plainTime)}else t=VJ(e);let r=Q(this,HG),i;return n===void 0?i=YJ(t,r):(n=fJ(n),i=KJ(t,Rq(r,Q(n,WG)),`compatible`)),AJ(i,t,Q(this,GG))}toPlainYearMonth(){$(this,_q);let e=Q(this,GG);return EJ(zJ(e,rJ(e,Q(this,HG)),`constrain`),e)}toPlainMonthDay(){$(this,_q);let e=Q(this,GG);return SJ(BJ(e,rJ(e,Q(this,HG)),`constrain`),e)}static from(e,t=void 0){return oJ(e,t)}static compare(e,t){let n=oJ(e),r=oJ(t);return AX(Q(n,HG),Q(r,HG))}};function kZ(e,t){$(e,_q);let n=Q(e,HG);return nJ(e).isoToDate(n,{[t]:!0})[t]}EK(OZ,`Temporal.PlainDate`);var AZ=class{constructor(e,t,n,r=0,i=0,a=0,o=0,s=0,c=0,l=`iso8601`){let u=tq(e),d=tq(t),f=tq(n),p=r===void 0?0:tq(r),m=i===void 0?0:tq(i),h=a===void 0?0:tq(a),g=o===void 0?0:tq(o),_=s===void 0?0:tq(s),v=c===void 0?0:tq(c),y=UX(l===void 0?`iso8601`:aq(l));zY(u,d,f,p,m,h,g,_,v),yJ(this,{isoDate:{year:u,month:d,day:f},time:{hour:p,minute:m,second:h,millisecond:g,microsecond:_,nanosecond:v}},y)}get calendarId(){return $(this,yq),Q(this,GG)}get year(){return jZ(this,`year`)}get month(){return jZ(this,`month`)}get monthCode(){return jZ(this,`monthCode`)}get day(){return jZ(this,`day`)}get hour(){return MZ(this,`hour`)}get minute(){return MZ(this,`minute`)}get second(){return MZ(this,`second`)}get millisecond(){return MZ(this,`millisecond`)}get microsecond(){return MZ(this,`microsecond`)}get nanosecond(){return MZ(this,`nanosecond`)}get era(){return jZ(this,`era`)}get eraYear(){return jZ(this,`eraYear`)}get dayOfWeek(){return jZ(this,`dayOfWeek`)}get dayOfYear(){return jZ(this,`dayOfYear`)}get weekOfYear(){return jZ(this,`weekOfYear`)?.week}get yearOfWeek(){return jZ(this,`weekOfYear`)?.year}get daysInWeek(){return jZ(this,`daysInWeek`)}get daysInYear(){return jZ(this,`daysInYear`)}get daysInMonth(){return jZ(this,`daysInMonth`)}get monthsInYear(){return jZ(this,`monthsInYear`)}get inLeapYear(){return jZ(this,`inLeapYear`)}with(e,t=void 0){if($(this,yq),!QK(e))throw TypeError(`invalid argument`);Cq(e);let n=Q(this,GG),r=Q(this,UG),i={...rJ(n,r.isoDate),...r.time};return i=MJ(n,i,iJ(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],`partial`)),bJ(sJ(n,i,zq(BX(t))),n)}withPlainTime(e=void 0){$(this,yq);let t=pJ(e);return bJ(Rq(Q(this,UG).isoDate,t),Q(this,GG))}withCalendar(e){$(this,yq);let t=FJ(e);return bJ(Q(this,UG),t)}add(e,t=void 0){return $(this,yq),bX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,yq),bX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,yq),uX(`until`,this,e,t)}since(e,t=void 0){return $(this,yq),uX(`since`,this,e,t)}round(e){if($(this,yq),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?VX(`smallestUnit`,e):BX(e),n=Wq(t),r=Vq(t,`halfExpand`),i=Yq(t,`smallestUnit`,`time`,Jq,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];Gq(n,a,a===1);let o=Q(this,UG);return bJ(n===1&&i===`nanosecond`?o:EX(o,n,i,r),Q(this,GG))}equals(e){$(this,yq);let t=cJ(e);return MX(Q(this,UG),Q(t,UG))===0&&LJ(Q(this,GG),Q(t,GG))}toString(e=void 0){$(this,yq);let t=BX(e),n=Uq(t),r=Kq(t),i=Vq(t,`trunc`),a=Yq(t,`smallestUnit`,`time`,void 0);if(a===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let{precision:o,unit:s,increment:c}=qq(a,r),l=EX(Q(this,UG),c,s,i);return BY(l),iY(l,Q(this,GG),o,n)}toJSON(){return $(this,yq),iY(Q(this,UG),Q(this,GG),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,yq),new gZ(e,t).format(this)}valueOf(){GX(`PlainDateTime`)}toZonedDateTime(e,t=void 0){$(this,yq);let n=VJ(e),r=Bq(BX(t));return AJ(KJ(n,Q(this,UG),r),n,Q(this,GG))}toPlainDate(){return $(this,yq),vJ(Q(this,UG).isoDate,Q(this,GG))}toPlainTime(){return $(this,yq),wJ(Q(this,UG).time)}static from(e,t=void 0){return cJ(e,t)}static compare(e,t){let n=cJ(e),r=cJ(t);return MX(Q(n,UG),Q(r,UG))}};function jZ(e,t){$(e,yq);let n=Q(e,UG).isoDate;return nJ(e).isoToDate(n,{[t]:!0})[t]}function MZ(e,t){return $(e,yq),Q(e,UG).time[t]}EK(AZ,`Temporal.PlainDateTime`);var NZ=class e{constructor(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c=0,l=0){let u=e===void 0?0:rq(e),d=t===void 0?0:rq(t),f=n===void 0?0:rq(n),p=r===void 0?0:rq(r),m=i===void 0?0:rq(i),h=a===void 0?0:rq(a),g=o===void 0?0:rq(o),_=s===void 0?0:rq(s),v=c===void 0?0:rq(c),y=l===void 0?0:rq(l);WY(u,d,f,p,m,h,g,_,v,y),SK(this),wK(this,XG,u),wK(this,ZG,d),wK(this,QG,f),wK(this,$G,p),wK(this,eK,m),wK(this,tK,h),wK(this,nK,g),wK(this,rK,_),wK(this,iK,v),wK(this,aK,y)}get years(){return $(this,gq),Q(this,XG)}get months(){return $(this,gq),Q(this,ZG)}get weeks(){return $(this,gq),Q(this,QG)}get days(){return $(this,gq),Q(this,$G)}get hours(){return $(this,gq),Q(this,eK)}get minutes(){return $(this,gq),Q(this,tK)}get seconds(){return $(this,gq),Q(this,nK)}get milliseconds(){return $(this,gq),Q(this,rK)}get microseconds(){return $(this,gq),Q(this,iK)}get nanoseconds(){return $(this,gq),Q(this,aK)}get sign(){return $(this,gq),wY(this)}get blank(){return $(this,gq),wY(this)===0}with(t){$(this,gq);let{years:n=Q(this,XG),months:r=Q(this,ZG),weeks:i=Q(this,QG),days:a=Q(this,$G),hours:o=Q(this,eK),minutes:s=Q(this,tK),seconds:c=Q(this,nK),milliseconds:l=Q(this,rK),microseconds:u=Q(this,iK),nanoseconds:d=Q(this,aK)}=Iq(t);return new e(n,r,i,a,o,s,c,l,u,d)}negated(){return $(this,gq),MY(this)}abs(){return $(this,gq),new e(Math.abs(Q(this,XG)),Math.abs(Q(this,ZG)),Math.abs(Q(this,QG)),Math.abs(Q(this,$G)),Math.abs(Q(this,eK)),Math.abs(Q(this,tK)),Math.abs(Q(this,nK)),Math.abs(Q(this,rK)),Math.abs(Q(this,iK)),Math.abs(Q(this,aK)))}add(e){return $(this,gq),_X(`add`,this,e)}subtract(e){return $(this,gq),_X(`subtract`,this,e)}round(e){if($(this,gq),e===void 0)throw TypeError(`options parameter is required`);let t=Zq(this),n=typeof e==`string`?VX(`smallestUnit`,e):BX(e),r=Yq(n,`largestUnit`,`datetime`,void 0,[`auto`]),{plainRelativeTo:i,zonedRelativeTo:a}=Xq(n),o=Wq(n),s=Vq(n,`halfExpand`),c=Yq(n,`smallestUnit`,`datetime`,void 0),l=!0;c||=(l=!1,`nanosecond`);let u=Qq(t,c),d=!0;if(r||=(d=!1,u),r===`auto`&&(r=u),!l&&!d)throw RangeError(`at least one of smallestUnit or largestUnit is required`);if(Qq(r,c)!==r)throw RangeError(`largestUnit ${r} cannot be smaller than smallestUnit ${c}`);let f={hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[c];if(f!==void 0&&Gq(o,f,!1),o>1&&eJ(c)===`date`&&r!==c)throw RangeError(`For calendar units with roundingIncrement > 1, use largestUnit = smallestUnit`);if(a){let e=GY(this),t=Q(a,YG),n=Q(a,GG),i=Q(a,VG);return e=oX(i,gX(i,t,n,e),t,n,r,o,c,s),eJ(r)===`date`&&(r=`hour`),JY(e,r)}if(i){let e=KY(this),t=mX({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),n=Q(i,HG),a=Q(i,GG),l=NJ(a,n,Lq(e.date,t.deltaDays),`constrain`);return e=aX(Rq(n,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Rq(l,t),a,r,o,c,s),JY(e,r)}if($q(t))throw RangeError(`a starting point is required for ${t}s balancing`);if($q(r))throw RangeError(`a starting point is required for ${r}s balancing`);let p=KY(this);if(c===`day`){let{quotient:e,remainder:t}=p.time.divmod(GK),n=p.date.days+e+kX(t,`day`);n=wX(n,o,s),p=YY({years:0,months:0,weeks:0,days:n},NK.ZERO)}else p=YY({years:0,months:0,weeks:0,days:0},OX(p.time,o,c,s));return JY(p,r)}total(e){if($(this,gq),e===void 0)throw TypeError(`options argument is required`);let t=typeof e==`string`?VX(`unit`,e):BX(e),{plainRelativeTo:n,zonedRelativeTo:r}=Xq(t),i=Yq(t,`unit`,`datetime`,Jq);if(r){let e=GY(this),t=Q(r,YG),n=Q(r,GG),a=Q(r,VG);return function(e,t,n,r,i){return eJ(i)===`time`?kX(NK.fromEpochNsDiff(t,e),i):iX(tX(e,t,n,r,i),t,GJ(n,e),n,r,i)}(a,gX(a,t,n,e),t,n,i)}if(n){let e=KY(this),t=mX({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),r=Q(n,HG),a=Q(n,GG),o=NJ(a,r,Lq(e.date,t.deltaDays),`constrain`);return function(e,t,n,r){if(MX(e,t)==0)return 0;BY(e),BY(t);let i=eX(e,t,n,r);return r===`nanosecond`?Z.default.toNumber(i.time.totalNs):iX(i,_Y(t),e,null,n,r)}(Rq(r,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Rq(o,t),a,i)}let a=Zq(this);if($q(a))throw RangeError(`a starting point is required for ${a}s total`);if($q(i))throw RangeError(`a starting point is required for ${i}s total`);return kX(KY(this).time,i)}toString(e=void 0){$(this,gq);let t=BX(e),n=Kq(t),r=Vq(t,`trunc`),i=Yq(t,`smallestUnit`,`time`,void 0);if(i===`hour`||i===`minute`)throw RangeError(`smallestUnit must be a time unit other than "hours" or "minutes"`);let{precision:a,unit:o,increment:s}=qq(i,n);if(o===`nanosecond`&&s===1)return tY(this,a);let c=Zq(this),l=GY(this),u=OX(l.time,s,o,r);return l=YY(l.date,u),tY(JY(l,Qq(c,`second`)),a)}toJSON(){return $(this,gq),tY(this,`auto`)}toLocaleString(e=void 0,t=void 0){if($(this,gq),typeof Intl.DurationFormat==`function`){let n=new Intl.DurationFormat(e,t);return EZ.call(n,this)}return console.warn(`Temporal.Duration.prototype.toLocaleString() requires Intl.DurationFormat.`),tY(this,`auto`)}valueOf(){GX(`Duration`)}static from(e){return lJ(e)}static compare(e,t,n=void 0){let r=lJ(e),i=lJ(t),{plainRelativeTo:a,zonedRelativeTo:o}=Xq(BX(n));if(Q(r,XG)===Q(i,XG)&&Q(r,ZG)===Q(i,ZG)&&Q(r,QG)===Q(i,QG)&&Q(r,$G)===Q(i,$G)&&Q(r,eK)===Q(i,eK)&&Q(r,tK)===Q(i,tK)&&Q(r,nK)===Q(i,nK)&&Q(r,rK)===Q(i,rK)&&Q(r,iK)===Q(i,iK)&&Q(r,aK)===Q(i,aK))return 0;let s=Zq(r),c=Zq(i),l=GY(r),u=GY(i);if(o&&(eJ(s)===`date`||eJ(c)===`date`)){let e=Q(o,YG),t=Q(o,GG),n=Q(o,VG),r=gX(n,e,t,l),i=gX(n,e,t,u);return zX(Z.default.toNumber(Z.default.subtract(r,i)))}let d=l.date.days,f=u.date.days;if($q(s)||$q(c)){if(!a)throw RangeError(`A starting point is required for years, months, or weeks comparison`);d=jY(l.date,a),f=jY(u.date,a)}let p=l.time.add24HourDays(d),m=u.time.add24HourDays(f);return p.cmp(m)}};EK(NZ,`Temporal.Duration`);var PZ=class{constructor(e,t,n=`iso8601`,r=1972){let i=tq(e),a=tq(t),o=UX(n===void 0?`iso8601`:aq(n)),s=tq(r);IY(s,i,a),xJ(this,{year:s,month:i,day:a},o)}get monthCode(){return FZ(this,`monthCode`)}get day(){return FZ(this,`day`)}get calendarId(){return $(this,xq),Q(this,GG)}with(e,t=void 0){if($(this,xq),!QK(e))throw TypeError(`invalid argument`);Cq(e);let n=Q(this,GG),r=rJ(n,Q(this,HG),`month-day`);return r=MJ(n,r,iJ(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),SJ(BJ(n,r,zq(BX(t))),n)}equals(e){$(this,xq);let t=dJ(e);return AX(Q(this,HG),Q(t,HG))===0&&LJ(Q(this,GG),Q(t,GG))}toString(e=void 0){return $(this,xq),aY(this,Uq(BX(e)))}toJSON(){return $(this,xq),aY(this)}toLocaleString(e=void 0,t=void 0){return $(this,xq),new gZ(e,t).format(this)}valueOf(){GX(`PlainMonthDay`)}toPlainDate(e){if($(this,xq),!QK(e))throw TypeError(`argument should be an object`);let t=Q(this,GG);return vJ(RJ(t,MJ(t,rJ(t,Q(this,HG),`month-day`),iJ(t,e,[`year`],[],[])),`constrain`),t)}static from(e,t=void 0){return dJ(e,t)}};function FZ(e,t){$(e,xq);let n=Q(e,HG);return nJ(e).isoToDate(n,{[t]:!0})[t]}function IZ(e){return GJ(e,LX())}EK(PZ,`Temporal.PlainMonthDay`);var LZ={instant:()=>OJ(LX()),plainDateTimeISO:(e=RX())=>bJ(IZ(VJ(e)),`iso8601`),plainDateISO:(e=RX())=>vJ(IZ(VJ(e)).isoDate,`iso8601`),plainTimeISO:(e=RX())=>wJ(IZ(VJ(e)).time),timeZoneId:()=>RX(),zonedDateTimeISO:(e=RX())=>{let t=VJ(e);return AJ(LX(),t,`iso8601`)},[Symbol.toStringTag]:`Temporal.Now`};Object.defineProperty(LZ,Symbol.toStringTag,{value:`Temporal.Now`,writable:!1,enumerable:!1,configurable:!0});var RZ=class e{constructor(e=0,t=0,n=0,r=0,i=0,a=0){let o=e===void 0?0:tq(e),s=t===void 0?0:tq(t),c=n===void 0?0:tq(n),l=r===void 0?0:tq(r),u=i===void 0?0:tq(i),d=a===void 0?0:tq(a);RY(o,s,c,l,u,d),CJ(this,{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d})}get hour(){return $(this,vq),Q(this,WG).hour}get minute(){return $(this,vq),Q(this,WG).minute}get second(){return $(this,vq),Q(this,WG).second}get millisecond(){return $(this,vq),Q(this,WG).millisecond}get microsecond(){return $(this,vq),Q(this,WG).microsecond}get nanosecond(){return $(this,vq),Q(this,WG).nanosecond}with(t,n=void 0){if($(this,vq),!QK(t))throw TypeError(`invalid argument`);Cq(t);let r=aJ(t,`partial`),i=aJ(this),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=Object.assign(i,r),d=zq(BX(n));return{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=Fq(a,o,s,c,l,u,d),new e(a,o,s,c,l,u)}add(e){return $(this,vq),xX(`add`,this,e)}subtract(e){return $(this,vq),xX(`subtract`,this,e)}until(e,t=void 0){return $(this,vq),dX(`until`,this,e,t)}since(e,t=void 0){return $(this,vq),dX(`since`,this,e,t)}round(e){if($(this,vq),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?VX(`smallestUnit`,e):BX(e),n=Wq(t),r=Vq(t,`halfExpand`),i=Yq(t,`smallestUnit`,`time`,Jq);return Gq(n,{hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i],!1),wJ(DX(Q(this,WG),n,i,r))}equals(e){$(this,vq);let t=fJ(e);return jX(Q(this,WG),Q(t,WG))===0}toString(e=void 0){$(this,vq);let t=BX(e),n=Kq(t),r=Vq(t,`trunc`),i=Yq(t,`smallestUnit`,`time`,void 0);if(i===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let{precision:a,unit:o,increment:s}=qq(i,n);return rY(DX(Q(this,WG),s,o,r),a)}toJSON(){return $(this,vq),rY(Q(this,WG),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,vq),new gZ(e,t).format(this)}valueOf(){GX(`PlainTime`)}static from(e,t=void 0){return fJ(e,t)}static compare(e,t){let n=fJ(e),r=fJ(t);return jX(Q(n,WG),Q(r,WG))}};EK(RZ,`Temporal.PlainTime`);var zZ=class{constructor(e,t,n=`iso8601`,r=1){let i=tq(e),a=tq(t),o=UX(n===void 0?`iso8601`:aq(n)),s=tq(r);IY(i,a,s),TJ(this,{year:i,month:a,day:s},o)}get year(){return BZ(this,`year`)}get month(){return BZ(this,`month`)}get monthCode(){return BZ(this,`monthCode`)}get calendarId(){return $(this,bq),Q(this,GG)}get era(){return BZ(this,`era`)}get eraYear(){return BZ(this,`eraYear`)}get daysInMonth(){return BZ(this,`daysInMonth`)}get daysInYear(){return BZ(this,`daysInYear`)}get monthsInYear(){return BZ(this,`monthsInYear`)}get inLeapYear(){return BZ(this,`inLeapYear`)}with(e,t=void 0){if($(this,bq),!QK(e))throw TypeError(`invalid argument`);Cq(e);let n=Q(this,GG),r=rJ(n,Q(this,HG),`year-month`);return r=MJ(n,r,iJ(n,e,[`year`,`month`,`monthCode`],[],`partial`)),EJ(zJ(n,r,zq(BX(t))),n)}add(e,t=void 0){return $(this,bq),SX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,bq),SX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,bq),fX(`until`,this,e,t)}since(e,t=void 0){return $(this,bq),fX(`since`,this,e,t)}equals(e){$(this,bq);let t=mJ(e);return AX(Q(this,HG),Q(t,HG))===0&&LJ(Q(this,GG),Q(t,GG))}toString(e=void 0){return $(this,bq),oY(this,Uq(BX(e)))}toJSON(){return $(this,bq),oY(this)}toLocaleString(e=void 0,t=void 0){return $(this,bq),new gZ(e,t).format(this)}valueOf(){GX(`PlainYearMonth`)}toPlainDate(e){if($(this,bq),!QK(e))throw TypeError(`argument should be an object`);let t=Q(this,GG);return vJ(RJ(t,MJ(t,rJ(t,Q(this,HG),`year-month`),iJ(t,e,[`day`],[],[])),`constrain`),t)}static from(e,t=void 0){return mJ(e,t)}static compare(e,t){let n=mJ(e),r=mJ(t);return AX(Q(n,HG),Q(r,HG))}};function BZ(e,t){$(e,bq);let n=Q(e,HG);return nJ(e).isoToDate(n,{[t]:!0})[t]}EK(zZ,`Temporal.PlainYearMonth`);var jye=gZ.prototype.resolvedOptions,VZ=class{constructor(e,t,n=`iso8601`){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);let r=IX(e),i=aq(t),{tzName:a,offsetMinutes:o}=Nq(i);if(o===void 0){let e=dY(a);if(!e)throw RangeError(`unknown time zone ${a}`);i=e.identifier}else i=mY(o);kJ(this,r,i,UX(n===void 0?`iso8601`:aq(n)))}get calendarId(){return $(this,Sq),Q(this,GG)}get timeZoneId(){return $(this,Sq),Q(this,YG)}get year(){return UZ(this,`year`)}get month(){return UZ(this,`month`)}get monthCode(){return UZ(this,`monthCode`)}get day(){return UZ(this,`day`)}get hour(){return WZ(this,`hour`)}get minute(){return WZ(this,`minute`)}get second(){return WZ(this,`second`)}get millisecond(){return WZ(this,`millisecond`)}get microsecond(){return WZ(this,`microsecond`)}get nanosecond(){return WZ(this,`nanosecond`)}get era(){return UZ(this,`era`)}get eraYear(){return UZ(this,`eraYear`)}get epochMilliseconds(){return $(this,Sq),PX(Q(this,VG),`floor`)}get epochNanoseconds(){return $(this,Sq),NX(Q(this,VG))}get dayOfWeek(){return UZ(this,`dayOfWeek`)}get dayOfYear(){return UZ(this,`dayOfYear`)}get weekOfYear(){return UZ(this,`weekOfYear`)?.week}get yearOfWeek(){return UZ(this,`weekOfYear`)?.year}get hoursInDay(){$(this,Sq);let e=Q(this,YG),t=HZ(this).isoDate,n=OY(t.year,t.month,t.day+1),r=YJ(e,t),i=YJ(e,n);return kX(NK.fromEpochNsDiff(i,r),`hour`)}get daysInWeek(){return UZ(this,`daysInWeek`)}get daysInMonth(){return UZ(this,`daysInMonth`)}get daysInYear(){return UZ(this,`daysInYear`)}get monthsInYear(){return UZ(this,`monthsInYear`)}get inLeapYear(){return UZ(this,`inLeapYear`)}get offset(){return $(this,Sq),WJ(UJ(Q(this,YG),Q(this,VG)))}get offsetNanoseconds(){return $(this,Sq),UJ(Q(this,YG),Q(this,VG))}with(e,t=void 0){if($(this,Sq),!QK(e))throw TypeError(`invalid zoned-date-time-like`);Cq(e);let n=Q(this,GG),r=Q(this,YG),i=UJ(r,Q(this,VG)),a=HZ(this),o={...rJ(n,a.isoDate),...a.time,offset:WJ(i)};o=MJ(n,o,iJ(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`],`partial`));let s=BX(t),c=Bq(s),l=Hq(s,`prefer`),u=sJ(n,o,zq(s)),d=lY(o.offset);return AJ(hJ(u.isoDate,u.time,`option`,d,r,c,l,!1),r,n)}withPlainTime(e=void 0){$(this,Sq);let t=Q(this,YG),n=Q(this,GG),r=HZ(this).isoDate,i;return i=e===void 0?YJ(t,r):KJ(t,Rq(r,Q(fJ(e),WG)),`compatible`),AJ(i,t,n)}withTimeZone(e){$(this,Sq);let t=VJ(e);return AJ(Q(this,VG),t,Q(this,GG))}withCalendar(e){$(this,Sq);let t=FJ(e);return AJ(Q(this,VG),Q(this,YG),t)}add(e,t=void 0){return $(this,Sq),CX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,Sq),CX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,Sq),pX(`until`,this,e,t)}since(e,t=void 0){return $(this,Sq),pX(`since`,this,e,t)}round(e){if($(this,Sq),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?VX(`smallestUnit`,e):BX(e),n=Wq(t),r=Vq(t,`halfExpand`),i=Yq(t,`smallestUnit`,`time`,Jq,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];if(Gq(n,a,a===1),i===`nanosecond`&&n===1)return AJ(Q(this,VG),Q(this,YG),Q(this,GG));let o=Q(this,YG),s=Q(this,VG),c=HZ(this),l;if(i===`day`){let e=c.isoDate,t=OY(e.year,e.month,e.day+1),n=YJ(o,e),i=YJ(o,t),a=Z.default.subtract(i,n);l=NK.fromEpochNsDiff(s,n).round(a,r).addToEpochNs(n)}else{let e=EX(c,n,i,r),t=UJ(o,s);l=hJ(e.isoDate,e.time,`option`,t,o,`compatible`,`prefer`,!1)}return AJ(l,o,Q(this,GG))}equals(e){$(this,Sq);let t=gJ(e),n=Q(this,VG),r=Q(t,VG);return!!Z.default.equal(Z.default.BigInt(n),Z.default.BigInt(r))&&!!HJ(Q(this,YG),Q(t,YG))&&LJ(Q(this,GG),Q(t,GG))}toString(e=void 0){$(this,Sq);let t=BX(e),n=Uq(t),r=Kq(t),i=function(e){return HX(e,`offset`,[`auto`,`never`],`auto`)}(t),a=Vq(t,`trunc`),o=Yq(t,`smallestUnit`,`time`,void 0);if(o===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let s=function(e){return HX(e,`timeZoneName`,[`auto`,`never`,`critical`],`auto`)}(t),{precision:c,unit:l,increment:u}=qq(o,r);return sY(this,c,n,s,i,{unit:l,increment:u,roundingMode:a})}toLocaleString(e=void 0,t=void 0){$(this,Sq);let n=BX(t),r=Object.create(null);if(function(e,t,n,r){if(t==null)return;let i=Reflect.ownKeys(t);for(let r=0;r<i.length;r++){let a=i[r];!n.some((e=>Object.is(e,a)))&&Object.prototype.propertyIsEnumerable.call(t,a)&&(e[a]=t[a])}}(r,n,[`timeZone`]),n.timeZone!==void 0)throw TypeError(`ZonedDateTime toLocaleString does not accept a timeZone option`);if(r.year===void 0&&r.month===void 0&&r.day===void 0&&r.era===void 0&&r.weekday===void 0&&r.dateStyle===void 0&&r.hour===void 0&&r.minute===void 0&&r.second===void 0&&r.fractionalSecondDigits===void 0&&r.timeStyle===void 0&&r.dayPeriod===void 0&&r.timeZoneName===void 0&&(r.timeZoneName=`short`),r.timeZone=Q(this,YG),cY(r.timeZone))throw RangeError(`toLocaleString does not currently support offset time zones`);let i=new gZ(e,r),a=jye.call(i).calendar,o=Q(this,GG);if(o!==`iso8601`&&a!==`iso8601`&&!LJ(a,o))throw RangeError(`cannot format ZonedDateTime with calendar ${o} in locale with calendar ${a}`);return i.format(OJ(Q(this,VG)))}toJSON(){return $(this,Sq),sY(this,`auto`)}valueOf(){GX(`ZonedDateTime`)}startOfDay(){$(this,Sq);let e=Q(this,YG);return AJ(YJ(e,HZ(this).isoDate),e,Q(this,GG))}getTimeZoneTransition(e){$(this,Sq);let t=Q(this,YG);if(e===void 0)throw TypeError(`options parameter is required`);let n=HX(typeof e==`string`?VX(`direction`,e):BX(e),`direction`,[`next`,`previous`],Jq);if(n===void 0)throw TypeError(`direction option is required`);if(cY(t)||t===`UTC`)return null;let r=Q(this,VG),i=n===`next`?yY(t,r):bY(t,r);return i===null?null:AJ(i,t,Q(this,GG))}toInstant(){return $(this,Sq),OJ(Q(this,VG))}toPlainDate(){return $(this,Sq),vJ(HZ(this).isoDate,Q(this,GG))}toPlainTime(){return $(this,Sq),wJ(HZ(this).time)}toPlainDateTime(){return $(this,Sq),bJ(HZ(this),Q(this,GG))}static from(e,t=void 0){return gJ(e,t)}static compare(e,t){let n=gJ(e),r=gJ(t),i=Q(n,VG),a=Q(r,VG);return Z.default.lessThan(Z.default.BigInt(i),Z.default.BigInt(a))?-1:+!!Z.default.greaterThan(Z.default.BigInt(i),Z.default.BigInt(a))}};function HZ(e){return GJ(Q(e,YG),Q(e,VG))}function UZ(e,t){$(e,Sq);let n=HZ(e).isoDate;return nJ(e).isoToDate(n,{[t]:!0})[t]}function WZ(e,t){return $(e,Sq),HZ(e).time[t]}EK(VZ,`Temporal.ZonedDateTime`);var Mye=Object.freeze({__proto__:null,Duration:NZ,Instant:DZ,Now:LZ,PlainDate:OZ,PlainDateTime:AZ,PlainMonthDay:PZ,PlainTime:RZ,PlainYearMonth:zZ,ZonedDateTime:VZ});(class{toTemporalInstant(){return OJ(FX(Date.prototype.valueOf.call(this)))}}).prototype.toTemporalInstant;var Nye=[DZ,OZ,AZ,NZ,PZ,RZ,zZ,VZ];for(let e of Nye){let t=Object.getOwnPropertyDescriptor(e,`prototype`);(t.configurable||t.enumerable||t.writable)&&(t.configurable=!1,t.enumerable=!1,t.writable=!1,Object.defineProperty(e,"prototype",t))}function Pye(e,t){let n=new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).formatToParts(e),r=e=>{let t=n.find(t=>t.type===e);if(!t)throw Error(`This timezone isn't recognised. Enter a timezone name like Europe/Tirane.`);return t.value};return`${r(`year`)}-${r(`month`)}-${r(`day`)}T${r(`hour`)}:${r(`minute`)}`}function Fye(e,t){return Pye(new Date(e),t)}function Iye(e,t){if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(e))throw Error(`Pick a date and time for the one-off run.`);let n=Mye.PlainDateTime.from(e,{overflow:`reject`}),r=n.toZonedDateTime(t,{disambiguation:`compatible`});if(!n.equals(r.toPlainDateTime()))throw Error(`That time is skipped in this timezone (a clock change). Choose another time.`);return r.toInstant().toString({smallestUnit:`millisecond`})}function GZ(e,t){return new Intl.DateTimeFormat(void 0,{timeZone:t,dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}function Lye(e,t){return new Intl.DateTimeFormat(void 0,{timeZone:t,year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,timeZoneName:`short`}).format(new Date(e))}var KZ={"claude-code":{name:`Claude Code`,command:`claude auth login`},codex:{name:`Codex`,command:`codex login`},gemini:{name:`Gemini`,command:`gemini`}},Rye=/not signed in|sign-in has expired|not logged in|run\s+"?(?:codex login|claude auth login)|authentication required/i,zye=/ENOSPC|no space left on device|disk (?:is )?full|not enough (?:free )?(?:disk )?space/i,Bye=/refused to make|content (?:rules|policy|filter)|safety (?:system|filter)|flagged|moderation/i,Vye=/\bunknown model\b|\bmodel\b[^\n]{0,80}?\b(?:not found|does not exist|retired|deprecated|decommissioned|no longer (?:available|supported)|is not available)/i,Hye=/did not accept the API key|API key is saved|invalid api key|key may be wrong/i,Uye=[`images`,`thumbnail`],Wye=/^Short \d+ image \d+:/;function qZ(e){let t=e.reason??``,n=Gye(e.provider,t);if(n!==void 0&&(Rye.test(t)||e.kind===`auth`))return{kind:`sign-in`,label:`Sign in to ${KZ[n].name}`,cli:n,command:KZ[n].command};if(zye.test(t))return{kind:`free-space`,label:`Free space`};if(e.kind===`refusal`||Bye.test(t))return Uye.includes(e.stage)||e.stage===`video`&&Wye.test(t)?{kind:`refused`,label:`Soften and retry`,soften:!0}:{kind:`refused`,label:`Edit the prompt`,soften:!1};if(Vye.test(t))return{kind:`switch-model`,label:`Switch model`};if(e.kind===`auth`||e.kind===`missing_key`||Hye.test(t)){let t=Kye(e.provider);return{kind:`provider-settings`,label:t===void 0?`Open Settings → Providers`:`Open Settings → Providers → ${t}`,provider:e.provider??``}}}function Gye(e,t){if(e===`claude-code`||e===`gemini`)return e;if(e===`codex`||e===`codex-image`||/Codex CLI/.test(t))return`codex`;if(/Claude Code CLI/.test(t))return`claude-code`;if(/Gemini CLI/.test(t))return`gemini`}function Kye(e){return zA.find(t=>t.id===e)?.displayName}function qye(e,t){switch(t){case`audio`:return e.audio?.provider;case`images`:case`thumbnail`:return e.images?.provider;case`research`:case`article`:return e.llm?.provider;default:return}}function Jye(e){let t=e.topics.error;if(t!==null)return qZ({stage:`article`,reason:t,provider:e.topicGeneration.llm?.provider})}function JZ({schedule:e,title:t,retry:n,className:r}){if(e.topics.error===null)return null;let i=Jye(e);return(0,h.jsx)(fM,{tone:`danger`,title:t,...r===void 0?{}:{className:r},...i===void 0?{}:{actions:(0,h.jsx)(Cz,{fix:i,retry:n,variant:`secondary`,size:`small`})},children:e.topics.error})}var YZ=e=>e.length===1?`“${e[0]?.title??``}”`:wG(e.length,`topic`,`topics`);function Yye({schedule:e}){let{api:t}=B(),n=_(),[r,i]=(0,m.useState)(null),a=Lv(),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(!1),u=e.deletedAt===null&&(e.status===`active`||e.status===`paused`),d=F({queryKey:[...NT(e.id),e.topics.held,e.topics.generatedAt],enabled:u&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await PT(t,e.id);if(!n.ok)throw Error(n.message);return n.value}}),f=F({queryKey:[`project-template`,e.templateId],enabled:u&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await MO(t,e.templateId);if(!n.ok)throw Error(n.message);return n.value}}).data?.document.form,p=(f===void 0?[]:tG(f)).filter(t=>t!==e.topicKeyword),g=t=>e.values[t]??f?.values[t]??``,v=d.data??[],y=yG(v.map(e=>e.id)),b=I({mutationFn:e=>e(),onSuccess:e=>{i(e.ok?null:e.message),e.ok&&s(null)},onError:e=>i(e.message),onSettled:async()=>{await Promise.all([n.invalidateQueries({queryKey:OT}),n.invalidateQueries({queryKey:NT(e.id)}),n.invalidateQueries({queryKey:VT})])}}),x=b.isPending,S=(e,t)=>b.mutate(e,{onSuccess:e=>{e.ok&&t!==void 0&&(y.clear(),a(t.message,`success`,t.undo===void 0?void 0:{label:`Undo`,run:t.undo}))}}),C=n=>S(()=>oce(t,e.id,n.map(e=>e.id)),{message:`Turned down ${YZ(n)}. Later generations won't suggest ${n.length===1?`it`:`them`} again.`,undo:()=>S(()=>sce(t,e.id,n),{message:`${YZ(n)} ${n.length===1?`is`:`are`} waiting again.`})}),w=n=>S(()=>n.length===1&&n[0]!==void 0?LT(t,e.id,n[0].id):ace(t,e.id,n.map(e=>e.id)),{message:`Approved ${YZ(n)}: added to the end of the queue.`}),T=v.filter(e=>y.has(e.id));if(!u||e.topicGeneration.mode===`off`)return null;let{topics:E}=e;return(0,h.jsxs)(`section`,{"aria-label":`Topic generation`,children:[(0,h.jsx)(vG,{className:`my-6`}),(0,h.jsxs)(U,{as:`h3`,title:`Topic generation`,meta:`${E.generatingSince===null?E.generatedAt===null?`No topics generated yet.`:`Topics last generated ${Lye(E.generatedAt,e.timezone)}.`:`Generating topics now…`} Keeps at least ${String(e.topicGeneration.keepAtLeast)} ${e.topicGeneration.mode===`hold`?`queued or waiting`:`queued`}.`,children:[(0,h.jsx)(H,{id:`planning.schedule.generate-now`}),(0,h.jsx)(z,{disabled:x||E.generatingSince!==null,disabledReason:`Topics are being generated now`,onClick:()=>b.mutate(()=>IT(t,e.id)),children:`Generate topics now`})]}),(0,h.jsx)(JZ,{schedule:e,title:`The last topic generation failed.`,className:`mt-3`,retry:{run:()=>b.mutate(()=>IT(t,e.id)),busy:x||E.generatingSince!==null}}),r===null?null:(0,h.jsx)(fM,{tone:`danger`,title:`That didn't work.`,className:`mt-3`,children:r}),e.topicGeneration.mode===`hold`?(0,h.jsxs)(`div`,{className:`mt-4`,...Py,children:[(0,h.jsxs)(U,{as:`h3`,title:`Topics waiting · ${String(v.length)}`,info:`planning.schedule.held`,children:[(0,h.jsx)(z,{variant:`primary`,disabled:x||v.length===0,disabledReason:`Nothing is waiting`,onClick:()=>S(()=>RT(t,e.id),{message:`Approved ${YZ(v)}: added to the end of the queue.`}),children:`Approve all`}),(0,h.jsx)(z,{variant:`quiet`,disabled:x||v.length===0,disabledReason:`Nothing is waiting`,onClick:()=>l(!0),children:`Reject all`})]}),d.error?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-danger`,children:`The waiting topics couldn't be loaded: ${d.error.message} Reload the page to try again.`}):v.length===0?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-ink-3`,children:`Nothing is waiting. New topics appear here for you to approve.`}):(0,h.jsxs)(`div`,{onKeyDown:y.onKeyDown,children:[v.length>1?(0,h.jsx)(CG,{className:`mt-2`,selection:y,total:v.length,noun:[`topic waiting`,`topics waiting`],actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{size:`small`,disabled:x||T.length===0,disabledReason:`Tick the topics to approve`,onClick:()=>w(T),children:`Approve selected`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:x||T.length===0,disabledReason:`Tick the topics to turn down`,onClick:()=>C(T),children:`Reject selected`})]})}):null,(0,h.jsx)(qL,{label:`Topics waiting`,className:`mt-2 [&_.sl-row__actions]:flex-wrap`,children:v.map(n=>(0,h.jsx)(EG,{topic:n,editing:o?.id===n.id?o:void 0,keywords:p,everyRun:g,busy:x,selection:y,onEdit:s,onCancel:()=>s(null),onSave:()=>{o!==null&&b.mutate(()=>lce(t,e.id,n.id,o.title.trim(),Object.fromEntries(Object.entries(o.values).filter(([,e])=>e.trim()!==``))))},onApprove:()=>w([n]),onReject:()=>C([n])},n.id))})]}),(0,h.jsx)($v,{open:c,title:`Reject all ${wG(v.length,`waiting topic`,`waiting topics`)}?`,consequence:`Turns down the ${wG(v.length,`topic`,`topics`)} waiting for ${e.name} now (topics generated after this list was shown are not included). Later generations won't suggest them again; Undo in the message that follows brings them back.`,confirmLabel:`Reject ${wG(v.length,`topic`,`topics`)}`,cancelLabel:`Keep them waiting`,pending:x,onCancel:()=>l(!1),onConfirm:()=>{l(!1),C(v)}})]}):null]})}function XZ(e){return e.filter(e=>e.deletedAt===null&&e.topicGeneration.mode!==`off`&&(e.status===`active`||e.status===`paused`))}function Xye({schedules:e}){let t=XZ(e),n=e.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:t.length===0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(U,{title:`Suggested topics`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No schedule suggests its own topics yet. Turn on topic generation in a schedule and its suggestions wait here for you.`}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:n.length===0?(0,h.jsx)(KO,{to:`/calendar`,search:{tab:`schedules`},children:`Open schedules`}):n.slice(0,4).map(e=>(0,h.jsxs)(KO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:[`Open `,e.name]},e.id))})]}):t.map((e,t)=>(0,h.jsx)(Zye,{schedule:e,first:t===0},e.id))})}function Zye({schedule:e,first:t}){let{api:n}=B(),r=_(),i=Lv(),a=F({queryKey:[...NT(e.id),e.topics.held,e.version],queryFn:async()=>{let t=await PT(n,e.id);if(!t.ok)throw Error(t.message);return t.value},enabled:e.topics.held>0}),o=I({mutationFn:e=>e(),onSuccess:e=>{e.ok||i(e.message,`error`)},onError:e=>i(`The topics weren't changed: ${e.message} Try again in a moment.`,`error`),onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:OT}),r.invalidateQueries({queryKey:VT}),r.invalidateQueries({queryKey:NT(e.id)})])}}),s=e.topics.held>0?a.data??[]:[],c=()=>o.mutate(()=>RT(n,e.id));cb({id:`calendar.approve-all.${e.id}`,title:`Queue all suggested topics`,group:`Calendar`,context:e.name,keywords:[`approve`,`suggestions`,`topics`],run:c});let l=e.topics.generatingSince!==null,u=e.topicGeneration.mode===`hold`;return(0,h.jsxs)(`section`,{"aria-label":`Suggested topics for ${e.name}`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{title:t?`Suggested topics`:e.name,kicker:t?e.name:void 0,meta:`From the series brief · not made or queued before`,info:`planning.schedule.held`,children:s.length>0?(0,h.jsx)(z,{size:`small`,variant:`secondary`,disabled:o.isPending,onClick:c,children:`Queue all ${String(s.length)}`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{id:`planning.schedule.generate-now`,label:`Suggest topics now`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:o.isPending||l,disabledReason:l?`Slopify is suggesting topics now.`:`Working…`,onClick:()=>o.mutate(()=>IT(n,e.id)),children:l?`Suggesting…`:`Suggest topics now`})]})}),(0,h.jsx)(JZ,{schedule:e,title:`The last suggestion failed.`,retry:{run:()=>o.mutate(()=>IT(n,e.id)),busy:o.isPending||l}}),a.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The suggestions didn't load: ${a.error.message} Reload the page to try again.`}),s.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:l?`Slopify is asking for new topics. They appear here when it finishes.`:`No suggestions are waiting.`}):(0,h.jsx)(qL,{label:`Suggestions for ${e.name}`,children:s.map(t=>(0,h.jsx)(JL,{title:t.title,meta:TG(t.values),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:o.isPending,onClick:()=>o.mutate(()=>LT(n,e.id,t.id)),"aria-label":`Queue ${t.title}`,children:`Queue`}),(0,h.jsx)(Nv,{size:`small`,label:`Reject ${t.title}`,disabled:o.isPending,onClick:()=>o.mutate(()=>cce(n,e.id,t.id)),children:(0,h.jsx)(kl,{"aria-hidden":`true`,strokeWidth:1.75})})]})},t.id))}),(0,h.jsx)(fM,{title:`Keeps at least ${String(e.topicGeneration.keepAtLeast)} ${e.topicGeneration.keepAtLeast===1?`topic`:`topics`} queued.`,children:u?`New suggestions wait here for you. Change this under Schedules → Edit.`:`New suggestions join the queue straight away. Change this under Schedules → Edit.`})]})}function Qye(e,t){if(e.kind===`move`)return{kind:`move`,scheduleId:e.scheduleId,baseVersion:t.source.version,from:e.to,to:e.from};let n=t.target??t.source;return{kind:`transfer`,scheduleId:e.targetId,baseVersion:n.version,index:e.position??n.items.length-1,targetId:e.scheduleId,position:e.index}}function $ye(e,t){if(t.kind!==`move`)return e;let n=e.runs.filter(e=>e.scheduleId===t.scheduleId&&e.index!==null).toSorted((e,t)=>(e.index??0)-(t.index??0)),r=n.map(ebe),[i]=r.splice(t.from,1);if(i===void 0)return e;r.splice(t.to,0,i);let a=new Map(n.map((e,t)=>[e,r[t]]));return{...e,runs:e.runs.map(e=>{let t=a.get(e);return t===void 0?e:{...e,...t}})}}function ebe(e){return{topic:e.topic,topicSource:e.topicSource,renderedTitle:e.renderedTitle,prepared:e.prepared}}function tbe(e,t){let{api:n}=B(),r=_(),i=Lv(),a=I({mutationFn:async({drop:e})=>{if(e.kind===`move`){let t=await zT(n,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to});return t.ok?{ok:!0,value:{source:t.value}}:t}return uce(n,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}})},onMutate:async({drop:n})=>{await r.cancelQueries({queryKey:e});let i=r.getQueryData(e);return i!==void 0&&r.setQueryData(e,$ye(i,n)),t(null),{before:i}},onSuccess:(n,o,s)=>{if(!n.ok){s.before!==void 0&&r.setQueryData(e,s.before),t(`${o.title} wasn't moved: ${n.message} The calendar shows where it is now; move it again if you still want to.`);return}if(o.undo===!0){i(`${o.title} is back where it was.`,`success`);return}i(`Moved ${o.title} to ${o.where}.`,`success`,{label:`Undo`,run:()=>a.mutate({drop:Qye(o.drop,n.value),title:o.title,where:``,undo:!0})})},onError:(n,i,a)=>{a?.before!==void 0&&r.setQueryData(e,a.before),t(`${i.title} wasn't moved: ${n.message} The calendar has been read again; try the move once more.`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:VT}),r.invalidateQueries({queryKey:OT})])}});return a}var ZZ=[`trash`];async function QZ(e){return(await L(await e.client.trash.$get())).items}async function $Z(e,t,n){return(await L(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function nbe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await po(r)}async function eQ(e,t){return L(await e.client.trash.bulk.restore.$post({json:{items:[...t]}}))}async function rbe(e,t){return L(await e.client.trash.bulk.delete.$post({json:{items:[...t]}}))}var tQ=[`batch-queue`];function ibe(){let{api:e}=B(),t=F({queryKey:tQ,queryFn:async()=>L(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=F(_y(e)),r=t.data?.queue.length,i=r===void 0?t.error===null?`…`:`?`:String(r);return(0,h.jsxs)(jy,{children:[(0,h.jsx)(My,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,disabled:r===0&&t.error===null,disabledReason:`Nothing is queued`,"aria-label":r===void 0?t.error===null?`Video queue: loading`:`Video queue: didn't load`:`Video queue: ${String(r)} remaining`,children:[(0,h.jsx)(il,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,i]})]})}),(0,h.jsxs)(Ny,{align:`end`,className:`p-0`,children:[(0,h.jsx)(`p`,{className:`border-b border-line px-3 py-2 text-small text-ink-2`,children:Oy(`play.queue`).body}),(0,h.jsx)(`div`,{className:`px-3 py-2 empty:hidden`,children:(0,h.jsx)(PL,{query:t,what:`The video queue`,compact:!0,loading:null,children:()=>null})}),(0,h.jsx)(abe,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function abe({queue:e,projects:t}){let n=e.filter(e=>e.state===`queued`);return(0,h.jsx)(`ol`,{className:`max-h-60 overflow-y-auto px-4 py-2`,children:e.map((e,r)=>{let i=t?.find(t=>t.id===e.projectId),a=i?.title??`Video`;return(0,h.jsxs)(`li`,{className:`flex items-center justify-between gap-2 py-1 text-small`,children:[(0,h.jsxs)(pa,{className:`min-w-0 truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[r+1,`. `,a]}),(0,h.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-ink-2`,children:[i?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`,e.state===`queued`?(0,h.jsx)(nQ,{projectId:e.projectId,title:a,place:n.indexOf(e),waiting:n.length}):null]})]},e.projectId)})})}function nQ({projectId:e,title:t,place:n,waiting:r}){let{api:i}=B(),a=_(),o=Lv(),s=()=>{a.invalidateQueries({queryKey:tQ}),a.invalidateQueries({queryKey:[`projects`]}),a.invalidateQueries({queryKey:[`calendar`]})},c=I({mutationFn:t=>obe(i,e,t),onSuccess:s,onError:e=>{s(),o(`${t} wasn't moved: ${e.message}`,`error`)}}),l=I({mutationFn:()=>Fo(i,e),onSuccess:()=>{s(),o(`${t} left the queue and is in Settings → Trash.`,`success`,{label:`Undo`,run:()=>void $Z(i,`project`,e).then(s,e=>o(`${t} wasn't put back: ${e.message} Restore it from Settings → Trash.`,`error`))})},onError:e=>o(`${t} wasn't removed: ${e.message}`,`error`)}),u=c.isPending||l.isPending;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Nv,{size:`small`,label:`Move ${t} earlier in the queue`,disabled:u||n<=0,onClick:()=>c.mutate(-1),children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{size:`small`,label:`Move ${t} later in the queue`,disabled:u||n>=r-1,onClick:()=>c.mutate(1),children:(0,h.jsx)(bc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Nv,{size:`small`,label:`Remove ${t} from the queue`,disabled:u,onClick:()=>l.mutate(),children:(0,h.jsx)(kl,{"aria-hidden":`true`,strokeWidth:1.75})})]})}async function obe(e,t,n){return L(await e.fetch(`${e.origin}/api/projects/queue/${encodeURIComponent(t)}/move`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({by:n})}))}var rQ=`sl-tab inline-flex items-center gap-[6px]`;function iQ({items:e,value:t,onChange:n,label:r,idPrefix:i,trailing:a,className:o}){let s=(0,m.useRef)(null);return pG(s,t),(0,h.jsxs)(`div`,{className:R(`flex min-w-0 items-end gap-3 border-b border-line`,o),"data-slot":`tabs`,children:[(0,h.jsx)(`div`,{ref:s,role:`tablist`,"aria-label":r,onKeyDown:r=>{let a=e.filter(e=>!e.disabled),o=a.findIndex(e=>e.id===t),c=r.key===`ArrowRight`?a[(o+1)%a.length]:r.key===`ArrowLeft`?a[(o-1+a.length)%a.length]:r.key===`Home`?a[0]:r.key===`End`?a[a.length-1]:void 0;c&&(r.preventDefault(),n(c.id),s.current?.querySelector(`#${i}-tab-${c.id}`)?.focus())},className:`sl-tabs min-w-0 flex-1 border-b-0`,children:e.map(e=>(0,h.jsxs)(`button`,{id:`${i}-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":e.id===t,"aria-controls":`${i}-panel-${e.id}`,tabIndex:e.id===t?0:-1,disabled:e.disabled,onClick:()=>n(e.id),className:rQ,children:[e.label,e.badge===void 0?null:(0,h.jsx)(`span`,{className:`sl-tab__count ml-0`,children:e.badge})]},e.id))}),a?(0,h.jsx)(`div`,{className:`flex shrink-0 items-center gap-2 pb-1`,children:a}):null]})}function sbe({items:e,label:t,className:n}){let r=(0,m.useRef)(null);return pG(r,Ha({select:e=>e.pathname})),(0,h.jsx)(`nav`,{ref:r,"aria-label":t,className:R(`sl-tabs min-w-0`,n),children:e.map(e=>(0,h.jsx)(pa,{to:e.to,...e.search?{search:e.search}:{},activeOptions:{exact:!1,includeSearch:!1},className:rQ,activeProps:{"aria-current":`page`},children:e.label},e.to))})}function aQ({idPrefix:e,id:t,active:n,children:r,className:i}){return(0,h.jsx)(`div`,{id:`${e}-panel-${t}`,role:`tabpanel`,"aria-labelledby":`${e}-tab-${t}`,hidden:!n,className:i,children:r})}function oQ({title:e,children:t,actions:n,className:r}){return(0,h.jsxs)(`div`,{className:R(`sl-empty`,r),"data-slot":`empty-state`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title`,children:e}),t===void 0?null:(0,h.jsx)(`p`,{children:t}),n===void 0?null:(0,h.jsx)(`div`,{className:`sl-btn-row`,children:n})]})}function sQ(e){return e.channelId??`00000000-0000-4000-8000-000000000001`}function cbe({channelId:e}){let{api:t}=B(),n=_(),r=F(jO(t)),i=F(Xy(t)),a=I({mutationFn:e=>xre(t,e.templateId,e.channelId),onSettled:()=>Promise.all([n.invalidateQueries({queryKey:DO}),n.invalidateQueries({queryKey:Ky})])}),o=(r.data??[]).filter(t=>sQ(t)===e);return(0,h.jsxs)(`div`,{...Py,children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:[`Runs from these templates use this channel's brand kit and cast. Save new ones from Play in`,` `,(0,h.jsx)(pa,{to:`/templates`,className:`underline`,children:`Library → Templates`}),`. Move to sends a template and its schedules to another channel.`,` `,(0,h.jsx)(H,{id:`planning.channel.template-move`,className:`-my-1 align-middle`})]}),(0,h.jsx)(CR,{tone:a.error||r.error?`error`:`info`,className:`mb-2`,children:a.error?.message??r.error?.message}),r.data&&o.length===0?(0,h.jsx)(oQ,{title:`No templates in this channel`,children:`Pick this channel on Play, then save the setup as a template, or move one here from another channel.`}):null,o.length>0?(0,h.jsx)(qL,{label:`Channel templates`,className:`[&_.sl-row__actions]:flex-wrap`,children:o.map(t=>(0,h.jsx)(JL,{title:t.name,meta:`Version ${String(t.version)}`,actions:(0,h.jsxs)(`span`,{className:`flex items-center gap-2 text-small text-ink-2`,children:[`Move to`,(0,h.jsx)(cL,{"aria-label":`Channel of ${t.name}`,value:e,disabled:a.isPending,onChange:e=>a.mutate({templateId:t.id,channelId:e.target.value}),options:(i.data??[]).map(e=>({value:e.id,label:e.name}))})]})},t.id))}):null]})}function lbe({channelId:e}){let{api:t}=B(),n=F(jO(t)),r=F(kT(t)),i=new Set((n.data??[]).filter(t=>sQ(t)===e).map(e=>e.id)),a=(r.data??[]).filter(e=>e.deletedAt===null&&i.has(e.templateId));return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:[`A schedule belongs to the channel of the template it runs. Create and change schedules in`,` `,(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`schedules`},className:`underline`,children:`Calendar → Schedules`}),`.`]}),(0,h.jsx)(CR,{tone:r.error?`error`:`info`,className:`mb-2`,children:r.error?.message}),r.data&&a.length===0?(0,h.jsx)(oQ,{title:`No schedules run this channel's templates`,children:`Make one in Calendar → Schedules from one of this channel's templates.`}):null,a.length>0?(0,h.jsx)(qL,{label:`Channel schedules`,children:a.map(e=>(0,h.jsx)(JL,{title:(0,h.jsx)(KO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name}),meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(tk,{tone:VL[e.status].tone,children:VL[e.status].word}),` · ${e.nextRunAt===null?`No next run`:`Next run ${GZ(e.nextRunAt,e.timezone)}`} · ${String(e.items.length)} queued`]})},e.id))}):null]})}function cQ(e,t,n){let r=new Intl.NumberFormat(`en-US`),i=e-t,a=`${r.format(e)} of ${r.format(t)} ${n}`;return i>0?`${a}: ${r.format(i)} over the limit, shorten it to save.`:a}function lQ(e){return eD(e)?`script`:`article`}function ube(e){let{form:t}=e,n=[],r=[];if(mQ(n,t.title),lD(t)&&mQ(n,fQ(e.prompts,`narration`,t.narrationPrompt??``)),t.sources.article===`generate`&&mQ(n,fQ(e.prompts,lQ(t),t.articlePrompt)),t.sources.audio===`generate`&&(mQ(n,pQ(e.entries,`intro`,t.intro)),mQ(n,pQ(e.entries,`outro`,t.outro))),uD(t)&&mQ(n,fQ(e.prompts,`description`,t.descriptionPrompt??``)),$k(t)&&(mQ(n,fQ(e.prompts,`shorts`,t.shorts?.prompt??``)),mQ(r,fQ(e.prompts,`image`,t.shorts?.imagePrompt??``))),t.sources.images===`generate`){for(let n of t.imagePrompts)mQ(r,fQ(e.prompts,`image`,n.name));t.reference?.source===`prompt`&&mQ(r,fQ(e.prompts,`image`,t.reference.prompt))}return(t.sources.thumbnail===`from_prompt`||t.sources.thumbnail===`prompt_by_llm`)&&mQ(r,fQ(e.prompts,`thumbnail`,t.thumbnailPrompt)),ZW(n,r)}function dbe(e){let t=ube(e),n={form:e.form,entries:e.entries,slots:t.map(e=>e.name),silenceGapSeconds:e.silenceGapSeconds},r=iA(n),i=lle({draft:r,staged:wue(e.form.provided),requiredSlots:n.slots}),a=Qk(r.subtitles??e.form.subtitles)?i:{ok:!1,fields:[...i.ok?[]:i.fields,{field:`subtitles.fontSize`,message:`Choose a whole subtitle font size from 16 to 120.`}]};return{fields:t,draft:r,result:a,blocker:fbe(e.form,a)}}var uQ=`sources,provided.research,articlePrompt,provided.article,audio,provided.audio,voices,narrationPrompt,imagePrompts,images,provided.images,reference,provided.reference,thumbnailPrompt,provided.thumbnail,subtitles,title,intro,outro,llm,values,silenceGapSeconds,edgeSilenceSeconds,imageSeconds,zoomPercent,motionStyle,youtubeDescription,descriptionPrompt,shorts.enabled,shorts.count,shorts.minSeconds,shorts.maxSeconds,shorts.prompt,shorts.imagePrompt,shorts.speed,shorts.musicVolume,shorts.music,shorts.fullVideoLink,videoEdit.transitionSeconds,videoEdit.chapterCards,videoEdit.animate,videoEdit.animateEvery,videoEdit.animateModel,ambientBed,sentencePauseSeconds,paragraphPauseSeconds,loudness.videoLufs,loudness.audioFilesLufs`.split(`,`);function fbe(e,t){let n=pbe(e);if(n!==void 0)return n;if(t.ok)return;let r=[...t.fields].sort((e,t)=>dQ(e.field)-dQ(t.field))[0];return r===void 0?void 0:{field:r.field,hint:mbe(e,r)}}function pbe(e){let{sources:t,provided:n}=e,r=[];if(t.audio===`provide`&&n.audio!==void 0&&r.push(n.audio),t.images===`provide`&&r.push(...n.images),t.thumbnail===`provide`&&n.thumbnail!==void 0&&r.push(n.thumbnail),t.images===`generate`&&e.reference?.source===`provide`&&n.reference!==void 0&&r.push(n.reference),$k(e)&&n.shortsMusic!==void 0&&r.push(n.shortsMusic),eA(e)&&n.ambientBed!==void 0&&r.push(n.ambientBed),r.some(e=>e.error!==void 0))return{field:`provided`,hint:`Remove the upload that failed to play`};if(r.some(e=>e.file===void 0))return{field:`provided`,hint:`Wait for the uploads to finish to play`}}function dQ(e){let t=uQ.length;for(let[n,r]of uQ.entries())(e===r||e.startsWith(`${r}.`))&&n<t&&(t=n);return t}function mbe(e,t){if(t.field.startsWith(`values.`))return`Fill ${t.field.slice(7)} to play`;if(t.field.startsWith(`imagePrompts.`))return t.field.endsWith(`.number`)?`Set a Number between 1 and 20 to play`:`Pick an image prompt to play`;switch(t.field){case`title`:return e.title.trim()===``?`Name the video to play`:`Shorten the title to 200 characters to play`;case`imagePrompts`:return e.imagePrompts.length===0?`Tick an image prompt to play`:`Lower the Numbers to play: a run makes at most 60 images`;case`llm`:return`Pick an LLM provider and model to play`;case`articlePrompt`:return lQ(e)===`script`?`Pick a script prompt to play`:`Pick an article prompt to play`;case`audio`:return`Pick a narration provider to play`;case`audio.voice`:return`Pick a voice to play`;case`images`:return`Pick an image provider and model to play`;case`thumbnailPrompt`:return`Pick a thumbnail prompt to play`;case`youtubeDescription`:return`Turn narration on, or the YouTube description off, to play`;case`shorts.enabled`:return`Turn narration on, or Shorts off, to play`;case`shorts.count`:return`Set how many shorts to make to play`;case`shorts.minSeconds`:case`shorts.maxSeconds`:return`Set the shorts' length to play`;case`shorts.speed`:return`Choose the shorts' speed to play`;case`shorts.musicVolume`:return`Set the shorts' music volume to play`;case`shorts.music`:return`Attach the shorts' background music again, or remove it, to play`;case`shorts.fullVideoLink`:return`Fix the full video link to play`;case`provided.research`:return`Paste your text under Article to play`;case`provided.article`:return`Paste the article to play`;case`provided.audio`:return`Attach the narration audio to play`;case`provided.images`:return e.provided.images.length>60?`Remove images to play: a run holds at most 60`:`Attach at least one image to play`;case`provided.thumbnail`:return`Attach the thumbnail image to play`;case`reference.prompt`:return`Pick the establishing image's prompt to play`;case`provided.reference`:return`Attach the establishing image to play`;default:return t.message}}function fQ(e,t,n){if(n!==``)return e.find(e=>e.kind===t&&e.name===n)?.body}function pQ(e,t,n){if(n!==``)return e.find(e=>e.category===t&&e.name===n)?.body}function mQ(e,t){t!==void 0&&e.push(t)}function hQ(e){let t=new Map,n=(e,n)=>{if(e)for(let r of YW(e).names){let e=t.get(r)??[];e.includes(n)||e.push(n),t.set(r,e)}},{form:r,prompts:i,entries:a}=e;if(n(r.title,`Project title`),lD(r)&&n(fQ(i,`narration`,r.narrationPrompt??``),`Narration Preparation`),r.sources.article===`generate`&&n(fQ(i,lQ(r),r.articlePrompt),`Article`),r.sources.images===`generate`){for(let e of r.imagePrompts)n(fQ(i,`image`,e.name),`Image: ${e.name}`);r.reference?.source===`prompt`&&n(fQ(i,`image`,r.reference.prompt),`Establishing image`)}if((r.sources.thumbnail===`from_prompt`||r.sources.thumbnail===`prompt_by_llm`)&&n(fQ(i,`thumbnail`,r.thumbnailPrompt),`Thumbnail`),r.sources.audio===`generate`)for(let e of[`intro`,`outro`])n(pQ(a,e,r[e]),e===`intro`?`Intro`:`Outro`);return uD(r)&&n(fQ(i,`description`,r.descriptionPrompt??``),`YouTube description`),$k(r)&&(n(fQ(i,`shorts`,r.shorts?.prompt??``),`Shorts`),n(fQ(i,`image`,r.shorts?.imagePrompt??``),`Shorts images`)),t}var gQ=[`name`,`template`,`once`,`time`,`weekdays`,`timezone`,`spend`,`topics`,`brief`,`generation`],hbe={name:`schedule-name`,template:`schedule-template`,once:`schedule-once`,time:`schedule-time`,weekdays:`schedule-weekdays`,timezone:`schedule-timezone`,spend:`schedule-spend`,topics:`schedule-topics`,brief:`schedule-brief`,generation:`schedule-generation`},gbe={name:`Name`,template:`Template`,once:`Run at`,time:`Local time`,weekdays:`Weekdays`,timezone:`Timezone`,spend:`Spend ceiling`,topics:`Topics`,brief:`Series brief`,generation:`Topic generation`};function _be(e){let t={};return e.name.trim()===``&&(t.name=`Give the schedule a name.`),e.templateChosen||(t.template=`Choose the template each run starts from.`),e.kind===`once`&&e.onceAt===``&&(t.once=`Pick the date and time of the one run.`),e.kind!==`once`&&e.time===``&&(t.time=`Pick the time of day runs start.`),e.kind===`weekly`&&e.days.length===0&&(t.weekdays=`Choose at least one weekday for a weekly schedule.`),fT(e.timezone.trim())||(t.timezone=`Enter a timezone name like Europe/Tirane or America/New_York; start typing to see the list.`),_Q(e.spend)===void 0&&(t.spend=`Enter the ceiling in US dollars, such as 5 or 2.50, or leave it empty for no ceiling.`),e.topicProblems.length>0?t.topics=`Fix the topics first. ${e.topicProblems.slice(0,3).join(` `)}`:e.topicCount>500&&(t.topics=`Keep the list to 500 topics or fewer; it has ${String(e.topicCount)}.`),e.brief.trim().length>4e3&&(t.brief=`Keep the series brief to ${String(vT)} characters or fewer.`),e.generationLlm!==null&&(e.generationLlm.provider===``||e.generationLlm.model===``)&&(t.generation=`Pick both a provider and a model for topic generation, or tick Use the template's LLM.`),t}function vbe(e){return gQ.find(t=>e[t]!==void 0)}function ybe(e){return gQ.filter(t=>e[t]!==void 0).map(t=>`${gbe[t]}: ${e[t]??``}`).join(` `)}function _Q(e){let t=e.trim().replace(/^\$/,``);if(t===``)return null;if(/^\d+(\.\d{1,2})?$/.test(t))return Math.round(Number(t)*100)}function bbe(e){return e==null?``:e%100==0?String(e/100):(e/100).toFixed(2)}function xbe(){try{return typeof Intl.supportedValuesOf==`function`?Intl.supportedValuesOf(`timeZone`):[]}catch{return[]}}var Sbe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],vQ=J({day:K().int().min(0).max(6),time:G().regex(/^([01]\d|2[0-3]):[0-5]\d$/)}),Cbe=J({name:G().trim().min(1).max(20),series:G().trim().max(100).default(``),long:vQ,shorts:q(vQ).max(10),schedule:G().optional(),runDay:K().int().min(0).max(6).optional(),timeZone:G().optional(),label:G().optional()});J({timeZone:G().min(1).max(100),rows:q(Cbe).max(14)});var wbe=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Tbe=[1,2,3,4,5,6,0];function yQ(e,t){return{day:(e+1+Math.floor(t/2))%7,time:t%2==0?`12:00`:`17:00`}}function Ebe(e,t){return{day:e,long:{day:e,time:`20:00`},shorts:Array.from({length:t},(t,n)=>yQ(e,n))}}function bQ(e,t,n){return Tbe.filter(e=>t.includes(e)).map(t=>{let r=e.find(e=>e.day===t)??Ebe(t,n);return{...r,shorts:Array.from({length:n},(e,n)=>r.shorts[n]??yQ(t,n))}})}function xQ({value:e,label:t,onChange:n}){return(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`w-[64px] shrink-0 text-small text-ink-3`,children:t}),(0,h.jsx)(cL,{"aria-label":`${t}: day`,className:`w-[84px]`,value:String(e.day),onChange:t=>n({...e,day:Number(t.currentTarget.value)}),options:Sbe.map((e,t)=>({value:String(t),label:e}))}),(0,h.jsx)(X,{"aria-label":`${t}: time`,type:`time`,className:`w-[124px]`,value:e.time,onChange:t=>n({...e,time:t.currentTarget.value||e.time})})]})}function Dbe({releases:e,onReleases:t,runDays:n,shorts:r,once:i,timezone:a}){let o=e===null?[]:bQ(e,n,r),s=(e,n)=>t(o.map(t=>t.day===e?n:t));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`,...Py,children:[(0,h.jsx)(`legend`,{className:`float-left mb-1 w-full text-title-3 font-semibold`,children:`Release times`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i?`A one-time schedule has no release times: set the project's in its Video section once it is done.`:`When each run's project goes out on YouTube, in ${a}. Each short goes out the first time its day and hour come round after the one before it. Calendar → Releases shows them, and the Studio extension types them into Studio.`}),i?null:e===null?(0,h.jsx)(`div`,{children:(0,h.jsx)(z,{variant:`secondary`,onClick:()=>t(bQ([],n,r)),disabled:n.length===0,children:`Set release times`})}):(0,h.jsxs)(h.Fragment,{children:[o.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-line pb-3 last:border-b-0`,children:[(0,h.jsxs)(`div`,{className:`text-small font-semibold`,children:[wbe[e.day],`'s run`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2`,children:[(0,h.jsx)(xQ,{label:`Video`,value:e.long,onChange:t=>s(e.day,{...e,long:t})}),e.shorts.map((t,n)=>(0,h.jsx)(xQ,{label:`Short ${String(n+1)}`,value:t,onChange:t=>s(e.day,{...e,shorts:e.shorts.map((e,r)=>r===n?t:e)})},n))]})]},e.day)),r===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The template makes no shorts, so only the long video has a time.`}):null,(0,h.jsx)(`div`,{children:(0,h.jsx)(z,{variant:`quiet`,onClick:()=>t(null),children:`Set no release times`})})]})]})}function SQ(e){let t=[e.feeds.length===0?`Not used by any picked prompt`:`Feeds ${e.feeds.join(` · `)}`,...e.topic?[`left empty in templates`]:[]].join(` · `);return e.note===void 0?t:`${t}. ${e.note}`}function CQ({keywords:e,onChange:t,problem:n,fieldPrefix:r=`values`,empty:i,label:a=e=>e,inputLabel:o,tip:s=`play.keyword`,maxLength:c=200}){if(e.length===0)return i===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i});let l=SQ;return t===void 0?(0,h.jsx)(qL,{label:`Keywords`,children:e.map(e=>(0,h.jsx)(JL,{title:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`code`,{className:`sl-code`,children:`{{${e.name}}}`}),` `,e.value===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:e.topic?`the topic`:`empty`}):e.value]}),meta:l(e)},e.name))}):(0,h.jsx)(`div`,{"data-tour":`play-keywords`,className:`grid min-w-0 grid-cols-1 gap-4 min-[700px]:grid-cols-2`,children:e.map(e=>(0,h.jsx)(aL,{label:a(e.name),tip:s,help:l(e),error:n?.(`${r}.${e.name}`),children:(0,h.jsx)(X,{"data-play-field":`${r}.${e.name}`,value:e.value,maxLength:c,...o===void 0?{}:{"aria-label":o(e.name)},spellCheck:e.topic===!0,"aria-invalid":n?.(`${r}.${e.name}`)!==void 0,onChange:n=>t(e.name,n.target.value)})},e.name))})}var wQ={lines:`One per line`,table:`Table`,yaml:`YAML / JSON`};function TQ(e){return{mode:`lines`,rows:e,lines:uG(e),base:e,yaml:``,columns:EQ(e,[])}}function EQ(e,t){return[...new Set([...t,...e.flatMap(e=>Object.keys(e.values))])]}function DQ(e){return e.keywords.filter(t=>t!==e.topicKeyword&&(e.everyRun[t]??``).trim()===``)}function OQ(e,t){if(t.form===void 0)return{rows:e.rows,problems:[]};if(e.mode===`yaml`){let n=dG(e.yaml,{keywords:t.keywords,topicKeyword:t.topicKeyword,required:DQ(t)});return n.ok?{rows:n.rows,problems:[]}:{rows:[],problems:n.problems}}let n=e.rows.map(e=>({title:e.title.trim(),values:Object.fromEntries(Object.entries(e.values).filter(([,e])=>e!==``))}));return{rows:n,problems:sG(n,{keywords:t.keywords,topicKeyword:t.topicKeyword,...e.mode===`table`?{required:DQ(t)}:{},kept:t.kept})}}function Obe(e,t,n){if(t===e.mode)return{queue:e,problems:[]};let r=e.rows;if(e.mode===`yaml`){let t=dG(e.yaml,{keywords:n.keywords.length===0?Object.keys(n.everyRun):n.keywords,topicKeyword:n.topicKeyword});if(!t.ok)return{queue:e,problems:t.problems};r=t.rows}return{queue:{...e,mode:t,rows:r,lines:t===`lines`?uG(r):e.lines,base:t===`lines`?r:e.base,yaml:t===`yaml`?fG(r,n.topicKeyword):e.yaml,columns:EQ(r,e.columns)},problems:[]}}function kQ(e,t,n){return{...e,rows:t,lines:e.mode===`lines`?uG(t):e.lines,base:e.mode===`lines`?t:e.base,yaml:e.mode===`yaml`?fG(t,n):e.yaml,columns:EQ(t,e.columns)}}function kbe(e,t,n){if(!/\.(ya?ml|json)$/i.test(e))return{ok:!0,rows:lG(t,[])};let r=dG(t,{keywords:n.keywords.length===0?Object.keys(n.everyRun):n.keywords,topicKeyword:n.topicKeyword});return r.ok?{ok:!0,rows:r.rows}:{ok:!1,problems:r.problems}}var AQ={"aria-hidden":!0,strokeWidth:1.75};function jQ(e,t,n){if(!e.altKey||e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return!1;e.preventDefault();let r=e.key===`ArrowUp`;return t.busy||r&&t.index===0||!r&&t.index===t.count-1||n(t.index+(r?-1:1),r?`up`:`down`),!0}var MQ=`Alt+ArrowUp Alt+ArrowDown`;function NQ({name:e,index:t,count:n,busy:r,onMove:i,onRemove:a,onInsertBelow:o,onDuplicate:s}){let c=(0,m.useRef)(!1),l=t===0,u=t===n-1;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Nv,{size:`small`,label:`Move ${e} up`,disabled:r||l,onClick:()=>i(t-1,`up`),children:(0,h.jsx)(wc,{...AQ})}),(0,h.jsx)(Nv,{size:`small`,label:`Move ${e} down`,disabled:r||u,onClick:()=>i(t+1,`down`),children:(0,h.jsx)(bc,{...AQ})}),(0,h.jsx)(Nv,{size:`small`,label:`Remove ${e}`,disabled:r,onClick:a,children:(0,h.jsx)(kl,{...AQ})}),(0,h.jsxs)(YO,{children:[(0,h.jsx)(XO,{asChild:!0,children:(0,h.jsx)(Nv,{size:`small`,label:`More for ${e}`,disabled:r,children:(0,h.jsx)(Hc,{...AQ})})}),(0,h.jsxs)(ZO,{onCloseAutoFocus:e=>{c.current&&(c.current=!1,e.preventDefault(),o())},children:[(0,h.jsxs)(QO,{disabled:l,onSelect:()=>i(0,`to the top`),children:[(0,h.jsx)(Cc,{...AQ,className:`size-4`}),`Move to top`]}),(0,h.jsxs)(QO,{disabled:u,onSelect:()=>i(n-1,`to the bottom`),children:[(0,h.jsx)(vc,{...AQ,className:`size-4`}),`Move to bottom`]}),(0,h.jsxs)(QO,{onSelect:()=>{c.current=!0},children:[(0,h.jsx)(rl,{...AQ,className:`size-4`}),`Insert below`]}),(0,h.jsxs)(QO,{onSelect:s,children:[(0,h.jsx)(Bc,{...AQ,className:`size-4`}),`Duplicate`]})]})]})]})}function PQ(e){return e.split(/\r?\n/).map(e=>e.replace(/^\s*[-*•]\s+/,``).trim()).filter(e=>e!==``)}function FQ(e,t,n){let r=[...e],[i]=r.splice(t,1);return i===void 0||r.splice(Math.min(Math.max(n,0),r.length),0,i),r}function IQ(e,t,n){let r=Math.min(Math.max(t,0),e.length);return[...e.slice(0,r),...n,...e.slice(r)]}var LQ=0;function RQ(e){return Array.from({length:e},()=>(LQ+=1,`row-${String(LQ)}`))}function zQ(e,t,n){let r=new Map;return e.forEach((e,n)=>{let i=t[n];i!==void 0&&r.set(e.title,[...r.get(e.title)??[],i])}),n.map(e=>r.get(e.title)?.shift()??RQ(1)[0]??``)}var BQ=()=>({title:``,values:{}});function Abe({queue:e,onQueue:t,keyword:n,addable:r,titleOf:i}){let a=Lv(),o=n===null?`Title`:`{{${n}}}`,s=(0,m.useRef)({rows:e.rows,keys:RQ(e.rows.length)});s.current.rows!==e.rows&&(s.current={rows:e.rows,keys:zQ(s.current.rows,s.current.keys,e.rows)});let c=s.current.keys,l=(0,m.useRef)(e);l.current=e;let u=yG(c),d=(0,m.useRef)(new Map),f=(0,m.useRef)(null);(0,m.useEffect)(()=>{let e=f.current;e!==null&&c.includes(e)&&(f.current=null,d.current.get(e)?.focus())},[c]);let p=(n,r,i)=>{s.current={rows:n,keys:r},i!==void 0&&(f.current=i),t({...e,rows:n})},g=(t,n)=>{let r=RQ(n.length);p(IQ(e.rows,t,n),IQ(c,t,r),r[0])},_=(t,n)=>p(e.rows.map((e,r)=>r===t?n:e),c),v=(t,n)=>{let r=c[t];p(FQ(e.rows,t,n),FQ(c,t,n),r)},y=r=>{let i=[...new Set(r)].filter(e=>e>=0).sort((e,t)=>e-t),o=i.flatMap(t=>{let n=e.rows[t];return n===void 0?[]:[{at:t,row:n}]});if(o.length===0)return;let s=new Set(i);p(e.rows.filter((e,t)=>!s.has(t)),c.filter((e,t)=>!s.has(t)));let u=o[0]?.row.title.trim()??``;a(o.length===1?`Removed ${u===``?`an empty topic`:`“${u}”`}. Save the schedule to keep it.`:`Removed ${wG(o.length,`topic`,`topics`)}. Save the schedule to keep it.`,`success`,{label:`Undo`,run:()=>{let e=[...l.current.rows];for(let{at:t,row:n}of o)e=IQ(e,t,[n]);t(kQ(l.current,e,n))}})};return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Py,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(z,{size:`small`,onClick:()=>g(e.rows.length,[BQ()]),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]}),r.length===0?null:(0,h.jsxs)(cL,{"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))]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,onKeyDown:u.onKeyDown,children:[e.rows.length>1?(0,h.jsx)(CG,{selection:u,total:e.rows.length,noun:[`topic`,`topics`],actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:u.count===0,disabledReason:`Tick the topics to remove`,onClick:()=>{y(u.selected.map(e=>c.indexOf(e))),u.clear()},children:`Remove selected`})}):null,(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)(`span`,{className:`sr-only`,children:`Select`})}),(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)(H,{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)(Nv,{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)(kl,{"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:`Actions`})})]})}),(0,h.jsx)(`tbody`,{children:e.rows.map((t,n)=>{let r=c[n]??String(n),a=t.title.trim()===``?`topic ${String(n+1)}`:t.title;return(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{children:(0,h.jsx)(xG,{selection:u,value:r,label:a})}),(0,h.jsx)(`td`,{className:`num`,children:n+1}),(0,h.jsx)(`td`,{children:(0,h.jsx)(X,{ref:e=>{e===null?d.current.delete(r):d.current.set(r,e)},"aria-label":`Topic ${String(n+1)} ${o}`,"aria-keyshortcuts":MQ,maxLength:200,value:t.title,className:`min-w-[14rem]`,onChange:e=>_(n,{...t,title:e.target.value}),onPaste:t=>{let r=PQ(t.clipboardData.getData(`text`));if(r.length<2)return;t.preventDefault();let[i=``,...a]=r,o=e.rows.map((e,t)=>t===n?{...e,title:`${e.title}${i}`}:e),s=RQ(a.length);p(IQ(o,n+1,a.map(e=>({title:e,values:{}}))),IQ(c,n+1,s),s.at(-1))},onKeyDown:t=>{jQ(t,{index:n,count:e.rows.length,busy:!1},e=>v(n,e))||t.key===`Enter`&&(t.preventDefault(),g(n+1,[BQ()]))}})}),e.columns.map(e=>(0,h.jsx)(`td`,{children:(0,h.jsx)(X,{"aria-label":`Topic ${String(n+1)} ${e}`,maxLength:eG,placeholder:`Every-run value`,value:t.values[e]??``,className:`min-w-[8rem]`,onChange:r=>_(n,{...t,values:{...t.values,[e]:r.target.value}})})},e)),(0,h.jsx)(`td`,{className:`min-w-[180px] text-small text-ink-2`,children:i(t)??`—`}),(0,h.jsx)(`td`,{children:(0,h.jsx)(`span`,{className:`flex items-center gap-1`,children:(0,h.jsx)(NQ,{name:a,index:n,count:e.rows.length,busy:!1,onMove:e=>v(n,e),onRemove:()=>y([n]),onInsertBelow:()=>g(n+1,[BQ()]),onDuplicate:()=>g(n+1,[t])})})})]},r)})})]})})]})]})}function jbe({queue:e,onQueue:t,context:n,onKeyword:r,onValue:i,loading:a,exportName:o}){let[s,c]=(0,m.useState)([]),[l,u]=(0,m.useState)(null),{keywords:d,topicKeyword:f,form:p,everyRun:g}=n,_=e=>n.origins?.get(e)??[],v=OQ(e,n),y=e.mode===`yaml`?v.rows:e.rows,b=e=>p===void 0?void 0:rG(p,{topicKeyword:f,values:g},e),x=y[0],S=x===void 0?void 0:b(x),C=f!==null&&p?.title.includes(`{{${f}}}`)===!0,w=()=>fG(OQ(e,n).rows,f),T=()=>{let e=w();if(!navigator.clipboard){u(`Couldn't copy the list. Switch to YAML / JSON, select the text and copy it.`);return}navigator.clipboard.writeText(e).then(()=>u(`Copied ${String(y.length)} topics as YAML.`),()=>u(`Couldn't copy the list. Switch to YAML / JSON, select the text and copy it.`))},E=()=>{let e=URL.createObjectURL(new Blob([w()],{type:`application/yaml`})),t=document.createElement(`a`);t.href=e,t.download=`${(o.trim()||`schedule`).replace(/[^\w.-]+/g,`-`)}-topics.yaml`,t.click(),URL.revokeObjectURL(e),u(`Downloaded ${String(y.length)} topics as YAML.`)},D=(0,m.useRef)(null),O=async r=>{let i=kbe(r.name,await r.text(),n);if(!i.ok){u(`${r.name} wasn't imported: ${i.problems.slice(0,3).join(` `)} Fix the file and import it again, or paste its text under YAML / JSON to see every problem.`);return}if(i.rows.length===0){u(`${r.name} has no topics in it. Put one topic per line, or a YAML / JSON list.`);return}t(kQ(e,[...OQ(e,n).rows,...i.rows],f)),u(`Imported ${String(i.rows.length)} ${i.rows.length===1?`topic`:`topics`} from ${r.name}, after the ones already here.`)},k=d.filter(t=>t!==f&&!e.columns.includes(t)),A=[...s,...v.problems];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:[`Topics (optional)`,(0,h.jsx)(H,{id:`planning.schedule.topics`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(Iy,{label:`How to write the topics`,tip:`planning.schedule.topic-format`,value:e.mode,options:Object.keys(wQ).map(e=>({value:e,label:wQ[e]})),onChange:r=>{let i=Obe(e,r,n);c(i.problems),t(i.queue)}}),(0,h.jsxs)(z,{variant:`quiet`,size:`small`,disabled:y.length===0||v.problems.length>0,disabledReason:`Add topics, and fix the problems below, first`,onClick:T,children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Copy as YAML`]}),(0,h.jsxs)(z,{variant:`quiet`,size:`small`,disabled:y.length===0||v.problems.length>0,disabledReason:`Add topics, and fix the problems below, first`,onClick:E,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Export as YAML`]}),(0,h.jsxs)(z,{variant:`quiet`,size:`small`,onClick:()=>D.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Import`]}),(0,h.jsx)(`input`,{ref:D,type:`file`,hidden:!0,accept:`.yaml,.yml,.json,.txt,text/plain,application/json,application/yaml`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&O(t)}}),l===null?null:(0,h.jsx)(`span`,{role:`status`,className:`text-small text-ink-2`,children:l})]}),e.mode===`lines`?(0,h.jsx)(aL,{id:`schedule-topics`,tip:`planning.schedule.topic-lines`,tipLabel:`Topics, one per line`,label:y.length===0?`One per line`:`${String(y.length)} ${y.length===1?`topic`:`topics`} · next: ${x?.title??``}`,children:(0,h.jsx)(sL,{rows:Math.min(16,Math.max(6,y.length+1)),value:e.lines,onChange:n=>t({...e,lines:n.target.value,rows:lG(n.target.value,e.base)}),placeholder:`Pyramids
272
272
  Sphinxes
273
273
  Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(aL,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(sL,{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)(Abe,{queue:e,onQueue:t,keyword:f,addable:k,titleOf:b}),v.rows.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,"aria-live":`polite`,children:`${cQ(v.rows.length,500,`topics`)}.`}),A.length===0?null:(0,h.jsx)(fM,{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:[A.slice(0,8).map(e=>(0,h.jsx)(`li`,{children:e},e)),A.length>8?(0,h.jsx)(`li`,{children:`And ${String(A.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)(aL,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:SQ({feeds:_(f)})},children:(0,h.jsx)(cL,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(CQ,{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]})}var Mbe=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Nbe({templates:e,pending:t,onCreated:n,onError:r,editing:i,onCancel:a,error:o,onBusy:s}){let{api:c}=B(),[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`?Fye(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)(bbe(i?.spendLimitCents)),[k,A]=(0,m.useState)(()=>TQ(i?.items??[])),[j,M]=(0,m.useState)(i?.topicKeyword??null),[ee,N]=(0,m.useState)(i?.values??{}),[te,P]=(0,m.useState)(i?.brief??``),[ne,re]=(0,m.useState)(i?.topicGeneration??bT),[ie,ae]=(0,m.useState)((i?.releases??[]).length===0?null:i?.releases??null),[oe,se]=(0,m.useState)(!1),[ce,le]=(0,m.useState)(!1),[ue,de]=(0,m.useState)(!1),fe=(0,m.useId)(),pe=(0,m.useRef)(!1),me=(0,m.useRef)(null),he=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,ge=he.find(e=>e.id===d),_e=F({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await MO(c,d);if(!e.ok)throw Error(e.message);return e.value}}),ve=_e.data?.document.form,ye=ve===void 0?void 0:hQ({form:ve,prompts:_e.data?.document.librarySnapshot?.prompts??[],entries:_e.data?.document.librarySnapshot?.entries??[]}),be=ve===void 0?[]:tG(ve),xe=j!==null&&be.includes(j)?j:be.find(e=>ve?.title.includes(`{{${e}}}`))??be[0]??null,Se=Object.fromEntries(be.filter(e=>e!==xe).map(e=>[e,ee[e]??ve?.values[e]??``])),Ce={keywords:be,topicKeyword:xe,everyRun:Se,form:ve,kept:i?.items??[],...ye===void 0?{}:{origins:ye}},we=OQ(k,Ce),Te=p===`weekly`?x:p===`daily`?[0,1,2,3,4,5,6]:[],Ee=ve!==void 0&&ve.sources.audio!==`off`&&ve.shorts?.enabled===!0?Math.max(0,Math.min(10,Number(ve.shorts.count)||0)):0,De=()=>_be({name:l,templateChosen:ge!==void 0,kind:p,onceAt:_,time:y,days:x,timezone:C,spend:D,topicProblems:we.problems,topicCount:we.rows.length,brief:te,generationLlm:ne.llm}),Oe=ue?De():{};async function ke(e){if(e.preventDefault(),!(pe.current||t)){if(!me.current){let e=De(),t=vbe(e);if(t!==void 0){de(!0),r(ybe(e)),Pbe(hbe[t]);return}}pe.current=!0,se(!0),s(!0);try{if(!me.current){if(!ge)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!fT(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Iye(_,e)}:p===`weekly`?{kind:p,time:y,days:x}:{kind:p,time:y},n=_Q(D);if(n===void 0)throw Error(`Enter the spend ceiling in US dollars, such as 5 or 2.50, or leave it empty.`);let r={id:i?.id??crypto.randomUUID(),name:l.trim(),templateId:ge.id,templateVersion:ge.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:we.rows,topicKeyword:xe,values:Se,brief:te.trim()===``?null:te.trim(),topicGeneration:ne,releases:ie===null||p===`once`?[]:bQ(ie,Te,Ee)};me.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=me.current,{id:t,...a}=e,o=`mutationId`in a?await jT(c,t,a):await AT(c,e);if(!o.ok){me.current=null,le(!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}me.current=null,le(!1),de(!1),u(``),A(TQ([])),n()}catch(e){le(me.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{pe.current=!1,se(!1),s(me.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(fM,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{noValidate:!0,onSubmit:e=>void ke(e),children:[(0,h.jsxs)(`fieldset`,{disabled:oe||ce||t,className:`m-0 grid min-w-0 gap-4 border-0 p-0 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(aL,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,error:Oe.name,children:(0,h.jsx)(X,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(aL,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,error:Oe.template,children:(0,h.jsxs)(cL,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:he.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),he.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(aL,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(cL,{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)(aL,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,error:Oe.once,children:(0,h.jsx)(X,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(aL,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,error:Oe.time,children:(0,h.jsx)(X,{required:!0,type:`time`,value:y,onChange:e=>b(e.target.value)})}),p===`weekly`?(0,h.jsxs)(`fieldset`,{id:`schedule-weekdays`,className:`m-0 min-w-0 border-0 p-0`,"aria-invalid":Oe.weekdays!==void 0,"aria-describedby":Oe.weekdays===void 0?void 0:`schedule-weekdays-error`,...Py,children:[(0,h.jsxs)(`legend`,{className:`sl-field__label mb-2 flex items-center gap-1`,children:[`Weekdays`,(0,h.jsx)(H,{id:`planning.schedule.weekdays`,className:`-my-1`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Mbe.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))}),Oe.weekdays===void 0?null:(0,h.jsx)(`p`,{id:`schedule-weekdays-error`,className:`sl-field__error m-0 mt-1`,children:Oe.weekdays})]}):(0,h.jsx)(`div`,{}),(0,h.jsx)(aL,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,help:`Start typing to pick from the list. This computer uses ${Fbe}.`,error:Oe.timezone,children:(0,h.jsx)(X,{value:C,list:fe,autoComplete:`off`,spellCheck:!1,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(`datalist`,{id:fe,children:xbe().map(e=>(0,h.jsx)(`option`,{value:e},e))}),(0,h.jsx)(aL,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(cL,{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)(aL,{label:`Spend ceiling per run (US$, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,help:`In dollars, such as 5 or 2.50. Empty means no ceiling.`,error:Oe.spend,children:(0,h.jsx)(X,{inputMode:`decimal`,value:D,onChange:e=>O(e.target.value),placeholder:`10.00`})}),(0,h.jsxs)(`div`,{id:`schedule-topics`,tabIndex:-1,className:`min-w-0 min-[700px]:col-span-2`,children:[(0,h.jsx)(jbe,{queue:k,onQueue:A,context:Ce,onKeyword:M,onValue:(e,t)=>N(n=>({...n,[e]:t})),loading:d!==``&&_e.isPending,exportName:l}),Oe.topics===void 0?null:(0,h.jsx)(`p`,{className:`sl-field__error m-0 mt-2`,children:Oe.topics})]}),(0,h.jsx)(Dbe,{releases:ie,onReleases:ae,runDays:Te,shorts:Ee,once:p===`once`,timezone:C}),(0,h.jsx)(Ibe,{problems:Oe,brief:te,onBrief:P,generation:ne,onGeneration:re,templateLlm:ve?.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)(z,{type:`submit`,variant:`primary`,disabled:t||oe||he.length===0&&!ce,children:oe?`Saving…`:ce?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(z,{variant:`quiet`,disabled:oe||ce,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Pbe(e){let t=document.getElementById(e);t!==null&&(((t instanceof HTMLFieldSetElement?t.querySelector(`input, select, textarea`):t)??t).focus(),t.scrollIntoView?.({block:`center`,behavior:`smooth`}))}var Fbe=Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`;function Ibe({problems:e,brief:t,onBrief:n,generation:r,onGeneration:i,templateLlm:a}){let{api:o}=B(),s=F({...xy(o),enabled:r.mode!==`off`}),c=r.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)(H,{id:`planning.schedule.generation`})]}),(0,h.jsx)(aL,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,help:cQ(t.length,vT,`characters`),error:e.brief,children:(0,h.jsx)(sL,{rows:3,maxLength:vT,value:t,onChange:e=>n(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)(aL,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,error:e.generation,children:(0,h.jsxs)(cL,{value:r.mode,onChange:e=>{let t=e.target.value;i({...r,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`})]})}),r.mode===`off`?null:(0,h.jsx)(aL,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(X,{type:`number`,min:1,max:100,value:String(r.keepAtLeast),onChange:e=>{let t=Math.round(Number(e.target.value));i({...r,keepAtLeast:Number.isFinite(t)?Math.min(100,Math.max(1,t)):1})}})})]}),r.mode===`off`?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Py,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:c===null,onChange:e=>i({...r,llm:e.target.checked?null:{provider:a?.provider??``,model:a?.model??``}})}),`Use the template's LLM`,c===null&&a!==void 0&&a.provider!==``?` (${a.provider} · ${a.model})`:``]}),(0,h.jsx)(H,{id:`planning.schedule.generation-llm`,className:`-my-1`})]}),c===null?null:(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(yL,{label:`Provider`,family:`llm`,providers:s.data?.providers??[],value:c.provider,problem:s.error?.message,onPick:e=>i({...r,llm:{provider:e,model:``}})}),(0,h.jsx)(gL,{label:`Model`,provider:c.provider,value:c.model,problem:void 0,onPick:e=>i({...r,llm:{...c,model:e}})})]})]})]})}function Lbe(e,t){let n=new Set(t);for(let t=1;;t+=1){let r=t===1?` (copy)`:` (copy ${String(t)})`,i=`${e.slice(0,200-r.length)}${r}`;if(!n.has(i))return i}}function Rbe(e,t,n){return{id:t,name:n,templateId:e.templateId,templateVersion:e.templateVersion,cadence:e.cadence,timezone:e.timezone,missedPolicy:e.missedPolicy,overlapPolicy:e.overlapPolicy,spendLimitCents:e.spendLimitCents,items:[],topicKeyword:e.topicKeyword,values:e.values,brief:e.brief,topicGeneration:e.topicGeneration,releases:e.releases}}async function zbe(e,t,n){let r=Lbe(t.name,n),i=await AT(e,Rbe(t,crypto.randomUUID(),r));if(!i.ok)return{...i,message:i.reason===`not-due`?`“${t.name}” wasn't duplicated: its one-time run has already passed. Press New schedule and choose a time in the future instead.`:`“${t.name}” wasn't duplicated: ${i.message}`};let a=await MT(e,i.value.id,`pause`,i.value.version);return a.ok?a:{...a,message:`“${r}” was made but couldn't be paused: ${a.message} Press Pause on its row before its first run.`}}var VQ={newest:`Newest first`,next:`Next run first`,name:`Name A–Z`,changed:`Recently changed`},Bbe=e=>Object.hasOwn(VQ,e);function Vbe(e,t,n){let r=t.trim().toLowerCase().split(/\s+/).filter(Boolean),i=e.filter(e=>r.every(t=>e.name.toLowerCase().includes(t)));return n===`newest`?i:[...i].sort((e,t)=>n===`name`?e.name.localeCompare(t.name):n===`changed`?t.updatedAt.localeCompare(e.updatedAt):(e.nextRunAt??`~`).localeCompare(t.nextRunAt??`~`))}function Hbe({query:e,sort:t,onQuery:n,onSort:r}){return(0,h.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,...Py,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search schedules by name`,placeholder:`Search schedules`,value:e,className:`min-w-0 flex-1`,onChange:e=>n(e.target.value)}),(0,h.jsx)(cL,{"aria-label":`Sort schedules`,value:t,className:`w-auto`,onChange:e=>{let t=e.target.value;Bbe(t)&&r(t)},children:Object.keys(VQ).map(e=>(0,h.jsx)(`option`,{value:e,children:VQ[e]},e))}),(0,h.jsx)(H,{id:`planning.schedules`})]})}function Ube({rowKey:e,index:t,title:n,count:r,busy:i,selection:a,inputRef:o,onRename:s,onMove:c,onRemove:l,onInsertBelow:u,onDuplicate:d}){let[f,p]=(0,m.useState)(n);return(0,m.useEffect)(()=>p(n),[n]),(0,h.jsx)(JL,{lead:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(xG,{selection:a,value:e,label:n}),(0,h.jsx)(`span`,{className:`w-7 text-right text-small text-ink-3 tabular-nums`,children:t+1})]}),title:(0,h.jsx)(X,{ref:o,"aria-label":`Topic ${String(t+1)}`,"aria-keyshortcuts":MQ,maxLength:200,value:f,className:`min-w-[12rem]`,onChange:e=>p(e.target.value),onBlur:()=>s(f),onKeyDown:e=>{jQ(e,{index:t,count:r,busy:i},c)||(e.key===`Enter`?(e.preventDefault(),s(f)):e.key===`Escape`&&f!==n&&(e.preventDefault(),p(n)))}}),actions:(0,h.jsx)(NQ,{name:n,index:t,count:r,busy:i,onMove:c,onRemove:l,onInsertBelow:u,onDuplicate:d})})}function HQ({label:e,placeholder:t,buttonLabel:n,disabled:r,disabledReason:i,autoFocus:a=!1,className:o,onAdd:s,onCancel:c}){let[l,u]=(0,m.useState)(``),d=async e=>{await s(e)&&u(``)};return(0,h.jsxs)(`form`,{className:R(`flex flex-wrap items-center gap-2`,o),onSubmit:e=>{e.preventDefault(),d(PQ(l))},children:[(0,h.jsx)(X,{"aria-label":e,placeholder:t,maxLength:200,value:l,autoFocus:a,className:`min-w-0 flex-1`,onChange:e=>u(e.target.value),onPaste:e=>{let t=e.clipboardData.getData(`text`);/\r?\n/.test(t.trim())&&(e.preventDefault(),d(PQ(`${l}${t}`)))},onKeyDown:e=>{e.key===`Escape`&&(c===void 0?l!==``&&(e.preventDefault(),u(``)):(e.preventDefault(),c()))}}),(0,h.jsxs)(z,{type:`submit`,size:`small`,disabled:r,disabledReason:i,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),n]}),c===void 0?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,onClick:c,children:`Cancel`})]})}var UQ=e=>`“${e}”`;function Wbe(e,t){let{api:n}=B(),r=_(),i=Lv(),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=(0,m.useRef)(!1),u=(0,m.useRef)(e);e.version>u.current.version&&(u.current=e);let d=(0,m.useRef)({version:e.version,items:e.items,keys:RQ(e.items.length)});if(d.current.version!==u.current.version){let{items:e}=u.current;d.current={version:u.current.version,items:e,keys:zQ(d.current.items,d.current.keys,e)}}let f=(0,m.useRef)(null),p=u.current.items,h=d.current.keys,g=async(e,t,a,s)=>{if(l.current)return!1;l.current=!0;let f=u.current,p=d.current.keys;c(!0),o(null);try{let c=await e(f);return c.ok?(u.current=c.value,d.current={version:c.value.version,items:c.value.items,keys:t.length===c.value.items.length?t:zQ(f.items,p,c.value.items)},r.setQueryData(OT,e=>e?.map(e=>e.id===c.value.id?c.value:e)),r.invalidateQueries({queryKey:VT}),i(a,`success`,s?{label:`Undo`,run:()=>void g(e=>BT(n,e.id,{baseVersion:e.version,items:f.items}),p,`Put the topics back as they were.`,!1)}:void 0),!0):(o(c.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: ${c.message}`),await r.invalidateQueries({queryKey:OT}),!1)}catch(e){return o(`The topics weren't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then try again.`),!1}finally{l.current=!1,c(!1)}},v=(e,t,r)=>g(t=>BT(n,t.id,{baseVersion:t.version,items:e}),t,r,!0);return{items:p,keys:h,saving:s,error:a,setError:o,focusKey:f,add:async(e,n=p.length,r=!1)=>{if(e.length===0)return o(`Write the new topic's ${t} first, then press Add topic.`),!1;let i=500-p.length;if(e.length>i)return o(`${wG(e.length,`topic`,`topics`)} didn't fit: a queue holds at most 500 and ${wG(i,`more fits`,`more fit`)}. Remove some topics first, or add fewer lines.`),!1;let a=RQ(e.length),s=a[0];return r&&s!==void 0&&(f.current=s),v(IQ(p,n,e.map(e=>({title:e,values:{}}))),IQ(h,n,a),e.length===1?`Added ${UQ(e[0]??``)}.`:`Added ${wG(e.length,`topic`,`topics`)}.`)},rename:(e,n)=>{let r=p[e],i=n.trim();if(r!==void 0&&i!==r.title){if(i===``){o(`Topic ${String(e+1)} needs a ${t}. Write one, or press its Remove button.`);return}v(p.map((t,n)=>n===e?{...t,title:i}:t),h,`Renamed to ${UQ(i)}.`)}},move:(e,t,r)=>{let i=p[e],a=h[e];i!==void 0&&e!==t&&(a!==void 0&&(f.current=a),g(r=>zT(n,r.id,{baseVersion:r.version,from:e,to:t}),FQ(h,e,t),`Moved ${UQ(i.title)} ${r}.`,!0))},remove:e=>{let t=new Set(e),n=p[e[0]??-1];return n===void 0?Promise.resolve(!1):v(p.filter((e,n)=>!t.has(n)),h.filter((e,n)=>!t.has(n)),t.size===1?`Removed ${UQ(n.title)}.`:`Removed ${wG(t.size,`topic`,`topics`)}.`)},duplicate:e=>{let t=p[e];if(t===void 0)return;if(p.length>=500){o(`${UQ(t.title)} wasn't duplicated: a queue holds at most 500 topics. Remove one first.`);return}let[n]=RQ(1);n!==void 0&&(f.current=n),v(IQ(p,e+1,[t]),IQ(h,e+1,n===void 0?[]:[n]),`Duplicated ${UQ(t.title)}.`)}}}function Gbe({schedule:e}){let t=e.topicKeyword===null?`title`:`{{${e.topicKeyword}}}`,n=Wbe(e,t),{items:r,keys:i,saving:a}=n,o=yG(i),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(new Map);(0,m.useEffect)(()=>{let e=n.focusKey.current;if(e!==null&&i.includes(e)){if(!l&&i.indexOf(e)>=100){u(!0);return}n.focusKey.current=null,d.current.get(e)?.focus()}},[i,n.focusKey,l]);let f=r.length>=500,p=a?`Saving the last change`:`A queue holds at most 500 topics`,g=l?r.length:Math.min(r.length,100),_=s===null?-1:i.indexOf(s);return(0,h.jsxs)(`section`,{"aria-label":`Queued topics`,className:`mt-6`,...Py,children:[(0,h.jsx)(U,{as:`h3`,title:`Queued topics · ${String(r.length)}`,info:`planning.schedule.inline-topics`,meta:e.topicKeyword===null?`Each topic becomes the next project's title.`:`Each topic fills ${t}; the next run takes the first.`}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:n.error}),(0,h.jsx)(HQ,{className:`mt-3`,label:`New topic`,placeholder:`${e.topicKeyword===null?`New topic`:`New ${t}`}, or paste several lines`,buttonLabel:`Add topic`,disabled:a||f,disabledReason:p,onAdd:e=>n.add(e)}),r.length===0?null:(0,h.jsxs)(`div`,{onKeyDown:o.onKeyDown,children:[r.length>1?(0,h.jsx)(CG,{className:`mt-3`,selection:o,total:r.length,noun:[`topic`,`topics`],actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:a||o.count===0,disabledReason:a?`Saving the last change`:`Tick the topics to remove`,onClick:()=>void n.remove(o.selected.map(e=>i.indexOf(e))).then(e=>{e&&o.clear()}),children:`Remove selected`})}):null,(0,h.jsx)(qL,{label:`Topics of ${e.name}`,className:`mt-2`,children:r.slice(0,g).flatMap((e,t)=>{let s=i[t]??String(t),l=(0,h.jsx)(Ube,{rowKey:s,index:t,title:e.title,count:r.length,busy:a,selection:o,inputRef:e=>{e===null?d.current.delete(s):d.current.set(s,e)},onRename:e=>n.rename(t,e),onMove:(e,r)=>n.move(t,e,r),onRemove:()=>void n.remove([t]),onInsertBelow:()=>c(s),onDuplicate:()=>n.duplicate(t)},s);return t===_?[l,(0,h.jsx)(JL,{title:(0,h.jsx)(HQ,{autoFocus:!0,label:`New topic below ${String(t+1)}`,placeholder:`New topic, or paste several lines`,buttonLabel:`Insert`,disabled:a||f,disabledReason:p,onAdd:async e=>{let r=await n.add(e,t+1,!0);return r&&c(null),r},onCancel:()=>c(null)})},`${s}:insert`)]:[l]})}),g<r.length?(0,h.jsx)(z,{variant:`quiet`,size:`small`,className:`mt-2`,onClick:()=>u(!0),children:`Show all ${String(r.length)} topics`}):null]})]})}function Kbe(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}function WQ({schedule:e}){return e.deletedAt===null?(0,h.jsx)(tk,{tone:VL[e.status].tone,children:VL[e.status].word}):(0,h.jsx)(tk,{tone:`off`,children:`Deleted`})}function GQ({schedule:e,nextTitle:t,selected:n,pending:r,onSelect:i,onEdit:a,onAction:o,onConfirm:s}){let{api:c}=B(),l=e.deletedAt===null,u=l&&(e.status===`active`||e.status===`paused`),d=e.status===`canceled`||e.status===`completed`;return(0,h.jsx)(JL,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(WQ,{schedule:e}),` · ${Kbe(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${GZ(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${GZ(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)(z,{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)(z,{variant:`quiet`,size:`small`,"aria-label":`Resume ${e.name}`,disabled:r,onClick:()=>o(()=>MT(c,e.id,`resume`,e.version)),children:`Resume`}):(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Pause ${e.name}`,disabled:r||e.status!==`active`,disabledReason:`Only an active schedule can pause`,onClick:()=>o(()=>MT(c,e.id,`pause`,e.version)),children:`Pause`}),(0,h.jsx)(z,{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 qbe({schedule:e,pending:t,onAction:n,onConfirm:r,onDuplicate:i}){let{api:a}=B(),o=F({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await tce(a,e.id);if(!t.ok)throw Error(t.message);return t.value},refetchInterval:3e4}),s=e.deletedAt===null,c=s&&(e.status===`active`||e.status===`paused`),l=e.status===`paused`,u=[[`When`,e.cadence.kind===`once`?`Once, ${GZ(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`:GZ(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:[s&&c?(0,h.jsx)(Jbe,{schedule:e,paused:l,onAction:n}):null,(0,h.jsxs)(U,{kicker:(0,h.jsx)(WQ,{schedule:e}),title:e.name,meta:e.topics.held>0?`${String(e.topics.held)} topics waiting for you`:void 0,children:[s?(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:t,disabledReason:`Finish or cancel the open change first`,onClick:i,children:`Duplicate`}):null,s?(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Cancel ${e.name}`,disabled:t||!c,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:u.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))}),c?(0,h.jsx)(Gbe,{schedule:e}):null,(0,h.jsx)(Yye,{schedule:e}),(0,h.jsx)(vG,{className:`my-6`}),(0,h.jsx)(U,{as:`h3`,title:`Run history`}),(0,h.jsx)(`div`,{className:`mt-3`,children:o.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading history…`}):o.error?(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The run history couldn't be loaded: ${o.error.message} It tries again every 30 seconds.`}):o.data.runs.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No runs yet.`}):(0,h.jsx)(qL,{label:`Runs of ${e.name}`,children:o.data.runs.map(t=>(0,h.jsx)(JL,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${GZ(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)(pa,{className:`underline hover:text-ink`,to:`/projects/$projectId`,params:{projectId:e},children:[`Project `,t+1]},e))}):`No projects`},t.id))})})]})}function Jbe({schedule:e,paused:t,onAction:n}){let{api:r}=B();return cb({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>MT(r,e.id,t?`resume`:`pause`,e.version))}),null}var KQ={llm:`Text model`,audio:`Voice model`,images:`Image model`,animate:`Animation model`},Ybe=RegExp(`Settings → (${uk.map(e=>e.label.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).toSorted((e,t)=>t.length-e.length).join(`|`)})`,`g`);function Xbe(e){let t=[],n=0;for(let r of e.matchAll(Ybe)){let i=r[1],a=uk.find(e=>e.label===i);a!==void 0&&r.index!==void 0&&(r.index>n&&t.push(e.slice(n,r.index)),t.push({label:r[0],section:a.id}),n=r.index+r[0].length)}return n<e.length&&t.push(e.slice(n)),t}function qQ({text:e}){if(hi({warn:!1})==null)return(0,h.jsx)(h.Fragment,{children:e});let t=Xbe(e).map((e,t)=>typeof e==`string`?e:(0,h.jsx)(KO,{to:`/settings`,search:{section:e.section},children:e.label},t));return(0,h.jsx)(h.Fragment,{children:t})}function JQ({kind:e,id:t,name:n}){let{api:r}=B(),i=_(),a=F({queryKey:sz.retired,queryFn:()=>mz(r)}),o=I({mutationFn:e=>hz(r,e),onSuccess:()=>Promise.all([i.invalidateQueries({queryKey:sz.retired}),i.invalidateQueries({queryKey:DO}),i.invalidateQueries({queryKey:OT})])}),s=(a.data??[]).filter(n=>n.kind===e&&n.id===t);return s.length===0?null:(0,h.jsxs)(`li`,{"aria-label":`Retired models in ${n}`,className:`flex flex-col gap-2 px-3 pb-3`,children:[s.map(t=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsxs)(`span`,{className:`text-waiting`,children:[`${KQ[t.slot]} ${t.model} is ${t.why===`retired`?`retired`:`no longer listed`}.`,t.blocked===null?``:` ${t.blocked}`,t.replacement===null&&t.blocked===null?(0,h.jsx)(qQ,{text:` No replacement is suggested: choose another model in Settings → Models, or edit the ${e}.`}):null]}),t.replacement===null?null:(0,h.jsx)(z,{size:`small`,disabled:t.blocked!==null||o.isPending,disabledReason:t.blocked??`Switching…`,onClick:()=>o.mutate(t),children:`Switch to ${t.replacement.name}`})]},t.key)),o.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The model wasn't switched: ${o.error.message}`}):null]})}function Zbe({tools:e,loaded:t,live:n,hiddenBySearch:r,channelFiltered:i,deleted:a,selectedId:o,pending:s,nextTitles:c,onPick:l,onEdit:u,onAction:d,onConfirm:f}){return(0,h.jsxs)(h.Fragment,{children:[e,n.length===0&&r>0?(0,h.jsx)(oQ,{title:`No schedule matches this search`,children:`Check the spelling, or clear the search to see all ${String(r)}.`}):t&&n.length===0?(0,h.jsx)(oQ,{title:i?`No schedules run this channel's templates`:a.length===0?`No schedules yet`:`No active schedules`,children:i?`Pick All channels to see the others, or make one from this channel's templates.`:a.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.`}):null,n.length>0?(0,h.jsx)(qL,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:n.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(GQ,{schedule:e,nextTitle:c.get(e.id),selected:o===e.id,pending:s,onSelect:()=>l(e.id),onEdit:()=>u(e),onAction:d,onConfirm:t=>f(t,e)}),(0,h.jsx)(JQ,{kind:`schedule`,id:e.id,name:e.name})]},e.id))}):null,a.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 · `,a.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)(qL,{label:`Deleted schedules`,children:a.map(e=>(0,h.jsx)(GQ,{schedule:e,nextTitle:void 0,selected:o===e.id,pending:!1,onSelect:()=>l(e.id),onEdit:()=>void 0,onAction:d,onConfirm:()=>void 0},e.id))})]}):null]})}function Qbe({pickedId:e,onPick:t}={}){let{api:n}=B(),r=_(),i=F(kT(n)),a=F(jO(n)),[o,s]=(0,m.useState)(null),c=Lv(),[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=F(Xy(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=F(HT(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=ab().channelId,[A,j]=(0,m.useState)(k??``),M=e=>{if(A===``)return!0;let t=a.data?.find(t=>t.id===e.templateId);return(t?sQ(t):Uy)===A},[ee,N]=(0,m.useState)(``),[te,P]=(0,m.useState)(`newest`),ne=i.data?.filter(e=>e.deletedAt===null)??[],re=ne.length>=5,ie=ne.filter(M),ae=re?Vbe(ie,ee,te):ie,oe=i.data?.filter(e=>e.deletedAt!==null)??[],se=b!==null&&i.data!==void 0&&!i.data.some(e=>e.id===b),ce=se?null:i.data?.find(e=>e.id===b)??ae[0]??null,le=I({onError:e=>s(e.message),onSettled:async()=>{w.current=!1,await r.invalidateQueries({queryKey:OT})},mutationFn:async e=>e(),onSuccess:async e=>{if(!e.ok){s(e.message);return}s(null)}}),ue=e=>{w.current||(w.current=!0,s(null),le.mutate(e))},de=d||l!==null,fe=()=>{u(null),f(!1),s(null)},pe=a.data?.length===0,me=()=>{de||pe||(u(null),f(!0),s(null))},he=e=>ue(async()=>{let t=await zbe(n,e,(i.data??[]).map(e=>e.name));if(t.ok){let e=t.value;await r.invalidateQueries({queryKey:OT}),x(e.id),c(`Duplicated as “${e.name}”: paused, with an empty topic queue. Press Edit to change it, then Resume.`,`success`,{label:`Edit`,run:()=>ge(e)})}return t}),ge=e=>{f(!1),x(e.id),u(e),s(null)};cb({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:me}),VO(LO.newSchedule,()=>{pe?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`):me()},a.data!==void 0);let _e=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,ve=le.isPending||p||de;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:pe?(0,h.jsxs)(h.Fragment,{children:[`Save a template in`,` `,(0,h.jsx)(pa,{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)(H,{id:`planning.schedules`})]})}),(0,h.jsxs)(Fv,{children:[(0,h.jsxs)(cL,{"aria-label":`Filter schedules by channel`,value:A,className:`w-auto min-w-[160px]`,onChange:e=>j(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)(z,{variant:`primary`,onClick:me,disabled:de||pe,disabledReason:pe?`Save a template in Library → Templates first`:`Finish or cancel the open form first`,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New schedule`]})]})]}),(0,h.jsx)(CR,{tone:de?`info`:_e?.tone??`info`,className:`mb-2`,children:de?void 0:_e?.text}),(0,h.jsx)(_G,{className:`min-[768px]:grid-cols-[minmax(320px,460px)_minmax(0,1fr)]`,list:(0,h.jsx)(Zbe,{tools:re?(0,h.jsx)(Hbe,{query:ee,sort:te,onQuery:N,onSort:P}):null,loaded:i.data!==void 0,live:ae,hiddenBySearch:re?ie.length-ae.length:0,channelFiltered:A!==``,deleted:oe,selectedId:de?void 0:ce?.id,pending:ve,nextTitles:O,onPick:x,onEdit:ge,onAction:ue,onConfirm:(e,t)=>C({kind:e,schedule:t})}),detail:de?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(U,{kicker:l?l.name:void 0,title:l?`Edit schedule`:`New schedule`,className:`mb-4`}),(0,h.jsx)(Nbe,{onBusy:g,editing:l,onCancel:()=>{p||fe()},templates:a.data??[],pending:le.isPending,error:o,onCreated:()=>{c(l?`Schedule updated.`:`Schedule saved. It will run automatically while Slopify is open.`,`success`),fe(),r.invalidateQueries({queryKey:OT})},onError:e=>{s(e),r.invalidateQueries({queryKey:OT})}},l?.id??`new`)]}):se?(0,h.jsx)(oQ,{title:`This schedule wasn't found`,children:`The link names a schedule that is no longer here: a deleted schedule leaves Settings → Trash after 30 days. Pick one from the list, or press New schedule.`}):ce?(0,h.jsx)(qbe,{schedule:ce,pending:ve,onAction:ue,onConfirm:e=>C({kind:e,schedule:ce}),onDuplicate:()=>he(ce)},ce.id):null}),(0,h.jsx)($v,{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:le.isPending,onCancel:()=>{le.isPending||C(null)},onConfirm:()=>{if(!S)return;let{kind:e,schedule:t}=S;ue(async()=>{let r=e===`delete`?await nce(n,t.id,t.version):await MT(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}var YQ=[`studio`,`releases`],XQ=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),$be=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`}),ZQ=e=>`${XQ.format(new Date(e))}, ${$be.format(new Date(e))}`;function exe(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 txe(e){switch(e.state){case`scheduled`:return e.checks===`ok`?{tone:`neutral`,word:`✓ Scheduled · checks clear`}:e.checks===null?{tone:`info`,word:`✓ Scheduled · checks pending`}:{tone:`failed`,word:`Scheduled · ${e.checks}`};case`filled`:return{tone:`waiting`,word:`Filled in Studio, not scheduled`};case`late`:return{tone:`failed`,word:`Late · upload now`};case`not-ready`:return{tone:`neutral`,word:`Not rendered yet`};default:return{tone:`neutral`,word:`Ready to upload`}}}function nxe(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 ${XQ.format(r)}`}}function rxe({item:e,projectId:t,onDone:n}){let{api:r}=B(),i=_(),a=Lv(),[o,s]=(0,m.useState)(e.at===null?``:exe(e.at)),c=I({mutationFn:n=>hs(r,t,{short:e.short,at:n}),onSuccess:()=>{i.invalidateQueries({queryKey:YQ}),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)(X,{"aria-label":`${l}: release`,type:`datetime-local`,className:`w-[200px]`,value:o,onChange:e=>s(e.currentTarget.value)}),(0,h.jsx)(z,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(new Date(o).toISOString()),children:`Save`}),e.short===0?(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,disabled:c.isPending,onClick:()=>c.mutate(null),children:`Not scheduled`}):null,(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,onClick:n,children:`Cancel`})]})}function QQ({item:e,projectId:t,editing:n,onEdit:r}){let i=txe(e),a=n?.projectId===t&&n.short===e.short,o=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[o,e.at===null?``:` · goes public`]}),e.short===0?null:(0,h.jsx)(`span`,{className:`w-full truncate text-small`,title:e.title,children:e.title}),a?(0,h.jsx)(rxe,{item:e,projectId:t,onDone:()=>r(void 0)}):(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,"aria-label":`${o}: move from ${e.at===null?`no time`:ZQ(e.at)}`,onClick:()=>r({projectId:t,short:e.short}),children:e.at===null?`Set a time`:ZQ(e.at)}),(0,h.jsx)(nk,{tone:i.tone,children:i.word})]})}function ixe({entry:e,candidates:t}){let{api:n}=B(),r=_(),i=Lv(),a=t.filter(t=>e.series===``||t.series===e.series),[o,s]=(0,m.useState)(``),c=I({mutationFn:t=>hs(n,t,{short:0,at:e.at,...e.line===null?{}:{line:e.line}}),onSuccess:()=>void r.invalidateQueries({queryKey:YQ}),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)(cL,{"aria-label":`Project for ${ZQ(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)(z,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(o),children:`Put it here`})]})}var $Q=6048e5;function axe(e,t){let n=Math.min(Math.max(0,e),3),r=Math.min(8,(n+1)*2);return{weeks:r,start:n===0?void 0:new Date(t.getTime()+n*2*$Q),end:new Date(t.getTime()+r*$Q),hasEarlier:n>0,hasLater:n<3}}function oxe(e,t){return e.filter(e=>{let n=new Date(e.at).getTime();return(t.start===void 0||n>=t.start.getTime())&&n<t.end.getTime()})}function sxe(){let{api:e}=B(),[t,n]=(0,m.useState)(0),[r]=(0,m.useState)(()=>new Date),i=axe(t,r),a=F({queryKey:[...YQ,i.weeks],queryFn:()=>fs(e,i.weeks),placeholderData:e=>e}),[o,s]=(0,m.useState)();if(a.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the releases…`});if(a.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The releases didn't load: `,a.error.message,` Reload the page to try again.`]});let c=a.data,l=oxe(c.entries,i),u=t===0?`The next two weeks`:`${XQ.format(i.start??r)} to ${XQ.format(i.end)}`,d=new Map;for(let e of l){let t=nxe(e.at,r),n=d.get(t.key)??{label:t.label,entries:[]};n.entries.push(e),d.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(c.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)(pa,{to:`/settings`,search:{section:`studio`},children:`Settings → YouTube Studio`}),`.`]}),(0,h.jsxs)(`nav`,{"aria-label":`Release weeks`,className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(Fv,{children:[(0,h.jsx)(z,{size:`small`,disabled:!i.hasEarlier,disabledReason:`Releases already public are not listed here; open the project to see its release.`,onClick:()=>n(t-1),children:`Earlier`}),(0,h.jsx)(z,{size:`small`,disabled:!i.hasLater,disabledReason:`Releases are listed up to 8 weeks ahead.`,onClick:()=>n(t+1),children:`Later`}),t===0?null:(0,h.jsx)(z,{size:`small`,variant:`quiet`,onClick:()=>n(0),children:`Back to this week`})]}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:u})]}),l.length===0?t===0?(0,h.jsx)(oQ,{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, or press Later to look further ahead.`}):(0,h.jsx)(oQ,{title:`No releases from ${u}`,children:`Nothing is planned in these weeks yet. Press Back to this week, or Earlier.`}):null,[...d.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),n=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:ZQ(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)(pa,{to:`/projects/$projectId`,params:{projectId:e.project.id},children:e.project.title})]}),e.project===null?(0,h.jsx)(ixe,{entry:e,candidates:c.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)(QQ,{item:t,projectId:e.project.id,editing:o,onEdit:s}),n.map(t=>(0,h.jsx)(QQ,{item:t,projectId:e.project?.id??``,editing:o,onEdit:s},t.short))]})]},`${e.at}-${e.project?.id??`free`}`)})})]},e.label))]})}var e$=4;function cxe(e){return e===`schedules`?`schedules`:e===`releases`?`releases`:`weeks`}var t$=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),n$=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),r$=864e5,i$=`slopify.calendar.view`;function lxe(){try{return window.localStorage.getItem(i$)===`list`?`list`:`weeks`}catch{return`weeks`}}function uxe({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=B(),a=ab(),[o,s]=(0,m.useState)(0),c=(0,m.useMemo)(()=>tR(new Date(Date.now()+o*e$*7*r$),e$),[o]),[l,u]=(0,m.useState)(lxe),[d,f]=(0,m.useState)(e??`weeks`),p=n===void 0?d:e??`weeks`,g=e=>{n===void 0?f(e):n(e)},[_,v]=(0,m.useState)(!1),y=F(HT(i,c.from,c.to)),b=F(kT(i)),x=F(jO(i)),S=F(_y(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=>a.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>a.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>a.includes(O.get(e.id)))},j=(0,m.useMemo)(()=>A===void 0?new Map:eR(A),[A]),M=A?.runs??[],ee=Eve(A?.projects??[]),N=tbe(HT(i,c.from,c.to).queryKey,w),te=(e,t,n)=>{if(e.kind!==`none`){if(e.kind===`refused`){w(e.message);return}N.mutate({drop:e,title:t,where:n})}},P=(e,t)=>{let n=rR(M,e,t);if(n===void 0){w(t===-1?`${iR(e)} is already the next topic of ${e.scheduleName}.`:`${iR(e)} is the last topic on the calendar for ${e.scheduleName}. Show Later weeks to move it further.`);return}let r=t$.format(new Date(n.at));te(nR(e,n,r),iR(e),r)},ne=e=>{u(e),p!==`weeks`&&g(`weeks`);try{window.localStorage.setItem(i$,e)}catch{}};cb({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),cb({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>g(`schedules`)}),VO(LO.addToCalendar,()=>v(!0)),cb({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>ne(`weeks`)}),cb({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>ne(`list`)});let re=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),ie=ZL(new Date),ae=`${n$.format(new Date(c.from))} to ${n$.format(new Date(Date.parse(c.to)-2*r$))}`,oe=(A?.queued??[]).toSorted((e,t)=>e.position-t.position),se=oe.filter(e=>e.state===`queued`),ce=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(mG,{title:`Calendar`,meta:`${a.channel?.name??`Every channel`} · ${String(M.length)} scheduled ${M.length===1?`run`:`runs`} ${o===0?`in the next ${String(e$)} weeks`:ae} · ${String(re)} ${re===1?`topic`:`topics`} queued`,actions:p===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Iy,{label:`Calendar view`,tip:`planning.calendar.view`,value:l,onChange:ne,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(z,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]}):void 0}),(0,h.jsx)(iQ,{items:[{id:`weeks`,label:`Coming weeks`},{id:`releases`,label:`Releases`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ce)}}],value:p,onChange:g,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(aQ,{idPrefix:`calendar`,id:`releases`,active:p===`releases`,children:p===`releases`?(0,h.jsx)(sxe,{}):null}),(0,h.jsx)(aQ,{idPrefix:`calendar`,id:`schedules`,active:p===`schedules`,children:p===`schedules`?(0,h.jsx)(Qbe,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(aQ,{idPrefix:`calendar`,id:`weeks`,active:p===`weeks`,children:[(0,h.jsx)(CR,{tone:C===null?`info`:`error`,className:`mb-3`,children:C??void 0}),y.data===void 0||y.error===null?null:(0,h.jsx)(`div`,{className:`mb-3`,children:(0,h.jsx)(NL,{what:`the calendar`,error:y.error,updatedAt:y.dataUpdatedAt,onRetry:()=>void y.refetch(),retrying:y.isFetching})}),y.data===void 0&&y.error!==null?(0,h.jsx)(ML,{what:`The calendar`,error:y.error,onRetry:()=>void y.refetch(),retrying:y.isFetching}):(0,h.jsxs)(h.Fragment,{children:[A===void 0||ee.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[Tve(ee),`. `,(0,h.jsx)(KO,{to:`/`,children:`Open Home`}),` to act on them.`]}),b.data!==void 0&&XZ(k).length===0?null:(0,h.jsx)(`section`,{"aria-label":`Suggested topics`,className:`mb-6 min-w-0`,children:b.data===void 0&&b.error!==null?(0,h.jsx)(ML,{compact:!0,what:`Your schedules`,error:b.error,onRetry:()=>void b.refetch(),retrying:b.isFetching}):(0,h.jsx)(Xye,{schedules:k})}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(dxe,{label:ae,shift:o,onShift:e=>s(t=>e===0?0:t+e)}),y.data===void 0?(0,h.jsx)(jL,{label:`Loading the calendar…`,rows:2,rowClassName:`h-40`}):l===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic by its grip 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+→.`}),$L(new Date(c.from),e$).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=ZL(e),n=j.get(t);return(0,h.jsx)(cR,{date:e,today:t===ie,day:n,dragging:T,busy:N.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(te(nR(T,t,t$.format(e)),iR(T),t$.format(e)),E(null))},onStep:P},t)})},ZL(e[0]??new Date)))]}):(0,h.jsx)(QB,{days:j,busy:N.isPending,onStep:P,schedules:k,onMove:(e,t)=>{let n=t$.format(new Date(t.at));te(nR(e,t,n),iR(e),n)},onTransfer:(e,t)=>{e.index!==null&&te({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0},iR(e),`the end of ${k.find(e=>e.id===t)?.name??`the other schedule`}`)}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(U,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(qL,{label:`Batch queue`,children:oe.map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(JL,{title:(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(tk,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`}),e.state===`queued`?(0,h.jsx)(nQ,{projectId:e.projectId,title:e.title,place:se.indexOf(e),waiting:se.length}):null]})},e.projectId)})})]}):null]})]})]}),(0,h.jsx)(Cve,{open:_,onOpenChange:v,schedules:k})]})}function dxe({label:e,shift:t,onShift:n}){return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(z,{size:`small`,variant:`secondary`,onClick:()=>n(-1),children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Earlier`]}),(0,h.jsx)(`span`,{className:`text-small text-ink-2 tabular-nums`,"aria-live":`polite`,children:e}),(0,h.jsxs)(z,{size:`small`,variant:`secondary`,onClick:()=>n(1),children:[`Later`,(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})]}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:t===0,onClick:()=>n(0),children:`This week`})]})}var fxe=hD.map(e=>({value:e,label:gD[e]}));function pxe({channel:e}){let{api:t}=B(),n=_(),r=Lv(),i=I({mutationFn:n=>Sre(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${gD[e.aiDisclosure]}.`,`success`),n.setQueryData(qy(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:Ky,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)(aL,{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)(cL,{value:i.isPending?i.variables:e.aiDisclosure,options:fxe,disabled:i.isPending,onChange:e=>{let t=hD.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(CR,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}var mxe=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;function a$(e){let t=mxe.exec(e.trim())?.[1];if(t!==void 0)return`#${(t.length===3?[...t].map(e=>e+e).join(``):t).toLowerCase()}`}var hxe=`Write the colour as # and 3 or 6 hex digits, like #8c1e14 or #fff.`;function o$(e){if(e.trim()!==``)return a$(e)===void 0?hxe:void 0}function s$(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function c$(e){let t=Number.parseInt(e.slice(1,3),16),n=Number.parseInt(e.slice(3,5),16),r=Number.parseInt(e.slice(5,7),16);return .2126*s$(t)+.7152*s$(n)+.0722*s$(r)}function gxe(e,t){let n=a$(e),r=a$(t);if(n===void 0||r===void 0)return;let[i,a]=[c$(n),c$(r)].sort((e,t)=>t-e);return(i+.05)/(a+.05)}function l$(e,t,n,r){let i=gxe(e,t);if(!(i===void 0||i>=r))return`Hard to read on ${n}: contrast ${i.toFixed(1)}:1, below the ${String(r)}:1 text needs. Pick a lighter or darker colour.`}function u$({value:e,onChange:t,pickerLabel:n,className:r,...i}){let a=a$(e),o=(0,m.useRef)(a);a!==void 0&&(o.current=a),e.trim()===``&&(o.current=void 0);let s=a??o.current;return(0,h.jsxs)(`span`,{className:R(`flex min-w-0 items-center gap-2`,r),children:[(0,h.jsx)(`span`,{"data-partial":a===void 0&&s!==void 0?``:void 0,className:`relative size-8 shrink-0 overflow-hidden rounded-control border border-line-strong data-[partial]:opacity-40`,style:{background:s??`repeating-linear-gradient(45deg, transparent 0 4px, var(--color-line) 4px 5px)`},children:(0,h.jsx)(`input`,{type:`color`,"aria-label":n,value:s??`#ffffff`,className:`absolute inset-0 size-full cursor-pointer opacity-0`,onChange:e=>t(e.target.value)})}),(0,h.jsx)(X,{...i,className:`w-28 font-mono`,spellCheck:!1,autoComplete:`off`,value:e,onChange:e=>t(e.target.value)})]})}function d$({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)(aL,{label:r,tip:o,help:_xe(s),error:i,children:(0,h.jsxs)(cL,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:WT.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,GT(n.language).name,`)`]}),UT.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function _xe(e){let t=GT(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=KT(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 vxe({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`,...Py,children:[(0,h.jsx)(U,{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.jsxs)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:[(0,h.jsxs)(`li`,{"aria-hidden":`true`,className:`hidden grid-cols-[220px_minmax(0,1fr)_auto] gap-2 border-b border-line pt-1 pb-2 text-label text-ink-2 md:grid`,children:[(0,h.jsxs)(`span`,{children:[`Name, used as `,`{{Name}}`]}),(0,h.jsx)(`span`,{children:`Address`})]}),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.jsxs)(`span`,{className:`grid gap-1`,children:[(0,h.jsxs)(`span`,{"aria-hidden":`true`,className:`text-label text-ink-2 md:hidden`,children:[`Name, used as `,`{{Name}}`]}),(0,h.jsx)(X,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})})]}),(0,h.jsxs)(`span`,{className:`grid gap-1`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`text-label text-ink-2 md:hidden`,children:`Address`}),(0,h.jsx)(X,{"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)(z,{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)(xl,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))]}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(z,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function yxe(){return(0,h.jsxs)(`div`,{...Py,children:[(0,h.jsx)(U,{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)(GO,{to:`/channels/$channelId`,params:{channelId:Uy},children:`Open the default channel's links`})})]})}function f$({changed:e,defaultText:t,label:n,onReset:r}){return(0,h.jsxs)(`span`,{className:`mt-1 flex min-h-7 items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:e?`Changed · default ${t}`:`Default`}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,disabled:!e,"aria-label":`Reset ${n} to ${t}`,onClick:r,children:`Reset`})]})}function p$({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(CE.levelDb),fadeIn:e?.fadeIn??String(CE.fadeInSeconds),tail:e?.tail??String(CE.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.jsxs)(aL,{label:n,help:r,tip:a,error:i(t),children:[(0,h.jsx)(X,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})}),t===`level`?(0,h.jsx)(f$,{changed:e.level.trim()!==String(CE.levelDb),defaultText:`${String(CE.levelDb)} dB`,label:`ambient level`,onReset:()=>s({...e,level:String(CE.levelDb)})}):null]});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(aL,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(cL,{"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:Gce[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 bxe({value:e,onChange:t}){let n=DE(e),r=n===void 0?[]:wE(n);return(0,h.jsx)(p$,{value:e,inherit:`Not set`,sources:xE,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function xxe(e){return e.ambientBed===void 0?void 0:EE(e.ambientBed)}function Sxe(e){let t=DE(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:wE(t).length>0}}var m$=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`],h$=1e4;function Cxe(e){return Object.fromEntries(m$.map(t=>[t,e[t]??``]))}function wxe({channel:e}){let{api:t}=B(),n=_(),r=Lv(),i=F({queryKey:Lk,queryFn:()=>Rk(t)}),a=F(wy(t)),o=F(Ty(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(Cxe(e.brand)),[p,g]=(0,m.useState)(xxe(e.brand)),v=Sxe(p),y=F({queryKey:V.channelLinks,queryFn:()=>Vs(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=I({mutationFn:()=>Qy(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(m$.flatMap(e=>d[e].trim()===``?[]:[[e,Txe(e,d[e])]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(qy(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:Ky}),n.invalidateQueries({queryKey:V.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=v$.some(e=>o$(d[e])!==void 0),D=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),O=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),k=[...(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)(aL,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(X,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(aL,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules. ${cQ(l.length,h$,`characters`)}.`,children:(0,h.jsx)(sL,{rows:4,value:l,maxLength:h$,onChange:e=>u(e.target.value)})}),(0,h.jsx)(U,{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)(d$,{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)(g$,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:D,onPick:T(`captionFontId`)}),(0,h.jsx)(_$,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(_$,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`),contrast:l$(d.captionColor,d.captionOutlineColor,`the caption colour`,3)})]}),(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)(g$,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:D,onPick:T(`titleFontId`)}),(0,h.jsx)(_$,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(aL,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(X,{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)(g$,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:O(`intro`),onPick:T(`intro`)}),(0,h.jsx)(g$,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:O(`outro`),onPick:T(`outro`)}),(0,h.jsx)(g$,{label:`PDF theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:k,onPick:T(`documentTheme`)})]}),(0,h.jsx)(bxe,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(vxe,{rows:S,onChange:x})})]}),(0,h.jsx)(wR,{status:(0,h.jsx)(CR,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(z,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked||E,disabledReason:s.trim()===``?`Give the channel a name`:E?`Fix the colour marked above`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function g$({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(aL,{label:e,tip:t,children:(0,h.jsxs)(cL,{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 _$({label:e,tip:t,value:n,onChange:r,contrast:i}){let a=o$(n);return(0,h.jsx)(aL,{label:e,tip:t,...a===void 0?{}:{error:a},...a===void 0&&i!==void 0?{help:i}:{},children:(0,h.jsx)(u$,{value:n,placeholder:`#FFFFFF`,maxLength:7,pickerLabel:`${e} picker`,onChange:r})})}var v$=[`captionColor`,`captionOutlineColor`,`titleColor`];function Txe(e,t){let n=t.trim();return v$.includes(e)?a$(n)?.toUpperCase()??n:n}function y$(e,t){return e.languages===void 0||e.languages.includes(GT(t).code)}function Exe(e,t,n,r){return n?e:e.filter(e=>y$(e,t)||e.voiceId===r)}function Dxe(e,t){if(e===void 0||y$(e,t))return;let n=GT(t).name,r=(e.languages??[]).map(e=>GT(e).code===e?GT(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 b$(e,t,n){let[r,i]=(0,m.useState)(!1),a=Exe(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function x$({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=Dxe(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`,...Py,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 ${GT(e).name})`]}),(0,h.jsx)(H,{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 S$(e,t,n){let r=t+n,i=e[t];if(i===void 0||r<0||r>=e.length)return[...e];let a=e.filter((e,n)=>n!==t);return a.splice(r,0,i),a}function C$(e,t,n){let r=`${e.trim()||`Untitled`} copy`,i=new Set(t.map(e=>e.trim().toLowerCase())),a=1,o=r;for(;i.has(o.slice(0,n).toLowerCase());)a+=1,o=`${r} ${String(a)}`;return o.slice(0,n)}var Oxe=200;function kxe({channelId:e,member:t,onCreated:n}){let{api:r}=B(),i=_(),a=Lv(),o=F(Zy(r,e)),s=I({mutationFn:()=>eb(r,e,crypto.randomUUID(),{kind:t.kind,name:C$(t.name,(o.data?.cast??[]).map(e=>e.name),Oxe),aliases:[],description:t.description,voice:t.voice??null,host:!1}),onSuccess:async t=>{await Promise.all([i.invalidateQueries({queryKey:qy(e)}),i.invalidateQueries({queryKey:Ky})]),a(`Made “${t.name}”. Its pictures are not copied: upload or generate them under Reference pictures.`,`success`),n(t.id)},onError:e=>a(`Couldn't duplicate ${t.name}: ${e.message} Press Duplicate in its editor to try again.`,`error`)});return(0,h.jsx)(z,{variant:`quiet`,size:`small`,disabled:s.isPending||o.data===void 0,disabledReason:s.isPending?`Making the copy`:`Loading the cast`,onClick:()=>s.mutate(),children:`Duplicate`})}var w$=4e3;function Axe({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=B(),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:qy(e)}),o.invalidateQueries({queryKey:Ky})]),T=I({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?eb(a,e,crypto.randomUUID(),n):hre(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.jsxs)(U,{kicker:t===void 0?`New cast member`:Gy[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:[t===void 0?null:(0,h.jsx)(kxe,{channelId:e,member:t,onCreated:i}),(0,h.jsx)(z,{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)(aL,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(cL,{value:s,onChange:e=>c(Wy.find(t=>t===e.target.value)??`character`),options:Wy.map(e=>({value:e,label:Gy[e]}))})}),(0,h.jsx)(aL,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(X,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(aL,{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)(X,{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)(z,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(pl,{"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)(rk,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(aL,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(sL,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(Mxe,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(Fy,{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)(CR,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(z,{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)(jxe,{channelId:e,member:t})]}):null}function jxe({channelId:e,member:t}){let{api:n}=B(),r=_(),i=F(xy(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:qy(e)}),r.invalidateQueries({queryKey:Ky})]),g=I({mutationFn:e=>vre(n,t.id,e),onSettled:p}),v=I({mutationFn:()=>yre(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=I({mutationFn:e=>bre(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:tb(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)(vG,{className:`mb-6`}),(0,h.jsx)(U,{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)(rz,{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)(nz,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:tb(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)(nk,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(z,{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)(Nxe,{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)(iz,{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)(qO,{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)(z,{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`,...Py,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(H,{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)(yL,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(gL,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(aL,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,help:cQ(d.length,w$,`characters`),children:(0,h.jsx)(sL,{ref:o,rows:3,value:d,maxLength:w$,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(z,{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)(CR,{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 Mxe({channelId:e,value:t,onChange:n}){let{api:r}=B(),i=F(xy(r)),a=F(Sy(r)),o=F(Zy(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=b$(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`,...Py,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(H,{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)(yL,{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)(gL,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(vL,{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)(x$,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(vL,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:qE.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)(z,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function Nxe({error:e,retry:t,onReword:n}){let r=qZ({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)(Fv,{className:`mt-2`,children:(0,h.jsx)(Cz,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(z,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}var T$=`Alt+ArrowUp Alt+ArrowDown`;function Pxe(e,t){let{api:n}=B(),r=_(),i=Lv(),a=(0,m.useRef)(t);a.current=t;let o=I({mutationFn:t=>_re(n,e,t.member.id,t.to),onSuccess:async t=>{r.setQueryData(qy(e),e=>e===void 0?e:{...e,cast:t}),await r.invalidateQueries({queryKey:qy(e)})}}),s=(e,t,n,r=!0)=>{let c=a.current,l=c.findIndex(t=>t.id===e.id);l<0||t===l||t<0||t>=c.length||o.mutate({member:e,to:t},{onSuccess:()=>i(`Moved ${e.name} ${n}: ${String(t+1)} of ${String(c.length)}.`,`success`,r?{label:`Undo`,run:()=>s(e,l,`back`,!1)}:void 0),onError:t=>i(`Couldn't move ${e.name}: ${t.message} Try Move up or Move down in its More menu again.`,`error`)})};return{busy:o.isPending,move:s,onKeyDown:e=>t=>{if(!t.altKey||t.key!==`ArrowUp`&&t.key!==`ArrowDown`||(t.preventDefault(),o.isPending))return;let n=a.current.findIndex(t=>t.id===e.id),r=t.key===`ArrowUp`;s(e,n+(r?-1:1),r?`up`:`down`)}}}function Fxe({member:e,index:t,count:n,order:r}){let i=t===0,a=t===n-1;return(0,h.jsxs)(YO,{modal:!1,children:[(0,h.jsx)(XO,{asChild:!0,children:(0,h.jsx)(Nv,{size:`small`,label:`More for ${e.name}`,"aria-keyshortcuts":T$,disabled:n<2,disabledReason:`Add another member to change the order`,onKeyDown:r.onKeyDown(e),children:(0,h.jsx)(Hc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsxs)(ZO,{children:[(0,h.jsx)(QO,{disabled:i||r.busy,onSelect:()=>r.move(e,t-1,`up`),children:`Move up`}),(0,h.jsx)(QO,{disabled:a||r.busy,onSelect:()=>r.move(e,t+1,`down`),children:`Move down`}),(0,h.jsx)(QO,{disabled:i||r.busy,onSelect:()=>r.move(e,0,`to the top`),children:`Move to top`}),(0,h.jsx)(QO,{disabled:a||r.busy,onSelect:()=>r.move(e,n-1,`to the bottom`),children:`Move to bottom`})]})]})}var E$=e=>`It is deleted permanently: ${e} do not go to Settings → Trash, so it cannot be restored.`,D$=e=>e===void 0?`Delete this channel?`:`Delete the channel “${e}”?`,O$=`${E$(`channels`)} Its cast and their reference pictures, its episode summaries, its video memory and its brand settings go with it. Its projects move to the default channel and keep what they were made with.`,Ixe=e=>e===void 0?`Delete this cast member?`:`Delete “${e}” from the cast?`,Lxe=`${E$(`cast members`)} Its reference pictures go with it, and new videos stop using them. Videos already made keep the pictures they were started with.`,Rxe=e=>e===void 0?`Delete this episode summary?`:`Delete the episode summary of “${e}”?`,zxe=`${E$(`episode summaries`)} New episodes stop being reminded of it. The video itself is not changed.`,Bxe=8;function Vxe({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=B(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=I({mutationFn:e=>gre(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:qy(e)}),a.invalidateQueries({queryKey:Ky})])}}),p=t.find(e=>e.id===c),g=Pxe(e,t),v=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:tb(i,t)}]:[]}),y=v.map(e=>({src:e.src,alt:e.member.name,caption:`${Gy[e.member.kind]} · ${e.member.description||`No description yet`}`})),[b,x]=(0,m.useState)(null),[S,C]=(0,m.useState)(``),w=S.trim().toLowerCase(),T=w===``?t:t.filter(e=>e.id===c||[e.name,...e.aliases,Gy[e.kind],e.description].join(` `).toLowerCase().includes(w)),E=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)(oQ,{title:`No cast yet`,actions:(0,h.jsx)(z,{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.jsxs)(h.Fragment,{children:[t.length>Bxe?(0,h.jsx)(X,{type:`search`,"aria-label":`Search the cast`,placeholder:`Search ${String(t.length)} members by name, kind or description`,value:S,onChange:e=>C(e.target.value),className:`mb-4 max-w-[420px]`}):null,T.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No member's name, kind or description contains "${S.trim()}".`}):null,(0,h.jsx)(rz,{label:`Cast`,children:T.map(e=>{let n=e.images.filter(e=>e.state===`ready`),r=n[0]?.sha256;return(0,h.jsx)(nz,{className:R(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...r?{src:tb(i,r)}:{},alt:e.name,onOpen:()=>x(v.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${Gy[e.kind]}${e.host===!0?` · Host`:``} · ${String(n.length)} ${n.length===1?`picture`:`pictures`}`,...n.length===0?{badge:(0,h.jsx)(nk,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,"aria-keyshortcuts":T$,onKeyDown:g.onKeyDown(e),onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(z,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`}),(0,h.jsx)(Fxe,{member:e,index:t.indexOf(e),count:t.length,order:g})]})},e.id)})})]}),(0,h.jsx)(iz,{items:y,index:b,onIndex:x,onClose:()=>x(null),actions:(e,t)=>{let n=v[t];return n===void 0?null:(0,h.jsx)(z,{size:`small`,onClick:()=>{x(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(CR,{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:E?(0,h.jsx)(Axe,{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)($v,{open:u!==null,title:Ixe(u?.name),consequence:f.error?.message??Lxe,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var k$=e=>[`channels`,e,`episodes`],A$=e=>[`channels`,e,`videos`],j$=(e,t)=>`${e.origin}/api/channels/${t}`,M$=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function Hxe(e,t){return ot({queryKey:k$(t),queryFn:async()=>L(await e.fetch(`${j$(e,t)}/episodes`))})}async function Uxe(e,t,n){return L(await e.fetch(`${j$(e,t)}/episodes/setting`,M$(`PUT`,{enabled:n})))}async function Wxe(e,t,n,r){return L(await e.fetch(`${j$(e,t)}/episodes/${encodeURIComponent(n)}`,M$(`PUT`,{summary:r})))}async function Gxe(e,t,n){let r=await e.fetch(`${j$(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await L(r)}function N$(e,t){return ot({queryKey:A$(t),queryFn:async()=>(await L(await e.fetch(`${j$(e,t)}/videos`))).videos})}async function P$(e,t,n){return L(await e.fetch(`${j$(e,t)}/videos`,M$(`POST`,n)))}async function Kxe(e,t,n){return L(await e.fetch(`${j$(e,t)}/videos/preview`,M$(`POST`,{format:`csv`,text:n})))}async function qxe(e,t,n){let r=await e.fetch(`${j$(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await L(r)}async function Jxe(e,t){await L(await e.fetch(`${j$(e,t)}/videos`,{method:`DELETE`}))}function Yxe(e,t){let n=t.trim().toLowerCase().split(/\s+/u).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=[e.title,e.summary,...e.cast].join(` `).toLowerCase();return n.every(e=>t.includes(e))})}var Xxe=e=>e.length>160?`${e.slice(0,160)}…`:e;function Zxe({channelId:e}){let{api:t}=B(),n=_(),r=F(Hxe(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:k$(e)}),l=I({mutationFn:n=>Uxe(t,e,n),onSuccess:t=>n.setQueryData(k$(e),t)}),u=I({mutationFn:n=>Gxe(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[],[p,g]=(0,m.useState)(``),v=Yxe(f,p);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(Fy,{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)(CR,{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)(oQ,{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.jsxs)(`div`,{className:`mt-2 mb-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search episode summaries`,placeholder:`Search episode summaries`,value:p,className:`w-full min-w-0 sm:w-64`,onChange:e=>g(e.target.value)}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:p.trim()===``?`${String(f.length)} ${f.length===1?`episode`:`episodes`}`:`${String(v.length)} of ${String(f.length)} match`})]}):null,f.length>0&&v.length===0?(0,h.jsx)(oQ,{title:`No episode matches`,children:`No title, cast member or summary contains “${p.trim()}”. Clear the search to see every episode.`}):null,v.length>0?(0,h.jsx)(qL,{label:`Episode summaries`,children:v.map(e=>(0,h.jsx)(JL,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,Xxe(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(z,{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)(Qxe,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)($v,{open:o!==null,title:Rxe(o?.title),consequence:u.error?.message??zxe,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function Qxe({channelId:e,memory:t,onClose:n}){let{api:r}=B(),i=_(),[a,o]=(0,m.useState)(t.summary),s=I({mutationFn:()=>Wxe(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:k$(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Qv,{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)(z,{onClick:n,children:`Close`}),(0,h.jsx)(z,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(aL,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(sL,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}function F$(e,t){let[n,r]=(0,m.useState)({limit:200,resetOn:t}),i=Object.is(n.resetOn,t)?n.limit:200;return Object.is(n.resetOn,t)||r({limit:200,resetOn:t}),{shown:e.length>i?e.slice(0,i):e,hidden:Math.max(0,e.length-i),more:()=>r({limit:i+200,resetOn:t})}}function I$({hidden:e,onMore:t}){return e===0?null:(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(z,{size:`small`,onClick:t,children:`Show ${Math.min(e,200).toLocaleString(`en`)} more`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`${e.toLocaleString(`en`)} not shown`})]})}var L$=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function R$(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function $xe(e,t,n,r){let i=t===void 0?n:Math.min(t,n),a=t===void 0?n:Math.max(t,n);return e.map((e,t)=>t>=i&&t<=a?r:e)}function eSe({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=(0,m.useRef)(void 0),l=(0,m.useRef)(!1),u=e.ticked.filter(Boolean).length,d=F$(e.titles,e.titles);return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...Py,children:[(0,h.jsxs)(U,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${u.toLocaleString(`en`)} of ${L$(e.titles.length,`title`,`titles`)} ticked · Shift+click ticks a range`,children:[(0,h.jsxs)(z,{variant:`primary`,disabled:n||u===0,onClick:a,children:[`Add `,L$(u,`ticked title`,`ticked titles`)]}),(0,h.jsx)(z,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(aL,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(X,{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)(z,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(z,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(qL,{label:`Titles in the CSV`,className:`mt-2`,children:d.shown.map((t,r)=>(0,h.jsx)(JL,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onClick:e=>{l.current=e.shiftKey},onChange:t=>{let n=l.current?c.current:void 0;l.current=!1,c.current=r,i($xe(e.ticked,n,r,t.target.checked))}}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))}),(0,h.jsx)(I$,{hidden:d.hidden,onMore:d.more})]})}var z$=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function tSe({channelId:e}){let{api:t}=B(),n=_(),r=F(N$(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:A$(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=I({mutationFn:n=>P$(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${z$(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=I({mutationFn:n=>Kxe(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:R$(e.titles,e.filter)})}}),x=Lv(),S=I({mutationFn:n=>qxe(t,e,n.id),onSuccess:async(e,t)=>{x(`Removed “${t.title}”.`,`info`,{label:`Undo`,run:()=>C.mutate(t.title)}),await d()}}),C=I({mutationFn:n=>P$(t,e,{format:`lines`,text:n}),onSuccess:d,onError:(e,t)=>x(`Couldn't put “${t}” back: ${e.message} Paste it into Paste titles and press Add titles.`,`error`)}),[w,T]=(0,m.useState)(``),E=I({mutationFn:()=>Jxe(t,e),onSuccess:async()=>{s(!1),await d()}}),D=r.data??[],O=w.trim().toLowerCase(),k=O===``?D:D.filter(e=>e.title.toLowerCase().includes(O)),A=F$(k,O),j=y.isPending||b.isPending||S.isPending||C.isPending||E.isPending,M=r.error??b.error??y.error??S.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)(aL,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(sL,{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)(z,{variant:`primary`,disabled:j||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(z,{disabled:j,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(H,{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)(z,{variant:`quiet`,disabled:j||D.length===0,onClick:()=>{E.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(CR,{tone:M?`error`:c?`success`:`info`,className:`mt-1`,children:M?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(eSe,{preview:f,filter:g,busy:j,onFilter:e=>{v(e),p({...f,ticked:R$(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(`
274
- `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&D.length===0?(0,h.jsx)(oQ,{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,D.length>0?(0,h.jsxs)(`section`,{"aria-label":`Existing videos`,className:`mt-4`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search existing videos`,placeholder:`Search existing videos`,value:w,className:`w-full min-w-0 sm:w-64`,onChange:e=>T(e.target.value)}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:O===``?z$(D.length,`title`,`titles`):`${k.length.toLocaleString(`en`)} of ${z$(D.length,`title`,`titles`)} match`})]}),k.length===0?(0,h.jsx)(oQ,{title:`No title matches`,children:`None of the titles contains “${w.trim()}”. Clear the search to see them all.`}):(0,h.jsx)(qL,{label:`Existing videos`,children:A.shown.map(e=>(0,h.jsx)(JL,{title:e.title,actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:j,"aria-label":`Remove ${e.title}`,onClick:()=>S.mutate(e),children:`Remove`})},e.id))}),(0,h.jsx)(I$,{hidden:A.hidden,onMore:A.more})]}):null,(0,h.jsx)($v,{open:o,title:`Remove all ${z$(D.length,`title`,`titles`)}?`,consequence:E.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,cancelLabel:`Keep them`,pending:E.isPending,onConfirm:()=>E.mutate(),onCancel:()=>s(!1)})]})}function B$({className:e,children:t}){return(0,h.jsx)(`dl`,{className:R(`sl-stats m-0`,e),children:t})}function V$({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 H$({value:e,label:t,valueText:n,tone:r=`accent`,progress:i=!1,className:a}){let o=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100),s=n??`${String(o)}%`,c=R(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,a),l=(0,h.jsx)(`span`,{style:{width:`${String(o)}%`}});return i?(0,h.jsx)(`div`,{role:`progressbar`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l}):(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l})}function U$({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:R(`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 W$=56,G$=12,K$=12,nSe=28;function rSe(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 q$({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=rSe(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-W$-G$,y=e=>W$+(f<=1?0:e/(f-1)*v),b=e=>K$+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=K$+i+nSe,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:R(`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-W$)/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:W$,x2:c-G$,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:K$+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:K$,y2:K$+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 J$=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function iSe(e,t){return L(await e.fetch(J$(e,t)))}async function aSe(e,t,n){return L(await e.fetch(J$(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}async function oSe(e,t,n){return L(await e.fetch(`${e.origin}/api/studio/channels/${t}/export-view`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:n})}))}function sSe({channelId:e,saved:t}){let{api:n}=B(),r=_(),i=Lv(),[a,o]=(0,m.useState)(),s=a??t??``,c=I({mutationFn:t=>oSe(n,e,t),onSuccess:t=>{r.setQueryData([`studio`,`report`,e],t),o(void 0),i(t.exportView?`The extension exports this view every day.`:`The extension no longer exports a view for this channel.`,`success`)},onError:e=>i(`The view wasn't saved: ${e.message}`,`error`)});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(X,{"aria-label":`Studio Analytics view to export every day`,placeholder:`https://studio.youtube.com/channel/…/analytics/…/explore?…`,className:`min-w-0 flex-1 basis-[320px]`,value:s,onChange:e=>o(e.currentTarget.value)}),(0,h.jsx)(z,{type:`button`,disabled:c.isPending||s.trim()===(t??``),onClick:()=>c.mutate(s.trim()===``?null:s.trim()),children:`Save view`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The Studio extension opens this view once a day, exports it and brings it in here: every column, and each video's numbers on its project. Paste the address of Analytics → Advanced mode as you set it up; the start date stays, the end moves to today.`})]})}function Y$(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 X$=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],Z$=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),Q$=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function $$(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 cSe({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,[d,f]=(0,m.useState)(!1),p=t.filter(e=>n.includes(e.videoId)),g=e.from===null?new Date:new Date(`${e.from}T00:00:00`),_=Math.max(0,...t.map(e=>e.daily.length)),v,y;if(o===`dates`){let t=c===`all`?0:Math.max(0,_-Number(c)),n=_-t>200;v=Array.from({length:_-t},(e,r)=>{let i=new Date(g);return i.setDate(i.getDate()+t+r),(n?Q$:Z$).format(i)}),y=p.map(e=>{let n=e.daily.findIndex(e=>e>0),a=$$(e.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:e.videoId,label:e.title,color:r(e.videoId),values:a.slice(t)}}),d&&e.dailyTotals!==void 0&&(y=[{id:`channel-total`,label:`Channel total`,color:`var(--color-ink-2)`,values:$$(e.dailyTotals,i).slice(t)},...y])}else{let e=Math.max(1,...p.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));v=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),y=p.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=$$(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let b=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:b}),(0,h.jsx)(`span`,{className:`flex-1`}),e.dailyTotals===void 0||o!==`dates`?null:(0,h.jsxs)(`label`,{className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.currentTarget.checked)}),`Channel total`]}),(0,h.jsx)(cL,{"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)(cL,{"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)(cL,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),p.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(q$,{series:y,xLabels:v,label:`${b} for ${String(p.length)} videos`,formatValue:e1})]})}var e1=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function lSe({report:e,row:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`),s=t.daily.findIndex(e=>e>0);if(s<0)return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart this one, tick it in Advanced mode's chart before you export.`});let c=$$(t.daily.slice(s),n),l=r===`all`?0:Math.max(0,c.length-Number(r)),u=c.slice(l),d=u.map((e,t)=>{let n=new Date(o);return n.setDate(n.getDate()+s+l+t),(u.length>200?Q$:Z$).format(n)}),f=t.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`${a} · ${f.toLocaleString(`en`)} total`}),(0,h.jsx)(q$,{height:180,legend:!1,label:`${a} for ${t.title}`,xLabels:d,formatValue:e1,series:[{id:t.videoId,label:t.title,color:i(t.videoId),values:u}]})]})}var t1=e=>`slopify.studioReport.hidden.${e}`;function uSe(e){try{let t=window.localStorage.getItem(t1(e));return t===null?void 0:JSON.parse(t)}catch{return}}function n1({channelId:e}){let{api:t}=B(),n=_(),r=Lv(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=F({queryKey:a,queryFn:()=>iSe(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(()=>uSe(e)),w=I({mutationFn:n=>aSe(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),T=o.data?.report??null,E=T?.columns??[],D=E.filter((e,t)=>(T?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),O=S??D,k=t=>{C(t);try{window.localStorage.setItem(t1(e),JSON.stringify(t))}catch{}},A=E.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!O.includes(e.label)),j=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},M=[...T?.rows??[]].toSorted((e,t)=>j(t,s)-j(e,s)),ee=[...T?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),N=l??ee.slice(0,5).map(e=>e.videoId),te=e=>{let t=(T?.rows??[]).findIndex(t=>t.videoId===e);return X$[(t<0?0:t)%X$.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(U,{as:`h3`,title:`From Studio's export`,meta:T===null?void 0:`${String(T.rows.length)} videos · ${T.from??`?`} to ${T.to??`?`} · imported ${new Date(T.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&w.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(z,{type:`button`,variant:`secondary`,disabled:w.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,strokeWidth:1.75}),w.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),(0,h.jsx)(sSe,{channelId:e,saved:o.data?.exportView??null}),T===null?null:(0,h.jsxs)(h.Fragment,{children:[T.chartMetric===null?null:(0,h.jsx)(cSe,{report:T,rows:M,picked:N,colorOf:te,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)(cL,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:E.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(A.length),` of `,String(E.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:E.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!O.includes(e.label),onChange:t=>k(t.currentTarget.checked?O.filter(t=>t!==e.label):[...O,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),A.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),A.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:Y$(T.totals[t]??null,e.kind,e.label)},e.label))]}),M.map(e=>{let t=o.data?.projects[e.videoId],n=b===e.videoId;return(0,h.jsxs)(m.Fragment,{children:[(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:N.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...N,e.videoId]:N.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:N.includes(e.videoId)?te(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[T.chartMetric===null?null:(0,h.jsx)(Nv,{size:`small`,"aria-expanded":n,label:`${n?`Hide`:`Show`} the chart of ${e.title}`,onClick:()=>x(n?void 0:e.videoId),children:n?(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})}),t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title})]}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),A.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:Y$(e.values[n]??null,t.kind,t.label)},t.label))]}),n?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:A.length+2,children:(0,h.jsx)(lSe,{report:T,row:e,shape:d,range:v,colorOf:te})})}):null]},e.videoId)})]})]})})]})]})}var r1=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),i1=e=>e==null?`–`:`${e.toFixed(1)}%`;function a1(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 dSe=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),o1=e=>e===null?`–`:dSe.format(new Date(e));function s1({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(B$,{children:[(0,h.jsx)(V$,{value:r1(t.views),label:`Views`}),(0,h.jsx)(V$,{value:r1(t.impressions),label:`Impressions`}),(0,h.jsx)(V$,{value:i1(t.ctr),label:`Click-through rate`}),(0,h.jsx)(V$,{value:a1(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(V$,{value:r1(t.watchHours),label:`Watch hours`})]})]})}var c1=(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 fSe({channelId:e}){let{api:t}=B(),[n,r]=(0,m.useState)(`newest`),i=F({queryKey:[`studio`,`performance`,e],queryFn:()=>ys(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)(n1,{channelId:e}),(0,h.jsx)(oQ,{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)=>c1(t,n)-c1(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 ${o1(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)(s1,{label:`Long videos`,totals:a.long}),(0,h.jsx)(s1,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(n1,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:`Every video`,children:(0,h.jsx)(cL,{"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)(U$,{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)(pa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>o1(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>r1(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>i1(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>r1(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>a1(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 l1=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],u1={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function pSe(e){return l1.find(t=>t===e)??`brand`}function mSe({channelId:e,tab:t,onTab:n}){let{api:r}=B(),i=_(),a=Yi(),o=F(Zy(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=I({mutationFn:()=>$y(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:Ky}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[];Wv(f===void 0?void 0:`${f.name} · ${u1[t]}`);let g=()=>{n(`cast`),u(`new`)};return cb({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),o.error!==null&&o.data===void 0?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(mG,{crumb:(0,h.jsx)(pa,{to:`/channels`,children:`Channels`}),title:`Channel not opened`}),(0,h.jsx)(oQ,{title:`This channel could not be opened`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(GO,{to:`/channels`,variant:`primary`,children:`Open Channels`}),(0,h.jsx)(z,{disabled:o.isFetching,disabledReason:`Trying again…`,onClick:()=>void o.refetch(),children:`Try again`})]}),children:`${o.error.message} A deleted channel is gone for good (its videos moved to the default channel). Pick a channel from Channels, or press Try again.`})]}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(mG,{crumb:(0,h.jsx)(pa,{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)(z,{variant:`primary`,onClick:g,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(z,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(iQ,{items:l1.map(e=>({id:e,label:u1[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(CR,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be read again: ${o.error.message} What is shown may be out of date; reload the page to try again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(aQ,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(pxe,{channel:f}),(0,h.jsx)(wxe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(Vxe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(cbe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(lbe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Zxe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(tSe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(fSe,{channelId:f.id}):null})]}):null,(0,h.jsx)($v,{open:s,title:D$(f?.name),consequence:d.error?.message??O$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function hSe(){let{api:e}=B(),t=_(),n=Yi(),r=F(Xy(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=I({mutationFn:()=>mre(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:Ky}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=I({mutationFn:t=>Qy(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:Ky}),a(null)}}),v=I({mutationFn:t=>$y(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:Ky})}}),y=()=>{p.reset(),l(``),a(`new`)};cb({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)(mG,{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)(H,{id:`planning.channels`})]}),actions:(0,h.jsxs)(z,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(CR,{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)(oQ,{title:`No channels yet`,actions:(0,h.jsx)(z,{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)(_G,{list:(0,h.jsx)(qL,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(JL,{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)(KO,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(z,{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)(z,{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)(gSe,{channel:f})}):null,(0,h.jsx)(Qv,{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)(CR,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(z,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(z,{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)(aL,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(X,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)($v,{open:o!==null,title:D$(o?.name),consequence:v.error?.message??O$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function gSe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`PDF theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(U,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(GO,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(B$,{className:`mb-6`,children:[(0,h.jsx)(V$,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(V$,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(U,{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)(U,{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 d1=2e3;function f1(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()},d1);return()=>{clearTimeout(t)}},[e])}function p1(){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)(Ac,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function m1({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Lv();cb({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:lk.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)(z,{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)(CR,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(p1,{}):t)}),a,(0,h.jsx)(z,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":bb(lk.save),onClick:()=>{c||s()},children:`Save`})]})}var _Se=`rounded-media border border-line bg-surface p-4`;function h1(){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:`${_Se} 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 vSe=`modulepreload`,ySe=function(e){return`/`+e},g1={},_1=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=ySe(t,n),t=s(t),t in g1)return;g1[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`:vSe,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 v1({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 bSe(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 bSe(e,t){let n=await _1(()=>import(`./pdf-DBgNgPzd.js`),[]),r=await _1(()=>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 y1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),b1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),x1=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),S1=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),C1=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),w1=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),T1=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),E1=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},y1([`page`,`margin`],`Margins`),y1([`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:[T1(`body`,`Body`),T1(`strong`,`Bold text`),T1(`emphasis`,`Italic text`),T1(`heading`,`Headings`),T1(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),T1(`decorative`,`Tagline and title-page link`),T1(`dropCap`,`Drop caps`),T1(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[b1([`sizes`,`title`],`Title`),b1([`sizes`,`brand`],`Brand`),b1([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),b1([`sizes`,`heading`],`Second-level headings`),b1([`sizes`,`subheading`],`Third-level headings`),b1([`sizes`,`body`],`Body`),b1([`sizes`,`meta`],`Date and word count`),b1([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[y1([`spacing`,`bodyLine`],`Body line height`),y1([`spacing`,`headingLine`],`Heading line height`),y1([`spacing`,`subheadingLine`],`Subheading line height`),x1([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),x1([`spacing`,`headingGap`],`Before a heading`,`× line`),x1([`spacing`,`itemGap`],`After a list item`,`× line`),y1([`spacing`,`listIndent`],`List indent`),y1([`spacing`,`quoteIndent`],`Quote indent`),y1([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[S1([`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`}]},x1([`dropCap`,`scale`],`Letter size`,`× lines`),y1([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},x1([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[y1([`titlePage`,`brandY`],`Brand from top`),y1([`titlePage`,`taglineOffset`],`Tagline below brand`),y1([`titlePage`,`titleY`],`Title from top`),y1([`titlePage`,`titleLine`],`Title line height`),y1([`titlePage`,`metaOffset`],`Details below title`),y1([`titlePage`,`metaLine`],`Details line height`),S1([`titlePage`,`showDate`],`Show the date`),S1([`titlePage`,`showWordCount`],`Show the word count`),S1([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),y1([`titlePage`,`cover`,`gap`],`Space around cover`),y1([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[w1([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),w1([`brand`,`tagline`],`Tagline`),w1([`brand`,`url`],`Website`,`Where the brand and its link go.`),w1([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[S1([`contents`,`enabled`],`Contents page`),C1([`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`}]},y1([`contents`,`titleOffset`],`Title from top margin`),y1([`contents`,`firstEntryOffset`],`First entry from top margin`),y1([`contents`,`line`],`Line height`),y1([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[S1([`header`,`enabled`],`Running header`,`The title at the top of each page.`),y1([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},S1([`footer`,`enabled`],`Page numbers`),C1([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),y1([`footer`,`bottom`],`From the bottom`),y1([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[S1([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),C1([`sources`,`title`],`Title`),y1([`sources`,`titleOffset`],`Title from top margin`),y1([`sources`,`bodyOffset`],`List from top margin`),y1([`sources`,`line`],`Line height`),y1([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[S1([`endPage`,`enabled`],`Closing page`),C1([`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.`},S1([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},w1([`endPage`,`closing`],`Closing line`),y1([`endPage`,`titleOffset`],`Title from top margin`),y1([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[C1([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),C1([`metadata`,`subject`],`Subject`),C1([`metadata`,`keywords`],`Keywords`),C1([`metadata`,`creator`],`Creator`)]}],D1=BD.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function O1(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 k1(e,t){let n=e;for(let e of t)n=n?.[e];return n}function A1(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:A1(a,i,n)}}function xSe(e){let t=qD;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function j1(e){return`values.${e.join(`.`)}`}var M1=`pt-1`,N1=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function P1({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Nc,{"aria-hidden":`true`}),e]})}function F1({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(fM,{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 I1(e){return`theme-group-${e.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`}function SSe({problems:e,changed:t}){return e===0&&t===0?null:(0,h.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 text-small font-normal`,children:[e===0?null:(0,h.jsx)(nk,{tone:`failed`,children:`${String(e)} to fix`}),t===0?null:(0,h.jsx)(nk,{children:`${String(t)} changed`})]})}function CSe({groups:e,onJump:t}){return(0,h.jsx)(`nav`,{"aria-label":`Theme groups`,className:`flex flex-wrap gap-1 border-t border-line pt-3`,children:e.map(e=>{let n=[e.problems===0?``:`${String(e.problems)} to fix`,e.changed===0?``:`${String(e.changed)} changed`].filter(e=>e!==``);return(0,h.jsx)(z,{variant:`quiet`,size:`small`,className:e.problems===0?void 0:`text-danger`,onClick:()=>t(e.title),children:n.length===0?e.title:`${e.title} · ${n.join(` · `)}`},e.title)})})}var wSe={"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 L1(e,t){let n=j1(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 TSe({field:e,theme:t,original:n,problem:r,onChange:i}){let a=(0,m.useId)(),o=k1(t,e.path),s=k1(n,e.path),c=z1(t,n,e.path),l=wSe[j1(e.path)],u=n=>{i(A1(t,e.path,n))},d=(0,h.jsxs)(h.Fragment,{children:[l===void 0?null:(0,h.jsx)(H,{id:l,label:e.label,className:`-my-1`}),c?(0,h.jsx)(Nv,{label:`Reset ${e.label} to ${B1(s)}`,tip:`Changed. Reset to ${B1(s)}`,className:`-my-1 size-6`,onClick:()=>u(s),children:(0,h.jsx)(gl,{"aria-hidden":`true`,className:`size-[13px]`})}):null]}),f=e.kind===`color`&&r===void 0?DSe(t,e.path):void 0,p=[e.help===void 0?``:`${a}-help`,r===void 0?``:`${a}-error`,f===void 0?``:`${a}-contrast`].filter(e=>e!==``).join(` `),g=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${a}-help`,className:`sl-field__help m-0`,children:e.help}),r===void 0?null:(0,h.jsx)(`p`,{id:`${a}-error`,className:`sl-field__error m-0`,children:r}),f===void 0?null:(0,h.jsx)(`p`,{id:`${a}-contrast`,className:`m-0 text-small text-waiting`,children:f})]}),_={id:a,"aria-invalid":r!==void 0,"aria-describedby":p===``?void 0:p};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Py,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{..._,type:`checkbox`,checked:o===!0,className:`size-4 accent-accent`,onChange:e=>{u(e.currentTarget.checked)}}),e.label]}),d]}),g]});case`number`:{let{min:t,max:n}=xSe(e.path);return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(X,{..._,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof o==`number`&&Number.isFinite(o)?o:``,onChange:e=>{u(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(u$,{..._,pickerLabel:`${e.label} colour`,value:typeof o==`string`?o:``,onChange:u})});case`text`:return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value)}})});case`optional-text`:return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===o);return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(cL,{..._,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&u(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=o,n=O1(t.family);return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(cL,{..._,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=D1.find(t=>t.value===e.target.value);if(n===void 0)return;let r=O1(n.value).some(e=>e.value===t.style);u({...t,family:n.value,style:r?t.style:`normal`})},children:D1.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(cL,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{u({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(X,{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=>{u({...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`,...Py,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:a,className:`sl-field__label`,children:e.label}),d]}),(0,h.jsx)(sL,{..._,rows:8,value:Array.isArray(o)?o.join(`
274
+ `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&D.length===0?(0,h.jsx)(oQ,{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,D.length>0?(0,h.jsxs)(`section`,{"aria-label":`Existing videos`,className:`mt-4`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search existing videos`,placeholder:`Search existing videos`,value:w,className:`w-full min-w-0 sm:w-64`,onChange:e=>T(e.target.value)}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:O===``?z$(D.length,`title`,`titles`):`${k.length.toLocaleString(`en`)} of ${z$(D.length,`title`,`titles`)} match`})]}),k.length===0?(0,h.jsx)(oQ,{title:`No title matches`,children:`None of the titles contains “${w.trim()}”. Clear the search to see them all.`}):(0,h.jsx)(qL,{label:`Existing videos`,children:A.shown.map(e=>(0,h.jsx)(JL,{title:e.title,actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:j,"aria-label":`Remove ${e.title}`,onClick:()=>S.mutate(e),children:`Remove`})},e.id))}),(0,h.jsx)(I$,{hidden:A.hidden,onMore:A.more})]}):null,(0,h.jsx)($v,{open:o,title:`Remove all ${z$(D.length,`title`,`titles`)}?`,consequence:E.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,cancelLabel:`Keep them`,pending:E.isPending,onConfirm:()=>E.mutate(),onCancel:()=>s(!1)})]})}function B$({className:e,children:t}){return(0,h.jsx)(`dl`,{className:R(`sl-stats m-0`,e),children:t})}function V$({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 H$({value:e,label:t,valueText:n,tone:r=`accent`,progress:i=!1,className:a}){let o=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100),s=n??`${String(o)}%`,c=R(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,a),l=(0,h.jsx)(`span`,{style:{width:`${String(o)}%`}});return i?(0,h.jsx)(`div`,{role:`progressbar`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l}):(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l})}function U$({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:R(`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 W$=56,G$=12,K$=12,nSe=28;function rSe(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 q$({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=rSe(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-W$-G$,y=e=>W$+(f<=1?0:e/(f-1)*v),b=e=>K$+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=K$+i+nSe,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:R(`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-W$)/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:W$,x2:c-G$,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:K$+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:K$,y2:K$+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 J$=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function iSe(e,t){return L(await e.fetch(J$(e,t)))}async function aSe(e,t,n){return L(await e.fetch(J$(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}async function oSe(e,t,n){return L(await e.fetch(`${e.origin}/api/studio/channels/${t}/export-view`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:n})}))}function sSe({channelId:e,saved:t}){let{api:n}=B(),r=_(),i=Lv(),[a,o]=(0,m.useState)(),s=a??t??``,c=I({mutationFn:t=>oSe(n,e,t),onSuccess:t=>{r.setQueryData([`studio`,`report`,e],t),o(void 0),i(t.exportView?`The extension exports this view every day.`:`The extension no longer exports a view for this channel.`,`success`)},onError:e=>i(`The view wasn't saved: ${e.message}`,`error`)});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(X,{"aria-label":`Studio Analytics view to export every day`,placeholder:`https://studio.youtube.com/channel/…/analytics/…/explore?…`,className:`min-w-0 flex-1 basis-[320px]`,value:s,onChange:e=>o(e.currentTarget.value)}),(0,h.jsx)(z,{type:`button`,disabled:c.isPending||s.trim()===(t??``),onClick:()=>c.mutate(s.trim()===``?null:s.trim()),children:`Save view`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The Studio extension opens this view once a day, exports it and brings it in here: every column, and each video's numbers on its project. Paste the address of Analytics → Advanced mode as you set it up; the start date stays, the end moves to today.`})]})}function Y$(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 X$=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],Z$=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),Q$=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function $$(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 cSe({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,[d,f]=(0,m.useState)(!1),p=t.filter(e=>n.includes(e.videoId)),g=e.from===null?new Date:new Date(`${e.from}T00:00:00`),_=Math.max(0,...t.map(e=>e.daily.length)),v,y;if(o===`dates`){let t=c===`all`?0:Math.max(0,_-Number(c)),n=_-t>200;v=Array.from({length:_-t},(e,r)=>{let i=new Date(g);return i.setDate(i.getDate()+t+r),(n?Q$:Z$).format(i)}),y=p.map(e=>{let n=e.daily.findIndex(e=>e>0),a=$$(e.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:e.videoId,label:e.title,color:r(e.videoId),values:a.slice(t)}}),d&&e.dailyTotals!==void 0&&(y=[{id:`channel-total`,label:`Channel total`,color:`var(--color-ink-2)`,values:$$(e.dailyTotals,i).slice(t)},...y])}else{let e=Math.max(1,...p.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));v=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),y=p.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=$$(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let b=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:b}),(0,h.jsx)(`span`,{className:`flex-1`}),e.dailyTotals===void 0||o!==`dates`?null:(0,h.jsxs)(`label`,{className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.currentTarget.checked)}),`Channel total`]}),(0,h.jsx)(cL,{"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)(cL,{"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)(cL,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),p.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(q$,{series:y,xLabels:v,label:`${b} for ${String(p.length)} videos`,formatValue:e1})]})}var e1=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function lSe({report:e,row:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`),s=t.daily.findIndex(e=>e>0);if(s<0)return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart this one, tick it in Advanced mode's chart before you export.`});let c=$$(t.daily.slice(s),n),l=r===`all`?0:Math.max(0,c.length-Number(r)),u=c.slice(l),d=u.map((e,t)=>{let n=new Date(o);return n.setDate(n.getDate()+s+l+t),(u.length>200?Q$:Z$).format(n)}),f=t.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`${a} · ${f.toLocaleString(`en`)} total`}),(0,h.jsx)(q$,{height:180,legend:!1,label:`${a} for ${t.title}`,xLabels:d,formatValue:e1,series:[{id:t.videoId,label:t.title,color:i(t.videoId),values:u}]})]})}var t1=e=>`slopify.studioReport.hidden.${e}`;function uSe(e){try{let t=window.localStorage.getItem(t1(e));return t===null?void 0:JSON.parse(t)}catch{return}}function n1({channelId:e}){let{api:t}=B(),n=_(),r=Lv(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=F({queryKey:a,queryFn:()=>iSe(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(()=>uSe(e)),w=I({mutationFn:n=>aSe(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),T=o.data?.report??null,E=T?.columns??[],D=E.filter((e,t)=>(T?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),O=S??D,k=t=>{C(t);try{window.localStorage.setItem(t1(e),JSON.stringify(t))}catch{}},A=E.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!O.includes(e.label)),j=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},M=[...T?.rows??[]].toSorted((e,t)=>j(t,s)-j(e,s)),ee=[...T?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),N=l??ee.slice(0,5).map(e=>e.videoId),te=e=>{let t=(T?.rows??[]).findIndex(t=>t.videoId===e);return X$[(t<0?0:t)%X$.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(U,{as:`h3`,title:`From Studio's export`,meta:T===null?void 0:`${String(T.rows.length)} videos · ${T.from??`?`} to ${T.to??`?`} · imported ${new Date(T.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&w.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(z,{type:`button`,variant:`secondary`,disabled:w.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,strokeWidth:1.75}),w.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),(0,h.jsx)(sSe,{channelId:e,saved:o.data?.exportView??null}),T===null?null:(0,h.jsxs)(h.Fragment,{children:[T.chartMetric===null?null:(0,h.jsx)(cSe,{report:T,rows:M,picked:N,colorOf:te,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)(cL,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:E.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(A.length),` of `,String(E.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:E.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!O.includes(e.label),onChange:t=>k(t.currentTarget.checked?O.filter(t=>t!==e.label):[...O,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),A.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),A.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:Y$(T.totals[t]??null,e.kind,e.label)},e.label))]}),M.map(e=>{let t=o.data?.projects[e.videoId],n=b===e.videoId;return(0,h.jsxs)(m.Fragment,{children:[(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:N.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...N,e.videoId]:N.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:N.includes(e.videoId)?te(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[T.chartMetric===null?null:(0,h.jsx)(Nv,{size:`small`,"aria-expanded":n,label:`${n?`Hide`:`Show`} the chart of ${e.title}`,onClick:()=>x(n?void 0:e.videoId),children:n?(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})}),t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title})]}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),A.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:Y$(e.values[n]??null,t.kind,t.label)},t.label))]}),n?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:A.length+2,children:(0,h.jsx)(lSe,{report:T,row:e,shape:d,range:v,colorOf:te})})}):null]},e.videoId)})]})]})})]})]})}var r1=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),i1=e=>e==null?`–`:`${e.toFixed(1)}%`;function a1(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 dSe=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),o1=e=>e===null?`–`:dSe.format(new Date(e));function s1({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(B$,{children:[(0,h.jsx)(V$,{value:r1(t.views),label:`Views`}),(0,h.jsx)(V$,{value:r1(t.impressions),label:`Impressions`}),(0,h.jsx)(V$,{value:i1(t.ctr),label:`Click-through rate`}),(0,h.jsx)(V$,{value:a1(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(V$,{value:r1(t.watchHours),label:`Watch hours`})]})]})}var c1=(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 fSe({channelId:e}){let{api:t}=B(),[n,r]=(0,m.useState)(`newest`),i=F({queryKey:[`studio`,`performance`,e],queryFn:()=>ys(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)(n1,{channelId:e}),(0,h.jsx)(oQ,{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)=>c1(t,n)-c1(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 ${o1(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)(s1,{label:`Long videos`,totals:a.long}),(0,h.jsx)(s1,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(n1,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:`Every video`,children:(0,h.jsx)(cL,{"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)(U$,{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)(pa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>o1(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>r1(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>i1(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>r1(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>a1(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 l1=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],u1={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function pSe(e){return l1.find(t=>t===e)??`brand`}function mSe({channelId:e,tab:t,onTab:n}){let{api:r}=B(),i=_(),a=Yi(),o=F(Zy(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=I({mutationFn:()=>$y(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:Ky}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[];Wv(f===void 0?void 0:`${f.name} · ${u1[t]}`);let g=()=>{n(`cast`),u(`new`)};return cb({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),o.error!==null&&o.data===void 0?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(mG,{crumb:(0,h.jsx)(pa,{to:`/channels`,children:`Channels`}),title:`Channel not opened`}),(0,h.jsx)(oQ,{title:`This channel could not be opened`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(GO,{to:`/channels`,variant:`primary`,children:`Open Channels`}),(0,h.jsx)(z,{disabled:o.isFetching,disabledReason:`Trying again…`,onClick:()=>void o.refetch(),children:`Try again`})]}),children:`${o.error.message} A deleted channel is gone for good (its videos moved to the default channel). Pick a channel from Channels, or press Try again.`})]}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(mG,{crumb:(0,h.jsx)(pa,{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)(z,{variant:`primary`,onClick:g,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(z,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(iQ,{items:l1.map(e=>({id:e,label:u1[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(CR,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be read again: ${o.error.message} What is shown may be out of date; reload the page to try again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(aQ,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(pxe,{channel:f}),(0,h.jsx)(wxe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(Vxe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(cbe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(lbe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Zxe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(tSe,{channelId:f.id}):null}),(0,h.jsx)(aQ,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(fSe,{channelId:f.id}):null})]}):null,(0,h.jsx)($v,{open:s,title:D$(f?.name),consequence:d.error?.message??O$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function hSe(){let{api:e}=B(),t=_(),n=Yi(),r=F(Xy(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=I({mutationFn:()=>mre(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:Ky}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=I({mutationFn:t=>Qy(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:Ky}),a(null)}}),v=I({mutationFn:t=>$y(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:Ky})}}),y=()=>{p.reset(),l(``),a(`new`)};cb({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)(mG,{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)(H,{id:`planning.channels`})]}),actions:(0,h.jsxs)(z,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(CR,{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)(oQ,{title:`No channels yet`,actions:(0,h.jsx)(z,{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)(_G,{list:(0,h.jsx)(qL,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(JL,{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)(KO,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(z,{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)(z,{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)(gSe,{channel:f})}):null,(0,h.jsx)(Qv,{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)(CR,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(z,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(z,{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)(aL,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(X,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)($v,{open:o!==null,title:D$(o?.name),consequence:v.error?.message??O$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function gSe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`PDF theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(U,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(GO,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(B$,{className:`mb-6`,children:[(0,h.jsx)(V$,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(V$,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(U,{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)(U,{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 d1=2e3;function f1(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()},d1);return()=>{clearTimeout(t)}},[e])}function p1(){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)(Ac,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function m1({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Lv();cb({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:lk.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)(z,{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)(CR,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(p1,{}):t)}),a,(0,h.jsx)(z,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":bb(lk.save),onClick:()=>{c||s()},children:`Save`})]})}var _Se=`rounded-media border border-line bg-surface p-4`;function h1(){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:`${_Se} 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 vSe=`modulepreload`,ySe=function(e){return`/`+e},g1={},_1=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=ySe(t,n),t=s(t),t in g1)return;g1[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`:vSe,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 v1({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 bSe(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 bSe(e,t){let n=await _1(()=>import(`./pdf-C1R7KZQ3.js`),[]),r=await _1(()=>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 y1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),b1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),x1=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),S1=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),C1=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),w1=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),T1=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),E1=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},y1([`page`,`margin`],`Margins`),y1([`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:[T1(`body`,`Body`),T1(`strong`,`Bold text`),T1(`emphasis`,`Italic text`),T1(`heading`,`Headings`),T1(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),T1(`decorative`,`Tagline and title-page link`),T1(`dropCap`,`Drop caps`),T1(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[b1([`sizes`,`title`],`Title`),b1([`sizes`,`brand`],`Brand`),b1([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),b1([`sizes`,`heading`],`Second-level headings`),b1([`sizes`,`subheading`],`Third-level headings`),b1([`sizes`,`body`],`Body`),b1([`sizes`,`meta`],`Date and word count`),b1([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[y1([`spacing`,`bodyLine`],`Body line height`),y1([`spacing`,`headingLine`],`Heading line height`),y1([`spacing`,`subheadingLine`],`Subheading line height`),x1([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),x1([`spacing`,`headingGap`],`Before a heading`,`× line`),x1([`spacing`,`itemGap`],`After a list item`,`× line`),y1([`spacing`,`listIndent`],`List indent`),y1([`spacing`,`quoteIndent`],`Quote indent`),y1([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[S1([`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`}]},x1([`dropCap`,`scale`],`Letter size`,`× lines`),y1([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},x1([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[y1([`titlePage`,`brandY`],`Brand from top`),y1([`titlePage`,`taglineOffset`],`Tagline below brand`),y1([`titlePage`,`titleY`],`Title from top`),y1([`titlePage`,`titleLine`],`Title line height`),y1([`titlePage`,`metaOffset`],`Details below title`),y1([`titlePage`,`metaLine`],`Details line height`),S1([`titlePage`,`showDate`],`Show the date`),S1([`titlePage`,`showWordCount`],`Show the word count`),S1([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),y1([`titlePage`,`cover`,`gap`],`Space around cover`),y1([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[w1([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),w1([`brand`,`tagline`],`Tagline`),w1([`brand`,`url`],`Website`,`Where the brand and its link go.`),w1([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[S1([`contents`,`enabled`],`Contents page`),C1([`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`}]},y1([`contents`,`titleOffset`],`Title from top margin`),y1([`contents`,`firstEntryOffset`],`First entry from top margin`),y1([`contents`,`line`],`Line height`),y1([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[S1([`header`,`enabled`],`Running header`,`The title at the top of each page.`),y1([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},S1([`footer`,`enabled`],`Page numbers`),C1([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),y1([`footer`,`bottom`],`From the bottom`),y1([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[S1([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),C1([`sources`,`title`],`Title`),y1([`sources`,`titleOffset`],`Title from top margin`),y1([`sources`,`bodyOffset`],`List from top margin`),y1([`sources`,`line`],`Line height`),y1([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[S1([`endPage`,`enabled`],`Closing page`),C1([`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.`},S1([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},w1([`endPage`,`closing`],`Closing line`),y1([`endPage`,`titleOffset`],`Title from top margin`),y1([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[C1([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),C1([`metadata`,`subject`],`Subject`),C1([`metadata`,`keywords`],`Keywords`),C1([`metadata`,`creator`],`Creator`)]}],D1=BD.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function O1(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 k1(e,t){let n=e;for(let e of t)n=n?.[e];return n}function A1(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:A1(a,i,n)}}function xSe(e){let t=qD;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function j1(e){return`values.${e.join(`.`)}`}var M1=`pt-1`,N1=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function P1({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Nc,{"aria-hidden":`true`}),e]})}function F1({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(fM,{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 I1(e){return`theme-group-${e.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`}function SSe({problems:e,changed:t}){return e===0&&t===0?null:(0,h.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 text-small font-normal`,children:[e===0?null:(0,h.jsx)(nk,{tone:`failed`,children:`${String(e)} to fix`}),t===0?null:(0,h.jsx)(nk,{children:`${String(t)} changed`})]})}function CSe({groups:e,onJump:t}){return(0,h.jsx)(`nav`,{"aria-label":`Theme groups`,className:`flex flex-wrap gap-1 border-t border-line pt-3`,children:e.map(e=>{let n=[e.problems===0?``:`${String(e.problems)} to fix`,e.changed===0?``:`${String(e.changed)} changed`].filter(e=>e!==``);return(0,h.jsx)(z,{variant:`quiet`,size:`small`,className:e.problems===0?void 0:`text-danger`,onClick:()=>t(e.title),children:n.length===0?e.title:`${e.title} · ${n.join(` · `)}`},e.title)})})}var wSe={"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 L1(e,t){let n=j1(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 TSe({field:e,theme:t,original:n,problem:r,onChange:i}){let a=(0,m.useId)(),o=k1(t,e.path),s=k1(n,e.path),c=z1(t,n,e.path),l=wSe[j1(e.path)],u=n=>{i(A1(t,e.path,n))},d=(0,h.jsxs)(h.Fragment,{children:[l===void 0?null:(0,h.jsx)(H,{id:l,label:e.label,className:`-my-1`}),c?(0,h.jsx)(Nv,{label:`Reset ${e.label} to ${B1(s)}`,tip:`Changed. Reset to ${B1(s)}`,className:`-my-1 size-6`,onClick:()=>u(s),children:(0,h.jsx)(gl,{"aria-hidden":`true`,className:`size-[13px]`})}):null]}),f=e.kind===`color`&&r===void 0?DSe(t,e.path):void 0,p=[e.help===void 0?``:`${a}-help`,r===void 0?``:`${a}-error`,f===void 0?``:`${a}-contrast`].filter(e=>e!==``).join(` `),g=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${a}-help`,className:`sl-field__help m-0`,children:e.help}),r===void 0?null:(0,h.jsx)(`p`,{id:`${a}-error`,className:`sl-field__error m-0`,children:r}),f===void 0?null:(0,h.jsx)(`p`,{id:`${a}-contrast`,className:`m-0 text-small text-waiting`,children:f})]}),_={id:a,"aria-invalid":r!==void 0,"aria-describedby":p===``?void 0:p};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Py,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{..._,type:`checkbox`,checked:o===!0,className:`size-4 accent-accent`,onChange:e=>{u(e.currentTarget.checked)}}),e.label]}),d]}),g]});case`number`:{let{min:t,max:n}=xSe(e.path);return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(X,{..._,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof o==`number`&&Number.isFinite(o)?o:``,onChange:e=>{u(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(u$,{..._,pickerLabel:`${e.label} colour`,value:typeof o==`string`?o:``,onChange:u})});case`text`:return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value)}})});case`optional-text`:return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===o);return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(cL,{..._,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&u(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=o,n=O1(t.family);return(0,h.jsx)(R1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(cL,{..._,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=D1.find(t=>t.value===e.target.value);if(n===void 0)return;let r=O1(n.value).some(e=>e.value===t.style);u({...t,family:n.value,style:r?t.style:`normal`})},children:D1.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(cL,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{u({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(X,{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=>{u({...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`,...Py,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:a,className:`sl-field__label`,children:e.label}),d]}),(0,h.jsx)(sL,{..._,rows:8,value:Array.isArray(o)?o.join(`
275
275
  `):``,onChange:e=>{u(e.target.value.split(`
276
276
  `))}}),g]});case`link`:{let t=o;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Py,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:a,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{u(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),d]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(X,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{u({...t,text:e.target.value})}}),(0,h.jsx)(X,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{u({...t,url:e.target.value===``?null:e.target.value})}})]}),g]})}}}function R1({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Py,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 z1(e,t,n){return JSON.stringify(k1(e,n))!==JSON.stringify(k1(t,n))}function B1(e){return e==null||e===``?`empty`:typeof e==`boolean`?e?`on`:`off`:typeof e==`string`||typeof e==`number`?String(e):`the starting value`}var ESe={"colors.text":4.5,"colors.heading":3,"colors.muted":3,"colors.faint":3};function DSe(e,t){let n=ESe[t.join(`.`)];if(n===void 0||e.background.image!==null)return;let r=k1(e,t);if(typeof r==`string`)return l$(r,e.background.color,`the page colour`,n)}function V1({themeId:e,from:t,onLeave:n}){let{api:r}=B(),i=_(),a=F(Ty(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=I({mutationFn:t=>Qs(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:Ty(r).queryKey})}}),w=I({mutationFn:e=>$s(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:Ty(r).queryKey}),n()}});f1(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:qD.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:Fle(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)(H1,{children:a.error.message});if(v===void 0)return(0,h.jsx)(h1,{});if(S===void 0)return(0,h.jsx)(H1,{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=E1.map(e=>({title:e.title,problems:e.fields.filter(e=>L1(E,e.path)!==void 0).length,changed:x===void 0?0:e.fields.filter(e=>z1(S.values,x.values,e.path)).length})),k=O.filter(e=>e.problems>0).map(e=>e.title),A=S.name.trim()===``?`Give the theme a name.`:E.length>0?k.length===0?`Fix the highlighted settings first.`:`Fix the highlighted settings first, in ${k.join(`, `)}.`:void 0,j=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(mG,{crumb:(0,h.jsx)(P1,{children:(0,h.jsx)(pa,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New PDF theme`:`Edit PDF 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:`${M1} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(aL,{label:`Name`,tip:`library.theme.name`,...j.length===0?{}:{error:j.map(e=>e.message).join(` `)},children:(0,h.jsx)(X,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),(0,h.jsx)(CSe,{groups:O,onJump:e=>{let t=document.getElementById(I1(e));t instanceof HTMLDetailsElement&&(t.open=!0,t.scrollIntoView?.({block:`start`,behavior:`smooth`}),t.querySelector(`summary`)?.focus())}}),E1.map((e,t)=>{let n=O[t];return(0,h.jsxs)(`details`,{id:I1(e.title),open:t<2||(n?.problems??0)>0,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)(Nc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title,(0,h.jsx)(SSe,{problems:n?.problems??0,changed:n?.changed??0})]}),(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)(TSe,{field:e,theme:S.values,original:x?.values??S.values,problem:L1(E,e.path),onChange:t=>{D({...S,values:t},j1(e.path))}},e.path.join(`.`)))})]},e.title)}),(0,h.jsx)(m1,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:A,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(GO,{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)(OSe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)($v,{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)}})]})}function OSe({values:e}){let{api:t}=B(),[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`),ec(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:N1,children:[(0,h.jsx)(U,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(qO,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Uc,{"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)(v1,{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 H1({children:e}){return(0,h.jsx)(F1,{back:(0,h.jsx)(pa,{to:`/document-themes`,children:`Back to Documents`}),children:e})}function U1({selection:e,total:t,noun:n,scope:r,busy:i,onDuplicate:a,onExport:o,onDelete:s,deleteLabel:c=`Delete selected`}){return e.count===0?null:(0,h.jsx)(CG,{selection:e,total:t,noun:n,className:`mb-2`,...r===void 0?{}:{scope:r},actions:(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsxs)(z,{size:`small`,disabled:i,disabledReason:`Working on the last press`,onClick:a,children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,className:`size-[14px]`}),`Duplicate selected`]}),o===void 0?null:(0,h.jsxs)(z,{size:`small`,onClick:o,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-[14px]`}),`Export selected`]}),(0,h.jsxs)(z,{size:`small`,variant:`destructive`,disabled:i,disabledReason:`Working on the last press`,onClick:s,children:[(0,h.jsx)(xl,{"aria-hidden":`true`,className:`size-[14px]`}),c]})]})})}function W1({selection:e,children:t}){return(0,h.jsx)(`div`,{onKeyDown:e.onKeyDown,children:t})}function G1(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${K1(e.fonts.body.family)} body`}function K1(e){return D1.find(t=>t.value===e)?.label??e}function q1(e){return e.startsWith(`#`)?e:`#${e}`}function J1({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)(U,{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)(Y1,{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:q1(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:q1(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(Y1,{label:`${e} font`,children:`${K1(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(Y1,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${q1(r.background.color)}`} background`})]})]})}function Y1({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 X1({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:q1(e)}},t))})}var Z1=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,Q1=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function $1({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 e0({what:e,message:t,onRetry:n}){return(0,h.jsx)(fM,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(z,{size:`small`,onClick:n,children:`Try again`}),children:t})}function t0({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:R(`flex flex-wrap items-center gap-0.5`,o),children:[t,r===void 0?null:(0,h.jsx)(z,{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`}),(0,h.jsxs)(YO,{children:[(0,h.jsx)(XO,{asChild:!0,children:(0,h.jsx)(Nv,{size:`small`,label:`More actions for ${e}`,children:(0,h.jsx)(Hc,{"aria-hidden":`true`})})}),(0,h.jsxs)(ZO,{children:[(0,h.jsx)(QO,{asChild:!0,children:n}),i===void 0?null:(0,h.jsxs)(QO,{"aria-label":`History of ${e}`,onSelect:i,children:[(0,h.jsx)(hl,{"aria-hidden":`true`,className:`size-4`}),`History`]}),(0,h.jsx)($O,{}),(0,h.jsxs)(QO,{"aria-label":`Delete ${e}`,onSelect:a,children:[(0,h.jsx)(xl,{"aria-hidden":`true`,className:`size-4`}),`Delete`]})]})]})]})}var n0=[{value:`name`,label:`Name`},{value:`changed`,label:`Last changed`}];function r0(e,t){return[...e].sort((e,n)=>t===`changed`?n.updatedAt.localeCompare(e.updatedAt)||e.name.localeCompare(n.name):e.name.localeCompare(n.name,void 0,{sensitivity:`base`}))}var i0=e=>`slopify.library.sort.${e}`;function kSe(e){try{return globalThis.localStorage?.getItem(i0(e))===`changed`?`changed`:`name`}catch{return`name`}}function a0(e){let[t,n]=(0,m.useState)(()=>kSe(e));return[t,t=>{n(t);try{globalThis.localStorage?.setItem(i0(e),t)}catch{}}]}function o0({what:e,sort:t,onSort:n}){let r=n0.find(e=>e.value===t)?.label??`Name`;return(0,h.jsxs)(YO,{children:[(0,h.jsx)(XO,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,size:`small`,"aria-label":`Sort ${e}: ${r}`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`}),r]})}),(0,h.jsx)(ZO,{align:`start`,children:n0.map(e=>(0,h.jsxs)(QO,{"aria-label":`Sort by ${e.label.toLowerCase()}${e.value===t?` (current)`:``}`,onSelect:()=>n(e.value),children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:e.value===t?`size-4`:`size-4 opacity-0`}),e.value===`changed`?`Last changed first`:`Name, A to Z`]},e.value))})]})}var ASe=4e3;function s0(e){return e.match(/\s+|[^\s]+/gu)??[]}function jSe(e,t){let n=s0(e),r=s0(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=[];l0(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 NSe(s,c))l0(o,e.op,e.text);return l0(o,`same`,n.slice(n.length-a).join(``)),o}function c0(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function MSe(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+s0(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function l0(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 NSe(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,ASe),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())l0(f,e.op,e.text);return f}function u0({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>jSe(e,t),[e,t]),a=MSe(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)(d0,{label:n,parts:c0(i,`before`)}),(0,h.jsx)(d0,{label:r,parts:c0(i,`after`)})]})]})}function d0({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:PSe(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 PSe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var f0={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function p0(e,t){let{api:n}=B();return F({queryKey:f0.versions(e,t),queryFn:()=>Ks(n,e,t)})}function FSe(e,t){let{api:n}=B();return F({queryKey:f0.usedBy(e,t),queryFn:()=>qs(n,e,t)})}function m0({item:e,id:t,name:n,onClose:r}){let{api:i}=B(),a=_(),o=p0(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=I({mutationFn:n=>Js(i,e,t,n),onSuccess:async(n,r)=>{v(`Restored version ${String(r)} as a new version.`),l({}),await Promise.all([a.invalidateQueries({queryKey:f0.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?V.prompts:V.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)(eM,{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)(U,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(aL,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(cL,{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:g0(e,b)},e.version))})}),(0,h.jsx)(aL,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(cL,{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:g0(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)(u0,{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)(U,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(qL,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(JL,{title:`Version ${String(e.version)}`,meta:h0(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(z,{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)(CR,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function h0(e){return`${e.author} · ${_0(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function g0(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${_0(e.createdAt)}`}function _0(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function v0({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)(U,{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)(lL,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(ISe,{item:e,id:t}),(0,h.jsx)(LSe,{item:e,id:t,name:n,onOpenHistory:c})]})}function ISe({item:e,id:t}){let n=FSe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:RSe(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)(qL,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(JL,{title:(0,h.jsx)(pa,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(JL,{title:(0,h.jsx)(pa,{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)(JL,{title:(0,h.jsx)(pa,{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 LSe({item:e,id:t,name:n,onOpenHistory:r}){let i=p0(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:(0,h.jsx)(`span`,{title:b0(o.createdAt),children:`${y0(a.length,`version`)} · latest ${h0(o)}`})},children:(0,h.jsx)(z,{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)(u0,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function RSe(e){return[y0(e.templates.length,`template`),y0(e.schedules.length,`schedule`),y0(e.projects.length,`project`)].join(`, `)}function y0(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function zSe(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}function b0(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,timeZoneName:`short`})}function x0({iso:e,children:t}){return(0,h.jsx)(`time`,{dateTime:e,title:b0(e),children:t??zSe(e)})}function S0({what:e,exports:t,accept:n,onFile:r,disabled:i=!1}){let a=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(YO,{children:[(0,h.jsx)(XO,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,disabled:i,disabledReason:`Still loading`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,className:`size-[14px]`}),`Import or export`]})}),(0,h.jsxs)(ZO,{children:[t.map(e=>(0,h.jsxs)(QO,{disabled:e.disabled===!0,onSelect:e.run,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-4`}),e.label]},e.label)),(0,h.jsx)($O,{}),(0,h.jsxs)(QO,{onSelect:()=>a.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,className:`size-4`}),`Import from a file…`]})]})]}),(0,h.jsx)(`input`,{ref:a,type:`file`,hidden:!0,accept:n,"aria-label":`Import ${e} from a file`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&r(t)}})]})}var C0=`slopify-library`,BSe=20971520,w0=1e4,VSe={prompts:`prompts`,entries:`intros or outros`,documentThemes:`PDF themes`,aliases:`narration aliases`},T0={prompts:e=>({kind:e.kind,name:e.name,body:e.body}),entries:e=>({category:e.category,mode:e.mode,name:e.name,body:e.body}),documentThemes:e=>({name:e.name,values:e.values}),aliases:e=>({written:e.written,spoken:e.spoken,wholeWord:e.wholeWord,caseSensitive:e.caseSensitive})};function E0(e,t){return{format:C0,version:1,exportedAt:t.toISOString(),...e.prompts===void 0?{}:{prompts:e.prompts.map(T0.prompts)},...e.entries===void 0?{}:{entries:e.entries.map(T0.entries)},...e.documentThemes===void 0?{}:{documentThemes:e.documentThemes.map(T0.documentThemes)},...e.aliases===void 0?{}:{aliases:e.aliases.map(T0.aliases)}}}var D0=e=>G({error:`it has no name.`}).trim().min(1,{error:`it has no name.`}).max(e,{error:`its name is longer than ${String(e)} characters.`}),O0=G({error:`it has no text.`}).max(zb,{error:`its text is longer than ${String(zb)} characters.`}),HSe={prompts:J({kind:Y(Lb,{error:`its kind isn't one of ${Lb.join(`, `)}.`}),name:D0(200),body:O0}),entries:J({category:Y(Rb,{error:`it is neither an intro nor an outro.`}),mode:Y(Mb,{error:`its mode isn't one of ${Mb.join(`, `)}.`}),name:D0(200),body:O0}),documentThemes:J({name:D0(80),values:qD}),aliases:XD},USe=J({format:nT(C0),version:K().int().positive()}).loose();function k0(e,t){let n=VSe[t],r;try{r=JSON.parse(e)}catch{return{ok:!1,message:`it isn't a Slopify library file (the text isn't JSON). Pick a .json file made by Export.`}}let i=USe.safeParse(r);if(!i.success)return{ok:!1,message:`it isn't a Slopify library file. Pick a .json file made by Export on a Library tab.`};if(i.data.version>1)return{ok:!1,message:`it was made by a newer Slopify. Update Slopify (Settings → Updates), then import it again.`};let a=i.data[t];if(!Array.isArray(a)||a.length===0)return{ok:!1,message:`it holds no ${n}. Import it on the Library tab it was exported from.`};if(a.length>w0)return{ok:!1,message:`it holds more than ${String(w0)} ${n}. Split it into smaller files.`};let o=[],s=[],c=HSe[t];for(let[e,t]of a.entries()){let n=c.safeParse(t);n.success?o.push(n.data):s.push({item:WSe(t,e),reason:GSe(n.error)})}return{ok:!0,items:o,skipped:s}}function WSe(e,t){let n=J({name:G().trim().min(1)}).safeParse(e);if(n.success)return n.data.name;let r=J({written:G().trim().min(1)}).safeParse(e);return r.success?r.data.written:`Item ${String(t+1)}`}function GSe(e){let t=e.issues[0];if(t===void 0)return`it doesn't fit.`;let[n]=t.path;return n===`values`?`its setting ${t.path.slice(1).join(`.`)}: ${t.message}`:n===`written`||n===`spoken`?`its ${n===`written`?`written form`:`spoken form`} is empty or too long.`:typeof n==`string`&&/^it/u.test(t.message)?t.message:n===void 0?`it isn't an item.`:`its ${String(n)} is missing or wrong.`}function KSe(e,t,n){return A0(e,t,n,e=>e===1?` (imported)`:` (imported ${String(e)})`)}function qSe(e,t,n){return A0(e,t,n,e=>e===1?` copy`:` copy ${String(e)}`,!1)}function A0(e,t,n,r,i=!0){let a=e.trim();if(i&&!t.has(a.toLowerCase()))return a;for(let e=1;;e+=1){let i=r(e),o=`${a.slice(0,Math.max(0,n-i.length)).trimEnd()}${i}`;if(!t.has(o.toLowerCase()))return o}}var j0=e=>e instanceof Error?e.message:String(e);function M0({noun:e,listKey:t,all:n,groupOf:r=()=>``,nameMax:i,duplicate:a,remove:o,trash:s,selection:c}){let{api:l}=B(),u=_(),d=Lv(),f=t=>wG(t,e[0],e[1]),p=async()=>{await Promise.all([u.invalidateQueries({queryKey:t}),...s===void 0?[]:[u.invalidateQueries({queryKey:ZZ})]])},m=(e,t,n)=>{let r=e[0];r!==void 0&&d(`${f(e.length)} ${e.length===1?`wasn't`:`weren't`} ${t}: “${r.item.name}”: ${r.reason} ${n}`,`error`)},h=I({mutationFn:async e=>{let t=new Map;for(let e of n){let n=t.get(r(e))??new Set;n.add(e.name.trim().toLowerCase()),t.set(r(e),n)}let o=[],s=[];for(let n of e){let e=t.get(r(n))??new Set;t.set(r(n),e);let c=qSe(n.name,e,i);try{let t=await a(n,c);t===null?(e.add(c.toLowerCase()),o.push(c)):s.push({item:n,reason:t})}catch(e){s.push({item:n,reason:j0(e)})}}return{made:o,refused:s}},onSuccess:({made:e,refused:t})=>{let[n]=e;e.length===1&&n!==void 0?d(`Duplicated as “${n}”.`,`success`):e.length>1&&d(`Duplicated ${f(e.length)}.`,`success`),m(t,`duplicated`,`Press Duplicate selected again.`)},onError:e=>d(`Nothing was duplicated: ${j0(e)} Press Duplicate selected again.`,`error`),onSettled:async()=>{c.clear(),await p()}}),g=async(t,n)=>{try{let e=await eQ(l,t.map(e=>({kind:n,id:e.id})));e.failed.length>0?d(`${f(e.failed.length)} couldn't be restored: ${e.failed[0]?.detail??``} Restore ${e.failed.length===1?`it`:`them`} in Settings → Backup & storage → Trash.`,`error`):d(`Restored ${f(e.restored.length)}.`,`success`)}catch(t){d(`The ${e[1]} weren't restored: ${j0(t)} Restore them in Settings → Backup & storage → Trash.`,`error`)}finally{await p()}},v=I({mutationFn:async e=>{let t=[],n=[];for(let r of e)try{await o(r),t.push(r)}catch(e){n.push({item:r,reason:j0(e)})}return{done:t,refused:n}},onSuccess:({done:e,refused:t})=>{e.length>0&&(s===void 0?d(`Deleted ${f(e.length)} permanently.`,`success`):d(`Moved ${f(e.length)} to the trash.`,`success`,{label:`Undo`,run:()=>void g(e,s)})),m(t,`deleted`,`Press Delete selected again.`)},onError:e=>d(`Nothing was deleted: ${j0(e)} Press Delete selected again.`,`error`),onSettled:async()=>{c.clear(),await p()}});return{duplicate:e=>h.mutate(e),remove:e=>v.mutate(e),busy:h.isPending||v.isPending}}function N0(e){return e.ok?null:(e.fields??[]).map(e=>e.message).join(` `)}function P0(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=document.createElement(`a`);i.href=r,i.download=e,i.click(),URL.revokeObjectURL(r)}function F0(e,t){P0(`slopify-${e}-${t.exportedAt.slice(0,10)}.json`,`${JSON.stringify(t,null,2)}\n`,`application/json`)}async function I0(e){if(e.size>20971520)return{ok:!1,message:`it is larger than ${String(BSe/1024/1024)} MB, far more than a Library export. Pick the .json file Export made.`};try{return{ok:!0,text:await e.text()}}catch(e){return{ok:!1,message:`the file couldn't be read (${e instanceof Error?e.message:String(e)}). Pick it again.`}}}var JSe=3;async function YSe(e,t){let n=new Map,r=e=>{let t=n.get(e);if(t!==void 0)return t;let r=new Set;return n.set(e,r),r};for(let e of t.existing)r(e.group).add(e.name.trim().toLowerCase());let i=0,a=0,o=[];for(let n of e){let e=r(t.groupOf(n)),s=``;for(let r=0;r<JSe;r+=1){let r=KSe(n.name,e,t.max);try{let o=await t.save({...n,name:r});if(e.add(r.toLowerCase()),o.ok){i+=1,r!==n.name.trim()&&(a+=1),s=``;break}if(s=o.fields.map(e=>e.message).join(` `),!o.fields.some(e=>e.field===`name`))break}catch(e){s=e instanceof Error?e.message:String(e);break}}s!==``&&o.push({item:n.name.trim()||`An item`,reason:s})}return{added:i,renamed:a,skipped:o}}function L0(e){if(e.length===0)return``;let t=e.slice(0,3).map(e=>`“${e.item}”: ${e.reason}`).join(` `),n=e.length>3?` And ${String(e.length-3)} more.`:``;return`Skipped ${String(e.length)}: ${t}${n}`}function XSe(e,t,n){let r=L0(n.skipped);if(n.added===0)return{text:`Nothing was imported from ${e}. ${r} Fix the file and import it again.`,tone:`error`};let i=n.renamed===0?``:` ${wG(n.renamed,`was`,`were`)} renamed “(imported)” because the name was taken.`;return{text:`Imported ${wG(n.added,t[0],t[1])} from ${e}.${i}${r===``?``:` ${r}`}`,tone:`success`}}var R0=(e,t)=>`${e} wasn't imported: ${t}`;function z0({section:e,pack:t,stem:n,noun:r,listKey:i,existing:a,groupOf:o,nameMax:s,save:c}){let l=_(),u=Lv(),d=I({mutationFn:async t=>{let n=await I0(t);if(!n.ok)return{refused:n.message};let r=k0(n.text,e);if(!r.ok)return{refused:r.message};let i=await YSe(r.items,{existing:a.map(e=>({group:o(e),name:e.name})),groupOf:o,max:s,save:c});return{outcome:{...i,skipped:[...r.skipped,...i.skipped]}}},onSuccess:(e,t)=>{if(`refused`in e){u(R0(t.name,e.refused),`error`);return}let n=XSe(t.name,r,e.outcome);u(n.text,n.tone)},onError:(e,t)=>u(R0(t.name,`${e.message} Press Import or export, then Import from a file, to try again.`),`error`),onSettled:()=>l.invalidateQueries({queryKey:i})});return{exportItems:e=>{F0(n,E0(t(e),new Date)),u(`Exported ${wG(e.length,r[0],r[1])}.`,`success`)},importFile:e=>d.mutate(e),importing:d.isPending}}var ZSe=[{label:`Setups`,tabs:[{to:`/templates`,label:`Templates`}]},{label:`Building blocks`,tabs:[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & outros`},{to:`/document-themes`,label:`PDF themes`},{to:`/narration-aliases`,label:`Narration aliases`}]},{label:`Results`,tabs:[{to:`/ab-results`,label:`A/B results`}]}];function QSe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(mG,{title:`Library`,meta:`Templates to start from, and the prompts, intros and outros, PDF themes and narration aliases they use`}),(0,h.jsx)(`div`,{className:`mb-6 flex min-w-0 flex-wrap items-end gap-x-8 gap-y-3 border-b border-line`,children:ZSe.map(e=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:e.label}),(0,h.jsx)(sbe,{items:e.tabs,label:e.label,className:`border-b-0`})]},e.label))}),(0,h.jsx)($Se,{}),(0,h.jsx)(ka,{})]})}function $Se(){let e=Yi(),t=Va({select:e=>e.location}),n=t.search,r=Yb(t.pathname===`/prompts`?n.kind:void 0),i=Kb(t.pathname===`/entries`?n.category:void 0);return cb({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),cb({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),cb({id:`library.new-document-theme`,title:`New PDF theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`,`document`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),cb({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),cb({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),cb({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),cb({id:`library.open-document-themes`,title:`Open PDF themes`,group:`Library`,keywords:[`pdf`,`documents`,`document themes`],run:()=>{e({to:`/document-themes`})}}),null}function B0({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:R(`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)(Fv,{className:`ml-auto shrink-0`,children:t})]})}function eCe(){let{api:e}=B(),t=_(),n=F(Ty(e)),[r,i]=tL(),[a,o]=a0(`document-theme`),[s,c]=(0,m.useState)(void 0),l=I({mutationFn:t=>$s(e,t),onSettled:async()=>{c(void 0),await t.invalidateQueries({queryKey:V.documentThemes})}}),u=n.data,d=u===void 0?[]:r0(u.themes,a),f=d.find(e=>e.id===r),p=f===void 0?u?.builtIns.find(e=>e.name===r):void 0,g=f===void 0&&p===void 0?d[0]:void 0,v=f??g,y=v===void 0?p??u?.builtIns[0]:void 0,b=yG(d.map(e=>e.id)),x=d.filter(e=>b.has(e.id)),[S,C]=(0,m.useState)(!1),w=M0({noun:V0,listKey:V.documentThemes,all:d,nameMax:80,duplicate:async(t,n)=>N0(await Qs(e,{name:n,values:t.values},void 0)),remove:t=>$s(e,t.id),trash:void 0,selection:b}),T=z0({section:`documentThemes`,pack:e=>({documentThemes:e}),stem:`pdf-themes`,noun:V0,listKey:V.documentThemes,existing:d,groupOf:()=>``,nameMax:80,save:t=>Qs(e,t,void 0)});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B0,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(S0,{what:`PDF themes`,disabled:u===void 0||T.importing,exports:[{label:`Export all ${wG(d.length,`theme`,`themes`)} of yours`,run:()=>T.exportItems(d),disabled:d.length===0}],accept:`.json,application/json`,onFile:T.importFile}),(0,h.jsx)(GO,{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)(e0,{what:`PDF themes`,message:n.error.message,onRetry:()=>void n.refetch()}),u===void 0?n.error===null?(0,h.jsx)($1,{label:`PDF themes`}):null:(0,h.jsx)(_G,{className:Z1,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)(U,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`,children:d.length>1?(0,h.jsx)(o0,{what:`your themes`,sort:a,onSort:o}):null}),u.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.jsxs)(W1,{selection:b,children:[(0,h.jsx)(U1,{selection:b,total:d.length,noun:V0,busy:w.busy,onDuplicate:()=>w.duplicate(x),onExport:()=>T.exportItems(x),onDelete:()=>C(!0)}),(0,h.jsx)(qL,{label:`Your themes`,children:d.map(e=>(0,h.jsx)(JL,{className:Q1,lead:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(xG,{selection:b,value:e.id,label:e.name}),(0,h.jsx)(X1,{colors:e.values.colors})]}),title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[`${G1(e.values)} · updated `,(0,h.jsx)(x0,{iso:e.updatedAt})]}),selected:e.id===v?.id,onSelect:()=>i(e.id),actions:(0,h.jsx)(t0,{name:e.name,edit:(0,h.jsx)(GO,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(GO,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>c(e)})},e.id))})]})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(qL,{label:`Built-in themes`,children:u.builtIns.map(e=>(0,h.jsx)(JL,{className:Q1,lead:(0,h.jsx)(X1,{colors:e.values.colors}),title:e.label,meta:G1(e.values),selected:e.name===y?.name,onSelect:()=>i(e.name),actions:(0,h.jsx)(GO,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:v===void 0?y===void 0?null:(0,h.jsx)(J1,{name:y.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:y.values,action:(0,h.jsx)(GO,{to:`/document-themes/new`,search:{from:y.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(J1,{name:v.name,kicker:`Your theme`,meta:(0,h.jsxs)(h.Fragment,{children:[`Updated `,(0,h.jsx)(x0,{iso:v.updatedAt})]}),values:v.values,action:(0,h.jsx)(GO,{to:`/document-themes/$themeId`,params:{themeId:v.id},size:`small`,children:`Edit theme`})})}),l.error===null?null:(0,h.jsx)(fM,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:l.error.message}),(0,h.jsx)($v,{open:s!==void 0,title:`Delete the PDF theme “${s?.name??``}”?`,consequence:tCe,confirmLabel:`Delete theme permanently`,pending:l.isPending,onConfirm:()=>{s!==void 0&&l.mutate(s.id)},onCancel:()=>c(void 0)}),(0,h.jsx)($v,{open:S,title:`Delete ${wG(x.length,`PDF theme`,`PDF themes`)} permanently?`,consequence:`${x.length===1?`“${x[0]?.name??``}” is`:`These ${String(x.length)} themes are`} deleted permanently: PDF themes do not go to Settings → Trash, so they cannot be restored. Projects that used them keep their own copy of the settings.`,confirmLabel:`Delete ${wG(x.length,`theme`,`themes`)} permanently`,cancelLabel:`Keep them`,pending:w.busy,onConfirm:()=>{w.remove(x),C(!1)},onCancel:()=>C(!1)})]})}var V0=[`PDF theme`,`PDF themes`],tCe=`It is deleted permanently: PDF themes do not go to Settings → Trash, so it cannot be restored. Projects that used it keep their own copy of its settings.`;function H0(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 U0({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Lv(),[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`,...Py,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(X,{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)(z,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(H,{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)(YL,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(Nv,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(ul,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function nCe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=B(),a=_(),o=F(wy(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=lb(l,`intros and outros`),[d,f]=tL(),[p,g]=a0(`entry`),[v,y]=(0,m.useState)(void 0),[b,x]=(0,m.useState)(void 0),S=I({mutationFn:e=>ic(i,e),onSettled:async()=>{y(void 0),await a.invalidateQueries({queryKey:V.entries})}}),C=async(e,t)=>{let n=await Xs(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:V.entries}),n.ok?null:H0(n.fields)},w=o.data?.entries.filter(t=>t.category===e),T=s.trim().toLowerCase(),E=T===``?w:w?.filter(e=>e.name.toLowerCase().includes(T)||e.body.toLowerCase().includes(T)),D=E===void 0?void 0:r0(E,p),O=D?.find(e=>e.id===d)??D?.[0],k=o.data?.entries??[],A=yG(D?.map(e=>e.id)??[]),j=D?.filter(e=>A.has(e.id))??[],M=[e,`${e}s`],ee=M0({noun:M,listKey:V.entries,all:k,groupOf:e=>e.category,nameMax:200,duplicate:async(e,t)=>N0(await Xs(i,{category:e.category,mode:e.mode,name:t,body:e.body},void 0)),remove:e=>ic(i,e.id),trash:`entry`,selection:A}),N=z0({section:`entries`,pack:e=>({entries:e}),stem:`intros-and-outros`,noun:[`intro or outro`,`intros and outros`],listKey:V.entries,existing:k,groupOf:e=>e.category,nameMax:200,save:e=>Xs(i,e,void 0)});return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B0,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(S0,{what:`intros and outros`,disabled:o.data===void 0||N.importing,exports:[{label:`Export all ${String(k.length)} intros and outros`,run:()=>N.exportItems(k),disabled:k.length===0}],accept:`.json,application/json`,onFile:N.importFile}),(0,h.jsx)(GO,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`})]}),children:[(0,h.jsx)(X,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":bb(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)(Iy,{label:`Entry category`,value:e,options:Bb.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`}),(0,h.jsx)(o0,{what:`intros and outros`,sort:p,onSort:g})]}),o.error===null?null:(0,h.jsx)(e0,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),D===void 0||w===void 0?o.error===null?(0,h.jsx)($1,{label:`Intros and outros`}):null:w.length===0?(0,h.jsx)(iCe,{category:e}):(0,h.jsx)(_G,{className:Z1,list:D.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.jsxs)(W1,{selection:A,children:[(0,h.jsx)(U1,{selection:A,total:D.length,noun:M,scope:T===``?void 0:`Select all ${String(D.length)} shown`,busy:ee.busy,onDuplicate:()=>ee.duplicate(j),onExport:()=>N.exportItems(j),onDelete:()=>ee.remove(j)}),(0,h.jsx)(qL,{label:`${Hb(e)}s`,children:D.map(e=>(0,h.jsx)(JL,{className:Q1,lead:(0,h.jsx)(xG,{selection:A,value:e.id,label:e.name}),title:(0,h.jsx)(U0,{name:e.name,onSelect:()=>f(e.id),onRename:t=>C(e,t)}),meta:rCe(e),selected:e.id===O?.id,actions:(0,h.jsx)(t0,{name:e.name,edit:(0,h.jsx)(GO,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(GO,{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:()=>x(e),onDelete:()=>y(e)})},e.id))})]}),detail:O===void 0?null:(0,h.jsx)(v0,{item:`entry`,id:O.id,name:O.name,kicker:`${Hb(O.category)} · ${Ub(O.mode)}`,meta:(0,h.jsxs)(h.Fragment,{children:[`Updated `,(0,h.jsx)(x0,{iso:O.updatedAt})]}),body:O.body,slots:O.slots,actions:(0,h.jsx)(GO,{to:`/entries/$entryId`,params:{entryId:O.id},size:`small`,children:`Edit ${O.category}`}),onOpenHistory:()=>x(O)},O.id)}),S.error===null?null:(0,h.jsx)(fM,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:S.error.message}),b===void 0?null:(0,h.jsx)(m0,{item:`entry`,id:b.id,name:b.name,onClose:()=>x(void 0)},b.id),(0,h.jsx)($v,{open:v!==void 0,title:v===void 0?``:`Delete "${v.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${v?.category??e}`,pending:S.isPending,onConfirm:()=>{v!==void 0&&S.mutate(v.id)},onCancel:()=>y(void 0)})]})}function rCe(e){return(0,h.jsxs)(h.Fragment,{children:[`${Ub(e.mode)} · ${y0(e.slots.length,`keyword`)} · updated `,(0,h.jsx)(x0,{iso:e.updatedAt})]})}function iCe({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(oQ,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function aCe({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:R(`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 W0({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)(U,{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)(aCe,{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=>{let n=sCe(t,e.message);return(0,h.jsxs)(`span`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message}),n===void 0?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,onClick:()=>cCe(r,n),children:`Go to ${oCe(e.message)??`it`}`})]},e.message)})]})]})}var G0=/line (\d+), column (\d+)/;function oCe(e){return G0.exec(e)?.[0]}function sCe(e,t){let n=G0.exec(t);if(n===null)return;let r=e.split(`
277
277
  `),i=Number(n[1]),a=Number(n[2]);if(!(i<1||i>r.length))return r.slice(0,i-1).reduce((e,t)=>e+t.length+1,0)+a-1}function cCe(e,t){let n=document.querySelector(`textarea[aria-describedby~="${e}"]`);n instanceof HTMLTextAreaElement&&(n.focus(),n.setSelectionRange(t,Math.min(t+2,n.value.length)))}function K0({className:e,...t}){return(0,h.jsx)(vne,{"data-slot":`label`,className:R(`engraved block select-none text-ink-3`,e),...t})}function q0({className:e,...t}){return(0,h.jsx)(Mne,{"data-slot":`toggle-group`,className:R(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function J0({className:e,...t}){return(0,h.jsx)(Lne,{"data-slot":`toggle-group-item`,className:R(`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 Y0({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...Py,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K0,{id:o,children:e}),i===void 0?null:(0,h.jsx)(H,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(q0,{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)(J0,{value:e.value,children:e.label},e.value))})]})}function X0(e){return Z0(e.name,e.body)}function lCe(e){return Z0(e.name,e.body)}function Z0(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(zb)} characters or fewer.`}),n;for(let e of YW(t).errors)n.push({field:`body`,message:uCe(e,t)});return n}function uCe(e,t){let n=dCe(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 dCe(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`