@gentbajko/slopify 3.8.0 → 3.8.1

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.
@@ -269,8 +269,8 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
269
269
  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),vq=Z.default.BigInt(0),yq=Z.default.BigInt(1),bq=Z.default.BigInt(2),xq=Z.default.BigInt(10),Sq=Z.default.BigInt(24),Cq=Z.default.BigInt(60),wq=Z.default.BigInt(1e3),Tq=Z.default.BigInt(1e6),Eq=Z.default.BigInt(1e9),Dq=Z.default.multiply(Z.default.BigInt(3600),Eq),Oq=Z.default.multiply(Cq,Eq),kq=Z.default.multiply(Dq,Sq);function Aq(e){return typeof e==`bigint`?Z.default.BigInt(e.toString(10)):e}function jq(e){return Z.default.equal(Z.default.remainder(e,bq),vq)}function Mq(e){return Z.default.lessThan(e,vq)?Z.default.unaryMinus(e):e}function Nq(e,t){return Z.default.lessThan(e,t)?-1:+!!Z.default.greaterThan(e,t)}function Pq(e,t){return{quotient:Z.default.divide(e,t),remainder:Z.default.remainder(e,t)}}var Fq,Iq,Lq=`slot-epochNanoSeconds`,Rq=`slot-iso-date`,zq=`slot-iso-date-time`,Bq=`slot-time`,Vq=`slot-calendar`,Hq=`slot-date-brand`,Uq=`slot-year-month-brand`,Wq=`slot-month-day-brand`,Gq=`slot-time-zone`,Kq=`slot-years`,qq=`slot-months`,Jq=`slot-weeks`,Yq=`slot-days`,Xq=`slot-hours`,Zq=`slot-minutes`,Qq=`slot-seconds`,$q=`slot-milliseconds`,eJ=`slot-microseconds`,tJ=`slot-nanoseconds`,nJ=`date`,rJ=`ym`,iJ=`md`,aJ=`time`,oJ=`datetime`,sJ=`instant`,cJ=`original`,lJ=`timezone-canonical`,uJ=`timezone-original`,dJ=`calendar-id`,fJ=`locale`,pJ=`options`,mJ=new WeakMap,hJ=Symbol.for(`@@Temporal__GetSlots`);(Fq=globalThis)[hJ]||(Fq[hJ]=function(e){return mJ.get(e)});var gJ=globalThis[hJ],_J=Symbol.for(`@@Temporal__CreateSlots`);(Iq=globalThis)[_J]||(Iq[_J]=function(e){mJ.set(e,Object.create(null))});var vJ=globalThis[_J];function yJ(e,...t){if(!e||typeof e!=`object`)return!1;let n=gJ(e);return!!n&&t.every((e=>e in n))}function Q(e,t){let n=gJ(e)?.[t];if(n===void 0)throw TypeError(`Missing internal slot ${t}`);return n}function bJ(e,t,n){let r=gJ(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 xJ={};function SJ(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))}CJ(t,e),CJ(`${t}.prototype`,e.prototype)}function CJ(e,t){let n=`%${e}%`;if(xJ[n]!==void 0)throw Error(`intrinsic ${e} already exists`);xJ[n]=t}function wJ(e){return xJ[e]}function TJ(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 EJ(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 DJ(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 OJ(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 kJ=class e{constructor(e){this.totalNs=Aq(e),this.sec=Z.default.toNumber(Z.default.divide(this.totalNs,Eq)),this.subsec=Z.default.toNumber(Z.default.remainder(this.totalNs,Eq))}static validateNew(t,n){if(Z.default.greaterThan(Mq(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(Aq(t),Aq(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),wq)),Z.default.multiply(Z.default.BigInt(i),Tq)),Z.default.multiply(Z.default.BigInt(r),Eq)),Z.default.multiply(Z.default.BigInt(n),Oq)),Z.default.multiply(Z.default.BigInt(t),Dq));return e.validateNew(s,`total`)}abs(){return new e(Mq(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),kq)),`sum`)}addToEpochNs(e){return Z.default.add(Aq(e),this.totalNs)}cmp(e){return Nq(this.totalNs,e.totalNs)}divmod(t){let{quotient:n,remainder:r}=Pq(this.totalNs,Z.default.BigInt(t));return{quotient:Z.default.toNumber(n),remainder:new e(r)}}fdiv(e){let t=Aq(e),n=Z.default.BigInt(t),{quotient:r,remainder:i}=Pq(this.totalNs,n),a=[],o,s=(Z.default.lessThan(this.totalNs,vq)?-1:1)*Math.sign(Z.default.toNumber(t));for(;!Z.default.equal(i,vq)&&a.length<50;)i=Z.default.multiply(i,xq),{quotient:o,remainder:i}=Pq(i,n),a.push(Math.abs(Z.default.toNumber(o)));return s*Number(Mq(r).toString()+`.`+a.join(``))}isZero(){return Z.default.equal(this.totalNs,vq)}round(t,n){let r=Aq(t);if(Z.default.equal(r,yq))return this;let{quotient:i,remainder:a}=Pq(this.totalNs,r),o=Z.default.lessThan(this.totalNs,vq)?`negative`:`positive`,s=Z.default.multiply(Mq(i),r),c=Z.default.add(s,r),l=Nq(Mq(Z.default.multiply(a,bq)),r),u=DJ(n,o),d=Z.default.equal(Mq(this.totalNs),s)?s:OJ(s,c,l,jq(i),u),f=o===`positive`?d:Z.default.unaryMinus(d);return e.validateNew(f,`rounding`)}sign(){return this.cmp(new e(vq))}subtract(t){return e.validateNew(Z.default.subtract(this.totalNs,t.totalNs),`difference`)}};kJ.MAX=Z.default.BigInt(`9007199254740991999999999`),kJ.ZERO=new kJ(vq);var AJ=/[A-Za-z._][A-Za-z._0-9+-]*/,jJ=RegExp(`(?:(?:[+-](?:[01][0-9]|2[0-3])(?::?[0-5][0-9])?)|(?:${AJ.source})(?:\\/(?:${AJ.source}))*)`),MJ=/(?:[+-]\d{6}|\d{4})/,NJ=/(?:0[1-9]|1[0-2])/,PJ=/(?:0[1-9]|[12]\d|3[01])/,FJ=RegExp(`(${MJ.source})(?:-(${NJ.source})-(${PJ.source})|(${NJ.source})(${PJ.source}))`),IJ=/(\d{2})(?::(\d{2})(?::(\d{2})(?:[.,](\d{1,9}))?)?|(\d{2})(?:(\d{2})(?:[.,](\d{1,9}))?)?)?/,LJ=/((?:[+-])(?:[01][0-9]|2[0-3])(?::?(?:[0-5][0-9])(?::?(?:[0-5][0-9])(?:[.,](?:\d{1,9}))?)?)?)/,RJ=RegExp(`([zZ])|${LJ.source}?`),zJ=/\[(!)?([a-z_][a-z0-9_-]*)=([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)\]/g,BJ=new RegExp([`^${FJ.source}`,`(?:(?:[tT]|\\s+)${IJ.source}(?:${RJ.source})?)?`,`(?:\\[!?(${jJ.source})\\])?`,`((?:${zJ.source})*)$`].join(``)),VJ=new RegExp([`^[tT]?${IJ.source}`,`(?:${RJ.source})?`,`(?:\\[!?${jJ.source}\\])?`,`((?:${zJ.source})*)$`].join(``)),HJ=RegExp(`^(${MJ.source})-?(${NJ.source})(?:\\[!?${jJ.source}\\])?((?:${zJ.source})*)$`),UJ=RegExp(`^(?:--)?(${NJ.source})-?(${PJ.source})(?:\\[!?${jJ.source}\\])?((?:${zJ.source})*)$`),WJ=/(\d+)(?:[.,](\d{1,9}))?/,GJ=RegExp(`(?:${WJ.source}H)?(?:${WJ.source}M)?(?:${WJ.source}S)?`),KJ=RegExp(`^([+-])?P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?!$)${GJ.source})?$`,`i`),qJ=864e5,JJ=1e6*qJ,YJ=6e10,XJ=1e8*qJ,ZJ=YQ(XJ),QJ=Z.default.unaryMinus(ZJ),$J=Z.default.add(Z.default.subtract(QJ,kq),yq),eY=Z.default.subtract(Z.default.add(ZJ,kq),yq),tY=146097*qJ,nY=-271821,rY=275760,iY=Date.UTC(1847,0,1),aY=[`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`],oY=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 sY(e){return typeof e==`object`&&!!e||typeof e==`function`}function cY(e){if(typeof e==`bigint`)throw TypeError(`Cannot convert BigInt to number`);return Number(e)}function lY(e){if(typeof e==`symbol`)throw TypeError(`Cannot convert a Symbol value to a String`);return String(e)}function uY(e){let t=cY(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 dY(e,t){let n=uY(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 fY(e){let t=cY(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 pY(e,t){return String(e).padStart(t,`0`)}function mY(e){if(typeof e!=`string`)throw TypeError(`expected a string, not ${String(e)}`);return e}function hY(e,t){if(sY(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 gY=[`era`,`eraYear`,`year`,`month`,`monthCode`,`day`,`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],_Y={era:lY,eraYear:uY,year:uY,month:dY,monthCode:function(e){let t=mY(hY(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:dY,hour:uY,minute:uY,second:uY,millisecond:uY,microsecond:uY,nanosecond:uY,offset:function(e){let t=mY(hY(e));return SZ(t),t},timeZone:eZ},vY={hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},yY=[[`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`]],bY=Object.fromEntries(yY.map((e=>[e[0],e[1]]))),xY=Object.fromEntries(yY.map((([e,t])=>[t,e]))),SY=yY.map((([,e])=>e)),CY={day:JJ,hour:36e11,minute:6e10,second:1e9,millisecond:1e6,microsecond:1e3,nanosecond:1},wY=[`days`,`hours`,`microseconds`,`milliseconds`,`minutes`,`months`,`nanoseconds`,`seconds`,`weeks`,`years`],TY=Intl.DateTimeFormat,EY=new Map;function DY(e){let t=i$(e),n=EY.get(t);return n===void 0&&(n=new TY(`en-us`,{timeZone:t,hour12:!1,era:`short`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`}),EY.set(t,n)),n}function OY(e){return yJ(e,Lq)&&!yJ(e,Gq,Vq)}function kY(e){return yJ(e,Kq,qq,Yq,Xq,Zq,Qq,$q,eJ,tJ)}function AY(e){return yJ(e,Hq)}function jY(e){return yJ(e,Bq)}function MY(e){return yJ(e,zq)}function NY(e){return yJ(e,Uq)}function PY(e){return yJ(e,Wq)}function FY(e){return yJ(e,Lq,Gq,Vq)}function $(e,t){if(!t(e))throw TypeError(`invalid receiver: method called with the wrong type of this-object`)}function IY(e){if(yJ(e,Vq)||yJ(e,Gq))throw TypeError(`with() does not support a calendar or timeZone property`);if(jY(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 LY(e,t){return t===`never`||t===`auto`&&e===`iso8601`?``:`[${t===`critical`?`!`:``}u-ca=${e}]`}function RY(e){let t,n,r=!1;for(zJ.lastIndex=0;n=zJ.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 zY(e){let t=BJ.exec(e);if(!t)throw RangeError(`invalid RFC 9557 string: ${e}`);let n=RY(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 $Z(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 BY(e){let t=VJ.exec(e),n,r,i,a,o,s,c;if(t){c=RY(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}=zY(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(QZ(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}=HY(e);XZ(1972,t,n)}catch{try{let{year:t,month:n}=VY(e);XZ(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 VY(e){let t=HJ.exec(e),n,r,i,a;if(t){i=RY(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}=zY(e),t)throw RangeError(`Z designator not supported for PlainYearMonth`)}return{year:n,month:r,calendar:i,referenceISODay:a}}function HY(e){let t=UJ.exec(e),n,r,i,a;if(t){if(i=RY(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}=zY(e),t)throw RangeError(`Z designator not supported for PlainMonthDay`)}return{month:n,day:r,calendar:i,referenceISOYear:a}}var UY=RegExp(`^${jJ.source}$`,`i`),WY=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])?)?$`);function GY(e){let t=fde.test(e)?`Seconds not allowed in offset time zone`:`Invalid time zone`;throw RangeError(`${t}: ${e}`)}function KY(e){return UY.test(e)||GY(e),WY.test(e)?{offsetMinutes:SZ(e)/6e10}:{tzName:e}}function qY(e,t,n,r){let i=e,a=t,o=n;switch(r){case`reject`:XZ(i,a,o);break;case`constrain`:({year:i,month:a,day:o}=JZ(i,a,o))}return{year:i,month:a,day:o}}function JY(e,t,n,r,i,a,o){let s=e,c=t,l=n,u=r,d=i,f=a;switch(o){case`reject`:QZ(s,c,l,u,d,f);break;case`constrain`:s=qZ(s,0,23),c=qZ(c,0,59),l=qZ(l,0,59),u=qZ(u,0,999),d=qZ(d,0,999),f=qZ(f,0,999)}return{hour:s,minute:c,second:l,millisecond:u,microsecond:d,nanosecond:f}}function YY(e){if(!sY(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<wY.length;r++){let i=wY[r],a=e[i];a!==void 0&&(n=!0,t[i]=fY(a))}if(!n)throw TypeError(`invalid duration-like`);return t}function XY({years:e,months:t,weeks:n,days:r},i,a,o){return{years:e,months:o??t,weeks:a??n,days:i??r}}function ZY(e,t){return{isoDate:e,time:t}}function QY(e){return n$(e,`overflow`,[`constrain`,`reject`],`constrain`)}function $Y(e){return n$(e,`disambiguation`,[`compatible`,`earlier`,`later`,`reject`],`compatible`)}function eX(e,t){return n$(e,`roundingMode`,[`ceil`,`floor`,`expand`,`trunc`,`halfCeil`,`halfFloor`,`halfExpand`,`halfTrunc`,`halfEven`],t)}function tX(e,t){return n$(e,`offset`,[`prefer`,`use`,`ignore`,`reject`],t)}function nX(e){return n$(e,`calendarName`,[`auto`,`always`,`never`,`critical`],`auto`)}function rX(e){let t=e.roundingIncrement;if(t===void 0)return 1;let n=uY(t);if(n<1||n>1e9)throw RangeError(`roundingIncrement must be at least 1 and at most 1e9, not ${t}`);return n}function iX(e,t,n){let r=n?t:t-1;if(e>r)throw RangeError(`roundingIncrement must be at least 1 and less than ${r}, not ${e}`);if(t%e!=0)throw RangeError(`Rounding increment must divide evenly into ${t}`)}function aX(e){let t=e.fractionalSecondDigits;if(t===void 0)return`auto`;if(typeof t!=`number`){if(lY(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 oX(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 sX=Symbol(`~required~`);function cX(e,t,n,r,i=[]){let a=[];for(let e=0;e<yY.length;e++){let t=yY[e],r=t[1],i=t[2];n!==`datetime`&&n!==i||a.push(r)}a=a.concat(i);let o=r;o===sX?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=xY[a[e]];t!==void 0&&s.push(t)}let c=n$(e,t,s,o);if(c===void 0&&r===sX)throw RangeError(`${t} is required`);return c&&c in bY?bY[c]:c}function lX(e){let t=e.relativeTo;if(t===void 0)return{};let n,r,i,a,o,s=`option`,c=!1;if(sY(t)){if(FY(t))return{zonedRelativeTo:t};if(AY(t))return{plainRelativeTo:t};if(MY(t))return{plainRelativeTo:jX(Q(t,zq).isoDate,Q(t,Vq))};i=YX(t);let e=_X(i,t,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`,`timeZone`],[]);({isoDate:n,time:r}=bX(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}=zY(mY(t)),e)a=eZ(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=r$(i),n={year:u,month:d,day:f}}return a===void 0?{plainRelativeTo:jX(n,i)}:{zonedRelativeTo:UX(OX(n,r,s,s===`option`?SZ(o):0,a,`compatible`,`reject`,c),a,i)}}function uX(e){return Q(e,Kq)===0?Q(e,qq)===0?Q(e,Jq)===0?Q(e,Yq)===0?Q(e,Xq)===0?Q(e,Zq)===0?Q(e,Qq)===0?Q(e,$q)===0?Q(e,eJ)===0?`nanosecond`:`microsecond`:`millisecond`:`second`:`minute`:`hour`:`day`:`week`:`month`:`year`}function dX(e,t){return SY.indexOf(e)>SY.indexOf(t)?t:e}function fX(e){return e===`year`||e===`month`||e===`week`}function pX(e){return fX(e)||e===`day`?`date`:`time`}function mX(e){return wJ(`%calendarImpl%`)(e)}function hX(e){return wJ(`%calendarImpl%`)(Q(e,Vq))}function gX(e,t,n=`date`){let r=Object.create(null),i=mX(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 _X(e,t,n,r,i){let a=mX(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,_Y[n])(r);else if(i!==`partial`){if(i.includes(n))throw TypeError(`required property '${n}' missing or undefined`);s[n]=vY[n]}}if(i===`partial`&&!c)throw TypeError(`no supported properties found`);return s}function vX(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]=uY(s),r=!0)}if(!r)throw TypeError(`invalid time-like`);return i}function yX(e,t){if(sY(e)){if(AY(e))return QY(e$(t)),jX(Q(e,Rq),Q(e,Vq));if(FY(e)){let n=iZ(Q(e,Gq),Q(e,Lq));return QY(e$(t)),jX(n.isoDate,Q(e,Vq))}if(MY(e))return QY(e$(t)),jX(Q(e,zq).isoDate,Q(e,Vq));let n=YX(e);return jX(ZX(n,_X(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),QY(e$(t))),n)}let{year:n,month:r,day:i,calendar:a,z:o}=zY(mY(e));if(o)throw RangeError(`Z designator not supported for PlainDate`);return a||=`iso8601`,a=r$(a),QY(e$(t)),jX({year:n,month:r,day:i},a)}function bX(e,t,n){return ZY(ZX(e,t,n),JY(t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond,n))}function xX(e,t){let n,r,i;if(sY(e)){if(MY(e))return QY(e$(t)),NX(Q(e,zq),Q(e,Vq));if(FY(e)){let n=iZ(Q(e,Gq),Q(e,Lq));return QY(e$(t)),NX(n,Q(e,Vq))}if(AY(e))return QY(e$(t)),NX(ZY(Q(e,Rq),{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),Q(e,Vq));i=YX(e);let a=_X(i,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],[]),o=QY(e$(t));({isoDate:n,time:r}=bX(i,a,o))}else{let a,o,s,c;if({year:o,month:s,day:c,time:r,calendar:i,z:a}=zY(mY(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}),$Z(o,s,c,r.hour,r.minute,r.second,r.millisecond,r.microsecond,r.nanosecond),i||=`iso8601`,i=r$(i),QY(e$(t)),n={year:o,month:s,day:c}}return NX(ZY(n,r),i)}function SX(e){let t=wJ(`%Temporal.Duration%`);if(kY(e))return new t(Q(e,Kq),Q(e,qq),Q(e,Jq),Q(e,Yq),Q(e,Xq),Q(e,Zq),Q(e,Qq),Q(e,$q),Q(e,eJ),Q(e,tJ));if(!sY(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=KJ.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:uY(t[2])*n,i=t[3]===void 0?0:uY(t[3])*n,a=t[4]===void 0?0:uY(t[4])*n,o=t[5]===void 0?0:uY(t[5])*n,s=t[6]===void 0?0:uY(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*uY((c+`000000000`).slice(0,9))*n}else if(p=l===void 0?0:uY(l)*n,u!==void 0){if(d??f)throw RangeError(`only the smallest unit can be fractional`);h=60*uY((u+`000000000`).slice(0,9))*n}else m=d===void 0?0:uY(d)*n,f!==void 0&&(h=uY((f+`000000000`).slice(0,9))*n);let g=h%1e3,_=Math.trunc(h/1e3)%1e3,v=Math.trunc(h/1e6)%1e3;return m+=Math.trunc(h/1e9)%60,p+=Math.trunc(h/6e10),iQ(r,i,a,o,s,p,m,v,_,g),{years:r,months:i,weeks:a,days:o,hours:s,minutes:p,seconds:m,milliseconds:v,microseconds:_,nanoseconds:g}}(e);return new(wJ(`%Temporal.Duration%`))(t,n,r,i,a,o,s,c,l,u)}(mY(e));let n={years:0,months:0,weeks:0,days:0,hours:0,minutes:0,seconds:0,milliseconds:0,microseconds:0,nanoseconds:0},r=YY(e);for(let e=0;e<wY.length;e++){let t=wY[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 CX(e){let t;if(sY(e)){if(OY(e)||FY(e))return VX(Q(e,Lq));t=hY(e)}else t=e;let{year:n,month:r,day:i,time:a,offset:o,z:s}=function(e){let t=zY(e);if(!t.z&&!t.offset)throw RangeError(`Temporal.Instant requires a time zone offset`);return t}(mY(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=UZ(n,r,i,c,l,u,d,f,p-(s?0:SZ(o)));return dQ(m.isoDate),VX(jZ(m))}function wX(e,t){if(sY(e)){if(PY(e))return QY(e$(t)),FX(Q(e,Rq),Q(e,Vq));let n;return yJ(e,Vq)?n=Q(e,Vq):(n=e.calendar,n===void 0&&(n=`iso8601`),n=JX(n)),FX($X(n,_X(n,e,[`year`,`month`,`monthCode`,`day`],[],[]),QY(e$(t))),n)}let{month:n,day:r,referenceISOYear:i,calendar:a}=HY(mY(e));if(a===void 0&&(a=`iso8601`),a=r$(a),QY(e$(t)),a===`iso8601`)return FX({year:1972,month:n,day:r},a);let o={year:i,month:n,day:r};return ZZ(o),o=$X(a,gX(a,o,`month-day`),`constrain`),FX(o,a)}function TX(e,t){let n;if(sY(e)){if(jY(e))return QY(e$(t)),LX(Q(e,Bq));if(MY(e))return QY(e$(t)),LX(Q(e,zq).time);if(FY(e)){let n=iZ(Q(e,Gq),Q(e,Lq));return QY(e$(t)),LX(n.time)}let{hour:r,minute:i,second:a,millisecond:o,microsecond:s,nanosecond:c}=vX(e);n=JY(r,i,a,o,s,c,QY(e$(t)))}else n=BY(mY(e)),QY(e$(t));return LX(n)}function EX(e){return e===void 0?{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}:Q(TX(e),Bq)}function DX(e,t){if(sY(e)){if(NY(e))return QY(e$(t)),zX(Q(e,Rq),Q(e,Vq));let n=YX(e);return zX(QX(n,_X(n,e,[`year`,`month`,`monthCode`],[],[]),QY(e$(t))),n)}let{year:n,month:r,referenceISODay:i,calendar:a}=VY(mY(e));a===void 0&&(a=`iso8601`),a=r$(a),QY(e$(t));let o={year:n,month:r,day:i};return rQ(o),o=QX(a,gX(a,o,`year-month`),`constrain`),zX(o,a)}function OX(e,t,n,r,i,a,o,s){if(t===`start-of-day`)return cZ(i,e);let c=ZY(e,t);if(n===`wall`||o===`ignore`)return aZ(i,c,a);if(n===`exact`||o===`use`){let n=UZ(e.year,e.month,e.day,t.hour,t.minute,t.second,t.millisecond,t.microsecond,t.nanosecond-r);dQ(n.isoDate);let i=jZ(n);return nQ(i),i}dQ(e);let l=jZ(c),u=sZ(i,c);for(let e=0;e<u.length;e++){let t=u[e],n=Z.default.toNumber(Z.default.subtract(l,t)),i=RQ(n,6e10,`halfExpand`);if(n===r||s&&i===r)return t}if(o===`reject`){let e=rZ(r),t=_Z(c,`iso8601`,`auto`);throw RangeError(`Offset ${e} is invalid for ${t} in ${i}`)}return oZ(u,i,c,a)}function kX(e,t){let n,r,i,a,o,s,c,l=!1,u=`option`;if(sY(e)){if(FY(e)){let n=e$(t);return $Y(n),tX(n,`reject`),QY(n),UX(Q(e,Lq),Q(e,Gq),Q(e,Vq))}o=YX(e);let l=_X(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=e$(t);s=$Y(d),c=tX(d,`reject`);let f=QY(d);({isoDate:n,time:r}=bX(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=zY(e);if(!t.tzAnnotation)throw RangeError(`Temporal.ZonedDateTime requires a time zone ID in brackets`);return t}(mY(e))),i=eZ(d),f?u=`exact`:a||(u=`wall`),o||=`iso8601`,o=r$(o),l=!0;let g=e$(t);s=$Y(g),c=tX(g,`reject`),QY(g),n={year:p,month:m,day:h}}let d=0;return u===`option`&&(d=SZ(a)),UX(OX(n,r,u,d,i,s,c,l),i,o)}function AX(e,t,n){ZZ(t),vJ(e),bJ(e,Rq,t),bJ(e,Vq,n),bJ(e,Hq,!0)}function jX(e,t){let n=wJ(`%Temporal.PlainDate%`),r=Object.create(n.prototype);return AX(r,e,t),r}function MX(e,t,n){eQ(t),vJ(e),bJ(e,zq,t),bJ(e,Vq,n)}function NX(e,t){let n=wJ(`%Temporal.PlainDateTime%`),r=Object.create(n.prototype);return MX(r,e,t),r}function PX(e,t,n){ZZ(t),vJ(e),bJ(e,Rq,t),bJ(e,Vq,n),bJ(e,Wq,!0)}function FX(e,t){let n=wJ(`%Temporal.PlainMonthDay%`),r=Object.create(n.prototype);return PX(r,e,t),r}function IX(e,t){vJ(e),bJ(e,Bq,t)}function LX(e){let t=wJ(`%Temporal.PlainTime%`),n=Object.create(t.prototype);return IX(n,e),n}function RX(e,t,n){rQ(t),vJ(e),bJ(e,Rq,t),bJ(e,Vq,n),bJ(e,Uq,!0)}function zX(e,t){let n=wJ(`%Temporal.PlainYearMonth%`),r=Object.create(n.prototype);return RX(r,e,t),r}function BX(e,t){nQ(t),vJ(e),bJ(e,Lq,t)}function VX(e){let t=wJ(`%Temporal.Instant%`),n=Object.create(t.prototype);return BX(n,e),n}function HX(e,t,n,r){nQ(t),vJ(e),bJ(e,Lq,t),bJ(e,Gq,n),bJ(e,Vq,r)}function UX(e,t,n=`iso8601`){let r=wJ(`%Temporal.ZonedDateTime%`),i=Object.create(r.prototype);return HX(i,e,t,n),i}function WX(e){return gY.filter((t=>e[t]!==void 0))}function GX(e,t,n){let r=WX(n),i=mX(e).fieldKeysToIgnore(r),a=Object.create(null),o=WX(t);for(let e=0;e<gY.length;e++){let s,c=gY[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 KX(e,t,n,r){let i=mX(e).dateAdd(t,n,r);return ZZ(i),i}function qX(e,t,n,r){return mX(e).dateUntil(t,n,r)}function JX(e){if(sY(e)&&yJ(e,Vq))return Q(e,Vq);let t=mY(e);try{return r$(t)}catch{}let n;try{({calendar:n}=zY(t))}catch{try{({calendar:n}=BY(t))}catch{try{({calendar:n}=VY(t))}catch{({calendar:n}=HY(t))}}}return n||=`iso8601`,r$(n)}function YX(e){if(yJ(e,Vq))return Q(e,Vq);let{calendar:t}=e;return t===void 0?`iso8601`:JX(t)}function XX(e,t){return r$(e)===r$(t)}function ZX(e,t,n){let r=mX(e);r.resolveFields(t,`date`);let i=r.dateToISO(t,n);return ZZ(i),i}function QX(e,t,n){let r=mX(e);r.resolveFields(t,`year-month`),t.day=1;let i=r.dateToISO(t,n);return rQ(i),i}function $X(e,t,n){let r=mX(e);r.resolveFields(t,`month-day`);let i=r.monthDayToISOReferenceDate(t,n);return ZZ(i),i}function eZ(e){if(sY(e)&&FY(e))return Q(e,Gq);let t=mY(e);if(t===`UTC`)return`UTC`;let{tzName:n,offsetMinutes:r}=function(e){let{tzAnnotation:t,offset:n,z:r}=function(e){if(UY.test(e))return{tzAnnotation:e,offset:void 0,z:!1};try{let{tzAnnotation:t,offset:n,z:r}=zY(e);if(r||t||n)return{tzAnnotation:t,offset:n,z:r}}catch{}GY(e)}(e);return t?KY(t):r?KY(`UTC`):n?KY(n):void 0}(t);if(r!==void 0)return OZ(r);let i=TZ(n);if(!i)throw RangeError(`Unrecognized time zone ${n}`);return i.identifier}function tZ(e,t){if(e===t)return!0;let n=KY(e).offsetMinutes,r=KY(t).offsetMinutes;if(n===void 0&&r===void 0){let n=TZ(t);if(!n)return!1;let r=TZ(e);return!!r&&r.primaryIdentifier===n.primaryIdentifier}return n===r}function nZ(e,t){let n=KY(e).offsetMinutes;return n===void 0?DZ(e,t):6e10*n}function rZ(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}${fZ(r,i,a,o,a===0&&o===0?`minute`:`auto`)}`}function iZ(e,t){let n=nZ(e,t),{isoDate:{year:r,month:i,day:a},time:{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d}}=MZ(t);return UZ(r,i,a,o,s,c,l,u,d+n)}function aZ(e,t,n){return oZ(sZ(e,t),e,t,n)}function oZ(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=jZ(n),o=Z.default.subtract(a,kq);nQ(o);let s=nZ(t,o),c=Z.default.add(a,kq);nQ(c);let l=nZ(t,c)-s;switch(r){case`earlier`:{let e=kJ.fromComponents(0,0,0,0,0,-l),r=OQ(n.time,e);return sZ(t,ZY(HZ(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r))[0]}case`compatible`:case`later`:{let e=kJ.fromComponents(0,0,0,0,0,l),r=OQ(n.time,e),i=sZ(t,ZY(HZ(n.isoDate.year,n.isoDate.month,n.isoDate.day+r.deltaDays),r));return i[i.length-1]}}}function sZ(e,t){if(e===`UTC`)return dQ(t.isoDate),[jZ(t)];let n=KY(e).offsetMinutes;if(n!==void 0){let e=UZ(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);dQ(e.isoDate);let r=jZ(e);return nQ(r),[r]}return dQ(t.isoDate),function(e,t){let n=jZ(t),r=Z.default.subtract(n,kq);Z.default.lessThan(r,QJ)&&(r=n);let i=Z.default.add(n,kq);Z.default.greaterThan(i,ZJ)&&(i=n);let a=DZ(e,r),o=DZ(e,i);return(a===o?[a]:[a,o]).map((r=>{let i=Z.default.subtract(n,Z.default.BigInt(r));if(KQ(t,function(e,t){let{epochMilliseconds:n,time:{millisecond:r,microsecond:i,nanosecond:a}}=MZ(t),{year:o,month:s,day:c,hour:l,minute:u,second:d}=FZ(e,n);return UZ(o,s,c,l,u,d,r,i,a)}(e,i))===0)return nQ(i),i})).filter((e=>e!==void 0))}(e,t)}function cZ(e,t){let n=ZY(t,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),r=sZ(e,n);if(r.length)return r[0];let i=jZ(n),a=Z.default.subtract(i,kq);return nQ(a),NZ(e,a)}function lZ(e){let t;return t=e<0||e>9999?(e<0?`-`:`+`)+pY(Math.abs(e),6):pY(e,4),t}function uZ(e){return pY(e,2)}function dZ(e,t){let n;if(t===`auto`){if(e===0)return``;n=pY(e,9).replace(/0+$/,``)}else{if(t===0)return``;n=pY(e,9).slice(0,t)}return`.${n}`}function fZ(e,t,n,r,i){let a=`${uZ(e)}:${uZ(t)}`;return i===`minute`||(a+=`:${uZ(n)}`,a+=dZ(r,i)),a}function pZ(e,t,n){let r=t;r===void 0&&(r=`UTC`);let i=Q(e,Lq),a=_Z(iZ(r,i),`iso8601`,n,`never`),o=`Z`;return t!==void 0&&(o=kZ(nZ(r,i))),`${a}${o}`}function mZ(e,t){let n=Q(e,Kq),r=Q(e,qq),i=Q(e,Jq),a=Q(e,Yq),o=Q(e,Xq),s=Q(e,Zq),c=RZ(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=kJ.fromComponents(0,0,Q(e,Qq),Q(e,$q),Q(e,eJ),Q(e,tJ));d.isZero()&&![`second`,`millisecond`,`microsecond`,`nanosecond`].includes(uX(e))&&t===`auto`||(u+=`${Math.abs(d.sec)}${dZ(Math.abs(d.subsec),t)}S`);let f=`${c<0?`-`:``}P${l}`;return u&&(f=`${f}T${u}`),f}function hZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,Rq);return`${lZ(n)}-${uZ(r)}-${uZ(i)}${LY(Q(e,Vq),t)}`}function gZ({hour:e,minute:t,second:n,millisecond:r,microsecond:i,nanosecond:a},o){return fZ(e,t,n,1e6*r+1e3*i+a,o)}function _Z(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`${lZ(i)}-${uZ(a)}-${uZ(o)}T${fZ(s,c,l,1e6*u+1e3*d+f,n)}${LY(t,r)}`}function vZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,Rq),a=`${uZ(r)}-${uZ(i)}`,o=Q(e,Vq);t!==`always`&&t!==`critical`&&o===`iso8601`||(a=`${lZ(n)}-${a}`);let s=LY(o,t);return s&&(a+=s),a}function yZ(e,t=`auto`){let{year:n,month:r,day:i}=Q(e,Rq),a=`${lZ(n)}-${uZ(r)}`,o=Q(e,Vq);t!==`always`&&t!==`critical`&&o===`iso8601`||(a+=`-${uZ(i)}`);let s=LY(o,t);return s&&(a+=s),a}function bZ(e,t,n=`auto`,r=`auto`,i=`auto`,a=void 0){let o=Q(e,Lq);if(a){let{unit:e,increment:t,roundingMode:n}=a;o=zQ(o,t,e,n)}let s=Q(e,Gq),c=nZ(s,o),l=_Z(iZ(s,o),`iso8601`,t,`never`);return i!==`never`&&(l+=kZ(c)),r!==`never`&&(l+=`[${r===`critical`?`!`:``}${s}]`),l+=LY(Q(e,Vq),n),l}function xZ(e){return WY.test(e)}function SZ(e){let t=pde.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 CZ,wZ=Object.assign(Object.create(null),{"/":!0,"-":!0,_:!0});function TZ(e){if(CZ===void 0){let e=Intl.supportedValuesOf?.(`timeZone`);if(e){CZ=new Map;for(let t=0;t<e.length;t++){let n=e[t];CZ.set(i$(n),n)}}else CZ=null}let t=i$(e),n=CZ?.get(t);if(n)return{identifier:n,primaryIdentifier:n};try{n=DY(e).resolvedOptions().timeZone}catch{return}if(t===`antarctica/south_pole`&&(n=`Antarctica/McMurdo`),oY.has(e))throw RangeError(`${e} is a legacy time zone identifier from ICU. Use ${n} instead`);let r=[...t].map(((e,n)=>n===0||wZ[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 EZ(e,t){let{year:n,month:r,day:i,hour:a,minute:o,second:s}=FZ(e,t),c=t%1e3;return c<0&&(c+=1e3),1e6*(AZ({isoDate:{year:n,month:r,day:i},time:{hour:a,minute:o,second:s,millisecond:c}})-t)}function DZ(e,t){return EZ(e,JQ(t,`floor`))}function OZ(e){let t=e<0?`-`:`+`,n=Math.abs(e);return`${t}${fZ(Math.floor(n/60),n%60,0,0,`minute`)}`}function kZ(e){return OZ(RQ(e,YJ,`halfExpand`)/6e10)}function AZ({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()+tY*c}function jZ(e){let t=AZ(e),n=1e3*e.time.microsecond+e.time.nanosecond;return Z.default.add(YQ(t),Z.default.BigInt(n))}function MZ(e){let t=JQ(e,`trunc`),n=Z.default.toNumber(Z.default.remainder(e,Tq));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 NZ(e,t){if(e===`UTC`)return null;let n=JQ(t,`floor`);if(n<iY)return NZ(e,YQ(iY));let r=Math.max(n,Date.now())+366*qJ*3,i=n,a=EZ(e,i),o=i,s=a;for(;a===s&&i<r;){if(o=i+2*qJ*7,o>XJ)return null;s=EZ(e,o),a===s&&(i=o)}return a===s?null:YQ(o$((t=>EZ(e,t)),i,o,a,s))}function PZ(e,t){if(e===`UTC`)return null;let n=JQ(t,`ceil`),r=Date.now(),i=r+366*qJ*3;if(n>i){let t=PZ(e,YQ(i));if(t===null||Z.default.lessThan(t,YQ(r)))return t}if(e===`Africa/Casablanca`||e===`Africa/El_Aaiun`){let t=Date.UTC(2088,0,1);if(t<n)return PZ(e,YQ(t))}let a=n-1;if(a<iY)return null;let o=EZ(e,a),s=a,c=o;for(;o===c&&a>iY;){if(s=a-2*qJ*7,s<iY)return null;c=EZ(e,s),o===c&&(a=s)}return o===c?null:YQ(o$((t=>EZ(e,t)),s,a,c,o))}function FZ(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}}(DY(e).format(t))}function IZ(e){return e!==void 0&&!(e%4!=0||e%100==0&&e%400!=0)}function LZ(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]}[IZ(e)?`leapyear`:`standard`][t-1]}function RZ(e){let t=[Q(e,Kq),Q(e,qq),Q(e,Jq),Q(e,Yq),Q(e,Xq),Q(e,Zq),Q(e,Qq),Q(e,$q),Q(e,eJ),Q(e,tJ)];for(let e=0;e<t.length;e++){let n=t[e];if(n!==0)return n<0?-1:1}return 0}function zZ(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 BZ(e){let t=zZ(e.date);return t===0?e.time.sign():t}function VZ(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 HZ(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}=VZ(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=IZ(c)?366:365,a<-s;)--r,--c,a+=s;for(c+=1;s=IZ(c)?366:365,a>s;)r+=1,c+=1,a-=s;for(;a<1;)({year:r,month:i}=VZ(r,i-1)),a+=LZ(r,i);for(;a>LZ(r,i);)a-=LZ(r,i),{year:r,month:i}=VZ(r,i+1);return{year:r,month:i,day:a}}function UZ(e,t,n,r,i,a,o,s,c){let l=WZ(r,i,a,o,s,c);return ZY(HZ(e,t,n+l.deltaDays),l)}function WZ(e,t,n,r,i,a){let o,s=e,c=t,l=n,u=r,d=i,f=a;({div:o,mod:f}=TJ(f,3)),d+=o,f<0&&(--d,f+=1e3),{div:o,mod:d}=TJ(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 GZ(e,t){let n=XY(e,0);if(zZ(n)===0)return e.days;let r=Q(t,Rq),i=KX(Q(t,Vq),r,n,`constrain`),a=uQ(r.year,r.month-1,r.day),o=uQ(i.year,i.month-1,i.day)-a;return e.days+o}function KZ(e){return new(wJ(`%Temporal.Duration%`))(-Q(e,Kq),-Q(e,qq),-Q(e,Jq),-Q(e,Yq),-Q(e,Xq),-Q(e,Zq),-Q(e,Qq),-Q(e,$q),-Q(e,eJ),-Q(e,tJ))}function qZ(e,t,n){return Math.min(n,Math.max(t,e))}function JZ(e,t,n){let r=qZ(t,1,12);return{year:e,month:r,day:qZ(n,1,LZ(e,r))}}function YZ(e,t,n){if(e<t||e>n)throw RangeError(`value out of range: ${t} <= ${e} <= ${n}`)}function XZ(e,t,n){YZ(t,1,12),YZ(n,1,LZ(e,t))}function ZZ(e){eQ(ZY(e,{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}))}function QZ(e,t,n,r,i,a){YZ(e,0,23),YZ(t,0,59),YZ(n,0,59),YZ(r,0,999),YZ(i,0,999),YZ(a,0,999)}function $Z(e,t,n,r,i,a,o,s,c){XZ(e,t,n),QZ(r,i,a,o,s,c)}function eQ(e){let t=jZ(e);(Z.default.lessThan(t,$J)||Z.default.greaterThan(t,eY))&&nQ(t)}function tQ(e){jZ(e)}function nQ(e){if(Z.default.lessThan(e,QJ)||Z.default.greaterThan(e,ZJ))throw RangeError(`date/time value is outside of supported range`)}function rQ({year:e,month:t}){YZ(e,nY,rY),e===nY?YZ(t,4,12):e===rY&&YZ(t,1,9)}function iQ(e,t,n,r,i,a,o,s,c,l){let u=0,d=[e,t,n,r,i,a,o,s,c,l];for(let e=0;e<d.length;e++){let t=d[e];if(t===1/0||t===-1/0)throw RangeError(`infinite values not allowed as duration fields`);if(t!==0){let e=t<0?-1:1;if(u!==0&&e!==u)throw RangeError(`mixed-sign values not allowed as duration fields`);u=e}}if(Math.abs(e)>=2**32||Math.abs(t)>=2**32||Math.abs(n)>=2**32)throw RangeError(`years, months, and weeks must be < 2³²`);let f=TJ(s,3),p=TJ(c,6),m=TJ(l,9),h=TJ(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 aQ(e){return{date:{years:Q(e,Kq),months:Q(e,qq),weeks:Q(e,Jq),days:Q(e,Yq)},time:kJ.fromComponents(Q(e,Xq),Q(e,Zq),Q(e,Qq),Q(e,$q),Q(e,eJ),Q(e,tJ))}}function oQ(e){let t=kJ.fromComponents(Q(e,Xq),Q(e,Zq),Q(e,Qq),Q(e,$q),Q(e,eJ),Q(e,tJ)).add24HourDays(Q(e,Yq));return{date:{years:Q(e,Kq),months:Q(e,qq),weeks:Q(e,Jq),days:0},time:t}}function sQ(e){let t=oQ(e),n=Math.trunc(t.time.sec/86400);return iQ(t.date.years,t.date.months,t.date.weeks,n,0,0,0,0,0,0),{...t.date,days:n}}function cQ(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=EJ(o,3,Math.trunc(i/1e3)),i%=1e3,o=0;break;case`microsecond`:i=EJ(o,6,Math.trunc(r/1e3)),r%=1e3,o=0;break;case`nanosecond`:r=EJ(o,9,r),o=0}return new(wJ(`%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 lQ(e,t){return zZ(e),t.sign(),{date:e,time:t}}function uQ(e,t,n){return AZ({isoDate:{year:e,month:t+1,day:n},time:{hour:0,minute:0,second:0,millisecond:0}})/qJ}function dQ({year:e,month:t,day:n}){if(Math.abs(uQ(e,t-1,n))>1e8)throw RangeError(`date/time value is outside the supported range`)}function fQ(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 kJ.fromComponents(n,r,i,a,o,s)}function pQ(e,t,n,r,i){let a=kJ.fromEpochNsDiff(t,e);return a=HQ(a,n,r,i),lQ({years:0,months:0,weeks:0,days:0},a)}function mQ(e,t,n,r){tQ(e),tQ(t);let i=fQ(e.time,t.time),a=i.sign(),o=WQ(e.isoDate,t.isoDate),s=t.isoDate;o===a&&(s=HZ(s.year,s.month,s.day+a),i=i.add24HourDays(-a));let c=dX(`day`,r),l=qX(n,e.isoDate,s,c);return r!==c&&(i=i.add24HourDays(l.days),l.days=0),lQ(l,i)}function hQ(e,t,n,r,i){let a=Z.default.subtract(t,e);if(Z.default.equal(a,vq))return{date:{years:0,months:0,weeks:0,days:0},time:kJ.ZERO};let o=Z.default.lessThan(a,vq)?-1:1,s=iZ(n,e),c=iZ(n,t),l,u=0,d=o===1?2:1,f=fQ(s.time,c.time);for(f.sign()===-o&&u++;u<=d;u++){l=ZY(HZ(c.isoDate.year,c.isoDate.month,c.isoDate.day-u*o),s.time);let e=aZ(n,l,`compatible`);if(f=kJ.fromEpochNsDiff(t,e),f.sign()!==-o)break}let p=dX(`day`,i);return lQ(qX(r,s.isoDate,l.isoDate,p),f)}function gQ(e,t,n,r,i,a,o,s,c){let l,u,d,f,p=t;switch(s){case`year`:{let t=RQ(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=RQ(p.date.months,o,`trunc`);l=t,u=t+o*e,d=XY(p.date,0,0,l),f=XY(p.date,0,0,u);break}case`week`:{let t=XY(p.date,0,0),n=KX(a,r.isoDate,t,`constrain`),i=qX(a,n,HZ(n.year,n.month,n.day+p.date.days),`week`),s=RQ(p.date.weeks+i.weeks,o,`trunc`);l=s,u=s+o*e,d=XY(p.date,0,l),f=XY(p.date,0,u);break}case`day`:{let t=RQ(p.date.days,o,`trunc`);l=t,u=t+o*e,d=XY(p.date,l),f=XY(p.date,u);break}}let m=KX(a,r.isoDate,d,`constrain`),h=KX(a,r.isoDate,f,`constrain`),g,_,v=ZY(m,r.time),y=ZY(h,r.time);i?(g=aZ(i,v,`compatible`),_=aZ(i,y,`compatible`)):(g=jZ(v),_=jZ(y));let b=kJ.fromEpochNsDiff(n,g),x=kJ.fromEpochNsDiff(_,g),S=DJ(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)?OJ(Math.abs(l),Math.abs(u),C,w,S):Math.abs(u),E=new kJ(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:kJ.ZERO},{nudgeResult:{duration:p,nudgedEpochNs:D?_:g,didExpandCalendarUnit:D},total:E}}function _Q(e,t,n,r,i,a,o,s,c){let l=e,u=fX(s)||r&&s===`day`,d=BZ(l)<0?-1:1,f;return u?{nudgeResult:f}=gQ(d,l,t,n,r,i,o,s,c):f=r?function(e,t,n,r,i,a,o,s){let c=t,l=KX(i,n.isoDate,c.date,`constrain`),u=ZY(l,n.time),d=ZY(HZ(l.year,l.month,l.day+e),n.time),f=aZ(r,u,`compatible`),p=aZ(r,d,`compatible`),m=kJ.fromEpochNsDiff(p,f);if(m.sign()!==e)throw RangeError(`time zone returned inconsistent Instants`);let h=Z.default.BigInt(CY[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:lQ(XY(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*CY[i]),a),l=c.subtract(s),{quotient:u}=s.divmod(JJ),{quotient:d}=c.divmod(JJ),f=Math.sign(d-u)===s.sign(),p=l.addToEpochNs(t),m=0,h=c;return pX(n)===`date`&&(m=d,h=c.add(kJ.fromComponents(24*-d,0,0,0,0,0))),{duration:{date:XY(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=SY.indexOf(o);for(let t=SY.indexOf(s)-1;t>=l;t--){let s=SY[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=XY(c.date,0,0,t);break}case`week`:{let t=c.date.weeks+e;l=XY(c.date,0,t);break}}let u=ZY(KX(a,r.isoDate,l,`constrain`),r.time),d;if(d=i?aZ(i,u,`compatible`):jZ(u),Nq(n,d)===-e)break;c={date:l,time:kJ.ZERO}}return c}(d,l,f.nudgedEpochNs,n,r,i,a,dX(s,`day`))),l}function vQ(e,t,n,r,i,a){return fX(a)||r&&a===`day`?gQ(BZ(e)<0?-1:1,e,t,n,r,i,1,a,`trunc`).total:UQ(e.time.add24HourDays(e.date.days),a)}function yQ(e,t,n,r,i,a,o){if(KQ(e,t)==0)return{date:{years:0,months:0,weeks:0,days:0},time:kJ.ZERO};eQ(e),eQ(t);let s=mQ(e,t,n,r);return a===`nanosecond`&&i===1?s:_Q(s,jZ(t),e,null,n,r,i,a,o)}function bQ(e,t,n,r,i,a,o,s){if(pX(i)===`time`)return pQ(e,t,a,o,s);let c=hQ(e,t,n,r,i);return o===`nanosecond`&&a===1?c:_Q(c,t,iZ(n,e),n,r,i,a,o,s)}function xQ(e,t,n,r,i,a){let o=yY.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=cX(t,`largestUnit`,n,`auto`);if(r.includes(s))throw RangeError(`largestUnit must be one of ${o.join(`, `)}, not ${s}`);let c=rX(t),l=eX(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=cX(t,`smallestUnit`,n,i);if(r.includes(u))throw RangeError(`smallestUnit must be one of ${o.join(`, `)}, not ${u}`);let d=dX(a,u);if(s===`auto`&&(s=d),dX(s,u)!==s)throw RangeError(`largestUnit ${s} cannot be smaller than smallestUnit ${u}`);let f={hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[u];return f!==void 0&&iX(c,f,!1),{largestUnit:s,roundingIncrement:c,roundingMode:l,smallestUnit:u}}function SQ(e,t,n,r){let i=CX(n),a=xQ(e,e$(r),`time`,[],`nanosecond`,`second`),o=cQ(pQ(Q(t,Lq),Q(i,Lq),a.roundingIncrement,a.smallestUnit,a.roundingMode),a.largestUnit);return e===`since`&&(o=KZ(o)),o}function CQ(e,t,n,r){let i=yX(n),a=Q(t,Vq),o=Q(i,Vq);if(!XX(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=xQ(e,e$(r),`date`,[],`day`,`day`),c=wJ(`%Temporal.Duration%`),l=Q(t,Rq),u=Q(i,Rq);if(WQ(l,u)===0)return new c;let d={date:qX(a,l,u,s.largestUnit),time:kJ.ZERO};if(s.smallestUnit!==`day`||s.roundingIncrement!==1){let e=ZY(l,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});d=_Q(d,jZ(ZY(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=cQ(d,`day`);return e===`since`&&(f=KZ(f)),f}function wQ(e,t,n,r){let i=xX(n),a=Q(t,Vq),o=Q(i,Vq);if(!XX(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=xQ(e,e$(r),`datetime`,[],`nanosecond`,`day`),c=wJ(`%Temporal.Duration%`),l=Q(t,zq),u=Q(i,zq);if(KQ(l,u)===0)return new c;let d=cQ(yQ(l,u,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);return e===`since`&&(d=KZ(d)),d}function TQ(e,t,n,r){let i=TX(n),a=xQ(e,e$(r),`time`,[],`nanosecond`,`hour`),o=fQ(Q(t,Bq),Q(i,Bq));o=HQ(o,a.roundingIncrement,a.smallestUnit,a.roundingMode);let s=cQ(lQ({years:0,months:0,weeks:0,days:0},o),a.largestUnit);return e===`since`&&(s=KZ(s)),s}function EQ(e,t,n,r){let i=DX(n),a=Q(t,Vq),o=Q(i,Vq);if(!XX(a,o))throw RangeError(`cannot compute difference between months of ${a} and ${o} calendars`);let s=xQ(e,e$(r),`date`,[`week`,`day`],`month`,`year`),c=wJ(`%Temporal.Duration%`);if(WQ(Q(t,Rq),Q(i,Rq))==0)return new c;let l=gX(a,Q(t,Rq),`year-month`);l.day=1;let u=ZX(a,l,`constrain`),d=gX(a,Q(i,Rq),`year-month`);d.day=1;let f=ZX(a,d,`constrain`),p={date:XY(qX(a,u,f,s.largestUnit),0,0),time:kJ.ZERO};if(s.smallestUnit!==`month`||s.roundingIncrement!==1){let e=ZY(u,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});p=_Q(p,jZ(ZY(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=cQ(p,`day`);return e===`since`&&(m=KZ(m)),m}function DQ(e,t,n,r){let i=kX(n),a=Q(t,Vq),o=Q(i,Vq);if(!XX(a,o))throw RangeError(`cannot compute difference between dates of ${a} and ${o} calendars`);let s=xQ(e,e$(r),`datetime`,[],`nanosecond`,`hour`),c=Q(t,Lq),l=Q(i,Lq),u=wJ(`%Temporal.Duration%`),d;if(pX(s.largestUnit)!==`date`)d=cQ(pQ(c,l,s.roundingIncrement,s.smallestUnit,s.roundingMode),s.largestUnit);else{let e=Q(t,Gq);if(!tZ(e,Q(i,Gq)))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=cQ(bQ(c,l,e,a,s.largestUnit,s.roundingIncrement,s.smallestUnit,s.roundingMode),`hour`)}return e===`since`&&(d=KZ(d)),d}function OQ({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,WZ(e,t,s,r,i,c)}function kQ(e,t){let n=t.addToEpochNs(e);return nQ(n),n}function AQ(e,t,n,r,i=`constrain`){if(zZ(r.date)===0)return kQ(e,r.time);let a=iZ(t,e);return kQ(aZ(t,ZY(KX(n,a.isoDate,r.date,i),a.time),`compatible`),r.time)}function jQ(e,t,n){let r=SX(n);e===`subtract`&&(r=KZ(r));let i=dX(uX(t),uX(r));if(fX(i))throw RangeError(`For years, months, or weeks arithmetic, use date arithmetic relative to a starting point`);let a=oQ(t),o=oQ(r);return cQ(lQ({years:0,months:0,weeks:0,days:0},a.time.add(o.time)),i)}function MQ(e,t,n){let r=SX(n);e===`subtract`&&(r=KZ(r));let i=uX(r);if(pX(i)===`date`)throw RangeError(`Duration field ${i} not supported by Temporal.Instant. Try Temporal.ZonedDateTime instead.`);let a=oQ(r);return VX(kQ(Q(t,Lq),a.time))}function NQ(e,t,n,r){let i=Q(t,Vq),a=SX(n);e===`subtract`&&(a=KZ(a));let o=sQ(a),s=QY(e$(r));return jX(KX(i,Q(t,Rq),o,s),i)}function PQ(e,t,n,r){let i=SX(n);e===`subtract`&&(i=KZ(i));let a=QY(e$(r)),o=Q(t,Vq),s=oQ(i),c=Q(t,zq),l=OQ(c.time,s.time),u=XY(s.date,l.deltaDays);return iQ(u.years,u.months,u.weeks,u.days,0,0,0,0,0,0),NX(ZY(KX(o,c.isoDate,u,a),l),o)}function FQ(e,t,n){let r=SX(n);e===`subtract`&&(r=KZ(r));let i=oQ(r),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=OQ(Q(t,Bq),i.time);return LX(JY(a,o,s,c,l,u,`reject`))}function IQ(e,t,n,r){let i=SX(n);e===`subtract`&&(i=KZ(i));let a=QY(e$(r)),o=RZ(i),s=Q(t,Vq),c=gX(s,Q(t,Rq),`year-month`);c.day=1;let l=ZX(s,c,`constrain`);if(o<0){let e=KX(s,l,{months:1},`constrain`);l=HZ(e.year,e.month,e.day-1)}let u=sQ(i);return ZZ(l),zX(QX(s,gX(s,KX(s,l,u,a),`year-month`),a),s)}function LQ(e,t,n,r){let i=SX(n);e===`subtract`&&(i=KZ(i));let a=QY(e$(r)),o=Q(t,Gq),s=Q(t,Vq),c=aQ(i);return UX(AQ(Q(t,Lq),o,s,c,a),o,s)}function RQ(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=$Q(Math.abs(2*i)-t),l=o%2==0,u=DJ(n,a),d=i===0?o:OJ(o,s,c,l,u);return t*(a===`positive`?d:-d)}function zQ(e,t,n,r){let i=CY[n]*t;return function(e,t,n){let r=Aq(e),i=Aq(t),a=Z.default.divide(r,i),o=Z.default.remainder(r,i),s=DJ(n,`positive`),c,l;Z.default.lessThan(r,vq)?(c=Z.default.subtract(a,yq),l=a):(c=a,l=Z.default.add(a,yq));let u=Nq(Mq(Z.default.multiply(o,bq)),i)*(Z.default.lessThan(r,vq)?-1:1)+0,d=Z.default.equal(o,vq)?a:OJ(c,l,u,jq(c),s);return Z.default.multiply(d,i)}(e,Z.default.BigInt(i),r)}function BQ(e,t,n,r){tQ(e);let{year:i,month:a,day:o}=e.isoDate,s=VQ(e.time,t,n,r);return ZY(HZ(i,a,o+s.deltaDays),s)}function VQ({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=CY[s],d=RQ(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 WZ(d,0,0,0,0,0);case`minute`:return WZ(e,d,0,0,0,0);case`second`:return WZ(e,t,d,0,0,0);case`millisecond`:return WZ(e,t,n,d,0,0);case`microsecond`:return WZ(e,t,n,r,d,0);case`nanosecond`:return WZ(e,t,n,r,i,d);default:throw Error(`Invalid unit ${s}`)}}function HQ(e,t,n,r){let i=CY[n];return e.round(Z.default.BigInt(i*t),r)}function UQ(e,t){let n=CY[t];return e.fdiv(Z.default.BigInt(n))}function WQ(e,t){return e.year===t.year?e.month===t.month?e.day===t.day?0:$Q(e.day-t.day):$Q(e.month-t.month):$Q(e.year-t.year)}function GQ(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:$Q(e.nanosecond-t.nanosecond):$Q(e.microsecond-t.microsecond):$Q(e.millisecond-t.millisecond):$Q(e.second-t.second):$Q(e.minute-t.minute):$Q(e.hour-t.hour)}function KQ(e,t){let n=WQ(e.isoDate,t.isoDate);return n===0?GQ(e.time,t.time):n}function qQ(e){let t=XQ(e);return globalThis.BigInt===void 0?t:globalThis.BigInt(t.toString(10))}function JQ(e,t){let{quotient:n,remainder:r}=Pq(Aq(e),Tq),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 YQ(e){if(!Number.isInteger(e))throw RangeError(`epoch milliseconds must be an integer`);return Z.default.multiply(Z.default.BigInt(e),Tq)}function XQ(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 ZQ=(()=>{let e=Z.default.BigInt(Date.now()%1e6);return()=>{let t=Date.now(),n=Z.default.BigInt(t),r=Z.default.add(YQ(t),e);return e=Z.default.remainder(n,Tq),Z.default.greaterThan(r,ZJ)?ZJ:Z.default.lessThan(r,QJ)?QJ:r}})();function QQ(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}function $Q(e){return e<0?-1:e>0?1:e}function e$(e){if(e===void 0)return Object.create(null);if(sY(e)&&e!==null)return e;throw TypeError(`Options parameter must be an object, not `+(e===null?`null`:typeof e))}function t$(e,t){let n=Object.create(null);return n[e]=t,n}function n$(e,t,n,r){let i=e[t];if(i!==void 0){if(i=lY(i),!n.includes(i))throw RangeError(`${t} must be one of ${n.join(`, `)}, not ${i}`);return i}if(r===sX)throw RangeError(`${t} option is required`);return r}function r$(e){let t=i$(e);if(!aY.includes(i$(t)))throw RangeError(`invalid calendar identifier ${t}`);switch(t){case`ethiopic-amete-alem`:return`ethioaa`;case`islamicc`:return`islamic-civil`}return t}function i$(e){let t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t+=r>=65&&r<=90?String.fromCharCode(r+32):String.fromCharCode(r)}return t}function a$(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 fde=RegExp(`^${LJ.source}$`),pde=RegExp(`^([+-])([01][0-9]|2[0-3])(?::?([0-5][0-9])(?::?([0-5][0-9])(?:[.,](\\d{1,9}))?)?)?$`);function o$(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 s$(e){return[...e]}function c$(e,t){if(e!==`gregory`&&e!==`iso8601`)return;let n=u$[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 l$(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 u$={};function d$(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 f$(e,t=!1){return`M${`${e}`.padStart(2,`0`)}${t?`L`:``}`}function p$(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`&&YZ(r,1,n),t===`constrain`&&(r=qZ(r,1,n)),i=f$(r)}else{let e=d$(i);if(i!==f$(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}}u$.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,p$(e))},dateToISO:(e,t)=>qY(e.year,e.month,e.day,t),monthDayToISOReferenceDate(e,t){let{month:n,day:r}=qY(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 s$(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}=VZ(o,s),{year:o,month:s,day:c}=qY(o,s,c,a),c+=i+7*r,HZ(o,s,c)},dateUntil(e,t,n){let r=-WQ(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);!l$(r,e.year+s,e.month,e.day,t);)a=s,s+=r;let c=r;for(i=VZ(e.year+a,e.month+c);!l$(r,i.year,i.month,e.day,t);)o=c,c+=r,i=VZ(i.year,i.month+r);n===`month`&&(o+=12*a,a=0)}i=VZ(e.year+a,e.month+o);let s=JZ(i.year,i.month,e.day),c=0,l=uQ(t.year,t.month-1,t.day)-uQ(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=f$(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+=LZ(e,n);i.dayOfYear=r}return r.weekOfYear&&(i.weekOfYear=c$(`iso8601`,{year:e,month:t,day:n})),r.daysInMonth&&(i.daysInMonth=LZ(e,t)),(r.daysInYear||r.inLeapYear)&&(i.inLeapYear=IZ(e),i.daysInYear=i.inLeapYear?366:365),i},getFirstDayOfWeek:()=>1,getMinimalDaysInFirstWeek:()=>4};var m$=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 h$({isoYear:e,isoMonth:t,isoDay:n}){return`${lZ(e)}-${uZ(t)}-${uZ(n)}T00:00Z`}function g$(e,t){return{years:e.year-t.year,months:e.month-t.month,days:e.day-t.day}}m$.objectMap=new WeakMap,m$.MAX_CACHE_ENTRIES=1e3;var _$=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=h$({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}=p$(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`?(YZ(i,1,r),YZ(a,1,this.maximumMonthLength(e))):(i=qZ(i,1,r),a=qZ(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=g$(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=g$(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=g$(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:$Q(e.day-t.day):$Q(e.month-t.month):$Q(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 HZ(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 uQ(i.year,i.month-1,i.day)-uQ(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(){}},mde=class extends _${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?f$(5,!0):f$(t<6?t:t-1):f$(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=d$(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`?(YZ(a,1,this.monthsInYear({year:i})),YZ(s,1,this.maximumMonthLength({year:i,month:a}))):(a=qZ(a,1,this.monthsInYear({year:i})),s=qZ(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}}},v$=class extends _${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}}},hde=class extends v${constructor(){super(...arguments),this.id=`islamic`}},gde=class extends v${constructor(){super(...arguments),this.id=`islamic-umalqura`}},_de=class extends v${constructor(){super(...arguments),this.id=`islamic-tbla`}},vde=class extends v${constructor(){super(...arguments),this.id=`islamic-civil`}},yde=class extends v${constructor(){super(...arguments),this.id=`islamic-rgsa`}},bde=class extends v${constructor(){super(...arguments),this.id=`islamicc`}},xde=class extends _${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 d$(e)<=6?31:30}estimateIsoDate(e){let{year:t}=this.adjustCalendarDate(e);return{year:t+621,month:1,day:1}}},Sde=class extends _${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 y$(e.year+78)}monthsInYear(){return 12}minimumMonthLength(e){return this.getMonthInfo(e).length}maximumMonthLength(e){return this.getMonthInfo(e).length}maxLengthOfMonthCodeInAnyYear(e){let t=d$(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 HZ(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 y$(e){return e%4==0&&(e%100!=0||e%400==0)}var b$=class extends _${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 y$(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][d$(e)-1]}estimateIsoDate(e){let t=this.adjustCalendarDate(e);return qY(t.year+this.isoEpoch.year,t.month+this.isoEpoch.month,t.day+this.isoEpoch.day,`constrain`)}},x$=class extends _${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 y$(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][d$(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:d$(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 qY(t+i.isoEpoch.year-+!i.hasYearZero,n,r,`constrain`)}},S$=class extends x${constructor(e,t){super(e,t)}isoToCalendarDate(e){let{year:t,month:n,day:r}=e,i=f$(n),a=t-this.anchorEra.isoEpoch.year+1;return this.completeEraYear({year:a,month:n,monthCode:i,day:r})}},C$={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},Cde=class extends b${constructor(e,t){super(e,t),this.inLeapYear=C$.inLeapYear,this.monthsInYear=C$.monthsInYear,this.minimumMonthLength=C$.minimumMonthLength,this.maximumMonthLength=C$.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=C$.maxLengthOfMonthCodeInAnyYear}},w$=class extends x${constructor(e,t){super(e,t),this.inLeapYear=C$.inLeapYear,this.monthsInYear=C$.monthsInYear,this.minimumMonthLength=C$.minimumMonthLength,this.maximumMonthLength=C$.maximumMonthLength,this.maxLengthOfMonthCodeInAnyYear=C$.maxLengthOfMonthCodeInAnyYear}},wde=class extends Cde{constructor(){super(`ethioaa`,{year:-5492,month:7,day:17})}},Tde=class extends w${constructor(){super(`coptic`,[{code:`coptic`,isoEpoch:{year:284,month:8,day:29}},{code:`coptic-inverse`,reverseOf:`coptic`}])}},Ede=class extends w${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}}])}},Dde=class extends S${constructor(){super(`roc`,[{code:`roc`,names:[`minguo`],isoEpoch:{year:1912,month:1,day:1}},{code:`roc-inverse`,names:[`before-roc`],reverseOf:`roc`}])}},Ode=class extends b${constructor(){super(`buddhist`,{year:-543,month:1,day:1})}},kde=class extends S${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}},Ade=class extends S${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}}},T$=class extends _${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=h$({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=f$(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=f$(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`?(YZ(a,1,o),YZ(s,1,this.maximumMonthLength())):(a=qZ(a,1,o),s=qZ(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=f$(+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}}},jde=class extends T${constructor(){super(...arguments),this.id=`chinese`}},Mde=class extends T${constructor(){super(...arguments),this.id=`dangi`}},Nde=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 m$;p$(e,void 0,this.helper.monthsInYear({year:e.year??1972},t))}}dateToISO(e,t){let n=new m$,r=this.helper.calendarToIsoDate(e,t,n);return n.setObject(r),r}monthDayToISOReferenceDate(e,t){let n=new m$,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 s$(t)}dateAdd(e,{years:t,months:n,weeks:r,days:i},a){let o=m$.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 m$.getCacheForObject(l)||new m$(o).setObject(l),l}dateUntil(e,t,n){let r=m$.getCacheForObject(e),i=m$.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=m$.getCacheForObject(e),r=this.helper.isoToCalendarDate(e,n);if(t.dayOfWeek&&(r.dayOfWeek=u$.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=c$(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[mde,xde,Ede,wde,Tde,jde,Mde,Dde,Sde,Ode,kde,Ade,hde,gde,_de,vde,yde,bde]){let t=new e;u$[t.id]=new Nde(t)}CJ(`calendarImpl`,(function(e){return u$[e]}));var E$=Intl.DateTimeFormat;function D$(e,t){let n=Q(e,t);return typeof n==`function`&&(n=new E$(Q(e,fJ),n(Q(e,pJ))),function(e,t,n){let r=gJ(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 O$(e){return yJ(e,cJ)}var k$=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 E$(t,i),o=a.resolvedOptions();if(vJ(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,bJ(e,pJ,t)}else bJ(e,pJ,i);bJ(e,fJ,o.locale),bJ(e,cJ,a),bJ(e,lJ,o.timeZone),bJ(e,dJ,o.calendar),bJ(e,nJ,Hde),bJ(e,rJ,Bde),bJ(e,iJ,Vde),bJ(e,aJ,zde),bJ(e,oJ,Ude),bJ(e,sJ,Wde);let s=r?i.timeZone:void 0;if(s===void 0)bJ(e,uJ,o.timeZone);else{let t=lY(s);if(t.startsWith(`−`))throw RangeError(`Unicode minus (U+2212) is not supported in time zone offsets`);bJ(e,uJ,eZ(t))}})(this,e,t)}get format(){$(this,O$);let e=Fde.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,O$),Lde.call(this,e,t)}formatToParts(e,...t){return $(this,O$),Ide.call(this,e,...t)}formatRangeToParts(e,t){return $(this,O$),Rde.call(this,e,t)}resolvedOptions(){return $(this,O$),Pde.call(this)}};`formatToParts`in E$.prototype||delete k$.prototype.formatToParts,`formatRangeToParts`in E$.prototype||delete k$.prototype.formatRangeToParts;var A$=function(e=void 0,t=void 0){return new k$(e,t)};function Pde(){let e=Q(this,cJ).resolvedOptions();return e.timeZone=Q(this,uJ),e}function Fde(e,...t){let n,r,i=R$(e,this);return i.formatter?(n=i.formatter,r=[JQ(i.epochNs,`floor`)]):(n=Q(this,cJ),r=[e,...t]),n.format(...r)}function Ide(e,...t){let n,r,i=R$(e,this);return i.formatter?(n=i.formatter,r=[JQ(i.epochNs,`floor`)]):(n=Q(this,cJ),r=[e,...t]),n.formatToParts(...r)}function Lde(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=I$(e),r=I$(t),i,a=[n,r];if(F$(n)!==F$(r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);if(F$(n)){if(!L$(n,r))throw TypeError(`Intl.DateTimeFormat.formatRange accepts two values of the same type`);let{epochNs:e,formatter:t}=R$(n,this),{epochNs:o,formatter:s}=R$(r,this);t&&(i=t,a=[JQ(e,`floor`),JQ(o,`floor`)])}return i||=Q(this,cJ),i.formatRange(...a)}function Rde(e,t){if(e===void 0||t===void 0)throw TypeError(`Intl.DateTimeFormat.formatRange requires two values`);let n=I$(e),r=I$(t),i,a=[n,r];if(F$(n)!==F$(r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);if(F$(n)){if(!L$(n,r))throw TypeError(`Intl.DateTimeFormat.formatRangeToParts accepts two values of the same type`);let{epochNs:e,formatter:t}=R$(n,this),{epochNs:o,formatter:s}=R$(r,this);t&&(i=t,a=[JQ(e,`floor`),JQ(o,`floor`)])}return i||=Q(this,cJ),i.formatRangeToParts(...a)}function j$(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 zde(e){let t=j$(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`})),!N$(t)){if(P$(e))throw TypeError(`cannot format Temporal.PlainTime with options [${Object.keys(e)}]`);Object.assign(t,{hour:`numeric`,minute:`numeric`,second:`numeric`})}return t}function Bde(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=j$(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(P$(e))throw TypeError(`cannot format PlainYearMonth with options [${Object.keys(e)}]`);Object.assign(n,{year:`numeric`,month:`numeric`})}return n}function Vde(e){let t={short:{month:`numeric`,day:`numeric`},medium:{month:`short`,day:`numeric`},long:{month:`long`,day:`numeric`},full:{month:`long`,day:`numeric`}},n=j$(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(P$(e))throw TypeError(`cannot format PlainMonthDay with options [${Object.keys(e)}]`);Object.assign(n,{month:`numeric`,day:`numeric`})}return n}function Hde(e){let t=j$(e,{hour:!1,minute:!1,second:!1,dayPeriod:!1,timeZoneName:!1,timeStyle:!1});if(!M$(t)){if(P$(e))throw TypeError(`cannot format PlainDate with options [${Object.keys(e)}]`);Object.assign(t,{year:`numeric`,month:`numeric`,day:`numeric`})}return t}function Ude(e){let t=j$(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),!N$(t)&&!M$(t)){if(P$(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 Wde(e){let t=e;return N$(t)||M$(t)||(t=Object.assign({},t,{year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`})),t}function M$(e){return`year`in e||`month`in e||`day`in e||`weekday`in e||`dateStyle`in e||`era`in e}function N$(e){return`hour`in e||`minute`in e||`second`in e||`timeStyle`in e||`dayPeriod`in e||`fractionalSecondDigits`in e}function P$(e){return M$(e)||N$(e)||`dateStyle`in e||`timeStyle`in e||`timeZoneName`in e}function F$(e){return AY(e)||jY(e)||MY(e)||FY(e)||NY(e)||PY(e)||OY(e)}function I$(e){return F$(e)?e:cY(e)}function L$(e,t){return!(!F$(e)||!F$(t)||jY(e)&&!jY(t)||AY(e)&&!AY(t)||MY(e)&&!MY(t)||FY(e)&&!FY(t)||NY(e)&&!NY(t)||PY(e)&&!PY(t)||OY(e)&&!OY(t))}function R$(e,t){if(jY(e)){let n={isoDate:{year:1970,month:1,day:1},time:Q(e,Bq)};return{epochNs:aZ(Q(t,lJ),n,`compatible`),formatter:D$(t,aJ)}}if(NY(e)){let n=Q(e,Vq),r=Q(t,dJ);if(n!==r)throw RangeError(`cannot format PlainYearMonth with calendar ${n} in locale with calendar ${r}`);let i=ZY(Q(e,Rq),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:aZ(Q(t,lJ),i,`compatible`),formatter:D$(t,rJ)}}if(PY(e)){let n=Q(e,Vq),r=Q(t,dJ);if(n!==r)throw RangeError(`cannot format PlainMonthDay with calendar ${n} in locale with calendar ${r}`);let i=ZY(Q(e,Rq),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:aZ(Q(t,lJ),i,`compatible`),formatter:D$(t,iJ)}}if(AY(e)){let n=Q(e,Vq),r=Q(t,dJ);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDate with calendar ${n} in locale with calendar ${r}`);let i=ZY(Q(e,Rq),{deltaDays:0,hour:12,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0});return{epochNs:aZ(Q(t,lJ),i,`compatible`),formatter:D$(t,nJ)}}if(MY(e)){let n=Q(e,Vq),r=Q(t,dJ);if(n!==`iso8601`&&n!==r)throw RangeError(`cannot format PlainDateTime with calendar ${n} in locale with calendar ${r}`);let i=Q(e,zq);return{epochNs:aZ(Q(t,lJ),i,`compatible`),formatter:D$(t,oJ)}}if(FY(e))throw TypeError(`Temporal.ZonedDateTime not supported in DateTimeFormat methods. Use toLocaleString() instead.`);return OY(e)?{epochNs:Q(e,Lq),formatter:D$(t,sJ)}:{}}function z$(e){let t=Object.create(null);return t.years=Q(e,Kq),t.months=Q(e,qq),t.weeks=Q(e,Jq),t.days=Q(e,Yq),t.hours=Q(e,Xq),t.minutes=Q(e,Zq),t.seconds=Q(e,Qq),t.milliseconds=Q(e,$q),t.microseconds=Q(e,eJ),t.nanoseconds=Q(e,tJ),t}k$.prototype.constructor=A$,Object.defineProperty(A$,"prototype",{value:k$.prototype,writable:!1,enumerable:!1,configurable:!1}),A$.supportedLocalesOf=E$.supportedLocalesOf,SJ(A$,`Intl.DateTimeFormat`);var{format:Gde,formatToParts:Kde}=Intl.DurationFormat?.prototype??Object.create(null);function B$(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=z$(SX(e));return Gde.call(this,t)}Intl.DurationFormat?.prototype&&(Intl.DurationFormat.prototype.format=B$,Intl.DurationFormat.prototype.formatToParts=function(e){Intl.DurationFormat.prototype.resolvedOptions.call(this);let t=z$(SX(e));return Kde.call(this,t)}),Object.freeze({__proto__:null,DateTimeFormat:A$,ModifiedIntlDurationFormatPrototypeFormat:B$});var V$=class{constructor(e){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);BX(this,XQ(e))}get epochMilliseconds(){return $(this,OY),JQ(Q(this,Lq),`floor`)}get epochNanoseconds(){return $(this,OY),qQ(Z.default.BigInt(Q(this,Lq)))}add(e){return $(this,OY),MQ(`add`,this,e)}subtract(e){return $(this,OY),MQ(`subtract`,this,e)}until(e,t=void 0){return $(this,OY),SQ(`until`,this,e,t)}since(e,t=void 0){return $(this,OY),SQ(`since`,this,e,t)}round(e){if($(this,OY),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?t$(`smallestUnit`,e):e$(e),n=rX(t),r=eX(t,`halfExpand`),i=cX(t,`smallestUnit`,`time`,sX);return iX(n,{hour:24,minute:1440,second:86400,millisecond:864e5,microsecond:864e8,nanosecond:864e11}[i],!0),VX(zQ(Q(this,Lq),n,i,r))}equals(e){$(this,OY);let t=CX(e),n=Q(this,Lq),r=Q(t,Lq);return Z.default.equal(Z.default.BigInt(n),Z.default.BigInt(r))}toString(e=void 0){$(this,OY);let t=e$(e),n=aX(t),r=eX(t,`trunc`),i=cX(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=eZ(a));let{precision:o,unit:s,increment:c}=oX(i,n);return pZ(VX(zQ(Q(this,Lq),c,s,r)),a,o)}toJSON(){return $(this,OY),pZ(this,void 0,`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,OY),new A$(e,t).format(this)}valueOf(){a$(`Instant`)}toZonedDateTimeISO(e){$(this,OY);let t=eZ(e);return UX(Q(this,Lq),t,`iso8601`)}static fromEpochMilliseconds(e){return VX(YQ(cY(e)))}static fromEpochNanoseconds(e){return VX(XQ(e))}static from(e){return CX(e)}static compare(e,t){let n=CX(e),r=CX(t),i=Q(n,Lq),a=Q(r,Lq);return Z.default.lessThan(i,a)?-1:+!!Z.default.greaterThan(i,a)}};SJ(V$,`Temporal.Instant`);var H$=class{constructor(e,t,n,r=`iso8601`){let i=uY(e),a=uY(t),o=uY(n),s=r$(r===void 0?`iso8601`:mY(r));XZ(i,a,o),AX(this,{year:i,month:a,day:o},s)}get calendarId(){return $(this,AY),Q(this,Vq)}get era(){return U$(this,`era`)}get eraYear(){return U$(this,`eraYear`)}get year(){return U$(this,`year`)}get month(){return U$(this,`month`)}get monthCode(){return U$(this,`monthCode`)}get day(){return U$(this,`day`)}get dayOfWeek(){return U$(this,`dayOfWeek`)}get dayOfYear(){return U$(this,`dayOfYear`)}get weekOfYear(){return U$(this,`weekOfYear`)?.week}get yearOfWeek(){return U$(this,`weekOfYear`)?.year}get daysInWeek(){return U$(this,`daysInWeek`)}get daysInMonth(){return U$(this,`daysInMonth`)}get daysInYear(){return U$(this,`daysInYear`)}get monthsInYear(){return U$(this,`monthsInYear`)}get inLeapYear(){return U$(this,`inLeapYear`)}with(e,t=void 0){if($(this,AY),!sY(e))throw TypeError(`invalid argument`);IY(e);let n=Q(this,Vq),r=gX(n,Q(this,Rq));return r=GX(n,r,_X(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),jX(ZX(n,r,QY(e$(t))),n)}withCalendar(e){$(this,AY);let t=JX(e);return jX(Q(this,Rq),t)}add(e,t=void 0){return $(this,AY),NQ(`add`,this,e,t)}subtract(e,t=void 0){return $(this,AY),NQ(`subtract`,this,e,t)}until(e,t=void 0){return $(this,AY),CQ(`until`,this,e,t)}since(e,t=void 0){return $(this,AY),CQ(`since`,this,e,t)}equals(e){$(this,AY);let t=yX(e);return WQ(Q(this,Rq),Q(t,Rq))===0&&XX(Q(this,Vq),Q(t,Vq))}toString(e=void 0){return $(this,AY),hZ(this,nX(e$(e)))}toJSON(){return $(this,AY),hZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,AY),new A$(e,t).format(this)}valueOf(){a$(`PlainDate`)}toPlainDateTime(e=void 0){$(this,AY);let t=EX(e);return NX(ZY(Q(this,Rq),t),Q(this,Vq))}toZonedDateTime(e){let t,n;if($(this,AY),sY(e)){let r=e.timeZone;r===void 0?t=eZ(e):(t=eZ(r),n=e.plainTime)}else t=eZ(e);let r=Q(this,Rq),i;return n===void 0?i=cZ(t,r):(n=TX(n),i=aZ(t,ZY(r,Q(n,Bq)),`compatible`)),UX(i,t,Q(this,Vq))}toPlainYearMonth(){$(this,AY);let e=Q(this,Vq);return zX(QX(e,gX(e,Q(this,Rq)),`constrain`),e)}toPlainMonthDay(){$(this,AY);let e=Q(this,Vq);return FX($X(e,gX(e,Q(this,Rq)),`constrain`),e)}static from(e,t=void 0){return yX(e,t)}static compare(e,t){let n=yX(e),r=yX(t);return WQ(Q(n,Rq),Q(r,Rq))}};function U$(e,t){$(e,AY);let n=Q(e,Rq);return hX(e).isoToDate(n,{[t]:!0})[t]}SJ(H$,`Temporal.PlainDate`);var W$=class{constructor(e,t,n,r=0,i=0,a=0,o=0,s=0,c=0,l=`iso8601`){let u=uY(e),d=uY(t),f=uY(n),p=r===void 0?0:uY(r),m=i===void 0?0:uY(i),h=a===void 0?0:uY(a),g=o===void 0?0:uY(o),_=s===void 0?0:uY(s),v=c===void 0?0:uY(c),y=r$(l===void 0?`iso8601`:mY(l));$Z(u,d,f,p,m,h,g,_,v),MX(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,MY),Q(this,Vq)}get year(){return G$(this,`year`)}get month(){return G$(this,`month`)}get monthCode(){return G$(this,`monthCode`)}get day(){return G$(this,`day`)}get hour(){return K$(this,`hour`)}get minute(){return K$(this,`minute`)}get second(){return K$(this,`second`)}get millisecond(){return K$(this,`millisecond`)}get microsecond(){return K$(this,`microsecond`)}get nanosecond(){return K$(this,`nanosecond`)}get era(){return G$(this,`era`)}get eraYear(){return G$(this,`eraYear`)}get dayOfWeek(){return G$(this,`dayOfWeek`)}get dayOfYear(){return G$(this,`dayOfYear`)}get weekOfYear(){return G$(this,`weekOfYear`)?.week}get yearOfWeek(){return G$(this,`weekOfYear`)?.year}get daysInWeek(){return G$(this,`daysInWeek`)}get daysInYear(){return G$(this,`daysInYear`)}get daysInMonth(){return G$(this,`daysInMonth`)}get monthsInYear(){return G$(this,`monthsInYear`)}get inLeapYear(){return G$(this,`inLeapYear`)}with(e,t=void 0){if($(this,MY),!sY(e))throw TypeError(`invalid argument`);IY(e);let n=Q(this,Vq),r=Q(this,zq),i={...gX(n,r.isoDate),...r.time};return i=GX(n,i,_X(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`],`partial`)),NX(bX(n,i,QY(e$(t))),n)}withPlainTime(e=void 0){$(this,MY);let t=EX(e);return NX(ZY(Q(this,zq).isoDate,t),Q(this,Vq))}withCalendar(e){$(this,MY);let t=JX(e);return NX(Q(this,zq),t)}add(e,t=void 0){return $(this,MY),PQ(`add`,this,e,t)}subtract(e,t=void 0){return $(this,MY),PQ(`subtract`,this,e,t)}until(e,t=void 0){return $(this,MY),wQ(`until`,this,e,t)}since(e,t=void 0){return $(this,MY),wQ(`since`,this,e,t)}round(e){if($(this,MY),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?t$(`smallestUnit`,e):e$(e),n=rX(t),r=eX(t,`halfExpand`),i=cX(t,`smallestUnit`,`time`,sX,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];iX(n,a,a===1);let o=Q(this,zq);return NX(n===1&&i===`nanosecond`?o:BQ(o,n,i,r),Q(this,Vq))}equals(e){$(this,MY);let t=xX(e);return KQ(Q(this,zq),Q(t,zq))===0&&XX(Q(this,Vq),Q(t,Vq))}toString(e=void 0){$(this,MY);let t=e$(e),n=nX(t),r=aX(t),i=eX(t,`trunc`),a=cX(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}=oX(a,r),l=BQ(Q(this,zq),c,s,i);return eQ(l),_Z(l,Q(this,Vq),o,n)}toJSON(){return $(this,MY),_Z(Q(this,zq),Q(this,Vq),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,MY),new A$(e,t).format(this)}valueOf(){a$(`PlainDateTime`)}toZonedDateTime(e,t=void 0){$(this,MY);let n=eZ(e),r=$Y(e$(t));return UX(aZ(n,Q(this,zq),r),n,Q(this,Vq))}toPlainDate(){return $(this,MY),jX(Q(this,zq).isoDate,Q(this,Vq))}toPlainTime(){return $(this,MY),LX(Q(this,zq).time)}static from(e,t=void 0){return xX(e,t)}static compare(e,t){let n=xX(e),r=xX(t);return KQ(Q(n,zq),Q(r,zq))}};function G$(e,t){$(e,MY);let n=Q(e,zq).isoDate;return hX(e).isoToDate(n,{[t]:!0})[t]}function K$(e,t){return $(e,MY),Q(e,zq).time[t]}SJ(W$,`Temporal.PlainDateTime`);var q$=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:fY(e),d=t===void 0?0:fY(t),f=n===void 0?0:fY(n),p=r===void 0?0:fY(r),m=i===void 0?0:fY(i),h=a===void 0?0:fY(a),g=o===void 0?0:fY(o),_=s===void 0?0:fY(s),v=c===void 0?0:fY(c),y=l===void 0?0:fY(l);iQ(u,d,f,p,m,h,g,_,v,y),vJ(this),bJ(this,Kq,u),bJ(this,qq,d),bJ(this,Jq,f),bJ(this,Yq,p),bJ(this,Xq,m),bJ(this,Zq,h),bJ(this,Qq,g),bJ(this,$q,_),bJ(this,eJ,v),bJ(this,tJ,y)}get years(){return $(this,kY),Q(this,Kq)}get months(){return $(this,kY),Q(this,qq)}get weeks(){return $(this,kY),Q(this,Jq)}get days(){return $(this,kY),Q(this,Yq)}get hours(){return $(this,kY),Q(this,Xq)}get minutes(){return $(this,kY),Q(this,Zq)}get seconds(){return $(this,kY),Q(this,Qq)}get milliseconds(){return $(this,kY),Q(this,$q)}get microseconds(){return $(this,kY),Q(this,eJ)}get nanoseconds(){return $(this,kY),Q(this,tJ)}get sign(){return $(this,kY),RZ(this)}get blank(){return $(this,kY),RZ(this)===0}with(t){$(this,kY);let{years:n=Q(this,Kq),months:r=Q(this,qq),weeks:i=Q(this,Jq),days:a=Q(this,Yq),hours:o=Q(this,Xq),minutes:s=Q(this,Zq),seconds:c=Q(this,Qq),milliseconds:l=Q(this,$q),microseconds:u=Q(this,eJ),nanoseconds:d=Q(this,tJ)}=YY(t);return new e(n,r,i,a,o,s,c,l,u,d)}negated(){return $(this,kY),KZ(this)}abs(){return $(this,kY),new e(Math.abs(Q(this,Kq)),Math.abs(Q(this,qq)),Math.abs(Q(this,Jq)),Math.abs(Q(this,Yq)),Math.abs(Q(this,Xq)),Math.abs(Q(this,Zq)),Math.abs(Q(this,Qq)),Math.abs(Q(this,$q)),Math.abs(Q(this,eJ)),Math.abs(Q(this,tJ)))}add(e){return $(this,kY),jQ(`add`,this,e)}subtract(e){return $(this,kY),jQ(`subtract`,this,e)}round(e){if($(this,kY),e===void 0)throw TypeError(`options parameter is required`);let t=uX(this),n=typeof e==`string`?t$(`smallestUnit`,e):e$(e),r=cX(n,`largestUnit`,`datetime`,void 0,[`auto`]),{plainRelativeTo:i,zonedRelativeTo:a}=lX(n),o=rX(n),s=eX(n,`halfExpand`),c=cX(n,`smallestUnit`,`datetime`,void 0),l=!0;c||=(l=!1,`nanosecond`);let u=dX(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(dX(r,c)!==r)throw RangeError(`largestUnit ${r} cannot be smaller than smallestUnit ${c}`);let f={hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[c];if(f!==void 0&&iX(o,f,!1),o>1&&pX(c)===`date`&&r!==c)throw RangeError(`For calendar units with roundingIncrement > 1, use largestUnit = smallestUnit`);if(a){let e=aQ(this),t=Q(a,Gq),n=Q(a,Vq),i=Q(a,Lq);return e=bQ(i,AQ(i,t,n,e),t,n,r,o,c,s),pX(r)===`date`&&(r=`hour`),cQ(e,r)}if(i){let e=oQ(this),t=OQ({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),n=Q(i,Rq),a=Q(i,Vq),l=KX(a,n,XY(e.date,t.deltaDays),`constrain`);return e=yQ(ZY(n,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),ZY(l,t),a,r,o,c,s),cQ(e,r)}if(fX(t))throw RangeError(`a starting point is required for ${t}s balancing`);if(fX(r))throw RangeError(`a starting point is required for ${r}s balancing`);let p=oQ(this);if(c===`day`){let{quotient:e,remainder:t}=p.time.divmod(JJ),n=p.date.days+e+UQ(t,`day`);n=RQ(n,o,s),p=lQ({years:0,months:0,weeks:0,days:n},kJ.ZERO)}else p=lQ({years:0,months:0,weeks:0,days:0},HQ(p.time,o,c,s));return cQ(p,r)}total(e){if($(this,kY),e===void 0)throw TypeError(`options argument is required`);let t=typeof e==`string`?t$(`unit`,e):e$(e),{plainRelativeTo:n,zonedRelativeTo:r}=lX(t),i=cX(t,`unit`,`datetime`,sX);if(r){let e=aQ(this),t=Q(r,Gq),n=Q(r,Vq),a=Q(r,Lq);return function(e,t,n,r,i){return pX(i)===`time`?UQ(kJ.fromEpochNsDiff(t,e),i):vQ(hQ(e,t,n,r,i),t,iZ(n,e),n,r,i)}(a,AQ(a,t,n,e),t,n,i)}if(n){let e=oQ(this),t=OQ({deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0},e.time),r=Q(n,Rq),a=Q(n,Vq),o=KX(a,r,XY(e.date,t.deltaDays),`constrain`);return function(e,t,n,r){if(KQ(e,t)==0)return 0;eQ(e),eQ(t);let i=mQ(e,t,n,r);return r===`nanosecond`?Z.default.toNumber(i.time.totalNs):vQ(i,jZ(t),e,null,n,r)}(ZY(r,{deltaDays:0,hour:0,minute:0,second:0,millisecond:0,microsecond:0,nanosecond:0}),ZY(o,t),a,i)}let a=uX(this);if(fX(a))throw RangeError(`a starting point is required for ${a}s total`);if(fX(i))throw RangeError(`a starting point is required for ${i}s total`);return UQ(oQ(this).time,i)}toString(e=void 0){$(this,kY);let t=e$(e),n=aX(t),r=eX(t,`trunc`),i=cX(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}=oX(i,n);if(o===`nanosecond`&&s===1)return mZ(this,a);let c=uX(this),l=aQ(this),u=HQ(l.time,s,o,r);return l=lQ(l.date,u),mZ(cQ(l,dX(c,`second`)),a)}toJSON(){return $(this,kY),mZ(this,`auto`)}toLocaleString(e=void 0,t=void 0){if($(this,kY),typeof Intl.DurationFormat==`function`){let n=new Intl.DurationFormat(e,t);return B$.call(n,this)}return console.warn(`Temporal.Duration.prototype.toLocaleString() requires Intl.DurationFormat.`),mZ(this,`auto`)}valueOf(){a$(`Duration`)}static from(e){return SX(e)}static compare(e,t,n=void 0){let r=SX(e),i=SX(t),{plainRelativeTo:a,zonedRelativeTo:o}=lX(e$(n));if(Q(r,Kq)===Q(i,Kq)&&Q(r,qq)===Q(i,qq)&&Q(r,Jq)===Q(i,Jq)&&Q(r,Yq)===Q(i,Yq)&&Q(r,Xq)===Q(i,Xq)&&Q(r,Zq)===Q(i,Zq)&&Q(r,Qq)===Q(i,Qq)&&Q(r,$q)===Q(i,$q)&&Q(r,eJ)===Q(i,eJ)&&Q(r,tJ)===Q(i,tJ))return 0;let s=uX(r),c=uX(i),l=aQ(r),u=aQ(i);if(o&&(pX(s)===`date`||pX(c)===`date`)){let e=Q(o,Gq),t=Q(o,Vq),n=Q(o,Lq),r=AQ(n,e,t,l),i=AQ(n,e,t,u);return $Q(Z.default.toNumber(Z.default.subtract(r,i)))}let d=l.date.days,f=u.date.days;if(fX(s)||fX(c)){if(!a)throw RangeError(`A starting point is required for years, months, or weeks comparison`);d=GZ(l.date,a),f=GZ(u.date,a)}let p=l.time.add24HourDays(d),m=u.time.add24HourDays(f);return p.cmp(m)}};SJ(q$,`Temporal.Duration`);var J$=class{constructor(e,t,n=`iso8601`,r=1972){let i=uY(e),a=uY(t),o=r$(n===void 0?`iso8601`:mY(n)),s=uY(r);XZ(s,i,a),PX(this,{year:s,month:i,day:a},o)}get monthCode(){return Y$(this,`monthCode`)}get day(){return Y$(this,`day`)}get calendarId(){return $(this,PY),Q(this,Vq)}with(e,t=void 0){if($(this,PY),!sY(e))throw TypeError(`invalid argument`);IY(e);let n=Q(this,Vq),r=gX(n,Q(this,Rq),`month-day`);return r=GX(n,r,_X(n,e,[`year`,`month`,`monthCode`,`day`],[],`partial`)),FX($X(n,r,QY(e$(t))),n)}equals(e){$(this,PY);let t=wX(e);return WQ(Q(this,Rq),Q(t,Rq))===0&&XX(Q(this,Vq),Q(t,Vq))}toString(e=void 0){return $(this,PY),vZ(this,nX(e$(e)))}toJSON(){return $(this,PY),vZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,PY),new A$(e,t).format(this)}valueOf(){a$(`PlainMonthDay`)}toPlainDate(e){if($(this,PY),!sY(e))throw TypeError(`argument should be an object`);let t=Q(this,Vq);return jX(ZX(t,GX(t,gX(t,Q(this,Rq),`month-day`),_X(t,e,[`year`],[],[])),`constrain`),t)}static from(e,t=void 0){return wX(e,t)}};function Y$(e,t){$(e,PY);let n=Q(e,Rq);return hX(e).isoToDate(n,{[t]:!0})[t]}function X$(e){return iZ(e,ZQ())}SJ(J$,`Temporal.PlainMonthDay`);var Z$={instant:()=>VX(ZQ()),plainDateTimeISO:(e=QQ())=>NX(X$(eZ(e)),`iso8601`),plainDateISO:(e=QQ())=>jX(X$(eZ(e)).isoDate,`iso8601`),plainTimeISO:(e=QQ())=>LX(X$(eZ(e)).time),timeZoneId:()=>QQ(),zonedDateTimeISO:(e=QQ())=>{let t=eZ(e);return UX(ZQ(),t,`iso8601`)},[Symbol.toStringTag]:`Temporal.Now`};Object.defineProperty(Z$,Symbol.toStringTag,{value:`Temporal.Now`,writable:!1,enumerable:!1,configurable:!0});var Q$=class e{constructor(e=0,t=0,n=0,r=0,i=0,a=0){let o=e===void 0?0:uY(e),s=t===void 0?0:uY(t),c=n===void 0?0:uY(n),l=r===void 0?0:uY(r),u=i===void 0?0:uY(i),d=a===void 0?0:uY(a);QZ(o,s,c,l,u,d),IX(this,{hour:o,minute:s,second:c,millisecond:l,microsecond:u,nanosecond:d})}get hour(){return $(this,jY),Q(this,Bq).hour}get minute(){return $(this,jY),Q(this,Bq).minute}get second(){return $(this,jY),Q(this,Bq).second}get millisecond(){return $(this,jY),Q(this,Bq).millisecond}get microsecond(){return $(this,jY),Q(this,Bq).microsecond}get nanosecond(){return $(this,jY),Q(this,Bq).nanosecond}with(t,n=void 0){if($(this,jY),!sY(t))throw TypeError(`invalid argument`);IY(t);let r=vX(t,`partial`),i=vX(this),{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=Object.assign(i,r),d=QY(e$(n));return{hour:a,minute:o,second:s,millisecond:c,microsecond:l,nanosecond:u}=JY(a,o,s,c,l,u,d),new e(a,o,s,c,l,u)}add(e){return $(this,jY),FQ(`add`,this,e)}subtract(e){return $(this,jY),FQ(`subtract`,this,e)}until(e,t=void 0){return $(this,jY),TQ(`until`,this,e,t)}since(e,t=void 0){return $(this,jY),TQ(`since`,this,e,t)}round(e){if($(this,jY),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?t$(`smallestUnit`,e):e$(e),n=rX(t),r=eX(t,`halfExpand`),i=cX(t,`smallestUnit`,`time`,sX);return iX(n,{hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i],!1),LX(VQ(Q(this,Bq),n,i,r))}equals(e){$(this,jY);let t=TX(e);return GQ(Q(this,Bq),Q(t,Bq))===0}toString(e=void 0){$(this,jY);let t=e$(e),n=aX(t),r=eX(t,`trunc`),i=cX(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}=oX(i,n);return gZ(VQ(Q(this,Bq),s,o,r),a)}toJSON(){return $(this,jY),gZ(Q(this,Bq),`auto`)}toLocaleString(e=void 0,t=void 0){return $(this,jY),new A$(e,t).format(this)}valueOf(){a$(`PlainTime`)}static from(e,t=void 0){return TX(e,t)}static compare(e,t){let n=TX(e),r=TX(t);return GQ(Q(n,Bq),Q(r,Bq))}};SJ(Q$,`Temporal.PlainTime`);var $$=class{constructor(e,t,n=`iso8601`,r=1){let i=uY(e),a=uY(t),o=r$(n===void 0?`iso8601`:mY(n)),s=uY(r);XZ(i,a,s),RX(this,{year:i,month:a,day:s},o)}get year(){return e1(this,`year`)}get month(){return e1(this,`month`)}get monthCode(){return e1(this,`monthCode`)}get calendarId(){return $(this,NY),Q(this,Vq)}get era(){return e1(this,`era`)}get eraYear(){return e1(this,`eraYear`)}get daysInMonth(){return e1(this,`daysInMonth`)}get daysInYear(){return e1(this,`daysInYear`)}get monthsInYear(){return e1(this,`monthsInYear`)}get inLeapYear(){return e1(this,`inLeapYear`)}with(e,t=void 0){if($(this,NY),!sY(e))throw TypeError(`invalid argument`);IY(e);let n=Q(this,Vq),r=gX(n,Q(this,Rq),`year-month`);return r=GX(n,r,_X(n,e,[`year`,`month`,`monthCode`],[],`partial`)),zX(QX(n,r,QY(e$(t))),n)}add(e,t=void 0){return $(this,NY),IQ(`add`,this,e,t)}subtract(e,t=void 0){return $(this,NY),IQ(`subtract`,this,e,t)}until(e,t=void 0){return $(this,NY),EQ(`until`,this,e,t)}since(e,t=void 0){return $(this,NY),EQ(`since`,this,e,t)}equals(e){$(this,NY);let t=DX(e);return WQ(Q(this,Rq),Q(t,Rq))===0&&XX(Q(this,Vq),Q(t,Vq))}toString(e=void 0){return $(this,NY),yZ(this,nX(e$(e)))}toJSON(){return $(this,NY),yZ(this)}toLocaleString(e=void 0,t=void 0){return $(this,NY),new A$(e,t).format(this)}valueOf(){a$(`PlainYearMonth`)}toPlainDate(e){if($(this,NY),!sY(e))throw TypeError(`argument should be an object`);let t=Q(this,Vq);return jX(ZX(t,GX(t,gX(t,Q(this,Rq),`year-month`),_X(t,e,[`day`],[],[])),`constrain`),t)}static from(e,t=void 0){return DX(e,t)}static compare(e,t){let n=DX(e),r=DX(t);return WQ(Q(n,Rq),Q(r,Rq))}};function e1(e,t){$(e,NY);let n=Q(e,Rq);return hX(e).isoToDate(n,{[t]:!0})[t]}SJ($$,`Temporal.PlainYearMonth`);var qde=A$.prototype.resolvedOptions,t1=class{constructor(e,t,n=`iso8601`){if(arguments.length<1)throw TypeError(`missing argument: epochNanoseconds is required`);let r=XQ(e),i=mY(t),{tzName:a,offsetMinutes:o}=KY(i);if(o===void 0){let e=TZ(a);if(!e)throw RangeError(`unknown time zone ${a}`);i=e.identifier}else i=OZ(o);HX(this,r,i,r$(n===void 0?`iso8601`:mY(n)))}get calendarId(){return $(this,FY),Q(this,Vq)}get timeZoneId(){return $(this,FY),Q(this,Gq)}get year(){return r1(this,`year`)}get month(){return r1(this,`month`)}get monthCode(){return r1(this,`monthCode`)}get day(){return r1(this,`day`)}get hour(){return i1(this,`hour`)}get minute(){return i1(this,`minute`)}get second(){return i1(this,`second`)}get millisecond(){return i1(this,`millisecond`)}get microsecond(){return i1(this,`microsecond`)}get nanosecond(){return i1(this,`nanosecond`)}get era(){return r1(this,`era`)}get eraYear(){return r1(this,`eraYear`)}get epochMilliseconds(){return $(this,FY),JQ(Q(this,Lq),`floor`)}get epochNanoseconds(){return $(this,FY),qQ(Q(this,Lq))}get dayOfWeek(){return r1(this,`dayOfWeek`)}get dayOfYear(){return r1(this,`dayOfYear`)}get weekOfYear(){return r1(this,`weekOfYear`)?.week}get yearOfWeek(){return r1(this,`weekOfYear`)?.year}get hoursInDay(){$(this,FY);let e=Q(this,Gq),t=n1(this).isoDate,n=HZ(t.year,t.month,t.day+1),r=cZ(e,t),i=cZ(e,n);return UQ(kJ.fromEpochNsDiff(i,r),`hour`)}get daysInWeek(){return r1(this,`daysInWeek`)}get daysInMonth(){return r1(this,`daysInMonth`)}get daysInYear(){return r1(this,`daysInYear`)}get monthsInYear(){return r1(this,`monthsInYear`)}get inLeapYear(){return r1(this,`inLeapYear`)}get offset(){return $(this,FY),rZ(nZ(Q(this,Gq),Q(this,Lq)))}get offsetNanoseconds(){return $(this,FY),nZ(Q(this,Gq),Q(this,Lq))}with(e,t=void 0){if($(this,FY),!sY(e))throw TypeError(`invalid zoned-date-time-like`);IY(e);let n=Q(this,Vq),r=Q(this,Gq),i=nZ(r,Q(this,Lq)),a=n1(this),o={...gX(n,a.isoDate),...a.time,offset:rZ(i)};o=GX(n,o,_X(n,e,[`year`,`month`,`monthCode`,`day`],[`hour`,`minute`,`second`,`millisecond`,`microsecond`,`nanosecond`,`offset`],`partial`));let s=e$(t),c=$Y(s),l=tX(s,`prefer`),u=bX(n,o,QY(s)),d=SZ(o.offset);return UX(OX(u.isoDate,u.time,`option`,d,r,c,l,!1),r,n)}withPlainTime(e=void 0){$(this,FY);let t=Q(this,Gq),n=Q(this,Vq),r=n1(this).isoDate,i;return i=e===void 0?cZ(t,r):aZ(t,ZY(r,Q(TX(e),Bq)),`compatible`),UX(i,t,n)}withTimeZone(e){$(this,FY);let t=eZ(e);return UX(Q(this,Lq),t,Q(this,Vq))}withCalendar(e){$(this,FY);let t=JX(e);return UX(Q(this,Lq),Q(this,Gq),t)}add(e,t=void 0){return $(this,FY),LQ(`add`,this,e,t)}subtract(e,t=void 0){return $(this,FY),LQ(`subtract`,this,e,t)}until(e,t=void 0){return $(this,FY),DQ(`until`,this,e,t)}since(e,t=void 0){return $(this,FY),DQ(`since`,this,e,t)}round(e){if($(this,FY),e===void 0)throw TypeError(`options parameter is required`);let t=typeof e==`string`?t$(`smallestUnit`,e):e$(e),n=rX(t),r=eX(t,`halfExpand`),i=cX(t,`smallestUnit`,`time`,sX,[`day`]),a={day:1,hour:24,minute:60,second:60,millisecond:1e3,microsecond:1e3,nanosecond:1e3}[i];if(iX(n,a,a===1),i===`nanosecond`&&n===1)return UX(Q(this,Lq),Q(this,Gq),Q(this,Vq));let o=Q(this,Gq),s=Q(this,Lq),c=n1(this),l;if(i===`day`){let e=c.isoDate,t=HZ(e.year,e.month,e.day+1),n=cZ(o,e),i=cZ(o,t),a=Z.default.subtract(i,n);l=kJ.fromEpochNsDiff(s,n).round(a,r).addToEpochNs(n)}else{let e=BQ(c,n,i,r),t=nZ(o,s);l=OX(e.isoDate,e.time,`option`,t,o,`compatible`,`prefer`,!1)}return UX(l,o,Q(this,Vq))}equals(e){$(this,FY);let t=kX(e),n=Q(this,Lq),r=Q(t,Lq);return!!Z.default.equal(Z.default.BigInt(n),Z.default.BigInt(r))&&!!tZ(Q(this,Gq),Q(t,Gq))&&XX(Q(this,Vq),Q(t,Vq))}toString(e=void 0){$(this,FY);let t=e$(e),n=nX(t),r=aX(t),i=function(e){return n$(e,`offset`,[`auto`,`never`],`auto`)}(t),a=eX(t,`trunc`),o=cX(t,`smallestUnit`,`time`,void 0);if(o===`hour`)throw RangeError(`smallestUnit must be a time unit other than "hour"`);let s=function(e){return n$(e,`timeZoneName`,[`auto`,`never`,`critical`],`auto`)}(t),{precision:c,unit:l,increment:u}=oX(o,r);return bZ(this,c,n,s,i,{unit:l,increment:u,roundingMode:a})}toLocaleString(e=void 0,t=void 0){$(this,FY);let n=e$(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,Gq),xZ(r.timeZone))throw RangeError(`toLocaleString does not currently support offset time zones`);let i=new A$(e,r),a=qde.call(i).calendar,o=Q(this,Vq);if(o!==`iso8601`&&a!==`iso8601`&&!XX(a,o))throw RangeError(`cannot format ZonedDateTime with calendar ${o} in locale with calendar ${a}`);return i.format(VX(Q(this,Lq)))}toJSON(){return $(this,FY),bZ(this,`auto`)}valueOf(){a$(`ZonedDateTime`)}startOfDay(){$(this,FY);let e=Q(this,Gq);return UX(cZ(e,n1(this).isoDate),e,Q(this,Vq))}getTimeZoneTransition(e){$(this,FY);let t=Q(this,Gq);if(e===void 0)throw TypeError(`options parameter is required`);let n=n$(typeof e==`string`?t$(`direction`,e):e$(e),`direction`,[`next`,`previous`],sX);if(n===void 0)throw TypeError(`direction option is required`);if(xZ(t)||t===`UTC`)return null;let r=Q(this,Lq),i=n===`next`?NZ(t,r):PZ(t,r);return i===null?null:UX(i,t,Q(this,Vq))}toInstant(){return $(this,FY),VX(Q(this,Lq))}toPlainDate(){return $(this,FY),jX(n1(this).isoDate,Q(this,Vq))}toPlainTime(){return $(this,FY),LX(n1(this).time)}toPlainDateTime(){return $(this,FY),NX(n1(this),Q(this,Vq))}static from(e,t=void 0){return kX(e,t)}static compare(e,t){let n=kX(e),r=kX(t),i=Q(n,Lq),a=Q(r,Lq);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 n1(e){return iZ(Q(e,Gq),Q(e,Lq))}function r1(e,t){$(e,FY);let n=n1(e).isoDate;return hX(e).isoToDate(n,{[t]:!0})[t]}function i1(e,t){return $(e,FY),n1(e).time[t]}SJ(t1,`Temporal.ZonedDateTime`);var Jde=Object.freeze({__proto__:null,Duration:q$,Instant:V$,Now:Z$,PlainDate:H$,PlainDateTime:W$,PlainMonthDay:J$,PlainTime:Q$,PlainYearMonth:$$,ZonedDateTime:t1});(class{toTemporalInstant(){return VX(YQ(Date.prototype.valueOf.call(this)))}}).prototype.toTemporalInstant;var Yde=[V$,H$,W$,q$,J$,Q$,$$,t1];for(let e of Yde){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 Xde(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 Zde(e,t){return Xde(new Date(e),t)}function Qde(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=Jde.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 a1(e,t){return new Intl.DateTimeFormat(void 0,{timeZone:t,dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}var o1={"claude-code":{name:`Claude Code`,command:`claude auth login`},codex:{name:`Codex`,command:`codex login`},gemini:{name:`Gemini`,command:`gemini`}},$de=/not signed in|sign-in has expired|not logged in|run\s+"?(?:codex login|claude auth login)|authentication required/i,efe=/ENOSPC|no space left on device|disk (?:is )?full|not enough (?:free )?(?:disk )?space/i,tfe=/refused to make|content (?:rules|policy|filter)|safety (?:system|filter)|flagged|moderation/i,nfe=/\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,rfe=/did not accept the API key|API key is saved|invalid api key|key may be wrong/i,ife=[`images`,`thumbnail`],afe=/^Short \d+ image \d+:/;function s1(e){let t=e.reason??``,n=ofe(e.provider,t);if(n!==void 0&&($de.test(t)||e.kind===`auth`))return{kind:`sign-in`,label:`Sign in to ${o1[n].name}`,cli:n,command:o1[n].command};if(efe.test(t))return{kind:`free-space`,label:`Free space`};if(e.kind===`refusal`||tfe.test(t))return ife.includes(e.stage)||e.stage===`video`&&afe.test(t)?{kind:`refused`,label:`Soften and retry`,soften:!0}:{kind:`refused`,label:`Edit the prompt`,soften:!1};if(nfe.test(t))return{kind:`switch-model`,label:`Switch model`};if(e.kind===`auth`||e.kind===`missing_key`||rfe.test(t)){let t=sfe(e.provider);return{kind:`provider-settings`,label:t===void 0?`Open Settings → Providers`:`Open Settings → Providers → ${t}`,provider:e.provider??``}}}function ofe(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 sfe(e){return FF.find(t=>t.id===e)?.displayName}function cfe(e,t){switch(t){case`audio`:return e.audio?.provider;case`images`:case`thumbnail`:return e.images?.provider;case`research`:case`article`:return e.llm?.provider;default:return}}var c1={catalogue:[`catalogue`],retired:[`catalogue`,`retired`],firstRun:[`first-run`]},l1={method:`POST`};async function lfe(e,t,n){return R(await e.fetch(`${e.origin}/api/providers/${t}/key/test`,n===void 0?l1:{...l1,headers:{"content-type":`application/json`},body:JSON.stringify({key:n})}))}async function u1(e,t){let n=t===void 0?``:`?provider=${encodeURIComponent(t)}`;return R(await e.fetch(`${e.origin}/api/providers/health${n}`,l1))}async function ufe(e){return R(await e.fetch(`${e.origin}/api/providers/catalogue`))}async function dfe(e){return R(await e.fetch(`${e.origin}/api/providers/catalogue/check`,l1))}async function ffe(e){return R(await e.fetch(`${e.origin}/api/providers/catalogue/refresh`,l1))}async function d1(e){return(await R(await e.fetch(`${e.origin}/api/providers/catalogue/retired`))).usages}async function f1(e,t){await R(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:t.kind,id:t.id,slot:t.slot,from:{provider:t.provider,model:t.model},to:t.replacement?.id??``})}))}async function pfe(e){return R(await e.fetch(`${e.origin}/api/providers/catalogue/retired/switch-all`,l1))}async function mfe(e){return R(await e.fetch(`${e.origin}/api/providers/first-run`))}async function hfe(e){let t=await e.fetch(`${e.origin}/api/providers/first-run/dismiss`,l1);t.ok||await R(t)}function gfe(e,t){let n=e.providers.find(e=>e.id===t.cli)?.checks.find(e=>e.label===`Signed in`);return n?.state===`ok`?`signed-in`:n?.state===`problem`?`signed-out`:`unknown`}function _fe(e){return e.label.replace(/^Sign in to /,``)}async function p1(e){if(!navigator.clipboard)return!1;try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function m1({fix:e,retry:t,variant:n=`primary`,size:r=`default`}){let{api:i}=V(),a=Ry(),o=_fe(e),s=L({mutationFn:async()=>gfe(await u1(i,e.cli),e),onSuccess:n=>{if(n===`signed-out`){a(`${o} is still signed out. Run ${e.command} in a terminal on the computer running Slopify, sign in, then press Check again.`,`error`);return}if(t===void 0){a(n===`signed-in`?`${o} is signed in.`:`Slopify couldn't tell whether ${o} is signed in. If ${e.command} finished without an error, try the step again.`,n===`signed-in`?`success`:`info`);return}a(`${o} is signed in. Trying again.`,`success`),t.run()},onError:e=>a(`Slopify couldn't check ${o}'s sign-in: ${e.message} Press Check again in a moment, or use Check all in Settings → Providers.`,`error`)}),c=async()=>{let t=await p1(e.command);a(t?`Copied ${e.command}. Paste it in a terminal on the computer running Slopify and sign in, then press Check again.`:`Couldn't copy: the browser blocked the clipboard. Type ${e.command} in a terminal on the computer running Slopify, sign in, then press Check again.`,t?`success`:`error`)};return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:n,size:r,onClick:()=>void c(),children:`Copy sign-in command`}),(0,h.jsx)(B,{variant:`secondary`,size:r,disabled:s.isPending||t?.busy===!0,disabledReason:`Checking the sign-in…`,onClick:()=>s.mutate(),children:s.isPending?`Checking…`:`Check again`})]})}function h1({fix:e,retry:t,edit:n,variant:r=`primary`,size:i=`default`}){switch(e.kind){case`sign-in`:return(0,h.jsx)(m1,{fix:e,retry:t,variant:r,size:i});case`provider-settings`:return(0,h.jsx)(CS,{to:`/settings`,search:{section:`providers`},variant:r,size:i,children:e.label});case`free-space`:return(0,h.jsx)(CS,{to:`/settings`,search:{section:`storage`},variant:r,size:i,children:e.label});case`refused`:case`switch-model`:return n??null}}function vfe(e){let t=e.topics.error;if(t!==null)return s1({stage:`article`,reason:t,provider:e.topicGeneration.llm?.provider})}function g1({schedule:e,title:t,retry:n,className:r}){if(e.topics.error===null)return null;let i=vfe(e);return(0,h.jsx)(aI,{tone:`danger`,title:t,...r===void 0?{}:{className:r},...i===void 0?{}:{actions:(0,h.jsx)(h1,{fix:i,retry:n,variant:`secondary`,size:`small`})},children:e.topics.error})}function _1(e){let t=Object.entries(e);return t.length===0?void 0:t.map(([e,t])=>`${e}: ${t}`).join(` · `)}function yfe({schedule:e}){let{api:t}=V(),n=_(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(null),s=e.deletedAt===null&&(e.status===`active`||e.status===`paused`),c=I({queryKey:[...eH(e.id),e.topics.held,e.topics.generatedAt],enabled:s&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await tH(t,e.id);if(!n.ok)throw Error(n.message);return n.value}}),l=I({queryKey:[`project-template`,e.templateId],enabled:s&&e.topicGeneration.mode===`hold`,queryFn:async()=>{let n=await uq(t,e.templateId);if(!n.ok)throw Error(n.message);return n.value}}).data?.document.form,u=(l===void 0?[]:RK(l)).filter(t=>t!==e.topicKeyword),d=t=>e.values[t]??l?.values[t]??``,f=L({mutationFn:e=>e(),onSuccess:e=>{i(e.ok?null:e.message),e.ok&&o(null)},onError:e=>i(e.message),onSettled:async()=>{await Promise.all([n.invalidateQueries({queryKey:KV}),n.invalidateQueries({queryKey:eH(e.id)}),n.invalidateQueries({queryKey:fH})])}});if(!s||e.topicGeneration.mode===`off`)return null;let{topics:p}=e,g=f.isPending,v=c.data??[];return(0,h.jsxs)(`section`,{"aria-label":`Topic generation`,children:[(0,h.jsx)($K,{className:`my-6`}),(0,h.jsxs)(W,{as:`h3`,title:`Topic generation`,meta:`${p.generatingSince===null?p.generatedAt===null?`No topics generated yet.`:`Topics last generated ${a1(p.generatedAt,e.timezone)}.`:`Generating topics now…`} Keeps at least ${String(e.topicGeneration.keepAtLeast)} ${e.topicGeneration.mode===`hold`?`queued or waiting`:`queued`}.`,children:[(0,h.jsx)(U,{id:`planning.schedule.generate-now`}),(0,h.jsx)(B,{disabled:g||p.generatingSince!==null,disabledReason:`Topics are being generated now`,onClick:()=>f.mutate(()=>rH(t,e.id)),children:`Generate topics now`})]}),(0,h.jsx)(g1,{schedule:e,title:`The last topic generation failed.`,className:`mt-3`,retry:{run:()=>f.mutate(()=>rH(t,e.id)),busy:g||p.generatingSince!==null}}),r===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`That didn't work.`,className:`mt-3`,children:r}),e.topicGeneration.mode===`hold`?(0,h.jsxs)(`div`,{className:`mt-4`,...zb,children:[(0,h.jsx)(W,{as:`h3`,title:`Topics waiting · ${String(v.length)}`,info:`planning.schedule.held`,children:(0,h.jsx)(B,{variant:`primary`,disabled:g||v.length===0,disabledReason:`Nothing is waiting`,onClick:()=>f.mutate(()=>oH(t,e.id)),children:`Approve all`})}),c.error?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-danger`,children:`The waiting topics couldn't be loaded: ${c.error.message} Reload the page to try again.`}):v.length===0?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-ink-3`,children:`Nothing is waiting. New topics appear here for you to approve.`}):(0,h.jsx)(PH,{label:`Topics waiting`,className:`mt-2 [&_.sl-row__actions]:flex-wrap`,children:v.map(n=>(0,h.jsx)(FH,{title:a?.id===n.id?(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(zB,{"aria-label":`Edit ${n.title}`,className:`w-full`,maxLength:200,value:a.title,onChange:e=>o({...a,title:e.target.value})}),u.length===0?null:(0,h.jsx)(`div`,{className:`grid grid-cols-1 gap-2 min-[600px]:grid-cols-2`,children:u.map(e=>(0,h.jsx)(LB,{label:e,tip:`planning.schedule.held-keywords`,children:(0,h.jsx)(zB,{maxLength:2e3,placeholder:d(e)||`Not set`,value:a.values[e]??``,onChange:t=>o({...a,values:{...a.values,[e]:t.target.value}})})},e))})]}):n.title,meta:a?.id===n.id?void 0:_1(n.values),actions:a?.id===n.id?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,disabled:g||a.title.trim()===``,onClick:()=>f.mutate(()=>cH(t,e.id,n.id,a.title.trim(),Object.fromEntries(Object.entries(a.values).filter(([,e])=>e.trim()!==``)))),children:`Save`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:()=>o(null),children:`Cancel`})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,disabled:g,onClick:()=>f.mutate(()=>aH(t,e.id,n.id)),children:`Approve`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:g,onClick:()=>o({id:n.id,title:n.title,values:n.values}),children:`Edit`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:g,onClick:()=>f.mutate(()=>sH(t,e.id,n.id)),children:`Reject`})]})},n.id))})]}):null]})}function bfe({schedules:e}){let t=e.filter(e=>e.deletedAt===null&&e.topicGeneration.mode!==`off`&&(e.status===`active`||e.status===`paused`));return(0,h.jsx)(`div`,{className:`flex flex-col gap-6`,children:t.length===0?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Suggested topics`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No schedule suggests its own topics yet. Turn on topic generation in a schedule and its suggestions wait here for you.`}),(0,h.jsx)(`div`,{children:(0,h.jsx)(wS,{to:`/calendar`,search:{tab:`schedules`},children:`Open schedules`})})]}):t.map((e,t)=>(0,h.jsx)(xfe,{schedule:e,first:t===0},e.id))})}function xfe({schedule:e,first:t}){let{api:n}=V(),r=_(),i=Ry(),a=I({queryKey:[...eH(e.id),e.topics.held,e.version],queryFn:async()=>{let t=await tH(n,e.id);if(!t.ok)throw Error(t.message);return t.value},enabled:e.topics.held>0}),o=L({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:KV}),r.invalidateQueries({queryKey:fH}),r.invalidateQueries({queryKey:eH(e.id)})])}}),s=e.topics.held>0?a.data??[]:[],c=()=>o.mutate(()=>oH(n,e.id));jx({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)(W,{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)(B,{size:`small`,variant:`secondary`,disabled:o.isPending,onClick:c,children:`Queue all ${String(s.length)}`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(U,{id:`planning.schedule.generate-now`,label:`Suggest topics now`}),(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:o.isPending||l,disabledReason:l?`Slopify is suggesting topics now.`:`Working…`,onClick:()=>o.mutate(()=>rH(n,e.id)),children:l?`Suggesting…`:`Suggest topics now`})]})}),(0,h.jsx)(g1,{schedule:e,title:`The last suggestion failed.`,retry:{run:()=>o.mutate(()=>rH(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)(PH,{label:`Suggestions for ${e.name}`,children:s.map(t=>(0,h.jsx)(FH,{title:t.title,meta:_1(t.values),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:o.isPending,onClick:()=>o.mutate(()=>aH(n,e.id,t.id)),"aria-label":`Queue ${t.title}`,children:`Queue`}),(0,h.jsx)(Py,{size:`small`,label:`Reject ${t.title}`,disabled:o.isPending,onClick:()=>o.mutate(()=>sH(n,e.id,t.id)),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]})},t.id))}),(0,h.jsx)(aI,{title:`Keeps at least ${String(e.topicGeneration.keepAtLeast)} ${e.topicGeneration.keepAtLeast===1?`topic`:`topics`} queued.`,children:u?`New suggestions wait here for you. Change this under Schedules → Edit.`:`New suggestions join the queue straight away. Change this under Schedules → Edit.`})]})}var Sfe={info:`text-ink-2`,error:`text-danger`,warning:`text-waiting`,success:`text-accent-ink`};function v1({children:e,tone:t=`info`,className:n,id:r}){let i=typeof e==`string`?e:void 0;return(0,h.jsx)(`div`,{id:r,"data-slot":`status-slot`,role:t===`error`?`alert`:`status`,title:i,className:z(`flex min-h-8 min-w-0 flex-1 items-center gap-2 overflow-hidden text-small`,Sfe[t],n),children:e==null||e===!1?null:i===void 0?e:(0,h.jsx)(`span`,{className:`min-w-0 truncate`,children:i})})}function y1({status:e,children:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`action-bar`,className:z(`sticky bottom-0 z-20 -mx-4 mt-6 flex min-h-14 flex-wrap items-center gap-x-3 gap-y-2 border-t border-line bg-surface px-4 py-2 pb-[max(8px,env(safe-area-inset-bottom))] max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))] md:-mx-10 md:px-10`,n),children:[(0,h.jsx)(`div`,{className:`flex w-full min-w-0 sm:w-auto sm:flex-1`,children:e??(0,h.jsx)(v1,{})}),(0,h.jsx)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:t})]})}function b1({split:e=`main-side`,className:t,children:n}){return(0,h.jsx)(`div`,{"data-slot":`board`,className:z(`sl-board`,`sl-board--${e}`,t),children:n})}function x1({as:e=`div`,label:t,className:n,children:r}){let i=z(`sl-board__column`,n);return e===`aside`?(0,h.jsx)(`aside`,{"aria-label":t,className:i,children:r}):t===void 0?(0,h.jsx)(`div`,{className:i,children:r}):(0,h.jsx)(`section`,{"aria-label":t,className:i,children:r})}var S1=`sl-tab inline-flex items-center gap-[6px]`;function C1({items:e,value:t,onChange:n,label:r,idPrefix:i,trailing:a,className:o}){let s=(0,m.useRef)(null);return(0,h.jsxs)(`div`,{className:z(`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:S1,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 Cfe({items:e,label:t,className:n}){return(0,h.jsx)(`nav`,{"aria-label":t,className:z(`sl-tabs min-w-0`,n),children:e.map(e=>(0,h.jsx)(fa,{to:e.to,...e.search?{search:e.search}:{},activeOptions:{exact:!1,includeSearch:!1},className:S1,activeProps:{"aria-current":`page`},children:e.label},e.to))})}function w1({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 T1({title:e,children:t,actions:n,className:r}){return(0,h.jsxs)(`div`,{className:z(`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 E1(e){return e.channelId??`00000000-0000-4000-8000-000000000001`}function wfe({channelId:e}){let{api:t}=V(),n=_(),r=I(lq(t)),i=I(cx(t)),a=L({mutationFn:e=>yx(t,e.templateId,e.channelId),onSettled:()=>Promise.all([n.invalidateQueries({queryKey:iq}),n.invalidateQueries({queryKey:ix})])}),o=(r.data??[]).filter(t=>E1(t)===e);return(0,h.jsxs)(`div`,{...zb,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)(fa,{to:`/templates`,className:`underline`,children:`Library → Templates`}),`. Move to sends a template and its schedules to another channel.`,` `,(0,h.jsx)(U,{id:`planning.channel.template-move`,className:`-my-1 align-middle`})]}),(0,h.jsx)(v1,{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)(T1,{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)(PH,{label:`Channel templates`,className:`[&_.sl-row__actions]:flex-wrap`,children:o.map(t=>(0,h.jsx)(FH,{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)(VB,{"aria-label":`Channel of ${t.name}`,value:e,disabled:a.isPending,onChange:e=>a.mutate({templateId:t.id,channelId:e.target.value}),options:(i.data??[]).map(e=>({value:e.id,label:e.name}))})]})},t.id))}):null]})}var Tfe={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Efe={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function Dfe({channelId:e}){let{api:t}=V(),n=I(lq(t)),r=I(qV(t)),i=new Set((n.data??[]).filter(t=>E1(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)(fa,{to:`/calendar`,search:{tab:`schedules`},className:`underline`,children:`Calendar → Schedules`}),`.`]}),(0,h.jsx)(v1,{tone:r.error?`error`:`info`,className:`mb-2`,children:r.error?.message}),r.data&&a.length===0?(0,h.jsx)(T1,{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)(PH,{label:`Channel schedules`,children:a.map(e=>(0,h.jsx)(FH,{title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(OS,{tone:Efe[e.status],children:Tfe[e.status]}),` · ${e.nextRunAt===null?`No next run`:`Next run ${a1(e.nextRunAt,e.timezone)}`} · ${String(e.items.length)} queued`]})},e.id))}):null]})}var D1={llm:`Text model`,audio:`Voice model`,images:`Image model`,animate:`Animation model`};function O1({kind:e,id:t,name:n}){let{api:r}=V(),i=_(),a=I({queryKey:c1.retired,queryFn:()=>d1(r)}),o=L({mutationFn:e=>f1(r,e),onSuccess:()=>Promise.all([i.invalidateQueries({queryKey:c1.retired}),i.invalidateQueries({queryKey:iq}),i.invalidateQueries({queryKey:KV})])}),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:[`${D1[t.slot]} ${t.model} is ${t.why===`retired`?`retired`:`no longer listed`}.`,t.blocked===null?``:` ${t.blocked}`,t.replacement===null&&t.blocked===null?` No replacement is suggested: choose another model in Settings → Models, or edit the ${e}.`:``]}),t.replacement===null?null:(0,h.jsx)(B,{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 k1(e){return IA(e)?`script`:`article`}function Ofe(e){let{form:t}=e,n=[],r=[];if(P1(n,t.title),rj(t)&&P1(n,M1(e.prompts,`narration`,t.narrationPrompt??``)),t.sources.article===`generate`&&P1(n,M1(e.prompts,k1(t),t.articlePrompt)),t.sources.audio===`generate`&&(P1(n,N1(e.entries,`intro`,t.intro)),P1(n,N1(e.entries,`outro`,t.outro))),oj(t)&&P1(n,M1(e.prompts,`description`,t.descriptionPrompt??``)),wN(t)&&(P1(n,M1(e.prompts,`shorts`,t.shorts?.prompt??``)),P1(r,M1(e.prompts,`image`,t.shorts?.imagePrompt??``))),t.sources.images===`generate`){for(let n of t.imagePrompts)P1(r,M1(e.prompts,`image`,n.name));t.reference?.source===`prompt`&&P1(r,M1(e.prompts,`image`,t.reference.prompt))}return(t.sources.thumbnail===`from_prompt`||t.sources.thumbnail===`prompt_by_llm`)&&P1(r,M1(e.prompts,`thumbnail`,t.thumbnailPrompt)),PK(n,r)}function kfe(e){let t=Ofe(e),n={form:e.form,entries:e.entries,slots:t.map(e=>e.name),silenceGapSeconds:e.silenceGapSeconds},r=MN(n),i=qA({draft:r,staged:jN(e.form.provided),requiredSlots:n.slots}),a=SN(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:Afe(e.form,a)}}var A1=`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 Afe(e,t){let n=jfe(e);if(n!==void 0)return n;if(t.ok)return;let r=[...t.fields].sort((e,t)=>j1(e.field)-j1(t.field))[0];return r===void 0?void 0:{field:r.field,hint:Mfe(e,r)}}function jfe(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),wN(e)&&n.shortsMusic!==void 0&&r.push(n.shortsMusic),TN(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 j1(e){let t=A1.length;for(let[n,r]of A1.entries())(e===r||e.startsWith(`${r}.`))&&n<t&&(t=n);return t}function Mfe(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 k1(e)===`script`?`Pick a script prompt to play`:`Pick an article prompt to play`;case`audio`:return`Pick a narration provider to play`;case`audio.voice`:return`Pick a voice to play`;case`images`:return`Pick an image provider and model to play`;case`thumbnailPrompt`:return`Pick a thumbnail prompt to play`;case`youtubeDescription`:return`Turn narration on, or the YouTube description off, to play`;case`shorts.enabled`:return`Turn narration on, or Shorts off, to play`;case`shorts.count`:return`Set how many shorts to make to play`;case`shorts.minSeconds`:case`shorts.maxSeconds`:return`Set the shorts' length to play`;case`shorts.speed`:return`Choose the shorts' speed to play`;case`shorts.musicVolume`:return`Set the shorts' music volume to play`;case`shorts.music`:return`Attach the shorts' background music again, or remove it, to play`;case`shorts.fullVideoLink`:return`Fix the full video link to play`;case`provided.research`:return`Paste the research notes to play`;case`provided.article`:return`Paste the article to play`;case`provided.audio`:return`Attach the narration audio to play`;case`provided.images`:return e.provided.images.length>60?`Remove images to play: a run holds at most 60`:`Attach at least one image to play`;case`provided.thumbnail`:return`Attach the thumbnail image to play`;case`reference.prompt`:return`Pick the establishing image's prompt to play`;case`provided.reference`:return`Attach the establishing image to play`;default:return t.message}}function M1(e,t,n){if(n!==``)return e.find(e=>e.kind===t&&e.name===n)?.body}function N1(e,t,n){if(n!==``)return e.find(e=>e.category===t&&e.name===n)?.body}function P1(e,t){t!==void 0&&e.push(t)}function F1(e){let t=new Map,n=(e,n)=>{if(e)for(let r of MK(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`),rj(r)&&n(M1(i,`narration`,r.narrationPrompt??``),`Narration Preparation`),r.sources.article===`generate`&&n(M1(i,k1(r),r.articlePrompt),`Article`),r.sources.images===`generate`){for(let e of r.imagePrompts)n(M1(i,`image`,e.name),`Image: ${e.name}`);r.reference?.source===`prompt`&&n(M1(i,`image`,r.reference.prompt),`Establishing image`)}if((r.sources.thumbnail===`from_prompt`||r.sources.thumbnail===`prompt_by_llm`)&&n(M1(i,`thumbnail`,r.thumbnailPrompt),`Thumbnail`),r.sources.audio===`generate`)for(let e of[`intro`,`outro`])n(N1(a,e,r[e]),e===`intro`?`Intro`:`Outro`);return oj(r)&&n(M1(i,`description`,r.descriptionPrompt??``),`YouTube description`),wN(r)&&(n(M1(i,`shorts`,r.shorts?.prompt??``),`Shorts`),n(M1(i,`image`,r.shorts?.imagePrompt??``),`Shorts images`)),t}var Nfe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],I1=Y({day:q().int().min(0).max(6),time:K().regex(/^([01]\d|2[0-3]):[0-5]\d$/)}),Pfe=Y({name:K().trim().min(1).max(20),series:K().trim().max(100).default(``),long:I1,shorts:J(I1).max(10),schedule:K().optional(),runDay:q().int().min(0).max(6).optional(),timeZone:K().optional(),label:K().optional()});Y({timeZone:K().min(1).max(100),rows:J(Pfe).max(14)});var Ffe=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Ife=[1,2,3,4,5,6,0];function L1(e,t){return{day:(e+1+Math.floor(t/2))%7,time:t%2==0?`12:00`:`17:00`}}function Lfe(e,t){return{day:e,long:{day:e,time:`20:00`},shorts:Array.from({length:t},(t,n)=>L1(e,n))}}function R1(e,t,n){return Ife.filter(e=>t.includes(e)).map(t=>{let r=e.find(e=>e.day===t)??Lfe(t,n);return{...r,shorts:Array.from({length:n},(e,n)=>r.shorts[n]??L1(t,n))}})}function z1({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)(VB,{"aria-label":`${t}: day`,className:`w-[84px]`,value:String(e.day),onChange:t=>n({...e,day:Number(t.currentTarget.value)}),options:Nfe.map((e,t)=>({value:String(t),label:e}))}),(0,h.jsx)(zB,{"aria-label":`${t}: time`,type:`time`,className:`w-[124px]`,value:e.time,onChange:t=>n({...e,time:t.currentTarget.value||e.time})})]})}function Rfe({releases:e,onReleases:t,runDays:n,shorts:r,once:i,timezone:a}){let o=e===null?[]:R1(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`,...zb,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)(B,{variant:`secondary`,onClick:()=>t(R1([],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:[Ffe[e.day],`'s run`]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-x-5 gap-y-2`,children:[(0,h.jsx)(z1,{label:`Video`,value:e.long,onChange:t=>s(e.day,{...e,long:t})}),e.shorts.map((t,n)=>(0,h.jsx)(z1,{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)(B,{variant:`quiet`,onClick:()=>t(null),children:`Set no release times`})})]})]})}function B1(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 V1({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=B1;return t===void 0?(0,h.jsx)(PH,{label:`Keywords`,children:e.map(e=>(0,h.jsx)(FH,{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)(LB,{label:a(e.name),tip:s,help:l(e),error:n?.(`${r}.${e.name}`),children:(0,h.jsx)(zB,{"data-play-field":`${r}.${e.name}`,value:e.value,maxLength:c,...o===void 0?{}:{"aria-label":o(e.name)},spellCheck:!1,"aria-invalid":n?.(`${r}.${e.name}`)!==void 0,onChange:n=>t(e.name,n.target.value)})},e.name))})}var H1={lines:`One per line`,table:`Table`,yaml:`YAML / JSON`};function U1(e){return{mode:`lines`,rows:e,lines:qK(e),base:e,yaml:``,columns:W1(e,[])}}function W1(e,t){return[...new Set([...t,...e.flatMap(e=>Object.keys(e.values))])]}function G1(e){return e.keywords.filter(t=>t!==e.topicKeyword&&(e.everyRun[t]??``).trim()===``)}function K1(e,t){if(t.form===void 0)return{rows:e.rows,problems:[]};if(e.mode===`yaml`){let n=JK(e.yaml,{keywords:t.keywords,topicKeyword:t.topicKeyword,required:G1(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:WK(n,{keywords:t.keywords,topicKeyword:t.topicKeyword,...e.mode===`table`?{required:G1(t)}:{},kept:t.kept})}}function zfe(e,t,n){if(t===e.mode)return{queue:e,problems:[]};let r=e.rows;if(e.mode===`yaml`){let t=JK(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`?qK(r):e.lines,base:t===`lines`?r:e.base,yaml:t===`yaml`?YK(r,n.topicKeyword):e.yaml,columns:W1(r,e.columns)},problems:[]}}function Bfe({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=K1(e,n),y=e.mode===`yaml`?v.rows:e.rows,b=e=>p===void 0?void 0:BK(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=()=>YK(K1(e,n).rows,f),T=()=>{let e=w();if(!navigator.clipboard){u(`Couldn't copy the list. Switch to YAML / JSON, select the text and copy it.`);return}navigator.clipboard.writeText(e).then(()=>u(`Copied ${String(y.length)} topics as YAML.`),()=>u(`Couldn't copy the list. Switch to YAML / JSON, select the text and copy it.`))},E=()=>{let e=URL.createObjectURL(new Blob([w()],{type:`application/yaml`})),t=document.createElement(`a`);t.href=e,t.download=`${(o.trim()||`schedule`).replace(/[^\w.-]+/g,`-`)}-topics.yaml`,t.click(),URL.revokeObjectURL(e),u(`Downloaded ${String(y.length)} topics as YAML.`)},D=(n,r)=>t({...e,rows:e.rows.map((e,t)=>t===n?r:e)}),O=d.filter(t=>t!==f&&!e.columns.includes(t)),k=[...s,...v.problems];return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topics (optional)`,(0,h.jsx)(U,{id:`planning.schedule.topics`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(Vb,{label:`How to write the topics`,tip:`planning.schedule.topic-format`,value:e.mode,options:Object.keys(H1).map(e=>({value:e,label:H1[e]})),onChange:r=>{let i=zfe(e,r,n);c(i.problems),t(i.queue)}}),(0,h.jsxs)(B,{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)(kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Copy as YAML`]}),(0,h.jsxs)(B,{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)(Ac,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Export as YAML`]}),l===null?null:(0,h.jsx)(`span`,{role:`status`,className:`text-small text-ink-2`,children:l})]}),e.mode===`lines`?(0,h.jsx)(LB,{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)(BB,{rows:6,value:e.lines,onChange:n=>t({...e,lines:n.target.value,rows:KK(n.target.value,e.base)}),placeholder:`Pyramids
270
270
  Sphinxes
271
271
  Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(LB,{id:`schedule-topics-yaml`,label:`Topics as YAML or JSON`,tip:`planning.schedule.topic-yaml`,children:(0,h.jsx)(BB,{rows:10,className:`font-mono`,spellCheck:!1,value:e.yaml,onChange:n=>t({...e,yaml:n.target.value}),placeholder:`- ${f??`Topic`}: Cleopatra\n ${d.find(e=>e!==f)??`Min. Word Count`}: 12000\n- Hypatia`})}):(0,h.jsx)(Vfe,{queue:e,onQueue:t,keyword:f,addable:O,setRow:D,titleOf:b}),k.length===0?null:(0,h.jsx)(aI,{tone:`danger`,title:`These topics can't be saved yet.`,children:(0,h.jsxs)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:[k.slice(0,8).map(e=>(0,h.jsx)(`li`,{children:e},e)),k.length>8?(0,h.jsx)(`li`,{children:`And ${String(k.length-8)} more.`}):null]})}),e.mode===`yaml`&&v.rows.length>0?(0,h.jsxs)(`section`,{"aria-label":`Project titles`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-1 text-small text-ink-2`,children:`Project titles, in order:`}),(0,h.jsxs)(`ol`,{className:`m-0 flex flex-col gap-1 pl-5 text-small`,children:[v.rows.slice(0,20).map((e,t)=>(0,h.jsx)(`li`,{children:b(e)},t)),v.rows.length>20?(0,h.jsx)(`li`,{className:`list-none text-ink-3`,children:`And ${String(v.rows.length-20)} more.`}):null]})]}):null,a?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Reading the template's keywords…`}):d.length===0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`This template has no keywords such as `,`{{Topic}}`,`, so each topic becomes the project's title.`]}):(0,h.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,h.jsx)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:(0,h.jsx)(LB,{label:`Each topic fills`,id:`schedule-topic-keyword`,tip:`planning.schedule.topic-keyword`,...f===null?{}:{help:B1({feeds:_(f)})},children:(0,h.jsx)(VB,{value:f??``,onChange:e=>r(e.target.value),children:d.map(e=>(0,h.jsx)(`option`,{value:e,children:`{{${e}}}`},e))})})}),(0,h.jsx)(V1,{keywords:d.filter(e=>e!==f).map(t=>({name:t,value:g[t]??``,feeds:_(t),...e.columns.includes(t)?{note:`Unless a topic sets its own.`}:{}})),onChange:i,fieldPrefix:`everyRun`,label:e=>`${e} (every run)`,inputLabel:e=>`${e} for every run`,tip:`planning.schedule.every-run`,maxLength:1e4})]}),e.mode===`lines`&&S!==void 0&&x!==void 0?(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Next project: `,(0,h.jsx)(`span`,{className:`font-semibold text-ink`,children:S}),f===null||C?null:(0,h.jsxs)(`span`,{className:`block text-ink-3`,children:[`The template's project title does not use `,`{{${f}}}`,`, so every project gets this title. Edit the template's title to include it.`]})]}):null]})}function Vfe({queue:e,onQueue:t,keyword:n,addable:r,setRow:i,titleOf:a}){let o=n===null?`Title`:`{{${n}}}`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...zb,children:[(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table`,"aria-label":`Topics`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,children:`#`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[o,(0,h.jsx)(U,{id:`planning.schedule.topic-table`,className:`-my-1`})]})}),e.columns.map(n=>(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`{{${n}}}`,(0,h.jsx)(Py,{label:`Use the every-run ${n} for all topics`,size:`small`,onClick:()=>t({...e,columns:e.columns.filter(e=>e!==n),rows:e.rows.map(e=>({title:e.title,values:Object.fromEntries(Object.entries(e.values).filter(([e])=>e!==n))}))}),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]})},n)),(0,h.jsx)(`th`,{scope:`col`,children:`Project title`}),(0,h.jsx)(`th`,{scope:`col`,children:(0,h.jsx)(`span`,{className:`sr-only`,children:`Remove`})})]})}),(0,h.jsx)(`tbody`,{children:e.rows.map((n,r)=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{className:`num`,children:r+1}),(0,h.jsx)(`td`,{children:(0,h.jsx)(zB,{"aria-label":`Topic ${String(r+1)} ${o}`,maxLength:200,value:n.title,onChange:e=>i(r,{...n,title:e.target.value})})}),e.columns.map(e=>(0,h.jsx)(`td`,{children:(0,h.jsx)(zB,{"aria-label":`Topic ${String(r+1)} ${e}`,maxLength:LK,placeholder:`Every-run value`,value:n.values[e]??``,onChange:t=>i(r,{...n,values:{...n.values,[e]:t.target.value}})})},e)),(0,h.jsx)(`td`,{className:`min-w-[180px] text-small text-ink-2`,children:a(n)??`—`}),(0,h.jsx)(`td`,{children:(0,h.jsx)(Py,{label:`Remove topic ${String(r+1)}`,size:`small`,onClick:()=>t({...e,rows:e.rows.filter((e,t)=>t!==r)}),children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})})]},r))})]})}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(B,{size:`small`,onClick:()=>t({...e,rows:[...e.rows,{title:``,values:{}}]}),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]}),r.length===0?null:(0,h.jsxs)(VB,{"aria-label":`Set a keyword per topic`,value:``,className:`w-auto`,onChange:n=>{let r=n.target.value;r!==``&&t({...e,columns:[...e.columns,r]})},children:[(0,h.jsx)(`option`,{value:``,children:`Set a keyword per topic…`}),r.map(e=>(0,h.jsx)(`option`,{value:e,children:e},e))]})]})]})}var Hfe=[[1,`Mon`],[2,`Tue`],[3,`Wed`],[4,`Thu`],[5,`Fri`],[6,`Sat`],[0,`Sun`]];function Ufe({templates:e,pending:t,onCreated:n,onError:r,editing:i,onCancel:a,error:o,onBusy:s}){let{api:c}=V(),[l,u]=(0,m.useState)(i?.name??``),[d,f]=(0,m.useState)(i?.templateId??``),[p,g]=(0,m.useState)(i?.cadence.kind??`daily`),[_,v]=(0,m.useState)(i?.cadence.kind===`once`?Zde(i.cadence.at,i.timezone):``),[y,b]=(0,m.useState)(i&&i.cadence.kind!==`once`?i.cadence.time:`09:00`),[x,S]=(0,m.useState)(i?.cadence.kind===`weekly`?i.cadence.days:[1,3,5]),[C,w]=(0,m.useState)(()=>i?.timezone??(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`)),[T,E]=(0,m.useState)(i?.missedPolicy??`skip`),[D,O]=(0,m.useState)(i?.spendLimitCents?.toString()??``),[k,A]=(0,m.useState)(()=>U1(i?.items??[])),[j,M]=(0,m.useState)(i?.topicKeyword??null),[ee,N]=(0,m.useState)(i?.values??{}),[P,F]=(0,m.useState)(i?.brief??``),[te,ne]=(0,m.useState)(i?.topicGeneration??OV),[re,ie]=(0,m.useState)((i?.releases??[]).length===0?null:i?.releases??null),[ae,oe]=(0,m.useState)(!1),[se,ce]=(0,m.useState)(!1),le=(0,m.useRef)(!1),ue=(0,m.useRef)(null),de=i&&!e.some(e=>e.id===i.templateId)?[...e,{id:i.templateId,version:i.templateVersion,name:`Saved template`}]:e,fe=de.find(e=>e.id===d),pe=I({queryKey:[`project-template`,d],enabled:d!==``,queryFn:async()=>{let e=await uq(c,d);if(!e.ok)throw Error(e.message);return e.value}}),me=pe.data?.document.form,he=me===void 0?void 0:F1({form:me,prompts:pe.data?.document.librarySnapshot?.prompts??[],entries:pe.data?.document.librarySnapshot?.entries??[]}),ge=me===void 0?[]:RK(me),_e=j!==null&&ge.includes(j)?j:ge.find(e=>me?.title.includes(`{{${e}}}`))??ge[0]??null,ve=Object.fromEntries(ge.filter(e=>e!==_e).map(e=>[e,ee[e]??me?.values[e]??``])),ye={keywords:ge,topicKeyword:_e,everyRun:ve,form:me,kept:i?.items??[],...he===void 0?{}:{origins:he}},be=K1(k,ye),xe=p===`weekly`?x:p===`daily`?[0,1,2,3,4,5,6]:[],Se=me!==void 0&&me.sources.audio!==`off`&&me.shorts?.enabled===!0?Math.max(0,Math.min(10,Number(me.shorts.count)||0)):0;async function Ce(e){if(e.preventDefault(),!(le.current||t)){if(!fe&&!ue.current){r(`Choose a template before saving the schedule.`);return}if(!ue.current&&be.problems.length>0){r(`Fix the topics first. ${be.problems.slice(0,3).join(` `)}`);return}if(be.rows.length>500){r(`Keep the list to 500 topics or fewer.`);return}if(P.trim().length>4e3){r(`Keep the series brief to ${String(EV)} characters or fewer.`);return}if(te.llm!==null&&(te.llm.provider===``||te.llm.model===``)){r(`Pick both a provider and a model for topic generation, or choose Use the template's LLM.`);return}if(p===`weekly`&&x.length===0){r(`Choose at least one weekday for a weekly schedule.`);return}le.current=!0,oe(!0),s(!0);try{if(!ue.current){if(!fe)throw Error(`Choose a template before saving the schedule.`);let e=C.trim();if(!vV(e))throw Error(`Enter a timezone name like Europe/Tirane or America/New_York.`);let t=p===`once`?{kind:p,at:Qde(_,e)}:p===`weekly`?{kind:p,time:y,days:x}:{kind:p,time:y},n=D.trim()===``?null:Number(D);if(n!==null&&(!Number.isInteger(n)||n<0))throw Error(`Enter the spend limit as a whole number of cents, 0 or more (500 is $5.00), or leave it empty.`);let r={id:i?.id??crypto.randomUUID(),name:l.trim(),templateId:fe.id,templateVersion:fe.version,cadence:t,timezone:e,missedPolicy:T,overlapPolicy:`skip`,spendLimitCents:n,items:be.rows,topicKeyword:_e,values:ve,brief:P.trim()===``?null:P.trim(),topicGeneration:te,releases:re===null||p===`once`?[]:R1(re,xe,Se)};ue.current=i?{...r,baseVersion:i.version,mutationId:crypto.randomUUID()}:r}let e=ue.current,{id:t,...a}=e,o=`mutationId`in a?await XV(c,t,a):await YV(c,e);if(!o.ok){ue.current=null,ce(!1),r(o.reason===`conflict`?`${o.message} Your inputs are kept here. To load the latest saved version, cancel editing and press Edit again.`:o.message);return}ue.current=null,ce(!1),u(``),A(U1([])),n()}catch(e){ce(ue.current!==null),r(e instanceof Error?e.message:`The schedule wasn't saved. Try again.`)}finally{le.current=!1,oe(!1),s(ue.current!==null)}}}return(0,h.jsxs)(`section`,{"aria-label":i?`Edit schedule`:`New schedule`,children:[o?(0,h.jsx)(aI,{tone:`danger`,title:`The schedule wasn't saved.`,className:`mb-4`,children:o}):null,(0,h.jsxs)(`form`,{onSubmit:e=>void Ce(e),children:[(0,h.jsxs)(`fieldset`,{disabled:ae||se||t,className:`m-0 grid min-w-0 gap-4 border-0 p-0 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Name`,id:`schedule-name`,tip:`planning.schedule.name`,children:(0,h.jsx)(zB,{required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`Monday morning stories`})}),(0,h.jsx)(LB,{label:`Template`,id:`schedule-template`,tip:`planning.schedule.template`,children:(0,h.jsxs)(VB,{required:!0,value:d,onChange:e=>f(e.target.value),disabled:de.length===0,children:[(0,h.jsx)(`option`,{value:``,children:`Choose a template`}),de.map(e=>(0,h.jsxs)(`option`,{value:e.id,children:[e.name,` · v`,e.version]},e.id))]})}),(0,h.jsx)(LB,{label:`Cadence`,id:`schedule-cadence`,tip:`planning.schedule.cadence`,children:(0,h.jsxs)(VB,{value:p,onChange:e=>g(e.target.value===`once`?`once`:e.target.value===`weekly`?`weekly`:`daily`),children:[(0,h.jsx)(`option`,{value:`daily`,children:`Every day`}),(0,h.jsx)(`option`,{value:`weekly`,children:`Selected weekdays`}),(0,h.jsx)(`option`,{value:`once`,children:`One time`})]})}),p===`once`?(0,h.jsx)(LB,{label:`Run at`,id:`schedule-once`,tip:`planning.schedule.once-at`,children:(0,h.jsx)(zB,{required:!0,type:`datetime-local`,value:_,onChange:e=>v(e.target.value)})}):(0,h.jsx)(LB,{label:`Local time`,id:`schedule-time`,tip:`planning.schedule.time`,children:(0,h.jsx)(zB,{required:!0,type:`time`,value:y,onChange:e=>b(e.target.value)})}),p===`weekly`?(0,h.jsxs)(`fieldset`,{className:`m-0 min-w-0 border-0 p-0`,...zb,children:[(0,h.jsxs)(`legend`,{className:`sl-field__label mb-2 flex items-center gap-1`,children:[`Weekdays`,(0,h.jsx)(U,{id:`planning.schedule.weekdays`,className:`-my-1`})]}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:Hfe.map(([e,t])=>(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),onChange:t=>S(n=>t.target.checked?[...n,e]:n.filter(t=>t!==e))}),t]},e))})]}):(0,h.jsx)(`div`,{}),(0,h.jsx)(LB,{label:`Timezone`,id:`schedule-timezone`,tip:p===`once`?`planning.schedule.timezone-once`:`planning.schedule.timezone`,children:(0,h.jsx)(zB,{value:C,onChange:e=>w(e.target.value),placeholder:`Europe/Tirane`})}),(0,h.jsx)(LB,{label:`Missed run`,id:`schedule-missed`,tip:`planning.schedule.missed`,children:(0,h.jsxs)(VB,{value:T,onChange:e=>E(e.target.value===`run-once`?`run-once`:`skip`),children:[(0,h.jsx)(`option`,{value:`skip`,children:`Skip if Slopify was closed`}),(0,h.jsx)(`option`,{value:`run-once`,children:`Run once when Slopify reopens`})]})}),(0,h.jsx)(LB,{label:`Spend ceiling (cents, optional)`,id:`schedule-spend`,tip:`planning.schedule.spend`,tipLabel:`Spend ceiling`,children:(0,h.jsx)(zB,{inputMode:`numeric`,value:D,onChange:e=>O(e.target.value),placeholder:`1000`})}),(0,h.jsx)(Bfe,{queue:k,onQueue:A,context:ye,onKeyword:M,onValue:(e,t)=>N(n=>({...n,[e]:t})),loading:d!==``&&pe.isPending,exportName:l}),(0,h.jsx)(Rfe,{releases:re,onReleases:ie,runDays:xe,shorts:Se,once:p===`once`,timezone:C}),(0,h.jsx)(Wfe,{brief:P,onBrief:F,generation:te,onGeneration:ne,templateLlm:me?.llm})]}),(0,h.jsxs)(`div`,{className:`sticky bottom-0 z-10 mt-6 flex flex-wrap gap-2 border-t border-line bg-ground py-3 max-md:bottom-[68px]`,children:[(0,h.jsx)(B,{type:`submit`,variant:`primary`,disabled:t||ae||de.length===0&&!se,children:ae?`Saving…`:se?`Retry save`:i?`Save changes`:`Save schedule`}),(0,h.jsx)(B,{variant:`quiet`,disabled:ae||se,onClick:a,children:i?`Cancel editing`:`Cancel`})]})]})]})}function Wfe({brief:e,onBrief:t,generation:n,onGeneration:r,templateLlm:i}){let{api:a}=V(),o=I({...db(a),enabled:n.mode!==`off`}),s=n.llm;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex min-w-0 flex-col gap-3 border-0 border-t border-line p-0 pt-5 min-[700px]:col-span-2`,children:[(0,h.jsxs)(`legend`,{className:`float-left mb-1 flex w-full items-center gap-1 text-title-3 font-semibold`,children:[`Topic generation`,(0,h.jsx)(U,{id:`planning.schedule.generation`})]}),(0,h.jsx)(LB,{label:`Series brief (optional)`,id:`schedule-brief`,tip:`planning.schedule.brief`,tipLabel:`Series brief`,children:(0,h.jsx)(BB,{rows:3,maxLength:EV,value:e,onChange:e=>t(e.target.value),placeholder:`Ancient history, documentary style. Famous rulers and places first.`})}),(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`New topics`,id:`schedule-generation`,tip:`planning.schedule.new-topics`,children:(0,h.jsxs)(VB,{value:n.mode,onChange:e=>{let t=e.target.value;r({...n,mode:t===`queue`||t===`hold`?t:`off`})},children:[(0,h.jsx)(`option`,{value:`off`,children:`Off: add topics yourself`}),(0,h.jsx)(`option`,{value:`queue`,children:`Generate and queue directly`}),(0,h.jsx)(`option`,{value:`hold`,children:`Generate and hold for approval`})]})}),n.mode===`off`?null:(0,h.jsx)(LB,{label:`Keep at least this many queued`,id:`schedule-keep`,tip:`planning.schedule.keep-count`,children:(0,h.jsx)(zB,{type:`number`,min:1,max:100,value:String(n.keepAtLeast),onChange:e=>{let t=Math.round(Number(e.target.value));r({...n,keepAtLeast:Number.isFinite(t)?Math.min(100,Math.max(1,t)):1})}})})]}),n.mode===`off`?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:s===null,onChange:e=>r({...n,llm:e.target.checked?null:{provider:i?.provider??``,model:i?.model??``}})}),`Use the template's LLM`,s===null&&i!==void 0&&i.provider!==``?` (${i.provider} · ${i.model})`:``]}),(0,h.jsx)(U,{id:`planning.schedule.generation-llm`,className:`-my-1`})]}),s===null?null:(0,h.jsxs)(`div`,{className:`grid gap-4 min-[700px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Provider`,family:`llm`,providers:o.data?.providers??[],value:s.provider,problem:o.error?.message,onPick:e=>r({...n,llm:{provider:e,model:``}})}),(0,h.jsx)(tV,{label:`Model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>r({...n,llm:{...s,model:e}})})]})]})]})}function Gfe({schedule:e}){let{api:t}=V(),n=_(),r=Ry(),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(!1),c=(0,m.useRef)(!1),[l,u]=(0,m.useState)(``),d=(0,m.useRef)(e);e.version>d.current.version&&(d.current=e);let f=d.current.items,p=e.topicKeyword===null?`title`:`{{${e.topicKeyword}}}`,g=async(e,i,o)=>{if(c.current)return!1;c.current=!0;let l=d.current;s(!0),a(null);try{let s=await uH(t,l.id,{baseVersion:l.version,items:e});return s.ok?(d.current=s.value,n.setQueryData(KV,e=>e?.map(e=>e.id===s.value.id?s.value:e)),n.invalidateQueries({queryKey:fH}),r(i,`success`,o?{label:`Undo`,run:()=>void g(l.items,`Put the topics back as they were.`,!1)}:void 0),!0):(a(s.reason===`conflict`?`The topics weren't saved: this schedule changed since the page loaded, possibly because a run just took a topic. The list now shows the latest; make your change again.`:`The topics weren't saved: ${s.message}`),await n.invalidateQueries({queryKey:KV}),!1)}catch(e){return a(`The topics weren't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then try again.`),!1}finally{c.current=!1,s(!1)}},v=async e=>{e.preventDefault();let t=l.trim();if(t===``){a(`Write the new topic's ${p} first, then press Add topic.`);return}await g([...f,{title:t,values:{}}],`Added “${t}”.`,!0)&&u(``)},y=(e,t)=>{let n=f[e];if(n!==void 0&&t.trim()!==n.title){if(t.trim()===``){a(`Topic ${String(e+1)} needs a ${p}. Write one, or press its Remove button.`);return}g(f.map((n,r)=>r===e?{...n,title:t.trim()}:n),`Renamed to “${t.trim()}”.`,!0)}},b=(e,t)=>{let n=f[e];if(n===void 0)return;let r=[...f];r.splice(e,1),r.splice(e+t,0,n),g(r,`Moved “${n.title}” ${t===-1?`up`:`down`}.`,!0)},x=e=>{let t=f[e];t!==void 0&&g(f.filter((t,n)=>n!==e),`Removed “${t.title}”.`,!0)};return(0,h.jsxs)(`section`,{"aria-label":`Queued topics`,className:`mt-6`,...zb,children:[(0,h.jsx)(W,{as:`h3`,title:`Queued topics · ${String(f.length)}`,info:`planning.schedule.inline-topics`,meta:e.topicKeyword===null?`Each topic becomes the next project's title.`:`Each topic fills ${p}; the next run takes the first.`}),i===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:i}),f.length===0?null:(0,h.jsx)(PH,{label:`Topics of ${e.name}`,className:`mt-2`,children:f.map((e,t)=>(0,h.jsx)(Kfe,{index:t,title:e.title,count:f.length,busy:o,onRename:e=>y(t,e),onMove:e=>b(t,e),onRemove:()=>x(t)},`${String(t)}:${e.title}`))}),(0,h.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-center gap-2`,onSubmit:e=>void v(e),children:[(0,h.jsx)(zB,{"aria-label":`New topic`,placeholder:e.topicKeyword===null?`New topic`:`New ${p}`,maxLength:200,value:l,className:`min-w-0 flex-1`,onChange:e=>u(e.target.value)}),(0,h.jsxs)(B,{type:`submit`,size:`small`,disabled:o||f.length>=500,disabledReason:o?`Saving the last change`:`A queue holds at most 500 topics`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add topic`]})]})]})}function Kfe({index:e,title:t,count:n,busy:r,onRename:i,onMove:a,onRemove:o}){let[s,c]=(0,m.useState)(t);(0,m.useEffect)(()=>c(t),[t]);let l=`Topic ${String(e+1)}`;return(0,h.jsx)(FH,{lead:(0,h.jsx)(`span`,{className:`w-6 text-small text-ink-3 tabular-nums`,children:e+1}),title:(0,h.jsx)(zB,{"aria-label":l,maxLength:200,value:s,onChange:e=>c(e.target.value),onBlur:()=>i(s),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i(s)):e.key===`Escape`&&c(t)}}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Py,{size:`small`,label:`Move ${t} up`,disabled:r||e===0,onClick:()=>a(-1),children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{size:`small`,label:`Move ${t} down`,disabled:r||e===n-1,onClick:()=>a(1),children:(0,h.jsx)(mc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{size:`small`,label:`Remove ${t}`,disabled:r,onClick:o,children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})]})})}function qfe({pickedId:e,onPick:t}={}){let{api:n}=V(),r=_(),i=I(qV(n)),a=I(lq(n)),[o,s]=(0,m.useState)(null),c=Ry(),[l,u]=(0,m.useState)(null),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),[v,y]=(0,m.useState)(null),b=t===void 0?v:e??null,x=e=>{t===void 0?y(e):t(e)},[S,C]=(0,m.useState)(null),w=(0,m.useRef)(!1),T=I(cx(n)),[E]=(0,m.useState)(()=>{let e=new Date;return{from:e.toISOString(),to:new Date(e.valueOf()+79488e5).toISOString()}}),D=I(pH(n,E.from,E.to)),O=new Map;for(let e of D.data?.runs??[])e.renderedTitle!==null&&!O.has(e.scheduleId)&&O.set(e.scheduleId,e.renderedTitle);let[k,A]=(0,m.useState)(``),j=e=>{if(k===``)return!0;let t=a.data?.find(t=>t.id===e.templateId);return(t?E1(t):tx)===k},M=i.data?.filter(e=>e.deletedAt===null&&j(e))??[],ee=i.data?.filter(e=>e.deletedAt!==null)??[],N=i.data?.find(e=>e.id===b)??M[0]??null,P=L({onError:e=>s(e.message),onSettled:async()=>{w.current=!1,await r.invalidateQueries({queryKey:KV})},mutationFn:async e=>e(),onSuccess:async e=>{if(!e.ok){s(e.message);return}s(null)}}),F=e=>{w.current||(w.current=!0,s(null),P.mutate(e))},te=d||l!==null,ne=()=>{u(null),f(!1),s(null)},re=a.data?.length===0,ie=()=>{te||re||(u(null),f(!0),s(null))},ae=e=>{f(!1),x(e.id),u(e),s(null)};jx({id:`schedules.new`,title:`New schedule`,group:`Schedules`,keywords:[`calendar`,`recurring`],run:ie}),oS(tS.newSchedule,()=>{re?c(`A schedule runs a project template, and there is none yet. Open a project, choose Save as template, then run New schedule again.`,`error`):ie()},a.data!==void 0);let oe=o?{tone:`error`,text:o}:i.error?{tone:`error`,text:`The schedules couldn't be loaded: ${i.error.message} Reload the page to try again.`}:a.error?{tone:`error`,text:`The templates couldn't be loaded: ${a.error.message} Reload the page to try again.`}:void 0,se=P.isPending||p||te;return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 min-w-0 text-small text-ink-2`,children:re?(0,h.jsxs)(h.Fragment,{children:[`Save a template in`,` `,(0,h.jsx)(fa,{className:`underline`,to:`/templates`,children:`Library → Templates`}),` `,`before creating a schedule.`]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Runs a saved template on this machine at a local time.`,(0,h.jsx)(U,{id:`planning.schedules`})]})}),(0,h.jsxs)(Iy,{children:[(0,h.jsxs)(VB,{"aria-label":`Filter schedules by channel`,value:k,className:`w-auto min-w-[160px]`,onChange:e=>A(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`All channels`}),(T.data??[]).map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,h.jsxs)(B,{variant:`primary`,onClick:ie,disabled:te||re,disabledReason:re?`Save a template in Library → Templates first`:`Finish or cancel the open form first`,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New schedule`]})]})]}),(0,h.jsx)(v1,{tone:te?`info`:oe?.tone??`info`,className:`mb-2`,children:te?void 0:oe?.text}),(0,h.jsx)(QK,{className:`min-[768px]:grid-cols-[minmax(320px,460px)_minmax(0,1fr)]`,list:(0,h.jsxs)(h.Fragment,{children:[i.data&&M.length===0?(0,h.jsx)(T1,{title:k===``?ee.length===0?`No schedules yet`:`No active schedules`:`No schedules run this channel's templates`,children:k===``?ee.length===0?`Your first one can be a one-off run or a recurring series. Press New schedule.`:`Create one with New schedule, or review deleted history below.`:`Pick All channels to see the others, or make one from this channel's templates.`}):null,M.length>0?(0,h.jsx)(PH,{label:`Saved schedules`,className:`[&_.sl-row__actions]:flex-wrap`,children:M.map(e=>(0,h.jsxs)(m.Fragment,{children:[(0,h.jsx)(J1,{schedule:e,nextTitle:O.get(e.id),selected:!te&&N?.id===e.id,pending:se,onSelect:()=>x(e.id),onEdit:()=>ae(e),onAction:F,onConfirm:t=>C({kind:t,schedule:e})}),(0,h.jsx)(O1,{kind:`schedule`,id:e.id,name:e.name})]},e.id))}):null,ee.length>0?(0,h.jsxs)(`details`,{className:`mt-6`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-small font-semibold text-ink-2`,children:[`Deleted schedules · `,ee.length]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 mb-2 text-small text-ink-2`,children:`Deleted schedules stay in Settings → Trash for 30 days, where Restore brings one back paused. Pick one to see its run history.`}),(0,h.jsx)(PH,{label:`Deleted schedules`,children:ee.map(e=>(0,h.jsx)(J1,{schedule:e,nextTitle:void 0,selected:!te&&N?.id===e.id,pending:!1,onSelect:()=>x(e.id),onEdit:()=>void 0,onAction:F,onConfirm:()=>void 0},e.id))})]}):null]}),detail:te?(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{kicker:l?l.name:void 0,title:l?`Edit schedule`:`New schedule`,className:`mb-4`}),(0,h.jsx)(Ufe,{onBusy:g,editing:l,onCancel:()=>{p||ne()},templates:a.data??[],pending:P.isPending,error:o,onCreated:()=>{c(l?`Schedule updated.`:`Schedule saved. It will run automatically while Slopify is open.`,`success`),ne(),r.invalidateQueries({queryKey:KV})},onError:e=>{s(e),r.invalidateQueries({queryKey:KV})}},l?.id??`new`)]}):N?(0,h.jsx)(Zfe,{schedule:N,pending:se,onAction:F,onConfirm:e=>C({kind:e,schedule:N})},N.id):null}),(0,h.jsx)(Hy,{open:S!==null,title:S?.kind===`delete`?`Delete schedule?`:`Cancel schedule?`,consequence:(S?.kind===`delete`?`Moves this schedule to the trash for 30 days (Settings → Trash). Its run history is kept.`:`Stops future scheduled runs. Existing projects and run history are kept.`)+(o?` ${o}`:``),confirmLabel:S?.kind===`delete`?`Delete schedule`:`Cancel schedule`,cancelLabel:`Keep schedule`,pending:P.isPending,onCancel:()=>{P.isPending||C(null)},onConfirm:()=>{if(!S)return;let{kind:e,schedule:t}=S;F(async()=>{let r=e===`delete`?await QV(n,t.id,t.version):await ZV(n,t.id,`cancel`,t.version);return r.ok&&C(null),r})}})]})}function Jfe(e){return e.cadence.kind===`once`?`One time`:e.cadence.kind===`daily`?`Daily at ${e.cadence.time}`:`Weekly at ${e.cadence.time}`}var Yfe={active:`Active`,paused:`Paused`,completed:`Completed`,canceled:`Canceled`},Xfe={active:`running`,paused:`waiting`,completed:`done`,canceled:`off`};function q1({schedule:e}){return e.deletedAt===null?(0,h.jsx)(OS,{tone:Xfe[e.status],children:Yfe[e.status]}):(0,h.jsx)(OS,{tone:`off`,children:`Deleted`})}function J1({schedule:e,nextTitle:t,selected:n,pending:r,onSelect:i,onEdit:a,onAction:o,onConfirm:s}){let{api:c}=V(),l=e.deletedAt===null,u=l&&(e.status===`active`||e.status===`paused`),d=e.status===`canceled`||e.status===`completed`;return(0,h.jsx)(FH,{selected:n,onSelect:i,title:e.name,meta:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(q1,{schedule:e}),` · ${Jfe(e)} · ${e.deletedAt===null?e.nextRunAt===null?`No future run`:`Next: ${a1(e.nextRunAt,e.timezone)}${t===void 0?``:` · “${t}”`}`:`Deleted: ${a1(e.deletedAt,e.timezone)}`}${e.topics.held>0?` · ${String(e.topics.held)} waiting for you`:``}`]}),actions:l?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Edit ${e.name}`,disabled:r||!u,disabledReason:u?`Finish or cancel the open form first`:`Only a live schedule can change`,onClick:a,children:`Edit`}),e.status===`paused`?(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Resume ${e.name}`,disabled:r,onClick:()=>o(()=>ZV(c,e.id,`resume`,e.version)),children:`Resume`}):(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Pause ${e.name}`,disabled:r||e.status!==`active`,disabledReason:`Only an active schedule can pause`,onClick:()=>o(()=>ZV(c,e.id,`pause`,e.version)),children:`Pause`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,disabled:r||!d,disabledReason:`Cancel the schedule first; a completed or canceled one can be deleted`,onClick:()=>s(`delete`),children:`Delete`})]}):void 0})}function Zfe({schedule:e,pending:t,onAction:n,onConfirm:r}){let{api:i}=V(),a=I({queryKey:[`schedule`,e.id],queryFn:async()=>{let t=await JV(i,e.id);if(!t.ok)throw Error(t.message);return t.value},refetchInterval:3e4}),o=e.deletedAt===null,s=o&&(e.status===`active`||e.status===`paused`),c=e.status===`paused`,l=[[`When`,e.cadence.kind===`once`?`Once, ${a1(e.cadence.at,e.timezone)}`:e.cadence.kind===`daily`?`Every day at ${e.cadence.time}`:`Selected weekdays at ${e.cadence.time}`],[`Timezone`,e.timezone],[`Next run`,e.deletedAt!==null||e.nextRunAt===null?`None`:a1(e.nextRunAt,e.timezone)],[`Topics`,e.items.length===0?e.topicGeneration.mode===`off`?`Template as saved`:`No topics queued`:`${String(e.items.length)} ${e.items.length===1?`topic`:`topics`} left`],[`Missed runs`,e.missedPolicy===`skip`?`Skip`:`Run once on reopening`],[`Overlap`,`Skip`],[`Spend ceiling`,e.spendLimitCents===null?`Not set`:`${String(e.spendLimitCents)} cents`]];return(0,h.jsxs)(`section`,{"aria-label":`${e.name} detail`,children:[o&&s?(0,h.jsx)(Qfe,{schedule:e,paused:c,onAction:n}):null,(0,h.jsx)(W,{kicker:(0,h.jsx)(q1,{schedule:e}),title:e.name,meta:e.topics.held>0?`${String(e.topics.held)} topics waiting for you`:void 0,children:o?(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Cancel ${e.name}`,disabled:t||!s,disabledReason:`Only an active or paused schedule can be canceled`,onClick:()=>r(`cancel`),children:`Cancel schedule`}):null}),(0,h.jsx)(`dl`,{className:`m-0 mt-4 grid grid-cols-1 gap-x-6 gap-y-3 text-small min-[600px]:grid-cols-2`,children:l.map(([e,t])=>(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`dt`,{className:`sl-kicker`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 break-words text-ink`,children:t})]},e))}),s?(0,h.jsx)(Gfe,{schedule:e}):null,(0,h.jsx)(yfe,{schedule:e}),(0,h.jsx)($K,{className:`my-6`}),(0,h.jsx)(W,{as:`h3`,title:`Run history`}),(0,h.jsx)(`div`,{className:`mt-3`,children:a.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading history…`}):a.error?(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The run history couldn't be loaded: ${a.error.message} It tries again every 30 seconds.`}):a.data.runs.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`No runs yet.`}):(0,h.jsx)(PH,{label:`Runs of ${e.name}`,children:a.data.runs.map(t=>(0,h.jsx)(FH,{title:(0,h.jsx)(`span`,{className:`capitalize`,children:`${t.status} · ${a1(t.scheduledFor,e.timezone)}`}),meta:t.error?t.error:t.projectIds.length>0?(0,h.jsx)(`span`,{className:`inline-flex flex-wrap gap-x-3`,children:t.projectIds.map((e,t)=>(0,h.jsxs)(fa,{className:`underline hover:text-ink`,to:`/projects/$projectId`,params:{projectId:e},children:[`Project `,t+1]},e))}):`No projects`},t.id))})})]})}function Qfe({schedule:e,paused:t,onAction:n}){let{api:r}=V();return jx({id:`schedules.pause-resume`,title:t?`Resume schedule`:`Pause schedule`,group:`Schedules`,context:e.name,run:()=>n(()=>ZV(r,e.id,t?`resume`:`pause`,e.version))}),null}var Y1=`https://www.youtube.com/upload`,$fe=[`video`,`title`,`description`,`thumbnails`,`playlist`,`audience`,`altered`,`tags`,`schedule`];function epe(e){return e.join(`, `)}var tpe=[.75,1,1.25,1.5,1.75,2];function X1(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0,n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}function Z1(e){return`${String(e)}×`}function npe(e,t){return e.filter(e=>e.start<=t).at(-1)}function Q1(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}var $1=(e,t,n)=>Math.min(n,Math.max(t,e));function e0(){let e=(0,m.useRef)(null),t=(0,m.useId)(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(0),[o,s]=(0,m.useState)(0),[c,l]=(0,m.useState)(0),[u,d]=(0,m.useState)(1),[f,p]=(0,m.useState)(!1),[h,g]=(0,m.useState)(1),[_,v]=(0,m.useState)(!1),[y,b]=(0,m.useState)(null),[x,S]=(0,m.useState)(!1),C=Number.isFinite(o)&&o>0,w=()=>{let t=e.current;t!==null&&(t.paused||t.ended?t.play()?.catch(()=>void 0):t.pause())},T=t=>{let n=e.current;if(n===null||!C)return;let r=$1(t,0,o);n.currentTime=r,a(r)},E=t=>T((e.current?.currentTime??i)+t),D=t=>{let n=e.current;if(n===null)return;let r=$1(Math.round(t*100)/100,0,1);n.volume=r,n.muted=r===0,d(r),p(r===0)},O=()=>{let t=e.current;t!==null&&(t.muted=!t.muted,p(t.muted))};return{media:e,menuId:t,playing:n,current:i,duration:o,buffered:c,known:C,volume:u,muted:f,rate:h,menu:_,setMenu:v,hover:y,setHover:b,seeking:x,setSeeking:S,toggle:w,seekTo:T,jump:E,setLevel:D,toggleMute:O,pickRate:n=>{let r=e.current;r!==null&&(r.playbackRate=n),g(n),v(!1),document.getElementById(`${t}-button`)?.focus()},keyAction:e=>{let t=e.length===1?e.toLowerCase():e;if(t===` `||t===`k`)return w;if(t===`j`)return()=>E(-10);if(t===`l`)return()=>E(10);if(t===`ArrowLeft`)return()=>E(-5);if(t===`ArrowRight`)return()=>E(5);if(t===`m`)return O;if(/^[0-9]$/.test(t))return()=>T(Number(t)/10*o)},events:{onPlay:()=>r(!0),onPause:()=>r(!1),onEnded:()=>r(!1),onTimeUpdate:e=>{x||a(e.currentTarget.currentTime)},onDurationChange:e=>s(e.currentTarget.duration),onLoadedMetadata:e=>s(e.currentTarget.duration),onProgress:e=>{let t=e.currentTarget.buffered;l(t.length>0?t.end(t.length-1):0)},onVolumeChange:e=>{d(e.currentTarget.volume),p(e.currentTarget.muted)},onRateChange:e=>g(e.currentTarget.playbackRate)}}}function t0(e,t){let n=e?.getBoundingClientRect();return n===void 0||n.width===0?0:$1((t-n.left)/n.width,0,1)}function n0(e,t){t!==void 0&&(e.preventDefault(),e.stopPropagation(),t())}function r0({controls:e,className:t}){return(0,h.jsx)(Py,{size:`small`,label:e.playing?`Pause`:`Play`,className:t,onClick:e.toggle,children:e.playing?(0,h.jsx)(Hc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})})}function i0({controls:e}){return(0,h.jsxs)(`span`,{className:`sl-player__time`,children:[(0,h.jsx)(`span`,{className:`sl-player__now`,children:X1(e.current)}),(0,h.jsx)(`span`,{className:`sl-player__total`,children:` / ${e.known?X1(e.duration):`-:--`}`})]})}function a0({controls:e,chapters:t=[],waveform:n}){let r=(0,m.useRef)(null),{known:i,duration:a,current:o,buffered:s,seeking:c,hover:l}=e,u=ape(r),d=n===void 0?void 0:ipe(n,u),f=i?t.filter(e=>e.start>0&&e.start<a):[],p=t=>{i&&(t.currentTarget.setPointerCapture?.(t.pointerId),e.setSeeking(!0),e.seekTo(t0(r.current,t.clientX)*a))},g=t=>{let n=t0(r.current,t.clientX);e.setHover(n),c&&e.seekTo(n*a)},_=t=>{t.currentTarget.releasePointerCapture?.(t.pointerId),e.setSeeking(!1)},v=t=>{n0(t,{ArrowLeft:()=>e.jump(-5),ArrowDown:()=>e.jump(-5),ArrowRight:()=>e.jump(5),ArrowUp:()=>e.jump(5),PageDown:()=>e.jump(-10),PageUp:()=>e.jump(10),Home:()=>e.seekTo(0),End:()=>e.seekTo(a)}[t.key])},y=i?o/a*100:0,b=i?s/a*100:0,x=l===null||!i?void 0:l*a,S=x===void 0?void 0:npe(t,x);return(0,h.jsxs)(`div`,{ref:r,role:`slider`,tabIndex:0,"aria-label":`Seek`,"aria-valuemin":0,"aria-valuemax":i?Math.floor(a):0,"aria-valuenow":Math.floor(o),"aria-valuetext":`${X1(o)} of ${i?X1(a):`unknown length`}`,"aria-disabled":!i,className:`sl-player__track`,onPointerDown:p,onPointerMove:g,onPointerUp:_,onPointerCancel:_,onPointerLeave:()=>e.setHover(null),onKeyDown:v,children:[d===void 0||d.length===0?(0,h.jsxs)(`span`,{className:`sl-player__rail`,children:[(0,h.jsx)(`span`,{className:`sl-player__buffered`,style:{width:`${String(b)}%`}}),(0,h.jsx)(`span`,{className:`sl-player__played`,style:{width:`${String(y)}%`}})]}):(0,h.jsx)(`span`,{className:`sl-player__wave`,"data-slot":`waveform`,"aria-hidden":`true`,children:d.map((e,t)=>(0,h.jsx)(`span`,{className:`sl-player__peak`,"data-played":(t+.5)/d.length*100<=y?``:void 0,style:{height:`${String(Math.max(12,Math.round(e*100)))}%`}},t))}),f.map(e=>(0,h.jsx)(`span`,{className:`sl-player__mark`,"data-chapter":e.title,title:e.title,style:{left:`${String(e.start/a*100)}%`}},`${String(e.start)}-${e.title}`)),(0,h.jsx)(`span`,{className:`sl-player__knob`,style:{left:`${String(y)}%`}}),x===void 0||l===null?null:(0,h.jsxs)(`span`,{className:`sl-player__tip`,"aria-hidden":`true`,style:{left:`${String(l*100)}%`},children:[S===void 0?null:(0,h.jsx)(`span`,{className:`sl-player__tip-title`,children:S.title}),X1(x)]})]})}function o0({controls:e}){let t=(0,m.useRef)(null),{muted:n,volume:r}=e,i=n?0:r;return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Py,{size:`small`,label:n?`Unmute`:`Mute`,"aria-pressed":n,className:`sl-player__mute`,onClick:e.toggleMute,children:n||r===0?(0,h.jsx)(il,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(rl,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(`div`,{ref:t,role:`slider`,tabIndex:0,"aria-label":`Volume`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(i*100),"aria-valuetext":n?`Muted`:`${String(Math.round(i*100))}%`,className:`sl-player__volume`,onPointerDown:n=>{n.currentTarget.setPointerCapture?.(n.pointerId),e.setLevel(t0(t.current,n.clientX))},onPointerMove:n=>{n.buttons===1&&e.setLevel(t0(t.current,n.clientX))},onKeyDown:t=>{let n={ArrowLeft:i-.05,ArrowDown:i-.05,ArrowRight:i+.05,ArrowUp:i+.05,Home:0,End:1}[t.key];n0(t,n===void 0?void 0:()=>e.setLevel(n))},children:(0,h.jsx)(`span`,{className:`sl-player__rail`,children:(0,h.jsx)(`span`,{className:`sl-player__played`,style:{width:`${String(i*100)}%`}})})})]})}function s0({controls:e}){let{menuId:t,menu:n,rate:r}=e;return(0,h.jsxs)(`span`,{className:`sl-player__speed`,children:[(0,h.jsx)(B,{id:`${t}-button`,variant:`quiet`,size:`small`,className:`sl-player__rate`,"aria-label":`Playback speed, ${Z1(r)}`,"aria-haspopup":`menu`,"aria-expanded":n,"aria-controls":n?`${t}-menu`:void 0,onClick:()=>e.setMenu(e=>!e),children:Z1(r)}),n?(0,h.jsx)(`div`,{id:`${t}-menu`,role:`menu`,"aria-label":`Playback speed`,className:`sl-player__menu`,onKeyDown:n=>{if(n.key===`Escape`){n0(n,()=>{e.setMenu(!1),document.getElementById(`${t}-button`)?.focus()});return}if(n.key!==`ArrowDown`&&n.key!==`ArrowUp`)return;let r=[...n.currentTarget.querySelectorAll(`[role=menuitemradio]`)],i=r[(r.indexOf(document.activeElement)+(n.key===`ArrowDown`?1:-1)+r.length)%r.length];n0(n,()=>i?.focus())},children:tpe.map(t=>(0,h.jsx)(B,{variant:`quiet`,size:`small`,role:`menuitemradio`,"aria-checked":t===r,className:z(`sl-player__option`),autoFocus:t===r,onClick:()=>e.pickRate(t),children:t===1?`Normal`:Z1(t)},t))}):null]})}var rpe=4;function ipe(e,t){let n=Math.floor(t/rpe);if(n<=0||e.length<=n)return e;let r=[];for(let t=0;t<n;t+=1){let i=Math.floor(t*e.length/n),a=Math.max(i+1,Math.floor((t+1)*e.length/n));r.push(Math.max(...e.slice(i,a)))}return r}function ape(e){let[t,n]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let t=e.current;if(t===null||(n(t.clientWidth),typeof ResizeObserver>`u`))return;let r=new ResizeObserver(()=>n(t.clientWidth));return r.observe(t),()=>r.disconnect()},[e]),t}var ope=2500;function c0({src:e,poster:t,label:n,portrait:r=!1,square:i=!1,captions:a,chapters:o=[],ref:s,className:c,children:l}){let u=e0(),d=u.media,f=(0,m.useRef)(null),p=(0,m.useRef)(void 0),[g,_]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(0),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(!1),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(!0),{playing:A,menu:j,seeking:M,hover:ee,events:N}=u,P=a!==void 0||b>0,F=typeof document<`u`&&`pictureInPictureEnabled`in document&&document.pictureInPictureEnabled===!0,te=(0,m.useCallback)(()=>{k(!0),clearTimeout(p.current),p.current=setTimeout(()=>k(!1),ope)},[]);(0,m.useEffect)(()=>()=>clearTimeout(p.current),[]);let ne=A&&!O&&!j&&!E&&!M&&ee===null;(0,m.useEffect)(()=>{let e=()=>C(document.fullscreenElement===f.current);return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]),(0,m.useEffect)(()=>{let e=d.current;if(e===null)return;let t=()=>T(!0),n=()=>T(!1);return e.addEventListener(`enterpictureinpicture`,t),e.addEventListener(`leavepictureinpicture`,n),()=>{e.removeEventListener(`enterpictureinpicture`,t),e.removeEventListener(`leavepictureinpicture`,n)}},[d]),(0,m.useEffect)(()=>{let e=d.current?.textTracks;if(e!==void 0)for(let t=0;t<e.length;t+=1){let n=e[t];n!==void 0&&(n.mode=v&&t===0?`showing`:`hidden`)}},[v,d]);let re=()=>{let e=d.current;e!==null&&(e.paused||e.ended)&&_(!0),u.toggle()},ie=()=>{let e=f.current;e!==null&&(document.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()?.catch(()=>void 0))},ae=()=>{let e=d.current;e!==null&&(document.pictureInPictureElement===e?document.exitPictureInPicture?.().catch(()=>void 0):e.requestPictureInPicture?.().catch(()=>void 0))};return(0,h.jsxs)(`div`,{ref:f,"data-slot":`player`,"data-state":A?`playing`:`paused`,className:z(`sl-player`,r&&`sl-player--portrait`,i&&`sl-player--square`,ne&&`sl-player--bare`,S&&`sl-player--full`,c),onKeyDown:e=>{if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target.closest(`button`)!==null,n=e.key.length===1?e.key.toLowerCase():e.key,r=n===` `&&t?void 0:n===` `||n===`k`?re:n===`f`?ie:n===`c`?P?()=>y(e=>!e):void 0:u.keyAction(n);r!==void 0&&(e.preventDefault(),e.stopPropagation(),te(),r())},onPointerMove:te,onPointerDown:te,onFocus:()=>D(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(D(!1),u.setMenu(!1))},children:[(0,h.jsxs)(`video`,{ref:Q1(d,s),src:e,poster:t,preload:`metadata`,playsInline:!0,"aria-label":n,onClick:re,...N,onPlay:e=>{N.onPlay(e),_(!0),te()},onPause:e=>{N.onPause(e),k(!0)},onEnded:e=>{N.onEnded(e),k(!0)},onLoadedMetadata:e=>{N.onLoadedMetadata(e),x(e.currentTarget.textTracks?.length??0)},children:[a===void 0?null:(0,h.jsx)(`track`,{kind:`captions`,src:a.src,srcLang:a.lang,label:a.label}),l]}),g?null:(0,h.jsx)(Py,{label:`Play ${n}`,className:`sl-player__big`,onClick:re,children:(0,h.jsx)(Gc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsxs)(`div`,{className:`sl-player__bar`,role:`group`,"aria-label":`${n} controls`,children:[(0,h.jsx)(r0,{controls:{...u,toggle:re}}),(0,h.jsx)(i0,{controls:u}),(0,h.jsx)(a0,{controls:u,chapters:o}),(0,h.jsx)(o0,{controls:u}),(0,h.jsx)(s0,{controls:u}),P?(0,h.jsx)(Py,{size:`small`,label:`Captions`,"aria-pressed":v,onClick:()=>y(e=>!e),children:(0,h.jsx)(xc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,F?(0,h.jsx)(Py,{size:`small`,label:`Picture in picture`,"aria-pressed":w,className:`sl-player__pip`,onClick:ae,children:(0,h.jsx)(Wc,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Py,{size:`small`,label:S?`Exit full screen`:`Full screen`,"aria-pressed":S,onClick:ie,children:S?(0,h.jsx)(Vc,{"aria-hidden":`true`,strokeWidth:1.75}):(0,h.jsx)(Bc,{"aria-hidden":`true`,strokeWidth:1.75})})]})]})}var spe={landscape:void 0,portrait:`sl-media__frame--portrait`,square:`sl-media__frame--square`};function l0({src:e,alt:t,kind:n=`image`,poster:r,aspect:i=`landscape`,title:a,meta:o,badge:s,actions:c,actionsShown:l=!1,generating:u,onOpen:d,openLabel:f,className:p}){let m=u==null||u===!1;return(0,h.jsxs)(`figure`,{className:z(`sl-media m-0`,p),"data-slot":`media-frame`,children:[(0,h.jsxs)(`div`,{className:z(`sl-media__frame`,spe[i]),children:[m&&e!==void 0?n===`video`?(0,h.jsx)(`video`,{src:e,poster:r,muted:!0,preload:`metadata`,"aria-label":t}):(0,h.jsx)(`img`,{src:e,alt:t,loading:`lazy`,decoding:`async`}):null,m?null:(0,h.jsxs)(`div`,{className:`sl-media__generating`,role:`status`,children:[(0,h.jsx)(DS,{tone:`running`}),(0,h.jsx)(`span`,{children:u})]}),s===void 0?null:(0,h.jsx)(`span`,{className:`sl-media__badge`,children:s}),c===void 0?null:(0,h.jsx)(`div`,{className:z(`sl-media__actions`,l&&`sl-media__actions--shown`),children:c})]}),d!==void 0&&m&&e!==void 0?(0,h.jsx)(`button`,{type:`button`,className:`sl-media__open`,"aria-label":f??`Open ${t} full size`,onClick:d}):null,a===void 0&&o===void 0?null:(0,h.jsxs)(`figcaption`,{className:`sl-media__caption`,children:[a===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`strong`,{className:`min-w-0 truncate`,children:a}),o===void 0?null:(0,h.jsx)(`span`,{className:`shrink-0`,children:o})]})]})}function u0({shorts:e=!1,density:t=`default`,list:n=!1,className:r,children:i,label:a}){let o=z(`sl-grid`,e&&`sl-grid--shorts`,t===`compact`&&`sl-grid--compact`,n&&`m-0 list-none p-0`,r);return n?(0,h.jsx)(`ul`,{"aria-label":a,className:o,"data-slot":`media-grid`,children:i}):(0,h.jsx)(`section`,{"aria-label":a,className:o,"data-slot":`media-grid`,children:i})}function d0({items:e,index:t,onIndex:n,onClose:r,actions:i}){let a=t===null?void 0:e[t],o=e.length,s=e=>{t!==null&&o!==0&&n((t+e+o)%o)};return(0,h.jsx)(Nm,{open:a!==void 0,onOpenChange:e=>{e||r()},children:(0,h.jsx)(Lm,{children:(0,h.jsx)(Um,{className:`sl-lightbox sl-enter`,onKeyDown:e=>{e.key===`ArrowRight`?(e.preventDefault(),s(1)):e.key===`ArrowLeft`&&(e.preventDefault(),s(-1))},"aria-describedby":void 0,children:a===void 0||t===null?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`sl-lightbox__bar`,children:[(0,h.jsx)(Km,{className:`m-0 text-small font-semibold`,children:`${String(t+1)} of ${String(o)} · ${a.alt}`}),(0,h.jsxs)(`div`,{className:`sl-btn-row`,children:[i?.(a,t),(0,h.jsx)(Py,{label:`Previous`,onClick:()=>s(-1),disabled:o<2,children:(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{label:`Next`,onClick:()=>s(1),disabled:o<2,children:(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Xm,{asChild:!0,children:(0,h.jsx)(Py,{label:`Close`,children:(0,h.jsx)(al,{"aria-hidden":`true`,strokeWidth:1.75})})})]})]}),(0,h.jsx)(`div`,{className:`sl-lightbox__stage`,children:a.kind===`video`?(0,h.jsx)(c0,{src:a.src,label:a.alt,className:`sl-lightbox__player`,...a.poster===void 0?{}:{poster:a.poster}},a.src):(0,h.jsx)(`img`,{src:a.src,alt:a.alt},a.src)}),a.caption===void 0?(0,h.jsx)(`span`,{}):(0,h.jsx)(`p`,{className:`sl-lightbox__caption`,children:a.caption})]})})})})}var f0={location:oO(`docker-host`),path:K().min(1)},p0=JD([Y({opened:oO(!0)}).strict(),Y({opened:oO(!0),...f0}).strict(),Y({opened:oO(!1),...f0}).strict()]),m0=XD(`kind`,[Y({kind:oO(`allAffected`)}).strict(),Y({kind:oO(`selected`),workKeys:J(K().min(1).max(200)).min(1).max(1e4)}).strict()]),h0=K().min(1).max(64),cpe=Y({baseRevisionId:h0,request:m0}).strict(),lpe=Y({baseRevisionId:h0,idempotencyKey:_D(),previewId:K().min(1).max(64),acknowledgeUnknownCosts:RD(),confirmedProvidedWorkKeys:J(K().min(1).max(200)).max(1e4)}).strict(),upe=Y({stage:K(),low:q().finite().nonnegative().nullable(),high:q().finite().nonnegative().nullable(),detail:K(),onPlan:RD().optional(),apiLow:q().finite().nonnegative().nullable().optional(),apiHigh:q().finite().nonnegative().nullable().optional()}),dpe=Y({currency:oO(`USD`),rows:J(upe),low:q().finite().nonnegative(),high:q().finite().nonnegative(),unknown:q().int().nonnegative(),apiLow:q().finite().nonnegative().optional(),apiHigh:q().finite().nonnegative().optional(),apiUnknown:q().int().nonnegative().optional(),expectedWords:q().finite().nonnegative(),catalogueDate:K().nullable(),assumptions:J(K())}),g0=Y({revisionId:h0,admissionId:K().min(1).max(64),workIds:J(K().min(1).max(64)),replayed:RD()}),fpe=Y({id:K().min(1).max(64),projectId:K().min(1).max(64),baseRevisionId:h0,planFingerprint:K().min(1),selection:m0,changedInputs:J(Y({path:K(),before:K().nullable(),after:K().nullable()})),work:J(Y({key:K(),stage:X(KS),kind:X([`provider`,`local`,`provided`]),disposition:X([`reuse`,`generate`,`local`,`review`,`blocked`]),requestFingerprint:K(),fingerprint:K(),dependsOn:J(K()),reason:K(),inflight:RD(),pieceIds:J(K())})),retained:J(Y({slot:K(),outputId:K(),assetId:K(),state:X([`ready`,`outdated`,`review`])})),providedReuseRequired:J(K()),costs:dpe,wholeRequestNotice:K().nullable(),warnings:J(K()),review:Y({inputChanges:J(Y({label:K(),before:K().nullable(),after:K().nullable()})),requests:J(Y({key:K(),label:K(),text:K().nullable(),settings:K().nullable()}))}).optional()}),_0=[`chapter`,`chunk`,`segment`,`image`,`prompt_written`,`article_written`],v0=[`pending`,`running`,`done`,`failed`];Y({id:K(),stage_id:K(),kind:X(_0),idx:q(),state:X(v0),payload:K().nullable()});var ppe=`notes.article_md.article_txt.narration_txt.tts_script.sources.glossary.audio_body.audio_intro.audio_outro.audio_export.image.thumbnail.video.render_params.subtitles_srt.subtitles_vtt.subtitle_words.subtitle_ass.subtitle_font.instructions.document_pdf.youtube_description.youtube_tags.youtube_pinned_comment.youtube_titles.shorts.short_image.short_video.animated_image.figure_card.reference.script_md.audio_mp3.audio_m4b.audio_levelled`.split(`.`),mpe=[`copying`,`staged`],hpe=Y({segment:X([`body`,`intro`,`outro`]).optional(),subtitleOmissions:J(Y({start:q().finite().nonnegative(),text:K()})).optional(),subtitlesMode:X([`off`,`files`,`burn-in`]).optional(),promptName:K().optional(),prompt:K().optional(),index:q().optional(),short:q().optional(),format:X([`16:9`,`9:16`,`1:1`]).optional(),sentences:eO([q(),q()]).optional(),warnings:J(K()).optional(),provider:K().optional(),model:K().optional(),voice:K().optional(),loudness:Y({pieces:q(),skipped:q(),spreadBefore:q(),spreadAfter:q(),target:q()}).optional(),master:Y({target:q(),integrated:q(),truePeak:q()}).optional()}),gpe=Y({id:K(),projectId:K(),stageKind:X(KS),role:X(ppe),path:K(),originalFilename:K().nullable(),bytes:q().nonnegative(),durationMs:q().nonnegative().nullable(),meta:hpe,createdAt:K()});Y({id:K(),stageKind:X(KS),path:K(),originalFilename:K(),bytes:q().nonnegative(),state:X(mpe),createdAt:K()});var y0=K().min(1).max(64).regex(/^[0-9A-Za-z_-]+$/),b0=K().min(1).max(256),_pe=nO(b0,y0),vpe=Y({id:y0,text:K().trim().min(1).max(1e4),start:q().finite().nonnegative(),end:q().finite().positive(),speaker:K().min(1).max(60).regex(/^[a-z0-9-]+$/).optional()}).strict().refine(e=>e.end>e.start,{path:[`end`],message:`The end time must be after the start time.`}),x0=Y({articleMarkdown:K().max(5e5).optional(),articleEdited:RD().default(!1),provided:Y({research:y0.optional(),article:y0.optional(),audio:y0.optional(),thumbnail:y0.optional(),reference:y0.optional()}).strict(),imageOrder:J(y0).max(240),imageDefinitions:nO(y0,Y({source:X([`generate`,`provide`]),assetId:y0.nullable(),prompt:K().max(5e5).nullable(),templateKey:K().min(1).max(256).nullable().optional()}).strict()),narrationOverrides:nO(b0,XD(`kind`,[Y({kind:oO(`asset`),assetId:y0}).strict(),Y({kind:oO(`text`),text:K().trim().min(1).max(5e5),direction:K().trim().min(1).max(2e4).optional()}).strict()])),narrationSources:nO(b0,Y({text:K().min(1).max(5e5),start:q().int().nonnegative().max(5e5),bodyFingerprint:K().regex(/^[0-9a-f]{64}$/u),chunkingFingerprint:K().regex(/^[0-9a-f]{64}$/u)}).strict()).refine(e=>Object.keys(e).length<=1e4&&Object.values(e).reduce((e,t)=>e+t.text.length,0)<=5e5,`Narration source bindings exceed the article limit.`).optional(),subtitleCues:Y({audioFingerprint:K().min(1),cues:J(vpe)}).strict().optional(),regenerationTokens:_pe,promptTemplates:nO(K().min(1),K().max(5e5).nullable()),shortsMusic:y0.optional(),shortsRanges:nO(K().regex(/^[1-9]\d?$/u),Y({first:q().int().positive(),last:q().int().positive(),pick:K().min(1).max(128)}).strict()).optional(),ambientBed:y0.optional()}).strict(),ype=Y({baseRevisionId:y0,idempotencyKey:y0,edit:Y({config:mM.strict(),content:x0,regenerate:J(b0).optional(),uploads:J(Y({stagedFileId:y0,destination:XD(`kind`,[Y({kind:oO(`provided`),stage:X([`audio`,`thumbnail`,`reference`])}).strict(),Y({kind:oO(`image`),imageKey:y0}).strict(),Y({kind:oO(`narration`),key:b0}).strict(),Y({kind:oO(`shortsMusic`)}).strict()])}).strict()).max(1e4).optional()}).strict()}).strict(),bpe=Y({baseRevisionId:y0,idempotencyKey:y0,targetRevisionId:y0}).strict(),xpe=Y({id:y0,projectId:y0,parentId:y0.nullable(),restoredFromId:y0.nullable(),config:mM,content:x0,fingerprints:nO(b0,K()),createdAt:K()}),Spe=Y({id:y0,stageId:y0,kind:X(_0),idx:q().int(),state:X(v0),payload:K().nullable()}),Cpe=Y({slot:K(),workKey:b0,assetId:y0,output:gpe,fingerprint:K(),state:X([`ready`,`outdated`,`review`])}),wpe=Y({key:b0,stageKind:X(KS),piece:Spe,assetId:y0.nullable(),fingerprint:K()}),S0={recordId:y0,publicationId:y0.nullable(),selected:RD(),available:RD()},C0=Y({articleMarkdown:K().nullable(),revision:xpe,outputs:J(Cpe.extend(S0)),pieces:J(wpe.extend(S0)),current:RD()}),Tpe=Y({id:y0,parentId:y0.nullable(),restoredFromId:y0.nullable(),title:K(),createdAt:K(),current:RD()}),w0=Y({ok:oO(!0),view:C0,duplicate:RD()}),Epe=Y({ok:oO(!0),view:C0,created:RD()}),Dpe=Y({title:K(),status:q(),detail:K().optional(),reason:K().optional(),currentRevisionId:K().nullable().optional(),fields:J(Y({field:K(),message:K()})).optional(),errors:J(Y({path:K(),message:K()})).optional()});async function T0(e,t){let n;try{n=await e.json()}catch{throw lo(e,void 0)}if(e.ok)return{ok:!0,value:yo(t,n)};let r=Dpe.safeParse(n);if(!r.success)throw lo(e,void 0);let i=r.data;if(![400,404,409].includes(e.status))throw lo(e,{title:i.title,status:i.status,...i.detail===void 0?{}:{detail:i.detail},...i.fields===void 0?{}:{fields:i.fields}});return{ok:!1,reason:i.reason??`invalid-request`,message:i.detail??i.title,currentRevisionId:i.currentRevisionId??null,fields:i.fields??i.errors?.map(e=>({field:e.path,message:e.message}))??[]}}async function E0(e,t,n,r,i){return T0(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}${n}`,i===void 0?{method:`GET`}:{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}),r)}function D0(e,t){return E0(e,t,`/revisions/prepare`,Epe,{})}function O0(e,t,n){return E0(e,t,`/revisions`,w0,ype.parse(n))}function Ope(e,t,n){return E0(e,t,`/revisions/restore`,w0,bpe.parse(n))}function kpe(e,t){return E0(e,t,`/revisions`,Y({revisions:J(Tpe)}))}function k0(e,t,n){return E0(e,t,`/revisions/${encodeURIComponent(n)}`,Y({view:C0}))}var A0=J(K()).readonly();function Ape(e,t,n){return E0(e,t,`/revisions/${encodeURIComponent(n)}/narration-chunks`,Y({chunks:Y({intro:A0.optional(),body:A0.optional(),outro:A0.optional()}).nullable()}))}function jpe(e,t,n){return E0(e,t,`/rebuild/preview`,Y({ok:oO(!0),value:fpe}),cpe.parse(n))}function Mpe(e,t,n){return E0(e,t,`/rebuild`,Y({ok:oO(!0),value:g0}),lpe.parse(n))}function j0(e,t,n,r){return`${e.origin}/files/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}`}async function Npe(e,t,n,r){let i=await T0(await e.fetch(`${e.origin}/api/projects/${encodeURIComponent(t)}/revisions/${encodeURIComponent(n)}/${encodeURIComponent(r)}/open-folder`,{method:`POST`}),p0);if(!i.ok)throw Error(i.message);return i.value}function Ppe(e,t,n){return j0(e,t,n,`images.zip`)}async function M0(e,{projectId:t,asset:n,folder:r=null}){if(r)return Npe(e,t,r.revisionId,r.recordId);let i=await e.client.projects[`:id`][`open-folder`].$post({param:{id:t},json:{asset:n}});if(!i.ok)throw lo(i,await uo(i));return p0.parse(await i.json())}var N0=`Slopify runs in Docker, which can't open windows on your desktop. Copy this path into your file manager. To have Open folder open it directly, run the Docker launcher again (npx @gentbajko/slopify@latest --docker) so it sets up the host helper.`;function P0(e){return(0,h.jsx)(Fpe,{...e},JSON.stringify([e.projectId,e.asset,e.folder?.revisionId,e.folder?.recordId]))}function Fpe(e){let{api:t}=V(),[n,r]=(0,m.useState)(!1),[i,a]=(0,m.useState)(),[o,s]=(0,m.useState)();async function c(){r(!0),a(void 0),s(void 0);try{let n=await M0(t,e);n.opened||s(n.path)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Press Open folder to try again.`)}finally{r(!1)}}return(0,h.jsxs)(Nb,{open:o!==void 0||i!==void 0,onOpenChange:e=>{e||(s(void 0),a(void 0))},children:[(0,h.jsx)(Fb,{asChild:!0,children:(0,h.jsxs)(B,{variant:`secondary`,size:e.size??`default`,disabled:n,onClick:()=>void c(),title:`Locate the saved output folder on the machine running Slopify`,children:[(0,h.jsx)(Pc,{"aria-hidden":`true`,strokeWidth:1.75}),n?`Locating…`:o?`Locate folder`:`Open folder`]})}),(0,h.jsxs)(Lb,{className:`flex flex-col gap-2`,children:[o===void 0?null:(0,h.jsxs)(`div`,{role:`status`,className:`flex min-w-0 flex-col gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:N0}),(0,h.jsx)(`input`,{"aria-label":`Saved folder path`,readOnly:!0,value:o,onFocus:e=>e.currentTarget.select(),className:`sl-input w-full min-w-0 font-mono text-small`})]}),i===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i})]})]})}var Ipe={chrome:`Chrome, Edge, Brave`,firefox:`Firefox`};function Lpe(){return typeof navigator<`u`&&/firefox/i.test(navigator.userAgent)?`firefox`:`chrome`}function F0(){let{api:e}=V(),[t,n]=(0,m.useState)(Lpe),r=`slopify-studio-${t}.zip`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(Vb,{label:`Browser`,value:t,onChange:n,tip:`settings.studio.install`,options:[`chrome`,`firefox`].map(e=>({value:e,label:Ipe[e]}))}),(0,h.jsxs)(TS,{href:_s(e,t),download:r,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download for ${t===`chrome`?`Chrome`:`Firefox`}`]})]}),(0,h.jsxs)(`ol`,{"aria-label":`Install steps`,className:`m-0 flex list-decimal flex-col gap-1 pl-5`,children:[t===`chrome`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`li`,{children:[`Press Download for Chrome, then unzip `,(0,h.jsx)(HB,{children:r}),` into a folder you keep: the browser loads the extension from there.`]}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(HB,{children:`chrome://extensions`}),` (Edge: `,(0,h.jsx)(HB,{children:`edge://extensions`}),`), turn on Developer mode, press Load unpacked and pick that folder.`]})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`li`,{children:`Press Download for Firefox. It needs Firefox 128 or newer; keep the zip, you pick it in the next step.`}),(0,h.jsxs)(`li`,{children:[`Open `,(0,h.jsx)(HB,{children:`about:debugging#/runtime/this-firefox`}),`, press Load Temporary Add-on and pick `,(0,h.jsx)(HB,{children:r}),`. Firefox removes it when it restarts; load it again then.`]})]}),(0,h.jsx)(`li`,{children:`Pair it: press Copy beside the pairing token in Settings → YouTube Studio, click the Slopify extension's toolbar button, paste the token and press Pair.`})]})]})}var I0=[`studio`,`plan`];function Rpe({autoComment:e}){let{api:t}=V(),n=_(),r=Ry(),i=I({queryKey:I0,queryFn:()=>as(t)}),a=L({mutationFn:e=>os(t,{...e,rows:[]}),onSuccess:e=>{n.setQueryData(I0,e),n.invalidateQueries({queryKey:[`studio`,`releases`]}),r(`Removed the old posting plan. Each schedule's release times apply now.`,`success`)},onError:e=>r(`The old posting plan wasn't removed: ${e.message} Try Remove the old plan again.`,`error`)}),o=L({mutationFn:e=>ss(t,e),onSuccess:e=>{n.setQueryData(I0,e),n.invalidateQueries({queryKey:[`studio`,`releases`]}),r(`Each upload is now due ${String(e.leadHours)} hours before its release.`,`success`)},onError:e=>r(`The lead time wasn't saved: ${e.message}`,`error`)}),s=L({mutationFn:e=>fs(t,e),onSuccess:()=>n.invalidateQueries({queryKey:[`studio`,`settings`]}),onError:e=>r(`Not saved: ${e.message}`,`error`)});if(i.data===void 0)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the release settings…`});let c=i.data.plan;return(0,h.jsxs)(`section`,{"aria-label":`Release times`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{as:`h3`,title:`Release times`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Each schedule sets when its videos and shorts go out, one line for each day it runs, with a time for every short its template makes:`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`},children:`Calendar → Schedules`}),` `,`→ Edit → Release times. See and move them in Calendar → Releases.`]}),c.rows.length>0?(0,h.jsx)(aI,{tone:`info`,title:`An older posting plan still applies`,actions:(0,h.jsx)(B,{variant:`secondary`,disabled:a.isPending,onClick:()=>a.mutate(c),children:`Remove the old plan`}),children:(0,h.jsx)(`p`,{className:`m-0`,children:`It has ${String(c.rows.length)} line${c.rows.length===1?``:`s`}, and gives release times to projects no schedule made, and to a schedule's projects when its own times are taken. Set release times in your schedules, then remove it. Times already given keep.`})}):null,(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[`Upload and schedule each video and short at least`,(0,h.jsx)(zB,{"aria-label":`Hours before release`,type:`number`,min:1,max:168,className:`w-[72px]`,defaultValue:i.data?.leadHours??24,onBlur:e=>{let t=Number(e.currentTarget.value);Number.isInteger(t)&&t>=1&&t<=168&&t!==i.data?.leadHours&&o.mutate(t)}},i.data?.leadHours??24),`hours before its release, so YouTube's copyright and ad checks finish while it is private.`]}),(0,h.jsx)(Bb,{checked:e===!0,disabled:s.isPending||e===void 0,onChange:e=>s.mutate(e),label:`Post and pin each video's comment once it is public (the extension posts it in your name)`})]})}var L0=[`studio`,`settings`];function zpe(){let{api:e}=V(),t=I({queryKey:L0,queryFn:()=>ts(e)});return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(W,{title:`Upload pack and extension`,info:`settings.studio.extension`}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsx)(Bpe,{}),(0,h.jsx)(Rpe,{autoComment:t.data?.autoComment??!1}),(0,h.jsx)(Hpe,{}),(0,h.jsxs)(`section`,{"aria-label":`Install the Studio extension`,children:[(0,h.jsx)(W,{as:`h3`,title:`Install the Studio extension`,className:`mb-3`}),(0,h.jsx)(F0,{})]})]})]})}var R0=``;function Bpe(){let{api:e}=V(),t=_(),n=Ry(),r=(0,m.useId)(),i=I({queryKey:L0,queryFn:()=>ts(e)}),a=I(cx(e)),o=(0,m.useId)(),[s,c]=(0,m.useState)(R0),[l,u]=(0,m.useState)(void 0),d=i.data?.playlists??[],f=s===R0?void 0:i.data?.channelPlaylists[s],p=l??(s===R0?d:f??[]),g=Vpe(p),v=L({mutationFn:t=>ns(e,t,s===R0?void 0:s),onSuccess:()=>{u(void 0),t.invalidateQueries({queryKey:L0}),n(`Playlists saved.`,`success`)}}),y=e=>{v.reset(),u(e)},b=g??v.error?.message,x=[{value:R0,label:`Every channel (default)`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(LB,{label:`Playlists`,tip:`settings.studio.playlist`,help:s===R0?`The playlists upload packs offer, for every channel without its own. Ticked ones are on for every project; Prepare upload changes them for one project.`:f===void 0&&d.length>0?`This channel uses the default list (${(e=>e.map(e=>e.name).join(`, `))(d)}) until you add its own.`:`This channel's own playlists. Ticked ones are on for every project; Prepare upload changes them for one project.`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(VB,{id:o,"aria-label":`Channel`,value:s,options:x,onChange:e=>{v.reset(),u(void 0),c(e.currentTarget.value)},className:`max-w-[260px]`}),p.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(zB,{autoComplete:`off`,"aria-label":`Playlist ${String(t+1)} name`,placeholder:`The playlist's name in Studio`,className:`min-w-0 flex-1 basis-[220px]`,value:e.name,disabled:i.data===void 0,"aria-invalid":e.name.trim().length>150,"aria-describedby":b===void 0?void 0:r,onChange:e=>y(p.map((n,r)=>r===t?{...n,name:e.target.value}:n))}),(0,h.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.byDefault,onChange:e=>{let n=e.currentTarget.checked;y(p.map((e,r)=>r===t?{...e,byDefault:n}:e))}}),`On by default`]}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Remove ${e.name.trim()||`playlist ${String(t+1)}`}`,onClick:()=>y(p.filter((e,n)=>n!==t)),children:`Remove`})]},t)),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsxs)(B,{variant:`secondary`,disabled:i.data===void 0||p.length>=20,onClick:()=>y([...p,{name:``,byDefault:p.length===0}]),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add playlist`]}),(0,h.jsx)(B,{variant:`primary`,disabled:v.isPending||l===void 0||g!==void 0,onClick:()=>v.mutate(p),children:`Save playlists`})]})]}),b===void 0?null:(0,h.jsx)(`p`,{id:r,role:`alert`,className:`m-0 text-small text-danger`,children:b})]})}function Vpe(e){if(e.find(e=>e.name.trim().length>150)!==void 0)return`A playlist name is longer than YouTube allows (150 characters). Shorten it.`;let t=new Set;for(let n of e){let e=n.name.trim().toLowerCase();if(e!==``){if(t.has(e))return`"${n.name.trim()}" is listed twice. Remove one.`;t.add(e)}}}function Hpe(){let{api:e}=V(),t=_(),n=Ry(),r=I({queryKey:L0,queryFn:()=>ts(e)}),i=L({mutationFn:()=>bs(e),onSuccess:()=>{t.invalidateQueries({queryKey:L0}),n(`New pairing token made. Pair the extension again with it.`,`success`)}}),a=r.data?.pairing;return(0,h.jsxs)(`div`,{className:`sl-field`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,h.jsx)(`span`,{className:`sl-field__label`,children:`Extension pairing token`}),(0,h.jsx)(U,{id:`settings.studio.pairing`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`code`,{className:`sl-code min-w-0 flex-1 basis-[220px] truncate py-2 select-all`,children:a?.token??`…`}),(0,h.jsxs)(B,{variant:`quiet`,disabled:a===void 0,onClick:()=>{if(a!==void 0){if(!navigator.clipboard){n(`Couldn't copy the token. Select it and copy it.`,`error`);return}navigator.clipboard.writeText(a.token).then(()=>n(`Pairing token copied. Paste it into the extension's options.`,`success`),()=>n(`Couldn't copy the token. Select it and copy it.`,`error`))}},children:[(0,h.jsx)(kc,{"aria-hidden":`true`,className:`size-[14px] shrink-0`}),`Copy`]}),(0,h.jsx)(B,{variant:`quiet`,disabled:i.isPending||a===void 0,onClick:()=>i.mutate(),children:`New pairing token`})]}),(0,h.jsx)(`p`,{className:`sl-field__help m-0`,children:a?.origin==null?`No extension is paired. Paste this token into the Slopify Studio extension's options and press Pair.`:`Paired with the extension at ${a.origin}. A new token unpairs it.`}),i.error===null?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:i.error.message})]})}var z0=[`studio`,`queue`];function B0({projectId:e,ready:t,variant:n=`secondary`,size:r=`default`}){let[i,a]=(0,m.useState)(!1);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:n,size:r,disabled:!t,disabledReason:`Available once the video has been made`,onClick:()=>a(!0),children:`Prepare upload`}),i?(0,h.jsx)(W0,{projectId:e,onClose:()=>a(!1)}):null]})}var V0={video:`Video file`,title:`Title`,description:`Description`,thumbnails:`Thumbnail`,playlist:`Playlist`,audience:`Audience`,altered:`AI use (under Show more)`,tags:`Tags (under Show more)`,schedule:`Schedule (Visibility)`};function H0(e){return new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`}).format(new Date(e))}function U0(e){return e.kind===`video`?`video`:`short-${String(e.short)}`}function W0({projectId:e,onClose:t}){let{api:n}=V(),r=_(),i=[`studio`,`pack`,e],a=I({queryKey:i,queryFn:()=>xs(n,e)}),[o,s]=(0,m.useState)(`video`),[c,l]=(0,m.useState)(),u=a.data?.items??[],d=u.find(e=>U0(e)===o)??u[0],f=I({queryKey:L0,queryFn:()=>ts(n)}),p=f.data===void 0?void 0:f.data.pairing.origin!==null,g=I({queryKey:z0,queryFn:()=>vs(n)}),v=L({mutationFn:t=>Cs(n,e,t.short),onSuccess:e=>{r.setQueryData(z0,e),l({text:e.length>1?`Added; ${String(e.length)} uploads are waiting. Studio is opening: each upload you start there is filled with the next one, in the order under Waiting for Studio. Check everything and publish yourself.`:`Studio is opening. The Slopify Studio extension puts the video into its upload dialog and fills in the details. Check everything and publish yourself.`,tone:`success`})},onError:e=>l({text:`Couldn't hand this to the extension: ${e.message}`,tone:`error`})}),y=L({mutationFn:e=>ys(n,e.projectId,e.short),onSuccess:e=>r.setQueryData(z0,e),onError:e=>l({text:`Couldn't remove it from Waiting for Studio: ${e.message} Press Remove again.`,tone:`error`})}),b=L({mutationFn:t=>Ss(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved. The AI use answer is updated.`,tone:`success`})},onError:e=>l({text:`Couldn't save whether the clips are real footage: ${e.message} Press the switch again.`,tone:`error`})}),x=L({mutationFn:t=>rs(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved this project's playlists.`,tone:`success`})},onError:e=>l({text:`Couldn't save the playlists: ${e.message} Tick the playlist again.`,tone:`error`})}),S=L({mutationFn:t=>ps(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved when this project goes out.`,tone:`success`})},onError:e=>l({text:`Couldn't change the slot: ${e.message} Choose it again.`,tone:`error`})}),C=L({mutationFn:t=>is(n,e,t),onSuccess:e=>{r.setQueryData(i,e),l({text:`Saved what the upload uses.`,tone:`success`})},onError:e=>l({text:`Couldn't save the choice: ${e.message} Choose it again.`,tone:`error`})});return(0,h.jsxs)(HP,{open:!0,title:`Prepare upload`,onClose:t,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:c?.tone??`info`,children:c?.text}),p===!1?(0,h.jsx)(TS,{href:Y1,target:`_blank`,rel:`noopener noreferrer`,variant:`secondary`,children:`Open YouTube Studio`}):null,(0,h.jsx)(B,{variant:`primary`,disabled:d===void 0||v.isPending||p!==!0,disabledReason:p===!1?`Install and pair the Slopify Studio extension first (steps above)`:f.error===null?`Wait for the upload pack to load`:`Couldn't check whether the extension is paired: ${f.error.message} Close Prepare upload and open it again.`,onClick:()=>{d!==void 0&&(window.open(Y1,`_blank`,`noopener`),v.mutate(d))},children:`Fill in YouTube Studio`}),(0,h.jsx)(U,{id:`project.upload.fill-studio`})]}),children:[a.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The upload pack couldn't be read.`,children:`${a.error.message} Close Prepare upload and open it again.`}),a.data===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p===!1?(0,h.jsx)(aI,{tone:`waiting`,title:`The Slopify Studio extension isn't paired.`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0`,children:`Without it, the steps below are the upload pack: copy each into Studio's upload dialog. To have Studio filled in for you, install the extension:`}),(0,h.jsx)(F0,{})]})}):null,u.length>1?(0,h.jsx)(Vb,{label:`What to upload`,value:d===void 0?``:U0(d),onChange:s,tip:`project.upload.item`,options:u.map(e=>({value:U0(e),label:e.kind===`video`?`Video`:`Short ${String(e.short)}`})),className:`self-start`}):null,a.data.missing.length===0?null:(0,h.jsx)(aI,{tone:`waiting`,title:`Some of it isn't made yet.`,children:(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:a.data.missing.map(e=>(0,h.jsx)(`li`,{children:e},e))})}),d===void 0?null:(0,h.jsx)(Wpe,{projectId:e,item:d,footageSwitch:d.kind===`video`&&a.data.footage!==void 0?(0,h.jsx)(Bb,{checked:b.isPending?b.variables:a.data.footage.real,disabled:b.isPending,onChange:e=>b.mutate(e),tip:`project.upload.real-footage`,label:`The ${a.data.footage.clips===1?`uploaded clip is`:`${String(a.data.footage.clips)} uploaded clips are`} real footage (filmed, not made by AI)`}):void 0,playlistPicker:a.data.playlistChoices.length>1?(0,h.jsx)(`span`,{className:`flex flex-col gap-1`,children:a.data.playlistChoices.map(e=>(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-[var(--color-accent)]`,checked:e.chosen,disabled:x.isPending,onChange:t=>{let n=t.currentTarget.checked;x.mutate(a.data.playlistChoices.filter(t=>t.name===e.name?n:t.chosen).map(e=>e.name))}}),e.name]},e.name))}):void 0,copy:(e,t)=>{if(!navigator.clipboard){l({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`});return}navigator.clipboard.writeText(e).then(()=>l({text:`Copied the ${t}.`,tone:`success`}),()=>l({text:`Couldn't copy the ${t}. Select the text and copy it.`,tone:`error`}))},onPick:e=>C.mutate(e),slotPicker:d.kind===`video`?(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,...zb,children:[(0,h.jsx)(VB,{"aria-label":`Posting plan slot`,value:a.data.schedule===void 0?``:`${a.data.schedule.row}|${a.data.schedule.longAt}`,disabled:S.isPending,onChange:e=>{let[t,n]=e.currentTarget.value.split(`|`);S.mutate(t===void 0||n===void 0?null:{row:t,longAt:n})},options:[{value:``,label:`Not scheduled (set it in Studio yourself)`},...a.data.schedule===void 0?[]:[{value:`${a.data.schedule.row}|${a.data.schedule.longAt}`,label:H0(a.data.schedule.longAt)}],...(a.data.slotChoices??[]).map(e=>({value:`${e.row}|${e.longAt}`,label:H0(e.longAt)}))]}),(0,h.jsx)(U,{id:`project.upload.slot`})]}):void 0,picking:C.isPending,doneKey:`slopify.upload.${e}.${U0(d)}`},U0(d)),(g.data??[]).length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Waiting for Studio`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:`Waiting for Studio`}),(0,h.jsx)(U,{id:`project.upload.queue`,className:`-my-1`})]}),(0,h.jsx)(PH,{label:`Waiting to be filled`,children:(g.data??[]).map((e,t)=>{let n=e.short===null?`Video`:`Short ${String(e.short)}`;return(0,h.jsx)(FH,{title:`${e.projectTitle} · ${n}`,meta:t===0?`Next: filled in the next upload dialog you open in Studio.`:`Filled after ${String(t)} more upload${t===1?``:`s`}.`,actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:y.isPending,"aria-label":`Remove ${e.projectTitle} ${n.toLowerCase()} from Waiting for Studio`,onClick:()=>y.mutate(e),children:`Remove`})},`${e.projectId}-${String(e.short)}`)})})]}),(0,h.jsx)(aI,{title:`Slopify never publishes.`,children:p===!1?`Copy each step into Studio's upload dialog (Open YouTube Studio), check it and press Publish yourself.`:`Fill in YouTube Studio hands this to the Slopify Studio extension, which puts the video into Studio's upload dialog and fills in the details. You check it and press Publish.`})]})]})}function Upe(e){try{let t=JSON.parse(localStorage.getItem(e)??`[]`);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function G0({href:e,filename:t}){return(0,h.jsxs)(TS,{href:e,download:t,"aria-label":`Download ${t}`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Ac,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Download`]})}function Wpe({projectId:e,item:t,footageSwitch:n,playlistPicker:r,copy:i,onPick:a,picking:o,slotPicker:s,doneKey:c}){let{api:l}=V(),[u,d]=(0,m.useState)(()=>Upe(c)),[f,p]=(0,m.useState)(null),g=e=>{d(e);try{localStorage.setItem(c,JSON.stringify(e))}catch{}},_=(e,t)=>g(t?[...u,e]:u.filter(t=>t!==e)),v=$fe.filter(e=>e!==`thumbnails`||t.kind===`video`),y=v.filter(e=>u.includes(e)).length,b=e=>{let n=q0(t,e);return(0,h.jsxs)(B,{variant:`quiet`,size:`small`,disabled:n===``,disabledReason:`Nothing to copy yet`,"aria-label":`Copy ${V0[e].toLowerCase()}`,onClick:()=>i(n,V0[e].toLowerCase()),children:[(0,h.jsx)(kc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy`]})},x=c=>{switch(c){case`video`:return t.video===null?{value:(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not made yet.`})}:{value:t.video.filename,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(G0,{href:`${l.origin}${t.video.url}`,filename:t.video.filename}),(0,h.jsx)(P0,{projectId:e,asset:t.video.asset,size:`small`})]})};case`thumbnails`:return t.thumbnails.length===0?{value:(0,h.jsx)(`span`,{className:`text-ink-3`,children:`None made.`})}:{value:t.thumbnails.length>1?`${K0(t.pickable?.thumbnail??0)} under Thumbnail (choose below). The A/B test tries all ${String(t.thumbnails.length)} once the video is public.`:t.thumbnails[0]?.filename??``,actions:(0,h.jsx)(P0,{projectId:e,asset:t.thumbnails[0]?.asset??`thumbnail`,size:`small`})};case`audience`:return{value:`No, it's not made for kids`};case`altered`:return{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:t.alteredContent.altered?`Yes`:`No`}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:t.alteredContent.why}),n]})};case`description`:return{value:t.chapterNotice===void 0?q0(t,c)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}):(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{children:t.description}),(0,h.jsx)(`span`,{className:`text-waiting`,children:t.chapterNotice})]}),actions:b(c)};case`title`:return t.titles.length===0||t.pickable===void 0?{value:q0(t,c),actions:b(c)}:{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`span`,{role:`radiogroup`,"aria-label":`Title the upload uses`,className:`flex flex-col gap-1`,children:t.pickable.titles.map((n,r)=>(0,h.jsxs)(`label`,{className:`flex min-h-8 items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`radio`,name:`upload-title-${e}`,className:`size-4 accent-[var(--color-accent)]`,checked:r===t.pickable?.title,disabled:o,onChange:()=>a({title:r,thumbnail:t.pickable?.thumbnail??0})}),n]},n))}),(0,h.jsx)(`span`,{className:`text-ink-2`,children:`The upload uses the chosen title; the A/B test tries the others beside it once the video is public.`})]}),actions:(0,h.jsxs)(h.Fragment,{children:[b(c),(0,h.jsxs)(B,{variant:`quiet`,size:`small`,"aria-label":`Copy the other titles`,onClick:()=>i(t.titles.join(`
272
- `),`other titles`),children:[(0,h.jsx)(kc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy others`]})]})};case`schedule`:return{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[s,(0,h.jsx)(`span`,{className:`text-ink-2`,children:t.scheduleAt===void 0?`Not scheduled: Slopify has no slot for it. Set the date in Studio's Visibility step.`:`${H0(t.scheduleAt)}, your time. The extension types it into Studio's Visibility step; you press Schedule.`})]})};case`playlist`:return{value:r??(t.playlists.length>0?t.playlists.join(`, `):(0,h.jsx)(`span`,{className:`text-ink-3`,children:`None set (Settings → YouTube Studio).`})),actions:b(c)};default:return{value:q0(t,c)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}),actions:b(c)}}};return(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`In the order Studio asks`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:`In the order Studio asks`}),(0,h.jsx)(U,{id:`project.upload.steps`,className:`-my-1`}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsxs)(`label`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:y===v.length,ref:e=>{e!==null&&(e.indeterminate=y>0&&y<v.length)},onChange:e=>g(e.currentTarget.checked?[...v]:[]),className:`size-4 shrink-0 accent-[var(--color-accent)]`}),`Select all`]})]}),(0,h.jsx)(PH,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:v.map(e=>{let{value:t,actions:n}=x(e);return(0,h.jsx)(FH,{className:`items-start`,lead:(0,h.jsx)(`input`,{type:`checkbox`,checked:u.includes(e),onChange:t=>_(e,t.currentTarget.checked),className:`mt-1 size-4 shrink-0 self-start accent-[var(--color-accent)]`,"aria-label":`${V0[e]} done`}),title:V0[e],meta:(0,h.jsx)(`span`,{className:`line-clamp-4 whitespace-pre-wrap break-words text-ink`,children:t}),actions:n},e)})})]}),t.thumbnails.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Thumbnails`,children:[(0,h.jsx)(W,{as:`h3`,kicker:`Thumbnails · A/B Testing`,title:`${String(t.thumbnails.length)} ${t.thumbnails.length===1?`thumbnail`:`thumbnails`}`,className:`mb-3`}),(0,h.jsx)(u0,{label:`Thumbnails to upload`,density:`compact`,children:(t.pickable?.thumbnails??t.thumbnails).map((e,n)=>{let r=n===(t.pickable?.thumbnail??0);return(0,h.jsx)(l0,{src:`${l.origin}${e.url}`,alt:`Thumbnail ${K0(n)}`,title:r&&t.thumbnails.length>1?`${K0(n)} · upload`:K0(n),meta:e.filename,onOpen:()=>p(n),openLabel:`Open thumbnail ${K0(n)} full size`,actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[r||t.pickable===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:o,onClick:()=>a({title:t.pickable?.title??0,thumbnail:n}),children:`Use for upload`}),(0,h.jsx)(G0,{href:`${l.origin}${e.url}`,filename:e.filename})]})},e.asset)})}),(0,h.jsx)(d0,{items:(t.pickable?.thumbnails??t.thumbnails).map((e,t)=>({src:`${l.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,caption:e.filename})),index:f,onIndex:p,onClose:()=>p(null),actions:(e,n)=>{let r=(t.pickable?.thumbnails??t.thumbnails)[n];return r===void 0?null:(0,h.jsx)(G0,{href:`${l.origin}${r.url}`,filename:r.filename})}})]})]})}function K0(e){return String.fromCharCode(65+e)}function q0(e,t){switch(t){case`title`:return e.title;case`description`:return e.description;case`tags`:return epe(e.tags);case`playlist`:return e.playlists.join(`, `);default:return``}}var J0=[`studio`,`releases`],Y0=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),Gpe=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`}),X0=e=>`${Y0.format(new Date(e))}, ${Gpe.format(new Date(e))}`;function Kpe(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function qpe(e){switch(e.state){case`scheduled`:return e.checks===`ok`?{tone:`neutral`,word:`✓ Scheduled · checks clear`}:e.checks===null?{tone:`info`,word:`✓ Scheduled · checks pending`}:{tone:`failed`,word:`Scheduled · ${e.checks}`};case`filled`:return{tone:`waiting`,word:`Filled in Studio, not scheduled`};case`late`:return{tone:`failed`,word:`Late · upload now`};case`not-ready`:return{tone:`neutral`,word:`Not rendered yet`};default:return{tone:`waiting`,word:e.uploadBy===null?`No time`:`Upload by ${X0(e.uploadBy)}`}}}function Jpe(e,t){let n=new Date(e),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-(n.getDay()+6)%7),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(t.getDay()+6)%7),a=Math.round((r.getTime()-i.getTime())/6048e5);return{key:r.toISOString(),label:a<=0?`This week`:a===1?`Next week`:`Week of ${Y0.format(r)}`}}function Ype({item:e,projectId:t,onDone:n}){let{api:r}=V(),i=_(),a=Ry(),[o,s]=(0,m.useState)(e.at===null?``:Kpe(e.at)),c=L({mutationFn:n=>ds(r,t,{short:e.short,at:n}),onSuccess:()=>{i.invalidateQueries({queryKey:J0}),n()},onError:e=>a(`The time wasn't changed: ${e.message}`,`error`)}),l=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(zB,{"aria-label":`${l}: release`,type:`datetime-local`,className:`w-[200px]`,value:o,onChange:e=>s(e.currentTarget.value)}),(0,h.jsx)(B,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(new Date(o).toISOString()),children:`Save`}),e.short===0?(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:c.isPending,onClick:()=>c.mutate(null),children:`Not scheduled`}):null,(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,onClick:n,children:`Cancel`})]})}function Z0({item:e,projectId:t,editing:n,onEdit:r}){let i=qpe(e),a=n?.projectId===t&&n.short===e.short,o=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:o}),e.short===0?null:(0,h.jsx)(`span`,{className:`w-full truncate text-small`,title:e.title,children:e.title}),a?(0,h.jsx)(Ype,{item:e,projectId:t,onDone:()=>r(void 0)}):(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,"aria-label":`${o}: move from ${e.at===null?`no time`:X0(e.at)}`,onClick:()=>r({projectId:t,short:e.short}),children:e.at===null?`Set a time`:X0(e.at)}),(0,h.jsx)(kS,{tone:i.tone,children:i.word})]})}function Xpe({entry:e,candidates:t}){let{api:n}=V(),r=_(),i=Ry(),a=t.filter(t=>e.series===``||t.series===e.series),[o,s]=(0,m.useState)(``),c=L({mutationFn:t=>ds(n,t,{short:0,at:e.at,...e.line===null?{}:{line:e.line}}),onSuccess:()=>void r.invalidateQueries({queryKey:J0}),onError:e=>i(`The project wasn't put there: ${e.message}`,`error`)});return a.length===0?(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[`Free · no finished project`,e.series===``?``:` of ${e.series}`,` waits for a time`]}):(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(VB,{"aria-label":`Project for ${X0(e.at)}`,className:`w-[260px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:``,label:`Free · pick a finished project`},...a.map(e=>({value:e.id,label:e.title}))]}),(0,h.jsx)(B,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(o),children:`Put it here`})]})}function Zpe(){let{api:e}=V(),t=I({queryKey:J0,queryFn:()=>cs(e)}),[n,r]=(0,m.useState)();if(t.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the releases…`});if(t.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The releases didn't load: `,t.error.message,` Reload the page to try again.`]});let i=t.data;if(i.entries.length===0)return(0,h.jsx)(T1,{title:`No releases in the next two weeks`,children:`Add your week in Settings → YouTube Studio → Posting plan: each finished project then takes its next free time, and its shorts the times after it. Or open a finished project's Prepare upload.`});let a=new Date,o=new Map;for(let e of i.entries){let t=Jpe(e.at,a),n=o.get(t.key)??{label:t.label,entries:[]};n.entries.push(e),o.set(t.key,n)}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Every video and short is due `,String(i.leadHours),` hours before its release, so YouTube's copyright and ad checks finish while it is private. Change that, or the weekly times, in`,` `,(0,h.jsx)(fa,{to:`/settings`,search:{section:`studio`},children:`Settings → YouTube Studio`}),`.`]}),[...o.values()].map(e=>(0,h.jsxs)(`section`,{"aria-label":e.label,className:`flex flex-col gap-3`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:e.label}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:e.entries.map(e=>{let t=e.items.find(e=>e.short===0),a=e.items.filter(e=>e.short>0);return(0,h.jsxs)(`li`,{className:`flex flex-col gap-2 border-b border-line pb-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:X0(e.at)}),e.series===``?null:(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.series}),e.project===null?null:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.project.id},children:e.project.title})]}),e.project===null?(0,h.jsx)(Xpe,{entry:e,candidates:i.candidates}):(0,h.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-x-4 gap-y-3`,children:[t===void 0?null:(0,h.jsx)(Z0,{item:t,projectId:e.project.id,editing:n,onEdit:r}),a.map(t=>(0,h.jsx)(Z0,{item:t,projectId:e.project?.id??``,editing:n,onEdit:r},t.short))]})]},`${e.at}-${e.project?.id??`free`}`)})})]},e.label))]})}var Q0=4;function Qpe(e){return e===`schedules`?`schedules`:e===`releases`?`releases`:`weeks`}var $0=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),e2=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),t2=new Intl.DateTimeFormat(void 0,{timeStyle:`short`}),n2=`slopify.calendar.view`;function $pe(){try{return window.localStorage.getItem(n2)===`list`?`list`:`weeks`}catch{return`weeks`}}function eme({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=V(),a=_(),o=Dx(),[s]=(0,m.useState)(()=>OH(new Date,Q0)),[c,l]=(0,m.useState)($pe),[u,d]=(0,m.useState)(e??`weeks`),f=n===void 0?u:e??`weeks`,p=e=>{n===void 0?d(e):n(e)},[g,v]=(0,m.useState)(!1),y=I(pH(i,s.from,s.to)),b=I(qV(i)),x=I(lq(i)),S=I(ob(i)),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),D=(0,m.useMemo)(()=>new Map((x.data??[]).map(e=>[e.id,e.channelId])),[x.data]),O=(0,m.useMemo)(()=>new Map((S.data?.projects??[]).map(e=>[e.id,e.channelId])),[S.data]),k=(b.data??[]).filter(e=>o.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>o.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>o.includes(O.get(e.id)))},j=(0,m.useMemo)(()=>A===void 0?new Map:DH(A),[A]),M=A?.runs??[],ee=SH(A?.projects??[]),N=L({mutationFn:e=>e(),onSuccess:e=>w(e.ok?{tone:`info`,text:`Moved.`}:{tone:`error`,text:e.message}),onError:e=>w({tone:`error`,text:`The topic wasn't moved: ${e.message} Reload the calendar and try again.`}),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:fH}),a.invalidateQueries({queryKey:KV})])}}),P=e=>{if(e.kind!==`none`){if(e.kind===`refused`){w({tone:`error`,text:e.message});return}e.kind===`move`?N.mutate(()=>lH(i,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to})):N.mutate(()=>dH(i,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}}))}},F=(e,t)=>{let n=AH(M,e,t);if(n===void 0){w({tone:`error`,text:t===-1?`${jH(e)} is already the next topic of ${e.scheduleName}.`:`${jH(e)} is the last topic on the calendar for ${e.scheduleName}.`});return}P(kH(e,n,e2.format(new Date(n.at))))},te=e=>{l(e),f!==`weeks`&&p(`weeks`);try{window.localStorage.setItem(n2,e)}catch{}};jx({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),jx({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>p(`schedules`)}),oS(tS.addToCalendar,()=>v(!0)),jx({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>te(`weeks`)}),jx({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>te(`list`)});let ne=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),re=C?.text??y.error?.message??b.error?.message,ie=wH(new Date),ae=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(XK,{title:`Calendar`,meta:`${o.channel?.name??`Every channel`} · ${String(M.length)} scheduled ${M.length===1?`run`:`runs`} in the next ${String(Q0)} weeks · ${String(ne)} ${ne===1?`topic`:`topics`} queued`,actions:f===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Vb,{label:`Calendar view`,tip:`planning.calendar.view`,value:c,onChange:te,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(B,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]}):void 0}),(0,h.jsx)(C1,{items:[{id:`weeks`,label:`Coming weeks`},{id:`releases`,label:`Releases`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ae)}}],value:f,onChange:p,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(w1,{idPrefix:`calendar`,id:`releases`,active:f===`releases`,children:f===`releases`?(0,h.jsx)(Zpe,{}):null}),(0,h.jsx)(w1,{idPrefix:`calendar`,id:`schedules`,active:f===`schedules`,children:f===`schedules`?(0,h.jsx)(qfe,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(w1,{idPrefix:`calendar`,id:`weeks`,active:f===`weeks`,children:[(0,h.jsx)(v1,{tone:C?.tone===`info`?`info`:re?`error`:`info`,className:`mb-3`,children:re}),(0,h.jsxs)(b1,{split:`aside`,className:`mb-6`,children:[(0,h.jsx)(x1,{label:`Needs you`,children:ee.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Nothing needs you right now.`}):(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(W,{title:`Needs you`,meta:xH(ee)}),(0,h.jsx)(PH,{label:`Needs you`,children:ee.map(e=>(0,h.jsx)(a2,{project:e},e.id))})]})}),(0,h.jsx)(x1,{as:`aside`,label:`Suggested topics`,children:(0,h.jsx)(bfe,{schedules:k})})]}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[y.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the calendar…`}):c===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic to another day to change when it runs, or onto another schedule's run to move it there. With the keyboard: focus a topic and press Alt+← or Alt+→.`}),EH(new Date(s.from),Q0).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=wH(e),n=j.get(t);return(0,h.jsx)(tme,{date:e,today:t===ie,day:n,dragging:T,busy:N.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(P(kH(T,t,e2.format(e))),E(null))},onStep:F},t)})},wH(e[0]??new Date)))]}):(0,h.jsx)(rme,{days:j,busy:N.isPending,onStep:F,schedules:k,onTransfer:(e,t)=>{e.index!==null&&P({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0})}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(W,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(PH,{label:`Batch queue`,children:A.queued.toSorted((e,t)=>e.position-t.position).map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsx)(OS,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`})},e.projectId)})})]}):null]})]}),(0,h.jsx)(hH,{open:g,onOpenChange:v,schedules:k})]})}function tme({date:e,today:t,day:n,dragging:r,busy:i,onDragStart:a,onDragEnd:o,onDrop:s,onStep:c}){let[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(!1),p=n?.runs??[],g=n?.projects??[],_=d?g:g.slice(0,r2),v=()=>p.find(e=>e.scheduleId===r?.scheduleId)??p[0];return(0,h.jsxs)(`section`,{"aria-label":e2.format(e),className:z(`sl-cal-day`,t&&`sl-cal-day--today`,l&&`sl-cal-day--over`),onDragOver:e=>{r!==null&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,u(!0))},onDragLeave:()=>u(!1),onDrop:e=>{e.preventDefault(),u(!1),s(v())},children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:t?`Today · ${$0.format(e)}`:$0.format(e)}),p.map(e=>(0,h.jsx)(nme,{run:e,busy:i,onDragStart:a,onDragEnd:o,onDrop:t=>{t.preventDefault(),t.stopPropagation(),u(!1),s(e)},onStep:c},`${e.scheduleId}-${e.at}`)),_.map(e=>{let t=bH(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${MH}`,children:[(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${NH}`,children:e.title}),(0,h.jsx)(OS,{tone:t.tone,children:t.word})]},e.id)}),g.length>r2?(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-expanded":d,className:`self-start`,onClick:()=>f(e=>!e),children:d?`Show fewer`:`+${String(g.length-r2)} more`}):null]})}var r2=3;function nme({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=jH(e);return(0,h.jsxs)(`article`,{tabIndex:e.index===null?void 0:0,"aria-label":`${s}, ${t2.format(new Date(e.at))}, ${e.scheduleName}${e.index===null?``:`. Alt+arrow keys move it.`}`,draggable:o,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,s),n(e)},onDragEnd:r,onDragOver:e=>e.preventDefault(),onDrop:i,onKeyDown:t=>{o&&t.altKey&&(t.key===`ArrowLeft`||t.key===`ArrowUp`?(t.preventDefault(),a(e,-1)):(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(t.preventDefault(),a(e,1)))},className:z(`sl-cal-item`,o&&`sl-cal-item--movable`),children:[(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:t2.format(new Date(e.at))}),(0,h.jsx)(`b`,{className:z(`text-small`,e.topic===null&&`font-normal text-ink-2`),children:s}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.scheduleName}),e.paused?(0,h.jsx)(OS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(OS,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(OS,{tone:`off`,children:`Queued`}):(0,h.jsx)(OS,{tone:`info`,children:`Prepared`}),(0,h.jsx)(i2,{run:e,compact:!0})]})}function i2({run:e,compact:t=!1}){let{api:n}=V(),r=_(),[i,a]=(0,m.useState)(),o=L({mutationFn:async()=>{if(e.topic===null)throw Error(`This run has no topic to prepare yet.`);let t=await iH(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:fH}),r.invalidateQueries({queryKey:[`projects`]})},onError:e=>a(e.message)});return e.prepared===null?e.index===null||e.topic===null||e.topicSource!==`queued`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,variant:t?`quiet`:`secondary`,disabled:o.isPending,onClick:e=>{e.stopPropagation(),o.mutate()},children:o.isPending?`Preparing…`:`Prepare`}),i===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-label text-danger`,children:i})]}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}function a2({project:e}){let t=bH(e);return(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(OS,{tone:t.tone,children:t.word}),t.action===void 0?null:t.action.kind===`upload`?(0,h.jsx)(B0,{projectId:e.id,ready:!0}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function rme({days:e,busy:t,schedules:n,onStep:r,onTransfer:i}){let a=[...e.values()].sort((e,t)=>e.key.localeCompare(t.key));if(a.length===0)return(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Nothing is planned for the next `,Q0,` weeks. Add topics with Add to calendar, or create a schedule on the`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`},children:`Schedules`}),` `,`tab.`]});let o=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,...zb,children:[(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Move a topic earlier, later or to another schedule from its row.`,(0,h.jsx)(U,{id:`planning.calendar.move`,className:`-my-1`})]}),a.map(e=>(0,h.jsxs)(`section`,{"aria-label":e2.format(e.date),children:[(0,h.jsx)(W,{title:e2.format(e.date),as:`h3`}),(0,h.jsxs)(PH,{label:`Planned on ${e2.format(e.date)}`,children:[e.runs.map(e=>{let n=jH(e),a=o.filter(t=>t.id!==e.scheduleId);return(0,h.jsx)(FH,{title:n,meta:`${t2.format(new Date(e.at))} · ${e.scheduleName}${e.templateName===null?``:` · ${e.templateName}`}${e.paused?` · Paused`:``}`,actions:e.index===null?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i2,{run:e}),(0,h.jsx)(Py,{size:`small`,label:`Move ${n} earlier`,disabled:t,onClick:()=>r(e,-1),children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{size:`small`,label:`Move ${n} later`,disabled:t,onClick:()=>r(e,1),children:(0,h.jsx)(mc,{"aria-hidden":`true`,strokeWidth:1.75})}),a.length===0?null:(0,h.jsxs)(`select`,{"aria-label":`Move ${n} to another schedule`,className:`sl-select h-8 w-auto text-small`,value:``,disabled:t,onChange:t=>{t.target.value!==``&&i(e,t.target.value)},children:[(0,h.jsx)(`option`,{value:``,children:`Move to…`}),a.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})},`${e.scheduleId}-${e.at}`)}),e.projects.map(e=>(0,h.jsx)(a2,{project:e},e.id))]})]},e.key))]})}var ime=_j.map(e=>({value:e,label:vj[e]}));function ame({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=L({mutationFn:n=>bx(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${vj[e.aiDisclosure]}.`,`success`),n.setQueryData(ax(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:ix,exact:!0})}});return(0,h.jsxs)(`section`,{"aria-label":`YouTube AI disclosure`,className:`mb-6 max-w-3xl border-b border-line pb-5`,children:[(0,h.jsx)(LB,{label:`YouTube AI disclosure`,tip:`planning.channel.ai-disclosure`,help:`Mark voices in Settings → Voices and Image prompts in Library → Prompts.`,children:(0,h.jsx)(VB,{value:i.isPending?i.variables:e.aiDisclosure,options:ime,disabled:i.isPending,onChange:e=>{let t=_j.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(v1,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}function o2({value:e,onChange:t,inherited:n,label:r=`Language`,error:i,disabled:a=!1,tip:o=`play.language`}){let s=e??n?.language;return(0,h.jsx)(LB,{label:r,tip:o,help:ome(s),error:i,children:(0,h.jsxs)(VB,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:MO.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,NO(n.language).name,`)`]}),jO.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function ome(e){let t=NO(e);if(t.code===`en`)return`Everything is written and timed in English.`;let n=`The article, narration, YouTube description and Shorts titles are written in ${t.name}; pick a voice that speaks it.`,r=PO(t.code);return r===void 0?`${n} Captions are timed word by word with a free 248 MB model, downloaded the first time a ${t.name} project makes captions.`:`${n} ${r}`}function sme({rows:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,h.jsxs)(`section`,{"aria-label":`Channel links`,...zb,children:[(0,h.jsx)(W,{title:`Channel links`,meta:`Write a link's name in braces in a description, such as {{Patreon}}.`,info:`planning.links.named`}),e.length===0?(0,h.jsx)(`p`,{className:`m-0 border-y border-line py-4 text-ink-2`,children:`No channel links yet. Add one, then write its name in braces in a description.`}):(0,h.jsx)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:e.map((r,i)=>(0,h.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,1fr)] items-center gap-2 border-b border-line py-3 md:grid-cols-[220px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(zB,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})}),(0,h.jsx)(zB,{"aria-label":`Address of link ${String(i+1)}`,type:`url`,placeholder:`https://`,value:r.url,onChange:e=>n(i,{url:e.currentTarget.value})}),(0,h.jsxs)(B,{variant:`quiet`,size:`small`,className:`justify-self-start`,"aria-label":`Remove link ${String(i+1)}`,onClick:()=>t(e.filter((e,t)=>t!==i)),children:[(0,h.jsx)($c,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(B,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function cme(){return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsx)(W,{title:`Named links`,info:`planning.links.named`}),(0,h.jsx)(`p`,{className:`m-0 max-w-[60ch] text-ink-2`,children:`Each channel keeps its own links now, on its Brand tab under Channel links. Links saved here before fill the default channel's descriptions until you save its Brand tab.`}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsx)(CS,{to:`/channels/$channelId`,params:{channelId:tx},children:`Open the default channel's links`})})]})}function s2({value:e,inherit:t,sources:n,offerNone:r,problem:i,file:a,fieldPrefix:o=`ambientBed`,onChange:s}){let c=e!==void 0&&e.source!==`none`,l={level:e?.level??String(qk.levelDb),fadeIn:e?.fadeIn??String(qk.fadeInSeconds),tail:e?.tail??String(qk.tailSeconds)},u=e=>{if(e===``)s(void 0);else if(e===`none`)s({source:`none`,...l});else{let t=n.find(t=>t===e);t!==void 0&&s({source:t,...l})}},d=(t,n,r,a)=>e===void 0||!c?null:(0,h.jsx)(LB,{label:n,help:r,tip:a,error:i(t),children:(0,h.jsx)(zB,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})})});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(LB,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(VB,{"data-play-field":`${o}.source`,value:e?.source??``,onChange:e=>u(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:t}),r?(0,h.jsx)(`option`,{value:`none`,children:`None`}):null,n.map(e=>(0,h.jsx)(`option`,{value:e,children:Kk[e]},e))]})}),e?.source===`upload`?a:null,c?(0,h.jsxs)(`div`,{className:`contents`,children:[d(`level`,`Level (dB)`,`-40 to -6; 0 is about as loud as the voice.`,`project.ambient.level`),d(`fadeIn`,`Fade in (seconds)`,`0 to 30.`,`project.ambient.fade-in`),d(`tail`,`Tail after the narration (seconds)`,`0 to 30, fading out.`,`project.ambient.tail`)]}):null]})}function lme({value:e,onChange:t}){let n=Qk(e),r=n===void 0?[]:Yk(n);return(0,h.jsx)(s2,{value:e,inherit:`Not set`,sources:Wk,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function ume(e){return e.ambientBed===void 0?void 0:Zk(e.ambientBed)}function dme(e){let t=Qk(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:Yk(t).length>0}}var c2=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`];function fme(e){return Object.fromEntries(c2.map(t=>[t,e[t]??``]))}function pme({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=I({queryKey:eN,queryFn:()=>tN(t)}),a=I(mb(t)),o=I(hb(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(fme(e.brand)),[p,g]=(0,m.useState)(ume(e.brand)),v=dme(p),y=I({queryKey:H.channelLinks,queryFn:()=>Ls(t),enabled:e.isDefault&&e.brand.links===void 0}),[b,x]=(0,m.useState)(),S=b??e.brand.links??y.data??[],C=b!==void 0||e.brand.links!==void 0||(y.data?.length??0)>0,w=L({mutationFn:()=>dx(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(c2.flatMap(e=>d[e].trim()===``?[]:[[e,d[e].trim()]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(ax(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:ix}),n.invalidateQueries({queryKey:H.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),D=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),O=[...(o.data?.builtIns??[]).map(e=>({value:e.name,label:e.label})),...(o.data?.themes??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(`form`,{"aria-label":`Brand kit`,onSubmit:e=>{e.preventDefault(),w.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-5`,children:[(0,h.jsx)(LB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(zB,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(LB,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules.`,children:(0,h.jsx)(BB,{rows:4,value:l,maxLength:1e4,onChange:e=>u(e.target.value)})}),(0,h.jsx)(W,{title:`Brand kit`,meta:`Fills what a template leaves at its default. Blank fields add nothing.`,info:`planning.channel.brand-kit`,className:`mt-2 border-t border-line pt-6`}),(0,h.jsx)(`section`,{"aria-label":`Language`,className:`max-w-md`,children:(0,h.jsx)(o2,{label:`Language of new projects`,tip:`planning.channel.language`,value:d.language===``?void 0:d.language,inherited:{label:`Not set`,language:void 0},onChange:e=>T(`language`)(e??``)})}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:E,onPick:T(`captionFontId`)}),(0,h.jsx)(u2,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(u2,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`)})]}),(0,h.jsxs)(`section`,{"aria-label":`Chapter cards and end screen`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:E,onPick:T(`titleFontId`)}),(0,h.jsx)(u2,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(LB,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(zB,{value:d.endScreenText,maxLength:200,placeholder:`Subscribe for more`,onChange:e=>T(`endScreenText`)(e.target.value)})})]}),(0,h.jsxs)(`section`,{"aria-label":`Intro, outro and document`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:D(`intro`),onPick:T(`intro`)}),(0,h.jsx)(l2,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:D(`outro`),onPick:T(`outro`)}),(0,h.jsx)(l2,{label:`Document theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:O,onPick:T(`documentTheme`)})]}),(0,h.jsx)(lme,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(sme,{rows:S,onChange:x})})]}),(0,h.jsx)(y1,{status:(0,h.jsx)(v1,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(B,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked,disabledReason:s.trim()===``?`Give the channel a name`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function l2({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(LB,{label:e,tip:t,children:(0,h.jsxs)(VB,{value:n,onChange:e=>i(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Not set`}),n!==``&&!r.some(e=>e.value===n)?(0,h.jsxs)(`option`,{value:n,children:[n,` (no longer in the library)`]}):null,r.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))]})})}function u2({label:e,tip:t,value:n,onChange:r}){let i=/^#[0-9a-fA-F]{6}$/.test(n);return(0,h.jsx)(LB,{label:e,tip:t,...n!==``&&!i?{error:`Write the colour as # and six hex digits.`}:{},children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-6 shrink-0 rounded-control border border-line-strong`,style:{background:i?n:`transparent`}}),(0,h.jsx)(zB,{value:n,placeholder:`#FFFFFF`,maxLength:7,onChange:e=>r(e.target.value)})]})})}function d2(e,t){return e.languages===void 0||e.languages.includes(NO(t).code)}function mme(e,t,n,r){return n?e:e.filter(e=>d2(e,t)||e.voiceId===r)}function hme(e,t){if(e===void 0||d2(e,t))return;let n=NO(t).name,r=(e.languages??[]).map(e=>NO(e).code===e?NO(e).name:e);return`${e.name} is listed for ${r.join(`, `)}, not ${n}, so it may read the ${n} narration with the wrong accent. Pick a ${n} voice under Narration, or correct the voice's languages in Settings → Voices.`}function f2(e,t,n){let[r,i]=(0,m.useState)(!1),a=mme(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function p2({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=hme(t,e);return n===0&&!r&&o===void 0?null:(0,h.jsxs)(`div`,{className:`col-span-full grid gap-1`,children:[n>0||r?(0,h.jsxs)(`span`,{className:`flex min-h-8 items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:a,type:`checkbox`,checked:r,onChange:e=>i(e.target.checked)}),`Show all voices`,r?``:` (${String(n)} listed for other languages than ${NO(e).name})`]}),(0,h.jsx)(U,{id:`play.show-all-voices`})]}):null,o===void 0?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:o})]})}function gme({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=V(),o=_(),[s,c]=(0,m.useState)(t?.kind??`character`),[l,u]=(0,m.useState)(t?.name??``),[d,f]=(0,m.useState)(t?.aliases??[]),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(t?.description??``),[b,x]=(0,m.useState)(t?.voice),[S,C]=(0,m.useState)(t?.host===!0),w=()=>Promise.all([o.invalidateQueries({queryKey:ax(e)}),o.invalidateQueries({queryKey:ix})]),T=L({mutationFn:async()=>{let n={kind:s,name:l.trim(),aliases:d,description:v,voice:b!==void 0&&b.provider!==``&&b.model!==``&&b.voice!==``?b:null,host:S};return t===void 0?px(a,e,crypto.randomUUID(),n):mx(a,t.id,{...n,baseVersion:t.version})},onSuccess:async e=>{await w(),t===void 0&&i(e.id)}}),E=()=>{let e=p.trim();e===``||d.some(t=>t.toLowerCase()===e.toLowerCase())||(f([...d,e]),g(``))};return n?(0,h.jsxs)(`section`,{"aria-label":t===void 0?`Add to cast`:`Edit ${t.name}`,children:[(0,h.jsx)(W,{kicker:t===void 0?`New cast member`:rx[t.kind],title:t===void 0?`Add to cast`:t.name,meta:t===void 0?`Name it first, then give it reference pictures.`:`Used whenever a title or an image brief names it or one of its aliases.`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:r,children:`Close`})}),t!==void 0&&!t.images.some(e=>e.state===`ready`)?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-waiting`,children:`No picture yet, so it is not sent with any image. Upload or generate one below.`}):null,(0,h.jsxs)(`form`,{id:`cast-member-form`,"aria-label":`Cast member`,className:`mt-4 flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),l.trim()!==``&&T.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(LB,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(VB,{value:s,onChange:e=>c(nx.find(t=>t===e.target.value)??`character`),options:nx.map(e=>({value:e,label:rx[e]}))})}),(0,h.jsx)(LB,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(zB,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(LB,{label:`Aliases`,tip:`planning.cast.aliases`,help:`Press Enter to add each one.`,children:(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(zB,{value:p,maxLength:200,placeholder:`Another name, such as the Last Pharaoh`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,h.jsxs)(B,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add alias`]})]})}),d.length>0?(0,h.jsx)(`ul`,{"aria-label":`Aliases added`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:d.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(AS,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(LB,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(BB,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(vme,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(Bb,{label:`One of the channel's hosts`,tip:`planning.cast.host`,checked:S,onChange:C}),S&&(b===void 0||b.voice===``)?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`A host joins new podcasts and interviews only with a voice. Pick one under Voice above.`}):null]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(v1,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(B,{type:`submit`,form:`cast-member-form`,variant:t===void 0?`primary`:`secondary`,disabled:T.isPending||l.trim()===``,children:t===void 0?`Add to cast`:`Save`})]})]}),t===void 0?null:(0,h.jsx)(_me,{channelId:e,member:t})]}):null}function _me({channelId:e,member:t}){let{api:n}=V(),r=_(),i=I(db(n)),a=(0,m.useRef)(null),o=(0,m.useRef)(null),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(``),[d,f]=(0,m.useState)(`${t.name}${t.description.trim()?`, ${t.description.trim()}`:``}. A clear reference picture on a plain background, the whole ${t.kind===`place`?`place`:t.kind===`object`?`object`:`figure`} in view.`),p=()=>Promise.all([r.invalidateQueries({queryKey:ax(e)}),r.invalidateQueries({queryKey:ix})]),g=L({mutationFn:e=>gx(n,t.id,e),onSettled:p}),v=L({mutationFn:()=>_x(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=L({mutationFn:e=>vx(n,t.id,e),onSettled:p}),b=g.error??v.error??y.error,x=t.images.flatMap((e,t)=>e.state===`ready`&&e.sha256!==null?[{id:e.id,number:t+1,src:xx(n,e.sha256)}]:[]),[S,C]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Reference pictures`,className:`mt-6`,children:[(0,h.jsx)($K,{className:`mb-6`}),(0,h.jsx)(W,{as:`h3`,title:`Reference pictures`,meta:`Sent with every image whose brief, or the video's title, names ${t.name}.`,info:`planning.cast.pictures`}),t.images.length>0?(0,h.jsx)(u0,{list:!0,density:`compact`,label:`Pictures of ${t.name}`,className:`mt-3`,children:t.images.map((e,r)=>(0,h.jsxs)(`li`,{className:`min-w-0`,children:[(0,h.jsx)(l0,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:xx(n,e.sha256)}:{},...e.state===`generating`?{generating:`Making the picture…`}:{},onOpen:()=>C(x.findIndex(t=>t.id===e.id)),openLabel:`Open picture ${String(r+1)} of ${t.name} full size`,...e.state===`failed`?{badge:(0,h.jsx)(kS,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Delete picture ${String(r+1)} of ${t.name}`,disabled:y.isPending||e.state===`generating`,disabledReason:`Wait until the picture is made`,onClick:()=>y.mutate(e.id),children:`Delete`})}),e.state===`failed`&&e.error?(0,h.jsx)(yme,{error:e.error,retry:s===``||l===``||d.trim()===``?void 0:{run:()=>v.mutate(),busy:v.isPending},onReword:()=>o.current?.focus()}):null]},e.id))}):(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-3`,children:`No pictures yet.`}),(0,h.jsx)(d0,{items:x.map(e=>({src:e.src,alt:`${t.name}, reference ${String(e.number)}`})),index:S,onIndex:C,onClose:()=>C(null),actions:(e,n)=>{let r=x[n];return r===void 0?null:(0,h.jsx)(TS,{href:r.src,download:!0,size:`small`,"aria-label":`Download picture ${String(r.number)} of ${t.name}`,children:`Download`})}}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg`,className:`sr-only`,tabIndex:-1,"aria-hidden":`true`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&g.mutate(t)}}),(0,h.jsx)(B,{disabled:g.isPending,onClick:()=>a.current?.click(),children:`Upload a picture`}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`PNG or JPEG, up to 10 MB.`})]}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,...zb,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(U,{id:`planning.cast.generate`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(tV,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(LB,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,children:(0,h.jsx)(BB,{ref:o,rows:3,value:d,maxLength:4e3,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(B,{disabled:v.isPending||s===``||l===``||d.trim()===``,disabledReason:`Pick an image provider and model, and describe the picture`,onClick:()=>v.mutate(),children:`Generate a picture`})})]}),(0,h.jsx)(v1,{tone:b?`error`:`info`,className:`mt-2`,children:b?.message??(g.isPending?`Uploading…`:v.isSuccess?`The picture is being made; it appears here when it is ready.`:void 0)})]})}function vme({channelId:e,value:t,onChange:n}){let{api:r}=V(),i=I(db(r)),a=I(fb(r)),o=I(lx(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=f2(c,o,s.voice||void 0),u=l.listed;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-3 border-0 border-t border-line p-0 pt-4`,...zb,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(U,{id:`planning.cast.voice`,label:`Cast voice`,className:`-my-1`})]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`For multi-voice runs: pick this member under Speakers on Play.`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Voice provider`,family:`tts`,providers:i.data?.providers??[],value:s.provider,problem:void 0,onPick:e=>n(e===``?void 0:{provider:e,model:``,voice:``})}),(0,h.jsx)(tV,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(ZB,{label:`Voice`,value:s.voice,placeholder:u.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:u.map(e=>({value:e.voiceId,label:e.name})),problem:void 0,onPick:e=>n({...s,voice:e})}),(0,h.jsx)(p2,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(ZB,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:CA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:void 0,onPick:e=>{let{pace:t,...r}=s;n(Number(e)===1?r:{...r,pace:Number(e)})}})]}),t===void 0?null:(0,h.jsx)(B,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function yme({error:e,retry:t,onReword:n}){let r=s1({stage:`images`,reason:e});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 mt-1 text-small text-danger`,children:e}),r===void 0?null:(0,h.jsx)(Iy,{className:`mt-2`,children:(0,h.jsx)(h1,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(B,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}function bme({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=V(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=L({mutationFn:e=>hx(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:ax(e)}),a.invalidateQueries({queryKey:ix})])}}),p=t.find(e=>e.id===c),g=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:xx(i,t)}]:[]}),v=g.map(e=>({src:e.src,alt:e.member.name,caption:`${rx[e.member.kind]} · ${e.member.description||`No description yet`}`})),[y,b]=(0,m.useState)(null),x=c===`new`||p!==void 0;return(0,h.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 min-[1024px]:grid-cols-[minmax(0,1fr)_440px]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:`When a video's title or an image's brief names a member, its pictures go with that image as references, so it looks the same in every video.`}),t.length===0?(0,h.jsx)(T1,{title:`No cast yet`,actions:(0,h.jsx)(B,{variant:`secondary`,onClick:()=>l(`new`),children:`Add to cast`}),children:`Add the characters, creatures, places and objects this channel keeps coming back to.`}):(0,h.jsx)(u0,{label:`Cast`,children:t.map(e=>{let t=e.images.filter(e=>e.state===`ready`),n=t[0]?.sha256;return(0,h.jsx)(l0,{className:z(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...n?{src:xx(i,n)}:{},alt:e.name,onOpen:()=>b(g.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${rx[e.kind]}${e.host===!0?` · Host`:``} · ${String(t.length)} ${t.length===1?`picture`:`pictures`}`,...t.length===0?{badge:(0,h.jsx)(kS,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`})]})},e.id)})}),(0,h.jsx)(d0,{items:v,index:y,onIndex:b,onClose:()=>b(null),actions:(e,t)=>{let n=g[t];return n===void 0?null:(0,h.jsx)(B,{size:`small`,onClick:()=>{b(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(v1,{tone:`error`,className:`mt-2`,children:u?void 0:f.error?.message})]}),(0,h.jsx)(`aside`,{"aria-label":`Cast member editor`,className:`min-w-0`,children:x?(0,h.jsx)(gme,{channelId:e,member:p,open:!0,onClose:()=>l(null),onCreated:e=>l(e)},c??`closed`):t.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Pick a member's Edit to change its names, description and pictures here.`})}),(0,h.jsx)(Hy,{open:u!==null,title:`Delete ${u?.name??`this cast member`}?`,consequence:f.error?.message??`New videos stop using its pictures. Videos already made keep the pictures they were started with.`,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var m2=e=>[`channels`,e,`episodes`],h2=e=>[`channels`,e,`videos`],g2=(e,t)=>`${e.origin}/api/channels/${t}`,_2=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function xme(e,t){return at({queryKey:m2(t),queryFn:async()=>R(await e.fetch(`${g2(e,t)}/episodes`))})}async function Sme(e,t,n){return R(await e.fetch(`${g2(e,t)}/episodes/setting`,_2(`PUT`,{enabled:n})))}async function Cme(e,t,n,r){return R(await e.fetch(`${g2(e,t)}/episodes/${encodeURIComponent(n)}`,_2(`PUT`,{summary:r})))}async function wme(e,t,n){let r=await e.fetch(`${g2(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await R(r)}function v2(e,t){return at({queryKey:h2(t),queryFn:async()=>(await R(await e.fetch(`${g2(e,t)}/videos`))).videos})}async function Tme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos`,_2(`POST`,n)))}async function Eme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos/preview`,_2(`POST`,{format:`csv`,text:n})))}async function Dme(e,t,n){let r=await e.fetch(`${g2(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await R(r)}async function Ome(e,t){await R(await e.fetch(`${g2(e,t)}/videos`,{method:`DELETE`}))}var kme=e=>e.length>160?`${e.slice(0,160)}…`:e;function Ame({channelId:e}){let{api:t}=V(),n=_(),r=I(xme(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:m2(e)}),l=L({mutationFn:n=>Sme(t,e,n),onSuccess:t=>n.setQueryData(m2(e),t)}),u=L({mutationFn:n=>wme(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(Bb,{checked:d,disabled:r.data===void 0||l.isPending,onChange:e=>l.mutate(e),label:`Episode memory`,tip:`planning.channel.episode-memory`,describedBy:`${e}-memory-help`}),(0,h.jsx)(`p`,{id:`${e}-memory-help`,className:`mt-1 mb-3 text-small text-ink-2`,children:`Finished episodes leave a short summary that new related episodes are written with.`}),(0,h.jsx)(v1,{tone:r.error||l.error||u.error?`error`:`info`,children:r.error?.message??l.error?.message??(o?void 0:u.error?.message)??(r.isPending?`Loading the episodes…`:void 0)}),r.data&&f.length===0?(0,h.jsx)(T1,{title:`No episodes remembered yet`,children:d?`When a video on this channel finishes, its summary appears here.`:`Turn on episode memory, and the next finished video's summary appears here.`}):null,f.length>0?(0,h.jsx)(PH,{label:`Episode summaries`,children:f.map(e=>(0,h.jsx)(FH,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,kme(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(B,{size:`small`,variant:`quiet`,"aria-label":`Delete the summary of ${e.title}`,onClick:()=>{u.reset(),s(e)},children:`Delete`})]})},e.id))}):null,i?(0,h.jsx)(jme,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(Hy,{open:o!==null,title:`Delete the summary of ${o?.title??`this episode`}?`,consequence:u.error?.message??`New episodes stop being reminded of it. The video itself is not changed.`,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function jme({channelId:e,memory:t,onClose:n}){let{api:r}=V(),i=_(),[a,o]=(0,m.useState)(t.summary),s=L({mutationFn:()=>Cme(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:m2(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Vy,{open:!0,onOpenChange:e=>{e||n()},title:t.title,description:t.source===`edited`?`You edited this summary; finishing the video again keeps your text.`:`Written by the text model when the video finished. An edit here is kept.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{onClick:n,children:`Close`}),(0,h.jsx)(B,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(LB,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(BB,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}var y2=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function b2(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function Mme({channelId:e}){let{api:t}=V(),n=_(),r=I(v2(t,e)),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(void 0),u=(0,m.useRef)(null),d=()=>n.invalidateQueries({queryKey:h2(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=L({mutationFn:n=>Tme(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${y2(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=L({mutationFn:n=>Eme(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:b2(e.titles,e.filter)})}}),x=L({mutationFn:n=>Dme(t,e,n),onSuccess:d}),S=L({mutationFn:()=>Ome(t,e),onSuccess:async()=>{s(!1),await d()}}),C=r.data??[],w=y.isPending||b.isPending||x.isPending||S.isPending,T=r.error??b.error??y.error??x.error;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`Topic suggestions and duplicate checks skip these titles, as they skip the videos made here.`}),(0,h.jsx)(LB,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(BB,{rows:5,value:i,onChange:e=>a(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{variant:`primary`,disabled:w||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(B,{disabled:w,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(U,{id:`planning.channel.videos-csv`}),(0,h.jsx)(`input`,{ref:u,type:`file`,accept:`.csv,text/csv`,className:`hidden`,"aria-label":`YouTube Studio CSV file`,onChange:async e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&(l(void 0),y.reset(),b.mutate(await t.text()))}}),(0,h.jsx)(B,{variant:`quiet`,disabled:w||C.length===0,onClick:()=>{S.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(v1,{tone:T?`error`:c?`success`:`info`,className:`mt-1`,children:T?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(Nme,{preview:f,filter:g,busy:w,onFilter:e=>{v(e),p({...f,ticked:b2(f.titles,e)})},onTick:e=>p({...f,ticked:e}),onSave:()=>{l(void 0);let e=f.titles.filter((e,t)=>f.ticked[t]);y.mutate({text:e.join(`
273
- `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(T1,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(PH,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(FH,{title:e.title,actions:(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(Hy,{open:o,title:`Remove all ${y2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function Nme({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...zb,children:[(0,h.jsxs)(W,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${y2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(B,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,y2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(B,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(LB,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(zB,{value:t,maxLength:200,onChange:e=>r(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(PH,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(FH,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}function x2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:z(`sl-stats m-0`,e),children:t})}function S2({value:e,label:t,children:n}){return(0,h.jsxs)(`div`,{className:`sl-stat`,children:[(0,h.jsx)(`dt`,{className:`sl-stat__label order-2`,children:t}),(0,h.jsx)(`dd`,{className:`sl-stat__value order-1 m-0`,children:e}),n===void 0?null:(0,h.jsx)(`dd`,{className:`order-3 m-0 mt-1`,children:n})]})}function C2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:z(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function w2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:z(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}var T2=56,E2=12,D2=12,Pme=28;function Fme(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=5?5:10)*r}function O2({series:e,xLabels:t,formatValue:n,label:r,height:i=260,legend:a=!0,className:o}){let s=(0,m.useRef)(null),[c,l]=(0,m.useState)(800),[u,d]=(0,m.useState)();(0,m.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([e])=>{e!==void 0&&l(Math.max(320,Math.round(e.contentRect.width)))});return t.observe(e),()=>t.disconnect()},[]);let f=t.length,p=Math.max(0,...e.flatMap(e=>e.values.filter(e=>e!==null))),g=Fme(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-T2-E2,y=e=>T2+(f<=1?0:e/(f-1)*v),b=e=>D2+i-e/_*i,x=Array.from({length:Math.round(_/g)+1},(e,t)=>t*g),S=Math.min(f,Math.max(2,Math.floor(v/90))),C=Array.from({length:S},(e,t)=>Math.round(t/Math.max(1,S-1)*(f-1))),w=e=>{let t=``,n=!1;return e.forEach((e,r)=>{if(e===null){n=!1;return}t+=`${n?`L`:`M`}${y(r).toFixed(1)},${b(e).toFixed(1)}`,n=!0}),t},T=D2+i+Pme,E=u===void 0?[]:e.map(e=>({one:e,value:e.values[u]??null})).filter(e=>e.value!==null).toSorted((e,t)=>t.value-e.value);return(0,h.jsxs)(`figure`,{className:z(`m-0 flex flex-col gap-2`,o),children:[(0,h.jsxs)(`div`,{ref:s,className:`relative w-full`,children:[(0,h.jsxs)(`svg`,{role:`img`,"aria-label":r,width:c,height:T,viewBox:`0 0 ${String(c)} ${String(T)}`,className:`block select-none`,onMouseLeave:()=>d(void 0),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=Math.round((e.clientX-t.left-T2)/v*(f-1));d(n<0||n>=f?void 0:n)},children:[x.map(e=>(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:T2,x2:c-E2,y1:b(e),y2:b(e),stroke:`currentColor`,className:`text-line`,strokeWidth:`1`}),(0,h.jsx)(`text`,{x:48,y:b(e),textAnchor:`end`,dominantBaseline:`middle`,className:`fill-ink-3 text-[11px]`,children:n(e)})]},e)),C.map(e=>(0,h.jsx)(`text`,{x:y(e),y:D2+i+18,textAnchor:e===0?`start`:e===f-1?`end`:`middle`,className:`fill-ink-3 text-[11px]`,children:t[e]},e)),e.map(e=>(0,h.jsx)(`path`,{d:w(e.values),fill:`none`,stroke:e.color,strokeWidth:`1.75`,strokeLinejoin:`round`},e.id)),u===void 0?null:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:y(u),x2:y(u),y1:D2,y2:D2+i,stroke:`currentColor`,className:`text-ink-3`,strokeDasharray:`3 3`}),E.map(({one:e,value:t})=>(0,h.jsx)(`circle`,{cx:y(u),cy:b(t),r:`3.5`,fill:e.color},e.id))]})]}),u===void 0||E.length===0?null:(0,h.jsxs)(`div`,{className:`pointer-events-none absolute top-2 z-10 w-[340px] rounded-control border border-line bg-surface p-2 text-small shadow-md`,style:y(u)>c/2?{right:c-y(u)+12}:{left:y(u)+12},children:[(0,h.jsx)(`div`,{className:`mb-1 font-semibold`,children:t[u]}),E.map(({one:e,value:t})=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 shrink-0 rounded-full`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),(0,h.jsx)(`span`,{className:`tabular-nums`,children:n(t)})]},e.id))]})]}),a?(0,h.jsx)(`figcaption`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-small text-ink-2`,children:e.map(e=>(0,h.jsxs)(`span`,{className:`flex max-w-[320px] items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-[3px] w-4 shrink-0 rounded`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))}):null]})}var k2=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function Ime(e,t){return R(await e.fetch(k2(e,t)))}async function Lme(e,t,n){return R(await e.fetch(k2(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}function A2(e,t,n){if(e===null)return`–`;if(typeof e==`string`)return e;if(t===`duration`){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=String(Math.round(e%60)).padStart(2,`0`);return t>0?`${String(t)}:${String(n).padStart(2,`0`)}:${r}`:`${String(n)}:${r}`}let r=/%|\(|rpm|revenue|hours/i.test(n)&&!Number.isInteger(e)?1:0;return e.toLocaleString(`en`,{minimumFractionDigits:r,maximumFractionDigits:r})}var j2=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],M2=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),N2=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function P2(e,t){if(t===`total`){let t=0;return e.map(e=>t+=e)}return t===`average`?e.map((t,n)=>{let r=e.slice(Math.max(0,n-6),n+1);return r.reduce((e,t)=>e+t,0)/r.length}):[...e]}function Rme({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,d=t.filter(e=>n.includes(e.videoId)),f=e.from===null?new Date:new Date(`${e.from}T00:00:00`),p=Math.max(0,...t.map(e=>e.daily.length)),m,g;if(o===`dates`){let e=c===`all`?0:Math.max(0,p-Number(c)),t=p-e>200;m=Array.from({length:p-e},(n,r)=>{let i=new Date(f);return i.setDate(i.getDate()+e+r),(t?N2:M2).format(i)}),g=d.map(t=>{let n=t.daily.findIndex(e=>e>0),a=P2(t.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:t.videoId,label:t.title,color:r(t.videoId),values:a.slice(e)}})}else{let e=Math.max(1,...d.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));m=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),g=d.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=P2(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let _=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:_}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(VB,{"aria-label":`Show`,className:`w-[200px]`,value:i,onChange:e=>a(e.currentTarget.value),options:[{value:`average`,label:`7-day average`},{value:`daily`,label:`Per day`},{value:`total`,label:`Running total`}]}),(0,h.jsx)(VB,{"aria-label":`Timeline`,className:`w-[220px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:`dates`,label:`By date`},{value:`since`,label:`Days since release`}]}),(0,h.jsx)(VB,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),d.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(O2,{series:g,xLabels:m,label:`${_} for ${String(d.length)} videos`,formatValue:F2})]})}var F2=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function zme({report:e,rows:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`);return(0,h.jsxs)(`section`,{"aria-label":`Each video`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Each video · ${a}`}),t.some(e=>!e.daily.some(e=>e>0))?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart more, tick them in Advanced mode's chart before you export.`}):null,(0,h.jsx)(`div`,{className:`grid gap-6 lg:grid-cols-2`,children:t.map(e=>{let t=e.daily.findIndex(e=>e>0);if(t<0)return null;let s=P2(e.daily.slice(t),n),c=r===`all`?0:Math.max(0,s.length-Number(r)),l=s.slice(c),u=l.map((e,n)=>{let r=new Date(o);return r.setDate(r.getDate()+t+c+n),(l.length>200?N2:M2).format(r)}),d=e.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 shrink-0 rounded-full`,style:{background:i(e.videoId)}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold`,title:e.title,children:e.title}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`${d.toLocaleString(`en`)} total`})]}),(0,h.jsx)(O2,{height:150,legend:!1,label:`${a} for ${e.title}`,xLabels:u,formatValue:F2,series:[{id:e.videoId,label:e.title,color:i(e.videoId),values:l}]})]},e.videoId)})})]})}var I2=e=>`slopify.studioReport.hidden.${e}`;function Bme(e){try{let t=window.localStorage.getItem(I2(e));return t===null?void 0:JSON.parse(t)}catch{return}}function L2({channelId:e}){let{api:t}=V(),n=_(),r=Ry(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=I({queryKey:a,queryFn:()=>Ime(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(()=>Bme(e)),S=L({mutationFn:n=>Lme(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),C=o.data?.report??null,w=C?.columns??[],T=w.filter((e,t)=>(C?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),E=b??T,D=t=>{x(t);try{window.localStorage.setItem(I2(e),JSON.stringify(t))}catch{}},O=w.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!E.includes(e.label)),k=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},A=[...C?.rows??[]].toSorted((e,t)=>k(t,s)-k(e,s)),j=[...C?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),M=l??j.slice(0,5).map(e=>e.videoId),ee=e=>{let t=(C?.rows??[]).findIndex(t=>t.videoId===e);return j2[(t<0?0:t)%j2.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(W,{as:`h3`,title:`From Studio's export`,meta:C===null?void 0:`${String(C.rows.length)} videos · ${C.from??`?`} to ${C.to??`?`} · imported ${new Date(C.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&S.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(B,{type:`button`,variant:`secondary`,disabled:S.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(tl,{"aria-hidden":`true`,strokeWidth:1.75}),S.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),C===null?null:(0,h.jsxs)(h.Fragment,{children:[C.chartMetric===null?null:(0,h.jsx)(Rme,{report:C,rows:A,picked:M,colorOf:ee,shape:d,setShape:f,timeline:p,setTimeline:g,range:v,setRange:y}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(VB,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:w.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(O.length),` of `,String(w.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:w.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!E.includes(e.label),onChange:t=>D(t.currentTarget.checked?E.filter(t=>t!==e.label):[...E,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[C.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),O.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[C.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),O.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:A2(C.totals[t]??null,e.kind,e.label)},e.label))]}),A.map(e=>{let t=o.data?.projects[e.videoId];return(0,h.jsxs)(`tr`,{children:[C.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:M.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...M,e.videoId]:M.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:M.includes(e.videoId)?ee(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),O.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:A2(e.values[n]??null,t.kind,t.label)},t.label))]},e.videoId)})]})]})}),C.chartMetric===null?null:(0,h.jsx)(zme,{report:C,rows:A,shape:d,range:v,colorOf:ee})]})]})}var R2=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),z2=e=>e==null?`–`:`${e.toFixed(1)}%`;function B2(e){if(e==null)return`–`;let t=Math.round(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}var Vme=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),V2=e=>e===null?`–`:Vme.format(new Date(e));function H2({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(x2,{children:[(0,h.jsx)(S2,{value:R2(t.views),label:`Views`}),(0,h.jsx)(S2,{value:R2(t.impressions),label:`Impressions`}),(0,h.jsx)(S2,{value:z2(t.ctr),label:`Click-through rate`}),(0,h.jsx)(S2,{value:B2(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(S2,{value:R2(t.watchHours),label:`Watch hours`})]})]})}var U2=(e,t)=>{let n=e.long?.stats??null;return t===`views`?(n?.views??0)+e.shorts.reduce((e,t)=>e+(t.stats?.views??0),0):t===`ctr`?n?.ctr??-1:t===`duration`?n?.averageViewSeconds??-1:Date.parse(e.long?.releasedAt??e.shorts[0]?.releasedAt??``)||0};function Hme({channelId:e}){let{api:t}=V(),[n,r]=(0,m.useState)(`newest`),i=I({queryKey:[`studio`,`performance`,e],queryFn:()=>hs(t,e)});if(i.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the numbers…`});if(i.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The numbers didn't load: `,i.error.message,` Reload the page to try again.`]});let a=i.data;if(a.projects.length===0)return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(L2,{channelId:e}),(0,h.jsx)(T1,{title:`No video of this channel is known on YouTube yet`,children:`Upload with the Slopify Studio extension, or open YouTube Studio's Content list once so the extension links your videos. Their numbers then arrive daily, or at once with Read Studio numbers now in the extension's popup.`})]});let o=a.projects.toSorted((e,t)=>U2(t,n)-U2(e,n)).flatMap(e=>[...e.long===null?[]:[{key:`${e.projectId}-0`,projectId:e.projectId,row:e.long,isShort:!1}],...e.shorts.map(t=>({key:`${e.projectId}-${String(t.short??0)}`,projectId:e.projectId,row:t,isShort:!0}))]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Studio's numbers as the Slopify Studio extension last read them`,a.readAt===null?``:` (newest ${V2(a.readAt)})`,`: daily while Chrome is open, or at once with Read Studio numbers now in the extension's popup. "–" is a number Studio doesn't show for that video (most shorts have no click-through rate).`]}),(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,h.jsx)(H2,{label:`Long videos`,totals:a.long}),(0,h.jsx)(H2,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(L2,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:`Every video`,children:(0,h.jsx)(VB,{"aria-label":`Order`,value:n,onChange:e=>r(e.currentTarget.value),options:[{value:`newest`,label:`Newest first`},{value:`views`,label:`Most views`},{value:`ctr`,label:`Best click-through rate`},{value:`duration`,label:`Longest average view`}]})}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{columns:[{id:`title`,header:`Video`,cell:e=>e.isShort?(0,h.jsx)(`span`,{className:`block pl-5 text-small text-ink-2`,children:`Short ${String(e.row.short??``)} · ${e.row.title}`}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>V2(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>R2(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>z2(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>R2(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>B2(e.row.stats?.averageViewSeconds)},{id:`hours`,header:`Watch hours`,numeric:!0,cell:e=>e.row.stats?.watchHours===null||e.row.stats?.watchHours===void 0?`–`:e.row.stats.watchHours.toFixed(1)}],rows:o,rowKey:e=>e.key,caption:`The channel's videos and shorts with Studio's numbers`})})]})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],Ume={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function Wme(e){return W2.find(t=>t===e)??`brand`}function Gme({channelId:e,tab:t,onTab:n}){let{api:r}=V(),i=_(),a=Ji(),o=I(lx(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=L({mutationFn:()=>fx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:ix}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return jx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(fa,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(B,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(C1,{items:W2.map(e=>({id:e,label:Ume[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(v1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(w1,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(ame,{channel:f}),(0,h.jsx)(pme,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(bme,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(wfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Dfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Ame,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(Mme,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(Hme,{channelId:f.id}):null})]}):null,(0,h.jsx)(Hy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function Kme(){let{api:e}=V(),t=_(),n=Ji(),r=I(cx(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=L({mutationFn:()=>ux(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:ix}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=L({mutationFn:t=>dx(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:ix}),a(null)}}),v=L({mutationFn:t=>fx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:ix})}}),y=()=>{p.reset(),l(``),a(`new`)};jx({id:`channels.new`,title:`New channel`,group:`Channels`,run:y});let b=i===`new`?p:g,x=()=>{c.trim()!==``&&i!==null&&(i===`new`?p.mutate():g.mutate(i))};return(0,h.jsxs)(`div`,{"data-tour":`channels`,children:[(0,h.jsx)(XK,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(U,{id:`planning.channels`})]}),actions:(0,h.jsxs)(B,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(v1,{tone:r.error||v.error?`error`:`info`,className:`mb-2`,children:r.error?`The channels couldn't be loaded: ${r.error.message} Reload the page to try again.`:o===null&&v.error?v.error.message:r.isPending?`Loading channels…`:void 0}),r.data?.length===0?(0,h.jsx)(T1,{title:`No channels yet`,actions:(0,h.jsx)(B,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(QK,{list:(0,h.jsx)(PH,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(FH,{selected:e.id===f?.id,onSelect:()=>d(e.id),title:e.name,meta:`${e.isDefault?`Default · `:``}${String(e.templates)} ${e.templates===1?`template`:`templates`} · ${String(e.cast)} in the cast`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(qme,{channel:f})}):null,(0,h.jsx)(Vy,{open:i!==null,onOpenChange:e=>{!e&&!b.isPending&&a(null)},title:i===`new`||i===null?`New channel`:`Rename ${i.name}`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(B,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(B,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(LB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(zB,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Hy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function qme({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(W,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(CS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(x2,{className:`mb-6`,children:[(0,h.jsx)(S2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(S2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(W,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(W,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var G2=2e3;function K2(e,t){let n=(0,m.useRef)(t);(0,m.useEffect)(()=>{n.current=t}),(0,m.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{n.current()},G2);return()=>{clearTimeout(t)}},[e])}function q2(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(Sc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function J2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Ry();jx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:nP.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(B,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(v1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(q2,{}):t)}),a,(0,h.jsx)(B,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Ux(nP.save),onClick:()=>{c||s()},children:`Save`})]})}var Jme=`rounded-media border border-line bg-surface p-4`;function Y2(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${Jme} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var Yme=`modulepreload`,Xme=function(e){return`/`+e},X2={},Z2=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Xme(t,n),t=s(t),t in X2)return;X2[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Yme,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Zme({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return Qme(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function Qme(e,t){let n=await Z2(()=>import(`./pdf-DK_RqCdk.js`),[]),r=await Z2(()=>import(`./pdf.worker.min-zC6nfbxG.js`),[]);n.GlobalWorkerOptions.workerSrc=r.default;let i=n.getDocument({data:e.slice()}),a=await i.promise;try{let e=window.devicePixelRatio||1,n=[];for(let r=1;r<=a.numPages;r+=1){let i=await a.getPage(r),o=i.getViewport({scale:t*e/i.getViewport({scale:1}).width}),s=window.document.createElement(`canvas`);s.width=Math.floor(o.width),s.height=Math.floor(o.height),await i.render({canvas:s,viewport:o}).promise,n.push(s)}return n}finally{await i.destroy()}}var Q2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),$2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),e4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),t4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),n4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),i4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),$me=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},Q2([`page`,`margin`],`Margins`),Q2([`page`,`contentTop`],`Text starts at`,`From the top, on pages with the header.`),{kind:`choice`,path:[`background`,`image`],label:`Background`,options:[{value:`parchment`,label:`Parchment texture`},{value:null,label:`Flat colour`}]},{kind:`color`,path:[`background`,`color`],label:`Page colour`,help:`Used when the background is a flat colour.`}]},{title:`Colours`,fields:[{kind:`color`,path:[`colors`,`heading`],label:`Headings`,help:`Also drop caps, the brand name and links.`},{kind:`color`,path:[`colors`,`text`],label:`Body text`},{kind:`color`,path:[`colors`,`muted`],label:`Muted`,help:`Dates, bullets, quotes and the dots in the contents.`},{kind:`color`,path:[`colors`,`faint`],label:`Faint`,help:`Running header and page numbers.`}]},{title:`Fonts`,fields:[i4(`body`,`Body`),i4(`strong`,`Bold text`),i4(`emphasis`,`Italic text`),i4(`heading`,`Headings`),i4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),i4(`decorative`,`Tagline and title-page link`),i4(`dropCap`,`Drop caps`),i4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[$2([`sizes`,`title`],`Title`),$2([`sizes`,`brand`],`Brand`),$2([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),$2([`sizes`,`heading`],`Second-level headings`),$2([`sizes`,`subheading`],`Third-level headings`),$2([`sizes`,`body`],`Body`),$2([`sizes`,`meta`],`Date and word count`),$2([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[Q2([`spacing`,`bodyLine`],`Body line height`),Q2([`spacing`,`headingLine`],`Heading line height`),Q2([`spacing`,`subheadingLine`],`Subheading line height`),e4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),e4([`spacing`,`headingGap`],`Before a heading`,`× line`),e4([`spacing`,`itemGap`],`After a list item`,`× line`),Q2([`spacing`,`listIndent`],`List indent`),Q2([`spacing`,`quoteIndent`],`Quote indent`),Q2([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[t4([`dropCap`,`enabled`],`Drop caps`,`A large first letter after each heading.`),{kind:`choice`,path:[`dropCap`,`lines`],label:`Lines tall`,options:[{value:2,label:`2 lines`},{value:3,label:`3 lines`},{value:4,label:`4 lines`}]},e4([`dropCap`,`scale`],`Letter size`,`× lines`),Q2([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},e4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[Q2([`titlePage`,`brandY`],`Brand from top`),Q2([`titlePage`,`taglineOffset`],`Tagline below brand`),Q2([`titlePage`,`titleY`],`Title from top`),Q2([`titlePage`,`titleLine`],`Title line height`),Q2([`titlePage`,`metaOffset`],`Details below title`),Q2([`titlePage`,`metaLine`],`Details line height`),t4([`titlePage`,`showDate`],`Show the date`),t4([`titlePage`,`showWordCount`],`Show the word count`),t4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),Q2([`titlePage`,`cover`,`gap`],`Space around cover`),Q2([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[r4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),r4([`brand`,`tagline`],`Tagline`),r4([`brand`,`url`],`Website`,`Where the brand and its link go.`),r4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[t4([`contents`,`enabled`],`Contents page`),n4([`contents`,`title`],`Title`),{kind:`choice`,path:[`contents`,`depth`],label:`Lists headings down to`,options:[{value:1,label:`Top level`},{value:2,label:`Second level`},{value:3,label:`Third level`}]},Q2([`contents`,`titleOffset`],`Title from top margin`),Q2([`contents`,`firstEntryOffset`],`First entry from top margin`),Q2([`contents`,`line`],`Line height`),Q2([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[t4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),Q2([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},t4([`footer`,`enabled`],`Page numbers`),n4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),Q2([`footer`,`bottom`],`From the bottom`),Q2([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[t4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),n4([`sources`,`title`],`Title`),Q2([`sources`,`titleOffset`],`Title from top margin`),Q2([`sources`,`bodyOffset`],`List from top margin`),Q2([`sources`,`line`],`Line height`),Q2([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[t4([`endPage`,`enabled`],`Closing page`),n4([`endPage`,`title`],`Title`),{kind:`lines`,path:[`endPage`,`lines`],label:`Text`,help:`One line each. Start with "•" for a bullet, end with ":" for a bold label, leave a line empty for a gap.`},t4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},r4([`endPage`,`closing`],`Closing line`),Q2([`endPage`,`titleOffset`],`Title from top margin`),Q2([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[n4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),n4([`metadata`,`subject`],`Subject`),n4([`metadata`,`keywords`],`Keywords`),n4([`metadata`,`creator`],`Creator`)]}],a4=Kj.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function o4(e){let t={normal:`Regular`,medium:`Medium`,bold:`Bold`,black:`Black`,italic:`Italic`,bolditalic:`Bold italic`};return(e===`Cinzel`?[`normal`,`medium`,`bold`,`black`]:[`normal`,`bold`,`italic`,`bolditalic`]).map(e=>({value:e,label:t[e]}))}function ehe(e,t){let n=e;for(let e of t)n=n?.[e];return n}function s4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:s4(a,i,n)}}function the(e){let t=eM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function c4(e){return`values.${e.join(`.`)}`}var l4=`pt-1`,u4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function d4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Tc,{"aria-hidden":`true`}),e]})}function f4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(aI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function p4({themeId:e,from:t,onLeave:n}){let{api:r}=V(),i=_(),a=I(hb(r)),o=(0,m.useId)(),[s,c]=(0,m.useState)(void 0),[l,u]=(0,m.useState)([]),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),v=a.data,y=e===void 0?void 0:v?.themes.find(t=>t.id===e),b=e===void 0?v?.themes.find(e=>e.id===t)??v?.builtIns.find(e=>e.name===(t??`plain`))??v?.builtIns[0]:y,x=b===void 0?void 0:{name:e===void 0?`${`label`in b?b.label:b.name} copy`:b.name,values:b.values},S=s??x,C=L({mutationFn:t=>Js(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:hb(r).queryKey})}}),w=L({mutationFn:e=>Ys(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:hb(r).queryKey}),n()}});K2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:eM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:cC(S.name),...T===void 0||T.success?[]:T.error.issues.map(e=>({field:`values.${e.path.join(`.`)}`,message:e.message})),...l];if(a.error!==null)return(0,h.jsx)(g4,{children:a.error.message});if(v===void 0)return(0,h.jsx)(Y2,{});if(S===void 0)return(0,h.jsx)(g4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(LB,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),$me.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>m4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(ihe,{field:e,theme:S.values,problem:m4(E,e.path),onChange:t=>{D({...S,values:t},c4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(CS,{to:`/document-themes`,variant:`secondary`,children:`Cancel`}),errors:[C.error,w.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{C.mutate(S)}})]}),(0,h.jsx)(rhe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(Hy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var nhe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function m4(e,t){let n=c4(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function rhe({values:e}){let{api:t}=V(),[n,r]=(0,m.useState)(),[i,a]=(0,m.useState)(`busy`),[o,s]=(0,m.useState)(void 0),c=e===void 0?void 0:JSON.stringify(e);(0,m.useEffect)(()=>{if(c===void 0)return;let e=new AbortController,n=window.setTimeout(()=>{a(`busy`),Xs(t,JSON.parse(c),e.signal).then(async e=>({bytes:new Uint8Array(await e.arrayBuffer()),blob:e})).then(({bytes:t,blob:n})=>{e.signal.aborted||r({bytes:t,url:URL.createObjectURL(n)})},t=>{e.signal.aborted||(s(t instanceof Error?t.message:String(t)),a(`failed`))})},450);return()=>{window.clearTimeout(n),e.abort()}},[t,c]),(0,m.useEffect)(()=>()=>{n!==void 0&&URL.revokeObjectURL(n.url)},[n]);let l=(0,m.useCallback)(e=>{if(e===void 0){a(`idle`);return}s(e.message),a(`failed`)},[]),u=e===void 0?`Paused until the highlighted settings are fixed.`:i===`busy`?`Updating…`:i===`failed`?`The preview couldn't be made: ${o??`unknown error`}`:`A sample article with this theme. Your projects use their own text and thumbnail.`;return(0,h.jsxs)(`div`,{className:u4,children:[(0,h.jsx)(W,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(TS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open full size`]})}),(0,h.jsx)(`div`,{className:`max-h-[calc(100vh-220px)] min-h-[320px] overflow-y-auto rounded-media bg-sunken p-3`,children:(0,h.jsx)(Zme,{data:n?.bytes,label:`The sample article laid out with this theme`,onDrawn:l})}),(0,h.jsx)(`p`,{role:`status`,className:i===`failed`?`m-0 text-small text-danger`:`m-0 text-small text-ink-2`,children:u})]})}function ihe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=ehe(t,e.path),o=nhe[c4(e.path)],s=o===void 0?null:(0,h.jsx)(U,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(s4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=the(e.path);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(zB,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(zB,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(VB,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=o4(t.family);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(VB,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=a4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=o4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:a4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(VB,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(zB,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(BB,{...d,rows:8,value:Array.isArray(a)?a.join(`
272
+ `),`other titles`),children:[(0,h.jsx)(kc,{"aria-hidden":`true`,className:`size-4 shrink-0`,strokeWidth:1.75}),`Copy others`]})]})};case`schedule`:return{value:(0,h.jsxs)(`span`,{className:`flex flex-col gap-1`,children:[s,(0,h.jsx)(`span`,{className:`text-ink-2`,children:t.scheduleAt===void 0?`Not scheduled: Slopify has no slot for it. Set the date in Studio's Visibility step.`:`${H0(t.scheduleAt)}, your time. The extension types it into Studio's Visibility step; you press Schedule.`})]})};case`playlist`:return{value:r??(t.playlists.length>0?t.playlists.join(`, `):(0,h.jsx)(`span`,{className:`text-ink-3`,children:`None set (Settings → YouTube Studio).`})),actions:b(c)};default:return{value:q0(t,c)||(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Not written yet.`}),actions:b(c)}}};return(0,h.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,h.jsxs)(`section`,{"aria-label":`In the order Studio asks`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-1`,children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:`In the order Studio asks`}),(0,h.jsx)(U,{id:`project.upload.steps`,className:`-my-1`}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsxs)(`label`,{className:`flex min-h-8 cursor-pointer items-center gap-2 text-small text-ink-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:y===v.length,ref:e=>{e!==null&&(e.indeterminate=y>0&&y<v.length)},onChange:e=>g(e.currentTarget.checked?[...v]:[]),className:`size-4 shrink-0 accent-[var(--color-accent)]`}),`Select all`]})]}),(0,h.jsx)(PH,{label:`Upload steps`,className:`[&_.sl-row__actions]:flex-wrap`,children:v.map(e=>{let{value:t,actions:n}=x(e);return(0,h.jsx)(FH,{className:`items-start`,lead:(0,h.jsx)(`input`,{type:`checkbox`,checked:u.includes(e),onChange:t=>_(e,t.currentTarget.checked),className:`mt-1 size-4 shrink-0 self-start accent-[var(--color-accent)]`,"aria-label":`${V0[e]} done`}),title:V0[e],meta:(0,h.jsx)(`span`,{className:`line-clamp-4 whitespace-pre-wrap break-words text-ink`,children:t}),actions:n},e)})})]}),t.thumbnails.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Thumbnails`,children:[(0,h.jsx)(W,{as:`h3`,kicker:`Thumbnails · A/B Testing`,title:`${String(t.thumbnails.length)} ${t.thumbnails.length===1?`thumbnail`:`thumbnails`}`,className:`mb-3`}),(0,h.jsx)(u0,{label:`Thumbnails to upload`,density:`compact`,children:(t.pickable?.thumbnails??t.thumbnails).map((e,n)=>{let r=n===(t.pickable?.thumbnail??0);return(0,h.jsx)(l0,{src:`${l.origin}${e.url}`,alt:`Thumbnail ${K0(n)}`,title:r&&t.thumbnails.length>1?`${K0(n)} · upload`:K0(n),meta:e.filename,onOpen:()=>p(n),openLabel:`Open thumbnail ${K0(n)} full size`,actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[r||t.pickable===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:o,onClick:()=>a({title:t.pickable?.title??0,thumbnail:n}),children:`Use for upload`}),(0,h.jsx)(G0,{href:`${l.origin}${e.url}`,filename:e.filename})]})},e.asset)})}),(0,h.jsx)(d0,{items:(t.pickable?.thumbnails??t.thumbnails).map((e,t)=>({src:`${l.origin}${e.url}`,alt:`Thumbnail ${String.fromCharCode(65+t)}`,caption:e.filename})),index:f,onIndex:p,onClose:()=>p(null),actions:(e,n)=>{let r=(t.pickable?.thumbnails??t.thumbnails)[n];return r===void 0?null:(0,h.jsx)(G0,{href:`${l.origin}${r.url}`,filename:r.filename})}})]})]})}function K0(e){return String.fromCharCode(65+e)}function q0(e,t){switch(t){case`title`:return e.title;case`description`:return e.description;case`tags`:return epe(e.tags);case`playlist`:return e.playlists.join(`, `);default:return``}}var J0=[`studio`,`releases`],Y0=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),Gpe=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`}),X0=e=>`${Y0.format(new Date(e))}, ${Gpe.format(new Date(e))}`;function Kpe(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function qpe(e){switch(e.state){case`scheduled`:return e.checks===`ok`?{tone:`neutral`,word:`✓ Scheduled · checks clear`}:e.checks===null?{tone:`info`,word:`✓ Scheduled · checks pending`}:{tone:`failed`,word:`Scheduled · ${e.checks}`};case`filled`:return{tone:`waiting`,word:`Filled in Studio, not scheduled`};case`late`:return{tone:`failed`,word:`Late · upload now`};case`not-ready`:return{tone:`neutral`,word:`Not rendered yet`};default:return{tone:`neutral`,word:`Ready to upload`}}}function Jpe(e,t){let n=new Date(e),r=new Date(n.getFullYear(),n.getMonth(),n.getDate()-(n.getDay()+6)%7),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(t.getDay()+6)%7),a=Math.round((r.getTime()-i.getTime())/6048e5);return{key:r.toISOString(),label:a<=0?`This week`:a===1?`Next week`:`Week of ${Y0.format(r)}`}}function Ype({item:e,projectId:t,onDone:n}){let{api:r}=V(),i=_(),a=Ry(),[o,s]=(0,m.useState)(e.at===null?``:Kpe(e.at)),c=L({mutationFn:n=>ds(r,t,{short:e.short,at:n}),onSuccess:()=>{i.invalidateQueries({queryKey:J0}),n()},onError:e=>a(`The time wasn't changed: ${e.message}`,`error`)}),l=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1`,children:[(0,h.jsx)(zB,{"aria-label":`${l}: release`,type:`datetime-local`,className:`w-[200px]`,value:o,onChange:e=>s(e.currentTarget.value)}),(0,h.jsx)(B,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(new Date(o).toISOString()),children:`Save`}),e.short===0?(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:c.isPending,onClick:()=>c.mutate(null),children:`Not scheduled`}):null,(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,onClick:n,children:`Cancel`})]})}function Z0({item:e,projectId:t,editing:n,onEdit:r}){let i=qpe(e),a=n?.projectId===t&&n.short===e.short,o=e.short===0?`Long video`:`Short ${String(e.short)}`;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[o,e.at===null?``:` · goes public`]}),e.short===0?null:(0,h.jsx)(`span`,{className:`w-full truncate text-small`,title:e.title,children:e.title}),a?(0,h.jsx)(Ype,{item:e,projectId:t,onDone:()=>r(void 0)}):(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,"aria-label":`${o}: move from ${e.at===null?`no time`:X0(e.at)}`,onClick:()=>r({projectId:t,short:e.short}),children:e.at===null?`Set a time`:X0(e.at)}),(0,h.jsx)(kS,{tone:i.tone,children:i.word})]})}function Xpe({entry:e,candidates:t}){let{api:n}=V(),r=_(),i=Ry(),a=t.filter(t=>e.series===``||t.series===e.series),[o,s]=(0,m.useState)(``),c=L({mutationFn:t=>ds(n,t,{short:0,at:e.at,...e.line===null?{}:{line:e.line}}),onSuccess:()=>void r.invalidateQueries({queryKey:J0}),onError:e=>i(`The project wasn't put there: ${e.message}`,`error`)});return a.length===0?(0,h.jsxs)(`span`,{className:`text-small text-ink-3`,children:[`Free · no finished project`,e.series===``?``:` of ${e.series}`,` waits for a time`]}):(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(VB,{"aria-label":`Project for ${X0(e.at)}`,className:`w-[260px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:``,label:`Free · pick a finished project`},...a.map(e=>({value:e.id,label:e.title}))]}),(0,h.jsx)(B,{type:`button`,size:`small`,disabled:o===``||c.isPending,onClick:()=>c.mutate(o),children:`Put it here`})]})}function Zpe(){let{api:e}=V(),t=I({queryKey:J0,queryFn:()=>cs(e)}),[n,r]=(0,m.useState)();if(t.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the releases…`});if(t.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The releases didn't load: `,t.error.message,` Reload the page to try again.`]});let i=t.data;if(i.entries.length===0)return(0,h.jsx)(T1,{title:`No releases in the next two weeks`,children:`Add your week in Settings → YouTube Studio → Posting plan: each finished project then takes its next free time, and its shorts the times after it. Or open a finished project's Prepare upload.`});let a=new Date,o=new Map;for(let e of i.entries){let t=Jpe(e.at,a),n=o.get(t.key)??{label:t.label,entries:[]};n.entries.push(e),o.set(t.key,n)}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Every video and short is due `,String(i.leadHours),` hours before its release, so YouTube's copyright and ad checks finish while it is private. Change that, or the weekly times, in`,` `,(0,h.jsx)(fa,{to:`/settings`,search:{section:`studio`},children:`Settings → YouTube Studio`}),`.`]}),[...o.values()].map(e=>(0,h.jsxs)(`section`,{"aria-label":e.label,className:`flex flex-col gap-3`,children:[(0,h.jsx)(`h2`,{className:`sl-section-head__title m-0`,children:e.label}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-4 p-0`,children:e.entries.map(e=>{let t=e.items.find(e=>e.short===0),a=e.items.filter(e=>e.short>0);return(0,h.jsxs)(`li`,{className:`flex flex-col gap-2 border-b border-line pb-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:X0(e.at)}),e.series===``?null:(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.series}),e.project===null?null:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.project.id},children:e.project.title})]}),e.project===null?(0,h.jsx)(Xpe,{entry:e,candidates:i.candidates}):(0,h.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-x-4 gap-y-3`,children:[t===void 0?null:(0,h.jsx)(Z0,{item:t,projectId:e.project.id,editing:n,onEdit:r}),a.map(t=>(0,h.jsx)(Z0,{item:t,projectId:e.project?.id??``,editing:n,onEdit:r},t.short))]})]},`${e.at}-${e.project?.id??`free`}`)})})]},e.label))]})}var Q0=4;function Qpe(e){return e===`schedules`?`schedules`:e===`releases`?`releases`:`weeks`}var $0=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),e2=new Intl.DateTimeFormat(void 0,{dateStyle:`full`}),t2=new Intl.DateTimeFormat(void 0,{timeStyle:`short`}),n2=`slopify.calendar.view`;function $pe(){try{return window.localStorage.getItem(n2)===`list`?`list`:`weeks`}catch{return`weeks`}}function eme({tab:e,schedule:t,onTab:n,onSchedule:r}={}){let{api:i}=V(),a=_(),o=Dx(),[s]=(0,m.useState)(()=>OH(new Date,Q0)),[c,l]=(0,m.useState)($pe),[u,d]=(0,m.useState)(e??`weeks`),f=n===void 0?u:e??`weeks`,p=e=>{n===void 0?d(e):n(e)},[g,v]=(0,m.useState)(!1),y=I(pH(i,s.from,s.to)),b=I(qV(i)),x=I(lq(i)),S=I(ob(i)),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),D=(0,m.useMemo)(()=>new Map((x.data??[]).map(e=>[e.id,e.channelId])),[x.data]),O=(0,m.useMemo)(()=>new Map((S.data?.projects??[]).map(e=>[e.id,e.channelId])),[S.data]),k=(b.data??[]).filter(e=>o.includes(D.get(e.templateId))),A=y.data===void 0?void 0:{...y.data,runs:y.data.runs.filter(e=>o.includes(D.get(e.templateId))),projects:y.data.projects.filter(e=>o.includes(O.get(e.id)))},j=(0,m.useMemo)(()=>A===void 0?new Map:DH(A),[A]),M=A?.runs??[],ee=SH(A?.projects??[]),N=L({mutationFn:e=>e(),onSuccess:e=>w(e.ok?{tone:`info`,text:`Moved.`}:{tone:`error`,text:e.message}),onError:e=>w({tone:`error`,text:`The topic wasn't moved: ${e.message} Reload the calendar and try again.`}),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:fH}),a.invalidateQueries({queryKey:KV})])}}),P=e=>{if(e.kind!==`none`){if(e.kind===`refused`){w({tone:`error`,text:e.message});return}e.kind===`move`?N.mutate(()=>lH(i,e.scheduleId,{baseVersion:e.baseVersion,from:e.from,to:e.to})):N.mutate(()=>dH(i,e.scheduleId,{baseVersion:e.baseVersion,index:e.index,targetId:e.targetId,...e.position===void 0?{}:{position:e.position}}))}},F=(e,t)=>{let n=AH(M,e,t);if(n===void 0){w({tone:`error`,text:t===-1?`${jH(e)} is already the next topic of ${e.scheduleName}.`:`${jH(e)} is the last topic on the calendar for ${e.scheduleName}.`});return}P(kH(e,n,e2.format(new Date(n.at))))},te=e=>{l(e),f!==`weeks`&&p(`weeks`);try{window.localStorage.setItem(n2,e)}catch{}};jx({id:`calendar.add`,title:`Add to calendar`,group:`Calendar`,keywords:[`topics`,`batch`,`queue`],run:()=>v(!0)}),jx({id:`calendar.schedules`,title:`Show the schedules`,group:`Calendar`,keywords:[`edit`,`recurring`,`pause`,`resume`],run:()=>p(`schedules`)}),oS(tS.addToCalendar,()=>v(!0)),jx({id:`calendar.weeks`,title:`Show the calendar as weeks`,group:`Calendar`,run:()=>te(`weeks`)}),jx({id:`calendar.list`,title:`Show the calendar as a list`,group:`Calendar`,run:()=>te(`list`)});let ne=k.reduce((e,t)=>e+(t.deletedAt===null?t.items.length:0),0),re=C?.text??y.error?.message??b.error?.message,ie=wH(new Date),ae=(b.data??[]).filter(e=>e.deletedAt===null).length;return(0,h.jsxs)(`div`,{"data-tour":`calendar`,children:[(0,h.jsx)(XK,{title:`Calendar`,meta:`${o.channel?.name??`Every channel`} · ${String(M.length)} scheduled ${M.length===1?`run`:`runs`} in the next ${String(Q0)} weeks · ${String(ne)} ${ne===1?`topic`:`topics`} queued`,actions:f===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Vb,{label:`Calendar view`,tip:`planning.calendar.view`,value:c,onChange:te,options:[{value:`weeks`,label:`Weeks`},{value:`list`,label:`List`}]}),(0,h.jsxs)(B,{variant:`primary`,onClick:()=>v(!0),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Add to calendar`]})]}):void 0}),(0,h.jsx)(C1,{items:[{id:`weeks`,label:`Coming weeks`},{id:`releases`,label:`Releases`},{id:`schedules`,label:`Schedules`,...b.data===void 0?{}:{badge:String(ae)}}],value:f,onChange:p,label:`Calendar sections`,idPrefix:`calendar`,className:`mb-6`}),(0,h.jsx)(w1,{idPrefix:`calendar`,id:`releases`,active:f===`releases`,children:f===`releases`?(0,h.jsx)(Zpe,{}):null}),(0,h.jsx)(w1,{idPrefix:`calendar`,id:`schedules`,active:f===`schedules`,children:f===`schedules`?(0,h.jsx)(qfe,{pickedId:t,onPick:r}):null}),(0,h.jsxs)(w1,{idPrefix:`calendar`,id:`weeks`,active:f===`weeks`,children:[(0,h.jsx)(v1,{tone:C?.tone===`info`?`info`:re?`error`:`info`,className:`mb-3`,children:re}),(0,h.jsxs)(b1,{split:`aside`,className:`mb-6`,children:[(0,h.jsx)(x1,{label:`Needs you`,children:ee.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Nothing needs you right now.`}):(0,h.jsxs)(`section`,{"aria-label":`Needs you`,children:[(0,h.jsx)(W,{title:`Needs you`,meta:xH(ee)}),(0,h.jsx)(PH,{label:`Needs you`,children:ee.map(e=>(0,h.jsx)(a2,{project:e},e.id))})]})}),(0,h.jsx)(x1,{as:`aside`,label:`Suggested topics`,children:(0,h.jsx)(bfe,{schedules:k})})]}),(0,h.jsxs)(`section`,{"aria-label":`Coming weeks`,className:`flex min-w-0 flex-col gap-4`,children:[y.isPending?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Loading the calendar…`}):c===`weeks`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Drag a topic to another day to change when it runs, or onto another schedule's run to move it there. With the keyboard: focus a topic and press Alt+← or Alt+→.`}),EH(new Date(s.from),Q0).map(e=>(0,h.jsx)(`div`,{className:`sl-cal-week`,children:e.map(e=>{let t=wH(e),n=j.get(t);return(0,h.jsx)(tme,{date:e,today:t===ie,day:n,dragging:T,busy:N.isPending,onDragStart:E,onDragEnd:()=>E(null),onDrop:t=>{T!==null&&(P(kH(T,t,e2.format(e))),E(null))},onStep:F},t)})},wH(e[0]??new Date)))]}):(0,h.jsx)(rme,{days:j,busy:N.isPending,onStep:F,schedules:k,onTransfer:(e,t)=>{e.index!==null&&P({kind:`transfer`,scheduleId:e.scheduleId,baseVersion:e.scheduleVersion,index:e.index,targetId:t,position:void 0})}}),A!==void 0&&A.queued.length>0?(0,h.jsxs)(`section`,{"aria-label":`Batch queue`,children:[(0,h.jsx)(W,{title:`Batch queue`,meta:`${String(A.queued.length)} waiting to start`,info:`play.queue`}),(0,h.jsx)(PH,{label:`Batch queue`,children:A.queued.toSorted((e,t)=>e.position-t.position).map((e,t)=>{let n=A.projects.find(t=>t.id===e.projectId)?.state===`paused`;return(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.title}),meta:`${String(t+1)} in line`,actions:(0,h.jsx)(OS,{tone:n?`waiting`:e.state===`active`?`running`:`off`,children:n?`Paused`:e.state===`active`?`Running now`:`Waiting its turn`})},e.projectId)})})]}):null]})]}),(0,h.jsx)(hH,{open:g,onOpenChange:v,schedules:k})]})}function tme({date:e,today:t,day:n,dragging:r,busy:i,onDragStart:a,onDragEnd:o,onDrop:s,onStep:c}){let[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(!1),p=n?.runs??[],g=n?.projects??[],_=d?g:g.slice(0,r2),v=()=>p.find(e=>e.scheduleId===r?.scheduleId)??p[0];return(0,h.jsxs)(`section`,{"aria-label":e2.format(e),className:z(`sl-cal-day`,t&&`sl-cal-day--today`,l&&`sl-cal-day--over`),onDragOver:e=>{r!==null&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,u(!0))},onDragLeave:()=>u(!1),onDrop:e=>{e.preventDefault(),u(!1),s(v())},children:[(0,h.jsx)(`div`,{className:`sl-kicker`,children:t?`Today · ${$0.format(e)}`:$0.format(e)}),p.map(e=>(0,h.jsx)(nme,{run:e,busy:i,onDragStart:a,onDragEnd:o,onDrop:t=>{t.preventDefault(),t.stopPropagation(),u(!1),s(e)},onStep:c},`${e.scheduleId}-${e.at}`)),_.map(e=>{let t=bH(e);return(0,h.jsxs)(`div`,{className:`sl-cal-item sl-cal-item--project ${MH}`,children:[(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},className:`text-small font-semibold ${NH}`,children:e.title}),(0,h.jsx)(OS,{tone:t.tone,children:t.word})]},e.id)}),g.length>r2?(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-expanded":d,className:`self-start`,onClick:()=>f(e=>!e),children:d?`Show fewer`:`+${String(g.length-r2)} more`}):null]})}var r2=3;function nme({run:e,busy:t,onDragStart:n,onDragEnd:r,onDrop:i,onStep:a}){let o=e.index!==null&&!t,s=jH(e);return(0,h.jsxs)(`article`,{tabIndex:e.index===null?void 0:0,"aria-label":`${s}, ${t2.format(new Date(e.at))}, ${e.scheduleName}${e.index===null?``:`. Alt+arrow keys move it.`}`,draggable:o,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,s),n(e)},onDragEnd:r,onDragOver:e=>e.preventDefault(),onDrop:i,onKeyDown:t=>{o&&t.altKey&&(t.key===`ArrowLeft`||t.key===`ArrowUp`?(t.preventDefault(),a(e,-1)):(t.key===`ArrowRight`||t.key===`ArrowDown`)&&(t.preventDefault(),a(e,1)))},className:z(`sl-cal-item`,o&&`sl-cal-item--movable`),children:[(0,h.jsx)(`span`,{className:`text-label text-ink-3 tabular-nums`,children:t2.format(new Date(e.at))}),(0,h.jsx)(`b`,{className:z(`text-small`,e.topic===null&&`font-normal text-ink-2`),children:s}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.scheduleName}),e.paused?(0,h.jsx)(OS,{tone:`waiting`,children:`Paused`}):e.topicSource===`held`?(0,h.jsx)(OS,{tone:`info`,children:`Needs a topic`}):e.prepared===null?(0,h.jsx)(OS,{tone:`off`,children:`Queued`}):(0,h.jsx)(OS,{tone:`info`,children:`Prepared`}),(0,h.jsx)(i2,{run:e,compact:!0})]})}function i2({run:e,compact:t=!1}){let{api:n}=V(),r=_(),[i,a]=(0,m.useState)(),o=L({mutationFn:async()=>{if(e.topic===null)throw Error(`This run has no topic to prepare yet.`);let t=await iH(n,e.scheduleId,e.topic);if(!t.ok)throw Error(t.message);return t.value},onSuccess:()=>{a(void 0),r.invalidateQueries({queryKey:fH}),r.invalidateQueries({queryKey:[`projects`]})},onError:e=>a(e.message)});return e.prepared===null?e.index===null||e.topic===null||e.topicSource!==`queued`?null:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,variant:t?`quiet`:`secondary`,disabled:o.isPending,onClick:e=>{e.stopPropagation(),o.mutate()},children:o.isPending?`Preparing…`:`Prepare`}),i===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-label text-danger`,children:i})]}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.prepared},size:`small`,variant:`quiet`,children:t?`Open`:`Open prepared`})}function a2({project:e}){let t=bH(e);return(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(OS,{tone:t.tone,children:t.word}),t.action===void 0?null:t.action.kind===`upload`?(0,h.jsx)(B0,{projectId:e.id,ready:!0}):(0,h.jsx)(CS,{to:`/projects/$projectId`,params:{projectId:e.id},size:`small`,variant:`secondary`,children:t.action.label})]})})}function rme({days:e,busy:t,schedules:n,onStep:r,onTransfer:i}){let a=[...e.values()].sort((e,t)=>e.key.localeCompare(t.key));if(a.length===0)return(0,h.jsxs)(`p`,{className:`m-0 text-ink-2`,children:[`Nothing is planned for the next `,Q0,` weeks. Add topics with Add to calendar, or create a schedule on the`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`},children:`Schedules`}),` `,`tab.`]});let o=n.filter(e=>e.deletedAt===null&&(e.status===`active`||e.status===`paused`));return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,...zb,children:[(0,h.jsxs)(`p`,{className:`m-0 flex items-center gap-1 text-small text-ink-2`,children:[`Move a topic earlier, later or to another schedule from its row.`,(0,h.jsx)(U,{id:`planning.calendar.move`,className:`-my-1`})]}),a.map(e=>(0,h.jsxs)(`section`,{"aria-label":e2.format(e.date),children:[(0,h.jsx)(W,{title:e2.format(e.date),as:`h3`}),(0,h.jsxs)(PH,{label:`Planned on ${e2.format(e.date)}`,children:[e.runs.map(e=>{let n=jH(e),a=o.filter(t=>t.id!==e.scheduleId);return(0,h.jsx)(FH,{title:n,meta:`${t2.format(new Date(e.at))} · ${e.scheduleName}${e.templateName===null?``:` · ${e.templateName}`}${e.paused?` · Paused`:``}`,actions:e.index===null?void 0:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(i2,{run:e}),(0,h.jsx)(Py,{size:`small`,label:`Move ${n} earlier`,disabled:t,onClick:()=>r(e,-1),children:(0,h.jsx)(_c,{"aria-hidden":`true`,strokeWidth:1.75})}),(0,h.jsx)(Py,{size:`small`,label:`Move ${n} later`,disabled:t,onClick:()=>r(e,1),children:(0,h.jsx)(mc,{"aria-hidden":`true`,strokeWidth:1.75})}),a.length===0?null:(0,h.jsxs)(`select`,{"aria-label":`Move ${n} to another schedule`,className:`sl-select h-8 w-auto text-small`,value:``,disabled:t,onChange:t=>{t.target.value!==``&&i(e,t.target.value)},children:[(0,h.jsx)(`option`,{value:``,children:`Move to…`}),a.map(e=>(0,h.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})},`${e.scheduleId}-${e.at}`)}),e.projects.map(e=>(0,h.jsx)(a2,{project:e},e.id))]})]},e.key))]})}var ime=_j.map(e=>({value:e,label:vj[e]}));function ame({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=L({mutationFn:n=>bx(t,e.id,n),onSuccess:async e=>{r(`YouTube AI disclosure set to ${vj[e.aiDisclosure]}.`,`success`),n.setQueryData(ax(e.id),t=>typeof t==`object`&&t&&`channel`in t?{...t,channel:{...t.channel,aiDisclosure:e.aiDisclosure}}:t),await n.invalidateQueries({queryKey:ix,exact:!0})}});return(0,h.jsxs)(`section`,{"aria-label":`YouTube AI disclosure`,className:`mb-6 max-w-3xl border-b border-line pb-5`,children:[(0,h.jsx)(LB,{label:`YouTube AI disclosure`,tip:`planning.channel.ai-disclosure`,help:`Mark voices in Settings → Voices and Image prompts in Library → Prompts.`,children:(0,h.jsx)(VB,{value:i.isPending?i.variables:e.aiDisclosure,options:ime,disabled:i.isPending,onChange:e=>{let t=_j.find(t=>t===e.currentTarget.value);t!==void 0&&i.mutate(t)},className:`max-w-[260px]`})}),(0,h.jsx)(v1,{tone:`error`,children:i.error?`Couldn't save the YouTube AI disclosure: ${i.error.message}`:void 0})]})}function o2({value:e,onChange:t,inherited:n,label:r=`Language`,error:i,disabled:a=!1,tip:o=`play.language`}){let s=e??n?.language;return(0,h.jsx)(LB,{label:r,tip:o,help:ome(s),error:i,children:(0,h.jsxs)(VB,{"data-play-field":`language`,value:e??(n===void 0?`en`:``),disabled:a,onChange:e=>t(e.target.value===``?void 0:MO.parse(e.target.value)),children:[n===void 0?null:(0,h.jsxs)(`option`,{value:``,children:[n.label,` (`,NO(n.language).name,`)`]}),jO.map(e=>(0,h.jsx)(`option`,{value:e.code,children:e.native===e.name?e.name:`${e.native} · ${e.name}`},e.code))]})})}function ome(e){let t=NO(e);if(t.code===`en`)return`Everything is written and timed in English.`;let n=`The article, narration, YouTube description and Shorts titles are written in ${t.name}; pick a voice that speaks it.`,r=PO(t.code);return r===void 0?`${n} Captions are timed word by word with a free 248 MB model, downloaded the first time a ${t.name} project makes captions.`:`${n} ${r}`}function sme({rows:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,h.jsxs)(`section`,{"aria-label":`Channel links`,...zb,children:[(0,h.jsx)(W,{title:`Channel links`,meta:`Write a link's name in braces in a description, such as {{Patreon}}.`,info:`planning.links.named`}),e.length===0?(0,h.jsx)(`p`,{className:`m-0 border-y border-line py-4 text-ink-2`,children:`No channel links yet. Add one, then write its name in braces in a description.`}):(0,h.jsx)(`ul`,{"aria-label":`Channel links`,className:`sl-list m-0 list-none p-0`,children:e.map((r,i)=>(0,h.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,1fr)] items-center gap-2 border-b border-line py-3 md:grid-cols-[220px_minmax(0,1fr)_auto]`,children:[(0,h.jsx)(zB,{"aria-label":`Name of link ${String(i+1)}`,placeholder:`Patreon`,value:r.name,onChange:e=>n(i,{name:e.currentTarget.value})}),(0,h.jsx)(zB,{"aria-label":`Address of link ${String(i+1)}`,type:`url`,placeholder:`https://`,value:r.url,onChange:e=>n(i,{url:e.currentTarget.value})}),(0,h.jsxs)(B,{variant:`quiet`,size:`small`,className:`justify-self-start`,"aria-label":`Remove link ${String(i+1)}`,onClick:()=>t(e.filter((e,t)=>t!==i)),children:[(0,h.jsx)($c,{"aria-hidden":`true`,className:`size-[14px]`}),`Remove`]})]},i))}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsxs)(B,{onClick:()=>t([...e,{name:``,url:``}]),children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-[14px]`}),`Add link`]})})]})}function cme(){return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsx)(W,{title:`Named links`,info:`planning.links.named`}),(0,h.jsx)(`p`,{className:`m-0 max-w-[60ch] text-ink-2`,children:`Each channel keeps its own links now, on its Brand tab under Channel links. Links saved here before fill the default channel's descriptions until you save its Brand tab.`}),(0,h.jsx)(`div`,{className:`mt-3`,children:(0,h.jsx)(CS,{to:`/channels/$channelId`,params:{channelId:tx},children:`Open the default channel's links`})})]})}function s2({value:e,inherit:t,sources:n,offerNone:r,problem:i,file:a,fieldPrefix:o=`ambientBed`,onChange:s}){let c=e!==void 0&&e.source!==`none`,l={level:e?.level??String(qk.levelDb),fadeIn:e?.fadeIn??String(qk.fadeInSeconds),tail:e?.tail??String(qk.tailSeconds)},u=e=>{if(e===``)s(void 0);else if(e===`none`)s({source:`none`,...l});else{let t=n.find(t=>t===e);t!==void 0&&s({source:t,...l})}},d=(t,n,r,a)=>e===void 0||!c?null:(0,h.jsx)(LB,{label:n,help:r,tip:a,error:i(t),children:(0,h.jsx)(zB,{"data-play-field":`${o}.${t}`,type:`text`,inputMode:`decimal`,className:`sl-input--number`,value:e[t],onChange:n=>s({...e,[t]:n.target.value})})});return(0,h.jsxs)(`div`,{className:`sl-fields`,children:[(0,h.jsx)(LB,{label:`Ambient sound`,tip:`project.ambient.source`,error:i(`source`),children:(0,h.jsxs)(VB,{"data-play-field":`${o}.source`,value:e?.source??``,onChange:e=>u(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:t}),r?(0,h.jsx)(`option`,{value:`none`,children:`None`}):null,n.map(e=>(0,h.jsx)(`option`,{value:e,children:Kk[e]},e))]})}),e?.source===`upload`?a:null,c?(0,h.jsxs)(`div`,{className:`contents`,children:[d(`level`,`Level (dB)`,`-40 to -6; 0 is about as loud as the voice.`,`project.ambient.level`),d(`fadeIn`,`Fade in (seconds)`,`0 to 30.`,`project.ambient.fade-in`),d(`tail`,`Tail after the narration (seconds)`,`0 to 30, fading out.`,`project.ambient.tail`)]}):null]})}function lme({value:e,onChange:t}){let n=Qk(e),r=n===void 0?[]:Yk(n);return(0,h.jsx)(s2,{value:e,inherit:`Not set`,sources:Wk,offerNone:!1,fieldPrefix:`brand.ambientBed`,problem:e=>r.find(t=>t.field===e)?.message,onChange:t})}function ume(e){return e.ambientBed===void 0?void 0:Zk(e.ambientBed)}function dme(e){let t=Qk(e);return t===void 0||t.source===`upload`?{brand:{},blocked:!1}:{brand:{ambientBed:{...t,source:t.source}},blocked:Yk(t).length>0}}var c2=[`captionFontId`,`captionColor`,`captionOutlineColor`,`titleFontId`,`titleColor`,`intro`,`outro`,`endScreenText`,`documentTheme`,`language`];function fme(e){return Object.fromEntries(c2.map(t=>[t,e[t]??``]))}function pme({channel:e}){let{api:t}=V(),n=_(),r=Ry(),i=I({queryKey:eN,queryFn:()=>tN(t)}),a=I(mb(t)),o=I(hb(t)),[s,c]=(0,m.useState)(e.name),[l,u]=(0,m.useState)(e.seriesBrief),[d,f]=(0,m.useState)(fme(e.brand)),[p,g]=(0,m.useState)(ume(e.brand)),v=dme(p),y=I({queryKey:H.channelLinks,queryFn:()=>Ls(t),enabled:e.isDefault&&e.brand.links===void 0}),[b,x]=(0,m.useState)(),S=b??e.brand.links??y.data??[],C=b!==void 0||e.brand.links!==void 0||(y.data?.length??0)>0,w=L({mutationFn:()=>dx(t,e.id,{name:s,seriesBrief:l,brand:{...Object.fromEntries(c2.flatMap(e=>d[e].trim()===``?[]:[[e,d[e].trim()]])),...v.brand,...C?{links:S}:{}},baseVersion:e.version}),onSuccess:async e=>{r(`Channel saved.`,`success`),n.setQueryData(ax(e.id),t=>typeof t==`object`&&t?{...t,channel:e}:t),await Promise.all([n.invalidateQueries({queryKey:ix}),n.invalidateQueries({queryKey:H.channelLinks})])}}),T=e=>t=>f({...d,[e]:t}),E=(i.data?.fonts??[]).map(e=>({value:e.id,label:e.name})),D=e=>(a.data?.entries??[]).filter(t=>t.category===e).map(e=>({value:e.name,label:e.name})),O=[...(o.data?.builtIns??[]).map(e=>({value:e.name,label:e.label})),...(o.data?.themes??[]).map(e=>({value:e.id,label:e.name}))];return(0,h.jsxs)(`form`,{"aria-label":`Brand kit`,onSubmit:e=>{e.preventDefault(),w.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid max-w-3xl grid-cols-1 gap-5`,children:[(0,h.jsx)(LB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(zB,{value:s,maxLength:200,required:!0,onChange:e=>c(e.target.value)})}),(0,h.jsx)(LB,{label:`Series brief`,tip:`planning.channel.brief`,help:`Topic generation reads it for this channel's schedules.`,children:(0,h.jsx)(BB,{rows:4,value:l,maxLength:1e4,onChange:e=>u(e.target.value)})}),(0,h.jsx)(W,{title:`Brand kit`,meta:`Fills what a template leaves at its default. Blank fields add nothing.`,info:`planning.channel.brand-kit`,className:`mt-2 border-t border-line pt-6`}),(0,h.jsx)(`section`,{"aria-label":`Language`,className:`max-w-md`,children:(0,h.jsx)(o2,{label:`Language of new projects`,tip:`planning.channel.language`,value:d.language===``?void 0:d.language,inherited:{label:`Not set`,language:void 0},onChange:e=>T(`language`)(e??``)})}),(0,h.jsxs)(`section`,{"aria-label":`Captions`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Caption font`,tip:`planning.channel.brand.caption-font`,value:d.captionFontId,options:E,onPick:T(`captionFontId`)}),(0,h.jsx)(u2,{label:`Caption colour`,tip:`planning.channel.brand.caption-colour`,value:d.captionColor,onChange:T(`captionColor`)}),(0,h.jsx)(u2,{label:`Caption outline`,tip:`planning.channel.brand.caption-outline`,value:d.captionOutlineColor,onChange:T(`captionOutlineColor`)})]}),(0,h.jsxs)(`section`,{"aria-label":`Chapter cards and end screen`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Title font`,tip:`planning.channel.brand.font`,value:d.titleFontId,options:E,onPick:T(`titleFontId`)}),(0,h.jsx)(u2,{label:`Title colour`,tip:`planning.channel.brand.title-colour`,value:d.titleColor,onChange:T(`titleColor`)}),(0,h.jsx)(LB,{label:`End screen text`,tip:`planning.channel.brand.end-screen`,help:`Shown over the last 5 seconds.`,children:(0,h.jsx)(zB,{value:d.endScreenText,maxLength:200,placeholder:`Subscribe for more`,onChange:e=>T(`endScreenText`)(e.target.value)})})]}),(0,h.jsxs)(`section`,{"aria-label":`Intro, outro and document`,className:`grid grid-cols-1 gap-4 min-[700px]:grid-cols-3`,children:[(0,h.jsx)(l2,{label:`Intro`,tip:`planning.channel.brand.intro`,value:d.intro,options:D(`intro`),onPick:T(`intro`)}),(0,h.jsx)(l2,{label:`Outro`,tip:`planning.channel.brand.outro`,value:d.outro,options:D(`outro`),onPick:T(`outro`)}),(0,h.jsx)(l2,{label:`Document theme`,tip:`planning.channel.brand.document-theme`,value:d.documentTheme,options:O,onPick:T(`documentTheme`)})]}),(0,h.jsx)(lme,{value:p,onChange:g}),(0,h.jsx)(`div`,{className:`border-t border-line pt-6`,children:(0,h.jsx)(sme,{rows:S,onChange:x})})]}),(0,h.jsx)(y1,{status:(0,h.jsx)(v1,{tone:w.error?`error`:`info`,children:w.error?.message??(w.isPending?`Saving…`:void 0)}),children:(0,h.jsx)(B,{type:`submit`,variant:`primary`,disabled:w.isPending||s.trim()===``||v.blocked,disabledReason:s.trim()===``?`Give the channel a name`:`Fix the ambient sound settings above`,children:`Save channel`})})]})}function l2({label:e,tip:t,value:n,options:r,onPick:i}){return(0,h.jsx)(LB,{label:e,tip:t,children:(0,h.jsxs)(VB,{value:n,onChange:e=>i(e.target.value),children:[(0,h.jsx)(`option`,{value:``,children:`Not set`}),n!==``&&!r.some(e=>e.value===n)?(0,h.jsxs)(`option`,{value:n,children:[n,` (no longer in the library)`]}):null,r.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))]})})}function u2({label:e,tip:t,value:n,onChange:r}){let i=/^#[0-9a-fA-F]{6}$/.test(n);return(0,h.jsx)(LB,{label:e,tip:t,...n!==``&&!i?{error:`Write the colour as # and six hex digits.`}:{},children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-6 shrink-0 rounded-control border border-line-strong`,style:{background:i?n:`transparent`}}),(0,h.jsx)(zB,{value:n,placeholder:`#FFFFFF`,maxLength:7,onChange:e=>r(e.target.value)})]})})}function d2(e,t){return e.languages===void 0||e.languages.includes(NO(t).code)}function mme(e,t,n,r){return n?e:e.filter(e=>d2(e,t)||e.voiceId===r)}function hme(e,t){if(e===void 0||d2(e,t))return;let n=NO(t).name,r=(e.languages??[]).map(e=>NO(e).code===e?NO(e).name:e);return`${e.name} is listed for ${r.join(`, `)}, not ${n}, so it may read the ${n} narration with the wrong accent. Pick a ${n} voice under Narration, or correct the voice's languages in Settings → Voices.`}function f2(e,t,n){let[r,i]=(0,m.useState)(!1),a=mme(e,t,r,n);return{listed:a,hidden:e.length-a.length,showAll:r,setShowAll:i}}function p2({language:e,voice:t,hidden:n,showAll:r,onShowAll:i}){let a=(0,m.useId)(),o=hme(t,e);return n===0&&!r&&o===void 0?null:(0,h.jsxs)(`div`,{className:`col-span-full grid gap-1`,children:[n>0||r?(0,h.jsxs)(`span`,{className:`flex min-h-8 items-center gap-1`,...zb,children:[(0,h.jsxs)(`label`,{htmlFor:a,className:`flex items-center gap-2 text-small`,children:[(0,h.jsx)(`input`,{id:a,type:`checkbox`,checked:r,onChange:e=>i(e.target.checked)}),`Show all voices`,r?``:` (${String(n)} listed for other languages than ${NO(e).name})`]}),(0,h.jsx)(U,{id:`play.show-all-voices`})]}):null,o===void 0?null:(0,h.jsx)(`p`,{role:`status`,className:`m-0 text-small text-ink-2`,children:o})]})}function gme({channelId:e,member:t,open:n,onClose:r,onCreated:i}){let{api:a}=V(),o=_(),[s,c]=(0,m.useState)(t?.kind??`character`),[l,u]=(0,m.useState)(t?.name??``),[d,f]=(0,m.useState)(t?.aliases??[]),[p,g]=(0,m.useState)(``),[v,y]=(0,m.useState)(t?.description??``),[b,x]=(0,m.useState)(t?.voice),[S,C]=(0,m.useState)(t?.host===!0),w=()=>Promise.all([o.invalidateQueries({queryKey:ax(e)}),o.invalidateQueries({queryKey:ix})]),T=L({mutationFn:async()=>{let n={kind:s,name:l.trim(),aliases:d,description:v,voice:b!==void 0&&b.provider!==``&&b.model!==``&&b.voice!==``?b:null,host:S};return t===void 0?px(a,e,crypto.randomUUID(),n):mx(a,t.id,{...n,baseVersion:t.version})},onSuccess:async e=>{await w(),t===void 0&&i(e.id)}}),E=()=>{let e=p.trim();e===``||d.some(t=>t.toLowerCase()===e.toLowerCase())||(f([...d,e]),g(``))};return n?(0,h.jsxs)(`section`,{"aria-label":t===void 0?`Add to cast`:`Edit ${t.name}`,children:[(0,h.jsx)(W,{kicker:t===void 0?`New cast member`:rx[t.kind],title:t===void 0?`Add to cast`:t.name,meta:t===void 0?`Name it first, then give it reference pictures.`:`Used whenever a title or an image brief names it or one of its aliases.`,children:(0,h.jsx)(B,{variant:`quiet`,size:`small`,onClick:r,children:`Close`})}),t!==void 0&&!t.images.some(e=>e.state===`ready`)?(0,h.jsx)(`p`,{className:`m-0 mt-2 text-small text-waiting`,children:`No picture yet, so it is not sent with any image. Upload or generate one below.`}):null,(0,h.jsxs)(`form`,{id:`cast-member-form`,"aria-label":`Cast member`,className:`mt-4 flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),l.trim()!==``&&T.mutate()},children:[(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-[160px_minmax(0,1fr)]`,children:[(0,h.jsx)(LB,{label:`Kind`,tip:`planning.cast.kind`,children:(0,h.jsx)(VB,{value:s,onChange:e=>c(nx.find(t=>t===e.target.value)??`character`),options:nx.map(e=>({value:e,label:rx[e]}))})}),(0,h.jsx)(LB,{label:`Name`,tip:`planning.cast.name`,children:(0,h.jsx)(zB,{value:l,maxLength:200,required:!0,onChange:e=>u(e.target.value)})})]}),(0,h.jsx)(LB,{label:`Aliases`,tip:`planning.cast.aliases`,help:`Press Enter to add each one.`,children:(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsx)(zB,{value:p,maxLength:200,placeholder:`Another name, such as the Last Pharaoh`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),E())}}),(0,h.jsxs)(B,{onClick:E,disabled:p.trim()===``,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add alias`]})]})}),d.length>0?(0,h.jsx)(`ul`,{"aria-label":`Aliases added`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:d.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(AS,{removeLabel:`Remove alias ${e}`,onRemove:()=>f(d.filter(t=>t!==e)),children:e})},e))}):null,(0,h.jsx)(LB,{label:`Description for the image model`,tip:`planning.cast.description`,children:(0,h.jsx)(BB,{rows:3,value:v,maxLength:2e3,placeholder:`What they look like, in a sentence.`,onChange:e=>y(e.target.value)})}),(0,h.jsx)(vme,{channelId:e,value:b,onChange:x}),(0,h.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,h.jsx)(Bb,{label:`One of the channel's hosts`,tip:`planning.cast.host`,checked:S,onChange:C}),S&&(b===void 0||b.voice===``)?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`A host joins new podcasts and interviews only with a voice. Pick one under Voice above.`}):null]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(v1,{tone:T.error?`error`:`info`,children:T.error?.message??(T.isPending?`Saving…`:T.isSuccess?`Saved.`:void 0)}),(0,h.jsx)(B,{type:`submit`,form:`cast-member-form`,variant:t===void 0?`primary`:`secondary`,disabled:T.isPending||l.trim()===``,children:t===void 0?`Add to cast`:`Save`})]})]}),t===void 0?null:(0,h.jsx)(_me,{channelId:e,member:t})]}):null}function _me({channelId:e,member:t}){let{api:n}=V(),r=_(),i=I(db(n)),a=(0,m.useRef)(null),o=(0,m.useRef)(null),[s,c]=(0,m.useState)(``),[l,u]=(0,m.useState)(``),[d,f]=(0,m.useState)(`${t.name}${t.description.trim()?`, ${t.description.trim()}`:``}. A clear reference picture on a plain background, the whole ${t.kind===`place`?`place`:t.kind===`object`?`object`:`figure`} in view.`),p=()=>Promise.all([r.invalidateQueries({queryKey:ax(e)}),r.invalidateQueries({queryKey:ix})]),g=L({mutationFn:e=>gx(n,t.id,e),onSettled:p}),v=L({mutationFn:()=>_x(n,t.id,{prompt:d,provider:s,model:l}),onSettled:p}),y=L({mutationFn:e=>vx(n,t.id,e),onSettled:p}),b=g.error??v.error??y.error,x=t.images.flatMap((e,t)=>e.state===`ready`&&e.sha256!==null?[{id:e.id,number:t+1,src:xx(n,e.sha256)}]:[]),[S,C]=(0,m.useState)(null);return(0,h.jsxs)(`section`,{"aria-label":`Reference pictures`,className:`mt-6`,children:[(0,h.jsx)($K,{className:`mb-6`}),(0,h.jsx)(W,{as:`h3`,title:`Reference pictures`,meta:`Sent with every image whose brief, or the video's title, names ${t.name}.`,info:`planning.cast.pictures`}),t.images.length>0?(0,h.jsx)(u0,{list:!0,density:`compact`,label:`Pictures of ${t.name}`,className:`mt-3`,children:t.images.map((e,r)=>(0,h.jsxs)(`li`,{className:`min-w-0`,children:[(0,h.jsx)(l0,{aspect:`square`,alt:`${t.name}, reference ${String(r+1)}`,...e.state===`ready`&&e.sha256!==null?{src:xx(n,e.sha256)}:{},...e.state===`generating`?{generating:`Making the picture…`}:{},onOpen:()=>C(x.findIndex(t=>t.id===e.id)),openLabel:`Open picture ${String(r+1)} of ${t.name} full size`,...e.state===`failed`?{badge:(0,h.jsx)(kS,{tone:`failed`,children:`Failed`})}:{},actionsShown:!0,actions:(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Delete picture ${String(r+1)} of ${t.name}`,disabled:y.isPending||e.state===`generating`,disabledReason:`Wait until the picture is made`,onClick:()=>y.mutate(e.id),children:`Delete`})}),e.state===`failed`&&e.error?(0,h.jsx)(yme,{error:e.error,retry:s===``||l===``||d.trim()===``?void 0:{run:()=>v.mutate(),busy:v.isPending},onReword:()=>o.current?.focus()}):null]},e.id))}):(0,h.jsx)(`p`,{className:`m-0 mt-3 text-small text-ink-3`,children:`No pictures yet.`}),(0,h.jsx)(d0,{items:x.map(e=>({src:e.src,alt:`${t.name}, reference ${String(e.number)}`})),index:S,onIndex:C,onClose:()=>C(null),actions:(e,n)=>{let r=x[n];return r===void 0?null:(0,h.jsx)(TS,{href:r.src,download:!0,size:`small`,"aria-label":`Download picture ${String(r.number)} of ${t.name}`,children:`Download`})}}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg`,className:`sr-only`,tabIndex:-1,"aria-hidden":`true`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&g.mutate(t)}}),(0,h.jsx)(B,{disabled:g.isPending,onClick:()=>a.current?.click(),children:`Upload a picture`}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`PNG or JPEG, up to 10 MB.`})]}),(0,h.jsxs)(`div`,{className:`mt-4 flex flex-col gap-4`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,...zb,children:[(0,h.jsxs)(`p`,{className:`sl-kicker m-0 flex items-center gap-1`,children:[`Make a picture`,(0,h.jsx)(U,{id:`planning.cast.generate`,className:`-my-1`})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Image provider`,family:`image`,providers:i.data?.providers??[],value:s,problem:void 0,onPick:e=>{c(e),u(``)}}),(0,h.jsx)(tV,{label:`Image model`,provider:s,value:l,problem:void 0,onPick:u})]})]}),(0,h.jsx)(LB,{label:`Picture to make`,tip:`planning.cast.picture-prompt`,children:(0,h.jsx)(BB,{ref:o,rows:3,value:d,maxLength:4e3,onChange:e=>f(e.target.value)})}),(0,h.jsx)(`div`,{children:(0,h.jsx)(B,{disabled:v.isPending||s===``||l===``||d.trim()===``,disabledReason:`Pick an image provider and model, and describe the picture`,onClick:()=>v.mutate(),children:`Generate a picture`})})]}),(0,h.jsx)(v1,{tone:b?`error`:`info`,className:`mt-2`,children:b?.message??(g.isPending?`Uploading…`:v.isSuccess?`The picture is being made; it appears here when it is ready.`:void 0)})]})}function vme({channelId:e,value:t,onChange:n}){let{api:r}=V(),i=I(db(r)),a=I(fb(r)),o=I(lx(r,e)).data?.channel.brand.language??`en`,s=t??{provider:``,model:``,voice:``},c=(a.data?.voices??[]).filter(e=>e.provider===s.provider),l=f2(c,o,s.voice||void 0),u=l.listed;return(0,h.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-3 border-0 border-t border-line p-0 pt-4`,...zb,children:[(0,h.jsxs)(`legend`,{className:`sl-kicker flex items-center gap-1`,children:[`Voice`,(0,h.jsx)(U,{id:`planning.cast.voice`,label:`Cast voice`,className:`-my-1`})]}),(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`For multi-voice runs: pick this member under Speakers on Play.`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 min-[600px]:grid-cols-2`,children:[(0,h.jsx)(eV,{label:`Voice provider`,family:`tts`,providers:i.data?.providers??[],value:s.provider,problem:void 0,onPick:e=>n(e===``?void 0:{provider:e,model:``,voice:``})}),(0,h.jsx)(tV,{label:`Voice model`,provider:s.provider,value:s.model,problem:void 0,onPick:e=>n({...s,model:e})}),(0,h.jsx)(ZB,{label:`Voice`,value:s.voice,placeholder:u.length===0?`No voices. Add one in Settings.`:`Pick a voice`,options:u.map(e=>({value:e.voiceId,label:e.name})),problem:void 0,onPick:e=>n({...s,voice:e})}),(0,h.jsx)(p2,{language:o,voice:c.find(e=>e.voiceId===s.voice),hidden:l.hidden,showAll:l.showAll,onShowAll:l.setShowAll}),(0,h.jsx)(ZB,{label:`Pace`,value:String(s.pace??1),placeholder:`Pick a pace`,options:CA.map(e=>({value:String(e),label:e===1?`Normal`:`${String(e)}×`})),problem:void 0,onPick:e=>{let{pace:t,...r}=s;n(Number(e)===1?r:{...r,pace:Number(e)})}})]}),t===void 0?null:(0,h.jsx)(B,{variant:`quiet`,onClick:()=>n(void 0),children:`Remove the voice`})]})}function yme({error:e,retry:t,onReword:n}){let r=s1({stage:`images`,reason:e});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`m-0 mt-1 text-small text-danger`,children:e}),r===void 0?null:(0,h.jsx)(Iy,{className:`mt-2`,children:(0,h.jsx)(h1,{fix:r,retry:t,variant:`secondary`,size:`small`,edit:r.kind===`refused`?(0,h.jsx)(B,{variant:`secondary`,size:`small`,onClick:n,children:`Reword the picture`}):void 0})})]})}function bme({channelId:e,cast:t,selected:n,onSelect:r}){let{api:i}=V(),a=_(),[o,s]=(0,m.useState)(null),c=n===void 0?o:n,l=r??s,[u,d]=(0,m.useState)(null),f=L({mutationFn:e=>hx(i,e),onSuccess:async(t,n)=>{d(null),c===n&&l(null),await Promise.all([a.invalidateQueries({queryKey:ax(e)}),a.invalidateQueries({queryKey:ix})])}}),p=t.find(e=>e.id===c),g=t.flatMap(e=>{let t=e.images.find(e=>e.state===`ready`)?.sha256;return t?[{member:e,src:xx(i,t)}]:[]}),v=g.map(e=>({src:e.src,alt:e.member.name,caption:`${rx[e.member.kind]} · ${e.member.description||`No description yet`}`})),[y,b]=(0,m.useState)(null),x=c===`new`||p!==void 0;return(0,h.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 min-[1024px]:grid-cols-[minmax(0,1fr)_440px]`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`p`,{className:`m-0 mb-4 max-w-[68ch] text-small text-ink-2`,children:`When a video's title or an image's brief names a member, its pictures go with that image as references, so it looks the same in every video.`}),t.length===0?(0,h.jsx)(T1,{title:`No cast yet`,actions:(0,h.jsx)(B,{variant:`secondary`,onClick:()=>l(`new`),children:`Add to cast`}),children:`Add the characters, creatures, places and objects this channel keeps coming back to.`}):(0,h.jsx)(u0,{label:`Cast`,children:t.map(e=>{let t=e.images.filter(e=>e.state===`ready`),n=t[0]?.sha256;return(0,h.jsx)(l0,{className:z(e.id===c&&`rounded-media outline-2 outline-accent outline-offset-4 outline-solid`),...n?{src:xx(i,n)}:{},alt:e.name,onOpen:()=>b(g.findIndex(t=>t.member.id===e.id)),openLabel:`Open ${e.name}'s picture full size`,title:e.name,meta:`${rx[e.kind]}${e.host===!0?` · Host`:``} · ${String(t.length)} ${t.length===1?`picture`:`pictures`}`,...t.length===0?{badge:(0,h.jsx)(kS,{tone:`waiting`,children:`No picture`})}:{},actionsShown:!0,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Edit ${e.name}`,"aria-pressed":e.id===c,onClick:()=>l(e.id),children:`Edit`}),(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{f.reset(),d(e)},children:`Delete`})]})},e.id)})}),(0,h.jsx)(d0,{items:v,index:y,onIndex:b,onClose:()=>b(null),actions:(e,t)=>{let n=g[t];return n===void 0?null:(0,h.jsx)(B,{size:`small`,onClick:()=>{b(null),l(n.member.id)},children:`Edit ${n.member.name}`})}}),(0,h.jsx)(v1,{tone:`error`,className:`mt-2`,children:u?void 0:f.error?.message})]}),(0,h.jsx)(`aside`,{"aria-label":`Cast member editor`,className:`min-w-0`,children:x?(0,h.jsx)(gme,{channelId:e,member:p,open:!0,onClose:()=>l(null),onCreated:e=>l(e)},c??`closed`):t.length===0?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Pick a member's Edit to change its names, description and pictures here.`})}),(0,h.jsx)(Hy,{open:u!==null,title:`Delete ${u?.name??`this cast member`}?`,consequence:f.error?.message??`New videos stop using its pictures. Videos already made keep the pictures they were started with.`,confirmLabel:`Delete from cast`,cancelLabel:`Keep it`,pending:f.isPending,onConfirm:()=>{u&&f.mutate(u.id)},onCancel:()=>d(null)})]})}var m2=e=>[`channels`,e,`episodes`],h2=e=>[`channels`,e,`videos`],g2=(e,t)=>`${e.origin}/api/channels/${t}`,_2=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)});function xme(e,t){return at({queryKey:m2(t),queryFn:async()=>R(await e.fetch(`${g2(e,t)}/episodes`))})}async function Sme(e,t,n){return R(await e.fetch(`${g2(e,t)}/episodes/setting`,_2(`PUT`,{enabled:n})))}async function Cme(e,t,n,r){return R(await e.fetch(`${g2(e,t)}/episodes/${encodeURIComponent(n)}`,_2(`PUT`,{summary:r})))}async function wme(e,t,n){let r=await e.fetch(`${g2(e,t)}/episodes/${encodeURIComponent(n)}`,{method:`DELETE`});r.ok||await R(r)}function v2(e,t){return at({queryKey:h2(t),queryFn:async()=>(await R(await e.fetch(`${g2(e,t)}/videos`))).videos})}async function Tme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos`,_2(`POST`,n)))}async function Eme(e,t,n){return R(await e.fetch(`${g2(e,t)}/videos/preview`,_2(`POST`,{format:`csv`,text:n})))}async function Dme(e,t,n){let r=await e.fetch(`${g2(e,t)}/videos/${n}`,{method:`DELETE`});r.ok||await R(r)}async function Ome(e,t){await R(await e.fetch(`${g2(e,t)}/videos`,{method:`DELETE`}))}var kme=e=>e.length>160?`${e.slice(0,160)}…`:e;function Ame({channelId:e}){let{api:t}=V(),n=_(),r=I(xme(t,e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),c=()=>n.invalidateQueries({queryKey:m2(e)}),l=L({mutationFn:n=>Sme(t,e,n),onSuccess:t=>n.setQueryData(m2(e),t)}),u=L({mutationFn:n=>wme(t,e,n),onSuccess:async()=>{s(null),await c()}}),d=r.data?.enabled??!1,f=r.data?.memories??[];return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(Bb,{checked:d,disabled:r.data===void 0||l.isPending,onChange:e=>l.mutate(e),label:`Episode memory`,tip:`planning.channel.episode-memory`,describedBy:`${e}-memory-help`}),(0,h.jsx)(`p`,{id:`${e}-memory-help`,className:`mt-1 mb-3 text-small text-ink-2`,children:`Finished episodes leave a short summary that new related episodes are written with.`}),(0,h.jsx)(v1,{tone:r.error||l.error||u.error?`error`:`info`,children:r.error?.message??l.error?.message??(o?void 0:u.error?.message)??(r.isPending?`Loading the episodes…`:void 0)}),r.data&&f.length===0?(0,h.jsx)(T1,{title:`No episodes remembered yet`,children:d?`When a video on this channel finishes, its summary appears here.`:`Turn on episode memory, and the next finished video's summary appears here.`}):null,f.length>0?(0,h.jsx)(PH,{label:`Episode summaries`,children:f.map(e=>(0,h.jsx)(FH,{title:e.title,meta:(0,h.jsxs)(h.Fragment,{children:[e.source===`edited`?`Edited · `:``,e.cast.length>0?`${e.cast.join(`, `)} · `:``,kme(e.summary)]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{size:`small`,"aria-label":`Open the summary of ${e.title}`,onClick:()=>a(e),children:`Open`}),(0,h.jsx)(B,{size:`small`,variant:`quiet`,"aria-label":`Delete the summary of ${e.title}`,onClick:()=>{u.reset(),s(e)},children:`Delete`})]})},e.id))}):null,i?(0,h.jsx)(jme,{channelId:e,memory:i,onClose:()=>a(null)},i.id):null,(0,h.jsx)(Hy,{open:o!==null,title:`Delete the summary of ${o?.title??`this episode`}?`,consequence:u.error?.message??`New episodes stop being reminded of it. The video itself is not changed.`,confirmLabel:`Delete summary`,pending:u.isPending,onConfirm:()=>{o&&u.mutate(o.id)},onCancel:()=>s(null)})]})}function jme({channelId:e,memory:t,onClose:n}){let{api:r}=V(),i=_(),[a,o]=(0,m.useState)(t.summary),s=L({mutationFn:()=>Cme(r,e,t.id,a),onSuccess:async()=>{await i.invalidateQueries({queryKey:m2(e)}),n()}}),c=a.trim()!==t.summary.trim();return(0,h.jsx)(Vy,{open:!0,onOpenChange:e=>{e||n()},title:t.title,description:t.source===`edited`?`You edited this summary; finishing the video again keeps your text.`:`Written by the text model when the video finished. An edit here is kept.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{onClick:n,children:`Close`}),(0,h.jsx)(B,{variant:`primary`,disabled:!c||s.isPending,onClick:()=>s.mutate(),children:`Save summary`})]}),children:(0,h.jsx)(LB,{label:`Summary`,error:s.error?.message,tip:`planning.channel.episode-summary`,children:(0,h.jsx)(BB,{rows:8,value:a,onChange:e=>o(e.target.value)})})})}var y2=(e,t,n)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function b2(e,t){let n=t.trim().toLowerCase();return e.map(e=>n===``||e.toLowerCase().includes(n))}function Mme({channelId:e}){let{api:t}=V(),n=_(),r=I(v2(t,e)),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(void 0),u=(0,m.useRef)(null),d=()=>n.invalidateQueries({queryKey:h2(e)}),[f,p]=(0,m.useState)(void 0),[g,v]=(0,m.useState)(``),y=L({mutationFn:n=>Tme(t,e,{format:`lines`,...n}),onSuccess:async(e,t)=>{t.filter===void 0?a(``):p(void 0),l(`Added ${y2(e.added,`title`,`titles`)}${e.skipped>0?`; skipped ${e.skipped.toLocaleString(`en`)} already listed`:``}.`),await d()}}),b=L({mutationFn:n=>Eme(t,e,n),onSuccess:e=>{v(e.filter),p({titles:e.titles,ticked:b2(e.titles,e.filter)})}}),x=L({mutationFn:n=>Dme(t,e,n),onSuccess:d}),S=L({mutationFn:()=>Ome(t,e),onSuccess:async()=>{s(!1),await d()}}),C=r.data??[],w=y.isPending||b.isPending||x.isPending||S.isPending,T=r.error??b.error??y.error??x.error;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-3 text-small text-ink-2`,children:`Topic suggestions and duplicate checks skip these titles, as they skip the videos made here.`}),(0,h.jsx)(LB,{label:`Paste titles`,tip:`planning.channel.videos-paste`,help:`One title per line.`,children:(0,h.jsx)(BB,{rows:5,value:i,onChange:e=>a(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{variant:`primary`,disabled:w||i.trim()===``,onClick:()=>{l(void 0),y.mutate({text:i})},children:`Add titles`}),(0,h.jsx)(B,{disabled:w,onClick:()=>{u.current?.click()},children:`Import a YouTube Studio CSV…`}),(0,h.jsx)(U,{id:`planning.channel.videos-csv`}),(0,h.jsx)(`input`,{ref:u,type:`file`,accept:`.csv,text/csv`,className:`hidden`,"aria-label":`YouTube Studio CSV file`,onChange:async e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&(l(void 0),y.reset(),b.mutate(await t.text()))}}),(0,h.jsx)(B,{variant:`quiet`,disabled:w||C.length===0,onClick:()=>{S.reset(),s(!0)},children:`Remove all`})]}),(0,h.jsx)(v1,{tone:T?`error`:c?`success`:`info`,className:`mt-1`,children:T?.message??c??(r.isPending?`Loading the titles…`:b.isPending?`Reading the CSV…`:void 0)}),f===void 0?null:(0,h.jsx)(Nme,{preview:f,filter:g,busy:w,onFilter:e=>{v(e),p({...f,ticked:b2(f.titles,e)})},onTick:e=>p({...f,ticked:e}),onSave:()=>{l(void 0);let e=f.titles.filter((e,t)=>f.ticked[t]);y.mutate({text:e.join(`
273
+ `),filter:g})},onCancel:()=>{y.reset(),p(void 0)}}),r.data&&C.length===0?(0,h.jsx)(T1,{title:`No existing videos listed`,children:`In YouTube Studio open Analytics → Content → Advanced mode, export the table as a CSV, and import it here; or paste the titles above.`}):null,C.length>0?(0,h.jsx)(PH,{label:`Existing videos`,children:C.map(e=>(0,h.jsx)(FH,{title:e.title,actions:(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:w,"aria-label":`Remove ${e.title}`,onClick:()=>x.mutate(e.id),children:`Remove`})},e.id))}):null,(0,h.jsx)(Hy,{open:o,title:`Remove all ${y2(C.length,`title`,`titles`)}?`,consequence:S.error?.message??`Topic suggestions and duplicate checks stop skipping them. Your videos on YouTube are not touched.`,confirmLabel:`Remove all`,pending:S.isPending,onConfirm:()=>S.mutate(),onCancel:()=>s(!1)})]})}function Nme({preview:e,filter:t,busy:n,onFilter:r,onTick:i,onSave:a,onCancel:o}){let s=(0,m.useId)(),c=e.ticked.filter(Boolean).length;return(0,h.jsxs)(`section`,{"aria-label":`Titles in the CSV`,className:`mt-4`,...zb,children:[(0,h.jsxs)(W,{as:`h3`,title:`Titles in the CSV`,info:`planning.channel.videos-ticks`,meta:`${c.toLocaleString(`en`)} of ${y2(e.titles.length,`title`,`titles`)} ticked`,children:[(0,h.jsxs)(B,{variant:`primary`,disabled:n||c===0,onClick:a,children:[`Add `,y2(c,`ticked title`,`ticked titles`)]}),(0,h.jsx)(B,{variant:`quiet`,disabled:n,onClick:o,children:`Cancel`})]}),(0,h.jsx)(LB,{label:`Keep only titles containing…`,tip:`planning.channel.videos-filter`,tipLabel:`Keep only titles containing`,children:(0,h.jsx)(zB,{value:t,maxLength:200,onChange:e=>r(e.target.value)})}),(0,h.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!0)),children:`Tick all`}),(0,h.jsx)(B,{size:`small`,disabled:n,onClick:()=>i(e.titles.map(()=>!1)),children:`Untick all`})]}),(0,h.jsx)(PH,{label:`Titles in the CSV`,className:`mt-2`,children:e.titles.map((t,r)=>(0,h.jsx)(FH,{lead:(0,h.jsx)(`input`,{id:`${s}-${r}`,type:`checkbox`,checked:e.ticked[r]===!0,disabled:n,className:`size-4 shrink-0 accent-accent`,onChange:t=>i(e.ticked.map((e,n)=>n===r?t.target.checked:e))}),title:(0,h.jsx)(`label`,{htmlFor:`${s}-${r}`,children:t})},r))})]})}function x2({className:e,children:t}){return(0,h.jsx)(`dl`,{className:z(`sl-stats m-0`,e),children:t})}function S2({value:e,label:t,children:n}){return(0,h.jsxs)(`div`,{className:`sl-stat`,children:[(0,h.jsx)(`dt`,{className:`sl-stat__label order-2`,children:t}),(0,h.jsx)(`dd`,{className:`sl-stat__value order-1 m-0`,children:e}),n===void 0?null:(0,h.jsx)(`dd`,{className:`order-3 m-0 mt-1`,children:n})]})}function C2({value:e,label:t,valueText:n,tone:r=`accent`,className:i}){let a=Math.round(Math.min(1,Math.max(0,Number.isFinite(e)?e:0))*100);return(0,h.jsx)(`div`,{role:`meter`,"aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":a,"aria-valuetext":n??`${String(a)}%`,className:z(`sl-meter`,r===`waiting`&&`sl-meter--waiting`,i),children:(0,h.jsx)(`span`,{style:{width:`${String(a)}%`}})})}function w2({columns:e,rows:t,rowKey:n,caption:r,empty:i,className:a}){return(0,h.jsxs)(`table`,{className:z(`sl-table`,a),children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:r}),(0,h.jsx)(`thead`,{children:(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`th`,{scope:`col`,className:e.numeric?`num`:void 0,children:e.header},e.id))})}),(0,h.jsx)(`tbody`,{children:t.length===0&&i!==void 0?(0,h.jsx)(`tr`,{children:(0,h.jsx)(`td`,{colSpan:e.length,className:`text-ink-2`,children:i})}):t.map(t=>(0,h.jsx)(`tr`,{children:e.map(e=>(0,h.jsx)(`td`,{className:e.numeric?`num`:void 0,children:e.cell(t)},e.id))},n(t)))})]})}var T2=56,E2=12,D2=12,Pme=28;function Fme(e,t){let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r;return(i<=1?1:i<=2?2:i<=5?5:10)*r}function O2({series:e,xLabels:t,formatValue:n,label:r,height:i=260,legend:a=!0,className:o}){let s=(0,m.useRef)(null),[c,l]=(0,m.useState)(800),[u,d]=(0,m.useState)();(0,m.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(([e])=>{e!==void 0&&l(Math.max(320,Math.round(e.contentRect.width)))});return t.observe(e),()=>t.disconnect()},[]);let f=t.length,p=Math.max(0,...e.flatMap(e=>e.values.filter(e=>e!==null))),g=Fme(p>0?p:1,4),_=Math.max(g,Math.ceil((p>0?p:1)/g)*g),v=c-T2-E2,y=e=>T2+(f<=1?0:e/(f-1)*v),b=e=>D2+i-e/_*i,x=Array.from({length:Math.round(_/g)+1},(e,t)=>t*g),S=Math.min(f,Math.max(2,Math.floor(v/90))),C=Array.from({length:S},(e,t)=>Math.round(t/Math.max(1,S-1)*(f-1))),w=e=>{let t=``,n=!1;return e.forEach((e,r)=>{if(e===null){n=!1;return}t+=`${n?`L`:`M`}${y(r).toFixed(1)},${b(e).toFixed(1)}`,n=!0}),t},T=D2+i+Pme,E=u===void 0?[]:e.map(e=>({one:e,value:e.values[u]??null})).filter(e=>e.value!==null).toSorted((e,t)=>t.value-e.value);return(0,h.jsxs)(`figure`,{className:z(`m-0 flex flex-col gap-2`,o),children:[(0,h.jsxs)(`div`,{ref:s,className:`relative w-full`,children:[(0,h.jsxs)(`svg`,{role:`img`,"aria-label":r,width:c,height:T,viewBox:`0 0 ${String(c)} ${String(T)}`,className:`block select-none`,onMouseLeave:()=>d(void 0),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=Math.round((e.clientX-t.left-T2)/v*(f-1));d(n<0||n>=f?void 0:n)},children:[x.map(e=>(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:T2,x2:c-E2,y1:b(e),y2:b(e),stroke:`currentColor`,className:`text-line`,strokeWidth:`1`}),(0,h.jsx)(`text`,{x:48,y:b(e),textAnchor:`end`,dominantBaseline:`middle`,className:`fill-ink-3 text-[11px]`,children:n(e)})]},e)),C.map(e=>(0,h.jsx)(`text`,{x:y(e),y:D2+i+18,textAnchor:e===0?`start`:e===f-1?`end`:`middle`,className:`fill-ink-3 text-[11px]`,children:t[e]},e)),e.map(e=>(0,h.jsx)(`path`,{d:w(e.values),fill:`none`,stroke:e.color,strokeWidth:`1.75`,strokeLinejoin:`round`},e.id)),u===void 0?null:(0,h.jsxs)(`g`,{children:[(0,h.jsx)(`line`,{x1:y(u),x2:y(u),y1:D2,y2:D2+i,stroke:`currentColor`,className:`text-ink-3`,strokeDasharray:`3 3`}),E.map(({one:e,value:t})=>(0,h.jsx)(`circle`,{cx:y(u),cy:b(t),r:`3.5`,fill:e.color},e.id))]})]}),u===void 0||E.length===0?null:(0,h.jsxs)(`div`,{className:`pointer-events-none absolute top-2 z-10 w-[340px] rounded-control border border-line bg-surface p-2 text-small shadow-md`,style:y(u)>c/2?{right:c-y(u)+12}:{left:y(u)+12},children:[(0,h.jsx)(`div`,{className:`mb-1 font-semibold`,children:t[u]}),E.map(({one:e,value:t})=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 shrink-0 rounded-full`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),(0,h.jsx)(`span`,{className:`tabular-nums`,children:n(t)})]},e.id))]})]}),a?(0,h.jsx)(`figcaption`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-small text-ink-2`,children:e.map(e=>(0,h.jsxs)(`span`,{className:`flex max-w-[320px] items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-[3px] w-4 shrink-0 rounded`,style:{background:e.color}}),(0,h.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id))}):null]})}var k2=(e,t)=>`${e.origin}/api/studio/channels/${t}/report`;async function Ime(e,t){return R(await e.fetch(k2(e,t)))}async function Lme(e,t,n){return R(await e.fetch(k2(e,t),{method:`POST`,headers:{"content-type":n.type||`application/zip`},body:n}))}function A2(e,t,n){if(e===null)return`–`;if(typeof e==`string`)return e;if(t===`duration`){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=String(Math.round(e%60)).padStart(2,`0`);return t>0?`${String(t)}:${String(n).padStart(2,`0`)}:${r}`:`${String(n)}:${r}`}let r=/%|\(|rpm|revenue|hours/i.test(n)&&!Number.isInteger(e)?1:0;return e.toLocaleString(`en`,{minimumFractionDigits:r,maximumFractionDigits:r})}var j2=[`#7cb342`,`#42a5f5`,`#ef6c00`,`#ab47bc`,`#26a69a`,`#ec407a`,`#fdd835`,`#8d6e63`,`#5c6bc0`,`#78909c`],M2=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`}),N2=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});function P2(e,t){if(t===`total`){let t=0;return e.map(e=>t+=e)}return t===`average`?e.map((t,n)=>{let r=e.slice(Math.max(0,n-6),n+1);return r.reduce((e,t)=>e+t,0)/r.length}):[...e]}function Rme({report:e,rows:t,picked:n,colorOf:r,shape:i,setShape:a,timeline:o,setTimeline:s,range:c,setRange:l}){let u=e.chartMetric??`Views`,d=t.filter(e=>n.includes(e.videoId)),f=e.from===null?new Date:new Date(`${e.from}T00:00:00`),p=Math.max(0,...t.map(e=>e.daily.length)),m,g;if(o===`dates`){let e=c===`all`?0:Math.max(0,p-Number(c)),t=p-e>200;m=Array.from({length:p-e},(n,r)=>{let i=new Date(f);return i.setDate(i.getDate()+e+r),(t?N2:M2).format(i)}),g=d.map(t=>{let n=t.daily.findIndex(e=>e>0),a=P2(t.daily,i).map((e,t)=>n<0||t<n?null:e);return{id:t.videoId,label:t.title,color:r(t.videoId),values:a.slice(e)}})}else{let e=Math.max(1,...d.map(e=>{let t=e.daily.findIndex(e=>e>0);return t<0?0:e.daily.length-t})),t=c===`all`?e:Math.min(e,Number(c));m=Array.from({length:t},(e,t)=>`Day ${String(t+1)}`),g=d.map(e=>{let n=Math.max(0,e.daily.findIndex(e=>e>0)),a=P2(e.daily.slice(n),i).slice(0,t);return{id:e.videoId,label:e.title,color:r(e.videoId),values:Array.from({length:t},(e,t)=>a[t]??null)}})}let _=i===`daily`?`${u} per day`:i===`average`?`${u} per day, 7-day average`:`${u}, running total`;return(0,h.jsxs)(`section`,{"aria-label":`Over time`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:_}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(VB,{"aria-label":`Show`,className:`w-[200px]`,value:i,onChange:e=>a(e.currentTarget.value),options:[{value:`average`,label:`7-day average`},{value:`daily`,label:`Per day`},{value:`total`,label:`Running total`}]}),(0,h.jsx)(VB,{"aria-label":`Timeline`,className:`w-[220px]`,value:o,onChange:e=>s(e.currentTarget.value),options:[{value:`dates`,label:`By date`},{value:`since`,label:`Days since release`}]}),(0,h.jsx)(VB,{"aria-label":`Period`,className:`w-[170px]`,value:c,onChange:e=>l(e.currentTarget.value),options:[{value:`all`,label:o===`dates`?`All time`:`Whole life`},{value:`90`,label:o===`dates`?`Last 90 days`:`First 90 days`},{value:`30`,label:o===`dates`?`Last 30 days`:`First 30 days`}]})]}),d.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Tick videos in the Chart column below to compare them here.`}):(0,h.jsx)(O2,{series:g,xLabels:m,label:`${_} for ${String(d.length)} videos`,formatValue:F2})]})}var F2=e=>e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}k`:Math.round(e).toLocaleString(`en`);function zme({report:e,rows:t,shape:n,range:r,colorOf:i}){let a=e.chartMetric??`Views`,o=e.from===null?new Date:new Date(`${e.from}T00:00:00`);return(0,h.jsxs)(`section`,{"aria-label":`Each video`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(`span`,{className:`font-semibold`,children:`Each video · ${a}`}),t.some(e=>!e.daily.some(e=>e>0))?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Studio's export holds daily figures only for the videos drawn in its own chart. To chart more, tick them in Advanced mode's chart before you export.`}):null,(0,h.jsx)(`div`,{className:`grid gap-6 lg:grid-cols-2`,children:t.map(e=>{let t=e.daily.findIndex(e=>e>0);if(t<0)return null;let s=P2(e.daily.slice(t),n),c=r===`all`?0:Math.max(0,s.length-Number(r)),l=s.slice(c),u=l.map((e,n)=>{let r=new Date(o);return r.setDate(r.getDate()+t+c+n),(l.length>200?N2:M2).format(r)}),d=e.daily.reduce((e,t)=>e+t,0);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 shrink-0 rounded-full`,style:{background:i(e.videoId)}}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold`,title:e.title,children:e.title}),(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:`${d.toLocaleString(`en`)} total`})]}),(0,h.jsx)(O2,{height:150,legend:!1,label:`${a} for ${e.title}`,xLabels:u,formatValue:F2,series:[{id:e.videoId,label:e.title,color:i(e.videoId),values:l}]})]},e.videoId)})})]})}var I2=e=>`slopify.studioReport.hidden.${e}`;function Bme(e){try{let t=window.localStorage.getItem(I2(e));return t===null?void 0:JSON.parse(t)}catch{return}}function L2({channelId:e}){let{api:t}=V(),n=_(),r=Ry(),i=(0,m.useRef)(null),a=[`studio`,`report`,e],o=I({queryKey:a,queryFn:()=>Ime(t,e)}),[s,c]=(0,m.useState)(0),[l,u]=(0,m.useState)(),[d,f]=(0,m.useState)(`average`),[p,g]=(0,m.useState)(`dates`),[v,y]=(0,m.useState)(`all`),[b,x]=(0,m.useState)(()=>Bme(e)),S=L({mutationFn:n=>Lme(t,e,n),onSuccess:e=>{n.setQueryData(a,e),r(`Imported ${String(e.report?.rows.length??0)} videos from Studio's export.`,`success`)},onError:e=>r(`The export wasn't imported: ${e.message}`,`error`)}),C=o.data?.report??null,w=C?.columns??[],T=w.filter((e,t)=>(C?.rows??[]).every(e=>e.values[t]===null)).map(e=>e.label),E=b??T,D=t=>{x(t);try{window.localStorage.setItem(I2(e),JSON.stringify(t))}catch{}},O=w.map((e,t)=>({column:e,index:t})).filter(({column:e})=>!E.includes(e.label)),k=(e,t)=>{let n=e.values[t];return typeof n==`number`?n:-1},A=[...C?.rows??[]].toSorted((e,t)=>k(t,s)-k(e,s)),j=[...C?.rows??[]].toSorted((e,t)=>t.daily.reduce((e,t)=>e+t,0)-e.daily.reduce((e,t)=>e+t,0)),M=l??j.slice(0,5).map(e=>e.videoId),ee=e=>{let t=(C?.rows??[]).findIndex(t=>t.videoId===e);return j2[(t<0?0:t)%j2.length]??`#7cb342`};return(0,h.jsxs)(`section`,{"aria-label":`From Studio`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(W,{as:`h3`,title:`From Studio's export`,meta:C===null?void 0:`${String(C.rows.length)} videos · ${C.from??`?`} to ${C.to??`?`} · imported ${new Date(C.importedAt).toLocaleDateString()}`,children:[(0,h.jsx)(`input`,{ref:i,type:`file`,accept:`.zip,.csv,application/zip,text/csv`,hidden:!0,"aria-label":`Studio export file`,onChange:e=>{let t=e.currentTarget.files?.[0];t!==void 0&&S.mutate(t),e.currentTarget.value=``}}),(0,h.jsxs)(B,{type:`button`,variant:`secondary`,disabled:S.isPending,onClick:()=>i.current?.click(),children:[(0,h.jsx)(tl,{"aria-hidden":`true`,strokeWidth:1.75}),S.isPending?`Importing…`:`Import from Studio`]})]}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In YouTube Studio, open Analytics → Advanced mode, choose the metrics as columns, press the Export arrow → Comma-separated values, and import the zip it downloads here. Every column comes along; a new import replaces the old one.`}),C===null?null:(0,h.jsxs)(h.Fragment,{children:[C.chartMetric===null?null:(0,h.jsx)(Rme,{report:C,rows:A,picked:M,colorOf:ee,shape:d,setShape:f,timeline:p,setTimeline:g,range:v,setRange:y}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,h.jsx)(VB,{"aria-label":`Order by`,className:`w-[280px]`,value:String(s),onChange:e=>c(Number(e.currentTarget.value)),options:w.map((e,t)=>({value:String(t),label:`Most ${e.label}`}))}),(0,h.jsxs)(`details`,{className:`text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer text-ink-2`,children:[`Columns (`,String(O.length),` of `,String(w.length),`)`]}),(0,h.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 sm:grid-cols-3`,children:w.map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:!E.includes(e.label),onChange:t=>D(t.currentTarget.checked?E.filter(t=>t!==e.label):[...E,e.label])}),e.label]},e.label))})]})]}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`sl-table [&_td]:px-3 [&_th]:px-3 [&_td.num]:whitespace-nowrap`,children:[(0,h.jsx)(`caption`,{className:`sr-only`,children:`Studio's numbers for every video`}),(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[C.chartMetric===null?null:(0,h.jsx)(`th`,{scope:`col`,children:`Chart`}),(0,h.jsx)(`th`,{scope:`col`,children:`Video`}),O.map(({column:e})=>(0,h.jsx)(`th`,{scope:`col`,className:`num`,children:e.label},e.label))]})}),(0,h.jsxs)(`tbody`,{children:[(0,h.jsxs)(`tr`,{className:`font-semibold`,children:[C.chartMetric===null?null:(0,h.jsx)(`td`,{}),(0,h.jsx)(`td`,{children:`Total`}),O.map(({column:e,index:t})=>(0,h.jsx)(`td`,{className:`num`,children:A2(C.totals[t]??null,e.kind,e.label)},e.label))]}),A.map(e=>{let t=o.data?.projects[e.videoId];return(0,h.jsxs)(`tr`,{children:[C.chartMetric===null?null:(0,h.jsx)(`td`,{children:(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,disabled:!e.daily.some(e=>e>0),"aria-label":`Compare ${e.title} in the chart`,checked:M.includes(e.videoId),onChange:t=>u(t.currentTarget.checked?[...M,e.videoId]:M.filter(t=>t!==e.videoId))}),(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 rounded-full`,style:{background:M.includes(e.videoId)?ee(e.videoId):`transparent`}})]})}),(0,h.jsxs)(`td`,{className:`max-w-[320px]`,children:[t===void 0?(0,h.jsx)(`span`,{className:`block truncate`,title:e.title,children:e.title}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:t.projectId},className:`block truncate`,title:e.title,children:e.title}),(0,h.jsx)(`span`,{className:`text-label text-ink-3`,children:e.published??``})]}),O.map(({column:t,index:n})=>(0,h.jsx)(`td`,{className:`num`,children:A2(e.values[n]??null,t.kind,t.label)},t.label))]},e.videoId)})]})]})}),C.chartMetric===null?null:(0,h.jsx)(zme,{report:C,rows:A,shape:d,range:v,colorOf:ee})]})]})}var R2=e=>e==null?`–`:Math.round(e).toLocaleString(`en`),z2=e=>e==null?`–`:`${e.toFixed(1)}%`;function B2(e){if(e==null)return`–`;let t=Math.round(e),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=String(t%60).padStart(2,`0`);return n>0?`${String(n)}:${String(r).padStart(2,`0`)}:${i}`:`${String(r)}:${i}`}var Vme=new Intl.DateTimeFormat(void 0,{day:`numeric`,month:`short`,year:`numeric`}),V2=e=>e===null?`–`:Vme.format(new Date(e));function H2({label:e,totals:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:e,meta:`${String(t.videos)} on YouTube`}),(0,h.jsxs)(x2,{children:[(0,h.jsx)(S2,{value:R2(t.views),label:`Views`}),(0,h.jsx)(S2,{value:R2(t.impressions),label:`Impressions`}),(0,h.jsx)(S2,{value:z2(t.ctr),label:`Click-through rate`}),(0,h.jsx)(S2,{value:B2(t.averageViewSeconds),label:`Average view duration`}),(0,h.jsx)(S2,{value:R2(t.watchHours),label:`Watch hours`})]})]})}var U2=(e,t)=>{let n=e.long?.stats??null;return t===`views`?(n?.views??0)+e.shorts.reduce((e,t)=>e+(t.stats?.views??0),0):t===`ctr`?n?.ctr??-1:t===`duration`?n?.averageViewSeconds??-1:Date.parse(e.long?.releasedAt??e.shorts[0]?.releasedAt??``)||0};function Hme({channelId:e}){let{api:t}=V(),[n,r]=(0,m.useState)(`newest`),i=I({queryKey:[`studio`,`performance`,e],queryFn:()=>hs(t,e)});if(i.isPending)return(0,h.jsx)(`p`,{className:`text-small text-ink-3`,children:`Loading the numbers…`});if(i.isError)return(0,h.jsxs)(`p`,{className:`text-small text-danger`,children:[`The numbers didn't load: `,i.error.message,` Reload the page to try again.`]});let a=i.data;if(a.projects.length===0)return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsx)(L2,{channelId:e}),(0,h.jsx)(T1,{title:`No video of this channel is known on YouTube yet`,children:`Upload with the Slopify Studio extension, or open YouTube Studio's Content list once so the extension links your videos. Their numbers then arrive daily, or at once with Read Studio numbers now in the extension's popup.`})]});let o=a.projects.toSorted((e,t)=>U2(t,n)-U2(e,n)).flatMap(e=>[...e.long===null?[]:[{key:`${e.projectId}-0`,projectId:e.projectId,row:e.long,isShort:!1}],...e.shorts.map(t=>({key:`${e.projectId}-${String(t.short??0)}`,projectId:e.projectId,row:t,isShort:!0}))]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-2`,children:[`Studio's numbers as the Slopify Studio extension last read them`,a.readAt===null?``:` (newest ${V2(a.readAt)})`,`: daily while Chrome is open, or at once with Read Studio numbers now in the extension's popup. "–" is a number Studio doesn't show for that video (most shorts have no click-through rate).`]}),(0,h.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-2`,children:[(0,h.jsx)(H2,{label:`Long videos`,totals:a.long}),(0,h.jsx)(H2,{label:`Shorts`,totals:a.shorts})]}),(0,h.jsx)(L2,{channelId:e}),(0,h.jsxs)(`section`,{"aria-label":`Every video`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:`Every video`,children:(0,h.jsx)(VB,{"aria-label":`Order`,value:n,onChange:e=>r(e.currentTarget.value),options:[{value:`newest`,label:`Newest first`},{value:`views`,label:`Most views`},{value:`ctr`,label:`Best click-through rate`},{value:`duration`,label:`Longest average view`}]})}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{columns:[{id:`title`,header:`Video`,cell:e=>e.isShort?(0,h.jsx)(`span`,{className:`block pl-5 text-small text-ink-2`,children:`Short ${String(e.row.short??``)} · ${e.row.title}`}):(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.projectId},children:e.row.title})},{id:`out`,header:`Released`,cell:e=>V2(e.row.releasedAt)},{id:`impressions`,header:`Impressions`,numeric:!0,cell:e=>R2(e.row.stats?.impressions)},{id:`ctr`,header:`CTR`,numeric:!0,cell:e=>z2(e.row.stats?.ctr)},{id:`views`,header:`Views`,numeric:!0,cell:e=>R2(e.row.stats?.views)},{id:`duration`,header:`Avg view`,numeric:!0,cell:e=>B2(e.row.stats?.averageViewSeconds)},{id:`hours`,header:`Watch hours`,numeric:!0,cell:e=>e.row.stats?.watchHours===null||e.row.stats?.watchHours===void 0?`–`:e.row.stats.watchHours.toFixed(1)}],rows:o,rowKey:e=>e.key,caption:`The channel's videos and shorts with Studio's numbers`})})]})]})}var W2=[`brand`,`cast`,`templates`,`schedules`,`episodes`,`videos`,`youtube`],Ume={brand:`Brand`,cast:`Cast`,templates:`Templates`,schedules:`Schedules`,episodes:`Episodes`,videos:`Existing videos`,youtube:`YouTube numbers`};function Wme(e){return W2.find(t=>t===e)??`brand`}function Gme({channelId:e,tab:t,onTab:n}){let{api:r}=V(),i=_(),a=Ji(),o=I(lx(r,e)),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(null),d=L({mutationFn:()=>fx(r,e),onSuccess:async()=>{c(!1),await i.invalidateQueries({queryKey:ix}),await a({to:`/channels`})}}),f=o.data?.channel,p=o.data?.cast??[],g=()=>{n(`cast`),u(`new`)};return jx({id:`channel.add-to-cast`,title:`Add to cast`,group:`Channel`,...f===void 0?{}:{context:f.name},keywords:[`character`,`creature`,`place`,`object`],run:g}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(fa,{to:`/channels`,children:`Channels`}),title:f?.name??`Channel`,meta:f?.isDefault?`Default channel`:void 0,actions:(0,h.jsxs)(h.Fragment,{children:[t===`cast`&&f?(0,h.jsxs)(B,{variant:`primary`,onClick:g,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`Add to cast`]}):null,f&&!f.isDefault?(0,h.jsx)(B,{variant:`quiet`,onClick:()=>{d.reset(),c(!0)},children:`Delete channel`}):null]})}),(0,h.jsx)(C1,{items:W2.map(e=>({id:e,label:Ume[e],...e===`cast`?{badge:String(p.length)}:{}})),value:t,onChange:n,label:`Channel sections`,idPrefix:`channel`,className:`mb-6`}),(0,h.jsx)(v1,{tone:o.error?`error`:`info`,className:`mb-2`,children:o.error?`The channel couldn't be loaded: ${o.error.message} Go back to Channels and open it again.`:o.isPending?`Loading the channel…`:void 0}),f?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(w1,{idPrefix:`channel`,id:`brand`,active:t===`brand`,children:[(0,h.jsx)(ame,{channel:f}),(0,h.jsx)(pme,{channel:f},`${f.id}:${String(f.version)}`)]}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`cast`,active:t===`cast`,children:(0,h.jsx)(bme,{channelId:f.id,cast:p,selected:l,onSelect:u})}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`templates`,active:t===`templates`,children:t===`templates`?(0,h.jsx)(wfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`schedules`,active:t===`schedules`,children:t===`schedules`?(0,h.jsx)(Dfe,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`episodes`,active:t===`episodes`,children:t===`episodes`?(0,h.jsx)(Ame,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`videos`,active:t===`videos`,children:t===`videos`?(0,h.jsx)(Mme,{channelId:f.id}):null}),(0,h.jsx)(w1,{idPrefix:`channel`,id:`youtube`,active:t===`youtube`,children:t===`youtube`?(0,h.jsx)(Hme,{channelId:f.id}):null})]}):null,(0,h.jsx)(Hy,{open:s,title:`Delete ${f?.name??`this channel`}?`,consequence:d.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:d.isPending,onConfirm:()=>d.mutate(),onCancel:()=>c(!1)})]})}function Kme(){let{api:e}=V(),t=_(),n=Ji(),r=I(cx(e)),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(null),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(null),f=r.data?.find(e=>e.id===u)??r.data?.[0],p=L({mutationFn:()=>ux(e,crypto.randomUUID(),c.trim()),onSuccess:async e=>{await t.invalidateQueries({queryKey:ix}),a(null),l(``),await n({to:`/channels/$channelId`,params:{channelId:e.id}})}}),g=L({mutationFn:t=>dx(e,t.id,{name:c.trim(),brand:t.brand,seriesBrief:t.seriesBrief,baseVersion:t.version}),onSuccess:async()=>{await t.invalidateQueries({queryKey:ix}),a(null)}}),v=L({mutationFn:t=>fx(e,t.id),onSuccess:async()=>{s(null),await t.invalidateQueries({queryKey:ix})}}),y=()=>{p.reset(),l(``),a(`new`)};jx({id:`channels.new`,title:`New channel`,group:`Channels`,run:y});let b=i===`new`?p:g,x=()=>{c.trim()!==``&&i!==null&&(i===`new`?p.mutate():g.mutate(i))};return(0,h.jsxs)(`div`,{"data-tour":`channels`,children:[(0,h.jsx)(XK,{title:`Channels`,meta:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`A channel keeps its brand kit, cast, series brief, templates and schedules together.`,(0,h.jsx)(U,{id:`planning.channels`})]}),actions:(0,h.jsxs)(B,{variant:`primary`,"aria-expanded":i===`new`,onClick:y,children:[(0,h.jsx)(Kc,{"aria-hidden":`true`,className:`size-4`,strokeWidth:1.75}),`New channel`]})}),(0,h.jsx)(v1,{tone:r.error||v.error?`error`:`info`,className:`mb-2`,children:r.error?`The channels couldn't be loaded: ${r.error.message} Reload the page to try again.`:o===null&&v.error?v.error.message:r.isPending?`Loading channels…`:void 0}),r.data?.length===0?(0,h.jsx)(T1,{title:`No channels yet`,actions:(0,h.jsx)(B,{variant:`primary`,onClick:y,children:`New channel`}),children:`Make one for each series you run; it keeps that series' look and cast.`}):null,r.data?.length?(0,h.jsx)(QK,{list:(0,h.jsx)(PH,{label:`Channels`,className:`[&_.sl-row__actions]:flex-wrap`,children:r.data.map(e=>(0,h.jsx)(FH,{selected:e.id===f?.id,onSelect:()=>d(e.id),title:e.name,meta:`${e.isDefault?`Default · `:``}${String(e.templates)} ${e.templates===1?`template`:`templates`} · ${String(e.cast)} in the cast`,actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wS,{to:`/channels/$channelId`,params:{channelId:e.id},"aria-label":`Open ${e.name}`,className:`px-2 text-small`,children:`Open`}),(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Rename ${e.name}`,onClick:()=>{g.reset(),l(e.name),a(e)},children:`Rename`}),e.isDefault?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Delete ${e.name}`,onClick:()=>{v.reset(),s(e)},children:`Delete`})]})},e.id))}),detail:f===void 0?null:(0,h.jsx)(qme,{channel:f})}):null,(0,h.jsx)(Vy,{open:i!==null,onOpenChange:e=>{!e&&!b.isPending&&a(null)},title:i===`new`||i===null?`New channel`:`Rename ${i.name}`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(v1,{tone:b.error?`error`:`info`,children:b.error?.message??(b.isPending?`Saving…`:void 0)}),(0,h.jsx)(B,{disabled:b.isPending,onClick:()=>a(null),children:`Cancel`}),(0,h.jsx)(B,{type:`submit`,form:`channel-name-form`,variant:`primary`,disabled:b.isPending||c.trim()===``,children:i===`new`?`Create channel`:`Rename channel`})]}),children:(0,h.jsx)(`form`,{id:`channel-name-form`,"aria-label":i===`new`?`New channel`:`Rename channel`,onSubmit:e=>{e.preventDefault(),x()},children:(0,h.jsx)(LB,{label:`Channel name`,tip:`planning.channel.name`,children:(0,h.jsx)(zB,{value:c,maxLength:200,required:!0,disabled:b.isPending,onChange:e=>l(e.target.value)})})})}),(0,h.jsx)(Hy,{open:o!==null,title:`Delete ${o?.name??`this channel`}?`,consequence:v.error?.message??`Its cast goes with it. Its videos move to the default channel and keep what they were made with.`,confirmLabel:`Delete channel`,cancelLabel:`Keep it`,pending:v.isPending,onConfirm:()=>{o&&v.mutate(o)},onCancel:()=>s(null)})]})}function qme({channel:e}){let t=e.brand,n=[[`Intro`,t.intro??`None`],[`Outro`,t.outro??`None`],[`Document theme`,t.documentTheme??`Default`],[`End screen text`,t.endScreenText??`None`]];return(0,h.jsxs)(`section`,{"aria-label":`About ${e.name}`,children:[(0,h.jsx)(W,{title:`About ${e.name}`,meta:e.isDefault?`The default channel`:void 0,children:(0,h.jsx)(CS,{to:`/channels/$channelId`,params:{channelId:e.id},children:`Open channel`})}),(0,h.jsxs)(x2,{className:`mb-6`,children:[(0,h.jsx)(S2,{value:String(e.templates),label:`Templates`}),(0,h.jsx)(S2,{value:String(e.cast),label:`In the cast`})]}),(0,h.jsx)(W,{as:`h3`,title:`Series brief`,className:`pb-2`}),(0,h.jsx)(`p`,{className:`m-0 mb-6 whitespace-pre-wrap text-body text-ink-2`,children:e.seriesBrief.trim()===``?`No series brief yet. Open the channel to say what it covers.`:e.seriesBrief}),(0,h.jsx)(W,{as:`h3`,title:`Brand kit`,className:`pb-2`}),(0,h.jsx)(`dl`,{className:`m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-6 gap-y-2 text-small`,children:n.map(([e,t])=>(0,h.jsxs)(`div`,{className:`contents`,children:[(0,h.jsx)(`dt`,{className:`text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 truncate`,children:t})]},e))})]})}var G2=2e3;function K2(e,t){let n=(0,m.useRef)(t);(0,m.useEffect)(()=>{n.current=t}),(0,m.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{n.current()},G2);return()=>{clearTimeout(t)}},[e])}function q2(){return(0,h.jsxs)(`span`,{className:`inline-flex animate-tick-in items-center gap-1 text-label text-accent-ink motion-reduce:animate-none`,children:[(0,h.jsx)(Sc,{"aria-hidden":`true`,className:`size-[14px]`}),`Saved`]})}function J2({onDelete:e,blocked:t,blockedId:n,pending:r,saved:i,cancel:a,errors:o,onSave:s}){let c=t!==void 0||r||i,l=Ry();jx({id:`editor.save`,title:`Save`,group:`This editor`,keywords:[`save`,`keep`],shortcut:nP.save,run:()=>{c?t!==void 0&&l(`Not saved yet: ${t}`,`error`):s()}});let u=o.join(` `);return(0,h.jsxs)(`div`,{"data-slot":`editor-actions`,className:`sticky bottom-0 z-10 flex flex-wrap items-center gap-3 border-t border-line bg-ground py-3 max-md:bottom-[calc(48px+max(12px,env(safe-area-inset-bottom)))]`,children:[(0,h.jsx)(B,{variant:`destructive`,onClick:e,disabled:e===void 0,"aria-hidden":e===void 0||void 0,tabIndex:e===void 0?-1:void 0,style:e===void 0?{visibility:`hidden`}:void 0,children:`Delete`}),(0,h.jsx)(v1,{tone:u?`error`:`info`,id:u?void 0:n,children:u||(i?(0,h.jsx)(q2,{}):t)}),a,(0,h.jsx)(B,{variant:`primary`,"aria-disabled":c,"aria-describedby":t===void 0?void 0:n,"aria-keyshortcuts":Ux(nP.save),onClick:()=>{c||s()},children:`Save`})]})}var Jme=`rounded-media border border-line bg-surface p-4`;function Y2(){return(0,h.jsxs)(`div`,{className:`mx-auto grid max-w-[1440px] grid-cols-[minmax(0,1fr)] gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,h.jsxs)(`div`,{className:`${Jme} flex flex-col gap-4`,children:[(0,h.jsx)(`span`,{className:`h-8 w-64 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-[520px] rounded-control bg-sunken`})]}),(0,h.jsx)(`div`,{className:`flex flex-col gap-3 pt-1`,children:(0,h.jsx)(`span`,{className:`h-3 w-28 rounded-control bg-sunken`})})]})}var Yme=`modulepreload`,Xme=function(e){return`/`+e},X2={},Z2=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Xme(t,n),t=s(t),t in X2)return;X2[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Yme,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function Zme({data:e,label:t,onDrawn:n}){let r=(0,m.useRef)(null),[i,a]=(0,m.useState)(0);return(0,m.useEffect)(()=>{let e=r.current;if(e===null)return;let t=new ResizeObserver(([e])=>{a(Math.floor(e?.contentRect.width??0))});return t.observe(e),()=>{t.disconnect()}},[]),(0,m.useEffect)(()=>{let t=r.current;if(t===null||e===void 0||i===0)return;let a=!1;return Qme(e,i).then(e=>{a||(t.replaceChildren(...e),n?.(void 0))},e=>{a||n?.(e instanceof Error?e:Error(String(e)))}),()=>{a=!0}},[e,i,n]),(0,h.jsx)(`div`,{ref:r,role:`img`,"aria-label":t,className:`flex flex-col gap-3 [&>canvas]:w-full [&>canvas]:shadow-[var(--shadow-pop)]`})}async function Qme(e,t){let n=await Z2(()=>import(`./pdf-BPNXDDg1.js`),[]),r=await Z2(()=>import(`./pdf.worker.min-zC6nfbxG.js`),[]);n.GlobalWorkerOptions.workerSrc=r.default;let i=n.getDocument({data:e.slice()}),a=await i.promise;try{let e=window.devicePixelRatio||1,n=[];for(let r=1;r<=a.numPages;r+=1){let i=await a.getPage(r),o=i.getViewport({scale:t*e/i.getViewport({scale:1}).width}),s=window.document.createElement(`canvas`);s.width=Math.floor(o.width),s.height=Math.floor(o.height),await i.render({canvas:s,viewport:o}).promise,n.push(s)}return n}finally{await i.destroy()}}var Q2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`mm`,step:1,...n===void 0?{}:{help:n}}),$2=(e,t,n)=>({kind:`number`,path:e,label:t,unit:`pt`,step:.5,...n===void 0?{}:{help:n}}),e4=(e,t,n,r)=>({kind:`number`,path:e,label:t,unit:n,step:.05,...r===void 0?{}:{help:r}}),t4=(e,t,n)=>({kind:`toggle`,path:e,label:t,...n===void 0?{}:{help:n}}),n4=(e,t,n)=>({kind:`text`,path:e,label:t,...n===void 0?{}:{help:n}}),r4=(e,t,n)=>({kind:`optional-text`,path:e,label:t,...n===void 0?{}:{help:n}}),i4=(e,t,n)=>({kind:`face`,path:[`fonts`,e],label:t,...n===void 0?{}:{help:n}}),$me=[{title:`Page`,fields:[{kind:`choice`,path:[`page`,`format`],label:`Paper size`,options:[{value:`a4`,label:`A4`},{value:`letter`,label:`US Letter`}]},Q2([`page`,`margin`],`Margins`),Q2([`page`,`contentTop`],`Text starts at`,`From the top, on pages with the header.`),{kind:`choice`,path:[`background`,`image`],label:`Background`,options:[{value:`parchment`,label:`Parchment texture`},{value:null,label:`Flat colour`}]},{kind:`color`,path:[`background`,`color`],label:`Page colour`,help:`Used when the background is a flat colour.`}]},{title:`Colours`,fields:[{kind:`color`,path:[`colors`,`heading`],label:`Headings`,help:`Also drop caps, the brand name and links.`},{kind:`color`,path:[`colors`,`text`],label:`Body text`},{kind:`color`,path:[`colors`,`muted`],label:`Muted`,help:`Dates, bullets, quotes and the dots in the contents.`},{kind:`color`,path:[`colors`,`faint`],label:`Faint`,help:`Running header and page numbers.`}]},{title:`Fonts`,fields:[i4(`body`,`Body`),i4(`strong`,`Bold text`),i4(`emphasis`,`Italic text`),i4(`heading`,`Headings`),i4(`dramatic`,`Chapter numbers and brand`,`The big number of a "Chapter 3:" heading.`),i4(`decorative`,`Tagline and title-page link`),i4(`dropCap`,`Drop caps`),i4(`footer`,`Header and page numbers`)]},{title:`Text sizes`,fields:[$2([`sizes`,`title`],`Title`),$2([`sizes`,`brand`],`Brand`),$2([`sizes`,`section`],`Top-level headings`,`Also the titles of the contents, sources and closing pages.`),$2([`sizes`,`heading`],`Second-level headings`),$2([`sizes`,`subheading`],`Third-level headings`),$2([`sizes`,`body`],`Body`),$2([`sizes`,`meta`],`Date and word count`),$2([`sizes`,`footer`],`Header and page numbers`)]},{title:`Spacing`,fields:[Q2([`spacing`,`bodyLine`],`Body line height`),Q2([`spacing`,`headingLine`],`Heading line height`),Q2([`spacing`,`subheadingLine`],`Subheading line height`),e4([`spacing`,`paragraphGap`],`After a paragraph`,`× line`),e4([`spacing`,`headingGap`],`Before a heading`,`× line`),e4([`spacing`,`itemGap`],`After a list item`,`× line`),Q2([`spacing`,`listIndent`],`List indent`),Q2([`spacing`,`quoteIndent`],`Quote indent`),Q2([`spacing`,`ruleWidth`],`Divider width`,`The short centred line a --- becomes.`)]},{title:`Drop caps`,fields:[t4([`dropCap`,`enabled`],`Drop caps`,`A large first letter after each heading.`),{kind:`choice`,path:[`dropCap`,`lines`],label:`Lines tall`,options:[{value:2,label:`2 lines`},{value:3,label:`3 lines`},{value:4,label:`4 lines`}]},e4([`dropCap`,`scale`],`Letter size`,`× lines`),Q2([`dropCap`,`gap`],`Gap beside it`),{kind:`number`,path:[`dropCap`,`minLength`],label:`Shortest paragraph`,unit:`chars`,step:10,help:`Shorter paragraphs start plainly.`},e4([`dropCap`,`minRoom`],`Room needed`,`of page`,`With less room left, the paragraph starts on the next page.`)]},{title:`Title page`,fields:[Q2([`titlePage`,`brandY`],`Brand from top`),Q2([`titlePage`,`taglineOffset`],`Tagline below brand`),Q2([`titlePage`,`titleY`],`Title from top`),Q2([`titlePage`,`titleLine`],`Title line height`),Q2([`titlePage`,`metaOffset`],`Details below title`),Q2([`titlePage`,`metaLine`],`Details line height`),t4([`titlePage`,`showDate`],`Show the date`),t4([`titlePage`,`showWordCount`],`Show the word count`),t4([`titlePage`,`cover`,`enabled`],`Thumbnail as cover`,`When the project has a thumbnail.`),Q2([`titlePage`,`cover`,`gap`],`Space around cover`),Q2([`titlePage`,`cover`,`maxHeight`],`Cover height at most`)]},{title:`Branding`,fields:[r4([`brand`,`name`],`Brand name`,`Leave empty to hide the brand.`),r4([`brand`,`tagline`],`Tagline`),r4([`brand`,`url`],`Website`,`Where the brand and its link go.`),r4([`brand`,`linkLabel`],`Link text`,`The linked line under the word count.`)]},{title:`Contents page`,fields:[t4([`contents`,`enabled`],`Contents page`),n4([`contents`,`title`],`Title`),{kind:`choice`,path:[`contents`,`depth`],label:`Lists headings down to`,options:[{value:1,label:`Top level`},{value:2,label:`Second level`},{value:3,label:`Third level`}]},Q2([`contents`,`titleOffset`],`Title from top margin`),Q2([`contents`,`firstEntryOffset`],`First entry from top margin`),Q2([`contents`,`line`],`Line height`),Q2([`contents`,`indent`],`Indent per level`)]},{title:`Header and footer`,fields:[t4([`header`,`enabled`],`Running header`,`The title at the top of each page.`),Q2([`header`,`top`],`Header from top`),{kind:`number`,path:[`header`,`maxTitleCharacters`],label:`Header title at most`,unit:`chars`,step:1},t4([`footer`,`enabled`],`Page numbers`),n4([`footer`,`text`],`Page number text`,`{page} becomes the page number.`),Q2([`footer`,`bottom`],`From the bottom`),Q2([`footer`,`reserve`],`Space kept above it`)]},{title:`Sources page`,fields:[t4([`sources`,`enabled`],`Sources page`,`The links the article and research used.`),n4([`sources`,`title`],`Title`),Q2([`sources`,`titleOffset`],`Title from top margin`),Q2([`sources`,`bodyOffset`],`List from top margin`),Q2([`sources`,`line`],`Line height`),Q2([`sources`,`gap`],`Gap between sources`)]},{title:`Closing page`,fields:[t4([`endPage`,`enabled`],`Closing page`),n4([`endPage`,`title`],`Title`),{kind:`lines`,path:[`endPage`,`lines`],label:`Text`,help:`One line each. Start with "•" for a bullet, end with ":" for a bold label, leave a line empty for a gap.`},t4([`endPage`,`showDocumentDetails`],`Add date, word and page counts`),{kind:`link`,path:[`endPage`,`link`],label:`Link`},r4([`endPage`,`closing`],`Closing line`),Q2([`endPage`,`titleOffset`],`Title from top margin`),Q2([`endPage`,`bodyOffset`],`Text from top margin`)]},{title:`PDF details`,fields:[n4([`metadata`,`author`],`Author`,`Shown in a PDF reader's document properties. {title} becomes the title.`),n4([`metadata`,`subject`],`Subject`),n4([`metadata`,`keywords`],`Keywords`),n4([`metadata`,`creator`],`Creator`)]}],a4=Kj.map(e=>({value:e,label:{Cinzel:`Cinzel`,Literata:`Literata`,times:`Times`,helvetica:`Helvetica`,courier:`Courier`}[e]}));function o4(e){let t={normal:`Regular`,medium:`Medium`,bold:`Bold`,black:`Black`,italic:`Italic`,bolditalic:`Bold italic`};return(e===`Cinzel`?[`normal`,`medium`,`bold`,`black`]:[`normal`,`bold`,`italic`,`bolditalic`]).map(e=>({value:e,label:t[e]}))}function ehe(e,t){let n=e;for(let e of t)n=n?.[e];return n}function s4(e,t,n){let[r,...i]=t;if(r===void 0)return n;let a=e[r];return{...e,[r]:i.length===0?n:s4(a,i,n)}}function the(e){let t=eM;for(let n of e)t=t?.shape?.[n];return{min:t?.minValue??0,max:t?.maxValue??1e3}}function c4(e){return`values.${e.join(`.`)}`}var l4=`pt-1`,u4=`flex min-w-0 flex-col gap-3 pt-1 lg:sticky lg:top-16`;function d4({children:e}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{children:`Library`}),(0,h.jsx)(Tc,{"aria-hidden":`true`}),e]})}function f4({children:e,back:t}){return(0,h.jsxs)(`div`,{className:`mx-auto flex max-w-[1440px] flex-col gap-3`,children:[(0,h.jsx)(aI,{tone:`danger`,title:`This can't be opened.`,children:e}),(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink underline underline-offset-[3px]`,children:t})]})}function p4({themeId:e,from:t,onLeave:n}){let{api:r}=V(),i=_(),a=I(hb(r)),o=(0,m.useId)(),[s,c]=(0,m.useState)(void 0),[l,u]=(0,m.useState)([]),[d,f]=(0,m.useState)(!1),[p,g]=(0,m.useState)(!1),v=a.data,y=e===void 0?void 0:v?.themes.find(t=>t.id===e),b=e===void 0?v?.themes.find(e=>e.id===t)??v?.builtIns.find(e=>e.name===(t??`plain`))??v?.builtIns[0]:y,x=b===void 0?void 0:{name:e===void 0?`${`label`in b?b.label:b.name} copy`:b.name,values:b.values},S=s??x,C=L({mutationFn:t=>Js(r,t,e),onSuccess:async e=>{if(!e.ok){u(e.fields);return}f(!0),await i.invalidateQueries({queryKey:hb(r).queryKey})}}),w=L({mutationFn:e=>Ys(r,e),onSuccess:async()=>{g(!1),await i.invalidateQueries({queryKey:hb(r).queryKey}),n()}});K2(d,n);let T=(0,m.useMemo)(()=>S===void 0?void 0:eM.safeParse(S.values),[S]),E=[...S===void 0||S.name.trim()===``?[]:cC(S.name),...T===void 0||T.success?[]:T.error.issues.map(e=>({field:`values.${e.path.join(`.`)}`,message:e.message})),...l];if(a.error!==null)return(0,h.jsx)(g4,{children:a.error.message});if(v===void 0)return(0,h.jsx)(Y2,{});if(S===void 0)return(0,h.jsx)(g4,{children:`That theme is gone. It may have been deleted in another tab.`});let D=(e,t)=>{c(e),u(e=>e.filter(e=>e.field!==t))},O=S.name.trim()===``?`Give the theme a name.`:E.length>0?`Fix the highlighted settings first.`:void 0,k=E.filter(e=>e.field===`name`);return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{crumb:(0,h.jsx)(d4,{children:(0,h.jsx)(fa,{to:`/document-themes`,children:`Documents`})}),title:e===void 0?`New document theme`:`Edit document theme`,meta:`How a project's PDF looks`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] items-start gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,440px)]`,children:[(0,h.jsxs)(`div`,{className:`${l4} flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(LB,{label:`Name`,tip:`library.theme.name`,...k.length===0?{}:{error:k.map(e=>e.message).join(` `)},children:(0,h.jsx)(zB,{value:S.name,onChange:e=>{D({...S,name:e.target.value},`name`)}})}),$me.map((e,t)=>(0,h.jsxs)(`details`,{open:t<2||e.fields.some(e=>m4(E,e.path)),className:`group border-t border-line`,children:[(0,h.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-3 text-title-3 font-semibold`,onClick:e=>{let t=e.currentTarget.parentElement;requestAnimationFrame(()=>{t instanceof HTMLDetailsElement&&t.open&&t.scrollIntoView?.({block:`nearest`,behavior:`smooth`})})},children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,className:`size-[14px] text-ink-2 transition-transform group-open:rotate-90 motion-reduce:transition-none`}),e.title]}),(0,h.jsx)(`div`,{className:`grid grid-cols-[minmax(0,1fr)] gap-x-5 gap-y-4 pb-4 sm:grid-cols-2`,children:e.fields.map(e=>(0,h.jsx)(ihe,{field:e,theme:S.values,problem:m4(E,e.path),onChange:t=>{D({...S,values:t},c4(e.path))}},e.path.join(`.`)))})]},e.title)),(0,h.jsx)(J2,{onDelete:e===void 0?void 0:()=>{g(!0)},blocked:O,blockedId:o,pending:C.isPending,saved:d,cancel:(0,h.jsx)(CS,{to:`/document-themes`,variant:`secondary`,children:`Cancel`}),errors:[C.error,w.error].flatMap(e=>e===null?[]:[e.message]),onSave:()=>{C.mutate(S)}})]}),(0,h.jsx)(rhe,{values:T?.success===!0?S.values:void 0})]}),(0,h.jsx)(Hy,{open:p,title:`Delete "${S.name}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:w.isPending,onConfirm:()=>{e!==void 0&&w.mutate(e)},onCancel:()=>{g(!1)}})]})}var nhe={"values.page.format":`library.theme.page.format`,"values.page.margin":`library.theme.page.margin`,"values.page.contentTop":`library.theme.page.content-top`,"values.background.image":`library.theme.background.image`,"values.background.color":`library.theme.background.color`,"values.colors.heading":`library.theme.colors.heading`,"values.colors.text":`library.theme.colors.text`,"values.colors.muted":`library.theme.colors.muted`,"values.colors.faint":`library.theme.colors.faint`,"values.fonts.body":`library.theme.fonts.body`,"values.fonts.strong":`library.theme.fonts.strong`,"values.fonts.emphasis":`library.theme.fonts.emphasis`,"values.fonts.heading":`library.theme.fonts.heading`,"values.fonts.dramatic":`library.theme.fonts.dramatic`,"values.fonts.decorative":`library.theme.fonts.decorative`,"values.fonts.dropCap":`library.theme.fonts.drop-cap`,"values.fonts.footer":`library.theme.fonts.footer`,"values.sizes.title":`library.theme.sizes.title`,"values.sizes.brand":`library.theme.sizes.brand`,"values.sizes.section":`library.theme.sizes.section`,"values.sizes.heading":`library.theme.sizes.heading`,"values.sizes.subheading":`library.theme.sizes.subheading`,"values.sizes.body":`library.theme.sizes.body`,"values.sizes.meta":`library.theme.sizes.meta`,"values.sizes.footer":`library.theme.sizes.footer`,"values.spacing.bodyLine":`library.theme.spacing.body-line`,"values.spacing.headingLine":`library.theme.spacing.heading-line`,"values.spacing.subheadingLine":`library.theme.spacing.subheading-line`,"values.spacing.paragraphGap":`library.theme.spacing.paragraph-gap`,"values.spacing.headingGap":`library.theme.spacing.heading-gap`,"values.spacing.itemGap":`library.theme.spacing.item-gap`,"values.spacing.listIndent":`library.theme.spacing.list-indent`,"values.spacing.quoteIndent":`library.theme.spacing.quote-indent`,"values.spacing.ruleWidth":`library.theme.spacing.rule-width`,"values.dropCap.enabled":`library.theme.drop-cap.enabled`,"values.dropCap.lines":`library.theme.drop-cap.lines`,"values.dropCap.scale":`library.theme.drop-cap.scale`,"values.dropCap.gap":`library.theme.drop-cap.gap`,"values.dropCap.minLength":`library.theme.drop-cap.min-length`,"values.dropCap.minRoom":`library.theme.drop-cap.min-room`,"values.titlePage.brandY":`library.theme.title-page.brand-y`,"values.titlePage.taglineOffset":`library.theme.title-page.tagline-offset`,"values.titlePage.titleY":`library.theme.title-page.title-y`,"values.titlePage.titleLine":`library.theme.title-page.title-line`,"values.titlePage.metaOffset":`library.theme.title-page.meta-offset`,"values.titlePage.metaLine":`library.theme.title-page.meta-line`,"values.titlePage.showDate":`library.theme.title-page.show-date`,"values.titlePage.showWordCount":`library.theme.title-page.show-word-count`,"values.titlePage.cover.enabled":`library.theme.title-page.cover`,"values.titlePage.cover.gap":`library.theme.title-page.cover-gap`,"values.titlePage.cover.maxHeight":`library.theme.title-page.cover-height`,"values.brand.name":`library.theme.brand.name`,"values.brand.tagline":`library.theme.brand.tagline`,"values.brand.url":`library.theme.brand.url`,"values.brand.linkLabel":`library.theme.brand.link-label`,"values.contents.enabled":`library.theme.contents.enabled`,"values.contents.title":`library.theme.contents.title`,"values.contents.depth":`library.theme.contents.depth`,"values.contents.titleOffset":`library.theme.contents.title-offset`,"values.contents.firstEntryOffset":`library.theme.contents.first-entry-offset`,"values.contents.line":`library.theme.contents.line`,"values.contents.indent":`library.theme.contents.indent`,"values.header.enabled":`library.theme.header.enabled`,"values.header.top":`library.theme.header.top`,"values.header.maxTitleCharacters":`library.theme.header.max-title`,"values.footer.enabled":`library.theme.footer.enabled`,"values.footer.text":`library.theme.footer.text`,"values.footer.bottom":`library.theme.footer.bottom`,"values.footer.reserve":`library.theme.footer.reserve`,"values.sources.enabled":`library.theme.sources.enabled`,"values.sources.title":`library.theme.sources.title`,"values.sources.titleOffset":`library.theme.sources.title-offset`,"values.sources.bodyOffset":`library.theme.sources.body-offset`,"values.sources.line":`library.theme.sources.line`,"values.sources.gap":`library.theme.sources.gap`,"values.endPage.enabled":`library.theme.end-page.enabled`,"values.endPage.title":`library.theme.end-page.title`,"values.endPage.lines":`library.theme.end-page.lines`,"values.endPage.showDocumentDetails":`library.theme.end-page.details`,"values.endPage.link":`library.theme.end-page.link`,"values.endPage.closing":`library.theme.end-page.closing`,"values.endPage.titleOffset":`library.theme.end-page.title-offset`,"values.endPage.bodyOffset":`library.theme.end-page.body-offset`,"values.metadata.author":`library.theme.metadata.author`,"values.metadata.subject":`library.theme.metadata.subject`,"values.metadata.keywords":`library.theme.metadata.keywords`,"values.metadata.creator":`library.theme.metadata.creator`};function m4(e,t){let n=c4(t),r=e.filter(e=>e.field===n||e.field.startsWith(`${n}.`));return r.length===0?void 0:r.map(e=>e.message).join(` `)}function rhe({values:e}){let{api:t}=V(),[n,r]=(0,m.useState)(),[i,a]=(0,m.useState)(`busy`),[o,s]=(0,m.useState)(void 0),c=e===void 0?void 0:JSON.stringify(e);(0,m.useEffect)(()=>{if(c===void 0)return;let e=new AbortController,n=window.setTimeout(()=>{a(`busy`),Xs(t,JSON.parse(c),e.signal).then(async e=>({bytes:new Uint8Array(await e.arrayBuffer()),blob:e})).then(({bytes:t,blob:n})=>{e.signal.aborted||r({bytes:t,url:URL.createObjectURL(n)})},t=>{e.signal.aborted||(s(t instanceof Error?t.message:String(t)),a(`failed`))})},450);return()=>{window.clearTimeout(n),e.abort()}},[t,c]),(0,m.useEffect)(()=>()=>{n!==void 0&&URL.revokeObjectURL(n.url)},[n]);let l=(0,m.useCallback)(e=>{if(e===void 0){a(`idle`);return}s(e.message),a(`failed`)},[]),u=e===void 0?`Paused until the highlighted settings are fixed.`:i===`busy`?`Updating…`:i===`failed`?`The preview couldn't be made: ${o??`unknown error`}`:`A sample article with this theme. Your projects use their own text and thumbnail.`;return(0,h.jsxs)(`div`,{className:u4,children:[(0,h.jsx)(W,{title:`Preview`,info:`library.theme.preview`,size:`small`,className:`pb-0`,children:n===void 0?null:(0,h.jsxs)(TS,{href:n.url,target:`_blank`,rel:`noreferrer`,variant:`secondary`,size:`small`,children:[(0,h.jsx)(Mc,{"aria-hidden":`true`,strokeWidth:1.75}),`Open full size`]})}),(0,h.jsx)(`div`,{className:`max-h-[calc(100vh-220px)] min-h-[320px] overflow-y-auto rounded-media bg-sunken p-3`,children:(0,h.jsx)(Zme,{data:n?.bytes,label:`The sample article laid out with this theme`,onDrawn:l})}),(0,h.jsx)(`p`,{role:`status`,className:i===`failed`?`m-0 text-small text-danger`:`m-0 text-small text-ink-2`,children:u})]})}function ihe({field:e,theme:t,problem:n,onChange:r}){let i=(0,m.useId)(),a=ehe(t,e.path),o=nhe[c4(e.path)],s=o===void 0?null:(0,h.jsx)(U,{id:o,label:e.label,className:`-my-1`}),c=n=>{r(s4(t,e.path,n))},l=[e.help===void 0?``:`${i}-help`,n===void 0?``:`${i}-error`].filter(e=>e!==``).join(` `),u=(0,h.jsxs)(h.Fragment,{children:[e.help===void 0?null:(0,h.jsx)(`p`,{id:`${i}-help`,className:`sl-field__help m-0`,children:e.help}),n===void 0?null:(0,h.jsx)(`p`,{id:`${i}-error`,className:`sl-field__error m-0`,children:n})]}),d={id:i,"aria-invalid":n!==void 0,"aria-describedby":l===``?void 0:l};switch(e.kind){case`toggle`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{...d,type:`checkbox`,checked:a===!0,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked)}}),e.label]}),s]}),u]});case`number`:{let{min:t,max:n}=the(e.path);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(zB,{...d,type:`number`,inputMode:`decimal`,min:t,max:n,step:e.step,className:`w-28`,value:typeof a==`number`&&Number.isFinite(a)?a:``,onChange:e=>{c(e.target.value===``?NaN:Number(e.target.value))}}),(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:e.unit})]})})}case`color`:{let t=typeof a==`string`?a:``,n=/^#?[0-9a-f]{6}$/i.test(t)?`#${t.replace(`#`,``)}`:/^#?[0-9a-f]{3}$/i.test(t)?`#${[...t.replace(`#`,``)].map(e=>e+e).join(``)}`:`#000000`;return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`color`,"aria-label":`${e.label} colour`,value:n,className:`h-8 w-10 cursor-pointer rounded-control border border-line-strong bg-transparent p-0.5`,onChange:e=>{c(e.target.value)}}),(0,h.jsx)(zB,{...d,className:`w-28 font-mono`,value:t,onChange:e=>{c(e.target.value)}})]})})}case`text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value)}})});case`optional-text`:return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(zB,{...d,value:typeof a==`string`?a:``,onChange:e=>{c(e.target.value===``?null:e.target.value)}})});case`choice`:{let t=e.options.findIndex(e=>e.value===a);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsx)(VB,{...d,value:String(t),onChange:t=>{let n=e.options[Number(t.target.value)];n!==void 0&&c(n.value)},children:e.options.map((e,t)=>(0,h.jsx)(`option`,{value:String(t),children:e.label},e.label))})})}case`face`:{let t=a,n=o4(t.family);return(0,h.jsx)(h4,{id:i,label:e.label,notes:u,info:s,children:(0,h.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(VB,{...d,"aria-label":`${e.label} font`,value:t.family,onChange:e=>{let n=a4.find(t=>t.value===e.target.value);if(n===void 0)return;let r=o4(n.value).some(e=>e.value===t.style);c({...t,family:n.value,style:r?t.style:`normal`})},children:a4.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(VB,{"aria-label":`${e.label} style`,value:t.style,onChange:e=>{c({...t,style:e.target.value})},children:n.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(zB,{type:`number`,"aria-label":`${e.label} letter spacing in millimetres`,title:`Letter spacing (mm)`,step:.01,className:`w-20`,value:Number.isFinite(t.letterSpacing)?t.letterSpacing:``,onChange:e=>{c({...t,letterSpacing:e.target.value===``?NaN:Number(e.target.value)})}})]})})}case`lines`:return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:i,className:`sl-field__label`,children:e.label}),s]}),(0,h.jsx)(BB,{...d,rows:8,value:Array.isArray(a)?a.join(`
274
274
  `):``,onChange:e=>{c(e.target.value.split(`
275
275
  `))}}),u]});case`link`:{let t=a;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 sm:col-span-2`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(`label`,{htmlFor:i,className:`flex min-h-8 items-center gap-3 text-small font-semibold`,children:[(0,h.jsx)(`input`,{id:i,type:`checkbox`,checked:t!==null,className:`size-4 accent-accent`,onChange:e=>{c(e.currentTarget.checked?{text:`Visit the website`,url:null}:null)}}),e.label]}),s]}),t===null?null:(0,h.jsxs)(`span`,{className:`grid grid-cols-[minmax(0,1fr)] gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(zB,{"aria-label":`Link text`,placeholder:`Link text`,value:t.text,onChange:e=>{c({...t,text:e.target.value})}}),(0,h.jsx)(zB,{"aria-label":`Link address`,placeholder:`https://`,value:t.url??``,onChange:e=>{c({...t,url:e.target.value===``?null:e.target.value})}})]}),u]})}}}function h4({id:e,label:t,notes:n,info:r,children:i}){return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{htmlFor:e,className:`sl-field__label`,children:t}),r]}),i,n]})}function g4({children:e}){return(0,h.jsx)(f4,{back:(0,h.jsx)(fa,{to:`/document-themes`,children:`Back to Documents`}),children:e})}var ahe=4e3;function _4(e){return e.match(/\s+|[^\s]+/gu)??[]}function ohe(e,t){let n=_4(e),r=_4(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i+=1;let a=0;for(;a<n.length-i&&a<r.length-i&&n[n.length-1-a]===r[r.length-1-a];)a+=1;let o=[];y4(o,`same`,n.slice(0,i).join(``));let s=n.slice(i,n.length-a),c=r.slice(i,r.length-a);for(let e of che(s,c))y4(o,e.op,e.text);return y4(o,`same`,n.slice(n.length-a).join(``)),o}function v4(e,t){let n=t===`before`?`added`:`removed`;return e.filter(e=>e.op!==n)}function she(e){let t=t=>e.filter(e=>e.op===t).reduce((e,t)=>e+_4(t.text).filter(e=>e.trim()!==``).length,0);return{added:t(`added`),removed:t(`removed`)}}function y4(e,t,n){if(n===``)return;let r=e.at(-1);r!==void 0&&r.op===t?e[e.length-1]={op:t,text:r.text+n}:e.push({op:t,text:n})}function che(e,t){if(e.length===0&&t.length===0)return[];if(e.length===0)return[{op:`added`,text:t.join(``)}];if(t.length===0)return[{op:`removed`,text:e.join(``)}];let n=e.length,r=t.length,i=Math.min(n+r,ahe),a=i+1,o=new Int32Array(2*i+3),s=[],c=!1;for(let l=0;l<=i&&!c;l+=1){s.push(o.slice());let i=o.slice();for(let s=-l;s<=l;s+=2){let u=s===-l||s!==l&&(o[a+s-1]??0)<(o[a+s+1]??0)?o[a+s+1]??0:(o[a+s-1]??0)+1,d=u-s;for(;u<n&&d<r&&e[u]===t[d];)u+=1,d+=1;if(i[a+s]=u,u>=n&&d>=r){c=!0;break}}o=i}if(!c)return[{op:`removed`,text:e.join(``)},{op:`added`,text:t.join(``)}];let l=[],u=n,d=r;for(let n=s.length-1;n>=0;--n){let r=s[n]??new Int32Array,i=u-d,o=i===-n||i!==n&&(r[a+i-1]??0)<(r[a+i+1]??0),c=o?i+1:i-1,f=r[a+c]??0,p=f-c;for(;u>f&&d>p;)l.push({op:`same`,text:e[u-1]??``}),--u,--d;n>0&&(o?l.push({op:`added`,text:t[d-1]??``}):l.push({op:`removed`,text:e[u-1]??``}),u=f,d=p)}let f=[];for(let e of l.reverse())y4(f,e.op,e.text);return f}function b4({before:e,after:t,beforeLabel:n,afterLabel:r}){let i=(0,m.useMemo)(()=>ohe(e,t),[e,t]),a=she(i);return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:a.added===0&&a.removed===0?`The two texts are the same.`:`${String(a.added)} ${a.added===1?`word`:`words`} added, ${String(a.removed)} removed.`}),(0,h.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,h.jsx)(x4,{label:n,parts:v4(i,`before`)}),(0,h.jsx)(x4,{label:r,parts:v4(i,`after`)})]})]})}function x4({label:e,parts:t}){return(0,h.jsxs)(`section`,{"aria-label":e,className:`flex min-w-0 flex-col gap-1`,children:[(0,h.jsx)(`h4`,{className:`sl-kicker m-0`,children:e}),(0,h.jsx)(`div`,{className:`min-w-0 whitespace-pre-wrap break-words border-l-2 border-line pl-3 text-small leading-relaxed text-ink`,children:lhe(t).map(({key:e,part:t})=>t.op===`removed`?(0,h.jsx)(`del`,{className:`rounded-[2px] bg-danger-tint text-danger line-through`,children:t.text},e):t.op===`added`?(0,h.jsx)(`ins`,{className:`rounded-[2px] bg-accent-tint text-accent-ink no-underline`,children:t.text},e):(0,h.jsx)(`span`,{children:t.text},e))})]})}function lhe(e){let t=0;return e.map(e=>{let n=`${e.op}-${String(t)}`;return t+=e.text.length,{key:n,part:e}})}var S4={versions:(e,t)=>[`library-history`,e,t],usedBy:(e,t)=>[`library-used-by`,e,t]};function C4(e,t){let{api:n}=V();return I({queryKey:S4.versions(e,t),queryFn:()=>Hs(n,e,t)})}function uhe(e,t){let{api:n}=V();return I({queryKey:S4.usedBy(e,t),queryFn:()=>Us(n,e,t)})}function w4({item:e,id:t,name:n,onClose:r}){let{api:i}=V(),a=_(),o=C4(e,t),s=o.data?.versions??[],[c,l]=(0,m.useState)({}),u=c.after??s[0]?.version,d=c.before??s[1]?.version??u,f=s.find(e=>e.version===d),p=s.find(e=>e.version===u),[g,v]=(0,m.useState)(),y=L({mutationFn:n=>Ws(i,e,t,n),onSuccess:async(n,r)=>{v(`Restored version ${String(r)} as a new version.`),l({}),await Promise.all([a.invalidateQueries({queryKey:S4.versions(e,t)}),a.invalidateQueries({queryKey:e===`prompt`?H.prompts:H.entries})])},onError:()=>v(void 0)}),b=s[0]?.version;return(0,h.jsx)(HP,{open:!0,title:`History of ${n}`,onClose:r,className:`sm:w-[min(1080px,100vw)]`,children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[o.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-body text-danger`,children:`The history couldn't be read: ${o.error.message}`}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`Compare`,as:`h3`}),(0,h.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,h.jsx)(LB,{label:`Older`,tip:`library.history.compare`,children:(0,h.jsx)(VB,{value:d===void 0?``:String(d),disabled:s.length===0,onChange:e=>l(t=>({...t,before:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:E4(e,b)},e.version))})}),(0,h.jsx)(LB,{label:`Newer`,tip:`library.history.compare`,children:(0,h.jsx)(VB,{value:u===void 0?``:String(u),disabled:s.length===0,onChange:e=>l(t=>({...t,after:Number(e.currentTarget.value)})),children:s.map(e=>(0,h.jsx)(`option`,{value:e.version,children:E4(e,b)},e.version))})})]}),f===void 0||p===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o.isPending?`Loading the versions…`:`No versions to compare.`}):(0,h.jsxs)(h.Fragment,{children:[f.name===p.name?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Renamed from "${f.name}" to "${p.name}".`}),(0,h.jsx)(b4,{before:f.body,after:p.body,beforeLabel:`Version ${String(f.version)}`,afterLabel:`Version ${String(p.version)}`})]})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Versions`,as:`h3`,info:`library.history.versions`}),(0,h.jsx)(PH,{label:`Versions of ${n}`,children:s.map(e=>(0,h.jsx)(FH,{title:`Version ${String(e.version)}`,meta:T4(e),actions:e.version===b?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Current`}):(0,h.jsx)(B,{size:`small`,"aria-label":`Restore version ${String(e.version)}`,disabled:y.isPending,disabledReason:`Restoring a version`,onClick:()=>{v(void 0),y.mutate(e.version)},children:`Restore`})},e.version))}),(0,h.jsx)(v1,{tone:y.error===null?`success`:`error`,children:y.error?.message??g})]})]})})}function T4(e){return`${e.author} · ${D4(e.createdAt)}${e.restoredFrom===null?``:` · restored from version ${String(e.restoredFrom)}`}`}function E4(e,t){return`Version ${String(e.version)}${e.version===t?` (current)`:``} · ${D4(e.createdAt)}`}function D4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}function O4({item:e,id:t,name:n,kicker:r,meta:i,body:a,slots:o,actions:s,onOpenHistory:c}){return(0,h.jsxs)(`section`,{"aria-label":`${n} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(W,{title:n,kicker:r,meta:i,className:`pb-0`,children:s}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`div`,{className:`m-0 max-h-[420px] min-w-0 overflow-y-auto whitespace-pre-wrap break-words rounded-media bg-sunken p-4 font-mono text-small text-ink-2`,children:a}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No keywords. It runs as written.`}):(0,h.jsx)(`ul`,{"aria-label":`Keywords`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:o.map(e=>(0,h.jsx)(`li`,{children:(0,h.jsx)(HB,{children:`{{${e}}}`})},e))})]}),(0,h.jsx)(dhe,{item:e,id:t}),(0,h.jsx)(fhe,{item:e,id:t,name:n,onOpenHistory:c})]})}function dhe({item:e,id:t}){let n=uhe(e,t),r=n.data;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Used by`,as:`h3`,className:`pb-0`,info:`library.used-by`,...r===void 0?{}:{meta:phe(r)}}),n.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`What uses it couldn't be read: ${n.error.message}`}),r===void 0?null:r.templates.length+r.schedules.length+r.projects.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Nothing uses it yet.`}):(0,h.jsxs)(PH,{label:`Used by`,children:[r.templates.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/templates`,children:e.name}),meta:`Template`},`t-${e.id}`)),r.schedules.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`schedules`,schedule:e.id},children:e.name}),meta:e.status===`paused`?`Schedule · paused`:`Schedule`},`s-${e.id}`)),r.projects.map(e=>(0,h.jsx)(FH,{title:(0,h.jsx)(fa,{to:`/projects/$projectId`,params:{projectId:e.id},children:e.title}),meta:`Project${e.totalRevisions===0?``:` · ${String(e.revisions)} of ${String(e.totalRevisions)} ${e.totalRevisions===1?`revision`:`revisions`}${e.current?`, including the current one`:`, not the current one`}`}`},`p-${e.id}`))]})]})}function fhe({item:e,id:t,name:n,onOpenHistory:r}){let i=C4(e,t),a=i.data?.versions??[],[o,s]=a;return(0,h.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{title:`History`,as:`h3`,className:`pb-0`,info:`library.history`,...o===void 0?{}:{meta:`${k4(a.length,`version`)} · latest ${T4(o)}`},children:(0,h.jsx)(B,{size:`small`,"aria-label":`Compare versions of ${n}`,onClick:r,children:`Compare versions`})}),i.error===null?null:(0,h.jsx)(`p`,{className:`m-0 text-small text-danger`,children:`The history couldn't be read: ${i.error.message}`}),o===void 0?null:s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Only one version so far.`}):(0,h.jsx)(b4,{before:s.body,after:o.body,beforeLabel:`Version ${String(s.version)}`,afterLabel:`Version ${String(o.version)}`})]})}function phe(e){return[k4(e.templates.length,`template`),k4(e.schedules.length,`schedule`),k4(e.projects.length,`project`)].join(`, `)}function k4(e,t){return`${String(e)} ${t}${e===1?``:`s`}`}function A4(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{dateStyle:`medium`})}var j4=`min-[1180px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,M4=`grid-cols-1 2xl:grid-cols-[minmax(0,1fr)_auto]`;function N4({label:e}){return(0,h.jsx)(`ul`,{"aria-label":`${e}, loading`,"aria-busy":`true`,className:`sl-list m-0 list-none p-0`,children:[0,1,2].map(e=>(0,h.jsx)(`li`,{className:`sl-row`,"aria-hidden":`true`,children:(0,h.jsxs)(`span`,{className:`flex flex-col gap-2 py-0.5`,children:[(0,h.jsx)(`span`,{className:`h-3 w-40 rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-3 w-56 rounded-control bg-sunken`})]})},e))})}function P4({what:e,message:t,onRetry:n}){return(0,h.jsx)(aI,{tone:`danger`,title:`The ${e} couldn't be loaded.`,actions:(0,h.jsx)(B,{size:`small`,onClick:n,children:`Try again`}),children:t})}function F4({name:e,edit:t,duplicate:n,play:r,onHistory:i,onDelete:a,className:o}){return(0,h.jsxs)(`div`,{role:`group`,"aria-label":`Actions for ${e}`,className:z(`flex flex-wrap items-center gap-0.5`,o),children:[t,n,r===void 0?null:(0,h.jsx)(B,{variant:`quiet`,size:`small`,"aria-label":`Use ${e} in Play`,title:r.blocked,disabled:r.run===void 0||r.blocked!==void 0,onClick:r.run,children:`Use in Play`}),i===void 0?null:(0,h.jsx)(Py,{size:`small`,label:`History of ${e}`,onClick:i,children:(0,h.jsx)(Jc,{"aria-hidden":`true`})}),(0,h.jsx)(Py,{size:`small`,label:`Delete ${e}`,onClick:a,children:(0,h.jsx)($c,{"aria-hidden":`true`})})]})}var mhe=[{to:`/prompts`,label:`Prompts`},{to:`/entries`,label:`Intros & Outros`},{to:`/templates`,label:`Templates`},{to:`/document-themes`,label:`Documents`},{to:`/narration-aliases`,label:`Aliases`},{to:`/ab-results`,label:`A/B results`}];function hhe(){return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(XK,{title:`Library`,meta:`Prompts, intros and outros, templates, document themes, narration aliases and A/B results`}),(0,h.jsx)(Cfe,{items:mhe,label:`Library sections`,className:`mb-6`}),(0,h.jsx)(ghe,{}),(0,h.jsx)(Oa,{})]})}function ghe(){let e=Ji(),t=Ra({select:e=>e.location}),n=t.search,r=PB(t.pathname===`/prompts`?n.kind:void 0),i=jB(t.pathname===`/entries`?n.category:void 0);return jx({id:`library.new-prompt`,title:`New prompt`,group:`Library`,keywords:[`create`,`article`,`image`,`thumbnail`],run:()=>{e({to:`/prompts/new`,search:{kind:r}})}}),jx({id:`library.new-entry`,title:`New intro or outro`,group:`Library`,keywords:[`create`,`entry`],run:()=>{e({to:`/entries/new`,search:{category:i}})}}),jx({id:`library.new-document-theme`,title:`New document theme`,group:`Library`,keywords:[`create`,`pdf`,`theme`],run:()=>{e({to:`/document-themes/new`,search:{from:`plain`}})}}),jx({id:`library.open-prompts`,title:`Open prompts`,group:`Library`,run:()=>{e({to:`/prompts`,search:{kind:`article`}})}}),jx({id:`library.open-entries`,title:`Open intros and outros`,group:`Library`,keywords:[`entries`],run:()=>{e({to:`/entries`,search:{category:`intro`}})}}),jx({id:`library.open-templates`,title:`Open templates`,group:`Library`,keywords:[`setups`],run:()=>{e({to:`/templates`})}}),jx({id:`library.open-document-themes`,title:`Open document themes`,group:`Library`,keywords:[`pdf`,`documents`],run:()=>{e({to:`/document-themes`})}}),null}function I4({children:e,action:t,className:n}){return(0,h.jsxs)(`div`,{"data-slot":`library-toolbar`,className:z(`mb-5 flex min-h-9 flex-wrap items-center gap-x-4 gap-y-3`,n),children:[(0,h.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-3`,children:e}),t===void 0?null:(0,h.jsx)(Iy,{className:`ml-auto shrink-0`,children:t})]})}function _he(){let{api:e}=V(),t=_(),n=I(hb(e)),[r,i]=(0,m.useState)(void 0),[a,o]=(0,m.useState)(void 0),s=L({mutationFn:t=>Ys(e,t),onSettled:async()=>{o(void 0),await t.invalidateQueries({queryKey:H.documentThemes})}}),c=n.data,l=r!==void 0&&`saved`in r?c?.themes.find(e=>e.id===r.saved):void 0,u=r!==void 0&&`builtIn`in r?c?.builtIns.find(e=>e.name===r.builtIn):void 0,d=l===void 0&&u===void 0?c?.themes[0]:void 0,f=l??d,p=f===void 0?u??c?.builtIns[0]:void 0;return(0,h.jsxs)(`div`,{children:[(0,h.jsx)(I4,{action:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:`plain`},variant:`primary`,children:`New theme`}),children:(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`How a project's PDF looks. Pick one on the Document row in Play or in Edit project.`})}),n.error===null?null:(0,h.jsx)(P4,{what:`document themes`,message:n.error.message,onRetry:()=>void n.refetch()}),c===void 0?n.error===null?(0,h.jsx)(N4,{label:`Document themes`}):null:(0,h.jsx)(QK,{className:j4,list:(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Your themes`,as:`h3`,className:`pb-0`,info:`library.themes.yours`}),c.themes.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No themes of your own yet. Copy a built-in below to start one.`}):(0,h.jsx)(PH,{label:`Your themes`,children:c.themes.map(e=>(0,h.jsx)(FH,{className:M4,lead:(0,h.jsx)(H4,{colors:e.values.colors}),title:e.name,meta:`${L4(e.values)} · updated ${A4(e.updatedAt)}`,selected:e.id===f?.id,onSelect:()=>i({saved:e.id}),actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/document-themes/$themeId`,params:{themeId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),onDelete:()=>o(e)})},e.id))})]}),(0,h.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{title:`Built in`,as:`h3`,className:`pb-0`,info:`library.themes.built-in`}),(0,h.jsx)(PH,{label:`Built-in themes`,children:c.builtIns.map(e=>(0,h.jsx)(FH,{className:M4,lead:(0,h.jsx)(H4,{colors:e.values.colors}),title:e.label,meta:L4(e.values),selected:e.name===p?.name,onSelect:()=>i({builtIn:e.name}),actions:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:e.name},"aria-label":`Copy ${e.label}`,variant:`quiet`,size:`small`,children:`Copy`})},e.name))})]})]}),detail:f===void 0?p===void 0?null:(0,h.jsx)(B4,{name:p.label,kicker:`Built in`,meta:`Built-in themes can't be changed. Copy one to make it yours.`,values:p.values,action:(0,h.jsx)(CS,{to:`/document-themes/new`,search:{from:p.name},size:`small`,children:`Copy theme`})}):(0,h.jsx)(B4,{name:f.name,kicker:`Your theme`,meta:`Updated ${A4(f.updatedAt)}`,values:f.values,action:(0,h.jsx)(CS,{to:`/document-themes/$themeId`,params:{themeId:f.id},size:`small`,children:`Edit theme`})})}),s.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The theme wasn't deleted.`,className:`mt-4`,children:s.error.message}),(0,h.jsx)(Hy,{open:a!==void 0,title:`Delete "${a?.name??``}"?`,consequence:`Projects that used it keep their own copy of its settings.`,confirmLabel:`Delete theme`,pending:s.isPending,onConfirm:()=>{a!==void 0&&s.mutate(a.id)},onCancel:()=>o(void 0)})]})}function L4(e){return`${e.page.format===`a4`?`A4`:`Letter`} · ${R4(e.fonts.body.family)} body`}function R4(e){return a4.find(t=>t.value===e)?.label??e}function z4(e){return e.startsWith(`#`)?e:`#${e}`}function B4({name:e,kicker:t,meta:n,values:r,action:i}){let a=[[`Headings`,r.colors.heading],[`Text`,r.colors.text],[`Muted`,r.colors.muted],[`Header and page numbers`,r.colors.faint]],o=[[`Body`,r.fonts.body],[`Headings`,r.fonts.heading],[`Drop cap`,r.fonts.dropCap]];return(0,h.jsxs)(`section`,{"aria-label":`${e} details`,className:`flex min-w-0 flex-col gap-6`,children:[(0,h.jsx)(W,{title:e,kicker:t,meta:n,className:`pb-0`,children:i}),(0,h.jsxs)(`dl`,{className:`m-0 grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-[max-content_minmax(0,1fr)]`,children:[a.map(([e,t])=>(0,h.jsx)(V4,{label:e,children:(0,h.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`size-4 rounded-full border border-line`,style:{backgroundColor:z4(t)}}),(0,h.jsx)(`span`,{className:`font-mono text-small`,children:z4(t)})]})},e)),o.map(([e,t])=>(0,h.jsx)(V4,{label:`${e} font`,children:`${R4(t.family)}, ${t.style}`},`font-${e}`)),(0,h.jsx)(V4,{label:`Page`,children:`${r.page.format===`a4`?`A4`:`Letter`}, ${r.background.image===`parchment`?`parchment`:`flat ${z4(r.background.color)}`} background`})]})]})}function V4({label:e,children:t}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`dt`,{className:`text-small text-ink-2`,children:e}),(0,h.jsx)(`dd`,{className:`m-0 min-w-0 text-body text-ink`,children:t})]})}function H4({colors:e}){return(0,h.jsx)(`span`,{"aria-hidden":`true`,className:`flex shrink-0 gap-1`,children:[e.heading,e.text,e.muted].map((e,t)=>(0,h.jsx)(`span`,{className:`size-3 rounded-full border border-line`,style:{backgroundColor:z4(e)}},t))})}function U4(e){let t=e.map(e=>e.message).join(` `);return`The name wasn't saved. ${t===``?`Pick another name and press Save name again.`:t}`}function W4({name:e,onSelect:t,onRename:n,tip:r=`library.inline-rename`,maxLength:i=200}){let a=Ry(),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(e),[u,d]=(0,m.useState)(null),[f,p]=(0,m.useState)(!1),g=(0,m.useRef)(!1),_=async e=>{try{return await n(e)}catch(e){return`The name wasn't saved: ${e instanceof Error?e.message:`Slopify didn't answer.`} Check that Slopify is running, then press Save name again.`}},v=async()=>{let t=c.trim();if(t===e){s(!1),d(null);return}if(t===``){d(`Write a name first, or press Cancel to keep the old one.`);return}if(g.current)return;g.current=!0,p(!0);let n=await _(t);if(g.current=!1,p(!1),n!==null){d(n);return}s(!1),d(null),a(`Renamed “${e}” to “${t}”.`,`success`,{label:`Undo`,run:()=>void _(e).then(t=>{t===null?a(`Renamed back to “${e}”.`,`success`):a(t,`error`)})})},y=()=>{s(!1),l(e),d(null)};return o?(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-1`,children:[(0,h.jsx)(zB,{autoFocus:!0,"aria-label":`New name for ${e}`,"aria-invalid":u!==null,maxLength:i,value:c,className:`min-w-0 flex-1`,onChange:e=>{l(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v()):e.key===`Escape`&&(e.preventDefault(),y())}}),(0,h.jsx)(B,{size:`small`,variant:`primary`,disabled:f,onClick:()=>void v(),children:f?`Saving…`:`Save name`}),(0,h.jsx)(B,{size:`small`,variant:`quiet`,disabled:f,onClick:y,children:`Cancel`}),(0,h.jsx)(U,{id:r,label:`Rename`})]}),u===null?null:(0,h.jsx)(`span`,{role:`alert`,className:`text-small font-normal text-danger`,children:u})]}):(0,h.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[t===void 0?(0,h.jsx)(`span`,{className:`min-w-0 break-words`,children:e}):(0,h.jsx)(IH,{onSelect:t,className:`min-w-0`,children:e}),(0,h.jsx)(Py,{size:`small`,label:`Rename ${e}`,onClick:()=>{l(e),s(!0)},children:(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75})})]})}function vhe({category:e,onCategory:t,onUseInPlay:n,playBlocked:r}){let{api:i}=V(),a=_(),o=I(mb(i)),[s,c]=(0,m.useState)(``),l=(0,m.useRef)(null),u=Mx(l,`intros and outros`),[d,f]=(0,m.useState)(void 0),[p,g]=(0,m.useState)(void 0),[v,y]=(0,m.useState)(void 0),b=L({mutationFn:e=>ec(i,e),onSettled:async()=>{g(void 0),await a.invalidateQueries({queryKey:H.entries})}}),x=async(e,t)=>{let n=await Ks(i,{category:e.category,mode:e.mode,name:t,body:e.body},e.id);return await a.invalidateQueries({queryKey:H.entries}),n.ok?null:U4(n.fields)},S=o.data?.entries.filter(t=>t.category===e),C=s.trim().toLowerCase(),w=C===``?S:S?.filter(e=>e.name.toLowerCase().includes(C)||e.body.toLowerCase().includes(C)),T=w?.find(e=>e.id===d)??w?.[0];return(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(I4,{action:(0,h.jsx)(CS,{to:`/entries/new`,search:{category:e},variant:`primary`,children:`New intro or outro`}),children:[(0,h.jsx)(zB,{type:`search`,ref:l,"aria-label":`Search intros and outros`,"aria-keyshortcuts":Ux(u),placeholder:`Search intros and outros`,value:s,className:`w-full min-w-0 sm:w-64`,onChange:e=>c(e.target.value)}),(0,h.jsx)(Vb,{label:`Entry category`,value:e,options:TB.map(e=>({...e,label:`${e.label}s`})),onChange:t,tip:`library.entry.category`})]}),o.error===null?null:(0,h.jsx)(P4,{what:`intros and outros`,message:o.error.message,onRetry:()=>void o.refetch()}),w===void 0||S===void 0?o.error===null?(0,h.jsx)(N4,{label:`Intros and outros`}):null:S.length===0?(0,h.jsx)(bhe,{category:e}):(0,h.jsx)(QK,{className:j4,list:w.length===0?(0,h.jsx)(`p`,{className:`m-0 py-3 text-small text-ink-2`,children:`No ${e}s match "${s.trim()}".`}):(0,h.jsx)(PH,{label:`${DB(e)}s`,children:w.map(e=>(0,h.jsx)(FH,{className:M4,title:(0,h.jsx)(W4,{name:e.name,onSelect:()=>f(e.id),onRename:t=>x(e,t)}),meta:yhe(e),selected:e.id===T?.id,actions:(0,h.jsx)(F4,{name:e.name,edit:(0,h.jsx)(CS,{to:`/entries/$entryId`,params:{entryId:e.id},"aria-label":`Edit ${e.name}`,variant:`quiet`,size:`small`,children:`Edit`}),duplicate:(0,h.jsx)(CS,{to:`/entries/new`,search:{category:e.category,from:e.id},"aria-label":`Duplicate ${e.name}`,variant:`quiet`,size:`small`,children:`Duplicate`}),play:{run:n===void 0?void 0:()=>n(e),blocked:r},onHistory:()=>y(e),onDelete:()=>g(e)})},e.id))}),detail:T===void 0?null:(0,h.jsx)(O4,{item:`entry`,id:T.id,name:T.name,kicker:`${DB(T.category)} · ${OB(T.mode)}`,meta:`Updated ${A4(T.updatedAt)}`,body:T.body,slots:T.slots,actions:(0,h.jsx)(CS,{to:`/entries/$entryId`,params:{entryId:T.id},size:`small`,children:`Edit ${T.category}`}),onOpenHistory:()=>y(T)},T.id)}),b.error===null?null:(0,h.jsx)(aI,{tone:`danger`,title:`The ${e} wasn't deleted.`,className:`mt-4`,children:b.error.message}),v===void 0?null:(0,h.jsx)(w4,{item:`entry`,id:v.id,name:v.name,onClose:()=>y(void 0)},v.id),(0,h.jsx)(Hy,{open:p!==void 0,title:p===void 0?``:`Delete "${p.name}"?`,consequence:`Moves it to the trash for 30 days (Settings → Trash). Projects that used it keep their text.`,confirmLabel:`Delete ${p?.category??e}`,pending:b.isPending,onConfirm:()=>{p!==void 0&&b.mutate(p.id)},onCancel:()=>g(void 0)})]})}function yhe(e){return`${OB(e.mode)} · ${k4(e.slots.length,`keyword`)} · updated ${A4(e.updatedAt)}`}function bhe({category:e}){let t=e===`intro`?`before`:`after`;return(0,h.jsx)(T1,{title:`No ${e}s yet`,children:`An ${e} is narrated ${t} the body in the run's voice.`})}function xhe({name:e,className:t}){return(0,h.jsx)(`span`,{"data-slot-chip":e,className:z(`animate-tick-in rounded-control border border-line-strong bg-sunken px-2 py-0.5 font-mono text-label text-ink-2 motion-reduce:animate-none`,t),children:e})}function G4({slots:e,body:t,lint:n,lintId:r,noSlots:i=`No slots. This prompt runs as written.`}){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(W,{title:`Detected slots`,info:`library.slots`,size:`small`,className:`pb-0`}),e.length>0?(0,h.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.map(e=>(0,h.jsx)(xhe,{name:e,className:`px-2 py-1`},e))}):t.trim()===``?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Slots appear here as you type {{name}}.`}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:i}),n.length===0?null:(0,h.jsxs)(`div`,{id:r,className:`flex flex-col gap-2 border-t border-line pt-3`,children:[(0,h.jsx)(`span`,{className:`sl-kicker text-danger`,children:n.length===1?`1 slot error`:`${String(n.length)} slot errors`}),n.map(e=>(0,h.jsx)(`span`,{className:`text-small text-danger`,children:e.message},e.message))]})]})}function K4({className:e,...t}){return(0,h.jsx)(uy,{"data-slot":`label`,className:z(`engraved block select-none text-ink-3`,e),...t})}function q4({className:e,...t}){return(0,h.jsx)(nte,{"data-slot":`toggle-group`,className:z(`inline-flex w-fit items-stretch overflow-hidden rounded-control border border-line-strong`,e),...t})}function J4({className:e,...t}){return(0,h.jsx)(ste,{"data-slot":`toggle-group-item`,className:z(`min-h-8 shrink-0 border-r border-line-strong px-3 py-1 text-label text-ink-2 last:border-r-0`,`transition-colors duration-150 ease-out motion-reduce:transition-none hover:bg-raised hover:text-ink`,`data-[state=on]:bg-raised data-[state=on]:text-ink data-[state=on]:shadow-[inset_0_-2px_0_var(--color-accent)]`,`disabled:cursor-not-allowed disabled:opacity-40`,e),...t})}function Y4({label:e,value:t,options:n,describedBy:r,tip:i,onPick:a}){let o=(0,m.useId)();return(0,h.jsxs)(`div`,{...zb,children:[(0,h.jsxs)(`div`,{className:`mb-1 flex items-center gap-1`,children:[(0,h.jsx)(K4,{id:o,children:e}),i===void 0?null:(0,h.jsx)(U,{id:i,label:e,className:`-my-1`})]}),(0,h.jsx)(q4,{type:`single`,value:t,"aria-labelledby":o,"aria-describedby":r,onValueChange:e=>{let t=n.find(t=>t.value===e);t!==void 0&&a(t.value)},children:n.map(e=>(0,h.jsx)(J4,{value:e.value,children:e.label},e.value))})]})}function She(e){return X4(e.name,e.body)}function Che(e){return X4(e.name,e.body)}function X4(e,t){let n=[],r=e.trim();if(r===``?n.push({field:`name`,message:`Enter a name.`}):r.length>200&&n.push({field:`name`,message:`Keep the name to 200 characters or fewer.`}),t.trim()===``)return n.push({field:`body`,message:`Enter the text.`}),n;if(t.length>1e5)return n.push({field:`body`,message:`The text is too long. Keep it to ${String(_M)} characters or fewer.`}),n;for(let e of MK(t).errors)n.push({field:`body`,message:whe(e,t)});return n}function whe(e,t){let n=The(t,e.at);switch(e.kind){case`unclosed`:return`The \`{{\` at ${n} is never closed. Add \`}}\` after the keyword name.`;case`empty`:return`The keyword at ${n} has no name. Write a name between \`{{\` and \`}}\`.`;case`nested`:return`The keyword at ${n} contains a brace. Keywords cannot be placed inside other keywords.`}}function The(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`
276
276
  `),i=n.split(`
@@ -297,8 +297,8 @@ Obelisks`})}):e.mode===`yaml`?(0,h.jsx)(LB,{id:`schedule-topics-yaml`,label:`Top
297
297
  `).trim(),chapters:o.join(`
298
298
  `),hashtags:i,tags:t.trim(),pinnedComment:(n.pinnedComment??``).trim(),titles:(n.titles??``).trim()}}function Rye(e){let[t=``,...n]=e.trim().split(/\s+/u);return v5(t)!==void 0&&n.length>0}function zye(e){return[e.summary.trim(),e.chapters.trim(),e.hashtags.trim()].filter(e=>e!==``).join(`
299
299
 
300
- `)}function Bye(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function x5(e,t){let n=n=>Bye(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function S5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}function Vye(e,t,n,r){return`https://studio.youtube.com/video/${e}/edit#slopify-ab=${t}&p=${encodeURIComponent(n)}&s=${String(r??0)}`}var C5=e=>[`project`,e,`youtube-videos`];function w5(e){let{api:t}=V();return I({queryKey:C5(e),queryFn:()=>ws(t,e)})}function Hye(e){let t=e?.find(e=>e.short===null&&e.uploadState===`done`);return t===void 0?void 0:`https://youtu.be/${t.videoId}`}function Uye(e){return e===null?`Video`:`Short ${String(e)}`}function Wye(e){if(e.uploadState===`filled`)return`Filled in Studio, but not scheduled or published yet (cancelled, or left as a draft). Upload it again from the extension, or paste its link once it is up.`;let t=[`On YouTube.`];return e.finishState===`waiting`&&t.push(`Related video, end screen and captions are being set.`),e.finishState===`failed`&&t.push(`Details touches failed: ${e.finishMessage??`no reason given`}`),e.commentState===`waiting`&&t.push(`The comment is pinned once it is public.`),e.commentState===`done`&&t.push(`Comment pinned.`),e.commentState===`failed`&&t.push(`Pinning the comment failed: ${e.commentMessage??`no reason given`}`),t.join(` `)}function Gye({projectId:e,shorts:t}){let n=w5(e),{api:r}=V(),i=I({queryKey:[`project`,e,`youtube-stats`],queryFn:()=>ms(r,e)}),a=[null,...Array.from({length:t},(e,t)=>t+1)];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-field__label`,children:`On YouTube`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The extension keeps each upload's link when Studio confirms it. Paste a link for an upload made by hand. A/B test opens the video in Studio with A/B Testing set up; press Set test and Save there.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:a.map(t=>(0,h.jsx)(Kye,{projectId:e,short:t,video:n.data?.find(e=>e.short===t),stats:i.data?.find(e=>e.short===t)},t??0))})]})}function Kye({projectId:e,short:t,video:n,stats:r}){let{api:i}=V(),a=_(),o=(0,m.useId)(),s=n===void 0?``:`https://youtu.be/${n.videoId}`,[c,l]=(0,m.useState)(),u=c??s,[d,f]=(0,m.useState)(),p=L({mutationFn:()=>Ts(i,e,t,u),onSuccess:t=>{a.setQueryData(C5(e),t),l(void 0),f(void 0)},onError:e=>f(e.message)});return(0,h.jsxs)(`li`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`label`,{className:`w-[64px] shrink-0 text-small text-ink-2`,htmlFor:o,children:Uye(t)}),(0,h.jsx)(zB,{id:o,type:`url`,className:`min-w-[220px] flex-1 sm:max-w-[360px]`,placeholder:`https://youtu.be/…`,value:u,onChange:e=>l(e.currentTarget.value)}),u.trim()===s?null:(0,h.jsx)(B,{type:`button`,size:`small`,disabled:p.isPending,onClick:()=>p.mutate(),children:`Save link`}),n===void 0||n.uploadState!==`done`||t!==null?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,children:`A/B test`})}),(0,h.jsx)(f8,{children:[[`both`,`Titles and thumbnails`],[`titles`,`Titles`],[`thumbnails`,`Thumbnails`]].map(([r,i])=>(0,h.jsx)(p8,{onSelect:()=>window.open(Vye(n.videoId,r,e,t),`_blank`,`noopener`),children:i},r))})]})]}),n===void 0&&d===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small ${d!==void 0||n?.finishState===`failed`||n?.commentState===`failed`?`text-danger`:`text-ink-3`}`,children:d??(n===void 0?``:Wye(n))}),r===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small tabular-nums text-ink-2`,children:qye(r)})]})}function qye(e){let t=[];if(e.views!==null&&t.push(`${e.views.toLocaleString()} views`),e.ctr!==null&&t.push(`${String(e.ctr)}% CTR${e.impressions===null?``:` of ${e.impressions.toLocaleString()} impressions`}`),e.averageViewSeconds!==null){let n=Math.round(e.averageViewSeconds),r=n>=3600?`${String(Math.floor(n/3600))}:${String(Math.floor(n%3600/60)).padStart(2,`0`)}:${String(n%60).padStart(2,`0`)}`:`${String(Math.floor(n/60))}:${String(n%60).padStart(2,`0`)}`;t.push(`${r} average view`)}return t.push(`read ${new Date(e.readAt).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}`),t.join(` · `)}var Jye=Y({number:q().int().positive(),first:q().int().positive(),last:q().int().positive(),start:q().finite().nonnegative(),end:q().finite().positive(),title:K(),description:K(),hashtags:J(K()),why:K(),text:K(),seed:K().nullable().optional()}),Yye=.25,Xye=.4;function T5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(Yye,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(Xye,(s-a.end)/2)));return{start:E5(c),end:E5(l)}}Y({first:JD([q(),K()]),last:JD([q(),K()]),title:K(),description:K(),hashtags:J(K()),why:K().optional()});function E5(e){return Math.round(e*1e3)/1e3}var Zye=Y({shorts:J(Jye),durationSeconds:q().finite().nonnegative().optional(),sentences:J(Y({start:q().finite().nonnegative(),end:q().finite().nonnegative(),text:K()})).optional()});function Qye(e){if(e!=null)try{let t=Zye.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function $ye(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=T5(o,n,r,ebe(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function ebe(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function D5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:FK(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:FK(n,e.config.values)]))}}}}function tbe(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:xN(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function O5(e,t,n){return D5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function nbe(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function k5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=V(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await zo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await nbe(r.signal);let e=(await Mo(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Bo(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(LB,{label:e,id:s,children:(0,h.jsx)(zB,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(B,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var A5=`shorts:pick`,j5=e=>`shorts:${String(e)}`;function M5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],A5])]}}function N5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],j5(t)])]}}function rbe(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=Qye(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function ibe({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Ak,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Vk(o)}),l=[...n,...P5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...P5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(A5)===!0,f=rbe(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(dV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(abe,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(w6,{settings:cV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?cbe(n,e):O5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=Bk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(obe,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function abe({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(k5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function obe({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:T5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(U,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==A5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:()=>o(M5(e)),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(sbe,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(j5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):$ye(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?N5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==j5(t.number))})},t.number))})]})}function sbe({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(B,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(LB,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(VB,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(U,{id:`project.shorts.remake`})]})]})]})}function P5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function cbe(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return D5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var lbe=Y({shorts:J(Y({number:q(),first:q().optional(),last:q().optional(),start:q(),end:q(),title:K(),description:K(),hashtags:J(K())}))});function ube({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=c8(n,e),a=l8(i,`shorts`),o=L5(i),s=j8(t.id),[c,l]=(0,m.useState)(),u=F5(i,`short_video`,o),d=t.config.shorts,f=w5(t.id),p=d?.fullVideoLink??Hye(f.data),g=(0,m.use)(W8),_=(0,m.use)(G8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let v=g&&_!==void 0&&d?.enabled===!0,y=e=>{let t=Ik(e,p),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(E8,{files:o.map(e=>({output:u.find(t=>I5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:v&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...zb,children:[(0,h.jsx)(B,{onClick:()=>_({section:`shorts`,change:M5}),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(u0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(dbe,{clip:n,projectId:t.id,review:M8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>I5(e,n)),stills:F5(i,`short_image`,o).filter(e=>I5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:p,wanted:zk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:mbe(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>y(n),...v?{onRemake:()=>_({section:`shorts`,change:e=>N5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(v1,{tone:c?.tone??`info`,children:c?.text})]})}function dbe({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=g8(r),g=g8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(c0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(l0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:uF(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(fbe,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(I8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Iy,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(ES,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Py,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(Py,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(f8,{align:`start`,children:(0,h.jsxs)(p8,{onSelect:d,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function fbe({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(kS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function F5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>I5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function I5(e,t){return e.meta.short===t.number}function L5(e){return pbe(O8(l8(e,`shorts`)).data)}function pbe(e){if(e===void 0)return[];try{let t=lbe.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function mbe(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function hbe({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=V(),a=Ry(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=l8(c8(n,e),o?`audio_export`:`video`),c=c8(n,e),l=l8(c,`subtitles_srt`),u=l8(c,`subtitles_vtt`),d=l8(c,`youtube_description`),f=l8(c,`youtube_tags`),p=l8(c,`audio_mp3`),m=l8(c,`audio_m4b`),g=F5(c,`short_video`,L5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=g8(s),v=g8(gbe(n)),y=_be(t.id,d,f,s?.durationMs??null),b=g8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=dF(e.progressCurrent??0,e.progressTotal??0);return jx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await M0(i,{projectId:t.id,asset:C3(s),folder:_?.folder??null});e.opened||a(`${N0} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(b8,{children:r}):(0,h.jsxs)(b8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:QP(e,t.config)?`Preparing subtitles · ${String(dF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:rF(nF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)(Y8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(c0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,square:t.format===`1:1`,className:t.format===`9:16`?`max-w-[360px]`:t.format===`1:1`?`max-w-[640px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(E8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(D8,{children:[uF(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:ck(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||PO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:PO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function gbe(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function _be(e,t,n,r){let{api:i}=V(),a=O8(t).data,o=O8(n).data,s=I({queryKey:H.youtubeEdits(e),queryFn:()=>zs(i,e),enabled:t!==void 0});return a===void 0?[]:vbe(S5(x5(b5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function vbe(e,t){return y5(e,t).text.split(`
301
- `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:v5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function ybe(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(Yve,{...e});case`audio`:return(0,h.jsx)(aye,{...e});case`images`:return(0,h.jsx)(Pye,{...e});case`video`:return(0,h.jsx)(hbe,{...e});case`document`:return(0,h.jsx)(lye,{...e});case`research`:case`thumbnail`:return null}}Y({summary:K(),chapters:J(Y({start:JD([K(),q()]),title:K()})),hashtags:J(K()),tags:J(K()),pinnedComment:K(),titles:J(K())});function R5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var z5=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`});function B5(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function bbe({projectId:e}){let{api:t}=V(),n=_(),r=Ry(),i=[`studio`,`project-releases`,e],a=I({queryKey:i,queryFn:()=>us(t,e)}),[o,s]=(0,m.useState)({}),c=(I({queryKey:[`studio`,`releases`,`swap`,8],queryFn:()=>cs(t,8)}).data?.entries??[]).flatMap(t=>t.project===null||t.project.id===e?[]:[{id:t.project.id,title:t.project.title,at:t.at}]),l=L({mutationFn:n=>ls(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),n.invalidateQueries({queryKey:[`studio`,`project-releases`,t]}),r(`Swapped release times with ${c.find(e=>e.id===t)?.title??`the other video`}; each one's shorts moved with it.`,`success`)},onError:e=>r(`The times weren't swapped: ${e.message}`,`error`)}),u=L({mutationFn:n=>ds(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),s(e=>{let{[t.short]:n,...r}=e;return r}),r(t.at===null?`Not scheduled: set its time in Studio yourself, or pick one here.`:`Saved the release time.`,`success`)},onError:e=>r(`The time wasn't saved: ${e.message}`,`error`)});if(a.data===void 0)return null;let{items:d,free:f,leadHours:p}=a.data;return d.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Release`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{as:`h3`,size:`small`,title:`Release`,meta:`Upload and schedule each one at least ${String(p)} hours before it goes out.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:d.map(e=>{let t=e.short===0?`Long video`:`Short ${String(e.short)}`,n=o[e.short]??(e.at===null?``:B5(e.at)),r=n!==(e.at===null?``:B5(e.at)),i=!e.onYoutube&&e.uploadBy!==null&&Date.parse(e.uploadBy)<Date.now();return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,h.jsx)(`span`,{className:`w-[86px] shrink-0 text-small font-semibold`,children:t}),(0,h.jsx)(zB,{"aria-label":`${t}: release`,type:`datetime-local`,className:`w-[210px]`,value:n,onChange:t=>{let n=t.currentTarget.value;s(t=>({...t,[e.short]:n}))}}),r?(0,h.jsx)(B,{type:`button`,size:`small`,disabled:n===``||u.isPending,onClick:()=>u.mutate({short:e.short,at:new Date(n).toISOString()}),children:`Save`}):null,e.short===0&&f.length>0?(0,h.jsx)(VB,{"aria-label":`Take a free time of the posting plan`,className:`w-[230px]`,value:``,onChange:e=>{let t=f.find(t=>t.longAt===e.currentTarget.value);t!==void 0&&u.mutate({short:0,at:t.longAt,line:t.row})},options:[{value:``,label:`Free plan times…`},...f.map(e=>({value:e.longAt,label:z5.format(new Date(e.longAt))}))]}):null,e.at!==null&&e.short===0&&c.length>0?(0,h.jsx)(VB,{"aria-label":`Swap release times with another video`,className:`w-[260px]`,value:``,disabled:l.isPending,onChange:e=>{e.currentTarget.value!==``&&l.mutate(e.currentTarget.value)},options:[{value:``,label:`Swap with…`},...c.map(e=>({value:e.id,label:`${e.title.split(` | `)[0]??e.title} · ${z5.format(new Date(e.at))}`}))]}):null,e.at!==null&&e.short===0?(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:u.isPending,onClick:()=>u.mutate({short:0,at:null}),children:`Not scheduled`}):null,(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.onYoutube?(0,h.jsx)(kS,{children:`✓ on YouTube`}):e.uploadBy===null?`No time yet`:i?(0,h.jsx)(kS,{tone:`failed`,children:`Late · upload now`}):`Upload by ${z5.format(new Date(e.uploadBy))}`})]},e.short)})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Every video's times are together in`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`releases`},children:`Calendar → Releases`}),`.`]})]})}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function xbe({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=V(),a=_(),o=c8(n,e),s=l8(o,`youtube_description`),c=l8(o,`youtube_tags`),l=l8(o,`youtube_pinned_comment`),u=l8(o,`youtube_titles`),d=O8(s).data,f=O8(c).data,p=O8(l).data,g=O8(u).data,v=(0,m.use)(K8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=I({queryKey:H.youtubeEdits(t.id),queryFn:()=>zs(i,t.id)}),T=I({queryKey:H.projectChannelLinks(t.id),queryFn:()=>Rs(i,t.id)}),[E,D]=(0,m.useState)(),O=Ry(),k=e=>a.setQueryData(H.youtubeEdits(t.id),e),A=L({mutationFn:e=>Bs(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),j=(0,m.useRef)({});if(jx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:nP.copyDescription,run:()=>j.current.description===void 0?O(`The description has not been written yet.`,`info`):j.current.description()}),jx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>j.current.tags===void 0?O(`The tags have not been written yet.`,`info`):j.current.tags()}),jx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>j.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):j.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let M=d===void 0?void 0:b5(d,f??``,{pinnedComment:p,titles:g}),ee=x5(M,w.data?.fields??{}),N=S5(ee),P=Ej(T.data?.links??[],w.data?.links??[]),F=l8(o,`video`),te=y5(N.chapters,F?.durationMs===null||F?.durationMs===void 0?void 0:F.durationMs/1e3),ne=Lye(te.adjustments),re=Oj(zye({...N,chapters:te.text}),P),ie=Oj(N.tags,P),ae=Oj(N.pinnedComment,P),oe=[...re.unknown,...ie.unknown,...ae.unknown].filter((e,t,n)=>n.findIndex(t=>Tj(t)===Tj(e))===t),se=G5(ie.text),ce=M!==void 0,le=ae.text.trim()!==``,ue=N.titles.split(`
300
+ `)}function Bye(e,t){return t===void 0?{text:e??``,edited:!1}:e===void 0||t.base===e?{text:t.text,edited:!0}:t.text===e?{text:e,edited:!1}:{text:t.text,edited:!0,pending:e}}function x5(e,t){let n=n=>Bye(e?.[n],t[n]);return{summary:n(`summary`),chapters:n(`chapters`),hashtags:n(`hashtags`),tags:n(`tags`),pinnedComment:n(`pinnedComment`),titles:n(`titles`)}}function S5(e){return{summary:e.summary.text,chapters:e.chapters.text,hashtags:e.hashtags.text,tags:e.tags.text,pinnedComment:e.pinnedComment.text,titles:e.titles.text}}function Vye(e,t,n,r){return`https://studio.youtube.com/video/${e}/edit#slopify-ab=${t}&p=${encodeURIComponent(n)}&s=${String(r??0)}`}var C5=e=>[`project`,e,`youtube-videos`];function w5(e){let{api:t}=V();return I({queryKey:C5(e),queryFn:()=>ws(t,e)})}function Hye(e){let t=e?.find(e=>e.short===null&&e.uploadState===`done`);return t===void 0?void 0:`https://youtu.be/${t.videoId}`}function Uye(e){return e===null?`Video`:`Short ${String(e)}`}function Wye(e){if(e.uploadState===`filled`)return`Filled in Studio, but not scheduled or published yet (cancelled, or left as a draft). Upload it again from the extension, or paste its link once it is up.`;let t=[`On YouTube.`];return e.finishState===`waiting`&&t.push(`Related video, end screen and captions are being set.`),e.finishState===`failed`&&t.push(`Details touches failed: ${e.finishMessage??`no reason given`}`),e.commentState===`waiting`&&t.push(`The comment is pinned once it is public.`),e.commentState===`done`&&t.push(`Comment pinned.`),e.commentState===`failed`&&t.push(`Pinning the comment failed: ${e.commentMessage??`no reason given`}`),t.join(` `)}function Gye({projectId:e,shorts:t}){let n=w5(e),{api:r}=V(),i=I({queryKey:[`project`,e,`youtube-stats`],queryFn:()=>ms(r,e)}),a=[null,...Array.from({length:t},(e,t)=>t+1)];return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,h.jsx)(`div`,{className:`sl-field__label`,children:`On YouTube`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`The extension keeps each upload's link when Studio confirms it. Paste a link for an upload made by hand. A/B test opens the video in Studio with A/B Testing set up; press Set test and Save there.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:a.map(t=>(0,h.jsx)(Kye,{projectId:e,short:t,video:n.data?.find(e=>e.short===t),stats:i.data?.find(e=>e.short===t)},t??0))})]})}function Kye({projectId:e,short:t,video:n,stats:r}){let{api:i}=V(),a=_(),o=(0,m.useId)(),s=n===void 0?``:`https://youtu.be/${n.videoId}`,[c,l]=(0,m.useState)(),u=c??s,[d,f]=(0,m.useState)(),p=t=>{a.setQueryData(C5(e),t),l(void 0),f(void 0)},g=L({mutationFn:()=>Ts(i,e,t,u),onSuccess:p,onError:e=>f(e.message)}),v=L({mutationFn:()=>Ts(i,e,t,``),onSuccess:p,onError:e=>f(`${e.message} Press Deleted on YouTube again, or clear the link and save.`)});return(0,h.jsxs)(`li`,{className:`flex flex-col gap-1`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`label`,{className:`w-[64px] shrink-0 text-small text-ink-2`,htmlFor:o,children:Uye(t)}),(0,h.jsx)(zB,{id:o,type:`url`,className:`min-w-[220px] flex-1 sm:max-w-[360px]`,placeholder:`https://youtu.be/…`,value:u,onChange:e=>l(e.currentTarget.value)}),u.trim()===s?null:(0,h.jsx)(B,{type:`button`,size:`small`,disabled:g.isPending,onClick:()=>g.mutate(),children:`Save link`}),n===void 0||u.trim()!==s?null:(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:v.isPending,onClick:()=>v.mutate(),children:`Deleted on YouTube`}),n===void 0||n.uploadState!==`done`||t!==null?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,children:`A/B test`})}),(0,h.jsx)(f8,{children:[[`both`,`Titles and thumbnails`],[`titles`,`Titles`],[`thumbnails`,`Thumbnails`]].map(([r,i])=>(0,h.jsx)(p8,{onSelect:()=>window.open(Vye(n.videoId,r,e,t),`_blank`,`noopener`),children:i},r))})]})]}),n===void 0&&d===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small ${d!==void 0||n?.finishState===`failed`||n?.commentState===`failed`?`text-danger`:`text-ink-3`}`,children:d??(n===void 0?``:Wye(n))}),r===void 0?null:(0,h.jsx)(`p`,{className:`m-0 pl-18 text-small tabular-nums text-ink-2`,children:qye(r)})]})}function qye(e){let t=[];if(e.views!==null&&t.push(`${e.views.toLocaleString()} views`),e.ctr!==null&&t.push(`${String(e.ctr)}% CTR${e.impressions===null?``:` of ${e.impressions.toLocaleString()} impressions`}`),e.averageViewSeconds!==null){let n=Math.round(e.averageViewSeconds),r=n>=3600?`${String(Math.floor(n/3600))}:${String(Math.floor(n%3600/60)).padStart(2,`0`)}:${String(n%60).padStart(2,`0`)}`:`${String(Math.floor(n/60))}:${String(n%60).padStart(2,`0`)}`;t.push(`${r} average view`)}return t.push(`read ${new Date(e.readAt).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}`),t.join(` · `)}var Jye=Y({number:q().int().positive(),first:q().int().positive(),last:q().int().positive(),start:q().finite().nonnegative(),end:q().finite().positive(),title:K(),description:K(),hashtags:J(K()),why:K(),text:K(),seed:K().nullable().optional()}),Yye=.25,Xye=.4;function T5(e,t,n,r){let i=e[t-1],a=e[n-1];if(i===void 0||a===void 0||t>n)return;let o=e[t-2]?.end??0,s=e[n]?.start??r,c=Math.max(0,i.start-Math.max(0,Math.min(Yye,(i.start-o)/2))),l=Math.min(r,a.end+Math.max(0,Math.min(Xye,(s-a.end)/2)));return{start:E5(c),end:E5(l)}}Y({first:JD([q(),K()]),last:JD([q(),K()]),title:K(),description:K(),hashtags:J(K()),why:K().optional()});function E5(e){return Math.round(e*1e3)/1e3}var Zye=Y({shorts:J(Jye),durationSeconds:q().finite().nonnegative().optional(),sentences:J(Y({start:q().finite().nonnegative(),end:q().finite().nonnegative(),text:K()})).optional()});function Qye(e){if(e!=null)try{let t=Zye.safeParse(JSON.parse(e));return t.success?t.data:void 0}catch{return}}function $ye(e,t,n,r,i,a=[]){let o=e.sentences;if(o===void 0||o.length===0)return`These shorts were picked before clips could be adjusted by hand. Use Pick different moments, then adjust the new clips.`;if(!e.shorts.some(e=>e.number===t))return`There is no short ${String(t)} any more. Reload the page and choose again.`;if(!Number.isInteger(n)||!Number.isInteger(r)||n<1||r>o.length||n>r)return`Choose a start sentence that comes before the end sentence, between 1 and ${String(o.length)}.`;let s=T5(o,n,r,ebe(e));if(s===void 0)return`Choose a start and an end sentence from the transcript.`;let c=s.end-s.start;if(c<i.minSeconds-.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, shorter than the ${String(i.minSeconds)}-second minimum. Start it earlier or end it later.`;if(c>i.maxSeconds+.01)return`Short ${String(t)} would last ${String(Math.round(c))} seconds, longer than the ${String(i.maxSeconds)}-second maximum. Start it later or end it earlier.`;let l=a.find(e=>e.number!==t&&n<=e.last&&r>=e.first);if(l!==void 0)return`Short ${String(t)} would share sentences with short ${String(l.number)} (sentences ${String(l.first)}-${String(l.last)}). Choose a range that doesn't overlap it.`}function ebe(e){return e.durationSeconds??e.sentences?.at(-1)?.end??0}function D5(e){let t=Object.fromEntries(Object.entries(e.content.imageDefinitions).map(([t,n])=>{let r=n.templateKey===null||n.templateKey===void 0?null:e.content.promptTemplates[n.templateKey]??null;return[t,r===null||n.source!==`generate`?n:{...n,prompt:FK(r,e.config.values)}]}));return{...e,content:{...e.content,imageDefinitions:t},config:{...e.config,rendered:{...e.config.rendered,...Object.fromEntries(Object.entries(e.content.promptTemplates).map(([t,n])=>[t,n===null?e.config.rendered[t]??``:FK(n,e.config.values)]))}}}}function tbe(e,t,n){let r=t===`article`&&n===`off`,i={...e.config.sources,[t]:n,...t===`images`&&n===`off`?{video:`off`}:{},...r?{research:`off`,audio:`off`,document:`off`,...e.config.sources.thumbnail===`prompt_by_llm`?{thumbnail:`from_prompt`}:{}}:{}},{imageScenes:a,...o}=e.config;return{...e,config:{...r?o:e.config,sources:i,subtitles:xN(e.config.subtitles,i),...r?{youtubeDescription:!1,...e.config.shorts===void 0?{}:{shorts:{...e.config.shorts,enabled:!1}}}:{}}}}function O5(e,t,n){return D5({...e,content:{...e.content,promptTemplates:{...e.content.promptTemplates,[t]:n}}})}function nbe(e){return new Promise((t,n)=>{if(e.aborted){n(Error(`Upload canceled.`));return}let r=()=>{clearTimeout(i),n(Error(`Upload canceled.`))},i=setTimeout(()=>{e.removeEventListener(`abort`,r),t()},200);e.addEventListener(`abort`,r,{once:!0})})}function k5({label:e,kind:t,disabled:n=!1,onReady:r,onPending:i,accept:a}){let{api:o}=V(),s=(0,m.useId)(),[c,l]=(0,m.useState)(),[u,d]=(0,m.useState)(!1),f=(0,m.useRef)(void 0),p=(0,m.useRef)(r);p.current=r;let g=(0,m.useRef)(i);g.current=i;let _=(0,m.useRef)(!0);(0,m.useEffect)(()=>(_.current=!0,()=>{_.current=!1,f.current?.abort(),g.current(!1)}),[]);async function v(e){if(n||f.current!==void 0)return;let r=new AbortController;f.current=r,d(!0),g.current(!0),l(void 0);let i;try{let n=await zo(o,t,e);for(i=n.id,r.signal.throwIfAborted();n.state!==`staged`;){await nbe(r.signal);let e=(await Mo(o)).files.find(e=>e.id===n.id);if(r.signal.throwIfAborted(),e===void 0)throw Error(`The upload stopped before the file finished copying. Choose the file again.`);n=e}p.current(n)}catch(e){let t=r.signal.aborted?`Upload canceled.`:e instanceof Error?e.message:String(e);if(i!==void 0)try{await Bo(o,i)}catch(e){t+=` The partial upload couldn't be removed (${e instanceof Error?e.message:String(e)}); use Clean orphan files in Settings → Backup & storage to clear it.`}_.current?l(t):t.includes(`partial upload couldn't be removed`)&&console.error(t)}finally{f.current===r&&(f.current=void 0,_.current&&(d(!1),g.current(!1)))}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(LB,{label:e,id:s,children:(0,h.jsx)(zB,{id:s,type:`file`,disabled:u||n,accept:a??(t===`audio`?`audio/*`:`image/png,image/jpeg,image/webp`),onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t!==void 0&&v(t)}})}),u?(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`p`,{role:`status`,className:`text-small text-ink-2`,children:`Copying upload…`}),(0,h.jsx)(B,{type:`button`,onClick:()=>f.current?.abort(),children:`Cancel upload`})]}):null,c===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:c})]})}var A5=`shorts:pick`,j5=e=>`shorts:${String(e)}`;function M5(e){let{shortsRanges:t,...n}=e.content;return{...e,content:n,regenerate:[...new Set([...e.regenerate??[],A5])]}}function N5(e,t){return{...e,regenerate:[...new Set([...e.regenerate??[],j5(t)])]}}function rbe(e){let t=e.pieces.find(e=>e.key===`shorts:pick`&&e.selected&&e.piece.state===`done`),n=Qye(t?.piece.payload);return t===void 0||n===void 0?void 0:{fingerprint:t.fingerprint,picked:n}}function ibe({edit:e,view:t,prompts:n,problem:r,onChange:i,onPending:a}){let o=e.config.shorts??Ak,[s,c]=(0,m.useState)({count:String(o.count),minSeconds:String(o.minSeconds),maxSeconds:String(o.maxSeconds),...Vk(o)}),l=[...n,...P5(t,`shorts`,`shorts`,t.revision.config.shorts?.prompt,n),...P5(t,`image`,`shortsImage`,t.revision.config.shorts?.imagePrompt,n)],u={enabled:o.enabled,...s,prompt:o.prompt??``,imagePrompt:o.imagePrompt??``,...o.titleOnScreen===void 0?{}:{titleOnScreen:o.titleOnScreen}},d=e.regenerate?.includes(A5)===!0,f=rbe(t);return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(dV,{value:u,prompts:l,narrated:e.config.sources.audio!==`off`,problem:r,music:(0,h.jsx)(abe,{edit:e,disabled:!o.enabled,onChange:i,onPending:a}),preview:(0,h.jsx)(w6,{settings:cV(u,e.config.subtitles?.fontId??`default`)}),onChange:t=>{c({count:t.count,minSeconds:t.minSeconds,maxSeconds:t.maxSeconds,...t.musicVolume===void 0?{}:{musicVolume:t.musicVolume},...t.speed===void 0?{}:{speed:t.speed},...t.fullVideoLink===void 0?{}:{fullVideoLink:t.fullVideoLink}});let n=e;for(let[e,r,i,a]of[[`shorts`,`shorts`,u.prompt,t.prompt],[`shortsImage`,`image`,u.imagePrompt,t.imagePrompt]]){if(i===a)continue;let t=l.find(e=>e.kind===r&&e.name===a);n=t===void 0?cbe(n,e):O5(n,e,t.body)}let r=e=>{let t=Number(e);return e.trim()===``||!Number.isFinite(t)?0:t},a=Bk(t);i({...n,config:{...n.config,shorts:{enabled:t.enabled,count:r(t.count),minSeconds:r(t.minSeconds),maxSeconds:r(t.maxSeconds),...t.prompt===``?{}:{prompt:t.prompt},...t.imagePrompt===``?{}:{imagePrompt:t.imagePrompt},...a,...a.musicVolume!==void 0&&!Number.isFinite(a.musicVolume)?{musicVolume:-1}:{},...a.speed!==void 0&&!Number.isFinite(a.speed)?{speed:0}:{}}}})}}),f!==void 0&&o.enabled?(0,h.jsx)(obe,{edit:e,view:t,pick:f,settings:o,again:d,problem:r,onChange:i}):null]})}function abe({edit:e,disabled:t,onChange:n,onPending:r}){let i=(e.uploads??[]).some(e=>e.destination.kind===`shortsMusic`),a=e.content.shortsMusic!==void 0;return(0,h.jsxs)(`div`,{className:`basis-full space-y-2`,children:[i||a?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-ink-2`,children:[i?`New background music chosen. It is mixed under every short after you save and press Remake.`:`Background music plays quietly under every short and dips while the narrator speaks.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:t,onClick:()=>{let{shortsMusic:t,...r}=e.content;n({...e,content:r,uploads:(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`)})},children:`Remove the music`})]}):null,(0,h.jsx)(k5,{label:i||a?`Replace the background music`:`Background music (optional): an audio file, looped if shorter than a short`,kind:`audio`,disabled:t,onPending:r,onReady:t=>n({...e,uploads:[...(e.uploads??[]).filter(e=>e.destination.kind!==`shortsMusic`),{stagedFileId:t.id,destination:{kind:`shortsMusic`}}]})})]})}function obe({edit:e,view:t,pick:n,settings:r,again:i,problem:a,onChange:o}){let s=(0,m.useId)(),c=t.revision.config.shorts,l=i||c===void 0||c.count!==r.count||c.minSeconds!==r.minSeconds||c.maxSeconds!==r.maxSeconds||(c.prompt??``)!==(r.prompt??``),u=Object.fromEntries(Object.entries(e.content.shortsRanges??{}).filter(([,e])=>e.pick===n.fingerprint)),d=n.picked.sentences??[],f=n.picked.durationSeconds??d.at(-1)?.end??0,p=n.picked.shorts.map(e=>{let t=u[String(e.number)],n=t===void 0?void 0:T5(d,t.first,t.last,f);return t===void 0||n===void 0?e:{...e,first:t.first,last:t.last,...n}}),g=(t,r,i)=>{let a=n.picked.shorts.find(e=>e.number===t.number),{[String(t.number)]:s,...c}=u,l=a!==void 0&&a.first===r&&a.last===i?c:{...c,[String(t.number)]:{first:r,last:i,pick:n.fingerprint}},{shortsRanges:d,...f}=e.content;o({...e,content:Object.keys(l).length===0?f:{...f,shortsRanges:l}})};return(0,h.jsxs)(`section`,{"aria-labelledby":`${s}-clips`,className:`space-y-3 border-t border-line pt-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h4`,{id:`${s}-clips`,className:`sl-kicker m-0`,children:`Picked clips`}),(0,h.jsx)(U,{id:`project.shorts.clips`})]}),i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`The moments will be picked again after you save and press Remake; clips on the same sentences keep their images.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>o({...e,regenerate:(e.regenerate??[]).filter(e=>e!==A5)}),children:`Keep the current moments`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,onClick:()=>o(M5(e)),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]})]}),l&&!i?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These settings pick the moments again after you save and press Remake, so the clips below can be adjusted once the new ones are picked.`}):null,(0,h.jsx)(`ol`,{className:`space-y-3`,children:p.map(t=>(0,h.jsx)(sbe,{clip:t,picked:n.picked,adjusted:u[String(t.number)]!==void 0,locked:l,remade:e.regenerate?.includes(j5(t.number))===!0,problem:(()=>{let e=u[String(t.number)];return e===void 0?a(`content.shortsRanges.${String(t.number)}`):$ye(n.picked,t.number,e.first,e.last,r,p)})(),onRange:(e,n)=>g(t,e,n),onRemake:n=>o(n?N5(e,t.number):{...e,regenerate:(e.regenerate??[]).filter(e=>e!==j5(t.number))})},t.number))})]})}function sbe({clip:e,picked:t,adjusted:n,locked:r,remade:i,problem:a,onRange:o,onRemake:s}){let c=(0,m.useId)(),l=t.sentences??[],[u,d]=(0,m.useState)(!1),f=String(e.number),p=e=>l[e-1]?.text??``,g=(e,t,n,i)=>(0,h.jsx)(B,{type:`button`,variant:`quiet`,"aria-label":`${e} of short ${f}`,disabled:r||!i,onClick:()=>o(t,n),children:e.split(` `)[0]}),_=Math.round(e.end-e.start);return(0,h.jsxs)(`li`,{"aria-labelledby":`${c}-title`,className:`space-y-2 border-t border-line pt-3 first:border-t-0 first:pt-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,h.jsxs)(`h5`,{id:`${c}-title`,className:`min-w-0 text-small font-semibold text-ink`,children:[`Short `,f,` · `,e.title]}),(0,h.jsxs)(`span`,{className:`text-label text-ink-3`,children:[`Sentences `,String(e.first),`-`,String(e.last),` · `,String(_),` s`,n?` · set by hand`:``]})]}),l.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`These shorts were picked before clips could be moved by hand. Use Pick different moments to adjust them.`}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Starts: “`,p(e.first),`”`]}),g(`Earlier start`,e.first-1,e.last,e.first>1),g(`Later start`,e.first+1,e.last,e.first<e.last)]}),(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-small text-ink-2`,children:[(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Ends: “`,p(e.last),`”`]}),g(`Earlier end`,e.first,e.last-1,e.last>e.first),g(`Later end`,e.first,e.last+1,e.last<l.length)]}),u?(0,h.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[`first`,`last`].map(t=>(0,h.jsx)(LB,{id:`${c}-${t}`,label:t===`first`?`Start sentence`:`End sentence`,tip:`project.shorts.range`,children:(0,h.jsx)(VB,{value:String(e[t]),disabled:r,onChange:n=>{let r=Number(n.target.value);o(t===`first`?r:e.first,t===`last`?r:e.last)},children:l.map((e,t)=>(0,h.jsxs)(`option`,{value:String(t+1),children:[String(t+1),`.`,` `,e.text.length>70?`${e.text.slice(0,69)}…`:e.text]},String(t+1)))})},t))}):null]}),a===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`text-small text-danger`,children:a}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l.length===0?null:(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>d(!u),children:u?`Hide the sentence lists`:`Use my own range`}),n?(0,h.jsx)(B,{type:`button`,variant:`quiet`,disabled:r,onClick:()=>{let n=t.shorts.find(t=>t.number===e.number);n!==void 0&&o(n.first,n.last)},children:`Back to the AI's choice`}):null,i?(0,h.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-small text-accent-ink`,children:[`Short `,f,` will be made again, with new images, after you save and press Remake.`,(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:()=>s(!1),children:`Keep this short`})]}):(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{type:`button`,disabled:r,onClick:()=>s(!0),children:`Make this short again`}),(0,h.jsx)(U,{id:`project.shorts.remake`})]})]})]})}function P5(e,t,n,r,i){let a=e.revision.content.promptTemplates[n]??e.revision.config.rendered[n];return!r||a==null||i.some(e=>e.kind===t&&e.name===r)?[]:[{id:`saved-${n}`,kind:t,name:r,body:a,slots:[],updatedAt:e.revision.createdAt}]}function cbe(e,t){let{[t]:n,...r}=e.content.promptTemplates,{[t]:i,...a}=e.config.rendered;return D5({...e,config:{...e.config,rendered:a},content:{...e.content,promptTemplates:r}})}var lbe=Y({shorts:J(Y({number:q(),first:q().optional(),last:q().optional(),start:q(),end:q(),title:K(),description:K(),hashtags:J(K())}))});function ube({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),i=c8(n,e),a=l8(i,`shorts`),o=L5(i),s=j8(t.id),[c,l]=(0,m.useState)(),u=F5(i,`short_video`,o),d=t.config.shorts,f=w5(t.id),p=d?.fullVideoLink??Hye(f.data),g=(0,m.use)(W8),_=(0,m.use)(G8);if(d?.enabled!==!0&&a===void 0&&u.length===0)return null;let v=g&&_!==void 0&&d?.enabled===!0,y=e=>{let t=Ik(e,p),n={text:`Couldn't copy short ${String(e.number)}. Select its text and copy it.`,tone:`error`};if(!navigator.clipboard){l(n);return}navigator.clipboard.writeText(t).then(()=>l({text:`Copied short ${String(e.number)}.`,tone:`success`}),()=>l(n))};return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sl-kicker m-0`,children:o.length===0?`Shorts`:`${String(o.length)} short${o.length===1?``:`s`} · 9:16`}),(0,h.jsx)(E8,{files:o.map(e=>({output:u.find(t=>I5(t,e)),label:`Short ${String(e.number)}: ${e.title} (.mp4)`})),label:u.length===1?`Download the short`:`Download`,children:v&&o.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,...zb,children:[(0,h.jsx)(B,{onClick:()=>_({section:`shorts`,change:M5}),children:`Pick different moments`}),(0,h.jsx)(U,{id:`project.shorts.pick-again`})]}):null}),o.length===0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`running`?`The clips are picked after the subtitle timing.`:`Not made yet. They are made with the video.`}):(0,h.jsx)(u0,{shorts:!0,list:!0,label:`Shorts`,className:`gap-y-7`,children:o.map(n=>(0,h.jsx)(dbe,{clip:n,projectId:t.id,review:M8(s,{itemKey:`shorts:${String(n.number)}`}),video:u.find(e=>I5(e,n)),stills:F5(i,`short_image`,o).filter(e=>I5(e,n)).toSorted((e,t)=>(e.meta.index??0)-(t.meta.index??0)),link:p,wanted:zk(n.end-n.start,t.config.imageSeconds),state:e.state,failed:mbe(e.failureReason,n.number),ownDownload:u.length>1,onCopy:()=>y(n),...v?{onRemake:()=>_({section:`shorts`,change:e=>N5(e,n.number)})}:{}},n.number))}),(0,h.jsx)(v1,{tone:c?.tone??`info`,children:c?.text})]})}function dbe({clip:e,projectId:t,review:n,video:r,stills:i,wanted:a,state:o,failed:s,link:c,ownDownload:l,onCopy:u,onRemake:d}){let f=(0,m.useId)(),p=g8(r),g=g8(i[0]),_=i.length,v=s?`Couldn't make this short. Open Error details in the Video section to see why.`:o===`running`?_<a?`Making images · ${String(_)} of ${String(a)}`:`Rendering`:`Not made yet. It is made with the video.`;return(0,h.jsxs)(`li`,{"aria-labelledby":`${f}-title`,className:`flex min-w-0 flex-col gap-2`,children:[r!==void 0&&p!==void 0?(0,h.jsx)(c0,{src:p.url,label:`Short ${String(e.number)}`,portrait:!0,...g===void 0?{}:{poster:g.url}},r.id):s||o!==`running`?(0,h.jsx)(`div`,{className:`sl-media__frame sl-media__frame--portrait`,children:(0,h.jsx)(`p`,{className:`m-0 flex size-full items-center justify-center p-3 text-center text-small ${s?`text-danger`:`text-ink-3`}`,children:v})}):(0,h.jsx)(l0,{alt:`Short ${String(e.number)}`,aspect:`portrait`,generating:v}),(0,h.jsx)(`h4`,{id:`${f}-title`,className:`m-0 min-w-0 break-words text-small font-semibold text-ink`,children:e.title}),(0,h.jsx)(`p`,{className:`m-0 text-label text-ink-2 tabular-nums`,children:uF(r?.durationMs??Math.round((e.end-e.start)*1e3))}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.description}),(0,h.jsx)(fbe,{link:c}),(0,h.jsx)(`p`,{className:`m-0 break-words text-small text-ink-2`,children:e.hashtags.join(` `)}),(0,h.jsx)(I8,{review:n,projectId:t,busy:o===`running`}),(0,h.jsxs)(Iy,{className:`mt-1 flex-nowrap gap-1`,children:[l&&r!==void 0&&p!==void 0?(0,h.jsx)(ES,{href:p.url,download:!0,size:`small`,label:`Download short ${String(e.number)}`,tip:`Download`,children:(0,h.jsx)(Ac,{"aria-hidden":`true`,strokeWidth:1.75})}):null,(0,h.jsx)(Py,{size:`small`,tip:`Copy title, description and hashtags`,label:`Copy short ${String(e.number)}'s title, description and hashtags`,onClick:u,children:(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75})}),d===void 0?null:(0,h.jsxs)(u8,{children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(Py,{size:`small`,tip:`More`,label:`More for short ${String(e.number)}`,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(f8,{align:`start`,children:(0,h.jsxs)(p8,{onSelect:d,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-4`}),`Make short `,String(e.number),` again`]})})]})]})]})}function fbe({link:e}){let t=e?.trim()??``;return(0,h.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-2 gap-y-1 break-words text-small text-ink-2`,children:[(0,h.jsx)(`span`,{children:`Watch the full video:`}),t===``?(0,h.jsxs)(kS,{tone:`waiting`,title:`No link to the full video is saved. Copy leaves a placeholder to paste it over; to fill it in for every short, add the link under Edit settings → Shorts.`,children:[(0,h.jsx)(Rc,{"aria-hidden":`true`,strokeWidth:1.75,className:`size-3`}),`Link needed`]}):(0,h.jsx)(`span`,{className:`min-w-0 break-all text-ink`,children:t})]})}function F5(e,t,n){let r=e.find(e=>e.role===`shorts`);return e.filter(e=>e.role===t&&(r===void 0||e.createdAt>=r.createdAt||n.some(t=>I5(e,t)&&e.meta.sentences?.[0]===t.first&&e.meta.sentences?.[1]===t.last)))}function I5(e,t){return e.meta.short===t.number}function L5(e){return pbe(O8(l8(e,`shorts`)).data)}function pbe(e){if(e===void 0)return[];try{let t=lbe.safeParse(JSON.parse(e));return t.success?t.data.shorts:[]}catch{return[]}}function mbe(e,t){return e?.startsWith(`Short ${String(t)}:`)===!0||e?.startsWith(`Short ${String(t)} `)===!0}function hbe({stage:e,project:t,outputs:n,subtitleControls:r}){let{api:i}=V(),a=Ry(),o=t.config.sources.video===`off`&&t.config.sources.audio!==`off`,s=l8(c8(n,e),o?`audio_export`:`video`),c=c8(n,e),l=l8(c,`subtitles_srt`),u=l8(c,`subtitles_vtt`),d=l8(c,`youtube_description`),f=l8(c,`youtube_tags`),p=l8(c,`audio_mp3`),m=l8(c,`audio_m4b`),g=F5(c,`short_video`,L5(c)).toSorted((e,t)=>(e.meta.short??0)-(t.meta.short??0)),_=g8(s),v=g8(gbe(n)),y=_be(t.id,d,f,s?.durationMs??null),b=g8(u),x=s?.meta.subtitlesMode??t.config.subtitles?.mode,S=e.state===`running`,C=dF(e.progressCurrent??0,e.progressTotal??0);return jx({id:`project.folder`,title:`Open the project folder`,group:`This project`,context:t.title,keywords:[`folder`,`files`,`finder`,`explorer`,`video`],run:async()=>{if(s===void 0){a(`The video has not been saved yet, so there is no folder to open.`,`info`);return}try{let e=await M0(i,{projectId:t.id,asset:C3(s),folder:_?.folder??null});e.opened||a(`${N0} ${e.path}`,`info`)}catch(e){a(e instanceof Error?e.message:`The folder couldn't be opened. Use Open folder under the video.`,`error`)}}}),t.config.sources.video===`off`&&!o?(0,h.jsx)(b8,{children:r}):(0,h.jsxs)(b8,{className:`p-0`,children:[S?(0,h.jsx)(`p`,{className:`m-0 text-small text-accent-ink`,children:QP(e,t.config)?`Preparing subtitles · ${String(dF(e.progressCurrent??0,35))}%`:o?`Exporting combined audio`:e.activity===void 0?e.progressTotal===null?`Rendering`:`Rendering · ${String(C)}%`:rF(nF(e)??``)}):null,s===void 0?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:o?`No combined audio export has landed yet.`:`No render has landed yet.`}):o?(0,h.jsx)(Y8,{label:`Combined narration`,src:_?.url,marks:y},s.id):_===void 0?null:(0,h.jsx)(c0,{src:_.url,label:`Generated video`,...v===void 0?{}:{poster:v.url},chapters:y,portrait:t.format===`9:16`,square:t.format===`1:1`,className:t.format===`9:16`?`max-w-[360px]`:t.format===`1:1`?`max-w-[640px]`:`max-w-[1100px]`,...x===`files`&&u&&b?{captions:{src:b.url,lang:`en`,label:`English`}}:{}},s.id),(0,h.jsx)(E8,{files:[{output:s,label:o?`Audio (.wav)`:`Video (.mp4)`},{output:l,label:`Subtitles (.srt)`},{output:u,label:`Subtitles (.vtt)`},{output:d,label:`YouTube description (.txt)`},{output:f,label:`YouTube tags (.txt)`},{output:p,label:`Audio with chapters (.mp3)`},{output:m,label:`Audiobook with chapters (.m4b)`},...g.map(e=>({output:e,label:`Short ${String(e.meta.short??``)} (.mp4)`}))]}),s===void 0?null:(0,h.jsx)(D8,{children:[uF(s?.durationMs??void 0),o?`WAV · stereo · 48 kHz`:t.format,s?.meta.master===void 0?void 0:ck(s.meta.master)].filter(e=>e!==void 0).join(` · `)}),s?.meta.warnings?.length?(0,h.jsx)(`ul`,{"aria-label":`Render notes`,className:`m-0 flex flex-col gap-1 pl-5 text-small text-ink-2`,children:s.meta.warnings.map(e=>(0,h.jsx)(`li`,{children:e},e))}):null,t.config.sources.audio===`off`||PO(t.config.language)===void 0?null:(0,h.jsx)(`p`,{role:`note`,className:`border-t border-line pt-3 text-small text-ink-2`,children:PO(t.config.language)}),s?.meta.subtitleOmissions?.length?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3 text-small`,children:[(0,h.jsxs)(`summary`,{className:`cursor-pointer font-semibold`,children:[`Subtitles recovered after missing narration (`,s.meta.subtitleOmissions.length,`)`]}),(0,h.jsx)(`p`,{className:`m-0 mt-2 text-ink-2`,children:`These transcript passages could not be matched to the audio and were left out of the captions. The audio is unchanged. Review these passages before sharing.`}),(0,h.jsx)(`ul`,{className:`m-0 mt-2 flex flex-col gap-2 pl-5`,children:s.meta.subtitleOmissions.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:new Date(e.start*1e3).toISOString().slice(11,19)}),` —`,` `,e.text]},`${e.start}-${e.text}`))})]}):null,r?(0,h.jsxs)(`details`,{className:`border-t border-line pt-3`,children:[(0,h.jsx)(`summary`,{className:`cursor-pointer text-small font-semibold`,children:`Subtitles & fonts`}),r]}):null]})}function gbe(e){return e.filter(e=>e.role===`thumbnail`).toSorted((e,t)=>(e.meta.index??1)-(t.meta.index??1))[0]}function _be(e,t,n,r){let{api:i}=V(),a=O8(t).data,o=O8(n).data,s=I({queryKey:H.youtubeEdits(e),queryFn:()=>zs(i,e),enabled:t!==void 0});return a===void 0?[]:vbe(S5(x5(b5(a,o??``),s.data?.fields??{})).chapters,r===null?void 0:r/1e3)}function vbe(e,t){return y5(e,t).text.split(`
301
+ `).flatMap(e=>{let t=/^(\S+)\s+(.+)$/u.exec(e.trim()),n=t===null?void 0:v5(t[1]??``),r=t?.[2]?.trim()??``;return n===void 0||r===``?[]:[{start:n,title:r}]})}function ybe(e){switch(e.stage.kind){case`article`:return(0,h.jsx)(Yve,{...e});case`audio`:return(0,h.jsx)(aye,{...e});case`images`:return(0,h.jsx)(Pye,{...e});case`video`:return(0,h.jsx)(hbe,{...e});case`document`:return(0,h.jsx)(lye,{...e});case`research`:case`thumbnail`:return null}}Y({summary:K(),chapters:J(Y({start:JD([K(),q()]),title:K()})),hashtags:J(K()),tags:J(K()),pinnedComment:K(),titles:J(K())});function R5(e){return e.reduce((e,t)=>e+t.length+(/\s/.test(t)?2:0),0)+Math.max(0,e.length-1)}var z5=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`});function B5(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${String(t.getFullYear())}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function bbe({projectId:e}){let{api:t}=V(),n=_(),r=Ry(),i=[`studio`,`project-releases`,e],a=I({queryKey:i,queryFn:()=>us(t,e)}),[o,s]=(0,m.useState)({}),c=(I({queryKey:[`studio`,`releases`,`swap`,8],queryFn:()=>cs(t,8)}).data?.entries??[]).flatMap(t=>t.project===null||t.project.id===e?[]:[{id:t.project.id,title:t.project.title,at:t.at}]),l=L({mutationFn:n=>ls(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),n.invalidateQueries({queryKey:[`studio`,`project-releases`,t]}),r(`Swapped release times with ${c.find(e=>e.id===t)?.title??`the other video`}; each one's shorts moved with it.`,`success`)},onError:e=>r(`The times weren't swapped: ${e.message}`,`error`)}),u=L({mutationFn:n=>ds(t,e,n),onSuccess:(e,t)=>{n.invalidateQueries({queryKey:i}),n.invalidateQueries({queryKey:[`studio`,`releases`]}),s(e=>{let{[t.short]:n,...r}=e;return r}),r(t.at===null?`Not scheduled: set its time in Studio yourself, or pick one here.`:`Saved the release time.`,`success`)},onError:e=>r(`The time wasn't saved: ${e.message}`,`error`)});if(a.data===void 0)return null;let{items:d,free:f,leadHours:p}=a.data;return d.length===0?null:(0,h.jsxs)(`section`,{"aria-label":`Release`,className:`flex flex-col gap-3`,children:[(0,h.jsx)(W,{as:`h3`,size:`small`,title:`Release`,meta:`Upload and schedule each one at least ${String(p)} hours before it goes out.`}),(0,h.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:d.map(e=>{let t=e.short===0?`Long video`:`Short ${String(e.short)}`,n=o[e.short]??(e.at===null?``:B5(e.at)),r=n!==(e.at===null?``:B5(e.at)),i=!e.onYoutube&&e.uploadBy!==null&&Date.parse(e.uploadBy)<Date.now();return(0,h.jsxs)(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,h.jsx)(`span`,{className:`w-[86px] shrink-0 text-small font-semibold`,children:t}),(0,h.jsx)(zB,{"aria-label":`${t}: release`,type:`datetime-local`,className:`w-[210px]`,value:n,onChange:t=>{let n=t.currentTarget.value;s(t=>({...t,[e.short]:n}))}}),r?(0,h.jsx)(B,{type:`button`,size:`small`,disabled:n===``||u.isPending,onClick:()=>u.mutate({short:e.short,at:new Date(n).toISOString()}),children:`Save`}):null,e.short===0&&f.length>0?(0,h.jsx)(VB,{"aria-label":`Take a free time of the posting plan`,className:`w-[230px]`,value:``,onChange:e=>{let t=f.find(t=>t.longAt===e.currentTarget.value);t!==void 0&&u.mutate({short:0,at:t.longAt,line:t.row})},options:[{value:``,label:`Free plan times…`},...f.map(e=>({value:e.longAt,label:z5.format(new Date(e.longAt))}))]}):null,e.at!==null&&e.short===0&&c.length>0?(0,h.jsx)(VB,{"aria-label":`Swap release times with another video`,className:`w-[260px]`,value:``,disabled:l.isPending,onChange:e=>{e.currentTarget.value!==``&&l.mutate(e.currentTarget.value)},options:[{value:``,label:`Swap with…`},...c.map(e=>({value:e.id,label:`${e.title.split(` | `)[0]??e.title} · ${z5.format(new Date(e.at))}`}))]}):null,e.at!==null&&e.short===0?(0,h.jsx)(B,{type:`button`,size:`small`,variant:`quiet`,disabled:u.isPending,onClick:()=>u.mutate({short:0,at:null}),children:`Not scheduled`}):null,(0,h.jsx)(`span`,{className:`text-small text-ink-3`,children:e.onYoutube?(0,h.jsx)(kS,{children:`✓ on YouTube`}):e.uploadBy===null?`No time yet`:i?(0,h.jsx)(kS,{tone:`failed`,children:`Late · upload now`}):`Ready to upload`})]},e.short)})}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Every video's times are together in`,` `,(0,h.jsx)(fa,{to:`/calendar`,search:{tab:`releases`},children:`Calendar → Releases`}),`.`]})]})}var V5={summary:`Summary`,chapters:`Chapters`,hashtags:`Hashtags`,tags:`Tags`,pinnedComment:`Pinned comment`,titles:`Other titles`},H5={Summary:`project.youtube.summary`,Chapters:`project.youtube.chapters`,Hashtags:`project.youtube.hashtags`,Tags:`project.youtube.tags`,"Pinned comment":`project.youtube.pinned-comment`,"Other titles":`project.youtube.titles`};function xbe({stage:e,project:t,outputs:n}){let r=(0,m.useId)(),{api:i}=V(),a=_(),o=c8(n,e),s=l8(o,`youtube_description`),c=l8(o,`youtube_tags`),l=l8(o,`youtube_pinned_comment`),u=l8(o,`youtube_titles`),d=O8(s).data,f=O8(c).data,p=O8(l).data,g=O8(u).data,v=(0,m.use)(K8),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(`description`),C=e=>({open:x===e,onToggle:()=>S(e)}),w=I({queryKey:H.youtubeEdits(t.id),queryFn:()=>zs(i,t.id)}),T=I({queryKey:H.projectChannelLinks(t.id),queryFn:()=>Rs(i,t.id)}),[E,D]=(0,m.useState)(),O=Ry(),k=e=>a.setQueryData(H.youtubeEdits(t.id),e),A=L({mutationFn:e=>Bs(i,t.id,e.field,e.edit),onSuccess:(e,t)=>{k(e),D({text:t.done,tone:`success`})},onError:e=>D({text:`Couldn't save the change: ${e.message}`,tone:`error`})}),j=(0,m.useRef)({});if(jx({id:`project.copy-description`,title:`Copy description`,group:`This project`,context:t.title,keywords:[`youtube`,`description`,`chapters`,`clipboard`],shortcut:nP.copyDescription,run:()=>j.current.description===void 0?O(`The description has not been written yet.`,`info`):j.current.description()}),jx({id:`project.copy-tags`,title:`Copy tags`,group:`This project`,context:t.title,keywords:[`youtube`,`tags`,`clipboard`],run:()=>j.current.tags===void 0?O(`The tags have not been written yet.`,`info`):j.current.tags()}),jx({id:`project.copy-pinned-comment`,title:`Copy pinned comment`,group:`This project`,context:t.title,keywords:[`youtube`,`comment`,`pin`,`clipboard`],run:()=>j.current.pinnedComment===void 0?O(`The pinned comment has not been written yet.`,`info`):j.current.pinnedComment()}),t.config.youtubeDescription!==!0&&s===void 0)return null;let M=d===void 0?void 0:b5(d,f??``,{pinnedComment:p,titles:g}),ee=x5(M,w.data?.fields??{}),N=S5(ee),P=Ej(T.data?.links??[],w.data?.links??[]),F=l8(o,`video`),te=y5(N.chapters,F?.durationMs===null||F?.durationMs===void 0?void 0:F.durationMs/1e3),ne=Lye(te.adjustments),re=Oj(zye({...N,chapters:te.text}),P),ie=Oj(N.tags,P),ae=Oj(N.pinnedComment,P),oe=[...re.unknown,...ie.unknown,...ae.unknown].filter((e,t,n)=>n.findIndex(t=>Tj(t)===Tj(e))===t),se=G5(ie.text),ce=M!==void 0,le=ae.text.trim()!==``,ue=N.titles.split(`
302
302
  `).map(e=>e.trim()).filter(e=>e!==``),de=ce&&v!==void 0&&e.state!==`running`?()=>b(!0):void 0,fe=(e,t)=>{let n=`Couldn't copy the ${t}. Select the text in the YouTube section and copy it.`;if(!navigator.clipboard){D({text:n,tone:`error`}),O(n,`error`);return}navigator.clipboard.writeText(e).then(()=>{D({text:`Copied the ${t}.`,tone:`success`}),O(`Copied the ${t}.`,`success`)},()=>{D({text:n,tone:`error`}),O(n,`error`)})};j.current=ce?{description:()=>fe(re.text,`description`),tags:()=>fe(ie.text,`tags`),...le?{pinnedComment:()=>fe(ae.text,`pinned comment`)}:{}}:{};let pe=e.state===`running`?`Written after the subtitle timing.`:`Not written yet. It is made with the video.`,me=(e,t)=>(0,h.jsx)(Sbe,{label:V5[e],value:ee[e],links:P,disabled:!ce||A.isPending,multiline:e!==`hashtags`,placeholder:ce&&e===`pinnedComment`?`Written before pinned comments existed. Use Write again to have one written, or Edit to write your own.`:ce&&e===`titles`?`Written before other titles existed. Use Write again to have two written, or Edit to write your own, one per line.`:pe,render:t,onSave:t=>A.mutate({field:e,edit:{text:t,base:M?.[e]??``},done:`Saved your ${V5[e].toLowerCase()}.`}),onUseGenerated:()=>A.mutate({field:e,edit:null,done:`The ${V5[e].toLowerCase()} follows the generated text again.`}),onKeepMine:(t,n)=>A.mutate({field:e,edit:{text:t,base:n},done:`Kept your ${V5[e].toLowerCase()}.`})},e);return(0,h.jsxs)(`section`,{"aria-labelledby":`${r}-title`,className:`@container flex min-w-0 flex-col gap-4`,children:[(0,h.jsx)(`h3`,{id:`${r}-title`,className:`sr-only`,children:`YouTube`}),(0,h.jsxs)(`div`,{className:`flex min-w-0 max-w-[80ch] flex-col gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`description`),id:`${r}-description`,label:`Description`,copy:ce?()=>fe(re.text,`description`):void 0,keyshortcuts:Ux(nP.copyDescription),count:ce?`${String(re.text.length)} / ${String(v6)} characters`:void 0,over:re.text.length>v6,main:!0,again:de}),(0,h.jsxs)(`div`,{hidden:x!==`description`,className:`flex min-w-0 flex-col gap-3`,children:[me(`summary`),me(`chapters`,()=>te.text===``?(0,h.jsx)(`span`,{className:`text-ink-3`,children:`Left out; see the note below.`}):(0,h.jsx)(W5,{text:te.text,links:P})),ne===void 0?null:(0,h.jsx)(`p`,{className:`text-small text-waiting`,children:ne}),me(`hashtags`)]})]}),(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,h.jsx)(U5,{...C(`tags`),id:`${r}-tags`,label:`Tags`,copy:ce?()=>fe(ie.text,`tags`):void 0,count:ce?`${String(R5(se))} / 500 characters`:void 0,over:R5(se)>500}),(0,h.jsx)(`div`,{hidden:x!==`tags`,children:me(`tags`,e=>(0,h.jsx)(Cbe,{text:e,links:P}))}),(0,h.jsx)(U5,{...C(`pinned`),id:`${r}-pinned`,label:`Pinned comment`,copy:ce&&le?()=>fe(ae.text,`pinned comment`):void 0,count:ce&&le?`${String(ae.text.length)} / 500 characters`:void 0,over:ae.text.length>500,again:de}),(0,h.jsxs)(`div`,{hidden:x!==`pinned`,className:`flex min-w-0 flex-col gap-3`,children:[me(`pinnedComment`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Post it under the video once it is published, then choose Pin in the comment's menu.`})]}),(0,h.jsx)(U5,{...C(`titles`),id:`${r}-titles`,label:`Other titles`,copy:ce&&ue.length>0?()=>fe(ue.join(`
303
303
  `),`other titles`):void 0,count:ce&&ue.length>0?`${String(ue.length+1)} titles to test`:void 0,over:ue.some(e=>e.length>100),again:de}),(0,h.jsxs)(`div`,{hidden:x!==`titles`,className:`flex min-w-0 flex-col gap-3`,children:[me(`titles`),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`For YouTube's A/B Testing beside the title, with this project's own title "${t.title}". One per line.`})]})]})]}),oe.length===0?null:(0,h.jsxs)(`p`,{className:`text-small text-waiting`,children:[`No link is saved for ${oe.map(e=>`{{${e}}}`).join(`, `)}, so it stays as typed. Add it under Channel links on `,T.data===void 0?`the channel's Brand tab`:(0,h.jsx)(fa,{to:`/channels/$channelId`,params:{channelId:T.data.channelId},className:`underline`,children:`the channel's Brand tab`}),`${oe.some(e=>Tj(e)===Tj(`Previous video`))?`, or set this project's Previous video below`:``}.`]}),(0,h.jsx)(bbe,{projectId:t.id}),(0,h.jsx)(Gye,{projectId:t.id,shorts:n.filter(e=>e.role===`short_video`).length}),(0,h.jsx)(wbe,{projectId:t.id,edits:w.data,onSaved:e=>{k(e),D({text:`Saved this project's Previous video link.`,tone:`success`})},onError:e=>D({text:e,tone:`error`})}),(0,h.jsx)(v1,{tone:E?.tone??`info`,children:E?.text}),(0,h.jsx)(Hy,{open:y,title:`Write the description again?`,consequence:`Your text model writes a new summary, chapters, hashtags, tags, pinned comment and other titles. It is one AI call, billed like the first. A field you edited keeps your text and offers the new one beside it.`,confirmLabel:`Write again`,cancelLabel:`Keep what is there`,tone:`primary`,onConfirm:()=>{b(!1),v?.([`youtube:description`]),D({text:`Writing the description again.`,tone:`info`})},onCancel:()=>b(!1)})]})}function U5({id:e,label:t,copy:n,count:r,over:i,keyshortcuts:a,main:o=!1,again:s,open:c,onToggle:l}){return(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-3 border-b border-line pb-2`,children:[(0,h.jsx)(`h4`,{id:e,className:`m-0 text-title-3 font-semibold text-ink`,children:l===void 0?t:(0,h.jsxs)(B,{type:`button`,variant:`quiet`,"aria-expanded":c===!0,onClick:l,className:`-ml-2 h-auto px-2 py-1 text-title-3 font-semibold text-ink`,children:[(0,h.jsx)(Tc,{"aria-hidden":`true`,strokeWidth:1.75,className:z(`size-4 transition-transform`,c===!0&&`rotate-90`)}),t]})}),r===void 0?null:(0,h.jsx)(`span`,{className:z(`text-small tabular-nums`,i?`text-danger`:`text-ink-3`),children:i?`${r}, over YouTube's limit`:r}),(0,h.jsx)(`span`,{className:`flex-1`}),s===void 0?null:(0,h.jsxs)(B,{type:`button`,variant:`secondary`,"aria-label":`Write the ${t.toLowerCase()} again`,onClick:s,children:[(0,h.jsx)(qc,{"aria-hidden":`true`,strokeWidth:1.75}),`Write again`]}),(0,h.jsxs)(B,{type:`button`,variant:o?`primary`:`secondary`,disabled:n===void 0,"aria-label":`Copy ${t.toLowerCase()}`,"aria-keyshortcuts":a,onClick:n,children:[(0,h.jsx)(kc,{"aria-hidden":`true`,strokeWidth:1.75}),`Copy`]})]})}function Sbe({label:e,value:t,links:n,disabled:r,multiline:i,placeholder:a,render:o,onSave:s,onUseGenerated:c,onKeepMine:l}){let u=(0,m.useId)(),[d,f]=(0,m.useState)(),[p,g]=(0,m.useState)(!1),_=d!==void 0,v=e.toLowerCase(),y=e in H5?H5[e]:void 0;return(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2`,children:[(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(`h5`,{id:`${u}-label`,className:`sl-kicker text-ink-3`,children:e}),y===void 0?null:(0,h.jsx)(U,{id:y,label:v,className:`-my-1`})]}),t.edited?(0,h.jsx)(`span`,{className:`text-small text-ink-2`,children:`Your edit`}):null,(0,h.jsx)(`span`,{className:`flex-1`}),t.edited&&!_?(0,h.jsx)(B,{type:`button`,variant:`quiet`,size:`small`,disabled:r,"aria-label":`Use the generated ${v}`,onClick:c,children:`Use generated`}):null,(0,h.jsxs)(B,{type:`button`,variant:`quiet`,size:`small`,disabled:r||_,"aria-label":`Edit ${v}`,onClick:()=>f(t.text),children:[(0,h.jsx)(Uc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit`]})]}),t.pending===void 0?null:(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-l-2 border-waiting pl-3`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`p`,{className:`text-small text-ink`,children:`New generated version available.`}),(0,h.jsx)(B,{type:`button`,disabled:r,"aria-label":`Use the new generated ${v}`,onClick:c,children:`Use it`}),(0,h.jsx)(B,{type:`button`,disabled:r,"aria-label":`Keep my ${v}`,onClick:()=>l(t.text,t.pending??``),children:`Keep mine`}),(0,h.jsx)(B,{type:`button`,variant:`quiet`,"aria-expanded":p,"aria-label":`${p?`Hide`:`View`} the ${v} diff`,onClick:()=>g(e=>!e),children:p?`Hide diff`:`View diff`})]}),p?(0,h.jsx)(b4,{before:t.text,after:t.pending,beforeLabel:`Yours`,afterLabel:`New generated`}):null]}),_?(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`label`,{htmlFor:`${u}-edit`,className:`sr-only`,children:e}),i?(0,h.jsx)(BB,{id:`${u}-edit`,rows:e===`Chapters`?8:5,value:d,onChange:e=>f(e.currentTarget.value)}):(0,h.jsx)(zB,{id:`${u}-edit`,value:d,onChange:e=>f(e.currentTarget.value)}),(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,h.jsxs)(B,{type:`button`,variant:`primary`,disabled:r,onClick:()=>{s(d),f(void 0)},children:[`Save `,v]}),(0,h.jsx)(B,{type:`button`,variant:`secondary`,onClick:()=>f(void 0),children:`Cancel`})]})]}):(0,h.jsx)(`section`,{"aria-labelledby":`${u}-label`,className:z(`min-w-0 whitespace-pre-wrap break-words text-small`,t.text===``?`text-ink-3`:`text-ink`),children:t.text===``?a:o===void 0?(0,h.jsx)(W5,{text:t.text,links:n}):o(t.text)})]})}function W5({text:e,links:t}){let n=0;return(0,h.jsx)(h.Fragment,{children:Dj(e,t).map(e=>{let t=String(n);return n+=e.kind===`text`?e.text.length:e.raw.length,e.kind===`text`?(0,h.jsx)(`span`,{children:e.text},t):e.url===void 0?(0,h.jsx)(`mark`,{title:`No link named ${e.name}`,className:`rounded-[2px] bg-waiting/25 px-0.5 text-ink`,children:e.raw},t):(0,h.jsx)(`span`,{title:e.raw,className:`underline decoration-dotted underline-offset-[3px]`,children:e.url},t)})})}function G5(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function Cbe({text:e,links:t}){return(0,h.jsx)(`ul`,{className:`flex flex-wrap gap-2 whitespace-normal`,children:G5(e).map((e,n)=>(0,h.jsx)(`li`,{className:`rounded-full border border-line bg-raised px-2 py-0.5 text-small text-ink`,children:(0,h.jsx)(W5,{text:e,links:t})},n))})}function wbe({projectId:e,edits:t,onSaved:n,onError:r}){let{api:i}=V(),a=(0,m.useId)(),o=t?.links.find(e=>Tj(e.name)===Tj(`Previous video`))?.url??``,[s,c]=(0,m.useState)(),l=s??o,u=L({mutationFn:()=>{let n=(t?.links??[]).filter(e=>Tj(e.name)!==Tj(Sj));return Vs(i,e,l.trim()===``?n:[...n,{name:Sj,url:l.trim()}])},onSuccess:e=>{c(void 0),n(e)},onError:e=>r(e.message)});return(0,h.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-[260px] flex-1 flex-col gap-1 sm:max-w-[520px]`,...zb,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsx)(`label`,{className:`sl-field__label`,htmlFor:a,children:`Previous video for this project`}),(0,h.jsx)(U,{id:`project.youtube.previous-video`,className:`-my-1`})]}),(0,h.jsx)(zB,{id:a,type:`url`,placeholder:`https://youtu.be/…`,value:l,onChange:e=>c(e.currentTarget.value)})]}),(0,h.jsx)(B,{type:`button`,disabled:u.isPending||t===void 0||l.trim()===o,onClick:()=>u.mutate(),children:`Save links`})]})}var K5=[{stage:`audio`,name:`Audio`},{stage:`images`,name:`Images`},{stage:`video`,name:`Video / export`}];function Tbe({projectId:e,revisionId:t,gates:n,stages:r,reload:i,saved:a}){let{api:o}=V(),[s,c]=(0,m.useState)(null),[l,u]=(0,m.useState)(!1),[d,f]=(0,m.useState)(null),p=(0,m.useRef)(!1),g=(0,m.useRef)(!0),_=(0,m.useRef)(null),v=(0,m.useRef)(null),y=JSON.stringify([t,n.map(e=>[e.stage,e.checkpointId]).toSorted()]),b=s!==null&&s.baseIdentity!==y,x=s?.stages??n.map(e=>e.stage),S=K5.some(({stage:e})=>x.includes(e)!==n.some(t=>t.stage===e)),C=b||d!==null&&d.kind!==`success`,w=b?{kind:`refused`,message:`Checkpoint choices changed elsewhere. Press Reload checkpoint choices before saving, then make your change again.`}:d;(0,m.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,m.useEffect)(()=>{(d||b)&&_.current?.focus()},[d,b]);async function T(){if(!(p.current||!S||C)){p.current=!0,u(!0);try{let n=await Nhe(o,e,{revisionId:t,stages:x});if(!g.current)return;n.ok?n.value.revisionId===t?(a(n.value),c(null),f({kind:`success`,message:`Checkpoint choices saved.`})):f({kind:`refused`,message:`The project was edited elsewhere. Press Reload checkpoint choices to see its current choices.`}):f({kind:`refused`,message:n.message})}catch(e){g.current&&f({kind:`transport`,message:`${_o(e instanceof Error?e.message:`Slopify didn't confirm the change`)} It may or may not have saved. Press Reload checkpoint choices before changing anything else.`})}finally{p.current=!1,g.current&&u(!1)}}}async function E(){if(!p.current){p.current=!0,u(!0);try{let e=await i();g.current&&e&&(c(null),f(null),v.current?.focus())}finally{p.current=!1,g.current&&u(!1)}}}return(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(`fieldset`,{ref:v,tabIndex:-1,className:`space-y-2`,...zb,children:[(0,h.jsx)(`legend`,{className:`float-left mr-1`,children:`Checkpoint choices`}),(0,h.jsx)(U,{id:`project.checkpoints.choices`,className:`-my-1`}),(0,h.jsx)(`div`,{className:`clear-both`}),K5.map(({stage:e,name:t})=>{let n=r.find(t=>t.kind===e),i=n?.state===`pending`&&(e===`video`?n.source!==`off`||r.some(e=>e.kind===`audio`&&e.source!==`off`&&e.state!==`skipped`):(n.source??`generate`)===`generate`);return(0,h.jsxs)(`label`,{className:`flex min-h-10 items-center gap-3`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:x.includes(e),disabled:!i||l||C,onChange:t=>{c({baseIdentity:s?.baseIdentity??y,stages:t.target.checked?[...x,e]:x.filter(t=>t!==e)}),f(null)}}),`Before `,t]},e)})]}),w?(0,h.jsx)(`p`,{ref:_,tabIndex:-1,role:w.kind===`success`?`status`:`alert`,children:w.message}):null,(0,h.jsx)(B,{type:`button`,disabled:!S||l||C,onClick:()=>void T(),children:l?`Saving…`:`Save checkpoints`}),C?(0,h.jsx)(B,{type:`button`,disabled:l,onClick:()=>void E(),children:`Reload checkpoint choices`}):null]})}var q5=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ebe(e){return e.revisionId===null?null:(0,h.jsx)(Dbe,{...e,revisionId:e.revisionId},`${e.projectId}:${e.revisionId}`)}function Dbe({projectId:e,revisionId:t,paused:n,stages:r,approvedInRail:i}){let{api:a}=V(),o=_(),s=I({queryKey:c3(e,t),queryFn:()=>u3(a,e),retry:!1}),c=s.data,l=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t?e.data.value:void 0},u=async()=>{let e=await s.refetch();return!e.isError&&e.data?.ok===!0&&e.data.value.revisionId===t};return s.isPending?null:s.error||c?.ok===!1?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:[(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:s.error?.message??(c?.ok===!1?c.message:`Checkpoints couldn't be loaded. Press Reload checkpoints.`)}),(0,h.jsx)(B,{onClick:()=>void u(),children:`Reload checkpoints`})]}):c?.ok?c.value.revisionId===t?(0,h.jsxs)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col gap-5`,children:[(0,h.jsx)(W,{title:`Review checkpoints`,size:`small`,className:`pb-0`}),n?(0,h.jsx)(`p`,{className:`m-0 text-small text-waiting`,children:`The project is paused. Continue the run before approving held work.`}):null,(0,h.jsx)(Tbe,{projectId:e,revisionId:t,gates:c.value.checkpoints,stages:r,reload:l,saved:n=>{o.setQueryData(c3(e,t),{ok:!0,value:n}),o.invalidateQueries({queryKey:H.project(e)}),o.invalidateQueries({queryKey:H.projects})}}),c.value.checkpoints.map(a=>(0,h.jsx)(Obe,{gate:a,disabled:n||a.projectId!==e||a.revisionId!==t||r.some(e=>e.kind===a.stage&&[`running`,`canceled`].includes(e.state)),reload:u,...a.checkpointId===i?{inRail:!0}:{}},`${a.checkpointId}:${a.fingerprint}`))]}):(0,h.jsx)(`section`,{"aria-label":`Review checkpoints`,className:`flex flex-col items-start gap-3`,children:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 text-small text-danger`,children:`The project was edited after these checkpoints loaded. Press Reload checkpoints before approving.`})}):null}function Obe({gate:e,disabled:t,reload:n,inRail:r=!1}){let{api:i}=V(),a=_(),o=(0,m.useRef)(null),s=(0,m.useRef)(!1),c=(0,m.useRef)(!0),l=(0,m.useRef)(null),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(null);(0,m.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),(0,m.useEffect)(()=>{f!==null&&l.current?.focus()},[f]);let g=[`configured`,`pending-review`,`held`].includes(e.state)&&e.fingerprint===e.currentFingerprint;async function v(){if(!(s.current||t||!g||f?.kind===`refused`||f?.kind===`success`)){s.current=!0,d(!0),o.current??={revisionId:e.revisionId,fingerprint:e.fingerprint,idempotencyKey:crypto.randomUUID()};try{let t=await d3(i,e.projectId,e.checkpointId,o.current);o.current=null,c.current&&p(t.ok?{kind:`success`,message:t.value.replayed?`Checkpoint already approved.`:`Checkpoint approved. Work will run when its dependencies are ready.`}:{kind:`refused`,message:t.message}),a.invalidateQueries({queryKey:s3(e.projectId)}),a.invalidateQueries({queryKey:H.project(e.projectId)}),a.invalidateQueries({queryKey:H.projects})}catch(e){c.current&&p({kind:`transport`,message:`${_o(e instanceof Error?e.message:`Slopify didn't confirm the approval`)} Press Retry approval to check whether it went through.`})}finally{s.current=!1,c.current&&d(!1)}}}return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-line pt-4`,children:[(0,h.jsx)(W,{as:`h3`,title:`${q5(e.stage)} checkpoint`,className:`pb-0`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:e.state===`released`&&e.approvedAt!==null?`Authorized for this revision. Work can run when dependencies are ready and the project is resumed.`:e.state===`satisfied`?`Checkpoint satisfied. Its reviewed work is complete.`:e.state===`invalidated`||e.fingerprint!==e.currentFingerprint?`Inputs changed. Review the current revision before approving.`:g?`${q5(e.stage)} is held for your review. Its dependent work waits for this approval; independent work can continue.`:`Checkpoint ${e.state}.`}),(0,h.jsxs)(`p`,{className:`m-0 text-small text-ink-3`,children:[`Reviewed revision: `,e.revisionId]}),e.dependents.length?(0,h.jsx)(`ul`,{"aria-label":`Dependent work`,className:`m-0 flex list-none flex-wrap gap-2 p-0`,children:e.dependents.map(e=>(0,h.jsx)(`li`,{className:`sl-chip`,children:q5(e)},e))}):(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`No dependent stages.`}),f?(0,h.jsx)(`p`,{ref:l,tabIndex:-1,role:f.kind===`success`?`status`:`alert`,className:f.kind===`success`?`m-0 text-small`:`m-0 text-small text-danger`,children:f.message}):null,g&&r&&f===null?(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`Its approval is the project's next action, in the right rail.`}):g?(0,h.jsx)(B,{className:`self-start`,disabled:t||u||f?.kind===`refused`||f?.kind===`success`,onClick:()=>void v(),children:u?`Approving…`:f?.kind===`transport`?`Retry approval`:`Approve ${q5(e.stage)} checkpoint`}):null,f?.kind===`refused`?(0,h.jsx)(B,{className:`self-start`,onClick:async()=>{await n()&&p(null)},children:`Reload checkpoints`}):null]})}function kbe({projects:e,queryKey:t}){let{api:n}=V(),r=_(),i=Ry(),[a,o]=(0,m.useState)(),[s,c]=(0,m.useState)(),l=L({mutationFn:e=>Ro(n,e.id),onMutate:()=>c(void 0),onSuccess:(e,t)=>{i(e.files===0?`"${t.title}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t.title}" (${String(e.files)} working file${e.files===1?``:`s`}).`,`success`)},onError:e=>c(e.message),onSettled:()=>r.invalidateQueries({queryKey:t})}),u=e.toSorted((e,t)=>t.bytes-e.bytes);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`p`,{className:`m-0 mb-2 flex items-center gap-1 text-small text-ink-2`,children:[`Keep outputs only frees a finished project's working files.`,(0,h.jsx)(U,{id:`settings.storage.keep-outputs`})]}),(0,h.jsx)(PH,{label:`Storage by project`,children:u.map(e=>(0,h.jsx)(FH,{title:e.title,meta:(0,h.jsxs)(`span`,{className:`tabular-nums`,children:[Y5(e.bytes),` · outputs `,Y5(e.outputsBytes),` · working files `,Y5(e.workingBytes)]}),actions:(0,h.jsx)(B,{variant:`quiet`,size:`small`,disabled:!e.finished||e.removableBytes===0||l.isPending,title:e.finished?e.removableBytes===0?`No working files left to remove.`:`Frees ${Y5(e.removableBytes)}.`:`Available once the project has finished.`,onClick:()=>o(e),children:l.isPending&&l.variables?.id===e.id?`Removing…`:`Keep outputs only`})},e.id))}),s===void 0?null:(0,h.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-small text-danger`,children:s}),(0,h.jsx)(Hy,{open:a!==void 0,title:`Keep only the outputs of "${a?.title??``}"?`,consequence:J5(a?.removableFiles??0,a?.removableBytes??0),confirmLabel:`Keep outputs only`,pending:l.isPending,onConfirm:()=>{let e=a;o(void 0),e!==void 0&&l.mutate(e)},onCancel:()=>o(void 0)})]})}function J5(e,t){return`This removes ${String(e)} working file(s) and frees ${Y5(t)}: the images, narration parts, subtitle timing and render settings the project was made from. The video, shorts, thumbnail, article, description and document stay, and so does anything you uploaded. If you change this project later (edit an image, a caption style or the narration, or re-render), Slopify has to make those files again first, which takes time and uses provider credits.`}function Y5(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=t[0]??`KB`;for(let e of t)if(n/=1024,r=e,n<1024||e===t.at(-1))break;return`${n>=10?n.toFixed(0):n.toFixed(1).replace(/\.0$/,``)} ${r}`}var X5=e=>[`storage`,`project`,e];function Abe({projectId:e,title:t,status:n,sample:r}){let{api:i}=V(),a=_(),o=Ry(),[s,c]=(0,m.useState)(!1),l=n===`done`||n===`partial`,u=I({queryKey:[...X5(e),n],queryFn:()=>Lo(i,e),enabled:l&&!r}),d=L({mutationFn:()=>Ro(i,e),onSuccess:e=>o(e.files===0?`"${t}" had no working files left to remove.`:`Freed ${Y5(e.bytesFreed)} from "${t}". The outputs are all still here.`,`success`),onError:e=>o(`The working files of "${t}" weren't removed: ${e.message}`,`error`),onSettled:async()=>{await Promise.all([a.invalidateQueries({queryKey:X5(e)}),a.invalidateQueries({queryKey:[`storage-usage`]}),a.invalidateQueries({queryKey:H.project(e)})])}}),f=u.data;if(!l||r||f===void 0||!f.finished||f.removableBytes===0)return null;let p=Y5(f.removableBytes);return(0,h.jsxs)(`section`,{"aria-label":`Free space`,className:`flex flex-col gap-2`,children:[(0,h.jsx)(W,{as:`h3`,title:`Free space`,meta:`Outputs ${Y5(f.outputsBytes)} · working files ${Y5(f.workingBytes)}`,info:`project.free-space`,children:(0,h.jsx)(B,{variant:`secondary`,size:`small`,"aria-label":`Free ${p}: keep the outputs, drop the working files`,disabled:d.isPending,disabledReason:`Removing the working files…`,onClick:()=>c(!0),children:d.isPending?`Removing…`:`Free ${p}`})}),(0,h.jsx)(Hy,{open:s,title:`Free ${p} from "${t}"?`,consequence:J5(f.removableFiles,f.removableBytes),confirmLabel:`Free ${p}`,cancelLabel:`Keep the working files`,pending:d.isPending,onConfirm:()=>{c(!1),d.mutate()},onCancel:()=>c(!1)})]})}function jbe({project:e,prompts:t,editing:n,onEdit:r,more:i,nextChapter:a,clock:o}){let s=e.status===`pending`&&e.setAside===!0?{tone:`done`,word:`Kept as is`}:Pbe(e.status);return(0,h.jsx)(XK,{crumb:(0,h.jsxs)(fa,{to:`/projects`,className:`inline-flex items-center gap-1 text-ink-3 hover:text-ink`,children:[(0,h.jsx)(wc,{"aria-hidden":`true`,strokeWidth:1.75}),`Projects`]}),title:e.title,row:!0,meta:(0,h.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1`,children:[Fbe(e,t),o]}),actions:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(OS,{tone:s.tone,children:[s.word,(0,h.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:`Project: ${s.word}`})]}),a!==void 0&&Mbe(e)?(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,h.jsx)(B,{variant:`secondary`,disabled:a.pending,onClick:a.run,children:a.pending?`Making the next chapter…`:`Make the next chapter`}),(0,h.jsx)(U,{id:`project.next-chapter`}),a.error===void 0?null:(0,h.jsx)(`span`,{role:`alert`,className:`max-w-[320px] text-small text-danger`,children:a.error})]}):null,(0,h.jsxs)(B,{variant:`secondary`,"aria-pressed":n,onClick:r,children:[(0,h.jsx)(Zc,{"aria-hidden":`true`,strokeWidth:1.75}),`Edit settings`]}),(0,h.jsxs)(u8,{modal:!1,children:[(0,h.jsx)(d8,{asChild:!0,children:(0,h.jsx)(Py,{label:`More project actions`,children:(0,h.jsx)(jc,{"aria-hidden":`true`,strokeWidth:1.75})})}),(0,h.jsx)(f8,{children:i.map(e=>(0,h.jsx)(Nbe,{item:e},e.id))})]})]})})}function Mbe(e){return e.config.voices?.format===`audiobook`&&(e.status===`done`||e.status===`partial`)}function Nbe({item:e}){return(0,h.jsxs)(h.Fragment,{children:[e.apart?(0,h.jsx)(Eve,{}):null,(0,h.jsx)(p8,{...e.disabled?{disabled:!0}:{},onSelect:()=>e.run(),children:e.label})]})}function Pbe(e){switch(e){case`running`:return{tone:`running`,word:`Running`};case`paused`:return{tone:`waiting`,word:`Paused`};case`failed`:return{tone:`failed`,word:`Failed`};case`partial`:return{tone:`waiting`,word:`Done with problems`};case`done`:return{tone:`done`,word:`Done`};case`canceled`:return{tone:`off`,word:`Canceled`};case`pending`:return{tone:`off`,word:`Queued`}}}function Fbe(e,t){let n=e.config.articlePrompt,r=t===void 0||t.some(e=>e.name===n),i=n===void 0||n===``?void 0:r?n:`${n} (deleted)`,a=e.config.voices?.book;return[a===void 0?void 0:AA(a),i,e.format,`started ${Wu(e.createdAt)}`].filter(e=>e!==void 0).join(` · `)}function Ibe({projectId:e}){let{api:t}=V(),n=I(cb(t,e));return n.error===null?n.data===void 0?(0,h.jsxs)(`div`,{role:`status`,"aria-label":`Loading run cost`,className:`flex flex-col gap-8`,children:[(0,h.jsx)(`span`,{className:`h-16 max-w-3xl rounded-control bg-sunken`}),(0,h.jsx)(`span`,{className:`h-40 rounded-control bg-sunken`})]}):(0,h.jsx)(Vbe,{cost:n.data}):(0,h.jsx)(aI,{tone:`danger`,title:`The run cost could not be loaded.`,children:`${n.error.message} Reload the page to try again.`})}var Lbe=new Set([`done`,`partial`,`failed`,`canceled`]);function Rbe({cost:e,status:t,measuredAt:n}){let r=e?.run??null,i=t===`running`,a=r?.current===!0&&!Lbe.has(t),[o,s]=(0,m.useState)(()=>Date.now());if((0,m.useEffect)(()=>{if(!i)return;let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[i]),!a||r===null)return null;let c=r.workingMs+(i?Math.max(0,o-n):0),l=i?Kbe(c):o7(c);return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,h.jsxs)(`span`,{role:`timer`,"aria-label":`Run time`,className:i?`inline-flex items-center gap-1.5 rounded-full bg-accent/15 px-2.5 py-0.5 font-semibold text-ink tabular-nums`:`inline-flex items-center gap-1.5 rounded-full bg-surface-2 px-2.5 py-0.5 font-semibold text-ink-2 tabular-nums`,children:[(0,h.jsx)(Qc,{"aria-hidden":`true`,strokeWidth:2,className:`size-3.5 shrink-0`}),i?`Working · ${l}`:`${l} of work so far`]})]})}var zbe=[{id:`stage`,header:`Stage`,cell:e=>(0,h.jsx)(`strong`,{children:YP[e.stage]})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`time`,header:`Working time`,numeric:!0,cell:e=>e.wallMs===null?`—`:o7(e.wallMs)}],Bbe=[{id:`model`,header:`Provider · model`,cell:e=>(0,h.jsx)(`strong`,{children:Wbe(e)})},{id:`cost`,header:`Cost`,numeric:!0,cell:Q5},{id:`api`,header:`Via API`,numeric:!0,cell:$5},{id:`usage`,header:`Usage`,numeric:!0,cell:e=>e7(e)||`—`},{id:`calls`,header:`Calls`,numeric:!0,cell:e=>t7.format(e.calls)}];function Z5(e){return e===`five_hour`?`5-hour`:e===`weekly`?`weekly`:`current`}function Vbe({cost:e}){if(e.calls===0&&e.byStage.length===0)return(0,h.jsx)(`p`,{className:`m-0 text-body text-ink-2`,children:`Nothing has been spent yet. The cost of each provider call appears here as the run makes it.`});let t=e.byModel.some(e=>e.onPlan),n=e.plans.flatMap(e=>e.reported?e.windows.map(t=>({plan:e,window:t})):[]);return(0,h.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,h.jsxs)(`section`,{"aria-label":`Run cost summary`,className:`flex flex-col gap-3`,children:[(0,h.jsxs)(x2,{children:[(0,h.jsx)(S2,{value:a7(e.cost),label:e.unpriced>0?`known cost, paid to providers`:`paid to providers`}),e.apiEquivalent===null?null:(0,h.jsx)(S2,{value:`~${a7(e.apiEquivalent)}`,label:`same work via API`}),n.map(({plan:e,window:t})=>{let n=`${Z5(t.kind)} ${e.name} limit`,r=t.usedPercent<1?`<1%`:`${n7.format(t.usedPercent)}%`;return(0,h.jsx)(S2,{value:r,label:`of ${n}`,children:(0,h.jsx)(C2,{value:t.usedPercent/100,label:`Share of the ${n} this run used`,valueText:`${r} of your ${n}; now at ${n7.format(t.nowPercent)}%`,tone:t.nowPercent>=80?`waiting`:`accent`})},`${e.account}/${t.kind}`)}),e.run===null?null:(0,h.jsx)(S2,{value:o7(e.run.workingMs),label:`this run's working time`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1 text-small text-ink-2`,children:[e.unpriced>0?(0,h.jsx)(`p`,{className:`m-0`,children:`Plus ${i7(e.unpriced,`call`)} the model catalogue has no price for.`}):null,t?(0,h.jsx)(`p`,{className:`m-0`,children:Hbe(e)}):null,e.plans.map(e=>(0,h.jsx)(`p`,{className:`m-0`,children:Ube(e)},e.account))]})]}),(0,h.jsxs)(`section`,{"aria-label":`By stage`,children:[(0,h.jsx)(W,{title:`By stage`,info:`project.cost.by-stage`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Run cost by stage`,columns:zbe,rows:e.byStage,rowKey:e=>e.stage})})]}),(0,h.jsxs)(`section`,{"aria-label":`By model`,children:[(0,h.jsx)(W,{title:`By model`,info:`project.cost.by-model`,className:`mb-3`}),(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsx)(w2,{caption:`Run cost by model`,columns:Bbe,rows:e.byModel,rowKey:e=>`${e.provider}/${e.model}/${e.kind}`})})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-2`,children:`In total: ${e7(e.totals)||`no reported usage`} · ${o7(e.totals.wallMs)} working, over every run.`}),(0,h.jsx)(`p`,{className:`m-0 text-small text-ink-3`,children:`Priced from the model catalogue${e.catalogueDate===null?``:` of ${e.catalogueDate}`} when each call finished. Retries that failed are not charged here; taxes and included credits are not counted.`})]})]})}function Hbe(e){let t=e.apiEquivalent??0;if(t===0&&e.apiUnpriced>0)return`CLI calls: $0 on your plan · no API price is listed for their models.`;let n=e.apiUnpriced>0?` (plus ${i7(e.apiUnpriced,`call`)} with no API price)`:``;return`CLI calls: $0 on your plan · ~${a7(t)} via API${n}.`}function Ube(e){return e.reported?e.windows.length===0?`${e.name} reported no limit windows for this run.`:e.windows.map(t=>{let n=Z5(t.kind),r=t.usedPercent<1?`under 1%`:`~${n7.format(t.usedPercent)}%`,i=`now at ${n7.format(t.nowPercent)}%${t.resetsAt===null?``:`, resets ${qbe(t.resetsAt)}`}`;return`This run used ${r} of your ${n} ${e.name} limit (${i}).`}).join(` `):`${e.name} did not report its plan limits for this run, so the share it used is not known.`}function Q5(e){return e.calls===0?`—`:`onPlan`in e&&e.onPlan?`$0 on plan`:e.unpriced>0?e.unpriced===e.calls?`Unknown`:`${a7(e.cost)} + unknown`:a7(e.cost)}function $5(e){return e.apiEquivalent===null?`—`:e.apiUnpriced>0&&e.apiEquivalent===0?`No API price`:`~${a7(e.apiEquivalent)}`}function Wbe(e){let t=e.model===``?`default model`:e.model;return e.apiModel===null?`${e.provider} · ${t}`:`${e.provider} · ${t} (as ${e.apiModel})`}function e7(e){let t=[];return e.tokensIn+e.tokensOut>0&&t.push(`${r7(e.tokensIn)} in / ${r7(e.tokensOut)} out tokens${e.cachedTokens>0?` (${r7(e.cachedTokens)} cached)`:``}`),e.characters>0&&t.push(`${r7(e.characters)} characters`),e.images>0&&t.push(i7(e.images,`image`)),e.seconds>0&&t.push(`${t7.format(e.seconds)} s of video`),t.join(` · `)}var t7=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),n7=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}),Gbe=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function r7(e){return e<1e4?t7.format(e):Gbe.format(e)}function i7(e,t){return`${t7.format(e)} ${t}${e===1?``:`s`}`}function a7(e){return e===0?`$0`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function Kbe(e){let t=Math.max(0,Math.floor(e/1e3)),n=e=>String(e).padStart(2,`0`);return`${String(Math.floor(t/3600))}:${n(Math.floor(t%3600/60))}:${n(t%60)}`}function o7(e){let t=Math.round(e/1e3);if(t<60)return`${t} s`;let n=Math.floor(t/60);return n<60?`${n} min ${t%60} s`:`${Math.floor(n/60)} h ${n%60} min`}function qbe(e){return new Date(e).toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})}function Jbe({project:e,revisionId:t,stages:n,outputs:r}){let i=r.filter(e=>e.role===`image`).sort((e,t)=>(e.meta.index??0)-(t.meta.index??0)),a=n.find(e=>e.kind===`article`),o=(0,m.use)(f3);return(0,h.jsx)(`div`,{className:`flex min-w-0 flex-col`,children:(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(W,{title:`Article`}),a?.state===`running`?(0,h.jsx)(D3,{projectId:e.id,stage:`article`,className:`mb-6`}):a?.state===`done`?(0,h.jsxs)(`p`,{className:`mb-6 flex flex-wrap items-center gap-3 text-small text-ink-2`,children:[`The article is written.`,o===void 0?null:(0,h.jsx)(B,{variant:`secondary`,size:`small`,onClick:()=>o(`output`),children:`Read it`})]}):(0,h.jsx)(`p`,{className:`mb-6 text-small text-ink-2`,children:a===void 0||a.state===`skipped`?`This project has no article.`:`The article appears here as it is written.`}),(0,h.jsx)(W,{title:`Narration`}),(0,h.jsx)(Xbe,{projectId:e.id,revisionId:t,audio:n.find(e=>e.kind===`audio`),outputs:r}),(0,h.jsx)(W,{title:`Images`}),i.length===0?(0,h.jsx)(`p`,{className:`text-small text-ink-2`,children:`The images appear here as each one is drawn.`}):(0,h.jsx)(u0,{list:!0,density:`compact`,label:`Images so far`,children:i.map(t=>(0,h.jsx)(Ybe,{output:t,aspect:l5(e.format)},t.id))})]})})}function Ybe({output:e,aspect:t}){let n=g8(e);if(n===void 0)return null;let r=e.meta.index===void 0?``:` ${String(e.meta.index)}`;return(0,h.jsx)(`li`,{className:`min-w-0`,children:(0,h.jsx)(l0,{src:n.url,alt:e.meta.prompt??`Image${r}`,aspect:t,...e.meta.index===void 0?{}:{meta:`#${String(e.meta.index)}`}})})}function Xbe({projectId:e,revisionId:t,audio:n,outputs:r}){let i=r.find(e=>e.role===`audio_levelled`&&e.meta.segment===`body`)??r.find(e=>e.role===`audio_body`),a=g8(n?.state===`running`?void 0:i);return n?.state===`running`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(s7,{projectId:e,revisionId:t}),(0,h.jsx)(U8,{projectId:e})]}):a===void 0?(0,h.jsx)(s7,{projectId:e,revisionId:t}):(0,h.jsx)(`div`,{className:`mb-6`,children:(0,h.jsx)(Y8,{label:`Body narration`,src:a.url})})}var Zbe=240;function s7({projectId:e,revisionId:t}){let{api:n}=V(),r=I({queryKey:Gy(e,t),queryFn:()=>rb(n,e),enabled:t!==null}),i=(r.data?.pieces??[]).flatMap(e=>e.peaks),a=(r.data?.pieces??[]).reduce((e,t)=>e+t.seconds,0),o=Math.max(1,Math.ceil(i.length/Zbe)),s=[];for(let e=0;e<i.length;e+=o)s.push(Math.max(...i.slice(e,e+o)));return(0,h.jsxs)(`div`,{className:`mb-6`,children:[(0,h.jsx)(`div`,{role:`img`,"aria-label":s.length===0?`No narration yet`:`Narration so far: ${o7(a*1e3)}`,className:`flex h-16 items-center gap-px overflow-hidden rounded-control border border-line bg-raised px-2`,children:s.map((e,t)=>(0,h.jsx)(`span`,{className:`w-[3px] shrink-0 rounded-full bg-accent`,style:{height:`${String(Math.max(4,Math.round(e*100)))}%`}},t))}),(0,h.jsx)(`p`,{className:`mt-1 text-label text-ink-3`,children:r.error?r.error.message:s.length===0?`The waveform grows as each part of the narration is spoken.`:`${o7(a*1e3)} narrated${r.data!==void 0&&`complete`in r.data&&r.data.complete?``:` so far`}`})]})}function Qbe({projectId:e,title:t,open:n,onClose:r}){let{api:i}=V(),a=_(),o=Ry(),s=Dx(),[c,l]=(0,m.useState)(``),u=L({mutationFn:()=>Ao(i,[e],c),onSuccess:()=>{a.invalidateQueries({queryKey:H.projects}),o(`Moved "${t}" to ${s.channels.find(e=>e.id===c)?.name??`the channel`}.`,`success`),r()},onError:e=>o(`The project wasn't moved: ${e.message}`,`error`)});return(0,h.jsx)(Vy,{open:n,onOpenChange:e=>{e||r()},title:`Move to channel`,description:`The project shows in that channel's list and uses its brand and playlists. Nothing it made changes.`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(B,{type:`button`,variant:`quiet`,onClick:r,children:`Cancel`}),(0,h.jsx)(B,{type:`button`,disabled:c===``||u.isPending,onClick:()=>u.mutate(),children:`Move`})]}),children:(0,h.jsx)(LB,{label:`Channel`,children:(0,h.jsx)(VB,{value:c,onChange:e=>l(e.currentTarget.value),options:[{value:``,label:`Choose a channel`},...s.channels.map(e=>({value:e.id,label:e.name}))]})})})}function $be(e){let t=[],n=[],r=0,i=()=>{let e=n[0],r=n.at(-1);e!==void 0&&r!==void 0&&t.push({start:e.start,end:r.end,text:c7(n.map(e=>e.text)),...e.speaker===void 0?{}:{speaker:e.speaker}}),n=[]};for(let t of e){if(!Number.isFinite(t.start)||!Number.isFinite(t.end)||t.start<r-.001||t.end<=t.start)throw Error(`The saved caption timing is damaged. Use More → Render the video again in the Video section to time them again, then Try again.`);let e=n[0];e!==void 0&&(t.start-r>.7||t.speaker!==e.speaker||t.end-e.start>5||c7([...n.map(e=>e.text),t.text]).split(`
304
304
  `).length>2)&&i(),n.push({...t,text:t.text.replace(/\s+/g,` `).trim()}),r=t.end,/[.!?]["'’”)]*$/.test(t.text)&&i()}return i(),t}function c7(e){let t=[],n=``;for(let r of e)n!==``&&n.length+r.length+1>42&&(t.push(n),n=``),n=n===``?r:`${n} ${r}`;return n!==``&&t.push(n),t.join(`