@gentbajko/slopify 3.11.0 → 3.11.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.
- package/dist/extension/slopify-studio-chrome.zip +0 -0
- package/dist/extension/slopify-studio-firefox.zip +0 -0
- package/dist/kernel/db/migrations/0053-local-work-times.sql +14 -0
- package/dist/patch-notes/3.11.1.md +8 -0
- package/dist/patch-notes/3.11.2.md +5 -0
- package/dist/patch-notes/index.json +12 -0
- package/dist/slices/document/fonts.js +5 -1
- package/dist/slices/document/pages.js +20 -7
- package/dist/slices/document/sources.js +93 -1
- package/dist/slices/rebuild/recipe-audio.js +27 -4
- package/dist/slices/rebuild/recipe-save.js +6 -4
- package/dist/slices/rebuild/recipe-text.js +4 -3
- package/dist/slices/rebuild/runtime-run.js +25 -0
- package/dist/slices/run-cost/timing.js +7 -2
- package/dist/slices/storage/backup-format.js +2 -0
- package/dist/web/assets/{index-CASczIQ9.js → index-CmQ2so2R.js} +2 -2
- package/dist/web/assets/{pdf-DWBP2BjM.js → pdf-B0AMuc3F.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
|
@@ -271,7 +271,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
271
271
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _(e,t){if(t&&(typeof t==`object`||typeof t==`function`))return t;if(t!==void 0)throw TypeError(`Derived constructors may only return object or undefined`);return i(e)}function v(e,t){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},v(e,t)}function y(e,t){return r(e)||h(e,t)||C(e,t)||g()}function b(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function x(e){var t=b(e,`string`);return typeof t==`symbol`?t:t+``}function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function C(e,t){if(e){if(typeof e==`string`)return n(e,t);var r={}.toString.call(e).slice(8,-1);return r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`?Array.from(e):r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function w(e){var t=typeof Map==`function`?new Map:void 0;return w=function(e){function n(){return s(e,arguments,d(this).constructor)}if(e===null||!p(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,n)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),v(n,e)},w(e)}var T=function(e){var t=Math.abs,n=Math.max,r=Math.floor;function i(e,t){var n;if(o(this,i),n=a(this,i,[e]),n.sign=t,Object.setPrototypeOf(n,i.prototype),e>i.__kMaxLength)throw RangeError(`Maximum BigInt size exceeded`);return n}return f(i,e),l(i,[{key:`toDebugString`,value:function(){var e,t=[`BigInt[`],n=u(this);try{for(n.s();!(e=n.n()).done;){var r=e.value;t.push((r&&(r>>>0).toString(16))+`, `)}}catch(e){n.e(e)}finally{n.f()}return t.push(`]`),t.join(``)}},{key:`toString`,value:function(){var e=0<arguments.length&&arguments[0]!==void 0?arguments[0]:10;if(2>e||36<e)throw RangeError(`toString() radix argument must be between 2 and 36`);return this.length===0?`0`:e&e-1?i.__toStringGeneric(this,e,!1):i.__toStringBasePowerOfTwo(this,e)}},{key:`valueOf`,value:function(){throw Error("Convert JSBI instances to native numbers using `toNumber`.")}},{key:`__copy`,value:function(){for(var e=new i(this.length,this.sign),t=0;t<this.length;t++)e[t]=this[t];return e}},{key:`__trim`,value:function(){for(var e=this.length,t=this[e-1];t===0;)e--,t=this[e-1],this.pop();return e===0&&(this.sign=!1),this}},{key:`__initializeDigits`,value:function(){for(var e=0;e<this.length;e++)this[e]=0}},{key:`__clzmsd`,value:function(){return i.__clz30(this.__digit(this.length-1))}},{key:`__inplaceMultiplyAdd`,value:function(e,t,n){n>this.length&&(n=this.length);for(var r=32767&e,a=e>>>15,o=0,s=t,c=0;c<n;c++){var l=this.__digit(c),u=32767&l,d=l>>>15,f=i.__imul(u,r),p=i.__imul(u,a),m=i.__imul(d,r),h=i.__imul(d,a),g=s+f+o;o=g>>>30,g&=1073741823,g+=((32767&p)<<15)+((32767&m)<<15),o+=g>>>30,s=h+(p>>>15)+(m>>>15),this.__setDigit(c,1073741823&g)}if(o!==0||s!==0)throw Error(`implementation bug`)}},{key:`__inplaceAdd`,value:function(e,t,n){for(var r,i=0,a=0;a<n;a++)r=this.__halfDigit(t+a)+e.__halfDigit(a)+i,i=r>>>15,this.__setHalfDigit(t+a,32767&r);return i}},{key:`__inplaceSub`,value:function(e,t,n){var r=n-1>>>1,i=0;if(1&t){t>>=1;for(var a=this.__digit(t),o=32767&a,s=0;s<r;s++){var c=e.__digit(s),l=(a>>>15)-(32767&c)-i;i=1&l>>>15,this.__setDigit(t+s,(32767&l)<<15|32767&o),a=this.__digit(t+s+1),o=(32767&a)-(c>>>15)-i,i=1&o>>>15}var u=e.__digit(s),d=(a>>>15)-(32767&u)-i;i=1&d>>>15,this.__setDigit(t+s,(32767&d)<<15|32767&o);var f=u>>>15;if(t+s+1>=this.length)throw RangeError(`out of bounds`);!(1&n)&&(a=this.__digit(t+s+1),o=(32767&a)-f-i,i=1&o>>>15,this.__setDigit(t+e.length,1073709056&a|32767&o))}else{t>>=1;for(var p=0;p<e.length-1;p++){var m=this.__digit(t+p),h=e.__digit(p),g=(32767&m)-(32767&h)-i;i=1&g>>>15;var _=(m>>>15)-(h>>>15)-i;i=1&_>>>15,this.__setDigit(t+p,(32767&_)<<15|32767&g)}var v=this.__digit(t+p),y=e.__digit(p),b=(32767&v)-(32767&y)-i;i=1&b>>>15;var x=0;!(1&n)&&(x=(v>>>15)-(y>>>15)-i,i=1&x>>>15),this.__setDigit(t+p,(32767&x)<<15|32767&b)}return i}},{key:`__inplaceRightShift`,value:function(e){if(e!==0){for(var t,n=this.__digit(0)>>>e,r=this.length-1,i=0;i<r;i++)t=this.__digit(i+1),this.__setDigit(i,1073741823&t<<30-e|n),n=t>>>e;this.__setDigit(r,n)}}},{key:`__digit`,value:function(e){return this[e]}},{key:`__unsignedDigit`,value:function(e){return this[e]>>>0}},{key:`__setDigit`,value:function(e,t){this[e]=0|t}},{key:`__setDigitGrow`,value:function(e,t){this[e]=0|t}},{key:`__halfDigitLength`,value:function(){var e=this.length;return 32767>=this.__unsignedDigit(e-1)?2*e-1:2*e}},{key:`__halfDigit`,value:function(e){return 32767&this[e>>>1]>>>15*(1&e)}},{key:`__setHalfDigit`,value:function(e,t){var n=e>>>1,r=this.__digit(n),i=1&e?32767&r|t<<15:1073709056&r|32767&t;this.__setDigit(n,i)}}],[{key:`BigInt`,value:function(e){var t=Number.isFinite;if(typeof e==`number`){if(e===0)return i.__zero();if(i.__isOneDigitInt(e))return 0>e?i.__oneDigit(-e,!0):i.__oneDigit(e,!1);if(!t(e)||r(e)!==e)throw RangeError(`The number `+e+` cannot be converted to BigInt because it is not an integer`);return i.__fromDouble(e)}if(typeof e==`string`){var n=i.__fromString(e);if(n===null)throw SyntaxError(`Cannot convert `+e+` to a BigInt`);return n}if(typeof e==`boolean`)return!0===e?i.__oneDigit(1,!1):i.__zero();if(S(e)===`object`){if(e.constructor===i)return e;var a=i.__toPrimitive(e);return i.BigInt(a)}throw TypeError(`Cannot convert `+e+` to a BigInt`)}},{key:`toNumber`,value:function(e){var t=e.length;if(t===0)return 0;if(t===1){var n=e.__unsignedDigit(0);return e.sign?-n:n}var r=e.__digit(t-1),a=i.__clz30(r),o=30*t-a;if(1024<o)return e.sign?-1/0:1/0;var s=o-1,c=r,l=t-1,u=a+3,d=u===32?0:c<<u;d>>>=12;var f=u-12,p=12<=u?0:c<<20+u,m=20+u;for(0<f&&0<l&&(l--,c=e.__digit(l),d|=c>>>30-f,p=c<<f+2,m=f+2);0<m&&0<l;)l--,c=e.__digit(l),p|=30<=m?c<<m-30:c>>>30-m,m-=30;var h=i.__decideRounding(e,m,l,c);if((h===1||h===0&&(1&p)==1)&&(p=p+1>>>0,p===0&&(d++,d>>>20&&(d=0,s++,1023<s))))return e.sign?-1/0:1/0;var g=e.sign?-2147483648:0;return s=s+1023<<20,i.__kBitConversionInts[i.__kBitConversionIntHigh]=g|s|d,i.__kBitConversionInts[i.__kBitConversionIntLow]=p,i.__kBitConversionDouble[0]}},{key:`unaryMinus`,value:function(e){if(e.length===0)return e;var t=e.__copy();return t.sign=!e.sign,t}},{key:`bitwiseNot`,value:function(e){return e.sign?i.__absoluteSubOne(e).__trim():i.__absoluteAddOne(e,!0)}},{key:`exponentiate`,value:function(e,t){if(t.sign)throw RangeError(`Exponent must be positive`);if(t.length===0)return i.__oneDigit(1,!1);if(e.length===0)return e;if(e.length===1&&e.__digit(0)===1)return e.sign&&!(1&t.__digit(0))?i.unaryMinus(e):e;if(1<t.length)throw RangeError(`BigInt too big`);var n=t.__unsignedDigit(0);if(n===1)return e;if(n>=i.__kMaxLengthBits)throw RangeError(`BigInt too big`);if(e.length===1&&e.__digit(0)===2){var r=1+(0|n/30),a=new i(r,e.sign&&!!(1&n));a.__initializeDigits();var o=1<<n%30;return a.__setDigit(r-1,o),a}var s=null,c=e;for(1&n&&(s=e),n>>=1;n!==0;n>>=1)c=i.multiply(c,c),1&n&&(s=s===null?c:i.multiply(s,c));return s}},{key:`multiply`,value:function(e,t){if(e.length===0)return e;if(t.length===0)return t;var n=e.length+t.length;30<=e.__clzmsd()+t.__clzmsd()&&n--;var r=new i(n,e.sign!==t.sign);r.__initializeDigits();for(var a=0;a<e.length;a++)i.__multiplyAccumulate(t,e.__digit(a),r,a);return r.__trim()}},{key:`divide`,value:function(e,t){if(t.length===0)throw RangeError(`Division by zero`);if(0>i.__absoluteCompare(e,t))return i.__zero();var n,r=e.sign!==t.sign,a=t.__unsignedDigit(0);if(t.length===1&&32767>=a){if(a===1)return r===e.sign?e:i.unaryMinus(e);n=i.__absoluteDivSmall(e,a,null)}else n=i.__absoluteDivLarge(e,t,!0,!1);return n.sign=r,n.__trim()}},{key:`remainder`,value:function(e,t){if(t.length===0)throw RangeError(`Division by zero`);if(0>i.__absoluteCompare(e,t))return e;var n=t.__unsignedDigit(0);if(t.length===1&&32767>=n){if(n===1)return i.__zero();var r=i.__absoluteModSmall(e,n);return r===0?i.__zero():i.__oneDigit(r,e.sign)}var a=i.__absoluteDivLarge(e,t,!1,!0);return a.sign=e.sign,a.__trim()}},{key:`add`,value:function(e,t){var n=e.sign;return n===t.sign?i.__absoluteAdd(e,t,n):0<=i.__absoluteCompare(e,t)?i.__absoluteSub(e,t,n):i.__absoluteSub(t,e,!n)}},{key:`subtract`,value:function(e,t){var n=e.sign;return n===t.sign?0<=i.__absoluteCompare(e,t)?i.__absoluteSub(e,t,n):i.__absoluteSub(t,e,!n):i.__absoluteAdd(e,t,n)}},{key:`leftShift`,value:function(e,t){return t.length===0||e.length===0?e:t.sign?i.__rightShiftByAbsolute(e,t):i.__leftShiftByAbsolute(e,t)}},{key:`signedRightShift`,value:function(e,t){return t.length===0||e.length===0?e:t.sign?i.__leftShiftByAbsolute(e,t):i.__rightShiftByAbsolute(e,t)}},{key:`unsignedRightShift`,value:function(){throw TypeError(`BigInts have no unsigned right shift; use >> instead`)}},{key:`lessThan`,value:function(e,t){return 0>i.__compareToBigInt(e,t)}},{key:`lessThanOrEqual`,value:function(e,t){return 0>=i.__compareToBigInt(e,t)}},{key:`greaterThan`,value:function(e,t){return 0<i.__compareToBigInt(e,t)}},{key:`greaterThanOrEqual`,value:function(e,t){return 0<=i.__compareToBigInt(e,t)}},{key:`equal`,value:function(e,t){if(e.sign!==t.sign||e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e.__digit(n)!==t.__digit(n))return!1;return!0}},{key:`notEqual`,value:function(e,t){return!i.equal(e,t)}},{key:`bitwiseAnd`,value:function(e,t){if(!e.sign&&!t.sign)return i.__absoluteAnd(e,t).__trim();if(e.sign&&t.sign){var r=n(e.length,t.length)+1,a=i.__absoluteSubOne(e,r),o=i.__absoluteSubOne(t);return a=i.__absoluteOr(a,o,a),i.__absoluteAddOne(a,!0,a).__trim()}if(e.sign){var s=[t,e];e=s[0],t=s[1]}return i.__absoluteAndNot(e,i.__absoluteSubOne(t)).__trim()}},{key:`bitwiseXor`,value:function(e,t){if(!e.sign&&!t.sign)return i.__absoluteXor(e,t).__trim();if(e.sign&&t.sign){var r=n(e.length,t.length),a=i.__absoluteSubOne(e,r),o=i.__absoluteSubOne(t);return i.__absoluteXor(a,o,a).__trim()}var s=n(e.length,t.length)+1;if(e.sign){var c=[t,e];e=c[0],t=c[1]}var l=i.__absoluteSubOne(t,s);return l=i.__absoluteXor(l,e,l),i.__absoluteAddOne(l,!0,l).__trim()}},{key:`bitwiseOr`,value:function(e,t){var r=n(e.length,t.length);if(!e.sign&&!t.sign)return i.__absoluteOr(e,t).__trim();if(e.sign&&t.sign){var a=i.__absoluteSubOne(e,r),o=i.__absoluteSubOne(t);return a=i.__absoluteAnd(a,o,a),i.__absoluteAddOne(a,!0,a).__trim()}if(e.sign){var s=[t,e];e=s[0],t=s[1]}var c=i.__absoluteSubOne(t,r);return c=i.__absoluteAndNot(c,e,c),i.__absoluteAddOne(c,!0,c).__trim()}},{key:`asIntN`,value:function(e,t){if(t.length===0)return t;if(e=r(e),0>e)throw RangeError(`Invalid value: not (convertible to) a safe integer`);if(e===0)return i.__zero();if(e>=i.__kMaxLengthBits)return t;var n=0|(e+29)/30;if(t.length<n)return t;var a=t.__unsignedDigit(n-1),o=1<<(e-1)%30;if(t.length===n&&a<o)return t;if((a&o)!==o)return i.__truncateToNBits(e,t);if(!t.sign)return i.__truncateAndSubFromPowerOfTwo(e,t,!0);if(!(a&o-1)){for(var s=n-2;0<=s;s--)if(t.__digit(s)!==0)return i.__truncateAndSubFromPowerOfTwo(e,t,!1);return t.length===n&&a===o?t:i.__truncateToNBits(e,t)}return i.__truncateAndSubFromPowerOfTwo(e,t,!1)}},{key:`asUintN`,value:function(e,t){if(t.length===0)return t;if(e=r(e),0>e)throw RangeError(`Invalid value: not (convertible to) a safe integer`);if(e===0)return i.__zero();if(t.sign){if(e>i.__kMaxLengthBits)throw RangeError(`BigInt too big`);return i.__truncateAndSubFromPowerOfTwo(e,t,!1)}if(e>=i.__kMaxLengthBits)return t;var n=0|(e+29)/30;if(t.length<n)return t;var a=e%30;return t.length==n&&(a===0||!(t.__digit(n-1)>>>a))?t:i.__truncateToNBits(e,t)}},{key:`ADD`,value:function(e,t){if(e=i.__toPrimitive(e),t=i.__toPrimitive(t),typeof e==`string`)return typeof t!=`string`&&(t=t.toString()),e+t;if(typeof t==`string`)return e.toString()+t;if(e=i.__toNumeric(e),t=i.__toNumeric(t),i.__isBigInt(e)&&i.__isBigInt(t))return i.add(e,t);if(typeof e==`number`&&typeof t==`number`)return e+t;throw TypeError(`Cannot mix BigInt and other types, use explicit conversions`)}},{key:`LT`,value:function(e,t){return i.__compare(e,t,0)}},{key:`LE`,value:function(e,t){return i.__compare(e,t,1)}},{key:`GT`,value:function(e,t){return i.__compare(e,t,2)}},{key:`GE`,value:function(e,t){return i.__compare(e,t,3)}},{key:`EQ`,value:function(e,t){for(;;){if(i.__isBigInt(e))return i.__isBigInt(t)?i.equal(e,t):i.EQ(t,e);if(typeof e==`number`){if(i.__isBigInt(t))return i.__equalToNumber(t,e);if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(typeof e==`string`){if(i.__isBigInt(t))return e=i.__fromString(e),e!==null&&i.equal(e,t);if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(typeof e==`boolean`){if(i.__isBigInt(t))return i.__equalToNumber(t,+e);if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(S(e)===`symbol`){if(i.__isBigInt(t))return!1;if(S(t)!==`object`)return e==t;t=i.__toPrimitive(t)}else if(S(e)===`object`){if(S(t)===`object`&&t.constructor!==i)return e==t;e=i.__toPrimitive(e)}else return e==t}}},{key:`NE`,value:function(e,t){return!i.EQ(e,t)}},{key:`DataViewGetBigInt64`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0&&arguments[2];return i.asIntN(64,i.DataViewGetBigUint64(e,t,n))}},{key:`DataViewGetBigUint64`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0&&arguments[2],r=y(n?[4,0]:[0,4],2),a=r[0],o=r[1],s=e.getUint32(t+a,n),c=e.getUint32(t+o,n),l=new i(3,!1);return l.__setDigit(0,1073741823&c),l.__setDigit(1,(268435455&s)<<2|c>>>30),l.__setDigit(2,s>>>28),l.__trim()}},{key:`DataViewSetBigInt64`,value:function(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0&&arguments[3];i.DataViewSetBigUint64(e,t,n,r)}},{key:`DataViewSetBigUint64`,value:function(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0&&arguments[3];n=i.asUintN(64,n);var a=0,o=0;if(0<n.length&&(o=n.__digit(0),1<n.length)){var s=n.__digit(1);o|=s<<30,a=s>>>2,2<n.length&&(a|=n.__digit(2)<<28)}var c=y(r?[4,0]:[0,4],2),l=c[0],u=c[1];e.setUint32(t+l,a,r),e.setUint32(t+u,o,r)}},{key:`__zero`,value:function(){return new i(0,!1)}},{key:`__oneDigit`,value:function(e,t){var n=new i(1,t);return n.__setDigit(0,e),n}},{key:`__decideRounding`,value:function(e,t,n,r){if(0<t)return-1;var i;if(0>t)i=-t-1;else{if(n===0)return-1;n--,r=e.__digit(n),i=29}var a=1<<i;if((r&a)==0)return-1;if(--a,(r&a)!=0)return 1;for(;0<n;)if(n--,e.__digit(n)!==0)return 1;return 0}},{key:`__fromDouble`,value:function(e){var t=0>e;i.__kBitConversionDouble[0]=e;var n,r=(2047&i.__kBitConversionInts[i.__kBitConversionIntHigh]>>>20)-1023,a=(0|r/30)+1,o=new i(a,t),s=1048575&i.__kBitConversionInts[i.__kBitConversionIntHigh]|1048576,c=i.__kBitConversionInts[i.__kBitConversionIntLow],l=20,u=r%30,d=0;if(u<l){var f=l-u;d=f+32,n=s>>>f,s=s<<32-f|c>>>f,c<<=32-f}else if(u===l)d=32,n=s,s=c,c=0;else{var p=u-l;d=32-p,n=s<<p|c>>>32-p,s=c<<p,c=0}o.__setDigit(a-1,n);for(var m=a-2;0<=m;m--)0<d?(d-=30,n=s>>>2,s=s<<30|c>>>2,c<<=30):n=0,o.__setDigit(m,n);return o.__trim()}},{key:`__isWhitespace`,value:function(e){return 13>=e&&9<=e||(159>=e?e==32:131071>=e?e==160||e==5760:196607>=e?(e&=131071,10>=e||e==40||e==41||e==47||e==95||e==4096):e==65279)}},{key:`__fromString`,value:function(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0,n=0,r=e.length,a=0;if(a===r)return i.__zero();for(var o=e.charCodeAt(a);i.__isWhitespace(o);){if(++a===r)return i.__zero();o=e.charCodeAt(a)}if(o===43){if(++a===r)return null;o=e.charCodeAt(a),n=1}else if(o===45){if(++a===r)return null;o=e.charCodeAt(a),n=-1}if(t===0){if(t=10,o===48){if(++a===r)return i.__zero();if(o=e.charCodeAt(a),o===88||o===120){if(t=16,++a===r)return null;o=e.charCodeAt(a)}else if(o===79||o===111){if(t=8,++a===r)return null;o=e.charCodeAt(a)}else if(o===66||o===98){if(t=2,++a===r)return null;o=e.charCodeAt(a)}}}else if(t===16&&o===48){if(++a===r)return i.__zero();if(o=e.charCodeAt(a),o===88||o===120){if(++a===r)return null;o=e.charCodeAt(a)}}if(n!==0&&t!==10)return null;for(;o===48;){if(++a===r)return i.__zero();o=e.charCodeAt(a)}var s=r-a,c=i.__kMaxBitsPerChar[t],l=i.__kBitsPerCharTableMultiplier-1;if(s>1073741824/c)return null;var u=new i(0|((c*s+l>>>i.__kBitsPerCharTableShift)+29)/30,!1),d=10>t?t:10,f=10<t?t-10:0;if(t&t-1){u.__initializeDigits();var p=!1,m=0;do{for(var h,g=0,_=1;;){if(h=void 0,o-48>>>0<d)h=o-48;else if((32|o)-97>>>0<f)h=(32|o)-87;else{p=!0;break}var v=_*t;if(1073741823<v)break;if(_=v,g=g*t+h,m++,++a===r){p=!0;break}o=e.charCodeAt(a)}l=30*i.__kBitsPerCharTableMultiplier-1;var y=0|(c*m+l>>>i.__kBitsPerCharTableShift)/30;u.__inplaceMultiplyAdd(_,g,y)}while(!p)}else{c>>=i.__kBitsPerCharTableShift;var b=[],x=[],S=!1;do{for(var C,w=0,T=0;;){if(C=void 0,o-48>>>0<d)C=o-48;else if((32|o)-97>>>0<f)C=(32|o)-87;else{S=!0;break}if(T+=c,w=w<<c|C,++a===r){S=!0;break}if(o=e.charCodeAt(a),30<T+c)break}b.push(w),x.push(T)}while(!S);i.__fillFromParts(u,b,x)}if(a!==r){if(!i.__isWhitespace(o))return null;for(a++;a<r;a++)if(o=e.charCodeAt(a),!i.__isWhitespace(o))return null}return u.sign=n===-1,u.__trim()}},{key:`__fillFromParts`,value:function(e,t,n){for(var r=0,i=0,a=0,o=t.length-1;0<=o;o--){var s=t[o],c=n[o];i|=s<<a,a+=c,a===30?(e.__setDigit(r++,i),a=0,i=0):30<a&&(e.__setDigit(r++,1073741823&i),a-=30,i=s>>>c-a)}if(i!==0){if(r>=e.length)throw Error(`implementation bug`);e.__setDigit(r++,i)}for(;r<e.length;r++)e.__setDigit(r,0)}},{key:`__toStringBasePowerOfTwo`,value:function(e,t){var n=e.length,r=t-1;r=(85&r>>>1)+(85&r),r=(51&r>>>2)+(51&r),r=(15&r>>>4)+(15&r);var a=r,o=t-1,s=e.__digit(n-1),c=i.__clz30(s),l=0|(30*n-c+a-1)/a;if(e.sign&&l++,268435456<l)throw Error(`string too long`);for(var u=Array(l),d=l-1,f=0,p=0,m=0;m<n-1;m++){var h=e.__digit(m),g=(f|h<<p)&o;u[d--]=i.__kConversionChars[g];var _=a-p;for(f=h>>>_,p=30-_;p>=a;)u[d--]=i.__kConversionChars[f&o],f>>>=a,p-=a}var v=(f|s<<p)&o;for(u[d--]=i.__kConversionChars[v],f=s>>>a-p;f!==0;)u[d--]=i.__kConversionChars[f&o],f>>>=a;if(e.sign&&(u[d--]=`-`),d!==-1)throw Error(`implementation bug`);return u.join(``)}},{key:`__toStringGeneric`,value:function(e,t,n){var r=e.length;if(r===0)return``;if(r===1){var a=e.__unsignedDigit(0).toString(t);return!1===n&&e.sign&&(a=`-`+a),a}var o=30*r-i.__clz30(e.__digit(r-1)),s=i.__kMaxBitsPerChar[t]-1,c=o*i.__kBitsPerCharTableMultiplier;c+=s-1,c=0|c/s;var l,u,d=c+1>>1,f=i.exponentiate(i.__oneDigit(t,!1),i.__oneDigit(d,!1)),p=f.__unsignedDigit(0);if(f.length===1&&32767>=p){l=new i(e.length,!1),l.__initializeDigits();for(var m,h=0,g=2*e.length-1;0<=g;g--)m=h<<15|e.__halfDigit(g),l.__setHalfDigit(g,0|m/p),h=0|m%p;u=h.toString(t)}else{var _=i.__absoluteDivLarge(e,f,!0,!0);l=_.quotient;var v=_.remainder.__trim();u=i.__toStringGeneric(v,t,!0)}l.__trim();for(var y=i.__toStringGeneric(l,t,!0);u.length<d;)u=`0`+u;return!1===n&&e.sign&&(y=`-`+y),y+u}},{key:`__unequalSign`,value:function(e){return e?-1:1}},{key:`__absoluteGreater`,value:function(e){return e?-1:1}},{key:`__absoluteLess`,value:function(e){return e?1:-1}},{key:`__compareToBigInt`,value:function(e,t){var n=e.sign;if(n!==t.sign)return i.__unequalSign(n);var r=i.__absoluteCompare(e,t);return 0<r?i.__absoluteGreater(n):0>r?i.__absoluteLess(n):0}},{key:`__compareToNumber`,value:function(e,n){if(i.__isOneDigitInt(n)){var r=e.sign,a=0>n;if(r!==a)return i.__unequalSign(r);if(e.length===0){if(a)throw Error(`implementation bug`);return n===0?0:-1}if(1<e.length)return i.__absoluteGreater(r);var o=t(n),s=e.__unsignedDigit(0);return s>o?i.__absoluteGreater(r):s<o?i.__absoluteLess(r):0}return i.__compareToDouble(e,n)}},{key:`__compareToDouble`,value:function(e,t){if(t!==t)return t;if(t===1/0)return-1;if(t===-1/0)return 1;var n=e.sign;if(n!==0>t)return i.__unequalSign(n);if(t===0)throw Error(`implementation bug: should be handled elsewhere`);if(e.length===0)return-1;i.__kBitConversionDouble[0]=t;var r=2047&i.__kBitConversionInts[i.__kBitConversionIntHigh]>>>20;if(r==2047)throw Error(`implementation bug: handled elsewhere`);var a=r-1023;if(0>a)return i.__absoluteGreater(n);var o=e.length,s=e.__digit(o-1),c=i.__clz30(s),l=30*o-c,u=a+1;if(l<u)return i.__absoluteLess(n);if(l>u)return i.__absoluteGreater(n);var d=1048576|1048575&i.__kBitConversionInts[i.__kBitConversionIntHigh],f=i.__kBitConversionInts[i.__kBitConversionIntLow],p=20,m=29-c;if(m!==(0|(l-1)%30))throw Error(`implementation bug`);var h,g=0;if(m<p){var _=p-m;g=_+32,h=d>>>_,d=d<<32-_|f>>>_,f<<=32-_}else if(m===p)g=32,h=d,d=f,f=0;else{var v=m-p;g=32-v,h=d<<v|f>>>32-v,d=f<<v,f=0}if(s>>>=0,h>>>=0,s>h)return i.__absoluteGreater(n);if(s<h)return i.__absoluteLess(n);for(var y=o-2;0<=y;y--){0<g?(g-=30,h=d>>>2,d=d<<30|f>>>2,f<<=30):h=0;var b=e.__unsignedDigit(y);if(b>h)return i.__absoluteGreater(n);if(b<h)return i.__absoluteLess(n)}if(d!==0||f!==0){if(g===0)throw Error(`implementation bug`);return i.__absoluteLess(n)}return 0}},{key:`__equalToNumber`,value:function(e,n){return i.__isOneDigitInt(n)?n===0?e.length===0:e.length===1&&e.sign===0>n&&e.__unsignedDigit(0)===t(n):i.__compareToDouble(e,n)===0}},{key:`__comparisonResultToBool`,value:function(e,t){return t===0?0>e:t===1?0>=e:t===2?0<e:t===3?0<=e:void 0}},{key:`__compare`,value:function(e,t,n){if(e=i.__toPrimitive(e),t=i.__toPrimitive(t),typeof e==`string`&&typeof t==`string`)switch(n){case 0:return e<t;case 1:return e<=t;case 2:return e>t;case 3:return e>=t}if(i.__isBigInt(e)&&typeof t==`string`)return t=i.__fromString(t),t!==null&&i.__comparisonResultToBool(i.__compareToBigInt(e,t),n);if(typeof e==`string`&&i.__isBigInt(t))return e=i.__fromString(e),e!==null&&i.__comparisonResultToBool(i.__compareToBigInt(e,t),n);if(e=i.__toNumeric(e),t=i.__toNumeric(t),i.__isBigInt(e)){if(i.__isBigInt(t))return i.__comparisonResultToBool(i.__compareToBigInt(e,t),n);if(typeof t!=`number`)throw Error(`implementation bug`);return i.__comparisonResultToBool(i.__compareToNumber(e,t),n)}if(typeof e!=`number`)throw Error(`implementation bug`);if(i.__isBigInt(t))return i.__comparisonResultToBool(i.__compareToNumber(t,e),2^n);if(typeof t!=`number`)throw Error(`implementation bug`);return n===0?e<t:n===1?e<=t:n===2?e>t:n===3?e>=t:void 0}},{key:`__absoluteAdd`,value:function(e,t,n){if(e.length<t.length)return i.__absoluteAdd(t,e,n);if(e.length===0)return e;if(t.length===0)return e.sign===n?e:i.unaryMinus(e);var r=e.length;(e.__clzmsd()===0||t.length===e.length&&t.__clzmsd()===0)&&r++;for(var a,o=new i(r,n),s=0,c=0;c<t.length;c++)a=e.__digit(c)+t.__digit(c)+s,s=a>>>30,o.__setDigit(c,1073741823&a);for(;c<e.length;c++){var l=e.__digit(c)+s;s=l>>>30,o.__setDigit(c,1073741823&l)}return c<o.length&&o.__setDigit(c,s),o.__trim()}},{key:`__absoluteSub`,value:function(e,t,n){if(e.length===0)return e;if(t.length===0)return e.sign===n?e:i.unaryMinus(e);for(var r,a=new i(e.length,n),o=0,s=0;s<t.length;s++)r=e.__digit(s)-t.__digit(s)-o,o=1&r>>>30,a.__setDigit(s,1073741823&r);for(;s<e.length;s++){var c=e.__digit(s)-o;o=1&c>>>30,a.__setDigit(s,1073741823&c)}return a.__trim()}},{key:`__absoluteAddOne`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length;n===null?n=new i(r,t):n.sign=t;for(var a,o=1,s=0;s<r;s++)a=e.__digit(s)+o,o=a>>>30,n.__setDigit(s,1073741823&a);return o!==0&&n.__setDigitGrow(r,1),n}},{key:`__absoluteSubOne`,value:function(e,t){var n=e.length;t||=n;for(var r,a=new i(t,!1),o=1,s=0;s<n;s++)r=e.__digit(s)-o,o=1&r>>>30,a.__setDigit(s,1073741823&r);if(o!==0)throw Error(`implementation bug`);for(var c=n;c<t;c++)a.__setDigit(c,0);return a}},{key:`__absoluteAnd`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;if(r<a){o=r;var s=e,c=r;e=t,r=a,t=s,a=c}var l=o;n===null?n=new i(l,!1):l=n.length;for(var u=0;u<o;u++)n.__setDigit(u,e.__digit(u)&t.__digit(u));for(;u<l;u++)n.__setDigit(u,0);return n}},{key:`__absoluteAndNot`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;r<a&&(o=r);var s=r;n===null?n=new i(s,!1):s=n.length;for(var c=0;c<o;c++)n.__setDigit(c,e.__digit(c)&~t.__digit(c));for(;c<r;c++)n.__setDigit(c,e.__digit(c));for(;c<s;c++)n.__setDigit(c,0);return n}},{key:`__absoluteOr`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;if(r<a){o=r;var s=e,c=r;e=t,r=a,t=s,a=c}var l=r;n===null?n=new i(l,!1):l=n.length;for(var u=0;u<o;u++)n.__setDigit(u,e.__digit(u)|t.__digit(u));for(;u<r;u++)n.__setDigit(u,e.__digit(u));for(;u<l;u++)n.__setDigit(u,0);return n}},{key:`__absoluteXor`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,r=e.length,a=t.length,o=a;if(r<a){o=r;var s=e,c=r;e=t,r=a,t=s,a=c}var l=r;n===null?n=new i(l,!1):l=n.length;for(var u=0;u<o;u++)n.__setDigit(u,e.__digit(u)^t.__digit(u));for(;u<r;u++)n.__setDigit(u,e.__digit(u));for(;u<l;u++)n.__setDigit(u,0);return n}},{key:`__absoluteCompare`,value:function(e,t){var n=e.length-t.length;if(n!=0)return n;for(var r=e.length-1;0<=r&&e.__digit(r)===t.__digit(r);)r--;return 0>r?0:e.__unsignedDigit(r)>t.__unsignedDigit(r)?1:-1}},{key:`__multiplyAccumulate`,value:function(e,t,n,r){if(t!==0){for(var a=32767&t,o=t>>>15,s=0,c=0,l=0;l<e.length;l++,r++){var u=n.__digit(r),d=e.__digit(l),f=32767&d,p=d>>>15,m=i.__imul(f,a),h=i.__imul(f,o),g=i.__imul(p,a),_=i.__imul(p,o);u+=c+m+s,s=u>>>30,u&=1073741823,u+=((32767&h)<<15)+((32767&g)<<15),s+=u>>>30,c=_+(h>>>15)+(g>>>15),n.__setDigit(r,1073741823&u)}for(;s!==0||c!==0;r++){var v=n.__digit(r);v+=s+c,c=0,s=v>>>30,n.__setDigit(r,1073741823&v)}}}},{key:`__internalMultiplyAdd`,value:function(e,t,n,r,a){for(var o=n,s=0,c=0;c<r;c++){var l=e.__digit(c),u=i.__imul(32767&l,t),d=i.__imul(l>>>15,t),f=u+((32767&d)<<15)+s+o;o=f>>>30,s=d>>>15,a.__setDigit(c,1073741823&f)}if(a.length>r)for(a.__setDigit(r++,o+s);r<a.length;)a.__setDigit(r++,0);else if(o+s!==0)throw Error(`implementation bug`)}},{key:`__absoluteDivSmall`,value:function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;n===null&&(n=new i(e.length,!1));for(var r=0,a=2*e.length-1;0<=a;a-=2){var o=(r<<15|e.__halfDigit(a))>>>0,s=0|o/t;r=0|o%t,o=(r<<15|e.__halfDigit(a-1))>>>0;var c=0|o/t;r=0|o%t,n.__setDigit(a>>>1,s<<15|c)}return n}},{key:`__absoluteModSmall`,value:function(e,t){for(var n,r=0,i=2*e.length-1;0<=i;i--)n=(r<<15|e.__halfDigit(i))>>>0,r=0|n%t;return r}},{key:`__absoluteDivLarge`,value:function(e,t,n,r){var a=t.__halfDigitLength(),o=t.length,s=e.__halfDigitLength()-a,c=null;n&&(c=new i(s+2>>>1,!1),c.__initializeDigits());var l=new i(a+2>>>1,!1);l.__initializeDigits();var u=i.__clz15(t.__halfDigit(a-1));0<u&&(t=i.__specialLeftShift(t,u,0));for(var d=i.__specialLeftShift(e,u,1),f=t.__halfDigit(a-1),p=0,m=s;0<=m;m--){var h=32767,g=d.__halfDigit(m+a);if(g!==f){var _=(g<<15|d.__halfDigit(m+a-1))>>>0;h=0|_/f;for(var v=0|_%f,y=t.__halfDigit(a-2),b=d.__halfDigit(m+a-2);i.__imul(h,y)>>>0>(v<<16|b)>>>0&&(h--,v+=f,!(32767<v)););}i.__internalMultiplyAdd(t,h,0,o,l);var x=d.__inplaceSub(l,m,a+1);x!==0&&(x=d.__inplaceAdd(t,m,a),d.__setHalfDigit(m+a,32767&d.__halfDigit(m+a)+x),h--),n&&(1&m?p=h<<15:c.__setDigit(m>>>1,p|h))}if(r)return d.__inplaceRightShift(u),n?{quotient:c,remainder:d}:d;if(n)return c;throw Error(`unreachable`)}},{key:`__clz15`,value:function(e){return i.__clz30(e)-15}},{key:`__specialLeftShift`,value:function(e,t,n){var r=e.length,a=new i(r+n,!1);if(t===0){for(var o=0;o<r;o++)a.__setDigit(o,e.__digit(o));return 0<n&&a.__setDigit(r,0),a}for(var s,c=0,l=0;l<r;l++)s=e.__digit(l),a.__setDigit(l,1073741823&s<<t|c),c=s>>>30-t;return 0<n&&a.__setDigit(r,c),a}},{key:`__leftShiftByAbsolute`,value:function(e,t){var n=i.__toShiftAmount(t);if(0>n)throw RangeError(`BigInt too big`);var r=0|n/30,a=n%30,o=e.length,s=a!==0&&!!(e.__digit(o-1)>>>30-a),c=o+r+ +!!s,l=new i(c,e.sign);if(a===0){for(var u=0;u<r;u++)l.__setDigit(u,0);for(;u<c;u++)l.__setDigit(u,e.__digit(u-r))}else{for(var d=0,f=0;f<r;f++)l.__setDigit(f,0);for(var p,m=0;m<o;m++)p=e.__digit(m),l.__setDigit(m+r,1073741823&p<<a|d),d=p>>>30-a;if(s)l.__setDigit(o+r,d);else if(d!==0)throw Error(`implementation bug`)}return l.__trim()}},{key:`__rightShiftByAbsolute`,value:function(e,t){var n=e.length,r=e.sign,a=i.__toShiftAmount(t);if(0>a)return i.__rightShiftByMaximum(r);var o=0|a/30,s=a%30,c=n-o;if(0>=c)return i.__rightShiftByMaximum(r);var l=!1;if(r){var u=(1<<s)-1;if((e.__digit(o)&u)!=0)l=!0;else for(var d=0;d<o;d++)if(e.__digit(d)!==0){l=!0;break}}l&&s===0&&~e.__digit(n-1)==0&&c++;var f=new i(c,r);if(s===0){f.__setDigit(c-1,0);for(var p=o;p<n;p++)f.__setDigit(p-o,e.__digit(p))}else{for(var m,h=e.__digit(o)>>>s,g=n-o-1,_=0;_<g;_++)m=e.__digit(_+o+1),f.__setDigit(_,1073741823&m<<30-s|h),h=m>>>s;f.__setDigit(g,h)}return l&&(f=i.__absoluteAddOne(f,!0,f)),f.__trim()}},{key:`__rightShiftByMaximum`,value:function(e){return e?i.__oneDigit(1,!0):i.__zero()}},{key:`__toShiftAmount`,value:function(e){if(1<e.length)return-1;var t=e.__unsignedDigit(0);return t>i.__kMaxLengthBits?-1:t}},{key:`__toPrimitive`,value:function(e){var t=1<arguments.length&&arguments[1]!==void 0?arguments[1]:`default`;if(S(e)!==`object`||e.constructor===i)return e;if(typeof Symbol<`u`&&S(Symbol.toPrimitive)===`symbol`&&e[Symbol.toPrimitive]){var n=e[Symbol.toPrimitive](t);if(S(n)!==`object`)return n;throw TypeError(`Cannot convert object to primitive value`)}var r=e.valueOf;if(r){var a=r.call(e);if(S(a)!==`object`)return a}var o=e.toString;if(o){var s=o.call(e);if(S(s)!==`object`)return s}throw TypeError(`Cannot convert object to primitive value`)}},{key:`__toNumeric`,value:function(e){return i.__isBigInt(e)?e:+e}},{key:`__isBigInt`,value:function(e){return S(e)===`object`&&e!==null&&e.constructor===i}},{key:`__truncateToNBits`,value:function(e,t){for(var n=0|(e+29)/30,r=new i(n,t.sign),a=n-1,o=0;o<a;o++)r.__setDigit(o,t.__digit(o));var s=t.__digit(a);if(e%30!=0){var c=32-e%30;s=s<<c>>>c}return r.__setDigit(a,s),r.__trim()}},{key:`__truncateAndSubFromPowerOfTwo`,value:function(e,t,n){for(var r=Math.min,a,o=0|(e+29)/30,s=new i(o,n),c=0,l=o-1,u=0,d=r(l,t.length);c<d;c++)a=0-t.__digit(c)-u,u=1&a>>>30,s.__setDigit(c,1073741823&a);for(;c<l;c++)s.__setDigit(c,0|1073741823&-u);var f,p=l<t.length?t.__digit(l):0,m=e%30;if(m===0)f=0-p-u,f&=1073741823;else{var h=32-m;p=p<<h>>>h;var g=1<<32-h;f=g-p-u,f&=g-1}return s.__setDigit(l,f),s.__trim()}},{key:`__digitPow`,value:function(e,t){for(var n=1;0<t;)1&t&&(n*=e),t>>>=1,e*=e;return n}},{key:`__detectBigEndian`,value:function(){return i.__kBitConversionDouble[0]=-0,i.__kBitConversionInts[0]!==0}},{key:`__isOneDigitInt`,value:function(e){return(1073741823&e)===e}}])}(w(Array));return T.__kMaxLength=33554432,T.__kMaxLengthBits=T.__kMaxLength<<5,T.__kMaxBitsPerChar=[0,0,32,51,64,75,83,90,96,102,107,111,115,119,122,126,128,131,134,136,139,141,143,145,147,149,151,153,154,156,158,159,160,162,163,165,166],T.__kBitsPerCharTableShift=5,T.__kBitsPerCharTableMultiplier=1<<T.__kBitsPerCharTableShift,T.__kConversionChars=`0123456789abcdefghijklmnopqrstuvwxyz`.split(``),T.__kBitConversionBuffer=new ArrayBuffer(8),T.__kBitConversionDouble=new Float64Array(T.__kBitConversionBuffer),T.__kBitConversionInts=new Int32Array(T.__kBitConversionBuffer),T.__kBitConversionIntHigh=+!T.__detectBigEndian(),T.__kBitConversionIntLow=+!!T.__detectBigEndian(),T.__clz30=t?function(e){return t(e)-2}:function(e){var t=Math.LN2,n=Math.log;return e===0?30:0|29-(0|n(e>>>0)/t)},T.__imul=e||function(e,t){return 0|e*t},T})}))(),1),TG=Z.default.BigInt(0),EG=Z.default.BigInt(1),DG=Z.default.BigInt(2),OG=Z.default.BigInt(10),Ove=Z.default.BigInt(24),kve=Z.default.BigInt(60),Ave=Z.default.BigInt(1e3),kG=Z.default.BigInt(1e6),AG=Z.default.BigInt(1e9),jG=Z.default.multiply(Z.default.BigInt(3600),AG),jve=Z.default.multiply(kve,AG),MG=Z.default.multiply(jG,Ove);function NG(e){return typeof e==`bigint`?Z.default.BigInt(e.toString(10)):e}function PG(e){return Z.default.equal(Z.default.remainder(e,DG),TG)}function FG(e){return Z.default.lessThan(e,TG)?Z.default.unaryMinus(e):e}function IG(e,t){return Z.default.lessThan(e,t)?-1:+!!Z.default.greaterThan(e,t)}function LG(e,t){return{quotient:Z.default.divide(e,t),remainder:Z.default.remainder(e,t)}}var RG,zG,BG=`slot-epochNanoSeconds`,VG=`slot-iso-date`,HG=`slot-iso-date-time`,UG=`slot-time`,WG=`slot-calendar`,GG=`slot-date-brand`,KG=`slot-year-month-brand`,qG=`slot-month-day-brand`,JG=`slot-time-zone`,YG=`slot-years`,XG=`slot-months`,ZG=`slot-weeks`,QG=`slot-days`,$G=`slot-hours`,eK=`slot-minutes`,tK=`slot-seconds`,nK=`slot-milliseconds`,rK=`slot-microseconds`,iK=`slot-nanoseconds`,aK=`date`,oK=`ym`,sK=`md`,cK=`time`,lK=`datetime`,uK=`instant`,dK=`original`,fK=`timezone-canonical`,pK=`timezone-original`,mK=`calendar-id`,hK=`locale`,gK=`options`,_K=new WeakMap,vK=Symbol.for(`@@Temporal__GetSlots`);(RG=globalThis)[vK]||(RG[vK]=function(e){return _K.get(e)});var yK=globalThis[vK],bK=Symbol.for(`@@Temporal__CreateSlots`);(zG=globalThis)[bK]||(zG[bK]=function(e){_K.set(e,Object.create(null))});var xK=globalThis[bK];function SK(e,...t){if(!e||typeof e!=`object`)return!1;let n=yK(e);return!!n&&t.every((e=>e in n))}function Q(e,t){let n=yK(e)?.[t];if(n===void 0)throw TypeError(`Missing internal slot ${t}`);return n}function CK(e,t,n){let r=yK(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 wK={};function TK(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))}EK(t,e),EK(`${t}.prototype`,e.prototype)}function EK(e,t){let n=`%${e}%`;if(wK[n]!==void 0)throw Error(`intrinsic ${e} already exists`);wK[n]=t}function DK(e){return wK[e]}function OK(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 kK(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 AK(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 jK(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 MK=class e{constructor(e){this.totalNs=NG(e),this.sec=Z.default.toNumber(Z.default.divide(this.totalNs,AG)),this.subsec=Z.default.toNumber(Z.default.remainder(this.totalNs,AG))}static validateNew(t,n){if(Z.default.greaterThan(FG(t),e.MAX))throw RangeError(`${n} of duration time units cannot exceed ${e.MAX} s`);return new e(t)}static fromEpochNsDiff(t,n){let r=Z.default.subtract(NG(t),NG(n));return new e(r)}static fromComponents(t,n,r,i,a,o){let s=Z.default.add(Z.default.add(Z.default.add(Z.default.add(Z.default.add(Z.default.BigInt(o),Z.default.multiply(Z.default.BigInt(a),Ave)),Z.default.multiply(Z.default.BigInt(i),kG)),Z.default.multiply(Z.default.BigInt(r),AG)),Z.default.multiply(Z.default.BigInt(n),jve)),Z.default.multiply(Z.default.BigInt(t),jG));return e.validateNew(s,`total`)}abs(){return new e(FG(this.totalNs))}add(t){return e.validateNew(Z.default.add(this.totalNs,t.totalNs),`sum`)}add24HourDays(t){return e.validateNew(Z.default.add(this.totalNs,Z.default.multiply(Z.default.BigInt(t),MG)),`sum`)}addToEpochNs(e){return Z.default.add(NG(e),this.totalNs)}cmp(e){return IG(this.totalNs,e.totalNs)}divmod(t){let{quotient:n,remainder:r}=LG(this.totalNs,Z.default.BigInt(t));return{quotient:Z.default.toNumber(n),remainder:new e(r)}}fdiv(e){let t=NG(e),n=Z.default.BigInt(t),{quotient:r,remainder:i}=LG(this.totalNs,n),a=[],o,s=(Z.default.lessThan(this.totalNs,TG)?-1:1)*Math.sign(Z.default.toNumber(t));for(;!Z.default.equal(i,TG)&&a.length<50;)i=Z.default.multiply(i,OG),{quotient:o,remainder:i}=LG(i,n),a.push(Math.abs(Z.default.toNumber(o)));return s*Number(FG(r).toString()+`.`+a.join(``))}isZero(){return Z.default.equal(this.totalNs,TG)}round(t,n){let r=NG(t);if(Z.default.equal(r,EG))return this;let{quotient:i,remainder:a}=LG(this.totalNs,r),o=Z.default.lessThan(this.totalNs,TG)?`negative`:`positive`,s=Z.default.multiply(FG(i),r),c=Z.default.add(s,r),l=IG(FG(Z.default.multiply(a,DG)),r),u=AK(n,o),d=Z.default.equal(FG(this.totalNs),s)?s:jK(s,c,l,PG(i),u),f=o===`positive`?d:Z.default.unaryMinus(d);return e.validateNew(f,`rounding`)}sign(){return this.cmp(new e(TG))}subtract(t){return e.validateNew(Z.default.subtract(this.totalNs,t.totalNs),`difference`)}};MK.MAX=Z.default.BigInt(`9007199254740991999999999`),MK.ZERO=new MK(TG);var NK=/[A-Za-z._][A-Za-z._0-9+-]*/,PK=RegExp(`(?:(?:[+-](?:[01][0-9]|2[0-3])(?::?[0-5][0-9])?)|(?:${NK.source})(?:\\/(?:${NK.source}))*)`),FK=/(?:[+-]\d{6}|\d{4})/,IK=/(?:0[1-9]|1[0-2])/,LK=/(?:0[1-9]|[12]\d|3[01])/,Mve=RegExp(`(${FK.source})(?:-(${IK.source})-(${LK.source})|(${IK.source})(${LK.source}))`),RK=/(\d{2})(?::(\d{2})(?::(\d{2})(?:[.,](\d{1,9}))?)?|(\d{2})(?:(\d{2})(?:[.,](\d{1,9}))?)?)?/,zK=/((?:[+-])(?:[01][0-9]|2[0-3])(?::?(?:[0-5][0-9])(?::?(?:[0-5][0-9])(?:[.,](?:\d{1,9}))?)?)?)/,BK=RegExp(`([zZ])|${zK.source}?`),VK=/\[(!)?([a-z_][a-z0-9_-]*)=([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)\]/g,Nve=new RegExp([`^${Mve.source}`,`(?:(?:[tT]|\\s+)${RK.source}(?:${BK.source})?)?`,`(?:\\[!?(${PK.source})\\])?`,`((?:${VK.source})*)$`].join(``)),Pve=new RegExp([`^[tT]?${RK.source}`,`(?:${BK.source})?`,`(?:\\[!?${PK.source}\\])?`,`((?:${VK.source})*)$`].join(``)),Fve=RegExp(`^(${FK.source})-?(${IK.source})(?:\\[!?${PK.source}\\])?((?:${VK.source})*)$`),Ive=RegExp(`^(?:--)?(${IK.source})-?(${LK.source})(?:\\[!?${PK.source}\\])?((?:${VK.source})*)$`),HK=/(\d+)(?:[.,](\d{1,9}))?/,Lve=RegExp(`(?:${HK.source}H)?(?:${HK.source}M)?(?:${HK.source}S)?`),Rve=RegExp(`^([+-])?P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?!$)${Lve.source})?$`,`i`),UK=864e5,WK=1e6*UK,zve=6e10,GK=1e8*UK,KK=PX(GK),qK=Z.default.unaryMinus(KK),Bve=Z.default.add(Z.default.subtract(qK,MG),EG),Vve=Z.default.subtract(Z.default.add(KK,MG),EG),Hve=146097*UK,JK=-271821,YK=275760,XK=Date.UTC(1847,0,1),Uve=[`iso8601`,`hebrew`,`islamic`,`islamic-umalqura`,`islamic-tbla`,`islamic-civil`,`islamic-rgsa`,`islamicc`,`persian`,`ethiopic`,`ethioaa`,`ethiopic-amete-alem`,`coptic`,`chinese`,`dangi`,`roc`,`indian`,`buddhist`,`japanese`,`gregory`],Wve=new Set([`ACT`,`AET`,`AGT`,`ART`,`AST`,`BET`,`BST`,`CAT`,`CNT`,`CST`,`CTT`,`EAT`,`ECT`,`IET`,`IST`,`JST`,`MIT`,`NET`,`NST`,`PLT`,`PNT`,`PRT`,`PST`,`SST`,`VST`]);function ZK(e){return typeof e==`object`&&!!e||typeof e==`function`}function QK(e){if(typeof e==`bigint`)throw TypeError(`Cannot convert BigInt to number`);return Number(e)}function $K(e){if(typeof e==`symbol`)throw TypeError(`Cannot convert a Symbol value to a String`);return String(e)}function eq(e){let t=QK(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 tq(e,t){let n=eq(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 nq(e){let t=QK(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 rq(e,t){return String(e).padStart(t,`0`)}function iq(e){if(typeof e!=`string`)throw TypeError(`expected a string, not ${String(e)}`);return e}function aq(e,t){if(ZK(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 oq=[`era`,`eraYear`,`year`,`month`,`monthCode`,`day`,`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],Gve={era:$K,eraYear:eq,year:eq,month:tq,monthCode:function(e){let t=iq(aq(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:tq,hour:eq,minute:eq,second:eq,millisecond:eq,microsecond:eq,nanosecond:eq,offset:function(e){let t=iq(aq(e));return cY(t),t},timeZone:BJ},Kve={hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},sq=[[`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`]],cq=Object.fromEntries(sq.map((e=>[e[0],e[1]]))),qve=Object.fromEntries(sq.map((([e,t])=>[t,e]))),lq=sq.map((([,e])=>e)),uq={day:WK,hour:36e11,minute:6e10,second:1e9,millisecond:1e6,microsecond:1e3,nanosecond:1},dq=[`days`,`hours`,`microseconds`,`milliseconds`,`minutes`,`months`,`nanoseconds`,`seconds`,`weeks`,`years`],Jve=Intl.DateTimeFormat,fq=new Map;function pq(e){let t=UX(e),n=fq.get(t);return n===void 0&&(n=new Jve(`en-us`,{timeZone:t,hour12:!1,era:`short`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`}),fq.set(t,n)),n}function mq(e){return SK(e,BG)&&!SK(e,JG,WG)}function hq(e){return SK(e,YG,XG,QG,$G,eK,tK,nK,rK,iK)}function gq(e){return SK(e,GG)}function _q(e){return SK(e,UG)}function vq(e){return SK(e,HG)}function yq(e){return SK(e,KG)}function bq(e){return SK(e,qG)}function xq(e){return SK(e,BG,JG,WG)}function $(e,t){if(!t(e))throw TypeError(`invalid receiver: method called with the wrong type of this-object`)}function Sq(e){if(SK(e,WG)||SK(e,JG))throw TypeError(`with() does not support a calendar or timeZone property`);if(_q(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 Cq(e,t){return t===`never`||t===`auto`&&e===`iso8601`?``:`[${t===`critical`?`!`:``}u-ca=${e}]`}function wq(e){let t,n,r=!1;for(VK.lastIndex=0;n=VK.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 Tq(e){let t=Nve.exec(e);if(!t)throw RangeError(`invalid RFC 9557 string: ${e}`);let n=wq(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 RY(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 Eq(e){let t=Pve.exec(e),n,r,i,a,o,s,c;if(t){c=wq(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}=Tq(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(LY(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}=Oq(e);FY(1972,t,n)}catch{try{let{year:t,month:n}=Dq(e);FY(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 Dq(e){let t=Fve.exec(e),n,r,i,a;if(t){i=wq(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}=Tq(e),t)throw RangeError(`Z designator not supported for PlainYearMonth`)}return{year:n,month:r,calendar:i,referenceISODay:a}}function Oq(e){let t=Ive.exec(e),n,r,i,a;if(t){if(i=wq(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}=Tq(e),t)throw RangeError(`Z designator not supported for PlainMonthDay`)}return{month:n,day:r,calendar:i,referenceISOYear:a}}var kq=RegExp(`^${PK.source}$`,`i`),Aq=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])?)?$`);function jq(e){let t=Xve.test(e)?`Seconds not allowed in offset time zone`:`Invalid time zone`;throw RangeError(`${t}: ${e}`)}function Mq(e){return kq.test(e)||jq(e),Aq.test(e)?{offsetMinutes:cY(e)/6e10}:{tzName:e}}function Nq(e,t,n,r){let i=e,a=t,o=n;switch(r){case`reject`:FY(i,a,o);break;case`constrain`:({year:i,month:a,day:o}=NY(i,a,o))}return{year:i,month:a,day:o}}function Pq(e,t,n,r,i,a,o){let s=e,c=t,l=n,u=r,d=i,f=a;switch(o){case`reject`:LY(s,c,l,u,d,f);break;case`constrain`:s=MY(s,0,23),c=MY(c,0,59),l=MY(l,0,59),u=MY(u,0,999),d=MY(d,0,999),f=MY(f,0,999)}return{hour:s,minute:c,second:l,millisecond:u,microsecond:d,nanosecond:f}}function Fq(e){if(!ZK(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<dq.length;r++){let i=dq[r],a=e[i];a!==void 0&&(n=!0,t[i]=nq(a))}if(!n)throw TypeError(`invalid duration-like`);return t}function Iq({years:e,months:t,weeks:n,days:r},i,a,o){return{years:e,months:o??t,weeks:a??n,days:i??r}}function Lq(e,t){return{isoDate:e,time:t}}function Rq(e){return VX(e,`overflow`,[`constrain`,`reject`],`constrain`)}function zq(e){return VX(e,`disambiguation`,[`compatible`,`earlier`,`later`,`reject`],`compatible`)}function Bq(e,t){return VX(e,`roundingMode`,[`ceil`,`floor`,`expand`,`trunc`,`halfCeil`,`halfFloor`,`halfExpand`,`halfTrunc`,`halfEven`],t)}function Vq(e,t){return VX(e,`offset`,[`prefer`,`use`,`ignore`,`reject`],t)}function Hq(e){return VX(e,`calendarName`,[`auto`,`always`,`never`,`critical`],`auto`)}function Uq(e){let t=e.roundingIncrement;if(t===void 0)return 1;let n=eq(t);if(n<1||n>1e9)throw RangeError(`roundingIncrement must be at least 1 and at most 1e9, not ${t}`);return n}function Wq(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 Gq(e){let t=e.fractionalSecondDigits;if(t===void 0)return`auto`;if(typeof t!=`number`){if($K(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 Kq(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 qq=Symbol(`~required~`);function Jq(e,t,n,r,i=[]){let a=[];for(let e=0;e<sq.length;e++){let t=sq[e],r=t[1],i=t[2];n!==`datetime`&&n!==i||a.push(r)}a=a.concat(i);let o=r;o===qq?o=void 0:o!==void 0&&a.push(o);let s=[];s=s.concat(a);for(let e=0;e<a.length;e++){let t=qve[a[e]];t!==void 0&&s.push(t)}let c=VX(e,t,s,o);if(c===void 0&&r===qq)throw RangeError(`${t} is required`);return c&&c in cq?cq[c]:c}function Yq(e){let t=e.relativeTo;if(t===void 0)return{};let n,r,i,a,o,s=`option`,c=!1;if(ZK(t)){if(xq(t))return{zonedRelativeTo:t};if(gq(t))return{plainRelativeTo:t};if(vq(t))return{plainRelativeTo:_J(Q(t,HG).isoDate,Q(t,WG))};i=FJ(t);let e=rJ(i,t,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],[]);({isoDate:n,time:r}=oJ(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}=Tq(iq(t)),e)a=BJ(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=HX(i),n={year:u,month:d,day:f}}return a===void 0?{plainRelativeTo:_J(n,i)}:{zonedRelativeTo:kJ(mJ(n,r,s,s===`option`?cY(o):0,a,`compatible`,`reject`,c),a,i)}}function Xq(e){return Q(e,YG)===0?Q(e,XG)===0?Q(e,ZG)===0?Q(e,QG)===0?Q(e,$G)===0?Q(e,eK)===0?Q(e,tK)===0?Q(e,nK)===0?Q(e,rK)===0?`nanosecond`:`microsecond`:`millisecond`:`second`:`minute`:`hour`:`day`:`week`:`month`:`year`}function Zq(e,t){return lq.indexOf(e)>lq.indexOf(t)?t:e}function Qq(e){return e===`year`||e===`month`||e===`week`}function $q(e){return Qq(e)||e===`day`?`date`:`time`}function eJ(e){return DK(`%calendarImpl%`)(e)}function tJ(e){return DK(`%calendarImpl%`)(Q(e,WG))}function nJ(e,t,n=`date`){let r=Object.create(null),i=eJ(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 rJ(e,t,n,r,i){let a=eJ(e).extraFields(n),o=n.concat(r,a),s=Object.create(null),c=!1;o.sort();for(let e=0;e<o.length;e++){let n=o[e],r=t[n];if(r!==void 0)c=!0,s[n]=(0,Gve[n])(r);else if(i!==`partial`){if(i.includes(n))throw TypeError(`required property '${n}' missing or undefined`);s[n]=Kve[n]}}if(i===`partial`&&!c)throw TypeError(`no supported properties found`);return s}function iJ(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]=eq(s),r=!0)}if(!r)throw TypeError(`invalid time-like`);return i}function aJ(e,t){if(ZK(e)){if(gq(e))return Rq(zX(t)),_J(Q(e,VG),Q(e,WG));if(xq(e)){let n=WJ(Q(e,JG),Q(e,BG));return Rq(zX(t)),_J(n.isoDate,Q(e,WG))}if(vq(e))return Rq(zX(t)),_J(Q(e,HG).isoDate,Q(e,WG));let n=FJ(e);return _J(LJ(n,rJ(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),Rq(zX(t))),n)}let{year:n,month:r,day:i,calendar:a,z:o}=Tq(iq(e));if(o)throw RangeError(`Z designator not supported for PlainDate`);return a||=`iso8601`,a=HX(a),Rq(zX(t)),_J({year:n,month:r,day:i},a)}function oJ(e,t,n){return Lq(LJ(e,t,n),Pq(t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond,n))}function sJ(e,t){let n,r,i;if(ZK(e)){if(vq(e))return Rq(zX(t)),yJ(Q(e,HG),Q(e,WG));if(xq(e)){let n=WJ(Q(e,JG),Q(e,BG));return Rq(zX(t)),yJ(n,Q(e,WG))}if(gq(e))return Rq(zX(t)),yJ(Lq(Q(e,VG),{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Q(e,WG));i=FJ(e);let a=rJ(i,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],[]),o=Rq(zX(t));({isoDate:n,time:r}=oJ(i,a,o))}else{let a,o,s,c;if({year:o,month:s,day:c,time:r,calendar:i,z:a}=Tq(iq(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}),RY(o,s,c,r.hour,r.minute,r.second,r.millisecond,r.microsecond,r.nanosecond),i||=`iso8601`,i=HX(i),Rq(zX(t)),n={year:o,month:s,day:c}}return yJ(Lq(n,r),i)}function cJ(e){let t=DK(`%Temporal.Duration%`);if(hq(e))return new t(Q(e,YG),Q(e,XG),Q(e,ZG),Q(e,QG),Q(e,$G),Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK));if(!ZK(e))return function(e){let{years:t,months:n,weeks:r,days:i,hours:a,minutes:o,seconds:s,milliseconds:c,microseconds:l,nanoseconds:u}=function(e){let t=Rve.exec(e);if(!t||t.every(((e,t)=>t<2||e===void 0)))throw RangeError(`invalid duration: ${e}`);let n=t[1]===`-`?-1:1,r=t[2]===void 0?0:eq(t[2])*n,i=t[3]===void 0?0:eq(t[3])*n,a=t[4]===void 0?0:eq(t[4])*n,o=t[5]===void 0?0:eq(t[5])*n,s=t[6]===void 0?0:eq(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*eq((c+`000000000`).slice(0,9))*n}else if(p=l===void 0?0:eq(l)*n,u!==void 0){if(d??f)throw RangeError(`only the smallest unit can be fractional`);h=60*eq((u+`000000000`).slice(0,9))*n}else m=d===void 0?0:eq(d)*n,f!==void 0&&(h=eq((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),UY(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(DK(`%Temporal.Duration%`))(t,n,r,i,a,o,s,c,l,u)}(iq(e));let n={years:0,months:0,weeks:0,days:0,hours:0,minutes:0,seconds:0,milliseconds:0,microseconds:0,nanoseconds:0},r=Fq(e);for(let e=0;e<dq.length;e++){let t=dq[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 lJ(e){let t;if(ZK(e)){if(mq(e)||xq(e))return DJ(Q(e,BG));t=aq(e)}else t=e;let{year:n,month:r,day:i,time:a,offset:o,z:s}=function(e){let t=Tq(e);if(!t.z&&!t.offset)throw RangeError(`Temporal.Instant requires a time zone offset`);return t}(iq(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=OY(n,r,i,c,l,u,d,f,p-(s?0:cY(o)));return XY(m.isoDate),DJ(gY(m))}function uJ(e,t){if(ZK(e)){if(bq(e))return Rq(zX(t)),xJ(Q(e,VG),Q(e,WG));let n;return SK(e,WG)?n=Q(e,WG):(n=e.calendar,n===void 0&&(n=`iso8601`),n=PJ(n)),xJ(zJ(n,rJ(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),Rq(zX(t))),n)}let{month:n,day:r,referenceISOYear:i,calendar:a}=Oq(iq(e));if(a===void 0&&(a=`iso8601`),a=HX(a),Rq(zX(t)),a===`iso8601`)return xJ({year:1972,month:n,day:r},a);let o={year:i,month:n,day:r};return IY(o),o=zJ(a,nJ(a,o,`month-day`),`constrain`),xJ(o,a)}function dJ(e,t){let n;if(ZK(e)){if(_q(e))return Rq(zX(t)),CJ(Q(e,UG));if(vq(e))return Rq(zX(t)),CJ(Q(e,HG).time);if(xq(e)){let n=WJ(Q(e,JG),Q(e,BG));return Rq(zX(t)),CJ(n.time)}let{hour:r,minute:i,second:a,millisecond:o,microsecond:s,nanosecond:c}=iJ(e);n=Pq(r,i,a,o,s,c,Rq(zX(t)))}else n=Eq(iq(e)),Rq(zX(t));return CJ(n)}function fJ(e){return e===void 0?{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}:Q(dJ(e),UG)}function pJ(e,t){if(ZK(e)){if(yq(e))return Rq(zX(t)),TJ(Q(e,VG),Q(e,WG));let n=FJ(e);return TJ(RJ(n,rJ(n,e,[`year`,`month`,`monthCode`],[],[]),Rq(zX(t))),n)}let{year:n,month:r,referenceISODay:i,calendar:a}=Dq(iq(e));a===void 0&&(a=`iso8601`),a=HX(a),Rq(zX(t));let o={year:n,month:r,day:i};return HY(o),o=RJ(a,nJ(a,o,`year-month`),`constrain`),TJ(o,a)}function mJ(e,t,n,r,i,a,o,s){if(t===`start-of-day`)return JJ(i,e);let c=Lq(e,t);if(n===`wall`||o===`ignore`)return GJ(i,c,a);if(n===`exact`||o===`use`){let n=OY(e.year,e.month,e.day,t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond-r);XY(n.isoDate);let i=gY(n);return VY(i),i}XY(e);let l=gY(c),u=qJ(i,c);for(let e=0;e<u.length;e++){let t=u[e],n=Z.default.toNumber(Z.default.subtract(l,t)),i=CX(n,6e10,`halfExpand`);if(n===r||s&&i===r)return t}if(o===`reject`){let e=UJ(r),t=rY(c,`iso8601`,`auto`);throw RangeError(`Offset ${e} is invalid for ${t} in ${i}`)}return KJ(u,i,c,a)}function hJ(e,t){let n,r,i,a,o,s,c,l=!1,u=`option`;if(ZK(e)){if(xq(e)){let n=zX(t);return zq(n),Vq(n,`reject`),Rq(n),kJ(Q(e,BG),Q(e,JG),Q(e,WG))}o=FJ(e);let l=rJ(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=zX(t);s=zq(d),c=Vq(d,`reject`);let f=Rq(d);({isoDate:n,time:r}=oJ(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=Tq(e);if(!t.tzAnnotation)throw RangeError(`Temporal.ZonedDateTime requires a time zone ID in brackets`);return t}(iq(e))),i=BJ(d),f?u=`exact`:a||(u=`wall`),o||=`iso8601`,o=HX(o),l=!0;let g=zX(t);s=zq(g),c=Vq(g,`reject`),Rq(g),n={year:p,month:m,day:h}}let d=0;return u===`option`&&(d=cY(a)),kJ(mJ(n,r,u,d,i,s,c,l),i,o)}function gJ(e,t,n){IY(t),xK(e),CK(e,VG,t),CK(e,WG,n),CK(e,GG,!0)}function _J(e,t){let n=DK(`%Temporal.PlainDate%`),r=Object.create(n.prototype);return gJ(r,e,t),r}function vJ(e,t,n){zY(t),xK(e),CK(e,HG,t),CK(e,WG,n)}function yJ(e,t){let n=DK(`%Temporal.PlainDateTime%`),r=Object.create(n.prototype);return vJ(r,e,t),r}function bJ(e,t,n){IY(t),xK(e),CK(e,VG,t),CK(e,WG,n),CK(e,qG,!0)}function xJ(e,t){let n=DK(`%Temporal.PlainMonthDay%`),r=Object.create(n.prototype);return bJ(r,e,t),r}function SJ(e,t){xK(e),CK(e,UG,t)}function CJ(e){let t=DK(`%Temporal.PlainTime%`),n=Object.create(t.prototype);return SJ(n,e),n}function wJ(e,t,n){HY(t),xK(e),CK(e,VG,t),CK(e,WG,n),CK(e,KG,!0)}function TJ(e,t){let n=DK(`%Temporal.PlainYearMonth%`),r=Object.create(n.prototype);return wJ(r,e,t),r}function EJ(e,t){VY(t),xK(e),CK(e,BG,t)}function DJ(e){let t=DK(`%Temporal.Instant%`),n=Object.create(t.prototype);return EJ(n,e),n}function OJ(e,t,n,r){VY(t),xK(e),CK(e,BG,t),CK(e,JG,n),CK(e,WG,r)}function kJ(e,t,n=`iso8601`){let r=DK(`%Temporal.ZonedDateTime%`),i=Object.create(r.prototype);return OJ(i,e,t,n),i}function AJ(e){return oq.filter((t=>e[t]!==void 0))}function jJ(e,t,n){let r=AJ(n),i=eJ(e).fieldKeysToIgnore(r),a=Object.create(null),o=AJ(t);for(let e=0;e<oq.length;e++){let s,c=oq[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 MJ(e,t,n,r){let i=eJ(e).dateAdd(t,n,r);return IY(i),i}function NJ(e,t,n,r){return eJ(e).dateUntil(t,n,r)}function PJ(e){if(ZK(e)&&SK(e,WG))return Q(e,WG);let t=iq(e);try{return HX(t)}catch{}let n;try{({calendar:n}=Tq(t))}catch{try{({calendar:n}=Eq(t))}catch{try{({calendar:n}=Dq(t))}catch{({calendar:n}=Oq(t))}}}return n||=`iso8601`,HX(n)}function FJ(e){if(SK(e,WG))return Q(e,WG);let{calendar:t}=e;return t===void 0?`iso8601`:PJ(t)}function IJ(e,t){return HX(e)===HX(t)}function LJ(e,t,n){let r=eJ(e);r.resolveFields(t,`date`);let i=r.dateToISO(t,n);return IY(i),i}function RJ(e,t,n){let r=eJ(e);r.resolveFields(t,`year-month`),t.day=1;let i=r.dateToISO(t,n);return HY(i),i}function zJ(e,t,n){let r=eJ(e);r.resolveFields(t,`month-day`);let i=r.monthDayToISOReferenceDate(t,n);return IY(i),i}function BJ(e){if(ZK(e)&&xq(e))return Q(e,JG);let t=iq(e);if(t===`UTC`)return`UTC`;let{tzName:n,offsetMinutes:r}=function(e){let{tzAnnotation:t,offset:n,z:r}=function(e){if(kq.test(e))return{tzAnnotation:e,offset:void 0,z:!1};try{let{tzAnnotation:t,offset:n,z:r}=Tq(e);if(r||t||n)return{tzAnnotation:t,offset:n,z:r}}catch{}jq(e)}(e);return t?Mq(t):r?Mq(`UTC`):n?Mq(n):void 0}(t);if(r!==void 0)return pY(r);let i=uY(n);if(!i)throw RangeError(`Unrecognized time zone ${n}`);return i.identifier}function VJ(e,t){if(e===t)return!0;let n=Mq(e).offsetMinutes,r=Mq(t).offsetMinutes;if(n===void 0&&r===void 0){let n=uY(t);if(!n)return!1;let r=uY(e);return!!r&&r.primaryIdentifier===n.primaryIdentifier}return n===r}function HJ(e,t){let n=Mq(e).offsetMinutes;return n===void 0?fY(e,t):6e10*n}function UJ(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}${QJ(r,i,a,o,a===0&&o===0?`minute`:`auto`)}`}function WJ(e,t){let n=HJ(e,t),{isoDate:{year:r,month:i,day:a},time:{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d}}=_Y(t);return OY(r,i,a,o,s,c,l,u,d+n)}function GJ(e,t,n){return KJ(qJ(e,t),e,t,n)}function KJ(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=gY(n),o=Z.default.subtract(a,MG);VY(o);let s=HJ(t,o),c=Z.default.add(a,MG);VY(c);let l=HJ(t,c)-s;switch(r){case`earlier`:{let e=MK.fromComponents(0,0,0,0,0,-l),r=pX(n.time,e);return qJ(t,Lq(DY(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r))[0]}case`compatible`:case`later`:{let e=MK.fromComponents(0,0,0,0,0,l),r=pX(n.time,e),i=qJ(t,Lq(DY(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r));return i[i.length-1]}}}function qJ(e,t){if(e===`UTC`)return XY(t.isoDate),[gY(t)];let n=Mq(e).offsetMinutes;if(n!==void 0){let e=OY(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);XY(e.isoDate);let r=gY(e);return VY(r),[r]}return XY(t.isoDate),function(e,t){let n=gY(t),r=Z.default.subtract(n,MG);Z.default.lessThan(r,qK)&&(r=n);let i=Z.default.add(n,MG);Z.default.greaterThan(i,KK)&&(i=n);let a=fY(e,r),o=fY(e,i);return(a===o?[a]:[a,o]).map((r=>{let i=Z.default.subtract(n,Z.default.BigInt(r));if(jX(t,function(e,t){let{epochMilliseconds:n,time:{millisecond:r,microsecond:i,nanosecond:a}}=_Y(t),{year:o,month:s,day:c,hour:l,minute:u,second:d}=bY(e,n);return OY(o,s,c,l,u,d,r,i,a)}(e,i))===0)return VY(i),i})).filter((e=>e!==void 0))}(e,t)}function JJ(e,t){let n=Lq(t,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),r=qJ(e,n);if(r.length)return r[0];let i=gY(n),a=Z.default.subtract(i,MG);return VY(a),vY(e,a)}function YJ(e){let t;return t=e<0||e>9999?(e<0?`-`:`+`)+rq(Math.abs(e),6):rq(e,4),t}function XJ(e){return rq(e,2)}function ZJ(e,t){let n;if(t===`auto`){if(e===0)return``;n=rq(e,9).replace(/0+$/,``)}else{if(t===0)return``;n=rq(e,9).slice(0,t)}return`.${n}`}function QJ(e,t,n,r,i){let a=`${XJ(e)}:${XJ(t)}`;return i===`minute`||(a+=`:${XJ(n)}`,a+=ZJ(r,i)),a}function $J(e,t,n){let r=t;r===void 0&&(r=`UTC`);let i=Q(e,BG),a=rY(WJ(r,i),`iso8601`,n,`never`),o=`Z`;return t!==void 0&&(o=mY(HJ(r,i))),`${a}${o}`}function eY(e,t){let n=Q(e,YG),r=Q(e,XG),i=Q(e,ZG),a=Q(e,QG),o=Q(e,$G),s=Q(e,eK),c=CY(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=MK.fromComponents(0,0,Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK));d.isZero()&&![`second`,`millisecond`,`microsecond`,`nanosecond`].includes(Xq(e))&&t===`auto`||(u+=`${Math.abs(d.sec)}${ZJ(Math.abs(d.subsec),t)}S`);let f=`${c<0?`-`:``}P${l}`;return u&&(f=`${f}T${u}`),f}function tY(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,VG);return`${YJ(n)}-${XJ(r)}-${XJ(i)}${Cq(Q(e,WG),t)}`}function nY({hour:e,minute:t,second:n,millisecond:r,microsecond:i,nanosecond:a},o){return QJ(e,t,n,1e6*r+1e3*i+a,o)}function rY(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`${YJ(i)}-${XJ(a)}-${XJ(o)}T${QJ(s,c,l,1e6*u+1e3*d+f,n)}${Cq(t,r)}`}function iY(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,VG),a=`${XJ(r)}-${XJ(i)}`,o=Q(e,WG);t!==`always`&&t!==`critical`&&o===`iso8601`||(a=`${YJ(n)}-${a}`);let s=Cq(o,t);return s&&(a+=s),a}function aY(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,VG),a=`${YJ(n)}-${XJ(r)}`,o=Q(e,WG);t!==`always`&&t!==`critical`&&o===`iso8601`||(a+=`-${XJ(i)}`);let s=Cq(o,t);return s&&(a+=s),a}function oY(e,t,n=`auto`,r=`auto`,i=`auto`,a=void 0){let o=Q(e,BG);if(a){let{unit:e,increment:t,roundingMode:n}=a;o=wX(o,t,e,n)}let s=Q(e,JG),c=HJ(s,o),l=rY(WJ(s,o),`iso8601`,t,`never`);return i!==`never`&&(l+=mY(c)),r!==`never`&&(l+=`[${r===`critical`?`!`:``}${s}]`),l+=Cq(Q(e,WG),n),l}function sY(e){return Aq.test(e)}function cY(e){let t=Zve.exec(e);if(!t)throw RangeError(`invalid time zone offset: ${e}; must match ±HH:MM[:SS.SSSSSSSSS]`);return(t[1]===`-`?-1:1)*(1e9*(60*(60*t[2]+ +(t[3]||0))+ +(t[4]||0))+ +((t[5]||0)+`000000000`).slice(0,9))}var lY,Yve=Object.assign(Object.create(null),{"/":!0,"-":!0,_:!0});function uY(e){if(lY===void 0){let e=Intl.supportedValuesOf?.(`timeZone`);if(e){lY=new Map;for(let t=0;t<e.length;t++){let n=e[t];lY.set(UX(n),n)}}else lY=null}let t=UX(e),n=lY?.get(t);if(n)return{identifier:n,primaryIdentifier:n};try{n=pq(e).resolvedOptions().timeZone}catch{return}if(t===`antarctica/south_pole`&&(n=`Antarctica/McMurdo`),Wve.has(e))throw RangeError(`${e} is a legacy time zone identifier from ICU. Use ${n} instead`);let r=[...t].map(((e,n)=>n===0||Yve[t[n-1]]?e.toUpperCase():e)).join(``).split(`/`);if(r.length===1)return t===`gb-eire`?{identifier:`GB-Eire`,primaryIdentifier:n}:{identifier:t.length<=3||/[-0-9]/.test(t)?t.toUpperCase():r[0],primaryIdentifier:n};if(r[0]===`Etc`)return{identifier:`Etc/${[`Zulu`,`Greenwich`,`Universal`].includes(r[1])?r[1]:r[1].toUpperCase()}`,primaryIdentifier:n};if(r[0]===`Us`)return{identifier:`US/${r[1]}`,primaryIdentifier:n};let i=new Map([[`Act`,`ACT`],[`Lhi`,`LHI`],[`Nsw`,`NSW`],[`Dar_Es_Salaam`,`Dar_es_Salaam`],[`Port_Of_Spain`,`Port_of_Spain`],[`Port-Au-Prince`,`Port-au-Prince`],[`Isle_Of_Man`,`Isle_of_Man`],[`Comodrivadavia`,`ComodRivadavia`],[`Knox_In`,`Knox_IN`],[`Dumontdurville`,`DumontDUrville`],[`Mcmurdo`,`McMurdo`],[`Denoronha`,`DeNoronha`],[`Easterisland`,`EasterIsland`],[`Bajanorte`,`BajaNorte`],[`Bajasur`,`BajaSur`]]);return r[1]=i.get(r[1])??r[1],r.length>2&&(r[2]=i.get(r[2])??r[2]),{identifier:r.join(`/`),primaryIdentifier:n}}function dY(e,t){let{year:n,month:r,day:i,hour:a,minute:o,second:s}=bY(e,t),c=t%1e3;return c<0&&(c+=1e3),1e6*(hY({isoDate:{year:n,month:r,day:i},time:{hour:a,minute:o,second:s,millisecond:c}})-t)}function fY(e,t){return dY(e,NX(t,`floor`))}function pY(e){let t=e<0?`-`:`+`,n=Math.abs(e);return`${t}${QJ(Math.floor(n/60),n%60,0,0,`minute`)}`}function mY(e){return pY(CX(e,zve,`halfExpand`)/6e10)}function hY({isoDate:{year:e,month:t,day:n},time:{hour:r,minute:i,second:a,millisecond:o}}){let s=e%400,c=(e-s)/400,l=new Date;return l.setUTCHours(r,i,a,o),l.setUTCFullYear(s,t-1,n),l.getTime()+Hve*c}function gY(e){let t=hY(e),n=1e3*e.time.microsecond+e.time.nanosecond;return Z.default.add(PX(t),Z.default.BigInt(n))}function _Y(e){let t=NX(e,`trunc`),n=Z.default.toNumber(Z.default.remainder(e,kG));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 vY(e,t){if(e===`UTC`)return null;let n=NX(t,`floor`);if(n<XK)return vY(e,PX(XK));let r=Math.max(n,Date.now())+366*UK*3,i=n,a=dY(e,i),o=i,s=a;for(;a===s&&i<r;){if(o=i+2*UK*7,o>GK)return null;s=dY(e,o),a===s&&(i=o)}return a===s?null:PX(GX((t=>dY(e,t)),i,o,a,s))}function yY(e,t){if(e===`UTC`)return null;let n=NX(t,`ceil`),r=Date.now(),i=r+366*UK*3;if(n>i){let t=yY(e,PX(i));if(t===null||Z.default.lessThan(t,PX(r)))return t}if(e===`Africa/Casablanca`||e===`Africa/El_Aaiun`){let t=Date.UTC(2088,0,1);if(t<n)return yY(e,PX(t))}let a=n-1;if(a<XK)return null;let o=dY(e,a),s=a,c=o;for(;o===c&&a>XK;){if(s=a-2*UK*7,s<XK)return null;c=dY(e,s),o===c&&(a=s)}return o===c?null:PX(GX((t=>dY(e,t)),s,a,c,o))}function bY(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}}(pq(e).format(t))}function xY(e){return e!==void 0&&!(e%4!=0||e%100==0&&e%400!=0)}function SY(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]}[xY(e)?`leapyear`:`standard`][t-1]}function CY(e){let t=[Q(e,YG),Q(e,XG),Q(e,ZG),Q(e,QG),Q(e,$G),Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK)];for(let e=0;e<t.length;e++){let n=t[e];if(n!==0)return n<0?-1:1}return 0}function wY(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 TY(e){let t=wY(e.date);return t===0?e.time.sign():t}function EY(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 DY(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}=EY(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=xY(c)?366:365,a<-s;)--r,--c,a+=s;for(c+=1;s=xY(c)?366:365,a>s;)r+=1,c+=1,a-=s;for(;a<1;)({year:r,month:i}=EY(r,i-1)),a+=SY(r,i);for(;a>SY(r,i);)a-=SY(r,i),{year:r,month:i}=EY(r,i+1);return{year:r,month:i,day:a}}function OY(e,t,n,r,i,a,o,s,c){let l=kY(r,i,a,o,s,c);return Lq(DY(e,t,n+l.deltaDays),l)}function kY(e,t,n,r,i,a){let o,s=e,c=t,l=n,u=r,d=i,f=a;({div:o,mod:f}=OK(f,3)),d+=o,f<0&&(--d,f+=1e3),{div:o,mod:d}=OK(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 AY(e,t){let n=Iq(e,0);if(wY(n)===0)return e.days;let r=Q(t,VG),i=MJ(Q(t,WG),r,n,`constrain`),a=YY(r.year,r.month-1,r.day),o=YY(i.year,i.month-1,i.day)-a;return e.days+o}function jY(e){return new(DK(`%Temporal.Duration%`))(-Q(e,YG),-Q(e,XG),-Q(e,ZG),-Q(e,QG),-Q(e,$G),-Q(e,eK),-Q(e,tK),-Q(e,nK),-Q(e,rK),-Q(e,iK))}function MY(e,t,n){return Math.min(n,Math.max(t,e))}function NY(e,t,n){let r=MY(t,1,12);return{year:e,month:r,day:MY(n,1,SY(e,r))}}function PY(e,t,n){if(e<t||e>n)throw RangeError(`value out of range: ${t} <= ${e} <= ${n}`)}function FY(e,t,n){PY(t,1,12),PY(n,1,SY(e,t))}function IY(e){zY(Lq(e,{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}))}function LY(e,t,n,r,i,a){PY(e,0,23),PY(t,0,59),PY(n,0,59),PY(r,0,999),PY(i,0,999),PY(a,0,999)}function RY(e,t,n,r,i,a,o,s,c){FY(e,t,n),LY(r,i,a,o,s,c)}function zY(e){let t=gY(e);(Z.default.lessThan(t,Bve)||Z.default.greaterThan(t,Vve))&&VY(t)}function BY(e){gY(e)}function VY(e){if(Z.default.lessThan(e,qK)||Z.default.greaterThan(e,KK))throw RangeError(`date/time value is outside of supported range`)}function HY({year:e,month:t}){PY(e,JK,YK),e===JK?PY(t,4,12):e===YK&&PY(t,1,9)}function UY(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=OK(s,3),p=OK(c,6),m=OK(l,9),h=OK(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 WY(e){return{date:{years:Q(e,YG),months:Q(e,XG),weeks:Q(e,ZG),days:Q(e,QG)},time:MK.fromComponents(Q(e,$G),Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK))}}function GY(e){let t=MK.fromComponents(Q(e,$G),Q(e,eK),Q(e,tK),Q(e,nK),Q(e,rK),Q(e,iK)).add24HourDays(Q(e,QG));return{date:{years:Q(e,YG),months:Q(e,XG),weeks:Q(e,ZG),days:0},time:t}}function KY(e){let t=GY(e),n=Math.trunc(t.time.sec/86400);return UY(t.date.years,t.date.months,t.date.weeks,n,0,0,0,0,0,0),{...t.date,days:n}}function qY(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=kK(o,3,Math.trunc(i/1e3)),i%=1e3,o=0;break;case`microsecond`:i=kK(o,6,Math.trunc(r/1e3)),r%=1e3,o=0;break;case`nanosecond`:r=kK(o,9,r),o=0}return new(DK(`%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 JY(e,t){return wY(e),t.sign(),{date:e,time:t}}function YY(e,t,n){return hY({isoDate:{year:e,month:t+1,day:n},time:{hour:0,minute:0,second:0,millisecond:0}})/UK}function XY({year:e,month:t,day:n}){if(Math.abs(YY(e,t-1,n))>1e8)throw RangeError(`date/time value is outside the supported range`)}function ZY(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 MK.fromComponents(n,r,i,a,o,s)}function QY(e,t,n,r,i){let a=MK.fromEpochNsDiff(t,e);return a=DX(a,n,r,i),JY({years:0,months:0,weeks:0,days:0},a)}function $Y(e,t,n,r){BY(e),BY(t);let i=ZY(e.time,t.time),a=i.sign(),o=kX(e.isoDate,t.isoDate),s=t.isoDate;o===a&&(s=DY(s.year,s.month,s.day+a),i=i.add24HourDays(-a));let c=Zq(`day`,r),l=NJ(n,e.isoDate,s,c);return r!==c&&(i=i.add24HourDays(l.days),l.days=0),JY(l,i)}function eX(e,t,n,r,i){let a=Z.default.subtract(t,e);if(Z.default.equal(a,TG))return{date:{years:0,months:0,weeks:0,days:0},time:MK.ZERO};let o=Z.default.lessThan(a,TG)?-1:1,s=WJ(n,e),c=WJ(n,t),l,u=0,d=o===1?2:1,f=ZY(s.time,c.time);for(f.sign()===-o&&u++;u<=d;u++){l=Lq(DY(c.isoDate.year,c.isoDate.month,c.isoDate.day-u*o),s.time);let e=GJ(n,l,`compatible`);if(f=MK.fromEpochNsDiff(t,e),f.sign()!==-o)break}let p=Zq(`day`,i);return JY(NJ(r,s.isoDate,l.isoDate,p),f)}function tX(e,t,n,r,i,a,o,s,c){let l,u,d,f,p=t;switch(s){case`year`:{let t=CX(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=CX(p.date.months,o,`trunc`);l=t,u=t+o*e,d=Iq(p.date,0,0,l),f=Iq(p.date,0,0,u);break}case`week`:{let t=Iq(p.date,0,0),n=MJ(a,r.isoDate,t,`constrain`),i=NJ(a,n,DY(n.year,n.month,n.day+p.date.days),`week`),s=CX(p.date.weeks+i.weeks,o,`trunc`);l=s,u=s+o*e,d=Iq(p.date,0,l),f=Iq(p.date,0,u);break}case`day`:{let t=CX(p.date.days,o,`trunc`);l=t,u=t+o*e,d=Iq(p.date,l),f=Iq(p.date,u);break}}let m=MJ(a,r.isoDate,d,`constrain`),h=MJ(a,r.isoDate,f,`constrain`),g,_,v=Lq(m,r.time),y=Lq(h,r.time);i?(g=GJ(i,v,`compatible`),_=GJ(i,y,`compatible`)):(g=gY(v),_=gY(y));let b=MK.fromEpochNsDiff(n,g),x=MK.fromEpochNsDiff(_,g),S=AK(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)?jK(Math.abs(l),Math.abs(u),C,w,S):Math.abs(u),E=new MK(Z.default.add(Z.default.multiply(x.totalNs,Z.default.BigInt(l)),Z.default.multiply(b.totalNs,Z.default.BigInt(o*e)))).fdiv(x.totalNs),D=T===Math.abs(u);return p={date:D?f:d,time:MK.ZERO},{nudgeResult:{duration:p,nudgedEpochNs:D?_:g,didExpandCalendarUnit:D},total:E}}function nX(e,t,n,r,i,a,o,s,c){let l=e,u=Qq(s)||r&&s===`day`,d=TY(l)<0?-1:1,f;return u?{nudgeResult:f}=tX(d,l,t,n,r,i,o,s,c):f=r?function(e,t,n,r,i,a,o,s){let c=t,l=MJ(i,n.isoDate,c.date,`constrain`),u=Lq(l,n.time),d=Lq(DY(l.year,l.month,l.day+e),n.time),f=GJ(r,u,`compatible`),p=GJ(r,d,`compatible`),m=MK.fromEpochNsDiff(p,f);if(m.sign()!==e)throw RangeError(`time zone returned inconsistent Instants`);let h=Z.default.BigInt(uq[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:JY(Iq(c.date,c.date.days+y),g),nudgedEpochNs:b,didExpandCalendarUnit:v}}(d,l,n,r,i,o,s,c):function(e,t,n,r,i,a){let o=e,s=o.time.add24HourDays(o.date.days),c=s.round(Z.default.BigInt(r*uq[i]),a),l=c.subtract(s),{quotient:u}=s.divmod(WK),{quotient:d}=c.divmod(WK),f=Math.sign(d-u)===s.sign(),p=l.addToEpochNs(t),m=0,h=c;return $q(n)===`date`&&(m=d,h=c.add(MK.fromComponents(24*-d,0,0,0,0,0))),{duration:{date:Iq(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=lq.indexOf(o);for(let t=lq.indexOf(s)-1;t>=l;t--){let s=lq[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=Iq(c.date,0,0,t);break}case`week`:{let t=c.date.weeks+e;l=Iq(c.date,0,t);break}}let u=Lq(MJ(a,r.isoDate,l,`constrain`),r.time),d;if(d=i?GJ(i,u,`compatible`):gY(u),IG(n,d)===-e)break;c={date:l,time:MK.ZERO}}return c}(d,l,f.nudgedEpochNs,n,r,i,a,Zq(s,`day`))),l}function rX(e,t,n,r,i,a){return Qq(a)||r&&a===`day`?tX(TY(e)<0?-1:1,e,t,n,r,i,1,a,`trunc`).total:OX(e.time.add24HourDays(e.date.days),a)}function iX(e,t,n,r,i,a,o){if(jX(e,t)==0)return{date:{years:0,months:0,weeks:0,days:0},time:MK.ZERO};zY(e),zY(t);let s=$Y(e,t,n,r);return a===`nanosecond`&&i===1?s:nX(s,gY(t),e,null,n,r,i,a,o)}function aX(e,t,n,r,i,a,o,s){if($q(i)===`time`)return QY(e,t,a,o,s);let c=eX(e,t,n,r,i);return o===`nanosecond`&&a===1?c:nX(c,t,WJ(n,e),n,r,i,a,o,s)}function oX(e,t,n,r,i,a){let o=sq.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=Jq(t,`largestUnit`,n,`auto`);if(r.includes(s))throw RangeError(`largestUnit must be one of ${o.join(`, `)}, not ${s}`);let c=Uq(t),l=Bq(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=Jq(t,`smallestUnit`,n,i);if(r.includes(u))throw RangeError(`smallestUnit must be one of ${o.join(`, `)}, not ${u}`);let d=Zq(a,u);if(s===`auto`&&(s=d),Zq(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&&Wq(c,f,!1),{largestUnit:s,roundingIncrement:c,roundingMode:l,smallestUnit:u}}function sX(e,t,n,r){let i=lJ(n),a=oX(e,zX(r),`time`,[],`nanosecond`,`second`),o=qY(QY(Q(t,BG),Q(i,BG),a.roundingIncrement,a.smallestUnit,a.roundingMode),a.largestUnit);return e===`since`&&(o=jY(o)),o}function cX(e,t,n,r){let i=aJ(n),a=Q(t,WG),o=Q(i,WG);if(!IJ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=oX(e,zX(r),`date`,[],`day`,`day`),c=DK(`%Temporal.Duration%`),l=Q(t,VG),u=Q(i,VG);if(kX(l,u)===0)return new c;let d={date:NJ(a,l,u,s.largestUnit),time:MK.ZERO};if(s.smallestUnit!==`day`||s.roundingIncrement!==1){let e=Lq(l,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});d=nX(d,gY(Lq(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=qY(d,`day`);return e===`since`&&(f=jY(f)),f}function lX(e,t,n,r){let i=sJ(n),a=Q(t,WG),o=Q(i,WG);if(!IJ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=oX(e,zX(r),`datetime`,[],`nanosecond`,`day`),c=DK(`%Temporal.Duration%`),l=Q(t,HG),u=Q(i,HG);if(jX(l,u)===0)return new c;let d=qY(iX(l,u,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);return e===`since`&&(d=jY(d)),d}function uX(e,t,n,r){let i=dJ(n),a=oX(e,zX(r),`time`,[],`nanosecond`,`hour`),o=ZY(Q(t,UG),Q(i,UG));o=DX(o,a.roundingIncrement,a.smallestUnit,a.roundingMode);let s=qY(JY({years:0,months:0,weeks:0,days:0},o),a.largestUnit);return e===`since`&&(s=jY(s)),s}function dX(e,t,n,r){let i=pJ(n),a=Q(t,WG),o=Q(i,WG);if(!IJ(a,o))throw RangeError(`cannot compute difference between months of ${a} and ${o} calendars`);let s=oX(e,zX(r),`date`,[`week`,`day`],`month`,`year`),c=DK(`%Temporal.Duration%`);if(kX(Q(t,VG),Q(i,VG))==0)return new c;let l=nJ(a,Q(t,VG),`year-month`);l.day=1;let u=LJ(a,l,`constrain`),d=nJ(a,Q(i,VG),`year-month`);d.day=1;let f=LJ(a,d,`constrain`),p={date:Iq(NJ(a,u,f,s.largestUnit),0,0),time:MK.ZERO};if(s.smallestUnit!==`month`||s.roundingIncrement!==1){let e=Lq(u,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});p=nX(p,gY(Lq(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=qY(p,`day`);return e===`since`&&(m=jY(m)),m}function fX(e,t,n,r){let i=hJ(n),a=Q(t,WG),o=Q(i,WG);if(!IJ(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=oX(e,zX(r),`datetime`,[],`nanosecond`,`hour`),c=Q(t,BG),l=Q(i,BG),u=DK(`%Temporal.Duration%`),d;if($q(s.largestUnit)!==`date`)d=qY(QY(c,l,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);else{let e=Q(t,JG);if(!VJ(e,Q(i,JG)))throw RangeError(`When calculating difference between time zones, largestUnit must be 'hours' or smaller because day lengths can vary between time zones due to DST or time zone offset changes.`);if(Z.default.equal(c,l))return new u;d=qY(aX(c,l,e,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),`hour`)}return e===`since`&&(d=jY(d)),d}function pX({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,kY(e,t,s,r,i,c)}function mX(e,t){let n=t.addToEpochNs(e);return VY(n),n}function hX(e,t,n,r,i=`constrain`){if(wY(r.date)===0)return mX(e,r.time);let a=WJ(t,e);return mX(GJ(t,Lq(MJ(n,a.isoDate,r.date,i),a.time),`compatible`),r.time)}function gX(e,t,n){let r=cJ(n);e===`subtract`&&(r=jY(r));let i=Zq(Xq(t),Xq(r));if(Qq(i))throw RangeError(`For years, months, or weeks arithmetic, use date arithmetic relative to a starting point`);let a=GY(t),o=GY(r);return qY(JY({years:0,months:0,weeks:0,days:0},a.time.add(o.time)),i)}function _X(e,t,n){let r=cJ(n);e===`subtract`&&(r=jY(r));let i=Xq(r);if($q(i)===`date`)throw RangeError(`Duration field ${i} not supported by Temporal.Instant. Try Temporal.ZonedDateTime instead.`);let a=GY(r);return DJ(mX(Q(t,BG),a.time))}function vX(e,t,n,r){let i=Q(t,WG),a=cJ(n);e===`subtract`&&(a=jY(a));let o=KY(a),s=Rq(zX(r));return _J(MJ(i,Q(t,VG),o,s),i)}function yX(e,t,n,r){let i=cJ(n);e===`subtract`&&(i=jY(i));let a=Rq(zX(r)),o=Q(t,WG),s=GY(i),c=Q(t,HG),l=pX(c.time,s.time),u=Iq(s.date,l.deltaDays);return UY(u.years,u.months,u.weeks,u.days,0,0,0,0,0,0),yJ(Lq(MJ(o,c.isoDate,u,a),l),o)}function bX(e,t,n){let r=cJ(n);e===`subtract`&&(r=jY(r));let i=GY(r),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=pX(Q(t,UG),i.time);return CJ(Pq(a,o,s,c,l,u,`reject`))}function xX(e,t,n,r){let i=cJ(n);e===`subtract`&&(i=jY(i));let a=Rq(zX(r)),o=CY(i),s=Q(t,WG),c=nJ(s,Q(t,VG),`year-month`);c.day=1;let l=LJ(s,c,`constrain`);if(o<0){let e=MJ(s,l,{months:1},`constrain`);l=DY(e.year,e.month,e.day-1)}let u=KY(i);return IY(l),TJ(RJ(s,nJ(s,MJ(s,l,u,a),`year-month`),a),s)}function SX(e,t,n,r){let i=cJ(n);e===`subtract`&&(i=jY(i));let a=Rq(zX(r)),o=Q(t,JG),s=Q(t,WG),c=WY(i);return kJ(hX(Q(t,BG),o,s,c,a),o,s)}function CX(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=RX(Math.abs(2*i)-t),l=o%2==0,u=AK(n,a),d=i===0?o:jK(o,s,c,l,u);return t*(a===`positive`?d:-d)}function wX(e,t,n,r){let i=uq[n]*t;return function(e,t,n){let r=NG(e),i=NG(t),a=Z.default.divide(r,i),o=Z.default.remainder(r,i),s=AK(n,`positive`),c,l;Z.default.lessThan(r,TG)?(c=Z.default.subtract(a,EG),l=a):(c=a,l=Z.default.add(a,EG));let u=IG(FG(Z.default.multiply(o,DG)),i)*(Z.default.lessThan(r,TG)?-1:1)+0,d=Z.default.equal(o,TG)?a:jK(c,l,u,PG(c),s);return Z.default.multiply(d,i)}(e,Z.default.BigInt(i),r)}function TX(e,t,n,r){BY(e);let{year:i,month:a,day:o}=e.isoDate,s=EX(e.time,t,n,r);return Lq(DY(i,a,o+s.deltaDays),s)}function EX({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=uq[s],d=CX(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 kY(d,0,0,0,0,0);case`minute`:return kY(e,d,0,0,0,0);case`second`:return kY(e,t,d,0,0,0);case`millisecond`:return kY(e,t,n,d,0,0);case`microsecond`:return kY(e,t,n,r,d,0);case`nanosecond`:return kY(e,t,n,r,i,d);default:throw Error(`Invalid unit ${s}`)}}function DX(e,t,n,r){let i=uq[n];return e.round(Z.default.BigInt(i*t),r)}function OX(e,t){let n=uq[t];return e.fdiv(Z.default.BigInt(n))}function kX(e,t){return e.year===t.year?e.month===t.month?e.day===t.day?0:RX(e.day-t.day):RX(e.month-t.month):RX(e.year-t.year)}function AX(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:RX(e.nanosecond-t.nanosecond):RX(e.microsecond-t.microsecond):RX(e.millisecond-t.millisecond):RX(e.second-t.second):RX(e.minute-t.minute):RX(e.hour-t.hour)}function jX(e,t){let n=kX(e.isoDate,t.isoDate);return n===0?AX(e.time,t.time):n}function MX(e){let t=FX(e);return globalThis.BigInt===void 0?t:globalThis.BigInt(t.toString(10))}function NX(e,t){let{quotient:n,remainder:r}=LG(NG(e),kG),i=Z.default.toNumber(n);return t===`floor`&&Z.default.toNumber(r)<0&&--i,t===`ceil`&&Z.default.toNumber(r)>0&&(i+=1),i}function PX(e){if(!Number.isInteger(e))throw RangeError(`epoch milliseconds must be an integer`);return Z.default.multiply(Z.default.BigInt(e),kG)}function FX(e){let t=e;if(typeof e==`object`){let n=e[Symbol.toPrimitive];n&&typeof n==`function`&&(t=n.call(e,`number`))}if(typeof t==`number`)throw TypeError(`cannot convert number to bigint`);return typeof t==`bigint`?Z.default.BigInt(t.toString(10)):Z.default.BigInt(t)}var IX=(()=>{let e=Z.default.BigInt(Date.now()%1e6);return()=>{let t=Date.now(),n=Z.default.BigInt(t),r=Z.default.add(PX(t),e);return e=Z.default.remainder(n,kG),Z.default.greaterThan(r,KK)?KK:Z.default.lessThan(r,qK)?qK:r}})();function LX(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}function RX(e){return e<0?-1:e>0?1:e}function zX(e){if(e===void 0)return Object.create(null);if(ZK(e)&&e!==null)return e;throw TypeError(`Options parameter must be an object, not `+(e===null?`null`:typeof e))}function BX(e,t){let n=Object.create(null);return n[e]=t,n}function VX(e,t,n,r){let i=e[t];if(i!==void 0){if(i=$K(i),!n.includes(i))throw RangeError(`${t} must be one of ${n.join(`, `)}, not ${i}`);return i}if(r===qq)throw RangeError(`${t} option is required`);return r}function HX(e){let t=UX(e);if(!Uve.includes(UX(t)))throw RangeError(`invalid calendar identifier ${t}`);switch(t){case`ethiopic-amete-alem`:return`ethioaa`;case`islamicc`:return`islamic-civil`}return t}function UX(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 WX(e){throw TypeError(`Do not use built-in arithmetic operators with Temporal objects. When comparing, use ${e===`PlainMonthDay`?`Temporal.PlainDate.compare(obj1.toPlainDate(year), obj2.toPlainDate(year))`:`Temporal.${e}.compare(obj1, obj2)`}, not obj1 > obj2. When coercing to strings, use \`\${obj}\` or String(obj), not '' + obj. When coercing to numbers, use properties or methods of the object, not \`+obj\`. When concatenating with strings, use \`\${str}\${obj}\` or str.concat(obj), not str + obj. In React, coerce to a string before rendering a Temporal object.`)}var Xve=RegExp(`^${zK.source}$`),Zve=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])(?::?([0-5][0-9])(?:[.,](\\d{1,9}))?)?)?$`);function GX(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 KX(e){return[...e]}function qX(e,t){if(e!==`gregory`&&e!==`iso8601`)return;let n=YX[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 JX(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 YX={};function XX(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 ZX(e,t=!1){return`M${`${e}`.padStart(2,`0`)}${t?`L`:``}`}function QX(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`&&PY(r,1,n),t===`constrain`&&(r=MY(r,1,n)),i=ZX(r)}else{let e=XX(i);if(i!==ZX(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}}YX.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,QX(e))},dateToISO:(e,t)=>Nq(e.year,e.month,e.day,t),monthDayToISOReferenceDate(e,t){let{month:n,day:r}=Nq(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 KX(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}=EY(o,s),{year:o,month:s,day:c}=Nq(o,s,c,a),c+=i+7*r,DY(o,s,c)},dateUntil(e,t,n){let r=-kX(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);!JX(r,e.year+s,e.month,e.day,t);)a=s,s+=r;let c=r;for(i=EY(e.year+a,e.month+c);!JX(r,i.year,i.month,e.day,t);)o=c,c+=r,i=EY(i.year,i.month+r);n===`month`&&(o+=12*a,a=0)}i=EY(e.year+a,e.month+o);let s=NY(i.year,i.month,e.day),c=0,l=YY(t.year,t.month-1,t.day)-YY(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=ZX(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+=SY(e,n);i.dayOfYear=r}return r.weekOfYear&&(i.weekOfYear=qX(`iso8601`,{year:e,month:t,day:n})),r.daysInMonth&&(i.daysInMonth=SY(e,t)),(r.daysInYear||r.inLeapYear)&&(i.inLeapYear=xY(e),i.daysInYear=i.inLeapYear?366:365),i},getFirstDayOfWeek:()=>1,getMinimalDaysInFirstWeek:()=>4};var $X=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 eZ({isoYear:e,isoMonth:t,isoDay:n}){return`${YJ(e)}-${XJ(t)}-${XJ(n)}T00:00Z`}function tZ(e,t){return{years:e.year-t.year,months:e.month-t.month,days:e.day-t.day}}$X.objectMap=new WeakMap,$X.MAX_CACHE_ENTRIES=1e3;var nZ=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=eZ({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}=QX(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`?(PY(i,1,r),PY(a,1,this.maximumMonthLength(e))):(i=MY(i,1,r),a=MY(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=tZ(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=tZ(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=tZ(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:RX(e.day-t.day):RX(e.month-t.month):RX(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 DY(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 YY(i.year,i.month-1,i.day)-YY(r.year,r.month-1,r.day)}monthDaySearchStartYear(e,t){return 1972}monthDayFromFields(e,t,n){let r,i,a,o,s,{era:c,eraYear:l,year:u,month:d,monthCode:f,day:p}=e;if(d!==void 0&&u===void 0&&(!this.hasEra||c===void 0||l===void 0))throw TypeError(`when month is present, year (or era and eraYear) are required`);(f===void 0||u!==void 0||this.hasEra&&l!==void 0)&&({monthCode:f,day:p}=this.isoToCalendarDate(this.calendarToIsoDate(e,t,n),n));let m={year:this.monthDaySearchStartYear(f,p),month:12,day:31},h=this.isoToCalendarDate(m,n),g=h.monthCode>f||h.monthCode===f&&h.day>=p?h.year:h.year-1;for(let e=0;e<20;e++){let c=this.adjustCalendarDate({day:p,monthCode:f,year:g-e},n),l=this.calendarToIsoDate(c,`constrain`,n),u=this.isoToCalendarDate(l,n);if({year:r,month:i,day:a}=l,u.monthCode===f&&u.day===p)return{month:i,day:a,year:r};if(t===`constrain`){let e=this.maxLengthOfMonthCodeInAnyYear(u.monthCode);if(u.monthCode===f&&u.day===e&&p>e)return{month:i,day:a,year:r};(o===void 0||u.monthCode===o.monthCode&&u.day>o.day)&&(o=u,s=l)}}if(t===`constrain`&&s!==void 0)return s;throw RangeError(`No recent ${this.id} year with monthCode ${f} and day ${p}`)}getFirstDayOfWeek(){}getMinimalDaysInFirstWeek(){}},Qve=class extends nZ{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?ZX(5,!0):ZX(t<6?t:t-1):ZX(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=XX(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`?(PY(a,1,this.monthsInYear({year:i})),PY(s,1,this.maximumMonthLength({year:i,month:a}))):(a=MY(a,1,this.monthsInYear({year:i})),s=MY(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}}},rZ=class extends nZ{constructor(){super(...arguments),this.calendarType=`lunar`,this.DAYS_PER_ISLAMIC_YEAR=354+11/30,this.DAYS_PER_ISO_YEAR=365.2425}inLeapYear(e,t){let n={year:e.year,month:1,monthCode:`M01`,day:1},r={year:e.year+1,month:1,monthCode:`M01`,day:1};return this.calendarDaysUntil(n,r,t)===355}monthsInYear(){return 12}minimumMonthLength(){return 29}maximumMonthLength(){return 30}maxLengthOfMonthCodeInAnyYear(){return 30}estimateIsoDate(e){let{year:t}=this.adjustCalendarDate(e);return{year:Math.floor(t*this.DAYS_PER_ISLAMIC_YEAR/this.DAYS_PER_ISO_YEAR)+622,month:1,day:1}}},$ve=class extends rZ{constructor(){super(...arguments),this.id=`islamic`}},eye=class extends rZ{constructor(){super(...arguments),this.id=`islamic-umalqura`}},tye=class extends rZ{constructor(){super(...arguments),this.id=`islamic-tbla`}},nye=class extends rZ{constructor(){super(...arguments),this.id=`islamic-civil`}},rye=class extends rZ{constructor(){super(...arguments),this.id=`islamic-rgsa`}},iye=class extends rZ{constructor(){super(...arguments),this.id=`islamicc`}},aye=class extends nZ{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 XX(e)<=6?31:30}estimateIsoDate(e){let{year:t}=this.adjustCalendarDate(e);return{year:t+621,month:1,day:1}}},oye=class extends nZ{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 iZ(e.year+78)}monthsInYear(){return 12}minimumMonthLength(e){return this.getMonthInfo(e).length}maximumMonthLength(e){return this.getMonthInfo(e).length}maxLengthOfMonthCodeInAnyYear(e){let t=XX(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 DY(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 iZ(e){return e%4==0&&(e%100!=0||e%400==0)}var aZ=class extends nZ{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 iZ(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][XX(e)-1]}estimateIsoDate(e){let t=this.adjustCalendarDate(e);return Nq(t.year+this.isoEpoch.year,t.month+this.isoEpoch.month,t.day+this.isoEpoch.day,`constrain`)}},oZ=class extends nZ{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 iZ(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][XX(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:XX(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 Nq(t+i.isoEpoch.year-+!i.hasYearZero,n,r,`constrain`)}},sZ=class extends oZ{constructor(e,t){super(e,t)}isoToCalendarDate(e){let{year:t,month:n,day:r}=e,i=ZX(n),a=t-this.anchorEra.isoEpoch.year+1;return this.completeEraYear({year:a,month:n,monthCode:i,day:r})}},cZ={inLeapYear(e){let{year:t}=e;return(t+1)%4==0},monthsInYear:()=>13,minimumMonthLength(e){let{month:t}=e;return t===13?this.inLeapYear(e)?6:5:30},maximumMonthLength(e){return this.minimumMonthLength(e)},maxLengthOfMonthCodeInAnyYear:e=>e===`M13`?6:30},sye=class extends aZ{constructor(e,t){super(e,t),this.inLeapYear=cZ.inLeapYear,this.monthsInYear=cZ.monthsInYear,this.minimumMonthLength=cZ.minimumMonthLength,this.maximumMonthLength=cZ.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=cZ.maxLengthOfMonthCodeInAnyYear}},lZ=class extends oZ{constructor(e,t){super(e,t),this.inLeapYear=cZ.inLeapYear,this.monthsInYear=cZ.monthsInYear,this.minimumMonthLength=cZ.minimumMonthLength,this.maximumMonthLength=cZ.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=cZ.maxLengthOfMonthCodeInAnyYear}},cye=class extends sye{constructor(){super(`ethioaa`,{year:-5492,month:7,day:17})}},lye=class extends lZ{constructor(){super(`coptic`,[{code:`coptic`,isoEpoch:{year:284,month:8,day:29}},{code:`coptic-inverse`,reverseOf:`coptic`}])}},uye=class extends lZ{constructor(){super(`ethiopic`,[{code:`ethioaa`,names:[`ethiopic-amete-alem`,`mundi`],isoEpoch:{year:-5492,month:7,day:17}},{code:`ethiopic`,names:[`incar`],isoEpoch:{year:8,month:8,day:27},anchorEpoch:{year:5501}}])}},dye=class extends sZ{constructor(){super(`roc`,[{code:`roc`,names:[`minguo`],isoEpoch:{year:1912,month:1,day:1}},{code:`roc-inverse`,names:[`before-roc`],reverseOf:`roc`}])}},fye=class extends aZ{constructor(){super(`buddhist`,{year:-543,month:1,day:1})}},pye=class extends sZ{constructor(){super(`gregory`,[{code:`gregory`,names:[`ad`,`ce`],isoEpoch:{year:1,month:1,day:1}},{code:`gregory-inverse`,names:[`be`,`bce`],reverseOf:`gregory`}])}reviseIntlEra(e){let{era:t,eraYear:n}=e;return t===`b`&&(t=`gregory-inverse`),t===`a`&&(t=`gregory`),{era:t,eraYear:n}}getFirstDayOfWeek(){return 1}getMinimalDaysInFirstWeek(){return 1}},mye=class extends sZ{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}}},uZ=class extends nZ{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=eZ({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=ZX(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=ZX(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`?(PY(a,1,o),PY(s,1,this.maximumMonthLength())):(a=MY(a,1,o),s=MY(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=ZX(+l[0].replace(`bis`,``),l[0].indexOf(`bis`)!==-1)}else{let e=this.getMonthList(i,t),n=c.replace(/^M|L$/g,(e=>e===`L`?`bis`:``));n[0]===`0`&&(n=n.slice(1));let r=e[n];if(!r)throw RangeError(`Unmatched monthCode ${c} in Chinese year ${i}`);if(a!==r.monthIndex)throw RangeError(`monthCode ${c} doesn't correspond to month ${a} in Chinese year ${i}`)}return{...e,year:i,month:a,monthCode:c,day:s}}},hye=class extends uZ{constructor(){super(...arguments),this.id=`chinese`}},gye=class extends uZ{constructor(){super(...arguments),this.id=`dangi`}},_ye=class{constructor(e){this.helper=e}extraFields(e){return this.helper.hasEra&&e.includes(`year`)?[`era`,`eraYear`]:[]}resolveFields(e){if(this.helper.calendarType!==`lunisolar`){let t=new $X;QX(e,void 0,this.helper.monthsInYear({year:e.year??1972},t))}}dateToISO(e,t){let n=new $X,r=this.helper.calendarToIsoDate(e,t,n);return n.setObject(r),r}monthDayToISOReferenceDate(e,t){let n=new $X,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 KX(t)}dateAdd(e,{years:t,months:n,weeks:r,days:i},a){let o=$X.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 $X.getCacheForObject(l)||new $X(o).setObject(l),l}dateUntil(e,t,n){let r=$X.getCacheForObject(e),i=$X.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=$X.getCacheForObject(e),r=this.helper.isoToCalendarDate(e,n);if(t.dayOfWeek&&(r.dayOfWeek=YX.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=qX(this.helper.id,e)),r.daysInWeek=7,t.daysInMonth&&(r.daysInMonth=this.helper.daysInMonth(r,n)),t.daysInYear){let e=this.helper.startOfCalendarYear(r),t=this.helper.addCalendar(e,{years:1},`constrain`,n);r.daysInYear=this.helper.calendarDaysUntil(e,t,n)}return t.monthsInYear&&(r.monthsInYear=this.helper.monthsInYear(r,n)),t.inLeapYear&&(r.inLeapYear=this.helper.inLeapYear(r,n)),r}getFirstDayOfWeek(){return this.helper.getFirstDayOfWeek()}getMinimalDaysInFirstWeek(){return this.helper.getMinimalDaysInFirstWeek()}};for(let e of[Qve,aye,uye,cye,lye,hye,gye,dye,oye,fye,pye,mye,$ve,eye,tye,nye,rye,iye]){let t=new e;YX[t.id]=new _ye(t)}EK(`calendarImpl`,(function(e){return YX[e]}));var dZ=Intl.DateTimeFormat;function fZ(e,t){let n=Q(e,t);return typeof n==`function`&&(n=new dZ(Q(e,hK),n(Q(e,gK))),function(e,t,n){let r=yK(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 pZ(e){return SK(e,dK)}var mZ=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 dZ(t,i),o=a.resolvedOptions();if(xK(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,CK(e,gK,t)}else CK(e,gK,i);CK(e,hK,o.locale),CK(e,dK,a),CK(e,fK,o.timeZone),CK(e,mK,o.calendar),CK(e,aK,Eye),CK(e,oK,wye),CK(e,sK,Tye),CK(e,cK,Cye),CK(e,lK,Dye),CK(e,uK,Oye);let s=r?i.timeZone:void 0;if(s===void 0)CK(e,pK,o.timeZone);else{let t=$K(s);if(t.startsWith(`−`))throw RangeError(`Unicode minus (U+2212) is not supported in time zone offsets`);CK(e,pK,BJ(t))}})(this,e,t)}get format(){$(this,pZ);let e=yye.bind(this);return Object.defineProperties(e,{length:{value:1,enumerable:!1,writable:!1,configurable:!0},name:{value:``,enumerable:!1,writable:!1,configurable:!0}}),e}formatRange(e,t){return $(this,pZ),xye.call(this,e,t)}formatToParts(e,...t){return $(this,pZ),bye.call(this,e,...t)}formatRangeToParts(e,t){return $(this,pZ),Sye.call(this,e,t)}resolvedOptions(){return $(this,pZ),vye.call(this)}};`formatToParts`in dZ.prototype||delete mZ.prototype.formatToParts,`formatRangeToParts`in dZ.prototype||delete mZ.prototype.formatRangeToParts;var hZ=function(e=void 0,t=void 0){return new mZ(e,t)};function vye(){let e=Q(this,dK).resolvedOptions();return e.timeZone=Q(this,pK),e}function yye(e,...t){let n,r,i=CZ(e,this);return i.formatter?(n=i.formatter,r=[NX(i.epochNs,`floor`)]):(n=Q(this,dK),r=[e,...t]),n.format(...r)}function bye(e,...t){let n,r,i=CZ(e,this);return i.formatter?(n=i.formatter,r=[NX(i.epochNs,`floor`)]):(n=Q(this,dK),r=[e,...t]),n.formatToParts(...r)}function xye(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=xZ(e),r=xZ(t),i,a=[n,r];if(bZ(n)!==bZ(r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);if(bZ(n)){if(!SZ(n,r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);let{epochNs:e,formatter:t}=CZ(n,this),{epochNs:o,formatter:s}=CZ(r,this);t&&(i=t,a=[NX(e,`floor`),NX(o,`floor`)])}return i||=Q(this,dK),i.formatRange(...a)}function Sye(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=xZ(e),r=xZ(t),i,a=[n,r];if(bZ(n)!==bZ(r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);if(bZ(n)){if(!SZ(n,r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);let{epochNs:e,formatter:t}=CZ(n,this),{epochNs:o,formatter:s}=CZ(r,this);t&&(i=t,a=[NX(e,`floor`),NX(o,`floor`)])}return i||=Q(this,dK),i.formatRangeToParts(...a)}function gZ(e={},t={}){let n=Object.assign({},e),r=[`year`,`month`,`day`,`hour`,`minute`,`second`,`weekday`,`dayPeriod`,`timeZoneName`,`dateStyle`,`timeStyle`];for(let e=0;e<r.length;e++){let i=r[e];n[i]=i in t?t[i]:n[i],!1!==n[i]&&n[i]!==void 0||delete n[i]}return n}function Cye(e){let t=gZ(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`})),!vZ(t)){if(yZ(e))throw TypeError(`cannot format Temporal.PlainTime with options [${Object.keys(e)}]`);Object.assign(t,{hour:`numeric`,minute:`numeric`,second:`numeric`})}return t}function wye(e){let t={short:{year:`2-digit`,month:`numeric`},medium:{year:`numeric`,month:`short`},long:{year:`numeric`,month:`long`},full:{year:`numeric`,month:`long`}},n=gZ(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(yZ(e))throw TypeError(`cannot format PlainYearMonth with options [${Object.keys(e)}]`);Object.assign(n,{year:`numeric`,month:`numeric`})}return n}function Tye(e){let t={short:{month:`numeric`,day:`numeric`},medium:{month:`short`,day:`numeric`},long:{month:`long`,day:`numeric`},full:{month:`long`,day:`numeric`}},n=gZ(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(yZ(e))throw TypeError(`cannot format PlainMonthDay with options [${Object.keys(e)}]`);Object.assign(n,{month:`numeric`,day:`numeric`})}return n}function Eye(e){let t=gZ(e,{hour:!1,minute:!1,second:!1,dayPeriod:!1,timeZoneName:!1,timeStyle:!1});if(!_Z(t)){if(yZ(e))throw TypeError(`cannot format PlainDate with options [${Object.keys(e)}]`);Object.assign(t,{year:`numeric`,month:`numeric`,day:`numeric`})}return t}function Dye(e){let t=gZ(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),!vZ(t)&&!_Z(t)){if(yZ(e))throw TypeError(`cannot format PlainDateTime with options [${Object.keys(e)}]`);Object.assign(t,{year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})}return t}function Oye(e){let t=e;return vZ(t)||_Z(t)||(t=Object.assign({},t,{year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})),t}function _Z(e){return`year`in e||`month`in e||`day`in e||`weekday`in e||`dateStyle`in e||`era`in e}function vZ(e){return`hour`in e||`minute`in e||`second`in e||`timeStyle`in e||`dayPeriod`in e||`fractionalSecondDigits`in e}function yZ(e){return _Z(e)||vZ(e)||`dateStyle`in e||`timeStyle`in e||`timeZoneName`in e}function bZ(e){return gq(e)||_q(e)||vq(e)||xq(e)||yq(e)||bq(e)||mq(e)}function xZ(e){return bZ(e)?e:QK(e)}function SZ(e,t){return!(!bZ(e)||!bZ(t)||_q(e)&&!_q(t)||gq(e)&&!gq(t)||vq(e)&&!vq(t)||xq(e)&&!xq(t)||yq(e)&&!yq(t)||bq(e)&&!bq(t)||mq(e)&&!mq(t))}function CZ(e,t){if(_q(e)){let n={isoDate:{year:1970,month:1,day:1},time:Q(e,UG)};return{epochNs:GJ(Q(t,fK),n,`compatible`),formatter:fZ(t,cK)}}if(yq(e)){let n=Q(e,WG),r=Q(t,mK);if(n!==r)throw RangeError(`cannot format PlainYearMonth with calendar ${n} in locale with calendar ${r}`);let i=Lq(Q(e,VG),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:GJ(Q(t,fK),i,`compatible`),formatter:fZ(t,oK)}}if(bq(e)){let n=Q(e,WG),r=Q(t,mK);if(n!==r)throw RangeError(`cannot format PlainMonthDay with calendar ${n} in locale with calendar ${r}`);let i=Lq(Q(e,VG),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:GJ(Q(t,fK),i,`compatible`),formatter:fZ(t,sK)}}if(gq(e)){let n=Q(e,WG),r=Q(t,mK);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDate with calendar ${n} in locale with calendar ${r}`);let i=Lq(Q(e,VG),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:GJ(Q(t,fK),i,`compatible`),formatter:fZ(t,aK)}}if(vq(e)){let n=Q(e,WG),r=Q(t,mK);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDateTime with calendar ${n} in locale with calendar ${r}`);let i=Q(e,HG);return{epochNs:GJ(Q(t,fK),i,`compatible`),formatter:fZ(t,lK)}}if(xq(e))throw TypeError(`Temporal.ZonedDateTime not supported in DateTimeFormat methods. Use toLocaleString() instead.`);return mq(e)?{epochNs:Q(e,BG),formatter:fZ(t,uK)}:{}}function wZ(e){let t=Object.create(null);return t.years=Q(e,YG),t.months=Q(e,XG),t.weeks=Q(e,ZG),t.days=Q(e,QG),t.hours=Q(e,$G),t.minutes=Q(e,eK),t.seconds=Q(e,tK),t.milliseconds=Q(e,nK),t.microseconds=Q(e,rK),t.nanoseconds=Q(e,iK),t}mZ.prototype.constructor=hZ,Object.defineProperty(hZ,"prototype",{value:mZ.prototype,writable:!1,enumerable:!1,configurable:!1}),hZ.supportedLocalesOf=dZ.supportedLocalesOf,TK(hZ,`Intl.DateTimeFormat`);var{format:kye,formatToParts:Aye}=Intl.DurationFormat?.prototype??Object.create(null);function TZ(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=wZ(cJ(e));return kye.call(this,t)}Intl.DurationFormat?.prototype&&(Intl.DurationFormat.prototype.format=TZ,Intl.DurationFormat.prototype.formatToParts=function(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=wZ(cJ(e));return Aye.call(this,t)}),Object.freeze({__proto__:null,DateTimeFormat:hZ,ModifiedIntlDurationFormatPrototypeFormat:TZ});var EZ=class{constructor(e){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);EJ(this,FX(e))}get epochMilliseconds(){return $(this,mq),NX(Q(this,BG),`floor`)}get epochNanoseconds(){return $(this,mq),MX(Z.default.BigInt(Q(this,BG)))}add(e){return $(this,mq),_X(`add`,this,e)}subtract(e){return $(this,mq),_X(`subtract`,this,e)}until(e,t=void 0){return $(this,mq),sX(`until`,this,e,t)}since(e,t=void 0){return $(this,mq),sX(`since`,this,e,t)}round(e){if($(this,mq),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?BX(`smallestUnit`,e):zX(e),n=Uq(t),r=Bq(t,`halfExpand`),i=Jq(t,`smallestUnit`,`time`,qq);return Wq(n,{hour:24,minute:1440,second:86400,millisecond:864e5,microsecond:864e8,nanosecond:864e11}[i],!0),DJ(wX(Q(this,BG),n,i,r))}equals(e){$(this,mq);let t=lJ(e),n=Q(this,BG),r=Q(t,BG);return Z.default.equal(Z.default.BigInt(n),Z.default.BigInt(r))}toString(e=void 0){$(this,mq);let t=zX(e),n=Gq(t),r=Bq(t,`trunc`),i=Jq(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=BJ(a));let{precision:o,unit:s,increment:c}=Kq(i,n);return $J(DJ(wX(Q(this,BG),c,s,r)),a,o)}toJSON(){return $(this,mq),$J(this,void 0,`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,mq),new hZ(e,t).format(this)}valueOf(){WX(`Instant`)}toZonedDateTimeISO(e){$(this,mq);let t=BJ(e);return kJ(Q(this,BG),t,`iso8601`)}static fromEpochMilliseconds(e){return DJ(PX(QK(e)))}static fromEpochNanoseconds(e){return DJ(FX(e))}static from(e){return lJ(e)}static compare(e,t){let n=lJ(e),r=lJ(t),i=Q(n,BG),a=Q(r,BG);return Z.default.lessThan(i,a)?-1:+!!Z.default.greaterThan(i,a)}};TK(EZ,`Temporal.Instant`);var DZ=class{constructor(e,t,n,r=`iso8601`){let i=eq(e),a=eq(t),o=eq(n),s=HX(r===void 0?`iso8601`:iq(r));FY(i,a,o),gJ(this,{year:i,month:a,day:o},s)}get calendarId(){return $(this,gq),Q(this,WG)}get era(){return OZ(this,`era`)}get eraYear(){return OZ(this,`eraYear`)}get year(){return OZ(this,`year`)}get month(){return OZ(this,`month`)}get monthCode(){return OZ(this,`monthCode`)}get day(){return OZ(this,`day`)}get dayOfWeek(){return OZ(this,`dayOfWeek`)}get dayOfYear(){return OZ(this,`dayOfYear`)}get weekOfYear(){return OZ(this,`weekOfYear`)?.week}get yearOfWeek(){return OZ(this,`weekOfYear`)?.year}get daysInWeek(){return OZ(this,`daysInWeek`)}get daysInMonth(){return OZ(this,`daysInMonth`)}get daysInYear(){return OZ(this,`daysInYear`)}get monthsInYear(){return OZ(this,`monthsInYear`)}get inLeapYear(){return OZ(this,`inLeapYear`)}with(e,t=void 0){if($(this,gq),!ZK(e))throw TypeError(`invalid argument`);Sq(e);let n=Q(this,WG),r=nJ(n,Q(this,VG));return r=jJ(n,r,rJ(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),_J(LJ(n,r,Rq(zX(t))),n)}withCalendar(e){$(this,gq);let t=PJ(e);return _J(Q(this,VG),t)}add(e,t=void 0){return $(this,gq),vX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,gq),vX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,gq),cX(`until`,this,e,t)}since(e,t=void 0){return $(this,gq),cX(`since`,this,e,t)}equals(e){$(this,gq);let t=aJ(e);return kX(Q(this,VG),Q(t,VG))===0&&IJ(Q(this,WG),Q(t,WG))}toString(e=void 0){return $(this,gq),tY(this,Hq(zX(e)))}toJSON(){return $(this,gq),tY(this)}toLocaleString(e=void 0,t=void 0){return $(this,gq),new hZ(e,t).format(this)}valueOf(){WX(`PlainDate`)}toPlainDateTime(e=void 0){$(this,gq);let t=fJ(e);return yJ(Lq(Q(this,VG),t),Q(this,WG))}toZonedDateTime(e){let t,n;if($(this,gq),ZK(e)){let r=e.timeZone;r===void 0?t=BJ(e):(t=BJ(r),n=e.plainTime)}else t=BJ(e);let r=Q(this,VG),i;return n===void 0?i=JJ(t,r):(n=dJ(n),i=GJ(t,Lq(r,Q(n,UG)),`compatible`)),kJ(i,t,Q(this,WG))}toPlainYearMonth(){$(this,gq);let e=Q(this,WG);return TJ(RJ(e,nJ(e,Q(this,VG)),`constrain`),e)}toPlainMonthDay(){$(this,gq);let e=Q(this,WG);return xJ(zJ(e,nJ(e,Q(this,VG)),`constrain`),e)}static from(e,t=void 0){return aJ(e,t)}static compare(e,t){let n=aJ(e),r=aJ(t);return kX(Q(n,VG),Q(r,VG))}};function OZ(e,t){$(e,gq);let n=Q(e,VG);return tJ(e).isoToDate(n,{[t]:!0})[t]}TK(DZ,`Temporal.PlainDate`);var kZ=class{constructor(e,t,n,r=0,i=0,a=0,o=0,s=0,c=0,l=`iso8601`){let u=eq(e),d=eq(t),f=eq(n),p=r===void 0?0:eq(r),m=i===void 0?0:eq(i),h=a===void 0?0:eq(a),g=o===void 0?0:eq(o),_=s===void 0?0:eq(s),v=c===void 0?0:eq(c),y=HX(l===void 0?`iso8601`:iq(l));RY(u,d,f,p,m,h,g,_,v),vJ(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,vq),Q(this,WG)}get year(){return AZ(this,`year`)}get month(){return AZ(this,`month`)}get monthCode(){return AZ(this,`monthCode`)}get day(){return AZ(this,`day`)}get hour(){return jZ(this,`hour`)}get minute(){return jZ(this,`minute`)}get second(){return jZ(this,`second`)}get millisecond(){return jZ(this,`millisecond`)}get microsecond(){return jZ(this,`microsecond`)}get nanosecond(){return jZ(this,`nanosecond`)}get era(){return AZ(this,`era`)}get eraYear(){return AZ(this,`eraYear`)}get dayOfWeek(){return AZ(this,`dayOfWeek`)}get dayOfYear(){return AZ(this,`dayOfYear`)}get weekOfYear(){return AZ(this,`weekOfYear`)?.week}get yearOfWeek(){return AZ(this,`weekOfYear`)?.year}get daysInWeek(){return AZ(this,`daysInWeek`)}get daysInYear(){return AZ(this,`daysInYear`)}get daysInMonth(){return AZ(this,`daysInMonth`)}get monthsInYear(){return AZ(this,`monthsInYear`)}get inLeapYear(){return AZ(this,`inLeapYear`)}with(e,t=void 0){if($(this,vq),!ZK(e))throw TypeError(`invalid argument`);Sq(e);let n=Q(this,WG),r=Q(this,HG),i={...nJ(n,r.isoDate),...r.time};return i=jJ(n,i,rJ(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],`partial`)),yJ(oJ(n,i,Rq(zX(t))),n)}withPlainTime(e=void 0){$(this,vq);let t=fJ(e);return yJ(Lq(Q(this,HG).isoDate,t),Q(this,WG))}withCalendar(e){$(this,vq);let t=PJ(e);return yJ(Q(this,HG),t)}add(e,t=void 0){return $(this,vq),yX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,vq),yX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,vq),lX(`until`,this,e,t)}since(e,t=void 0){return $(this,vq),lX(`since`,this,e,t)}round(e){if($(this,vq),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?BX(`smallestUnit`,e):zX(e),n=Uq(t),r=Bq(t,`halfExpand`),i=Jq(t,`smallestUnit`,`time`,qq,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];Wq(n,a,a===1);let o=Q(this,HG);return yJ(n===1&&i===`nanosecond`?o:TX(o,n,i,r),Q(this,WG))}equals(e){$(this,vq);let t=sJ(e);return jX(Q(this,HG),Q(t,HG))===0&&IJ(Q(this,WG),Q(t,WG))}toString(e=void 0){$(this,vq);let t=zX(e),n=Hq(t),r=Gq(t),i=Bq(t,`trunc`),a=Jq(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}=Kq(a,r),l=TX(Q(this,HG),c,s,i);return zY(l),rY(l,Q(this,WG),o,n)}toJSON(){return $(this,vq),rY(Q(this,HG),Q(this,WG),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,vq),new hZ(e,t).format(this)}valueOf(){WX(`PlainDateTime`)}toZonedDateTime(e,t=void 0){$(this,vq);let n=BJ(e),r=zq(zX(t));return kJ(GJ(n,Q(this,HG),r),n,Q(this,WG))}toPlainDate(){return $(this,vq),_J(Q(this,HG).isoDate,Q(this,WG))}toPlainTime(){return $(this,vq),CJ(Q(this,HG).time)}static from(e,t=void 0){return sJ(e,t)}static compare(e,t){let n=sJ(e),r=sJ(t);return jX(Q(n,HG),Q(r,HG))}};function AZ(e,t){$(e,vq);let n=Q(e,HG).isoDate;return tJ(e).isoToDate(n,{[t]:!0})[t]}function jZ(e,t){return $(e,vq),Q(e,HG).time[t]}TK(kZ,`Temporal.PlainDateTime`);var MZ=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:nq(e),d=t===void 0?0:nq(t),f=n===void 0?0:nq(n),p=r===void 0?0:nq(r),m=i===void 0?0:nq(i),h=a===void 0?0:nq(a),g=o===void 0?0:nq(o),_=s===void 0?0:nq(s),v=c===void 0?0:nq(c),y=l===void 0?0:nq(l);UY(u,d,f,p,m,h,g,_,v,y),xK(this),CK(this,YG,u),CK(this,XG,d),CK(this,ZG,f),CK(this,QG,p),CK(this,$G,m),CK(this,eK,h),CK(this,tK,g),CK(this,nK,_),CK(this,rK,v),CK(this,iK,y)}get years(){return $(this,hq),Q(this,YG)}get months(){return $(this,hq),Q(this,XG)}get weeks(){return $(this,hq),Q(this,ZG)}get days(){return $(this,hq),Q(this,QG)}get hours(){return $(this,hq),Q(this,$G)}get minutes(){return $(this,hq),Q(this,eK)}get seconds(){return $(this,hq),Q(this,tK)}get milliseconds(){return $(this,hq),Q(this,nK)}get microseconds(){return $(this,hq),Q(this,rK)}get nanoseconds(){return $(this,hq),Q(this,iK)}get sign(){return $(this,hq),CY(this)}get blank(){return $(this,hq),CY(this)===0}with(t){$(this,hq);let{years:n=Q(this,YG),months:r=Q(this,XG),weeks:i=Q(this,ZG),days:a=Q(this,QG),hours:o=Q(this,$G),minutes:s=Q(this,eK),seconds:c=Q(this,tK),milliseconds:l=Q(this,nK),microseconds:u=Q(this,rK),nanoseconds:d=Q(this,iK)}=Fq(t);return new e(n,r,i,a,o,s,c,l,u,d)}negated(){return $(this,hq),jY(this)}abs(){return $(this,hq),new e(Math.abs(Q(this,YG)),Math.abs(Q(this,XG)),Math.abs(Q(this,ZG)),Math.abs(Q(this,QG)),Math.abs(Q(this,$G)),Math.abs(Q(this,eK)),Math.abs(Q(this,tK)),Math.abs(Q(this,nK)),Math.abs(Q(this,rK)),Math.abs(Q(this,iK)))}add(e){return $(this,hq),gX(`add`,this,e)}subtract(e){return $(this,hq),gX(`subtract`,this,e)}round(e){if($(this,hq),e===void 0)throw TypeError(`options parameter is required`);let t=Xq(this),n=typeof e==`string`?BX(`smallestUnit`,e):zX(e),r=Jq(n,`largestUnit`,`datetime`,void 0,[`auto`]),{plainRelativeTo:i,zonedRelativeTo:a}=Yq(n),o=Uq(n),s=Bq(n,`halfExpand`),c=Jq(n,`smallestUnit`,`datetime`,void 0),l=!0;c||=(l=!1,`nanosecond`);let u=Zq(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(Zq(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&&Wq(o,f,!1),o>1&&$q(c)===`date`&&r!==c)throw RangeError(`For calendar units with roundingIncrement > 1, use largestUnit = smallestUnit`);if(a){let e=WY(this),t=Q(a,JG),n=Q(a,WG),i=Q(a,BG);return e=aX(i,hX(i,t,n,e),t,n,r,o,c,s),$q(r)===`date`&&(r=`hour`),qY(e,r)}if(i){let e=GY(this),t=pX({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),n=Q(i,VG),a=Q(i,WG),l=MJ(a,n,Iq(e.date,t.deltaDays),`constrain`);return e=iX(Lq(n,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Lq(l,t),a,r,o,c,s),qY(e,r)}if(Qq(t))throw RangeError(`a starting point is required for ${t}s balancing`);if(Qq(r))throw RangeError(`a starting point is required for ${r}s balancing`);let p=GY(this);if(c===`day`){let{quotient:e,remainder:t}=p.time.divmod(WK),n=p.date.days+e+OX(t,`day`);n=CX(n,o,s),p=JY({years:0,months:0,weeks:0,days:n},MK.ZERO)}else p=JY({years:0,months:0,weeks:0,days:0},DX(p.time,o,c,s));return qY(p,r)}total(e){if($(this,hq),e===void 0)throw TypeError(`options argument is required`);let t=typeof e==`string`?BX(`unit`,e):zX(e),{plainRelativeTo:n,zonedRelativeTo:r}=Yq(t),i=Jq(t,`unit`,`datetime`,qq);if(r){let e=WY(this),t=Q(r,JG),n=Q(r,WG),a=Q(r,BG);return function(e,t,n,r,i){return $q(i)===`time`?OX(MK.fromEpochNsDiff(t,e),i):rX(eX(e,t,n,r,i),t,WJ(n,e),n,r,i)}(a,hX(a,t,n,e),t,n,i)}if(n){let e=GY(this),t=pX({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),r=Q(n,VG),a=Q(n,WG),o=MJ(a,r,Iq(e.date,t.deltaDays),`constrain`);return function(e,t,n,r){if(jX(e,t)==0)return 0;zY(e),zY(t);let i=$Y(e,t,n,r);return r===`nanosecond`?Z.default.toNumber(i.time.totalNs):rX(i,gY(t),e,null,n,r)}(Lq(r,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Lq(o,t),a,i)}let a=Xq(this);if(Qq(a))throw RangeError(`a starting point is required for ${a}s total`);if(Qq(i))throw RangeError(`a starting point is required for ${i}s total`);return OX(GY(this).time,i)}toString(e=void 0){$(this,hq);let t=zX(e),n=Gq(t),r=Bq(t,`trunc`),i=Jq(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}=Kq(i,n);if(o===`nanosecond`&&s===1)return eY(this,a);let c=Xq(this),l=WY(this),u=DX(l.time,s,o,r);return l=JY(l.date,u),eY(qY(l,Zq(c,`second`)),a)}toJSON(){return $(this,hq),eY(this,`auto`)}toLocaleString(e=void 0,t=void 0){if($(this,hq),typeof Intl.DurationFormat==`function`){let n=new Intl.DurationFormat(e,t);return TZ.call(n,this)}return console.warn(`Temporal.Duration.prototype.toLocaleString() requires Intl.DurationFormat.`),eY(this,`auto`)}valueOf(){WX(`Duration`)}static from(e){return cJ(e)}static compare(e,t,n=void 0){let r=cJ(e),i=cJ(t),{plainRelativeTo:a,zonedRelativeTo:o}=Yq(zX(n));if(Q(r,YG)===Q(i,YG)&&Q(r,XG)===Q(i,XG)&&Q(r,ZG)===Q(i,ZG)&&Q(r,QG)===Q(i,QG)&&Q(r,$G)===Q(i,$G)&&Q(r,eK)===Q(i,eK)&&Q(r,tK)===Q(i,tK)&&Q(r,nK)===Q(i,nK)&&Q(r,rK)===Q(i,rK)&&Q(r,iK)===Q(i,iK))return 0;let s=Xq(r),c=Xq(i),l=WY(r),u=WY(i);if(o&&($q(s)===`date`||$q(c)===`date`)){let e=Q(o,JG),t=Q(o,WG),n=Q(o,BG),r=hX(n,e,t,l),i=hX(n,e,t,u);return RX(Z.default.toNumber(Z.default.subtract(r,i)))}let d=l.date.days,f=u.date.days;if(Qq(s)||Qq(c)){if(!a)throw RangeError(`A starting point is required for years, months, or weeks comparison`);d=AY(l.date,a),f=AY(u.date,a)}let p=l.time.add24HourDays(d),m=u.time.add24HourDays(f);return p.cmp(m)}};TK(MZ,`Temporal.Duration`);var NZ=class{constructor(e,t,n=`iso8601`,r=1972){let i=eq(e),a=eq(t),o=HX(n===void 0?`iso8601`:iq(n)),s=eq(r);FY(s,i,a),bJ(this,{year:s,month:i,day:a},o)}get monthCode(){return PZ(this,`monthCode`)}get day(){return PZ(this,`day`)}get calendarId(){return $(this,bq),Q(this,WG)}with(e,t=void 0){if($(this,bq),!ZK(e))throw TypeError(`invalid argument`);Sq(e);let n=Q(this,WG),r=nJ(n,Q(this,VG),`month-day`);return r=jJ(n,r,rJ(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),xJ(zJ(n,r,Rq(zX(t))),n)}equals(e){$(this,bq);let t=uJ(e);return kX(Q(this,VG),Q(t,VG))===0&&IJ(Q(this,WG),Q(t,WG))}toString(e=void 0){return $(this,bq),iY(this,Hq(zX(e)))}toJSON(){return $(this,bq),iY(this)}toLocaleString(e=void 0,t=void 0){return $(this,bq),new hZ(e,t).format(this)}valueOf(){WX(`PlainMonthDay`)}toPlainDate(e){if($(this,bq),!ZK(e))throw TypeError(`argument should be an object`);let t=Q(this,WG);return _J(LJ(t,jJ(t,nJ(t,Q(this,VG),`month-day`),rJ(t,e,[`year`],[],[])),`constrain`),t)}static from(e,t=void 0){return uJ(e,t)}};function PZ(e,t){$(e,bq);let n=Q(e,VG);return tJ(e).isoToDate(n,{[t]:!0})[t]}function FZ(e){return WJ(e,IX())}TK(NZ,`Temporal.PlainMonthDay`);var IZ={instant:()=>DJ(IX()),plainDateTimeISO:(e=LX())=>yJ(FZ(BJ(e)),`iso8601`),plainDateISO:(e=LX())=>_J(FZ(BJ(e)).isoDate,`iso8601`),plainTimeISO:(e=LX())=>CJ(FZ(BJ(e)).time),timeZoneId:()=>LX(),zonedDateTimeISO:(e=LX())=>{let t=BJ(e);return kJ(IX(),t,`iso8601`)},[Symbol.toStringTag]:`Temporal.Now`};Object.defineProperty(IZ,Symbol.toStringTag,{value:`Temporal.Now`,writable:!1,enumerable:!1,configurable:!0});var LZ=class e{constructor(e=0,t=0,n=0,r=0,i=0,a=0){let o=e===void 0?0:eq(e),s=t===void 0?0:eq(t),c=n===void 0?0:eq(n),l=r===void 0?0:eq(r),u=i===void 0?0:eq(i),d=a===void 0?0:eq(a);LY(o,s,c,l,u,d),SJ(this,{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d})}get hour(){return $(this,_q),Q(this,UG).hour}get minute(){return $(this,_q),Q(this,UG).minute}get second(){return $(this,_q),Q(this,UG).second}get millisecond(){return $(this,_q),Q(this,UG).millisecond}get microsecond(){return $(this,_q),Q(this,UG).microsecond}get nanosecond(){return $(this,_q),Q(this,UG).nanosecond}with(t,n=void 0){if($(this,_q),!ZK(t))throw TypeError(`invalid argument`);Sq(t);let r=iJ(t,`partial`),i=iJ(this),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=Object.assign(i,r),d=Rq(zX(n));return{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=Pq(a,o,s,c,l,u,d),new e(a,o,s,c,l,u)}add(e){return $(this,_q),bX(`add`,this,e)}subtract(e){return $(this,_q),bX(`subtract`,this,e)}until(e,t=void 0){return $(this,_q),uX(`until`,this,e,t)}since(e,t=void 0){return $(this,_q),uX(`since`,this,e,t)}round(e){if($(this,_q),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?BX(`smallestUnit`,e):zX(e),n=Uq(t),r=Bq(t,`halfExpand`),i=Jq(t,`smallestUnit`,`time`,qq);return Wq(n,{hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i],!1),CJ(EX(Q(this,UG),n,i,r))}equals(e){$(this,_q);let t=dJ(e);return AX(Q(this,UG),Q(t,UG))===0}toString(e=void 0){$(this,_q);let t=zX(e),n=Gq(t),r=Bq(t,`trunc`),i=Jq(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}=Kq(i,n);return nY(EX(Q(this,UG),s,o,r),a)}toJSON(){return $(this,_q),nY(Q(this,UG),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,_q),new hZ(e,t).format(this)}valueOf(){WX(`PlainTime`)}static from(e,t=void 0){return dJ(e,t)}static compare(e,t){let n=dJ(e),r=dJ(t);return AX(Q(n,UG),Q(r,UG))}};TK(LZ,`Temporal.PlainTime`);var RZ=class{constructor(e,t,n=`iso8601`,r=1){let i=eq(e),a=eq(t),o=HX(n===void 0?`iso8601`:iq(n)),s=eq(r);FY(i,a,s),wJ(this,{year:i,month:a,day:s},o)}get year(){return zZ(this,`year`)}get month(){return zZ(this,`month`)}get monthCode(){return zZ(this,`monthCode`)}get calendarId(){return $(this,yq),Q(this,WG)}get era(){return zZ(this,`era`)}get eraYear(){return zZ(this,`eraYear`)}get daysInMonth(){return zZ(this,`daysInMonth`)}get daysInYear(){return zZ(this,`daysInYear`)}get monthsInYear(){return zZ(this,`monthsInYear`)}get inLeapYear(){return zZ(this,`inLeapYear`)}with(e,t=void 0){if($(this,yq),!ZK(e))throw TypeError(`invalid argument`);Sq(e);let n=Q(this,WG),r=nJ(n,Q(this,VG),`year-month`);return r=jJ(n,r,rJ(n,e,[`year`,`month`,`monthCode`],[],`partial`)),TJ(RJ(n,r,Rq(zX(t))),n)}add(e,t=void 0){return $(this,yq),xX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,yq),xX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,yq),dX(`until`,this,e,t)}since(e,t=void 0){return $(this,yq),dX(`since`,this,e,t)}equals(e){$(this,yq);let t=pJ(e);return kX(Q(this,VG),Q(t,VG))===0&&IJ(Q(this,WG),Q(t,WG))}toString(e=void 0){return $(this,yq),aY(this,Hq(zX(e)))}toJSON(){return $(this,yq),aY(this)}toLocaleString(e=void 0,t=void 0){return $(this,yq),new hZ(e,t).format(this)}valueOf(){WX(`PlainYearMonth`)}toPlainDate(e){if($(this,yq),!ZK(e))throw TypeError(`argument should be an object`);let t=Q(this,WG);return _J(LJ(t,jJ(t,nJ(t,Q(this,VG),`year-month`),rJ(t,e,[`day`],[],[])),`constrain`),t)}static from(e,t=void 0){return pJ(e,t)}static compare(e,t){let n=pJ(e),r=pJ(t);return kX(Q(n,VG),Q(r,VG))}};function zZ(e,t){$(e,yq);let n=Q(e,VG);return tJ(e).isoToDate(n,{[t]:!0})[t]}TK(RZ,`Temporal.PlainYearMonth`);var jye=hZ.prototype.resolvedOptions,BZ=class{constructor(e,t,n=`iso8601`){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);let r=FX(e),i=iq(t),{tzName:a,offsetMinutes:o}=Mq(i);if(o===void 0){let e=uY(a);if(!e)throw RangeError(`unknown time zone ${a}`);i=e.identifier}else i=pY(o);OJ(this,r,i,HX(n===void 0?`iso8601`:iq(n)))}get calendarId(){return $(this,xq),Q(this,WG)}get timeZoneId(){return $(this,xq),Q(this,JG)}get year(){return HZ(this,`year`)}get month(){return HZ(this,`month`)}get monthCode(){return HZ(this,`monthCode`)}get day(){return HZ(this,`day`)}get hour(){return UZ(this,`hour`)}get minute(){return UZ(this,`minute`)}get second(){return UZ(this,`second`)}get millisecond(){return UZ(this,`millisecond`)}get microsecond(){return UZ(this,`microsecond`)}get nanosecond(){return UZ(this,`nanosecond`)}get era(){return HZ(this,`era`)}get eraYear(){return HZ(this,`eraYear`)}get epochMilliseconds(){return $(this,xq),NX(Q(this,BG),`floor`)}get epochNanoseconds(){return $(this,xq),MX(Q(this,BG))}get dayOfWeek(){return HZ(this,`dayOfWeek`)}get dayOfYear(){return HZ(this,`dayOfYear`)}get weekOfYear(){return HZ(this,`weekOfYear`)?.week}get yearOfWeek(){return HZ(this,`weekOfYear`)?.year}get hoursInDay(){$(this,xq);let e=Q(this,JG),t=VZ(this).isoDate,n=DY(t.year,t.month,t.day+1),r=JJ(e,t),i=JJ(e,n);return OX(MK.fromEpochNsDiff(i,r),`hour`)}get daysInWeek(){return HZ(this,`daysInWeek`)}get daysInMonth(){return HZ(this,`daysInMonth`)}get daysInYear(){return HZ(this,`daysInYear`)}get monthsInYear(){return HZ(this,`monthsInYear`)}get inLeapYear(){return HZ(this,`inLeapYear`)}get offset(){return $(this,xq),UJ(HJ(Q(this,JG),Q(this,BG)))}get offsetNanoseconds(){return $(this,xq),HJ(Q(this,JG),Q(this,BG))}with(e,t=void 0){if($(this,xq),!ZK(e))throw TypeError(`invalid zoned-date-time-like`);Sq(e);let n=Q(this,WG),r=Q(this,JG),i=HJ(r,Q(this,BG)),a=VZ(this),o={...nJ(n,a.isoDate),...a.time,offset:UJ(i)};o=jJ(n,o,rJ(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`],`partial`));let s=zX(t),c=zq(s),l=Vq(s,`prefer`),u=oJ(n,o,Rq(s)),d=cY(o.offset);return kJ(mJ(u.isoDate,u.time,`option`,d,r,c,l,!1),r,n)}withPlainTime(e=void 0){$(this,xq);let t=Q(this,JG),n=Q(this,WG),r=VZ(this).isoDate,i;return i=e===void 0?JJ(t,r):GJ(t,Lq(r,Q(dJ(e),UG)),`compatible`),kJ(i,t,n)}withTimeZone(e){$(this,xq);let t=BJ(e);return kJ(Q(this,BG),t,Q(this,WG))}withCalendar(e){$(this,xq);let t=PJ(e);return kJ(Q(this,BG),Q(this,JG),t)}add(e,t=void 0){return $(this,xq),SX(`add`,this,e,t)}subtract(e,t=void 0){return $(this,xq),SX(`subtract`,this,e,t)}until(e,t=void 0){return $(this,xq),fX(`until`,this,e,t)}since(e,t=void 0){return $(this,xq),fX(`since`,this,e,t)}round(e){if($(this,xq),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?BX(`smallestUnit`,e):zX(e),n=Uq(t),r=Bq(t,`halfExpand`),i=Jq(t,`smallestUnit`,`time`,qq,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];if(Wq(n,a,a===1),i===`nanosecond`&&n===1)return kJ(Q(this,BG),Q(this,JG),Q(this,WG));let o=Q(this,JG),s=Q(this,BG),c=VZ(this),l;if(i===`day`){let e=c.isoDate,t=DY(e.year,e.month,e.day+1),n=JJ(o,e),i=JJ(o,t),a=Z.default.subtract(i,n);l=MK.fromEpochNsDiff(s,n).round(a,r).addToEpochNs(n)}else{let e=TX(c,n,i,r),t=HJ(o,s);l=mJ(e.isoDate,e.time,`option`,t,o,`compatible`,`prefer`,!1)}return kJ(l,o,Q(this,WG))}equals(e){$(this,xq);let t=hJ(e),n=Q(this,BG),r=Q(t,BG);return!!Z.default.equal(Z.default.BigInt(n),Z.default.BigInt(r))&&!!VJ(Q(this,JG),Q(t,JG))&&IJ(Q(this,WG),Q(t,WG))}toString(e=void 0){$(this,xq);let t=zX(e),n=Hq(t),r=Gq(t),i=function(e){return VX(e,`offset`,[`auto`,`never`],`auto`)}(t),a=Bq(t,`trunc`),o=Jq(t,`smallestUnit`,`time`,void 0);if(o===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let s=function(e){return VX(e,`timeZoneName`,[`auto`,`never`,`critical`],`auto`)}(t),{precision:c,unit:l,increment:u}=Kq(o,r);return oY(this,c,n,s,i,{unit:l,increment:u,roundingMode:a})}toLocaleString(e=void 0,t=void 0){$(this,xq);let n=zX(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,JG),sY(r.timeZone))throw RangeError(`toLocaleString does not currently support offset time zones`);let i=new hZ(e,r),a=jye.call(i).calendar,o=Q(this,WG);if(o!==`iso8601`&&a!==`iso8601`&&!IJ(a,o))throw RangeError(`cannot format ZonedDateTime with calendar ${o} in locale with calendar ${a}`);return i.format(DJ(Q(this,BG)))}toJSON(){return $(this,xq),oY(this,`auto`)}valueOf(){WX(`ZonedDateTime`)}startOfDay(){$(this,xq);let e=Q(this,JG);return kJ(JJ(e,VZ(this).isoDate),e,Q(this,WG))}getTimeZoneTransition(e){$(this,xq);let t=Q(this,JG);if(e===void 0)throw TypeError(`options parameter is required`);let n=VX(typeof e==`string`?BX(`direction`,e):zX(e),`direction`,[`next`,`previous`],qq);if(n===void 0)throw TypeError(`direction option is required`);if(sY(t)||t===`UTC`)return null;let r=Q(this,BG),i=n===`next`?vY(t,r):yY(t,r);return i===null?null:kJ(i,t,Q(this,WG))}toInstant(){return $(this,xq),DJ(Q(this,BG))}toPlainDate(){return $(this,xq),_J(VZ(this).isoDate,Q(this,WG))}toPlainTime(){return $(this,xq),CJ(VZ(this).time)}toPlainDateTime(){return $(this,xq),yJ(VZ(this),Q(this,WG))}static from(e,t=void 0){return hJ(e,t)}static compare(e,t){let n=hJ(e),r=hJ(t),i=Q(n,BG),a=Q(r,BG);return Z.default.lessThan(Z.default.BigInt(i),Z.default.BigInt(a))?-1:+!!Z.default.greaterThan(Z.default.BigInt(i),Z.default.BigInt(a))}};function VZ(e){return WJ(Q(e,JG),Q(e,BG))}function HZ(e,t){$(e,xq);let n=VZ(e).isoDate;return tJ(e).isoToDate(n,{[t]:!0})[t]}function UZ(e,t){return $(e,xq),VZ(e).time[t]}TK(BZ,`Temporal.ZonedDateTime`);var Mye=Object.freeze({__proto__:null,Duration:MZ,Instant:EZ,Now:IZ,PlainDate:DZ,PlainDateTime:kZ,PlainMonthDay:NZ,PlainTime:LZ,PlainYearMonth:RZ,ZonedDateTime:BZ});(class{toTemporalInstant(){return DJ(PX(Date.prototype.valueOf.call(this)))}}).prototype.toTemporalInstant;var Nye=[EZ,DZ,kZ,MZ,NZ,LZ,RZ,BZ];for(let e of Nye){let t=Object.getOwnPropertyDescriptor(e,`prototype`);(t.configurable||t.enumerable||t.writable)&&(t.configurable=!1,t.enumerable=!1,t.writable=!1,Object.defineProperty(e,"prototype",t))}function Pye(e,t){let n=new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).formatToParts(e),r=e=>{let t=n.find(t=>t.type===e);if(!t)throw Error(`This timezone isn't recognised. Enter a timezone name like Europe/Tirane.`);return t.value};return`${r(`year`)}-${r(`month`)}-${r(`day`)}T${r(`hour`)}:${r(`minute`)}`}function Fye(e,t){return Pye(new Date(e),t)}function Iye(e,t){if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(e))throw Error(`Pick a date and time for the one-off run.`);let n=Mye.PlainDateTime.from(e,{overflow:`reject`}),r=n.toZonedDateTime(t,{disambiguation:`compatible`});if(!n.equals(r.toPlainDateTime()))throw Error(`That time is skipped in this timezone (a clock change). Choose another time.`);return r.toInstant().toString({smallestUnit:`millisecond`})}function WZ(e,t){return new Intl.DateTimeFormat(void 0,{timeZone:t,dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}function Lye(e,t){return new Intl.DateTimeFormat(void 0,{timeZone:t,year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,timeZoneName:`short`}).format(new Date(e))}var GZ={"claude-code":{name:`Claude Code`,command:`claude auth login`},codex:{name:`Codex`,command:`codex login`},gemini:{name:`Gemini`,command:`gemini`}},Rye=/not signed in|sign-in has expired|not logged in|run\s+"?(?:codex login|claude auth login)|authentication required/i,zye=/ENOSPC|no space left on device|disk (?:is )?full|not enough (?:free )?(?:disk )?space/i,Bye=/refused to make|content (?:rules|policy|filter)|safety (?:system|filter)|flagged|moderation/i,Vye=/\bunknown model\b|\bmodel\b[^\n]{0,80}?\b(?:not found|does not exist|retired|deprecated|decommissioned|no longer (?:available|supported)|is not available)/i,Hye=/did not accept the API key|API key is saved|invalid api key|key may be wrong/i,Uye=[`images`,`thumbnail`],Wye=/^Short \d+ image \d+:/;function KZ(e){let t=e.reason??``,n=Gye(e.provider,t);if(n!==void 0&&(Rye.test(t)||e.kind===`auth`))return{kind:`sign-in`,label:`Sign in to ${GZ[n].name}`,cli:n,command:GZ[n].command};if(zye.test(t))return{kind:`free-space`,label:`Free space`};if(e.kind===`refusal`||Bye.test(t))return Uye.includes(e.stage)||e.stage===`video`&&Wye.test(t)?{kind:`refused`,label:`Soften and retry`,soften:!0}:{kind:`refused`,label:`Edit the prompt`,soften:!1};if(Vye.test(t))return{kind:`switch-model`,label:`Switch model`};if(e.kind===`auth`||e.kind===`missing_key`||Hye.test(t)){let t=Kye(e.provider);return{kind:`provider-settings`,label:t===void 0?`Open Settings → Providers`:`Open Settings → Providers → ${t}`,provider:e.provider??``}}}function Gye(e,t){if(e===`claude-code`||e===`gemini`)return e;if(e===`codex`||e===`codex-image`||/Codex CLI/.test(t))return`codex`;if(/Claude Code CLI/.test(t))return`claude-code`;if(/Gemini CLI/.test(t))return`gemini`}function Kye(e){return RA.find(t=>t.id===e)?.displayName}function qye(e,t){switch(t){case`audio`:return e.audio?.provider;case`images`:case`thumbnail`:return e.images?.provider;case`research`:case`article`:return e.llm?.provider;default:return}}function Jye(e){let t=e.topics.error;if(t!==null)return KZ({stage:`article`,reason:t,provider:e.topicGeneration.llm?.provider})}function qZ({schedule:e,title:t,retry:n,className:r}){if(e.topics.error===null)return null;let i=Jye(e);return(0,h.jsx)(dM,{tone:`danger`,title:t,...r===void 0?{}:{className:r},...i===void 0?{}:{actions:(0,h.jsx)(Sz,{fix:i,retry:n,variant:`secondary`,size:`small`})},children:e.topics.error})}var JZ=e=>e.length===1?`“${e[0]?.title??``}”`:SG(e.length,`topic`,`topics`);function Yye({schedule:e}){let{api:t}=B(),n=_(),[r,i]=(0,m.useState)(null),a=Iv(),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(!1),u=e.deletedAt===null&&(e.status===`active`||e.status===`paused`),d=F({queryKey:[...MT(e.id),e.topics.held,e.topics.generatedAt],enabled:u&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await NT(t,e.id);if(!n.ok)throw Error(n.message);return n.value}}),f=F({queryKey:[`project-template`,e.templateId],enabled:u&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await jO(t,e.templateId);if(!n.ok)throw Error(n.message);return n.value}}).data?.document.form,p=(f===void 0?[]:$W(f)).filter(t=>t!==e.topicKeyword),g=t=>e.values[t]??f?.values[t]??``,v=d.data??[],y=_G(v.map(e=>e.id)),b=I({mutationFn:e=>e(),onSuccess:e=>{i(e.ok?null:e.message),e.ok&&s(null)},onError:e=>i(e.message),onSettled:async()=>{await Promise.all([n.invalidateQueries({queryKey:DT}),n.invalidateQueries({queryKey:MT(e.id)}),n.invalidateQueries({queryKey:BT})])}}),x=b.isPending,S=(e,t)=>b.mutate(e,{onSuccess:e=>{e.ok&&t!==void 0&&(y.clear(),a(t.message,`success`,t.undo===void 0?void 0:{label:`Undo`,run:t.undo}))}}),C=n=>S(()=>sce(t,e.id,n.map(e=>e.id)),{message:`Turned down ${JZ(n)}. Later generations won't suggest ${n.length===1?`it`:`them`} again.`,undo:()=>S(()=>cce(t,e.id,n),{message:`${JZ(n)} ${n.length===1?`is`:`are`} waiting again.`})}),w=n=>S(()=>n.length===1&&n[0]!==void 0?IT(t,e.id,n[0].id):oce(t,e.id,n.map(e=>e.id)),{message:`Approved ${JZ(n)}: added to the end of the queue.`}),T=v.filter(e=>y.has(e.id));if(!u||e.topicGeneration.mode===`off`)return null;let{topics:E}=e;return(0,h.jsxs)(`section`,{"aria-label":`Topic generation`,children:[(0,h.jsx)(gG,{className:`my-6`}),(0,h.jsxs)(U,{as:`h3`,title:`Topic generation`,meta:`${E.generatingSince===null?E.generatedAt===null?`No topics generated yet.`:`Topics last generated ${Lye(E.generatedAt,e.timezone)}.`:`Generating topics now…`} Keeps at least ${String(e.topicGeneration.keepAtLeast)} ${e.topicGeneration.mode===`hold`?`queued or waiting`:`queued`}.`,children:[(0,h.jsx)(H,{id:`planning.schedule.generate-now`}),(0,h.jsx)(z,{disabled:x||E.generatingSince!==null,disabledReason:`Topics are being generated now`,onClick:()=>b.mutate(()=>FT(t,e.id)),children:`Generate topics now`})]}),(0,h.jsx)(qZ,{schedule:e,title:`The last topic generation failed.`,className:`mt-3`,retry:{run:()=>b.mutate(()=>FT(t,e.id)),busy:x||E.generatingSince!==null}}),r===null?null:(0,h.jsx)(dM,{tone:`danger`,title:`That didn't work.`,className:`mt-3`,children:r}),e.topicGeneration.mode===`hold`?(0,h.jsxs)(`div`,{className:`mt-4`,...Ny,children:[(0,h.jsxs)(U,{as:`h3`,title:`Topics waiting · ${String(v.length)}`,info:`planning.schedule.held`,children:[(0,h.jsx)(z,{variant:`primary`,disabled:x||v.length===0,disabledReason:`Nothing is waiting`,onClick:()=>S(()=>LT(t,e.id),{message:`Approved ${JZ(v)}: added to the end of the queue.`}),children:`Approve all`}),(0,h.jsx)(z,{variant:`quiet`,disabled:x||v.length===0,disabledReason:`Nothing is waiting`,onClick:()=>l(!0),children:`Reject all`})]}),d.error?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-danger`,children:`The waiting topics couldn't be loaded: ${d.error.message} Reload the page to try again.`}):v.length===0?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-ink-3`,children:`Nothing is waiting. New topics appear here for you to approve.`}):(0,h.jsxs)(`div`,{onKeyDown:y.onKeyDown,children:[v.length>1?(0,h.jsx)(xG,{className:`mt-2`,selection:y,total:v.length,noun:[`topic waiting`,`topics waiting`],actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{size:`small`,disabled:x||T.length===0,disabledReason:`Tick the topics to approve`,onClick:()=>w(T),children:`Approve selected`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:x||T.length===0,disabledReason:`Tick the topics to turn down`,onClick:()=>C(T),children:`Reject selected`})]})}):null,(0,h.jsx)(KL,{label:`Topics waiting`,className:`mt-2 [&_.sl-row__actions]:flex-wrap`,children:v.map(n=>(0,h.jsx)(wG,{topic:n,editing:o?.id===n.id?o:void 0,keywords:p,everyRun:g,busy:x,selection:y,onEdit:s,onCancel:()=>s(null),onSave:()=>{o!==null&&b.mutate(()=>uce(t,e.id,n.id,o.title.trim(),Object.fromEntries(Object.entries(o.values).filter(([,e])=>e.trim()!==``))))},onApprove:()=>w([n]),onReject:()=>C([n])},n.id))})]}),(0,h.jsx)(Qv,{open:c,title:`Reject all ${SG(v.length,`waiting topic`,`waiting topics`)}?`,consequence:`Turns down the ${SG(v.length,`topic`,`topics`)} waiting for ${e.name} now (topics generated after this list was shown are not included). Later generations won't suggest them again; Undo in the message that follows brings them back.`,confirmLabel:`Reject ${SG(v.length,`topic`,`topics`)}`,cancelLabel:`Keep them waiting`,pending:x,onCancel:()=>l(!1),onConfirm:()=>{l(!1),C(v)}})]}):null]})}function YZ(e){return e.filter(e=>e.deletedAt===null&&e.topicGeneration.mode!==`off`&&(e.status===`active`||e.status===`paused`))}function Xye({schedules:e}){let t=YZ(e),n=e.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:t.length===0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(U,{title:`Suggested topics`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No schedule suggests its own topics yet. Turn on topic generation in a schedule and its suggestions wait here for you.`}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:n.length===0?(0,h.jsx)(GO,{to:`/calendar`,search:{tab:`schedules`},children:`Open schedules`}):n.slice(0,4).map(e=>(0,h.jsxs)(GO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:[`Open `,e.name]},e.id))})]}):t.map((e,t)=>(0,h.jsx)(Zye,{schedule:e,first:t===0},e.id))})}function Zye({schedule:e,first:t}){let{api:n}=B(),r=_(),i=Iv(),a=F({queryKey:[...MT(e.id),e.topics.held,e.version],queryFn:async()=>{let t=await NT(n,e.id);if(!t.ok)throw Error(t.message);return t.value},enabled:e.topics.held>0}),o=I({mutationFn:e=>e(),onSuccess:e=>{e.ok||i(e.message,`error`)},onError:e=>i(`The topics weren't changed: ${e.message} Try again in a moment.`,`error`),onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:DT}),r.invalidateQueries({queryKey:BT}),r.invalidateQueries({queryKey:MT(e.id)})])}}),s=e.topics.held>0?a.data??[]:[],c=()=>o.mutate(()=>LT(n,e.id));sb({id:`calendar.approve-all.${e.id}`,title:`Queue all suggested topics`,group:`Calendar`,context:e.name,keywords:[`approve`,`suggestions`,`topics`],run:c});let l=e.topics.generatingSince!==null,u=e.topicGeneration.mode===`hold`;return(0,h.jsxs)(`section`,{"aria-label":`Suggested topics for ${e.name}`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{title:t?`Suggested topics`:e.name,kicker:t?e.name:void 0,meta:`From the series brief · not made or queued before`,info:`planning.schedule.held`,children:s.length>0?(0,h.jsx)(z,{size:`small`,variant:`secondary`,disabled:o.isPending,onClick:c,children:`Queue all ${String(s.length)}`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(H,{id:`planning.schedule.generate-now`,label:`Suggest topics now`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:o.isPending||l,disabledReason:l?`Slopify is suggesting topics now.`:`Working…`,onClick:()=>o.mutate(()=>FT(n,e.id)),children:l?`Suggesting…`:`Suggest topics now`})]})}),(0,h.jsx)(qZ,{schedule:e,title:`The last suggestion failed.`,retry:{run:()=>o.mutate(()=>FT(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)(KL,{label:`Suggestions for ${e.name}`,children:s.map(t=>(0,h.jsx)(qL,{title:t.title,meta:CG(t.values),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:o.isPending,onClick:()=>o.mutate(()=>IT(n,e.id,t.id)),"aria-label":`Queue ${t.title}`,children:`Queue`}),(0,h.jsx)(Mv,{size:`small`,label:`Reject ${t.title}`,disabled:o.isPending,onClick:()=>o.mutate(()=>lce(n,e.id,t.id)),children:(0,h.jsx)(kl,{"aria-hidden":`true`,strokeWidth:1.75})})]})},t.id))}),(0,h.jsx)(dM,{title:`Keeps at least ${String(e.topicGeneration.keepAtLeast)} ${e.topicGeneration.keepAtLeast===1?`topic`:`topics`} queued.`,children:u?`New suggestions wait here for you. Change this under Schedules → Edit.`:`New suggestions join the queue straight away. Change this under Schedules → Edit.`})]})}function Qye(e,t){if(e.kind===`move`)return{kind:`move`,scheduleId:e.scheduleId,baseVersion:t.source.version,from:e.to,to:e.from};let n=t.target??t.source;return{kind:`transfer`,scheduleId:e.targetId,baseVersion:n.version,index:e.position??n.items.length-1,targetId:e.scheduleId,position:e.index}}function $ye(e,t){if(t.kind!==`move`)return e;let n=e.runs.filter(e=>e.scheduleId===t.scheduleId&&e.index!==null).toSorted((e,t)=>(e.index??0)-(t.index??0)),r=n.map(ebe),[i]=r.splice(t.from,1);if(i===void 0)return e;r.splice(t.to,0,i);let a=new Map(n.map((e,t)=>[e,r[t]]));return{...e,runs:e.runs.map(e=>{let t=a.get(e);return t===void 0?e:{...e,...t}})}}function ebe(e){return{topic:e.topic,topicSource:e.topicSource,renderedTitle:e.renderedTitle,prepared:e.prepared}}function tbe(e,t){let{api:n}=B(),r=_(),i=Iv(),a=I({mutationFn:async({drop:e})=>{if(e.kind===`move`){let t=await RT(n,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to});return t.ok?{ok:!0,value:{source:t.value}}:t}return dce(n,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}})},onMutate:async({drop:n})=>{await r.cancelQueries({queryKey:e});let i=r.getQueryData(e);return i!==void 0&&r.setQueryData(e,$ye(i,n)),t(null),{before:i}},onSuccess:(n,o,s)=>{if(!n.ok){s.before!==void 0&&r.setQueryData(e,s.before),t(`${o.title} wasn't moved: ${n.message} The calendar shows where it is now; move it again if you still want to.`);return}if(o.undo===!0){i(`${o.title} is back where it was.`,`success`);return}i(`Moved ${o.title} to ${o.where}.`,`success`,{label:`Undo`,run:()=>a.mutate({drop:Qye(o.drop,n.value),title:o.title,where:``,undo:!0})})},onError:(n,i,a)=>{a?.before!==void 0&&r.setQueryData(e,a.before),t(`${i.title} wasn't moved: ${n.message} The calendar has been read again; try the move once more.`)},onSettled:async()=>{await Promise.all([r.invalidateQueries({queryKey:BT}),r.invalidateQueries({queryKey:DT})])}});return a}var XZ=[`trash`];async function ZZ(e){return(await L(await e.client.trash.$get())).items}async function QZ(e,t,n){return(await L(await e.client.trash[`:kind`][`:id`].restore.$post({param:{kind:t,id:n}}))).restored}async function nbe(e,t,n){let r=await e.client.trash[`:kind`][`:id`].$delete({param:{kind:t,id:n}});if(!r.ok)throw await po(r)}async function $Z(e,t){return L(await e.client.trash.bulk.restore.$post({json:{items:[...t]}}))}async function rbe(e,t){return L(await e.client.trash.bulk.delete.$post({json:{items:[...t]}}))}var eQ=[`batch-queue`];function ibe(){let{api:e}=B(),t=F({queryKey:eQ,queryFn:async()=>L(await e.fetch(`${e.origin}/api/projects/queue`)),refetchInterval:2e3,retry:!1}),n=F(gy(e)),r=t.data?.queue.length,i=r===void 0?t.error===null?`…`:`?`:String(r);return(0,h.jsxs)(Ay,{children:[(0,h.jsx)(jy,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,disabled:r===0&&t.error===null,disabledReason:`Nothing is queued`,"aria-label":r===void 0?t.error===null?`Video queue: loading`:`Video queue: didn't load`:`Video queue: ${String(r)} remaining`,children:[(0,h.jsx)(il,{"aria-hidden":`true`,className:`size-4`}),(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[`Queue · `,i]})]})}),(0,h.jsxs)(My,{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:Dy(`play.queue`).body}),(0,h.jsx)(`div`,{className:`px-3 py-2 empty:hidden`,children:(0,h.jsx)(NL,{query:t,what:`The video queue`,compact:!0,loading:null,children:()=>null})}),(0,h.jsx)(abe,{queue:t.data?.queue??[],projects:n.data?.projects})]})]})}function abe({queue:e,projects:t}){let n=e.filter(e=>e.state===`queued`);return(0,h.jsx)(`ol`,{className:`max-h-60 overflow-y-auto px-4 py-2`,children:e.map((e,r)=>{let i=t?.find(t=>t.id===e.projectId),a=i?.title??`Video`;return(0,h.jsxs)(`li`,{className:`flex items-center justify-between gap-2 py-1 text-small`,children:[(0,h.jsxs)(pa,{className:`min-w-0 truncate`,to:`/projects/$projectId`,params:{projectId:e.projectId},children:[r+1,`. `,a]}),(0,h.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-ink-2`,children:[i?.status===`paused`?`Paused`:e.state===`active`?`Active`:`Queued`,e.state===`queued`?(0,h.jsx)(tQ,{projectId:e.projectId,title:a,place:n.indexOf(e),waiting:n.length}):null]})]},e.projectId)})})}function tQ({projectId:e,title:t,place:n,waiting:r}){let{api:i}=B(),a=_(),o=Iv(),s=()=>{a.invalidateQueries({queryKey:eQ}),a.invalidateQueries({queryKey:[`projects`]}),a.invalidateQueries({queryKey:[`calendar`]})},c=I({mutationFn:t=>obe(i,e,t),onSuccess:s,onError:e=>{s(),o(`${t} wasn't moved: ${e.message}`,`error`)}}),l=I({mutationFn:()=>Fo(i,e),onSuccess:()=>{s(),o(`${t} left the queue and is in Settings → Trash.`,`success`,{label:`Undo`,run:()=>void QZ(i,`project`,e).then(s,e=>o(`${t} wasn't put back: ${e.message} Restore it from Settings → Trash.`,`error`))})},onError:e=>o(`${t} wasn't removed: ${e.message}`,`error`)}),u=c.isPending||l.isPending;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mv,{size:`small`,label:`Move ${t} earlier in the queue`,disabled:u||n<=0,onClick:()=>c.mutate(-1),children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Mv,{size:`small`,label:`Move ${t} later in the queue`,disabled:u||n>=r-1,onClick:()=>c.mutate(1),children:(0,h.jsx)(bc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Mv,{size:`small`,label:`Remove ${t} from the queue`,disabled:u,onClick:()=>l.mutate(),children:(0,h.jsx)(kl,{"aria-hidden":`true`,strokeWidth:1.75})})]})}async function obe(e,t,n){return L(await e.fetch(`${e.origin}/api/projects/queue/${encodeURIComponent(t)}/move`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({by:n})}))}var nQ=`sl-tab inline-flex items-center gap-[6px]`;function rQ({items:e,value:t,onChange:n,label:r,idPrefix:i,trailing:a,className:o}){let s=(0,m.useRef)(null);return dG(s,t),(0,h.jsxs)(`div`,{className:R(`flex min-w-0 items-end gap-3 border-b border-line`,o),"data-slot":`tabs`,children:[(0,h.jsx)(`div`,{ref:s,role:`tablist`,"aria-label":r,onKeyDown:r=>{let a=e.filter(e=>!e.disabled),o=a.findIndex(e=>e.id===t),c=r.key===`ArrowRight`?a[(o+1)%a.length]:r.key===`ArrowLeft`?a[(o-1+a.length)%a.length]:r.key===`Home`?a[0]:r.key===`End`?a[a.length-1]:void 0;c&&(r.preventDefault(),n(c.id),s.current?.querySelector(`#${i}-tab-${c.id}`)?.focus())},className:`sl-tabs min-w-0 flex-1 border-b-0`,children:e.map(e=>(0,h.jsxs)(`button`,{id:`${i}-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":e.id===t,"aria-controls":`${i}-panel-${e.id}`,tabIndex:e.id===t?0:-1,disabled:e.disabled,onClick:()=>n(e.id),className:nQ,children:[e.label,e.badge===void 0?null:(0,h.jsx)(`span`,{className:`sl-tab__count ml-0`,children:e.badge})]},e.id))}),a?(0,h.jsx)(`div`,{className:`flex shrink-0 items-center gap-2 pb-1`,children:a}):null]})}function sbe({items:e,label:t,className:n}){let r=(0,m.useRef)(null);return dG(r,Ha({select:e=>e.pathname})),(0,h.jsx)(`nav`,{ref:r,"aria-label":t,className:R(`sl-tabs min-w-0`,n),children:e.map(e=>(0,h.jsx)(pa,{to:e.to,...e.search?{search:e.search}:{},activeOptions:{exact:!1,includeSearch:!1},className:nQ,activeProps:{"aria-current":`page`},children:e.label},e.to))})}function iQ({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 aQ({title:e,children:t,actions:n,className:r}){return(0,h.jsxs)(`div`,{className:R(`sl-empty`,r),"data-slot":`empty-state`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title`,children:e}),t===void 0?null:(0,h.jsx)(`p`,{children:t}),n===void 0?null:(0,h.jsx)(`div`,{className:`sl-btn-row`,children:n})]})}function oQ(e){return e.channelId??`00000000-0000-4000-8000-000000000001`}function cbe({channelId:e}){let{api:t}=B(),n=_(),r=F(AO(t)),i=F(Yy(t)),a=I({mutationFn:e=>Sre(t,e.templateId,e.channelId),onSettled:()=>Promise.all([n.invalidateQueries({queryKey:EO}),n.invalidateQueries({queryKey:Gy})])}),o=(r.data??[]).filter(t=>oQ(t)===e);return(0,h.jsxs)(`div`,{...Ny,children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:[`Runs from these templates use this channel's brand kit and cast. Save new ones from Play in`,` `,(0,h.jsx)(pa,{to:`/templates`,className:`underline`,children:`Library → Templates`}),`. Move to sends a template and its schedules to another channel.`,` `,(0,h.jsx)(H,{id:`planning.channel.template-move`,className:`-my-1 align-middle`})]}),(0,h.jsx)(SR,{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)(aQ,{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)(KL,{label:`Channel templates`,className:`[&_.sl-row__actions]:flex-wrap`,children:o.map(t=>(0,h.jsx)(qL,{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)(sL,{"aria-label":`Channel of ${t.name}`,value:e,disabled:a.isPending,onChange:e=>a.mutate({templateId:t.id,channelId:e.target.value}),options:(i.data??[]).map(e=>({value:e.id,label:e.name}))})]})},t.id))}):null]})}function lbe({channelId:e}){let{api:t}=B(),n=F(AO(t)),r=F(OT(t)),i=new Set((n.data??[]).filter(t=>oQ(t)===e).map(e=>e.id)),a=(r.data??[]).filter(e=>e.deletedAt===null&&i.has(e.templateId));return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:[`A schedule belongs to the channel of the template it runs. Create and change schedules in`,` `,(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`schedules`},className:`underline`,children:`Calendar → Schedules`}),`.`]}),(0,h.jsx)(SR,{tone:r.error?`error`:`info`,className:`mb-2`,children:r.error?.message}),r.data&&a.length===0?(0,h.jsx)(aQ,{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)(KL,{label:`Channel schedules`,children:a.map(e=>(0,h.jsx)(qL,{title:(0,h.jsx)(GO,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name}),meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ek,{tone:BL[e.status].tone,children:BL[e.status].word}),` · ${e.nextRunAt===null?`No next run`:`Next run ${WZ(e.nextRunAt,e.timezone)}`} · ${String(e.items.length)} queued`]})},e.id))}):null]})}function sQ(e,t,n){let r=new Intl.NumberFormat(`en-US`),i=e-t,a=`${r.format(e)} of ${r.format(t)} ${n}`;return i>0?`${a}: ${r.format(i)} over the limit, shorten it to save.`:a}function cQ(e){return $E(e)?`script`:`article`}function ube(e){let{form:t}=e,n=[],r=[];if(pQ(n,t.title),cD(t)&&pQ(n,dQ(e.prompts,`narration`,t.narrationPrompt??``)),t.sources.article===`generate`&&pQ(n,dQ(e.prompts,cQ(t),t.articlePrompt)),t.sources.audio===`generate`&&(pQ(n,fQ(e.entries,`intro`,t.intro)),pQ(n,fQ(e.entries,`outro`,t.outro))),lD(t)&&pQ(n,dQ(e.prompts,`description`,t.descriptionPrompt??``)),Qk(t)&&(pQ(n,dQ(e.prompts,`shorts`,t.shorts?.prompt??``)),pQ(r,dQ(e.prompts,`image`,t.shorts?.imagePrompt??``))),t.sources.images===`generate`){for(let n of t.imagePrompts)pQ(r,dQ(e.prompts,`image`,n.name));t.reference?.source===`prompt`&&pQ(r,dQ(e.prompts,`image`,t.reference.prompt))}return(t.sources.thumbnail===`from_prompt`||t.sources.thumbnail===`prompt_by_llm`)&&pQ(r,dQ(e.prompts,`thumbnail`,t.thumbnailPrompt)),YW(n,r)}function dbe(e){let t=ube(e),n={form:e.form,entries:e.entries,slots:t.map(e=>e.name),silenceGapSeconds:e.silenceGapSeconds},r=rA(n),i=ule({draft:r,staged:Tue(e.form.provided),requiredSlots:n.slots}),a=Zk(r.subtitles??e.form.subtitles)?i:{ok:!1,fields:[...i.ok?[]:i.fields,{field:`subtitles.fontSize`,message:`Choose a whole subtitle font size from 16 to 120.`}]};return{fields:t,draft:r,result:a,blocker:fbe(e.form,a)}}var lQ=`sources,provided.research,articlePrompt,provided.article,audio,provided.audio,voices,narrationPrompt,imagePrompts,images,provided.images,reference,provided.reference,thumbnailPrompt,provided.thumbnail,subtitles,title,intro,outro,llm,values,silenceGapSeconds,edgeSilenceSeconds,imageSeconds,zoomPercent,motionStyle,youtubeDescription,descriptionPrompt,shorts.enabled,shorts.count,shorts.minSeconds,shorts.maxSeconds,shorts.prompt,shorts.imagePrompt,shorts.speed,shorts.musicVolume,shorts.music,shorts.fullVideoLink,videoEdit.transitionSeconds,videoEdit.chapterCards,videoEdit.animate,videoEdit.animateEvery,videoEdit.animateModel,ambientBed,sentencePauseSeconds,paragraphPauseSeconds,loudness.videoLufs,loudness.audioFilesLufs`.split(`,`);function fbe(e,t){let n=pbe(e);if(n!==void 0)return n;if(t.ok)return;let r=[...t.fields].sort((e,t)=>uQ(e.field)-uQ(t.field))[0];return r===void 0?void 0:{field:r.field,hint:mbe(e,r)}}function pbe(e){let{sources:t,provided:n}=e,r=[];if(t.audio===`provide`&&n.audio!==void 0&&r.push(n.audio),t.images===`provide`&&r.push(...n.images),t.thumbnail===`provide`&&n.thumbnail!==void 0&&r.push(n.thumbnail),t.images===`generate`&&e.reference?.source===`provide`&&n.reference!==void 0&&r.push(n.reference),Qk(e)&&n.shortsMusic!==void 0&&r.push(n.shortsMusic),$k(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 uQ(e){let t=lQ.length;for(let[n,r]of lQ.entries())(e===r||e.startsWith(`${r}.`))&&n<t&&(t=n);return t}function mbe(e,t){if(t.field.startsWith(`values.`))return`Fill ${t.field.slice(7)} to play`;if(t.field.startsWith(`imagePrompts.`))return t.field.endsWith(`.number`)?`Set a Number between 1 and 20 to play`:`Pick an image prompt to play`;switch(t.field){case`title`:return e.title.trim()===``?`Name the video to play`:`Shorten the title to 200 characters to play`;case`imagePrompts`:return e.imagePrompts.length===0?`Tick an image prompt to play`:`Lower the Numbers to play: a run makes at most 60 images`;case`llm`:return`Pick an LLM provider and model to play`;case`articlePrompt`:return cQ(e)===`script`?`Pick a script prompt to play`:`Pick an article prompt to play`;case`audio`:return`Pick a narration provider to play`;case`audio.voice`:return`Pick a voice to play`;case`images`:return`Pick an image provider and model to play`;case`thumbnailPrompt`:return`Pick a thumbnail prompt to play`;case`youtubeDescription`:return`Turn narration on, or the YouTube description off, to play`;case`shorts.enabled`:return`Turn narration on, or Shorts off, to play`;case`shorts.count`:return`Set how many shorts to make to play`;case`shorts.minSeconds`:case`shorts.maxSeconds`:return`Set the shorts' length to play`;case`shorts.speed`:return`Choose the shorts' speed to play`;case`shorts.musicVolume`:return`Set the shorts' music volume to play`;case`shorts.music`:return`Attach the shorts' background music again, or remove it, to play`;case`shorts.fullVideoLink`:return`Fix the full video link to play`;case`provided.research`:return`Paste your text under Article to play`;case`provided.article`:return`Paste the article to play`;case`provided.audio`:return`Attach the narration audio to play`;case`provided.images`:return e.provided.images.length>60?`Remove images to play: a run holds at most 60`:`Attach at least one image to play`;case`provided.thumbnail`:return`Attach the thumbnail image to play`;case`reference.prompt`:return`Pick the establishing image's prompt to play`;case`provided.reference`:return`Attach the establishing image to play`;default:return t.message}}function dQ(e,t,n){if(n!==``)return e.find(e=>e.kind===t&&e.name===n)?.body}function fQ(e,t,n){if(n!==``)return e.find(e=>e.category===t&&e.name===n)?.body}function pQ(e,t){t!==void 0&&e.push(t)}function mQ(e){let t=new Map,n=(e,n)=>{if(e)for(let r of qW(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`),cD(r)&&n(dQ(i,`narration`,r.narrationPrompt??``),`Narration Preparation`),r.sources.article===`generate`&&n(dQ(i,cQ(r),r.articlePrompt),`Article`),r.sources.images===`generate`){for(let e of r.imagePrompts)n(dQ(i,`image`,e.name),`Image: ${e.name}`);r.reference?.source===`prompt`&&n(dQ(i,`image`,r.reference.prompt),`Establishing image`)}if((r.sources.thumbnail===`from_prompt`||r.sources.thumbnail===`prompt_by_llm`)&&n(dQ(i,`thumbnail`,r.thumbnailPrompt),`Thumbnail`),r.sources.audio===`generate`)for(let e of[`intro`,`outro`])n(fQ(a,e,r[e]),e===`intro`?`Intro`:`Outro`);return lD(r)&&n(dQ(i,`description`,r.descriptionPrompt??``),`YouTube description`),Qk(r)&&(n(dQ(i,`shorts`,r.shorts?.prompt??``),`Shorts`),n(dQ(i,`image`,r.shorts?.imagePrompt??``),`Shorts images`)),t}var hQ=[`name`,`template`,`once`,`time`,`weekdays`,`timezone`,`spend`,`topics`,`brief`,`generation`],hbe={name:`schedule-name`,template:`schedule-template`,once:`schedule-once`,time:`schedule-time`,weekdays:`schedule-weekdays`,timezone:`schedule-timezone`,spend:`schedule-spend`,topics:`schedule-topics`,brief:`schedule-brief`,generation:`schedule-generation`},gbe={name:`Name`,template:`Template`,once:`Run at`,time:`Local time`,weekdays:`Weekdays`,timezone:`Timezone`,spend:`Spend ceiling`,topics:`Topics`,brief:`Series brief`,generation:`Topic generation`};function _be(e){let t={};return e.name.trim()===``&&(t.name=`Give the schedule a name.`),e.templateChosen||(t.template=`Choose the template each run starts from.`),e.kind===`once`&&e.onceAt===``&&(t.once=`Pick the date and time of the one run.`),e.kind!==`once`&&e.time===``&&(t.time=`Pick the time of day runs start.`),e.kind===`weekly`&&e.days.length===0&&(t.weekdays=`Choose at least one weekday for a weekly schedule.`),dT(e.timezone.trim())||(t.timezone=`Enter a timezone name like Europe/Tirane or America/New_York; start typing to see the list.`),gQ(e.spend)===void 0&&(t.spend=`Enter the ceiling in US dollars, such as 5 or 2.50, or leave it empty for no ceiling.`),e.topicProblems.length>0?t.topics=`Fix the topics first. ${e.topicProblems.slice(0,3).join(` `)}`:e.topicCount>500&&(t.topics=`Keep the list to 500 topics or fewer; it has ${String(e.topicCount)}.`),e.brief.trim().length>4e3&&(t.brief=`Keep the series brief to ${String(_T)} characters or fewer.`),e.generationLlm!==null&&(e.generationLlm.provider===``||e.generationLlm.model===``)&&(t.generation=`Pick both a provider and a model for topic generation, or tick Use the template's LLM.`),t}function vbe(e){return hQ.find(t=>e[t]!==void 0)}function ybe(e){return hQ.filter(t=>e[t]!==void 0).map(t=>`${gbe[t]}: ${e[t]??``}`).join(` `)}function gQ(e){let t=e.trim().replace(/^\$/,``);if(t===``)return null;if(/^\d+(\.\d{1,2})?$/.test(t))return Math.round(Number(t)*100)}function bbe(e){return e==null?``:e%100==0?String(e/100):(e/100).toFixed(2)}function xbe(){try{return typeof Intl.supportedValuesOf==`function`?Intl.supportedValuesOf(`timeZone`):[]}catch{return[]}}var Sbe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],_Q=J({day:K().int().min(0).max(6),time:G().regex(/^([01]\d|2[0-3]):[0-5]\d$/)}),Cbe=J({name:G().trim().min(1).max(20),series:G().trim().max(100).default(``),long:_Q,shorts:q(_Q).max(10),schedule:G().optional(),runDay:K().int().min(0).max(6).optional(),timeZone:G().optional(),label:G().optional()});J({timeZone:G().min(1).max(100),rows:q(Cbe).max(14)});var wbe=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Tbe=[1,2,3,4,5,6,0];function vQ(e,t){return{day:(e+1+Math.floor(t/2))%7,time:t%2==0?`12:00`:`17:00`}}function Ebe(e,t){return{day:e,long:{day:e,time:`20:00`},shorts:Array.from({length:t},(t,n)=>vQ(e,n))}}function yQ(e,t,n){return Tbe.filter(e=>t.includes(e)).map(t=>{let r=e.find(e=>e.day===t)??Ebe(t,n);return{...r,shorts:Array.from({length:n},(e,n)=>r.shorts[n]??vQ(t,n))}})}function bQ({value:e,label:t,onChange:n}){return(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`w-[64px] shrink-0 text-small text-ink-3`,children:t}),(0,h.jsx)(sL,{"aria-label":`${t}: day`,className:`w-[84px]`,value:String(e.day),onChange:t=>n({...e,day:Number(t.currentTarget.value)}),options:Sbe.map((e,t)=>({value:String(t),label:e}))}),(0,h.jsx)(X,{"aria-label":`${t}: time`,type:`time`,className:`w-[124px]`,value:e.time,onChange:t=>n({...e,time:t.currentTarget.value||e.time})})]})}function Dbe({releases:e,onReleases:t,runDays:n,shorts:r,once:i,timezone:a}){let o=e===null?[]:yQ(e,n,r),s=(e,n)=>t(o.map(t=>t.day===e?n:t));return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,...Ny,children:[(0,h.jsx)(`legend`,{className:`float-left mb-1 w-full text-title-3 font-semibold`,children:`Release times`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i?`A one-time schedule has no release times: set the project's in its Video section once it is done.`:`When each run's project goes out on YouTube, in ${a}. Each short goes out the first time its day and hour come round after the one before it. Calendar → Releases shows them, and the Studio extension types them into Studio.`}),i?null:e===null?(0,h.jsx)(`div`,{children:(0,h.jsx)(z,{variant:`secondary`,onClick:()=>t(yQ([],n,r)),disabled:n.length===0,children:`Set release times`})}):(0,h.jsxs)(h.Fragment,{children:[o.map(e=>(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-line pb-3 last:border-b-0`,children:[(0,h.jsxs)(`div`,{className:`text-small font-semibold`,children:[wbe[e.day],`'s run`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2`,children:[(0,h.jsx)(bQ,{label:`Video`,value:e.long,onChange:t=>s(e.day,{...e,long:t})}),e.shorts.map((t,n)=>(0,h.jsx)(bQ,{label:`Short ${String(n+1)}`,value:t,onChange:t=>s(e.day,{...e,shorts:e.shorts.map((e,r)=>r===n?t:e)})},n))]})]},e.day)),r===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The template makes no shorts, so only the long video has a time.`}):null,(0,h.jsx)(`div`,{children:(0,h.jsx)(z,{variant:`quiet`,onClick:()=>t(null),children:`Set no release times`})})]})]})}function xQ(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 SQ({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=xQ;return t===void 0?(0,h.jsx)(KL,{label:`Keywords`,children:e.map(e=>(0,h.jsx)(qL,{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)(iL,{label:a(e.name),tip:s,help:l(e),error:n?.(`${r}.${e.name}`),children:(0,h.jsx)(X,{"data-play-field":`${r}.${e.name}`,value:e.value,maxLength:c,...o===void 0?{}:{"aria-label":o(e.name)},spellCheck:e.topic===!0,"aria-invalid":n?.(`${r}.${e.name}`)!==void 0,onChange:n=>t(e.name,n.target.value)})},e.name))})}var CQ={lines:`One per line`,table:`Table`,yaml:`YAML / JSON`};function wQ(e){return{mode:`lines`,rows:e,lines:cG(e),base:e,yaml:``,columns:TQ(e,[])}}function TQ(e,t){return[...new Set([...t,...e.flatMap(e=>Object.keys(e.values))])]}function EQ(e){return e.keywords.filter(t=>t!==e.topicKeyword&&(e.everyRun[t]??``).trim()===``)}function DQ(e,t){if(t.form===void 0)return{rows:e.rows,problems:[]};if(e.mode===`yaml`){let n=lG(e.yaml,{keywords:t.keywords,topicKeyword:t.topicKeyword,required:EQ(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:aG(n,{keywords:t.keywords,topicKeyword:t.topicKeyword,...e.mode===`table`?{required:EQ(t)}:{},kept:t.kept})}}function Obe(e,t,n){if(t===e.mode)return{queue:e,problems:[]};let r=e.rows;if(e.mode===`yaml`){let t=lG(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`?cG(r):e.lines,base:t===`lines`?r:e.base,yaml:t===`yaml`?uG(r,n.topicKeyword):e.yaml,columns:TQ(r,e.columns)},problems:[]}}function OQ(e,t,n){return{...e,rows:t,lines:e.mode===`lines`?cG(t):e.lines,base:e.mode===`lines`?t:e.base,yaml:e.mode===`yaml`?uG(t,n):e.yaml,columns:TQ(t,e.columns)}}function kbe(e,t,n){if(!/\.(ya?ml|json)$/i.test(e))return{ok:!0,rows:sG(t,[])};let r=lG(t,{keywords:n.keywords.length===0?Object.keys(n.everyRun):n.keywords,topicKeyword:n.topicKeyword});return r.ok?{ok:!0,rows:r.rows}:{ok:!1,problems:r.problems}}var kQ={"aria-hidden":!0,strokeWidth:1.75};function AQ(e,t,n){if(!e.altKey||e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return!1;e.preventDefault();let r=e.key===`ArrowUp`;return t.busy||r&&t.index===0||!r&&t.index===t.count-1||n(t.index+(r?-1:1),r?`up`:`down`),!0}var jQ=`Alt+ArrowUp Alt+ArrowDown`;function MQ({name:e,index:t,count:n,busy:r,onMove:i,onRemove:a,onInsertBelow:o,onDuplicate:s}){let c=(0,m.useRef)(!1),l=t===0,u=t===n-1;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Mv,{size:`small`,label:`Move ${e} up`,disabled:r||l,onClick:()=>i(t-1,`up`),children:(0,h.jsx)(wc,{...kQ})}),(0,h.jsx)(Mv,{size:`small`,label:`Move ${e} down`,disabled:r||u,onClick:()=>i(t+1,`down`),children:(0,h.jsx)(bc,{...kQ})}),(0,h.jsx)(Mv,{size:`small`,label:`Remove ${e}`,disabled:r,onClick:a,children:(0,h.jsx)(kl,{...kQ})}),(0,h.jsxs)(JO,{children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsx)(Mv,{size:`small`,label:`More for ${e}`,disabled:r,children:(0,h.jsx)(Hc,{...kQ})})}),(0,h.jsxs)(XO,{onCloseAutoFocus:e=>{c.current&&(c.current=!1,e.preventDefault(),o())},children:[(0,h.jsxs)(ZO,{disabled:l,onSelect:()=>i(0,`to the top`),children:[(0,h.jsx)(Cc,{...kQ,className:`size-4`}),`Move to top`]}),(0,h.jsxs)(ZO,{disabled:u,onSelect:()=>i(n-1,`to the bottom`),children:[(0,h.jsx)(vc,{...kQ,className:`size-4`}),`Move to bottom`]}),(0,h.jsxs)(ZO,{onSelect:()=>{c.current=!0},children:[(0,h.jsx)(rl,{...kQ,className:`size-4`}),`Insert below`]}),(0,h.jsxs)(ZO,{onSelect:s,children:[(0,h.jsx)(Bc,{...kQ,className:`size-4`}),`Duplicate`]})]})]})]})}function NQ(e){return e.split(/\r?\n/).map(e=>e.replace(/^\s*[-*•]\s+/,``).trim()).filter(e=>e!==``)}function PQ(e,t,n){let r=[...e],[i]=r.splice(t,1);return i===void 0||r.splice(Math.min(Math.max(n,0),r.length),0,i),r}function FQ(e,t,n){let r=Math.min(Math.max(t,0),e.length);return[...e.slice(0,r),...n,...e.slice(r)]}var IQ=0;function LQ(e){return Array.from({length:e},()=>(IQ+=1,`row-${String(IQ)}`))}function RQ(e,t,n){let r=new Map;return e.forEach((e,n)=>{let i=t[n];i!==void 0&&r.set(e.title,[...r.get(e.title)??[],i])}),n.map(e=>r.get(e.title)?.shift()??LQ(1)[0]??``)}var zQ=()=>({title:``,values:{}});function Abe({queue:e,onQueue:t,keyword:n,addable:r,titleOf:i}){let a=Iv(),o=n===null?`Title`:`{{${n}}}`,s=(0,m.useRef)({rows:e.rows,keys:LQ(e.rows.length)});s.current.rows!==e.rows&&(s.current={rows:e.rows,keys:RQ(s.current.rows,s.current.keys,e.rows)});let c=s.current.keys,l=(0,m.useRef)(e);l.current=e;let u=_G(c),d=(0,m.useRef)(new Map),f=(0,m.useRef)(null);(0,m.useEffect)(()=>{let e=f.current;e!==null&&c.includes(e)&&(f.current=null,d.current.get(e)?.focus())},[c]);let p=(n,r,i)=>{s.current={rows:n,keys:r},i!==void 0&&(f.current=i),t({...e,rows:n})},g=(t,n)=>{let r=LQ(n.length);p(FQ(e.rows,t,n),FQ(c,t,r),r[0])},_=(t,n)=>p(e.rows.map((e,r)=>r===t?n:e),c),v=(t,n)=>{let r=c[t];p(PQ(e.rows,t,n),PQ(c,t,n),r)},y=r=>{let i=[...new Set(r)].filter(e=>e>=0).sort((e,t)=>e-t),o=i.flatMap(t=>{let n=e.rows[t];return n===void 0?[]:[{at:t,row:n}]});if(o.length===0)return;let s=new Set(i);p(e.rows.filter((e,t)=>!s.has(t)),c.filter((e,t)=>!s.has(t)));let u=o[0]?.row.title.trim()??``;a(o.length===1?`Removed ${u===``?`an empty topic`:`“${u}”`}. Save the schedule to keep it.`:`Removed ${SG(o.length,`topic`,`topics`)}. Save the schedule to keep it.`,`success`,{label:`Undo`,run:()=>{let e=[...l.current.rows];for(let{at:t,row:n}of o)e=FQ(e,t,[n]);t(OQ(l.current,e,n))}})};return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ny,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(z,{size:`small`,onClick:()=>g(e.rows.length,[zQ()]),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]}),r.length===0?null:(0,h.jsxs)(sL,{"aria-label":`Set a keyword per topic`,value:``,className:`w-auto`,onChange:n=>{let r=n.target.value;r!==``&&t({...e,columns:[...e.columns,r]})},children:[(0,h.jsx)(`option`,{value:``,children:`Set a keyword per topic…`}),r.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))]})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,onKeyDown:u.onKeyDown,children:[e.rows.length>1?(0,h.jsx)(xG,{selection:u,total:e.rows.length,noun:[`topic`,`topics`],actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:u.count===0,disabledReason:`Tick the topics to remove`,onClick:()=>{y(u.selected.map(e=>c.indexOf(e))),u.clear()},children:`Remove selected`})}):null,(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table`,"aria-label":`Topics`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Select`})}),(0,h.jsx)(`th`,{scope:`col`,children:`#`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[o,(0,h.jsx)(H,{id:`planning.schedule.topic-table`,className:`-my-1`})]})}),e.columns.map(n=>(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`{{${n}}}`,(0,h.jsx)(Mv,{label:`Use the every-run ${n} for all topics`,size:`small`,onClick:()=>t({...e,columns:e.columns.filter(e=>e!==n),rows:e.rows.map(e=>({title:e.title,values:Object.fromEntries(Object.entries(e.values).filter(([e])=>e!==n))}))}),children:(0,h.jsx)(kl,{"aria-hidden":`true`,strokeWidth:1.75})})]})},n)),(0,h.jsx)(`th`,{scope:`col`,children:`Project title`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,h.jsx)(`tbody`,{children:e.rows.map((t,n)=>{let r=c[n]??String(n),a=t.title.trim()===``?`topic ${String(n+1)}`:t.title;return(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{children:(0,h.jsx)(yG,{selection:u,value:r,label:a})}),(0,h.jsx)(`td`,{className:`num`,children:n+1}),(0,h.jsx)(`td`,{children:(0,h.jsx)(X,{ref:e=>{e===null?d.current.delete(r):d.current.set(r,e)},"aria-label":`Topic ${String(n+1)} ${o}`,"aria-keyshortcuts":jQ,maxLength:200,value:t.title,className:`min-w-[14rem]`,onChange:e=>_(n,{...t,title:e.target.value}),onPaste:t=>{let r=NQ(t.clipboardData.getData(`text`));if(r.length<2)return;t.preventDefault();let[i=``,...a]=r,o=e.rows.map((e,t)=>t===n?{...e,title:`${e.title}${i}`}:e),s=LQ(a.length);p(FQ(o,n+1,a.map(e=>({title:e,values:{}}))),FQ(c,n+1,s),s.at(-1))},onKeyDown:t=>{AQ(t,{index:n,count:e.rows.length,busy:!1},e=>v(n,e))||t.key===`Enter`&&(t.preventDefault(),g(n+1,[zQ()]))}})}),e.columns.map(e=>(0,h.jsx)(`td`,{children:(0,h.jsx)(X,{"aria-label":`Topic ${String(n+1)} ${e}`,maxLength:QW,placeholder:`Every-run value`,value:t.values[e]??``,className:`min-w-[8rem]`,onChange:r=>_(n,{...t,values:{...t.values,[e]:r.target.value}})})},e)),(0,h.jsx)(`td`,{className:`min-w-[180px] text-small text-ink-2`,children:i(t)??`—`}),(0,h.jsx)(`td`,{children:(0,h.jsx)(`span`,{className:`flex items-center gap-1`,children:(0,h.jsx)(MQ,{name:a,index:n,count:e.rows.length,busy:!1,onMove:e=>v(n,e),onRemove:()=>y([n]),onInsertBelow:()=>g(n+1,[zQ()]),onDuplicate:()=>g(n+1,[t])})})})]},r)})})]})})]})]})}function jbe({queue:e,onQueue:t,context:n,onKeyword:r,onValue:i,loading:a,exportName:o}){let[s,c]=(0,m.useState)([]),[l,u]=(0,m.useState)(null),{keywords:d,topicKeyword:f,form:p,everyRun:g}=n,_=e=>n.origins?.get(e)??[],v=DQ(e,n),y=e.mode===`yaml`?v.rows:e.rows,b=e=>p===void 0?void 0:tG(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=()=>uG(DQ(e,n).rows,f),T=()=>{let e=w();if(!navigator.clipboard){u(`Couldn't copy the list. Switch to YAML / JSON, select the text and copy it.`);return}navigator.clipboard.writeText(e).then(()=>u(`Copied ${String(y.length)} topics as YAML.`),()=>u(`Couldn't copy the list. Switch to YAML / JSON, select the text and copy it.`))},E=()=>{let e=URL.createObjectURL(new Blob([w()],{type:`application/yaml`})),t=document.createElement(`a`);t.href=e,t.download=`${(o.trim()||`schedule`).replace(/[^\w.-]+/g,`-`)}-topics.yaml`,t.click(),URL.revokeObjectURL(e),u(`Downloaded ${String(y.length)} topics as YAML.`)},D=(0,m.useRef)(null),O=async r=>{let i=kbe(r.name,await r.text(),n);if(!i.ok){u(`${r.name} wasn't imported: ${i.problems.slice(0,3).join(` `)} Fix the file and import it again, or paste its text under YAML / JSON to see every problem.`);return}if(i.rows.length===0){u(`${r.name} has no topics in it. Put one topic per line, or a YAML / JSON list.`);return}t(OQ(e,[...DQ(e,n).rows,...i.rows],f)),u(`Imported ${String(i.rows.length)} ${i.rows.length===1?`topic`:`topics`} from ${r.name}, after the ones already here.`)},k=d.filter(t=>t!==f&&!e.columns.includes(t)),A=[...s,...v.problems];return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topics (optional)`,(0,h.jsx)(H,{id:`planning.schedule.topics`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(Fy,{label:`How to write the topics`,tip:`planning.schedule.topic-format`,value:e.mode,options:Object.keys(CQ).map(e=>({value:e,label:CQ[e]})),onChange:r=>{let i=Obe(e,r,n);c(i.problems),t(i.queue)}}),(0,h.jsxs)(z,{variant:`quiet`,size:`small`,disabled:y.length===0||v.problems.length>0,disabledReason:`Add topics, and fix the problems below, first`,onClick:T,children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Copy as YAML`]}),(0,h.jsxs)(z,{variant:`quiet`,size:`small`,disabled:y.length===0||v.problems.length>0,disabledReason:`Add topics, and fix the problems below, first`,onClick:E,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Export as YAML`]}),(0,h.jsxs)(z,{variant:`quiet`,size:`small`,onClick:()=>D.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Import`]}),(0,h.jsx)(`input`,{ref:D,type:`file`,hidden:!0,accept:`.yaml,.yml,.json,.txt,text/plain,application/json,application/yaml`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&O(t)}}),l===null?null:(0,h.jsx)(`span`,{role:`status`,className:`text-small text-ink-2`,children:l})]}),e.mode===`lines`?(0,h.jsx)(iL,{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)(oL,{rows:Math.min(16,Math.max(6,y.length+1)),value:e.lines,onChange:n=>t({...e,lines:n.target.value,rows:sG(n.target.value,e.base)}),placeholder:`Pyramids
|
|
272
272
|
Sphinxes
|
|
273
273
|
Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(iL,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(oL,{rows:10,className:`font-mono`,spellCheck:!1,value:e.yaml,onChange:n=>t({...e,yaml:n.target.value}),placeholder:`- ${f??`Topic`}: Cleopatra\n ${d.find(e=>e!==f)??`Min. Word Count`}: 12000\n- Hypatia`})}):(0,h.jsx)(Abe,{queue:e,onQueue:t,keyword:f,addable:k,titleOf:b}),v.rows.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,"aria-live":`polite`,children:`${sQ(v.rows.length,500,`topics`)}.`}),A.length===0?null:(0,h.jsx)(dM,{tone:`danger`,title:`These topics can't be saved yet.`,children:(0,h.jsxs)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:[A.slice(0,8).map(e=>(0,h.jsx)(`li`,{children:e},e)),A.length>8?(0,h.jsx)(`li`,{children:`And ${String(A.length-8)} more.`}):null]})}),e.mode===`yaml`&&v.rows.length>0?(0,h.jsxs)(`section`,{"aria-label":`Project titles`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-1 text-small text-ink-2`,children:`Project titles, in order:`}),(0,h.jsxs)(`ol`,{className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:[v.rows.slice(0,20).map((e,t)=>(0,h.jsx)(`li`,{children:b(e)},t)),v.rows.length>20?(0,h.jsx)(`li`,{className:`list-none text-ink-3`,children:`And ${String(v.rows.length-20)} more.`}):null]})]}):null,a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Reading the template's keywords…`}):d.length===0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`This template has no keywords such as `,`{{Topic}}`,`, so each topic becomes the project's title.`]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:(0,h.jsx)(iL,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:xQ({feeds:_(f)})},children:(0,h.jsx)(sL,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(SQ,{keywords:d.filter(e=>e!==f).map(t=>({name:t,value:g[t]??``,feeds:_(t),...e.columns.includes(t)?{note:`Unless a topic sets its own.`}:{}})),onChange:i,fieldPrefix:`everyRun`,label:e=>`${e} (every run)`,inputLabel:e=>`${e} for every run`,tip:`planning.schedule.every-run`,maxLength:1e4})]}),e.mode===`lines`&&S!==void 0&&x!==void 0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Next project: `,(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:S}),f===null||C?null:(0,h.jsxs)(`span`,{className:`block text-ink-3`,children:[`The template's project title does not use `,`{{${f}}}`,`, so every project gets this title. Edit the template's title to include it.`]})]}):null]})}var Mbe=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Nbe({templates:e,pending:t,onCreated:n,onError:r,editing:i,onCancel:a,error:o,onBusy:s}){let{api:c}=B(),[l,u]=(0,m.useState)(i?.name??``),[d,f]=(0,m.useState)(i?.templateId??``),[p,g]=(0,m.useState)(i?.cadence.kind??`daily`),[_,v]=(0,m.useState)(i?.cadence.kind===`once`?Fye(i.cadence.at,i.timezone):``),[y,b]=(0,m.useState)(i&&i.cadence.kind!==`once`?i.cadence.time:`09:00`),[x,S]=(0,m.useState)(i?.cadence.kind===`weekly`?i.cadence.days:[1,3,5]),[C,w]=(0,m.useState)(()=>i?.timezone??(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`)),[T,E]=(0,m.useState)(i?.missedPolicy??`skip`),[D,O]=(0,m.useState)(bbe(i?.spendLimitCents)),[k,A]=(0,m.useState)(()=>wQ(i?.items??[])),[j,M]=(0,m.useState)(i?.topicKeyword??null),[ee,N]=(0,m.useState)(i?.values??{}),[te,P]=(0,m.useState)(i?.brief??``),[ne,re]=(0,m.useState)(i?.topicGeneration??yT),[ie,ae]=(0,m.useState)((i?.releases??[]).length===0?null:i?.releases??null),[oe,se]=(0,m.useState)(!1),[ce,le]=(0,m.useState)(!1),[ue,de]=(0,m.useState)(!1),fe=(0,m.useId)(),pe=(0,m.useRef)(!1),me=(0,m.useRef)(null),he=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,ge=he.find(e=>e.id===d),_e=F({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await jO(c,d);if(!e.ok)throw Error(e.message);return e.value}}),ve=_e.data?.document.form,ye=ve===void 0?void 0:mQ({form:ve,prompts:_e.data?.document.librarySnapshot?.prompts??[],entries:_e.data?.document.librarySnapshot?.entries??[]}),be=ve===void 0?[]:$W(ve),xe=j!==null&&be.includes(j)?j:be.find(e=>ve?.title.includes(`{{${e}}}`))??be[0]??null,Se=Object.fromEntries(be.filter(e=>e!==xe).map(e=>[e,ee[e]??ve?.values[e]??``])),Ce={keywords:be,topicKeyword:xe,everyRun:Se,form:ve,kept:i?.items??[],...ye===void 0?{}:{origins:ye}},we=DQ(k,Ce),Te=p===`weekly`?x:p===`daily`?[0,1,2,3,4,5,6]:[],Ee=ve!==void 0&&ve.sources.audio!==`off`&&ve.shorts?.enabled===!0?Math.max(0,Math.min(10,Number(ve.shorts.count)||0)):0,De=()=>_be({name:l,templateChosen:ge!==void 0,kind:p,onceAt:_,time:y,days:x,timezone:C,spend:D,topicProblems:we.problems,topicCount:we.rows.length,brief:te,generationLlm:ne.llm}),Oe=ue?De():{};async function ke(e){if(e.preventDefault(),!(pe.current||t)){if(!me.current){let e=De(),t=vbe(e);if(t!==void 0){de(!0),r(ybe(e)),Pbe(hbe[t]);return}}pe.current=!0,se(!0),s(!0);try{if(!me.current){if(!ge)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!dT(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Iye(_,e)}:p===`weekly`?{kind:p,time:y,days:x}:{kind:p,time:y},n=gQ(D);if(n===void 0)throw Error(`Enter the spend ceiling in US dollars, such as 5 or 2.50, or leave it empty.`);let r={id:i?.id??crypto.randomUUID(),name:l.trim(),templateId:ge.id,templateVersion:ge.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:we.rows,topicKeyword:xe,values:Se,brief:te.trim()===``?null:te.trim(),topicGeneration:ne,releases:ie===null||p===`once`?[]:yQ(ie,Te,Ee)};me.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=me.current,{id:t,...a}=e,o=`mutationId`in a?await AT(c,t,a):await kT(c,e);if(!o.ok){me.current=null,le(!1),r(o.reason===`conflict`?`${o.message} Your inputs are kept here. To load the latest saved version, cancel editing and press Edit again.`:o.message);return}me.current=null,le(!1),de(!1),u(``),A(wQ([])),n()}catch(e){le(me.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{pe.current=!1,se(!1),s(me.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(dM,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{noValidate:!0,onSubmit:e=>void ke(e),children:[(0,h.jsxs)(`fieldset`,{disabled:oe||ce||t,className:`m-0 grid min-w-0 gap-4 border-0 p-0 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(iL,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,error:Oe.name,children:(0,h.jsx)(X,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(iL,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,error:Oe.template,children:(0,h.jsxs)(sL,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:he.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),he.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(iL,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(sL,{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)(iL,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,error:Oe.once,children:(0,h.jsx)(X,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(iL,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,error:Oe.time,children:(0,h.jsx)(X,{required:!0,type:`time`,value:y,onChange:e=>b(e.target.value)})}),p===`weekly`?(0,h.jsxs)(`fieldset`,{id:`schedule-weekdays`,className:`m-0 min-w-0 border-0 p-0`,"aria-invalid":Oe.weekdays!==void 0,"aria-describedby":Oe.weekdays===void 0?void 0:`schedule-weekdays-error`,...Ny,children:[(0,h.jsxs)(`legend`,{className:`sl-field__label mb-2 flex items-center gap-1`,children:[`Weekdays`,(0,h.jsx)(H,{id:`planning.schedule.weekdays`,className:`-my-1`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Mbe.map(([e,t])=>(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),onChange:t=>S(n=>t.target.checked?[...n,e]:n.filter(t=>t!==e))}),t]},e))}),Oe.weekdays===void 0?null:(0,h.jsx)(`p`,{id:`schedule-weekdays-error`,className:`sl-field__error m-0 mt-1`,children:Oe.weekdays})]}):(0,h.jsx)(`div`,{}),(0,h.jsx)(iL,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,help:`Start typing to pick from the list. This computer uses ${Fbe}.`,error:Oe.timezone,children:(0,h.jsx)(X,{value:C,list:fe,autoComplete:`off`,spellCheck:!1,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(`datalist`,{id:fe,children:xbe().map(e=>(0,h.jsx)(`option`,{value:e},e))}),(0,h.jsx)(iL,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(sL,{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)(iL,{label:`Spend ceiling per run (US$, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,help:`In dollars, such as 5 or 2.50. Empty means no ceiling.`,error:Oe.spend,children:(0,h.jsx)(X,{inputMode:`decimal`,value:D,onChange:e=>O(e.target.value),placeholder:`10.00`})}),(0,h.jsxs)(`div`,{id:`schedule-topics`,tabIndex:-1,className:`min-w-0 min-[700px]:col-span-2`,children:[(0,h.jsx)(jbe,{queue:k,onQueue:A,context:Ce,onKeyword:M,onValue:(e,t)=>N(n=>({...n,[e]:t})),loading:d!==``&&_e.isPending,exportName:l}),Oe.topics===void 0?null:(0,h.jsx)(`p`,{className:`sl-field__error m-0 mt-2`,children:Oe.topics})]}),(0,h.jsx)(Dbe,{releases:ie,onReleases:ae,runDays:Te,shorts:Ee,once:p===`once`,timezone:C}),(0,h.jsx)(Ibe,{problems:Oe,brief:te,onBrief:P,generation:ne,onGeneration:re,templateLlm:ve?.llm})]}),(0,h.jsxs)(`div`,{className:`sticky bottom-0 z-10 mt-6 flex flex-wrap gap-2 border-t border-line bg-ground py-3 max-md:bottom-[68px]`,children:[(0,h.jsx)(z,{type:`submit`,variant:`primary`,disabled:t||oe||he.length===0&&!ce,children:oe?`Saving…`:ce?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(z,{variant:`quiet`,disabled:oe||ce,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Pbe(e){let t=document.getElementById(e);t!==null&&(((t instanceof HTMLFieldSetElement?t.querySelector(`input, select, textarea`):t)??t).focus(),t.scrollIntoView?.({block:`center`,behavior:`smooth`}))}var Fbe=Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`;function Ibe({problems:e,brief:t,onBrief:n,generation:r,onGeneration:i,templateLlm:a}){let{api:o}=B(),s=F({...by(o),enabled:r.mode!==`off`}),c=r.llm;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topic generation`,(0,h.jsx)(H,{id:`planning.schedule.generation`})]}),(0,h.jsx)(iL,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,help:sQ(t.length,_T,`characters`),error:e.brief,children:(0,h.jsx)(oL,{rows:3,maxLength:_T,value:t,onChange:e=>n(e.target.value),placeholder:`Ancient history, documentary style. Famous rulers and places first.`})}),(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(iL,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,error:e.generation,children:(0,h.jsxs)(sL,{value:r.mode,onChange:e=>{let t=e.target.value;i({...r,mode:t===`queue`||t===`hold`?t:`off`})},children:[(0,h.jsx)(`option`,{value:`off`,children:`Off: add topics yourself`}),(0,h.jsx)(`option`,{value:`queue`,children:`Generate and queue directly`}),(0,h.jsx)(`option`,{value:`hold`,children:`Generate and hold for approval`})]})}),r.mode===`off`?null:(0,h.jsx)(iL,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(X,{type:`number`,min:1,max:100,value:String(r.keepAtLeast),onChange:e=>{let t=Math.round(Number(e.target.value));i({...r,keepAtLeast:Number.isFinite(t)?Math.min(100,Math.max(1,t)):1})}})})]}),r.mode===`off`?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...Ny,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:c===null,onChange:e=>i({...r,llm:e.target.checked?null:{provider:a?.provider??``,model:a?.model??``}})}),`Use the template's LLM`,c===null&&a!==void 0&&a.provider!==``?` (${a.provider} · ${a.model})`:``]}),(0,h.jsx)(H,{id:`planning.schedule.generation-llm`,className:`-my-1`})]}),c===null?null:(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(vL,{label:`Provider`,family:`llm`,providers:s.data?.providers??[],value:c.provider,problem:s.error?.message,onPick:e=>i({...r,llm:{provider:e,model:``}})}),(0,h.jsx)(hL,{label:`Model`,provider:c.provider,value:c.model,problem:void 0,onPick:e=>i({...r,llm:{...c,model:e}})})]})]})]})}function Lbe(e,t){let n=new Set(t);for(let t=1;;t+=1){let r=t===1?` (copy)`:` (copy ${String(t)})`,i=`${e.slice(0,200-r.length)}${r}`;if(!n.has(i))return i}}function Rbe(e,t,n){return{id:t,name:n,templateId:e.templateId,templateVersion:e.templateVersion,cadence:e.cadence,timezone:e.timezone,missedPolicy:e.missedPolicy,overlapPolicy:e.overlapPolicy,spendLimitCents:e.spendLimitCents,items:[],topicKeyword:e.topicKeyword,values:e.values,brief:e.brief,topicGeneration:e.topicGeneration,releases:e.releases}}async function zbe(e,t,n){let r=Lbe(t.name,n),i=await kT(e,Rbe(t,crypto.randomUUID(),r));if(!i.ok)return{...i,message:i.reason===`not-due`?`“${t.name}” wasn't duplicated: its one-time run has already passed. Press New schedule and choose a time in the future instead.`:`“${t.name}” wasn't duplicated: ${i.message}`};let a=await jT(e,i.value.id,`pause`,i.value.version);return a.ok?a:{...a,message:`“${r}” was made but couldn't be paused: ${a.message} Press Pause on its row before its first run.`}}var BQ={newest:`Newest first`,next:`Next run first`,name:`Name A–Z`,changed:`Recently changed`},Bbe=e=>Object.hasOwn(BQ,e);function Vbe(e,t,n){let r=t.trim().toLowerCase().split(/\s+/).filter(Boolean),i=e.filter(e=>r.every(t=>e.name.toLowerCase().includes(t)));return n===`newest`?i:[...i].sort((e,t)=>n===`name`?e.name.localeCompare(t.name):n===`changed`?t.updatedAt.localeCompare(e.updatedAt):(e.nextRunAt??`~`).localeCompare(t.nextRunAt??`~`))}function Hbe({query:e,sort:t,onQuery:n,onSort:r}){return(0,h.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,...Ny,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search schedules by name`,placeholder:`Search schedules`,value:e,className:`min-w-0 flex-1`,onChange:e=>n(e.target.value)}),(0,h.jsx)(sL,{"aria-label":`Sort schedules`,value:t,className:`w-auto`,onChange:e=>{let t=e.target.value;Bbe(t)&&r(t)},children:Object.keys(BQ).map(e=>(0,h.jsx)(`option`,{value:e,children:BQ[e]},e))}),(0,h.jsx)(H,{id:`planning.schedules`})]})}function Ube({rowKey:e,index:t,title:n,count:r,busy:i,selection:a,inputRef:o,onRename:s,onMove:c,onRemove:l,onInsertBelow:u,onDuplicate:d}){let[f,p]=(0,m.useState)(n);return(0,m.useEffect)(()=>p(n),[n]),(0,h.jsx)(qL,{lead:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(yG,{selection:a,value:e,label:n}),(0,h.jsx)(`span`,{className:`w-7 text-right text-small text-ink-3 tabular-nums`,children:t+1})]}),title:(0,h.jsx)(X,{ref:o,"aria-label":`Topic ${String(t+1)}`,"aria-keyshortcuts":jQ,maxLength:200,value:f,className:`min-w-[12rem]`,onChange:e=>p(e.target.value),onBlur:()=>s(f),onKeyDown:e=>{AQ(e,{index:t,count:r,busy:i},c)||(e.key===`Enter`?(e.preventDefault(),s(f)):e.key===`Escape`&&f!==n&&(e.preventDefault(),p(n)))}}),actions:(0,h.jsx)(MQ,{name:n,index:t,count:r,busy:i,onMove:c,onRemove:l,onInsertBelow:u,onDuplicate:d})})}function VQ({label:e,placeholder:t,buttonLabel:n,disabled:r,disabledReason:i,autoFocus:a=!1,className:o,onAdd:s,onCancel:c}){let[l,u]=(0,m.useState)(``),d=async e=>{await s(e)&&u(``)};return(0,h.jsxs)(`form`,{className:R(`flex flex-wrap items-center gap-2`,o),onSubmit:e=>{e.preventDefault(),d(NQ(l))},children:[(0,h.jsx)(X,{"aria-label":e,placeholder:t,maxLength:200,value:l,autoFocus:a,className:`min-w-0 flex-1`,onChange:e=>u(e.target.value),onPaste:e=>{let t=e.clipboardData.getData(`text`);/\r?\n/.test(t.trim())&&(e.preventDefault(),d(NQ(`${l}${t}`)))},onKeyDown:e=>{e.key===`Escape`&&(c===void 0?l!==``&&(e.preventDefault(),u(``)):(e.preventDefault(),c()))}}),(0,h.jsxs)(z,{type:`submit`,size:`small`,disabled:r,disabledReason:i,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),n]}),c===void 0?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,onClick:c,children:`Cancel`})]})}var HQ=e=>`“${e}”`;function Wbe(e,t){let{api:n}=B(),r=_(),i=Iv(),[a,o]=(0,m.useState)(null),[s,c]=(0,m.useState)(!1),l=(0,m.useRef)(!1),u=(0,m.useRef)(e);e.version>u.current.version&&(u.current=e);let d=(0,m.useRef)({version:e.version,items:e.items,keys:LQ(e.items.length)});if(d.current.version!==u.current.version){let{items:e}=u.current;d.current={version:u.current.version,items:e,keys:RQ(d.current.items,d.current.keys,e)}}let f=(0,m.useRef)(null),p=u.current.items,h=d.current.keys,g=async(e,t,a,s)=>{if(l.current)return!1;l.current=!0;let f=u.current,p=d.current.keys;c(!0),o(null);try{let c=await e(f);return c.ok?(u.current=c.value,d.current={version:c.value.version,items:c.value.items,keys:t.length===c.value.items.length?t:RQ(f.items,p,c.value.items)},r.setQueryData(DT,e=>e?.map(e=>e.id===c.value.id?c.value:e)),r.invalidateQueries({queryKey:BT}),i(a,`success`,s?{label:`Undo`,run:()=>void g(e=>zT(n,e.id,{baseVersion:e.version,items:f.items}),p,`Put the topics back as they were.`,!1)}:void 0),!0):(o(c.reason===`conflict`?`The topics weren't saved: this schedule changed since the page loaded, possibly because a run just took a topic. The list now shows the latest; make your change again.`:`The topics weren't saved: ${c.message}`),await r.invalidateQueries({queryKey:DT}),!1)}catch(e){return o(`The topics weren't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then try again.`),!1}finally{l.current=!1,c(!1)}},v=(e,t,r)=>g(t=>zT(n,t.id,{baseVersion:t.version,items:e}),t,r,!0);return{items:p,keys:h,saving:s,error:a,setError:o,focusKey:f,add:async(e,n=p.length,r=!1)=>{if(e.length===0)return o(`Write the new topic's ${t} first, then press Add topic.`),!1;let i=500-p.length;if(e.length>i)return o(`${SG(e.length,`topic`,`topics`)} didn't fit: a queue holds at most 500 and ${SG(i,`more fits`,`more fit`)}. Remove some topics first, or add fewer lines.`),!1;let a=LQ(e.length),s=a[0];return r&&s!==void 0&&(f.current=s),v(FQ(p,n,e.map(e=>({title:e,values:{}}))),FQ(h,n,a),e.length===1?`Added ${HQ(e[0]??``)}.`:`Added ${SG(e.length,`topic`,`topics`)}.`)},rename:(e,n)=>{let r=p[e],i=n.trim();if(r!==void 0&&i!==r.title){if(i===``){o(`Topic ${String(e+1)} needs a ${t}. Write one, or press its Remove button.`);return}v(p.map((t,n)=>n===e?{...t,title:i}:t),h,`Renamed to ${HQ(i)}.`)}},move:(e,t,r)=>{let i=p[e],a=h[e];i!==void 0&&e!==t&&(a!==void 0&&(f.current=a),g(r=>RT(n,r.id,{baseVersion:r.version,from:e,to:t}),PQ(h,e,t),`Moved ${HQ(i.title)} ${r}.`,!0))},remove:e=>{let t=new Set(e),n=p[e[0]??-1];return n===void 0?Promise.resolve(!1):v(p.filter((e,n)=>!t.has(n)),h.filter((e,n)=>!t.has(n)),t.size===1?`Removed ${HQ(n.title)}.`:`Removed ${SG(t.size,`topic`,`topics`)}.`)},duplicate:e=>{let t=p[e];if(t===void 0)return;if(p.length>=500){o(`${HQ(t.title)} wasn't duplicated: a queue holds at most 500 topics. Remove one first.`);return}let[n]=LQ(1);n!==void 0&&(f.current=n),v(FQ(p,e+1,[t]),FQ(h,e+1,n===void 0?[]:[n]),`Duplicated ${HQ(t.title)}.`)}}}function Gbe({schedule:e}){let t=e.topicKeyword===null?`title`:`{{${e.topicKeyword}}}`,n=Wbe(e,t),{items:r,keys:i,saving:a}=n,o=_G(i),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),d=(0,m.useRef)(new Map);(0,m.useEffect)(()=>{let e=n.focusKey.current;if(e!==null&&i.includes(e)){if(!l&&i.indexOf(e)>=100){u(!0);return}n.focusKey.current=null,d.current.get(e)?.focus()}},[i,n.focusKey,l]);let f=r.length>=500,p=a?`Saving the last change`:`A queue holds at most 500 topics`,g=l?r.length:Math.min(r.length,100),_=s===null?-1:i.indexOf(s);return(0,h.jsxs)(`section`,{"aria-label":`Queued topics`,className:`mt-6`,...Ny,children:[(0,h.jsx)(U,{as:`h3`,title:`Queued topics · ${String(r.length)}`,info:`planning.schedule.inline-topics`,meta:e.topicKeyword===null?`Each topic becomes the next project's title.`:`Each topic fills ${t}; the next run takes the first.`}),n.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:n.error}),(0,h.jsx)(VQ,{className:`mt-3`,label:`New topic`,placeholder:`${e.topicKeyword===null?`New topic`:`New ${t}`}, or paste several lines`,buttonLabel:`Add topic`,disabled:a||f,disabledReason:p,onAdd:e=>n.add(e)}),r.length===0?null:(0,h.jsxs)(`div`,{onKeyDown:o.onKeyDown,children:[r.length>1?(0,h.jsx)(xG,{className:`mt-3`,selection:o,total:r.length,noun:[`topic`,`topics`],actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:a||o.count===0,disabledReason:a?`Saving the last change`:`Tick the topics to remove`,onClick:()=>void n.remove(o.selected.map(e=>i.indexOf(e))).then(e=>{e&&o.clear()}),children:`Remove selected`})}):null,(0,h.jsx)(KL,{label:`Topics of ${e.name}`,className:`mt-2`,children:r.slice(0,g).flatMap((e,t)=>{let s=i[t]??String(t),l=(0,h.jsx)(Ube,{rowKey:s,index:t,title:e.title,count:r.length,busy:a,selection:o,inputRef:e=>{e===null?d.current.delete(s):d.current.set(s,e)},onRename:e=>n.rename(t,e),onMove:(e,r)=>n.move(t,e,r),onRemove:()=>void n.remove([t]),onInsertBelow:()=>c(s),onDuplicate:()=>n.duplicate(t)},s);return t===_?[l,(0,h.jsx)(qL,{title:(0,h.jsx)(VQ,{autoFocus:!0,label:`New topic below ${String(t+1)}`,placeholder:`New topic, or paste several lines`,buttonLabel:`Insert`,disabled:a||f,disabledReason:p,onAdd:async e=>{let r=await n.add(e,t+1,!0);return r&&c(null),r},onCancel:()=>c(null)})},`${s}:insert`)]:[l]})}),g<r.length?(0,h.jsx)(z,{variant:`quiet`,size:`small`,className:`mt-2`,onClick:()=>u(!0),children:`Show all ${String(r.length)} topics`}):null]})]})}function Kbe(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}function UQ({schedule:e}){return e.deletedAt===null?(0,h.jsx)(ek,{tone:BL[e.status].tone,children:BL[e.status].word}):(0,h.jsx)(ek,{tone:`off`,children:`Deleted`})}function WQ({schedule:e,nextTitle:t,selected:n,pending:r,onSelect:i,onEdit:a,onAction:o,onConfirm:s}){let{api:c}=B(),l=e.deletedAt===null,u=l&&(e.status===`active`||e.status===`paused`),d=e.status===`canceled`||e.status===`completed`;return(0,h.jsx)(qL,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(UQ,{schedule:e}),` · ${Kbe(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${WZ(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${WZ(e.deletedAt,e.timezone)}`}${e.topics.held>0?` · ${String(e.topics.held)} waiting for you`:``}`]}),actions:l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,disabled:r||!u,disabledReason:u?`Finish or cancel the open form first`:`Only a live schedule can change`,onClick:a,children:`Edit`}),e.status===`paused`?(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Resume ${e.name}`,disabled:r,onClick:()=>o(()=>jT(c,e.id,`resume`,e.version)),children:`Resume`}):(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Pause ${e.name}`,disabled:r||e.status!==`active`,disabledReason:`Only an active schedule can pause`,onClick:()=>o(()=>jT(c,e.id,`pause`,e.version)),children:`Pause`}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,disabled:r||!d,disabledReason:`Cancel the schedule first; a completed or canceled one can be deleted`,onClick:()=>s(`delete`),children:`Delete`})]}):void 0})}function qbe({schedule:e,pending:t,onAction:n,onConfirm:r,onDuplicate:i}){let{api:a}=B(),o=F({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await nce(a,e.id);if(!t.ok)throw Error(t.message);return t.value},refetchInterval:3e4}),s=e.deletedAt===null,c=s&&(e.status===`active`||e.status===`paused`),l=e.status===`paused`,u=[[`When`,e.cadence.kind===`once`?`Once, ${WZ(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`:WZ(e.nextRunAt,e.timezone)],[`Topics`,e.items.length===0?e.topicGeneration.mode===`off`?`Template as saved`:`No topics queued`:`${String(e.items.length)} ${e.items.length===1?`topic`:`topics`} left`],[`Missed runs`,e.missedPolicy===`skip`?`Skip`:`Run once on reopening`],[`Overlap`,`Skip`],[`Spend ceiling`,e.spendLimitCents===null?`Not set`:`${String(e.spendLimitCents)} cents`]];return(0,h.jsxs)(`section`,{"aria-label":`${e.name} detail`,children:[s&&c?(0,h.jsx)(Jbe,{schedule:e,paused:l,onAction:n}):null,(0,h.jsxs)(U,{kicker:(0,h.jsx)(UQ,{schedule:e}),title:e.name,meta:e.topics.held>0?`${String(e.topics.held)} topics waiting for you`:void 0,children:[s?(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Duplicate ${e.name}`,disabled:t,disabledReason:`Finish or cancel the open change first`,onClick:i,children:`Duplicate`}):null,s?(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Cancel ${e.name}`,disabled:t||!c,disabledReason:`Only an active or paused schedule can be canceled`,onClick:()=>r(`cancel`),children:`Cancel schedule`}):null]}),(0,h.jsx)(`dl`,{className:`m-0 mt-4 grid grid-cols-1 gap-x-6 gap-y-3 text-small min-[600px]:grid-cols-2`,children:u.map(([e,t])=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`dt`,{className:`sl-kicker`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-words text-ink`,children:t})]},e))}),c?(0,h.jsx)(Gbe,{schedule:e}):null,(0,h.jsx)(Yye,{schedule:e}),(0,h.jsx)(gG,{className:`my-6`}),(0,h.jsx)(U,{as:`h3`,title:`Run history`}),(0,h.jsx)(`div`,{className:`mt-3`,children:o.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading history…`}):o.error?(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The run history couldn't be loaded: ${o.error.message} It tries again every 30 seconds.`}):o.data.runs.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No runs yet.`}):(0,h.jsx)(KL,{label:`Runs of ${e.name}`,children:o.data.runs.map(t=>(0,h.jsx)(qL,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${WZ(t.scheduledFor,e.timezone)}`}),meta:t.error?t.error:t.projectIds.length>0?(0,h.jsx)(`span`,{className:`inline-flex flex-wrap gap-x-3`,children:t.projectIds.map((e,t)=>(0,h.jsxs)(pa,{className:`underline hover:text-ink`,to:`/projects/$projectId`,params:{projectId:e},children:[`Project `,t+1]},e))}):`No projects`},t.id))})})]})}function Jbe({schedule:e,paused:t,onAction:n}){let{api:r}=B();return sb({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>jT(r,e.id,t?`resume`:`pause`,e.version))}),null}var GQ={llm:`Text model`,audio:`Voice model`,images:`Image model`,animate:`Animation model`},Ybe=RegExp(`Settings → (${lk.map(e=>e.label.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).toSorted((e,t)=>t.length-e.length).join(`|`)})`,`g`);function Xbe(e){let t=[],n=0;for(let r of e.matchAll(Ybe)){let i=r[1],a=lk.find(e=>e.label===i);a!==void 0&&r.index!==void 0&&(r.index>n&&t.push(e.slice(n,r.index)),t.push({label:r[0],section:a.id}),n=r.index+r[0].length)}return n<e.length&&t.push(e.slice(n)),t}function KQ({text:e}){if(hi({warn:!1})==null)return(0,h.jsx)(h.Fragment,{children:e});let t=Xbe(e).map((e,t)=>typeof e==`string`?e:(0,h.jsx)(GO,{to:`/settings`,search:{section:e.section},children:e.label},t));return(0,h.jsx)(h.Fragment,{children:t})}function qQ({kind:e,id:t,name:n}){let{api:r}=B(),i=_(),a=F({queryKey:oz.retired,queryFn:()=>pz(r)}),o=I({mutationFn:e=>mz(r,e),onSuccess:()=>Promise.all([i.invalidateQueries({queryKey:oz.retired}),i.invalidateQueries({queryKey:EO}),i.invalidateQueries({queryKey:DT})])}),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:[`${GQ[t.slot]} ${t.model} is ${t.why===`retired`?`retired`:`no longer listed`}.`,t.blocked===null?``:` ${t.blocked}`,t.replacement===null&&t.blocked===null?(0,h.jsx)(KQ,{text:` No replacement is suggested: choose another model in Settings → Models, or edit the ${e}.`}):null]}),t.replacement===null?null:(0,h.jsx)(z,{size:`small`,disabled:t.blocked!==null||o.isPending,disabledReason:t.blocked??`Switching…`,onClick:()=>o.mutate(t),children:`Switch to ${t.replacement.name}`})]},t.key)),o.error?(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The model wasn't switched: ${o.error.message}`}):null]})}function Zbe({tools:e,loaded:t,live:n,hiddenBySearch:r,channelFiltered:i,deleted:a,selectedId:o,pending:s,nextTitles:c,onPick:l,onEdit:u,onAction:d,onConfirm:f}){return(0,h.jsxs)(h.Fragment,{children:[e,n.length===0&&r>0?(0,h.jsx)(aQ,{title:`No schedule matches this search`,children:`Check the spelling, or clear the search to see all ${String(r)}.`}):t&&n.length===0?(0,h.jsx)(aQ,{title:i?`No schedules run this channel's templates`:a.length===0?`No schedules yet`:`No active schedules`,children:i?`Pick All channels to see the others, or make one from this channel's templates.`:a.length===0?`Your first one can be a one-off run or a recurring series. Press New schedule.`:`Create one with New schedule, or review deleted history below.`}):null,n.length>0?(0,h.jsx)(KL,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:n.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(WQ,{schedule:e,nextTitle:c.get(e.id),selected:o===e.id,pending:s,onSelect:()=>l(e.id),onEdit:()=>u(e),onAction:d,onConfirm:t=>f(t,e)}),(0,h.jsx)(qQ,{kind:`schedule`,id:e.id,name:e.name})]},e.id))}):null,a.length>0?(0,h.jsxs)(`details`,{className:`mt-6`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-small font-semibold text-ink-2`,children:[`Deleted schedules · `,a.length]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 mb-2 text-small text-ink-2`,children:`Deleted schedules stay in Settings → Trash for 30 days, where Restore brings one back paused. Pick one to see its run history.`}),(0,h.jsx)(KL,{label:`Deleted schedules`,children:a.map(e=>(0,h.jsx)(WQ,{schedule:e,nextTitle:void 0,selected:o===e.id,pending:!1,onSelect:()=>l(e.id),onEdit:()=>void 0,onAction:d,onConfirm:()=>void 0},e.id))})]}):null]})}function Qbe({pickedId:e,onPick:t}={}){let{api:n}=B(),r=_(),i=F(OT(n)),a=F(AO(n)),[o,s]=(0,m.useState)(null),c=Iv(),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(null),b=t===void 0?v:e??null,x=e=>{t===void 0?y(e):t(e)},[S,C]=(0,m.useState)(null),w=(0,m.useRef)(!1),T=F(Yy(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=F(VT(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=ib().channelId,[A,j]=(0,m.useState)(k??``),M=e=>{if(A===``)return!0;let t=a.data?.find(t=>t.id===e.templateId);return(t?oQ(t):Hy)===A},[ee,N]=(0,m.useState)(``),[te,P]=(0,m.useState)(`newest`),ne=i.data?.filter(e=>e.deletedAt===null)??[],re=ne.length>=5,ie=ne.filter(M),ae=re?Vbe(ie,ee,te):ie,oe=i.data?.filter(e=>e.deletedAt!==null)??[],se=b!==null&&i.data!==void 0&&!i.data.some(e=>e.id===b),ce=se?null:i.data?.find(e=>e.id===b)??ae[0]??null,le=I({onError:e=>s(e.message),onSettled:async()=>{w.current=!1,await r.invalidateQueries({queryKey:DT})},mutationFn:async e=>e(),onSuccess:async e=>{if(!e.ok){s(e.message);return}s(null)}}),ue=e=>{w.current||(w.current=!0,s(null),le.mutate(e))},de=d||l!==null,fe=()=>{u(null),f(!1),s(null)},pe=a.data?.length===0,me=()=>{de||pe||(u(null),f(!0),s(null))},he=e=>ue(async()=>{let t=await zbe(n,e,(i.data??[]).map(e=>e.name));if(t.ok){let e=t.value;await r.invalidateQueries({queryKey:DT}),x(e.id),c(`Duplicated as “${e.name}”: paused, with an empty topic queue. Press Edit to change it, then Resume.`,`success`,{label:`Edit`,run:()=>ge(e)})}return t}),ge=e=>{f(!1),x(e.id),u(e),s(null)};sb({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:me}),BO(IO.newSchedule,()=>{pe?c(`A schedule runs a project template, and there is none yet. Open a project, choose Save as template, then run New schedule again.`,`error`):me()},a.data!==void 0);let _e=o?{tone:`error`,text:o}:i.error?{tone:`error`,text:`The schedules couldn't be loaded: ${i.error.message} Reload the page to try again.`}:a.error?{tone:`error`,text:`The templates couldn't be loaded: ${a.error.message} Reload the page to try again.`}:void 0,ve=le.isPending||p||de;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 min-w-0 text-small text-ink-2`,children:pe?(0,h.jsxs)(h.Fragment,{children:[`Save a template in`,` `,(0,h.jsx)(pa,{className:`underline`,to:`/templates`,children:`Library → Templates`}),` `,`before creating a schedule.`]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Runs a saved template on this machine at a local time.`,(0,h.jsx)(H,{id:`planning.schedules`})]})}),(0,h.jsxs)(Pv,{children:[(0,h.jsxs)(sL,{"aria-label":`Filter schedules by channel`,value:A,className:`w-auto min-w-[160px]`,onChange:e=>j(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(T.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsxs)(z,{variant:`primary`,onClick:me,disabled:de||pe,disabledReason:pe?`Save a template in Library → Templates first`:`Finish or cancel the open form first`,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New schedule`]})]})]}),(0,h.jsx)(SR,{tone:de?`info`:_e?.tone??`info`,className:`mb-2`,children:de?void 0:_e?.text}),(0,h.jsx)(hG,{className:`min-[768px]:grid-cols-[minmax(320px,460px)_minmax(0,1fr)]`,list:(0,h.jsx)(Zbe,{tools:re?(0,h.jsx)(Hbe,{query:ee,sort:te,onQuery:N,onSort:P}):null,loaded:i.data!==void 0,live:ae,hiddenBySearch:re?ie.length-ae.length:0,channelFiltered:A!==``,deleted:oe,selectedId:de?void 0:ce?.id,pending:ve,nextTitles:O,onPick:x,onEdit:ge,onAction:ue,onConfirm:(e,t)=>C({kind:e,schedule:t})}),detail:de?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(U,{kicker:l?l.name:void 0,title:l?`Edit schedule`:`New schedule`,className:`mb-4`}),(0,h.jsx)(Nbe,{onBusy:g,editing:l,onCancel:()=>{p||fe()},templates:a.data??[],pending:le.isPending,error:o,onCreated:()=>{c(l?`Schedule updated.`:`Schedule saved. It will run automatically while Slopify is open.`,`success`),fe(),r.invalidateQueries({queryKey:DT})},onError:e=>{s(e),r.invalidateQueries({queryKey:DT})}},l?.id??`new`)]}):se?(0,h.jsx)(aQ,{title:`This schedule wasn't found`,children:`The link names a schedule that is no longer here: a deleted schedule leaves Settings → Trash after 30 days. Pick one from the list, or press New schedule.`}):ce?(0,h.jsx)(qbe,{schedule:ce,pending:ve,onAction:ue,onConfirm:e=>C({kind:e,schedule:ce}),onDuplicate:()=>he(ce)},ce.id):null}),(0,h.jsx)(Qv,{open:S!==null,title:S?.kind===`delete`?`Delete schedule?`:`Cancel schedule?`,consequence:(S?.kind===`delete`?`Moves this schedule to the trash for 30 days (Settings → Trash). Its run history is kept.`:`Stops future scheduled runs. Existing projects and run history are kept.`)+(o?` ${o}`:``),confirmLabel:S?.kind===`delete`?`Delete schedule`:`Cancel schedule`,cancelLabel:`Keep schedule`,pending:le.isPending,onCancel:()=>{le.isPending||C(null)},onConfirm:()=>{if(!S)return;let{kind:e,schedule:t}=S;ue(async()=>{let r=e===`delete`?await rce(n,t.id,t.version):await jT(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}var JQ=[`studio`,`releases`],YQ=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),$be=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`}),XQ=e=>`${YQ.format(new Date(e))}, ${$be.format(new Date(e))}`;function exe(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function txe(e){switch(e.state){case`scheduled`:return e.checks===`ok`?{tone:`neutral`,word:`✓ Scheduled · checks clear`}:e.checks===null?{tone:`info`,word:`✓ Scheduled · checks pending`}:{tone:`failed`,word:`Scheduled · ${e.checks}`};case`filled`:return{tone:`waiting`,word:`Filled in Studio, not scheduled`};case`late`:return{tone:`failed`,word:`Late · upload now`};case`not-ready`:return{tone:`neutral`,word:`Not rendered yet`};default:return{tone:`neutral`,word:`Ready to upload`}}}function nxe(e,t){let n=new Date(e),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-(n.getDay()+6)%7),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(t.getDay()+6)%7),a=Math.round((r.getTime()-i.getTime())/6048e5);return{key:r.toISOString(),label:a<=0?`This week`:a===1?`Next week`:`Week of ${YQ.format(r)}`}}function rxe({item:e,projectId:t,onDone:n}){let{api:r}=B(),i=_(),a=Iv(),[o,s]=(0,m.useState)(e.at===null?``:exe(e.at)),c=I({mutationFn:n=>hs(r,t,{short:e.short,at:n}),onSuccess:()=>{i.invalidateQueries({queryKey:JQ}),n()},onError:e=>a(`The time wasn't changed: ${e.message}`,`error`)}),l=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(X,{"aria-label":`${l}: release`,type:`datetime-local`,className:`w-[200px]`,value:o,onChange:e=>s(e.currentTarget.value)}),(0,h.jsx)(z,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(new Date(o).toISOString()),children:`Save`}),e.short===0?(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,disabled:c.isPending,onClick:()=>c.mutate(null),children:`Not scheduled`}):null,(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,onClick:n,children:`Cancel`})]})}function ZQ({item:e,projectId:t,editing:n,onEdit:r}){let i=txe(e),a=n?.projectId===t&&n.short===e.short,o=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[o,e.at===null?``:` · goes public`]}),e.short===0?null:(0,h.jsx)(`span`,{className:`w-full truncate text-small`,title:e.title,children:e.title}),a?(0,h.jsx)(rxe,{item:e,projectId:t,onDone:()=>r(void 0)}):(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,"aria-label":`${o}: move from ${e.at===null?`no time`:XQ(e.at)}`,onClick:()=>r({projectId:t,short:e.short}),children:e.at===null?`Set a time`:XQ(e.at)}),(0,h.jsx)(tk,{tone:i.tone,children:i.word})]})}function ixe({entry:e,candidates:t}){let{api:n}=B(),r=_(),i=Iv(),a=t.filter(t=>e.series===``||t.series===e.series),[o,s]=(0,m.useState)(``),c=I({mutationFn:t=>hs(n,t,{short:0,at:e.at,...e.line===null?{}:{line:e.line}}),onSuccess:()=>void r.invalidateQueries({queryKey:JQ}),onError:e=>i(`The project wasn't put there: ${e.message}`,`error`)});return a.length===0?(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[`Free · no finished project`,e.series===``?``:` of ${e.series}`,` waits for a time`]}):(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(sL,{"aria-label":`Project for ${XQ(e.at)}`,className:`w-[260px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:``,label:`Free · pick a finished project`},...a.map(e=>({value:e.id,label:e.title}))]}),(0,h.jsx)(z,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(o),children:`Put it here`})]})}var QQ=6048e5;function axe(e,t){let n=Math.min(Math.max(0,e),3),r=Math.min(8,(n+1)*2);return{weeks:r,start:n===0?void 0:new Date(t.getTime()+n*2*QQ),end:new Date(t.getTime()+r*QQ),hasEarlier:n>0,hasLater:n<3}}function oxe(e,t){return e.filter(e=>{let n=new Date(e.at).getTime();return(t.start===void 0||n>=t.start.getTime())&&n<t.end.getTime()})}function sxe(){let{api:e}=B(),[t,n]=(0,m.useState)(0),[r]=(0,m.useState)(()=>new Date),i=axe(t,r),a=F({queryKey:[...JQ,i.weeks],queryFn:()=>fs(e,i.weeks),placeholderData:e=>e}),[o,s]=(0,m.useState)();if(a.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the releases…`});if(a.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The releases didn't load: `,a.error.message,` Reload the page to try again.`]});let c=a.data,l=oxe(c.entries,i),u=t===0?`The next two weeks`:`${YQ.format(i.start??r)} to ${YQ.format(i.end)}`,d=new Map;for(let e of l){let t=nxe(e.at,r),n=d.get(t.key)??{label:t.label,entries:[]};n.entries.push(e),d.set(t.key,n)}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Every video and short is due `,String(c.leadHours),` hours before its release, so YouTube's copyright and ad checks finish while it is private. Change that, or the weekly times, in`,` `,(0,h.jsx)(pa,{to:`/settings`,search:{section:`studio`},children:`Settings → YouTube Studio`}),`.`]}),(0,h.jsxs)(`nav`,{"aria-label":`Release weeks`,className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsxs)(Pv,{children:[(0,h.jsx)(z,{size:`small`,disabled:!i.hasEarlier,disabledReason:`Releases already public are not listed here; open the project to see its release.`,onClick:()=>n(t-1),children:`Earlier`}),(0,h.jsx)(z,{size:`small`,disabled:!i.hasLater,disabledReason:`Releases are listed up to 8 weeks ahead.`,onClick:()=>n(t+1),children:`Later`}),t===0?null:(0,h.jsx)(z,{size:`small`,variant:`quiet`,onClick:()=>n(0),children:`Back to this week`})]}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:u})]}),l.length===0?t===0?(0,h.jsx)(aQ,{title:`No releases in the next two weeks`,children:`Add your week in Settings → YouTube Studio → Posting plan: each finished project then takes its next free time, and its shorts the times after it. Or open a finished project's Prepare upload, or press Later to look further ahead.`}):(0,h.jsx)(aQ,{title:`No releases from ${u}`,children:`Nothing is planned in these weeks yet. Press Back to this week, or Earlier.`}):null,[...d.values()].map(e=>(0,h.jsxs)(`section`,{"aria-label":e.label,className:`flex flex-col gap-3`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:e.label}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:e.entries.map(e=>{let t=e.items.find(e=>e.short===0),n=e.items.filter(e=>e.short>0);return(0,h.jsxs)(`li`,{className:`flex flex-col gap-2 border-b border-line pb-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:XQ(e.at)}),e.series===``?null:(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.series}),e.project===null?null:(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.project.id},children:e.project.title})]}),e.project===null?(0,h.jsx)(ixe,{entry:e,candidates:c.candidates}):(0,h.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-x-4 gap-y-3`,children:[t===void 0?null:(0,h.jsx)(ZQ,{item:t,projectId:e.project.id,editing:o,onEdit:s}),n.map(t=>(0,h.jsx)(ZQ,{item:t,projectId:e.project?.id??``,editing:o,onEdit:s},t.short))]})]},`${e.at}-${e.project?.id??`free`}`)})})]},e.label))]})}var $Q=4;function cxe(e){return e===`schedules`?`schedules`:e===`releases`?`releases`:`weeks`}var e$=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),t$=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),n$=864e5,r$=`slopify.calendar.view`;function lxe(){try{return window.localStorage.getItem(r$)===`list`?`list`:`weeks`}catch{return`weeks`}}function uxe({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=B(),a=ib(),[o,s]=(0,m.useState)(0),c=(0,m.useMemo)(()=>eR(new Date(Date.now()+o*$Q*7*n$),$Q),[o]),[l,u]=(0,m.useState)(lxe),[d,f]=(0,m.useState)(e??`weeks`),p=n===void 0?d:e??`weeks`,g=e=>{n===void 0?f(e):n(e)},[_,v]=(0,m.useState)(!1),y=F(VT(i,c.from,c.to)),b=F(OT(i)),x=F(AO(i)),S=F(gy(i)),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),D=(0,m.useMemo)(()=>new Map((x.data??[]).map(e=>[e.id,e.channelId])),[x.data]),O=(0,m.useMemo)(()=>new Map((S.data?.projects??[]).map(e=>[e.id,e.channelId])),[S.data]),k=(b.data??[]).filter(e=>a.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>a.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>a.includes(O.get(e.id)))},j=(0,m.useMemo)(()=>A===void 0?new Map:$L(A),[A]),M=A?.runs??[],ee=Dve(A?.projects??[]),N=tbe(VT(i,c.from,c.to).queryKey,w),te=(e,t,n)=>{if(e.kind!==`none`){if(e.kind===`refused`){w(e.message);return}N.mutate({drop:e,title:t,where:n})}},P=(e,t)=>{let n=nR(M,e,t);if(n===void 0){w(t===-1?`${rR(e)} is already the next topic of ${e.scheduleName}.`:`${rR(e)} is the last topic on the calendar for ${e.scheduleName}. Show Later weeks to move it further.`);return}let r=e$.format(new Date(n.at));te(tR(e,n,r),rR(e),r)},ne=e=>{u(e),p!==`weeks`&&g(`weeks`);try{window.localStorage.setItem(r$,e)}catch{}};sb({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),sb({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>g(`schedules`)}),BO(IO.addToCalendar,()=>v(!0)),sb({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>ne(`weeks`)}),sb({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>ne(`list`)});let re=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),ie=XL(new Date),ae=`${t$.format(new Date(c.from))} to ${t$.format(new Date(Date.parse(c.to)-2*n$))}`,oe=(A?.queued??[]).toSorted((e,t)=>e.position-t.position),se=oe.filter(e=>e.state===`queued`),ce=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(fG,{title:`Calendar`,meta:`${a.channel?.name??`Every channel`} · ${String(M.length)} scheduled ${M.length===1?`run`:`runs`} ${o===0?`in the next ${String($Q)} weeks`:ae} · ${String(re)} ${re===1?`topic`:`topics`} queued`,actions:p===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Fy,{label:`Calendar view`,tip:`planning.calendar.view`,value:l,onChange:ne,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(z,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]}):void 0}),(0,h.jsx)(rQ,{items:[{id:`weeks`,label:`Coming weeks`},{id:`releases`,label:`Releases`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ce)}}],value:p,onChange:g,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(iQ,{idPrefix:`calendar`,id:`releases`,active:p===`releases`,children:p===`releases`?(0,h.jsx)(sxe,{}):null}),(0,h.jsx)(iQ,{idPrefix:`calendar`,id:`schedules`,active:p===`schedules`,children:p===`schedules`?(0,h.jsx)(Qbe,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(iQ,{idPrefix:`calendar`,id:`weeks`,active:p===`weeks`,children:[(0,h.jsx)(SR,{tone:C===null?`info`:`error`,className:`mb-3`,children:C??void 0}),y.data===void 0||y.error===null?null:(0,h.jsx)(`div`,{className:`mb-3`,children:(0,h.jsx)(ML,{what:`the calendar`,error:y.error,updatedAt:y.dataUpdatedAt,onRetry:()=>void y.refetch(),retrying:y.isFetching})}),y.data===void 0&&y.error!==null?(0,h.jsx)(jL,{what:`The calendar`,error:y.error,onRetry:()=>void y.refetch(),retrying:y.isFetching}):(0,h.jsxs)(h.Fragment,{children:[A===void 0||ee.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 mb-4 text-small text-ink-2`,children:[Eve(ee),`. `,(0,h.jsx)(GO,{to:`/`,children:`Open Home`}),` to act on them.`]}),b.data!==void 0&&YZ(k).length===0?null:(0,h.jsx)(`section`,{"aria-label":`Suggested topics`,className:`mb-6 min-w-0`,children:b.data===void 0&&b.error!==null?(0,h.jsx)(jL,{compact:!0,what:`Your schedules`,error:b.error,onRetry:()=>void b.refetch(),retrying:b.isFetching}):(0,h.jsx)(Xye,{schedules:k})}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(dxe,{label:ae,shift:o,onShift:e=>s(t=>e===0?0:t+e)}),y.data===void 0?(0,h.jsx)(AL,{label:`Loading the calendar…`,rows:2,rowClassName:`h-40`}):l===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic by its grip to another day to change when it runs, or onto another schedule's run to move it there. With the keyboard: focus a topic and press Alt+← or Alt+→.`}),QL(new Date(c.from),$Q).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=XL(e),n=j.get(t);return(0,h.jsx)(sR,{date:e,today:t===ie,day:n,dragging:T,busy:N.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(te(tR(T,t,e$.format(e)),rR(T),e$.format(e)),E(null))},onStep:P},t)})},XL(e[0]??new Date)))]}):(0,h.jsx)(XB,{days:j,busy:N.isPending,onStep:P,schedules:k,onMove:(e,t)=>{let n=e$.format(new Date(t.at));te(tR(e,t,n),rR(e),n)},onTransfer:(e,t)=>{e.index!==null&&te({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0},rR(e),`the end of ${k.find(e=>e.id===t)?.name??`the other schedule`}`)}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(U,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(KL,{label:`Batch queue`,children:oe.map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(qL,{title:(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ek,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`}),e.state===`queued`?(0,h.jsx)(tQ,{projectId:e.projectId,title:e.title,place:se.indexOf(e),waiting:se.length}):null]})},e.projectId)})})]}):null]})]})]}),(0,h.jsx)(wve,{open:_,onOpenChange:v,schedules:k})]})}function dxe({label:e,shift:t,onShift:n}){return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(z,{size:`small`,variant:`secondary`,onClick:()=>n(-1),children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Earlier`]}),(0,h.jsx)(`span`,{className:`text-small text-ink-2 tabular-nums`,"aria-live":`polite`,children:e}),(0,h.jsxs)(z,{size:`small`,variant:`secondary`,onClick:()=>n(1),children:[`Later`,(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})]}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:t===0,onClick:()=>n(0),children:`This week`})]})}var fxe=mD.map(e=>({value:e,label:hD[e]}));function pxe({channel:e}){let{api:t}=B(),n=_(),r=Iv(),i=I({mutationFn:n=>Cre(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${hD[e.aiDisclosure]}.`,`success`),n.setQueryData(Ky(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:Gy,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)(iL,{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)(sL,{value:i.isPending?i.variables:e.aiDisclosure,options:fxe,disabled:i.isPending,onChange:e=>{let t=mD.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(SR,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}var mxe=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;function i$(e){let t=mxe.exec(e.trim())?.[1];if(t!==void 0)return`#${(t.length===3?[...t].map(e=>e+e).join(``):t).toLowerCase()}`}var hxe=`Write the colour as # and 3 or 6 hex digits, like #8c1e14 or #fff.`;function a$(e){if(e.trim()!==``)return i$(e)===void 0?hxe:void 0}function o$(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function s$(e){let t=Number.parseInt(e.slice(1,3),16),n=Number.parseInt(e.slice(3,5),16),r=Number.parseInt(e.slice(5,7),16);return .2126*o$(t)+.7152*o$(n)+.0722*o$(r)}function gxe(e,t){let n=i$(e),r=i$(t);if(n===void 0||r===void 0)return;let[i,a]=[s$(n),s$(r)].sort((e,t)=>t-e);return(i+.05)/(a+.05)}function c$(e,t,n,r){let i=gxe(e,t);if(!(i===void 0||i>=r))return`Hard to read on ${n}: contrast ${i.toFixed(1)}:1, below the ${String(r)}:1 text needs. Pick a lighter or darker colour.`}function l$({value:e,onChange:t,pickerLabel:n,className:r,...i}){let a=i$(e),o=(0,m.useRef)(a);a!==void 0&&(o.current=a),e.trim()===``&&(o.current=void 0);let s=a??o.current;return(0,h.jsxs)(`span`,{className:R(`flex min-w-0 items-center gap-2`,r),children:[(0,h.jsx)(`span`,{"data-partial":a===void 0&&s!==void 0?``:void 0,className:`relative size-8 shrink-0 overflow-hidden rounded-control border border-line-strong data-[partial]:opacity-40`,style:{background:s??`repeating-linear-gradient(45deg, transparent 0 4px, var(--color-line) 4px 5px)`},children:(0,h.jsx)(`input`,{type:`color`,"aria-label":n,value:s??`#ffffff`,className:`absolute inset-0 size-full cursor-pointer opacity-0`,onChange:e=>t(e.target.value)})}),(0,h.jsx)(X,{...i,className:`w-28 font-mono`,spellCheck:!1,autoComplete:`off`,value:e,onChange:e=>t(e.target.value)})]})}function u$({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)(iL,{label:r,tip:o,help:_xe(s),error:i,children:(0,h.jsxs)(sL,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:UT.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,WT(n.language).name,`)`]}),HT.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function _xe(e){let t=WT(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=GT(t.code);return r===void 0?`${n} Captions are timed word by word with a free 248 MB model, downloaded the first time a ${t.name} project makes captions.`:`${n} ${r}`}function vxe({rows:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,h.jsxs)(`section`,{"aria-label":`Channel links`,...Ny,children:[(0,h.jsx)(U,{title:`Channel links`,meta:`Write a link's name in braces in a description, such as {{Patreon}}.`,info:`planning.links.named`}),e.length===0?(0,h.jsx)(`p`,{className:`m-0 border-y border-line py-4 text-ink-2`,children:`No channel links yet. Add one, then write its name in braces in a description.`}):(0,h.jsxs)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:[(0,h.jsxs)(`li`,{"aria-hidden":`true`,className:`hidden grid-cols-[220px_minmax(0,1fr)_auto] gap-2 border-b border-line pt-1 pb-2 text-label text-ink-2 md:grid`,children:[(0,h.jsxs)(`span`,{children:[`Name, used as `,`{{Name}}`]}),(0,h.jsx)(`span`,{children:`Address`})]}),e.map((r,i)=>(0,h.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,1fr)] items-center gap-2 border-b border-line py-3 md:grid-cols-[220px_minmax(0,1fr)_auto]`,children:[(0,h.jsxs)(`span`,{className:`grid gap-1`,children:[(0,h.jsxs)(`span`,{"aria-hidden":`true`,className:`text-label text-ink-2 md:hidden`,children:[`Name, used as `,`{{Name}}`]}),(0,h.jsx)(X,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})})]}),(0,h.jsxs)(`span`,{className:`grid gap-1`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`text-label text-ink-2 md:hidden`,children:`Address`}),(0,h.jsx)(X,{"aria-label":`Address of link ${String(i+1)}`,type:`url`,placeholder:`https://`,value:r.url,onChange:e=>n(i,{url:e.currentTarget.value})})]}),(0,h.jsxs)(z,{variant:`quiet`,size:`small`,className:`justify-self-start`,"aria-label":`Remove link ${String(i+1)}`,onClick:()=>t(e.filter((e,t)=>t!==i)),children:[(0,h.jsx)(xl,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))]}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(z,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function yxe(){return(0,h.jsxs)(`div`,{...Ny,children:[(0,h.jsx)(U,{title:`Named links`,info:`planning.links.named`}),(0,h.jsx)(`p`,{className:`m-0 max-w-[60ch] text-ink-2`,children:`Each channel keeps its own links now, on its Brand tab under Channel links. Links saved here before fill the default channel's descriptions until you save its Brand tab.`}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsx)(WO,{to:`/channels/$channelId`,params:{channelId:Hy},children:`Open the default channel's links`})})]})}function d$({changed:e,defaultText:t,label:n,onReset:r}){return(0,h.jsxs)(`span`,{className:`mt-1 flex min-h-7 items-center gap-2 text-label text-ink-2`,children:[(0,h.jsx)(`span`,{children:e?`Changed · default ${t}`:`Default`}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,disabled:!e,"aria-label":`Reset ${n} to ${t}`,onClick:r,children:`Reset`})]})}function f$({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(SE.levelDb),fadeIn:e?.fadeIn??String(SE.fadeInSeconds),tail:e?.tail??String(SE.tailSeconds)},u=e=>{if(e===``)s(void 0);else if(e===`none`)s({source:`none`,...l});else{let t=n.find(t=>t===e);t!==void 0&&s({source:t,...l})}},d=(t,n,r,a)=>e===void 0||!c?null:(0,h.jsxs)(iL,{label:n,help:r,tip:a,error:i(t),children:[(0,h.jsx)(X,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})}),t===`level`?(0,h.jsx)(d$,{changed:e.level.trim()!==String(SE.levelDb),defaultText:`${String(SE.levelDb)} dB`,label:`ambient level`,onReset:()=>s({...e,level:String(SE.levelDb)})}):null]});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(iL,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(sL,{"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:Kce[e]},e))]})}),e?.source===`upload`?a:null,c?(0,h.jsxs)(`div`,{className:`contents`,children:[d(`level`,`Level (dB)`,`-40 to -6; 0 is about as loud as the voice.`,`project.ambient.level`),d(`fadeIn`,`Fade in (seconds)`,`0 to 30.`,`project.ambient.fade-in`),d(`tail`,`Tail after the narration (seconds)`,`0 to 30, fading out.`,`project.ambient.tail`)]}):null]})}function bxe({value:e,onChange:t}){let n=EE(e),r=n===void 0?[]:CE(n);return(0,h.jsx)(f$,{value:e,inherit:`Not set`,sources:bE,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function xxe(e){return e.ambientBed===void 0?void 0:TE(e.ambientBed)}function Sxe(e){let t=EE(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:CE(t).length>0}}var p$=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`],m$=1e4;function Cxe(e){return Object.fromEntries(p$.map(t=>[t,e[t]??``]))}function wxe({channel:e}){let{api:t}=B(),n=_(),r=Iv(),i=F({queryKey:Ik,queryFn:()=>Lk(t)}),a=F(Cy(t)),o=F(wy(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(Cxe(e.brand)),[p,g]=(0,m.useState)(xxe(e.brand)),v=Sxe(p),y=F({queryKey:V.channelLinks,queryFn:()=>Vs(t),enabled:e.isDefault&&e.brand.links===void 0}),[b,x]=(0,m.useState)(),S=b??e.brand.links??y.data??[],C=b!==void 0||e.brand.links!==void 0||(y.data?.length??0)>0,w=I({mutationFn:()=>Zy(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(p$.flatMap(e=>d[e].trim()===``?[]:[[e,Txe(e,d[e])]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(Ky(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:Gy}),n.invalidateQueries({queryKey:V.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=_$.some(e=>a$(d[e])!==void 0),D=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),O=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),k=[...(o.data?.builtIns??[]).map(e=>({value:e.name,label:e.label})),...(o.data?.themes??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(`form`,{"aria-label":`Brand kit`,onSubmit:e=>{e.preventDefault(),w.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-5`,children:[(0,h.jsx)(iL,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(X,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(iL,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules. ${sQ(l.length,m$,`characters`)}.`,children:(0,h.jsx)(oL,{rows:4,value:l,maxLength:m$,onChange:e=>u(e.target.value)})}),(0,h.jsx)(U,{title:`Brand kit`,meta:`Fills what a template leaves at its default. Blank fields add nothing.`,info:`planning.channel.brand-kit`,className:`mt-2 border-t border-line pt-6`}),(0,h.jsx)(`section`,{"aria-label":`Language`,className:`max-w-md`,children:(0,h.jsx)(u$,{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)(h$,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:D,onPick:T(`captionFontId`)}),(0,h.jsx)(g$,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(g$,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`),contrast:c$(d.captionColor,d.captionOutlineColor,`the caption colour`,3)})]}),(0,h.jsxs)(`section`,{"aria-label":`Chapter cards and end screen`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(h$,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:D,onPick:T(`titleFontId`)}),(0,h.jsx)(g$,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(iL,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(X,{value:d.endScreenText,maxLength:200,placeholder:`Subscribe for more`,onChange:e=>T(`endScreenText`)(e.target.value)})})]}),(0,h.jsxs)(`section`,{"aria-label":`Intro, outro and document`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(h$,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:O(`intro`),onPick:T(`intro`)}),(0,h.jsx)(h$,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:O(`outro`),onPick:T(`outro`)}),(0,h.jsx)(h$,{label:`PDF theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:k,onPick:T(`documentTheme`)})]}),(0,h.jsx)(bxe,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(vxe,{rows:S,onChange:x})})]}),(0,h.jsx)(CR,{status:(0,h.jsx)(SR,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(z,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked||E,disabledReason:s.trim()===``?`Give the channel a name`:E?`Fix the colour marked above`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function h$({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(iL,{label:e,tip:t,children:(0,h.jsxs)(sL,{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 g$({label:e,tip:t,value:n,onChange:r,contrast:i}){let a=a$(n);return(0,h.jsx)(iL,{label:e,tip:t,...a===void 0?{}:{error:a},...a===void 0&&i!==void 0?{help:i}:{},children:(0,h.jsx)(l$,{value:n,placeholder:`#FFFFFF`,maxLength:7,pickerLabel:`${e} picker`,onChange:r})})}var _$=[`captionColor`,`captionOutlineColor`,`titleColor`];function Txe(e,t){let n=t.trim();return _$.includes(e)?i$(n)?.toUpperCase()??n:n}function v$(e,t){return e.languages===void 0||e.languages.includes(WT(t).code)}function Exe(e,t,n,r){return n?e:e.filter(e=>v$(e,t)||e.voiceId===r)}function Dxe(e,t){if(e===void 0||v$(e,t))return;let n=WT(t).name,r=(e.languages??[]).map(e=>WT(e).code===e?WT(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 y$(e,t,n){let[r,i]=(0,m.useState)(!1),a=Exe(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function b$({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=Dxe(t,e);return n===0&&!r&&o===void 0?null:(0,h.jsxs)(`div`,{className:`col-span-full grid gap-1`,children:[n>0||r?(0,h.jsxs)(`span`,{className:`flex min-h-8 items-center gap-1`,...Ny,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 ${WT(e).name})`]}),(0,h.jsx)(H,{id:`play.show-all-voices`})]}):null,o===void 0?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:o})]})}function x$(e,t,n){let r=t+n,i=e[t];if(i===void 0||r<0||r>=e.length)return[...e];let a=e.filter((e,n)=>n!==t);return a.splice(r,0,i),a}function S$(e,t,n){let r=`${e.trim()||`Untitled`} copy`,i=new Set(t.map(e=>e.trim().toLowerCase())),a=1,o=r;for(;i.has(o.slice(0,n).toLowerCase());)a+=1,o=`${r} ${String(a)}`;return o.slice(0,n)}var Oxe=200;function kxe({channelId:e,member:t,onCreated:n}){let{api:r}=B(),i=_(),a=Iv(),o=F(Xy(r,e)),s=I({mutationFn:()=>$y(r,e,crypto.randomUUID(),{kind:t.kind,name:S$(t.name,(o.data?.cast??[]).map(e=>e.name),Oxe),aliases:[],description:t.description,voice:t.voice??null,host:!1}),onSuccess:async t=>{await Promise.all([i.invalidateQueries({queryKey:Ky(e)}),i.invalidateQueries({queryKey:Gy})]),a(`Made “${t.name}”. Its pictures are not copied: upload or generate them under Reference pictures.`,`success`),n(t.id)},onError:e=>a(`Couldn't duplicate ${t.name}: ${e.message} Press Duplicate in its editor to try again.`,`error`)});return(0,h.jsx)(z,{variant:`quiet`,size:`small`,disabled:s.isPending||o.data===void 0,disabledReason:s.isPending?`Making the copy`:`Loading the cast`,onClick:()=>s.mutate(),children:`Duplicate`})}var C$=4e3;function Axe({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=B(),o=_(),[s,c]=(0,m.useState)(t?.kind??`character`),[l,u]=(0,m.useState)(t?.name??``),[d,f]=(0,m.useState)(t?.aliases??[]),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(t?.description??``),[b,x]=(0,m.useState)(t?.voice),[S,C]=(0,m.useState)(t?.host===!0),w=()=>Promise.all([o.invalidateQueries({queryKey:Ky(e)}),o.invalidateQueries({queryKey:Gy})]),T=I({mutationFn:async()=>{let n={kind:s,name:l.trim(),aliases:d,description:v,voice:b!==void 0&&b.provider!==``&&b.model!==``&&b.voice!==``?b:null,host:S};return t===void 0?$y(a,e,crypto.randomUUID(),n):gre(a,t.id,{...n,baseVersion:t.version})},onSuccess:async e=>{await w(),t===void 0&&i(e.id)}}),E=()=>{let e=p.trim();e===``||d.some(t=>t.toLowerCase()===e.toLowerCase())||(f([...d,e]),g(``))};return n?(0,h.jsxs)(`section`,{"aria-label":t===void 0?`Add to cast`:`Edit ${t.name}`,children:[(0,h.jsxs)(U,{kicker:t===void 0?`New cast member`:Wy[t.kind],title:t===void 0?`Add to cast`:t.name,meta:t===void 0?`Name it first, then give it reference pictures.`:`Used whenever a title or an image brief names it or one of its aliases.`,children:[t===void 0?null:(0,h.jsx)(kxe,{channelId:e,member:t,onCreated:i}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,onClick:r,children:`Close`})]}),t!==void 0&&!t.images.some(e=>e.state===`ready`)?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-waiting`,children:`No picture yet, so it is not sent with any image. Upload or generate one below.`}):null,(0,h.jsxs)(`form`,{id:`cast-member-form`,"aria-label":`Cast member`,className:`mt-4 flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),l.trim()!==``&&T.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(iL,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(sL,{value:s,onChange:e=>c(Uy.find(t=>t===e.target.value)??`character`),options:Uy.map(e=>({value:e,label:Wy[e]}))})}),(0,h.jsx)(iL,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(X,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(iL,{label:`Aliases`,tip:`planning.cast.aliases`,help:`Press Enter to add each one.`,children:(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(X,{value:p,maxLength:200,placeholder:`Another name, such as the Last Pharaoh`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,h.jsxs)(z,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add alias`]})]})}),d.length>0?(0,h.jsx)(`ul`,{"aria-label":`Aliases added`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:d.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(nk,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(iL,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(oL,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(Mxe,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(Py,{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)(SR,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(z,{type:`submit`,form:`cast-member-form`,variant:t===void 0?`primary`:`secondary`,disabled:T.isPending||l.trim()===``,children:t===void 0?`Add to cast`:`Save`})]})]}),t===void 0?null:(0,h.jsx)(jxe,{channelId:e,member:t})]}):null}function jxe({channelId:e,member:t}){let{api:n}=B(),r=_(),i=F(by(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:Ky(e)}),r.invalidateQueries({queryKey:Gy})]),g=I({mutationFn:e=>yre(n,t.id,e),onSettled:p}),v=I({mutationFn:()=>bre(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=I({mutationFn:e=>xre(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:eb(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)(gG,{className:`mb-6`}),(0,h.jsx)(U,{as:`h3`,title:`Reference pictures`,meta:`Sent with every image whose brief, or the video's title, names ${t.name}.`,info:`planning.cast.pictures`}),t.images.length>0?(0,h.jsx)(nz,{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)(tz,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:eb(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)(tk,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(z,{variant:`secondary`,size:`small`,"aria-label":`Delete picture ${String(r+1)} of ${t.name}`,disabled:y.isPending||e.state===`generating`,disabledReason:`Wait until the picture is made`,onClick:()=>y.mutate(e.id),children:`Delete`})}),e.state===`failed`&&e.error?(0,h.jsx)(Nxe,{error:e.error,retry:s===``||l===``||d.trim()===``?void 0:{run:()=>v.mutate(),busy:v.isPending},onReword:()=>o.current?.focus()}):null]},e.id))}):(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-3`,children:`No pictures yet.`}),(0,h.jsx)(rz,{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)(KO,{href:r.src,download:!0,size:`small`,"aria-label":`Download picture ${String(r.number)} of ${t.name}`,children:`Download`})}}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg`,className:`sr-only`,tabIndex:-1,"aria-hidden":`true`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&g.mutate(t)}}),(0,h.jsx)(z,{disabled:g.isPending,onClick:()=>a.current?.click(),children:`Upload a picture`}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`PNG or JPEG, up to 10 MB.`})]}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,...Ny,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(H,{id:`planning.cast.generate`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(vL,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(hL,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(iL,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,help:sQ(d.length,C$,`characters`),children:(0,h.jsx)(oL,{ref:o,rows:3,value:d,maxLength:C$,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(z,{disabled:v.isPending||s===``||l===``||d.trim()===``,disabledReason:`Pick an image provider and model, and describe the picture`,onClick:()=>v.mutate(),children:`Generate a picture`})})]}),(0,h.jsx)(SR,{tone:b?`error`:`info`,className:`mt-2`,children:b?.message??(g.isPending?`Uploading…`:v.isSuccess?`The picture is being made; it appears here when it is ready.`:void 0)})]})}function Mxe({channelId:e,value:t,onChange:n}){let{api:r}=B(),i=F(by(r)),a=F(xy(r)),o=F(Xy(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=y$(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`,...Ny,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(H,{id:`planning.cast.voice`,label:`Cast voice`,className:`-my-1`})]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`For multi-voice runs: pick this member under Speakers on Play.`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(vL,{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)(hL,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(_L,{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)(b$,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(_L,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:KE.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:void 0,onPick:e=>{let{pace:t,...r}=s;n(Number(e)===1?r:{...r,pace:Number(e)})}})]}),t===void 0?null:(0,h.jsx)(z,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function Nxe({error:e,retry:t,onReword:n}){let r=KZ({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)(Pv,{className:`mt-2`,children:(0,h.jsx)(Sz,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(z,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}var w$=`Alt+ArrowUp Alt+ArrowDown`;function Pxe(e,t){let{api:n}=B(),r=_(),i=Iv(),a=(0,m.useRef)(t);a.current=t;let o=I({mutationFn:t=>vre(n,e,t.member.id,t.to),onSuccess:async t=>{r.setQueryData(Ky(e),e=>e===void 0?e:{...e,cast:t}),await r.invalidateQueries({queryKey:Ky(e)})}}),s=(e,t,n,r=!0)=>{let c=a.current,l=c.findIndex(t=>t.id===e.id);l<0||t===l||t<0||t>=c.length||o.mutate({member:e,to:t},{onSuccess:()=>i(`Moved ${e.name} ${n}: ${String(t+1)} of ${String(c.length)}.`,`success`,r?{label:`Undo`,run:()=>s(e,l,`back`,!1)}:void 0),onError:t=>i(`Couldn't move ${e.name}: ${t.message} Try Move up or Move down in its More menu again.`,`error`)})};return{busy:o.isPending,move:s,onKeyDown:e=>t=>{if(!t.altKey||t.key!==`ArrowUp`&&t.key!==`ArrowDown`||(t.preventDefault(),o.isPending))return;let n=a.current.findIndex(t=>t.id===e.id),r=t.key===`ArrowUp`;s(e,n+(r?-1:1),r?`up`:`down`)}}}function Fxe({member:e,index:t,count:n,order:r}){let i=t===0,a=t===n-1;return(0,h.jsxs)(JO,{modal:!1,children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsx)(Mv,{size:`small`,label:`More for ${e.name}`,"aria-keyshortcuts":w$,disabled:n<2,disabledReason:`Add another member to change the order`,onKeyDown:r.onKeyDown(e),children:(0,h.jsx)(Hc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsxs)(XO,{children:[(0,h.jsx)(ZO,{disabled:i||r.busy,onSelect:()=>r.move(e,t-1,`up`),children:`Move up`}),(0,h.jsx)(ZO,{disabled:a||r.busy,onSelect:()=>r.move(e,t+1,`down`),children:`Move down`}),(0,h.jsx)(ZO,{disabled:i||r.busy,onSelect:()=>r.move(e,0,`to the top`),children:`Move to top`}),(0,h.jsx)(ZO,{disabled:a||r.busy,onSelect:()=>r.move(e,n-1,`to the bottom`),children:`Move to bottom`})]})]})}var T$=e=>`It is deleted permanently: ${e} do not go to Settings → Trash, so it cannot be restored.`,E$=e=>e===void 0?`Delete this channel?`:`Delete the channel “${e}”?`,D$=`${T$(`channels`)} Its cast and their reference pictures, its episode summaries, its video memory and its brand settings go with it. Its projects move to the default channel and keep what they were made with.`,Ixe=e=>e===void 0?`Delete this cast member?`:`Delete “${e}” from the cast?`,Lxe=`${T$(`cast members`)} Its reference pictures go with it, and new videos stop using them. Videos already made keep the pictures they were started with.`,Rxe=e=>e===void 0?`Delete this episode summary?`:`Delete the episode summary of “${e}”?`,zxe=`${T$(`episode summaries`)} New episodes stop being reminded of it. The video itself is not changed.`,Bxe=8;function Vxe({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=B(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=I({mutationFn:e=>_re(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:Ky(e)}),a.invalidateQueries({queryKey:Gy})])}}),p=t.find(e=>e.id===c),g=Pxe(e,t),v=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:eb(i,t)}]:[]}),y=v.map(e=>({src:e.src,alt:e.member.name,caption:`${Wy[e.member.kind]} · ${e.member.description||`No description yet`}`})),[b,x]=(0,m.useState)(null),[S,C]=(0,m.useState)(``),w=S.trim().toLowerCase(),T=w===``?t:t.filter(e=>e.id===c||[e.name,...e.aliases,Wy[e.kind],e.description].join(` `).toLowerCase().includes(w)),E=c===`new`||p!==void 0;return(0,h.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 min-[1024px]:grid-cols-[minmax(0,1fr)_440px]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:`When a video's title or an image's brief names a member, its pictures go with that image as references, so it looks the same in every video.`}),t.length===0?(0,h.jsx)(aQ,{title:`No cast yet`,actions:(0,h.jsx)(z,{variant:`secondary`,onClick:()=>l(`new`),children:`Add to cast`}),children:`Add the characters, creatures, places and objects this channel keeps coming back to.`}):(0,h.jsxs)(h.Fragment,{children:[t.length>Bxe?(0,h.jsx)(X,{type:`search`,"aria-label":`Search the cast`,placeholder:`Search ${String(t.length)} members by name, kind or description`,value:S,onChange:e=>C(e.target.value),className:`mb-4 max-w-[420px]`}):null,T.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No member's name, kind or description contains "${S.trim()}".`}):null,(0,h.jsx)(nz,{label:`Cast`,children:T.map(e=>{let n=e.images.filter(e=>e.state===`ready`),r=n[0]?.sha256;return(0,h.jsx)(tz,{className:R(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...r?{src:eb(i,r)}:{},alt:e.name,onOpen:()=>x(v.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${Wy[e.kind]}${e.host===!0?` · Host`:``} · ${String(n.length)} ${n.length===1?`picture`:`pictures`}`,...n.length===0?{badge:(0,h.jsx)(tk,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,"aria-keyshortcuts":w$,onKeyDown:g.onKeyDown(e),onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(z,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`}),(0,h.jsx)(Fxe,{member:e,index:t.indexOf(e),count:t.length,order:g})]})},e.id)})})]}),(0,h.jsx)(rz,{items:y,index:b,onIndex:x,onClose:()=>x(null),actions:(e,t)=>{let n=v[t];return n===void 0?null:(0,h.jsx)(z,{size:`small`,onClick:()=>{x(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(SR,{tone:`error`,className:`mt-2`,children:u?void 0:f.error?.message})]}),(0,h.jsx)(`aside`,{"aria-label":`Cast member editor`,className:`min-w-0`,children:E?(0,h.jsx)(Axe,{channelId:e,member:p,open:!0,onClose:()=>l(null),onCreated:e=>l(e)},c??`closed`):t.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Pick a member's Edit to change its names, description and pictures here.`})}),(0,h.jsx)(Qv,{open:u!==null,title:Ixe(u?.name),consequence:f.error?.message??Lxe,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var O$=e=>[`channels`,e,`episodes`],k$=e=>[`channels`,e,`videos`],A$=(e,t)=>`${e.origin}/api/channels/${t}`,j$=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function Hxe(e,t){return ot({queryKey:O$(t),queryFn:async()=>L(await e.fetch(`${A$(e,t)}/episodes`))})}async function Uxe(e,t,n){return L(await e.fetch(`${A$(e,t)}/episodes/setting`,j$(`PUT`,{enabled:n})))}async function Wxe(e,t,n,r){return L(await e.fetch(`${A$(e,t)}/episodes/${encodeURIComponent(n)}`,j$(`PUT`,{summary:r})))}async function Gxe(e,t,n){let r=await e.fetch(`${A$(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await L(r)}function M$(e,t){return ot({queryKey:k$(t),queryFn:async()=>(await L(await e.fetch(`${A$(e,t)}/videos`))).videos})}async function N$(e,t,n){return L(await e.fetch(`${A$(e,t)}/videos`,j$(`POST`,n)))}async function Kxe(e,t,n){return L(await e.fetch(`${A$(e,t)}/videos/preview`,j$(`POST`,{format:`csv`,text:n})))}async function qxe(e,t,n){let r=await e.fetch(`${A$(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await L(r)}async function Jxe(e,t){await L(await e.fetch(`${A$(e,t)}/videos`,{method:`DELETE`}))}function Yxe(e,t){let n=t.trim().toLowerCase().split(/\s+/u).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=[e.title,e.summary,...e.cast].join(` `).toLowerCase();return n.every(e=>t.includes(e))})}var Xxe=e=>e.length>160?`${e.slice(0,160)}…`:e;function Zxe({channelId:e}){let{api:t}=B(),n=_(),r=F(Hxe(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:O$(e)}),l=I({mutationFn:n=>Uxe(t,e,n),onSuccess:t=>n.setQueryData(O$(e),t)}),u=I({mutationFn:n=>Gxe(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[],[p,g]=(0,m.useState)(``),v=Yxe(f,p);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(Py,{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)(SR,{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)(aQ,{title:`No episodes remembered yet`,children:d?`When a video on this channel finishes, its summary appears here.`:`Turn on episode memory, and the next finished video's summary appears here.`}):null,f.length>0?(0,h.jsxs)(`div`,{className:`mt-2 mb-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search episode summaries`,placeholder:`Search episode summaries`,value:p,className:`w-full min-w-0 sm:w-64`,onChange:e=>g(e.target.value)}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:p.trim()===``?`${String(f.length)} ${f.length===1?`episode`:`episodes`}`:`${String(v.length)} of ${String(f.length)} match`})]}):null,f.length>0&&v.length===0?(0,h.jsx)(aQ,{title:`No episode matches`,children:`No title, cast member or summary contains “${p.trim()}”. Clear the search to see every episode.`}):null,v.length>0?(0,h.jsx)(KL,{label:`Episode summaries`,children:v.map(e=>(0,h.jsx)(qL,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,Xxe(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,"aria-label":`Delete the summary of ${e.title}`,onClick:()=>{u.reset(),s(e)},children:`Delete`})]})},e.id))}):null,i?(0,h.jsx)(Qxe,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(Qv,{open:o!==null,title:Rxe(o?.title),consequence:u.error?.message??zxe,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function Qxe({channelId:e,memory:t,onClose:n}){let{api:r}=B(),i=_(),[a,o]=(0,m.useState)(t.summary),s=I({mutationFn:()=>Wxe(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:O$(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Zv,{open:!0,onOpenChange:e=>{e||n()},title:t.title,description:t.source===`edited`?`You edited this summary; finishing the video again keeps your text.`:`Written by the text model when the video finished. An edit here is kept.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{onClick:n,children:`Close`}),(0,h.jsx)(z,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(iL,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(oL,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}function P$(e,t){let[n,r]=(0,m.useState)({limit:200,resetOn:t}),i=Object.is(n.resetOn,t)?n.limit:200;return Object.is(n.resetOn,t)||r({limit:200,resetOn:t}),{shown:e.length>i?e.slice(0,i):e,hidden:Math.max(0,e.length-i),more:()=>r({limit:i+200,resetOn:t})}}function F$({hidden:e,onMore:t}){return e===0?null:(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(z,{size:`small`,onClick:t,children:`Show ${Math.min(e,200).toLocaleString(`en`)} more`}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`${e.toLocaleString(`en`)} not shown`})]})}var I$=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function L$(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function $xe(e,t,n,r){let i=t===void 0?n:Math.min(t,n),a=t===void 0?n:Math.max(t,n);return e.map((e,t)=>t>=i&&t<=a?r:e)}function eSe({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=(0,m.useRef)(void 0),l=(0,m.useRef)(!1),u=e.ticked.filter(Boolean).length,d=P$(e.titles,e.titles);return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...Ny,children:[(0,h.jsxs)(U,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${u.toLocaleString(`en`)} of ${I$(e.titles.length,`title`,`titles`)} ticked · Shift+click ticks a range`,children:[(0,h.jsxs)(z,{variant:`primary`,disabled:n||u===0,onClick:a,children:[`Add `,I$(u,`ticked title`,`ticked titles`)]}),(0,h.jsx)(z,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(iL,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(X,{value:t,maxLength:200,onChange:e=>r(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(z,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(z,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(KL,{label:`Titles in the CSV`,className:`mt-2`,children:d.shown.map((t,r)=>(0,h.jsx)(qL,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onClick:e=>{l.current=e.shiftKey},onChange:t=>{let n=l.current?c.current:void 0;l.current=!1,c.current=r,i($xe(e.ticked,n,r,t.target.checked))}}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))}),(0,h.jsx)(F$,{hidden:d.hidden,onMore:d.more})]})}var R$=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function tSe({channelId:e}){let{api:t}=B(),n=_(),r=F(M$(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:k$(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=I({mutationFn:n=>N$(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${R$(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=I({mutationFn:n=>Kxe(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:L$(e.titles,e.filter)})}}),x=Iv(),S=I({mutationFn:n=>qxe(t,e,n.id),onSuccess:async(e,t)=>{x(`Removed “${t.title}”.`,`info`,{label:`Undo`,run:()=>C.mutate(t.title)}),await d()}}),C=I({mutationFn:n=>N$(t,e,{format:`lines`,text:n}),onSuccess:d,onError:(e,t)=>x(`Couldn't put “${t}” back: ${e.message} Paste it into Paste titles and press Add titles.`,`error`)}),[w,T]=(0,m.useState)(``),E=I({mutationFn:()=>Jxe(t,e),onSuccess:async()=>{s(!1),await d()}}),D=r.data??[],O=w.trim().toLowerCase(),k=O===``?D:D.filter(e=>e.title.toLowerCase().includes(O)),A=P$(k,O),j=y.isPending||b.isPending||S.isPending||C.isPending||E.isPending,M=r.error??b.error??y.error??S.error;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`Topic suggestions and duplicate checks skip these titles, as they skip the videos made here.`}),(0,h.jsx)(iL,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(oL,{rows:5,value:i,onChange:e=>a(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(z,{variant:`primary`,disabled:j||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(z,{disabled:j,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(H,{id:`planning.channel.videos-csv`}),(0,h.jsx)(`input`,{ref:u,type:`file`,accept:`.csv,text/csv`,className:`hidden`,"aria-label":`YouTube Studio CSV file`,onChange:async e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&(l(void 0),y.reset(),b.mutate(await t.text()))}}),(0,h.jsx)(z,{variant:`quiet`,disabled:j||D.length===0,onClick:()=>{E.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(SR,{tone:M?`error`:c?`success`:`info`,className:`mt-1`,children:M?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(eSe,{preview:f,filter:g,busy:j,onFilter:e=>{v(e),p({...f,ticked:L$(f.titles,e)})},onTick:e=>p({...f,ticked:e}),onSave:()=>{l(void 0);let e=f.titles.filter((e,t)=>f.ticked[t]);y.mutate({text:e.join(`
|
|
274
|
-
`),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&D.length===0?(0,h.jsx)(aQ,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,D.length>0?(0,h.jsxs)(`section`,{"aria-label":`Existing videos`,className:`mt-4`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search existing videos`,placeholder:`Search existing videos`,value:w,className:`w-full min-w-0 sm:w-64`,onChange:e=>T(e.target.value)}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:O===``?R$(D.length,`title`,`titles`):`${k.length.toLocaleString(`en`)} of ${R$(D.length,`title`,`titles`)} match`})]}),k.length===0?(0,h.jsx)(aQ,{title:`No title matches`,children:`None of the titles contains “${w.trim()}”. Clear the search to see them all.`}):(0,h.jsx)(KL,{label:`Existing videos`,children:A.shown.map(e=>(0,h.jsx)(qL,{title:e.title,actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:j,"aria-label":`Remove ${e.title}`,onClick:()=>S.mutate(e),children:`Remove`})},e.id))}),(0,h.jsx)(F$,{hidden:A.hidden,onMore:A.more})]}):null,(0,h.jsx)(Qv,{open:o,title:`Remove all ${R$(D.length,`title`,`titles`)}?`,consequence:E.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,cancelLabel:`Keep them`,pending:E.isPending,onConfirm:()=>E.mutate(),onCancel:()=>s(!1)})]})}function z$({className:e,children:t}){return(0,h.jsx)(`dl`,{className:R(`sl-stats m-0`,e),children:t})}function B$({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 V$({value:e,label:t,valueText:n,tone:r=`accent`,progress:i=!1,className:a}){let o=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100),s=n??`${String(o)}%`,c=R(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,a),l=(0,h.jsx)(`span`,{style:{width:`${String(o)}%`}});return i?(0,h.jsx)(`div`,{role:`progressbar`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l}):(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l})}function H$({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:R(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}var U$=56,W$=12,G$=12,nSe=28;function rSe(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=5?5:10)*r}function K$({series:e,xLabels:t,formatValue:n,label:r,height:i=260,legend:a=!0,className:o}){let s=(0,m.useRef)(null),[c,l]=(0,m.useState)(800),[u,d]=(0,m.useState)();(0,m.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([e])=>{e!==void 0&&l(Math.max(320,Math.round(e.contentRect.width)))});return t.observe(e),()=>t.disconnect()},[]);let f=t.length,p=Math.max(0,...e.flatMap(e=>e.values.filter(e=>e!==null))),g=rSe(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-U$-W$,y=e=>U$+(f<=1?0:e/(f-1)*v),b=e=>G$+i-e/_*i,x=Array.from({length:Math.round(_/g)+1},(e,t)=>t*g),S=Math.min(f,Math.max(2,Math.floor(v/90))),C=Array.from({length:S},(e,t)=>Math.round(t/Math.max(1,S-1)*(f-1))),w=e=>{let t=``,n=!1;return e.forEach((e,r)=>{if(e===null){n=!1;return}t+=`${n?`L`:`M`}${y(r).toFixed(1)},${b(e).toFixed(1)}`,n=!0}),t},T=G$+i+nSe,E=u===void 0?[]:e.map(e=>({one:e,value:e.values[u]??null})).filter(e=>e.value!==null).toSorted((e,t)=>t.value-e.value);return(0,h.jsxs)(`figure`,{className:R(`m-0 flex flex-col gap-2`,o),children:[(0,h.jsxs)(`div`,{ref:s,className:`relative w-full`,children:[(0,h.jsxs)(`svg`,{role:`img`,"aria-label":r,width:c,height:T,viewBox:`0 0 ${String(c)} ${String(T)}`,className:`block select-none`,onMouseLeave:()=>d(void 0),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=Math.round((e.clientX-t.left-U$)/v*(f-1));d(n<0||n>=f?void 0:n)},children:[x.map(e=>(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:U$,x2:c-W$,y1:b(e),y2:b(e),stroke:`currentColor`,className:`text-line`,strokeWidth:`1`}),(0,h.jsx)(`text`,{x:48,y:b(e),textAnchor:`end`,dominantBaseline:`middle`,className:`fill-ink-3 text-[11px]`,children:n(e)})]},e)),C.map(e=>(0,h.jsx)(`text`,{x:y(e),y:G$+i+18,textAnchor:e===0?`start`:e===f-1?`end`:`middle`,className:`fill-ink-3 text-[11px]`,children:t[e]},e)),e.map(e=>(0,h.jsx)(`path`,{d:w(e.values),fill:`none`,stroke:e.color,strokeWidth:`1.75`,strokeLinejoin:`round`},e.id)),u===void 0?null:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:y(u),x2:y(u),y1:G$,y2:G$+i,stroke:`currentColor`,className:`text-ink-3`,strokeDasharray:`3 3`}),E.map(({one:e,value:t})=>(0,h.jsx)(`circle`,{cx:y(u),cy:b(t),r:`3.5`,fill:e.color},e.id))]})]}),u===void 0||E.length===0?null:(0,h.jsxs)(`div`,{className:`pointer-events-none absolute top-2 z-10 w-[340px] rounded-control border border-line bg-surface p-2 text-small shadow-md`,style:y(u)>c/2?{right:c-y(u)+12}:{left:y(u)+12},children:[(0,h.jsx)(`div`,{className:`mb-1 font-semibold`,children:t[u]}),E.map(({one:e,value:t})=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 shrink-0 rounded-full`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),(0,h.jsx)(`span`,{className:`tabular-nums`,children:n(t)})]},e.id))]})]}),a?(0,h.jsx)(`figcaption`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-small text-ink-2`,children:e.map(e=>(0,h.jsxs)(`span`,{className:`flex max-w-[320px] items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-[3px] w-4 shrink-0 rounded`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))}):null]})}var q$=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function iSe(e,t){return L(await e.fetch(q$(e,t)))}async function aSe(e,t,n){return L(await e.fetch(q$(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}async function oSe(e,t,n){return L(await e.fetch(`${e.origin}/api/studio/channels/${t}/export-view`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:n})}))}function sSe({channelId:e,saved:t}){let{api:n}=B(),r=_(),i=Iv(),[a,o]=(0,m.useState)(),s=a??t??``,c=I({mutationFn:t=>oSe(n,e,t),onSuccess:t=>{r.setQueryData([`studio`,`report`,e],t),o(void 0),i(t.exportView?`The extension exports this view every day.`:`The extension no longer exports a view for this channel.`,`success`)},onError:e=>i(`The view wasn't saved: ${e.message}`,`error`)});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(X,{"aria-label":`Studio Analytics view to export every day`,placeholder:`https://studio.youtube.com/channel/…/analytics/…/explore?…`,className:`min-w-0 flex-1 basis-[320px]`,value:s,onChange:e=>o(e.currentTarget.value)}),(0,h.jsx)(z,{type:`button`,disabled:c.isPending||s.trim()===(t??``),onClick:()=>c.mutate(s.trim()===``?null:s.trim()),children:`Save view`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The Studio extension opens this view once a day, exports it and brings it in here: every column, and each video's numbers on its project. Paste the address of Analytics → Advanced mode as you set it up; the start date stays, the end moves to today.`})]})}function J$(e,t,n){if(e===null)return`–`;if(typeof e==`string`)return e;if(t===`duration`){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=String(Math.round(e%60)).padStart(2,`0`);return t>0?`${String(t)}:${String(n).padStart(2,`0`)}:${r}`:`${String(n)}:${r}`}let r=/%|\(|rpm|revenue|hours/i.test(n)&&!Number.isInteger(e)?1:0;return e.toLocaleString(`en`,{minimumFractionDigits:r,maximumFractionDigits:r})}var Y$=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],X$=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),Z$=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function Q$(e,t){if(t===`total`){let t=0;return e.map(e=>t+=e)}return t===`average`?e.map((t,n)=>{let r=e.slice(Math.max(0,n-6),n+1);return r.reduce((e,t)=>e+t,0)/r.length}):[...e]}function cSe({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,[d,f]=(0,m.useState)(!1),p=t.filter(e=>n.includes(e.videoId)),g=e.from===null?new Date:new Date(`${e.from}T00:00:00`),_=Math.max(0,...t.map(e=>e.daily.length)),v,y;if(o===`dates`){let t=c===`all`?0:Math.max(0,_-Number(c)),n=_-t>200;v=Array.from({length:_-t},(e,r)=>{let i=new Date(g);return i.setDate(i.getDate()+t+r),(n?Z$:X$).format(i)}),y=p.map(e=>{let n=e.daily.findIndex(e=>e>0),a=Q$(e.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:e.videoId,label:e.title,color:r(e.videoId),values:a.slice(t)}}),d&&e.dailyTotals!==void 0&&(y=[{id:`channel-total`,label:`Channel total`,color:`var(--color-ink-2)`,values:Q$(e.dailyTotals,i).slice(t)},...y])}else{let e=Math.max(1,...p.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));v=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),y=p.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=Q$(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let b=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:b}),(0,h.jsx)(`span`,{className:`flex-1`}),e.dailyTotals===void 0||o!==`dates`?null:(0,h.jsxs)(`label`,{className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.currentTarget.checked)}),`Channel total`]}),(0,h.jsx)(sL,{"aria-label":`Show`,className:`w-[200px]`,value:i,onChange:e=>a(e.currentTarget.value),options:[{value:`average`,label:`7-day average`},{value:`daily`,label:`Per day`},{value:`total`,label:`Running total`}]}),(0,h.jsx)(sL,{"aria-label":`Timeline`,className:`w-[220px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:`dates`,label:`By date`},{value:`since`,label:`Days since release`}]}),(0,h.jsx)(sL,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),p.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(K$,{series:y,xLabels:v,label:`${b} for ${String(p.length)} videos`,formatValue:$$})]})}var $$=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function lSe({report:e,row:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`),s=t.daily.findIndex(e=>e>0);if(s<0)return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart this one, tick it in Advanced mode's chart before you export.`});let c=Q$(t.daily.slice(s),n),l=r===`all`?0:Math.max(0,c.length-Number(r)),u=c.slice(l),d=u.map((e,t)=>{let n=new Date(o);return n.setDate(n.getDate()+s+l+t),(u.length>200?Z$:X$).format(n)}),f=t.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`${a} · ${f.toLocaleString(`en`)} total`}),(0,h.jsx)(K$,{height:180,legend:!1,label:`${a} for ${t.title}`,xLabels:d,formatValue:$$,series:[{id:t.videoId,label:t.title,color:i(t.videoId),values:u}]})]})}var e1=e=>`slopify.studioReport.hidden.${e}`;function uSe(e){try{let t=window.localStorage.getItem(e1(e));return t===null?void 0:JSON.parse(t)}catch{return}}function t1({channelId:e}){let{api:t}=B(),n=_(),r=Iv(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=F({queryKey:a,queryFn:()=>iSe(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(()=>uSe(e)),w=I({mutationFn:n=>aSe(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),T=o.data?.report??null,E=T?.columns??[],D=E.filter((e,t)=>(T?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),O=S??D,k=t=>{C(t);try{window.localStorage.setItem(e1(e),JSON.stringify(t))}catch{}},A=E.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!O.includes(e.label)),j=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},M=[...T?.rows??[]].toSorted((e,t)=>j(t,s)-j(e,s)),ee=[...T?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),N=l??ee.slice(0,5).map(e=>e.videoId),te=e=>{let t=(T?.rows??[]).findIndex(t=>t.videoId===e);return Y$[(t<0?0:t)%Y$.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(U,{as:`h3`,title:`From Studio's export`,meta:T===null?void 0:`${String(T.rows.length)} videos · ${T.from??`?`} to ${T.to??`?`} · imported ${new Date(T.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&w.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(z,{type:`button`,variant:`secondary`,disabled:w.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,strokeWidth:1.75}),w.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),(0,h.jsx)(sSe,{channelId:e,saved:o.data?.exportView??null}),T===null?null:(0,h.jsxs)(h.Fragment,{children:[T.chartMetric===null?null:(0,h.jsx)(cSe,{report:T,rows:M,picked:N,colorOf:te,shape:d,setShape:f,timeline:p,setTimeline:g,range:v,setRange:y}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(sL,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:E.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(A.length),` of `,String(E.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:E.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!O.includes(e.label),onChange:t=>k(t.currentTarget.checked?O.filter(t=>t!==e.label):[...O,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),A.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),A.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:J$(T.totals[t]??null,e.kind,e.label)},e.label))]}),M.map(e=>{let t=o.data?.projects[e.videoId],n=b===e.videoId;return(0,h.jsxs)(m.Fragment,{children:[(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:N.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...N,e.videoId]:N.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:N.includes(e.videoId)?te(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[T.chartMetric===null?null:(0,h.jsx)(Mv,{size:`small`,"aria-expanded":n,label:`${n?`Hide`:`Show`} the chart of ${e.title}`,onClick:()=>x(n?void 0:e.videoId),children:n?(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})}),t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title})]}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),A.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:J$(e.values[n]??null,t.kind,t.label)},t.label))]}),n?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:A.length+2,children:(0,h.jsx)(lSe,{report:T,row:e,shape:d,range:v,colorOf:te})})}):null]},e.videoId)})]})]})})]})]})}var n1=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),r1=e=>e==null?`–`:`${e.toFixed(1)}%`;function i1(e){if(e==null)return`–`;let t=Math.round(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}var dSe=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),a1=e=>e===null?`–`:dSe.format(new Date(e));function o1({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(z$,{children:[(0,h.jsx)(B$,{value:n1(t.views),label:`Views`}),(0,h.jsx)(B$,{value:n1(t.impressions),label:`Impressions`}),(0,h.jsx)(B$,{value:r1(t.ctr),label:`Click-through rate`}),(0,h.jsx)(B$,{value:i1(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(B$,{value:n1(t.watchHours),label:`Watch hours`})]})]})}var s1=(e,t)=>{let n=e.long?.stats??null;return t===`views`?(n?.views??0)+e.shorts.reduce((e,t)=>e+(t.stats?.views??0),0):t===`ctr`?n?.ctr??-1:t===`duration`?n?.averageViewSeconds??-1:Date.parse(e.long?.releasedAt??e.shorts[0]?.releasedAt??``)||0};function fSe({channelId:e}){let{api:t}=B(),[n,r]=(0,m.useState)(`newest`),i=F({queryKey:[`studio`,`performance`,e],queryFn:()=>ys(t,e)});if(i.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the numbers…`});if(i.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The numbers didn't load: `,i.error.message,` Reload the page to try again.`]});let a=i.data;if(a.projects.length===0)return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(t1,{channelId:e}),(0,h.jsx)(aQ,{title:`No video of this channel is known on YouTube yet`,children:`Upload with the Slopify Studio extension, or open YouTube Studio's Content list once so the extension links your videos. Their numbers then arrive daily, or at once with Read Studio numbers now in the extension's popup.`})]});let o=a.projects.toSorted((e,t)=>s1(t,n)-s1(e,n)).flatMap(e=>[...e.long===null?[]:[{key:`${e.projectId}-0`,projectId:e.projectId,row:e.long,isShort:!1}],...e.shorts.map(t=>({key:`${e.projectId}-${String(t.short??0)}`,projectId:e.projectId,row:t,isShort:!0}))]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Studio's numbers as the Slopify Studio extension last read them`,a.readAt===null?``:` (newest ${a1(a.readAt)})`,`: daily while Chrome is open, or at once with Read Studio numbers now in the extension's popup. "–" is a number Studio doesn't show for that video (most shorts have no click-through rate).`]}),(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,h.jsx)(o1,{label:`Long videos`,totals:a.long}),(0,h.jsx)(o1,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(t1,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:`Every video`,children:(0,h.jsx)(sL,{"aria-label":`Order`,value:n,onChange:e=>r(e.currentTarget.value),options:[{value:`newest`,label:`Newest first`},{value:`views`,label:`Most views`},{value:`ctr`,label:`Best click-through rate`},{value:`duration`,label:`Longest average view`}]})}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(H$,{columns:[{id:`title`,header:`Video`,cell:e=>e.isShort?(0,h.jsx)(`span`,{className:`block pl-5 text-small text-ink-2`,children:`Short ${String(e.row.short??``)} · ${e.row.title}`}):(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>a1(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>n1(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>r1(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>n1(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>i1(e.row.stats?.averageViewSeconds)},{id:`hours`,header:`Watch hours`,numeric:!0,cell:e=>e.row.stats?.watchHours===null||e.row.stats?.watchHours===void 0?`–`:e.row.stats.watchHours.toFixed(1)}],rows:o,rowKey:e=>e.key,caption:`The channel's videos and shorts with Studio's numbers`})})]})]})}var c1=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],l1={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function pSe(e){return c1.find(t=>t===e)??`brand`}function mSe({channelId:e,tab:t,onTab:n}){let{api:r}=B(),i=_(),a=Yi(),o=F(Xy(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=I({mutationFn:()=>Qy(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:Gy}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[];Uv(f===void 0?void 0:`${f.name} · ${l1[t]}`);let g=()=>{n(`cast`),u(`new`)};return sb({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),o.error!==null&&o.data===void 0?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(fG,{crumb:(0,h.jsx)(pa,{to:`/channels`,children:`Channels`}),title:`Channel not opened`}),(0,h.jsx)(aQ,{title:`This channel could not be opened`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(WO,{to:`/channels`,variant:`primary`,children:`Open Channels`}),(0,h.jsx)(z,{disabled:o.isFetching,disabledReason:`Trying again…`,onClick:()=>void o.refetch(),children:`Try again`})]}),children:`${o.error.message} A deleted channel is gone for good (its videos moved to the default channel). Pick a channel from Channels, or press Try again.`})]}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(fG,{crumb:(0,h.jsx)(pa,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(z,{variant:`primary`,onClick:g,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(z,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(rQ,{items:c1.map(e=>({id:e,label:l1[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(SR,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be read again: ${o.error.message} What is shown may be out of date; reload the page to try again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(iQ,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(pxe,{channel:f}),(0,h.jsx)(wxe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(Vxe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(cbe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(lbe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Zxe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(tSe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(fSe,{channelId:f.id}):null})]}):null,(0,h.jsx)(Qv,{open:s,title:E$(f?.name),consequence:d.error?.message??D$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function hSe(){let{api:e}=B(),t=_(),n=Yi(),r=F(Yy(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=I({mutationFn:()=>hre(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:Gy}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=I({mutationFn:t=>Zy(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:Gy}),a(null)}}),v=I({mutationFn:t=>Qy(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:Gy})}}),y=()=>{p.reset(),l(``),a(`new`)};sb({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)(fG,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(H,{id:`planning.channels`})]}),actions:(0,h.jsxs)(z,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(SR,{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)(aQ,{title:`No channels yet`,actions:(0,h.jsx)(z,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(hG,{list:(0,h.jsx)(KL,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(qL,{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)(GO,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(gSe,{channel:f})}):null,(0,h.jsx)(Zv,{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)(SR,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(z,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(z,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(iL,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(X,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Qv,{open:o!==null,title:E$(o?.name),consequence:v.error?.message??D$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function gSe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`PDF theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(U,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(WO,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(z$,{className:`mb-6`,children:[(0,h.jsx)(B$,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(B$,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(U,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(U,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var u1=2e3;function d1(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()},u1);return()=>{clearTimeout(t)}},[e])}function f1(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function p1({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Iv();sb({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:ck.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(z,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(SR,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(f1,{}):t)}),a,(0,h.jsx)(z,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":yb(ck.save),onClick:()=>{c||s()},children:`Save`})]})}var _Se=`rounded-media border border-line bg-surface p-4`;function m1(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${_Se} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var vSe=`modulepreload`,ySe=function(e){return`/`+e},h1={},g1=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=ySe(t,n),t=s(t),t in h1)return;h1[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:vSe,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function _1({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return bSe(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function bSe(e,t){let n=await g1(()=>import(`./pdf-DWBP2BjM.js`),[]),r=await g1(()=>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 v1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),y1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),b1=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),x1=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),S1=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),C1=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),w1=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),T1=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},v1([`page`,`margin`],`Margins`),v1([`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:[w1(`body`,`Body`),w1(`strong`,`Bold text`),w1(`emphasis`,`Italic text`),w1(`heading`,`Headings`),w1(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),w1(`decorative`,`Tagline and title-page link`),w1(`dropCap`,`Drop caps`),w1(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[y1([`sizes`,`title`],`Title`),y1([`sizes`,`brand`],`Brand`),y1([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),y1([`sizes`,`heading`],`Second-level headings`),y1([`sizes`,`subheading`],`Third-level headings`),y1([`sizes`,`body`],`Body`),y1([`sizes`,`meta`],`Date and word count`),y1([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[v1([`spacing`,`bodyLine`],`Body line height`),v1([`spacing`,`headingLine`],`Heading line height`),v1([`spacing`,`subheadingLine`],`Subheading line height`),b1([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),b1([`spacing`,`headingGap`],`Before a heading`,`× line`),b1([`spacing`,`itemGap`],`After a list item`,`× line`),v1([`spacing`,`listIndent`],`List indent`),v1([`spacing`,`quoteIndent`],`Quote indent`),v1([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[x1([`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`}]},b1([`dropCap`,`scale`],`Letter size`,`× lines`),v1([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},b1([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[v1([`titlePage`,`brandY`],`Brand from top`),v1([`titlePage`,`taglineOffset`],`Tagline below brand`),v1([`titlePage`,`titleY`],`Title from top`),v1([`titlePage`,`titleLine`],`Title line height`),v1([`titlePage`,`metaOffset`],`Details below title`),v1([`titlePage`,`metaLine`],`Details line height`),x1([`titlePage`,`showDate`],`Show the date`),x1([`titlePage`,`showWordCount`],`Show the word count`),x1([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),v1([`titlePage`,`cover`,`gap`],`Space around cover`),v1([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[C1([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),C1([`brand`,`tagline`],`Tagline`),C1([`brand`,`url`],`Website`,`Where the brand and its link go.`),C1([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[x1([`contents`,`enabled`],`Contents page`),S1([`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`}]},v1([`contents`,`titleOffset`],`Title from top margin`),v1([`contents`,`firstEntryOffset`],`First entry from top margin`),v1([`contents`,`line`],`Line height`),v1([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[x1([`header`,`enabled`],`Running header`,`The title at the top of each page.`),v1([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},x1([`footer`,`enabled`],`Page numbers`),S1([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),v1([`footer`,`bottom`],`From the bottom`),v1([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[x1([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),S1([`sources`,`title`],`Title`),v1([`sources`,`titleOffset`],`Title from top margin`),v1([`sources`,`bodyOffset`],`List from top margin`),v1([`sources`,`line`],`Line height`),v1([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[x1([`endPage`,`enabled`],`Closing page`),S1([`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.`},x1([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},C1([`endPage`,`closing`],`Closing line`),v1([`endPage`,`titleOffset`],`Title from top margin`),v1([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[S1([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),S1([`metadata`,`subject`],`Subject`),S1([`metadata`,`keywords`],`Keywords`),S1([`metadata`,`creator`],`Creator`)]}],E1=zD.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function D1(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 O1(e,t){let n=e;for(let e of t)n=n?.[e];return n}function k1(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:k1(a,i,n)}}function xSe(e){let t=KD;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function A1(e){return`values.${e.join(`.`)}`}var j1=`pt-1`,M1=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function N1({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Nc,{"aria-hidden":`true`}),e]})}function P1({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(dM,{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 F1(e){return`theme-group-${e.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`}function SSe({problems:e,changed:t}){return e===0&&t===0?null:(0,h.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 text-small font-normal`,children:[e===0?null:(0,h.jsx)(tk,{tone:`failed`,children:`${String(e)} to fix`}),t===0?null:(0,h.jsx)(tk,{children:`${String(t)} changed`})]})}function CSe({groups:e,onJump:t}){return(0,h.jsx)(`nav`,{"aria-label":`Theme groups`,className:`flex flex-wrap gap-1 border-t border-line pt-3`,children:e.map(e=>{let n=[e.problems===0?``:`${String(e.problems)} to fix`,e.changed===0?``:`${String(e.changed)} changed`].filter(e=>e!==``);return(0,h.jsx)(z,{variant:`quiet`,size:`small`,className:e.problems===0?void 0:`text-danger`,onClick:()=>t(e.title),children:n.length===0?e.title:`${e.title} · ${n.join(` · `)}`},e.title)})})}var wSe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function I1(e,t){let n=A1(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function TSe({field:e,theme:t,original:n,problem:r,onChange:i}){let a=(0,m.useId)(),o=O1(t,e.path),s=O1(n,e.path),c=R1(t,n,e.path),l=wSe[A1(e.path)],u=n=>{i(k1(t,e.path,n))},d=(0,h.jsxs)(h.Fragment,{children:[l===void 0?null:(0,h.jsx)(H,{id:l,label:e.label,className:`-my-1`}),c?(0,h.jsx)(Mv,{label:`Reset ${e.label} to ${z1(s)}`,tip:`Changed. Reset to ${z1(s)}`,className:`-my-1 size-6`,onClick:()=>u(s),children:(0,h.jsx)(gl,{"aria-hidden":`true`,className:`size-[13px]`})}):null]}),f=e.kind===`color`&&r===void 0?DSe(t,e.path):void 0,p=[e.help===void 0?``:`${a}-help`,r===void 0?``:`${a}-error`,f===void 0?``:`${a}-contrast`].filter(e=>e!==``).join(` `),g=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${a}-help`,className:`sl-field__help m-0`,children:e.help}),r===void 0?null:(0,h.jsx)(`p`,{id:`${a}-error`,className:`sl-field__error m-0`,children:r}),f===void 0?null:(0,h.jsx)(`p`,{id:`${a}-contrast`,className:`m-0 text-small text-waiting`,children:f})]}),_={id:a,"aria-invalid":r!==void 0,"aria-describedby":p===``?void 0:p};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ny,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{..._,type:`checkbox`,checked:o===!0,className:`size-4 accent-accent`,onChange:e=>{u(e.currentTarget.checked)}}),e.label]}),d]}),g]});case`number`:{let{min:t,max:n}=xSe(e.path);return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(X,{..._,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof o==`number`&&Number.isFinite(o)?o:``,onChange:e=>{u(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(l$,{..._,pickerLabel:`${e.label} colour`,value:typeof o==`string`?o:``,onChange:u})});case`text`:return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value)}})});case`optional-text`:return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===o);return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(sL,{..._,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&u(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=o,n=D1(t.family);return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(sL,{..._,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=E1.find(t=>t.value===e.target.value);if(n===void 0)return;let r=D1(n.value).some(e=>e.value===t.style);u({...t,family:n.value,style:r?t.style:`normal`})},children:E1.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(sL,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{u({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(X,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{u({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ny,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:a,className:`sl-field__label`,children:e.label}),d]}),(0,h.jsx)(oL,{..._,rows:8,value:Array.isArray(o)?o.join(`
|
|
274
|
+
`),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&D.length===0?(0,h.jsx)(aQ,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,D.length>0?(0,h.jsxs)(`section`,{"aria-label":`Existing videos`,className:`mt-4`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(X,{type:`search`,"aria-label":`Search existing videos`,placeholder:`Search existing videos`,value:w,className:`w-full min-w-0 sm:w-64`,onChange:e=>T(e.target.value)}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,role:`status`,children:O===``?R$(D.length,`title`,`titles`):`${k.length.toLocaleString(`en`)} of ${R$(D.length,`title`,`titles`)} match`})]}),k.length===0?(0,h.jsx)(aQ,{title:`No title matches`,children:`None of the titles contains “${w.trim()}”. Clear the search to see them all.`}):(0,h.jsx)(KL,{label:`Existing videos`,children:A.shown.map(e=>(0,h.jsx)(qL,{title:e.title,actions:(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:j,"aria-label":`Remove ${e.title}`,onClick:()=>S.mutate(e),children:`Remove`})},e.id))}),(0,h.jsx)(F$,{hidden:A.hidden,onMore:A.more})]}):null,(0,h.jsx)(Qv,{open:o,title:`Remove all ${R$(D.length,`title`,`titles`)}?`,consequence:E.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,cancelLabel:`Keep them`,pending:E.isPending,onConfirm:()=>E.mutate(),onCancel:()=>s(!1)})]})}function z$({className:e,children:t}){return(0,h.jsx)(`dl`,{className:R(`sl-stats m-0`,e),children:t})}function B$({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 V$({value:e,label:t,valueText:n,tone:r=`accent`,progress:i=!1,className:a}){let o=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100),s=n??`${String(o)}%`,c=R(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,a),l=(0,h.jsx)(`span`,{style:{width:`${String(o)}%`}});return i?(0,h.jsx)(`div`,{role:`progressbar`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l}):(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,"aria-valuetext":s,className:c,children:l})}function H$({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:R(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}var U$=56,W$=12,G$=12,nSe=28;function rSe(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=5?5:10)*r}function K$({series:e,xLabels:t,formatValue:n,label:r,height:i=260,legend:a=!0,className:o}){let s=(0,m.useRef)(null),[c,l]=(0,m.useState)(800),[u,d]=(0,m.useState)();(0,m.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([e])=>{e!==void 0&&l(Math.max(320,Math.round(e.contentRect.width)))});return t.observe(e),()=>t.disconnect()},[]);let f=t.length,p=Math.max(0,...e.flatMap(e=>e.values.filter(e=>e!==null))),g=rSe(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-U$-W$,y=e=>U$+(f<=1?0:e/(f-1)*v),b=e=>G$+i-e/_*i,x=Array.from({length:Math.round(_/g)+1},(e,t)=>t*g),S=Math.min(f,Math.max(2,Math.floor(v/90))),C=Array.from({length:S},(e,t)=>Math.round(t/Math.max(1,S-1)*(f-1))),w=e=>{let t=``,n=!1;return e.forEach((e,r)=>{if(e===null){n=!1;return}t+=`${n?`L`:`M`}${y(r).toFixed(1)},${b(e).toFixed(1)}`,n=!0}),t},T=G$+i+nSe,E=u===void 0?[]:e.map(e=>({one:e,value:e.values[u]??null})).filter(e=>e.value!==null).toSorted((e,t)=>t.value-e.value);return(0,h.jsxs)(`figure`,{className:R(`m-0 flex flex-col gap-2`,o),children:[(0,h.jsxs)(`div`,{ref:s,className:`relative w-full`,children:[(0,h.jsxs)(`svg`,{role:`img`,"aria-label":r,width:c,height:T,viewBox:`0 0 ${String(c)} ${String(T)}`,className:`block select-none`,onMouseLeave:()=>d(void 0),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=Math.round((e.clientX-t.left-U$)/v*(f-1));d(n<0||n>=f?void 0:n)},children:[x.map(e=>(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:U$,x2:c-W$,y1:b(e),y2:b(e),stroke:`currentColor`,className:`text-line`,strokeWidth:`1`}),(0,h.jsx)(`text`,{x:48,y:b(e),textAnchor:`end`,dominantBaseline:`middle`,className:`fill-ink-3 text-[11px]`,children:n(e)})]},e)),C.map(e=>(0,h.jsx)(`text`,{x:y(e),y:G$+i+18,textAnchor:e===0?`start`:e===f-1?`end`:`middle`,className:`fill-ink-3 text-[11px]`,children:t[e]},e)),e.map(e=>(0,h.jsx)(`path`,{d:w(e.values),fill:`none`,stroke:e.color,strokeWidth:`1.75`,strokeLinejoin:`round`},e.id)),u===void 0?null:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:y(u),x2:y(u),y1:G$,y2:G$+i,stroke:`currentColor`,className:`text-ink-3`,strokeDasharray:`3 3`}),E.map(({one:e,value:t})=>(0,h.jsx)(`circle`,{cx:y(u),cy:b(t),r:`3.5`,fill:e.color},e.id))]})]}),u===void 0||E.length===0?null:(0,h.jsxs)(`div`,{className:`pointer-events-none absolute top-2 z-10 w-[340px] rounded-control border border-line bg-surface p-2 text-small shadow-md`,style:y(u)>c/2?{right:c-y(u)+12}:{left:y(u)+12},children:[(0,h.jsx)(`div`,{className:`mb-1 font-semibold`,children:t[u]}),E.map(({one:e,value:t})=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 shrink-0 rounded-full`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),(0,h.jsx)(`span`,{className:`tabular-nums`,children:n(t)})]},e.id))]})]}),a?(0,h.jsx)(`figcaption`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-small text-ink-2`,children:e.map(e=>(0,h.jsxs)(`span`,{className:`flex max-w-[320px] items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-[3px] w-4 shrink-0 rounded`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))}):null]})}var q$=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function iSe(e,t){return L(await e.fetch(q$(e,t)))}async function aSe(e,t,n){return L(await e.fetch(q$(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}async function oSe(e,t,n){return L(await e.fetch(`${e.origin}/api/studio/channels/${t}/export-view`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:n})}))}function sSe({channelId:e,saved:t}){let{api:n}=B(),r=_(),i=Iv(),[a,o]=(0,m.useState)(),s=a??t??``,c=I({mutationFn:t=>oSe(n,e,t),onSuccess:t=>{r.setQueryData([`studio`,`report`,e],t),o(void 0),i(t.exportView?`The extension exports this view every day.`:`The extension no longer exports a view for this channel.`,`success`)},onError:e=>i(`The view wasn't saved: ${e.message}`,`error`)});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(X,{"aria-label":`Studio Analytics view to export every day`,placeholder:`https://studio.youtube.com/channel/…/analytics/…/explore?…`,className:`min-w-0 flex-1 basis-[320px]`,value:s,onChange:e=>o(e.currentTarget.value)}),(0,h.jsx)(z,{type:`button`,disabled:c.isPending||s.trim()===(t??``),onClick:()=>c.mutate(s.trim()===``?null:s.trim()),children:`Save view`})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The Studio extension opens this view once a day, exports it and brings it in here: every column, and each video's numbers on its project. Paste the address of Analytics → Advanced mode as you set it up; the start date stays, the end moves to today.`})]})}function J$(e,t,n){if(e===null)return`–`;if(typeof e==`string`)return e;if(t===`duration`){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=String(Math.round(e%60)).padStart(2,`0`);return t>0?`${String(t)}:${String(n).padStart(2,`0`)}:${r}`:`${String(n)}:${r}`}let r=/%|\(|rpm|revenue|hours/i.test(n)&&!Number.isInteger(e)?1:0;return e.toLocaleString(`en`,{minimumFractionDigits:r,maximumFractionDigits:r})}var Y$=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],X$=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),Z$=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function Q$(e,t){if(t===`total`){let t=0;return e.map(e=>t+=e)}return t===`average`?e.map((t,n)=>{let r=e.slice(Math.max(0,n-6),n+1);return r.reduce((e,t)=>e+t,0)/r.length}):[...e]}function cSe({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,[d,f]=(0,m.useState)(!1),p=t.filter(e=>n.includes(e.videoId)),g=e.from===null?new Date:new Date(`${e.from}T00:00:00`),_=Math.max(0,...t.map(e=>e.daily.length)),v,y;if(o===`dates`){let t=c===`all`?0:Math.max(0,_-Number(c)),n=_-t>200;v=Array.from({length:_-t},(e,r)=>{let i=new Date(g);return i.setDate(i.getDate()+t+r),(n?Z$:X$).format(i)}),y=p.map(e=>{let n=e.daily.findIndex(e=>e>0),a=Q$(e.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:e.videoId,label:e.title,color:r(e.videoId),values:a.slice(t)}}),d&&e.dailyTotals!==void 0&&(y=[{id:`channel-total`,label:`Channel total`,color:`var(--color-ink-2)`,values:Q$(e.dailyTotals,i).slice(t)},...y])}else{let e=Math.max(1,...p.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));v=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),y=p.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=Q$(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let b=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:b}),(0,h.jsx)(`span`,{className:`flex-1`}),e.dailyTotals===void 0||o!==`dates`?null:(0,h.jsxs)(`label`,{className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.currentTarget.checked)}),`Channel total`]}),(0,h.jsx)(sL,{"aria-label":`Show`,className:`w-[200px]`,value:i,onChange:e=>a(e.currentTarget.value),options:[{value:`average`,label:`7-day average`},{value:`daily`,label:`Per day`},{value:`total`,label:`Running total`}]}),(0,h.jsx)(sL,{"aria-label":`Timeline`,className:`w-[220px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:`dates`,label:`By date`},{value:`since`,label:`Days since release`}]}),(0,h.jsx)(sL,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),p.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(K$,{series:y,xLabels:v,label:`${b} for ${String(p.length)} videos`,formatValue:$$})]})}var $$=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function lSe({report:e,row:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`),s=t.daily.findIndex(e=>e>0);if(s<0)return(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart this one, tick it in Advanced mode's chart before you export.`});let c=Q$(t.daily.slice(s),n),l=r===`all`?0:Math.max(0,c.length-Number(r)),u=c.slice(l),d=u.map((e,t)=>{let n=new Date(o);return n.setDate(n.getDate()+s+l+t),(u.length>200?Z$:X$).format(n)}),f=t.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`${a} · ${f.toLocaleString(`en`)} total`}),(0,h.jsx)(K$,{height:180,legend:!1,label:`${a} for ${t.title}`,xLabels:d,formatValue:$$,series:[{id:t.videoId,label:t.title,color:i(t.videoId),values:u}]})]})}var e1=e=>`slopify.studioReport.hidden.${e}`;function uSe(e){try{let t=window.localStorage.getItem(e1(e));return t===null?void 0:JSON.parse(t)}catch{return}}function t1({channelId:e}){let{api:t}=B(),n=_(),r=Iv(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=F({queryKey:a,queryFn:()=>iSe(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(),[S,C]=(0,m.useState)(()=>uSe(e)),w=I({mutationFn:n=>aSe(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),T=o.data?.report??null,E=T?.columns??[],D=E.filter((e,t)=>(T?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),O=S??D,k=t=>{C(t);try{window.localStorage.setItem(e1(e),JSON.stringify(t))}catch{}},A=E.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!O.includes(e.label)),j=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},M=[...T?.rows??[]].toSorted((e,t)=>j(t,s)-j(e,s)),ee=[...T?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),N=l??ee.slice(0,5).map(e=>e.videoId),te=e=>{let t=(T?.rows??[]).findIndex(t=>t.videoId===e);return Y$[(t<0?0:t)%Y$.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(U,{as:`h3`,title:`From Studio's export`,meta:T===null?void 0:`${String(T.rows.length)} videos · ${T.from??`?`} to ${T.to??`?`} · imported ${new Date(T.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&w.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(z,{type:`button`,variant:`secondary`,disabled:w.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,strokeWidth:1.75}),w.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),(0,h.jsx)(sSe,{channelId:e,saved:o.data?.exportView??null}),T===null?null:(0,h.jsxs)(h.Fragment,{children:[T.chartMetric===null?null:(0,h.jsx)(cSe,{report:T,rows:M,picked:N,colorOf:te,shape:d,setShape:f,timeline:p,setTimeline:g,range:v,setRange:y}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(sL,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:E.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(A.length),` of `,String(E.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:E.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!O.includes(e.label),onChange:t=>k(t.currentTarget.checked?O.filter(t=>t!==e.label):[...O,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),A.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),A.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:J$(T.totals[t]??null,e.kind,e.label)},e.label))]}),M.map(e=>{let t=o.data?.projects[e.videoId],n=b===e.videoId;return(0,h.jsxs)(m.Fragment,{children:[(0,h.jsxs)(`tr`,{children:[T.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:N.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...N,e.videoId]:N.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:N.includes(e.videoId)?te(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[T.chartMetric===null?null:(0,h.jsx)(Mv,{size:`small`,"aria-expanded":n,label:`${n?`Hide`:`Show`} the chart of ${e.title}`,onClick:()=>x(n?void 0:e.videoId),children:n?(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Nc,{"aria-hidden":`true`,strokeWidth:1.75})}),t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title})]}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),A.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:J$(e.values[n]??null,t.kind,t.label)},t.label))]}),n?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:A.length+2,children:(0,h.jsx)(lSe,{report:T,row:e,shape:d,range:v,colorOf:te})})}):null]},e.videoId)})]})]})})]})]})}var n1=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),r1=e=>e==null?`–`:`${e.toFixed(1)}%`;function i1(e){if(e==null)return`–`;let t=Math.round(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}var dSe=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),a1=e=>e===null?`–`:dSe.format(new Date(e));function o1({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(z$,{children:[(0,h.jsx)(B$,{value:n1(t.views),label:`Views`}),(0,h.jsx)(B$,{value:n1(t.impressions),label:`Impressions`}),(0,h.jsx)(B$,{value:r1(t.ctr),label:`Click-through rate`}),(0,h.jsx)(B$,{value:i1(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(B$,{value:n1(t.watchHours),label:`Watch hours`})]})]})}var s1=(e,t)=>{let n=e.long?.stats??null;return t===`views`?(n?.views??0)+e.shorts.reduce((e,t)=>e+(t.stats?.views??0),0):t===`ctr`?n?.ctr??-1:t===`duration`?n?.averageViewSeconds??-1:Date.parse(e.long?.releasedAt??e.shorts[0]?.releasedAt??``)||0};function fSe({channelId:e}){let{api:t}=B(),[n,r]=(0,m.useState)(`newest`),i=F({queryKey:[`studio`,`performance`,e],queryFn:()=>ys(t,e)});if(i.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the numbers…`});if(i.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The numbers didn't load: `,i.error.message,` Reload the page to try again.`]});let a=i.data;if(a.projects.length===0)return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(t1,{channelId:e}),(0,h.jsx)(aQ,{title:`No video of this channel is known on YouTube yet`,children:`Upload with the Slopify Studio extension, or open YouTube Studio's Content list once so the extension links your videos. Their numbers then arrive daily, or at once with Read Studio numbers now in the extension's popup.`})]});let o=a.projects.toSorted((e,t)=>s1(t,n)-s1(e,n)).flatMap(e=>[...e.long===null?[]:[{key:`${e.projectId}-0`,projectId:e.projectId,row:e.long,isShort:!1}],...e.shorts.map(t=>({key:`${e.projectId}-${String(t.short??0)}`,projectId:e.projectId,row:t,isShort:!0}))]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Studio's numbers as the Slopify Studio extension last read them`,a.readAt===null?``:` (newest ${a1(a.readAt)})`,`: daily while Chrome is open, or at once with Read Studio numbers now in the extension's popup. "–" is a number Studio doesn't show for that video (most shorts have no click-through rate).`]}),(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,h.jsx)(o1,{label:`Long videos`,totals:a.long}),(0,h.jsx)(o1,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(t1,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:`Every video`,children:(0,h.jsx)(sL,{"aria-label":`Order`,value:n,onChange:e=>r(e.currentTarget.value),options:[{value:`newest`,label:`Newest first`},{value:`views`,label:`Most views`},{value:`ctr`,label:`Best click-through rate`},{value:`duration`,label:`Longest average view`}]})}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(H$,{columns:[{id:`title`,header:`Video`,cell:e=>e.isShort?(0,h.jsx)(`span`,{className:`block pl-5 text-small text-ink-2`,children:`Short ${String(e.row.short??``)} · ${e.row.title}`}):(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>a1(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>n1(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>r1(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>n1(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>i1(e.row.stats?.averageViewSeconds)},{id:`hours`,header:`Watch hours`,numeric:!0,cell:e=>e.row.stats?.watchHours===null||e.row.stats?.watchHours===void 0?`–`:e.row.stats.watchHours.toFixed(1)}],rows:o,rowKey:e=>e.key,caption:`The channel's videos and shorts with Studio's numbers`})})]})]})}var c1=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],l1={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function pSe(e){return c1.find(t=>t===e)??`brand`}function mSe({channelId:e,tab:t,onTab:n}){let{api:r}=B(),i=_(),a=Yi(),o=F(Xy(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=I({mutationFn:()=>Qy(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:Gy}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[];Uv(f===void 0?void 0:`${f.name} · ${l1[t]}`);let g=()=>{n(`cast`),u(`new`)};return sb({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),o.error!==null&&o.data===void 0?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(fG,{crumb:(0,h.jsx)(pa,{to:`/channels`,children:`Channels`}),title:`Channel not opened`}),(0,h.jsx)(aQ,{title:`This channel could not be opened`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(WO,{to:`/channels`,variant:`primary`,children:`Open Channels`}),(0,h.jsx)(z,{disabled:o.isFetching,disabledReason:`Trying again…`,onClick:()=>void o.refetch(),children:`Try again`})]}),children:`${o.error.message} A deleted channel is gone for good (its videos moved to the default channel). Pick a channel from Channels, or press Try again.`})]}):(0,h.jsxs)(`div`,{children:[(0,h.jsx)(fG,{crumb:(0,h.jsx)(pa,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(z,{variant:`primary`,onClick:g,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(z,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(rQ,{items:c1.map(e=>({id:e,label:l1[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(SR,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be read again: ${o.error.message} What is shown may be out of date; reload the page to try again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(iQ,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(pxe,{channel:f}),(0,h.jsx)(wxe,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(Vxe,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(cbe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(lbe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Zxe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(tSe,{channelId:f.id}):null}),(0,h.jsx)(iQ,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(fSe,{channelId:f.id}):null})]}):null,(0,h.jsx)(Qv,{open:s,title:E$(f?.name),consequence:d.error?.message??D$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function hSe(){let{api:e}=B(),t=_(),n=Yi(),r=F(Yy(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=I({mutationFn:()=>hre(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:Gy}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=I({mutationFn:t=>Zy(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:Gy}),a(null)}}),v=I({mutationFn:t=>Qy(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:Gy})}}),y=()=>{p.reset(),l(``),a(`new`)};sb({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)(fG,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(H,{id:`planning.channels`})]}),actions:(0,h.jsxs)(z,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(pl,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(SR,{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)(aQ,{title:`No channels yet`,actions:(0,h.jsx)(z,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(hG,{list:(0,h.jsx)(KL,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(qL,{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)(GO,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(gSe,{channel:f})}):null,(0,h.jsx)(Zv,{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)(SR,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(z,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(z,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(iL,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(X,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Qv,{open:o!==null,title:E$(o?.name),consequence:v.error?.message??D$,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function gSe({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`PDF theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(U,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(WO,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(z$,{className:`mb-6`,children:[(0,h.jsx)(B$,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(B$,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(U,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(U,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var u1=2e3;function d1(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()},u1);return()=>{clearTimeout(t)}},[e])}function f1(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function p1({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Iv();sb({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:ck.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(z,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(SR,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(f1,{}):t)}),a,(0,h.jsx)(z,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":yb(ck.save),onClick:()=>{c||s()},children:`Save`})]})}var _Se=`rounded-media border border-line bg-surface p-4`;function m1(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${_Se} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var vSe=`modulepreload`,ySe=function(e){return`/`+e},h1={},g1=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=ySe(t,n),t=s(t),t in h1)return;h1[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:vSe,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function _1({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return bSe(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function bSe(e,t){let n=await g1(()=>import(`./pdf-B0AMuc3F.js`),[]),r=await g1(()=>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 v1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),y1=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),b1=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),x1=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),S1=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),C1=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),w1=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),T1=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},v1([`page`,`margin`],`Margins`),v1([`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:[w1(`body`,`Body`),w1(`strong`,`Bold text`),w1(`emphasis`,`Italic text`),w1(`heading`,`Headings`),w1(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),w1(`decorative`,`Tagline and title-page link`),w1(`dropCap`,`Drop caps`),w1(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[y1([`sizes`,`title`],`Title`),y1([`sizes`,`brand`],`Brand`),y1([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),y1([`sizes`,`heading`],`Second-level headings`),y1([`sizes`,`subheading`],`Third-level headings`),y1([`sizes`,`body`],`Body`),y1([`sizes`,`meta`],`Date and word count`),y1([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[v1([`spacing`,`bodyLine`],`Body line height`),v1([`spacing`,`headingLine`],`Heading line height`),v1([`spacing`,`subheadingLine`],`Subheading line height`),b1([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),b1([`spacing`,`headingGap`],`Before a heading`,`× line`),b1([`spacing`,`itemGap`],`After a list item`,`× line`),v1([`spacing`,`listIndent`],`List indent`),v1([`spacing`,`quoteIndent`],`Quote indent`),v1([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[x1([`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`}]},b1([`dropCap`,`scale`],`Letter size`,`× lines`),v1([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},b1([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[v1([`titlePage`,`brandY`],`Brand from top`),v1([`titlePage`,`taglineOffset`],`Tagline below brand`),v1([`titlePage`,`titleY`],`Title from top`),v1([`titlePage`,`titleLine`],`Title line height`),v1([`titlePage`,`metaOffset`],`Details below title`),v1([`titlePage`,`metaLine`],`Details line height`),x1([`titlePage`,`showDate`],`Show the date`),x1([`titlePage`,`showWordCount`],`Show the word count`),x1([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),v1([`titlePage`,`cover`,`gap`],`Space around cover`),v1([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[C1([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),C1([`brand`,`tagline`],`Tagline`),C1([`brand`,`url`],`Website`,`Where the brand and its link go.`),C1([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[x1([`contents`,`enabled`],`Contents page`),S1([`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`}]},v1([`contents`,`titleOffset`],`Title from top margin`),v1([`contents`,`firstEntryOffset`],`First entry from top margin`),v1([`contents`,`line`],`Line height`),v1([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[x1([`header`,`enabled`],`Running header`,`The title at the top of each page.`),v1([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},x1([`footer`,`enabled`],`Page numbers`),S1([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),v1([`footer`,`bottom`],`From the bottom`),v1([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[x1([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),S1([`sources`,`title`],`Title`),v1([`sources`,`titleOffset`],`Title from top margin`),v1([`sources`,`bodyOffset`],`List from top margin`),v1([`sources`,`line`],`Line height`),v1([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[x1([`endPage`,`enabled`],`Closing page`),S1([`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.`},x1([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},C1([`endPage`,`closing`],`Closing line`),v1([`endPage`,`titleOffset`],`Title from top margin`),v1([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[S1([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),S1([`metadata`,`subject`],`Subject`),S1([`metadata`,`keywords`],`Keywords`),S1([`metadata`,`creator`],`Creator`)]}],E1=zD.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function D1(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 O1(e,t){let n=e;for(let e of t)n=n?.[e];return n}function k1(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:k1(a,i,n)}}function xSe(e){let t=KD;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function A1(e){return`values.${e.join(`.`)}`}var j1=`pt-1`,M1=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function N1({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Nc,{"aria-hidden":`true`}),e]})}function P1({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(dM,{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 F1(e){return`theme-group-${e.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`}function SSe({problems:e,changed:t}){return e===0&&t===0?null:(0,h.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 text-small font-normal`,children:[e===0?null:(0,h.jsx)(tk,{tone:`failed`,children:`${String(e)} to fix`}),t===0?null:(0,h.jsx)(tk,{children:`${String(t)} changed`})]})}function CSe({groups:e,onJump:t}){return(0,h.jsx)(`nav`,{"aria-label":`Theme groups`,className:`flex flex-wrap gap-1 border-t border-line pt-3`,children:e.map(e=>{let n=[e.problems===0?``:`${String(e.problems)} to fix`,e.changed===0?``:`${String(e.changed)} changed`].filter(e=>e!==``);return(0,h.jsx)(z,{variant:`quiet`,size:`small`,className:e.problems===0?void 0:`text-danger`,onClick:()=>t(e.title),children:n.length===0?e.title:`${e.title} · ${n.join(` · `)}`},e.title)})})}var wSe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function I1(e,t){let n=A1(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function TSe({field:e,theme:t,original:n,problem:r,onChange:i}){let a=(0,m.useId)(),o=O1(t,e.path),s=O1(n,e.path),c=R1(t,n,e.path),l=wSe[A1(e.path)],u=n=>{i(k1(t,e.path,n))},d=(0,h.jsxs)(h.Fragment,{children:[l===void 0?null:(0,h.jsx)(H,{id:l,label:e.label,className:`-my-1`}),c?(0,h.jsx)(Mv,{label:`Reset ${e.label} to ${z1(s)}`,tip:`Changed. Reset to ${z1(s)}`,className:`-my-1 size-6`,onClick:()=>u(s),children:(0,h.jsx)(gl,{"aria-hidden":`true`,className:`size-[13px]`})}):null]}),f=e.kind===`color`&&r===void 0?DSe(t,e.path):void 0,p=[e.help===void 0?``:`${a}-help`,r===void 0?``:`${a}-error`,f===void 0?``:`${a}-contrast`].filter(e=>e!==``).join(` `),g=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${a}-help`,className:`sl-field__help m-0`,children:e.help}),r===void 0?null:(0,h.jsx)(`p`,{id:`${a}-error`,className:`sl-field__error m-0`,children:r}),f===void 0?null:(0,h.jsx)(`p`,{id:`${a}-contrast`,className:`m-0 text-small text-waiting`,children:f})]}),_={id:a,"aria-invalid":r!==void 0,"aria-describedby":p===``?void 0:p};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ny,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{..._,type:`checkbox`,checked:o===!0,className:`size-4 accent-accent`,onChange:e=>{u(e.currentTarget.checked)}}),e.label]}),d]}),g]});case`number`:{let{min:t,max:n}=xSe(e.path);return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(X,{..._,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof o==`number`&&Number.isFinite(o)?o:``,onChange:e=>{u(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(l$,{..._,pickerLabel:`${e.label} colour`,value:typeof o==`string`?o:``,onChange:u})});case`text`:return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value)}})});case`optional-text`:return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(X,{..._,value:typeof o==`string`?o:``,onChange:e=>{u(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===o);return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsx)(sL,{..._,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&u(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=o,n=D1(t.family);return(0,h.jsx)(L1,{id:a,label:e.label,notes:g,info:d,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(sL,{..._,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=E1.find(t=>t.value===e.target.value);if(n===void 0)return;let r=D1(n.value).some(e=>e.value===t.style);u({...t,family:n.value,style:r?t.style:`normal`})},children:E1.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(sL,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{u({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(X,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{u({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ny,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:a,className:`sl-field__label`,children:e.label}),d]}),(0,h.jsx)(oL,{..._,rows:8,value:Array.isArray(o)?o.join(`
|
|
275
275
|
`):``,onChange:e=>{u(e.target.value.split(`
|
|
276
276
|
`))}}),g]});case`link`:{let t=o;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...Ny,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:a,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{u(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),d]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(X,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{u({...t,text:e.target.value})}}),(0,h.jsx)(X,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{u({...t,url:e.target.value===``?null:e.target.value})}})]}),g]})}}}function L1({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ny,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 R1(e,t,n){return JSON.stringify(O1(e,n))!==JSON.stringify(O1(t,n))}function z1(e){return e==null||e===``?`empty`:typeof e==`boolean`?e?`on`:`off`:typeof e==`string`||typeof e==`number`?String(e):`the starting value`}var ESe={"colors.text":4.5,"colors.heading":3,"colors.muted":3,"colors.faint":3};function DSe(e,t){let n=ESe[t.join(`.`)];if(n===void 0||e.background.image!==null)return;let r=O1(e,t);if(typeof r==`string`)return c$(r,e.background.color,`the page colour`,n)}function B1({themeId:e,from:t,onLeave:n}){let{api:r}=B(),i=_(),a=F(wy(r)),o=(0,m.useId)(),[s,c]=(0,m.useState)(void 0),[l,u]=(0,m.useState)([]),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),v=a.data,y=e===void 0?void 0:v?.themes.find(t=>t.id===e),b=e===void 0?v?.themes.find(e=>e.id===t)??v?.builtIns.find(e=>e.name===(t??`plain`))??v?.builtIns[0]:y,x=b===void 0?void 0:{name:e===void 0?`${`label`in b?b.label:b.name} copy`:b.name,values:b.values},S=s??x,C=I({mutationFn:t=>Qs(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:wy(r).queryKey})}}),w=I({mutationFn:e=>$s(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:wy(r).queryKey}),n()}});d1(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:KD.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:Ile(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)(V1,{children:a.error.message});if(v===void 0)return(0,h.jsx)(m1,{});if(S===void 0)return(0,h.jsx)(V1,{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=T1.map(e=>({title:e.title,problems:e.fields.filter(e=>I1(E,e.path)!==void 0).length,changed:x===void 0?0:e.fields.filter(e=>R1(S.values,x.values,e.path)).length})),k=O.filter(e=>e.problems>0).map(e=>e.title),A=S.name.trim()===``?`Give the theme a name.`:E.length>0?k.length===0?`Fix the highlighted settings first.`:`Fix the highlighted settings first, in ${k.join(`, `)}.`:void 0,j=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(fG,{crumb:(0,h.jsx)(N1,{children:(0,h.jsx)(pa,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New PDF theme`:`Edit PDF theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${j1} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(iL,{label:`Name`,tip:`library.theme.name`,...j.length===0?{}:{error:j.map(e=>e.message).join(` `)},children:(0,h.jsx)(X,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),(0,h.jsx)(CSe,{groups:O,onJump:e=>{let t=document.getElementById(F1(e));t instanceof HTMLDetailsElement&&(t.open=!0,t.scrollIntoView?.({block:`start`,behavior:`smooth`}),t.querySelector(`summary`)?.focus())}}),T1.map((e,t)=>{let n=O[t];return(0,h.jsxs)(`details`,{id:F1(e.title),open:t<2||(n?.problems??0)>0,className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(Nc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title,(0,h.jsx)(SSe,{problems:n?.problems??0,changed:n?.changed??0})]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(TSe,{field:e,theme:S.values,original:x?.values??S.values,problem:I1(E,e.path),onChange:t=>{D({...S,values:t},A1(e.path))}},e.path.join(`.`)))})]},e.title)}),(0,h.jsx)(p1,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:A,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(WO,{to:`/document-themes`,variant:`secondary`,children:`Cancel`}),errors:[C.error,w.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{C.mutate(S)}})]}),(0,h.jsx)(OSe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(Qv,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}function OSe({values:e}){let{api:t}=B(),[n,r]=(0,m.useState)(),[i,a]=(0,m.useState)(`busy`),[o,s]=(0,m.useState)(void 0),c=e===void 0?void 0:JSON.stringify(e);(0,m.useEffect)(()=>{if(c===void 0)return;let e=new AbortController,n=window.setTimeout(()=>{a(`busy`),ec(t,JSON.parse(c),e.signal).then(async e=>({bytes:new Uint8Array(await e.arrayBuffer()),blob:e})).then(({bytes:t,blob:n})=>{e.signal.aborted||r({bytes:t,url:URL.createObjectURL(n)})},t=>{e.signal.aborted||(s(t instanceof Error?t.message:String(t)),a(`failed`))})},450);return()=>{window.clearTimeout(n),e.abort()}},[t,c]),(0,m.useEffect)(()=>()=>{n!==void 0&&URL.revokeObjectURL(n.url)},[n]);let l=(0,m.useCallback)(e=>{if(e===void 0){a(`idle`);return}s(e.message),a(`failed`)},[]),u=e===void 0?`Paused until the highlighted settings are fixed.`:i===`busy`?`Updating…`:i===`failed`?`The preview couldn't be made: ${o??`unknown error`}`:`A sample article with this theme. Your projects use their own text and thumbnail.`;return(0,h.jsxs)(`div`,{className:M1,children:[(0,h.jsx)(U,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(KO,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open full size`]})}),(0,h.jsx)(`div`,{className:`max-h-[calc(100vh-220px)] min-h-[320px] overflow-y-auto rounded-media bg-sunken p-3`,children:(0,h.jsx)(_1,{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 V1({children:e}){return(0,h.jsx)(P1,{back:(0,h.jsx)(pa,{to:`/document-themes`,children:`Back to Documents`}),children:e})}function H1({selection:e,total:t,noun:n,scope:r,busy:i,onDuplicate:a,onExport:o,onDelete:s,deleteLabel:c=`Delete selected`}){return e.count===0?null:(0,h.jsx)(xG,{selection:e,total:t,noun:n,className:`mb-2`,...r===void 0?{}:{scope:r},actions:(0,h.jsxs)(h.Fragment,{children:[a===void 0?null:(0,h.jsxs)(z,{size:`small`,disabled:i,disabledReason:`Working on the last press`,onClick:a,children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,className:`size-[14px]`}),`Duplicate selected`]}),o===void 0?null:(0,h.jsxs)(z,{size:`small`,onClick:o,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-[14px]`}),`Export selected`]}),(0,h.jsxs)(z,{size:`small`,variant:`destructive`,disabled:i,disabledReason:`Working on the last press`,onClick:s,children:[(0,h.jsx)(xl,{"aria-hidden":`true`,className:`size-[14px]`}),c]})]})})}function U1({selection:e,children:t}){return(0,h.jsx)(`div`,{onKeyDown:e.onKeyDown,children:t})}function W1(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${G1(e.fonts.body.family)} body`}function G1(e){return E1.find(t=>t.value===e)?.label??e}function K1(e){return e.startsWith(`#`)?e:`#${e}`}function q1({name:e,kicker:t,meta:n,values:r,action:i}){let a=[[`Headings`,r.colors.heading],[`Text`,r.colors.text],[`Muted`,r.colors.muted],[`Header and page numbers`,r.colors.faint]],o=[[`Body`,r.fonts.body],[`Headings`,r.fonts.heading],[`Drop cap`,r.fonts.dropCap]];return(0,h.jsxs)(`section`,{"aria-label":`${e} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(U,{title:e,kicker:t,meta:n,className:`pb-0`,children:i}),(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-[max-content_minmax(0,1fr)]`,children:[a.map(([e,t])=>(0,h.jsx)(J1,{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:K1(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:K1(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(J1,{label:`${e} font`,children:`${G1(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(J1,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${K1(r.background.color)}`} background`})]})]})}function J1({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 Y1({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:K1(e)}},t))})}var X1=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,Z1=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function Q1({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 $1({what:e,message:t,onRetry:n}){return(0,h.jsx)(dM,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(z,{size:`small`,onClick:n,children:`Try again`}),children:t})}function e0({name:e,edit:t,duplicate:n,play:r,onHistory:i,onDelete:a,className:o}){return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`Actions for ${e}`,className:R(`flex flex-wrap items-center gap-0.5`,o),children:[t,r===void 0?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,"aria-label":`Use ${e} in Play`,title:r.blocked,disabled:r.run===void 0||r.blocked!==void 0,onClick:r.run,children:`Use in Play`}),(0,h.jsxs)(JO,{children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsx)(Mv,{size:`small`,label:`More actions for ${e}`,children:(0,h.jsx)(Hc,{"aria-hidden":`true`})})}),(0,h.jsxs)(XO,{children:[(0,h.jsx)(ZO,{asChild:!0,children:n}),i===void 0?null:(0,h.jsxs)(ZO,{"aria-label":`History of ${e}`,onSelect:i,children:[(0,h.jsx)(hl,{"aria-hidden":`true`,className:`size-4`}),`History`]}),(0,h.jsx)(QO,{}),(0,h.jsxs)(ZO,{"aria-label":`Delete ${e}`,onSelect:a,children:[(0,h.jsx)(xl,{"aria-hidden":`true`,className:`size-4`}),`Delete`]})]})]})]})}var t0=[{value:`name`,label:`Name`},{value:`changed`,label:`Last changed`}];function n0(e,t){return[...e].sort((e,n)=>t===`changed`?n.updatedAt.localeCompare(e.updatedAt)||e.name.localeCompare(n.name):e.name.localeCompare(n.name,void 0,{sensitivity:`base`}))}var r0=e=>`slopify.library.sort.${e}`;function kSe(e){try{return globalThis.localStorage?.getItem(r0(e))===`changed`?`changed`:`name`}catch{return`name`}}function i0(e){let[t,n]=(0,m.useState)(()=>kSe(e));return[t,t=>{n(t);try{globalThis.localStorage?.setItem(r0(e),t)}catch{}}]}function a0({what:e,sort:t,onSort:n}){let r=t0.find(e=>e.value===t)?.label??`Name`;return(0,h.jsxs)(JO,{children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,size:`small`,"aria-label":`Sort ${e}: ${r}`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`}),r]})}),(0,h.jsx)(XO,{align:`start`,children:t0.map(e=>(0,h.jsxs)(ZO,{"aria-label":`Sort by ${e.label.toLowerCase()}${e.value===t?` (current)`:``}`,onSelect:()=>n(e.value),children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:e.value===t?`size-4`:`size-4 opacity-0`}),e.value===`changed`?`Last changed first`:`Name, A to Z`]},e.value))})]})}var ASe=4e3;function o0(e){return e.match(/\s+|[^\s]+/gu)??[]}function jSe(e,t){let n=o0(e),r=o0(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=[];c0(o,`same`,n.slice(0,i).join(``));let s=n.slice(i,n.length-a),c=r.slice(i,r.length-a);for(let e of NSe(s,c))c0(o,e.op,e.text);return c0(o,`same`,n.slice(n.length-a).join(``)),o}function s0(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function MSe(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+o0(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function c0(e,t,n){if(n===``)return;let r=e.at(-1);r!==void 0&&r.op===t?e[e.length-1]={op:t,text:r.text+n}:e.push({op:t,text:n})}function NSe(e,t){if(e.length===0&&t.length===0)return[];if(e.length===0)return[{op:`added`,text:t.join(``)}];if(t.length===0)return[{op:`removed`,text:e.join(``)}];let n=e.length,r=t.length,i=Math.min(n+r,ASe),a=i+1,o=new Int32Array(2*i+3),s=[],c=!1;for(let l=0;l<=i&&!c;l+=1){s.push(o.slice());let i=o.slice();for(let s=-l;s<=l;s+=2){let u=s===-l||s!==l&&(o[a+s-1]??0)<(o[a+s+1]??0)?o[a+s+1]??0:(o[a+s-1]??0)+1,d=u-s;for(;u<n&&d<r&&e[u]===t[d];)u+=1,d+=1;if(i[a+s]=u,u>=n&&d>=r){c=!0;break}}o=i}if(!c)return[{op:`removed`,text:e.join(``)},{op:`added`,text:t.join(``)}];let l=[],u=n,d=r;for(let n=s.length-1;n>=0;--n){let r=s[n]??new Int32Array,i=u-d,o=i===-n||i!==n&&(r[a+i-1]??0)<(r[a+i+1]??0),c=o?i+1:i-1,f=r[a+c]??0,p=f-c;for(;u>f&&d>p;)l.push({op:`same`,text:e[u-1]??``}),--u,--d;n>0&&(o?l.push({op:`added`,text:t[d-1]??``}):l.push({op:`removed`,text:e[u-1]??``}),u=f,d=p)}let f=[];for(let e of l.reverse())c0(f,e.op,e.text);return f}function l0({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>jSe(e,t),[e,t]),a=MSe(i);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:a.added===0&&a.removed===0?`The two texts are the same.`:`${String(a.added)} ${a.added===1?`word`:`words`} added, ${String(a.removed)} removed.`}),(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,h.jsx)(u0,{label:n,parts:s0(i,`before`)}),(0,h.jsx)(u0,{label:r,parts:s0(i,`after`)})]})]})}function u0({label:e,parts:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`h4`,{className:`sl-kicker m-0`,children:e}),(0,h.jsx)(`div`,{className:`min-w-0 whitespace-pre-wrap break-words border-l-2 border-line pl-3 text-small leading-relaxed text-ink`,children:PSe(t).map(({key:e,part:t})=>t.op===`removed`?(0,h.jsx)(`del`,{className:`rounded-[2px] bg-danger-tint text-danger line-through`,children:t.text},e):t.op===`added`?(0,h.jsx)(`ins`,{className:`rounded-[2px] bg-accent-tint text-accent-ink no-underline`,children:t.text},e):(0,h.jsx)(`span`,{children:t.text},e))})]})}function PSe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var d0={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function f0(e,t){let{api:n}=B();return F({queryKey:d0.versions(e,t),queryFn:()=>Ks(n,e,t)})}function FSe(e,t){let{api:n}=B();return F({queryKey:d0.usedBy(e,t),queryFn:()=>qs(n,e,t)})}function p0({item:e,id:t,name:n,onClose:r}){let{api:i}=B(),a=_(),o=f0(e,t),s=o.data?.versions??[],[c,l]=(0,m.useState)({}),u=c.after??s[0]?.version,d=c.before??s[1]?.version??u,f=s.find(e=>e.version===d),p=s.find(e=>e.version===u),[g,v]=(0,m.useState)(),y=I({mutationFn:n=>Js(i,e,t,n),onSuccess:async(n,r)=>{v(`Restored version ${String(r)} as a new version.`),l({}),await Promise.all([a.invalidateQueries({queryKey:d0.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?V.prompts:V.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)($j,{open:!0,title:`History of ${n}`,onClose:r,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[o.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:`The history couldn't be read: ${o.error.message}`}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(iL,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(sL,{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:h0(e,b)},e.version))})}),(0,h.jsx)(iL,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(sL,{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:h0(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)(l0,{before:f.body,after:p.body,beforeLabel:`Version ${String(f.version)}`,afterLabel:`Version ${String(p.version)}`})]})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(KL,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(qL,{title:`Version ${String(e.version)}`,meta:m0(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(z,{size:`small`,"aria-label":`Restore version ${String(e.version)}`,disabled:y.isPending,disabledReason:`Restoring a version`,onClick:()=>{v(void 0),y.mutate(e.version)},children:`Restore`})},e.version))}),(0,h.jsx)(SR,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function m0(e){return`${e.author} · ${g0(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function h0(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${g0(e.createdAt)}`}function g0(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function _0({item:e,id:t,name:n,kicker:r,meta:i,body:a,slots:o,actions:s,onOpenHistory:c}){return(0,h.jsxs)(`section`,{"aria-label":`${n} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(U,{title:n,kicker:r,meta:i,className:`pb-0`,children:s}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`div`,{className:`m-0 max-h-[420px] min-w-0 overflow-y-auto whitespace-pre-wrap break-words rounded-media bg-sunken p-4 font-mono text-small text-ink-2`,children:a}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No keywords. It runs as written.`}):(0,h.jsx)(`ul`,{"aria-label":`Keywords`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:o.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(cL,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(ISe,{item:e,id:t}),(0,h.jsx)(LSe,{item:e,id:t,name:n,onOpenHistory:c})]})}function ISe({item:e,id:t}){let n=FSe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:RSe(r)}}),n.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`What uses it couldn't be read: ${n.error.message}`}),r===void 0?null:r.templates.length+r.schedules.length+r.projects.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Nothing uses it yet.`}):(0,h.jsxs)(KL,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(qL,{title:(0,h.jsx)(pa,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(qL,{title:(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name}),meta:e.status===`paused`?`Schedule · paused`:`Schedule`},`s-${e.id}`)),r.projects.map(e=>(0,h.jsx)(qL,{title:(0,h.jsx)(pa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),meta:`Project${e.totalRevisions===0?``:` · ${String(e.revisions)} of ${String(e.totalRevisions)} ${e.totalRevisions===1?`revision`:`revisions`}${e.current?`, including the current one`:`, not the current one`}`}`},`p-${e.id}`))]})]})}function LSe({item:e,id:t,name:n,onOpenHistory:r}){let i=f0(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:(0,h.jsx)(`span`,{title:y0(o.createdAt),children:`${v0(a.length,`version`)} · latest ${m0(o)}`})},children:(0,h.jsx)(z,{size:`small`,"aria-label":`Compare versions of ${n}`,onClick:r,children:`Compare versions`})}),i.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The history couldn't be read: ${i.error.message}`}),o===void 0?null:s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Only one version so far.`}):(0,h.jsx)(l0,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function RSe(e){return[v0(e.templates.length,`template`),v0(e.schedules.length,`schedule`),v0(e.projects.length,`project`)].join(`, `)}function v0(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function zSe(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}function y0(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,timeZoneName:`short`})}function b0({iso:e,children:t}){return(0,h.jsx)(`time`,{dateTime:e,title:y0(e),children:t??zSe(e)})}function x0({what:e,exports:t,accept:n,onFile:r,disabled:i=!1}){let a=(0,m.useRef)(null);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(JO,{children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,disabled:i,disabledReason:`Still loading`,children:[(0,h.jsx)(yc,{"aria-hidden":`true`,className:`size-[14px]`}),`Import or export`]})}),(0,h.jsxs)(XO,{children:[t.map(e=>(0,h.jsxs)(ZO,{disabled:e.disabled===!0,onSelect:e.run,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,className:`size-4`}),e.label]},e.label)),(0,h.jsx)(QO,{}),(0,h.jsxs)(ZO,{onSelect:()=>a.current?.click(),children:[(0,h.jsx)(Cl,{"aria-hidden":`true`,className:`size-4`}),`Import from a file…`]})]})]}),(0,h.jsx)(`input`,{ref:a,type:`file`,hidden:!0,accept:n,"aria-label":`Import ${e} from a file`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&r(t)}})]})}var S0=`slopify-library`,BSe=20971520,C0=1e4,VSe={prompts:`prompts`,entries:`intros or outros`,documentThemes:`PDF themes`,aliases:`narration aliases`},w0={prompts:e=>({kind:e.kind,name:e.name,body:e.body}),entries:e=>({category:e.category,mode:e.mode,name:e.name,body:e.body}),documentThemes:e=>({name:e.name,values:e.values}),aliases:e=>({written:e.written,spoken:e.spoken,wholeWord:e.wholeWord,caseSensitive:e.caseSensitive})};function T0(e,t){return{format:S0,version:1,exportedAt:t.toISOString(),...e.prompts===void 0?{}:{prompts:e.prompts.map(w0.prompts)},...e.entries===void 0?{}:{entries:e.entries.map(w0.entries)},...e.documentThemes===void 0?{}:{documentThemes:e.documentThemes.map(w0.documentThemes)},...e.aliases===void 0?{}:{aliases:e.aliases.map(w0.aliases)}}}var E0=e=>G({error:`it has no name.`}).trim().min(1,{error:`it has no name.`}).max(e,{error:`its name is longer than ${String(e)} characters.`}),D0=G({error:`it has no text.`}).max(zb,{error:`its text is longer than ${String(zb)} characters.`}),HSe={prompts:J({kind:Y(Lb,{error:`its kind isn't one of ${Lb.join(`, `)}.`}),name:E0(200),body:D0}),entries:J({category:Y(Rb,{error:`it is neither an intro nor an outro.`}),mode:Y(Mb,{error:`its mode isn't one of ${Mb.join(`, `)}.`}),name:E0(200),body:D0}),documentThemes:J({name:E0(80),values:KD}),aliases:YD},USe=J({format:tT(S0),version:K().int().positive()}).loose();function O0(e,t){let n=VSe[t],r;try{r=JSON.parse(e)}catch{return{ok:!1,message:`it isn't a Slopify library file (the text isn't JSON). Pick a .json file made by Export.`}}let i=USe.safeParse(r);if(!i.success)return{ok:!1,message:`it isn't a Slopify library file. Pick a .json file made by Export on a Library tab.`};if(i.data.version>1)return{ok:!1,message:`it was made by a newer Slopify. Update Slopify (Settings → Updates), then import it again.`};let a=i.data[t];if(!Array.isArray(a)||a.length===0)return{ok:!1,message:`it holds no ${n}. Import it on the Library tab it was exported from.`};if(a.length>C0)return{ok:!1,message:`it holds more than ${String(C0)} ${n}. Split it into smaller files.`};let o=[],s=[],c=HSe[t];for(let[e,t]of a.entries()){let n=c.safeParse(t);n.success?o.push(n.data):s.push({item:WSe(t,e),reason:GSe(n.error)})}return{ok:!0,items:o,skipped:s}}function WSe(e,t){let n=J({name:G().trim().min(1)}).safeParse(e);if(n.success)return n.data.name;let r=J({written:G().trim().min(1)}).safeParse(e);return r.success?r.data.written:`Item ${String(t+1)}`}function GSe(e){let t=e.issues[0];if(t===void 0)return`it doesn't fit.`;let[n]=t.path;return n===`values`?`its setting ${t.path.slice(1).join(`.`)}: ${t.message}`:n===`written`||n===`spoken`?`its ${n===`written`?`written form`:`spoken form`} is empty or too long.`:typeof n==`string`&&/^it/u.test(t.message)?t.message:n===void 0?`it isn't an item.`:`its ${String(n)} is missing or wrong.`}function KSe(e,t,n){return k0(e,t,n,e=>e===1?` (imported)`:` (imported ${String(e)})`)}function qSe(e,t,n){return k0(e,t,n,e=>e===1?` copy`:` copy ${String(e)}`,!1)}function k0(e,t,n,r,i=!0){let a=e.trim();if(i&&!t.has(a.toLowerCase()))return a;for(let e=1;;e+=1){let i=r(e),o=`${a.slice(0,Math.max(0,n-i.length)).trimEnd()}${i}`;if(!t.has(o.toLowerCase()))return o}}var A0=e=>e instanceof Error?e.message:String(e);function j0({noun:e,listKey:t,all:n,groupOf:r=()=>``,nameMax:i,duplicate:a,remove:o,trash:s,selection:c}){let{api:l}=B(),u=_(),d=Iv(),f=t=>SG(t,e[0],e[1]),p=async()=>{await Promise.all([u.invalidateQueries({queryKey:t}),...s===void 0?[]:[u.invalidateQueries({queryKey:XZ})]])},m=(e,t,n)=>{let r=e[0];r!==void 0&&d(`${f(e.length)} ${e.length===1?`wasn't`:`weren't`} ${t}: “${r.item.name}”: ${r.reason} ${n}`,`error`)},h=I({mutationFn:async e=>{let t=new Map;for(let e of n){let n=t.get(r(e))??new Set;n.add(e.name.trim().toLowerCase()),t.set(r(e),n)}let o=[],s=[];for(let n of e){let e=t.get(r(n))??new Set;t.set(r(n),e);let c=qSe(n.name,e,i);try{let t=await a(n,c);t===null?(e.add(c.toLowerCase()),o.push(c)):s.push({item:n,reason:t})}catch(e){s.push({item:n,reason:A0(e)})}}return{made:o,refused:s}},onSuccess:({made:e,refused:t})=>{let[n]=e;e.length===1&&n!==void 0?d(`Duplicated as “${n}”.`,`success`):e.length>1&&d(`Duplicated ${f(e.length)}.`,`success`),m(t,`duplicated`,`Press Duplicate selected again.`)},onError:e=>d(`Nothing was duplicated: ${A0(e)} Press Duplicate selected again.`,`error`),onSettled:async()=>{c.clear(),await p()}}),g=async(t,n)=>{try{let e=await $Z(l,t.map(e=>({kind:n,id:e.id})));e.failed.length>0?d(`${f(e.failed.length)} couldn't be restored: ${e.failed[0]?.detail??``} Restore ${e.failed.length===1?`it`:`them`} in Settings → Backup & storage → Trash.`,`error`):d(`Restored ${f(e.restored.length)}.`,`success`)}catch(t){d(`The ${e[1]} weren't restored: ${A0(t)} Restore them in Settings → Backup & storage → Trash.`,`error`)}finally{await p()}},v=I({mutationFn:async e=>{let t=[],n=[];for(let r of e)try{await o(r),t.push(r)}catch(e){n.push({item:r,reason:A0(e)})}return{done:t,refused:n}},onSuccess:({done:e,refused:t})=>{e.length>0&&(s===void 0?d(`Deleted ${f(e.length)} permanently.`,`success`):d(`Moved ${f(e.length)} to the trash.`,`success`,{label:`Undo`,run:()=>void g(e,s)})),m(t,`deleted`,`Press Delete selected again.`)},onError:e=>d(`Nothing was deleted: ${A0(e)} Press Delete selected again.`,`error`),onSettled:async()=>{c.clear(),await p()}});return{duplicate:e=>h.mutate(e),remove:e=>v.mutate(e),busy:h.isPending||v.isPending}}function M0(e){return e.ok?null:(e.fields??[]).map(e=>e.message).join(` `)}function N0(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=document.createElement(`a`);i.href=r,i.download=e,i.click(),URL.revokeObjectURL(r)}function P0(e,t){N0(`slopify-${e}-${t.exportedAt.slice(0,10)}.json`,`${JSON.stringify(t,null,2)}\n`,`application/json`)}async function F0(e){if(e.size>20971520)return{ok:!1,message:`it is larger than ${String(BSe/1024/1024)} MB, far more than a Library export. Pick the .json file Export made.`};try{return{ok:!0,text:await e.text()}}catch(e){return{ok:!1,message:`the file couldn't be read (${e instanceof Error?e.message:String(e)}). Pick it again.`}}}var JSe=3;async function YSe(e,t){let n=new Map,r=e=>{let t=n.get(e);if(t!==void 0)return t;let r=new Set;return n.set(e,r),r};for(let e of t.existing)r(e.group).add(e.name.trim().toLowerCase());let i=0,a=0,o=[];for(let n of e){let e=r(t.groupOf(n)),s=``;for(let r=0;r<JSe;r+=1){let r=KSe(n.name,e,t.max);try{let o=await t.save({...n,name:r});if(e.add(r.toLowerCase()),o.ok){i+=1,r!==n.name.trim()&&(a+=1),s=``;break}if(s=o.fields.map(e=>e.message).join(` `),!o.fields.some(e=>e.field===`name`))break}catch(e){s=e instanceof Error?e.message:String(e);break}}s!==``&&o.push({item:n.name.trim()||`An item`,reason:s})}return{added:i,renamed:a,skipped:o}}function I0(e){if(e.length===0)return``;let t=e.slice(0,3).map(e=>`“${e.item}”: ${e.reason}`).join(` `),n=e.length>3?` And ${String(e.length-3)} more.`:``;return`Skipped ${String(e.length)}: ${t}${n}`}function XSe(e,t,n){let r=I0(n.skipped);if(n.added===0)return{text:`Nothing was imported from ${e}. ${r} Fix the file and import it again.`,tone:`error`};let i=n.renamed===0?``:` ${SG(n.renamed,`was`,`were`)} renamed “(imported)” because the name was taken.`;return{text:`Imported ${SG(n.added,t[0],t[1])} from ${e}.${i}${r===``?``:` ${r}`}`,tone:`success`}}var L0=(e,t)=>`${e} wasn't imported: ${t}`;function R0({section:e,pack:t,stem:n,noun:r,listKey:i,existing:a,groupOf:o,nameMax:s,save:c}){let l=_(),u=Iv(),d=I({mutationFn:async t=>{let n=await F0(t);if(!n.ok)return{refused:n.message};let r=O0(n.text,e);if(!r.ok)return{refused:r.message};let i=await YSe(r.items,{existing:a.map(e=>({group:o(e),name:e.name})),groupOf:o,max:s,save:c});return{outcome:{...i,skipped:[...r.skipped,...i.skipped]}}},onSuccess:(e,t)=>{if(`refused`in e){u(L0(t.name,e.refused),`error`);return}let n=XSe(t.name,r,e.outcome);u(n.text,n.tone)},onError:(e,t)=>u(L0(t.name,`${e.message} Press Import or export, then Import from a file, to try again.`),`error`),onSettled:()=>l.invalidateQueries({queryKey:i})});return{exportItems:e=>{P0(n,T0(t(e),new Date)),u(`Exported ${SG(e.length,r[0],r[1])}.`,`success`)},importFile:e=>d.mutate(e),importing:d.isPending}}var ZSe=[{label:`Setups`,tabs:[{to:`/templates`,label:`Templates`}]},{label:`Building blocks`,tabs:[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & outros`},{to:`/document-themes`,label:`PDF themes`},{to:`/narration-aliases`,label:`Narration aliases`}]},{label:`Results`,tabs:[{to:`/ab-results`,label:`A/B results`}]}];function QSe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(fG,{title:`Library`,meta:`Templates to start from, and the prompts, intros and outros, PDF themes and narration aliases they use`}),(0,h.jsx)(`div`,{className:`mb-6 flex min-w-0 flex-wrap items-end gap-x-8 gap-y-3 border-b border-line`,children:ZSe.map(e=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:e.label}),(0,h.jsx)(sbe,{items:e.tabs,label:e.label,className:`border-b-0`})]},e.label))}),(0,h.jsx)($Se,{}),(0,h.jsx)(ka,{})]})}function $Se(){let e=Yi(),t=Va({select:e=>e.location}),n=t.search,r=Yb(t.pathname===`/prompts`?n.kind:void 0),i=Kb(t.pathname===`/entries`?n.category:void 0);return sb({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),sb({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),sb({id:`library.new-document-theme`,title:`New PDF theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`,`document`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),sb({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),sb({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),sb({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),sb({id:`library.open-document-themes`,title:`Open PDF themes`,group:`Library`,keywords:[`pdf`,`documents`,`document themes`],run:()=>{e({to:`/document-themes`})}}),null}function z0({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:R(`mb-5 flex min-h-9 flex-wrap items-center gap-x-4 gap-y-3`,n),children:[(0,h.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-3`,children:e}),t===void 0?null:(0,h.jsx)(Pv,{className:`ml-auto shrink-0`,children:t})]})}function eCe(){let{api:e}=B(),t=_(),n=F(wy(e)),[r,i]=eL(),[a,o]=i0(`document-theme`),[s,c]=(0,m.useState)(void 0),l=I({mutationFn:t=>$s(e,t),onSettled:async()=>{c(void 0),await t.invalidateQueries({queryKey:V.documentThemes})}}),u=n.data,d=u===void 0?[]:n0(u.themes,a),f=d.find(e=>e.id===r),p=f===void 0?u?.builtIns.find(e=>e.name===r):void 0,g=f===void 0&&p===void 0?d[0]:void 0,v=f??g,y=v===void 0?p??u?.builtIns[0]:void 0,b=_G(d.map(e=>e.id)),x=d.filter(e=>b.has(e.id)),[S,C]=(0,m.useState)(!1),w=j0({noun:B0,listKey:V.documentThemes,all:d,nameMax:80,duplicate:async(t,n)=>M0(await Qs(e,{name:n,values:t.values},void 0)),remove:t=>$s(e,t.id),trash:void 0,selection:b}),T=R0({section:`documentThemes`,pack:e=>({documentThemes:e}),stem:`pdf-themes`,noun:B0,listKey:V.documentThemes,existing:d,groupOf:()=>``,nameMax:80,save:t=>Qs(e,t,void 0)});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(z0,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x0,{what:`PDF themes`,disabled:u===void 0||T.importing,exports:[{label:`Export all ${SG(d.length,`theme`,`themes`)} of yours`,run:()=>T.exportItems(d),disabled:d.length===0}],accept:`.json,application/json`,onFile:T.importFile}),(0,h.jsx)(WO,{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)($1,{what:`PDF themes`,message:n.error.message,onRetry:()=>void n.refetch()}),u===void 0?n.error===null?(0,h.jsx)(Q1,{label:`PDF themes`}):null:(0,h.jsx)(hG,{className:X1,list:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`,children:d.length>1?(0,h.jsx)(a0,{what:`your themes`,sort:a,onSort:o}):null}),u.themes.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No themes of your own yet. Copy a built-in below to start one.`}):(0,h.jsxs)(U1,{selection:b,children:[(0,h.jsx)(H1,{selection:b,total:d.length,noun:B0,busy:w.busy,onDuplicate:()=>w.duplicate(x),onExport:()=>T.exportItems(x),onDelete:()=>C(!0)}),(0,h.jsx)(KL,{label:`Your themes`,children:d.map(e=>(0,h.jsx)(qL,{className:Z1,lead:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(yG,{selection:b,value:e.id,label:e.name}),(0,h.jsx)(Y1,{colors:e.values.colors})]}),title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[`${W1(e.values)} · updated `,(0,h.jsx)(b0,{iso:e.updatedAt})]}),selected:e.id===v?.id,onSelect:()=>i(e.id),actions:(0,h.jsx)(e0,{name:e.name,edit:(0,h.jsx)(WO,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(WO,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>c(e)})},e.id))})]})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(KL,{label:`Built-in themes`,children:u.builtIns.map(e=>(0,h.jsx)(qL,{className:Z1,lead:(0,h.jsx)(Y1,{colors:e.values.colors}),title:e.label,meta:W1(e.values),selected:e.name===y?.name,onSelect:()=>i(e.name),actions:(0,h.jsx)(WO,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:v===void 0?y===void 0?null:(0,h.jsx)(q1,{name:y.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:y.values,action:(0,h.jsx)(WO,{to:`/document-themes/new`,search:{from:y.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(q1,{name:v.name,kicker:`Your theme`,meta:(0,h.jsxs)(h.Fragment,{children:[`Updated `,(0,h.jsx)(b0,{iso:v.updatedAt})]}),values:v.values,action:(0,h.jsx)(WO,{to:`/document-themes/$themeId`,params:{themeId:v.id},size:`small`,children:`Edit theme`})})}),l.error===null?null:(0,h.jsx)(dM,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:l.error.message}),(0,h.jsx)(Qv,{open:s!==void 0,title:`Delete the PDF theme “${s?.name??``}”?`,consequence:tCe,confirmLabel:`Delete theme permanently`,pending:l.isPending,onConfirm:()=>{s!==void 0&&l.mutate(s.id)},onCancel:()=>c(void 0)}),(0,h.jsx)(Qv,{open:S,title:`Delete ${SG(x.length,`PDF theme`,`PDF themes`)} permanently?`,consequence:`${x.length===1?`“${x[0]?.name??``}” is`:`These ${String(x.length)} themes are`} deleted permanently: PDF themes do not go to Settings → Trash, so they cannot be restored. Projects that used them keep their own copy of the settings.`,confirmLabel:`Delete ${SG(x.length,`theme`,`themes`)} permanently`,cancelLabel:`Keep them`,pending:w.busy,onConfirm:()=>{w.remove(x),C(!1)},onCancel:()=>C(!1)})]})}var B0=[`PDF theme`,`PDF themes`],tCe=`It is deleted permanently: PDF themes do not go to Settings → Trash, so it cannot be restored. Projects that used it keep their own copy of its settings.`;function V0(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 H0({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Iv(),[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`,...Ny,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(X,{autoFocus:!0,"aria-label":`New name for ${e}`,"aria-invalid":u!==null,maxLength:i,value:c,className:`min-w-0 flex-1`,onChange:e=>{l(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v()):e.key===`Escape`&&(e.preventDefault(),y())}}),(0,h.jsx)(z,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(H,{id:r,label:`Rename`})]}),u===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small font-normal text-danger`,children:u})]}):(0,h.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[t===void 0?(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:e}):(0,h.jsx)(JL,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(Mv,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(ul,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function nCe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=B(),a=_(),o=F(Cy(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=cb(l,`intros and outros`),[d,f]=eL(),[p,g]=i0(`entry`),[v,y]=(0,m.useState)(void 0),[b,x]=(0,m.useState)(void 0),S=I({mutationFn:e=>ic(i,e),onSettled:async()=>{y(void 0),await a.invalidateQueries({queryKey:V.entries})}}),C=async(e,t)=>{let n=await Xs(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:V.entries}),n.ok?null:V0(n.fields)},w=o.data?.entries.filter(t=>t.category===e),T=s.trim().toLowerCase(),E=T===``?w:w?.filter(e=>e.name.toLowerCase().includes(T)||e.body.toLowerCase().includes(T)),D=E===void 0?void 0:n0(E,p),O=D?.find(e=>e.id===d)??D?.[0],k=o.data?.entries??[],A=_G(D?.map(e=>e.id)??[]),j=D?.filter(e=>A.has(e.id))??[],M=[e,`${e}s`],ee=j0({noun:M,listKey:V.entries,all:k,groupOf:e=>e.category,nameMax:200,duplicate:async(e,t)=>M0(await Xs(i,{category:e.category,mode:e.mode,name:t,body:e.body},void 0)),remove:e=>ic(i,e.id),trash:`entry`,selection:A}),N=R0({section:`entries`,pack:e=>({entries:e}),stem:`intros-and-outros`,noun:[`intro or outro`,`intros and outros`],listKey:V.entries,existing:k,groupOf:e=>e.category,nameMax:200,save:e=>Xs(i,e,void 0)});return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(z0,{action:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x0,{what:`intros and outros`,disabled:o.data===void 0||N.importing,exports:[{label:`Export all ${String(k.length)} intros and outros`,run:()=>N.exportItems(k),disabled:k.length===0}],accept:`.json,application/json`,onFile:N.importFile}),(0,h.jsx)(WO,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`})]}),children:[(0,h.jsx)(X,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":yb(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)(Fy,{label:`Entry category`,value:e,options:Bb.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`}),(0,h.jsx)(a0,{what:`intros and outros`,sort:p,onSort:g})]}),o.error===null?null:(0,h.jsx)($1,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),D===void 0||w===void 0?o.error===null?(0,h.jsx)(Q1,{label:`Intros and outros`}):null:w.length===0?(0,h.jsx)(iCe,{category:e}):(0,h.jsx)(hG,{className:X1,list:D.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${e}s match "${s.trim()}".`}):(0,h.jsxs)(U1,{selection:A,children:[(0,h.jsx)(H1,{selection:A,total:D.length,noun:M,scope:T===``?void 0:`Select all ${String(D.length)} shown`,busy:ee.busy,onDuplicate:()=>ee.duplicate(j),onExport:()=>N.exportItems(j),onDelete:()=>ee.remove(j)}),(0,h.jsx)(KL,{label:`${Hb(e)}s`,children:D.map(e=>(0,h.jsx)(qL,{className:Z1,lead:(0,h.jsx)(yG,{selection:A,value:e.id,label:e.name}),title:(0,h.jsx)(H0,{name:e.name,onSelect:()=>f(e.id),onRename:t=>C(e,t)}),meta:rCe(e),selected:e.id===O?.id,actions:(0,h.jsx)(e0,{name:e.name,edit:(0,h.jsx)(WO,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(WO,{to:`/entries/new`,search:{category:e.category,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>x(e),onDelete:()=>y(e)})},e.id))})]}),detail:O===void 0?null:(0,h.jsx)(_0,{item:`entry`,id:O.id,name:O.name,kicker:`${Hb(O.category)} · ${Ub(O.mode)}`,meta:(0,h.jsxs)(h.Fragment,{children:[`Updated `,(0,h.jsx)(b0,{iso:O.updatedAt})]}),body:O.body,slots:O.slots,actions:(0,h.jsx)(WO,{to:`/entries/$entryId`,params:{entryId:O.id},size:`small`,children:`Edit ${O.category}`}),onOpenHistory:()=>x(O)},O.id)}),S.error===null?null:(0,h.jsx)(dM,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:S.error.message}),b===void 0?null:(0,h.jsx)(p0,{item:`entry`,id:b.id,name:b.name,onClose:()=>x(void 0)},b.id),(0,h.jsx)(Qv,{open:v!==void 0,title:v===void 0?``:`Delete "${v.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${v?.category??e}`,pending:S.isPending,onConfirm:()=>{v!==void 0&&S.mutate(v.id)},onCancel:()=>y(void 0)})]})}function rCe(e){return(0,h.jsxs)(h.Fragment,{children:[`${Ub(e.mode)} · ${v0(e.slots.length,`keyword`)} · updated `,(0,h.jsx)(b0,{iso:e.updatedAt})]})}function iCe({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(aQ,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function aCe({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:R(`animate-tick-in rounded-control border border-line-strong bg-sunken px-2 py-0.5 font-mono text-label text-ink-2 motion-reduce:animate-none`,t),children:e})}function U0({slots:e,body:t,lint:n,lintId:r,noSlots:i=`No slots. This prompt runs as written.`}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(U,{title:`Detected slots`,info:`library.slots`,size:`small`,className:`pb-0`}),e.length>0?(0,h.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.map(e=>(0,h.jsx)(aCe,{name:e,className:`px-2 py-1`},e))}):t.trim()===``?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Slots appear here as you type {{name}}.`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i}),n.length===0?null:(0,h.jsxs)(`div`,{id:r,className:`flex flex-col gap-2 border-t border-line pt-3`,children:[(0,h.jsx)(`span`,{className:`sl-kicker text-danger`,children:n.length===1?`1 slot error`:`${String(n.length)} slot errors`}),n.map(e=>{let n=sCe(t,e.message);return(0,h.jsxs)(`span`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message}),n===void 0?null:(0,h.jsx)(z,{variant:`quiet`,size:`small`,onClick:()=>cCe(r,n),children:`Go to ${oCe(e.message)??`it`}`})]},e.message)})]})]})}var W0=/line (\d+), column (\d+)/;function oCe(e){return W0.exec(e)?.[0]}function sCe(e,t){let n=W0.exec(t);if(n===null)return;let r=e.split(`
|
|
277
277
|
`),i=Number(n[1]),a=Number(n[2]);if(!(i<1||i>r.length))return r.slice(0,i-1).reduce((e,t)=>e+t.length+1,0)+a-1}function cCe(e,t){let n=document.querySelector(`textarea[aria-describedby~="${e}"]`);n instanceof HTMLTextAreaElement&&(n.focus(),n.setSelectionRange(t,Math.min(t+2,n.value.length)))}function G0({className:e,...t}){return(0,h.jsx)(vne,{"data-slot":`label`,className:R(`engraved block select-none text-ink-3`,e),...t})}function K0({className:e,...t}){return(0,h.jsx)(Nne,{"data-slot":`toggle-group`,className:R(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function q0({className:e,...t}){return(0,h.jsx)(Rne,{"data-slot":`toggle-group-item`,className:R(`min-h-8 shrink-0 border-r border-line-strong px-3 py-1 text-label text-ink-2 last:border-r-0`,`transition-colors duration-150 ease-out motion-reduce:transition-none hover:bg-raised hover:text-ink`,`data-[state=on]:bg-raised data-[state=on]:text-ink data-[state=on]:shadow-[inset_0_-2px_0_var(--color-accent)]`,`disabled:cursor-not-allowed disabled:opacity-40`,e),...t})}function J0({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...Ny,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(G0,{id:o,children:e}),i===void 0?null:(0,h.jsx)(H,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(K0,{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)(q0,{value:e.value,children:e.label},e.value))})]})}function Y0(e){return X0(e.name,e.body)}function lCe(e){return X0(e.name,e.body)}function X0(e,t){let n=[],r=e.trim();if(r===``?n.push({field:`name`,message:`Enter a name.`}):r.length>200&&n.push({field:`name`,message:`Keep the name to 200 characters or fewer.`}),t.trim()===``)return n.push({field:`body`,message:`Enter the text.`}),n;if(t.length>1e5)return n.push({field:`body`,message:`The text is too long. Keep it to ${String(zb)} characters or fewer.`}),n;for(let e of qW(t).errors)n.push({field:`body`,message:uCe(e,t)});return n}function uCe(e,t){let n=dCe(t,e.at);switch(e.kind){case`unclosed`:return`The \`{{\` at ${n} is never closed. Add \`}}\` after the keyword name.`;case`empty`:return`The keyword at ${n} has no name. Write a name between \`{{\` and \`}}\`.`;case`nested`:return`The keyword at ${n} contains a brace. Keywords cannot be placed inside other keywords.`}}function dCe(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
|
|
@@ -312,7 +312,7 @@ St. = Saint`,"aria-describedby":o.skipped.length===0?void 0:`${a}-skipped`,onCha
|
|
|
312
312
|
`)}function hke(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 U8(e,t){let n=n=>hke(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function W8(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}function gke(e,t,n,r){return`https://studio.youtube.com/video/${e}/edit#slopify-ab=${t}&p=${encodeURIComponent(n)}&s=${String(r??0)}`}var G8=e=>[`project`,e,`youtube-videos`];function K8(e){let{api:t}=B();return F({queryKey:G8(e),queryFn:()=>Os(t,e)})}function _ke(e){let t=e?.find(e=>e.short===null&&e.uploadState===`done`);return t===void 0?void 0:`https://youtu.be/${t.videoId}`}function vke(e){return e===null?`Video`:`Short ${String(e)}`}function yke(e){if(e.uploadState===`filled`)return`Filled in Studio, but not scheduled or published yet (canceled, or left as a draft). Upload it again from the extension, or paste its link once it is up.`;let t=[`On YouTube.`];return e.finishState===`waiting`&&t.push(`Related video, end screen and captions are being set.`),e.finishState===`failed`&&t.push(`Details touches failed: ${e.finishMessage??`no reason given`}`),e.commentState===`waiting`&&t.push(`The comment is pinned once it is public.`),e.commentState===`done`&&t.push(`Comment pinned.`),e.commentState===`failed`&&t.push(`Pinning the comment failed: ${e.commentMessage??`no reason given`}`),t.join(` `)}function bke({projectId:e,shorts:t}){let n=K8(e),{api:r}=B(),i=F({queryKey:[`project`,e,`youtube-stats`],queryFn:()=>vs(r,e)}),a=[null,...Array.from({length:t},(e,t)=>t+1)];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-field__label`,children:`On YouTube`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The extension keeps each upload's link when Studio confirms it. Paste a link for an upload made by hand. A/B test opens the video in Studio with A/B Testing set up; press Set test and Save there.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:a.map(t=>(0,h.jsx)(xke,{projectId:e,short:t,video:n.data?.find(e=>e.short===t),stats:i.data?.find(e=>e.short===t)},t??0))})]})}function xke({projectId:e,short:t,video:n,stats:r}){let{api:i}=B(),a=_(),o=(0,m.useId)(),s=n===void 0?``:`https://youtu.be/${n.videoId}`,[c,l]=(0,m.useState)(),u=c??s,[d,f]=(0,m.useState)(),p=t=>{a.setQueryData(G8(e),t),l(void 0),f(void 0)},g=I({mutationFn:()=>ks(i,e,t,u),onSuccess:p,onError:e=>f(e.message)}),v=I({mutationFn:()=>ks(i,e,t,``),onSuccess:p,onError:e=>f(`${e.message} Press Deleted on YouTube again, or clear the link and save.`)});return(0,h.jsxs)(`li`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`label`,{className:`w-[64px] shrink-0 text-small text-ink-2`,htmlFor:o,children:vke(t)}),(0,h.jsx)(X,{id:o,type:`url`,className:`min-w-[220px] flex-1 sm:max-w-[360px]`,placeholder:`https://youtu.be/…`,value:u,onChange:e=>l(e.currentTarget.value)}),u.trim()===s?null:(0,h.jsx)(z,{type:`button`,size:`small`,disabled:g.isPending,onClick:()=>g.mutate(),children:`Save link`}),n===void 0||u.trim()!==s?null:(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,disabled:v.isPending,onClick:()=>v.mutate(),children:`Deleted on YouTube`}),n===void 0||n.uploadState!==`done`||t!==null?null:(0,h.jsxs)(JO,{children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,children:`A/B test`})}),(0,h.jsx)(XO,{children:[[`both`,`Titles and thumbnails`],[`titles`,`Titles`],[`thumbnails`,`Thumbnails`]].map(([r,i])=>(0,h.jsx)(ZO,{onSelect:()=>window.open(gke(n.videoId,r,e,t),`_blank`,`noopener`),children:i},r))})]})]}),n===void 0&&d===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small ${d!==void 0||n?.finishState===`failed`||n?.commentState===`failed`?`text-danger`:`text-ink-3`}`,children:d??(n===void 0?``:yke(n))}),r===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small tabular-nums text-ink-2`,children:Ske(r)})]})}function Ske(e){let t=[];if(e.views!==null&&t.push(`${e.views.toLocaleString()} views`),e.ctr!==null&&t.push(`${String(e.ctr)}% CTR${e.impressions===null?``:` of ${e.impressions.toLocaleString()} impressions`}`),e.averageViewSeconds!==null){let n=Math.round(e.averageViewSeconds),r=n>=3600?`${String(Math.floor(n/3600))}:${String(Math.floor(n%3600/60)).padStart(2,`0`)}:${String(n%60).padStart(2,`0`)}`:`${String(Math.floor(n/60))}:${String(n%60).padStart(2,`0`)}`;t.push(`${r} average view`)}return t.push(`read ${yd(e.readAt)}`),t.join(` · `)}var Cke=J({number:K().int().positive(),first:K().int().positive(),last:K().int().positive(),start:K().finite().nonnegative(),end:K().finite().positive(),title:G(),description:G(),hashtags:q(G()),why:G(),text:G(),seed:G().nullable().optional()}),wke=.25,Tke=.4;function q8(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(wke,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(Tke,(s-a.end)/2)));return{start:J8(c),end:J8(l)}}J({first:Yw([K(),G()]),last:Yw([K(),G()]),title:G(),description:G(),hashtags:q(G()),why:G().optional()});function J8(e){return Math.round(e*1e3)/1e3}var Eke=J({shorts:q(Cke),durationSeconds:K().finite().nonnegative().optional(),sentences:q(J({start:K().finite().nonnegative(),end:K().finite().nonnegative(),text:G()})).optional()});function Dke(e){if(e!=null)try{let t=Eke.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function Oke(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=q8(o,n,r,kke(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 kke(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function Ake(e){let t=e?.outputs.find(e=>e.selected&&e.available&&e.state===`ready`&&e.output.stageKind===`video`&&e.output.role===`video`)??e?.outputs.find(e=>e.selected&&e.available&&e.state===`ready`&&e.output.role===`audio_export`);return t===void 0?void 0:t.recordId}function Y8(e){let{api:t}=B(),n=Ake(e),r=n===void 0||e===void 0?void 0:dB(t,e.revision.projectId,e.revision.id,n),i=(0,m.useRef)(null),a=(0,m.useRef)(void 0),[o,s]=(0,m.useState)(),c=(0,m.useCallback)(()=>{i.current?.pause(),a.current=void 0,s(void 0)},[]);(0,m.useEffect)(()=>c,[c]);let l=(0,m.useCallback)((e,t,n)=>{let r=i.current;r!==null&&(r.currentTime=Math.max(0,e),a.current=t,s(n),r.play().catch(()=>{a.current=void 0,s(void 0)}))},[]);return{element:r===void 0?null:(0,h.jsx)(`audio`,{ref:i,src:r,preload:`none`,hidden:!0,onTimeUpdate:e=>{a.current!==void 0&&e.currentTarget.currentTime>=a.current&&c()},onEnded:c,onPause:()=>{a.current===void 0&&s(void 0)}}),play:r===void 0?void 0:l,stop:c,playing:o}}var jke=6;function Mke({audition:e,clip:t}){let n=e.play;if(n===void 0)return null;let r=String(t.number),i=`short-${r}`,a=`short-${r}-end`,o=(r,i)=>e.playing===r?e.stop():n(i,t.end,r);return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,"aria-label":e.playing===i?`Stop short ${r}`:`Play short ${r}`,onClick:()=>o(i,t.start),children:e.playing===i?`Stop`:`Play the clip`}),(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,"aria-label":e.playing===a?`Stop the ending of short ${r}`:`Hear the ending of short ${r}`,onClick:()=>o(a,Math.max(t.start,t.end-jke)),children:e.playing===a?`Stop`:`Hear the ending`}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:`From the finished video, as the range is set now`})]})}function X8(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:XW(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]??``:XW(n,e.config.values)]))}}}}function Nke(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:Xk(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function Z8(e,t,n){return X8({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}var Q8=`shorts:pick`,$8=e=>`shorts:${String(e)}`;function e5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],Q8])]}}function t5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],$8(t)])]}}function Pke(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=Dke(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function Fke({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??_E,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Uce(o)}),l=[...n,...n5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...n5(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(Q8)===!0,f=Pke(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(TL,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(Ike,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)($4,{settings:CL(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?zke(n,e):Z8(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=yE(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)(Lke,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function Ike({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)(z,{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)(p8,{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 Lke({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=Y8(t),l=t.revision.config.shorts,u=i||l===void 0||l.count!==r.count||l.minSeconds!==r.minSeconds||l.maxSeconds!==r.maxSeconds||(l.prompt??``)!==(r.prompt??``),d=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),f=n.picked.sentences??[],p=n.picked.durationSeconds??f.at(-1)?.end??0,g=n.picked.shorts.map(e=>{let t=d[String(e.number)],n=t===void 0?void 0:q8(f,t.first,t.last,p);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),_=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=d,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:u,...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)(H,{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)(z,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==Q8)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{type:`button`,onClick:()=>o(e5(e)),children:`Pick different moments`}),(0,h.jsx)(H,{id:`project.shorts.pick-again`})]})]}),u&&!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,c.element,(0,h.jsx)(`ol`,{className:`space-y-3`,children:g.map(t=>(0,h.jsx)(Rke,{clip:t,audition:c,picked:n.picked,adjusted:d[String(t.number)]!==void 0,locked:u,remade:e.regenerate?.includes($8(t.number))===!0,problem:(()=>{let e=d[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):Oke(n.picked,t.number,e.first,e.last,r,g)})(),onRange:(e,n)=>_(t,e,n),onRemake:n=>o(n?t5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==$8(t.number))})},t.number))})]})}function Rke({clip:e,audition:t,picked:n,adjusted:r,locked:i,remade:a,problem:o,onRange:s,onRemake:c}){let l=(0,m.useId)(),u=n.sentences??[],[d,f]=(0,m.useState)(!1),p=String(e.number),g=e=>u[e-1]?.text??``,_=(e,t,n,r)=>(0,h.jsx)(z,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${p}`,disabled:i||!r,onClick:()=>s(t,n),children:e.split(` `)[0]}),v=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${l}-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:`${l}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,p,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(v),` s`,r?` · set by hand`:``]})]}),u.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: “`,g(e.first),`”`]}),_(`Earlier start`,e.first-1,e.last,e.first>1),_(`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: “`,g(e.last),`”`]}),_(`Earlier end`,e.first,e.last-1,e.last>e.first),_(`Later end`,e.first,e.last+1,e.last<u.length)]}),d?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(iL,{id:`${l}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(sL,{value:String(e[t]),disabled:i,onChange:n=>{let r=Number(n.target.value);s(t===`first`?r:e.first,t===`last`?r:e.last)},children:u.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]}),(0,h.jsx)(Mke,{audition:t,clip:e}),o===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:o}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u.length===0?null:(0,h.jsx)(z,{type:`button`,variant:`quiet`,disabled:i,onClick:()=>f(!d),children:d?`Hide the sentence lists`:`Use my own range`}),r?(0,h.jsx)(z,{type:`button`,variant:`quiet`,disabled:i,onClick:()=>{let t=n.shorts.find(t=>t.number===e.number);t!==void 0&&s(t.first,t.last)},children:`Back to the AI's choice`}):null,a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,p,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(z,{type:`button`,variant:`quiet`,onClick:()=>c(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{type:`button`,disabled:i,onClick:()=>c(!0),children:`Make this short again`}),(0,h.jsx)(H,{id:`project.shorts.remake`})]})]})]})}function n5(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 zke(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return X8({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var Bke=J({shorts:q(J({number:K(),first:K().optional(),last:K().optional(),start:K(),end:K(),title:G(),description:G(),hashtags:q(G())}))});function Vke({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=W3(n,e),a=G3(i,`shorts`),o=a5(i),s=E6(t.id),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=r5(i,`short_video`,o),p=t.config.shorts,g=K8(t.id),_=p?.fullVideoLink??_ke(g.data),v=(0,m.use)(t8),y=(0,m.use)(n8);if(p?.enabled!==!0&&a===void 0&&f.length===0)return null;let b=v&&y!==void 0&&p?.enabled===!0,x=e=>{let t=zce(e,_),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)(x6,{files:o.map(e=>({output:f.find(t=>i5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:f.length===1?`Download the short`:`Download`,zip:{set:`shorts`,members:f},children:b&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...Ny,children:[(0,h.jsx)(z,{onClick:()=>y({section:`shorts`,change:e5}),children:`Pick different moments`}),(0,h.jsx)(H,{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.jsxs)(h.Fragment,{children:[f.length===0?null:(0,h.jsx)(Py,{checked:u,onChange:d,label:`Show what YouTube covers on a phone`,className:`self-start`}),(0,h.jsx)(nz,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(Hke,{clip:n,projectId:t.id,review:D6(s,{itemKey:`shorts:${String(n.number)}`}),video:f.find(e=>i5(e,n)),stills:r5(i,`short_image`,o).filter(e=>i5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:_,wanted:Hce(n.end-n.start,t.config.imageSeconds),state:e.state,failed:Gke(e.failureReason,n.number),ownDownload:f.length>1,onCopy:()=>x(n),safeZone:u,...b?{onRemake:()=>y({section:`shorts`,change:e=>t5(e,n.number)})}:{}},n.number))})]}),(0,h.jsx)(SR,{tone:c?.tone??`info`,children:c?.text})]})}function Hke({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d,safeZone:f}){let p=(0,m.useId)(),g=n6(r),_=n6(i[0]),v=i.length,y=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?v<a?`Making images · ${String(v)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${p}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&g!==void 0?(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(XR,{src:g.url,label:`Short ${String(e.number)}`,portrait:!0,..._===void 0?{}:{poster:_.url}},r.id),f?(0,h.jsx)(w3,{}):null]}):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:y})}):(0,h.jsx)(tz,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:y}),(0,h.jsx)(`h4`,{id:`${p}-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:xA(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)(Uke,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(j6,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Pv,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&g!==void 0?(0,h.jsx)(qO,{href:g.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Mv,{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)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(JO,{children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsx)(Mv,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(Hc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(XO,{align:`start`,children:(0,h.jsxs)(ZO,{onSelect:d,children:[(0,h.jsx)(ml,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function Uke({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)(tk,{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)(nl,{"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 r5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>i5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function i5(e,t){return e.meta.short===t.number}function a5(e){return Wke(w6(G3(e,`shorts`)).data)}function Wke(e){if(e===void 0)return[];try{let t=Bke.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function Gke(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function Kke({project:e,outputs:t,media:n,chapters:r,omissions:i}){let a=_8(t),{chunks:o,open:s}=g8(),c=e.config.voices,l=(0,m.useMemo)(()=>{let e=e8(c?.speakers);return a.map((t,r)=>({key:String(r),text:t.text,start:t.start,end:t.end,shownAt:t.start,media:n,speaker:e(t.speaker)}))},[a,n,c]),u=(0,m.useCallback)(e=>s?.(X6(Y6(o),e.text)),[s,o]),d=c?.format===`podcast`||c?.format===`interview`;return l.length===0&&r.length===0&&i.length===0?null:(0,h.jsxs)(h.Fragment,{children:[r.length===0?null:(0,h.jsx)(`nav`,{"aria-label":`Chapters`,className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:r.map(e=>(0,h.jsx)(o5,{seconds:e.start,media:n,label:e.title},`${String(e.start)}-${e.title}`))}),l.length===0?null:(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,open:d,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:d?`Conversation, turn by turn`:`Transcript`}),(0,h.jsx)(`p`,{className:`m-0 mt-2 mb-1 text-small text-ink-2`,children:c===void 0?`Press a line to play from there.`:`Press a line to play from there; each line names its speaker.`}),(0,h.jsx)(Q6,{lines:l,label:d?`Conversation`:`Transcript`,onFix:s===void 0?void 0:u,...d?{fixLabel:`Correct or remake this turn`}:{}})]}),i.length===0?null:(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 (`,i.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. Press a time to hear that moment before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:i.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(o5,{seconds:e.start,media:n}),` — `,e.text]},`${String(e.start)}-${e.text}`))})]})]})}function o5({seconds:e,media:t,label:n}){return(0,h.jsxs)(z,{variant:`quiet`,size:`small`,className:`gap-1 font-normal`,"aria-label":`Play from ${NR(e)}${n===void 0?``:`, ${n}`}`,onClick:()=>Z6(t.current,e),children:[(0,h.jsx)(`strong`,{className:`tabular-nums text-ink`,children:NR(e)}),n]})}function qke({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=B(),a=Iv(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=G3(W3(n,e),o?`audio_export`:`video`),c=W3(n,e),l=G3(c,`subtitles_srt`),u=G3(c,`subtitles_vtt`),d=G3(c,`youtube_description`),f=G3(c,`youtube_tags`),p=G3(c,`audio_mp3`),g=G3(c,`audio_m4b`),_=r5(c,`short_video`,a5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),v=n6(s),y=n6(Jke(n)),b=Yke(t.id,d,f,s?.durationMs??null),x=n6(u),S=s?.meta.subtitlesMode??t.config.subtitles?.mode,C=e.state===`running`,w=(0,m.useRef)(null),T=e=>{w.current=e},E=SA(e.progressCurrent??0,e.progressTotal??0);return sb({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 mB(i,{projectId:t.id,asset:D2(s),folder:v?.folder??null});e.opened||a(`${hB} ${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)(h6,{children:r}):(0,h.jsxs)(h6,{className:`p-0`,children:[C?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:hA(e,t.config)?`Preparing subtitles · ${String(SA(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(E)}%`:vA(_A(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)(v8,{ref:T,label:`Combined narration`,src:v?.url,marks:b},s.id):v===void 0?null:(0,h.jsx)(XR,{ref:T,src:v.url,label:`Generated video`,...y===void 0?{}:{poster:y.url},chapters:b,portrait:t.format===`9:16`,square:t.format===`1:1`,className:t.format===`9:16`?`max-w-[360px]`:t.format===`1:1`?`max-w-[640px]`:`max-w-[1100px]`,...S===`files`&&u&&x?{captions:{src:x.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(x6,{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:g,label:`Audiobook with chapters (.m4b)`},..._.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(C6,{children:[xA(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:Tce(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`||GT(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:GT(t.config.language)}),s===void 0?null:(0,h.jsx)(Kke,{project:t,outputs:n,media:w,chapters:b,omissions:s.meta.subtitleOmissions??[]}),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 Jke(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function Yke(e,t,n,r){let{api:i}=B(),a=w6(t).data,o=w6(n).data,s=F({queryKey:V.youtubeEdits(e),queryFn:()=>Us(i,e),enabled:t!==void 0});return a===void 0?[]:Xke(W8(U8(H8(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function Xke(e,t){return V8(e,t).text.split(`
|
|
313
313
|
`).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:U6(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function Zke(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(QDe,{...e});case`audio`:return(0,h.jsx)(NOe,{...e});case`images`:return(0,h.jsx)(lke,{...e});case`video`:return(0,h.jsx)(qke,{...e});case`document`:return(0,h.jsx)(LOe,{...e});case`research`:case`thumbnail`:return null}}J({summary:G(),chapters:q(J({start:Yw([G(),K()]),title:G()})),hashtags:q(G()),tags:q(G()),pinnedComment:G(),titles:q(G())});function s5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var c5=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`});function l5(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function Qke({projectId:e}){let{api:t}=B(),n=_(),r=Iv(),i=[`studio`,`project-releases`,e],a=F({queryKey:i,queryFn:()=>ms(t,e)}),[o,s]=(0,m.useState)({}),c=(F({queryKey:[`studio`,`releases`,`swap`,8],queryFn:()=>fs(t,8)}).data?.entries??[]).flatMap(t=>t.project===null||t.project.id===e?[]:[{id:t.project.id,title:t.project.title,at:t.at}]),[l,u]=(0,m.useState)(``),[d,f]=(0,m.useState)(``),p=I({mutationFn:({other:n})=>ps(t,e,n),onSuccess:(e,{other:t,undo:a})=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),n.invalidateQueries({queryKey:[`studio`,`project-releases`,t]}),f(``);let o=c.find(e=>e.id===t)?.title??`the other video`;a?r(`Swapped back: the times with ${o} are as they were.`,`success`):r(`Swapped release times with ${o}; each one's shorts moved with it.`,`success`,{label:`Undo`,run:()=>p.mutate({other:t,undo:!0})})},onError:e=>r(`The times weren't swapped: ${e.message} Pick the video under Swap with… and press Swap again.`,`error`)}),g=I({mutationFn:n=>hs(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),s(e=>{let{[t.short]:n,...r}=e;return r}),t.line!==void 0&&u(``),r(t.at===null?`Not scheduled: set its time in Studio yourself, or pick one here.`:`Saved the release time.`,`success`)},onError:e=>r(`The time wasn't saved: ${e.message}`,`error`)});if(a.data===void 0)return null;let{items:v,free:y,leadHours:b}=a.data;return v.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Release`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(U,{as:`h3`,size:`small`,title:`Release`,meta:`Upload and schedule each one at least ${String(b)} hours before it goes out.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:v.map(e=>{let t=e.short===0?`Long video`:`Short ${String(e.short)}`,n=o[e.short]??(e.at===null?``:l5(e.at)),r=n!==(e.at===null?``:l5(e.at)),i=!e.onYoutube&&e.uploadBy!==null&&Date.parse(e.uploadBy)<Date.now();return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,h.jsx)(`span`,{className:`w-[86px] shrink-0 text-small font-semibold`,children:t}),(0,h.jsx)(X,{"aria-label":`${t}: release`,type:`datetime-local`,className:`w-[210px]`,value:n,onChange:t=>{let n=t.currentTarget.value;s(t=>({...t,[e.short]:n}))}}),r?(0,h.jsx)(z,{type:`button`,size:`small`,disabled:n===``||g.isPending,onClick:()=>g.mutate({short:e.short,at:new Date(n).toISOString()}),children:`Save`}):null,e.short===0&&y.length>0?(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(sL,{"aria-label":`Take a free time of the posting plan`,className:`w-[230px]`,value:l,onChange:e=>u(e.currentTarget.value),options:[{value:``,label:`Free plan times…`},...y.map(e=>({value:e.longAt,label:c5.format(new Date(e.longAt))}))]}),(0,h.jsx)(z,{type:`button`,size:`small`,variant:`secondary`,disabled:l===``||g.isPending,onClick:()=>{let e=y.find(e=>e.longAt===l);e!==void 0&&g.mutate({short:0,at:e.longAt,line:e.row})},children:`Take this time`})]}):null,e.at!==null&&e.short===0&&c.length>0?(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(sL,{"aria-label":`Swap release times with another video`,className:`w-[260px]`,value:d,disabled:p.isPending,onChange:e=>f(e.currentTarget.value),options:[{value:``,label:`Swap with…`},...c.map(e=>({value:e.id,label:`${e.title.split(` | `)[0]??e.title} · ${c5.format(new Date(e.at))}`}))]}),(0,h.jsx)(z,{type:`button`,size:`small`,variant:`secondary`,disabled:d===``||p.isPending,onClick:()=>p.mutate({other:d,undo:!1}),children:`Swap`})]}):null,e.at!==null&&e.short===0?(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,disabled:g.isPending,onClick:()=>g.mutate({short:0,at:null}),children:`Not scheduled`}):null,(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.onYoutube?(0,h.jsx)(tk,{children:`✓ on YouTube`}):e.uploadBy===null?`No time yet`:i?(0,h.jsx)(tk,{tone:`failed`,children:`Late · upload now`}):`Ready to upload`})]},e.short)})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Every video's times are together in`,` `,(0,h.jsx)(pa,{to:`/calendar`,search:{tab:`releases`},children:`Calendar → Releases`}),`.`]})]})}function $ke({label:e,tip:t,value:n,draft:r,onDraft:i,note:a,links:o,disabled:s,multiline:c,placeholder:l,render:u,onSave:d,onUseGenerated:f,onKeepMine:p}){let g=(0,m.useId)(),_=i,[v,y]=(0,m.useState)(!1),b=r!==void 0,x=e.toLowerCase();return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...Ny,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:`${g}-label`,className:`sl-kicker text-ink-3`,children:e}),t===void 0?null:(0,h.jsx)(H,{id:t,label:x,className:`-my-1`})]}),n.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),n.edited&&!b?(0,h.jsx)(z,{type:`button`,variant:`quiet`,size:`small`,disabled:s,"aria-label":`Use the generated ${x}`,onClick:f,children:`Use generated`}):null,(0,h.jsxs)(z,{type:`button`,variant:`quiet`,size:`small`,disabled:s||b,"aria-label":`Edit ${x}`,onClick:()=>_(n.text),children:[(0,h.jsx)(ul,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),n.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)(z,{type:`button`,disabled:s||b,disabledReason:`Save or cancel your ${x} edit first, so your typing isn't lost.`,"aria-label":`Use the new generated ${x}`,onClick:f,children:`Use it`}),(0,h.jsx)(z,{type:`button`,disabled:s,"aria-label":`Keep my ${x}`,onClick:()=>p(n.text,n.pending??``),children:`Keep mine`}),(0,h.jsx)(z,{type:`button`,variant:`quiet`,"aria-expanded":v,"aria-label":`${v?`Hide`:`View`} the ${x} diff`,onClick:()=>y(e=>!e),children:v?`Hide diff`:`View diff`})]}),v?(0,h.jsx)(l0,{before:n.text,after:n.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),b?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${g}-edit`,className:`sr-only`,children:e}),c?(0,h.jsx)(oL,{id:`${g}-edit`,rows:e===`Chapters`?8:5,value:r,onChange:e=>_(e.currentTarget.value)}):(0,h.jsx)(X,{id:`${g}-edit`,value:r,onChange:e=>_(e.currentTarget.value)}),a===void 0?null:(0,h.jsx)(u5,{note:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(z,{type:`button`,variant:`primary`,disabled:s,onClick:()=>{d(r),_(void 0)},children:[`Save `,x]}),(0,h.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>_(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${g}-label`,className:R(`min-w-0 whitespace-pre-wrap break-words text-small`,n.text===``?`text-ink-3`:`text-ink`),children:n.text===``?l:u===void 0?(0,h.jsx)(d5,{text:n.text,links:o}):u(n.text)}),b||a===void 0?null:(0,h.jsx)(u5,{note:a})]})}function u5({note:e}){return(0,h.jsx)(`p`,{className:R(`m-0 text-small`,e.warn?`text-danger`:`text-ink-3`),children:e.text})}function d5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:bD(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 f5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function eAe({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:f5(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)(d5,{text:e,links:t})},n))})}var p5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},tAe={summary:`project.youtube.summary`,chapters:`project.youtube.chapters`,hashtags:`project.youtube.hashtags`,tags:`project.youtube.tags`,pinnedComment:`project.youtube.pinned-comment`,titles:`project.youtube.titles`};function nAe({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=B(),a=_(),o=W3(n,e),s=G3(o,`youtube_description`),c=G3(o,`youtube_tags`),l=G3(o,`youtube_pinned_comment`),u=G3(o,`youtube_titles`),d=w6(s).data,f=w6(c).data,p=w6(l).data,g=w6(u).data,v=(0,m.use)(r8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=F({queryKey:V.youtubeEdits(t.id),queryFn:()=>Us(i,t.id)}),T=F({queryKey:V.projectChannelLinks(t.id),queryFn:()=>Hs(i,t.id)}),[E,D]=(0,m.useState)(),[O,k]=(0,m.useState)({}),A=e=>t=>k(n=>{let{[e]:r,...i}=n;return t===void 0?i:{...i,[e]:t}}),j=Iv(),M=e=>a.setQueryData(V.youtubeEdits(t.id),e),ee=I({mutationFn:e=>Ws(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{M(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),N=(0,m.useRef)({});if(sb({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:ck.copyDescription,run:()=>N.current.description===void 0?j(`The description has not been written yet.`,`info`):N.current.description()}),sb({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>N.current.tags===void 0?j(`The tags have not been written yet.`,`info`):N.current.tags()}),sb({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>N.current.pinnedComment===void 0?j(`The pinned comment has not been written yet.`,`info`):N.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let te=d===void 0?void 0:H8(d,f??``,{pinnedComment:p,titles:g}),P=U8(te,w.data?.fields??{}),ne={...W8(P),...O},re=Ole(T.data?.links??[],w.data?.links??[]),ie=G3(o,`video`),ae=V8(ne.chapters,ie?.durationMs===null||ie?.durationMs===void 0?void 0:ie.durationMs/1e3),oe=fke(ae.adjustments),se=xD(mke({...ne,chapters:ae.text}),re),ce=xD(ne.tags,re),le=xD(ne.pinnedComment,re),ue=[...se.unknown,...ce.unknown,...le.unknown].filter((e,t,n)=>n.findIndex(t=>yD(t)===yD(e))===t),de=f5(ce.text),fe=te!==void 0,pe=le.text.trim()!==``,me=ne.titles.split(`
|
|
314
314
|
`).map(e=>e.trim()).filter(e=>e!==``),he=me.map(vR).find(e=>e!==void 0),ge=fe?yR(se.text):void 0,_e=bR(ne.hashtags),ve={...ge===void 0?{}:{summary:{text:ge,warn:!0}},..._e===void 0?{}:{hashtags:{text:_e,warn:_e.includes(`ignores`)}},...he===void 0?{}:{titles:{text:he,warn:!0}}},ye=e=>{let t=w.data?.fields[e],n=p5[e].toLowerCase();ee.mutate({field:e,edit:null,done:`The ${n} follows the generated text again.`},{onSuccess:()=>{t!==void 0&&j(`The ${n} follows the generated text again.`,`success`,{label:`Undo`,run:()=>ee.mutate({field:e,edit:{text:t.text,base:t.base},done:`Put your ${n} back.`})})}})},be=fe&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0,xe=(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`}),j(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),j(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),j(n,`error`)})};N.current=fe?{description:()=>xe(se.text,`description`),tags:()=>xe(ce.text,`tags`),...pe?{pinnedComment:()=>xe(le.text,`pinned comment`)}:{}}:{};let Se=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,Ce=(e,t)=>(0,h.jsx)($ke,{label:p5[e],tip:tAe[e],value:P[e],draft:O[e],onDraft:A(e),note:ve[e],links:re,disabled:!fe||ee.isPending,multiline:e!==`hashtags`,placeholder:fe&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again to have one written, or Edit to write your own.`:fe&&e===`titles`?`Written before other titles existed. Use Write again to have two written, or Edit to write your own, one per line.`:Se,render:t,onSave:t=>ee.mutate({field:e,edit:{text:t,base:te?.[e]??``},done:`Saved your ${p5[e].toLowerCase()}.`}),onUseGenerated:()=>ye(e),onKeepMine:(t,n)=>ee.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${p5[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)(m5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:fe?()=>xe(se.text,`description`):void 0,keyshortcuts:yb(ck.copyDescription),count:fe?`${String(se.text.length)} / ${String(mR)} characters`:void 0,over:se.text.length>mR,main:!0,again:be}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[Ce(`summary`),Ce(`chapters`,()=>ae.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(d5,{text:ae.text,links:re})),oe===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:oe}),Ce(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(m5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:fe?()=>xe(ce.text,`tags`):void 0,count:fe?`${String(s5(de))} / 500 characters`:void 0,over:s5(de)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:Ce(`tags`,e=>(0,h.jsx)(eAe,{text:e,links:re}))}),(0,h.jsx)(m5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:fe&&pe?()=>xe(le.text,`pinned comment`):void 0,count:fe&&pe?`${String(le.text.length)} / 500 characters`:void 0,over:le.text.length>500,again:be}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[Ce(`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)(m5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:fe&&me.length>0?()=>xe(me.join(`
|
|
315
|
-
`),`other titles`):void 0,count:fe&&me.length>0?`${String(me.length+1)} titles to test`:void 0,over:me.some(e=>e.length>100),again:be}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[Ce(`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.`})]})]})]}),ue.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${ue.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)(pa,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${ue.some(e=>yD(e)===yD(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(Qke,{projectId:t.id}),(0,h.jsx)(bke,{projectId:t.id,shorts:n.filter(e=>e.role===`short_video`).length}),(0,h.jsx)(rAe,{projectId:t.id,edits:w.data,onSaved:e=>{M(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(SR,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(Qv,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags, pinned comment and other titles. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function m5({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)(z,{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)(Nc,{"aria-hidden":`true`,strokeWidth:1.75,className:R(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:R(`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)(z,{type:`button`,variant:`secondary`,"aria-label":`Write the ${t.toLowerCase()} again`,onClick:s,children:[(0,h.jsx)(ml,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(z,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function rAe({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=B(),a=(0,m.useId)(),o=t?.links.find(e=>yD(e.name)===yD(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=I({mutationFn:()=>{let n=(t?.links??[]).filter(e=>yD(e.name)!==yD(_D));return Gs(i,e,l.trim()===``?n:[...n,{name:_D,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]`,...Ny,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)(H,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(X,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(z,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var h5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function iAe({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=B(),[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=h5.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 xCe(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:`${xo(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`,...Ny,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(H,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),h5.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)(z,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(z,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var g5=e=>e.charAt(0).toUpperCase()+e.slice(1);function aAe(e){return e.revisionId===null?null:(0,h.jsx)(oAe,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function oAe({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=B(),o=_(),s=F({queryKey:u2(e,t),queryFn:()=>f2(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)(z,{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)(U,{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)(iAe,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(u2(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:V.project(e)}),o.invalidateQueries({queryKey:V.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(sAe,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,current:a.revisionId===t,...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 sAe({gate:e,disabled:t,reload:n,current:r,inRail:i=!1}){let{api:a}=B(),o=_(),s=(0,m.useRef)(null),c=(0,m.useRef)(!1),l=(0,m.useRef)(!0),u=(0,m.useRef)(null),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(null);(0,m.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]),(0,m.useEffect)(()=>{p!==null&&u.current?.focus()},[p]);let v=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function y(){if(!(c.current||t||!v||p?.kind===`refused`||p?.kind===`success`)){c.current=!0,f(!0),s.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await p2(a,e.projectId,e.checkpointId,s.current);s.current=null,l.current&&g(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}),o.invalidateQueries({queryKey:l2(e.projectId)}),o.invalidateQueries({queryKey:V.project(e.projectId)}),o.invalidateQueries({queryKey:V.projects})}catch(e){l.current&&g({kind:`transport`,message:`${xo(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{c.current=!1,l.current&&f(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(U,{as:`h3`,title:`${g5(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.`:v?`${g5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,title:`Version ${e.revisionId}`,children:r?`Applies to the project as it is now.`:`Set on an earlier version. Reload checkpoints to see the current one.`}),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:g5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),p?(0,h.jsx)(`p`,{ref:u,tabIndex:-1,role:p.kind===`success`?`status`:`alert`,className:p.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:p.message}):null,v&&i&&p===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.`}):v?(0,h.jsx)(z,{className:`self-start`,disabled:t||d||p?.kind===`refused`||p?.kind===`success`,onClick:()=>void y(),children:d?`Approving…`:p?.kind===`transport`?`Retry approval`:`Approve ${g5(e.stage)} checkpoint`}):null,p?.kind===`refused`?(0,h.jsx)(z,{className:`self-start`,onClick:async()=>{await n()&&g(null)},children:`Reload checkpoints`}):null]})}function cAe({projects:e,queryKey:t}){let{api:n}=B(),r=_(),i=Iv(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=I({mutationFn:e=>Ho(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${v5(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)(H,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(KL,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(qL,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[v5(e.bytes),` · outputs `,v5(e.outputsBytes),` · working files `,v5(e.workingBytes)]}),actions:(0,h.jsx)(z,{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 ${v5(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)(Qv,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:_5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,cancelLabel:`Keep everything`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function _5(e,t){return`This removes ${String(e)} working file(s) and frees ${v5(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.`}var v5=F2,y5=e=>[`storage`,`project`,e];function lAe({projectId:e,title:t,status:n,sample:r}){let{api:i}=B(),a=_(),o=Iv(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=F({queryKey:[...y5(e),n],queryFn:()=>Vo(i,e),enabled:l&&!r}),d=I({mutationFn:()=>Ho(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${v5(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:y5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:V.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=v5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:`Free space`,meta:`Outputs ${v5(f.outputsBytes)} · working files ${v5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(z,{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)(Qv,{open:s,title:`Free ${p} from "${t}"?`,consequence:_5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function uAe({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=e.status===`pending`&&e.setAside===!0?IL:FL[e.status],c=bde();return(0,h.jsx)(fG,{crumb:(0,h.jsxs)(pa,{to:c.to,search:c.search,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),c.label]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[pAe(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(ek,{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&&dAe(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(H,{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)(z,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(yl,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(JO,{modal:!1,children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsx)(Mv,{label:`More project actions`,children:(0,h.jsx)(Hc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(XO,{children:i.map(e=>(0,h.jsx)(fAe,{item:e},e.id))})]})]})})}function dAe(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function fAe({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(QO,{}):null,(0,h.jsx)(ZO,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function pAe(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:YE(a),i,e.format,`started ${vd(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function mAe({projectId:e}){let{api:t}=B(),n=F(vy(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)(yAe,{cost:n.data}):(0,h.jsx)(dM,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var hAe=new Set([`done`,`partial`,`failed`,`canceled`]);function gAe({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=t===`running`,a=r?.current===!0&&!hAe.has(t),[o,s]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[i]),!a||r===null)return null;let c=r.workingMs+(i?Math.max(0,o-n):0),l=i?wAe(c):k5(c);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:i?`inline-flex items-center gap-1.5 rounded-full bg-accent/15 px-2.5 py-0.5 font-semibold text-ink tabular-nums`:`inline-flex items-center gap-1.5 rounded-full bg-surface-2 px-2.5 py-0.5 font-semibold text-ink-2 tabular-nums`,children:[(0,h.jsx)(bl,{"aria-hidden":`true`,strokeWidth:2,className:`size-3.5 shrink-0`}),i?`Working · ${l}`:`${l} of work so far`]})]})}var _Ae=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:pA[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:x5},{id:`api`,header:`Via API`,numeric:!0,cell:S5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>C5(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:k5(e.wallMs)}],vAe=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:SAe(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:x5},{id:`api`,header:`Via API`,numeric:!0,cell:S5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>C5(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>w5.format(e.calls)}];function b5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function yAe({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)(z$,{children:[(0,h.jsx)(B$,{value:O5(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(B$,{value:`~${O5(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${b5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${T5.format(t.usedPercent)}%`;return(0,h.jsx)(B$,{value:r,label:`of ${n}`,children:(0,h.jsx)(V$,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${T5.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(B$,{value:k5(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 ${D5(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:bAe(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:xAe(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(U,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(H$,{caption:`Run cost by stage`,columns:_Ae,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(U,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(H$,{caption:`Run cost by model`,columns:vAe,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: ${C5(e.totals)||`no reported usage`} · ${k5(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 bAe(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 ${D5(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${O5(t)} via API${n}.`}function xAe(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=b5(t.kind),r=t.usedPercent<1?`under 1%`:`~${T5.format(t.usedPercent)}%`,i=`now at ${T5.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${TAe(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 x5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${O5(e.cost)} + unknown`:O5(e.cost)}function S5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${O5(e.apiEquivalent)}`}function SAe(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function C5(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${E5(e.tokensIn)} in / ${E5(e.tokensOut)} out tokens${e.cachedTokens>0?` (${E5(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${E5(e.characters)} characters`),e.images>0&&t.push(D5(e.images,`image`)),e.seconds>0&&t.push(`${w5.format(e.seconds)} s of video`),t.join(` · `)}var w5=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),T5=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),CAe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function E5(e){return e<1e4?w5.format(e):CAe.format(e)}function D5(e,t){return`${w5.format(e)} ${t}${e===1?``:`s`}`}var O5=P2;function wAe(e){let t=Math.max(0,Math.floor(e/1e3)),n=e=>String(e).padStart(2,`0`);return`${String(Math.floor(t/3600))}:${n(Math.floor(t%3600/60))}:${n(t%60)}`}function k5(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 TAe(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function EAe({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)(m2);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)(U,{title:`Article`}),a?.state===`running`?(0,h.jsx)(j2,{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)(z,{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)(U,{title:`Narration`}),(0,h.jsx)(OAe,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(U,{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)(nz,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(DAe,{output:t,aspect:N8(e.format)},t.id))})]})})}function DAe({output:e,aspect:t}){let n=n6(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)(tz,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function OAe({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=n6(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(A5,{projectId:e,revisionId:t}),(0,h.jsx)(R6,{projectId:e})]}):a===void 0?(0,h.jsx)(A5,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)(v8,{label:`Body narration`,src:a.url})})}var kAe=240;function A5({projectId:e,revisionId:t}){let{api:n}=B(),r=F({queryKey:ty(e,t),queryFn:()=>py(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/kAe)),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: ${k5(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.`:`${k5(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function AAe({projectId:e,title:t,open:n,onClose:r}){let{api:i}=B(),a=_(),o=Iv(),s=ib(),[c,l]=(0,m.useState)(``),u=I({mutationFn:()=>Po(i,[e],c),onSuccess:()=>{a.invalidateQueries({queryKey:V.projects}),o(`Moved "${t}" to ${s.channels.find(e=>e.id===c)?.name??`the channel`}.`,`success`),r()},onError:e=>o(`The project wasn't moved: ${e.message}`,`error`)});return(0,h.jsx)(Zv,{open:n,onOpenChange:e=>{e||r()},title:`Move to channel`,description:`The project shows in that channel's list and uses its brand and playlists. Nothing it made changes.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{type:`button`,variant:`quiet`,onClick:r,children:`Cancel`}),(0,h.jsx)(z,{type:`button`,disabled:c===``||u.isPending,onClick:()=>u.mutate(),children:`Move`})]}),children:(0,h.jsx)(iL,{label:`Channel`,children:(0,h.jsx)(sL,{value:c,onChange:e=>l(e.currentTarget.value),options:[{value:``,label:`Choose a channel`},...s.channels.map(e=>({value:e.id,label:e.name}))]})})})}function jAe({projectId:e,revisionId:t,config:n,controller:r,onClose:i}){let{api:a}=B(),o=_(),s=a6.flatMap(e=>{let t=dDe(n,e);return!t.ok&&t.reason===`already`?[]:[{kind:e,refusal:t.ok?void 0:t.message}]}),[c,l]=(0,m.useState)(s.find(e=>e.refusal===void 0)?.kind),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[g,v]=(0,m.useState)(),y=(0,m.useRef)(void 0),b=s.find(e=>e.kind===c)?.refusal,x=F({queryKey:[`project`,e,`add-output`,t,c??``],enabled:c!==void 0&&b===void 0,staleTime:0,queryFn:async()=>{if(c===void 0)throw Error(`Choose an output to add.`);let n=await SDe(a,e,{baseRevisionId:t,kind:c});if(!n.ok)throw Error(n.message);return n.value}}),S=x.data,C=S!==void 0&&S.problems.length>0,w=async()=>{if(c!==void 0&&S!==void 0){d(!0),v(void 0);try{y.current?.kind!==c&&(y.current={kind:c,id:crypto.randomUUID()});let n=await CDe(a,e,{baseRevisionId:t,kind:c,idempotencyKey:y.current.id,...S.adapts?{adapt:f}:{}});if(!n.ok){v(n.message);return}await o.invalidateQueries({queryKey:V.project(e)}),i(),n.value.workKeys.length>0&&r.review({kind:`selected`,workKeys:n.value.workKeys},{autoStart:!0,approvedUpTo:S.estimate.unknown===0?S.estimate.high:void 0})}catch(e){v(e instanceof Error?e.message:String(e))}finally{d(!1)}}},T=c===void 0?`output`:o6[c].replace(/ \(.*\)$/,``);return(0,h.jsxs)(Zv,{open:!0,onOpenChange:e=>{!e&&!u&&i()},title:`Add another output`,description:`Made from this project's brief, sources and accepted text. What it already has stays as it is.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(SR,{tone:g===void 0?`info`:`error`,children:g??(x.error===null?void 0:x.error.message)}),(0,h.jsx)(z,{variant:`secondary`,disabled:u,onClick:i,children:`Cancel`}),(0,h.jsx)(z,{variant:`primary`,disabled:u||S===void 0||C||b!==void 0||c===void 0||S.adapts&&!f,disabledReason:u?`Adding it`:C?`Set the missing choices in Settings first`:S?.adapts===!0&&!f?`Tick Adapt my article into a conversation first`:`Choose an output it can add`,onClick:()=>void w(),children:`Add ${T.toLowerCase()}`})]}),children:[(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 border-0 p-0`,children:[(0,h.jsx)(`legend`,{className:`sl-kicker mb-1`,children:`Output`}),s.map(e=>(0,h.jsxs)(`label`,{className:`flex items-start gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`radio`,name:`added-output`,className:`mt-1`,checked:c===e.kind,onChange:()=>{l(e.kind),p(!1),v(void 0)}}),(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:o6[e.kind]}),e.refusal===void 0||c!==e.kind?null:(0,h.jsx)(`span`,{className:`block text-ink-2`,children:e.refusal})]})]},e.kind))]}),S===void 0||b!==void 0?x.isFetching?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Working out what it needs…`}):null:(0,h.jsxs)(F6,{label:`What adding ${T.toLowerCase()} does`,children:[(0,h.jsx)(I6,{label:`Reused as it is`,children:S.reused.join(`, `)}),(0,h.jsx)(I6,{label:`Made new`,children:S.created.join(`, `)}),(0,h.jsx)(I6,{label:`Your text`,children:S.textUse}),(0,h.jsx)(I6,{label:`Estimated extra cost`,children:MAe(S.estimate)})]}),S?.adapts===!0&&b===void 0?(0,h.jsxs)(`label`,{className:`flex items-start gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,checked:f,onChange:e=>p(e.target.checked)}),(0,h.jsx)(`span`,{children:`Adapt my article into a conversation (the article itself stays as it is)`})]}):null,S!==void 0&&C?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5 text-small text-danger`,children:S.problems.map(e=>(0,h.jsx)(`li`,{children:e.message},e.field))}),(0,h.jsx)(z,{variant:`secondary`,className:`self-start`,onClick:()=>{let e=S.config;i(),r.requestEdit({section:NAe(S.problems[0]?.field??``),change:t=>({...t,config:e})})},children:`Open Settings with ${T.toLowerCase()} switched on`})]}):null]})}function MAe(e){let t=e.low===e.high?i8(e.high):`${i8(e.low)}–${i8(e.high)}`;return e.unknown>0?e.high===0?`Unknown: ${String(e.unknown)} ${e.unknown===1?`step has`:`steps have`} no price yet. The remake review shows the rest before anything is charged.`:`About ${t}, plus ${String(e.unknown)} ${e.unknown===1?`step`:`steps`} with no price yet.`:e.high===0?e.rows.some(e=>e.onPlan===!0)?`$0 on your CLI plan; it uses some of the plan's limits.`:`No extra charge: it runs on this computer.`:`About ${t}.`}function NAe(e){return e.startsWith(`imagePrompts`)||e.endsWith(`Prompt`)?`prompts`:e.startsWith(`audio`)||e.startsWith(`voices`)||e.startsWith(`images`)||e.startsWith(`llm`)?`providers`:`inputs`}function PAe({projectId:e,revisionId:t,config:n,stages:r,outputs:i,controller:a}){let o=t6(),[s,c]=(0,m.useState)(!1),l=PDe({config:n,stages:r,outputs:i,states:new Map((o?.outputs??[]).filter(e=>e.selected).map(e=>[e.output.id,e.available?e.state:`missing`]))});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`What this project makes, with each file's state and its downloads.`}),(0,h.jsxs)(z,{variant:`secondary`,disabled:t===null||a.busy,disabledReason:t===null?`This project has no saved version yet; wait for its first step to start`:`Finish or close the open edit or remake first`,onClick:()=>c(!0),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,strokeWidth:1.75}),`Add another output`]})]}),(0,h.jsx)(KL,{label:`Outputs`,children:l.map(t=>(0,h.jsx)(FAe,{projectId:e,row:t},t.kind))}),s&&t!==null?(0,h.jsx)(jAe,{projectId:e,revisionId:t,config:n,controller:a,onClose:()=>c(!1)}):null]})}function FAe({projectId:e,row:t}){return(0,h.jsx)(qL,{lead:(0,h.jsx)(BAe,{kind:t.kind,output:t.main}),title:t.title,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ek,{tone:t.tone,children:t.stateWords}),t.version===void 0?null:(0,h.jsx)(`span`,{children:` · ${t.version}`})]}),actions:(0,h.jsxs)(Pv,{children:[t.set===void 0?null:(0,h.jsx)(m6,{projectId:e,set:t.set.set,members:t.set.members,variant:`secondary`}),t.primary===void 0?null:(0,h.jsx)(IAe,{file:t.primary,older:t.state===`older`}),t.alternatives.length===0?null:(0,h.jsx)(LAe,{files:t.alternatives})]}),children:(0,h.jsx)(GO,{to:`/projects/$projectId`,params:{projectId:e},search:{section:t.section},resetScroll:!1,className:`text-small`,children:t.next})})}function IAe({file:e,older:t}){let n=n6(e.output);return n===void 0?null:(0,h.jsxs)(KO,{href:n.url,download:!0,variant:`secondary`,title:t?`${e.label}, the previous version`:e.label,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),t?`${e.label} · previous version`:e.label]})}function LAe({files:e}){return(0,h.jsxs)(JO,{modal:!1,children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,children:[`Other formats`,(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(XO,{children:e.map(e=>(0,h.jsx)(RAe,{file:e},e.output.id))})]})}function RAe({file:e}){let t=n6(e.output);return t===void 0?null:(0,h.jsx)(ZO,{asChild:!0,children:(0,h.jsxs)(`a`,{href:t.url,download:!0,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),e.label]})})}var zAe={article:(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),narration:(0,h.jsx)(sl,{"aria-hidden":`true`,strokeWidth:1.75}),voices:(0,h.jsx)(sl,{"aria-hidden":`true`,strokeWidth:1.75}),images:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75}),thumbnails:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75}),video:(0,h.jsx)(Tl,{"aria-hidden":`true`,strokeWidth:1.75}),shorts:(0,h.jsx)(Tl,{"aria-hidden":`true`,strokeWidth:1.75}),pdf:(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75})};function BAe({kind:e,output:t}){let n=n6(t),r=t!==void 0&&(t.role===`image`||t.role===`thumbnail`);return(0,h.jsx)(`span`,{className:`flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-control bg-sunken text-ink-2`,children:r&&n!==void 0?(0,h.jsx)(`img`,{src:n.url,alt:``,className:`size-full object-cover`,loading:`lazy`}):t?.durationMs!==null&&t?.durationMs!==void 0?(0,h.jsx)(`span`,{className:`text-small tabular-nums`,children:VAe(t.durationMs)}):zAe[e]})}function VAe(e){let t=Math.round(e/1e3),n=Math.floor(t/60);return n>=60?`${String(Math.floor(n/60))}h ${String(n%60).padStart(2,`0`)}m`:`${String(n)}:${String(t%60).padStart(2,`0`)}`}function HAe({cues:e,duration:t,onChange:n,onPending:r,audition:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(r);f.current=r,(0,m.useEffect)(()=>{f.current(u)},[u]),(0,m.useEffect)(()=>()=>f.current(!1),[]);function p(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){l(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,a]of o.entries()){let o=a.start.trim()===``?NaN:Number(a.start),s=a.end.trim()===``?NaN:Number(a.end);if(r.has(a.id)){l(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(a.id),!Number.isFinite(o)||o<0||o<i){l(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=o||s>t){l(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(a.text.trim()===``){l(`Caption ${n+1}: enter caption text.`);return}e.push({id:a.id,text:a.text,start:o,end:s,...a.speaker===void 0?{}:{speaker:a.speaker}}),i=s}n(e),l(void 0),d(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...Ny,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(H,{id:`project.captions.editor`})]}),o.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]}),i?.play===void 0?null:(0,h.jsx)(UAe,{audition:i,id:e.id,number:t+1,start:Number(e.start),end:Number(e.end)}),(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(oL,{id:`${a}-${e.id}-text`,value:e.text,onChange:n=>{d(!0),s(o.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(X,{id:`${a}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{d(!0),s(o.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(X,{id:`${a}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{d(!0),s(o.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:c}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{type:`button`,onClick:p,children:`Apply caption edits to draft`}),(0,h.jsx)(H,{id:`project.captions.apply`})]}),u?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function UAe({audition:e,id:t,number:n,start:r,end:i}){let a=e.playing===t;return(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,disabled:!(Number.isFinite(r)&&Number.isFinite(i)&&i>r&&r>=0),disabledReason:`Enter a start and an end in seconds to play this caption`,"aria-label":a?`Stop caption ${String(n)}`:`Play caption ${String(n)}`,onClick:()=>a?e.stop():e.play?.(r,i,t),children:a?`Stop`:`Play`})}function j5(e){return`imagePrompts.${String(e)}`}function M5(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function WAe(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function GAe(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))M5(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))M5(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=j5(t),l=i[t]??-1;if(l>=0){let t=j5(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]=XW(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=M5(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=j5(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=M5(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===j5(s)?a:{...a,templateKey:j5(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 KAe({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)(T4,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(qAe,{edit:e,saved:t,prompts:o,problem:r})]})}function qAe({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(WAe(t,i))return a===void 0?null:(0,h.jsx)(N5,{children:a});let o=0,s=GAe({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)(N5,{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)(N5,{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 N5({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function JAe({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:TE(r)),o=r?.source===`upload`?[...bE,`upload`]:bE,s=i===void 0?[]:[...ZAe(i)];return(0,h.jsx)(f$,{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=EE(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function YAe({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...QT,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(e3,{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 XAe({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=o3(r[e]);return t===void 0?`Enter a number of seconds.`:lE(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(a3,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=o3(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function ZAe(e){let t=EE(e);return t===void 0?[]:CE(t)}function QAe({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:hce(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(qT(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=P5(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:ZT(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:P5(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(KT)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(JT(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`,...Ny,children:[(0,h.jsx)(Py,{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)(Fy,{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:$Ae(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(X,{"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 P5(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?YT(t):void 0:t>=1&&t<=240?t:void 0}function $Ae(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 eje({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`,...Ny,children:(0,h.jsx)(Py,{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 tje({edit:e,view:t,imageKey:n,index:r}){let{api:i}=B(),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)(XR,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:dB(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(tz,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:dB(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}var F5=e=>t=>t.destination.kind===`image`&&t.destination.imageKey===e;function nje(e,t){let{content:n}=e,r=n.imageDefinitions[t],i=n.imageOrder.indexOf(t),a=n.imageOrder.filter(e=>e!==t);return{next:{...e,config:a.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...n,imageOrder:a,imageDefinitions:Object.fromEntries(Object.entries(n.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>!F5(t)(e))},removed:r===void 0||i===-1?void 0:{key:t,index:i,definition:r,uploads:(e.uploads??[]).filter(F5(t)),regenerate:e.regenerate?.includes(`image:${t}`)===!0,sources:e.config.sources}}}function rje(e,t){if(e.content.imageOrder.includes(t.key))return;let n=[...e.content.imageOrder];return n.splice(Math.min(t.index,n.length),0,t.key),{...e,config:{...e.config,sources:n.length===1?t.sources:e.config.sources},content:{...e.content,imageOrder:n,imageDefinitions:{...e.content.imageDefinitions,[t.key]:t.definition}},uploads:[...e.uploads??[],...t.uploads],regenerate:t.regenerate?[...new Set([...e.regenerate??[],`image:${t.key}`])]:e.regenerate}}function ije({imageKey:e,children:t}){let n=(0,m.useRef)(null);return f8(`image:${e}`,n),(0,h.jsx)(`fieldset`,{ref:n,tabIndex:-1,className:`space-y-2 rounded-control border border-line-strong p-3`,children:t})}function I5(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 aje({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),[c,l]=(0,m.useState)(),{content:u}=e,d=mce(e.config),f=(0,m.useRef)(e);f.current=e;function p(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`}:{}}}};f.current=i,t(i)}function g(e,t){let n=i?.()??f.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})),p(Z8({...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 _(e){let t=i?.()??f.current,n=t.content,r=crypto.randomUUID();p({...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}}]})}function v(){let e=c;l(void 0);let t=e===void 0?void 0:rje(i?.()??f.current,e);t!==void 0&&p(t)}let y=c===void 0?null:(0,h.jsxs)(`p`,{role:`status`,className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[`Image `,c.index+1,` is deleted from this draft; it goes when you save.`,(0,h.jsx)(z,{type:`button`,variant:`quiet`,size:`small`,onClick:v,children:`Undo`})]});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)(H,{id:`project.images.editor`})]}),u.imageOrder.map((t,s)=>{let d=u.imageDefinitions[t];return d===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(m.Fragment,{children:[c?.index===s?y:null,(0,h.jsxs)(ije,{imageKey:t,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(tje,{edit:e,view:r,imageKey:t,index:s}),d.source===`generate`?(0,h.jsxs)(`div`,{...Ny,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)(H,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(oL,{id:`${a}-${t}-prompt`,value:d.templateKey===void 0||d.templateKey===null?d.prompt??``:u.promptTemplates[d.templateKey]??d.prompt??``,onChange:e=>g(t,e.target.value)})]}):null,d.source===`generate`&&d.templateKey==null?(0,h.jsxs)(z,{type:`button`,onClick:()=>g(t,d.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(p8,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??f.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&p({...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)(z,{type:`button`,disabled:s===0,onClick:()=>p({...e,content:{...u,imageOrder:I5(u.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(z,{type:`button`,disabled:s===u.imageOrder.length-1,onClick:()=>p({...e,content:{...u,imageOrder:I5(u.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(z,{type:`button`,onClick:()=>{let{next:n,removed:r}=nje(e,t);l(r),p(n)},children:[`Delete image `,s+1,u.imageOrder.length===1?` and turn Images and Video Off`:``]}),d.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(z,{type:`button`,onClick:()=>p({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(z,{type:`button`,onClick:()=>p({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(H,{id:`project.images.regenerate`})]}):null]})]},t)}),c!==void 0&&c.index>=u.imageOrder.length?y:null,(0,h.jsx)(z,{type:`button`,disabled:u.imageOrder.length>=d,onClick:()=>{if(u.imageOrder.length>=d)return;let t=crypto.randomUUID();p({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...u,imageOrder:[...u.imageOrder,t],promptTemplates:{...u.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...u.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),u.imageOrder.length>=d?(0,h.jsxs)(`p`,{children:[`At most `,d,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(p8,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:_},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(p8,{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:_},`new-clip:${e.config.sources.images===`off`}`)]})]})}function oje(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(L5))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`)&&L5(e.output.durationMs))?.output.durationMs;return L5(s)?s/1e3:void 0}function L5(e){return e!=null&&Number.isFinite(e)&&e>0}function sje({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?W4:{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)(G4,{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:Z8(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(p8,{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 cje=J({words:q(J({text:G().trim().min(1),start:K().finite().nonnegative(),end:K().finite().positive(),confidence:K().optional(),speaker:G().min(1).optional()})).min(1)});function R5(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 lje({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=B(),s=F(Sy(o)).data?.prompts??[],c=R5(t),l=t.config.sources.audio!==`off`&&c===R5({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?oje(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,S]=(0,m.useState)(),C=Y8(e),w=(0,m.useRef)(void 0),T=(0,m.useRef)(!0),E=(0,m.useCallback)((e,t)=>{T.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)(()=>(T.current=!0,()=>{T.current=!1,w.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&w.current?.abort()}},[e.revision.id,c]);function D(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:R5(e)},t(e)}async function O(){if(w.current!==void 0)return;let t=new AbortController;w.current=t;let n=p.current;E(`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(dB(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=cje.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=B6(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!T.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;D({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){T.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{w.current===t&&(w.current=void 0),E(`captions:load`,!1)}}let k=t.content.subtitleCues,A=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[C.element,(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!A(`images`),className:`space-y-6`,children:[(0,h.jsx)(KAe,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:D}),(0,h.jsx)(QAe,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:D}),(0,h.jsx)(eje,{edit:t,onChange:D}),(0,h.jsx)(sje,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:D,onPending:e=>E(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(s3,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;D({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,(0,h.jsx)(WOe,{edit:t,getEdit:()=>p.current.edit,onChange:D,onPending:E}),[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(p8,{label:`Replace provided ${e}`,kind:e,onPending:t=>E(`provided:${e}`,t),onReady:t=>{let n=p.current;if(n.edit.config.sources[e]===`provide`){if(e===`thumbnail`){let e=C8(t.bytes);if(S(e),e!==void 0)return}D({...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),x===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}),(0,h.jsx)(aje,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:D,onPending:E})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!A(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(EOe,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:D,onPending:E}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!A(`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.`}),k===void 0?(0,h.jsx)(z,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void O(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[k.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)(HAe,{audition:C,cues:k.cues,duration:d,onPending:e=>E(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&D({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(z,{type:`button`,onClick:()=>D({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function uje({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(u$,{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}})}})})}var z5=5e5,B5=new Intl.NumberFormat(`en`);function dje({value:e,error:t,help:n,onChange:r}){let i=e.length-z5;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(iL,{label:`Article text`,tip:`project.edit.article-text`,error:t??(i>0?`The article is ${B5.format(i)} characters over the ${B5.format(5e5)} limit. Shorten it, then press Save changes; nothing was cut.`:void 0),help:n,children:(0,h.jsx)(oL,{rows:12,value:e,onChange:e=>r(e.target.value)})}),(0,h.jsx)(`p`,{className:`m-0 text-small tabular-nums ${i>0?`text-danger`:`text-ink-2`}`,children:`${B5.format(e.length)} of ${B5.format(z5)} characters`})]})}function fje({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=B(),a=F(Yy(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:Hy,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)(iL,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(pa,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(sL,{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)(Py,{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 PDF 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 pje(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=D3([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 mje({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)(H4,{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:Z8(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function V5(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function H5(e,t){return e===t||JSON.stringify(e)===JSON.stringify(t)}function U5(e,t,n){if(H5(e,t))return n;if(V5(e)&&V5(t)&&V5(n)){let r={};for(let i of new Set([...Object.keys(n),...Object.keys(t)])){let a=U5(e[i],t[i],n[i]);a!==void 0&&(r[i]=a)}return r}return t}function W5(e,t,n){return{...t,config:U5(e.config,t.config,n.config),content:U5(e.content,t.content,n.content)}}function G5(e,t,n,r){if(H5(e,t))return;if(V5(e)&&V5(t)){for(let i of new Set([...Object.keys(e),...Object.keys(t)]))G5(e[i],t[i],n===``?i:`${n}.${i}`,r);return}let i=t===void 0?`(removed)`:typeof t==`string`?t:JSON.stringify(t,null,2);r.push(`${n}:\n${i}`)}function hje(e,t){let n=[];return G5(e.config,t.config,`config`,n),G5(e.content,t.content,`content`,n),(t.regenerate?.length??0)>0&&n.push(`Marked to make again:\n${(t.regenerate??[]).join(`
|
|
315
|
+
`),`other titles`):void 0,count:fe&&me.length>0?`${String(me.length+1)} titles to test`:void 0,over:me.some(e=>e.length>100),again:be}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[Ce(`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.`})]})]})]}),ue.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${ue.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)(pa,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${ue.some(e=>yD(e)===yD(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(Qke,{projectId:t.id}),(0,h.jsx)(bke,{projectId:t.id,shorts:n.filter(e=>e.role===`short_video`).length}),(0,h.jsx)(rAe,{projectId:t.id,edits:w.data,onSaved:e=>{M(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(SR,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(Qv,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags, pinned comment and other titles. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function m5({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)(z,{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)(Nc,{"aria-hidden":`true`,strokeWidth:1.75,className:R(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:R(`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)(z,{type:`button`,variant:`secondary`,"aria-label":`Write the ${t.toLowerCase()} again`,onClick:s,children:[(0,h.jsx)(ml,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(z,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function rAe({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=B(),a=(0,m.useId)(),o=t?.links.find(e=>yD(e.name)===yD(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=I({mutationFn:()=>{let n=(t?.links??[]).filter(e=>yD(e.name)!==yD(_D));return Gs(i,e,l.trim()===``?n:[...n,{name:_D,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]`,...Ny,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)(H,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(X,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(z,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var h5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function iAe({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=B(),[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=h5.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 xCe(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:`${xo(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`,...Ny,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(H,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),h5.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)(z,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(z,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var g5=e=>e.charAt(0).toUpperCase()+e.slice(1);function aAe(e){return e.revisionId===null?null:(0,h.jsx)(oAe,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function oAe({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=B(),o=_(),s=F({queryKey:u2(e,t),queryFn:()=>f2(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)(z,{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)(U,{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)(iAe,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(u2(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:V.project(e)}),o.invalidateQueries({queryKey:V.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(sAe,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,current:a.revisionId===t,...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 sAe({gate:e,disabled:t,reload:n,current:r,inRail:i=!1}){let{api:a}=B(),o=_(),s=(0,m.useRef)(null),c=(0,m.useRef)(!1),l=(0,m.useRef)(!0),u=(0,m.useRef)(null),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(null);(0,m.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]),(0,m.useEffect)(()=>{p!==null&&u.current?.focus()},[p]);let v=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function y(){if(!(c.current||t||!v||p?.kind===`refused`||p?.kind===`success`)){c.current=!0,f(!0),s.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await p2(a,e.projectId,e.checkpointId,s.current);s.current=null,l.current&&g(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}),o.invalidateQueries({queryKey:l2(e.projectId)}),o.invalidateQueries({queryKey:V.project(e.projectId)}),o.invalidateQueries({queryKey:V.projects})}catch(e){l.current&&g({kind:`transport`,message:`${xo(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{c.current=!1,l.current&&f(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(U,{as:`h3`,title:`${g5(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.`:v?`${g5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,title:`Version ${e.revisionId}`,children:r?`Applies to the project as it is now.`:`Set on an earlier version. Reload checkpoints to see the current one.`}),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:g5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),p?(0,h.jsx)(`p`,{ref:u,tabIndex:-1,role:p.kind===`success`?`status`:`alert`,className:p.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:p.message}):null,v&&i&&p===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.`}):v?(0,h.jsx)(z,{className:`self-start`,disabled:t||d||p?.kind===`refused`||p?.kind===`success`,onClick:()=>void y(),children:d?`Approving…`:p?.kind===`transport`?`Retry approval`:`Approve ${g5(e.stage)} checkpoint`}):null,p?.kind===`refused`?(0,h.jsx)(z,{className:`self-start`,onClick:async()=>{await n()&&g(null)},children:`Reload checkpoints`}):null]})}function cAe({projects:e,queryKey:t}){let{api:n}=B(),r=_(),i=Iv(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=I({mutationFn:e=>Ho(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${v5(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)(H,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(KL,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(qL,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[v5(e.bytes),` · outputs `,v5(e.outputsBytes),` · working files `,v5(e.workingBytes)]}),actions:(0,h.jsx)(z,{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 ${v5(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)(Qv,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:_5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,cancelLabel:`Keep everything`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function _5(e,t){return`This removes ${String(e)} working file(s) and frees ${v5(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.`}var v5=F2,y5=e=>[`storage`,`project`,e];function lAe({projectId:e,title:t,status:n,sample:r}){let{api:i}=B(),a=_(),o=Iv(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=F({queryKey:[...y5(e),n],queryFn:()=>Vo(i,e),enabled:l&&!r}),d=I({mutationFn:()=>Ho(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${v5(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:y5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:V.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=v5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(U,{as:`h3`,title:`Free space`,meta:`Outputs ${v5(f.outputsBytes)} · working files ${v5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(z,{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)(Qv,{open:s,title:`Free ${p} from "${t}"?`,consequence:_5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function uAe({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=e.status===`pending`&&e.setAside===!0?IL:FL[e.status],c=bde();return(0,h.jsx)(fG,{crumb:(0,h.jsxs)(pa,{to:c.to,search:c.search,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),c.label]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[pAe(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(ek,{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&&dAe(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(H,{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)(z,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(yl,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(JO,{modal:!1,children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsx)(Mv,{label:`More project actions`,children:(0,h.jsx)(Hc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(XO,{children:i.map(e=>(0,h.jsx)(fAe,{item:e},e.id))})]})]})})}function dAe(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function fAe({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(QO,{}):null,(0,h.jsx)(ZO,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function pAe(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:YE(a),i,e.format,`started ${vd(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function mAe({projectId:e}){let{api:t}=B(),n=F(vy(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)(yAe,{cost:n.data}):(0,h.jsx)(dM,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var hAe=new Set([`done`,`partial`,`failed`,`canceled`]);function gAe({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=t===`running`,a=r?.current===!0&&!hAe.has(t),[o,s]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[i]),!a||r===null)return null;let c=r.workingMs+(i&&r.running?Math.max(0,o-n):0),l=i?wAe(c):k5(c);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:i?`inline-flex items-center gap-1.5 rounded-full bg-accent/15 px-2.5 py-0.5 font-semibold text-ink tabular-nums`:`inline-flex items-center gap-1.5 rounded-full bg-surface-2 px-2.5 py-0.5 font-semibold text-ink-2 tabular-nums`,children:[(0,h.jsx)(bl,{"aria-hidden":`true`,strokeWidth:2,className:`size-3.5 shrink-0`}),i?`Working · ${l}`:`${l} of work so far`]})]})}var _Ae=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:pA[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:x5},{id:`api`,header:`Via API`,numeric:!0,cell:S5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>C5(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:k5(e.wallMs)}],vAe=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:SAe(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:x5},{id:`api`,header:`Via API`,numeric:!0,cell:S5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>C5(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>w5.format(e.calls)}];function b5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function yAe({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)(z$,{children:[(0,h.jsx)(B$,{value:O5(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(B$,{value:`~${O5(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${b5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${T5.format(t.usedPercent)}%`;return(0,h.jsx)(B$,{value:r,label:`of ${n}`,children:(0,h.jsx)(V$,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${T5.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(B$,{value:k5(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 ${D5(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:bAe(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:xAe(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(U,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(H$,{caption:`Run cost by stage`,columns:_Ae,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(U,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(H$,{caption:`Run cost by model`,columns:vAe,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: ${C5(e.totals)||`no reported usage`} · ${k5(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 bAe(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 ${D5(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${O5(t)} via API${n}.`}function xAe(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=b5(t.kind),r=t.usedPercent<1?`under 1%`:`~${T5.format(t.usedPercent)}%`,i=`now at ${T5.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${TAe(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 x5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${O5(e.cost)} + unknown`:O5(e.cost)}function S5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${O5(e.apiEquivalent)}`}function SAe(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function C5(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${E5(e.tokensIn)} in / ${E5(e.tokensOut)} out tokens${e.cachedTokens>0?` (${E5(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${E5(e.characters)} characters`),e.images>0&&t.push(D5(e.images,`image`)),e.seconds>0&&t.push(`${w5.format(e.seconds)} s of video`),t.join(` · `)}var w5=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),T5=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),CAe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function E5(e){return e<1e4?w5.format(e):CAe.format(e)}function D5(e,t){return`${w5.format(e)} ${t}${e===1?``:`s`}`}var O5=P2;function wAe(e){let t=Math.max(0,Math.floor(e/1e3)),n=e=>String(e).padStart(2,`0`);return`${String(Math.floor(t/3600))}:${n(Math.floor(t%3600/60))}:${n(t%60)}`}function k5(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 TAe(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function EAe({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)(m2);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)(U,{title:`Article`}),a?.state===`running`?(0,h.jsx)(j2,{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)(z,{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)(U,{title:`Narration`}),(0,h.jsx)(OAe,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(U,{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)(nz,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(DAe,{output:t,aspect:N8(e.format)},t.id))})]})})}function DAe({output:e,aspect:t}){let n=n6(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)(tz,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function OAe({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=n6(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(A5,{projectId:e,revisionId:t}),(0,h.jsx)(R6,{projectId:e})]}):a===void 0?(0,h.jsx)(A5,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)(v8,{label:`Body narration`,src:a.url})})}var kAe=240;function A5({projectId:e,revisionId:t}){let{api:n}=B(),r=F({queryKey:ty(e,t),queryFn:()=>py(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/kAe)),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: ${k5(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.`:`${k5(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function AAe({projectId:e,title:t,open:n,onClose:r}){let{api:i}=B(),a=_(),o=Iv(),s=ib(),[c,l]=(0,m.useState)(``),u=I({mutationFn:()=>Po(i,[e],c),onSuccess:()=>{a.invalidateQueries({queryKey:V.projects}),o(`Moved "${t}" to ${s.channels.find(e=>e.id===c)?.name??`the channel`}.`,`success`),r()},onError:e=>o(`The project wasn't moved: ${e.message}`,`error`)});return(0,h.jsx)(Zv,{open:n,onOpenChange:e=>{e||r()},title:`Move to channel`,description:`The project shows in that channel's list and uses its brand and playlists. Nothing it made changes.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{type:`button`,variant:`quiet`,onClick:r,children:`Cancel`}),(0,h.jsx)(z,{type:`button`,disabled:c===``||u.isPending,onClick:()=>u.mutate(),children:`Move`})]}),children:(0,h.jsx)(iL,{label:`Channel`,children:(0,h.jsx)(sL,{value:c,onChange:e=>l(e.currentTarget.value),options:[{value:``,label:`Choose a channel`},...s.channels.map(e=>({value:e.id,label:e.name}))]})})})}function jAe({projectId:e,revisionId:t,config:n,controller:r,onClose:i}){let{api:a}=B(),o=_(),s=a6.flatMap(e=>{let t=dDe(n,e);return!t.ok&&t.reason===`already`?[]:[{kind:e,refusal:t.ok?void 0:t.message}]}),[c,l]=(0,m.useState)(s.find(e=>e.refusal===void 0)?.kind),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[g,v]=(0,m.useState)(),y=(0,m.useRef)(void 0),b=s.find(e=>e.kind===c)?.refusal,x=F({queryKey:[`project`,e,`add-output`,t,c??``],enabled:c!==void 0&&b===void 0,staleTime:0,queryFn:async()=>{if(c===void 0)throw Error(`Choose an output to add.`);let n=await SDe(a,e,{baseRevisionId:t,kind:c});if(!n.ok)throw Error(n.message);return n.value}}),S=x.data,C=S!==void 0&&S.problems.length>0,w=async()=>{if(c!==void 0&&S!==void 0){d(!0),v(void 0);try{y.current?.kind!==c&&(y.current={kind:c,id:crypto.randomUUID()});let n=await CDe(a,e,{baseRevisionId:t,kind:c,idempotencyKey:y.current.id,...S.adapts?{adapt:f}:{}});if(!n.ok){v(n.message);return}await o.invalidateQueries({queryKey:V.project(e)}),i(),n.value.workKeys.length>0&&r.review({kind:`selected`,workKeys:n.value.workKeys},{autoStart:!0,approvedUpTo:S.estimate.unknown===0?S.estimate.high:void 0})}catch(e){v(e instanceof Error?e.message:String(e))}finally{d(!1)}}},T=c===void 0?`output`:o6[c].replace(/ \(.*\)$/,``);return(0,h.jsxs)(Zv,{open:!0,onOpenChange:e=>{!e&&!u&&i()},title:`Add another output`,description:`Made from this project's brief, sources and accepted text. What it already has stays as it is.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(SR,{tone:g===void 0?`info`:`error`,children:g??(x.error===null?void 0:x.error.message)}),(0,h.jsx)(z,{variant:`secondary`,disabled:u,onClick:i,children:`Cancel`}),(0,h.jsx)(z,{variant:`primary`,disabled:u||S===void 0||C||b!==void 0||c===void 0||S.adapts&&!f,disabledReason:u?`Adding it`:C?`Set the missing choices in Settings first`:S?.adapts===!0&&!f?`Tick Adapt my article into a conversation first`:`Choose an output it can add`,onClick:()=>void w(),children:`Add ${T.toLowerCase()}`})]}),children:[(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 border-0 p-0`,children:[(0,h.jsx)(`legend`,{className:`sl-kicker mb-1`,children:`Output`}),s.map(e=>(0,h.jsxs)(`label`,{className:`flex items-start gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`radio`,name:`added-output`,className:`mt-1`,checked:c===e.kind,onChange:()=>{l(e.kind),p(!1),v(void 0)}}),(0,h.jsxs)(`span`,{className:`min-w-0`,children:[(0,h.jsx)(`span`,{className:`text-ink`,children:o6[e.kind]}),e.refusal===void 0||c!==e.kind?null:(0,h.jsx)(`span`,{className:`block text-ink-2`,children:e.refusal})]})]},e.kind))]}),S===void 0||b!==void 0?x.isFetching?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Working out what it needs…`}):null:(0,h.jsxs)(F6,{label:`What adding ${T.toLowerCase()} does`,children:[(0,h.jsx)(I6,{label:`Reused as it is`,children:S.reused.join(`, `)}),(0,h.jsx)(I6,{label:`Made new`,children:S.created.join(`, `)}),(0,h.jsx)(I6,{label:`Your text`,children:S.textUse}),(0,h.jsx)(I6,{label:`Estimated extra cost`,children:MAe(S.estimate)})]}),S?.adapts===!0&&b===void 0?(0,h.jsxs)(`label`,{className:`flex items-start gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,checked:f,onChange:e=>p(e.target.checked)}),(0,h.jsx)(`span`,{children:`Adapt my article into a conversation (the article itself stays as it is)`})]}):null,S!==void 0&&C?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5 text-small text-danger`,children:S.problems.map(e=>(0,h.jsx)(`li`,{children:e.message},e.field))}),(0,h.jsx)(z,{variant:`secondary`,className:`self-start`,onClick:()=>{let e=S.config;i(),r.requestEdit({section:NAe(S.problems[0]?.field??``),change:t=>({...t,config:e})})},children:`Open Settings with ${T.toLowerCase()} switched on`})]}):null]})}function MAe(e){let t=e.low===e.high?i8(e.high):`${i8(e.low)}–${i8(e.high)}`;return e.unknown>0?e.high===0?`Unknown: ${String(e.unknown)} ${e.unknown===1?`step has`:`steps have`} no price yet. The remake review shows the rest before anything is charged.`:`About ${t}, plus ${String(e.unknown)} ${e.unknown===1?`step`:`steps`} with no price yet.`:e.high===0?e.rows.some(e=>e.onPlan===!0)?`$0 on your CLI plan; it uses some of the plan's limits.`:`No extra charge: it runs on this computer.`:`About ${t}.`}function NAe(e){return e.startsWith(`imagePrompts`)||e.endsWith(`Prompt`)?`prompts`:e.startsWith(`audio`)||e.startsWith(`voices`)||e.startsWith(`images`)||e.startsWith(`llm`)?`providers`:`inputs`}function PAe({projectId:e,revisionId:t,config:n,stages:r,outputs:i,controller:a}){let o=t6(),[s,c]=(0,m.useState)(!1),l=PDe({config:n,stages:r,outputs:i,states:new Map((o?.outputs??[]).filter(e=>e.selected).map(e=>[e.output.id,e.available?e.state:`missing`]))});return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`What this project makes, with each file's state and its downloads.`}),(0,h.jsxs)(z,{variant:`secondary`,disabled:t===null||a.busy,disabledReason:t===null?`This project has no saved version yet; wait for its first step to start`:`Finish or close the open edit or remake first`,onClick:()=>c(!0),children:[(0,h.jsx)(pl,{"aria-hidden":`true`,strokeWidth:1.75}),`Add another output`]})]}),(0,h.jsx)(KL,{label:`Outputs`,children:l.map(t=>(0,h.jsx)(FAe,{projectId:e,row:t},t.kind))}),s&&t!==null?(0,h.jsx)(jAe,{projectId:e,revisionId:t,config:n,controller:a,onClose:()=>c(!1)}):null]})}function FAe({projectId:e,row:t}){return(0,h.jsx)(qL,{lead:(0,h.jsx)(BAe,{kind:t.kind,output:t.main}),title:t.title,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ek,{tone:t.tone,children:t.stateWords}),t.version===void 0?null:(0,h.jsx)(`span`,{children:` · ${t.version}`})]}),actions:(0,h.jsxs)(Pv,{children:[t.set===void 0?null:(0,h.jsx)(m6,{projectId:e,set:t.set.set,members:t.set.members,variant:`secondary`}),t.primary===void 0?null:(0,h.jsx)(IAe,{file:t.primary,older:t.state===`older`}),t.alternatives.length===0?null:(0,h.jsx)(LAe,{files:t.alternatives})]}),children:(0,h.jsx)(GO,{to:`/projects/$projectId`,params:{projectId:e},search:{section:t.section},resetScroll:!1,className:`text-small`,children:t.next})})}function IAe({file:e,older:t}){let n=n6(e.output);return n===void 0?null:(0,h.jsxs)(KO,{href:n.url,download:!0,variant:`secondary`,title:t?`${e.label}, the previous version`:e.label,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}),t?`${e.label} · previous version`:e.label]})}function LAe({files:e}){return(0,h.jsxs)(JO,{modal:!1,children:[(0,h.jsx)(YO,{asChild:!0,children:(0,h.jsxs)(z,{variant:`quiet`,children:[`Other formats`,(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})]})}),(0,h.jsx)(XO,{children:e.map(e=>(0,h.jsx)(RAe,{file:e},e.output.id))})]})}function RAe({file:e}){let t=n6(e.output);return t===void 0?null:(0,h.jsx)(ZO,{asChild:!0,children:(0,h.jsxs)(`a`,{href:t.url,download:!0,children:[(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4 text-ink-2`}),e.label]})})}var zAe={article:(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),narration:(0,h.jsx)(sl,{"aria-hidden":`true`,strokeWidth:1.75}),voices:(0,h.jsx)(sl,{"aria-hidden":`true`,strokeWidth:1.75}),images:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75}),thumbnails:(0,h.jsx)($c,{"aria-hidden":`true`,strokeWidth:1.75}),video:(0,h.jsx)(Tl,{"aria-hidden":`true`,strokeWidth:1.75}),shorts:(0,h.jsx)(Tl,{"aria-hidden":`true`,strokeWidth:1.75}),pdf:(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75})};function BAe({kind:e,output:t}){let n=n6(t),r=t!==void 0&&(t.role===`image`||t.role===`thumbnail`);return(0,h.jsx)(`span`,{className:`flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-control bg-sunken text-ink-2`,children:r&&n!==void 0?(0,h.jsx)(`img`,{src:n.url,alt:``,className:`size-full object-cover`,loading:`lazy`}):t?.durationMs!==null&&t?.durationMs!==void 0?(0,h.jsx)(`span`,{className:`text-small tabular-nums`,children:VAe(t.durationMs)}):zAe[e]})}function VAe(e){let t=Math.round(e/1e3),n=Math.floor(t/60);return n>=60?`${String(Math.floor(n/60))}h ${String(n%60).padStart(2,`0`)}m`:`${String(n)}:${String(t%60).padStart(2,`0`)}`}function HAe({cues:e,duration:t,onChange:n,onPending:r,audition:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)(()=>e.map(e=>({...e,start:String(e.start),end:String(e.end)}))),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(r);f.current=r,(0,m.useEffect)(()=>{f.current(u)},[u]),(0,m.useEffect)(()=>()=>f.current(!1),[]);function p(){let e=[],r=new Set,i=0;if(!Number.isFinite(t)||t<=0){l(`The narration length isn't known yet, so captions can't be checked. Reload the page and try again.`);return}for(let[n,a]of o.entries()){let o=a.start.trim()===``?NaN:Number(a.start),s=a.end.trim()===``?NaN:Number(a.end);if(r.has(a.id)){l(`Caption ${n+1}: this caption is listed twice. Remove the copy.`);return}if(r.add(a.id),!Number.isFinite(o)||o<0||o<i){l(`Caption ${n+1}: start must be a number of seconds, no earlier than the previous caption's end.`);return}if(!Number.isFinite(s)||s<=o||s>t){l(`Caption ${n+1}: end must be after its start and no later than the end of the narration.`);return}if(a.text.trim()===``){l(`Caption ${n+1}: enter caption text.`);return}e.push({id:a.id,text:a.text,start:o,end:s,...a.speaker===void 0?{}:{speaker:a.speaker}}),i=s}n(e),l(void 0),d(!1)}return(0,h.jsxs)(`section`,{"aria-label":`Edit caption cues`,className:`space-y-3`,...Ny,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`h3`,{children:`Caption text and timing`}),(0,h.jsx)(H,{id:`project.captions.editor`})]}),o.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]}),i?.play===void 0?null:(0,h.jsx)(UAe,{audition:i,id:e.id,number:t+1,start:Number(e.start),end:Number(e.end)}),(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.id}-text`,className:`block text-small`,children:[`Text for caption `,t+1,(0,h.jsx)(oL,{id:`${a}-${e.id}-text`,value:e.text,onChange:n=>{d(!0),s(o.with(t,{...e,text:n.target.value}))}})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.id}-start`,className:`block text-small`,children:[`Start for caption `,t+1,(0,h.jsx)(X,{id:`${a}-${e.id}-start`,inputMode:`decimal`,value:e.start,onChange:n=>{d(!0),s(o.with(t,{...e,start:n.target.value}))}})]}),(0,h.jsxs)(`label`,{htmlFor:`${a}-${e.id}-end`,className:`block text-small`,children:[`End for caption `,t+1,(0,h.jsx)(X,{id:`${a}-${e.id}-end`,inputMode:`decimal`,value:e.end,onChange:n=>{d(!0),s(o.with(t,{...e,end:n.target.value}))}})]})]})]},e.id)),c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:c}),(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{type:`button`,onClick:p,children:`Apply caption edits to draft`}),(0,h.jsx)(H,{id:`project.captions.apply`})]}),u?(0,h.jsx)(`p`,{children:`Apply these caption edits before saving the project.`}):null]})}function UAe({audition:e,id:t,number:n,start:r,end:i}){let a=e.playing===t;return(0,h.jsx)(z,{type:`button`,size:`small`,variant:`quiet`,disabled:!(Number.isFinite(r)&&Number.isFinite(i)&&i>r&&r>=0),disabledReason:`Enter a start and an end in seconds to play this caption`,"aria-label":a?`Stop caption ${String(n)}`:`Play caption ${String(n)}`,onClick:()=>a?e.stop():e.play?.(r,i,t),children:a?`Stop`:`Play`})}function j5(e){return`imagePrompts.${String(e)}`}function M5(e){let t=/^imagePrompts\.(\d+)$/.exec(e??``);return t?.[1]===void 0?void 0:Number(t[1])}function WAe(e,t){return e.length===t.length&&e.every((e,n)=>e.name===t[n]?.name&&e.number===t[n]?.number)}function GAe(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))M5(e)===void 0&&(o[e]=t);for(let[t,n]of Object.entries(e.rendered))M5(t)===void 0&&(s[t]=n);for(let[t,c]of n.entries()){let n=j5(t),l=i[t]??-1;if(l>=0){let t=j5(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]=XW(u,e.values)}if(a.length>0)return{ok:!1,fields:a};let c=new Map;for(let e of r.imageOrder){let n=M5(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=j5(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=M5(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===j5(s)?a:{...a,templateKey:j5(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 KAe({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)(T4,{prompts:o,picked:a.imagePrompts,problem:r,onPick:t=>i({...e,config:{...a,imagePrompts:t}})}),(0,h.jsx)(qAe,{edit:e,saved:t,prompts:o,problem:r})]})}function qAe({edit:e,saved:t,prompts:n,problem:r}){let i=e.config.imagePrompts,a=r(`imagePrompts`);if(WAe(t,i))return a===void 0?null:(0,h.jsx)(N5,{children:a});let o=0,s=GAe({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)(N5,{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)(N5,{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 N5({children:e}){return(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:e})}function JAe({edit:e,problem:t,onChange:n}){let r=e.config.ambientBed,[i,a]=(0,m.useState)(()=>r===void 0?void 0:TE(r)),o=r?.source===`upload`?[...bE,`upload`]:bE,s=i===void 0?[]:[...ZAe(i)];return(0,h.jsx)(f$,{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=EE(t),{ambientBed:i,...o}=e.config;n({...e,config:r===void 0?o:{...o,ambientBed:r}})}})}function YAe({edit:e,problem:t,onChange:n}){let r=e.config.loudness,[i,a]=(0,m.useState)(()=>r===void 0?{...QT,enabled:!1}:{...r,enabled:!0});return(0,h.jsx)(e3,{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 XAe({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=o3(r[e]);return t===void 0?`Enter a number of seconds.`:lE(t,e===`sentencePauseSeconds`?`sentences`:`paragraphs`)};return(0,h.jsx)(a3,{sentence:r.sentencePauseSeconds,paragraph:r.paragraphPauseSeconds,problem:e=>a(e)??t(e),onChange:(t,a)=>{i({...r,[t]:a});let o=o3(a);if(o===void 0)return;let{[t]:s,...c}=e.config;n({...e,config:o===0?c:{...c,[t]:o}})}})}function ZAe(e){let t=EE(e);return t===void 0?[]:CE(t)}function QAe({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:hce(a));if(i.sources.images!==`generate`)return null;let c=a?.words??(qT(e.content.articleMarkdown??``)||1500),l=t=>{s(t);let{imageScale:r,...o}=i;if(t===void 0){n({...e,config:o});return}let l=P5(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:ZT(i).reduce((e,t)=>e+t,0),f=o===void 0?void 0:P5(o),p=o===void 0?void 0:f===void 0?{problem:!0,text:o.every===`minutes`?`Enter a number of minutes between ${String(KT)} and 60.`:`Enter a number of images per hour between 1 and 240.`}:{problem:!1,text:`For about ${String(Math.max(1,Math.round(JT(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`,...Ny,children:[(0,h.jsx)(Py,{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)(Fy,{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:$Ae(o.value,o.every,e)})}),o.every===`minutes`?(0,h.jsx)(`span`,{children:`One image every`}):null,(0,h.jsx)(X,{"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 P5(e){let t=Number(e.value.trim());if(e.value.trim()!==``&&Number.isFinite(t))return e.every===`minutes`?t>=.25&&t<=60?YT(t):void 0:t>=1&&t<=240?t:void 0}function $Ae(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 eje({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`,...Ny,children:(0,h.jsx)(Py,{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 tje({edit:e,view:t,imageKey:n,index:r}){let{api:i}=B(),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)(XR,{className:`max-w-[240px]`,label:`Video clip ${r+1}`,src:dB(i,t.revision.projectId,t.revision.id,l.recordId)}):(0,h.jsx)(tz,{className:`max-w-[240px]`,alt:`Retained scene ${r+1}`,src:dB(i,t.revision.projectId,t.revision.id,l.recordId)}),(0,h.jsx)(`p`,{children:m?`${p} · video clip, played muted`:p})]})}var F5=e=>t=>t.destination.kind===`image`&&t.destination.imageKey===e;function nje(e,t){let{content:n}=e,r=n.imageDefinitions[t],i=n.imageOrder.indexOf(t),a=n.imageOrder.filter(e=>e!==t);return{next:{...e,config:a.length===0?{...e.config,sources:{...e.config.sources,images:`off`,video:`off`}}:e.config,content:{...n,imageOrder:a,imageDefinitions:Object.fromEntries(Object.entries(n.imageDefinitions).filter(([e])=>e!==t))},regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`),uploads:(e.uploads??[]).filter(e=>!F5(t)(e))},removed:r===void 0||i===-1?void 0:{key:t,index:i,definition:r,uploads:(e.uploads??[]).filter(F5(t)),regenerate:e.regenerate?.includes(`image:${t}`)===!0,sources:e.config.sources}}}function rje(e,t){if(e.content.imageOrder.includes(t.key))return;let n=[...e.content.imageOrder];return n.splice(Math.min(t.index,n.length),0,t.key),{...e,config:{...e.config,sources:n.length===1?t.sources:e.config.sources},content:{...e.content,imageOrder:n,imageDefinitions:{...e.content.imageDefinitions,[t.key]:t.definition}},uploads:[...e.uploads??[],...t.uploads],regenerate:t.regenerate?[...new Set([...e.regenerate??[],`image:${t.key}`])]:e.regenerate}}function ije({imageKey:e,children:t}){let n=(0,m.useRef)(null);return f8(`image:${e}`,n),(0,h.jsx)(`fieldset`,{ref:n,tabIndex:-1,className:`space-y-2 rounded-control border border-line-strong p-3`,children:t})}function I5(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 aje({edit:e,onChange:t,onPending:n,view:r,getEdit:i}){let a=(0,m.useId)(),[o,s]=(0,m.useState)({}),[c,l]=(0,m.useState)(),{content:u}=e,d=mce(e.config),f=(0,m.useRef)(e);f.current=e;function p(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`}:{}}}};f.current=i,t(i)}function g(e,t){let n=i?.()??f.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})),p(Z8({...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 _(e){let t=i?.()??f.current,n=t.content,r=crypto.randomUUID();p({...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}}]})}function v(){let e=c;l(void 0);let t=e===void 0?void 0:rje(i?.()??f.current,e);t!==void 0&&p(t)}let y=c===void 0?null:(0,h.jsxs)(`p`,{role:`status`,className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[`Image `,c.index+1,` is deleted from this draft; it goes when you save.`,(0,h.jsx)(z,{type:`button`,variant:`quiet`,size:`small`,onClick:v,children:`Undo`})]});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)(H,{id:`project.images.editor`})]}),u.imageOrder.map((t,s)=>{let d=u.imageDefinitions[t];return d===void 0?(0,h.jsxs)(`p`,{role:`alert`,children:[`Image definition missing: `,t]},t):(0,h.jsxs)(m.Fragment,{children:[c?.index===s?y:null,(0,h.jsxs)(ije,{imageKey:t,children:[(0,h.jsxs)(`legend`,{children:[`Image `,s+1]}),(0,h.jsx)(tje,{edit:e,view:r,imageKey:t,index:s}),d.source===`generate`?(0,h.jsxs)(`div`,{...Ny,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)(H,{id:`project.images.prompt`,label:`prompt for image ${String(s+1)}`})]}),(0,h.jsx)(oL,{id:`${a}-${t}-prompt`,value:d.templateKey===void 0||d.templateKey===null?d.prompt??``:u.promptTemplates[d.templateKey]??d.prompt??``,onChange:e=>g(t,e.target.value)})]}):null,d.source===`generate`&&d.templateKey==null?(0,h.jsxs)(z,{type:`button`,onClick:()=>g(t,d.prompt??``),children:[`Use saved wording as template for image `,s+1]}):null,(0,h.jsx)(p8,{label:`Replace image ${s+1}`,kind:`images`,onPending:e=>n(`image:${t}`,e),onReady:e=>{let n=i?.()??f.current,r=n.content,a=r.imageDefinitions[t];a!==void 0&&r.imageOrder.includes(t)&&p({...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)(z,{type:`button`,disabled:s===0,onClick:()=>p({...e,content:{...u,imageOrder:I5(u.imageOrder,s,-1)}}),children:[`Move image `,s+1,` earlier`]}),(0,h.jsxs)(z,{type:`button`,disabled:s===u.imageOrder.length-1,onClick:()=>p({...e,content:{...u,imageOrder:I5(u.imageOrder,s,1)}}),children:[`Move image `,s+1,` later`]}),(0,h.jsxs)(z,{type:`button`,onClick:()=>{let{next:n,removed:r}=nje(e,t);l(r),p(n)},children:[`Delete image `,s+1,u.imageOrder.length===1?` and turn Images and Video Off`:``]}),d.source===`generate`?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e.regenerate?.includes(`image:${t}`)===!0?(0,h.jsxs)(z,{type:`button`,onClick:()=>p({...e,regenerate:(e.regenerate??[]).filter(e=>e!==`image:${t}`)}),children:[`Keep image `,s+1]}):(0,h.jsxs)(z,{type:`button`,onClick:()=>p({...e,regenerate:[...new Set([...e.regenerate??[],`image:${t}`])]}),children:[`Regenerate image `,s+1]}),(0,h.jsx)(H,{id:`project.images.regenerate`})]}):null]})]},t)}),c!==void 0&&c.index>=u.imageOrder.length?y:null,(0,h.jsx)(z,{type:`button`,disabled:u.imageOrder.length>=d,onClick:()=>{if(u.imageOrder.length>=d)return;let t=crypto.randomUUID();p({...e,config:{...e.config,sources:{...e.config.sources,images:`generate`}},content:{...u,imageOrder:[...u.imageOrder,t],promptTemplates:{...u.promptTemplates,[`image:${t}`]:``},imageDefinitions:{...u.imageDefinitions,[t]:{source:`generate`,assetId:null,prompt:``,templateKey:`image:${t}`}}}})},children:`Add generated image`}),u.imageOrder.length>=d?(0,h.jsxs)(`p`,{children:[`At most `,d,` images can be included.`]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(p8,{label:`Add provided image`,kind:`images`,onPending:e=>n(`image:new`,e),onReady:_},`new-image:${e.config.sources.images===`off`}`),(0,h.jsx)(p8,{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:_},`new-clip:${e.config.sources.images===`off`}`)]})]})}function oje(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(L5))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`)&&L5(e.output.durationMs))?.output.durationMs;return L5(s)?s/1e3:void 0}function L5(e){return e!=null&&Number.isFinite(e)&&e>0}function sje({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?W4:{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)(G4,{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:Z8(d,`referencePrompt`,u.body);r(n.source===`provide`?f:l(f))},upload:(0,h.jsx)(p8,{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 cje=J({words:q(J({text:G().trim().min(1),start:K().finite().nonnegative(),end:K().finite().positive(),confidence:K().optional(),speaker:G().min(1).optional()})).min(1)});function R5(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 lje({view:e,edit:t,fields:n,onChange:r,onPending:i,section:a}){let{api:o}=B(),s=F(Sy(o)).data?.prompts??[],c=R5(t),l=t.config.sources.audio!==`off`&&c===R5({config:e.revision.config,content:e.revision.content}),u=e.revision.fingerprints[`subtitles:timing`],d=l?oje(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,S]=(0,m.useState)(),C=Y8(e),w=(0,m.useRef)(void 0),T=(0,m.useRef)(!0),E=(0,m.useCallback)((e,t)=>{T.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)(()=>(T.current=!0,()=>{T.current=!1,w.current?.abort(),g.current(!1)}),[]),(0,m.useEffect)(()=>{let t=e.revision.id;return()=>{(p.current.revisionId!==t||p.current.identity!==c)&&w.current?.abort()}},[e.revision.id,c]);function D(e){let t=p.current.onChange;p.current={...p.current,edit:e,identity:R5(e)},t(e)}async function O(){if(w.current!==void 0)return;let t=new AbortController;w.current=t;let n=p.current;E(`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(dB(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=cje.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=B6(a.words).map(e=>({...e,id:crypto.randomUUID()})),l=p.current;if(!T.current||t.signal.aborted||l.revisionId!==n.revisionId||l.identity!==n.identity||l.edit.content.subtitleCues!==n.edit.content.subtitleCues)return;D({...l.edit,content:{...l.edit.content,subtitleCues:{audioFingerprint:u,cues:c}}})}catch(e){T.current&&!t.signal.aborted&&b(e instanceof Error?e.message:String(e))}finally{w.current===t&&(w.current=void 0),E(`captions:load`,!1)}}let k=t.content.subtitleCues,A=e=>a===void 0||a===e;return(0,h.jsxs)(`div`,{className:`space-y-5`,children:[C.element,(0,h.jsxs)(`section`,{"aria-label":`Images`,hidden:!A(`images`),className:`space-y-6`,children:[(0,h.jsx)(KAe,{edit:t,saved:e.revision.config.imagePrompts,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:D}),(0,h.jsx)(QAe,{edit:t,problem:e=>n.find(t=>t.field===e||t.field===`config.${e}`)?.message,onChange:D}),(0,h.jsx)(eje,{edit:t,onChange:D}),(0,h.jsx)(sje,{edit:t,prompts:s,problem:e=>n.find(t=>t.field===e||t.field===`content.${e}`)?.message,getEdit:()=>p.current.edit,onChange:D,onPending:e=>E(`provided:reference`,e)}),t.config.sources.thumbnail===`from_prompt`||t.config.sources.thumbnail===`prompt_by_llm`?(0,h.jsx)(s3,{value:t.config.thumbnailCount===3?3:1,onPick:e=>{let{thumbnailCount:t,...n}=p.current.edit.config;D({...p.current.edit,config:e===3?{...n,thumbnailCount:3}:n})}}):null,(0,h.jsx)(WOe,{edit:t,getEdit:()=>p.current.edit,onChange:D,onPending:E}),[`audio`,`thumbnail`].map(e=>t.config.sources[e]===`provide`?(0,h.jsx)(p8,{label:`Replace provided ${e}`,kind:e,onPending:t=>E(`provided:${e}`,t),onReady:t=>{let n=p.current;if(n.edit.config.sources[e]===`provide`){if(e===`thumbnail`){let e=C8(t.bytes);if(S(e),e!==void 0)return}D({...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),x===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:x}),(0,h.jsx)(aje,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:D,onPending:E})]}),(0,h.jsx)(`section`,{"aria-label":`Narration`,hidden:!A(`narration`),className:`space-y-5`,children:t.config.sources.audio===`generate`?(0,h.jsx)(EOe,{getEdit:()=>p.current.edit,view:e,edit:t,onChange:D,onPending:E}):null}),y===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-danger`,children:y}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,hidden:!A(`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.`}),k===void 0?(0,h.jsx)(z,{type:`button`,disabled:!f||_.has(`captions:load`),onClick:()=>void O(),children:`Edit existing caption cues`}):(0,h.jsxs)(h.Fragment,{children:[k.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)(HAe,{audition:C,cues:k.cues,duration:d,onPending:e=>E(`captions:dirty`,e),onChange:e=>{let t=p.current,n=t.edit.content.subtitleCues;n!==void 0&&D({...t.edit,content:{...t.edit.content,subtitleCues:{...n,cues:e}}})}},`${e.revision.id}:${u}`):null,(0,h.jsx)(z,{type:`button`,onClick:()=>D({...t,content:{...t.content,subtitleCues:void 0}}),children:`Discard caption edits`})]})]})]})}function uje({edit:e,error:t,onChange:n}){return(0,h.jsx)(`div`,{className:`mb-5`,children:(0,h.jsx)(u$,{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}})}})})}var z5=5e5,B5=new Intl.NumberFormat(`en`);function dje({value:e,error:t,help:n,onChange:r}){let i=e.length-z5;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(iL,{label:`Article text`,tip:`project.edit.article-text`,error:t??(i>0?`The article is ${B5.format(i)} characters over the ${B5.format(5e5)} limit. Shorten it, then press Save changes; nothing was cut.`:void 0),help:n,children:(0,h.jsx)(oL,{rows:12,value:e,onChange:e=>r(e.target.value)})}),(0,h.jsx)(`p`,{className:`m-0 text-small tabular-nums ${i>0?`text-danger`:`text-ink-2`}`,children:`${B5.format(e.length)} of ${B5.format(z5)} characters`})]})}function fje({edit:e,saved:t,problem:n,onChange:r}){let{api:i}=B(),a=F(Yy(i)),{config:o}=e,s=e=>e!==void 0&&(a.data?.some(t=>t.id===e)??!0)?e:Hy,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)(iL,{label:`Channel`,tip:`play.channel`,error:n(`channelId`),help:l===void 0?void 0:(0,h.jsxs)(pa,{to:`/channels/$channelId`,params:{channelId:l.id},className:`underline`,children:[`Edit `,l.name]}),children:(0,h.jsxs)(sL,{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)(Py,{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 PDF 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 pje(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=D3([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 mje({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)(H4,{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:Z8(e,`narration`,r.body);i({...o,config:{...o.config,narrationPrompt:t}})}})}function V5(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function H5(e,t){return e===t||JSON.stringify(e)===JSON.stringify(t)}function U5(e,t,n){if(H5(e,t))return n;if(V5(e)&&V5(t)&&V5(n)){let r={};for(let i of new Set([...Object.keys(n),...Object.keys(t)])){let a=U5(e[i],t[i],n[i]);a!==void 0&&(r[i]=a)}return r}return t}function W5(e,t,n){return{...t,config:U5(e.config,t.config,n.config),content:U5(e.content,t.content,n.content)}}function G5(e,t,n,r){if(H5(e,t))return;if(V5(e)&&V5(t)){for(let i of new Set([...Object.keys(e),...Object.keys(t)]))G5(e[i],t[i],n===``?i:`${n}.${i}`,r);return}let i=t===void 0?`(removed)`:typeof t==`string`?t:JSON.stringify(t,null,2);r.push(`${n}:\n${i}`)}function hje(e,t){let n=[];return G5(e.config,t.config,`config`,n),G5(e.content,t.content,`content`,n),(t.regenerate?.length??0)>0&&n.push(`Marked to make again:\n${(t.regenerate??[]).join(`
|
|
316
316
|
`)}`),n.length===0?`No changes.`:n.join(`
|
|
317
317
|
|
|
318
318
|
`)}function K5(e){return V5(e)&&V5(e.config)&&V5(e.content)}function gje({id:e,name:t,value:n,onChange:r}){let i=n.trim()===``||n.length>1e5||qW(n).errors.length===0?[]:Y0({kind:`article`,name:t,body:n}).filter(e=>e.field===`body`).map(e=>e.message),a=i.length===0?void 0:i.join(` `);return(0,h.jsx)(iL,{label:`Raw prompt for ${t}`,id:e,tip:`project.prompts.raw`,error:a,children:(0,h.jsx)(r2,{id:e,value:n,invalid:a!==void 0,describedBy:a===void 0?void 0:`${e}-error`,onChange:r})})}function _je({edit:e,saved:t=e.config.imagePrompts,prompts:n,entries:r,onChange:i}){let a=(0,m.useId)(),o=Iv(),s=(0,m.useRef)(e);s.current=e;let c=(t,n)=>{let r=e;i(t),o(n,`info`,{label:`Undo`,run:()=>{let e=W5(t,r,s.current);i({...s.current,config:e.config,content:e.content})}})},l=[...new Set([...Object.keys(e.config.rendered),...Object.keys(e.content.promptTemplates),...e.config.sources.article===`generate`?[`article`]:[],...cD(e.config)?[`narration`]:[],...lD(e.config)&&e.config.descriptionPrompt?[`description`]:[],...dD(e.config)&&e.config.shorts?.prompt?[`shorts`]:[],...dD(e.config)&&e.config.shorts?.imagePrompt?[`shortsImage`]:[],...[`from_prompt`,`prompt_by_llm`].includes(e.config.sources.thumbnail)?[`thumbnailPrompt`]:[],...uD(e.config)&&e.config.reference?.source===`prompt`?[`referencePrompt`]:[],...e.config.intro===void 0?[]:[`intro`],...e.config.outro===void 0?[]:[`outro`]])].filter(n=>{let r=X5(n);if(r===void 0)return!0;let i=t[r]?.name;return i===void 0||e.config.imagePrompts.some(e=>e.name===i)}),u=e.config.imagePrompts.filter(e=>!t.some(t=>t.name===e.name)),d=e=>bje(e,t),f=[...new Set([...Object.keys(e.config.values),...Object.values(e.content.promptTemplates).flatMap(e=>e===null?[]:qW(e).names)])].filter(e=>!JW.includes(e)),p=t=>[...qW(e.config.title).names.includes(t)?[`Project title`]:[],...Object.entries(e.content.promptTemplates).flatMap(([e,n])=>n!==null&&qW(n).names.includes(t)?[d(e)]:[])],g=qW(e.config.title).names;return(0,h.jsxs)(`section`,{"aria-label":`Prompt snapshots`,className:`space-y-6`,children:[l.map(o=>{let s=d(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`?$E(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)(dM,{tone:`info`,title:`Original template unavailable`,actions:(0,h.jsx)(z,{"aria-label":`Use saved wording as template for ${s}`,onClick:()=>i(Z8(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)(yje,{label:s,raw:l,library:vje(e,o,u,t),onUse:t=>c(Z8(e,o,t),`${s} now uses the Library version.`)}),(0,h.jsx)(iL,{label:`Use saved template for ${s}`,id:`${a}-library-${o}`,tip:`project.prompts.template`,children:(0,h.jsxs)(sL,{value:``,onChange:t=>{let n=u.find(e=>e.id===t.target.value);if(n===void 0)return;let r=Z8(e,o,n.body),i=`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;c({...r,config:i},`${s} now uses "${n.name}".`)},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)(gje,{id:`${a}-raw-${o}`,name:s,value:l??``,onChange:t=>i(Z8(e,o,t))}),(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)}),u.length===0?null:(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[u.map(e=>`"${e.name}"`).join(`, `),` `,u.length===1?`uses its`:`use their`,` Library wording. Save, then change it here.`]}),f.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)(SQ,{fieldPrefix:`config.values`,keywords:f.map(t=>({name:t,value:e.config.values[t]??``,feeds:p(t),topic:g.includes(t)})),onChange:(t,n)=>i(X8({...e,config:{...e.config,values:{...e.config.values,[t]:n}}}))})]}):null]})}function vje(e,t,n,r){let{config:i}=e,a=X5(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 q5=`slopify.library-kept`;function J5(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 Y5(){try{let e=window.localStorage.getItem(q5),t=e===null?[]:JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function yje({label:e,raw:t,library:n,onUse:r}){let i=n===void 0||t===null?``:`${e}:${J5(t)}:${J5(n.body)}`,[a,o]=(0,m.useState)(()=>Y5().includes(i));return n===void 0||t===null||n.body===t||a?null:(0,h.jsx)(dM,{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)(z,{"aria-label":`Use the Library version for ${e}`,onClick:()=>{r(n.body)},children:`Use the Library version`}),(0,h.jsx)(z,{variant:`quiet`,"aria-label":`Keep this project's version for ${e}`,onClick:()=>{try{window.localStorage.setItem(q5,JSON.stringify([...Y5().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 X5(e){let t=/^imagePrompts\.(\d+)$/.exec(e);return t?.[1]===void 0?void 0:Number(t[1])}function bje(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=X5(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 xje(e,t,n){let{api:r}=B(),[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 tc(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)(z,{type:`button`,variant:`quiet`,disabled:i.busy,onClick:()=>void c(),children:i.busy?`Copying…`:`Update from other projects`}),(0,h.jsx)(H,{id:`project.edit.update-glossary`})]}):void 0;return{value:s?.shareGlossary===!0,onChange:e=>{e?c():l()},note:d}}function Sje(e,t){let{api:n}=B(),[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 nc(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 → Narration aliases.`:`${String(c)} ${c===1?`alias`:`aliases`} copied from Library → Narration aliases.`:`Couldn't read Library → Narration aliases: ${r.error} Try Update from Library again.`,(0,h.jsx)(z,{type:`button`,variant:`quiet`,disabled:r.busy,onClick:()=>void s(),children:r.busy?`Copying…`:`Update from Library`}),(0,h.jsx)(H,{id:`project.edit.update-aliases`})]}):void 0}}function Cje({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=xje(e,t,i),l=Sje(t,i),{api:u}=B(),d=F(Xy(u,a.channelId??`00000000-0000-4000-8000-000000000001`)),f=a.images??{provider:``,model:``},p=cD(a)||a.sources.audio===`generate`&&a.audio?.describeFigures===!0||a.sources.research===`generate`||a.sources.article===`generate`||a.sources.thumbnail===`prompt_by_llm`||QE(a)&&(a.voices?.source===`attribute`||a.voices?.source===`adapt`)||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)(vL,{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)(hL,{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)(K4,{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)(vL,{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)(hL,{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)(_L,{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)(C4,{value:a.chunking??{mode:`whole`},onPick:e=>i({...t,config:{...a,chunking:e}})}),(0,h.jsx)(U4,{shared:c,value:s.usePronunciationGlossary,supported:pD({sources:a.sources,audio:{...s,usePronunciationGlossary:!0}}),onChange:e=>i({...t,config:{...a,audio:{...s,usePronunciationGlossary:e}}})}),(0,h.jsx)(V4,{...l}),(0,h.jsx)(z4,{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)(L4,{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)(vL,{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)(hL,{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)(K4,{field:`images.thinking`,label:`Effort`,tip:`play.images.effort`,choice:f,onChange:e=>i({...t,config:{...a,images:e}})})]}):null]})}function wje({edit:e,providers:t,prompts:n,problem:r,onChange:i}){let{config:a}=e,o=a.reviews===void 0?yL:jce(a.reviews),[s,c]=(0,m.useState)(o),l=a.shorts?.enabled===!0&&a.sources.audio!==`off`,u=e=>gE({sources:a.sources,shorts:l?{enabled:!0}:void 0},e),d=hE(s,u).retriesProblem;return(0,h.jsx)(bL,{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}=hE(t,u),o={...e.content.promptTemplates},s={...a.rendered};for(let e of uE){let t=Ace(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(X8({...e,config:{...d,rendered:s,...r===void 0?{}:{reviews:r}},content:{...e.content,promptTemplates:o}}))}})}function Tje({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===Z5&&e.state===`ready`),l=e.regenerate?.includes(Z5)===!0;return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(J4,{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?Eje(e):Z8(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)(z,{type:`button`,variant:`quiet`,onClick:()=>{i({...e,regenerate:(e.regenerate??[]).filter(e=>e!==Z5)})},children:`Keep the current description`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{type:`button`,onClick:()=>{i({...e,regenerate:[...new Set([...e.regenerate??[],Z5])]})},children:`Write the description again after review`}),(0,h.jsx)(H,{id:`project.edit.rewrite-description`})]}):null]})}var Z5=`youtube:description`;function Eje(e){let{description:t,...n}=e.content.promptTemplates,{description:r,...i}=e.config.rendered;return X8({config:{...e.config,rendered:i},content:{...e.content,promptTemplates:n}})}var Dje={research:`Research source`,article:`Article source`,audio:`Audio source`,images:`Images source`,thumbnail:`Thumbnail source`,video:`Video source`,document:`Document source`},Oje={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`},kje=`\0kept:`;function Q5({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:R(`grid min-w-0 gap-4`,n&&`md:grid-cols-2`),children:t})]})}function Aje(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}=B(),_=F(by(g)),v=F(xy(g)),y=F(Sy(g)),b=F(Cy(g)),{config:x}=n,S=pje(t,n,F(Xy(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:dB(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=Y4({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=>R(`min-w-0 space-y-6`,O===e?void 0:`hidden`),A=e=>Number.isFinite(e)?e:``,j=x.sources.video!==`off`;return(0,h.jsxs)(`div`,{className:`grid min-w-0 gap-8 md:grid-cols-[180px_minmax(0,1fr)]`,children:[(0,h.jsx)(`nav`,{"aria-label":`Edit sections`,className:`min-w-0 md:sticky md:top-16 md:self-start`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none gap-1 overflow-x-auto p-0 [scrollbar-width:none] md:flex-col`,children:D.map(e=>(0,h.jsx)(`li`,{className:`shrink-0`,children:(0,h.jsx)(H3,{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)(Q5,{title:`Project`,children:[(0,h.jsx)(iL,{label:`Project title`,error:T(`title`),className:`md:col-span-2`,children:(0,h.jsx)(X,{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)(E3,{value:x.format,onPick:e=>r({...n,config:{...x,format:e}})})})]}),(0,h.jsx)(gG,{}),(0,h.jsx)(Q5,{title:`Channel`,columns:!1,children:(0,h.jsx)(fje,{edit:n,saved:t.revision.config,problem:T,onChange:r})}),(0,h.jsx)(gG,{}),(0,h.jsxs)(Q5,{title:`Stages`,children:[Db.filter(e=>x.sources.article!==`off`||e!==`research`&&e!==`audio`&&e!==`document`).map(e=>(0,h.jsx)(iL,{label:Dje[e],tip:Oje[e],error:T(`sources.${e}`),children:(0,h.jsx)(sL,{value:Ab(x.sources,e),onChange:i=>{let a=tA(e).find(e=>e.value===i.target.value);if(a===void 0)return;let o=Nke(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:tA(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)(iL,{label:`PDF theme`,id:`${o}-document-theme`,tip:`play.document-theme`,children:(0,h.jsx)(S4,{id:`${o}-document-theme`,disabled:Ab(x.sources,`document`)===`off`,value:x.document,onChange:e=>{r({...n,config:{...x,document:e}})}})})]}),(0,h.jsx)(gG,{}),(0,h.jsxs)(Q5,{title:`Timing`,children:[(0,h.jsx)(iL,{label:`Silence gap (seconds)`,tip:`play.silence-gap`,error:T(`silenceGapSeconds`),children:(0,h.jsx)(X,{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)(iL,{label:`Silence at start and end (seconds)`,tip:`play.edge-silence`,error:T(`edgeSilenceSeconds`),children:(0,h.jsx)(X,{type:`number`,min:0,max:30,step:.5,value:A(x.edgeSilenceSeconds),onChange:e=>r({...n,config:{...x,edgeSilenceSeconds:Number(e.target.value)}})})}),j?(0,h.jsx)(iL,{label:`Seconds per image`,tip:`play.image-seconds`,error:T(`imageSeconds`),children:(0,h.jsx)(X,{type:`number`,min:1,max:600,step:1,value:A(x.imageSeconds),onChange:e=>r({...n,config:{...x,imageSeconds:Number(e.target.value)}})})}):null,j?(0,h.jsx)(iL,{label:`Zoom (%)`,tip:`play.zoom`,error:T(`zoomPercent`),children:(0,h.jsx)(X,{type:`number`,min:0,max:50,step:.5,value:A(x.zoomPercent),onChange:e=>r({...n,config:{...x,zoomPercent:Number(e.target.value)}})})}):null,j?(0,h.jsx)(iL,{label:`Motion`,tip:`play.motion`,children:(0,h.jsx)(sL,{value:x.motionStyle,onChange:e=>r({...n,config:{...x,motionStyle:e.target.value}}),children:jb.map(e=>(0,h.jsx)(`option`,{value:e,children:nD[e]},e))})}):null]}),j?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(gG,{}),(0,h.jsxs)(Q5,{title:`Cuts and look`,columns:!1,children:[E.cuts,E.look,x.sources.audio===`generate`&&x.audio?.describeFigures===!0?(0,h.jsx)(B4,{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)(gG,{}),(0,h.jsx)(Q5,{title:`Ambient sound`,columns:!1,children:(0,h.jsx)(JAe,{edit:n,problem:T,onChange:r})})]})]}):null,x.sources.audio===`off`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(gG,{}),(0,h.jsxs)(Q5,{title:`Pauses and volume`,columns:!1,children:[(0,h.jsx)(XAe,{edit:n,problem:T,onChange:r}),(0,h.jsx)(YAe,{edit:n,problem:T,onChange:r})]})]}),(0,h.jsx)(gG,{}),(0,h.jsx)(Q5,{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=`${kje}${i??``}`,u=i===void 0?``:s&&c!==o?.body?l:i;return(0,h.jsx)(iL,{label:e===`intro`?`Intro`:`Outro`,tip:e===`intro`?`play.intro`:`play.outro`,children:(0,h.jsxs)(sL,{value:u,onChange:i=>{if(i.target.value===l&&typeof a==`string`){r(X8({...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(X8({...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)(gG,{}),(0,h.jsx)(Q5,{title:`Research`,columns:!1,children:(0,h.jsx)(iL,{label:`Research notes`,tip:`play.provided.research`,error:T(`provided.research`),children:(0,h.jsx)(oL,{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)(dje,{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,value:(n.content.articleEdited?n.content.articleMarkdown:t.articleMarkdown)??n.content.articleMarkdown??x.provided.article??``,onChange:e=>r({...n,content:{...n.content,articleMarkdown:e,articleEdited:!0}})}),x.sources.article===`generate`?(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(z,{onClick:()=>r({...n,regenerate:[...new Set([...n.regenerate??[],`article:body`])]}),children:`Regenerate article after review`}),(0,h.jsx)(H,{id:`project.edit.regenerate-article`})]}):null]}),(0,h.jsxs)(`section`,{"aria-label":`Providers`,hidden:O!==`providers`,className:k(`providers`),children:[(0,h.jsx)(uje,{edit:n,error:T(`language`),onChange:r}),(0,h.jsx)(Cje,{projectId:t.revision.projectId,edit:n,providers:_.data?.providers??[],voices:v.data?.voices??[],onChange:r}),(0,h.jsx)(mje,{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)(Tje,{edit:n,view:t,prompts:y.data?.prompts??[],problem:T,onChange:r}),(0,h.jsx)(_je,{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)(wje,{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)(Fke,{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)(T3,{value:x.subtitles??eO,format:x.format,language:x.language,audioEnabled:x.sources.audio!==`off`,videoEnabled:j,onChange:e=>r({...n,config:{...x,subtitles:Xk(e,x.sources)}}),onUploading:d,problem:T})}),O!==`subtitles`||!j?null:(0,h.jsx)($4,{drawnOn:S?.drawnOn,poster:w,settings:{format:x.format,subtitles:{mode:(x.subtitles??eO).mode,fontId:(x.subtitles??eO).fontId,fontSize:(x.subtitles??eO).fontSize,position:(x.subtitles??eO).position??`bottom`},videoEdit:x.videoEdit,image:S?.image}})]}),e.renderContent?.({view:t,edit:n,fields:a,onChange:r,onPending:f,section:O})]})]})}var jje={"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 $5(e){let t=jje[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 e7(e){let t=new Map,n=new Map;for(let t of e.work){let e=$5(t.key);n.set(e,(n.get(e)??0)+1)}let r=new Map;for(let i of e.work){let e=$5(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)??$5(e)}function Mje({preview:e,label:t}){let n=t=>e.work.filter(e=>e.disposition===t).map(e=>e.key),r=n(`generate`),i=n(`local`),a=n(`reuse`),o=e.costs.high===0&&e.costs.rows.some(e=>e.onPlan===!0),s=[r.length===0?void 0:`Made again${o?` on your plan`:e.costs.high>0?`, charged`:``}: ${t7(r,t)}.`,i.length===0?void 0:`${r.length===0?`Rebuilt`:`Then rebuilt`} on this computer, free: ${t7(i,t)}.`,a.length===0?void 0:`Stays as it is: ${t7(a,t)}.`,r.length+i.length===0?void 0:`If anything fails, the current version stays in use and the step can be tried again.`].filter(e=>e!==void 0);return(0,h.jsx)(`ul`,{"aria-label":`What this remake does`,className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:s.map(e=>(0,h.jsx)(`li`,{children:e},e))})}function t7(e,t){let n=new Map;for(let t of e)n.set($5(t),[...n.get($5(t))??[],t]);let r=[...n].map(([e,n])=>n.length===1?t(n[0]??``):`${String(n.length)} ${Nje(e)}`);return r.length<=4?r.join(`, `):`${r.slice(0,4).join(`, `)} and ${String(r.length-4)} more`}function Nje(e){let t=/^[A-Z]{2}/.test(e)?e:e.charAt(0).toLowerCase()+e.slice(1);return/s$/u.test(t)?t:`${t}s`}function Pje({preview:e,pending:t,feedback:n,onStart:r,onCancel:i}){let a=e7(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=Ije.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:a7(e.costs.low,e.costs.high)})]})]}),(0,h.jsx)(Mje,{preview:e,label:a}),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?``:` · ~${a7(x,S)} via API`}.`}):null,d.length===0?null:(0,h.jsx)(dM,{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:Lje(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)(n7,{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)(r7,{label:`Before`,text:e.before}),(0,h.jsx)(r7,{label:`After`,text:e.after})]})]},e.label))})}):null,(0,h.jsxs)(n7,{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=>TDe(e.slot)).join(`, `)||`None`]})]}),e.costs.rows.length===0?null:(0,h.jsx)(n7,{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),`: `,Fje(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`,...Ny,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)(H,{id:`project.rebuild.keep-provided`,className:`-my-1`})]},e)),e.costs.unknown===0?null:(0,h.jsxs)(`div`,{className:`flex items-start gap-1`,...Ny,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)(H,{id:`project.rebuild.unknown-costs`,className:`-my-1`})]})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(z,{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)(z,{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 n7({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 r7({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 i7=e=>e===null?`Unknown`:P2(e);function a7(e,t){return e===t?i7(e):`${i7(e)}–${i7(t)}`}function Fje(e){return e.onPlan===!0?`$0 on plan${e.apiLow===void 0||e.apiLow===null||e.apiHigh===void 0?``:` · ~${a7(e.apiLow,e.apiHigh??null)} via API`}`:a7(e.low,e.high)}var Ije=[`generate`,`local`,`review`,`reuse`,`blocked`];function Lje(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($5)).size===1?Rje($5(n[0]??``)):`items`}`}))}function Rje(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`};function zje(e){return!e.work.some(e=>e.disposition===`blocked`)&&e.providedReuseRequired.length===0&&e.costs.unknown===0}function s7(e,t){return zje(e)?e.costs.high>0||e.work.some(e=>e.disposition===`generate`&&e.kind===`provider`)?t!==void 0&&e.costs.high<=t:!0:!1}function c7(e,t,n){let r=JSON.stringify(t);return e?.payload===r?e:{payload:r,idempotencyKey:n()}}var Bje=400;function Vje(e){return`project-revision:${e}`}function Hje(e,t,n,r){let i=Vje(e),a=(0,m.useRef)(void 0),o=(0,m.useRef)(void 0);return(0,m.useEffect)(()=>{if(n===void 0||t===void 0)return;if(!r){o.current=void 0,$A(i);return}let e=t.revision.id,a=()=>{o.current=void 0,wde(i,n,e)};o.current=a;let s=setTimeout(a,Bje);return()=>clearTimeout(s)},[i,n,t,r]),(0,m.useEffect)(()=>{let e=()=>o.current?.(),t=Ede(e);return window.addEventListener(`pagehide`,e),()=>{t(),window.removeEventListener(`pagehide`,e),e()}},[]),{waiting:()=>a.current===i?!1:QA(i,K5)!==void 0||(a.current=i,!1),take:()=>{if(a.current!==i)return a.current=i,QA(i,K5)},clear:()=>{o.current=void 0,$A(i)}}}var l7=e=>({config:structuredClone(e.revision.config),content:structuredClone(e.revision.content)});function Uje(e,t,n={}){let{api:r}=B(),i=_(),a=F({queryKey:V.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 oB(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,T]=(0,m.useState)(),[E,D]=(0,m.useState)(),O=(0,m.useRef)(void 0),k=(0,m.useRef)(void 0),A=(0,m.useRef)(void 0),j=(0,m.useRef)(n.onOpenEdit);j.current=n.onOpenEdit;let M=(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]),ee=Hje(e,o,c,M),N=c!==void 0&&o!==void 0&&t!==null&&t!==o.revision.id,te=(0,m.useRef)(!1);async function P(e){if(!te.current){te.current=!0,g(!0),x(void 0),C(void 0);try{await e()}catch(e){x(e instanceof Error?e.message:String(e))}finally{te.current=!1,g(!1)}}}async function ne(t){let n=await nB(r,e);if(!n.ok){C(n);return}return C(void 0),s(n.value.view),t&&l(l7(n.value.view)),n.value.view}async function re(){let t=ee.take();if(t===void 0)return!1;let n=await oB(r,e,t.base),i=n.ok?n.value.view:await ne(!1);return i!==void 0&&(s(i),l(t.value),T({kind:`restored`,savedAt:t.savedAt}),j.current?.(),!0)}(0,m.useEffect)(()=>{t!==null&&!te.current&&ee.waiting()&&P(async()=>{await re()})});async function ie(t){let n=await Mo(r,e);return i.setQueryData(V.project(e),n),await i.invalidateQueries({queryKey:V.revisions(e)}),!t.current||n.revisionId!==t.revision.id?(C({ok:!1,reason:`conflict`,message:`The project changed again while saving. Your edit is kept: press Reload latest and re-apply my edit, check it, then Save changes.`,currentRevisionId:n.revisionId,fields:[]}),!1):(ee.clear(),s(t),l(void 0),C(void 0),d(void 0),T(void 0),!0)}async function ae(){if(v||o===void 0||c===void 0)return;let t={baseRevisionId:o.revision.id,edit:c},n=c7(O.current,t,()=>crypto.randomUUID());O.current=n;let i=await rB(r,e,{...t,idempotencyKey:n.idempotencyKey});if(!i.ok){C(i);return}await ie(i.value.view),O.current=void 0}async function oe(t,n=u){if(n===void 0)return;let a={baseRevisionId:n.baseRevisionId,previewId:n.id,...t},o=c7(A.current,a,()=>crypto.randomUUID());A.current=o;let s=await uB(r,e,{...a,idempotencyKey:o.idempotencyKey});if(!s.ok){C(s),(s.reason===`stale-preview`||s.reason===`conflict`)&&d(void 0);return}A.current=void 0,d(void 0),await i.invalidateQueries({queryKey:V.project(e)})}async function se(t,n,i){let a=await ne(!1);if(a===void 0)return;let o=await lB(r,e,{baseRevisionId:a.revision.id,request:t});if(!o.ok){C(o);return}let s=o.value.value;if(A.current=void 0,n&&s7(s,i)){await oe({acknowledgeUnknownCosts:!1,confirmedProvidedWorkKeys:[]},s);return}d(s)}async function ce(t){let n=o??a.data??await ne(!1);if(n===void 0)return;let i={baseRevisionId:n.revision.id,targetRevisionId:t},s=c7(k.current,i,()=>crypto.randomUUID());k.current=s;let c=await iB(r,e,{...i,idempotencyKey:s.idempotencyKey});if(!c.ok){C(c);return}await ie(c.value.view),k.current=void 0}return{saved:a,view:o,edit:c,preview:u,focus:f,pending:h,uploading:v,error:b,refusal:S,unsaved:M,remoteChanged:N,notice:w,busy:h||v||c!==void 0||u!==void 0,setEdit:e=>{l(e),w?.kind!==`restored`&&w?.kind!==`reapplied`&&T(void 0)},setUploading:y,openEditor:()=>void P(async()=>{T(void 0),D(void 0),!await re()&&await ne(!0)}),discard:()=>{o!==void 0&&c!==void 0&&M?(D({view:o,edit:c}),T({kind:`discarded`})):T(void 0),ee.clear(),l(void 0),C(void 0),y(!1),O.current=void 0},undoDiscard:()=>{E!==void 0&&c===void 0&&(s(E.view),l(E.edit),D(void 0),T(void 0),j.current?.())},dismissNotice:()=>{T(void 0),D(void 0)},save:()=>void P(ae),reapply:()=>void P(async()=>{if(c===void 0||o===void 0)return;let e=c,t=o;O.current=void 0;let n=await ne(!1);n!==void 0&&(l(W5(t.revision,e,n.revision)),T({kind:`reapplied`}))}),copyEdit:()=>{c!==void 0&&o!==void 0&&bz(hje(o.revision,c)).then(e=>T({kind:`copied`,ok:e}))},reloadCurrent:()=>void P(async()=>{k.current=void 0,A.current=void 0,d(void 0),await ne(!1),await i.invalidateQueries({queryKey:V.project(e)})}),requestEdit:e=>void P(async()=>{let t=o,n=c;if(t===void 0||n===void 0){if(await re()){p({section:e.section});return}if(t=await ne(!1),t===void 0)return;n=l7(t)}l(e.change(n,t)),p({section:e.section}),j.current?.()}),regenerateNow:(t,n)=>void P(async()=>{let i=e=>({...e,regenerate:[...new Set([...e.regenerate??[],...t])]});if(c!==void 0&&M){l(i(c)),p({section:`images`}),j.current?.();return}let a=await ne(!1);if(a===void 0)return;let o=await rB(r,e,{baseRevisionId:a.revision.id,edit:i(l7(a)),idempotencyKey:crypto.randomUUID()});if(!o.ok){C(o);return}await ie(o.value.view)&&await se({kind:`selected`,workKeys:t},!0,n?.approvedUpTo)}),review:(e,t)=>void P(()=>se(e,t?.autoStart===!0,t?.approvedUpTo)),start:e=>void P(()=>oe(e)),closePreview:()=>{h||(d(void 0),A.current=void 0)},restore:e=>void P(()=>ce(e))}}function Wje({projectId:e,dirty:t}){let n=`/projects/${e}`;return(0,h.jsx)(K2,{dirty:t,leaves:e=>e!==n&&!e.startsWith(`${n}/`),askOnUnload:()=>!Ode(),tone:`primary`,title:`Leave with unsaved changes?`,consequence:`Your edit stays in this browser and comes back when you open this project again. It is not saved to the project until you press Save changes.`,confirmLabel:`Leave, keep my edit for later`,cancelLabel:`Stay and keep editing`})}var Gje={llm:`Text generation`,image:`Images`,images:`Images`,tts:`Audio`,audio:`Audio`};function u7({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)(Sl,{"aria-hidden":`true`,strokeWidth:1.75}),(0,h.jsx)(`p`,{className:`sl-callout__title m-0`,children:(0,h.jsx)(KQ,{text: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:[Gje[e.split(`.`)[0]??``]??`Project`,`: `,(0,h.jsx)(KQ,{text:t})]},`${e}:${t}`))}):null]})}var Kje=e=>vd(e);function qje({c:e}){let t=(e,t,n)=>(0,h.jsxs)(SR,{tone:e,children:[(0,h.jsx)(`span`,{className:`min-w-0 truncate`,title:t,children:t}),n]});if(e.uploading)return t(`info`,`Waiting for uploads to finish…`);let n=e.notice;return n?.kind===`restored`?t(`info`,`Restored your unsaved edit from ${Kje(n.savedAt)}.`,(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{size:`small`,variant:`quiet`,onClick:e.dismissNotice,children:`Keep`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,onClick:e.discard,children:`Discard`})]})):n?.kind===`reapplied`?t(`info`,`Your edit is laid over the latest revision. Check it, then press Save changes.`):n?.kind===`copied`?n.ok?t(`success`,`Your edit is on the clipboard.`):t(`error`,`Couldn't copy: the browser blocked the clipboard. Your edit is still kept here and in this browser.`):e.remoteChanged?t(`warning`,`A newer revision is available. Your unsaved changes are kept below and in this browser.`):(0,h.jsx)(SR,{})}function Jje({controller:e,renderEditor:t,active:n=!0,intro:r,projectId:i}){let a=e,o=i===void 0?null:(0,h.jsx)(Wje,{projectId:i,dirty:a.unsaved});if(a.view===void 0||a.edit===void 0)return(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[o,r??(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(U,{title:`Saved revision`,info:`project.saved-revision`}),a.saved.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:a.saved.error.message}),a.saved.data===void 0?null:(0,h.jsx)(`ul`,{"aria-label":`Saved output status`,className:`sl-list m-0 list-none p-0`,children:a.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:l6(e.output)}),(0,h.jsx)(`span`,{className:`sl-row__meta`,children:$3(e.state,e.output.role,e.available)})]},e.recordId))})]}),a.preview===void 0&&n?(0,h.jsx)(u7,{error:a.error,refusal:a.refusal}):null,(0,h.jsxs)(CR,{status:a.notice?.kind===`discarded`?(0,h.jsxs)(SR,{children:[(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:`Changes discarded.`}),(0,h.jsx)(z,{size:`small`,variant:`quiet`,onClick:a.undoDiscard,children:`Undo`})]}):void 0,children:[a.refusal?.reason===`conflict`&&n?(0,h.jsx)(z,{disabled:a.pending,onClick:a.reloadCurrent,children:`Reload current revision`}):null,(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(z,{disabled:a.busy,onClick:()=>a.review({kind:`allAffected`}),variant:`secondary`,children:`Choose what to remake`}),(0,h.jsx)(H,{id:`project.choose-remake`})]}),(0,h.jsx)(z,{variant:`primary`,disabled:a.busy,onClick:a.openEditor,children:`Edit project`})]})]});let s=a.remoteChanged||a.refusal?.reason===`conflict`;return(0,h.jsxs)(`form`,{"aria-label":`Edit project`,onSubmit:e=>{e.preventDefault(),a.save()},children:[o,(0,h.jsx)(`fieldset`,{disabled:a.pending,className:`m-0 min-w-0 border-0 p-0`,children:t({view:a.view,edit:a.edit,fields:a.refusal?.fields??[],onChange:a.setEdit,onPending:a.setUploading,...a.focus===void 0?{}:{focus:a.focus}})}),a.preview===void 0?(0,h.jsx)(u7,{error:a.error,refusal:a.refusal}):null,(0,h.jsxs)(CR,{status:(0,h.jsx)(qje,{c:a}),children:[s?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(z,{variant:`quiet`,disabled:a.pending,onClick:a.copyEdit,children:`Copy my edit`}),(0,h.jsx)(z,{disabled:a.pending||a.uploading,onClick:a.reapply,children:`Reload latest and re-apply my edit`})]}):null,(0,h.jsx)(z,{variant:`quiet`,disabled:a.pending||a.uploading,onClick:a.discard,children:`Discard changes`}),(0,h.jsx)(z,{variant:`primary`,type:`submit`,disabled:a.pending||a.uploading,children:`Save changes`})]})]})}var Yje=J({text:G().optional(),logicalText:G().optional(),title:G().optional(),notes:G().optional(),outline:q(G()).optional(),prompt:G().optional()});function Xje(e){if(e===null)return`No text was recorded for this part.`;try{let t=Yje.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(`
|