@gentbajko/slopify 3.2.1 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -265,45 +265,45 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
265
265
  `)}function Dq(e,t){if(e.trim()===``)return{ok:!0,rows:[]};let n;try{n=oq(e,{schema:`failsafe`,uniqueKeys:!0})}catch(e){return{ok:!1,problems:[`The list couldn't be read as YAML or JSON: ${(e instanceof Error?e.message.split(`
266
266
  `)[0]:``)??``}. Write one item per topic, such as "- Topic: Cleopatra".`]}}if(!Array.isArray(n))return{ok:!1,problems:[`The list must be a list of topics: start each one with "- " in YAML, or wrap them in [ ] in JSON.`]};let r=[],i=[];n.forEach((e,n)=>{let a=`Topic ${String(n+1)}`;if(typeof e==`string`){i.push({title:e.trim(),values:{}});return}if(typeof e!=`object`||!e||Array.isArray(e)){r.push(`${a} is not a topic or a set of keywords. Write it as "- Cleopatra" or "- Topic: Cleopatra".`);return}let o=``,s={};for(let[n,i]of Object.entries(e)){let e=n.trim(),c=i??``;if(typeof c!=`string`){r.push(`${a}: ${bq(e)} holds a list or a map. Give it one value, such as "${e}: 12000".`);continue}t.topicKeyword!==null&&e===t.topicKeyword?o=c.trim():t.keywords.includes(e)?s[e]=c.trim():r.push(`${a}: ${bq(e)} is not a keyword of this template (its keywords are ${xq(t.keywords)}). Rename it to one of them or remove it.`)}i.push({title:o,values:s})});let a=[...r,...Cq(i,t)];return a.length>0?{ok:!1,problems:a}:{ok:!0,rows:i}}function Oq(e,t){return e.length===0?``:sq(e.map(e=>Object.keys(e.values).length===0||t===null?e.title:{[t]:e.title,...e.values}),{lineWidth:0})}function kq({title:e,crumb:t,meta:n,actions:r,display:i=!1,row:a=!1,className:o}){return a?(0,h.jsxs)(`header`,{className:L(`sl-page-header-row mb-4 flex flex-wrap items-center gap-x-4 gap-y-2`,o),"data-slot":`page-header`,children:[t===void 0?null:(0,h.jsx)(`div`,{className:`sl-crumb shrink-0`,children:t}),(0,h.jsx)(`h1`,{className:`sl-title-1 min-w-0 break-words`,children:e}),n===void 0?null:(0,h.jsx)(`p`,{className:`m-0 min-w-0 text-small text-ink-2`,children:n}),r===void 0?null:(0,h.jsx)(`div`,{className:`sl-btn-row ml-auto`,children:r})]}):(0,h.jsxs)(`header`,{className:L(`mb-6 flex flex-wrap items-end justify-between gap-4`,o),"data-slot":`page-header`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[t===void 0?null:(0,h.jsx)(`div`,{className:`sl-crumb`,children:t}),(0,h.jsx)(`h1`,{className:L(i?`sl-display`:`sl-title-1`,`mt-1 break-words`),children:e}),n===void 0?null:(0,h.jsx)(`p`,{className:`m-0 mt-1 text-small text-ink-2`,children:n})]}),r===void 0?null:(0,h.jsx)(`div`,{className:`sl-btn-row`,children:r})]})}function Aq({sections:e,aside:t,asideLabel:n=`Status and next action`,children:r,className:i}){return(0,h.jsxs)(`div`,{className:L(`sl-workspace`,e===void 0&&`sl-workspace--no-sections`,t===void 0&&`sl-workspace--no-aside`,e===void 0&&t===void 0&&`!grid-cols-1`,i),children:[e===void 0?null:(0,h.jsx)(`div`,{className:`sl-workspace__sections`,children:e}),(0,h.jsx)(`div`,{className:`sl-workspace__main`,children:r}),t===void 0?null:(0,h.jsx)(`aside`,{"aria-label":n,className:`sl-workspace__aside`,children:t})]})}function jq({list:e,detail:t,className:n}){return(0,h.jsxs)(`div`,{className:L(`sl-listdetail`,n),children:[(0,h.jsx)(`div`,{className:`sl-listdetail__list`,children:e}),(0,h.jsx)(`div`,{className:`sl-listdetail__detail`,children:t})]})}function Mq({className:e}){return(0,h.jsx)(`hr`,{className:L(`sl-rule`,e)})}q({id:wD(),name:W().trim().min(1).max(120),document:PM}).strict().readonly().unwrap().extend({name:W().trim().min(1).max(200),baseVersion:G().int().positive(),mutationId:wD()}).strict().readonly(),q({id:wD(),baseVersion:G().int().positive()}).strict().readonly(),q({templateId:wD(),id:wD(),version:G().int().positive()}).strict().readonly(),q({id:wD(),name:W(),version:G().int().positive(),createdAt:W(),updatedAt:W(),document:PM}).strict().readonly();var Nq=q({id:wD(),name:W(),version:G().int().positive(),updatedAt:W(),channelId:W().optional()}),Pq=Nq.extend({document:PM}),Fq=tO([Pq,q({template:Pq}).transform(e=>e.template)]),Iq=q({title:W(),detail:W().optional(),reason:W().optional()}),Lq=[`project-templates`],Rq=e=>`${e.origin}/api/project-templates`;async function zq(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=Iq.safeParse(n);if(!r.success)throw po(e,void 0);let i=r.data.detail??r.data.title;if(![400,404,409].includes(e.status))throw Error(i);return{ok:!1,message:i,reason:r.data.reason??`invalid-request`}}var Bq=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});async function Vq(e){return zq(await e.fetch(Rq(e)),q({templates:K(Nq)}).transform(e=>e.templates))}function Hq(e){return{queryKey:Lq,queryFn:async()=>{let t=await Vq(e);if(!t.ok)throw Error(t.message);return t.value}}}async function Uq(e,t,n){let r=n===void 0?``:`?version=${String(n)}`;return zq(await e.fetch(`${Rq(e)}/${encodeURIComponent(t)}${r}`),Fq)}async function Wq(e,t){let n=q({id:wD(),name:W().trim().min(1),document:PM}).parse(t);return zq(await e.fetch(Rq(e),Bq(`POST`,n)),Fq)}async function Gq(e,t,n){let r=q({baseVersion:G().int().positive(),mutationId:wD(),name:W().trim().min(1),document:PM}).parse(n);return zq(await e.fetch(`${Rq(e)}/${encodeURIComponent(t)}`,Bq(`PUT`,r)),Fq)}async function Kq(e,t,n){let r=await Uq(e,t);if(!r.ok)return`The name wasn't saved: ${r.message} Press Refresh templates, then rename it again.`;let i=await Gq(e,t,{baseVersion:r.value.version,mutationId:crypto.randomUUID(),name:n,document:r.value.document});return i.ok?null:`The name wasn't saved: ${i.message}${i.reason===`conflict`?` Press Refresh templates, then rename it again.`:``}`}async function qq(e,t,n){let r=q({id:wD(),name:W().trim().min(1).max(120),revisionId:W().min(1).max(64)}).parse(n);return zq(await e.fetch(`${Rq(e)}/from-project/${encodeURIComponent(t)}`,Bq(`POST`,r)),Fq)}async function Jq(e,t){let n=await e.fetch(`${Rq(e)}/${encodeURIComponent(t.id)}`,Bq(`DELETE`,{baseVersion:t.version}));return n.ok?{ok:!0,value:null}:zq(n,qD())}async function Yq(e,t,n){return zq(await e.fetch(`${Rq(e)}/next-chapter/${encodeURIComponent(t)}`,Bq(`POST`,{id:wD().parse(n)})),tO([WM,q({draft:WM}).transform(e=>e.draft)]))}async function Xq(e,t,n){let r=q({id:wD(),version:G().int().positive()}).parse({id:n,version:t.version});return zq(await e.fetch(`${Rq(e)}/${encodeURIComponent(t.id)}/instantiate`,Bq(`POST`,r)),tO([WM,q({draft:WM}).transform(e=>e.draft)]))}var X=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n||=self,n.JSBI=r())})(e,function(){var e=Math.imul,t=Math.clz32;function n(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function r(e){if(Array.isArray(e))return e}function i(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function a(e,t,n){return t=d(t),_(e,m()?Reflect.construct(t,n||[],d(e).constructor):t.apply(e,n))}function o(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function s(e,t,n){if(m())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&v(i,n.prototype),i}function c(e,t){for(var n,r=0;r<t.length;r++)n=t[r],n.enumerable=n.enumerable||!1,n.configurable=!0,`value`in n&&(n.writable=!0),Object.defineProperty(e,x(n.key),n)}function l(e,t,n){return t&&c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(e,t){var n=typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(!n){if(Array.isArray(e)||(n=C(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
267
267
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}function f(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&v(e,t)}function p(e){try{return Function.toString.call(e).indexOf(`[native code]`)!==-1}catch{return typeof e==`function`}}function m(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(m=function(){return!!e})()}function h(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function g(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
268
- 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),Zq=X.default.BigInt(0),Qq=X.default.BigInt(1),$q=X.default.BigInt(2),eJ=X.default.BigInt(10),tJ=X.default.BigInt(24),nJ=X.default.BigInt(60),rJ=X.default.BigInt(1e3),iJ=X.default.BigInt(1e6),aJ=X.default.BigInt(1e9),oJ=X.default.multiply(X.default.BigInt(3600),aJ),sJ=X.default.multiply(nJ,aJ),cJ=X.default.multiply(oJ,tJ);function lJ(e){return typeof e==`bigint`?X.default.BigInt(e.toString(10)):e}function uJ(e){return X.default.equal(X.default.remainder(e,$q),Zq)}function dJ(e){return X.default.lessThan(e,Zq)?X.default.unaryMinus(e):e}function fJ(e,t){return X.default.lessThan(e,t)?-1:+!!X.default.greaterThan(e,t)}function pJ(e,t){return{quotient:X.default.divide(e,t),remainder:X.default.remainder(e,t)}}var mJ,hJ,gJ=`slot-epochNanoSeconds`,_J=`slot-iso-date`,vJ=`slot-iso-date-time`,yJ=`slot-time`,Z=`slot-calendar`,bJ=`slot-date-brand`,xJ=`slot-year-month-brand`,SJ=`slot-month-day-brand`,CJ=`slot-time-zone`,wJ=`slot-years`,TJ=`slot-months`,EJ=`slot-weeks`,DJ=`slot-days`,OJ=`slot-hours`,kJ=`slot-minutes`,AJ=`slot-seconds`,jJ=`slot-milliseconds`,MJ=`slot-microseconds`,NJ=`slot-nanoseconds`,PJ=`date`,FJ=`ym`,IJ=`md`,LJ=`time`,RJ=`datetime`,zJ=`instant`,BJ=`original`,VJ=`timezone-canonical`,HJ=`timezone-original`,UJ=`calendar-id`,WJ=`locale`,GJ=`options`,KJ=new WeakMap,qJ=Symbol.for(`@@Temporal__GetSlots`);(mJ=globalThis)[qJ]||(mJ[qJ]=function(e){return KJ.get(e)});var JJ=globalThis[qJ],YJ=Symbol.for(`@@Temporal__CreateSlots`);(hJ=globalThis)[YJ]||(hJ[YJ]=function(e){KJ.set(e,Object.create(null))});var XJ=globalThis[YJ];function ZJ(e,...t){if(!e||typeof e!=`object`)return!1;let n=JJ(e);return!!n&&t.every((e=>e in n))}function Q(e,t){let n=JJ(e)?.[t];if(n===void 0)throw TypeError(`Missing internal slot ${t}`);return n}function QJ(e,t,n){let r=JJ(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 $J={};function eY(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))}tY(t,e),tY(`${t}.prototype`,e.prototype)}function tY(e,t){let n=`%${e}%`;if($J[n]!==void 0)throw Error(`intrinsic ${e} already exists`);$J[n]=t}function nY(e){return $J[e]}function rY(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 iY(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 aY(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 oY(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 sY=class e{constructor(e){this.totalNs=lJ(e),this.sec=X.default.toNumber(X.default.divide(this.totalNs,aJ)),this.subsec=X.default.toNumber(X.default.remainder(this.totalNs,aJ))}static validateNew(t,n){if(X.default.greaterThan(dJ(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=X.default.subtract(lJ(t),lJ(n));return new e(r)}static fromComponents(t,n,r,i,a,o){let s=X.default.add(X.default.add(X.default.add(X.default.add(X.default.add(X.default.BigInt(o),X.default.multiply(X.default.BigInt(a),rJ)),X.default.multiply(X.default.BigInt(i),iJ)),X.default.multiply(X.default.BigInt(r),aJ)),X.default.multiply(X.default.BigInt(n),sJ)),X.default.multiply(X.default.BigInt(t),oJ));return e.validateNew(s,`total`)}abs(){return new e(dJ(this.totalNs))}add(t){return e.validateNew(X.default.add(this.totalNs,t.totalNs),`sum`)}add24HourDays(t){return e.validateNew(X.default.add(this.totalNs,X.default.multiply(X.default.BigInt(t),cJ)),`sum`)}addToEpochNs(e){return X.default.add(lJ(e),this.totalNs)}cmp(e){return fJ(this.totalNs,e.totalNs)}divmod(t){let{quotient:n,remainder:r}=pJ(this.totalNs,X.default.BigInt(t));return{quotient:X.default.toNumber(n),remainder:new e(r)}}fdiv(e){let t=lJ(e),n=X.default.BigInt(t),{quotient:r,remainder:i}=pJ(this.totalNs,n),a=[],o,s=(X.default.lessThan(this.totalNs,Zq)?-1:1)*Math.sign(X.default.toNumber(t));for(;!X.default.equal(i,Zq)&&a.length<50;)i=X.default.multiply(i,eJ),{quotient:o,remainder:i}=pJ(i,n),a.push(Math.abs(X.default.toNumber(o)));return s*Number(dJ(r).toString()+`.`+a.join(``))}isZero(){return X.default.equal(this.totalNs,Zq)}round(t,n){let r=lJ(t);if(X.default.equal(r,Qq))return this;let{quotient:i,remainder:a}=pJ(this.totalNs,r),o=X.default.lessThan(this.totalNs,Zq)?`negative`:`positive`,s=X.default.multiply(dJ(i),r),c=X.default.add(s,r),l=fJ(dJ(X.default.multiply(a,$q)),r),u=aY(n,o),d=X.default.equal(dJ(this.totalNs),s)?s:oY(s,c,l,uJ(i),u),f=o===`positive`?d:X.default.unaryMinus(d);return e.validateNew(f,`rounding`)}sign(){return this.cmp(new e(Zq))}subtract(t){return e.validateNew(X.default.subtract(this.totalNs,t.totalNs),`difference`)}};sY.MAX=X.default.BigInt(`9007199254740991999999999`),sY.ZERO=new sY(Zq);var cY=/[A-Za-z._][A-Za-z._0-9+-]*/,lY=RegExp(`(?:(?:[+-](?:[01][0-9]|2[0-3])(?::?[0-5][0-9])?)|(?:${cY.source})(?:\\/(?:${cY.source}))*)`),uY=/(?:[+-]\d{6}|\d{4})/,dY=/(?:0[1-9]|1[0-2])/,fY=/(?:0[1-9]|[12]\d|3[01])/,pY=RegExp(`(${uY.source})(?:-(${dY.source})-(${fY.source})|(${dY.source})(${fY.source}))`),mY=/(\d{2})(?::(\d{2})(?::(\d{2})(?:[.,](\d{1,9}))?)?|(\d{2})(?:(\d{2})(?:[.,](\d{1,9}))?)?)?/,hY=/((?:[+-])(?:[01][0-9]|2[0-3])(?::?(?:[0-5][0-9])(?::?(?:[0-5][0-9])(?:[.,](?:\d{1,9}))?)?)?)/,gY=RegExp(`([zZ])|${hY.source}?`),_Y=/\[(!)?([a-z_][a-z0-9_-]*)=([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)\]/g,vY=new RegExp([`^${pY.source}`,`(?:(?:[tT]|\\s+)${mY.source}(?:${gY.source})?)?`,`(?:\\[!?(${lY.source})\\])?`,`((?:${_Y.source})*)$`].join(``)),yY=new RegExp([`^[tT]?${mY.source}`,`(?:${gY.source})?`,`(?:\\[!?${lY.source}\\])?`,`((?:${_Y.source})*)$`].join(``)),bY=RegExp(`^(${uY.source})-?(${dY.source})(?:\\[!?${lY.source}\\])?((?:${_Y.source})*)$`),xY=RegExp(`^(?:--)?(${dY.source})-?(${fY.source})(?:\\[!?${lY.source}\\])?((?:${_Y.source})*)$`),SY=/(\d+)(?:[.,](\d{1,9}))?/,CY=RegExp(`(?:${SY.source}H)?(?:${SY.source}M)?(?:${SY.source}S)?`),wY=RegExp(`^([+-])?P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?!$)${CY.source})?$`,`i`),TY=864e5,EY=1e6*TY,DY=6e10,OY=1e8*TY,kY=D$(OY),AY=X.default.unaryMinus(kY),jY=X.default.add(X.default.subtract(AY,cJ),Qq),MY=X.default.subtract(X.default.add(kY,cJ),Qq),NY=146097*TY,PY=-271821,FY=275760,IY=Date.UTC(1847,0,1),LY=[`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`],RY=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 zY(e){return typeof e==`object`&&!!e||typeof e==`function`}function BY(e){if(typeof e==`bigint`)throw TypeError(`Cannot convert BigInt to number`);return Number(e)}function VY(e){if(typeof e==`symbol`)throw TypeError(`Cannot convert a Symbol value to a String`);return String(e)}function HY(e){let t=BY(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 UY(e,t){let n=HY(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 WY(e){let t=BY(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 GY(e,t){return String(e).padStart(t,`0`)}function KY(e){if(typeof e!=`string`)throw TypeError(`expected a string, not ${String(e)}`);return e}function qY(e,t){if(zY(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 JY=[`era`,`eraYear`,`year`,`month`,`monthCode`,`day`,`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],YY={era:VY,eraYear:HY,year:HY,month:UY,monthCode:function(e){let t=KY(qY(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:UY,hour:HY,minute:HY,second:HY,millisecond:HY,microsecond:HY,nanosecond:HY,offset:function(e){let t=KY(qY(e));return eQ(t),t},timeZone:MZ},XY={hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},ZY=[[`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`]],QY=Object.fromEntries(ZY.map((e=>[e[0],e[1]]))),$Y=Object.fromEntries(ZY.map((([e,t])=>[t,e]))),eX=ZY.map((([,e])=>e)),tX={day:EY,hour:36e11,minute:6e10,second:1e9,millisecond:1e6,microsecond:1e3,nanosecond:1},nX=[`days`,`hours`,`microseconds`,`milliseconds`,`minutes`,`months`,`nanoseconds`,`seconds`,`weeks`,`years`],rX=Intl.DateTimeFormat,iX=new Map;function aX(e){let t=I$(e),n=iX.get(t);return n===void 0&&(n=new rX(`en-us`,{timeZone:t,hour12:!1,era:`short`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`}),iX.set(t,n)),n}function oX(e){return ZJ(e,gJ)&&!ZJ(e,CJ,Z)}function sX(e){return ZJ(e,wJ,TJ,DJ,OJ,kJ,AJ,jJ,MJ,NJ)}function cX(e){return ZJ(e,bJ)}function lX(e){return ZJ(e,yJ)}function uX(e){return ZJ(e,vJ)}function dX(e){return ZJ(e,xJ)}function fX(e){return ZJ(e,SJ)}function pX(e){return ZJ(e,gJ,CJ,Z)}function $(e,t){if(!t(e))throw TypeError(`invalid receiver: method called with the wrong type of this-object`)}function mX(e){if(ZJ(e,Z)||ZJ(e,CJ))throw TypeError(`with() does not support a calendar or timeZone property`);if(lX(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 hX(e,t){return t===`never`||t===`auto`&&e===`iso8601`?``:`[${t===`critical`?`!`:``}u-ca=${e}]`}function gX(e){let t,n,r=!1;for(_Y.lastIndex=0;n=_Y.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 _X(e){let t=vY.exec(e);if(!t)throw RangeError(`invalid RFC 9557 string: ${e}`);let n=gX(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 jQ(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 vX(e){let t=yY.exec(e),n,r,i,a,o,s,c;if(t){c=gX(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}=_X(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(AQ(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}=bX(e);OQ(1972,t,n)}catch{try{let{year:t,month:n}=yX(e);OQ(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 yX(e){let t=bY.exec(e),n,r,i,a;if(t){i=gX(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}=_X(e),t)throw RangeError(`Z designator not supported for PlainYearMonth`)}return{year:n,month:r,calendar:i,referenceISODay:a}}function bX(e){let t=xY.exec(e),n,r,i,a;if(t){if(i=gX(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}=_X(e),t)throw RangeError(`Z designator not supported for PlainMonthDay`)}return{month:n,day:r,calendar:i,referenceISOYear:a}}var xX=RegExp(`^${lY.source}$`,`i`),SX=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])?)?$`);function CX(e){let t=R$.test(e)?`Seconds not allowed in offset time zone`:`Invalid time zone`;throw RangeError(`${t}: ${e}`)}function wX(e){return xX.test(e)||CX(e),SX.test(e)?{offsetMinutes:eQ(e)/6e10}:{tzName:e}}function TX(e,t,n,r){let i=e,a=t,o=n;switch(r){case`reject`:OQ(i,a,o);break;case`constrain`:({year:i,month:a,day:o}=EQ(i,a,o))}return{year:i,month:a,day:o}}function EX(e,t,n,r,i,a,o){let s=e,c=t,l=n,u=r,d=i,f=a;switch(o){case`reject`:AQ(s,c,l,u,d,f);break;case`constrain`:s=TQ(s,0,23),c=TQ(c,0,59),l=TQ(l,0,59),u=TQ(u,0,999),d=TQ(d,0,999),f=TQ(f,0,999)}return{hour:s,minute:c,second:l,millisecond:u,microsecond:d,nanosecond:f}}function DX(e){if(!zY(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<nX.length;r++){let i=nX[r],a=e[i];a!==void 0&&(n=!0,t[i]=WY(a))}if(!n)throw TypeError(`invalid duration-like`);return t}function OX({years:e,months:t,weeks:n,days:r},i,a,o){return{years:e,months:o??t,weeks:a??n,days:i??r}}function kX(e,t){return{isoDate:e,time:t}}function AX(e){return P$(e,`overflow`,[`constrain`,`reject`],`constrain`)}function jX(e){return P$(e,`disambiguation`,[`compatible`,`earlier`,`later`,`reject`],`compatible`)}function MX(e,t){return P$(e,`roundingMode`,[`ceil`,`floor`,`expand`,`trunc`,`halfCeil`,`halfFloor`,`halfExpand`,`halfTrunc`,`halfEven`],t)}function NX(e,t){return P$(e,`offset`,[`prefer`,`use`,`ignore`,`reject`],t)}function PX(e){return P$(e,`calendarName`,[`auto`,`always`,`never`,`critical`],`auto`)}function FX(e){let t=e.roundingIncrement;if(t===void 0)return 1;let n=HY(t);if(n<1||n>1e9)throw RangeError(`roundingIncrement must be at least 1 and at most 1e9, not ${t}`);return n}function IX(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 LX(e){let t=e.fractionalSecondDigits;if(t===void 0)return`auto`;if(typeof t!=`number`){if(VY(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 RX(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 zX=Symbol(`~required~`);function BX(e,t,n,r,i=[]){let a=[];for(let e=0;e<ZY.length;e++){let t=ZY[e],r=t[1],i=t[2];n!==`datetime`&&n!==i||a.push(r)}a=a.concat(i);let o=r;o===zX?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=$Y[a[e]];t!==void 0&&s.push(t)}let c=P$(e,t,s,o);if(c===void 0&&r===zX)throw RangeError(`${t} is required`);return c&&c in QY?QY[c]:c}function VX(e){let t=e.relativeTo;if(t===void 0)return{};let n,r,i,a,o,s=`option`,c=!1;if(zY(t)){if(pX(t))return{zonedRelativeTo:t};if(cX(t))return{plainRelativeTo:t};if(uX(t))return{plainRelativeTo:lZ(Q(t,vJ).isoDate,Q(t,Z))};i=DZ(t);let e=YX(i,t,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],[]);({isoDate:n,time:r}=QX(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}=_X(KY(t)),e)a=MZ(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=F$(i),n={year:u,month:d,day:f}}return a===void 0?{plainRelativeTo:lZ(n,i)}:{zonedRelativeTo:xZ(oZ(n,r,s,s===`option`?eQ(o):0,a,`compatible`,`reject`,c),a,i)}}function HX(e){return Q(e,wJ)===0?Q(e,TJ)===0?Q(e,EJ)===0?Q(e,DJ)===0?Q(e,OJ)===0?Q(e,kJ)===0?Q(e,AJ)===0?Q(e,jJ)===0?Q(e,MJ)===0?`nanosecond`:`microsecond`:`millisecond`:`second`:`minute`:`hour`:`day`:`week`:`month`:`year`}function UX(e,t){return eX.indexOf(e)>eX.indexOf(t)?t:e}function WX(e){return e===`year`||e===`month`||e===`week`}function GX(e){return WX(e)||e===`day`?`date`:`time`}function KX(e){return nY(`%calendarImpl%`)(e)}function qX(e){return nY(`%calendarImpl%`)(Q(e,Z))}function JX(e,t,n=`date`){let r=Object.create(null),i=KX(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 YX(e,t,n,r,i){let a=KX(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,YY[n])(r);else if(i!==`partial`){if(i.includes(n))throw TypeError(`required property '${n}' missing or undefined`);s[n]=XY[n]}}if(i===`partial`&&!c)throw TypeError(`no supported properties found`);return s}function XX(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]=HY(s),r=!0)}if(!r)throw TypeError(`invalid time-like`);return i}function ZX(e,t){if(zY(e)){if(cX(e))return AX(M$(t)),lZ(Q(e,_J),Q(e,Z));if(pX(e)){let n=IZ(Q(e,CJ),Q(e,gJ));return AX(M$(t)),lZ(n.isoDate,Q(e,Z))}if(uX(e))return AX(M$(t)),lZ(Q(e,vJ).isoDate,Q(e,Z));let n=DZ(e);return lZ(kZ(n,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),AX(M$(t))),n)}let{year:n,month:r,day:i,calendar:a,z:o}=_X(KY(e));if(o)throw RangeError(`Z designator not supported for PlainDate`);return a||=`iso8601`,a=F$(a),AX(M$(t)),lZ({year:n,month:r,day:i},a)}function QX(e,t,n){return kX(kZ(e,t,n),EX(t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond,n))}function $X(e,t){let n,r,i;if(zY(e)){if(uX(e))return AX(M$(t)),dZ(Q(e,vJ),Q(e,Z));if(pX(e)){let n=IZ(Q(e,CJ),Q(e,gJ));return AX(M$(t)),dZ(n,Q(e,Z))}if(cX(e))return AX(M$(t)),dZ(kX(Q(e,_J),{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Q(e,Z));i=DZ(e);let a=YX(i,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],[]),o=AX(M$(t));({isoDate:n,time:r}=QX(i,a,o))}else{let a,o,s,c;if({year:o,month:s,day:c,time:r,calendar:i,z:a}=_X(KY(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}),jQ(o,s,c,r.hour,r.minute,r.second,r.millisecond,r.microsecond,r.nanosecond),i||=`iso8601`,i=F$(i),AX(M$(t)),n={year:o,month:s,day:c}}return dZ(kX(n,r),i)}function eZ(e){let t=nY(`%Temporal.Duration%`);if(sX(e))return new t(Q(e,wJ),Q(e,TJ),Q(e,EJ),Q(e,DJ),Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ));if(!zY(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=wY.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:HY(t[2])*n,i=t[3]===void 0?0:HY(t[3])*n,a=t[4]===void 0?0:HY(t[4])*n,o=t[5]===void 0?0:HY(t[5])*n,s=t[6]===void 0?0:HY(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*HY((c+`000000000`).slice(0,9))*n}else if(p=l===void 0?0:HY(l)*n,u!==void 0){if(d??f)throw RangeError(`only the smallest unit can be fractional`);h=60*HY((u+`000000000`).slice(0,9))*n}else m=d===void 0?0:HY(d)*n,f!==void 0&&(h=HY((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),IQ(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(nY(`%Temporal.Duration%`))(t,n,r,i,a,o,s,c,l,u)}(KY(e));let n={years:0,months:0,weeks:0,days:0,hours:0,minutes:0,seconds:0,milliseconds:0,microseconds:0,nanoseconds:0},r=DX(e);for(let e=0;e<nX.length;e++){let t=nX[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 tZ(e){let t;if(zY(e)){if(oX(e)||pX(e))return yZ(Q(e,gJ));t=qY(e)}else t=e;let{year:n,month:r,day:i,time:a,offset:o,z:s}=function(e){let t=_X(e);if(!t.z&&!t.offset)throw RangeError(`Temporal.Instant requires a time zone offset`);return t}(KY(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=xQ(n,r,i,c,l,u,d,f,p-(s?0:eQ(o)));return UQ(m.isoDate),yZ(lQ(m))}function nZ(e,t){if(zY(e)){if(fX(e))return AX(M$(t)),pZ(Q(e,_J),Q(e,Z));let n;return ZJ(e,Z)?n=Q(e,Z):(n=e.calendar,n===void 0&&(n=`iso8601`),n=EZ(n)),pZ(jZ(n,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),AX(M$(t))),n)}let{month:n,day:r,referenceISOYear:i,calendar:a}=bX(KY(e));if(a===void 0&&(a=`iso8601`),a=F$(a),AX(M$(t)),a===`iso8601`)return pZ({year:1972,month:n,day:r},a);let o={year:i,month:n,day:r};return kQ(o),o=jZ(a,JX(a,o,`month-day`),`constrain`),pZ(o,a)}function rZ(e,t){let n;if(zY(e)){if(lX(e))return AX(M$(t)),hZ(Q(e,yJ));if(uX(e))return AX(M$(t)),hZ(Q(e,vJ).time);if(pX(e)){let n=IZ(Q(e,CJ),Q(e,gJ));return AX(M$(t)),hZ(n.time)}let{hour:r,minute:i,second:a,millisecond:o,microsecond:s,nanosecond:c}=XX(e);n=EX(r,i,a,o,s,c,AX(M$(t)))}else n=vX(KY(e)),AX(M$(t));return hZ(n)}function iZ(e){return e===void 0?{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}:Q(rZ(e),yJ)}function aZ(e,t){if(zY(e)){if(dX(e))return AX(M$(t)),_Z(Q(e,_J),Q(e,Z));let n=DZ(e);return _Z(AZ(n,YX(n,e,[`year`,`month`,`monthCode`],[],[]),AX(M$(t))),n)}let{year:n,month:r,referenceISODay:i,calendar:a}=yX(KY(e));a===void 0&&(a=`iso8601`),a=F$(a),AX(M$(t));let o={year:n,month:r,day:i};return FQ(o),o=AZ(a,JX(a,o,`year-month`),`constrain`),_Z(o,a)}function oZ(e,t,n,r,i,a,o,s){if(t===`start-of-day`)return BZ(i,e);let c=kX(e,t);if(n===`wall`||o===`ignore`)return LZ(i,c,a);if(n===`exact`||o===`use`){let n=xQ(e.year,e.month,e.day,t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond-r);UQ(n.isoDate);let i=lQ(n);return PQ(i),i}UQ(e);let l=lQ(c),u=zZ(i,c);for(let e=0;e<u.length;e++){let t=u[e],n=X.default.toNumber(X.default.subtract(l,t)),i=g$(n,6e10,`halfExpand`);if(n===r||s&&i===r)return t}if(o===`reject`){let e=FZ(r),t=YZ(c,`iso8601`,`auto`);throw RangeError(`Offset ${e} is invalid for ${t} in ${i}`)}return RZ(u,i,c,a)}function sZ(e,t){let n,r,i,a,o,s,c,l=!1,u=`option`;if(zY(e)){if(pX(e)){let n=M$(t);return jX(n),NX(n,`reject`),AX(n),xZ(Q(e,gJ),Q(e,CJ),Q(e,Z))}o=DZ(e);let l=YX(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=M$(t);s=jX(d),c=NX(d,`reject`);let f=AX(d);({isoDate:n,time:r}=QX(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=_X(e);if(!t.tzAnnotation)throw RangeError(`Temporal.ZonedDateTime requires a time zone ID in brackets`);return t}(KY(e))),i=MZ(d),f?u=`exact`:a||(u=`wall`),o||=`iso8601`,o=F$(o),l=!0;let g=M$(t);s=jX(g),c=NX(g,`reject`),AX(g),n={year:p,month:m,day:h}}let d=0;return u===`option`&&(d=eQ(a)),xZ(oZ(n,r,u,d,i,s,c,l),i,o)}function cZ(e,t,n){kQ(t),XJ(e),QJ(e,_J,t),QJ(e,Z,n),QJ(e,bJ,!0)}function lZ(e,t){let n=nY(`%Temporal.PlainDate%`),r=Object.create(n.prototype);return cZ(r,e,t),r}function uZ(e,t,n){MQ(t),XJ(e),QJ(e,vJ,t),QJ(e,Z,n)}function dZ(e,t){let n=nY(`%Temporal.PlainDateTime%`),r=Object.create(n.prototype);return uZ(r,e,t),r}function fZ(e,t,n){kQ(t),XJ(e),QJ(e,_J,t),QJ(e,Z,n),QJ(e,SJ,!0)}function pZ(e,t){let n=nY(`%Temporal.PlainMonthDay%`),r=Object.create(n.prototype);return fZ(r,e,t),r}function mZ(e,t){XJ(e),QJ(e,yJ,t)}function hZ(e){let t=nY(`%Temporal.PlainTime%`),n=Object.create(t.prototype);return mZ(n,e),n}function gZ(e,t,n){FQ(t),XJ(e),QJ(e,_J,t),QJ(e,Z,n),QJ(e,xJ,!0)}function _Z(e,t){let n=nY(`%Temporal.PlainYearMonth%`),r=Object.create(n.prototype);return gZ(r,e,t),r}function vZ(e,t){PQ(t),XJ(e),QJ(e,gJ,t)}function yZ(e){let t=nY(`%Temporal.Instant%`),n=Object.create(t.prototype);return vZ(n,e),n}function bZ(e,t,n,r){PQ(t),XJ(e),QJ(e,gJ,t),QJ(e,CJ,n),QJ(e,Z,r)}function xZ(e,t,n=`iso8601`){let r=nY(`%Temporal.ZonedDateTime%`),i=Object.create(r.prototype);return bZ(i,e,t,n),i}function SZ(e){return JY.filter((t=>e[t]!==void 0))}function CZ(e,t,n){let r=SZ(n),i=KX(e).fieldKeysToIgnore(r),a=Object.create(null),o=SZ(t);for(let e=0;e<JY.length;e++){let s,c=JY[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 wZ(e,t,n,r){let i=KX(e).dateAdd(t,n,r);return kQ(i),i}function TZ(e,t,n,r){return KX(e).dateUntil(t,n,r)}function EZ(e){if(zY(e)&&ZJ(e,Z))return Q(e,Z);let t=KY(e);try{return F$(t)}catch{}let n;try{({calendar:n}=_X(t))}catch{try{({calendar:n}=vX(t))}catch{try{({calendar:n}=yX(t))}catch{({calendar:n}=bX(t))}}}return n||=`iso8601`,F$(n)}function DZ(e){if(ZJ(e,Z))return Q(e,Z);let{calendar:t}=e;return t===void 0?`iso8601`:EZ(t)}function OZ(e,t){return F$(e)===F$(t)}function kZ(e,t,n){let r=KX(e);r.resolveFields(t,`date`);let i=r.dateToISO(t,n);return kQ(i),i}function AZ(e,t,n){let r=KX(e);r.resolveFields(t,`year-month`),t.day=1;let i=r.dateToISO(t,n);return FQ(i),i}function jZ(e,t,n){let r=KX(e);r.resolveFields(t,`month-day`);let i=r.monthDayToISOReferenceDate(t,n);return kQ(i),i}function MZ(e){if(zY(e)&&pX(e))return Q(e,CJ);let t=KY(e);if(t===`UTC`)return`UTC`;let{tzName:n,offsetMinutes:r}=function(e){let{tzAnnotation:t,offset:n,z:r}=function(e){if(xX.test(e))return{tzAnnotation:e,offset:void 0,z:!1};try{let{tzAnnotation:t,offset:n,z:r}=_X(e);if(r||t||n)return{tzAnnotation:t,offset:n,z:r}}catch{}CX(e)}(e);return t?wX(t):r?wX(`UTC`):n?wX(n):void 0}(t);if(r!==void 0)return oQ(r);let i=rQ(n);if(!i)throw RangeError(`Unrecognized time zone ${n}`);return i.identifier}function NZ(e,t){if(e===t)return!0;let n=wX(e).offsetMinutes,r=wX(t).offsetMinutes;if(n===void 0&&r===void 0){let n=rQ(t);if(!n)return!1;let r=rQ(e);return!!r&&r.primaryIdentifier===n.primaryIdentifier}return n===r}function PZ(e,t){let n=wX(e).offsetMinutes;return n===void 0?aQ(e,t):6e10*n}function FZ(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}${WZ(r,i,a,o,a===0&&o===0?`minute`:`auto`)}`}function IZ(e,t){let n=PZ(e,t),{isoDate:{year:r,month:i,day:a},time:{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d}}=uQ(t);return xQ(r,i,a,o,s,c,l,u,d+n)}function LZ(e,t,n){return RZ(zZ(e,t),e,t,n)}function RZ(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=lQ(n),o=X.default.subtract(a,cJ);PQ(o);let s=PZ(t,o),c=X.default.add(a,cJ);PQ(c);let l=PZ(t,c)-s;switch(r){case`earlier`:{let e=sY.fromComponents(0,0,0,0,0,-l),r=o$(n.time,e);return zZ(t,kX(bQ(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r))[0]}case`compatible`:case`later`:{let e=sY.fromComponents(0,0,0,0,0,l),r=o$(n.time,e),i=zZ(t,kX(bQ(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r));return i[i.length-1]}}}function zZ(e,t){if(e===`UTC`)return UQ(t.isoDate),[lQ(t)];let n=wX(e).offsetMinutes;if(n!==void 0){let e=xQ(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);UQ(e.isoDate);let r=lQ(e);return PQ(r),[r]}return UQ(t.isoDate),function(e,t){let n=lQ(t),r=X.default.subtract(n,cJ);X.default.lessThan(r,AY)&&(r=n);let i=X.default.add(n,cJ);X.default.greaterThan(i,kY)&&(i=n);let a=aQ(e,r),o=aQ(e,i);return(a===o?[a]:[a,o]).map((r=>{let i=X.default.subtract(n,X.default.BigInt(r));if(w$(t,function(e,t){let{epochMilliseconds:n,time:{millisecond:r,microsecond:i,nanosecond:a}}=uQ(t),{year:o,month:s,day:c,hour:l,minute:u,second:d}=pQ(e,n);return xQ(o,s,c,l,u,d,r,i,a)}(e,i))===0)return PQ(i),i})).filter((e=>e!==void 0))}(e,t)}function BZ(e,t){let n=kX(t,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),r=zZ(e,n);if(r.length)return r[0];let i=lQ(n),a=X.default.subtract(i,cJ);return PQ(a),dQ(e,a)}function VZ(e){let t;return t=e<0||e>9999?(e<0?`-`:`+`)+GY(Math.abs(e),6):GY(e,4),t}function HZ(e){return GY(e,2)}function UZ(e,t){let n;if(t===`auto`){if(e===0)return``;n=GY(e,9).replace(/0+$/,``)}else{if(t===0)return``;n=GY(e,9).slice(0,t)}return`.${n}`}function WZ(e,t,n,r,i){let a=`${HZ(e)}:${HZ(t)}`;return i===`minute`||(a+=`:${HZ(n)}`,a+=UZ(r,i)),a}function GZ(e,t,n){let r=t;r===void 0&&(r=`UTC`);let i=Q(e,gJ),a=YZ(IZ(r,i),`iso8601`,n,`never`),o=`Z`;return t!==void 0&&(o=sQ(PZ(r,i))),`${a}${o}`}function KZ(e,t){let n=Q(e,wJ),r=Q(e,TJ),i=Q(e,EJ),a=Q(e,DJ),o=Q(e,OJ),s=Q(e,kJ),c=gQ(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=sY.fromComponents(0,0,Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ));d.isZero()&&![`second`,`millisecond`,`microsecond`,`nanosecond`].includes(HX(e))&&t===`auto`||(u+=`${Math.abs(d.sec)}${UZ(Math.abs(d.subsec),t)}S`);let f=`${c<0?`-`:``}P${l}`;return u&&(f=`${f}T${u}`),f}function qZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,_J);return`${VZ(n)}-${HZ(r)}-${HZ(i)}${hX(Q(e,Z),t)}`}function JZ({hour:e,minute:t,second:n,millisecond:r,microsecond:i,nanosecond:a},o){return WZ(e,t,n,1e6*r+1e3*i+a,o)}function YZ(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`${VZ(i)}-${HZ(a)}-${HZ(o)}T${WZ(s,c,l,1e6*u+1e3*d+f,n)}${hX(t,r)}`}function XZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,_J),a=`${HZ(r)}-${HZ(i)}`,o=Q(e,Z);t!==`always`&&t!==`critical`&&o===`iso8601`||(a=`${VZ(n)}-${a}`);let s=hX(o,t);return s&&(a+=s),a}function ZZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,_J),a=`${VZ(n)}-${HZ(r)}`,o=Q(e,Z);t!==`always`&&t!==`critical`&&o===`iso8601`||(a+=`-${HZ(i)}`);let s=hX(o,t);return s&&(a+=s),a}function QZ(e,t,n=`auto`,r=`auto`,i=`auto`,a=void 0){let o=Q(e,gJ);if(a){let{unit:e,increment:t,roundingMode:n}=a;o=_$(o,t,e,n)}let s=Q(e,CJ),c=PZ(s,o),l=YZ(IZ(s,o),`iso8601`,t,`never`);return i!==`never`&&(l+=sQ(c)),r!==`never`&&(l+=`[${r===`critical`?`!`:``}${s}]`),l+=hX(Q(e,Z),n),l}function $Z(e){return SX.test(e)}function eQ(e){let t=z$.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 tQ,nQ=Object.assign(Object.create(null),{"/":!0,"-":!0,_:!0});function rQ(e){if(tQ===void 0){let e=Intl.supportedValuesOf?.(`timeZone`);if(e){tQ=new Map;for(let t=0;t<e.length;t++){let n=e[t];tQ.set(I$(n),n)}}else tQ=null}let t=I$(e),n=tQ?.get(t);if(n)return{identifier:n,primaryIdentifier:n};try{n=aX(e).resolvedOptions().timeZone}catch{return}if(t===`antarctica/south_pole`&&(n=`Antarctica/McMurdo`),RY.has(e))throw RangeError(`${e} is a legacy time zone identifier from ICU. Use ${n} instead`);let r=[...t].map(((e,n)=>n===0||nQ[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 iQ(e,t){let{year:n,month:r,day:i,hour:a,minute:o,second:s}=pQ(e,t),c=t%1e3;return c<0&&(c+=1e3),1e6*(cQ({isoDate:{year:n,month:r,day:i},time:{hour:a,minute:o,second:s,millisecond:c}})-t)}function aQ(e,t){return iQ(e,E$(t,`floor`))}function oQ(e){let t=e<0?`-`:`+`,n=Math.abs(e);return`${t}${WZ(Math.floor(n/60),n%60,0,0,`minute`)}`}function sQ(e){return oQ(g$(e,DY,`halfExpand`)/6e10)}function cQ({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()+NY*c}function lQ(e){let t=cQ(e),n=1e3*e.time.microsecond+e.time.nanosecond;return X.default.add(D$(t),X.default.BigInt(n))}function uQ(e){let t=E$(e,`trunc`),n=X.default.toNumber(X.default.remainder(e,iJ));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 dQ(e,t){if(e===`UTC`)return null;let n=E$(t,`floor`);if(n<IY)return dQ(e,D$(IY));let r=Math.max(n,Date.now())+366*TY*3,i=n,a=iQ(e,i),o=i,s=a;for(;a===s&&i<r;){if(o=i+2*TY*7,o>OY)return null;s=iQ(e,o),a===s&&(i=o)}return a===s?null:D$(B$((t=>iQ(e,t)),i,o,a,s))}function fQ(e,t){if(e===`UTC`)return null;let n=E$(t,`ceil`),r=Date.now(),i=r+366*TY*3;if(n>i){let t=fQ(e,D$(i));if(t===null||X.default.lessThan(t,D$(r)))return t}if(e===`Africa/Casablanca`||e===`Africa/El_Aaiun`){let t=Date.UTC(2088,0,1);if(t<n)return fQ(e,D$(t))}let a=n-1;if(a<IY)return null;let o=iQ(e,a),s=a,c=o;for(;o===c&&a>IY;){if(s=a-2*TY*7,s<IY)return null;c=iQ(e,s),o===c&&(a=s)}return o===c?null:D$(B$((t=>iQ(e,t)),s,a,c,o))}function pQ(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}}(aX(e).format(t))}function mQ(e){return e!==void 0&&!(e%4!=0||e%100==0&&e%400!=0)}function hQ(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]}[mQ(e)?`leapyear`:`standard`][t-1]}function gQ(e){let t=[Q(e,wJ),Q(e,TJ),Q(e,EJ),Q(e,DJ),Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ)];for(let e=0;e<t.length;e++){let n=t[e];if(n!==0)return n<0?-1:1}return 0}function _Q(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 vQ(e){let t=_Q(e.date);return t===0?e.time.sign():t}function yQ(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 bQ(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}=yQ(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=mQ(c)?366:365,a<-s;)--r,--c,a+=s;for(c+=1;s=mQ(c)?366:365,a>s;)r+=1,c+=1,a-=s;for(;a<1;)({year:r,month:i}=yQ(r,i-1)),a+=hQ(r,i);for(;a>hQ(r,i);)a-=hQ(r,i),{year:r,month:i}=yQ(r,i+1);return{year:r,month:i,day:a}}function xQ(e,t,n,r,i,a,o,s,c){let l=SQ(r,i,a,o,s,c);return kX(bQ(e,t,n+l.deltaDays),l)}function SQ(e,t,n,r,i,a){let o,s=e,c=t,l=n,u=r,d=i,f=a;({div:o,mod:f}=rY(f,3)),d+=o,f<0&&(--d,f+=1e3),{div:o,mod:d}=rY(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 CQ(e,t){let n=OX(e,0);if(_Q(n)===0)return e.days;let r=Q(t,_J),i=wZ(Q(t,Z),r,n,`constrain`),a=HQ(r.year,r.month-1,r.day),o=HQ(i.year,i.month-1,i.day)-a;return e.days+o}function wQ(e){return new(nY(`%Temporal.Duration%`))(-Q(e,wJ),-Q(e,TJ),-Q(e,EJ),-Q(e,DJ),-Q(e,OJ),-Q(e,kJ),-Q(e,AJ),-Q(e,jJ),-Q(e,MJ),-Q(e,NJ))}function TQ(e,t,n){return Math.min(n,Math.max(t,e))}function EQ(e,t,n){let r=TQ(t,1,12);return{year:e,month:r,day:TQ(n,1,hQ(e,r))}}function DQ(e,t,n){if(e<t||e>n)throw RangeError(`value out of range: ${t} <= ${e} <= ${n}`)}function OQ(e,t,n){DQ(t,1,12),DQ(n,1,hQ(e,t))}function kQ(e){MQ(kX(e,{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}))}function AQ(e,t,n,r,i,a){DQ(e,0,23),DQ(t,0,59),DQ(n,0,59),DQ(r,0,999),DQ(i,0,999),DQ(a,0,999)}function jQ(e,t,n,r,i,a,o,s,c){OQ(e,t,n),AQ(r,i,a,o,s,c)}function MQ(e){let t=lQ(e);(X.default.lessThan(t,jY)||X.default.greaterThan(t,MY))&&PQ(t)}function NQ(e){lQ(e)}function PQ(e){if(X.default.lessThan(e,AY)||X.default.greaterThan(e,kY))throw RangeError(`date/time value is outside of supported range`)}function FQ({year:e,month:t}){DQ(e,PY,FY),e===PY?DQ(t,4,12):e===FY&&DQ(t,1,9)}function IQ(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=rY(s,3),p=rY(c,6),m=rY(l,9),h=rY(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 LQ(e){return{date:{years:Q(e,wJ),months:Q(e,TJ),weeks:Q(e,EJ),days:Q(e,DJ)},time:sY.fromComponents(Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ))}}function RQ(e){let t=sY.fromComponents(Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ)).add24HourDays(Q(e,DJ));return{date:{years:Q(e,wJ),months:Q(e,TJ),weeks:Q(e,EJ),days:0},time:t}}function zQ(e){let t=RQ(e),n=Math.trunc(t.time.sec/86400);return IQ(t.date.years,t.date.months,t.date.weeks,n,0,0,0,0,0,0),{...t.date,days:n}}function BQ(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=iY(o,3,Math.trunc(i/1e3)),i%=1e3,o=0;break;case`microsecond`:i=iY(o,6,Math.trunc(r/1e3)),r%=1e3,o=0;break;case`nanosecond`:r=iY(o,9,r),o=0}return new(nY(`%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 VQ(e,t){return _Q(e),t.sign(),{date:e,time:t}}function HQ(e,t,n){return cQ({isoDate:{year:e,month:t+1,day:n},time:{hour:0,minute:0,second:0,millisecond:0}})/TY}function UQ({year:e,month:t,day:n}){if(Math.abs(HQ(e,t-1,n))>1e8)throw RangeError(`date/time value is outside the supported range`)}function WQ(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 sY.fromComponents(n,r,i,a,o,s)}function GQ(e,t,n,r,i){let a=sY.fromEpochNsDiff(t,e);return a=b$(a,n,r,i),VQ({years:0,months:0,weeks:0,days:0},a)}function KQ(e,t,n,r){NQ(e),NQ(t);let i=WQ(e.time,t.time),a=i.sign(),o=S$(e.isoDate,t.isoDate),s=t.isoDate;o===a&&(s=bQ(s.year,s.month,s.day+a),i=i.add24HourDays(-a));let c=UX(`day`,r),l=TZ(n,e.isoDate,s,c);return r!==c&&(i=i.add24HourDays(l.days),l.days=0),VQ(l,i)}function qQ(e,t,n,r,i){let a=X.default.subtract(t,e);if(X.default.equal(a,Zq))return{date:{years:0,months:0,weeks:0,days:0},time:sY.ZERO};let o=X.default.lessThan(a,Zq)?-1:1,s=IZ(n,e),c=IZ(n,t),l,u=0,d=o===1?2:1,f=WQ(s.time,c.time);for(f.sign()===-o&&u++;u<=d;u++){l=kX(bQ(c.isoDate.year,c.isoDate.month,c.isoDate.day-u*o),s.time);let e=LZ(n,l,`compatible`);if(f=sY.fromEpochNsDiff(t,e),f.sign()!==-o)break}let p=UX(`day`,i);return VQ(TZ(r,s.isoDate,l.isoDate,p),f)}function JQ(e,t,n,r,i,a,o,s,c){let l,u,d,f,p=t;switch(s){case`year`:{let t=g$(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=g$(p.date.months,o,`trunc`);l=t,u=t+o*e,d=OX(p.date,0,0,l),f=OX(p.date,0,0,u);break}case`week`:{let t=OX(p.date,0,0),n=wZ(a,r.isoDate,t,`constrain`),i=TZ(a,n,bQ(n.year,n.month,n.day+p.date.days),`week`),s=g$(p.date.weeks+i.weeks,o,`trunc`);l=s,u=s+o*e,d=OX(p.date,0,l),f=OX(p.date,0,u);break}case`day`:{let t=g$(p.date.days,o,`trunc`);l=t,u=t+o*e,d=OX(p.date,l),f=OX(p.date,u);break}}let m=wZ(a,r.isoDate,d,`constrain`),h=wZ(a,r.isoDate,f,`constrain`),g,_,v=kX(m,r.time),y=kX(h,r.time);i?(g=LZ(i,v,`compatible`),_=LZ(i,y,`compatible`)):(g=lQ(v),_=lQ(y));let b=sY.fromEpochNsDiff(n,g),x=sY.fromEpochNsDiff(_,g),S=aY(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)?oY(Math.abs(l),Math.abs(u),C,w,S):Math.abs(u),E=new sY(X.default.add(X.default.multiply(x.totalNs,X.default.BigInt(l)),X.default.multiply(b.totalNs,X.default.BigInt(o*e)))).fdiv(x.totalNs),D=T===Math.abs(u);return p={date:D?f:d,time:sY.ZERO},{nudgeResult:{duration:p,nudgedEpochNs:D?_:g,didExpandCalendarUnit:D},total:E}}function YQ(e,t,n,r,i,a,o,s,c){let l=e,u=WX(s)||r&&s===`day`,d=vQ(l)<0?-1:1,f;return u?{nudgeResult:f}=JQ(d,l,t,n,r,i,o,s,c):f=r?function(e,t,n,r,i,a,o,s){let c=t,l=wZ(i,n.isoDate,c.date,`constrain`),u=kX(l,n.time),d=kX(bQ(l.year,l.month,l.day+e),n.time),f=LZ(r,u,`compatible`),p=LZ(r,d,`compatible`),m=sY.fromEpochNsDiff(p,f);if(m.sign()!==e)throw RangeError(`time zone returned inconsistent Instants`);let h=X.default.BigInt(tX[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:VQ(OX(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(X.default.BigInt(r*tX[i]),a),l=c.subtract(s),{quotient:u}=s.divmod(EY),{quotient:d}=c.divmod(EY),f=Math.sign(d-u)===s.sign(),p=l.addToEpochNs(t),m=0,h=c;return GX(n)===`date`&&(m=d,h=c.add(sY.fromComponents(24*-d,0,0,0,0,0))),{duration:{date:OX(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=eX.indexOf(o);for(let t=eX.indexOf(s)-1;t>=l;t--){let s=eX[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=OX(c.date,0,0,t);break}case`week`:{let t=c.date.weeks+e;l=OX(c.date,0,t);break}}let u=kX(wZ(a,r.isoDate,l,`constrain`),r.time),d;if(d=i?LZ(i,u,`compatible`):lQ(u),fJ(n,d)===-e)break;c={date:l,time:sY.ZERO}}return c}(d,l,f.nudgedEpochNs,n,r,i,a,UX(s,`day`))),l}function XQ(e,t,n,r,i,a){return WX(a)||r&&a===`day`?JQ(vQ(e)<0?-1:1,e,t,n,r,i,1,a,`trunc`).total:x$(e.time.add24HourDays(e.date.days),a)}function ZQ(e,t,n,r,i,a,o){if(w$(e,t)==0)return{date:{years:0,months:0,weeks:0,days:0},time:sY.ZERO};MQ(e),MQ(t);let s=KQ(e,t,n,r);return a===`nanosecond`&&i===1?s:YQ(s,lQ(t),e,null,n,r,i,a,o)}function QQ(e,t,n,r,i,a,o,s){if(GX(i)===`time`)return GQ(e,t,a,o,s);let c=qQ(e,t,n,r,i);return o===`nanosecond`&&a===1?c:YQ(c,t,IZ(n,e),n,r,i,a,o,s)}function $Q(e,t,n,r,i,a){let o=ZY.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=BX(t,`largestUnit`,n,`auto`);if(r.includes(s))throw RangeError(`largestUnit must be one of ${o.join(`, `)}, not ${s}`);let c=FX(t),l=MX(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=BX(t,`smallestUnit`,n,i);if(r.includes(u))throw RangeError(`smallestUnit must be one of ${o.join(`, `)}, not ${u}`);let d=UX(a,u);if(s===`auto`&&(s=d),UX(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&&IX(c,f,!1),{largestUnit:s,roundingIncrement:c,roundingMode:l,smallestUnit:u}}function e$(e,t,n,r){let i=tZ(n),a=$Q(e,M$(r),`time`,[],`nanosecond`,`second`),o=BQ(GQ(Q(t,gJ),Q(i,gJ),a.roundingIncrement,a.smallestUnit,a.roundingMode),a.largestUnit);return e===`since`&&(o=wQ(o)),o}function t$(e,t,n,r){let i=ZX(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`date`,[],`day`,`day`),c=nY(`%Temporal.Duration%`),l=Q(t,_J),u=Q(i,_J);if(S$(l,u)===0)return new c;let d={date:TZ(a,l,u,s.largestUnit),time:sY.ZERO};if(s.smallestUnit!==`day`||s.roundingIncrement!==1){let e=kX(l,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});d=YQ(d,lQ(kX(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=BQ(d,`day`);return e===`since`&&(f=wQ(f)),f}function n$(e,t,n,r){let i=$X(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`datetime`,[],`nanosecond`,`day`),c=nY(`%Temporal.Duration%`),l=Q(t,vJ),u=Q(i,vJ);if(w$(l,u)===0)return new c;let d=BQ(ZQ(l,u,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);return e===`since`&&(d=wQ(d)),d}function r$(e,t,n,r){let i=rZ(n),a=$Q(e,M$(r),`time`,[],`nanosecond`,`hour`),o=WQ(Q(t,yJ),Q(i,yJ));o=b$(o,a.roundingIncrement,a.smallestUnit,a.roundingMode);let s=BQ(VQ({years:0,months:0,weeks:0,days:0},o),a.largestUnit);return e===`since`&&(s=wQ(s)),s}function i$(e,t,n,r){let i=aZ(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between months of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`date`,[`week`,`day`],`month`,`year`),c=nY(`%Temporal.Duration%`);if(S$(Q(t,_J),Q(i,_J))==0)return new c;let l=JX(a,Q(t,_J),`year-month`);l.day=1;let u=kZ(a,l,`constrain`),d=JX(a,Q(i,_J),`year-month`);d.day=1;let f=kZ(a,d,`constrain`),p={date:OX(TZ(a,u,f,s.largestUnit),0,0),time:sY.ZERO};if(s.smallestUnit!==`month`||s.roundingIncrement!==1){let e=kX(u,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});p=YQ(p,lQ(kX(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=BQ(p,`day`);return e===`since`&&(m=wQ(m)),m}function a$(e,t,n,r){let i=sZ(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`datetime`,[],`nanosecond`,`hour`),c=Q(t,gJ),l=Q(i,gJ),u=nY(`%Temporal.Duration%`),d;if(GX(s.largestUnit)!==`date`)d=BQ(GQ(c,l,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);else{let e=Q(t,CJ);if(!NZ(e,Q(i,CJ)))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(X.default.equal(c,l))return new u;d=BQ(QQ(c,l,e,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),`hour`)}return e===`since`&&(d=wQ(d)),d}function o$({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,SQ(e,t,s,r,i,c)}function s$(e,t){let n=t.addToEpochNs(e);return PQ(n),n}function c$(e,t,n,r,i=`constrain`){if(_Q(r.date)===0)return s$(e,r.time);let a=IZ(t,e);return s$(LZ(t,kX(wZ(n,a.isoDate,r.date,i),a.time),`compatible`),r.time)}function l$(e,t,n){let r=eZ(n);e===`subtract`&&(r=wQ(r));let i=UX(HX(t),HX(r));if(WX(i))throw RangeError(`For years, months, or weeks arithmetic, use date arithmetic relative to a starting point`);let a=RQ(t),o=RQ(r);return BQ(VQ({years:0,months:0,weeks:0,days:0},a.time.add(o.time)),i)}function u$(e,t,n){let r=eZ(n);e===`subtract`&&(r=wQ(r));let i=HX(r);if(GX(i)===`date`)throw RangeError(`Duration field ${i} not supported by Temporal.Instant. Try Temporal.ZonedDateTime instead.`);let a=RQ(r);return yZ(s$(Q(t,gJ),a.time))}function d$(e,t,n,r){let i=Q(t,Z),a=eZ(n);e===`subtract`&&(a=wQ(a));let o=zQ(a),s=AX(M$(r));return lZ(wZ(i,Q(t,_J),o,s),i)}function f$(e,t,n,r){let i=eZ(n);e===`subtract`&&(i=wQ(i));let a=AX(M$(r)),o=Q(t,Z),s=RQ(i),c=Q(t,vJ),l=o$(c.time,s.time),u=OX(s.date,l.deltaDays);return IQ(u.years,u.months,u.weeks,u.days,0,0,0,0,0,0),dZ(kX(wZ(o,c.isoDate,u,a),l),o)}function p$(e,t,n){let r=eZ(n);e===`subtract`&&(r=wQ(r));let i=RQ(r),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=o$(Q(t,yJ),i.time);return hZ(EX(a,o,s,c,l,u,`reject`))}function m$(e,t,n,r){let i=eZ(n);e===`subtract`&&(i=wQ(i));let a=AX(M$(r)),o=gQ(i),s=Q(t,Z),c=JX(s,Q(t,_J),`year-month`);c.day=1;let l=kZ(s,c,`constrain`);if(o<0){let e=wZ(s,l,{months:1},`constrain`);l=bQ(e.year,e.month,e.day-1)}let u=zQ(i);return kQ(l),_Z(AZ(s,JX(s,wZ(s,l,u,a),`year-month`),a),s)}function h$(e,t,n,r){let i=eZ(n);e===`subtract`&&(i=wQ(i));let a=AX(M$(r)),o=Q(t,CJ),s=Q(t,Z),c=LQ(i);return xZ(c$(Q(t,gJ),o,s,c,a),o,s)}function g$(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=j$(Math.abs(2*i)-t),l=o%2==0,u=aY(n,a),d=i===0?o:oY(o,s,c,l,u);return t*(a===`positive`?d:-d)}function _$(e,t,n,r){let i=tX[n]*t;return function(e,t,n){let r=lJ(e),i=lJ(t),a=X.default.divide(r,i),o=X.default.remainder(r,i),s=aY(n,`positive`),c,l;X.default.lessThan(r,Zq)?(c=X.default.subtract(a,Qq),l=a):(c=a,l=X.default.add(a,Qq));let u=fJ(dJ(X.default.multiply(o,$q)),i)*(X.default.lessThan(r,Zq)?-1:1)+0,d=X.default.equal(o,Zq)?a:oY(c,l,u,uJ(c),s);return X.default.multiply(d,i)}(e,X.default.BigInt(i),r)}function v$(e,t,n,r){NQ(e);let{year:i,month:a,day:o}=e.isoDate,s=y$(e.time,t,n,r);return kX(bQ(i,a,o+s.deltaDays),s)}function y$({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=tX[s],d=g$(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 SQ(d,0,0,0,0,0);case`minute`:return SQ(e,d,0,0,0,0);case`second`:return SQ(e,t,d,0,0,0);case`millisecond`:return SQ(e,t,n,d,0,0);case`microsecond`:return SQ(e,t,n,r,d,0);case`nanosecond`:return SQ(e,t,n,r,i,d);default:throw Error(`Invalid unit ${s}`)}}function b$(e,t,n,r){let i=tX[n];return e.round(X.default.BigInt(i*t),r)}function x$(e,t){let n=tX[t];return e.fdiv(X.default.BigInt(n))}function S$(e,t){return e.year===t.year?e.month===t.month?e.day===t.day?0:j$(e.day-t.day):j$(e.month-t.month):j$(e.year-t.year)}function C$(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:j$(e.nanosecond-t.nanosecond):j$(e.microsecond-t.microsecond):j$(e.millisecond-t.millisecond):j$(e.second-t.second):j$(e.minute-t.minute):j$(e.hour-t.hour)}function w$(e,t){let n=S$(e.isoDate,t.isoDate);return n===0?C$(e.time,t.time):n}function T$(e){let t=O$(e);return globalThis.BigInt===void 0?t:globalThis.BigInt(t.toString(10))}function E$(e,t){let{quotient:n,remainder:r}=pJ(lJ(e),iJ),i=X.default.toNumber(n);return t===`floor`&&X.default.toNumber(r)<0&&--i,t===`ceil`&&X.default.toNumber(r)>0&&(i+=1),i}function D$(e){if(!Number.isInteger(e))throw RangeError(`epoch milliseconds must be an integer`);return X.default.multiply(X.default.BigInt(e),iJ)}function O$(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`?X.default.BigInt(t.toString(10)):X.default.BigInt(t)}var k$=(()=>{let e=X.default.BigInt(Date.now()%1e6);return()=>{let t=Date.now(),n=X.default.BigInt(t),r=X.default.add(D$(t),e);return e=X.default.remainder(n,iJ),X.default.greaterThan(r,kY)?kY:X.default.lessThan(r,AY)?AY:r}})();function A$(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}function j$(e){return e<0?-1:e>0?1:e}function M$(e){if(e===void 0)return Object.create(null);if(zY(e)&&e!==null)return e;throw TypeError(`Options parameter must be an object, not `+(e===null?`null`:typeof e))}function N$(e,t){let n=Object.create(null);return n[e]=t,n}function P$(e,t,n,r){let i=e[t];if(i!==void 0){if(i=VY(i),!n.includes(i))throw RangeError(`${t} must be one of ${n.join(`, `)}, not ${i}`);return i}if(r===zX)throw RangeError(`${t} option is required`);return r}function F$(e){let t=I$(e);if(!LY.includes(I$(t)))throw RangeError(`invalid calendar identifier ${t}`);switch(t){case`ethiopic-amete-alem`:return`ethioaa`;case`islamicc`:return`islamic-civil`}return t}function I$(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 L$(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 R$=RegExp(`^${hY.source}$`),z$=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])(?::?([0-5][0-9])(?:[.,](\\d{1,9}))?)?)?$`);function B$(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 V$(e){return[...e]}function H$(e,t){if(e!==`gregory`&&e!==`iso8601`)return;let n=W$[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 U$(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 W$={};function G$(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 K$(e,t=!1){return`M${`${e}`.padStart(2,`0`)}${t?`L`:``}`}function q$(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`&&DQ(r,1,n),t===`constrain`&&(r=TQ(r,1,n)),i=K$(r)}else{let e=G$(i);if(i!==K$(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}}W$.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,q$(e))},dateToISO:(e,t)=>TX(e.year,e.month,e.day,t),monthDayToISOReferenceDate(e,t){let{month:n,day:r}=TX(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 V$(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}=yQ(o,s),{year:o,month:s,day:c}=TX(o,s,c,a),c+=i+7*r,bQ(o,s,c)},dateUntil(e,t,n){let r=-S$(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);!U$(r,e.year+s,e.month,e.day,t);)a=s,s+=r;let c=r;for(i=yQ(e.year+a,e.month+c);!U$(r,i.year,i.month,e.day,t);)o=c,c+=r,i=yQ(i.year,i.month+r);n===`month`&&(o+=12*a,a=0)}i=yQ(e.year+a,e.month+o);let s=EQ(i.year,i.month,e.day),c=0,l=HQ(t.year,t.month-1,t.day)-HQ(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=K$(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+=hQ(e,n);i.dayOfYear=r}return r.weekOfYear&&(i.weekOfYear=H$(`iso8601`,{year:e,month:t,day:n})),r.daysInMonth&&(i.daysInMonth=hQ(e,t)),(r.daysInYear||r.inLeapYear)&&(i.inLeapYear=mQ(e),i.daysInYear=i.inLeapYear?366:365),i},getFirstDayOfWeek:()=>1,getMinimalDaysInFirstWeek:()=>4};var J$=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 Y$({isoYear:e,isoMonth:t,isoDay:n}){return`${VZ(e)}-${HZ(t)}-${HZ(n)}T00:00Z`}function X$(e,t){return{years:e.year-t.year,months:e.month-t.month,days:e.day-t.day}}J$.objectMap=new WeakMap,J$.MAX_CACHE_ENTRIES=1e3;var Z$=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=Y$({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}=q$(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`?(DQ(i,1,r),DQ(a,1,this.maximumMonthLength(e))):(i=TQ(i,1,r),a=TQ(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=X$(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=X$(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=X$(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:j$(e.day-t.day):j$(e.month-t.month):j$(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 bQ(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 HQ(i.year,i.month-1,i.day)-HQ(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(){}},fue=class extends Z${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?K$(5,!0):K$(t<6?t:t-1):K$(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=G$(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`?(DQ(a,1,this.monthsInYear({year:i})),DQ(s,1,this.maximumMonthLength({year:i,month:a}))):(a=TQ(a,1,this.monthsInYear({year:i})),s=TQ(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}}},Q$=class extends Z${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}}},pue=class extends Q${constructor(){super(...arguments),this.id=`islamic`}},mue=class extends Q${constructor(){super(...arguments),this.id=`islamic-umalqura`}},hue=class extends Q${constructor(){super(...arguments),this.id=`islamic-tbla`}},gue=class extends Q${constructor(){super(...arguments),this.id=`islamic-civil`}},_ue=class extends Q${constructor(){super(...arguments),this.id=`islamic-rgsa`}},vue=class extends Q${constructor(){super(...arguments),this.id=`islamicc`}},yue=class extends Z${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 G$(e)<=6?31:30}estimateIsoDate(e){let{year:t}=this.adjustCalendarDate(e);return{year:t+621,month:1,day:1}}},bue=class extends Z${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 $$(e.year+78)}monthsInYear(){return 12}minimumMonthLength(e){return this.getMonthInfo(e).length}maximumMonthLength(e){return this.getMonthInfo(e).length}maxLengthOfMonthCodeInAnyYear(e){let t=G$(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 bQ(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 $$(e){return e%4==0&&(e%100!=0||e%400==0)}var e1=class extends Z${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 $$(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][G$(e)-1]}estimateIsoDate(e){let t=this.adjustCalendarDate(e);return TX(t.year+this.isoEpoch.year,t.month+this.isoEpoch.month,t.day+this.isoEpoch.day,`constrain`)}},t1=class extends Z${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 $$(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][G$(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:G$(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 TX(t+i.isoEpoch.year-+!i.hasYearZero,n,r,`constrain`)}},n1=class extends t1{constructor(e,t){super(e,t)}isoToCalendarDate(e){let{year:t,month:n,day:r}=e,i=K$(n),a=t-this.anchorEra.isoEpoch.year+1;return this.completeEraYear({year:a,month:n,monthCode:i,day:r})}},r1={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},xue=class extends e1{constructor(e,t){super(e,t),this.inLeapYear=r1.inLeapYear,this.monthsInYear=r1.monthsInYear,this.minimumMonthLength=r1.minimumMonthLength,this.maximumMonthLength=r1.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=r1.maxLengthOfMonthCodeInAnyYear}},i1=class extends t1{constructor(e,t){super(e,t),this.inLeapYear=r1.inLeapYear,this.monthsInYear=r1.monthsInYear,this.minimumMonthLength=r1.minimumMonthLength,this.maximumMonthLength=r1.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=r1.maxLengthOfMonthCodeInAnyYear}},Sue=class extends xue{constructor(){super(`ethioaa`,{year:-5492,month:7,day:17})}},Cue=class extends i1{constructor(){super(`coptic`,[{code:`coptic`,isoEpoch:{year:284,month:8,day:29}},{code:`coptic-inverse`,reverseOf:`coptic`}])}},wue=class extends i1{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}}])}},Tue=class extends n1{constructor(){super(`roc`,[{code:`roc`,names:[`minguo`],isoEpoch:{year:1912,month:1,day:1}},{code:`roc-inverse`,names:[`before-roc`],reverseOf:`roc`}])}},Eue=class extends e1{constructor(){super(`buddhist`,{year:-543,month:1,day:1})}},Due=class extends n1{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}},Oue=class extends n1{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}}},a1=class extends Z${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=Y$({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=K$(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=K$(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`?(DQ(a,1,o),DQ(s,1,this.maximumMonthLength())):(a=TQ(a,1,o),s=TQ(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=K$(+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}}},kue=class extends a1{constructor(){super(...arguments),this.id=`chinese`}},Aue=class extends a1{constructor(){super(...arguments),this.id=`dangi`}},jue=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 J$;q$(e,void 0,this.helper.monthsInYear({year:e.year??1972},t))}}dateToISO(e,t){let n=new J$,r=this.helper.calendarToIsoDate(e,t,n);return n.setObject(r),r}monthDayToISOReferenceDate(e,t){let n=new J$,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 V$(t)}dateAdd(e,{years:t,months:n,weeks:r,days:i},a){let o=J$.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 J$.getCacheForObject(l)||new J$(o).setObject(l),l}dateUntil(e,t,n){let r=J$.getCacheForObject(e),i=J$.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=J$.getCacheForObject(e),r=this.helper.isoToCalendarDate(e,n);if(t.dayOfWeek&&(r.dayOfWeek=W$.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=H$(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[fue,yue,wue,Sue,Cue,kue,Aue,Tue,bue,Eue,Due,Oue,pue,mue,hue,gue,_ue,vue]){let t=new e;W$[t.id]=new jue(t)}tY(`calendarImpl`,(function(e){return W$[e]}));var o1=Intl.DateTimeFormat;function s1(e,t){let n=Q(e,t);return typeof n==`function`&&(n=new o1(Q(e,WJ),n(Q(e,GJ))),function(e,t,n){let r=JJ(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 c1(e){return ZJ(e,BJ)}var l1=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 o1(t,i),o=a.resolvedOptions();if(XJ(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,QJ(e,GJ,t)}else QJ(e,GJ,i);QJ(e,WJ,o.locale),QJ(e,BJ,a),QJ(e,VJ,o.timeZone),QJ(e,UJ,o.calendar),QJ(e,PJ,Bue),QJ(e,FJ,Rue),QJ(e,IJ,zue),QJ(e,LJ,Lue),QJ(e,RJ,Vue),QJ(e,zJ,Hue);let s=r?i.timeZone:void 0;if(s===void 0)QJ(e,HJ,o.timeZone);else{let t=VY(s);if(t.startsWith(`−`))throw RangeError(`Unicode minus (U+2212) is not supported in time zone offsets`);QJ(e,HJ,MZ(t))}})(this,e,t)}get format(){$(this,c1);let e=Nue.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,c1),Fue.call(this,e,t)}formatToParts(e,...t){return $(this,c1),Pue.call(this,e,...t)}formatRangeToParts(e,t){return $(this,c1),Iue.call(this,e,t)}resolvedOptions(){return $(this,c1),Mue.call(this)}};`formatToParts`in o1.prototype||delete l1.prototype.formatToParts,`formatRangeToParts`in o1.prototype||delete l1.prototype.formatRangeToParts;var u1=function(e=void 0,t=void 0){return new l1(e,t)};function Mue(){let e=Q(this,BJ).resolvedOptions();return e.timeZone=Q(this,HJ),e}function Nue(e,...t){let n,r,i=v1(e,this);return i.formatter?(n=i.formatter,r=[E$(i.epochNs,`floor`)]):(n=Q(this,BJ),r=[e,...t]),n.format(...r)}function Pue(e,...t){let n,r,i=v1(e,this);return i.formatter?(n=i.formatter,r=[E$(i.epochNs,`floor`)]):(n=Q(this,BJ),r=[e,...t]),n.formatToParts(...r)}function Fue(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=g1(e),r=g1(t),i,a=[n,r];if(h1(n)!==h1(r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);if(h1(n)){if(!_1(n,r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);let{epochNs:e,formatter:t}=v1(n,this),{epochNs:o,formatter:s}=v1(r,this);t&&(i=t,a=[E$(e,`floor`),E$(o,`floor`)])}return i||=Q(this,BJ),i.formatRange(...a)}function Iue(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=g1(e),r=g1(t),i,a=[n,r];if(h1(n)!==h1(r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);if(h1(n)){if(!_1(n,r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);let{epochNs:e,formatter:t}=v1(n,this),{epochNs:o,formatter:s}=v1(r,this);t&&(i=t,a=[E$(e,`floor`),E$(o,`floor`)])}return i||=Q(this,BJ),i.formatRangeToParts(...a)}function d1(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 Lue(e){let t=d1(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`})),!p1(t)){if(m1(e))throw TypeError(`cannot format Temporal.PlainTime with options [${Object.keys(e)}]`);Object.assign(t,{hour:`numeric`,minute:`numeric`,second:`numeric`})}return t}function Rue(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=d1(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(m1(e))throw TypeError(`cannot format PlainYearMonth with options [${Object.keys(e)}]`);Object.assign(n,{year:`numeric`,month:`numeric`})}return n}function zue(e){let t={short:{month:`numeric`,day:`numeric`},medium:{month:`short`,day:`numeric`},long:{month:`long`,day:`numeric`},full:{month:`long`,day:`numeric`}},n=d1(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(m1(e))throw TypeError(`cannot format PlainMonthDay with options [${Object.keys(e)}]`);Object.assign(n,{month:`numeric`,day:`numeric`})}return n}function Bue(e){let t=d1(e,{hour:!1,minute:!1,second:!1,dayPeriod:!1,timeZoneName:!1,timeStyle:!1});if(!f1(t)){if(m1(e))throw TypeError(`cannot format PlainDate with options [${Object.keys(e)}]`);Object.assign(t,{year:`numeric`,month:`numeric`,day:`numeric`})}return t}function Vue(e){let t=d1(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),!p1(t)&&!f1(t)){if(m1(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 Hue(e){let t=e;return p1(t)||f1(t)||(t=Object.assign({},t,{year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})),t}function f1(e){return`year`in e||`month`in e||`day`in e||`weekday`in e||`dateStyle`in e||`era`in e}function p1(e){return`hour`in e||`minute`in e||`second`in e||`timeStyle`in e||`dayPeriod`in e||`fractionalSecondDigits`in e}function m1(e){return f1(e)||p1(e)||`dateStyle`in e||`timeStyle`in e||`timeZoneName`in e}function h1(e){return cX(e)||lX(e)||uX(e)||pX(e)||dX(e)||fX(e)||oX(e)}function g1(e){return h1(e)?e:BY(e)}function _1(e,t){return!(!h1(e)||!h1(t)||lX(e)&&!lX(t)||cX(e)&&!cX(t)||uX(e)&&!uX(t)||pX(e)&&!pX(t)||dX(e)&&!dX(t)||fX(e)&&!fX(t)||oX(e)&&!oX(t))}function v1(e,t){if(lX(e)){let n={isoDate:{year:1970,month:1,day:1},time:Q(e,yJ)};return{epochNs:LZ(Q(t,VJ),n,`compatible`),formatter:s1(t,LJ)}}if(dX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==r)throw RangeError(`cannot format PlainYearMonth with calendar ${n} in locale with calendar ${r}`);let i=kX(Q(e,_J),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,FJ)}}if(fX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==r)throw RangeError(`cannot format PlainMonthDay with calendar ${n} in locale with calendar ${r}`);let i=kX(Q(e,_J),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,IJ)}}if(cX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDate with calendar ${n} in locale with calendar ${r}`);let i=kX(Q(e,_J),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,PJ)}}if(uX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDateTime with calendar ${n} in locale with calendar ${r}`);let i=Q(e,vJ);return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,RJ)}}if(pX(e))throw TypeError(`Temporal.ZonedDateTime not supported in DateTimeFormat methods. Use toLocaleString() instead.`);return oX(e)?{epochNs:Q(e,gJ),formatter:s1(t,zJ)}:{}}function y1(e){let t=Object.create(null);return t.years=Q(e,wJ),t.months=Q(e,TJ),t.weeks=Q(e,EJ),t.days=Q(e,DJ),t.hours=Q(e,OJ),t.minutes=Q(e,kJ),t.seconds=Q(e,AJ),t.milliseconds=Q(e,jJ),t.microseconds=Q(e,MJ),t.nanoseconds=Q(e,NJ),t}l1.prototype.constructor=u1,Object.defineProperty(u1,"prototype",{value:l1.prototype,writable:!1,enumerable:!1,configurable:!1}),u1.supportedLocalesOf=o1.supportedLocalesOf,eY(u1,`Intl.DateTimeFormat`);var{format:Uue,formatToParts:Wue}=Intl.DurationFormat?.prototype??Object.create(null);function b1(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=y1(eZ(e));return Uue.call(this,t)}Intl.DurationFormat?.prototype&&(Intl.DurationFormat.prototype.format=b1,Intl.DurationFormat.prototype.formatToParts=function(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=y1(eZ(e));return Wue.call(this,t)}),Object.freeze({__proto__:null,DateTimeFormat:u1,ModifiedIntlDurationFormatPrototypeFormat:b1});var x1=class{constructor(e){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);vZ(this,O$(e))}get epochMilliseconds(){return $(this,oX),E$(Q(this,gJ),`floor`)}get epochNanoseconds(){return $(this,oX),T$(X.default.BigInt(Q(this,gJ)))}add(e){return $(this,oX),u$(`add`,this,e)}subtract(e){return $(this,oX),u$(`subtract`,this,e)}until(e,t=void 0){return $(this,oX),e$(`until`,this,e,t)}since(e,t=void 0){return $(this,oX),e$(`since`,this,e,t)}round(e){if($(this,oX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX);return IX(n,{hour:24,minute:1440,second:86400,millisecond:864e5,microsecond:864e8,nanosecond:864e11}[i],!0),yZ(_$(Q(this,gJ),n,i,r))}equals(e){$(this,oX);let t=tZ(e),n=Q(this,gJ),r=Q(t,gJ);return X.default.equal(X.default.BigInt(n),X.default.BigInt(r))}toString(e=void 0){$(this,oX);let t=M$(e),n=LX(t),r=MX(t,`trunc`),i=BX(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=MZ(a));let{precision:o,unit:s,increment:c}=RX(i,n);return GZ(yZ(_$(Q(this,gJ),c,s,r)),a,o)}toJSON(){return $(this,oX),GZ(this,void 0,`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,oX),new u1(e,t).format(this)}valueOf(){L$(`Instant`)}toZonedDateTimeISO(e){$(this,oX);let t=MZ(e);return xZ(Q(this,gJ),t,`iso8601`)}static fromEpochMilliseconds(e){return yZ(D$(BY(e)))}static fromEpochNanoseconds(e){return yZ(O$(e))}static from(e){return tZ(e)}static compare(e,t){let n=tZ(e),r=tZ(t),i=Q(n,gJ),a=Q(r,gJ);return X.default.lessThan(i,a)?-1:+!!X.default.greaterThan(i,a)}};eY(x1,`Temporal.Instant`);var S1=class{constructor(e,t,n,r=`iso8601`){let i=HY(e),a=HY(t),o=HY(n),s=F$(r===void 0?`iso8601`:KY(r));OQ(i,a,o),cZ(this,{year:i,month:a,day:o},s)}get calendarId(){return $(this,cX),Q(this,Z)}get era(){return C1(this,`era`)}get eraYear(){return C1(this,`eraYear`)}get year(){return C1(this,`year`)}get month(){return C1(this,`month`)}get monthCode(){return C1(this,`monthCode`)}get day(){return C1(this,`day`)}get dayOfWeek(){return C1(this,`dayOfWeek`)}get dayOfYear(){return C1(this,`dayOfYear`)}get weekOfYear(){return C1(this,`weekOfYear`)?.week}get yearOfWeek(){return C1(this,`weekOfYear`)?.year}get daysInWeek(){return C1(this,`daysInWeek`)}get daysInMonth(){return C1(this,`daysInMonth`)}get daysInYear(){return C1(this,`daysInYear`)}get monthsInYear(){return C1(this,`monthsInYear`)}get inLeapYear(){return C1(this,`inLeapYear`)}with(e,t=void 0){if($(this,cX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=JX(n,Q(this,_J));return r=CZ(n,r,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),lZ(kZ(n,r,AX(M$(t))),n)}withCalendar(e){$(this,cX);let t=EZ(e);return lZ(Q(this,_J),t)}add(e,t=void 0){return $(this,cX),d$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,cX),d$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,cX),t$(`until`,this,e,t)}since(e,t=void 0){return $(this,cX),t$(`since`,this,e,t)}equals(e){$(this,cX);let t=ZX(e);return S$(Q(this,_J),Q(t,_J))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){return $(this,cX),qZ(this,PX(M$(e)))}toJSON(){return $(this,cX),qZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,cX),new u1(e,t).format(this)}valueOf(){L$(`PlainDate`)}toPlainDateTime(e=void 0){$(this,cX);let t=iZ(e);return dZ(kX(Q(this,_J),t),Q(this,Z))}toZonedDateTime(e){let t,n;if($(this,cX),zY(e)){let r=e.timeZone;r===void 0?t=MZ(e):(t=MZ(r),n=e.plainTime)}else t=MZ(e);let r=Q(this,_J),i;return n===void 0?i=BZ(t,r):(n=rZ(n),i=LZ(t,kX(r,Q(n,yJ)),`compatible`)),xZ(i,t,Q(this,Z))}toPlainYearMonth(){$(this,cX);let e=Q(this,Z);return _Z(AZ(e,JX(e,Q(this,_J)),`constrain`),e)}toPlainMonthDay(){$(this,cX);let e=Q(this,Z);return pZ(jZ(e,JX(e,Q(this,_J)),`constrain`),e)}static from(e,t=void 0){return ZX(e,t)}static compare(e,t){let n=ZX(e),r=ZX(t);return S$(Q(n,_J),Q(r,_J))}};function C1(e,t){$(e,cX);let n=Q(e,_J);return qX(e).isoToDate(n,{[t]:!0})[t]}eY(S1,`Temporal.PlainDate`);var w1=class{constructor(e,t,n,r=0,i=0,a=0,o=0,s=0,c=0,l=`iso8601`){let u=HY(e),d=HY(t),f=HY(n),p=r===void 0?0:HY(r),m=i===void 0?0:HY(i),h=a===void 0?0:HY(a),g=o===void 0?0:HY(o),_=s===void 0?0:HY(s),v=c===void 0?0:HY(c),y=F$(l===void 0?`iso8601`:KY(l));jQ(u,d,f,p,m,h,g,_,v),uZ(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,uX),Q(this,Z)}get year(){return T1(this,`year`)}get month(){return T1(this,`month`)}get monthCode(){return T1(this,`monthCode`)}get day(){return T1(this,`day`)}get hour(){return E1(this,`hour`)}get minute(){return E1(this,`minute`)}get second(){return E1(this,`second`)}get millisecond(){return E1(this,`millisecond`)}get microsecond(){return E1(this,`microsecond`)}get nanosecond(){return E1(this,`nanosecond`)}get era(){return T1(this,`era`)}get eraYear(){return T1(this,`eraYear`)}get dayOfWeek(){return T1(this,`dayOfWeek`)}get dayOfYear(){return T1(this,`dayOfYear`)}get weekOfYear(){return T1(this,`weekOfYear`)?.week}get yearOfWeek(){return T1(this,`weekOfYear`)?.year}get daysInWeek(){return T1(this,`daysInWeek`)}get daysInYear(){return T1(this,`daysInYear`)}get daysInMonth(){return T1(this,`daysInMonth`)}get monthsInYear(){return T1(this,`monthsInYear`)}get inLeapYear(){return T1(this,`inLeapYear`)}with(e,t=void 0){if($(this,uX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=Q(this,vJ),i={...JX(n,r.isoDate),...r.time};return i=CZ(n,i,YX(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],`partial`)),dZ(QX(n,i,AX(M$(t))),n)}withPlainTime(e=void 0){$(this,uX);let t=iZ(e);return dZ(kX(Q(this,vJ).isoDate,t),Q(this,Z))}withCalendar(e){$(this,uX);let t=EZ(e);return dZ(Q(this,vJ),t)}add(e,t=void 0){return $(this,uX),f$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,uX),f$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,uX),n$(`until`,this,e,t)}since(e,t=void 0){return $(this,uX),n$(`since`,this,e,t)}round(e){if($(this,uX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];IX(n,a,a===1);let o=Q(this,vJ);return dZ(n===1&&i===`nanosecond`?o:v$(o,n,i,r),Q(this,Z))}equals(e){$(this,uX);let t=$X(e);return w$(Q(this,vJ),Q(t,vJ))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){$(this,uX);let t=M$(e),n=PX(t),r=LX(t),i=MX(t,`trunc`),a=BX(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}=RX(a,r),l=v$(Q(this,vJ),c,s,i);return MQ(l),YZ(l,Q(this,Z),o,n)}toJSON(){return $(this,uX),YZ(Q(this,vJ),Q(this,Z),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,uX),new u1(e,t).format(this)}valueOf(){L$(`PlainDateTime`)}toZonedDateTime(e,t=void 0){$(this,uX);let n=MZ(e),r=jX(M$(t));return xZ(LZ(n,Q(this,vJ),r),n,Q(this,Z))}toPlainDate(){return $(this,uX),lZ(Q(this,vJ).isoDate,Q(this,Z))}toPlainTime(){return $(this,uX),hZ(Q(this,vJ).time)}static from(e,t=void 0){return $X(e,t)}static compare(e,t){let n=$X(e),r=$X(t);return w$(Q(n,vJ),Q(r,vJ))}};function T1(e,t){$(e,uX);let n=Q(e,vJ).isoDate;return qX(e).isoToDate(n,{[t]:!0})[t]}function E1(e,t){return $(e,uX),Q(e,vJ).time[t]}eY(w1,`Temporal.PlainDateTime`);var D1=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:WY(e),d=t===void 0?0:WY(t),f=n===void 0?0:WY(n),p=r===void 0?0:WY(r),m=i===void 0?0:WY(i),h=a===void 0?0:WY(a),g=o===void 0?0:WY(o),_=s===void 0?0:WY(s),v=c===void 0?0:WY(c),y=l===void 0?0:WY(l);IQ(u,d,f,p,m,h,g,_,v,y),XJ(this),QJ(this,wJ,u),QJ(this,TJ,d),QJ(this,EJ,f),QJ(this,DJ,p),QJ(this,OJ,m),QJ(this,kJ,h),QJ(this,AJ,g),QJ(this,jJ,_),QJ(this,MJ,v),QJ(this,NJ,y)}get years(){return $(this,sX),Q(this,wJ)}get months(){return $(this,sX),Q(this,TJ)}get weeks(){return $(this,sX),Q(this,EJ)}get days(){return $(this,sX),Q(this,DJ)}get hours(){return $(this,sX),Q(this,OJ)}get minutes(){return $(this,sX),Q(this,kJ)}get seconds(){return $(this,sX),Q(this,AJ)}get milliseconds(){return $(this,sX),Q(this,jJ)}get microseconds(){return $(this,sX),Q(this,MJ)}get nanoseconds(){return $(this,sX),Q(this,NJ)}get sign(){return $(this,sX),gQ(this)}get blank(){return $(this,sX),gQ(this)===0}with(t){$(this,sX);let{years:n=Q(this,wJ),months:r=Q(this,TJ),weeks:i=Q(this,EJ),days:a=Q(this,DJ),hours:o=Q(this,OJ),minutes:s=Q(this,kJ),seconds:c=Q(this,AJ),milliseconds:l=Q(this,jJ),microseconds:u=Q(this,MJ),nanoseconds:d=Q(this,NJ)}=DX(t);return new e(n,r,i,a,o,s,c,l,u,d)}negated(){return $(this,sX),wQ(this)}abs(){return $(this,sX),new e(Math.abs(Q(this,wJ)),Math.abs(Q(this,TJ)),Math.abs(Q(this,EJ)),Math.abs(Q(this,DJ)),Math.abs(Q(this,OJ)),Math.abs(Q(this,kJ)),Math.abs(Q(this,AJ)),Math.abs(Q(this,jJ)),Math.abs(Q(this,MJ)),Math.abs(Q(this,NJ)))}add(e){return $(this,sX),l$(`add`,this,e)}subtract(e){return $(this,sX),l$(`subtract`,this,e)}round(e){if($(this,sX),e===void 0)throw TypeError(`options parameter is required`);let t=HX(this),n=typeof e==`string`?N$(`smallestUnit`,e):M$(e),r=BX(n,`largestUnit`,`datetime`,void 0,[`auto`]),{plainRelativeTo:i,zonedRelativeTo:a}=VX(n),o=FX(n),s=MX(n,`halfExpand`),c=BX(n,`smallestUnit`,`datetime`,void 0),l=!0;c||=(l=!1,`nanosecond`);let u=UX(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(UX(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&&IX(o,f,!1),o>1&&GX(c)===`date`&&r!==c)throw RangeError(`For calendar units with roundingIncrement > 1, use largestUnit = smallestUnit`);if(a){let e=LQ(this),t=Q(a,CJ),n=Q(a,Z),i=Q(a,gJ);return e=QQ(i,c$(i,t,n,e),t,n,r,o,c,s),GX(r)===`date`&&(r=`hour`),BQ(e,r)}if(i){let e=RQ(this),t=o$({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),n=Q(i,_J),a=Q(i,Z),l=wZ(a,n,OX(e.date,t.deltaDays),`constrain`);return e=ZQ(kX(n,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),kX(l,t),a,r,o,c,s),BQ(e,r)}if(WX(t))throw RangeError(`a starting point is required for ${t}s balancing`);if(WX(r))throw RangeError(`a starting point is required for ${r}s balancing`);let p=RQ(this);if(c===`day`){let{quotient:e,remainder:t}=p.time.divmod(EY),n=p.date.days+e+x$(t,`day`);n=g$(n,o,s),p=VQ({years:0,months:0,weeks:0,days:n},sY.ZERO)}else p=VQ({years:0,months:0,weeks:0,days:0},b$(p.time,o,c,s));return BQ(p,r)}total(e){if($(this,sX),e===void 0)throw TypeError(`options argument is required`);let t=typeof e==`string`?N$(`unit`,e):M$(e),{plainRelativeTo:n,zonedRelativeTo:r}=VX(t),i=BX(t,`unit`,`datetime`,zX);if(r){let e=LQ(this),t=Q(r,CJ),n=Q(r,Z),a=Q(r,gJ);return function(e,t,n,r,i){return GX(i)===`time`?x$(sY.fromEpochNsDiff(t,e),i):XQ(qQ(e,t,n,r,i),t,IZ(n,e),n,r,i)}(a,c$(a,t,n,e),t,n,i)}if(n){let e=RQ(this),t=o$({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),r=Q(n,_J),a=Q(n,Z),o=wZ(a,r,OX(e.date,t.deltaDays),`constrain`);return function(e,t,n,r){if(w$(e,t)==0)return 0;MQ(e),MQ(t);let i=KQ(e,t,n,r);return r===`nanosecond`?X.default.toNumber(i.time.totalNs):XQ(i,lQ(t),e,null,n,r)}(kX(r,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),kX(o,t),a,i)}let a=HX(this);if(WX(a))throw RangeError(`a starting point is required for ${a}s total`);if(WX(i))throw RangeError(`a starting point is required for ${i}s total`);return x$(RQ(this).time,i)}toString(e=void 0){$(this,sX);let t=M$(e),n=LX(t),r=MX(t,`trunc`),i=BX(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}=RX(i,n);if(o===`nanosecond`&&s===1)return KZ(this,a);let c=HX(this),l=LQ(this),u=b$(l.time,s,o,r);return l=VQ(l.date,u),KZ(BQ(l,UX(c,`second`)),a)}toJSON(){return $(this,sX),KZ(this,`auto`)}toLocaleString(e=void 0,t=void 0){if($(this,sX),typeof Intl.DurationFormat==`function`){let n=new Intl.DurationFormat(e,t);return b1.call(n,this)}return console.warn(`Temporal.Duration.prototype.toLocaleString() requires Intl.DurationFormat.`),KZ(this,`auto`)}valueOf(){L$(`Duration`)}static from(e){return eZ(e)}static compare(e,t,n=void 0){let r=eZ(e),i=eZ(t),{plainRelativeTo:a,zonedRelativeTo:o}=VX(M$(n));if(Q(r,wJ)===Q(i,wJ)&&Q(r,TJ)===Q(i,TJ)&&Q(r,EJ)===Q(i,EJ)&&Q(r,DJ)===Q(i,DJ)&&Q(r,OJ)===Q(i,OJ)&&Q(r,kJ)===Q(i,kJ)&&Q(r,AJ)===Q(i,AJ)&&Q(r,jJ)===Q(i,jJ)&&Q(r,MJ)===Q(i,MJ)&&Q(r,NJ)===Q(i,NJ))return 0;let s=HX(r),c=HX(i),l=LQ(r),u=LQ(i);if(o&&(GX(s)===`date`||GX(c)===`date`)){let e=Q(o,CJ),t=Q(o,Z),n=Q(o,gJ),r=c$(n,e,t,l),i=c$(n,e,t,u);return j$(X.default.toNumber(X.default.subtract(r,i)))}let d=l.date.days,f=u.date.days;if(WX(s)||WX(c)){if(!a)throw RangeError(`A starting point is required for years, months, or weeks comparison`);d=CQ(l.date,a),f=CQ(u.date,a)}let p=l.time.add24HourDays(d),m=u.time.add24HourDays(f);return p.cmp(m)}};eY(D1,`Temporal.Duration`);var O1=class{constructor(e,t,n=`iso8601`,r=1972){let i=HY(e),a=HY(t),o=F$(n===void 0?`iso8601`:KY(n)),s=HY(r);OQ(s,i,a),fZ(this,{year:s,month:i,day:a},o)}get monthCode(){return k1(this,`monthCode`)}get day(){return k1(this,`day`)}get calendarId(){return $(this,fX),Q(this,Z)}with(e,t=void 0){if($(this,fX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=JX(n,Q(this,_J),`month-day`);return r=CZ(n,r,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),pZ(jZ(n,r,AX(M$(t))),n)}equals(e){$(this,fX);let t=nZ(e);return S$(Q(this,_J),Q(t,_J))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){return $(this,fX),XZ(this,PX(M$(e)))}toJSON(){return $(this,fX),XZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,fX),new u1(e,t).format(this)}valueOf(){L$(`PlainMonthDay`)}toPlainDate(e){if($(this,fX),!zY(e))throw TypeError(`argument should be an object`);let t=Q(this,Z);return lZ(kZ(t,CZ(t,JX(t,Q(this,_J),`month-day`),YX(t,e,[`year`],[],[])),`constrain`),t)}static from(e,t=void 0){return nZ(e,t)}};function k1(e,t){$(e,fX);let n=Q(e,_J);return qX(e).isoToDate(n,{[t]:!0})[t]}function A1(e){return IZ(e,k$())}eY(O1,`Temporal.PlainMonthDay`);var j1={instant:()=>yZ(k$()),plainDateTimeISO:(e=A$())=>dZ(A1(MZ(e)),`iso8601`),plainDateISO:(e=A$())=>lZ(A1(MZ(e)).isoDate,`iso8601`),plainTimeISO:(e=A$())=>hZ(A1(MZ(e)).time),timeZoneId:()=>A$(),zonedDateTimeISO:(e=A$())=>{let t=MZ(e);return xZ(k$(),t,`iso8601`)},[Symbol.toStringTag]:`Temporal.Now`};Object.defineProperty(j1,Symbol.toStringTag,{value:`Temporal.Now`,writable:!1,enumerable:!1,configurable:!0});var M1=class e{constructor(e=0,t=0,n=0,r=0,i=0,a=0){let o=e===void 0?0:HY(e),s=t===void 0?0:HY(t),c=n===void 0?0:HY(n),l=r===void 0?0:HY(r),u=i===void 0?0:HY(i),d=a===void 0?0:HY(a);AQ(o,s,c,l,u,d),mZ(this,{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d})}get hour(){return $(this,lX),Q(this,yJ).hour}get minute(){return $(this,lX),Q(this,yJ).minute}get second(){return $(this,lX),Q(this,yJ).second}get millisecond(){return $(this,lX),Q(this,yJ).millisecond}get microsecond(){return $(this,lX),Q(this,yJ).microsecond}get nanosecond(){return $(this,lX),Q(this,yJ).nanosecond}with(t,n=void 0){if($(this,lX),!zY(t))throw TypeError(`invalid argument`);mX(t);let r=XX(t,`partial`),i=XX(this),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=Object.assign(i,r),d=AX(M$(n));return{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=EX(a,o,s,c,l,u,d),new e(a,o,s,c,l,u)}add(e){return $(this,lX),p$(`add`,this,e)}subtract(e){return $(this,lX),p$(`subtract`,this,e)}until(e,t=void 0){return $(this,lX),r$(`until`,this,e,t)}since(e,t=void 0){return $(this,lX),r$(`since`,this,e,t)}round(e){if($(this,lX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX);return IX(n,{hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i],!1),hZ(y$(Q(this,yJ),n,i,r))}equals(e){$(this,lX);let t=rZ(e);return C$(Q(this,yJ),Q(t,yJ))===0}toString(e=void 0){$(this,lX);let t=M$(e),n=LX(t),r=MX(t,`trunc`),i=BX(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}=RX(i,n);return JZ(y$(Q(this,yJ),s,o,r),a)}toJSON(){return $(this,lX),JZ(Q(this,yJ),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,lX),new u1(e,t).format(this)}valueOf(){L$(`PlainTime`)}static from(e,t=void 0){return rZ(e,t)}static compare(e,t){let n=rZ(e),r=rZ(t);return C$(Q(n,yJ),Q(r,yJ))}};eY(M1,`Temporal.PlainTime`);var N1=class{constructor(e,t,n=`iso8601`,r=1){let i=HY(e),a=HY(t),o=F$(n===void 0?`iso8601`:KY(n)),s=HY(r);OQ(i,a,s),gZ(this,{year:i,month:a,day:s},o)}get year(){return P1(this,`year`)}get month(){return P1(this,`month`)}get monthCode(){return P1(this,`monthCode`)}get calendarId(){return $(this,dX),Q(this,Z)}get era(){return P1(this,`era`)}get eraYear(){return P1(this,`eraYear`)}get daysInMonth(){return P1(this,`daysInMonth`)}get daysInYear(){return P1(this,`daysInYear`)}get monthsInYear(){return P1(this,`monthsInYear`)}get inLeapYear(){return P1(this,`inLeapYear`)}with(e,t=void 0){if($(this,dX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=JX(n,Q(this,_J),`year-month`);return r=CZ(n,r,YX(n,e,[`year`,`month`,`monthCode`],[],`partial`)),_Z(AZ(n,r,AX(M$(t))),n)}add(e,t=void 0){return $(this,dX),m$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,dX),m$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,dX),i$(`until`,this,e,t)}since(e,t=void 0){return $(this,dX),i$(`since`,this,e,t)}equals(e){$(this,dX);let t=aZ(e);return S$(Q(this,_J),Q(t,_J))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){return $(this,dX),ZZ(this,PX(M$(e)))}toJSON(){return $(this,dX),ZZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,dX),new u1(e,t).format(this)}valueOf(){L$(`PlainYearMonth`)}toPlainDate(e){if($(this,dX),!zY(e))throw TypeError(`argument should be an object`);let t=Q(this,Z);return lZ(kZ(t,CZ(t,JX(t,Q(this,_J),`year-month`),YX(t,e,[`day`],[],[])),`constrain`),t)}static from(e,t=void 0){return aZ(e,t)}static compare(e,t){let n=aZ(e),r=aZ(t);return S$(Q(n,_J),Q(r,_J))}};function P1(e,t){$(e,dX);let n=Q(e,_J);return qX(e).isoToDate(n,{[t]:!0})[t]}eY(N1,`Temporal.PlainYearMonth`);var Gue=u1.prototype.resolvedOptions,F1=class{constructor(e,t,n=`iso8601`){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);let r=O$(e),i=KY(t),{tzName:a,offsetMinutes:o}=wX(i);if(o===void 0){let e=rQ(a);if(!e)throw RangeError(`unknown time zone ${a}`);i=e.identifier}else i=oQ(o);bZ(this,r,i,F$(n===void 0?`iso8601`:KY(n)))}get calendarId(){return $(this,pX),Q(this,Z)}get timeZoneId(){return $(this,pX),Q(this,CJ)}get year(){return L1(this,`year`)}get month(){return L1(this,`month`)}get monthCode(){return L1(this,`monthCode`)}get day(){return L1(this,`day`)}get hour(){return R1(this,`hour`)}get minute(){return R1(this,`minute`)}get second(){return R1(this,`second`)}get millisecond(){return R1(this,`millisecond`)}get microsecond(){return R1(this,`microsecond`)}get nanosecond(){return R1(this,`nanosecond`)}get era(){return L1(this,`era`)}get eraYear(){return L1(this,`eraYear`)}get epochMilliseconds(){return $(this,pX),E$(Q(this,gJ),`floor`)}get epochNanoseconds(){return $(this,pX),T$(Q(this,gJ))}get dayOfWeek(){return L1(this,`dayOfWeek`)}get dayOfYear(){return L1(this,`dayOfYear`)}get weekOfYear(){return L1(this,`weekOfYear`)?.week}get yearOfWeek(){return L1(this,`weekOfYear`)?.year}get hoursInDay(){$(this,pX);let e=Q(this,CJ),t=I1(this).isoDate,n=bQ(t.year,t.month,t.day+1),r=BZ(e,t),i=BZ(e,n);return x$(sY.fromEpochNsDiff(i,r),`hour`)}get daysInWeek(){return L1(this,`daysInWeek`)}get daysInMonth(){return L1(this,`daysInMonth`)}get daysInYear(){return L1(this,`daysInYear`)}get monthsInYear(){return L1(this,`monthsInYear`)}get inLeapYear(){return L1(this,`inLeapYear`)}get offset(){return $(this,pX),FZ(PZ(Q(this,CJ),Q(this,gJ)))}get offsetNanoseconds(){return $(this,pX),PZ(Q(this,CJ),Q(this,gJ))}with(e,t=void 0){if($(this,pX),!zY(e))throw TypeError(`invalid zoned-date-time-like`);mX(e);let n=Q(this,Z),r=Q(this,CJ),i=PZ(r,Q(this,gJ)),a=I1(this),o={...JX(n,a.isoDate),...a.time,offset:FZ(i)};o=CZ(n,o,YX(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`],`partial`));let s=M$(t),c=jX(s),l=NX(s,`prefer`),u=QX(n,o,AX(s)),d=eQ(o.offset);return xZ(oZ(u.isoDate,u.time,`option`,d,r,c,l,!1),r,n)}withPlainTime(e=void 0){$(this,pX);let t=Q(this,CJ),n=Q(this,Z),r=I1(this).isoDate,i;return i=e===void 0?BZ(t,r):LZ(t,kX(r,Q(rZ(e),yJ)),`compatible`),xZ(i,t,n)}withTimeZone(e){$(this,pX);let t=MZ(e);return xZ(Q(this,gJ),t,Q(this,Z))}withCalendar(e){$(this,pX);let t=EZ(e);return xZ(Q(this,gJ),Q(this,CJ),t)}add(e,t=void 0){return $(this,pX),h$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,pX),h$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,pX),a$(`until`,this,e,t)}since(e,t=void 0){return $(this,pX),a$(`since`,this,e,t)}round(e){if($(this,pX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];if(IX(n,a,a===1),i===`nanosecond`&&n===1)return xZ(Q(this,gJ),Q(this,CJ),Q(this,Z));let o=Q(this,CJ),s=Q(this,gJ),c=I1(this),l;if(i===`day`){let e=c.isoDate,t=bQ(e.year,e.month,e.day+1),n=BZ(o,e),i=BZ(o,t),a=X.default.subtract(i,n);l=sY.fromEpochNsDiff(s,n).round(a,r).addToEpochNs(n)}else{let e=v$(c,n,i,r),t=PZ(o,s);l=oZ(e.isoDate,e.time,`option`,t,o,`compatible`,`prefer`,!1)}return xZ(l,o,Q(this,Z))}equals(e){$(this,pX);let t=sZ(e),n=Q(this,gJ),r=Q(t,gJ);return!!X.default.equal(X.default.BigInt(n),X.default.BigInt(r))&&!!NZ(Q(this,CJ),Q(t,CJ))&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){$(this,pX);let t=M$(e),n=PX(t),r=LX(t),i=function(e){return P$(e,`offset`,[`auto`,`never`],`auto`)}(t),a=MX(t,`trunc`),o=BX(t,`smallestUnit`,`time`,void 0);if(o===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let s=function(e){return P$(e,`timeZoneName`,[`auto`,`never`,`critical`],`auto`)}(t),{precision:c,unit:l,increment:u}=RX(o,r);return QZ(this,c,n,s,i,{unit:l,increment:u,roundingMode:a})}toLocaleString(e=void 0,t=void 0){$(this,pX);let n=M$(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,CJ),$Z(r.timeZone))throw RangeError(`toLocaleString does not currently support offset time zones`);let i=new u1(e,r),a=Gue.call(i).calendar,o=Q(this,Z);if(o!==`iso8601`&&a!==`iso8601`&&!OZ(a,o))throw RangeError(`cannot format ZonedDateTime with calendar ${o} in locale with calendar ${a}`);return i.format(yZ(Q(this,gJ)))}toJSON(){return $(this,pX),QZ(this,`auto`)}valueOf(){L$(`ZonedDateTime`)}startOfDay(){$(this,pX);let e=Q(this,CJ);return xZ(BZ(e,I1(this).isoDate),e,Q(this,Z))}getTimeZoneTransition(e){$(this,pX);let t=Q(this,CJ);if(e===void 0)throw TypeError(`options parameter is required`);let n=P$(typeof e==`string`?N$(`direction`,e):M$(e),`direction`,[`next`,`previous`],zX);if(n===void 0)throw TypeError(`direction option is required`);if($Z(t)||t===`UTC`)return null;let r=Q(this,gJ),i=n===`next`?dQ(t,r):fQ(t,r);return i===null?null:xZ(i,t,Q(this,Z))}toInstant(){return $(this,pX),yZ(Q(this,gJ))}toPlainDate(){return $(this,pX),lZ(I1(this).isoDate,Q(this,Z))}toPlainTime(){return $(this,pX),hZ(I1(this).time)}toPlainDateTime(){return $(this,pX),dZ(I1(this),Q(this,Z))}static from(e,t=void 0){return sZ(e,t)}static compare(e,t){let n=sZ(e),r=sZ(t),i=Q(n,gJ),a=Q(r,gJ);return X.default.lessThan(X.default.BigInt(i),X.default.BigInt(a))?-1:+!!X.default.greaterThan(X.default.BigInt(i),X.default.BigInt(a))}};function I1(e){return IZ(Q(e,CJ),Q(e,gJ))}function L1(e,t){$(e,pX);let n=I1(e).isoDate;return qX(e).isoToDate(n,{[t]:!0})[t]}function R1(e,t){return $(e,pX),I1(e).time[t]}eY(F1,`Temporal.ZonedDateTime`);var Kue=Object.freeze({__proto__:null,Duration:D1,Instant:x1,Now:j1,PlainDate:S1,PlainDateTime:w1,PlainMonthDay:O1,PlainTime:M1,PlainYearMonth:N1,ZonedDateTime:F1});(class{toTemporalInstant(){return yZ(D$(Date.prototype.valueOf.call(this)))}}).prototype.toTemporalInstant;var que=[x1,S1,w1,D1,O1,M1,N1,F1];for(let e of que){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 Jue(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 Yue(e,t){return Jue(new Date(e),t)}function Xue(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=Kue.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 z1(e,t){return new Intl.DateTimeFormat(void 0,{timeZone:t,dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}var B1={"claude-code":{name:`Claude Code`,command:`claude auth login`},codex:{name:`Codex`,command:`codex login`},gemini:{name:`Gemini`,command:`gemini`}},Zue=/not signed in|sign-in has expired|not logged in|run\s+"?(?:codex login|claude auth login)|authentication required/i,Que=/ENOSPC|no space left on device|disk (?:is )?full|not enough (?:free )?(?:disk )?space/i,$ue=/refused to make|content (?:rules|policy|filter)|safety (?:system|filter)|flagged|moderation/i,ede=/\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,tde=/did not accept the API key|API key is saved|invalid api key|key may be wrong/i,nde=[`images`,`thumbnail`];function V1(e){let t=e.reason??``,n=rde(e.provider,t);if(n!==void 0&&(Zue.test(t)||e.kind===`auth`))return{kind:`sign-in`,label:`Sign in to ${B1[n].name}`,cli:n,command:B1[n].command};if(Que.test(t))return{kind:`free-space`,label:`Free space`};if(e.kind===`refusal`||$ue.test(t))return nde.includes(e.stage)?{kind:`refused`,label:`Soften and retry`,soften:!0}:{kind:`refused`,label:`Edit the prompt`,soften:!1};if(ede.test(t))return{kind:`switch-model`,label:`Switch model`};if(e.kind===`auth`||e.kind===`missing_key`||tde.test(t)){let t=ide(e.provider);return{kind:`provider-settings`,label:t===void 0?`Open Settings → Providers`:`Open Settings → Providers → ${t}`,provider:e.provider??``}}}function rde(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 ide(e){return HF.find(t=>t.id===e)?.displayName}function ade(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}}var H1={catalogue:[`catalogue`],retired:[`catalogue`,`retired`],firstRun:[`first-run`]},U1={method:`POST`};async function ode(e,t,n){return F(await e.fetch(`${e.origin}/api/providers/${t}/key/test`,n===void 0?U1:{...U1,headers:{"content-type":`application/json`},body:JSON.stringify({key:n})}))}async function W1(e,t){let n=t===void 0?``:`?provider=${encodeURIComponent(t)}`;return F(await e.fetch(`${e.origin}/api/providers/health${n}`,U1))}async function sde(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue`))}async function cde(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue/check`,U1))}async function lde(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue/refresh`,U1))}async function G1(e){return(await F(await e.fetch(`${e.origin}/api/providers/catalogue/retired`))).usages}async function K1(e,t){await F(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 ude(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch-all`,U1))}async function dde(e){return F(await e.fetch(`${e.origin}/api/providers/first-run`))}async function fde(e){let t=await e.fetch(`${e.origin}/api/providers/first-run/dismiss`,U1);t.ok||await F(t)}function pde(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 mde(e){return e.label.replace(/^Sign in to /,``)}async function q1(e){if(!navigator.clipboard)return!1;try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function J1({fix:e,retry:t,variant:n=`primary`,size:r=`default`}){let{api:i}=z(),a=Oy(),o=mde(e),s=P({mutationFn:async()=>pde(await W1(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 q1(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)(R,{variant:n,size:r,onClick:()=>void c(),children:`Copy sign-in command`}),(0,h.jsx)(R,{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 Y1({fix:e,retry:t,edit:n,variant:r=`primary`,size:i=`default`}){switch(e.kind){case`sign-in`:return(0,h.jsx)(J1,{fix:e,retry:t,variant:r,size:i});case`provider-settings`:return(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},variant:r,size:i,children:e.label});case`free-space`:return(0,h.jsx)(fS,{to:`/settings`,search:{section:`storage`},variant:r,size:i,children:e.label});case`refused`:case`switch-model`:return n??null}}function hde(e){let t=e.topics.error;if(t!==null)return V1({stage:`article`,reason:t,provider:e.topicGeneration.llm?.provider})}function X1({schedule:e,title:t,retry:n,className:r}){if(e.topics.error===null)return null;let i=hde(e);return(0,h.jsx)(SI,{tone:`danger`,title:t,...r===void 0?{}:{className:r},...i===void 0?{}:{actions:(0,h.jsx)(Y1,{fix:i,retry:n,variant:`secondary`,size:`small`})},children:e.topics.error})}function Z1(e){let t=Object.entries(e);return t.length===0?void 0:t.map(([e,t])=>`${e}: ${t}`).join(` · `)}function gde({schedule:e}){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),s=e.deletedAt===null&&(e.status===`active`||e.status===`paused`),c=N({queryKey:[...NH(e.id),e.topics.held,e.topics.generatedAt],enabled:s&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await PH(t,e.id);if(!n.ok)throw Error(n.message);return n.value}}),l=N({queryKey:[`project-template`,e.templateId],enabled:s&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await Uq(t,e.templateId);if(!n.ok)throw Error(n.message);return n.value}}).data?.document.form,u=(l===void 0?[]:_q(l)).filter(t=>t!==e.topicKeyword),d=t=>e.values[t]??l?.values[t]??``,f=P({mutationFn:e=>e(),onSuccess:e=>{i(e.ok?null:e.message),e.ok&&o(null)},onError:e=>i(e.message),onSettled:async()=>{await Promise.all([n.invalidateQueries({queryKey:TH}),n.invalidateQueries({queryKey:NH(e.id)}),n.invalidateQueries({queryKey:GH})])}});if(!s||e.topicGeneration.mode===`off`)return null;let{topics:p}=e,g=f.isPending,v=c.data??[];return(0,h.jsxs)(`section`,{"aria-label":`Topic generation`,children:[(0,h.jsx)(Mq,{className:`my-6`}),(0,h.jsxs)(H,{as:`h3`,title:`Topic generation`,meta:`${p.generatingSince===null?p.generatedAt===null?`No topics generated yet.`:`Topics last generated ${z1(p.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)(V,{id:`planning.schedule.generate-now`}),(0,h.jsx)(R,{disabled:g||p.generatingSince!==null,disabledReason:`Topics are being generated now`,onClick:()=>f.mutate(()=>IH(t,e.id)),children:`Generate topics now`})]}),(0,h.jsx)(X1,{schedule:e,title:`The last topic generation failed.`,className:`mt-3`,retry:{run:()=>f.mutate(()=>IH(t,e.id)),busy:g||p.generatingSince!==null}}),r===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`That didn't work.`,className:`mt-3`,children:r}),e.topicGeneration.mode===`hold`?(0,h.jsxs)(`div`,{className:`mt-4`,...Ob,children:[(0,h.jsx)(H,{as:`h3`,title:`Topics waiting · ${String(v.length)}`,info:`planning.schedule.held`,children:(0,h.jsx)(R,{variant:`primary`,disabled:g||v.length===0,disabledReason:`Nothing is waiting`,onClick:()=>f.mutate(()=>zH(t,e.id)),children:`Approve all`})}),c.error?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-danger`,children:`The waiting topics couldn't be loaded: ${c.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.jsx)(pU,{label:`Topics waiting`,className:`mt-2 [&_.sl-row__actions]:flex-wrap`,children:v.map(n=>(0,h.jsx)(mU,{title:a?.id===n.id?(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(CV,{"aria-label":`Edit ${n.title}`,className:`w-full`,maxLength:200,value:a.title,onChange:e=>o({...a,title:e.target.value})}),u.length===0?null:(0,h.jsx)(`div`,{className:`grid grid-cols-1 gap-2 min-[600px]:grid-cols-2`,children:u.map(e=>(0,h.jsx)(xV,{label:e,tip:`planning.schedule.held-keywords`,children:(0,h.jsx)(CV,{maxLength:2e3,placeholder:d(e)||`Not set`,value:a.values[e]??``,onChange:t=>o({...a,values:{...a.values,[e]:t.target.value}})})},e))})]}):n.title,meta:a?.id===n.id?void 0:Z1(n.values),actions:a?.id===n.id?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:g||a.title.trim()===``,onClick:()=>f.mutate(()=>VH(t,e.id,n.id,a.title.trim(),Object.fromEntries(Object.entries(a.values).filter(([,e])=>e.trim()!==``)))),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>o(null),children:`Cancel`})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:g,onClick:()=>f.mutate(()=>RH(t,e.id,n.id)),children:`Approve`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:g,onClick:()=>o({id:n.id,title:n.title,values:n.values}),children:`Edit`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:g,onClick:()=>f.mutate(()=>BH(t,e.id,n.id)),children:`Reject`})]})},n.id))})]}):null]})}function _de({schedules:e}){let t=e.filter(e=>e.deletedAt===null&&e.topicGeneration.mode!==`off`&&(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)(H,{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`,{children:(0,h.jsx)(pS,{to:`/calendar`,search:{tab:`schedules`},children:`Open schedules`})})]}):t.map((e,t)=>(0,h.jsx)(vde,{schedule:e,first:t===0},e.id))})}function vde({schedule:e,first:t}){let{api:n}=z(),r=_(),i=Oy(),a=N({queryKey:[...NH(e.id),e.topics.held,e.version],queryFn:async()=>{let t=await PH(n,e.id);if(!t.ok)throw Error(t.message);return t.value},enabled:e.topics.held>0}),o=P({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:TH}),r.invalidateQueries({queryKey:GH}),r.invalidateQueries({queryKey:NH(e.id)})])}}),s=e.topics.held>0?a.data??[]:[],c=()=>o.mutate(()=>zH(n,e.id));bx({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)(H,{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)(R,{size:`small`,variant:`secondary`,disabled:o.isPending,onClick:c,children:`Queue all ${String(s.length)}`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(V,{id:`planning.schedule.generate-now`,label:`Suggest topics now`}),(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:o.isPending||l,disabledReason:l?`Slopify is suggesting topics now.`:`Working…`,onClick:()=>o.mutate(()=>IH(n,e.id)),children:l?`Suggesting…`:`Suggest topics now`})]})}),(0,h.jsx)(X1,{schedule:e,title:`The last suggestion failed.`,retry:{run:()=>o.mutate(()=>IH(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)(pU,{label:`Suggestions for ${e.name}`,children:s.map(t=>(0,h.jsx)(mU,{title:t.title,meta:Z1(t.values),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:o.isPending,onClick:()=>o.mutate(()=>RH(n,e.id,t.id)),"aria-label":`Queue ${t.title}`,children:`Queue`}),(0,h.jsx)(wy,{size:`small`,label:`Reject ${t.title}`,disabled:o.isPending,onClick:()=>o.mutate(()=>BH(n,e.id,t.id)),children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})},t.id))}),(0,h.jsx)(SI,{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.`})]})}var yde={info:`text-ink-2`,error:`text-danger`,warning:`text-waiting`,success:`text-accent-ink`};function Q1({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:L(`flex min-h-8 min-w-0 flex-1 items-center gap-2 overflow-hidden text-small`,yde[t],n),children:e==null||e===!1?null:i===void 0?e:(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:i})})}function $1({status:e,children:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`action-bar`,className:L(`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)(Q1,{})}),(0,h.jsx)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:t})]})}function e0({split:e=`main-side`,className:t,children:n}){return(0,h.jsx)(`div`,{"data-slot":`board`,className:L(`sl-board`,`sl-board--${e}`,t),children:n})}function t0({as:e=`div`,label:t,className:n,children:r}){let i=L(`sl-board__column`,n);return e===`aside`?(0,h.jsx)(`aside`,{"aria-label":t,className:i,children:r}):t===void 0?(0,h.jsx)(`div`,{className:i,children:r}):(0,h.jsx)(`section`,{"aria-label":t,className:i,children:r})}var n0=`sl-tab inline-flex items-center gap-[6px]`;function r0({items:e,value:t,onChange:n,label:r,idPrefix:i,trailing:a,className:o}){let s=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:L(`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:n0,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 bde({items:e,label:t,className:n}){return(0,h.jsx)(`nav`,{"aria-label":t,className:L(`sl-tabs min-w-0`,n),children:e.map(e=>(0,h.jsx)(ha,{to:e.to,...e.search?{search:e.search}:{},activeOptions:{exact:!1,includeSearch:!1},className:n0,activeProps:{"aria-current":`page`},children:e.label},e.to))})}function i0({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 a0({title:e,children:t,actions:n,className:r}){return(0,h.jsxs)(`div`,{className:L(`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 o0(e){return e.channelId??`00000000-0000-4000-8000-000000000001`}function xde({channelId:e}){let{api:t}=z(),n=_(),r=N(Hq(t)),i=N(Zb(t)),a=P({mutationFn:e=>cx(t,e.templateId,e.channelId),onSettled:()=>Promise.all([n.invalidateQueries({queryKey:Lq}),n.invalidateQueries({queryKey:qb})])}),o=(r.data??[]).filter(t=>o0(t)===e);return(0,h.jsxs)(`div`,{...Ob,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)(ha,{to:`/templates`,className:`underline`,children:`Library → Templates`}),`. Move to sends a template and its schedules to another channel.`,` `,(0,h.jsx)(V,{id:`planning.channel.template-move`,className:`-my-1 align-middle`})]}),(0,h.jsx)(Q1,{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)(a0,{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)(pU,{label:`Channel templates`,className:`[&_.sl-row__actions]:flex-wrap`,children:o.map(t=>(0,h.jsx)(mU,{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)(TV,{"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]})}var Sde={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Cde={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function wde({channelId:e}){let{api:t}=z(),n=N(Hq(t)),r=N(EH(t)),i=new Set((n.data??[]).filter(t=>o0(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)(ha,{to:`/calendar`,search:{tab:`schedules`},className:`underline`,children:`Calendar → Schedules`}),`.`]}),(0,h.jsx)(Q1,{tone:r.error?`error`:`info`,className:`mb-2`,children:r.error?.message}),r.data&&a.length===0?(0,h.jsx)(a0,{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)(pU,{label:`Channel schedules`,children:a.map(e=>(0,h.jsx)(mU,{title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(_S,{tone:Cde[e.status],children:Sde[e.status]}),` · ${e.nextRunAt===null?`No next run`:`Next run ${z1(e.nextRunAt,e.timezone)}`} · ${String(e.items.length)} queued`]})},e.id))}):null]})}var s0={llm:`Text model`,audio:`Voice model`,images:`Image model`,animate:`Animation model`};function c0({kind:e,id:t,name:n}){let{api:r}=z(),i=_(),a=N({queryKey:H1.retired,queryFn:()=>G1(r)}),o=P({mutationFn:e=>K1(r,e),onSuccess:()=>Promise.all([i.invalidateQueries({queryKey:H1.retired}),i.invalidateQueries({queryKey:Lq}),i.invalidateQueries({queryKey:TH})])}),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:[`${s0[t.slot]} ${t.model} is ${t.why===`retired`?`retired`:`no longer listed`}.`,t.blocked===null?``:` ${t.blocked}`,t.replacement===null&&t.blocked===null?` No replacement is suggested: choose another model in Settings → Models, or edit the ${e}.`:``]}),t.replacement===null?null:(0,h.jsx)(R,{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 l0(e){return UA(e)?`script`:`article`}function Tde(e){let{form:t}=e,n=[],r=[];if(m0(n,t.title),uj(t)&&m0(n,f0(e.prompts,`narration`,t.narrationPrompt??``)),t.sources.article===`generate`&&m0(n,f0(e.prompts,l0(t),t.articlePrompt)),t.sources.audio===`generate`&&(m0(n,p0(e.entries,`intro`,t.intro)),m0(n,p0(e.entries,`outro`,t.outro))),pj(t)&&m0(n,f0(e.prompts,`description`,t.descriptionPrompt??``)),jN(t)&&(m0(n,f0(e.prompts,`shorts`,t.shorts?.prompt??``)),m0(r,f0(e.prompts,`image`,t.shorts?.imagePrompt??``))),t.sources.images===`generate`){for(let n of t.imagePrompts)m0(r,f0(e.prompts,`image`,n.name));t.reference?.source===`prompt`&&m0(r,f0(e.prompts,`image`,t.reference.prompt))}return(t.sources.thumbnail===`from_prompt`||t.sources.thumbnail===`prompt_by_llm`)&&m0(r,f0(e.prompts,`thumbnail`,t.thumbnailPrompt)),pq(n,r)}function Ede(e){let t=Tde(e),n={form:e.form,entries:e.entries,slots:t.map(e=>e.name),silenceGapSeconds:e.silenceGapSeconds},r=zN(n),i=ej({draft:r,staged:RN(e.form.provided),requiredSlots:n.slots}),a=kN(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:Dde(e.form,a)}}var u0=`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 Dde(e,t){let n=Ode(e);if(n!==void 0)return n;if(t.ok)return;let r=[...t.fields].sort((e,t)=>d0(e.field)-d0(t.field))[0];return r===void 0?void 0:{field:r.field,hint:kde(e,r)}}function Ode(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),jN(e)&&n.shortsMusic!==void 0&&r.push(n.shortsMusic),MN(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 d0(e){let t=u0.length;for(let[n,r]of u0.entries())(e===r||e.startsWith(`${r}.`))&&n<t&&(t=n);return t}function kde(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 l0(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 the research notes 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 f0(e,t,n){if(n!==``)return e.find(e=>e.kind===t&&e.name===n)?.body}function p0(e,t,n){if(n!==``)return e.find(e=>e.category===t&&e.name===n)?.body}function m0(e,t){t!==void 0&&e.push(t)}function h0(e){let t=new Map,n=(e,n)=>{if(e)for(let r of dq(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`),uj(r)&&n(f0(i,`narration`,r.narrationPrompt??``),`Narration Preparation`),r.sources.article===`generate`&&n(f0(i,l0(r),r.articlePrompt),`Article`),r.sources.images===`generate`){for(let e of r.imagePrompts)n(f0(i,`image`,e.name),`Image: ${e.name}`);r.reference?.source===`prompt`&&n(f0(i,`image`,r.reference.prompt),`Establishing image`)}if((r.sources.thumbnail===`from_prompt`||r.sources.thumbnail===`prompt_by_llm`)&&n(f0(i,`thumbnail`,r.thumbnailPrompt),`Thumbnail`),r.sources.audio===`generate`)for(let e of[`intro`,`outro`])n(p0(a,e,r[e]),e===`intro`?`Intro`:`Outro`);return pj(r)&&n(f0(i,`description`,r.descriptionPrompt??``),`YouTube description`),jN(r)&&(n(f0(i,`shorts`,r.shorts?.prompt??``),`Shorts`),n(f0(i,`image`,r.shorts?.imagePrompt??``),`Shorts images`)),t}function g0(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 _0({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=g0;return t===void 0?(0,h.jsx)(pU,{label:`Keywords`,children:e.map(e=>(0,h.jsx)(mU,{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)(xV,{label:a(e.name),tip:s,help:l(e),error:n?.(`${r}.${e.name}`),children:(0,h.jsx)(CV,{"data-play-field":`${r}.${e.name}`,value:e.value,maxLength:c,...o===void 0?{}:{"aria-label":o(e.name)},spellCheck:!1,"aria-invalid":n?.(`${r}.${e.name}`)!==void 0,onChange:n=>t(e.name,n.target.value)})},e.name))})}var v0={lines:`One per line`,table:`Table`,yaml:`YAML / JSON`};function y0(e){return{mode:`lines`,rows:e,lines:Eq(e),base:e,yaml:``,columns:b0(e,[])}}function b0(e,t){return[...new Set([...t,...e.flatMap(e=>Object.keys(e.values))])]}function x0(e){return e.keywords.filter(t=>t!==e.topicKeyword&&(e.everyRun[t]??``).trim()===``)}function S0(e,t){if(t.form===void 0)return{rows:e.rows,problems:[]};if(e.mode===`yaml`){let n=Dq(e.yaml,{keywords:t.keywords,topicKeyword:t.topicKeyword,required:x0(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:Cq(n,{keywords:t.keywords,topicKeyword:t.topicKeyword,...e.mode===`table`?{required:x0(t)}:{},kept:t.kept})}}function Ade(e,t,n){if(t===e.mode)return{queue:e,problems:[]};let r=e.rows;if(e.mode===`yaml`){let t=Dq(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`?Eq(r):e.lines,base:t===`lines`?r:e.base,yaml:t===`yaml`?Oq(r,n.topicKeyword):e.yaml,columns:b0(r,e.columns)},problems:[]}}function jde({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=S0(e,n),y=e.mode===`yaml`?v.rows:e.rows,b=e=>p===void 0?void 0:yq(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=()=>Oq(S0(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=(n,r)=>t({...e,rows:e.rows.map((e,t)=>t===n?r:e)}),O=d.filter(t=>t!==f&&!e.columns.includes(t)),k=[...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)(V,{id:`planning.schedule.topics`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(Ab,{label:`How to write the topics`,tip:`planning.schedule.topic-format`,value:e.mode,options:Object.keys(v0).map(e=>({value:e,label:v0[e]})),onChange:r=>{let i=Ade(e,r,n);c(i.problems),t(i.queue)}}),(0,h.jsxs)(R,{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)(gc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Copy as YAML`]}),(0,h.jsxs)(R,{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)(_c,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Export as YAML`]}),l===null?null:(0,h.jsx)(`span`,{role:`status`,className:`text-small text-ink-2`,children:l})]}),e.mode===`lines`?(0,h.jsx)(xV,{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)(wV,{rows:6,value:e.lines,onChange:n=>t({...e,lines:n.target.value,rows:Tq(n.target.value,e.base)}),placeholder:`Pyramids
268
+ 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),Zq=X.default.BigInt(0),Qq=X.default.BigInt(1),$q=X.default.BigInt(2),eJ=X.default.BigInt(10),tJ=X.default.BigInt(24),nJ=X.default.BigInt(60),rJ=X.default.BigInt(1e3),iJ=X.default.BigInt(1e6),aJ=X.default.BigInt(1e9),oJ=X.default.multiply(X.default.BigInt(3600),aJ),sJ=X.default.multiply(nJ,aJ),cJ=X.default.multiply(oJ,tJ);function lJ(e){return typeof e==`bigint`?X.default.BigInt(e.toString(10)):e}function uJ(e){return X.default.equal(X.default.remainder(e,$q),Zq)}function dJ(e){return X.default.lessThan(e,Zq)?X.default.unaryMinus(e):e}function fJ(e,t){return X.default.lessThan(e,t)?-1:+!!X.default.greaterThan(e,t)}function pJ(e,t){return{quotient:X.default.divide(e,t),remainder:X.default.remainder(e,t)}}var mJ,hJ,gJ=`slot-epochNanoSeconds`,_J=`slot-iso-date`,vJ=`slot-iso-date-time`,yJ=`slot-time`,Z=`slot-calendar`,bJ=`slot-date-brand`,xJ=`slot-year-month-brand`,SJ=`slot-month-day-brand`,CJ=`slot-time-zone`,wJ=`slot-years`,TJ=`slot-months`,EJ=`slot-weeks`,DJ=`slot-days`,OJ=`slot-hours`,kJ=`slot-minutes`,AJ=`slot-seconds`,jJ=`slot-milliseconds`,MJ=`slot-microseconds`,NJ=`slot-nanoseconds`,PJ=`date`,FJ=`ym`,IJ=`md`,LJ=`time`,RJ=`datetime`,zJ=`instant`,BJ=`original`,VJ=`timezone-canonical`,HJ=`timezone-original`,UJ=`calendar-id`,WJ=`locale`,GJ=`options`,KJ=new WeakMap,qJ=Symbol.for(`@@Temporal__GetSlots`);(mJ=globalThis)[qJ]||(mJ[qJ]=function(e){return KJ.get(e)});var JJ=globalThis[qJ],YJ=Symbol.for(`@@Temporal__CreateSlots`);(hJ=globalThis)[YJ]||(hJ[YJ]=function(e){KJ.set(e,Object.create(null))});var XJ=globalThis[YJ];function ZJ(e,...t){if(!e||typeof e!=`object`)return!1;let n=JJ(e);return!!n&&t.every((e=>e in n))}function Q(e,t){let n=JJ(e)?.[t];if(n===void 0)throw TypeError(`Missing internal slot ${t}`);return n}function QJ(e,t,n){let r=JJ(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 $J={};function eY(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))}tY(t,e),tY(`${t}.prototype`,e.prototype)}function tY(e,t){let n=`%${e}%`;if($J[n]!==void 0)throw Error(`intrinsic ${e} already exists`);$J[n]=t}function nY(e){return $J[e]}function rY(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 iY(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 aY(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 oY(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 sY=class e{constructor(e){this.totalNs=lJ(e),this.sec=X.default.toNumber(X.default.divide(this.totalNs,aJ)),this.subsec=X.default.toNumber(X.default.remainder(this.totalNs,aJ))}static validateNew(t,n){if(X.default.greaterThan(dJ(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=X.default.subtract(lJ(t),lJ(n));return new e(r)}static fromComponents(t,n,r,i,a,o){let s=X.default.add(X.default.add(X.default.add(X.default.add(X.default.add(X.default.BigInt(o),X.default.multiply(X.default.BigInt(a),rJ)),X.default.multiply(X.default.BigInt(i),iJ)),X.default.multiply(X.default.BigInt(r),aJ)),X.default.multiply(X.default.BigInt(n),sJ)),X.default.multiply(X.default.BigInt(t),oJ));return e.validateNew(s,`total`)}abs(){return new e(dJ(this.totalNs))}add(t){return e.validateNew(X.default.add(this.totalNs,t.totalNs),`sum`)}add24HourDays(t){return e.validateNew(X.default.add(this.totalNs,X.default.multiply(X.default.BigInt(t),cJ)),`sum`)}addToEpochNs(e){return X.default.add(lJ(e),this.totalNs)}cmp(e){return fJ(this.totalNs,e.totalNs)}divmod(t){let{quotient:n,remainder:r}=pJ(this.totalNs,X.default.BigInt(t));return{quotient:X.default.toNumber(n),remainder:new e(r)}}fdiv(e){let t=lJ(e),n=X.default.BigInt(t),{quotient:r,remainder:i}=pJ(this.totalNs,n),a=[],o,s=(X.default.lessThan(this.totalNs,Zq)?-1:1)*Math.sign(X.default.toNumber(t));for(;!X.default.equal(i,Zq)&&a.length<50;)i=X.default.multiply(i,eJ),{quotient:o,remainder:i}=pJ(i,n),a.push(Math.abs(X.default.toNumber(o)));return s*Number(dJ(r).toString()+`.`+a.join(``))}isZero(){return X.default.equal(this.totalNs,Zq)}round(t,n){let r=lJ(t);if(X.default.equal(r,Qq))return this;let{quotient:i,remainder:a}=pJ(this.totalNs,r),o=X.default.lessThan(this.totalNs,Zq)?`negative`:`positive`,s=X.default.multiply(dJ(i),r),c=X.default.add(s,r),l=fJ(dJ(X.default.multiply(a,$q)),r),u=aY(n,o),d=X.default.equal(dJ(this.totalNs),s)?s:oY(s,c,l,uJ(i),u),f=o===`positive`?d:X.default.unaryMinus(d);return e.validateNew(f,`rounding`)}sign(){return this.cmp(new e(Zq))}subtract(t){return e.validateNew(X.default.subtract(this.totalNs,t.totalNs),`difference`)}};sY.MAX=X.default.BigInt(`9007199254740991999999999`),sY.ZERO=new sY(Zq);var cY=/[A-Za-z._][A-Za-z._0-9+-]*/,lY=RegExp(`(?:(?:[+-](?:[01][0-9]|2[0-3])(?::?[0-5][0-9])?)|(?:${cY.source})(?:\\/(?:${cY.source}))*)`),uY=/(?:[+-]\d{6}|\d{4})/,dY=/(?:0[1-9]|1[0-2])/,fY=/(?:0[1-9]|[12]\d|3[01])/,pY=RegExp(`(${uY.source})(?:-(${dY.source})-(${fY.source})|(${dY.source})(${fY.source}))`),mY=/(\d{2})(?::(\d{2})(?::(\d{2})(?:[.,](\d{1,9}))?)?|(\d{2})(?:(\d{2})(?:[.,](\d{1,9}))?)?)?/,hY=/((?:[+-])(?:[01][0-9]|2[0-3])(?::?(?:[0-5][0-9])(?::?(?:[0-5][0-9])(?:[.,](?:\d{1,9}))?)?)?)/,gY=RegExp(`([zZ])|${hY.source}?`),_Y=/\[(!)?([a-z_][a-z0-9_-]*)=([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)\]/g,vY=new RegExp([`^${pY.source}`,`(?:(?:[tT]|\\s+)${mY.source}(?:${gY.source})?)?`,`(?:\\[!?(${lY.source})\\])?`,`((?:${_Y.source})*)$`].join(``)),yY=new RegExp([`^[tT]?${mY.source}`,`(?:${gY.source})?`,`(?:\\[!?${lY.source}\\])?`,`((?:${_Y.source})*)$`].join(``)),bY=RegExp(`^(${uY.source})-?(${dY.source})(?:\\[!?${lY.source}\\])?((?:${_Y.source})*)$`),xY=RegExp(`^(?:--)?(${dY.source})-?(${fY.source})(?:\\[!?${lY.source}\\])?((?:${_Y.source})*)$`),SY=/(\d+)(?:[.,](\d{1,9}))?/,CY=RegExp(`(?:${SY.source}H)?(?:${SY.source}M)?(?:${SY.source}S)?`),wY=RegExp(`^([+-])?P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?!$)${CY.source})?$`,`i`),TY=864e5,EY=1e6*TY,DY=6e10,OY=1e8*TY,kY=D$(OY),AY=X.default.unaryMinus(kY),jY=X.default.add(X.default.subtract(AY,cJ),Qq),MY=X.default.subtract(X.default.add(kY,cJ),Qq),NY=146097*TY,PY=-271821,FY=275760,IY=Date.UTC(1847,0,1),LY=[`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`],RY=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 zY(e){return typeof e==`object`&&!!e||typeof e==`function`}function BY(e){if(typeof e==`bigint`)throw TypeError(`Cannot convert BigInt to number`);return Number(e)}function VY(e){if(typeof e==`symbol`)throw TypeError(`Cannot convert a Symbol value to a String`);return String(e)}function HY(e){let t=BY(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 UY(e,t){let n=HY(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 WY(e){let t=BY(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 GY(e,t){return String(e).padStart(t,`0`)}function KY(e){if(typeof e!=`string`)throw TypeError(`expected a string, not ${String(e)}`);return e}function qY(e,t){if(zY(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 JY=[`era`,`eraYear`,`year`,`month`,`monthCode`,`day`,`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],YY={era:VY,eraYear:HY,year:HY,month:UY,monthCode:function(e){let t=KY(qY(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:UY,hour:HY,minute:HY,second:HY,millisecond:HY,microsecond:HY,nanosecond:HY,offset:function(e){let t=KY(qY(e));return eQ(t),t},timeZone:MZ},XY={hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},ZY=[[`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`]],QY=Object.fromEntries(ZY.map((e=>[e[0],e[1]]))),$Y=Object.fromEntries(ZY.map((([e,t])=>[t,e]))),eX=ZY.map((([,e])=>e)),tX={day:EY,hour:36e11,minute:6e10,second:1e9,millisecond:1e6,microsecond:1e3,nanosecond:1},nX=[`days`,`hours`,`microseconds`,`milliseconds`,`minutes`,`months`,`nanoseconds`,`seconds`,`weeks`,`years`],rX=Intl.DateTimeFormat,iX=new Map;function aX(e){let t=I$(e),n=iX.get(t);return n===void 0&&(n=new rX(`en-us`,{timeZone:t,hour12:!1,era:`short`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`}),iX.set(t,n)),n}function oX(e){return ZJ(e,gJ)&&!ZJ(e,CJ,Z)}function sX(e){return ZJ(e,wJ,TJ,DJ,OJ,kJ,AJ,jJ,MJ,NJ)}function cX(e){return ZJ(e,bJ)}function lX(e){return ZJ(e,yJ)}function uX(e){return ZJ(e,vJ)}function dX(e){return ZJ(e,xJ)}function fX(e){return ZJ(e,SJ)}function pX(e){return ZJ(e,gJ,CJ,Z)}function $(e,t){if(!t(e))throw TypeError(`invalid receiver: method called with the wrong type of this-object`)}function mX(e){if(ZJ(e,Z)||ZJ(e,CJ))throw TypeError(`with() does not support a calendar or timeZone property`);if(lX(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 hX(e,t){return t===`never`||t===`auto`&&e===`iso8601`?``:`[${t===`critical`?`!`:``}u-ca=${e}]`}function gX(e){let t,n,r=!1;for(_Y.lastIndex=0;n=_Y.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 _X(e){let t=vY.exec(e);if(!t)throw RangeError(`invalid RFC 9557 string: ${e}`);let n=gX(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 jQ(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 vX(e){let t=yY.exec(e),n,r,i,a,o,s,c;if(t){c=gX(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}=_X(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(AQ(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}=bX(e);OQ(1972,t,n)}catch{try{let{year:t,month:n}=yX(e);OQ(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 yX(e){let t=bY.exec(e),n,r,i,a;if(t){i=gX(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}=_X(e),t)throw RangeError(`Z designator not supported for PlainYearMonth`)}return{year:n,month:r,calendar:i,referenceISODay:a}}function bX(e){let t=xY.exec(e),n,r,i,a;if(t){if(i=gX(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}=_X(e),t)throw RangeError(`Z designator not supported for PlainMonthDay`)}return{month:n,day:r,calendar:i,referenceISOYear:a}}var xX=RegExp(`^${lY.source}$`,`i`),SX=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])?)?$`);function CX(e){let t=R$.test(e)?`Seconds not allowed in offset time zone`:`Invalid time zone`;throw RangeError(`${t}: ${e}`)}function wX(e){return xX.test(e)||CX(e),SX.test(e)?{offsetMinutes:eQ(e)/6e10}:{tzName:e}}function TX(e,t,n,r){let i=e,a=t,o=n;switch(r){case`reject`:OQ(i,a,o);break;case`constrain`:({year:i,month:a,day:o}=EQ(i,a,o))}return{year:i,month:a,day:o}}function EX(e,t,n,r,i,a,o){let s=e,c=t,l=n,u=r,d=i,f=a;switch(o){case`reject`:AQ(s,c,l,u,d,f);break;case`constrain`:s=TQ(s,0,23),c=TQ(c,0,59),l=TQ(l,0,59),u=TQ(u,0,999),d=TQ(d,0,999),f=TQ(f,0,999)}return{hour:s,minute:c,second:l,millisecond:u,microsecond:d,nanosecond:f}}function DX(e){if(!zY(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<nX.length;r++){let i=nX[r],a=e[i];a!==void 0&&(n=!0,t[i]=WY(a))}if(!n)throw TypeError(`invalid duration-like`);return t}function OX({years:e,months:t,weeks:n,days:r},i,a,o){return{years:e,months:o??t,weeks:a??n,days:i??r}}function kX(e,t){return{isoDate:e,time:t}}function AX(e){return P$(e,`overflow`,[`constrain`,`reject`],`constrain`)}function jX(e){return P$(e,`disambiguation`,[`compatible`,`earlier`,`later`,`reject`],`compatible`)}function MX(e,t){return P$(e,`roundingMode`,[`ceil`,`floor`,`expand`,`trunc`,`halfCeil`,`halfFloor`,`halfExpand`,`halfTrunc`,`halfEven`],t)}function NX(e,t){return P$(e,`offset`,[`prefer`,`use`,`ignore`,`reject`],t)}function PX(e){return P$(e,`calendarName`,[`auto`,`always`,`never`,`critical`],`auto`)}function FX(e){let t=e.roundingIncrement;if(t===void 0)return 1;let n=HY(t);if(n<1||n>1e9)throw RangeError(`roundingIncrement must be at least 1 and at most 1e9, not ${t}`);return n}function IX(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 LX(e){let t=e.fractionalSecondDigits;if(t===void 0)return`auto`;if(typeof t!=`number`){if(VY(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 RX(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 zX=Symbol(`~required~`);function BX(e,t,n,r,i=[]){let a=[];for(let e=0;e<ZY.length;e++){let t=ZY[e],r=t[1],i=t[2];n!==`datetime`&&n!==i||a.push(r)}a=a.concat(i);let o=r;o===zX?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=$Y[a[e]];t!==void 0&&s.push(t)}let c=P$(e,t,s,o);if(c===void 0&&r===zX)throw RangeError(`${t} is required`);return c&&c in QY?QY[c]:c}function VX(e){let t=e.relativeTo;if(t===void 0)return{};let n,r,i,a,o,s=`option`,c=!1;if(zY(t)){if(pX(t))return{zonedRelativeTo:t};if(cX(t))return{plainRelativeTo:t};if(uX(t))return{plainRelativeTo:lZ(Q(t,vJ).isoDate,Q(t,Z))};i=DZ(t);let e=YX(i,t,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],[]);({isoDate:n,time:r}=QX(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}=_X(KY(t)),e)a=MZ(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=F$(i),n={year:u,month:d,day:f}}return a===void 0?{plainRelativeTo:lZ(n,i)}:{zonedRelativeTo:xZ(oZ(n,r,s,s===`option`?eQ(o):0,a,`compatible`,`reject`,c),a,i)}}function HX(e){return Q(e,wJ)===0?Q(e,TJ)===0?Q(e,EJ)===0?Q(e,DJ)===0?Q(e,OJ)===0?Q(e,kJ)===0?Q(e,AJ)===0?Q(e,jJ)===0?Q(e,MJ)===0?`nanosecond`:`microsecond`:`millisecond`:`second`:`minute`:`hour`:`day`:`week`:`month`:`year`}function UX(e,t){return eX.indexOf(e)>eX.indexOf(t)?t:e}function WX(e){return e===`year`||e===`month`||e===`week`}function GX(e){return WX(e)||e===`day`?`date`:`time`}function KX(e){return nY(`%calendarImpl%`)(e)}function qX(e){return nY(`%calendarImpl%`)(Q(e,Z))}function JX(e,t,n=`date`){let r=Object.create(null),i=KX(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 YX(e,t,n,r,i){let a=KX(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,YY[n])(r);else if(i!==`partial`){if(i.includes(n))throw TypeError(`required property '${n}' missing or undefined`);s[n]=XY[n]}}if(i===`partial`&&!c)throw TypeError(`no supported properties found`);return s}function XX(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]=HY(s),r=!0)}if(!r)throw TypeError(`invalid time-like`);return i}function ZX(e,t){if(zY(e)){if(cX(e))return AX(M$(t)),lZ(Q(e,_J),Q(e,Z));if(pX(e)){let n=IZ(Q(e,CJ),Q(e,gJ));return AX(M$(t)),lZ(n.isoDate,Q(e,Z))}if(uX(e))return AX(M$(t)),lZ(Q(e,vJ).isoDate,Q(e,Z));let n=DZ(e);return lZ(kZ(n,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),AX(M$(t))),n)}let{year:n,month:r,day:i,calendar:a,z:o}=_X(KY(e));if(o)throw RangeError(`Z designator not supported for PlainDate`);return a||=`iso8601`,a=F$(a),AX(M$(t)),lZ({year:n,month:r,day:i},a)}function QX(e,t,n){return kX(kZ(e,t,n),EX(t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond,n))}function $X(e,t){let n,r,i;if(zY(e)){if(uX(e))return AX(M$(t)),dZ(Q(e,vJ),Q(e,Z));if(pX(e)){let n=IZ(Q(e,CJ),Q(e,gJ));return AX(M$(t)),dZ(n,Q(e,Z))}if(cX(e))return AX(M$(t)),dZ(kX(Q(e,_J),{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Q(e,Z));i=DZ(e);let a=YX(i,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],[]),o=AX(M$(t));({isoDate:n,time:r}=QX(i,a,o))}else{let a,o,s,c;if({year:o,month:s,day:c,time:r,calendar:i,z:a}=_X(KY(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}),jQ(o,s,c,r.hour,r.minute,r.second,r.millisecond,r.microsecond,r.nanosecond),i||=`iso8601`,i=F$(i),AX(M$(t)),n={year:o,month:s,day:c}}return dZ(kX(n,r),i)}function eZ(e){let t=nY(`%Temporal.Duration%`);if(sX(e))return new t(Q(e,wJ),Q(e,TJ),Q(e,EJ),Q(e,DJ),Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ));if(!zY(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=wY.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:HY(t[2])*n,i=t[3]===void 0?0:HY(t[3])*n,a=t[4]===void 0?0:HY(t[4])*n,o=t[5]===void 0?0:HY(t[5])*n,s=t[6]===void 0?0:HY(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*HY((c+`000000000`).slice(0,9))*n}else if(p=l===void 0?0:HY(l)*n,u!==void 0){if(d??f)throw RangeError(`only the smallest unit can be fractional`);h=60*HY((u+`000000000`).slice(0,9))*n}else m=d===void 0?0:HY(d)*n,f!==void 0&&(h=HY((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),IQ(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(nY(`%Temporal.Duration%`))(t,n,r,i,a,o,s,c,l,u)}(KY(e));let n={years:0,months:0,weeks:0,days:0,hours:0,minutes:0,seconds:0,milliseconds:0,microseconds:0,nanoseconds:0},r=DX(e);for(let e=0;e<nX.length;e++){let t=nX[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 tZ(e){let t;if(zY(e)){if(oX(e)||pX(e))return yZ(Q(e,gJ));t=qY(e)}else t=e;let{year:n,month:r,day:i,time:a,offset:o,z:s}=function(e){let t=_X(e);if(!t.z&&!t.offset)throw RangeError(`Temporal.Instant requires a time zone offset`);return t}(KY(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=xQ(n,r,i,c,l,u,d,f,p-(s?0:eQ(o)));return UQ(m.isoDate),yZ(lQ(m))}function nZ(e,t){if(zY(e)){if(fX(e))return AX(M$(t)),pZ(Q(e,_J),Q(e,Z));let n;return ZJ(e,Z)?n=Q(e,Z):(n=e.calendar,n===void 0&&(n=`iso8601`),n=EZ(n)),pZ(jZ(n,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),AX(M$(t))),n)}let{month:n,day:r,referenceISOYear:i,calendar:a}=bX(KY(e));if(a===void 0&&(a=`iso8601`),a=F$(a),AX(M$(t)),a===`iso8601`)return pZ({year:1972,month:n,day:r},a);let o={year:i,month:n,day:r};return kQ(o),o=jZ(a,JX(a,o,`month-day`),`constrain`),pZ(o,a)}function rZ(e,t){let n;if(zY(e)){if(lX(e))return AX(M$(t)),hZ(Q(e,yJ));if(uX(e))return AX(M$(t)),hZ(Q(e,vJ).time);if(pX(e)){let n=IZ(Q(e,CJ),Q(e,gJ));return AX(M$(t)),hZ(n.time)}let{hour:r,minute:i,second:a,millisecond:o,microsecond:s,nanosecond:c}=XX(e);n=EX(r,i,a,o,s,c,AX(M$(t)))}else n=vX(KY(e)),AX(M$(t));return hZ(n)}function iZ(e){return e===void 0?{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}:Q(rZ(e),yJ)}function aZ(e,t){if(zY(e)){if(dX(e))return AX(M$(t)),_Z(Q(e,_J),Q(e,Z));let n=DZ(e);return _Z(AZ(n,YX(n,e,[`year`,`month`,`monthCode`],[],[]),AX(M$(t))),n)}let{year:n,month:r,referenceISODay:i,calendar:a}=yX(KY(e));a===void 0&&(a=`iso8601`),a=F$(a),AX(M$(t));let o={year:n,month:r,day:i};return FQ(o),o=AZ(a,JX(a,o,`year-month`),`constrain`),_Z(o,a)}function oZ(e,t,n,r,i,a,o,s){if(t===`start-of-day`)return BZ(i,e);let c=kX(e,t);if(n===`wall`||o===`ignore`)return LZ(i,c,a);if(n===`exact`||o===`use`){let n=xQ(e.year,e.month,e.day,t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond-r);UQ(n.isoDate);let i=lQ(n);return PQ(i),i}UQ(e);let l=lQ(c),u=zZ(i,c);for(let e=0;e<u.length;e++){let t=u[e],n=X.default.toNumber(X.default.subtract(l,t)),i=g$(n,6e10,`halfExpand`);if(n===r||s&&i===r)return t}if(o===`reject`){let e=FZ(r),t=YZ(c,`iso8601`,`auto`);throw RangeError(`Offset ${e} is invalid for ${t} in ${i}`)}return RZ(u,i,c,a)}function sZ(e,t){let n,r,i,a,o,s,c,l=!1,u=`option`;if(zY(e)){if(pX(e)){let n=M$(t);return jX(n),NX(n,`reject`),AX(n),xZ(Q(e,gJ),Q(e,CJ),Q(e,Z))}o=DZ(e);let l=YX(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=M$(t);s=jX(d),c=NX(d,`reject`);let f=AX(d);({isoDate:n,time:r}=QX(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=_X(e);if(!t.tzAnnotation)throw RangeError(`Temporal.ZonedDateTime requires a time zone ID in brackets`);return t}(KY(e))),i=MZ(d),f?u=`exact`:a||(u=`wall`),o||=`iso8601`,o=F$(o),l=!0;let g=M$(t);s=jX(g),c=NX(g,`reject`),AX(g),n={year:p,month:m,day:h}}let d=0;return u===`option`&&(d=eQ(a)),xZ(oZ(n,r,u,d,i,s,c,l),i,o)}function cZ(e,t,n){kQ(t),XJ(e),QJ(e,_J,t),QJ(e,Z,n),QJ(e,bJ,!0)}function lZ(e,t){let n=nY(`%Temporal.PlainDate%`),r=Object.create(n.prototype);return cZ(r,e,t),r}function uZ(e,t,n){MQ(t),XJ(e),QJ(e,vJ,t),QJ(e,Z,n)}function dZ(e,t){let n=nY(`%Temporal.PlainDateTime%`),r=Object.create(n.prototype);return uZ(r,e,t),r}function fZ(e,t,n){kQ(t),XJ(e),QJ(e,_J,t),QJ(e,Z,n),QJ(e,SJ,!0)}function pZ(e,t){let n=nY(`%Temporal.PlainMonthDay%`),r=Object.create(n.prototype);return fZ(r,e,t),r}function mZ(e,t){XJ(e),QJ(e,yJ,t)}function hZ(e){let t=nY(`%Temporal.PlainTime%`),n=Object.create(t.prototype);return mZ(n,e),n}function gZ(e,t,n){FQ(t),XJ(e),QJ(e,_J,t),QJ(e,Z,n),QJ(e,xJ,!0)}function _Z(e,t){let n=nY(`%Temporal.PlainYearMonth%`),r=Object.create(n.prototype);return gZ(r,e,t),r}function vZ(e,t){PQ(t),XJ(e),QJ(e,gJ,t)}function yZ(e){let t=nY(`%Temporal.Instant%`),n=Object.create(t.prototype);return vZ(n,e),n}function bZ(e,t,n,r){PQ(t),XJ(e),QJ(e,gJ,t),QJ(e,CJ,n),QJ(e,Z,r)}function xZ(e,t,n=`iso8601`){let r=nY(`%Temporal.ZonedDateTime%`),i=Object.create(r.prototype);return bZ(i,e,t,n),i}function SZ(e){return JY.filter((t=>e[t]!==void 0))}function CZ(e,t,n){let r=SZ(n),i=KX(e).fieldKeysToIgnore(r),a=Object.create(null),o=SZ(t);for(let e=0;e<JY.length;e++){let s,c=JY[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 wZ(e,t,n,r){let i=KX(e).dateAdd(t,n,r);return kQ(i),i}function TZ(e,t,n,r){return KX(e).dateUntil(t,n,r)}function EZ(e){if(zY(e)&&ZJ(e,Z))return Q(e,Z);let t=KY(e);try{return F$(t)}catch{}let n;try{({calendar:n}=_X(t))}catch{try{({calendar:n}=vX(t))}catch{try{({calendar:n}=yX(t))}catch{({calendar:n}=bX(t))}}}return n||=`iso8601`,F$(n)}function DZ(e){if(ZJ(e,Z))return Q(e,Z);let{calendar:t}=e;return t===void 0?`iso8601`:EZ(t)}function OZ(e,t){return F$(e)===F$(t)}function kZ(e,t,n){let r=KX(e);r.resolveFields(t,`date`);let i=r.dateToISO(t,n);return kQ(i),i}function AZ(e,t,n){let r=KX(e);r.resolveFields(t,`year-month`),t.day=1;let i=r.dateToISO(t,n);return FQ(i),i}function jZ(e,t,n){let r=KX(e);r.resolveFields(t,`month-day`);let i=r.monthDayToISOReferenceDate(t,n);return kQ(i),i}function MZ(e){if(zY(e)&&pX(e))return Q(e,CJ);let t=KY(e);if(t===`UTC`)return`UTC`;let{tzName:n,offsetMinutes:r}=function(e){let{tzAnnotation:t,offset:n,z:r}=function(e){if(xX.test(e))return{tzAnnotation:e,offset:void 0,z:!1};try{let{tzAnnotation:t,offset:n,z:r}=_X(e);if(r||t||n)return{tzAnnotation:t,offset:n,z:r}}catch{}CX(e)}(e);return t?wX(t):r?wX(`UTC`):n?wX(n):void 0}(t);if(r!==void 0)return oQ(r);let i=rQ(n);if(!i)throw RangeError(`Unrecognized time zone ${n}`);return i.identifier}function NZ(e,t){if(e===t)return!0;let n=wX(e).offsetMinutes,r=wX(t).offsetMinutes;if(n===void 0&&r===void 0){let n=rQ(t);if(!n)return!1;let r=rQ(e);return!!r&&r.primaryIdentifier===n.primaryIdentifier}return n===r}function PZ(e,t){let n=wX(e).offsetMinutes;return n===void 0?aQ(e,t):6e10*n}function FZ(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}${WZ(r,i,a,o,a===0&&o===0?`minute`:`auto`)}`}function IZ(e,t){let n=PZ(e,t),{isoDate:{year:r,month:i,day:a},time:{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d}}=uQ(t);return xQ(r,i,a,o,s,c,l,u,d+n)}function LZ(e,t,n){return RZ(zZ(e,t),e,t,n)}function RZ(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=lQ(n),o=X.default.subtract(a,cJ);PQ(o);let s=PZ(t,o),c=X.default.add(a,cJ);PQ(c);let l=PZ(t,c)-s;switch(r){case`earlier`:{let e=sY.fromComponents(0,0,0,0,0,-l),r=o$(n.time,e);return zZ(t,kX(bQ(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r))[0]}case`compatible`:case`later`:{let e=sY.fromComponents(0,0,0,0,0,l),r=o$(n.time,e),i=zZ(t,kX(bQ(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r));return i[i.length-1]}}}function zZ(e,t){if(e===`UTC`)return UQ(t.isoDate),[lQ(t)];let n=wX(e).offsetMinutes;if(n!==void 0){let e=xQ(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);UQ(e.isoDate);let r=lQ(e);return PQ(r),[r]}return UQ(t.isoDate),function(e,t){let n=lQ(t),r=X.default.subtract(n,cJ);X.default.lessThan(r,AY)&&(r=n);let i=X.default.add(n,cJ);X.default.greaterThan(i,kY)&&(i=n);let a=aQ(e,r),o=aQ(e,i);return(a===o?[a]:[a,o]).map((r=>{let i=X.default.subtract(n,X.default.BigInt(r));if(w$(t,function(e,t){let{epochMilliseconds:n,time:{millisecond:r,microsecond:i,nanosecond:a}}=uQ(t),{year:o,month:s,day:c,hour:l,minute:u,second:d}=pQ(e,n);return xQ(o,s,c,l,u,d,r,i,a)}(e,i))===0)return PQ(i),i})).filter((e=>e!==void 0))}(e,t)}function BZ(e,t){let n=kX(t,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),r=zZ(e,n);if(r.length)return r[0];let i=lQ(n),a=X.default.subtract(i,cJ);return PQ(a),dQ(e,a)}function VZ(e){let t;return t=e<0||e>9999?(e<0?`-`:`+`)+GY(Math.abs(e),6):GY(e,4),t}function HZ(e){return GY(e,2)}function UZ(e,t){let n;if(t===`auto`){if(e===0)return``;n=GY(e,9).replace(/0+$/,``)}else{if(t===0)return``;n=GY(e,9).slice(0,t)}return`.${n}`}function WZ(e,t,n,r,i){let a=`${HZ(e)}:${HZ(t)}`;return i===`minute`||(a+=`:${HZ(n)}`,a+=UZ(r,i)),a}function GZ(e,t,n){let r=t;r===void 0&&(r=`UTC`);let i=Q(e,gJ),a=YZ(IZ(r,i),`iso8601`,n,`never`),o=`Z`;return t!==void 0&&(o=sQ(PZ(r,i))),`${a}${o}`}function KZ(e,t){let n=Q(e,wJ),r=Q(e,TJ),i=Q(e,EJ),a=Q(e,DJ),o=Q(e,OJ),s=Q(e,kJ),c=gQ(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=sY.fromComponents(0,0,Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ));d.isZero()&&![`second`,`millisecond`,`microsecond`,`nanosecond`].includes(HX(e))&&t===`auto`||(u+=`${Math.abs(d.sec)}${UZ(Math.abs(d.subsec),t)}S`);let f=`${c<0?`-`:``}P${l}`;return u&&(f=`${f}T${u}`),f}function qZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,_J);return`${VZ(n)}-${HZ(r)}-${HZ(i)}${hX(Q(e,Z),t)}`}function JZ({hour:e,minute:t,second:n,millisecond:r,microsecond:i,nanosecond:a},o){return WZ(e,t,n,1e6*r+1e3*i+a,o)}function YZ(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`${VZ(i)}-${HZ(a)}-${HZ(o)}T${WZ(s,c,l,1e6*u+1e3*d+f,n)}${hX(t,r)}`}function XZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,_J),a=`${HZ(r)}-${HZ(i)}`,o=Q(e,Z);t!==`always`&&t!==`critical`&&o===`iso8601`||(a=`${VZ(n)}-${a}`);let s=hX(o,t);return s&&(a+=s),a}function ZZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,_J),a=`${VZ(n)}-${HZ(r)}`,o=Q(e,Z);t!==`always`&&t!==`critical`&&o===`iso8601`||(a+=`-${HZ(i)}`);let s=hX(o,t);return s&&(a+=s),a}function QZ(e,t,n=`auto`,r=`auto`,i=`auto`,a=void 0){let o=Q(e,gJ);if(a){let{unit:e,increment:t,roundingMode:n}=a;o=_$(o,t,e,n)}let s=Q(e,CJ),c=PZ(s,o),l=YZ(IZ(s,o),`iso8601`,t,`never`);return i!==`never`&&(l+=sQ(c)),r!==`never`&&(l+=`[${r===`critical`?`!`:``}${s}]`),l+=hX(Q(e,Z),n),l}function $Z(e){return SX.test(e)}function eQ(e){let t=z$.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 tQ,nQ=Object.assign(Object.create(null),{"/":!0,"-":!0,_:!0});function rQ(e){if(tQ===void 0){let e=Intl.supportedValuesOf?.(`timeZone`);if(e){tQ=new Map;for(let t=0;t<e.length;t++){let n=e[t];tQ.set(I$(n),n)}}else tQ=null}let t=I$(e),n=tQ?.get(t);if(n)return{identifier:n,primaryIdentifier:n};try{n=aX(e).resolvedOptions().timeZone}catch{return}if(t===`antarctica/south_pole`&&(n=`Antarctica/McMurdo`),RY.has(e))throw RangeError(`${e} is a legacy time zone identifier from ICU. Use ${n} instead`);let r=[...t].map(((e,n)=>n===0||nQ[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 iQ(e,t){let{year:n,month:r,day:i,hour:a,minute:o,second:s}=pQ(e,t),c=t%1e3;return c<0&&(c+=1e3),1e6*(cQ({isoDate:{year:n,month:r,day:i},time:{hour:a,minute:o,second:s,millisecond:c}})-t)}function aQ(e,t){return iQ(e,E$(t,`floor`))}function oQ(e){let t=e<0?`-`:`+`,n=Math.abs(e);return`${t}${WZ(Math.floor(n/60),n%60,0,0,`minute`)}`}function sQ(e){return oQ(g$(e,DY,`halfExpand`)/6e10)}function cQ({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()+NY*c}function lQ(e){let t=cQ(e),n=1e3*e.time.microsecond+e.time.nanosecond;return X.default.add(D$(t),X.default.BigInt(n))}function uQ(e){let t=E$(e,`trunc`),n=X.default.toNumber(X.default.remainder(e,iJ));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 dQ(e,t){if(e===`UTC`)return null;let n=E$(t,`floor`);if(n<IY)return dQ(e,D$(IY));let r=Math.max(n,Date.now())+366*TY*3,i=n,a=iQ(e,i),o=i,s=a;for(;a===s&&i<r;){if(o=i+2*TY*7,o>OY)return null;s=iQ(e,o),a===s&&(i=o)}return a===s?null:D$(B$((t=>iQ(e,t)),i,o,a,s))}function fQ(e,t){if(e===`UTC`)return null;let n=E$(t,`ceil`),r=Date.now(),i=r+366*TY*3;if(n>i){let t=fQ(e,D$(i));if(t===null||X.default.lessThan(t,D$(r)))return t}if(e===`Africa/Casablanca`||e===`Africa/El_Aaiun`){let t=Date.UTC(2088,0,1);if(t<n)return fQ(e,D$(t))}let a=n-1;if(a<IY)return null;let o=iQ(e,a),s=a,c=o;for(;o===c&&a>IY;){if(s=a-2*TY*7,s<IY)return null;c=iQ(e,s),o===c&&(a=s)}return o===c?null:D$(B$((t=>iQ(e,t)),s,a,c,o))}function pQ(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}}(aX(e).format(t))}function mQ(e){return e!==void 0&&!(e%4!=0||e%100==0&&e%400!=0)}function hQ(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]}[mQ(e)?`leapyear`:`standard`][t-1]}function gQ(e){let t=[Q(e,wJ),Q(e,TJ),Q(e,EJ),Q(e,DJ),Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ)];for(let e=0;e<t.length;e++){let n=t[e];if(n!==0)return n<0?-1:1}return 0}function _Q(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 vQ(e){let t=_Q(e.date);return t===0?e.time.sign():t}function yQ(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 bQ(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}=yQ(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=mQ(c)?366:365,a<-s;)--r,--c,a+=s;for(c+=1;s=mQ(c)?366:365,a>s;)r+=1,c+=1,a-=s;for(;a<1;)({year:r,month:i}=yQ(r,i-1)),a+=hQ(r,i);for(;a>hQ(r,i);)a-=hQ(r,i),{year:r,month:i}=yQ(r,i+1);return{year:r,month:i,day:a}}function xQ(e,t,n,r,i,a,o,s,c){let l=SQ(r,i,a,o,s,c);return kX(bQ(e,t,n+l.deltaDays),l)}function SQ(e,t,n,r,i,a){let o,s=e,c=t,l=n,u=r,d=i,f=a;({div:o,mod:f}=rY(f,3)),d+=o,f<0&&(--d,f+=1e3),{div:o,mod:d}=rY(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 CQ(e,t){let n=OX(e,0);if(_Q(n)===0)return e.days;let r=Q(t,_J),i=wZ(Q(t,Z),r,n,`constrain`),a=HQ(r.year,r.month-1,r.day),o=HQ(i.year,i.month-1,i.day)-a;return e.days+o}function wQ(e){return new(nY(`%Temporal.Duration%`))(-Q(e,wJ),-Q(e,TJ),-Q(e,EJ),-Q(e,DJ),-Q(e,OJ),-Q(e,kJ),-Q(e,AJ),-Q(e,jJ),-Q(e,MJ),-Q(e,NJ))}function TQ(e,t,n){return Math.min(n,Math.max(t,e))}function EQ(e,t,n){let r=TQ(t,1,12);return{year:e,month:r,day:TQ(n,1,hQ(e,r))}}function DQ(e,t,n){if(e<t||e>n)throw RangeError(`value out of range: ${t} <= ${e} <= ${n}`)}function OQ(e,t,n){DQ(t,1,12),DQ(n,1,hQ(e,t))}function kQ(e){MQ(kX(e,{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}))}function AQ(e,t,n,r,i,a){DQ(e,0,23),DQ(t,0,59),DQ(n,0,59),DQ(r,0,999),DQ(i,0,999),DQ(a,0,999)}function jQ(e,t,n,r,i,a,o,s,c){OQ(e,t,n),AQ(r,i,a,o,s,c)}function MQ(e){let t=lQ(e);(X.default.lessThan(t,jY)||X.default.greaterThan(t,MY))&&PQ(t)}function NQ(e){lQ(e)}function PQ(e){if(X.default.lessThan(e,AY)||X.default.greaterThan(e,kY))throw RangeError(`date/time value is outside of supported range`)}function FQ({year:e,month:t}){DQ(e,PY,FY),e===PY?DQ(t,4,12):e===FY&&DQ(t,1,9)}function IQ(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=rY(s,3),p=rY(c,6),m=rY(l,9),h=rY(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 LQ(e){return{date:{years:Q(e,wJ),months:Q(e,TJ),weeks:Q(e,EJ),days:Q(e,DJ)},time:sY.fromComponents(Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ))}}function RQ(e){let t=sY.fromComponents(Q(e,OJ),Q(e,kJ),Q(e,AJ),Q(e,jJ),Q(e,MJ),Q(e,NJ)).add24HourDays(Q(e,DJ));return{date:{years:Q(e,wJ),months:Q(e,TJ),weeks:Q(e,EJ),days:0},time:t}}function zQ(e){let t=RQ(e),n=Math.trunc(t.time.sec/86400);return IQ(t.date.years,t.date.months,t.date.weeks,n,0,0,0,0,0,0),{...t.date,days:n}}function BQ(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=iY(o,3,Math.trunc(i/1e3)),i%=1e3,o=0;break;case`microsecond`:i=iY(o,6,Math.trunc(r/1e3)),r%=1e3,o=0;break;case`nanosecond`:r=iY(o,9,r),o=0}return new(nY(`%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 VQ(e,t){return _Q(e),t.sign(),{date:e,time:t}}function HQ(e,t,n){return cQ({isoDate:{year:e,month:t+1,day:n},time:{hour:0,minute:0,second:0,millisecond:0}})/TY}function UQ({year:e,month:t,day:n}){if(Math.abs(HQ(e,t-1,n))>1e8)throw RangeError(`date/time value is outside the supported range`)}function WQ(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 sY.fromComponents(n,r,i,a,o,s)}function GQ(e,t,n,r,i){let a=sY.fromEpochNsDiff(t,e);return a=b$(a,n,r,i),VQ({years:0,months:0,weeks:0,days:0},a)}function KQ(e,t,n,r){NQ(e),NQ(t);let i=WQ(e.time,t.time),a=i.sign(),o=S$(e.isoDate,t.isoDate),s=t.isoDate;o===a&&(s=bQ(s.year,s.month,s.day+a),i=i.add24HourDays(-a));let c=UX(`day`,r),l=TZ(n,e.isoDate,s,c);return r!==c&&(i=i.add24HourDays(l.days),l.days=0),VQ(l,i)}function qQ(e,t,n,r,i){let a=X.default.subtract(t,e);if(X.default.equal(a,Zq))return{date:{years:0,months:0,weeks:0,days:0},time:sY.ZERO};let o=X.default.lessThan(a,Zq)?-1:1,s=IZ(n,e),c=IZ(n,t),l,u=0,d=o===1?2:1,f=WQ(s.time,c.time);for(f.sign()===-o&&u++;u<=d;u++){l=kX(bQ(c.isoDate.year,c.isoDate.month,c.isoDate.day-u*o),s.time);let e=LZ(n,l,`compatible`);if(f=sY.fromEpochNsDiff(t,e),f.sign()!==-o)break}let p=UX(`day`,i);return VQ(TZ(r,s.isoDate,l.isoDate,p),f)}function JQ(e,t,n,r,i,a,o,s,c){let l,u,d,f,p=t;switch(s){case`year`:{let t=g$(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=g$(p.date.months,o,`trunc`);l=t,u=t+o*e,d=OX(p.date,0,0,l),f=OX(p.date,0,0,u);break}case`week`:{let t=OX(p.date,0,0),n=wZ(a,r.isoDate,t,`constrain`),i=TZ(a,n,bQ(n.year,n.month,n.day+p.date.days),`week`),s=g$(p.date.weeks+i.weeks,o,`trunc`);l=s,u=s+o*e,d=OX(p.date,0,l),f=OX(p.date,0,u);break}case`day`:{let t=g$(p.date.days,o,`trunc`);l=t,u=t+o*e,d=OX(p.date,l),f=OX(p.date,u);break}}let m=wZ(a,r.isoDate,d,`constrain`),h=wZ(a,r.isoDate,f,`constrain`),g,_,v=kX(m,r.time),y=kX(h,r.time);i?(g=LZ(i,v,`compatible`),_=LZ(i,y,`compatible`)):(g=lQ(v),_=lQ(y));let b=sY.fromEpochNsDiff(n,g),x=sY.fromEpochNsDiff(_,g),S=aY(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)?oY(Math.abs(l),Math.abs(u),C,w,S):Math.abs(u),E=new sY(X.default.add(X.default.multiply(x.totalNs,X.default.BigInt(l)),X.default.multiply(b.totalNs,X.default.BigInt(o*e)))).fdiv(x.totalNs),D=T===Math.abs(u);return p={date:D?f:d,time:sY.ZERO},{nudgeResult:{duration:p,nudgedEpochNs:D?_:g,didExpandCalendarUnit:D},total:E}}function YQ(e,t,n,r,i,a,o,s,c){let l=e,u=WX(s)||r&&s===`day`,d=vQ(l)<0?-1:1,f;return u?{nudgeResult:f}=JQ(d,l,t,n,r,i,o,s,c):f=r?function(e,t,n,r,i,a,o,s){let c=t,l=wZ(i,n.isoDate,c.date,`constrain`),u=kX(l,n.time),d=kX(bQ(l.year,l.month,l.day+e),n.time),f=LZ(r,u,`compatible`),p=LZ(r,d,`compatible`),m=sY.fromEpochNsDiff(p,f);if(m.sign()!==e)throw RangeError(`time zone returned inconsistent Instants`);let h=X.default.BigInt(tX[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:VQ(OX(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(X.default.BigInt(r*tX[i]),a),l=c.subtract(s),{quotient:u}=s.divmod(EY),{quotient:d}=c.divmod(EY),f=Math.sign(d-u)===s.sign(),p=l.addToEpochNs(t),m=0,h=c;return GX(n)===`date`&&(m=d,h=c.add(sY.fromComponents(24*-d,0,0,0,0,0))),{duration:{date:OX(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=eX.indexOf(o);for(let t=eX.indexOf(s)-1;t>=l;t--){let s=eX[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=OX(c.date,0,0,t);break}case`week`:{let t=c.date.weeks+e;l=OX(c.date,0,t);break}}let u=kX(wZ(a,r.isoDate,l,`constrain`),r.time),d;if(d=i?LZ(i,u,`compatible`):lQ(u),fJ(n,d)===-e)break;c={date:l,time:sY.ZERO}}return c}(d,l,f.nudgedEpochNs,n,r,i,a,UX(s,`day`))),l}function XQ(e,t,n,r,i,a){return WX(a)||r&&a===`day`?JQ(vQ(e)<0?-1:1,e,t,n,r,i,1,a,`trunc`).total:x$(e.time.add24HourDays(e.date.days),a)}function ZQ(e,t,n,r,i,a,o){if(w$(e,t)==0)return{date:{years:0,months:0,weeks:0,days:0},time:sY.ZERO};MQ(e),MQ(t);let s=KQ(e,t,n,r);return a===`nanosecond`&&i===1?s:YQ(s,lQ(t),e,null,n,r,i,a,o)}function QQ(e,t,n,r,i,a,o,s){if(GX(i)===`time`)return GQ(e,t,a,o,s);let c=qQ(e,t,n,r,i);return o===`nanosecond`&&a===1?c:YQ(c,t,IZ(n,e),n,r,i,a,o,s)}function $Q(e,t,n,r,i,a){let o=ZY.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=BX(t,`largestUnit`,n,`auto`);if(r.includes(s))throw RangeError(`largestUnit must be one of ${o.join(`, `)}, not ${s}`);let c=FX(t),l=MX(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=BX(t,`smallestUnit`,n,i);if(r.includes(u))throw RangeError(`smallestUnit must be one of ${o.join(`, `)}, not ${u}`);let d=UX(a,u);if(s===`auto`&&(s=d),UX(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&&IX(c,f,!1),{largestUnit:s,roundingIncrement:c,roundingMode:l,smallestUnit:u}}function e$(e,t,n,r){let i=tZ(n),a=$Q(e,M$(r),`time`,[],`nanosecond`,`second`),o=BQ(GQ(Q(t,gJ),Q(i,gJ),a.roundingIncrement,a.smallestUnit,a.roundingMode),a.largestUnit);return e===`since`&&(o=wQ(o)),o}function t$(e,t,n,r){let i=ZX(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`date`,[],`day`,`day`),c=nY(`%Temporal.Duration%`),l=Q(t,_J),u=Q(i,_J);if(S$(l,u)===0)return new c;let d={date:TZ(a,l,u,s.largestUnit),time:sY.ZERO};if(s.smallestUnit!==`day`||s.roundingIncrement!==1){let e=kX(l,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});d=YQ(d,lQ(kX(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=BQ(d,`day`);return e===`since`&&(f=wQ(f)),f}function n$(e,t,n,r){let i=$X(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`datetime`,[],`nanosecond`,`day`),c=nY(`%Temporal.Duration%`),l=Q(t,vJ),u=Q(i,vJ);if(w$(l,u)===0)return new c;let d=BQ(ZQ(l,u,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);return e===`since`&&(d=wQ(d)),d}function r$(e,t,n,r){let i=rZ(n),a=$Q(e,M$(r),`time`,[],`nanosecond`,`hour`),o=WQ(Q(t,yJ),Q(i,yJ));o=b$(o,a.roundingIncrement,a.smallestUnit,a.roundingMode);let s=BQ(VQ({years:0,months:0,weeks:0,days:0},o),a.largestUnit);return e===`since`&&(s=wQ(s)),s}function i$(e,t,n,r){let i=aZ(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between months of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`date`,[`week`,`day`],`month`,`year`),c=nY(`%Temporal.Duration%`);if(S$(Q(t,_J),Q(i,_J))==0)return new c;let l=JX(a,Q(t,_J),`year-month`);l.day=1;let u=kZ(a,l,`constrain`),d=JX(a,Q(i,_J),`year-month`);d.day=1;let f=kZ(a,d,`constrain`),p={date:OX(TZ(a,u,f,s.largestUnit),0,0),time:sY.ZERO};if(s.smallestUnit!==`month`||s.roundingIncrement!==1){let e=kX(u,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});p=YQ(p,lQ(kX(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=BQ(p,`day`);return e===`since`&&(m=wQ(m)),m}function a$(e,t,n,r){let i=sZ(n),a=Q(t,Z),o=Q(i,Z);if(!OZ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=$Q(e,M$(r),`datetime`,[],`nanosecond`,`hour`),c=Q(t,gJ),l=Q(i,gJ),u=nY(`%Temporal.Duration%`),d;if(GX(s.largestUnit)!==`date`)d=BQ(GQ(c,l,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);else{let e=Q(t,CJ);if(!NZ(e,Q(i,CJ)))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(X.default.equal(c,l))return new u;d=BQ(QQ(c,l,e,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),`hour`)}return e===`since`&&(d=wQ(d)),d}function o$({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,SQ(e,t,s,r,i,c)}function s$(e,t){let n=t.addToEpochNs(e);return PQ(n),n}function c$(e,t,n,r,i=`constrain`){if(_Q(r.date)===0)return s$(e,r.time);let a=IZ(t,e);return s$(LZ(t,kX(wZ(n,a.isoDate,r.date,i),a.time),`compatible`),r.time)}function l$(e,t,n){let r=eZ(n);e===`subtract`&&(r=wQ(r));let i=UX(HX(t),HX(r));if(WX(i))throw RangeError(`For years, months, or weeks arithmetic, use date arithmetic relative to a starting point`);let a=RQ(t),o=RQ(r);return BQ(VQ({years:0,months:0,weeks:0,days:0},a.time.add(o.time)),i)}function u$(e,t,n){let r=eZ(n);e===`subtract`&&(r=wQ(r));let i=HX(r);if(GX(i)===`date`)throw RangeError(`Duration field ${i} not supported by Temporal.Instant. Try Temporal.ZonedDateTime instead.`);let a=RQ(r);return yZ(s$(Q(t,gJ),a.time))}function d$(e,t,n,r){let i=Q(t,Z),a=eZ(n);e===`subtract`&&(a=wQ(a));let o=zQ(a),s=AX(M$(r));return lZ(wZ(i,Q(t,_J),o,s),i)}function f$(e,t,n,r){let i=eZ(n);e===`subtract`&&(i=wQ(i));let a=AX(M$(r)),o=Q(t,Z),s=RQ(i),c=Q(t,vJ),l=o$(c.time,s.time),u=OX(s.date,l.deltaDays);return IQ(u.years,u.months,u.weeks,u.days,0,0,0,0,0,0),dZ(kX(wZ(o,c.isoDate,u,a),l),o)}function p$(e,t,n){let r=eZ(n);e===`subtract`&&(r=wQ(r));let i=RQ(r),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=o$(Q(t,yJ),i.time);return hZ(EX(a,o,s,c,l,u,`reject`))}function m$(e,t,n,r){let i=eZ(n);e===`subtract`&&(i=wQ(i));let a=AX(M$(r)),o=gQ(i),s=Q(t,Z),c=JX(s,Q(t,_J),`year-month`);c.day=1;let l=kZ(s,c,`constrain`);if(o<0){let e=wZ(s,l,{months:1},`constrain`);l=bQ(e.year,e.month,e.day-1)}let u=zQ(i);return kQ(l),_Z(AZ(s,JX(s,wZ(s,l,u,a),`year-month`),a),s)}function h$(e,t,n,r){let i=eZ(n);e===`subtract`&&(i=wQ(i));let a=AX(M$(r)),o=Q(t,CJ),s=Q(t,Z),c=LQ(i);return xZ(c$(Q(t,gJ),o,s,c,a),o,s)}function g$(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=j$(Math.abs(2*i)-t),l=o%2==0,u=aY(n,a),d=i===0?o:oY(o,s,c,l,u);return t*(a===`positive`?d:-d)}function _$(e,t,n,r){let i=tX[n]*t;return function(e,t,n){let r=lJ(e),i=lJ(t),a=X.default.divide(r,i),o=X.default.remainder(r,i),s=aY(n,`positive`),c,l;X.default.lessThan(r,Zq)?(c=X.default.subtract(a,Qq),l=a):(c=a,l=X.default.add(a,Qq));let u=fJ(dJ(X.default.multiply(o,$q)),i)*(X.default.lessThan(r,Zq)?-1:1)+0,d=X.default.equal(o,Zq)?a:oY(c,l,u,uJ(c),s);return X.default.multiply(d,i)}(e,X.default.BigInt(i),r)}function v$(e,t,n,r){NQ(e);let{year:i,month:a,day:o}=e.isoDate,s=y$(e.time,t,n,r);return kX(bQ(i,a,o+s.deltaDays),s)}function y$({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=tX[s],d=g$(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 SQ(d,0,0,0,0,0);case`minute`:return SQ(e,d,0,0,0,0);case`second`:return SQ(e,t,d,0,0,0);case`millisecond`:return SQ(e,t,n,d,0,0);case`microsecond`:return SQ(e,t,n,r,d,0);case`nanosecond`:return SQ(e,t,n,r,i,d);default:throw Error(`Invalid unit ${s}`)}}function b$(e,t,n,r){let i=tX[n];return e.round(X.default.BigInt(i*t),r)}function x$(e,t){let n=tX[t];return e.fdiv(X.default.BigInt(n))}function S$(e,t){return e.year===t.year?e.month===t.month?e.day===t.day?0:j$(e.day-t.day):j$(e.month-t.month):j$(e.year-t.year)}function C$(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:j$(e.nanosecond-t.nanosecond):j$(e.microsecond-t.microsecond):j$(e.millisecond-t.millisecond):j$(e.second-t.second):j$(e.minute-t.minute):j$(e.hour-t.hour)}function w$(e,t){let n=S$(e.isoDate,t.isoDate);return n===0?C$(e.time,t.time):n}function T$(e){let t=O$(e);return globalThis.BigInt===void 0?t:globalThis.BigInt(t.toString(10))}function E$(e,t){let{quotient:n,remainder:r}=pJ(lJ(e),iJ),i=X.default.toNumber(n);return t===`floor`&&X.default.toNumber(r)<0&&--i,t===`ceil`&&X.default.toNumber(r)>0&&(i+=1),i}function D$(e){if(!Number.isInteger(e))throw RangeError(`epoch milliseconds must be an integer`);return X.default.multiply(X.default.BigInt(e),iJ)}function O$(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`?X.default.BigInt(t.toString(10)):X.default.BigInt(t)}var k$=(()=>{let e=X.default.BigInt(Date.now()%1e6);return()=>{let t=Date.now(),n=X.default.BigInt(t),r=X.default.add(D$(t),e);return e=X.default.remainder(n,iJ),X.default.greaterThan(r,kY)?kY:X.default.lessThan(r,AY)?AY:r}})();function A$(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}function j$(e){return e<0?-1:e>0?1:e}function M$(e){if(e===void 0)return Object.create(null);if(zY(e)&&e!==null)return e;throw TypeError(`Options parameter must be an object, not `+(e===null?`null`:typeof e))}function N$(e,t){let n=Object.create(null);return n[e]=t,n}function P$(e,t,n,r){let i=e[t];if(i!==void 0){if(i=VY(i),!n.includes(i))throw RangeError(`${t} must be one of ${n.join(`, `)}, not ${i}`);return i}if(r===zX)throw RangeError(`${t} option is required`);return r}function F$(e){let t=I$(e);if(!LY.includes(I$(t)))throw RangeError(`invalid calendar identifier ${t}`);switch(t){case`ethiopic-amete-alem`:return`ethioaa`;case`islamicc`:return`islamic-civil`}return t}function I$(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 L$(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 R$=RegExp(`^${hY.source}$`),z$=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])(?::?([0-5][0-9])(?:[.,](\\d{1,9}))?)?)?$`);function B$(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 V$(e){return[...e]}function H$(e,t){if(e!==`gregory`&&e!==`iso8601`)return;let n=W$[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 U$(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 W$={};function G$(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 K$(e,t=!1){return`M${`${e}`.padStart(2,`0`)}${t?`L`:``}`}function q$(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`&&DQ(r,1,n),t===`constrain`&&(r=TQ(r,1,n)),i=K$(r)}else{let e=G$(i);if(i!==K$(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}}W$.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,q$(e))},dateToISO:(e,t)=>TX(e.year,e.month,e.day,t),monthDayToISOReferenceDate(e,t){let{month:n,day:r}=TX(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 V$(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}=yQ(o,s),{year:o,month:s,day:c}=TX(o,s,c,a),c+=i+7*r,bQ(o,s,c)},dateUntil(e,t,n){let r=-S$(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);!U$(r,e.year+s,e.month,e.day,t);)a=s,s+=r;let c=r;for(i=yQ(e.year+a,e.month+c);!U$(r,i.year,i.month,e.day,t);)o=c,c+=r,i=yQ(i.year,i.month+r);n===`month`&&(o+=12*a,a=0)}i=yQ(e.year+a,e.month+o);let s=EQ(i.year,i.month,e.day),c=0,l=HQ(t.year,t.month-1,t.day)-HQ(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=K$(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+=hQ(e,n);i.dayOfYear=r}return r.weekOfYear&&(i.weekOfYear=H$(`iso8601`,{year:e,month:t,day:n})),r.daysInMonth&&(i.daysInMonth=hQ(e,t)),(r.daysInYear||r.inLeapYear)&&(i.inLeapYear=mQ(e),i.daysInYear=i.inLeapYear?366:365),i},getFirstDayOfWeek:()=>1,getMinimalDaysInFirstWeek:()=>4};var J$=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 Y$({isoYear:e,isoMonth:t,isoDay:n}){return`${VZ(e)}-${HZ(t)}-${HZ(n)}T00:00Z`}function X$(e,t){return{years:e.year-t.year,months:e.month-t.month,days:e.day-t.day}}J$.objectMap=new WeakMap,J$.MAX_CACHE_ENTRIES=1e3;var Z$=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=Y$({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}=q$(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`?(DQ(i,1,r),DQ(a,1,this.maximumMonthLength(e))):(i=TQ(i,1,r),a=TQ(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=X$(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=X$(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=X$(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:j$(e.day-t.day):j$(e.month-t.month):j$(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 bQ(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 HQ(i.year,i.month-1,i.day)-HQ(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(){}},fue=class extends Z${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?K$(5,!0):K$(t<6?t:t-1):K$(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=G$(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`?(DQ(a,1,this.monthsInYear({year:i})),DQ(s,1,this.maximumMonthLength({year:i,month:a}))):(a=TQ(a,1,this.monthsInYear({year:i})),s=TQ(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}}},Q$=class extends Z${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}}},pue=class extends Q${constructor(){super(...arguments),this.id=`islamic`}},mue=class extends Q${constructor(){super(...arguments),this.id=`islamic-umalqura`}},hue=class extends Q${constructor(){super(...arguments),this.id=`islamic-tbla`}},gue=class extends Q${constructor(){super(...arguments),this.id=`islamic-civil`}},_ue=class extends Q${constructor(){super(...arguments),this.id=`islamic-rgsa`}},vue=class extends Q${constructor(){super(...arguments),this.id=`islamicc`}},yue=class extends Z${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 G$(e)<=6?31:30}estimateIsoDate(e){let{year:t}=this.adjustCalendarDate(e);return{year:t+621,month:1,day:1}}},bue=class extends Z${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 $$(e.year+78)}monthsInYear(){return 12}minimumMonthLength(e){return this.getMonthInfo(e).length}maximumMonthLength(e){return this.getMonthInfo(e).length}maxLengthOfMonthCodeInAnyYear(e){let t=G$(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 bQ(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 $$(e){return e%4==0&&(e%100!=0||e%400==0)}var e1=class extends Z${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 $$(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][G$(e)-1]}estimateIsoDate(e){let t=this.adjustCalendarDate(e);return TX(t.year+this.isoEpoch.year,t.month+this.isoEpoch.month,t.day+this.isoEpoch.day,`constrain`)}},t1=class extends Z${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 $$(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][G$(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:G$(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 TX(t+i.isoEpoch.year-+!i.hasYearZero,n,r,`constrain`)}},n1=class extends t1{constructor(e,t){super(e,t)}isoToCalendarDate(e){let{year:t,month:n,day:r}=e,i=K$(n),a=t-this.anchorEra.isoEpoch.year+1;return this.completeEraYear({year:a,month:n,monthCode:i,day:r})}},r1={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},xue=class extends e1{constructor(e,t){super(e,t),this.inLeapYear=r1.inLeapYear,this.monthsInYear=r1.monthsInYear,this.minimumMonthLength=r1.minimumMonthLength,this.maximumMonthLength=r1.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=r1.maxLengthOfMonthCodeInAnyYear}},i1=class extends t1{constructor(e,t){super(e,t),this.inLeapYear=r1.inLeapYear,this.monthsInYear=r1.monthsInYear,this.minimumMonthLength=r1.minimumMonthLength,this.maximumMonthLength=r1.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=r1.maxLengthOfMonthCodeInAnyYear}},Sue=class extends xue{constructor(){super(`ethioaa`,{year:-5492,month:7,day:17})}},Cue=class extends i1{constructor(){super(`coptic`,[{code:`coptic`,isoEpoch:{year:284,month:8,day:29}},{code:`coptic-inverse`,reverseOf:`coptic`}])}},wue=class extends i1{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}}])}},Tue=class extends n1{constructor(){super(`roc`,[{code:`roc`,names:[`minguo`],isoEpoch:{year:1912,month:1,day:1}},{code:`roc-inverse`,names:[`before-roc`],reverseOf:`roc`}])}},Eue=class extends e1{constructor(){super(`buddhist`,{year:-543,month:1,day:1})}},Due=class extends n1{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}},Oue=class extends n1{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}}},a1=class extends Z${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=Y$({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=K$(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=K$(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`?(DQ(a,1,o),DQ(s,1,this.maximumMonthLength())):(a=TQ(a,1,o),s=TQ(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=K$(+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}}},kue=class extends a1{constructor(){super(...arguments),this.id=`chinese`}},Aue=class extends a1{constructor(){super(...arguments),this.id=`dangi`}},jue=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 J$;q$(e,void 0,this.helper.monthsInYear({year:e.year??1972},t))}}dateToISO(e,t){let n=new J$,r=this.helper.calendarToIsoDate(e,t,n);return n.setObject(r),r}monthDayToISOReferenceDate(e,t){let n=new J$,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 V$(t)}dateAdd(e,{years:t,months:n,weeks:r,days:i},a){let o=J$.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 J$.getCacheForObject(l)||new J$(o).setObject(l),l}dateUntil(e,t,n){let r=J$.getCacheForObject(e),i=J$.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=J$.getCacheForObject(e),r=this.helper.isoToCalendarDate(e,n);if(t.dayOfWeek&&(r.dayOfWeek=W$.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=H$(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[fue,yue,wue,Sue,Cue,kue,Aue,Tue,bue,Eue,Due,Oue,pue,mue,hue,gue,_ue,vue]){let t=new e;W$[t.id]=new jue(t)}tY(`calendarImpl`,(function(e){return W$[e]}));var o1=Intl.DateTimeFormat;function s1(e,t){let n=Q(e,t);return typeof n==`function`&&(n=new o1(Q(e,WJ),n(Q(e,GJ))),function(e,t,n){let r=JJ(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 c1(e){return ZJ(e,BJ)}var l1=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 o1(t,i),o=a.resolvedOptions();if(XJ(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,QJ(e,GJ,t)}else QJ(e,GJ,i);QJ(e,WJ,o.locale),QJ(e,BJ,a),QJ(e,VJ,o.timeZone),QJ(e,UJ,o.calendar),QJ(e,PJ,Bue),QJ(e,FJ,Rue),QJ(e,IJ,zue),QJ(e,LJ,Lue),QJ(e,RJ,Vue),QJ(e,zJ,Hue);let s=r?i.timeZone:void 0;if(s===void 0)QJ(e,HJ,o.timeZone);else{let t=VY(s);if(t.startsWith(`−`))throw RangeError(`Unicode minus (U+2212) is not supported in time zone offsets`);QJ(e,HJ,MZ(t))}})(this,e,t)}get format(){$(this,c1);let e=Nue.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,c1),Fue.call(this,e,t)}formatToParts(e,...t){return $(this,c1),Pue.call(this,e,...t)}formatRangeToParts(e,t){return $(this,c1),Iue.call(this,e,t)}resolvedOptions(){return $(this,c1),Mue.call(this)}};`formatToParts`in o1.prototype||delete l1.prototype.formatToParts,`formatRangeToParts`in o1.prototype||delete l1.prototype.formatRangeToParts;var u1=function(e=void 0,t=void 0){return new l1(e,t)};function Mue(){let e=Q(this,BJ).resolvedOptions();return e.timeZone=Q(this,HJ),e}function Nue(e,...t){let n,r,i=v1(e,this);return i.formatter?(n=i.formatter,r=[E$(i.epochNs,`floor`)]):(n=Q(this,BJ),r=[e,...t]),n.format(...r)}function Pue(e,...t){let n,r,i=v1(e,this);return i.formatter?(n=i.formatter,r=[E$(i.epochNs,`floor`)]):(n=Q(this,BJ),r=[e,...t]),n.formatToParts(...r)}function Fue(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=g1(e),r=g1(t),i,a=[n,r];if(h1(n)!==h1(r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);if(h1(n)){if(!_1(n,r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);let{epochNs:e,formatter:t}=v1(n,this),{epochNs:o,formatter:s}=v1(r,this);t&&(i=t,a=[E$(e,`floor`),E$(o,`floor`)])}return i||=Q(this,BJ),i.formatRange(...a)}function Iue(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=g1(e),r=g1(t),i,a=[n,r];if(h1(n)!==h1(r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);if(h1(n)){if(!_1(n,r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);let{epochNs:e,formatter:t}=v1(n,this),{epochNs:o,formatter:s}=v1(r,this);t&&(i=t,a=[E$(e,`floor`),E$(o,`floor`)])}return i||=Q(this,BJ),i.formatRangeToParts(...a)}function d1(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 Lue(e){let t=d1(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`})),!p1(t)){if(m1(e))throw TypeError(`cannot format Temporal.PlainTime with options [${Object.keys(e)}]`);Object.assign(t,{hour:`numeric`,minute:`numeric`,second:`numeric`})}return t}function Rue(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=d1(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(m1(e))throw TypeError(`cannot format PlainYearMonth with options [${Object.keys(e)}]`);Object.assign(n,{year:`numeric`,month:`numeric`})}return n}function zue(e){let t={short:{month:`numeric`,day:`numeric`},medium:{month:`short`,day:`numeric`},long:{month:`long`,day:`numeric`},full:{month:`long`,day:`numeric`}},n=d1(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(m1(e))throw TypeError(`cannot format PlainMonthDay with options [${Object.keys(e)}]`);Object.assign(n,{month:`numeric`,day:`numeric`})}return n}function Bue(e){let t=d1(e,{hour:!1,minute:!1,second:!1,dayPeriod:!1,timeZoneName:!1,timeStyle:!1});if(!f1(t)){if(m1(e))throw TypeError(`cannot format PlainDate with options [${Object.keys(e)}]`);Object.assign(t,{year:`numeric`,month:`numeric`,day:`numeric`})}return t}function Vue(e){let t=d1(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),!p1(t)&&!f1(t)){if(m1(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 Hue(e){let t=e;return p1(t)||f1(t)||(t=Object.assign({},t,{year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})),t}function f1(e){return`year`in e||`month`in e||`day`in e||`weekday`in e||`dateStyle`in e||`era`in e}function p1(e){return`hour`in e||`minute`in e||`second`in e||`timeStyle`in e||`dayPeriod`in e||`fractionalSecondDigits`in e}function m1(e){return f1(e)||p1(e)||`dateStyle`in e||`timeStyle`in e||`timeZoneName`in e}function h1(e){return cX(e)||lX(e)||uX(e)||pX(e)||dX(e)||fX(e)||oX(e)}function g1(e){return h1(e)?e:BY(e)}function _1(e,t){return!(!h1(e)||!h1(t)||lX(e)&&!lX(t)||cX(e)&&!cX(t)||uX(e)&&!uX(t)||pX(e)&&!pX(t)||dX(e)&&!dX(t)||fX(e)&&!fX(t)||oX(e)&&!oX(t))}function v1(e,t){if(lX(e)){let n={isoDate:{year:1970,month:1,day:1},time:Q(e,yJ)};return{epochNs:LZ(Q(t,VJ),n,`compatible`),formatter:s1(t,LJ)}}if(dX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==r)throw RangeError(`cannot format PlainYearMonth with calendar ${n} in locale with calendar ${r}`);let i=kX(Q(e,_J),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,FJ)}}if(fX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==r)throw RangeError(`cannot format PlainMonthDay with calendar ${n} in locale with calendar ${r}`);let i=kX(Q(e,_J),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,IJ)}}if(cX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDate with calendar ${n} in locale with calendar ${r}`);let i=kX(Q(e,_J),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,PJ)}}if(uX(e)){let n=Q(e,Z),r=Q(t,UJ);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDateTime with calendar ${n} in locale with calendar ${r}`);let i=Q(e,vJ);return{epochNs:LZ(Q(t,VJ),i,`compatible`),formatter:s1(t,RJ)}}if(pX(e))throw TypeError(`Temporal.ZonedDateTime not supported in DateTimeFormat methods. Use toLocaleString() instead.`);return oX(e)?{epochNs:Q(e,gJ),formatter:s1(t,zJ)}:{}}function y1(e){let t=Object.create(null);return t.years=Q(e,wJ),t.months=Q(e,TJ),t.weeks=Q(e,EJ),t.days=Q(e,DJ),t.hours=Q(e,OJ),t.minutes=Q(e,kJ),t.seconds=Q(e,AJ),t.milliseconds=Q(e,jJ),t.microseconds=Q(e,MJ),t.nanoseconds=Q(e,NJ),t}l1.prototype.constructor=u1,Object.defineProperty(u1,"prototype",{value:l1.prototype,writable:!1,enumerable:!1,configurable:!1}),u1.supportedLocalesOf=o1.supportedLocalesOf,eY(u1,`Intl.DateTimeFormat`);var{format:Uue,formatToParts:Wue}=Intl.DurationFormat?.prototype??Object.create(null);function b1(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=y1(eZ(e));return Uue.call(this,t)}Intl.DurationFormat?.prototype&&(Intl.DurationFormat.prototype.format=b1,Intl.DurationFormat.prototype.formatToParts=function(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=y1(eZ(e));return Wue.call(this,t)}),Object.freeze({__proto__:null,DateTimeFormat:u1,ModifiedIntlDurationFormatPrototypeFormat:b1});var x1=class{constructor(e){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);vZ(this,O$(e))}get epochMilliseconds(){return $(this,oX),E$(Q(this,gJ),`floor`)}get epochNanoseconds(){return $(this,oX),T$(X.default.BigInt(Q(this,gJ)))}add(e){return $(this,oX),u$(`add`,this,e)}subtract(e){return $(this,oX),u$(`subtract`,this,e)}until(e,t=void 0){return $(this,oX),e$(`until`,this,e,t)}since(e,t=void 0){return $(this,oX),e$(`since`,this,e,t)}round(e){if($(this,oX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX);return IX(n,{hour:24,minute:1440,second:86400,millisecond:864e5,microsecond:864e8,nanosecond:864e11}[i],!0),yZ(_$(Q(this,gJ),n,i,r))}equals(e){$(this,oX);let t=tZ(e),n=Q(this,gJ),r=Q(t,gJ);return X.default.equal(X.default.BigInt(n),X.default.BigInt(r))}toString(e=void 0){$(this,oX);let t=M$(e),n=LX(t),r=MX(t,`trunc`),i=BX(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=MZ(a));let{precision:o,unit:s,increment:c}=RX(i,n);return GZ(yZ(_$(Q(this,gJ),c,s,r)),a,o)}toJSON(){return $(this,oX),GZ(this,void 0,`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,oX),new u1(e,t).format(this)}valueOf(){L$(`Instant`)}toZonedDateTimeISO(e){$(this,oX);let t=MZ(e);return xZ(Q(this,gJ),t,`iso8601`)}static fromEpochMilliseconds(e){return yZ(D$(BY(e)))}static fromEpochNanoseconds(e){return yZ(O$(e))}static from(e){return tZ(e)}static compare(e,t){let n=tZ(e),r=tZ(t),i=Q(n,gJ),a=Q(r,gJ);return X.default.lessThan(i,a)?-1:+!!X.default.greaterThan(i,a)}};eY(x1,`Temporal.Instant`);var S1=class{constructor(e,t,n,r=`iso8601`){let i=HY(e),a=HY(t),o=HY(n),s=F$(r===void 0?`iso8601`:KY(r));OQ(i,a,o),cZ(this,{year:i,month:a,day:o},s)}get calendarId(){return $(this,cX),Q(this,Z)}get era(){return C1(this,`era`)}get eraYear(){return C1(this,`eraYear`)}get year(){return C1(this,`year`)}get month(){return C1(this,`month`)}get monthCode(){return C1(this,`monthCode`)}get day(){return C1(this,`day`)}get dayOfWeek(){return C1(this,`dayOfWeek`)}get dayOfYear(){return C1(this,`dayOfYear`)}get weekOfYear(){return C1(this,`weekOfYear`)?.week}get yearOfWeek(){return C1(this,`weekOfYear`)?.year}get daysInWeek(){return C1(this,`daysInWeek`)}get daysInMonth(){return C1(this,`daysInMonth`)}get daysInYear(){return C1(this,`daysInYear`)}get monthsInYear(){return C1(this,`monthsInYear`)}get inLeapYear(){return C1(this,`inLeapYear`)}with(e,t=void 0){if($(this,cX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=JX(n,Q(this,_J));return r=CZ(n,r,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),lZ(kZ(n,r,AX(M$(t))),n)}withCalendar(e){$(this,cX);let t=EZ(e);return lZ(Q(this,_J),t)}add(e,t=void 0){return $(this,cX),d$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,cX),d$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,cX),t$(`until`,this,e,t)}since(e,t=void 0){return $(this,cX),t$(`since`,this,e,t)}equals(e){$(this,cX);let t=ZX(e);return S$(Q(this,_J),Q(t,_J))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){return $(this,cX),qZ(this,PX(M$(e)))}toJSON(){return $(this,cX),qZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,cX),new u1(e,t).format(this)}valueOf(){L$(`PlainDate`)}toPlainDateTime(e=void 0){$(this,cX);let t=iZ(e);return dZ(kX(Q(this,_J),t),Q(this,Z))}toZonedDateTime(e){let t,n;if($(this,cX),zY(e)){let r=e.timeZone;r===void 0?t=MZ(e):(t=MZ(r),n=e.plainTime)}else t=MZ(e);let r=Q(this,_J),i;return n===void 0?i=BZ(t,r):(n=rZ(n),i=LZ(t,kX(r,Q(n,yJ)),`compatible`)),xZ(i,t,Q(this,Z))}toPlainYearMonth(){$(this,cX);let e=Q(this,Z);return _Z(AZ(e,JX(e,Q(this,_J)),`constrain`),e)}toPlainMonthDay(){$(this,cX);let e=Q(this,Z);return pZ(jZ(e,JX(e,Q(this,_J)),`constrain`),e)}static from(e,t=void 0){return ZX(e,t)}static compare(e,t){let n=ZX(e),r=ZX(t);return S$(Q(n,_J),Q(r,_J))}};function C1(e,t){$(e,cX);let n=Q(e,_J);return qX(e).isoToDate(n,{[t]:!0})[t]}eY(S1,`Temporal.PlainDate`);var w1=class{constructor(e,t,n,r=0,i=0,a=0,o=0,s=0,c=0,l=`iso8601`){let u=HY(e),d=HY(t),f=HY(n),p=r===void 0?0:HY(r),m=i===void 0?0:HY(i),h=a===void 0?0:HY(a),g=o===void 0?0:HY(o),_=s===void 0?0:HY(s),v=c===void 0?0:HY(c),y=F$(l===void 0?`iso8601`:KY(l));jQ(u,d,f,p,m,h,g,_,v),uZ(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,uX),Q(this,Z)}get year(){return T1(this,`year`)}get month(){return T1(this,`month`)}get monthCode(){return T1(this,`monthCode`)}get day(){return T1(this,`day`)}get hour(){return E1(this,`hour`)}get minute(){return E1(this,`minute`)}get second(){return E1(this,`second`)}get millisecond(){return E1(this,`millisecond`)}get microsecond(){return E1(this,`microsecond`)}get nanosecond(){return E1(this,`nanosecond`)}get era(){return T1(this,`era`)}get eraYear(){return T1(this,`eraYear`)}get dayOfWeek(){return T1(this,`dayOfWeek`)}get dayOfYear(){return T1(this,`dayOfYear`)}get weekOfYear(){return T1(this,`weekOfYear`)?.week}get yearOfWeek(){return T1(this,`weekOfYear`)?.year}get daysInWeek(){return T1(this,`daysInWeek`)}get daysInYear(){return T1(this,`daysInYear`)}get daysInMonth(){return T1(this,`daysInMonth`)}get monthsInYear(){return T1(this,`monthsInYear`)}get inLeapYear(){return T1(this,`inLeapYear`)}with(e,t=void 0){if($(this,uX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=Q(this,vJ),i={...JX(n,r.isoDate),...r.time};return i=CZ(n,i,YX(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],`partial`)),dZ(QX(n,i,AX(M$(t))),n)}withPlainTime(e=void 0){$(this,uX);let t=iZ(e);return dZ(kX(Q(this,vJ).isoDate,t),Q(this,Z))}withCalendar(e){$(this,uX);let t=EZ(e);return dZ(Q(this,vJ),t)}add(e,t=void 0){return $(this,uX),f$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,uX),f$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,uX),n$(`until`,this,e,t)}since(e,t=void 0){return $(this,uX),n$(`since`,this,e,t)}round(e){if($(this,uX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];IX(n,a,a===1);let o=Q(this,vJ);return dZ(n===1&&i===`nanosecond`?o:v$(o,n,i,r),Q(this,Z))}equals(e){$(this,uX);let t=$X(e);return w$(Q(this,vJ),Q(t,vJ))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){$(this,uX);let t=M$(e),n=PX(t),r=LX(t),i=MX(t,`trunc`),a=BX(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}=RX(a,r),l=v$(Q(this,vJ),c,s,i);return MQ(l),YZ(l,Q(this,Z),o,n)}toJSON(){return $(this,uX),YZ(Q(this,vJ),Q(this,Z),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,uX),new u1(e,t).format(this)}valueOf(){L$(`PlainDateTime`)}toZonedDateTime(e,t=void 0){$(this,uX);let n=MZ(e),r=jX(M$(t));return xZ(LZ(n,Q(this,vJ),r),n,Q(this,Z))}toPlainDate(){return $(this,uX),lZ(Q(this,vJ).isoDate,Q(this,Z))}toPlainTime(){return $(this,uX),hZ(Q(this,vJ).time)}static from(e,t=void 0){return $X(e,t)}static compare(e,t){let n=$X(e),r=$X(t);return w$(Q(n,vJ),Q(r,vJ))}};function T1(e,t){$(e,uX);let n=Q(e,vJ).isoDate;return qX(e).isoToDate(n,{[t]:!0})[t]}function E1(e,t){return $(e,uX),Q(e,vJ).time[t]}eY(w1,`Temporal.PlainDateTime`);var D1=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:WY(e),d=t===void 0?0:WY(t),f=n===void 0?0:WY(n),p=r===void 0?0:WY(r),m=i===void 0?0:WY(i),h=a===void 0?0:WY(a),g=o===void 0?0:WY(o),_=s===void 0?0:WY(s),v=c===void 0?0:WY(c),y=l===void 0?0:WY(l);IQ(u,d,f,p,m,h,g,_,v,y),XJ(this),QJ(this,wJ,u),QJ(this,TJ,d),QJ(this,EJ,f),QJ(this,DJ,p),QJ(this,OJ,m),QJ(this,kJ,h),QJ(this,AJ,g),QJ(this,jJ,_),QJ(this,MJ,v),QJ(this,NJ,y)}get years(){return $(this,sX),Q(this,wJ)}get months(){return $(this,sX),Q(this,TJ)}get weeks(){return $(this,sX),Q(this,EJ)}get days(){return $(this,sX),Q(this,DJ)}get hours(){return $(this,sX),Q(this,OJ)}get minutes(){return $(this,sX),Q(this,kJ)}get seconds(){return $(this,sX),Q(this,AJ)}get milliseconds(){return $(this,sX),Q(this,jJ)}get microseconds(){return $(this,sX),Q(this,MJ)}get nanoseconds(){return $(this,sX),Q(this,NJ)}get sign(){return $(this,sX),gQ(this)}get blank(){return $(this,sX),gQ(this)===0}with(t){$(this,sX);let{years:n=Q(this,wJ),months:r=Q(this,TJ),weeks:i=Q(this,EJ),days:a=Q(this,DJ),hours:o=Q(this,OJ),minutes:s=Q(this,kJ),seconds:c=Q(this,AJ),milliseconds:l=Q(this,jJ),microseconds:u=Q(this,MJ),nanoseconds:d=Q(this,NJ)}=DX(t);return new e(n,r,i,a,o,s,c,l,u,d)}negated(){return $(this,sX),wQ(this)}abs(){return $(this,sX),new e(Math.abs(Q(this,wJ)),Math.abs(Q(this,TJ)),Math.abs(Q(this,EJ)),Math.abs(Q(this,DJ)),Math.abs(Q(this,OJ)),Math.abs(Q(this,kJ)),Math.abs(Q(this,AJ)),Math.abs(Q(this,jJ)),Math.abs(Q(this,MJ)),Math.abs(Q(this,NJ)))}add(e){return $(this,sX),l$(`add`,this,e)}subtract(e){return $(this,sX),l$(`subtract`,this,e)}round(e){if($(this,sX),e===void 0)throw TypeError(`options parameter is required`);let t=HX(this),n=typeof e==`string`?N$(`smallestUnit`,e):M$(e),r=BX(n,`largestUnit`,`datetime`,void 0,[`auto`]),{plainRelativeTo:i,zonedRelativeTo:a}=VX(n),o=FX(n),s=MX(n,`halfExpand`),c=BX(n,`smallestUnit`,`datetime`,void 0),l=!0;c||=(l=!1,`nanosecond`);let u=UX(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(UX(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&&IX(o,f,!1),o>1&&GX(c)===`date`&&r!==c)throw RangeError(`For calendar units with roundingIncrement > 1, use largestUnit = smallestUnit`);if(a){let e=LQ(this),t=Q(a,CJ),n=Q(a,Z),i=Q(a,gJ);return e=QQ(i,c$(i,t,n,e),t,n,r,o,c,s),GX(r)===`date`&&(r=`hour`),BQ(e,r)}if(i){let e=RQ(this),t=o$({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),n=Q(i,_J),a=Q(i,Z),l=wZ(a,n,OX(e.date,t.deltaDays),`constrain`);return e=ZQ(kX(n,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),kX(l,t),a,r,o,c,s),BQ(e,r)}if(WX(t))throw RangeError(`a starting point is required for ${t}s balancing`);if(WX(r))throw RangeError(`a starting point is required for ${r}s balancing`);let p=RQ(this);if(c===`day`){let{quotient:e,remainder:t}=p.time.divmod(EY),n=p.date.days+e+x$(t,`day`);n=g$(n,o,s),p=VQ({years:0,months:0,weeks:0,days:n},sY.ZERO)}else p=VQ({years:0,months:0,weeks:0,days:0},b$(p.time,o,c,s));return BQ(p,r)}total(e){if($(this,sX),e===void 0)throw TypeError(`options argument is required`);let t=typeof e==`string`?N$(`unit`,e):M$(e),{plainRelativeTo:n,zonedRelativeTo:r}=VX(t),i=BX(t,`unit`,`datetime`,zX);if(r){let e=LQ(this),t=Q(r,CJ),n=Q(r,Z),a=Q(r,gJ);return function(e,t,n,r,i){return GX(i)===`time`?x$(sY.fromEpochNsDiff(t,e),i):XQ(qQ(e,t,n,r,i),t,IZ(n,e),n,r,i)}(a,c$(a,t,n,e),t,n,i)}if(n){let e=RQ(this),t=o$({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),r=Q(n,_J),a=Q(n,Z),o=wZ(a,r,OX(e.date,t.deltaDays),`constrain`);return function(e,t,n,r){if(w$(e,t)==0)return 0;MQ(e),MQ(t);let i=KQ(e,t,n,r);return r===`nanosecond`?X.default.toNumber(i.time.totalNs):XQ(i,lQ(t),e,null,n,r)}(kX(r,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),kX(o,t),a,i)}let a=HX(this);if(WX(a))throw RangeError(`a starting point is required for ${a}s total`);if(WX(i))throw RangeError(`a starting point is required for ${i}s total`);return x$(RQ(this).time,i)}toString(e=void 0){$(this,sX);let t=M$(e),n=LX(t),r=MX(t,`trunc`),i=BX(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}=RX(i,n);if(o===`nanosecond`&&s===1)return KZ(this,a);let c=HX(this),l=LQ(this),u=b$(l.time,s,o,r);return l=VQ(l.date,u),KZ(BQ(l,UX(c,`second`)),a)}toJSON(){return $(this,sX),KZ(this,`auto`)}toLocaleString(e=void 0,t=void 0){if($(this,sX),typeof Intl.DurationFormat==`function`){let n=new Intl.DurationFormat(e,t);return b1.call(n,this)}return console.warn(`Temporal.Duration.prototype.toLocaleString() requires Intl.DurationFormat.`),KZ(this,`auto`)}valueOf(){L$(`Duration`)}static from(e){return eZ(e)}static compare(e,t,n=void 0){let r=eZ(e),i=eZ(t),{plainRelativeTo:a,zonedRelativeTo:o}=VX(M$(n));if(Q(r,wJ)===Q(i,wJ)&&Q(r,TJ)===Q(i,TJ)&&Q(r,EJ)===Q(i,EJ)&&Q(r,DJ)===Q(i,DJ)&&Q(r,OJ)===Q(i,OJ)&&Q(r,kJ)===Q(i,kJ)&&Q(r,AJ)===Q(i,AJ)&&Q(r,jJ)===Q(i,jJ)&&Q(r,MJ)===Q(i,MJ)&&Q(r,NJ)===Q(i,NJ))return 0;let s=HX(r),c=HX(i),l=LQ(r),u=LQ(i);if(o&&(GX(s)===`date`||GX(c)===`date`)){let e=Q(o,CJ),t=Q(o,Z),n=Q(o,gJ),r=c$(n,e,t,l),i=c$(n,e,t,u);return j$(X.default.toNumber(X.default.subtract(r,i)))}let d=l.date.days,f=u.date.days;if(WX(s)||WX(c)){if(!a)throw RangeError(`A starting point is required for years, months, or weeks comparison`);d=CQ(l.date,a),f=CQ(u.date,a)}let p=l.time.add24HourDays(d),m=u.time.add24HourDays(f);return p.cmp(m)}};eY(D1,`Temporal.Duration`);var O1=class{constructor(e,t,n=`iso8601`,r=1972){let i=HY(e),a=HY(t),o=F$(n===void 0?`iso8601`:KY(n)),s=HY(r);OQ(s,i,a),fZ(this,{year:s,month:i,day:a},o)}get monthCode(){return k1(this,`monthCode`)}get day(){return k1(this,`day`)}get calendarId(){return $(this,fX),Q(this,Z)}with(e,t=void 0){if($(this,fX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=JX(n,Q(this,_J),`month-day`);return r=CZ(n,r,YX(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),pZ(jZ(n,r,AX(M$(t))),n)}equals(e){$(this,fX);let t=nZ(e);return S$(Q(this,_J),Q(t,_J))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){return $(this,fX),XZ(this,PX(M$(e)))}toJSON(){return $(this,fX),XZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,fX),new u1(e,t).format(this)}valueOf(){L$(`PlainMonthDay`)}toPlainDate(e){if($(this,fX),!zY(e))throw TypeError(`argument should be an object`);let t=Q(this,Z);return lZ(kZ(t,CZ(t,JX(t,Q(this,_J),`month-day`),YX(t,e,[`year`],[],[])),`constrain`),t)}static from(e,t=void 0){return nZ(e,t)}};function k1(e,t){$(e,fX);let n=Q(e,_J);return qX(e).isoToDate(n,{[t]:!0})[t]}function A1(e){return IZ(e,k$())}eY(O1,`Temporal.PlainMonthDay`);var j1={instant:()=>yZ(k$()),plainDateTimeISO:(e=A$())=>dZ(A1(MZ(e)),`iso8601`),plainDateISO:(e=A$())=>lZ(A1(MZ(e)).isoDate,`iso8601`),plainTimeISO:(e=A$())=>hZ(A1(MZ(e)).time),timeZoneId:()=>A$(),zonedDateTimeISO:(e=A$())=>{let t=MZ(e);return xZ(k$(),t,`iso8601`)},[Symbol.toStringTag]:`Temporal.Now`};Object.defineProperty(j1,Symbol.toStringTag,{value:`Temporal.Now`,writable:!1,enumerable:!1,configurable:!0});var M1=class e{constructor(e=0,t=0,n=0,r=0,i=0,a=0){let o=e===void 0?0:HY(e),s=t===void 0?0:HY(t),c=n===void 0?0:HY(n),l=r===void 0?0:HY(r),u=i===void 0?0:HY(i),d=a===void 0?0:HY(a);AQ(o,s,c,l,u,d),mZ(this,{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d})}get hour(){return $(this,lX),Q(this,yJ).hour}get minute(){return $(this,lX),Q(this,yJ).minute}get second(){return $(this,lX),Q(this,yJ).second}get millisecond(){return $(this,lX),Q(this,yJ).millisecond}get microsecond(){return $(this,lX),Q(this,yJ).microsecond}get nanosecond(){return $(this,lX),Q(this,yJ).nanosecond}with(t,n=void 0){if($(this,lX),!zY(t))throw TypeError(`invalid argument`);mX(t);let r=XX(t,`partial`),i=XX(this),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=Object.assign(i,r),d=AX(M$(n));return{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=EX(a,o,s,c,l,u,d),new e(a,o,s,c,l,u)}add(e){return $(this,lX),p$(`add`,this,e)}subtract(e){return $(this,lX),p$(`subtract`,this,e)}until(e,t=void 0){return $(this,lX),r$(`until`,this,e,t)}since(e,t=void 0){return $(this,lX),r$(`since`,this,e,t)}round(e){if($(this,lX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX);return IX(n,{hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i],!1),hZ(y$(Q(this,yJ),n,i,r))}equals(e){$(this,lX);let t=rZ(e);return C$(Q(this,yJ),Q(t,yJ))===0}toString(e=void 0){$(this,lX);let t=M$(e),n=LX(t),r=MX(t,`trunc`),i=BX(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}=RX(i,n);return JZ(y$(Q(this,yJ),s,o,r),a)}toJSON(){return $(this,lX),JZ(Q(this,yJ),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,lX),new u1(e,t).format(this)}valueOf(){L$(`PlainTime`)}static from(e,t=void 0){return rZ(e,t)}static compare(e,t){let n=rZ(e),r=rZ(t);return C$(Q(n,yJ),Q(r,yJ))}};eY(M1,`Temporal.PlainTime`);var N1=class{constructor(e,t,n=`iso8601`,r=1){let i=HY(e),a=HY(t),o=F$(n===void 0?`iso8601`:KY(n)),s=HY(r);OQ(i,a,s),gZ(this,{year:i,month:a,day:s},o)}get year(){return P1(this,`year`)}get month(){return P1(this,`month`)}get monthCode(){return P1(this,`monthCode`)}get calendarId(){return $(this,dX),Q(this,Z)}get era(){return P1(this,`era`)}get eraYear(){return P1(this,`eraYear`)}get daysInMonth(){return P1(this,`daysInMonth`)}get daysInYear(){return P1(this,`daysInYear`)}get monthsInYear(){return P1(this,`monthsInYear`)}get inLeapYear(){return P1(this,`inLeapYear`)}with(e,t=void 0){if($(this,dX),!zY(e))throw TypeError(`invalid argument`);mX(e);let n=Q(this,Z),r=JX(n,Q(this,_J),`year-month`);return r=CZ(n,r,YX(n,e,[`year`,`month`,`monthCode`],[],`partial`)),_Z(AZ(n,r,AX(M$(t))),n)}add(e,t=void 0){return $(this,dX),m$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,dX),m$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,dX),i$(`until`,this,e,t)}since(e,t=void 0){return $(this,dX),i$(`since`,this,e,t)}equals(e){$(this,dX);let t=aZ(e);return S$(Q(this,_J),Q(t,_J))===0&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){return $(this,dX),ZZ(this,PX(M$(e)))}toJSON(){return $(this,dX),ZZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,dX),new u1(e,t).format(this)}valueOf(){L$(`PlainYearMonth`)}toPlainDate(e){if($(this,dX),!zY(e))throw TypeError(`argument should be an object`);let t=Q(this,Z);return lZ(kZ(t,CZ(t,JX(t,Q(this,_J),`year-month`),YX(t,e,[`day`],[],[])),`constrain`),t)}static from(e,t=void 0){return aZ(e,t)}static compare(e,t){let n=aZ(e),r=aZ(t);return S$(Q(n,_J),Q(r,_J))}};function P1(e,t){$(e,dX);let n=Q(e,_J);return qX(e).isoToDate(n,{[t]:!0})[t]}eY(N1,`Temporal.PlainYearMonth`);var Gue=u1.prototype.resolvedOptions,F1=class{constructor(e,t,n=`iso8601`){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);let r=O$(e),i=KY(t),{tzName:a,offsetMinutes:o}=wX(i);if(o===void 0){let e=rQ(a);if(!e)throw RangeError(`unknown time zone ${a}`);i=e.identifier}else i=oQ(o);bZ(this,r,i,F$(n===void 0?`iso8601`:KY(n)))}get calendarId(){return $(this,pX),Q(this,Z)}get timeZoneId(){return $(this,pX),Q(this,CJ)}get year(){return L1(this,`year`)}get month(){return L1(this,`month`)}get monthCode(){return L1(this,`monthCode`)}get day(){return L1(this,`day`)}get hour(){return R1(this,`hour`)}get minute(){return R1(this,`minute`)}get second(){return R1(this,`second`)}get millisecond(){return R1(this,`millisecond`)}get microsecond(){return R1(this,`microsecond`)}get nanosecond(){return R1(this,`nanosecond`)}get era(){return L1(this,`era`)}get eraYear(){return L1(this,`eraYear`)}get epochMilliseconds(){return $(this,pX),E$(Q(this,gJ),`floor`)}get epochNanoseconds(){return $(this,pX),T$(Q(this,gJ))}get dayOfWeek(){return L1(this,`dayOfWeek`)}get dayOfYear(){return L1(this,`dayOfYear`)}get weekOfYear(){return L1(this,`weekOfYear`)?.week}get yearOfWeek(){return L1(this,`weekOfYear`)?.year}get hoursInDay(){$(this,pX);let e=Q(this,CJ),t=I1(this).isoDate,n=bQ(t.year,t.month,t.day+1),r=BZ(e,t),i=BZ(e,n);return x$(sY.fromEpochNsDiff(i,r),`hour`)}get daysInWeek(){return L1(this,`daysInWeek`)}get daysInMonth(){return L1(this,`daysInMonth`)}get daysInYear(){return L1(this,`daysInYear`)}get monthsInYear(){return L1(this,`monthsInYear`)}get inLeapYear(){return L1(this,`inLeapYear`)}get offset(){return $(this,pX),FZ(PZ(Q(this,CJ),Q(this,gJ)))}get offsetNanoseconds(){return $(this,pX),PZ(Q(this,CJ),Q(this,gJ))}with(e,t=void 0){if($(this,pX),!zY(e))throw TypeError(`invalid zoned-date-time-like`);mX(e);let n=Q(this,Z),r=Q(this,CJ),i=PZ(r,Q(this,gJ)),a=I1(this),o={...JX(n,a.isoDate),...a.time,offset:FZ(i)};o=CZ(n,o,YX(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`],`partial`));let s=M$(t),c=jX(s),l=NX(s,`prefer`),u=QX(n,o,AX(s)),d=eQ(o.offset);return xZ(oZ(u.isoDate,u.time,`option`,d,r,c,l,!1),r,n)}withPlainTime(e=void 0){$(this,pX);let t=Q(this,CJ),n=Q(this,Z),r=I1(this).isoDate,i;return i=e===void 0?BZ(t,r):LZ(t,kX(r,Q(rZ(e),yJ)),`compatible`),xZ(i,t,n)}withTimeZone(e){$(this,pX);let t=MZ(e);return xZ(Q(this,gJ),t,Q(this,Z))}withCalendar(e){$(this,pX);let t=EZ(e);return xZ(Q(this,gJ),Q(this,CJ),t)}add(e,t=void 0){return $(this,pX),h$(`add`,this,e,t)}subtract(e,t=void 0){return $(this,pX),h$(`subtract`,this,e,t)}until(e,t=void 0){return $(this,pX),a$(`until`,this,e,t)}since(e,t=void 0){return $(this,pX),a$(`since`,this,e,t)}round(e){if($(this,pX),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?N$(`smallestUnit`,e):M$(e),n=FX(t),r=MX(t,`halfExpand`),i=BX(t,`smallestUnit`,`time`,zX,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];if(IX(n,a,a===1),i===`nanosecond`&&n===1)return xZ(Q(this,gJ),Q(this,CJ),Q(this,Z));let o=Q(this,CJ),s=Q(this,gJ),c=I1(this),l;if(i===`day`){let e=c.isoDate,t=bQ(e.year,e.month,e.day+1),n=BZ(o,e),i=BZ(o,t),a=X.default.subtract(i,n);l=sY.fromEpochNsDiff(s,n).round(a,r).addToEpochNs(n)}else{let e=v$(c,n,i,r),t=PZ(o,s);l=oZ(e.isoDate,e.time,`option`,t,o,`compatible`,`prefer`,!1)}return xZ(l,o,Q(this,Z))}equals(e){$(this,pX);let t=sZ(e),n=Q(this,gJ),r=Q(t,gJ);return!!X.default.equal(X.default.BigInt(n),X.default.BigInt(r))&&!!NZ(Q(this,CJ),Q(t,CJ))&&OZ(Q(this,Z),Q(t,Z))}toString(e=void 0){$(this,pX);let t=M$(e),n=PX(t),r=LX(t),i=function(e){return P$(e,`offset`,[`auto`,`never`],`auto`)}(t),a=MX(t,`trunc`),o=BX(t,`smallestUnit`,`time`,void 0);if(o===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let s=function(e){return P$(e,`timeZoneName`,[`auto`,`never`,`critical`],`auto`)}(t),{precision:c,unit:l,increment:u}=RX(o,r);return QZ(this,c,n,s,i,{unit:l,increment:u,roundingMode:a})}toLocaleString(e=void 0,t=void 0){$(this,pX);let n=M$(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,CJ),$Z(r.timeZone))throw RangeError(`toLocaleString does not currently support offset time zones`);let i=new u1(e,r),a=Gue.call(i).calendar,o=Q(this,Z);if(o!==`iso8601`&&a!==`iso8601`&&!OZ(a,o))throw RangeError(`cannot format ZonedDateTime with calendar ${o} in locale with calendar ${a}`);return i.format(yZ(Q(this,gJ)))}toJSON(){return $(this,pX),QZ(this,`auto`)}valueOf(){L$(`ZonedDateTime`)}startOfDay(){$(this,pX);let e=Q(this,CJ);return xZ(BZ(e,I1(this).isoDate),e,Q(this,Z))}getTimeZoneTransition(e){$(this,pX);let t=Q(this,CJ);if(e===void 0)throw TypeError(`options parameter is required`);let n=P$(typeof e==`string`?N$(`direction`,e):M$(e),`direction`,[`next`,`previous`],zX);if(n===void 0)throw TypeError(`direction option is required`);if($Z(t)||t===`UTC`)return null;let r=Q(this,gJ),i=n===`next`?dQ(t,r):fQ(t,r);return i===null?null:xZ(i,t,Q(this,Z))}toInstant(){return $(this,pX),yZ(Q(this,gJ))}toPlainDate(){return $(this,pX),lZ(I1(this).isoDate,Q(this,Z))}toPlainTime(){return $(this,pX),hZ(I1(this).time)}toPlainDateTime(){return $(this,pX),dZ(I1(this),Q(this,Z))}static from(e,t=void 0){return sZ(e,t)}static compare(e,t){let n=sZ(e),r=sZ(t),i=Q(n,gJ),a=Q(r,gJ);return X.default.lessThan(X.default.BigInt(i),X.default.BigInt(a))?-1:+!!X.default.greaterThan(X.default.BigInt(i),X.default.BigInt(a))}};function I1(e){return IZ(Q(e,CJ),Q(e,gJ))}function L1(e,t){$(e,pX);let n=I1(e).isoDate;return qX(e).isoToDate(n,{[t]:!0})[t]}function R1(e,t){return $(e,pX),I1(e).time[t]}eY(F1,`Temporal.ZonedDateTime`);var Kue=Object.freeze({__proto__:null,Duration:D1,Instant:x1,Now:j1,PlainDate:S1,PlainDateTime:w1,PlainMonthDay:O1,PlainTime:M1,PlainYearMonth:N1,ZonedDateTime:F1});(class{toTemporalInstant(){return yZ(D$(Date.prototype.valueOf.call(this)))}}).prototype.toTemporalInstant;var que=[x1,S1,w1,D1,O1,M1,N1,F1];for(let e of que){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 Jue(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 Yue(e,t){return Jue(new Date(e),t)}function Xue(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=Kue.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 z1(e,t){return new Intl.DateTimeFormat(void 0,{timeZone:t,dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}var B1={"claude-code":{name:`Claude Code`,command:`claude auth login`},codex:{name:`Codex`,command:`codex login`},gemini:{name:`Gemini`,command:`gemini`}},Zue=/not signed in|sign-in has expired|not logged in|run\s+"?(?:codex login|claude auth login)|authentication required/i,Que=/ENOSPC|no space left on device|disk (?:is )?full|not enough (?:free )?(?:disk )?space/i,$ue=/refused to make|content (?:rules|policy|filter)|safety (?:system|filter)|flagged|moderation/i,ede=/\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,tde=/did not accept the API key|API key is saved|invalid api key|key may be wrong/i,nde=[`images`,`thumbnail`],rde=/^Short \d+ image \d+:/;function V1(e){let t=e.reason??``,n=ide(e.provider,t);if(n!==void 0&&(Zue.test(t)||e.kind===`auth`))return{kind:`sign-in`,label:`Sign in to ${B1[n].name}`,cli:n,command:B1[n].command};if(Que.test(t))return{kind:`free-space`,label:`Free space`};if(e.kind===`refusal`||$ue.test(t))return nde.includes(e.stage)||e.stage===`video`&&rde.test(t)?{kind:`refused`,label:`Soften and retry`,soften:!0}:{kind:`refused`,label:`Edit the prompt`,soften:!1};if(ede.test(t))return{kind:`switch-model`,label:`Switch model`};if(e.kind===`auth`||e.kind===`missing_key`||tde.test(t)){let t=ade(e.provider);return{kind:`provider-settings`,label:t===void 0?`Open Settings → Providers`:`Open Settings → Providers → ${t}`,provider:e.provider??``}}}function ide(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 ade(e){return HF.find(t=>t.id===e)?.displayName}function ode(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}}var H1={catalogue:[`catalogue`],retired:[`catalogue`,`retired`],firstRun:[`first-run`]},U1={method:`POST`};async function sde(e,t,n){return F(await e.fetch(`${e.origin}/api/providers/${t}/key/test`,n===void 0?U1:{...U1,headers:{"content-type":`application/json`},body:JSON.stringify({key:n})}))}async function W1(e,t){let n=t===void 0?``:`?provider=${encodeURIComponent(t)}`;return F(await e.fetch(`${e.origin}/api/providers/health${n}`,U1))}async function cde(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue`))}async function lde(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue/check`,U1))}async function ude(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue/refresh`,U1))}async function G1(e){return(await F(await e.fetch(`${e.origin}/api/providers/catalogue/retired`))).usages}async function K1(e,t){await F(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 dde(e){return F(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch-all`,U1))}async function fde(e){return F(await e.fetch(`${e.origin}/api/providers/first-run`))}async function pde(e){let t=await e.fetch(`${e.origin}/api/providers/first-run/dismiss`,U1);t.ok||await F(t)}function mde(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 hde(e){return e.label.replace(/^Sign in to /,``)}async function q1(e){if(!navigator.clipboard)return!1;try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function J1({fix:e,retry:t,variant:n=`primary`,size:r=`default`}){let{api:i}=z(),a=Oy(),o=hde(e),s=P({mutationFn:async()=>mde(await W1(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 q1(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)(R,{variant:n,size:r,onClick:()=>void c(),children:`Copy sign-in command`}),(0,h.jsx)(R,{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 Y1({fix:e,retry:t,edit:n,variant:r=`primary`,size:i=`default`}){switch(e.kind){case`sign-in`:return(0,h.jsx)(J1,{fix:e,retry:t,variant:r,size:i});case`provider-settings`:return(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},variant:r,size:i,children:e.label});case`free-space`:return(0,h.jsx)(fS,{to:`/settings`,search:{section:`storage`},variant:r,size:i,children:e.label});case`refused`:case`switch-model`:return n??null}}function gde(e){let t=e.topics.error;if(t!==null)return V1({stage:`article`,reason:t,provider:e.topicGeneration.llm?.provider})}function X1({schedule:e,title:t,retry:n,className:r}){if(e.topics.error===null)return null;let i=gde(e);return(0,h.jsx)(SI,{tone:`danger`,title:t,...r===void 0?{}:{className:r},...i===void 0?{}:{actions:(0,h.jsx)(Y1,{fix:i,retry:n,variant:`secondary`,size:`small`})},children:e.topics.error})}function Z1(e){let t=Object.entries(e);return t.length===0?void 0:t.map(([e,t])=>`${e}: ${t}`).join(` · `)}function _de({schedule:e}){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),s=e.deletedAt===null&&(e.status===`active`||e.status===`paused`),c=N({queryKey:[...NH(e.id),e.topics.held,e.topics.generatedAt],enabled:s&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await PH(t,e.id);if(!n.ok)throw Error(n.message);return n.value}}),l=N({queryKey:[`project-template`,e.templateId],enabled:s&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await Uq(t,e.templateId);if(!n.ok)throw Error(n.message);return n.value}}).data?.document.form,u=(l===void 0?[]:_q(l)).filter(t=>t!==e.topicKeyword),d=t=>e.values[t]??l?.values[t]??``,f=P({mutationFn:e=>e(),onSuccess:e=>{i(e.ok?null:e.message),e.ok&&o(null)},onError:e=>i(e.message),onSettled:async()=>{await Promise.all([n.invalidateQueries({queryKey:TH}),n.invalidateQueries({queryKey:NH(e.id)}),n.invalidateQueries({queryKey:GH})])}});if(!s||e.topicGeneration.mode===`off`)return null;let{topics:p}=e,g=f.isPending,v=c.data??[];return(0,h.jsxs)(`section`,{"aria-label":`Topic generation`,children:[(0,h.jsx)(Mq,{className:`my-6`}),(0,h.jsxs)(H,{as:`h3`,title:`Topic generation`,meta:`${p.generatingSince===null?p.generatedAt===null?`No topics generated yet.`:`Topics last generated ${z1(p.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)(V,{id:`planning.schedule.generate-now`}),(0,h.jsx)(R,{disabled:g||p.generatingSince!==null,disabledReason:`Topics are being generated now`,onClick:()=>f.mutate(()=>IH(t,e.id)),children:`Generate topics now`})]}),(0,h.jsx)(X1,{schedule:e,title:`The last topic generation failed.`,className:`mt-3`,retry:{run:()=>f.mutate(()=>IH(t,e.id)),busy:g||p.generatingSince!==null}}),r===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`That didn't work.`,className:`mt-3`,children:r}),e.topicGeneration.mode===`hold`?(0,h.jsxs)(`div`,{className:`mt-4`,...Ob,children:[(0,h.jsx)(H,{as:`h3`,title:`Topics waiting · ${String(v.length)}`,info:`planning.schedule.held`,children:(0,h.jsx)(R,{variant:`primary`,disabled:g||v.length===0,disabledReason:`Nothing is waiting`,onClick:()=>f.mutate(()=>zH(t,e.id)),children:`Approve all`})}),c.error?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-danger`,children:`The waiting topics couldn't be loaded: ${c.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.jsx)(pU,{label:`Topics waiting`,className:`mt-2 [&_.sl-row__actions]:flex-wrap`,children:v.map(n=>(0,h.jsx)(mU,{title:a?.id===n.id?(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(CV,{"aria-label":`Edit ${n.title}`,className:`w-full`,maxLength:200,value:a.title,onChange:e=>o({...a,title:e.target.value})}),u.length===0?null:(0,h.jsx)(`div`,{className:`grid grid-cols-1 gap-2 min-[600px]:grid-cols-2`,children:u.map(e=>(0,h.jsx)(xV,{label:e,tip:`planning.schedule.held-keywords`,children:(0,h.jsx)(CV,{maxLength:2e3,placeholder:d(e)||`Not set`,value:a.values[e]??``,onChange:t=>o({...a,values:{...a.values,[e]:t.target.value}})})},e))})]}):n.title,meta:a?.id===n.id?void 0:Z1(n.values),actions:a?.id===n.id?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:g||a.title.trim()===``,onClick:()=>f.mutate(()=>VH(t,e.id,n.id,a.title.trim(),Object.fromEntries(Object.entries(a.values).filter(([,e])=>e.trim()!==``)))),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>o(null),children:`Cancel`})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:g,onClick:()=>f.mutate(()=>RH(t,e.id,n.id)),children:`Approve`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:g,onClick:()=>o({id:n.id,title:n.title,values:n.values}),children:`Edit`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:g,onClick:()=>f.mutate(()=>BH(t,e.id,n.id)),children:`Reject`})]})},n.id))})]}):null]})}function vde({schedules:e}){let t=e.filter(e=>e.deletedAt===null&&e.topicGeneration.mode!==`off`&&(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)(H,{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`,{children:(0,h.jsx)(pS,{to:`/calendar`,search:{tab:`schedules`},children:`Open schedules`})})]}):t.map((e,t)=>(0,h.jsx)(yde,{schedule:e,first:t===0},e.id))})}function yde({schedule:e,first:t}){let{api:n}=z(),r=_(),i=Oy(),a=N({queryKey:[...NH(e.id),e.topics.held,e.version],queryFn:async()=>{let t=await PH(n,e.id);if(!t.ok)throw Error(t.message);return t.value},enabled:e.topics.held>0}),o=P({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:TH}),r.invalidateQueries({queryKey:GH}),r.invalidateQueries({queryKey:NH(e.id)})])}}),s=e.topics.held>0?a.data??[]:[],c=()=>o.mutate(()=>zH(n,e.id));bx({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)(H,{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)(R,{size:`small`,variant:`secondary`,disabled:o.isPending,onClick:c,children:`Queue all ${String(s.length)}`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(V,{id:`planning.schedule.generate-now`,label:`Suggest topics now`}),(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:o.isPending||l,disabledReason:l?`Slopify is suggesting topics now.`:`Working…`,onClick:()=>o.mutate(()=>IH(n,e.id)),children:l?`Suggesting…`:`Suggest topics now`})]})}),(0,h.jsx)(X1,{schedule:e,title:`The last suggestion failed.`,retry:{run:()=>o.mutate(()=>IH(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)(pU,{label:`Suggestions for ${e.name}`,children:s.map(t=>(0,h.jsx)(mU,{title:t.title,meta:Z1(t.values),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:o.isPending,onClick:()=>o.mutate(()=>RH(n,e.id,t.id)),"aria-label":`Queue ${t.title}`,children:`Queue`}),(0,h.jsx)(wy,{size:`small`,label:`Reject ${t.title}`,disabled:o.isPending,onClick:()=>o.mutate(()=>BH(n,e.id,t.id)),children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})},t.id))}),(0,h.jsx)(SI,{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.`})]})}var bde={info:`text-ink-2`,error:`text-danger`,warning:`text-waiting`,success:`text-accent-ink`};function Q1({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:L(`flex min-h-8 min-w-0 flex-1 items-center gap-2 overflow-hidden text-small`,bde[t],n),children:e==null||e===!1?null:i===void 0?e:(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:i})})}function $1({status:e,children:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`action-bar`,className:L(`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)(Q1,{})}),(0,h.jsx)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:t})]})}function e0({split:e=`main-side`,className:t,children:n}){return(0,h.jsx)(`div`,{"data-slot":`board`,className:L(`sl-board`,`sl-board--${e}`,t),children:n})}function t0({as:e=`div`,label:t,className:n,children:r}){let i=L(`sl-board__column`,n);return e===`aside`?(0,h.jsx)(`aside`,{"aria-label":t,className:i,children:r}):t===void 0?(0,h.jsx)(`div`,{className:i,children:r}):(0,h.jsx)(`section`,{"aria-label":t,className:i,children:r})}var n0=`sl-tab inline-flex items-center gap-[6px]`;function r0({items:e,value:t,onChange:n,label:r,idPrefix:i,trailing:a,className:o}){let s=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:L(`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:n0,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 xde({items:e,label:t,className:n}){return(0,h.jsx)(`nav`,{"aria-label":t,className:L(`sl-tabs min-w-0`,n),children:e.map(e=>(0,h.jsx)(ha,{to:e.to,...e.search?{search:e.search}:{},activeOptions:{exact:!1,includeSearch:!1},className:n0,activeProps:{"aria-current":`page`},children:e.label},e.to))})}function i0({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 a0({title:e,children:t,actions:n,className:r}){return(0,h.jsxs)(`div`,{className:L(`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 o0(e){return e.channelId??`00000000-0000-4000-8000-000000000001`}function Sde({channelId:e}){let{api:t}=z(),n=_(),r=N(Hq(t)),i=N(Zb(t)),a=P({mutationFn:e=>cx(t,e.templateId,e.channelId),onSettled:()=>Promise.all([n.invalidateQueries({queryKey:Lq}),n.invalidateQueries({queryKey:qb})])}),o=(r.data??[]).filter(t=>o0(t)===e);return(0,h.jsxs)(`div`,{...Ob,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)(ha,{to:`/templates`,className:`underline`,children:`Library → Templates`}),`. Move to sends a template and its schedules to another channel.`,` `,(0,h.jsx)(V,{id:`planning.channel.template-move`,className:`-my-1 align-middle`})]}),(0,h.jsx)(Q1,{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)(a0,{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)(pU,{label:`Channel templates`,className:`[&_.sl-row__actions]:flex-wrap`,children:o.map(t=>(0,h.jsx)(mU,{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)(TV,{"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]})}var Cde={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},wde={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function Tde({channelId:e}){let{api:t}=z(),n=N(Hq(t)),r=N(EH(t)),i=new Set((n.data??[]).filter(t=>o0(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)(ha,{to:`/calendar`,search:{tab:`schedules`},className:`underline`,children:`Calendar → Schedules`}),`.`]}),(0,h.jsx)(Q1,{tone:r.error?`error`:`info`,className:`mb-2`,children:r.error?.message}),r.data&&a.length===0?(0,h.jsx)(a0,{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)(pU,{label:`Channel schedules`,children:a.map(e=>(0,h.jsx)(mU,{title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(_S,{tone:wde[e.status],children:Cde[e.status]}),` · ${e.nextRunAt===null?`No next run`:`Next run ${z1(e.nextRunAt,e.timezone)}`} · ${String(e.items.length)} queued`]})},e.id))}):null]})}var s0={llm:`Text model`,audio:`Voice model`,images:`Image model`,animate:`Animation model`};function c0({kind:e,id:t,name:n}){let{api:r}=z(),i=_(),a=N({queryKey:H1.retired,queryFn:()=>G1(r)}),o=P({mutationFn:e=>K1(r,e),onSuccess:()=>Promise.all([i.invalidateQueries({queryKey:H1.retired}),i.invalidateQueries({queryKey:Lq}),i.invalidateQueries({queryKey:TH})])}),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:[`${s0[t.slot]} ${t.model} is ${t.why===`retired`?`retired`:`no longer listed`}.`,t.blocked===null?``:` ${t.blocked}`,t.replacement===null&&t.blocked===null?` No replacement is suggested: choose another model in Settings → Models, or edit the ${e}.`:``]}),t.replacement===null?null:(0,h.jsx)(R,{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 l0(e){return UA(e)?`script`:`article`}function Ede(e){let{form:t}=e,n=[],r=[];if(m0(n,t.title),uj(t)&&m0(n,f0(e.prompts,`narration`,t.narrationPrompt??``)),t.sources.article===`generate`&&m0(n,f0(e.prompts,l0(t),t.articlePrompt)),t.sources.audio===`generate`&&(m0(n,p0(e.entries,`intro`,t.intro)),m0(n,p0(e.entries,`outro`,t.outro))),pj(t)&&m0(n,f0(e.prompts,`description`,t.descriptionPrompt??``)),jN(t)&&(m0(n,f0(e.prompts,`shorts`,t.shorts?.prompt??``)),m0(r,f0(e.prompts,`image`,t.shorts?.imagePrompt??``))),t.sources.images===`generate`){for(let n of t.imagePrompts)m0(r,f0(e.prompts,`image`,n.name));t.reference?.source===`prompt`&&m0(r,f0(e.prompts,`image`,t.reference.prompt))}return(t.sources.thumbnail===`from_prompt`||t.sources.thumbnail===`prompt_by_llm`)&&m0(r,f0(e.prompts,`thumbnail`,t.thumbnailPrompt)),pq(n,r)}function Dde(e){let t=Ede(e),n={form:e.form,entries:e.entries,slots:t.map(e=>e.name),silenceGapSeconds:e.silenceGapSeconds},r=zN(n),i=ej({draft:r,staged:RN(e.form.provided),requiredSlots:n.slots}),a=kN(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:Ode(e.form,a)}}var u0=`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 Ode(e,t){let n=kde(e);if(n!==void 0)return n;if(t.ok)return;let r=[...t.fields].sort((e,t)=>d0(e.field)-d0(t.field))[0];return r===void 0?void 0:{field:r.field,hint:Ade(e,r)}}function kde(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),jN(e)&&n.shortsMusic!==void 0&&r.push(n.shortsMusic),MN(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 d0(e){let t=u0.length;for(let[n,r]of u0.entries())(e===r||e.startsWith(`${r}.`))&&n<t&&(t=n);return t}function Ade(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 l0(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 the research notes 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 f0(e,t,n){if(n!==``)return e.find(e=>e.kind===t&&e.name===n)?.body}function p0(e,t,n){if(n!==``)return e.find(e=>e.category===t&&e.name===n)?.body}function m0(e,t){t!==void 0&&e.push(t)}function h0(e){let t=new Map,n=(e,n)=>{if(e)for(let r of dq(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`),uj(r)&&n(f0(i,`narration`,r.narrationPrompt??``),`Narration Preparation`),r.sources.article===`generate`&&n(f0(i,l0(r),r.articlePrompt),`Article`),r.sources.images===`generate`){for(let e of r.imagePrompts)n(f0(i,`image`,e.name),`Image: ${e.name}`);r.reference?.source===`prompt`&&n(f0(i,`image`,r.reference.prompt),`Establishing image`)}if((r.sources.thumbnail===`from_prompt`||r.sources.thumbnail===`prompt_by_llm`)&&n(f0(i,`thumbnail`,r.thumbnailPrompt),`Thumbnail`),r.sources.audio===`generate`)for(let e of[`intro`,`outro`])n(p0(a,e,r[e]),e===`intro`?`Intro`:`Outro`);return pj(r)&&n(f0(i,`description`,r.descriptionPrompt??``),`YouTube description`),jN(r)&&(n(f0(i,`shorts`,r.shorts?.prompt??``),`Shorts`),n(f0(i,`image`,r.shorts?.imagePrompt??``),`Shorts images`)),t}function g0(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 _0({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=g0;return t===void 0?(0,h.jsx)(pU,{label:`Keywords`,children:e.map(e=>(0,h.jsx)(mU,{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)(xV,{label:a(e.name),tip:s,help:l(e),error:n?.(`${r}.${e.name}`),children:(0,h.jsx)(CV,{"data-play-field":`${r}.${e.name}`,value:e.value,maxLength:c,...o===void 0?{}:{"aria-label":o(e.name)},spellCheck:!1,"aria-invalid":n?.(`${r}.${e.name}`)!==void 0,onChange:n=>t(e.name,n.target.value)})},e.name))})}var v0={lines:`One per line`,table:`Table`,yaml:`YAML / JSON`};function y0(e){return{mode:`lines`,rows:e,lines:Eq(e),base:e,yaml:``,columns:b0(e,[])}}function b0(e,t){return[...new Set([...t,...e.flatMap(e=>Object.keys(e.values))])]}function x0(e){return e.keywords.filter(t=>t!==e.topicKeyword&&(e.everyRun[t]??``).trim()===``)}function S0(e,t){if(t.form===void 0)return{rows:e.rows,problems:[]};if(e.mode===`yaml`){let n=Dq(e.yaml,{keywords:t.keywords,topicKeyword:t.topicKeyword,required:x0(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:Cq(n,{keywords:t.keywords,topicKeyword:t.topicKeyword,...e.mode===`table`?{required:x0(t)}:{},kept:t.kept})}}function jde(e,t,n){if(t===e.mode)return{queue:e,problems:[]};let r=e.rows;if(e.mode===`yaml`){let t=Dq(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`?Eq(r):e.lines,base:t===`lines`?r:e.base,yaml:t===`yaml`?Oq(r,n.topicKeyword):e.yaml,columns:b0(r,e.columns)},problems:[]}}function Mde({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=S0(e,n),y=e.mode===`yaml`?v.rows:e.rows,b=e=>p===void 0?void 0:yq(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=()=>Oq(S0(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=(n,r)=>t({...e,rows:e.rows.map((e,t)=>t===n?r:e)}),O=d.filter(t=>t!==f&&!e.columns.includes(t)),k=[...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)(V,{id:`planning.schedule.topics`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(Ab,{label:`How to write the topics`,tip:`planning.schedule.topic-format`,value:e.mode,options:Object.keys(v0).map(e=>({value:e,label:v0[e]})),onChange:r=>{let i=jde(e,r,n);c(i.problems),t(i.queue)}}),(0,h.jsxs)(R,{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)(gc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Copy as YAML`]}),(0,h.jsxs)(R,{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)(_c,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Export as YAML`]}),l===null?null:(0,h.jsx)(`span`,{role:`status`,className:`text-small text-ink-2`,children:l})]}),e.mode===`lines`?(0,h.jsx)(xV,{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)(wV,{rows:6,value:e.lines,onChange:n=>t({...e,lines:n.target.value,rows:Tq(n.target.value,e.base)}),placeholder:`Pyramids
269
269
  Sphinxes
270
- Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(xV,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(wV,{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)(Mde,{queue:e,onQueue:t,keyword:f,addable:O,setRow:D,titleOf:b}),k.length===0?null:(0,h.jsx)(SI,{tone:`danger`,title:`These topics can't be saved yet.`,children:(0,h.jsxs)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:[k.slice(0,8).map(e=>(0,h.jsx)(`li`,{children:e},e)),k.length>8?(0,h.jsx)(`li`,{children:`And ${String(k.length-8)} more.`}):null]})}),e.mode===`yaml`&&v.rows.length>0?(0,h.jsxs)(`section`,{"aria-label":`Project titles`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-1 text-small text-ink-2`,children:`Project titles, in order:`}),(0,h.jsxs)(`ol`,{className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:[v.rows.slice(0,20).map((e,t)=>(0,h.jsx)(`li`,{children:b(e)},t)),v.rows.length>20?(0,h.jsx)(`li`,{className:`list-none text-ink-3`,children:`And ${String(v.rows.length-20)} more.`}):null]})]}):null,a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Reading the template's keywords…`}):d.length===0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`This template has no keywords such as `,`{{Topic}}`,`, so each topic becomes the project's title.`]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:(0,h.jsx)(xV,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:g0({feeds:_(f)})},children:(0,h.jsx)(TV,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(_0,{keywords:d.filter(e=>e!==f).map(t=>({name:t,value:g[t]??``,feeds:_(t),...e.columns.includes(t)?{note:`Unless a topic sets its own.`}:{}})),onChange:i,fieldPrefix:`everyRun`,label:e=>`${e} (every run)`,inputLabel:e=>`${e} for every run`,tip:`planning.schedule.every-run`,maxLength:1e4})]}),e.mode===`lines`&&S!==void 0&&x!==void 0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Next project: `,(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:S}),f===null||C?null:(0,h.jsxs)(`span`,{className:`block text-ink-3`,children:[`The template's project title does not use `,`{{${f}}}`,`, so every project gets this title. Edit the template's title to include it.`]})]}):null]})}function Mde({queue:e,onQueue:t,keyword:n,addable:r,setRow:i,titleOf:a}){let o=n===null?`Title`:`{{${n}}}`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ob,children:[(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table`,"aria-label":`Topics`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,children:`#`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[o,(0,h.jsx)(V,{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)(wy,{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)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})},n)),(0,h.jsx)(`th`,{scope:`col`,children:`Project title`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:e.rows.map((n,r)=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`num`,children:r+1}),(0,h.jsx)(`td`,{children:(0,h.jsx)(CV,{"aria-label":`Topic ${String(r+1)} ${o}`,maxLength:200,value:n.title,onChange:e=>i(r,{...n,title:e.target.value})})}),e.columns.map(e=>(0,h.jsx)(`td`,{children:(0,h.jsx)(CV,{"aria-label":`Topic ${String(r+1)} ${e}`,maxLength:gq,placeholder:`Every-run value`,value:n.values[e]??``,onChange:t=>i(r,{...n,values:{...n.values,[e]:t.target.value}})})},e)),(0,h.jsx)(`td`,{className:`min-w-[180px] text-small text-ink-2`,children:a(n)??`—`}),(0,h.jsx)(`td`,{children:(0,h.jsx)(wy,{label:`Remove topic ${String(r+1)}`,size:`small`,onClick:()=>t({...e,rows:e.rows.filter((e,t)=>t!==r)}),children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})})]},r))})]})}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(R,{size:`small`,onClick:()=>t({...e,rows:[...e.rows,{title:``,values:{}}]}),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]}),r.length===0?null:(0,h.jsxs)(TV,{"aria-label":`Set a keyword per topic`,value:``,className:`w-auto`,onChange:n=>{let r=n.target.value;r!==``&&t({...e,columns:[...e.columns,r]})},children:[(0,h.jsx)(`option`,{value:``,children:`Set a keyword per topic…`}),r.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))]})]})]})}var Nde=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Pde({templates:e,pending:t,onCreated:n,onError:r,editing:i,onCancel:a,error:o,onBusy:s}){let{api:c}=z(),[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`?Yue(i.cadence.at,i.timezone):``),[y,b]=(0,m.useState)(i&&i.cadence.kind!==`once`?i.cadence.time:`09:00`),[x,S]=(0,m.useState)(i?.cadence.kind===`weekly`?i.cadence.days:[1,3,5]),[C,w]=(0,m.useState)(()=>i?.timezone??(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`)),[T,E]=(0,m.useState)(i?.missedPolicy??`skip`),[D,O]=(0,m.useState)(i?.spendLimitCents?.toString()??``),[k,A]=(0,m.useState)(()=>y0(i?.items??[])),[ee,te]=(0,m.useState)(i?.topicKeyword??null),[ne,j]=(0,m.useState)(i?.values??{}),[re,M]=(0,m.useState)(i?.brief??``),[ie,ae]=(0,m.useState)(i?.topicGeneration??lH),[oe,se]=(0,m.useState)(!1),[ce,le]=(0,m.useState)(!1),ue=(0,m.useRef)(!1),de=(0,m.useRef)(null),fe=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,pe=fe.find(e=>e.id===d),me=N({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await Uq(c,d);if(!e.ok)throw Error(e.message);return e.value}}),he=me.data?.document.form,ge=he===void 0?void 0:h0({form:he,prompts:me.data?.document.librarySnapshot?.prompts??[],entries:me.data?.document.librarySnapshot?.entries??[]}),_e=he===void 0?[]:_q(he),ve=ee!==null&&_e.includes(ee)?ee:_e.find(e=>he?.title.includes(`{{${e}}}`))??_e[0]??null,ye=Object.fromEntries(_e.filter(e=>e!==ve).map(e=>[e,ne[e]??he?.values[e]??``])),be={keywords:_e,topicKeyword:ve,everyRun:ye,form:he,kept:i?.items??[],...ge===void 0?{}:{origins:ge}},xe=S0(k,be);async function Se(e){if(e.preventDefault(),!(ue.current||t)){if(!pe&&!de.current){r(`Choose a template before saving the schedule.`);return}if(!de.current&&xe.problems.length>0){r(`Fix the topics first. ${xe.problems.slice(0,3).join(` `)}`);return}if(xe.rows.length>500){r(`Keep the list to 500 topics or fewer.`);return}if(re.trim().length>4e3){r(`Keep the series brief to ${String(sH)} characters or fewer.`);return}if(ie.llm!==null&&(ie.llm.provider===``||ie.llm.model===``)){r(`Pick both a provider and a model for topic generation, or choose Use the template's LLM.`);return}if(p===`weekly`&&x.length===0){r(`Choose at least one weekday for a weekly schedule.`);return}ue.current=!0,se(!0),s(!0);try{if(!de.current){if(!pe)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!$V(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Xue(_,e)}:p===`weekly`?{kind:p,time:y,days:x}:{kind:p,time:y},n=D.trim()===``?null:Number(D);if(n!==null&&(!Number.isInteger(n)||n<0))throw Error(`Enter the spend limit as a whole number of cents, 0 or more (500 is $5.00), or leave it empty.`);let r={id:i?.id??crypto.randomUUID(),name:l.trim(),templateId:pe.id,templateVersion:pe.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:xe.rows,topicKeyword:ve,values:ye,brief:re.trim()===``?null:re.trim(),topicGeneration:ie};de.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=de.current,{id:t,...a}=e,o=`mutationId`in a?await kH(c,t,a):await OH(c,e);if(!o.ok){de.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}de.current=null,le(!1),u(``),A(y0([])),n()}catch(e){le(de.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{ue.current=!1,se(!1),s(de.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(SI,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{onSubmit:e=>void Se(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)(xV,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,children:(0,h.jsx)(CV,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(xV,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,children:(0,h.jsxs)(TV,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:fe.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),fe.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(xV,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(TV,{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)(xV,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,children:(0,h.jsx)(CV,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(xV,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,children:(0,h.jsx)(CV,{required:!0,type:`time`,value:y,onChange:e=>b(e.target.value)})}),p===`weekly`?(0,h.jsxs)(`fieldset`,{className:`m-0 min-w-0 border-0 p-0`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`sl-field__label mb-2 flex items-center gap-1`,children:[`Weekdays`,(0,h.jsx)(V,{id:`planning.schedule.weekdays`,className:`-my-1`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Nde.map(([e,t])=>(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),onChange:t=>S(n=>t.target.checked?[...n,e]:n.filter(t=>t!==e))}),t]},e))})]}):(0,h.jsx)(`div`,{}),(0,h.jsx)(xV,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,children:(0,h.jsx)(CV,{value:C,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(xV,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(TV,{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)(xV,{label:`Spend ceiling (cents, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,children:(0,h.jsx)(CV,{inputMode:`numeric`,value:D,onChange:e=>O(e.target.value),placeholder:`1000`})}),(0,h.jsx)(jde,{queue:k,onQueue:A,context:be,onKeyword:te,onValue:(e,t)=>j(n=>({...n,[e]:t})),loading:d!==``&&me.isPending,exportName:l}),(0,h.jsx)(Fde,{brief:re,onBrief:M,generation:ie,onGeneration:ae,templateLlm:he?.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)(R,{type:`submit`,variant:`primary`,disabled:t||oe||fe.length===0&&!ce,children:oe?`Saving…`:ce?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(R,{variant:`quiet`,disabled:oe||ce,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Fde({brief:e,onBrief:t,generation:n,onGeneration:r,templateLlm:i}){let{api:a}=z(),o=N({...eb(a),enabled:n.mode!==`off`}),s=n.llm;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topic generation`,(0,h.jsx)(V,{id:`planning.schedule.generation`})]}),(0,h.jsx)(xV,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,children:(0,h.jsx)(wV,{rows:3,maxLength:sH,value:e,onChange:e=>t(e.target.value),placeholder:`Ancient history, documentary style. Famous rulers and places first.`})}),(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,children:(0,h.jsxs)(TV,{value:n.mode,onChange:e=>{let t=e.target.value;r({...n,mode:t===`queue`||t===`hold`?t:`off`})},children:[(0,h.jsx)(`option`,{value:`off`,children:`Off: add topics yourself`}),(0,h.jsx)(`option`,{value:`queue`,children:`Generate and queue directly`}),(0,h.jsx)(`option`,{value:`hold`,children:`Generate and hold for approval`})]})}),n.mode===`off`?null:(0,h.jsx)(xV,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(CV,{type:`number`,min:1,max:100,value:String(n.keepAtLeast),onChange:e=>{let t=Math.round(Number(e.target.value));r({...n,keepAtLeast:Number.isFinite(t)?Math.min(100,Math.max(1,t)):1})}})})]}),n.mode===`off`?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s===null,onChange:e=>r({...n,llm:e.target.checked?null:{provider:i?.provider??``,model:i?.model??``}})}),`Use the template's LLM`,s===null&&i!==void 0&&i.provider!==``?` (${i.provider} · ${i.model})`:``]}),(0,h.jsx)(V,{id:`planning.schedule.generation-llm`,className:`-my-1`})]}),s===null?null:(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(RV,{label:`Provider`,family:`llm`,providers:o.data?.providers??[],value:s.provider,problem:o.error?.message,onPick:e=>r({...n,llm:{provider:e,model:``}})}),(0,h.jsx)(zV,{label:`Model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>r({...n,llm:{...s,model:e}})})]})]})]})}function Ide({schedule:e}){let{api:t}=z(),n=_(),r=Oy(),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(!1),c=(0,m.useRef)(!1),[l,u]=(0,m.useState)(``),d=(0,m.useRef)(e);e.version>d.current.version&&(d.current=e);let f=d.current.items,p=e.topicKeyword===null?`title`:`{{${e.topicKeyword}}}`,g=async(e,i,o)=>{if(c.current)return!1;c.current=!0;let l=d.current;s(!0),a(null);try{let s=await UH(t,l.id,{baseVersion:l.version,items:e});return s.ok?(d.current=s.value,n.setQueryData(TH,e=>e?.map(e=>e.id===s.value.id?s.value:e)),n.invalidateQueries({queryKey:GH}),r(i,`success`,o?{label:`Undo`,run:()=>void g(l.items,`Put the topics back as they were.`,!1)}:void 0),!0):(a(s.reason===`conflict`?`The topics weren't saved: this schedule changed since the page loaded, possibly because a run just took a topic. The list now shows the latest; make your change again.`:`The topics weren't saved: ${s.message}`),await n.invalidateQueries({queryKey:TH}),!1)}catch(e){return a(`The topics weren't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then try again.`),!1}finally{c.current=!1,s(!1)}},v=async e=>{e.preventDefault();let t=l.trim();if(t===``){a(`Write the new topic's ${p} first, then press Add topic.`);return}await g([...f,{title:t,values:{}}],`Added “${t}”.`,!0)&&u(``)},y=(e,t)=>{let n=f[e];if(n!==void 0&&t.trim()!==n.title){if(t.trim()===``){a(`Topic ${String(e+1)} needs a ${p}. Write one, or press its Remove button.`);return}g(f.map((n,r)=>r===e?{...n,title:t.trim()}:n),`Renamed to “${t.trim()}”.`,!0)}},b=(e,t)=>{let n=f[e];if(n===void 0)return;let r=[...f];r.splice(e,1),r.splice(e+t,0,n),g(r,`Moved “${n.title}” ${t===-1?`up`:`down`}.`,!0)},x=e=>{let t=f[e];t!==void 0&&g(f.filter((t,n)=>n!==e),`Removed “${t.title}”.`,!0)};return(0,h.jsxs)(`section`,{"aria-label":`Queued topics`,className:`mt-6`,...Ob,children:[(0,h.jsx)(H,{as:`h3`,title:`Queued topics · ${String(f.length)}`,info:`planning.schedule.inline-topics`,meta:e.topicKeyword===null?`Each topic becomes the next project's title.`:`Each topic fills ${p}; the next run takes the first.`}),i===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:i}),f.length===0?null:(0,h.jsx)(pU,{label:`Topics of ${e.name}`,className:`mt-2`,children:f.map((e,t)=>(0,h.jsx)(Lde,{index:t,title:e.title,count:f.length,busy:o,onRename:e=>y(t,e),onMove:e=>b(t,e),onRemove:()=>x(t)},`${String(t)}:${e.title}`))}),(0,h.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-center gap-2`,onSubmit:e=>void v(e),children:[(0,h.jsx)(CV,{"aria-label":`New topic`,placeholder:e.topicKeyword===null?`New topic`:`New ${p}`,maxLength:200,value:l,className:`min-w-0 flex-1`,onChange:e=>u(e.target.value)}),(0,h.jsxs)(R,{type:`submit`,size:`small`,disabled:o||f.length>=500,disabledReason:o?`Saving the last change`:`A queue holds at most 500 topics`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]})]})]})}function Lde({index:e,title:t,count:n,busy:r,onRename:i,onMove:a,onRemove:o}){let[s,c]=(0,m.useState)(t);(0,m.useEffect)(()=>c(t),[t]);let l=`Topic ${String(e+1)}`;return(0,h.jsx)(mU,{lead:(0,h.jsx)(`span`,{className:`w-6 text-small text-ink-3 tabular-nums`,children:e+1}),title:(0,h.jsx)(CV,{"aria-label":l,maxLength:200,value:s,onChange:e=>c(e.target.value),onBlur:()=>i(s),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i(s)):e.key===`Escape`&&c(t)}}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wy,{size:`small`,label:`Move ${t} up`,disabled:r||e===0,onClick:()=>a(-1),children:(0,h.jsx)(ic,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Move ${t} down`,disabled:r||e===n-1,onClick:()=>a(1),children:(0,h.jsx)(tc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Remove ${t}`,disabled:r,onClick:o,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function Rde({pickedId:e,onPick:t}={}){let{api:n}=z(),r=_(),i=N(EH(n)),a=N(Hq(n)),[o,s]=(0,m.useState)(null),c=Oy(),[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=N(Zb(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=N(KH(n,E.from,E.to)),O=new Map;for(let e of D.data?.runs??[])e.renderedTitle!==null&&!O.has(e.scheduleId)&&O.set(e.scheduleId,e.renderedTitle);let[k,A]=(0,m.useState)(``),ee=e=>{if(k===``)return!0;let t=a.data?.find(t=>t.id===e.templateId);return(t?o0(t):Wb)===k},te=i.data?.filter(e=>e.deletedAt===null&&ee(e))??[],ne=i.data?.filter(e=>e.deletedAt!==null)??[],j=i.data?.find(e=>e.id===b)??te[0]??null,re=P({onError:e=>s(e.message),onSettled:async()=>{w.current=!1,await r.invalidateQueries({queryKey:TH})},mutationFn:async e=>e(),onSuccess:async e=>{if(!e.ok){s(e.message);return}s(null)}}),M=e=>{w.current||(w.current=!0,s(null),re.mutate(e))},ie=d||l!==null,ae=()=>{u(null),f(!1),s(null)},oe=a.data?.length===0,se=()=>{ie||oe||(u(null),f(!0),s(null))},ce=e=>{f(!1),x(e.id),u(e),s(null)};bx({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:se}),Yx(Wx.newSchedule,()=>{oe?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`):se()},a.data!==void 0);let le=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,ue=re.isPending||p||ie;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:oe?(0,h.jsxs)(h.Fragment,{children:[`Save a template in`,` `,(0,h.jsx)(ha,{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)(V,{id:`planning.schedules`})]})}),(0,h.jsxs)(Ey,{children:[(0,h.jsxs)(TV,{"aria-label":`Filter schedules by channel`,value:k,className:`w-auto min-w-[160px]`,onChange:e=>A(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(T.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsxs)(R,{variant:`primary`,onClick:se,disabled:ie||oe,disabledReason:oe?`Save a template in Library → Templates first`:`Finish or cancel the open form first`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New schedule`]})]})]}),(0,h.jsx)(Q1,{tone:ie?`info`:le?.tone??`info`,className:`mb-2`,children:ie?void 0:le?.text}),(0,h.jsx)(jq,{className:`min-[768px]:grid-cols-[minmax(320px,460px)_minmax(0,1fr)]`,list:(0,h.jsxs)(h.Fragment,{children:[i.data&&te.length===0?(0,h.jsx)(a0,{title:k===``?ne.length===0?`No schedules yet`:`No active schedules`:`No schedules run this channel's templates`,children:k===``?ne.length===0?`Your first one can be a one-off run or a recurring series. Press New schedule.`:`Create one with New schedule, or review deleted history below.`:`Pick All channels to see the others, or make one from this channel's templates.`}):null,te.length>0?(0,h.jsx)(pU,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:te.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(w0,{schedule:e,nextTitle:O.get(e.id),selected:!ie&&j?.id===e.id,pending:ue,onSelect:()=>x(e.id),onEdit:()=>ce(e),onAction:M,onConfirm:t=>C({kind:t,schedule:e})}),(0,h.jsx)(c0,{kind:`schedule`,id:e.id,name:e.name})]},e.id))}):null,ne.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 · `,ne.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)(pU,{label:`Deleted schedules`,children:ne.map(e=>(0,h.jsx)(w0,{schedule:e,nextTitle:void 0,selected:!ie&&j?.id===e.id,pending:!1,onSelect:()=>x(e.id),onEdit:()=>void 0,onAction:M,onConfirm:()=>void 0},e.id))})]}):null]}),detail:ie?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{kicker:l?l.name:void 0,title:l?`Edit schedule`:`New schedule`,className:`mb-4`}),(0,h.jsx)(Pde,{onBusy:g,editing:l,onCancel:()=>{p||ae()},templates:a.data??[],pending:re.isPending,error:o,onCreated:()=>{c(l?`Schedule updated.`:`Schedule saved. It will run automatically while Slopify is open.`,`success`),ae(),r.invalidateQueries({queryKey:TH})},onError:e=>{s(e),r.invalidateQueries({queryKey:TH})}},l?.id??`new`)]}):j?(0,h.jsx)(Hde,{schedule:j,pending:ue,onAction:M,onConfirm:e=>C({kind:e,schedule:j})},j.id):null}),(0,h.jsx)(jy,{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:re.isPending,onCancel:()=>{re.isPending||C(null)},onConfirm:()=>{if(!S)return;let{kind:e,schedule:t}=S;M(async()=>{let r=e===`delete`?await jH(n,t.id,t.version):await AH(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}function zde(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}var Bde={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Vde={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function C0({schedule:e}){return e.deletedAt===null?(0,h.jsx)(_S,{tone:Vde[e.status],children:Bde[e.status]}):(0,h.jsx)(_S,{tone:`off`,children:`Deleted`})}function w0({schedule:e,nextTitle:t,selected:n,pending:r,onSelect:i,onEdit:a,onAction:o,onConfirm:s}){let{api:c}=z(),l=e.deletedAt===null,u=l&&(e.status===`active`||e.status===`paused`),d=e.status===`canceled`||e.status===`completed`;return(0,h.jsx)(mU,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(C0,{schedule:e}),` · ${zde(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${z1(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${z1(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)(R,{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)(R,{variant:`quiet`,size:`small`,"aria-label":`Resume ${e.name}`,disabled:r,onClick:()=>o(()=>AH(c,e.id,`resume`,e.version)),children:`Resume`}):(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Pause ${e.name}`,disabled:r||e.status!==`active`,disabledReason:`Only an active schedule can pause`,onClick:()=>o(()=>AH(c,e.id,`pause`,e.version)),children:`Pause`}),(0,h.jsx)(R,{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 Hde({schedule:e,pending:t,onAction:n,onConfirm:r}){let{api:i}=z(),a=N({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await DH(i,e.id);if(!t.ok)throw Error(t.message);return t.value},refetchInterval:3e4}),o=e.deletedAt===null,s=o&&(e.status===`active`||e.status===`paused`),c=e.status===`paused`,l=[[`When`,e.cadence.kind===`once`?`Once, ${z1(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`:z1(e.nextRunAt,e.timezone)],[`Topics`,e.items.length===0?e.topicGeneration.mode===`off`?`Template as saved`:`No topics queued`:`${String(e.items.length)} ${e.items.length===1?`topic`:`topics`} left`],[`Missed runs`,e.missedPolicy===`skip`?`Skip`:`Run once on reopening`],[`Overlap`,`Skip`],[`Spend ceiling`,e.spendLimitCents===null?`Not set`:`${String(e.spendLimitCents)} cents`]];return(0,h.jsxs)(`section`,{"aria-label":`${e.name} detail`,children:[o&&s?(0,h.jsx)(Ude,{schedule:e,paused:c,onAction:n}):null,(0,h.jsx)(H,{kicker:(0,h.jsx)(C0,{schedule:e}),title:e.name,meta:e.topics.held>0?`${String(e.topics.held)} topics waiting for you`:void 0,children:o?(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Cancel ${e.name}`,disabled:t||!s,disabledReason:`Only an active or paused schedule can be canceled`,onClick:()=>r(`cancel`),children:`Cancel schedule`}):null}),(0,h.jsx)(`dl`,{className:`m-0 mt-4 grid grid-cols-1 gap-x-6 gap-y-3 text-small min-[600px]:grid-cols-2`,children:l.map(([e,t])=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`dt`,{className:`sl-kicker`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-words text-ink`,children:t})]},e))}),s?(0,h.jsx)(Ide,{schedule:e}):null,(0,h.jsx)(gde,{schedule:e}),(0,h.jsx)(Mq,{className:`my-6`}),(0,h.jsx)(H,{as:`h3`,title:`Run history`}),(0,h.jsx)(`div`,{className:`mt-3`,children:a.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading history…`}):a.error?(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The run history couldn't be loaded: ${a.error.message} It tries again every 30 seconds.`}):a.data.runs.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No runs yet.`}):(0,h.jsx)(pU,{label:`Runs of ${e.name}`,children:a.data.runs.map(t=>(0,h.jsx)(mU,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${z1(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)(ha,{className:`underline hover:text-ink`,to:`/projects/$projectId`,params:{projectId:e},children:[`Project `,t+1]},e))}):`No projects`},t.id))})})]})}function Ude({schedule:e,paused:t,onAction:n}){let{api:r}=z();return bx({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>AH(r,e.id,t?`resume`:`pause`,e.version))}),null}var T0=`https://www.youtube.com/upload`,Wde=[`video`,`title`,`description`,`thumbnails`,`playlist`,`audience`,`altered`,`tags`];function Gde(e){return e.join(`, `)}var Kde=[.75,1,1.25,1.5,1.75,2];function E0(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 D0(e){return`${String(e)}×`}function qde(e,t){return e.filter(e=>e.start<=t).at(-1)}function O0(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var k0=(e,t,n)=>Math.min(n,Math.max(t,e));function A0(){let e=(0,m.useRef)(null),t=(0,m.useId)(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(0),[c,l]=(0,m.useState)(0),[u,d]=(0,m.useState)(1),[f,p]=(0,m.useState)(!1),[h,g]=(0,m.useState)(1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(null),[x,S]=(0,m.useState)(!1),C=Number.isFinite(o)&&o>0,w=()=>{let t=e.current;t!==null&&(t.paused||t.ended?t.play()?.catch(()=>void 0):t.pause())},T=t=>{let n=e.current;if(n===null||!C)return;let r=k0(t,0,o);n.currentTime=r,a(r)},E=t=>T((e.current?.currentTime??i)+t),D=t=>{let n=e.current;if(n===null)return;let r=k0(Math.round(t*100)/100,0,1);n.volume=r,n.muted=r===0,d(r),p(r===0)},O=()=>{let t=e.current;t!==null&&(t.muted=!t.muted,p(t.muted))};return{media:e,menuId:t,playing:n,current:i,duration:o,buffered:c,known:C,volume:u,muted:f,rate:h,menu:_,setMenu:v,hover:y,setHover:b,seeking:x,setSeeking:S,toggle:w,seekTo:T,jump:E,setLevel:D,toggleMute:O,pickRate:n=>{let r=e.current;r!==null&&(r.playbackRate=n),g(n),v(!1),document.getElementById(`${t}-button`)?.focus()},keyAction:e=>{let t=e.length===1?e.toLowerCase():e;if(t===` `||t===`k`)return w;if(t===`j`)return()=>E(-10);if(t===`l`)return()=>E(10);if(t===`ArrowLeft`)return()=>E(-5);if(t===`ArrowRight`)return()=>E(5);if(t===`m`)return O;if(/^[0-9]$/.test(t))return()=>T(Number(t)/10*o)},events:{onPlay:()=>r(!0),onPause:()=>r(!1),onEnded:()=>r(!1),onTimeUpdate:e=>{x||a(e.currentTarget.currentTime)},onDurationChange:e=>s(e.currentTarget.duration),onLoadedMetadata:e=>s(e.currentTarget.duration),onProgress:e=>{let t=e.currentTarget.buffered;l(t.length>0?t.end(t.length-1):0)},onVolumeChange:e=>{d(e.currentTarget.volume),p(e.currentTarget.muted)},onRateChange:e=>g(e.currentTarget.playbackRate)}}}function j0(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:k0((t-n.left)/n.width,0,1)}function M0(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function N0({controls:e,className:t}){return(0,h.jsx)(wy,{size:`small`,label:e.playing?`Pause`:`Play`,className:t,onClick:e.toggle,children:e.playing?(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})})}function P0({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:E0(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?E0(e.duration):`-:--`}`})]})}function F0({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=Xde(r),d=n===void 0?void 0:Yde(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(j0(r.current,t.clientX)*a))},g=t=>{let n=j0(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{M0(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:qde(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":`${E0(o)} of ${i?E0(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}),E0(x)]})]})}function I0({controls:e}){let t=(0,m.useRef)(null),{muted:n,volume:r}=e,i=n?0:r;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wy,{size:`small`,label:n?`Unmute`:`Mute`,"aria-pressed":n,className:`sl-player__mute`,onClick:e.toggleMute,children:n||r===0?(0,h.jsx)(Wc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Uc,{"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(j0(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel(j0(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];M0(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 L0({controls:e}){let{menuId:t,menu:n,rate:r}=e;return(0,h.jsxs)(`span`,{className:`sl-player__speed`,children:[(0,h.jsx)(R,{id:`${t}-button`,variant:`quiet`,size:`small`,className:`sl-player__rate`,"aria-label":`Playback speed, ${D0(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:D0(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`){M0(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];M0(n,()=>i?.focus())},children:Kde.map(t=>(0,h.jsx)(R,{variant:`quiet`,size:`small`,role:`menuitemradio`,"aria-checked":t===r,className:L(`sl-player__option`),autoFocus:t===r,onClick:()=>e.pickRate(t),children:t===1?`Normal`:D0(t)},t))}):null]})}var Jde=4;function Yde(e,t){let n=Math.floor(t/Jde);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 Xde(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 Zde=2500;function R0({src:e,poster:t,label:n,portrait:r=!1,captions:i,chapters:a=[],ref:o,className:s,children:c}){let l=A0(),u=l.media,d=(0,m.useRef)(null),f=(0,m.useRef)(void 0),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(0),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),[T,E]=(0,m.useState)(!1),[D,O]=(0,m.useState)(!0),{playing:k,menu:A,seeking:ee,hover:te,events:ne}=l,j=i!==void 0||y>0,re=typeof document<`u`&&`pictureInPictureEnabled`in document&&document.pictureInPictureEnabled===!0,M=(0,m.useCallback)(()=>{O(!0),clearTimeout(f.current),f.current=setTimeout(()=>O(!1),Zde)},[]);(0,m.useEffect)(()=>()=>clearTimeout(f.current),[]);let ie=k&&!D&&!A&&!T&&!ee&&te===null;(0,m.useEffect)(()=>{let e=()=>S(document.fullscreenElement===d.current);return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,m.useEffect)(()=>{let e=u.current;if(e===null)return;let t=()=>w(!0),n=()=>w(!1);return e.addEventListener(`enterpictureinpicture`,t),e.addEventListener(`leavepictureinpicture`,n),()=>{e.removeEventListener(`enterpictureinpicture`,t),e.removeEventListener(`leavepictureinpicture`,n)}},[u]),(0,m.useEffect)(()=>{let e=u.current?.textTracks;if(e!==void 0)for(let t=0;t<e.length;t+=1){let n=e[t];n!==void 0&&(n.mode=_&&t===0?`showing`:`hidden`)}},[_,u]);let ae=()=>{let e=u.current;e!==null&&(e.paused||e.ended)&&g(!0),l.toggle()},oe=()=>{let e=d.current;e!==null&&(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()?.catch(()=>void 0))},se=()=>{let e=u.current;e!==null&&(document.pictureInPictureElement===e?document.exitPictureInPicture?.().catch(()=>void 0):e.requestPictureInPicture?.().catch(()=>void 0))};return(0,h.jsxs)(`div`,{ref:d,"data-slot":`player`,"data-state":k?`playing`:`paused`,className:L(`sl-player`,r&&`sl-player--portrait`,ie&&`sl-player--bare`,x&&`sl-player--full`,s),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`?ae:n===`f`?oe:n===`c`?j?()=>v(e=>!e):void 0:l.keyAction(n);r!==void 0&&(e.preventDefault(),e.stopPropagation(),M(),r())},onPointerMove:M,onPointerDown:M,onFocus:()=>E(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(E(!1),l.setMenu(!1))},children:[(0,h.jsxs)(`video`,{ref:O0(u,o),src:e,poster:t,preload:`metadata`,playsInline:!0,"aria-label":n,onClick:ae,...ne,onPlay:e=>{ne.onPlay(e),g(!0),M()},onPause:e=>{ne.onPause(e),O(!0)},onEnded:e=>{ne.onEnded(e),O(!0)},onLoadedMetadata:e=>{ne.onLoadedMetadata(e),b(e.currentTarget.textTracks?.length??0)},children:[i===void 0?null:(0,h.jsx)(`track`,{kind:`captions`,src:i.src,srcLang:i.lang,label:i.label}),c]}),p?null:(0,h.jsx)(wy,{label:`Play ${n}`,className:`sl-player__big`,onClick:ae,children:(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsxs)(`div`,{className:`sl-player__bar`,role:`group`,"aria-label":`${n} controls`,children:[(0,h.jsx)(N0,{controls:{...l,toggle:ae}}),(0,h.jsx)(P0,{controls:l}),(0,h.jsx)(F0,{controls:l,chapters:a}),(0,h.jsx)(I0,{controls:l}),(0,h.jsx)(L0,{controls:l}),j?(0,h.jsx)(wy,{size:`small`,label:`Captions`,"aria-pressed":_,onClick:()=>v(e=>!e),children:(0,h.jsx)(cc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,re?(0,h.jsx)(wy,{size:`small`,label:`Picture in picture`,"aria-pressed":C,className:`sl-player__pip`,onClick:se,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(wy,{size:`small`,label:x?`Exit full screen`:`Full screen`,"aria-pressed":x,onClick:oe,children:x?(0,h.jsx)(Oc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Dc,{"aria-hidden":`true`,strokeWidth:1.75})})]})]})}var Qde={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function z0({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:L(`sl-media m-0`,p),"data-slot":`media-frame`,children:[(0,h.jsxs)(`div`,{className:L(`sl-media__frame`,Qde[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)(gS,{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:L(`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 B0({shorts:e=!1,density:t=`default`,list:n=!1,className:r,children:i,label:a}){let o=L(`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 V0({items:e,index:t,onIndex:n,onClose:r,actions:i}){let a=t===null?void 0:e[t],o=e.length,s=e=>{t!==null&&o!==0&&n((t+e+o)%o)};return(0,h.jsx)(_m,{open:a!==void 0,onOpenChange:e=>{e||r()},children:(0,h.jsx)(xm,{children:(0,h.jsx)(Em,{className:`sl-lightbox sl-enter`,onKeyDown:e=>{e.key===`ArrowRight`?(e.preventDefault(),s(1)):e.key===`ArrowLeft`&&(e.preventDefault(),s(-1))},"aria-describedby":void 0,children:a===void 0||t===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`sl-lightbox__bar`,children:[(0,h.jsx)(jm,{className:`m-0 text-small font-semibold`,children:`${String(t+1)} of ${String(o)} · ${a.alt}`}),(0,h.jsxs)(`div`,{className:`sl-btn-row`,children:[i?.(a,t),(0,h.jsx)(wy,{label:`Previous`,onClick:()=>s(-1),disabled:o<2,children:(0,h.jsx)(dc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{label:`Next`,onClick:()=>s(1),disabled:o<2,children:(0,h.jsx)(fc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Fm,{asChild:!0,children:(0,h.jsx)(wy,{label:`Close`,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})})]})]}),(0,h.jsx)(`div`,{className:`sl-lightbox__stage`,children:a.kind===`video`?(0,h.jsx)(R0,{src:a.src,label:a.alt,className:`sl-lightbox__player`,...a.poster===void 0?{}:{poster:a.poster}},a.src):(0,h.jsx)(`img`,{src:a.src,alt:a.alt},a.src)}),a.caption===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`p`,{className:`sl-lightbox__caption`,children:a.caption})]})})})})}var H0={location:pO(`docker-host`),path:W().min(1)},U0=tO([q({opened:pO(!0)}).strict(),q({opened:pO(!0),...H0}).strict(),q({opened:pO(!1),...H0}).strict()]),W0=rO(`kind`,[q({kind:pO(`allAffected`)}).strict(),q({kind:pO(`selected`),workKeys:K(W().min(1).max(200)).min(1).max(1e4)}).strict()]),G0=W().min(1).max(64),$de=q({baseRevisionId:G0,request:W0}).strict(),efe=q({baseRevisionId:G0,idempotencyKey:wD(),previewId:W().min(1).max(64),acknowledgeUnknownCosts:GD(),confirmedProvidedWorkKeys:K(W().min(1).max(200)).max(1e4)}).strict(),tfe=q({stage:W(),low:G().finite().nonnegative().nullable(),high:G().finite().nonnegative().nullable(),detail:W(),onPlan:GD().optional(),apiLow:G().finite().nonnegative().nullable().optional(),apiHigh:G().finite().nonnegative().nullable().optional()}),nfe=q({currency:pO(`USD`),rows:K(tfe),low:G().finite().nonnegative(),high:G().finite().nonnegative(),unknown:G().int().nonnegative(),apiLow:G().finite().nonnegative().optional(),apiHigh:G().finite().nonnegative().optional(),apiUnknown:G().int().nonnegative().optional(),expectedWords:G().finite().nonnegative(),catalogueDate:W().nullable(),assumptions:K(W())}),K0=q({revisionId:G0,admissionId:W().min(1).max(64),workIds:K(W().min(1).max(64)),replayed:GD()}),rfe=q({id:W().min(1).max(64),projectId:W().min(1).max(64),baseRevisionId:G0,planFingerprint:W().min(1),selection:W0,changedInputs:K(q({path:W(),before:W().nullable(),after:W().nullable()})),work:K(q({key:W(),stage:J(FS),kind:J([`provider`,`local`,`provided`]),disposition:J([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:W(),fingerprint:W(),dependsOn:K(W()),reason:W(),inflight:GD(),pieceIds:K(W())})),retained:K(q({slot:W(),outputId:W(),assetId:W(),state:J([`ready`,`outdated`,`review`])})),providedReuseRequired:K(W()),costs:nfe,wholeRequestNotice:W().nullable(),warnings:K(W()),review:q({inputChanges:K(q({label:W(),before:W().nullable(),after:W().nullable()})),requests:K(q({key:W(),label:W(),text:W().nullable(),settings:W().nullable()}))}).optional()}),q0=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],J0=[`pending`,`running`,`done`,`failed`];q({id:W(),stage_id:W(),kind:J(q0),idx:G(),state:J(J0),payload:W().nullable()});var ife=`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(`.`),afe=[`copying`,`staged`],ofe=q({segment:J([`body`,`intro`,`outro`]).optional(),subtitleOmissions:K(q({start:G().finite().nonnegative(),text:W()})).optional(),subtitlesMode:J([`off`,`files`,`burn-in`]).optional(),promptName:W().optional(),prompt:W().optional(),index:G().optional(),short:G().optional(),format:J([`16:9`,`9:16`]).optional(),sentences:sO([G(),G()]).optional(),warnings:K(W()).optional(),provider:W().optional(),model:W().optional(),voice:W().optional(),loudness:q({pieces:G(),skipped:G(),spreadBefore:G(),spreadAfter:G(),target:G()}).optional(),master:q({target:G(),integrated:G(),truePeak:G()}).optional()}),sfe=q({id:W(),projectId:W(),stageKind:J(FS),role:J(ife),path:W(),originalFilename:W().nullable(),bytes:G().nonnegative(),durationMs:G().nonnegative().nullable(),meta:ofe,createdAt:W()});q({id:W(),stageKind:J(FS),path:W(),originalFilename:W(),bytes:G().nonnegative(),state:J(afe),createdAt:W()});var Y0=W().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),X0=W().min(1).max(256),cfe=lO(X0,Y0),lfe=q({id:Y0,text:W().trim().min(1).max(1e4),start:G().finite().nonnegative(),end:G().finite().positive(),speaker:W().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.`}),Z0=q({articleMarkdown:W().max(5e5).optional(),articleEdited:GD().default(!1),provided:q({research:Y0.optional(),article:Y0.optional(),audio:Y0.optional(),thumbnail:Y0.optional(),reference:Y0.optional()}).strict(),imageOrder:K(Y0).max(240),imageDefinitions:lO(Y0,q({source:J([`generate`,`provide`]),assetId:Y0.nullable(),prompt:W().max(5e5).nullable(),templateKey:W().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:lO(X0,rO(`kind`,[q({kind:pO(`asset`),assetId:Y0}).strict(),q({kind:pO(`text`),text:W().trim().min(1).max(5e5),direction:W().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:lO(X0,q({text:W().min(1).max(5e5),start:G().int().nonnegative().max(5e5),bodyFingerprint:W().regex(/^[0-9a-f]{64}$/u),chunkingFingerprint:W().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:q({audioFingerprint:W().min(1),cues:K(lfe)}).strict().optional(),regenerationTokens:cfe,promptTemplates:lO(W().min(1),W().max(5e5).nullable()),shortsMusic:Y0.optional(),shortsRanges:lO(W().regex(/^[1-9]\d?$/u),q({first:G().int().positive(),last:G().int().positive(),pick:W().min(1).max(128)}).strict()).optional(),ambientBed:Y0.optional()}).strict(),ufe=q({baseRevisionId:Y0,idempotencyKey:Y0,edit:q({config:xM.strict(),content:Z0,regenerate:K(X0).optional(),uploads:K(q({stagedFileId:Y0,destination:rO(`kind`,[q({kind:pO(`provided`),stage:J([`audio`,`thumbnail`,`reference`])}).strict(),q({kind:pO(`image`),imageKey:Y0}).strict(),q({kind:pO(`narration`),key:X0}).strict(),q({kind:pO(`shortsMusic`)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),dfe=q({baseRevisionId:Y0,idempotencyKey:Y0,targetRevisionId:Y0}).strict(),ffe=q({id:Y0,projectId:Y0,parentId:Y0.nullable(),restoredFromId:Y0.nullable(),config:xM,content:Z0,fingerprints:lO(X0,W()),createdAt:W()}),pfe=q({id:Y0,stageId:Y0,kind:J(q0),idx:G().int(),state:J(J0),payload:W().nullable()}),mfe=q({slot:W(),workKey:X0,assetId:Y0,output:sfe,fingerprint:W(),state:J([`ready`,`outdated`,`review`])}),hfe=q({key:X0,stageKind:J(FS),piece:pfe,assetId:Y0.nullable(),fingerprint:W()}),Q0={recordId:Y0,publicationId:Y0.nullable(),selected:GD(),available:GD()},$0=q({articleMarkdown:W().nullable(),revision:ffe,outputs:K(mfe.extend(Q0)),pieces:K(hfe.extend(Q0)),current:GD()}),gfe=q({id:Y0,parentId:Y0.nullable(),restoredFromId:Y0.nullable(),title:W(),createdAt:W(),current:GD()}),e2=q({ok:pO(!0),view:$0,duplicate:GD()}),_fe=q({ok:pO(!0),view:$0,created:GD()}),vfe=q({title:W(),status:G(),detail:W().optional(),reason:W().optional(),currentRevisionId:W().nullable().optional(),fields:K(q({field:W(),message:W()})).optional(),errors:K(q({path:W(),message:W()})).optional()});async function t2(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=vfe.safeParse(n);if(!r.success)throw po(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw po(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 n2(e,t,n,r,i){return t2(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 r2(e,t){return n2(e,t,`/revisions/prepare`,_fe,{})}function i2(e,t,n){return n2(e,t,`/revisions`,e2,ufe.parse(n))}function yfe(e,t,n){return n2(e,t,`/revisions/restore`,e2,dfe.parse(n))}function bfe(e,t){return n2(e,t,`/revisions`,q({revisions:K(gfe)}))}function a2(e,t,n){return n2(e,t,`/revisions/${encodeURIComponent(n)}`,q({view:$0}))}var o2=K(W()).readonly();function xfe(e,t,n){return n2(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,q({chunks:q({intro:o2.optional(),body:o2.optional(),outro:o2.optional()}).nullable()}))}function Sfe(e,t,n){return n2(e,t,`/rebuild/preview`,q({ok:pO(!0),value:rfe}),$de.parse(n))}function Cfe(e,t,n){return n2(e,t,`/rebuild`,q({ok:pO(!0),value:K0}),efe.parse(n))}function s2(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function wfe(e,t,n,r){let i=await t2(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),U0);if(!i.ok)throw Error(i.message);return i.value}function Tfe(e,t,n){return s2(e,t,n,`images.zip`)}async function c2(e,{projectId:t,asset:n,folder:r=null}){if(r)return wfe(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 po(i,await mo(i));return U0.parse(await i.json())}var l2=`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 u2(e){return(0,h.jsx)(Efe,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function Efe(e){let{api:t}=z(),[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 c2(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)(Sb,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(wb,{asChild:!0,children:(0,h.jsxs)(R,{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)(xc,{"aria-hidden":`true`,strokeWidth:1.75}),n?`Locating…`:o?`Locate folder`:`Open folder`]})}),(0,h.jsxs)(Eb,{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:l2}),(0,h.jsx)(`input`,{"aria-label":`Saved folder path`,readOnly:!0,value:o,onFocus:e=>e.currentTarget.select(),className:`sl-input w-full min-w-0 font-mono text-small`})]}),i===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i})]})]})}var Dfe={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function Ofe(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function d2(){let{api:e}=z(),[t,n]=(0,m.useState)(Ofe),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)(Ab,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:Dfe[e]}))}),(0,h.jsxs)(mS,{href:os(e,t),download:r,children:[(0,h.jsx)(_c,{"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)(EV,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(EV,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(EV,{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)(EV,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(EV,{children:r}),`. Firefox removes it when it restarts; load it again then.`]})]}),(0,h.jsx)(`li`,{children:`Pair it: press Copy beside the pairing token in Settings → YouTube Studio, click the Slopify extension's toolbar button, paste the token and press Pair.`})]})]})}var f2=[`studio`,`settings`];function kfe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Upload pack and extension`,info:`settings.studio.extension`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(Afe,{}),(0,h.jsx)(Mfe,{}),(0,h.jsxs)(`section`,{"aria-label":`Install the Studio extension`,children:[(0,h.jsx)(H,{as:`h3`,title:`Install the Studio extension`,className:`mb-3`}),(0,h.jsx)(d2,{})]})]})]})}var p2=``;function Afe(){let{api:e}=z(),t=_(),n=Oy(),r=(0,m.useId)(),i=N({queryKey:f2,queryFn:()=>rs(e)}),a=N(Zb(e)),o=(0,m.useId)(),[s,c]=(0,m.useState)(p2),[l,u]=(0,m.useState)(void 0),d=i.data?.playlists??[],f=s===p2?void 0:i.data?.channelPlaylists[s],p=l??(s===p2?d:f??[]),g=jfe(p),v=P({mutationFn:t=>is(e,t,s===p2?void 0:s),onSuccess:()=>{u(void 0),t.invalidateQueries({queryKey:f2}),n(`Playlists saved.`,`success`)}}),y=e=>{v.reset(),u(e)},b=g??v.error?.message,x=[{value:p2,label:`Every channel (default)`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(xV,{label:`Playlists`,tip:`settings.studio.playlist`,help:s===p2?`The playlists upload packs offer, for every channel without its own. Ticked ones are on for every project; Prepare upload changes them for one project.`:f===void 0&&d.length>0?`This channel uses the default list (${(e=>e.map(e=>e.name).join(`, `))(d)}) until you add its own.`:`This channel's own playlists. Ticked ones are on for every project; Prepare upload changes them for one project.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(TV,{id:o,"aria-label":`Channel`,value:s,options:x,onChange:e=>{v.reset(),u(void 0),c(e.currentTarget.value)},className:`max-w-[260px]`}),p.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{autoComplete:`off`,"aria-label":`Playlist ${String(t+1)} name`,placeholder:`The playlist's name in Studio`,className:`min-w-0 flex-1 basis-[220px]`,value:e.name,disabled:i.data===void 0,"aria-invalid":e.name.trim().length>150,"aria-describedby":b===void 0?void 0:r,onChange:e=>y(p.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,h.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.byDefault,onChange:e=>{let n=e.currentTarget.checked;y(p.map((e,r)=>r===t?{...e,byDefault:n}:e))}}),`On by default`]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name.trim()||`playlist ${String(t+1)}`}`,onClick:()=>y(p.filter((e,n)=>n!==t)),children:`Remove`})]},t)),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(R,{variant:`secondary`,disabled:i.data===void 0||p.length>=20,onClick:()=>y([...p,{name:``,byDefault:p.length===0}]),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add playlist`]}),(0,h.jsx)(R,{variant:`primary`,disabled:v.isPending||l===void 0||g!==void 0,onClick:()=>v.mutate(p),children:`Save playlists`})]})]}),b===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:b})]})}function jfe(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 Mfe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:f2,queryFn:()=>rs(e)}),i=P({mutationFn:()=>ls(e),onSuccess:()=>{t.invalidateQueries({queryKey:f2}),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)(V,{id:`settings.studio.pairing`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`code`,{className:`sl-code min-w-0 flex-1 basis-[220px] truncate py-2 select-all`,children:a?.token??`…`}),(0,h.jsxs)(R,{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)(gc,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}),`Copy`]}),(0,h.jsx)(R,{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 m2=[`studio`,`queue`];function h2({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)(R,{variant:n,size:r,disabled:!t,disabledReason:`Available once the video has been made`,onClick:()=>a(!0),children:`Prepare upload`}),i?(0,h.jsx)(v2,{projectId:e,onClose:()=>a(!1)}):null]})}var g2={video:`Video file`,title:`Title`,description:`Description`,thumbnails:`Thumbnail`,playlist:`Playlist`,audience:`Audience`,altered:`AI use (under Show more)`,tags:`Tags (under Show more)`};function _2(e){return e.kind===`video`?`video`:`short-${String(e.short)}`}function v2({projectId:e,onClose:t}){let{api:n}=z(),r=_(),i=[`studio`,`pack`,e],a=N({queryKey:i,queryFn:()=>us(n,e)}),[o,s]=(0,m.useState)(`video`),[c,l]=(0,m.useState)(),u=a.data?.items??[],d=u.find(e=>_2(e)===o)??u[0],f=N({queryKey:f2,queryFn:()=>rs(n)}),p=f.data===void 0?void 0:f.data.pairing.origin!==null,g=N({queryKey:m2,queryFn:()=>ss(n)}),v=P({mutationFn:t=>fs(n,e,t.short),onSuccess:e=>{r.setQueryData(m2,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. Drop the video file into its upload dialog; the Slopify Studio extension 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=P({mutationFn:e=>cs(n,e.projectId,e.short),onSuccess:e=>r.setQueryData(m2,e),onError:e=>l({text:`Couldn't remove it from Waiting for Studio: ${e.message} Press Remove again.`,tone:`error`})}),b=P({mutationFn:t=>ds(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=P({mutationFn:t=>as(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`})});return(0,h.jsxs)(YP,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(mS,{href:T0,target:`_blank`,rel:`noopener noreferrer`,variant:`secondary`,children:`Open YouTube Studio`}):null,(0,h.jsx)(R,{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(T0,`_blank`,`noopener`),v.mutate(d))},children:`Fill in YouTube Studio`}),(0,h.jsx)(V,{id:`project.upload.fill-studio`})]}),children:[a.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The upload pack couldn't be read.`,children:`${a.error.message} Close Prepare upload and open it again.`}),a.data===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p===!1?(0,h.jsx)(SI,{tone:`waiting`,title:`The Slopify Studio extension isn't paired.`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Without it, the steps below are the upload pack: copy each into Studio's upload dialog. To have Studio filled in for you, install the extension:`}),(0,h.jsx)(d2,{})]})}):null,u.length>1?(0,h.jsx)(Ab,{label:`What to upload`,value:d===void 0?``:_2(d),onChange:s,tip:`project.upload.item`,options:u.map(e=>({value:_2(e),label:e.kind===`video`?`Video`:`Short ${String(e.short)}`})),className:`self-start`}):null,a.data.missing.length===0?null:(0,h.jsx)(SI,{tone:`waiting`,title:`Some of it isn't made yet.`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:a.data.missing.map(e=>(0,h.jsx)(`li`,{children:e},e))})}),d===void 0?null:(0,h.jsx)(Pfe,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(kb,{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`}))},doneKey:`slopify.upload.${e}.${_2(d)}`},_2(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)(V,{id:`project.upload.queue`,className:`-my-1`})]}),(0,h.jsx)(pU,{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)(mU,{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)(R,{variant:`quiet`,size:`small`,disabled:y.isPending,"aria-label":`Remove ${e.projectTitle} ${n.toLowerCase()} from Waiting for Studio`,onClick:()=>y.mutate(e),children:`Remove`})},`${e.projectId}-${String(e.short)}`)})})]}),(0,h.jsx)(SI,{title:`Slopify never publishes.`,children:p===!1?`Copy each step into Studio's upload dialog (Open YouTube Studio), check it and press Publish yourself.`:`Fill in YouTube Studio hands this to the Slopify Studio extension after you drop the video in. You check it and press Publish.`})]})]})}function Nfe(e){try{let t=JSON.parse(localStorage.getItem(e)??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function y2({href:e,filename:t}){return(0,h.jsxs)(mS,{href:e,download:t,"aria-label":`Download ${t}`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download`]})}function Pfe({projectId:e,item:t,footageSwitch:n,playlistPicker:r,copy:i,doneKey:a}){let{api:o}=z(),[s,c]=(0,m.useState)(()=>Nfe(a)),[l,u]=(0,m.useState)(null),d=e=>{c(e);try{localStorage.setItem(a,JSON.stringify(e))}catch{}},f=(e,t)=>d(t?[...s,e]:s.filter(t=>t!==e)),p=Wde.filter(e=>e!==`thumbnails`||t.kind===`video`),g=p.filter(e=>s.includes(e)).length,_=e=>{let n=b2(t,e);return(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:n===``,disabledReason:`Nothing to copy yet`,"aria-label":`Copy ${g2[e].toLowerCase()}`,onClick:()=>i(n,g2[e].toLowerCase()),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy`]})},v=a=>{switch(a){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)(y2,{href:`${o.origin}${t.video.url}`,filename:t.video.filename}),(0,h.jsx)(u2,{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?`The first under Thumbnail; all ${String(t.thumbnails.length)} in A/B Testing (beside the title).`:t.thumbnails[0]?.filename??``,actions:(0,h.jsx)(u2,{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?b2(t,a)||(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:_(a)};case`title`:return t.titles.length===0?{value:b2(t,a),actions:_(a)}:{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:t.title}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:`A/B Testing (beside the title): also ${t.titles.map(e=>`"${e}"`).join(` and `)}`})]}),actions:(0,h.jsxs)(h.Fragment,{children:[_(a),(0,h.jsxs)(R,{variant:`quiet`,size:`small`,"aria-label":`Copy the other titles`,onClick:()=>i(t.titles.join(`
271
- `),`other titles`),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy others`]})]})};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:_(a)};default:return{value:b2(t,a)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}),actions:_(a)}}};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)(V,{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:g===p.length,ref:e=>{e!==null&&(e.indeterminate=g>0&&g<p.length)},onChange:e=>d(e.currentTarget.checked?[...p]:[]),className:`size-4 shrink-0 accent-[var(--color-accent)]`}),`Select all`]})]}),(0,h.jsx)(pU,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:p.map(e=>{let{value:t,actions:n}=v(e);return(0,h.jsx)(mU,{className:`items-start`,lead:(0,h.jsx)(`input`,{type:`checkbox`,checked:s.includes(e),onChange:t=>f(e,t.currentTarget.checked),className:`mt-1 size-4 shrink-0 self-start accent-[var(--color-accent)]`,"aria-label":`${g2[e]} done`}),title:g2[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)(H,{as:`h3`,kicker:`Thumbnails · A/B Testing`,title:`${String(t.thumbnails.length)} ${t.thumbnails.length===1?`thumbnail`:`thumbnails`}`,className:`mb-3`}),(0,h.jsx)(B0,{label:`Thumbnails to upload`,density:`compact`,children:t.thumbnails.map((e,t)=>(0,h.jsx)(z0,{src:`${o.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,title:String.fromCharCode(65+t),meta:e.filename,onOpen:()=>u(t),openLabel:`Open thumbnail ${String.fromCharCode(65+t)} full size`,actionsShown:!0,actions:(0,h.jsx)(y2,{href:`${o.origin}${e.url}`,filename:e.filename})},e.asset))}),(0,h.jsx)(V0,{items:t.thumbnails.map((e,t)=>({src:`${o.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,caption:e.filename})),index:l,onIndex:u,onClose:()=>u(null),actions:(e,n)=>{let r=t.thumbnails[n];return r===void 0?null:(0,h.jsx)(y2,{href:`${o.origin}${r.url}`,filename:r.filename})}})]})]})}function b2(e,t){switch(t){case`title`:return e.title;case`description`:return e.description;case`tags`:return Gde(e.tags);case`playlist`:return e.playlists.join(`, `);default:return``}}var x2=4;function Ffe(e){return e===`schedules`?`schedules`:`weeks`}var S2=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),C2=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),w2=new Intl.DateTimeFormat(void 0,{timeStyle:`short`}),T2=`slopify.calendar.view`;function Ife(){try{return window.localStorage.getItem(T2)===`list`?`list`:`weeks`}catch{return`weeks`}}function Lfe({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=z(),a=_(),o=gx(),[s]=(0,m.useState)(()=>sU(new Date,x2)),[c,l]=(0,m.useState)(Ife),[u,d]=(0,m.useState)(e??`weeks`),f=n===void 0?u:e??`weeks`,p=e=>{n===void 0?d(e):n(e)},[g,v]=(0,m.useState)(!1),y=N(KH(i,s.from,s.to)),b=N(EH(i)),x=N(Hq(i)),S=N(Yy(i)),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),D=(0,m.useMemo)(()=>new Map((x.data??[]).map(e=>[e.id,e.channelId])),[x.data]),O=(0,m.useMemo)(()=>new Map((S.data?.projects??[]).map(e=>[e.id,e.channelId])),[S.data]),k=(b.data??[]).filter(e=>o.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>o.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>o.includes(O.get(e.id)))},ee=(0,m.useMemo)(()=>A===void 0?new Map:oU(A),[A]),te=A?.runs??[],ne=tU(A?.projects??[]),j=P({mutationFn:e=>e(),onSuccess:e=>w(e.ok?{tone:`info`,text:`Moved.`}:{tone:`error`,text:e.message}),onError:e=>w({tone:`error`,text:`The topic wasn't moved: ${e.message} Reload the calendar and try again.`}),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:GH}),a.invalidateQueries({queryKey:TH})])}}),re=e=>{if(e.kind!==`none`){if(e.kind===`refused`){w({tone:`error`,text:e.message});return}e.kind===`move`?j.mutate(()=>HH(i,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to})):j.mutate(()=>WH(i,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}}))}},M=(e,t)=>{let n=lU(te,e,t);if(n===void 0){w({tone:`error`,text:t===-1?`${uU(e)} is already the next topic of ${e.scheduleName}.`:`${uU(e)} is the last topic on the calendar for ${e.scheduleName}.`});return}re(cU(e,n,C2.format(new Date(n.at))))},ie=e=>{l(e),f!==`weeks`&&p(`weeks`);try{window.localStorage.setItem(T2,e)}catch{}};bx({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),bx({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>p(`schedules`)}),Yx(Wx.addToCalendar,()=>v(!0)),bx({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>ie(`weeks`)}),bx({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>ie(`list`)});let ae=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),oe=C?.text??y.error?.message??b.error?.message,se=rU(new Date),ce=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(kq,{title:`Calendar`,meta:`${o.channel?.name??`Every channel`} · ${String(te.length)} scheduled ${te.length===1?`run`:`runs`} in the next ${String(x2)} weeks · ${String(ae)} ${ae===1?`topic`:`topics`} queued`,actions:f===`schedules`?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Ab,{label:`Calendar view`,tip:`planning.calendar.view`,value:c,onChange:ie,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(R,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]})}),(0,h.jsx)(r0,{items:[{id:`weeks`,label:`Coming weeks`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ce)}}],value:f,onChange:p,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(i0,{idPrefix:`calendar`,id:`schedules`,active:f===`schedules`,children:f===`schedules`?(0,h.jsx)(Rde,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(i0,{idPrefix:`calendar`,id:`weeks`,active:f===`weeks`,children:[(0,h.jsx)(Q1,{tone:C?.tone===`info`?`info`:oe?`error`:`info`,className:`mb-3`,children:oe}),(0,h.jsxs)(e0,{split:`aside`,className:`mb-6`,children:[(0,h.jsx)(t0,{label:`Needs you`,children:ne.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Nothing needs you right now.`}):(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(H,{title:`Needs you`,meta:eU(ne)}),(0,h.jsx)(pU,{label:`Needs you`,children:ne.map(e=>(0,h.jsx)(O2,{project:e},e.id))})]})}),(0,h.jsx)(t0,{as:`aside`,label:`Suggested topics`,children:(0,h.jsx)(_de,{schedules:k})})]}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[y.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the calendar…`}):c===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic to another day to change when it runs, or onto another schedule's run to move it there. With the keyboard: focus a topic and press Alt+← or Alt+→.`}),aU(new Date(s.from),x2).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=rU(e),n=ee.get(t);return(0,h.jsx)(Rfe,{date:e,today:t===se,day:n,dragging:T,busy:j.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(re(cU(T,t,C2.format(e))),E(null))},onStep:M},t)})},rU(e[0]??new Date)))]}):(0,h.jsx)(Bfe,{days:ee,busy:j.isPending,onStep:M,schedules:k,onTransfer:(e,t)=>{e.index!==null&&re({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0})}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(H,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(pU,{label:`Batch queue`,children:A.queued.toSorted((e,t)=>e.position-t.position).map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsx)(_S,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`})},e.projectId)})})]}):null]})]}),(0,h.jsx)(JH,{open:g,onOpenChange:v,schedules:k})]})}function Rfe({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,E2),v=()=>p.find(e=>e.scheduleId===r?.scheduleId)??p[0];return(0,h.jsxs)(`section`,{"aria-label":C2.format(e),className:L(`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 · ${S2.format(e)}`:S2.format(e)}),p.map(e=>(0,h.jsx)(zfe,{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=$H(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${dU}`,children:[(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${fU}`,children:e.title}),(0,h.jsx)(_S,{tone:t.tone,children:t.word})]},e.id)}),g.length>E2?(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":d,className:`self-start`,onClick:()=>f(e=>!e),children:d?`Show fewer`:`+${String(g.length-E2)} more`}):null]})}var E2=3;function zfe({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=uU(e);return(0,h.jsxs)(`article`,{tabIndex:e.index===null?void 0:0,"aria-label":`${s}, ${w2.format(new Date(e.at))}, ${e.scheduleName}${e.index===null?``:`. Alt+arrow keys move it.`}`,draggable:o,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,s),n(e)},onDragEnd:r,onDragOver:e=>e.preventDefault(),onDrop:i,onKeyDown:t=>{o&&t.altKey&&(t.key===`ArrowLeft`||t.key===`ArrowUp`?(t.preventDefault(),a(e,-1)):(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(t.preventDefault(),a(e,1)))},className:L(`sl-cal-item`,o&&`sl-cal-item--movable`),children:[(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:w2.format(new Date(e.at))}),(0,h.jsx)(`b`,{className:L(`text-small`,e.topic===null&&`font-normal text-ink-2`),children:s}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.scheduleName}),e.paused?(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(_S,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(_S,{tone:`off`,children:`Queued`}):(0,h.jsx)(_S,{tone:`info`,children:`Prepared`}),(0,h.jsx)(D2,{run:e,compact:!0})]})}function D2({run:e,compact:t=!1}){let{api:n}=z(),r=_(),[i,a]=(0,m.useState)(),o=P({mutationFn:async()=>{if(e.topic===null)throw Error(`This run has no topic to prepare yet.`);let t=await LH(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:GH}),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)(R,{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)(fS,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}function O2({project:e}){let t=$H(e);return(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(_S,{tone:t.tone,children:t.word}),t.action===void 0?null:t.action.kind===`upload`?(0,h.jsx)(h2,{projectId:e.id,ready:!0}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function Bfe({days:e,busy:t,schedules:n,onStep:r,onTransfer:i}){let a=[...e.values()].sort((e,t)=>e.key.localeCompare(t.key));if(a.length===0)return(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Nothing is planned for the next `,x2,` weeks. Add topics with Add to calendar, or create a schedule on the`,` `,(0,h.jsx)(ha,{to:`/calendar`,search:{tab:`schedules`},children:`Schedules`}),` `,`tab.`]});let o=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,...Ob,children:[(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Move a topic earlier, later or to another schedule from its row.`,(0,h.jsx)(V,{id:`planning.calendar.move`,className:`-my-1`})]}),a.map(e=>(0,h.jsxs)(`section`,{"aria-label":C2.format(e.date),children:[(0,h.jsx)(H,{title:C2.format(e.date),as:`h3`}),(0,h.jsxs)(pU,{label:`Planned on ${C2.format(e.date)}`,children:[e.runs.map(e=>{let n=uU(e),a=o.filter(t=>t.id!==e.scheduleId);return(0,h.jsx)(mU,{title:n,meta:`${w2.format(new Date(e.at))} · ${e.scheduleName}${e.templateName===null?``:` · ${e.templateName}`}${e.paused?` · Paused`:``}`,actions:e.index===null?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(D2,{run:e}),(0,h.jsx)(wy,{size:`small`,label:`Move ${n} earlier`,disabled:t,onClick:()=>r(e,-1),children:(0,h.jsx)(ic,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Move ${n} later`,disabled:t,onClick:()=>r(e,1),children:(0,h.jsx)(tc,{"aria-hidden":`true`,strokeWidth:1.75})}),a.length===0?null:(0,h.jsxs)(`select`,{"aria-label":`Move ${n} to another schedule`,className:`sl-select h-8 w-auto text-small`,value:``,disabled:t,onChange:t=>{t.target.value!==``&&i(e,t.target.value)},children:[(0,h.jsx)(`option`,{value:``,children:`Move to…`}),a.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})},`${e.scheduleId}-${e.at}`)}),e.projects.map(e=>(0,h.jsx)(O2,{project:e},e.id))]})]},e.key))]})}var Vfe=wj.map(e=>({value:e,label:Tj[e]}));function Hfe({channel:e}){let{api:t}=z(),n=_(),r=Oy(),i=P({mutationFn:n=>lx(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${Tj[e.aiDisclosure]}.`,`success`),n.setQueryData(Jb(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:qb,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)(xV,{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)(TV,{value:i.isPending?i.variables:e.aiDisclosure,options:Vfe,disabled:i.isPending,onChange:e=>{let t=wj.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(Q1,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}function k2({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)(xV,{label:r,tip:o,help:Ufe(s),error:i,children:(0,h.jsxs)(TV,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:zO.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,BO(n.language).name,`)`]}),RO.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function Ufe(e){let t=BO(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=VO(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 Wfe({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`,...Ob,children:[(0,h.jsx)(H,{title:`Channel links`,meta:`Write a link's name in braces in a description, such as {{Patreon}}.`,info:`planning.links.named`}),e.length===0?(0,h.jsx)(`p`,{className:`m-0 border-y border-line py-4 text-ink-2`,children:`No channel links yet. Add one, then write its name in braces in a description.`}):(0,h.jsx)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:e.map((r,i)=>(0,h.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,1fr)] items-center gap-2 border-b border-line py-3 md:grid-cols-[220px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(CV,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})}),(0,h.jsx)(CV,{"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)(R,{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)(Bc,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(R,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function Gfe(){return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsx)(H,{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)(fS,{to:`/channels/$channelId`,params:{channelId:Wb},children:`Open the default channel's links`})})]})}function A2({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(eA.levelDb),fadeIn:e?.fadeIn??String(eA.fadeInSeconds),tail:e?.tail??String(eA.tailSeconds)},u=e=>{if(e===``)s(void 0);else if(e===`none`)s({source:`none`,...l});else{let t=n.find(t=>t===e);t!==void 0&&s({source:t,...l})}},d=(t,n,r,a)=>e===void 0||!c?null:(0,h.jsx)(xV,{label:n,help:r,tip:a,error:i(t),children:(0,h.jsx)(CV,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})})});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(xV,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(TV,{"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:$k[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 Kfe({value:e,onChange:t}){let n=aA(e),r=n===void 0?[]:nA(n);return(0,h.jsx)(A2,{value:e,inherit:`Not set`,sources:Zk,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function qfe(e){return e.ambientBed===void 0?void 0:iA(e.ambientBed)}function Jfe(e){let t=aA(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:nA(t).length>0}}var j2=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`];function Yfe(e){return Object.fromEntries(j2.map(t=>[t,e[t]??``]))}function Xfe({channel:e}){let{api:t}=z(),n=_(),r=Oy(),i=N({queryKey:sN,queryFn:()=>cN(t)}),a=N(rb(t)),o=N(ib(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(Yfe(e.brand)),[p,g]=(0,m.useState)(qfe(e.brand)),v=Jfe(p),y=N({queryKey:B.channelLinks,queryFn:()=>ws(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=P({mutationFn:()=>ex(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(j2.flatMap(e=>d[e].trim()===``?[]:[[e,d[e].trim()]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(Jb(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:qb}),n.invalidateQueries({queryKey:B.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),D=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),O=[...(o.data?.builtIns??[]).map(e=>({value:e.name,label:e.label})),...(o.data?.themes??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(`form`,{"aria-label":`Brand kit`,onSubmit:e=>{e.preventDefault(),w.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-5`,children:[(0,h.jsx)(xV,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(CV,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(xV,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules.`,children:(0,h.jsx)(wV,{rows:4,value:l,maxLength:1e4,onChange:e=>u(e.target.value)})}),(0,h.jsx)(H,{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)(k2,{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)(M2,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:E,onPick:T(`captionFontId`)}),(0,h.jsx)(N2,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(N2,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`)})]}),(0,h.jsxs)(`section`,{"aria-label":`Chapter cards and end screen`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(M2,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:E,onPick:T(`titleFontId`)}),(0,h.jsx)(N2,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(xV,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(CV,{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)(M2,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:D(`intro`),onPick:T(`intro`)}),(0,h.jsx)(M2,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:D(`outro`),onPick:T(`outro`)}),(0,h.jsx)(M2,{label:`Document theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:O,onPick:T(`documentTheme`)})]}),(0,h.jsx)(Kfe,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(Wfe,{rows:S,onChange:x})})]}),(0,h.jsx)($1,{status:(0,h.jsx)(Q1,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked,disabledReason:s.trim()===``?`Give the channel a name`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function M2({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(xV,{label:e,tip:t,children:(0,h.jsxs)(TV,{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 N2({label:e,tip:t,value:n,onChange:r}){let i=/^#[0-9a-fA-F]{6}$/.test(n);return(0,h.jsx)(xV,{label:e,tip:t,...n!==``&&!i?{error:`Write the colour as # and six hex digits.`}:{},children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-6 shrink-0 rounded-control border border-line-strong`,style:{background:i?n:`transparent`}}),(0,h.jsx)(CV,{value:n,placeholder:`#FFFFFF`,maxLength:7,onChange:e=>r(e.target.value)})]})})}function P2(e,t){return e.languages===void 0||e.languages.includes(BO(t).code)}function Zfe(e,t,n,r){return n?e:e.filter(e=>P2(e,t)||e.voiceId===r)}function Qfe(e,t){if(e===void 0||P2(e,t))return;let n=BO(t).name,r=(e.languages??[]).map(e=>BO(e).code===e?BO(e).name:e);return`${e.name} is listed for ${r.join(`, `)}, not ${n}, so it may read the ${n} narration with the wrong accent. Pick a ${n} voice under Narration, or correct the voice's languages in Settings → Voices.`}function F2(e,t,n){let[r,i]=(0,m.useState)(!1),a=Zfe(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function I2({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=Qfe(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`,...Ob,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 ${BO(e).name})`]}),(0,h.jsx)(V,{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 $fe({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=z(),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:Jb(e)}),o.invalidateQueries({queryKey:qb})]),T=P({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?nx(a,e,crypto.randomUUID(),n):rx(a,t.id,{...n,baseVersion:t.version})},onSuccess:async e=>{await w(),t===void 0&&i(e.id)}}),E=()=>{let e=p.trim();e===``||d.some(t=>t.toLowerCase()===e.toLowerCase())||(f([...d,e]),g(``))};return n?(0,h.jsxs)(`section`,{"aria-label":t===void 0?`Add to cast`:`Edit ${t.name}`,children:[(0,h.jsx)(H,{kicker:t===void 0?`New cast member`:Kb[t.kind],title:t===void 0?`Add to cast`:t.name,meta:t===void 0?`Name it first, then give it reference pictures.`:`Used whenever a title or an image brief names it or one of its aliases.`,children:(0,h.jsx)(R,{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)(xV,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(TV,{value:s,onChange:e=>c(Gb.find(t=>t===e.target.value)??`character`),options:Gb.map(e=>({value:e,label:Kb[e]}))})}),(0,h.jsx)(xV,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(CV,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(xV,{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)(CV,{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)(R,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(Nc,{"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)(yS,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(xV,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(wV,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(tpe,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(kb,{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)(Q1,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(R,{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)(epe,{channelId:e,member:t})]}):null}function epe({channelId:e,member:t}){let{api:n}=z(),r=_(),i=N(eb(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:Jb(e)}),r.invalidateQueries({queryKey:qb})]),g=P({mutationFn:e=>ax(n,t.id,e),onSettled:p}),v=P({mutationFn:()=>ox(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=P({mutationFn:e=>sx(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:ux(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)(Mq,{className:`mb-6`}),(0,h.jsx)(H,{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)(B0,{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)(z0,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:ux(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)(vS,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(R,{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)(npe,{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)(V0,{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)(mS,{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)(R,{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`,...Ob,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(V,{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)(RV,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(zV,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(xV,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,children:(0,h.jsx)(wV,{ref:o,rows:3,value:d,maxLength:4e3,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(R,{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)(Q1,{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 tpe({channelId:e,value:t,onChange:n}){let{api:r}=z(),i=N(eb(r)),a=N(tb(r)),o=N(Qb(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=F2(c,o,s.voice||void 0),u=l.listed;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-3 border-0 border-t border-line p-0 pt-4`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(V,{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)(RV,{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)(zV,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(FV,{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)(I2,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(FV,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:AA.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)(R,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function npe({error:e,retry:t,onReword:n}){let r=V1({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)(Ey,{className:`mt-2`,children:(0,h.jsx)(Y1,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(R,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}function rpe({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=z(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=P({mutationFn:e=>ix(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:Jb(e)}),a.invalidateQueries({queryKey:qb})])}}),p=t.find(e=>e.id===c),g=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:ux(i,t)}]:[]}),v=g.map(e=>({src:e.src,alt:e.member.name,caption:`${Kb[e.member.kind]} · ${e.member.description||`No description yet`}`})),[y,b]=(0,m.useState)(null),x=c===`new`||p!==void 0;return(0,h.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 min-[1024px]:grid-cols-[minmax(0,1fr)_440px]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:`When a video's title or an image's brief names a member, its pictures go with that image as references, so it looks the same in every video.`}),t.length===0?(0,h.jsx)(a0,{title:`No cast yet`,actions:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>l(`new`),children:`Add to cast`}),children:`Add the characters, creatures, places and objects this channel keeps coming back to.`}):(0,h.jsx)(B0,{label:`Cast`,children:t.map(e=>{let t=e.images.filter(e=>e.state===`ready`),n=t[0]?.sha256;return(0,h.jsx)(z0,{className:L(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...n?{src:ux(i,n)}:{},alt:e.name,onOpen:()=>b(g.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${Kb[e.kind]}${e.host===!0?` · Host`:``} · ${String(t.length)} ${t.length===1?`picture`:`pictures`}`,...t.length===0?{badge:(0,h.jsx)(vS,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`})]})},e.id)})}),(0,h.jsx)(V0,{items:v,index:y,onIndex:b,onClose:()=>b(null),actions:(e,t)=>{let n=g[t];return n===void 0?null:(0,h.jsx)(R,{size:`small`,onClick:()=>{b(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(Q1,{tone:`error`,className:`mt-2`,children:u?void 0:f.error?.message})]}),(0,h.jsx)(`aside`,{"aria-label":`Cast member editor`,className:`min-w-0`,children:x?(0,h.jsx)($fe,{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)(jy,{open:u!==null,title:`Delete ${u?.name??`this cast member`}?`,consequence:f.error?.message??`New videos stop using its pictures. Videos already made keep the pictures they were started with.`,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var L2=e=>[`channels`,e,`episodes`],R2=e=>[`channels`,e,`videos`],z2=(e,t)=>`${e.origin}/api/channels/${t}`,B2=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function ipe(e,t){return ct({queryKey:L2(t),queryFn:async()=>F(await e.fetch(`${z2(e,t)}/episodes`))})}async function ape(e,t,n){return F(await e.fetch(`${z2(e,t)}/episodes/setting`,B2(`PUT`,{enabled:n})))}async function ope(e,t,n,r){return F(await e.fetch(`${z2(e,t)}/episodes/${encodeURIComponent(n)}`,B2(`PUT`,{summary:r})))}async function spe(e,t,n){let r=await e.fetch(`${z2(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await F(r)}function V2(e,t){return ct({queryKey:R2(t),queryFn:async()=>(await F(await e.fetch(`${z2(e,t)}/videos`))).videos})}async function cpe(e,t,n){return F(await e.fetch(`${z2(e,t)}/videos`,B2(`POST`,n)))}async function lpe(e,t,n){return F(await e.fetch(`${z2(e,t)}/videos/preview`,B2(`POST`,{format:`csv`,text:n})))}async function upe(e,t,n){let r=await e.fetch(`${z2(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await F(r)}async function dpe(e,t){await F(await e.fetch(`${z2(e,t)}/videos`,{method:`DELETE`}))}var fpe=e=>e.length>160?`${e.slice(0,160)}…`:e;function ppe({channelId:e}){let{api:t}=z(),n=_(),r=N(ipe(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:L2(e)}),l=P({mutationFn:n=>ape(t,e,n),onSuccess:t=>n.setQueryData(L2(e),t)}),u=P({mutationFn:n=>spe(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kb,{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)(Q1,{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)(a0,{title:`No episodes remembered yet`,children:d?`When a video on this channel finishes, its summary appears here.`:`Turn on episode memory, and the next finished video's summary appears here.`}):null,f.length>0?(0,h.jsx)(pU,{label:`Episode summaries`,children:f.map(e=>(0,h.jsx)(mU,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,fpe(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(R,{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)(mpe,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(jy,{open:o!==null,title:`Delete the summary of ${o?.title??`this episode`}?`,consequence:u.error?.message??`New episodes stop being reminded of it. The video itself is not changed.`,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function mpe({channelId:e,memory:t,onClose:n}){let{api:r}=z(),i=_(),[a,o]=(0,m.useState)(t.summary),s=P({mutationFn:()=>ope(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:L2(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Ay,{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)(R,{onClick:n,children:`Close`}),(0,h.jsx)(R,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(xV,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(wV,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}var H2=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function U2(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function hpe({channelId:e}){let{api:t}=z(),n=_(),r=N(V2(t,e)),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(void 0),u=(0,m.useRef)(null),d=()=>n.invalidateQueries({queryKey:R2(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=P({mutationFn:n=>cpe(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${H2(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=P({mutationFn:n=>lpe(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:U2(e.titles,e.filter)})}}),x=P({mutationFn:n=>upe(t,e,n),onSuccess:d}),S=P({mutationFn:()=>dpe(t,e),onSuccess:async()=>{s(!1),await d()}}),C=r.data??[],w=y.isPending||b.isPending||x.isPending||S.isPending,T=r.error??b.error??y.error??x.error;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`Topic suggestions and duplicate checks skip these titles, as they skip the videos made here.`}),(0,h.jsx)(xV,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(wV,{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)(R,{variant:`primary`,disabled:w||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(R,{disabled:w,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(V,{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)(R,{variant:`quiet`,disabled:w||C.length===0,onClick:()=>{S.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(Q1,{tone:T?`error`:c?`success`:`info`,className:`mt-1`,children:T?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(gpe,{preview:f,filter:g,busy:w,onFilter:e=>{v(e),p({...f,ticked:U2(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(`
272
- `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(a0,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(pU,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(mU,{title:e.title,actions:(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(jy,{open:o,title:`Remove all ${H2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function gpe({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...Ob,children:[(0,h.jsxs)(H,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${H2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(R,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,H2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(R,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(xV,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(CV,{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)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(pU,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(mU,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`],_pe={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`};function vpe(e){return W2.find(t=>t===e)??`brand`}function ype({channelId:e,tab:t,onTab:n}){let{api:r}=z(),i=_(),a=Zi(),o=N(Qb(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=P({mutationFn:()=>tx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:qb}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return bx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(ha,{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)(R,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(r0,{items:W2.map(e=>({id:e,label:_pe[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(Q1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(i0,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(Hfe,{channel:f}),(0,h.jsx)(Xfe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(rpe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(xde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(wde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(ppe,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(hpe,{channelId:f.id}):null})]}):null,(0,h.jsx)(jy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function G2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:L(`sl-stats m-0`,e),children:t})}function K2({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 q2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:L(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function J2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:L(`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)))})]})}function bpe(){let{api:e}=z(),t=_(),n=Zi(),r=N(Zb(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=P({mutationFn:()=>$b(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:qb}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=P({mutationFn:t=>ex(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:qb}),a(null)}}),v=P({mutationFn:t=>tx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:qb})}}),y=()=>{p.reset(),l(``),a(`new`)};bx({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)(kq,{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)(V,{id:`planning.channels`})]}),actions:(0,h.jsxs)(R,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(Q1,{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)(a0,{title:`No channels yet`,actions:(0,h.jsx)(R,{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)(jq,{list:(0,h.jsx)(pU,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(mU,{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)(pS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(R,{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)(R,{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)(xpe,{channel:f})}):null,(0,h.jsx)(Ay,{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)(Q1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(R,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(R,{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)(xV,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(CV,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(jy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function xpe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(H,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(fS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(G2,{className:`mb-6`,children:[(0,h.jsx)(K2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(K2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(H,{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)(H,{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 Y2=2e3;function X2(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()},Y2);return()=>{clearTimeout(t)}},[e])}function Z2(){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)(lc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function Q2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Oy();bx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:lP.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)(R,{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)(Q1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(Z2,{}):t)}),a,(0,h.jsx)(R,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Mx(lP.save),onClick:()=>{c||s()},children:`Save`})]})}var Spe=`rounded-media border border-line bg-surface p-4`;function $2(){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:`${Spe} 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 Cpe=`modulepreload`,wpe=function(e){return`/`+e},e4={},t4=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=wpe(t,n),t=s(t),t in e4)return;e4[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`:Cpe,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 Tpe({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 Epe(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 Epe(e,t){let n=await t4(()=>import(`./pdf-DjcINuld.js`),[]),r=await t4(()=>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 n4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),i4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),a4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),o4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),s4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),c4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),Dpe=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},n4([`page`,`margin`],`Margins`),n4([`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:[c4(`body`,`Body`),c4(`strong`,`Bold text`),c4(`emphasis`,`Italic text`),c4(`heading`,`Headings`),c4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),c4(`decorative`,`Tagline and title-page link`),c4(`dropCap`,`Drop caps`),c4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[r4([`sizes`,`title`],`Title`),r4([`sizes`,`brand`],`Brand`),r4([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),r4([`sizes`,`heading`],`Second-level headings`),r4([`sizes`,`subheading`],`Third-level headings`),r4([`sizes`,`body`],`Body`),r4([`sizes`,`meta`],`Date and word count`),r4([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[n4([`spacing`,`bodyLine`],`Body line height`),n4([`spacing`,`headingLine`],`Heading line height`),n4([`spacing`,`subheadingLine`],`Subheading line height`),i4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),i4([`spacing`,`headingGap`],`Before a heading`,`× line`),i4([`spacing`,`itemGap`],`After a list item`,`× line`),n4([`spacing`,`listIndent`],`List indent`),n4([`spacing`,`quoteIndent`],`Quote indent`),n4([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[a4([`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`}]},i4([`dropCap`,`scale`],`Letter size`,`× lines`),n4([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},i4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[n4([`titlePage`,`brandY`],`Brand from top`),n4([`titlePage`,`taglineOffset`],`Tagline below brand`),n4([`titlePage`,`titleY`],`Title from top`),n4([`titlePage`,`titleLine`],`Title line height`),n4([`titlePage`,`metaOffset`],`Details below title`),n4([`titlePage`,`metaLine`],`Details line height`),a4([`titlePage`,`showDate`],`Show the date`),a4([`titlePage`,`showWordCount`],`Show the word count`),a4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),n4([`titlePage`,`cover`,`gap`],`Space around cover`),n4([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[s4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),s4([`brand`,`tagline`],`Tagline`),s4([`brand`,`url`],`Website`,`Where the brand and its link go.`),s4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[a4([`contents`,`enabled`],`Contents page`),o4([`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`}]},n4([`contents`,`titleOffset`],`Title from top margin`),n4([`contents`,`firstEntryOffset`],`First entry from top margin`),n4([`contents`,`line`],`Line height`),n4([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[a4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),n4([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},a4([`footer`,`enabled`],`Page numbers`),o4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),n4([`footer`,`bottom`],`From the bottom`),n4([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[a4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),o4([`sources`,`title`],`Title`),n4([`sources`,`titleOffset`],`Title from top margin`),n4([`sources`,`bodyOffset`],`List from top margin`),n4([`sources`,`line`],`Line height`),n4([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[a4([`endPage`,`enabled`],`Closing page`),o4([`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.`},a4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},s4([`endPage`,`closing`],`Closing line`),n4([`endPage`,`titleOffset`],`Title from top margin`),n4([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[o4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),o4([`metadata`,`subject`],`Subject`),o4([`metadata`,`keywords`],`Keywords`),o4([`metadata`,`creator`],`Creator`)]}],l4=$j.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function u4(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 Ope(e,t){let n=e;for(let e of t)n=n?.[e];return n}function d4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:d4(a,i,n)}}function kpe(e){let t=sM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function f4(e){return`values.${e.join(`.`)}`}var p4=`pt-1`,m4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function h4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(fc,{"aria-hidden":`true`}),e]})}function g4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(SI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function _4({themeId:e,from:t,onLeave:n}){let{api:r}=z(),i=_(),a=N(ib(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=P({mutationFn:t=>Fs(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:ib(r).queryKey})}}),w=P({mutationFn:e=>Is(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:ib(r).queryKey}),n()}});X2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:sM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:ZS(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)(b4,{children:a.error.message});if(v===void 0)return(0,h.jsx)($2,{});if(S===void 0)return(0,h.jsx)(b4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(xV,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),Dpe.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>v4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(fc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(Mpe,{field:e,theme:S.values,problem:v4(E,e.path),onChange:t=>{D({...S,values:t},f4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(fS,{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)(jpe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(jy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var Ape={"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 v4(e,t){let n=f4(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 jpe({values:e}){let{api:t}=z(),[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`),Ls(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:m4,children:[(0,h.jsx)(H,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(mS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(yc,{"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)(Tpe,{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 Mpe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=Ope(t,e.path),o=Ape[f4(e.path)],s=o===void 0?null:(0,h.jsx)(V,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(d4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=kpe(e.path);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(CV,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(CV,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(TV,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=u4(t.family);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(TV,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=l4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=u4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:l4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(TV,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(CV,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(wV,{...d,rows:8,value:Array.isArray(a)?a.join(`
270
+ Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(xV,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(wV,{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)(Nde,{queue:e,onQueue:t,keyword:f,addable:O,setRow:D,titleOf:b}),k.length===0?null:(0,h.jsx)(SI,{tone:`danger`,title:`These topics can't be saved yet.`,children:(0,h.jsxs)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:[k.slice(0,8).map(e=>(0,h.jsx)(`li`,{children:e},e)),k.length>8?(0,h.jsx)(`li`,{children:`And ${String(k.length-8)} more.`}):null]})}),e.mode===`yaml`&&v.rows.length>0?(0,h.jsxs)(`section`,{"aria-label":`Project titles`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-1 text-small text-ink-2`,children:`Project titles, in order:`}),(0,h.jsxs)(`ol`,{className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:[v.rows.slice(0,20).map((e,t)=>(0,h.jsx)(`li`,{children:b(e)},t)),v.rows.length>20?(0,h.jsx)(`li`,{className:`list-none text-ink-3`,children:`And ${String(v.rows.length-20)} more.`}):null]})]}):null,a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Reading the template's keywords…`}):d.length===0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`This template has no keywords such as `,`{{Topic}}`,`, so each topic becomes the project's title.`]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:(0,h.jsx)(xV,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:g0({feeds:_(f)})},children:(0,h.jsx)(TV,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(_0,{keywords:d.filter(e=>e!==f).map(t=>({name:t,value:g[t]??``,feeds:_(t),...e.columns.includes(t)?{note:`Unless a topic sets its own.`}:{}})),onChange:i,fieldPrefix:`everyRun`,label:e=>`${e} (every run)`,inputLabel:e=>`${e} for every run`,tip:`planning.schedule.every-run`,maxLength:1e4})]}),e.mode===`lines`&&S!==void 0&&x!==void 0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Next project: `,(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:S}),f===null||C?null:(0,h.jsxs)(`span`,{className:`block text-ink-3`,children:[`The template's project title does not use `,`{{${f}}}`,`, so every project gets this title. Edit the template's title to include it.`]})]}):null]})}function Nde({queue:e,onQueue:t,keyword:n,addable:r,setRow:i,titleOf:a}){let o=n===null?`Title`:`{{${n}}}`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ob,children:[(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table`,"aria-label":`Topics`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,children:`#`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[o,(0,h.jsx)(V,{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)(wy,{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)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})},n)),(0,h.jsx)(`th`,{scope:`col`,children:`Project title`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:e.rows.map((n,r)=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`num`,children:r+1}),(0,h.jsx)(`td`,{children:(0,h.jsx)(CV,{"aria-label":`Topic ${String(r+1)} ${o}`,maxLength:200,value:n.title,onChange:e=>i(r,{...n,title:e.target.value})})}),e.columns.map(e=>(0,h.jsx)(`td`,{children:(0,h.jsx)(CV,{"aria-label":`Topic ${String(r+1)} ${e}`,maxLength:gq,placeholder:`Every-run value`,value:n.values[e]??``,onChange:t=>i(r,{...n,values:{...n.values,[e]:t.target.value}})})},e)),(0,h.jsx)(`td`,{className:`min-w-[180px] text-small text-ink-2`,children:a(n)??`—`}),(0,h.jsx)(`td`,{children:(0,h.jsx)(wy,{label:`Remove topic ${String(r+1)}`,size:`small`,onClick:()=>t({...e,rows:e.rows.filter((e,t)=>t!==r)}),children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})})]},r))})]})}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(R,{size:`small`,onClick:()=>t({...e,rows:[...e.rows,{title:``,values:{}}]}),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]}),r.length===0?null:(0,h.jsxs)(TV,{"aria-label":`Set a keyword per topic`,value:``,className:`w-auto`,onChange:n=>{let r=n.target.value;r!==``&&t({...e,columns:[...e.columns,r]})},children:[(0,h.jsx)(`option`,{value:``,children:`Set a keyword per topic…`}),r.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))]})]})]})}var Pde=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Fde({templates:e,pending:t,onCreated:n,onError:r,editing:i,onCancel:a,error:o,onBusy:s}){let{api:c}=z(),[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`?Yue(i.cadence.at,i.timezone):``),[y,b]=(0,m.useState)(i&&i.cadence.kind!==`once`?i.cadence.time:`09:00`),[x,S]=(0,m.useState)(i?.cadence.kind===`weekly`?i.cadence.days:[1,3,5]),[C,w]=(0,m.useState)(()=>i?.timezone??(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`)),[T,E]=(0,m.useState)(i?.missedPolicy??`skip`),[D,O]=(0,m.useState)(i?.spendLimitCents?.toString()??``),[k,A]=(0,m.useState)(()=>y0(i?.items??[])),[ee,te]=(0,m.useState)(i?.topicKeyword??null),[ne,j]=(0,m.useState)(i?.values??{}),[re,M]=(0,m.useState)(i?.brief??``),[ie,ae]=(0,m.useState)(i?.topicGeneration??lH),[oe,se]=(0,m.useState)(!1),[ce,le]=(0,m.useState)(!1),ue=(0,m.useRef)(!1),de=(0,m.useRef)(null),fe=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,pe=fe.find(e=>e.id===d),me=N({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await Uq(c,d);if(!e.ok)throw Error(e.message);return e.value}}),he=me.data?.document.form,ge=he===void 0?void 0:h0({form:he,prompts:me.data?.document.librarySnapshot?.prompts??[],entries:me.data?.document.librarySnapshot?.entries??[]}),_e=he===void 0?[]:_q(he),ve=ee!==null&&_e.includes(ee)?ee:_e.find(e=>he?.title.includes(`{{${e}}}`))??_e[0]??null,ye=Object.fromEntries(_e.filter(e=>e!==ve).map(e=>[e,ne[e]??he?.values[e]??``])),be={keywords:_e,topicKeyword:ve,everyRun:ye,form:he,kept:i?.items??[],...ge===void 0?{}:{origins:ge}},xe=S0(k,be);async function Se(e){if(e.preventDefault(),!(ue.current||t)){if(!pe&&!de.current){r(`Choose a template before saving the schedule.`);return}if(!de.current&&xe.problems.length>0){r(`Fix the topics first. ${xe.problems.slice(0,3).join(` `)}`);return}if(xe.rows.length>500){r(`Keep the list to 500 topics or fewer.`);return}if(re.trim().length>4e3){r(`Keep the series brief to ${String(sH)} characters or fewer.`);return}if(ie.llm!==null&&(ie.llm.provider===``||ie.llm.model===``)){r(`Pick both a provider and a model for topic generation, or choose Use the template's LLM.`);return}if(p===`weekly`&&x.length===0){r(`Choose at least one weekday for a weekly schedule.`);return}ue.current=!0,se(!0),s(!0);try{if(!de.current){if(!pe)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!$V(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Xue(_,e)}:p===`weekly`?{kind:p,time:y,days:x}:{kind:p,time:y},n=D.trim()===``?null:Number(D);if(n!==null&&(!Number.isInteger(n)||n<0))throw Error(`Enter the spend limit as a whole number of cents, 0 or more (500 is $5.00), or leave it empty.`);let r={id:i?.id??crypto.randomUUID(),name:l.trim(),templateId:pe.id,templateVersion:pe.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:xe.rows,topicKeyword:ve,values:ye,brief:re.trim()===``?null:re.trim(),topicGeneration:ie};de.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=de.current,{id:t,...a}=e,o=`mutationId`in a?await kH(c,t,a):await OH(c,e);if(!o.ok){de.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}de.current=null,le(!1),u(``),A(y0([])),n()}catch(e){le(de.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{ue.current=!1,se(!1),s(de.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(SI,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{onSubmit:e=>void Se(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)(xV,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,children:(0,h.jsx)(CV,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(xV,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,children:(0,h.jsxs)(TV,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:fe.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),fe.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(xV,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(TV,{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)(xV,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,children:(0,h.jsx)(CV,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(xV,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,children:(0,h.jsx)(CV,{required:!0,type:`time`,value:y,onChange:e=>b(e.target.value)})}),p===`weekly`?(0,h.jsxs)(`fieldset`,{className:`m-0 min-w-0 border-0 p-0`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`sl-field__label mb-2 flex items-center gap-1`,children:[`Weekdays`,(0,h.jsx)(V,{id:`planning.schedule.weekdays`,className:`-my-1`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Pde.map(([e,t])=>(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),onChange:t=>S(n=>t.target.checked?[...n,e]:n.filter(t=>t!==e))}),t]},e))})]}):(0,h.jsx)(`div`,{}),(0,h.jsx)(xV,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,children:(0,h.jsx)(CV,{value:C,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(xV,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(TV,{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)(xV,{label:`Spend ceiling (cents, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,children:(0,h.jsx)(CV,{inputMode:`numeric`,value:D,onChange:e=>O(e.target.value),placeholder:`1000`})}),(0,h.jsx)(Mde,{queue:k,onQueue:A,context:be,onKeyword:te,onValue:(e,t)=>j(n=>({...n,[e]:t})),loading:d!==``&&me.isPending,exportName:l}),(0,h.jsx)(Ide,{brief:re,onBrief:M,generation:ie,onGeneration:ae,templateLlm:he?.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)(R,{type:`submit`,variant:`primary`,disabled:t||oe||fe.length===0&&!ce,children:oe?`Saving…`:ce?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(R,{variant:`quiet`,disabled:oe||ce,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Ide({brief:e,onBrief:t,generation:n,onGeneration:r,templateLlm:i}){let{api:a}=z(),o=N({...eb(a),enabled:n.mode!==`off`}),s=n.llm;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topic generation`,(0,h.jsx)(V,{id:`planning.schedule.generation`})]}),(0,h.jsx)(xV,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,children:(0,h.jsx)(wV,{rows:3,maxLength:sH,value:e,onChange:e=>t(e.target.value),placeholder:`Ancient history, documentary style. Famous rulers and places first.`})}),(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,children:(0,h.jsxs)(TV,{value:n.mode,onChange:e=>{let t=e.target.value;r({...n,mode:t===`queue`||t===`hold`?t:`off`})},children:[(0,h.jsx)(`option`,{value:`off`,children:`Off: add topics yourself`}),(0,h.jsx)(`option`,{value:`queue`,children:`Generate and queue directly`}),(0,h.jsx)(`option`,{value:`hold`,children:`Generate and hold for approval`})]})}),n.mode===`off`?null:(0,h.jsx)(xV,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(CV,{type:`number`,min:1,max:100,value:String(n.keepAtLeast),onChange:e=>{let t=Math.round(Number(e.target.value));r({...n,keepAtLeast:Number.isFinite(t)?Math.min(100,Math.max(1,t)):1})}})})]}),n.mode===`off`?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s===null,onChange:e=>r({...n,llm:e.target.checked?null:{provider:i?.provider??``,model:i?.model??``}})}),`Use the template's LLM`,s===null&&i!==void 0&&i.provider!==``?` (${i.provider} · ${i.model})`:``]}),(0,h.jsx)(V,{id:`planning.schedule.generation-llm`,className:`-my-1`})]}),s===null?null:(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(RV,{label:`Provider`,family:`llm`,providers:o.data?.providers??[],value:s.provider,problem:o.error?.message,onPick:e=>r({...n,llm:{provider:e,model:``}})}),(0,h.jsx)(zV,{label:`Model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>r({...n,llm:{...s,model:e}})})]})]})]})}function Lde({schedule:e}){let{api:t}=z(),n=_(),r=Oy(),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(!1),c=(0,m.useRef)(!1),[l,u]=(0,m.useState)(``),d=(0,m.useRef)(e);e.version>d.current.version&&(d.current=e);let f=d.current.items,p=e.topicKeyword===null?`title`:`{{${e.topicKeyword}}}`,g=async(e,i,o)=>{if(c.current)return!1;c.current=!0;let l=d.current;s(!0),a(null);try{let s=await UH(t,l.id,{baseVersion:l.version,items:e});return s.ok?(d.current=s.value,n.setQueryData(TH,e=>e?.map(e=>e.id===s.value.id?s.value:e)),n.invalidateQueries({queryKey:GH}),r(i,`success`,o?{label:`Undo`,run:()=>void g(l.items,`Put the topics back as they were.`,!1)}:void 0),!0):(a(s.reason===`conflict`?`The topics weren't saved: this schedule changed since the page loaded, possibly because a run just took a topic. The list now shows the latest; make your change again.`:`The topics weren't saved: ${s.message}`),await n.invalidateQueries({queryKey:TH}),!1)}catch(e){return a(`The topics weren't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then try again.`),!1}finally{c.current=!1,s(!1)}},v=async e=>{e.preventDefault();let t=l.trim();if(t===``){a(`Write the new topic's ${p} first, then press Add topic.`);return}await g([...f,{title:t,values:{}}],`Added “${t}”.`,!0)&&u(``)},y=(e,t)=>{let n=f[e];if(n!==void 0&&t.trim()!==n.title){if(t.trim()===``){a(`Topic ${String(e+1)} needs a ${p}. Write one, or press its Remove button.`);return}g(f.map((n,r)=>r===e?{...n,title:t.trim()}:n),`Renamed to “${t.trim()}”.`,!0)}},b=(e,t)=>{let n=f[e];if(n===void 0)return;let r=[...f];r.splice(e,1),r.splice(e+t,0,n),g(r,`Moved “${n.title}” ${t===-1?`up`:`down`}.`,!0)},x=e=>{let t=f[e];t!==void 0&&g(f.filter((t,n)=>n!==e),`Removed “${t.title}”.`,!0)};return(0,h.jsxs)(`section`,{"aria-label":`Queued topics`,className:`mt-6`,...Ob,children:[(0,h.jsx)(H,{as:`h3`,title:`Queued topics · ${String(f.length)}`,info:`planning.schedule.inline-topics`,meta:e.topicKeyword===null?`Each topic becomes the next project's title.`:`Each topic fills ${p}; the next run takes the first.`}),i===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:i}),f.length===0?null:(0,h.jsx)(pU,{label:`Topics of ${e.name}`,className:`mt-2`,children:f.map((e,t)=>(0,h.jsx)(Rde,{index:t,title:e.title,count:f.length,busy:o,onRename:e=>y(t,e),onMove:e=>b(t,e),onRemove:()=>x(t)},`${String(t)}:${e.title}`))}),(0,h.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-center gap-2`,onSubmit:e=>void v(e),children:[(0,h.jsx)(CV,{"aria-label":`New topic`,placeholder:e.topicKeyword===null?`New topic`:`New ${p}`,maxLength:200,value:l,className:`min-w-0 flex-1`,onChange:e=>u(e.target.value)}),(0,h.jsxs)(R,{type:`submit`,size:`small`,disabled:o||f.length>=500,disabledReason:o?`Saving the last change`:`A queue holds at most 500 topics`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]})]})]})}function Rde({index:e,title:t,count:n,busy:r,onRename:i,onMove:a,onRemove:o}){let[s,c]=(0,m.useState)(t);(0,m.useEffect)(()=>c(t),[t]);let l=`Topic ${String(e+1)}`;return(0,h.jsx)(mU,{lead:(0,h.jsx)(`span`,{className:`w-6 text-small text-ink-3 tabular-nums`,children:e+1}),title:(0,h.jsx)(CV,{"aria-label":l,maxLength:200,value:s,onChange:e=>c(e.target.value),onBlur:()=>i(s),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i(s)):e.key===`Escape`&&c(t)}}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wy,{size:`small`,label:`Move ${t} up`,disabled:r||e===0,onClick:()=>a(-1),children:(0,h.jsx)(ic,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Move ${t} down`,disabled:r||e===n-1,onClick:()=>a(1),children:(0,h.jsx)(tc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Remove ${t}`,disabled:r,onClick:o,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function zde({pickedId:e,onPick:t}={}){let{api:n}=z(),r=_(),i=N(EH(n)),a=N(Hq(n)),[o,s]=(0,m.useState)(null),c=Oy(),[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=N(Zb(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=N(KH(n,E.from,E.to)),O=new Map;for(let e of D.data?.runs??[])e.renderedTitle!==null&&!O.has(e.scheduleId)&&O.set(e.scheduleId,e.renderedTitle);let[k,A]=(0,m.useState)(``),ee=e=>{if(k===``)return!0;let t=a.data?.find(t=>t.id===e.templateId);return(t?o0(t):Wb)===k},te=i.data?.filter(e=>e.deletedAt===null&&ee(e))??[],ne=i.data?.filter(e=>e.deletedAt!==null)??[],j=i.data?.find(e=>e.id===b)??te[0]??null,re=P({onError:e=>s(e.message),onSettled:async()=>{w.current=!1,await r.invalidateQueries({queryKey:TH})},mutationFn:async e=>e(),onSuccess:async e=>{if(!e.ok){s(e.message);return}s(null)}}),M=e=>{w.current||(w.current=!0,s(null),re.mutate(e))},ie=d||l!==null,ae=()=>{u(null),f(!1),s(null)},oe=a.data?.length===0,se=()=>{ie||oe||(u(null),f(!0),s(null))},ce=e=>{f(!1),x(e.id),u(e),s(null)};bx({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:se}),Yx(Wx.newSchedule,()=>{oe?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`):se()},a.data!==void 0);let le=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,ue=re.isPending||p||ie;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:oe?(0,h.jsxs)(h.Fragment,{children:[`Save a template in`,` `,(0,h.jsx)(ha,{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)(V,{id:`planning.schedules`})]})}),(0,h.jsxs)(Ey,{children:[(0,h.jsxs)(TV,{"aria-label":`Filter schedules by channel`,value:k,className:`w-auto min-w-[160px]`,onChange:e=>A(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(T.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsxs)(R,{variant:`primary`,onClick:se,disabled:ie||oe,disabledReason:oe?`Save a template in Library → Templates first`:`Finish or cancel the open form first`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New schedule`]})]})]}),(0,h.jsx)(Q1,{tone:ie?`info`:le?.tone??`info`,className:`mb-2`,children:ie?void 0:le?.text}),(0,h.jsx)(jq,{className:`min-[768px]:grid-cols-[minmax(320px,460px)_minmax(0,1fr)]`,list:(0,h.jsxs)(h.Fragment,{children:[i.data&&te.length===0?(0,h.jsx)(a0,{title:k===``?ne.length===0?`No schedules yet`:`No active schedules`:`No schedules run this channel's templates`,children:k===``?ne.length===0?`Your first one can be a one-off run or a recurring series. Press New schedule.`:`Create one with New schedule, or review deleted history below.`:`Pick All channels to see the others, or make one from this channel's templates.`}):null,te.length>0?(0,h.jsx)(pU,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:te.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(w0,{schedule:e,nextTitle:O.get(e.id),selected:!ie&&j?.id===e.id,pending:ue,onSelect:()=>x(e.id),onEdit:()=>ce(e),onAction:M,onConfirm:t=>C({kind:t,schedule:e})}),(0,h.jsx)(c0,{kind:`schedule`,id:e.id,name:e.name})]},e.id))}):null,ne.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 · `,ne.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)(pU,{label:`Deleted schedules`,children:ne.map(e=>(0,h.jsx)(w0,{schedule:e,nextTitle:void 0,selected:!ie&&j?.id===e.id,pending:!1,onSelect:()=>x(e.id),onEdit:()=>void 0,onAction:M,onConfirm:()=>void 0},e.id))})]}):null]}),detail:ie?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{kicker:l?l.name:void 0,title:l?`Edit schedule`:`New schedule`,className:`mb-4`}),(0,h.jsx)(Fde,{onBusy:g,editing:l,onCancel:()=>{p||ae()},templates:a.data??[],pending:re.isPending,error:o,onCreated:()=>{c(l?`Schedule updated.`:`Schedule saved. It will run automatically while Slopify is open.`,`success`),ae(),r.invalidateQueries({queryKey:TH})},onError:e=>{s(e),r.invalidateQueries({queryKey:TH})}},l?.id??`new`)]}):j?(0,h.jsx)(Ude,{schedule:j,pending:ue,onAction:M,onConfirm:e=>C({kind:e,schedule:j})},j.id):null}),(0,h.jsx)(jy,{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:re.isPending,onCancel:()=>{re.isPending||C(null)},onConfirm:()=>{if(!S)return;let{kind:e,schedule:t}=S;M(async()=>{let r=e===`delete`?await jH(n,t.id,t.version):await AH(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}function Bde(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}var Vde={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Hde={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function C0({schedule:e}){return e.deletedAt===null?(0,h.jsx)(_S,{tone:Hde[e.status],children:Vde[e.status]}):(0,h.jsx)(_S,{tone:`off`,children:`Deleted`})}function w0({schedule:e,nextTitle:t,selected:n,pending:r,onSelect:i,onEdit:a,onAction:o,onConfirm:s}){let{api:c}=z(),l=e.deletedAt===null,u=l&&(e.status===`active`||e.status===`paused`),d=e.status===`canceled`||e.status===`completed`;return(0,h.jsx)(mU,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(C0,{schedule:e}),` · ${Bde(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${z1(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${z1(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)(R,{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)(R,{variant:`quiet`,size:`small`,"aria-label":`Resume ${e.name}`,disabled:r,onClick:()=>o(()=>AH(c,e.id,`resume`,e.version)),children:`Resume`}):(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Pause ${e.name}`,disabled:r||e.status!==`active`,disabledReason:`Only an active schedule can pause`,onClick:()=>o(()=>AH(c,e.id,`pause`,e.version)),children:`Pause`}),(0,h.jsx)(R,{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 Ude({schedule:e,pending:t,onAction:n,onConfirm:r}){let{api:i}=z(),a=N({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await DH(i,e.id);if(!t.ok)throw Error(t.message);return t.value},refetchInterval:3e4}),o=e.deletedAt===null,s=o&&(e.status===`active`||e.status===`paused`),c=e.status===`paused`,l=[[`When`,e.cadence.kind===`once`?`Once, ${z1(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`:z1(e.nextRunAt,e.timezone)],[`Topics`,e.items.length===0?e.topicGeneration.mode===`off`?`Template as saved`:`No topics queued`:`${String(e.items.length)} ${e.items.length===1?`topic`:`topics`} left`],[`Missed runs`,e.missedPolicy===`skip`?`Skip`:`Run once on reopening`],[`Overlap`,`Skip`],[`Spend ceiling`,e.spendLimitCents===null?`Not set`:`${String(e.spendLimitCents)} cents`]];return(0,h.jsxs)(`section`,{"aria-label":`${e.name} detail`,children:[o&&s?(0,h.jsx)(Wde,{schedule:e,paused:c,onAction:n}):null,(0,h.jsx)(H,{kicker:(0,h.jsx)(C0,{schedule:e}),title:e.name,meta:e.topics.held>0?`${String(e.topics.held)} topics waiting for you`:void 0,children:o?(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Cancel ${e.name}`,disabled:t||!s,disabledReason:`Only an active or paused schedule can be canceled`,onClick:()=>r(`cancel`),children:`Cancel schedule`}):null}),(0,h.jsx)(`dl`,{className:`m-0 mt-4 grid grid-cols-1 gap-x-6 gap-y-3 text-small min-[600px]:grid-cols-2`,children:l.map(([e,t])=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`dt`,{className:`sl-kicker`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-words text-ink`,children:t})]},e))}),s?(0,h.jsx)(Lde,{schedule:e}):null,(0,h.jsx)(_de,{schedule:e}),(0,h.jsx)(Mq,{className:`my-6`}),(0,h.jsx)(H,{as:`h3`,title:`Run history`}),(0,h.jsx)(`div`,{className:`mt-3`,children:a.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading history…`}):a.error?(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The run history couldn't be loaded: ${a.error.message} It tries again every 30 seconds.`}):a.data.runs.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No runs yet.`}):(0,h.jsx)(pU,{label:`Runs of ${e.name}`,children:a.data.runs.map(t=>(0,h.jsx)(mU,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${z1(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)(ha,{className:`underline hover:text-ink`,to:`/projects/$projectId`,params:{projectId:e},children:[`Project `,t+1]},e))}):`No projects`},t.id))})})]})}function Wde({schedule:e,paused:t,onAction:n}){let{api:r}=z();return bx({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>AH(r,e.id,t?`resume`:`pause`,e.version))}),null}var T0=`https://www.youtube.com/upload`,Gde=[`video`,`title`,`description`,`thumbnails`,`playlist`,`audience`,`altered`,`tags`];function Kde(e){return e.join(`, `)}var qde=[.75,1,1.25,1.5,1.75,2];function E0(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 D0(e){return`${String(e)}×`}function Jde(e,t){return e.filter(e=>e.start<=t).at(-1)}function O0(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var k0=(e,t,n)=>Math.min(n,Math.max(t,e));function A0(){let e=(0,m.useRef)(null),t=(0,m.useId)(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(0),[c,l]=(0,m.useState)(0),[u,d]=(0,m.useState)(1),[f,p]=(0,m.useState)(!1),[h,g]=(0,m.useState)(1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(null),[x,S]=(0,m.useState)(!1),C=Number.isFinite(o)&&o>0,w=()=>{let t=e.current;t!==null&&(t.paused||t.ended?t.play()?.catch(()=>void 0):t.pause())},T=t=>{let n=e.current;if(n===null||!C)return;let r=k0(t,0,o);n.currentTime=r,a(r)},E=t=>T((e.current?.currentTime??i)+t),D=t=>{let n=e.current;if(n===null)return;let r=k0(Math.round(t*100)/100,0,1);n.volume=r,n.muted=r===0,d(r),p(r===0)},O=()=>{let t=e.current;t!==null&&(t.muted=!t.muted,p(t.muted))};return{media:e,menuId:t,playing:n,current:i,duration:o,buffered:c,known:C,volume:u,muted:f,rate:h,menu:_,setMenu:v,hover:y,setHover:b,seeking:x,setSeeking:S,toggle:w,seekTo:T,jump:E,setLevel:D,toggleMute:O,pickRate:n=>{let r=e.current;r!==null&&(r.playbackRate=n),g(n),v(!1),document.getElementById(`${t}-button`)?.focus()},keyAction:e=>{let t=e.length===1?e.toLowerCase():e;if(t===` `||t===`k`)return w;if(t===`j`)return()=>E(-10);if(t===`l`)return()=>E(10);if(t===`ArrowLeft`)return()=>E(-5);if(t===`ArrowRight`)return()=>E(5);if(t===`m`)return O;if(/^[0-9]$/.test(t))return()=>T(Number(t)/10*o)},events:{onPlay:()=>r(!0),onPause:()=>r(!1),onEnded:()=>r(!1),onTimeUpdate:e=>{x||a(e.currentTarget.currentTime)},onDurationChange:e=>s(e.currentTarget.duration),onLoadedMetadata:e=>s(e.currentTarget.duration),onProgress:e=>{let t=e.currentTarget.buffered;l(t.length>0?t.end(t.length-1):0)},onVolumeChange:e=>{d(e.currentTarget.volume),p(e.currentTarget.muted)},onRateChange:e=>g(e.currentTarget.playbackRate)}}}function j0(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:k0((t-n.left)/n.width,0,1)}function M0(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function N0({controls:e,className:t}){return(0,h.jsx)(wy,{size:`small`,label:e.playing?`Pause`:`Play`,className:t,onClick:e.toggle,children:e.playing?(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})})}function P0({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:E0(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?E0(e.duration):`-:--`}`})]})}function F0({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=Zde(r),d=n===void 0?void 0:Xde(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(j0(r.current,t.clientX)*a))},g=t=>{let n=j0(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{M0(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:Jde(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":`${E0(o)} of ${i?E0(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}),E0(x)]})]})}function I0({controls:e}){let t=(0,m.useRef)(null),{muted:n,volume:r}=e,i=n?0:r;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wy,{size:`small`,label:n?`Unmute`:`Mute`,"aria-pressed":n,className:`sl-player__mute`,onClick:e.toggleMute,children:n||r===0?(0,h.jsx)(Wc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Uc,{"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(j0(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel(j0(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];M0(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 L0({controls:e}){let{menuId:t,menu:n,rate:r}=e;return(0,h.jsxs)(`span`,{className:`sl-player__speed`,children:[(0,h.jsx)(R,{id:`${t}-button`,variant:`quiet`,size:`small`,className:`sl-player__rate`,"aria-label":`Playback speed, ${D0(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:D0(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`){M0(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];M0(n,()=>i?.focus())},children:qde.map(t=>(0,h.jsx)(R,{variant:`quiet`,size:`small`,role:`menuitemradio`,"aria-checked":t===r,className:L(`sl-player__option`),autoFocus:t===r,onClick:()=>e.pickRate(t),children:t===1?`Normal`:D0(t)},t))}):null]})}var Yde=4;function Xde(e,t){let n=Math.floor(t/Yde);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 Zde(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 Qde=2500;function R0({src:e,poster:t,label:n,portrait:r=!1,captions:i,chapters:a=[],ref:o,className:s,children:c}){let l=A0(),u=l.media,d=(0,m.useRef)(null),f=(0,m.useRef)(void 0),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(0),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),[T,E]=(0,m.useState)(!1),[D,O]=(0,m.useState)(!0),{playing:k,menu:A,seeking:ee,hover:te,events:ne}=l,j=i!==void 0||y>0,re=typeof document<`u`&&`pictureInPictureEnabled`in document&&document.pictureInPictureEnabled===!0,M=(0,m.useCallback)(()=>{O(!0),clearTimeout(f.current),f.current=setTimeout(()=>O(!1),Qde)},[]);(0,m.useEffect)(()=>()=>clearTimeout(f.current),[]);let ie=k&&!D&&!A&&!T&&!ee&&te===null;(0,m.useEffect)(()=>{let e=()=>S(document.fullscreenElement===d.current);return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,m.useEffect)(()=>{let e=u.current;if(e===null)return;let t=()=>w(!0),n=()=>w(!1);return e.addEventListener(`enterpictureinpicture`,t),e.addEventListener(`leavepictureinpicture`,n),()=>{e.removeEventListener(`enterpictureinpicture`,t),e.removeEventListener(`leavepictureinpicture`,n)}},[u]),(0,m.useEffect)(()=>{let e=u.current?.textTracks;if(e!==void 0)for(let t=0;t<e.length;t+=1){let n=e[t];n!==void 0&&(n.mode=_&&t===0?`showing`:`hidden`)}},[_,u]);let ae=()=>{let e=u.current;e!==null&&(e.paused||e.ended)&&g(!0),l.toggle()},oe=()=>{let e=d.current;e!==null&&(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()?.catch(()=>void 0))},se=()=>{let e=u.current;e!==null&&(document.pictureInPictureElement===e?document.exitPictureInPicture?.().catch(()=>void 0):e.requestPictureInPicture?.().catch(()=>void 0))};return(0,h.jsxs)(`div`,{ref:d,"data-slot":`player`,"data-state":k?`playing`:`paused`,className:L(`sl-player`,r&&`sl-player--portrait`,ie&&`sl-player--bare`,x&&`sl-player--full`,s),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`?ae:n===`f`?oe:n===`c`?j?()=>v(e=>!e):void 0:l.keyAction(n);r!==void 0&&(e.preventDefault(),e.stopPropagation(),M(),r())},onPointerMove:M,onPointerDown:M,onFocus:()=>E(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(E(!1),l.setMenu(!1))},children:[(0,h.jsxs)(`video`,{ref:O0(u,o),src:e,poster:t,preload:`metadata`,playsInline:!0,"aria-label":n,onClick:ae,...ne,onPlay:e=>{ne.onPlay(e),g(!0),M()},onPause:e=>{ne.onPause(e),O(!0)},onEnded:e=>{ne.onEnded(e),O(!0)},onLoadedMetadata:e=>{ne.onLoadedMetadata(e),b(e.currentTarget.textTracks?.length??0)},children:[i===void 0?null:(0,h.jsx)(`track`,{kind:`captions`,src:i.src,srcLang:i.lang,label:i.label}),c]}),p?null:(0,h.jsx)(wy,{label:`Play ${n}`,className:`sl-player__big`,onClick:ae,children:(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsxs)(`div`,{className:`sl-player__bar`,role:`group`,"aria-label":`${n} controls`,children:[(0,h.jsx)(N0,{controls:{...l,toggle:ae}}),(0,h.jsx)(P0,{controls:l}),(0,h.jsx)(F0,{controls:l,chapters:a}),(0,h.jsx)(I0,{controls:l}),(0,h.jsx)(L0,{controls:l}),j?(0,h.jsx)(wy,{size:`small`,label:`Captions`,"aria-pressed":_,onClick:()=>v(e=>!e),children:(0,h.jsx)(cc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,re?(0,h.jsx)(wy,{size:`small`,label:`Picture in picture`,"aria-pressed":C,className:`sl-player__pip`,onClick:se,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(wy,{size:`small`,label:x?`Exit full screen`:`Full screen`,"aria-pressed":x,onClick:oe,children:x?(0,h.jsx)(Oc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Dc,{"aria-hidden":`true`,strokeWidth:1.75})})]})]})}var $de={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function z0({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:L(`sl-media m-0`,p),"data-slot":`media-frame`,children:[(0,h.jsxs)(`div`,{className:L(`sl-media__frame`,$de[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)(gS,{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:L(`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 B0({shorts:e=!1,density:t=`default`,list:n=!1,className:r,children:i,label:a}){let o=L(`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 V0({items:e,index:t,onIndex:n,onClose:r,actions:i}){let a=t===null?void 0:e[t],o=e.length,s=e=>{t!==null&&o!==0&&n((t+e+o)%o)};return(0,h.jsx)(_m,{open:a!==void 0,onOpenChange:e=>{e||r()},children:(0,h.jsx)(xm,{children:(0,h.jsx)(Em,{className:`sl-lightbox sl-enter`,onKeyDown:e=>{e.key===`ArrowRight`?(e.preventDefault(),s(1)):e.key===`ArrowLeft`&&(e.preventDefault(),s(-1))},"aria-describedby":void 0,children:a===void 0||t===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`sl-lightbox__bar`,children:[(0,h.jsx)(jm,{className:`m-0 text-small font-semibold`,children:`${String(t+1)} of ${String(o)} · ${a.alt}`}),(0,h.jsxs)(`div`,{className:`sl-btn-row`,children:[i?.(a,t),(0,h.jsx)(wy,{label:`Previous`,onClick:()=>s(-1),disabled:o<2,children:(0,h.jsx)(dc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{label:`Next`,onClick:()=>s(1),disabled:o<2,children:(0,h.jsx)(fc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Fm,{asChild:!0,children:(0,h.jsx)(wy,{label:`Close`,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})})]})]}),(0,h.jsx)(`div`,{className:`sl-lightbox__stage`,children:a.kind===`video`?(0,h.jsx)(R0,{src:a.src,label:a.alt,className:`sl-lightbox__player`,...a.poster===void 0?{}:{poster:a.poster}},a.src):(0,h.jsx)(`img`,{src:a.src,alt:a.alt},a.src)}),a.caption===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`p`,{className:`sl-lightbox__caption`,children:a.caption})]})})})})}var H0={location:pO(`docker-host`),path:W().min(1)},U0=tO([q({opened:pO(!0)}).strict(),q({opened:pO(!0),...H0}).strict(),q({opened:pO(!1),...H0}).strict()]),W0=rO(`kind`,[q({kind:pO(`allAffected`)}).strict(),q({kind:pO(`selected`),workKeys:K(W().min(1).max(200)).min(1).max(1e4)}).strict()]),G0=W().min(1).max(64),efe=q({baseRevisionId:G0,request:W0}).strict(),tfe=q({baseRevisionId:G0,idempotencyKey:wD(),previewId:W().min(1).max(64),acknowledgeUnknownCosts:GD(),confirmedProvidedWorkKeys:K(W().min(1).max(200)).max(1e4)}).strict(),nfe=q({stage:W(),low:G().finite().nonnegative().nullable(),high:G().finite().nonnegative().nullable(),detail:W(),onPlan:GD().optional(),apiLow:G().finite().nonnegative().nullable().optional(),apiHigh:G().finite().nonnegative().nullable().optional()}),rfe=q({currency:pO(`USD`),rows:K(nfe),low:G().finite().nonnegative(),high:G().finite().nonnegative(),unknown:G().int().nonnegative(),apiLow:G().finite().nonnegative().optional(),apiHigh:G().finite().nonnegative().optional(),apiUnknown:G().int().nonnegative().optional(),expectedWords:G().finite().nonnegative(),catalogueDate:W().nullable(),assumptions:K(W())}),K0=q({revisionId:G0,admissionId:W().min(1).max(64),workIds:K(W().min(1).max(64)),replayed:GD()}),ife=q({id:W().min(1).max(64),projectId:W().min(1).max(64),baseRevisionId:G0,planFingerprint:W().min(1),selection:W0,changedInputs:K(q({path:W(),before:W().nullable(),after:W().nullable()})),work:K(q({key:W(),stage:J(FS),kind:J([`provider`,`local`,`provided`]),disposition:J([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:W(),fingerprint:W(),dependsOn:K(W()),reason:W(),inflight:GD(),pieceIds:K(W())})),retained:K(q({slot:W(),outputId:W(),assetId:W(),state:J([`ready`,`outdated`,`review`])})),providedReuseRequired:K(W()),costs:rfe,wholeRequestNotice:W().nullable(),warnings:K(W()),review:q({inputChanges:K(q({label:W(),before:W().nullable(),after:W().nullable()})),requests:K(q({key:W(),label:W(),text:W().nullable(),settings:W().nullable()}))}).optional()}),q0=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],J0=[`pending`,`running`,`done`,`failed`];q({id:W(),stage_id:W(),kind:J(q0),idx:G(),state:J(J0),payload:W().nullable()});var afe=`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(`.`),ofe=[`copying`,`staged`],sfe=q({segment:J([`body`,`intro`,`outro`]).optional(),subtitleOmissions:K(q({start:G().finite().nonnegative(),text:W()})).optional(),subtitlesMode:J([`off`,`files`,`burn-in`]).optional(),promptName:W().optional(),prompt:W().optional(),index:G().optional(),short:G().optional(),format:J([`16:9`,`9:16`]).optional(),sentences:sO([G(),G()]).optional(),warnings:K(W()).optional(),provider:W().optional(),model:W().optional(),voice:W().optional(),loudness:q({pieces:G(),skipped:G(),spreadBefore:G(),spreadAfter:G(),target:G()}).optional(),master:q({target:G(),integrated:G(),truePeak:G()}).optional()}),cfe=q({id:W(),projectId:W(),stageKind:J(FS),role:J(afe),path:W(),originalFilename:W().nullable(),bytes:G().nonnegative(),durationMs:G().nonnegative().nullable(),meta:sfe,createdAt:W()});q({id:W(),stageKind:J(FS),path:W(),originalFilename:W(),bytes:G().nonnegative(),state:J(ofe),createdAt:W()});var Y0=W().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),X0=W().min(1).max(256),lfe=lO(X0,Y0),ufe=q({id:Y0,text:W().trim().min(1).max(1e4),start:G().finite().nonnegative(),end:G().finite().positive(),speaker:W().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.`}),Z0=q({articleMarkdown:W().max(5e5).optional(),articleEdited:GD().default(!1),provided:q({research:Y0.optional(),article:Y0.optional(),audio:Y0.optional(),thumbnail:Y0.optional(),reference:Y0.optional()}).strict(),imageOrder:K(Y0).max(240),imageDefinitions:lO(Y0,q({source:J([`generate`,`provide`]),assetId:Y0.nullable(),prompt:W().max(5e5).nullable(),templateKey:W().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:lO(X0,rO(`kind`,[q({kind:pO(`asset`),assetId:Y0}).strict(),q({kind:pO(`text`),text:W().trim().min(1).max(5e5),direction:W().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:lO(X0,q({text:W().min(1).max(5e5),start:G().int().nonnegative().max(5e5),bodyFingerprint:W().regex(/^[0-9a-f]{64}$/u),chunkingFingerprint:W().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:q({audioFingerprint:W().min(1),cues:K(ufe)}).strict().optional(),regenerationTokens:lfe,promptTemplates:lO(W().min(1),W().max(5e5).nullable()),shortsMusic:Y0.optional(),shortsRanges:lO(W().regex(/^[1-9]\d?$/u),q({first:G().int().positive(),last:G().int().positive(),pick:W().min(1).max(128)}).strict()).optional(),ambientBed:Y0.optional()}).strict(),dfe=q({baseRevisionId:Y0,idempotencyKey:Y0,edit:q({config:xM.strict(),content:Z0,regenerate:K(X0).optional(),uploads:K(q({stagedFileId:Y0,destination:rO(`kind`,[q({kind:pO(`provided`),stage:J([`audio`,`thumbnail`,`reference`])}).strict(),q({kind:pO(`image`),imageKey:Y0}).strict(),q({kind:pO(`narration`),key:X0}).strict(),q({kind:pO(`shortsMusic`)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),ffe=q({baseRevisionId:Y0,idempotencyKey:Y0,targetRevisionId:Y0}).strict(),pfe=q({id:Y0,projectId:Y0,parentId:Y0.nullable(),restoredFromId:Y0.nullable(),config:xM,content:Z0,fingerprints:lO(X0,W()),createdAt:W()}),mfe=q({id:Y0,stageId:Y0,kind:J(q0),idx:G().int(),state:J(J0),payload:W().nullable()}),hfe=q({slot:W(),workKey:X0,assetId:Y0,output:cfe,fingerprint:W(),state:J([`ready`,`outdated`,`review`])}),gfe=q({key:X0,stageKind:J(FS),piece:mfe,assetId:Y0.nullable(),fingerprint:W()}),Q0={recordId:Y0,publicationId:Y0.nullable(),selected:GD(),available:GD()},$0=q({articleMarkdown:W().nullable(),revision:pfe,outputs:K(hfe.extend(Q0)),pieces:K(gfe.extend(Q0)),current:GD()}),_fe=q({id:Y0,parentId:Y0.nullable(),restoredFromId:Y0.nullable(),title:W(),createdAt:W(),current:GD()}),e2=q({ok:pO(!0),view:$0,duplicate:GD()}),vfe=q({ok:pO(!0),view:$0,created:GD()}),yfe=q({title:W(),status:G(),detail:W().optional(),reason:W().optional(),currentRevisionId:W().nullable().optional(),fields:K(q({field:W(),message:W()})).optional(),errors:K(q({path:W(),message:W()})).optional()});async function t2(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=yfe.safeParse(n);if(!r.success)throw po(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw po(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 n2(e,t,n,r,i){return t2(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 r2(e,t){return n2(e,t,`/revisions/prepare`,vfe,{})}function i2(e,t,n){return n2(e,t,`/revisions`,e2,dfe.parse(n))}function bfe(e,t,n){return n2(e,t,`/revisions/restore`,e2,ffe.parse(n))}function xfe(e,t){return n2(e,t,`/revisions`,q({revisions:K(_fe)}))}function a2(e,t,n){return n2(e,t,`/revisions/${encodeURIComponent(n)}`,q({view:$0}))}var o2=K(W()).readonly();function Sfe(e,t,n){return n2(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,q({chunks:q({intro:o2.optional(),body:o2.optional(),outro:o2.optional()}).nullable()}))}function Cfe(e,t,n){return n2(e,t,`/rebuild/preview`,q({ok:pO(!0),value:ife}),efe.parse(n))}function wfe(e,t,n){return n2(e,t,`/rebuild`,q({ok:pO(!0),value:K0}),tfe.parse(n))}function s2(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function Tfe(e,t,n,r){let i=await t2(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),U0);if(!i.ok)throw Error(i.message);return i.value}function Efe(e,t,n){return s2(e,t,n,`images.zip`)}async function c2(e,{projectId:t,asset:n,folder:r=null}){if(r)return Tfe(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 po(i,await mo(i));return U0.parse(await i.json())}var l2=`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 u2(e){return(0,h.jsx)(Dfe,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function Dfe(e){let{api:t}=z(),[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 c2(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)(Sb,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(wb,{asChild:!0,children:(0,h.jsxs)(R,{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)(xc,{"aria-hidden":`true`,strokeWidth:1.75}),n?`Locating…`:o?`Locate folder`:`Open folder`]})}),(0,h.jsxs)(Eb,{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:l2}),(0,h.jsx)(`input`,{"aria-label":`Saved folder path`,readOnly:!0,value:o,onFocus:e=>e.currentTarget.select(),className:`sl-input w-full min-w-0 font-mono text-small`})]}),i===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i})]})]})}var Ofe={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function kfe(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function d2(){let{api:e}=z(),[t,n]=(0,m.useState)(kfe),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)(Ab,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:Ofe[e]}))}),(0,h.jsxs)(mS,{href:os(e,t),download:r,children:[(0,h.jsx)(_c,{"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)(EV,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(EV,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(EV,{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)(EV,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(EV,{children:r}),`. Firefox removes it when it restarts; load it again then.`]})]}),(0,h.jsx)(`li`,{children:`Pair it: press Copy beside the pairing token in Settings → YouTube Studio, click the Slopify extension's toolbar button, paste the token and press Pair.`})]})]})}var f2=[`studio`,`settings`];function Afe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Upload pack and extension`,info:`settings.studio.extension`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(jfe,{}),(0,h.jsx)(Nfe,{}),(0,h.jsxs)(`section`,{"aria-label":`Install the Studio extension`,children:[(0,h.jsx)(H,{as:`h3`,title:`Install the Studio extension`,className:`mb-3`}),(0,h.jsx)(d2,{})]})]})]})}var p2=``;function jfe(){let{api:e}=z(),t=_(),n=Oy(),r=(0,m.useId)(),i=N({queryKey:f2,queryFn:()=>rs(e)}),a=N(Zb(e)),o=(0,m.useId)(),[s,c]=(0,m.useState)(p2),[l,u]=(0,m.useState)(void 0),d=i.data?.playlists??[],f=s===p2?void 0:i.data?.channelPlaylists[s],p=l??(s===p2?d:f??[]),g=Mfe(p),v=P({mutationFn:t=>is(e,t,s===p2?void 0:s),onSuccess:()=>{u(void 0),t.invalidateQueries({queryKey:f2}),n(`Playlists saved.`,`success`)}}),y=e=>{v.reset(),u(e)},b=g??v.error?.message,x=[{value:p2,label:`Every channel (default)`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(xV,{label:`Playlists`,tip:`settings.studio.playlist`,help:s===p2?`The playlists upload packs offer, for every channel without its own. Ticked ones are on for every project; Prepare upload changes them for one project.`:f===void 0&&d.length>0?`This channel uses the default list (${(e=>e.map(e=>e.name).join(`, `))(d)}) until you add its own.`:`This channel's own playlists. Ticked ones are on for every project; Prepare upload changes them for one project.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(TV,{id:o,"aria-label":`Channel`,value:s,options:x,onChange:e=>{v.reset(),u(void 0),c(e.currentTarget.value)},className:`max-w-[260px]`}),p.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{autoComplete:`off`,"aria-label":`Playlist ${String(t+1)} name`,placeholder:`The playlist's name in Studio`,className:`min-w-0 flex-1 basis-[220px]`,value:e.name,disabled:i.data===void 0,"aria-invalid":e.name.trim().length>150,"aria-describedby":b===void 0?void 0:r,onChange:e=>y(p.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,h.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.byDefault,onChange:e=>{let n=e.currentTarget.checked;y(p.map((e,r)=>r===t?{...e,byDefault:n}:e))}}),`On by default`]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name.trim()||`playlist ${String(t+1)}`}`,onClick:()=>y(p.filter((e,n)=>n!==t)),children:`Remove`})]},t)),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(R,{variant:`secondary`,disabled:i.data===void 0||p.length>=20,onClick:()=>y([...p,{name:``,byDefault:p.length===0}]),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add playlist`]}),(0,h.jsx)(R,{variant:`primary`,disabled:v.isPending||l===void 0||g!==void 0,onClick:()=>v.mutate(p),children:`Save playlists`})]})]}),b===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:b})]})}function Mfe(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 Nfe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:f2,queryFn:()=>rs(e)}),i=P({mutationFn:()=>ls(e),onSuccess:()=>{t.invalidateQueries({queryKey:f2}),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)(V,{id:`settings.studio.pairing`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`code`,{className:`sl-code min-w-0 flex-1 basis-[220px] truncate py-2 select-all`,children:a?.token??`…`}),(0,h.jsxs)(R,{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)(gc,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}),`Copy`]}),(0,h.jsx)(R,{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 m2=[`studio`,`queue`];function h2({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)(R,{variant:n,size:r,disabled:!t,disabledReason:`Available once the video has been made`,onClick:()=>a(!0),children:`Prepare upload`}),i?(0,h.jsx)(v2,{projectId:e,onClose:()=>a(!1)}):null]})}var g2={video:`Video file`,title:`Title`,description:`Description`,thumbnails:`Thumbnail`,playlist:`Playlist`,audience:`Audience`,altered:`AI use (under Show more)`,tags:`Tags (under Show more)`};function _2(e){return e.kind===`video`?`video`:`short-${String(e.short)}`}function v2({projectId:e,onClose:t}){let{api:n}=z(),r=_(),i=[`studio`,`pack`,e],a=N({queryKey:i,queryFn:()=>us(n,e)}),[o,s]=(0,m.useState)(`video`),[c,l]=(0,m.useState)(),u=a.data?.items??[],d=u.find(e=>_2(e)===o)??u[0],f=N({queryKey:f2,queryFn:()=>rs(n)}),p=f.data===void 0?void 0:f.data.pairing.origin!==null,g=N({queryKey:m2,queryFn:()=>ss(n)}),v=P({mutationFn:t=>fs(n,e,t.short),onSuccess:e=>{r.setQueryData(m2,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. Drop the video file into its upload dialog; the Slopify Studio extension 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=P({mutationFn:e=>cs(n,e.projectId,e.short),onSuccess:e=>r.setQueryData(m2,e),onError:e=>l({text:`Couldn't remove it from Waiting for Studio: ${e.message} Press Remove again.`,tone:`error`})}),b=P({mutationFn:t=>ds(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=P({mutationFn:t=>as(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`})});return(0,h.jsxs)(YP,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(mS,{href:T0,target:`_blank`,rel:`noopener noreferrer`,variant:`secondary`,children:`Open YouTube Studio`}):null,(0,h.jsx)(R,{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(T0,`_blank`,`noopener`),v.mutate(d))},children:`Fill in YouTube Studio`}),(0,h.jsx)(V,{id:`project.upload.fill-studio`})]}),children:[a.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The upload pack couldn't be read.`,children:`${a.error.message} Close Prepare upload and open it again.`}),a.data===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p===!1?(0,h.jsx)(SI,{tone:`waiting`,title:`The Slopify Studio extension isn't paired.`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Without it, the steps below are the upload pack: copy each into Studio's upload dialog. To have Studio filled in for you, install the extension:`}),(0,h.jsx)(d2,{})]})}):null,u.length>1?(0,h.jsx)(Ab,{label:`What to upload`,value:d===void 0?``:_2(d),onChange:s,tip:`project.upload.item`,options:u.map(e=>({value:_2(e),label:e.kind===`video`?`Video`:`Short ${String(e.short)}`})),className:`self-start`}):null,a.data.missing.length===0?null:(0,h.jsx)(SI,{tone:`waiting`,title:`Some of it isn't made yet.`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:a.data.missing.map(e=>(0,h.jsx)(`li`,{children:e},e))})}),d===void 0?null:(0,h.jsx)(Ffe,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(kb,{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`}))},doneKey:`slopify.upload.${e}.${_2(d)}`},_2(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)(V,{id:`project.upload.queue`,className:`-my-1`})]}),(0,h.jsx)(pU,{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)(mU,{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)(R,{variant:`quiet`,size:`small`,disabled:y.isPending,"aria-label":`Remove ${e.projectTitle} ${n.toLowerCase()} from Waiting for Studio`,onClick:()=>y.mutate(e),children:`Remove`})},`${e.projectId}-${String(e.short)}`)})})]}),(0,h.jsx)(SI,{title:`Slopify never publishes.`,children:p===!1?`Copy each step into Studio's upload dialog (Open YouTube Studio), check it and press Publish yourself.`:`Fill in YouTube Studio hands this to the Slopify Studio extension after you drop the video in. You check it and press Publish.`})]})]})}function Pfe(e){try{let t=JSON.parse(localStorage.getItem(e)??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function y2({href:e,filename:t}){return(0,h.jsxs)(mS,{href:e,download:t,"aria-label":`Download ${t}`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download`]})}function Ffe({projectId:e,item:t,footageSwitch:n,playlistPicker:r,copy:i,doneKey:a}){let{api:o}=z(),[s,c]=(0,m.useState)(()=>Pfe(a)),[l,u]=(0,m.useState)(null),d=e=>{c(e);try{localStorage.setItem(a,JSON.stringify(e))}catch{}},f=(e,t)=>d(t?[...s,e]:s.filter(t=>t!==e)),p=Gde.filter(e=>e!==`thumbnails`||t.kind===`video`),g=p.filter(e=>s.includes(e)).length,_=e=>{let n=b2(t,e);return(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:n===``,disabledReason:`Nothing to copy yet`,"aria-label":`Copy ${g2[e].toLowerCase()}`,onClick:()=>i(n,g2[e].toLowerCase()),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy`]})},v=a=>{switch(a){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)(y2,{href:`${o.origin}${t.video.url}`,filename:t.video.filename}),(0,h.jsx)(u2,{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?`The first under Thumbnail; all ${String(t.thumbnails.length)} in A/B Testing (beside the title).`:t.thumbnails[0]?.filename??``,actions:(0,h.jsx)(u2,{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?b2(t,a)||(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:_(a)};case`title`:return t.titles.length===0?{value:b2(t,a),actions:_(a)}:{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:t.title}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:`A/B Testing (beside the title): also ${t.titles.map(e=>`"${e}"`).join(` and `)}`})]}),actions:(0,h.jsxs)(h.Fragment,{children:[_(a),(0,h.jsxs)(R,{variant:`quiet`,size:`small`,"aria-label":`Copy the other titles`,onClick:()=>i(t.titles.join(`
271
+ `),`other titles`),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy others`]})]})};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:_(a)};default:return{value:b2(t,a)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}),actions:_(a)}}};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)(V,{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:g===p.length,ref:e=>{e!==null&&(e.indeterminate=g>0&&g<p.length)},onChange:e=>d(e.currentTarget.checked?[...p]:[]),className:`size-4 shrink-0 accent-[var(--color-accent)]`}),`Select all`]})]}),(0,h.jsx)(pU,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:p.map(e=>{let{value:t,actions:n}=v(e);return(0,h.jsx)(mU,{className:`items-start`,lead:(0,h.jsx)(`input`,{type:`checkbox`,checked:s.includes(e),onChange:t=>f(e,t.currentTarget.checked),className:`mt-1 size-4 shrink-0 self-start accent-[var(--color-accent)]`,"aria-label":`${g2[e]} done`}),title:g2[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)(H,{as:`h3`,kicker:`Thumbnails · A/B Testing`,title:`${String(t.thumbnails.length)} ${t.thumbnails.length===1?`thumbnail`:`thumbnails`}`,className:`mb-3`}),(0,h.jsx)(B0,{label:`Thumbnails to upload`,density:`compact`,children:t.thumbnails.map((e,t)=>(0,h.jsx)(z0,{src:`${o.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,title:String.fromCharCode(65+t),meta:e.filename,onOpen:()=>u(t),openLabel:`Open thumbnail ${String.fromCharCode(65+t)} full size`,actionsShown:!0,actions:(0,h.jsx)(y2,{href:`${o.origin}${e.url}`,filename:e.filename})},e.asset))}),(0,h.jsx)(V0,{items:t.thumbnails.map((e,t)=>({src:`${o.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,caption:e.filename})),index:l,onIndex:u,onClose:()=>u(null),actions:(e,n)=>{let r=t.thumbnails[n];return r===void 0?null:(0,h.jsx)(y2,{href:`${o.origin}${r.url}`,filename:r.filename})}})]})]})}function b2(e,t){switch(t){case`title`:return e.title;case`description`:return e.description;case`tags`:return Kde(e.tags);case`playlist`:return e.playlists.join(`, `);default:return``}}var x2=4;function Ife(e){return e===`schedules`?`schedules`:`weeks`}var S2=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),C2=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),w2=new Intl.DateTimeFormat(void 0,{timeStyle:`short`}),T2=`slopify.calendar.view`;function Lfe(){try{return window.localStorage.getItem(T2)===`list`?`list`:`weeks`}catch{return`weeks`}}function Rfe({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=z(),a=_(),o=gx(),[s]=(0,m.useState)(()=>sU(new Date,x2)),[c,l]=(0,m.useState)(Lfe),[u,d]=(0,m.useState)(e??`weeks`),f=n===void 0?u:e??`weeks`,p=e=>{n===void 0?d(e):n(e)},[g,v]=(0,m.useState)(!1),y=N(KH(i,s.from,s.to)),b=N(EH(i)),x=N(Hq(i)),S=N(Yy(i)),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),D=(0,m.useMemo)(()=>new Map((x.data??[]).map(e=>[e.id,e.channelId])),[x.data]),O=(0,m.useMemo)(()=>new Map((S.data?.projects??[]).map(e=>[e.id,e.channelId])),[S.data]),k=(b.data??[]).filter(e=>o.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>o.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>o.includes(O.get(e.id)))},ee=(0,m.useMemo)(()=>A===void 0?new Map:oU(A),[A]),te=A?.runs??[],ne=tU(A?.projects??[]),j=P({mutationFn:e=>e(),onSuccess:e=>w(e.ok?{tone:`info`,text:`Moved.`}:{tone:`error`,text:e.message}),onError:e=>w({tone:`error`,text:`The topic wasn't moved: ${e.message} Reload the calendar and try again.`}),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:GH}),a.invalidateQueries({queryKey:TH})])}}),re=e=>{if(e.kind!==`none`){if(e.kind===`refused`){w({tone:`error`,text:e.message});return}e.kind===`move`?j.mutate(()=>HH(i,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to})):j.mutate(()=>WH(i,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}}))}},M=(e,t)=>{let n=lU(te,e,t);if(n===void 0){w({tone:`error`,text:t===-1?`${uU(e)} is already the next topic of ${e.scheduleName}.`:`${uU(e)} is the last topic on the calendar for ${e.scheduleName}.`});return}re(cU(e,n,C2.format(new Date(n.at))))},ie=e=>{l(e),f!==`weeks`&&p(`weeks`);try{window.localStorage.setItem(T2,e)}catch{}};bx({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),bx({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>p(`schedules`)}),Yx(Wx.addToCalendar,()=>v(!0)),bx({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>ie(`weeks`)}),bx({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>ie(`list`)});let ae=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),oe=C?.text??y.error?.message??b.error?.message,se=rU(new Date),ce=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(kq,{title:`Calendar`,meta:`${o.channel?.name??`Every channel`} · ${String(te.length)} scheduled ${te.length===1?`run`:`runs`} in the next ${String(x2)} weeks · ${String(ae)} ${ae===1?`topic`:`topics`} queued`,actions:f===`schedules`?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Ab,{label:`Calendar view`,tip:`planning.calendar.view`,value:c,onChange:ie,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(R,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]})}),(0,h.jsx)(r0,{items:[{id:`weeks`,label:`Coming weeks`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ce)}}],value:f,onChange:p,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(i0,{idPrefix:`calendar`,id:`schedules`,active:f===`schedules`,children:f===`schedules`?(0,h.jsx)(zde,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(i0,{idPrefix:`calendar`,id:`weeks`,active:f===`weeks`,children:[(0,h.jsx)(Q1,{tone:C?.tone===`info`?`info`:oe?`error`:`info`,className:`mb-3`,children:oe}),(0,h.jsxs)(e0,{split:`aside`,className:`mb-6`,children:[(0,h.jsx)(t0,{label:`Needs you`,children:ne.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Nothing needs you right now.`}):(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(H,{title:`Needs you`,meta:eU(ne)}),(0,h.jsx)(pU,{label:`Needs you`,children:ne.map(e=>(0,h.jsx)(O2,{project:e},e.id))})]})}),(0,h.jsx)(t0,{as:`aside`,label:`Suggested topics`,children:(0,h.jsx)(vde,{schedules:k})})]}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[y.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the calendar…`}):c===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic to another day to change when it runs, or onto another schedule's run to move it there. With the keyboard: focus a topic and press Alt+← or Alt+→.`}),aU(new Date(s.from),x2).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=rU(e),n=ee.get(t);return(0,h.jsx)(zfe,{date:e,today:t===se,day:n,dragging:T,busy:j.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(re(cU(T,t,C2.format(e))),E(null))},onStep:M},t)})},rU(e[0]??new Date)))]}):(0,h.jsx)(Vfe,{days:ee,busy:j.isPending,onStep:M,schedules:k,onTransfer:(e,t)=>{e.index!==null&&re({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0})}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(H,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(pU,{label:`Batch queue`,children:A.queued.toSorted((e,t)=>e.position-t.position).map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsx)(_S,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`})},e.projectId)})})]}):null]})]}),(0,h.jsx)(JH,{open:g,onOpenChange:v,schedules:k})]})}function zfe({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,E2),v=()=>p.find(e=>e.scheduleId===r?.scheduleId)??p[0];return(0,h.jsxs)(`section`,{"aria-label":C2.format(e),className:L(`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 · ${S2.format(e)}`:S2.format(e)}),p.map(e=>(0,h.jsx)(Bfe,{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=$H(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${dU}`,children:[(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${fU}`,children:e.title}),(0,h.jsx)(_S,{tone:t.tone,children:t.word})]},e.id)}),g.length>E2?(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":d,className:`self-start`,onClick:()=>f(e=>!e),children:d?`Show fewer`:`+${String(g.length-E2)} more`}):null]})}var E2=3;function Bfe({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=uU(e);return(0,h.jsxs)(`article`,{tabIndex:e.index===null?void 0:0,"aria-label":`${s}, ${w2.format(new Date(e.at))}, ${e.scheduleName}${e.index===null?``:`. Alt+arrow keys move it.`}`,draggable:o,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,s),n(e)},onDragEnd:r,onDragOver:e=>e.preventDefault(),onDrop:i,onKeyDown:t=>{o&&t.altKey&&(t.key===`ArrowLeft`||t.key===`ArrowUp`?(t.preventDefault(),a(e,-1)):(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(t.preventDefault(),a(e,1)))},className:L(`sl-cal-item`,o&&`sl-cal-item--movable`),children:[(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:w2.format(new Date(e.at))}),(0,h.jsx)(`b`,{className:L(`text-small`,e.topic===null&&`font-normal text-ink-2`),children:s}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.scheduleName}),e.paused?(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(_S,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(_S,{tone:`off`,children:`Queued`}):(0,h.jsx)(_S,{tone:`info`,children:`Prepared`}),(0,h.jsx)(D2,{run:e,compact:!0})]})}function D2({run:e,compact:t=!1}){let{api:n}=z(),r=_(),[i,a]=(0,m.useState)(),o=P({mutationFn:async()=>{if(e.topic===null)throw Error(`This run has no topic to prepare yet.`);let t=await LH(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:GH}),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)(R,{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)(fS,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}function O2({project:e}){let t=$H(e);return(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(_S,{tone:t.tone,children:t.word}),t.action===void 0?null:t.action.kind===`upload`?(0,h.jsx)(h2,{projectId:e.id,ready:!0}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function Vfe({days:e,busy:t,schedules:n,onStep:r,onTransfer:i}){let a=[...e.values()].sort((e,t)=>e.key.localeCompare(t.key));if(a.length===0)return(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Nothing is planned for the next `,x2,` weeks. Add topics with Add to calendar, or create a schedule on the`,` `,(0,h.jsx)(ha,{to:`/calendar`,search:{tab:`schedules`},children:`Schedules`}),` `,`tab.`]});let o=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,...Ob,children:[(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Move a topic earlier, later or to another schedule from its row.`,(0,h.jsx)(V,{id:`planning.calendar.move`,className:`-my-1`})]}),a.map(e=>(0,h.jsxs)(`section`,{"aria-label":C2.format(e.date),children:[(0,h.jsx)(H,{title:C2.format(e.date),as:`h3`}),(0,h.jsxs)(pU,{label:`Planned on ${C2.format(e.date)}`,children:[e.runs.map(e=>{let n=uU(e),a=o.filter(t=>t.id!==e.scheduleId);return(0,h.jsx)(mU,{title:n,meta:`${w2.format(new Date(e.at))} · ${e.scheduleName}${e.templateName===null?``:` · ${e.templateName}`}${e.paused?` · Paused`:``}`,actions:e.index===null?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(D2,{run:e}),(0,h.jsx)(wy,{size:`small`,label:`Move ${n} earlier`,disabled:t,onClick:()=>r(e,-1),children:(0,h.jsx)(ic,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(wy,{size:`small`,label:`Move ${n} later`,disabled:t,onClick:()=>r(e,1),children:(0,h.jsx)(tc,{"aria-hidden":`true`,strokeWidth:1.75})}),a.length===0?null:(0,h.jsxs)(`select`,{"aria-label":`Move ${n} to another schedule`,className:`sl-select h-8 w-auto text-small`,value:``,disabled:t,onChange:t=>{t.target.value!==``&&i(e,t.target.value)},children:[(0,h.jsx)(`option`,{value:``,children:`Move to…`}),a.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})},`${e.scheduleId}-${e.at}`)}),e.projects.map(e=>(0,h.jsx)(O2,{project:e},e.id))]})]},e.key))]})}var Hfe=wj.map(e=>({value:e,label:Tj[e]}));function Ufe({channel:e}){let{api:t}=z(),n=_(),r=Oy(),i=P({mutationFn:n=>lx(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${Tj[e.aiDisclosure]}.`,`success`),n.setQueryData(Jb(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:qb,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)(xV,{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)(TV,{value:i.isPending?i.variables:e.aiDisclosure,options:Hfe,disabled:i.isPending,onChange:e=>{let t=wj.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(Q1,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}function k2({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)(xV,{label:r,tip:o,help:Wfe(s),error:i,children:(0,h.jsxs)(TV,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:zO.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,BO(n.language).name,`)`]}),RO.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function Wfe(e){let t=BO(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=VO(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 Gfe({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`,...Ob,children:[(0,h.jsx)(H,{title:`Channel links`,meta:`Write a link's name in braces in a description, such as {{Patreon}}.`,info:`planning.links.named`}),e.length===0?(0,h.jsx)(`p`,{className:`m-0 border-y border-line py-4 text-ink-2`,children:`No channel links yet. Add one, then write its name in braces in a description.`}):(0,h.jsx)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:e.map((r,i)=>(0,h.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,1fr)] items-center gap-2 border-b border-line py-3 md:grid-cols-[220px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(CV,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})}),(0,h.jsx)(CV,{"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)(R,{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)(Bc,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(R,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function Kfe(){return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsx)(H,{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)(fS,{to:`/channels/$channelId`,params:{channelId:Wb},children:`Open the default channel's links`})})]})}function A2({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(eA.levelDb),fadeIn:e?.fadeIn??String(eA.fadeInSeconds),tail:e?.tail??String(eA.tailSeconds)},u=e=>{if(e===``)s(void 0);else if(e===`none`)s({source:`none`,...l});else{let t=n.find(t=>t===e);t!==void 0&&s({source:t,...l})}},d=(t,n,r,a)=>e===void 0||!c?null:(0,h.jsx)(xV,{label:n,help:r,tip:a,error:i(t),children:(0,h.jsx)(CV,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})})});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(xV,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(TV,{"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:$k[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 qfe({value:e,onChange:t}){let n=aA(e),r=n===void 0?[]:nA(n);return(0,h.jsx)(A2,{value:e,inherit:`Not set`,sources:Zk,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function Jfe(e){return e.ambientBed===void 0?void 0:iA(e.ambientBed)}function Yfe(e){let t=aA(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:nA(t).length>0}}var j2=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`];function Xfe(e){return Object.fromEntries(j2.map(t=>[t,e[t]??``]))}function Zfe({channel:e}){let{api:t}=z(),n=_(),r=Oy(),i=N({queryKey:sN,queryFn:()=>cN(t)}),a=N(rb(t)),o=N(ib(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(Xfe(e.brand)),[p,g]=(0,m.useState)(Jfe(e.brand)),v=Yfe(p),y=N({queryKey:B.channelLinks,queryFn:()=>ws(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=P({mutationFn:()=>ex(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(j2.flatMap(e=>d[e].trim()===``?[]:[[e,d[e].trim()]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(Jb(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:qb}),n.invalidateQueries({queryKey:B.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),D=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),O=[...(o.data?.builtIns??[]).map(e=>({value:e.name,label:e.label})),...(o.data?.themes??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(`form`,{"aria-label":`Brand kit`,onSubmit:e=>{e.preventDefault(),w.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-5`,children:[(0,h.jsx)(xV,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(CV,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(xV,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules.`,children:(0,h.jsx)(wV,{rows:4,value:l,maxLength:1e4,onChange:e=>u(e.target.value)})}),(0,h.jsx)(H,{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)(k2,{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)(M2,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:E,onPick:T(`captionFontId`)}),(0,h.jsx)(N2,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(N2,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`)})]}),(0,h.jsxs)(`section`,{"aria-label":`Chapter cards and end screen`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(M2,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:E,onPick:T(`titleFontId`)}),(0,h.jsx)(N2,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(xV,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(CV,{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)(M2,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:D(`intro`),onPick:T(`intro`)}),(0,h.jsx)(M2,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:D(`outro`),onPick:T(`outro`)}),(0,h.jsx)(M2,{label:`Document theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:O,onPick:T(`documentTheme`)})]}),(0,h.jsx)(qfe,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(Gfe,{rows:S,onChange:x})})]}),(0,h.jsx)($1,{status:(0,h.jsx)(Q1,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked,disabledReason:s.trim()===``?`Give the channel a name`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function M2({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(xV,{label:e,tip:t,children:(0,h.jsxs)(TV,{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 N2({label:e,tip:t,value:n,onChange:r}){let i=/^#[0-9a-fA-F]{6}$/.test(n);return(0,h.jsx)(xV,{label:e,tip:t,...n!==``&&!i?{error:`Write the colour as # and six hex digits.`}:{},children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-6 shrink-0 rounded-control border border-line-strong`,style:{background:i?n:`transparent`}}),(0,h.jsx)(CV,{value:n,placeholder:`#FFFFFF`,maxLength:7,onChange:e=>r(e.target.value)})]})})}function P2(e,t){return e.languages===void 0||e.languages.includes(BO(t).code)}function Qfe(e,t,n,r){return n?e:e.filter(e=>P2(e,t)||e.voiceId===r)}function $fe(e,t){if(e===void 0||P2(e,t))return;let n=BO(t).name,r=(e.languages??[]).map(e=>BO(e).code===e?BO(e).name:e);return`${e.name} is listed for ${r.join(`, `)}, not ${n}, so it may read the ${n} narration with the wrong accent. Pick a ${n} voice under Narration, or correct the voice's languages in Settings → Voices.`}function F2(e,t,n){let[r,i]=(0,m.useState)(!1),a=Qfe(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function I2({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=$fe(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`,...Ob,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 ${BO(e).name})`]}),(0,h.jsx)(V,{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 epe({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=z(),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:Jb(e)}),o.invalidateQueries({queryKey:qb})]),T=P({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?nx(a,e,crypto.randomUUID(),n):rx(a,t.id,{...n,baseVersion:t.version})},onSuccess:async e=>{await w(),t===void 0&&i(e.id)}}),E=()=>{let e=p.trim();e===``||d.some(t=>t.toLowerCase()===e.toLowerCase())||(f([...d,e]),g(``))};return n?(0,h.jsxs)(`section`,{"aria-label":t===void 0?`Add to cast`:`Edit ${t.name}`,children:[(0,h.jsx)(H,{kicker:t===void 0?`New cast member`:Kb[t.kind],title:t===void 0?`Add to cast`:t.name,meta:t===void 0?`Name it first, then give it reference pictures.`:`Used whenever a title or an image brief names it or one of its aliases.`,children:(0,h.jsx)(R,{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)(xV,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(TV,{value:s,onChange:e=>c(Gb.find(t=>t===e.target.value)??`character`),options:Gb.map(e=>({value:e,label:Kb[e]}))})}),(0,h.jsx)(xV,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(CV,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(xV,{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)(CV,{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)(R,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(Nc,{"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)(yS,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(xV,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(wV,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(npe,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(kb,{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)(Q1,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(R,{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)(tpe,{channelId:e,member:t})]}):null}function tpe({channelId:e,member:t}){let{api:n}=z(),r=_(),i=N(eb(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:Jb(e)}),r.invalidateQueries({queryKey:qb})]),g=P({mutationFn:e=>ax(n,t.id,e),onSettled:p}),v=P({mutationFn:()=>ox(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=P({mutationFn:e=>sx(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:ux(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)(Mq,{className:`mb-6`}),(0,h.jsx)(H,{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)(B0,{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)(z0,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:ux(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)(vS,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(R,{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)(rpe,{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)(V0,{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)(mS,{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)(R,{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`,...Ob,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(V,{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)(RV,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(zV,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(xV,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,children:(0,h.jsx)(wV,{ref:o,rows:3,value:d,maxLength:4e3,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(R,{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)(Q1,{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 npe({channelId:e,value:t,onChange:n}){let{api:r}=z(),i=N(eb(r)),a=N(tb(r)),o=N(Qb(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=F2(c,o,s.voice||void 0),u=l.listed;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-3 border-0 border-t border-line p-0 pt-4`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(V,{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)(RV,{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)(zV,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(FV,{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)(I2,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(FV,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:AA.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)(R,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function rpe({error:e,retry:t,onReword:n}){let r=V1({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)(Ey,{className:`mt-2`,children:(0,h.jsx)(Y1,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(R,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}function ipe({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=z(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=P({mutationFn:e=>ix(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:Jb(e)}),a.invalidateQueries({queryKey:qb})])}}),p=t.find(e=>e.id===c),g=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:ux(i,t)}]:[]}),v=g.map(e=>({src:e.src,alt:e.member.name,caption:`${Kb[e.member.kind]} · ${e.member.description||`No description yet`}`})),[y,b]=(0,m.useState)(null),x=c===`new`||p!==void 0;return(0,h.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 min-[1024px]:grid-cols-[minmax(0,1fr)_440px]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:`When a video's title or an image's brief names a member, its pictures go with that image as references, so it looks the same in every video.`}),t.length===0?(0,h.jsx)(a0,{title:`No cast yet`,actions:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>l(`new`),children:`Add to cast`}),children:`Add the characters, creatures, places and objects this channel keeps coming back to.`}):(0,h.jsx)(B0,{label:`Cast`,children:t.map(e=>{let t=e.images.filter(e=>e.state===`ready`),n=t[0]?.sha256;return(0,h.jsx)(z0,{className:L(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...n?{src:ux(i,n)}:{},alt:e.name,onOpen:()=>b(g.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${Kb[e.kind]}${e.host===!0?` · Host`:``} · ${String(t.length)} ${t.length===1?`picture`:`pictures`}`,...t.length===0?{badge:(0,h.jsx)(vS,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`})]})},e.id)})}),(0,h.jsx)(V0,{items:v,index:y,onIndex:b,onClose:()=>b(null),actions:(e,t)=>{let n=g[t];return n===void 0?null:(0,h.jsx)(R,{size:`small`,onClick:()=>{b(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(Q1,{tone:`error`,className:`mt-2`,children:u?void 0:f.error?.message})]}),(0,h.jsx)(`aside`,{"aria-label":`Cast member editor`,className:`min-w-0`,children:x?(0,h.jsx)(epe,{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)(jy,{open:u!==null,title:`Delete ${u?.name??`this cast member`}?`,consequence:f.error?.message??`New videos stop using its pictures. Videos already made keep the pictures they were started with.`,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var L2=e=>[`channels`,e,`episodes`],R2=e=>[`channels`,e,`videos`],z2=(e,t)=>`${e.origin}/api/channels/${t}`,B2=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function ape(e,t){return ct({queryKey:L2(t),queryFn:async()=>F(await e.fetch(`${z2(e,t)}/episodes`))})}async function ope(e,t,n){return F(await e.fetch(`${z2(e,t)}/episodes/setting`,B2(`PUT`,{enabled:n})))}async function spe(e,t,n,r){return F(await e.fetch(`${z2(e,t)}/episodes/${encodeURIComponent(n)}`,B2(`PUT`,{summary:r})))}async function cpe(e,t,n){let r=await e.fetch(`${z2(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await F(r)}function V2(e,t){return ct({queryKey:R2(t),queryFn:async()=>(await F(await e.fetch(`${z2(e,t)}/videos`))).videos})}async function lpe(e,t,n){return F(await e.fetch(`${z2(e,t)}/videos`,B2(`POST`,n)))}async function upe(e,t,n){return F(await e.fetch(`${z2(e,t)}/videos/preview`,B2(`POST`,{format:`csv`,text:n})))}async function dpe(e,t,n){let r=await e.fetch(`${z2(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await F(r)}async function fpe(e,t){await F(await e.fetch(`${z2(e,t)}/videos`,{method:`DELETE`}))}var ppe=e=>e.length>160?`${e.slice(0,160)}…`:e;function mpe({channelId:e}){let{api:t}=z(),n=_(),r=N(ape(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:L2(e)}),l=P({mutationFn:n=>ope(t,e,n),onSuccess:t=>n.setQueryData(L2(e),t)}),u=P({mutationFn:n=>cpe(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kb,{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)(Q1,{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)(a0,{title:`No episodes remembered yet`,children:d?`When a video on this channel finishes, its summary appears here.`:`Turn on episode memory, and the next finished video's summary appears here.`}):null,f.length>0?(0,h.jsx)(pU,{label:`Episode summaries`,children:f.map(e=>(0,h.jsx)(mU,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,ppe(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(R,{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)(hpe,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(jy,{open:o!==null,title:`Delete the summary of ${o?.title??`this episode`}?`,consequence:u.error?.message??`New episodes stop being reminded of it. The video itself is not changed.`,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function hpe({channelId:e,memory:t,onClose:n}){let{api:r}=z(),i=_(),[a,o]=(0,m.useState)(t.summary),s=P({mutationFn:()=>spe(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:L2(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Ay,{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)(R,{onClick:n,children:`Close`}),(0,h.jsx)(R,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(xV,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(wV,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}var H2=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function U2(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function gpe({channelId:e}){let{api:t}=z(),n=_(),r=N(V2(t,e)),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(void 0),u=(0,m.useRef)(null),d=()=>n.invalidateQueries({queryKey:R2(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=P({mutationFn:n=>lpe(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${H2(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=P({mutationFn:n=>upe(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:U2(e.titles,e.filter)})}}),x=P({mutationFn:n=>dpe(t,e,n),onSuccess:d}),S=P({mutationFn:()=>fpe(t,e),onSuccess:async()=>{s(!1),await d()}}),C=r.data??[],w=y.isPending||b.isPending||x.isPending||S.isPending,T=r.error??b.error??y.error??x.error;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`Topic suggestions and duplicate checks skip these titles, as they skip the videos made here.`}),(0,h.jsx)(xV,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(wV,{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)(R,{variant:`primary`,disabled:w||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(R,{disabled:w,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(V,{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)(R,{variant:`quiet`,disabled:w||C.length===0,onClick:()=>{S.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(Q1,{tone:T?`error`:c?`success`:`info`,className:`mt-1`,children:T?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(_pe,{preview:f,filter:g,busy:w,onFilter:e=>{v(e),p({...f,ticked:U2(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(`
272
+ `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(a0,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(pU,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(mU,{title:e.title,actions:(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(jy,{open:o,title:`Remove all ${H2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function _pe({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...Ob,children:[(0,h.jsxs)(H,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${H2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(R,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,H2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(R,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(xV,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(CV,{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)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(R,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(pU,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(mU,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`],vpe={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`};function ype(e){return W2.find(t=>t===e)??`brand`}function bpe({channelId:e,tab:t,onTab:n}){let{api:r}=z(),i=_(),a=Zi(),o=N(Qb(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=P({mutationFn:()=>tx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:qb}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return bx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(ha,{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)(R,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(r0,{items:W2.map(e=>({id:e,label:vpe[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(Q1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(i0,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(Ufe,{channel:f}),(0,h.jsx)(Zfe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(ipe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(Sde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Tde,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(mpe,{channelId:f.id}):null}),(0,h.jsx)(i0,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(gpe,{channelId:f.id}):null})]}):null,(0,h.jsx)(jy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function G2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:L(`sl-stats m-0`,e),children:t})}function K2({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 q2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:L(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function J2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:L(`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)))})]})}function xpe(){let{api:e}=z(),t=_(),n=Zi(),r=N(Zb(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=P({mutationFn:()=>$b(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:qb}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=P({mutationFn:t=>ex(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:qb}),a(null)}}),v=P({mutationFn:t=>tx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:qb})}}),y=()=>{p.reset(),l(``),a(`new`)};bx({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)(kq,{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)(V,{id:`planning.channels`})]}),actions:(0,h.jsxs)(R,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(Q1,{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)(a0,{title:`No channels yet`,actions:(0,h.jsx)(R,{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)(jq,{list:(0,h.jsx)(pU,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(mU,{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)(pS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(R,{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)(R,{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)(Spe,{channel:f})}):null,(0,h.jsx)(Ay,{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)(Q1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(R,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(R,{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)(xV,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(CV,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(jy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function Spe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(H,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(fS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(G2,{className:`mb-6`,children:[(0,h.jsx)(K2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(K2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(H,{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)(H,{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 Y2=2e3;function X2(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()},Y2);return()=>{clearTimeout(t)}},[e])}function Z2(){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)(lc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function Q2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Oy();bx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:lP.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)(R,{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)(Q1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(Z2,{}):t)}),a,(0,h.jsx)(R,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Mx(lP.save),onClick:()=>{c||s()},children:`Save`})]})}var Cpe=`rounded-media border border-line bg-surface p-4`;function $2(){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:`${Cpe} 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 wpe=`modulepreload`,Tpe=function(e){return`/`+e},e4={},t4=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=Tpe(t,n),t=s(t),t in e4)return;e4[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`:wpe,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 Epe({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 Dpe(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 Dpe(e,t){let n=await t4(()=>import(`./pdf-Dh7upqzO.js`),[]),r=await t4(()=>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 n4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),i4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),a4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),o4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),s4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),c4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),Ope=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},n4([`page`,`margin`],`Margins`),n4([`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:[c4(`body`,`Body`),c4(`strong`,`Bold text`),c4(`emphasis`,`Italic text`),c4(`heading`,`Headings`),c4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),c4(`decorative`,`Tagline and title-page link`),c4(`dropCap`,`Drop caps`),c4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[r4([`sizes`,`title`],`Title`),r4([`sizes`,`brand`],`Brand`),r4([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),r4([`sizes`,`heading`],`Second-level headings`),r4([`sizes`,`subheading`],`Third-level headings`),r4([`sizes`,`body`],`Body`),r4([`sizes`,`meta`],`Date and word count`),r4([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[n4([`spacing`,`bodyLine`],`Body line height`),n4([`spacing`,`headingLine`],`Heading line height`),n4([`spacing`,`subheadingLine`],`Subheading line height`),i4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),i4([`spacing`,`headingGap`],`Before a heading`,`× line`),i4([`spacing`,`itemGap`],`After a list item`,`× line`),n4([`spacing`,`listIndent`],`List indent`),n4([`spacing`,`quoteIndent`],`Quote indent`),n4([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[a4([`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`}]},i4([`dropCap`,`scale`],`Letter size`,`× lines`),n4([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},i4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[n4([`titlePage`,`brandY`],`Brand from top`),n4([`titlePage`,`taglineOffset`],`Tagline below brand`),n4([`titlePage`,`titleY`],`Title from top`),n4([`titlePage`,`titleLine`],`Title line height`),n4([`titlePage`,`metaOffset`],`Details below title`),n4([`titlePage`,`metaLine`],`Details line height`),a4([`titlePage`,`showDate`],`Show the date`),a4([`titlePage`,`showWordCount`],`Show the word count`),a4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),n4([`titlePage`,`cover`,`gap`],`Space around cover`),n4([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[s4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),s4([`brand`,`tagline`],`Tagline`),s4([`brand`,`url`],`Website`,`Where the brand and its link go.`),s4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[a4([`contents`,`enabled`],`Contents page`),o4([`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`}]},n4([`contents`,`titleOffset`],`Title from top margin`),n4([`contents`,`firstEntryOffset`],`First entry from top margin`),n4([`contents`,`line`],`Line height`),n4([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[a4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),n4([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},a4([`footer`,`enabled`],`Page numbers`),o4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),n4([`footer`,`bottom`],`From the bottom`),n4([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[a4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),o4([`sources`,`title`],`Title`),n4([`sources`,`titleOffset`],`Title from top margin`),n4([`sources`,`bodyOffset`],`List from top margin`),n4([`sources`,`line`],`Line height`),n4([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[a4([`endPage`,`enabled`],`Closing page`),o4([`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.`},a4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},s4([`endPage`,`closing`],`Closing line`),n4([`endPage`,`titleOffset`],`Title from top margin`),n4([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[o4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),o4([`metadata`,`subject`],`Subject`),o4([`metadata`,`keywords`],`Keywords`),o4([`metadata`,`creator`],`Creator`)]}],l4=$j.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function u4(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 kpe(e,t){let n=e;for(let e of t)n=n?.[e];return n}function d4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:d4(a,i,n)}}function Ape(e){let t=sM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function f4(e){return`values.${e.join(`.`)}`}var p4=`pt-1`,m4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function h4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(fc,{"aria-hidden":`true`}),e]})}function g4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(SI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function _4({themeId:e,from:t,onLeave:n}){let{api:r}=z(),i=_(),a=N(ib(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=P({mutationFn:t=>Fs(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:ib(r).queryKey})}}),w=P({mutationFn:e=>Is(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:ib(r).queryKey}),n()}});X2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:sM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:ZS(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)(b4,{children:a.error.message});if(v===void 0)return(0,h.jsx)($2,{});if(S===void 0)return(0,h.jsx)(b4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(xV,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),Ope.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>v4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(fc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(Npe,{field:e,theme:S.values,problem:v4(E,e.path),onChange:t=>{D({...S,values:t},f4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(fS,{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)(Mpe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(jy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var jpe={"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 v4(e,t){let n=f4(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 Mpe({values:e}){let{api:t}=z(),[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`),Ls(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:m4,children:[(0,h.jsx)(H,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(mS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(yc,{"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)(Epe,{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 Npe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=kpe(t,e.path),o=jpe[f4(e.path)],s=o===void 0?null:(0,h.jsx)(V,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(d4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=Ape(e.path);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(CV,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(CV,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(CV,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(TV,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=u4(t.family);return(0,h.jsx)(y4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(TV,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=l4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=u4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:l4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(TV,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(CV,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(wV,{...d,rows:8,value:Array.isArray(a)?a.join(`
273
273
  `):``,onChange:e=>{c(e.target.value.split(`
274
- `))}}),u]});case`link`:{let t=a;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),s]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(CV,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{c({...t,text:e.target.value})}}),(0,h.jsx)(CV,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{c({...t,url:e.target.value===``?null:e.target.value})}})]}),u]})}}}function y4({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ob,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 b4({children:e}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/document-themes`,children:`Back to Documents`}),children:e})}var Npe=4e3;function x4(e){return e.match(/\s+|[^\s]+/gu)??[]}function Ppe(e,t){let n=x4(e),r=x4(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=[];C4(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 Ipe(s,c))C4(o,e.op,e.text);return C4(o,`same`,n.slice(n.length-a).join(``)),o}function S4(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function Fpe(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+x4(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function C4(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 Ipe(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,Npe),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())C4(f,e.op,e.text);return f}function w4({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>Ppe(e,t),[e,t]),a=Fpe(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)(T4,{label:n,parts:S4(i,`before`)}),(0,h.jsx)(T4,{label:r,parts:S4(i,`after`)})]})]})}function T4({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:Lpe(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 Lpe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var E4={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function D4(e,t){let{api:n}=z();return N({queryKey:E4.versions(e,t),queryFn:()=>ks(n,e,t)})}function Rpe(e,t){let{api:n}=z();return N({queryKey:E4.usedBy(e,t),queryFn:()=>As(n,e,t)})}function O4({item:e,id:t,name:n,onClose:r}){let{api:i}=z(),a=_(),o=D4(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=P({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:E4.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?B.prompts:B.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)(YP,{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)(H,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(TV,{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:A4(e,b)},e.version))})}),(0,h.jsx)(xV,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(TV,{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:A4(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)(w4,{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)(H,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(pU,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(mU,{title:`Version ${String(e.version)}`,meta:k4(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(R,{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)(Q1,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function k4(e){return`${e.author} · ${j4(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function A4(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${j4(e.createdAt)}`}function j4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function M4({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)(H,{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)(EV,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(zpe,{item:e,id:t}),(0,h.jsx)(Bpe,{item:e,id:t,name:n,onOpenHistory:c})]})}function zpe({item:e,id:t}){let n=Rpe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:Vpe(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)(pU,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{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)(mU,{title:(0,h.jsx)(ha,{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 Bpe({item:e,id:t,name:n,onOpenHistory:r}){let i=D4(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:`${N4(a.length,`version`)} · latest ${k4(o)}`},children:(0,h.jsx)(R,{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)(w4,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function Vpe(e){return[N4(e.templates.length,`template`),N4(e.schedules.length,`schedule`),N4(e.projects.length,`project`)].join(`, `)}function N4(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function P4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}var F4=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,I4=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function L4({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 R4({what:e,message:t,onRetry:n}){return(0,h.jsx)(SI,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(R,{size:`small`,onClick:n,children:`Try again`}),children:t})}function z4({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:L(`flex flex-wrap items-center gap-0.5`,o),children:[t,n,r===void 0?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Use ${e} in Play`,title:r.blocked,disabled:r.run===void 0||r.blocked!==void 0,onClick:r.run,children:`Use in Play`}),i===void 0?null:(0,h.jsx)(wy,{size:`small`,label:`History of ${e}`,onClick:i,children:(0,h.jsx)(Fc,{"aria-hidden":`true`})}),(0,h.jsx)(wy,{size:`small`,label:`Delete ${e}`,onClick:a,children:(0,h.jsx)(Bc,{"aria-hidden":`true`})})]})}var Hpe=[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & Outros`},{to:`/templates`,label:`Templates`},{to:`/document-themes`,label:`Documents`},{to:`/narration-aliases`,label:`Aliases`}];function Upe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Library`,meta:`Prompts, intros and outros, templates, document themes and narration aliases`}),(0,h.jsx)(bde,{items:Hpe,label:`Library sections`,className:`mb-6`}),(0,h.jsx)(Wpe,{}),(0,h.jsx)(ja,{})]})}function Wpe(){let e=Zi(),t=Va({select:e=>e.location}),n=t.search,r=vV(t.pathname===`/prompts`?n.kind:void 0),i=hV(t.pathname===`/entries`?n.category:void 0);return bx({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),bx({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),bx({id:`library.new-document-theme`,title:`New document theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),bx({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),bx({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),bx({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),bx({id:`library.open-document-themes`,title:`Open document themes`,group:`Library`,keywords:[`pdf`,`documents`],run:()=>{e({to:`/document-themes`})}}),null}function B4({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:L(`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)(Ey,{className:`ml-auto shrink-0`,children:t})]})}function Gpe(){let{api:e}=z(),t=_(),n=N(ib(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(void 0),s=P({mutationFn:t=>Is(e,t),onSettled:async()=>{o(void 0),await t.invalidateQueries({queryKey:B.documentThemes})}}),c=n.data,l=r!==void 0&&`saved`in r?c?.themes.find(e=>e.id===r.saved):void 0,u=r!==void 0&&`builtIn`in r?c?.builtIns.find(e=>e.name===r.builtIn):void 0,d=l===void 0&&u===void 0?c?.themes[0]:void 0,f=l??d,p=f===void 0?u??c?.builtIns[0]:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B4,{action:(0,h.jsx)(fS,{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)(R4,{what:`document themes`,message:n.error.message,onRetry:()=>void n.refetch()}),c===void 0?n.error===null?(0,h.jsx)(L4,{label:`Document themes`}):null:(0,h.jsx)(jq,{className:F4,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)(H,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`}),c.themes.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No themes of your own yet. Copy a built-in below to start one.`}):(0,h.jsx)(pU,{label:`Your themes`,children:c.themes.map(e=>(0,h.jsx)(mU,{className:I4,lead:(0,h.jsx)(K4,{colors:e.values.colors}),title:e.name,meta:`${V4(e.values)} · updated ${P4(e.updatedAt)}`,selected:e.id===f?.id,onSelect:()=>i({saved:e.id}),actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>o(e)})},e.id))})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(pU,{label:`Built-in themes`,children:c.builtIns.map(e=>(0,h.jsx)(mU,{className:I4,lead:(0,h.jsx)(K4,{colors:e.values.colors}),title:e.label,meta:V4(e.values),selected:e.name===p?.name,onSelect:()=>i({builtIn:e.name}),actions:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:f===void 0?p===void 0?null:(0,h.jsx)(W4,{name:p.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:p.values,action:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:p.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(W4,{name:f.name,kicker:`Your theme`,meta:`Updated ${P4(f.updatedAt)}`,values:f.values,action:(0,h.jsx)(fS,{to:`/document-themes/$themeId`,params:{themeId:f.id},size:`small`,children:`Edit theme`})})}),s.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:s.error.message}),(0,h.jsx)(jy,{open:a!==void 0,title:`Delete "${a?.name??``}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:s.isPending,onConfirm:()=>{a!==void 0&&s.mutate(a.id)},onCancel:()=>o(void 0)})]})}function V4(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${H4(e.fonts.body.family)} body`}function H4(e){return l4.find(t=>t.value===e)?.label??e}function U4(e){return e.startsWith(`#`)?e:`#${e}`}function W4({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)(H,{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)(G4,{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:U4(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:U4(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(G4,{label:`${e} font`,children:`${H4(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(G4,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${U4(r.background.color)}`} background`})]})]})}function G4({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 K4({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:U4(e)}},t))})}function q4(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 J4({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Oy(),[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`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(CV,{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)(R,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(V,{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)(hU,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(wy,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function Kpe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=z(),a=_(),o=N(rb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=xx(l,`intros and outros`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=P({mutationFn:e=>Vs(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:B.entries})}}),x=async(e,t)=>{let n=await Ns(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:B.entries}),n.ok?null:q4(n.fields)},S=o.data?.entries.filter(t=>t.category===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B4,{action:(0,h.jsx)(fS,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`}),children:[(0,h.jsx)(CV,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":Mx(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)(Ab,{label:`Entry category`,value:e,options:lV.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`})]}),o.error===null?null:(0,h.jsx)(R4,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(L4,{label:`Intros and outros`}):null:S.length===0?(0,h.jsx)(Jpe,{category:e}):(0,h.jsx)(jq,{className:F4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${e}s match "${s.trim()}".`}):(0,h.jsx)(pU,{label:`${dV(e)}s`,children:w.map(e=>(0,h.jsx)(mU,{className:I4,title:(0,h.jsx)(J4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:qpe(e),selected:e.id===T?.id,actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/entries/new`,search:{category:e.category,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(M4,{item:`entry`,id:T.id,name:T.name,kicker:`${dV(T.category)} · ${fV(T.mode)}`,meta:`Updated ${P4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(fS,{to:`/entries/$entryId`,params:{entryId:T.id},size:`small`,children:`Edit ${T.category}`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(O4,{item:`entry`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(jy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${p?.category??e}`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function qpe(e){return`${fV(e.mode)} · ${N4(e.slots.length,`keyword`)} · updated ${P4(e.updatedAt)}`}function Jpe({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(a0,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function Ype({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:L(`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 Y4({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)(H,{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)(Ype,{name:e,className:`px-2 py-1`},e))}):t.trim()===``?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Slots appear here as you type {{name}}.`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i}),n.length===0?null:(0,h.jsxs)(`div`,{id:r,className:`flex flex-col gap-2 border-t border-line pt-3`,children:[(0,h.jsx)(`span`,{className:`sl-kicker text-danger`,children:n.length===1?`1 slot error`:`${String(n.length)} slot errors`}),n.map(e=>(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message},e.message))]})]})}function X4({className:e,...t}){return(0,h.jsx)(Wv,{"data-slot":`label`,className:L(`engraved block select-none text-ink-3`,e),...t})}function Z4({className:e,...t}){return(0,h.jsx)(Zee,{"data-slot":`toggle-group`,className:L(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function Q4({className:e,...t}){return(0,h.jsx)(nte,{"data-slot":`toggle-group-item`,className:L(`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 $4({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{id:o,children:e}),i===void 0?null:(0,h.jsx)(V,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(Z4,{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)(Q4,{value:e.value,children:e.label},e.value))})]})}function Xpe(e){return e3(e.name,e.body)}function Zpe(e){return e3(e.name,e.body)}function e3(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(wM)} characters or fewer.`}),n;for(let e of dq(t).errors)n.push({field:`body`,message:Qpe(e,t)});return n}function Qpe(e,t){let n=$pe(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 $pe(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
274
+ `))}}),u]});case`link`:{let t=a;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),s]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(CV,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{c({...t,text:e.target.value})}}),(0,h.jsx)(CV,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{c({...t,url:e.target.value===``?null:e.target.value})}})]}),u]})}}}function y4({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ob,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 b4({children:e}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/document-themes`,children:`Back to Documents`}),children:e})}var Ppe=4e3;function x4(e){return e.match(/\s+|[^\s]+/gu)??[]}function Fpe(e,t){let n=x4(e),r=x4(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=[];C4(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 Lpe(s,c))C4(o,e.op,e.text);return C4(o,`same`,n.slice(n.length-a).join(``)),o}function S4(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function Ipe(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+x4(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function C4(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 Lpe(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,Ppe),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())C4(f,e.op,e.text);return f}function w4({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>Fpe(e,t),[e,t]),a=Ipe(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)(T4,{label:n,parts:S4(i,`before`)}),(0,h.jsx)(T4,{label:r,parts:S4(i,`after`)})]})]})}function T4({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:Rpe(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 Rpe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var E4={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function D4(e,t){let{api:n}=z();return N({queryKey:E4.versions(e,t),queryFn:()=>ks(n,e,t)})}function zpe(e,t){let{api:n}=z();return N({queryKey:E4.usedBy(e,t),queryFn:()=>As(n,e,t)})}function O4({item:e,id:t,name:n,onClose:r}){let{api:i}=z(),a=_(),o=D4(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=P({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:E4.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?B.prompts:B.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)(YP,{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)(H,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(TV,{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:A4(e,b)},e.version))})}),(0,h.jsx)(xV,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(TV,{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:A4(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)(w4,{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)(H,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(pU,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(mU,{title:`Version ${String(e.version)}`,meta:k4(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(R,{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)(Q1,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function k4(e){return`${e.author} · ${j4(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function A4(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${j4(e.createdAt)}`}function j4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function M4({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)(H,{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)(EV,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(Bpe,{item:e,id:t}),(0,h.jsx)(Vpe,{item:e,id:t,name:n,onOpenHistory:c})]})}function Bpe({item:e,id:t}){let n=zpe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:Hpe(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)(pU,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(mU,{title:(0,h.jsx)(ha,{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)(mU,{title:(0,h.jsx)(ha,{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 Vpe({item:e,id:t,name:n,onOpenHistory:r}){let i=D4(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:`${N4(a.length,`version`)} · latest ${k4(o)}`},children:(0,h.jsx)(R,{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)(w4,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function Hpe(e){return[N4(e.templates.length,`template`),N4(e.schedules.length,`schedule`),N4(e.projects.length,`project`)].join(`, `)}function N4(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function P4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}var F4=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,I4=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function L4({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 R4({what:e,message:t,onRetry:n}){return(0,h.jsx)(SI,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(R,{size:`small`,onClick:n,children:`Try again`}),children:t})}function z4({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:L(`flex flex-wrap items-center gap-0.5`,o),children:[t,n,r===void 0?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Use ${e} in Play`,title:r.blocked,disabled:r.run===void 0||r.blocked!==void 0,onClick:r.run,children:`Use in Play`}),i===void 0?null:(0,h.jsx)(wy,{size:`small`,label:`History of ${e}`,onClick:i,children:(0,h.jsx)(Fc,{"aria-hidden":`true`})}),(0,h.jsx)(wy,{size:`small`,label:`Delete ${e}`,onClick:a,children:(0,h.jsx)(Bc,{"aria-hidden":`true`})})]})}var Upe=[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & Outros`},{to:`/templates`,label:`Templates`},{to:`/document-themes`,label:`Documents`},{to:`/narration-aliases`,label:`Aliases`}];function Wpe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Library`,meta:`Prompts, intros and outros, templates, document themes and narration aliases`}),(0,h.jsx)(xde,{items:Upe,label:`Library sections`,className:`mb-6`}),(0,h.jsx)(Gpe,{}),(0,h.jsx)(ja,{})]})}function Gpe(){let e=Zi(),t=Va({select:e=>e.location}),n=t.search,r=vV(t.pathname===`/prompts`?n.kind:void 0),i=hV(t.pathname===`/entries`?n.category:void 0);return bx({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),bx({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),bx({id:`library.new-document-theme`,title:`New document theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),bx({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),bx({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),bx({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),bx({id:`library.open-document-themes`,title:`Open document themes`,group:`Library`,keywords:[`pdf`,`documents`],run:()=>{e({to:`/document-themes`})}}),null}function B4({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:L(`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)(Ey,{className:`ml-auto shrink-0`,children:t})]})}function Kpe(){let{api:e}=z(),t=_(),n=N(ib(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(void 0),s=P({mutationFn:t=>Is(e,t),onSettled:async()=>{o(void 0),await t.invalidateQueries({queryKey:B.documentThemes})}}),c=n.data,l=r!==void 0&&`saved`in r?c?.themes.find(e=>e.id===r.saved):void 0,u=r!==void 0&&`builtIn`in r?c?.builtIns.find(e=>e.name===r.builtIn):void 0,d=l===void 0&&u===void 0?c?.themes[0]:void 0,f=l??d,p=f===void 0?u??c?.builtIns[0]:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B4,{action:(0,h.jsx)(fS,{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)(R4,{what:`document themes`,message:n.error.message,onRetry:()=>void n.refetch()}),c===void 0?n.error===null?(0,h.jsx)(L4,{label:`Document themes`}):null:(0,h.jsx)(jq,{className:F4,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)(H,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`}),c.themes.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No themes of your own yet. Copy a built-in below to start one.`}):(0,h.jsx)(pU,{label:`Your themes`,children:c.themes.map(e=>(0,h.jsx)(mU,{className:I4,lead:(0,h.jsx)(K4,{colors:e.values.colors}),title:e.name,meta:`${V4(e.values)} · updated ${P4(e.updatedAt)}`,selected:e.id===f?.id,onSelect:()=>i({saved:e.id}),actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>o(e)})},e.id))})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(pU,{label:`Built-in themes`,children:c.builtIns.map(e=>(0,h.jsx)(mU,{className:I4,lead:(0,h.jsx)(K4,{colors:e.values.colors}),title:e.label,meta:V4(e.values),selected:e.name===p?.name,onSelect:()=>i({builtIn:e.name}),actions:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:f===void 0?p===void 0?null:(0,h.jsx)(W4,{name:p.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:p.values,action:(0,h.jsx)(fS,{to:`/document-themes/new`,search:{from:p.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(W4,{name:f.name,kicker:`Your theme`,meta:`Updated ${P4(f.updatedAt)}`,values:f.values,action:(0,h.jsx)(fS,{to:`/document-themes/$themeId`,params:{themeId:f.id},size:`small`,children:`Edit theme`})})}),s.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:s.error.message}),(0,h.jsx)(jy,{open:a!==void 0,title:`Delete "${a?.name??``}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:s.isPending,onConfirm:()=>{a!==void 0&&s.mutate(a.id)},onCancel:()=>o(void 0)})]})}function V4(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${H4(e.fonts.body.family)} body`}function H4(e){return l4.find(t=>t.value===e)?.label??e}function U4(e){return e.startsWith(`#`)?e:`#${e}`}function W4({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)(H,{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)(G4,{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:U4(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:U4(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(G4,{label:`${e} font`,children:`${H4(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(G4,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${U4(r.background.color)}`} background`})]})]})}function G4({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 K4({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:U4(e)}},t))})}function q4(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 J4({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Oy(),[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`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(CV,{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)(R,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(R,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(V,{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)(hU,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(wy,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function qpe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=z(),a=_(),o=N(rb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=xx(l,`intros and outros`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=P({mutationFn:e=>Vs(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:B.entries})}}),x=async(e,t)=>{let n=await Ns(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:B.entries}),n.ok?null:q4(n.fields)},S=o.data?.entries.filter(t=>t.category===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B4,{action:(0,h.jsx)(fS,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`}),children:[(0,h.jsx)(CV,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":Mx(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)(Ab,{label:`Entry category`,value:e,options:lV.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`})]}),o.error===null?null:(0,h.jsx)(R4,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(L4,{label:`Intros and outros`}):null:S.length===0?(0,h.jsx)(Ype,{category:e}):(0,h.jsx)(jq,{className:F4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${e}s match "${s.trim()}".`}):(0,h.jsx)(pU,{label:`${dV(e)}s`,children:w.map(e=>(0,h.jsx)(mU,{className:I4,title:(0,h.jsx)(J4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:Jpe(e),selected:e.id===T?.id,actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/entries/new`,search:{category:e.category,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(M4,{item:`entry`,id:T.id,name:T.name,kicker:`${dV(T.category)} · ${fV(T.mode)}`,meta:`Updated ${P4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(fS,{to:`/entries/$entryId`,params:{entryId:T.id},size:`small`,children:`Edit ${T.category}`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(O4,{item:`entry`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(jy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${p?.category??e}`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function Jpe(e){return`${fV(e.mode)} · ${N4(e.slots.length,`keyword`)} · updated ${P4(e.updatedAt)}`}function Ype({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(a0,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function Xpe({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:L(`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 Y4({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)(H,{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)(Xpe,{name:e,className:`px-2 py-1`},e))}):t.trim()===``?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Slots appear here as you type {{name}}.`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i}),n.length===0?null:(0,h.jsxs)(`div`,{id:r,className:`flex flex-col gap-2 border-t border-line pt-3`,children:[(0,h.jsx)(`span`,{className:`sl-kicker text-danger`,children:n.length===1?`1 slot error`:`${String(n.length)} slot errors`}),n.map(e=>(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message},e.message))]})]})}function X4({className:e,...t}){return(0,h.jsx)(Wv,{"data-slot":`label`,className:L(`engraved block select-none text-ink-3`,e),...t})}function Z4({className:e,...t}){return(0,h.jsx)(Zee,{"data-slot":`toggle-group`,className:L(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function Q4({className:e,...t}){return(0,h.jsx)(nte,{"data-slot":`toggle-group-item`,className:L(`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 $4({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{id:o,children:e}),i===void 0?null:(0,h.jsx)(V,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(Z4,{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)(Q4,{value:e.value,children:e.label},e.value))})]})}function Zpe(e){return e3(e.name,e.body)}function Qpe(e){return e3(e.name,e.body)}function e3(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(wM)} characters or fewer.`}),n;for(let e of dq(t).errors)n.push({field:`body`,message:$pe(e,t)});return n}function $pe(e,t){let n=eme(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 eme(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
275
275
  `),i=n.split(`
276
- `).length,a=t-r;return`line ${String(i)}, column ${String(a)}`}function t3(e,t){return[...`kind`in e?Xpe(e):Zpe(e),...t]}function n3(e){return e[0]?.message}function r3(e){return e.filter(e=>e.field===`body`)}function i3(e){return e.filter(e=>e.field===`name`)}function a3(e){return dq(e).names}function eme(e){let t=[],n=0;for(let r of dq(e).errors){if(r.at<n)continue;r.at>n&&t.push({start:n,text:e.slice(n,r.at),marked:!1});let i=Math.min(r.at+2,e.length);t.push({start:r.at,text:e.slice(r.at,i),marked:!0}),n=i}return n<e.length&&t.push({start:n,text:e.slice(n),marked:!1}),t}var o3=`px-3 py-3 font-sans text-body leading-[1.5] break-words [scrollbar-gutter:stable]`;function s3({id:e,value:t,invalid:n,describedBy:r,onChange:i}){let a=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:`relative max-w-[75ch]`,children:[(0,h.jsxs)(`div`,{ref:a,"aria-hidden":`true`,"data-slot":`lint-overlay`,className:L(o3,`pointer-events-none absolute inset-0 overflow-hidden whitespace-pre-wrap`,`rounded-control border border-transparent bg-sunken text-ink`),children:[eme(t).map(e=>(0,h.jsx)(`span`,{"data-lint-mark":e.marked?e.start:void 0,className:e.marked?`text-danger underline decoration-danger decoration-2 underline-offset-[3px]`:void 0,children:e.text},e.start)),`
277
- `]}),(0,h.jsx)(wV,{id:e,rows:24,value:t,spellCheck:!1,"aria-invalid":n,"aria-describedby":r,className:L(o3,`relative block min-h-[520px] resize-y border-line-strong overflow-auto bg-transparent text-transparent caret-ink`),onChange:e=>{i(e.target.value)},onScroll:e=>{let t=a.current;t!==null&&(t.scrollTop=e.currentTarget.scrollTop,t.scrollLeft=e.currentTarget.scrollLeft)}})]})}function c3({entryId:e,category:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=N(rb(i)),s=(0,m.useId)(),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),S=o.data?.entries,C=e??n,w=C===void 0?void 0:S?.find(e=>e.id===C),T=w===void 0?{category:t,mode:`text`,name:``,body:``}:{category:w.category,mode:w.mode,name:e===void 0?`${w.name} copy`:w.name,body:w.body},E=d??T,D=P({mutationFn:t=>Ns(i,t,e),onSuccess:async e=>{if(!e.ok){g(e.fields);return}y(!0),await a.invalidateQueries({queryKey:rb(i).queryKey})}}),O=P({mutationFn:e=>Vs(i,e),onSuccess:async()=>{x(!1),await a.invalidateQueries({queryKey:rb(i).queryKey}),r(E.category)}});X2(v,()=>{r(E.category)});let k=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},A=t3(E,p),ee=n3(A),te=a3(E.body),ne=E.body.trim()===``?[]:r3(A),j=E.name.trim()===``?[]:i3(A);return o.error===null?C!==void 0&&S===void 0?(0,h.jsx)($2,{}):C!==void 0&&w===void 0?(0,h.jsx)(l3,{category:t,children:`That entry is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/entries`,search:{category:E.category},children:`Intros & Outros`})}),title:e===void 0?`New entry`:`Edit entry`,meta:dV(E.category)}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{className:`min-w-[200px] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.entry.name`,...j.length===0?{}:{error:j.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:E.name,onChange:e=>{k({...E,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Category`,value:E.category,options:lV,tip:`library.entry.category`,onPick:e=>{k({...E,category:e},`name`)}}),(0,h.jsx)($4,{label:`Mode`,value:E.mode,options:uV,describedBy:s,tip:`library.entry.mode`,onPick:e=>{k({...E,mode:e},`mode`)}})]}),(0,h.jsx)(`p`,{id:s,className:`-mt-2 text-right text-small text-ink-2`,children:pV(E.mode)}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:`library.entry.body`,label:`Body`,className:`-my-1`})]}),(0,h.jsx)(s3,{id:c,value:E.body,invalid:ne.length>0,describedBy:ne.length===0?void 0:l,onChange:e=>{k({...E,body:e},`body`)}})]}),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{x(!0)},blocked:ee,blockedId:u,pending:D.isPending,saved:v,cancel:(0,h.jsx)(fS,{to:`/entries`,search:{category:E.category},variant:`secondary`,children:`Cancel`}),errors:[D.error,O.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{D.mutate(E)}})]}),(0,h.jsx)(`div`,{className:m4,children:(0,h.jsx)(Y4,{slots:te,body:E.body,lint:ne,lintId:l,noSlots:mV(E.mode)})})]}),(0,h.jsx)(jy,{open:b,title:`Delete "${E.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${E.category}`,pending:O.isPending,onConfirm:()=>{e!==void 0&&O.mutate(e)},onCancel:()=>{x(!1)}})]}):(0,h.jsx)(l3,{category:E.category,children:o.error.message})}function l3({category:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/entries`,search:{category:e},children:`Back to Intros & Outros`}),children:t})}var tme=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),nme=new Intl.DateTimeFormat(void 0,{timeStyle:`short`});function rme({runs:e}){return(0,h.jsx)(pU,{label:`Coming up`,children:e.map(e=>(0,h.jsx)(mU,{title:`${tme.format(new Date(e.at))} · ${nme.format(new Date(e.at))} · ${uU(e)}`,meta:[e.scheduleName,e.templateName].filter(e=>e!==null).join(` · `),actions:e.paused?(0,h.jsx)(vS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(vS,{tone:`info`,children:`Needs a topic`}):(0,h.jsx)(vS,{children:`Queued`})},`${e.scheduleId}-${e.at}`))})}var u3=q({revisionId:W(),checkpoints:K(Zj.unwrap().extend({currentFingerprint:W().regex(/^[a-f0-9]{64}$/),dependents:K(J(FS)),workKeys:K(W())}))}),ime=q({revisionId:W().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),stages:K(Xj).max(3).refine(e=>new Set(e).size===e.length).readonly()}).strict(),ame=q({title:W(),status:G(),detail:W().optional(),reason:J([`duplicate`,`not-found`,`conflict`,`invalid-input`]).optional()}),ome=Qj.unwrap().omit({projectId:!0,checkpointId:!0,approvedAt:!0}),d3=e=>[`checkpoints`,e],f3=(e,t)=>[...d3(e),t];async function p3(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=ame.safeParse(n);if(!r.success)throw po(e,void 0);if(![400,404,409].includes(e.status))throw Error(r.data.detail??r.data.title);return{ok:!1,reason:r.data.reason??`invalid-input`,message:r.data.detail??r.data.title}}async function m3(e,t){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`),u3)}async function h3(e,t,n,r){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints/${encodeURIComponent(n)}/approve`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(ome.parse(r))}),q({checkpoint:Zj,replayed:GD()}))}async function sme(e,t,n){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(ime.parse(n))}),u3)}var g3=(0,m.createContext)(void 0);function _3(e,t){if(e.state===`failed`)return V1({stage:e.kind,kind:e.failureKind,reason:e.failureReason,provider:ade(t.config,e.kind)})}function v3({projectId:e,className:t}){let{api:n}=z(),[r,i]=(0,m.useState)(!1);return(0,h.jsx)(`div`,{className:L(`sl-media__frame`,t),"aria-hidden":`true`,children:r?(0,h.jsx)(`div`,{className:`flex size-full items-center justify-center bg-sunken text-ink-3`,children:(0,h.jsx)(bc,{strokeWidth:1.75,className:`size-6`})}):(0,h.jsx)(`img`,{src:Ko(n,e,`thumbnail`),alt:``,loading:`lazy`,decoding:`async`,onError:()=>i(!0)})})}function y3(e){return e.status===`pending`&&e.progress>0}function b3({lead:e,status:t,title:n,detail:r,action:i}){return(0,h.jsxs)(`li`,{className:L(`sl-home-item`,dU),children:[e,(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[t,(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:n}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:r})]}),(0,h.jsx)(Ey,{className:`sl-home-item__action`,children:i})]})}function x3(e){return(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}var cme={audio:`Approve the article and record`,images:`Approve and draw the images`,video:`Approve and render`},lme={audio:`review before the narration`,images:`review before the images`,video:`review before the video`};function ume({project:e,primary:t}){let{api:n}=z(),r=_(),i=Oy(),a=Zi(),o=(0,m.useRef)(null),s=N({queryKey:d3(e.id),queryFn:async()=>{let t=await m3(n,e.id);if(!t.ok)throw Error(t.message);return t.value}}).data?.checkpoints.find(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint),c=P({mutationFn:async t=>{o.current??={revisionId:t.revisionId,fingerprint:t.fingerprint,idempotencyKey:crypto.randomUUID()};let r=await h3(n,e.id,t.checkpointId,o.current);return o.current=null,r},onSuccess:t=>{i(t.ok?`Approved: ${e.title}. The run continues.`:`${e.title} wasn't approved: ${t.message} Open the project to review it there.`,t.ok?`success`:`error`)},onError:t=>{i(`Slopify didn't confirm the approval of ${e.title}: ${t.message} Press the button again to check whether it went through.`,`error`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:d3(e.id)}),r.invalidateQueries({queryKey:B.projects})])}}),l=s===void 0?void 0:cme[s.stage];return bx({id:`home.approve.${e.id}`,title:l??`Open the held run`,group:`Needs you`,context:e.title,keywords:[`approve`,`review`,`waiting`],run:()=>{s===void 0?a({to:`/projects/$projectId`,params:{projectId:e.id}}):c.mutate(s)}}),(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:s===void 0?`Waiting for you`:`Waiting for you · ${lme[s.stage]}`}),title:x3(e),detail:s===void 0?`Its next step is held. Open the project to review it and continue the run.`:`Everything before this step is done. Approve to let the run go on, or open the project to look first.`,action:s===void 0||l===void 0?(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`}):(0,h.jsx)(R,{variant:t?`primary`:`secondary`,disabled:c.isPending,disabledReason:`Approving…`,onClick:()=>c.mutate(s),children:c.isPending?`Approving…`:l})})}function dme({schedule:e,primary:t}){let n=e.topics.held;return(0,h.jsx)(b3,{lead:(0,h.jsx)(`div`,{className:`sl-media__frame flex items-center justify-center bg-sunken text-info`,children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-7`})}),status:(0,h.jsx)(_S,{tone:`info`,children:`${String(n)} new ${n===1?`topic`:`topics`}`}),title:e.name,detail:`Slopify suggested ${n===1?`a topic`:`${String(n)} topics`} for this schedule. Queue the ones you want and reject the rest.`,action:(0,h.jsx)(fS,{to:`/calendar`,variant:t?`primary`:`secondary`,className:fU,children:`Review topics`})})}function fme({project:e,primary:t}){return(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}),title:x3(e),detail:`You paused this run. Nothing more happens until you open it and press Continue the run.`,action:(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`})})}function pme({project:e,primary:t}){let{api:n}=z(),r=N({queryKey:B.project(e.id),queryFn:()=>jo(n,e.id)}),i=r.data?.stages.find(e=>e.state===`failed`),a=Oy(),o=async e=>{let t=await q1(e);a(t?`Copied ${e}. Run it in a terminal on the computer running Slopify and sign in, then open the project and press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e} in a terminal, sign in, then open the project and press Check again.`,t?`success`:`error`)},s=i===void 0||r.data===void 0?void 0:_3(i,r.data.project),c=BP(i?.failureReason)??`The run stopped with an error.`,l=i===void 0?``:` · ${nF[i.kind]}`,u=t?`primary`:`secondary`,d=s?.kind===`provider-settings`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},variant:u,children:s.label}):s?.kind===`free-space`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`storage`},variant:u,children:s.label}):s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:u,onClick:()=>void o(s.command),children:`Copy sign-in command`}),(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},children:`Open to retry`})]}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:u,children:s?.label??`Open to retry`});return(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`failed`,children:`Failed${l}`}),title:x3(e),detail:s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[c,` Run `,(0,h.jsx)(`code`,{className:`sl-code`,children:s.command}),` in a terminal to sign in, then press Check again on the project to retry the step.`]}):c,action:d})}var mme=[`home`,`week`];function hme(e=new Date){let t=new Date(e);t.setHours(0,0,0,0);let n=(t.getDay()+6)%7;return t.setDate(t.getDate()-n),t}function gme(e,t,n){return ct({queryKey:[...mme,t,n],queryFn:async()=>{let r=new URLSearchParams({since:t});return n!==null&&r.set(`channelId`,n),F(await e.fetch(`${e.origin}/api/home/week?${r.toString()}`))},staleTime:3e4})}async function S3(e,t,n){return F(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/uploaded`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({uploaded:n})}))}function C3(e){return(e.status===`done`||e.status===`partial`)&&e.config.sources.video!==`off`&&e.uploadedAt===null}function _me({project:e}){let{api:t}=z(),n=_(),r=Oy(),i=P({mutationFn:n=>S3(t,e.id,n),onSuccess:(t,n)=>{r(n?`Marked uploaded: ${e.title}. It is off Ready to upload; Projects still lists it.`:`${e.title} is back on Ready to upload.`,`success`)},onError:t=>{r(`${e.title} wasn't marked uploaded: ${t.message} Press Mark uploaded again.`,`error`)},onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});return bx({id:`home.uploaded.${e.id}`,title:`Mark uploaded`,group:`Ready to upload`,context:e.title,keywords:[`youtube`,`published`,`done`],run:()=>i.mutate(!0)}),(0,h.jsxs)(`li`,{className:`sl-home-ready ${dU}`,children:[(0,h.jsx)(v3,{projectId:e.id}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:`${e.format} · finished ${ku(e.updatedAt)}${e.status===`partial`?` · a step failed`:``}`}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(h2,{projectId:e.id,ready:!0,size:`small`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i.isPending,disabledReason:`Saving…`,onClick:()=>i.mutate(!0),children:`Mark uploaded`})]})]})]})}function w3(e){return e.status===`pending`&&e.progress===0}var vme=2;function yme({running:e,queued:t}){let n=e>3;if(!n&&t.length===0)return null;let r=t.slice(0,vme).map(e=>e.title.trim()||`Untitled project`),i=t.length-r.length;return(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n?(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/projects`,search:{show:`running`},children:`See all ${String(e)} running`})}):null,t.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-ink`,children:`Queued, waiting to start (${String(t.length)}): `}),r.join(`, `),i>0?` and ${String(i)} more`:``]}),(0,h.jsx)(pS,{to:`/projects`,search:{show:`queued`},children:`See queued`})]})]})}function T3(e,t){if(e.state!==`running`)return;let n=e.startedAt===null?NaN:Date.parse(e.startedAt),r=Number.isFinite(n)?Math.max(0,(t-n)/1e3):void 0,i=e.progressCurrent??0,a=e.progressTotal??0;if(r!==void 0&&a>0&&i>0)return i>=a?{basis:`progress`,seconds:0}:{basis:`progress`,seconds:Math.round(r/i*(a-i))};let o=e.typicalSeconds;if(o===void 0||!Number.isFinite(o)||o<=0)return{basis:`unknown`};let s=o-(r??0);return s>0?{basis:`history`,seconds:Math.round(s)}:{basis:`overdue`}}function E3(e){if(e.basis===`unknown`)return`time left unknown`;if(e.basis===`overdue`)return`taking longer than usual`;let t=e.seconds??0;if(t<=0)return`finishing up`;if(t<60)return`under a minute left`;let n=Math.round(t/60);if(n<60)return`about ${String(n)} min left`;let r=Math.floor(n/60),i=n%60;return i===0?`about ${String(r)} h left`:`about ${String(r)} h ${String(i)} min left`}function D3(e){let t=e.role.replaceAll(`_`,`-`);return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment!==void 0?`${t}-${e.meta.segment}`:e.role===`short_video`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}`:e.role===`short_image`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}-${String(e.meta.index??1)}`:e.role===`thumbnail`&&e.meta.index!==void 0&&e.meta.index>1?`${t}-${String(e.meta.index)}`:e.role===`instructions`?`${e.stageKind}-${t}`:(e.role===`image`||e.role===`animated_image`)&&e.meta.index!==void 0?`${t}-${String(e.meta.index)}`:t}function O3({steps:e,label:t,dense:n=!1,className:r}){return(0,h.jsx)(`ol`,{"aria-label":t,className:L(`sl-steps m-0 list-none p-0`,n&&`sl-steps--dense`,r),children:e.map(e=>(0,h.jsxs)(`li`,{className:`sl-step`,"data-tone":e.tone,children:[(0,h.jsx)(gS,{tone:e.tone}),(0,h.jsxs)(`span`,{className:`sl-step__name`,children:[e.name,(0,h.jsx)(`span`,{className:`sr-only`,children:`, ${e.state}`})]}),(0,h.jsx)(`span`,{className:`sl-step__time`,children:e.time??`—`}),e.detail===void 0?null:(0,h.jsx)(`span`,{className:`sl-step__detail`,children:e.detail})]},e.id))})}function k3(e){let{api:t}=z();return N({...Xy(t,e),enabled:!1,select:e=>e.revisionId??null}).data??null}var A3=(e,t=null)=>[`live-writing`,e,t];function bme(e,t){let n=e=>e.callId===t.callId&&e.revisionId===t.revisionId&&e.workId===t.workId,r=e.find(n),i=(t.reset?t.text:`${r?.text??``}${t.text}`).slice(-65536),a={...t.revisionId===void 0?{}:{revisionId:t.revisionId},...t.workId===void 0?{}:{workId:t.workId},...t.workPieceId===void 0?{}:{workPieceId:t.workPieceId},stage:t.stage,callId:t.callId,...t.label===void 0?{}:{label:t.label},text:i};return(r?e.map(e=>n(e)?a:e):[...e,a]).slice(-24)}function j3({projectId:e,stage:t,className:n=`mx-5 mt-5`}){let r=(N({queryKey:A3(e,k3(e)),queryFn:()=>[],enabled:!1}).data??[]).filter(e=>e.stage===t),[i,a]=(0,m.useState)(),o=r.find(e=>e.callId===i)??r.at(-1),[s,c]=(0,m.useState)(!0),l=(0,m.useRef)(null);return(0,m.useEffect)(()=>{o?.text&&s&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},[s,o?.text]),r.length===0&&t!==`research`&&t!==`article`?null:(0,h.jsxs)(`div`,{className:L(`border-y border-line`,n),children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-line py-3`,...Ob,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-accent-ink`,children:`Live writing`}),(0,h.jsx)(V,{id:`project.live.writing`})]}),r.length>1?(0,h.jsx)(TV,{"aria-label":`Live writing task`,value:o?.callId??``,onChange:e=>a(e.target.value),className:`max-w-[280px]`,children:r.map((e,t)=>(0,h.jsxs)(`option`,{value:e.callId,children:[e.label??`Writing`,` · `,t+1]},e.callId))}):null,(0,h.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Follow output`]})]}),(0,h.jsx)(`section`,{ref:l,"aria-label":`Live writing preview`,tabIndex:0,className:`max-h-[360px] min-h-32 overflow-auto whitespace-pre-wrap break-words py-4 font-sans text-small leading-relaxed text-ink-2`,children:o?.text||`Waiting for the provider's first text…`}),(0,h.jsx)(`p`,{className:`border-t border-line py-2 text-label text-ink-3`,children:`Live preview. The complete output is saved when this stage finishes.`})]})}var xme=q({id:W(),projectId:W(),revisionId:W(),itemKey:W(),stage:J(Ck),itemFingerprint:W(),reviewFingerprint:W(),passed:GD(),reasons:K(W()),outcome:J([`passed`,`flagged`,`redo`]),attempt:G(),action:J([`overruled`,`redone`]).nullable(),actionAt:W().nullable(),redoState:J([`pending`,`started`,`failed`]).nullable(),redoError:W().nullable(),createdAt:W(),current:GD(),outputId:W().nullable(),verdicts:G()}),M3=e=>[`reviews`,e],Sme=q({title:W(),detail:W().optional()});async function Cme(e,t){let n=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews`);if(!n.ok)throw po(n,void 0);return So(q({reviews:K(xme)}),await n.json()).reviews}async function wme(e,t,n,r,i){let a=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews/${encodeURIComponent(n)}/${r}`,{method:`POST`,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}});if(a.ok)return{ok:!0};let o;try{o=await a.json()}catch{throw po(a,void 0)}let s=Sme.safeParse(o);if(!s.success||![400,404,409,503].includes(a.status))throw po(a,void 0);return{ok:!1,message:s.data.detail??s.data.title}}var Tme=200;function N3(e,t=null){let{api:n,openEvents:r}=z(),i=_();(0,m.useEffect)(()=>{i.setQueryData(B.article(e,t),``),i.setQueryData(A3(e,t),[]);let a=()=>i.getQueryData(B.project(e))?.revisionId??null,o=kB(()=>{i.invalidateQueries({queryKey:B.project(e)}),i.invalidateQueries({queryKey:B.projects}),i.invalidateQueries({queryKey:d3(e)}),i.invalidateQueries({queryKey:M3(e)})},Tme),s=AS(r,Hs(n,`projects/${e}`),{refetch:o.ask,accept:e=>e.type===`project.updated`||e.type===`project.state`&&e.revisionId===void 0||(e.revisionId??null)===a()||(o.ask(),!1),previewWriting:t=>{i.setQueryData(A3(e,a()),e=>bme(e??[],t))},narrationPiece:()=>{i.invalidateQueries({queryKey:Py(e,a())})},appendArticle:t=>{i.setQueryData(B.article(e,a()),e=>`${e??``}${t}`)},patch:t=>{if(t.type===`stage.state`&&t.state===`running`&&(i.setQueryData(A3(e,a()),e=>(e??[]).filter(e=>e.stage!==t.stage||e.workId!==t.workId||e.revisionId!==t.revisionId)),t.stage===`article`&&i.setQueryData(B.article(e,a()),``)),t.type!==`project.state`&&t.workId!==void 0){o.ask();return}i.setQueryData(B.project(e),e=>DB(e,t))}});return()=>{s(),o.stop()}},[n,r,i,e,t])}var Eme={pending:`off`,running:`running`,done:`done`,provided:`done`,failed:`failed`,canceled:`off`,skipped:`off`},Dme={pending:`Not started`,running:`Running`,done:`Done`,provided:`Provided`,failed:`Failed`,canceled:`Canceled`,skipped:`Skipped`};function Ome(e,t,n){if(e===null)return;let r=(t===null?n:Date.parse(t))-Date.parse(e);if(!Number.isFinite(r)||r<0)return;let i=Math.round(r/1e3);if(i<60)return`${String(i)} s`;let a=Math.round(i/60);if(a<60)return`${String(a)} min`;let o=Math.floor(a/60);return`${String(o)} h ${String(a%60)} min`}function kme(e,t){let n=T3(e,t);if(n!==void 0)return`${e.progressTotal!==null&&e.progressTotal>0?`${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)} · `:``}${E3(n)}`}function Ame({project:e,now:t}){let{api:n}=z();N3(e.id);let[r,i]=(0,m.useState)(null),a=N(Xy(n,e.id)),o=(a.data?.stages??[]).filter(e=>e.source!==`off`&&e.state!==`skipped`),s=(a.data?.outputs??[]).filter(e=>e.role===`image`).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),c=o.find(e=>e.kind===`images`&&e.state===`running`),l=o.find(e=>e.state===`running`),u=YH(e.limitWaits),d=s.slice(c===void 0?-4:-3),f=o.map(n=>({id:n.kind,name:iF(n.kind,e.config),tone:Eme[n.state],state:Dme[n.state],time:Ome(n.startedAt,n.finishedAt,t),detail:kme(n,t)}));return(0,h.jsxs)(`li`,{className:`sl-home-run ${dU}`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),e.status===`paused`?(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}):u===void 0?(0,h.jsx)(_S,{tone:`running`,children:l===void 0?`Running`:`${iF(l.kind,e.config)}`}):(0,h.jsx)(_S,{tone:`waiting`,children:u})]}),d.length===0&&c===void 0?null:(0,h.jsxs)(B0,{list:!0,density:`compact`,label:`Images of ${e.title}`,children:[d.map((t,r)=>(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,onOpen:()=>i(r)})},t.id)),c===void 0?null:(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{alt:`The next image`,generating:`Drawing · ${String(s.length)} so far`})})]}),(0,h.jsx)(V0,{items:d.map(t=>({src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,...t.meta.prompt===void 0?{}:{caption:t.meta.prompt}})),index:r,onIndex:i,onClose:()=>i(null)}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Images ${String(c.progressCurrent??s.length)} of ${String(c.progressTotal??`?`)}`})]}),(0,h.jsx)(O3,{steps:f,label:`Steps of ${e.title}`})]})}var P3=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2});function jme(e){return`spent${e.apiEquivalent===null?``:` · ~${P3.format(e.apiEquivalent)} via API`}${e.unpriced===0?``:` · ${String(e.unpriced)} ${e.unpriced===1?`call`:`calls`} without a price`}`}function Mme({channelId:e}){let{api:t}=z(),n=N(gme(t,hme().toISOString(),e));if(n.error!==null)return(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`This week's numbers didn't load: ${n.error.message} Reload the page to try again.`});let r=n.data;return(0,h.jsxs)(G2,{className:`sl-home-stats`,children:[(0,h.jsx)(K2,{value:r===void 0?`—`:String(r.videos),label:`videos made`}),(0,h.jsx)(K2,{value:r===void 0?`—`:P3.format(r.cost),label:r===void 0?`spent`:jme(r)}),(r?.plans??[]).filter(e=>e.weeklyPercent!==null).map(e=>{let t=Math.round(e.weeklyPercent??0);return(0,h.jsx)(K2,{value:`${String(t)}%`,label:`weekly ${e.name} limit`,children:(0,h.jsx)(q2,{value:t/100,label:`Weekly ${e.name} limit`,valueText:`${String(t)}% of your weekly ${e.name} limit`,tone:t>=80?`waiting`:`accent`})},e.account)})]})}var Nme=864e5,Pme=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`}),F3=4,I3=!1,L3=!1;function Fme(){let{api:e}=z(),t=gx(),n=N(Yy(e)),r=N(EH(e)),i=N(Hq(e)),[a]=(0,m.useState)(()=>{let e=new Date;return e.setHours(0,0,0,0),{from:new Date().toISOString(),to:new Date(e.valueOf()+8*Nme).toISOString()}}),o=N(KH(e,a.from,a.to)),s=N({queryKey:My,queryFn:()=>Iy(e)}),c=Zi();(0,m.useEffect)(()=>{s.data?.show===!0&&!I3&&(I3=!0,c({to:`/welcome`}))},[s.data?.show,c]),(0,m.useEffect)(()=>{s.data?.settle===!0&&!L3&&(L3=!0,Ly(e).catch(()=>{L3=!1}))},[s.data?.settle,e]);let[l,u]=(0,m.useState)(()=>Date.now());(0,m.useEffect)(()=>{let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[]);let d=(0,m.useMemo)(()=>new Map((i.data??[]).map(e=>[e.id,e.channelId])),[i.data]),f=(n.data?.projects??[]).filter(e=>t.includes(e.channelId)),p=f.filter(e=>e.status===`running`),g=f.filter(w3),_=f.filter(e=>e.status===`paused`),v=f.filter(y3),y=f.filter(e=>e.status===`failed`),b=new Set(Object.values(s.data?.samples??{}).filter(e=>e!==null)),x=f.filter(e=>C3(e)&&!b.has(e.id)),S=(r.data??[]).filter(e=>e.deletedAt===null&&e.topicGeneration.mode===`hold`&&e.topics.held>0&&t.includes(d.get(e.templateId))),C=(o.data?.runs??[]).filter(e=>t.includes(d.get(e.templateId))),w=[...v.map(e=>({kind:`waiting`,project:e})),..._.map(e=>({kind:`paused`,project:e})),...S.map(e=>({kind:`held`,schedule:e})),...y.slice(0,F3).map(e=>({kind:`failed`,project:e}))],T=n.isPending;return(0,h.jsxs)(`div`,{"data-tour":`home`,children:[(0,h.jsx)(kq,{display:!0,crumb:Pme.format(new Date),title:t.channel?.name??`Home`,meta:t.channelId===null?`Every channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(fS,{to:`/play`,variant:`secondary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]}),(0,h.jsxs)(fS,{to:`/calendar`,variant:`quiet`,children:[(0,h.jsx)(sc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open calendar`]})]})}),(0,h.jsxs)(`div`,{className:`mb-5 flex items-end gap-1 md:hidden`,...Ob,children:[(0,h.jsx)(_x,{className:`min-w-0 flex-1`}),(0,h.jsx)(V,{id:`home.channel`,className:`mb-1`})]}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-5 text-danger`,children:`Your projects didn't load: ${n.error.message} Check that Slopify is still running, then reload the page.`}),(0,h.jsxs)(e0,{split:`main-side`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(H,{title:`Needs you`,info:`home.needs-you`,meta:T?`Loading…`:w.length===0?`Nothing is waiting for a decision`:`${String(w.length)} ${w.length===1?`thing is`:`things are`} waiting for you`}),w.length===0?null:(0,h.jsx)(`ul`,{"aria-label":`Waiting for you`,className:`m-0 flex list-none flex-col gap-3 p-0`,children:w.map((e,t)=>e.kind===`waiting`?(0,h.jsx)(ume,{project:e.project,primary:t===0},e.project.id):e.kind===`paused`?(0,h.jsx)(fme,{project:e.project,primary:t===0},e.project.id):e.kind===`held`?(0,h.jsx)(dme,{schedule:e.schedule,primary:t===0},e.schedule.id):(0,h.jsx)(pme,{project:e.project,primary:t===0},e.project.id))})]}),(0,h.jsxs)(`section`,{id:`running`,"aria-label":`Running now`,children:[(0,h.jsx)(H,{title:`Running now`,info:`home.running`,meta:p.length===0?`Nothing is running`:`${String(p.length)} ${p.length===1?`video`:`videos`}`}),p.length===0?T||g.length>0?null:(0,h.jsx)(a0,{title:`Start the next video`,children:`Pick a template and a topic on Play, or let a schedule start one.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:p.slice(0,3).map(e=>(0,h.jsx)(Ame,{project:e,now:l},e.id))}),(0,h.jsx)(yme,{running:p.length,queued:g})]})]}),(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Coming up`,children:[(0,h.jsx)(H,{title:`Coming up`,info:`home.coming-up`,meta:`Next 7 days`,children:(0,h.jsx)(pS,{to:`/calendar`,children:`Calendar`})}),o.error===null?C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading…`:`No scheduled runs this week. Plan some on the calendar.`}):(0,h.jsx)(rme,{runs:C.slice(0,6)}):(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The calendar didn't load: ${o.error.message} Reload the page to try again.`})]}),(0,h.jsxs)(`section`,{"aria-label":`Ready to upload`,children:[(0,h.jsx)(H,{title:`Ready to upload`,info:`home.ready`,meta:x.length===0?`Finished videos you haven't marked uploaded show here`:`${String(x.length)} finished and not marked uploaded`}),x.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:x.slice(0,F3).map(e=>(0,h.jsx)(_me,{project:e},e.id))})]}),(0,h.jsxs)(`section`,{"aria-label":`This week`,children:[(0,h.jsx)(H,{title:`This week`,info:`home.this-week`,meta:`Since Monday`}),(0,h.jsx)(Mme,{channelId:t.channelId})]})]})]})]})}function R3({className:e,...t}){return(0,h.jsx)(`input`,{"data-slot":`input`,className:L(`h-8 w-full min-w-0 rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,`placeholder:text-ink-3 aria-invalid:border-danger`,e),...t})}var Ime={written:``,spoken:``,wholeWord:!0,caseSensitive:!1};function Lme(){let{api:e}=z(),t=_(),n=N(ab(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)({}),[s,c]=(0,m.useState)(),l=(0,m.useRef)(0),u=(0,m.useId)(),d=e=>e.map(e=>(l.current+=1,{...e,key:l.current}));(0,m.useEffect)(()=>{r===void 0&&n.data!==void 0&&i(d(n.data.aliases))});let f=r??[],p=P({mutationFn:t=>Bs(e,t),onSuccess:async e=>{if(!e.ok){let t={};for(let n of e.fields){let e=/^aliases\.(\d+)/u.exec(n.field)?.[1];e!==void 0&&(t[Number(e)]=n.message)}o(t),c({text:`Not saved: ${e.fields.map(e=>e.message).join(` `)}`,tone:`error`});return}o({}),i(d(e.value.aliases)),c({text:`Saved. New projects use these aliases; a project you already started keeps its copy until you refresh it in Edit project.`,tone:`success`}),await t.invalidateQueries({queryKey:B.narrationAliases})},onError:e=>c({text:`Couldn't save the aliases: ${e.message}`,tone:`error`})});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B4,{action:(0,h.jsxs)(R,{type:`button`,onClick:()=>{l.current+=1,i([...f,{...Ime,key:l.current}]),c(void 0)},disabled:r===void 0,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add alias`]}),children:(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Words the narrator says differently, like Dr. as Doctor.`,(0,h.jsx)(V,{id:`library.aliases`})]})}),n.error===null?null:(0,h.jsxs)(SI,{tone:`danger`,title:`Couldn't load the aliases`,className:`mb-6`,children:[n.error.message,` Reload the page to try again.`]}),(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsx)(t0,{label:`Aliases`,children:r===void 0?null:f.length===0?(0,h.jsx)(a0,{title:`No aliases yet`,children:`Use Add alias to say a word differently from how it is written.`}):(0,h.jsx)(Rme,{rows:f,errors:a,idPrefix:u,update:(e,t)=>{i(f.map(n=>n.key===e?{...n,...t}:n)),c(void 0)},remove:e=>{i(f.filter(t=>t.key!==e)),o({}),c(void 0)}})}),(0,h.jsx)(t0,{as:`aside`,label:`How aliases are used`,children:(0,h.jsxs)(`section`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(H,{title:`How they are used`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`The narrator reads the alias instead of the written word. The article, the captions and the PDF keep the written word.`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`A project takes a copy of this list when it starts and uses it while Use narration aliases is on. A project you already started keeps its copy until you refresh it in Edit project.`}),(0,h.jsx)(`p`,{className:`m-0`,children:`Whole word skips matches inside longer words; Match case only matches the exact capitals.`})]})})]}),(0,h.jsx)($1,{status:(0,h.jsx)(Q1,{tone:s?.tone??`info`,children:s?.text}),children:(0,h.jsx)(R,{type:`button`,variant:`primary`,disabled:r===void 0||p.isPending,onClick:()=>p.mutate(f.map(({written:e,spoken:t,wholeWord:n,caseSensitive:r})=>({written:e,spoken:t,wholeWord:n,caseSensitive:r}))),children:p.isPending?`Saving…`:`Save aliases`})})]})}function Rme({rows:e,errors:t,idPrefix:n,update:r,remove:i}){return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-4 gap-y-1 pb-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Written`,(0,h.jsx)(V,{id:`library.aliases.written`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Say it as`,(0,h.jsx)(V,{id:`library.aliases.spoken`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Whole word`,(0,h.jsx)(V,{id:`library.aliases.whole-word`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Match case`,(0,h.jsx)(V,{id:`library.aliases.match-case`})]})]}),(0,h.jsx)(pU,{label:`Narration aliases`,children:e.map((e,a)=>{let o=`${n}-${e.key}`,s=t[a],c=e.written.trim(),l=e.spoken.trim();return(0,h.jsx)(mU,{title:`Alias ${String(a+1)}`,meta:c===``||l===``?`Not filled in yet`:`Says ${c} as ${l}${e.wholeWord?` · whole word`:``}${e.caseSensitive?` · match case`:``}`,actions:(0,h.jsx)(wy,{size:`small`,label:`Remove alias ${String(a+1)}`,onClick:()=>i(e.key),children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto_auto] md:items-end`,children:[(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-written`,children:[`Written`,(0,h.jsx)(R3,{id:`${o}-written`,value:e.written,placeholder:`Dr.`,maxLength:200,"aria-invalid":s!==void 0,"aria-describedby":s===void 0?void 0:`${o}-error`,onChange:t=>r(e.key,{written:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-spoken`,children:[`Say it as`,(0,h.jsx)(R3,{id:`${o}-spoken`,value:e.spoken,placeholder:`Doctor`,maxLength:500,"aria-invalid":s!==void 0,onChange:t=>r(e.key,{spoken:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.wholeWord,onChange:t=>r(e.key,{wholeWord:t.target.checked})}),`Whole word`]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.caseSensitive,onChange:t=>r(e.key,{caseSensitive:t.target.checked})}),`Match case`]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${o}-error`,className:`m-0 text-small text-danger md:col-span-4`,children:s})]})},e.key)})})]})}function z3(e){return dq(e).names}function zme(e,t){let n=z3(e),r=Object.create(null);for(let[e,i]of Object.entries(t))r[e]=n.includes(e)?``:i;return r}function Bme(e){return{...e,form:{...e.form,values:zme(e.form.title,e.form.values)},variants:[]}}function B3({onDefaults:e}){let{api:t}=z(),n=_(),r=N({queryKey:H1.firstRun,queryFn:()=>dde(t),retry:!1,staleTime:1/0}),i=r.data?.defaults;(0,m.useEffect)(()=>{i!==void 0&&(vN(i),e?.(i))},[i,e]);let a=P({mutationFn:()=>fde(t),onSuccess:()=>n.invalidateQueries({queryKey:H1.firstRun})}),o=r.data;if(o===void 0||!o.firstRun||o.message===null)return null;let s=o.detected.filter(e=>e.usable);return(0,h.jsxs)(SI,{title:o.message,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:a.isPending,onClick:()=>a.mutate(),children:`Got it`}),children:[o.detail===null?null:(0,h.jsx)(`p`,{className:`m-0`,children:o.detail}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0`,children:[`Found:`,` `,s.map(e=>`${e.displayName}${e.version===void 0?``:` ${e.version}`}`).join(`, `)]}),a.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:a.error.message}):null]})}function V3(){let{api:e}=z(),{document:t}=rP(),n=N(Hq(e)),r=t.templateSource,i=n.data?.find(e=>e.id===r?.id);return t.channelId??(i===void 0?`00000000-0000-4000-8000-000000000001`:o0(i))}function H3(){let{api:e}=z();return N(Qb(e,V3())).data?.cast??[]}function Vme({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),{document:i}=n,a=V3(),o=r.data?.find(e=>e.id===a),s=i.form.useBrandKit!==!1,c=e=>{n.edit(e),n.invalidateReview(!0)};return(0,h.jsxs)(`div`,{className:`sl-fields items-end`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,children:(0,h.jsxs)(TV,{"data-play-field":`channelId`,value:a,disabled:e,onChange:e=>c({...i,channelId:e.target.value}),children:[r.data===void 0?(0,h.jsx)(`option`,{value:a,children:`Loading channels…`}):null,(r.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsx)(kb,{label:`Use the channel's brand kit`,tip:`play.brand-kit`,checked:s,disabled:e,className:`min-h-[38px]`,onChange:e=>{let{useBrandKit:t,...n}=i.form;c({...i,form:e?n:{...n,useBrandKit:!1}})}}),o?(0,h.jsxs)(`p`,{className:`sl-fields__wide m-0 text-small text-ink-3`,children:[(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:o.id},className:`underline`,children:[`Edit `,o.name]}),s?``:` · its cast is still used`]}):null]})}function U3(){let{api:e}=z(),{document:t}=rP(),n=N(Zb(e)),r=V3(),i=n.data?.find(e=>e.id===r);return t.form.language??i?.brand.language??`en`}function Hme({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),i=V3(),a=r.data?.find(e=>e.id===i),{document:o}=n;return(0,h.jsx)(`div`,{children:(0,h.jsx)(k2,{value:o.form.language,inherited:{label:`Channel's language`,language:a?.brand.language},disabled:e,onChange:e=>{let{language:t,...r}=o.form;n.edit({...o,form:e===void 0?r:{...r,language:e}}),n.invalidateReview(!0)}})})}var W3=[{stage:`audio`,label:`Audio`},{stage:`images`,label:`Images`},{stage:`video`,label:`Video / export`}];function Ume(e,t){if(e===`reviews`||e.startsWith(`reviews.`))return{section:`review`,field:e};if(e!==`checkpoints`&&!e.startsWith(`checkpoints.`))return;let n=e.slice(12),r=/^\d+$/.test(n)?t.checkpoints?.[Number(n)]:n;return{section:`review`,field:W3.some(e=>e.stage===r)?`checkpoints.${r}`:`checkpoints`}}function Wme({problem:e}){let t=rP(),{document:n,review:r}=t,{form:i}=n,a=(0,m.useId)(),o=i.checkpoints??[];return(0,h.jsxs)(`fieldset`,{"data-play-field":`checkpoints`,tabIndex:-1,"aria-invalid":e(`checkpoints`)!==void 0,disabled:r.starting||r.uncertain,className:`min-w-0 rounded-media border border-line px-3 pt-1 pb-2`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`flex items-center gap-1 px-1 font-semibold`,children:[`Review checkpoints`,(0,h.jsx)(V,{id:`play.checkpoints`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-6`,children:W3.map(({stage:r,label:s})=>{let c=o.includes(r),l=r===`video`?i.sources.video!==`off`&&i.sources.images!==`off`||i.sources.audio!==`off`:i.sources[r]===`generate`,u=e(`checkpoints.${r}`),d=`${a}-${r}`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:d,className:`flex min-h-10 items-center gap-3 max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:d,type:`checkbox`,"data-play-field":`checkpoints.${r}`,"aria-invalid":u!==void 0,"aria-describedby":`${d}-detail`,checked:c,disabled:!l&&!c,className:`size-4 accent-accent`,onChange:e=>{let a=e.target.checked?[...o,r]:o.filter(e=>e!==r);t.edit({...n,form:{...i,checkpoints:a}}),t.invalidateReview(!0)}}),`Before `,s]}),(0,h.jsx)(`p`,{id:`${d}-detail`,className:u||c&&!l?`pl-7 text-small text-danger`:`sr-only`,children:u??(l?`Approval required before this step and its dependents run.`:c?`This step is unavailable. Remove its checkpoint or enable the step.`:r===`video`?`Enable Video or Audio to review before export.`:`Choose Generate for ${s} to add this checkpoint.`)})]},r)})}),e(`checkpoints`)?(0,h.jsx)(`p`,{className:`text-small text-danger`,children:e(`checkpoints`)}):null]})}function G3({id:e,value:t,disabled:n,className:r,field:i,onChange:a}){let{api:o}=z(),s=N(ib(o)).data?.themes??[],c=t?.custom,l=c===void 0?void 0:s.find(e=>e.id===c.id),u=c!==void 0&&(l===void 0||l.name!==c.name||JSON.stringify(l.values)!==JSON.stringify(c.values)),d=c===void 0&&JS(t)===`dicemaster`,f=c===void 0?`builtin:${JS(t)}`:u?`kept`:`custom:${c.id}`;return(0,h.jsxs)(DV,{id:e,"data-play-field":i,className:r,disabled:n,value:f,onChange:e=>{let n=e.target.value;if(n===`kept`)return;if(n.startsWith(`builtin:`)){let e=WS.find(e=>`builtin:${e}`===n);e!==void 0&&a({theme:e});return}let r=s.find(e=>`custom:${e.id}`===n);r!==void 0&&a({theme:JS(t),custom:{id:r.id,name:r.name,values:r.values}})},children:[(0,h.jsxs)(`optgroup`,{label:`Built in`,children:[WS.map(e=>(0,h.jsx)(`option`,{value:`builtin:${e}`,children:qS[e]},e)),d?(0,h.jsx)(`option`,{value:`builtin:${GS}`,children:`${qS[GS]} (retired, this project's look)`}):null]}),s.length===0&&!u?null:(0,h.jsxs)(`optgroup`,{label:`Your themes`,children:[u?(0,h.jsx)(`option`,{value:`kept`,children:`${c.name} (this project's copy)`}):null,s.map(e=>(0,h.jsx)(`option`,{value:`custom:${e.id}`,children:u&&l?.id===e.id?`${e.name} (current version)`:e.name},e.id))]})]})}function K3({label:e,field:t,hideLabel:n=!1,value:r,options:i,className:a,tip:o,onPick:s}){let c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:L(`inline-flex items-center gap-3`,a),...o===void 0?{}:Ob,children:[(0,h.jsx)(X4,{id:c,className:n?`sr-only`:`shrink-0`,children:e}),(0,h.jsx)(Z4,{type:`single`,value:r,"aria-labelledby":c,onValueChange:e=>{let t=i.find(t=>t.value===e);t!==void 0&&t.disabled!==!0&&s(t.value)},children:i.map(e=>(0,h.jsx)(Q4,{value:e.value,"data-play-field":e.value===r?t:void 0,disabled:e.disabled===!0,children:e.label},e.value))}),o===void 0?null:(0,h.jsx)(V,{id:o,label:e,className:`-ml-1`})]})}function q3({value:e,onPick:t,rawCounts:n}){let r=e.words??500,i=e.characters??3e3,a=e.mode===`words`||e.mode===`characters`,o=e.mode===`characters`,s=o?e.characters:e.words;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(K3,{field:`chunking.mode`,label:`Chunking`,tip:`play.chunking`,className:`min-w-0 max-w-full flex-wrap [&_[data-slot=toggle-group]]:max-w-full [&_[data-slot=toggle-group]]:flex-wrap`,value:e.mode,options:[{value:`whole`,label:`Whole`},{value:`paragraph`,label:`Paragraph`},{value:`words`,label:`Every ${String(n?.words??r)} words`},{value:`characters`,label:`Every ${String(n?.characters??i)} characters`}],onPick:e=>{if(n){n.onChange(e,e===`characters`?n.characters:n.words);return}t(e===`words`?{mode:e,words:r}:e===`characters`?{mode:e,characters:i}:{mode:e})}}),a?(0,h.jsx)(PV,{label:o?`Characters`:`Words`,tip:`play.chunking.count`,problem:void 0,children:({id:r})=>(0,h.jsx)(CV,{id:r,"data-play-field":o?`chunking.characters`:`chunking.words`,type:n?`text`:`number`,min:1,max:o?1e6:1e4,inputMode:`numeric`,className:`sl-input--number`,value:n?o?n.characters:n.words:s===void 0?``:String(s),onChange:r=>{if(n){n.onChange(e.mode,r.target.value);return}let i=Number.parseInt(r.target.value,10),a=Number.isFinite(i)&&i>0;t(o?a?{mode:`characters`,characters:Math.min(i,1e6)}:{mode:`characters`}:a?{mode:`words`,words:Math.min(i,1e4)}:{mode:`words`})}})}):null]})}var J3=1;function Y3({prompts:e,picked:t,problem:n,onPick:r,rawNumbers:i}){let a=(0,m.useId)(),o=t.reduce((e,t)=>e+t.number,0),s=t.filter(t=>!e.some(e=>e.name===t.name)),c=[...e.map(e=>({name:e.name,missing:!1})),...s.map(e=>({name:e.name,missing:!0}))];return c.length===0?(0,h.jsx)(`p`,{className:`sl-fields__wide basis-full text-small text-ink-3`,children:`No image prompts saved. Write one on Prompts.`}):(0,h.jsxs)(`div`,{className:`sl-fields__wide flex w-full basis-full flex-col gap-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{id:a,className:`engraved text-ink-3`,children:`Image prompts`}),(0,h.jsx)(V,{id:`play.image-prompts`,className:`-my-1`})]}),(0,h.jsx)(`ul`,{"aria-labelledby":a,className:`m-0 grid w-full list-none grid-cols-[repeat(auto-fill,minmax(min(100%,15rem),1fr))] gap-x-6 gap-y-2 p-0`,children:c.map(e=>{let a=t.findIndex(t=>t.name===e.name),o=a===-1?void 0:t[a];return(0,h.jsxs)(`li`,{children:[e.missing?(0,h.jsx)(`span`,{className:`block text-label text-danger`,children:`Missing template · untick to remove`}):null,(0,h.jsx)(Gme,{name:e.name,number:o?.number,rawNumber:i?{value:i.values.find(t=>t.name===e.name)?.number??``,onChange:t=>i.onChange(e.name,t)}:void 0,problem:a===-1?void 0:n(`imagePrompts.${String(a)}.number`),onTick:n=>{r(n?[...t,{name:e.name,number:J3}]:t.filter(t=>t.name!==e.name))},onNumber:n=>{r(t.map(t=>t.name===e.name?{name:t.name,number:n}:t))}})]},e.name)})}),t.length===0?null:(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:Number.isFinite(o)?`${String(o)} of 60 images`:`Complete image counts to see the total`})]})}function Gme({name:e,number:t,problem:n,onTick:r,onNumber:i,rawNumber:a}){let o=(0,m.useId)(),s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex w-full min-w-0 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:o,"data-play-field":`imagePrompts`,type:`checkbox`,checked:t!==void 0,className:`size-[14px] shrink-0 accent-accent`,onChange:e=>{r(e.target.checked)}}),(0,h.jsx)(`label`,{htmlFor:o,title:e,className:L(`min-w-0 flex-1 truncate`,t===void 0?`text-ink-3`:`text-ink`),children:e}),(0,h.jsx)(X4,{htmlFor:s,className:`sr-only`,children:`Number for ${e}`}),(0,h.jsx)(CV,{id:s,"data-play-field":`imagePrompts.${e}.number`,type:a?`text`:`number`,min:J3,max:20,inputMode:`numeric`,disabled:t===void 0,"aria-invalid":n!==void 0,"aria-describedby":n===void 0?void 0:c,className:`sl-input--number`,value:a?.value??(t===void 0||t===0?``:String(t)),onChange:e=>{if(a){a.onChange(e.target.value);return}let t=Number.parseInt(e.target.value,10);i(Number.isFinite(t)?t:0)}}),n===void 0?null:(0,h.jsx)(`span`,{id:c,className:`text-label text-danger`,children:n})]})}var Kme=`text-small text-ink-2 file:mr-3 file:h-8 file:rounded-control file:border file:border-line-strong file:bg-raised file:px-3 file:text-ink`;function X3({label:e,field:t,value:n,placeholder:r,problem:i,tip:a,onChange:o}){let s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`div`,{...a===void 0?{}:Ob,children:[(0,h.jsxs)(`span`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:s,children:e}),a===void 0?null:(0,h.jsx)(V,{id:a,label:e,className:`-my-1`})]}),(0,h.jsx)(wV,{id:s,"data-play-field":t,rows:6,value:n,placeholder:r,"aria-invalid":i!==void 0,"aria-describedby":i===void 0?void 0:c,onChange:e=>{o(e.target.value)}}),i===void 0?null:(0,h.jsx)(`p`,{id:c,className:`mt-1 text-label text-danger`,children:i})]})}function Z3({label:e,field:t,accept:n,multiple:r=!1,disabled:i=!1,uploads:a,problem:o,numbered:s=!1,onPick:c,onRemove:l,onReattach:u}){let d=(0,m.useId)(),f=(0,m.useId)();return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(X4,{htmlFor:d,className:`mb-1`,children:e}),(0,h.jsx)(`input`,{id:d,"data-play-field":t,type:`file`,accept:n,multiple:r,disabled:i,"aria-invalid":o!==void 0,"aria-describedby":o===void 0?void 0:f,className:Kme,onChange:e=>{c([...e.target.files??[]]),e.target.value=``}}),o===void 0?null:(0,h.jsx)(`p`,{id:f,className:`mt-1 text-label text-danger`,children:o}),a.length===0?null:(0,h.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,children:a.map((e,t)=>(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3`,children:[s?(0,h.jsx)(`span`,{className:`engraved w-6 text-ink-3`,children:String(t+1)}):null,(0,h.jsx)(qme,{upload:e}),e.error!==void 0&&u?(0,h.jsxs)(`label`,{className:`text-small text-ink-2`,children:[`Reattach`,(0,h.jsx)(`input`,{"aria-label":`Reattach ${e.name}`,className:`max-w-full`,type:`file`,accept:n,onChange:t=>{let n=t.target.files?.[0];t.target.value=``,n&&u(e.key,n)}})]}):null,l===void 0?null:(0,h.jsx)(R,{variant:`quiet`,className:`ml-auto`,"aria-label":`Remove ${e.name}`,onClick:()=>{l(e.key)},children:`Remove`})]},e.key))})]})}function qme({upload:e}){return(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-3 text-small [overflow-wrap:anywhere]`,children:[(0,h.jsx)(`span`,{className:e.error===void 0?`text-ink`:`text-danger`,children:e.name}),e.error===void 0?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:e.file===void 0?`Copying`:`Staged`}):(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.error})]})}var Q3=`col-span-3 min-w-0 sl-fields`,$3=`col-span-3 min-w-0`;function e6({kind:e,name:t,dim:n,titled:r=!0,children:i}){return(0,h.jsxs)(`section`,{"data-tour":`play-${e}`,className:`grid grid-cols-[24px_1fr_auto] items-center gap-x-2 gap-y-4 border-b border-line py-4 [&>div:empty]:hidden`,children:[r?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(sS,{kind:e,className:n?`text-ink-3`:`text-ink-2`}),(0,h.jsx)(`h3`,{className:L(`m-0 text-title-3`,n?`text-ink-3`:void 0),children:t})]}):(0,h.jsx)(`span`,{className:`sl-field__label col-span-2`,children:`Source`}),i]})}var Jme={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`};function t6({kind:e,form:t,update:n}){return(0,h.jsx)(K3,{field:`sources.${e}`,label:`${e} source`,hideLabel:!0,tip:Jme[e],className:`max-[700px]:col-span-3 max-[700px]:justify-self-start [&_[data-slot=toggle-group]]:flex-wrap`,value:t.sources[e],options:FN(e).filter(n=>e!==`thumbnail`||n.value!==`prompt_by_llm`||t.sources.article!==`off`).map(n=>({...n,disabled:e===`video`&&n.value===`generate`&&t.sources.images===`off`})),onPick:r=>{if(e===`article`&&r===`off`){n(Yme(t));return}n({sources:{...t.sources,[e]:r,...e===`images`&&r===`off`?{video:`off`}:{}}})}})}function n6(e,t){return e.filter(e=>e.kind===t).map(e=>({value:e.name,label:e.name}))}function Yme(e){return{sources:{...e.sources,article:`off`,research:`off`,audio:`off`,document:`off`,...e.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}},subtitles:{...e.subtitles,mode:`off`},youtubeDescription:!1,...e.shorts===void 0?{}:{shorts:{...e.shorts,enabled:!1}}}}function Xme(e){let t=this;t.compiler=n;function n(n){return yle(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}var r6=QR().use(vR).use(Xme).freeze(),i6=`[ˈˌ]?[abdefghijklmnoprstuvwxzæðŋθɑɒɔəɚɛɜɝɡɪɹʃʊʌʒʔɫɾ][\\u0303\\u031a\\u0325\\u0329\\u032a\\u032c\\u032f\\u035c\\u0361ʰʲʷ]*[ːˑ]?`,Zme=RegExp(`^(?:${i6})+(?:\\.(?:${i6})+)*$`,`u`),a6=`[ˈˌ]?[a-zæçðøħŋœɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɪɫɬɭɮɯɰɱɲɳɴɵɶɸɹɺɻɽɾʀʁʂʃʄʈʉʊʋʌʍʎʏʐʑʒʔʕʙʛʜʝʟʡʢβθχ][\\u0300-\\u036fʰʱʲʷʼˠˤ˞]*[ːˑ]?`,Qme=RegExp(`^(?:${a6})+(?:\\.(?:${a6})+)*$`,`u`);function o6(e){return e.type===`break`?`
278
- `:e.value??e.children?.map(o6).join(``)??``}function s6(e){if(e.type===`heading`){let t=o6(e).trim();return/^pronunciation glossary:?\s*$/iu.test(t)?[]:[t]}return e.type===`table`?(e.children??[]).slice(1).map(e=>{let t=e.children??[];if(t.length<2)return o6(e);let[n,r]=t.slice(0,2).map(e=>o6(e).trim());return`${n}: ${r!==void 0&&r!==``&&!r.includes(`/`)?`/${r}/`:r}`}):e.type===`paragraph`?o6(e).split(/\r?\n/u):e.type===`root`||e.type===`list`||e.type===`listItem`?(e.children??[]).flatMap(s6):[`(unsupported glossary block)`]}function $me(e){return Array.from(e,e=>{let t=e.toLowerCase(),n=t.toUpperCase().toLowerCase();if(n===e)return e;let r=RegExp(`^${e.replace(/[|\\{}()[\]^$+*?.]/gu,`\\$&`)}$`,`iu`);return r.test(n)?n:r.test(t)?t:e}).join(``)}function c6(e,t){let n=t===void 0||t===`en`,r=n?Zme:Qme,i=n?`standard-English IPA`:`IPA`,a=s6(r6().use(pB).parse(e)),o=new Map,s=[];for(let[e,t]of a.entries()){let a=t=>{s.push({row:e+1,reason:t})},c=t.trim();if(c===``||/^pronunciation glossary:?\s*$/iu.test(c))continue;let l=/^([^:]+):\s*(.+)$/u.exec(c),u=l?.[1]?.trim().replace(/\s+/gu,` `),d=l?.[2];if(u===void 0||d===void 0||!/[\p{L}\p{N}]/u.test(u)||/[/[\]<>\p{Cc}]/u.test(u)){a(`use Term: /IPA/ or a Term | IPA table`);continue}let f=/^(\/[^/]+\/(?:\s+\/[^/]+\/)*)(?:\s+[^/]+)?$/u.exec(d);if(f?.[1]===void 0){a(`use slash-delimited ${i}`);continue}let p=Array.from(f[1].matchAll(/\/([^/]+)\//gu)).flatMap(e=>(e[1]??``).trim().split(/\s+/u));if(p.length===0||p.some(e=>!r.test(e))){a(n?`use standard-English IPA only, not ARPAbet, delivery tags or non-English sounds; give a foreign name an English approximation`:`use IPA, not ARPAbet or delivery tags`);continue}if(u.split(` `).length!==p.length){a(`supply one IPA word for each written word`);continue}let m=$me(u),h=o.get(m);if(h!==void 0&&h.ipa.join(` `)!==p.join(` `)){a(`an earlier entry already gives this term a different pronunciation`);continue}h===void 0&&o.set(m,{term:u,ipa:p})}return s.length===0?{ok:!0,entries:[...o.values()]}:{ok:!0,entries:[...o.values()],skipped:s}}function ehe(e,t){return e.flatMap(e=>{if(!e.pronunciations?.trim())return[];let n=c6(e.pronunciations,t),r=n.ok?n.skipped??[]:[];return r.length===0?[]:[{speaker:e.name.trim()||`A speaker`,skipped:r}]})}function the(e,t){let n=t?.turns.find(t=>t.speaker===e.id)?.text??nhe(e);if(n.length<=200)return n;let r=n.slice(0,200),i=Math.max(r.lastIndexOf(`. `),r.lastIndexOf(`? `),r.lastIndexOf(`! `));return i>60?r.slice(0,i+1):`${r.slice(0,r.lastIndexOf(` `))}…`}function nhe(e){let t=e.name.trim()||`your speaker`;switch(e.role){case`narrator`:return`The night was quiet, and the old house held its breath. I'm ${t}, and I'll be telling this story.`;case`host`:return`Hi everyone, I'm ${t}, and welcome back to the show. Today's topic is a good one.`;case`guest`:return`Thanks for having me. I'm ${t}, and I've been looking forward to this conversation.`;case`character`:return`You really thought I wouldn't find out? My name is ${t}, and I always find out.`}}function rhe(e){return e.flatMap(e=>e.host===!0&&e.voice!==void 0?[l6(e,`host`)]:[])}function ihe(e){let t=e.toLowerCase();return/^[a-z0-9-]{1,55}$/.test(t)?`cast-${t}`:`cast-h${ahe(e)}`}function ahe(e){let t=3735928559,n=1103547991;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,2654435761),n=Math.imul(n^i,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(4294967296*(2097151&n)+(t>>>0)).toString(36)}function l6(e,t){let n=e.voice;return{id:ihe(e.id),name:e.name.slice(0,40),role:t,voice:n===void 0?{provider:``,model:``,voice:``}:{provider:n.provider,model:n.model,voice:n.voice},...n?.pace===void 0||n.pace===1?{}:{pace:n.pace},...n?.pronunciations?.trim()?{pronunciations:n.pronunciations}:{},castId:e.id,...ohe(e)}}function ohe(e){let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null)?.sha256;return t==null?{}:{portrait:t}}var she=/^#{1,6}\s+(.+?)\s*#*\s*$/,che=/^\*{0,2}([^:*\n]{1,60}?)\*{0,2}\s*:\s*\*{0,2}\s*(.*)$/;function u6(e,t,n=!1){let r=new Map(t.map(e=>[e.name.trim().toLowerCase(),e])),i=t.map(e=>e.name.trim()).join(`, `),a=[],o=[],s=!1;for(let[t,n]of e.replace(/\r\n?/g,`
276
+ `).length,a=t-r;return`line ${String(i)}, column ${String(a)}`}function t3(e,t){return[...`kind`in e?Zpe(e):Qpe(e),...t]}function n3(e){return e[0]?.message}function r3(e){return e.filter(e=>e.field===`body`)}function i3(e){return e.filter(e=>e.field===`name`)}function a3(e){return dq(e).names}function tme(e){let t=[],n=0;for(let r of dq(e).errors){if(r.at<n)continue;r.at>n&&t.push({start:n,text:e.slice(n,r.at),marked:!1});let i=Math.min(r.at+2,e.length);t.push({start:r.at,text:e.slice(r.at,i),marked:!0}),n=i}return n<e.length&&t.push({start:n,text:e.slice(n),marked:!1}),t}var o3=`px-3 py-3 font-sans text-body leading-[1.5] break-words [scrollbar-gutter:stable]`;function s3({id:e,value:t,invalid:n,describedBy:r,onChange:i}){let a=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:`relative max-w-[75ch]`,children:[(0,h.jsxs)(`div`,{ref:a,"aria-hidden":`true`,"data-slot":`lint-overlay`,className:L(o3,`pointer-events-none absolute inset-0 overflow-hidden whitespace-pre-wrap`,`rounded-control border border-transparent bg-sunken text-ink`),children:[tme(t).map(e=>(0,h.jsx)(`span`,{"data-lint-mark":e.marked?e.start:void 0,className:e.marked?`text-danger underline decoration-danger decoration-2 underline-offset-[3px]`:void 0,children:e.text},e.start)),`
277
+ `]}),(0,h.jsx)(wV,{id:e,rows:24,value:t,spellCheck:!1,"aria-invalid":n,"aria-describedby":r,className:L(o3,`relative block min-h-[520px] resize-y border-line-strong overflow-auto bg-transparent text-transparent caret-ink`),onChange:e=>{i(e.target.value)},onScroll:e=>{let t=a.current;t!==null&&(t.scrollTop=e.currentTarget.scrollTop,t.scrollLeft=e.currentTarget.scrollLeft)}})]})}function c3({entryId:e,category:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=N(rb(i)),s=(0,m.useId)(),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),S=o.data?.entries,C=e??n,w=C===void 0?void 0:S?.find(e=>e.id===C),T=w===void 0?{category:t,mode:`text`,name:``,body:``}:{category:w.category,mode:w.mode,name:e===void 0?`${w.name} copy`:w.name,body:w.body},E=d??T,D=P({mutationFn:t=>Ns(i,t,e),onSuccess:async e=>{if(!e.ok){g(e.fields);return}y(!0),await a.invalidateQueries({queryKey:rb(i).queryKey})}}),O=P({mutationFn:e=>Vs(i,e),onSuccess:async()=>{x(!1),await a.invalidateQueries({queryKey:rb(i).queryKey}),r(E.category)}});X2(v,()=>{r(E.category)});let k=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},A=t3(E,p),ee=n3(A),te=a3(E.body),ne=E.body.trim()===``?[]:r3(A),j=E.name.trim()===``?[]:i3(A);return o.error===null?C!==void 0&&S===void 0?(0,h.jsx)($2,{}):C!==void 0&&w===void 0?(0,h.jsx)(l3,{category:t,children:`That entry is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/entries`,search:{category:E.category},children:`Intros & Outros`})}),title:e===void 0?`New entry`:`Edit entry`,meta:dV(E.category)}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{className:`min-w-[200px] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.entry.name`,...j.length===0?{}:{error:j.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:E.name,onChange:e=>{k({...E,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Category`,value:E.category,options:lV,tip:`library.entry.category`,onPick:e=>{k({...E,category:e},`name`)}}),(0,h.jsx)($4,{label:`Mode`,value:E.mode,options:uV,describedBy:s,tip:`library.entry.mode`,onPick:e=>{k({...E,mode:e},`mode`)}})]}),(0,h.jsx)(`p`,{id:s,className:`-mt-2 text-right text-small text-ink-2`,children:pV(E.mode)}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:`library.entry.body`,label:`Body`,className:`-my-1`})]}),(0,h.jsx)(s3,{id:c,value:E.body,invalid:ne.length>0,describedBy:ne.length===0?void 0:l,onChange:e=>{k({...E,body:e},`body`)}})]}),(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{x(!0)},blocked:ee,blockedId:u,pending:D.isPending,saved:v,cancel:(0,h.jsx)(fS,{to:`/entries`,search:{category:E.category},variant:`secondary`,children:`Cancel`}),errors:[D.error,O.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{D.mutate(E)}})]}),(0,h.jsx)(`div`,{className:m4,children:(0,h.jsx)(Y4,{slots:te,body:E.body,lint:ne,lintId:l,noSlots:mV(E.mode)})})]}),(0,h.jsx)(jy,{open:b,title:`Delete "${E.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${E.category}`,pending:O.isPending,onConfirm:()=>{e!==void 0&&O.mutate(e)},onCancel:()=>{x(!1)}})]}):(0,h.jsx)(l3,{category:E.category,children:o.error.message})}function l3({category:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/entries`,search:{category:e},children:`Back to Intros & Outros`}),children:t})}var nme=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),rme=new Intl.DateTimeFormat(void 0,{timeStyle:`short`});function ime({runs:e}){return(0,h.jsx)(pU,{label:`Coming up`,children:e.map(e=>(0,h.jsx)(mU,{title:`${nme.format(new Date(e.at))} · ${rme.format(new Date(e.at))} · ${uU(e)}`,meta:[e.scheduleName,e.templateName].filter(e=>e!==null).join(` · `),actions:e.paused?(0,h.jsx)(vS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(vS,{tone:`info`,children:`Needs a topic`}):(0,h.jsx)(vS,{children:`Queued`})},`${e.scheduleId}-${e.at}`))})}var u3=q({revisionId:W(),checkpoints:K(Zj.unwrap().extend({currentFingerprint:W().regex(/^[a-f0-9]{64}$/),dependents:K(J(FS)),workKeys:K(W())}))}),ame=q({revisionId:W().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),stages:K(Xj).max(3).refine(e=>new Set(e).size===e.length).readonly()}).strict(),ome=q({title:W(),status:G(),detail:W().optional(),reason:J([`duplicate`,`not-found`,`conflict`,`invalid-input`]).optional()}),sme=Qj.unwrap().omit({projectId:!0,checkpointId:!0,approvedAt:!0}),d3=e=>[`checkpoints`,e],f3=(e,t)=>[...d3(e),t];async function p3(e,t){let n;try{n=await e.json()}catch{throw po(e,void 0)}if(e.ok)return{ok:!0,value:So(t,n)};let r=ome.safeParse(n);if(!r.success)throw po(e,void 0);if(![400,404,409].includes(e.status))throw Error(r.data.detail??r.data.title);return{ok:!1,reason:r.data.reason??`invalid-input`,message:r.data.detail??r.data.title}}async function m3(e,t){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`),u3)}async function h3(e,t,n,r){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints/${encodeURIComponent(n)}/approve`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(sme.parse(r))}),q({checkpoint:Zj,replayed:GD()}))}async function cme(e,t,n){return p3(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/checkpoints`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(ame.parse(n))}),u3)}var g3=(0,m.createContext)(void 0);function _3(e,t){if(e.state===`failed`)return V1({stage:e.kind,kind:e.failureKind,reason:e.failureReason,provider:ode(t.config,e.kind)})}function v3({projectId:e,className:t}){let{api:n}=z(),[r,i]=(0,m.useState)(!1);return(0,h.jsx)(`div`,{className:L(`sl-media__frame`,t),"aria-hidden":`true`,children:r?(0,h.jsx)(`div`,{className:`flex size-full items-center justify-center bg-sunken text-ink-3`,children:(0,h.jsx)(bc,{strokeWidth:1.75,className:`size-6`})}):(0,h.jsx)(`img`,{src:Ko(n,e,`thumbnail`),alt:``,loading:`lazy`,decoding:`async`,onError:()=>i(!0)})})}function y3(e){return e.status===`pending`&&e.progress>0}function b3({lead:e,status:t,title:n,detail:r,action:i}){return(0,h.jsxs)(`li`,{className:L(`sl-home-item`,dU),children:[e,(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[t,(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:n}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:r})]}),(0,h.jsx)(Ey,{className:`sl-home-item__action`,children:i})]})}function x3(e){return(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}var lme={audio:`Approve the article and record`,images:`Approve and draw the images`,video:`Approve and render`},ume={audio:`review before the narration`,images:`review before the images`,video:`review before the video`};function dme({project:e,primary:t}){let{api:n}=z(),r=_(),i=Oy(),a=Zi(),o=(0,m.useRef)(null),s=N({queryKey:d3(e.id),queryFn:async()=>{let t=await m3(n,e.id);if(!t.ok)throw Error(t.message);return t.value}}).data?.checkpoints.find(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint),c=P({mutationFn:async t=>{o.current??={revisionId:t.revisionId,fingerprint:t.fingerprint,idempotencyKey:crypto.randomUUID()};let r=await h3(n,e.id,t.checkpointId,o.current);return o.current=null,r},onSuccess:t=>{i(t.ok?`Approved: ${e.title}. The run continues.`:`${e.title} wasn't approved: ${t.message} Open the project to review it there.`,t.ok?`success`:`error`)},onError:t=>{i(`Slopify didn't confirm the approval of ${e.title}: ${t.message} Press the button again to check whether it went through.`,`error`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:d3(e.id)}),r.invalidateQueries({queryKey:B.projects})])}}),l=s===void 0?void 0:lme[s.stage];return bx({id:`home.approve.${e.id}`,title:l??`Open the held run`,group:`Needs you`,context:e.title,keywords:[`approve`,`review`,`waiting`],run:()=>{s===void 0?a({to:`/projects/$projectId`,params:{projectId:e.id}}):c.mutate(s)}}),(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:s===void 0?`Waiting for you`:`Waiting for you · ${ume[s.stage]}`}),title:x3(e),detail:s===void 0?`Its next step is held. Open the project to review it and continue the run.`:`Everything before this step is done. Approve to let the run go on, or open the project to look first.`,action:s===void 0||l===void 0?(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`}):(0,h.jsx)(R,{variant:t?`primary`:`secondary`,disabled:c.isPending,disabledReason:`Approving…`,onClick:()=>c.mutate(s),children:c.isPending?`Approving…`:l})})}function fme({schedule:e,primary:t}){let n=e.topics.held;return(0,h.jsx)(b3,{lead:(0,h.jsx)(`div`,{className:`sl-media__frame flex items-center justify-center bg-sunken text-info`,children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-7`})}),status:(0,h.jsx)(_S,{tone:`info`,children:`${String(n)} new ${n===1?`topic`:`topics`}`}),title:e.name,detail:`Slopify suggested ${n===1?`a topic`:`${String(n)} topics`} for this schedule. Queue the ones you want and reject the rest.`,action:(0,h.jsx)(fS,{to:`/calendar`,variant:t?`primary`:`secondary`,className:fU,children:`Review topics`})})}function pme({project:e,primary:t}){return(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}),title:x3(e),detail:`You paused this run. Nothing more happens until you open it and press Continue the run.`,action:(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:t?`primary`:`secondary`,children:`Open to continue`})})}function mme({project:e,primary:t}){let{api:n}=z(),r=N({queryKey:B.project(e.id),queryFn:()=>jo(n,e.id)}),i=r.data?.stages.find(e=>e.state===`failed`),a=Oy(),o=async e=>{let t=await q1(e);a(t?`Copied ${e}. Run it in a terminal on the computer running Slopify and sign in, then open the project and press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e} in a terminal, sign in, then open the project and press Check again.`,t?`success`:`error`)},s=i===void 0||r.data===void 0?void 0:_3(i,r.data.project),c=BP(i?.failureReason)??`The run stopped with an error.`,l=i===void 0?``:` · ${nF[i.kind]}`,u=t?`primary`:`secondary`,d=s?.kind===`provider-settings`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},variant:u,children:s.label}):s?.kind===`free-space`?(0,h.jsx)(fS,{to:`/settings`,search:{section:`storage`},variant:u,children:s.label}):s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:u,onClick:()=>void o(s.command),children:`Copy sign-in command`}),(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},children:`Open to retry`})]}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:e.id},variant:u,children:s?.label??`Open to retry`});return(0,h.jsx)(b3,{lead:(0,h.jsx)(v3,{projectId:e.id}),status:(0,h.jsx)(_S,{tone:`failed`,children:`Failed${l}`}),title:x3(e),detail:s?.kind===`sign-in`?(0,h.jsxs)(h.Fragment,{children:[c,` Run `,(0,h.jsx)(`code`,{className:`sl-code`,children:s.command}),` in a terminal to sign in, then press Check again on the project to retry the step.`]}):c,action:d})}var hme=[`home`,`week`];function gme(e=new Date){let t=new Date(e);t.setHours(0,0,0,0);let n=(t.getDay()+6)%7;return t.setDate(t.getDate()-n),t}function _me(e,t,n){return ct({queryKey:[...hme,t,n],queryFn:async()=>{let r=new URLSearchParams({since:t});return n!==null&&r.set(`channelId`,n),F(await e.fetch(`${e.origin}/api/home/week?${r.toString()}`))},staleTime:3e4})}async function S3(e,t,n){return F(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/uploaded`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({uploaded:n})}))}function C3(e){return(e.status===`done`||e.status===`partial`)&&e.config.sources.video!==`off`&&e.uploadedAt===null}function vme({project:e}){let{api:t}=z(),n=_(),r=Oy(),i=P({mutationFn:n=>S3(t,e.id,n),onSuccess:(t,n)=>{r(n?`Marked uploaded: ${e.title}. It is off Ready to upload; Projects still lists it.`:`${e.title} is back on Ready to upload.`,`success`)},onError:t=>{r(`${e.title} wasn't marked uploaded: ${t.message} Press Mark uploaded again.`,`error`)},onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});return bx({id:`home.uploaded.${e.id}`,title:`Mark uploaded`,group:`Ready to upload`,context:e.title,keywords:[`youtube`,`published`,`done`],run:()=>i.mutate(!0)}),(0,h.jsxs)(`li`,{className:`sl-home-ready ${dU}`,children:[(0,h.jsx)(v3,{projectId:e.id}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),(0,h.jsx)(`div`,{className:`text-small text-ink-2`,children:`${e.format} · finished ${ku(e.updatedAt)}${e.status===`partial`?` · a step failed`:``}`}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(h2,{projectId:e.id,ready:!0,size:`small`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i.isPending,disabledReason:`Saving…`,onClick:()=>i.mutate(!0),children:`Mark uploaded`})]})]})]})}function w3(e){return e.status===`pending`&&e.progress===0}var yme=2;function bme({running:e,queued:t}){let n=e>3;if(!n&&t.length===0)return null;let r=t.slice(0,yme).map(e=>e.title.trim()||`Untitled project`),i=t.length-r.length;return(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n?(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/projects`,search:{show:`running`},children:`See all ${String(e)} running`})}):null,t.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-ink`,children:`Queued, waiting to start (${String(t.length)}): `}),r.join(`, `),i>0?` and ${String(i)} more`:``]}),(0,h.jsx)(pS,{to:`/projects`,search:{show:`queued`},children:`See queued`})]})]})}function T3(e,t){if(e.state!==`running`)return;let n=e.startedAt===null?NaN:Date.parse(e.startedAt),r=Number.isFinite(n)?Math.max(0,(t-n)/1e3):void 0,i=e.progressCurrent??0,a=e.progressTotal??0;if(r!==void 0&&a>0&&i>0)return i>=a?{basis:`progress`,seconds:0}:{basis:`progress`,seconds:Math.round(r/i*(a-i))};let o=e.typicalSeconds;if(o===void 0||!Number.isFinite(o)||o<=0)return{basis:`unknown`};let s=o-(r??0);return s>0?{basis:`history`,seconds:Math.round(s)}:{basis:`overdue`}}function E3(e){if(e.basis===`unknown`)return`time left unknown`;if(e.basis===`overdue`)return`taking longer than usual`;let t=e.seconds??0;if(t<=0)return`finishing up`;if(t<60)return`under a minute left`;let n=Math.round(t/60);if(n<60)return`about ${String(n)} min left`;let r=Math.floor(n/60),i=n%60;return i===0?`about ${String(r)} h left`:`about ${String(r)} h ${String(i)} min left`}function D3(e){let t=e.role.replaceAll(`_`,`-`);return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment!==void 0?`${t}-${e.meta.segment}`:e.role===`short_video`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}`:e.role===`short_image`&&e.meta.short!==void 0?`${t}-${String(e.meta.short)}-${String(e.meta.index??1)}`:e.role===`thumbnail`&&e.meta.index!==void 0&&e.meta.index>1?`${t}-${String(e.meta.index)}`:e.role===`instructions`?`${e.stageKind}-${t}`:(e.role===`image`||e.role===`animated_image`)&&e.meta.index!==void 0?`${t}-${String(e.meta.index)}`:t}function O3({steps:e,label:t,dense:n=!1,className:r}){return(0,h.jsx)(`ol`,{"aria-label":t,className:L(`sl-steps m-0 list-none p-0`,n&&`sl-steps--dense`,r),children:e.map(e=>(0,h.jsxs)(`li`,{className:`sl-step`,"data-tone":e.tone,children:[(0,h.jsx)(gS,{tone:e.tone}),(0,h.jsxs)(`span`,{className:`sl-step__name`,children:[e.name,(0,h.jsx)(`span`,{className:`sr-only`,children:`, ${e.state}`})]}),(0,h.jsx)(`span`,{className:`sl-step__time`,children:e.time??`—`}),e.detail===void 0?null:(0,h.jsx)(`span`,{className:`sl-step__detail`,children:e.detail})]},e.id))})}function k3(e){let{api:t}=z();return N({...Xy(t,e),enabled:!1,select:e=>e.revisionId??null}).data??null}var A3=(e,t=null)=>[`live-writing`,e,t];function xme(e,t){let n=e=>e.callId===t.callId&&e.revisionId===t.revisionId&&e.workId===t.workId,r=e.find(n),i=(t.reset?t.text:`${r?.text??``}${t.text}`).slice(-65536),a={...t.revisionId===void 0?{}:{revisionId:t.revisionId},...t.workId===void 0?{}:{workId:t.workId},...t.workPieceId===void 0?{}:{workPieceId:t.workPieceId},stage:t.stage,callId:t.callId,...t.label===void 0?{}:{label:t.label},text:i};return(r?e.map(e=>n(e)?a:e):[...e,a]).slice(-24)}function j3({projectId:e,stage:t,className:n=`mx-5 mt-5`}){let r=(N({queryKey:A3(e,k3(e)),queryFn:()=>[],enabled:!1}).data??[]).filter(e=>e.stage===t),[i,a]=(0,m.useState)(),o=r.find(e=>e.callId===i)??r.at(-1),[s,c]=(0,m.useState)(!0),l=(0,m.useRef)(null);return(0,m.useEffect)(()=>{o?.text&&s&&l.current&&(l.current.scrollTop=l.current.scrollHeight)},[s,o?.text]),r.length===0&&t!==`research`&&t!==`article`?null:(0,h.jsxs)(`div`,{className:L(`border-y border-line`,n),children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-line py-3`,...Ob,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-accent-ink`,children:`Live writing`}),(0,h.jsx)(V,{id:`project.live.writing`})]}),r.length>1?(0,h.jsx)(TV,{"aria-label":`Live writing task`,value:o?.callId??``,onChange:e=>a(e.target.value),className:`max-w-[280px]`,children:r.map((e,t)=>(0,h.jsxs)(`option`,{value:e.callId,children:[e.label??`Writing`,` · `,t+1]},e.callId))}):null,(0,h.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`Follow output`]})]}),(0,h.jsx)(`section`,{ref:l,"aria-label":`Live writing preview`,tabIndex:0,className:`max-h-[360px] min-h-32 overflow-auto whitespace-pre-wrap break-words py-4 font-sans text-small leading-relaxed text-ink-2`,children:o?.text||`Waiting for the provider's first text…`}),(0,h.jsx)(`p`,{className:`border-t border-line py-2 text-label text-ink-3`,children:`Live preview. The complete output is saved when this stage finishes.`})]})}var Sme=q({id:W(),projectId:W(),revisionId:W(),itemKey:W(),stage:J(Ck),itemFingerprint:W(),reviewFingerprint:W(),passed:GD(),reasons:K(W()),outcome:J([`passed`,`flagged`,`redo`]),attempt:G(),action:J([`overruled`,`redone`]).nullable(),actionAt:W().nullable(),redoState:J([`pending`,`started`,`failed`]).nullable(),redoError:W().nullable(),createdAt:W(),current:GD(),outputId:W().nullable(),verdicts:G()}),M3=e=>[`reviews`,e],Cme=q({title:W(),detail:W().optional()});async function wme(e,t){let n=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews`);if(!n.ok)throw po(n,void 0);return So(q({reviews:K(Sme)}),await n.json()).reviews}async function Tme(e,t,n,r,i){let a=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/reviews/${encodeURIComponent(n)}/${r}`,{method:`POST`,...i===void 0?{}:{headers:{"content-type":`application/json`},body:JSON.stringify(i)}});if(a.ok)return{ok:!0};let o;try{o=await a.json()}catch{throw po(a,void 0)}let s=Cme.safeParse(o);if(!s.success||![400,404,409,503].includes(a.status))throw po(a,void 0);return{ok:!1,message:s.data.detail??s.data.title}}var Eme=200;function N3(e,t=null){let{api:n,openEvents:r}=z(),i=_();(0,m.useEffect)(()=>{i.setQueryData(B.article(e,t),``),i.setQueryData(A3(e,t),[]);let a=()=>i.getQueryData(B.project(e))?.revisionId??null,o=kB(()=>{i.invalidateQueries({queryKey:B.project(e)}),i.invalidateQueries({queryKey:B.projects}),i.invalidateQueries({queryKey:d3(e)}),i.invalidateQueries({queryKey:M3(e)})},Eme),s=AS(r,Hs(n,`projects/${e}`),{refetch:o.ask,accept:e=>e.type===`project.updated`||e.type===`project.state`&&e.revisionId===void 0||(e.revisionId??null)===a()||(o.ask(),!1),previewWriting:t=>{i.setQueryData(A3(e,a()),e=>xme(e??[],t))},narrationPiece:()=>{i.invalidateQueries({queryKey:Py(e,a())})},appendArticle:t=>{i.setQueryData(B.article(e,a()),e=>`${e??``}${t}`)},patch:t=>{if(t.type===`stage.state`&&t.state===`running`&&(i.setQueryData(A3(e,a()),e=>(e??[]).filter(e=>e.stage!==t.stage||e.workId!==t.workId||e.revisionId!==t.revisionId)),t.stage===`article`&&i.setQueryData(B.article(e,a()),``)),t.type!==`project.state`&&t.workId!==void 0){o.ask();return}i.setQueryData(B.project(e),e=>DB(e,t))}});return()=>{s(),o.stop()}},[n,r,i,e,t])}var Dme={pending:`off`,running:`running`,done:`done`,provided:`done`,failed:`failed`,canceled:`off`,skipped:`off`},Ome={pending:`Not started`,running:`Running`,done:`Done`,provided:`Provided`,failed:`Failed`,canceled:`Canceled`,skipped:`Skipped`};function kme(e,t,n){if(e===null)return;let r=(t===null?n:Date.parse(t))-Date.parse(e);if(!Number.isFinite(r)||r<0)return;let i=Math.round(r/1e3);if(i<60)return`${String(i)} s`;let a=Math.round(i/60);if(a<60)return`${String(a)} min`;let o=Math.floor(a/60);return`${String(o)} h ${String(a%60)} min`}function Ame(e,t){let n=T3(e,t);if(n!==void 0)return`${e.progressTotal!==null&&e.progressTotal>0?`${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)} · `:``}${E3(n)}`}function jme({project:e,now:t}){let{api:n}=z();N3(e.id);let[r,i]=(0,m.useState)(null),a=N(Xy(n,e.id)),o=(a.data?.stages??[]).filter(e=>e.source!==`off`&&e.state!==`skipped`),s=(a.data?.outputs??[]).filter(e=>e.role===`image`).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),c=o.find(e=>e.kind===`images`&&e.state===`running`),l=o.find(e=>e.state===`running`),u=YH(e.limitWaits),d=s.slice(c===void 0?-4:-3),f=o.map(n=>({id:n.kind,name:iF(n.kind,e.config),tone:Dme[n.state],state:Ome[n.state],time:kme(n.startedAt,n.finishedAt,t),detail:Ame(n,t)}));return(0,h.jsxs)(`li`,{className:`sl-home-run ${dU}`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-row__title text-[17px]`,children:(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title})}),e.status===`paused`?(0,h.jsx)(_S,{tone:`waiting`,children:`Paused`}):u===void 0?(0,h.jsx)(_S,{tone:`running`,children:l===void 0?`Running`:`${iF(l.kind,e.config)}`}):(0,h.jsx)(_S,{tone:`waiting`,children:u})]}),d.length===0&&c===void 0?null:(0,h.jsxs)(B0,{list:!0,density:`compact`,label:`Images of ${e.title}`,children:[d.map((t,r)=>(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,onOpen:()=>i(r)})},t.id)),c===void 0?null:(0,h.jsx)(`li`,{children:(0,h.jsx)(z0,{alt:`The next image`,generating:`Drawing · ${String(s.length)} so far`})})]}),(0,h.jsx)(V0,{items:d.map(t=>({src:Ko(n,e.id,D3(t)),alt:`Image ${String(t.meta.index??``)}`,...t.meta.prompt===void 0?{}:{caption:t.meta.prompt}})),index:r,onIndex:i,onClose:()=>i(null)}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Images ${String(c.progressCurrent??s.length)} of ${String(c.progressTotal??`?`)}`})]}),(0,h.jsx)(O3,{steps:f,label:`Steps of ${e.title}`})]})}var P3=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2});function Mme(e){return`spent${e.apiEquivalent===null?``:` · ~${P3.format(e.apiEquivalent)} via API`}${e.unpriced===0?``:` · ${String(e.unpriced)} ${e.unpriced===1?`call`:`calls`} without a price`}`}function Nme({channelId:e}){let{api:t}=z(),n=N(_me(t,gme().toISOString(),e));if(n.error!==null)return(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`This week's numbers didn't load: ${n.error.message} Reload the page to try again.`});let r=n.data;return(0,h.jsxs)(G2,{className:`sl-home-stats`,children:[(0,h.jsx)(K2,{value:r===void 0?`—`:String(r.videos),label:`videos made`}),(0,h.jsx)(K2,{value:r===void 0?`—`:P3.format(r.cost),label:r===void 0?`spent`:Mme(r)}),(r?.plans??[]).filter(e=>e.weeklyPercent!==null).map(e=>{let t=Math.round(e.weeklyPercent??0);return(0,h.jsx)(K2,{value:`${String(t)}%`,label:`weekly ${e.name} limit`,children:(0,h.jsx)(q2,{value:t/100,label:`Weekly ${e.name} limit`,valueText:`${String(t)}% of your weekly ${e.name} limit`,tone:t>=80?`waiting`:`accent`})},e.account)})]})}var Pme=864e5,Fme=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`}),F3=4,I3=!1,L3=!1;function Ime(){let{api:e}=z(),t=gx(),n=N(Yy(e)),r=N(EH(e)),i=N(Hq(e)),[a]=(0,m.useState)(()=>{let e=new Date;return e.setHours(0,0,0,0),{from:new Date().toISOString(),to:new Date(e.valueOf()+8*Pme).toISOString()}}),o=N(KH(e,a.from,a.to)),s=N({queryKey:My,queryFn:()=>Iy(e)}),c=Zi();(0,m.useEffect)(()=>{s.data?.show===!0&&!I3&&(I3=!0,c({to:`/welcome`}))},[s.data?.show,c]),(0,m.useEffect)(()=>{s.data?.settle===!0&&!L3&&(L3=!0,Ly(e).catch(()=>{L3=!1}))},[s.data?.settle,e]);let[l,u]=(0,m.useState)(()=>Date.now());(0,m.useEffect)(()=>{let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[]);let d=(0,m.useMemo)(()=>new Map((i.data??[]).map(e=>[e.id,e.channelId])),[i.data]),f=(n.data?.projects??[]).filter(e=>t.includes(e.channelId)),p=f.filter(e=>e.status===`running`),g=f.filter(w3),_=f.filter(e=>e.status===`paused`),v=f.filter(y3),y=f.filter(e=>e.status===`failed`),b=new Set(Object.values(s.data?.samples??{}).filter(e=>e!==null)),x=f.filter(e=>C3(e)&&!b.has(e.id)),S=(r.data??[]).filter(e=>e.deletedAt===null&&e.topicGeneration.mode===`hold`&&e.topics.held>0&&t.includes(d.get(e.templateId))),C=(o.data?.runs??[]).filter(e=>t.includes(d.get(e.templateId))),w=[...v.map(e=>({kind:`waiting`,project:e})),..._.map(e=>({kind:`paused`,project:e})),...S.map(e=>({kind:`held`,schedule:e})),...y.slice(0,F3).map(e=>({kind:`failed`,project:e}))],T=n.isPending;return(0,h.jsxs)(`div`,{"data-tour":`home`,children:[(0,h.jsx)(kq,{display:!0,crumb:Fme.format(new Date),title:t.channel?.name??`Home`,meta:t.channelId===null?`Every channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(fS,{to:`/play`,variant:`secondary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]}),(0,h.jsxs)(fS,{to:`/calendar`,variant:`quiet`,children:[(0,h.jsx)(sc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open calendar`]})]})}),(0,h.jsxs)(`div`,{className:`mb-5 flex items-end gap-1 md:hidden`,...Ob,children:[(0,h.jsx)(_x,{className:`min-w-0 flex-1`}),(0,h.jsx)(V,{id:`home.channel`,className:`mb-1`})]}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-5 text-danger`,children:`Your projects didn't load: ${n.error.message} Check that Slopify is still running, then reload the page.`}),(0,h.jsxs)(e0,{split:`main-side`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(H,{title:`Needs you`,info:`home.needs-you`,meta:T?`Loading…`:w.length===0?`Nothing is waiting for a decision`:`${String(w.length)} ${w.length===1?`thing is`:`things are`} waiting for you`}),w.length===0?null:(0,h.jsx)(`ul`,{"aria-label":`Waiting for you`,className:`m-0 flex list-none flex-col gap-3 p-0`,children:w.map((e,t)=>e.kind===`waiting`?(0,h.jsx)(dme,{project:e.project,primary:t===0},e.project.id):e.kind===`paused`?(0,h.jsx)(pme,{project:e.project,primary:t===0},e.project.id):e.kind===`held`?(0,h.jsx)(fme,{schedule:e.schedule,primary:t===0},e.schedule.id):(0,h.jsx)(mme,{project:e.project,primary:t===0},e.project.id))})]}),(0,h.jsxs)(`section`,{id:`running`,"aria-label":`Running now`,children:[(0,h.jsx)(H,{title:`Running now`,info:`home.running`,meta:p.length===0?`Nothing is running`:`${String(p.length)} ${p.length===1?`video`:`videos`}`}),p.length===0?T||g.length>0?null:(0,h.jsx)(a0,{title:`Start the next video`,children:`Pick a template and a topic on Play, or let a schedule start one.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:p.slice(0,3).map(e=>(0,h.jsx)(jme,{project:e,now:l},e.id))}),(0,h.jsx)(bme,{running:p.length,queued:g})]})]}),(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`section`,{"aria-label":`Coming up`,children:[(0,h.jsx)(H,{title:`Coming up`,info:`home.coming-up`,meta:`Next 7 days`,children:(0,h.jsx)(pS,{to:`/calendar`,children:`Calendar`})}),o.error===null?C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading…`:`No scheduled runs this week. Plan some on the calendar.`}):(0,h.jsx)(ime,{runs:C.slice(0,6)}):(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The calendar didn't load: ${o.error.message} Reload the page to try again.`})]}),(0,h.jsxs)(`section`,{"aria-label":`Ready to upload`,children:[(0,h.jsx)(H,{title:`Ready to upload`,info:`home.ready`,meta:x.length===0?`Finished videos you haven't marked uploaded show here`:`${String(x.length)} finished and not marked uploaded`}),x.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:x.slice(0,F3).map(e=>(0,h.jsx)(vme,{project:e},e.id))})]}),(0,h.jsxs)(`section`,{"aria-label":`This week`,children:[(0,h.jsx)(H,{title:`This week`,info:`home.this-week`,meta:`Since Monday`}),(0,h.jsx)(Nme,{channelId:t.channelId})]})]})]})]})}function R3({className:e,...t}){return(0,h.jsx)(`input`,{"data-slot":`input`,className:L(`h-8 w-full min-w-0 rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,`placeholder:text-ink-3 aria-invalid:border-danger`,e),...t})}var Lme={written:``,spoken:``,wholeWord:!0,caseSensitive:!1};function Rme(){let{api:e}=z(),t=_(),n=N(ab(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)({}),[s,c]=(0,m.useState)(),l=(0,m.useRef)(0),u=(0,m.useId)(),d=e=>e.map(e=>(l.current+=1,{...e,key:l.current}));(0,m.useEffect)(()=>{r===void 0&&n.data!==void 0&&i(d(n.data.aliases))});let f=r??[],p=P({mutationFn:t=>Bs(e,t),onSuccess:async e=>{if(!e.ok){let t={};for(let n of e.fields){let e=/^aliases\.(\d+)/u.exec(n.field)?.[1];e!==void 0&&(t[Number(e)]=n.message)}o(t),c({text:`Not saved: ${e.fields.map(e=>e.message).join(` `)}`,tone:`error`});return}o({}),i(d(e.value.aliases)),c({text:`Saved. New projects use these aliases; a project you already started keeps its copy until you refresh it in Edit project.`,tone:`success`}),await t.invalidateQueries({queryKey:B.narrationAliases})},onError:e=>c({text:`Couldn't save the aliases: ${e.message}`,tone:`error`})});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(B4,{action:(0,h.jsxs)(R,{type:`button`,onClick:()=>{l.current+=1,i([...f,{...Lme,key:l.current}]),c(void 0)},disabled:r===void 0,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add alias`]}),children:(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Words the narrator says differently, like Dr. as Doctor.`,(0,h.jsx)(V,{id:`library.aliases`})]})}),n.error===null?null:(0,h.jsxs)(SI,{tone:`danger`,title:`Couldn't load the aliases`,className:`mb-6`,children:[n.error.message,` Reload the page to try again.`]}),(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsx)(t0,{label:`Aliases`,children:r===void 0?null:f.length===0?(0,h.jsx)(a0,{title:`No aliases yet`,children:`Use Add alias to say a word differently from how it is written.`}):(0,h.jsx)(zme,{rows:f,errors:a,idPrefix:u,update:(e,t)=>{i(f.map(n=>n.key===e?{...n,...t}:n)),c(void 0)},remove:e=>{i(f.filter(t=>t.key!==e)),o({}),c(void 0)}})}),(0,h.jsx)(t0,{as:`aside`,label:`How aliases are used`,children:(0,h.jsxs)(`section`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(H,{title:`How they are used`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`The narrator reads the alias instead of the written word. The article, the captions and the PDF keep the written word.`}),(0,h.jsx)(`p`,{className:`m-0 mb-3`,children:`A project takes a copy of this list when it starts and uses it while Use narration aliases is on. A project you already started keeps its copy until you refresh it in Edit project.`}),(0,h.jsx)(`p`,{className:`m-0`,children:`Whole word skips matches inside longer words; Match case only matches the exact capitals.`})]})})]}),(0,h.jsx)($1,{status:(0,h.jsx)(Q1,{tone:s?.tone??`info`,children:s?.text}),children:(0,h.jsx)(R,{type:`button`,variant:`primary`,disabled:r===void 0||p.isPending,onClick:()=>p.mutate(f.map(({written:e,spoken:t,wholeWord:n,caseSensitive:r})=>({written:e,spoken:t,wholeWord:n,caseSensitive:r}))),children:p.isPending?`Saving…`:`Save aliases`})})]})}function zme({rows:e,errors:t,idPrefix:n,update:r,remove:i}){return(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-4 gap-y-1 pb-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Written`,(0,h.jsx)(V,{id:`library.aliases.written`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Say it as`,(0,h.jsx)(V,{id:`library.aliases.spoken`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Whole word`,(0,h.jsx)(V,{id:`library.aliases.whole-word`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[`Match case`,(0,h.jsx)(V,{id:`library.aliases.match-case`})]})]}),(0,h.jsx)(pU,{label:`Narration aliases`,children:e.map((e,a)=>{let o=`${n}-${e.key}`,s=t[a],c=e.written.trim(),l=e.spoken.trim();return(0,h.jsx)(mU,{title:`Alias ${String(a+1)}`,meta:c===``||l===``?`Not filled in yet`:`Says ${c} as ${l}${e.wholeWord?` · whole word`:``}${e.caseSensitive?` · match case`:``}`,actions:(0,h.jsx)(wy,{size:`small`,label:`Remove alias ${String(a+1)}`,onClick:()=>i(e.key),children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto_auto] md:items-end`,children:[(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-written`,children:[`Written`,(0,h.jsx)(R3,{id:`${o}-written`,value:e.written,placeholder:`Dr.`,maxLength:200,"aria-invalid":s!==void 0,"aria-describedby":s===void 0?void 0:`${o}-error`,onChange:t=>r(e.key,{written:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`grid gap-1 text-label text-ink-2`,htmlFor:`${o}-spoken`,children:[`Say it as`,(0,h.jsx)(R3,{id:`${o}-spoken`,value:e.spoken,placeholder:`Doctor`,maxLength:500,"aria-invalid":s!==void 0,onChange:t=>r(e.key,{spoken:t.target.value})})]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.wholeWord,onChange:t=>r(e.key,{wholeWord:t.target.checked})}),`Whole word`]}),(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-accent`,checked:e.caseSensitive,onChange:t=>r(e.key,{caseSensitive:t.target.checked})}),`Match case`]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${o}-error`,className:`m-0 text-small text-danger md:col-span-4`,children:s})]})},e.key)})})]})}function z3(e){return dq(e).names}function Bme(e,t){let n=z3(e),r=Object.create(null);for(let[e,i]of Object.entries(t))r[e]=n.includes(e)?``:i;return r}function Vme(e){return{...e,form:{...e.form,values:Bme(e.form.title,e.form.values)},variants:[]}}function B3({onDefaults:e}){let{api:t}=z(),n=_(),r=N({queryKey:H1.firstRun,queryFn:()=>fde(t),retry:!1,staleTime:1/0}),i=r.data?.defaults;(0,m.useEffect)(()=>{i!==void 0&&(vN(i),e?.(i))},[i,e]);let a=P({mutationFn:()=>pde(t),onSuccess:()=>n.invalidateQueries({queryKey:H1.firstRun})}),o=r.data;if(o===void 0||!o.firstRun||o.message===null)return null;let s=o.detected.filter(e=>e.usable);return(0,h.jsxs)(SI,{title:o.message,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:a.isPending,onClick:()=>a.mutate(),children:`Got it`}),children:[o.detail===null?null:(0,h.jsx)(`p`,{className:`m-0`,children:o.detail}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0`,children:[`Found:`,` `,s.map(e=>`${e.displayName}${e.version===void 0?``:` ${e.version}`}`).join(`, `)]}),a.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:a.error.message}):null]})}function V3(){let{api:e}=z(),{document:t}=rP(),n=N(Hq(e)),r=t.templateSource,i=n.data?.find(e=>e.id===r?.id);return t.channelId??(i===void 0?`00000000-0000-4000-8000-000000000001`:o0(i))}function H3(){let{api:e}=z();return N(Qb(e,V3())).data?.cast??[]}function Hme({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),{document:i}=n,a=V3(),o=r.data?.find(e=>e.id===a),s=i.form.useBrandKit!==!1,c=e=>{n.edit(e),n.invalidateReview(!0)};return(0,h.jsxs)(`div`,{className:`sl-fields items-end`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,children:(0,h.jsxs)(TV,{"data-play-field":`channelId`,value:a,disabled:e,onChange:e=>c({...i,channelId:e.target.value}),children:[r.data===void 0?(0,h.jsx)(`option`,{value:a,children:`Loading channels…`}):null,(r.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsx)(kb,{label:`Use the channel's brand kit`,tip:`play.brand-kit`,checked:s,disabled:e,className:`min-h-[38px]`,onChange:e=>{let{useBrandKit:t,...n}=i.form;c({...i,form:e?n:{...n,useBrandKit:!1}})}}),o?(0,h.jsxs)(`p`,{className:`sl-fields__wide m-0 text-small text-ink-3`,children:[(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:o.id},className:`underline`,children:[`Edit `,o.name]}),s?``:` · its cast is still used`]}):null]})}function U3(){let{api:e}=z(),{document:t}=rP(),n=N(Zb(e)),r=V3(),i=n.data?.find(e=>e.id===r);return t.form.language??i?.brand.language??`en`}function Ume({disabled:e=!1}){let{api:t}=z(),n=rP(),r=N(Zb(t)),i=V3(),a=r.data?.find(e=>e.id===i),{document:o}=n;return(0,h.jsx)(`div`,{children:(0,h.jsx)(k2,{value:o.form.language,inherited:{label:`Channel's language`,language:a?.brand.language},disabled:e,onChange:e=>{let{language:t,...r}=o.form;n.edit({...o,form:e===void 0?r:{...r,language:e}}),n.invalidateReview(!0)}})})}var W3=[{stage:`audio`,label:`Audio`},{stage:`images`,label:`Images`},{stage:`video`,label:`Video / export`}];function Wme(e,t){if(e===`reviews`||e.startsWith(`reviews.`))return{section:`review`,field:e};if(e!==`checkpoints`&&!e.startsWith(`checkpoints.`))return;let n=e.slice(12),r=/^\d+$/.test(n)?t.checkpoints?.[Number(n)]:n;return{section:`review`,field:W3.some(e=>e.stage===r)?`checkpoints.${r}`:`checkpoints`}}function Gme({problem:e}){let t=rP(),{document:n,review:r}=t,{form:i}=n,a=(0,m.useId)(),o=i.checkpoints??[];return(0,h.jsxs)(`fieldset`,{"data-play-field":`checkpoints`,tabIndex:-1,"aria-invalid":e(`checkpoints`)!==void 0,disabled:r.starting||r.uncertain,className:`min-w-0 rounded-media border border-line px-3 pt-1 pb-2`,...Ob,children:[(0,h.jsxs)(`legend`,{className:`flex items-center gap-1 px-1 font-semibold`,children:[`Review checkpoints`,(0,h.jsx)(V,{id:`play.checkpoints`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-6`,children:W3.map(({stage:r,label:s})=>{let c=o.includes(r),l=r===`video`?i.sources.video!==`off`&&i.sources.images!==`off`||i.sources.audio!==`off`:i.sources[r]===`generate`,u=e(`checkpoints.${r}`),d=`${a}-${r}`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`label`,{htmlFor:d,className:`flex min-h-10 items-center gap-3 max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:d,type:`checkbox`,"data-play-field":`checkpoints.${r}`,"aria-invalid":u!==void 0,"aria-describedby":`${d}-detail`,checked:c,disabled:!l&&!c,className:`size-4 accent-accent`,onChange:e=>{let a=e.target.checked?[...o,r]:o.filter(e=>e!==r);t.edit({...n,form:{...i,checkpoints:a}}),t.invalidateReview(!0)}}),`Before `,s]}),(0,h.jsx)(`p`,{id:`${d}-detail`,className:u||c&&!l?`pl-7 text-small text-danger`:`sr-only`,children:u??(l?`Approval required before this step and its dependents run.`:c?`This step is unavailable. Remove its checkpoint or enable the step.`:r===`video`?`Enable Video or Audio to review before export.`:`Choose Generate for ${s} to add this checkpoint.`)})]},r)})}),e(`checkpoints`)?(0,h.jsx)(`p`,{className:`text-small text-danger`,children:e(`checkpoints`)}):null]})}function G3({id:e,value:t,disabled:n,className:r,field:i,onChange:a}){let{api:o}=z(),s=N(ib(o)).data?.themes??[],c=t?.custom,l=c===void 0?void 0:s.find(e=>e.id===c.id),u=c!==void 0&&(l===void 0||l.name!==c.name||JSON.stringify(l.values)!==JSON.stringify(c.values)),d=c===void 0&&JS(t)===`dicemaster`,f=c===void 0?`builtin:${JS(t)}`:u?`kept`:`custom:${c.id}`;return(0,h.jsxs)(DV,{id:e,"data-play-field":i,className:r,disabled:n,value:f,onChange:e=>{let n=e.target.value;if(n===`kept`)return;if(n.startsWith(`builtin:`)){let e=WS.find(e=>`builtin:${e}`===n);e!==void 0&&a({theme:e});return}let r=s.find(e=>`custom:${e.id}`===n);r!==void 0&&a({theme:JS(t),custom:{id:r.id,name:r.name,values:r.values}})},children:[(0,h.jsxs)(`optgroup`,{label:`Built in`,children:[WS.map(e=>(0,h.jsx)(`option`,{value:`builtin:${e}`,children:qS[e]},e)),d?(0,h.jsx)(`option`,{value:`builtin:${GS}`,children:`${qS[GS]} (retired, this project's look)`}):null]}),s.length===0&&!u?null:(0,h.jsxs)(`optgroup`,{label:`Your themes`,children:[u?(0,h.jsx)(`option`,{value:`kept`,children:`${c.name} (this project's copy)`}):null,s.map(e=>(0,h.jsx)(`option`,{value:`custom:${e.id}`,children:u&&l?.id===e.id?`${e.name} (current version)`:e.name},e.id))]})]})}function K3({label:e,field:t,hideLabel:n=!1,value:r,options:i,className:a,tip:o,onPick:s}){let c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:L(`inline-flex items-center gap-3`,a),...o===void 0?{}:Ob,children:[(0,h.jsx)(X4,{id:c,className:n?`sr-only`:`shrink-0`,children:e}),(0,h.jsx)(Z4,{type:`single`,value:r,"aria-labelledby":c,onValueChange:e=>{let t=i.find(t=>t.value===e);t!==void 0&&t.disabled!==!0&&s(t.value)},children:i.map(e=>(0,h.jsx)(Q4,{value:e.value,"data-play-field":e.value===r?t:void 0,disabled:e.disabled===!0,children:e.label},e.value))}),o===void 0?null:(0,h.jsx)(V,{id:o,label:e,className:`-ml-1`})]})}function q3({value:e,onPick:t,rawCounts:n}){let r=e.words??500,i=e.characters??3e3,a=e.mode===`words`||e.mode===`characters`,o=e.mode===`characters`,s=o?e.characters:e.words;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(K3,{field:`chunking.mode`,label:`Chunking`,tip:`play.chunking`,className:`min-w-0 max-w-full flex-wrap [&_[data-slot=toggle-group]]:max-w-full [&_[data-slot=toggle-group]]:flex-wrap`,value:e.mode,options:[{value:`whole`,label:`Whole`},{value:`paragraph`,label:`Paragraph`},{value:`words`,label:`Every ${String(n?.words??r)} words`},{value:`characters`,label:`Every ${String(n?.characters??i)} characters`}],onPick:e=>{if(n){n.onChange(e,e===`characters`?n.characters:n.words);return}t(e===`words`?{mode:e,words:r}:e===`characters`?{mode:e,characters:i}:{mode:e})}}),a?(0,h.jsx)(PV,{label:o?`Characters`:`Words`,tip:`play.chunking.count`,problem:void 0,children:({id:r})=>(0,h.jsx)(CV,{id:r,"data-play-field":o?`chunking.characters`:`chunking.words`,type:n?`text`:`number`,min:1,max:o?1e6:1e4,inputMode:`numeric`,className:`sl-input--number`,value:n?o?n.characters:n.words:s===void 0?``:String(s),onChange:r=>{if(n){n.onChange(e.mode,r.target.value);return}let i=Number.parseInt(r.target.value,10),a=Number.isFinite(i)&&i>0;t(o?a?{mode:`characters`,characters:Math.min(i,1e6)}:{mode:`characters`}:a?{mode:`words`,words:Math.min(i,1e4)}:{mode:`words`})}})}):null]})}var J3=1;function Y3({prompts:e,picked:t,problem:n,onPick:r,rawNumbers:i}){let a=(0,m.useId)(),o=t.reduce((e,t)=>e+t.number,0),s=t.filter(t=>!e.some(e=>e.name===t.name)),c=[...e.map(e=>({name:e.name,missing:!1})),...s.map(e=>({name:e.name,missing:!0}))];return c.length===0?(0,h.jsx)(`p`,{className:`sl-fields__wide basis-full text-small text-ink-3`,children:`No image prompts saved. Write one on Prompts.`}):(0,h.jsxs)(`div`,{className:`sl-fields__wide flex w-full basis-full flex-col gap-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{id:a,className:`engraved text-ink-3`,children:`Image prompts`}),(0,h.jsx)(V,{id:`play.image-prompts`,className:`-my-1`})]}),(0,h.jsx)(`ul`,{"aria-labelledby":a,className:`m-0 grid w-full list-none grid-cols-[repeat(auto-fill,minmax(min(100%,15rem),1fr))] gap-x-6 gap-y-2 p-0`,children:c.map(e=>{let a=t.findIndex(t=>t.name===e.name),o=a===-1?void 0:t[a];return(0,h.jsxs)(`li`,{children:[e.missing?(0,h.jsx)(`span`,{className:`block text-label text-danger`,children:`Missing template · untick to remove`}):null,(0,h.jsx)(Kme,{name:e.name,number:o?.number,rawNumber:i?{value:i.values.find(t=>t.name===e.name)?.number??``,onChange:t=>i.onChange(e.name,t)}:void 0,problem:a===-1?void 0:n(`imagePrompts.${String(a)}.number`),onTick:n=>{r(n?[...t,{name:e.name,number:J3}]:t.filter(t=>t.name!==e.name))},onNumber:n=>{r(t.map(t=>t.name===e.name?{name:t.name,number:n}:t))}})]},e.name)})}),t.length===0?null:(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:Number.isFinite(o)?`${String(o)} of 60 images`:`Complete image counts to see the total`})]})}function Kme({name:e,number:t,problem:n,onTick:r,onNumber:i,rawNumber:a}){let o=(0,m.useId)(),s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex w-full min-w-0 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:o,"data-play-field":`imagePrompts`,type:`checkbox`,checked:t!==void 0,className:`size-[14px] shrink-0 accent-accent`,onChange:e=>{r(e.target.checked)}}),(0,h.jsx)(`label`,{htmlFor:o,title:e,className:L(`min-w-0 flex-1 truncate`,t===void 0?`text-ink-3`:`text-ink`),children:e}),(0,h.jsx)(X4,{htmlFor:s,className:`sr-only`,children:`Number for ${e}`}),(0,h.jsx)(CV,{id:s,"data-play-field":`imagePrompts.${e}.number`,type:a?`text`:`number`,min:J3,max:20,inputMode:`numeric`,disabled:t===void 0,"aria-invalid":n!==void 0,"aria-describedby":n===void 0?void 0:c,className:`sl-input--number`,value:a?.value??(t===void 0||t===0?``:String(t)),onChange:e=>{if(a){a.onChange(e.target.value);return}let t=Number.parseInt(e.target.value,10);i(Number.isFinite(t)?t:0)}}),n===void 0?null:(0,h.jsx)(`span`,{id:c,className:`text-label text-danger`,children:n})]})}var qme=`text-small text-ink-2 file:mr-3 file:h-8 file:rounded-control file:border file:border-line-strong file:bg-raised file:px-3 file:text-ink`;function X3({label:e,field:t,value:n,placeholder:r,problem:i,tip:a,onChange:o}){let s=(0,m.useId)(),c=(0,m.useId)();return(0,h.jsxs)(`div`,{...a===void 0?{}:Ob,children:[(0,h.jsxs)(`span`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:s,children:e}),a===void 0?null:(0,h.jsx)(V,{id:a,label:e,className:`-my-1`})]}),(0,h.jsx)(wV,{id:s,"data-play-field":t,rows:6,value:n,placeholder:r,"aria-invalid":i!==void 0,"aria-describedby":i===void 0?void 0:c,onChange:e=>{o(e.target.value)}}),i===void 0?null:(0,h.jsx)(`p`,{id:c,className:`mt-1 text-label text-danger`,children:i})]})}function Z3({label:e,field:t,accept:n,multiple:r=!1,disabled:i=!1,uploads:a,problem:o,numbered:s=!1,onPick:c,onRemove:l,onReattach:u}){let d=(0,m.useId)(),f=(0,m.useId)();return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(X4,{htmlFor:d,className:`mb-1`,children:e}),(0,h.jsx)(`input`,{id:d,"data-play-field":t,type:`file`,accept:n,multiple:r,disabled:i,"aria-invalid":o!==void 0,"aria-describedby":o===void 0?void 0:f,className:qme,onChange:e=>{c([...e.target.files??[]]),e.target.value=``}}),o===void 0?null:(0,h.jsx)(`p`,{id:f,className:`mt-1 text-label text-danger`,children:o}),a.length===0?null:(0,h.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,children:a.map((e,t)=>(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3`,children:[s?(0,h.jsx)(`span`,{className:`engraved w-6 text-ink-3`,children:String(t+1)}):null,(0,h.jsx)(Jme,{upload:e}),e.error!==void 0&&u?(0,h.jsxs)(`label`,{className:`text-small text-ink-2`,children:[`Reattach`,(0,h.jsx)(`input`,{"aria-label":`Reattach ${e.name}`,className:`max-w-full`,type:`file`,accept:n,onChange:t=>{let n=t.target.files?.[0];t.target.value=``,n&&u(e.key,n)}})]}):null,l===void 0?null:(0,h.jsx)(R,{variant:`quiet`,className:`ml-auto`,"aria-label":`Remove ${e.name}`,onClick:()=>{l(e.key)},children:`Remove`})]},e.key))})]})}function Jme({upload:e}){return(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-3 text-small [overflow-wrap:anywhere]`,children:[(0,h.jsx)(`span`,{className:e.error===void 0?`text-ink`:`text-danger`,children:e.name}),e.error===void 0?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:e.file===void 0?`Copying`:`Staged`}):(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.error})]})}var Q3=`col-span-3 min-w-0 sl-fields`,$3=`col-span-3 min-w-0`;function e6({kind:e,name:t,dim:n,titled:r=!0,children:i}){return(0,h.jsxs)(`section`,{"data-tour":`play-${e}`,className:`grid grid-cols-[24px_1fr_auto] items-center gap-x-2 gap-y-4 border-b border-line py-4 [&>div:empty]:hidden`,children:[r?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(sS,{kind:e,className:n?`text-ink-3`:`text-ink-2`}),(0,h.jsx)(`h3`,{className:L(`m-0 text-title-3`,n?`text-ink-3`:void 0),children:t})]}):(0,h.jsx)(`span`,{className:`sl-field__label col-span-2`,children:`Source`}),i]})}var Yme={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`};function t6({kind:e,form:t,update:n}){return(0,h.jsx)(K3,{field:`sources.${e}`,label:`${e} source`,hideLabel:!0,tip:Yme[e],className:`max-[700px]:col-span-3 max-[700px]:justify-self-start [&_[data-slot=toggle-group]]:flex-wrap`,value:t.sources[e],options:FN(e).filter(n=>e!==`thumbnail`||n.value!==`prompt_by_llm`||t.sources.article!==`off`).map(n=>({...n,disabled:e===`video`&&n.value===`generate`&&t.sources.images===`off`})),onPick:r=>{if(e===`article`&&r===`off`){n(Xme(t));return}n({sources:{...t.sources,[e]:r,...e===`images`&&r===`off`?{video:`off`}:{}}})}})}function n6(e,t){return e.filter(e=>e.kind===t).map(e=>({value:e.name,label:e.name}))}function Xme(e){return{sources:{...e.sources,article:`off`,research:`off`,audio:`off`,document:`off`,...e.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}},subtitles:{...e.subtitles,mode:`off`},youtubeDescription:!1,...e.shorts===void 0?{}:{shorts:{...e.shorts,enabled:!1}}}}function Zme(e){let t=this;t.compiler=n;function n(n){return yle(n,{...t.data(`settings`),...e,extensions:t.data(`toMarkdownExtensions`)||[]})}}var r6=QR().use(vR).use(Zme).freeze(),i6=`[ˈˌ]?[abdefghijklmnoprstuvwxzæðŋθɑɒɔəɚɛɜɝɡɪɹʃʊʌʒʔɫɾ][\\u0303\\u031a\\u0325\\u0329\\u032a\\u032c\\u032f\\u035c\\u0361ʰʲʷ]*[ːˑ]?`,Qme=RegExp(`^(?:${i6})+(?:\\.(?:${i6})+)*$`,`u`),a6=`[ˈˌ]?[a-zæçðøħŋœɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɪɫɬɭɮɯɰɱɲɳɴɵɶɸɹɺɻɽɾʀʁʂʃʄʈʉʊʋʌʍʎʏʐʑʒʔʕʙʛʜʝʟʡʢβθχ][\\u0300-\\u036fʰʱʲʷʼˠˤ˞]*[ːˑ]?`,$me=RegExp(`^(?:${a6})+(?:\\.(?:${a6})+)*$`,`u`);function o6(e){return e.type===`break`?`
278
+ `:e.value??e.children?.map(o6).join(``)??``}function s6(e){if(e.type===`heading`){let t=o6(e).trim();return/^pronunciation glossary:?\s*$/iu.test(t)?[]:[t]}return e.type===`table`?(e.children??[]).slice(1).map(e=>{let t=e.children??[];if(t.length<2)return o6(e);let[n,r]=t.slice(0,2).map(e=>o6(e).trim());return`${n}: ${r!==void 0&&r!==``&&!r.includes(`/`)?`/${r}/`:r}`}):e.type===`paragraph`?o6(e).split(/\r?\n/u):e.type===`root`||e.type===`list`||e.type===`listItem`?(e.children??[]).flatMap(s6):[`(unsupported glossary block)`]}function ehe(e){return Array.from(e,e=>{let t=e.toLowerCase(),n=t.toUpperCase().toLowerCase();if(n===e)return e;let r=RegExp(`^${e.replace(/[|\\{}()[\]^$+*?.]/gu,`\\$&`)}$`,`iu`);return r.test(n)?n:r.test(t)?t:e}).join(``)}function c6(e,t){let n=t===void 0||t===`en`,r=n?Qme:$me,i=n?`standard-English IPA`:`IPA`,a=s6(r6().use(pB).parse(e)),o=new Map,s=[];for(let[e,t]of a.entries()){let a=t=>{s.push({row:e+1,reason:t})},c=t.trim();if(c===``||/^pronunciation glossary:?\s*$/iu.test(c))continue;let l=/^([^:]+):\s*(.+)$/u.exec(c),u=l?.[1]?.trim().replace(/\s+/gu,` `),d=l?.[2];if(u===void 0||d===void 0||!/[\p{L}\p{N}]/u.test(u)||/[/[\]<>\p{Cc}]/u.test(u)){a(`use Term: /IPA/ or a Term | IPA table`);continue}let f=/^(\/[^/]+\/(?:\s+\/[^/]+\/)*)(?:\s+[^/]+)?$/u.exec(d);if(f?.[1]===void 0){a(`use slash-delimited ${i}`);continue}let p=Array.from(f[1].matchAll(/\/([^/]+)\//gu)).flatMap(e=>(e[1]??``).trim().split(/\s+/u));if(p.length===0||p.some(e=>!r.test(e))){a(n?`use standard-English IPA only, not ARPAbet, delivery tags or non-English sounds; give a foreign name an English approximation`:`use IPA, not ARPAbet or delivery tags`);continue}if(u.split(` `).length!==p.length){a(`supply one IPA word for each written word`);continue}let m=ehe(u),h=o.get(m);if(h!==void 0&&h.ipa.join(` `)!==p.join(` `)){a(`an earlier entry already gives this term a different pronunciation`);continue}h===void 0&&o.set(m,{term:u,ipa:p})}return s.length===0?{ok:!0,entries:[...o.values()]}:{ok:!0,entries:[...o.values()],skipped:s}}function the(e,t){return e.flatMap(e=>{if(!e.pronunciations?.trim())return[];let n=c6(e.pronunciations,t),r=n.ok?n.skipped??[]:[];return r.length===0?[]:[{speaker:e.name.trim()||`A speaker`,skipped:r}]})}function nhe(e,t){let n=t?.turns.find(t=>t.speaker===e.id)?.text??rhe(e);if(n.length<=200)return n;let r=n.slice(0,200),i=Math.max(r.lastIndexOf(`. `),r.lastIndexOf(`? `),r.lastIndexOf(`! `));return i>60?r.slice(0,i+1):`${r.slice(0,r.lastIndexOf(` `))}…`}function rhe(e){let t=e.name.trim()||`your speaker`;switch(e.role){case`narrator`:return`The night was quiet, and the old house held its breath. I'm ${t}, and I'll be telling this story.`;case`host`:return`Hi everyone, I'm ${t}, and welcome back to the show. Today's topic is a good one.`;case`guest`:return`Thanks for having me. I'm ${t}, and I've been looking forward to this conversation.`;case`character`:return`You really thought I wouldn't find out? My name is ${t}, and I always find out.`}}function ihe(e){return e.flatMap(e=>e.host===!0&&e.voice!==void 0?[l6(e,`host`)]:[])}function ahe(e){let t=e.toLowerCase();return/^[a-z0-9-]{1,55}$/.test(t)?`cast-${t}`:`cast-h${ohe(e)}`}function ohe(e){let t=3735928559,n=1103547991;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,2654435761),n=Math.imul(n^i,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(4294967296*(2097151&n)+(t>>>0)).toString(36)}function l6(e,t){let n=e.voice;return{id:ahe(e.id),name:e.name.slice(0,40),role:t,voice:n===void 0?{provider:``,model:``,voice:``}:{provider:n.provider,model:n.model,voice:n.voice},...n?.pace===void 0||n.pace===1?{}:{pace:n.pace},...n?.pronunciations?.trim()?{pronunciations:n.pronunciations}:{},castId:e.id,...she(e)}}function she(e){let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null)?.sha256;return t==null?{}:{portrait:t}}var che=/^#{1,6}\s+(.+?)\s*#*\s*$/,lhe=/^\*{0,2}([^:*\n]{1,60}?)\*{0,2}\s*:\s*\*{0,2}\s*(.*)$/;function u6(e,t,n=!1){let r=new Map(t.map(e=>[e.name.trim().toLowerCase(),e])),i=t.map(e=>e.name.trim()).join(`, `),a=[],o=[],s=!1;for(let[t,n]of e.replace(/\r\n?/g,`
279
279
  `).split(`
280
- `).entries()){let e=n.trim(),c=t+1;if(e===``){s=!1;continue}let l=she.exec(e);if(l!==null){o.push({title:d6(l[1]??``),firstTurn:a.length+1}),s=!1;continue}if(/^([-*_=~])\1{2,}$/.test(e)){s=!1;continue}let u=che.exec(e),d=u===null?void 0:r.get((u[1]??``).trim().toLowerCase());if(u!==null&&d!==void 0){a.push({speaker:d.id,lines:[u[2]??``],section:o.length-1}),s=!0;continue}let f=a.at(-1);if(s&&f!==void 0){f.lines.push(e);continue}return{ok:!1,reason:u===null?`Line ${String(c)} of the script is not a turn. Start every turn with a speaker's name and a colon (${i}), one turn per paragraph.`:`Line ${String(c)} of the script is spoken by "${(u[1]??``).trim()}", who is not one of the speakers (${i}). Use only these names, or add the speaker under Speakers (Play → Narration, or Edit project → Providers).`}}let c=[];for(let e of a){let t=d6(e.lines.join(` `));t!==``&&c.push({index:c.length+1,speaker:e.speaker,text:t,section:e.section,...n?{markdown:e.lines.join(`
281
- `)}:{}})}if(c.length===0)return{ok:!1,reason:`The script has no spoken turns. Write each turn as a speaker's name, a colon and their words (${i}).`};let l=[],u=new Map;for(let[e,t]of o.entries()){let n=c.find(t=>t.section===e);n!==void 0&&t.title!==``&&(u.set(e,l.length),l.push({title:t.title,firstTurn:n.index}))}return{ok:!0,script:{turns:c.map(e=>({...e,section:u.get(e.section)??-1})),sections:l}}}function d6(e){return e.replace(/\[[^\]]*\]\([^)]*\)/g,e=>e.slice(1,e.indexOf(`]`))).replace(/\[[^\]]*\]/g,` `).replace(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g,`$2`).replace(/`/g,``).replace(/\s+/g,` `).trim()}var lhe={narrator:`Narrator`,host:`Host`,guest:`Guest`,character:`Character`};function f6({value:e,onChange:t,providers:n,voices:r,script:i,problem:a,cast:o=[],language:s}){let c=(0,m.useMemo)(()=>{if(e===void 0||i===void 0||i.trim()===``)return;let t=u6(i,e.speakers);return t.ok?t.script:void 0},[i,e]),l=n=>{if(n===``){t(void 0);return}let r=EA.find(e=>e===n);r!==void 0&&t(e===void 0?zA(r,rhe(o)):{...e,format:r,source:r===`audiobook`?e.source:`script`})},u=n=>{e!==void 0&&t({...e,...n})},d=o.filter(t=>t.voice!==void 0&&!(e?.speakers??[]).some(e=>e.castId===t.id)),f=(t,n)=>{e!==void 0&&u({speakers:e.speakers.map((e,r)=>r===t?n:e)})};return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-3`,"data-play-field":`voices`,children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(FV,{field:`voices.format`,label:`Format`,tip:`play.speakers.format`,value:e?.format??``,placeholder:`Narration (one voice)`,options:EA.map(e=>({value:e,label:DA[e]})),problem:a?.(`voices.format`),onPick:l}),e?.format===`audiobook`?(0,h.jsx)(FV,{field:`voices.source`,label:`Script`,tip:`play.speakers.script`,value:e.source,placeholder:`Pick where the script comes from`,options:[{value:`script`,label:`Write a script (Script prompt)`},{value:`attribute`,label:`Split the article into speakers`}],problem:a?.(`voices.source`),onPick:e=>u({source:e===`attribute`?`attribute`:`script`})}):null]}),e===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`One voice reads the article. Pick a format for an audiobook, podcast, radio drama or interview with several speakers.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.source===`script`?"The article prompt must be a Script prompt: the text model writes speaker turns, one `Name: words` paragraph each.":`The article is written or pasted as usual; the text model then hands its narration and dialogue to the speakers.`}),a?.(`voices.speakers`)===void 0?null:(0,h.jsx)(`p`,{className:`text-label text-danger`,children:a(`voices.speakers`)}),(0,h.jsx)(`ol`,{"aria-label":`Speakers`,className:`divide-y divide-line border-y border-line`,children:e.speakers.map((t,i)=>(0,h.jsx)(phe,{index:i,speaker:t,line:the(t,c),providers:n,voices:r,language:s,problem:a,onChange:e=>f(i,e),onRemove:e.speakers.length>1?()=>u({speakers:e.speakers.filter((e,t)=>t!==i)}):void 0},t.id))}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsx)(R,{type:`button`,disabled:e.speakers.length>=10,onClick:()=>u({speakers:[...e.speakers,fhe(e.speakers)]}),children:`Add speaker`}),(0,h.jsx)(FV,{label:`Add from the cast`,tip:`play.speakers.add-from-cast`,value:``,placeholder:d.length===0?`No cast member has a voice yet`:`Pick one of ${String(d.length)}`,options:d.map(e=>({value:e.id,label:e.name})),disabled:d.length===0||e.speakers.length>=10,problem:void 0,onPick:t=>{let n=d.find(e=>e.id===t);n!==void 0&&u({speakers:[...e.speakers,l6(n,dhe(e))]})}}),(0,h.jsx)(FV,{field:`voices.turnGapSeconds`,label:`Gap between turns`,tip:`play.speakers.turn-gap`,value:String(e.turnGapSeconds),placeholder:`Pick a gap`,options:jA.map(e=>({value:String(e),label:`${e} s`})),problem:a?.(`voices.turnGapSeconds`),onPick:e=>u({turnGapSeconds:Number(e)})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{label:`Speaker names on captions`,tip:`play.speakers.name-tags`,checked:e.nameTags,onChange:e=>u({nameTags:e})}),(0,h.jsx)(kb,{label:`One request for consecutive turns where the voice provider can (ElevenLabs v3, Gemini)`,tip:`play.speakers.native-dialogue`,checked:e.nativeDialogue,onChange:e=>u({nativeDialogue:e})}),(0,h.jsx)(kb,{label:`Also make MP3 and M4B files with chapter markers`,tip:`play.speakers.audio-files`,checked:e.audioFiles,onChange:e=>u({audioFiles:e})})]}),e.format===`audiobook`?(0,h.jsx)(uhe,{value:e,onChange:t,problem:a}):null,e.format===`podcast`||e.format===`interview`?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The speaker panel (a tile per speaker, the one talking lit, their name below) is drawn with the captions: set Captions to Burn in under Style to see it in the video.`}):null]})]})}function uhe({value:e,onChange:t,problem:n}){let r=e.book,i=n=>t({...e,...n});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(kb,{label:`A chapter of a book`,tip:`play.speakers.book`,checked:r!==void 0,onChange:n=>{if(n)i({book:{title:``,chapter:1}});else{let{book:n,...r}=e;t(r)}}}),r===void 0?null:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-[minmax(0,1fr)_160px]`,children:[(0,h.jsx)(xV,{label:`Book title`,tip:`play.speakers.book-title`,error:n?.(`voices.book.title`),children:(0,h.jsx)(CV,{value:r.title,maxLength:200,onChange:e=>i({book:{...r,title:e.target.value}})})}),(0,h.jsx)(xV,{label:`Chapter`,tip:`play.speakers.book-chapter`,error:n?.(`voices.book.chapter`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:FA,step:1,value:r.chapter===0?``:String(r.chapter),onChange:e=>i({book:{...r,chapter:Number(e.target.value)||0}})})})]})]})}function dhe(e){return e.format===`podcast`?`host`:e.format===`interview`?e.speakers.some(e=>e.role===`host`)?`guest`:`host`:e.speakers.some(e=>e.role===`narrator`)?`character`:`narrator`}function fhe(e){let t=e.length+1;for(;e.some(e=>e.id===`speaker-${String(t)}`);)t+=1;return{id:`speaker-${String(t)}`,name:`Speaker ${String(t)}`,role:`character`,voice:{provider:``,model:``,voice:``}}}function phe({index:e,speaker:t,line:n,providers:r,voices:i,language:a,problem:o,onChange:s,onRemove:c}){let l=`voices.speakers.${String(e)}`,u=t.voice,d=i.filter(e=>e.provider===u.provider),f=F2(d,a,u.voice||void 0),p=a===void 0?d:f.listed,g=t.name.trim()||`this speaker`,_=(0,m.useMemo)(()=>ehe([t],a??`und`)[0]?.skipped??[],[t,a]);return(0,h.jsxs)(`li`,{className:`grid grid-cols-1 gap-3 py-3 min-[700px]:grid-cols-2`,"data-play-field":l,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-end gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`mb-2 size-3 shrink-0 rounded-full`,style:{background:`var(--color-speaker-${String(e%6+1)})`}}),(0,h.jsx)(xV,{label:`Speaker name`,tip:`play.speaker.name`,error:o?.(`${l}.name`),className:`min-w-0 flex-1`,children:(0,h.jsx)(CV,{value:t.name,maxLength:40,onChange:e=>s({...t,name:e.target.value})})})]}),(0,h.jsx)(FV,{label:`Role`,tip:`play.speaker.role`,value:t.role,placeholder:`Pick a role`,options:OA.map(e=>({value:e,label:lhe[e]})),problem:void 0,onPick:e=>{let n=OA.find(t=>t===e);n!==void 0&&s({...t,role:n})}}),(0,h.jsx)(RV,{field:`${l}.voice`,label:`Voice provider`,tip:`play.speaker.provider`,family:`tts`,providers:r,value:u.provider,problem:o?.(`${l}.voice`),onPick:e=>s({...t,voice:{provider:e,model:``,voice:``}})}),(0,h.jsx)(zV,{label:`Voice model`,tip:`play.speaker.model`,provider:u.provider,value:u.model,problem:void 0,onPick:e=>s({...t,voice:{...u,model:e}})}),(0,h.jsx)(FV,{field:`${l}.voice.voice`,label:`Voice`,tip:`play.speaker.voice`,value:u.voice,placeholder:p.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:p.map(e=>({value:e.voiceId,label:e.name})),problem:o?.(`${l}.voice.voice`),onPick:e=>s({...t,voice:{...u,voice:e}})}),a===void 0?null:(0,h.jsx)(I2,{language:a,voice:d.find(e=>e.voiceId===u.voice),hidden:f.hidden,showAll:f.showAll,onShowAll:f.setShowAll}),(0,h.jsx)(FV,{field:`${l}.pace`,label:`Pace`,tip:`play.speaker.pace`,value:String(t.pace??1),placeholder:`Pick a pace`,options:AA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:o?.(`${l}.pace`),onPick:e=>{let{pace:n,...r}=t;s(Number(e)===1?r:{...r,pace:Number(e)})}}),(0,h.jsxs)(`details`,{className:`col-span-full text-small`,...Ob,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-ink-2`,children:[`Pronunciations for `,t.name.trim()||`this speaker`,t.pronunciations?.trim()?` · set`:``,(0,h.jsx)(V,{id:`play.speaker.pronunciations`})]}),(0,h.jsx)(wV,{rows:3,"aria-label":`Pronunciations for ${t.name.trim()||`this speaker`}`,value:t.pronunciations??``,placeholder:`Arda: /ˈɑɹdə/`,onChange:e=>{let{pronunciations:n,...r}=t;s(e.target.value===``?r:{...r,pronunciations:e.target.value})}})]}),_.length===0?null:(0,h.jsxs)(SI,{tone:`waiting`,className:`col-span-full`,title:`${String(_.length)} ${_.length===1?`pronunciation`:`pronunciations`} for ${g} ${_.length===1?`is`:`are`} skipped`,children:[(0,h.jsx)(`ul`,{children:_.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsxs)(`p`,{children:[`Those words are read as ordinary text; the other entries are used. Fix them in Pronunciations for `,g,` above: one `,(0,h.jsx)(`code`,{children:`Term: /IPA/`}),` per line.`]})]}),(0,h.jsxs)(`div`,{className:`col-span-full flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(hhe,{speaker:t,line:n}),(0,h.jsx)(`span`,{className:`flex-1`}),c===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:c,children:[`Remove `,t.name.trim()||`speaker`]})]})]})}var mhe=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:4});function hhe({speaker:e,line:t}){let{api:n}=z(),{provider:r,model:i,voice:a}=e.voice,o=r!==``&&i!==``&&a!==``,s=N({queryKey:[`audition-quote`,r,i,t],queryFn:()=>Us(n,[{speaker:e.name.trim()||`Speaker`,provider:r,model:i,text:t}]),enabled:o,staleTime:6e4}),[c,l]=(0,m.useState)(void 0);(0,m.useEffect)(()=>()=>{c!==void 0&&URL.revokeObjectURL(c)},[c]);let u=P({mutationFn:()=>Ws(n,{provider:r,model:i,voice:a,text:t}),onSuccess:e=>{let t=URL.createObjectURL(e);l(t),new Audio(t).play().catch(()=>{})}}),d=s.data?.estimate,f=d==null?void 0:d.unknown>0?`price unknown`:`about ${mhe.format(d.high)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:!o||u.isPending,onClick:()=>u.mutate(),title:`Reads: ${t}`,children:u.isPending?`Speaking…`:`Audition${f===void 0?``:` · ${f}`}`}),(0,h.jsx)(V,{id:`play.speaker.audition`})]}),(0,h.jsx)(`span`,{className:`min-h-5 text-label text-ink-2`,"aria-live":`polite`,children:o?u.error===null?c===void 0?`Reads their first line: “${t.length>60?`${t.slice(0,60)}…`:t}”`:`Playing the audition.`:u.error.message:`Pick a provider, model and voice to audition.`})]})}function ghe(e){return e===void 0?`Narration`:DA[e]}function p6({value:e,skipCode:t,onChange:n,tip:r=`play.describe-figures`}){let i=(0,m.useId)(),a=e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.describeFigures`,checked:a,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:e.currentTarget.checked,skipCode:t===!0})}),`Describe tables and figures in the narration`]}),(0,h.jsx)(V,{id:r})]}),a?(0,h.jsxs)(`span`,{className:`flex items-center gap-1 pl-7`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-code`,className:`flex min-h-10 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-code`,type:`checkbox`,"data-play-field":`audio.skipCode`,checked:t===!0,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:!0,skipCode:e.currentTarget.checked})}),`Leave code out`]}),(0,h.jsx)(V,{id:`play.skip-code`})]}):null]})}function m6({value:e,onChange:t,tip:n=`play.show-figures`}){let r=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`showFigures`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Show tables and figures on screen`]}),(0,h.jsx)(V,{id:n})]})}function h6({value:e,onChange:t,note:n}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`audio.useNarrationAliases`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Use narration aliases`]}),(0,h.jsx)(V,{id:`play.narration-aliases`})]}),n===void 0?null:(0,h.jsx)(`div`,{className:`pl-7`,children:n})]})}function g6({value:e,prompts:t,supported:n,error:r,libraryLinks:i=!0,onChange:a}){let o=(0,m.useId)(),s=t.filter(e=>e.kind===`narration`),c=s.find(t=>t.name===e),l=r??(e!==``&&!n?`Choose Inworld TTS-2 or turn preparation Off.`:void 0);return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:o,className:`text-small font-semibold`,children:`Narration Preparation`}),(0,h.jsx)(V,{id:`play.narration-preparation`})]}),(0,h.jsxs)(DV,{id:o,"data-play-field":`narrationPrompt`,value:e,"aria-describedby":l?`${o}-error`:void 0,"aria-invalid":l!==void 0||void 0,onChange:e=>a(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),e!==``&&c===void 0?(0,h.jsxs)(`option`,{value:e,children:[e,` (saved selection)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`text-small text-danger`,children:l}):null,i?(0,h.jsxs)(`div`,{className:`flex gap-4 text-small`,children:[(0,h.jsx)(ha,{to:`/prompts/new`,search:{kind:`narration`},children:`Create prompt`}),c?(0,h.jsx)(ha,{to:`/prompts/$promptId`,params:{promptId:c.id},children:`View prompt`}):null]}):null]})}function _6({value:e,supported:t,onChange:n,shared:r}){let i=(0,m.useId)(),a=t&&e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.usePronunciationGlossary`,checked:e===!0,disabled:!t,"aria-describedby":t?void 0:`${i}-support`,className:`size-4 accent-accent`,onChange:e=>n(e.currentTarget.checked)}),`Use Pronunciation Glossary`]}),(0,h.jsx)(V,{id:`play.pronunciation-glossary`})]}),r===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-1 pl-7`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-shared`,className:`flex min-h-8 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-shared`,type:`checkbox`,"data-play-field":`audio.shareGlossary`,checked:r.value===!0,disabled:!a,className:`size-4 accent-accent`,onChange:e=>r.onChange(e.currentTarget.checked)}),`Also use pronunciations from my other projects`]}),(0,h.jsx)(V,{id:`play.share-glossary`})]}),r.note===void 0?null:r.note]}),t?null:(0,h.jsx)(`p`,{id:`${i}-support`,className:`text-label text-ink-3`,children:`Unavailable for this provider or model. Your saved preference is retained.`})]})}var v6={source:`off`,prompt:``,thumbnail:!0},_he=[{value:`prompt`,label:`From a prompt`},{value:`provide`,label:`Upload`}];function y6({value:e,prompts:t,problem:n,upload:r,prompt:i,onChange:a}){let o=(0,m.useId)(),s=e.source===`off`,c=t.filter(e=>e.kind===`image`).map(e=>({value:e.name,label:e.name}));return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsx)(`div`,{className:`min-w-0`,children:(0,h.jsx)(FV,{field:`reference.source`,label:`Establishing image`,tip:`play.reference`,value:s?``:e.source,placeholder:`Off`,options:_he,problem:n?.(`reference.source`),onPick:t=>a({...e,source:t===`prompt`||t===`provide`?t:`off`})})}),e.source===`provide`?(0,h.jsx)(`div`,{className:`min-w-0`,children:r}):i??(0,h.jsx)(FV,{field:`reference.prompt`,label:`Establishing prompt`,tip:`play.reference.prompt`,value:e.prompt,placeholder:s?`Off`:`Pick an image prompt`,options:c,disabled:s,problem:n?.(`reference.prompt`),onPick:t=>a({...e,prompt:t})}),(0,h.jsxs)(`div`,{className:`col-span-full flex min-h-9 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:o,className:`flex cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{id:o,type:`checkbox`,"data-play-field":`reference.thumbnail`,checked:e.thumbnail,disabled:s,onChange:t=>a({...e,thumbnail:t.target.checked})}),`Draw the thumbnail from it too`]}),(0,h.jsx)(V,{id:`play.reference.thumbnail`})]})]})}function b6({choice:e,onChange:t,field:n=`llm.thinking`,label:r=`Thinking`,tip:i=`play.llm.thinking`,problem:a}){let{api:o}=z(),s=N(AV(o,e.provider)).data?.models.find(t=>t.id===e.model)?.thinkingModes??[];if(!s.length&&!e.thinking)return null;let c=r===`Thinking`?`thinking level`:r.toLowerCase();return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(FV,{field:n,label:r,tip:i,value:e.thinking??`default`,placeholder:`Model default`,problem:e.thinking&&!s.includes(e.thinking)?`Choose a supported ${c}.`:a,options:[{value:`default`,label:`Model default`},...e.thinking&&!s.includes(e.thinking)?[{value:e.thinking,label:`${e.thinking} (saved level)`}]:[],...s.map(e=>({value:e,label:e===`off`?`Off`:e.charAt(0).toUpperCase()+e.slice(1)}))],onPick:n=>{let r=s.find(e=>e===n),{thinking:i,...a}=e;t(r===void 0?a:{...a,thinking:r})}}),r===`Thinking`&&s.length&&!s.includes(`off`)?(0,h.jsx)(`p`,{className:`mt-1 text-small text-ink-3`,children:`This model does not support turning thinking off.`}):null]})}function vhe({form:e,prompts:t,providers:n,voices:r,problem:i,update:a,onPickFiles:o,onRemoveFile:s,onReattachFile:c,rawCounts:l,advanced:u,cast:d,language:f,titled:p}){let g=r.filter(t=>t.provider===e.audio.provider),_=F2(g,f??`en`,e.audio.voice||void 0),v=f===void 0?g:_.listed,y=e.voices?.speakers.find(e=>e.voice.provider&&e.voice.model&&e.voice.voice)?.voice,b=e.intro!==``||e.outro!==``,x=e.voices!==void 0&&!b&&y!==void 0;(0,m.useEffect)(()=>{if(!x||y===void 0)return;let t=e.audio;(t.provider!==y.provider||t.model!==y.model||t.voice!==y.voice)&&a({audio:{...t,provider:y.provider,model:y.model,voice:y.voice}})},[x,y,e.audio,a]);let S=e.voices!==void 0,C=[e.chunking.mode,e.intro?`intro ${e.intro}`:void 0,e.outro?`outro ${e.outro}`:void 0,e.narrationPrompt?`preparation on`:void 0,e.audio.usePronunciationGlossary?`glossary on`:void 0].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(e6,{kind:`audio`,name:`Audio`,dim:e.sources.audio===`off`,titled:p,children:[(0,h.jsx)(t6,{kind:`audio`,form:e,update:a}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[x?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`audio.provider`,label:S?`Intro and outro TTS`:`TTS`,tip:`play.tts.provider`,family:`tts`,providers:n,value:e.audio.provider,problem:i(`audio`),onPick:t=>{a({audio:{...e.audio,provider:t,model:``,voice:``}})}}),(0,h.jsx)(zV,{field:`audio.model`,label:`TTS model`,tip:`play.tts.model`,provider:e.audio.provider,value:e.audio.model,problem:i(`audio.model`),onPick:t=>a({audio:{...e.audio,model:t}})}),(0,h.jsx)(FV,{field:`audio.voice`,label:S?`Intro and outro voice`:`Voice`,tip:`play.voice`,value:e.audio.voice,placeholder:v.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:v.map(e=>({value:e.voiceId,label:e.name})),problem:i(`audio.voice`),onPick:t=>{a({audio:{...e.audio,voice:t}})}}),f===void 0?null:(0,h.jsx)(I2,{language:f,voice:g.find(t=>t.voiceId===e.audio.voice),hidden:_.hidden,showAll:_.showAll,onShowAll:_.setShowAll}),S?(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`This voice reads only the intro and outro. Each speaker's voice is set under Speakers.`}):null]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Speakers ·`,` `,e.voices===void 0?`Narration, one voice`:`${ghe(e.voices.format)}, ${String(e.voices.speakers.length)} ${e.voices.speakers.length===1?`speaker`:`speakers`}`]}),(0,h.jsx)(`div`,{className:`pt-2 pb-3`,children:(0,h.jsx)(f6,{value:e.voices,providers:n,voices:r,script:e.sources.article===`provide`?e.provided.article:void 0,problem:i,cast:d,language:f,onChange:e=>a({voices:e})})})]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Audio Advanced · `,C]}),(0,h.jsxs)(`div`,{className:`sl-fields pt-2 pb-3`,children:[(0,h.jsx)(`div`,{className:`col-span-full`,children:(0,h.jsx)(q3,{...l?{rawCounts:l}:{},value:e.chunking,onPick:e=>{a({chunking:e})}})}),u,(0,h.jsx)(g6,{value:e.narrationPrompt??``,prompts:t,supported:e.audio.provider===`inworld`&&e.audio.model===`inworld-tts-2`,error:i(`narrationPrompt`),onChange:e=>a({narrationPrompt:e})}),(0,h.jsx)(_6,{value:e.audio.usePronunciationGlossary,supported:Sj({sources:e.sources,audio:{...e.audio,usePronunciationGlossary:!0}}),onChange:t=>a({audio:{...e.audio,usePronunciationGlossary:t}}),shared:{value:e.audio.shareGlossary??!0,onChange:t=>a({audio:{...e.audio,shareGlossary:t}})}}),(0,h.jsx)(h6,{value:e.audio.useNarrationAliases,onChange:t=>a({audio:{...e.audio,useNarrationAliases:t}})}),(0,h.jsx)(p6,{value:e.audio.describeFigures,skipCode:e.audio.skipCode,onChange:t=>a({audio:{...e.audio,...t}})})]})]})]}):null}),e.sources.audio===`provide`?(0,h.jsxs)(`div`,{className:$3,children:[(0,h.jsx)(Z3,{field:`provided.audio`,label:`Narration file`,accept:`audio/*`,uploads:e.provided.audio===void 0?[]:[e.provided.audio],problem:i(`provided.audio`),onPick:e=>{o(`audio`,e)},onReattach:c?(e,t)=>c(`audio`,e,t):void 0,onRemove:e=>{s(`audio`,e)}}),(0,h.jsx)(`p`,{className:`mt-2 text-small text-ink-2`,children:`Uploaded narration is used as-is; include any intro and outro in that file.`})]}):null]})}function yhe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawNumbers:c,more:l,titled:u}){return(0,h.jsxs)(e6,{kind:`images`,name:`Images`,dim:e.sources.images===`off`,titled:u,children:[(0,h.jsx)(t6,{kind:`images`,form:e,update:i}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.images===`generate`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}),(0,h.jsx)(Y3,{prompts:n.filter(e=>e.kind===`image`),...c?{rawNumbers:c}:{},picked:e.imagePrompts,problem:r,onPick:e=>{i({imagePrompts:e})}}),(0,h.jsx)(bhe,{form:e,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s?{onReattachFile:s}:{}}),l]}):null}),e.sources.images===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.images`,label:`Slideshow images`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,numbered:!0,uploads:e.provided.images,problem:r(`provided.images`),onPick:e=>{a(`images`,e)},onReattach:s?(e,t)=>s(`images`,e,t):void 0,onRemove:e=>{o(`images`,e)}})}):null]})}function x6({form:e,providers:t,problem:n,update:r}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`images.provider`,label:`Provider`,tip:`play.images.provider`,family:`image`,providers:t,value:e.images.provider,problem:n(`images`),onPick:e=>r({images:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`images.model`,label:`Model`,tip:`play.images.model`,provider:e.images.provider,value:e.images.model,problem:n(`images.model`),onPick:t=>r({images:{...e.images,model:t}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:e.images,problem:n(`images.thinking`),onChange:e=>r({images:e})})]})}function bhe({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsx)(y6,{value:e.reference??v6,prompts:t,problem:n,onChange:e=>r({reference:e}),upload:(0,h.jsx)(Z3,{field:`provided.reference`,label:`Establishing image file`,accept:`image/png,image/jpeg`,uploads:e.provided.reference===void 0?[]:[e.provided.reference],problem:n(`provided.reference`),onPick:e=>{i(`reference`,e)},onReattach:o?(e,t)=>o(`reference`,e,t):void 0,onRemove:e=>{a(`reference`,e)}})})}var S6=5e3,xhe=[`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(`
282
- `),She=`Built-in`;function C6({enabled:e,prompt:t,prompts:n,narrated:r,problem:i,onChange:a}){let o=(0,m.useId)(),s=n.filter(e=>e.kind===`description`),c=t!==``&&!s.some(e=>e.name===t),l=i?.(`youtubeDescription`)??i?.(`descriptionPrompt`);return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1 self-end`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${o}-switch`,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${o}-switch`,type:`checkbox`,"data-play-field":`youtubeDescription`,checked:e,disabled:!r&&!e,"aria-describedby":l?`${o}-error`:void 0,className:`size-4 accent-accent`,onChange:e=>a({youtubeDescription:e.currentTarget.checked,descriptionPrompt:t})}),`YouTube description`]}),(0,h.jsx)(V,{id:`play.youtube-description`})]}),(0,h.jsx)(WV,{htmlFor:`${o}-prompt`,label:`Description prompt`,tip:`play.description-prompt`,children:(0,h.jsxs)(DV,{id:`${o}-prompt`,"data-play-field":`descriptionPrompt`,value:t,disabled:!e,onChange:t=>a({youtubeDescription:e,descriptionPrompt:t.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:She}),c?(0,h.jsxs)(`option`,{value:t,children:[t,` (saved choice)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`sl-fields__wide m-0 text-small text-danger`,children:l}):r?null:(0,h.jsx)(`p`,{className:`sl-fields__wide m-0 text-label text-ink-3`,children:`Needs narration.`})]})}function w6({value:e,narrated:t,imageProvider:n,problem:r,onChange:i,fieldPrefix:a=`videoEdit`,language:o}){let s=(0,m.useId)(),c=e??fA,l=e=>i({...c,...e}),{api:u}=z(),d=N(jV(u,n,c.animate!==`off`)),f=e=>r?.(`${a}.${e}`),p=[c.transition===`cut`?void 0:`${_A[c.transition]} ${String(c.transitionSeconds)} s`,c.grade===`none`?void 0:yA[c.grade],c.atmosphere===`none`?void 0:bA[c.atmosphere],c.vignette===`off`?void 0:`Vignette`,c.grain===`off`?void 0:`Grain`,c.chapterCards?`Chapter cards`:void 0,c.animate===`off`?void 0:`Animated images`].filter(e=>e!==void 0),g=[`transition`,`transitionSeconds`,`chapterCards`,`animate`,`animateEvery`,`animateModel`].map(f).filter(e=>e!==void 0),_=d.data?.models??[],v=c.animateModel!==``&&!_.some(e=>e.id===c.animateModel),y=VO(o);return{cuts:(0,h.jsxs)(T6,{id:`${s}-cuts`,label:`Cuts`,tip:`project.video.cuts`,children:[(0,h.jsx)(DV,{id:`${s}-cuts`,"data-play-field":`${a}.cuts`,className:`min-w-0`,value:y===void 0?c.cuts:`interval`,disabled:y!==void 0,"aria-describedby":y===void 0?void 0:`${s}-cuts-note`,onChange:e=>l({cuts:e.target.value}),children:oA.map(e=>(0,h.jsx)(`option`,{value:e,children:gA[e]},e))}),y===void 0?null:(0,h.jsx)(`p`,{id:`${s}-cuts-note`,className:`m-0 basis-full text-small text-ink-3`,children:y})]}),look:(0,h.jsxs)(`details`,{className:`group min-w-0 rounded-control border border-line-strong`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-10 cursor-pointer items-center gap-3 px-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Look`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-ink-3`,children:p.length===0?`Plain cuts, no effects`:p.join(` · `)})]}),(0,h.jsxs)(`div`,{className:`sl-fields border-line-strong border-t p-3`,children:[(0,h.jsxs)(T6,{id:`${s}-transition`,label:`Transition`,tip:`project.video.transition`,children:[(0,h.jsx)(DV,{id:`${s}-transition`,"data-play-field":`${a}.transition`,className:`min-w-0`,value:c.transition,onChange:e=>l({transition:e.target.value}),children:sA.map(e=>(0,h.jsx)(`option`,{value:e,children:_A[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Transition length`,"data-play-field":`${a}.transitionSeconds`,"aria-invalid":f(`transitionSeconds`)!==void 0,className:`w-24 flex-none`,disabled:c.transition===`cut`,value:String(c.transitionSeconds),onChange:e=>l({transitionSeconds:Number(e.target.value)}),children:hA.map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[e,` s`]},e))})]}),(0,h.jsx)(T6,{id:`${s}-grade`,label:`Colour grade`,tip:`project.video.grade`,children:(0,h.jsx)(E6,{id:`${s}-grade`,field:`${a}.grade`,value:c.grade,options:lA,labels:yA,onChange:e=>l({grade:e})})}),(0,h.jsx)(T6,{id:`${s}-vignette`,label:`Vignette`,tip:`project.video.vignette`,children:(0,h.jsx)(E6,{id:`${s}-vignette`,field:`${a}.vignette`,value:c.vignette,options:cA,labels:vA,onChange:e=>l({vignette:e})})}),(0,h.jsx)(T6,{id:`${s}-grain`,label:`Film grain`,tip:`project.video.grain`,children:(0,h.jsx)(E6,{id:`${s}-grain`,field:`${a}.grain`,value:c.grain,options:cA,labels:vA,onChange:e=>l({grain:e})})}),(0,h.jsx)(T6,{id:`${s}-atmosphere`,label:`Atmosphere`,tip:`project.video.atmosphere`,children:(0,h.jsx)(E6,{id:`${s}-atmosphere`,field:`${a}.atmosphere`,value:c.atmosphere,options:uA,labels:bA,onChange:e=>l({atmosphere:e})})}),(0,h.jsx)(T6,{id:`${s}-cards`,label:`Chapter cards`,tip:`project.video.chapter-cards`,children:(0,h.jsx)(`input`,{id:`${s}-cards`,type:`checkbox`,"data-play-field":`${a}.chapterCards`,className:`size-4 accent-accent`,checked:c.chapterCards,disabled:!t&&!c.chapterCards,onChange:e=>l({chapterCards:e.currentTarget.checked})})}),(0,h.jsxs)(T6,{id:`${s}-animate`,label:`Animate images`,tip:`project.video.animate`,wide:!0,children:[(0,h.jsx)(DV,{id:`${s}-animate`,"data-play-field":`${a}.animate`,"aria-invalid":f(`animate`)!==void 0,className:`min-w-0`,value:c.animate,onChange:e=>l({animate:e.target.value}),children:dA.map(e=>(0,h.jsx)(`option`,{value:e,disabled:e===`chapters`&&!t,children:xA[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Animate every how many images`,"data-play-field":`${a}.animateEvery`,"aria-invalid":f(`animateEvery`)!==void 0,className:`w-24 flex-none`,disabled:c.animate!==`every`,value:String(c.animateEvery),onChange:e=>l({animateEvery:Number(e.target.value)}),children:Array.from({length:9},(e,t)=>t+2).map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[`every `,e]},e))}),(0,h.jsxs)(DV,{"aria-label":`Image-to-video model`,"data-play-field":`${a}.animateModel`,"aria-invalid":f(`animateModel`)!==void 0,className:`min-w-0`,disabled:c.animate===`off`,value:c.animateModel,onChange:e=>l({animateModel:e.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a model`}),v?(0,h.jsxs)(`option`,{value:c.animateModel,children:[c.animateModel,` (saved choice)`]}):null,_.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),g.length>0?(0,h.jsx)(`p`,{className:`col-span-full text-small text-danger`,children:g[0]}):c.animate!==`off`&&d.isSuccess&&_.length===0?(0,h.jsx)(`p`,{className:`col-span-full text-label text-ink-3`,children:`This image provider has no image-to-video models. Choose fal.ai or Replicate for images to animate them.`}):null]})]})}}function T6({id:e,label:t,tip:n,wide:r=!1,children:i}){return(0,h.jsxs)(`div`,{className:L(`sl-field`,r&&`sl-fields__wide`),...Ob,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),(0,h.jsx)(V,{id:n,label:t.toLowerCase()})]}),(0,h.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-start gap-2 [&>select]:min-w-0 [&>select]:flex-1`,children:i})]})}function E6({id:e,field:t,value:n,options:r,labels:i,onChange:a}){return(0,h.jsx)(DV,{id:e,"data-play-field":t,className:`min-w-0`,value:n,onChange:e=>a(e.target.value),children:r.map(e=>(0,h.jsx)(`option`,{value:e,children:i[e]},e))})}var Che=rO(`kind`,[q({kind:pO(`upload`),stagedFileId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`output`),outputId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`picture`),sha256:W().regex(/^[a-f0-9]{64}$/)})]),D6=q({format:J(PS),subtitles:q({mode:J(fM),fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/),fontSize:G().finite().min(16).max(120),position:J(pM)}),videoEdit:yM.optional(),previewText:W().max(200).optional(),image:Che.optional(),shorts:q({titleOnScreen:GD(),speed:G().finite().min(1).max(1.25).optional(),title:W().max(100).optional()}).optional(),force:GD().optional()}),whe=q({hash:W().regex(/^[a-f0-9]{64}$/),url:W().min(1),cached:GD(),seconds:G().positive()});async function The(e,t,n){let r=await e.fetch(`${e.origin}/api/style-preview`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),...n===void 0?{}:{signal:n}});if(!r.ok)throw await fo(r);let i=So(whe,await r.json());return{...i,src:`${e.origin}${i.url}`}}var Ehe=600;function O6({settings:e,label:t,drawnOn:n,poster:r}){let{api:i}=z(),a=N({queryKey:sN,queryFn:()=>cN(i),staleTime:6e4}),{format:o,subtitles:s,videoEdit:c,previewText:l,image:u,shorts:d}=e,f=r??(u?.kind===`picture`?ux(i,u.sha256):void 0),p=u===void 0?``:JSON.stringify(u),g=d===void 0?``:JSON.stringify(d),_=(0,m.useMemo)(()=>JSON.stringify({format:o,subtitles:{mode:s.mode,fontId:s.fontId,fontSize:s.fontSize,position:s.position},...c===void 0?{}:{videoEdit:c},...l===void 0||l.trim()===``?{}:{previewText:l},...p===``?{}:{image:JSON.parse(p)},...g===``?{}:{shorts:JSON.parse(g)}}),[o,s.mode,s.fontId,s.fontSize,s.position,c,l,p,g]),v=(0,m.useMemo)(()=>D6.safeParse(JSON.parse(_)).success,[_]),[y,b]=(0,m.useState)({kind:`idle`}),[x,S]=(0,m.useState)(void 0),C=(0,m.useRef)(void 0),w=(0,m.useCallback)(async e=>{C.current?.abort();let t=new AbortController;C.current=t,b({kind:`pending`});try{let n=await The(i,{...D6.parse(JSON.parse(_)),...e?{force:e}:{}},t.signal);if(C.current!==t)return;S(n.src),b({kind:`ready`,src:n.src})}catch(e){if(C.current!==t||t.signal.aborted)return;b({kind:`failed`,message:e instanceof Error&&e.message!==``?e.message:`The style preview couldn't render. Press Render again.`})}},[i,_]);(0,m.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>{w(!1)},Ehe);return()=>clearTimeout(e)},[w,v]),(0,m.useEffect)(()=>()=>C.current?.abort(),[]);let T=a.data?.fonts.find(e=>e.id===s.fontId)?.name??(s.fontId==="default"?`Barlow`:`Chosen font`),E=d===void 0?s.mode===`burn-in`?`Captions: ${T} ${String(s.fontSize)} · ${Dhe(s.position)}`:s.mode===`files`?`Captions: a separate file, which players show in their own style`:`Captions: off`:[`Captions: ${T}, word by word`,d.titleOnScreen?`Title on screen`:`No title on screen`,d.speed===void 0||d.speed===1?void 0:`${d.speed.toFixed(2)}×`].filter(e=>e!==void 0).join(` · `),D=d===void 0?`Style preview`:`Shorts preview`,O=o===`9:16`||d!==void 0;return(0,h.jsxs)(`section`,{"aria-label":D,className:`min-w-0 space-y-3`,children:[(0,h.jsx)(H,{as:`h3`,title:D,meta:d===void 0?`6 seconds of the sample, rendered with your settings`:`A few seconds of the sample as a short, rendered with your settings`,info:d===void 0?`project.video.style-preview`:`play.shorts.preview`,children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:!v||y.kind===`pending`,disabledReason:v?`Rendering the preview…`:`Fix the caption settings to render the preview.`,onClick:()=>{w(!0)},children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,size:16,strokeWidth:1.75}),`Render again`]})}),x===void 0?null:(0,h.jsx)(R0,{src:x,label:t??D,...f===void 0?{}:{poster:f},portrait:O,className:O?`max-w-[270px]`:`max-w-[480px]`}),y.kind===`pending`?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Rendering the preview…`}):null,y.kind===`failed`?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:y.message}):null,v?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The preview renders again once the caption size is between 16 and 120.`}),(0,h.jsxs)(`p`,{className:`text-small text-ink-2`,children:[E,u===void 0||n===void 0?``:` · Drawn on ${n}`]})]})}function Dhe(e){let t=e.replace(/-/g,` `);return`${t[0]?.toUpperCase()??``}${t.slice(1)}`}function Ohe({form:e,problem:t,update:n,onPickFiles:r,onRemoveFile:i,onReattachFile:a}){let o=e.provided.ambientBed;return(0,h.jsx)(A2,{value:e.ambientBed,inherit:`The channel's (brand kit)`,sources:Qk,offerNone:!0,problem:e=>t(`ambientBed.${e}`),file:(0,h.jsx)(Z3,{field:`ambientBed.file`,label:`Ambient sound file: an audio file, looped if shorter than the video`,accept:`audio/*`,uploads:o===void 0?[]:[o],problem:t(`ambientBed.file`),onPick:e=>r(`ambientBed`,e),onReattach:a?(e,t)=>a(`ambientBed`,e,t):void 0,onRemove:e=>i(`ambientBed`,e)}),onChange:e=>n({ambientBed:e})})}function k6({value:e,onChange:t,problem:n,switchTip:r=`project.loudness`,switchLabel:i=`Level the volume`}){return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[(0,h.jsx)(kb,{checked:e.enabled,label:i,tip:r,onChange:n=>t({...e,enabled:n})}),e.enabled?(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(j6,{target:`video`,label:`Video volume`,tip:`project.loudness.video`,lufs:e.videoLufs,error:n?.(`videoLufs`),onChange:n=>t({...e,videoLufs:n})}),(0,h.jsx)(j6,{target:`audioFiles`,label:`Audio files volume`,tip:`project.loudness.audio-files`,lufs:e.audioFilesLufs,error:n?.(`audioFilesLufs`),onChange:n=>t({...e,audioFilesLufs:n})})]}):null]})}var khe=`Enter a volume between ${M6(-10)} dB and ${M6(4)} dB (${String(ck(-10))}% to ${String(ck(4))}%).`;function A6(e,t){let n=e.trim().replace(`−`,`-`).replace(`,`,`.`);if(n===``)return;let r=Number(n.replace(/(dB|%)$/i,``).trim());if(!Number.isFinite(r)||t===`percent`&&r<=0)return;let i=t===`db`?r:lk(r);if(!(i<-10.25||i>4.25))return uk(i)}function j6({target:e,label:t,tip:n,lufs:r,error:i,onChange:a}){let o=(0,m.useId)(),s=ok(r,e),[c,l]=(0,m.useState)(),u=c===void 0||A6(c.text,c.unit)!==void 0,d=(t,n)=>{l({unit:t,text:n});let r=A6(n,t);r!==void 0&&a(sk(r,e))},f=c?.unit===`db`?c.text:M6(s),p=c?.unit===`percent`?c.text:String(ck(s));return(0,h.jsx)(xV,{label:t,tip:n,help:`0 dB is the recommended ${N6(ik(e))} LUFS; this is ${N6(r)} LUFS. Peaks stay under ${N6(ak(e))} dBTP.`,error:u?i:khe,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`loudness.${e===`video`?`videoLufs`:`audioFilesLufs`}`,value:f,onChange:e=>d(`db`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`dB`}),(0,h.jsx)(CV,{id:`${o}-percent`,"aria-label":`${t} as a percentage of the recommended level`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:p,onChange:e=>d(`percent`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`%`})]})})}function M6(e){return e>0?`+${String(e)}`:N6(e)}function N6(e){return String(e).replace(`-`,`−`)}function P6({sentence:e,paragraph:t,problem:n,onChange:r}){let i=`0 to 2 in steps of ${String(yk)}`;return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(xV,{label:`Pause between sentences (seconds)`,tip:`project.pause.sentence`,help:`${i}; ${String(vk)} is the default. 0 leaves the voice's own.`,error:n(`sentencePauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`sentencePauseSeconds`,value:e,onChange:e=>r(`sentencePauseSeconds`,e.target.value)})}),(0,h.jsx)(xV,{label:`Pause between paragraphs (seconds)`,tip:`project.pause.paragraph`,help:`${i}; 0 (the default) keeps the sentence pause.`,error:n(`paragraphPauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`paragraphPauseSeconds`,value:t,onChange:e=>r(`paragraphPauseSeconds`,e.target.value)})})]})}function F6(e){let t=e.trim().replace(`,`,`.`);if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function Ahe({form:e,problem:t,update:n}){let{api:r}=z(),i=N(ob(r)).data?.loudness??tk,a=e.loudness;return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[e.sources.audio===`generate`?(0,h.jsx)(P6,{sentence:e.sentencePause??`0.4`,paragraph:e.paragraphPause??`0`,problem:t,onChange:(e,t)=>n(e===`sentencePauseSeconds`?{sentencePause:t}:{paragraphPause:t})}):null,(0,h.jsx)(k6,{value:{enabled:a?.enabled??i.enabled,videoLufs:a?.videoLufs??i.videoLufs,audioFilesLufs:a?.audioFilesLufs??i.audioFilesLufs},problem:e=>t(`loudness.${e}`),onChange:e=>n({loudness:e})})]})}function I6({value:e,onPick:t,disabled:n=!1}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,...Ob,children:[(0,h.jsx)(X4,{id:r,className:`shrink-0`,children:`Thumbnails`}),(0,h.jsxs)(Z4,{type:`single`,value:String(e),"aria-labelledby":r,disabled:n,"data-play-field":`thumbnailCount`,onValueChange:e=>{(e===`1`||e===`3`)&&t(e===`3`?3:1)},children:[(0,h.jsx)(Q4,{value:`1`,children:`1`}),(0,h.jsx)(Q4,{value:`3`,children:`3`})]}),(0,h.jsx)(V,{id:`play.thumbnail-count`})]})}function jhe({form:e,problem:t,update:n}){return(0,h.jsxs)(e6,{kind:`research`,name:`Research`,dim:e.sources.research===`off`,children:[(0,h.jsx)(t6,{kind:`research`,form:e,update:n}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.research===`generate`?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:`Runs through the LLM, one agent per chapter`}):null}),e.sources.research===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.research`,label:`Research notes`,tip:`play.provided.research`,value:e.provided.research,placeholder:`Paste the notes the article will be written from.`,problem:t(`provided.research`),onChange:t=>{n({provided:{...e.provided,research:t}})}})}):null]})}function Mhe({form:e,prompts:t,problem:n,update:r,titled:i}){return(0,h.jsxs)(e6,{kind:`article`,name:`Article`,dim:!1,titled:i,children:[(0,h.jsx)(t6,{kind:`article`,form:e,update:r}),(0,h.jsx)(`div`,{className:`${$3} grid gap-4`,children:e.sources.article===`generate`?(0,h.jsx)(FV,{field:`articlePrompt`,label:UA(e)?`Script prompt`:`Article prompt`,tip:`play.article-prompt`,value:e.articlePrompt,placeholder:`Pick a prompt`,options:n6(t,l0(e)),problem:n(`articlePrompt`),onPick:e=>{r({articlePrompt:e})}}):null}),e.sources.article===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.article`,label:`Article text`,tip:`play.provided.article`,value:e.provided.article,placeholder:`Paste the article that will be narrated.`,problem:n(`provided.article`),onChange:t=>{r({provided:{...e.provided,article:t}})}})}):null]})}function Nhe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s}){let c=e.sources.thumbnail===`from_prompt`||e.sources.thumbnail===`prompt_by_llm`;return(0,h.jsxs)(e6,{kind:`thumbnail`,name:`Thumbnail`,dim:e.sources.thumbnail===`off`,children:[(0,h.jsx)(t6,{kind:`thumbnail`,form:e,update:i}),(0,h.jsxs)(`div`,{className:Q3,children:[c&&e.sources.images!==`generate`?(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}):null,c?(0,h.jsx)(FV,{field:`thumbnailPrompt`,label:`Thumbnail prompt`,tip:`play.thumbnail-prompt`,value:e.thumbnailPrompt,placeholder:`Pick a prompt`,options:n6(n,`thumbnail`),problem:r(`thumbnailPrompt`),onPick:e=>{i({thumbnailPrompt:e})}}):null,c?(0,h.jsx)(I6,{value:e.thumbnailCount===3?3:1,onPick:e=>{i({thumbnailCount:e})}}):null]}),e.sources.thumbnail===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.thumbnail`,label:`Thumbnail image`,accept:`image/png,image/jpeg,image/webp`,uploads:e.provided.thumbnail===void 0?[]:[e.provided.thumbnail],problem:r(`provided.thumbnail`),onPick:e=>{a(`thumbnail`,e)},onReattach:s?(e,t)=>s(`thumbnail`,e,t):void 0,onRemove:e=>{o(`thumbnail`,e)}})}):null]})}function Phe({form:e,prompts:t,silenceGapSeconds:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawTiming:c,extras:l=!0,language:u,titled:d}){let f=e.sources.video===`generate`?e.sources.audio===`off`?`Silent video · each image shown once`:`Images and narration · ${String(n)} s segment gaps`:e.sources.audio===`off`?`Download each enabled stage separately`:`Combined WAV export with narration and segment gaps`,p=t=>({value:c?c[t]:Number.isFinite(e[t])?String(e[t]):``,onChange:e=>{c?c.onChange(t,e):i({[t]:e.trim()===``?NaN:Number(e)})}}),m=w6({value:e.videoEdit,narrated:e.sources.audio!==`off`,imageProvider:e.images.provider,problem:r,language:u??e.language,onChange:e=>i({videoEdit:e})});return(0,h.jsxs)(e6,{kind:`video`,name:`Export`,dim:e.sources.video===`off`,titled:d,children:[(0,h.jsx)(t6,{kind:`video`,form:e,update:i}),(0,h.jsx)(`span`,{className:Q3,children:(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:f})}),e.sources.video===`generate`||e.sources.audio!==`off`?(0,h.jsxs)(`div`,{className:Q3,children:[e.sources.video===`generate`?(0,h.jsx)(R6,{field:`imageSeconds`,label:`Seconds per image`,tip:`play.image-seconds`,step:1,problem:r(`imageSeconds`),...p(`imageSeconds`)}):null,e.sources.video===`generate`?(0,h.jsx)(R6,{field:`zoomPercent`,label:`Zoom (%)`,tip:`play.zoom`,step:.5,problem:r(`zoomPercent`),...p(`zoomPercent`)}):null,e.sources.video===`generate`?(0,h.jsx)(PV,{label:`Motion`,tip:`play.motion`,problem:void 0,children:({id:t})=>(0,h.jsx)(DV,{id:t,"data-play-field":`motionStyle`,className:`w-full`,value:e.motionStyle,onChange:e=>i({motionStyle:e.target.value}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null,e.sources.video===`generate`?m.cuts:null,e.sources.audio===`off`?null:(0,h.jsx)(R6,{field:`edgeSilenceSeconds`,label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,step:.5,problem:r(`edgeSilenceSeconds`),...p(`edgeSilenceSeconds`)})]}):null,e.sources.video===`generate`?(0,h.jsx)(`div`,{className:$3,children:m.look}):null,e.sources.video===`generate`&&e.sources.audio!==`off`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Ohe,{form:e,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s})}):null,e.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Ahe,{form:e,problem:r,update:i})}),l?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(L6,{form:e,prompts:t,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s===void 0?{}:{onReattachFile:s}})}):null,e.sources.images===`off`?(0,h.jsx)(`p`,{className:`${$3} text-small text-ink-2`,children:`Video is Off because Images is Off. Generate or provide images to enable video.`}):null]})}function L6({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[e.sources.audio===`generate`&&e.audio.describeFigures===!0?(0,h.jsx)(m6,{value:e.showFigures,onChange:e=>r({showFigures:e})}):null,e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(C6,{enabled:e.youtubeDescription===!0,prompt:e.descriptionPrompt??``,prompts:t,narrated:e.sources.audio!==`off`,problem:n,onChange:e=>r(e)})}),e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(YV,{value:e.shorts??GV,prompts:t,narrated:e.sources.audio!==`off`,problem:n,musicName:e.provided.shortsMusic?.name,music:(0,h.jsxs)(`div`,{className:`basis-full`,children:[(0,h.jsx)(Z3,{field:`shorts.music`,label:`Background music (optional): an audio file, looped if shorter than a short`,accept:`audio/*`,disabled:!jN(e),uploads:e.provided.shortsMusic===void 0?[]:[e.provided.shortsMusic],problem:n(`shorts.music`),onPick:e=>i(`shortsMusic`,e),onReattach:o?(e,t)=>o(`shortsMusic`,e,t):void 0,onRemove:e=>a(`shortsMusic`,e)}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:`Plays at the volume above under every short and dips while the narrator speaks.`})]}),preview:(0,h.jsx)(O6,{settings:KV(e.shorts??GV,e.subtitles.fontId)}),onChange:e=>r({shorts:e})})})]})}function R6({field:e,label:t,tip:n,placeholder:r,step:i,problem:a,value:o,onChange:s}){return(0,h.jsx)(PV,{label:t,tip:n,problem:a,children:({id:t,describedBy:n})=>(0,h.jsx)(CV,{id:t,"data-play-field":e,type:`text`,inputMode:i<1?`decimal`:`numeric`,className:`sl-input--number`,"aria-invalid":a!==void 0,"aria-describedby":n,placeholder:r,value:o,onChange:e=>s(e.target.value)})})}function Fhe({form:e,update:t}){let n=e.sources.document===`off`;return(0,h.jsxs)(e6,{kind:`document`,name:`Document`,dim:n,children:[(0,h.jsx)(t6,{kind:`document`,form:e,update:t}),(0,h.jsx)(`div`,{className:Q3,children:(0,h.jsx)(PV,{label:`Theme`,tip:`play.document-theme`,problem:void 0,children:({id:r})=>(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(G3,{id:r,field:`document.theme`,className:`w-auto min-w-[120px]`,disabled:n,value:e.document,onChange:e=>{t({document:e})}}),(0,h.jsx)(ha,{to:`/document-themes`,className:`text-small text-accent-ink underline`,children:`Edit themes`})]})})})]})}function Ihe({form:e,providers:t,problem:n,update:r,uses:i,onSettings:a}){let o=[...new Set(i.map(e=>e.label))],s=o.length<=1?o[0]??``:`${o.slice(0,-1).join(`, `)} and ${o.at(-1)??``}`;return(0,h.jsxs)(`section`,{"aria-label":`Text generation`,className:`border-y border-line py-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`Text generation`,meta:`Used for ${s}.`,info:`play.text-generation`,className:`pb-3`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Settings`})}),(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(RV,{field:`llm.provider`,label:`LLM`,tip:`play.llm.provider`,family:`llm`,providers:t,value:e.llm.provider,problem:n(`llm.provider`)??(e.llm.provider===``?n(`llm`):void 0),onPick:e=>r({llm:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`llm.model`,label:`Text model`,tip:`play.llm.model`,provider:e.llm.provider,value:e.llm.model,problem:n(`llm.model`)??(e.llm.provider!==``&&n(`llm`)?`Pick a text model.`:void 0),onPick:t=>r({llm:{...e.llm,model:t}})}),(0,h.jsx)(b6,{choice:e.llm,onChange:e=>r({llm:e})})]})]})}function z6({section:e,entries:t,...n}){let r=IN(n.form,t);return r[0]?.section===e?(0,h.jsx)(Ihe,{...n,uses:r}):null}function Lhe(e){let{form:t,onLibrary:n}=e,r=e.prompts.find(e=>e.kind===l0(t)&&e.name===t.articlePrompt);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mhe,{...e,titled:!1}),t.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3 py-3`,children:[r?(0,h.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`summary`,{"data-play-field":`articlePrompt.preview`,className:`cursor-pointer py-2 text-small text-accent-ink`,children:`View prompt`}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words py-3 font-sans text-body text-ink-2`,children:r.body})]}):(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.prompts.some(e=>e.kind===l0(t))?`Choose a saved ${l0(t)} prompt.`:`No ${l0(t)} prompts saved. Create a prompt to begin.`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>n(`/prompts`),children:`Create prompt`})]}):(0,h.jsxs)(`p`,{className:`py-3 text-small text-ink-3`,children:[t.provided.article.trim()?t.provided.article.trim().split(/\s+/).length:0,` `,`words · `,t.provided.article.length,` characters`]}),(0,h.jsx)(z6,{...e,section:`article`,onSettings:()=>n(`/settings`)}),t.sources.article===`off`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`No article: for a project of images or a thumbnail made from prompts. Narration, the PDF and anything else that reads the article stay off.`}):t.sources.article===`provide`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`Research is Off because the article is provided.`}):(0,h.jsx)(jhe,{...e})]})}function Rhe(){let{api:e}=z(),t=rP(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=Oy(),u=N({queryKey:[`play-drafts`],queryFn:async()=>{let t=await ZM(e);if(!t.ok)throw Error(t.message);return t.value.drafts}}),d=async()=>{if(!r||s)return;let e=r.id;c(!0),o(null);try{await t.discard({id:r.id,version:r.version}),i(null),await n.cancelQueries({queryKey:[`play-drafts`]}),n.setQueryData([`play-drafts`],t=>t?.filter(t=>t.id!==e))}catch(e){let t=e instanceof Error?e.message:`The draft wasn't discarded. Try again.`;o(t),l(t,`error`)}finally{c(!1)}};return(0,h.jsxs)(`section`,{"aria-label":`Drafts`,className:`flex min-w-0 flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(`p`,{role:`status`,className:L(`engraved min-w-[112px] text-right`,t.status===`saved`?`text-accent-ink`:t.status===`error`||t.status===`conflict`?`text-danger`:`text-ink-3`),children:{unsaved:`Unsaved`,saving:`Saving…`,saved:`Saved`,error:`Couldn't save`,conflict:`Changed elsewhere`}[t.status]}),t.status===`error`?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{!t.view&&t.activeId&&t.edited===0?t.open(t.activeId):t.flush()},children:`Retry`}):null,t.status===`conflict`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{t.activeId&&t.open(t.activeId)},children:`Reload saved draft`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void t.saveAsNew(),children:`Save as a new draft`}),(0,h.jsx)(V,{id:`play.draft-conflict`})]}):null,(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,children:[`Drafts`,(0,h.jsx)(uc,{"aria-hidden":`true`,className:`size-4`})]})}),(0,h.jsxs)(Eb,{align:`end`,className:`w-[340px] p-0`,"aria-label":`Saved drafts`,children:[u.isPending?(0,h.jsx)(`p`,{role:`status`,className:`px-3 py-2`,children:`Loading drafts…`}):null,u.error?(0,h.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:[u.error.message,` `,(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void u.refetch(),children:`Retry`})]}):null,u.data?.length===0?(0,h.jsx)(`p`,{className:`px-3 py-2`,children:`No saved drafts`}):null,a?(0,h.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:a}):null,u.data?.length?(0,h.jsx)(pU,{label:`Saved drafts`,className:`max-h-72 overflow-y-auto border-t-0`,children:u.data.map(e=>(0,h.jsx)(mU,{title:e.title||`Untitled draft`,onSelect:()=>void t.open(e.id),meta:(0,h.jsxs)(`time`,{dateTime:e.updatedAt,children:[`Last edited `,ku(e.updatedAt)]}),actions:(0,h.jsx)(wy,{size:`small`,label:`Discard ${e.title||`Untitled draft`}`,onClick:()=>{i(e),o(null)},children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:e.readable?null:(0,h.jsx)(`p`,{className:`m-0 text-label text-waiting`,children:`Unsupported or corrupt draft. Try opening it to recover, or discard it.`})},e.id))}):null]})]}),(0,h.jsx)(R,{onClick:()=>void t.newDraft(),children:`New draft`}),(0,h.jsx)(V,{id:`play.drafts`}),(0,h.jsx)(jy,{open:r!==null,title:`Discard ${r?.title||`Untitled draft`}?`,consequence:`The draft is removed. This cannot be undone.`,confirmLabel:`Discard draft`,pending:s,onConfirm:()=>void d(),onCancel:()=>{s||i(null)}})]})}function B6(e,t){let n=[...e.querySelectorAll(`[data-play-field]`)].find(e=>e.dataset.playField===t);if(!n||n.hasAttribute(`disabled`))return!1;let r=n.closest(`details`);return r!==null&&!r.open&&(r.open=!0),n.focus(),n.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`instant`}),document.activeElement===n}function zhe(e,t,n,r=[]){let i=e;if(e===`fontUpload`&&(i=`subtitles.fontUpload`),/^provided\.images\.\d+$/.test(e)&&(i=`provided.images`),e===`subtitles`&&(i=`subtitles.mode`),e===`chunking`&&(i=`chunking.mode`),[`audio`,`llm`,`images`].includes(e)&&(i=`${e}.provider`),e===`provided`){let e=[`audio`,`images`,`thumbnail`].find(e=>t.sources[e]===`provide`&&(e===`images`?t.provided.images:[t.provided[e]]).some(e=>e&&(e.error!==void 0||e.file===void 0))),n=t.provided.shortsMusic;i=e===void 0&&jN(t)&&n!==void 0&&(n.error!==void 0||n.file===void 0)?`shorts.music`:t.reference?.source===`provide`&&t.provided.reference!==void 0&&(t.provided.reference.error!==void 0||t.provided.reference.file===void 0)?`provided.reference`:`provided.${e??`audio`}`;let r=t.provided.ambientBed;e===void 0&&MN(t)&&r!==void 0&&(r.error!==void 0||r.file===void 0)&&(i=`ambientBed.file`)}let a=/^imagePrompts\.(\d+)\.(.+)$/.exec(e);if(a){let e=t.imagePrompts[Number(a[1])];e&&(i=`imagePrompts.${e.name}.${a[2]}`)}e===`imagePrompts`&&(i=t.imagePrompts[0]?`imagePrompts.${t.imagePrompts[0].name}.number`:`imagePrompts`);let o=/^variants\.(\d+)\.(.+)$/.exec(e);o&&(i=`items.${n[Number(o[1])]?.key??o[1]}.${o[2]}`);let s=/^items\.(\d+)\.(.+)$/.exec(e);s&&(i=Number(s[1])===0?s[2]??e:`items.${n[Number(s[1])-1]?.key??s[1]}.${s[2]}`);let c=t=>t.some(t=>e===t||e.startsWith(`${t}.`));return{section:c([`title`,`articlePrompt`,`provided.article`,`provided.research`,`sources.article`,`sources.research`,...(IN(t,r)[0]?.section??`article`)===`article`?[`llm`]:[],`values`])?`content`:c([`format`,`subtitles`,`fontUpload`])?`style`:c(`audio,narrationPrompt,voices,provided.audio,intro,outro,chunking,images,imagePrompts,imageScale,provided.images,thumbnailPrompt,provided.thumbnail,provided.reference,reference,provided,sources,imageSeconds,zoomPercent,motionStyle,edgeSilenceSeconds,document,youtubeDescription,descriptionPrompt,shorts,videoEdit,ambientBed,loudness,sentencePauseSeconds,paragraphPauseSeconds,llm`.split(`,`))?`outputs`:`review`,field:i}}function Bhe({fields:e,values:t,origins:n,topics:r=[],hide:i=[],problem:a,onChange:o}){let s=e.filter(e=>!i.includes(e.name));return s.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-3 text-small text-ink-2`,children:`Each keyword is entered once and fills every place that names it.`}),(0,h.jsx)(_0,{keywords:s.map(e=>({name:e.name,value:Object.hasOwn(t,e.name)?t[e.name]??``:``,feeds:n?.get(e.name)??[],topic:r.includes(e.name)})),problem:a,onChange:o})]}):null}var Vhe={every:`minutes`,value:`2`};function Hhe({document:e,problem:t,onEdit:n}){let r=(0,m.useId)(),{form:i}=e,a=i.imageScale,o=t(`imageScale.value`)??t(`imageScale`),s=a===void 0?void 0:o===void 0?Whe(e):{text:o,problem:!0},c=t=>{let{imageScale:r,...o}=i;n({...e,form:{...o,...t===void 0?{}:{imageScale:t},...t!==void 0&&a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})};return(0,h.jsxs)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{checked:a!==void 0,label:`More images for long videos`,tip:`play.image-scale`,describedBy:`${r}-line`,onChange:e=>c(e?Vhe:void 0)}),a===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,...Ob,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,tip:`play.image-scale.rate`,value:a.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>c({every:e,value:Uhe(a.value,a.every,e)})}),a.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{id:`${r}-value`,"data-play-field":`imageScale.value`,"aria-label":a.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`sl-input--number`,"aria-invalid":s?.problem===!0,"aria-describedby":`${r}-line`,value:a.value,onChange:e=>c({every:a.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:a.every===`minutes`?`minutes`:`images per hour`})]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:s.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:s.text})]})}function Uhe(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function Whe(e){let{form:t}=e,n=t.imageScale;if(n===void 0)return{text:``,problem:!1};let r=Number(n.value.trim()),i=n.every===`minutes`;if(!(n.value.trim()!==``&&(i?r>=.25&&r<=60:r>=1&&r<=240)))return{text:i?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`,problem:!0};let a=i?YO(r):r,o=t.sources.article===`provide`,s=Number(e.expectedWords.trim()),c=o?Math.max(1,qO(t.provided.article)):Number.isInteger(s)&&s>=1&&s<=1e5?s:GO,l=t.imagePrompts.map(e=>({name:e.name,number:Math.max(0,Number.parseInt(e.number,10)||0)})),u=l.reduce((e,t)=>e+t.number,0),d={perHour:a,words:c},f=$O({imagePrompts:l,imageScale:d,sources:t.sources}).reduce((e,t)=>e+t,0),p=`about ${String(Math.max(1,Math.round(JO(c))))} minutes (${c.toLocaleString(`en-US`)} words ${o?`in the article`:`expected, set on Review`})`;if(l.length===0)return{text:`For ${p}: tick an image prompt to see the count.`,problem:!1};let m=ZO(d)>=240?` That is the most a run makes (240); the images repeat after that.`:``;return{text:f>u?`For ${p}: ${String(f)} images, ${String(f-u)} more than the prompts' ${String(u)}.${m}`:`For ${p}: the prompts' ${String(u)} images already cover it.`,problem:!1}}function Ghe({document:e,onEdit:t}){let{form:n}=e;return(0,h.jsx)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,form:{...a,...r?{imageScenes:!0}:{}}})}})})}function Khe(e){return e.upload?(0,h.jsx)(V6,{value:e.value,onPick:e.onPick,upload:e.upload}):(0,h.jsx)(qhe,{...e})}function qhe({value:e,onPick:t,onUploading:n}){let{api:r}=z(),i=_(),a=P({mutationFn:e=>lN(r,e),onSuccess:({font:e})=>{i.setQueryData(sN,t=>({fonts:[...(t?.fonts??[]).filter(t=>t.id!==e.id),e]})),i.invalidateQueries({queryKey:sN})}}),o=a.isPending,s=(0,m.useRef)(t);s.current=t;let c=(0,m.useRef)(n);return c.current=n,(0,m.useEffect)(()=>{c.current(o)},[o]),(0,m.useEffect)(()=>()=>c.current(!1),[]),(0,h.jsx)(V6,{value:e,onPick:t,upload:{pending:o,error:a.error?.message,pick:e=>a.mutate(e,{onSuccess:({font:e})=>s.current(e.id)})}})}function V6({value:e,onPick:t,upload:n}){let{api:r}=z(),i=(0,m.useId)(),a=(0,m.useId)(),o=N({queryKey:sN,queryFn:()=>cN(r),staleTime:6e4}),s=n.pending,c=o.data?.fonts??[],l=e!=="default"&&!c.some(t=>t.id===e);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:i,children:`Subtitle font`}),(0,h.jsx)(V,{id:`project.subtitles.font`,className:`-my-1`})]}),(0,h.jsxs)(TV,{id:i,"data-play-field":`subtitles.fontId`,value:e,disabled:s,onChange:e=>t(e.target.value),className:`text-small`,children:[c.some(e=>e.id==="default")?null:(0,h.jsx)(`option`,{value:`default`,children:`Default font · bundled`}),l?(0,h.jsxs)(`option`,{value:e,children:[e,` · saved font`]}):null,c.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.source]},e.id))]})]}),(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,children:[(0,h.jsx)(X4,{htmlFor:a,className:`mb-1`,children:`Upload font (.ttf or .otf)`}),(0,h.jsx)(`input`,{id:a,"data-play-field":`subtitles.fontUpload`,type:`file`,accept:`.ttf,.otf,font/ttf,font/otf`,disabled:s,className:`w-full text-small text-ink-2 file:mr-2 file:rounded-control file:border file:border-line-strong file:bg-sunken file:px-2 file:py-1 file:text-ink`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&n.pick(t)}})]})]}),s?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Uploading font…`}):null,n.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:n.error}):null,l&&o.data?(0,h.jsx)(`p`,{role:`alert`,children:`Saved font is unavailable. Choose another font or upload it again.`}):null,o.error?(0,h.jsxs)(`p`,{role:`alert`,className:`text-small text-danger`,children:[`The font list couldn't be loaded. `,o.error.message]}):null]})}function Jhe(e){return e===`9:16`?{width:1080,height:1920}:{width:1920,height:1080}}function Yhe(e,t){switch(e){case`top`:return{y:60,alignment:8,translateY:0};case`upper-middle`:return{y:t/4,alignment:5,translateY:-50};case`center`:return{y:t/2,alignment:5,translateY:-50};case`lower-middle`:return{y:t*3/4,alignment:5,translateY:-50};case`bottom`:return{y:t-60,alignment:2,translateY:-100}}}function Xhe({value:e,format:t,sample:n=`Every story begins with a word.`,backgroundUrl:r,showCaptions:i=!0,maxFrameHeight:a}){let{api:o}=z(),s=uN(o,e.fontId),c=`subtitle-preview-${(0,m.useId)().replace(/[^a-zA-Z0-9]/g,``)}`,[l,u]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(typeof FontFace>`u`||!document.fonts)return;let e=!0,t=new FontFace(c,`url(${JSON.stringify(s)})`);return u(!1),t.load().then(t=>{e&&document.fonts.add(t)}).catch(()=>{e&&u(!0)}),()=>{e=!1,document.fonts.delete(t)}},[c,s]);let d=Jhe(t),f=Yhe(e.position??`bottom`,d.height),p=Number.isFinite(e.fontSize)?Math.max(16,Math.min(120,e.fontSize)):48,g={position:`absolute`,left:`50%`,top:`${f.y/d.height*100}%`,width:`${(d.width-120)/d.width*100}%`,transform:`translate(-50%, ${f.translateY}%)`,fontFamily:`"${c}", sans-serif`,fontSize:`${p/d.width*100}cqw`,lineHeight:1.2,overflowWrap:`anywhere`,WebkitTextStroke:`${2.5/d.width*100}cqw #101010`,paintOrder:`stroke fill`,textShadow:`0 ${100/d.width}cqw ${100/d.width}cqw #000`};return(0,h.jsxs)(`figure`,{className:`min-w-0 self-start`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Style preview`}),(0,h.jsx)(`span`,{children:t})]}),(0,h.jsxs)(`div`,{role:`img`,"aria-label":`Subtitle style preview`,"data-format":t,"data-position":e.position??`bottom`,className:`sl-media__frame mx-auto w-full text-center text-white`,style:{aspectRatio:`${d.width} / ${d.height}`,maxWidth:t===`9:16`?a?`min(240px, calc((${a}) * 9 / 16))`:240:480,containerType:`inline-size`},children:[r?(0,h.jsx)(`img`,{src:r,alt:``,className:`absolute inset-0 h-full w-full object-cover`}):null,i?(0,h.jsx)(`span`,{role:`note`,"aria-label":`Caption sample`,style:g,children:n}):null]}),(0,h.jsxs)(`figcaption`,{className:`mt-2 text-label text-ink-3`,children:[d.width,` × `,d.height,` · Preview at reduced scale.`,l?` Font preview unavailable; showing a fallback.`:``]})]})}function H6({value:e,format:t=`16:9`,audioEnabled:n,videoEnabled:r,disabled:i=!1,onChange:a,onUploading:o,problem:s,session:c,fontUpload:l,showPreview:u=!0,illustratedPositions:d=!1,rawFontSize:f}){let p=(0,m.useId)(),g=(0,m.useId)(),_=(0,m.useId)(),v=(0,m.useId)(),[y,b]=(0,m.useState)(!1),x=s?.(`subtitles.fontId`),S=s?.(`subtitles.fontSize`),C=s?.(`subtitles.mode`)??s?.(`subtitles`);return(0,h.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":`Subtitles`,children:[(0,h.jsxs)(`fieldset`,{disabled:i||!n,className:`flex min-w-0 flex-col gap-3 disabled:opacity-60`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 flex-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:p,children:`Subtitles`}),(0,h.jsx)(V,{id:`project.subtitles.mode`,className:`-my-1`})]}),(0,h.jsxs)(`select`,{id:p,"data-play-field":`subtitles.mode`,value:n?e.mode:`off`,disabled:l?.pending??y,"aria-describedby":_,"aria-invalid":C!==void 0,onChange:t=>a({...e,mode:t.target.value}),className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:[(0,h.jsx)(`option`,{value:`off`,children:`Off`}),(0,h.jsx)(`option`,{value:`files`,children:`Subtitle files (.srt + .vtt)`}),(0,h.jsx)(`option`,{value:`burn-in`,disabled:!r,children:`Burn into video + files`})]})]}),(0,h.jsx)(`span`,{className:`pb-1 text-label text-ink-3`,children:`English · local · no paid API`})]}),e.mode!==`off`&&n?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Timed from your narration on this computer. First use downloads an approximately 95 MB speech model. Review the subtitles before publishing.`}),(0,h.jsxs)(`div`,{className:`grid items-start gap-5`,style:{gridTemplateColumns:`repeat(auto-fit, minmax(min(100%, 240px), 1fr))`},children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(Khe,{...l?{upload:l}:{},value:e.fontId,onPick:t=>c?c.selectFont(t):a({...e,fontId:t}),onUploading:e=>{b(e),o?.(e)}}),(0,h.jsxs)(`div`,{className:d?`w-full`:`max-w-[180px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:g,children:`Subtitle font size`}),(0,h.jsx)(V,{id:`project.subtitles.size`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-5`,children:[d?(0,h.jsx)(`input`,{"aria-label":`Subtitle font size slider`,type:`range`,min:16,max:120,step:1,value:Math.max(16,Math.min(120,Number.isFinite(e.fontSize)?e.fontSize:48)),className:`min-w-0 flex-1 accent-accent`,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})}):null,(0,h.jsx)(CV,{className:d?`w-20`:void 0,id:g,"data-play-field":`subtitles.fontSize`,type:`number`,min:16,max:120,step:1,value:f?.value??e.fontSize,"aria-invalid":!kN(e)||S!==void 0,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})})]}),!kN(e)||S?(0,h.jsx)(`p`,{role:`alert`,className:`mt-1 text-label text-danger`,children:S??`Choose a whole font size from 16 to 120.`}):null]}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:d?void 0:v,id:`${v}-label`,children:`Subtitle position`}),(0,h.jsx)(V,{id:`project.subtitles.position`,className:`-my-1`})]}),d?(0,h.jsx)(Z4,{type:`single`,"aria-labelledby":`${v}-label`,value:e.position??`bottom`,onValueChange:t=>{let n=pM.find(e=>e===t);n&&a({...e,position:n})},className:`grid w-full grid-cols-5 gap-2 overflow-visible border-0`,children:pM.map((t,n)=>(0,h.jsxs)(Q4,{value:t,"aria-label":t,"data-play-field":(e.position??`bottom`)===t?`subtitles.position`:void 0,className:`flex min-w-0 flex-col items-center gap-2 rounded-control border border-line-strong bg-surface px-1 py-3 text-[10px] last:border-r data-[state=on]:border-focus data-[state=on]:text-accent-ink data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`relative block h-11 w-7 rounded-[2px] border border-current`,children:(0,h.jsx)(`span`,{className:`absolute left-1 right-1 h-[3px] bg-current`,style:{top:`${8+n*20}%`}})}),(0,h.jsxs)(`span`,{children:[t[0]?.toUpperCase(),t.slice(1)]})]},t))}):(0,h.jsx)(`select`,{id:v,"data-play-field":`subtitles.position`,value:e.position??`bottom`,onChange:t=>{let n=pM.find(e=>e===t.target.value);n&&a({...e,position:n})},className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:pM.map(e=>(0,h.jsxs)(`option`,{value:e,children:[e[0]?.toUpperCase(),e.slice(1)]},e))})]})]}),u?(0,h.jsx)(Xhe,{value:e,format:t,...c?{sample:c.previewText}:{}}):null]}),c?.fontUpload&&!c.fontUploading?(0,h.jsxs)(`p`,{role:`alert`,children:[`Reattach `,c.fontUpload.name,`, or select a font.`]}):null,x?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}):null,e.mode===`files`?(0,h.jsx)(`p`,{className:`text-label text-ink-3`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]}):null]}),c?.fontUpload&&(e.mode===`off`||!n)?(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:c.fontUploading?`status`:`alert`,className:`text-small text-ink-2`,children:c.fontUploading?`Uploading ${c.fontUpload.name}…`:`Unfinished font upload: ${c.fontUpload.name}`}),l?.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:l.error}):null,(0,h.jsx)(R,{"data-play-field":`subtitles.fontUpload`,disabled:i,onClick:()=>c.selectFont(e.fontId),children:`Keep current font`})]}):null,C?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:C}):null,(0,h.jsx)(`p`,{id:_,className:`text-small text-ink-2`,children:n?r?`Optional: download subtitles separately or keep them visible in the video.`:`Audio exports support separate subtitle files. Enable Video to burn captions into an MP4.`:`Turn Audio on to add subtitles.`})]})}function U6({value:e,onPick:t}){let n=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`w-full`,...Ob,children:[(0,h.jsxs)(`span`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(X4,{id:n,children:`Frame format`}),(0,h.jsx)(V,{id:`play.format`,className:`-my-1`})]}),(0,h.jsx)(Z4,{type:`single`,value:e,"aria-labelledby":n,className:`w-full max-w-[400px] gap-3 overflow-visible border-0`,onValueChange:e=>{(e===`16:9`||e===`9:16`)&&t(e)},children:[`16:9`,`9:16`].map(t=>(0,h.jsxs)(Q4,{value:t,"data-play-field":e===t?`format`:void 0,"aria-label":t,className:`flex h-28 min-w-0 flex-1 items-center justify-center gap-4 rounded-control border border-line-strong bg-surface p-3 last:border-r data-[state=on]:border-focus data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{className:`flex h-12 items-center justify-center`,"aria-hidden":`true`,children:(0,h.jsx)(`span`,{"data-format-shape":t,className:`block rounded-[2px] border-2 border-current`,style:{width:t===`16:9`?64:27,aspectRatio:t===`16:9`?`16 / 9`:`9 / 16`}})}),(0,h.jsxs)(`span`,{className:`text-left`,children:[(0,h.jsx)(`span`,{className:`block text-body font-semibold`,children:t}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:t===`16:9`?`Landscape`:`Portrait`})]})]},t))})]})}function Zhe({problem:e}){let t=rP(),{document:n}=t,{form:r}=n,i=e=>t.edit({...n,form:{...r,subtitles:{...e,fontSize:r.subtitles.fontSize}}});return(0,h.jsxs)(`div`,{"data-tour":`play-subtitles`,className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`See frame and caption changes in the preview as you go.`}),(0,h.jsx)(U6,{value:r.format,onPick:e=>t.edit({...n,form:{...r,format:e}})}),(0,h.jsx)(`div`,{className:`border-t border-line pt-4`,children:(0,h.jsx)(H6,{showPreview:!1,illustratedPositions:!0,fontUpload:t.fontUpload,session:{previewText:n.previewText,fontUploading:t.fontUploading,fontUpload:n.fontUpload,selectFont:t.selectFont,uploadSubtitleFont:t.uploadSubtitleFont},value:{...r.subtitles,fontSize:Number(r.subtitles.fontSize)},rawFontSize:{value:r.subtitles.fontSize,onChange:e=>t.edit({...n,form:{...r,subtitles:{...r.subtitles,fontSize:e}}})},format:r.format,audioEnabled:r.sources.audio!==`off`,videoEnabled:r.sources.video===`generate`&&r.sources.images!==`off`,onChange:i,problem:e})}),(0,h.jsx)(xV,{label:`Preview text`,tip:`play.preview-text`,className:`border-t border-line pt-4`,children:(0,h.jsx)(CV,{value:n.previewText,onChange:e=>t.edit({...n,previewText:e.target.value})})})]})}function Qhe(e){let t=rP(),n=t.document,r=H3(),i=U3(),{form:a,entries:o,problem:s,update:c}=e;return(0,h.jsx)(vhe,{...e,titled:!1,cast:r,language:i,rawCounts:{...n.form.chunking,onChange:(e,r)=>t.edit({...n,form:{...n.form,chunking:{...n.form.chunking,mode:e,...e===`words`?{words:r}:e===`characters`?{characters:r}:{}}}})},advanced:(0,h.jsxs)(h.Fragment,{children:[[`intro`,`outro`].map(e=>(0,h.jsx)(FV,{field:e,label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,value:a[e],placeholder:`Off`,options:o.filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),problem:s(e),onPick:t=>c({[e]:t})},e)),(0,h.jsx)(`div`,{className:`col-span-full flex flex-wrap gap-2`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:e.onSettings,children:`Settings`})}),(0,h.jsx)(`div`,{className:`col-span-full empty:hidden`,children:(0,h.jsx)(z6,{...e,section:`narration`,onSettings:e.onSettings})})]})})}function $he(e){let t=rP(),n=t.document;return(0,h.jsx)(yhe,{...e,titled:!1,more:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Hhe,{document:n,problem:e.problem,onEdit:t.edit}),n.form.sources.article===`off`?null:(0,h.jsx)(Ghe,{document:n,onEdit:t.edit})]}),rawNumbers:{values:n.form.imagePrompts,onChange:(e,r)=>t.edit({...n,form:{...n.form,imagePrompts:n.form.imagePrompts.map(t=>t.name===e?{...t,number:r}:t)}})}})}function ege(e){let t=rP(),n=t.document,r=U3();return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Phe,{...e,titled:!1,extras:!1,language:r,rawTiming:{imageSeconds:n.form.imageSeconds,zoomPercent:n.form.zoomPercent,edgeSilenceSeconds:n.form.edgeSilenceSeconds,onChange:(e,r)=>t.edit({...n,form:{...n.form,[e]:r}})}}),n.form.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:`sl-fields border-b border-line py-4`,children:(0,h.jsx)(R6,{field:`silenceGapSeconds`,label:`Silence between segments (seconds)`,tip:`play.silence-gap`,placeholder:String(e.silenceGapSeconds),step:.1,problem:e.problem(`silenceGapSeconds`),value:n.form.silenceGapSeconds??``,onChange:e=>{let{silenceGapSeconds:r,...i}=n.form;t.edit({...n,form:e.trim()===``?i:{...i,silenceGapSeconds:e}})}})}),(0,h.jsx)(Zhe,{problem:e.problemOf})]})}function tge(e){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z6,{...e,section:`outputs`,onSettings:e.onSettings}),(0,h.jsx)(Nhe,{...e}),(0,h.jsx)(`section`,{className:`border-b border-line py-4`,children:(0,h.jsx)(L6,{form:e.form,prompts:e.prompts,problem:e.problem,update:e.update,onPickFiles:e.onPickFiles,onRemoveFile:e.onRemoveFile,...e.onReattachFile===void 0?{}:{onReattachFile:e.onReattachFile}})}),e.form.sources.article===`off`?null:(0,h.jsx)(Fhe,{...e})]})}function W6(e,t){if(t===void 0||t.length===0||e.trim()===``)return[];let n=[];for(let[r,i]of t.entries()){let t=1/0;for(let n of[i.name,...i.aliases]){let r=nge(e,n);r!==void 0&&r<t&&(t=r)}Number.isFinite(t)&&n.push({member:i,at:t,order:r})}return n.sort((e,t)=>e.at-t.at||e.order-t.order).map(e=>e.member)}function nge(e,t){let n=t.trim().split(/\s+/u).filter(Boolean);if(n.length===0)return;let r=RegExp(`(?<![\\p{L}\\p{N}])${n.map(rge).join(`\\s+`)}(?![\\p{L}\\p{N}])`,`iu`).exec(e);return r===null?void 0:r.index}function rge(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function ige(e,t){let n=e.provided.reference?.file;if(e.sources.images===`generate`&&e.reference?.source===`provide`&&n!==void 0)return{image:{kind:`upload`,stagedFileId:n.id},drawnOn:`the establishing image`};let r=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),i=W6([e.title,...Object.values(e.values)].join(` `),r)[0]??r[0],a=i?.images[0];if(i!==void 0&&a!==void 0)return{image:{kind:`picture`,sha256:a},drawnOn:`${i.name}'s picture`}}function age({selected:e,reviewed:t}){let n=e=>W3.find(t=>t.stage===e)?.label??e;return e?.length?(0,h.jsxs)(`div`,{className:`space-y-3 text-body`,children:[t?.length?t.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`font-medium`,children:[`Run `,e.runIndex+1,` · Before `,n(e.stage)]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.dependents.length?`Also holds: ${e.dependents.map(n).join(`, `)}.`:`No dependent steps.`})]},`${e.runIndex}-${e.checkpointId}`)):(0,h.jsxs)(`p`,{children:[`Selected: `,e.map(e=>`Before ${n(e)}`).join(`, `),`. Refresh review to confirm dependent steps.`]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Approval required on the project page. Starting this run does not approve these checkpoints.`})]}):(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No review checkpoints selected.`})}function oge({estimates:e}){let t=e.reduce((e,t)=>e+t.low,0),n=e.reduce((e,t)=>e+t.high,0),r=e.reduce((e,t)=>e+t.unknown,0),i=e[0]?.rows.map((t,n)=>({...t,low:e.some(e=>e.rows[n]?.low===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.low??0),0),high:e.some(e=>e.rows[n]?.high===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.high??0),0),apiLow:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiLow==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiLow??0),0),apiHigh:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiHigh==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiHigh??0),0)}))??[],a=e.some(e=>e.apiLow!==void 0),o=e.reduce((e,t)=>e+(t.apiLow??0),0),s=e.reduce((e,t)=>e+(t.apiHigh??0),0),c=e.reduce((e,t)=>e+(t.apiUnknown??0),0);return e.length===0?(0,h.jsx)(`div`,{}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-title-2 font-semibold`,children:[r?`Known subtotal: `:`Estimated total: `,G6(t,n)]}),r?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Plus `,r,` stage charge`,r===1?``:`s`,` with unavailable pricing.`]}):null,(0,h.jsxs)(`details`,{className:`rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Cost by stage · `,i.length,` `,i.length===1?`stage`:`stages`]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 pt-1 pb-3`,children:[a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o===0&&s===0?`CLI steps: $0 on your plan · no API price is listed for their models.`:`CLI steps: $0 on your plan · ~${G6(o,s)} via API${c?` (plus ${String(c)} with no API price)`:``}.`}):null,(0,h.jsx)(`ul`,{"aria-label":`Cost by stage`,className:`m-0 list-none divide-y divide-line p-0`,children:i.map(e=>(0,h.jsxs)(`li`,{className:`py-2`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between gap-4 text-small`,children:[(0,h.jsx)(`span`,{children:e.stage}),(0,h.jsx)(`span`,{className:`text-right tabular-nums`,children:e.onPlan===!0?e.apiLow===null||e.apiHigh===null?`$0 on your plan · API price unknown`:`$0 on your plan · ~${G6(e.apiLow,e.apiHigh)} via API`:e.low===null||e.high===null?`Unknown`:G6(e.low,e.high)})]}),(0,h.jsx)(`p`,{className:`m-0 mt-0.5 text-label text-ink-3`,children:e.detail})]},e.stage))}),[...new Set(e.flatMap(e=>e.assumptions))].map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e},e)),(0,h.jsxs)(`p`,{className:`m-0 text-label text-ink-3`,children:[`Catalogue verified `,e[0]?.catalogueDate??`date unavailable`,`. Batch rows show combined costs.`]})]})]})]})}function G6(e,t){let n=e=>e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`;return e===t?n(e):`${n(e)} – ${n(t)}`}function K6(e){let t=TA(SA(e)),n=new Map(TA(fA)),r=t.filter(([e,t])=>e!==`Cuts`&&n.get(e)!==t).map(([e,t])=>e===`Animate images`?`Animated images: ${t} (paid)`:e===`Chapter cards`?`Chapter cards`:e===`Transition`?t:`${e}: ${t}`);return r.length===0?`Plain cuts, no effects`:r.join(` · `)}function sge(e){return e===void 0?{ok:!1,text:`Provider status unavailable`}:e.readiness.kind===`cli`?tF(e.readiness)?{ok:!0,text:e.readiness.version===void 0?`CLI ready`:`CLI ready · ${e.readiness.version}`}:{ok:!1,text:e.readiness.issue??`CLI not found`}:e.readiness.kind===`local`?e.readiness.available?{ok:!0,text:`Built-in voice · ${e.readiness.engine??`ready`}`}:{ok:!1,text:e.readiness.issue??`No speech program found`}:e.readiness.hasKey?{ok:!0,text:`API key saved`}:{ok:!1,text:`API key missing`}}function cge(e,t){let n=e.sources.audio===`generate`,r=[`from_prompt`,`prompt_by_llm`].includes(e.sources.thumbnail);return[...(e.sources.article===`generate`||e.sources.thumbnail===`prompt_by_llm`||pj(e)||jN(e)||n&&[`intro`,`outro`].some(n=>t.some(t=>t.category===n&&t.name===e[n]&&t.mode===`llm`)))&&e.llm?[{field:`llm.provider`,family:`llm`,label:`Text generation`,provider:e.llm.provider,model:e.llm.model}]:[],...n&&e.audio?[{field:`audio.provider`,family:`tts`,label:`Narration`,provider:e.audio.provider,model:e.audio.model,voice:e.audio.voice}]:[],...(e.sources.images===`generate`||r||jN(e)||CA(e))&&e.images?[{field:`images.provider`,family:`image`,label:`Images`,provider:e.images.provider,model:e.images.model}]:[]]}function q6({name:e,children:t}){return(0,h.jsxs)(`section`,{"aria-label":`${e} summary`,className:`min-w-0 border-t border-line pt-5`,children:[(0,h.jsx)(`h3`,{className:`mb-4 font-semibold`,children:e}),t]})}function lge({form:e,entries:t,providers:n,voices:r,textModels:i,audioModels:a,imageModels:o,onReveal:s}){let c=cge(e,t);if(!c.length)return(0,h.jsx)(q6,{name:`Run readiness`,children:(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No generated providers required. Supplied content is ready for processing.`})});let l={llm:i,tts:a,image:o};return(0,h.jsxs)(q6,{name:`Run readiness`,children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`These checks are refreshed with Review and checked again when you start.`}),(0,h.jsx)(`ul`,{className:`divide-y divide-line`,"aria-label":`Run readiness checks`,children:c.map(e=>{let t=n?.find(t=>t.id===e.provider&&t.family===e.family),i=sge(t),a=l[e.family],o=a?.models.find(t=>t.id===e.model),c=a===void 0?{ok:!0,text:`Model checked at Start`}:o!==void 0||a.allowsCustom?{ok:!0,text:`Model available`}:{ok:!1,text:`Model unavailable`},u=e.voice===void 0?void 0:r===void 0?{ok:!1,text:`Voice list unavailable`}:r.some(t=>t.provider===e.provider&&t.voiceId===e.voice)?{ok:!0,text:`Voice saved`}:{ok:!1,text:`Voice missing`},d=[i,c,...u?[u]:[]],f=d.every(e=>e.ok);return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-3 py-3`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,h.jsx)(`span`,{className:f?`text-lime`:`text-danger`,children:f?`Ready`:d.filter(e=>!e.ok).map(e=>e.text).join(` · `)}),f?null:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>s(e.field),children:`Edit ↗`})]},`${e.family}:${e.provider}`)})})]})}function uge({fields:e,onReveal:t,children:n}){let{document:r,review:i}=rP(),{form:a}=r,{api:o}=z(),s=_(),c=s.getQueryData(eb(o).queryKey),l=s.getQueryData(rb(o).queryKey),u=s.getQueryData(tb(o).queryKey),d=s.getQueryData(sN),f=s.getQueryData(OV(a.llm.provider)),p=s.getQueryData(OV(a.audio.provider)),m=s.getQueryData(OV(a.images.provider)),g=a.sources.audio===`generate`,v=[`from_prompt`,`prompt_by_llm`].includes(a.sources.thumbnail),y=a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||pj(a)||jN(a)||g&&[`intro`,`outro`].some(e=>l?.entries.some(t=>t.category===e&&t.name===a[e]&&t.mode===`llm`)),b=e=>c?.providers.find(t=>t.id===e)?.displayName??e,x=(e,n,r)=>(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[90px_minmax(0,1fr)_auto] items-start gap-x-3 py-1 sm:grid-cols-[145px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(`dt`,{className:`break-words py-2 text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`min-w-0 whitespace-pre-wrap break-words py-2`,children:r||`Not selected`}),n?(0,h.jsx)(`dd`,{children:(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit ${e}`,onClick:()=>t(n),children:`Edit ↗`})}):null]},n??e),S=a.chunking.mode===`words`||a.chunking.mode===`characters`?a.chunking.mode:null;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(lge,{form:a,entries:l?.entries??[],providers:c?.providers,voices:u?.voices,textModels:f,audioModels:p,imageModels:m,onReveal:t}),(0,h.jsxs)(q6,{name:`Content`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Project`,`title`,a.title||`Untitled run`),x(`Article`,`sources.article`,PN[a.sources.article]),a.sources.article===`generate`?x(`Article prompt`,`articlePrompt`,a.articlePrompt):x(`Article text`,`provided.article`,`Your article`),a.sources.article===`generate`?x(`Research`,`sources.research`,PN[a.sources.research]):x(`Research`,null,`Off · Article is provided`),a.sources.research===`provide`&&a.sources.article===`generate`?x(`Research text`,`provided.research`,a.provided.research):null,y?(0,h.jsxs)(h.Fragment,{children:[x(`Text provider`,`llm.provider`,b(a.llm.provider)),x(`Text model`,`llm.model`,f?.models.find(e=>e.id===a.llm.model)?.name??a.llm.model),a.llm.thinking||f?.models.find(e=>e.id===a.llm.model)?.thinkingModes?.length?x(`Thinking`,`llm.thinking`,a.llm.thinking??`Model default`):null]}):null,e.map(({name:e})=>x(e,`values.${e}`,a.values[e]??``))]}),n]}),(0,h.jsx)(q6,{name:`Outputs`,children:(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Narration`,`sources.audio`,PN[a.sources.audio]),g?(0,h.jsxs)(h.Fragment,{children:[x(`Audio provider`,`audio.provider`,b(a.audio.provider)),x(`Audio model`,`audio.model`,p?.models.find(e=>e.id===a.audio.model)?.name??a.audio.model),x(`Voice`,`audio.voice`,u?.voices.find(e=>e.provider===a.audio.provider&&e.voiceId===a.audio.voice)?.name??a.audio.voice),x(`Chunking`,S?`chunking.${S}`:`chunking.mode`,S?`Every ${a.chunking[S]||`(not entered)`} ${S}`:a.chunking.mode===`whole`?`Whole text`:`Paragraph`),x(`Intro`,`intro`,a.intro||`Off`),x(`Narration Preparation`,`narrationPrompt`,a.narrationPrompt?`${a.narrationPrompt} · One LLM call per narration chunk and entry`:`Off`),x(`Outro`,`outro`,a.outro||`Off`)]}):null,a.sources.audio===`provide`?x(`Narration file`,`provided.audio`,a.provided.audio?.name):null,x(`Images`,`sources.images`,PN[a.sources.images]),a.sources.images===`generate`||v||jN(a)?(0,h.jsxs)(h.Fragment,{children:[x(`Image provider`,`images.provider`,b(a.images.provider)),x(`Image model`,`images.model`,m?.models.find(e=>e.id===a.images.model)?.name??a.images.model),a.images.thinking===void 0?null:x(`Image effort`,`images.thinking`,a.images.thinking)]}):null,a.sources.images===`generate`&&a.reference!==void 0&&a.reference.source!==`off`?x(`Establishing image`,a.reference.source===`prompt`?`reference.prompt`:`provided.reference`,`${a.reference.source===`prompt`?a.reference.prompt||`(no prompt picked)`:a.provided.reference?.name??`(no file attached)`}${a.reference.thumbnail?` · thumbnail too`:``}`):null,a.sources.images===`generate`?a.imagePrompts.length?a.imagePrompts.map((e,t)=>x(e.name,`imagePrompts.${t}.number`,`${e.name} · ${e.number||`(not entered)`} images`)):x(`Image prompts`,`imagePrompts`,`None selected`):null,a.sources.images===`provide`?x(`Image files`,`provided.images`,a.provided.images.length?(0,h.jsx)(`ol`,{className:`list-inside list-decimal`,children:a.provided.images.map(e=>(0,h.jsx)(`li`,{children:e.name},e.attachmentId))}):`No files selected`):null,x(`Thumbnail`,`sources.thumbnail`,PN[a.sources.thumbnail]),v?x(`Thumbnail prompt`,`thumbnailPrompt`,a.thumbnailPrompt):null,a.sources.thumbnail===`provide`?x(`Thumbnail file`,`provided.thumbnail`,a.provided.thumbnail?.name):null,x(`Video`,`sources.video`,PN[a.sources.video]),a.sources.video===`generate`?x(`Seconds per image`,`imageSeconds`,a.imageSeconds||`(not entered)`):null,a.sources.video===`generate`?x(`Zoom`,`zoomPercent`,a.zoomPercent?`${a.zoomPercent}%`:`(not entered)`):null,a.sources.video===`generate`?x(`Motion`,`motionStyle`,YA[a.motionStyle]):null,a.sources.video===`generate`?x(`Cuts`,`videoEdit.cuts`,gA[SA(a).cuts]):null,a.sources.video===`generate`?x(`Look`,`videoEdit`,K6(a)):null,a.sources.audio===`off`?null:x(`Silence at start and end`,`edgeSilenceSeconds`,a.edgeSilenceSeconds?`${a.edgeSilenceSeconds} s`:`(not entered)`),a.sources.audio===`off`?null:x(`YouTube description`,`youtubeDescription`,a.youtubeDescription===!0?`${a.descriptionPrompt||`Built-in`} prompt · One LLM call after subtitle timing`:`Off`),a.sources.audio===`off`?null:x(`Shorts`,`shorts.enabled`,jN(a)&&a.shorts!==void 0?[`${a.shorts.count} shorts of ${a.shorts.minSeconds}-${a.shorts.maxSeconds} s`,`${a.shorts.prompt||`Built-in`} prompt`,`${a.shorts.imagePrompt||`Built-in`} image style`,...dge(a.shorts,a.provided.shortsMusic?.name),`Vertical images and renders after subtitle timing`].join(` · `):`Off`),x(`Document`,`sources.document`,RS(a.sources,`document`)===`generate`?`PDF · ${XS(a.document)} theme`:PN.off)]})}),(0,h.jsxs)(q6,{name:`Checkpoints`,children:[(0,h.jsx)(age,{selected:a.checkpoints,reviewed:i.valid?i.receipt?.checkpointSet:void 0}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit checkpoints`,onClick:()=>t(`checkpoints`),children:`Edit checkpoints ↗`})]}),(0,h.jsxs)(q6,{name:`Style`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Frame`,`format`,a.format),a.sources.audio===`off`?x(`Subtitles`,null,`Off · Audio is Off`):x(`Subtitles`,`subtitles.mode`,a.subtitles.mode),a.sources.audio!==`off`&&a.subtitles.mode!==`off`?(0,h.jsxs)(h.Fragment,{children:[x(`Subtitle font`,`subtitles.fontId`,d?.fonts.find(e=>e.id===a.subtitles.fontId)?.name??a.subtitles.fontId),x(`Subtitle size`,`subtitles.fontSize`,`${a.subtitles.fontSize||`(not entered)`} px`),x(`Subtitle position`,`subtitles.position`,a.subtitles.position)]}):null]}),a.sources.audio!==`off`&&a.subtitles.mode===`files`?(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]})]})}function dge(e,t){let n=qk(e),r=n.speed,i=n.musicVolume;return[...n.titleOnScreen===!0?[`Title on screen`]:[],...r!==void 0&&r!==1?[`${r.toFixed(2)}× speed`]:[],...t===void 0?i!==void 0&&i!==15?[`Music at ${String(i)}% once added in Edit project`]:[]:[`Music: ${t} at ${String(i??15)}%`],...n.fullVideoLink===void 0?[]:[`Links ${n.fullVideoLink}`]]}function fge({fields:e,errors:t,onReveal:n,problem:r}){let i=rP(),{document:a,review:o}=i,s=a.form;(0,m.useEffect)(()=>{i.reviewDraft()},[i.reviewDraft]);let c=o.valid?o.receipt?.runs??[]:[];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Everything this run will do, the checkpoints it stops at and the reviews it runs. The estimate and the Play key stay in the right rail.`}),t.length?(0,h.jsx)(`ul`,{"aria-label":`Setup errors`,className:`text-small text-danger`,children:t.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>n(e.field),children:e.message})},`${e.field}-${e.message}`))}):null,(0,h.jsx)(Wme,{problem:r}),(0,h.jsx)(VV,{problem:r}),(0,h.jsx)(uge,{fields:e,onReveal:n,children:(0,h.jsxs)(`details`,{className:`mt-5 border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:s.sources.article===`provide`?`Read the supplied article and resolved prompts`:`Read the resolved prompt`}),c.length?c.map((e,t)=>(0,h.jsxs)(`div`,{className:`mt-4`,children:[(0,h.jsx)(`h4`,{className:`font-medium`,children:e.draft.title}),e.draft.sources.article===`provide`?(0,h.jsx)(`p`,{className:`mt-3 whitespace-pre-wrap break-words text-body`,children:e.draft.provided.article}):null,Object.entries(e.rendered).map(([e,t])=>(0,h.jsxs)(`div`,{className:`mt-3`,children:[(0,h.jsx)(`h5`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-body`,children:t})]},e))]},a.variants[t-1]?.id??i.activeId)):(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Refresh review to read the exact resolved inputs.`})]})})]})}function pge(e,t,n){return[...z3(e).map(e=>(t[e]??``).trim()===``?`${e} is left empty in the template.`:`${e} is left empty in the template (this video's ${e}, "${t[e]}", is not saved).`),...n>0?[`The ${n===1?`other video`:`${String(n)} other videos`} queued here ${n===1?`is`:`are`} not saved.`]:[]]}function mge({open:e,onClose:t}){let{api:n}=z(),r=_(),i=rP(),a=Oy(),o=N(Hq(n)),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),p=(0,m.useRef)(null),{document:g}=i,v=pge(g.form.title,g.form.values,g.variants.length),y=()=>{u(null),t()},b=async()=>{let e=s.trim();if(!(e===``||d)){f(!0),u(null);try{if(!await i.flush()){u(`Your draft wasn't saved, so the template wasn't either. Press Retry beside Drafts, then Save template again.`);return}p.current?.name!==e&&(p.current={name:e,id:crypto.randomUUID()});let s=o.data?.find(e=>e.id===g.templateSource?.id),l=g.channelId??(s?o0(s):void 0),d=Bme(g),f=await Wq(n,{id:p.current.id,name:e,document:l===void 0?d:{...d,channelId:l}});if(!f.ok){p.current=null,u(`The template wasn't saved. ${f.message}`);return}p.current=null,c(``),a(`Template "${e}" saved.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}catch(e){u(`The template wasn't saved. ${e instanceof Error?e.message:`Press Save template again.`}`)}finally{f(!1)}}};return(0,h.jsx)(Ay,{open:e,onOpenChange:e=>{e||y()},title:`Save as template`,description:`Keeps this setup's prompts, voice, images, style, outputs and reviews to start the next video from.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`secondary`,onClick:y,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,disabled:s.trim()===``||d,disabledReason:d?`Saving the template`:`Name the template first`,onClick:()=>void b(),children:`Save template`})]}),children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,value:s,maxLength:120,placeholder:g.form.title.replace(/\{\{[^}]*\}\}/g,``).trim()||`My setup`,onChange:e=>c(e.target.value)})}),v.length?(0,h.jsx)(`ul`,{"aria-label":`Left out of the template`,className:`m-0 flex list-none flex-col gap-1 p-0 text-small text-ink-2`,children:v.map(e=>(0,h.jsx)(`li`,{children:e},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Every keyword keeps its value: the title names none.`}),l?(0,h.jsx)(SI,{tone:`danger`,title:l}):null]})})}var hge=new Set([`a`,`an`,`the`,`of`,`and`,`or`,`in`,`on`,`to`,`for`,`with`,`vs`,`s`]);function J6(e){return e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase().replace(/&/g,` and `).replace(/[^\p{L}\p{N}]+/gu,` `).trim()}function Y6(e){let t=J6(e).split(` `).filter(e=>e!==``&&!hge.has(e)).map(e=>e.length>3&&e.endsWith(`s`)&&!e.endsWith(`ss`)?e.slice(0,-1):e);return new Set(t)}function gge(e,t){let n=0;for(let r of e)t.has(r)&&(n+=1);return n}function _ge(e,t){let n=J6(e);if(n===J6(t))return n!==``;let r=Y6(e),i=Y6(t);if(r.size===0||i.size===0)return!1;let a=gge(r,i);if(a/(r.size+i.size-a)>=.6)return!0;let o=Math.min(r.size,i.size),s=Math.max(r.size,i.size);return a===o&&o/s>=.5}function vge(e,t,n){let r=e.map(e=>e.trim()).filter(e=>e!==``);if(r.length===0)return;let i=e=>r.some(t=>_ge(t,e)),a=t.find(i);if(a!==void 0)return{title:a,where:`project`};let o=n.find(i);return o===void 0?void 0:{title:o,where:`video`}}function yge({topics:e}){let{api:t}=z(),n=rP(),{document:r}=n,i=V3(),a=N(Yy(t)),o=N(V2(t,i)),{form:s}=r,c=mq(s.title,s.values),l=vge(e.length===0?[s.title]:[c,...e.map(e=>s.values[e]??``)],(a.data?.projects??[]).filter(e=>e.channelId===i).map(e=>e.title),(o.data??[]).map(e=>e.title));return l===void 0||n.review.created!==null?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.where===`project`?`This channel already has a video on this: "${l.title}" (in Projects). Start anyway if you want another take.`:`This channel already uploaded "${l.title}" (Channel → Existing videos). Start anyway if you want another take.`})}function bge({rows:e,open:t,onChange:n}){return(0,h.jsx)(`ul`,{"aria-label":`Setup`,className:`m-0 flex list-none flex-col border-t border-line p-0`,children:e.map(e=>{let r=t.has(e.id)&&e.editor!==void 0,i=`play-row-${e.id}`;return(0,h.jsxs)(`li`,{"data-setup-row":e.id,className:`border-b border-line`,children:[(0,h.jsx)(H,{title:e.label,size:`small`,className:`items-center py-3.5`,status:e.problem?(0,h.jsx)(_S,{tone:`failed`,children:`Needs setup`}):void 0,meta:(0,h.jsx)(`span`,{"data-row-summary":!0,className:e.problem&&!r?`block break-words text-danger`:`block truncate text-ink-2`,title:e.problem&&!r?void 0:e.summary,children:r?e.summary:e.problem??e.summary}),children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":e.editor===void 0?void 0:r,"aria-controls":e.editor===void 0?void 0:i,"aria-label":`${r?`Done with`:`Change`} ${e.label.toLowerCase()}`,onClick:()=>n(e.id,!r),children:r?`Done`:`Change`})}),r?(0,h.jsx)(`section`,{id:i,"aria-label":e.label,className:`min-w-0 pb-6`,children:e.editor}):null]},e.id)})})}var X6=[{id:`title`,label:`Title and keywords`,section:`content`},{id:`article`,label:`Article`,section:`content`},{id:`narration`,label:`Narration`,section:`outputs`},{id:`images`,label:`Images`,section:`outputs`},{id:`video`,label:`Video and style`,section:`style`},{id:`outputs`,label:`Outputs`,section:`outputs`},{id:`reviews`,label:`Reviews`,section:`review`},{id:`channel`,label:`Channel`,section:`content`}],xge=[[`title`,[`title`,`values`]],[`article`,[`sources.article`,`sources.research`,`articlePrompt`,`provided.article`,`provided.research`,`llm`]],[`narration`,[`sources.audio`,`audio`,`voices`,`provided.audio`,`narrationPrompt`,`intro`,`outro`,`chunking`]],[`images`,[`sources.images`,`images`,`imagePrompts`,`provided.images`,`reference`,`provided.reference`]],[`video`,[`sources.video`,`imageSeconds`,`zoomPercent`,`motionStyle`,`edgeSilenceSeconds`,`silenceGapSeconds`,`sentencePauseSeconds`,`paragraphPauseSeconds`,`loudness`,`videoEdit`,`format`,`subtitles`,`fontUpload`]],[`outputs`,[`sources.thumbnail`,`thumbnailPrompt`,`provided.thumbnail`,`thumbnailCount`,`youtubeDescription`,`descriptionPrompt`,`shorts`,`sources.document`,`document`]],[`reviews`,[`checkpoints`,`reviews`]],[`channel`,[`channelId`,`useBrandKit`,`language`]]],Z6=(e,t)=>e.some(e=>t===e||t.startsWith(`${e}.`));function Q6(e,t=`article`){return Z6([`llm`],e)?t:xge.find(([,t])=>Z6(t,e))?.[0]}function Sge(e){switch(e){case`content`:return[`title`,`article`,`channel`];case`outputs`:return[`narration`,`images`,`video`,`outputs`];case`style`:return[`video`];case`review`:return[`reviews`]}}function $6(e,t,n,r=`article`){return t.find(t=>Q6(t.field,r)===e?e===`title`?t.field===`title`?n.length>0:!n.some(e=>t.field===`values.${e}`):!0:!1)}function Cge(e,t,n){let r=e=>e===``?`no provider`:n.providers.find(t=>t.id===e)?.displayName??e,i=e=>e.filter(e=>typeof e==`string`&&e!==``).join(` · `);switch(e){case`title`:return i([n.topics.length?t.title:!1,n.keywords===0?`No keywords`:`${String(n.keywords)} keyword${n.keywords===1?``:`s`}`]);case`article`:return t.sources.article===`off`?`Off: no article`:t.sources.article===`provide`?`Your article`:i([t.articlePrompt||`No prompt picked`,t.llm.provider?`${r(t.llm.provider)} · ${t.llm.model||`no model`}`:!1,t.sources.research===`off`?`research off`:`research: ${PN[t.sources.research].toLowerCase()}`]);case`narration`:{if(t.sources.audio===`off`)return`Off, a silent video`;if(t.sources.audio===`provide`)return t.provided.audio?.name??`Your narration file`;let e=n.voices.find(e=>e.provider===t.audio.provider&&e.voiceId===t.audio.voice);return i([r(t.audio.provider),t.voices===void 0?e?.name??(t.audio.voice||`no voice`):`${DA[t.voices.format]}, ${String(t.voices.speakers.length)} speakers`,t.narrationPrompt?`prepared with ${t.narrationPrompt}`:!1,t.intro?`intro ${t.intro}`:!1,t.outro?`outro ${t.outro}`:!1])}case`images`:{if(t.sources.images===`off`)return`Off`;if(t.sources.images===`provide`)return`${String(t.provided.images.length)} of your images`;let e=t.imagePrompts.map(e=>`${e.name} × ${e.number||`?`}`);return i([e.length?e.join(`, `):`No image prompts picked`,r(t.images.provider),t.images.model,t.reference!==void 0&&t.reference.source!==`off`&&`establishing image`])}case`video`:return i([t.format,t.sources.video===`off`?`no video`:gA[SA(t).cuts].toLowerCase(),t.sources.video!==`off`&&n.look,t.sources.audio!==`off`&&t.subtitles.mode!==`off`?`captions ${n.fontName??t.subtitles.fontId} ${t.subtitles.fontSize} ${t.subtitles.position}`:`no captions`]);case`outputs`:return i([t.sources.thumbnail===`off`?!1:t.sources.thumbnail===`provide`?`your thumbnail`:t.thumbnailCount===3?`3 thumbnails`:`1 thumbnail`,jN(t)&&t.shorts?`${t.shorts.count} shorts`:!1,t.youtubeDescription===!0&&t.sources.audio!==`off`&&`YouTube description`,t.sources.document===`generate`&&`PDF (${XS(t.document)})`])||`Only the video`;case`reviews`:return i([n.checkpoints===0?`No checkpoints`:`${String(n.checkpoints)} checkpoint${n.checkpoints===1?``:`s`}`,n.reviews===0?`no automatic reviews`:`${String(n.reviews)} automatic review${n.reviews===1?``:`s`}`]);case`channel`:return i([n.channel??`Default channel`,n.brandKit?`brand kit on`:`brand kit off`,t.language===void 0?void 0:BO(t.language).name])}}function wge({review:e,blocker:t,errors:n,pendingUpload:r}){if(e.starting)return;if(e.uncertain)return{text:`Slopify didn't confirm the last start. Press Check Start result to find out before starting again.`};if(t)return{text:t.hint,field:t.field};let i=n[0];if(i)return{text:i.message,field:i.field};if(r)return{text:`Wait for uploads to finish before Start`,field:r};if(e.error)return{text:e.error};if(e.pending||!e.valid)return{text:`Checking your setup and the estimate…`}}function Tge({errors:e,blocker:t,saveProblem:n,onReveal:r,onWholeSetup:i,onSaveTemplate:a,preview:o}){let s=rP(),{document:c,review:l}=s,u=YN(c,s.view),d=l.starting||l.uncertain;(0,m.useEffect)(()=>{s.reviewDraft()},[s.reviewDraft]);let f=!l.valid&&!l.pending&&!l.starting&&!l.uncertain&&l.error===null&&e.length===0&&t===void 0&&!u&&s.activeId!==null;(0,m.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>void s.reviewDraft(),800);return()=>clearTimeout(e)},[f,c,s.reviewDraft]);let p=l.valid&&l.receipt?l.receipt.runs.length:GN(c),g=wge({review:l,blocker:t,errors:e,pendingUpload:u}),_=l.starting||!l.uncertain&&(!l.valid||l.pending||e.length>0||!!u);return(0,h.jsxs)(h.Fragment,{children:[o,(0,h.jsxs)(`section`,{"aria-label":`Start`,className:`flex min-w-0 flex-col gap-4 border-t border-line pt-5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:p===1?`1 video`:`${String(p)} videos`}),p>1?(0,h.jsx)(kb,{label:`Queue`,tip:`play.batch-queue`,checked:JN(c),disabled:d,onChange:e=>s.edit({...c,queue:e})}):(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`One run`})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Estimated cost`,info:`play.estimate`,size:`small`,className:`pb-0`}),l.valid&&l.receipt?(0,h.jsx)(oge,{estimates:l.receipt.estimates}):(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.pending?`Calculating the estimate…`:`The estimate appears once the setup is complete.`}),(0,h.jsx)(xV,{label:`Expected article words per video`,tip:`play.expected-words`,className:`mt-2`,children:(0,h.jsx)(CV,{"data-play-field":`expectedWords`,type:`number`,min:1,max:1e5,value:c.expectedWords,disabled:d,onChange:e=>s.edit({...c,expectedWords:e.target.value})})})]}),n?(0,h.jsx)(SI,{tone:`danger`,title:n}):null,(0,h.jsxs)(Ty,{"data-tour":`play-start`,disabled:_,"aria-describedby":g?`play-start-reason`:void 0,onClick:()=>{s.startRun()},children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),qN(l,c)]}),(0,h.jsx)(`div`,{id:`play-start-reason`,className:`min-h-5 text-center text-small`,children:g===void 0?(0,h.jsx)(`span`,{className:`text-ink-3`,children:p===1?`Nothing starts until you press it.`:JN(c)?`They run one after another. Nothing starts until you press it.`:`They all run at once. Nothing starts until you press it.`}):g.field===void 0?(0,h.jsx)(`span`,{role:l.error?`alert`:`status`,className:l.error?`text-danger`:`text-ink-2`,children:g.text}):(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center justify-center gap-x-1`,children:[(0,h.jsx)(`span`,{id:`play-start-field`,className:`text-waiting`,children:g.text}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-describedby":`play-start-field`,onClick:()=>r(g.field??``),children:`Go to the field`})]})}),(0,h.jsxs)(Ey,{className:`justify-center`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:l.pending||d||!!u,onClick:()=>{s.reviewDraft()},children:`Refresh review`}),(0,h.jsx)(V,{id:`play.refresh-review`})]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-keyshortcuts":Mx(lP.reviewSetup),onClick:i,children:`Review the whole setup`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Save as template`})]})]})]})}function Ege(e,t,n){let r=e?.prompts??[],i=e?.entries??[];return{prompts:[...r,...t.filter(e=>!r.some(t=>t.kind===e.kind&&t.name.toLowerCase()===e.name.toLowerCase()))],entries:[...i,...n.filter(e=>!i.some(t=>t.category===e.category&&t.name.toLowerCase()===e.name.toLowerCase()))]}}function Dge({topics:e,onError:t}){let{api:n}=z(),r=_(),i=rP(),a=N(Hq(n)),o=N(Zb(n)),[s,c]=(0,m.useState)(!1),l=i.review.starting||i.review.uncertain||i.review.created!==null,u=i.document.templateSource,d=a.data?.find(e=>e.id===u?.id),f=e=>o.data?.find(t=>t.id===e)?.name,p=async o=>{if(t(null),o===``){await i.newDraft();return}let s=a.data?.find(e=>e.id===o);if(s){c(!0);try{if(!await i.flush()){t(`Your draft wasn't saved, so the template wasn't applied. Press Retry beside Drafts, then pick the template again.`);return}let a=Object.fromEntries(e.map(e=>[e,i.document.form.values[e]??``]).filter(([,e])=>e.trim()!==``)),o=await Xq(n,s,crypto.randomUUID());if(!o.ok){t(`The template "${s.name}" wasn't applied. ${o.message}`);return}if(await r.invalidateQueries({queryKey:[`play-drafts`]}),!await i.open(o.value.draft.id)){t(`The draft made from "${s.name}" didn't open. Open it from Drafts.`);return}let c=o.value.draft.document,l=Object.fromEntries(Object.entries(a).filter(([e])=>(c.form.values[e]??``)===``));Object.keys(l).length>0&&i.edit({...c,form:{...c.form,values:{...c.form.values,...l}}})}catch(e){t(e instanceof Error?`The template "${s.name}" wasn't applied. ${e.message}`:`The template "${s.name}" wasn't applied. Pick it again.`)}finally{c(!1)}}},g=a.error?`Templates didn't load. ${a.error.message}`:d?[f(o0(d)),`version ${String(d.version)}`].filter(Boolean).join(` · `):a.data?.length===0?`No templates yet. Set this video up, then Save as template.`:void 0;return(0,h.jsx)(xV,{label:`Template`,tip:`play.template`,help:g,children:(0,h.jsxs)(TV,{"data-play-field":`template`,value:d?.id??``,disabled:s||l,onChange:e=>void p(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:u&&!d?`Template no longer saved`:`No template`}),(a.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})}function Oge({topics:e,problem:t}){let n=rP(),{document:r}=n,{form:i}=r,a=e=>{n.edit({...r,form:e}),n.invalidateReview(!0)};if(e.length===0)return(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:t(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,className:`!h-11 text-[17px]`,value:i.title,maxLength:200,placeholder:`What's the video about?`,"aria-invalid":t(`title`)!==void 0,onChange:e=>a({...i,title:e.target.value})})});let o=mq(i.title,i.values);return(0,h.jsx)(`div`,{className:`grid min-w-0 gap-4`,children:e.map((n,r)=>(0,h.jsx)(xV,{label:n,tip:`play.topic`,help:r===e.length-1?(0,h.jsxs)(h.Fragment,{children:[`Title: `,(0,h.jsx)(`b`,{className:`font-semibold text-ink`,children:o})]}):void 0,error:t(`values.${n}`)??(r===e.length-1?t(`title`):void 0),children:(0,h.jsx)(CV,{"data-play-field":`values.${n}`,className:`!h-11 text-[17px]`,value:i.values[n]??``,maxLength:200,spellCheck:!1,"aria-invalid":t(`values.${n}`)!==void 0,onChange:e=>a({...i,values:{...i.values,[n]:e.target.value}})})},n))})}function kge({topics:e,keywordNames:t,origins:n,problem:r,adding:i,onAdding:a,open:o,onOpen:s}){let c=rP(),{document:l}=c,{form:u}=l,[d,f]=(0,m.useState)(``),p=(0,m.useId)(),g=(0,m.useRef)(null),_=c.review.starting||c.review.uncertain,v=l.variants,y=e=>{c.edit({...l,variants:e})},b=e[0],x=e=>b===void 0?e.title:e.values[b]||e.title,S=()=>{let e=d.trim();e===``||v.length>=49||(y([...v,{id:crypto.randomUUID(),title:b===void 0?e:u.title,values:b===void 0?{...u.values}:{...u.values,[b]:e}}]),f(``),g.current?.focus())},C=v.findIndex(e=>e.id===o),w=C===-1?void 0:v[C];return(0,h.jsxs)(`section`,{"aria-label":`More videos from the same setup`,className:`min-w-0`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:`More videos from the same setup`}),(0,h.jsx)(V,{id:`play.more-videos`,className:`-my-1`})]}),(0,h.jsxs)(Ey,{className:`flex-wrap`,children:[v.map((e,n)=>{let i=x(e)||`Video ${String(n+2)}`,a=[`items.${String(n+1)}.title`,...t.map(e=>`items.${String(n+1)}.values.${e}`)].some(e=>r(e)!==void 0);return(0,h.jsx)(yS,{...a?{className:`border-danger`}:{},..._?{}:{onRemove:()=>y(v.filter(t=>t.id!==e.id)),removeLabel:`Remove ${i}`},children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,"data-play-field":`items.${e.id}`,className:`-my-1 -ml-1.5 h-6 px-1.5 text-ink`,"aria-label":`Change the keywords of ${i}`,onClick:()=>s(e.id),children:[i,(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})]})},e.id)}),i?(0,h.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,h.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:b===void 0?`Title of another video`:`${b} of another video`}),(0,h.jsx)(CV,{ref:g,id:p,autoFocus:!0,className:`!h-8 w-48`,value:d,maxLength:200,placeholder:b===void 0?`Another title`:`Another ${b}`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(!1)}}),(0,h.jsx)(R,{type:`submit`,size:`small`,disabled:d.trim()===``,children:`Add`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>a(!1),children:`Done`})]}):(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:_||v.length>=49,disabledReason:_?`Wait for the start to finish`:`One Start queues at most 50 videos`,onClick:()=>a(!0),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add topic`]})]}),(0,h.jsx)(YP,{open:w!==void 0,title:w?`Video ${String(C+2)}: ${x(w)||`untitled`}`:``,width:`narrow`,onClose:()=>s(null),footer:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>s(null),children:`Done`}),children:w?(0,h.jsxs)(`fieldset`,{disabled:_,className:`flex min-w-0 flex-col gap-5 border-0 p-0`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Everything else comes from the setup of the first video.`}),(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:r(`items.${String(C+1)}.title`),children:(0,h.jsx)(CV,{"data-play-field":`items.${w.id}.title`,value:w.title,maxLength:200,onChange:e=>y(v.map(t=>t.id===w.id?{...t,title:e.target.value}:t))})}),(0,h.jsx)(_0,{fieldPrefix:`items.${w.id}.values`,keywords:t.map(t=>({name:t,value:w.values[t]??``,feeds:n.get(t)??[],topic:e.includes(t)})),problem:e=>r(e.replace(`items.${w.id}.`,`items.${String(C+1)}.`)),onChange:(e,t)=>y(v.map(n=>n.id===w.id?{...n,values:{...n.values,[e]:t}}:n))})]}):null})]})}function Age(){let e=Zi();return(0,h.jsx)(jge,{onCreated:t=>{e({to:`/projects/$projectId`,params:{projectId:t}})}})}function jge({onCreated:e}){let{api:t}=z(),n=lI(),r=N(eb(t)),i=N(nb(t)),a=N(rb(t)),o=N(tb(t)),s=N(ob(t)),c=N(Zb(t)),l=N(Hq(t)),u=N({queryKey:sN,queryFn:()=>cN(t),staleTime:6e4}),[d,f]=cP(),p=H3(),g=rP(),{document:_}=g,v=Ege(_.librarySnapshot,i.data?.prompts??[],a.data?.entries??[]),y=_.variants.map(({id:e,...t})=>({...t,key:e})),b=g.fontUploading||_.fontUpload!==null,x=g.review.fields,[S,C]=(0,m.useState)(new Set),[w,T]=(0,m.useState)(new Set),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,ee]=(0,m.useState)(!1),[te,ne]=(0,m.useState)(null),j=(0,m.useRef)(null),re=(0,m.useRef)(null),M=(0,m.useRef)(null),ie=Zi(),ae=(0,m.useRef)(g.activeId);(0,m.useLayoutEffect)(()=>{ae.current!==g.activeId&&(ae.current=g.activeId,C(new Set),k(null))},[g.activeId]);let oe=e=>{f(t=>{let n={...t,...e};return{...n,subtitles:ON(n.subtitles,n.sources)}}),g.invalidateReview(!0)},se=s.data?.silenceGapSeconds??3,ce=_.form.silenceGapSeconds?.trim()??``,le={form:d,prompts:v.prompts,entries:v.entries,silenceGapSeconds:ce===``?se:Number(ce)},{fields:ue,result:de,blocker:fe}=Ede(le),pe=h0(le),me=z3(d.title).filter(e=>ue.some(t=>t.name===e)),he=b?{field:`subtitles.fontUpload`,hint:`Wait for the subtitle font upload to finish to play`}:fe;(0,m.useEffect)(()=>{if(!g.review.created)return;let t=g.takeCreated()?.projectIds[0];t&&(n({type:`project-created`,id:t}),e(t))},[g.review.created,g.takeCreated,n,e]);let ge=de.ok?x:[...de.fields,...x],_e=(...e)=>!ge.some(t=>e.some(e=>t.field===e||t.field.startsWith(`${e}.`))),ve=(e,t)=>v.prompts.some(n=>n.kind===e&&n.name===t),ye=e=>e?.file!==void 0&&e.error===void 0;cI({playArticleReady:_e(`sources.article`,`articlePrompt`,`provided.article`)&&(d.sources.article===`provide`||ve(`article`,d.articlePrompt)),playAudioReady:d.sources.audio===`off`||_e(`sources.audio`,`audio`,`provided.audio`)&&(d.sources.audio!==`provide`||ye(d.provided.audio)),playImagesReady:d.sources.images===`off`||_e(`sources.images`,`images`,`imagePrompts`,`provided.images`)&&(d.sources.images===`provide`?d.provided.images.every(ye):d.imagePrompts.every(e=>ve(`image`,e.name))),playVideoReady:_e(`sources.video`),playSubtitlesReady:_e(`subtitles`)&&!b,playOptionsReady:_e(`title`,`format`,`llm`,`intro`,`outro`),playHasKeywords:ue.length>0,playKeywordsReady:_e(`values`),playReady:he===void 0&&!g.review.starting});let be=IN(d,v.entries)[0]?.section??`article`,xe=e=>Ume(e,d)??zhe(e,d,y,v.entries),Se=e=>{let t=xe(e).field;return ge.find(n=>xe(n.field).field===t&&(x.includes(n)||S.has(e)||S.has(t)))?.message},Ce=e=>{let t=xe(e);C(n=>new Set([...n,e,t.field])),g.navigate(t.field.startsWith(`items.`)?`content`:t.section,t.field)},we=[r,i,a,o,s].every(e=>e.isSuccess||e.isError),Te=(0,m.useRef)(null),Ee=g.generation();(0,m.useEffect)(()=>{if(!we)return;let e=Te.current;Te.current={generation:Ee,id:g.activeId},(e===null||e.generation!==Ee||e.id!==g.activeId&&e.id!==null)&&T(new Set(X6.map(e=>e.id).filter(e=>e!==`reviews`&&$6(e,ge,me,be)!==void 0)))},[we,g.activeId,Ee]);let De=(0,m.useRef)(null);(0,m.useLayoutEffect)(()=>{let e=g.reveal;if(e||(De.current=null),!e||e.sequence===De.current||!j.current)return;let t=e.field,n=t?/^items\.([^.]+)(\.|$)/.exec(t)?.[1]:void 0;if(e.section===`review`){if(De.current=e.sequence,t&&B6(j.current,t))return;M.current?.focus();return}if(n!==void 0&&_.variants.some(e=>e.id===n)){if(O!==n){k(n);return}}else if(!(t&&me.some(e=>t===`values.${e}`))){let n=t?Q6(t,be):void 0,r=(n===void 0?Sge(e.section):[n]).filter(e=>!w.has(e));if((t!==`title`||me.length!==0)&&r.length>0){T(e=>new Set([...e,...r]));return}}De.current=e.sequence,!(t&&B6(j.current,t))&&re.current?.focus()},[g.reveal,w,O]);let Oe=async e=>{await g.flush()&&(e===`/prompts`?await ie({to:`/prompts/new`,search:{kind:`article`}}):await ie({to:e}))},ke=()=>{g.navigate(`review`)},Ae=(e,t)=>{g.invalidateReview(!0),g.attach(e,t)},je=(e,t)=>{f(n=>({...n,provided:e===`images`?{...n.provided,images:n.provided.images.filter(e=>e.key!==t)}:{...n.provided,[e]:void 0}}))},Me=[r,i,a,o,s].find(e=>e.error!==null)?.error?.message,Ne=g.error?`Your draft wasn't saved. ${g.error}`:Me,Pe={form:d,providers:r.data?.providers??[],prompts:v.prompts,voices:o.data?.voices??[],silenceGapSeconds:s.data?.silenceGapSeconds??3,problem:Se,update:oe,onPickFiles:Ae,onRemoveFile:je,onReattachFile:(e,t,n)=>{g.attach(e,[n],t)}},Fe=l.data?.find(e=>e.id===_.templateSource?.id),Ie=_.channelId??(Fe===void 0?`00000000-0000-4000-8000-000000000001`:o0(Fe)),Le=Object.values(_.form.reviews?.stages??{}).filter(e=>e.mode!==`off`).length,Re={providers:r.data?.providers??[],voices:o.data?.voices??[],keywords:ue.length,topics:me,channel:c.data?.find(e=>e.id===Ie)?.name,brandKit:_.form.useBrandKit!==!1,look:K6(_.form),fontName:u.data?.fonts.find(e=>e.id===d.subtitles.fontId)?.name,checkpoints:d.checkpoints?.length??0,reviews:Le},ze={title:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[me.length?(0,h.jsx)(xV,{label:`Title pattern`,tip:`play.title-pattern`,error:Se(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,value:d.title,maxLength:200,"aria-invalid":Se(`title`)!==void 0,onChange:e=>oe({title:e.target.value})})}):null,(0,h.jsx)(Bhe,{fields:ue,origins:pe,topics:me,hide:me,values:d.values,problem:Se,onChange:(e,t)=>oe({values:{...d.values,[e]:t}})}),ue.length===me.length?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:ue.length===0?`No keywords. A prompt or the title that names {{a keyword}} adds one here.`:`The only keywords are the topic, typed at the top.`}):null]}),article:(0,h.jsx)(Lhe,{...Pe,entries:v.entries,onLibrary:e=>{Oe(e)}}),narration:(0,h.jsx)(Qhe,{...Pe,entries:v.entries,onKeyword:Ce,onSettings:()=>{Oe(`/settings`)}}),images:(0,h.jsx)($he,{...Pe}),video:(0,h.jsx)(ege,{...Pe,problemOf:Se}),outputs:(0,h.jsx)(tge,{...Pe,entries:v.entries,onSettings:()=>{Oe(`/settings`)}}),reviews:void 0,channel:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(Vme,{}),(0,h.jsx)(Hme,{})]})},Be=X6.filter(e=>e.id!==`narration`||d.sources.article!==`off`),Ve=Be.map(e=>({id:e.id,label:e.label,summary:Cge(e.id,d,Re),problem:$6(e.id,ge,me,be)?.message,editor:ze[e.id]})),He=(e,t)=>{if(e===`reviews`){ke();return}T(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},Ue=e=>{He(e,!0),requestAnimationFrame(()=>{j.current?.querySelector(`[data-setup-row="${e}"]`)?.scrollIntoView({block:`start`,behavior:`smooth`})})},We=_.variants.length+1,Ge=YN(_,g.view),Ke=!g.review.starting&&(g.review.uncertain||g.review.valid&&!g.review.pending&&ge.length===0&&!Ge);bx({id:`play.start`,title:qN(g.review,_),group:`Play`,context:d.title||`New project`,keywords:[`start`,`queue`,`run`,`play`,`go`],run:()=>{Ke?g.startRun():he?Ce(he.field):ge[0]&&Ce(ge[0].field)}}),bx({id:`play.add-topic`,title:`Add a topic for another video`,group:`Play`,context:`${String(We)} video${We===1?``:`s`}`,keywords:[`more videos`,`variation`,`batch`,`queue`],run:()=>D(!0)}),bx({id:`play.save-template`,title:`Save as template`,group:`Play`,keywords:[`template`,`setup`,`reuse`],run:()=>ee(!0)}),bx({id:`play.review`,title:`Review the whole setup`,group:`Play`,keywords:[`summary`,`checkpoints`,`prompt`],shortcut:lP.reviewSetup,run:ke}),bx({id:`play.template`,title:`Pick a template`,group:`Play`,keywords:[`template`,`setup`],run:()=>{j.current&&B6(j.current,`template`)}});let qe=d.sources.video===`generate`&&d.sources.images!==`off`,Je=ige(d,p),Ye=qe?(0,h.jsx)(O6,{drawnOn:Je?.drawnOn,settings:{format:d.format,subtitles:{mode:d.sources.audio===`off`?`off`:d.subtitles.mode,fontId:d.subtitles.fontId,fontSize:Number(_.form.subtitles.fontSize)||d.subtitles.fontSize,position:d.subtitles.position},videoEdit:d.videoEdit,previewText:_.previewText,image:Je?.image}}):null;return(0,h.jsxs)(`div`,{ref:j,onBlurCapture:e=>{let t=e.target.dataset.playField;t&&C(e=>new Set([...e,t]))},"data-play-grid":`true`,className:`min-w-0 max-[767px]:[&_button]:min-h-11 max-[767px]:[&_input:not([type=checkbox])]:min-h-11 max-[767px]:[&_select]:min-h-11 max-[767px]:[&_summary]:min-h-11`,children:[(0,h.jsx)(kq,{crumb:`New project`,title:(0,h.jsx)(`span`,{ref:re,tabIndex:-1,children:`What's the video about?`}),meta:d.title.trim()===``?`Untitled draft`:d.title,actions:(0,h.jsx)(Rhe,{})}),(0,h.jsx)(B3,{onDefaults:g.adoptDefaults}),(0,h.jsxs)(Aq,{className:`sl-workspace--play`,aside:(0,h.jsx)(Tge,{errors:ge,blocker:he,saveProblem:Ne,onReveal:Ce,onWholeSetup:ke,onSaveTemplate:()=>ee(!0),preview:Ye}),asideLabel:`Review and start`,children:[(0,h.jsxs)(`div`,{"data-tour":`play-options`,className:`grid min-w-0 grid-cols-1 items-start gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(Dge,{topics:me,onError:ne}),(0,h.jsx)(Oge,{topics:me,problem:Se})]}),(0,h.jsx)(yge,{topics:me}),te?(0,h.jsx)(SI,{tone:`danger`,title:te}):null,(0,h.jsx)(kge,{topics:me,keywordNames:ue.map(e=>e.name),origins:pe,problem:Se,adding:E,onAdding:D,open:O,onOpen:k}),(0,h.jsx)(bge,{rows:Ve,open:w,onChange:He})]}),(0,h.jsx)(YP,{open:g.section===`review`,title:`Review`,headingRef:M,onClose:()=>{g.navigate(`content`)},children:(0,h.jsx)(fge,{fields:ue,errors:ge,problem:Se,onReveal:Ce})}),(0,h.jsx)(mge,{open:A,onClose:()=>ee(!1)}),Be.map(e=>(0,h.jsx)(Mge,{id:e.id,label:e.label,onOpen:Ue},e.id))]})}function Mge({id:e,label:t,onOpen:n}){return bx({id:`play.row.${e}`,title:`Change ${t.toLowerCase()}`,group:`Play`,keywords:[`open`,`edit`,`section`,t],run:()=>n(e)}),null}function Nge(){let{api:e}=z(),t=N({queryKey:[`batch-queue`],queryFn:async()=>F(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=N(Yy(e)),r=t.data?.queue.length??0;return(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,disabled:r===0,"aria-label":`Video queue: ${r} remaining`,children:[(0,h.jsx)(Ec,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,r]})]})}),(0,h.jsxs)(Eb,{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:pb(`play.queue`).body}),(0,h.jsx)(Pge,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function Pge({queue:e,projects:t}){return(0,h.jsx)(`ol`,{className:`max-h-40 overflow-y-auto px-4 py-2`,children:e.map((e,n)=>{let r=t?.find(t=>t.id===e.projectId);return(0,h.jsxs)(`li`,{className:`flex justify-between gap-3 py-1 text-small`,children:[(0,h.jsxs)(ha,{className:`truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[n+1,`. `,r?.title??`Video`]}),(0,h.jsx)(`span`,{className:`shrink-0 text-ink-2`,children:r?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`})]},e.projectId)})})}function e8({label:e,className:t,children:n}){return(0,h.jsx)(`nav`,{"aria-label":e,className:L(`sl-rail`,t),children:n})}function Fge({icon:e,meta:t,children:n}){return(0,h.jsxs)(h.Fragment,{children:[e,(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:n}),t===void 0?null:(0,h.jsx)(`span`,{className:`sl-rail__meta`,children:t})]})}function t8({icon:e,meta:t,current:n=!1,onClick:r,className:i,children:a,"data-tour":o}){return(0,h.jsx)(`button`,{type:`button`,"data-tour":o,"aria-current":n?`true`:void 0,onClick:r,className:L(`sl-rail__item w-full border-0 bg-transparent text-left font-[inherit]`,n&&`bg-accent-tint font-semibold text-ink`,i),children:(0,h.jsx)(Fge,{icon:e,meta:t,children:a})})}var n8=/^(?:[-*+]|\d+[.)])\s+/u;function Ige(e){let t=e.split(/\r?\n/u).filter(e=>e.trim()!==``),n=[];for(let e of t.slice(1)){let t=e.trim().replace(n8,``).trim(),r=n.length-1;/^\s/u.test(e)&&!n8.test(e.trim())&&r>=0?n[r]=`${n[r]??``} ${t}`:t!==``&&n.push(t)}return n}var Lge={blockquote:o8,break:Hge,code:s8,definition:s8,delete:o8,emphasis:o8,footnoteReference:s8,footnoteDefinition:s8,heading:Vge,html:s8,image:i8,imageReference:i8,inlineCode:a8,list:o8,listItem:o8,link:o8,linkReference:o8,strong:o8,table:s8,tableCell:s8,text:a8,thematicBreak:s8,toml:s8,yaml:s8},Rge={},r8=[];function zge(e){let t={...Lge},n=e||Rge,r=n.keep||r8,i=n.remove||r8,a=-1;for(;++a<i.length;){let e=i[a];typeof e==`string`?t[e]=s8:t[e[0]]=e[1]}let o={};if(r.length===0)o=t;else{let e;for(e in t)r.includes(e)||(o[e]=t[e]);for(a=-1;++a<r.length;)if(e=r[a],!Object.hasOwn(t,e))throw Error("Unknown node type `"+e+"` in `keep`, use a replace tuple with a handle instead: `remove: [['"+e+"', handle]]`")}return function(e){return s(e)};function s(e){let t=e.type,n=e;if(Object.hasOwn(o,t)){let e=o[t];e&&(n=e(n)||void 0)}return n=Array.isArray(n)?c(n):n,n&&`children`in n&&(n.children=c(n.children)),n}function c(e){let t=-1,n=[];for(;++t<e.length;){let r=s(e[t]);Array.isArray(r)?n.push(...c(r)):r&&n.push(r)}return Bge(n)}}function Bge(e){let t=-1,n=[],r;for(;++t<e.length;){let i=e[t];r&&i.type===r.type&&`value`in i&&`value`in r?r.value+=i.value:(n.push(i),r=i)}return n}function i8(e){let t=`title`in e?e.title:``,n=e.alt||t||``;return n?{type:`text`,value:n}:void 0}function a8(e){return{type:`text`,value:e.value}}function Vge(e){return{type:`paragraph`,children:e.children}}function o8(e){return e.children}function Hge(){return{type:`text`,value:`
283
- `}}function s8(){}var Uge=64,c8=new Map;function Wge(e){let t=c8.get(e);if(t!==void 0)return t;let n=Gge(e);for(c8.set(e,n);c8.size>Uge;){let e=c8.keys().next().value;if(e===void 0)break;c8.delete(e)}return n}function Gge(e){let t=r6().use(pB).use(zge),n=t.runSync(t.parse(e)).children.map(e=>{if(e.type!==`paragraph`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.children.map(e=>{if(e.type!==`text`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.value}).join(``)}).filter(e=>e.trim()!==``);return n.length===0?``:n.join(`
280
+ `).entries()){let e=n.trim(),c=t+1;if(e===``){s=!1;continue}let l=che.exec(e);if(l!==null){o.push({title:d6(l[1]??``),firstTurn:a.length+1}),s=!1;continue}if(/^([-*_=~])\1{2,}$/.test(e)){s=!1;continue}let u=lhe.exec(e),d=u===null?void 0:r.get((u[1]??``).trim().toLowerCase());if(u!==null&&d!==void 0){a.push({speaker:d.id,lines:[u[2]??``],section:o.length-1}),s=!0;continue}let f=a.at(-1);if(s&&f!==void 0){f.lines.push(e);continue}return{ok:!1,reason:u===null?`Line ${String(c)} of the script is not a turn. Start every turn with a speaker's name and a colon (${i}), one turn per paragraph.`:`Line ${String(c)} of the script is spoken by "${(u[1]??``).trim()}", who is not one of the speakers (${i}). Use only these names, or add the speaker under Speakers (Play → Narration, or Edit project → Providers).`}}let c=[];for(let e of a){let t=d6(e.lines.join(` `));t!==``&&c.push({index:c.length+1,speaker:e.speaker,text:t,section:e.section,...n?{markdown:e.lines.join(`
281
+ `)}:{}})}if(c.length===0)return{ok:!1,reason:`The script has no spoken turns. Write each turn as a speaker's name, a colon and their words (${i}).`};let l=[],u=new Map;for(let[e,t]of o.entries()){let n=c.find(t=>t.section===e);n!==void 0&&t.title!==``&&(u.set(e,l.length),l.push({title:t.title,firstTurn:n.index}))}return{ok:!0,script:{turns:c.map(e=>({...e,section:u.get(e.section)??-1})),sections:l}}}function d6(e){return e.replace(/\[[^\]]*\]\([^)]*\)/g,e=>e.slice(1,e.indexOf(`]`))).replace(/\[[^\]]*\]/g,` `).replace(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g,`$2`).replace(/`/g,``).replace(/\s+/g,` `).trim()}var uhe={narrator:`Narrator`,host:`Host`,guest:`Guest`,character:`Character`};function f6({value:e,onChange:t,providers:n,voices:r,script:i,problem:a,cast:o=[],language:s}){let c=(0,m.useMemo)(()=>{if(e===void 0||i===void 0||i.trim()===``)return;let t=u6(i,e.speakers);return t.ok?t.script:void 0},[i,e]),l=n=>{if(n===``){t(void 0);return}let r=EA.find(e=>e===n);r!==void 0&&t(e===void 0?zA(r,ihe(o)):{...e,format:r,source:r===`audiobook`?e.source:`script`})},u=n=>{e!==void 0&&t({...e,...n})},d=o.filter(t=>t.voice!==void 0&&!(e?.speakers??[]).some(e=>e.castId===t.id)),f=(t,n)=>{e!==void 0&&u({speakers:e.speakers.map((e,r)=>r===t?n:e)})};return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-3`,"data-play-field":`voices`,children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(FV,{field:`voices.format`,label:`Format`,tip:`play.speakers.format`,value:e?.format??``,placeholder:`Narration (one voice)`,options:EA.map(e=>({value:e,label:DA[e]})),problem:a?.(`voices.format`),onPick:l}),e?.format===`audiobook`?(0,h.jsx)(FV,{field:`voices.source`,label:`Script`,tip:`play.speakers.script`,value:e.source,placeholder:`Pick where the script comes from`,options:[{value:`script`,label:`Write a script (Script prompt)`},{value:`attribute`,label:`Split the article into speakers`}],problem:a?.(`voices.source`),onPick:e=>u({source:e===`attribute`?`attribute`:`script`})}):null]}),e===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`One voice reads the article. Pick a format for an audiobook, podcast, radio drama or interview with several speakers.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.source===`script`?"The article prompt must be a Script prompt: the text model writes speaker turns, one `Name: words` paragraph each.":`The article is written or pasted as usual; the text model then hands its narration and dialogue to the speakers.`}),a?.(`voices.speakers`)===void 0?null:(0,h.jsx)(`p`,{className:`text-label text-danger`,children:a(`voices.speakers`)}),(0,h.jsx)(`ol`,{"aria-label":`Speakers`,className:`divide-y divide-line border-y border-line`,children:e.speakers.map((t,i)=>(0,h.jsx)(mhe,{index:i,speaker:t,line:nhe(t,c),providers:n,voices:r,language:s,problem:a,onChange:e=>f(i,e),onRemove:e.speakers.length>1?()=>u({speakers:e.speakers.filter((e,t)=>t!==i)}):void 0},t.id))}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsx)(R,{type:`button`,disabled:e.speakers.length>=10,onClick:()=>u({speakers:[...e.speakers,phe(e.speakers)]}),children:`Add speaker`}),(0,h.jsx)(FV,{label:`Add from the cast`,tip:`play.speakers.add-from-cast`,value:``,placeholder:d.length===0?`No cast member has a voice yet`:`Pick one of ${String(d.length)}`,options:d.map(e=>({value:e.id,label:e.name})),disabled:d.length===0||e.speakers.length>=10,problem:void 0,onPick:t=>{let n=d.find(e=>e.id===t);n!==void 0&&u({speakers:[...e.speakers,l6(n,fhe(e))]})}}),(0,h.jsx)(FV,{field:`voices.turnGapSeconds`,label:`Gap between turns`,tip:`play.speakers.turn-gap`,value:String(e.turnGapSeconds),placeholder:`Pick a gap`,options:jA.map(e=>({value:String(e),label:`${e} s`})),problem:a?.(`voices.turnGapSeconds`),onPick:e=>u({turnGapSeconds:Number(e)})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{label:`Speaker names on captions`,tip:`play.speakers.name-tags`,checked:e.nameTags,onChange:e=>u({nameTags:e})}),(0,h.jsx)(kb,{label:`One request for consecutive turns where the voice provider can (ElevenLabs v3, Gemini)`,tip:`play.speakers.native-dialogue`,checked:e.nativeDialogue,onChange:e=>u({nativeDialogue:e})}),(0,h.jsx)(kb,{label:`Also make MP3 and M4B files with chapter markers`,tip:`play.speakers.audio-files`,checked:e.audioFiles,onChange:e=>u({audioFiles:e})})]}),e.format===`audiobook`?(0,h.jsx)(dhe,{value:e,onChange:t,problem:a}):null,e.format===`podcast`||e.format===`interview`?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The speaker panel (a tile per speaker, the one talking lit, their name below) is drawn with the captions: set Captions to Burn in under Style to see it in the video.`}):null]})]})}function dhe({value:e,onChange:t,problem:n}){let r=e.book,i=n=>t({...e,...n});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(kb,{label:`A chapter of a book`,tip:`play.speakers.book`,checked:r!==void 0,onChange:n=>{if(n)i({book:{title:``,chapter:1}});else{let{book:n,...r}=e;t(r)}}}),r===void 0?null:(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[700px]:grid-cols-[minmax(0,1fr)_160px]`,children:[(0,h.jsx)(xV,{label:`Book title`,tip:`play.speakers.book-title`,error:n?.(`voices.book.title`),children:(0,h.jsx)(CV,{value:r.title,maxLength:200,onChange:e=>i({book:{...r,title:e.target.value}})})}),(0,h.jsx)(xV,{label:`Chapter`,tip:`play.speakers.book-chapter`,error:n?.(`voices.book.chapter`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:FA,step:1,value:r.chapter===0?``:String(r.chapter),onChange:e=>i({book:{...r,chapter:Number(e.target.value)||0}})})})]})]})}function fhe(e){return e.format===`podcast`?`host`:e.format===`interview`?e.speakers.some(e=>e.role===`host`)?`guest`:`host`:e.speakers.some(e=>e.role===`narrator`)?`character`:`narrator`}function phe(e){let t=e.length+1;for(;e.some(e=>e.id===`speaker-${String(t)}`);)t+=1;return{id:`speaker-${String(t)}`,name:`Speaker ${String(t)}`,role:`character`,voice:{provider:``,model:``,voice:``}}}function mhe({index:e,speaker:t,line:n,providers:r,voices:i,language:a,problem:o,onChange:s,onRemove:c}){let l=`voices.speakers.${String(e)}`,u=t.voice,d=i.filter(e=>e.provider===u.provider),f=F2(d,a,u.voice||void 0),p=a===void 0?d:f.listed,g=t.name.trim()||`this speaker`,_=(0,m.useMemo)(()=>the([t],a??`und`)[0]?.skipped??[],[t,a]);return(0,h.jsxs)(`li`,{className:`grid grid-cols-1 gap-3 py-3 min-[700px]:grid-cols-2`,"data-play-field":l,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-end gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`mb-2 size-3 shrink-0 rounded-full`,style:{background:`var(--color-speaker-${String(e%6+1)})`}}),(0,h.jsx)(xV,{label:`Speaker name`,tip:`play.speaker.name`,error:o?.(`${l}.name`),className:`min-w-0 flex-1`,children:(0,h.jsx)(CV,{value:t.name,maxLength:40,onChange:e=>s({...t,name:e.target.value})})})]}),(0,h.jsx)(FV,{label:`Role`,tip:`play.speaker.role`,value:t.role,placeholder:`Pick a role`,options:OA.map(e=>({value:e,label:uhe[e]})),problem:void 0,onPick:e=>{let n=OA.find(t=>t===e);n!==void 0&&s({...t,role:n})}}),(0,h.jsx)(RV,{field:`${l}.voice`,label:`Voice provider`,tip:`play.speaker.provider`,family:`tts`,providers:r,value:u.provider,problem:o?.(`${l}.voice`),onPick:e=>s({...t,voice:{provider:e,model:``,voice:``}})}),(0,h.jsx)(zV,{label:`Voice model`,tip:`play.speaker.model`,provider:u.provider,value:u.model,problem:void 0,onPick:e=>s({...t,voice:{...u,model:e}})}),(0,h.jsx)(FV,{field:`${l}.voice.voice`,label:`Voice`,tip:`play.speaker.voice`,value:u.voice,placeholder:p.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:p.map(e=>({value:e.voiceId,label:e.name})),problem:o?.(`${l}.voice.voice`),onPick:e=>s({...t,voice:{...u,voice:e}})}),a===void 0?null:(0,h.jsx)(I2,{language:a,voice:d.find(e=>e.voiceId===u.voice),hidden:f.hidden,showAll:f.showAll,onShowAll:f.setShowAll}),(0,h.jsx)(FV,{field:`${l}.pace`,label:`Pace`,tip:`play.speaker.pace`,value:String(t.pace??1),placeholder:`Pick a pace`,options:AA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:o?.(`${l}.pace`),onPick:e=>{let{pace:n,...r}=t;s(Number(e)===1?r:{...r,pace:Number(e)})}}),(0,h.jsxs)(`details`,{className:`col-span-full text-small`,...Ob,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-ink-2`,children:[`Pronunciations for `,t.name.trim()||`this speaker`,t.pronunciations?.trim()?` · set`:``,(0,h.jsx)(V,{id:`play.speaker.pronunciations`})]}),(0,h.jsx)(wV,{rows:3,"aria-label":`Pronunciations for ${t.name.trim()||`this speaker`}`,value:t.pronunciations??``,placeholder:`Arda: /ˈɑɹdə/`,onChange:e=>{let{pronunciations:n,...r}=t;s(e.target.value===``?r:{...r,pronunciations:e.target.value})}})]}),_.length===0?null:(0,h.jsxs)(SI,{tone:`waiting`,className:`col-span-full`,title:`${String(_.length)} ${_.length===1?`pronunciation`:`pronunciations`} for ${g} ${_.length===1?`is`:`are`} skipped`,children:[(0,h.jsx)(`ul`,{children:_.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsxs)(`p`,{children:[`Those words are read as ordinary text; the other entries are used. Fix them in Pronunciations for `,g,` above: one `,(0,h.jsx)(`code`,{children:`Term: /IPA/`}),` per line.`]})]}),(0,h.jsxs)(`div`,{className:`col-span-full flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(ghe,{speaker:t,line:n}),(0,h.jsx)(`span`,{className:`flex-1`}),c===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:c,children:[`Remove `,t.name.trim()||`speaker`]})]})]})}var hhe=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:4});function ghe({speaker:e,line:t}){let{api:n}=z(),{provider:r,model:i,voice:a}=e.voice,o=r!==``&&i!==``&&a!==``,s=N({queryKey:[`audition-quote`,r,i,t],queryFn:()=>Us(n,[{speaker:e.name.trim()||`Speaker`,provider:r,model:i,text:t}]),enabled:o,staleTime:6e4}),[c,l]=(0,m.useState)(void 0);(0,m.useEffect)(()=>()=>{c!==void 0&&URL.revokeObjectURL(c)},[c]);let u=P({mutationFn:()=>Ws(n,{provider:r,model:i,voice:a,text:t}),onSuccess:e=>{let t=URL.createObjectURL(e);l(t),new Audio(t).play().catch(()=>{})}}),d=s.data?.estimate,f=d==null?void 0:d.unknown>0?`price unknown`:`about ${hhe.format(d.high)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:!o||u.isPending,onClick:()=>u.mutate(),title:`Reads: ${t}`,children:u.isPending?`Speaking…`:`Audition${f===void 0?``:` · ${f}`}`}),(0,h.jsx)(V,{id:`play.speaker.audition`})]}),(0,h.jsx)(`span`,{className:`min-h-5 text-label text-ink-2`,"aria-live":`polite`,children:o?u.error===null?c===void 0?`Reads their first line: “${t.length>60?`${t.slice(0,60)}…`:t}”`:`Playing the audition.`:u.error.message:`Pick a provider, model and voice to audition.`})]})}function _he(e){return e===void 0?`Narration`:DA[e]}function p6({value:e,skipCode:t,onChange:n,tip:r=`play.describe-figures`}){let i=(0,m.useId)(),a=e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.describeFigures`,checked:a,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:e.currentTarget.checked,skipCode:t===!0})}),`Describe tables and figures in the narration`]}),(0,h.jsx)(V,{id:r})]}),a?(0,h.jsxs)(`span`,{className:`flex items-center gap-1 pl-7`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-code`,className:`flex min-h-10 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-code`,type:`checkbox`,"data-play-field":`audio.skipCode`,checked:t===!0,className:`size-4 accent-accent`,onChange:e=>n({describeFigures:!0,skipCode:e.currentTarget.checked})}),`Leave code out`]}),(0,h.jsx)(V,{id:`play.skip-code`})]}):null]})}function m6({value:e,onChange:t,tip:n=`play.show-figures`}){let r=(0,m.useId)();return(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`showFigures`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Show tables and figures on screen`]}),(0,h.jsx)(V,{id:n})]})}function h6({value:e,onChange:t,note:n}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:r,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:r,type:`checkbox`,"data-play-field":`audio.useNarrationAliases`,checked:e===!0,className:`size-4 accent-accent`,onChange:e=>t(e.currentTarget.checked)}),`Use narration aliases`]}),(0,h.jsx)(V,{id:`play.narration-aliases`})]}),n===void 0?null:(0,h.jsx)(`div`,{className:`pl-7`,children:n})]})}function g6({value:e,prompts:t,supported:n,error:r,libraryLinks:i=!0,onChange:a}){let o=(0,m.useId)(),s=t.filter(e=>e.kind===`narration`),c=s.find(t=>t.name===e),l=r??(e!==``&&!n?`Choose Inworld TTS-2 or turn preparation Off.`:void 0);return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:o,className:`text-small font-semibold`,children:`Narration Preparation`}),(0,h.jsx)(V,{id:`play.narration-preparation`})]}),(0,h.jsxs)(DV,{id:o,"data-play-field":`narrationPrompt`,value:e,"aria-describedby":l?`${o}-error`:void 0,"aria-invalid":l!==void 0||void 0,onChange:e=>a(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),e!==``&&c===void 0?(0,h.jsxs)(`option`,{value:e,children:[e,` (saved selection)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`text-small text-danger`,children:l}):null,i?(0,h.jsxs)(`div`,{className:`flex gap-4 text-small`,children:[(0,h.jsx)(ha,{to:`/prompts/new`,search:{kind:`narration`},children:`Create prompt`}),c?(0,h.jsx)(ha,{to:`/prompts/$promptId`,params:{promptId:c.id},children:`View prompt`}):null]}):null]})}function _6({value:e,supported:t,onChange:n,shared:r}){let i=(0,m.useId)(),a=t&&e===!0;return(0,h.jsxs)(`div`,{className:`col-span-full min-w-0 space-y-2`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,"data-play-field":`audio.usePronunciationGlossary`,checked:e===!0,disabled:!t,"aria-describedby":t?void 0:`${i}-support`,className:`size-4 accent-accent`,onChange:e=>n(e.currentTarget.checked)}),`Use Pronunciation Glossary`]}),(0,h.jsx)(V,{id:`play.pronunciation-glossary`})]}),r===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-1 pl-7`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-shared`,className:`flex min-h-8 items-center gap-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${i}-shared`,type:`checkbox`,"data-play-field":`audio.shareGlossary`,checked:r.value===!0,disabled:!a,className:`size-4 accent-accent`,onChange:e=>r.onChange(e.currentTarget.checked)}),`Also use pronunciations from my other projects`]}),(0,h.jsx)(V,{id:`play.share-glossary`})]}),r.note===void 0?null:r.note]}),t?null:(0,h.jsx)(`p`,{id:`${i}-support`,className:`text-label text-ink-3`,children:`Unavailable for this provider or model. Your saved preference is retained.`})]})}var v6={source:`off`,prompt:``,thumbnail:!0},vhe=[{value:`prompt`,label:`From a prompt`},{value:`provide`,label:`Upload`}];function y6({value:e,prompts:t,problem:n,upload:r,prompt:i,onChange:a}){let o=(0,m.useId)(),s=e.source===`off`,c=t.filter(e=>e.kind===`image`).map(e=>({value:e.name,label:e.name}));return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsx)(`div`,{className:`min-w-0`,children:(0,h.jsx)(FV,{field:`reference.source`,label:`Establishing image`,tip:`play.reference`,value:s?``:e.source,placeholder:`Off`,options:vhe,problem:n?.(`reference.source`),onPick:t=>a({...e,source:t===`prompt`||t===`provide`?t:`off`})})}),e.source===`provide`?(0,h.jsx)(`div`,{className:`min-w-0`,children:r}):i??(0,h.jsx)(FV,{field:`reference.prompt`,label:`Establishing prompt`,tip:`play.reference.prompt`,value:e.prompt,placeholder:s?`Off`:`Pick an image prompt`,options:c,disabled:s,problem:n?.(`reference.prompt`),onPick:t=>a({...e,prompt:t})}),(0,h.jsxs)(`div`,{className:`col-span-full flex min-h-9 items-center gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:o,className:`flex cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{id:o,type:`checkbox`,"data-play-field":`reference.thumbnail`,checked:e.thumbnail,disabled:s,onChange:t=>a({...e,thumbnail:t.target.checked})}),`Draw the thumbnail from it too`]}),(0,h.jsx)(V,{id:`play.reference.thumbnail`})]})]})}function b6({choice:e,onChange:t,field:n=`llm.thinking`,label:r=`Thinking`,tip:i=`play.llm.thinking`,problem:a}){let{api:o}=z(),s=N(AV(o,e.provider)).data?.models.find(t=>t.id===e.model)?.thinkingModes??[];if(!s.length&&!e.thinking)return null;let c=r===`Thinking`?`thinking level`:r.toLowerCase();return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(FV,{field:n,label:r,tip:i,value:e.thinking??`default`,placeholder:`Model default`,problem:e.thinking&&!s.includes(e.thinking)?`Choose a supported ${c}.`:a,options:[{value:`default`,label:`Model default`},...e.thinking&&!s.includes(e.thinking)?[{value:e.thinking,label:`${e.thinking} (saved level)`}]:[],...s.map(e=>({value:e,label:e===`off`?`Off`:e.charAt(0).toUpperCase()+e.slice(1)}))],onPick:n=>{let r=s.find(e=>e===n),{thinking:i,...a}=e;t(r===void 0?a:{...a,thinking:r})}}),r===`Thinking`&&s.length&&!s.includes(`off`)?(0,h.jsx)(`p`,{className:`mt-1 text-small text-ink-3`,children:`This model does not support turning thinking off.`}):null]})}function yhe({form:e,prompts:t,providers:n,voices:r,problem:i,update:a,onPickFiles:o,onRemoveFile:s,onReattachFile:c,rawCounts:l,advanced:u,cast:d,language:f,titled:p}){let g=r.filter(t=>t.provider===e.audio.provider),_=F2(g,f??`en`,e.audio.voice||void 0),v=f===void 0?g:_.listed,y=e.voices?.speakers.find(e=>e.voice.provider&&e.voice.model&&e.voice.voice)?.voice,b=e.intro!==``||e.outro!==``,x=e.voices!==void 0&&!b&&y!==void 0;(0,m.useEffect)(()=>{if(!x||y===void 0)return;let t=e.audio;(t.provider!==y.provider||t.model!==y.model||t.voice!==y.voice)&&a({audio:{...t,provider:y.provider,model:y.model,voice:y.voice}})},[x,y,e.audio,a]);let S=e.voices!==void 0,C=[e.chunking.mode,e.intro?`intro ${e.intro}`:void 0,e.outro?`outro ${e.outro}`:void 0,e.narrationPrompt?`preparation on`:void 0,e.audio.usePronunciationGlossary?`glossary on`:void 0].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(e6,{kind:`audio`,name:`Audio`,dim:e.sources.audio===`off`,titled:p,children:[(0,h.jsx)(t6,{kind:`audio`,form:e,update:a}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[x?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`audio.provider`,label:S?`Intro and outro TTS`:`TTS`,tip:`play.tts.provider`,family:`tts`,providers:n,value:e.audio.provider,problem:i(`audio`),onPick:t=>{a({audio:{...e.audio,provider:t,model:``,voice:``}})}}),(0,h.jsx)(zV,{field:`audio.model`,label:`TTS model`,tip:`play.tts.model`,provider:e.audio.provider,value:e.audio.model,problem:i(`audio.model`),onPick:t=>a({audio:{...e.audio,model:t}})}),(0,h.jsx)(FV,{field:`audio.voice`,label:S?`Intro and outro voice`:`Voice`,tip:`play.voice`,value:e.audio.voice,placeholder:v.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:v.map(e=>({value:e.voiceId,label:e.name})),problem:i(`audio.voice`),onPick:t=>{a({audio:{...e.audio,voice:t}})}}),f===void 0?null:(0,h.jsx)(I2,{language:f,voice:g.find(t=>t.voiceId===e.audio.voice),hidden:_.hidden,showAll:_.showAll,onShowAll:_.setShowAll}),S?(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`This voice reads only the intro and outro. Each speaker's voice is set under Speakers.`}):null]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Speakers ·`,` `,e.voices===void 0?`Narration, one voice`:`${_he(e.voices.format)}, ${String(e.voices.speakers.length)} ${e.voices.speakers.length===1?`speaker`:`speakers`}`]}),(0,h.jsx)(`div`,{className:`pt-2 pb-3`,children:(0,h.jsx)(f6,{value:e.voices,providers:n,voices:r,script:e.sources.article===`provide`?e.provided.article:void 0,problem:i,cast:d,language:f,onChange:e=>a({voices:e})})})]}),(0,h.jsxs)(`details`,{className:`col-span-full rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Audio Advanced · `,C]}),(0,h.jsxs)(`div`,{className:`sl-fields pt-2 pb-3`,children:[(0,h.jsx)(`div`,{className:`col-span-full`,children:(0,h.jsx)(q3,{...l?{rawCounts:l}:{},value:e.chunking,onPick:e=>{a({chunking:e})}})}),u,(0,h.jsx)(g6,{value:e.narrationPrompt??``,prompts:t,supported:e.audio.provider===`inworld`&&e.audio.model===`inworld-tts-2`,error:i(`narrationPrompt`),onChange:e=>a({narrationPrompt:e})}),(0,h.jsx)(_6,{value:e.audio.usePronunciationGlossary,supported:Sj({sources:e.sources,audio:{...e.audio,usePronunciationGlossary:!0}}),onChange:t=>a({audio:{...e.audio,usePronunciationGlossary:t}}),shared:{value:e.audio.shareGlossary??!0,onChange:t=>a({audio:{...e.audio,shareGlossary:t}})}}),(0,h.jsx)(h6,{value:e.audio.useNarrationAliases,onChange:t=>a({audio:{...e.audio,useNarrationAliases:t}})}),(0,h.jsx)(p6,{value:e.audio.describeFigures,skipCode:e.audio.skipCode,onChange:t=>a({audio:{...e.audio,...t}})})]})]})]}):null}),e.sources.audio===`provide`?(0,h.jsxs)(`div`,{className:$3,children:[(0,h.jsx)(Z3,{field:`provided.audio`,label:`Narration file`,accept:`audio/*`,uploads:e.provided.audio===void 0?[]:[e.provided.audio],problem:i(`provided.audio`),onPick:e=>{o(`audio`,e)},onReattach:c?(e,t)=>c(`audio`,e,t):void 0,onRemove:e=>{s(`audio`,e)}}),(0,h.jsx)(`p`,{className:`mt-2 text-small text-ink-2`,children:`Uploaded narration is used as-is; include any intro and outro in that file.`})]}):null]})}function bhe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawNumbers:c,more:l,titled:u}){return(0,h.jsxs)(e6,{kind:`images`,name:`Images`,dim:e.sources.images===`off`,titled:u,children:[(0,h.jsx)(t6,{kind:`images`,form:e,update:i}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.images===`generate`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}),(0,h.jsx)(Y3,{prompts:n.filter(e=>e.kind===`image`),...c?{rawNumbers:c}:{},picked:e.imagePrompts,problem:r,onPick:e=>{i({imagePrompts:e})}}),(0,h.jsx)(xhe,{form:e,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s?{onReattachFile:s}:{}}),l]}):null}),e.sources.images===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.images`,label:`Slideshow images`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,numbered:!0,uploads:e.provided.images,problem:r(`provided.images`),onPick:e=>{a(`images`,e)},onReattach:s?(e,t)=>s(`images`,e,t):void 0,onRemove:e=>{o(`images`,e)}})}):null]})}function x6({form:e,providers:t,problem:n,update:r}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{field:`images.provider`,label:`Provider`,tip:`play.images.provider`,family:`image`,providers:t,value:e.images.provider,problem:n(`images`),onPick:e=>r({images:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`images.model`,label:`Model`,tip:`play.images.model`,provider:e.images.provider,value:e.images.model,problem:n(`images.model`),onPick:t=>r({images:{...e.images,model:t}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:e.images,problem:n(`images.thinking`),onChange:e=>r({images:e})})]})}function xhe({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsx)(y6,{value:e.reference??v6,prompts:t,problem:n,onChange:e=>r({reference:e}),upload:(0,h.jsx)(Z3,{field:`provided.reference`,label:`Establishing image file`,accept:`image/png,image/jpeg`,uploads:e.provided.reference===void 0?[]:[e.provided.reference],problem:n(`provided.reference`),onPick:e=>{i(`reference`,e)},onReattach:o?(e,t)=>o(`reference`,e,t):void 0,onRemove:e=>{a(`reference`,e)}})})}var S6=5e3,She=[`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(`
282
+ `),Che=`Built-in`;function C6({enabled:e,prompt:t,prompts:n,narrated:r,problem:i,onChange:a}){let o=(0,m.useId)(),s=n.filter(e=>e.kind===`description`),c=t!==``&&!s.some(e=>e.name===t),l=i?.(`youtubeDescription`)??i?.(`descriptionPrompt`);return(0,h.jsxs)(`div`,{className:`col-span-full sl-fields`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1 self-end`,...Ob,children:[(0,h.jsxs)(`label`,{htmlFor:`${o}-switch`,className:`flex min-h-10 items-center gap-3 text-small font-semibold max-[1099px]:min-h-11`,children:[(0,h.jsx)(`input`,{id:`${o}-switch`,type:`checkbox`,"data-play-field":`youtubeDescription`,checked:e,disabled:!r&&!e,"aria-describedby":l?`${o}-error`:void 0,className:`size-4 accent-accent`,onChange:e=>a({youtubeDescription:e.currentTarget.checked,descriptionPrompt:t})}),`YouTube description`]}),(0,h.jsx)(V,{id:`play.youtube-description`})]}),(0,h.jsx)(WV,{htmlFor:`${o}-prompt`,label:`Description prompt`,tip:`play.description-prompt`,children:(0,h.jsxs)(DV,{id:`${o}-prompt`,"data-play-field":`descriptionPrompt`,value:t,disabled:!e,onChange:t=>a({youtubeDescription:e,descriptionPrompt:t.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:Che}),c?(0,h.jsxs)(`option`,{value:t,children:[t,` (saved choice)`]}):null,s.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),l?(0,h.jsx)(`p`,{id:`${o}-error`,className:`sl-fields__wide m-0 text-small text-danger`,children:l}):r?null:(0,h.jsx)(`p`,{className:`sl-fields__wide m-0 text-label text-ink-3`,children:`Needs narration.`})]})}function w6({value:e,narrated:t,imageProvider:n,problem:r,onChange:i,fieldPrefix:a=`videoEdit`,language:o}){let s=(0,m.useId)(),c=e??fA,l=e=>i({...c,...e}),{api:u}=z(),d=N(jV(u,n,c.animate!==`off`)),f=e=>r?.(`${a}.${e}`),p=[c.transition===`cut`?void 0:`${_A[c.transition]} ${String(c.transitionSeconds)} s`,c.grade===`none`?void 0:yA[c.grade],c.atmosphere===`none`?void 0:bA[c.atmosphere],c.vignette===`off`?void 0:`Vignette`,c.grain===`off`?void 0:`Grain`,c.chapterCards?`Chapter cards`:void 0,c.animate===`off`?void 0:`Animated images`].filter(e=>e!==void 0),g=[`transition`,`transitionSeconds`,`chapterCards`,`animate`,`animateEvery`,`animateModel`].map(f).filter(e=>e!==void 0),_=d.data?.models??[],v=c.animateModel!==``&&!_.some(e=>e.id===c.animateModel),y=VO(o);return{cuts:(0,h.jsxs)(T6,{id:`${s}-cuts`,label:`Cuts`,tip:`project.video.cuts`,children:[(0,h.jsx)(DV,{id:`${s}-cuts`,"data-play-field":`${a}.cuts`,className:`min-w-0`,value:y===void 0?c.cuts:`interval`,disabled:y!==void 0,"aria-describedby":y===void 0?void 0:`${s}-cuts-note`,onChange:e=>l({cuts:e.target.value}),children:oA.map(e=>(0,h.jsx)(`option`,{value:e,children:gA[e]},e))}),y===void 0?null:(0,h.jsx)(`p`,{id:`${s}-cuts-note`,className:`m-0 basis-full text-small text-ink-3`,children:y})]}),look:(0,h.jsxs)(`details`,{className:`group min-w-0 rounded-control border border-line-strong`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-10 cursor-pointer items-center gap-3 px-3 text-small max-[1099px]:min-h-11`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Look`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-ink-3`,children:p.length===0?`Plain cuts, no effects`:p.join(` · `)})]}),(0,h.jsxs)(`div`,{className:`sl-fields border-line-strong border-t p-3`,children:[(0,h.jsxs)(T6,{id:`${s}-transition`,label:`Transition`,tip:`project.video.transition`,children:[(0,h.jsx)(DV,{id:`${s}-transition`,"data-play-field":`${a}.transition`,className:`min-w-0`,value:c.transition,onChange:e=>l({transition:e.target.value}),children:sA.map(e=>(0,h.jsx)(`option`,{value:e,children:_A[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Transition length`,"data-play-field":`${a}.transitionSeconds`,"aria-invalid":f(`transitionSeconds`)!==void 0,className:`w-24 flex-none`,disabled:c.transition===`cut`,value:String(c.transitionSeconds),onChange:e=>l({transitionSeconds:Number(e.target.value)}),children:hA.map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[e,` s`]},e))})]}),(0,h.jsx)(T6,{id:`${s}-grade`,label:`Colour grade`,tip:`project.video.grade`,children:(0,h.jsx)(E6,{id:`${s}-grade`,field:`${a}.grade`,value:c.grade,options:lA,labels:yA,onChange:e=>l({grade:e})})}),(0,h.jsx)(T6,{id:`${s}-vignette`,label:`Vignette`,tip:`project.video.vignette`,children:(0,h.jsx)(E6,{id:`${s}-vignette`,field:`${a}.vignette`,value:c.vignette,options:cA,labels:vA,onChange:e=>l({vignette:e})})}),(0,h.jsx)(T6,{id:`${s}-grain`,label:`Film grain`,tip:`project.video.grain`,children:(0,h.jsx)(E6,{id:`${s}-grain`,field:`${a}.grain`,value:c.grain,options:cA,labels:vA,onChange:e=>l({grain:e})})}),(0,h.jsx)(T6,{id:`${s}-atmosphere`,label:`Atmosphere`,tip:`project.video.atmosphere`,children:(0,h.jsx)(E6,{id:`${s}-atmosphere`,field:`${a}.atmosphere`,value:c.atmosphere,options:uA,labels:bA,onChange:e=>l({atmosphere:e})})}),(0,h.jsx)(T6,{id:`${s}-cards`,label:`Chapter cards`,tip:`project.video.chapter-cards`,children:(0,h.jsx)(`input`,{id:`${s}-cards`,type:`checkbox`,"data-play-field":`${a}.chapterCards`,className:`size-4 accent-accent`,checked:c.chapterCards,disabled:!t&&!c.chapterCards,onChange:e=>l({chapterCards:e.currentTarget.checked})})}),(0,h.jsxs)(T6,{id:`${s}-animate`,label:`Animate images`,tip:`project.video.animate`,wide:!0,children:[(0,h.jsx)(DV,{id:`${s}-animate`,"data-play-field":`${a}.animate`,"aria-invalid":f(`animate`)!==void 0,className:`min-w-0`,value:c.animate,onChange:e=>l({animate:e.target.value}),children:dA.map(e=>(0,h.jsx)(`option`,{value:e,disabled:e===`chapters`&&!t,children:xA[e]},e))}),(0,h.jsx)(DV,{"aria-label":`Animate every how many images`,"data-play-field":`${a}.animateEvery`,"aria-invalid":f(`animateEvery`)!==void 0,className:`w-24 flex-none`,disabled:c.animate!==`every`,value:String(c.animateEvery),onChange:e=>l({animateEvery:Number(e.target.value)}),children:Array.from({length:9},(e,t)=>t+2).map(e=>(0,h.jsxs)(`option`,{value:String(e),children:[`every `,e]},e))}),(0,h.jsxs)(DV,{"aria-label":`Image-to-video model`,"data-play-field":`${a}.animateModel`,"aria-invalid":f(`animateModel`)!==void 0,className:`min-w-0`,disabled:c.animate===`off`,value:c.animateModel,onChange:e=>l({animateModel:e.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a model`}),v?(0,h.jsxs)(`option`,{value:c.animateModel,children:[c.animateModel,` (saved choice)`]}):null,_.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),g.length>0?(0,h.jsx)(`p`,{className:`col-span-full text-small text-danger`,children:g[0]}):c.animate!==`off`&&d.isSuccess&&_.length===0?(0,h.jsx)(`p`,{className:`col-span-full text-label text-ink-3`,children:`This image provider has no image-to-video models. Choose fal.ai or Replicate for images to animate them.`}):null]})]})}}function T6({id:e,label:t,tip:n,wide:r=!1,children:i}){return(0,h.jsxs)(`div`,{className:L(`sl-field`,r&&`sl-fields__wide`),...Ob,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),(0,h.jsx)(V,{id:n,label:t.toLowerCase()})]}),(0,h.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-start gap-2 [&>select]:min-w-0 [&>select]:flex-1`,children:i})]})}function E6({id:e,field:t,value:n,options:r,labels:i,onChange:a}){return(0,h.jsx)(DV,{id:e,"data-play-field":t,className:`min-w-0`,value:n,onChange:e=>a(e.target.value),children:r.map(e=>(0,h.jsx)(`option`,{value:e,children:i[e]},e))})}var whe=rO(`kind`,[q({kind:pO(`upload`),stagedFileId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`output`),outputId:W().regex(/^[A-Za-z0-9_-]{1,64}$/)}),q({kind:pO(`picture`),sha256:W().regex(/^[a-f0-9]{64}$/)})]),D6=q({format:J(PS),subtitles:q({mode:J(fM),fontId:W().max(160).regex(/^[A-Za-z0-9_-]+$/),fontSize:G().finite().min(16).max(120),position:J(pM)}),videoEdit:yM.optional(),previewText:W().max(200).optional(),image:whe.optional(),shorts:q({titleOnScreen:GD(),speed:G().finite().min(1).max(1.25).optional(),title:W().max(100).optional()}).optional(),force:GD().optional()}),The=q({hash:W().regex(/^[a-f0-9]{64}$/),url:W().min(1),cached:GD(),seconds:G().positive()});async function Ehe(e,t,n){let r=await e.fetch(`${e.origin}/api/style-preview`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),...n===void 0?{}:{signal:n}});if(!r.ok)throw await fo(r);let i=So(The,await r.json());return{...i,src:`${e.origin}${i.url}`}}var Dhe=600;function O6({settings:e,label:t,drawnOn:n,poster:r}){let{api:i}=z(),a=N({queryKey:sN,queryFn:()=>cN(i),staleTime:6e4}),{format:o,subtitles:s,videoEdit:c,previewText:l,image:u,shorts:d}=e,f=r??(u?.kind===`picture`?ux(i,u.sha256):void 0),p=u===void 0?``:JSON.stringify(u),g=d===void 0?``:JSON.stringify(d),_=(0,m.useMemo)(()=>JSON.stringify({format:o,subtitles:{mode:s.mode,fontId:s.fontId,fontSize:s.fontSize,position:s.position},...c===void 0?{}:{videoEdit:c},...l===void 0||l.trim()===``?{}:{previewText:l},...p===``?{}:{image:JSON.parse(p)},...g===``?{}:{shorts:JSON.parse(g)}}),[o,s.mode,s.fontId,s.fontSize,s.position,c,l,p,g]),v=(0,m.useMemo)(()=>D6.safeParse(JSON.parse(_)).success,[_]),[y,b]=(0,m.useState)({kind:`idle`}),[x,S]=(0,m.useState)(void 0),C=(0,m.useRef)(void 0),w=(0,m.useCallback)(async e=>{C.current?.abort();let t=new AbortController;C.current=t,b({kind:`pending`});try{let n=await Ehe(i,{...D6.parse(JSON.parse(_)),...e?{force:e}:{}},t.signal);if(C.current!==t)return;S(n.src),b({kind:`ready`,src:n.src})}catch(e){if(C.current!==t||t.signal.aborted)return;b({kind:`failed`,message:e instanceof Error&&e.message!==``?e.message:`The style preview couldn't render. Press Render again.`})}},[i,_]);(0,m.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>{w(!1)},Dhe);return()=>clearTimeout(e)},[w,v]),(0,m.useEffect)(()=>()=>C.current?.abort(),[]);let T=a.data?.fonts.find(e=>e.id===s.fontId)?.name??(s.fontId==="default"?`Barlow`:`Chosen font`),E=d===void 0?s.mode===`burn-in`?`Captions: ${T} ${String(s.fontSize)} · ${Ohe(s.position)}`:s.mode===`files`?`Captions: a separate file, which players show in their own style`:`Captions: off`:[`Captions: ${T}, word by word`,d.titleOnScreen?`Title on screen`:`No title on screen`,d.speed===void 0||d.speed===1?void 0:`${d.speed.toFixed(2)}×`].filter(e=>e!==void 0).join(` · `),D=d===void 0?`Style preview`:`Shorts preview`,O=o===`9:16`||d!==void 0;return(0,h.jsxs)(`section`,{"aria-label":D,className:`min-w-0 space-y-3`,children:[(0,h.jsx)(H,{as:`h3`,title:D,meta:d===void 0?`6 seconds of the sample, rendered with your settings`:`A few seconds of the sample as a short, rendered with your settings`,info:d===void 0?`project.video.style-preview`:`play.shorts.preview`,children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:!v||y.kind===`pending`,disabledReason:v?`Rendering the preview…`:`Fix the caption settings to render the preview.`,onClick:()=>{w(!0)},children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,size:16,strokeWidth:1.75}),`Render again`]})}),x===void 0?null:(0,h.jsx)(R0,{src:x,label:t??D,...f===void 0?{}:{poster:f},portrait:O,className:O?`max-w-[270px]`:`max-w-[480px]`}),y.kind===`pending`?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Rendering the preview…`}):null,y.kind===`failed`?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:y.message}):null,v?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The preview renders again once the caption size is between 16 and 120.`}),(0,h.jsxs)(`p`,{className:`text-small text-ink-2`,children:[E,u===void 0||n===void 0?``:` · Drawn on ${n}`]})]})}function Ohe(e){let t=e.replace(/-/g,` `);return`${t[0]?.toUpperCase()??``}${t.slice(1)}`}function khe({form:e,problem:t,update:n,onPickFiles:r,onRemoveFile:i,onReattachFile:a}){let o=e.provided.ambientBed;return(0,h.jsx)(A2,{value:e.ambientBed,inherit:`The channel's (brand kit)`,sources:Qk,offerNone:!0,problem:e=>t(`ambientBed.${e}`),file:(0,h.jsx)(Z3,{field:`ambientBed.file`,label:`Ambient sound file: an audio file, looped if shorter than the video`,accept:`audio/*`,uploads:o===void 0?[]:[o],problem:t(`ambientBed.file`),onPick:e=>r(`ambientBed`,e),onReattach:a?(e,t)=>a(`ambientBed`,e,t):void 0,onRemove:e=>i(`ambientBed`,e)}),onChange:e=>n({ambientBed:e})})}function k6({value:e,onChange:t,problem:n,switchTip:r=`project.loudness`,switchLabel:i=`Level the volume`}){return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[(0,h.jsx)(kb,{checked:e.enabled,label:i,tip:r,onChange:n=>t({...e,enabled:n})}),e.enabled?(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(j6,{target:`video`,label:`Video volume`,tip:`project.loudness.video`,lufs:e.videoLufs,error:n?.(`videoLufs`),onChange:n=>t({...e,videoLufs:n})}),(0,h.jsx)(j6,{target:`audioFiles`,label:`Audio files volume`,tip:`project.loudness.audio-files`,lufs:e.audioFilesLufs,error:n?.(`audioFilesLufs`),onChange:n=>t({...e,audioFilesLufs:n})})]}):null]})}var Ahe=`Enter a volume between ${M6(-10)} dB and ${M6(4)} dB (${String(ck(-10))}% to ${String(ck(4))}%).`;function A6(e,t){let n=e.trim().replace(`−`,`-`).replace(`,`,`.`);if(n===``)return;let r=Number(n.replace(/(dB|%)$/i,``).trim());if(!Number.isFinite(r)||t===`percent`&&r<=0)return;let i=t===`db`?r:lk(r);if(!(i<-10.25||i>4.25))return uk(i)}function j6({target:e,label:t,tip:n,lufs:r,error:i,onChange:a}){let o=(0,m.useId)(),s=ok(r,e),[c,l]=(0,m.useState)(),u=c===void 0||A6(c.text,c.unit)!==void 0,d=(t,n)=>{l({unit:t,text:n});let r=A6(n,t);r!==void 0&&a(sk(r,e))},f=c?.unit===`db`?c.text:M6(s),p=c?.unit===`percent`?c.text:String(ck(s));return(0,h.jsx)(xV,{label:t,tip:n,help:`0 dB is the recommended ${N6(ik(e))} LUFS; this is ${N6(r)} LUFS. Peaks stay under ${N6(ak(e))} dBTP.`,error:u?i:Ahe,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`loudness.${e===`video`?`videoLufs`:`audioFilesLufs`}`,value:f,onChange:e=>d(`db`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`dB`}),(0,h.jsx)(CV,{id:`${o}-percent`,"aria-label":`${t} as a percentage of the recommended level`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:p,onChange:e=>d(`percent`,e.target.value),onBlur:()=>l(void 0)}),(0,h.jsx)(`span`,{children:`%`})]})})}function M6(e){return e>0?`+${String(e)}`:N6(e)}function N6(e){return String(e).replace(`-`,`−`)}function P6({sentence:e,paragraph:t,problem:n,onChange:r}){let i=`0 to 2 in steps of ${String(yk)}`;return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(xV,{label:`Pause between sentences (seconds)`,tip:`project.pause.sentence`,help:`${i}; ${String(vk)} is the default. 0 leaves the voice's own.`,error:n(`sentencePauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`sentencePauseSeconds`,value:e,onChange:e=>r(`sentencePauseSeconds`,e.target.value)})}),(0,h.jsx)(xV,{label:`Pause between paragraphs (seconds)`,tip:`project.pause.paragraph`,help:`${i}; 0 (the default) keeps the sentence pause.`,error:n(`paragraphPauseSeconds`),children:(0,h.jsx)(CV,{type:`text`,inputMode:`decimal`,className:`sl-input--number`,"data-play-field":`paragraphPauseSeconds`,value:t,onChange:e=>r(`paragraphPauseSeconds`,e.target.value)})})]})}function F6(e){let t=e.trim().replace(`,`,`.`);if(t===``)return;let n=Number(t);return Number.isFinite(n)?n:void 0}function jhe({form:e,problem:t,update:n}){let{api:r}=z(),i=N(ob(r)).data?.loudness??tk,a=e.loudness;return(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3`,children:[e.sources.audio===`generate`?(0,h.jsx)(P6,{sentence:e.sentencePause??`0.4`,paragraph:e.paragraphPause??`0`,problem:t,onChange:(e,t)=>n(e===`sentencePauseSeconds`?{sentencePause:t}:{paragraphPause:t})}):null,(0,h.jsx)(k6,{value:{enabled:a?.enabled??i.enabled,videoLufs:a?.videoLufs??i.videoLufs,audioFilesLufs:a?.audioFilesLufs??i.audioFilesLufs},problem:e=>t(`loudness.${e}`),onChange:e=>n({loudness:e})})]})}function I6({value:e,onPick:t,disabled:n=!1}){let r=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,...Ob,children:[(0,h.jsx)(X4,{id:r,className:`shrink-0`,children:`Thumbnails`}),(0,h.jsxs)(Z4,{type:`single`,value:String(e),"aria-labelledby":r,disabled:n,"data-play-field":`thumbnailCount`,onValueChange:e=>{(e===`1`||e===`3`)&&t(e===`3`?3:1)},children:[(0,h.jsx)(Q4,{value:`1`,children:`1`}),(0,h.jsx)(Q4,{value:`3`,children:`3`})]}),(0,h.jsx)(V,{id:`play.thumbnail-count`})]})}function Mhe({form:e,problem:t,update:n}){return(0,h.jsxs)(e6,{kind:`research`,name:`Research`,dim:e.sources.research===`off`,children:[(0,h.jsx)(t6,{kind:`research`,form:e,update:n}),(0,h.jsx)(`div`,{className:Q3,children:e.sources.research===`generate`?(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:`Runs through the LLM, one agent per chapter`}):null}),e.sources.research===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.research`,label:`Research notes`,tip:`play.provided.research`,value:e.provided.research,placeholder:`Paste the notes the article will be written from.`,problem:t(`provided.research`),onChange:t=>{n({provided:{...e.provided,research:t}})}})}):null]})}function Nhe({form:e,prompts:t,problem:n,update:r,titled:i}){return(0,h.jsxs)(e6,{kind:`article`,name:`Article`,dim:!1,titled:i,children:[(0,h.jsx)(t6,{kind:`article`,form:e,update:r}),(0,h.jsx)(`div`,{className:`${$3} grid gap-4`,children:e.sources.article===`generate`?(0,h.jsx)(FV,{field:`articlePrompt`,label:UA(e)?`Script prompt`:`Article prompt`,tip:`play.article-prompt`,value:e.articlePrompt,placeholder:`Pick a prompt`,options:n6(t,l0(e)),problem:n(`articlePrompt`),onPick:e=>{r({articlePrompt:e})}}):null}),e.sources.article===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(X3,{field:`provided.article`,label:`Article text`,tip:`play.provided.article`,value:e.provided.article,placeholder:`Paste the article that will be narrated.`,problem:n(`provided.article`),onChange:t=>{r({provided:{...e.provided,article:t}})}})}):null]})}function Phe({form:e,providers:t,prompts:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s}){let c=e.sources.thumbnail===`from_prompt`||e.sources.thumbnail===`prompt_by_llm`;return(0,h.jsxs)(e6,{kind:`thumbnail`,name:`Thumbnail`,dim:e.sources.thumbnail===`off`,children:[(0,h.jsx)(t6,{kind:`thumbnail`,form:e,update:i}),(0,h.jsxs)(`div`,{className:Q3,children:[c&&e.sources.images!==`generate`?(0,h.jsx)(x6,{form:e,providers:t,problem:r,update:i}):null,c?(0,h.jsx)(FV,{field:`thumbnailPrompt`,label:`Thumbnail prompt`,tip:`play.thumbnail-prompt`,value:e.thumbnailPrompt,placeholder:`Pick a prompt`,options:n6(n,`thumbnail`),problem:r(`thumbnailPrompt`),onPick:e=>{i({thumbnailPrompt:e})}}):null,c?(0,h.jsx)(I6,{value:e.thumbnailCount===3?3:1,onPick:e=>{i({thumbnailCount:e})}}):null]}),e.sources.thumbnail===`provide`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(Z3,{field:`provided.thumbnail`,label:`Thumbnail image`,accept:`image/png,image/jpeg,image/webp`,uploads:e.provided.thumbnail===void 0?[]:[e.provided.thumbnail],problem:r(`provided.thumbnail`),onPick:e=>{a(`thumbnail`,e)},onReattach:s?(e,t)=>s(`thumbnail`,e,t):void 0,onRemove:e=>{o(`thumbnail`,e)}})}):null]})}function Fhe({form:e,prompts:t,silenceGapSeconds:n,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s,rawTiming:c,extras:l=!0,language:u,titled:d}){let f=e.sources.video===`generate`?e.sources.audio===`off`?`Silent video · each image shown once`:`Images and narration · ${String(n)} s segment gaps`:e.sources.audio===`off`?`Download each enabled stage separately`:`Combined WAV export with narration and segment gaps`,p=t=>({value:c?c[t]:Number.isFinite(e[t])?String(e[t]):``,onChange:e=>{c?c.onChange(t,e):i({[t]:e.trim()===``?NaN:Number(e)})}}),m=w6({value:e.videoEdit,narrated:e.sources.audio!==`off`,imageProvider:e.images.provider,problem:r,language:u??e.language,onChange:e=>i({videoEdit:e})});return(0,h.jsxs)(e6,{kind:`video`,name:`Export`,dim:e.sources.video===`off`,titled:d,children:[(0,h.jsx)(t6,{kind:`video`,form:e,update:i}),(0,h.jsx)(`span`,{className:Q3,children:(0,h.jsx)(`span`,{className:`engraved text-ink-3`,children:f})}),e.sources.video===`generate`||e.sources.audio!==`off`?(0,h.jsxs)(`div`,{className:Q3,children:[e.sources.video===`generate`?(0,h.jsx)(R6,{field:`imageSeconds`,label:`Seconds per image`,tip:`play.image-seconds`,step:1,problem:r(`imageSeconds`),...p(`imageSeconds`)}):null,e.sources.video===`generate`?(0,h.jsx)(R6,{field:`zoomPercent`,label:`Zoom (%)`,tip:`play.zoom`,step:.5,problem:r(`zoomPercent`),...p(`zoomPercent`)}):null,e.sources.video===`generate`?(0,h.jsx)(PV,{label:`Motion`,tip:`play.motion`,problem:void 0,children:({id:t})=>(0,h.jsx)(DV,{id:t,"data-play-field":`motionStyle`,className:`w-full`,value:e.motionStyle,onChange:e=>i({motionStyle:e.target.value}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null,e.sources.video===`generate`?m.cuts:null,e.sources.audio===`off`?null:(0,h.jsx)(R6,{field:`edgeSilenceSeconds`,label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,step:.5,problem:r(`edgeSilenceSeconds`),...p(`edgeSilenceSeconds`)})]}):null,e.sources.video===`generate`?(0,h.jsx)(`div`,{className:$3,children:m.look}):null,e.sources.video===`generate`&&e.sources.audio!==`off`?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(khe,{form:e,problem:r,update:i,onPickFiles:a,onRemoveFile:o,onReattachFile:s})}):null,e.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(jhe,{form:e,problem:r,update:i})}),l?(0,h.jsx)(`div`,{className:$3,children:(0,h.jsx)(L6,{form:e,prompts:t,problem:r,update:i,onPickFiles:a,onRemoveFile:o,...s===void 0?{}:{onReattachFile:s}})}):null,e.sources.images===`off`?(0,h.jsx)(`p`,{className:`${$3} text-small text-ink-2`,children:`Video is Off because Images is Off. Generate or provide images to enable video.`}):null]})}function L6({form:e,prompts:t,problem:n,update:r,onPickFiles:i,onRemoveFile:a,onReattachFile:o}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[e.sources.audio===`generate`&&e.audio.describeFigures===!0?(0,h.jsx)(m6,{value:e.showFigures,onChange:e=>r({showFigures:e})}):null,e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(C6,{enabled:e.youtubeDescription===!0,prompt:e.descriptionPrompt??``,prompts:t,narrated:e.sources.audio!==`off`,problem:n,onChange:e=>r(e)})}),e.sources.article===`off`?null:(0,h.jsx)(`div`,{children:(0,h.jsx)(YV,{value:e.shorts??GV,prompts:t,narrated:e.sources.audio!==`off`,problem:n,musicName:e.provided.shortsMusic?.name,music:(0,h.jsxs)(`div`,{className:`basis-full`,children:[(0,h.jsx)(Z3,{field:`shorts.music`,label:`Background music (optional): an audio file, looped if shorter than a short`,accept:`audio/*`,disabled:!jN(e),uploads:e.provided.shortsMusic===void 0?[]:[e.provided.shortsMusic],problem:n(`shorts.music`),onPick:e=>i(`shortsMusic`,e),onReattach:o?(e,t)=>o(`shortsMusic`,e,t):void 0,onRemove:e=>a(`shortsMusic`,e)}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:`Plays at the volume above under every short and dips while the narrator speaks.`})]}),preview:(0,h.jsx)(O6,{settings:KV(e.shorts??GV,e.subtitles.fontId)}),onChange:e=>r({shorts:e})})})]})}function R6({field:e,label:t,tip:n,placeholder:r,step:i,problem:a,value:o,onChange:s}){return(0,h.jsx)(PV,{label:t,tip:n,problem:a,children:({id:t,describedBy:n})=>(0,h.jsx)(CV,{id:t,"data-play-field":e,type:`text`,inputMode:i<1?`decimal`:`numeric`,className:`sl-input--number`,"aria-invalid":a!==void 0,"aria-describedby":n,placeholder:r,value:o,onChange:e=>s(e.target.value)})})}function Ihe({form:e,update:t}){let n=e.sources.document===`off`;return(0,h.jsxs)(e6,{kind:`document`,name:`Document`,dim:n,children:[(0,h.jsx)(t6,{kind:`document`,form:e,update:t}),(0,h.jsx)(`div`,{className:Q3,children:(0,h.jsx)(PV,{label:`Theme`,tip:`play.document-theme`,problem:void 0,children:({id:r})=>(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(G3,{id:r,field:`document.theme`,className:`w-auto min-w-[120px]`,disabled:n,value:e.document,onChange:e=>{t({document:e})}}),(0,h.jsx)(ha,{to:`/document-themes`,className:`text-small text-accent-ink underline`,children:`Edit themes`})]})})})]})}function Lhe({form:e,providers:t,problem:n,update:r,uses:i,onSettings:a}){let o=[...new Set(i.map(e=>e.label))],s=o.length<=1?o[0]??``:`${o.slice(0,-1).join(`, `)} and ${o.at(-1)??``}`;return(0,h.jsxs)(`section`,{"aria-label":`Text generation`,className:`border-y border-line py-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`Text generation`,meta:`Used for ${s}.`,info:`play.text-generation`,className:`pb-3`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Settings`})}),(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(RV,{field:`llm.provider`,label:`LLM`,tip:`play.llm.provider`,family:`llm`,providers:t,value:e.llm.provider,problem:n(`llm.provider`)??(e.llm.provider===``?n(`llm`):void 0),onPick:e=>r({llm:{provider:e,model:``}})}),(0,h.jsx)(zV,{field:`llm.model`,label:`Text model`,tip:`play.llm.model`,provider:e.llm.provider,value:e.llm.model,problem:n(`llm.model`)??(e.llm.provider!==``&&n(`llm`)?`Pick a text model.`:void 0),onPick:t=>r({llm:{...e.llm,model:t}})}),(0,h.jsx)(b6,{choice:e.llm,onChange:e=>r({llm:e})})]})]})}function z6({section:e,entries:t,...n}){let r=IN(n.form,t);return r[0]?.section===e?(0,h.jsx)(Lhe,{...n,uses:r}):null}function Rhe(e){let{form:t,onLibrary:n}=e,r=e.prompts.find(e=>e.kind===l0(t)&&e.name===t.articlePrompt);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Nhe,{...e,titled:!1}),t.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3 py-3`,children:[r?(0,h.jsxs)(`details`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`summary`,{"data-play-field":`articlePrompt.preview`,className:`cursor-pointer py-2 text-small text-accent-ink`,children:`View prompt`}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words py-3 font-sans text-body text-ink-2`,children:r.body})]}):(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.prompts.some(e=>e.kind===l0(t))?`Choose a saved ${l0(t)} prompt.`:`No ${l0(t)} prompts saved. Create a prompt to begin.`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>n(`/prompts`),children:`Create prompt`})]}):(0,h.jsxs)(`p`,{className:`py-3 text-small text-ink-3`,children:[t.provided.article.trim()?t.provided.article.trim().split(/\s+/).length:0,` `,`words · `,t.provided.article.length,` characters`]}),(0,h.jsx)(z6,{...e,section:`article`,onSettings:()=>n(`/settings`)}),t.sources.article===`off`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`No article: for a project of images or a thumbnail made from prompts. Narration, the PDF and anything else that reads the article stay off.`}):t.sources.article===`provide`?(0,h.jsx)(`p`,{className:`py-4 text-small text-ink-3`,children:`Research is Off because the article is provided.`}):(0,h.jsx)(Mhe,{...e})]})}function zhe(){let{api:e}=z(),t=rP(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=Oy(),u=N({queryKey:[`play-drafts`],queryFn:async()=>{let t=await ZM(e);if(!t.ok)throw Error(t.message);return t.value.drafts}}),d=async()=>{if(!r||s)return;let e=r.id;c(!0),o(null);try{await t.discard({id:r.id,version:r.version}),i(null),await n.cancelQueries({queryKey:[`play-drafts`]}),n.setQueryData([`play-drafts`],t=>t?.filter(t=>t.id!==e))}catch(e){let t=e instanceof Error?e.message:`The draft wasn't discarded. Try again.`;o(t),l(t,`error`)}finally{c(!1)}};return(0,h.jsxs)(`section`,{"aria-label":`Drafts`,className:`flex min-w-0 flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(`p`,{role:`status`,className:L(`engraved min-w-[112px] text-right`,t.status===`saved`?`text-accent-ink`:t.status===`error`||t.status===`conflict`?`text-danger`:`text-ink-3`),children:{unsaved:`Unsaved`,saving:`Saving…`,saved:`Saved`,error:`Couldn't save`,conflict:`Changed elsewhere`}[t.status]}),t.status===`error`?(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{!t.view&&t.activeId&&t.edited===0?t.open(t.activeId):t.flush()},children:`Retry`}):null,t.status===`conflict`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,onClick:()=>{t.activeId&&t.open(t.activeId)},children:`Reload saved draft`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void t.saveAsNew(),children:`Save as a new draft`}),(0,h.jsx)(V,{id:`play.draft-conflict`})]}):null,(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,children:[`Drafts`,(0,h.jsx)(uc,{"aria-hidden":`true`,className:`size-4`})]})}),(0,h.jsxs)(Eb,{align:`end`,className:`w-[340px] p-0`,"aria-label":`Saved drafts`,children:[u.isPending?(0,h.jsx)(`p`,{role:`status`,className:`px-3 py-2`,children:`Loading drafts…`}):null,u.error?(0,h.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:[u.error.message,` `,(0,h.jsx)(R,{variant:`quiet`,onClick:()=>void u.refetch(),children:`Retry`})]}):null,u.data?.length===0?(0,h.jsx)(`p`,{className:`px-3 py-2`,children:`No saved drafts`}):null,a?(0,h.jsx)(`p`,{role:`alert`,className:`px-3 py-2 text-danger`,children:a}):null,u.data?.length?(0,h.jsx)(pU,{label:`Saved drafts`,className:`max-h-72 overflow-y-auto border-t-0`,children:u.data.map(e=>(0,h.jsx)(mU,{title:e.title||`Untitled draft`,onSelect:()=>void t.open(e.id),meta:(0,h.jsxs)(`time`,{dateTime:e.updatedAt,children:[`Last edited `,ku(e.updatedAt)]}),actions:(0,h.jsx)(wy,{size:`small`,label:`Discard ${e.title||`Untitled draft`}`,onClick:()=>{i(e),o(null)},children:(0,h.jsx)(Bc,{"aria-hidden":`true`})}),children:e.readable?null:(0,h.jsx)(`p`,{className:`m-0 text-label text-waiting`,children:`Unsupported or corrupt draft. Try opening it to recover, or discard it.`})},e.id))}):null]})]}),(0,h.jsx)(R,{onClick:()=>void t.newDraft(),children:`New draft`}),(0,h.jsx)(V,{id:`play.drafts`}),(0,h.jsx)(jy,{open:r!==null,title:`Discard ${r?.title||`Untitled draft`}?`,consequence:`The draft is removed. This cannot be undone.`,confirmLabel:`Discard draft`,pending:s,onConfirm:()=>void d(),onCancel:()=>{s||i(null)}})]})}function B6(e,t){let n=[...e.querySelectorAll(`[data-play-field]`)].find(e=>e.dataset.playField===t);if(!n||n.hasAttribute(`disabled`))return!1;let r=n.closest(`details`);return r!==null&&!r.open&&(r.open=!0),n.focus(),n.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`instant`}),document.activeElement===n}function Bhe(e,t,n,r=[]){let i=e;if(e===`fontUpload`&&(i=`subtitles.fontUpload`),/^provided\.images\.\d+$/.test(e)&&(i=`provided.images`),e===`subtitles`&&(i=`subtitles.mode`),e===`chunking`&&(i=`chunking.mode`),[`audio`,`llm`,`images`].includes(e)&&(i=`${e}.provider`),e===`provided`){let e=[`audio`,`images`,`thumbnail`].find(e=>t.sources[e]===`provide`&&(e===`images`?t.provided.images:[t.provided[e]]).some(e=>e&&(e.error!==void 0||e.file===void 0))),n=t.provided.shortsMusic;i=e===void 0&&jN(t)&&n!==void 0&&(n.error!==void 0||n.file===void 0)?`shorts.music`:t.reference?.source===`provide`&&t.provided.reference!==void 0&&(t.provided.reference.error!==void 0||t.provided.reference.file===void 0)?`provided.reference`:`provided.${e??`audio`}`;let r=t.provided.ambientBed;e===void 0&&MN(t)&&r!==void 0&&(r.error!==void 0||r.file===void 0)&&(i=`ambientBed.file`)}let a=/^imagePrompts\.(\d+)\.(.+)$/.exec(e);if(a){let e=t.imagePrompts[Number(a[1])];e&&(i=`imagePrompts.${e.name}.${a[2]}`)}e===`imagePrompts`&&(i=t.imagePrompts[0]?`imagePrompts.${t.imagePrompts[0].name}.number`:`imagePrompts`);let o=/^variants\.(\d+)\.(.+)$/.exec(e);o&&(i=`items.${n[Number(o[1])]?.key??o[1]}.${o[2]}`);let s=/^items\.(\d+)\.(.+)$/.exec(e);s&&(i=Number(s[1])===0?s[2]??e:`items.${n[Number(s[1])-1]?.key??s[1]}.${s[2]}`);let c=t=>t.some(t=>e===t||e.startsWith(`${t}.`));return{section:c([`title`,`articlePrompt`,`provided.article`,`provided.research`,`sources.article`,`sources.research`,...(IN(t,r)[0]?.section??`article`)===`article`?[`llm`]:[],`values`])?`content`:c([`format`,`subtitles`,`fontUpload`])?`style`:c(`audio,narrationPrompt,voices,provided.audio,intro,outro,chunking,images,imagePrompts,imageScale,provided.images,thumbnailPrompt,provided.thumbnail,provided.reference,reference,provided,sources,imageSeconds,zoomPercent,motionStyle,edgeSilenceSeconds,document,youtubeDescription,descriptionPrompt,shorts,videoEdit,ambientBed,loudness,sentencePauseSeconds,paragraphPauseSeconds,llm`.split(`,`))?`outputs`:`review`,field:i}}function Vhe({fields:e,values:t,origins:n,topics:r=[],hide:i=[],problem:a,onChange:o}){let s=e.filter(e=>!i.includes(e.name));return s.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-3 text-small text-ink-2`,children:`Each keyword is entered once and fills every place that names it.`}),(0,h.jsx)(_0,{keywords:s.map(e=>({name:e.name,value:Object.hasOwn(t,e.name)?t[e.name]??``:``,feeds:n?.get(e.name)??[],topic:r.includes(e.name)})),problem:a,onChange:o})]}):null}var Hhe={every:`minutes`,value:`2`};function Uhe({document:e,problem:t,onEdit:n}){let r=(0,m.useId)(),{form:i}=e,a=i.imageScale,o=t(`imageScale.value`)??t(`imageScale`),s=a===void 0?void 0:o===void 0?Ghe(e):{text:o,problem:!0},c=t=>{let{imageScale:r,...o}=i;n({...e,form:{...o,...t===void 0?{}:{imageScale:t},...t!==void 0&&a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})};return(0,h.jsxs)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:[(0,h.jsx)(kb,{checked:a!==void 0,label:`More images for long videos`,tip:`play.image-scale`,describedBy:`${r}-line`,onChange:e=>c(e?Hhe:void 0)}),a===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,...Ob,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,tip:`play.image-scale.rate`,value:a.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>c({every:e,value:Whe(a.value,a.every,e)})}),a.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{id:`${r}-value`,"data-play-field":`imageScale.value`,"aria-label":a.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`sl-input--number`,"aria-invalid":s?.problem===!0,"aria-describedby":`${r}-line`,value:a.value,onChange:e=>c({every:a.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:a.every===`minutes`?`minutes`:`images per hour`})]}),s===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:s.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:s.text})]})}function Whe(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function Ghe(e){let{form:t}=e,n=t.imageScale;if(n===void 0)return{text:``,problem:!1};let r=Number(n.value.trim()),i=n.every===`minutes`;if(!(n.value.trim()!==``&&(i?r>=.25&&r<=60:r>=1&&r<=240)))return{text:i?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`,problem:!0};let a=i?YO(r):r,o=t.sources.article===`provide`,s=Number(e.expectedWords.trim()),c=o?Math.max(1,qO(t.provided.article)):Number.isInteger(s)&&s>=1&&s<=1e5?s:GO,l=t.imagePrompts.map(e=>({name:e.name,number:Math.max(0,Number.parseInt(e.number,10)||0)})),u=l.reduce((e,t)=>e+t.number,0),d={perHour:a,words:c},f=$O({imagePrompts:l,imageScale:d,sources:t.sources}).reduce((e,t)=>e+t,0),p=`about ${String(Math.max(1,Math.round(JO(c))))} minutes (${c.toLocaleString(`en-US`)} words ${o?`in the article`:`expected, set on Review`})`;if(l.length===0)return{text:`For ${p}: tick an image prompt to see the count.`,problem:!1};let m=ZO(d)>=240?` That is the most a run makes (240); the images repeat after that.`:``;return{text:f>u?`For ${p}: ${String(f)} images, ${String(f-u)} more than the prompts' ${String(u)}.${m}`:`For ${p}: the prompts' ${String(u)} images already cover it.`,problem:!1}}function Khe({document:e,onEdit:t}){let{form:n}=e;return(0,h.jsx)(`div`,{className:`flex basis-full flex-col items-start gap-2`,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,form:{...a,...r?{imageScenes:!0}:{}}})}})})}function qhe(e){return e.upload?(0,h.jsx)(V6,{value:e.value,onPick:e.onPick,upload:e.upload}):(0,h.jsx)(Jhe,{...e})}function Jhe({value:e,onPick:t,onUploading:n}){let{api:r}=z(),i=_(),a=P({mutationFn:e=>lN(r,e),onSuccess:({font:e})=>{i.setQueryData(sN,t=>({fonts:[...(t?.fonts??[]).filter(t=>t.id!==e.id),e]})),i.invalidateQueries({queryKey:sN})}}),o=a.isPending,s=(0,m.useRef)(t);s.current=t;let c=(0,m.useRef)(n);return c.current=n,(0,m.useEffect)(()=>{c.current(o)},[o]),(0,m.useEffect)(()=>()=>c.current(!1),[]),(0,h.jsx)(V6,{value:e,onPick:t,upload:{pending:o,error:a.error?.message,pick:e=>a.mutate(e,{onSuccess:({font:e})=>s.current(e.id)})}})}function V6({value:e,onPick:t,upload:n}){let{api:r}=z(),i=(0,m.useId)(),a=(0,m.useId)(),o=N({queryKey:sN,queryFn:()=>cN(r),staleTime:6e4}),s=n.pending,c=o.data?.fonts??[],l=e!=="default"&&!c.some(t=>t.id===e);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:i,children:`Subtitle font`}),(0,h.jsx)(V,{id:`project.subtitles.font`,className:`-my-1`})]}),(0,h.jsxs)(TV,{id:i,"data-play-field":`subtitles.fontId`,value:e,disabled:s,onChange:e=>t(e.target.value),className:`text-small`,children:[c.some(e=>e.id==="default")?null:(0,h.jsx)(`option`,{value:`default`,children:`Default font · bundled`}),l?(0,h.jsxs)(`option`,{value:e,children:[e,` · saved font`]}):null,c.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.source]},e.id))]})]}),(0,h.jsxs)(`div`,{className:`min-w-0 basis-full`,children:[(0,h.jsx)(X4,{htmlFor:a,className:`mb-1`,children:`Upload font (.ttf or .otf)`}),(0,h.jsx)(`input`,{id:a,"data-play-field":`subtitles.fontUpload`,type:`file`,accept:`.ttf,.otf,font/ttf,font/otf`,disabled:s,className:`w-full text-small text-ink-2 file:mr-2 file:rounded-control file:border file:border-line-strong file:bg-sunken file:px-2 file:py-1 file:text-ink`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&n.pick(t)}})]})]}),s?(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Uploading font…`}):null,n.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:n.error}):null,l&&o.data?(0,h.jsx)(`p`,{role:`alert`,children:`Saved font is unavailable. Choose another font or upload it again.`}):null,o.error?(0,h.jsxs)(`p`,{role:`alert`,className:`text-small text-danger`,children:[`The font list couldn't be loaded. `,o.error.message]}):null]})}function Yhe(e){return e===`9:16`?{width:1080,height:1920}:{width:1920,height:1080}}function Xhe(e,t){switch(e){case`top`:return{y:60,alignment:8,translateY:0};case`upper-middle`:return{y:t/4,alignment:5,translateY:-50};case`center`:return{y:t/2,alignment:5,translateY:-50};case`lower-middle`:return{y:t*3/4,alignment:5,translateY:-50};case`bottom`:return{y:t-60,alignment:2,translateY:-100}}}function Zhe({value:e,format:t,sample:n=`Every story begins with a word.`,backgroundUrl:r,showCaptions:i=!0,maxFrameHeight:a}){let{api:o}=z(),s=uN(o,e.fontId),c=`subtitle-preview-${(0,m.useId)().replace(/[^a-zA-Z0-9]/g,``)}`,[l,u]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(typeof FontFace>`u`||!document.fonts)return;let e=!0,t=new FontFace(c,`url(${JSON.stringify(s)})`);return u(!1),t.load().then(t=>{e&&document.fonts.add(t)}).catch(()=>{e&&u(!0)}),()=>{e=!1,document.fonts.delete(t)}},[c,s]);let d=Yhe(t),f=Xhe(e.position??`bottom`,d.height),p=Number.isFinite(e.fontSize)?Math.max(16,Math.min(120,e.fontSize)):48,g={position:`absolute`,left:`50%`,top:`${f.y/d.height*100}%`,width:`${(d.width-120)/d.width*100}%`,transform:`translate(-50%, ${f.translateY}%)`,fontFamily:`"${c}", sans-serif`,fontSize:`${p/d.width*100}cqw`,lineHeight:1.2,overflowWrap:`anywhere`,WebkitTextStroke:`${2.5/d.width*100}cqw #101010`,paintOrder:`stroke fill`,textShadow:`0 ${100/d.width}cqw ${100/d.width}cqw #000`};return(0,h.jsxs)(`figure`,{className:`min-w-0 self-start`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Style preview`}),(0,h.jsx)(`span`,{children:t})]}),(0,h.jsxs)(`div`,{role:`img`,"aria-label":`Subtitle style preview`,"data-format":t,"data-position":e.position??`bottom`,className:`sl-media__frame mx-auto w-full text-center text-white`,style:{aspectRatio:`${d.width} / ${d.height}`,maxWidth:t===`9:16`?a?`min(240px, calc((${a}) * 9 / 16))`:240:480,containerType:`inline-size`},children:[r?(0,h.jsx)(`img`,{src:r,alt:``,className:`absolute inset-0 h-full w-full object-cover`}):null,i?(0,h.jsx)(`span`,{role:`note`,"aria-label":`Caption sample`,style:g,children:n}):null]}),(0,h.jsxs)(`figcaption`,{className:`mt-2 text-label text-ink-3`,children:[d.width,` × `,d.height,` · Preview at reduced scale.`,l?` Font preview unavailable; showing a fallback.`:``]})]})}function H6({value:e,format:t=`16:9`,audioEnabled:n,videoEnabled:r,disabled:i=!1,onChange:a,onUploading:o,problem:s,session:c,fontUpload:l,showPreview:u=!0,illustratedPositions:d=!1,rawFontSize:f}){let p=(0,m.useId)(),g=(0,m.useId)(),_=(0,m.useId)(),v=(0,m.useId)(),[y,b]=(0,m.useState)(!1),x=s?.(`subtitles.fontId`),S=s?.(`subtitles.fontSize`),C=s?.(`subtitles.mode`)??s?.(`subtitles`);return(0,h.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":`Subtitles`,children:[(0,h.jsxs)(`fieldset`,{disabled:i||!n,className:`flex min-w-0 flex-col gap-3 disabled:opacity-60`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 flex-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:p,children:`Subtitles`}),(0,h.jsx)(V,{id:`project.subtitles.mode`,className:`-my-1`})]}),(0,h.jsxs)(`select`,{id:p,"data-play-field":`subtitles.mode`,value:n?e.mode:`off`,disabled:l?.pending??y,"aria-describedby":_,"aria-invalid":C!==void 0,onChange:t=>a({...e,mode:t.target.value}),className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:[(0,h.jsx)(`option`,{value:`off`,children:`Off`}),(0,h.jsx)(`option`,{value:`files`,children:`Subtitle files (.srt + .vtt)`}),(0,h.jsx)(`option`,{value:`burn-in`,disabled:!r,children:`Burn into video + files`})]})]}),(0,h.jsx)(`span`,{className:`pb-1 text-label text-ink-3`,children:`English · local · no paid API`})]}),e.mode!==`off`&&n?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Timed from your narration on this computer. First use downloads an approximately 95 MB speech model. Review the subtitles before publishing.`}),(0,h.jsxs)(`div`,{className:`grid items-start gap-5`,style:{gridTemplateColumns:`repeat(auto-fit, minmax(min(100%, 240px), 1fr))`},children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(qhe,{...l?{upload:l}:{},value:e.fontId,onPick:t=>c?c.selectFont(t):a({...e,fontId:t}),onUploading:e=>{b(e),o?.(e)}}),(0,h.jsxs)(`div`,{className:d?`w-full`:`max-w-[180px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:g,children:`Subtitle font size`}),(0,h.jsx)(V,{id:`project.subtitles.size`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-5`,children:[d?(0,h.jsx)(`input`,{"aria-label":`Subtitle font size slider`,type:`range`,min:16,max:120,step:1,value:Math.max(16,Math.min(120,Number.isFinite(e.fontSize)?e.fontSize:48)),className:`min-w-0 flex-1 accent-accent`,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})}):null,(0,h.jsx)(CV,{className:d?`w-20`:void 0,id:g,"data-play-field":`subtitles.fontSize`,type:`number`,min:16,max:120,step:1,value:f?.value??e.fontSize,"aria-invalid":!kN(e)||S!==void 0,onChange:t=>f?f.onChange(t.target.value):a({...e,fontSize:Number(t.target.value)})})]}),!kN(e)||S?(0,h.jsx)(`p`,{role:`alert`,className:`mt-1 text-label text-danger`,children:S??`Choose a whole font size from 16 to 120.`}):null]}),(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(X4,{htmlFor:d?void 0:v,id:`${v}-label`,children:`Subtitle position`}),(0,h.jsx)(V,{id:`project.subtitles.position`,className:`-my-1`})]}),d?(0,h.jsx)(Z4,{type:`single`,"aria-labelledby":`${v}-label`,value:e.position??`bottom`,onValueChange:t=>{let n=pM.find(e=>e===t);n&&a({...e,position:n})},className:`grid w-full grid-cols-5 gap-2 overflow-visible border-0`,children:pM.map((t,n)=>(0,h.jsxs)(Q4,{value:t,"aria-label":t,"data-play-field":(e.position??`bottom`)===t?`subtitles.position`:void 0,className:`flex min-w-0 flex-col items-center gap-2 rounded-control border border-line-strong bg-surface px-1 py-3 text-[10px] last:border-r data-[state=on]:border-focus data-[state=on]:text-accent-ink data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`relative block h-11 w-7 rounded-[2px] border border-current`,children:(0,h.jsx)(`span`,{className:`absolute left-1 right-1 h-[3px] bg-current`,style:{top:`${8+n*20}%`}})}),(0,h.jsxs)(`span`,{children:[t[0]?.toUpperCase(),t.slice(1)]})]},t))}):(0,h.jsx)(`select`,{id:v,"data-play-field":`subtitles.position`,value:e.position??`bottom`,onChange:t=>{let n=pM.find(e=>e===t.target.value);n&&a({...e,position:n})},className:`h-8 w-full rounded-control border border-line-strong bg-raised px-3 text-small text-ink`,children:pM.map(e=>(0,h.jsxs)(`option`,{value:e,children:[e[0]?.toUpperCase(),e.slice(1)]},e))})]})]}),u?(0,h.jsx)(Zhe,{value:e,format:t,...c?{sample:c.previewText}:{}}):null]}),c?.fontUpload&&!c.fontUploading?(0,h.jsxs)(`p`,{role:`alert`,children:[`Reattach `,c.fontUpload.name,`, or select a font.`]}):null,x?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}):null,e.mode===`files`?(0,h.jsx)(`p`,{className:`text-label text-ink-3`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]}):null]}),c?.fontUpload&&(e.mode===`off`||!n)?(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:c.fontUploading?`status`:`alert`,className:`text-small text-ink-2`,children:c.fontUploading?`Uploading ${c.fontUpload.name}…`:`Unfinished font upload: ${c.fontUpload.name}`}),l?.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:l.error}):null,(0,h.jsx)(R,{"data-play-field":`subtitles.fontUpload`,disabled:i,onClick:()=>c.selectFont(e.fontId),children:`Keep current font`})]}):null,C?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:C}):null,(0,h.jsx)(`p`,{id:_,className:`text-small text-ink-2`,children:n?r?`Optional: download subtitles separately or keep them visible in the video.`:`Audio exports support separate subtitle files. Enable Video to burn captions into an MP4.`:`Turn Audio on to add subtitles.`})]})}function U6({value:e,onPick:t}){let n=(0,m.useId)();return(0,h.jsxs)(`div`,{className:`w-full`,...Ob,children:[(0,h.jsxs)(`span`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(X4,{id:n,children:`Frame format`}),(0,h.jsx)(V,{id:`play.format`,className:`-my-1`})]}),(0,h.jsx)(Z4,{type:`single`,value:e,"aria-labelledby":n,className:`w-full max-w-[400px] gap-3 overflow-visible border-0`,onValueChange:e=>{(e===`16:9`||e===`9:16`)&&t(e)},children:[`16:9`,`9:16`].map(t=>(0,h.jsxs)(Q4,{value:t,"data-play-field":e===t?`format`:void 0,"aria-label":t,className:`flex h-28 min-w-0 flex-1 items-center justify-center gap-4 rounded-control border border-line-strong bg-surface p-3 last:border-r data-[state=on]:border-focus data-[state=on]:shadow-none`,children:[(0,h.jsx)(`span`,{className:`flex h-12 items-center justify-center`,"aria-hidden":`true`,children:(0,h.jsx)(`span`,{"data-format-shape":t,className:`block rounded-[2px] border-2 border-current`,style:{width:t===`16:9`?64:27,aspectRatio:t===`16:9`?`16 / 9`:`9 / 16`}})}),(0,h.jsxs)(`span`,{className:`text-left`,children:[(0,h.jsx)(`span`,{className:`block text-body font-semibold`,children:t}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:t===`16:9`?`Landscape`:`Portrait`})]})]},t))})]})}function Qhe({problem:e}){let t=rP(),{document:n}=t,{form:r}=n,i=e=>t.edit({...n,form:{...r,subtitles:{...e,fontSize:r.subtitles.fontSize}}});return(0,h.jsxs)(`div`,{"data-tour":`play-subtitles`,className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`See frame and caption changes in the preview as you go.`}),(0,h.jsx)(U6,{value:r.format,onPick:e=>t.edit({...n,form:{...r,format:e}})}),(0,h.jsx)(`div`,{className:`border-t border-line pt-4`,children:(0,h.jsx)(H6,{showPreview:!1,illustratedPositions:!0,fontUpload:t.fontUpload,session:{previewText:n.previewText,fontUploading:t.fontUploading,fontUpload:n.fontUpload,selectFont:t.selectFont,uploadSubtitleFont:t.uploadSubtitleFont},value:{...r.subtitles,fontSize:Number(r.subtitles.fontSize)},rawFontSize:{value:r.subtitles.fontSize,onChange:e=>t.edit({...n,form:{...r,subtitles:{...r.subtitles,fontSize:e}}})},format:r.format,audioEnabled:r.sources.audio!==`off`,videoEnabled:r.sources.video===`generate`&&r.sources.images!==`off`,onChange:i,problem:e})}),(0,h.jsx)(xV,{label:`Preview text`,tip:`play.preview-text`,className:`border-t border-line pt-4`,children:(0,h.jsx)(CV,{value:n.previewText,onChange:e=>t.edit({...n,previewText:e.target.value})})})]})}function $he(e){let t=rP(),n=t.document,r=H3(),i=U3(),{form:a,entries:o,problem:s,update:c}=e;return(0,h.jsx)(yhe,{...e,titled:!1,cast:r,language:i,rawCounts:{...n.form.chunking,onChange:(e,r)=>t.edit({...n,form:{...n.form,chunking:{...n.form.chunking,mode:e,...e===`words`?{words:r}:e===`characters`?{characters:r}:{}}}})},advanced:(0,h.jsxs)(h.Fragment,{children:[[`intro`,`outro`].map(e=>(0,h.jsx)(FV,{field:e,label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,value:a[e],placeholder:`Off`,options:o.filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),problem:s(e),onPick:t=>c({[e]:t})},e)),(0,h.jsx)(`div`,{className:`col-span-full flex flex-wrap gap-2`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:e.onSettings,children:`Settings`})}),(0,h.jsx)(`div`,{className:`col-span-full empty:hidden`,children:(0,h.jsx)(z6,{...e,section:`narration`,onSettings:e.onSettings})})]})})}function ege(e){let t=rP(),n=t.document;return(0,h.jsx)(bhe,{...e,titled:!1,more:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Uhe,{document:n,problem:e.problem,onEdit:t.edit}),n.form.sources.article===`off`?null:(0,h.jsx)(Khe,{document:n,onEdit:t.edit})]}),rawNumbers:{values:n.form.imagePrompts,onChange:(e,r)=>t.edit({...n,form:{...n.form,imagePrompts:n.form.imagePrompts.map(t=>t.name===e?{...t,number:r}:t)}})}})}function tge(e){let t=rP(),n=t.document,r=U3();return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Fhe,{...e,titled:!1,extras:!1,language:r,rawTiming:{imageSeconds:n.form.imageSeconds,zoomPercent:n.form.zoomPercent,edgeSilenceSeconds:n.form.edgeSilenceSeconds,onChange:(e,r)=>t.edit({...n,form:{...n.form,[e]:r}})}}),n.form.sources.audio===`off`?null:(0,h.jsx)(`div`,{className:`sl-fields border-b border-line py-4`,children:(0,h.jsx)(R6,{field:`silenceGapSeconds`,label:`Silence between segments (seconds)`,tip:`play.silence-gap`,placeholder:String(e.silenceGapSeconds),step:.1,problem:e.problem(`silenceGapSeconds`),value:n.form.silenceGapSeconds??``,onChange:e=>{let{silenceGapSeconds:r,...i}=n.form;t.edit({...n,form:e.trim()===``?i:{...i,silenceGapSeconds:e}})}})}),(0,h.jsx)(Qhe,{problem:e.problemOf})]})}function nge(e){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z6,{...e,section:`outputs`,onSettings:e.onSettings}),(0,h.jsx)(Phe,{...e}),(0,h.jsx)(`section`,{className:`border-b border-line py-4`,children:(0,h.jsx)(L6,{form:e.form,prompts:e.prompts,problem:e.problem,update:e.update,onPickFiles:e.onPickFiles,onRemoveFile:e.onRemoveFile,...e.onReattachFile===void 0?{}:{onReattachFile:e.onReattachFile}})}),e.form.sources.article===`off`?null:(0,h.jsx)(Ihe,{...e})]})}function W6(e,t){if(t===void 0||t.length===0||e.trim()===``)return[];let n=[];for(let[r,i]of t.entries()){let t=1/0;for(let n of[i.name,...i.aliases]){let r=rge(e,n);r!==void 0&&r<t&&(t=r)}Number.isFinite(t)&&n.push({member:i,at:t,order:r})}return n.sort((e,t)=>e.at-t.at||e.order-t.order).map(e=>e.member)}function rge(e,t){let n=t.trim().split(/\s+/u).filter(Boolean);if(n.length===0)return;let r=RegExp(`(?<![\\p{L}\\p{N}])${n.map(ige).join(`\\s+`)}(?![\\p{L}\\p{N}])`,`iu`).exec(e);return r===null?void 0:r.index}function ige(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function age(e,t){let n=e.provided.reference?.file;if(e.sources.images===`generate`&&e.reference?.source===`provide`&&n!==void 0)return{image:{kind:`upload`,stagedFileId:n.id},drawnOn:`the establishing image`};let r=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),i=W6([e.title,...Object.values(e.values)].join(` `),r)[0]??r[0],a=i?.images[0];if(i!==void 0&&a!==void 0)return{image:{kind:`picture`,sha256:a},drawnOn:`${i.name}'s picture`}}function oge({selected:e,reviewed:t}){let n=e=>W3.find(t=>t.stage===e)?.label??e;return e?.length?(0,h.jsxs)(`div`,{className:`space-y-3 text-body`,children:[t?.length?t.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`font-medium`,children:[`Run `,e.runIndex+1,` · Before `,n(e.stage)]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:e.dependents.length?`Also holds: ${e.dependents.map(n).join(`, `)}.`:`No dependent steps.`})]},`${e.runIndex}-${e.checkpointId}`)):(0,h.jsxs)(`p`,{children:[`Selected: `,e.map(e=>`Before ${n(e)}`).join(`, `),`. Refresh review to confirm dependent steps.`]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Approval required on the project page. Starting this run does not approve these checkpoints.`})]}):(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No review checkpoints selected.`})}function sge({estimates:e}){let t=e.reduce((e,t)=>e+t.low,0),n=e.reduce((e,t)=>e+t.high,0),r=e.reduce((e,t)=>e+t.unknown,0),i=e[0]?.rows.map((t,n)=>({...t,low:e.some(e=>e.rows[n]?.low===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.low??0),0),high:e.some(e=>e.rows[n]?.high===null)?null:e.reduce((e,t)=>e+(t.rows[n]?.high??0),0),apiLow:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiLow==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiLow??0),0),apiHigh:e.some(e=>e.rows[n]?.onPlan===!0&&e.rows[n]?.apiHigh==null)?null:e.reduce((e,t)=>e+(t.rows[n]?.apiHigh??0),0)}))??[],a=e.some(e=>e.apiLow!==void 0),o=e.reduce((e,t)=>e+(t.apiLow??0),0),s=e.reduce((e,t)=>e+(t.apiHigh??0),0),c=e.reduce((e,t)=>e+(t.apiUnknown??0),0);return e.length===0?(0,h.jsx)(`div`,{}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-title-2 font-semibold`,children:[r?`Known subtotal: `:`Estimated total: `,G6(t,n)]}),r?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Plus `,r,` stage charge`,r===1?``:`s`,` with unavailable pricing.`]}):null,(0,h.jsxs)(`details`,{className:`rounded-control border border-line px-3`,children:[(0,h.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer items-center text-small text-ink-2`,children:[`Cost by stage · `,i.length,` `,i.length===1?`stage`:`stages`]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 pt-1 pb-3`,children:[a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o===0&&s===0?`CLI steps: $0 on your plan · no API price is listed for their models.`:`CLI steps: $0 on your plan · ~${G6(o,s)} via API${c?` (plus ${String(c)} with no API price)`:``}.`}):null,(0,h.jsx)(`ul`,{"aria-label":`Cost by stage`,className:`m-0 list-none divide-y divide-line p-0`,children:i.map(e=>(0,h.jsxs)(`li`,{className:`py-2`,children:[(0,h.jsxs)(`div`,{className:`flex justify-between gap-4 text-small`,children:[(0,h.jsx)(`span`,{children:e.stage}),(0,h.jsx)(`span`,{className:`text-right tabular-nums`,children:e.onPlan===!0?e.apiLow===null||e.apiHigh===null?`$0 on your plan · API price unknown`:`$0 on your plan · ~${G6(e.apiLow,e.apiHigh)} via API`:e.low===null||e.high===null?`Unknown`:G6(e.low,e.high)})]}),(0,h.jsx)(`p`,{className:`m-0 mt-0.5 text-label text-ink-3`,children:e.detail})]},e.stage))}),[...new Set(e.flatMap(e=>e.assumptions))].map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e},e)),(0,h.jsxs)(`p`,{className:`m-0 text-label text-ink-3`,children:[`Catalogue verified `,e[0]?.catalogueDate??`date unavailable`,`. Batch rows show combined costs.`]})]})]})]})}function G6(e,t){let n=e=>e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`;return e===t?n(e):`${n(e)} – ${n(t)}`}function K6(e){let t=TA(SA(e)),n=new Map(TA(fA)),r=t.filter(([e,t])=>e!==`Cuts`&&n.get(e)!==t).map(([e,t])=>e===`Animate images`?`Animated images: ${t} (paid)`:e===`Chapter cards`?`Chapter cards`:e===`Transition`?t:`${e}: ${t}`);return r.length===0?`Plain cuts, no effects`:r.join(` · `)}function cge(e){return e===void 0?{ok:!1,text:`Provider status unavailable`}:e.readiness.kind===`cli`?tF(e.readiness)?{ok:!0,text:e.readiness.version===void 0?`CLI ready`:`CLI ready · ${e.readiness.version}`}:{ok:!1,text:e.readiness.issue??`CLI not found`}:e.readiness.kind===`local`?e.readiness.available?{ok:!0,text:`Built-in voice · ${e.readiness.engine??`ready`}`}:{ok:!1,text:e.readiness.issue??`No speech program found`}:e.readiness.hasKey?{ok:!0,text:`API key saved`}:{ok:!1,text:`API key missing`}}function lge(e,t){let n=e.sources.audio===`generate`,r=[`from_prompt`,`prompt_by_llm`].includes(e.sources.thumbnail);return[...(e.sources.article===`generate`||e.sources.thumbnail===`prompt_by_llm`||pj(e)||jN(e)||n&&[`intro`,`outro`].some(n=>t.some(t=>t.category===n&&t.name===e[n]&&t.mode===`llm`)))&&e.llm?[{field:`llm.provider`,family:`llm`,label:`Text generation`,provider:e.llm.provider,model:e.llm.model}]:[],...n&&e.audio?[{field:`audio.provider`,family:`tts`,label:`Narration`,provider:e.audio.provider,model:e.audio.model,voice:e.audio.voice}]:[],...(e.sources.images===`generate`||r||jN(e)||CA(e))&&e.images?[{field:`images.provider`,family:`image`,label:`Images`,provider:e.images.provider,model:e.images.model}]:[]]}function q6({name:e,children:t}){return(0,h.jsxs)(`section`,{"aria-label":`${e} summary`,className:`min-w-0 border-t border-line pt-5`,children:[(0,h.jsx)(`h3`,{className:`mb-4 font-semibold`,children:e}),t]})}function uge({form:e,entries:t,providers:n,voices:r,textModels:i,audioModels:a,imageModels:o,onReveal:s}){let c=lge(e,t);if(!c.length)return(0,h.jsx)(q6,{name:`Run readiness`,children:(0,h.jsx)(`p`,{className:`text-body text-ink-2`,children:`No generated providers required. Supplied content is ready for processing.`})});let l={llm:i,tts:a,image:o};return(0,h.jsxs)(q6,{name:`Run readiness`,children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`These checks are refreshed with Review and checked again when you start.`}),(0,h.jsx)(`ul`,{className:`divide-y divide-line`,"aria-label":`Run readiness checks`,children:c.map(e=>{let t=n?.find(t=>t.id===e.provider&&t.family===e.family),i=cge(t),a=l[e.family],o=a?.models.find(t=>t.id===e.model),c=a===void 0?{ok:!0,text:`Model checked at Start`}:o!==void 0||a.allowsCustom?{ok:!0,text:`Model available`}:{ok:!1,text:`Model unavailable`},u=e.voice===void 0?void 0:r===void 0?{ok:!1,text:`Voice list unavailable`}:r.some(t=>t.provider===e.provider&&t.voiceId===e.voice)?{ok:!0,text:`Voice saved`}:{ok:!1,text:`Voice missing`},d=[i,c,...u?[u]:[]],f=d.every(e=>e.ok);return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-3 py-3`,children:[(0,h.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,h.jsx)(`span`,{className:f?`text-lime`:`text-danger`,children:f?`Ready`:d.filter(e=>!e.ok).map(e=>e.text).join(` · `)}),f?null:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>s(e.field),children:`Edit ↗`})]},`${e.family}:${e.provider}`)})})]})}function dge({fields:e,onReveal:t,children:n}){let{document:r,review:i}=rP(),{form:a}=r,{api:o}=z(),s=_(),c=s.getQueryData(eb(o).queryKey),l=s.getQueryData(rb(o).queryKey),u=s.getQueryData(tb(o).queryKey),d=s.getQueryData(sN),f=s.getQueryData(OV(a.llm.provider)),p=s.getQueryData(OV(a.audio.provider)),m=s.getQueryData(OV(a.images.provider)),g=a.sources.audio===`generate`,v=[`from_prompt`,`prompt_by_llm`].includes(a.sources.thumbnail),y=a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||pj(a)||jN(a)||g&&[`intro`,`outro`].some(e=>l?.entries.some(t=>t.category===e&&t.name===a[e]&&t.mode===`llm`)),b=e=>c?.providers.find(t=>t.id===e)?.displayName??e,x=(e,n,r)=>(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[90px_minmax(0,1fr)_auto] items-start gap-x-3 py-1 sm:grid-cols-[145px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(`dt`,{className:`break-words py-2 text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`min-w-0 whitespace-pre-wrap break-words py-2`,children:r||`Not selected`}),n?(0,h.jsx)(`dd`,{children:(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit ${e}`,onClick:()=>t(n),children:`Edit ↗`})}):null]},n??e),S=a.chunking.mode===`words`||a.chunking.mode===`characters`?a.chunking.mode:null;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(uge,{form:a,entries:l?.entries??[],providers:c?.providers,voices:u?.voices,textModels:f,audioModels:p,imageModels:m,onReveal:t}),(0,h.jsxs)(q6,{name:`Content`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Project`,`title`,a.title||`Untitled run`),x(`Article`,`sources.article`,PN[a.sources.article]),a.sources.article===`generate`?x(`Article prompt`,`articlePrompt`,a.articlePrompt):x(`Article text`,`provided.article`,`Your article`),a.sources.article===`generate`?x(`Research`,`sources.research`,PN[a.sources.research]):x(`Research`,null,`Off · Article is provided`),a.sources.research===`provide`&&a.sources.article===`generate`?x(`Research text`,`provided.research`,a.provided.research):null,y?(0,h.jsxs)(h.Fragment,{children:[x(`Text provider`,`llm.provider`,b(a.llm.provider)),x(`Text model`,`llm.model`,f?.models.find(e=>e.id===a.llm.model)?.name??a.llm.model),a.llm.thinking||f?.models.find(e=>e.id===a.llm.model)?.thinkingModes?.length?x(`Thinking`,`llm.thinking`,a.llm.thinking??`Model default`):null]}):null,e.map(({name:e})=>x(e,`values.${e}`,a.values[e]??``))]}),n]}),(0,h.jsx)(q6,{name:`Outputs`,children:(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Narration`,`sources.audio`,PN[a.sources.audio]),g?(0,h.jsxs)(h.Fragment,{children:[x(`Audio provider`,`audio.provider`,b(a.audio.provider)),x(`Audio model`,`audio.model`,p?.models.find(e=>e.id===a.audio.model)?.name??a.audio.model),x(`Voice`,`audio.voice`,u?.voices.find(e=>e.provider===a.audio.provider&&e.voiceId===a.audio.voice)?.name??a.audio.voice),x(`Chunking`,S?`chunking.${S}`:`chunking.mode`,S?`Every ${a.chunking[S]||`(not entered)`} ${S}`:a.chunking.mode===`whole`?`Whole text`:`Paragraph`),x(`Intro`,`intro`,a.intro||`Off`),x(`Narration Preparation`,`narrationPrompt`,a.narrationPrompt?`${a.narrationPrompt} · One LLM call per narration chunk and entry`:`Off`),x(`Outro`,`outro`,a.outro||`Off`)]}):null,a.sources.audio===`provide`?x(`Narration file`,`provided.audio`,a.provided.audio?.name):null,x(`Images`,`sources.images`,PN[a.sources.images]),a.sources.images===`generate`||v||jN(a)?(0,h.jsxs)(h.Fragment,{children:[x(`Image provider`,`images.provider`,b(a.images.provider)),x(`Image model`,`images.model`,m?.models.find(e=>e.id===a.images.model)?.name??a.images.model),a.images.thinking===void 0?null:x(`Image effort`,`images.thinking`,a.images.thinking)]}):null,a.sources.images===`generate`&&a.reference!==void 0&&a.reference.source!==`off`?x(`Establishing image`,a.reference.source===`prompt`?`reference.prompt`:`provided.reference`,`${a.reference.source===`prompt`?a.reference.prompt||`(no prompt picked)`:a.provided.reference?.name??`(no file attached)`}${a.reference.thumbnail?` · thumbnail too`:``}`):null,a.sources.images===`generate`?a.imagePrompts.length?a.imagePrompts.map((e,t)=>x(e.name,`imagePrompts.${t}.number`,`${e.name} · ${e.number||`(not entered)`} images`)):x(`Image prompts`,`imagePrompts`,`None selected`):null,a.sources.images===`provide`?x(`Image files`,`provided.images`,a.provided.images.length?(0,h.jsx)(`ol`,{className:`list-inside list-decimal`,children:a.provided.images.map(e=>(0,h.jsx)(`li`,{children:e.name},e.attachmentId))}):`No files selected`):null,x(`Thumbnail`,`sources.thumbnail`,PN[a.sources.thumbnail]),v?x(`Thumbnail prompt`,`thumbnailPrompt`,a.thumbnailPrompt):null,a.sources.thumbnail===`provide`?x(`Thumbnail file`,`provided.thumbnail`,a.provided.thumbnail?.name):null,x(`Video`,`sources.video`,PN[a.sources.video]),a.sources.video===`generate`?x(`Seconds per image`,`imageSeconds`,a.imageSeconds||`(not entered)`):null,a.sources.video===`generate`?x(`Zoom`,`zoomPercent`,a.zoomPercent?`${a.zoomPercent}%`:`(not entered)`):null,a.sources.video===`generate`?x(`Motion`,`motionStyle`,YA[a.motionStyle]):null,a.sources.video===`generate`?x(`Cuts`,`videoEdit.cuts`,gA[SA(a).cuts]):null,a.sources.video===`generate`?x(`Look`,`videoEdit`,K6(a)):null,a.sources.audio===`off`?null:x(`Silence at start and end`,`edgeSilenceSeconds`,a.edgeSilenceSeconds?`${a.edgeSilenceSeconds} s`:`(not entered)`),a.sources.audio===`off`?null:x(`YouTube description`,`youtubeDescription`,a.youtubeDescription===!0?`${a.descriptionPrompt||`Built-in`} prompt · One LLM call after subtitle timing`:`Off`),a.sources.audio===`off`?null:x(`Shorts`,`shorts.enabled`,jN(a)&&a.shorts!==void 0?[`${a.shorts.count} shorts of ${a.shorts.minSeconds}-${a.shorts.maxSeconds} s`,`${a.shorts.prompt||`Built-in`} prompt`,`${a.shorts.imagePrompt||`Built-in`} image style`,...fge(a.shorts,a.provided.shortsMusic?.name),`Vertical images and renders after subtitle timing`].join(` · `):`Off`),x(`Document`,`sources.document`,RS(a.sources,`document`)===`generate`?`PDF · ${XS(a.document)} theme`:PN.off)]})}),(0,h.jsxs)(q6,{name:`Checkpoints`,children:[(0,h.jsx)(oge,{selected:a.checkpoints,reviewed:i.valid?i.receipt?.checkpointSet:void 0}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Edit checkpoints`,onClick:()=>t(`checkpoints`),children:`Edit checkpoints ↗`})]}),(0,h.jsxs)(q6,{name:`Style`,children:[(0,h.jsxs)(`dl`,{className:`text-body`,children:[x(`Frame`,`format`,a.format),a.sources.audio===`off`?x(`Subtitles`,null,`Off · Audio is Off`):x(`Subtitles`,`subtitles.mode`,a.subtitles.mode),a.sources.audio!==`off`&&a.subtitles.mode!==`off`?(0,h.jsxs)(h.Fragment,{children:[x(`Subtitle font`,`subtitles.fontId`,d?.fonts.find(e=>e.id===a.subtitles.fontId)?.name??a.subtitles.fontId),x(`Subtitle size`,`subtitles.fontSize`,`${a.subtitles.fontSize||`(not entered)`} px`),x(`Subtitle position`,`subtitles.position`,a.subtitles.position)]}):null]}),a.sources.audio!==`off`&&a.subtitles.mode===`files`?(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Font, size and position apply to burned captions. SRT/VTT players choose their own styling.`}):null]})]})}function fge(e,t){let n=qk(e),r=n.speed,i=n.musicVolume;return[...n.titleOnScreen===!0?[`Title on screen`]:[],...r!==void 0&&r!==1?[`${r.toFixed(2)}× speed`]:[],...t===void 0?i!==void 0&&i!==15?[`Music at ${String(i)}% once added in Edit project`]:[]:[`Music: ${t} at ${String(i??15)}%`],...n.fullVideoLink===void 0?[]:[`Links ${n.fullVideoLink}`]]}function pge({fields:e,errors:t,onReveal:n,problem:r}){let i=rP(),{document:a,review:o}=i,s=a.form;(0,m.useEffect)(()=>{i.reviewDraft()},[i.reviewDraft]);let c=o.valid?o.receipt?.runs??[]:[];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Everything this run will do, the checkpoints it stops at and the reviews it runs. The estimate and the Play key stay in the right rail.`}),t.length?(0,h.jsx)(`ul`,{"aria-label":`Setup errors`,className:`text-small text-danger`,children:t.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(R,{variant:`quiet`,onClick:()=>n(e.field),children:e.message})},`${e.field}-${e.message}`))}):null,(0,h.jsx)(Gme,{problem:r}),(0,h.jsx)(VV,{problem:r}),(0,h.jsx)(dge,{fields:e,onReveal:n,children:(0,h.jsxs)(`details`,{className:`mt-5 border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:s.sources.article===`provide`?`Read the supplied article and resolved prompts`:`Read the resolved prompt`}),c.length?c.map((e,t)=>(0,h.jsxs)(`div`,{className:`mt-4`,children:[(0,h.jsx)(`h4`,{className:`font-medium`,children:e.draft.title}),e.draft.sources.article===`provide`?(0,h.jsx)(`p`,{className:`mt-3 whitespace-pre-wrap break-words text-body`,children:e.draft.provided.article}):null,Object.entries(e.rendered).map(([e,t])=>(0,h.jsxs)(`div`,{className:`mt-3`,children:[(0,h.jsx)(`h5`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-body`,children:t})]},e))]},a.variants[t-1]?.id??i.activeId)):(0,h.jsx)(`p`,{className:`mt-3 text-small text-ink-2`,children:`Refresh review to read the exact resolved inputs.`})]})})]})}function mge(e,t,n){return[...z3(e).map(e=>(t[e]??``).trim()===``?`${e} is left empty in the template.`:`${e} is left empty in the template (this video's ${e}, "${t[e]}", is not saved).`),...n>0?[`The ${n===1?`other video`:`${String(n)} other videos`} queued here ${n===1?`is`:`are`} not saved.`]:[]]}function hge({open:e,onClose:t}){let{api:n}=z(),r=_(),i=rP(),a=Oy(),o=N(Hq(n)),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),p=(0,m.useRef)(null),{document:g}=i,v=mge(g.form.title,g.form.values,g.variants.length),y=()=>{u(null),t()},b=async()=>{let e=s.trim();if(!(e===``||d)){f(!0),u(null);try{if(!await i.flush()){u(`Your draft wasn't saved, so the template wasn't either. Press Retry beside Drafts, then Save template again.`);return}p.current?.name!==e&&(p.current={name:e,id:crypto.randomUUID()});let s=o.data?.find(e=>e.id===g.templateSource?.id),l=g.channelId??(s?o0(s):void 0),d=Vme(g),f=await Wq(n,{id:p.current.id,name:e,document:l===void 0?d:{...d,channelId:l}});if(!f.ok){p.current=null,u(`The template wasn't saved. ${f.message}`);return}p.current=null,c(``),a(`Template "${e}" saved.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}catch(e){u(`The template wasn't saved. ${e instanceof Error?e.message:`Press Save template again.`}`)}finally{f(!1)}}};return(0,h.jsx)(Ay,{open:e,onOpenChange:e=>{e||y()},title:`Save as template`,description:`Keeps this setup's prompts, voice, images, style, outputs and reviews to start the next video from.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`secondary`,onClick:y,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,disabled:s.trim()===``||d,disabledReason:d?`Saving the template`:`Name the template first`,onClick:()=>void b(),children:`Save template`})]}),children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,value:s,maxLength:120,placeholder:g.form.title.replace(/\{\{[^}]*\}\}/g,``).trim()||`My setup`,onChange:e=>c(e.target.value)})}),v.length?(0,h.jsx)(`ul`,{"aria-label":`Left out of the template`,className:`m-0 flex list-none flex-col gap-1 p-0 text-small text-ink-2`,children:v.map(e=>(0,h.jsx)(`li`,{children:e},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Every keyword keeps its value: the title names none.`}),l?(0,h.jsx)(SI,{tone:`danger`,title:l}):null]})})}var gge=new Set([`a`,`an`,`the`,`of`,`and`,`or`,`in`,`on`,`to`,`for`,`with`,`vs`,`s`]);function J6(e){return e.normalize(`NFKD`).replace(/\p{M}/gu,``).toLowerCase().replace(/&/g,` and `).replace(/[^\p{L}\p{N}]+/gu,` `).trim()}function Y6(e){let t=J6(e).split(` `).filter(e=>e!==``&&!gge.has(e)).map(e=>e.length>3&&e.endsWith(`s`)&&!e.endsWith(`ss`)?e.slice(0,-1):e);return new Set(t)}function _ge(e,t){let n=0;for(let r of e)t.has(r)&&(n+=1);return n}function vge(e,t){let n=J6(e);if(n===J6(t))return n!==``;let r=Y6(e),i=Y6(t);if(r.size===0||i.size===0)return!1;let a=_ge(r,i);if(a/(r.size+i.size-a)>=.6)return!0;let o=Math.min(r.size,i.size),s=Math.max(r.size,i.size);return a===o&&o/s>=.5}function yge(e,t,n){let r=e.map(e=>e.trim()).filter(e=>e!==``);if(r.length===0)return;let i=e=>r.some(t=>vge(t,e)),a=t.find(i);if(a!==void 0)return{title:a,where:`project`};let o=n.find(i);return o===void 0?void 0:{title:o,where:`video`}}function bge({topics:e}){let{api:t}=z(),n=rP(),{document:r}=n,i=V3(),a=N(Yy(t)),o=N(V2(t,i)),{form:s}=r,c=mq(s.title,s.values),l=yge(e.length===0?[s.title]:[c,...e.map(e=>s.values[e]??``)],(a.data?.projects??[]).filter(e=>e.channelId===i).map(e=>e.title),(o.data??[]).map(e=>e.title));return l===void 0||n.review.created!==null?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.where===`project`?`This channel already has a video on this: "${l.title}" (in Projects). Start anyway if you want another take.`:`This channel already uploaded "${l.title}" (Channel → Existing videos). Start anyway if you want another take.`})}function xge({rows:e,open:t,onChange:n}){return(0,h.jsx)(`ul`,{"aria-label":`Setup`,className:`m-0 flex list-none flex-col border-t border-line p-0`,children:e.map(e=>{let r=t.has(e.id)&&e.editor!==void 0,i=`play-row-${e.id}`;return(0,h.jsxs)(`li`,{"data-setup-row":e.id,className:`border-b border-line`,children:[(0,h.jsx)(H,{title:e.label,size:`small`,className:`items-center py-3.5`,status:e.problem?(0,h.jsx)(_S,{tone:`failed`,children:`Needs setup`}):void 0,meta:(0,h.jsx)(`span`,{"data-row-summary":!0,className:e.problem&&!r?`block break-words text-danger`:`block truncate text-ink-2`,title:e.problem&&!r?void 0:e.summary,children:r?e.summary:e.problem??e.summary}),children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":e.editor===void 0?void 0:r,"aria-controls":e.editor===void 0?void 0:i,"aria-label":`${r?`Done with`:`Change`} ${e.label.toLowerCase()}`,onClick:()=>n(e.id,!r),children:r?`Done`:`Change`})}),r?(0,h.jsx)(`section`,{id:i,"aria-label":e.label,className:`min-w-0 pb-6`,children:e.editor}):null]},e.id)})})}var X6=[{id:`title`,label:`Title and keywords`,section:`content`},{id:`article`,label:`Article`,section:`content`},{id:`narration`,label:`Narration`,section:`outputs`},{id:`images`,label:`Images`,section:`outputs`},{id:`video`,label:`Video and style`,section:`style`},{id:`outputs`,label:`Outputs`,section:`outputs`},{id:`reviews`,label:`Reviews`,section:`review`},{id:`channel`,label:`Channel`,section:`content`}],Sge=[[`title`,[`title`,`values`]],[`article`,[`sources.article`,`sources.research`,`articlePrompt`,`provided.article`,`provided.research`,`llm`]],[`narration`,[`sources.audio`,`audio`,`voices`,`provided.audio`,`narrationPrompt`,`intro`,`outro`,`chunking`]],[`images`,[`sources.images`,`images`,`imagePrompts`,`provided.images`,`reference`,`provided.reference`]],[`video`,[`sources.video`,`imageSeconds`,`zoomPercent`,`motionStyle`,`edgeSilenceSeconds`,`silenceGapSeconds`,`sentencePauseSeconds`,`paragraphPauseSeconds`,`loudness`,`videoEdit`,`format`,`subtitles`,`fontUpload`]],[`outputs`,[`sources.thumbnail`,`thumbnailPrompt`,`provided.thumbnail`,`thumbnailCount`,`youtubeDescription`,`descriptionPrompt`,`shorts`,`sources.document`,`document`]],[`reviews`,[`checkpoints`,`reviews`]],[`channel`,[`channelId`,`useBrandKit`,`language`]]],Z6=(e,t)=>e.some(e=>t===e||t.startsWith(`${e}.`));function Q6(e,t=`article`){return Z6([`llm`],e)?t:Sge.find(([,t])=>Z6(t,e))?.[0]}function Cge(e){switch(e){case`content`:return[`title`,`article`,`channel`];case`outputs`:return[`narration`,`images`,`video`,`outputs`];case`style`:return[`video`];case`review`:return[`reviews`]}}function $6(e,t,n,r=`article`){return t.find(t=>Q6(t.field,r)===e?e===`title`?t.field===`title`?n.length>0:!n.some(e=>t.field===`values.${e}`):!0:!1)}function wge(e,t,n){let r=e=>e===``?`no provider`:n.providers.find(t=>t.id===e)?.displayName??e,i=e=>e.filter(e=>typeof e==`string`&&e!==``).join(` · `);switch(e){case`title`:return i([n.topics.length?t.title:!1,n.keywords===0?`No keywords`:`${String(n.keywords)} keyword${n.keywords===1?``:`s`}`]);case`article`:return t.sources.article===`off`?`Off: no article`:t.sources.article===`provide`?`Your article`:i([t.articlePrompt||`No prompt picked`,t.llm.provider?`${r(t.llm.provider)} · ${t.llm.model||`no model`}`:!1,t.sources.research===`off`?`research off`:`research: ${PN[t.sources.research].toLowerCase()}`]);case`narration`:{if(t.sources.audio===`off`)return`Off, a silent video`;if(t.sources.audio===`provide`)return t.provided.audio?.name??`Your narration file`;let e=n.voices.find(e=>e.provider===t.audio.provider&&e.voiceId===t.audio.voice);return i([r(t.audio.provider),t.voices===void 0?e?.name??(t.audio.voice||`no voice`):`${DA[t.voices.format]}, ${String(t.voices.speakers.length)} speakers`,t.narrationPrompt?`prepared with ${t.narrationPrompt}`:!1,t.intro?`intro ${t.intro}`:!1,t.outro?`outro ${t.outro}`:!1])}case`images`:{if(t.sources.images===`off`)return`Off`;if(t.sources.images===`provide`)return`${String(t.provided.images.length)} of your images`;let e=t.imagePrompts.map(e=>`${e.name} × ${e.number||`?`}`);return i([e.length?e.join(`, `):`No image prompts picked`,r(t.images.provider),t.images.model,t.reference!==void 0&&t.reference.source!==`off`&&`establishing image`])}case`video`:return i([t.format,t.sources.video===`off`?`no video`:gA[SA(t).cuts].toLowerCase(),t.sources.video!==`off`&&n.look,t.sources.audio!==`off`&&t.subtitles.mode!==`off`?`captions ${n.fontName??t.subtitles.fontId} ${t.subtitles.fontSize} ${t.subtitles.position}`:`no captions`]);case`outputs`:return i([t.sources.thumbnail===`off`?!1:t.sources.thumbnail===`provide`?`your thumbnail`:t.thumbnailCount===3?`3 thumbnails`:`1 thumbnail`,jN(t)&&t.shorts?`${t.shorts.count} shorts`:!1,t.youtubeDescription===!0&&t.sources.audio!==`off`&&`YouTube description`,t.sources.document===`generate`&&`PDF (${XS(t.document)})`])||`Only the video`;case`reviews`:return i([n.checkpoints===0?`No checkpoints`:`${String(n.checkpoints)} checkpoint${n.checkpoints===1?``:`s`}`,n.reviews===0?`no automatic reviews`:`${String(n.reviews)} automatic review${n.reviews===1?``:`s`}`]);case`channel`:return i([n.channel??`Default channel`,n.brandKit?`brand kit on`:`brand kit off`,t.language===void 0?void 0:BO(t.language).name])}}function Tge({review:e,blocker:t,errors:n,pendingUpload:r}){if(e.starting)return;if(e.uncertain)return{text:`Slopify didn't confirm the last start. Press Check Start result to find out before starting again.`};if(t)return{text:t.hint,field:t.field};let i=n[0];if(i)return{text:i.message,field:i.field};if(r)return{text:`Wait for uploads to finish before Start`,field:r};if(e.error)return{text:e.error};if(e.pending||!e.valid)return{text:`Checking your setup and the estimate…`}}function Ege({errors:e,blocker:t,saveProblem:n,onReveal:r,onWholeSetup:i,onSaveTemplate:a,preview:o}){let s=rP(),{document:c,review:l}=s,u=YN(c,s.view),d=l.starting||l.uncertain;(0,m.useEffect)(()=>{s.reviewDraft()},[s.reviewDraft]);let f=!l.valid&&!l.pending&&!l.starting&&!l.uncertain&&l.error===null&&e.length===0&&t===void 0&&!u&&s.activeId!==null;(0,m.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>void s.reviewDraft(),800);return()=>clearTimeout(e)},[f,c,s.reviewDraft]);let p=l.valid&&l.receipt?l.receipt.runs.length:GN(c),g=Tge({review:l,blocker:t,errors:e,pendingUpload:u}),_=l.starting||!l.uncertain&&(!l.valid||l.pending||e.length>0||!!u);return(0,h.jsxs)(h.Fragment,{children:[o,(0,h.jsxs)(`section`,{"aria-label":`Start`,className:`flex min-w-0 flex-col gap-4 border-t border-line pt-5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:p===1?`1 video`:`${String(p)} videos`}),p>1?(0,h.jsx)(kb,{label:`Queue`,tip:`play.batch-queue`,checked:JN(c),disabled:d,onChange:e=>s.edit({...c,queue:e})}):(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`One run`})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Estimated cost`,info:`play.estimate`,size:`small`,className:`pb-0`}),l.valid&&l.receipt?(0,h.jsx)(sge,{estimates:l.receipt.estimates}):(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.pending?`Calculating the estimate…`:`The estimate appears once the setup is complete.`}),(0,h.jsx)(xV,{label:`Expected article words per video`,tip:`play.expected-words`,className:`mt-2`,children:(0,h.jsx)(CV,{"data-play-field":`expectedWords`,type:`number`,min:1,max:1e5,value:c.expectedWords,disabled:d,onChange:e=>s.edit({...c,expectedWords:e.target.value})})})]}),n?(0,h.jsx)(SI,{tone:`danger`,title:n}):null,(0,h.jsxs)(Ty,{"data-tour":`play-start`,disabled:_,"aria-describedby":g?`play-start-reason`:void 0,onClick:()=>{s.startRun()},children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),qN(l,c)]}),(0,h.jsx)(`div`,{id:`play-start-reason`,className:`min-h-5 text-center text-small`,children:g===void 0?(0,h.jsx)(`span`,{className:`text-ink-3`,children:p===1?`Nothing starts until you press it.`:JN(c)?`They run one after another. Nothing starts until you press it.`:`They all run at once. Nothing starts until you press it.`}):g.field===void 0?(0,h.jsx)(`span`,{role:l.error?`alert`:`status`,className:l.error?`text-danger`:`text-ink-2`,children:g.text}):(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center justify-center gap-x-1`,children:[(0,h.jsx)(`span`,{id:`play-start-field`,className:`text-waiting`,children:g.text}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-describedby":`play-start-field`,onClick:()=>r(g.field??``),children:`Go to the field`})]})}),(0,h.jsxs)(Ey,{className:`justify-center`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:l.pending||d||!!u,onClick:()=>{s.reviewDraft()},children:`Refresh review`}),(0,h.jsx)(V,{id:`play.refresh-review`})]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-keyshortcuts":Mx(lP.reviewSetup),onClick:i,children:`Review the whole setup`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:a,children:`Save as template`})]})]})]})}function Dge(e,t,n){let r=e?.prompts??[],i=e?.entries??[];return{prompts:[...r,...t.filter(e=>!r.some(t=>t.kind===e.kind&&t.name.toLowerCase()===e.name.toLowerCase()))],entries:[...i,...n.filter(e=>!i.some(t=>t.category===e.category&&t.name.toLowerCase()===e.name.toLowerCase()))]}}function Oge({topics:e,onError:t}){let{api:n}=z(),r=_(),i=rP(),a=N(Hq(n)),o=N(Zb(n)),[s,c]=(0,m.useState)(!1),l=i.review.starting||i.review.uncertain||i.review.created!==null,u=i.document.templateSource,d=a.data?.find(e=>e.id===u?.id),f=e=>o.data?.find(t=>t.id===e)?.name,p=async o=>{if(t(null),o===``){await i.newDraft();return}let s=a.data?.find(e=>e.id===o);if(s){c(!0);try{if(!await i.flush()){t(`Your draft wasn't saved, so the template wasn't applied. Press Retry beside Drafts, then pick the template again.`);return}let a=Object.fromEntries(e.map(e=>[e,i.document.form.values[e]??``]).filter(([,e])=>e.trim()!==``)),o=await Xq(n,s,crypto.randomUUID());if(!o.ok){t(`The template "${s.name}" wasn't applied. ${o.message}`);return}if(await r.invalidateQueries({queryKey:[`play-drafts`]}),!await i.open(o.value.draft.id)){t(`The draft made from "${s.name}" didn't open. Open it from Drafts.`);return}let c=o.value.draft.document,l=Object.fromEntries(Object.entries(a).filter(([e])=>(c.form.values[e]??``)===``));Object.keys(l).length>0&&i.edit({...c,form:{...c.form,values:{...c.form.values,...l}}})}catch(e){t(e instanceof Error?`The template "${s.name}" wasn't applied. ${e.message}`:`The template "${s.name}" wasn't applied. Pick it again.`)}finally{c(!1)}}},g=a.error?`Templates didn't load. ${a.error.message}`:d?[f(o0(d)),`version ${String(d.version)}`].filter(Boolean).join(` · `):a.data?.length===0?`No templates yet. Set this video up, then Save as template.`:void 0;return(0,h.jsx)(xV,{label:`Template`,tip:`play.template`,help:g,children:(0,h.jsxs)(TV,{"data-play-field":`template`,value:d?.id??``,disabled:s||l,onChange:e=>void p(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:u&&!d?`Template no longer saved`:`No template`}),(a.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})}function kge({topics:e,problem:t}){let n=rP(),{document:r}=n,{form:i}=r,a=e=>{n.edit({...r,form:e}),n.invalidateReview(!0)};if(e.length===0)return(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:t(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,className:`!h-11 text-[17px]`,value:i.title,maxLength:200,placeholder:`What's the video about?`,"aria-invalid":t(`title`)!==void 0,onChange:e=>a({...i,title:e.target.value})})});let o=mq(i.title,i.values);return(0,h.jsx)(`div`,{className:`grid min-w-0 gap-4`,children:e.map((n,r)=>(0,h.jsx)(xV,{label:n,tip:`play.topic`,help:r===e.length-1?(0,h.jsxs)(h.Fragment,{children:[`Title: `,(0,h.jsx)(`b`,{className:`font-semibold text-ink`,children:o})]}):void 0,error:t(`values.${n}`)??(r===e.length-1?t(`title`):void 0),children:(0,h.jsx)(CV,{"data-play-field":`values.${n}`,className:`!h-11 text-[17px]`,value:i.values[n]??``,maxLength:200,spellCheck:!1,"aria-invalid":t(`values.${n}`)!==void 0,onChange:e=>a({...i,values:{...i.values,[n]:e.target.value}})})},n))})}function Age({topics:e,keywordNames:t,origins:n,problem:r,adding:i,onAdding:a,open:o,onOpen:s}){let c=rP(),{document:l}=c,{form:u}=l,[d,f]=(0,m.useState)(``),p=(0,m.useId)(),g=(0,m.useRef)(null),_=c.review.starting||c.review.uncertain,v=l.variants,y=e=>{c.edit({...l,variants:e})},b=e[0],x=e=>b===void 0?e.title:e.values[b]||e.title,S=()=>{let e=d.trim();e===``||v.length>=49||(y([...v,{id:crypto.randomUUID(),title:b===void 0?e:u.title,values:b===void 0?{...u.values}:{...u.values,[b]:e}}]),f(``),g.current?.focus())},C=v.findIndex(e=>e.id===o),w=C===-1?void 0:v[C];return(0,h.jsxs)(`section`,{"aria-label":`More videos from the same setup`,className:`min-w-0`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:`More videos from the same setup`}),(0,h.jsx)(V,{id:`play.more-videos`,className:`-my-1`})]}),(0,h.jsxs)(Ey,{className:`flex-wrap`,children:[v.map((e,n)=>{let i=x(e)||`Video ${String(n+2)}`,a=[`items.${String(n+1)}.title`,...t.map(e=>`items.${String(n+1)}.values.${e}`)].some(e=>r(e)!==void 0);return(0,h.jsx)(yS,{...a?{className:`border-danger`}:{},..._?{}:{onRemove:()=>y(v.filter(t=>t.id!==e.id)),removeLabel:`Remove ${i}`},children:(0,h.jsxs)(R,{variant:`quiet`,size:`small`,"data-play-field":`items.${e.id}`,className:`-my-1 -ml-1.5 h-6 px-1.5 text-ink`,"aria-label":`Change the keywords of ${i}`,onClick:()=>s(e.id),children:[i,(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})]})},e.id)}),i?(0,h.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,h.jsx)(`label`,{htmlFor:p,className:`sr-only`,children:b===void 0?`Title of another video`:`${b} of another video`}),(0,h.jsx)(CV,{ref:g,id:p,autoFocus:!0,className:`!h-8 w-48`,value:d,maxLength:200,placeholder:b===void 0?`Another title`:`Another ${b}`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(!1)}}),(0,h.jsx)(R,{type:`submit`,size:`small`,disabled:d.trim()===``,children:`Add`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>a(!1),children:`Done`})]}):(0,h.jsxs)(R,{variant:`quiet`,size:`small`,disabled:_||v.length>=49,disabledReason:_?`Wait for the start to finish`:`One Start queues at most 50 videos`,onClick:()=>a(!0),children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add topic`]})]}),(0,h.jsx)(YP,{open:w!==void 0,title:w?`Video ${String(C+2)}: ${x(w)||`untitled`}`:``,width:`narrow`,onClose:()=>s(null),footer:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>s(null),children:`Done`}),children:w?(0,h.jsxs)(`fieldset`,{disabled:_,className:`flex min-w-0 flex-col gap-5 border-0 p-0`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Everything else comes from the setup of the first video.`}),(0,h.jsx)(xV,{label:`Title`,tip:`play.title`,error:r(`items.${String(C+1)}.title`),children:(0,h.jsx)(CV,{"data-play-field":`items.${w.id}.title`,value:w.title,maxLength:200,onChange:e=>y(v.map(t=>t.id===w.id?{...t,title:e.target.value}:t))})}),(0,h.jsx)(_0,{fieldPrefix:`items.${w.id}.values`,keywords:t.map(t=>({name:t,value:w.values[t]??``,feeds:n.get(t)??[],topic:e.includes(t)})),problem:e=>r(e.replace(`items.${w.id}.`,`items.${String(C+1)}.`)),onChange:(e,t)=>y(v.map(n=>n.id===w.id?{...n,values:{...n.values,[e]:t}}:n))})]}):null})]})}function jge(){let e=Zi();return(0,h.jsx)(Mge,{onCreated:t=>{e({to:`/projects/$projectId`,params:{projectId:t}})}})}function Mge({onCreated:e}){let{api:t}=z(),n=lI(),r=N(eb(t)),i=N(nb(t)),a=N(rb(t)),o=N(tb(t)),s=N(ob(t)),c=N(Zb(t)),l=N(Hq(t)),u=N({queryKey:sN,queryFn:()=>cN(t),staleTime:6e4}),[d,f]=cP(),p=H3(),g=rP(),{document:_}=g,v=Dge(_.librarySnapshot,i.data?.prompts??[],a.data?.entries??[]),y=_.variants.map(({id:e,...t})=>({...t,key:e})),b=g.fontUploading||_.fontUpload!==null,x=g.review.fields,[S,C]=(0,m.useState)(new Set),[w,T]=(0,m.useState)(new Set),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,ee]=(0,m.useState)(!1),[te,ne]=(0,m.useState)(null),j=(0,m.useRef)(null),re=(0,m.useRef)(null),M=(0,m.useRef)(null),ie=Zi(),ae=(0,m.useRef)(g.activeId);(0,m.useLayoutEffect)(()=>{ae.current!==g.activeId&&(ae.current=g.activeId,C(new Set),k(null))},[g.activeId]);let oe=e=>{f(t=>{let n={...t,...e};return{...n,subtitles:ON(n.subtitles,n.sources)}}),g.invalidateReview(!0)},se=s.data?.silenceGapSeconds??3,ce=_.form.silenceGapSeconds?.trim()??``,le={form:d,prompts:v.prompts,entries:v.entries,silenceGapSeconds:ce===``?se:Number(ce)},{fields:ue,result:de,blocker:fe}=Dde(le),pe=h0(le),me=z3(d.title).filter(e=>ue.some(t=>t.name===e)),he=b?{field:`subtitles.fontUpload`,hint:`Wait for the subtitle font upload to finish to play`}:fe;(0,m.useEffect)(()=>{if(!g.review.created)return;let t=g.takeCreated()?.projectIds[0];t&&(n({type:`project-created`,id:t}),e(t))},[g.review.created,g.takeCreated,n,e]);let ge=de.ok?x:[...de.fields,...x],_e=(...e)=>!ge.some(t=>e.some(e=>t.field===e||t.field.startsWith(`${e}.`))),ve=(e,t)=>v.prompts.some(n=>n.kind===e&&n.name===t),ye=e=>e?.file!==void 0&&e.error===void 0;cI({playArticleReady:_e(`sources.article`,`articlePrompt`,`provided.article`)&&(d.sources.article===`provide`||ve(`article`,d.articlePrompt)),playAudioReady:d.sources.audio===`off`||_e(`sources.audio`,`audio`,`provided.audio`)&&(d.sources.audio!==`provide`||ye(d.provided.audio)),playImagesReady:d.sources.images===`off`||_e(`sources.images`,`images`,`imagePrompts`,`provided.images`)&&(d.sources.images===`provide`?d.provided.images.every(ye):d.imagePrompts.every(e=>ve(`image`,e.name))),playVideoReady:_e(`sources.video`),playSubtitlesReady:_e(`subtitles`)&&!b,playOptionsReady:_e(`title`,`format`,`llm`,`intro`,`outro`),playHasKeywords:ue.length>0,playKeywordsReady:_e(`values`),playReady:he===void 0&&!g.review.starting});let be=IN(d,v.entries)[0]?.section??`article`,xe=e=>Wme(e,d)??Bhe(e,d,y,v.entries),Se=e=>{let t=xe(e).field;return ge.find(n=>xe(n.field).field===t&&(x.includes(n)||S.has(e)||S.has(t)))?.message},Ce=e=>{let t=xe(e);C(n=>new Set([...n,e,t.field])),g.navigate(t.field.startsWith(`items.`)?`content`:t.section,t.field)},we=[r,i,a,o,s].every(e=>e.isSuccess||e.isError),Te=(0,m.useRef)(null),Ee=g.generation();(0,m.useEffect)(()=>{if(!we)return;let e=Te.current;Te.current={generation:Ee,id:g.activeId},(e===null||e.generation!==Ee||e.id!==g.activeId&&e.id!==null)&&T(new Set(X6.map(e=>e.id).filter(e=>e!==`reviews`&&$6(e,ge,me,be)!==void 0)))},[we,g.activeId,Ee]);let De=(0,m.useRef)(null);(0,m.useLayoutEffect)(()=>{let e=g.reveal;if(e||(De.current=null),!e||e.sequence===De.current||!j.current)return;let t=e.field,n=t?/^items\.([^.]+)(\.|$)/.exec(t)?.[1]:void 0;if(e.section===`review`){if(De.current=e.sequence,t&&B6(j.current,t))return;M.current?.focus();return}if(n!==void 0&&_.variants.some(e=>e.id===n)){if(O!==n){k(n);return}}else if(!(t&&me.some(e=>t===`values.${e}`))){let n=t?Q6(t,be):void 0,r=(n===void 0?Cge(e.section):[n]).filter(e=>!w.has(e));if((t!==`title`||me.length!==0)&&r.length>0){T(e=>new Set([...e,...r]));return}}De.current=e.sequence,!(t&&B6(j.current,t))&&re.current?.focus()},[g.reveal,w,O]);let Oe=async e=>{await g.flush()&&(e===`/prompts`?await ie({to:`/prompts/new`,search:{kind:`article`}}):await ie({to:e}))},ke=()=>{g.navigate(`review`)},Ae=(e,t)=>{g.invalidateReview(!0),g.attach(e,t)},je=(e,t)=>{f(n=>({...n,provided:e===`images`?{...n.provided,images:n.provided.images.filter(e=>e.key!==t)}:{...n.provided,[e]:void 0}}))},Me=[r,i,a,o,s].find(e=>e.error!==null)?.error?.message,Ne=g.error?`Your draft wasn't saved. ${g.error}`:Me,Pe={form:d,providers:r.data?.providers??[],prompts:v.prompts,voices:o.data?.voices??[],silenceGapSeconds:s.data?.silenceGapSeconds??3,problem:Se,update:oe,onPickFiles:Ae,onRemoveFile:je,onReattachFile:(e,t,n)=>{g.attach(e,[n],t)}},Fe=l.data?.find(e=>e.id===_.templateSource?.id),Ie=_.channelId??(Fe===void 0?`00000000-0000-4000-8000-000000000001`:o0(Fe)),Le=Object.values(_.form.reviews?.stages??{}).filter(e=>e.mode!==`off`).length,Re={providers:r.data?.providers??[],voices:o.data?.voices??[],keywords:ue.length,topics:me,channel:c.data?.find(e=>e.id===Ie)?.name,brandKit:_.form.useBrandKit!==!1,look:K6(_.form),fontName:u.data?.fonts.find(e=>e.id===d.subtitles.fontId)?.name,checkpoints:d.checkpoints?.length??0,reviews:Le},ze={title:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[me.length?(0,h.jsx)(xV,{label:`Title pattern`,tip:`play.title-pattern`,error:Se(`title`),children:(0,h.jsx)(CV,{"data-play-field":`title`,value:d.title,maxLength:200,"aria-invalid":Se(`title`)!==void 0,onChange:e=>oe({title:e.target.value})})}):null,(0,h.jsx)(Vhe,{fields:ue,origins:pe,topics:me,hide:me,values:d.values,problem:Se,onChange:(e,t)=>oe({values:{...d.values,[e]:t}})}),ue.length===me.length?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:ue.length===0?`No keywords. A prompt or the title that names {{a keyword}} adds one here.`:`The only keywords are the topic, typed at the top.`}):null]}),article:(0,h.jsx)(Rhe,{...Pe,entries:v.entries,onLibrary:e=>{Oe(e)}}),narration:(0,h.jsx)($he,{...Pe,entries:v.entries,onKeyword:Ce,onSettings:()=>{Oe(`/settings`)}}),images:(0,h.jsx)(ege,{...Pe}),video:(0,h.jsx)(tge,{...Pe,problemOf:Se}),outputs:(0,h.jsx)(nge,{...Pe,entries:v.entries,onSettings:()=>{Oe(`/settings`)}}),reviews:void 0,channel:(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4 py-4`,children:[(0,h.jsx)(Hme,{}),(0,h.jsx)(Ume,{})]})},Be=X6.filter(e=>e.id!==`narration`||d.sources.article!==`off`),Ve=Be.map(e=>({id:e.id,label:e.label,summary:wge(e.id,d,Re),problem:$6(e.id,ge,me,be)?.message,editor:ze[e.id]})),He=(e,t)=>{if(e===`reviews`){ke();return}T(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},Ue=e=>{He(e,!0),requestAnimationFrame(()=>{j.current?.querySelector(`[data-setup-row="${e}"]`)?.scrollIntoView({block:`start`,behavior:`smooth`})})},We=_.variants.length+1,Ge=YN(_,g.view),Ke=!g.review.starting&&(g.review.uncertain||g.review.valid&&!g.review.pending&&ge.length===0&&!Ge);bx({id:`play.start`,title:qN(g.review,_),group:`Play`,context:d.title||`New project`,keywords:[`start`,`queue`,`run`,`play`,`go`],run:()=>{Ke?g.startRun():he?Ce(he.field):ge[0]&&Ce(ge[0].field)}}),bx({id:`play.add-topic`,title:`Add a topic for another video`,group:`Play`,context:`${String(We)} video${We===1?``:`s`}`,keywords:[`more videos`,`variation`,`batch`,`queue`],run:()=>D(!0)}),bx({id:`play.save-template`,title:`Save as template`,group:`Play`,keywords:[`template`,`setup`,`reuse`],run:()=>ee(!0)}),bx({id:`play.review`,title:`Review the whole setup`,group:`Play`,keywords:[`summary`,`checkpoints`,`prompt`],shortcut:lP.reviewSetup,run:ke}),bx({id:`play.template`,title:`Pick a template`,group:`Play`,keywords:[`template`,`setup`],run:()=>{j.current&&B6(j.current,`template`)}});let qe=d.sources.video===`generate`&&d.sources.images!==`off`,Je=age(d,p),Ye=qe?(0,h.jsx)(O6,{drawnOn:Je?.drawnOn,settings:{format:d.format,subtitles:{mode:d.sources.audio===`off`?`off`:d.subtitles.mode,fontId:d.subtitles.fontId,fontSize:Number(_.form.subtitles.fontSize)||d.subtitles.fontSize,position:d.subtitles.position},videoEdit:d.videoEdit,previewText:_.previewText,image:Je?.image}}):null;return(0,h.jsxs)(`div`,{ref:j,onBlurCapture:e=>{let t=e.target.dataset.playField;t&&C(e=>new Set([...e,t]))},"data-play-grid":`true`,className:`min-w-0 max-[767px]:[&_button]:min-h-11 max-[767px]:[&_input:not([type=checkbox])]:min-h-11 max-[767px]:[&_select]:min-h-11 max-[767px]:[&_summary]:min-h-11`,children:[(0,h.jsx)(kq,{crumb:`New project`,title:(0,h.jsx)(`span`,{ref:re,tabIndex:-1,children:`What's the video about?`}),meta:d.title.trim()===``?`Untitled draft`:d.title,actions:(0,h.jsx)(zhe,{})}),(0,h.jsx)(B3,{onDefaults:g.adoptDefaults}),(0,h.jsxs)(Aq,{className:`sl-workspace--play`,aside:(0,h.jsx)(Ege,{errors:ge,blocker:he,saveProblem:Ne,onReveal:Ce,onWholeSetup:ke,onSaveTemplate:()=>ee(!0),preview:Ye}),asideLabel:`Review and start`,children:[(0,h.jsxs)(`div`,{"data-tour":`play-options`,className:`grid min-w-0 grid-cols-1 items-start gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(Oge,{topics:me,onError:ne}),(0,h.jsx)(kge,{topics:me,problem:Se})]}),(0,h.jsx)(bge,{topics:me}),te?(0,h.jsx)(SI,{tone:`danger`,title:te}):null,(0,h.jsx)(Age,{topics:me,keywordNames:ue.map(e=>e.name),origins:pe,problem:Se,adding:E,onAdding:D,open:O,onOpen:k}),(0,h.jsx)(xge,{rows:Ve,open:w,onChange:He})]}),(0,h.jsx)(YP,{open:g.section===`review`,title:`Review`,headingRef:M,onClose:()=>{g.navigate(`content`)},children:(0,h.jsx)(pge,{fields:ue,errors:ge,problem:Se,onReveal:Ce})}),(0,h.jsx)(hge,{open:A,onClose:()=>ee(!1)}),Be.map(e=>(0,h.jsx)(Nge,{id:e.id,label:e.label,onOpen:Ue},e.id))]})}function Nge({id:e,label:t,onOpen:n}){return bx({id:`play.row.${e}`,title:`Change ${t.toLowerCase()}`,group:`Play`,keywords:[`open`,`edit`,`section`,t],run:()=>n(e)}),null}function Pge(){let{api:e}=z(),t=N({queryKey:[`batch-queue`],queryFn:async()=>F(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=N(Yy(e)),r=t.data?.queue.length??0;return(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{asChild:!0,children:(0,h.jsxs)(R,{variant:`quiet`,disabled:r===0,"aria-label":`Video queue: ${r} remaining`,children:[(0,h.jsx)(Ec,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,r]})]})}),(0,h.jsxs)(Eb,{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:pb(`play.queue`).body}),(0,h.jsx)(Fge,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function Fge({queue:e,projects:t}){return(0,h.jsx)(`ol`,{className:`max-h-40 overflow-y-auto px-4 py-2`,children:e.map((e,n)=>{let r=t?.find(t=>t.id===e.projectId);return(0,h.jsxs)(`li`,{className:`flex justify-between gap-3 py-1 text-small`,children:[(0,h.jsxs)(ha,{className:`truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[n+1,`. `,r?.title??`Video`]}),(0,h.jsx)(`span`,{className:`shrink-0 text-ink-2`,children:r?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`})]},e.projectId)})})}function e8({label:e,className:t,children:n}){return(0,h.jsx)(`nav`,{"aria-label":e,className:L(`sl-rail`,t),children:n})}function Ige({icon:e,meta:t,children:n}){return(0,h.jsxs)(h.Fragment,{children:[e,(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:n}),t===void 0?null:(0,h.jsx)(`span`,{className:`sl-rail__meta`,children:t})]})}function t8({icon:e,meta:t,current:n=!1,onClick:r,className:i,children:a,"data-tour":o}){return(0,h.jsx)(`button`,{type:`button`,"data-tour":o,"aria-current":n?`true`:void 0,onClick:r,className:L(`sl-rail__item w-full border-0 bg-transparent text-left font-[inherit]`,n&&`bg-accent-tint font-semibold text-ink`,i),children:(0,h.jsx)(Ige,{icon:e,meta:t,children:a})})}var n8=/^(?:[-*+]|\d+[.)])\s+/u;function Lge(e){let t=e.split(/\r?\n/u).filter(e=>e.trim()!==``),n=[];for(let e of t.slice(1)){let t=e.trim().replace(n8,``).trim(),r=n.length-1;/^\s/u.test(e)&&!n8.test(e.trim())&&r>=0?n[r]=`${n[r]??``} ${t}`:t!==``&&n.push(t)}return n}var Rge={blockquote:o8,break:Uge,code:s8,definition:s8,delete:o8,emphasis:o8,footnoteReference:s8,footnoteDefinition:s8,heading:Hge,html:s8,image:i8,imageReference:i8,inlineCode:a8,list:o8,listItem:o8,link:o8,linkReference:o8,strong:o8,table:s8,tableCell:s8,text:a8,thematicBreak:s8,toml:s8,yaml:s8},zge={},r8=[];function Bge(e){let t={...Rge},n=e||zge,r=n.keep||r8,i=n.remove||r8,a=-1;for(;++a<i.length;){let e=i[a];typeof e==`string`?t[e]=s8:t[e[0]]=e[1]}let o={};if(r.length===0)o=t;else{let e;for(e in t)r.includes(e)||(o[e]=t[e]);for(a=-1;++a<r.length;)if(e=r[a],!Object.hasOwn(t,e))throw Error("Unknown node type `"+e+"` in `keep`, use a replace tuple with a handle instead: `remove: [['"+e+"', handle]]`")}return function(e){return s(e)};function s(e){let t=e.type,n=e;if(Object.hasOwn(o,t)){let e=o[t];e&&(n=e(n)||void 0)}return n=Array.isArray(n)?c(n):n,n&&`children`in n&&(n.children=c(n.children)),n}function c(e){let t=-1,n=[];for(;++t<e.length;){let r=s(e[t]);Array.isArray(r)?n.push(...c(r)):r&&n.push(r)}return Vge(n)}}function Vge(e){let t=-1,n=[],r;for(;++t<e.length;){let i=e[t];r&&i.type===r.type&&`value`in i&&`value`in r?r.value+=i.value:(n.push(i),r=i)}return n}function i8(e){let t=`title`in e?e.title:``,n=e.alt||t||``;return n?{type:`text`,value:n}:void 0}function a8(e){return{type:`text`,value:e.value}}function Hge(e){return{type:`paragraph`,children:e.children}}function o8(e){return e.children}function Uge(){return{type:`text`,value:`
283
+ `}}function s8(){}var Wge=64,c8=new Map;function Gge(e){let t=c8.get(e);if(t!==void 0)return t;let n=Kge(e);for(c8.set(e,n);c8.size>Wge;){let e=c8.keys().next().value;if(e===void 0)break;c8.delete(e)}return n}function Kge(e){let t=r6().use(pB).use(Bge),n=t.runSync(t.parse(e)).children.map(e=>{if(e.type!==`paragraph`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.children.map(e=>{if(e.type!==`text`)throw Error(`Slopify hit an internal error (the article couldn't be turned into plain text). Try again; if it happens again, use Download diagnostics in Settings and report it.`);return e.value}).join(``)}).filter(e=>e.trim()!==``);return n.length===0?``:n.join(`
284
284
 
285
285
  `)+`
286
- `}var l8={"sources consulted":`sources`,"pronunciation glossary":`glossary`},Kge=16,u8=new Map;function d8(e){let t=u8.get(e);if(t!==void 0)return t;let n=qge(e);for(u8.set(e,n);u8.size>Kge;){let e=u8.keys().next().value;if(e===void 0)break;u8.delete(e)}return n}function qge(e){let t=Jge(e),n=t[0];if(n===void 0)return{body:e,sources:``,glossary:``};let r={sources:``,glossary:``};for(let[n,i]of t.entries())r[i.part]+=e.slice(i.at,t[n+1]?.at??e.length);return{body:e.slice(0,n.at),sources:r.sources,glossary:r.glossary}}function Jge(e){let t=r6().use(pB).parse(e),n=[];for(let r of t.children){if(r.type!==`heading`&&r.type!==`paragraph`)continue;let t=r.position?.start.offset,i=r.position?.end.offset;if(t===void 0||i===void 0)continue;let a=Zge(e.slice(t,i));a!==void 0&&n.push({part:a,at:t})}return n}var Yge=Object.keys(l8).map(e=>e.replace(/[^a-z]/g,``));function Xge(e){let t=e.toLowerCase().replace(/[^a-z]/g,``);return Yge.some(e=>{let n=0;for(let r of t)r===e[n]&&(n+=1);return n>=e.length})}function Zge(e){return Xge(e)?l8[Wge(e).trim().toLowerCase().replace(/:$/,``)]:void 0}function Qge({script:e,voices:t}){let n=(0,m.useMemo)(()=>u6(e,t.speakers),[e,t.speakers]);if(!n.ok)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`This script can't be narrated yet: `,n.reason,` Fix it in Edit project → Article.`]});let r=new Map(t.speakers.map((e,t)=>[e.id,t])),i=new Map(t.speakers.map(e=>[e.id,e.name.trim()]));return(0,h.jsx)(`ol`,{"aria-label":`Script`,className:`space-y-3`,children:n.script.turns.map(e=>{let t=n.script.sections.find(t=>t.firstTurn===e.index),a=`var(--color-speaker-${String((r.get(e.speaker)??0)%6+1)})`;return(0,h.jsxs)(`li`,{className:`space-y-2`,children:[t===void 0?null:(0,h.jsx)(`h3`,{className:`pt-2 text-title-3 font-semibold text-ink`,children:t.title}),(0,h.jsxs)(`div`,{className:`border-l-4 pl-3`,style:{borderColor:a},children:[(0,h.jsx)(`p`,{className:`text-label font-semibold text-ink-2`,children:i.get(e.speaker)??e.speaker}),(0,h.jsx)(`p`,{className:`text-body text-ink`,children:e.text})]})]},e.index)})})}function f8(e,t){return e.filter(e=>e.stageKind===t.kind)}function p8(e,t){return e.find(e=>e.role===t)}var m8=Lv,h8=Rv;function g8({className:e,sideOffset:t=4,align:n=`end`,...r}){return(0,h.jsx)(zv,{children:(0,h.jsx)(Bv,{"data-slot":`menu-content`,sideOffset:t,align:n,className:L(`z-50 min-w-[180px] overflow-hidden rounded-control border border-line bg-raised p-1`,`shadow-[var(--shadow-pop)]`,e),...r})})}function _8({className:e,...t}){return(0,h.jsx)(Vv,{"data-slot":`menu-item`,className:L(`flex cursor-default items-center gap-2 rounded-control px-[10px] py-[6px] text-small text-ink`,`outline-hidden select-none focus:bg-sunken data-highlighted:bg-sunken`,`data-disabled:text-ink-3`,e),...t})}function $ge({className:e}){return(0,h.jsx)(Hv,{className:L(`my-1 h-px bg-line`,e)})}var v8=(0,m.createContext)(null);function e_e({projectId:e,revisionId:t,children:n}){let{api:r}=z(),i=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved version yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);let i=n.value.view;if(i.revision.id!==t||i.revision.projectId!==e)throw Error(`The project changed while its files were loading. Reload the page.`);return i}});return(0,h.jsxs)(v8,{value:{projectId:e,revisionId:t,view:i.data},children:[i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:i.error.message}),n]})}function y8(){return(0,m.useContext)(v8)?.view}function b8(e){let t=(0,m.useContext)(v8),{api:n}=z();return S8(n,t,e)}function x8(e){let t=(0,m.useContext)(v8),{api:n}=z(),r=new Map;for(let i of e){let e=S8(n,t,i);e!==void 0&&r.set(i.id,e)}return r}function S8(e,t,n){if(n===void 0||t!==null&&t.projectId!==n.projectId)return;if(t===null||t.revisionId===null)return{url:Ko(e,n.projectId,D3(n)),cacheKey:B.file(n.projectId,n.id),folder:null};let r=t.view?.outputs.find(e=>e.selected&&e.available&&e.output.id===n.id);return r===void 0?void 0:C8(e,t.projectId,t.revisionId,r)}function t_e(e,t){let n=(0,m.useContext)(v8),{api:r}=z();if(n!==null&&n.projectId!==e)return;if(n===null||n.revisionId===null)return{url:Ko(r,e,t),cacheKey:B.file(e,t),folder:null};let i=n.view?.outputs.find(e=>e.selected&&e.available&&(t===`images.zip`?e.output.role===`image`||e.output.role===`thumbnail`:D3(e.output)===t));if(i===void 0)return;let a=C8(r,e,n.revisionId,i);return t===`images.zip`?{...a,url:s2(r,e,n.revisionId,`images.zip`),cacheKey:B.revisionFile(e,n.revisionId,`images.zip`)}:a}function C8(e,t,n,r){return{url:s2(e,t,n,r.recordId),cacheKey:B.revisionFile(t,n,r.recordId),folder:{revisionId:n,recordId:r.recordId}}}function w8({children:e,className:t}){return(0,h.jsx)(`div`,{className:L(`flex min-w-0 flex-col gap-5`,t),children:e})}function T8({children:e}){return(0,h.jsx)(`span`,{className:`sl-kicker`,children:e})}var n_e={h1:({children:e})=>(0,h.jsx)(E8,{size:`text-title-2`,children:e}),h2:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h3:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h4:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h5:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h6:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),p:({children:e})=>(0,h.jsx)(`p`,{className:`m-0`,children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),ul:({children:e})=>(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5`,children:e}),ol:({children:e})=>(0,h.jsx)(`ol`,{className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:e}),li:({children:e})=>(0,h.jsx)(`li`,{className:`m-0`,children:e}),a:({children:e,href:t})=>(0,h.jsx)(`a`,{href:t,className:`rounded-control text-accent-ink underline underline-offset-[3px]`,target:`_blank`,rel:`noreferrer`,children:e}),code:({children:e})=>(0,h.jsx)(`code`,{className:`rounded-control bg-sunken px-1 py-0.5 font-mono text-small`,children:e}),pre:({children:e})=>(0,h.jsx)(`pre`,{className:`m-0 overflow-x-auto rounded-control bg-sunken p-3 font-mono text-small`,children:e}),blockquote:({children:e})=>(0,h.jsx)(`blockquote`,{className:`m-0 flex flex-col gap-2 border-l-2 border-line-strong pl-3 text-ink-2`,children:e}),hr:()=>(0,h.jsx)(`hr`,{className:`my-2 border-line`}),table:({children:e})=>(0,h.jsx)(`table`,{className:`w-full border-collapse text-left text-small`,children:e}),th:({children:e})=>(0,h.jsx)(`th`,{className:`sl-kicker border-b border-line py-2 pr-4 text-left`,children:e}),td:({children:e})=>(0,h.jsx)(`td`,{className:`border-b border-line py-2 pr-4 align-top`,children:e})},r_e={p:({children:e})=>(0,h.jsx)(h.Fragment,{children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),a:({children:e})=>(0,h.jsx)(h.Fragment,{children:e})};function E8({size:e,children:t}){return(0,h.jsx)(`h3`,{className:L(`mt-2 font-bold tracking-[-0.01em]`,e),children:t})}function D8({markdown:e}){return(0,h.jsx)(`div`,{className:`flex max-w-[68ch] flex-col gap-2 text-pretty text-body text-ink`,children:(0,h.jsx)(sz,{remarkPlugins:[pB],components:n_e,children:e})})}function i_e({markdown:e}){return(0,h.jsx)(sz,{remarkPlugins:[pB],components:r_e,children:e})}var a_e=/^#{1,6}[ \t]+(.*?)[ \t]*#*[ \t]*(?:\r?\n|$)/;function o_e(e){let t=e.replace(/^[\s]*\n/,``),n=a_e.exec(t);return n===null?{title:void 0,body:e.trim()}:{title:n[1]??``,body:t.slice(n[0].length).trim()}}function s_e({projectId:e,asset:t,label:n=`Download`,variant:r=`primary`}){let i=t_e(e,t);return i===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]}),(0,h.jsx)(u2,{projectId:e,asset:t,folder:i.folder})]})}function c_e(e){return e.flatMap(e=>e.output===void 0?[]:[e.output])}function O8({files:e,label:t=`Download`,variant:n=`primary`}){let r=e.filter(e=>e.output!==void 0),[i]=r;return i===void 0?null:r.length===1?(0,h.jsx)(l_e,{output:i.output,label:t,file:i.label,variant:n}):(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsxs)(R,{variant:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t,(0,h.jsx)(uc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(g8,{children:r.map(e=>(0,h.jsx)(u_e,{output:e.output,label:e.label},e.output.id))})]})}function l_e({output:e,label:t,file:n,variant:r}){let i=b8(e);return i===void 0?null:(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,title:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t]})}function u_e({output:e,label:t}){let n=b8(e);return n===void 0?null:(0,h.jsx)(_8,{asChild:!0,children:(0,h.jsxs)(`a`,{href:n.url,download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),t]})})}function k8({output:e}){let t=b8(e);return e===void 0||t===void 0?null:(0,h.jsx)(u2,{projectId:e.projectId,asset:D3(e),folder:t.folder})}function A8({files:e,label:t=`Download`,variant:n=`primary`,children:r}){let i=c_e(e);return i.length===0&&r===void 0?null:(0,h.jsxs)(Ey,{children:[(0,h.jsx)(O8,{files:e,label:t,variant:n}),(0,h.jsx)(k8,{output:i[0]}),r]})}function j8({children:e}){return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:e})}function M8(e){let{api:t}=z(),n=b8(e);return N({queryKey:n?.cacheKey??B.revisionFile(``,``,`unavailable`),queryFn:async()=>n===void 0?``:lo(await t.fetch(n.url)),enabled:n!==void 0,staleTime:1/0})}function d_e({output:e,as:t=`prose`}){let n=M8(e);return n.error===null?n.data===void 0?(0,h.jsx)(`span`,{className:`h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):t===`prose`?(0,h.jsx)(D8,{markdown:n.data}):(0,h.jsx)(`pre`,{className:`m-0 max-w-[68ch] overflow-x-auto whitespace-pre-wrap font-sans text-small text-ink-2`,children:n.data}):(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:n.error.message})}function N8({output:e}){let[t,n]=(0,m.useState)(!1);return e===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":t,onClick:()=>{n(!t)},children:t?`Hide instructions`:`Show instructions`}),t?(0,h.jsx)(`div`,{className:`w-full basis-full`,children:(0,h.jsx)(d_e,{output:e,as:`plain`})}):null]})}function f_e({projectId:e,stage:t,notes:n,onCopy:r}){let i=t.state===`running`,a=M8(n);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[i?(0,h.jsx)(j3,{projectId:e,stage:`research`,className:``}):null,i&&n===void 0?null:a.error===null?(0,h.jsx)(CB,{markdown:a.data??``,label:`Research notes`,regionLabel:`Research notes`,anchorPrefix:`research-`,what:`research notes`,onCopy:r,copyAll:!1,children:n===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:p_e(t)}):(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}):(0,h.jsx)(`p`,{className:`text-body text-danger`,children:a.error.message})]})}function p_e(e){switch(e.state){case`failed`:case`canceled`:return`Research stopped before any notes were saved. Try the research again with the next action beside it.`;case`pending`:return`The research runs first; its notes appear here when it finishes.`;default:return`No notes were written.`}}var m_e=[{segment:`intro`,name:`Intro`},{segment:`body`,name:`Body`},{segment:`outro`,name:`Outro`}];function P8(e){let t=/\.([a-z0-9]+)$/i.exec(e.path);return t===null?``:` (.${(t[1]??``).toLowerCase()})`}function h_e(e,t=[],n){return[...g_e(e,t),...n===void 0?[]:[{output:n,label:`Script by speaker${P8(n)}`}]]}function g_e(e,t){return m_e.flatMap(({segment:n,name:r})=>{let i=t=>e.find(e=>e.role===t&&e.meta.segment===n),a=t.find(e=>e.segment===n)?.output,o=i(`narration_txt`),s=i(`tts_script`);return[...a===void 0?[]:[{output:a,label:`${r} narration${P8(a)}`}],...o===void 0?[]:[{output:o,label:`${r} clean narration${P8(o)}`}],...s===void 0?[]:[{output:s,label:`${r} TTS script${P8(s)}`}]]})}function __e(e){return e.some(e=>e.role===`narration_txt`||e.role===`tts_script`)}function F8(e){let{api:t}=z();return(N({queryKey:M3(e),queryFn:()=>Cme(t,e)}).data??[]).filter(e=>e.current)}function I8(e,t){return e.find(e=>t.itemKey===void 0?t.outputId!==void 0&&e.outputId===t.outputId:e.itemKey===t.itemKey)}function v_e(e){return e.passed?e.attempt>1?{label:`Redone after review`,tone:`info`}:{label:`Review passed`,tone:`neutral`}:e.action===`overruled`?{label:`Accepted by you`,tone:`neutral`}:e.action===`redone`?{label:`Being made again`,tone:`running`}:e.redoState===`pending`?{label:`Waiting to be made again`,tone:`running`}:e.redoState===`started`?{label:`Being made again`,tone:`running`}:{label:`Flagged by review`,tone:`info`}}function y_e({review:e}){let t=v_e(e);return(0,h.jsx)(vS,{tone:t.tone,children:t.label})}function L8({review:e}){return(0,h.jsx)(y_e,{review:e})}function R8({review:e}){return(0,h.jsxs)(h.Fragment,{children:[e.reasons.length===0?(0,h.jsx)(`p`,{className:`m-0`,children:`The reviewer found nothing to fix.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-4`,children:e.reasons.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:e.outcome===`flagged`&&!e.passed&&e.attempt>1?`Kept after ${String(e.attempt)} tries: the redo limit was reached.`:`Try ${String(e.attempt)}.`}),e.redoState===`failed`&&e.redoError?(0,h.jsx)(`p`,{className:`m-0 text-danger`,children:e.redoError}):null]})}function z8({review:e,projectId:t,busy:n}){let{api:r}=z(),i=_(),[a,o]=(0,m.useState)(null),s=P({mutationFn:async n=>{let a=i.getQueryData(B.project(t))?.revisionId;return wme(r,t,e.id,n,n===`redo`&&a?{baseRevisionId:a,idempotencyKey:crypto.randomUUID()}:void 0)},onSuccess:async e=>{o(e.ok?null:e.message),await i.invalidateQueries({queryKey:M3(t)}),await i.invalidateQueries({queryKey:B.project(t)})},onError:e=>o(e.message)});if(e.passed||e.action!==null)return null;let c=e.redoState===`pending`,l=c||e.redoState===`started`;return(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n&&!c||e.redoState===`started`||s.isPending,disabledReason:e.redoState===`started`?`Slopify is already making this item again; wait for the new version`:`Wait until the work on this project is done`,onClick:()=>s.mutate(`overrule`),children:`Overrule`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n||l||s.isPending,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.mutate(`redo`),children:`Redo`}),a?(0,h.jsx)(`span`,{role:`alert`,className:`basis-full text-small text-danger`,children:a}):null]})}function B8({review:e,projectId:t,busy:n}){return e===void 0?null:(0,h.jsxs)(`section`,{"aria-label":`${Tk[e.stage]} review`,className:`flex min-w-0 flex-col gap-1 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsx)(z8,{review:e,projectId:t,busy:n})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-1 text-ink-2`,children:(0,h.jsx)(R8,{review:e})})]})}function V8({review:e}){return e===void 0||e.passed&&e.attempt<=1?null:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{type:`button`,"aria-label":`About this review`,className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Cc,{"aria-hidden":`true`,className:`size-[15px]`})}),(0,h.jsx)(Eb,{className:`space-y-2 leading-[1.45]`,children:(0,h.jsx)(R8,{review:e})})]})]})}function b_e(e){let t=[e.stage,e.companion].filter(e=>e!==void 0);for(let e of[`failed`,`canceled`,`running`]){let n=t.find(t=>t.state===e);if(n!==void 0)return n}return e.stage.state===`skipped`&&e.companion!==void 0?e.companion:e.stage}var H8=e=>e.state!==`pending`&&e.state!==`skipped`;function x_e(e){return e.replace(/^\s*[^\n]*\n?/u,``).trim()}function S_e({stage:e,companion:t,project:n,outputs:r,busy:i}){let a=F8(n.id),o=k3(n.id),s=f8(r,e),c=t?.kind===`research`?t:void 0,l=c===void 0?[]:f8(r,c),u=p8(l,`notes`),d=M8(u),f=p8(s,`article_md`)??p8(s,`article_txt`),p=p8(s,`sources`),g=p8(s,`glossary`),_=HA(n.config)?n.config.voices:void 0,v=p8(s,`script_md`),y=M8(v),b=M8(f),x=N({queryKey:A3(n.id,o),queryFn:()=>[],enabled:!1}).data?.some(e=>e.stage===`article`)===!0,S=N({queryKey:B.article(n.id,o),queryFn:()=>``,enabled:!1}),C=b.data??``,w=e.state===`running`,T=o_e(w?S.data??``:C),E=T.title??n.title,D=(0,m.useMemo)(()=>w?{body:T.body,sources:``,glossary:``}:d8(T.body),[w,T.body]),O=(0,m.useMemo)(()=>Ige(D.sources),[D.sources]),k=x_e(D.glossary),A=(0,m.useMemo)(()=>{if(D.glossary.trim()===``)return[];let e=c6(D.glossary);return e.ok?e.skipped??[]:[]},[D.glossary]),ee=_===void 0||w?``:_.source===`script`?d8(C).body:y.data??``,te=[{id:`article`,label:_?.source===`script`?`Script text`:`Article`},...ee.trim()===``?[]:[{id:`script`,label:`Speakers`}],...c===void 0?[]:[{id:`research`,label:`Research`}],...O.length>0?[{id:`sources`,label:`Sources`,badge:String(O.length)}]:[],...k===``?[]:[{id:`pronunciation`,label:`Pronunciation`}]],ne=c!==void 0&&b_e({kind:`article`,stage:e,companion:c})===c,[j,re]=(0,m.useState)(),M=j??(ne?`research`:`article`),ie=te.some(e=>e.id===M)?M:`article`,ae=(0,m.useId)().replace(/:/gu,``),[oe,se]=(0,m.useState)(),ce={article:`${T.title===void 0?``:`# ${T.title}\n\n`}${D.body.trim()}\n`,script:`${ee.trim()}\n`,research:`${(d.data??``).trim()}\n`,sources:`${O.map(e=>`- ${e}`).join(`
287
- `)}\n`,pronunciation:`${k}\n`},le={article:`article`,script:`script`,research:`research notes`,sources:`sources`,pronunciation:`pronunciation table`},ue=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>se({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),de=e=>ue(ce[e],le[e]);return(0,h.jsxs)(w8,{children:[(0,h.jsx)(B8,{review:I8(a,{itemKey:`article:body`}),projectId:n.id,busy:i}),(0,h.jsxs)(A8,{files:[...f===void 0?[]:[{output:f,label:`Article${P8(f)}`}],...p===void 0?[]:[{output:p,label:`Sources${P8(p)}`}],...g===void 0?[]:[{output:g,label:`Pronunciation glossary${P8(g)}`}],...u===void 0?[]:[{output:u,label:`Research notes${P8(u)}`}],...v===void 0?[]:[{output:v,label:`Script by speaker${P8(v)}`}]],children:[(ie===`research`?c?.state===`running`||d.data===void 0:w||C===``)?null:(0,h.jsxs)(R,{variant:`secondary`,onClick:()=>de(ie),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy `,le[ie]]}),ie===`research`&&c!==void 0?(0,h.jsx)(N8,{output:p8(l,`instructions`)}):(0,h.jsx)(N8,{output:p8(s,`instructions`)}),(0,h.jsx)(Q1,{tone:oe?.tone??`info`,children:oe?.text})]}),b.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:b.error.message}),te.length>1?(0,h.jsx)(r0,{items:te,value:ie,onChange:e=>{re(e),se(void 0)},label:`Article parts`,idPrefix:ae}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3 font-semibold text-ink`,children:(0,h.jsx)(i_e,{markdown:E})}),D.body.trim()===``?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:C_e(D.body)})]}),(0,h.jsx)(i0,{idPrefix:ae,id:`article`,active:ie===`article`,children:w?(0,h.jsx)(`section`,{"aria-label":`Article content`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:x?(0,h.jsx)(j3,{projectId:n.id,stage:`article`,className:``}):(0,h.jsx)(D8,{markdown:D.body})}):(0,h.jsx)(CB,{markdown:D.body,label:`Article`,regionLabel:`Article content`,anchorPrefix:`article-`,what:`article`,onCopy:ue,copyAll:!1,children:H8(e)&&f!==void 0&&b.data===void 0?(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:H8(e)?`No article was saved.`:c===void 0?`The article will be written when its inputs are ready.`:`The article is written once the research has finished.`})})}),_===void 0||ee.trim()===``?null:(0,h.jsx)(i0,{idPrefix:ae,id:`script`,active:ie===`script`,children:(0,h.jsx)(`section`,{"aria-label":`Script by speaker`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:(0,h.jsx)(Qge,{script:ee,voices:_})})}),c===void 0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`research`,active:ie===`research`,children:(0,h.jsx)(f_e,{projectId:n.id,stage:c,notes:u,onCopy:ue})}),O.length===0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`sources`,active:ie===`sources`,children:(0,h.jsx)(CB,{markdown:O.map((e,t)=>`${String(t+1)}. ${e}`).join(`
288
- `),label:`Sources`,regionLabel:`Sources`,anchorPrefix:`sources-`,what:`sources`,onCopy:ue,copyAll:!1})}),k===``?null:(0,h.jsxs)(i0,{idPrefix:ae,id:`pronunciation`,active:ie===`pronunciation`,children:[A.length===0?null:(0,h.jsxs)(SI,{className:`mb-3`,title:`${A.length===1?`1 entry is`:`${A.length} entries are`} skipped by the narration and read as ordinary text`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:A.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsx)(`p`,{className:`m-0 mt-1`,children:`The other entries are used. To fix these, edit the Pronunciation Glossary at the end of the article in Edit settings → Article.`})]}),(0,h.jsx)(`div`,{className:`sl-stage-scroll pr-3`,children:(0,h.jsx)(D8,{markdown:k})})]})]})}var U8=new Intl.NumberFormat(`en`);function C_e(e){let t=e.replace(/\]\([^)]*\)/g,`]`).replace(/[#*_>`[\]]/g,``).replace(/[ \t]+/g,` `).trim(),n=t.split(/\s+/).filter(e=>/[\p{L}\p{N}]/u.test(e)).length,r=t.replace(/\s*\n\s*/g,` `).length;return`${U8.format(n)} ${n===1?`word`:`words`} · ${U8.format(r)} characters`}function W8({className:e,label:t,children:n}){return(0,h.jsx)(`dl`,{"aria-label":t,className:L(`m-0 grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[max-content_minmax(0,1fr)] sm:gap-y-3`,e),children:n})}function G8({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2 max-sm:mt-2 max-sm:first:mt-0`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function K8({src:e,label:t,marks:n=[],waveform:r,compact:i=!1,preload:a=`metadata`,onError:o,ref:s,className:c}){let l=A0(),u=l.media;return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`${t} controls`,"data-slot":`audio-player`,"data-state":l.playing?`playing`:`paused`,className:L(`sl-audio`,i&&`sl-audio--compact`,r!==void 0&&r.length>0&&`sl-audio--wave`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.key===` `&&e.target.closest(`button`)!==null)return;let t=l.keyAction(e.key);t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||l.setMenu(!1)},children:[(0,h.jsx)(`audio`,{ref:O0(u,s),src:e,preload:a,"aria-label":t,onError:o,...l.events}),(0,h.jsx)(N0,{controls:l,className:`sl-audio__key`}),(0,h.jsx)(P0,{controls:l}),(0,h.jsx)(F0,{controls:l,chapters:n,waveform:r}),(0,h.jsx)(I0,{controls:l}),(0,h.jsx)(L0,{controls:l})]})}function q8({projectId:e,revisionId:t}){let n=k3(e),r=t===void 0?n:t,{api:i}=z(),a=N({queryKey:B.audioPreview(e,r),queryFn:async()=>F(await i.client.projects[`:projectId`][`audio-preview`].$get({param:{projectId:e}})),refetchInterval:1e3,staleTime:0,gcTime:0,retry:!1}),o=(a.data?.revisionId??null)===r?a.data?.previews??[]:[];return(0,h.jsxs)(`section`,{"aria-label":`Live narration`,className:`grid gap-3 border-y border-line py-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-ink`,children:`Listen while it generates`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Play any part. Each preview starts from its beginning.`})]}),a.error===null?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Live preview is temporarily unavailable. Finished audio will still appear here.`}),o.length===0&&a.error===null?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Waiting for the first audio bytes…`}):null,(0,h.jsx)(`div`,{className:`grid max-h-[420px] gap-3 overflow-y-auto`,children:o.map(t=>(0,h.jsx)(w_e,{preview:t,url:`${i.origin}/api/projects/${encodeURIComponent(e)}/audio-preview/${t.id}`},t.id))})]})}function w_e({preview:e,url:t}){let[n,r]=(0,m.useState)(!1),i=(e.state===`streaming`||e.state===`ready`)&&e.bytes>0,a=e.state===`ready`?`Ready`:e.state===`streaming`?`Generating`:`Preview stopped`;return(0,h.jsxs)(`div`,{className:`grid gap-2 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:e.label}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:a})]}),i&&!n?(0,h.jsx)(T_e,{label:e.label,url:t,onError:()=>r(!0)}):(0,h.jsx)(`p`,{className:`text-ink-2`,children:e.state===`streaming`&&!n?`Waiting for audio…`:`This preview has stopped. The finished narration will be available when generation completes.`})]})}function T_e({label:e,url:t,onError:n}){let r=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=r.current;return()=>{e!==null&&(e.pause(),e.removeAttribute(`src`),e.load())}},[]),(0,h.jsx)(K8,{ref:r,compact:!0,preload:`none`,label:`Live ${e} narration`,src:t,onError:n,className:`max-w-[620px]`})}function E_e({outputs:e}){let t=(0,m.useId)(),n=t=>e.find(e=>e.role===`narration_txt`&&e.meta.segment===t),r=M8(n(`intro`)).data,i=M8(n(`body`)).data,a=M8(n(`outro`)).data,[o,s]=(0,m.useState)(),c=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>s({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),l=[[`Intro`,r],[`Body`,i],[`Outro`,a]].filter(([,e])=>e!==void 0&&e.trim()!==``);if(!e.some(e=>e.role===`narration_txt`))return null;let u=l.length===1?(l[0]?.[1]??``).trim():l.map(([e,t])=>`## ${e}\n\n${(t??``).trim()}`).join(`
286
+ `}var l8={"sources consulted":`sources`,"pronunciation glossary":`glossary`},qge=16,u8=new Map;function d8(e){let t=u8.get(e);if(t!==void 0)return t;let n=Jge(e);for(u8.set(e,n);u8.size>qge;){let e=u8.keys().next().value;if(e===void 0)break;u8.delete(e)}return n}function Jge(e){let t=Yge(e),n=t[0];if(n===void 0)return{body:e,sources:``,glossary:``};let r={sources:``,glossary:``};for(let[n,i]of t.entries())r[i.part]+=e.slice(i.at,t[n+1]?.at??e.length);return{body:e.slice(0,n.at),sources:r.sources,glossary:r.glossary}}function Yge(e){let t=r6().use(pB).parse(e),n=[];for(let r of t.children){if(r.type!==`heading`&&r.type!==`paragraph`)continue;let t=r.position?.start.offset,i=r.position?.end.offset;if(t===void 0||i===void 0)continue;let a=Qge(e.slice(t,i));a!==void 0&&n.push({part:a,at:t})}return n}var Xge=Object.keys(l8).map(e=>e.replace(/[^a-z]/g,``));function Zge(e){let t=e.toLowerCase().replace(/[^a-z]/g,``);return Xge.some(e=>{let n=0;for(let r of t)r===e[n]&&(n+=1);return n>=e.length})}function Qge(e){return Zge(e)?l8[Gge(e).trim().toLowerCase().replace(/:$/,``)]:void 0}function $ge({script:e,voices:t}){let n=(0,m.useMemo)(()=>u6(e,t.speakers),[e,t.speakers]);if(!n.ok)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`This script can't be narrated yet: `,n.reason,` Fix it in Edit project → Article.`]});let r=new Map(t.speakers.map((e,t)=>[e.id,t])),i=new Map(t.speakers.map(e=>[e.id,e.name.trim()]));return(0,h.jsx)(`ol`,{"aria-label":`Script`,className:`space-y-3`,children:n.script.turns.map(e=>{let t=n.script.sections.find(t=>t.firstTurn===e.index),a=`var(--color-speaker-${String((r.get(e.speaker)??0)%6+1)})`;return(0,h.jsxs)(`li`,{className:`space-y-2`,children:[t===void 0?null:(0,h.jsx)(`h3`,{className:`pt-2 text-title-3 font-semibold text-ink`,children:t.title}),(0,h.jsxs)(`div`,{className:`border-l-4 pl-3`,style:{borderColor:a},children:[(0,h.jsx)(`p`,{className:`text-label font-semibold text-ink-2`,children:i.get(e.speaker)??e.speaker}),(0,h.jsx)(`p`,{className:`text-body text-ink`,children:e.text})]})]},e.index)})})}function f8(e,t){return e.filter(e=>e.stageKind===t.kind)}function p8(e,t){return e.find(e=>e.role===t)}var m8=Lv,h8=Rv;function g8({className:e,sideOffset:t=4,align:n=`end`,...r}){return(0,h.jsx)(zv,{children:(0,h.jsx)(Bv,{"data-slot":`menu-content`,sideOffset:t,align:n,className:L(`z-50 min-w-[180px] overflow-hidden rounded-control border border-line bg-raised p-1`,`shadow-[var(--shadow-pop)]`,e),...r})})}function _8({className:e,...t}){return(0,h.jsx)(Vv,{"data-slot":`menu-item`,className:L(`flex cursor-default items-center gap-2 rounded-control px-[10px] py-[6px] text-small text-ink`,`outline-hidden select-none focus:bg-sunken data-highlighted:bg-sunken`,`data-disabled:text-ink-3`,e),...t})}function e_e({className:e}){return(0,h.jsx)(Hv,{className:L(`my-1 h-px bg-line`,e)})}var v8=(0,m.createContext)(null);function t_e({projectId:e,revisionId:t,children:n}){let{api:r}=z(),i=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved version yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);let i=n.value.view;if(i.revision.id!==t||i.revision.projectId!==e)throw Error(`The project changed while its files were loading. Reload the page.`);return i}});return(0,h.jsxs)(v8,{value:{projectId:e,revisionId:t,view:i.data},children:[i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:i.error.message}),n]})}function y8(){return(0,m.useContext)(v8)?.view}function b8(e){let t=(0,m.useContext)(v8),{api:n}=z();return S8(n,t,e)}function x8(e){let t=(0,m.useContext)(v8),{api:n}=z(),r=new Map;for(let i of e){let e=S8(n,t,i);e!==void 0&&r.set(i.id,e)}return r}function S8(e,t,n){if(n===void 0||t!==null&&t.projectId!==n.projectId)return;if(t===null||t.revisionId===null)return{url:Ko(e,n.projectId,D3(n)),cacheKey:B.file(n.projectId,n.id),folder:null};let r=t.view?.outputs.find(e=>e.selected&&e.available&&e.output.id===n.id);return r===void 0?void 0:C8(e,t.projectId,t.revisionId,r)}function n_e(e,t){let n=(0,m.useContext)(v8),{api:r}=z();if(n!==null&&n.projectId!==e)return;if(n===null||n.revisionId===null)return{url:Ko(r,e,t),cacheKey:B.file(e,t),folder:null};let i=n.view?.outputs.find(e=>e.selected&&e.available&&(t===`images.zip`?e.output.role===`image`||e.output.role===`thumbnail`:D3(e.output)===t));if(i===void 0)return;let a=C8(r,e,n.revisionId,i);return t===`images.zip`?{...a,url:s2(r,e,n.revisionId,`images.zip`),cacheKey:B.revisionFile(e,n.revisionId,`images.zip`)}:a}function C8(e,t,n,r){return{url:s2(e,t,n,r.recordId),cacheKey:B.revisionFile(t,n,r.recordId),folder:{revisionId:n,recordId:r.recordId}}}function w8({children:e,className:t}){return(0,h.jsx)(`div`,{className:L(`flex min-w-0 flex-col gap-5`,t),children:e})}function T8({children:e}){return(0,h.jsx)(`span`,{className:`sl-kicker`,children:e})}var r_e={h1:({children:e})=>(0,h.jsx)(E8,{size:`text-title-2`,children:e}),h2:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h3:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h4:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h5:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),h6:({children:e})=>(0,h.jsx)(E8,{size:`text-title-3`,children:e}),p:({children:e})=>(0,h.jsx)(`p`,{className:`m-0`,children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),ul:({children:e})=>(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5`,children:e}),ol:({children:e})=>(0,h.jsx)(`ol`,{className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:e}),li:({children:e})=>(0,h.jsx)(`li`,{className:`m-0`,children:e}),a:({children:e,href:t})=>(0,h.jsx)(`a`,{href:t,className:`rounded-control text-accent-ink underline underline-offset-[3px]`,target:`_blank`,rel:`noreferrer`,children:e}),code:({children:e})=>(0,h.jsx)(`code`,{className:`rounded-control bg-sunken px-1 py-0.5 font-mono text-small`,children:e}),pre:({children:e})=>(0,h.jsx)(`pre`,{className:`m-0 overflow-x-auto rounded-control bg-sunken p-3 font-mono text-small`,children:e}),blockquote:({children:e})=>(0,h.jsx)(`blockquote`,{className:`m-0 flex flex-col gap-2 border-l-2 border-line-strong pl-3 text-ink-2`,children:e}),hr:()=>(0,h.jsx)(`hr`,{className:`my-2 border-line`}),table:({children:e})=>(0,h.jsx)(`table`,{className:`w-full border-collapse text-left text-small`,children:e}),th:({children:e})=>(0,h.jsx)(`th`,{className:`sl-kicker border-b border-line py-2 pr-4 text-left`,children:e}),td:({children:e})=>(0,h.jsx)(`td`,{className:`border-b border-line py-2 pr-4 align-top`,children:e})},i_e={p:({children:e})=>(0,h.jsx)(h.Fragment,{children:e}),strong:({children:e})=>(0,h.jsx)(`strong`,{className:`font-semibold`,children:e}),a:({children:e})=>(0,h.jsx)(h.Fragment,{children:e})};function E8({size:e,children:t}){return(0,h.jsx)(`h3`,{className:L(`mt-2 font-bold tracking-[-0.01em]`,e),children:t})}function D8({markdown:e}){return(0,h.jsx)(`div`,{className:`flex max-w-[68ch] flex-col gap-2 text-pretty text-body text-ink`,children:(0,h.jsx)(sz,{remarkPlugins:[pB],components:r_e,children:e})})}function a_e({markdown:e}){return(0,h.jsx)(sz,{remarkPlugins:[pB],components:i_e,children:e})}var o_e=/^#{1,6}[ \t]+(.*?)[ \t]*#*[ \t]*(?:\r?\n|$)/;function s_e(e){let t=e.replace(/^[\s]*\n/,``),n=o_e.exec(t);return n===null?{title:void 0,body:e.trim()}:{title:n[1]??``,body:t.slice(n[0].length).trim()}}function c_e({projectId:e,asset:t,label:n=`Download`,variant:r=`primary`}){let i=n_e(e,t);return i===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]}),(0,h.jsx)(u2,{projectId:e,asset:t,folder:i.folder})]})}function l_e(e){return e.flatMap(e=>e.output===void 0?[]:[e.output])}function O8({files:e,label:t=`Download`,variant:n=`primary`}){let r=e.filter(e=>e.output!==void 0),[i]=r;return i===void 0?null:r.length===1?(0,h.jsx)(u_e,{output:i.output,label:t,file:i.label,variant:n}):(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsxs)(R,{variant:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t,(0,h.jsx)(uc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(g8,{children:r.map(e=>(0,h.jsx)(d_e,{output:e.output,label:e.label},e.output.id))})]})}function u_e({output:e,label:t,file:n,variant:r}){let i=b8(e);return i===void 0?null:(0,h.jsxs)(mS,{href:i.url,download:!0,variant:r,title:n,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),t]})}function d_e({output:e,label:t}){let n=b8(e);return n===void 0?null:(0,h.jsx)(_8,{asChild:!0,children:(0,h.jsxs)(`a`,{href:n.url,download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),t]})})}function k8({output:e}){let t=b8(e);return e===void 0||t===void 0?null:(0,h.jsx)(u2,{projectId:e.projectId,asset:D3(e),folder:t.folder})}function A8({files:e,label:t=`Download`,variant:n=`primary`,children:r}){let i=l_e(e);return i.length===0&&r===void 0?null:(0,h.jsxs)(Ey,{children:[(0,h.jsx)(O8,{files:e,label:t,variant:n}),(0,h.jsx)(k8,{output:i[0]}),r]})}function j8({children:e}){return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:e})}function M8(e){let{api:t}=z(),n=b8(e);return N({queryKey:n?.cacheKey??B.revisionFile(``,``,`unavailable`),queryFn:async()=>n===void 0?``:lo(await t.fetch(n.url)),enabled:n!==void 0,staleTime:1/0})}function f_e({output:e,as:t=`prose`}){let n=M8(e);return n.error===null?n.data===void 0?(0,h.jsx)(`span`,{className:`h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):t===`prose`?(0,h.jsx)(D8,{markdown:n.data}):(0,h.jsx)(`pre`,{className:`m-0 max-w-[68ch] overflow-x-auto whitespace-pre-wrap font-sans text-small text-ink-2`,children:n.data}):(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:n.error.message})}function N8({output:e}){let[t,n]=(0,m.useState)(!1);return e===void 0?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-expanded":t,onClick:()=>{n(!t)},children:t?`Hide instructions`:`Show instructions`}),t?(0,h.jsx)(`div`,{className:`w-full basis-full`,children:(0,h.jsx)(f_e,{output:e,as:`plain`})}):null]})}function p_e({projectId:e,stage:t,notes:n,onCopy:r}){let i=t.state===`running`,a=M8(n);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[i?(0,h.jsx)(j3,{projectId:e,stage:`research`,className:``}):null,i&&n===void 0?null:a.error===null?(0,h.jsx)(CB,{markdown:a.data??``,label:`Research notes`,regionLabel:`Research notes`,anchorPrefix:`research-`,what:`research notes`,onCopy:r,copyAll:!1,children:n===void 0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:m_e(t)}):(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}):(0,h.jsx)(`p`,{className:`text-body text-danger`,children:a.error.message})]})}function m_e(e){switch(e.state){case`failed`:case`canceled`:return`Research stopped before any notes were saved. Try the research again with the next action beside it.`;case`pending`:return`The research runs first; its notes appear here when it finishes.`;default:return`No notes were written.`}}var h_e=[{segment:`intro`,name:`Intro`},{segment:`body`,name:`Body`},{segment:`outro`,name:`Outro`}];function P8(e){let t=/\.([a-z0-9]+)$/i.exec(e.path);return t===null?``:` (.${(t[1]??``).toLowerCase()})`}function g_e(e,t=[],n){return[...__e(e,t),...n===void 0?[]:[{output:n,label:`Script by speaker${P8(n)}`}]]}function __e(e,t){return h_e.flatMap(({segment:n,name:r})=>{let i=t=>e.find(e=>e.role===t&&e.meta.segment===n),a=t.find(e=>e.segment===n)?.output,o=i(`narration_txt`),s=i(`tts_script`);return[...a===void 0?[]:[{output:a,label:`${r} narration${P8(a)}`}],...o===void 0?[]:[{output:o,label:`${r} clean narration${P8(o)}`}],...s===void 0?[]:[{output:s,label:`${r} TTS script${P8(s)}`}]]})}function v_e(e){return e.some(e=>e.role===`narration_txt`||e.role===`tts_script`)}function F8(e){let{api:t}=z();return(N({queryKey:M3(e),queryFn:()=>wme(t,e)}).data??[]).filter(e=>e.current)}function I8(e,t){return e.find(e=>t.itemKey===void 0?t.outputId!==void 0&&e.outputId===t.outputId:e.itemKey===t.itemKey)}function y_e(e){return e.passed?e.attempt>1?{label:`Redone after review`,tone:`info`}:{label:`Review passed`,tone:`neutral`}:e.action===`overruled`?{label:`Accepted by you`,tone:`neutral`}:e.action===`redone`?{label:`Being made again`,tone:`running`}:e.redoState===`pending`?{label:`Waiting to be made again`,tone:`running`}:e.redoState===`started`?{label:`Being made again`,tone:`running`}:{label:`Flagged by review`,tone:`info`}}function b_e({review:e}){let t=y_e(e);return(0,h.jsx)(vS,{tone:t.tone,children:t.label})}function L8({review:e}){return(0,h.jsx)(b_e,{review:e})}function R8({review:e}){return(0,h.jsxs)(h.Fragment,{children:[e.reasons.length===0?(0,h.jsx)(`p`,{className:`m-0`,children:`The reviewer found nothing to fix.`}):(0,h.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-4`,children:e.reasons.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:e.outcome===`flagged`&&!e.passed&&e.attempt>1?`Kept after ${String(e.attempt)} tries: the redo limit was reached.`:`Try ${String(e.attempt)}.`}),e.redoState===`failed`&&e.redoError?(0,h.jsx)(`p`,{className:`m-0 text-danger`,children:e.redoError}):null]})}function z8({review:e,projectId:t,busy:n}){let{api:r}=z(),i=_(),[a,o]=(0,m.useState)(null),s=P({mutationFn:async n=>{let a=i.getQueryData(B.project(t))?.revisionId;return Tme(r,t,e.id,n,n===`redo`&&a?{baseRevisionId:a,idempotencyKey:crypto.randomUUID()}:void 0)},onSuccess:async e=>{o(e.ok?null:e.message),await i.invalidateQueries({queryKey:M3(t)}),await i.invalidateQueries({queryKey:B.project(t)})},onError:e=>o(e.message)});if(e.passed||e.action!==null)return null;let c=e.redoState===`pending`,l=c||e.redoState===`started`;return(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n&&!c||e.redoState===`started`||s.isPending,disabledReason:e.redoState===`started`?`Slopify is already making this item again; wait for the new version`:`Wait until the work on this project is done`,onClick:()=>s.mutate(`overrule`),children:`Overrule`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:n||l||s.isPending,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.mutate(`redo`),children:`Redo`}),a?(0,h.jsx)(`span`,{role:`alert`,className:`basis-full text-small text-danger`,children:a}):null]})}function B8({review:e,projectId:t,busy:n}){return e===void 0?null:(0,h.jsxs)(`section`,{"aria-label":`${Tk[e.stage]} review`,className:`flex min-w-0 flex-col gap-1 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsx)(z8,{review:e,projectId:t,busy:n})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-1 text-ink-2`,children:(0,h.jsx)(R8,{review:e})})]})}function V8({review:e}){return e===void 0||e.passed&&e.attempt<=1?null:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,h.jsx)(L8,{review:e}),(0,h.jsxs)(Sb,{children:[(0,h.jsx)(Cb,{type:`button`,"aria-label":`About this review`,className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-ink-3 hover:bg-raised hover:text-ink`,children:(0,h.jsx)(Cc,{"aria-hidden":`true`,className:`size-[15px]`})}),(0,h.jsx)(Eb,{className:`space-y-2 leading-[1.45]`,children:(0,h.jsx)(R8,{review:e})})]})]})}function x_e(e){let t=[e.stage,e.companion].filter(e=>e!==void 0);for(let e of[`failed`,`canceled`,`running`]){let n=t.find(t=>t.state===e);if(n!==void 0)return n}return e.stage.state===`skipped`&&e.companion!==void 0?e.companion:e.stage}var H8=e=>e.state!==`pending`&&e.state!==`skipped`;function S_e(e){return e.replace(/^\s*[^\n]*\n?/u,``).trim()}function C_e({stage:e,companion:t,project:n,outputs:r,busy:i}){let a=F8(n.id),o=k3(n.id),s=f8(r,e),c=t?.kind===`research`?t:void 0,l=c===void 0?[]:f8(r,c),u=p8(l,`notes`),d=M8(u),f=p8(s,`article_md`)??p8(s,`article_txt`),p=p8(s,`sources`),g=p8(s,`glossary`),_=HA(n.config)?n.config.voices:void 0,v=p8(s,`script_md`),y=M8(v),b=M8(f),x=N({queryKey:A3(n.id,o),queryFn:()=>[],enabled:!1}).data?.some(e=>e.stage===`article`)===!0,S=N({queryKey:B.article(n.id,o),queryFn:()=>``,enabled:!1}),C=b.data??``,w=e.state===`running`,T=s_e(w?S.data??``:C),E=T.title??n.title,D=(0,m.useMemo)(()=>w?{body:T.body,sources:``,glossary:``}:d8(T.body),[w,T.body]),O=(0,m.useMemo)(()=>Lge(D.sources),[D.sources]),k=S_e(D.glossary),A=(0,m.useMemo)(()=>{if(D.glossary.trim()===``)return[];let e=c6(D.glossary);return e.ok?e.skipped??[]:[]},[D.glossary]),ee=_===void 0||w?``:_.source===`script`?d8(C).body:y.data??``,te=[{id:`article`,label:_?.source===`script`?`Script text`:`Article`},...ee.trim()===``?[]:[{id:`script`,label:`Speakers`}],...c===void 0?[]:[{id:`research`,label:`Research`}],...O.length>0?[{id:`sources`,label:`Sources`,badge:String(O.length)}]:[],...k===``?[]:[{id:`pronunciation`,label:`Pronunciation`}]],ne=c!==void 0&&x_e({kind:`article`,stage:e,companion:c})===c,[j,re]=(0,m.useState)(),M=j??(ne?`research`:`article`),ie=te.some(e=>e.id===M)?M:`article`,ae=(0,m.useId)().replace(/:/gu,``),[oe,se]=(0,m.useState)(),ce={article:`${T.title===void 0?``:`# ${T.title}\n\n`}${D.body.trim()}\n`,script:`${ee.trim()}\n`,research:`${(d.data??``).trim()}\n`,sources:`${O.map(e=>`- ${e}`).join(`
287
+ `)}\n`,pronunciation:`${k}\n`},le={article:`article`,script:`script`,research:`research notes`,sources:`sources`,pronunciation:`pronunciation table`},ue=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>se({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>se({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),de=e=>ue(ce[e],le[e]);return(0,h.jsxs)(w8,{children:[(0,h.jsx)(B8,{review:I8(a,{itemKey:`article:body`}),projectId:n.id,busy:i}),(0,h.jsxs)(A8,{files:[...f===void 0?[]:[{output:f,label:`Article${P8(f)}`}],...p===void 0?[]:[{output:p,label:`Sources${P8(p)}`}],...g===void 0?[]:[{output:g,label:`Pronunciation glossary${P8(g)}`}],...u===void 0?[]:[{output:u,label:`Research notes${P8(u)}`}],...v===void 0?[]:[{output:v,label:`Script by speaker${P8(v)}`}]],children:[(ie===`research`?c?.state===`running`||d.data===void 0:w||C===``)?null:(0,h.jsxs)(R,{variant:`secondary`,onClick:()=>de(ie),children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy `,le[ie]]}),ie===`research`&&c!==void 0?(0,h.jsx)(N8,{output:p8(l,`instructions`)}):(0,h.jsx)(N8,{output:p8(s,`instructions`)}),(0,h.jsx)(Q1,{tone:oe?.tone??`info`,children:oe?.text})]}),b.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:b.error.message}),te.length>1?(0,h.jsx)(r0,{items:te,value:ie,onChange:e=>{re(e),se(void 0)},label:`Article parts`,idPrefix:ae}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3 font-semibold text-ink`,children:(0,h.jsx)(a_e,{markdown:E})}),D.body.trim()===``?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 tabular-nums`,children:w_e(D.body)})]}),(0,h.jsx)(i0,{idPrefix:ae,id:`article`,active:ie===`article`,children:w?(0,h.jsx)(`section`,{"aria-label":`Article content`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:x?(0,h.jsx)(j3,{projectId:n.id,stage:`article`,className:``}):(0,h.jsx)(D8,{markdown:D.body})}):(0,h.jsx)(CB,{markdown:D.body,label:`Article`,regionLabel:`Article content`,anchorPrefix:`article-`,what:`article`,onCopy:ue,copyAll:!1,children:H8(e)&&f!==void 0&&b.data===void 0?(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-sunken`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:H8(e)?`No article was saved.`:c===void 0?`The article will be written when its inputs are ready.`:`The article is written once the research has finished.`})})}),_===void 0||ee.trim()===``?null:(0,h.jsx)(i0,{idPrefix:ae,id:`script`,active:ie===`script`,children:(0,h.jsx)(`section`,{"aria-label":`Script by speaker`,tabIndex:0,className:`sl-stage-scroll min-h-48 pr-3`,children:(0,h.jsx)($ge,{script:ee,voices:_})})}),c===void 0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`research`,active:ie===`research`,children:(0,h.jsx)(p_e,{projectId:n.id,stage:c,notes:u,onCopy:ue})}),O.length===0?null:(0,h.jsx)(i0,{idPrefix:ae,id:`sources`,active:ie===`sources`,children:(0,h.jsx)(CB,{markdown:O.map((e,t)=>`${String(t+1)}. ${e}`).join(`
288
+ `),label:`Sources`,regionLabel:`Sources`,anchorPrefix:`sources-`,what:`sources`,onCopy:ue,copyAll:!1})}),k===``?null:(0,h.jsxs)(i0,{idPrefix:ae,id:`pronunciation`,active:ie===`pronunciation`,children:[A.length===0?null:(0,h.jsxs)(SI,{className:`mb-3`,title:`${A.length===1?`1 entry is`:`${A.length} entries are`} skipped by the narration and read as ordinary text`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:A.map(e=>(0,h.jsxs)(`li`,{children:[`Entry `,e.row,`: `,e.reason,`.`]},e.row))}),(0,h.jsx)(`p`,{className:`m-0 mt-1`,children:`The other entries are used. To fix these, edit the Pronunciation Glossary at the end of the article in Edit settings → Article.`})]}),(0,h.jsx)(`div`,{className:`sl-stage-scroll pr-3`,children:(0,h.jsx)(D8,{markdown:k})})]})]})}var U8=new Intl.NumberFormat(`en`);function w_e(e){let t=e.replace(/\]\([^)]*\)/g,`]`).replace(/[#*_>`[\]]/g,``).replace(/[ \t]+/g,` `).trim(),n=t.split(/\s+/).filter(e=>/[\p{L}\p{N}]/u.test(e)).length,r=t.replace(/\s*\n\s*/g,` `).length;return`${U8.format(n)} ${n===1?`word`:`words`} · ${U8.format(r)} characters`}function W8({className:e,label:t,children:n}){return(0,h.jsx)(`dl`,{"aria-label":t,className:L(`m-0 grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-[max-content_minmax(0,1fr)] sm:gap-y-3`,e),children:n})}function G8({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2 max-sm:mt-2 max-sm:first:mt-0`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function K8({src:e,label:t,marks:n=[],waveform:r,compact:i=!1,preload:a=`metadata`,onError:o,ref:s,className:c}){let l=A0(),u=l.media;return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`${t} controls`,"data-slot":`audio-player`,"data-state":l.playing?`playing`:`paused`,className:L(`sl-audio`,i&&`sl-audio--compact`,r!==void 0&&r.length>0&&`sl-audio--wave`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey||e.key===` `&&e.target.closest(`button`)!==null)return;let t=l.keyAction(e.key);t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||l.setMenu(!1)},children:[(0,h.jsx)(`audio`,{ref:O0(u,s),src:e,preload:a,"aria-label":t,onError:o,...l.events}),(0,h.jsx)(N0,{controls:l,className:`sl-audio__key`}),(0,h.jsx)(P0,{controls:l}),(0,h.jsx)(F0,{controls:l,chapters:n,waveform:r}),(0,h.jsx)(I0,{controls:l}),(0,h.jsx)(L0,{controls:l})]})}function q8({projectId:e,revisionId:t}){let n=k3(e),r=t===void 0?n:t,{api:i}=z(),a=N({queryKey:B.audioPreview(e,r),queryFn:async()=>F(await i.client.projects[`:projectId`][`audio-preview`].$get({param:{projectId:e}})),refetchInterval:1e3,staleTime:0,gcTime:0,retry:!1}),o=(a.data?.revisionId??null)===r?a.data?.previews??[]:[];return(0,h.jsxs)(`section`,{"aria-label":`Live narration`,className:`grid gap-3 border-y border-line py-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[(0,h.jsx)(`span`,{className:`text-small font-semibold text-ink`,children:`Listen while it generates`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Play any part. Each preview starts from its beginning.`})]}),a.error===null?null:(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Live preview is temporarily unavailable. Finished audio will still appear here.`}),o.length===0&&a.error===null?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`Waiting for the first audio bytes…`}):null,(0,h.jsx)(`div`,{className:`grid max-h-[420px] gap-3 overflow-y-auto`,children:o.map(t=>(0,h.jsx)(T_e,{preview:t,url:`${i.origin}/api/projects/${encodeURIComponent(e)}/audio-preview/${t.id}`},t.id))})]})}function T_e({preview:e,url:t}){let[n,r]=(0,m.useState)(!1),i=(e.state===`streaming`||e.state===`ready`)&&e.bytes>0,a=e.state===`ready`?`Ready`:e.state===`streaming`?`Generating`:`Preview stopped`;return(0,h.jsxs)(`div`,{className:`grid gap-2 text-small`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:e.label}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:a})]}),i&&!n?(0,h.jsx)(E_e,{label:e.label,url:t,onError:()=>r(!0)}):(0,h.jsx)(`p`,{className:`text-ink-2`,children:e.state===`streaming`&&!n?`Waiting for audio…`:`This preview has stopped. The finished narration will be available when generation completes.`})]})}function E_e({label:e,url:t,onError:n}){let r=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=r.current;return()=>{e!==null&&(e.pause(),e.removeAttribute(`src`),e.load())}},[]),(0,h.jsx)(K8,{ref:r,compact:!0,preload:`none`,label:`Live ${e} narration`,src:t,onError:n,className:`max-w-[620px]`})}function D_e({outputs:e}){let t=(0,m.useId)(),n=t=>e.find(e=>e.role===`narration_txt`&&e.meta.segment===t),r=M8(n(`intro`)).data,i=M8(n(`body`)).data,a=M8(n(`outro`)).data,[o,s]=(0,m.useState)(),c=(0,m.useCallback)((e,t)=>{if(!navigator.clipboard){s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>s({text:`Copied the ${t} as Markdown.`,tone:`success`}),()=>s({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},[]),l=[[`Intro`,r],[`Body`,i],[`Outro`,a]].filter(([,e])=>e!==void 0&&e.trim()!==``);if(!e.some(e=>e.role===`narration_txt`))return null;let u=l.length===1?(l[0]?.[1]??``).trim():l.map(([e,t])=>`## ${e}\n\n${(t??``).trim()}`).join(`
289
289
 
290
- `);return(0,h.jsxs)(`section`,{"aria-labelledby":`${t}-title`,className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`h3`,{id:`${t}-title`,className:`sl-kicker text-ink-3`,children:`Narration text`}),(0,h.jsx)(CB,{markdown:u,label:`Narration text`,regionLabel:`Narration text`,anchorPrefix:`narration-`,what:`narration text`,onCopy:c,children:(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}),(0,h.jsx)(Q1,{tone:o?.tone??`info`,children:o?.text})]})}var J8=(0,m.createContext)(!1),Y8=(0,m.createContext)(void 0),X8=(0,m.createContext)(void 0);function Z8(e){let t=y8();return e===void 0?!1:t?.outputs.some(t=>t.output.id===e.id&&t.state===`outdated`)??!1}function Q8(e,t,n){let[r,i]=(0,m.useState)(),a=(0,m.use)(J8),o=(0,m.use)(Y8),s=(0,m.use)(X8),c=y8(),l=e===void 0?void 0:c?.outputs.find(t=>t.output.id===e.id)?.workKey,u=a&&l!==void 0;return{act:t=>{if(e===void 0)return;if(!u||l===void 0||t===`regenerate-image`){i(t);return}if(!l.startsWith(`image:`))return;let n=l.slice(6);o?.({section:`images`,change:e=>({...e,content:{...e.content,imageOrder:e.content.imageOrder.filter(e=>e!==n),imageDefinitions:Object.fromEntries(Object.entries(e.content.imageDefinitions).filter(([e])=>e!==n))},regenerate:(e.regenerate??[]).filter(e=>e!==l)})})},asking:r,confirm:()=>{let n=r;i(void 0),n!==void 0&&e!==void 0&&(u&&l!==void 0&&n===`regenerate-image`?s?.([l]):t.run({kind:n,outputId:e.id}))},dismiss:()=>i(void 0),unavailable:e===void 0||n||t.pending||u&&(o===void 0||s===void 0),viaEdit:u,now:u,ready:!a||c!==void 0}}function D_e(e,t){let[n,r]=(0,m.useState)(!1),i=(0,m.use)(J8),a=(0,m.use)(X8),o=y8();if(!i||o===void 0)return;let s=new Set(e.map(e=>e.id)),c=o.outputs.flatMap(e=>s.has(e.output.id)&&e.workKey.startsWith(`image:`)?[e.workKey]:[]);if(c.length!==0)return{count:c.length,asking:n,act:()=>r(!0),confirm:()=>{r(!1),a?.(c)},dismiss:()=>r(!1),unavailable:t||a===void 0}}var O_e=200,k_e=q({seconds:G(),peaks:K(G())});function A_e(e){if(e===void 0)return;let t;try{t=new URL(e,window.location.href)}catch{return}if(t.pathname.startsWith(`/files/`))return t.searchParams.set(`waveform`,String(O_e)),t.toString()}function j_e(e){let{api:t}=z(),n=A_e(e);return N({queryKey:[`waveform`,n],enabled:n!==void 0,staleTime:1/0,retry:!1,queryFn:async()=>{if(n===void 0)return[];let e=await t.fetch(n);if(!e.ok)throw po(e,void 0);let{peaks:r}=So(k_e,await e.json()),i=Math.max(0,...r);return i===0?[]:r.map(e=>e/i)}}).data}function $8(e){return(0,h.jsx)(K8,{...e,waveform:j_e(e.src)})}var e5=[{role:`audio_intro`,segment:`intro`,name:`Intro`},{role:`audio_body`,segment:`body`,name:`Body`},{role:`audio_outro`,segment:`outro`,name:`Outro`}];function M_e({stage:e,project:t,outputs:n,busy:r}){let{api:i}=z(),a=N(tb(i)),o=F8(t.id),s=f8(n,e),c=s.filter(e=>e.role===`audio_levelled`),l=e5.flatMap(e=>{let t=p8(s,e.role),n=c.find(t=>t.meta.segment===e.segment)??t;return n===void 0?[]:[{...e,output:n,...t===void 0||t===n?{}:{plain:t}}]}),u=e5.flatMap(e=>{let t=c.find(t=>t.meta.segment===e.segment)?.meta.loudness;return t===void 0?[]:[{name:e.name,report:t}]}),d=l.find(e=>e.output.meta.voice!==void 0)?.output.meta,f=l.length>0?d?.voice:t.config.audio?.voice,p=l.length>0?d?.provider:t.config.audio?.provider,m=a.data?.voices.find(e=>e.voiceId===f&&e.provider===p)?.name??f;return(0,h.jsxs)(w8,{children:[e.state===`running`?(0,h.jsx)(q8,{projectId:t.id}):null,l.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No narration has landed yet.`}):l.map(e=>(0,h.jsx)(N_e,{name:e.name,output:e.output,...e.plain===void 0?{}:{plain:e.plain}},e.role)),(0,h.jsx)(A8,{files:h_e(s,l,n.find(e=>e.role===`script_md`))}),u.length===0?null:(0,h.jsx)(j8,{children:u.map(({name:e,report:t})=>u.length===1?mk(t):`${e}: ${mk(t)}`).join(` `)}),(0,h.jsxs)(W8,{label:`How it was recorded`,children:[m===void 0?null:(0,h.jsx)(G8,{label:`Voice`,children:m}),(0,h.jsx)(G8,{label:`Chunking`,children:P_e(F_e(t.config.chunking))}),__e(s)?(0,h.jsx)(G8,{label:`Text files`,children:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Clean narration is the spoken text used for captions. The TTS script adds delivery cues, with a blank line between requests. Uploaded audio has no TTS request.`})}):null]}),(0,h.jsx)(B8,{review:I8(o,{itemKey:`narration`}),projectId:t.id,busy:r}),(0,h.jsx)(E_e,{outputs:s})]})}function N_e({name:e,output:t,plain:n}){let r=b8(t),i=Z8(t),a=Z8(n)||n===void 0?void 0:n,o=b8(i?a:void 0);return(0,h.jsxs)(`div`,{className:`grid grid-cols-[64px_minmax(0,1fr)] items-center gap-3 text-small`,children:[(0,h.jsx)(T8,{children:e}),(0,h.jsx)($8,{label:`${e} narration`,src:r?.url,className:`max-w-[640px]`}),i?(0,h.jsx)(`p`,{className:`col-start-2 m-0 text-small text-ink-2`,children:a===void 0?`Outdated: this is the narration from before your last change. The new one is made when the run carries on: press Continue the run, or Remake at the top of the page.`:`Outdated: this is the levelled narration from before your last change. The new narration is below as it was spoken; it is levelled when the run carries on: press Continue the run, or Remake at the top of the page.`}):null,i&&a!==void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(T8,{children:`New`}),(0,h.jsx)($8,{label:`${e} narration, new, before levelling`,src:o?.url,className:`max-w-[640px]`})]}):null]})}function P_e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function F_e(e){return e===void 0||e.mode===`whole`?`the whole text as one request`:e.mode===`paragraph`?`one request per paragraph`:e.mode===`characters`?`every ${String(e.characters??3e3)} characters`:`every ${String(e.words??500)} words`}function I_e({stage:e,project:t,outputs:n}){let r=p8(f8(n,e),`document_pdf`),i=b8(r),a=XS(t.config.document);return(0,h.jsxs)(w8,{children:[r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The PDF will be saved when rendering finishes.`:`No PDF has been saved yet.`}):(0,h.jsx)(A8,{files:[{output:r,label:`PDF`}],label:`Download PDF`,children:i?.folder?(0,h.jsxs)(mS,{href:`${i.url}?inline=1`,target:`_blank`,rel:`noopener`,variant:`secondary`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open PDF`]}):null}),(0,h.jsx)(W8,{label:`PDF details`,children:(0,h.jsx)(G8,{label:`Theme`,children:a})})]})}var L_e={research:`Generates fresh research and affected article, narration, entries, thumbnail and exports; previous outputs stay in History.`,article:`Generates a fresh article and affected narration, entries, thumbnail and exports; previous outputs stay in History.`,audio:`Regenerates narration and affected exports, keeping compatible cue preparation; previous outputs stay in History.`,images:`Regenerates generated images and affected video, keeping supplied images and narration; previous outputs stay in History.`,thumbnail:`Regenerates the thumbnail without changing the main video; previous outputs stay in History.`,video:`Rebuilds local exports from saved media without regenerating narration or images; previous outputs stay in History.`,document:`Renders the PDF again from the saved article and title without regenerating anything else; previous outputs stay in History.`};function t5(e){switch(e.kind){case`cancel`:return{title:`Cancel this run?`,consequence:`Stops every running stage; finished outputs are kept.`,verb:`Cancel run`,dismiss:`Keep running`};case`rerun`:return{title:`Re-run this stage?`,consequence:L_e[e.stage],verb:`Re-run`,dismiss:`Cancel`};case`delete-image`:return{title:`Delete this image?`,consequence:`Removes the image and re-renders video when enabled.`,verb:`Delete`,dismiss:`Cancel`};case`regenerate-image`:return{title:`Regenerate this image?`,consequence:e.now?`Makes a new image now, one paid image call. The video keeps the current one until you remake it; the old image stays in History.`:`Replaces the image with a new one and re-renders video when enabled.`,verb:`Regenerate`,dismiss:`Cancel`};case`save-article`:return{title:`Save the edited article?`,consequence:`Replaces the article, then updates the enabled narration and final export.`,verb:`Save & update outputs`,dismiss:`Cancel`};case`discard-article`:return{title:`Discard these edits?`,consequence:`The article goes back to the text on disk.`,verb:`Discard`,dismiss:`Keep editing`}}}function R_e(e,t){let{config:n,content:r,fingerprints:i}=e.revision;switch(t){case`research`:return n.sources.research===`generate`;case`article`:return n.sources.article===`generate`&&!r.articleEdited;case`audio`:return n.sources.audio===`generate`&&Object.keys(i).some(e=>!/^audio:(body:.+|intro|outro):[0-9]+$/.test(e)&&!/^audio:(body|intro|outro):future$/.test(e)?!1:!Object.entries(r.narrationOverrides).some(([t,n])=>n.kind===`asset`&&(e===t||e.startsWith(`${t}:`))));case`images`:return n.sources.images!==`off`&&r.imageOrder.some(e=>r.imageDefinitions[e]?.source===`generate`);case`thumbnail`:return n.sources.thumbnail===`from_prompt`||n.sources.thumbnail===`prompt_by_llm`;case`video`:return n.sources.video!==`off`||n.sources.audio!==`off`;case`document`:return RS(n.sources,`document`)===`generate`}}function n5(e){switch(e){case`research`:case`article`:return`article`;case`audio`:return`narration`;case`images`:case`thumbnail`:return`images`;case`video`:return`video`;case`document`:return`document`}}var r5={research:`Research`,article:`Article`,audio:`Narration`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`PDF`},i5=e=>/^[A-Z]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1);function z_e(e){let{project:t,stages:n}=e,r=t.config,i=e=>e===`video`&&rF(r)===`audio`?`Audio export`:r5[e];if(e.sample)return{situation:`sample`,tone:`info`,status:`Sample project`,title:`This is the sample project, finished and free to explore.`,why:`It is read-only. Your own copy can be edited and made again.`,action:{label:`Make my own copy`,intent:{kind:`copy-sample`}}};if(t.status===`paused`){let t=W_e(e.outdated);return{situation:`paused`,tone:`waiting`,status:`Paused`,title:`The run is paused.`,why:t===void 0?`Everything made so far is kept. Continuing picks up where it stopped.`:`Everything made so far is kept. Still to make: ${t}. They stay outdated until you continue.`,action:{label:`Continue the run`,intent:{kind:`resume`}}}}let a=n.find(e=>e.state===`failed`&&e.retryAt===void 0);if(a!==void 0){let t=i(a.kind),n=e.fixOf(a),r={label:`Try ${i5(a5(t))} again`,intent:{kind:`retry`,stage:a.kind}},o={situation:`failed`,tone:`failed`,status:`Failed`,section:n5(a.kind),...a.failureReason===null?{}:{detail:a.failureReason}};switch(n?.kind){case`sign-in`:return{...o,title:`${n.label.replace(/^Sign in to /,``)} is signed out, so ${i5(a5(t))} stopped.`,why:`Copy the sign-in command (${n.command}), run it in a terminal on the computer running Slopify and sign in, then press Check again. Once ${n.label.replace(/^Sign in to /,``)} is signed in, Slopify tries ${i5(a5(t))} again.`,action:{label:`Copy sign-in command`,intent:{kind:`sign-in`,stage:a.kind,fix:n}}};case`refused`:return{...o,title:`A content filter refused a prompt, so ${i5(a5(t))} stopped.`,why:n.soften?`Softening rewrites each refused prompt without what the filter flagged, then draws it again.`:`Change the prompt in the project settings, then try again.`,action:n.soften?{label:n.label,intent:{kind:`soften`,stage:a.kind}}:{label:`Edit the prompt`,intent:{kind:`edit`}}};case`switch-model`:return{...o,title:`The model for ${i5(a5(t))} is no longer offered.`,why:`Pick another model in the project settings, then try again.`,action:{label:`Switch model`,intent:{kind:`edit`}}};case`provider-settings`:return{...o,title:`The provider did not accept its key, so ${i5(a5(t))} stopped.`,why:`Check the key in Settings, then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`providers`}}};case`free-space`:return{...o,title:`The disk is full, so ${i5(a5(t))} stopped.`,why:`Storage in Settings shows what can go. Then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`storage`}}};case void 0:return{...o,title:`${t} stopped with an error.`,why:`Trying again keeps everything already made.`,action:r}}}let o=e.held[0];if(o!==void 0){let e=i(o.stage);return{situation:`held`,tone:`waiting`,status:`Waiting for you`,title:`The ${i5(e)} ${H_e(e)} ready for your review.`,why:o.dependents.length===0?`Approving marks it reviewed.`:`Approving lets ${o5(o.dependents.map(e=>i5(a5(i(e)))))} run. Nothing after it runs until you do.`,action:{label:B_e(o,i),intent:{kind:`approve`,gate:o}},section:n5(o.stage)}}let s=n.find(e=>e.state===`failed`&&e.retryAt!==void 0),c=e.waits[0];if(c!==void 0||s!==void 0){if(c!==void 0){let t=XH(e.waits);return{situation:`waiting`,tone:`waiting`,status:`Waiting for limits`,title:`${YH(e.waits,e.clock)??``}.`,why:`Nothing to do: the run carries on by itself when they reset, and work that does not need ${t} keeps going.`,section:n5(c.stage)}}if(s!==void 0)return{situation:`waiting`,tone:`waiting`,status:`Waiting to try again`,title:`${i(s.kind)} will try again by itself at ${e.clock(s.retryAt??``)}.`,why:`Nothing to do: the run carries on when it does.`,section:n5(s.kind),...s.failureReason===null?{}:{detail:s.failureReason}}}let l=n.find(e=>e.state===`running`);if(t.status===`running`||l!==void 0)return{situation:`running`,tone:`running`,status:`Running`,title:l===void 0?`The run is starting.`:`Making the ${i5(i(l.kind))}${V_e(l)}.`,why:`Pausing lets the current call finish and keeps everything made so far.`,action:{label:`Pause`,intent:{kind:`pause`}},...l===void 0?{}:{section:n5(l.kind)}};if(e.resumable||t.status===`canceled`||t.status===`failed`&&a===void 0)return{situation:`stopped`,tone:`off`,status:t.status===`canceled`?`Canceled`:`Stopped`,title:`The run stopped before it finished.`,why:`Continuing makes only what is missing; everything made so far is kept.`,action:{label:`Continue the run`,intent:{kind:`resume`}}};if(t.status===`pending`)return{situation:`queued`,tone:`off`,status:`Queued`,title:`Waiting for its turn.`,why:`It starts by itself when the videos ahead of it are done.`};let u=U_e(e.outdated);if(u!==void 0)return{situation:`outdated`,tone:`info`,status:`Outdated`,title:u.count===1||u.singular?`The ${u.noun} ${u.noun.endsWith(`s`)?`are`:`is`} outdated after your edit.`:`${String(u.count)} ${u.plural} are outdated after your edit.`,why:`They keep their current version until you remake them. Nothing else is made again.`,action:{label:u.count===1||u.singular?`Remake the outdated ${u.noun}`:`Remake ${String(u.count)} outdated ${u.plural}`,intent:{kind:`remake`,workKeys:u.workKeys}},section:u.section};if(t.status===`done`&&r.mode===`short`)return{situation:`done`,tone:`done`,status:`Done`,title:`The short is ready.`,why:`Play opens set up for a long video on the same topic, with the same starter pack and providers. Nothing starts until you press Play.`,action:{label:`Make the full video on this topic`,intent:{kind:`full-video`}}};if((t.status===`done`||t.status===`partial`)&&e.uploadReady)return{situation:`done`,tone:`done`,status:`Done`,title:`The video is ready.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}}function B_e(e,t){if(e.dependents.includes(`video`))return`Approve and render the video`;if(e.dependents.includes(`images`))return`Approve and make the images`;if(e.dependents.includes(`audio`))return`Approve and record the narration`;let n=e.dependents[0];return n===void 0?`Approve the ${i5(t(e.stage))}`:`Approve and make the ${i5(t(n))}`}function V_e(e){let t=lF(e);return t===void 0?e.progressTotal===null||e.progressTotal<=0?``:` · ${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)}`:` · ${t}`}function a5(e){return/s$/i.test(e)?e:`the ${i5(e)}`}function H_e(e){return/s$/i.test(e)?`are`:`is`}function o5(e){return e.length<=1?e[0]??``:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`}var s5=[{id:`article`,noun:`article`,plural:`article files`,singular:!0,section:`article`,roles:[`notes`,`sources`,`article_md`,`article_txt`,`script_md`],counted:[`article_md`]},{id:`narration`,noun:`narration`,plural:`narration parts`,singular:!0,section:`narration`,roles:[`narration_txt`,`tts_script`,`glossary`,`audio_body`,`audio_intro`,`audio_outro`,`audio_levelled`],counted:[`audio_body`]},{id:`reference`,noun:`establishing image`,plural:`establishing images`,singular:!0,section:`images`,roles:[`reference`],counted:[`reference`]},{id:`images`,noun:`image`,plural:`images`,singular:!1,section:`images`,roles:[`image`],counted:[`image`]},{id:`animated`,noun:`animated image`,plural:`animated images`,singular:!1,section:`images`,roles:[`animated_image`],counted:[`animated_image`]},{id:`thumbnails`,noun:`thumbnail`,plural:`thumbnails`,singular:!1,section:`images`,roles:[`thumbnail`],counted:[`thumbnail`]},{id:`video`,noun:`video`,plural:`video files`,singular:!0,section:`video`,roles:[`video`,`audio_export`,`audio_mp3`,`audio_m4b`,`render_params`,`subtitles_srt`,`subtitles_vtt`,`subtitle_words`,`subtitle_ass`,`subtitle_font`],counted:[`video`,`audio_export`]},{id:`shorts`,noun:`short`,plural:`shorts`,singular:!1,section:`shorts`,roles:[`shorts`,`short_image`,`short_video`],counted:[`short_video`]},{id:`youtube`,noun:`YouTube description`,plural:`YouTube descriptions`,singular:!0,section:`youtube`,roles:[`youtube_description`,`youtube_tags`,`youtube_pinned_comment`,`youtube_titles`],counted:[`youtube_description`]},{id:`document`,noun:`PDF`,plural:`PDFs`,singular:!0,section:`document`,roles:[`document_pdf`],counted:[`document_pdf`]}];function U_e(e){for(let t of s5){let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)continue;let r=n.filter(e=>t.counted.includes(e.role)).length;return{noun:t.noun,plural:t.plural,singular:t.singular,count:Math.max(1,r),workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section}}}function W_e(e){let t=s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[t.singular?`the ${t.noun}`:r===1?`1 ${t.noun}`:`${String(r)} ${t.plural}`]});return t.length===0?void 0:o5(t)}function G_e(e){return s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[{label:r===1||t.singular?`Remake the outdated ${t.noun}`:`Remake ${String(r)} outdated ${t.plural}`,workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section,count:r}]})}function K_e({tone:e,status:t,title:n,why:r,action:i,className:a}){return(0,h.jsxs)(`section`,{"aria-label":`Next action`,className:L(`sl-next`,a),children:[(0,h.jsx)(_S,{tone:e,children:t}),(0,h.jsx)(`p`,{className:`sl-next__title`,children:n}),r===void 0?null:(0,h.jsx)(`p`,{className:`sl-next__why`,children:r}),i===void 0?null:(0,h.jsx)(`div`,{className:`flex flex-col [&>*]:w-full`,children:i})]})}function q_e({project:e,stages:t,resumable:n,sample:r,gates:i,outdated:a,waits:o,uploadReady:s,actions:c,controller:l,openSection:u,openUpload:d}){let{api:f}=z(),p=_(),h=Zi(),[g,v]=(0,m.useState)(),y=(0,m.useRef)(new Map),b=z_e({project:e,stages:t,resumable:n,sample:r,held:i.filter(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint).map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),outdated:a,waits:o,uploadReady:s,fixOf:t=>_3(t,e),clock:fF}),x=P({mutationFn:()=>Wy(f,e.id),onSuccess:async({projectId:e})=>{await p.invalidateQueries({queryKey:B.projects}),await h({to:`/projects/$projectId`,params:{projectId:e}})},onError:e=>v(`${bo(e.message)} The copy was not made. Press Make my own copy to try again.`)}),S=(0,m.useRef)(null),C=nP(),w=P({mutationFn:async()=>{if(C===null)throw Error(`Play isn't available on this page. Reload the page`);if(C.review.starting||C.review.uncertain||C.review.created!==null)throw Error(`Play is starting a run from its open draft. Wait for it to start`);if(!await C.flush())throw Error(`The draft open in Play couldn't be saved. Open Play, save or discard it`);S.current??=crypto.randomUUID();let{draft:t}=await By(f,{projectId:e.id,draftId:S.current});if(await p.invalidateQueries({queryKey:[`play-drafts`]}),!await C.open(t.id))throw Error(`The full video's draft was made but didn't open. Open Play and pick it`);S.current=null,await h({to:`/play`})},onError:e=>v(`${bo(e.message)} Then press Make the full video on this topic again.`)}),T=P({mutationFn:async t=>{let n=i.find(e=>e.checkpointId===t.checkpointId);if(n===void 0)throw Error(`The review changed before it was approved. Reload the page.`);let r=`${n.checkpointId}:${n.fingerprint}`,a=y.current.get(r)??crypto.randomUUID();y.current.set(r,a);let o=await h3(f,e.id,n.checkpointId,{revisionId:n.revisionId,fingerprint:n.fingerprint,idempotencyKey:a});if(y.current.delete(r),!o.ok)throw Error(o.message)},onSettled:async()=>{await p.invalidateQueries({queryKey:d3(e.id)}),await p.invalidateQueries({queryKey:B.project(e.id)}),p.invalidateQueries({queryKey:B.projects})},onError:e=>v(`${bo(e.message)} Press the approve button again to check whether it went through.`)});return{next:b,run:e=>{switch(v(void 0),e.kind){case`copy-sample`:x.mutate();return;case`resume`:case`pause`:c.run({kind:e.kind});return;case`retry`:case`soften`:c.run({kind:e.kind,stage:e.stage});return;case`sign-in`:q1(e.fix.command).then(t=>v(t?`Copied ${e.fix.command}. Run it in a terminal on the computer running Slopify, sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.fix.command} in a terminal, sign in, then press Check again.`));return;case`approve`:T.mutate(e.gate);return;case`remake`:l.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0});return;case`edit`:u(`settings`);return;case`open-settings`:h({to:`/settings`,search:{section:e.section}});return;case`prepare-upload`:d();return;case`full-video`:w.mutate();return}},pending:x.isPending||w.isPending||T.isPending||c.pending||l.pending,message:g}}function J_e(e){switch(e.kind){case`copy-sample`:return`Copying…`;case`resume`:return`Continuing…`;case`pause`:return`Pausing…`;case`approve`:return`Approving…`;case`remake`:return`Starting the remake…`;case`retry`:return`Trying again…`;case`soften`:return`Softening…`;case`full-video`:return`Opening Play…`;default:return}}function c5({state:e,variant:t,className:n}){let[r,i]=(0,m.useState)(!1),a=e.next?.action;if(a===void 0)return null;let o=a.intent;if(o.kind===`sign-in`)return(0,h.jsx)(J1,{fix:o.fix,variant:t,retry:{run:()=>e.run({kind:`retry`,stage:o.stage}),busy:e.pending}});if(o.kind===`open-settings`)return(0,h.jsx)(fS,{to:`/settings`,search:{section:o.section},variant:t,...n===void 0?{}:{className:n},children:a.label});let s=e.pending?J_e(o)??a.label:a.label;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:t,className:n,disabled:e.pending,disabledReason:`Working on the last press`,"aria-keyshortcuts":t===`primary`?Mx(lP.nextAction):void 0,onClick:()=>o.kind===`soften`?i(!0):e.run(o),children:s}),o.kind===`soften`?(0,h.jsx)(jy,{open:r,tone:`primary`,title:`Soften the refused prompt and try again?`,consequence:`Your project's AI model rewrites each refused prompt without what a content filter could flag, keeping the scene and style. The image is then drawn again from the new wording, which it keeps as its prompt. The AI call and the new image are charged like any other.`,confirmLabel:`Soften and retry`,cancelLabel:`Keep the prompt`,pending:e.pending,onConfirm:()=>{i(!1),e.run(o)},onCancel:()=>i(!1)}):null]})}function Y_e({state:e,feedback:t}){let n=e.next;return n===void 0&&t===void 0&&e.message===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n===void 0?null:(0,h.jsx)(K_e,{tone:n.tone,status:n.status,title:n.title,...n.why===void 0?{}:{why:n.why},...n.action===void 0?{}:{action:(0,h.jsx)(c5,{state:e,variant:`primary`})}}),e.message===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e.message}),t]})}var X_e={sample:void 0,paused:void 0,stopped:void 0,queued:void 0,running:void 0,failed:`danger`,held:`waiting`,waiting:`waiting`,outdated:`info`,done:void 0};function Z_e({state:e,section:t}){let n=e.next;if(n===void 0||n.section!==t)return null;let r=X_e[n.situation];return r===void 0?null:(0,h.jsx)(SI,{className:`max-[1180px]:hidden`,tone:r,title:n.title,...n.action===void 0?{}:{actions:(0,h.jsx)(c5,{state:e,variant:`secondary`})},children:n.why===void 0&&n.detail===void 0?void 0:(0,h.jsxs)(h.Fragment,{children:[n.why===void 0?null:(0,h.jsx)(`span`,{className:`block`,children:n.why}),n.detail===void 0?null:(0,h.jsxs)(`details`,{className:`mt-1`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:n.detail})]})]})})}var Q_e={research:`Research again`,article:`Write the article again`,audio:`Record the narration again`,images:`Make all images again`,thumbnail:`Make the thumbnails again`,video:`Render the video again`,document:`Render the PDF again`};function l5(e,t){return e===`video`&&t.config.sources.video===`off`?`Export the audio again`:Q_e[e]}function u5({id:e,title:t,kicker:n,stages:r,project:i,outputs:a,actions:o,next:s,active:c,meta:l,head:u=!0,extra:d,resumable:f=!1,children:p}){let m=r[0],g=r.some(e=>o.refusal?.stage===e.kind)?o.refusal?.message:void 0,_=r.filter(t=>t.state===`failed`&&t.retryAt===void 0&&(s.next?.situation!==`failed`||s.next.section!==e)),v=r.find(e=>e.state===`running`),y=v===void 0?void 0:dF(v),b=l??(m===void 0?void 0:r.filter(e=>e.state!==`skipped`).map(e=>e===m?cF(e,a,i,f):`${r5[e.kind]}: ${cF(e,a,i,f)}`).join(` · `));return(0,h.jsxs)(`section`,{hidden:!c,"aria-label":t,"data-tour":m===void 0?void 0:`project-${m.kind}`,className:`flex min-w-0 flex-col gap-5`,children:[u?(0,h.jsxs)(H,{row:!0,title:t,...n===void 0?{}:{kicker:n},...b===void 0||b===``?{}:{meta:b},children:[d,(0,h.jsx)(f5,{stages:r,project:i,actions:o})]}):null,y===void 0||v===void 0?null:(0,h.jsx)(q2,{value:y,label:`${r5[v.kind]} progress`,valueText:cF(v,a,i,f)}),(0,h.jsx)(Z_e,{state:s,section:e}),_.map(e=>(0,h.jsx)(SI,{tone:`danger`,title:`${r5[e.kind]} stopped with an error.`,children:e.failureReason===null?void 0:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.failureReason})]})},e.id)),g===void 0?null:(0,h.jsx)(SI,{tone:`danger`,title:g,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:o.dismissRefusal,children:`Dismiss`})}),m?.state===`running`&&m.kind!==`article`&&m.kind!==`images`&&m.kind!==`video`&&m.kind!==`document`?(0,h.jsx)(j3,{projectId:i.id,stage:m.kind}):null,p]})}function d5({stage:e,project:t,name:n}){return e===void 0||e.state===`skipped`?(0,h.jsx)(a0,{title:`${n} is off for this run.`,children:`Switch it on in the project settings to make it.`}):(0,h.jsx)(a0,{title:`No ${n.toLowerCase()} yet.`,children:t.status===`paused`?`It is made once you continue the run.`:`It starts when the steps before it are done. Finished work elsewhere can be looked at meanwhile.`})}function f5({stages:e,project:t,actions:n}){let r=(0,m.useContext)(J8),i=y8(),[a,o]=(0,m.useState)(),s=e.filter(e=>e.state!==`skipped`&&e.state!==`pending`&&(!r||i!==void 0&&R_e(i,e.kind)));if(s.length===0)return null;let c=n.pending||t.status===`running`||e.some(e=>e.state===`running`),l=a===void 0?void 0:t5({kind:`rerun`,stage:a});return(0,h.jsxs)(h.Fragment,{children:[s.map(e=>(0,h.jsxs)(R,{size:`small`,disabled:c,disabledReason:`Wait until the work on this project is done`,onClick:()=>o(e.kind),children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),l5(e.kind,t)]},e.id)),(0,h.jsx)(jy,{open:a!==void 0,title:a===void 0?``:`${l5(a,t)}?`,consequence:l?.consequence??``,confirmLabel:a===void 0?``:l5(a,t),cancelLabel:`Keep what is there`,pending:n.pending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&n.run({kind:`rerun`,stage:e})},onCancel:()=>o(void 0)})]})}function $_e({stage:e,project:t,outputs:n,actions:r,busy:i}){let a=f8(n,e),o=F8(t.id),s=VS(t.config),c=Array.from({length:s},(e,t)=>t+1).map(e=>({variant:e,output:a.find(t=>t.role===`thumbnail`&&(t.meta.index??1)===e)})),l=c.flatMap(e=>e.output===void 0?[]:[e.output]),u=x8(l),[d,f]=(0,m.useState)(null),p=l.filter(e=>u.has(e.id)),g=p.map(e=>({src:u.get(e.id)?.url??``,alt:`Thumbnail ${String(e.meta.index??1)}`})),_=t.format===`9:16`,v=({variant:n,output:a})=>(0,h.jsx)(eve,{variant:n,count:s,output:a,review:I8(o,{outputId:a?.id}),stage:e,project:t,actions:r,busy:i,onOpen:()=>f(a===void 0?null:tve(p,a))},n);return(0,h.jsxs)(`section`,{"aria-label":s===1?`Thumbnail`:`Thumbnails`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:s===1?`Thumbnail`:`Thumbnails`,meta:s===1?`The picture YouTube shows before the video plays`:`${String(s)} variants for YouTube's Test & compare`,children:[(0,h.jsx)(O8,{variant:`secondary`,files:l.map(e=>({output:e,label:s===1?`Thumbnail`:`Thumbnail ${String(e.meta.index??1)}`}))}),(0,h.jsx)(k8,{output:l[0]}),(0,h.jsx)(f5,{stages:[e],project:t,actions:r})]}),c.length===1?(0,h.jsx)(`div`,{className:_?`max-w-[280px]`:`max-w-[480px]`,children:c.map(v)}):(0,h.jsx)(B0,{list:!0,label:`Thumbnail variants`,children:c.map(e=>(0,h.jsx)(`li`,{className:`min-w-0`,children:v(e)},e.variant))}),(0,h.jsx)(V0,{items:g,index:d,onIndex:f,onClose:()=>f(null),actions:(e,t)=>{let n=p[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:s===1?`the thumbnail`:`thumbnail ${String(n.meta.index??1)}`,actions:r,busy:i},n.id)}})]})}function eve({variant:e,count:t,output:n,review:r,stage:i,project:a,actions:o,busy:s,onOpen:c}){let l=b8(n),u=Q8(n,o,s),d=t===1?`the thumbnail`:`thumbnail ${String(e)}`;bx({id:`project.thumbnail.${String(e)}`,title:t===1?`Regenerate the thumbnail`:`Regenerate thumbnail ${String(e)}`,group:`This project`,context:a.title,keywords:[`thumbnail`,`redraw`,`remake`],run:()=>u.act(`regenerate-image`)});let f=r!==void 0&&!r.passed&&r.action===null,p=String.fromCharCode(64+e),m=u.asking===void 0||n===void 0?void 0:t5({kind:u.asking,outputId:n.id,now:u.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:t===1?`Thumbnail for ${a.title}`:`Thumbnail ${String(e)} for ${a.title}`,aspect:p5(a.format),...l===void 0?{}:{src:l.url},...n===void 0&&i.state===`running`?{generating:`Making the thumbnail`}:{},title:t===1?`Thumbnail`:p,...n===void 0?{meta:nve(i)}:{},onOpen:c,openLabel:`Open ${d} full size`,...r===void 0?{}:{badge:(0,h.jsx)(V8,{review:r})},actionsShown:f,...n===void 0?{}:{actions:(0,h.jsxs)(h.Fragment,{children:[f&&r!==void 0?(0,h.jsx)(z8,{review:r,projectId:a.id,busy:s}):null,(0,h.jsxs)(R,{size:`small`,disabled:u.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>u.act(`regenerate-image`),"aria-label":`Regenerate ${d}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),l===void 0?null:(0,h.jsx)(v5,{href:l.url,label:`Download ${d}`})]})}}),(0,h.jsx)(jy,{open:u.asking!==void 0,tone:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:`Regenerate the thumbnail`,cancelLabel:`Keep it`,pending:o.pending,onConfirm:u.confirm,onCancel:u.dismiss})]})}function tve(e,t){let n=e.indexOf(t);return n===-1?null:n}function nve(e){switch(e.state){case`running`:return`Being made`;case`failed`:case`canceled`:return`Not made`;default:return`Not made yet`}}function rve(e,t){let n=e.filter(e=>e.role===`image`),r=new Map;for(let e of n){let t=e.meta.promptName??`Images`;r.set(t,[...r.get(t)??[],e])}let i=t.filter(e=>r.has(e)),a=[...r.keys()].filter(e=>!i.includes(e)).sort();return[...i,...a].flatMap(e=>{let t=r.get(e);return t===void 0?[]:[{name:e,images:[...t].sort(ive)}]})}function ive(e,t){return(e.meta.index??0)-(t.meta.index??0)}function ave(e,t,n,r,i){let a=Oy(),[o,s]=(0,m.useState)(),c=(r,i)=>{let o=r===`image`?t:n,c=r===`image`?`image`:`on-screen card`;if(i===void 0){a(`Type the ${c}'s number with the command, for example "regenerate ${c} 3".`);return}let l=o.find(e=>e.meta.index===i);if(l===void 0){let t=o.flatMap(e=>e.meta.index===void 0?[]:[e.meta.index]);a(t.length===0?`${e.title} has no ${c}s yet, so there is no ${c} ${String(i)} to regenerate. They appear under Images once the run makes them.`:`${e.title} has no ${c} ${String(i)}: its ${c}s are numbered ${String(Math.min(...t))} to ${String(Math.max(...t))}. Type one of those, or press Regenerate on the ${c} in Images.`,`error`);return}s(e=>({image:l,name:`${c[0]?.toUpperCase()??``}${c.slice(1)} ${String(i)}`,nonce:(e?.nonce??0)+1}))};return bx({id:`project.image.regenerate`,title:`Regenerate an image`,numbered:e=>`Regenerate image ${String(e)}`,group:`This project`,context:e.title,keywords:[`image`,`picture`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`image`,e)}),bx({id:`project.card.regenerate`,title:`Regenerate an on-screen card`,numbered:e=>`Regenerate on-screen card ${String(e)}`,group:`This project`,context:e.title,keywords:[`card`,`figure`,`table`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`card`,e)}),Yx(Wx.regenerateImage(e.id),e=>c(`image`,e)),o===void 0?null:(0,h.jsx)(ove,{request:o,actions:r,busy:i},o.nonce)}function ove({request:e,actions:t,busy:n}){let r=Oy(),i=Q8(e.image,t,n),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a.current&&i.ready&&(a.current=!0,i.unavailable?r(`${e.name} can't be regenerated while work on this project is running. Wait until it finishes, then run the command again or press Regenerate on it in Images.`,`error`):i.act(`regenerate-image`))},[i,r,e.name]);let o=i.asking===void 0?void 0:t5({kind:i.asking,outputId:e.image.id,now:i.now});return(0,h.jsx)(jy,{open:i.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate the image`,cancelLabel:`Keep it`,pending:t.pending,onConfirm:i.confirm,onCancel:i.dismiss})}function p5(e){return e===`9:16`?`portrait`:`landscape`}function sve({stage:e,companion:t,project:n,outputs:r,actions:i,busy:a}){let o=F8(n.id),s=f8(r,e),c=rve(s,n.config.imagePrompts?.map(e=>e.name)??[]),l=c.flatMap(e=>e.images),u=s.filter(e=>e.role===`figure_card`&&(e.meta.format??n.format)===n.format).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),d=[...l,...u],f=ave(n,l,u,i,a),p=D_e(l,a),g=x8(d),[_,v]=(0,m.useState)(null),y=d.filter(e=>g.has(e.id)),b=y.map(e=>({src:g.get(e.id)?.url??``,alt:e.role===`figure_card`?`On-screen card ${String(e.meta.index??``)}`:e.meta.prompt??`Image ${String(e.meta.index??``)}`,...m5(e)?{kind:`video`}:{},caption:e.role===`figure_card`?`Shown while the narration describes it`:e.meta.prompt??e.meta.promptName??`Slideshow image`})),x=n.config.reference===void 0?null:(0,h.jsx)(cve,{image:p8(s,`reference`),format:n.format,generated:n.config.reference.source===`prompt`,affected:l.length,actions:i,busy:a}),S=t?.kind===`thumbnail`?(0,h.jsx)($_e,{stage:t,project:n,outputs:r,actions:i,busy:a}):null,C=e.state===`running`&&e.progressTotal!==null?Math.max(0,e.progressTotal-l.length):0,w=o.filter(e=>l.some(t=>t.id===e.outputId)),T=w.filter(e=>e.passed&&e.attempt>1).length,E=w.filter(e=>!e.passed&&e.action===null).length,D=[l.length===0?void 0:`${String(l.length)} in the video`,w.length===0?void 0:`reviewed`,T===0?void 0:`${String(T)} redone after review`,E===0?void 0:`${String(E)} flagged`].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(h.Fragment,{children:[f,x,x===null||S===null&&e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),S,S===null||e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),e.state===`skipped`?null:(0,h.jsxs)(`section`,{"aria-label":`Slideshow images`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:`Images`,...D===``?{}:{meta:D},children:[p===void 0?null:(0,h.jsxs)(R,{size:`small`,disabled:p.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:p.act,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate all`]}),p===void 0?null:(0,h.jsx)(jy,{open:p.asking,tone:`primary`,title:`Regenerate all ${String(p.count)} images?`,consequence:`Makes ${String(p.count)} new images now, one paid image call each. The video keeps the current ones until you remake it; the old images stay in History.`,confirmLabel:`Regenerate them`,cancelLabel:`Keep them`,pending:i.pending,onConfirm:p.confirm,onCancel:p.dismiss}),(0,h.jsx)(s_e,{projectId:n.id,asset:`images.zip`,label:`Download all`}),(0,h.jsx)(f5,{stages:[e],project:n,actions:i})]}),c.length===0&&C===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`pending`?`The images are made once the narration is timed.`:`No images have landed yet.`}):null,c.map((e,t)=>(0,h.jsx)(y5,{name:e.name,count:e.images.length,showName:c.length>1,trailing:t===c.length-1&&C>0?Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the next image`:`Waiting its turn`},t)):null,children:t=>e.images.slice(0,t).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:I8(o,{outputId:e.id}),format:n.format,actions:i,busy:a,onOpen:()=>v(g5(y,e))},e.id))},e.name)),u.length===0?null:(0,h.jsx)(y5,{name:`From the article`,count:u.length,showName:!0,children:e=>u.slice(0,e).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:void 0,format:n.format,actions:i,busy:a,card:!0,onOpen:()=>v(g5(y,e))},e.id))}),c.length===0&&C>0?(0,h.jsx)(B0,{label:`Images being made`,children:Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the first image`:`Waiting its turn`},t))}):null,(0,h.jsx)(V0,{items:b,index:_,onIndex:v,onClose:()=>v(null),actions:(e,t)=>{let n=y[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:n.role===`figure_card`?`on-screen card${h5(n)}`:`image${h5(n)}`,actions:i,busy:a},n.id)}})]})]})}var m5=e=>/\.(mp4|mov|m4v|webm|mkv)$/i.test(e.path),h5=e=>e.meta.index===void 0?``:` ${String(e.meta.index)}`;function g5(e,t){let n=e.indexOf(t);return n===-1?null:n}function _5({output:e,name:t,actions:n,busy:r}){let i=b8(e),a=Q8(e,n,r),o=a.asking===void 0?void 0:t5({kind:a.asking,outputId:e.id,now:a.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(R,{size:`small`,disabled:a.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>a.act(`regenerate-image`),"aria-label":`Regenerate ${t}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),i===void 0?null:(0,h.jsx)(v5,{href:i.url,label:`Download ${t}`}),(0,h.jsx)(jy,{open:a.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate it`,cancelLabel:`Keep it`,pending:n.pending,onConfirm:a.confirm,onCancel:a.dismiss})]})}function v5({href:e,label:t,text:n}){return(0,h.jsxs)(mS,{href:e,download:!0,"aria-label":t,title:t,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]})}function cve({image:e,format:t,generated:n,affected:r,actions:i,busy:a}){let o=b8(e),s=Q8(e,i,a),[c,l]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Establishing image`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{kicker:`Reference · not in the video`,title:`Establishing image`,meta:`Every image follows it for the look, palette and style`,children:e!==void 0&&n?(0,h.jsx)(R,{disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.act(`regenerate-image`),children:`Make the establishing image again`}):null}),(0,h.jsx)(z0,{className:`w-full max-w-[360px]`,alt:e?.meta.prompt??`Establishing image`,aspect:p5(t),...o===void 0?{}:{src:o.url},title:`Establishing image`,...e===void 0?{meta:`Not made yet`}:{},onOpen:()=>l(0),openLabel:`Open the establishing image full size`,...e===void 0||o===void 0?{}:{actions:(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`,text:`Download`})}}),n&&r>0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Making it again marks ${String(r)} image${r===1?``:`s`} outdated. They keep their current version until you remake them.`}):null,(0,h.jsx)(V0,{items:o===void 0?[]:[{src:o.url,alt:`Establishing image`,caption:e?.meta.prompt??`The reference every image follows`}],index:c,onIndex:l,onClose:()=>l(null),actions:()=>o===void 0?null:(0,h.jsxs)(h.Fragment,{children:[n?(0,h.jsxs)(R,{size:`small`,disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>{l(null),s.act(`regenerate-image`)},"aria-label":`Make the establishing image again`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}):null,(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`})]})}),(0,h.jsx)(jy,{open:s.asking!==void 0,tone:`primary`,title:`Make the establishing image again?`,consequence:`A new establishing image replaces this one${r>0?`, and the ${String(r)} images drawn from it become outdated until you remake them`:``}. The old one stays in History.`,confirmLabel:`Make it again`,cancelLabel:`Keep this one`,pending:i.pending,onConfirm:s.confirm,onCancel:s.dismiss})]})}function y5({name:e,count:t,showName:n,trailing:r,children:i}){let[a,o]=(0,m.useState)(!1),s=t>12&&!a;return(0,h.jsxs)(`section`,{"aria-label":`${e} × ${String(t)}`,className:`flex flex-col gap-3`,children:[n?(0,h.jsx)(`h3`,{className:`sl-kicker m-0`,children:`${e} × ${String(t)}`}):null,(0,h.jsxs)(B0,{children:[i(s?12:t),r]}),t>12?(0,h.jsx)(R,{variant:`quiet`,"aria-expanded":a,className:`self-start`,onClick:()=>o(e=>!e),children:a?`Show fewer`:`Show all ${String(t)} images`}):null]})}function b5({image:e,projectId:t,review:n,format:r,actions:i,busy:a,card:o=!1,onOpen:s}){let c=b8(e),l=h5(e),u=o?`on-screen card${l}`:`image${l}`,d=Q8(e,i,a),f=Z8(e),p=n!==void 0&&!n.passed&&n.action===null,m=d.asking===void 0?void 0:t5({kind:d.asking,outputId:e.id,now:d.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:o?`On-screen card${l}`:e.meta.prompt??`Slideshow ${u}`,kind:m5(e)?`video`:`image`,aspect:p5(r),...c===void 0?{}:{src:c.url},title:o?`Card${l}`:e.meta.prompt??`Image${l}`,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`},onOpen:s,openLabel:`Open ${u} full size`,...n===void 0&&!f?{}:{badge:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap gap-1`,children:[f?(0,h.jsx)(vS,{tone:`info`,children:`Outdated`}):null,n===void 0?null:(0,h.jsx)(V8,{review:n})]})},actionsShown:p,actions:(0,h.jsxs)(h.Fragment,{children:[p&&n!==void 0?(0,h.jsx)(z8,{review:n,projectId:t,busy:a}):null,(0,h.jsxs)(R,{size:`small`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`regenerate-image`),"aria-label":`Regenerate ${u}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),c===void 0?null:(0,h.jsx)(v5,{href:c.url,label:`Download ${u}`}),o?null:(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`delete-image`),"aria-label":`Delete ${u}`,title:`Delete ${u}`,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})}),(0,h.jsx)(jy,{open:d.asking!==void 0,tone:d.asking===`delete-image`?`destructive`:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:d.asking===`delete-image`?`Delete the image`:`Regenerate the image`,cancelLabel:`Keep it`,pending:i.pending,onConfirm:d.confirm,onCancel:d.dismiss})]})}function x5(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function S5(e){let t=/^(?:(\d+):)?(\d{1,2}):(\d{2})$/.exec(e.trim());if(t===null)return;let n=Number(t[1]??`0`),r=Number(t[2]),i=Number(t[3]);if(!(i>59||t[1]!==void 0&&r>59))return n*3600+r*60+i}function lve(e){let t=e.trim(),n=/^(\S+)\s+(.+)$/u.exec(t);if(n===null)return;let r=S5(n[1]??``),i=(n[2]??``).trim();return r===void 0||i===``?void 0:{start:r,title:i}}function C5(e,t){let n=e.replace(/\r\n?/gu,`
290
+ `);return(0,h.jsxs)(`section`,{"aria-labelledby":`${t}-title`,className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`h3`,{id:`${t}-title`,className:`sl-kicker text-ink-3`,children:`Narration text`}),(0,h.jsx)(CB,{markdown:u,label:`Narration text`,regionLabel:`Narration text`,anchorPrefix:`narration-`,what:`narration text`,onCopy:c,children:(0,h.jsx)(`span`,{className:`block h-4 w-[40ch] max-w-full rounded-control bg-raised`})}),(0,h.jsx)(Q1,{tone:o?.tone??`info`,children:o?.text})]})}var J8=(0,m.createContext)(!1),Y8=(0,m.createContext)(void 0),X8=(0,m.createContext)(void 0);function Z8(e){let t=y8();return e===void 0?!1:t?.outputs.some(t=>t.output.id===e.id&&t.state===`outdated`)??!1}function Q8(e,t,n){let[r,i]=(0,m.useState)(),a=(0,m.use)(J8),o=(0,m.use)(Y8),s=(0,m.use)(X8),c=y8(),l=e===void 0?void 0:c?.outputs.find(t=>t.output.id===e.id)?.workKey,u=a&&l!==void 0;return{act:t=>{if(e===void 0)return;if(!u||l===void 0||t===`regenerate-image`){i(t);return}if(!l.startsWith(`image:`))return;let n=l.slice(6);o?.({section:`images`,change:e=>({...e,content:{...e.content,imageOrder:e.content.imageOrder.filter(e=>e!==n),imageDefinitions:Object.fromEntries(Object.entries(e.content.imageDefinitions).filter(([e])=>e!==n))},regenerate:(e.regenerate??[]).filter(e=>e!==l)})})},asking:r,confirm:()=>{let n=r;i(void 0),n!==void 0&&e!==void 0&&(u&&l!==void 0&&n===`regenerate-image`?s?.([l]):t.run({kind:n,outputId:e.id}))},dismiss:()=>i(void 0),unavailable:e===void 0||n||t.pending||u&&(o===void 0||s===void 0),viaEdit:u,now:u,ready:!a||c!==void 0}}function O_e(e,t){let[n,r]=(0,m.useState)(!1),i=(0,m.use)(J8),a=(0,m.use)(X8),o=y8();if(!i||o===void 0)return;let s=new Set(e.map(e=>e.id)),c=o.outputs.flatMap(e=>s.has(e.output.id)&&e.workKey.startsWith(`image:`)?[e.workKey]:[]);if(c.length!==0)return{count:c.length,asking:n,act:()=>r(!0),confirm:()=>{r(!1),a?.(c)},dismiss:()=>r(!1),unavailable:t||a===void 0}}var k_e=200,A_e=q({seconds:G(),peaks:K(G())});function j_e(e){if(e===void 0)return;let t;try{t=new URL(e,window.location.href)}catch{return}if(t.pathname.startsWith(`/files/`))return t.searchParams.set(`waveform`,String(k_e)),t.toString()}function M_e(e){let{api:t}=z(),n=j_e(e);return N({queryKey:[`waveform`,n],enabled:n!==void 0,staleTime:1/0,retry:!1,queryFn:async()=>{if(n===void 0)return[];let e=await t.fetch(n);if(!e.ok)throw po(e,void 0);let{peaks:r}=So(A_e,await e.json()),i=Math.max(0,...r);return i===0?[]:r.map(e=>e/i)}}).data}function $8(e){return(0,h.jsx)(K8,{...e,waveform:M_e(e.src)})}var e5=[{role:`audio_intro`,segment:`intro`,name:`Intro`},{role:`audio_body`,segment:`body`,name:`Body`},{role:`audio_outro`,segment:`outro`,name:`Outro`}];function N_e({stage:e,project:t,outputs:n,busy:r}){let{api:i}=z(),a=N(tb(i)),o=F8(t.id),s=f8(n,e),c=s.filter(e=>e.role===`audio_levelled`),l=e5.flatMap(e=>{let t=p8(s,e.role),n=c.find(t=>t.meta.segment===e.segment)??t;return n===void 0?[]:[{...e,output:n,...t===void 0||t===n?{}:{plain:t}}]}),u=e5.flatMap(e=>{let t=c.find(t=>t.meta.segment===e.segment)?.meta.loudness;return t===void 0?[]:[{name:e.name,report:t}]}),d=l.find(e=>e.output.meta.voice!==void 0)?.output.meta,f=l.length>0?d?.voice:t.config.audio?.voice,p=l.length>0?d?.provider:t.config.audio?.provider,m=a.data?.voices.find(e=>e.voiceId===f&&e.provider===p)?.name??f;return(0,h.jsxs)(w8,{children:[e.state===`running`?(0,h.jsx)(q8,{projectId:t.id}):null,l.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No narration has landed yet.`}):l.map(e=>(0,h.jsx)(P_e,{name:e.name,output:e.output,...e.plain===void 0?{}:{plain:e.plain}},e.role)),(0,h.jsx)(A8,{files:g_e(s,l,n.find(e=>e.role===`script_md`))}),u.length===0?null:(0,h.jsx)(j8,{children:u.map(({name:e,report:t})=>u.length===1?mk(t):`${e}: ${mk(t)}`).join(` `)}),(0,h.jsxs)(W8,{label:`How it was recorded`,children:[m===void 0?null:(0,h.jsx)(G8,{label:`Voice`,children:m}),(0,h.jsx)(G8,{label:`Chunking`,children:F_e(I_e(t.config.chunking))}),v_e(s)?(0,h.jsx)(G8,{label:`Text files`,children:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Clean narration is the spoken text used for captions. The TTS script adds delivery cues, with a blank line between requests. Uploaded audio has no TTS request.`})}):null]}),(0,h.jsx)(B8,{review:I8(o,{itemKey:`narration`}),projectId:t.id,busy:r}),(0,h.jsx)(D_e,{outputs:s})]})}function P_e({name:e,output:t,plain:n}){let r=b8(t),i=Z8(t),a=Z8(n)||n===void 0?void 0:n,o=b8(i?a:void 0);return(0,h.jsxs)(`div`,{className:`grid grid-cols-[64px_minmax(0,1fr)] items-center gap-3 text-small`,children:[(0,h.jsx)(T8,{children:e}),(0,h.jsx)($8,{label:`${e} narration`,src:r?.url,className:`max-w-[640px]`}),i?(0,h.jsx)(`p`,{className:`col-start-2 m-0 text-small text-ink-2`,children:a===void 0?`Outdated: this is the narration from before your last change. The new one is made when the run carries on: press Continue the run, or Remake at the top of the page.`:`Outdated: this is the levelled narration from before your last change. The new narration is below as it was spoken; it is levelled when the run carries on: press Continue the run, or Remake at the top of the page.`}):null,i&&a!==void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(T8,{children:`New`}),(0,h.jsx)($8,{label:`${e} narration, new, before levelling`,src:o?.url,className:`max-w-[640px]`})]}):null]})}function F_e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function I_e(e){return e===void 0||e.mode===`whole`?`the whole text as one request`:e.mode===`paragraph`?`one request per paragraph`:e.mode===`characters`?`every ${String(e.characters??3e3)} characters`:`every ${String(e.words??500)} words`}function L_e({stage:e,project:t,outputs:n}){let r=p8(f8(n,e),`document_pdf`),i=b8(r),a=XS(t.config.document);return(0,h.jsxs)(w8,{children:[r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The PDF will be saved when rendering finishes.`:`No PDF has been saved yet.`}):(0,h.jsx)(A8,{files:[{output:r,label:`PDF`}],label:`Download PDF`,children:i?.folder?(0,h.jsxs)(mS,{href:`${i.url}?inline=1`,target:`_blank`,rel:`noopener`,variant:`secondary`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open PDF`]}):null}),(0,h.jsx)(W8,{label:`PDF details`,children:(0,h.jsx)(G8,{label:`Theme`,children:a})})]})}var R_e={research:`Generates fresh research and affected article, narration, entries, thumbnail and exports; previous outputs stay in History.`,article:`Generates a fresh article and affected narration, entries, thumbnail and exports; previous outputs stay in History.`,audio:`Regenerates narration and affected exports, keeping compatible cue preparation; previous outputs stay in History.`,images:`Regenerates generated images and affected video, keeping supplied images and narration; previous outputs stay in History.`,thumbnail:`Regenerates the thumbnail without changing the main video; previous outputs stay in History.`,video:`Rebuilds local exports from saved media without regenerating narration or images; previous outputs stay in History.`,document:`Renders the PDF again from the saved article and title without regenerating anything else; previous outputs stay in History.`};function t5(e){switch(e.kind){case`cancel`:return{title:`Cancel this run?`,consequence:`Stops every running stage; finished outputs are kept.`,verb:`Cancel run`,dismiss:`Keep running`};case`rerun`:return{title:`Re-run this stage?`,consequence:R_e[e.stage],verb:`Re-run`,dismiss:`Cancel`};case`delete-image`:return{title:`Delete this image?`,consequence:`Removes the image and re-renders video when enabled.`,verb:`Delete`,dismiss:`Cancel`};case`regenerate-image`:return{title:`Regenerate this image?`,consequence:e.now?`Makes a new image now, one paid image call. The video keeps the current one until you remake it; the old image stays in History.`:`Replaces the image with a new one and re-renders video when enabled.`,verb:`Regenerate`,dismiss:`Cancel`};case`save-article`:return{title:`Save the edited article?`,consequence:`Replaces the article, then updates the enabled narration and final export.`,verb:`Save & update outputs`,dismiss:`Cancel`};case`discard-article`:return{title:`Discard these edits?`,consequence:`The article goes back to the text on disk.`,verb:`Discard`,dismiss:`Keep editing`}}}function z_e(e,t){let{config:n,content:r,fingerprints:i}=e.revision;switch(t){case`research`:return n.sources.research===`generate`;case`article`:return n.sources.article===`generate`&&!r.articleEdited;case`audio`:return n.sources.audio===`generate`&&Object.keys(i).some(e=>!/^audio:(body:.+|intro|outro):[0-9]+$/.test(e)&&!/^audio:(body|intro|outro):future$/.test(e)?!1:!Object.entries(r.narrationOverrides).some(([t,n])=>n.kind===`asset`&&(e===t||e.startsWith(`${t}:`))));case`images`:return n.sources.images!==`off`&&r.imageOrder.some(e=>r.imageDefinitions[e]?.source===`generate`);case`thumbnail`:return n.sources.thumbnail===`from_prompt`||n.sources.thumbnail===`prompt_by_llm`;case`video`:return n.sources.video!==`off`||n.sources.audio!==`off`;case`document`:return RS(n.sources,`document`)===`generate`}}function n5(e){switch(e){case`research`:case`article`:return`article`;case`audio`:return`narration`;case`images`:case`thumbnail`:return`images`;case`video`:return`video`;case`document`:return`document`}}var r5={research:`Research`,article:`Article`,audio:`Narration`,images:`Images`,thumbnail:`Thumbnail`,video:`Video`,document:`PDF`},i5=e=>/^[A-Z]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1);function B_e(e){let{project:t,stages:n}=e,r=t.config,i=e=>e===`video`&&rF(r)===`audio`?`Audio export`:r5[e];if(e.sample)return{situation:`sample`,tone:`info`,status:`Sample project`,title:`This is the sample project, finished and free to explore.`,why:`It is read-only. Your own copy can be edited and made again.`,action:{label:`Make my own copy`,intent:{kind:`copy-sample`}}};if(t.status===`paused`){let t=G_e(e.outdated);return{situation:`paused`,tone:`waiting`,status:`Paused`,title:`The run is paused.`,why:t===void 0?`Everything made so far is kept. Continuing picks up where it stopped.`:`Everything made so far is kept. Still to make: ${t}. They stay outdated until you continue.`,action:{label:`Continue the run`,intent:{kind:`resume`}}}}let a=n.find(e=>e.state===`failed`&&e.retryAt===void 0);if(a!==void 0){let t=i(a.kind),n=e.fixOf(a),r={label:`Try ${i5(a5(t))} again`,intent:{kind:`retry`,stage:a.kind}},o={situation:`failed`,tone:`failed`,status:`Failed`,section:n5(a.kind),...a.failureReason===null?{}:{detail:a.failureReason}};switch(n?.kind){case`sign-in`:return{...o,title:`${n.label.replace(/^Sign in to /,``)} is signed out, so ${i5(a5(t))} stopped.`,why:`Copy the sign-in command (${n.command}), run it in a terminal on the computer running Slopify and sign in, then press Check again. Once ${n.label.replace(/^Sign in to /,``)} is signed in, Slopify tries ${i5(a5(t))} again.`,action:{label:`Copy sign-in command`,intent:{kind:`sign-in`,stage:a.kind,fix:n}}};case`refused`:return{...o,title:`A content filter refused a prompt, so ${i5(a5(t))} stopped.`,why:n.soften?`Softening rewrites each refused prompt without what the filter flagged, then draws it again.`:`Change the prompt in the project settings, then try again.`,action:n.soften?{label:n.label,intent:{kind:`soften`,stage:a.kind}}:{label:`Edit the prompt`,intent:{kind:`edit`}}};case`switch-model`:return{...o,title:`The model for ${i5(a5(t))} is no longer offered.`,why:`Pick another model in the project settings, then try again.`,action:{label:`Switch model`,intent:{kind:`edit`}}};case`provider-settings`:return{...o,title:`The provider did not accept its key, so ${i5(a5(t))} stopped.`,why:`Check the key in Settings, then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`providers`}}};case`free-space`:return{...o,title:`The disk is full, so ${i5(a5(t))} stopped.`,why:`Storage in Settings shows what can go. Then try again.`,action:{label:n.label,intent:{kind:`open-settings`,section:`storage`}}};case void 0:return{...o,title:`${t} stopped with an error.`,why:`Trying again keeps everything already made.`,action:r}}}let o=e.held[0];if(o!==void 0){let e=i(o.stage);return{situation:`held`,tone:`waiting`,status:`Waiting for you`,title:`The ${i5(e)} ${U_e(e)} ready for your review.`,why:o.dependents.length===0?`Approving marks it reviewed.`:`Approving lets ${o5(o.dependents.map(e=>i5(a5(i(e)))))} run. Nothing after it runs until you do.`,action:{label:V_e(o,i),intent:{kind:`approve`,gate:o}},section:n5(o.stage)}}let s=n.find(e=>e.state===`failed`&&e.retryAt!==void 0),c=e.waits[0];if(c!==void 0||s!==void 0){if(c!==void 0){let t=XH(e.waits);return{situation:`waiting`,tone:`waiting`,status:`Waiting for limits`,title:`${YH(e.waits,e.clock)??``}.`,why:`Nothing to do: the run carries on by itself when they reset, and work that does not need ${t} keeps going.`,section:n5(c.stage)}}if(s!==void 0)return{situation:`waiting`,tone:`waiting`,status:`Waiting to try again`,title:`${i(s.kind)} will try again by itself at ${e.clock(s.retryAt??``)}.`,why:`Nothing to do: the run carries on when it does.`,section:n5(s.kind),...s.failureReason===null?{}:{detail:s.failureReason}}}let l=n.find(e=>e.state===`running`);if(t.status===`running`||l!==void 0)return{situation:`running`,tone:`running`,status:`Running`,title:l===void 0?`The run is starting.`:`Making the ${i5(i(l.kind))}${H_e(l)}.`,why:`Pausing lets the current call finish and keeps everything made so far.`,action:{label:`Pause`,intent:{kind:`pause`}},...l===void 0?{}:{section:n5(l.kind)}};if(e.resumable||t.status===`canceled`||t.status===`failed`&&a===void 0)return{situation:`stopped`,tone:`off`,status:t.status===`canceled`?`Canceled`:`Stopped`,title:`The run stopped before it finished.`,why:`Continuing makes only what is missing; everything made so far is kept.`,action:{label:`Continue the run`,intent:{kind:`resume`}}};if(t.status===`pending`)return{situation:`queued`,tone:`off`,status:`Queued`,title:`Waiting for its turn.`,why:`It starts by itself when the videos ahead of it are done.`};let u=W_e(e.outdated);if(u!==void 0)return{situation:`outdated`,tone:`info`,status:`Outdated`,title:u.count===1||u.singular?`The ${u.noun} ${u.noun.endsWith(`s`)?`are`:`is`} outdated after your edit.`:`${String(u.count)} ${u.plural} are outdated after your edit.`,why:`They keep their current version until you remake them. Nothing else is made again.`,action:{label:u.count===1||u.singular?`Remake the outdated ${u.noun}`:`Remake ${String(u.count)} outdated ${u.plural}`,intent:{kind:`remake`,workKeys:u.workKeys}},section:u.section};if(t.status===`done`&&r.mode===`short`)return{situation:`done`,tone:`done`,status:`Done`,title:`The short is ready.`,why:`Play opens set up for a long video on the same topic, with the same starter pack and providers. Nothing starts until you press Play.`,action:{label:`Make the full video on this topic`,intent:{kind:`full-video`}}};if((t.status===`done`||t.status===`partial`)&&e.uploadReady)return{situation:`done`,tone:`done`,status:`Done`,title:`The video is ready.`,why:`Prepare upload lays out the file, title, description, thumbnails and tags in the order YouTube Studio asks for them.`,action:{label:`Prepare upload`,intent:{kind:`prepare-upload`}},section:`youtube`}}function V_e(e,t){if(e.dependents.includes(`video`))return`Approve and render the video`;if(e.dependents.includes(`images`))return`Approve and make the images`;if(e.dependents.includes(`audio`))return`Approve and record the narration`;let n=e.dependents[0];return n===void 0?`Approve the ${i5(t(e.stage))}`:`Approve and make the ${i5(t(n))}`}function H_e(e){let t=lF(e);return t===void 0?e.progressTotal===null||e.progressTotal<=0?``:` · ${String(Math.floor(e.progressCurrent??0))} of ${String(e.progressTotal)}`:` · ${t}`}function a5(e){return/s$/i.test(e)?e:`the ${i5(e)}`}function U_e(e){return/s$/i.test(e)?`are`:`is`}function o5(e){return e.length<=1?e[0]??``:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)??``}`}var s5=[{id:`article`,noun:`article`,plural:`article files`,singular:!0,section:`article`,roles:[`notes`,`sources`,`article_md`,`article_txt`,`script_md`],counted:[`article_md`]},{id:`narration`,noun:`narration`,plural:`narration parts`,singular:!0,section:`narration`,roles:[`narration_txt`,`tts_script`,`glossary`,`audio_body`,`audio_intro`,`audio_outro`,`audio_levelled`],counted:[`audio_body`]},{id:`reference`,noun:`establishing image`,plural:`establishing images`,singular:!0,section:`images`,roles:[`reference`],counted:[`reference`]},{id:`images`,noun:`image`,plural:`images`,singular:!1,section:`images`,roles:[`image`],counted:[`image`]},{id:`animated`,noun:`animated image`,plural:`animated images`,singular:!1,section:`images`,roles:[`animated_image`],counted:[`animated_image`]},{id:`thumbnails`,noun:`thumbnail`,plural:`thumbnails`,singular:!1,section:`images`,roles:[`thumbnail`],counted:[`thumbnail`]},{id:`video`,noun:`video`,plural:`video files`,singular:!0,section:`video`,roles:[`video`,`audio_export`,`audio_mp3`,`audio_m4b`,`render_params`,`subtitles_srt`,`subtitles_vtt`,`subtitle_words`,`subtitle_ass`,`subtitle_font`],counted:[`video`,`audio_export`]},{id:`shorts`,noun:`short`,plural:`shorts`,singular:!1,section:`shorts`,roles:[`shorts`,`short_image`,`short_video`],counted:[`short_video`]},{id:`youtube`,noun:`YouTube description`,plural:`YouTube descriptions`,singular:!0,section:`youtube`,roles:[`youtube_description`,`youtube_tags`,`youtube_pinned_comment`,`youtube_titles`],counted:[`youtube_description`]},{id:`document`,noun:`PDF`,plural:`PDFs`,singular:!0,section:`document`,roles:[`document_pdf`],counted:[`document_pdf`]}];function W_e(e){for(let t of s5){let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)continue;let r=n.filter(e=>t.counted.includes(e.role)).length;return{noun:t.noun,plural:t.plural,singular:t.singular,count:Math.max(1,r),workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section}}}function G_e(e){let t=s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[t.singular?`the ${t.noun}`:r===1?`1 ${t.noun}`:`${String(r)} ${t.plural}`]});return t.length===0?void 0:o5(t)}function K_e(e){return s5.flatMap(t=>{let n=e.filter(e=>t.roles.includes(e.role));if(n.length===0)return[];let r=Math.max(1,n.filter(e=>t.counted.includes(e.role)).length);return[{label:r===1||t.singular?`Remake the outdated ${t.noun}`:`Remake ${String(r)} outdated ${t.plural}`,workKeys:[...new Set(n.map(e=>e.workKey))],section:t.section,count:r}]})}function q_e({tone:e,status:t,title:n,why:r,action:i,className:a}){return(0,h.jsxs)(`section`,{"aria-label":`Next action`,className:L(`sl-next`,a),children:[(0,h.jsx)(_S,{tone:e,children:t}),(0,h.jsx)(`p`,{className:`sl-next__title`,children:n}),r===void 0?null:(0,h.jsx)(`p`,{className:`sl-next__why`,children:r}),i===void 0?null:(0,h.jsx)(`div`,{className:`flex flex-col [&>*]:w-full`,children:i})]})}function J_e({project:e,stages:t,resumable:n,sample:r,gates:i,outdated:a,waits:o,uploadReady:s,actions:c,controller:l,openSection:u,openUpload:d}){let{api:f}=z(),p=_(),h=Zi(),[g,v]=(0,m.useState)(),y=(0,m.useRef)(new Map),b=B_e({project:e,stages:t,resumable:n,sample:r,held:i.filter(e=>(e.state===`held`||e.state===`pending-review`)&&e.fingerprint===e.currentFingerprint).map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),outdated:a,waits:o,uploadReady:s,fixOf:t=>_3(t,e),clock:fF}),x=P({mutationFn:()=>Wy(f,e.id),onSuccess:async({projectId:e})=>{await p.invalidateQueries({queryKey:B.projects}),await h({to:`/projects/$projectId`,params:{projectId:e}})},onError:e=>v(`${bo(e.message)} The copy was not made. Press Make my own copy to try again.`)}),S=(0,m.useRef)(null),C=nP(),w=P({mutationFn:async()=>{if(C===null)throw Error(`Play isn't available on this page. Reload the page`);if(C.review.starting||C.review.uncertain||C.review.created!==null)throw Error(`Play is starting a run from its open draft. Wait for it to start`);if(!await C.flush())throw Error(`The draft open in Play couldn't be saved. Open Play, save or discard it`);S.current??=crypto.randomUUID();let{draft:t}=await By(f,{projectId:e.id,draftId:S.current});if(await p.invalidateQueries({queryKey:[`play-drafts`]}),!await C.open(t.id))throw Error(`The full video's draft was made but didn't open. Open Play and pick it`);S.current=null,await h({to:`/play`})},onError:e=>v(`${bo(e.message)} Then press Make the full video on this topic again.`)}),T=P({mutationFn:async t=>{let n=i.find(e=>e.checkpointId===t.checkpointId);if(n===void 0)throw Error(`The review changed before it was approved. Reload the page.`);let r=`${n.checkpointId}:${n.fingerprint}`,a=y.current.get(r)??crypto.randomUUID();y.current.set(r,a);let o=await h3(f,e.id,n.checkpointId,{revisionId:n.revisionId,fingerprint:n.fingerprint,idempotencyKey:a});if(y.current.delete(r),!o.ok)throw Error(o.message)},onSettled:async()=>{await p.invalidateQueries({queryKey:d3(e.id)}),await p.invalidateQueries({queryKey:B.project(e.id)}),p.invalidateQueries({queryKey:B.projects})},onError:e=>v(`${bo(e.message)} Press the approve button again to check whether it went through.`)});return{next:b,run:e=>{switch(v(void 0),e.kind){case`copy-sample`:x.mutate();return;case`resume`:case`pause`:c.run({kind:e.kind});return;case`retry`:case`soften`:c.run({kind:e.kind,stage:e.stage});return;case`sign-in`:q1(e.fix.command).then(t=>v(t?`Copied ${e.fix.command}. Run it in a terminal on the computer running Slopify, sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.fix.command} in a terminal, sign in, then press Check again.`));return;case`approve`:T.mutate(e.gate);return;case`remake`:l.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0});return;case`edit`:u(`settings`);return;case`open-settings`:h({to:`/settings`,search:{section:e.section}});return;case`prepare-upload`:d();return;case`full-video`:w.mutate();return}},pending:x.isPending||w.isPending||T.isPending||c.pending||l.pending,message:g}}function Y_e(e){switch(e.kind){case`copy-sample`:return`Copying…`;case`resume`:return`Continuing…`;case`pause`:return`Pausing…`;case`approve`:return`Approving…`;case`remake`:return`Starting the remake…`;case`retry`:return`Trying again…`;case`soften`:return`Softening…`;case`full-video`:return`Opening Play…`;default:return}}function c5({state:e,variant:t,className:n}){let[r,i]=(0,m.useState)(!1),a=e.next?.action;if(a===void 0)return null;let o=a.intent;if(o.kind===`sign-in`)return(0,h.jsx)(J1,{fix:o.fix,variant:t,retry:{run:()=>e.run({kind:`retry`,stage:o.stage}),busy:e.pending}});if(o.kind===`open-settings`)return(0,h.jsx)(fS,{to:`/settings`,search:{section:o.section},variant:t,...n===void 0?{}:{className:n},children:a.label});let s=e.pending?Y_e(o)??a.label:a.label;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{variant:t,className:n,disabled:e.pending,disabledReason:`Working on the last press`,"aria-keyshortcuts":t===`primary`?Mx(lP.nextAction):void 0,onClick:()=>o.kind===`soften`?i(!0):e.run(o),children:s}),o.kind===`soften`?(0,h.jsx)(jy,{open:r,tone:`primary`,title:`Soften the refused prompt and try again?`,consequence:`Your project's AI model rewrites each refused prompt without what a content filter could flag, keeping the scene and style. The image is then drawn again from the new wording, which it keeps as its prompt. The AI call and the new image are charged like any other.`,confirmLabel:`Soften and retry`,cancelLabel:`Keep the prompt`,pending:e.pending,onConfirm:()=>{i(!1),e.run(o)},onCancel:()=>i(!1)}):null]})}function X_e({state:e,feedback:t}){let n=e.next;return n===void 0&&t===void 0&&e.message===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n===void 0?null:(0,h.jsx)(q_e,{tone:n.tone,status:n.status,title:n.title,...n.why===void 0?{}:{why:n.why},...n.action===void 0?{}:{action:(0,h.jsx)(c5,{state:e,variant:`primary`})}}),e.message===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e.message}),t]})}var Z_e={sample:void 0,paused:void 0,stopped:void 0,queued:void 0,running:void 0,failed:`danger`,held:`waiting`,waiting:`waiting`,outdated:`info`,done:void 0};function Q_e({state:e,section:t}){let n=e.next;if(n===void 0||n.section!==t)return null;let r=Z_e[n.situation];return r===void 0?null:(0,h.jsx)(SI,{className:`max-[1180px]:hidden`,tone:r,title:n.title,...n.action===void 0?{}:{actions:(0,h.jsx)(c5,{state:e,variant:`secondary`})},children:n.why===void 0&&n.detail===void 0?void 0:(0,h.jsxs)(h.Fragment,{children:[n.why===void 0?null:(0,h.jsx)(`span`,{className:`block`,children:n.why}),n.detail===void 0?null:(0,h.jsxs)(`details`,{className:`mt-1`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:n.detail})]})]})})}var $_e={research:`Research again`,article:`Write the article again`,audio:`Record the narration again`,images:`Make all images again`,thumbnail:`Make the thumbnails again`,video:`Render the video again`,document:`Render the PDF again`};function l5(e,t){return e===`video`&&t.config.sources.video===`off`?`Export the audio again`:$_e[e]}function u5({id:e,title:t,kicker:n,stages:r,project:i,outputs:a,actions:o,next:s,active:c,meta:l,head:u=!0,extra:d,resumable:f=!1,children:p}){let m=r[0],g=r.some(e=>o.refusal?.stage===e.kind)?o.refusal?.message:void 0,_=r.filter(t=>t.state===`failed`&&t.retryAt===void 0&&(s.next?.situation!==`failed`||s.next.section!==e)),v=r.find(e=>e.state===`running`),y=v===void 0?void 0:dF(v),b=l??(m===void 0?void 0:r.filter(e=>e.state!==`skipped`).map(e=>e===m?cF(e,a,i,f):`${r5[e.kind]}: ${cF(e,a,i,f)}`).join(` · `));return(0,h.jsxs)(`section`,{hidden:!c,"aria-label":t,"data-tour":m===void 0?void 0:`project-${m.kind}`,className:`flex min-w-0 flex-col gap-5`,children:[u?(0,h.jsxs)(H,{row:!0,title:t,...n===void 0?{}:{kicker:n},...b===void 0||b===``?{}:{meta:b},children:[d,(0,h.jsx)(f5,{stages:r,project:i,actions:o})]}):null,y===void 0||v===void 0?null:(0,h.jsx)(q2,{value:y,label:`${r5[v.kind]} progress`,valueText:cF(v,a,i,f)}),(0,h.jsx)(Q_e,{state:s,section:e}),_.map(e=>(0,h.jsx)(SI,{tone:`danger`,title:`${r5[e.kind]} stopped with an error.`,children:e.failureReason===null?void 0:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Error details`}),(0,h.jsx)(`pre`,{className:`m-0 mt-1 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.failureReason})]})},e.id)),g===void 0?null:(0,h.jsx)(SI,{tone:`danger`,title:g,actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:o.dismissRefusal,children:`Dismiss`})}),m?.state===`running`&&m.kind!==`article`&&m.kind!==`images`&&m.kind!==`video`&&m.kind!==`document`?(0,h.jsx)(j3,{projectId:i.id,stage:m.kind}):null,p]})}function d5({stage:e,project:t,name:n}){return e===void 0||e.state===`skipped`?(0,h.jsx)(a0,{title:`${n} is off for this run.`,children:`Switch it on in the project settings to make it.`}):(0,h.jsx)(a0,{title:`No ${n.toLowerCase()} yet.`,children:t.status===`paused`?`It is made once you continue the run.`:`It starts when the steps before it are done. Finished work elsewhere can be looked at meanwhile.`})}function f5({stages:e,project:t,actions:n}){let r=(0,m.useContext)(J8),i=y8(),[a,o]=(0,m.useState)(),s=e.filter(e=>e.state!==`skipped`&&e.state!==`pending`&&(!r||i!==void 0&&z_e(i,e.kind)));if(s.length===0)return null;let c=n.pending||t.status===`running`||e.some(e=>e.state===`running`),l=a===void 0?void 0:t5({kind:`rerun`,stage:a});return(0,h.jsxs)(h.Fragment,{children:[s.map(e=>(0,h.jsxs)(R,{size:`small`,disabled:c,disabledReason:`Wait until the work on this project is done`,onClick:()=>o(e.kind),children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),l5(e.kind,t)]},e.id)),(0,h.jsx)(jy,{open:a!==void 0,title:a===void 0?``:`${l5(a,t)}?`,consequence:l?.consequence??``,confirmLabel:a===void 0?``:l5(a,t),cancelLabel:`Keep what is there`,pending:n.pending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&n.run({kind:`rerun`,stage:e})},onCancel:()=>o(void 0)})]})}function eve({stage:e,project:t,outputs:n,actions:r,busy:i}){let a=f8(n,e),o=F8(t.id),s=VS(t.config),c=Array.from({length:s},(e,t)=>t+1).map(e=>({variant:e,output:a.find(t=>t.role===`thumbnail`&&(t.meta.index??1)===e)})),l=c.flatMap(e=>e.output===void 0?[]:[e.output]),u=x8(l),[d,f]=(0,m.useState)(null),p=l.filter(e=>u.has(e.id)),g=p.map(e=>({src:u.get(e.id)?.url??``,alt:`Thumbnail ${String(e.meta.index??1)}`})),_=t.format===`9:16`,v=({variant:n,output:a})=>(0,h.jsx)(tve,{variant:n,count:s,output:a,review:I8(o,{outputId:a?.id}),stage:e,project:t,actions:r,busy:i,onOpen:()=>f(a===void 0?null:nve(p,a))},n);return(0,h.jsxs)(`section`,{"aria-label":s===1?`Thumbnail`:`Thumbnails`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:s===1?`Thumbnail`:`Thumbnails`,meta:s===1?`The picture YouTube shows before the video plays`:`${String(s)} variants for YouTube's Test & compare`,children:[(0,h.jsx)(O8,{variant:`secondary`,files:l.map(e=>({output:e,label:s===1?`Thumbnail`:`Thumbnail ${String(e.meta.index??1)}`}))}),(0,h.jsx)(k8,{output:l[0]}),(0,h.jsx)(f5,{stages:[e],project:t,actions:r})]}),c.length===1?(0,h.jsx)(`div`,{className:_?`max-w-[280px]`:`max-w-[480px]`,children:c.map(v)}):(0,h.jsx)(B0,{list:!0,label:`Thumbnail variants`,children:c.map(e=>(0,h.jsx)(`li`,{className:`min-w-0`,children:v(e)},e.variant))}),(0,h.jsx)(V0,{items:g,index:d,onIndex:f,onClose:()=>f(null),actions:(e,t)=>{let n=p[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:s===1?`the thumbnail`:`thumbnail ${String(n.meta.index??1)}`,actions:r,busy:i},n.id)}})]})}function tve({variant:e,count:t,output:n,review:r,stage:i,project:a,actions:o,busy:s,onOpen:c}){let l=b8(n),u=Q8(n,o,s),d=t===1?`the thumbnail`:`thumbnail ${String(e)}`;bx({id:`project.thumbnail.${String(e)}`,title:t===1?`Regenerate the thumbnail`:`Regenerate thumbnail ${String(e)}`,group:`This project`,context:a.title,keywords:[`thumbnail`,`redraw`,`remake`],run:()=>u.act(`regenerate-image`)});let f=r!==void 0&&!r.passed&&r.action===null,p=String.fromCharCode(64+e),m=u.asking===void 0||n===void 0?void 0:t5({kind:u.asking,outputId:n.id,now:u.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:t===1?`Thumbnail for ${a.title}`:`Thumbnail ${String(e)} for ${a.title}`,aspect:p5(a.format),...l===void 0?{}:{src:l.url},...n===void 0&&i.state===`running`?{generating:`Making the thumbnail`}:{},title:t===1?`Thumbnail`:p,...n===void 0?{meta:rve(i)}:{},onOpen:c,openLabel:`Open ${d} full size`,...r===void 0?{}:{badge:(0,h.jsx)(V8,{review:r})},actionsShown:f,...n===void 0?{}:{actions:(0,h.jsxs)(h.Fragment,{children:[f&&r!==void 0?(0,h.jsx)(z8,{review:r,projectId:a.id,busy:s}):null,(0,h.jsxs)(R,{size:`small`,disabled:u.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>u.act(`regenerate-image`),"aria-label":`Regenerate ${d}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),l===void 0?null:(0,h.jsx)(v5,{href:l.url,label:`Download ${d}`})]})}}),(0,h.jsx)(jy,{open:u.asking!==void 0,tone:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:`Regenerate the thumbnail`,cancelLabel:`Keep it`,pending:o.pending,onConfirm:u.confirm,onCancel:u.dismiss})]})}function nve(e,t){let n=e.indexOf(t);return n===-1?null:n}function rve(e){switch(e.state){case`running`:return`Being made`;case`failed`:case`canceled`:return`Not made`;default:return`Not made yet`}}function ive(e,t){let n=e.filter(e=>e.role===`image`),r=new Map;for(let e of n){let t=e.meta.promptName??`Images`;r.set(t,[...r.get(t)??[],e])}let i=t.filter(e=>r.has(e)),a=[...r.keys()].filter(e=>!i.includes(e)).sort();return[...i,...a].flatMap(e=>{let t=r.get(e);return t===void 0?[]:[{name:e,images:[...t].sort(ave)}]})}function ave(e,t){return(e.meta.index??0)-(t.meta.index??0)}function ove(e,t,n,r,i){let a=Oy(),[o,s]=(0,m.useState)(),c=(r,i)=>{let o=r===`image`?t:n,c=r===`image`?`image`:`on-screen card`;if(i===void 0){a(`Type the ${c}'s number with the command, for example "regenerate ${c} 3".`);return}let l=o.find(e=>e.meta.index===i);if(l===void 0){let t=o.flatMap(e=>e.meta.index===void 0?[]:[e.meta.index]);a(t.length===0?`${e.title} has no ${c}s yet, so there is no ${c} ${String(i)} to regenerate. They appear under Images once the run makes them.`:`${e.title} has no ${c} ${String(i)}: its ${c}s are numbered ${String(Math.min(...t))} to ${String(Math.max(...t))}. Type one of those, or press Regenerate on the ${c} in Images.`,`error`);return}s(e=>({image:l,name:`${c[0]?.toUpperCase()??``}${c.slice(1)} ${String(i)}`,nonce:(e?.nonce??0)+1}))};return bx({id:`project.image.regenerate`,title:`Regenerate an image`,numbered:e=>`Regenerate image ${String(e)}`,group:`This project`,context:e.title,keywords:[`image`,`picture`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`image`,e)}),bx({id:`project.card.regenerate`,title:`Regenerate an on-screen card`,numbered:e=>`Regenerate on-screen card ${String(e)}`,group:`This project`,context:e.title,keywords:[`card`,`figure`,`table`,`redraw`,`remake`],searchOnly:!0,run:e=>c(`card`,e)}),Yx(Wx.regenerateImage(e.id),e=>c(`image`,e)),o===void 0?null:(0,h.jsx)(sve,{request:o,actions:r,busy:i},o.nonce)}function sve({request:e,actions:t,busy:n}){let r=Oy(),i=Q8(e.image,t,n),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{!a.current&&i.ready&&(a.current=!0,i.unavailable?r(`${e.name} can't be regenerated while work on this project is running. Wait until it finishes, then run the command again or press Regenerate on it in Images.`,`error`):i.act(`regenerate-image`))},[i,r,e.name]);let o=i.asking===void 0?void 0:t5({kind:i.asking,outputId:e.image.id,now:i.now});return(0,h.jsx)(jy,{open:i.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate the image`,cancelLabel:`Keep it`,pending:t.pending,onConfirm:i.confirm,onCancel:i.dismiss})}function p5(e){return e===`9:16`?`portrait`:`landscape`}function cve({stage:e,companion:t,project:n,outputs:r,actions:i,busy:a}){let o=F8(n.id),s=f8(r,e),c=ive(s,n.config.imagePrompts?.map(e=>e.name)??[]),l=c.flatMap(e=>e.images),u=s.filter(e=>e.role===`figure_card`&&(e.meta.format??n.format)===n.format).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),d=[...l,...u],f=ove(n,l,u,i,a),p=O_e(l,a),g=x8(d),[_,v]=(0,m.useState)(null),y=d.filter(e=>g.has(e.id)),b=y.map(e=>({src:g.get(e.id)?.url??``,alt:e.role===`figure_card`?`On-screen card ${String(e.meta.index??``)}`:e.meta.prompt??`Image ${String(e.meta.index??``)}`,...m5(e)?{kind:`video`}:{},caption:e.role===`figure_card`?`Shown while the narration describes it`:e.meta.prompt??e.meta.promptName??`Slideshow image`})),x=n.config.reference===void 0?null:(0,h.jsx)(lve,{image:p8(s,`reference`),format:n.format,generated:n.config.reference.source===`prompt`,affected:l.length,actions:i,busy:a}),S=t?.kind===`thumbnail`?(0,h.jsx)(eve,{stage:t,project:n,outputs:r,actions:i,busy:a}):null,C=e.state===`running`&&e.progressTotal!==null?Math.max(0,e.progressTotal-l.length):0,w=o.filter(e=>l.some(t=>t.id===e.outputId)),T=w.filter(e=>e.passed&&e.attempt>1).length,E=w.filter(e=>!e.passed&&e.action===null).length,D=[l.length===0?void 0:`${String(l.length)} in the video`,w.length===0?void 0:`reviewed`,T===0?void 0:`${String(T)} redone after review`,E===0?void 0:`${String(E)} flagged`].filter(e=>e!==void 0).join(` · `);return(0,h.jsxs)(h.Fragment,{children:[f,x,x===null||S===null&&e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),S,S===null||e.state===`skipped`?null:(0,h.jsx)(Mq,{className:`m-0`}),e.state===`skipped`?null:(0,h.jsxs)(`section`,{"aria-label":`Slideshow images`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(H,{title:`Images`,...D===``?{}:{meta:D},children:[p===void 0?null:(0,h.jsxs)(R,{size:`small`,disabled:p.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:p.act,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate all`]}),p===void 0?null:(0,h.jsx)(jy,{open:p.asking,tone:`primary`,title:`Regenerate all ${String(p.count)} images?`,consequence:`Makes ${String(p.count)} new images now, one paid image call each. The video keeps the current ones until you remake it; the old images stay in History.`,confirmLabel:`Regenerate them`,cancelLabel:`Keep them`,pending:i.pending,onConfirm:p.confirm,onCancel:p.dismiss}),(0,h.jsx)(c_e,{projectId:n.id,asset:`images.zip`,label:`Download all`}),(0,h.jsx)(f5,{stages:[e],project:n,actions:i})]}),c.length===0&&C===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`pending`?`The images are made once the narration is timed.`:`No images have landed yet.`}):null,c.map((e,t)=>(0,h.jsx)(y5,{name:e.name,count:e.images.length,showName:c.length>1,trailing:t===c.length-1&&C>0?Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the next image`:`Waiting its turn`},t)):null,children:t=>e.images.slice(0,t).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:I8(o,{outputId:e.id}),format:n.format,actions:i,busy:a,onOpen:()=>v(g5(y,e))},e.id))},e.name)),u.length===0?null:(0,h.jsx)(y5,{name:`From the article`,count:u.length,showName:!0,children:e=>u.slice(0,e).map(e=>(0,h.jsx)(b5,{image:e,projectId:n.id,review:void 0,format:n.format,actions:i,busy:a,card:!0,onOpen:()=>v(g5(y,e))},e.id))}),c.length===0&&C>0?(0,h.jsx)(B0,{label:`Images being made`,children:Array.from({length:Math.min(C,3)},(e,t)=>(0,h.jsx)(z0,{alt:`An image being made`,aspect:p5(n.format),generating:t===0?`Drawing the first image`:`Waiting its turn`},t))}):null,(0,h.jsx)(V0,{items:b,index:_,onIndex:v,onClose:()=>v(null),actions:(e,t)=>{let n=y[t];return n===void 0?null:(0,h.jsx)(_5,{output:n,name:n.role===`figure_card`?`on-screen card${h5(n)}`:`image${h5(n)}`,actions:i,busy:a},n.id)}})]})]})}var m5=e=>/\.(mp4|mov|m4v|webm|mkv)$/i.test(e.path),h5=e=>e.meta.index===void 0?``:` ${String(e.meta.index)}`;function g5(e,t){let n=e.indexOf(t);return n===-1?null:n}function _5({output:e,name:t,actions:n,busy:r}){let i=b8(e),a=Q8(e,n,r),o=a.asking===void 0?void 0:t5({kind:a.asking,outputId:e.id,now:a.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(R,{size:`small`,disabled:a.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>a.act(`regenerate-image`),"aria-label":`Regenerate ${t}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),i===void 0?null:(0,h.jsx)(v5,{href:i.url,label:`Download ${t}`}),(0,h.jsx)(jy,{open:a.asking!==void 0,tone:`primary`,title:o?.title??``,consequence:o?.consequence??``,confirmLabel:`Regenerate it`,cancelLabel:`Keep it`,pending:n.pending,onConfirm:a.confirm,onCancel:a.dismiss})]})}function v5({href:e,label:t,text:n}){return(0,h.jsxs)(mS,{href:e,download:!0,"aria-label":t,title:t,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),n]})}function lve({image:e,format:t,generated:n,affected:r,actions:i,busy:a}){let o=b8(e),s=Q8(e,i,a),[c,l]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Establishing image`,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{kicker:`Reference · not in the video`,title:`Establishing image`,meta:`Every image follows it for the look, palette and style`,children:e!==void 0&&n?(0,h.jsx)(R,{disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>s.act(`regenerate-image`),children:`Make the establishing image again`}):null}),(0,h.jsx)(z0,{className:`w-full max-w-[360px]`,alt:e?.meta.prompt??`Establishing image`,aspect:p5(t),...o===void 0?{}:{src:o.url},title:`Establishing image`,...e===void 0?{meta:`Not made yet`}:{},onOpen:()=>l(0),openLabel:`Open the establishing image full size`,...e===void 0||o===void 0?{}:{actions:(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`,text:`Download`})}}),n&&r>0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Making it again marks ${String(r)} image${r===1?``:`s`} outdated. They keep their current version until you remake them.`}):null,(0,h.jsx)(V0,{items:o===void 0?[]:[{src:o.url,alt:`Establishing image`,caption:e?.meta.prompt??`The reference every image follows`}],index:c,onIndex:l,onClose:()=>l(null),actions:()=>o===void 0?null:(0,h.jsxs)(h.Fragment,{children:[n?(0,h.jsxs)(R,{size:`small`,disabled:s.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>{l(null),s.act(`regenerate-image`)},"aria-label":`Make the establishing image again`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}):null,(0,h.jsx)(v5,{href:o.url,label:`Download the establishing image`})]})}),(0,h.jsx)(jy,{open:s.asking!==void 0,tone:`primary`,title:`Make the establishing image again?`,consequence:`A new establishing image replaces this one${r>0?`, and the ${String(r)} images drawn from it become outdated until you remake them`:``}. The old one stays in History.`,confirmLabel:`Make it again`,cancelLabel:`Keep this one`,pending:i.pending,onConfirm:s.confirm,onCancel:s.dismiss})]})}function y5({name:e,count:t,showName:n,trailing:r,children:i}){let[a,o]=(0,m.useState)(!1),s=t>12&&!a;return(0,h.jsxs)(`section`,{"aria-label":`${e} × ${String(t)}`,className:`flex flex-col gap-3`,children:[n?(0,h.jsx)(`h3`,{className:`sl-kicker m-0`,children:`${e} × ${String(t)}`}):null,(0,h.jsxs)(B0,{children:[i(s?12:t),r]}),t>12?(0,h.jsx)(R,{variant:`quiet`,"aria-expanded":a,className:`self-start`,onClick:()=>o(e=>!e),children:a?`Show fewer`:`Show all ${String(t)} images`}):null]})}function b5({image:e,projectId:t,review:n,format:r,actions:i,busy:a,card:o=!1,onOpen:s}){let c=b8(e),l=h5(e),u=o?`on-screen card${l}`:`image${l}`,d=Q8(e,i,a),f=Z8(e),p=n!==void 0&&!n.passed&&n.action===null,m=d.asking===void 0?void 0:t5({kind:d.asking,outputId:e.id,now:d.now});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z0,{alt:o?`On-screen card${l}`:e.meta.prompt??`Slideshow ${u}`,kind:m5(e)?`video`:`image`,aspect:p5(r),...c===void 0?{}:{src:c.url},title:o?`Card${l}`:e.meta.prompt??`Image${l}`,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`},onOpen:s,openLabel:`Open ${u} full size`,...n===void 0&&!f?{}:{badge:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap gap-1`,children:[f?(0,h.jsx)(vS,{tone:`info`,children:`Outdated`}):null,n===void 0?null:(0,h.jsx)(V8,{review:n})]})},actionsShown:p,actions:(0,h.jsxs)(h.Fragment,{children:[p&&n!==void 0?(0,h.jsx)(z8,{review:n,projectId:t,busy:a}):null,(0,h.jsxs)(R,{size:`small`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`regenerate-image`),"aria-label":`Regenerate ${u}`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Regenerate`]}),c===void 0?null:(0,h.jsx)(v5,{href:c.url,label:`Download ${u}`}),o?null:(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:d.unavailable,disabledReason:`Wait until the work on this project is done`,onClick:()=>d.act(`delete-image`),"aria-label":`Delete ${u}`,title:`Delete ${u}`,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})}),(0,h.jsx)(jy,{open:d.asking!==void 0,tone:d.asking===`delete-image`?`destructive`:`primary`,title:m?.title??``,consequence:m?.consequence??``,confirmLabel:d.asking===`delete-image`?`Delete the image`:`Regenerate the image`,cancelLabel:`Keep it`,pending:i.pending,onConfirm:d.confirm,onCancel:d.dismiss})]})}function x5(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function S5(e){let t=/^(?:(\d+):)?(\d{1,2}):(\d{2})$/.exec(e.trim());if(t===null)return;let n=Number(t[1]??`0`),r=Number(t[2]),i=Number(t[3]);if(!(i>59||t[1]!==void 0&&r>59))return n*3600+r*60+i}function uve(e){let t=e.trim(),n=/^(\S+)\s+(.+)$/u.exec(t);if(n===null)return;let r=S5(n[1]??``),i=(n[2]??``).trim();return r===void 0||i===``?void 0:{start:r,title:i}}function C5(e,t){let n=e.replace(/\r\n?/gu,`
291
291
  `).split(`
292
- `),r=[],i=[];for(let[e,t]of n.entries()){let n=lve(t);n!==void 0&&(r.push(e),i.push(n))}if(i.length===0)return{text:e,adjustments:[]};let a=[],o=e=>`"${e.title}"`,s=[...i].sort((e,t)=>e.start-t.start);s.some((e,t)=>e!==i[t])&&a.push(`put the chapters in time order`);let c=[];for(let e of s){let t=c.at(-1);t!==void 0&&t.start===e.start?a.push(`merged ${o(e)} (0 s) into ${o(t)}`):c.push(e)}s=c;let l=t!==void 0&&Number.isFinite(t)&&t>0?t:void 0;if(l!==void 0){let e=s.filter((e,t)=>t>0&&e.start>=l);for(let t of e)a.push(`removed ${o(t)} (${x5(t.start)}), which starts after the video ends at ${x5(l)}`);s=s.filter(t=>!e.includes(t))}let u=s[0];u!==void 0&&u.start!==0&&(a.push(`moved the first, ${o(u)}, from ${x5(u.start)} to 0:00`),s=[{start:0,title:u.title},...s.slice(1)]);let d=e=>{let t=s[e+1],n=s[e]?.start??0;return t===void 0?l===void 0?1/0:l-n:t.start-n},f=e=>`${String(Math.max(0,Math.floor(e)))} s`;for(;s.length>1;){let e=s.findIndex((e,t)=>d(t)<10);if(e===-1)break;let t=s[e];if(t===void 0)break;let n=f(d(e));if(e===0){let e=s[1];if(e===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(e)}`),s=[{start:0,title:e.title},...s.slice(2)]}else{let r=s[e-1];if(r===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(r)}`),s=s.filter((t,n)=>n!==e)}}if(s.length<3&&(a.push(`left the chapter list out, since YouTube needs at least 3 chapters of 10 s or more and only ${String(s.length)} ${s.length===1?`is`:`are`} left`),s=[]),a.length===0)return{text:e,adjustments:a};let p=new Map(r.map((e,t)=>[e,s[t]]));return{text:n.flatMap((e,t)=>{if(!p.has(t))return[e];let n=p.get(t);return n===void 0?[]:[`${x5(n.start)} ${n.title}`]}).join(`
293
- `).trim(),adjustments:a}}function uve(e){return e.length===0?void 0:`Chapters adjusted for YouTube: ${e.join(`; `)}.`}function w5(e,t,n={}){let r=e.replace(/\r\n?/gu,`
292
+ `),r=[],i=[];for(let[e,t]of n.entries()){let n=uve(t);n!==void 0&&(r.push(e),i.push(n))}if(i.length===0)return{text:e,adjustments:[]};let a=[],o=e=>`"${e.title}"`,s=[...i].sort((e,t)=>e.start-t.start);s.some((e,t)=>e!==i[t])&&a.push(`put the chapters in time order`);let c=[];for(let e of s){let t=c.at(-1);t!==void 0&&t.start===e.start?a.push(`merged ${o(e)} (0 s) into ${o(t)}`):c.push(e)}s=c;let l=t!==void 0&&Number.isFinite(t)&&t>0?t:void 0;if(l!==void 0){let e=s.filter((e,t)=>t>0&&e.start>=l);for(let t of e)a.push(`removed ${o(t)} (${x5(t.start)}), which starts after the video ends at ${x5(l)}`);s=s.filter(t=>!e.includes(t))}let u=s[0];u!==void 0&&u.start!==0&&(a.push(`moved the first, ${o(u)}, from ${x5(u.start)} to 0:00`),s=[{start:0,title:u.title},...s.slice(1)]);let d=e=>{let t=s[e+1],n=s[e]?.start??0;return t===void 0?l===void 0?1/0:l-n:t.start-n},f=e=>`${String(Math.max(0,Math.floor(e)))} s`;for(;s.length>1;){let e=s.findIndex((e,t)=>d(t)<10);if(e===-1)break;let t=s[e];if(t===void 0)break;let n=f(d(e));if(e===0){let e=s[1];if(e===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(e)}`),s=[{start:0,title:e.title},...s.slice(2)]}else{let r=s[e-1];if(r===void 0)break;a.push(`merged ${o(t)} (${n}) into ${o(r)}`),s=s.filter((t,n)=>n!==e)}}if(s.length<3&&(a.push(`left the chapter list out, since YouTube needs at least 3 chapters of 10 s or more and only ${String(s.length)} ${s.length===1?`is`:`are`} left`),s=[]),a.length===0)return{text:e,adjustments:a};let p=new Map(r.map((e,t)=>[e,s[t]]));return{text:n.flatMap((e,t)=>{if(!p.has(t))return[e];let n=p.get(t);return n===void 0?[]:[`${x5(n.start)} ${n.title}`]}).join(`
293
+ `).trim(),adjustments:a}}function dve(e){return e.length===0?void 0:`Chapters adjusted for YouTube: ${e.join(`; `)}.`}function w5(e,t,n={}){let r=e.replace(/\r\n?/gu,`
294
294
  `).split(`
295
- `);for(;r.length>0&&r.at(-1)?.trim()===``;)r.pop();let i=``,a=r.at(-1)?.trim()??``;for(a!==``&&a.split(/\s+/u).every(e=>/^#[\p{L}\p{N}_]+$/u.test(e))&&(i=a,r.pop());r.length>0&&r.at(-1)?.trim()===``;)r.pop();let o=[];for(;r.length>0&&dve(r.at(-1)??``);)o.unshift((r.pop()??``).trim());return{summary:r.join(`
295
+ `);for(;r.length>0&&r.at(-1)?.trim()===``;)r.pop();let i=``,a=r.at(-1)?.trim()??``;for(a!==``&&a.split(/\s+/u).every(e=>/^#[\p{L}\p{N}_]+$/u.test(e))&&(i=a,r.pop());r.length>0&&r.at(-1)?.trim()===``;)r.pop();let o=[];for(;r.length>0&&fve(r.at(-1)??``);)o.unshift((r.pop()??``).trim());return{summary:r.join(`
296
296
  `).trim(),chapters:o.join(`
297
- `),hashtags:i,tags:t.trim(),pinnedComment:(n.pinnedComment??``).trim(),titles:(n.titles??``).trim()}}function dve(e){let[t=``,...n]=e.trim().split(/\s+/u);return S5(t)!==void 0&&n.length>0}function fve(e){return[e.summary.trim(),e.chapters.trim(),e.hashtags.trim()].filter(e=>e!==``).join(`
297
+ `),hashtags:i,tags:t.trim(),pinnedComment:(n.pinnedComment??``).trim(),titles:(n.titles??``).trim()}}function fve(e){let[t=``,...n]=e.trim().split(/\s+/u);return S5(t)!==void 0&&n.length>0}function pve(e){return[e.summary.trim(),e.chapters.trim(),e.hashtags.trim()].filter(e=>e!==``).join(`
298
298
 
299
- `)}function pve(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function T5(e,t){let n=n=>pve(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function E5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}var mve=q({number:G().int().positive(),first:G().int().positive(),last:G().int().positive(),start:G().finite().nonnegative(),end:G().finite().positive(),title:W(),description:W(),hashtags:K(W()),why:W(),text:W(),seed:W().nullable().optional()}),hve=.25,gve=.4;function D5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(hve,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(gve,(s-a.end)/2)));return{start:O5(c),end:O5(l)}}q({first:tO([G(),W()]),last:tO([G(),W()]),title:W(),description:W(),hashtags:K(W()),why:W().optional()});function O5(e){return Math.round(e*1e3)/1e3}var _ve=q({shorts:K(mve),durationSeconds:G().finite().nonnegative().optional(),sentences:K(q({start:G().finite().nonnegative(),end:G().finite().nonnegative(),text:W()})).optional()});function vve(e){if(e!=null)try{let t=_ve.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function yve(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=D5(o,n,r,bve(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function bve(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function k5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:mq(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:mq(n,e.config.values)]))}}}}function xve(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:ON(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function A5(e,t,n){return k5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function Sve(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function j5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=z(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await Vo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await Sve(r.signal);let e=(await Po(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Ho(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(xV,{label:e,id:s,children:(0,h.jsx)(CV,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(R,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var M5=`shorts:pick`,N5=e=>`shorts:${String(e)}`;function P5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],M5])]}}function F5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],N5(t)])]}}function Cve(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=vve(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function wve({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Lk,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Jk(o)}),l=[...n,...I5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...I5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(M5)===!0,f=Cve(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(YV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(Tve,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(O6,{settings:KV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?Ove(n,e):A5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=qk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(Eve,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function Tve({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(j5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function Eve({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:D5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(V,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==M5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>o(P5(e)),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(Dve,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(N5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):yve(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?F5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==N5(t.number))})},t.number))})]})}function Dve({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(xV,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(TV,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(V,{id:`project.shorts.remake`})]})]})]})}function I5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function Ove(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return k5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var kve=q({shorts:K(q({number:G(),first:G().optional(),last:G().optional(),start:G(),end:G(),title:W(),description:W(),hashtags:K(W())}))});function Ave({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=f8(n,e),a=p8(i,`shorts`),o=z5(i),s=F8(t.id),[c,l]=(0,m.useState)(),u=L5(i,`short_video`,o),d=t.config.shorts,f=(0,m.use)(J8),p=(0,m.use)(Y8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let g=f&&p!==void 0&&d?.enabled===!0,_=e=>{let t=Uk(e,d?.fullVideoLink),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(A8,{files:o.map(e=>({output:u.find(t=>R5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:g&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...Ob,children:[(0,h.jsx)(R,{onClick:()=>p({section:`shorts`,change:P5}),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(B0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(jve,{clip:n,projectId:t.id,review:I8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>R5(e,n)),stills:L5(i,`short_image`,o).filter(e=>R5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:d?.fullVideoLink,wanted:Kk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:Pve(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>_(n),...g?{onRemake:()=>p({section:`shorts`,change:e=>F5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(Q1,{tone:c?.tone??`info`,children:c?.text})]})}function jve({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=b8(r),g=b8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(R0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(z0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:_F(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(Mve,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(B8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Ey,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(hS,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(wy,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(m8,{children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{align:`start`,children:(0,h.jsxs)(_8,{onSelect:d,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function Mve({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(vS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function L5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>R5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function R5(e,t){return e.meta.short===t.number}function z5(e){return Nve(M8(p8(e,`shorts`)).data)}function Nve(e){if(e===void 0)return[];try{let t=kve.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function Pve(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function Fve({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=z(),a=Oy(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=p8(f8(n,e),o?`audio_export`:`video`),c=f8(n,e),l=p8(c,`subtitles_srt`),u=p8(c,`subtitles_vtt`),d=p8(c,`youtube_description`),f=p8(c,`youtube_tags`),p=p8(c,`audio_mp3`),m=p8(c,`audio_m4b`),g=L5(c,`short_video`,z5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=b8(s),v=b8(Ive(n)),y=Lve(t.id,d,f,s?.durationMs??null),b=b8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=vF(e.progressCurrent??0,e.progressTotal??0);return bx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await c2(i,{projectId:t.id,asset:D3(s),folder:_?.folder??null});e.opened||a(`${l2} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(w8,{children:r}):(0,h.jsxs)(w8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:aF(e,t.config)?`Preparing subtitles · ${String(vF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:uF(lF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)($8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(R0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,className:t.format===`9:16`?`max-w-[360px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(A8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(j8,{children:[_F(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:hk(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||VO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:VO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function Ive(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function Lve(e,t,n,r){let{api:i}=z(),a=M8(t).data,o=M8(n).data,s=N({queryKey:B.youtubeEdits(e),queryFn:()=>Es(i,e),enabled:t!==void 0});return a===void 0?[]:Rve(E5(T5(w5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function Rve(e,t){return C5(e,t).text.split(`
300
- `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:S5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function zve(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(S_e,{...e});case`audio`:return(0,h.jsx)(M_e,{...e});case`images`:return(0,h.jsx)(sve,{...e});case`video`:return(0,h.jsx)(Fve,{...e});case`document`:return(0,h.jsx)(I_e,{...e});case`research`:case`thumbnail`:return null}}q({summary:W(),chapters:K(q({start:tO([W(),G()]),title:W()})),hashtags:K(W()),tags:K(W()),pinnedComment:W(),titles:K(W())});function B5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function Bve({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=z(),a=_(),o=f8(n,e),s=p8(o,`youtube_description`),c=p8(o,`youtube_tags`),l=p8(o,`youtube_pinned_comment`),u=p8(o,`youtube_titles`),d=M8(s).data,f=M8(c).data,p=M8(l).data,g=M8(u).data,v=(0,m.use)(X8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=N({queryKey:B.youtubeEdits(t.id),queryFn:()=>Es(i,t.id)}),T=N({queryKey:B.projectChannelLinks(t.id),queryFn:()=>Ts(i,t.id)}),[E,D]=(0,m.useState)(),O=Oy(),k=e=>a.setQueryData(B.youtubeEdits(t.id),e),A=P({mutationFn:e=>Ds(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),ee=(0,m.useRef)({});if(bx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:lP.copyDescription,run:()=>ee.current.description===void 0?O(`The description has not been written yet.`,`info`):ee.current.description()}),bx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>ee.current.tags===void 0?O(`The tags have not been written yet.`,`info`):ee.current.tags()}),bx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>ee.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):ee.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let te=d===void 0?void 0:w5(d,f??``,{pinnedComment:p,titles:g}),ne=T5(te,w.data?.fields??{}),j=E5(ne),re=Nj(T.data?.links??[],w.data?.links??[]),M=p8(o,`video`),ie=C5(j.chapters,M?.durationMs===null||M?.durationMs===void 0?void 0:M.durationMs/1e3),ae=uve(ie.adjustments),oe=Fj(fve({...j,chapters:ie.text}),re),se=Fj(j.tags,re),ce=Fj(j.pinnedComment,re),le=[...oe.unknown,...se.unknown,...ce.unknown].filter((e,t,n)=>n.findIndex(t=>Mj(t)===Mj(e))===t),ue=G5(se.text),de=te!==void 0,fe=ce.text.trim()!==``,pe=j.titles.split(`
301
- `).map(e=>e.trim()).filter(e=>e!==``),me=(e,t)=>{let n=`Couldn't copy the ${t}. Select the text in the YouTube section and copy it.`;if(!navigator.clipboard){D({text:n,tone:`error`}),O(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),O(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),O(n,`error`)})};ee.current=de?{description:()=>me(oe.text,`description`),tags:()=>me(se.text,`tags`),...fe?{pinnedComment:()=>me(ce.text,`pinned comment`)}:{}}:{};let he=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,ge=(e,t)=>(0,h.jsx)(Vve,{label:V5[e],value:ne[e],links:re,disabled:!de||A.isPending,multiline:e!==`hashtags`,placeholder:de&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again above to have one written, or Edit to write your own.`:de&&e===`titles`?`Written before other titles existed. Use Write again above to have two written, or Edit to write your own, one per line.`:he,render:t,onSave:t=>A.mutate({field:e,edit:{text:t,base:te?.[e]??``},done:`Saved your ${V5[e].toLowerCase()}.`}),onUseGenerated:()=>A.mutate({field:e,edit:null,done:`The ${V5[e].toLowerCase()} follows the generated text again.`}),onKeepMine:(t,n)=>A.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${V5[e].toLowerCase()}.`})},e);return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`@container flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sr-only`,children:`YouTube`}),(0,h.jsxs)(`div`,{className:`flex min-w-0 max-w-[80ch] flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:de?()=>me(oe.text,`description`):void 0,keyshortcuts:Mx(lP.copyDescription),count:de?`${String(oe.text.length)} / ${String(S6)} characters`:void 0,over:oe.text.length>S6,main:!0,again:de&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`summary`),ge(`chapters`,()=>ie.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(W5,{text:ie.text,links:re})),ae===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:ae}),ge(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:de?()=>me(se.text,`tags`):void 0,count:de?`${String(B5(ue))} / 500 characters`:void 0,over:B5(ue)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:ge(`tags`,e=>(0,h.jsx)(Hve,{text:e,links:re}))}),(0,h.jsx)(U5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:de&&fe?()=>me(ce.text,`pinned comment`):void 0,count:de&&fe?`${String(ce.text.length)} / 500 characters`:void 0,over:ce.text.length>500}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`pinnedComment`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Post it under the video once it is published, then choose Pin in the comment's menu.`})]}),(0,h.jsx)(U5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:de&&pe.length>0?()=>me(pe.join(`
302
- `),`other titles`):void 0,count:de&&pe.length>0?`${String(pe.length+1)} titles to test`:void 0,over:pe.some(e=>e.length>100)}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`titles`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`For YouTube's A/B Testing beside the title, with this project's own title "${t.title}". One per line.`})]})]})]}),le.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${le.map(e=>`{{${e}}}`).join(`, `)}, so it stays as typed. Add it under Channel links on `,T.data===void 0?`the channel's Brand tab`:(0,h.jsx)(ha,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${le.some(e=>Mj(e)===Mj(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(Uve,{projectId:t.id,edits:w.data,onSaved:e=>{k(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(Q1,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(jy,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags and pinned comment. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function U5({id:e,label:t,copy:n,count:r,over:i,keyshortcuts:a,main:o=!1,again:s,open:c,onToggle:l}){return(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-3 border-b border-line pb-2`,children:[(0,h.jsx)(`h4`,{id:e,className:`m-0 text-title-3 font-semibold text-ink`,children:l===void 0?t:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,"aria-expanded":c===!0,onClick:l,className:`-ml-2 h-auto px-2 py-1 text-title-3 font-semibold text-ink`,children:[(0,h.jsx)(fc,{"aria-hidden":`true`,strokeWidth:1.75,className:L(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:L(`text-small tabular-nums`,i?`text-danger`:`text-ink-3`),children:i?`${r}, over YouTube's limit`:r}),(0,h.jsx)(`span`,{className:`flex-1`}),s===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`secondary`,onClick:s,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(R,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function Vve({label:e,value:t,links:n,disabled:r,multiline:i,placeholder:a,render:o,onSave:s,onUseGenerated:c,onKeepMine:l}){let u=(0,m.useId)(),[d,f]=(0,m.useState)(),[p,g]=(0,m.useState)(!1),_=d!==void 0,v=e.toLowerCase(),y=e in H5?H5[e]:void 0;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h5`,{id:`${u}-label`,className:`sl-kicker text-ink-3`,children:e}),y===void 0?null:(0,h.jsx)(V,{id:y,label:v,className:`-my-1`})]}),t.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),t.edited&&!_?(0,h.jsx)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r,"aria-label":`Use the generated ${v}`,onClick:c,children:`Use generated`}):null,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r||_,"aria-label":`Edit ${v}`,onClick:()=>f(t.text),children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),t.pending===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-l-2 border-waiting pl-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`p`,{className:`text-small text-ink`,children:`New generated version available.`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Use the new generated ${v}`,onClick:c,children:`Use it`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Keep my ${v}`,onClick:()=>l(t.text,t.pending??``),children:`Keep mine`}),(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-expanded":p,"aria-label":`${p?`Hide`:`View`} the ${v} diff`,onClick:()=>g(e=>!e),children:p?`Hide diff`:`View diff`})]}),p?(0,h.jsx)(w4,{before:t.text,after:t.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),_?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${u}-edit`,className:`sr-only`,children:e}),i?(0,h.jsx)(wV,{id:`${u}-edit`,rows:e===`Chapters`?8:5,value:d,onChange:e=>f(e.currentTarget.value)}):(0,h.jsx)(CV,{id:`${u}-edit`,value:d,onChange:e=>f(e.currentTarget.value)}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(R,{type:`button`,variant:`primary`,disabled:r,onClick:()=>{s(d),f(void 0)},children:[`Save `,v]}),(0,h.jsx)(R,{type:`button`,variant:`secondary`,onClick:()=>f(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${u}-label`,className:L(`min-w-0 whitespace-pre-wrap break-words text-small`,t.text===``?`text-ink-3`:`text-ink`),children:t.text===``?a:o===void 0?(0,h.jsx)(W5,{text:t.text,links:n}):o(t.text)})]})}function W5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:Pj(e,t).map(e=>{let t=String(n);return n+=e.kind===`text`?e.text.length:e.raw.length,e.kind===`text`?(0,h.jsx)(`span`,{children:e.text},t):e.url===void 0?(0,h.jsx)(`mark`,{title:`No link named ${e.name}`,className:`rounded-[2px] bg-waiting/25 px-0.5 text-ink`,children:e.raw},t):(0,h.jsx)(`span`,{title:e.raw,className:`underline decoration-dotted underline-offset-[3px]`,children:e.url},t)})})}function G5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function Hve({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:G5(e).map((e,n)=>(0,h.jsx)(`li`,{className:`rounded-full border border-line bg-raised px-2 py-0.5 text-small text-ink`,children:(0,h.jsx)(W5,{text:e,links:t})},n))})}function Uve({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=z(),a=(0,m.useId)(),o=t?.links.find(e=>Mj(e.name)===Mj(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=P({mutationFn:()=>{let n=(t?.links??[]).filter(e=>Mj(e.name)!==Mj(kj));return Os(i,e,l.trim()===``?n:[...n,{name:kj,url:l.trim()}])},onSuccess:e=>{c(void 0),n(e)},onError:e=>r(e.message)});return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[260px] flex-1 flex-col gap-1 sm:max-w-[520px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{className:`sl-field__label`,htmlFor:a,children:`Previous video for this project`}),(0,h.jsx)(V,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(CV,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(R,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var K5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function Wve({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=z(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(!1),g=(0,m.useRef)(!0),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=JSON.stringify([t,n.map(e=>[e.stage,e.checkpointId]).toSorted()]),b=s!==null&&s.baseIdentity!==y,x=s?.stages??n.map(e=>e.stage),S=K5.some(({stage:e})=>x.includes(e)!==n.some(t=>t.stage===e)),C=b||d!==null&&d.kind!==`success`,w=b?{kind:`refused`,message:`Checkpoint choices changed elsewhere. Press Reload checkpoint choices before saving, then make your change again.`}:d;(0,m.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,m.useEffect)(()=>{(d||b)&&_.current?.focus()},[d,b]);async function T(){if(!(p.current||!S||C)){p.current=!0,u(!0);try{let n=await sme(o,e,{revisionId:t,stages:x});if(!g.current)return;n.ok?n.value.revisionId===t?(a(n.value),c(null),f({kind:`success`,message:`Checkpoint choices saved.`})):f({kind:`refused`,message:`The project was edited elsewhere. Press Reload checkpoint choices to see its current choices.`}):f({kind:`refused`,message:n.message})}catch(e){g.current&&f({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the change`)} It may or may not have saved. Press Reload checkpoint choices before changing anything else.`})}finally{p.current=!1,g.current&&u(!1)}}}async function E(){if(!p.current){p.current=!0,u(!0);try{let e=await i();g.current&&e&&(c(null),f(null),v.current?.focus())}finally{p.current=!1,g.current&&u(!1)}}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(`fieldset`,{ref:v,tabIndex:-1,className:`space-y-2`,...Ob,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(V,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),K5.map(({stage:e,name:t})=>{let n=r.find(t=>t.kind===e),i=n?.state===`pending`&&(e===`video`?n.source!==`off`||r.some(e=>e.kind===`audio`&&e.source!==`off`&&e.state!==`skipped`):(n.source??`generate`)===`generate`);return(0,h.jsxs)(`label`,{className:`flex min-h-10 items-center gap-3`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),disabled:!i||l||C,onChange:t=>{c({baseIdentity:s?.baseIdentity??y,stages:t.target.checked?[...x,e]:x.filter(t=>t!==e)}),f(null)}}),`Before `,t]},e)})]}),w?(0,h.jsx)(`p`,{ref:_,tabIndex:-1,role:w.kind===`success`?`status`:`alert`,children:w.message}):null,(0,h.jsx)(R,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(R,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var q5=e=>e.charAt(0).toUpperCase()+e.slice(1);function Gve(e){return e.revisionId===null?null:(0,h.jsx)(Kve,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function Kve({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=z(),o=_(),s=N({queryKey:f3(e,t),queryFn:()=>m3(a,e),retry:!1}),c=s.data,l=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t?e.data.value:void 0},u=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t};return s.isPending?null:s.error||c?.ok===!1?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:s.error?.message??(c?.ok===!1?c.message:`Checkpoints couldn't be loaded. Press Reload checkpoints.`)}),(0,h.jsx)(R,{onClick:()=>void u(),children:`Reload checkpoints`})]}):c?.ok?c.value.revisionId===t?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col gap-5`,children:[(0,h.jsx)(H,{title:`Review checkpoints`,size:`small`,className:`pb-0`}),n?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`The project is paused. Continue the run before approving held work.`}):null,(0,h.jsx)(Wve,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(f3(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:B.project(e)}),o.invalidateQueries({queryKey:B.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(qve,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,...a.checkpointId===i?{inRail:!0}:{}},`${a.checkpointId}:${a.fingerprint}`))]}):(0,h.jsx)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The project was edited after these checkpoints loaded. Press Reload checkpoints before approving.`})}):null}function qve({gate:e,disabled:t,reload:n,inRail:r=!1}){let{api:i}=z(),a=_(),o=(0,m.useRef)(null),s=(0,m.useRef)(!1),c=(0,m.useRef)(!0),l=(0,m.useRef)(null),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(null);(0,m.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,m.useEffect)(()=>{f!==null&&l.current?.focus()},[f]);let g=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function v(){if(!(s.current||t||!g||f?.kind===`refused`||f?.kind===`success`)){s.current=!0,d(!0),o.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await h3(i,e.projectId,e.checkpointId,o.current);o.current=null,c.current&&p(t.ok?{kind:`success`,message:t.value.replayed?`Checkpoint already approved.`:`Checkpoint approved. Work will run when its dependencies are ready.`}:{kind:`refused`,message:t.message}),a.invalidateQueries({queryKey:d3(e.projectId)}),a.invalidateQueries({queryKey:B.project(e.projectId)}),a.invalidateQueries({queryKey:B.projects})}catch(e){c.current&&p({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{s.current=!1,c.current&&d(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`${q5(e.stage)} checkpoint`,className:`pb-0`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`released`&&e.approvedAt!==null?`Authorized for this revision. Work can run when dependencies are ready and the project is resumed.`:e.state===`satisfied`?`Checkpoint satisfied. Its reviewed work is complete.`:e.state===`invalidated`||e.fingerprint!==e.currentFingerprint?`Inputs changed. Review the current revision before approving.`:g?`${q5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Reviewed revision: `,e.revisionId]}),e.dependents.length?(0,h.jsx)(`ul`,{"aria-label":`Dependent work`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:e.dependents.map(e=>(0,h.jsx)(`li`,{className:`sl-chip`,children:q5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),f?(0,h.jsx)(`p`,{ref:l,tabIndex:-1,role:f.kind===`success`?`status`:`alert`,className:f.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:f.message}):null,g&&r&&f===null?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Its approval is the project's next action, in the right rail.`}):g?(0,h.jsx)(R,{className:`self-start`,disabled:t||u||f?.kind===`refused`||f?.kind===`success`,onClick:()=>void v(),children:u?`Approving…`:f?.kind===`transport`?`Retry approval`:`Approve ${q5(e.stage)} checkpoint`}):null,f?.kind===`refused`?(0,h.jsx)(R,{className:`self-start`,onClick:async()=>{await n()&&p(null)},children:`Reload checkpoints`}):null]})}function Jve({projects:e,queryKey:t}){let{api:n}=z(),r=_(),i=Oy(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=P({mutationFn:e=>Bo(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t.title}" (${String(e.files)} working file${e.files===1?``:`s`}).`,`success`)},onError:e=>c(e.message),onSettled:()=>r.invalidateQueries({queryKey:t})}),u=e.toSorted((e,t)=>t.bytes-e.bytes);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-2 flex items-center gap-1 text-small text-ink-2`,children:[`Keep outputs only frees a finished project's working files.`,(0,h.jsx)(V,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(pU,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(mU,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[Y5(e.bytes),` · outputs `,Y5(e.outputsBytes),` · working files `,Y5(e.workingBytes)]}),actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:!e.finished||e.removableBytes===0||l.isPending,title:e.finished?e.removableBytes===0?`No working files left to remove.`:`Frees ${Y5(e.removableBytes)}.`:`Available once the project has finished.`,onClick:()=>o(e),children:l.isPending&&l.variables?.id===e.id?`Removing…`:`Keep outputs only`})},e.id))}),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:s}),(0,h.jsx)(jy,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:J5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function J5(e,t){return`This removes ${String(e)} working file(s) and frees ${Y5(t)}: the images, narration parts, subtitle timing and render settings the project was made from. The video, shorts, thumbnail, article, description and document stay, and so does anything you uploaded. If you change this project later (edit an image, a caption style or the narration, or re-render), Slopify has to make those files again first, which takes time and uses provider credits.`}function Y5(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var X5=e=>[`storage`,`project`,e];function Yve({projectId:e,title:t,status:n,sample:r}){let{api:i}=z(),a=_(),o=Oy(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=N({queryKey:[...X5(e),n],queryFn:()=>zo(i,e),enabled:l&&!r}),d=P({mutationFn:()=>Bo(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t}". The outputs are all still here.`,`success`),onError:e=>o(`The working files of "${t}" weren't removed: ${e.message}`,`error`),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:X5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:B.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=Y5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{as:`h3`,title:`Free space`,meta:`Outputs ${Y5(f.outputsBytes)} · working files ${Y5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Free ${p}: keep the outputs, drop the working files`,disabled:d.isPending,disabledReason:`Removing the working files…`,onClick:()=>c(!0),children:d.isPending?`Removing…`:`Free ${p}`})}),(0,h.jsx)(jy,{open:s,title:`Free ${p} from "${t}"?`,consequence:J5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function Xve({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=$ve(e.status);return(0,h.jsx)(kq,{crumb:(0,h.jsxs)(ha,{to:`/projects`,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(dc,{"aria-hidden":`true`,strokeWidth:1.75}),`Projects`]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[eye(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:s.tone,children:[s.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`Project: ${s.word}`})]}),a!==void 0&&Zve(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(V,{id:`project.next-chapter`}),a.error===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`max-w-[320px] text-small text-danger`,children:a.error})]}):null,(0,h.jsxs)(R,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{label:`More project actions`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{children:i.map(e=>(0,h.jsx)(Qve,{item:e},e.id))})]})]})})}function Zve(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function Qve({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)($ge,{}):null,(0,h.jsx)(_8,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function $ve(e){switch(e){case`running`:return{tone:`running`,word:`Running`};case`paused`:return{tone:`waiting`,word:`Paused`};case`failed`:return{tone:`failed`,word:`Failed`};case`partial`:return{tone:`waiting`,word:`Done with problems`};case`done`:return{tone:`done`,word:`Done`};case`canceled`:return{tone:`off`,word:`Canceled`};case`pending`:return{tone:`off`,word:`Queued`}}}function eye(e,t){let n=e.config.articlePrompt,r=t===void 0||t.some(e=>e.name===n),i=n===void 0||n===``?void 0:r?n:`${n} (deleted)`,a=e.config.voices?.book;return[a===void 0?void 0:LA(a),i,e.format,`started ${ku(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function tye({projectId:e}){let{api:t}=z(),n=N(Zy(t,e));return n.error===null?n.data===void 0?(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading run cost`,className:`flex flex-col gap-8`,children:[(0,h.jsx)(`span`,{className:`h-16 max-w-3xl rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`})]}):(0,h.jsx)(oye,{cost:n.data}):(0,h.jsx)(SI,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var nye=new Set([`done`,`partial`,`failed`,`canceled`]);function rye({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=r?.current===!0&&!nye.has(t),[a,o]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),!i||r===null)return null;let s=o7(r.workingMs+(r.running?Math.max(0,a-n):0));return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(zc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3.5 shrink-0`}),r.running?`Working for ${s}`:`${s} of work so far`]})]})}var iye=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:nF[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:o7(e.wallMs)}],aye=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:lye(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>t7.format(e.calls)}];function Z5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function oye({cost:e}){if(e.calls===0&&e.byStage.length===0)return(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Nothing has been spent yet. The cost of each provider call appears here as the run makes it.`});let t=e.byModel.some(e=>e.onPlan),n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({plan:e,window:t})):[]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{"aria-label":`Run cost summary`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(G2,{children:[(0,h.jsx)(K2,{value:a7(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(K2,{value:`~${a7(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${Z5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${n7.format(t.usedPercent)}%`;return(0,h.jsx)(K2,{value:r,label:`of ${n}`,children:(0,h.jsx)(q2,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${n7.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(K2,{value:o7(e.run.workingMs),label:`this run's working time`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 text-small text-ink-2`,children:[e.unpriced>0?(0,h.jsx)(`p`,{className:`m-0`,children:`Plus ${i7(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:sye(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:cye(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(H,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by stage`,columns:iye,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(H,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by model`,columns:aye,rows:e.byModel,rowKey:e=>`${e.provider}/${e.model}/${e.kind}`})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In total: ${e7(e.totals)||`no reported usage`} · ${o7(e.totals.wallMs)} working, over every run.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Priced from the model catalogue${e.catalogueDate===null?``:` of ${e.catalogueDate}`} when each call finished. Retries that failed are not charged here; taxes and included credits are not counted.`})]})]})}function sye(e){let t=e.apiEquivalent??0;if(t===0&&e.apiUnpriced>0)return`CLI calls: $0 on your plan · no API price is listed for their models.`;let n=e.apiUnpriced>0?` (plus ${i7(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${a7(t)} via API${n}.`}function cye(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=Z5(t.kind),r=t.usedPercent<1?`under 1%`:`~${n7.format(t.usedPercent)}%`,i=`now at ${n7.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${dye(t.resetsAt)}`}`;return`This run used ${r} of your ${n} ${e.name} limit (${i}).`}).join(` `):`${e.name} did not report its plan limits for this run, so the share it used is not known.`}function Q5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${a7(e.cost)} + unknown`:a7(e.cost)}function $5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${a7(e.apiEquivalent)}`}function lye(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function e7(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${r7(e.tokensIn)} in / ${r7(e.tokensOut)} out tokens${e.cachedTokens>0?` (${r7(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${r7(e.characters)} characters`),e.images>0&&t.push(i7(e.images,`image`)),e.seconds>0&&t.push(`${t7.format(e.seconds)} s of video`),t.join(` · `)}var t7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),n7=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),uye=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function r7(e){return e<1e4?t7.format(e):uye.format(e)}function i7(e,t){return`${t7.format(e)} ${t}${e===1?``:`s`}`}function a7(e){return e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function o7(e){let t=Math.round(e/1e3);if(t<60)return`${t} s`;let n=Math.floor(t/60);return n<60?`${n} min ${t%60} s`:`${Math.floor(n/60)} h ${n%60} min`}function dye(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function fye({project:e,revisionId:t,stages:n,outputs:r}){let i=r.filter(e=>e.role===`image`).sort((e,t)=>(e.meta.index??0)-(t.meta.index??0)),a=n.find(e=>e.kind===`article`),o=(0,m.use)(g3);return(0,h.jsx)(`div`,{className:`flex min-w-0 flex-col`,children:(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{title:`Article`}),a?.state===`running`?(0,h.jsx)(j3,{projectId:e.id,stage:`article`,className:`mb-6`}):a?.state===`done`?(0,h.jsxs)(`p`,{className:`mb-6 flex flex-wrap items-center gap-3 text-small text-ink-2`,children:[`The article is written.`,o===void 0?null:(0,h.jsx)(R,{variant:`secondary`,size:`small`,onClick:()=>o(`output`),children:`Read it`})]}):(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:a===void 0||a.state===`skipped`?`This project has no article.`:`The article appears here as it is written.`}),(0,h.jsx)(H,{title:`Narration`}),(0,h.jsx)(mye,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(H,{title:`Images`}),i.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The images appear here as each one is drawn.`}):(0,h.jsx)(B0,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(pye,{output:t,aspect:p5(e.format)},t.id))})]})})}function pye({output:e,aspect:t}){let n=b8(e);if(n===void 0)return null;let r=e.meta.index===void 0?``:` ${String(e.meta.index)}`;return(0,h.jsx)(`li`,{className:`min-w-0`,children:(0,h.jsx)(z0,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function mye({projectId:e,revisionId:t,audio:n,outputs:r}){let i=r.find(e=>e.role===`audio_levelled`&&e.meta.segment===`body`)??r.find(e=>e.role===`audio_body`),a=b8(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s7,{projectId:e,revisionId:t}),(0,h.jsx)(q8,{projectId:e})]}):a===void 0?(0,h.jsx)(s7,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)($8,{label:`Body narration`,src:a.url})})}var hye=240;function s7({projectId:e,revisionId:t}){let{api:n}=z(),r=N({queryKey:Py(e,t),queryFn:()=>Ky(n,e),enabled:t!==null}),i=(r.data?.pieces??[]).flatMap(e=>e.peaks),a=(r.data?.pieces??[]).reduce((e,t)=>e+t.seconds,0),o=Math.max(1,Math.ceil(i.length/hye)),s=[];for(let e=0;e<i.length;e+=o)s.push(Math.max(...i.slice(e,e+o)));return(0,h.jsxs)(`div`,{className:`mb-6`,children:[(0,h.jsx)(`div`,{role:`img`,"aria-label":s.length===0?`No narration yet`:`Narration so far: ${o7(a*1e3)}`,className:`flex h-16 items-center gap-px overflow-hidden rounded-control border border-line bg-raised px-2`,children:s.map((e,t)=>(0,h.jsx)(`span`,{className:`w-[3px] shrink-0 rounded-full bg-accent`,style:{height:`${String(Math.max(4,Math.round(e*100)))}%`}},t))}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:r.error?r.error.message:s.length===0?`The waveform grows as each part of the narration is spoken.`:`${o7(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function gye(e){let t=[],n=[],r=0,i=()=>{let e=n[0],r=n.at(-1);e!==void 0&&r!==void 0&&t.push({start:e.start,end:r.end,text:c7(n.map(e=>e.text)),...e.speaker===void 0?{}:{speaker:e.speaker}}),n=[]};for(let t of e){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<r-.001||t.end<=t.start)throw Error(`The saved caption timing is damaged. Use More → Render the video again in the Video section to time them again, then Try again.`);let e=n[0];e!==void 0&&(t.start-r>.7||t.speaker!==e.speaker||t.end-e.start>5||c7([...n.map(e=>e.text),t.text]).split(`
299
+ `)}function mve(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function T5(e,t){let n=n=>mve(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function E5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}var hve=q({number:G().int().positive(),first:G().int().positive(),last:G().int().positive(),start:G().finite().nonnegative(),end:G().finite().positive(),title:W(),description:W(),hashtags:K(W()),why:W(),text:W(),seed:W().nullable().optional()}),gve=.25,_ve=.4;function D5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(gve,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(_ve,(s-a.end)/2)));return{start:O5(c),end:O5(l)}}q({first:tO([G(),W()]),last:tO([G(),W()]),title:W(),description:W(),hashtags:K(W()),why:W().optional()});function O5(e){return Math.round(e*1e3)/1e3}var vve=q({shorts:K(hve),durationSeconds:G().finite().nonnegative().optional(),sentences:K(q({start:G().finite().nonnegative(),end:G().finite().nonnegative(),text:W()})).optional()});function yve(e){if(e!=null)try{let t=vve.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function bve(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=D5(o,n,r,xve(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function xve(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function k5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:mq(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:mq(n,e.config.values)]))}}}}function Sve(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:ON(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function A5(e,t,n){return k5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function Cve(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function j5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=z(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await Vo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await Cve(r.signal);let e=(await Po(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Ho(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(xV,{label:e,id:s,children:(0,h.jsx)(CV,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(R,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var M5=`shorts:pick`,N5=e=>`shorts:${String(e)}`;function P5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],M5])]}}function F5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],N5(t)])]}}function wve(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=yve(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function Tve({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Lk,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Jk(o)}),l=[...n,...I5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...I5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(M5)===!0,f=wve(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(YV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(Eve,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(O6,{settings:KV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?kve(n,e):A5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=qk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(Dve,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function Eve({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(j5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function Dve({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:D5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(V,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==M5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>o(P5(e)),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(Ove,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(N5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):bve(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?F5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==N5(t.number))})},t.number))})]})}function Ove({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(xV,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(TV,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(V,{id:`project.shorts.remake`})]})]})]})}function I5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function kve(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return k5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var Ave=q({shorts:K(q({number:G(),first:G().optional(),last:G().optional(),start:G(),end:G(),title:W(),description:W(),hashtags:K(W())}))});function jve({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=f8(n,e),a=p8(i,`shorts`),o=z5(i),s=F8(t.id),[c,l]=(0,m.useState)(),u=L5(i,`short_video`,o),d=t.config.shorts,f=(0,m.use)(J8),p=(0,m.use)(Y8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let g=f&&p!==void 0&&d?.enabled===!0,_=e=>{let t=Uk(e,d?.fullVideoLink),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(A8,{files:o.map(e=>({output:u.find(t=>R5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:g&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...Ob,children:[(0,h.jsx)(R,{onClick:()=>p({section:`shorts`,change:P5}),children:`Pick different moments`}),(0,h.jsx)(V,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(B0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(Mve,{clip:n,projectId:t.id,review:I8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>R5(e,n)),stills:L5(i,`short_image`,o).filter(e=>R5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:d?.fullVideoLink,wanted:Kk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:Fve(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>_(n),...g?{onRemake:()=>p({section:`shorts`,change:e=>F5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(Q1,{tone:c?.tone??`info`,children:c?.text})]})}function Mve({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=b8(r),g=b8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(R0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(z0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:_F(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(Nve,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(B8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Ey,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(hS,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(wy,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(m8,{children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{align:`start`,children:(0,h.jsxs)(_8,{onSelect:d,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function Nve({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(vS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function L5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>R5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function R5(e,t){return e.meta.short===t.number}function z5(e){return Pve(M8(p8(e,`shorts`)).data)}function Pve(e){if(e===void 0)return[];try{let t=Ave.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function Fve(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function Ive({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=z(),a=Oy(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=p8(f8(n,e),o?`audio_export`:`video`),c=f8(n,e),l=p8(c,`subtitles_srt`),u=p8(c,`subtitles_vtt`),d=p8(c,`youtube_description`),f=p8(c,`youtube_tags`),p=p8(c,`audio_mp3`),m=p8(c,`audio_m4b`),g=L5(c,`short_video`,z5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=b8(s),v=b8(Lve(n)),y=Rve(t.id,d,f,s?.durationMs??null),b=b8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=vF(e.progressCurrent??0,e.progressTotal??0);return bx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await c2(i,{projectId:t.id,asset:D3(s),folder:_?.folder??null});e.opened||a(`${l2} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(w8,{children:r}):(0,h.jsxs)(w8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:aF(e,t.config)?`Preparing subtitles · ${String(vF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:uF(lF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)($8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(R0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,className:t.format===`9:16`?`max-w-[360px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(A8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(j8,{children:[_F(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:hk(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||VO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:VO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function Lve(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function Rve(e,t,n,r){let{api:i}=z(),a=M8(t).data,o=M8(n).data,s=N({queryKey:B.youtubeEdits(e),queryFn:()=>Es(i,e),enabled:t!==void 0});return a===void 0?[]:zve(E5(T5(w5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function zve(e,t){return C5(e,t).text.split(`
300
+ `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:S5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function Bve(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(C_e,{...e});case`audio`:return(0,h.jsx)(N_e,{...e});case`images`:return(0,h.jsx)(cve,{...e});case`video`:return(0,h.jsx)(Ive,{...e});case`document`:return(0,h.jsx)(L_e,{...e});case`research`:case`thumbnail`:return null}}q({summary:W(),chapters:K(q({start:tO([W(),G()]),title:W()})),hashtags:K(W()),tags:K(W()),pinnedComment:W(),titles:K(W())});function B5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function Vve({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=z(),a=_(),o=f8(n,e),s=p8(o,`youtube_description`),c=p8(o,`youtube_tags`),l=p8(o,`youtube_pinned_comment`),u=p8(o,`youtube_titles`),d=M8(s).data,f=M8(c).data,p=M8(l).data,g=M8(u).data,v=(0,m.use)(X8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=N({queryKey:B.youtubeEdits(t.id),queryFn:()=>Es(i,t.id)}),T=N({queryKey:B.projectChannelLinks(t.id),queryFn:()=>Ts(i,t.id)}),[E,D]=(0,m.useState)(),O=Oy(),k=e=>a.setQueryData(B.youtubeEdits(t.id),e),A=P({mutationFn:e=>Ds(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),ee=(0,m.useRef)({});if(bx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:lP.copyDescription,run:()=>ee.current.description===void 0?O(`The description has not been written yet.`,`info`):ee.current.description()}),bx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>ee.current.tags===void 0?O(`The tags have not been written yet.`,`info`):ee.current.tags()}),bx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>ee.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):ee.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let te=d===void 0?void 0:w5(d,f??``,{pinnedComment:p,titles:g}),ne=T5(te,w.data?.fields??{}),j=E5(ne),re=Nj(T.data?.links??[],w.data?.links??[]),M=p8(o,`video`),ie=C5(j.chapters,M?.durationMs===null||M?.durationMs===void 0?void 0:M.durationMs/1e3),ae=dve(ie.adjustments),oe=Fj(pve({...j,chapters:ie.text}),re),se=Fj(j.tags,re),ce=Fj(j.pinnedComment,re),le=[...oe.unknown,...se.unknown,...ce.unknown].filter((e,t,n)=>n.findIndex(t=>Mj(t)===Mj(e))===t),ue=G5(se.text),de=te!==void 0,fe=ce.text.trim()!==``,pe=j.titles.split(`
301
+ `).map(e=>e.trim()).filter(e=>e!==``),me=(e,t)=>{let n=`Couldn't copy the ${t}. Select the text in the YouTube section and copy it.`;if(!navigator.clipboard){D({text:n,tone:`error`}),O(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),O(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),O(n,`error`)})};ee.current=de?{description:()=>me(oe.text,`description`),tags:()=>me(se.text,`tags`),...fe?{pinnedComment:()=>me(ce.text,`pinned comment`)}:{}}:{};let he=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,ge=(e,t)=>(0,h.jsx)(Hve,{label:V5[e],value:ne[e],links:re,disabled:!de||A.isPending,multiline:e!==`hashtags`,placeholder:de&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again above to have one written, or Edit to write your own.`:de&&e===`titles`?`Written before other titles existed. Use Write again above to have two written, or Edit to write your own, one per line.`:he,render:t,onSave:t=>A.mutate({field:e,edit:{text:t,base:te?.[e]??``},done:`Saved your ${V5[e].toLowerCase()}.`}),onUseGenerated:()=>A.mutate({field:e,edit:null,done:`The ${V5[e].toLowerCase()} follows the generated text again.`}),onKeepMine:(t,n)=>A.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${V5[e].toLowerCase()}.`})},e);return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`@container flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sr-only`,children:`YouTube`}),(0,h.jsxs)(`div`,{className:`flex min-w-0 max-w-[80ch] flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:de?()=>me(oe.text,`description`):void 0,keyshortcuts:Mx(lP.copyDescription),count:de?`${String(oe.text.length)} / ${String(S6)} characters`:void 0,over:oe.text.length>S6,main:!0,again:de&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`summary`),ge(`chapters`,()=>ie.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(W5,{text:ie.text,links:re})),ae===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:ae}),ge(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:de?()=>me(se.text,`tags`):void 0,count:de?`${String(B5(ue))} / 500 characters`:void 0,over:B5(ue)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:ge(`tags`,e=>(0,h.jsx)(Uve,{text:e,links:re}))}),(0,h.jsx)(U5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:de&&fe?()=>me(ce.text,`pinned comment`):void 0,count:de&&fe?`${String(ce.text.length)} / 500 characters`:void 0,over:ce.text.length>500}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`pinnedComment`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Post it under the video once it is published, then choose Pin in the comment's menu.`})]}),(0,h.jsx)(U5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:de&&pe.length>0?()=>me(pe.join(`
302
+ `),`other titles`):void 0,count:de&&pe.length>0?`${String(pe.length+1)} titles to test`:void 0,over:pe.some(e=>e.length>100)}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[ge(`titles`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`For YouTube's A/B Testing beside the title, with this project's own title "${t.title}". One per line.`})]})]})]}),le.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${le.map(e=>`{{${e}}}`).join(`, `)}, so it stays as typed. Add it under Channel links on `,T.data===void 0?`the channel's Brand tab`:(0,h.jsx)(ha,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${le.some(e=>Mj(e)===Mj(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(Wve,{projectId:t.id,edits:w.data,onSaved:e=>{k(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(Q1,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(jy,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags and pinned comment. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function U5({id:e,label:t,copy:n,count:r,over:i,keyshortcuts:a,main:o=!1,again:s,open:c,onToggle:l}){return(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-3 border-b border-line pb-2`,children:[(0,h.jsx)(`h4`,{id:e,className:`m-0 text-title-3 font-semibold text-ink`,children:l===void 0?t:(0,h.jsxs)(R,{type:`button`,variant:`quiet`,"aria-expanded":c===!0,onClick:l,className:`-ml-2 h-auto px-2 py-1 text-title-3 font-semibold text-ink`,children:[(0,h.jsx)(fc,{"aria-hidden":`true`,strokeWidth:1.75,className:L(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:L(`text-small tabular-nums`,i?`text-danger`:`text-ink-3`),children:i?`${r}, over YouTube's limit`:r}),(0,h.jsx)(`span`,{className:`flex-1`}),s===void 0?null:(0,h.jsxs)(R,{type:`button`,variant:`secondary`,onClick:s,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(R,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(gc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function Hve({label:e,value:t,links:n,disabled:r,multiline:i,placeholder:a,render:o,onSave:s,onUseGenerated:c,onKeepMine:l}){let u=(0,m.useId)(),[d,f]=(0,m.useState)(),[p,g]=(0,m.useState)(!1),_=d!==void 0,v=e.toLowerCase(),y=e in H5?H5[e]:void 0;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h5`,{id:`${u}-label`,className:`sl-kicker text-ink-3`,children:e}),y===void 0?null:(0,h.jsx)(V,{id:y,label:v,className:`-my-1`})]}),t.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),t.edited&&!_?(0,h.jsx)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r,"aria-label":`Use the generated ${v}`,onClick:c,children:`Use generated`}):null,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,size:`small`,disabled:r||_,"aria-label":`Edit ${v}`,onClick:()=>f(t.text),children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),t.pending===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-l-2 border-waiting pl-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`p`,{className:`text-small text-ink`,children:`New generated version available.`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Use the new generated ${v}`,onClick:c,children:`Use it`}),(0,h.jsx)(R,{type:`button`,disabled:r,"aria-label":`Keep my ${v}`,onClick:()=>l(t.text,t.pending??``),children:`Keep mine`}),(0,h.jsx)(R,{type:`button`,variant:`quiet`,"aria-expanded":p,"aria-label":`${p?`Hide`:`View`} the ${v} diff`,onClick:()=>g(e=>!e),children:p?`Hide diff`:`View diff`})]}),p?(0,h.jsx)(w4,{before:t.text,after:t.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),_?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${u}-edit`,className:`sr-only`,children:e}),i?(0,h.jsx)(wV,{id:`${u}-edit`,rows:e===`Chapters`?8:5,value:d,onChange:e=>f(e.currentTarget.value)}):(0,h.jsx)(CV,{id:`${u}-edit`,value:d,onChange:e=>f(e.currentTarget.value)}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(R,{type:`button`,variant:`primary`,disabled:r,onClick:()=>{s(d),f(void 0)},children:[`Save `,v]}),(0,h.jsx)(R,{type:`button`,variant:`secondary`,onClick:()=>f(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${u}-label`,className:L(`min-w-0 whitespace-pre-wrap break-words text-small`,t.text===``?`text-ink-3`:`text-ink`),children:t.text===``?a:o===void 0?(0,h.jsx)(W5,{text:t.text,links:n}):o(t.text)})]})}function W5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:Pj(e,t).map(e=>{let t=String(n);return n+=e.kind===`text`?e.text.length:e.raw.length,e.kind===`text`?(0,h.jsx)(`span`,{children:e.text},t):e.url===void 0?(0,h.jsx)(`mark`,{title:`No link named ${e.name}`,className:`rounded-[2px] bg-waiting/25 px-0.5 text-ink`,children:e.raw},t):(0,h.jsx)(`span`,{title:e.raw,className:`underline decoration-dotted underline-offset-[3px]`,children:e.url},t)})})}function G5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function Uve({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:G5(e).map((e,n)=>(0,h.jsx)(`li`,{className:`rounded-full border border-line bg-raised px-2 py-0.5 text-small text-ink`,children:(0,h.jsx)(W5,{text:e,links:t})},n))})}function Wve({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=z(),a=(0,m.useId)(),o=t?.links.find(e=>Mj(e.name)===Mj(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=P({mutationFn:()=>{let n=(t?.links??[]).filter(e=>Mj(e.name)!==Mj(kj));return Os(i,e,l.trim()===``?n:[...n,{name:kj,url:l.trim()}])},onSuccess:e=>{c(void 0),n(e)},onError:e=>r(e.message)});return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[260px] flex-1 flex-col gap-1 sm:max-w-[520px]`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{className:`sl-field__label`,htmlFor:a,children:`Previous video for this project`}),(0,h.jsx)(V,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(CV,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(R,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var K5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function Gve({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=z(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(!1),g=(0,m.useRef)(!0),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=JSON.stringify([t,n.map(e=>[e.stage,e.checkpointId]).toSorted()]),b=s!==null&&s.baseIdentity!==y,x=s?.stages??n.map(e=>e.stage),S=K5.some(({stage:e})=>x.includes(e)!==n.some(t=>t.stage===e)),C=b||d!==null&&d.kind!==`success`,w=b?{kind:`refused`,message:`Checkpoint choices changed elsewhere. Press Reload checkpoint choices before saving, then make your change again.`}:d;(0,m.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,m.useEffect)(()=>{(d||b)&&_.current?.focus()},[d,b]);async function T(){if(!(p.current||!S||C)){p.current=!0,u(!0);try{let n=await cme(o,e,{revisionId:t,stages:x});if(!g.current)return;n.ok?n.value.revisionId===t?(a(n.value),c(null),f({kind:`success`,message:`Checkpoint choices saved.`})):f({kind:`refused`,message:`The project was edited elsewhere. Press Reload checkpoint choices to see its current choices.`}):f({kind:`refused`,message:n.message})}catch(e){g.current&&f({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the change`)} It may or may not have saved. Press Reload checkpoint choices before changing anything else.`})}finally{p.current=!1,g.current&&u(!1)}}}async function E(){if(!p.current){p.current=!0,u(!0);try{let e=await i();g.current&&e&&(c(null),f(null),v.current?.focus())}finally{p.current=!1,g.current&&u(!1)}}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(`fieldset`,{ref:v,tabIndex:-1,className:`space-y-2`,...Ob,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(V,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),K5.map(({stage:e,name:t})=>{let n=r.find(t=>t.kind===e),i=n?.state===`pending`&&(e===`video`?n.source!==`off`||r.some(e=>e.kind===`audio`&&e.source!==`off`&&e.state!==`skipped`):(n.source??`generate`)===`generate`);return(0,h.jsxs)(`label`,{className:`flex min-h-10 items-center gap-3`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),disabled:!i||l||C,onChange:t=>{c({baseIdentity:s?.baseIdentity??y,stages:t.target.checked?[...x,e]:x.filter(t=>t!==e)}),f(null)}}),`Before `,t]},e)})]}),w?(0,h.jsx)(`p`,{ref:_,tabIndex:-1,role:w.kind===`success`?`status`:`alert`,children:w.message}):null,(0,h.jsx)(R,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(R,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var q5=e=>e.charAt(0).toUpperCase()+e.slice(1);function Kve(e){return e.revisionId===null?null:(0,h.jsx)(qve,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function qve({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=z(),o=_(),s=N({queryKey:f3(e,t),queryFn:()=>m3(a,e),retry:!1}),c=s.data,l=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t?e.data.value:void 0},u=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t};return s.isPending?null:s.error||c?.ok===!1?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:s.error?.message??(c?.ok===!1?c.message:`Checkpoints couldn't be loaded. Press Reload checkpoints.`)}),(0,h.jsx)(R,{onClick:()=>void u(),children:`Reload checkpoints`})]}):c?.ok?c.value.revisionId===t?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col gap-5`,children:[(0,h.jsx)(H,{title:`Review checkpoints`,size:`small`,className:`pb-0`}),n?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`The project is paused. Continue the run before approving held work.`}):null,(0,h.jsx)(Gve,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(f3(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:B.project(e)}),o.invalidateQueries({queryKey:B.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(Jve,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,...a.checkpointId===i?{inRail:!0}:{}},`${a.checkpointId}:${a.fingerprint}`))]}):(0,h.jsx)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The project was edited after these checkpoints loaded. Press Reload checkpoints before approving.`})}):null}function Jve({gate:e,disabled:t,reload:n,inRail:r=!1}){let{api:i}=z(),a=_(),o=(0,m.useRef)(null),s=(0,m.useRef)(!1),c=(0,m.useRef)(!0),l=(0,m.useRef)(null),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(null);(0,m.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,m.useEffect)(()=>{f!==null&&l.current?.focus()},[f]);let g=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function v(){if(!(s.current||t||!g||f?.kind===`refused`||f?.kind===`success`)){s.current=!0,d(!0),o.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await h3(i,e.projectId,e.checkpointId,o.current);o.current=null,c.current&&p(t.ok?{kind:`success`,message:t.value.replayed?`Checkpoint already approved.`:`Checkpoint approved. Work will run when its dependencies are ready.`}:{kind:`refused`,message:t.message}),a.invalidateQueries({queryKey:d3(e.projectId)}),a.invalidateQueries({queryKey:B.project(e.projectId)}),a.invalidateQueries({queryKey:B.projects})}catch(e){c.current&&p({kind:`transport`,message:`${bo(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{s.current=!1,c.current&&d(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(H,{as:`h3`,title:`${q5(e.stage)} checkpoint`,className:`pb-0`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`released`&&e.approvedAt!==null?`Authorized for this revision. Work can run when dependencies are ready and the project is resumed.`:e.state===`satisfied`?`Checkpoint satisfied. Its reviewed work is complete.`:e.state===`invalidated`||e.fingerprint!==e.currentFingerprint?`Inputs changed. Review the current revision before approving.`:g?`${q5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Reviewed revision: `,e.revisionId]}),e.dependents.length?(0,h.jsx)(`ul`,{"aria-label":`Dependent work`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:e.dependents.map(e=>(0,h.jsx)(`li`,{className:`sl-chip`,children:q5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),f?(0,h.jsx)(`p`,{ref:l,tabIndex:-1,role:f.kind===`success`?`status`:`alert`,className:f.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:f.message}):null,g&&r&&f===null?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Its approval is the project's next action, in the right rail.`}):g?(0,h.jsx)(R,{className:`self-start`,disabled:t||u||f?.kind===`refused`||f?.kind===`success`,onClick:()=>void v(),children:u?`Approving…`:f?.kind===`transport`?`Retry approval`:`Approve ${q5(e.stage)} checkpoint`}):null,f?.kind===`refused`?(0,h.jsx)(R,{className:`self-start`,onClick:async()=>{await n()&&p(null)},children:`Reload checkpoints`}):null]})}function Yve({projects:e,queryKey:t}){let{api:n}=z(),r=_(),i=Oy(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=P({mutationFn:e=>Bo(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t.title}" (${String(e.files)} working file${e.files===1?``:`s`}).`,`success`)},onError:e=>c(e.message),onSettled:()=>r.invalidateQueries({queryKey:t})}),u=e.toSorted((e,t)=>t.bytes-e.bytes);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-2 flex items-center gap-1 text-small text-ink-2`,children:[`Keep outputs only frees a finished project's working files.`,(0,h.jsx)(V,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(pU,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(mU,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[Y5(e.bytes),` · outputs `,Y5(e.outputsBytes),` · working files `,Y5(e.workingBytes)]}),actions:(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:!e.finished||e.removableBytes===0||l.isPending,title:e.finished?e.removableBytes===0?`No working files left to remove.`:`Frees ${Y5(e.removableBytes)}.`:`Available once the project has finished.`,onClick:()=>o(e),children:l.isPending&&l.variables?.id===e.id?`Removing…`:`Keep outputs only`})},e.id))}),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:s}),(0,h.jsx)(jy,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:J5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function J5(e,t){return`This removes ${String(e)} working file(s) and frees ${Y5(t)}: the images, narration parts, subtitle timing and render settings the project was made from. The video, shorts, thumbnail, article, description and document stay, and so does anything you uploaded. If you change this project later (edit an image, a caption style or the narration, or re-render), Slopify has to make those files again first, which takes time and uses provider credits.`}function Y5(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var X5=e=>[`storage`,`project`,e];function Xve({projectId:e,title:t,status:n,sample:r}){let{api:i}=z(),a=_(),o=Oy(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=N({queryKey:[...X5(e),n],queryFn:()=>zo(i,e),enabled:l&&!r}),d=P({mutationFn:()=>Bo(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t}". The outputs are all still here.`,`success`),onError:e=>o(`The working files of "${t}" weren't removed: ${e.message}`,`error`),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:X5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:B.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=Y5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{as:`h3`,title:`Free space`,meta:`Outputs ${Y5(f.outputsBytes)} · working files ${Y5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(R,{variant:`secondary`,size:`small`,"aria-label":`Free ${p}: keep the outputs, drop the working files`,disabled:d.isPending,disabledReason:`Removing the working files…`,onClick:()=>c(!0),children:d.isPending?`Removing…`:`Free ${p}`})}),(0,h.jsx)(jy,{open:s,title:`Free ${p} from "${t}"?`,consequence:J5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function Zve({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=eye(e.status);return(0,h.jsx)(kq,{crumb:(0,h.jsxs)(ha,{to:`/projects`,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(dc,{"aria-hidden":`true`,strokeWidth:1.75}),`Projects`]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[tye(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:s.tone,children:[s.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`Project: ${s.word}`})]}),a!==void 0&&Qve(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(V,{id:`project.next-chapter`}),a.error===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`max-w-[320px] text-small text-danger`,children:a.error})]}):null,(0,h.jsxs)(R,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(m8,{modal:!1,children:[(0,h.jsx)(h8,{asChild:!0,children:(0,h.jsx)(wy,{label:`More project actions`,children:(0,h.jsx)(vc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(g8,{children:i.map(e=>(0,h.jsx)($ve,{item:e},e.id))})]})]})})}function Qve(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function $ve({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(e_e,{}):null,(0,h.jsx)(_8,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function eye(e){switch(e){case`running`:return{tone:`running`,word:`Running`};case`paused`:return{tone:`waiting`,word:`Paused`};case`failed`:return{tone:`failed`,word:`Failed`};case`partial`:return{tone:`waiting`,word:`Done with problems`};case`done`:return{tone:`done`,word:`Done`};case`canceled`:return{tone:`off`,word:`Canceled`};case`pending`:return{tone:`off`,word:`Queued`}}}function tye(e,t){let n=e.config.articlePrompt,r=t===void 0||t.some(e=>e.name===n),i=n===void 0||n===``?void 0:r?n:`${n} (deleted)`,a=e.config.voices?.book;return[a===void 0?void 0:LA(a),i,e.format,`started ${ku(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function nye({projectId:e}){let{api:t}=z(),n=N(Zy(t,e));return n.error===null?n.data===void 0?(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading run cost`,className:`flex flex-col gap-8`,children:[(0,h.jsx)(`span`,{className:`h-16 max-w-3xl rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`})]}):(0,h.jsx)(sye,{cost:n.data}):(0,h.jsx)(SI,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var rye=new Set([`done`,`partial`,`failed`,`canceled`]);function iye({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=r?.current===!0&&!rye.has(t),[a,o]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),!i||r===null)return null;let s=o7(r.workingMs+(r.running?Math.max(0,a-n):0));return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(zc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3.5 shrink-0`}),r.running?`Working for ${s}`:`${s} of work so far`]})]})}var aye=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:nF[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:o7(e.wallMs)}],oye=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:uye(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>t7.format(e.calls)}];function Z5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function sye({cost:e}){if(e.calls===0&&e.byStage.length===0)return(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Nothing has been spent yet. The cost of each provider call appears here as the run makes it.`});let t=e.byModel.some(e=>e.onPlan),n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({plan:e,window:t})):[]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{"aria-label":`Run cost summary`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(G2,{children:[(0,h.jsx)(K2,{value:a7(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(K2,{value:`~${a7(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${Z5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${n7.format(t.usedPercent)}%`;return(0,h.jsx)(K2,{value:r,label:`of ${n}`,children:(0,h.jsx)(q2,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${n7.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(K2,{value:o7(e.run.workingMs),label:`this run's working time`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 text-small text-ink-2`,children:[e.unpriced>0?(0,h.jsx)(`p`,{className:`m-0`,children:`Plus ${i7(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:cye(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:lye(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(H,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by stage`,columns:aye,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(H,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Run cost by model`,columns:oye,rows:e.byModel,rowKey:e=>`${e.provider}/${e.model}/${e.kind}`})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In total: ${e7(e.totals)||`no reported usage`} · ${o7(e.totals.wallMs)} working, over every run.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Priced from the model catalogue${e.catalogueDate===null?``:` of ${e.catalogueDate}`} when each call finished. Retries that failed are not charged here; taxes and included credits are not counted.`})]})]})}function cye(e){let t=e.apiEquivalent??0;if(t===0&&e.apiUnpriced>0)return`CLI calls: $0 on your plan · no API price is listed for their models.`;let n=e.apiUnpriced>0?` (plus ${i7(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${a7(t)} via API${n}.`}function lye(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=Z5(t.kind),r=t.usedPercent<1?`under 1%`:`~${n7.format(t.usedPercent)}%`,i=`now at ${n7.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${fye(t.resetsAt)}`}`;return`This run used ${r} of your ${n} ${e.name} limit (${i}).`}).join(` `):`${e.name} did not report its plan limits for this run, so the share it used is not known.`}function Q5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${a7(e.cost)} + unknown`:a7(e.cost)}function $5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${a7(e.apiEquivalent)}`}function uye(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function e7(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${r7(e.tokensIn)} in / ${r7(e.tokensOut)} out tokens${e.cachedTokens>0?` (${r7(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${r7(e.characters)} characters`),e.images>0&&t.push(i7(e.images,`image`)),e.seconds>0&&t.push(`${t7.format(e.seconds)} s of video`),t.join(` · `)}var t7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),n7=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),dye=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function r7(e){return e<1e4?t7.format(e):dye.format(e)}function i7(e,t){return`${t7.format(e)} ${t}${e===1?``:`s`}`}function a7(e){return e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function o7(e){let t=Math.round(e/1e3);if(t<60)return`${t} s`;let n=Math.floor(t/60);return n<60?`${n} min ${t%60} s`:`${Math.floor(n/60)} h ${n%60} min`}function fye(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function pye({project:e,revisionId:t,stages:n,outputs:r}){let i=r.filter(e=>e.role===`image`).sort((e,t)=>(e.meta.index??0)-(t.meta.index??0)),a=n.find(e=>e.kind===`article`),o=(0,m.use)(g3);return(0,h.jsx)(`div`,{className:`flex min-w-0 flex-col`,children:(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{title:`Article`}),a?.state===`running`?(0,h.jsx)(j3,{projectId:e.id,stage:`article`,className:`mb-6`}):a?.state===`done`?(0,h.jsxs)(`p`,{className:`mb-6 flex flex-wrap items-center gap-3 text-small text-ink-2`,children:[`The article is written.`,o===void 0?null:(0,h.jsx)(R,{variant:`secondary`,size:`small`,onClick:()=>o(`output`),children:`Read it`})]}):(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:a===void 0||a.state===`skipped`?`This project has no article.`:`The article appears here as it is written.`}),(0,h.jsx)(H,{title:`Narration`}),(0,h.jsx)(hye,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(H,{title:`Images`}),i.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The images appear here as each one is drawn.`}):(0,h.jsx)(B0,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(mye,{output:t,aspect:p5(e.format)},t.id))})]})})}function mye({output:e,aspect:t}){let n=b8(e);if(n===void 0)return null;let r=e.meta.index===void 0?``:` ${String(e.meta.index)}`;return(0,h.jsx)(`li`,{className:`min-w-0`,children:(0,h.jsx)(z0,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function hye({projectId:e,revisionId:t,audio:n,outputs:r}){let i=r.find(e=>e.role===`audio_levelled`&&e.meta.segment===`body`)??r.find(e=>e.role===`audio_body`),a=b8(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s7,{projectId:e,revisionId:t}),(0,h.jsx)(q8,{projectId:e})]}):a===void 0?(0,h.jsx)(s7,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)($8,{label:`Body narration`,src:a.url})})}var gye=240;function s7({projectId:e,revisionId:t}){let{api:n}=z(),r=N({queryKey:Py(e,t),queryFn:()=>Ky(n,e),enabled:t!==null}),i=(r.data?.pieces??[]).flatMap(e=>e.peaks),a=(r.data?.pieces??[]).reduce((e,t)=>e+t.seconds,0),o=Math.max(1,Math.ceil(i.length/gye)),s=[];for(let e=0;e<i.length;e+=o)s.push(Math.max(...i.slice(e,e+o)));return(0,h.jsxs)(`div`,{className:`mb-6`,children:[(0,h.jsx)(`div`,{role:`img`,"aria-label":s.length===0?`No narration yet`:`Narration so far: ${o7(a*1e3)}`,className:`flex h-16 items-center gap-px overflow-hidden rounded-control border border-line bg-raised px-2`,children:s.map((e,t)=>(0,h.jsx)(`span`,{className:`w-[3px] shrink-0 rounded-full bg-accent`,style:{height:`${String(Math.max(4,Math.round(e*100)))}%`}},t))}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:r.error?r.error.message:s.length===0?`The waveform grows as each part of the narration is spoken.`:`${o7(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function _ye(e){let t=[],n=[],r=0,i=()=>{let e=n[0],r=n.at(-1);e!==void 0&&r!==void 0&&t.push({start:e.start,end:r.end,text:c7(n.map(e=>e.text)),...e.speaker===void 0?{}:{speaker:e.speaker}}),n=[]};for(let t of e){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<r-.001||t.end<=t.start)throw Error(`The saved caption timing is damaged. Use More → Render the video again in the Video section to time them again, then Try again.`);let e=n[0];e!==void 0&&(t.start-r>.7||t.speaker!==e.speaker||t.end-e.start>5||c7([...n.map(e=>e.text),t.text]).split(`
303
303
  `).length>2)&&i(),n.push({...t,text:t.text.replace(/\s+/g,` `).trim()}),r=t.end,/[.!?]["'’”)]*$/.test(t.text)&&i()}return i(),t}function c7(e){let t=[],n=``;for(let r of e)n!==``&&n.length+r.length+1>42&&(t.push(n),n=``),n=n===``?r:`${n} ${r}`;return n!==``&&t.push(n),t.join(`
304
- `)}function _ye({cues:e,duration:t,onChange:n,onPending:r}){let i=(0,m.useId)(),[a,o]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[s,c]=(0,m.useState)(),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(r);d.current=r,(0,m.useEffect)(()=>{d.current(l)},[l]),(0,m.useEffect)(()=>()=>d.current(!1),[]);function f(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){c(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,o]of a.entries()){let a=o.start.trim()===``?NaN:Number(o.start),s=o.end.trim()===``?NaN:Number(o.end);if(r.has(o.id)){c(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(o.id),!Number.isFinite(a)||a<0||a<i){c(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=a||s>t){c(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(o.text.trim()===``){c(`Caption ${n+1}: enter caption text.`);return}e.push({id:o.id,text:o.text,start:a,end:s,...o.speaker===void 0?{}:{speaker:o.speaker}}),i=s}n(e),c(void 0),u(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(V,{id:`project.captions.editor`})]}),a.map((e,t)=>(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Caption `,t+1]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(wV,{id:`${i}-${e.id}-text`,value:e.text,onChange:n=>{u(!0),o(a.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{u(!0),o(a.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{u(!0),o(a.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:s}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:f,children:`Apply caption edits to draft`}),(0,h.jsx)(V,{id:`project.captions.apply`})]}),l?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function l7(e){return`imagePrompts.${String(e)}`}function u7(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function vye(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function yye(e){let{from:t,to:n,content:r}=e,i=n.map(e=>t.findIndex(t=>t.name===e.name)),a=[],o={},s={};for(let[e,t]of Object.entries(r.promptTemplates))u7(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))u7(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=l7(t),l=i[t]??-1;if(l>=0){let t=l7(l);Object.hasOwn(r.promptTemplates,t)&&(o[n]=r.promptTemplates[t]??null);let i=e.rendered[t];i!==void 0&&(s[n]=i);continue}let u=e.body(c.name);if(u===void 0){a.push({field:`imagePrompts.${String(t)}.name`,message:`The image prompt "${c.name}" is not in the Library any more. Untick it under Images, or add it back on Library → Prompts.`});continue}o[n]=u,s[n]=mq(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=u7(r.imageDefinitions[e]?.templateKey);n===void 0||n>=t.length||c.set(n,[...c.get(n)??[],e])}let l={},u=[],d=[],f=(e,t)=>{let n=l7(e),r=o[n];return t===void 0?{source:`generate`,assetId:null,prompt:s[n]??null,templateKey:r==null?null:n}:{...t,source:`generate`,assetId:null,templateKey:t.templateKey??null}},p=(t,n,r)=>Array.from({length:Math.max(0,n)},()=>{let n=e.key();return l[n]=f(t,r),u.push(n),n}),m=[];for(let e of r.imageOrder){let a=r.imageDefinitions[e];if(a===void 0)continue;let o=u7(a.templateKey);if(o===void 0||o>=t.length){l[e]=a,m.push(e);continue}let s=i.indexOf(o);if(s===-1){d.push(e);continue}let u=c.get(o)??[],f=t[o]?.number!==n[s]?.number,h=f?n[s]?.number??0:u.length,g=u.indexOf(e);if(g>=h){d.push(e);continue}let _=a.templateKey===l7(s)?a:{...a,templateKey:l7(s)};l[e]=_,m.push(e),f&&g===Math.min(u.length,h)-1&&m.push(...p(s,h-u.length,_))}for(let[e,r]of n.entries()){let n=i[e]??-1,a=n>=0?c.get(n)??[]:[];n>=0&&(a.length>0||t[n]?.number===r.number)||m.push(...p(e,r.number,void 0))}return{ok:!0,content:{...r,imageOrder:m,imageDefinitions:l,promptTemplates:o},rendered:s,added:u,removed:d}}function bye({edit:e,saved:t,prompts:n,problem:r,onChange:i}){let{config:a}=e;if(a.sources.images!==`generate`)return null;let o=n.filter(e=>e.kind===`image`);return(0,h.jsxs)(`section`,{"aria-label":`Image prompts`,className:`space-y-3`,children:[(0,h.jsx)(Y3,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(xye,{edit:e,saved:t,prompts:o,problem:r})]})}function xye({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(vye(t,i))return a===void 0?null:(0,h.jsx)(d7,{children:a});let o=0,s=yye({from:t,to:i,content:e.content,rendered:e.config.rendered,values:e.config.values,body:e=>n.find(t=>t.name===e)?.body,key:()=>`planned-${String(++o)}`});if(!s.ok)return(0,h.jsx)(d7,{children:s.fields.map(e=>e.message).join(` `)});let c=e=>`${String(e)} ${e===1?`image`:`images`}`,l=[...s.added.length>0?[`adds ${c(s.added.length)} to make`]:[],...s.removed.length>0?[`removes ${c(s.removed.length)}`]:[]];return(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsx)(d7,{children:a}),(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.length===0?`Saving keeps every image as it is.`:`Saving ${l.join(` and `)}. The other images are kept; the new ones are made when you remake outdated outputs.`})]})}function d7({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function Sye({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:iA(r)),o=r?.source===`upload`?[...Zk,`upload`]:Zk,s=i===void 0?[]:[...Tye(i)];return(0,h.jsx)(A2,{value:i,inherit:`None`,sources:o,offerNone:!1,problem:e=>t(`ambientBed.${e}`)??s.find(t=>t.field===e)?.message,onChange:t=>{a(t);let r=aA(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function Cye({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...tk,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(k6,{value:i,problem:e=>t(`loudness.${e}`),onChange:t=>{a(t);let{loudness:r,...i}=e.config;n({...e,config:t.enabled?{...i,loudness:{videoLufs:t.videoLufs,audioFilesLufs:t.audioFilesLufs}}:i})}})}function wye({edit:e,problem:t,onChange:n}){let[r,i]=(0,m.useState)(()=>({sentencePauseSeconds:String(e.config.sentencePauseSeconds??0),paragraphPauseSeconds:String(e.config.paragraphPauseSeconds??0)}));if(e.config.sources.audio!==`generate`)return null;let a=e=>{let t=F6(r[e]);return t===void 0?`Enter a number of seconds.`:bk(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(P6,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=F6(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function Tye(e){let t=aA(e);return t===void 0?[]:nA(t)}function Eye({edit:e,problem:t,onChange:n}){let r=(0,m.useId)(),{config:i}=e,a=i.imageScale,[o,s]=(0,m.useState)(()=>a===void 0?void 0:XO(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(qO(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=f7(t);l!==void 0&&n({...e,config:{...o,imageScale:{perHour:l,words:c},...a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})},u=i.imagePrompts.reduce((e,t)=>e+t.number,0),d=a===void 0?u:$O(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:f7(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(JO(c))))} minutes of narration: ${String(d)} images${d>u?`, ${String(d-u)} more than the prompts' ${String(u)}`:`, which the prompts' Numbers already cover`}.`},g=t(`imageScale`)??void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:[(0,h.jsx)(kb,{checked:o!==void 0,label:`More images for long videos`,describedBy:`${r}-line`,tip:`play.image-scale`,onChange:e=>l(e?{every:`minutes`,value:`2`}:void 0)}),o===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,value:o.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>l({every:e,value:Dye(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{"aria-label":o.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`w-[72px] tabular-nums`,"aria-invalid":p?.problem===!0,"aria-describedby":`${r}-line`,value:o.value,onChange:e=>l({every:o.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:o.every===`minutes`?`minutes`:`images per hour`})]}),g===void 0&&p===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:g!==void 0||p?.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:g??p?.text})]})}function f7(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?YO(t):void 0:t>=1&&t<=240?t:void 0}function Dye(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function Oye({edit:e,onChange:t}){let{config:n}=e;return n.sources.images!==`generate`||n.sources.article===`off`?null:(0,h.jsx)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,config:{...a,...r?{imageScenes:!0}:{}}})}})})}function kye({edit:e,view:t,imageKey:n,index:r}){let{api:i}=z(),a=e.content.imageDefinitions[n];if(a===void 0)return null;let o=t?.outputs.filter(e=>e.output.stageKind===`images`&&e.output.role===`image`)??[],s=o.find(e=>e.selected&&e.workKey===`image:${n}`),c=e.uploads?.some(e=>e.destination.kind===`image`&&e.destination.imageKey===n)??!1,l=a.source===`generate`||c||s?.assetId===a.assetId?s:o.find(e=>e.assetId===a.assetId&&e.available),u=l?.available===!0,d=!u&&(l!==void 0||a.source===`provide`&&a.assetId!==null),f=e.regenerate?.includes(`image:${n}`)===!0,p=c?u?`Replacement ready to save; previous image shown until Save`:`Replacement ready to save; preview available after Save`:f?`Made again after you press Save changes; the current image stays until then`:d?`Image file unavailable`:u?a.source===`provide`&&l!==s?`Provided image selected`:l.state===`review`?`Image retained; review required`:l.state===`outdated`?`Outdated image retained until rebuilt`:`Current image retained`:`No completed image yet`,m=u&&/\.(mp4|mov|m4v|webm|mkv)$/i.test(l.output.path);return(0,h.jsxs)(h.Fragment,{children:[!u||t===void 0?null:m?(0,h.jsx)(R0,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(z0,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}function p7(e,t,n){let r=t+n,i=e[t],a=e[r];if(i===void 0||a===void 0)return e;let o=[...e];return o[t]=a,o[r]=i,o}function Aye({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),{content:c}=e,l=KO(e.config),u=(0,m.useRef)(e);u.current=e;function d(e){let n=e.content.imageOrder.flatMap(t=>{let n=e.content.imageDefinitions[t];return n===void 0?[]:[n]}),r=e.content.imageOrder.length===0||e.config.sources.images===`off`?`off`:n.some(e=>e.source===`generate`)?`generate`:`provide`,i={...e,config:{...e.config,sources:{...e.config.sources,images:r,...r===`off`?{video:`off`}:{}}}};u.current=i,t(i)}function f(e,t){let n=i?.()??u.current,r=n.content.imageDefinitions[e];if(r===void 0)return;let a=r.templateKey??`image:${e}`;s(t=>({...t,[e]:(t[e]??0)+1})),d(A5({...n,...n.uploads===void 0?{}:{uploads:n.uploads.filter(t=>t.destination.kind!==`image`||t.destination.imageKey!==e)},content:{...n.content,imageDefinitions:{...n.content.imageDefinitions,[e]:{...r,templateKey:a}}}},a,t))}function p(e){let t=i?.()??u.current,n=t.content,r=crypto.randomUUID();d({...t,config:{...t.config,sources:{...t.config.sources,images:t.config.sources.images===`off`?`provide`:t.config.sources.images}},content:{...n,imageOrder:[...n.imageOrder,r],imageDefinitions:{...n.imageDefinitions,[r]:{source:`provide`,assetId:null,prompt:null}}},uploads:[...t.uploads??[],{stagedFileId:e.id,destination:{kind:`image`,imageKey:r}}]})}return(0,h.jsxs)(`section`,{"aria-label":`Edit images`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Images`}),(0,h.jsx)(V,{id:`project.images.editor`})]}),c.imageOrder.map((t,s)=>{let l=c.imageDefinitions[t];return l===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(kye,{edit:e,view:r,imageKey:t,index:s}),l.source===`generate`?(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${t}-prompt`,children:[`Prompt for image `,s+1]}),(0,h.jsx)(V,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${t}-prompt`,value:l.templateKey===void 0||l.templateKey===null?l.prompt??``:c.promptTemplates[l.templateKey]??l.prompt??``,onChange:e=>f(t,e.target.value)})]}):null,l.source===`generate`&&l.templateKey==null?(0,h.jsxs)(R,{type:`button`,onClick:()=>f(t,l.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(j5,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??u.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&d({...n,regenerate:(n.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:[...(n.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t),{stagedFileId:e.id,destination:{kind:`image`,imageKey:t}}],content:{...r,imageDefinitions:{...r.imageDefinitions,[t]:{...a,source:`provide`,prompt:null,templateKey:null}}}})}},`${t}:${o[t]??0}:${e.config.sources.images===`off`}`),(0,h.jsxs)(R,{type:`button`,disabled:s===0,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(R,{type:`button`,disabled:s===c.imageOrder.length-1,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(R,{type:`button`,onClick:()=>{let n=c.imageOrder.filter(e=>e!==t);d({...e,config:n.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...c,imageOrder:n,imageDefinitions:Object.fromEntries(Object.entries(c.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t)})},children:[`Delete image `,s+1,c.imageOrder.length===1?` and turn Images and Video Off`:``]}),l.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(V,{id:`project.images.regenerate`})]}):null]},t)}),(0,h.jsx)(R,{type:`button`,disabled:c.imageOrder.length>=l,onClick:()=>{if(c.imageOrder.length>=l)return;let t=crypto.randomUUID();d({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...c,imageOrder:[...c.imageOrder,t],promptTemplates:{...c.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...c.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),c.imageOrder.length>=l?(0,h.jsxs)(`p`,{children:[`At most `,l,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(j5,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:p},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(j5,{label:`Add a video clip`,kind:`images`,accept:`video/mp4,video/quicktime,video/webm,video/x-matroska,.mp4,.mov,.m4v,.webm,.mkv`,onPending:e=>n(`clip:new`,e),onReady:p},`new-clip:${e.config.sources.images===`off`}`)]})]})}var jye=q({logicalKey:W().min(1),logicalText:W(),segment:J([`body`,`intro`,`outro`]),text:W()});function Mye(e,t){if(t==null)return e;let n=[...t.intro??[],...t.body??[],...t.outro??[]];return n.length===0?e:n.flatMap(t=>e.filter(e=>e.key===t))}function Nye(e){let t=new Map,n=new Set,r=0;for(let i of e.pieces){if(!i.selected||i.stageKind!==`audio`||i.piece.kind!==`chunk`)continue;let e;try{e=i.piece.payload===null?null:JSON.parse(i.piece.payload)}catch{r++;continue}let a=jye.safeParse(e);if(!a.success){r++;continue}let{logicalKey:o,logicalText:s}=a.data;if(n.has(o)){r++;continue}let c=t.get(o);if(c!==void 0&&c.text!==s){r+=c.parts+1,t.delete(o),n.add(o);continue}t.set(o,{key:o,text:s,parts:(c?.parts??0)+1})}return{groups:[...t.values()],unmapped:r}}function Pye({view:e,edit:t,onChange:n,onPending:r,getEdit:i}){let a=(0,m.useId)(),{api:o}=z(),s=N({queryKey:[`narration-chunks`,e.revision.projectId,e.revision.id],queryFn:async()=>{let t=await xfe(o,e.revision.projectId,e.revision.id);return t.ok?t.value.chunks:null},staleTime:1/0}),c=Nye(e),l=Mye(c.groups,s.data),u=c.unmapped,d=(0,m.useRef)(t);d.current=t;let[f,p]=(0,m.useState)({});function g(e){d.current=e,n(e)}return(0,h.jsxs)(`section`,{"aria-label":`Edit narration`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Narration`}),(0,h.jsx)(V,{id:`project.narration.editor`})]}),t.config.chunking?.mode===`whole`||t.config.chunking===void 0?(0,h.jsx)(`p`,{children:`This narration uses one whole request. Editing its text rebuilds the whole narration request.`}):null,u===0?null:(0,h.jsx)(`p`,{children:`Some older audio cannot be matched reliably to its narration text. Replace the provided narration or rebuild from the article to edit those chunks.`}),l.map((e,n)=>{let o=t.content.narrationOverrides[e.key];return(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Narration chunk `,n+1]}),(0,h.jsxs)(`p`,{children:[e.parts,` audio `,e.parts===1?`part`:`parts`,` in this narration chunk.`]}),(0,h.jsxs)(`div`,{className:`text-small`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.key}-text`,children:[`Text for narration chunk `,n+1]}),(0,h.jsx)(V,{id:`project.narration.chunk-text`,label:`text for narration chunk ${String(n+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${e.key}-text`,value:o?.kind===`text`?o.text:e.text,onChange:n=>{p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,...t.uploads===void 0?{}:{uploads:t.uploads.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key)},content:{...t.content,narrationOverrides:{...t.content.narrationOverrides,[e.key]:{kind:`text`,text:n.target.value}}}})}})]}),(0,h.jsx)(j5,{label:`Replace narration chunk ${n+1}`,kind:`audio`,onPending:t=>r(`narration:${e.key}`,t),onReady:t=>{let n=i?.()??d.current;g({...n,regenerate:(n.regenerate??[]).filter(t=>t!==e.key),uploads:[...(n.uploads??[]).filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),{stagedFileId:t.id,destination:{kind:`narration`,key:e.key}}]})}},`${e.key}:${f[e.key]??0}`),t.regenerate?.includes(e.key)?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Narration chunk `,n+1,` will be regenerated after you save and press Remake.`,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:()=>{let t=i?.()??d.current;g({...t,regenerate:(t.regenerate??[]).filter(t=>t!==e.key)})},children:[`Keep narration chunk `,n+1]})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(R,{type:`button`,onClick:()=>{let t=i?.()??d.current,n={...t.content.narrationOverrides};n[e.key]?.kind===`asset`&&delete n[e.key],p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,content:{...t.content,narrationOverrides:n},uploads:t.uploads?.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),regenerate:[...new Set([...t.regenerate??[],e.key])]})},children:[`Regenerate narration chunk `,n+1,` after review`]}),(0,h.jsx)(V,{id:`project.narration.regenerate`})]})]},e.key)})]})}function Fye(e){let{config:t,fingerprints:n}=e.revision;if(t.sources.audio===`off`)return;let r=t.sources.audio===`provide`?[{key:`audio:provided`,role:`audio_body`}]:[...t.intro===void 0?[]:[{key:`audio:intro`,role:`audio_intro`}],{key:`audio:body:concat`,role:`audio_body`},...t.outro===void 0?[]:[{key:`audio:outro`,role:`audio_outro`}]],i=e.outputs.filter(e=>e.selected&&e.state===`ready`&&e.available&&e.fingerprint===n[e.workKey]),a=r.map(({key:e,role:t})=>i.find(n=>n.workKey===e&&n.output.role===t));if(a.some(e=>e===void 0))return;let o=a.map(e=>e?.output.durationMs);if(o.every(m7))return o.reduce((e,t)=>e+t,0)/1e3+Math.max(0,r.length-1)*t.silenceGapSeconds+2*t.edgeSilenceSeconds;let s=i.find(e=>(e.output.role===`audio_export`||e.output.role===`video`)&&m7(e.output.durationMs))?.output.durationMs;return m7(s)?s/1e3:void 0}function m7(e){return e!=null&&Number.isFinite(e)&&e>0}function Iye({edit:e,prompts:t,problem:n,onChange:r,onPending:i,getEdit:a}){let{config:o}=e;if(o.sources.images!==`generate`)return null;let s=o.reference,c=s===void 0?v6:{source:s.source,prompt:s.prompt??``,thumbnail:s.thumbnail!==!1},l=e=>({...e,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`provided`||e.destination.stage!==`reference`)});return(0,h.jsx)(`section`,{"aria-label":`Establishing image`,className:`space-y-3`,children:(0,h.jsx)(y6,{value:c,prompts:t,problem:n,onChange:n=>{let{reference:i,...a}=o;if(n.source===`off`){r(l({...e,config:a}));return}let s={source:n.source,...n.source===`prompt`?{prompt:n.prompt}:{},...n.thumbnail?{}:{thumbnail:!1}},u=n.source===`prompt`&&n.prompt!==c.prompt?t.find(e=>e.kind===`image`&&e.name===n.prompt):void 0,d={...e,config:{...a,reference:s}},f=u===void 0?d:A5(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(j5,{label:e.content.provided.reference===void 0?`Upload the establishing image`:`Replace the establishing image`,kind:`images`,accept:`image/png,image/jpeg`,onPending:i,onReady:t=>{let n=l(a?.()??e);n.config.reference?.source===`provide`&&r({...n,uploads:[...n.uploads??[],{stagedFileId:t.id,destination:{kind:`provided`,stage:`reference`}}]})}})})})}var Lye=q({words:K(q({text:W().trim().min(1),start:G().finite().nonnegative(),end:G().finite().positive(),confidence:G().optional(),speaker:W().min(1).optional()})).min(1)});function h7(e){let{config:t,content:n}=e;return JSON.stringify({source:t.sources.audio,audio:n.provided.audio,uploads:e.uploads?.filter(e=>e.destination.kind===`narration`||e.destination.kind===`provided`&&e.destination.stage===`audio`)??[],edge:t.edgeSilenceSeconds,...t.sources.audio===`generate`?{choice:t.audio,chunking:t.chunking,article:n.articleMarkdown??t.provided.article,articleSource:t.sources.article,renderedArticle:t.rendered.article,intro:t.intro,outro:t.outro,renderedIntro:t.rendered.intro,renderedOutro:t.rendered.outro,gap:t.silenceGapSeconds,overrides:n.narrationOverrides,regenerate:e.regenerate?.filter(e=>/^(audio:|article:|entry:)/.test(e))??[]}:{}})}function Rye({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=z(),s=N(nb(o)).data?.prompts??[],c=h7(t),l=t.config.sources.audio!==`off`&&c===h7({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?Fye(e):void 0,f=d!==void 0&&u!==void 0&&u!==``,p=(0,m.useRef)({edit:t,onChange:r,revisionId:e.revision.id,identity:c});p.current={edit:t,onChange:r,revisionId:e.revision.id,identity:c};let g=(0,m.useRef)(i);g.current=i;let[_,v]=(0,m.useState)(new Set),[y,b]=(0,m.useState)(),x=(0,m.useRef)(void 0),S=(0,m.useRef)(!0),C=(0,m.useCallback)((e,t)=>{S.current&&v(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,m.useEffect)(()=>{g.current(_.size>0)},[_]),(0,m.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&x.current?.abort()}},[e.revision.id,c]);function w(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:h7(e)},t(e)}async function T(){if(x.current!==void 0)return;let t=new AbortController;x.current=t;let n=p.current;C(`captions:load`,!0),b(void 0);try{let r=e.outputs.find(e=>e.selected&&e.state===`ready`&&e.output.role===`subtitle_words`&&e.available);if(!f||d===void 0||u===void 0||r===void 0)throw Error(`Captions can't be edited until the current narration has finished and its subtitle timing is ready.`);let i=await o.fetch(s2(o,e.revision.projectId,e.revision.id,r.recordId),{signal:t.signal});if(!i.ok)throw Error(`The subtitle timing file couldn't be read. Reload the page and try again; if it still fails, use More → make it again in its section on Audio.`);let a=Lye.parse(await i.json()),s=0;for(let e of a.words){if(e.start<s||e.end<=e.start||e.end>d)throw Error(`The saved subtitle timing doesn't match the current narration. Use More → make it again in its section on Audio to rebuild it.`);s=e.end}let c=gye(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!S.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;w({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){S.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{x.current===t&&(x.current=void 0),C(`captions:load`,!1)}}let E=t.content.subtitleCues,D=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!D(`images`),className:`space-y-6`,children:[(0,h.jsx)(bye,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(Eye,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(Oye,{edit:t,onChange:w}),(0,h.jsx)(Iye,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:w,onPending:e=>C(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(I6,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;w({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(j5,{label:`Replace provided ${e}`,kind:e,onPending:t=>C(`provided:${e}`,t),onReady:t=>{let n=p.current;n.edit.config.sources[e]===`provide`&&w({...n.edit,uploads:[...(n.edit.uploads??[]).filter(t=>t.destination.kind!==`provided`||t.destination.stage!==e),{stagedFileId:t.id,destination:{kind:`provided`,stage:e}}]})}},e):null),(0,h.jsx)(Aye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!D(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(Pye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!D(`captions`),className:`space-y-5`,children:[f?null:(0,h.jsx)(`p`,{children:`Captions can be edited once the current narration has finished and its subtitle timing is ready.`}),E===void 0?(0,h.jsx)(R,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void T(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[E.audioFingerprint===u?null:(0,h.jsx)(`p`,{children:`These caption edits belong to an earlier narration. Review their text and timing against the current narration, then apply your corrections and save the project.`}),f&&d!==void 0?(0,h.jsx)(_ye,{cues:E.cues,duration:d,onPending:e=>C(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&w({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(R,{type:`button`,onClick:()=>w({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function zye({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(k2,{value:e.config.language,error:t,onChange:t=>{let{language:r,...i}=e.config;n({...e,config:t===void 0||t===`en`?i:{...i,language:t}})}})})}function Bye({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=z(),a=N(Zb(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:Wb,c=s(o.channelId),l=a.data?.find(e=>e.id===c),u=o.useBrandKit!==!1,d=c!==s(t.channelId),f=u!==(t.useBrandKit!==!1);return(0,h.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(TV,{value:c,onChange:t=>r({...e,config:{...o,channelId:t.target.value}}),children:[a.data===void 0?(0,h.jsx)(`option`,{value:c,children:`Loading channels…`}):null,(a.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col justify-end gap-1`,children:[(0,h.jsx)(kb,{checked:u,label:`Use the channel's brand kit`,tip:`play.brand-kit`,onChange:t=>{let{useBrandKit:n,...i}=o;r({...e,config:t?i:{...i,useBrandKit:!1}})}}),u?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Its cast is still used.`})]}),a.error===null?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-danger md:col-span-2`,children:[`The channels couldn't be loaded: `,a.error.message,`. Reload the page to pick a channel.`]}),d||f?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:[d?`Saving moves the project to this channel and takes its cast as it is now. `:``,u?`The brand kit fills the caption font and colours, title style, end screen, intro, outro and document theme where they are at their default or were set by the old kit.`:`What the old brand kit had set is taken off.`]}):null]})}function Vye(e,t,n){let r=e.outputs.find(e=>e.selected&&e.available&&e.output.role===`reference`);if(t.config.reference!==void 0&&r!==void 0)return{image:{kind:`output`,outputId:r.output.id},drawnOn:`the establishing image`};let i=n.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),a=W6([t.config.title,...Object.values(t.config.values??{})].join(` `),i)[0]??i[0],o=a?.images[0];if(a!==void 0&&o!==void 0)return{image:{kind:`picture`,sha256:o},drawnOn:`${a.name}'s picture`}}function Hye({edit:e,view:t,prompts:n,error:r,onChange:i}){let a=(0,m.useRef)(e.config.narrationPrompt);if(e.config.sources.audio!==`generate`)return null;let o=t.revision.config.narrationPrompt,s=t.revision.content.promptTemplates.narration??t.revision.config.rendered.narration,c=o&&s!==void 0&&!n.some(e=>e.kind===`narration`&&e.name===o)?[...n,{id:`saved-narration`,kind:`narration`,name:o,body:s,slots:[],updatedAt:t.revision.createdAt}]:n;return(0,h.jsx)(g6,{value:e.config.narrationPrompt??``,prompts:c,libraryLinks:!1,supported:e.config.audio?.provider===`inworld`&&e.config.audio.model===`inworld-tts-2`,error:r,onChange:t=>{let n=e.config.narrationPrompt||a.current;t===``&&(a.current=e.config.narrationPrompt);let r=c.find(e=>e.kind===`narration`&&e.name===t),o=r===void 0||t===n?e:A5(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function Uye({edit:e,saved:t=e.config.imagePrompts,prompts:n,entries:r,onChange:i}){let a=(0,m.useId)(),o=[...new Set([...Object.keys(e.config.rendered),...Object.keys(e.content.promptTemplates),...e.config.sources.article===`generate`?[`article`]:[],...uj(e.config)?[`narration`]:[],...pj(e.config)&&e.config.descriptionPrompt?[`description`]:[],..._j(e.config)&&e.config.shorts?.prompt?[`shorts`]:[],..._j(e.config)&&e.config.shorts?.imagePrompt?[`shortsImage`]:[],...[`from_prompt`,`prompt_by_llm`].includes(e.config.sources.thumbnail)?[`thumbnailPrompt`]:[],...hj(e.config)&&e.config.reference?.source===`prompt`?[`referencePrompt`]:[],...e.config.intro===void 0?[]:[`intro`],...e.config.outro===void 0?[]:[`outro`]])].filter(n=>{let r=y7(n);if(r===void 0)return!0;let i=t[r]?.name;return i===void 0||e.config.imagePrompts.some(e=>e.name===i)}),s=e.config.imagePrompts.filter(e=>!t.some(t=>t.name===e.name)),c=e=>Kye(e,t),l=[...new Set([...Object.keys(e.config.values),...Object.values(e.content.promptTemplates).flatMap(e=>e===null?[]:dq(e).names)])].filter(e=>!fq.includes(e)),u=t=>[...dq(e.config.title).names.includes(t)?[`Project title`]:[],...Object.entries(e.content.promptTemplates).flatMap(([e,n])=>n!==null&&dq(n).names.includes(t)?[c(e)]:[])],d=dq(e.config.title).names;return(0,h.jsxs)(`section`,{"aria-label":`Prompt snapshots`,className:`space-y-6`,children:[o.map(o=>{let s=c(o),l=e.content.promptTemplates[o]??null,u=o===`intro`||o===`outro`?r.filter(e=>e.category===o):n.filter(t=>t.kind===(o===`article`?UA(e.config)?`script`:`article`:o===`narration`?`narration`:o===`description`?`description`:o===`shorts`?`shorts`:o===`thumbnailPrompt`?`thumbnail`:`image`));return(0,h.jsxs)(`div`,{className:`min-w-0 space-y-4 border-t border-line pt-6 first:border-t-0 first:pt-0`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:s}),l===null?(0,h.jsx)(SI,{tone:`info`,title:`Original template unavailable`,actions:(0,h.jsx)(R,{"aria-label":`Use saved wording as template for ${s}`,onClick:()=>i(A5(e,o,e.config.rendered[o]??``)),children:`Use saved wording as template`}),children:`The saved prompt below stays as it is until you choose or write a template.`}):null,(0,h.jsx)(Gye,{label:s,raw:l,library:Wye(e,o,u,t),onUse:t=>i(A5(e,o,t))}),(0,h.jsx)(xV,{label:`Use saved template for ${s}`,id:`${a}-library-${o}`,tip:`project.prompts.template`,children:(0,h.jsxs)(TV,{value:``,onChange:t=>{let n=u.find(e=>e.id===t.target.value);if(n===void 0)return;let r=A5(e,o,n.body),a=`category`in n?{...r.config,[n.category]:{name:n.name,mode:n.mode}}:o===`article`?{...r.config,articlePrompt:n.name}:o===`narration`?{...r.config,narrationPrompt:n.name}:o===`description`?{...r.config,descriptionPrompt:n.name}:(o===`shorts`||o===`shortsImage`)&&r.config.shorts!==void 0?{...r.config,shorts:{...r.config.shorts,[o===`shorts`?`prompt`:`imagePrompt`]:n.name}}:o===`thumbnailPrompt`?{...r.config,thumbnailPrompt:n.name}:o===`referencePrompt`&&r.config.reference!==void 0?{...r.config,reference:{...r.config.reference,prompt:n.name}}:r.config;i({...r,config:a})},children:[(0,h.jsx)(`option`,{value:``,children:`Choose a saved template`}),u.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,h.jsx)(xV,{label:`Raw prompt for ${s}`,id:`${a}-raw-${o}`,tip:`project.prompts.raw`,children:(0,h.jsx)(wV,{rows:4,value:l??``,onChange:t=>i(A5(e,o,t.target.value))})}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`text-small text-ink-2`,children:`Saved rendered prompt`}),(0,h.jsx)(`pre`,{className:`m-0 mt-2 whitespace-pre-wrap break-words text-small`,children:e.config.rendered[o]??``})]})]},o)}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s.map(e=>`"${e.name}"`).join(`, `),` `,s.length===1?`uses its`:`use their`,` Library wording. Save, then change it here.`]}),l.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`space-y-3 pt-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:`Keywords`}),(0,h.jsx)(_0,{fieldPrefix:`config.values`,keywords:l.map(t=>({name:t,value:e.config.values[t]??``,feeds:u(t),topic:d.includes(t)})),onChange:(t,n)=>i(k5({...e,config:{...e.config,values:{...e.config.values,[t]:n}}}))})]}):null]})}function Wye(e,t,n,r){let{config:i}=e,a=y7(t);if(t===`intro`||t===`outro`){let e=i[t]?.name;return e===void 0||e===``?void 0:n.find(t=>`category`in t&&t.name===e)}let o=t===`article`?i.articlePrompt:t===`narration`?i.narrationPrompt:t===`description`?i.descriptionPrompt:t===`shorts`?i.shorts?.prompt:t===`shortsImage`?i.shorts?.imagePrompt:t===`thumbnailPrompt`?i.thumbnailPrompt:t===`referencePrompt`?i.reference?.prompt:a===void 0?void 0:r[a]?.name;if(o!==void 0&&o!==``)return n.find(e=>!(`category`in e)&&e.name===o)}var g7=`slopify.library-kept`;function _7(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t*33^e.charCodeAt(n))>>>0;return t.toString(36)}function v7(){try{let e=window.localStorage.getItem(g7),t=e===null?[]:JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Gye({label:e,raw:t,library:n,onUse:r}){let i=n===void 0||t===null?``:`${e}:${_7(t)}:${_7(n.body)}`,[a,o]=(0,m.useState)(()=>v7().includes(i));return n===void 0||t===null||n.body===t||a?null:(0,h.jsx)(SI,{tone:`info`,title:`The Library's "${n.name}" has changed since this project copied it`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{"aria-label":`Use the Library version for ${e}`,onClick:()=>{r(n.body)},children:`Use the Library version`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Keep this project's version for ${e}`,onClick:()=>{try{window.localStorage.setItem(g7,JSON.stringify([...v7().filter(e=>e!==i),i].slice(-200)))}catch{}o(!0)},children:`Keep this project's version`})]}),children:`The project uses its own copy below until you choose. Using the Library version marks what it wrote as outdated, to remake when you are ready.`})}function y7(e){let t=/^imagePrompts\.(\d+)$/.exec(e);return t?.[1]===void 0?void 0:Number(t[1])}function Kye(e,t){if(e===`article`)return`Article`;if(e===`narration`)return`Narration Preparation`;if(e===`description`)return`YouTube description`;if(e===`shorts`)return`Shorts`;if(e===`shortsImage`)return`Shorts image style`;if(e===`thumbnailPrompt`)return`Thumbnail`;if(e===`referencePrompt`)return`Establishing image`;if(e===`intro`)return`Intro`;if(e===`outro`)return`Outro`;let n=y7(e);if(n!==void 0){let e=t[n]?.name;return e===void 0||e===``?`Image prompt ${String(n+1)}`:`Image prompt "${e}"`}return e.replace(/[._-]/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`)}function qye(e,t,n){let{api:r}=z(),[i,a]=(0,m.useState)({busy:!1}),{config:o}=t,s=o.audio,c=async()=>{if(s!==void 0){a({busy:!0});try{let i=await Rs(r,e),{sharedGlossary:c,...l}=o;n({...t,config:{...l,audio:{...s,shareGlossary:!0},...i.entries.length===0?{}:{sharedGlossary:i.entries}}}),a({busy:!1,projects:i.projects})}catch(e){a({busy:!1,error:e instanceof Error?e.message:String(e)})}}},l=()=>{if(s===void 0)return;let{sharedGlossary:e,...r}=o;n({...t,config:{...r,audio:{...s,shareGlossary:!1}}})},u=o.sharedGlossary?.length??0,d=s?.shareGlossary===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[i.error===void 0?u===0?`No pronunciations from other projects are copied yet.`:`${String(u)} ${u===1?`term`:`terms`} copied from ${i.projects===void 0?`your other projects`:`${String(i.projects)} other ${i.projects===1?`project`:`projects`}`}.`:`Couldn't read your other projects' pronunciations: ${i.error}`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:i.busy,onClick:()=>void c(),children:i.busy?`Copying…`:`Update from other projects`}),(0,h.jsx)(V,{id:`project.edit.update-glossary`})]}):void 0;return{value:s?.shareGlossary===!0,onChange:e=>{e?c():l()},note:d}}function Jye(e,t){let{api:n}=z(),[r,i]=(0,m.useState)({busy:!1}),{config:a}=e,o=a.audio,s=async()=>{if(o!==void 0){i({busy:!0});try{let{aliases:r}=await zs(n),{narrationAliases:s,...c}=a;t({...e,config:{...c,audio:{...o,useNarrationAliases:!0},...r.length===0?{}:{narrationAliases:r}}}),i({busy:!1})}catch(e){i({busy:!1,error:e instanceof Error?e.message:String(e)})}}},c=a.narrationAliases?.length??0;return{value:o?.useNarrationAliases===!0,onChange:n=>{if(o!==void 0){if(n)s();else{let{narrationAliases:n,...r}=a;t({...e,config:{...r,audio:{...o,useNarrationAliases:!1}}})}}},note:o?.useNarrationAliases===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[r.error===void 0?c===0?`No aliases are copied yet. Add some in Library → Aliases.`:`${String(c)} ${c===1?`alias`:`aliases`} copied from Library → Aliases.`:`Couldn't read Library → Aliases: ${r.error} Try Update from Library again.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r.busy,onClick:()=>void s(),children:r.busy?`Copying…`:`Update from Library`}),(0,h.jsx)(V,{id:`project.edit.update-aliases`})]}):void 0}}function Yye({projectId:e,edit:t,providers:n,voices:r,onChange:i}){let{config:a}=t,o=a.llm??{provider:``,model:``},s=a.audio??{provider:``,model:``,voice:``},c=qye(e,t,i),l=Jye(t,i),{api:u}=z(),d=N(Qb(u,a.channelId??`00000000-0000-4000-8000-000000000001`)),f=a.images??{provider:``,model:``},p=uj(a)||a.sources.audio===`generate`&&a.audio?.describeFigures===!0||a.sources.research===`generate`||a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||HA(a)&&a.voices?.source===`attribute`||a.sources.audio===`generate`&&(a.intro?.mode===`llm`||a.outro?.mode===`llm`),m=a.sources.images===`generate`||a.sources.thumbnail===`from_prompt`||a.sources.thumbnail===`prompt_by_llm`,g=r.filter(e=>e.provider===s.provider).map(e=>({value:e.voiceId,label:e.name}));return(0,h.jsxs)(`section`,{"aria-label":`Generation providers`,className:`grid min-w-0 gap-3 sm:grid-cols-2`,children:[p?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Text provider`,tip:`play.llm.provider`,family:`llm`,providers:n,value:o.provider,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Text model`,tip:`play.llm.model`,provider:o.provider,value:o.model,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{...o,model:e}}})}),(0,h.jsx)(b6,{choice:o,onChange:e=>i({...t,config:{...a,llm:e}})})]}):null,a.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[a.voices!==void 0&&a.intro===void 0&&a.outro===void 0?null:(0,h.jsxs)(h.Fragment,{children:[a.voices===void 0?null:(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`The voice below reads only the intro and outro. Each speaker's voice is set under Speakers.`}),(0,h.jsx)(RV,{label:a.voices===void 0?`Narration provider`:`Intro and outro provider`,tip:`play.tts.provider`,family:`tts`,providers:n,value:s.provider,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,provider:e,model:``,voice:``}}})}),(0,h.jsx)(zV,{label:a.voices===void 0?`Narration model`:`Intro and outro model`,tip:`play.tts.model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,model:e}}})}),(0,h.jsx)(FV,{label:a.voices===void 0?`Narration voice`:`Intro and outro voice`,tip:`play.voice`,value:s.voice,problem:void 0,placeholder:`Choose a saved voice`,options:s.voice!==``&&!g.some(e=>e.value===s.voice)?[{value:s.voice,label:`${s.voice} (saved voice)`},...g]:g,onPick:e=>i({...t,config:{...a,audio:{...s,voice:e}}})})]}),(0,h.jsx)(q3,{value:a.chunking??{mode:`whole`},onPick:e=>i({...t,config:{...a,chunking:e}})}),(0,h.jsx)(_6,{shared:c,value:s.usePronunciationGlossary,supported:Sj({sources:a.sources,audio:{...s,usePronunciationGlossary:!0}}),onChange:e=>i({...t,config:{...a,audio:{...s,usePronunciationGlossary:e}}})}),(0,h.jsx)(h6,{...l}),(0,h.jsx)(p6,{tip:`project.edit.describe-figures`,value:s.describeFigures,skipCode:s.skipCode,onChange:({describeFigures:e,skipCode:n})=>{let{describeFigures:r,skipCode:o,...c}=s;i({...t,config:{...a,audio:{...c,...e?{describeFigures:e}:{},...e&&n?{skipCode:n}:{}}}})}}),(0,h.jsxs)(`section`,{"aria-label":`Speakers`,className:`col-span-full border-t border-line pt-3`,children:[(0,h.jsx)(`h3`,{className:`mb-2 text-small font-semibold`,children:`Speakers`}),(0,h.jsx)(f6,{value:a.voices,cast:d.data?.cast??[],language:a.language,providers:n,voices:r,script:t.content.articleMarkdown??void 0,onChange:e=>{let{voices:n,...r}=a;i({...t,config:e===void 0?r:{...r,voices:e}})}})]})]}):null,m?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Image provider`,tip:`play.images.provider`,family:`image`,providers:n,value:f.provider,problem:void 0,onPick:e=>i({...t,config:{...a,images:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Image model`,tip:`play.images.model`,provider:f.provider,value:f.model,problem:void 0,onPick:e=>i({...t,config:{...a,images:{...f,model:e}}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:f,onChange:e=>i({...t,config:{...a,images:e}})})]}):null]})}function Xye({edit:e,providers:t,prompts:n,problem:r,onChange:i}){let{config:a}=e,o=a.reviews===void 0?HV:jk(a.reviews),[s,c]=(0,m.useState)(o),l=a.shorts?.enabled===!0&&a.sources.audio!==`off`,u=e=>Nk({sources:a.sources,shorts:l?{enabled:!0}:void 0},e),d=Mk(s,u).retriesProblem;return(0,h.jsx)(UV,{value:s,providers:t,prompts:n,makes:u,problem:e=>e===`reviews.retries`&&d!==void 0?d:r(e),onChange:t=>{c(t);let{settings:r}=Mk(t,u),o={...e.content.promptTemplates},s={...a.rendered};for(let e of Ck){let t=Ak(e),i=r?.stages[e]?.prompt??``,c=n.find(e=>e.kind===`review`&&e.name===i);if(i===``){let{[t]:e,...n}=o,{[t]:r,...i}=s;o=n,s=i}else c!==void 0&&i!==(a.reviews?.stages[e]?.prompt??``)&&(o={...o,[t]:c.body})}let{reviews:l,...d}=a;i(k5({...e,config:{...d,rendered:s,...r===void 0?{}:{reviews:r}},content:{...e.content,promptTemplates:o}}))}})}function Zye({edit:e,view:t,prompts:n,problem:r,onChange:i}){let a=t.revision.config.descriptionPrompt,o=t.revision.content.promptTemplates.description??t.revision.config.rendered.description,s=a&&o!==void 0&&!n.some(e=>e.kind===`description`&&e.name===a)?[...n,{id:`saved-description`,kind:`description`,name:a,body:o,slots:[],updatedAt:t.revision.createdAt}]:n,c=t.outputs.some(e=>e.selected&&e.workKey===b7&&e.state===`ready`),l=e.regenerate?.includes(b7)===!0;return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(C6,{enabled:e.config.youtubeDescription===!0,prompt:e.config.descriptionPrompt??``,prompts:s,narrated:e.config.sources.audio!==`off`,problem:r,onChange:({youtubeDescription:t,descriptionPrompt:n})=>{let r=s.find(e=>e.kind===`description`&&e.name===n),a=n===(e.config.descriptionPrompt??``)?e:r===void 0?Qye(e):A5(e,`description`,r.body),{descriptionPrompt:o,...c}=a.config;i({...a,config:{...c,youtubeDescription:t,...n===``?{}:{descriptionPrompt:n}}})}}),c&&e.config.youtubeDescription===!0?l?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The YouTube description will be written again after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>{i({...e,regenerate:(e.regenerate??[]).filter(e=>e!==b7)})},children:`Keep the current description`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>{i({...e,regenerate:[...new Set([...e.regenerate??[],b7])]})},children:`Write the description again after review`}),(0,h.jsx)(V,{id:`project.edit.rewrite-description`})]}):null]})}var b7=`youtube:description`;function Qye(e){let{description:t,...n}=e.content.promptTemplates,{description:r,...i}=e.config.rendered;return k5({config:{...e.config,rendered:i},content:{...e.content,promptTemplates:n}})}var $ye={research:`Research source`,article:`Article source`,audio:`Audio source`,images:`Images source`,thumbnail:`Thumbnail source`,video:`Video source`,document:`Document source`},ebe={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`},tbe=`\0kept:`;function x7({title:e,children:t,columns:n=!0}){return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:e}),(0,h.jsx)(`div`,{className:L(`grid min-w-0 gap-4`,n&&`md:grid-cols-2`),children:t})]})}function nbe(e){let{view:t,edit:n,onChange:r,onPending:i,fields:a}=e,o=(0,m.useId)(),[s,c]=(0,m.useState)(e.focus?.section??`inputs`);(0,m.useEffect)(()=>{e.focus!==void 0&&c(e.focus.section)},[e.focus]);let[l,u]=(0,m.useState)({font:!1,content:!1,music:!1});(0,m.useEffect)(()=>{i(l.font||l.content||l.music)},[i,l]);let d=(0,m.useCallback)(e=>{u(t=>t.font===e?t:{...t,font:e})},[]),f=(0,m.useCallback)(e=>{u(t=>t.content===e?t:{...t,content:e})},[]),p=(0,m.useCallback)(e=>{u(t=>t.music===e?t:{...t,music:e})},[]),{api:g}=z(),_=N(eb(g)),v=N(tb(g)),y=N(nb(g)),b=N(rb(g)),{config:x}=n,S=Vye(t,n,N(Qb(g,x.channelId??`00000000-0000-4000-8000-000000000001`)).data?.cast??[]),C=S?.image.kind===`output`?t.outputs.find(e=>e.selected&&e.available&&S.image.kind===`output`&&e.output.id===S.image.outputId):void 0,w=C===void 0?void 0:s2(g,t.revision.projectId,t.revision.id,C.recordId),T=e=>a.find(t=>t.field===e||t.field===`config.${e}`||t.field===`edit.config.${e}`)?.message,E=w6({value:x.videoEdit,narrated:x.sources.audio!==`off`,imageProvider:x.images?.provider??``,problem:T,language:x.language,onChange:e=>r({...n,config:{...x,videoEdit:e}})}),D=[{id:`inputs`,label:`Inputs`},...x.sources.article===`off`?[]:[{id:`article`,label:`Article`,...n.content.articleEdited?{badge:`edited`}:{}}],{id:`providers`,label:`Providers`},{id:`prompts`,label:`Prompts`},{id:`reviews`,label:`Reviews`,...x.reviews===void 0?{}:{badge:`on`}},...x.sources.audio!==`off`||x.shorts?.enabled===!0?[{id:`shorts`,label:`Shorts`,...x.shorts?.enabled?{badge:`on`}:{}}]:[],...x.sources.article===`off`?[]:[{id:`subtitles`,label:`Subtitles`}],{id:`images`,label:`Images`,badge:String(n.content.imageOrder.length)},...x.sources.audio===`generate`?[{id:`narration`,label:`Narration`}]:[],...x.sources.article===`off`?[]:[{id:`captions`,label:`Captions`,...n.content.subtitleCues===void 0?{}:{badge:String(n.content.subtitleCues.cues.length)}}]],O=D.some(e=>e.id===s)?s:`inputs`,k=e=>L(`min-w-0 space-y-6`,O===e?void 0:`hidden`),A=e=>Number.isFinite(e)?e:``,ee=x.sources.video!==`off`;return(0,h.jsxs)(`div`,{className:`grid min-w-0 gap-8 md:grid-cols-[180px_minmax(0,1fr)]`,children:[(0,h.jsx)(`nav`,{"aria-label":`Edit sections`,className:`min-w-0 md:sticky md:top-16 md:self-start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none gap-1 overflow-x-auto p-0 [scrollbar-width:none] md:flex-col`,children:D.map(e=>(0,h.jsx)(`li`,{className:`shrink-0`,children:(0,h.jsx)(t8,{current:e.id===O,onClick:()=>c(e.id),meta:e.badge,className:`whitespace-nowrap`,children:e.label})},e.id))})}),(0,h.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[Object.entries({providers:_.error,voices:v.error,prompts:y.error,entries:b.error}).flatMap(([e,t])=>t===null?[]:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:t.message},e)]),a.length===0?null:(0,h.jsx)(`ul`,{role:`alert`,className:`m-0 space-y-1 pl-5 text-small text-danger`,children:a.map(e=>(0,h.jsx)(`li`,{children:e.message},`${e.field}-${e.message}`))}),(0,h.jsxs)(`section`,{"aria-label":`Inputs`,hidden:O!==`inputs`,className:k(`inputs`),children:[(0,h.jsxs)(x7,{title:`Project`,children:[(0,h.jsx)(xV,{label:`Project title`,error:T(`title`),className:`md:col-span-2`,children:(0,h.jsx)(CV,{value:x.title,maxLength:200,onChange:e=>r({...n,config:{...x,title:e.target.value}})})}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(U6,{value:x.format,onPick:e=>r({...n,config:{...x,format:e}})})})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Channel`,columns:!1,children:(0,h.jsx)(Bye,{edit:n,saved:t.revision.config,problem:T,onChange:r})}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Stages`,children:[FS.filter(e=>x.sources.article!==`off`||e!==`research`&&e!==`audio`&&e!==`document`).map(e=>(0,h.jsx)(xV,{label:$ye[e],tip:ebe[e],error:T(`sources.${e}`),children:(0,h.jsx)(TV,{value:RS(x.sources,e),onChange:i=>{let a=FN(e).find(e=>e.value===i.target.value);if(a===void 0)return;let o=xve(n,e,a.value);r(e===`article`&&a.value===`provide`&&!n.content.articleEdited?{...o,content:{...o.content,articleMarkdown:t.articleMarkdown??n.content.articleMarkdown}}:o)},children:FN(e).filter(t=>e!==`thumbnail`||t.value!==`prompt_by_llm`||x.sources.article!==`off`).map(t=>(0,h.jsx)(`option`,{value:t.value,disabled:e===`video`&&t.value===`generate`&&x.sources.images===`off`,children:t.label},t.value))})},e)),x.sources.images===`off`?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:`Images are Off. Video is also Off in these changes.`}):null,(0,h.jsx)(xV,{label:`Document theme`,id:`${o}-document-theme`,tip:`play.document-theme`,children:(0,h.jsx)(G3,{id:`${o}-document-theme`,disabled:RS(x.sources,`document`)===`off`,value:x.document,onChange:e=>{r({...n,config:{...x,document:e}})}})})]}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Timing`,children:[(0,h.jsx)(xV,{label:`Silence gap (seconds)`,tip:`play.silence-gap`,error:T(`silenceGapSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.1,value:A(x.silenceGapSeconds),onChange:e=>r({...n,config:{...x,silenceGapSeconds:Number(e.target.value)}})})}),x.sources.audio===`off`?null:(0,h.jsx)(xV,{label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,error:T(`edgeSilenceSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.5,value:A(x.edgeSilenceSeconds),onChange:e=>r({...n,config:{...x,edgeSilenceSeconds:Number(e.target.value)}})})}),ee?(0,h.jsx)(xV,{label:`Seconds per image`,tip:`play.image-seconds`,error:T(`imageSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:600,step:1,value:A(x.imageSeconds),onChange:e=>r({...n,config:{...x,imageSeconds:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Zoom (%)`,tip:`play.zoom`,error:T(`zoomPercent`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:50,step:.5,value:A(x.zoomPercent),onChange:e=>r({...n,config:{...x,zoomPercent:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Motion`,tip:`play.motion`,children:(0,h.jsx)(TV,{value:x.motionStyle,onChange:e=>r({...n,config:{...x,motionStyle:e.target.value}}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null]}),ee?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Cuts and look`,columns:!1,children:[E.cuts,E.look,x.sources.audio===`generate`&&x.audio?.describeFigures===!0?(0,h.jsx)(m6,{tip:`project.edit.show-figures`,value:x.showFigures,onChange:e=>{let{showFigures:t,...i}=x;r({...n,config:e?{...i,showFigures:!0}:i})}}):null]}),x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Ambient sound`,columns:!1,children:(0,h.jsx)(Sye,{edit:n,problem:T,onChange:r})})]})]}):null,x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Pauses and volume`,columns:!1,children:[(0,h.jsx)(wye,{edit:n,problem:T,onChange:r}),(0,h.jsx)(Cye,{edit:n,problem:T,onChange:r})]})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Intro and outro`,children:[`intro`,`outro`].map(e=>{let i=x[e]?.name,a=t.revision.content.promptTemplates[e],o=b.data?.entries.find(t=>t.category===e&&t.name===i),s=i!==void 0&&o!==void 0&&typeof a==`string`&&t.revision.config[e]?.name===i&&a!==o.body,c=n.content.promptTemplates[e],l=`${tbe}${i??``}`,u=i===void 0?``:s&&c!==o?.body?l:i;return(0,h.jsx)(xV,{label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,children:(0,h.jsxs)(TV,{value:u,onChange:i=>{if(i.target.value===l&&typeof a==`string`){r(k5({...n,config:{...x,[e]:t.revision.config[e]},content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:a}}}));return}let o=b.data?.entries.find(t=>t.category===e&&t.name===i.target.value),s={...x};o===void 0?delete s[e]:s[e]={name:o.name,mode:o.mode},r(k5({...n,config:s,content:o===void 0?n.content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:o.body}}}))},children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),i!==void 0&&!b.data?.entries.some(t=>t.category===e&&t.name===i)?(0,h.jsxs)(`option`,{value:i,children:[i,` (saved entry)`]}):null,s?(0,h.jsxs)(`option`,{value:l,children:[i,` · this project's version`]}):null,b.data?.entries.filter(t=>t.category===e).map(e=>(0,h.jsx)(`option`,{value:e.name,children:s&&e.name===i?`${e.name} · Library version (newer)`:e.name},e.id))]})},e)})}),x.sources.research===`provide`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Research`,columns:!1,children:(0,h.jsx)(xV,{label:`Research notes`,tip:`play.provided.research`,error:T(`provided.research`),children:(0,h.jsx)(wV,{rows:6,value:x.provided.research??``,onChange:e=>r({...n,config:{...x,provided:{...x.provided,research:e.target.value}}})})})})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Article`,hidden:O!==`article`,className:k(`article`),children:[(0,h.jsx)(xV,{label:`Article text`,tip:`project.edit.article-text`,error:T(`content.articleMarkdown`)??T(`provided.article`),help:n.content.articleEdited?`Your edited article is kept when other settings change. Regenerating it replaces it after the rebuild review.`:void 0,children:(0,h.jsx)(wV,{rows:12,maxLength:5e5,value:(n.content.articleEdited?n.content.articleMarkdown:t.articleMarkdown)??n.content.articleMarkdown??x.provided.article??``,onChange:e=>r({...n,content:{...n.content,articleMarkdown:e.target.value,articleEdited:!0}})})}),x.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:()=>r({...n,regenerate:[...new Set([...n.regenerate??[],`article:body`])]}),children:`Regenerate article after review`}),(0,h.jsx)(V,{id:`project.edit.regenerate-article`})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Providers`,hidden:O!==`providers`,className:k(`providers`),children:[(0,h.jsx)(zye,{edit:n,error:T(`language`),onChange:r}),(0,h.jsx)(Yye,{projectId:t.revision.projectId,edit:n,providers:_.data?.providers??[],voices:v.data?.voices??[],onChange:r}),(0,h.jsx)(Hye,{edit:n,view:t,prompts:y.data?.prompts??[],error:T(`narrationPrompt`),onChange:r})]}),(0,h.jsxs)(`section`,{"aria-label":`Prompts`,hidden:O!==`prompts`,className:k(`prompts`),children:[(0,h.jsx)(Zye,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r}),(0,h.jsx)(Uye,{edit:n,saved:t.revision.config.imagePrompts,prompts:y.data?.prompts??[],entries:b.data?.entries??[],onChange:r})]}),(0,h.jsx)(`section`,{"aria-label":`Reviews`,hidden:O!==`reviews`,className:k(`reviews`),children:(0,h.jsx)(Xye,{edit:n,providers:_.data?.providers??[],prompts:y.data?.prompts??[],problem:T,onChange:r})}),(0,h.jsx)(`section`,{"aria-label":`Shorts`,hidden:O!==`shorts`,className:k(`shorts`),children:(0,h.jsx)(wve,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r,onPending:p})}),(0,h.jsxs)(`section`,{"aria-label":`Subtitles`,hidden:O!==`subtitles`,className:k(`subtitles`),children:[(0,h.jsx)(`div`,{"data-tour":`project-subtitles`,children:(0,h.jsx)(H6,{value:x.subtitles??hM,format:x.format,audioEnabled:x.sources.audio!==`off`,videoEnabled:ee,onChange:e=>r({...n,config:{...x,subtitles:ON(e,x.sources)}}),onUploading:d,problem:T})}),O!==`subtitles`||!ee?null:(0,h.jsx)(O6,{drawnOn:S?.drawnOn,poster:w,settings:{format:x.format,subtitles:{mode:(x.subtitles??hM).mode,fontId:(x.subtitles??hM).fontId,fontSize:(x.subtitles??hM).fontSize,position:(x.subtitles??hM).position??`bottom`},videoEdit:x.videoEdit,image:S?.image}})]}),e.renderContent?.({view:t,edit:n,fields:a,onChange:r,onPending:f,section:O})]})]})}var S7={notes:`Research notes`,article_md:`Article (Markdown)`,article_txt:`Article text`,narration_txt:`Clean Narration`,tts_script:`TTS Script`,sources:`Research sources`,glossary:`Glossary`,audio_body:`Narration`,audio_intro:`Intro narration`,audio_outro:`Outro narration`,audio_export:`Audio export`,image:`Image`,thumbnail:`Thumbnail`,video:`Video`,render_params:`Export settings`,subtitles_srt:`Subtitles (SRT)`,subtitles_vtt:`Subtitles (VTT)`,subtitle_words:`Subtitle timing`,subtitle_ass:`Styled subtitles`,subtitle_font:`Subtitle font`,instructions:`Generation instructions`,document_pdf:`Document (PDF)`,youtube_description:`YouTube description`,youtube_tags:`YouTube tags`,youtube_pinned_comment:`Pinned comment`,youtube_titles:`Other titles`,shorts:`Shorts list`,short_image:`Short image`,short_video:`Short`,animated_image:`Animated image`,figure_card:`On-screen card`,reference:`Establishing image (reference)`,script_md:`Script (speaker split)`,audio_mp3:`Audio (MP3 with chapters)`,audio_m4b:`Audiobook (M4B with chapters)`,audio_levelled:`Levelled narration`};function C7(e){return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment?`${e.meta.segment===`body`?`Body`:e.meta.segment===`intro`?`Intro`:`Outro`} ${S7[e.role]}`:e.role===`short_video`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)}`:e.role===`short_image`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)} image ${String(e.meta.index??1)}`:e.role===`figure_card`&&typeof e.meta.index==`number`?`On-screen card ${String(e.meta.index)}`:e.role===`animated_image`&&typeof e.meta.index==`number`?`Animated image ${String(e.meta.index)}`:e.role===`image`&&typeof e.meta.index==`number`?`Image ${e.meta.index}`:S7[e.role]}function rbe(e){if(e.startsWith(`image:`))return`Image`;if(e.startsWith(`animate:`))return S7.animated_image;if(/^shorts:\d+:render$/.test(e))return S7.short_video;if(/^shorts:\d+:image:\d+$/.test(e))return S7.short_image;if(e===`document:pdf`)return S7.document_pdf;let t=e.split(`:`).at(-1);return Object.entries(S7).find(([e])=>e===t)?.[1]??`Saved output`}function ibe({preview:e,pending:t,feedback:n,onStart:r,onCancel:i}){let a=ube(e),[o,s]=(0,m.useState)([]),[c,l]=(0,m.useState)(!1),u=(0,m.useId)(),d=e.work.filter(e=>e.disposition===`blocked`),f=e.providedReuseRequired.filter(e=>!o.includes(e)),p=e.work.filter(e=>e.disposition===`generate`||e.disposition===`local`||e.disposition===`review`).length,g=p===1?`Remake 1 output`:`Remake ${String(p)} outputs`,_=[...d.length===0?[]:[`${d.length===1?`1 item is`:`${d.length} items are`} unavailable (reasons above)`],...f.map(e=>`tick “Keep the provided content for ${a(e)}”`),...e.costs.unknown===0||c?[]:[`tick “I understand that ${e.costs.unknown} cost estimates are unknown”`]],v=_.length===0,y=obe.map(t=>({disposition:t,count:e.work.filter(e=>e.disposition===t).length})).filter(e=>e.count>0),b=e.costs.rows.some(e=>e.onPlan===!0),x=e.costs.apiLow,S=e.costs.apiHigh;return(0,h.jsxs)(`section`,{"aria-label":`Review affected rebuild`,className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-6 gap-y-3 sm:grid-cols-3`,children:[y.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:O7[e.disposition]}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:e.count})]},e.disposition)),(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:e.costs.unknown>0?`known cost`:`cost`}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:D7(e.costs.low,e.costs.high)})]})]}),b?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`CLI work: $0 on your plan${x===void 0||S===void 0?``:` · ~${D7(x,S)} via API`}.`}):null,d.length===0?null:(0,h.jsx)(SI,{tone:`danger`,title:`${d.length===1?`1 item can’t`:`${d.length} items can’t`} run, so this rebuild can’t start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:sbe(d,a).map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.what,`:`]}),` `,e.reason]},e.reason))})}),e.wholeRequestNotice===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.wholeRequestNotice}),e.warnings.map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e},e)),(0,h.jsxs)(`div`,{className:`flex flex-col divide-y divide-line border-y border-line`,children:[e.review?.inputChanges.length?(0,h.jsx)(w7,{summary:`Changed inputs (${String(e.review.inputChanges.length)})`,children:(0,h.jsx)(`dl`,{className:`m-0 flex flex-col gap-3`,children:e.review.inputChanges.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`dt`,{className:`font-semibold`,children:e.label}),(0,h.jsxs)(`dd`,{className:`m-0 grid gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(T7,{label:`Before`,text:e.before}),(0,h.jsx)(T7,{label:`After`,text:e.after})]})]},e.label))})}):null,(0,h.jsxs)(w7,{summary:`Work items (${e.work.length}): ${y.map(e=>`${e.count} ${O7[e.disposition]}`).join(`, `)||`none`}`,children:[e.changedInputs.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 mb-3 flex flex-col gap-1 pl-5`,children:e.changedInputs.map(e=>(0,h.jsxs)(`li`,{children:[a(e.path),`:`,` `,e.after===null?`Removed`:e.before===null?`New output`:`Inputs changed`]},e.path))}),(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-2 pl-5`,children:e.work.map(t=>(0,h.jsxs)(`li`,{children:[a(t.key),`: `,O7[t.disposition],`. `,t.reason,t.inflight?` An already submitted request may still be billed.`:``,e.review?.requests.filter(e=>e.key===t.key).map(e=>(0,h.jsxs)(`div`,{children:[e.settings===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.settings}),e.text===null?null:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:`View request text`}),(0,h.jsx)(`pre`,{className:`m-0 max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.text})]})]},e.key))]},t.key))}),(0,h.jsxs)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:[`Retained outputs:`,` `,e.retained.map(e=>rbe(e.slot)).join(`, `)||`None`]})]}),e.costs.rows.length===0?null:(0,h.jsx)(w7,{summary:`Cost by step`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:e.costs.rows.map(e=>(0,h.jsxs)(`li`,{children:[a(e.stage),`: `,abe(e),`. `,e.detail]},`${e.stage}-${e.detail}`))})})]}),n,(0,h.jsxs)(`div`,{className:`sticky bottom-[-16px] -mx-4 flex flex-col gap-3 border-t border-line bg-raised px-4 py-3`,children:[e.providedReuseRequired.length===0&&e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small`,children:[e.providedReuseRequired.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:o.includes(e),onChange:t=>s(t.target.checked?[...o,e]:o.filter(t=>t!==e))}),(0,h.jsxs)(`span`,{children:[`Keep the provided content for `,a(e)]})]}),(0,h.jsx)(V,{id:`project.rebuild.keep-provided`,className:`-my-1`})]},e)),e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:c,onChange:e=>l(e.target.checked)}),(0,h.jsxs)(`span`,{children:[`I understand that `,e.costs.unknown,` cost estimates are unknown.`]})]}),(0,h.jsx)(V,{id:`project.rebuild.unknown-costs`,className:`-my-1`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:t||!v,"aria-describedby":v?void 0:u,onClick:()=>r({acknowledgeUnknownCosts:c,confirmedProvidedWorkKeys:o}),children:t?`Starting the remake…`:g}),(0,h.jsx)(R,{disabled:t,onClick:i,children:`Keep things as they are`}),v||t?null:(0,h.jsx)(`p`,{id:u,className:`m-0 min-w-0 text-small text-ink-2`,children:`${g} is off until: ${_.join(`; `)}.`})]})]})]})}function w7({summary:e,children:t}){return(0,h.jsxs)(`details`,{className:`py-3 text-small`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold text-ink`,children:e}),(0,h.jsx)(`div`,{className:`mt-3`,children:t})]})}function T7({label:e,text:t}){return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`pre`,{className:`m-0 max-h-40 overflow-auto whitespace-pre-wrap break-words text-small`,children:t??`Not set`})]})}var E7=e=>e===null?`Unknown`:e===0?`$0`:new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:e>0&&e<.01?4:2}).format(e);function D7(e,t){return e===t?E7(e):`${E7(e)}–${E7(t)}`}function abe(e){return e.onPlan===!0?`$0 on plan${e.apiLow===void 0||e.apiLow===null||e.apiHigh===void 0?``:` · ~${D7(e.apiLow,e.apiHigh??null)} via API`}`:D7(e.low,e.high)}var obe=[`generate`,`local`,`review`,`reuse`,`blocked`];function sbe(e,t){let n=new Map;for(let t of e){let e=t.reason.trim()||`No reason was given.`;n.set(e,[...n.get(e)??[],t.key])}return[...n].map(([e,n])=>({reason:e,what:n.length===1?t(n[0]??``):`${n.length} ${new Set(n.map(k7)).size===1?cbe(k7(n[0]??``)):`items`}`}))}function cbe(e){return/s$/u.test(e)?e:`${e.charAt(0).toLowerCase()}${e.slice(1)}s`}var O7={reuse:`kept as they are`,generate:`to make`,local:`built on this computer`,review:`to confirm`,blocked:`can't run`},lbe={"export:wav":`Audio export (WAV)`,"export:video":`Video export`,"subtitles:timing":`Subtitle timing`,"subtitles:cues":`Caption text and timing`,"subtitles:files":`Subtitle files`,"article:body":`Article`,"audio:provided":`Provided narration`,"audio:body:concat":`Combined narration`,"audio:intro":`Combined intro narration`,"audio:outro":`Combined outro narration`,"research:planner":`Research plan`,"research:notes":`Research notes`,"entry:intro:text":`Intro text`,"entry:outro:text":`Outro text`};function k7(e){let t=lbe[e];return t===void 0?{image:`Image request`,images:`Images`,audio:`Narration request`,article:`Article`,research:`Research`,thumbnail:`Thumbnail`,subtitles:`Subtitles`,video:`Video export`,export:`Export`,entry:`Intro or outro`}[e.split(`:`)[0]??``]??`Output`:t}function ube(e){let t=new Map,n=new Map;for(let t of e.work){let e=k7(t.key);n.set(e,(n.get(e)??0)+1)}let r=new Map;for(let i of e.work){let e=k7(i.key),a=(r.get(e)??0)+1;r.set(e,a),t.set(i.key,(n.get(e)??0)>1?`${e} ${a}`:e)}for(let n of e.review?.requests??[])t.set(n.key,n.label);return e=>t.get(e)??k7(e)}var dbe={llm:`Text generation`,image:`Images`,images:`Images`,tts:`Audio`,audio:`Audio`};function A7({error:e,refusal:t}){let n=(0,m.useRef)(null);return(0,m.useEffect)(()=>{(e!==void 0||t!==void 0)&&n.current?.focus()},[e,t]),e===void 0&&t===void 0?null:(0,h.jsxs)(`div`,{ref:n,role:`alert`,tabIndex:-1,"data-tone":`danger`,className:`sl-callout sl-callout--danger outline-none`,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),(0,h.jsx)(`p`,{className:`sl-callout__title m-0`,children:e??(t?.reason===`readiness`?t.fields.length>0?`This can't start yet. Fix the items below, then try again.`:`Slopify couldn't check your providers. Open Settings → Providers, make sure each one you use is set up, then try again.`:t?.message)}),t?.fields.length?(0,h.jsx)(`ul`,{className:`sl-callout__body m-0 list-disc pl-5`,children:t.fields.map(({field:e,message:t})=>(0,h.jsxs)(`li`,{children:[dbe[e.split(`.`)[0]??``]??`Project`,`: `,t]},`${e}:${t}`))}):null]})}var fbe=q({text:W().optional(),logicalText:W().optional(),title:W().optional(),notes:W().optional(),outline:K(W()).optional(),prompt:W().optional()});function pbe(e){if(e===null)return`No text was recorded for this part.`;try{let t=fbe.safeParse(JSON.parse(e));if(!t.success)return`Recorded text cannot be decoded.`;let{logicalText:n,text:r,title:i,notes:a,outline:o,prompt:s}=t.data;return[n,r,a?.trim()?[i,a].filter(e=>e?.trim()).join(`
304
+ `)}function vye({cues:e,duration:t,onChange:n,onPending:r}){let i=(0,m.useId)(),[a,o]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[s,c]=(0,m.useState)(),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(r);d.current=r,(0,m.useEffect)(()=>{d.current(l)},[l]),(0,m.useEffect)(()=>()=>d.current(!1),[]);function f(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){c(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,o]of a.entries()){let a=o.start.trim()===``?NaN:Number(o.start),s=o.end.trim()===``?NaN:Number(o.end);if(r.has(o.id)){c(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(o.id),!Number.isFinite(a)||a<0||a<i){c(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=a||s>t){c(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(o.text.trim()===``){c(`Caption ${n+1}: enter caption text.`);return}e.push({id:o.id,text:o.text,start:a,end:s,...o.speaker===void 0?{}:{speaker:o.speaker}}),i=s}n(e),c(void 0),u(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(V,{id:`project.captions.editor`})]}),a.map((e,t)=>(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Caption `,t+1]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(wV,{id:`${i}-${e.id}-text`,value:e.text,onChange:n=>{u(!0),o(a.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{u(!0),o(a.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${i}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(CV,{id:`${i}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{u(!0),o(a.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:s}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:f,children:`Apply caption edits to draft`}),(0,h.jsx)(V,{id:`project.captions.apply`})]}),l?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function l7(e){return`imagePrompts.${String(e)}`}function u7(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function yye(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function bye(e){let{from:t,to:n,content:r}=e,i=n.map(e=>t.findIndex(t=>t.name===e.name)),a=[],o={},s={};for(let[e,t]of Object.entries(r.promptTemplates))u7(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))u7(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=l7(t),l=i[t]??-1;if(l>=0){let t=l7(l);Object.hasOwn(r.promptTemplates,t)&&(o[n]=r.promptTemplates[t]??null);let i=e.rendered[t];i!==void 0&&(s[n]=i);continue}let u=e.body(c.name);if(u===void 0){a.push({field:`imagePrompts.${String(t)}.name`,message:`The image prompt "${c.name}" is not in the Library any more. Untick it under Images, or add it back on Library → Prompts.`});continue}o[n]=u,s[n]=mq(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=u7(r.imageDefinitions[e]?.templateKey);n===void 0||n>=t.length||c.set(n,[...c.get(n)??[],e])}let l={},u=[],d=[],f=(e,t)=>{let n=l7(e),r=o[n];return t===void 0?{source:`generate`,assetId:null,prompt:s[n]??null,templateKey:r==null?null:n}:{...t,source:`generate`,assetId:null,templateKey:t.templateKey??null}},p=(t,n,r)=>Array.from({length:Math.max(0,n)},()=>{let n=e.key();return l[n]=f(t,r),u.push(n),n}),m=[];for(let e of r.imageOrder){let a=r.imageDefinitions[e];if(a===void 0)continue;let o=u7(a.templateKey);if(o===void 0||o>=t.length){l[e]=a,m.push(e);continue}let s=i.indexOf(o);if(s===-1){d.push(e);continue}let u=c.get(o)??[],f=t[o]?.number!==n[s]?.number,h=f?n[s]?.number??0:u.length,g=u.indexOf(e);if(g>=h){d.push(e);continue}let _=a.templateKey===l7(s)?a:{...a,templateKey:l7(s)};l[e]=_,m.push(e),f&&g===Math.min(u.length,h)-1&&m.push(...p(s,h-u.length,_))}for(let[e,r]of n.entries()){let n=i[e]??-1,a=n>=0?c.get(n)??[]:[];n>=0&&(a.length>0||t[n]?.number===r.number)||m.push(...p(e,r.number,void 0))}return{ok:!0,content:{...r,imageOrder:m,imageDefinitions:l,promptTemplates:o},rendered:s,added:u,removed:d}}function xye({edit:e,saved:t,prompts:n,problem:r,onChange:i}){let{config:a}=e;if(a.sources.images!==`generate`)return null;let o=n.filter(e=>e.kind===`image`);return(0,h.jsxs)(`section`,{"aria-label":`Image prompts`,className:`space-y-3`,children:[(0,h.jsx)(Y3,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(Sye,{edit:e,saved:t,prompts:o,problem:r})]})}function Sye({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(yye(t,i))return a===void 0?null:(0,h.jsx)(d7,{children:a});let o=0,s=bye({from:t,to:i,content:e.content,rendered:e.config.rendered,values:e.config.values,body:e=>n.find(t=>t.name===e)?.body,key:()=>`planned-${String(++o)}`});if(!s.ok)return(0,h.jsx)(d7,{children:s.fields.map(e=>e.message).join(` `)});let c=e=>`${String(e)} ${e===1?`image`:`images`}`,l=[...s.added.length>0?[`adds ${c(s.added.length)} to make`]:[],...s.removed.length>0?[`removes ${c(s.removed.length)}`]:[]];return(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsx)(d7,{children:a}),(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:l.length===0?`Saving keeps every image as it is.`:`Saving ${l.join(` and `)}. The other images are kept; the new ones are made when you remake outdated outputs.`})]})}function d7({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function Cye({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:iA(r)),o=r?.source===`upload`?[...Zk,`upload`]:Zk,s=i===void 0?[]:[...Eye(i)];return(0,h.jsx)(A2,{value:i,inherit:`None`,sources:o,offerNone:!1,problem:e=>t(`ambientBed.${e}`)??s.find(t=>t.field===e)?.message,onChange:t=>{a(t);let r=aA(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function wye({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...tk,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(k6,{value:i,problem:e=>t(`loudness.${e}`),onChange:t=>{a(t);let{loudness:r,...i}=e.config;n({...e,config:t.enabled?{...i,loudness:{videoLufs:t.videoLufs,audioFilesLufs:t.audioFilesLufs}}:i})}})}function Tye({edit:e,problem:t,onChange:n}){let[r,i]=(0,m.useState)(()=>({sentencePauseSeconds:String(e.config.sentencePauseSeconds??0),paragraphPauseSeconds:String(e.config.paragraphPauseSeconds??0)}));if(e.config.sources.audio!==`generate`)return null;let a=e=>{let t=F6(r[e]);return t===void 0?`Enter a number of seconds.`:bk(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(P6,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=F6(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function Eye(e){let t=aA(e);return t===void 0?[]:nA(t)}function Dye({edit:e,problem:t,onChange:n}){let r=(0,m.useId)(),{config:i}=e,a=i.imageScale,[o,s]=(0,m.useState)(()=>a===void 0?void 0:XO(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(qO(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=f7(t);l!==void 0&&n({...e,config:{...o,imageScale:{perHour:l,words:c},...a===void 0&&i.motionStyle===`zoom`?{motionStyle:`mixed`}:{}}})},u=i.imagePrompts.reduce((e,t)=>e+t.number,0),d=a===void 0?u:$O(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:f7(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(UO)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(JO(c))))} minutes of narration: ${String(d)} images${d>u?`, ${String(d-u)} more than the prompts' ${String(u)}`:`, which the prompts' Numbers already cover`}.`},g=t(`imageScale`)??void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:[(0,h.jsx)(kb,{checked:o!==void 0,label:`More images for long videos`,describedBy:`${r}-line`,tip:`play.image-scale`,onChange:e=>l(e?{every:`minutes`,value:`2`}:void 0)}),o===void 0?null:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-small`,children:[(0,h.jsx)(Ab,{label:`How the rate is given`,value:o.every,options:[{value:`minutes`,label:`Every N minutes`},{value:`hour`,label:`N per hour`}],onChange:e=>l({every:e,value:Oye(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(CV,{"aria-label":o.every===`minutes`?`Minutes per image`:`Images per hour`,inputMode:`decimal`,className:`w-[72px] tabular-nums`,"aria-invalid":p?.problem===!0,"aria-describedby":`${r}-line`,value:o.value,onChange:e=>l({every:o.every,value:e.target.value})}),(0,h.jsx)(`span`,{children:o.every===`minutes`?`minutes`:`images per hour`})]}),g===void 0&&p===void 0?null:(0,h.jsx)(`p`,{id:`${r}-line`,className:g!==void 0||p?.problem?`m-0 text-label text-danger`:`m-0 text-label text-ink-3`,children:g??p?.text})]})}function f7(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?YO(t):void 0:t>=1&&t<=240?t:void 0}function Oye(e,t,n){if(t===n)return e;let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)||r<=0?e:String(Math.round(60/r*100)/100)}function kye({edit:e,onChange:t}){let{config:n}=e;return n.sources.images!==`generate`||n.sources.article===`off`?null:(0,h.jsx)(`div`,{className:`flex flex-col items-start gap-2`,...Ob,children:(0,h.jsx)(kb,{checked:n.imageScenes===!0,label:`Scenes from the article`,tip:`play.image-scenes`,onChange:r=>{let{imageScenes:i,...a}=n;t({...e,config:{...a,...r?{imageScenes:!0}:{}}})}})})}function Aye({edit:e,view:t,imageKey:n,index:r}){let{api:i}=z(),a=e.content.imageDefinitions[n];if(a===void 0)return null;let o=t?.outputs.filter(e=>e.output.stageKind===`images`&&e.output.role===`image`)??[],s=o.find(e=>e.selected&&e.workKey===`image:${n}`),c=e.uploads?.some(e=>e.destination.kind===`image`&&e.destination.imageKey===n)??!1,l=a.source===`generate`||c||s?.assetId===a.assetId?s:o.find(e=>e.assetId===a.assetId&&e.available),u=l?.available===!0,d=!u&&(l!==void 0||a.source===`provide`&&a.assetId!==null),f=e.regenerate?.includes(`image:${n}`)===!0,p=c?u?`Replacement ready to save; previous image shown until Save`:`Replacement ready to save; preview available after Save`:f?`Made again after you press Save changes; the current image stays until then`:d?`Image file unavailable`:u?a.source===`provide`&&l!==s?`Provided image selected`:l.state===`review`?`Image retained; review required`:l.state===`outdated`?`Outdated image retained until rebuilt`:`Current image retained`:`No completed image yet`,m=u&&/\.(mp4|mov|m4v|webm|mkv)$/i.test(l.output.path);return(0,h.jsxs)(h.Fragment,{children:[!u||t===void 0?null:m?(0,h.jsx)(R0,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(z0,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:s2(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}function p7(e,t,n){let r=t+n,i=e[t],a=e[r];if(i===void 0||a===void 0)return e;let o=[...e];return o[t]=a,o[r]=i,o}function jye({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),{content:c}=e,l=KO(e.config),u=(0,m.useRef)(e);u.current=e;function d(e){let n=e.content.imageOrder.flatMap(t=>{let n=e.content.imageDefinitions[t];return n===void 0?[]:[n]}),r=e.content.imageOrder.length===0||e.config.sources.images===`off`?`off`:n.some(e=>e.source===`generate`)?`generate`:`provide`,i={...e,config:{...e.config,sources:{...e.config.sources,images:r,...r===`off`?{video:`off`}:{}}}};u.current=i,t(i)}function f(e,t){let n=i?.()??u.current,r=n.content.imageDefinitions[e];if(r===void 0)return;let a=r.templateKey??`image:${e}`;s(t=>({...t,[e]:(t[e]??0)+1})),d(A5({...n,...n.uploads===void 0?{}:{uploads:n.uploads.filter(t=>t.destination.kind!==`image`||t.destination.imageKey!==e)},content:{...n.content,imageDefinitions:{...n.content.imageDefinitions,[e]:{...r,templateKey:a}}}},a,t))}function p(e){let t=i?.()??u.current,n=t.content,r=crypto.randomUUID();d({...t,config:{...t.config,sources:{...t.config.sources,images:t.config.sources.images===`off`?`provide`:t.config.sources.images}},content:{...n,imageOrder:[...n.imageOrder,r],imageDefinitions:{...n.imageDefinitions,[r]:{source:`provide`,assetId:null,prompt:null}}},uploads:[...t.uploads??[],{stagedFileId:e.id,destination:{kind:`image`,imageKey:r}}]})}return(0,h.jsxs)(`section`,{"aria-label":`Edit images`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Images`}),(0,h.jsx)(V,{id:`project.images.editor`})]}),c.imageOrder.map((t,s)=>{let l=c.imageDefinitions[t];return l===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(Aye,{edit:e,view:r,imageKey:t,index:s}),l.source===`generate`?(0,h.jsxs)(`div`,{...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${t}-prompt`,children:[`Prompt for image `,s+1]}),(0,h.jsx)(V,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${t}-prompt`,value:l.templateKey===void 0||l.templateKey===null?l.prompt??``:c.promptTemplates[l.templateKey]??l.prompt??``,onChange:e=>f(t,e.target.value)})]}):null,l.source===`generate`&&l.templateKey==null?(0,h.jsxs)(R,{type:`button`,onClick:()=>f(t,l.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(j5,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??u.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&d({...n,regenerate:(n.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:[...(n.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t),{stagedFileId:e.id,destination:{kind:`image`,imageKey:t}}],content:{...r,imageDefinitions:{...r.imageDefinitions,[t]:{...a,source:`provide`,prompt:null,templateKey:null}}}})}},`${t}:${o[t]??0}:${e.config.sources.images===`off`}`),(0,h.jsxs)(R,{type:`button`,disabled:s===0,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(R,{type:`button`,disabled:s===c.imageOrder.length-1,onClick:()=>d({...e,content:{...c,imageOrder:p7(c.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(R,{type:`button`,onClick:()=>{let n=c.imageOrder.filter(e=>e!==t);d({...e,config:n.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...c,imageOrder:n,imageDefinitions:Object.fromEntries(Object.entries(c.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`image`||e.destination.imageKey!==t)})},children:[`Delete image `,s+1,c.imageOrder.length===1?` and turn Images and Video Off`:``]}),l.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(R,{type:`button`,onClick:()=>d({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(V,{id:`project.images.regenerate`})]}):null]},t)}),(0,h.jsx)(R,{type:`button`,disabled:c.imageOrder.length>=l,onClick:()=>{if(c.imageOrder.length>=l)return;let t=crypto.randomUUID();d({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...c,imageOrder:[...c.imageOrder,t],promptTemplates:{...c.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...c.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),c.imageOrder.length>=l?(0,h.jsxs)(`p`,{children:[`At most `,l,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(j5,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:p},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(j5,{label:`Add a video clip`,kind:`images`,accept:`video/mp4,video/quicktime,video/webm,video/x-matroska,.mp4,.mov,.m4v,.webm,.mkv`,onPending:e=>n(`clip:new`,e),onReady:p},`new-clip:${e.config.sources.images===`off`}`)]})]})}var Mye=q({logicalKey:W().min(1),logicalText:W(),segment:J([`body`,`intro`,`outro`]),text:W()});function Nye(e,t){if(t==null)return e;let n=[...t.intro??[],...t.body??[],...t.outro??[]];return n.length===0?e:n.flatMap(t=>e.filter(e=>e.key===t))}function Pye(e){let t=new Map,n=new Set,r=0;for(let i of e.pieces){if(!i.selected||i.stageKind!==`audio`||i.piece.kind!==`chunk`)continue;let e;try{e=i.piece.payload===null?null:JSON.parse(i.piece.payload)}catch{r++;continue}let a=Mye.safeParse(e);if(!a.success){r++;continue}let{logicalKey:o,logicalText:s}=a.data;if(n.has(o)){r++;continue}let c=t.get(o);if(c!==void 0&&c.text!==s){r+=c.parts+1,t.delete(o),n.add(o);continue}t.set(o,{key:o,text:s,parts:(c?.parts??0)+1})}return{groups:[...t.values()],unmapped:r}}function Fye({view:e,edit:t,onChange:n,onPending:r,getEdit:i}){let a=(0,m.useId)(),{api:o}=z(),s=N({queryKey:[`narration-chunks`,e.revision.projectId,e.revision.id],queryFn:async()=>{let t=await Sfe(o,e.revision.projectId,e.revision.id);return t.ok?t.value.chunks:null},staleTime:1/0}),c=Pye(e),l=Nye(c.groups,s.data),u=c.unmapped,d=(0,m.useRef)(t);d.current=t;let[f,p]=(0,m.useState)({});function g(e){d.current=e,n(e)}return(0,h.jsxs)(`section`,{"aria-label":`Edit narration`,className:`space-y-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Narration`}),(0,h.jsx)(V,{id:`project.narration.editor`})]}),t.config.chunking?.mode===`whole`||t.config.chunking===void 0?(0,h.jsx)(`p`,{children:`This narration uses one whole request. Editing its text rebuilds the whole narration request.`}):null,u===0?null:(0,h.jsx)(`p`,{children:`Some older audio cannot be matched reliably to its narration text. Replace the provided narration or rebuild from the article to edit those chunks.`}),l.map((e,n)=>{let o=t.content.narrationOverrides[e.key];return(0,h.jsxs)(`fieldset`,{className:`space-y-2 rounded-control border border-line-strong p-3`,children:[(0,h.jsxs)(`legend`,{children:[`Narration chunk `,n+1]}),(0,h.jsxs)(`p`,{children:[e.parts,` audio `,e.parts===1?`part`:`parts`,` in this narration chunk.`]}),(0,h.jsxs)(`div`,{className:`text-small`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.key}-text`,children:[`Text for narration chunk `,n+1]}),(0,h.jsx)(V,{id:`project.narration.chunk-text`,label:`text for narration chunk ${String(n+1)}`})]}),(0,h.jsx)(wV,{id:`${a}-${e.key}-text`,value:o?.kind===`text`?o.text:e.text,onChange:n=>{p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,...t.uploads===void 0?{}:{uploads:t.uploads.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key)},content:{...t.content,narrationOverrides:{...t.content.narrationOverrides,[e.key]:{kind:`text`,text:n.target.value}}}})}})]}),(0,h.jsx)(j5,{label:`Replace narration chunk ${n+1}`,kind:`audio`,onPending:t=>r(`narration:${e.key}`,t),onReady:t=>{let n=i?.()??d.current;g({...n,regenerate:(n.regenerate??[]).filter(t=>t!==e.key),uploads:[...(n.uploads??[]).filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),{stagedFileId:t.id,destination:{kind:`narration`,key:e.key}}]})}},`${e.key}:${f[e.key]??0}`),t.regenerate?.includes(e.key)?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Narration chunk `,n+1,` will be regenerated after you save and press Remake.`,(0,h.jsxs)(R,{type:`button`,variant:`quiet`,onClick:()=>{let t=i?.()??d.current;g({...t,regenerate:(t.regenerate??[]).filter(t=>t!==e.key)})},children:[`Keep narration chunk `,n+1]})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(R,{type:`button`,onClick:()=>{let t=i?.()??d.current,n={...t.content.narrationOverrides};n[e.key]?.kind===`asset`&&delete n[e.key],p(t=>({...t,[e.key]:(t[e.key]??0)+1})),g({...t,content:{...t.content,narrationOverrides:n},uploads:t.uploads?.filter(t=>t.destination.kind!==`narration`||t.destination.key!==e.key),regenerate:[...new Set([...t.regenerate??[],e.key])]})},children:[`Regenerate narration chunk `,n+1,` after review`]}),(0,h.jsx)(V,{id:`project.narration.regenerate`})]})]},e.key)})]})}function Iye(e){let{config:t,fingerprints:n}=e.revision;if(t.sources.audio===`off`)return;let r=t.sources.audio===`provide`?[{key:`audio:provided`,role:`audio_body`}]:[...t.intro===void 0?[]:[{key:`audio:intro`,role:`audio_intro`}],{key:`audio:body:concat`,role:`audio_body`},...t.outro===void 0?[]:[{key:`audio:outro`,role:`audio_outro`}]],i=e.outputs.filter(e=>e.selected&&e.state===`ready`&&e.available&&e.fingerprint===n[e.workKey]),a=r.map(({key:e,role:t})=>i.find(n=>n.workKey===e&&n.output.role===t));if(a.some(e=>e===void 0))return;let o=a.map(e=>e?.output.durationMs);if(o.every(m7))return o.reduce((e,t)=>e+t,0)/1e3+Math.max(0,r.length-1)*t.silenceGapSeconds+2*t.edgeSilenceSeconds;let s=i.find(e=>(e.output.role===`audio_export`||e.output.role===`video`)&&m7(e.output.durationMs))?.output.durationMs;return m7(s)?s/1e3:void 0}function m7(e){return e!=null&&Number.isFinite(e)&&e>0}function Lye({edit:e,prompts:t,problem:n,onChange:r,onPending:i,getEdit:a}){let{config:o}=e;if(o.sources.images!==`generate`)return null;let s=o.reference,c=s===void 0?v6:{source:s.source,prompt:s.prompt??``,thumbnail:s.thumbnail!==!1},l=e=>({...e,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`provided`||e.destination.stage!==`reference`)});return(0,h.jsx)(`section`,{"aria-label":`Establishing image`,className:`space-y-3`,children:(0,h.jsx)(y6,{value:c,prompts:t,problem:n,onChange:n=>{let{reference:i,...a}=o;if(n.source===`off`){r(l({...e,config:a}));return}let s={source:n.source,...n.source===`prompt`?{prompt:n.prompt}:{},...n.thumbnail?{}:{thumbnail:!1}},u=n.source===`prompt`&&n.prompt!==c.prompt?t.find(e=>e.kind===`image`&&e.name===n.prompt):void 0,d={...e,config:{...a,reference:s}},f=u===void 0?d:A5(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(j5,{label:e.content.provided.reference===void 0?`Upload the establishing image`:`Replace the establishing image`,kind:`images`,accept:`image/png,image/jpeg`,onPending:i,onReady:t=>{let n=l(a?.()??e);n.config.reference?.source===`provide`&&r({...n,uploads:[...n.uploads??[],{stagedFileId:t.id,destination:{kind:`provided`,stage:`reference`}}]})}})})})}var Rye=q({words:K(q({text:W().trim().min(1),start:G().finite().nonnegative(),end:G().finite().positive(),confidence:G().optional(),speaker:W().min(1).optional()})).min(1)});function h7(e){let{config:t,content:n}=e;return JSON.stringify({source:t.sources.audio,audio:n.provided.audio,uploads:e.uploads?.filter(e=>e.destination.kind===`narration`||e.destination.kind===`provided`&&e.destination.stage===`audio`)??[],edge:t.edgeSilenceSeconds,...t.sources.audio===`generate`?{choice:t.audio,chunking:t.chunking,article:n.articleMarkdown??t.provided.article,articleSource:t.sources.article,renderedArticle:t.rendered.article,intro:t.intro,outro:t.outro,renderedIntro:t.rendered.intro,renderedOutro:t.rendered.outro,gap:t.silenceGapSeconds,overrides:n.narrationOverrides,regenerate:e.regenerate?.filter(e=>/^(audio:|article:|entry:)/.test(e))??[]}:{}})}function zye({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=z(),s=N(nb(o)).data?.prompts??[],c=h7(t),l=t.config.sources.audio!==`off`&&c===h7({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?Iye(e):void 0,f=d!==void 0&&u!==void 0&&u!==``,p=(0,m.useRef)({edit:t,onChange:r,revisionId:e.revision.id,identity:c});p.current={edit:t,onChange:r,revisionId:e.revision.id,identity:c};let g=(0,m.useRef)(i);g.current=i;let[_,v]=(0,m.useState)(new Set),[y,b]=(0,m.useState)(),x=(0,m.useRef)(void 0),S=(0,m.useRef)(!0),C=(0,m.useCallback)((e,t)=>{S.current&&v(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);(0,m.useEffect)(()=>{g.current(_.size>0)},[_]),(0,m.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&x.current?.abort()}},[e.revision.id,c]);function w(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:h7(e)},t(e)}async function T(){if(x.current!==void 0)return;let t=new AbortController;x.current=t;let n=p.current;C(`captions:load`,!0),b(void 0);try{let r=e.outputs.find(e=>e.selected&&e.state===`ready`&&e.output.role===`subtitle_words`&&e.available);if(!f||d===void 0||u===void 0||r===void 0)throw Error(`Captions can't be edited until the current narration has finished and its subtitle timing is ready.`);let i=await o.fetch(s2(o,e.revision.projectId,e.revision.id,r.recordId),{signal:t.signal});if(!i.ok)throw Error(`The subtitle timing file couldn't be read. Reload the page and try again; if it still fails, use More → make it again in its section on Audio.`);let a=Rye.parse(await i.json()),s=0;for(let e of a.words){if(e.start<s||e.end<=e.start||e.end>d)throw Error(`The saved subtitle timing doesn't match the current narration. Use More → make it again in its section on Audio to rebuild it.`);s=e.end}let c=_ye(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!S.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;w({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){S.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{x.current===t&&(x.current=void 0),C(`captions:load`,!1)}}let E=t.content.subtitleCues,D=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!D(`images`),className:`space-y-6`,children:[(0,h.jsx)(xye,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(Dye,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:w}),(0,h.jsx)(kye,{edit:t,onChange:w}),(0,h.jsx)(Lye,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:w,onPending:e=>C(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(I6,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;w({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(j5,{label:`Replace provided ${e}`,kind:e,onPending:t=>C(`provided:${e}`,t),onReady:t=>{let n=p.current;n.edit.config.sources[e]===`provide`&&w({...n.edit,uploads:[...(n.edit.uploads??[]).filter(t=>t.destination.kind!==`provided`||t.destination.stage!==e),{stagedFileId:t.id,destination:{kind:`provided`,stage:e}}]})}},e):null),(0,h.jsx)(jye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!D(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(Fye,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:w,onPending:C}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!D(`captions`),className:`space-y-5`,children:[f?null:(0,h.jsx)(`p`,{children:`Captions can be edited once the current narration has finished and its subtitle timing is ready.`}),E===void 0?(0,h.jsx)(R,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void T(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[E.audioFingerprint===u?null:(0,h.jsx)(`p`,{children:`These caption edits belong to an earlier narration. Review their text and timing against the current narration, then apply your corrections and save the project.`}),f&&d!==void 0?(0,h.jsx)(vye,{cues:E.cues,duration:d,onPending:e=>C(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&w({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(R,{type:`button`,onClick:()=>w({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function Bye({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(k2,{value:e.config.language,error:t,onChange:t=>{let{language:r,...i}=e.config;n({...e,config:t===void 0||t===`en`?i:{...i,language:t}})}})})}function Vye({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=z(),a=N(Zb(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:Wb,c=s(o.channelId),l=a.data?.find(e=>e.id===c),u=o.useBrandKit!==!1,d=c!==s(t.channelId),f=u!==(t.useBrandKit!==!1);return(0,h.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(ha,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(TV,{value:c,onChange:t=>r({...e,config:{...o,channelId:t.target.value}}),children:[a.data===void 0?(0,h.jsx)(`option`,{value:c,children:`Loading channels…`}):null,(a.data??[]).map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,e.cast>0?` · ${String(e.cast)} in the cast`:``]},e.id))]})}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col justify-end gap-1`,children:[(0,h.jsx)(kb,{checked:u,label:`Use the channel's brand kit`,tip:`play.brand-kit`,onChange:t=>{let{useBrandKit:n,...i}=o;r({...e,config:t?i:{...i,useBrandKit:!1}})}}),u?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Its cast is still used.`})]}),a.error===null?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-danger md:col-span-2`,children:[`The channels couldn't be loaded: `,a.error.message,`. Reload the page to pick a channel.`]}),d||f?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:[d?`Saving moves the project to this channel and takes its cast as it is now. `:``,u?`The brand kit fills the caption font and colours, title style, end screen, intro, outro and document theme where they are at their default or were set by the old kit.`:`What the old brand kit had set is taken off.`]}):null]})}function Hye(e,t,n){let r=e.outputs.find(e=>e.selected&&e.available&&e.output.role===`reference`);if(t.config.reference!==void 0&&r!==void 0)return{image:{kind:`output`,outputId:r.output.id},drawnOn:`the establishing image`};let i=n.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`&&e.sha256!==null);return t?.sha256?[{...e,images:[t.sha256]}]:[]}),a=W6([t.config.title,...Object.values(t.config.values??{})].join(` `),i)[0]??i[0],o=a?.images[0];if(a!==void 0&&o!==void 0)return{image:{kind:`picture`,sha256:o},drawnOn:`${a.name}'s picture`}}function Uye({edit:e,view:t,prompts:n,error:r,onChange:i}){let a=(0,m.useRef)(e.config.narrationPrompt);if(e.config.sources.audio!==`generate`)return null;let o=t.revision.config.narrationPrompt,s=t.revision.content.promptTemplates.narration??t.revision.config.rendered.narration,c=o&&s!==void 0&&!n.some(e=>e.kind===`narration`&&e.name===o)?[...n,{id:`saved-narration`,kind:`narration`,name:o,body:s,slots:[],updatedAt:t.revision.createdAt}]:n;return(0,h.jsx)(g6,{value:e.config.narrationPrompt??``,prompts:c,libraryLinks:!1,supported:e.config.audio?.provider===`inworld`&&e.config.audio.model===`inworld-tts-2`,error:r,onChange:t=>{let n=e.config.narrationPrompt||a.current;t===``&&(a.current=e.config.narrationPrompt);let r=c.find(e=>e.kind===`narration`&&e.name===t),o=r===void 0||t===n?e:A5(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function Wye({edit:e,saved:t=e.config.imagePrompts,prompts:n,entries:r,onChange:i}){let a=(0,m.useId)(),o=[...new Set([...Object.keys(e.config.rendered),...Object.keys(e.content.promptTemplates),...e.config.sources.article===`generate`?[`article`]:[],...uj(e.config)?[`narration`]:[],...pj(e.config)&&e.config.descriptionPrompt?[`description`]:[],..._j(e.config)&&e.config.shorts?.prompt?[`shorts`]:[],..._j(e.config)&&e.config.shorts?.imagePrompt?[`shortsImage`]:[],...[`from_prompt`,`prompt_by_llm`].includes(e.config.sources.thumbnail)?[`thumbnailPrompt`]:[],...hj(e.config)&&e.config.reference?.source===`prompt`?[`referencePrompt`]:[],...e.config.intro===void 0?[]:[`intro`],...e.config.outro===void 0?[]:[`outro`]])].filter(n=>{let r=y7(n);if(r===void 0)return!0;let i=t[r]?.name;return i===void 0||e.config.imagePrompts.some(e=>e.name===i)}),s=e.config.imagePrompts.filter(e=>!t.some(t=>t.name===e.name)),c=e=>qye(e,t),l=[...new Set([...Object.keys(e.config.values),...Object.values(e.content.promptTemplates).flatMap(e=>e===null?[]:dq(e).names)])].filter(e=>!fq.includes(e)),u=t=>[...dq(e.config.title).names.includes(t)?[`Project title`]:[],...Object.entries(e.content.promptTemplates).flatMap(([e,n])=>n!==null&&dq(n).names.includes(t)?[c(e)]:[])],d=dq(e.config.title).names;return(0,h.jsxs)(`section`,{"aria-label":`Prompt snapshots`,className:`space-y-6`,children:[o.map(o=>{let s=c(o),l=e.content.promptTemplates[o]??null,u=o===`intro`||o===`outro`?r.filter(e=>e.category===o):n.filter(t=>t.kind===(o===`article`?UA(e.config)?`script`:`article`:o===`narration`?`narration`:o===`description`?`description`:o===`shorts`?`shorts`:o===`thumbnailPrompt`?`thumbnail`:`image`));return(0,h.jsxs)(`div`,{className:`min-w-0 space-y-4 border-t border-line pt-6 first:border-t-0 first:pt-0`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:s}),l===null?(0,h.jsx)(SI,{tone:`info`,title:`Original template unavailable`,actions:(0,h.jsx)(R,{"aria-label":`Use saved wording as template for ${s}`,onClick:()=>i(A5(e,o,e.config.rendered[o]??``)),children:`Use saved wording as template`}),children:`The saved prompt below stays as it is until you choose or write a template.`}):null,(0,h.jsx)(Kye,{label:s,raw:l,library:Gye(e,o,u,t),onUse:t=>i(A5(e,o,t))}),(0,h.jsx)(xV,{label:`Use saved template for ${s}`,id:`${a}-library-${o}`,tip:`project.prompts.template`,children:(0,h.jsxs)(TV,{value:``,onChange:t=>{let n=u.find(e=>e.id===t.target.value);if(n===void 0)return;let r=A5(e,o,n.body),a=`category`in n?{...r.config,[n.category]:{name:n.name,mode:n.mode}}:o===`article`?{...r.config,articlePrompt:n.name}:o===`narration`?{...r.config,narrationPrompt:n.name}:o===`description`?{...r.config,descriptionPrompt:n.name}:(o===`shorts`||o===`shortsImage`)&&r.config.shorts!==void 0?{...r.config,shorts:{...r.config.shorts,[o===`shorts`?`prompt`:`imagePrompt`]:n.name}}:o===`thumbnailPrompt`?{...r.config,thumbnailPrompt:n.name}:o===`referencePrompt`&&r.config.reference!==void 0?{...r.config,reference:{...r.config.reference,prompt:n.name}}:r.config;i({...r,config:a})},children:[(0,h.jsx)(`option`,{value:``,children:`Choose a saved template`}),u.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,h.jsx)(xV,{label:`Raw prompt for ${s}`,id:`${a}-raw-${o}`,tip:`project.prompts.raw`,children:(0,h.jsx)(wV,{rows:4,value:l??``,onChange:t=>i(A5(e,o,t.target.value))})}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`text-small text-ink-2`,children:`Saved rendered prompt`}),(0,h.jsx)(`pre`,{className:`m-0 mt-2 whitespace-pre-wrap break-words text-small`,children:e.config.rendered[o]??``})]})]},o)}),s.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s.map(e=>`"${e.name}"`).join(`, `),` `,s.length===1?`uses its`:`use their`,` Library wording. Save, then change it here.`]}),l.length?(0,h.jsxs)(`section`,{"aria-label":`Keywords`,className:`space-y-3 pt-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:`Keywords`}),(0,h.jsx)(_0,{fieldPrefix:`config.values`,keywords:l.map(t=>({name:t,value:e.config.values[t]??``,feeds:u(t),topic:d.includes(t)})),onChange:(t,n)=>i(k5({...e,config:{...e.config,values:{...e.config.values,[t]:n}}}))})]}):null]})}function Gye(e,t,n,r){let{config:i}=e,a=y7(t);if(t===`intro`||t===`outro`){let e=i[t]?.name;return e===void 0||e===``?void 0:n.find(t=>`category`in t&&t.name===e)}let o=t===`article`?i.articlePrompt:t===`narration`?i.narrationPrompt:t===`description`?i.descriptionPrompt:t===`shorts`?i.shorts?.prompt:t===`shortsImage`?i.shorts?.imagePrompt:t===`thumbnailPrompt`?i.thumbnailPrompt:t===`referencePrompt`?i.reference?.prompt:a===void 0?void 0:r[a]?.name;if(o!==void 0&&o!==``)return n.find(e=>!(`category`in e)&&e.name===o)}var g7=`slopify.library-kept`;function _7(e){let t=5381;for(let n=0;n<e.length;n+=1)t=(t*33^e.charCodeAt(n))>>>0;return t.toString(36)}function v7(){try{let e=window.localStorage.getItem(g7),t=e===null?[]:JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Kye({label:e,raw:t,library:n,onUse:r}){let i=n===void 0||t===null?``:`${e}:${_7(t)}:${_7(n.body)}`,[a,o]=(0,m.useState)(()=>v7().includes(i));return n===void 0||t===null||n.body===t||a?null:(0,h.jsx)(SI,{tone:`info`,title:`The Library's "${n.name}" has changed since this project copied it`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{"aria-label":`Use the Library version for ${e}`,onClick:()=>{r(n.body)},children:`Use the Library version`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Keep this project's version for ${e}`,onClick:()=>{try{window.localStorage.setItem(g7,JSON.stringify([...v7().filter(e=>e!==i),i].slice(-200)))}catch{}o(!0)},children:`Keep this project's version`})]}),children:`The project uses its own copy below until you choose. Using the Library version marks what it wrote as outdated, to remake when you are ready.`})}function y7(e){let t=/^imagePrompts\.(\d+)$/.exec(e);return t?.[1]===void 0?void 0:Number(t[1])}function qye(e,t){if(e===`article`)return`Article`;if(e===`narration`)return`Narration Preparation`;if(e===`description`)return`YouTube description`;if(e===`shorts`)return`Shorts`;if(e===`shortsImage`)return`Shorts image style`;if(e===`thumbnailPrompt`)return`Thumbnail`;if(e===`referencePrompt`)return`Establishing image`;if(e===`intro`)return`Intro`;if(e===`outro`)return`Outro`;let n=y7(e);if(n!==void 0){let e=t[n]?.name;return e===void 0||e===``?`Image prompt ${String(n+1)}`:`Image prompt "${e}"`}return e.replace(/[._-]/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`)}function Jye(e,t,n){let{api:r}=z(),[i,a]=(0,m.useState)({busy:!1}),{config:o}=t,s=o.audio,c=async()=>{if(s!==void 0){a({busy:!0});try{let i=await Rs(r,e),{sharedGlossary:c,...l}=o;n({...t,config:{...l,audio:{...s,shareGlossary:!0},...i.entries.length===0?{}:{sharedGlossary:i.entries}}}),a({busy:!1,projects:i.projects})}catch(e){a({busy:!1,error:e instanceof Error?e.message:String(e)})}}},l=()=>{if(s===void 0)return;let{sharedGlossary:e,...r}=o;n({...t,config:{...r,audio:{...s,shareGlossary:!1}}})},u=o.sharedGlossary?.length??0,d=s?.shareGlossary===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[i.error===void 0?u===0?`No pronunciations from other projects are copied yet.`:`${String(u)} ${u===1?`term`:`terms`} copied from ${i.projects===void 0?`your other projects`:`${String(i.projects)} other ${i.projects===1?`project`:`projects`}`}.`:`Couldn't read your other projects' pronunciations: ${i.error}`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:i.busy,onClick:()=>void c(),children:i.busy?`Copying…`:`Update from other projects`}),(0,h.jsx)(V,{id:`project.edit.update-glossary`})]}):void 0;return{value:s?.shareGlossary===!0,onChange:e=>{e?c():l()},note:d}}function Yye(e,t){let{api:n}=z(),[r,i]=(0,m.useState)({busy:!1}),{config:a}=e,o=a.audio,s=async()=>{if(o!==void 0){i({busy:!0});try{let{aliases:r}=await zs(n),{narrationAliases:s,...c}=a;t({...e,config:{...c,audio:{...o,useNarrationAliases:!0},...r.length===0?{}:{narrationAliases:r}}}),i({busy:!1})}catch(e){i({busy:!1,error:e instanceof Error?e.message:String(e)})}}},c=a.narrationAliases?.length??0;return{value:o?.useNarrationAliases===!0,onChange:n=>{if(o!==void 0){if(n)s();else{let{narrationAliases:n,...r}=a;t({...e,config:{...r,audio:{...o,useNarrationAliases:!1}}})}}},note:o?.useNarrationAliases===!0?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-label text-ink-2`,children:[r.error===void 0?c===0?`No aliases are copied yet. Add some in Library → Aliases.`:`${String(c)} ${c===1?`alias`:`aliases`} copied from Library → Aliases.`:`Couldn't read Library → Aliases: ${r.error} Try Update from Library again.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,disabled:r.busy,onClick:()=>void s(),children:r.busy?`Copying…`:`Update from Library`}),(0,h.jsx)(V,{id:`project.edit.update-aliases`})]}):void 0}}function Xye({projectId:e,edit:t,providers:n,voices:r,onChange:i}){let{config:a}=t,o=a.llm??{provider:``,model:``},s=a.audio??{provider:``,model:``,voice:``},c=Jye(e,t,i),l=Yye(t,i),{api:u}=z(),d=N(Qb(u,a.channelId??`00000000-0000-4000-8000-000000000001`)),f=a.images??{provider:``,model:``},p=uj(a)||a.sources.audio===`generate`&&a.audio?.describeFigures===!0||a.sources.research===`generate`||a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||HA(a)&&a.voices?.source===`attribute`||a.sources.audio===`generate`&&(a.intro?.mode===`llm`||a.outro?.mode===`llm`),m=a.sources.images===`generate`||a.sources.thumbnail===`from_prompt`||a.sources.thumbnail===`prompt_by_llm`,g=r.filter(e=>e.provider===s.provider).map(e=>({value:e.voiceId,label:e.name}));return(0,h.jsxs)(`section`,{"aria-label":`Generation providers`,className:`grid min-w-0 gap-3 sm:grid-cols-2`,children:[p?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Text provider`,tip:`play.llm.provider`,family:`llm`,providers:n,value:o.provider,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Text model`,tip:`play.llm.model`,provider:o.provider,value:o.model,problem:void 0,onPick:e=>i({...t,config:{...a,llm:{...o,model:e}}})}),(0,h.jsx)(b6,{choice:o,onChange:e=>i({...t,config:{...a,llm:e}})})]}):null,a.sources.audio===`generate`?(0,h.jsxs)(h.Fragment,{children:[a.voices!==void 0&&a.intro===void 0&&a.outro===void 0?null:(0,h.jsxs)(h.Fragment,{children:[a.voices===void 0?null:(0,h.jsx)(`p`,{className:`col-span-full m-0 text-small text-ink-2`,children:`The voice below reads only the intro and outro. Each speaker's voice is set under Speakers.`}),(0,h.jsx)(RV,{label:a.voices===void 0?`Narration provider`:`Intro and outro provider`,tip:`play.tts.provider`,family:`tts`,providers:n,value:s.provider,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,provider:e,model:``,voice:``}}})}),(0,h.jsx)(zV,{label:a.voices===void 0?`Narration model`:`Intro and outro model`,tip:`play.tts.model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>i({...t,config:{...a,audio:{...s,model:e}}})}),(0,h.jsx)(FV,{label:a.voices===void 0?`Narration voice`:`Intro and outro voice`,tip:`play.voice`,value:s.voice,problem:void 0,placeholder:`Choose a saved voice`,options:s.voice!==``&&!g.some(e=>e.value===s.voice)?[{value:s.voice,label:`${s.voice} (saved voice)`},...g]:g,onPick:e=>i({...t,config:{...a,audio:{...s,voice:e}}})})]}),(0,h.jsx)(q3,{value:a.chunking??{mode:`whole`},onPick:e=>i({...t,config:{...a,chunking:e}})}),(0,h.jsx)(_6,{shared:c,value:s.usePronunciationGlossary,supported:Sj({sources:a.sources,audio:{...s,usePronunciationGlossary:!0}}),onChange:e=>i({...t,config:{...a,audio:{...s,usePronunciationGlossary:e}}})}),(0,h.jsx)(h6,{...l}),(0,h.jsx)(p6,{tip:`project.edit.describe-figures`,value:s.describeFigures,skipCode:s.skipCode,onChange:({describeFigures:e,skipCode:n})=>{let{describeFigures:r,skipCode:o,...c}=s;i({...t,config:{...a,audio:{...c,...e?{describeFigures:e}:{},...e&&n?{skipCode:n}:{}}}})}}),(0,h.jsxs)(`section`,{"aria-label":`Speakers`,className:`col-span-full border-t border-line pt-3`,children:[(0,h.jsx)(`h3`,{className:`mb-2 text-small font-semibold`,children:`Speakers`}),(0,h.jsx)(f6,{value:a.voices,cast:d.data?.cast??[],language:a.language,providers:n,voices:r,script:t.content.articleMarkdown??void 0,onChange:e=>{let{voices:n,...r}=a;i({...t,config:e===void 0?r:{...r,voices:e}})}})]})]}):null,m?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(RV,{label:`Image provider`,tip:`play.images.provider`,family:`image`,providers:n,value:f.provider,problem:void 0,onPick:e=>i({...t,config:{...a,images:{provider:e,model:``}}})}),(0,h.jsx)(zV,{label:`Image model`,tip:`play.images.model`,provider:f.provider,value:f.model,problem:void 0,onPick:e=>i({...t,config:{...a,images:{...f,model:e}}})}),(0,h.jsx)(b6,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:f,onChange:e=>i({...t,config:{...a,images:e}})})]}):null]})}function Zye({edit:e,providers:t,prompts:n,problem:r,onChange:i}){let{config:a}=e,o=a.reviews===void 0?HV:jk(a.reviews),[s,c]=(0,m.useState)(o),l=a.shorts?.enabled===!0&&a.sources.audio!==`off`,u=e=>Nk({sources:a.sources,shorts:l?{enabled:!0}:void 0},e),d=Mk(s,u).retriesProblem;return(0,h.jsx)(UV,{value:s,providers:t,prompts:n,makes:u,problem:e=>e===`reviews.retries`&&d!==void 0?d:r(e),onChange:t=>{c(t);let{settings:r}=Mk(t,u),o={...e.content.promptTemplates},s={...a.rendered};for(let e of Ck){let t=Ak(e),i=r?.stages[e]?.prompt??``,c=n.find(e=>e.kind===`review`&&e.name===i);if(i===``){let{[t]:e,...n}=o,{[t]:r,...i}=s;o=n,s=i}else c!==void 0&&i!==(a.reviews?.stages[e]?.prompt??``)&&(o={...o,[t]:c.body})}let{reviews:l,...d}=a;i(k5({...e,config:{...d,rendered:s,...r===void 0?{}:{reviews:r}},content:{...e.content,promptTemplates:o}}))}})}function Qye({edit:e,view:t,prompts:n,problem:r,onChange:i}){let a=t.revision.config.descriptionPrompt,o=t.revision.content.promptTemplates.description??t.revision.config.rendered.description,s=a&&o!==void 0&&!n.some(e=>e.kind===`description`&&e.name===a)?[...n,{id:`saved-description`,kind:`description`,name:a,body:o,slots:[],updatedAt:t.revision.createdAt}]:n,c=t.outputs.some(e=>e.selected&&e.workKey===b7&&e.state===`ready`),l=e.regenerate?.includes(b7)===!0;return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(C6,{enabled:e.config.youtubeDescription===!0,prompt:e.config.descriptionPrompt??``,prompts:s,narrated:e.config.sources.audio!==`off`,problem:r,onChange:({youtubeDescription:t,descriptionPrompt:n})=>{let r=s.find(e=>e.kind===`description`&&e.name===n),a=n===(e.config.descriptionPrompt??``)?e:r===void 0?$ye(e):A5(e,`description`,r.body),{descriptionPrompt:o,...c}=a.config;i({...a,config:{...c,youtubeDescription:t,...n===``?{}:{descriptionPrompt:n}}})}}),c&&e.config.youtubeDescription===!0?l?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The YouTube description will be written again after you save and press Remake.`,(0,h.jsx)(R,{type:`button`,variant:`quiet`,onClick:()=>{i({...e,regenerate:(e.regenerate??[]).filter(e=>e!==b7)})},children:`Keep the current description`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{type:`button`,onClick:()=>{i({...e,regenerate:[...new Set([...e.regenerate??[],b7])]})},children:`Write the description again after review`}),(0,h.jsx)(V,{id:`project.edit.rewrite-description`})]}):null]})}var b7=`youtube:description`;function $ye(e){let{description:t,...n}=e.content.promptTemplates,{description:r,...i}=e.config.rendered;return k5({config:{...e.config,rendered:i},content:{...e.content,promptTemplates:n}})}var ebe={research:`Research source`,article:`Article source`,audio:`Audio source`,images:`Images source`,thumbnail:`Thumbnail source`,video:`Video source`,document:`Document source`},tbe={research:`play.source.research`,article:`play.source.article`,audio:`play.source.audio`,images:`play.source.images`,thumbnail:`play.source.thumbnail`,video:`play.source.video`,document:`play.source.document`},nbe=`\0kept:`;function x7({title:e,children:t,columns:n=!0}){return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:e}),(0,h.jsx)(`div`,{className:L(`grid min-w-0 gap-4`,n&&`md:grid-cols-2`),children:t})]})}function rbe(e){let{view:t,edit:n,onChange:r,onPending:i,fields:a}=e,o=(0,m.useId)(),[s,c]=(0,m.useState)(e.focus?.section??`inputs`);(0,m.useEffect)(()=>{e.focus!==void 0&&c(e.focus.section)},[e.focus]);let[l,u]=(0,m.useState)({font:!1,content:!1,music:!1});(0,m.useEffect)(()=>{i(l.font||l.content||l.music)},[i,l]);let d=(0,m.useCallback)(e=>{u(t=>t.font===e?t:{...t,font:e})},[]),f=(0,m.useCallback)(e=>{u(t=>t.content===e?t:{...t,content:e})},[]),p=(0,m.useCallback)(e=>{u(t=>t.music===e?t:{...t,music:e})},[]),{api:g}=z(),_=N(eb(g)),v=N(tb(g)),y=N(nb(g)),b=N(rb(g)),{config:x}=n,S=Hye(t,n,N(Qb(g,x.channelId??`00000000-0000-4000-8000-000000000001`)).data?.cast??[]),C=S?.image.kind===`output`?t.outputs.find(e=>e.selected&&e.available&&S.image.kind===`output`&&e.output.id===S.image.outputId):void 0,w=C===void 0?void 0:s2(g,t.revision.projectId,t.revision.id,C.recordId),T=e=>a.find(t=>t.field===e||t.field===`config.${e}`||t.field===`edit.config.${e}`)?.message,E=w6({value:x.videoEdit,narrated:x.sources.audio!==`off`,imageProvider:x.images?.provider??``,problem:T,language:x.language,onChange:e=>r({...n,config:{...x,videoEdit:e}})}),D=[{id:`inputs`,label:`Inputs`},...x.sources.article===`off`?[]:[{id:`article`,label:`Article`,...n.content.articleEdited?{badge:`edited`}:{}}],{id:`providers`,label:`Providers`},{id:`prompts`,label:`Prompts`},{id:`reviews`,label:`Reviews`,...x.reviews===void 0?{}:{badge:`on`}},...x.sources.audio!==`off`||x.shorts?.enabled===!0?[{id:`shorts`,label:`Shorts`,...x.shorts?.enabled?{badge:`on`}:{}}]:[],...x.sources.article===`off`?[]:[{id:`subtitles`,label:`Subtitles`}],{id:`images`,label:`Images`,badge:String(n.content.imageOrder.length)},...x.sources.audio===`generate`?[{id:`narration`,label:`Narration`}]:[],...x.sources.article===`off`?[]:[{id:`captions`,label:`Captions`,...n.content.subtitleCues===void 0?{}:{badge:String(n.content.subtitleCues.cues.length)}}]],O=D.some(e=>e.id===s)?s:`inputs`,k=e=>L(`min-w-0 space-y-6`,O===e?void 0:`hidden`),A=e=>Number.isFinite(e)?e:``,ee=x.sources.video!==`off`;return(0,h.jsxs)(`div`,{className:`grid min-w-0 gap-8 md:grid-cols-[180px_minmax(0,1fr)]`,children:[(0,h.jsx)(`nav`,{"aria-label":`Edit sections`,className:`min-w-0 md:sticky md:top-16 md:self-start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none gap-1 overflow-x-auto p-0 [scrollbar-width:none] md:flex-col`,children:D.map(e=>(0,h.jsx)(`li`,{className:`shrink-0`,children:(0,h.jsx)(t8,{current:e.id===O,onClick:()=>c(e.id),meta:e.badge,className:`whitespace-nowrap`,children:e.label})},e.id))})}),(0,h.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[Object.entries({providers:_.error,voices:v.error,prompts:y.error,entries:b.error}).flatMap(([e,t])=>t===null?[]:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:t.message},e)]),a.length===0?null:(0,h.jsx)(`ul`,{role:`alert`,className:`m-0 space-y-1 pl-5 text-small text-danger`,children:a.map(e=>(0,h.jsx)(`li`,{children:e.message},`${e.field}-${e.message}`))}),(0,h.jsxs)(`section`,{"aria-label":`Inputs`,hidden:O!==`inputs`,className:k(`inputs`),children:[(0,h.jsxs)(x7,{title:`Project`,children:[(0,h.jsx)(xV,{label:`Project title`,error:T(`title`),className:`md:col-span-2`,children:(0,h.jsx)(CV,{value:x.title,maxLength:200,onChange:e=>r({...n,config:{...x,title:e.target.value}})})}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(U6,{value:x.format,onPick:e=>r({...n,config:{...x,format:e}})})})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Channel`,columns:!1,children:(0,h.jsx)(Vye,{edit:n,saved:t.revision.config,problem:T,onChange:r})}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Stages`,children:[FS.filter(e=>x.sources.article!==`off`||e!==`research`&&e!==`audio`&&e!==`document`).map(e=>(0,h.jsx)(xV,{label:ebe[e],tip:tbe[e],error:T(`sources.${e}`),children:(0,h.jsx)(TV,{value:RS(x.sources,e),onChange:i=>{let a=FN(e).find(e=>e.value===i.target.value);if(a===void 0)return;let o=Sve(n,e,a.value);r(e===`article`&&a.value===`provide`&&!n.content.articleEdited?{...o,content:{...o.content,articleMarkdown:t.articleMarkdown??n.content.articleMarkdown}}:o)},children:FN(e).filter(t=>e!==`thumbnail`||t.value!==`prompt_by_llm`||x.sources.article!==`off`).map(t=>(0,h.jsx)(`option`,{value:t.value,disabled:e===`video`&&t.value===`generate`&&x.sources.images===`off`,children:t.label},t.value))})},e)),x.sources.images===`off`?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2 md:col-span-2`,children:`Images are Off. Video is also Off in these changes.`}):null,(0,h.jsx)(xV,{label:`Document theme`,id:`${o}-document-theme`,tip:`play.document-theme`,children:(0,h.jsx)(G3,{id:`${o}-document-theme`,disabled:RS(x.sources,`document`)===`off`,value:x.document,onChange:e=>{r({...n,config:{...x,document:e}})}})})]}),(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Timing`,children:[(0,h.jsx)(xV,{label:`Silence gap (seconds)`,tip:`play.silence-gap`,error:T(`silenceGapSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.1,value:A(x.silenceGapSeconds),onChange:e=>r({...n,config:{...x,silenceGapSeconds:Number(e.target.value)}})})}),x.sources.audio===`off`?null:(0,h.jsx)(xV,{label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,error:T(`edgeSilenceSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:30,step:.5,value:A(x.edgeSilenceSeconds),onChange:e=>r({...n,config:{...x,edgeSilenceSeconds:Number(e.target.value)}})})}),ee?(0,h.jsx)(xV,{label:`Seconds per image`,tip:`play.image-seconds`,error:T(`imageSeconds`),children:(0,h.jsx)(CV,{type:`number`,min:1,max:600,step:1,value:A(x.imageSeconds),onChange:e=>r({...n,config:{...x,imageSeconds:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Zoom (%)`,tip:`play.zoom`,error:T(`zoomPercent`),children:(0,h.jsx)(CV,{type:`number`,min:0,max:50,step:.5,value:A(x.zoomPercent),onChange:e=>r({...n,config:{...x,zoomPercent:Number(e.target.value)}})})}):null,ee?(0,h.jsx)(xV,{label:`Motion`,tip:`play.motion`,children:(0,h.jsx)(TV,{value:x.motionStyle,onChange:e=>r({...n,config:{...x,motionStyle:e.target.value}}),children:zS.map(e=>(0,h.jsx)(`option`,{value:e,children:YA[e]},e))})}):null]}),ee?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Cuts and look`,columns:!1,children:[E.cuts,E.look,x.sources.audio===`generate`&&x.audio?.describeFigures===!0?(0,h.jsx)(m6,{tip:`project.edit.show-figures`,value:x.showFigures,onChange:e=>{let{showFigures:t,...i}=x;r({...n,config:e?{...i,showFigures:!0}:i})}}):null]}),x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Ambient sound`,columns:!1,children:(0,h.jsx)(Cye,{edit:n,problem:T,onChange:r})})]})]}):null,x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsxs)(x7,{title:`Pauses and volume`,columns:!1,children:[(0,h.jsx)(Tye,{edit:n,problem:T,onChange:r}),(0,h.jsx)(wye,{edit:n,problem:T,onChange:r})]})]}),(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Intro and outro`,children:[`intro`,`outro`].map(e=>{let i=x[e]?.name,a=t.revision.content.promptTemplates[e],o=b.data?.entries.find(t=>t.category===e&&t.name===i),s=i!==void 0&&o!==void 0&&typeof a==`string`&&t.revision.config[e]?.name===i&&a!==o.body,c=n.content.promptTemplates[e],l=`${nbe}${i??``}`,u=i===void 0?``:s&&c!==o?.body?l:i;return(0,h.jsx)(xV,{label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,children:(0,h.jsxs)(TV,{value:u,onChange:i=>{if(i.target.value===l&&typeof a==`string`){r(k5({...n,config:{...x,[e]:t.revision.config[e]},content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:a}}}));return}let o=b.data?.entries.find(t=>t.category===e&&t.name===i.target.value),s={...x};o===void 0?delete s[e]:s[e]={name:o.name,mode:o.mode},r(k5({...n,config:s,content:o===void 0?n.content:{...n.content,promptTemplates:{...n.content.promptTemplates,[e]:o.body}}}))},children:[(0,h.jsx)(`option`,{value:``,children:`Off`}),i!==void 0&&!b.data?.entries.some(t=>t.category===e&&t.name===i)?(0,h.jsxs)(`option`,{value:i,children:[i,` (saved entry)`]}):null,s?(0,h.jsxs)(`option`,{value:l,children:[i,` · this project's version`]}):null,b.data?.entries.filter(t=>t.category===e).map(e=>(0,h.jsx)(`option`,{value:e.name,children:s&&e.name===i?`${e.name} · Library version (newer)`:e.name},e.id))]})},e)})}),x.sources.research===`provide`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mq,{}),(0,h.jsx)(x7,{title:`Research`,columns:!1,children:(0,h.jsx)(xV,{label:`Research notes`,tip:`play.provided.research`,error:T(`provided.research`),children:(0,h.jsx)(wV,{rows:6,value:x.provided.research??``,onChange:e=>r({...n,config:{...x,provided:{...x.provided,research:e.target.value}}})})})})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Article`,hidden:O!==`article`,className:k(`article`),children:[(0,h.jsx)(xV,{label:`Article text`,tip:`project.edit.article-text`,error:T(`content.articleMarkdown`)??T(`provided.article`),help:n.content.articleEdited?`Your edited article is kept when other settings change. Regenerating it replaces it after the rebuild review.`:void 0,children:(0,h.jsx)(wV,{rows:12,maxLength:5e5,value:(n.content.articleEdited?n.content.articleMarkdown:t.articleMarkdown)??n.content.articleMarkdown??x.provided.article??``,onChange:e=>r({...n,content:{...n.content,articleMarkdown:e.target.value,articleEdited:!0}})})}),x.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:()=>r({...n,regenerate:[...new Set([...n.regenerate??[],`article:body`])]}),children:`Regenerate article after review`}),(0,h.jsx)(V,{id:`project.edit.regenerate-article`})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Providers`,hidden:O!==`providers`,className:k(`providers`),children:[(0,h.jsx)(Bye,{edit:n,error:T(`language`),onChange:r}),(0,h.jsx)(Xye,{projectId:t.revision.projectId,edit:n,providers:_.data?.providers??[],voices:v.data?.voices??[],onChange:r}),(0,h.jsx)(Uye,{edit:n,view:t,prompts:y.data?.prompts??[],error:T(`narrationPrompt`),onChange:r})]}),(0,h.jsxs)(`section`,{"aria-label":`Prompts`,hidden:O!==`prompts`,className:k(`prompts`),children:[(0,h.jsx)(Qye,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r}),(0,h.jsx)(Wye,{edit:n,saved:t.revision.config.imagePrompts,prompts:y.data?.prompts??[],entries:b.data?.entries??[],onChange:r})]}),(0,h.jsx)(`section`,{"aria-label":`Reviews`,hidden:O!==`reviews`,className:k(`reviews`),children:(0,h.jsx)(Zye,{edit:n,providers:_.data?.providers??[],prompts:y.data?.prompts??[],problem:T,onChange:r})}),(0,h.jsx)(`section`,{"aria-label":`Shorts`,hidden:O!==`shorts`,className:k(`shorts`),children:(0,h.jsx)(Tve,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r,onPending:p})}),(0,h.jsxs)(`section`,{"aria-label":`Subtitles`,hidden:O!==`subtitles`,className:k(`subtitles`),children:[(0,h.jsx)(`div`,{"data-tour":`project-subtitles`,children:(0,h.jsx)(H6,{value:x.subtitles??hM,format:x.format,audioEnabled:x.sources.audio!==`off`,videoEnabled:ee,onChange:e=>r({...n,config:{...x,subtitles:ON(e,x.sources)}}),onUploading:d,problem:T})}),O!==`subtitles`||!ee?null:(0,h.jsx)(O6,{drawnOn:S?.drawnOn,poster:w,settings:{format:x.format,subtitles:{mode:(x.subtitles??hM).mode,fontId:(x.subtitles??hM).fontId,fontSize:(x.subtitles??hM).fontSize,position:(x.subtitles??hM).position??`bottom`},videoEdit:x.videoEdit,image:S?.image}})]}),e.renderContent?.({view:t,edit:n,fields:a,onChange:r,onPending:f,section:O})]})]})}var S7={notes:`Research notes`,article_md:`Article (Markdown)`,article_txt:`Article text`,narration_txt:`Clean Narration`,tts_script:`TTS Script`,sources:`Research sources`,glossary:`Glossary`,audio_body:`Narration`,audio_intro:`Intro narration`,audio_outro:`Outro narration`,audio_export:`Audio export`,image:`Image`,thumbnail:`Thumbnail`,video:`Video`,render_params:`Export settings`,subtitles_srt:`Subtitles (SRT)`,subtitles_vtt:`Subtitles (VTT)`,subtitle_words:`Subtitle timing`,subtitle_ass:`Styled subtitles`,subtitle_font:`Subtitle font`,instructions:`Generation instructions`,document_pdf:`Document (PDF)`,youtube_description:`YouTube description`,youtube_tags:`YouTube tags`,youtube_pinned_comment:`Pinned comment`,youtube_titles:`Other titles`,shorts:`Shorts list`,short_image:`Short image`,short_video:`Short`,animated_image:`Animated image`,figure_card:`On-screen card`,reference:`Establishing image (reference)`,script_md:`Script (speaker split)`,audio_mp3:`Audio (MP3 with chapters)`,audio_m4b:`Audiobook (M4B with chapters)`,audio_levelled:`Levelled narration`};function C7(e){return(e.role===`narration_txt`||e.role===`tts_script`)&&e.meta.segment?`${e.meta.segment===`body`?`Body`:e.meta.segment===`intro`?`Intro`:`Outro`} ${S7[e.role]}`:e.role===`short_video`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)}`:e.role===`short_image`&&typeof e.meta.short==`number`?`Short ${String(e.meta.short)} image ${String(e.meta.index??1)}`:e.role===`figure_card`&&typeof e.meta.index==`number`?`On-screen card ${String(e.meta.index)}`:e.role===`animated_image`&&typeof e.meta.index==`number`?`Animated image ${String(e.meta.index)}`:e.role===`image`&&typeof e.meta.index==`number`?`Image ${e.meta.index}`:S7[e.role]}function ibe(e){if(e.startsWith(`image:`))return`Image`;if(e.startsWith(`animate:`))return S7.animated_image;if(/^shorts:\d+:render$/.test(e))return S7.short_video;if(/^shorts:\d+:image:\d+$/.test(e))return S7.short_image;if(e===`document:pdf`)return S7.document_pdf;let t=e.split(`:`).at(-1);return Object.entries(S7).find(([e])=>e===t)?.[1]??`Saved output`}function w7({preview:e,pending:t,feedback:n,onStart:r,onCancel:i}){let a=ube(e),[o,s]=(0,m.useState)([]),[c,l]=(0,m.useState)(!1),u=(0,m.useId)(),d=e.work.filter(e=>e.disposition===`blocked`),f=e.providedReuseRequired.filter(e=>!o.includes(e)),p=e.work.filter(e=>e.disposition===`generate`||e.disposition===`local`||e.disposition===`review`).length,g=p===1?`Remake 1 output`:`Remake ${String(p)} outputs`,_=[...d.length===0?[]:[`${d.length===1?`1 item is`:`${d.length} items are`} unavailable (reasons above)`],...f.map(e=>`tick “Keep the provided content for ${a(e)}”`),...e.costs.unknown===0||c?[]:[`tick “I understand that ${e.costs.unknown} cost estimates are unknown”`]],v=_.length===0,y=obe.map(t=>({disposition:t,count:e.work.filter(e=>e.disposition===t).length})).filter(e=>e.count>0),b=e.costs.rows.some(e=>e.onPlan===!0),x=e.costs.apiLow,S=e.costs.apiHigh;return(0,h.jsxs)(`section`,{"aria-label":`Review affected rebuild`,className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-6 gap-y-3 sm:grid-cols-3`,children:[y.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:k7[e.disposition]}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:e.count})]},e.disposition)),(0,h.jsxs)(`div`,{className:`flex flex-col`,children:[(0,h.jsx)(`dt`,{className:`order-2 text-small text-ink-2`,children:e.costs.unknown>0?`known cost`:`cost`}),(0,h.jsx)(`dd`,{className:`order-1 m-0 font-condensed text-title-2 tabular-nums`,children:O7(e.costs.low,e.costs.high)})]})]}),b?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`CLI work: $0 on your plan${x===void 0||S===void 0?``:` · ~${O7(x,S)} via API`}.`}):null,d.length===0?null:(0,h.jsx)(SI,{tone:`danger`,title:`${d.length===1?`1 item can’t`:`${d.length} items can’t`} run, so this rebuild can’t start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:sbe(d,a).map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.what,`:`]}),` `,e.reason]},e.reason))})}),e.wholeRequestNotice===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.wholeRequestNotice}),e.warnings.map(e=>(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e},e)),(0,h.jsxs)(`div`,{className:`flex flex-col divide-y divide-line border-y border-line`,children:[e.review?.inputChanges.length?(0,h.jsx)(T7,{summary:`Changed inputs (${String(e.review.inputChanges.length)})`,children:(0,h.jsx)(`dl`,{className:`m-0 flex flex-col gap-3`,children:e.review.inputChanges.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`dt`,{className:`font-semibold`,children:e.label}),(0,h.jsxs)(`dd`,{className:`m-0 grid gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(E7,{label:`Before`,text:e.before}),(0,h.jsx)(E7,{label:`After`,text:e.after})]})]},e.label))})}):null,(0,h.jsxs)(T7,{summary:`Work items (${e.work.length}): ${y.map(e=>`${e.count} ${k7[e.disposition]}`).join(`, `)||`none`}`,children:[e.changedInputs.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 mb-3 flex flex-col gap-1 pl-5`,children:e.changedInputs.map(e=>(0,h.jsxs)(`li`,{children:[a(e.path),`:`,` `,e.after===null?`Removed`:e.before===null?`New output`:`Inputs changed`]},e.path))}),(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-2 pl-5`,children:e.work.map(t=>(0,h.jsxs)(`li`,{children:[a(t.key),`: `,k7[t.disposition],`. `,t.reason,t.inflight?` An already submitted request may still be billed.`:``,e.review?.requests.filter(e=>e.key===t.key).map(e=>(0,h.jsxs)(`div`,{children:[e.settings===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.settings}),e.text===null?null:(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small`,children:`View request text`}),(0,h.jsx)(`pre`,{className:`m-0 max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-small`,children:e.text})]})]},e.key))]},t.key))}),(0,h.jsxs)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:[`Retained outputs:`,` `,e.retained.map(e=>ibe(e.slot)).join(`, `)||`None`]})]}),e.costs.rows.length===0?null:(0,h.jsx)(T7,{summary:`Cost by step`,children:(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5`,children:e.costs.rows.map(e=>(0,h.jsxs)(`li`,{children:[a(e.stage),`: `,abe(e),`. `,e.detail]},`${e.stage}-${e.detail}`))})})]}),n,(0,h.jsxs)(`div`,{className:`sticky bottom-[-16px] -mx-4 flex flex-col gap-3 border-t border-line bg-raised px-4 py-3`,children:[e.providedReuseRequired.length===0&&e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small`,children:[e.providedReuseRequired.map(e=>(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:o.includes(e),onChange:t=>s(t.target.checked?[...o,e]:o.filter(t=>t!==e))}),(0,h.jsxs)(`span`,{children:[`Keep the provided content for `,a(e)]})]}),(0,h.jsx)(V,{id:`project.rebuild.keep-provided`,className:`-my-1`})]},e)),e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ob,children:[(0,h.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:t,checked:c,onChange:e=>l(e.target.checked)}),(0,h.jsxs)(`span`,{children:[`I understand that `,e.costs.unknown,` cost estimates are unknown.`]})]}),(0,h.jsx)(V,{id:`project.rebuild.unknown-costs`,className:`-my-1`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:t||!v,"aria-describedby":v?void 0:u,onClick:()=>r({acknowledgeUnknownCosts:c,confirmedProvidedWorkKeys:o}),children:t?`Starting the remake…`:g}),(0,h.jsx)(R,{disabled:t,onClick:i,children:`Keep things as they are`}),v||t?null:(0,h.jsx)(`p`,{id:u,className:`m-0 min-w-0 text-small text-ink-2`,children:`${g} is off until: ${_.join(`; `)}.`})]})]})]})}function T7({summary:e,children:t}){return(0,h.jsxs)(`details`,{className:`py-3 text-small`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold text-ink`,children:e}),(0,h.jsx)(`div`,{className:`mt-3`,children:t})]})}function E7({label:e,text:t}){return(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`pre`,{className:`m-0 max-h-40 overflow-auto whitespace-pre-wrap break-words text-small`,children:t??`Not set`})]})}var D7=e=>e===null?`Unknown`:e===0?`$0`:new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:e>0&&e<.01?4:2}).format(e);function O7(e,t){return e===t?D7(e):`${D7(e)}–${D7(t)}`}function abe(e){return e.onPlan===!0?`$0 on plan${e.apiLow===void 0||e.apiLow===null||e.apiHigh===void 0?``:` · ~${O7(e.apiLow,e.apiHigh??null)} via API`}`:O7(e.low,e.high)}var obe=[`generate`,`local`,`review`,`reuse`,`blocked`];function sbe(e,t){let n=new Map;for(let t of e){let e=t.reason.trim()||`No reason was given.`;n.set(e,[...n.get(e)??[],t.key])}return[...n].map(([e,n])=>({reason:e,what:n.length===1?t(n[0]??``):`${n.length} ${new Set(n.map(A7)).size===1?cbe(A7(n[0]??``)):`items`}`}))}function cbe(e){return/s$/u.test(e)?e:`${e.charAt(0).toLowerCase()}${e.slice(1)}s`}var k7={reuse:`kept as they are`,generate:`to make`,local:`built on this computer`,review:`to confirm`,blocked:`can't run`},lbe={"export:wav":`Audio export (WAV)`,"export:video":`Video export`,"subtitles:timing":`Subtitle timing`,"subtitles:cues":`Caption text and timing`,"subtitles:files":`Subtitle files`,"article:body":`Article`,"audio:provided":`Provided narration`,"audio:body:concat":`Combined narration`,"audio:intro":`Combined intro narration`,"audio:outro":`Combined outro narration`,"research:planner":`Research plan`,"research:notes":`Research notes`,"entry:intro:text":`Intro text`,"entry:outro:text":`Outro text`};function A7(e){let t=lbe[e];return t===void 0?{image:`Image request`,images:`Images`,audio:`Narration request`,article:`Article`,research:`Research`,thumbnail:`Thumbnail`,subtitles:`Subtitles`,video:`Video export`,export:`Export`,entry:`Intro or outro`}[e.split(`:`)[0]??``]??`Output`:t}function ube(e){let t=new Map,n=new Map;for(let t of e.work){let e=A7(t.key);n.set(e,(n.get(e)??0)+1)}let r=new Map;for(let i of e.work){let e=A7(i.key),a=(r.get(e)??0)+1;r.set(e,a),t.set(i.key,(n.get(e)??0)>1?`${e} ${a}`:e)}for(let n of e.review?.requests??[])t.set(n.key,n.label);return e=>t.get(e)??A7(e)}var dbe={llm:`Text generation`,image:`Images`,images:`Images`,tts:`Audio`,audio:`Audio`};function j7({error:e,refusal:t}){let n=(0,m.useRef)(null);return(0,m.useEffect)(()=>{(e!==void 0||t!==void 0)&&n.current?.focus()},[e,t]),e===void 0&&t===void 0?null:(0,h.jsxs)(`div`,{ref:n,role:`alert`,tabIndex:-1,"data-tone":`danger`,className:`sl-callout sl-callout--danger outline-none`,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),(0,h.jsx)(`p`,{className:`sl-callout__title m-0`,children:e??(t?.reason===`readiness`?t.fields.length>0?`This can't start yet. Fix the items below, then try again.`:`Slopify couldn't check your providers. Open Settings → Providers, make sure each one you use is set up, then try again.`:t?.message)}),t?.fields.length?(0,h.jsx)(`ul`,{className:`sl-callout__body m-0 list-disc pl-5`,children:t.fields.map(({field:e,message:t})=>(0,h.jsxs)(`li`,{children:[dbe[e.split(`.`)[0]??``]??`Project`,`: `,t]},`${e}:${t}`))}):null]})}var fbe=q({text:W().optional(),logicalText:W().optional(),title:W().optional(),notes:W().optional(),outline:K(W()).optional(),prompt:W().optional()});function pbe(e){if(e===null)return`No text was recorded for this part.`;try{let t=fbe.safeParse(JSON.parse(e));if(!t.success)return`Recorded text cannot be decoded.`;let{logicalText:n,text:r,title:i,notes:a,outline:o,prompt:s}=t.data;return[n,r,a?.trim()?[i,a].filter(e=>e?.trim()).join(`
305
305
 
306
306
  `):void 0,o?.filter(e=>e.trim()).map((e,t)=>`${t+1}. ${e}`).join(`
307
- `),s].find(e=>e?.trim())??`No text was recorded for this part.`}catch{return`Recorded text cannot be decoded.`}}function mbe({projectId:e,pending:t,onRestore:n}){let{api:r}=z(),[i,a]=(0,m.useState)(),o=N({queryKey:B.revisions(e),queryFn:async()=>{let t=await bfe(r,e);if(!t.ok)throw Error(t.message);return t.value.revisions}}),s=N({queryKey:B.revision(e,i??``),enabled:i!==void 0,queryFn:async()=>{if(i===void 0)throw Error(`Choose a version from History first.`);let t=await a2(r,e,i);if(!t.ok)throw Error(t.message);return t.value.view}}),c=s.data,l=c?.outputs.find(e=>e.selected&&e.available&&(e.output.role===`image`||e.output.role===`thumbnail`)),u=l??c?.outputs.find(e=>e.available);return(0,h.jsxs)(`section`,{"aria-label":`Project history`,className:`space-y-3`,children:[(0,h.jsx)(H,{title:`Project history`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:o.error.message}),(0,h.jsx)(`ol`,{className:`space-y-2`,children:o.data?.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(R,{type:`button`,onClick:()=>a(e.id),children:[e.title,` · `,e.createdAt,e.current?` · Current`:``]})},e.id))}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:s.error.message}),c===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:c.revision.config.title}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{variant:`primary`,disabled:t,onClick:()=>n(c.revision.id),children:`Restore this revision`}),l===void 0?null:(0,h.jsxs)(mS,{href:Tfe(r,e,c.revision.id),download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download all images`]}),u===void 0?null:(0,h.jsx)(u2,{projectId:e,asset:``,folder:{revisionId:c.revision.id,recordId:u.recordId}})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-3 p-0`,children:c.outputs.map(t=>(0,h.jsxs)(`li`,{className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:C7(t.output)}),(0,h.jsxs)(`span`,{className:`text-small text-ink-2`,children:[` · ${t.state}${t.selected?``:` · Earlier result`}`,t.available?``:` · File missing`]})]}),t.available?(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,"aria-label":`Download ${C7(t.output)}`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download`]}):null]}),t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained output`}),t.output.role===`video`?(0,h.jsx)(R0,{className:`max-w-[640px]`,label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):[`audio_export`,`audio_body`,`audio_intro`,`audio_outro`].includes(t.output.role)?(0,h.jsx)($8,{label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):t.output.role===`image`||t.output.role===`thumbnail`?(0,h.jsx)(z0,{className:`max-w-[480px]`,alt:C7(t.output),title:C7(t.output),meta:t.selected?`Current`:`Earlier result`,src:s2(r,e,c.revision.id,t.recordId)}):(0,h.jsx)(`p`,{children:`Use Download to inspect this retained file.`})]}):null]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained narration parts`,children:c.pieces.filter(e=>e.stageKind===`audio`&&e.assetId!==null).map(t=>(0,h.jsxs)(`li`,{children:[`Narration part `,t.piece.idx,t.selected?``:` · Earlier result`,t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained audio part`}),(0,h.jsx)($8,{label:`Narration part ${String(t.piece.idx)}`,src:s2(r,e,c.revision.id,t.recordId)}),(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download narration part`]})]}):(0,h.jsx)(`span`,{children:` · File missing`})]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained text parts`,children:c.pieces.filter(e=>e.assetId===null).map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(`details`,{children:[(0,h.jsxs)(`summary`,{children:[e.stageKind,` part `,e.piece.idx]}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words`,children:pbe(e.piece.payload)})]})},e.recordId))})]})]})}function j7(e,t,n){let r=JSON.stringify(t);return e?.payload===r?e:{payload:r,idempotencyKey:n()}}function hbe(e,t,n={}){let{api:r}=z(),i=_(),a=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved settings to show yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);return n.value.view}}),[o,s]=(0,m.useState)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(),[f,p]=(0,m.useState)(),[h,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(),w=(0,m.useRef)(void 0),T=(0,m.useRef)(void 0),E=(0,m.useRef)(void 0),D=(0,m.useRef)(n.onOpenEdit);D.current=n.onOpenEdit;let O=(0,m.useMemo)(()=>c!==void 0&&(o===void 0||(c.regenerate?.length??0)>0||(c.uploads?.length??0)>0||JSON.stringify(c.config)!==JSON.stringify(o.revision.config)||JSON.stringify(c.content)!==JSON.stringify(o.revision.content)),[c,o]),k=c!==void 0&&o!==void 0&&t!==null&&t!==o.revision.id,A=(0,m.useRef)(!1);async function ee(e){if(!A.current){A.current=!0,g(!0),x(void 0),C(void 0);try{await e()}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1,g(!1)}}}async function te(t){let n=await r2(r,e);if(!n.ok){C(n);return}return C(void 0),s(n.value.view),t&&l({config:structuredClone(n.value.view.revision.config),content:structuredClone(n.value.view.revision.content)}),n.value.view}async function ne(t){let n=await jo(r,e);return i.setQueryData(B.project(e),n),await i.invalidateQueries({queryKey:B.revisions(e)}),!t.current||n.revisionId!==t.revision.id?(C({ok:!1,reason:`conflict`,message:`The project changed again. Your draft is preserved.`,currentRevisionId:n.revisionId,fields:[]}),!1):(s(t),l(void 0),C(void 0),d(void 0),!0)}async function j(){if(v||o===void 0||c===void 0)return;let t={baseRevisionId:o.revision.id,edit:c},n=j7(w.current,t,()=>crypto.randomUUID());w.current=n;let i=await i2(r,e,{...t,idempotencyKey:n.idempotencyKey});if(!i.ok){C(i);return}await ne(i.value.view),w.current=void 0}async function re(t,n=u){if(n===void 0)return;let a={baseRevisionId:n.baseRevisionId,previewId:n.id,...t},o=j7(E.current,a,()=>crypto.randomUUID());E.current=o;let s=await Cfe(r,e,{...a,idempotencyKey:o.idempotencyKey});if(!s.ok){C(s),(s.reason===`stale-preview`||s.reason===`conflict`)&&d(void 0);return}E.current=void 0,d(void 0),await i.invalidateQueries({queryKey:B.project(e)})}async function M(t,n){let i=await te(!1);if(i===void 0)return;let a=await Sfe(r,e,{baseRevisionId:i.revision.id,request:t});if(!a.ok){C(a);return}let o=a.value.value;if(E.current=void 0,n&&gbe(o)){await re({acknowledgeUnknownCosts:!1,confirmedProvidedWorkKeys:[]},o);return}d(o)}async function ie(t){let n=o??a.data??await te(!1);if(n===void 0)return;let i={baseRevisionId:n.revision.id,targetRevisionId:t},s=j7(T.current,i,()=>crypto.randomUUID());T.current=s;let c=await yfe(r,e,{...i,idempotencyKey:s.idempotencyKey});if(!c.ok){C(c);return}await ne(c.value.view),T.current=void 0}return{saved:a,view:o,edit:c,preview:u,focus:f,pending:h,uploading:v,error:b,refusal:S,unsaved:O,remoteChanged:k,busy:h||v||c!==void 0||u!==void 0,setEdit:l,setUploading:y,openEditor:()=>void ee(async()=>{await te(!0)}),discard:()=>{l(void 0),C(void 0),y(!1),w.current=void 0},save:()=>void ee(j),reloadDraft:()=>void ee(async()=>{w.current=void 0,y(!1),await te(!0),C(void 0)}),reloadCurrent:()=>void ee(async()=>{T.current=void 0,E.current=void 0,d(void 0),await te(!1),await i.invalidateQueries({queryKey:B.project(e)})}),requestEdit:e=>void ee(async()=>{let t=o,n=c;if(t===void 0||n===void 0){if(t=await te(!1),t===void 0)return;n={config:structuredClone(t.revision.config),content:structuredClone(t.revision.content)}}l(e.change(n,t)),p({section:e.section}),D.current?.()}),regenerateNow:t=>void ee(async()=>{let n=e=>({...e,regenerate:[...new Set([...e.regenerate??[],...t])]});if(c!==void 0&&O){l(n(c)),p({section:`images`}),D.current?.();return}let i=await te(!1);if(i===void 0)return;let a=await i2(r,e,{baseRevisionId:i.revision.id,edit:n({config:structuredClone(i.revision.config),content:structuredClone(i.revision.content)}),idempotencyKey:crypto.randomUUID()});if(!a.ok){C(a);return}await ne(a.value.view)&&await M({kind:`selected`,workKeys:t},!0)}),review:(e,t)=>void ee(()=>M(e,t?.autoStart===!0)),start:e=>void ee(()=>re(e)),closePreview:()=>{h||(d(void 0),E.current=void 0)},restore:e=>void ee(()=>ie(e))}}function gbe(e){return!e.work.some(e=>e.disposition===`blocked`)&&e.providedReuseRequired.length===0&&e.costs.unknown===0}function _be({controller:e,renderEditor:t,active:n=!0,intro:r}){let i=e;return i.view===void 0||i.edit===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r??(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Saved revision`,info:`project.saved-revision`}),i.saved.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.saved.error.message}),i.saved.data===void 0?null:(0,h.jsx)(`ul`,{"aria-label":`Saved output status`,className:`sl-list m-0 list-none p-0`,children:i.saved.data.outputs.filter(e=>e.selected).map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:C7(e.output)}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.available?e.state===`ready`?`Ready`:e.state===`outdated`?`Outdated; the retained version stays until it is remade`:`Provided content needs review`:`Retained file missing`})]},e.recordId))})]}),i.preview===void 0&&n?(0,h.jsx)(A7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{children:[i.refusal?.reason===`conflict`&&n?(0,h.jsx)(R,{disabled:i.pending,onClick:i.reloadCurrent,children:`Reload current revision`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{disabled:i.busy,onClick:()=>i.review({kind:`allAffected`}),variant:`secondary`,children:`Choose what to remake`}),(0,h.jsx)(V,{id:`project.choose-remake`})]}),(0,h.jsx)(R,{variant:`primary`,disabled:i.busy,onClick:i.openEditor,children:`Edit project`})]})]}):(0,h.jsxs)(`form`,{"aria-label":`Edit project`,onSubmit:e=>{e.preventDefault(),i.save()},children:[(0,h.jsx)(`fieldset`,{disabled:i.pending,className:`m-0 min-w-0 border-0 p-0`,children:t({view:i.view,edit:i.edit,fields:i.refusal?.fields??[],onChange:i.setEdit,onPending:i.setUploading,...i.focus===void 0?{}:{focus:i.focus}})}),i.preview===void 0?(0,h.jsx)(A7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:i.remoteChanged?`warning`:`info`,children:i.remoteChanged?`A newer revision is available. Your unsaved changes are kept below.`:i.uploading?`Waiting for uploads to finish…`:void 0}),children:[i.remoteChanged||i.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:i.pending||i.uploading,onClick:i.reloadDraft,children:`Reload current revision and discard my draft`}):null,(0,h.jsx)(R,{variant:`quiet`,disabled:i.pending||i.uploading,onClick:i.discard,children:`Discard changes`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:i.pending||i.uploading,children:`Save changes`})]})]})}function vbe({controller:e,projectId:t,active:n}){let r=e;return n?(0,h.jsxs)(h.Fragment,{children:[r.preview===void 0&&(r.error||r.refusal)?(0,h.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3`,children:[(0,h.jsx)(A7,{error:r.error,refusal:r.refusal}),r.edit===void 0&&r.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:r.pending,onClick:r.reloadCurrent,className:`self-start`,children:`Reload current revision`}):null]}):null,(0,h.jsx)(mbe,{projectId:t,pending:r.busy,onRestore:r.restore})]}):null}function ybe({controller:e}){let t=e;return(0,h.jsx)(YP,{open:t.preview!==void 0,title:`Choose what to remake`,onClose:t.closePreview,children:t.preview===void 0?null:(0,h.jsx)(ibe,{preview:t.preview,feedback:(0,h.jsx)(A7,{error:t.error,refusal:t.refusal}),pending:t.pending,onStart:t.start,onCancel:t.closePreview},t.preview.id)})}var bbe=(e,t)=>{if(t)return`waiting`;switch(e.state){case`running`:return`running`;case`done`:case`provided`:return`done`;case`failed`:return e.retryAt===void 0?`failed`:`waiting`;default:return`off`}},xbe=(e,t)=>{if(t)return`Held for you`;switch(e.state){case`running`:return`Running`;case`done`:return`Done`;case`provided`:return`Provided`;case`failed`:return e.retryAt===void 0?`Failed`:`Waiting to try again`;case`canceled`:return`Canceled`;case`skipped`:return`Off`;case`pending`:return`Not started`}};function Sbe(e,t){if(e.startedAt===null)return;let n=Date.parse(e.startedAt),r=e.finishedAt===null?t:Date.parse(e.finishedAt);if(!Number.isFinite(n)||!Number.isFinite(r)||r<n)return;let i=Math.round((r-n)/1e3);if(i<1)return;if(i<60)return`${String(i)} s`;let a=Math.round(i/60);return a<60?`${String(a)} min`:`${String(Math.floor(a/60))} h ${String(a%60)} min`}function Cbe(e,t,n){let r=T3(t,n);return r===void 0?e:e===void 0||e===``?E3(r):`${e} · ${E3(r)}`}function wbe({stages:e,outputs:t,project:n,resumable:r,held:i,now:a}){return e.filter(e=>e.state!==`skipped`).map(e=>{let o=i.some(t=>t.stage===e.kind),s=Sbe(e,a);return{id:e.id,name:e.kind===`video`&&rF(n.config)===`audio`?`Audio export`:r5[e.kind],tone:bbe(e,o),state:xbe(e,o),...s===void 0?{}:{time:s},detail:o?`Held for your review`:Cbe(cF(e,t,n,r),e,a)}})}function Tbe({stages:e}){return(0,h.jsx)(`div`,{className:`sr-only`,children:e.filter(e=>e.state!==`skipped`).map(e=>(0,h.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:`${r5[e.kind]}: ${e.state}`},e.id))})}function Ebe({steps:e}){return(0,h.jsxs)(`section`,{"aria-labelledby":`run-steps-title`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{id:`run-steps-title`,title:`Run`,size:`small`,className:`pb-0`}),(0,h.jsx)(O3,{steps:e,label:`Run steps`,dense:!0})]})}var M7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});function Dbe({cost:e,onOpen:t}){if(e===void 0||e.calls===0&&e.byStage.length===0)return null;let n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({key:`${e.account}/${t.kind}`,name:e.name,window:t.kind===`five_hour`?`5-hour`:t.kind===`weekly`?`weekly`:`current`,used:t.usedPercent,now:t.nowPercent})):[]);return(0,h.jsxs)(`section`,{"aria-labelledby":`cost-so-far-title`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{id:`cost-so-far-title`,title:`Cost so far`,size:`small`,className:`pb-0`,children:t===void 0?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`By stage`})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[(0,h.jsx)(`strong`,{className:`text-ink`,children:a7(e.cost)}),e.unpriced>0?` known, spent`:` spent`,e.apiEquivalent===null?null:` · ~${a7(e.apiEquivalent)} via API`,e.run===null||e.run.running?null:` · ${o7(e.run.workingMs)} of work`]}),n.map(e=>{let t=e.used<1?`under 1%`:`${M7.format(e.used)}%`,n=`${e.window} ${e.name} limit`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`${e.name}: ${t} of your ${e.window} limit`}),(0,h.jsx)(q2,{value:e.used/100,label:`Share of the ${n} this run used`,valueText:`${t} of your ${n}; now at ${M7.format(e.now)}%`,tone:e.now>=80?`waiting`:`accent`})]},e.key)})]})}function Obe({projectId:e,revisionId:t,title:n,open:r,onClose:i}){let{api:a}=z(),o=_(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=Oy(),g=(0,m.useRef)(!1),v=(0,m.useRef)(null);(0,m.useEffect)(()=>{r&&t!==null&&(c({revisionId:t,name:n}),f(null)),r||c(null)},[r,t,n]);async function y(){if(!s||g.current||!s.name.trim())return;g.current=!0,u(!0),f(null);let t=JSON.stringify([e,s.revisionId,s.name.trim()]);v.current?.key!==t&&(v.current={key:t,id:crypto.randomUUID()});try{let t=await qq(a,e,{id:v.current.id,name:s.name.trim(),revisionId:s.revisionId});if(!t.ok){v.current=null,f(t.message);return}v.current=null,i(),p(`Template saved.`,`success`),await o.invalidateQueries({queryKey:Lq})}catch(e){f(e instanceof Error?e.message:`The template wasn't saved. Press Save template to try again.`)}finally{g.current=!1,u(!1)}}return(0,h.jsx)(Ay,{open:r&&s!==null,onOpenChange:e=>{!e&&!g.current&&i()},title:`Save as template`,description:`Save this revision’s setup for a fresh Play draft. This does not rebuild the project.`,children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,required:!0,maxLength:200,disabled:l,value:s?.name??``,onChange:e=>{let t=e.target.value;c(e=>e&&{...e,name:t})}})}),d?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:d}):null,(0,h.jsxs)(`div`,{className:`sl-dialog__foot`,children:[(0,h.jsx)(R,{disabled:l,onClick:i,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:l||!s?.name.trim(),children:`Save template`})]})]})})}var N7=q({baseRevisionId:W().min(1).max(64),idempotencyKey:wD()}).strict(),kbe=rO(`kind`,[q({kind:pO(`resume`)}).strict(),q({kind:pO(`retry`),stage:J(FS)}).strict(),q({kind:pO(`rerun`),stage:J(FS)}).strict(),q({kind:pO(`redo`),item:W().min(1).max(200)}).strict()]);N7.extend({action:kbe}).strict();var Abe=rO(`ok`,[q({ok:pO(!0),value:K0.and(q({warnings:K(W()).readonly()}))}),q({ok:pO(!1),reason:J([`no-project`,`no-revision`,`conflict`,`idempotency-conflict`,`invalid-edit`,`stale-preview`,`invalid-selection`,`review-required`,`cost-ack-required`,`readiness`,`running`,`accepted-job`,`control-changed`]),fields:K(q({field:W(),message:W()})).readonly().optional(),intentRevisionId:W().optional(),currentRevisionId:W().nullable().optional()})]),P7=new Set([400,404,409]);async function jbe(e,t,n){return I7(e,t,`cancel`,n)}async function Mbe(e,t,n){return I7(e,t,`pause`,n)}function Nbe(e,t,n){return L7(e,t,`resume`,n)}function Pbe(e,t,n,r){return L7(e,t,`stages/${n}/retry`,r)}function Fbe(e,t,n,r){return L7(e,t,`stages/${n}/soften`,r)}function Ibe(e,t,n,r){return L7(e,t,`stages/${n}/rerun`,r)}async function Lbe(e,t,n){return F7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/providers`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function Rbe(e,t,n){return F7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/subtitles`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function zbe(e,t,n){return F7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/article`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({markdown:n})}))}async function Bbe(e,t,n){return F7(await e.client.projects[`:id`].images[`:outputId`].$delete({param:{id:t,outputId:n}}))}async function Vbe(e,t,n){return F7(await e.client.projects[`:id`].images[`:outputId`].regenerate.$post({param:{id:t,outputId:n}}))}async function F7(e){if(e.ok)return{ok:!0,value:await e.json()};let t=await mo(e);if(t!==void 0&&P7.has(e.status))return{ok:!1,message:po(e,t).message};throw po(e,t)}async function I7(e,t,n,r){let i=N7.parse(r);return F7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}))}async function L7(e,t,n,r){let i=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(N7.parse(r))});if(i.ok){let e=Abe.parse(await i.json());if(!e.ok)throw Error(xo);return{ok:!0,value:e.value,warnings:e.value.warnings}}let a=await mo(i);if(a!==void 0&&P7.has(i.status))return{ok:!1,message:po(i,a).message};throw po(i,a)}function Hbe(e){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(),s=(0,m.useRef)(new Map),c=(0,m.useRef)(!1),l=P({mutationFn:async e=>{let r=e.action;if(![`pause`,`cancel`,`resume`,`retry`,`soften`,`rerun`].includes(r.kind))return z7(t,e.projectId,r);let i=r.kind===`retry`||r.kind===`soften`||r.kind===`rerun`?r.stage:``,a=`${e.projectId}:${r.kind}:${i}`,o=s.current.get(a);if(!o){let r=n.getQueryData(B.project(e.projectId))?.revisionId;if(!r){let n=await r2(t,e.projectId);if(!n.ok)return{ok:!1,message:n.message};r=n.value.view.revision.id}o={baseRevisionId:r,idempotencyKey:crypto.randomUUID()},s.current.set(a,o)}let c=await z7(t,e.projectId,r,o);return s.current.delete(a),c.ok&&await jo(t,e.projectId).then(t=>n.setQueryData(B.project(e.projectId),t),e=>console.warn(`Project refresh after an accepted action failed`,e)),c},onMutate:()=>{i(void 0),o(void 0)},onSuccess:async(e,t)=>{e.ok?(o(`warnings`in e&&e.warnings.length>0?e.warnings.join(` `):void 0),n.invalidateQueries({queryKey:B.projects})):i({message:e.message,stage:R7(t.action)}),await n.invalidateQueries({queryKey:B.project(t.projectId)})},onSettled:()=>{c.current=!1},onError:(e,t)=>{i({message:e.message,stage:R7(t.action)})}});return{run:(t,n)=>{c.current||(c.current=!0,l.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok&&n?.()}}))},pending:l.isPending,performing:l.isPending?l.variables?.action:void 0,refusal:r,dismissRefusal:()=>{i(void 0)},notice:a}}function R7(e){switch(e.kind){case`cancel`:case`pause`:case`resume`:case`providers`:return;case`retry`:case`soften`:case`rerun`:return e.stage;case`subtitles`:return`video`;case`save-article`:return`article`;case`delete-image`:case`regenerate-image`:return`images`}}function z7(e,t,n,r){let i=()=>{if(!r)throw Error(`A saved revision and request identity are required.`);return r};switch(n.kind){case`pause`:return Mbe(e,t,i());case`cancel`:return jbe(e,t,i());case`resume`:return Nbe(e,t,i());case`retry`:return Pbe(e,t,n.stage,i());case`soften`:return Fbe(e,t,n.stage,i());case`rerun`:return Ibe(e,t,n.stage,i());case`providers`:return Lbe(e,t,n.choices);case`subtitles`:return Rbe(e,t,n.subtitles);case`save-article`:return zbe(e,t,n.markdown);case`delete-image`:return Bbe(e,t,n.outputId);case`regenerate-image`:return Vbe(e,t,n.outputId)}}var B7=e=>e.state===`done`||e.state===`provided`;function Ube(e){let t=e.find(e=>e.state===`failed`)??e.find(e=>e.state===`running`);if(t)return t.kind;let n=e.find(e=>e.kind===`video`&&B7(e));if(n)return n.kind;let r=e.find(e=>e.state===`pending`);return r?r.kind:e.find(e=>e.kind===`article`&&B7(e))?.kind??e.find(e=>e.state!==`skipped`)?.kind??`article`}function Wbe({projectId:e,openDraft:t}){return(0,h.jsx)(Gbe,{projectId:e,openDraft:t},e)}var V7=e=>{let t=e.filter(e=>e!==void 0);if(!(t.length===0||t.every(e=>e.state===`skipped`)))return t.some(e=>e.state===`failed`&&e.retryAt===void 0)?`failed`:t.some(e=>e.state===`running`)?`running`:t.some(e=>e.state===`failed`)?`waiting`:t.every(e=>e.state===`done`||e.state===`provided`||e.state===`skipped`)?`done`:`off`};function Gbe({projectId:e,openDraft:t}){let{api:n}=z(),r=Oy(),i=Jbe(e,t),a=N(Xy(n,e)),o=N(nb(n)),s=N(Zy(n,e)),c=Hbe(e),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),y=a.data?.revisionId??null,b=hbe(e,y,{onOpenEdit:()=>u(`settings`)}),x=uI(e),S=(0,m.useRef)(void 0);(0,m.useEffect)(()=>{if(x===void 0){S.current=void 0;return}a.data!==void 0&&S.current!==x&&(S.current=x,x===`download`&&u(rF(a.data.project.config)===`article`?`article`:`video`))},[x,a.data]),N3(e,y);let C=N({queryKey:Ny,queryFn:()=>Vy(n)}),w=Hy(C.data,e),T=N({queryKey:f3(e,y??``),queryFn:()=>m3(n,e),enabled:y!==null,retry:!1}),E=T.data?.ok===!0?T.data.value.checkpoints:[],D=b.saved.data?.outputs.filter(e=>e.selected&&e.state===`outdated`).map(e=>({workKey:e.workKey,role:e.output.role}))??[],O=a.data?.project,k=a.data?.stages??[],A=a.data?.outputs??[],ee=A.some(e=>e.role===`video`),te=e=>u(e),ne=q_e({project:O??Kbe,stages:k,resumable:a.data?.resumable??!1,sample:w,gates:E,outdated:D,waits:s.data?.waits??[],uploadReady:ee,actions:c,controller:b,openSection:te,openUpload:()=>f(!0)}),j=l===`settings`,re=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!j){re.current=!1;return}b.edit!==void 0&&(re.current=!0),!(re.current||b.busy)&&(re.current=!0,b.openEditor())},[j,b]);let M=k.some(e=>e.state===`running`),ie=O?.status===`running`,ae=O?.title??``,oe=ne.next?.action;bx({id:`project.next`,title:oe?.label??`Show the project's next action`,group:`This project`,context:ae,keywords:[`next`,`continue`,`resume`,`approve`,`retry`],shortcut:lP.nextAction,run:()=>{oe===void 0?r(`This project has no next action right now: nothing waits on you.`,`info`):oe.intent.kind===`soften`?r(`Soften and retry asks first: press it in the Next action panel on the right.`):ne.run(oe.intent)}}),Yx(Wx.showImages(e),()=>{let e=a.data?.stages.find(e=>e.kind===`images`);e===void 0||e.state===`skipped`?r(`${ae} makes no slideshow images, so there is no image to regenerate. To add them, open Settings in this project and choose how its images are made.`,`error`):u(`images`)},a.data!==void 0),bx({id:`project.pause`,title:O?.status===`paused`?`Continue the run`:`Pause the run`,group:`This project`,context:ae,keywords:[`pause`,`resume`,`continue`,`stop`],run:()=>c.run({kind:O?.status===`paused`?`resume`:`pause`})}),bx({id:`project.prepare-upload`,title:`Prepare upload`,group:`This project`,context:ae,keywords:[`youtube`,`studio`,`upload`,`publish`],run:()=>{ee?f(!0):r(`Prepare upload opens once the video has been made.`,`info`)}}),bx({id:`project.settings`,title:`Edit project settings`,group:`This project`,context:ae,keywords:[`edit`,`settings`,`prompts`,`providers`,`channel`],run:()=>u(`settings`)}),bx({id:`project.rebuild-review`,title:`Choose what to remake`,group:`This project`,context:ae,keywords:[`rebuild`,`review`,`remake`,`outdated`,`affected`],run:()=>b.review({kind:`allAffected`})}),bx({id:`project.template`,title:`Save as template`,group:`This project`,context:ae,keywords:[`template`,`reuse`],run:()=>g(!0)}),bx({id:`project.cancel`,title:`Cancel the run`,group:`This project`,context:ae,keywords:[`cancel`,`stop`],run:()=>v(!0)});let se=G_e(D);if(bx({id:`project.remake-1`,title:se[0]?.label??`Remake outdated outputs`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`],run:()=>{let e=se[0];e===void 0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0})}}),bx({id:`project.remake-all`,title:`Remake everything outdated`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`,`all`],run:()=>{let e=[...new Set(se.flatMap(e=>e.workKeys))];e.length===0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e},{autoStart:!0})}}),bx({id:`project.copy`,title:`Make my own copy`,group:`This project`,context:ae,keywords:[`sample`,`copy`,`duplicate`],run:()=>w?ne.run({kind:`copy-sample`}):r(`Only the sample project is copied this way.`,`info`)}),a.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The project could not be loaded.`,children:`${a.error.message} Reload the page to try again, or go back to Projects.`});if(a.data===void 0||O===void 0)return(0,h.jsx)(qbe,{});let ce=e=>k.find(t=>t.kind===e),le=ce(`article`),ue=ce(`research`),de=ce(`audio`),fe=ce(`images`),pe=ce(`thumbnail`),me=ce(`video`),he=ce(`document`),ge=O.config,_e=e=>e!==void 0&&e.state!==`skipped`,ve=ge.shorts?.enabled===!0||A.some(e=>e.role===`short_video`||e.role===`shorts`),ye=ge.youtubeDescription===!0||A.some(e=>e.role===`youtube_description`),be=E.filter(e=>e.state===`held`||e.state===`pending-review`),xe=[..._e(le)||_e(ue)?[{id:`article`,label:`Article`,tone:V7([le,ue])}]:[],..._e(de)?[{id:`narration`,label:`Narration`,tone:V7([de])}]:[],..._e(fe)||_e(pe)||ge.reference!==void 0?[{id:`images`,label:`Images`,tone:V7([fe,pe])}]:[],..._e(me)?[{id:`video`,label:rF(ge)===`audio`?`Audio export`:`Video`,tone:V7([me])}]:[],...ve?[{id:`shorts`,label:`Shorts`}]:[],...ye?[{id:`youtube`,label:`YouTube`}]:[],..._e(he)?[{id:`document`,label:`PDF`,tone:V7([he])}]:[],{id:`cost`,label:`Cost`},{id:`live`,label:`Live`}].map(e=>{let t=se.filter(t=>t.section===e.id).reduce((e,t)=>e+t.count,0);return t===0?e:{...e,meta:`${String(t)} outdated`}}),Se=[{id:`settings`,label:`Settings`,...b.unsaved?{meta:`unsaved`}:{}},...y===null?[]:[{id:`checkpoints`,label:`Checkpoints`,...be.length===0?{}:{meta:`${String(be.length)} held`}}],{id:`history`,label:`History`}],Ce=[...xe,...Se],we=ne.next?.situation,Te=ne.next?.section!==void 0&&we!==`done`&&we!==`running`?ne.next.section:we===`done`&&A.some(e=>e.role===`youtube_description`)?`youtube`:n5(Ube(k)),Ee=l!==void 0&&Ce.some(e=>e.id===l)?l:Ce.find(e=>e.id===Te)?.id??xe[0]?.id??`cost`,De=(...e)=>y===null?O.status===`running`||O.status===`paused`||M||c.pending:c.pending||e.some(e=>e?.state===`running`),Oe={project:O,outputs:A,actions:c,next:ne,resumable:a.data.resumable},ke=(e,t)=>e===void 0?null:(0,h.jsx)(zve,{stage:e,...t===void 0||t.state===`skipped`?{}:{companion:t},project:O,outputs:A,actions:c,busy:De(e,t)}),Ae=(...e)=>A.some(t=>e.some(e=>e!==void 0&&t.stageKind===e.kind)),je=(...e)=>Ae(...e)||e.some(e=>e!==void 0&&[`running`,`done`,`provided`,`failed`,`canceled`].includes(e.state)),Me=[{id:`rebuild`,label:`Choose what to remake…`,run:()=>b.review({kind:`allAffected`}),disabled:b.busy},{id:`template`,label:`Save as template…`,run:()=>g(!0),disabled:y===null||w},{id:`cancel`,label:`Cancel the run…`,run:()=>v(!0),disabled:!ie||c.pending,apart:!0}],Ne=t5({kind:`cancel`}),Pe=c.refusal?.stage===void 0?c.refusal:void 0,Fe=Pe===void 0?c.notice===void 0?b.preview===void 0&&(b.error||b.refusal)&&Ee!==`settings`&&Ee!==`history`?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:b.error??b.refusal?.message}):void 0:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:c.notice}):(0,h.jsx)(SI,{tone:`danger`,title:Pe.message,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,className:`mt-1`,onClick:c.dismissRefusal,children:`Dismiss`})}),Ie=wbe({stages:k,outputs:A,project:O,resumable:a.data.resumable,held:be.map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),now:Date.now()});return(0,h.jsx)(e_e,{projectId:e,revisionId:y,children:(0,h.jsx)(J8,{value:y!==null,children:(0,h.jsx)(g3,{value:e=>u(e===`edit`?`settings`:`article`),children:(0,h.jsx)(Y8,{value:b.pending||b.preview!==void 0?void 0:b.requestEdit,children:(0,h.jsxs)(X8,{value:b.pending||b.preview!==void 0?void 0:b.regenerateNow,children:[(0,h.jsxs)(`div`,{className:`sl-project`,children:[(0,h.jsx)(`div`,{"data-tour":`project-controls`,children:(0,h.jsx)(Xve,{project:O,prompts:o.data?.prompts,editing:Ee===`settings`,onEdit:()=>u(`settings`),more:Me,nextChapter:i,clock:(0,h.jsx)(rye,{cost:s.data,status:O.status,measuredAt:s.dataUpdatedAt})})}),(0,h.jsx)(Tbe,{stages:k}),(0,h.jsxs)(Aq,{sections:(0,h.jsxs)(e8,{label:`Project sections`,children:[xe.map(e=>(0,h.jsx)(U7,{item:e,selected:Ee,onSelect:te},e.id)),(0,h.jsx)(`hr`,{className:`sl-rule my-2`}),Se.map(e=>(0,h.jsx)(U7,{item:e,selected:Ee,onSelect:te},e.id))]}),aside:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Y_e,{state:ne,feedback:Fe}),O===void 0?null:(0,h.jsx)(Yve,{projectId:e,title:O.title,status:O.status,sample:w||C.isPending}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-6 max-[1180px]:hidden`,children:[(0,h.jsx)(Ebe,{steps:Ie}),(0,h.jsx)(Dbe,{cost:s.data,onOpen:()=>te(`cost`)}),(0,h.jsx)(Nge,{})]})]}),children:[(0,h.jsx)(u5,{id:`article`,title:`Article`,stages:[le,ue].filter(H7),active:Ee===`article`,...Oe,children:_e(le)||_e(ue)?ke(le,ue):(0,h.jsx)(d5,{stage:le,project:O,name:`Article`})}),(0,h.jsx)(u5,{id:`narration`,title:`Narration`,stages:[de].filter(H7),active:Ee===`narration`,...Oe,children:je(de)?ke(de):(0,h.jsx)(d5,{stage:de,project:O,name:`Narration`})}),(0,h.jsx)(u5,{id:`images`,title:`Images`,head:!1,stages:[fe,pe].filter(H7),active:Ee===`images`,...Oe,children:ke(fe,pe)}),(0,h.jsx)(u5,{id:`video`,title:rF(ge)===`audio`?`Audio export`:`Video`,stages:[me].filter(H7),active:Ee===`video`,...Oe,children:ke(me)}),me===void 0?null:(0,h.jsx)(u5,{id:`shorts`,title:`Shorts`,stages:[],active:Ee===`shorts`,...Oe,meta:`Vertical clips picked from the video, each with its title and hashtags`,children:(0,h.jsx)(Ave,{stage:me,project:O,outputs:A})}),me===void 0?null:(0,h.jsx)(u5,{id:`youtube`,title:`YouTube`,stages:[],active:Ee===`youtube`,...Oe,meta:`The description, chapters, hashtags and tags, as they go into YouTube Studio`,...ee&&ne.next?.action?.intent.kind!==`prepare-upload`?{extra:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>f(!0),children:`Prepare upload`})}:{},children:(0,h.jsx)(Bve,{stage:me,project:O,outputs:A})}),he===void 0?null:(0,h.jsx)(u5,{id:`document`,title:`PDF`,stages:[he],active:Ee===`document`,...Oe,children:je(he)?ke(he):(0,h.jsx)(d5,{stage:he,project:O,name:`PDF`})}),(0,h.jsx)(W7,{id:`cost`,title:`Run cost`,selected:Ee,children:(0,h.jsx)(tye,{projectId:e})}),(0,h.jsx)(W7,{id:`live`,title:`Live`,selected:Ee,children:Ee===`live`?(0,h.jsx)(fye,{project:O,revisionId:y,stages:k,outputs:A}):null}),(0,h.jsx)(W7,{id:`settings`,title:`Settings`,selected:Ee,children:(0,h.jsx)(_be,{controller:b,active:Ee===`settings`,renderEditor:e=>(0,h.jsx)(nbe,{...e,renderContent:e=>(0,h.jsx)(Rye,{...e},e.view.revision.id)})})}),y===null?null:(0,h.jsx)(W7,{id:`checkpoints`,title:`Checkpoints`,selected:Ee,children:(0,h.jsx)(Gve,{projectId:e,revisionId:y,paused:O.status===`paused`,stages:k,approvedInRail:ne.next?.action?.intent.kind===`approve`?ne.next.action.intent.gate.checkpointId:void 0})}),(0,h.jsx)(W7,{id:`history`,title:`History`,selected:Ee,children:(0,h.jsx)(vbe,{controller:b,projectId:e,active:Ee===`history`})})]})]}),(0,h.jsx)(ybe,{controller:b}),d?(0,h.jsx)(v2,{projectId:e,onClose:()=>f(!1)}):null,(0,h.jsx)(Obe,{projectId:e,revisionId:y,title:O.title,open:p,onClose:()=>g(!1)}),(0,h.jsx)(jy,{open:_,title:Ne.title,consequence:Ne.consequence,confirmLabel:Ne.verb,cancelLabel:Ne.dismiss,pending:c.pending,onConfirm:()=>{v(!1),c.run({kind:`cancel`})},onCancel:()=>v(!1)})]})})})})})}var H7=e=>e!==void 0;function U7({item:e,selected:t,onSelect:n}){return(0,h.jsx)(t8,{className:`max-md:w-auto`,"data-tour":`project-rail-${e.id}`,current:e.id===t,onClick:()=>n(e.id),...e.tone===void 0?{}:{icon:(0,h.jsx)(gS,{tone:e.tone})},...e.meta===void 0?{}:{meta:e.meta},children:e.label})}function W7({id:e,title:t,selected:n,children:r}){return(0,h.jsxs)(`section`,{hidden:n!==e,"aria-label":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:t}),r]})}var Kbe={id:``,title:``,format:`16:9`,status:`pending`,createdAt:``,config:{sources:{}}};function qbe(){return(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading project`,children:[(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-8 w-80 max-w-full rounded-control bg-sunken`})]}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(`div`,{className:`flex flex-col gap-2`,children:[`a`,`b`,`c`,`d`,`e`].map(e=>(0,h.jsx)(`span`,{className:`h-8 rounded-control bg-sunken`},e))}),aside:(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`}),children:(0,h.jsx)(`span`,{className:`h-[480px] rounded-control bg-sunken`})})]})}function Jbe(e,t){let{api:n}=z(),r=(0,m.useRef)(void 0),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0);if(t!==void 0)return{pending:i,error:o,run:()=>{i||(r.current??=crypto.randomUUID(),a(!0),s(void 0),Yq(n,e,r.current).then(async e=>{if(!e.ok){s(e.message);return}await t(e.value.draft.id)?r.current=void 0:s(`The next chapter's draft was made, but Play could not open it because the draft open there is not saved yet. Open Play, let it save, then press Make the next chapter again.`)}).catch(e=>s(`The next chapter could not be made (${e instanceof Error?e.message:`the connection dropped`}). Press Make the next chapter again.`)).finally(()=>a(!1)))}}}var Ybe=[`all`,`running`,`queued`,`waiting`,`ready`,`failed`];function Xbe(e){return Ybe.find(t=>t===e)}var G7=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`queued`,label:`Queued`},{value:`waiting`,label:`Needs you`},{value:`ready`,label:`Ready to upload`},{value:`failed`,label:`Failed`}];function K7(e,t){switch(t){case`all`:return!0;case`running`:return e.status===`running`||e.status===`paused`;case`queued`:return w3(e);case`waiting`:return y3(e);case`ready`:return C3(e);case`failed`:return e.status===`failed`||e.status===`partial`}}function Zbe(e){let t={running:{tone:`running`,word:`Running`},paused:{tone:`waiting`,word:`Paused`},pending:{tone:`off`,word:`Queued`},failed:{tone:`failed`,word:`Failed`},partial:{tone:`info`,word:`Done with problems`},done:{tone:`done`,word:`Done`},canceled:{tone:`off`,word:`Canceled`}};if(y3(e))return{tone:`waiting`,word:`Waiting for you`};let n=e.status===`running`?YH(e.limitWaits):void 0;return n===void 0?t[e.status]:{tone:`waiting`,word:n}}function Qbe(e){let t=e.config.articlePrompt,n=e.config.voices?.book;return[n===void 0?void 0:LA(n),t===void 0||t===``?void 0:t,e.format].filter(e=>e!==void 0).join(` · `)}function $be({initialFilter:e=`all`}={}){let{api:t}=z(),n=_(),r=Oy(),i=gx(),a=N(Yy(t)),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(e),u=N({queryKey:My,queryFn:()=>Iy(t)}),d=new Set(Object.values(u.data?.samples??{}).filter(e=>e!==null)),[f,p]=(0,m.useState)(``),g=(0,m.useRef)(null),v=xx(g,`projects`),y=P({mutationFn:e=>No(t,e),onSettled:async()=>{s(void 0),await n.invalidateQueries({queryKey:B.projects})}}),b=P({mutationFn:e=>S3(t,e.project.id,e.uploaded),onError:(e,t)=>r(`${t.project.title} wasn't changed: ${e.message} Press the button again.`,`error`),onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});bx({id:`projects.show.waiting`,title:`Show projects that need you`,group:`Projects`,keywords:[`waiting`,`filter`],run:()=>l(`waiting`)}),bx({id:`projects.show.ready`,title:`Show videos ready to upload`,group:`Projects`,keywords:[`upload`,`finished`,`filter`],run:()=>l(`ready`)}),bx({id:`projects.show.failed`,title:`Show failed projects`,group:`Projects`,keywords:[`error`,`filter`],run:()=>l(`failed`)});let x=(a.data?.projects??[]).filter(e=>i.includes(e.channelId)),S=f.trim().toLowerCase(),C=x.filter(e=>K7(e,c)&&(S===``||e.title.toLowerCase().includes(S)));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Projects`,meta:a.data===void 0?void 0:`${String(x.length)} ${x.length===1?`project`:`projects`} · ${i.channel?.name??`every channel`}`,actions:(0,h.jsxs)(fS,{to:`/play`,variant:`primary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]})}),a.data?.projects.length===0?(0,h.jsx)(jB,{}):null,a.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-4 text-danger`,children:a.error.message}),a.data===void 0?a.error===null?(0,h.jsx)(txe,{}):null:a.data.projects.length===0?(0,h.jsx)(a0,{title:`No projects yet`,actions:(0,h.jsx)(fS,{to:`/play`,variant:`primary`,children:`Make your first video`}),children:`Set up a run on Play: pick a template, type a topic and start.`}):(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsxs)(t0,{label:`Project list`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`div`,{className:`relative w-full max-w-[320px]`,children:[(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{type:`search`,ref:g,"aria-label":`Search projects`,"aria-keyshortcuts":Mx(v),placeholder:`Search projects`,value:f,onChange:e=>p(e.target.value),className:`sl-input pl-9`})]}),(0,h.jsx)(Ab,{label:`Show`,value:c,options:G7,onChange:l,className:`max-w-full overflow-x-auto`})]}),C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:x.length===0?`No projects in ${i.channel?.name??`this channel`} yet. Pick All channels in the rail to see the others.`:`No project matches. Clear the search or pick All.`}):(0,h.jsx)(pU,{label:`Projects`,children:C.map(e=>(0,h.jsx)(exe,{project:e,sample:d.has(e.id),onDelete:()=>s(e),onUploaded:t=>b.mutate({project:e,uploaded:t}),busy:b.isPending},e.id))})]}),(0,h.jsxs)(t0,{as:`aside`,label:`Projects at a glance`,children:[(0,h.jsxs)(`section`,{children:[(0,h.jsx)(H,{title:`At a glance`}),(0,h.jsx)(G2,{children:G7.filter(e=>e.value!==`all`).map(e=>(0,h.jsx)(K2,{label:e.label,value:String(x.filter(t=>K7(t,e.value)).length)},e.value))})]}),(0,h.jsxs)(`section`,{"aria-label":`Video queue`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Video queue`,info:`play.queue`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Videos started together, in the order they run, are on the calendar.`}),(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/calendar`,children:`Open calendar`})})]})]})]}),y.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`mt-3 text-small text-danger`,children:y.error.message}),(0,h.jsx)(jy,{open:o!==void 0,title:o===void 0?``:`Delete "${o.title}"?`,consequence:`Moves the project to the trash for 30 days. Restore it or delete it for good in Settings → Trash.`,confirmLabel:`Delete project`,cancelLabel:`Keep it`,pending:y.isPending,onConfirm:()=>{o!==void 0&&y.mutate(o.id)},onCancel:()=>s(void 0)})]})}function exe({project:e,sample:t,onDelete:n,onUploaded:r,busy:i}){let a=Zbe(e),o=e.status===`running`;return(0,h.jsx)(mU,{title:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),t?(0,h.jsx)(vS,{children:`Sample`}):null]}),meta:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:`${Qbe(e)} · started ${ku(e.createdAt)}`}),o?(0,h.jsx)(q2,{value:e.progress,label:`${e.title} progress`,valueText:`${String(Math.round(e.progress*100))}% done`,className:`max-w-[240px]`}):null]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:a.tone,children:[a.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`${e.title}: ${a.word}`})]}),C3(e)?(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!0),children:`Mark uploaded`}):null,C3(e)?(0,h.jsx)(V,{id:`project.mark-uploaded`}):e.uploadedAt===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(vS,{children:`Uploaded`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Mark ${e.title} not uploaded`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!1),children:`Undo`})]}),(0,h.jsx)(wy,{label:`Delete ${e.title}`,size:`small`,disabled:o,disabledReason:`Cancel the run first, then delete it.`,onClick:n,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function txe(){return(0,h.jsx)(`ul`,{"aria-label":`Loading projects`,className:`sl-list m-0 list-none p-0`,children:[0,1,2,3,4,5].map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,"data-slot":`skeleton-row`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-2/5 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[10px] w-1/4 rounded-control bg-sunken`})]}),(0,h.jsx)(`span`,{className:`h-[10px] w-16 rounded-control bg-sunken`})]},e))})}var nxe=`Prepare restrained delivery cues for a documentary narrator. Let the facts carry the scene. Use a measured pace and make only occasional changes where the supplied wording clearly calls for emphasis, reflection or tension. Prefer no cue to an unnecessary cue. Avoid theatrical emotion, invented reactions and routine laughter or sighs. Never rewrite, summarize, translate or add spoken words. Return only the cue annotations required by the supplied format contract.`;function q7({promptId:e,kind:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=lI(),s=N(nb(i)),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=oP(JSON.stringify(e===void 0?[`new`,t,n??null]:[`prompt`,e])),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(void 0),b=v!==void 0,[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),T=s.data?.prompts,E=e??n,D=E===void 0?void 0:T?.find(e=>e.id===E),O=D===void 0?{kind:t,name:``,body:``}:e===void 0?{kind:D.kind,name:`${D.name} copy`,body:D.body}:{kind:D.kind,name:D.name,body:D.body},k=d??v??O,A=P({mutationFn:t=>xs(i,t,e),onSuccess:async(e,t)=>{if(!e.ok){g(e.fields);return}y(e.value),f(e=>e===t?void 0:e),o({type:`prompt-saved`,id:e.value.id,kind:e.value.kind}),await a.invalidateQueries({queryKey:nb(i).queryKey})}}),ee=P({mutationFn:e=>Cs(i,e),onSuccess:async()=>{S(!1),f(void 0),await a.invalidateQueries({queryKey:nb(i).queryKey}),r(k.kind)}}),te=P({mutationFn:({id:e,on:t})=>Ss(i,e,t),onSettled:async()=>{await a.invalidateQueries({queryKey:nb(i).queryKey})}});X2(b,()=>{r(k.kind)});let ne=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},j=t3(k,p),re=n3(j),M=a3(k.body),ie=k.body.trim()===``?[]:r3(j),ae=k.name.trim()===``?[]:i3(j);return cI({promptNamed:k.name.trim()!==``&&ae.length===0,promptBodyReady:k.body.trim()!==``&&ie.length===0,promptHasKeywords:M.length>0&&ie.length===0,promptSaveReady:re===void 0&&!A.isPending&&!b,promptSaving:A.isPending||b,promptIsArticle:k.kind===`article`,promptIsImage:k.kind===`image`}),s.error===null?E!==void 0&&T===void 0?(0,h.jsx)($2,{}):E!==void 0&&D===void 0?(0,h.jsx)(Y7,{kind:t,children:`That prompt is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:k.kind},children:`Prompts`})}),title:e===void 0?`New prompt`:`Edit prompt`,meta:`${_V(k.kind)} prompt`}),(0,h.jsxs)(`div`,{"data-tour":`prompt-editor`,className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{"data-tour":`prompt-name`,className:`min-w-[min(100%,240px)] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.prompt.name`,...ae.length===0?{}:{error:ae.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:k.name,onChange:e=>{ne({...k,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Kind`,value:k.kind,options:gV,tip:`library.prompt.kind`,onPick:e=>{ne({...k,kind:e},`name`)}})]}),(0,h.jsxs)(`div`,{"data-tour":`prompt-body`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex min-h-8 items-end justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:rxe[k.kind],label:`${_V(k.kind)} prompt body`,className:`-my-1`})]}),J7(k.kind)?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=J7(k.kind);e!==void 0&&(k.body.trim()===``?ne({...k,body:e.body},`body`):w(!0))},children:J7(k.kind)?.label}),(0,h.jsx)(V,{id:`library.prompt.starter`,label:J7(k.kind)?.label})]}):null]}),(0,h.jsx)(s3,{id:c,value:k.body,invalid:ie.length>0,describedBy:ie.length===0?void 0:l,onChange:e=>{ne({...k,body:e},`body`)}})]}),k.kind===`image`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e!==void 0&&D?.kind===`image`?(0,h.jsx)(kb,{checked:te.isPending?te.variables.on:D.photorealistic===!0,disabled:te.isPending,onChange:t=>te.mutate({id:e,on:t}),label:`Draws photorealistic pictures`,tip:`library.prompt.photorealistic`}):(0,h.jsxs)(`span`,{className:`flex items-center gap-1 text-small text-ink-2`,children:[`Save this Image prompt first, then choose whether it draws photorealistic pictures.`,(0,h.jsx)(V,{id:`library.prompt.photorealistic`})]}),te.error===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small text-danger`,children:`Couldn't change Draws photorealistic pictures: ${te.error.message} Press the switch again.`})]}):null,(0,h.jsx)(`div`,{"data-tour":`prompt-save`,children:(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{S(!0)},blocked:re,blockedId:u,pending:A.isPending,saved:b,cancel:(0,h.jsx)(fS,{to:`/prompts`,search:{kind:k.kind},onClick:()=>{f(void 0)},variant:`secondary`,children:`Cancel`}),errors:[A.error,ee.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{A.mutate(k)}})})]}),(0,h.jsx)(`div`,{"data-tour":`prompt-slots`,className:m4,children:(0,h.jsx)(Y4,{slots:M,body:k.body,lint:ie,lintId:l})})]}),(0,h.jsx)(jy,{open:C,title:`Replace this prompt body?`,consequence:`The starter replaces the text in this editor. Nothing is saved until you choose Save.`,confirmLabel:`Use starter`,tone:`primary`,onConfirm:()=>{let e=J7(k.kind);e!==void 0&&ne({...k,body:e.body},`body`),w(!1)},onCancel:()=>w(!1)}),(0,h.jsx)(jy,{open:x,title:`Delete "${k.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:ee.isPending,onConfirm:()=>{e!==void 0&&ee.mutate(e)},onCancel:()=>{S(!1)}})]}):(0,h.jsx)(Y7,{kind:k.kind,children:s.error.message})}var rxe={article:`library.prompt.body.article`,image:`library.prompt.body.image`,thumbnail:`library.prompt.body.thumbnail`,narration:`library.prompt.body.narration`,description:`library.prompt.body.description`,shorts:`library.prompt.body.shorts`,review:`library.prompt.body.review`,script:`library.prompt.body.script`};function J7(e){if(e===`narration`)return{label:`Use Documentary Starter`,body:nxe};if(e===`description`)return{label:`Use Built-in Starter`,body:xhe};if(e===`shorts`)return{label:`Use Built-in Starter`,body:Gk}}function Y7({kind:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:e},children:`Back to Prompts`}),children:t})}function ixe({kind:e,onKind:t,onUseInPlay:n,playBlocked:r}){let{api:i}=z(),a=_(),o=N(nb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=xx(l,`prompts`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=P({mutationFn:e=>Cs(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:B.prompts})}}),x=async(e,t)=>{let n=await xs(i,{kind:e.kind,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:B.prompts}),n.ok?null:q4(n.fields)},S=o.data?.prompts.filter(t=>t.kind===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B4,{action:(0,h.jsx)(oxe,{kind:e}),children:[(0,h.jsx)(CV,{type:`search`,ref:l,"aria-label":`Search prompts`,"aria-keyshortcuts":Mx(u),placeholder:`Search prompts`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsx)(TV,{"aria-label":`Prompt kind`,value:e,className:`w-full sm:w-56`,options:gV,onChange:e=>{let n=gV.find(t=>t.value===e.target.value);n!==void 0&&t(n.value)}}),(0,h.jsx)(V,{id:`library.prompt.kind`})]})]}),o.error===null?null:(0,h.jsx)(R4,{what:`prompts`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(L4,{label:`Prompts`}):null:S.length===0?(0,h.jsxs)(a0,{title:`No ${_V(e).toLowerCase()} prompts yet`,children:[`A prompt is text with `,`{{keywords}}`,`; each keyword becomes a field on Play.`]}):(0,h.jsx)(jq,{className:F4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${_V(e).toLowerCase()} prompts match "${s.trim()}".`}):(0,h.jsx)(pU,{label:`Prompts`,children:w.map(e=>(0,h.jsx)(mU,{className:I4,title:(0,h.jsx)(J4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:axe(e),selected:e.id===T?.id,actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e.kind,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(M4,{item:`prompt`,id:T.id,name:T.name,kicker:`${_V(T.kind)} prompt`,meta:`Updated ${P4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:T.id},size:`small`,children:`Edit prompt`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The prompt wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(O4,{item:`prompt`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(jy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function axe(e){return`${_V(e.kind)} · ${N4(e.slots.length,`keyword`)} · updated ${P4(e.updatedAt)}`}function oxe({kind:e}){return(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e},variant:`primary`,children:`New prompt`})}var sxe={template:`Template`,schedule:`Schedule`,draft:`Draft`,project:`Project`};function X7(e){let t=[e.added.length>0?`${e.added.length} new`:null,e.priced.length>0?`${e.priced.length} repriced`:null,e.retired.length>0?`${e.retired.length} retired`:null].filter(e=>e!==null);return t.length===0?`No changes`:t.join(`, `)}function cxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:H1.catalogue,queryFn:()=>sde(e),refetchInterval:3e4}),i=N({queryKey:H1.retired,queryFn:()=>G1(e)}),a=async()=>{await Promise.all([t.invalidateQueries({queryKey:[`provider-models`]}),t.invalidateQueries({queryKey:H1.retired})])},o=P({mutationFn:()=>cde(e),onSuccess:async e=>{t.setQueryData(H1.catalogue,e),n(e.sync?.warning??`Model list checked: ${X7(e.sync?.changes??lxe)}.`,e.sync?.warning?`error`:`success`),await a()}}),s=P({mutationFn:()=>lde(e),onSuccess:async e=>{n(`Catalogue replaced with the published file.`,`success`),t.setQueryData(H1.catalogue,e),await a()}}),c=async()=>{await Promise.all([t.invalidateQueries({queryKey:H1.retired}),t.invalidateQueries({queryKey:Lq}),t.invalidateQueries({queryKey:TH}),t.invalidateQueries({queryKey:[`play-drafts`]}),t.invalidateQueries({queryKey:[`projects`]}),t.invalidateQueries({queryKey:[`project`]})])},l=P({mutationFn:t=>K1(e,t),onSuccess:c}),u=P({mutationFn:()=>ude(e),onSuccess:async e=>{n(e.failed.length===0?`Switched ${e.switched} ${e.switched===1?`use`:`uses`}.`:`Switched ${e.switched}; ${e.failed.length} could not be switched: ${e.failed[0]?.message??``}`,e.failed.length===0?`success`:`error`),await c()}}),d=r.data?.sync,f=i.data??[],p=f.filter(e=>e.blocked===null&&e.replacement!==null),m=o.error?.message??s.error?.message??r.error?.message??r.data?.warning??d?.warning??null;return bx({id:`settings.check-models`,title:`Check for new models`,group:`Settings`,context:`Models`,keywords:[`catalogue`,`prices`,`retired`],run:()=>{!o.isPending&&r.data?.path&&o.mutate()}}),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Model catalogue`,info:`settings.models.catalogue`,children:[(0,h.jsx)(R,{disabled:o.isPending||!r.data?.path,onClick:()=>o.mutate(),children:o.isPending?`Checking…`:`Check now`}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:s.isPending||!r.data?.path,onClick:()=>s.mutate(),children:s.isPending?`Replacing…`:`Replace with published file`}),(0,h.jsx)(V,{id:`settings.models.replace`})]})]}),(0,h.jsxs)(`dl`,{className:`m-0 grid gap-x-6 border-t border-line text-small sm:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Catalogue file`}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 border-b border-line pb-3 break-all font-mono text-ink-2 sm:pt-3`,children:r.data?.path??`Not available`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Verified`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:r.data?.updatedAt??`date unavailable`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Last checked`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:d?.checkedAt?`${new Date(d.checkedAt).toLocaleString()} · ${X7(d.changes)}`:`Not checked yet`})]}),d!==void 0&&d.changes.retired.length+d.changes.added.length>0?(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1 text-small text-ink-2`,children:[d.changes.added.length>0?(0,h.jsxs)(`span`,{children:[`New: `,d.changes.added.map(e=>e.name).join(`, `)]}):null,d.changes.retired.length>0?(0,h.jsxs)(`span`,{children:[`Retired: `,d.changes.retired.map(e=>e.name).join(`, `)]}):null]}):null,m===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-3 text-body text-danger`,children:m})]}),(0,h.jsxs)(`section`,{"aria-label":`Retired models in use`,children:[(0,h.jsx)(H,{title:`Retired models in use`,info:`settings.models.retired`,children:(0,h.jsx)(R,{variant:`primary`,disabled:u.isPending||p.length===0,onClick:()=>u.mutate(),children:u.isPending?`Switching…`:`Switch all`})}),i.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:i.error.message}):null,l.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:l.error.message}):null,f.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i.isPending?`Looking…`:`Nothing uses a retired model.`}):(0,h.jsx)(`ul`,{"aria-label":`Retired models in use`,className:`sl-list m-0 list-none p-0`,children:f.map(e=>(0,h.jsxs)(`li`,{className:`sl-row max-sm:grid-cols-1`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:sxe[e.kind]}),` `,(0,h.jsx)(`span`,{className:`font-semibold`,children:e.name})]}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s0[e.slot],`: `,e.model,` (`,e.why===`retired`?`retired`:`no longer listed`,`)`]}),e.blocked===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e.blocked})]}),(0,h.jsx)(Ey,{children:(0,h.jsx)(R,{size:`small`,disabled:e.blocked!==null||e.replacement===null||l.isPending,onClick:()=>l.mutate(e),children:e.replacement===null?`No replacement`:`Switch to ${e.replacement.name}`})})]},e.key))})]})]})}var lxe={added:[],retired:[],priced:[]},uxe={ok:`Ready`,warning:`Check`,problem:`Needs fixing`,unused:`Not set up`},dxe={ok:`done`,warning:`waiting`,problem:`failed`,unused:`off`},fxe={ok:`text-ink-2`,warning:`text-waiting`,problem:`text-danger`,skipped:`text-ink-3`};function Z7(){let{api:e}=z();return P({mutationFn:()=>W1(e)})}function pxe(e){let{api:t}=z(),[n,r]=(0,m.useState)({byId:new Map});return{one:P({mutationFn:e=>W1(t,e),onSuccess:t=>{r(n=>{let r=new Map(n.after===e?n.byId:[]);for(let e of t.providers)r.set(e.id,e);return{after:e,byId:r}})}}),latest:t=>n.after===e?n.byId.get(t.id)??t:t}}function mxe({run:e}={}){let t=Z7(),n=e??t,r=n.data,i=pxe(r?.checkedAt),a=r?.providers.filter(e=>e.state!==`unused`).map(i.latest)??[],o=r?.providers.filter(e=>e.state===`unused`)??[];return(0,h.jsxs)(`section`,{"aria-label":`Health check`,children:[(0,h.jsx)(H,{title:`Health check`,info:`settings.health`,children:e===void 0?(0,h.jsx)(R,{disabled:n.isPending,onClick:()=>{n.mutate()},children:n.isPending?`Checking…`:`Check all`}):void 0}),n.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:[`The health check didn't finish: `,n.error.message,` Press Check all to try again.`]}),i.one.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:`The check didn't finish: ${i.one.error.message} Press Check again on the provider to try again.`}),r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:n.isPending?`Checking every provider…`:`Not checked yet.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ul`,{"aria-label":`Health by provider`,className:`sl-list m-0 list-none p-0`,children:a.map(e=>(0,h.jsxs)(`li`,{className:`sl-row grid-cols-1 gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:e.displayName}),(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(_S,{tone:dxe[e.state],children:uxe[e.state]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Check ${e.displayName} again`,disabled:i.one.isPending,onClick:()=>{i.one.mutate(e.id)},children:i.one.isPending&&i.one.variables===e.id?`Checking…`:`Check again`})]})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-1 p-0`,children:e.checks.map(e=>(0,h.jsxs)(`li`,{className:L(`text-small`,fxe[e.state]),children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.label,`:`]}),` `,e.detail]},e.label))})]},e.id))}),(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:o.length===0?`Checked at ${new Date(r.checkedAt).toLocaleTimeString()}.`:`Not set up and not used anywhere: ${o.map(e=>e.displayName).join(`, `)}.`})]})]})}var Q7={openrouter:`settings.provider.openrouter`,"claude-code":`settings.provider.claude-code`,codex:`settings.provider.codex`,gemini:`settings.provider.gemini`,elevenlabs:`settings.provider.elevenlabs`,"openai-tts":`settings.provider.openai-tts`,cartesia:`settings.provider.cartesia`,inworld:`settings.provider.inworld`,"system-voice":`settings.provider.system-voice`,"google-tts":`settings.provider.google-tts`,fal:`settings.provider.fal`,replicate:`settings.provider.replicate`,"openai-image":`settings.provider.openai-image`,"google-image":`settings.provider.google-image`,"codex-image":`settings.provider.codex-image`};function $7(e){return tF(e)?{tone:`done`,word:`Ready`}:e.installed?{tone:`waiting`,word:`Needs attention`}:{tone:`off`,word:`Not found`}}function hxe({provider:e,readiness:t,kind:n}){let{api:r}=z(),i=_(),a=(0,m.useId)(),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(!1),u=e.cliPath?.configured??null,d=e.cliPath?.managedOnHost===!0,f=e.id===`claude-code`?`claude`:e.id===`codex-image`?`codex`:e.id,p=e.cliPath?.command??f,g=o??u??``,v=tF(t),y=P({mutationFn:t=>Yo(r,e.id,t),onMutate:()=>l(!1),onSuccess:async e=>{i.setQueryData(B.providers,t=>t?{...t,providers:t.providers.map(t=>t.id===e.id?e:t)}:void 0),s(void 0),l(!0),await i.invalidateQueries({queryKey:B.providers})}});(0,m.useEffect)(()=>{if(!c)return;let e=setTimeout(()=>l(!1),Y2);return()=>clearTimeout(e)},[c]);let[b,x]=(0,m.useState)(!1),S=(0,m.useId)();return(0,h.jsxs)(`section`,{"aria-labelledby":a,"data-ready":v,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:a,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:Q7[e.id],label:e.displayName})]}),(0,h.jsxs)(`p`,{className:`sl-section-head__meta`,children:[n,` · command line, no key needed`]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:$7(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:gxe(t,u)})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Command`}),(0,h.jsx)(EV,{className:`min-w-0 truncate`,title:p,children:p})]})]}),(0,h.jsxs)(Ey,{children:[d?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-small text-ink-2`,children:[`Managed on host`,(0,h.jsx)(V,{id:`settings.cli.managed-on-host`})]}):(0,h.jsx)(R,{"aria-expanded":b,"aria-controls":S,onClick:()=>x(e=>!e),children:b?`Close path`:`Change path`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:c?(0,h.jsx)(Z2,{}):null})]}),d||!b?null:(0,h.jsx)(`form`,{id:S,onSubmit:e=>{e.preventDefault(),y.isPending||y.mutate(g)},children:(0,h.jsx)(xV,{label:`Executable path`,tip:`settings.cli.path`,help:(0,h.jsxs)(h.Fragment,{children:[`Leave blank to find `,(0,h.jsx)(EV,{children:f}),` on PATH. Use an absolute path without quotes or arguments.`]}),error:y.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{autoComplete:`off`,spellCheck:!1,maxLength:4096,"aria-label":`${e.displayName} Executable path`,className:`min-w-0 flex-1 basis-[220px]`,placeholder:f,value:g,disabled:y.isPending,onChange:e=>{s(e.target.value),l(!1),y.reset()}}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,"aria-label":`Save ${e.displayName} path`,disabled:y.isPending,children:y.isPending?`Checking…`:`Save path`})]})})})]})}function gxe(e,t){return e.issue===void 0?e.installed?e.version===void 0?`Installed`:`Installed, version ${e.version}`:t===null?`Not found on PATH`:`Not found at saved path`:e.issue}var _xe=[`providers`,`system-voice`,`voices`];async function vxe(e){return F(await e.fetch(`${e.origin}/api/providers/system-voice/voices`))}function e9(e=!0){let{api:t}=z();return N({queryKey:_xe,queryFn:()=>vxe(t),enabled:e})}function t9(e){return e.available?{tone:`done`,word:`Ready`}:{tone:`off`,word:`Not found`}}function yxe({provider:e,readiness:t}){let n=(0,m.useId)(),r=e9(t.available).data?.engines??[];return(0,h.jsxs)(`section`,{"aria-labelledby":n,"data-ready":t.available,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:n,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:Q7[e.id],label:e.displayName})]}),(0,h.jsx)(`p`,{className:`sl-section-head__meta`,children:`Speech · built into this computer, no key needed`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:t9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:t.available?`Found ${t.engine??`a speech program`}. Narration with it is free; a keyed voice (ElevenLabs, OpenAI) sounds better.`:t.issue??`No speech program was found on this computer.`})]}),r.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 list-none p-0 text-small text-ink-2`,children:r.map(e=>{let t=e.voices.length;return(0,h.jsx)(`li`,{children:`${e.name}: ${t} voice${t===1?``:`s`}`},e.id)})}),t.available?(0,h.jsx)(Ey,{children:(0,h.jsx)(fS,{to:`/settings`,search:{section:`voices`},children:`Add a system voice`})}):null]})}function bxe({value:e,onPick:t}){let n=e9(),r=n.data?.engines??[];return n.data!==void 0&&r.length===0?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:n.data.issue??`No speech program was found on this computer.`}):(0,h.jsxs)(TV,{value:e,onChange:e=>{for(let n of r){let r=n.voices.find(t=>t.id===e.target.value);if(r!==void 0)return t(r)}},children:[(0,h.jsx)(`option`,{value:``,children:n.data===void 0?`Looking for voices…`:`Pick a voice`}),r.map(e=>(0,h.jsx)(`optgroup`,{label:e.name,children:e.voices.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.language===void 0?e.name:`${e.name} (${e.language})`},e.id))},e.id))]})}var n9=[`llm`,`tts`,`image`],r9={llm:`Text`,tts:`Speech`,image:`Images`},xxe=`••••••••••••`;function Sxe(e){return tF(e.readiness)}function Cxe(e){return e.readiness.kind===`cli`?$7(e.readiness):e.readiness.kind===`local`?t9(e.readiness):e.readiness.hasKey?{tone:`done`,word:`Key saved`}:{tone:`off`,word:`No key`}}function wxe(){let{api:e}=z(),t=N(eb(e)),[n,r]=(0,m.useState)(void 0),i=(0,m.useRef)(null),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{n!==void 0&&a.current&&(a.current=!1,typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&i.current?.scrollIntoView?.({block:`start`,behavior:`smooth`}))},[n]);let o=n9.flatMap(e=>(t.data?.providers??[]).filter(t=>t.family===e)),s=o.find(e=>!Sxe(e))??o[0];if(n===void 0&&s!==void 0&&r(s.id),t.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message});if(t.data===void 0)return(0,h.jsx)(Exe,{});let c=o.find(e=>e.id===n)??s,l=o.every(e=>e.readiness.kind!==`keyed`||!e.readiness.hasKey),u=e=>{a.current=!0,r(e)};return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:[l?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Paste a key to make its provider selectable on Play.`}):null,n9.map(e=>(0,h.jsxs)(`section`,{"data-tour":`keys-${e}`,"aria-labelledby":`keys-${e}-title`,className:`grid items-start gap-x-8 gap-y-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{id:`keys-${e}-title`,title:r9[e],size:`small`,className:`pb-2`}),(0,h.jsx)(pU,{label:`${r9[e]} providers`,children:o.filter(t=>t.family===e).map(e=>{let t=Cxe(e);return(0,h.jsx)(mU,{title:e.displayName,meta:e.readiness.kind===`cli`?`Command line`:e.readiness.kind===`local`?`Built in, no key`:`API key`,selected:e.id===c?.id,onSelect:()=>u(e.id),actions:(0,h.jsx)(_S,{tone:t.tone,children:t.word})},e.id)})})]}),c===void 0||c.family!==e?null:(0,h.jsx)(`div`,{ref:i,className:`min-w-0 scroll-mt-4`,children:c.readiness.kind===`cli`?(0,h.jsx)(hxe,{provider:c,readiness:c.readiness,kind:r9[c.family]},c.id):c.readiness.kind===`local`?(0,h.jsx)(yxe,{provider:c,readiness:c.readiness},c.id):(0,h.jsx)(Txe,{provider:c,hasKey:c.readiness.hasKey},c.id)})]},e))]})}function Txe({provider:e,hasKey:t}){let{api:n}=z(),r=_(),i=(0,m.useId)(),a=(0,m.useId)(),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(void 0),C=(0,m.useId)(),w=VF[e.id],T=o.trim(),E=async()=>{b(!0),S(void 0);try{S(await ode(n,e.id,T===``?void 0:T))}catch(e){p(e instanceof Error?e.message:String(e))}finally{b(!1)}},D=async()=>{l(!0),p(void 0);try{await Jo(n,e.id,o),s(``),d(!0),S(void 0),await r.invalidateQueries({queryKey:B.providers})}catch(e){p(e instanceof Error?e.message:String(e))}finally{l(!1)}},O=P({mutationFn:()=>Xo(n,e.id),onSuccess:async()=>{v(!1),p(void 0),await r.invalidateQueries({queryKey:B.providers})},onError:e=>{v(!1),p(e.message)}});(0,m.useEffect)(()=>{if(!u)return;let e=setTimeout(()=>{d(!1)},Y2);return()=>{clearTimeout(e)}},[u]);let k=[t?a:void 0,x===void 0?void 0:C].filter(e=>e!==void 0).join(` `);return(0,h.jsxs)(`section`,{"aria-labelledby":i,"data-ready":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{as:`h3`,size:`default`,id:i,title:t?e.displayName:`Set up ${e.displayName}`,info:Q7[e.id],infoLabel:e.displayName,meta:`${r9[e.family]} · ${t?`a key is saved`:`needs an API key`}`,className:`pb-0`}),w===void 0?null:t?(0,h.jsxs)(`details`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Where to get a key`}),(0,h.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:(0,h.jsx)(i9,{guide:w})})]}):(0,h.jsx)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:(0,h.jsx)(i9,{guide:w})}),(0,h.jsx)(xV,{label:`${e.displayName} API key`,tip:`settings.providers.api-key`,help:`Stored on this computer only. Never in backups or exports.`,error:f,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`password`,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 basis-[200px]`,"aria-describedby":k===``?void 0:k,placeholder:t?xxe:`Paste API key`,value:o,onChange:e=>{s(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,"aria-label":`Save ${e.displayName} key`,disabled:o.trim()===``||c,onClick:()=>{D()},children:`Save`})]})}),t?(0,h.jsx)(`span`,{id:a,className:`sr-only`,children:`A key is stored for this provider.`}):null,x===void 0?null:(0,h.jsx)(`p`,{id:C,role:x.ok?`status`:`alert`,className:L(`m-0 text-small`,x.ok?`text-accent-ink`:`text-danger`),children:x.message}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{"aria-label":`Test ${e.displayName} key`,disabled:!t&&T===``||y,disabledReason:`Paste a key first.`,onClick:()=>{E()},children:y?`Testing…`:`Test`}),(0,h.jsx)(V,{id:`settings.providers.test-key`,label:`Test`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Remove ${e.displayName} key`,disabled:!t,onClick:()=>{v(!0)},children:`Remove`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:u?(0,h.jsx)(Z2,{}):null})]}),(0,h.jsx)(jy,{open:g,title:`Remove the ${e.displayName} key?`,consequence:`Projects that used this provider cannot retry until a key is saved.`,confirmLabel:`Remove key`,pending:O.isPending,onConfirm:()=>{O.mutate()},onCancel:()=>{v(!1)}})]})}function i9({guide:e}){let t=(e,t)=>(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`underline`,children:t});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ol`,{className:`m-0 list-decimal space-y-1 pl-5`,children:e.steps.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`Sign up: `,t(e.signUp.url,e.signUp.label),`. Make the key:`,` `,t(e.keyPage.url,e.keyPage.label),`.`,e.billing===void 0?null:(0,h.jsxs)(h.Fragment,{children:[` Credit: `,t(e.billing.url,e.billing.label),`.`]})]}),(0,h.jsx)(`p`,{className:`m-0`,children:e.permissions}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`More in the provider's `,t(e.docs.url,e.docs.label),`. After saving, choose Test.`]})]})}function Exe(){return(0,h.jsxs)(`div`,{className:`grid items-start gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,role:`status`,"aria-label":`Loading providers`,children:[(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:[[`llm`,4],[`tts`,5],[`image`,5]].map(([e,t])=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`span`,{className:`mb-2 block h-3 w-16 rounded-control bg-raised`}),(0,h.jsx)(`div`,{className:`sl-list`,children:Array.from({length:t},(t,n)=>`${e}-${n}`).map(e=>(0,h.jsxs)(`div`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`h-4 w-32 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-4 w-20 rounded-control bg-raised`})]},e))})]},e))}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-6 w-48 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-10 rounded-control bg-raised`})]})]})}function a9(e){return e.split(/[\s,;]+/).map(e=>e.trim().toLowerCase()).filter(e=>e!==``)}function Dxe(e){return e.languages===void 0?`Any (not known)`:e.languages.map(e=>BO(e).code===e?BO(e).name:e).join(`, `)}function Oxe({voice:e}){let{api:t}=z(),n=_(),r=(0,m.useId)(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)((e.languages??[]).join(`, `)),[c,l]=(0,m.useState)(void 0),u=P({mutationFn:()=>hs(t,e.id,a9(o)),onSuccess:async e=>{if(e!==void 0){l(e.message);return}a(!1),l(void 0),await n.invalidateQueries({queryKey:B.voices})}});return i?(0,h.jsxs)(`div`,{className:`grid gap-1`,children:[(0,h.jsx)(CV,{id:r,"aria-label":`Languages of ${e.name}`,value:o,placeholder:`es, de`,"aria-invalid":c!==void 0,onChange:e=>{s(e.target.value),l(void 0)}}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:c}),u.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:u.error.message}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(R,{size:`small`,disabled:u.isPending,onClick:()=>u.mutate(),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{a(!1),l(void 0),s((e.languages??[]).join(`, `))},children:`Cancel`})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:Dxe(e)}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit the languages of ${e.name}`,onClick:()=>a(!0),children:`Edit`})]})}function kxe(){let{api:e}=z(),t=_(),n=N(tb(e)),r=N(eb(e)),[i,a]=(0,m.useState)(void 0),o=P({mutationFn:t=>_s(e,t),onSettled:async()=>{a(void 0),await t.invalidateQueries({queryKey:B.voices})}}),s=P({mutationFn:({id:t,on:n})=>gs(e,t,n),onSettled:async()=>{await t.invalidateQueries({queryKey:B.voices})}}),c=(r.data?.providers??[]).filter(e=>e.family===`tts`);if(n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});let l=n.data?.voices;return(0,h.jsxs)(`div`,{"data-tour":`voices`,className:`flex min-w-0 flex-col gap-10`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 overflow-x-auto`,children:[(0,h.jsxs)(`table`,{className:`sl-table min-w-[640px] table-fixed`,...Ob,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Voices`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:`Name`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[18%] pr-4`,children:`Provider`}),(0,h.jsx)(`th`,{scope:`col`,className:`pr-4`,children:`Voice ID`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Languages`,(0,h.jsx)(V,{id:`play.voices.languages`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[20%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Real person`,(0,h.jsx)(V,{id:`play.voices.real-person`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[96px]`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:l===void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,children:(0,h.jsx)(`span`,{className:`block h-4 w-64 rounded-control bg-raised`})})}):l.length===0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,className:`text-ink-2`,children:`Add a voice ID from your text-to-speech provider. Audio needs one to narrate.`})}):l.map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`truncate pr-4 font-semibold`,children:e.name}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:jxe(c,e.provider)}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:e.voiceId}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(Oxe,{voice:e})}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(kb,{checked:s.isPending&&s.variables.id===e.id?s.variables.on:e.imitatesRealPerson===!0,disabled:s.isPending,onChange:t=>s.mutate({id:e.id,on:t}),label:(0,h.jsx)(`span`,{className:`sr-only`,children:`${e.name} imitates a real person`}),className:`text-small`})}),(0,h.jsx)(`td`,{className:`text-right`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name}`,onClick:()=>{a(e)},children:`Remove`})})]},e.id))})]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:`Couldn't change Real person: ${s.error.message} Press the switch again.`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:o.error.message})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Add a voice`}),(0,h.jsx)(Axe,{tts:c})]}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Remove ${i.name}?`,consequence:`Projects that used this voice keep the audio they made with it.`,confirmLabel:`Remove voice`,pending:o.isPending,onConfirm:()=>{i!==void 0&&o.mutate(i.id)},onCancel:()=>{a(void 0)}})]})}function Axe({tts:e}){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(void 0),[d,f]=(0,m.useState)(void 0),p=l??e[0]?.id,g=P({mutationFn:e=>ms(t,e),onSuccess:async e=>{if(!e.ok){f(e.refusal);return}i(``),o(``),c(``),f(void 0),await n.invalidateQueries({queryKey:B.voices})}}),v=(e,t)=>{t(),d?.field===e&&f(void 0)},y=e=>d?.field===e?d.message:void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`grid items-start gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(xV,{label:`Voice name`,tip:`play.voices.name`,error:y(`name`),children:(0,h.jsx)(CV,{value:r,onChange:e=>{let t=e.target.value;v(`name`,()=>{i(t)})}})}),(0,h.jsx)(xV,{label:`Provider`,tip:`play.voices.provider`,error:y(`provider`),children:(0,h.jsxs)(TV,{value:p??``,onChange:t=>{let n=e.find(e=>e.id===t.target.value);n!==void 0&&v(`provider`,()=>{u(n.id)})},children:[e.length===0?(0,h.jsx)(`option`,{value:``,children:`No speech provider`}):null,e.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.displayName},e.id))]})}),(0,h.jsx)(xV,{label:`Voice ID`,tip:`play.voices.voice-id`,error:y(`voiceId`),...p===`inworld`?{help:`Use an Inworld voice ID, such as Dennis, or one from your workspace.`}:{},children:p===`system-voice`?(0,h.jsx)(bxe,{value:a,onPick:e=>{v(`voiceId`,()=>{o(e.id)}),r.trim()===``&&i(e.name);let t=/^([a-z]{2,3})(?:[-_]|$)/i.exec(e.language??``)?.[1];s.trim()===``&&t!==void 0&&c(t.toLowerCase())}}):p===`google-tts`?(0,h.jsx)(TV,{value:a,options:[{value:``,label:`Pick a Gemini voice`},...UF.map(e=>({value:e.name,label:`${e.name} (${e.style})`}))],onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t),r.trim()===``&&i(t)})}}):(0,h.jsx)(CV,{className:`tabular-nums`,value:a,onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t)})}})}),(0,h.jsx)(xV,{label:`Languages`,tip:`play.voices.languages`,help:`Codes such as es, de.`,error:y(`languages`),children:(0,h.jsx)(CV,{value:s,placeholder:`es, de`,onChange:e=>{let t=e.target.value;v(`languages`,()=>{c(t)})}})}),(0,h.jsx)(R,{variant:`primary`,className:`md:mt-6`,disabled:p===void 0||d!==void 0||g.isPending,onClick:()=>{if(p!==void 0){let e=a9(s);g.mutate({provider:p,name:r,voiceId:a,...e.length===0?{}:{languages:e}})}},children:`Add voice`})]}),g.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:g.error.message})]})}function jxe(e,t){return e.find(e=>e.id===t)?.displayName??t}var o9=[`settings`,`notifications`],Mxe=`The test notification couldn't be shown: this browser only allows notifications from installed apps. Set a Notification URL below instead.`;function Nxe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Browser and phone`,info:`settings.notifications`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(Pxe,{}),(0,h.jsx)(Fxe,{}),(0,h.jsx)(Ixe,{})]})]})}function Pxe(){let e=(0,m.useSyncExternalStore)(vP,gP,()=>!1),[t,n]=(0,m.useState)(hP),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=Oy(),c=e&&t===`granted`;async function l(e){if(i(void 0),!e){_P(!1);return}o(!0);try{let e=await xP();n(e);let t=bP(e);e===`granted`?(_P(!0),gP()||i(`Browser notifications couldn't be turned on because this browser blocks site storage for Slopify. Allow site data for this address in your browser's settings, then turn Browser notifications on again.`)):i(t??`Browser notifications weren't turned on because the permission prompt was dismissed. Turn Browser notifications on again and choose Allow.`)}finally{o(!1)}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Browser notifications`,tip:`settings.notifications.browser`,checked:c,disabled:a,onChange:e=>void l(e)}),(0,h.jsx)(R,{variant:`quiet`,disabled:!c,disabledReason:`Turn Browser notifications on first.`,onClick:()=>{i(void 0);try{CP({projectId:`test`,text:UP},()=>{}),s(`Test notification sent to this browser.`,`success`)}catch{i(Mxe)}},children:`Send test notification`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Works while any Slopify tab is open.`}),r===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:r})]})}function Fxe(){let e=(0,m.useSyncExternalStore)(AP,OP,()=>!0);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Run sounds`,tip:`settings.notifications.sounds`,checked:e,onChange:kP}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`start`),children:`Play start`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`end`),children:`Play end`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`A chime when a run starts and a different one when it finishes, fails or waits for you. Works while any Slopify tab is open; set your computer's volume for how loud.`})]})}function Ixe(){let{api:e}=z(),t=_(),n=Oy(),r=(0,m.useId)(),i=N({queryKey:o9,queryFn:()=>$o(e)}),[a,o]=(0,m.useState)(void 0),s=a??i.data?.url??``,c=GP(s),l=P({mutationFn:t=>ts(e,t),onSuccess:e=>{t.setQueryData(o9,e),o(void 0),n(e.url===null?`Notification URL removed.`:`Notification URL saved.`,`success`)}}),u=P({mutationFn:t=>ns(e,t),onSuccess:()=>{n(`Test notification sent. Check the app or page behind your Notification URL.`,`success`)}}),d=c??l.error?.message??u.error?.message,f=l.isPending||u.isPending||i.data===void 0;return(0,h.jsxs)(xV,{label:`Notification URL`,tip:`settings.notifications.url`,help:`Works with no tab open, for example an ntfy topic on your phone.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`url`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:`https://ntfy.sh/your-topic`,className:`min-w-0 flex-1 basis-[220px]`,value:s,disabled:i.data===void 0,"aria-invalid":c!==void 0,"aria-describedby":d===void 0?void 0:r,onChange:e=>{l.reset(),u.reset(),o(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,disabled:f||c!==void 0||a===void 0,onClick:()=>l.mutate(s),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,disabled:f||c!==void 0||s.trim()===``,onClick:()=>u.mutate(s),children:`Send test notification`})]}),i.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The saved Notification URL couldn't be read: `,i.error.message]}),d===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:d})]})}var s9={library:`The Library of Alexandria`,audiobook:`The Wind in the Willows (audiobook)`,podcast:`The Antikythera Mechanism (podcast)`};function Lxe(){let{api:e}=z(),t=_(),n=N({queryKey:Ny,queryFn:()=>Vy(e)}),r=P({mutationFn:()=>Uy(e),onSettled:async()=>{await t.invalidateQueries({queryKey:Ny}),await t.invalidateQueries({queryKey:My}),await t.invalidateQueries({queryKey:B.projects})}}),i=r.data?.samples??n.data?.samples;return(0,h.jsxs)(`div`,{className:`mt-8`,children:[(0,h.jsx)(H,{title:`Sample projects`,info:`settings.sample.restore`}),(0,h.jsx)(pU,{label:`Sample projects`,children:Object.keys(s9).map(e=>{let t=i?.[e]??null;return(0,h.jsx)(mU,{title:s9[e],meta:t===null?`Not in your projects`:`In your projects`,actions:t===null?void 0:(0,h.jsx)(pS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:`Open`})},e)})}),(0,h.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{disabled:r.isPending,onClick:()=>r.mutate(),children:r.isPending?`Restoring…`:`Restore samples`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Puts all three back as they shipped.`})]}),(0,h.jsx)(Q1,{tone:r.error?`error`:`success`,children:r.error?.message??(r.isSuccess?`The samples are back in Projects.`:void 0)})]})}var Rxe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function zxe(e){let[t,n,r]=e.split(`-`).map(Number),i=Rxe[(n??0)-1];return i===void 0||r===void 0?e:`${String(r)} ${i} ${String(t)}`}function c9(e,t){let n=[e.range===void 0?e.version:`Versions ${e.range}`,`released ${zxe(e.date)}`].filter(e=>e!==void 0).join(`, `),r=n.charAt(0).toUpperCase()+n.slice(1);return e.version===t?`${r}. The version you are running.`:`${r}.`}function Bxe({note:e,onNote:t}){let{api:n}=z(),r=N(fI(n));if(r.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The patch notes did not load`,actions:(0,h.jsx)(R,{onClick:()=>void r.refetch(),children:`Try again`}),children:`${r.error.message} Press Try again, or reload the page.`});if(r.data===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the patch notes…`});let{notes:i,version:a}=r.data,[o,...s]=i;if(o===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:`This version of Slopify has no patch notes.`});let c=e===void 0?void 0:i.find(t=>t.id===e),l=c!==void 0&&c.id!==o.id?c:void 0;return l===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e!==void 0&&c===void 0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`There are no patch notes called "${e}" in this version. The latest are below; older ones are under Earlier versions.`}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:`Latest version`,meta:c9(o,a),info:`settings.patch-notes`}),(0,h.jsx)(wB,{id:o.id})]}),s.length===0?null:(0,h.jsxs)(`details`,{className:`max-w-prose border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`Earlier versions (${String(s.length)})`}),(0,h.jsx)(pU,{label:`Earlier versions`,className:`mt-2`,children:s.map(e=>(0,h.jsx)(mU,{title:e.title,meta:c9(e,a),onSelect:()=>t(e.id),actions:(0,h.jsx)(R,{"aria-label":`Read ${e.title}`,onClick:()=>t(e.id),children:`Read`})},e.id))})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{children:(0,h.jsxs)(R,{variant:`quiet`,onClick:()=>t(void 0),children:[(0,h.jsx)(nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Back to the latest patch notes`]})}),(0,h.jsx)(H,{title:`Earlier version`,meta:c9(l,a)}),(0,h.jsx)(wB,{id:l.id})]})}var l9=[`trash`];async function Vxe(e){return(await F(await e.client.trash.$get())).items}async function Hxe(e,t,n){return(await F(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function Uxe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await fo(r)}var Wxe={project:`Project`,prompt:`Prompt`,entry:`Intro/outro`,template:`Template`,schedule:`Schedule`};function Gxe(e){return e.kind===`entry`&&e.detail!==null?e.detail===`intro`?`Intro`:`Outro`:e.kind===`prompt`&&e.detail!==null?`Prompt · ${e.detail}`:Wxe[e.kind]}function Kxe(e){return e<=0?`removed for good today`:e===1?`1 day left`:`${String(e)} days left`}var qxe=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}),Jxe={project:[B.projects,[`calendar`]],prompt:[B.prompts],entry:[B.entries],template:[Lq],schedule:[TH,[`calendar`]]};function Yxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:l9,queryFn:()=>Vxe(e)}),[i,a]=(0,m.useState)(void 0),o=async e=>{await Promise.all([l9,...Jxe[e.kind]].map(e=>t.invalidateQueries({queryKey:e})))},s=P({mutationFn:t=>Hxe(e,t.kind,t.id),onSuccess:async(e,t)=>{await o(t),n(e.renamedFrom===null?`Restored "${e.name}".`:`Restored as "${e.name}": another item is now called "${e.renamedFrom}".`,`success`),e.kind===`schedule`&&n(`The schedule is paused. Press Resume on Schedules to run it again.`,`info`)},onError:e=>n(e.message,`error`)}),c=P({mutationFn:t=>Uxe(e,t.kind,t.id),onSuccess:async(e,t)=>{a(void 0),await o(t),n(`Deleted "${t.name}" for good.`,`success`)},onError:e=>{a(void 0),n(e.message,`error`)}}),l=r.data??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Trash`,info:`settings.trash`}),r.isPending?(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the trash…`}):r.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:r.error.message}):l.length===0?(0,h.jsx)(a0,{title:`The trash is empty`,children:`Anything you delete stays here for 30 days before it is removed for good.`}):(0,h.jsx)(pU,{label:`Deleted items`,children:l.map(e=>(0,h.jsx)(mU,{title:e.name,meta:`${Gxe(e)} · deleted ${qxe.format(new Date(e.deletedAt))} · ${Kxe(e.daysLeft)}`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>s.mutate(e),children:`Restore`}),(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>a(e),children:`Delete now`})]})},`${e.kind}:${e.id}`))}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Delete "${i.name}" for good?`,consequence:i?.kind===`project`?`The project and every file it produced are removed from disk. This cannot be undone.`:i?.kind===`schedule`?`The schedule leaves the trash and cannot be restored. Its run history stays on Schedules.`:`It is removed for good. This cannot be undone.`,confirmLabel:`Delete for good`,cancelLabel:`Keep it`,pending:c.isPending,onConfirm:()=>{i!==void 0&&c.mutate(i)},onCancel:()=>{c.isPending||a(void 0)}})]})}var Xxe=`https://github.com/GentBajko/slopify`,Zxe=`https://www.patreon.com/cw/GentBajko`,Qxe=`https://buymeacoffee.com/gentbajko`;function $xe(){return[{href:Xxe,label:`GitHub`,detail:`The code, issues and releases.`,glyph:`github`},{href:Zxe,label:`Patreon`,detail:`Monthly support for the project.`,glyph:`patreon`},{href:Qxe,label:`Buy Me a Coffee`,detail:`A one-off thank you.`,glyph:`coffee`},{href:`https://slopify.stream/channel.html`,label:`How I run a channel with it`,detail:`A lore channel run on Slopify, start to finish.`}]}function eSe({onWhatsNew:e}){return(0,h.jsxs)(`div`,{className:`max-w-prose`,children:[(0,h.jsx)(H,{title:`About`}),(0,h.jsx)(`p`,{className:`m-0 mb-3 text-ink-2`,children:`Slopify is free and open source, and runs on your machine with your own keys. If it saves you time, you can support it here.`}),(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1 text-small text-ink-2`,children:[`Updates: the circular-arrows button at the foot of the sidebar (at the top on a phone).`,(0,h.jsx)(V,{id:`settings.updates`})]}),e===void 0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:e,children:`What's new in this version`}),(0,h.jsx)(V,{id:`settings.whats-new`})]}),(0,h.jsx)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:`Made by Gent Bajko. Apache License 2.0: anyone who redistributes Slopify or builds on it keeps this credit.`}),(0,h.jsx)(`ul`,{"aria-label":`Links`,className:`sl-list m-0 list-none p-0`,children:$xe().map(e=>(0,h.jsx)(`li`,{className:`sl-row`,children:(0,h.jsxs)(`div`,{className:`sl-row__lead`,children:[e.glyph===void 0?(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}):(0,h.jsx)(lS,{name:e.glyph,className:`shrink-0 text-ink-2`}),(0,h.jsxs)(`div`,{className:`sl-row__text`,children:[(0,h.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,className:`font-semibold text-ink underline underline-offset-3`,children:e.label}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.detail})]})]})},e.label))})]})}var u9=[`backups`],d9=1,f9=30;function p9(){return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}function tSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=d9&&Number(t)<=f9?void 0:`Keep between ${d9} and ${f9} backups.`}function nSe(e){return{enabled:e.config.enabled,time:e.config.time,keep:String(e.config.keep),folder:e.config.folder??``}}function m9(){let{api:e}=z(),t=_(),n=Oy();return P({mutationFn:()=>ko(e),onSuccess:e=>{t.setQueryData(u9,e),n(`Backup started. Its result shows here when it finishes.`,`success`)}})}function rSe(){let{api:e}=z(),t=_(),n=N({queryKey:u9,queryFn:()=>Do(e),refetchInterval:e=>e.state.data?.running===!0&&2e3}),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Oo(e,t),onSuccess:e=>{t.setQueryData(u9,e),i(void 0),o(!0)}}),c=m9();(0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Y2);return()=>clearTimeout(e)},[a]);let l=n.data,u=r??(l===void 0?void 0:nSe(l)),d=u===void 0?void 0:tSe(u.keep),f=e=>{u!==void 0&&i({...u,...e})};return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Daily backup`,info:`settings.backups`,children:(0,h.jsx)(R,{variant:`primary`,disabled:l===void 0||l.running||c.isPending,onClick:()=>c.mutate(),children:`Back up now`})}),(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-x-4 gap-y-1 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{role:`status`,children:l===void 0?(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`}):iSe(l)}),(0,h.jsx)(`span`,{children:l===void 0?null:aSe(l)})]}),l?.status.detail?l.status.lastResult===`failed`?(0,h.jsx)(SI,{tone:`danger`,title:`Why the last backup stopped`,children:l.status.detail}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:l.status.detail}):null,c.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:c.error.message}):null]}),n.error?(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The backup settings couldn't be read: `,n.error.message]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(kb,{label:`Back up automatically`,tip:`settings.backups.auto`,checked:u?.enabled===!0,disabled:u===void 0,className:`self-start`,onChange:e=>f({enabled:e})}),(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Time of day`,tip:`settings.backups.time`,help:`${p9()} time`,children:(0,h.jsx)(CV,{type:`time`,className:`w-[140px] tabular-nums`,value:u?.time??`03:00`,disabled:u===void 0,onChange:e=>f({time:e.target.value})})}),(0,h.jsx)(xV,{label:`Keep last`,tip:`settings.backups.keep`,help:`Backups kept in the folder.`,error:d,children:(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:d9,max:f9,step:1,className:`w-[88px] tabular-nums`,value:u?.keep??`5`,disabled:u===void 0,onChange:e=>f({keep:e.target.value})})}),(0,h.jsx)(xV,{label:`Folder`,tip:`settings.backups.folder`,className:`md:col-span-2`,...l===void 0?{}:{help:oSe(l)},children:(0,h.jsx)(CV,{value:u?.folder??``,placeholder:l?.defaultFolder??``,disabled:u===void 0,onChange:e=>f({folder:e.target.value})})})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:u===void 0||d!==void 0||s.isPending,onClick:()=>{u!==void 0&&(o(!1),s.mutate({enabled:u.enabled,time:u.time,timeZone:p9(),keep:Number(u.keep.trim()),folder:u.folder.trim()===``?null:u.folder.trim()}))},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 basis-full text-small text-danger`,children:s.error.message})]})]})]})}function h9(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function iSe(e){if(e.running)return`Backing up now…`;let{status:t}=e,n=t.lastSuccessAt===null?`No backup yet.`:`Last backup ${h9(t.lastSuccessAt)}${t.lastSuccessBytes===null?``:`, ${g9(t.lastSuccessBytes)}`}.`;return t.lastResult===`failed`&&t.lastAttemptAt!==null?`${n} The backup at ${h9(t.lastAttemptAt)} failed.`:t.lastResult===`waiting`?`${n} Waiting for projects to finish.`:n}function aSe(e){return e.config.enabled?e.overdue?`Next: shortly.`:e.nextRunAt===null?``:`Next: ${h9(e.nextRunAt)}.`:`Automatic backups are off.`}function oSe(e){let t=`${e.files.length} backup${e.files.length===1?``:`s`} here (${g9(e.files.reduce((e,t)=>e+t.bytes,0))}).`;return e.hostFolder===null?`Inside Slopify's Docker volume, not on your computer. Leave Folder empty to save backups in the Backups folder on your computer. ${t}`:`${e.config.folder===null?`Empty uses the default: `:`On your computer: `}${e.hostFolder}. ${t}`}function g9(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var _9=[`storage-files`];function sSe({usageQueryKey:e}){let{api:t}=z(),n=_(),r=Oy(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(),u=N({queryKey:_9,queryFn:()=>Io(t),refetchInterval:e=>y9(e.state.data)?1e3:!1}),d=P({mutationFn:e=>Lo(t,e),onMutate:()=>l(void 0),onSuccess:e=>{n.setQueryData(_9,e),a(!1)},onError:e=>l(e.message)}),f=P({mutationFn:()=>Ro(t),onSuccess:e=>{e.opened||r(`Your files are in ${e.path}.`,`info`)},onError:e=>r(e.message,`error`)}),p=u.data,g=y9(p),v=p?.move?.phase;if((0,m.useEffect)(()=>{v===`done`&&n.invalidateQueries({queryKey:e})},[v,n,e]),p===void 0)return(0,h.jsx)(`div`,{children:(0,h.jsx)(H,{title:`Your files`,meta:u.error?`Where your files are is unavailable. Reload the page to try again.`:`Loading…`})});if(p.docker)return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Your files`,meta:p.folder??`The Docker project folder isn't set up.`,info:`settings.files.docker`,children:(0,h.jsx)(R,{disabled:p.folder===null||f.isPending,onClick:()=>f.mutate(),children:`Open folder`})}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(v9,{view:p}),p.dockerCommand===null?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[`To move your projects to Documents/Slopify, run this on the computer running Docker (or use `,(0,h.jsx)(EV,{children:`--projects-dir <folder>`}),` for another folder):`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(EV,{className:`min-w-0 break-all`,children:p.dockerCommand}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=p.dockerCommand??``;navigator.clipboard.writeText(e).then(()=>r(`Command copied.`,`success`)).catch(()=>r(`Copying failed: this browser doesn't allow it here. Select the command and copy it yourself.`,`error`))},children:`Copy command`})]})]})]})]});let y=v===`failed`||v===`interrupted`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Your files`,meta:p.folder,info:`settings.files`,children:[p.inDocuments||p.documentsRoot===null?null:(0,h.jsx)(R,{variant:`primary`,disabled:g||d.isPending,onClick:()=>d.mutate(`documents`),children:`Move to Documents/Slopify`}),(0,h.jsx)(R,{disabled:f.isPending,onClick:()=>f.mutate(),children:`Open folder`}),(0,h.jsx)(R,{variant:`quiet`,disabled:g||d.isPending,onClick:()=>{a(e=>!e),l(void 0)},children:`Choose another folder`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 text-small text-ink-2`,children:[(0,h.jsx)(v9,{view:p}),i?(0,h.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),d.mutate(o)},children:[(0,h.jsx)(xV,{label:`New folder`,tip:`settings.files.new-folder`,help:`The full path; it must be empty or new.`,error:c,className:`min-w-0 flex-1 basis-80`,children:(0,h.jsx)(CV,{value:o,placeholder:p.documentsRoot??`/home/you/Videos/Slopify`,onChange:e=>s(e.target.value)})}),(0,h.jsx)(R,{type:`submit`,disabled:o.trim()===``||d.isPending,children:`Move here`})]}):c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:c}),p.move===null?null:g?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[p.move.phase===`copying`?`Copying`:`Checking the copy of`,` your files to`,` `,p.move.target,`: `,p.move.files,` of `,p.move.totalFiles,` files (`,Y5(p.move.bytes),` of `,Y5(p.move.totalBytes),`). Keep Slopify running until it finishes.`]}),(0,h.jsx)(q2,{label:p.move.phase===`copying`?`Files copied`:`Files checked`,value:p.move.totalBytes===0?0:p.move.bytes/p.move.totalBytes})]}):y?(0,h.jsx)(SI,{tone:v===`failed`?`danger`:`waiting`,title:v===`failed`?`Moving your files to ${p.move.target} stopped`:`Moving your files to ${p.move.target} didn't finish`,actions:(0,h.jsx)(R,{disabled:d.isPending,onClick:()=>d.mutate(p.move?.target??``),children:`Continue moving`}),children:p.move.error??`Slopify was stopped before the copy was checked, so it still uses the old folder. Continue moving picks up where it left off.`}):v===`done`&&p.move.oldFolder!==null?(0,h.jsxs)(SI,{tone:`info`,title:`Your files are now in ${p.move.target}`,children:[`Every file was copied and checked. The old folder `,p.move.oldFolder,` still has a copy; once your projects open fine, you can delete it to free the space.`]}):null]})]})}function v9({view:e}){let t=[[`Projects`,e.projects],[`Automatic backups`,e.backups],[`Exports`,e.exports]].filter(e=>e[1]!==null);return(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1`,children:t.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-3`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-all`,children:t})]},e))})}function y9(e){return e?.move?.phase===`copying`||e?.move?.phase===`verifying`}function cSe(){let{api:e}=z(),t=N($y(e));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[t.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message}),t.data===void 0?t.error===null?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(hSe,{cells:5}),(0,h.jsx)(gSe,{})]}):null:(0,h.jsx)(uSe,{usage:t.data})]})}var lSe=[{id:`stage`,header:`Stage`,cell:e=>nF[e.stage]},{id:`model`,header:`Provider · model`,cell:e=>dSe(e)},{id:`in`,header:`Tokens in`,numeric:!0,cell:e=>b9.format(e.tokensIn)},{id:`out`,header:`Tokens out`,numeric:!0,cell:e=>b9.format(e.tokensOut)}];function uSe({usage:e}){let t=Object.values(e.counters).every(e=>e===0);return(0,h.jsxs)(e0,{split:`even`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(G2,{children:mSe(e).map(e=>(0,h.jsx)(K2,{label:e.label,value:e.value},e.label))}),t?(0,h.jsx)(`p`,{className:`m-0 mt-3 text-body text-ink-2`,children:`Numbers appear after your first run.`}):null]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Machine ID ${e.machineId??`not made yet`} · Slopify ${e.appVersion}`})]}),(0,h.jsx)(t0,{children:(0,h.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Tokens by stage`,columns:lSe,rows:e.byStage,rowKey:e=>`${e.stage}/${e.provider}/${e.model??``}`,empty:`No stages have run yet.`,className:`min-w-[480px] [&_td]:pr-4 [&_th]:pr-4`})})})]})}function dSe(e){return e.model===null?e.provider:`${e.provider} · ${e.model}`}var b9=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),fSe=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),pSe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function mSe(e){let t=e.counters;return[{label:`Videos made`,value:b9.format(t.videosMade)},{label:`Hours of audio`,value:fSe.format(t.audioSeconds/3600)},{label:`Images made`,value:b9.format(t.imagesMade)},{label:`Tokens used`,value:t.tokensUsed<1e6?b9.format(t.tokensUsed):pSe.format(t.tokensUsed)},{label:`Projects`,value:b9.format(t.projects)}]}function hSe({cells:e}){return(0,h.jsx)(`div`,{className:`sl-stats`,children:Array.from({length:e},(e,t)=>t).map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-8 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`})]},e))})}function gSe(){return(0,h.jsx)(`div`,{className:`border-t border-line`,children:[0,1,2,3].map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-4 border-b border-line py-3`,children:[(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 max-w-[40%] rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`ml-auto h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`})]},e))})}var x9=[`storage-usage`],_Se=[x9,B.projects,[`project`],B.usage,B.documentThemes,TH,[`play-drafts`],B.settings,B.providers,B.voices,B.prompts,B.entries,B.staging,Lq,sN,[`provider-models`]];async function vSe(e){await Promise.all(_Se.map(t=>e.invalidateQueries({queryKey:t})))}var S9=30,ySe=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function bSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=0&&Number(t)<=S9?void 0:`The silence gap is a whole number of seconds between 0 and ${String(S9)}.`}var C9=[{id:`general`,label:`General`,meta:`How Slopify starts on this computer.`},{id:`providers`,label:`Providers`,meta:`Keys stay on this machine and go only to their provider. Readiness is checked again before each run.`},{id:`voices`,label:`Voices`,meta:`A wrong voice ID shows up when the audio stage uses it.`},{id:`models`,label:`Models`,meta:`New models, prices and retirements, checked once a day.`},{id:`playback`,label:`Playback & appearance`,meta:`How narration is paced and how Slopify looks.`},{id:`notifications`,label:`Notifications`,meta:`When a run finishes, fails, waits for you, or a review needs a decision.`},{id:`channel-links`,label:`Channel links`,meta:`The links a YouTube description's {{Name}} placeholders fill from.`},{id:`studio`,label:`YouTube Studio`,meta:`The playlist upload packs name, and the Studio extension's pairing.`},{id:`storage`,label:`Backup & storage`,meta:`Export everything, import a backup, and see what uses disk space.`},{id:`backups`,label:`Backups`,meta:`A daily copy of everything, in a folder you choose.`},{id:`trash`,label:`Trash`,meta:`Deleted projects, prompts, templates and schedules, kept for 30 days.`},{id:`usage`,label:`Usage`,meta:`This machine only. The same counters, anonymised, feed slopify.stream.`},{id:`patch-notes`,label:`Patch notes`,meta:`What changed in each version of Slopify.`},{id:`about`,label:`About`,meta:`Free and open source, running on your machine with your own keys.`}];function xSe(e){return C9.find(t=>t.id===e)?.id??`providers`}function SSe(e){let t=document.createElement(`a`);t.href=`${e}/api/diagnostics`,t.download=`slopify-diagnostics.json`,document.body.append(t),t.click(),t.remove()}function CSe({section:e=`providers`,note:t,onSection:n=()=>{},onNote:r=()=>{}}){let{api:i}=z(),a=_(),o=Oy(),s=Z7(),c=m9(),l=C9.find(t=>t.id===e)??C9[0];return bx({id:`settings.check-providers`,title:`Check all providers`,group:`Settings`,keywords:[`health`,`keys`,`signed in`],run:()=>{n(`providers`),s.mutate()}}),bx({id:`settings.back-up-now`,title:`Back up now`,group:`Settings`,keywords:[`backup`],run:()=>{n(`backups`),c.mutate(void 0,{onError:e=>{o(`The backup didn't start: ${e.message} Open Settings → Backups to see its state.`,`error`)}})}}),bx({id:`settings.download-diagnostics`,title:`Download diagnostics`,group:`Settings`,keywords:[`support`,`bug report`],run:()=>{SSe(i.origin)}}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:`Settings`,title:l.label,meta:l.meta,actions:(0,h.jsxs)(h.Fragment,{children:[e===`providers`?(0,h.jsx)(R,{disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check all`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(mS,{variant:`secondary`,href:`${i.origin}/api/diagnostics`,download:`slopify-diagnostics.json`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download diagnostics`]}),(0,h.jsx)(V,{id:`settings.diagnostics`})]})]})}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(e8,{label:`Settings sections`,children:C9.map(t=>(0,h.jsx)(t8,{current:t.id===e,onClick:()=>n(t.id),className:`whitespace-nowrap max-md:w-auto`,children:t.label},t.id))}),children:(0,h.jsxs)(`section`,{"aria-label":l.label,className:`flex min-w-0 flex-col gap-10`,children:[e===`providers`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B3,{}),(0,h.jsx)(wxe,{}),(0,h.jsx)(mxe,{run:s})]}):null,e===`general`?(0,h.jsx)(zb,{}):null,e===`voices`?(0,h.jsx)(kxe,{}):null,e===`models`?(0,h.jsx)(cxe,{}):null,e===`playback`?(0,h.jsx)(DSe,{}):null,e===`notifications`?(0,h.jsx)(Nxe,{}):null,e===`channel-links`?(0,h.jsx)(Gfe,{}):null,e===`studio`?(0,h.jsx)(kfe,{}):null,e===`storage`?(0,h.jsx)(sSe,{usageQueryKey:x9}):null,e===`storage`?(0,h.jsx)(wSe,{}):null,e===`storage`?(0,h.jsx)(Lxe,{}):null,e===`backups`?(0,h.jsx)(rSe,{}):null,e===`trash`?(0,h.jsx)(Yxe,{}):null,e===`usage`?(0,h.jsx)(cSe,{}):null,e===`patch-notes`?(0,h.jsx)(Bxe,{note:t,onNote:r}):null,e===`about`?(0,h.jsx)(eSe,{onWhatsNew:()=>{a.fetchQuery(fI(i)).then(e=>r(e.current??void 0),e=>{o(`The patch notes did not open: ${e instanceof Error?e.message:String(e)} Open Settings → Patch notes to try again.`,`error`)})}}):null]})})]})}var w9=`The backup wasn't imported. Check it is a file made with Export everything (.tar) or Export backup (.zip), then try again.`;function wSe(){let{api:e}=z(),t=_(),n=N({queryKey:x9,queryFn:()=>Fo(e),staleTime:3e4}),[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)({phase:`idle`}),[s,c]=(0,m.useState)({phase:`idle`}),[l,u]=(0,m.useState)(null),d=Oy(),[f,p]=(0,m.useState)(null);async function g(){p(null),o({phase:`preparing`});try{let t=await Eo(e);if(!t.ready){o({phase:`idle`}),p(t.detail??`The backup can't be made right now. Try again in a moment.`);return}o({phase:`downloading`,bytes:t.bytes??0,projects:t.projects??0});let n=document.createElement(`a`);n.href=`${e.origin}/api/storage/export`,n.download=``,document.body.append(n),n.click(),n.remove()}catch(e){o({phase:`idle`}),p(e instanceof Error?e.message:`The backup couldn't be prepared. Try again in a moment.`)}}async function v(n){let r=n.name.toLowerCase().endsWith(`.zip`)||n.type===`application/zip`;if(n.size===0||r&&n.size>104857600){p(r?`This file is empty or larger than 100 MB. Choose a .zip made with Export backup, or a .tar made with Export everything.`:`This file is empty. Choose the .tar made with Export everything.`);return}i(!0),p(null),u(null),c({phase:`uploading`,sent:0,total:n.size});try{let i=await e.upload(`${e.origin}/api/storage/import`,n,r?`application/zip`:`application/x-tar`,(e,t)=>{c(e>=t?{phase:`importing`}:{phase:`uploading`,sent:e,total:t})}),a=await i.json();if(!i.ok)throw Error(a.detail??w9);a.projects===void 0?d(`Imported ${a.templates??0} template(s), ${a.fonts??0} uploaded font(s), and ${a.stagedFiles??0} staged file(s).${a.fontFallbacks?` ${a.fontFallbacks} missing legacy font reference(s) now use the default font.`:``}`,`success`):(u(a),d(`Backup imported.`,`success`)),await vSe(t)}catch(e){p(e instanceof Error?e.message:w9)}finally{c({phase:`idle`}),i(!1)}}async function y(){i(!0),p(null);try{let n=await e.fetch(`${e.origin}/api/storage/cleanup`,{method:`POST`}),r=await n.json();if(!n.ok)throw Error(`Clean orphan files didn't finish. Try again in a moment.`);d(`Removed ${r.orphanFiles??0} orphan project file(s) and ${r.stagedFiles??0} stale staged file(s).`,`success`),await t.invalidateQueries({queryKey:x9})}catch(e){p(e instanceof Error?e.message:`Clean orphan files didn't finish. Try again in a moment.`)}finally{i(!1)}}bx({id:`settings.export-everything`,title:`Export everything`,group:`Settings`,context:`Backup & storage`,keywords:[`backup`,`download`],run:()=>{!r&&a.phase!==`preparing`&&g()}});let b=r||a.phase===`preparing`,x=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Export and import`,info:`settings.storage.export`,children:[(0,h.jsx)(R,{disabled:b,onClick:()=>void g(),children:`Export everything`}),(0,h.jsx)(R,{disabled:b,onClick:()=>x.current?.click(),children:`Import a backup`}),(0,h.jsx)(`input`,{ref:x,className:`sr-only`,type:`file`,tabIndex:-1,"aria-label":`Import a backup`,accept:`.tar,application/x-tar,.zip,application/zip`,disabled:b,onChange:e=>{let t=e.target.files?.[0];t&&v(t),e.target.value=``}}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:b,onClick:()=>void y(),children:`Clean orphan files`}),(0,h.jsx)(V,{id:`settings.storage.clean`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Provider keys are never included in a backup. After importing, enter them again in Settings → Providers.`}),a.phase===`preparing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Preparing the backup…`}):null,a.phase===`downloading`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 min-w-0 flex-1 text-ink`,children:[`Downloading `,Y5(a.bytes),` (`,a.projects,` project`,a.projects===1?``:`s`,`). Your browser's downloads show its progress; keep Slopify running until it finishes.`]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>o({phase:`idle`}),children:`Dismiss`})]}):null,s.phase===`uploading`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[`Uploading the backup: `,Y5(s.sent),` of`,` `,Y5(s.total)]}),(0,h.jsx)(q2,{label:`Backup upload`,value:s.total===0?0:s.sent/s.total})]}):null,s.phase===`importing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Checking and importing the backup… large projects can take a minute.`}):null,f?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:f}):null]})]}),l?(0,h.jsx)(ESe,{result:l,onDismiss:()=>u(null)}):null,(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Disk space`,info:`settings.storage.disk`,meta:n.data?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`font-semibold text-ink`,children:[Y5(n.data.data),` stored`]}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[` `,`· `,Y5(Math.max(0,n.data.projects-n.data.trash.bytes)),` project files · `,Y5(n.data.staging),` staged files`,n.data.trash.projects>0?` · ${Y5(n.data.trash.bytes)} in the trash (${TSe(n.data.trash.projects)}), freed when removed for good`:null]})]}):n.error?`Storage usage is unavailable. Reload the page to try again.`:(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`})}),n.data&&n.data.byProject.length>0?(0,h.jsx)(Jve,{projects:n.data.byProject,queryKey:[...x9]}):null]})]})}function TSe(e){return e===1?`1 deleted project`:`${String(e)} deleted projects`}function T9(e,t){if(t===void 0)return null;let n=[t.added>0?`${t.added} added`:null,t.renamed>0?`${t.renamed} added as “(imported)” because the name was taken`:null,t.skipped>0?`${t.skipped} already here`:null].filter(e=>e!==null);return n.length===0?null:`${e}: ${n.join(`, `)}.`}function ESe({result:e,onDismiss:t}){let n=[e.projects.imported.length>0?`Projects: ${e.projects.imported.length} added (${Y5(e.files.bytes)} of files).`:`Projects: none added.`,T9(`Prompts`,e.prompts),T9(`Intros and outros`,e.entries),T9(`Channels`,e.channels),T9(`Cast members`,e.cast),T9(`Episode memories`,e.episodeMemories),T9(`Existing videos`,e.channelVideos),T9(`Document themes`,e.documentThemes),T9(`Templates`,e.templates),T9(`Schedules`,e.schedules),e.schedules.paused>0?`${e.schedules.paused} schedule(s) arrived paused so two installs never run them both; resume them on the Schedules screen.`:null,T9(`Voices`,e.voices),T9(`Play drafts`,e.drafts),e.settings.added+e.settings.kept>0?`Settings: ${e.settings.added} filled in${e.settings.kept>0?`, ${e.settings.kept} kept as this install has them`:``}.`:null,e.fonts>0?`Uploaded fonts: ${e.fonts} added.`:null,e.usage.alreadyImported?`Usage: this backup's history was already added before, so it wasn't counted twice.`:`Usage: ${e.usage.events} recorded event(s) added to the totals.`,`Provider keys are not in backups: enter them in Settings → Providers.`].filter(e=>e!==null);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{as:`h3`,title:`Imported the backup from ${e.backup.createdAt.slice(0,10)}`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`Dismiss`})}),(0,h.jsxs)(`ul`,{"aria-label":`Import result`,className:`m-0 list-disc pl-5 text-small text-ink-2`,children:[n.map(e=>(0,h.jsx)(`li`,{className:`py-0.5`,children:e},e)),e.projects.skipped.map(e=>(0,h.jsxs)(`li`,{className:`py-0.5`,children:[`Skipped “`,e.title,`”: `,e.reason]},e.id))]})]})}function DSe(){let{api:e}=z(),t=_(),n=N(ob(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Qo(e,t),onMutate:e=>{let n=t.getQueryData(B.settings);return t.setQueryData(B.settings,e),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(B.settings,r.previous)},onSuccess:e=>{t.setQueryData(B.settings,e)}});if((0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>{o(!1)},Y2);return()=>{clearTimeout(e)}},[a]),n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});if(n.data===void 0)return(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,role:`status`,"aria-label":`Loading settings`,children:[(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`})]});let c=n.data,l=r??String(c.silenceGapSeconds),u=bSe(l);return(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Silence between segments`,tip:`settings.playback.silence-gap`,help:`Seconds of quiet between narrated segments.`,error:u??s.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:0,max:S9,step:1,className:`w-[88px] tabular-nums`,value:l,"aria-invalid":u!==void 0,onChange:e=>{i(e.target.value)}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`seconds`}),(0,h.jsx)(R,{variant:`primary`,disabled:u!==void 0||s.isPending,onClick:()=>{o(!1),s.mutate({...c,silenceGapSeconds:Number(l.trim())},{onSuccess:()=>{i(void 0),o(!0)}})},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null})]})}),(0,h.jsxs)(`div`,{className:`sl-field`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Appearance`}),(0,h.jsx)(V,{id:`settings.appearance`,className:`-my-1`})]}),(0,h.jsx)(Ab,{label:`Appearance`,value:c.appearance,options:ySe,className:`self-start`,onChange:e=>{s.mutate({...c,appearance:e})}})]}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(k6,{value:c.loudness??tk,switchLabel:`Level the volume for new runs`,switchTip:`settings.loudness`,onChange:e=>{s.mutate({...c,loudness:e})}})})]})}function OSe({open:e,onClose:t,onInstalled:n}){let{api:r}=z(),i=_(),a=N({queryKey:My,queryFn:()=>Iy(r),enabled:e}),o=P({mutationFn:e=>Ry(r,e),onSuccess:()=>n(),onSettled:()=>i.invalidateQueries({queryKey:My})});return(0,h.jsxs)(YP,{open:e,title:`Add a starter pack`,onClose:t,footer:(0,h.jsx)(Q1,{tone:o.error||a.error?`error`:`success`,children:o.error?.message??a.error?.message??(o.data===void 0?void 0:o.data.added?`Added: its prompts are in Prompts and its template is in this list.`:`That pack was already added.`)}),children:[(0,h.jsxs)(`p`,{className:`mb-4 flex items-center gap-1 text-small text-ink-2`,children:[`Prompts, a suggested voice and a template for one kind of channel.`,(0,h.jsx)(V,{id:`welcome.packs`})]}),(0,h.jsxs)(pU,{label:`Starter packs`,className:`[&_.sl-row__meta]:whitespace-normal`,children:[(a.data?.packs??[]).map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:(0,h.jsx)(R,{disabled:e.installed||o.isPending,onClick:()=>o.mutate(e.id),children:e.installed?`Added`:`Add pack`})},e.id)),a.data===void 0?(0,h.jsx)(mU,{title:`Loading packs…`}):null]})]})}function kSe({template:e}){let{api:t}=z(),n=N({queryKey:[...Lq,e.id,e.version],queryFn:async()=>{let n=await Uq(t,e.id);if(!n.ok)throw Error(n.message);return n.value}});if(n.error)return(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The keywords of `,e.name,` didn't load. `,n.error.message,` Press Keywords again.`]});if(!n.data)return(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`Reading the keywords…`});let{form:r,librarySnapshot:i}=n.data.document,a=h0({form:r,prompts:i?.prompts??[],entries:i?.entries??[]}),o=z3(r.title),s=[...new Set([...a.keys(),...Object.keys(r.values)])];return(0,h.jsx)(_0,{keywords:s.map(e=>({name:e,value:r.values[e]??``,feeds:a.get(e)??[],topic:o.includes(e)})),empty:`No keywords: the prompts and the title name none.`})}async function ASe(e,t,n,r){let i=await Gq(e,t.id,{baseVersion:t.version,mutationId:r,...n});if(!i.ok)throw Error(i.message);return i.value}function jSe({template:e}){return e===void 0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`Pick a template to see the keywords it fills.`}):(0,h.jsxs)(`section`,{"aria-label":`Keywords of ${e.name}`,className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:e.name,as:`h3`,info:`templates.edit`,className:`pb-0`}),(0,h.jsx)(kSe,{template:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`To change the settings, press Use in Play, change the draft, then Save a setup.`})]})}function MSe({template:e,onClose:t}){let{api:n}=z(),r=_(),i=Array.from({length:e.version},(t,n)=>e.version-n),a=ot({queries:i.map(t=>({queryKey:[...Lq,e.id,`version`,t],queryFn:async()=>{let r=await Uq(n,e.id,t);if(!r.ok)throw Error(r.message);return r.value},staleTime:1/0}))}),o=a[0]?.data,[s,c]=(0,m.useState)(i[1]??e.version),l=a[i.indexOf(s)]?.data,u=(0,m.useRef)(crypto.randomUUID()),d=Oy(),f=P({mutationFn:t=>ASe(n,e,{name:t.name,document:t.document},u.current),onSuccess:async(n,i)=>{u.current=crypto.randomUUID(),d(`Restored version ${String(i.version)} of ${e.name} as version ${String(n.version)}.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}}),p=a.find(e=>e.error!==null)?.error;return(0,h.jsx)(YP,{open:!0,title:`History of ${e.name}`,onClose:t,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[p?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:`A version couldn't be read: ${p.message} Close History and open it again.`}):null,(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Versions`,as:`h3`,info:`templates.history`}),(0,h.jsx)(pU,{label:`Versions of ${e.name}`,children:i.map((t,n)=>{let r=a[n]?.data;return(0,h.jsx)(mU,{title:`Version ${String(t)}`,selected:t===s,onSelect:()=>c(t),meta:r===void 0?`Loading…`:`${r.name} · ${j4(r.updatedAt)}`,actions:t===e.version?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(R,{size:`small`,"aria-label":`Restore version ${String(t)}`,disabled:r===void 0||f.isPending,disabledReason:r===void 0?`Reading the version`:`Restoring`,onClick:()=>{r!==void 0&&f.mutate(r)},children:`Restore`})},t)})}),(0,h.jsx)(Q1,{tone:`error`,children:f.error===null?void 0:`The version wasn't restored: ${f.error.message}`})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`Compare with the current version`,as:`h3`}),o===void 0||l===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Loading the versions…`}):l.version===o.version?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.version===1?`This is the only version so far.`:`Pick an older version in the list to compare it.`}):(0,h.jsxs)(h.Fragment,{children:[l.name===o.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${l.name}" to "${o.name}".`}),(0,h.jsx)(w4,{before:E9(l),after:E9(o),beforeLabel:`Version ${String(l.version)}`,afterLabel:`Version ${String(o.version)} (current)`})]})]})]})})}function E9(e){return JSON.stringify(e.document,null,1).split(`
307
+ `),s].find(e=>e?.trim())??`No text was recorded for this part.`}catch{return`Recorded text cannot be decoded.`}}function mbe({projectId:e,pending:t,onRestore:n}){let{api:r}=z(),[i,a]=(0,m.useState)(),o=N({queryKey:B.revisions(e),queryFn:async()=>{let t=await xfe(r,e);if(!t.ok)throw Error(t.message);return t.value.revisions}}),s=N({queryKey:B.revision(e,i??``),enabled:i!==void 0,queryFn:async()=>{if(i===void 0)throw Error(`Choose a version from History first.`);let t=await a2(r,e,i);if(!t.ok)throw Error(t.message);return t.value.view}}),c=s.data,l=c?.outputs.find(e=>e.selected&&e.available&&(e.output.role===`image`||e.output.role===`thumbnail`)),u=l??c?.outputs.find(e=>e.available);return(0,h.jsxs)(`section`,{"aria-label":`Project history`,className:`space-y-3`,children:[(0,h.jsx)(H,{title:`Project history`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:o.error.message}),(0,h.jsx)(`ol`,{className:`space-y-2`,children:o.data?.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(R,{type:`button`,onClick:()=>a(e.id),children:[e.title,` · `,e.createdAt,e.current?` · Current`:``]})},e.id))}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,children:s.error.message}),c===void 0?null:(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(0,h.jsx)(`h3`,{className:`m-0 text-title-3`,children:c.revision.config.title}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{variant:`primary`,disabled:t,onClick:()=>n(c.revision.id),children:`Restore this revision`}),l===void 0?null:(0,h.jsxs)(mS,{href:Efe(r,e,c.revision.id),download:!0,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download all images`]}),u===void 0?null:(0,h.jsx)(u2,{projectId:e,asset:``,folder:{revisionId:c.revision.id,recordId:u.recordId}})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-3 p-0`,children:c.outputs.map(t=>(0,h.jsxs)(`li`,{className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:C7(t.output)}),(0,h.jsxs)(`span`,{className:`text-small text-ink-2`,children:[` · ${t.state}${t.selected?``:` · Earlier result`}`,t.available?``:` · File missing`]})]}),t.available?(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,"aria-label":`Download ${C7(t.output)}`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download`]}):null]}),t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained output`}),t.output.role===`video`?(0,h.jsx)(R0,{className:`max-w-[640px]`,label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):[`audio_export`,`audio_body`,`audio_intro`,`audio_outro`].includes(t.output.role)?(0,h.jsx)($8,{label:C7(t.output),src:s2(r,e,c.revision.id,t.recordId)}):t.output.role===`image`||t.output.role===`thumbnail`?(0,h.jsx)(z0,{className:`max-w-[480px]`,alt:C7(t.output),title:C7(t.output),meta:t.selected?`Current`:`Earlier result`,src:s2(r,e,c.revision.id,t.recordId)}):(0,h.jsx)(`p`,{children:`Use Download to inspect this retained file.`})]}):null]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained narration parts`,children:c.pieces.filter(e=>e.stageKind===`audio`&&e.assetId!==null).map(t=>(0,h.jsxs)(`li`,{children:[`Narration part `,t.piece.idx,t.selected?``:` · Earlier result`,t.available?(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Preview retained audio part`}),(0,h.jsx)($8,{label:`Narration part ${String(t.piece.idx)}`,src:s2(r,e,c.revision.id,t.recordId)}),(0,h.jsxs)(mS,{href:s2(r,e,c.revision.id,t.recordId),download:!0,size:`small`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download narration part`]})]}):(0,h.jsx)(`span`,{children:` · File missing`})]},t.recordId))}),(0,h.jsx)(`ul`,{"aria-label":`Retained text parts`,children:c.pieces.filter(e=>e.assetId===null).map(e=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(`details`,{children:[(0,h.jsxs)(`summary`,{children:[e.stageKind,` part `,e.piece.idx]}),(0,h.jsx)(`pre`,{className:`whitespace-pre-wrap break-words`,children:pbe(e.piece.payload)})]})},e.recordId))})]})]})}function M7(e,t,n){let r=JSON.stringify(t);return e?.payload===r?e:{payload:r,idempotencyKey:n()}}function hbe(e,t,n={}){let{api:r}=z(),i=_(),a=N({queryKey:B.revision(e,t??``),enabled:t!==null,queryFn:async()=>{if(t===null)throw Error(`This project has no saved settings to show yet. Reload the page and try again.`);let n=await a2(r,e,t);if(!n.ok)throw Error(n.message);return n.value.view}}),[o,s]=(0,m.useState)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(),[f,p]=(0,m.useState)(),[h,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(),w=(0,m.useRef)(void 0),T=(0,m.useRef)(void 0),E=(0,m.useRef)(void 0),D=(0,m.useRef)(n.onOpenEdit);D.current=n.onOpenEdit;let O=(0,m.useMemo)(()=>c!==void 0&&(o===void 0||(c.regenerate?.length??0)>0||(c.uploads?.length??0)>0||JSON.stringify(c.config)!==JSON.stringify(o.revision.config)||JSON.stringify(c.content)!==JSON.stringify(o.revision.content)),[c,o]),k=c!==void 0&&o!==void 0&&t!==null&&t!==o.revision.id,A=(0,m.useRef)(!1);async function ee(e){if(!A.current){A.current=!0,g(!0),x(void 0),C(void 0);try{await e()}catch(e){x(e instanceof Error?e.message:String(e))}finally{A.current=!1,g(!1)}}}async function te(t){let n=await r2(r,e);if(!n.ok){C(n);return}return C(void 0),s(n.value.view),t&&l({config:structuredClone(n.value.view.revision.config),content:structuredClone(n.value.view.revision.content)}),n.value.view}async function ne(t){let n=await jo(r,e);return i.setQueryData(B.project(e),n),await i.invalidateQueries({queryKey:B.revisions(e)}),!t.current||n.revisionId!==t.revision.id?(C({ok:!1,reason:`conflict`,message:`The project changed again. Your draft is preserved.`,currentRevisionId:n.revisionId,fields:[]}),!1):(s(t),l(void 0),C(void 0),d(void 0),!0)}async function j(){if(v||o===void 0||c===void 0)return;let t={baseRevisionId:o.revision.id,edit:c},n=M7(w.current,t,()=>crypto.randomUUID());w.current=n;let i=await i2(r,e,{...t,idempotencyKey:n.idempotencyKey});if(!i.ok){C(i);return}await ne(i.value.view),w.current=void 0}async function re(t,n=u){if(n===void 0)return;let a={baseRevisionId:n.baseRevisionId,previewId:n.id,...t},o=M7(E.current,a,()=>crypto.randomUUID());E.current=o;let s=await wfe(r,e,{...a,idempotencyKey:o.idempotencyKey});if(!s.ok){C(s),(s.reason===`stale-preview`||s.reason===`conflict`)&&d(void 0);return}E.current=void 0,d(void 0),await i.invalidateQueries({queryKey:B.project(e)})}async function M(t,n){let i=await te(!1);if(i===void 0)return;let a=await Cfe(r,e,{baseRevisionId:i.revision.id,request:t});if(!a.ok){C(a);return}let o=a.value.value;if(E.current=void 0,n&&gbe(o)){await re({acknowledgeUnknownCosts:!1,confirmedProvidedWorkKeys:[]},o);return}d(o)}async function ie(t){let n=o??a.data??await te(!1);if(n===void 0)return;let i={baseRevisionId:n.revision.id,targetRevisionId:t},s=M7(T.current,i,()=>crypto.randomUUID());T.current=s;let c=await bfe(r,e,{...i,idempotencyKey:s.idempotencyKey});if(!c.ok){C(c);return}await ne(c.value.view),T.current=void 0}return{saved:a,view:o,edit:c,preview:u,focus:f,pending:h,uploading:v,error:b,refusal:S,unsaved:O,remoteChanged:k,busy:h||v||c!==void 0||u!==void 0,setEdit:l,setUploading:y,openEditor:()=>void ee(async()=>{await te(!0)}),discard:()=>{l(void 0),C(void 0),y(!1),w.current=void 0},save:()=>void ee(j),reloadDraft:()=>void ee(async()=>{w.current=void 0,y(!1),await te(!0),C(void 0)}),reloadCurrent:()=>void ee(async()=>{T.current=void 0,E.current=void 0,d(void 0),await te(!1),await i.invalidateQueries({queryKey:B.project(e)})}),requestEdit:e=>void ee(async()=>{let t=o,n=c;if(t===void 0||n===void 0){if(t=await te(!1),t===void 0)return;n={config:structuredClone(t.revision.config),content:structuredClone(t.revision.content)}}l(e.change(n,t)),p({section:e.section}),D.current?.()}),regenerateNow:t=>void ee(async()=>{let n=e=>({...e,regenerate:[...new Set([...e.regenerate??[],...t])]});if(c!==void 0&&O){l(n(c)),p({section:`images`}),D.current?.();return}let i=await te(!1);if(i===void 0)return;let a=await i2(r,e,{baseRevisionId:i.revision.id,edit:n({config:structuredClone(i.revision.config),content:structuredClone(i.revision.content)}),idempotencyKey:crypto.randomUUID()});if(!a.ok){C(a);return}await ne(a.value.view)&&await M({kind:`selected`,workKeys:t},!0)}),review:(e,t)=>void ee(()=>M(e,t?.autoStart===!0)),start:e=>void ee(()=>re(e)),closePreview:()=>{h||(d(void 0),E.current=void 0)},restore:e=>void ee(()=>ie(e))}}function gbe(e){return!e.work.some(e=>e.disposition===`blocked`)&&e.providedReuseRequired.length===0&&e.costs.unknown===0}function _be({controller:e,renderEditor:t,active:n=!0,intro:r}){let i=e;return i.view===void 0||i.edit===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r??(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Saved revision`,info:`project.saved-revision`}),i.saved.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.saved.error.message}),i.saved.data===void 0?null:(0,h.jsx)(`ul`,{"aria-label":`Saved output status`,className:`sl-list m-0 list-none p-0`,children:i.saved.data.outputs.filter(e=>e.selected).map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:C7(e.output)}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.available?e.state===`ready`?`Ready`:e.state===`outdated`?`Outdated; the retained version stays until it is remade`:`Provided content needs review`:`Retained file missing`})]},e.recordId))})]}),i.preview===void 0&&n?(0,h.jsx)(j7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{children:[i.refusal?.reason===`conflict`&&n?(0,h.jsx)(R,{disabled:i.pending,onClick:i.reloadCurrent,children:`Reload current revision`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{disabled:i.busy,onClick:()=>i.review({kind:`allAffected`}),variant:`secondary`,children:`Choose what to remake`}),(0,h.jsx)(V,{id:`project.choose-remake`})]}),(0,h.jsx)(R,{variant:`primary`,disabled:i.busy,onClick:i.openEditor,children:`Edit project`})]})]}):(0,h.jsxs)(`form`,{"aria-label":`Edit project`,onSubmit:e=>{e.preventDefault(),i.save()},children:[(0,h.jsx)(`fieldset`,{disabled:i.pending,className:`m-0 min-w-0 border-0 p-0`,children:t({view:i.view,edit:i.edit,fields:i.refusal?.fields??[],onChange:i.setEdit,onPending:i.setUploading,...i.focus===void 0?{}:{focus:i.focus}})}),i.preview===void 0?(0,h.jsx)(j7,{error:i.error,refusal:i.refusal}):null,(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:i.remoteChanged?`warning`:`info`,children:i.remoteChanged?`A newer revision is available. Your unsaved changes are kept below.`:i.uploading?`Waiting for uploads to finish…`:void 0}),children:[i.remoteChanged||i.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:i.pending||i.uploading,onClick:i.reloadDraft,children:`Reload current revision and discard my draft`}):null,(0,h.jsx)(R,{variant:`quiet`,disabled:i.pending||i.uploading,onClick:i.discard,children:`Discard changes`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:i.pending||i.uploading,children:`Save changes`})]})]})}function vbe({controller:e,projectId:t,active:n}){let r=e;return n?(0,h.jsxs)(h.Fragment,{children:[r.preview===void 0&&(r.error||r.refusal)?(0,h.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3`,children:[(0,h.jsx)(j7,{error:r.error,refusal:r.refusal}),r.edit===void 0&&r.refusal?.reason===`conflict`?(0,h.jsx)(R,{disabled:r.pending,onClick:r.reloadCurrent,className:`self-start`,children:`Reload current revision`}):null]}):null,(0,h.jsx)(mbe,{projectId:t,pending:r.busy,onRestore:r.restore})]}):null}function ybe({controller:e}){let t=e;return(0,h.jsx)(YP,{open:t.preview!==void 0,title:`Choose what to remake`,onClose:t.closePreview,children:t.preview===void 0?null:(0,h.jsx)(w7,{preview:t.preview,feedback:(0,h.jsx)(j7,{error:t.error,refusal:t.refusal}),pending:t.pending,onStart:t.start,onCancel:t.closePreview},t.preview.id)})}var bbe=(e,t)=>{if(t)return`waiting`;switch(e.state){case`running`:return`running`;case`done`:case`provided`:return`done`;case`failed`:return e.retryAt===void 0?`failed`:`waiting`;default:return`off`}},xbe=(e,t)=>{if(t)return`Held for you`;switch(e.state){case`running`:return`Running`;case`done`:return`Done`;case`provided`:return`Provided`;case`failed`:return e.retryAt===void 0?`Failed`:`Waiting to try again`;case`canceled`:return`Canceled`;case`skipped`:return`Off`;case`pending`:return`Not started`}};function Sbe(e,t){if(e.startedAt===null)return;let n=Date.parse(e.startedAt),r=e.finishedAt===null?t:Date.parse(e.finishedAt);if(!Number.isFinite(n)||!Number.isFinite(r)||r<n)return;let i=Math.round((r-n)/1e3);if(i<1)return;if(i<60)return`${String(i)} s`;let a=Math.round(i/60);return a<60?`${String(a)} min`:`${String(Math.floor(a/60))} h ${String(a%60)} min`}function Cbe(e,t,n){let r=T3(t,n);return r===void 0?e:e===void 0||e===``?E3(r):`${e} · ${E3(r)}`}function wbe({stages:e,outputs:t,project:n,resumable:r,held:i,now:a}){return e.filter(e=>e.state!==`skipped`).map(e=>{let o=i.some(t=>t.stage===e.kind),s=Sbe(e,a);return{id:e.id,name:e.kind===`video`&&rF(n.config)===`audio`?`Audio export`:r5[e.kind],tone:bbe(e,o),state:xbe(e,o),...s===void 0?{}:{time:s},detail:o?`Held for your review`:Cbe(cF(e,t,n,r),e,a)}})}function Tbe({stages:e}){return(0,h.jsx)(`div`,{className:`sr-only`,children:e.filter(e=>e.state!==`skipped`).map(e=>(0,h.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:`${r5[e.kind]}: ${e.state}`},e.id))})}function Ebe({steps:e}){return(0,h.jsxs)(`section`,{"aria-labelledby":`run-steps-title`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{id:`run-steps-title`,title:`Run`,size:`small`,className:`pb-0`}),(0,h.jsx)(O3,{steps:e,label:`Run steps`,dense:!0})]})}var N7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0});function Dbe({cost:e,onOpen:t}){if(e===void 0||e.calls===0&&e.byStage.length===0)return null;let n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({key:`${e.account}/${t.kind}`,name:e.name,window:t.kind===`five_hour`?`5-hour`:t.kind===`weekly`?`weekly`:`current`,used:t.usedPercent,now:t.nowPercent})):[]);return(0,h.jsxs)(`section`,{"aria-labelledby":`cost-so-far-title`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{id:`cost-so-far-title`,title:`Cost so far`,size:`small`,className:`pb-0`,children:t===void 0?null:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`By stage`})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[(0,h.jsx)(`strong`,{className:`text-ink`,children:a7(e.cost)}),e.unpriced>0?` known, spent`:` spent`,e.apiEquivalent===null?null:` · ~${a7(e.apiEquivalent)} via API`,e.run===null||e.run.running?null:` · ${o7(e.run.workingMs)} of work`]}),n.map(e=>{let t=e.used<1?`under 1%`:`${N7.format(e.used)}%`,n=`${e.window} ${e.name} limit`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`${e.name}: ${t} of your ${e.window} limit`}),(0,h.jsx)(q2,{value:e.used/100,label:`Share of the ${n} this run used`,valueText:`${t} of your ${n}; now at ${N7.format(e.now)}%`,tone:e.now>=80?`waiting`:`accent`})]},e.key)})]})}function Obe({projectId:e,revisionId:t,title:n,open:r,onClose:i}){let{api:a}=z(),o=_(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=Oy(),g=(0,m.useRef)(!1),v=(0,m.useRef)(null);(0,m.useEffect)(()=>{r&&t!==null&&(c({revisionId:t,name:n}),f(null)),r||c(null)},[r,t,n]);async function y(){if(!s||g.current||!s.name.trim())return;g.current=!0,u(!0),f(null);let t=JSON.stringify([e,s.revisionId,s.name.trim()]);v.current?.key!==t&&(v.current={key:t,id:crypto.randomUUID()});try{let t=await qq(a,e,{id:v.current.id,name:s.name.trim(),revisionId:s.revisionId});if(!t.ok){v.current=null,f(t.message);return}v.current=null,i(),p(`Template saved.`,`success`),await o.invalidateQueries({queryKey:Lq})}catch(e){f(e instanceof Error?e.message:`The template wasn't saved. Press Save template to try again.`)}finally{g.current=!1,u(!1)}}return(0,h.jsx)(Ay,{open:r&&s!==null,onOpenChange:e=>{!e&&!g.current&&i()},title:`Save as template`,description:`Save this revision’s setup for a fresh Play draft. This does not rebuild the project.`,children:(0,h.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,h.jsx)(xV,{label:`Template name`,tip:`play.template-name`,children:(0,h.jsx)(CV,{autoFocus:!0,required:!0,maxLength:200,disabled:l,value:s?.name??``,onChange:e=>{let t=e.target.value;c(e=>e&&{...e,name:t})}})}),d?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:d}):null,(0,h.jsxs)(`div`,{className:`sl-dialog__foot`,children:[(0,h.jsx)(R,{disabled:l,onClick:i,children:`Cancel`}),(0,h.jsx)(R,{variant:`primary`,type:`submit`,disabled:l||!s?.name.trim(),children:`Save template`})]})]})})}var P7=q({baseRevisionId:W().min(1).max(64),idempotencyKey:wD()}).strict(),kbe=rO(`kind`,[q({kind:pO(`resume`)}).strict(),q({kind:pO(`retry`),stage:J(FS)}).strict(),q({kind:pO(`rerun`),stage:J(FS)}).strict(),q({kind:pO(`redo`),item:W().min(1).max(200)}).strict()]);P7.extend({action:kbe}).strict();var Abe=rO(`ok`,[q({ok:pO(!0),value:K0.and(q({warnings:K(W()).readonly()}))}),q({ok:pO(!1),reason:J([`no-project`,`no-revision`,`conflict`,`idempotency-conflict`,`invalid-edit`,`stale-preview`,`invalid-selection`,`review-required`,`cost-ack-required`,`readiness`,`running`,`accepted-job`,`control-changed`]),fields:K(q({field:W(),message:W()})).readonly().optional(),intentRevisionId:W().optional(),currentRevisionId:W().nullable().optional()})]),F7=new Set([400,404,409]);async function jbe(e,t,n){return L7(e,t,`cancel`,n)}async function Mbe(e,t,n){return L7(e,t,`pause`,n)}function Nbe(e,t,n){return R7(e,t,`resume`,n)}function Pbe(e,t,n,r){return R7(e,t,`stages/${n}/retry`,r)}function Fbe(e,t,n,r){return R7(e,t,`stages/${n}/soften`,r)}function Ibe(e,t,n,r){return R7(e,t,`stages/${n}/rerun`,r)}async function Lbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/providers`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function Rbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/subtitles`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}))}async function zbe(e,t,n){return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/article`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({markdown:n})}))}async function Bbe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].$delete({param:{id:t,outputId:n}}))}async function Vbe(e,t,n){return I7(await e.client.projects[`:id`].images[`:outputId`].regenerate.$post({param:{id:t,outputId:n}}))}async function I7(e){if(e.ok)return{ok:!0,value:await e.json()};let t=await mo(e);if(t!==void 0&&F7.has(e.status))return{ok:!1,message:po(e,t).message};throw po(e,t)}async function L7(e,t,n,r){let i=P7.parse(r);return I7(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}))}async function R7(e,t,n,r){let i=await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/${n}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(P7.parse(r))});if(i.ok){let e=Abe.parse(await i.json());if(!e.ok)throw Error(xo);return{ok:!0,value:e.value,warnings:e.value.warnings}}let a=await mo(i);if(a!==void 0&&F7.has(i.status))return{ok:!1,message:po(i,a).message};throw po(i,a)}function Hbe(e){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(),s=(0,m.useRef)(new Map),c=(0,m.useRef)(!1),l=P({mutationFn:async e=>{let r=e.action;if(![`pause`,`cancel`,`resume`,`retry`,`soften`,`rerun`].includes(r.kind))return B7(t,e.projectId,r);let i=r.kind===`retry`||r.kind===`soften`||r.kind===`rerun`?r.stage:``,a=`${e.projectId}:${r.kind}:${i}`,o=s.current.get(a);if(!o){let r=n.getQueryData(B.project(e.projectId))?.revisionId;if(!r){let n=await r2(t,e.projectId);if(!n.ok)return{ok:!1,message:n.message};r=n.value.view.revision.id}o={baseRevisionId:r,idempotencyKey:crypto.randomUUID()},s.current.set(a,o)}let c=await B7(t,e.projectId,r,o);return s.current.delete(a),c.ok&&await jo(t,e.projectId).then(t=>n.setQueryData(B.project(e.projectId),t),e=>console.warn(`Project refresh after an accepted action failed`,e)),c},onMutate:()=>{i(void 0),o(void 0)},onSuccess:async(e,t)=>{e.ok?(o(`warnings`in e&&e.warnings.length>0?e.warnings.join(` `):void 0),n.invalidateQueries({queryKey:B.projects})):i({message:e.message,stage:z7(t.action)}),await n.invalidateQueries({queryKey:B.project(t.projectId)})},onSettled:()=>{c.current=!1},onError:(e,t)=>{i({message:e.message,stage:z7(t.action)})}});return{run:(t,n)=>{c.current||(c.current=!0,l.mutate({projectId:e,action:t},{onSuccess:e=>{e.ok&&n?.()}}))},pending:l.isPending,performing:l.isPending?l.variables?.action:void 0,refusal:r,dismissRefusal:()=>{i(void 0)},notice:a}}function z7(e){switch(e.kind){case`cancel`:case`pause`:case`resume`:case`providers`:return;case`retry`:case`soften`:case`rerun`:return e.stage;case`subtitles`:return`video`;case`save-article`:return`article`;case`delete-image`:case`regenerate-image`:return`images`}}function B7(e,t,n,r){let i=()=>{if(!r)throw Error(`A saved revision and request identity are required.`);return r};switch(n.kind){case`pause`:return Mbe(e,t,i());case`cancel`:return jbe(e,t,i());case`resume`:return Nbe(e,t,i());case`retry`:return Pbe(e,t,n.stage,i());case`soften`:return Fbe(e,t,n.stage,i());case`rerun`:return Ibe(e,t,n.stage,i());case`providers`:return Lbe(e,t,n.choices);case`subtitles`:return Rbe(e,t,n.subtitles);case`save-article`:return zbe(e,t,n.markdown);case`delete-image`:return Bbe(e,t,n.outputId);case`regenerate-image`:return Vbe(e,t,n.outputId)}}var V7=e=>e.state===`done`||e.state===`provided`;function Ube(e){let t=e.find(e=>e.state===`failed`)??e.find(e=>e.state===`running`);if(t)return t.kind;let n=e.find(e=>e.kind===`video`&&V7(e));if(n)return n.kind;let r=e.find(e=>e.state===`pending`);return r?r.kind:e.find(e=>e.kind===`article`&&V7(e))?.kind??e.find(e=>e.state!==`skipped`)?.kind??`article`}function Wbe({projectId:e,openDraft:t}){return(0,h.jsx)(Gbe,{projectId:e,openDraft:t},e)}var H7=e=>{let t=e.filter(e=>e!==void 0);if(!(t.length===0||t.every(e=>e.state===`skipped`)))return t.some(e=>e.state===`failed`&&e.retryAt===void 0)?`failed`:t.some(e=>e.state===`running`)?`running`:t.some(e=>e.state===`failed`)?`waiting`:t.every(e=>e.state===`done`||e.state===`provided`||e.state===`skipped`)?`done`:`off`};function Gbe({projectId:e,openDraft:t}){let{api:n}=z(),r=Oy(),i=Jbe(e,t),a=N(Xy(n,e)),o=N(nb(n)),s=N(Zy(n,e)),c=Hbe(e),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(!1),y=a.data?.revisionId??null,b=hbe(e,y,{onOpenEdit:()=>u(`settings`)}),x=uI(e),S=(0,m.useRef)(void 0);(0,m.useEffect)(()=>{if(x===void 0){S.current=void 0;return}a.data!==void 0&&S.current!==x&&(S.current=x,x===`download`&&u(rF(a.data.project.config)===`article`?`article`:`video`))},[x,a.data]),N3(e,y);let C=N({queryKey:Ny,queryFn:()=>Vy(n)}),w=Hy(C.data,e),T=N({queryKey:f3(e,y??``),queryFn:()=>m3(n,e),enabled:y!==null,retry:!1}),E=T.data?.ok===!0?T.data.value.checkpoints:[],D=b.saved.data?.outputs.filter(e=>e.selected&&e.state===`outdated`).map(e=>({workKey:e.workKey,role:e.output.role}))??[],O=a.data?.project,k=a.data?.stages??[],A=a.data?.outputs??[],ee=A.some(e=>e.role===`video`),te=e=>u(e),ne=J_e({project:O??Kbe,stages:k,resumable:a.data?.resumable??!1,sample:w,gates:E,outdated:D,waits:s.data?.waits??[],uploadReady:ee,actions:c,controller:b,openSection:te,openUpload:()=>f(!0)}),j=l===`settings`,re=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!j){re.current=!1;return}b.edit!==void 0&&(re.current=!0),!(re.current||b.busy)&&(re.current=!0,b.openEditor())},[j,b]);let M=k.some(e=>e.state===`running`),ie=O?.status===`running`,ae=O?.title??``,oe=ne.next?.action;bx({id:`project.next`,title:oe?.label??`Show the project's next action`,group:`This project`,context:ae,keywords:[`next`,`continue`,`resume`,`approve`,`retry`],shortcut:lP.nextAction,run:()=>{oe===void 0?r(`This project has no next action right now: nothing waits on you.`,`info`):oe.intent.kind===`soften`?r(`Soften and retry asks first: press it in the Next action panel on the right.`):ne.run(oe.intent)}}),Yx(Wx.showImages(e),()=>{let e=a.data?.stages.find(e=>e.kind===`images`);e===void 0||e.state===`skipped`?r(`${ae} makes no slideshow images, so there is no image to regenerate. To add them, open Settings in this project and choose how its images are made.`,`error`):u(`images`)},a.data!==void 0),bx({id:`project.pause`,title:O?.status===`paused`?`Continue the run`:`Pause the run`,group:`This project`,context:ae,keywords:[`pause`,`resume`,`continue`,`stop`],run:()=>c.run({kind:O?.status===`paused`?`resume`:`pause`})}),bx({id:`project.prepare-upload`,title:`Prepare upload`,group:`This project`,context:ae,keywords:[`youtube`,`studio`,`upload`,`publish`],run:()=>{ee?f(!0):r(`Prepare upload opens once the video has been made.`,`info`)}}),bx({id:`project.settings`,title:`Edit project settings`,group:`This project`,context:ae,keywords:[`edit`,`settings`,`prompts`,`providers`,`channel`],run:()=>u(`settings`)}),bx({id:`project.rebuild-review`,title:`Choose what to remake`,group:`This project`,context:ae,keywords:[`rebuild`,`review`,`remake`,`outdated`,`affected`],run:()=>b.review({kind:`allAffected`})}),bx({id:`project.template`,title:`Save as template`,group:`This project`,context:ae,keywords:[`template`,`reuse`],run:()=>g(!0)}),bx({id:`project.cancel`,title:`Cancel the run`,group:`This project`,context:ae,keywords:[`cancel`,`stop`],run:()=>v(!0)});let se=K_e(D);if(bx({id:`project.remake-1`,title:se[0]?.label??`Remake outdated outputs`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`],run:()=>{let e=se[0];e===void 0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e.workKeys},{autoStart:!0})}}),bx({id:`project.remake-all`,title:`Remake everything outdated`,group:`This project`,context:ae,keywords:[`remake`,`outdated`,`rebuild`,`all`],run:()=>{let e=[...new Set(se.flatMap(e=>e.workKeys))];e.length===0?r(`Nothing is outdated in this project.`,`info`):b.review({kind:`selected`,workKeys:e},{autoStart:!0})}}),bx({id:`project.copy`,title:`Make my own copy`,group:`This project`,context:ae,keywords:[`sample`,`copy`,`duplicate`],run:()=>w?ne.run({kind:`copy-sample`}):r(`Only the sample project is copied this way.`,`info`)}),a.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The project could not be loaded.`,children:`${a.error.message} Reload the page to try again, or go back to Projects.`});if(a.data===void 0||O===void 0)return(0,h.jsx)(qbe,{});let ce=e=>k.find(t=>t.kind===e),le=ce(`article`),ue=ce(`research`),de=ce(`audio`),fe=ce(`images`),pe=ce(`thumbnail`),me=ce(`video`),he=ce(`document`),ge=O.config,_e=e=>e!==void 0&&e.state!==`skipped`,ve=ge.shorts?.enabled===!0||A.some(e=>e.role===`short_video`||e.role===`shorts`),ye=ge.youtubeDescription===!0||A.some(e=>e.role===`youtube_description`),be=E.filter(e=>e.state===`held`||e.state===`pending-review`),xe=[..._e(le)||_e(ue)?[{id:`article`,label:`Article`,tone:H7([le,ue])}]:[],..._e(de)?[{id:`narration`,label:`Narration`,tone:H7([de])}]:[],..._e(fe)||_e(pe)||ge.reference!==void 0?[{id:`images`,label:`Images`,tone:H7([fe,pe])}]:[],..._e(me)?[{id:`video`,label:rF(ge)===`audio`?`Audio export`:`Video`,tone:H7([me])}]:[],...ve?[{id:`shorts`,label:`Shorts`}]:[],...ye?[{id:`youtube`,label:`YouTube`}]:[],..._e(he)?[{id:`document`,label:`PDF`,tone:H7([he])}]:[],{id:`cost`,label:`Cost`},{id:`live`,label:`Live`}].map(e=>{let t=se.filter(t=>t.section===e.id).reduce((e,t)=>e+t.count,0);return t===0?e:{...e,meta:`${String(t)} outdated`}}),Se=[{id:`settings`,label:`Settings`,...b.unsaved?{meta:`unsaved`}:{}},...y===null?[]:[{id:`checkpoints`,label:`Checkpoints`,...be.length===0?{}:{meta:`${String(be.length)} held`}}],{id:`history`,label:`History`}],Ce=[...xe,...Se],we=ne.next?.situation,Te=ne.next?.section!==void 0&&we!==`done`&&we!==`running`?ne.next.section:we===`done`&&A.some(e=>e.role===`youtube_description`)?`youtube`:n5(Ube(k)),Ee=l!==void 0&&Ce.some(e=>e.id===l)?l:Ce.find(e=>e.id===Te)?.id??xe[0]?.id??`cost`,De=(...e)=>y===null?O.status===`running`||O.status===`paused`||M||c.pending:c.pending||e.some(e=>e?.state===`running`),Oe={project:O,outputs:A,actions:c,next:ne,resumable:a.data.resumable},ke=(e,t)=>e===void 0?null:(0,h.jsx)(Bve,{stage:e,...t===void 0||t.state===`skipped`?{}:{companion:t},project:O,outputs:A,actions:c,busy:De(e,t)}),Ae=(...e)=>A.some(t=>e.some(e=>e!==void 0&&t.stageKind===e.kind)),je=(...e)=>Ae(...e)||e.some(e=>e!==void 0&&[`running`,`done`,`provided`,`failed`,`canceled`].includes(e.state)),Me=[{id:`rebuild`,label:`Choose what to remake…`,run:()=>b.review({kind:`allAffected`}),disabled:b.busy},{id:`template`,label:`Save as template…`,run:()=>g(!0),disabled:y===null||w},{id:`cancel`,label:`Cancel the run…`,run:()=>v(!0),disabled:!ie||c.pending,apart:!0}],Ne=t5({kind:`cancel`}),Pe=c.refusal?.stage===void 0?c.refusal:void 0,Fe=Pe===void 0?c.notice===void 0?b.preview===void 0&&(b.error||b.refusal)&&Ee!==`settings`&&Ee!==`history`?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:b.error??b.refusal?.message}):void 0:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:c.notice}):(0,h.jsx)(SI,{tone:`danger`,title:Pe.message,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,className:`mt-1`,onClick:c.dismissRefusal,children:`Dismiss`})}),Ie=wbe({stages:k,outputs:A,project:O,resumable:a.data.resumable,held:be.map(e=>({checkpointId:e.checkpointId,stage:e.stage,dependents:e.dependents})),now:Date.now()});return(0,h.jsx)(t_e,{projectId:e,revisionId:y,children:(0,h.jsx)(J8,{value:y!==null,children:(0,h.jsx)(g3,{value:e=>u(e===`edit`?`settings`:`article`),children:(0,h.jsx)(Y8,{value:b.pending||b.preview!==void 0?void 0:b.requestEdit,children:(0,h.jsxs)(X8,{value:b.pending||b.preview!==void 0?void 0:b.regenerateNow,children:[(0,h.jsxs)(`div`,{className:`sl-project`,children:[(0,h.jsx)(`div`,{"data-tour":`project-controls`,children:(0,h.jsx)(Zve,{project:O,prompts:o.data?.prompts,editing:Ee===`settings`,onEdit:()=>u(`settings`),more:Me,nextChapter:i,clock:(0,h.jsx)(iye,{cost:s.data,status:O.status,measuredAt:s.dataUpdatedAt})})}),(0,h.jsx)(Tbe,{stages:k}),(0,h.jsxs)(Aq,{sections:(0,h.jsxs)(e8,{label:`Project sections`,children:[xe.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:te},e.id)),(0,h.jsx)(`hr`,{className:`sl-rule my-2`}),Se.map(e=>(0,h.jsx)(W7,{item:e,selected:Ee,onSelect:te},e.id))]}),aside:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(X_e,{state:ne,feedback:Fe}),O===void 0?null:(0,h.jsx)(Xve,{projectId:e,title:O.title,status:O.status,sample:w||C.isPending}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-6 max-[1180px]:hidden`,children:[(0,h.jsx)(Ebe,{steps:Ie}),(0,h.jsx)(Dbe,{cost:s.data,onOpen:()=>te(`cost`)}),(0,h.jsx)(Pge,{})]})]}),children:[(0,h.jsx)(u5,{id:`article`,title:`Article`,stages:[le,ue].filter(U7),active:Ee===`article`,...Oe,children:_e(le)||_e(ue)?ke(le,ue):(0,h.jsx)(d5,{stage:le,project:O,name:`Article`})}),(0,h.jsx)(u5,{id:`narration`,title:`Narration`,stages:[de].filter(U7),active:Ee===`narration`,...Oe,children:je(de)?ke(de):(0,h.jsx)(d5,{stage:de,project:O,name:`Narration`})}),(0,h.jsx)(u5,{id:`images`,title:`Images`,head:!1,stages:[fe,pe].filter(U7),active:Ee===`images`,...Oe,children:ke(fe,pe)}),(0,h.jsx)(u5,{id:`video`,title:rF(ge)===`audio`?`Audio export`:`Video`,stages:[me].filter(U7),active:Ee===`video`,...Oe,children:ke(me)}),me===void 0?null:(0,h.jsx)(u5,{id:`shorts`,title:`Shorts`,stages:[],active:Ee===`shorts`,...Oe,meta:`Vertical clips picked from the video, each with its title and hashtags`,children:(0,h.jsx)(jve,{stage:me,project:O,outputs:A})}),me===void 0?null:(0,h.jsx)(u5,{id:`youtube`,title:`YouTube`,stages:[],active:Ee===`youtube`,...Oe,meta:`The description, chapters, hashtags and tags, as they go into YouTube Studio`,...ee&&ne.next?.action?.intent.kind!==`prepare-upload`?{extra:(0,h.jsx)(R,{variant:`secondary`,onClick:()=>f(!0),children:`Prepare upload`})}:{},children:(0,h.jsx)(Vve,{stage:me,project:O,outputs:A})}),he===void 0?null:(0,h.jsx)(u5,{id:`document`,title:`PDF`,stages:[he],active:Ee===`document`,...Oe,children:je(he)?ke(he):(0,h.jsx)(d5,{stage:he,project:O,name:`PDF`})}),(0,h.jsx)(G7,{id:`cost`,title:`Run cost`,selected:Ee,children:(0,h.jsx)(nye,{projectId:e})}),(0,h.jsx)(G7,{id:`live`,title:`Live`,selected:Ee,children:Ee===`live`?(0,h.jsx)(pye,{project:O,revisionId:y,stages:k,outputs:A}):null}),(0,h.jsx)(G7,{id:`settings`,title:`Settings`,selected:Ee,children:(0,h.jsx)(_be,{controller:b,active:Ee===`settings`,renderEditor:e=>(0,h.jsx)(rbe,{...e,renderContent:e=>(0,h.jsx)(zye,{...e},e.view.revision.id)})})}),y===null?null:(0,h.jsx)(G7,{id:`checkpoints`,title:`Checkpoints`,selected:Ee,children:(0,h.jsx)(Kve,{projectId:e,revisionId:y,paused:O.status===`paused`,stages:k,approvedInRail:ne.next?.action?.intent.kind===`approve`?ne.next.action.intent.gate.checkpointId:void 0})}),(0,h.jsx)(G7,{id:`history`,title:`History`,selected:Ee,children:(0,h.jsx)(vbe,{controller:b,projectId:e,active:Ee===`history`})})]})]}),(0,h.jsx)(ybe,{controller:b}),d?(0,h.jsx)(v2,{projectId:e,onClose:()=>f(!1)}):null,(0,h.jsx)(Obe,{projectId:e,revisionId:y,title:O.title,open:p,onClose:()=>g(!1)}),(0,h.jsx)(jy,{open:_,title:Ne.title,consequence:Ne.consequence,confirmLabel:Ne.verb,cancelLabel:Ne.dismiss,pending:c.pending,onConfirm:()=>{v(!1),c.run({kind:`cancel`})},onCancel:()=>v(!1)})]})})})})})}var U7=e=>e!==void 0;function W7({item:e,selected:t,onSelect:n}){return(0,h.jsx)(t8,{className:`max-md:w-auto`,"data-tour":`project-rail-${e.id}`,current:e.id===t,onClick:()=>n(e.id),...e.tone===void 0?{}:{icon:(0,h.jsx)(gS,{tone:e.tone})},...e.meta===void 0?{}:{meta:e.meta},children:e.label})}function G7({id:e,title:t,selected:n,children:r}){return(0,h.jsxs)(`section`,{hidden:n!==e,"aria-label":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:t}),r]})}var Kbe={id:``,title:``,format:`16:9`,status:`pending`,createdAt:``,config:{sources:{}}};function qbe(){return(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading project`,children:[(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-8 w-80 max-w-full rounded-control bg-sunken`})]}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(`div`,{className:`flex flex-col gap-2`,children:[`a`,`b`,`c`,`d`,`e`].map(e=>(0,h.jsx)(`span`,{className:`h-8 rounded-control bg-sunken`},e))}),aside:(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`}),children:(0,h.jsx)(`span`,{className:`h-[480px] rounded-control bg-sunken`})})]})}function Jbe(e,t){let{api:n}=z(),r=(0,m.useRef)(void 0),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0);if(t!==void 0)return{pending:i,error:o,run:()=>{i||(r.current??=crypto.randomUUID(),a(!0),s(void 0),Yq(n,e,r.current).then(async e=>{if(!e.ok){s(e.message);return}await t(e.value.draft.id)?r.current=void 0:s(`The next chapter's draft was made, but Play could not open it because the draft open there is not saved yet. Open Play, let it save, then press Make the next chapter again.`)}).catch(e=>s(`The next chapter could not be made (${e instanceof Error?e.message:`the connection dropped`}). Press Make the next chapter again.`)).finally(()=>a(!1)))}}}var Ybe=[`all`,`running`,`queued`,`waiting`,`ready`,`failed`];function Xbe(e){return Ybe.find(t=>t===e)}var K7=[{value:`all`,label:`All`},{value:`running`,label:`Running`},{value:`queued`,label:`Queued`},{value:`waiting`,label:`Needs you`},{value:`ready`,label:`Ready to upload`},{value:`failed`,label:`Failed`}];function q7(e,t){switch(t){case`all`:return!0;case`running`:return e.status===`running`||e.status===`paused`;case`queued`:return w3(e);case`waiting`:return y3(e);case`ready`:return C3(e);case`failed`:return e.status===`failed`||e.status===`partial`}}function Zbe(e){let t={running:{tone:`running`,word:`Running`},paused:{tone:`waiting`,word:`Paused`},pending:{tone:`off`,word:`Queued`},failed:{tone:`failed`,word:`Failed`},partial:{tone:`info`,word:`Done with problems`},done:{tone:`done`,word:`Done`},canceled:{tone:`off`,word:`Canceled`}};if(y3(e))return{tone:`waiting`,word:`Waiting for you`};let n=e.status===`running`?YH(e.limitWaits):void 0;return n===void 0?t[e.status]:{tone:`waiting`,word:n}}function Qbe(e){let t=e.config.articlePrompt,n=e.config.voices?.book;return[n===void 0?void 0:LA(n),t===void 0||t===``?void 0:t,e.format].filter(e=>e!==void 0).join(` · `)}function $be({initialFilter:e=`all`}={}){let{api:t}=z(),n=_(),r=Oy(),i=gx(),a=N(Yy(t)),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(e),u=N({queryKey:My,queryFn:()=>Iy(t)}),d=new Set(Object.values(u.data?.samples??{}).filter(e=>e!==null)),[f,p]=(0,m.useState)(``),g=(0,m.useRef)(null),v=xx(g,`projects`),y=P({mutationFn:e=>No(t,e),onSettled:async()=>{s(void 0),await n.invalidateQueries({queryKey:B.projects})}}),b=P({mutationFn:e=>S3(t,e.project.id,e.uploaded),onError:(e,t)=>r(`${t.project.title} wasn't changed: ${e.message} Press the button again.`,`error`),onSettled:async()=>{await n.invalidateQueries({queryKey:B.projects})}});bx({id:`projects.show.waiting`,title:`Show projects that need you`,group:`Projects`,keywords:[`waiting`,`filter`],run:()=>l(`waiting`)}),bx({id:`projects.show.ready`,title:`Show videos ready to upload`,group:`Projects`,keywords:[`upload`,`finished`,`filter`],run:()=>l(`ready`)}),bx({id:`projects.show.failed`,title:`Show failed projects`,group:`Projects`,keywords:[`error`,`filter`],run:()=>l(`failed`)});let x=(a.data?.projects??[]).filter(e=>i.includes(e.channelId)),S=f.trim().toLowerCase(),C=x.filter(e=>q7(e,c)&&(S===``||e.title.toLowerCase().includes(S)));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Projects`,meta:a.data===void 0?void 0:`${String(x.length)} ${x.length===1?`project`:`projects`} · ${i.channel?.name??`every channel`}`,actions:(0,h.jsxs)(fS,{to:`/play`,variant:`primary`,children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75}),`New project`]})}),a.data?.projects.length===0?(0,h.jsx)(jB,{}):null,a.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-4 text-danger`,children:a.error.message}),a.data===void 0?a.error===null?(0,h.jsx)(txe,{}):null:a.data.projects.length===0?(0,h.jsx)(a0,{title:`No projects yet`,actions:(0,h.jsx)(fS,{to:`/play`,variant:`primary`,children:`Make your first video`}),children:`Set up a run on Play: pick a template, type a topic and start.`}):(0,h.jsxs)(e0,{split:`aside`,children:[(0,h.jsxs)(t0,{label:`Project list`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(`div`,{className:`relative w-full max-w-[320px]`,children:[(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{type:`search`,ref:g,"aria-label":`Search projects`,"aria-keyshortcuts":Mx(v),placeholder:`Search projects`,value:f,onChange:e=>p(e.target.value),className:`sl-input pl-9`})]}),(0,h.jsx)(Ab,{label:`Show`,value:c,options:K7,onChange:l,className:`max-w-full overflow-x-auto`})]}),C.length===0?(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:x.length===0?`No projects in ${i.channel?.name??`this channel`} yet. Pick All channels in the rail to see the others.`:`No project matches. Clear the search or pick All.`}):(0,h.jsx)(pU,{label:`Projects`,children:C.map(e=>(0,h.jsx)(exe,{project:e,sample:d.has(e.id),onDelete:()=>s(e),onUploaded:t=>b.mutate({project:e,uploaded:t}),busy:b.isPending},e.id))})]}),(0,h.jsxs)(t0,{as:`aside`,label:`Projects at a glance`,children:[(0,h.jsxs)(`section`,{children:[(0,h.jsx)(H,{title:`At a glance`}),(0,h.jsx)(G2,{children:K7.filter(e=>e.value!==`all`).map(e=>(0,h.jsx)(K2,{label:e.label,value:String(x.filter(t=>q7(t,e.value)).length)},e.value))})]}),(0,h.jsxs)(`section`,{"aria-label":`Video queue`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Video queue`,info:`play.queue`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Videos started together, in the order they run, are on the calendar.`}),(0,h.jsx)(`div`,{children:(0,h.jsx)(pS,{to:`/calendar`,children:`Open calendar`})})]})]})]}),y.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`mt-3 text-small text-danger`,children:y.error.message}),(0,h.jsx)(jy,{open:o!==void 0,title:o===void 0?``:`Delete "${o.title}"?`,consequence:`Moves the project to the trash for 30 days. Restore it or delete it for good in Settings → Trash.`,confirmLabel:`Delete project`,cancelLabel:`Keep it`,pending:y.isPending,onConfirm:()=>{o!==void 0&&y.mutate(o.id)},onCancel:()=>s(void 0)})]})}function exe({project:e,sample:t,onDelete:n,onUploaded:r,busy:i}){let a=Zbe(e),o=e.status===`running`;return(0,h.jsx)(mU,{title:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(ha,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),t?(0,h.jsx)(vS,{children:`Sample`}):null]}),meta:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:`${Qbe(e)} · started ${ku(e.createdAt)}`}),o?(0,h.jsx)(q2,{value:e.progress,label:`${e.title} progress`,valueText:`${String(Math.round(e.progress*100))}% done`,className:`max-w-[240px]`}):null]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(_S,{tone:a.tone,children:[a.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`${e.title}: ${a.word}`})]}),C3(e)?(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!0),children:`Mark uploaded`}):null,C3(e)?(0,h.jsx)(V,{id:`project.mark-uploaded`}):e.uploadedAt===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(vS,{children:`Uploaded`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Mark ${e.title} not uploaded`,disabled:i,disabledReason:`Saving…`,onClick:()=>r(!1),children:`Undo`})]}),(0,h.jsx)(wy,{label:`Delete ${e.title}`,size:`small`,disabled:o,disabledReason:`Cancel the run first, then delete it.`,onClick:n,children:(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function txe(){return(0,h.jsx)(`ul`,{"aria-label":`Loading projects`,className:`sl-list m-0 list-none p-0`,children:[0,1,2,3,4,5].map(e=>(0,h.jsxs)(`li`,{className:`sl-row`,"data-slot":`skeleton-row`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-3 w-2/5 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[10px] w-1/4 rounded-control bg-sunken`})]}),(0,h.jsx)(`span`,{className:`h-[10px] w-16 rounded-control bg-sunken`})]},e))})}var nxe=`Prepare restrained delivery cues for a documentary narrator. Let the facts carry the scene. Use a measured pace and make only occasional changes where the supplied wording clearly calls for emphasis, reflection or tension. Prefer no cue to an unnecessary cue. Avoid theatrical emotion, invented reactions and routine laughter or sighs. Never rewrite, summarize, translate or add spoken words. Return only the cue annotations required by the supplied format contract.`;function J7({promptId:e,kind:t,from:n,onLeave:r}){let{api:i}=z(),a=_(),o=lI(),s=N(nb(i)),c=(0,m.useId)(),l=(0,m.useId)(),u=(0,m.useId)(),[d,f]=oP(JSON.stringify(e===void 0?[`new`,t,n??null]:[`prompt`,e])),[p,g]=(0,m.useState)([]),[v,y]=(0,m.useState)(void 0),b=v!==void 0,[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(!1),T=s.data?.prompts,E=e??n,D=E===void 0?void 0:T?.find(e=>e.id===E),O=D===void 0?{kind:t,name:``,body:``}:e===void 0?{kind:D.kind,name:`${D.name} copy`,body:D.body}:{kind:D.kind,name:D.name,body:D.body},k=d??v??O,A=P({mutationFn:t=>xs(i,t,e),onSuccess:async(e,t)=>{if(!e.ok){g(e.fields);return}y(e.value),f(e=>e===t?void 0:e),o({type:`prompt-saved`,id:e.value.id,kind:e.value.kind}),await a.invalidateQueries({queryKey:nb(i).queryKey})}}),ee=P({mutationFn:e=>Cs(i,e),onSuccess:async()=>{S(!1),f(void 0),await a.invalidateQueries({queryKey:nb(i).queryKey}),r(k.kind)}}),te=P({mutationFn:({id:e,on:t})=>Ss(i,e,t),onSettled:async()=>{await a.invalidateQueries({queryKey:nb(i).queryKey})}});X2(b,()=>{r(k.kind)});let ne=(e,t)=>{f(e),g(e=>e.filter(e=>e.field!==t))},j=t3(k,p),re=n3(j),M=a3(k.body),ie=k.body.trim()===``?[]:r3(j),ae=k.name.trim()===``?[]:i3(j);return cI({promptNamed:k.name.trim()!==``&&ae.length===0,promptBodyReady:k.body.trim()!==``&&ie.length===0,promptHasKeywords:M.length>0&&ie.length===0,promptSaveReady:re===void 0&&!A.isPending&&!b,promptSaving:A.isPending||b,promptIsArticle:k.kind===`article`,promptIsImage:k.kind===`image`}),s.error===null?E!==void 0&&T===void 0?(0,h.jsx)($2,{}):E!==void 0&&D===void 0?(0,h.jsx)(X7,{kind:t,children:`That prompt is gone. It may have been deleted in another tab.`}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsx)(h4,{children:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:k.kind},children:`Prompts`})}),title:e===void 0?`New prompt`:`Edit prompt`,meta:`${_V(k.kind)} prompt`}),(0,h.jsxs)(`div`,{"data-tour":`prompt-editor`,className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${p4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,h.jsx)(`div`,{"data-tour":`prompt-name`,className:`min-w-[min(100%,240px)] flex-1`,children:(0,h.jsx)(xV,{label:`Name`,tip:`library.prompt.name`,...ae.length===0?{}:{error:ae.map(e=>e.message).join(` `)},children:(0,h.jsx)(CV,{value:k.name,onChange:e=>{ne({...k,name:e.target.value},`name`)}})})}),(0,h.jsx)($4,{label:`Kind`,value:k.kind,options:gV,tip:`library.prompt.kind`,onPick:e=>{ne({...k,kind:e},`name`)}})]}),(0,h.jsxs)(`div`,{"data-tour":`prompt-body`,...Ob,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex min-h-8 items-end justify-between gap-3`,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:c,className:`sl-field__label`,children:`Body`}),(0,h.jsx)(V,{id:rxe[k.kind],label:`${_V(k.kind)} prompt body`,className:`-my-1`})]}),Y7(k.kind)?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=Y7(k.kind);e!==void 0&&(k.body.trim()===``?ne({...k,body:e.body},`body`):w(!0))},children:Y7(k.kind)?.label}),(0,h.jsx)(V,{id:`library.prompt.starter`,label:Y7(k.kind)?.label})]}):null]}),(0,h.jsx)(s3,{id:c,value:k.body,invalid:ie.length>0,describedBy:ie.length===0?void 0:l,onChange:e=>{ne({...k,body:e},`body`)}})]}),k.kind===`image`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e!==void 0&&D?.kind===`image`?(0,h.jsx)(kb,{checked:te.isPending?te.variables.on:D.photorealistic===!0,disabled:te.isPending,onChange:t=>te.mutate({id:e,on:t}),label:`Draws photorealistic pictures`,tip:`library.prompt.photorealistic`}):(0,h.jsxs)(`span`,{className:`flex items-center gap-1 text-small text-ink-2`,children:[`Save this Image prompt first, then choose whether it draws photorealistic pictures.`,(0,h.jsx)(V,{id:`library.prompt.photorealistic`})]}),te.error===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small text-danger`,children:`Couldn't change Draws photorealistic pictures: ${te.error.message} Press the switch again.`})]}):null,(0,h.jsx)(`div`,{"data-tour":`prompt-save`,children:(0,h.jsx)(Q2,{onDelete:e===void 0?void 0:()=>{S(!0)},blocked:re,blockedId:u,pending:A.isPending,saved:b,cancel:(0,h.jsx)(fS,{to:`/prompts`,search:{kind:k.kind},onClick:()=>{f(void 0)},variant:`secondary`,children:`Cancel`}),errors:[A.error,ee.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{A.mutate(k)}})})]}),(0,h.jsx)(`div`,{"data-tour":`prompt-slots`,className:m4,children:(0,h.jsx)(Y4,{slots:M,body:k.body,lint:ie,lintId:l})})]}),(0,h.jsx)(jy,{open:C,title:`Replace this prompt body?`,consequence:`The starter replaces the text in this editor. Nothing is saved until you choose Save.`,confirmLabel:`Use starter`,tone:`primary`,onConfirm:()=>{let e=Y7(k.kind);e!==void 0&&ne({...k,body:e.body},`body`),w(!1)},onCancel:()=>w(!1)}),(0,h.jsx)(jy,{open:x,title:`Delete "${k.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:ee.isPending,onConfirm:()=>{e!==void 0&&ee.mutate(e)},onCancel:()=>{S(!1)}})]}):(0,h.jsx)(X7,{kind:k.kind,children:s.error.message})}var rxe={article:`library.prompt.body.article`,image:`library.prompt.body.image`,thumbnail:`library.prompt.body.thumbnail`,narration:`library.prompt.body.narration`,description:`library.prompt.body.description`,shorts:`library.prompt.body.shorts`,review:`library.prompt.body.review`,script:`library.prompt.body.script`};function Y7(e){if(e===`narration`)return{label:`Use Documentary Starter`,body:nxe};if(e===`description`)return{label:`Use Built-in Starter`,body:She};if(e===`shorts`)return{label:`Use Built-in Starter`,body:Gk}}function X7({kind:e,children:t}){return(0,h.jsx)(g4,{back:(0,h.jsx)(ha,{to:`/prompts`,search:{kind:e},children:`Back to Prompts`}),children:t})}function ixe({kind:e,onKind:t,onUseInPlay:n,playBlocked:r}){let{api:i}=z(),a=_(),o=N(nb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=xx(l,`prompts`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=P({mutationFn:e=>Cs(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:B.prompts})}}),x=async(e,t)=>{let n=await xs(i,{kind:e.kind,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:B.prompts}),n.ok?null:q4(n.fields)},S=o.data?.prompts.filter(t=>t.kind===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(B4,{action:(0,h.jsx)(oxe,{kind:e}),children:[(0,h.jsx)(CV,{type:`search`,ref:l,"aria-label":`Search prompts`,"aria-keyshortcuts":Mx(u),placeholder:`Search prompts`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsx)(TV,{"aria-label":`Prompt kind`,value:e,className:`w-full sm:w-56`,options:gV,onChange:e=>{let n=gV.find(t=>t.value===e.target.value);n!==void 0&&t(n.value)}}),(0,h.jsx)(V,{id:`library.prompt.kind`})]})]}),o.error===null?null:(0,h.jsx)(R4,{what:`prompts`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(L4,{label:`Prompts`}):null:S.length===0?(0,h.jsxs)(a0,{title:`No ${_V(e).toLowerCase()} prompts yet`,children:[`A prompt is text with `,`{{keywords}}`,`; each keyword becomes a field on Play.`]}):(0,h.jsx)(jq,{className:F4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${_V(e).toLowerCase()} prompts match "${s.trim()}".`}):(0,h.jsx)(pU,{label:`Prompts`,children:w.map(e=>(0,h.jsx)(mU,{className:I4,title:(0,h.jsx)(J4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:axe(e),selected:e.id===T?.id,actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e.kind,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(M4,{item:`prompt`,id:T.id,name:T.name,kicker:`${_V(T.kind)} prompt`,meta:`Updated ${P4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(fS,{to:`/prompts/$promptId`,params:{promptId:T.id},size:`small`,children:`Edit prompt`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(SI,{tone:`danger`,title:`The prompt wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(O4,{item:`prompt`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(jy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete prompt`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function axe(e){return`${_V(e.kind)} · ${N4(e.slots.length,`keyword`)} · updated ${P4(e.updatedAt)}`}function oxe({kind:e}){return(0,h.jsx)(fS,{to:`/prompts/new`,search:{kind:e},variant:`primary`,children:`New prompt`})}var sxe={template:`Template`,schedule:`Schedule`,draft:`Draft`,project:`Project`};function Z7(e){let t=[e.added.length>0?`${e.added.length} new`:null,e.priced.length>0?`${e.priced.length} repriced`:null,e.retired.length>0?`${e.retired.length} retired`:null].filter(e=>e!==null);return t.length===0?`No changes`:t.join(`, `)}function cxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:H1.catalogue,queryFn:()=>cde(e),refetchInterval:3e4}),i=N({queryKey:H1.retired,queryFn:()=>G1(e)}),a=async()=>{await Promise.all([t.invalidateQueries({queryKey:[`provider-models`]}),t.invalidateQueries({queryKey:H1.retired})])},o=P({mutationFn:()=>lde(e),onSuccess:async e=>{t.setQueryData(H1.catalogue,e),n(e.sync?.warning??`Model list checked: ${Z7(e.sync?.changes??lxe)}.`,e.sync?.warning?`error`:`success`),await a()}}),s=P({mutationFn:()=>ude(e),onSuccess:async e=>{n(`Catalogue replaced with the published file.`,`success`),t.setQueryData(H1.catalogue,e),await a()}}),c=async()=>{await Promise.all([t.invalidateQueries({queryKey:H1.retired}),t.invalidateQueries({queryKey:Lq}),t.invalidateQueries({queryKey:TH}),t.invalidateQueries({queryKey:[`play-drafts`]}),t.invalidateQueries({queryKey:[`projects`]}),t.invalidateQueries({queryKey:[`project`]})])},l=P({mutationFn:t=>K1(e,t),onSuccess:c}),u=P({mutationFn:()=>dde(e),onSuccess:async e=>{n(e.failed.length===0?`Switched ${e.switched} ${e.switched===1?`use`:`uses`}.`:`Switched ${e.switched}; ${e.failed.length} could not be switched: ${e.failed[0]?.message??``}`,e.failed.length===0?`success`:`error`),await c()}}),d=r.data?.sync,f=i.data??[],p=f.filter(e=>e.blocked===null&&e.replacement!==null),m=o.error?.message??s.error?.message??r.error?.message??r.data?.warning??d?.warning??null;return bx({id:`settings.check-models`,title:`Check for new models`,group:`Settings`,context:`Models`,keywords:[`catalogue`,`prices`,`retired`],run:()=>{!o.isPending&&r.data?.path&&o.mutate()}}),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Model catalogue`,info:`settings.models.catalogue`,children:[(0,h.jsx)(R,{disabled:o.isPending||!r.data?.path,onClick:()=>o.mutate(),children:o.isPending?`Checking…`:`Check now`}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:s.isPending||!r.data?.path,onClick:()=>s.mutate(),children:s.isPending?`Replacing…`:`Replace with published file`}),(0,h.jsx)(V,{id:`settings.models.replace`})]})]}),(0,h.jsxs)(`dl`,{className:`m-0 grid gap-x-6 border-t border-line text-small sm:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Catalogue file`}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 border-b border-line pb-3 break-all font-mono text-ink-2 sm:pt-3`,children:r.data?.path??`Not available`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Verified`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:r.data?.updatedAt??`date unavailable`}),(0,h.jsx)(`dt`,{className:`pt-3 font-semibold text-ink sm:border-b sm:border-line sm:pb-3`,children:`Last checked`}),(0,h.jsx)(`dd`,{className:`m-0 border-b border-line pb-3 text-ink-2 sm:pt-3`,children:d?.checkedAt?`${new Date(d.checkedAt).toLocaleString()} · ${Z7(d.changes)}`:`Not checked yet`})]}),d!==void 0&&d.changes.retired.length+d.changes.added.length>0?(0,h.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1 text-small text-ink-2`,children:[d.changes.added.length>0?(0,h.jsxs)(`span`,{children:[`New: `,d.changes.added.map(e=>e.name).join(`, `)]}):null,d.changes.retired.length>0?(0,h.jsxs)(`span`,{children:[`Retired: `,d.changes.retired.map(e=>e.name).join(`, `)]}):null]}):null,m===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-3 text-body text-danger`,children:m})]}),(0,h.jsxs)(`section`,{"aria-label":`Retired models in use`,children:[(0,h.jsx)(H,{title:`Retired models in use`,info:`settings.models.retired`,children:(0,h.jsx)(R,{variant:`primary`,disabled:u.isPending||p.length===0,onClick:()=>u.mutate(),children:u.isPending?`Switching…`:`Switch all`})}),i.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:i.error.message}):null,l.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:l.error.message}):null,f.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i.isPending?`Looking…`:`Nothing uses a retired model.`}):(0,h.jsx)(`ul`,{"aria-label":`Retired models in use`,className:`sl-list m-0 list-none p-0`,children:f.map(e=>(0,h.jsxs)(`li`,{className:`sl-row max-sm:grid-cols-1`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[(0,h.jsx)(`span`,{className:`sl-kicker`,children:sxe[e.kind]}),` `,(0,h.jsx)(`span`,{className:`font-semibold`,children:e.name})]}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[s0[e.slot],`: `,e.model,` (`,e.why===`retired`?`retired`:`no longer listed`,`)`]}),e.blocked===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:e.blocked})]}),(0,h.jsx)(Ey,{children:(0,h.jsx)(R,{size:`small`,disabled:e.blocked!==null||e.replacement===null||l.isPending,onClick:()=>l.mutate(e),children:e.replacement===null?`No replacement`:`Switch to ${e.replacement.name}`})})]},e.key))})]})]})}var lxe={added:[],retired:[],priced:[]},uxe={ok:`Ready`,warning:`Check`,problem:`Needs fixing`,unused:`Not set up`},dxe={ok:`done`,warning:`waiting`,problem:`failed`,unused:`off`},fxe={ok:`text-ink-2`,warning:`text-waiting`,problem:`text-danger`,skipped:`text-ink-3`};function Q7(){let{api:e}=z();return P({mutationFn:()=>W1(e)})}function pxe(e){let{api:t}=z(),[n,r]=(0,m.useState)({byId:new Map});return{one:P({mutationFn:e=>W1(t,e),onSuccess:t=>{r(n=>{let r=new Map(n.after===e?n.byId:[]);for(let e of t.providers)r.set(e.id,e);return{after:e,byId:r}})}}),latest:t=>n.after===e?n.byId.get(t.id)??t:t}}function mxe({run:e}={}){let t=Q7(),n=e??t,r=n.data,i=pxe(r?.checkedAt),a=r?.providers.filter(e=>e.state!==`unused`).map(i.latest)??[],o=r?.providers.filter(e=>e.state===`unused`)??[];return(0,h.jsxs)(`section`,{"aria-label":`Health check`,children:[(0,h.jsx)(H,{title:`Health check`,info:`settings.health`,children:e===void 0?(0,h.jsx)(R,{disabled:n.isPending,onClick:()=>{n.mutate()},children:n.isPending?`Checking…`:`Check all`}):void 0}),n.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:[`The health check didn't finish: `,n.error.message,` Press Check all to try again.`]}),i.one.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mb-2 text-body text-danger`,children:`The check didn't finish: ${i.one.error.message} Press Check again on the provider to try again.`}),r===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:n.isPending?`Checking every provider…`:`Not checked yet.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ul`,{"aria-label":`Health by provider`,className:`sl-list m-0 list-none p-0`,children:a.map(e=>(0,h.jsxs)(`li`,{className:`sl-row grid-cols-1 gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2`,children:[(0,h.jsx)(`span`,{className:`sl-row__title`,children:e.displayName}),(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(_S,{tone:dxe[e.state],children:uxe[e.state]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Check ${e.displayName} again`,disabled:i.one.isPending,onClick:()=>{i.one.mutate(e.id)},children:i.one.isPending&&i.one.variables===e.id?`Checking…`:`Check again`})]})]}),(0,h.jsx)(`ul`,{className:`m-0 list-none space-y-1 p-0`,children:e.checks.map(e=>(0,h.jsxs)(`li`,{className:L(`text-small`,fxe[e.state]),children:[(0,h.jsxs)(`span`,{className:`font-semibold`,children:[e.label,`:`]}),` `,e.detail]},e.label))})]},e.id))}),(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-2`,children:o.length===0?`Checked at ${new Date(r.checkedAt).toLocaleTimeString()}.`:`Not set up and not used anywhere: ${o.map(e=>e.displayName).join(`, `)}.`})]})]})}var $7={openrouter:`settings.provider.openrouter`,"claude-code":`settings.provider.claude-code`,codex:`settings.provider.codex`,gemini:`settings.provider.gemini`,elevenlabs:`settings.provider.elevenlabs`,"openai-tts":`settings.provider.openai-tts`,cartesia:`settings.provider.cartesia`,inworld:`settings.provider.inworld`,"system-voice":`settings.provider.system-voice`,"google-tts":`settings.provider.google-tts`,fal:`settings.provider.fal`,replicate:`settings.provider.replicate`,"openai-image":`settings.provider.openai-image`,"google-image":`settings.provider.google-image`,"codex-image":`settings.provider.codex-image`};function e9(e){return tF(e)?{tone:`done`,word:`Ready`}:e.installed?{tone:`waiting`,word:`Needs attention`}:{tone:`off`,word:`Not found`}}function hxe({provider:e,readiness:t,kind:n}){let{api:r}=z(),i=_(),a=(0,m.useId)(),[o,s]=(0,m.useState)(void 0),[c,l]=(0,m.useState)(!1),u=e.cliPath?.configured??null,d=e.cliPath?.managedOnHost===!0,f=e.id===`claude-code`?`claude`:e.id===`codex-image`?`codex`:e.id,p=e.cliPath?.command??f,g=o??u??``,v=tF(t),y=P({mutationFn:t=>Yo(r,e.id,t),onMutate:()=>l(!1),onSuccess:async e=>{i.setQueryData(B.providers,t=>t?{...t,providers:t.providers.map(t=>t.id===e.id?e:t)}:void 0),s(void 0),l(!0),await i.invalidateQueries({queryKey:B.providers})}});(0,m.useEffect)(()=>{if(!c)return;let e=setTimeout(()=>l(!1),Y2);return()=>clearTimeout(e)},[c]);let[b,x]=(0,m.useState)(!1),S=(0,m.useId)();return(0,h.jsxs)(`section`,{"aria-labelledby":a,"data-ready":v,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:a,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:$7[e.id],label:e.displayName})]}),(0,h.jsxs)(`p`,{className:`sl-section-head__meta`,children:[n,` · command line, no key needed`]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:e9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:gxe(t,u)})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Command`}),(0,h.jsx)(EV,{className:`min-w-0 truncate`,title:p,children:p})]})]}),(0,h.jsxs)(Ey,{children:[d?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-small text-ink-2`,children:[`Managed on host`,(0,h.jsx)(V,{id:`settings.cli.managed-on-host`})]}):(0,h.jsx)(R,{"aria-expanded":b,"aria-controls":S,onClick:()=>x(e=>!e),children:b?`Close path`:`Change path`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:c?(0,h.jsx)(Z2,{}):null})]}),d||!b?null:(0,h.jsx)(`form`,{id:S,onSubmit:e=>{e.preventDefault(),y.isPending||y.mutate(g)},children:(0,h.jsx)(xV,{label:`Executable path`,tip:`settings.cli.path`,help:(0,h.jsxs)(h.Fragment,{children:[`Leave blank to find `,(0,h.jsx)(EV,{children:f}),` on PATH. Use an absolute path without quotes or arguments.`]}),error:y.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{autoComplete:`off`,spellCheck:!1,maxLength:4096,"aria-label":`${e.displayName} Executable path`,className:`min-w-0 flex-1 basis-[220px]`,placeholder:f,value:g,disabled:y.isPending,onChange:e=>{s(e.target.value),l(!1),y.reset()}}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,"aria-label":`Save ${e.displayName} path`,disabled:y.isPending,children:y.isPending?`Checking…`:`Save path`})]})})})]})}function gxe(e,t){return e.issue===void 0?e.installed?e.version===void 0?`Installed`:`Installed, version ${e.version}`:t===null?`Not found on PATH`:`Not found at saved path`:e.issue}var _xe=[`providers`,`system-voice`,`voices`];async function vxe(e){return F(await e.fetch(`${e.origin}/api/providers/system-voice/voices`))}function t9(e=!0){let{api:t}=z();return N({queryKey:_xe,queryFn:()=>vxe(t),enabled:e})}function n9(e){return e.available?{tone:`done`,word:`Ready`}:{tone:`off`,word:`Not found`}}function yxe({provider:e,readiness:t}){let n=(0,m.useId)(),r=t9(t.available).data?.engines??[];return(0,h.jsxs)(`section`,{"aria-labelledby":n,"data-ready":t.available,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`h3`,{id:n,className:`sl-section-head__title`,children:e.displayName}),(0,h.jsx)(V,{id:$7[e.id],label:e.displayName})]}),(0,h.jsx)(`p`,{className:`sl-section-head__meta`,children:`Speech · built into this computer, no key needed`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex min-w-0 items-center gap-2`,"aria-live":`polite`,children:[(0,h.jsx)(gS,{tone:n9(t).tone}),(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:t.available?`Found ${t.engine??`a speech program`}. Narration with it is free; a keyed voice (ElevenLabs, OpenAI) sounds better.`:t.issue??`No speech program was found on this computer.`})]}),r.length===0?null:(0,h.jsx)(`ul`,{className:`m-0 list-none p-0 text-small text-ink-2`,children:r.map(e=>{let t=e.voices.length;return(0,h.jsx)(`li`,{children:`${e.name}: ${t} voice${t===1?``:`s`}`},e.id)})}),t.available?(0,h.jsx)(Ey,{children:(0,h.jsx)(fS,{to:`/settings`,search:{section:`voices`},children:`Add a system voice`})}):null]})}function bxe({value:e,onPick:t}){let n=t9(),r=n.data?.engines??[];return n.data!==void 0&&r.length===0?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:n.data.issue??`No speech program was found on this computer.`}):(0,h.jsxs)(TV,{value:e,onChange:e=>{for(let n of r){let r=n.voices.find(t=>t.id===e.target.value);if(r!==void 0)return t(r)}},children:[(0,h.jsx)(`option`,{value:``,children:n.data===void 0?`Looking for voices…`:`Pick a voice`}),r.map(e=>(0,h.jsx)(`optgroup`,{label:e.name,children:e.voices.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.language===void 0?e.name:`${e.name} (${e.language})`},e.id))},e.id))]})}var r9=[`llm`,`tts`,`image`],i9={llm:`Text`,tts:`Speech`,image:`Images`},xxe=`••••••••••••`;function Sxe(e){return tF(e.readiness)}function Cxe(e){return e.readiness.kind===`cli`?e9(e.readiness):e.readiness.kind===`local`?n9(e.readiness):e.readiness.hasKey?{tone:`done`,word:`Key saved`}:{tone:`off`,word:`No key`}}function wxe(){let{api:e}=z(),t=N(eb(e)),[n,r]=(0,m.useState)(void 0),i=(0,m.useRef)(null),a=(0,m.useRef)(!1);(0,m.useEffect)(()=>{n!==void 0&&a.current&&(a.current=!1,typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 1023px)`).matches&&i.current?.scrollIntoView?.({block:`start`,behavior:`smooth`}))},[n]);let o=r9.flatMap(e=>(t.data?.providers??[]).filter(t=>t.family===e)),s=o.find(e=>!Sxe(e))??o[0];if(n===void 0&&s!==void 0&&r(s.id),t.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message});if(t.data===void 0)return(0,h.jsx)(Exe,{});let c=o.find(e=>e.id===n)??s,l=o.every(e=>e.readiness.kind!==`keyed`||!e.readiness.hasKey),u=e=>{a.current=!0,r(e)};return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:[l?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Paste a key to make its provider selectable on Play.`}):null,r9.map(e=>(0,h.jsxs)(`section`,{"data-tour":`keys-${e}`,"aria-labelledby":`keys-${e}-title`,className:`grid items-start gap-x-8 gap-y-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(H,{id:`keys-${e}-title`,title:i9[e],size:`small`,className:`pb-2`}),(0,h.jsx)(pU,{label:`${i9[e]} providers`,children:o.filter(t=>t.family===e).map(e=>{let t=Cxe(e);return(0,h.jsx)(mU,{title:e.displayName,meta:e.readiness.kind===`cli`?`Command line`:e.readiness.kind===`local`?`Built in, no key`:`API key`,selected:e.id===c?.id,onSelect:()=>u(e.id),actions:(0,h.jsx)(_S,{tone:t.tone,children:t.word})},e.id)})})]}),c===void 0||c.family!==e?null:(0,h.jsx)(`div`,{ref:i,className:`min-w-0 scroll-mt-4`,children:c.readiness.kind===`cli`?(0,h.jsx)(hxe,{provider:c,readiness:c.readiness,kind:i9[c.family]},c.id):c.readiness.kind===`local`?(0,h.jsx)(yxe,{provider:c,readiness:c.readiness},c.id):(0,h.jsx)(Txe,{provider:c,hasKey:c.readiness.hasKey},c.id)})]},e))]})}function Txe({provider:e,hasKey:t}){let{api:n}=z(),r=_(),i=(0,m.useId)(),a=(0,m.useId)(),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(void 0),C=(0,m.useId)(),w=VF[e.id],T=o.trim(),E=async()=>{b(!0),S(void 0);try{S(await sde(n,e.id,T===``?void 0:T))}catch(e){p(e instanceof Error?e.message:String(e))}finally{b(!1)}},D=async()=>{l(!0),p(void 0);try{await Jo(n,e.id,o),s(``),d(!0),S(void 0),await r.invalidateQueries({queryKey:B.providers})}catch(e){p(e instanceof Error?e.message:String(e))}finally{l(!1)}},O=P({mutationFn:()=>Xo(n,e.id),onSuccess:async()=>{v(!1),p(void 0),await r.invalidateQueries({queryKey:B.providers})},onError:e=>{v(!1),p(e.message)}});(0,m.useEffect)(()=>{if(!u)return;let e=setTimeout(()=>{d(!1)},Y2);return()=>{clearTimeout(e)}},[u]);let k=[t?a:void 0,x===void 0?void 0:C].filter(e=>e!==void 0).join(` `);return(0,h.jsxs)(`section`,{"aria-labelledby":i,"data-ready":t,className:`flex min-w-0 flex-col gap-5`,children:[(0,h.jsx)(H,{as:`h3`,size:`default`,id:i,title:t?e.displayName:`Set up ${e.displayName}`,info:$7[e.id],infoLabel:e.displayName,meta:`${i9[e.family]} · ${t?`a key is saved`:`needs an API key`}`,className:`pb-0`}),w===void 0?null:t?(0,h.jsxs)(`details`,{className:`text-small text-ink-2`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer`,children:`Where to get a key`}),(0,h.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:(0,h.jsx)(a9,{guide:w})})]}):(0,h.jsx)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:(0,h.jsx)(a9,{guide:w})}),(0,h.jsx)(xV,{label:`${e.displayName} API key`,tip:`settings.providers.api-key`,help:`Stored on this computer only. Never in backups or exports.`,error:f,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`password`,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 basis-[200px]`,"aria-describedby":k===``?void 0:k,placeholder:t?xxe:`Paste API key`,value:o,onChange:e=>{s(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,"aria-label":`Save ${e.displayName} key`,disabled:o.trim()===``||c,onClick:()=>{D()},children:`Save`})]})}),t?(0,h.jsx)(`span`,{id:a,className:`sr-only`,children:`A key is stored for this provider.`}):null,x===void 0?null:(0,h.jsx)(`p`,{id:C,role:x.ok?`status`:`alert`,className:L(`m-0 text-small`,x.ok?`text-accent-ink`:`text-danger`),children:x.message}),(0,h.jsxs)(Ey,{children:[(0,h.jsx)(R,{"aria-label":`Test ${e.displayName} key`,disabled:!t&&T===``||y,disabledReason:`Paste a key first.`,onClick:()=>{E()},children:y?`Testing…`:`Test`}),(0,h.jsx)(V,{id:`settings.providers.test-key`,label:`Test`}),(0,h.jsx)(R,{variant:`quiet`,"aria-label":`Remove ${e.displayName} key`,disabled:!t,onClick:()=>{v(!0)},children:`Remove`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:u?(0,h.jsx)(Z2,{}):null})]}),(0,h.jsx)(jy,{open:g,title:`Remove the ${e.displayName} key?`,consequence:`Projects that used this provider cannot retry until a key is saved.`,confirmLabel:`Remove key`,pending:O.isPending,onConfirm:()=>{O.mutate()},onCancel:()=>{v(!1)}})]})}function a9({guide:e}){let t=(e,t)=>(0,h.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`underline`,children:t});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`ol`,{className:`m-0 list-decimal space-y-1 pl-5`,children:e.steps.map(e=>(0,h.jsx)(`li`,{children:e},e))}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`Sign up: `,t(e.signUp.url,e.signUp.label),`. Make the key:`,` `,t(e.keyPage.url,e.keyPage.label),`.`,e.billing===void 0?null:(0,h.jsxs)(h.Fragment,{children:[` Credit: `,t(e.billing.url,e.billing.label),`.`]})]}),(0,h.jsx)(`p`,{className:`m-0`,children:e.permissions}),(0,h.jsxs)(`p`,{className:`m-0`,children:[`More in the provider's `,t(e.docs.url,e.docs.label),`. After saving, choose Test.`]})]})}function Exe(){return(0,h.jsxs)(`div`,{className:`grid items-start gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,role:`status`,"aria-label":`Loading providers`,children:[(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:[[`llm`,4],[`tts`,5],[`image`,5]].map(([e,t])=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`span`,{className:`mb-2 block h-3 w-16 rounded-control bg-raised`}),(0,h.jsx)(`div`,{className:`sl-list`,children:Array.from({length:t},(t,n)=>`${e}-${n}`).map(e=>(0,h.jsxs)(`div`,{className:`sl-row`,children:[(0,h.jsx)(`span`,{className:`h-4 w-32 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-4 w-20 rounded-control bg-raised`})]},e))})]},e))}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-6 w-48 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-10 rounded-control bg-raised`})]})]})}function o9(e){return e.split(/[\s,;]+/).map(e=>e.trim().toLowerCase()).filter(e=>e!==``)}function Dxe(e){return e.languages===void 0?`Any (not known)`:e.languages.map(e=>BO(e).code===e?BO(e).name:e).join(`, `)}function Oxe({voice:e}){let{api:t}=z(),n=_(),r=(0,m.useId)(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)((e.languages??[]).join(`, `)),[c,l]=(0,m.useState)(void 0),u=P({mutationFn:()=>hs(t,e.id,o9(o)),onSuccess:async e=>{if(e!==void 0){l(e.message);return}a(!1),l(void 0),await n.invalidateQueries({queryKey:B.voices})}});return i?(0,h.jsxs)(`div`,{className:`grid gap-1`,children:[(0,h.jsx)(CV,{id:r,"aria-label":`Languages of ${e.name}`,value:o,placeholder:`es, de`,"aria-invalid":c!==void 0,onChange:e=>{s(e.target.value),l(void 0)}}),c===void 0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:c}),u.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:u.error.message}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(R,{size:`small`,disabled:u.isPending,onClick:()=>u.mutate(),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{a(!1),l(void 0),s((e.languages??[]).join(`, `))},children:`Cancel`})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`span`,{className:`text-ink-2`,children:Dxe(e)}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit the languages of ${e.name}`,onClick:()=>a(!0),children:`Edit`})]})}function kxe(){let{api:e}=z(),t=_(),n=N(tb(e)),r=N(eb(e)),[i,a]=(0,m.useState)(void 0),o=P({mutationFn:t=>_s(e,t),onSettled:async()=>{a(void 0),await t.invalidateQueries({queryKey:B.voices})}}),s=P({mutationFn:({id:t,on:n})=>gs(e,t,n),onSettled:async()=>{await t.invalidateQueries({queryKey:B.voices})}}),c=(r.data?.providers??[]).filter(e=>e.family===`tts`);if(n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});let l=n.data?.voices;return(0,h.jsxs)(`div`,{"data-tour":`voices`,className:`flex min-w-0 flex-col gap-10`,children:[(0,h.jsxs)(`div`,{className:`min-w-0 overflow-x-auto`,children:[(0,h.jsxs)(`table`,{className:`sl-table min-w-[640px] table-fixed`,...Ob,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Voices`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:`Name`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[18%] pr-4`,children:`Provider`}),(0,h.jsx)(`th`,{scope:`col`,className:`pr-4`,children:`Voice ID`}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[22%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Languages`,(0,h.jsx)(V,{id:`play.voices.languages`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[20%] pr-4`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Real person`,(0,h.jsx)(V,{id:`play.voices.real-person`,className:`-my-1`})]})}),(0,h.jsx)(`th`,{scope:`col`,className:`w-[96px]`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:l===void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,children:(0,h.jsx)(`span`,{className:`block h-4 w-64 rounded-control bg-raised`})})}):l.length===0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:6,className:`text-ink-2`,children:`Add a voice ID from your text-to-speech provider. Audio needs one to narrate.`})}):l.map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`truncate pr-4 font-semibold`,children:e.name}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:jxe(c,e.provider)}),(0,h.jsx)(`td`,{className:`truncate pr-4 text-ink-2`,children:e.voiceId}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(Oxe,{voice:e})}),(0,h.jsx)(`td`,{className:`pr-4`,children:(0,h.jsx)(kb,{checked:s.isPending&&s.variables.id===e.id?s.variables.on:e.imitatesRealPerson===!0,disabled:s.isPending,onChange:t=>s.mutate({id:e.id,on:t}),label:(0,h.jsx)(`span`,{className:`sr-only`,children:`${e.name} imitates a real person`}),className:`text-small`})}),(0,h.jsx)(`td`,{className:`text-right`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name}`,onClick:()=>{a(e)},children:`Remove`})})]},e.id))})]}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:`Couldn't change Real person: ${s.error.message} Press the switch again.`}),o.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:o.error.message})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Add a voice`}),(0,h.jsx)(Axe,{tts:c})]}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Remove ${i.name}?`,consequence:`Projects that used this voice keep the audio they made with it.`,confirmLabel:`Remove voice`,pending:o.isPending,onConfirm:()=>{i!==void 0&&o.mutate(i.id)},onCancel:()=>{a(void 0)}})]})}function Axe({tts:e}){let{api:t}=z(),n=_(),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(void 0),[d,f]=(0,m.useState)(void 0),p=l??e[0]?.id,g=P({mutationFn:e=>ms(t,e),onSuccess:async e=>{if(!e.ok){f(e.refusal);return}i(``),o(``),c(``),f(void 0),await n.invalidateQueries({queryKey:B.voices})}}),v=(e,t)=>{t(),d?.field===e&&f(void 0)},y=e=>d?.field===e?d.message:void 0;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`grid items-start gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(xV,{label:`Voice name`,tip:`play.voices.name`,error:y(`name`),children:(0,h.jsx)(CV,{value:r,onChange:e=>{let t=e.target.value;v(`name`,()=>{i(t)})}})}),(0,h.jsx)(xV,{label:`Provider`,tip:`play.voices.provider`,error:y(`provider`),children:(0,h.jsxs)(TV,{value:p??``,onChange:t=>{let n=e.find(e=>e.id===t.target.value);n!==void 0&&v(`provider`,()=>{u(n.id)})},children:[e.length===0?(0,h.jsx)(`option`,{value:``,children:`No speech provider`}):null,e.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.displayName},e.id))]})}),(0,h.jsx)(xV,{label:`Voice ID`,tip:`play.voices.voice-id`,error:y(`voiceId`),...p===`inworld`?{help:`Use an Inworld voice ID, such as Dennis, or one from your workspace.`}:{},children:p===`system-voice`?(0,h.jsx)(bxe,{value:a,onPick:e=>{v(`voiceId`,()=>{o(e.id)}),r.trim()===``&&i(e.name);let t=/^([a-z]{2,3})(?:[-_]|$)/i.exec(e.language??``)?.[1];s.trim()===``&&t!==void 0&&c(t.toLowerCase())}}):p===`google-tts`?(0,h.jsx)(TV,{value:a,options:[{value:``,label:`Pick a Gemini voice`},...UF.map(e=>({value:e.name,label:`${e.name} (${e.style})`}))],onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t),r.trim()===``&&i(t)})}}):(0,h.jsx)(CV,{className:`tabular-nums`,value:a,onChange:e=>{let t=e.target.value;v(`voiceId`,()=>{o(t)})}})}),(0,h.jsx)(xV,{label:`Languages`,tip:`play.voices.languages`,help:`Codes such as es, de.`,error:y(`languages`),children:(0,h.jsx)(CV,{value:s,placeholder:`es, de`,onChange:e=>{let t=e.target.value;v(`languages`,()=>{c(t)})}})}),(0,h.jsx)(R,{variant:`primary`,className:`md:mt-6`,disabled:p===void 0||d!==void 0||g.isPending,onClick:()=>{if(p!==void 0){let e=o9(s);g.mutate({provider:p,name:r,voiceId:a,...e.length===0?{}:{languages:e}})}},children:`Add voice`})]}),g.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:g.error.message})]})}function jxe(e,t){return e.find(e=>e.id===t)?.displayName??t}var s9=[`settings`,`notifications`],Mxe=`The test notification couldn't be shown: this browser only allows notifications from installed apps. Set a Notification URL below instead.`;function Nxe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Browser and phone`,info:`settings.notifications`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(Pxe,{}),(0,h.jsx)(Fxe,{}),(0,h.jsx)(Ixe,{})]})]})}function Pxe(){let e=(0,m.useSyncExternalStore)(vP,gP,()=>!1),[t,n]=(0,m.useState)(hP),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=Oy(),c=e&&t===`granted`;async function l(e){if(i(void 0),!e){_P(!1);return}o(!0);try{let e=await xP();n(e);let t=bP(e);e===`granted`?(_P(!0),gP()||i(`Browser notifications couldn't be turned on because this browser blocks site storage for Slopify. Allow site data for this address in your browser's settings, then turn Browser notifications on again.`)):i(t??`Browser notifications weren't turned on because the permission prompt was dismissed. Turn Browser notifications on again and choose Allow.`)}finally{o(!1)}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Browser notifications`,tip:`settings.notifications.browser`,checked:c,disabled:a,onChange:e=>void l(e)}),(0,h.jsx)(R,{variant:`quiet`,disabled:!c,disabledReason:`Turn Browser notifications on first.`,onClick:()=>{i(void 0);try{CP({projectId:`test`,text:UP},()=>{}),s(`Test notification sent to this browser.`,`success`)}catch{i(Mxe)}},children:`Send test notification`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Works while any Slopify tab is open.`}),r===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:r})]})}function Fxe(){let e=(0,m.useSyncExternalStore)(AP,OP,()=>!0);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,h.jsx)(kb,{label:`Run sounds`,tip:`settings.notifications.sounds`,checked:e,onChange:kP}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`start`),children:`Play start`}),(0,h.jsx)(R,{variant:`quiet`,onClick:()=>FP(`end`),children:`Play end`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`A chime when a run starts and a different one when it finishes, fails or waits for you. Works while any Slopify tab is open; set your computer's volume for how loud.`})]})}function Ixe(){let{api:e}=z(),t=_(),n=Oy(),r=(0,m.useId)(),i=N({queryKey:s9,queryFn:()=>$o(e)}),[a,o]=(0,m.useState)(void 0),s=a??i.data?.url??``,c=GP(s),l=P({mutationFn:t=>ts(e,t),onSuccess:e=>{t.setQueryData(s9,e),o(void 0),n(e.url===null?`Notification URL removed.`:`Notification URL saved.`,`success`)}}),u=P({mutationFn:t=>ns(e,t),onSuccess:()=>{n(`Test notification sent. Check the app or page behind your Notification URL.`,`success`)}}),d=c??l.error?.message??u.error?.message,f=l.isPending||u.isPending||i.data===void 0;return(0,h.jsxs)(xV,{label:`Notification URL`,tip:`settings.notifications.url`,help:`Works with no tab open, for example an ntfy topic on your phone.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`url`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:`https://ntfy.sh/your-topic`,className:`min-w-0 flex-1 basis-[220px]`,value:s,disabled:i.data===void 0,"aria-invalid":c!==void 0,"aria-describedby":d===void 0?void 0:r,onChange:e=>{l.reset(),u.reset(),o(e.target.value)}}),(0,h.jsx)(R,{variant:`primary`,disabled:f||c!==void 0||a===void 0,onClick:()=>l.mutate(s),children:`Save`}),(0,h.jsx)(R,{variant:`quiet`,disabled:f||c!==void 0||s.trim()===``,onClick:()=>u.mutate(s),children:`Send test notification`})]}),i.error===null?null:(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The saved Notification URL couldn't be read: `,i.error.message]}),d===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:d})]})}var c9={library:`The Library of Alexandria`,audiobook:`The Wind in the Willows (audiobook)`,podcast:`The Antikythera Mechanism (podcast)`};function Lxe(){let{api:e}=z(),t=_(),n=N({queryKey:Ny,queryFn:()=>Vy(e)}),r=P({mutationFn:()=>Uy(e),onSettled:async()=>{await t.invalidateQueries({queryKey:Ny}),await t.invalidateQueries({queryKey:My}),await t.invalidateQueries({queryKey:B.projects})}}),i=r.data?.samples??n.data?.samples;return(0,h.jsxs)(`div`,{className:`mt-8`,children:[(0,h.jsx)(H,{title:`Sample projects`,info:`settings.sample.restore`}),(0,h.jsx)(pU,{label:`Sample projects`,children:Object.keys(c9).map(e=>{let t=i?.[e]??null;return(0,h.jsx)(mU,{title:c9[e],meta:t===null?`Not in your projects`:`In your projects`,actions:t===null?void 0:(0,h.jsx)(pS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:`Open`})},e)})}),(0,h.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(R,{disabled:r.isPending,onClick:()=>r.mutate(),children:r.isPending?`Restoring…`:`Restore samples`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Puts all three back as they shipped.`})]}),(0,h.jsx)(Q1,{tone:r.error?`error`:`success`,children:r.error?.message??(r.isSuccess?`The samples are back in Projects.`:void 0)})]})}var Rxe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function zxe(e){let[t,n,r]=e.split(`-`).map(Number),i=Rxe[(n??0)-1];return i===void 0||r===void 0?e:`${String(r)} ${i} ${String(t)}`}function l9(e,t){let n=[e.range===void 0?e.version:`Versions ${e.range}`,`released ${zxe(e.date)}`].filter(e=>e!==void 0).join(`, `),r=n.charAt(0).toUpperCase()+n.slice(1);return e.version===t?`${r}. The version you are running.`:`${r}.`}function Bxe({note:e,onNote:t}){let{api:n}=z(),r=N(fI(n));if(r.error!==null)return(0,h.jsx)(SI,{tone:`danger`,title:`The patch notes did not load`,actions:(0,h.jsx)(R,{onClick:()=>void r.refetch(),children:`Try again`}),children:`${r.error.message} Press Try again, or reload the page.`});if(r.data===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the patch notes…`});let{notes:i,version:a}=r.data,[o,...s]=i;if(o===void 0)return(0,h.jsx)(`p`,{className:`m-0 text-ink-2`,children:`This version of Slopify has no patch notes.`});let c=e===void 0?void 0:i.find(t=>t.id===e),l=c!==void 0&&c.id!==o.id?c:void 0;return l===void 0?(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e!==void 0&&c===void 0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`There are no patch notes called "${e}" in this version. The latest are below; older ones are under Earlier versions.`}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:`Latest version`,meta:l9(o,a),info:`settings.patch-notes`}),(0,h.jsx)(wB,{id:o.id})]}),s.length===0?null:(0,h.jsxs)(`details`,{className:`max-w-prose border-t border-line py-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer font-semibold`,children:`Earlier versions (${String(s.length)})`}),(0,h.jsx)(pU,{label:`Earlier versions`,className:`mt-2`,children:s.map(e=>(0,h.jsx)(mU,{title:e.title,meta:l9(e,a),onSelect:()=>t(e.id),actions:(0,h.jsx)(R,{"aria-label":`Read ${e.title}`,onClick:()=>t(e.id),children:`Read`})},e.id))})]})]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{children:(0,h.jsxs)(R,{variant:`quiet`,onClick:()=>t(void 0),children:[(0,h.jsx)(nc,{"aria-hidden":`true`,strokeWidth:1.75}),`Back to the latest patch notes`]})}),(0,h.jsx)(H,{title:`Earlier version`,meta:l9(l,a)}),(0,h.jsx)(wB,{id:l.id})]})}var u9=[`trash`];async function Vxe(e){return(await F(await e.client.trash.$get())).items}async function Hxe(e,t,n){return(await F(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function Uxe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await fo(r)}var Wxe={project:`Project`,prompt:`Prompt`,entry:`Intro/outro`,template:`Template`,schedule:`Schedule`};function Gxe(e){return e.kind===`entry`&&e.detail!==null?e.detail===`intro`?`Intro`:`Outro`:e.kind===`prompt`&&e.detail!==null?`Prompt · ${e.detail}`:Wxe[e.kind]}function Kxe(e){return e<=0?`removed for good today`:e===1?`1 day left`:`${String(e)} days left`}var qxe=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}),Jxe={project:[B.projects,[`calendar`]],prompt:[B.prompts],entry:[B.entries],template:[Lq],schedule:[TH,[`calendar`]]};function Yxe(){let{api:e}=z(),t=_(),n=Oy(),r=N({queryKey:u9,queryFn:()=>Vxe(e)}),[i,a]=(0,m.useState)(void 0),o=async e=>{await Promise.all([u9,...Jxe[e.kind]].map(e=>t.invalidateQueries({queryKey:e})))},s=P({mutationFn:t=>Hxe(e,t.kind,t.id),onSuccess:async(e,t)=>{await o(t),n(e.renamedFrom===null?`Restored "${e.name}".`:`Restored as "${e.name}": another item is now called "${e.renamedFrom}".`,`success`),e.kind===`schedule`&&n(`The schedule is paused. Press Resume on Schedules to run it again.`,`info`)},onError:e=>n(e.message,`error`)}),c=P({mutationFn:t=>Uxe(e,t.kind,t.id),onSuccess:async(e,t)=>{a(void 0),await o(t),n(`Deleted "${t.name}" for good.`,`success`)},onError:e=>{a(void 0),n(e.message,`error`)}}),l=r.data??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Trash`,info:`settings.trash`}),r.isPending?(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the trash…`}):r.error?(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:r.error.message}):l.length===0?(0,h.jsx)(a0,{title:`The trash is empty`,children:`Anything you delete stays here for 30 days before it is removed for good.`}):(0,h.jsx)(pU,{label:`Deleted items`,children:l.map(e=>(0,h.jsx)(mU,{title:e.name,meta:`${Gxe(e)} · deleted ${qxe.format(new Date(e.deletedAt))} · ${Kxe(e.daysLeft)}`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(R,{size:`small`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>s.mutate(e),children:`Restore`}),(0,h.jsx)(R,{size:`small`,variant:`destructive`,disabled:s.isPending||c.isPending,disabledReason:`Working on it`,onClick:()=>a(e),children:`Delete now`})]})},`${e.kind}:${e.id}`))}),(0,h.jsx)(jy,{open:i!==void 0,title:i===void 0?``:`Delete "${i.name}" for good?`,consequence:i?.kind===`project`?`The project and every file it produced are removed from disk. This cannot be undone.`:i?.kind===`schedule`?`The schedule leaves the trash and cannot be restored. Its run history stays on Schedules.`:`It is removed for good. This cannot be undone.`,confirmLabel:`Delete for good`,cancelLabel:`Keep it`,pending:c.isPending,onConfirm:()=>{i!==void 0&&c.mutate(i)},onCancel:()=>{c.isPending||a(void 0)}})]})}var Xxe=`https://github.com/GentBajko/slopify`,Zxe=`https://www.patreon.com/cw/GentBajko`,Qxe=`https://buymeacoffee.com/gentbajko`;function $xe(){return[{href:Xxe,label:`GitHub`,detail:`The code, issues and releases.`,glyph:`github`},{href:Zxe,label:`Patreon`,detail:`Monthly support for the project.`,glyph:`patreon`},{href:Qxe,label:`Buy Me a Coffee`,detail:`A one-off thank you.`,glyph:`coffee`},{href:`https://slopify.stream/channel.html`,label:`How I run a channel with it`,detail:`A lore channel run on Slopify, start to finish.`}]}function eSe({onWhatsNew:e}){return(0,h.jsxs)(`div`,{className:`max-w-prose`,children:[(0,h.jsx)(H,{title:`About`}),(0,h.jsx)(`p`,{className:`m-0 mb-3 text-ink-2`,children:`Slopify is free and open source, and runs on your machine with your own keys. If it saves you time, you can support it here.`}),(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1 text-small text-ink-2`,children:[`Updates: the circular-arrows button at the foot of the sidebar (at the top on a phone).`,(0,h.jsx)(V,{id:`settings.updates`})]}),e===void 0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-3 flex items-center gap-1`,children:[(0,h.jsx)(R,{onClick:e,children:`What's new in this version`}),(0,h.jsx)(V,{id:`settings.whats-new`})]}),(0,h.jsx)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:`Made by Gent Bajko. Apache License 2.0: anyone who redistributes Slopify or builds on it keeps this credit.`}),(0,h.jsx)(`ul`,{"aria-label":`Links`,className:`sl-list m-0 list-none p-0`,children:$xe().map(e=>(0,h.jsx)(`li`,{className:`sl-row`,children:(0,h.jsxs)(`div`,{className:`sl-row__lead`,children:[e.glyph===void 0?(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}):(0,h.jsx)(lS,{name:e.glyph,className:`shrink-0 text-ink-2`}),(0,h.jsxs)(`div`,{className:`sl-row__text`,children:[(0,h.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,className:`font-semibold text-ink underline underline-offset-3`,children:e.label}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:e.detail})]})]})},e.label))})]})}var d9=[`backups`],f9=1,p9=30;function m9(){return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}function tSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=f9&&Number(t)<=p9?void 0:`Keep between ${f9} and ${p9} backups.`}function nSe(e){return{enabled:e.config.enabled,time:e.config.time,keep:String(e.config.keep),folder:e.config.folder??``}}function h9(){let{api:e}=z(),t=_(),n=Oy();return P({mutationFn:()=>ko(e),onSuccess:e=>{t.setQueryData(d9,e),n(`Backup started. Its result shows here when it finishes.`,`success`)}})}function rSe(){let{api:e}=z(),t=_(),n=N({queryKey:d9,queryFn:()=>Do(e),refetchInterval:e=>e.state.data?.running===!0&&2e3}),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Oo(e,t),onSuccess:e=>{t.setQueryData(d9,e),i(void 0),o(!0)}}),c=h9();(0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Y2);return()=>clearTimeout(e)},[a]);let l=n.data,u=r??(l===void 0?void 0:nSe(l)),d=u===void 0?void 0:tSe(u.keep),f=e=>{u!==void 0&&i({...u,...e})};return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Daily backup`,info:`settings.backups`,children:(0,h.jsx)(R,{variant:`primary`,disabled:l===void 0||l.running||c.isPending,onClick:()=>c.mutate(),children:`Back up now`})}),(0,h.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-x-4 gap-y-1 text-small text-ink-2`,children:[(0,h.jsx)(`span`,{role:`status`,children:l===void 0?(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`}):iSe(l)}),(0,h.jsx)(`span`,{children:l===void 0?null:aSe(l)})]}),l?.status.detail?l.status.lastResult===`failed`?(0,h.jsx)(SI,{tone:`danger`,title:`Why the last backup stopped`,children:l.status.detail}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:l.status.detail}):null,c.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:c.error.message}):null]}),n.error?(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The backup settings couldn't be read: `,n.error.message]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(kb,{label:`Back up automatically`,tip:`settings.backups.auto`,checked:u?.enabled===!0,disabled:u===void 0,className:`self-start`,onChange:e=>f({enabled:e})}),(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Time of day`,tip:`settings.backups.time`,help:`${m9()} time`,children:(0,h.jsx)(CV,{type:`time`,className:`w-[140px] tabular-nums`,value:u?.time??`03:00`,disabled:u===void 0,onChange:e=>f({time:e.target.value})})}),(0,h.jsx)(xV,{label:`Keep last`,tip:`settings.backups.keep`,help:`Backups kept in the folder.`,error:d,children:(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:f9,max:p9,step:1,className:`w-[88px] tabular-nums`,value:u?.keep??`5`,disabled:u===void 0,onChange:e=>f({keep:e.target.value})})}),(0,h.jsx)(xV,{label:`Folder`,tip:`settings.backups.folder`,className:`md:col-span-2`,...l===void 0?{}:{help:oSe(l)},children:(0,h.jsx)(CV,{value:u?.folder??``,placeholder:l?.defaultFolder??``,disabled:u===void 0,onChange:e=>f({folder:e.target.value})})})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(R,{variant:`primary`,disabled:u===void 0||d!==void 0||s.isPending,onClick:()=>{u!==void 0&&(o(!1),s.mutate({enabled:u.enabled,time:u.time,timeZone:m9(),keep:Number(u.keep.trim()),folder:u.folder.trim()===``?null:u.folder.trim()}))},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null}),s.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 basis-full text-small text-danger`,children:s.error.message})]})]})]})}function g9(e){return new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function iSe(e){if(e.running)return`Backing up now…`;let{status:t}=e,n=t.lastSuccessAt===null?`No backup yet.`:`Last backup ${g9(t.lastSuccessAt)}${t.lastSuccessBytes===null?``:`, ${_9(t.lastSuccessBytes)}`}.`;return t.lastResult===`failed`&&t.lastAttemptAt!==null?`${n} The backup at ${g9(t.lastAttemptAt)} failed.`:t.lastResult===`waiting`?`${n} Waiting for projects to finish.`:n}function aSe(e){return e.config.enabled?e.overdue?`Next: shortly.`:e.nextRunAt===null?``:`Next: ${g9(e.nextRunAt)}.`:`Automatic backups are off.`}function oSe(e){let t=`${e.files.length} backup${e.files.length===1?``:`s`} here (${_9(e.files.reduce((e,t)=>e+t.bytes,0))}).`;return e.hostFolder===null?`Inside Slopify's Docker volume, not on your computer. Leave Folder empty to save backups in the Backups folder on your computer. ${t}`:`${e.config.folder===null?`Empty uses the default: `:`On your computer: `}${e.hostFolder}. ${t}`}function _9(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var v9=[`storage-files`];function sSe({usageQueryKey:e}){let{api:t}=z(),n=_(),r=Oy(),[i,a]=(0,m.useState)(!1),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(),u=N({queryKey:v9,queryFn:()=>Io(t),refetchInterval:e=>b9(e.state.data)?1e3:!1}),d=P({mutationFn:e=>Lo(t,e),onMutate:()=>l(void 0),onSuccess:e=>{n.setQueryData(v9,e),a(!1)},onError:e=>l(e.message)}),f=P({mutationFn:()=>Ro(t),onSuccess:e=>{e.opened||r(`Your files are in ${e.path}.`,`info`)},onError:e=>r(e.message,`error`)}),p=u.data,g=b9(p),v=p?.move?.phase;if((0,m.useEffect)(()=>{v===`done`&&n.invalidateQueries({queryKey:e})},[v,n,e]),p===void 0)return(0,h.jsx)(`div`,{children:(0,h.jsx)(H,{title:`Your files`,meta:u.error?`Where your files are is unavailable. Reload the page to try again.`:`Loading…`})});if(p.docker)return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Your files`,meta:p.folder??`The Docker project folder isn't set up.`,info:`settings.files.docker`,children:(0,h.jsx)(R,{disabled:p.folder===null||f.isPending,onClick:()=>f.mutate(),children:`Open folder`})}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),p.dockerCommand===null?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{className:`m-0`,children:[`To move your projects to Documents/Slopify, run this on the computer running Docker (or use `,(0,h.jsx)(EV,{children:`--projects-dir <folder>`}),` for another folder):`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(EV,{className:`min-w-0 break-all`,children:p.dockerCommand}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>{let e=p.dockerCommand??``;navigator.clipboard.writeText(e).then(()=>r(`Command copied.`,`success`)).catch(()=>r(`Copying failed: this browser doesn't allow it here. Select the command and copy it yourself.`,`error`))},children:`Copy command`})]})]})]})]});let y=v===`failed`||v===`interrupted`;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Your files`,meta:p.folder,info:`settings.files`,children:[p.inDocuments||p.documentsRoot===null?null:(0,h.jsx)(R,{variant:`primary`,disabled:g||d.isPending,onClick:()=>d.mutate(`documents`),children:`Move to Documents/Slopify`}),(0,h.jsx)(R,{disabled:f.isPending,onClick:()=>f.mutate(),children:`Open folder`}),(0,h.jsx)(R,{variant:`quiet`,disabled:g||d.isPending,onClick:()=>{a(e=>!e),l(void 0)},children:`Choose another folder`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3 text-small text-ink-2`,children:[(0,h.jsx)(y9,{view:p}),i?(0,h.jsxs)(`form`,{className:`flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),d.mutate(o)},children:[(0,h.jsx)(xV,{label:`New folder`,tip:`settings.files.new-folder`,help:`The full path; it must be empty or new.`,error:c,className:`min-w-0 flex-1 basis-80`,children:(0,h.jsx)(CV,{value:o,placeholder:p.documentsRoot??`/home/you/Videos/Slopify`,onChange:e=>s(e.target.value)})}),(0,h.jsx)(R,{type:`submit`,disabled:o.trim()===``||d.isPending,children:`Move here`})]}):c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:c}),p.move===null?null:g?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[p.move.phase===`copying`?`Copying`:`Checking the copy of`,` your files to`,` `,p.move.target,`: `,p.move.files,` of `,p.move.totalFiles,` files (`,Y5(p.move.bytes),` of `,Y5(p.move.totalBytes),`). Keep Slopify running until it finishes.`]}),(0,h.jsx)(q2,{label:p.move.phase===`copying`?`Files copied`:`Files checked`,value:p.move.totalBytes===0?0:p.move.bytes/p.move.totalBytes})]}):y?(0,h.jsx)(SI,{tone:v===`failed`?`danger`:`waiting`,title:v===`failed`?`Moving your files to ${p.move.target} stopped`:`Moving your files to ${p.move.target} didn't finish`,actions:(0,h.jsx)(R,{disabled:d.isPending,onClick:()=>d.mutate(p.move?.target??``),children:`Continue moving`}),children:p.move.error??`Slopify was stopped before the copy was checked, so it still uses the old folder. Continue moving picks up where it left off.`}):v===`done`&&p.move.oldFolder!==null?(0,h.jsxs)(SI,{tone:`info`,title:`Your files are now in ${p.move.target}`,children:[`Every file was copied and checked. The old folder `,p.move.oldFolder,` still has a copy; once your projects open fine, you can delete it to free the space.`]}):null]})]})}function y9({view:e}){let t=[[`Projects`,e.projects],[`Automatic backups`,e.backups],[`Exports`,e.exports]].filter(e=>e[1]!==null);return(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1`,children:t.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-3`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-all`,children:t})]},e))})}function b9(e){return e?.move?.phase===`copying`||e?.move?.phase===`verifying`}function cSe(){let{api:e}=z(),t=N($y(e));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[t.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:t.error.message}),t.data===void 0?t.error===null?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(hSe,{cells:5}),(0,h.jsx)(gSe,{})]}):null:(0,h.jsx)(uSe,{usage:t.data})]})}var lSe=[{id:`stage`,header:`Stage`,cell:e=>nF[e.stage]},{id:`model`,header:`Provider · model`,cell:e=>dSe(e)},{id:`in`,header:`Tokens in`,numeric:!0,cell:e=>x9.format(e.tokensIn)},{id:`out`,header:`Tokens out`,numeric:!0,cell:e=>x9.format(e.tokensOut)}];function uSe({usage:e}){let t=Object.values(e.counters).every(e=>e===0);return(0,h.jsxs)(e0,{split:`even`,children:[(0,h.jsxs)(t0,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(G2,{children:mSe(e).map(e=>(0,h.jsx)(K2,{label:e.label,value:e.value},e.label))}),t?(0,h.jsx)(`p`,{className:`m-0 mt-3 text-body text-ink-2`,children:`Numbers appear after your first run.`}):null]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Machine ID ${e.machineId??`not made yet`} · Slopify ${e.appVersion}`})]}),(0,h.jsx)(t0,{children:(0,h.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:(0,h.jsx)(J2,{caption:`Tokens by stage`,columns:lSe,rows:e.byStage,rowKey:e=>`${e.stage}/${e.provider}/${e.model??``}`,empty:`No stages have run yet.`,className:`min-w-[480px] [&_td]:pr-4 [&_th]:pr-4`})})})]})}function dSe(e){return e.model===null?e.provider:`${e.provider} · ${e.model}`}var x9=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),fSe=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),pSe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function mSe(e){let t=e.counters;return[{label:`Videos made`,value:x9.format(t.videosMade)},{label:`Hours of audio`,value:fSe.format(t.audioSeconds/3600)},{label:`Images made`,value:x9.format(t.imagesMade)},{label:`Tokens used`,value:t.tokensUsed<1e6?x9.format(t.tokensUsed):pSe.format(t.tokensUsed)},{label:`Projects`,value:x9.format(t.projects)}]}function hSe({cells:e}){return(0,h.jsx)(`div`,{className:`sl-stats`,children:Array.from({length:e},(e,t)=>t).map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`h-8 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`})]},e))})}function gSe(){return(0,h.jsx)(`div`,{className:`border-t border-line`,children:[0,1,2,3].map(e=>(0,h.jsxs)(`div`,{className:`flex items-center gap-4 border-b border-line py-3`,children:[(0,h.jsx)(`span`,{className:`h-3 w-24 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 max-w-[40%] rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`ml-auto h-3 w-20 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-20 rounded-control bg-sunken`})]},e))})}var S9=[`storage-usage`],_Se=[S9,B.projects,[`project`],B.usage,B.documentThemes,TH,[`play-drafts`],B.settings,B.providers,B.voices,B.prompts,B.entries,B.staging,Lq,sN,[`provider-models`]];async function vSe(e){await Promise.all(_Se.map(t=>e.invalidateQueries({queryKey:t})))}var C9=30,ySe=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function bSe(e){let t=e.trim();return/^\d+$/.test(t)&&Number(t)>=0&&Number(t)<=C9?void 0:`The silence gap is a whole number of seconds between 0 and ${String(C9)}.`}var w9=[{id:`general`,label:`General`,meta:`How Slopify starts on this computer.`},{id:`providers`,label:`Providers`,meta:`Keys stay on this machine and go only to their provider. Readiness is checked again before each run.`},{id:`voices`,label:`Voices`,meta:`A wrong voice ID shows up when the audio stage uses it.`},{id:`models`,label:`Models`,meta:`New models, prices and retirements, checked once a day.`},{id:`playback`,label:`Playback & appearance`,meta:`How narration is paced and how Slopify looks.`},{id:`notifications`,label:`Notifications`,meta:`When a run finishes, fails, waits for you, or a review needs a decision.`},{id:`channel-links`,label:`Channel links`,meta:`The links a YouTube description's {{Name}} placeholders fill from.`},{id:`studio`,label:`YouTube Studio`,meta:`The playlist upload packs name, and the Studio extension's pairing.`},{id:`storage`,label:`Backup & storage`,meta:`Export everything, import a backup, and see what uses disk space.`},{id:`backups`,label:`Backups`,meta:`A daily copy of everything, in a folder you choose.`},{id:`trash`,label:`Trash`,meta:`Deleted projects, prompts, templates and schedules, kept for 30 days.`},{id:`usage`,label:`Usage`,meta:`This machine only. The same counters, anonymised, feed slopify.stream.`},{id:`patch-notes`,label:`Patch notes`,meta:`What changed in each version of Slopify.`},{id:`about`,label:`About`,meta:`Free and open source, running on your machine with your own keys.`}];function xSe(e){return w9.find(t=>t.id===e)?.id??`providers`}function SSe(e){let t=document.createElement(`a`);t.href=`${e}/api/diagnostics`,t.download=`slopify-diagnostics.json`,document.body.append(t),t.click(),t.remove()}function CSe({section:e=`providers`,note:t,onSection:n=()=>{},onNote:r=()=>{}}){let{api:i}=z(),a=_(),o=Oy(),s=Q7(),c=h9(),l=w9.find(t=>t.id===e)??w9[0];return bx({id:`settings.check-providers`,title:`Check all providers`,group:`Settings`,keywords:[`health`,`keys`,`signed in`],run:()=>{n(`providers`),s.mutate()}}),bx({id:`settings.back-up-now`,title:`Back up now`,group:`Settings`,keywords:[`backup`],run:()=>{n(`backups`),c.mutate(void 0,{onError:e=>{o(`The backup didn't start: ${e.message} Open Settings → Backups to see its state.`,`error`)}})}}),bx({id:`settings.download-diagnostics`,title:`Download diagnostics`,group:`Settings`,keywords:[`support`,`bug report`],run:()=>{SSe(i.origin)}}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:`Settings`,title:l.label,meta:l.meta,actions:(0,h.jsxs)(h.Fragment,{children:[e===`providers`?(0,h.jsx)(R,{disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check all`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsxs)(mS,{variant:`secondary`,href:`${i.origin}/api/diagnostics`,download:`slopify-diagnostics.json`,children:[(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75}),`Download diagnostics`]}),(0,h.jsx)(V,{id:`settings.diagnostics`})]})]})}),(0,h.jsx)(Aq,{sections:(0,h.jsx)(e8,{label:`Settings sections`,children:w9.map(t=>(0,h.jsx)(t8,{current:t.id===e,onClick:()=>n(t.id),className:`whitespace-nowrap max-md:w-auto`,children:t.label},t.id))}),children:(0,h.jsxs)(`section`,{"aria-label":l.label,className:`flex min-w-0 flex-col gap-10`,children:[e===`providers`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B3,{}),(0,h.jsx)(wxe,{}),(0,h.jsx)(mxe,{run:s})]}):null,e===`general`?(0,h.jsx)(zb,{}):null,e===`voices`?(0,h.jsx)(kxe,{}):null,e===`models`?(0,h.jsx)(cxe,{}):null,e===`playback`?(0,h.jsx)(DSe,{}):null,e===`notifications`?(0,h.jsx)(Nxe,{}):null,e===`channel-links`?(0,h.jsx)(Kfe,{}):null,e===`studio`?(0,h.jsx)(Afe,{}):null,e===`storage`?(0,h.jsx)(sSe,{usageQueryKey:S9}):null,e===`storage`?(0,h.jsx)(wSe,{}):null,e===`storage`?(0,h.jsx)(Lxe,{}):null,e===`backups`?(0,h.jsx)(rSe,{}):null,e===`trash`?(0,h.jsx)(Yxe,{}):null,e===`usage`?(0,h.jsx)(cSe,{}):null,e===`patch-notes`?(0,h.jsx)(Bxe,{note:t,onNote:r}):null,e===`about`?(0,h.jsx)(eSe,{onWhatsNew:()=>{a.fetchQuery(fI(i)).then(e=>r(e.current??void 0),e=>{o(`The patch notes did not open: ${e instanceof Error?e.message:String(e)} Open Settings → Patch notes to try again.`,`error`)})}}):null]})})]})}var T9=`The backup wasn't imported. Check it is a file made with Export everything (.tar) or Export backup (.zip), then try again.`;function wSe(){let{api:e}=z(),t=_(),n=N({queryKey:S9,queryFn:()=>Fo(e),staleTime:3e4}),[r,i]=(0,m.useState)(!1),[a,o]=(0,m.useState)({phase:`idle`}),[s,c]=(0,m.useState)({phase:`idle`}),[l,u]=(0,m.useState)(null),d=Oy(),[f,p]=(0,m.useState)(null);async function g(){p(null),o({phase:`preparing`});try{let t=await Eo(e);if(!t.ready){o({phase:`idle`}),p(t.detail??`The backup can't be made right now. Try again in a moment.`);return}o({phase:`downloading`,bytes:t.bytes??0,projects:t.projects??0});let n=document.createElement(`a`);n.href=`${e.origin}/api/storage/export`,n.download=``,document.body.append(n),n.click(),n.remove()}catch(e){o({phase:`idle`}),p(e instanceof Error?e.message:`The backup couldn't be prepared. Try again in a moment.`)}}async function v(n){let r=n.name.toLowerCase().endsWith(`.zip`)||n.type===`application/zip`;if(n.size===0||r&&n.size>104857600){p(r?`This file is empty or larger than 100 MB. Choose a .zip made with Export backup, or a .tar made with Export everything.`:`This file is empty. Choose the .tar made with Export everything.`);return}i(!0),p(null),u(null),c({phase:`uploading`,sent:0,total:n.size});try{let i=await e.upload(`${e.origin}/api/storage/import`,n,r?`application/zip`:`application/x-tar`,(e,t)=>{c(e>=t?{phase:`importing`}:{phase:`uploading`,sent:e,total:t})}),a=await i.json();if(!i.ok)throw Error(a.detail??T9);a.projects===void 0?d(`Imported ${a.templates??0} template(s), ${a.fonts??0} uploaded font(s), and ${a.stagedFiles??0} staged file(s).${a.fontFallbacks?` ${a.fontFallbacks} missing legacy font reference(s) now use the default font.`:``}`,`success`):(u(a),d(`Backup imported.`,`success`)),await vSe(t)}catch(e){p(e instanceof Error?e.message:T9)}finally{c({phase:`idle`}),i(!1)}}async function y(){i(!0),p(null);try{let n=await e.fetch(`${e.origin}/api/storage/cleanup`,{method:`POST`}),r=await n.json();if(!n.ok)throw Error(`Clean orphan files didn't finish. Try again in a moment.`);d(`Removed ${r.orphanFiles??0} orphan project file(s) and ${r.stagedFiles??0} stale staged file(s).`,`success`),await t.invalidateQueries({queryKey:S9})}catch(e){p(e instanceof Error?e.message:`Clean orphan files didn't finish. Try again in a moment.`)}finally{i(!1)}}bx({id:`settings.export-everything`,title:`Export everything`,group:`Settings`,context:`Backup & storage`,keywords:[`backup`,`download`],run:()=>{!r&&a.phase!==`preparing`&&g()}});let b=r||a.phase===`preparing`,x=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(H,{title:`Export and import`,info:`settings.storage.export`,children:[(0,h.jsx)(R,{disabled:b,onClick:()=>void g(),children:`Export everything`}),(0,h.jsx)(R,{disabled:b,onClick:()=>x.current?.click(),children:`Import a backup`}),(0,h.jsx)(`input`,{ref:x,className:`sr-only`,type:`file`,tabIndex:-1,"aria-label":`Import a backup`,accept:`.tar,application/x-tar,.zip,application/zip`,disabled:b,onChange:e=>{let t=e.target.files?.[0];t&&v(t),e.target.value=``}}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`quiet`,disabled:b,onClick:()=>void y(),children:`Clean orphan files`}),(0,h.jsx)(V,{id:`settings.storage.clean`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Provider keys are never included in a backup. After importing, enter them again in Settings → Providers.`}),a.phase===`preparing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Preparing the backup…`}):null,a.phase===`downloading`?(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 min-w-0 flex-1 text-ink`,children:[`Downloading `,Y5(a.bytes),` (`,a.projects,` project`,a.projects===1?``:`s`,`). Your browser's downloads show its progress; keep Slopify running until it finishes.`]}),(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:()=>o({phase:`idle`}),children:`Dismiss`})]}):null,s.phase===`uploading`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsxs)(`p`,{role:`status`,className:`m-0 text-ink tabular-nums`,children:[`Uploading the backup: `,Y5(s.sent),` of`,` `,Y5(s.total)]}),(0,h.jsx)(q2,{label:`Backup upload`,value:s.total===0?0:s.sent/s.total})]}):null,s.phase===`importing`?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-ink`,children:`Checking and importing the backup… large projects can take a minute.`}):null,f?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-danger`,children:f}):null]})]}),l?(0,h.jsx)(ESe,{result:l,onDismiss:()=>u(null)}):null,(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{title:`Disk space`,info:`settings.storage.disk`,meta:n.data?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`font-semibold text-ink`,children:[Y5(n.data.data),` stored`]}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[` `,`· `,Y5(Math.max(0,n.data.projects-n.data.trash.bytes)),` project files · `,Y5(n.data.staging),` staged files`,n.data.trash.projects>0?` · ${Y5(n.data.trash.bytes)} in the trash (${TSe(n.data.trash.projects)}), freed when removed for good`:null]})]}):n.error?`Storage usage is unavailable. Reload the page to try again.`:(0,h.jsx)(`span`,{className:`inline-block h-4 w-48 rounded-control bg-raised`})}),n.data&&n.data.byProject.length>0?(0,h.jsx)(Yve,{projects:n.data.byProject,queryKey:[...S9]}):null]})]})}function TSe(e){return e===1?`1 deleted project`:`${String(e)} deleted projects`}function E9(e,t){if(t===void 0)return null;let n=[t.added>0?`${t.added} added`:null,t.renamed>0?`${t.renamed} added as “(imported)” because the name was taken`:null,t.skipped>0?`${t.skipped} already here`:null].filter(e=>e!==null);return n.length===0?null:`${e}: ${n.join(`, `)}.`}function ESe({result:e,onDismiss:t}){let n=[e.projects.imported.length>0?`Projects: ${e.projects.imported.length} added (${Y5(e.files.bytes)} of files).`:`Projects: none added.`,E9(`Prompts`,e.prompts),E9(`Intros and outros`,e.entries),E9(`Channels`,e.channels),E9(`Cast members`,e.cast),E9(`Episode memories`,e.episodeMemories),E9(`Existing videos`,e.channelVideos),E9(`Document themes`,e.documentThemes),E9(`Templates`,e.templates),E9(`Schedules`,e.schedules),e.schedules.paused>0?`${e.schedules.paused} schedule(s) arrived paused so two installs never run them both; resume them on the Schedules screen.`:null,E9(`Voices`,e.voices),E9(`Play drafts`,e.drafts),e.settings.added+e.settings.kept>0?`Settings: ${e.settings.added} filled in${e.settings.kept>0?`, ${e.settings.kept} kept as this install has them`:``}.`:null,e.fonts>0?`Uploaded fonts: ${e.fonts} added.`:null,e.usage.alreadyImported?`Usage: this backup's history was already added before, so it wasn't counted twice.`:`Usage: ${e.usage.events} recorded event(s) added to the totals.`,`Provider keys are not in backups: enter them in Settings → Providers.`].filter(e=>e!==null);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(H,{as:`h3`,title:`Imported the backup from ${e.backup.createdAt.slice(0,10)}`,children:(0,h.jsx)(R,{variant:`quiet`,size:`small`,onClick:t,children:`Dismiss`})}),(0,h.jsxs)(`ul`,{"aria-label":`Import result`,className:`m-0 list-disc pl-5 text-small text-ink-2`,children:[n.map(e=>(0,h.jsx)(`li`,{className:`py-0.5`,children:e},e)),e.projects.skipped.map(e=>(0,h.jsxs)(`li`,{className:`py-0.5`,children:[`Skipped “`,e.title,`”: `,e.reason]},e.id))]})]})}function DSe(){let{api:e}=z(),t=_(),n=N(ob(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(!1),s=P({mutationFn:t=>Qo(e,t),onMutate:e=>{let n=t.getQueryData(B.settings);return t.setQueryData(B.settings,e),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(B.settings,r.previous)},onSuccess:e=>{t.setQueryData(B.settings,e)}});if((0,m.useEffect)(()=>{if(!a)return;let e=setTimeout(()=>{o(!1)},Y2);return()=>{clearTimeout(e)}},[a]),n.error!==null)return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:n.error.message});if(n.data===void 0)return(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,role:`status`,"aria-label":`Loading settings`,children:[(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`}),(0,h.jsx)(`span`,{className:`h-16 rounded-control bg-raised`})]});let c=n.data,l=r??String(c.silenceGapSeconds),u=bSe(l);return(0,h.jsxs)(`div`,{className:`grid items-start gap-6 md:grid-cols-2`,children:[(0,h.jsx)(xV,{label:`Silence between segments`,tip:`settings.playback.silence-gap`,help:`Seconds of quiet between narrated segments.`,error:u??s.error?.message,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(CV,{type:`number`,inputMode:`numeric`,min:0,max:C9,step:1,className:`w-[88px] tabular-nums`,value:l,"aria-invalid":u!==void 0,onChange:e=>{i(e.target.value)}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`seconds`}),(0,h.jsx)(R,{variant:`primary`,disabled:u!==void 0||s.isPending,onClick:()=>{o(!1),s.mutate({...c,silenceGapSeconds:Number(l.trim())},{onSuccess:()=>{i(void 0),o(!0)}})},children:`Save`}),(0,h.jsx)(`span`,{className:`inline-flex w-[52px]`,children:a?(0,h.jsx)(Z2,{}):null})]})}),(0,h.jsxs)(`div`,{className:`sl-field`,...Ob,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Appearance`}),(0,h.jsx)(V,{id:`settings.appearance`,className:`-my-1`})]}),(0,h.jsx)(Ab,{label:`Appearance`,value:c.appearance,options:ySe,className:`self-start`,onChange:e=>{s.mutate({...c,appearance:e})}})]}),(0,h.jsx)(`div`,{className:`md:col-span-2`,children:(0,h.jsx)(k6,{value:c.loudness??tk,switchLabel:`Level the volume for new runs`,switchTip:`settings.loudness`,onChange:e=>{s.mutate({...c,loudness:e})}})})]})}function OSe({open:e,onClose:t,onInstalled:n}){let{api:r}=z(),i=_(),a=N({queryKey:My,queryFn:()=>Iy(r),enabled:e}),o=P({mutationFn:e=>Ry(r,e),onSuccess:()=>n(),onSettled:()=>i.invalidateQueries({queryKey:My})});return(0,h.jsxs)(YP,{open:e,title:`Add a starter pack`,onClose:t,footer:(0,h.jsx)(Q1,{tone:o.error||a.error?`error`:`success`,children:o.error?.message??a.error?.message??(o.data===void 0?void 0:o.data.added?`Added: its prompts are in Prompts and its template is in this list.`:`That pack was already added.`)}),children:[(0,h.jsxs)(`p`,{className:`mb-4 flex items-center gap-1 text-small text-ink-2`,children:[`Prompts, a suggested voice and a template for one kind of channel.`,(0,h.jsx)(V,{id:`welcome.packs`})]}),(0,h.jsxs)(pU,{label:`Starter packs`,className:`[&_.sl-row__meta]:whitespace-normal`,children:[(a.data?.packs??[]).map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:(0,h.jsx)(R,{disabled:e.installed||o.isPending,onClick:()=>o.mutate(e.id),children:e.installed?`Added`:`Add pack`})},e.id)),a.data===void 0?(0,h.jsx)(mU,{title:`Loading packs…`}):null]})]})}function kSe({template:e}){let{api:t}=z(),n=N({queryKey:[...Lq,e.id,e.version],queryFn:async()=>{let n=await Uq(t,e.id);if(!n.ok)throw Error(n.message);return n.value}});if(n.error)return(0,h.jsxs)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:[`The keywords of `,e.name,` didn't load. `,n.error.message,` Press Keywords again.`]});if(!n.data)return(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`Reading the keywords…`});let{form:r,librarySnapshot:i}=n.data.document,a=h0({form:r,prompts:i?.prompts??[],entries:i?.entries??[]}),o=z3(r.title),s=[...new Set([...a.keys(),...Object.keys(r.values)])];return(0,h.jsx)(_0,{keywords:s.map(e=>({name:e,value:r.values[e]??``,feeds:a.get(e)??[],topic:o.includes(e)})),empty:`No keywords: the prompts and the title name none.`})}async function ASe(e,t,n,r){let i=await Gq(e,t.id,{baseVersion:t.version,mutationId:r,...n});if(!i.ok)throw Error(i.message);return i.value}function jSe({template:e}){return e===void 0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`Pick a template to see the keywords it fills.`}):(0,h.jsxs)(`section`,{"aria-label":`Keywords of ${e.name}`,className:`flex flex-col gap-4`,children:[(0,h.jsx)(H,{title:e.name,as:`h3`,info:`templates.edit`,className:`pb-0`}),(0,h.jsx)(kSe,{template:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`To change the settings, press Use in Play, change the draft, then Save a setup.`})]})}function MSe({template:e,onClose:t}){let{api:n}=z(),r=_(),i=Array.from({length:e.version},(t,n)=>e.version-n),a=ot({queries:i.map(t=>({queryKey:[...Lq,e.id,`version`,t],queryFn:async()=>{let r=await Uq(n,e.id,t);if(!r.ok)throw Error(r.message);return r.value},staleTime:1/0}))}),o=a[0]?.data,[s,c]=(0,m.useState)(i[1]??e.version),l=a[i.indexOf(s)]?.data,u=(0,m.useRef)(crypto.randomUUID()),d=Oy(),f=P({mutationFn:t=>ASe(n,e,{name:t.name,document:t.document},u.current),onSuccess:async(n,i)=>{u.current=crypto.randomUUID(),d(`Restored version ${String(i.version)} of ${e.name} as version ${String(n.version)}.`,`success`),await r.invalidateQueries({queryKey:Lq}),t()}}),p=a.find(e=>e.error!==null)?.error;return(0,h.jsx)(YP,{open:!0,title:`History of ${e.name}`,onClose:t,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[p?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-body text-danger`,children:`A version couldn't be read: ${p.message} Close History and open it again.`}):null,(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(H,{title:`Versions`,as:`h3`,info:`templates.history`}),(0,h.jsx)(pU,{label:`Versions of ${e.name}`,children:i.map((t,n)=>{let r=a[n]?.data;return(0,h.jsx)(mU,{title:`Version ${String(t)}`,selected:t===s,onSelect:()=>c(t),meta:r===void 0?`Loading…`:`${r.name} · ${j4(r.updatedAt)}`,actions:t===e.version?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(R,{size:`small`,"aria-label":`Restore version ${String(t)}`,disabled:r===void 0||f.isPending,disabledReason:r===void 0?`Reading the version`:`Restoring`,onClick:()=>{r!==void 0&&f.mutate(r)},children:`Restore`})},t)})}),(0,h.jsx)(Q1,{tone:`error`,children:f.error===null?void 0:`The version wasn't restored: ${f.error.message}`})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(H,{title:`Compare with the current version`,as:`h3`}),o===void 0||l===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Loading the versions…`}):l.version===o.version?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.version===1?`This is the only version so far.`:`Pick an older version in the list to compare it.`}):(0,h.jsxs)(h.Fragment,{children:[l.name===o.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${l.name}" to "${o.name}".`}),(0,h.jsx)(w4,{before:D9(l),after:D9(o),beforeLabel:`Version ${String(l.version)}`,afterLabel:`Version ${String(o.version)} (current)`})]})]})]})})}function D9(e){return JSON.stringify(e.document,null,1).split(`
308
308
  `).map(e=>e.trim()).filter(e=>!/^[[\]{}],?$/u.test(e)).join(`
309
- `)}function NSe({onApplied:e,beforeApply:t,getGeneration:n,blocked:r=!1}){let{api:i}=z(),a=_(),o=N(Hq(i)),s=N(Zb(i)),[c,l]=(0,m.useState)(``),u=o.data?.filter(e=>c===``||o0(e)===c),d=e=>s.data?.find(t=>t.id===o0(e))?.name,f=N({queryKey:[`play-drafts`],queryFn:async()=>{let e=await ZM(i);if(!e.ok)throw Error(e.message);return e.value.drafts}}),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),E=Oy(),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!1),[ee,te]=(0,m.useState)(null),[ne,j]=(0,m.useState)(null),[re,M]=(0,m.useState)(null),ie=(0,m.useRef)(new Map),ae=(0,m.useRef)(!1),oe=(0,m.useRef)(null),se=(0,m.useRef)(new Map),ce=(0,m.useRef)(!0);(0,m.useEffect)(()=>(ce.current=!0,()=>{ce.current=!1}),[]);async function le(e){if(!ae.current){ae.current=!0,C(!0),T(null);try{await e()}catch(e){T(e instanceof Error?e.message:`That didn't finish. Try again.`)}finally{ae.current=!1,C(!1)}}}async function ue(){let e=await $M(i,p);if(!e.ok)throw Error(e.message);let t=JSON.stringify([p,e.value.draft.version,v.trim(),b]);oe.current?.key!==t&&(oe.current={key:t,id:crypto.randomUUID()});let n=e.value.draft.document,r=o.data?.find(e=>e.id===n.templateSource?.id),s=b||n.channelId||(r?o0(r):void 0),c=await Wq(i,{id:oe.current.id,name:v.trim(),document:s===void 0?n:{...n,channelId:s}});if(!c.ok)throw oe.current=null,Error(c.message);oe.current=null,y(``),O(!1),E(`Template saved.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function de(o){let s=n?.();if(r||t&&!await t())throw Error(`Save or discard the draft open in Play first, then apply the template again.`);if(!ce.current||s!==void 0&&s!==n?.())return;let c=`${o.id}:${o.version}`,l=se.current.get(c);l||(l=crypto.randomUUID(),se.current.set(c,l));let u=await Xq(i,o,l);if(!u.ok)throw se.current.delete(c),Error(u.message);if(!(!ce.current||s!==void 0&&s!==n?.())&&(await a.invalidateQueries({queryKey:[`play-drafts`]}),!(!ce.current||s!==void 0&&s!==n?.()))){if(await e(u.value.draft.id,()=>ce.current)!==!1)se.current.delete(c);else throw Error(`The template's draft was created but didn't open. Press Use in Play again to open it.`)}}async function fe(e){let t=`${e.id}:${e.version}`,n=ie.current.get(t);n||(n=crypto.randomUUID(),ie.current.set(t,n));let r=await Uq(i,e.id);if(!r.ok)throw Error(r.message);let o=await Wq(i,{id:n,name:`${e.name} copy`,document:r.value.document});if(!o.ok)throw Error(o.message);ie.current.delete(t),E(`Duplicated as ${o.value.name}.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function pe(){if(!ee)return;let e=ee.id,t=await Jq(i,ee);if(!t.ok)throw Error(t.message);te(null),await a.cancelQueries({queryKey:Lq}),a.setQueryData(Lq,t=>t?.filter(t=>t.id!==e)),E(`Template moved to the trash. Restore it in Settings → Trash within 30 days.`,`success`),await a.invalidateQueries({queryKey:Lq})}bx({id:`library.save-template`,title:`Save a setup as a template`,group:`Library`,keywords:[`template`,`new template`,`play draft`],run:()=>O(!0)});let me=w&&!ee?{tone:`error`,text:w}:r?{tone:`warning`,text:`A run is still starting in Play. Wait for it to finish (or press Check Start result there), then apply a template.`}:o.error?{tone:`error`,text:o.error.message}:o.isPending?{tone:`info`,text:`Loading templates…`}:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(OSe,{open:k,onClose:()=>A(!1),onInstalled:()=>void a.invalidateQueries({queryKey:Hq(i).queryKey})}),(0,h.jsxs)(B4,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,onClick:()=>A(!0),"aria-expanded":k,children:`Add pack`}),(0,h.jsx)(V,{id:`welcome.packs`,label:`Add pack`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`primary`,onClick:()=>O(!0),"aria-expanded":D,children:`Save a setup`}),(0,h.jsx)(V,{id:`templates.save`,label:`Save a setup`})]})]}),children:[(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsxs)(TV,{"aria-label":`Show templates of`,value:c,className:`w-full sm:w-56`,onChange:e=>l(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsx)(V,{id:`templates.show-channel`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Reuse a Play setup and its checkpoint choices. Use in Play creates a fresh draft to review.`,(0,h.jsx)(V,{id:`templates.apply`,label:`Use in Play`})]})]}),(0,h.jsxs)(`div`,{className:`mb-2 flex min-h-8 flex-wrap items-center gap-3`,children:[(0,h.jsx)(Q1,{tone:me?.tone??`info`,children:me?.text}),o.error?(0,h.jsx)(R,{size:`small`,onClick:()=>void o.refetch(),children:`Reload templates`}):null,(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:S||o.isFetching,onClick:()=>void o.refetch(),children:`Refresh templates`})]}),o.data?.length===0?(0,h.jsx)(a0,{title:`No templates yet`,children:`Use Save a setup to keep a Play draft for reuse.`}):null,o.data?.length&&u?.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No templates in this channel.`}):null,o.isPending&&!o.error?(0,h.jsx)(L4,{label:`Project templates`}):null,u?.length?(0,h.jsx)(jq,{className:F4,list:(0,h.jsx)(pU,{label:`Project templates`,children:u.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(mU,{className:`max-md:grid-cols-1`,title:(0,h.jsx)(J4,{name:e.name,maxLength:120,onSelect:()=>j(e.id),onRename:async t=>{let n=await Kq(i,e.id,t);return await a.invalidateQueries({queryKey:Lq}),n}}),selected:e.id===ne,meta:(0,h.jsxs)(h.Fragment,{children:[d(e)===void 0?``:`${d(e)} · `,`Version `,e.version,` · updated`,` `,(0,h.jsx)(`time`,{dateTime:e.updatedAt,children:e.updatedAt.slice(0,10)})]}),actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,onClick:()=>j(e.id),children:`Edit`}),duplicate:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:S,disabledReason:`Working on the last press`,onClick:()=>void le(()=>fe(e)),children:`Duplicate`}),play:{run:()=>void le(()=>de(e)),blocked:r?`A run is still starting in Play. Wait for it, then use the template.`:S?`Working on the last press`:void 0},onHistory:()=>M(e),onDelete:()=>{te(e),T(null)}})}),(0,h.jsx)(c0,{kind:`template`,id:e.id,name:e.name})]},e.id))}),detail:(0,h.jsx)(jSe,{template:u.find(e=>e.id===ne)})}):null,(0,h.jsxs)(YP,{open:D,title:`Save a setup`,width:`narrow`,onClose:()=>O(!1),footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:w?`error`:`info`,children:w??(S?`Saving…`:void 0)}),(0,h.jsx)(R,{type:`submit`,form:`save-template-form`,variant:`primary`,disabled:S||!p||!v.trim(),children:`Save template`})]}),children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[`Choose a saved Play draft, or`,` `,(0,h.jsx)(ha,{to:`/play`,className:`text-accent-ink underline`,children:`open Play`}),` `,`to prepare one.`]}),(0,h.jsx)(`p`,{className:`mb-4 text-small text-ink-2`,children:`A template keeps the settings, not one video's topic.`}),(0,h.jsxs)(`form`,{id:`save-template-form`,"aria-label":`Save a setup`,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),p&&v.trim()&&le(ue)},children:[(0,h.jsx)(xV,{label:`Saved Play draft`,tip:`templates.save.draft`,help:f.isPending?`Loading saved drafts…`:f.data?.length===0?`No saved drafts yet.`:void 0,children:(0,h.jsxs)(TV,{value:p,required:!0,disabled:S,onChange:e=>g(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a draft`}),f.data?.filter(e=>e.readable).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.title||`Untitled draft`},e.id))]})}),f.error?(0,h.jsx)(SI,{tone:`danger`,title:`The saved drafts couldn't be loaded.`,actions:(0,h.jsx)(R,{size:`small`,onClick:()=>void f.refetch(),children:`Reload drafts`}),children:f.error.message}):null,(0,h.jsx)(xV,{label:`Template name`,id:`template-name`,tip:`templates.save.name`,children:(0,h.jsx)(CV,{value:v,required:!0,maxLength:120,disabled:S,onChange:e=>y(e.target.value)})}),(0,h.jsx)(xV,{label:`Channel`,id:`template-channel`,tip:`templates.save.channel`,children:(0,h.jsxs)(TV,{value:b,disabled:S,onChange:e=>x(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`The draft's channel`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]})]}),re===null?null:(0,h.jsx)(MSe,{template:re,onClose:()=>M(null)},`${re.id}:${String(re.version)}`),(0,h.jsx)(jy,{open:ee!==null,title:`Delete ${ee?.name??`template`}?`,consequence:w??`Moves it to the trash for 30 days (Settings → Trash). Existing projects and drafts keep their setup.`,confirmLabel:`Delete template`,pending:S,onConfirm:()=>void le(pe),onCancel:()=>{S||te(null)}})]})}function PSe({page:e,anchor:t,words:n}){let{api:r}=z(),i=N(NB(r)),a=N(PB(r,e)),o=Zi(),[s,c]=(0,m.useState)(n??``);(0,m.useEffect)(()=>{c(n??``)},[n]);let l=(0,m.useRef)(null),u=(0,m.useMemo)(()=>new Set((i.data?.pages??[]).map(e=>e.id)),[i.data]),d=i.data?.pages.find(t=>t.id===e)?.title??e.replace(/-/g,` `),f=(0,m.useMemo)(()=>yb(a.data??``),[a.data]),p=(0,m.useMemo)(()=>a.data===void 0?``:vb(f.body,u,e),[a.data,f.body,u,e]);(0,m.useEffect)(()=>{if(p===``)return;let e=l.current;if(e===null)return;let n=t===void 0?void 0:xb(e,t,f.title===void 0?[]:[f.title]);n===void 0?window.scrollTo?.({top:0}):n.scrollIntoView?.({block:`start`})},[p,t,f.title]);let g=i.data?.groups.find(t=>t.pages.some(t=>t.id===e));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Help`}),(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`›`}),(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:i.data?.home.id??`Home`},children:`Tutorials`})]}),title:d,meta:g===void 0?`Guides to every screen of Slopify, for the version you are running.`:g.title}),(0,h.jsx)(Aq,{className:`sl-workspace--tutorials`,sections:(0,h.jsx)(FSe,{index:i.data,page:e,onOpenHit:(e,t)=>{o({to:`/help/tutorials/$page`,params:{page:e.page},search:{q:t},...e.anchor===``?{}:{hash:e.anchor}})}}),children:a.error===null?(0,h.jsxs)(`div`,{ref:l,onClick:e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey)return;let t=e.target.closest(`a`),n=t?.getAttribute(`href`);if(t===null||n==null)return;let r=bb(n);if(r!==void 0){e.preventDefault(),o({to:`/help/tutorials/$page`,params:{page:r.page},...r.anchor===void 0?{}:{hash:r.anchor}});return}/^https?:/.test(n)&&(e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`))},children:[(0,h.jsx)(CB,{markdown:p,label:`Tutorial`,what:`tutorial`,query:s,onQuery:c,anchorPrefix:`tutorial-`,children:(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the tutorial…`})}),i.data?.footer?(0,h.jsx)(`p`,{className:`mt-8 border-t border-line pt-4 text-small text-ink-3`,children:i.data.footer.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`)}):null]}):(0,h.jsx)(SI,{tone:`danger`,title:`This tutorial did not load`,actions:(0,h.jsx)(R,{onClick:()=>void a.refetch(),variant:`secondary`,children:`Try again`}),children:`${a.error.message} Press Try again, or pick another page on the left.`})})]})}function FSe({index:e,page:t,onOpenHit:n}){let{api:r}=z(),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),c=(0,m.useRef)(null),l=(0,m.useId)();xx(c,`the tutorials`),(0,m.useEffect)(()=>{let e=setTimeout(()=>s(i.trim()),200);return()=>clearTimeout(e)},[i]);let u=N(FB(r,o));return(0,h.jsxs)(`nav`,{"aria-label":`Tutorials`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(`label`,{htmlFor:l,className:`sr-only`,children:`Search all tutorials`}),(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{ref:c,id:l,type:`search`,value:i,placeholder:`Search all tutorials`,onChange:e=>a(e.target.value),onKeyDown:e=>{let t=u.data?.hits[0];e.key===`Enter`&&t!==void 0&&(e.preventDefault(),n(t,o))},className:`sl-input pl-9`})]}),o===``?e===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the tutorials…`}):(0,h.jsxs)(`div`,{className:`sl-tutorials-nav flex flex-col gap-4`,children:[(0,h.jsx)(D9,{id:e.home.id,title:e.home.title,current:t}),e.groups.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,h.jsx)(`div`,{className:`sl-kicker px-2.5 pb-1`,children:e.title}),e.pages.map(e=>(0,h.jsx)(D9,{id:e.id,title:e.title,current:t},e.id))]},e.title))]}):(0,h.jsx)(ISe,{query:o,hits:u.data?.hits,error:u.error?.message})]})}function D9({id:e,title:t,current:n}){return(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:e},"aria-current":e===n?`page`:void 0,className:`sl-tutorials-nav__link`,children:t})}function ISe({query:e,hits:t,error:n}){return n===void 0?t===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Searching…`}):t.length===0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`No tutorial mentions "${e}". Try fewer or other words.`}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{role:`status`,className:`m-0 px-2.5 text-small text-ink-3`,children:t.length===1?`1 section`:`${String(t.length)} sections`}),(0,h.jsx)(`ul`,{"aria-label":`Search results`,className:`m-0 flex list-none flex-col gap-1 p-0`,children:t.map(t=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(ha,{to:`/help/tutorials/$page`,params:{page:t.page},search:{q:e},...t.anchor===``?{}:{hash:t.anchor},className:`sl-tutorials-hit`,children:[(0,h.jsx)(`span`,{className:`block font-semibold text-ink`,children:t.heading===void 0?t.pageTitle:t.heading}),t.heading===void 0?null:(0,h.jsx)(`span`,{className:`block text-label text-ink-3`,children:t.pageTitle}),(0,h.jsx)(`span`,{className:`mt-0.5 block text-small text-ink-2`,children:t.snippet})]})},`${t.page}#${t.anchor}`))})]}):(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The search didn't run: ${n} Change the words or reload the page.`})}var LSe=[{id:`library`,name:`The Library of Alexandria`,summary:`A narrated video with its two shorts, article, PDF, description and images.`,action:`Explore the sample`},{id:`audiobook`,name:`The Wind in the Willows`,summary:`An audiobook: a narrator and two character voices, captions tagged with who speaks, MP3 and M4B with chapters.`,action:`See an audiobook`},{id:`podcast`,name:`The Antikythera Mechanism`,summary:`A two-host podcast with the speaker panel, name tags and portraits, and its MP3 and M4B.`,action:`Hear a podcast`}],O9=[{id:`found`,label:`1 · What you have`},{id:`style`,label:`2 · Pick a style`},{id:`make`,label:`3 · Make your first short`}];function RSe(e){return e.length<=2?e.join(` or `):`${e.slice(0,-1).join(`, `)} or ${e.at(-1)??``}`}function zSe(e){return e===void 0?{ready:!1,text:`Looking for a voice…`}:e.keyed===null?e.system.available?{ready:!0,text:`Narration uses your computer's built-in voice${e.system.engine===null?``:` (${e.system.engine})`}; add an ElevenLabs or OpenAI key later for a better one.`}:{ready:!1,text:e.system.issue??`No voice can narrate yet. Add an ElevenLabs or OpenAI key in Settings → Providers.`}:{ready:!0,text:`Narration uses your ${e.keyed} voice key.`}}function BSe(){let{api:e}=z(),t=_(),n=Zi(),r=N({queryKey:My,queryFn:()=>Iy(e)}),[i,a]=(0,m.useState)(`found`),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(void 0),f=(0,m.useRef)(void 0),p=P({mutationFn:()=>Ly(e),onSuccess:async()=>{await t.invalidateQueries({queryKey:My}),await n({to:`/`})}}),g=P({mutationFn:t=>Ry(e,t),onSettled:()=>t.invalidateQueries({queryKey:My})}),v=P({mutationFn:()=>(f.current??=crypto.randomUUID(),zy(e,{topic:o,requestId:f.current,...c===``?{}:{packId:c}})),onSuccess:async({projectId:e})=>{f.current=void 0,d(e),await t.invalidateQueries({queryKey:B.projects}),await t.invalidateQueries({queryKey:B.voices})}}),y=e=>{e.preventDefault(),o.trim()!==``&&v.mutate()},b=r.data,x=b?.clis.filter(e=>e.ready)??[],S=zSe(b?.voice),C=c===``?`General`:b?.packs.find(e=>e.id===c)?.name??c,w=v.error?{tone:`error`,text:v.error.message}:g.error?{tone:`error`,text:g.error.message}:p.error?{tone:`error`,text:p.error.message}:v.isPending?{tone:`info`,text:`Starting your short…`}:void 0,T=O9.findIndex(e=>e.id===i),E=O9[T+1],D=O9[T-1];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Welcome to Slopify`,meta:`Make a video from a topic, with the tools already on this computer.`,actions:(0,h.jsx)(R,{variant:`quiet`,disabled:p.isPending,onClick:()=>p.mutate(),children:u===void 0?`Skip`:`Done`})}),r.error?(0,h.jsx)(SI,{tone:`danger`,title:`Could not read what this computer has`,className:`mb-6`,children:r.error.message}):null,(0,h.jsx)(r0,{items:O9.map(e=>({id:e.id,label:e.label})),value:i,onChange:a,label:`First-run steps`,idPrefix:`welcome`,className:`mb-6`}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`found`,active:i===`found`,children:[(0,h.jsx)(H,{title:`Found on this computer`,info:`welcome.found`}),(0,h.jsxs)(pU,{label:`Tools found on this computer`,className:`mb-4`,children:[(b?.clis??[]).map(e=>(0,h.jsx)(mU,{title:e.name,actions:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.ready?`Ready${e.version===null?``:` · ${e.version}`}${e.draws?` · writes and draws`:` · writes`}`:e.installed?e.issue??`Installed, not usable yet`:`Not found`})},e.id)),b===void 0?(0,h.jsx)(mU,{title:`Looking for installed tools…`}):null]}),b!==void 0&&x.length>0?(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:`You can make a video now: no API keys are needed for ${RSe([`the text`,...x.some(e=>e.draws)?[`the images`]:[],...S.ready&&b.voice.keyed===null?[`the narration`]:[]])}.`}):null,b!==void 0&&x.length===0?(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`Nothing on this computer can write the script yet.`,actions:(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},children:`Open Settings → Providers`}),children:`Install Claude Code, Codex or Gemini CLI and sign in to it, then press Check again; or add an OpenRouter key in Settings → Providers.`}):null,(0,h.jsx)(H,{title:`Narration voice`,info:`welcome.voice`}),b===void 0?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6`,children:(0,h.jsx)(mU,{title:`Looking for a voice…`})}):(0,h.jsx)(k9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`style`,active:i===`style`,children:[(0,h.jsx)(H,{title:`Pick a style`,info:`welcome.pack`}),(0,h.jsx)(pU,{label:`Styles`,className:`mb-3 [&_.sl-row__meta]:whitespace-normal`,children:[{id:``,name:`General`,summary:`A neutral explainer style.`,installed:!1,library:!1},...(b?.packs??[]).map(e=>({...e,library:!0}))].map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,selected:c===e.id,actions:(0,h.jsxs)(h.Fragment,{children:[e.library?(0,h.jsx)(R,{variant:`quiet`,disabled:e.installed||g.isPending,"aria-label":e.installed?`${e.name} is in your library`:`Add ${e.name} to library`,onClick:()=>g.mutate(e.id),children:e.installed?`In your library`:`Add to library`}):null,(0,h.jsx)(R,{variant:c===e.id?`primary`:`secondary`,"aria-pressed":c===e.id,"aria-label":`Use ${e.name}`,onClick:()=>l(e.id),children:c===e.id?`Picked`:`Use this style`})]})},e.id===``?`general`:e.id))}),(0,h.jsxs)(`p`,{className:`mb-6 flex items-center gap-1 text-small text-ink-2`,...Ob,children:[`Add to library keeps a pack's prompts and Play template for later videos.`,(0,h.jsx)(V,{id:`welcome.packs`,className:`-my-1`})]})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`make`,active:i===`make`,children:[u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Make a 60-second short`,info:`welcome.short`}),(0,h.jsxs)(`p`,{className:`mb-3 text-small text-ink-2`,children:[`Style: ${C}. `,S.text]}),S.ready||b===void 0?null:(0,h.jsx)(`div`,{className:`mb-4`,children:(0,h.jsx)(k9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})}),(0,h.jsxs)(`form`,{onSubmit:y,className:`mb-6 flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[240px] flex-1 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:`welcome-topic`,className:`text-label text-ink-2`,children:`Topic`}),(0,h.jsx)(V,{id:`welcome.topic`,className:`-my-1`})]}),(0,h.jsx)(R3,{id:`welcome-topic`,value:o,maxLength:200,placeholder:`Why the sea glows at night`,onChange:e=>s(e.target.value)})]}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:o.trim()===``||v.isPending,disabledReason:`Type a topic first.`,children:`Make a 60-second short`})]})]}):(0,h.jsx)(SI,{tone:`info`,className:`mb-6`,title:`Your short is being made.`,actions:(0,h.jsx)(fS,{variant:`primary`,to:`/projects/$projectId`,params:{projectId:u},children:`Watch it being made`}),children:`It usually takes about five minutes. The live view shows each step as it runs; while you wait, look at a sample or set Slopify to start when you log in.`}),(0,h.jsx)(H,{title:`While you wait: the samples`,info:`welcome.samples`}),(0,h.jsx)(pU,{label:`Samples`,className:`mb-6 [&_.sl-row__meta]:whitespace-normal`,children:LSe.map(e=>{let t=b?.samples[e.id]??null;return(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:t===null?(0,h.jsx)(pS,{to:`/settings`,search:{section:`storage`},children:`Restore samples in Settings`}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:e.action})},e.id)})}),(0,h.jsx)(Vb,{})]}),(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:w?.tone??`info`,children:w?.text}),children:[(0,h.jsx)(pS,{to:`/play`,children:`Set up a long video instead`}),D===void 0?null:(0,h.jsx)(R,{onClick:()=>a(D.id),children:`Back`}),E===void 0?null:(0,h.jsx)(R,{variant:`primary`,onClick:()=>a(E.id),children:`Next: ${E.label.replace(/^\d · /,``)}`})]})]})}function k9({voice:e,checking:t,onCheck:n}){return e.ready?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6 [&_.sl-row__title]:whitespace-normal`,children:(0,h.jsx)(mU,{lead:(0,h.jsx)(gS,{tone:`done`}),title:e.text,actions:(0,h.jsx)(fS,{variant:`quiet`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`})})}):(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`No voice can narrate the short yet.`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(fS,{variant:`primary`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`}),(0,h.jsx)(R,{disabled:t,onClick:n,children:t?`Checking…`:`Check again`})]}),children:e.text})}var A9=ba({component:eV}),VSe=va({getParentRoute:()=>A9,path:`/`,component:Fme}),j9=va({getParentRoute:()=>A9,path:`projects`,validateSearch:e=>{let t=Xbe(e.show);return t===void 0?{}:{show:t}},component:HSe});function HSe(){let{show:e}=j9.useSearch();return(0,h.jsx)($be,{initialFilter:e??`all`},e??`all`)}var USe=va({getParentRoute:()=>A9,path:`welcome`,component:BSe}),WSe=va({getParentRoute:()=>A9,path:`play`,component:Age}),M9=va({getParentRoute:()=>A9,id:`_library`,component:Upe}),GSe=va({getParentRoute:()=>A9,path:`library`,beforeLoad:()=>{throw dn({to:`/prompts`,search:{kind:`article`}})}}),KSe=va({getParentRoute:()=>A9,path:`channels`,component:bpe}),N9=va({getParentRoute:()=>A9,path:`channels/$channelId`,validateSearch:e=>e.tab===void 0?{}:{tab:vpe(e.tab)},component:qSe});function qSe(){let{channelId:e}=N9.useParams(),{tab:t}=N9.useSearch(),n=Zi();return(0,h.jsx)(ype,{channelId:e,tab:t??`brand`,onTab:t=>{n({to:`/channels/$channelId`,params:{channelId:e},search:{tab:t},replace:!0})}},e)}var JSe=va({getParentRoute:()=>M9,path:`templates`,component:$Se}),YSe=/^[0-9A-Za-z-]{1,64}$/;function P9(e){return Ffe(e.tab)===`schedules`?typeof e.schedule==`string`&&YSe.test(e.schedule)?{tab:`schedules`,schedule:e.schedule}:{tab:`schedules`}:{}}var F9=va({getParentRoute:()=>A9,path:`calendar`,validateSearch:P9,component:QSe}),XSe=va({getParentRoute:()=>A9,path:`schedules`,beforeLoad:()=>{throw dn({to:`/calendar`,search:{tab:`schedules`},replace:!0})}}),ZSe=va({getParentRoute:()=>A9,path:`schedules/$scheduleId`,beforeLoad:({params:e})=>{throw dn({to:`/calendar`,search:P9({tab:`schedules`,schedule:e.scheduleId}),replace:!0})}});function QSe(){let e=P9(F9.useSearch()),t=Zi();return(0,h.jsx)(Lfe,{tab:e.tab??`weeks`,schedule:e.schedule,onTab:e=>{t({to:`/calendar`,search:e===`schedules`?{tab:`schedules`}:{},replace:!0})},onSchedule:e=>{t({to:`/calendar`,search:{tab:`schedules`,schedule:e},replace:!0})}})}function $Se(){let e=rP(),t=Zi();return(0,h.jsx)(NSe,{getGeneration:e.generation,blocked:e.review.starting||e.review.uncertain||e.review.created!==null,beforeApply:e.flush,onApplied:async(n,r)=>!r()||!await e.open(n,r)||!r()?!1:(await t({to:`/play`}),r())})}var I9=va({getParentRoute:()=>A9,path:`projects/$projectId`,component:cCe}),L9=va({getParentRoute:()=>M9,path:`prompts`,validateSearch:e=>({kind:vV(e.kind)}),component:lCe}),R9=va({getParentRoute:()=>A9,path:`prompts/new`,validateSearch:e=>{let t=vV(e.kind);return typeof e.from==`string`?{kind:t,from:e.from}:{kind:t}},component:uCe}),z9=va({getParentRoute:()=>A9,path:`prompts/$promptId`,component:dCe}),B9=va({getParentRoute:()=>M9,path:`entries`,validateSearch:e=>({category:hV(e.category)}),component:fCe}),V9=va({getParentRoute:()=>A9,path:`entries/new`,validateSearch:e=>{let t=hV(e.category);return typeof e.from==`string`?{category:t,from:e.from}:{category:t}},component:Y9}),H9=va({getParentRoute:()=>A9,path:`entries/$entryId`,component:pCe}),eCe=va({getParentRoute:()=>M9,path:`narration-aliases`,component:Lme}),tCe=va({getParentRoute:()=>M9,path:`document-themes`,component:Gpe}),U9=va({getParentRoute:()=>A9,path:`document-themes/new`,validateSearch:e=>typeof e.from==`string`?{from:e.from}:{},component:mCe}),W9=va({getParentRoute:()=>A9,path:`document-themes/$themeId`,component:hCe});function nCe(e){let t=e.section===void 0?void 0:xSe(e.section),n=t===`patch-notes`&&typeof e.note==`string`&&/^[0-9A-Za-z][0-9A-Za-z.-]{0,63}$/.test(e.note)?e.note:void 0;return{...t===void 0?{}:{section:t},...n===void 0?{}:{note:n}}}var G9=va({getParentRoute:()=>A9,path:`settings`,validateSearch:nCe,component:sCe}),K9=va({getParentRoute:()=>A9,path:`help/tutorials/$page`,validateSearch:e=>typeof e.q==`string`&&e.q.trim()!==``?{q:e.q.slice(0,200)}:{},component:rCe});function rCe(){let{page:e}=K9.useParams(),{q:t}=K9.useSearch(),n=Ha({select:e=>e.hash});return(0,h.jsx)(PSe,{page:e,anchor:n===``?void 0:n,words:t})}var iCe=va({getParentRoute:()=>A9,path:`help`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),aCe=va({getParentRoute:()=>A9,path:`help/tutorials`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),oCe=va({getParentRoute:()=>A9,path:`usage`,beforeLoad:()=>{throw dn({to:`/settings`,search:{section:`usage`}})}});function sCe(){let{section:e,note:t}=G9.useSearch(),n=Zi();return(0,h.jsx)(CSe,{section:e??`providers`,note:t,onSection:e=>{n({to:`/settings`,search:{section:e},replace:!0})},onNote:e=>{n({to:`/settings`,search:{section:`patch-notes`,...e===void 0?{}:{note:e}}})}})}function cCe(){let{projectId:e}=I9.useParams(),t=rP(),n=Zi();return(0,h.jsx)(Wbe,{projectId:e,openDraft:async e=>!await t.flush()||!await t.open(e)?!1:(await n({to:`/play`}),!0)},e)}function lCe(){let{kind:e}=L9.useSearch(),t=Zi(),n=q9();return(0,h.jsx)(ixe,{kind:e,onKind:e=>{t({to:`/prompts`,search:{kind:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function q9(){let e=rP(),t=Zi();return{blocked:e.review.starting||e.review.uncertain||e.review.created!==null?`Play is starting a run from its draft. Wait for it to start, then try again.`:void 0,use:n=>{let r=ZV(e.document,n);e.edit(r.document),t({to:`/play`}).then(()=>e.navigate(r.section,r.field))}}}function uCe(){let{kind:e,from:t}=R9.useSearch(),n=J9();return(0,h.jsx)(q7,{promptId:void 0,kind:e,from:t,onLeave:n},`${e}:${t??`new`}`)}function dCe(){let{promptId:e}=z9.useParams(),t=J9();return(0,h.jsx)(q7,{promptId:e,kind:`article`,from:void 0,onLeave:t},e)}function J9(){let e=Zi();return t=>{e({to:`/prompts`,search:{kind:t}})}}function fCe(){let{category:e}=B9.useSearch(),t=Zi(),n=q9();return(0,h.jsx)(Kpe,{category:e,onCategory:e=>{t({to:`/entries`,search:{category:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function Y9(){let{category:e,from:t}=V9.useSearch(),n=Z9();return(0,h.jsx)(c3,{entryId:void 0,category:e,from:t,onLeave:n})}function pCe(){let{entryId:e}=H9.useParams(),t=Z9();return(0,h.jsx)(c3,{entryId:e,category:`intro`,from:void 0,onLeave:t})}function mCe(){let{from:e}=U9.useSearch(),t=X9();return(0,h.jsx)(_4,{themeId:void 0,from:e,onLeave:t})}function hCe(){let{themeId:e}=W9.useParams(),t=X9();return(0,h.jsx)(_4,{themeId:e,from:void 0,onLeave:t})}function X9(){let e=Zi();return()=>{e({to:`/document-themes`})}}function Z9(){let e=Zi();return t=>{e({to:`/entries`,search:{category:t}})}}var gCe=A9.addChildren({homeRoute:VSe,projectsRoute:j9,welcomeRoute:USe,playRoute:WSe,libraryRoute:M9.addChildren({promptsRoute:L9,entriesRoute:B9,templatesRoute:JSe,documentThemesRoute:tCe,narrationAliasesRoute:eCe}),schedulesRoute:XSe,scheduleRoute:ZSe,calendarRoute:F9,libraryIndexRoute:GSe,channelsRoute:KSe,channelRoute:N9,projectRoute:I9,newPromptRoute:R9,promptRoute:z9,newEntryRoute:V9,entryRoute:H9,newDocumentThemeRoute:U9,documentThemeRoute:W9,settingsRoute:G9,usageRoute:oCe,helpRoute:iCe,tutorialsIndexRoute:aCe,tutorialsRoute:K9});function _Ce(){return La({routeTree:gCe})}function vCe(){let e,t,n=new Set;return{observe:r=>{if(e===void 0){e=r;for(let e of n)e();return}if(r!==e&&r!==t){t=r;for(let e of n)e()}},staleAt:()=>t,loadedAt:()=>e,subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function yCe(e,t){return async(n,r)=>{let i=await e(n,r),a=i.headers.get(`X-Slopify-Version`);return a!==null&&t.observe(a),i}}function bCe(){let e=new Map;return{observe:t=>{if(t.type===`stage.state`){let n=e.get(t.projectId);if(n){for(let[e,r]of n)r.stage===t.stage&&r.revisionId===t.revisionId&&r.workId===t.workId&&n.delete(e);n.size===0&&e.delete(t.projectId)}return}if(t.type!==`llm.preview`)return;let n=e.get(t.projectId)??new Map,r=JSON.stringify([t.revisionId,t.workId,t.callId]),i=n.get(r),a=(t.reset?t.text:`${i?.text??``}${t.text}`).slice(-65536);for(n.delete(r),n.set(r,{...t,text:a,reset:!0});n.size>8;){let e=n.keys().next().value;e!==void 0&&n.delete(e)}for(e.delete(t.projectId),e.set(t.projectId,n);e.size>16;){let t=e.keys().next().value;t!==void 0&&e.delete(t)}},snapshot:t=>[...e.get(t)?.values()??[]],snapshotAll:()=>[...e.values()].flatMap(e=>[...e.values()])}}var Q9=/\/events\/projects\/([^/?#]+)/,xCe=/\/events\/global(?:[?#]|$)/,SCe=[`running.count`,`staging.progress`,`staging.failed`,`schedule.topics`,`stage.state`,`stage.progress`,`article.delta`,`llm.preview`,`image.landed`,`narration.piece`,`project.state`,`project.updated`,`review.flagged`];function CCe(e){let t=new Set,n=bCe(),r,i=!1,a=(e,t,n)=>{for(let r of e.listeners.get(t)??[])r({data:n})},o=o=>{if(r!==void 0)return;let s=e(o);r=s,s.addEventListener(`open`,()=>{i=!0;for(let e of[...t])for(let t of e.opens)t()});for(let e of SCe)s.addEventListener(e,r=>{let i;try{let t=JSON.parse(r.data);typeof t.projectId==`string`&&(i=t.projectId),(e===`llm.preview`||e===`stage.state`)&&n.observe(t)}catch{return}for(let n of[...t])(n.projectId===void 0||n.projectId===i)&&a(n,e,r.data)})};return s=>{let c=Q9.exec(s)?.[1];if(c===void 0&&!xCe.test(s))return e(s);o(c===void 0?s:s.replace(Q9,`/events/global`));let l={projectId:c===void 0?void 0:decodeURIComponent(c),listeners:new Map,opens:new Set};return t.add(l),i&&queueMicrotask(()=>{if(t.has(l)){for(let e of l.opens)e();if(l.projectId!==void 0)for(let e of n.snapshot(l.projectId))a(l,`llm.preview`,JSON.stringify(e))}}),{addEventListener:(e,t)=>{if(e===`open`){l.opens.add(t);return}let n=l.listeners.get(e)??new Set;n.add(t),l.listeners.set(e,n)},close:()=>{t.delete(l),t.size===0&&r!==void 0&&(r.close(),r=void 0,i=!1)}}}}function wCe(e){let t=vCe(),n={api:Co(window.location.origin,yCe(window.fetch.bind(window),t),To(e=>{let n=e.headers.get(`X-Slopify-Version`);n!==null&&t.observe(n)})),openEvents:CCe(e=>new EventSource(e)),version:t};(0,co.createRoot)(e).render((0,h.jsx)(m.StrictMode,{children:(0,h.jsx)(v,{client:new Je,children:(0,h.jsx)(ste,{deps:n,children:(0,h.jsx)(Ba,{router:_Ce()})})})}))}var $9=document.getElementById(`root`);if($9===null)throw Error(`index.html carries no #root element for the app to mount on`);wCe($9);export{t4 as t};
309
+ `)}function NSe({onApplied:e,beforeApply:t,getGeneration:n,blocked:r=!1}){let{api:i}=z(),a=_(),o=N(Hq(i)),s=N(Zb(i)),[c,l]=(0,m.useState)(``),u=o.data?.filter(e=>c===``||o0(e)===c),d=e=>s.data?.find(t=>t.id===o0(e))?.name,f=N({queryKey:[`play-drafts`],queryFn:async()=>{let e=await ZM(i);if(!e.ok)throw Error(e.message);return e.value.drafts}}),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),E=Oy(),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!1),[ee,te]=(0,m.useState)(null),[ne,j]=(0,m.useState)(null),[re,M]=(0,m.useState)(null),ie=(0,m.useRef)(new Map),ae=(0,m.useRef)(!1),oe=(0,m.useRef)(null),se=(0,m.useRef)(new Map),ce=(0,m.useRef)(!0);(0,m.useEffect)(()=>(ce.current=!0,()=>{ce.current=!1}),[]);async function le(e){if(!ae.current){ae.current=!0,C(!0),T(null);try{await e()}catch(e){T(e instanceof Error?e.message:`That didn't finish. Try again.`)}finally{ae.current=!1,C(!1)}}}async function ue(){let e=await $M(i,p);if(!e.ok)throw Error(e.message);let t=JSON.stringify([p,e.value.draft.version,v.trim(),b]);oe.current?.key!==t&&(oe.current={key:t,id:crypto.randomUUID()});let n=e.value.draft.document,r=o.data?.find(e=>e.id===n.templateSource?.id),s=b||n.channelId||(r?o0(r):void 0),c=await Wq(i,{id:oe.current.id,name:v.trim(),document:s===void 0?n:{...n,channelId:s}});if(!c.ok)throw oe.current=null,Error(c.message);oe.current=null,y(``),O(!1),E(`Template saved.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function de(o){let s=n?.();if(r||t&&!await t())throw Error(`Save or discard the draft open in Play first, then apply the template again.`);if(!ce.current||s!==void 0&&s!==n?.())return;let c=`${o.id}:${o.version}`,l=se.current.get(c);l||(l=crypto.randomUUID(),se.current.set(c,l));let u=await Xq(i,o,l);if(!u.ok)throw se.current.delete(c),Error(u.message);if(!(!ce.current||s!==void 0&&s!==n?.())&&(await a.invalidateQueries({queryKey:[`play-drafts`]}),!(!ce.current||s!==void 0&&s!==n?.()))){if(await e(u.value.draft.id,()=>ce.current)!==!1)se.current.delete(c);else throw Error(`The template's draft was created but didn't open. Press Use in Play again to open it.`)}}async function fe(e){let t=`${e.id}:${e.version}`,n=ie.current.get(t);n||(n=crypto.randomUUID(),ie.current.set(t,n));let r=await Uq(i,e.id);if(!r.ok)throw Error(r.message);let o=await Wq(i,{id:n,name:`${e.name} copy`,document:r.value.document});if(!o.ok)throw Error(o.message);ie.current.delete(t),E(`Duplicated as ${o.value.name}.`,`success`),await a.invalidateQueries({queryKey:Lq})}async function pe(){if(!ee)return;let e=ee.id,t=await Jq(i,ee);if(!t.ok)throw Error(t.message);te(null),await a.cancelQueries({queryKey:Lq}),a.setQueryData(Lq,t=>t?.filter(t=>t.id!==e)),E(`Template moved to the trash. Restore it in Settings → Trash within 30 days.`,`success`),await a.invalidateQueries({queryKey:Lq})}bx({id:`library.save-template`,title:`Save a setup as a template`,group:`Library`,keywords:[`template`,`new template`,`play draft`],run:()=>O(!0)});let me=w&&!ee?{tone:`error`,text:w}:r?{tone:`warning`,text:`A run is still starting in Play. Wait for it to finish (or press Check Start result there), then apply a template.`}:o.error?{tone:`error`,text:o.error.message}:o.isPending?{tone:`info`,text:`Loading templates…`}:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(OSe,{open:k,onClose:()=>A(!1),onInstalled:()=>void a.invalidateQueries({queryKey:Hq(i).queryKey})}),(0,h.jsxs)(B4,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`secondary`,onClick:()=>A(!0),"aria-expanded":k,children:`Add pack`}),(0,h.jsx)(V,{id:`welcome.packs`,label:`Add pack`})]}),(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(R,{variant:`primary`,onClick:()=>O(!0),"aria-expanded":D,children:`Save a setup`}),(0,h.jsx)(V,{id:`templates.save`,label:`Save a setup`})]})]}),children:[(0,h.jsxs)(`span`,{className:`flex w-full items-center gap-1 sm:w-auto`,...Ob,children:[(0,h.jsxs)(TV,{"aria-label":`Show templates of`,value:c,className:`w-full sm:w-56`,onChange:e=>l(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsx)(V,{id:`templates.show-channel`})]}),(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Reuse a Play setup and its checkpoint choices. Use in Play creates a fresh draft to review.`,(0,h.jsx)(V,{id:`templates.apply`,label:`Use in Play`})]})]}),(0,h.jsxs)(`div`,{className:`mb-2 flex min-h-8 flex-wrap items-center gap-3`,children:[(0,h.jsx)(Q1,{tone:me?.tone??`info`,children:me?.text}),o.error?(0,h.jsx)(R,{size:`small`,onClick:()=>void o.refetch(),children:`Reload templates`}):null,(0,h.jsx)(R,{variant:`quiet`,size:`small`,disabled:S||o.isFetching,onClick:()=>void o.refetch(),children:`Refresh templates`})]}),o.data?.length===0?(0,h.jsx)(a0,{title:`No templates yet`,children:`Use Save a setup to keep a Play draft for reuse.`}):null,o.data?.length&&u?.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No templates in this channel.`}):null,o.isPending&&!o.error?(0,h.jsx)(L4,{label:`Project templates`}):null,u?.length?(0,h.jsx)(jq,{className:F4,list:(0,h.jsx)(pU,{label:`Project templates`,children:u.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(mU,{className:`max-md:grid-cols-1`,title:(0,h.jsx)(J4,{name:e.name,maxLength:120,onSelect:()=>j(e.id),onRename:async t=>{let n=await Kq(i,e.id,t);return await a.invalidateQueries({queryKey:Lq}),n}}),selected:e.id===ne,meta:(0,h.jsxs)(h.Fragment,{children:[d(e)===void 0?``:`${d(e)} · `,`Version `,e.version,` · updated`,` `,(0,h.jsx)(`time`,{dateTime:e.updatedAt,children:e.updatedAt.slice(0,10)})]}),actions:(0,h.jsx)(z4,{name:e.name,edit:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,onClick:()=>j(e.id),children:`Edit`}),duplicate:(0,h.jsx)(R,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:S,disabledReason:`Working on the last press`,onClick:()=>void le(()=>fe(e)),children:`Duplicate`}),play:{run:()=>void le(()=>de(e)),blocked:r?`A run is still starting in Play. Wait for it, then use the template.`:S?`Working on the last press`:void 0},onHistory:()=>M(e),onDelete:()=>{te(e),T(null)}})}),(0,h.jsx)(c0,{kind:`template`,id:e.id,name:e.name})]},e.id))}),detail:(0,h.jsx)(jSe,{template:u.find(e=>e.id===ne)})}):null,(0,h.jsxs)(YP,{open:D,title:`Save a setup`,width:`narrow`,onClose:()=>O(!1),footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Q1,{tone:w?`error`:`info`,children:w??(S?`Saving…`:void 0)}),(0,h.jsx)(R,{type:`submit`,form:`save-template-form`,variant:`primary`,disabled:S||!p||!v.trim(),children:`Save template`})]}),children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[`Choose a saved Play draft, or`,` `,(0,h.jsx)(ha,{to:`/play`,className:`text-accent-ink underline`,children:`open Play`}),` `,`to prepare one.`]}),(0,h.jsx)(`p`,{className:`mb-4 text-small text-ink-2`,children:`A template keeps the settings, not one video's topic.`}),(0,h.jsxs)(`form`,{id:`save-template-form`,"aria-label":`Save a setup`,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),p&&v.trim()&&le(ue)},children:[(0,h.jsx)(xV,{label:`Saved Play draft`,tip:`templates.save.draft`,help:f.isPending?`Loading saved drafts…`:f.data?.length===0?`No saved drafts yet.`:void 0,children:(0,h.jsxs)(TV,{value:p,required:!0,disabled:S,onChange:e=>g(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Choose a draft`}),f.data?.filter(e=>e.readable).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.title||`Untitled draft`},e.id))]})}),f.error?(0,h.jsx)(SI,{tone:`danger`,title:`The saved drafts couldn't be loaded.`,actions:(0,h.jsx)(R,{size:`small`,onClick:()=>void f.refetch(),children:`Reload drafts`}),children:f.error.message}):null,(0,h.jsx)(xV,{label:`Template name`,id:`template-name`,tip:`templates.save.name`,children:(0,h.jsx)(CV,{value:v,required:!0,maxLength:120,disabled:S,onChange:e=>y(e.target.value)})}),(0,h.jsx)(xV,{label:`Channel`,id:`template-channel`,tip:`templates.save.channel`,children:(0,h.jsxs)(TV,{value:b,disabled:S,onChange:e=>x(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`The draft's channel`}),(s.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]})]}),re===null?null:(0,h.jsx)(MSe,{template:re,onClose:()=>M(null)},`${re.id}:${String(re.version)}`),(0,h.jsx)(jy,{open:ee!==null,title:`Delete ${ee?.name??`template`}?`,consequence:w??`Moves it to the trash for 30 days (Settings → Trash). Existing projects and drafts keep their setup.`,confirmLabel:`Delete template`,pending:S,onConfirm:()=>void le(pe),onCancel:()=>{S||te(null)}})]})}function PSe({page:e,anchor:t,words:n}){let{api:r}=z(),i=N(NB(r)),a=N(PB(r,e)),o=Zi(),[s,c]=(0,m.useState)(n??``);(0,m.useEffect)(()=>{c(n??``)},[n]);let l=(0,m.useRef)(null),u=(0,m.useMemo)(()=>new Set((i.data?.pages??[]).map(e=>e.id)),[i.data]),d=i.data?.pages.find(t=>t.id===e)?.title??e.replace(/-/g,` `),f=(0,m.useMemo)(()=>yb(a.data??``),[a.data]),p=(0,m.useMemo)(()=>a.data===void 0?``:vb(f.body,u,e),[a.data,f.body,u,e]);(0,m.useEffect)(()=>{if(p===``)return;let e=l.current;if(e===null)return;let n=t===void 0?void 0:xb(e,t,f.title===void 0?[]:[f.title]);n===void 0?window.scrollTo?.({top:0}):n.scrollIntoView?.({block:`start`})},[p,t,f.title]);let g=i.data?.groups.find(t=>t.pages.some(t=>t.id===e));return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{crumb:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Help`}),(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`›`}),(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:i.data?.home.id??`Home`},children:`Tutorials`})]}),title:d,meta:g===void 0?`Guides to every screen of Slopify, for the version you are running.`:g.title}),(0,h.jsx)(Aq,{className:`sl-workspace--tutorials`,sections:(0,h.jsx)(FSe,{index:i.data,page:e,onOpenHit:(e,t)=>{o({to:`/help/tutorials/$page`,params:{page:e.page},search:{q:t},...e.anchor===``?{}:{hash:e.anchor}})}}),children:a.error===null?(0,h.jsxs)(`div`,{ref:l,onClick:e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey)return;let t=e.target.closest(`a`),n=t?.getAttribute(`href`);if(t===null||n==null)return;let r=bb(n);if(r!==void 0){e.preventDefault(),o({to:`/help/tutorials/$page`,params:{page:r.page},...r.anchor===void 0?{}:{hash:r.anchor}});return}/^https?:/.test(n)&&(e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`))},children:[(0,h.jsx)(CB,{markdown:p,label:`Tutorial`,what:`tutorial`,query:s,onQuery:c,anchorPrefix:`tutorial-`,children:(0,h.jsx)(`p`,{className:`m-0 text-ink-3`,children:`Loading the tutorial…`})}),i.data?.footer?(0,h.jsx)(`p`,{className:`mt-8 border-t border-line pt-4 text-small text-ink-3`,children:i.data.footer.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`)}):null]}):(0,h.jsx)(SI,{tone:`danger`,title:`This tutorial did not load`,actions:(0,h.jsx)(R,{onClick:()=>void a.refetch(),variant:`secondary`,children:`Try again`}),children:`${a.error.message} Press Try again, or pick another page on the left.`})})]})}function FSe({index:e,page:t,onOpenHit:n}){let{api:r}=z(),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),c=(0,m.useRef)(null),l=(0,m.useId)();xx(c,`the tutorials`),(0,m.useEffect)(()=>{let e=setTimeout(()=>s(i.trim()),200);return()=>clearTimeout(e)},[i]);let u=N(FB(r,o));return(0,h.jsxs)(`nav`,{"aria-label":`Tutorials`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(`label`,{htmlFor:l,className:`sr-only`,children:`Search all tutorials`}),(0,h.jsx)(Ic,{"aria-hidden":`true`,strokeWidth:1.75,className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3`}),(0,h.jsx)(`input`,{ref:c,id:l,type:`search`,value:i,placeholder:`Search all tutorials`,onChange:e=>a(e.target.value),onKeyDown:e=>{let t=u.data?.hits[0];e.key===`Enter`&&t!==void 0&&(e.preventDefault(),n(t,o))},className:`sl-input pl-9`})]}),o===``?e===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the tutorials…`}):(0,h.jsxs)(`div`,{className:`sl-tutorials-nav flex flex-col gap-4`,children:[(0,h.jsx)(O9,{id:e.home.id,title:e.home.title,current:t}),e.groups.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,h.jsx)(`div`,{className:`sl-kicker px-2.5 pb-1`,children:e.title}),e.pages.map(e=>(0,h.jsx)(O9,{id:e.id,title:e.title,current:t},e.id))]},e.title))]}):(0,h.jsx)(ISe,{query:o,hits:u.data?.hits,error:u.error?.message})]})}function O9({id:e,title:t,current:n}){return(0,h.jsx)(ha,{to:`/help/tutorials/$page`,params:{page:e},"aria-current":e===n?`page`:void 0,className:`sl-tutorials-nav__link`,children:t})}function ISe({query:e,hits:t,error:n}){return n===void 0?t===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Searching…`}):t.length===0?(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:`No tutorial mentions "${e}". Try fewer or other words.`}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{role:`status`,className:`m-0 px-2.5 text-small text-ink-3`,children:t.length===1?`1 section`:`${String(t.length)} sections`}),(0,h.jsx)(`ul`,{"aria-label":`Search results`,className:`m-0 flex list-none flex-col gap-1 p-0`,children:t.map(t=>(0,h.jsx)(`li`,{children:(0,h.jsxs)(ha,{to:`/help/tutorials/$page`,params:{page:t.page},search:{q:e},...t.anchor===``?{}:{hash:t.anchor},className:`sl-tutorials-hit`,children:[(0,h.jsx)(`span`,{className:`block font-semibold text-ink`,children:t.heading===void 0?t.pageTitle:t.heading}),t.heading===void 0?null:(0,h.jsx)(`span`,{className:`block text-label text-ink-3`,children:t.pageTitle}),(0,h.jsx)(`span`,{className:`mt-0.5 block text-small text-ink-2`,children:t.snippet})]})},`${t.page}#${t.anchor}`))})]}):(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The search didn't run: ${n} Change the words or reload the page.`})}var LSe=[{id:`library`,name:`The Library of Alexandria`,summary:`A narrated video with its two shorts, article, PDF, description and images.`,action:`Explore the sample`},{id:`audiobook`,name:`The Wind in the Willows`,summary:`An audiobook: a narrator and two character voices, captions tagged with who speaks, MP3 and M4B with chapters.`,action:`See an audiobook`},{id:`podcast`,name:`The Antikythera Mechanism`,summary:`A two-host podcast with the speaker panel, name tags and portraits, and its MP3 and M4B.`,action:`Hear a podcast`}],k9=[{id:`found`,label:`1 · What you have`},{id:`style`,label:`2 · Pick a style`},{id:`make`,label:`3 · Make your first short`}];function RSe(e){return e.length<=2?e.join(` or `):`${e.slice(0,-1).join(`, `)} or ${e.at(-1)??``}`}function zSe(e){return e===void 0?{ready:!1,text:`Looking for a voice…`}:e.keyed===null?e.system.available?{ready:!0,text:`Narration uses your computer's built-in voice${e.system.engine===null?``:` (${e.system.engine})`}; add an ElevenLabs or OpenAI key later for a better one.`}:{ready:!1,text:e.system.issue??`No voice can narrate yet. Add an ElevenLabs or OpenAI key in Settings → Providers.`}:{ready:!0,text:`Narration uses your ${e.keyed} voice key.`}}function BSe(){let{api:e}=z(),t=_(),n=Zi(),r=N({queryKey:My,queryFn:()=>Iy(e)}),[i,a]=(0,m.useState)(`found`),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(void 0),f=(0,m.useRef)(void 0),p=P({mutationFn:()=>Ly(e),onSuccess:async()=>{await t.invalidateQueries({queryKey:My}),await n({to:`/`})}}),g=P({mutationFn:t=>Ry(e,t),onSettled:()=>t.invalidateQueries({queryKey:My})}),v=P({mutationFn:()=>(f.current??=crypto.randomUUID(),zy(e,{topic:o,requestId:f.current,...c===``?{}:{packId:c}})),onSuccess:async({projectId:e})=>{f.current=void 0,d(e),await t.invalidateQueries({queryKey:B.projects}),await t.invalidateQueries({queryKey:B.voices})}}),y=e=>{e.preventDefault(),o.trim()!==``&&v.mutate()},b=r.data,x=b?.clis.filter(e=>e.ready)??[],S=zSe(b?.voice),C=c===``?`General`:b?.packs.find(e=>e.id===c)?.name??c,w=v.error?{tone:`error`,text:v.error.message}:g.error?{tone:`error`,text:g.error.message}:p.error?{tone:`error`,text:p.error.message}:v.isPending?{tone:`info`,text:`Starting your short…`}:void 0,T=k9.findIndex(e=>e.id===i),E=k9[T+1],D=k9[T-1];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(kq,{title:`Welcome to Slopify`,meta:`Make a video from a topic, with the tools already on this computer.`,actions:(0,h.jsx)(R,{variant:`quiet`,disabled:p.isPending,onClick:()=>p.mutate(),children:u===void 0?`Skip`:`Done`})}),r.error?(0,h.jsx)(SI,{tone:`danger`,title:`Could not read what this computer has`,className:`mb-6`,children:r.error.message}):null,(0,h.jsx)(r0,{items:k9.map(e=>({id:e.id,label:e.label})),value:i,onChange:a,label:`First-run steps`,idPrefix:`welcome`,className:`mb-6`}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`found`,active:i===`found`,children:[(0,h.jsx)(H,{title:`Found on this computer`,info:`welcome.found`}),(0,h.jsxs)(pU,{label:`Tools found on this computer`,className:`mb-4`,children:[(b?.clis??[]).map(e=>(0,h.jsx)(mU,{title:e.name,actions:(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.ready?`Ready${e.version===null?``:` · ${e.version}`}${e.draws?` · writes and draws`:` · writes`}`:e.installed?e.issue??`Installed, not usable yet`:`Not found`})},e.id)),b===void 0?(0,h.jsx)(mU,{title:`Looking for installed tools…`}):null]}),b!==void 0&&x.length>0?(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:`You can make a video now: no API keys are needed for ${RSe([`the text`,...x.some(e=>e.draws)?[`the images`]:[],...S.ready&&b.voice.keyed===null?[`the narration`]:[]])}.`}):null,b!==void 0&&x.length===0?(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`Nothing on this computer can write the script yet.`,actions:(0,h.jsx)(fS,{to:`/settings`,search:{section:`providers`},children:`Open Settings → Providers`}),children:`Install Claude Code, Codex or Gemini CLI and sign in to it, then press Check again; or add an OpenRouter key in Settings → Providers.`}):null,(0,h.jsx)(H,{title:`Narration voice`,info:`welcome.voice`}),b===void 0?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6`,children:(0,h.jsx)(mU,{title:`Looking for a voice…`})}):(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`style`,active:i===`style`,children:[(0,h.jsx)(H,{title:`Pick a style`,info:`welcome.pack`}),(0,h.jsx)(pU,{label:`Styles`,className:`mb-3 [&_.sl-row__meta]:whitespace-normal`,children:[{id:``,name:`General`,summary:`A neutral explainer style.`,installed:!1,library:!1},...(b?.packs??[]).map(e=>({...e,library:!0}))].map(e=>(0,h.jsx)(mU,{title:e.name,meta:e.summary,selected:c===e.id,actions:(0,h.jsxs)(h.Fragment,{children:[e.library?(0,h.jsx)(R,{variant:`quiet`,disabled:e.installed||g.isPending,"aria-label":e.installed?`${e.name} is in your library`:`Add ${e.name} to library`,onClick:()=>g.mutate(e.id),children:e.installed?`In your library`:`Add to library`}):null,(0,h.jsx)(R,{variant:c===e.id?`primary`:`secondary`,"aria-pressed":c===e.id,"aria-label":`Use ${e.name}`,onClick:()=>l(e.id),children:c===e.id?`Picked`:`Use this style`})]})},e.id===``?`general`:e.id))}),(0,h.jsxs)(`p`,{className:`mb-6 flex items-center gap-1 text-small text-ink-2`,...Ob,children:[`Add to library keeps a pack's prompts and Play template for later videos.`,(0,h.jsx)(V,{id:`welcome.packs`,className:`-my-1`})]})]}),(0,h.jsxs)(i0,{idPrefix:`welcome`,id:`make`,active:i===`make`,children:[u===void 0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{title:`Make a 60-second short`,info:`welcome.short`}),(0,h.jsxs)(`p`,{className:`mb-3 text-small text-ink-2`,children:[`Style: ${C}. `,S.text]}),S.ready||b===void 0?null:(0,h.jsx)(`div`,{className:`mb-4`,children:(0,h.jsx)(A9,{voice:S,checking:r.isFetching,onCheck:()=>void r.refetch()})}),(0,h.jsxs)(`form`,{onSubmit:y,className:`mb-6 flex flex-wrap items-end gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[240px] flex-1 flex-col gap-1`,...Ob,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:`welcome-topic`,className:`text-label text-ink-2`,children:`Topic`}),(0,h.jsx)(V,{id:`welcome.topic`,className:`-my-1`})]}),(0,h.jsx)(R3,{id:`welcome-topic`,value:o,maxLength:200,placeholder:`Why the sea glows at night`,onChange:e=>s(e.target.value)})]}),(0,h.jsx)(R,{type:`submit`,variant:`primary`,disabled:o.trim()===``||v.isPending,disabledReason:`Type a topic first.`,children:`Make a 60-second short`})]})]}):(0,h.jsx)(SI,{tone:`info`,className:`mb-6`,title:`Your short is being made.`,actions:(0,h.jsx)(fS,{variant:`primary`,to:`/projects/$projectId`,params:{projectId:u},children:`Watch it being made`}),children:`It usually takes about five minutes. The live view shows each step as it runs; while you wait, look at a sample or set Slopify to start when you log in.`}),(0,h.jsx)(H,{title:`While you wait: the samples`,info:`welcome.samples`}),(0,h.jsx)(pU,{label:`Samples`,className:`mb-6 [&_.sl-row__meta]:whitespace-normal`,children:LSe.map(e=>{let t=b?.samples[e.id]??null;return(0,h.jsx)(mU,{title:e.name,meta:e.summary,actions:t===null?(0,h.jsx)(pS,{to:`/settings`,search:{section:`storage`},children:`Restore samples in Settings`}):(0,h.jsx)(fS,{to:`/projects/$projectId`,params:{projectId:t},className:fU,children:e.action})},e.id)})}),(0,h.jsx)(Vb,{})]}),(0,h.jsxs)($1,{status:(0,h.jsx)(Q1,{tone:w?.tone??`info`,children:w?.text}),children:[(0,h.jsx)(pS,{to:`/play`,children:`Set up a long video instead`}),D===void 0?null:(0,h.jsx)(R,{onClick:()=>a(D.id),children:`Back`}),E===void 0?null:(0,h.jsx)(R,{variant:`primary`,onClick:()=>a(E.id),children:`Next: ${E.label.replace(/^\d · /,``)}`})]})]})}function A9({voice:e,checking:t,onCheck:n}){return e.ready?(0,h.jsx)(pU,{label:`Narration voice`,className:`mb-6 [&_.sl-row__title]:whitespace-normal`,children:(0,h.jsx)(mU,{lead:(0,h.jsx)(gS,{tone:`done`}),title:e.text,actions:(0,h.jsx)(fS,{variant:`quiet`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`})})}):(0,h.jsx)(SI,{tone:`waiting`,className:`mb-6`,title:`No voice can narrate the short yet.`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(fS,{variant:`primary`,to:`/settings`,search:{section:`providers`},children:`Add a voice key`}),(0,h.jsx)(R,{disabled:t,onClick:n,children:t?`Checking…`:`Check again`})]}),children:e.text})}var j9=ba({component:eV}),VSe=va({getParentRoute:()=>j9,path:`/`,component:Ime}),M9=va({getParentRoute:()=>j9,path:`projects`,validateSearch:e=>{let t=Xbe(e.show);return t===void 0?{}:{show:t}},component:HSe});function HSe(){let{show:e}=M9.useSearch();return(0,h.jsx)($be,{initialFilter:e??`all`},e??`all`)}var USe=va({getParentRoute:()=>j9,path:`welcome`,component:BSe}),WSe=va({getParentRoute:()=>j9,path:`play`,component:jge}),N9=va({getParentRoute:()=>j9,id:`_library`,component:Wpe}),GSe=va({getParentRoute:()=>j9,path:`library`,beforeLoad:()=>{throw dn({to:`/prompts`,search:{kind:`article`}})}}),KSe=va({getParentRoute:()=>j9,path:`channels`,component:xpe}),P9=va({getParentRoute:()=>j9,path:`channels/$channelId`,validateSearch:e=>e.tab===void 0?{}:{tab:ype(e.tab)},component:qSe});function qSe(){let{channelId:e}=P9.useParams(),{tab:t}=P9.useSearch(),n=Zi();return(0,h.jsx)(bpe,{channelId:e,tab:t??`brand`,onTab:t=>{n({to:`/channels/$channelId`,params:{channelId:e},search:{tab:t},replace:!0})}},e)}var JSe=va({getParentRoute:()=>N9,path:`templates`,component:$Se}),YSe=/^[0-9A-Za-z-]{1,64}$/;function F9(e){return Ife(e.tab)===`schedules`?typeof e.schedule==`string`&&YSe.test(e.schedule)?{tab:`schedules`,schedule:e.schedule}:{tab:`schedules`}:{}}var I9=va({getParentRoute:()=>j9,path:`calendar`,validateSearch:F9,component:QSe}),XSe=va({getParentRoute:()=>j9,path:`schedules`,beforeLoad:()=>{throw dn({to:`/calendar`,search:{tab:`schedules`},replace:!0})}}),ZSe=va({getParentRoute:()=>j9,path:`schedules/$scheduleId`,beforeLoad:({params:e})=>{throw dn({to:`/calendar`,search:F9({tab:`schedules`,schedule:e.scheduleId}),replace:!0})}});function QSe(){let e=F9(I9.useSearch()),t=Zi();return(0,h.jsx)(Rfe,{tab:e.tab??`weeks`,schedule:e.schedule,onTab:e=>{t({to:`/calendar`,search:e===`schedules`?{tab:`schedules`}:{},replace:!0})},onSchedule:e=>{t({to:`/calendar`,search:{tab:`schedules`,schedule:e},replace:!0})}})}function $Se(){let e=rP(),t=Zi();return(0,h.jsx)(NSe,{getGeneration:e.generation,blocked:e.review.starting||e.review.uncertain||e.review.created!==null,beforeApply:e.flush,onApplied:async(n,r)=>!r()||!await e.open(n,r)||!r()?!1:(await t({to:`/play`}),r())})}var L9=va({getParentRoute:()=>j9,path:`projects/$projectId`,component:cCe}),R9=va({getParentRoute:()=>N9,path:`prompts`,validateSearch:e=>({kind:vV(e.kind)}),component:lCe}),z9=va({getParentRoute:()=>j9,path:`prompts/new`,validateSearch:e=>{let t=vV(e.kind);return typeof e.from==`string`?{kind:t,from:e.from}:{kind:t}},component:uCe}),B9=va({getParentRoute:()=>j9,path:`prompts/$promptId`,component:dCe}),V9=va({getParentRoute:()=>N9,path:`entries`,validateSearch:e=>({category:hV(e.category)}),component:fCe}),H9=va({getParentRoute:()=>j9,path:`entries/new`,validateSearch:e=>{let t=hV(e.category);return typeof e.from==`string`?{category:t,from:e.from}:{category:t}},component:pCe}),U9=va({getParentRoute:()=>j9,path:`entries/$entryId`,component:mCe}),eCe=va({getParentRoute:()=>N9,path:`narration-aliases`,component:Rme}),tCe=va({getParentRoute:()=>N9,path:`document-themes`,component:Kpe}),W9=va({getParentRoute:()=>j9,path:`document-themes/new`,validateSearch:e=>typeof e.from==`string`?{from:e.from}:{},component:hCe}),G9=va({getParentRoute:()=>j9,path:`document-themes/$themeId`,component:gCe});function nCe(e){let t=e.section===void 0?void 0:xSe(e.section),n=t===`patch-notes`&&typeof e.note==`string`&&/^[0-9A-Za-z][0-9A-Za-z.-]{0,63}$/.test(e.note)?e.note:void 0;return{...t===void 0?{}:{section:t},...n===void 0?{}:{note:n}}}var K9=va({getParentRoute:()=>j9,path:`settings`,validateSearch:nCe,component:sCe}),q9=va({getParentRoute:()=>j9,path:`help/tutorials/$page`,validateSearch:e=>typeof e.q==`string`&&e.q.trim()!==``?{q:e.q.slice(0,200)}:{},component:rCe});function rCe(){let{page:e}=q9.useParams(),{q:t}=q9.useSearch(),n=Ha({select:e=>e.hash});return(0,h.jsx)(PSe,{page:e,anchor:n===``?void 0:n,words:t})}var iCe=va({getParentRoute:()=>j9,path:`help`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),aCe=va({getParentRoute:()=>j9,path:`help/tutorials`,beforeLoad:()=>{throw dn({to:`/help/tutorials/$page`,params:{page:`Home`}})}}),oCe=va({getParentRoute:()=>j9,path:`usage`,beforeLoad:()=>{throw dn({to:`/settings`,search:{section:`usage`}})}});function sCe(){let{section:e,note:t}=K9.useSearch(),n=Zi();return(0,h.jsx)(CSe,{section:e??`providers`,note:t,onSection:e=>{n({to:`/settings`,search:{section:e},replace:!0})},onNote:e=>{n({to:`/settings`,search:{section:`patch-notes`,...e===void 0?{}:{note:e}}})}})}function cCe(){let{projectId:e}=L9.useParams(),t=rP(),n=Zi();return(0,h.jsx)(Wbe,{projectId:e,openDraft:async e=>!await t.flush()||!await t.open(e)?!1:(await n({to:`/play`}),!0)},e)}function lCe(){let{kind:e}=R9.useSearch(),t=Zi(),n=J9();return(0,h.jsx)(ixe,{kind:e,onKind:e=>{t({to:`/prompts`,search:{kind:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function J9(){let e=rP(),t=Zi();return{blocked:e.review.starting||e.review.uncertain||e.review.created!==null?`Play is starting a run from its draft. Wait for it to start, then try again.`:void 0,use:n=>{let r=ZV(e.document,n);e.edit(r.document),t({to:`/play`}).then(()=>e.navigate(r.section,r.field))}}}function uCe(){let{kind:e,from:t}=z9.useSearch(),n=Y9();return(0,h.jsx)(J7,{promptId:void 0,kind:e,from:t,onLeave:n},`${e}:${t??`new`}`)}function dCe(){let{promptId:e}=B9.useParams(),t=Y9();return(0,h.jsx)(J7,{promptId:e,kind:`article`,from:void 0,onLeave:t},e)}function Y9(){let e=Zi();return t=>{e({to:`/prompts`,search:{kind:t}})}}function fCe(){let{category:e}=V9.useSearch(),t=Zi(),n=J9();return(0,h.jsx)(qpe,{category:e,onCategory:e=>{t({to:`/entries`,search:{category:e},replace:!0})},onUseInPlay:n.use,playBlocked:n.blocked})}function pCe(){let{category:e,from:t}=H9.useSearch(),n=Z9();return(0,h.jsx)(c3,{entryId:void 0,category:e,from:t,onLeave:n})}function mCe(){let{entryId:e}=U9.useParams(),t=Z9();return(0,h.jsx)(c3,{entryId:e,category:`intro`,from:void 0,onLeave:t})}function hCe(){let{from:e}=W9.useSearch(),t=X9();return(0,h.jsx)(_4,{themeId:void 0,from:e,onLeave:t})}function gCe(){let{themeId:e}=G9.useParams(),t=X9();return(0,h.jsx)(_4,{themeId:e,from:void 0,onLeave:t})}function X9(){let e=Zi();return()=>{e({to:`/document-themes`})}}function Z9(){let e=Zi();return t=>{e({to:`/entries`,search:{category:t}})}}var _Ce=j9.addChildren({homeRoute:VSe,projectsRoute:M9,welcomeRoute:USe,playRoute:WSe,libraryRoute:N9.addChildren({promptsRoute:R9,entriesRoute:V9,templatesRoute:JSe,documentThemesRoute:tCe,narrationAliasesRoute:eCe}),schedulesRoute:XSe,scheduleRoute:ZSe,calendarRoute:I9,libraryIndexRoute:GSe,channelsRoute:KSe,channelRoute:P9,projectRoute:L9,newPromptRoute:z9,promptRoute:B9,newEntryRoute:H9,entryRoute:U9,newDocumentThemeRoute:W9,documentThemeRoute:G9,settingsRoute:K9,usageRoute:oCe,helpRoute:iCe,tutorialsIndexRoute:aCe,tutorialsRoute:q9});function vCe(){return La({routeTree:_Ce})}function yCe(){let e,t,n=new Set;return{observe:r=>{if(e===void 0){e=r;for(let e of n)e();return}if(r!==e&&r!==t){t=r;for(let e of n)e()}},staleAt:()=>t,loadedAt:()=>e,subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function bCe(e,t){return async(n,r)=>{let i=await e(n,r),a=i.headers.get(`X-Slopify-Version`);return a!==null&&t.observe(a),i}}function xCe(){let e=new Map;return{observe:t=>{if(t.type===`stage.state`){let n=e.get(t.projectId);if(n){for(let[e,r]of n)r.stage===t.stage&&r.revisionId===t.revisionId&&r.workId===t.workId&&n.delete(e);n.size===0&&e.delete(t.projectId)}return}if(t.type!==`llm.preview`)return;let n=e.get(t.projectId)??new Map,r=JSON.stringify([t.revisionId,t.workId,t.callId]),i=n.get(r),a=(t.reset?t.text:`${i?.text??``}${t.text}`).slice(-65536);for(n.delete(r),n.set(r,{...t,text:a,reset:!0});n.size>8;){let e=n.keys().next().value;e!==void 0&&n.delete(e)}for(e.delete(t.projectId),e.set(t.projectId,n);e.size>16;){let t=e.keys().next().value;t!==void 0&&e.delete(t)}},snapshot:t=>[...e.get(t)?.values()??[]],snapshotAll:()=>[...e.values()].flatMap(e=>[...e.values()])}}var Q9=/\/events\/projects\/([^/?#]+)/,SCe=/\/events\/global(?:[?#]|$)/,CCe=[`running.count`,`staging.progress`,`staging.failed`,`schedule.topics`,`stage.state`,`stage.progress`,`article.delta`,`llm.preview`,`image.landed`,`narration.piece`,`project.state`,`project.updated`,`review.flagged`];function wCe(e){let t=new Set,n=xCe(),r,i=!1,a=(e,t,n)=>{for(let r of e.listeners.get(t)??[])r({data:n})},o=o=>{if(r!==void 0)return;let s=e(o);r=s,s.addEventListener(`open`,()=>{i=!0;for(let e of[...t])for(let t of e.opens)t()});for(let e of CCe)s.addEventListener(e,r=>{let i;try{let t=JSON.parse(r.data);typeof t.projectId==`string`&&(i=t.projectId),(e===`llm.preview`||e===`stage.state`)&&n.observe(t)}catch{return}for(let n of[...t])(n.projectId===void 0||n.projectId===i)&&a(n,e,r.data)})};return s=>{let c=Q9.exec(s)?.[1];if(c===void 0&&!SCe.test(s))return e(s);o(c===void 0?s:s.replace(Q9,`/events/global`));let l={projectId:c===void 0?void 0:decodeURIComponent(c),listeners:new Map,opens:new Set};return t.add(l),i&&queueMicrotask(()=>{if(t.has(l)){for(let e of l.opens)e();if(l.projectId!==void 0)for(let e of n.snapshot(l.projectId))a(l,`llm.preview`,JSON.stringify(e))}}),{addEventListener:(e,t)=>{if(e===`open`){l.opens.add(t);return}let n=l.listeners.get(e)??new Set;n.add(t),l.listeners.set(e,n)},close:()=>{t.delete(l),t.size===0&&r!==void 0&&(r.close(),r=void 0,i=!1)}}}}function TCe(e){let t=yCe(),n={api:Co(window.location.origin,bCe(window.fetch.bind(window),t),To(e=>{let n=e.headers.get(`X-Slopify-Version`);n!==null&&t.observe(n)})),openEvents:wCe(e=>new EventSource(e)),version:t};(0,co.createRoot)(e).render((0,h.jsx)(m.StrictMode,{children:(0,h.jsx)(v,{client:new Je,children:(0,h.jsx)(ste,{deps:n,children:(0,h.jsx)(Ba,{router:vCe()})})})}))}var $9=document.getElementById(`root`);if($9===null)throw Error(`index.html carries no #root element for the app to mount on`);TCe($9);export{t4 as t};