l(_e,V))A[Q]=_e,A[oe]=V,Q=oe;else break e}}return L}function l(A,L){var V=A.sortIndex-L.sortIndex;return V!==0?V:A.id-L.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var a=Date,o=a.now();e.unstable_now=function(){return a.now()-o}}var u=[],d=[],y=1,g=null,h=3,v=!1,x=!1,S=!1,N=typeof setTimeout=="function"?setTimeout:null,p=typeof clearTimeout=="function"?clearTimeout:null,f=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function m(A){for(var L=n(d);L!==null;){if(L.callback===null)r(d);else if(L.startTime<=A)r(d),L.sortIndex=L.expirationTime,t(u,L);else break;L=n(d)}}function k(A){if(S=!1,m(A),!x)if(n(u)!==null)x=!0,Ae(E);else{var L=n(d);L!==null&&ye(k,L.startTime-A)}}function E(A,L){x=!1,S&&(S=!1,p(j),j=-1),v=!0;var V=h;try{for(m(L),g=n(u);g!==null&&(!(g.expirationTime>L)||A&&!G());){var Q=g.callback;if(typeof Q=="function"){g.callback=null,h=g.priorityLevel;var te=Q(g.expirationTime<=L);L=e.unstable_now(),typeof te=="function"?g.callback=te:g===n(u)&&r(u),m(L)}else r(u);g=n(u)}if(g!==null)var ze=!0;else{var ne=n(d);ne!==null&&ye(k,ne.startTime-L),ze=!1}return ze}finally{g=null,h=V,v=!1}}var b=!1,T=null,j=-1,P=5,R=-1;function G(){return!(e.unstable_now()-RA||125Q?(A.sortIndex=V,t(d,A),n(u)===null&&A===n(d)&&(S?(p(j),j=-1):S=!0,ye(k,V-Q))):(A.sortIndex=te,t(u,A),x||v||(x=!0,Ae(E))),A},e.unstable_shouldYield=G,e.unstable_wrapCallback=function(A){var L=h;return function(){var V=h;h=L;try{return A.apply(this,arguments)}finally{h=V}}}})(ec);Zu.exports=ec;var Df=Zu.exports;/**
* @license React
* react-dom.production.min.js
*
@@ -30,18 +30,20 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
- */var If=c,ft=zf;function $(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ni=Object.prototype.hasOwnProperty,$f=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,xo={},wo={};function Df(e){return Ni.call(wo,e)?!0:Ni.call(xo,e)?!1:$f.test(e)?wo[e]=!0:(xo[e]=!0,!1)}function Of(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function Af(e,t,n,r){if(t===null||typeof t>"u"||Of(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function Ze(e,t,n,r,l,i,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=l,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=a}var He={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){He[e]=new Ze(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];He[t]=new Ze(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){He[e]=new Ze(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){He[e]=new Ze(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){He[e]=new Ze(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){He[e]=new Ze(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){He[e]=new Ze(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){He[e]=new Ze(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){He[e]=new Ze(e,5,!1,e.toLowerCase(),null,!1,!1)});var ka=/[\-:]([a-z])/g;function ja(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(ka,ja);He[t]=new Ze(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(ka,ja);He[t]=new Ze(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(ka,ja);He[t]=new Ze(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){He[e]=new Ze(e,1,!1,e.toLowerCase(),null,!1,!1)});He.xlinkHref=new Ze("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){He[e]=new Ze(e,1,!1,e.toLowerCase(),null,!0,!0)});function Sa(e,t,n,r){var l=He.hasOwnProperty(t)?He[t]:null;(l!==null?l.type!==0:r||!(2"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ni=Object.prototype.hasOwnProperty,Af=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,xo={},wo={};function Mf(e){return Ni.call(wo,e)?!0:Ni.call(xo,e)?!1:Af.test(e)?wo[e]=!0:(xo[e]=!0,!1)}function Ff(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function Bf(e,t,n,r){if(t===null||typeof t>"u"||Ff(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function et(e,t,n,r,l,i,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=l,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=a}var We={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){We[e]=new et(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];We[t]=new et(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){We[e]=new et(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){We[e]=new et(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){We[e]=new et(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){We[e]=new et(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){We[e]=new et(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){We[e]=new et(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){We[e]=new et(e,5,!1,e.toLowerCase(),null,!1,!1)});var ka=/[\-:]([a-z])/g;function ja(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(ka,ja);We[t]=new et(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(ka,ja);We[t]=new et(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(ka,ja);We[t]=new et(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){We[e]=new et(e,1,!1,e.toLowerCase(),null,!1,!1)});We.xlinkHref=new et("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){We[e]=new et(e,1,!1,e.toLowerCase(),null,!0,!0)});function Sa(e,t,n,r){var l=We.hasOwnProperty(t)?We[t]:null;(l!==null?l.type!==0:r||!(2o||l[a]!==i[o]){var u=`
-`+l[a].replace(" at new "," at ");return e.displayName&&u.includes("")&&(u=u.replace("",e.displayName)),u}while(1<=a&&0<=o);break}}}finally{Ks=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?zr(e):""}function Mf(e){switch(e.tag){case 5:return zr(e.type);case 16:return zr("Lazy");case 13:return zr("Suspense");case 19:return zr("SuspenseList");case 0:case 2:case 15:return e=Xs(e.type,!1),e;case 11:return e=Xs(e.type.render,!1),e;case 1:return e=Xs(e.type,!0),e;default:return""}}function bi(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Kn:return"Fragment";case qn:return"Portal";case _i:return"Profiler";case Na:return"StrictMode";case Ci:return"Suspense";case Ei:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case nc:return(e.displayName||"Context")+".Consumer";case tc:return(e._context.displayName||"Context")+".Provider";case _a:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Ca:return t=e.displayName||null,t!==null?t:bi(e.type)||"Memo";case rn:t=e._payload,e=e._init;try{return bi(e(t))}catch{}}return null}function Ff(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return bi(t);case 8:return t===Na?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function vn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function lc(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Bf(e){var t=lc(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var l=n.get,i=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return l.call(this)},set:function(a){r=""+a,i.call(this,a)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(a){r=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Sl(e){e._valueTracker||(e._valueTracker=Bf(e))}function sc(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=lc(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function es(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Ti(e,t){var n=t.checked;return Se({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function jo(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=vn(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function ic(e,t){t=t.checked,t!=null&&Sa(e,"checked",t,!1)}function Pi(e,t){ic(e,t);var n=vn(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Li(e,t.type,n):t.hasOwnProperty("defaultValue")&&Li(e,t.type,vn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function So(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function Li(e,t,n){(t!=="number"||es(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Ir=Array.isArray;function sr(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=Nl.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Xr(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Mr={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Uf=["Webkit","ms","Moz","O"];Object.keys(Mr).forEach(function(e){Uf.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Mr[t]=Mr[e]})});function cc(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Mr.hasOwnProperty(e)&&Mr[e]?(""+t).trim():t+"px"}function dc(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=cc(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var Hf=Se({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Ii(e,t){if(t){if(Hf[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error($(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error($(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error($(61))}if(t.style!=null&&typeof t.style!="object")throw Error($(62))}}function $i(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Di=null;function Ea(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Oi=null,ir=null,ar=null;function Co(e){if(e=gl(e)){if(typeof Oi!="function")throw Error($(280));var t=e.stateNode;t&&(t=Ps(t),Oi(e.stateNode,e.type,t))}}function fc(e){ir?ar?ar.push(e):ar=[e]:ir=e}function pc(){if(ir){var e=ir,t=ar;if(ar=ir=null,Co(e),t)for(e=0;e>>=0,e===0?32:31-(ep(e)/tp|0)|0}var _l=64,Cl=4194304;function $r(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function ls(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,l=e.suspendedLanes,i=e.pingedLanes,a=n&268435455;if(a!==0){var o=a&~l;o!==0?r=$r(o):(i&=a,i!==0&&(r=$r(i)))}else a=n&~l,a!==0?r=$r(a):i!==0&&(r=$r(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&l)&&(l=r&-r,i=t&-t,l>=i||l===16&&(i&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function hl(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Rt(t),e[t]=n}function sp(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Br),$o=" ",Do=!1;function zc(e,t){switch(e){case"keyup":return zp.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Ic(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Xn=!1;function $p(e,t){switch(e){case"compositionend":return Ic(t);case"keypress":return t.which!==32?null:(Do=!0,$o);case"textInput":return e=t.data,e===$o&&Do?null:e;default:return null}}function Dp(e,t){if(Xn)return e==="compositionend"||!$a&&zc(e,t)?(e=Lc(),Hl=Ra=on=null,Xn=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Fo(n)}}function Ac(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Ac(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Mc(){for(var e=window,t=es();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=es(e.document)}return t}function Da(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function Vp(e){var t=Mc(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Ac(n.ownerDocument.documentElement,n)){if(r!==null&&Da(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var l=n.textContent.length,i=Math.min(r.start,l);r=r.end===void 0?i:Math.min(r.end,l),!e.extend&&i>r&&(l=r,r=i,i=l),l=Bo(n,i);var a=Bo(n,r);l&&a&&(e.rangeCount!==1||e.anchorNode!==l.node||e.anchorOffset!==l.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(l.node,l.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(a.node,a.offset)):(t.setEnd(a.node,a.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,Jn=null,Hi=null,Hr=null,Wi=!1;function Uo(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Wi||Jn==null||Jn!==es(r)||(r=Jn,"selectionStart"in r&&Da(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Hr&&tl(Hr,r)||(Hr=r,r=as(Hi,"onSelect"),0Zn||(e.current=Ji[Zn],Ji[Zn]=null,Zn--)}function fe(e,t){Zn++,Ji[Zn]=e.current,e.current=t}var xn={},Xe=kn(xn),nt=kn(!1),In=xn;function pr(e,t){var n=e.type.contextTypes;if(!n)return xn;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var l={},i;for(i in n)l[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=l),l}function rt(e){return e=e.childContextTypes,e!=null}function us(){ge(nt),ge(Xe)}function Xo(e,t,n){if(Xe.current!==xn)throw Error($(168));fe(Xe,t),fe(nt,n)}function Kc(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var l in r)if(!(l in t))throw Error($(108,Ff(e)||"Unknown",l));return Se({},n,r)}function cs(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||xn,In=Xe.current,fe(Xe,e),fe(nt,nt.current),!0}function Jo(e,t,n){var r=e.stateNode;if(!r)throw Error($(169));n?(e=Kc(e,t,In),r.__reactInternalMemoizedMergedChildContext=e,ge(nt),ge(Xe),fe(Xe,e)):ge(nt),fe(nt,n)}var Qt=null,Ls=!1,ui=!1;function Xc(e){Qt===null?Qt=[e]:Qt.push(e)}function rh(e){Ls=!0,Xc(e)}function jn(){if(!ui&&Qt!==null){ui=!0;var e=0,t=ue;try{var n=Qt;for(ue=1;e>=a,l-=a,qt=1<<32-Rt(t)+l|n<j?(P=T,T=null):P=T.sibling;var R=h(p,T,m[j],k);if(R===null){T===null&&(T=P);break}e&&T&&R.alternate===null&&t(p,T),f=i(R,f,j),b===null?E=R:b.sibling=R,b=R,T=P}if(j===m.length)return n(p,T),xe&&Cn(p,j),E;if(T===null){for(;jj?(P=T,T=null):P=T.sibling;var G=h(p,T,R.value,k);if(G===null){T===null&&(T=P);break}e&&T&&G.alternate===null&&t(p,T),f=i(G,f,j),b===null?E=G:b.sibling=G,b=G,T=P}if(R.done)return n(p,T),xe&&Cn(p,j),E;if(T===null){for(;!R.done;j++,R=m.next())R=g(p,R.value,k),R!==null&&(f=i(R,f,j),b===null?E=R:b.sibling=R,b=R);return xe&&Cn(p,j),E}for(T=r(p,T);!R.done;j++,R=m.next())R=v(T,p,j,R.value,k),R!==null&&(e&&R.alternate!==null&&T.delete(R.key===null?j:R.key),f=i(R,f,j),b===null?E=R:b.sibling=R,b=R);return e&&T.forEach(function(H){return t(p,H)}),xe&&Cn(p,j),E}function N(p,f,m,k){if(typeof m=="object"&&m!==null&&m.type===Kn&&m.key===null&&(m=m.props.children),typeof m=="object"&&m!==null){switch(m.$$typeof){case jl:e:{for(var E=m.key,b=f;b!==null;){if(b.key===E){if(E=m.type,E===Kn){if(b.tag===7){n(p,b.sibling),f=l(b,m.props.children),f.return=p,p=f;break e}}else if(b.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===rn&&Zo(E)===b.type){n(p,b.sibling),f=l(b,m.props),f.ref=Tr(p,b,m),f.return=p,p=f;break e}n(p,b);break}else t(p,b);b=b.sibling}m.type===Kn?(f=zn(m.props.children,p.mode,k,m.key),f.return=p,p=f):(k=Gl(m.type,m.key,m.props,null,p.mode,k),k.ref=Tr(p,f,m),k.return=p,p=k)}return a(p);case qn:e:{for(b=m.key;f!==null;){if(f.key===b)if(f.tag===4&&f.stateNode.containerInfo===m.containerInfo&&f.stateNode.implementation===m.implementation){n(p,f.sibling),f=l(f,m.children||[]),f.return=p,p=f;break e}else{n(p,f);break}else t(p,f);f=f.sibling}f=yi(m,p.mode,k),f.return=p,p=f}return a(p);case rn:return b=m._init,N(p,f,b(m._payload),k)}if(Ir(m))return x(p,f,m,k);if(Nr(m))return S(p,f,m,k);zl(p,m)}return typeof m=="string"&&m!==""||typeof m=="number"?(m=""+m,f!==null&&f.tag===6?(n(p,f.sibling),f=l(f,m),f.return=p,p=f):(n(p,f),f=gi(m,p.mode,k),f.return=p,p=f),a(p)):n(p,f)}return N}var mr=Zc(!0),ed=Zc(!1),ps=kn(null),hs=null,nr=null,Fa=null;function Ba(){Fa=nr=hs=null}function Ua(e){var t=ps.current;ge(ps),e._currentValue=t}function Zi(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function ur(e,t){hs=e,Fa=nr=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(tt=!0),e.firstContext=null)}function St(e){var t=e._currentValue;if(Fa!==e)if(e={context:e,memoizedValue:t,next:null},nr===null){if(hs===null)throw Error($(308));nr=e,hs.dependencies={lanes:0,firstContext:e}}else nr=nr.next=e;return t}var Tn=null;function Ha(e){Tn===null?Tn=[e]:Tn.push(e)}function td(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Ha(t)):(n.next=l.next,l.next=n),t.interleaved=n,Yt(e,r)}function Yt(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var ln=!1;function Wa(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function nd(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Xt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function hn(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,ae&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,Yt(e,n)}return l=r.interleaved,l===null?(t.next=t,Ha(r)):(t.next=l.next,l.next=t),r.interleaved=t,Yt(e,n)}function Vl(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ta(e,n)}}function eu(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var l=null,i=null;if(n=n.firstBaseUpdate,n!==null){do{var a={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};i===null?l=i=a:i=i.next=a,n=n.next}while(n!==null);i===null?l=i=t:i=i.next=t}else l=i=t;n={baseState:r.baseState,firstBaseUpdate:l,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function ms(e,t,n,r){var l=e.updateQueue;ln=!1;var i=l.firstBaseUpdate,a=l.lastBaseUpdate,o=l.shared.pending;if(o!==null){l.shared.pending=null;var u=o,d=u.next;u.next=null,a===null?i=d:a.next=d,a=u;var y=e.alternate;y!==null&&(y=y.updateQueue,o=y.lastBaseUpdate,o!==a&&(o===null?y.firstBaseUpdate=d:o.next=d,y.lastBaseUpdate=u))}if(i!==null){var g=l.baseState;a=0,y=d=u=null,o=i;do{var h=o.lane,v=o.eventTime;if((r&h)===h){y!==null&&(y=y.next={eventTime:v,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var x=e,S=o;switch(h=t,v=n,S.tag){case 1:if(x=S.payload,typeof x=="function"){g=x.call(v,g,h);break e}g=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=S.payload,h=typeof x=="function"?x.call(v,g,h):x,h==null)break e;g=Se({},g,h);break e;case 2:ln=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,h=l.effects,h===null?l.effects=[o]:h.push(o))}else v={eventTime:v,lane:h,tag:o.tag,payload:o.payload,callback:o.callback,next:null},y===null?(d=y=v,u=g):y=y.next=v,a|=h;if(o=o.next,o===null){if(o=l.shared.pending,o===null)break;h=o,o=h.next,h.next=null,l.lastBaseUpdate=h,l.shared.pending=null}}while(!0);if(y===null&&(u=g),l.baseState=u,l.firstBaseUpdate=d,l.lastBaseUpdate=y,t=l.shared.interleaved,t!==null){l=t;do a|=l.lane,l=l.next;while(l!==t)}else i===null&&(l.shared.lanes=0);On|=a,e.lanes=a,e.memoizedState=g}}function tu(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=di.transition;di.transition={};try{e(!1),t()}finally{ue=n,di.transition=r}}function xd(){return Nt().memoizedState}function ah(e,t,n){var r=gn(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},wd(e))kd(t,n);else if(n=td(e,t,n,r),n!==null){var l=Ge();zt(n,e,r,l),jd(n,t,r)}}function oh(e,t,n){var r=gn(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(wd(e))kd(t,l);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var a=t.lastRenderedState,o=i(a,n);if(l.hasEagerState=!0,l.eagerState=o,It(o,a)){var u=t.interleaved;u===null?(l.next=l,Ha(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=td(e,t,l,r),n!==null&&(l=Ge(),zt(n,e,r,l),jd(n,t,r))}}function wd(e){var t=e.alternate;return e===je||t!==null&&t===je}function kd(e,t){Wr=ys=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function jd(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ta(e,n)}}var vs={readContext:St,useCallback:Qe,useContext:Qe,useEffect:Qe,useImperativeHandle:Qe,useInsertionEffect:Qe,useLayoutEffect:Qe,useMemo:Qe,useReducer:Qe,useRef:Qe,useState:Qe,useDebugValue:Qe,useDeferredValue:Qe,useTransition:Qe,useMutableSource:Qe,useSyncExternalStore:Qe,useId:Qe,unstable_isNewReconciler:!1},uh={readContext:St,useCallback:function(e,t){return Ft().memoizedState=[e,t===void 0?null:t],e},useContext:St,useEffect:ru,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,ql(4194308,4,hd.bind(null,t,e),n)},useLayoutEffect:function(e,t){return ql(4194308,4,e,t)},useInsertionEffect:function(e,t){return ql(4,2,e,t)},useMemo:function(e,t){var n=Ft();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ft();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=ah.bind(null,je,e),[r.memoizedState,e]},useRef:function(e){var t=Ft();return e={current:e},t.memoizedState=e},useState:nu,useDebugValue:Ya,useDeferredValue:function(e){return Ft().memoizedState=e},useTransition:function(){var e=nu(!1),t=e[0];return e=ih.bind(null,e[1]),Ft().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=je,l=Ft();if(xe){if(n===void 0)throw Error($(407));n=n()}else{if(n=t(),Me===null)throw Error($(349));Dn&30||id(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,ru(od.bind(null,r,i,e),[e]),r.flags|=2048,ul(9,ad.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Ft(),t=Me.identifierPrefix;if(xe){var n=Kt,r=qt;n=(r&~(1<<32-Rt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=al++,0")&&(u=u.replace("",e.displayName)),u}while(1<=a&&0<=o);break}}}finally{Ks=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?zr(e):""}function Uf(e){switch(e.tag){case 5:return zr(e.type);case 16:return zr("Lazy");case 13:return zr("Suspense");case 19:return zr("SuspenseList");case 0:case 2:case 15:return e=Xs(e.type,!1),e;case 11:return e=Xs(e.type.render,!1),e;case 1:return e=Xs(e.type,!0),e;default:return""}}function bi(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Kn:return"Fragment";case qn:return"Portal";case _i:return"Profiler";case Na:return"StrictMode";case Ci:return"Suspense";case Ei:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case rc:return(e.displayName||"Context")+".Consumer";case nc:return(e._context.displayName||"Context")+".Provider";case _a:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Ca:return t=e.displayName||null,t!==null?t:bi(e.type)||"Memo";case rn:t=e._payload,e=e._init;try{return bi(e(t))}catch{}}return null}function Hf(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return bi(t);case 8:return t===Na?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function vn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function sc(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Wf(e){var t=sc(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var l=n.get,i=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return l.call(this)},set:function(a){r=""+a,i.call(this,a)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(a){r=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Sl(e){e._valueTracker||(e._valueTracker=Wf(e))}function ic(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=sc(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function es(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Ti(e,t){var n=t.checked;return Ne({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function jo(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=vn(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function ac(e,t){t=t.checked,t!=null&&Sa(e,"checked",t,!1)}function Pi(e,t){ac(e,t);var n=vn(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Li(e,t.type,n):t.hasOwnProperty("defaultValue")&&Li(e,t.type,vn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function So(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function Li(e,t,n){(t!=="number"||es(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Ir=Array.isArray;function sr(e,t,n,r){if(e=e.options,t){t={};for(var l=0;l"+t.valueOf().toString()+"",t=Nl.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Xr(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Mr={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Vf=["Webkit","ms","Moz","O"];Object.keys(Mr).forEach(function(e){Vf.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Mr[t]=Mr[e]})});function dc(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Mr.hasOwnProperty(e)&&Mr[e]?(""+t).trim():t+"px"}function fc(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,l=dc(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,l):e[n]=l}}var Qf=Ne({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Ii(e,t){if(t){if(Qf[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error($(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error($(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error($(61))}if(t.style!=null&&typeof t.style!="object")throw Error($(62))}}function $i(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Di=null;function Ea(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Oi=null,ir=null,ar=null;function Co(e){if(e=gl(e)){if(typeof Oi!="function")throw Error($(280));var t=e.stateNode;t&&(t=Ps(t),Oi(e.stateNode,e.type,t))}}function pc(e){ir?ar?ar.push(e):ar=[e]:ir=e}function hc(){if(ir){var e=ir,t=ar;if(ar=ir=null,Co(e),t)for(e=0;e>>=0,e===0?32:31-(rp(e)/lp|0)|0}var _l=64,Cl=4194304;function $r(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function ls(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,l=e.suspendedLanes,i=e.pingedLanes,a=n&268435455;if(a!==0){var o=a&~l;o!==0?r=$r(o):(i&=a,i!==0&&(r=$r(i)))}else a=n&~l,a!==0?r=$r(a):i!==0&&(r=$r(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&l)&&(l=r&-r,i=t&-t,l>=i||l===16&&(i&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function hl(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Rt(t),e[t]=n}function op(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Br),$o=" ",Do=!1;function Ic(e,t){switch(e){case"keyup":return Dp.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function $c(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Xn=!1;function Ap(e,t){switch(e){case"compositionend":return $c(t);case"keypress":return t.which!==32?null:(Do=!0,$o);case"textInput":return e=t.data,e===$o&&Do?null:e;default:return null}}function Mp(e,t){if(Xn)return e==="compositionend"||!$a&&Ic(e,t)?(e=Rc(),Hl=Ra=on=null,Xn=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Fo(n)}}function Mc(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Mc(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Fc(){for(var e=window,t=es();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=es(e.document)}return t}function Da(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function Kp(e){var t=Fc(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Mc(n.ownerDocument.documentElement,n)){if(r!==null&&Da(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var l=n.textContent.length,i=Math.min(r.start,l);r=r.end===void 0?i:Math.min(r.end,l),!e.extend&&i>r&&(l=r,r=i,i=l),l=Bo(n,i);var a=Bo(n,r);l&&a&&(e.rangeCount!==1||e.anchorNode!==l.node||e.anchorOffset!==l.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(l.node,l.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(a.node,a.offset)):(t.setEnd(a.node,a.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,Jn=null,Hi=null,Hr=null,Wi=!1;function Uo(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Wi||Jn==null||Jn!==es(r)||(r=Jn,"selectionStart"in r&&Da(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Hr&&tl(Hr,r)||(Hr=r,r=as(Hi,"onSelect"),0Zn||(e.current=Ji[Zn],Ji[Zn]=null,Zn--)}function fe(e,t){Zn++,Ji[Zn]=e.current,e.current=t}var xn={},Je=kn(xn),rt=kn(!1),In=xn;function pr(e,t){var n=e.type.contextTypes;if(!n)return xn;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var l={},i;for(i in n)l[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=l),l}function lt(e){return e=e.childContextTypes,e!=null}function us(){ge(rt),ge(Je)}function Xo(e,t,n){if(Je.current!==xn)throw Error($(168));fe(Je,t),fe(rt,n)}function Xc(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var l in r)if(!(l in t))throw Error($(108,Hf(e)||"Unknown",l));return Ne({},n,r)}function cs(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||xn,In=Je.current,fe(Je,e),fe(rt,rt.current),!0}function Jo(e,t,n){var r=e.stateNode;if(!r)throw Error($(169));n?(e=Xc(e,t,In),r.__reactInternalMemoizedMergedChildContext=e,ge(rt),ge(Je),fe(Je,e)):ge(rt),fe(rt,n)}var Qt=null,Ls=!1,ui=!1;function Jc(e){Qt===null?Qt=[e]:Qt.push(e)}function ih(e){Ls=!0,Jc(e)}function jn(){if(!ui&&Qt!==null){ui=!0;var e=0,t=ue;try{var n=Qt;for(ue=1;e>=a,l-=a,qt=1<<32-Rt(t)+l|n<j?(P=T,T=null):P=T.sibling;var R=h(p,T,m[j],k);if(R===null){T===null&&(T=P);break}e&&T&&R.alternate===null&&t(p,T),f=i(R,f,j),b===null?E=R:b.sibling=R,b=R,T=P}if(j===m.length)return n(p,T),we&&Cn(p,j),E;if(T===null){for(;jj?(P=T,T=null):P=T.sibling;var G=h(p,T,R.value,k);if(G===null){T===null&&(T=P);break}e&&T&&G.alternate===null&&t(p,T),f=i(G,f,j),b===null?E=G:b.sibling=G,b=G,T=P}if(R.done)return n(p,T),we&&Cn(p,j),E;if(T===null){for(;!R.done;j++,R=m.next())R=g(p,R.value,k),R!==null&&(f=i(R,f,j),b===null?E=R:b.sibling=R,b=R);return we&&Cn(p,j),E}for(T=r(p,T);!R.done;j++,R=m.next())R=v(T,p,j,R.value,k),R!==null&&(e&&R.alternate!==null&&T.delete(R.key===null?j:R.key),f=i(R,f,j),b===null?E=R:b.sibling=R,b=R);return e&&T.forEach(function(H){return t(p,H)}),we&&Cn(p,j),E}function N(p,f,m,k){if(typeof m=="object"&&m!==null&&m.type===Kn&&m.key===null&&(m=m.props.children),typeof m=="object"&&m!==null){switch(m.$$typeof){case jl:e:{for(var E=m.key,b=f;b!==null;){if(b.key===E){if(E=m.type,E===Kn){if(b.tag===7){n(p,b.sibling),f=l(b,m.props.children),f.return=p,p=f;break e}}else if(b.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===rn&&Zo(E)===b.type){n(p,b.sibling),f=l(b,m.props),f.ref=Tr(p,b,m),f.return=p,p=f;break e}n(p,b);break}else t(p,b);b=b.sibling}m.type===Kn?(f=zn(m.props.children,p.mode,k,m.key),f.return=p,p=f):(k=Gl(m.type,m.key,m.props,null,p.mode,k),k.ref=Tr(p,f,m),k.return=p,p=k)}return a(p);case qn:e:{for(b=m.key;f!==null;){if(f.key===b)if(f.tag===4&&f.stateNode.containerInfo===m.containerInfo&&f.stateNode.implementation===m.implementation){n(p,f.sibling),f=l(f,m.children||[]),f.return=p,p=f;break e}else{n(p,f);break}else t(p,f);f=f.sibling}f=yi(m,p.mode,k),f.return=p,p=f}return a(p);case rn:return b=m._init,N(p,f,b(m._payload),k)}if(Ir(m))return x(p,f,m,k);if(Nr(m))return S(p,f,m,k);zl(p,m)}return typeof m=="string"&&m!==""||typeof m=="number"?(m=""+m,f!==null&&f.tag===6?(n(p,f.sibling),f=l(f,m),f.return=p,p=f):(n(p,f),f=gi(m,p.mode,k),f.return=p,p=f),a(p)):n(p,f)}return N}var mr=ed(!0),td=ed(!1),ps=kn(null),hs=null,nr=null,Fa=null;function Ba(){Fa=nr=hs=null}function Ua(e){var t=ps.current;ge(ps),e._currentValue=t}function Zi(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function ur(e,t){hs=e,Fa=nr=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(nt=!0),e.firstContext=null)}function St(e){var t=e._currentValue;if(Fa!==e)if(e={context:e,memoizedValue:t,next:null},nr===null){if(hs===null)throw Error($(308));nr=e,hs.dependencies={lanes:0,firstContext:e}}else nr=nr.next=e;return t}var Tn=null;function Ha(e){Tn===null?Tn=[e]:Tn.push(e)}function nd(e,t,n,r){var l=t.interleaved;return l===null?(n.next=n,Ha(t)):(n.next=l.next,l.next=n),t.interleaved=n,Yt(e,r)}function Yt(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var ln=!1;function Wa(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function rd(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Xt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function hn(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,ae&2){var l=r.pending;return l===null?t.next=t:(t.next=l.next,l.next=t),r.pending=t,Yt(e,n)}return l=r.interleaved,l===null?(t.next=t,Ha(r)):(t.next=l.next,l.next=t),r.interleaved=t,Yt(e,n)}function Vl(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ta(e,n)}}function eu(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var l=null,i=null;if(n=n.firstBaseUpdate,n!==null){do{var a={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};i===null?l=i=a:i=i.next=a,n=n.next}while(n!==null);i===null?l=i=t:i=i.next=t}else l=i=t;n={baseState:r.baseState,firstBaseUpdate:l,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function ms(e,t,n,r){var l=e.updateQueue;ln=!1;var i=l.firstBaseUpdate,a=l.lastBaseUpdate,o=l.shared.pending;if(o!==null){l.shared.pending=null;var u=o,d=u.next;u.next=null,a===null?i=d:a.next=d,a=u;var y=e.alternate;y!==null&&(y=y.updateQueue,o=y.lastBaseUpdate,o!==a&&(o===null?y.firstBaseUpdate=d:o.next=d,y.lastBaseUpdate=u))}if(i!==null){var g=l.baseState;a=0,y=d=u=null,o=i;do{var h=o.lane,v=o.eventTime;if((r&h)===h){y!==null&&(y=y.next={eventTime:v,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var x=e,S=o;switch(h=t,v=n,S.tag){case 1:if(x=S.payload,typeof x=="function"){g=x.call(v,g,h);break e}g=x;break e;case 3:x.flags=x.flags&-65537|128;case 0:if(x=S.payload,h=typeof x=="function"?x.call(v,g,h):x,h==null)break e;g=Ne({},g,h);break e;case 2:ln=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,h=l.effects,h===null?l.effects=[o]:h.push(o))}else v={eventTime:v,lane:h,tag:o.tag,payload:o.payload,callback:o.callback,next:null},y===null?(d=y=v,u=g):y=y.next=v,a|=h;if(o=o.next,o===null){if(o=l.shared.pending,o===null)break;h=o,o=h.next,h.next=null,l.lastBaseUpdate=h,l.shared.pending=null}}while(!0);if(y===null&&(u=g),l.baseState=u,l.firstBaseUpdate=d,l.lastBaseUpdate=y,t=l.shared.interleaved,t!==null){l=t;do a|=l.lane,l=l.next;while(l!==t)}else i===null&&(l.shared.lanes=0);On|=a,e.lanes=a,e.memoizedState=g}}function tu(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=di.transition;di.transition={};try{e(!1),t()}finally{ue=n,di.transition=r}}function wd(){return Nt().memoizedState}function ch(e,t,n){var r=gn(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},kd(e))jd(t,n);else if(n=nd(e,t,n,r),n!==null){var l=Ye();zt(n,e,r,l),Sd(n,t,r)}}function dh(e,t,n){var r=gn(e),l={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(kd(e))jd(t,l);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var a=t.lastRenderedState,o=i(a,n);if(l.hasEagerState=!0,l.eagerState=o,It(o,a)){var u=t.interleaved;u===null?(l.next=l,Ha(t)):(l.next=u.next,u.next=l),t.interleaved=l;return}}catch{}finally{}n=nd(e,t,l,r),n!==null&&(l=Ye(),zt(n,e,r,l),Sd(n,t,r))}}function kd(e){var t=e.alternate;return e===Se||t!==null&&t===Se}function jd(e,t){Wr=ys=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Sd(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ta(e,n)}}var vs={readContext:St,useCallback:qe,useContext:qe,useEffect:qe,useImperativeHandle:qe,useInsertionEffect:qe,useLayoutEffect:qe,useMemo:qe,useReducer:qe,useRef:qe,useState:qe,useDebugValue:qe,useDeferredValue:qe,useTransition:qe,useMutableSource:qe,useSyncExternalStore:qe,useId:qe,unstable_isNewReconciler:!1},fh={readContext:St,useCallback:function(e,t){return Ft().memoizedState=[e,t===void 0?null:t],e},useContext:St,useEffect:ru,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,ql(4194308,4,md.bind(null,t,e),n)},useLayoutEffect:function(e,t){return ql(4194308,4,e,t)},useInsertionEffect:function(e,t){return ql(4,2,e,t)},useMemo:function(e,t){var n=Ft();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ft();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=ch.bind(null,Se,e),[r.memoizedState,e]},useRef:function(e){var t=Ft();return e={current:e},t.memoizedState=e},useState:nu,useDebugValue:Ya,useDeferredValue:function(e){return Ft().memoizedState=e},useTransition:function(){var e=nu(!1),t=e[0];return e=uh.bind(null,e[1]),Ft().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=Se,l=Ft();if(we){if(n===void 0)throw Error($(407));n=n()}else{if(n=t(),Fe===null)throw Error($(349));Dn&30||ad(r,t,n)}l.memoizedState=n;var i={value:n,getSnapshot:t};return l.queue=i,ru(ud.bind(null,r,i,e),[e]),r.flags|=2048,ul(9,od.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Ft(),t=Fe.identifierPrefix;if(we){var n=Kt,r=qt;n=(r&~(1<<32-Rt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=al++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=a.createElement(n,{is:r.is}):(e=a.createElement(n),n==="select"&&(a=e,r.multiple?a.multiple=!0:r.size&&(a.size=r.size))):e=a.createElementNS(e,n),e[Bt]=t,e[ll]=r,Rd(e,t,!1,!1),t.stateNode=e;e:{switch(a=$i(n,r),n){case"dialog":me("cancel",e),me("close",e),l=r;break;case"iframe":case"object":case"embed":me("load",e),l=r;break;case"video":case"audio":for(l=0;lvr&&(t.flags|=128,r=!0,Pr(i,!1),t.lanes=4194304)}else{if(!r)if(e=gs(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Pr(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!xe)return qe(t),null}else 2*Ee()-i.renderingStartTime>vr&&n!==1073741824&&(t.flags|=128,r=!0,Pr(i,!1),t.lanes=4194304);i.isBackwards?(a.sibling=t.child,t.child=a):(n=i.last,n!==null?n.sibling=a:t.child=a,i.last=a)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=Ee(),t.sibling=null,n=ke.current,fe(ke,r?n&1|2:n&1),t):(qe(t),null);case 22:case 23:return lo(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?ot&1073741824&&(qe(t),t.subtreeFlags&6&&(t.flags|=8192)):qe(t),null;case 24:return null;case 25:return null}throw Error($(156,t.tag))}function yh(e,t){switch(Aa(t),t.tag){case 1:return rt(t.type)&&us(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return gr(),ge(nt),ge(Xe),qa(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Qa(t),null;case 13:if(ge(ke),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error($(340));hr()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ge(ke),null;case 4:return gr(),null;case 10:return Ua(t.type._context),null;case 22:case 23:return lo(),null;case 24:return null;default:return null}}var $l=!1,Ke=!1,vh=typeof WeakSet=="function"?WeakSet:Set,W=null;function rr(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){_e(e,t,r)}else n.current=null}function oa(e,t,n){try{n()}catch(r){_e(e,t,r)}}var hu=!1;function xh(e,t){if(Vi=ss,e=Mc(),Da(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{n.nodeType,i.nodeType}catch{n=null;break e}var a=0,o=-1,u=-1,d=0,y=0,g=e,h=null;t:for(;;){for(var v;g!==n||l!==0&&g.nodeType!==3||(o=a+l),g!==i||r!==0&&g.nodeType!==3||(u=a+r),g.nodeType===3&&(a+=g.nodeValue.length),(v=g.firstChild)!==null;)h=g,g=v;for(;;){if(g===e)break t;if(h===n&&++d===l&&(o=a),h===i&&++y===r&&(u=a),(v=g.nextSibling)!==null)break;g=h,h=g.parentNode}g=v}n=o===-1||u===-1?null:{start:o,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Qi={focusedElem:e,selectionRange:n},ss=!1,W=t;W!==null;)if(t=W,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,W=e;else for(;W!==null;){t=W;try{var x=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var S=x.memoizedProps,N=x.memoizedState,p=t.stateNode,f=p.getSnapshotBeforeUpdate(t.elementType===t.type?S:Tt(t.type,S),N);p.__reactInternalSnapshotBeforeUpdate=f}break;case 3:var m=t.stateNode.containerInfo;m.nodeType===1?m.textContent="":m.nodeType===9&&m.documentElement&&m.removeChild(m.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error($(163))}}catch(k){_e(t,t.return,k)}if(e=t.sibling,e!==null){e.return=t.return,W=e;break}W=t.return}return x=hu,hu=!1,x}function Vr(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var i=l.destroy;l.destroy=void 0,i!==void 0&&oa(t,n,i)}l=l.next}while(l!==r)}}function Is(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function ua(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function $d(e){var t=e.alternate;t!==null&&(e.alternate=null,$d(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Bt],delete t[ll],delete t[Xi],delete t[th],delete t[nh])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Dd(e){return e.tag===5||e.tag===3||e.tag===4}function mu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Dd(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function ca(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=os));else if(r!==4&&(e=e.child,e!==null))for(ca(e,t,n),e=e.sibling;e!==null;)ca(e,t,n),e=e.sibling}function da(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(da(e,t,n),e=e.sibling;e!==null;)da(e,t,n),e=e.sibling}var Be=null,Pt=!1;function nn(e,t,n){for(n=n.child;n!==null;)Od(e,t,n),n=n.sibling}function Od(e,t,n){if(Ut&&typeof Ut.onCommitFiberUnmount=="function")try{Ut.onCommitFiberUnmount(Cs,n)}catch{}switch(n.tag){case 5:Ke||rr(n,t);case 6:var r=Be,l=Pt;Be=null,nn(e,t,n),Be=r,Pt=l,Be!==null&&(Pt?(e=Be,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Be.removeChild(n.stateNode));break;case 18:Be!==null&&(Pt?(e=Be,n=n.stateNode,e.nodeType===8?oi(e.parentNode,n):e.nodeType===1&&oi(e,n),Zr(e)):oi(Be,n.stateNode));break;case 4:r=Be,l=Pt,Be=n.stateNode.containerInfo,Pt=!0,nn(e,t,n),Be=r,Pt=l;break;case 0:case 11:case 14:case 15:if(!Ke&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var i=l,a=i.destroy;i=i.tag,a!==void 0&&(i&2||i&4)&&oa(n,t,a),l=l.next}while(l!==r)}nn(e,t,n);break;case 1:if(!Ke&&(rr(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){_e(n,t,o)}nn(e,t,n);break;case 21:nn(e,t,n);break;case 22:n.mode&1?(Ke=(r=Ke)||n.memoizedState!==null,nn(e,t,n),Ke=r):nn(e,t,n);break;default:nn(e,t,n)}}function gu(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new vh),t.forEach(function(r){var l=bh.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function bt(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~i}if(r=l,r=Ee()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*kh(r/1960))-r,10e?16:e,un===null)var r=!1;else{if(e=un,un=null,ks=0,ae&6)throw Error($(331));var l=ae;for(ae|=4,W=e.current;W!==null;){var i=W,a=i.child;if(W.flags&16){var o=i.deletions;if(o!==null){for(var u=0;uEe()-no?Rn(e,0):to|=n),lt(e,t)}function Vd(e,t){t===0&&(e.mode&1?(t=Cl,Cl<<=1,!(Cl&130023424)&&(Cl=4194304)):t=1);var n=Ge();e=Yt(e,t),e!==null&&(hl(e,t,n),lt(e,n))}function Eh(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Vd(e,n)}function bh(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,l=e.memoizedState;l!==null&&(n=l.retryLane);break;case 19:r=e.stateNode;break;default:throw Error($(314))}r!==null&&r.delete(t),Vd(e,n)}var Qd;Qd=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||nt.current)tt=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return tt=!1,mh(e,t,n);tt=!!(e.flags&131072)}else tt=!1,xe&&t.flags&1048576&&Jc(t,fs,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Kl(e,t),e=t.pendingProps;var l=pr(t,Xe.current);ur(t,n),l=Xa(null,t,r,e,l,n);var i=Ja();return t.flags|=1,typeof l=="object"&&l!==null&&typeof l.render=="function"&&l.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,rt(r)?(i=!0,cs(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Wa(t),l.updater=zs,t.stateNode=l,l._reactInternals=t,ta(t,r,e,n),t=la(null,t,r,!0,i,n)):(t.tag=0,xe&&i&&Oa(t),Je(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Kl(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=Ph(r),e=Tt(r,e),l){case 0:t=ra(null,t,r,e,n);break e;case 1:t=du(null,t,r,e,n);break e;case 11:t=uu(null,t,r,e,n);break e;case 14:t=cu(null,t,r,Tt(r.type,e),n);break e}throw Error($(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),ra(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),du(e,t,r,l,n);case 3:e:{if(Td(t),e===null)throw Error($(387));r=t.pendingProps,i=t.memoizedState,l=i.element,nd(e,t),ms(t,r,null,n);var a=t.memoizedState;if(r=a.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){l=yr(Error($(423)),t),t=fu(e,t,r,n,l);break e}else if(r!==l){l=yr(Error($(424)),t),t=fu(e,t,r,n,l);break e}else for(ct=pn(t.stateNode.containerInfo.firstChild),dt=t,xe=!0,Lt=null,n=ed(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(hr(),r===l){t=Zt(e,t,n);break e}Je(e,t,r,n)}t=t.child}return t;case 5:return rd(t),e===null&&Yi(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,a=l.children,qi(r,l)?a=null:i!==null&&qi(r,i)&&(t.flags|=32),bd(e,t),Je(e,t,a,n),t.child;case 6:return e===null&&Yi(t),null;case 13:return Pd(e,t,n);case 4:return Va(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=mr(t,null,r,n):Je(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),uu(e,t,r,l,n);case 7:return Je(e,t,t.pendingProps,n),t.child;case 8:return Je(e,t,t.pendingProps.children,n),t.child;case 12:return Je(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,i=t.memoizedProps,a=l.value,fe(ps,r._currentValue),r._currentValue=a,i!==null)if(It(i.value,a)){if(i.children===l.children&&!nt.current){t=Zt(e,t,n);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var o=i.dependencies;if(o!==null){a=i.child;for(var u=o.firstContext;u!==null;){if(u.context===r){if(i.tag===1){u=Xt(-1,n&-n),u.tag=2;var d=i.updateQueue;if(d!==null){d=d.shared;var y=d.pending;y===null?u.next=u:(u.next=y.next,y.next=u),d.pending=u}}i.lanes|=n,u=i.alternate,u!==null&&(u.lanes|=n),Zi(i.return,n,t),o.lanes|=n;break}u=u.next}}else if(i.tag===10)a=i.type===t.type?null:i.child;else if(i.tag===18){if(a=i.return,a===null)throw Error($(341));a.lanes|=n,o=a.alternate,o!==null&&(o.lanes|=n),Zi(a,n,t),a=i.sibling}else a=i.child;if(a!==null)a.return=i;else for(a=i;a!==null;){if(a===t){a=null;break}if(i=a.sibling,i!==null){i.return=a.return,a=i;break}a=a.return}i=a}Je(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,ur(t,n),l=St(l),r=r(l),t.flags|=1,Je(e,t,r,n),t.child;case 14:return r=t.type,l=Tt(r,t.pendingProps),l=Tt(r.type,l),cu(e,t,r,l,n);case 15:return Cd(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),Kl(e,t),t.tag=1,rt(r)?(e=!0,cs(t)):e=!1,ur(t,n),Sd(t,r,l),ta(t,r,l,n),la(null,t,r,!0,e,n);case 19:return Ld(e,t,n);case 22:return Ed(e,t,n)}throw Error($(156,t.tag))};function qd(e,t){return wc(e,t)}function Th(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function kt(e,t,n,r){return new Th(e,t,n,r)}function io(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Ph(e){if(typeof e=="function")return io(e)?1:0;if(e!=null){if(e=e.$$typeof,e===_a)return 11;if(e===Ca)return 14}return 2}function yn(e,t){var n=e.alternate;return n===null?(n=kt(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Gl(e,t,n,r,l,i){var a=2;if(r=e,typeof e=="function")io(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Kn:return zn(n.children,l,i,t);case Na:a=8,l|=8;break;case _i:return e=kt(12,n,t,l|2),e.elementType=_i,e.lanes=i,e;case Ci:return e=kt(13,n,t,l),e.elementType=Ci,e.lanes=i,e;case Ei:return e=kt(19,n,t,l),e.elementType=Ei,e.lanes=i,e;case rc:return Ds(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case tc:a=10;break e;case nc:a=9;break e;case _a:a=11;break e;case Ca:a=14;break e;case rn:a=16,r=null;break e}throw Error($(130,e==null?e:typeof e,""))}return t=kt(a,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function zn(e,t,n,r){return e=kt(7,e,r,t),e.lanes=n,e}function Ds(e,t,n,r){return e=kt(22,e,r,t),e.elementType=rc,e.lanes=n,e.stateNode={isHidden:!1},e}function gi(e,t,n){return e=kt(6,e,null,t),e.lanes=n,e}function yi(e,t,n){return t=kt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Lh(e,t,n,r,l){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Gs(0),this.expirationTimes=Gs(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Gs(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function ao(e,t,n,r,l,i,a,o,u){return e=new Lh(e,t,n,o,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=kt(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Wa(i),e}function Rh(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Gd)}catch(e){console.error(e)}}Gd(),Gu.exports=pt;var Oh=Gu.exports,Yd,Nu=Oh;Yd=Nu.createRoot,Nu.hydrateRoot;async function be(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function _u(){return be("/api/archives")}async function Cu(e,t=null){const n=t?`/api/archives/${e}/entries?collection=${encodeURIComponent(t)}`:`/api/archives/${e}/entries`;return be(n)}async function Ah(e,t,n,r=null){const l=new URLSearchParams;return t&&l.set("q",t),n&&l.set("tag",n),r&&l.set("collection",r),be(`/api/archives/${e}/entries/search?${l}`)}async function Or(e,t){return be(`/api/archives/${e}/entries/${t}`)}async function Mh(e,t){return be(`/api/archives/${e}/entries/${t}/summary`)}async function Fh(e,t,{provider:n,force:r=!1,includeImages:l=!1}={}){const i=await fetch(`/api/archives/${e}/entries/${t}/summary`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n,force:r,include_images:l})});if(!i.ok){const a=await i.text();let o=a.trim();try{o=JSON.parse(a).error||o}catch{}throw new Error(o||`Summary request failed (${i.status})`)}return i.json()}async function Bh(e,t){return be(`/api/archives/${e}/entries/${t}/children`)}function Uh(e,t,n){return Promise.all(n.map(r=>be(`/api/archives/${e}/entries/${t}/artifacts/${r}`)))}async function Hh(e){if(!e||e.length===0)return{};const t=await fetch("/api/util/resolve-tco",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?t.json():{}}async function Wh(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:n??null})});if(!r.ok)throw new Error(await r.text())}async function Al(e,t){return be(`/api/archives/${e}/entries/${t}/tags`)}async function Eu(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag_path:n})});if(!r.ok)throw new Error(`Failed to add tag (${r.status})`)}async function Vh(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags/${n}`,{method:"DELETE"});if(!r.ok)throw new Error(`Remove failed (${r.status})`)}async function bu(e,t){const n=await fetch(`/api/archives/${e}/entries/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(`Delete failed (${n.status})`)}async function Qh(e,t,n){const r=await fetch(`/api/archives/${e}/tags/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})});if(!r.ok)throw new Error(await r.text());return r.json()}async function qh(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function Kh(e,t){const n=await fetch(`/api/archives/${e}/tags`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!n.ok)throw new Error(await n.text());return n.json()}async function Xh(e,t,n){const r=await fetch(`/api/archives/${e}/tags/${t}/move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({parent_uid:n??null})});if(!r.ok)throw new Error(await r.text());return r.json()}async function vi(e){return be(`/api/archives/${e}/runs`)}async function Ml(e){return be(`/api/archives/${e}/tags`)}async function Jh(e,t,n=null,r=null){const l={locator:t};n&&n!=="best"&&(l.quality=n),r&&(typeof r.ublock_enabled=="boolean"&&(l.ublock_enabled=r.ublock_enabled),typeof r.reader_mode=="boolean"&&(l.reader_mode=r.reader_mode),typeof r.cookie_ext_enabled=="boolean"&&(l.cookie_ext_enabled=r.cookie_ext_enabled),typeof r.modal_closer_enabled=="boolean"&&(l.modal_closer_enabled=r.modal_closer_enabled),typeof r.via_freedium=="boolean"&&(l.via_freedium=r.via_freedium),r.per_item_quality&&typeof r.per_item_quality=="object"&&Object.keys(r.per_item_quality).length>0&&(l.per_item_quality=r.per_item_quality),r.sync===!0&&(l.sync=!0));const i=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!i.ok){const a=await i.json().catch(()=>({})),o=new Error(a.error||`HTTP ${i.status}`);throw o.status=i.status,o}return i.json()}async function Gh(e,{title:t,body:n,mime:r="text/markdown"}){const l={title:t,body:n};r&&r!=="text/markdown"&&(l.mime=r);const i=await fetch(`/api/archives/${e}/captures/text`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!i.ok){const a=await i.json().catch(()=>({})),o=new Error(a.error||`HTTP ${i.status}`);throw o.status=i.status,o}return i.json()}async function Yh(e,t){return be(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function Zh(e,t){const n=await fetch(`/api/archives/${e}/captures/probe-playlist`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({locator:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function Zd(e,t){return be(`/api/archives/${e}/capture_jobs/${t}`)}async function em(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function tm(e,t){const n=await fetch("/api/auth/setup",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Setup failed");return n.json()}async function nm(e,t){const n=await fetch("/api/auth/login",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Login failed");return n.json()}async function rm(){await fetch("/api/auth/logout",{method:"POST"})}async function lm(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function sm(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({display_name:e})});if(!t.ok)throw new Error(await t.text())}async function im(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function am(e,t){const n=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({current_password:e,new_password:t})});if(!n.ok){let r=await n.text();try{r=JSON.parse(r).error??r}catch{}throw new Error(r)}}async function om(){return be("/api/auth/tokens")}async function um(e){const t=await fetch("/api/auth/tokens",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})});if(!t.ok)throw new Error(await t.text());return t.json()}async function cm(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function fo(){return be("/api/admin/instance-settings")}async function Yl(e){const t=await fetch("/api/admin/instance-settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function dm(){return be("/api/admin/users")}async function fm(e,t,n){const r=await fetch("/api/admin/users",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:t,email:n||void 0})});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error||`HTTP ${r.status}`)}return r.json()}async function pm(e,t){const n=await fetch(`/api/admin/users/${e}/status`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function hm(){return be("/api/admin/roles")}async function mm(e,t){const n=await fetch("/api/admin/roles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,name:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function po(e){return be(`/api/archives/${e}/collections`)}async function gm(e,t,n,r=2,l=!0){const i=await fetch(`/api/archives/${e}/collections`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,slug:n,default_visibility_bits:r,requires_auth:l})});if(!i.ok){const a=await i.json().catch(()=>({error:i.statusText}));throw new Error(a.error||i.statusText)}return i.json()}async function ym(e,t){return be(`/api/archives/${e}/collections/${t}`)}async function ga(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections/${t}/entries`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({entry_uid:n,visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}}async function vm(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"DELETE"});if(!r.ok){const l=await r.json().catch(()=>({error:r.statusText}));throw new Error(l.error||r.statusText)}}async function xm(e,t,n,r){const l=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}}async function Tu(e,t){return be(`/api/archives/${e}/entries/${t}/collections`)}async function xi(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error??r.statusText)}}async function wm(e,t){const n=await fetch(`/api/archives/${e}/collections/${t}`,{method:"DELETE"});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error??n.statusText)}}async function km(e){return be(`/api/archives/${e}/blob-cleanup`)}async function jm(e){const t=await fetch(`/api/archives/${e}/blob-cleanup`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error??t.statusText)}return t.json()}async function Sm(e,t){const n=await fetch(`/api/archives/${e}/entries/${t}/rearchive`,{method:"POST"});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.message||`rearchive failed: ${n.status}`)}return n.json()}async function Nm(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/artifacts/${n}/media-token`,{method:"POST"});if(!r.ok)throw new Error(`media-token ${r.status}`);return r.json()}async function _m(){return be("/api/admin/cookie-rules")}async function Cm(e,t,n){const r=await fetch("/api/admin/cookie-rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url_pattern:e||null,pattern_kind:t,cookies_json:n})});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.message||`HTTP ${r.status}`)}return r.json()}async function Em(e,t){const n=await fetch(`/api/admin/cookie-rules/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.message||`HTTP ${n.status}`)}}async function bm(e){const t=await fetch(`/api/admin/cookie-rules/${e}`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.message||`HTTP ${t.status}`)}}function Tm(e,t,n){let r;return{promise:new Promise((i,a)=>{const o=new FormData;o.append("file",t),r=new XMLHttpRequest,r.open("POST",`/api/archives/${e}/uploads`),r.upload.addEventListener("progress",u=>{u.lengthComputable&&n&&n(Math.round(u.loaded/u.total*100))}),r.addEventListener("load",()=>{if(r.status>=200&&r.status<300)try{i(JSON.parse(r.responseText))}catch{a(new Error("Invalid server response"))}else{let u=`Upload failed (${r.status})`;try{u=JSON.parse(r.responseText).message||u}catch{}a(new Error(u))}}),r.addEventListener("error",()=>a(new Error("Network error during upload"))),r.addEventListener("abort",()=>a(new Error("Upload cancelled"))),r.send(o)}),abort:()=>r==null?void 0:r.abort()}}async function wi(e,t){try{await fetch(`/api/archives/${e}/uploads`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({locator:t})})}catch{}}const Pm=window.fetch;window.fetch=async(...e)=>{var n;const t=await Pm(...e);return t.status===401&&((typeof e[0]=="string"?e[0]:((n=e[0])==null?void 0:n.url)??"").includes("/api/auth/")||window.dispatchEvent(new CustomEvent("auth:expired"))),t};function Lm({onLogin:e}){const[t,n]=c.useState(""),[r,l]=c.useState(""),[i,a]=c.useState(null),[o,u]=c.useState(!1);async function d(y){y.preventDefault(),a(null),u(!0);try{const g=await nm(t,r);e(g)}catch(g){a(g.message)}finally{u(!1)}}return s.jsx("div",{className:"login-page",children:s.jsxs("div",{className:"login-card",children:[s.jsx("h1",{className:"login-brand",children:"Archivr"}),s.jsx("p",{className:"login-tagline",children:"Sign in to your archive"}),s.jsxs("form",{onSubmit:d,children:[s.jsxs("div",{className:"login-field",children:[s.jsx("label",{className:"login-label",htmlFor:"login-username",children:"Username"}),s.jsx("input",{className:"login-input",id:"login-username",type:"text",value:t,onChange:y=>n(y.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),s.jsxs("div",{className:"login-field",children:[s.jsx("label",{className:"login-label",htmlFor:"login-password",children:"Password"}),s.jsx("input",{className:"login-input",id:"login-password",type:"password",value:r,onChange:y=>l(y.target.value),required:!0,autoComplete:"current-password"})]}),i&&s.jsx("p",{className:"login-error",children:i}),s.jsx("button",{className:"login-submit",type:"submit",disabled:o,children:o?"Signing in…":"Sign in"})]})]})})}function Rm({onComplete:e}){const[t,n]=c.useState(""),[r,l]=c.useState(""),[i,a]=c.useState(""),[o,u]=c.useState(null),[d,y]=c.useState(!1);async function g(h){if(h.preventDefault(),r!==i){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),y(!0);try{await tm(t,r),e()}catch(v){u(v.message)}finally{y(!1)}}return s.jsx("div",{className:"setup-page",children:s.jsxs("div",{className:"setup-card",children:[s.jsx("h1",{className:"setup-brand",children:"Archivr"}),s.jsx("p",{className:"setup-tagline",children:"Create your owner account to get started."}),s.jsxs("form",{onSubmit:g,children:[s.jsxs("div",{className:"setup-field",children:[s.jsx("label",{className:"setup-label",htmlFor:"setup-username",children:"Username"}),s.jsx("input",{className:"setup-input",id:"setup-username",type:"text",value:t,onChange:h=>n(h.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),s.jsxs("div",{className:"setup-field",children:[s.jsx("label",{className:"setup-label",htmlFor:"setup-password",children:"Password"}),s.jsx("input",{className:"setup-input",id:"setup-password",type:"password",value:r,onChange:h=>l(h.target.value),required:!0,autoComplete:"new-password"})]}),s.jsxs("div",{className:"setup-field",children:[s.jsx("label",{className:"setup-label",htmlFor:"setup-confirm",children:"Confirm password"}),s.jsx("input",{className:"setup-input",id:"setup-confirm",type:"password",value:i,onChange:h=>a(h.target.value),required:!0,autoComplete:"new-password"})]}),o&&s.jsx("p",{className:"setup-error",children:o}),s.jsx("button",{className:"setup-submit",type:"submit",disabled:d,children:d?"Creating account…":"Create account"})]})]})})}function zm({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:i,collections:a,selectedCollectionUid:o,onCollectionChange:u,isPublicSession:d,onSignInClick:y}){const{currentUser:g,setCurrentUser:h}=c.useContext(Us)??{},[v,x]=c.useState(!1);async function S(){x(!0),await rm(),h(null),window.location.reload()}const N=a.find(m=>m.slug==="_default_"),p=!d||!!N&&!N.requires_auth,f=a.filter(m=>m.slug!=="_default_").filter(m=>!d||!m.requires_auth);return s.jsxs("header",{className:"topbar",children:[s.jsx("div",{className:"brand",children:"Archivr"}),s.jsxs("div",{className:"switchers",children:[!d&&s.jsx("div",{className:"switcher",children:s.jsx("select",{"aria-label":"Select archive",value:t??"",onChange:m=>n(m.target.value),children:e.map(m=>s.jsx("option",{value:m.id,children:m.label},m.id))})}),f.length>0&&s.jsx("div",{className:"switcher",children:s.jsxs("select",{"aria-label":"Select collection",value:o??"",onChange:m=>u(m.target.value||null),children:[p&&s.jsx("option",{value:"",children:"All entries"}),f.map(m=>s.jsx("option",{value:m.collection_uid,children:m.name},m.collection_uid))]})})]}),d?s.jsxs(s.Fragment,{children:[s.jsx("span",{style:{flex:1}}),s.jsx("button",{className:"logout-btn",onClick:y,children:"Sign in"})]}):s.jsxs(s.Fragment,{children:[s.jsx("nav",{className:"nav","aria-label":"Primary",children:["archive","tags","collections","runs","admin","settings"].map(m=>s.jsx("button",{className:`nav-link${r===m?" is-active":""}`,onClick:()=>l(m),children:m.charAt(0).toUpperCase()+m.slice(1)},m))}),s.jsx("button",{className:"capture-button",onClick:i,children:"Capture"}),g&&s.jsxs("div",{className:"user-menu",children:[s.jsx("span",{className:"user-name",children:g.display_name||g.username}),s.jsx("button",{className:"logout-btn",onClick:S,disabled:v,children:v?"Logging out…":"Log out"})]})]})]})}let dl=1;function ef(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return!!(l.startsWith("video/")||l.startsWith("short/")||l.startsWith("shorts/")||/^[a-z0-9_-]{11}$/i.test(l))}if(n.startsWith("ytm:"))return!n.slice(4).startsWith("playlist/");for(const r of["x:","twitter:","tweet:"])if(n.startsWith(r))return n.slice(r.length).startsWith("media:");if(n.startsWith("spotify:"))return!1;if(n.startsWith("instagram:")||n.startsWith("facebook:")||n.startsWith("tiktok:")||n.startsWith("reddit:")||n.startsWith("snapchat:"))return!0;if(n.startsWith("http://")||n.startsWith("https://")){if(/^https?:\/\/music\.youtube\.com\/watch/.test(n)||/^https?:\/\/(?:www\.)?(?:youtu\.be\/[0-9A-Za-z_-]+|youtube\.com\/watch\?v=[0-9A-Za-z_-]+|youtube\.com\/shorts\/[0-9A-Za-z_-]+)/.test(t)||n.startsWith("https://x.com/")||n.startsWith("http://x.com/")||/^https?:\/\/(?:www\.)?instagram\.com\//.test(n)||/^https?:\/\/(?:www\.)?facebook\.com\//.test(n)||n.startsWith("https://fb.watch/")||n.startsWith("http://fb.watch/")||/^https?:\/\/(?:www\.)?tiktok\.com\//.test(n)||/^https?:\/\/(?:www\.)?reddit\.com\//.test(n)||n.startsWith("https://redd.it/")||n.startsWith("http://redd.it/")||/^https?:\/\/(?:www\.)?snapchat\.com\//.test(n))return!0;if(n.startsWith("https://open.spotify.com/")||n.startsWith("http://open.spotify.com/"))return!1}return!1}function Ln(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return l.startsWith("playlist/")||l.startsWith("@")||l.startsWith("channel/")||l.startsWith("c/")||l.startsWith("user/")}if(n.startsWith("ytm:"))return n.slice(4).startsWith("playlist/");if(n.startsWith("spotify:")){const r=n.slice(8);return r.startsWith("album:")||r.startsWith("playlist:")}if(n.startsWith("http://")||n.startsWith("https://"))try{const r=new URL(t),l=r.hostname;if((l==="youtube.com"||l==="www.youtube.com")&&(r.pathname==="/playlist"&&r.searchParams.has("list")||r.pathname.startsWith("/@")||r.pathname.startsWith("/channel/")||r.pathname.startsWith("/c/")||r.pathname.startsWith("/user/"))||l==="music.youtube.com"&&r.pathname==="/playlist"&&r.searchParams.has("list")||l==="open.spotify.com"&&(r.pathname.startsWith("/album/")||r.pathname.startsWith("/playlist/")))return!0}catch{}return!1}function Qn(e=""){return{id:dl++,locator:e,quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,status:"idle",error:null,jobUid:null,archiveId:null,playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1,syncEnabled:!1}}function Im(e){return{id:dl++,kind:"file",filename:e,uploadProgress:0,uploadStatus:"uploading",uploadLocator:null,uploadError:null,locator:"",quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1,syncEnabled:!1,error:null,status:"idle"}}function $m(){return{id:dl++,kind:"text",title:"",body:"",mime:"text/markdown",locator:"",quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1,syncEnabled:!1,error:null,status:"idle"}}function Dm(e,t){return e==="best"?t.map(n=>({...n,quality:"best"})):e==="audio"?t.map(n=>n.has_audio?{...n,quality:"audio"}:n.quality!==null?n:{...n,quality:null}):t.map(n=>n.qualities.includes(e)?{...n,quality:e}:n.quality!==null?n:{...n,quality:null})}function Pu(e){return Array.isArray(e.playlistItems)&&e.playlistItems.some(t=>t.quality===null)}function Om({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l,onJobStarted:i,onJobSettled:a,activeJobs:o=[]}){const u=c.useRef(null),d=c.useRef(!0),y=c.useRef(new Map),g=c.useRef(new Map),h=c.useRef(new Map),v=c.useRef(t);c.useEffect(()=>{v.current=t},[t]);const x=c.useRef(null),[S,N]=c.useState(!1),p=c.useRef([]),f=c.useRef(!1),m=c.useRef(new Map),k=c.useRef(r),E=c.useRef(l);c.useEffect(()=>{k.current=r},[r]),c.useEffect(()=>{E.current=l},[l]);const b=c.useRef(i),T=c.useRef(a);c.useEffect(()=>{b.current=i},[i]),c.useEffect(()=>{T.current=a},[a]);const[j,P]=c.useState(()=>{try{const w=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(w)&&w.length>0){const B=w.filter(M=>!M.status||M.status==="idle");if(B.length>0)return B.forEach(M=>{M.id>=dl&&(dl=M.id+1)}),B.map(M=>({...Qn(M.locator),...M}))}}catch{}return[Qn()]});c.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(j.filter(w=>w.kind!=="file")))},[j]),c.useEffect(()=>{p.current=j},[j]);const[R,G]=c.useState(!1),[H,Z]=c.useState(null),[re,ce]=c.useState(null),[De,ye]=c.useState(!0),[A,L]=c.useState(!0),[V,K]=c.useState(!0);c.useEffect(()=>{fo().then(w=>{ce(w),ye(w.cookie_ext_enabled??!0),L(w.modal_closer_enabled??!0)}).catch(()=>ce({}))},[]);const te=H!==null?H:(re==null?void 0:re.ublock_enabled)??!0,[Oe,ne]=c.useState(!1);c.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(w=>sessionStorage.removeItem(w)),o.forEach(w=>{w.jobUid&&!y.current.has(w.jobUid)&&we(w.id,w.jobUid,w.locator,w.archiveId,null)})},[]),c.useEffect(()=>{const w=u.current;if(!w)return;const B=()=>{if(g.current.forEach(M=>clearTimeout(M)),g.current.clear(),!f.current){const M=v.current;p.current.forEach(z=>{var F;z.kind==="file"&&(z.uploadStatus==="uploading"?((F=m.current.get(z.id))==null||F(),m.current.delete(z.id)):z.uploadStatus==="done"&&z.uploadLocator&&wi(M,z.uploadLocator).catch(()=>{}))})}f.current=!1,n()};return w.addEventListener("close",B),()=>w.removeEventListener("close",B)},[n]),c.useEffect(()=>{const w=u.current;w&&(e?(d.current||P([Qn()]),d.current=!1,w.open||w.showModal()):(g.current.forEach(B=>clearTimeout(B)),g.current.clear(),w.open&&w.close()))},[e]),c.useEffect(()=>()=>{y.current.forEach(w=>clearInterval(w)),g.current.forEach(w=>clearTimeout(w))},[]);function we(w,B,M,z,F=null){if(y.current.has(B))return;const U=setInterval(async()=>{var pe,de,Te,he;try{const Ve=await Zd(z,B);if(Ve.status==="completed"){clearInterval(y.current.get(B)),y.current.delete(B),await Promise.resolve((pe=k.current)==null?void 0:pe.call(k)),(de=T.current)==null||de.call(T,w);try{const ie=Ve.notes_json?JSON.parse(Ve.notes_json):null;if(ie!=null&&ie.ublock_skipped||ie!=null&&ie.cookie_ext_skipped){const yt=ie.ublock_skipped&&ie.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":ie.ublock_skipped?"Captured without ad-blocking. ARCHIVR_UBLOCK=true but ARCHIVR_UBLOCK_EXT is not set or the path is invalid.":"Captured without cookie-consent extension. ARCHIVR_COOKIE_EXT is not set or the path is invalid.";E.current(yt,M,"warning"),oe(F,"warning",M)}else F||E.current(null,M,"success"),oe(F,"archived")}catch{F||E.current(null,M,"success"),oe(F,"archived")}}else if(Ve.status==="failed"){clearInterval(y.current.get(B)),y.current.delete(B),(Te=T.current)==null||Te.call(T,w);const ie=Ve.error_text||"Capture failed.";E.current(ie,M),oe(F,"failed",M)}}catch(Ve){clearInterval(y.current.get(B)),y.current.delete(B),(he=T.current)==null||he.call(T,w);const ie=Ve.message||"Network error";E.current(ie,M),oe(F,"failed",M)}},500);y.current.set(B,U)}function oe(w,B,M=null){if(!w)return;const z=h.current.get(w);if(!z||(B==="archived"||B==="warning"?(z.archived++,B==="warning"&&(z.warnings++,M&&z.warningLocators.push(M))):(z.failed++,M&&z.failedLocators.push(M)),z.archived+z.failed0?`${F} archived (${U} with warnings)`:`${F} archived`;he=pe>0?`${yt}, ${pe} failed`:yt}const Ve=F===0?"error":pe>0||U>0?"warning":"success",ie=[];de.length>0&&ie.push(`Failed:
+`+i.stack}return{value:e,source:t,stack:l,digest:null}}function hi(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function na(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var mh=typeof WeakMap=="function"?WeakMap:Map;function _d(e,t,n){n=Xt(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){ws||(ws=!0,fa=r),na(e,t)},n}function Cd(e,t,n){n=Xt(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var l=t.value;n.payload=function(){return r(l)},n.callback=function(){na(e,t)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(n.callback=function(){na(e,t),typeof r!="function"&&(mn===null?mn=new Set([this]):mn.add(this));var a=t.stack;this.componentDidCatch(t.value,{componentStack:a!==null?a:""})}),n}function iu(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new mh;var l=new Set;r.set(t,l)}else l=r.get(t),l===void 0&&(l=new Set,r.set(t,l));l.has(n)||(l.add(n),e=Th.bind(null,e,t,n),t.then(e,e))}function au(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function ou(e,t,n,r,l){return e.mode&1?(e.flags|=65536,e.lanes=l,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=Xt(-1,1),t.tag=2,hn(n,t,1))),n.lanes|=1),e)}var gh=en.ReactCurrentOwner,nt=!1;function Ge(e,t,n,r){t.child=e===null?td(t,null,n,r):mr(t,e.child,n,r)}function uu(e,t,n,r,l){n=n.render;var i=t.ref;return ur(t,l),r=Xa(e,t,n,r,i,l),n=Ja(),e!==null&&!nt?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,Zt(e,t,l)):(we&&n&&Oa(t),t.flags|=1,Ge(e,t,r,l),t.child)}function cu(e,t,n,r,l){if(e===null){var i=n.type;return typeof i=="function"&&!io(i)&&i.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=i,Ed(e,t,i,r,l)):(e=Gl(n.type,null,r,t,t.mode,l),e.ref=t.ref,e.return=t,t.child=e)}if(i=e.child,!(e.lanes&l)){var a=i.memoizedProps;if(n=n.compare,n=n!==null?n:tl,n(a,r)&&e.ref===t.ref)return Zt(e,t,l)}return t.flags|=1,e=yn(i,r),e.ref=t.ref,e.return=t,t.child=e}function Ed(e,t,n,r,l){if(e!==null){var i=e.memoizedProps;if(tl(i,r)&&e.ref===t.ref)if(nt=!1,t.pendingProps=r=i,(e.lanes&l)!==0)e.flags&131072&&(nt=!0);else return t.lanes=e.lanes,Zt(e,t,l)}return ra(e,t,n,r,l)}function bd(e,t,n){var r=t.pendingProps,l=r.children,i=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},fe(lr,ot),ot|=n;else{if(!(n&1073741824))return e=i!==null?i.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,fe(lr,ot),ot|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:n,fe(lr,ot),ot|=r}else i!==null?(r=i.baseLanes|n,t.memoizedState=null):r=n,fe(lr,ot),ot|=r;return Ge(e,t,l,n),t.child}function Td(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function ra(e,t,n,r,l){var i=lt(n)?In:Je.current;return i=pr(t,i),ur(t,l),n=Xa(e,t,n,r,i,l),r=Ja(),e!==null&&!nt?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~l,Zt(e,t,l)):(we&&r&&Oa(t),t.flags|=1,Ge(e,t,n,l),t.child)}function du(e,t,n,r,l){if(lt(n)){var i=!0;cs(t)}else i=!1;if(ur(t,l),t.stateNode===null)Kl(e,t),Nd(t,n,r),ta(t,n,r,l),r=!0;else if(e===null){var a=t.stateNode,o=t.memoizedProps;a.props=o;var u=a.context,d=n.contextType;typeof d=="object"&&d!==null?d=St(d):(d=lt(n)?In:Je.current,d=pr(t,d));var y=n.getDerivedStateFromProps,g=typeof y=="function"||typeof a.getSnapshotBeforeUpdate=="function";g||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(o!==r||u!==d)&&su(t,a,r,d),ln=!1;var h=t.memoizedState;a.state=h,ms(t,r,a,l),u=t.memoizedState,o!==r||h!==u||rt.current||ln?(typeof y=="function"&&(ea(t,n,y,r),u=t.memoizedState),(o=ln||lu(t,n,o,r,h,u,d))?(g||typeof a.UNSAFE_componentWillMount!="function"&&typeof a.componentWillMount!="function"||(typeof a.componentWillMount=="function"&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount=="function"&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount=="function"&&(t.flags|=4194308)):(typeof a.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=u),a.props=r,a.state=u,a.context=d,r=o):(typeof a.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,rd(e,t),o=t.memoizedProps,d=t.type===t.elementType?o:Tt(t.type,o),a.props=d,g=t.pendingProps,h=a.context,u=n.contextType,typeof u=="object"&&u!==null?u=St(u):(u=lt(n)?In:Je.current,u=pr(t,u));var v=n.getDerivedStateFromProps;(y=typeof v=="function"||typeof a.getSnapshotBeforeUpdate=="function")||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(o!==g||h!==u)&&su(t,a,r,u),ln=!1,h=t.memoizedState,a.state=h,ms(t,r,a,l);var x=t.memoizedState;o!==g||h!==x||rt.current||ln?(typeof v=="function"&&(ea(t,n,v,r),x=t.memoizedState),(d=ln||lu(t,n,d,r,h,x,u)||!1)?(y||typeof a.UNSAFE_componentWillUpdate!="function"&&typeof a.componentWillUpdate!="function"||(typeof a.componentWillUpdate=="function"&&a.componentWillUpdate(r,x,u),typeof a.UNSAFE_componentWillUpdate=="function"&&a.UNSAFE_componentWillUpdate(r,x,u)),typeof a.componentDidUpdate=="function"&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof a.componentDidUpdate!="function"||o===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=x),a.props=r,a.state=x,a.context=u,r=d):(typeof a.componentDidUpdate!="function"||o===e.memoizedProps&&h===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&h===e.memoizedState||(t.flags|=1024),r=!1)}return la(e,t,n,r,i,l)}function la(e,t,n,r,l,i){Td(e,t);var a=(t.flags&128)!==0;if(!r&&!a)return l&&Jo(t,n,!1),Zt(e,t,i);r=t.stateNode,gh.current=t;var o=a&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&a?(t.child=mr(t,e.child,null,i),t.child=mr(t,null,o,i)):Ge(e,t,o,i),t.memoizedState=r.state,l&&Jo(t,n,!0),t.child}function Pd(e){var t=e.stateNode;t.pendingContext?Xo(e,t.pendingContext,t.pendingContext!==t.context):t.context&&Xo(e,t.context,!1),Va(e,t.containerInfo)}function fu(e,t,n,r,l){return hr(),Ma(l),t.flags|=256,Ge(e,t,n,r),t.child}var sa={dehydrated:null,treeContext:null,retryLane:0};function ia(e){return{baseLanes:e,cachePool:null,transitions:null}}function Ld(e,t,n){var r=t.pendingProps,l=je.current,i=!1,a=(t.flags&128)!==0,o;if((o=a)||(o=e!==null&&e.memoizedState===null?!1:(l&2)!==0),o?(i=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(l|=1),fe(je,l&1),e===null)return Yi(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(a=r.children,e=r.fallback,i?(r=t.mode,i=t.child,a={mode:"hidden",children:a},!(r&1)&&i!==null?(i.childLanes=0,i.pendingProps=a):i=Ds(a,r,0,null),e=zn(e,r,n,null),i.return=t,e.return=t,i.sibling=e,t.child=i,t.child.memoizedState=ia(n),t.memoizedState=sa,e):Za(t,a));if(l=e.memoizedState,l!==null&&(o=l.dehydrated,o!==null))return yh(e,t,a,r,o,l,n);if(i){i=r.fallback,a=t.mode,l=e.child,o=l.sibling;var u={mode:"hidden",children:r.children};return!(a&1)&&t.child!==l?(r=t.child,r.childLanes=0,r.pendingProps=u,t.deletions=null):(r=yn(l,u),r.subtreeFlags=l.subtreeFlags&14680064),o!==null?i=yn(o,i):(i=zn(i,a,n,null),i.flags|=2),i.return=t,r.return=t,r.sibling=i,t.child=r,r=i,i=t.child,a=e.child.memoizedState,a=a===null?ia(n):{baseLanes:a.baseLanes|n,cachePool:null,transitions:a.transitions},i.memoizedState=a,i.childLanes=e.childLanes&~n,t.memoizedState=sa,r}return i=e.child,e=i.sibling,r=yn(i,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function Za(e,t){return t=Ds({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function Il(e,t,n,r){return r!==null&&Ma(r),mr(t,e.child,null,n),e=Za(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function yh(e,t,n,r,l,i,a){if(n)return t.flags&256?(t.flags&=-257,r=hi(Error($(422))),Il(e,t,a,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(i=r.fallback,l=t.mode,r=Ds({mode:"visible",children:r.children},l,0,null),i=zn(i,l,a,null),i.flags|=2,r.return=t,i.return=t,r.sibling=i,t.child=r,t.mode&1&&mr(t,e.child,null,a),t.child.memoizedState=ia(a),t.memoizedState=sa,i);if(!(t.mode&1))return Il(e,t,a,null);if(l.data==="$!"){if(r=l.nextSibling&&l.nextSibling.dataset,r)var o=r.dgst;return r=o,i=Error($(419)),r=hi(i,r,void 0),Il(e,t,a,r)}if(o=(a&e.childLanes)!==0,nt||o){if(r=Fe,r!==null){switch(a&-a){case 4:l=2;break;case 16:l=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:l=32;break;case 536870912:l=268435456;break;default:l=0}l=l&(r.suspendedLanes|a)?0:l,l!==0&&l!==i.retryLane&&(i.retryLane=l,Yt(e,l),zt(r,e,l,-1))}return so(),r=hi(Error($(421))),Il(e,t,a,r)}return l.data==="$?"?(t.flags|=128,t.child=e.child,t=Ph.bind(null,e),l._reactRetry=t,null):(e=i.treeContext,ct=pn(l.nextSibling),dt=t,we=!0,Lt=null,e!==null&&(xt[wt++]=qt,xt[wt++]=Kt,xt[wt++]=$n,qt=e.id,Kt=e.overflow,$n=t),t=Za(t,r.children),t.flags|=4096,t)}function pu(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Zi(e.return,t,n)}function mi(e,t,n,r,l){var i=e.memoizedState;i===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:l}:(i.isBackwards=t,i.rendering=null,i.renderingStartTime=0,i.last=r,i.tail=n,i.tailMode=l)}function Rd(e,t,n){var r=t.pendingProps,l=r.revealOrder,i=r.tail;if(Ge(e,t,r.children,n),r=je.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&pu(e,n,t);else if(e.tag===19)pu(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(fe(je,r),!(t.mode&1))t.memoizedState=null;else switch(l){case"forwards":for(n=t.child,l=null;n!==null;)e=n.alternate,e!==null&&gs(e)===null&&(l=n),n=n.sibling;n=l,n===null?(l=t.child,t.child=null):(l=n.sibling,n.sibling=null),mi(t,!1,l,n,i);break;case"backwards":for(n=null,l=t.child,t.child=null;l!==null;){if(e=l.alternate,e!==null&&gs(e)===null){t.child=l;break}e=l.sibling,l.sibling=n,n=l,l=e}mi(t,!0,n,null,i);break;case"together":mi(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function Kl(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Zt(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),On|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error($(153));if(t.child!==null){for(e=t.child,n=yn(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=yn(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function vh(e,t,n){switch(t.tag){case 3:Pd(t),hr();break;case 5:ld(t);break;case 1:lt(t.type)&&cs(t);break;case 4:Va(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,l=t.memoizedProps.value;fe(ps,r._currentValue),r._currentValue=l;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(fe(je,je.current&1),t.flags|=128,null):n&t.child.childLanes?Ld(e,t,n):(fe(je,je.current&1),e=Zt(e,t,n),e!==null?e.sibling:null);fe(je,je.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return Rd(e,t,n);t.flags|=128}if(l=t.memoizedState,l!==null&&(l.rendering=null,l.tail=null,l.lastEffect=null),fe(je,je.current),r)break;return null;case 22:case 23:return t.lanes=0,bd(e,t,n)}return Zt(e,t,n)}var zd,aa,Id,$d;zd=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};aa=function(){};Id=function(e,t,n,r){var l=e.memoizedProps;if(l!==r){e=t.stateNode,Pn(Ht.current);var i=null;switch(n){case"input":l=Ti(e,l),r=Ti(e,r),i=[];break;case"select":l=Ne({},l,{value:void 0}),r=Ne({},r,{value:void 0}),i=[];break;case"textarea":l=Ri(e,l),r=Ri(e,r),i=[];break;default:typeof l.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=os)}Ii(n,r);var a;n=null;for(d in l)if(!r.hasOwnProperty(d)&&l.hasOwnProperty(d)&&l[d]!=null)if(d==="style"){var o=l[d];for(a in o)o.hasOwnProperty(a)&&(n||(n={}),n[a]="")}else d!=="dangerouslySetInnerHTML"&&d!=="children"&&d!=="suppressContentEditableWarning"&&d!=="suppressHydrationWarning"&&d!=="autoFocus"&&(Kr.hasOwnProperty(d)?i||(i=[]):(i=i||[]).push(d,null));for(d in r){var u=r[d];if(o=l!=null?l[d]:void 0,r.hasOwnProperty(d)&&u!==o&&(u!=null||o!=null))if(d==="style")if(o){for(a in o)!o.hasOwnProperty(a)||u&&u.hasOwnProperty(a)||(n||(n={}),n[a]="");for(a in u)u.hasOwnProperty(a)&&o[a]!==u[a]&&(n||(n={}),n[a]=u[a])}else n||(i||(i=[]),i.push(d,n)),n=u;else d==="dangerouslySetInnerHTML"?(u=u?u.__html:void 0,o=o?o.__html:void 0,u!=null&&o!==u&&(i=i||[]).push(d,u)):d==="children"?typeof u!="string"&&typeof u!="number"||(i=i||[]).push(d,""+u):d!=="suppressContentEditableWarning"&&d!=="suppressHydrationWarning"&&(Kr.hasOwnProperty(d)?(u!=null&&d==="onScroll"&&me("scroll",e),i||o===u||(i=[])):(i=i||[]).push(d,u))}n&&(i=i||[]).push("style",n);var d=i;(t.updateQueue=d)&&(t.flags|=4)}};$d=function(e,t,n,r){n!==r&&(t.flags|=4)};function Pr(e,t){if(!we)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Ke(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags&14680064,r|=l.flags&14680064,l.return=e,l=l.sibling;else for(l=e.child;l!==null;)n|=l.lanes|l.childLanes,r|=l.subtreeFlags,r|=l.flags,l.return=e,l=l.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function xh(e,t,n){var r=t.pendingProps;switch(Aa(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Ke(t),null;case 1:return lt(t.type)&&us(),Ke(t),null;case 3:return r=t.stateNode,gr(),ge(rt),ge(Je),qa(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Rl(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Lt!==null&&(ma(Lt),Lt=null))),aa(e,t),Ke(t),null;case 5:Qa(t);var l=Pn(il.current);if(n=t.type,e!==null&&t.stateNode!=null)Id(e,t,n,r,l),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error($(166));return Ke(t),null}if(e=Pn(Ht.current),Rl(t)){r=t.stateNode,n=t.type;var i=t.memoizedProps;switch(r[Bt]=t,r[ll]=i,e=(t.mode&1)!==0,n){case"dialog":me("cancel",r),me("close",r);break;case"iframe":case"object":case"embed":me("load",r);break;case"video":case"audio":for(l=0;l<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=a.createElement(n,{is:r.is}):(e=a.createElement(n),n==="select"&&(a=e,r.multiple?a.multiple=!0:r.size&&(a.size=r.size))):e=a.createElementNS(e,n),e[Bt]=t,e[ll]=r,zd(e,t,!1,!1),t.stateNode=e;e:{switch(a=$i(n,r),n){case"dialog":me("cancel",e),me("close",e),l=r;break;case"iframe":case"object":case"embed":me("load",e),l=r;break;case"video":case"audio":for(l=0;lvr&&(t.flags|=128,r=!0,Pr(i,!1),t.lanes=4194304)}else{if(!r)if(e=gs(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Pr(i,!0),i.tail===null&&i.tailMode==="hidden"&&!a.alternate&&!we)return Ke(t),null}else 2*be()-i.renderingStartTime>vr&&n!==1073741824&&(t.flags|=128,r=!0,Pr(i,!1),t.lanes=4194304);i.isBackwards?(a.sibling=t.child,t.child=a):(n=i.last,n!==null?n.sibling=a:t.child=a,i.last=a)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=be(),t.sibling=null,n=je.current,fe(je,r?n&1|2:n&1),t):(Ke(t),null);case 22:case 23:return lo(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?ot&1073741824&&(Ke(t),t.subtreeFlags&6&&(t.flags|=8192)):Ke(t),null;case 24:return null;case 25:return null}throw Error($(156,t.tag))}function wh(e,t){switch(Aa(t),t.tag){case 1:return lt(t.type)&&us(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return gr(),ge(rt),ge(Je),qa(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Qa(t),null;case 13:if(ge(je),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error($(340));hr()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ge(je),null;case 4:return gr(),null;case 10:return Ua(t.type._context),null;case 22:case 23:return lo(),null;case 24:return null;default:return null}}var $l=!1,Xe=!1,kh=typeof WeakSet=="function"?WeakSet:Set,W=null;function rr(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Ce(e,t,r)}else n.current=null}function oa(e,t,n){try{n()}catch(r){Ce(e,t,r)}}var hu=!1;function jh(e,t){if(Vi=ss,e=Fc(),Da(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var l=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{n.nodeType,i.nodeType}catch{n=null;break e}var a=0,o=-1,u=-1,d=0,y=0,g=e,h=null;t:for(;;){for(var v;g!==n||l!==0&&g.nodeType!==3||(o=a+l),g!==i||r!==0&&g.nodeType!==3||(u=a+r),g.nodeType===3&&(a+=g.nodeValue.length),(v=g.firstChild)!==null;)h=g,g=v;for(;;){if(g===e)break t;if(h===n&&++d===l&&(o=a),h===i&&++y===r&&(u=a),(v=g.nextSibling)!==null)break;g=h,h=g.parentNode}g=v}n=o===-1||u===-1?null:{start:o,end:u}}else n=null}n=n||{start:0,end:0}}else n=null;for(Qi={focusedElem:e,selectionRange:n},ss=!1,W=t;W!==null;)if(t=W,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,W=e;else for(;W!==null;){t=W;try{var x=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(x!==null){var S=x.memoizedProps,N=x.memoizedState,p=t.stateNode,f=p.getSnapshotBeforeUpdate(t.elementType===t.type?S:Tt(t.type,S),N);p.__reactInternalSnapshotBeforeUpdate=f}break;case 3:var m=t.stateNode.containerInfo;m.nodeType===1?m.textContent="":m.nodeType===9&&m.documentElement&&m.removeChild(m.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error($(163))}}catch(k){Ce(t,t.return,k)}if(e=t.sibling,e!==null){e.return=t.return,W=e;break}W=t.return}return x=hu,hu=!1,x}function Vr(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var l=r=r.next;do{if((l.tag&e)===e){var i=l.destroy;l.destroy=void 0,i!==void 0&&oa(t,n,i)}l=l.next}while(l!==r)}}function Is(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function ua(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Dd(e){var t=e.alternate;t!==null&&(e.alternate=null,Dd(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Bt],delete t[ll],delete t[Xi],delete t[lh],delete t[sh])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Od(e){return e.tag===5||e.tag===3||e.tag===4}function mu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Od(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function ca(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=os));else if(r!==4&&(e=e.child,e!==null))for(ca(e,t,n),e=e.sibling;e!==null;)ca(e,t,n),e=e.sibling}function da(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(da(e,t,n),e=e.sibling;e!==null;)da(e,t,n),e=e.sibling}var Ue=null,Pt=!1;function nn(e,t,n){for(n=n.child;n!==null;)Ad(e,t,n),n=n.sibling}function Ad(e,t,n){if(Ut&&typeof Ut.onCommitFiberUnmount=="function")try{Ut.onCommitFiberUnmount(Cs,n)}catch{}switch(n.tag){case 5:Xe||rr(n,t);case 6:var r=Ue,l=Pt;Ue=null,nn(e,t,n),Ue=r,Pt=l,Ue!==null&&(Pt?(e=Ue,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Ue.removeChild(n.stateNode));break;case 18:Ue!==null&&(Pt?(e=Ue,n=n.stateNode,e.nodeType===8?oi(e.parentNode,n):e.nodeType===1&&oi(e,n),Zr(e)):oi(Ue,n.stateNode));break;case 4:r=Ue,l=Pt,Ue=n.stateNode.containerInfo,Pt=!0,nn(e,t,n),Ue=r,Pt=l;break;case 0:case 11:case 14:case 15:if(!Xe&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){l=r=r.next;do{var i=l,a=i.destroy;i=i.tag,a!==void 0&&(i&2||i&4)&&oa(n,t,a),l=l.next}while(l!==r)}nn(e,t,n);break;case 1:if(!Xe&&(rr(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(o){Ce(n,t,o)}nn(e,t,n);break;case 21:nn(e,t,n);break;case 22:n.mode&1?(Xe=(r=Xe)||n.memoizedState!==null,nn(e,t,n),Xe=r):nn(e,t,n);break;default:nn(e,t,n)}}function gu(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new kh),t.forEach(function(r){var l=Lh.bind(null,e,r);n.has(r)||(n.add(r),r.then(l,l))})}}function bt(e,t){var n=t.deletions;if(n!==null)for(var r=0;rl&&(l=a),r&=~i}if(r=l,r=be()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Nh(r/1960))-r,10e?16:e,un===null)var r=!1;else{if(e=un,un=null,ks=0,ae&6)throw Error($(331));var l=ae;for(ae|=4,W=e.current;W!==null;){var i=W,a=i.child;if(W.flags&16){var o=i.deletions;if(o!==null){for(var u=0;ube()-no?Rn(e,0):to|=n),st(e,t)}function Qd(e,t){t===0&&(e.mode&1?(t=Cl,Cl<<=1,!(Cl&130023424)&&(Cl=4194304)):t=1);var n=Ye();e=Yt(e,t),e!==null&&(hl(e,t,n),st(e,n))}function Ph(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Qd(e,n)}function Lh(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,l=e.memoizedState;l!==null&&(n=l.retryLane);break;case 19:r=e.stateNode;break;default:throw Error($(314))}r!==null&&r.delete(t),Qd(e,n)}var qd;qd=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||rt.current)nt=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return nt=!1,vh(e,t,n);nt=!!(e.flags&131072)}else nt=!1,we&&t.flags&1048576&&Gc(t,fs,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Kl(e,t),e=t.pendingProps;var l=pr(t,Je.current);ur(t,n),l=Xa(null,t,r,e,l,n);var i=Ja();return t.flags|=1,typeof l=="object"&&l!==null&&typeof l.render=="function"&&l.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,lt(r)?(i=!0,cs(t)):i=!1,t.memoizedState=l.state!==null&&l.state!==void 0?l.state:null,Wa(t),l.updater=zs,t.stateNode=l,l._reactInternals=t,ta(t,r,e,n),t=la(null,t,r,!0,i,n)):(t.tag=0,we&&i&&Oa(t),Ge(null,t,l,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Kl(e,t),e=t.pendingProps,l=r._init,r=l(r._payload),t.type=r,l=t.tag=zh(r),e=Tt(r,e),l){case 0:t=ra(null,t,r,e,n);break e;case 1:t=du(null,t,r,e,n);break e;case 11:t=uu(null,t,r,e,n);break e;case 14:t=cu(null,t,r,Tt(r.type,e),n);break e}throw Error($(306,r,""))}return t;case 0:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),ra(e,t,r,l,n);case 1:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),du(e,t,r,l,n);case 3:e:{if(Pd(t),e===null)throw Error($(387));r=t.pendingProps,i=t.memoizedState,l=i.element,rd(e,t),ms(t,r,null,n);var a=t.memoizedState;if(r=a.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){l=yr(Error($(423)),t),t=fu(e,t,r,n,l);break e}else if(r!==l){l=yr(Error($(424)),t),t=fu(e,t,r,n,l);break e}else for(ct=pn(t.stateNode.containerInfo.firstChild),dt=t,we=!0,Lt=null,n=td(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(hr(),r===l){t=Zt(e,t,n);break e}Ge(e,t,r,n)}t=t.child}return t;case 5:return ld(t),e===null&&Yi(t),r=t.type,l=t.pendingProps,i=e!==null?e.memoizedProps:null,a=l.children,qi(r,l)?a=null:i!==null&&qi(r,i)&&(t.flags|=32),Td(e,t),Ge(e,t,a,n),t.child;case 6:return e===null&&Yi(t),null;case 13:return Ld(e,t,n);case 4:return Va(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=mr(t,null,r,n):Ge(e,t,r,n),t.child;case 11:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),uu(e,t,r,l,n);case 7:return Ge(e,t,t.pendingProps,n),t.child;case 8:return Ge(e,t,t.pendingProps.children,n),t.child;case 12:return Ge(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,l=t.pendingProps,i=t.memoizedProps,a=l.value,fe(ps,r._currentValue),r._currentValue=a,i!==null)if(It(i.value,a)){if(i.children===l.children&&!rt.current){t=Zt(e,t,n);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var o=i.dependencies;if(o!==null){a=i.child;for(var u=o.firstContext;u!==null;){if(u.context===r){if(i.tag===1){u=Xt(-1,n&-n),u.tag=2;var d=i.updateQueue;if(d!==null){d=d.shared;var y=d.pending;y===null?u.next=u:(u.next=y.next,y.next=u),d.pending=u}}i.lanes|=n,u=i.alternate,u!==null&&(u.lanes|=n),Zi(i.return,n,t),o.lanes|=n;break}u=u.next}}else if(i.tag===10)a=i.type===t.type?null:i.child;else if(i.tag===18){if(a=i.return,a===null)throw Error($(341));a.lanes|=n,o=a.alternate,o!==null&&(o.lanes|=n),Zi(a,n,t),a=i.sibling}else a=i.child;if(a!==null)a.return=i;else for(a=i;a!==null;){if(a===t){a=null;break}if(i=a.sibling,i!==null){i.return=a.return,a=i;break}a=a.return}i=a}Ge(e,t,l.children,n),t=t.child}return t;case 9:return l=t.type,r=t.pendingProps.children,ur(t,n),l=St(l),r=r(l),t.flags|=1,Ge(e,t,r,n),t.child;case 14:return r=t.type,l=Tt(r,t.pendingProps),l=Tt(r.type,l),cu(e,t,r,l,n);case 15:return Ed(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,l=t.pendingProps,l=t.elementType===r?l:Tt(r,l),Kl(e,t),t.tag=1,lt(r)?(e=!0,cs(t)):e=!1,ur(t,n),Nd(t,r,l),ta(t,r,l,n),la(null,t,r,!0,e,n);case 19:return Rd(e,t,n);case 22:return bd(e,t,n)}throw Error($(156,t.tag))};function Kd(e,t){return kc(e,t)}function Rh(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function kt(e,t,n,r){return new Rh(e,t,n,r)}function io(e){return e=e.prototype,!(!e||!e.isReactComponent)}function zh(e){if(typeof e=="function")return io(e)?1:0;if(e!=null){if(e=e.$$typeof,e===_a)return 11;if(e===Ca)return 14}return 2}function yn(e,t){var n=e.alternate;return n===null?(n=kt(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Gl(e,t,n,r,l,i){var a=2;if(r=e,typeof e=="function")io(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Kn:return zn(n.children,l,i,t);case Na:a=8,l|=8;break;case _i:return e=kt(12,n,t,l|2),e.elementType=_i,e.lanes=i,e;case Ci:return e=kt(13,n,t,l),e.elementType=Ci,e.lanes=i,e;case Ei:return e=kt(19,n,t,l),e.elementType=Ei,e.lanes=i,e;case lc:return Ds(n,l,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case nc:a=10;break e;case rc:a=9;break e;case _a:a=11;break e;case Ca:a=14;break e;case rn:a=16,r=null;break e}throw Error($(130,e==null?e:typeof e,""))}return t=kt(a,n,t,l),t.elementType=e,t.type=r,t.lanes=i,t}function zn(e,t,n,r){return e=kt(7,e,r,t),e.lanes=n,e}function Ds(e,t,n,r){return e=kt(22,e,r,t),e.elementType=lc,e.lanes=n,e.stateNode={isHidden:!1},e}function gi(e,t,n){return e=kt(6,e,null,t),e.lanes=n,e}function yi(e,t,n){return t=kt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Ih(e,t,n,r,l){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Gs(0),this.expirationTimes=Gs(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Gs(0),this.identifierPrefix=r,this.onRecoverableError=l,this.mutableSourceEagerHydrationData=null}function ao(e,t,n,r,l,i,a,o,u){return e=new Ih(e,t,n,o,u),t===1?(t=1,i===!0&&(t|=8)):t=0,i=kt(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Wa(i),e}function $h(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Yd)}catch(e){console.error(e)}}Yd(),Yu.exports=pt;var Fh=Yu.exports,Zd,Nu=Fh;Zd=Nu.createRoot,Nu.hydrateRoot;async function Te(e){const t=await fetch(e);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);return t.json()}async function _u(){return Te("/api/archives")}async function Cu(e,t=null){const n=t?`/api/archives/${e}/entries?collection=${encodeURIComponent(t)}`:`/api/archives/${e}/entries`;return Te(n)}async function Bh(e,t,n,r=null){const l=new URLSearchParams;return t&&l.set("q",t),n&&l.set("tag",n),r&&l.set("collection",r),Te(`/api/archives/${e}/entries/search?${l}`)}async function Or(e,t){return Te(`/api/archives/${e}/entries/${t}`)}async function Uh(e,t){return Te(`/api/archives/${e}/entries/${t}/summary`)}async function Hh(e,t,{provider:n,force:r=!1,includeImages:l=!1}={}){const i=await fetch(`/api/archives/${e}/entries/${t}/summary`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n,force:r,include_images:l})});if(!i.ok){const a=await i.text();let o=a.trim();try{o=JSON.parse(a).error||o}catch{}throw new Error(o||`Summary request failed (${i.status})`)}return i.json()}async function Wh(e,t){return Te(`/api/archives/${e}/entries/${t}/children`)}function Vh(e,t,n){return Promise.all(n.map(r=>Te(`/api/archives/${e}/entries/${t}/artifacts/${r}`)))}async function Qh(e){if(!e||e.length===0)return{};const t=await fetch("/api/util/resolve-tco",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?t.json():{}}async function qh(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:n??null})});if(!r.ok)throw new Error(await r.text())}async function Al(e,t){return Te(`/api/archives/${e}/entries/${t}/tags`)}async function Eu(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag_path:n})});if(!r.ok)throw new Error(`Failed to add tag (${r.status})`)}async function Kh(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/tags/${n}`,{method:"DELETE"});if(!r.ok)throw new Error(`Remove failed (${r.status})`)}async function bu(e,t){const n=await fetch(`/api/archives/${e}/entries/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(`Delete failed (${n.status})`)}async function Xh(e,t,n){const r=await fetch(`/api/archives/${e}/tags/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n})});if(!r.ok)throw new Error(await r.text());return r.json()}async function Jh(e,t){const n=await fetch(`/api/archives/${e}/tags/${t}`,{method:"DELETE"});if(!n.ok)throw new Error(await n.text())}async function Gh(e,t){const n=await fetch(`/api/archives/${e}/tags`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!n.ok)throw new Error(await n.text());return n.json()}async function Yh(e,t,n){const r=await fetch(`/api/archives/${e}/tags/${t}/move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({parent_uid:n??null})});if(!r.ok)throw new Error(await r.text());return r.json()}async function vi(e){return Te(`/api/archives/${e}/runs`)}async function Ml(e){return Te(`/api/archives/${e}/tags`)}async function Zh(e,t,n=null,r=null){const l={locator:t};n&&n!=="best"&&(l.quality=n),r&&(typeof r.ublock_enabled=="boolean"&&(l.ublock_enabled=r.ublock_enabled),typeof r.reader_mode=="boolean"&&(l.reader_mode=r.reader_mode),typeof r.cookie_ext_enabled=="boolean"&&(l.cookie_ext_enabled=r.cookie_ext_enabled),typeof r.modal_closer_enabled=="boolean"&&(l.modal_closer_enabled=r.modal_closer_enabled),typeof r.via_freedium=="boolean"&&(l.via_freedium=r.via_freedium),r.per_item_quality&&typeof r.per_item_quality=="object"&&Object.keys(r.per_item_quality).length>0&&(l.per_item_quality=r.per_item_quality),r.sync===!0&&(l.sync=!0));const i=await fetch(`/api/archives/${e}/captures`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!i.ok){const a=await i.json().catch(()=>({})),o=new Error(a.error||`HTTP ${i.status}`);throw o.status=i.status,o}return i.json()}async function em(e,{title:t,body:n,mime:r="text/markdown"}){const l={title:t,body:n};r&&r!=="text/markdown"&&(l.mime=r);const i=await fetch(`/api/archives/${e}/captures/text`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!i.ok){const a=await i.json().catch(()=>({})),o=new Error(a.error||`HTTP ${i.status}`);throw o.status=i.status,o}return i.json()}async function tm(e,t){return Te(`/api/archives/${e}/captures/probe?locator=${encodeURIComponent(t)}`)}async function nm(e,t){const n=await fetch(`/api/archives/${e}/captures/probe-playlist`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({locator:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function ef(e,t){return Te(`/api/archives/${e}/capture_jobs/${t}`)}async function rm(){return(await(await fetch("/api/auth/setup")).json()).setup_required===!0}async function lm(e,t){const n=await fetch("/api/auth/setup",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Setup failed");return n.json()}async function sm(e,t){const n=await fetch("/api/auth/login",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({username:e,password:t})});if(!n.ok)throw new Error((await n.json()).error||"Login failed");return n.json()}async function im(){await fetch("/api/auth/logout",{method:"POST"})}async function am(){const e=await fetch("/api/auth/me");return e.status===401?null:e.json()}async function om(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({display_name:e})});if(!t.ok)throw new Error(await t.text())}async function um(e){const t=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function cm(e,t){const n=await fetch("/api/auth/me",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({current_password:e,new_password:t})});if(!n.ok){let r=await n.text();try{r=JSON.parse(r).error??r}catch{}throw new Error(r)}}async function dm(){return Te("/api/auth/tokens")}async function fm(e){const t=await fetch("/api/auth/tokens",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})});if(!t.ok)throw new Error(await t.text());return t.json()}async function pm(e){const t=await fetch(`/api/auth/tokens/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(await t.text())}async function fo(){return Te("/api/admin/instance-settings")}async function Yl(e){const t=await fetch("/api/admin/instance-settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(await t.text())}async function hm(){return Te("/api/admin/users")}async function mm(e,t,n){const r=await fetch("/api/admin/users",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:t,email:n||void 0})});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error||`HTTP ${r.status}`)}return r.json()}async function gm(e,t){const n=await fetch(`/api/admin/users/${e}/status`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function ym(){return Te("/api/admin/roles")}async function vm(e,t){const n=await fetch("/api/admin/roles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,name:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`HTTP ${n.status}`)}return n.json()}async function po(e){return Te(`/api/archives/${e}/collections`)}async function xm(e,t,n,r=2,l=!0){const i=await fetch(`/api/archives/${e}/collections`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:t,slug:n,default_visibility_bits:r,requires_auth:l})});if(!i.ok){const a=await i.json().catch(()=>({error:i.statusText}));throw new Error(a.error||i.statusText)}return i.json()}async function wm(e,t){return Te(`/api/archives/${e}/collections/${t}`)}async function ga(e,t,n,r=2){const l=await fetch(`/api/archives/${e}/collections/${t}/entries`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({entry_uid:n,visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}}async function km(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"DELETE"});if(!r.ok){const l=await r.json().catch(()=>({error:r.statusText}));throw new Error(l.error||r.statusText)}}async function jm(e,t,n,r){const l=await fetch(`/api/archives/${e}/collections/${t}/entries/${n}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({visibility_bits:r})});if(!l.ok){const i=await l.json().catch(()=>({error:l.statusText}));throw new Error(i.error||l.statusText)}}async function Tu(e,t){return Te(`/api/archives/${e}/entries/${t}/collections`)}async function xi(e,t,n){const r=await fetch(`/api/archives/${e}/collections/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.error??r.statusText)}}async function Sm(e,t){const n=await fetch(`/api/archives/${e}/collections/${t}`,{method:"DELETE"});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error??n.statusText)}}async function Nm(e){return Te(`/api/archives/${e}/blob-cleanup`)}async function _m(e){const t=await fetch(`/api/archives/${e}/blob-cleanup`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error??t.statusText)}return t.json()}async function Cm(e,t){const n=await fetch(`/api/archives/${e}/entries/${t}/rearchive`,{method:"POST"});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.message||`rearchive failed: ${n.status}`)}return n.json()}async function Em(e,t,n){const r=await fetch(`/api/archives/${e}/entries/${t}/artifacts/${n}/media-token`,{method:"POST"});if(!r.ok)throw new Error(`media-token ${r.status}`);return r.json()}async function bm(){return Te("/api/admin/cookie-rules")}async function Tm(e,t,n){const r=await fetch("/api/admin/cookie-rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url_pattern:e||null,pattern_kind:t,cookies_json:n})});if(!r.ok){const l=await r.json().catch(()=>({}));throw new Error(l.message||`HTTP ${r.status}`)}return r.json()}async function Pm(e,t){const n=await fetch(`/api/admin/cookie-rules/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.message||`HTTP ${n.status}`)}}async function Lm(e){const t=await fetch(`/api/admin/cookie-rules/${e}`,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.message||`HTTP ${t.status}`)}}function Rm(e,t,n){let r;return{promise:new Promise((i,a)=>{const o=new FormData;o.append("file",t),r=new XMLHttpRequest,r.open("POST",`/api/archives/${e}/uploads`),r.upload.addEventListener("progress",u=>{u.lengthComputable&&n&&n(Math.round(u.loaded/u.total*100))}),r.addEventListener("load",()=>{if(r.status>=200&&r.status<300)try{i(JSON.parse(r.responseText))}catch{a(new Error("Invalid server response"))}else{let u=`Upload failed (${r.status})`;try{u=JSON.parse(r.responseText).message||u}catch{}a(new Error(u))}}),r.addEventListener("error",()=>a(new Error("Network error during upload"))),r.addEventListener("abort",()=>a(new Error("Upload cancelled"))),r.send(o)}),abort:()=>r==null?void 0:r.abort()}}async function wi(e,t){try{await fetch(`/api/archives/${e}/uploads`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({locator:t})})}catch{}}const zm=window.fetch;window.fetch=async(...e)=>{var n;const t=await zm(...e);return t.status===401&&((typeof e[0]=="string"?e[0]:((n=e[0])==null?void 0:n.url)??"").includes("/api/auth/")||window.dispatchEvent(new CustomEvent("auth:expired"))),t};function Im({onLogin:e}){const[t,n]=c.useState(""),[r,l]=c.useState(""),[i,a]=c.useState(null),[o,u]=c.useState(!1);async function d(y){y.preventDefault(),a(null),u(!0);try{const g=await sm(t,r);e(g)}catch(g){a(g.message)}finally{u(!1)}}return s.jsx("div",{className:"login-page",children:s.jsxs("div",{className:"login-card",children:[s.jsx("h1",{className:"login-brand",children:"Archivr"}),s.jsx("p",{className:"login-tagline",children:"Sign in to your archive"}),s.jsxs("form",{onSubmit:d,children:[s.jsxs("div",{className:"login-field",children:[s.jsx("label",{className:"login-label",htmlFor:"login-username",children:"Username"}),s.jsx("input",{className:"login-input",id:"login-username",type:"text",value:t,onChange:y=>n(y.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),s.jsxs("div",{className:"login-field",children:[s.jsx("label",{className:"login-label",htmlFor:"login-password",children:"Password"}),s.jsx("input",{className:"login-input",id:"login-password",type:"password",value:r,onChange:y=>l(y.target.value),required:!0,autoComplete:"current-password"})]}),i&&s.jsx("p",{className:"login-error",children:i}),s.jsx("button",{className:"login-submit",type:"submit",disabled:o,children:o?"Signing in…":"Sign in"})]})]})})}function $m({onComplete:e}){const[t,n]=c.useState(""),[r,l]=c.useState(""),[i,a]=c.useState(""),[o,u]=c.useState(null),[d,y]=c.useState(!1);async function g(h){if(h.preventDefault(),r!==i){u("Passwords do not match");return}if(r.length<8){u("Password must be at least 8 characters");return}u(null),y(!0);try{await lm(t,r),e()}catch(v){u(v.message)}finally{y(!1)}}return s.jsx("div",{className:"setup-page",children:s.jsxs("div",{className:"setup-card",children:[s.jsx("h1",{className:"setup-brand",children:"Archivr"}),s.jsx("p",{className:"setup-tagline",children:"Create your owner account to get started."}),s.jsxs("form",{onSubmit:g,children:[s.jsxs("div",{className:"setup-field",children:[s.jsx("label",{className:"setup-label",htmlFor:"setup-username",children:"Username"}),s.jsx("input",{className:"setup-input",id:"setup-username",type:"text",value:t,onChange:h=>n(h.target.value),autoFocus:!0,required:!0,autoComplete:"username"})]}),s.jsxs("div",{className:"setup-field",children:[s.jsx("label",{className:"setup-label",htmlFor:"setup-password",children:"Password"}),s.jsx("input",{className:"setup-input",id:"setup-password",type:"password",value:r,onChange:h=>l(h.target.value),required:!0,autoComplete:"new-password"})]}),s.jsxs("div",{className:"setup-field",children:[s.jsx("label",{className:"setup-label",htmlFor:"setup-confirm",children:"Confirm password"}),s.jsx("input",{className:"setup-input",id:"setup-confirm",type:"password",value:i,onChange:h=>a(h.target.value),required:!0,autoComplete:"new-password"})]}),o&&s.jsx("p",{className:"setup-error",children:o}),s.jsx("button",{className:"setup-submit",type:"submit",disabled:d,children:d?"Creating account…":"Create account"})]})]})})}function Dm({archives:e,archiveId:t,onArchiveChange:n,view:r,onViewChange:l,onCaptureClick:i,collections:a,selectedCollectionUid:o,onCollectionChange:u,isPublicSession:d,onSignInClick:y}){const{currentUser:g,setCurrentUser:h}=c.useContext(Us)??{},[v,x]=c.useState(!1);async function S(){x(!0),await im(),h(null),window.location.reload()}const N=a.find(m=>m.slug==="_default_"),p=!d||!!N&&!N.requires_auth,f=a.filter(m=>m.slug!=="_default_").filter(m=>!d||!m.requires_auth);return s.jsxs("header",{className:"topbar",children:[s.jsx("div",{className:"brand",children:"Archivr"}),s.jsxs("div",{className:"switchers",children:[!d&&s.jsx("div",{className:"switcher",children:s.jsx("select",{"aria-label":"Select archive",value:t??"",onChange:m=>n(m.target.value),children:e.map(m=>s.jsx("option",{value:m.id,children:m.label},m.id))})}),f.length>0&&s.jsx("div",{className:"switcher",children:s.jsxs("select",{"aria-label":"Select collection",value:o??"",onChange:m=>u(m.target.value||null),children:[p&&s.jsx("option",{value:"",children:"All entries"}),f.map(m=>s.jsx("option",{value:m.collection_uid,children:m.name},m.collection_uid))]})})]}),d?s.jsxs(s.Fragment,{children:[s.jsx("span",{style:{flex:1}}),s.jsx("button",{className:"logout-btn",onClick:y,children:"Sign in"})]}):s.jsxs(s.Fragment,{children:[s.jsx("nav",{className:"nav","aria-label":"Primary",children:["archive","tags","collections","runs","admin","settings"].map(m=>s.jsx("button",{className:`nav-link${r===m?" is-active":""}`,onClick:()=>l(m),children:m.charAt(0).toUpperCase()+m.slice(1)},m))}),s.jsx("button",{className:"capture-button",onClick:i,children:"Capture"}),g&&s.jsxs("div",{className:"user-menu",children:[s.jsx("span",{className:"user-name",children:g.display_name||g.username}),s.jsx("button",{className:"logout-btn",onClick:S,disabled:v,children:v?"Logging out…":"Log out"})]})]})]})}let dl=1;function tf(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return!!(l.startsWith("video/")||l.startsWith("short/")||l.startsWith("shorts/")||/^[a-z0-9_-]{11}$/i.test(l))}if(n.startsWith("ytm:"))return!n.slice(4).startsWith("playlist/");for(const r of["x:","twitter:","tweet:"])if(n.startsWith(r))return n.slice(r.length).startsWith("media:");if(n.startsWith("spotify:"))return!1;if(n.startsWith("instagram:")||n.startsWith("facebook:")||n.startsWith("tiktok:")||n.startsWith("reddit:")||n.startsWith("snapchat:"))return!0;if(n.startsWith("http://")||n.startsWith("https://")){if(/^https?:\/\/music\.youtube\.com\/watch/.test(n)||/^https?:\/\/(?:www\.)?(?:youtu\.be\/[0-9A-Za-z_-]+|youtube\.com\/watch\?v=[0-9A-Za-z_-]+|youtube\.com\/shorts\/[0-9A-Za-z_-]+)/.test(t)||n.startsWith("https://x.com/")||n.startsWith("http://x.com/")||/^https?:\/\/(?:www\.)?instagram\.com\//.test(n)||/^https?:\/\/(?:www\.)?facebook\.com\//.test(n)||n.startsWith("https://fb.watch/")||n.startsWith("http://fb.watch/")||/^https?:\/\/(?:www\.)?tiktok\.com\//.test(n)||/^https?:\/\/(?:www\.)?reddit\.com\//.test(n)||n.startsWith("https://redd.it/")||n.startsWith("http://redd.it/")||/^https?:\/\/(?:www\.)?snapchat\.com\//.test(n))return!0;if(n.startsWith("https://open.spotify.com/")||n.startsWith("http://open.spotify.com/"))return!1}return!1}function Ln(e){const t=e.trim(),n=t.toLowerCase();for(const r of["yt:","youtube:"])if(n.startsWith(r)){const l=n.slice(r.length);return l.startsWith("playlist/")||l.startsWith("@")||l.startsWith("channel/")||l.startsWith("c/")||l.startsWith("user/")}if(n.startsWith("ytm:"))return n.slice(4).startsWith("playlist/");if(n.startsWith("spotify:")){const r=n.slice(8);return r.startsWith("album:")||r.startsWith("playlist:")}if(n.startsWith("http://")||n.startsWith("https://"))try{const r=new URL(t),l=r.hostname;if((l==="youtube.com"||l==="www.youtube.com")&&(r.pathname==="/playlist"&&r.searchParams.has("list")||r.pathname.startsWith("/@")||r.pathname.startsWith("/channel/")||r.pathname.startsWith("/c/")||r.pathname.startsWith("/user/"))||l==="music.youtube.com"&&r.pathname==="/playlist"&&r.searchParams.has("list")||l==="open.spotify.com"&&(r.pathname.startsWith("/album/")||r.pathname.startsWith("/playlist/")))return!0}catch{}return!1}function Qn(e=""){return{id:dl++,locator:e,quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,status:"idle",error:null,jobUid:null,archiveId:null,playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1,syncEnabled:!1}}function Om(e){return{id:dl++,kind:"file",filename:e,uploadProgress:0,uploadStatus:"uploading",uploadLocator:null,uploadError:null,locator:"",quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1,syncEnabled:!1,error:null,status:"idle"}}function Am(){return{id:dl++,kind:"text",title:"",body:"",mime:"text/markdown",locator:"",quality:"best",probeState:"idle",probeQualities:null,probeHasAudio:!1,playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1,syncEnabled:!1,error:null,status:"idle"}}function Mm(e,t){return e==="best"?t.map(n=>({...n,quality:"best"})):e==="audio"?t.map(n=>n.has_audio?{...n,quality:"audio"}:n.quality!==null?n:{...n,quality:null}):t.map(n=>n.qualities.includes(e)?{...n,quality:e}:n.quality!==null?n:{...n,quality:null})}function Pu(e){return Array.isArray(e.playlistItems)&&e.playlistItems.some(t=>t.quality===null)}function Fm({open:e,archiveId:t,onClose:n,onCaptured:r,onToast:l,onJobStarted:i,onJobSettled:a,activeJobs:o=[]}){const u=c.useRef(null),d=c.useRef(!0),y=c.useRef(new Map),g=c.useRef(new Map),h=c.useRef(new Map),v=c.useRef(t);c.useEffect(()=>{v.current=t},[t]);const x=c.useRef(null),[S,N]=c.useState(!1),p=c.useRef([]),f=c.useRef(!1),m=c.useRef(new Map),k=c.useRef(r),E=c.useRef(l);c.useEffect(()=>{k.current=r},[r]),c.useEffect(()=>{E.current=l},[l]);const b=c.useRef(i),T=c.useRef(a);c.useEffect(()=>{b.current=i},[i]),c.useEffect(()=>{T.current=a},[a]);const[j,P]=c.useState(()=>{try{const w=JSON.parse(sessionStorage.getItem("captureItems")||"null");if(Array.isArray(w)&&w.length>0){const B=w.filter(M=>!M.status||M.status==="idle");if(B.length>0)return B.forEach(M=>{M.id>=dl&&(dl=M.id+1)}),B.map(M=>({...Qn(M.locator),...M}))}}catch{}return[Qn()]});c.useEffect(()=>{sessionStorage.setItem("captureItems",JSON.stringify(j.filter(w=>w.kind!=="file")))},[j]),c.useEffect(()=>{p.current=j},[j]);const[R,G]=c.useState(!1),[H,Z]=c.useState(null),[re,ce]=c.useState(null),[Ae,ye]=c.useState(!0),[A,L]=c.useState(!0),[V,Q]=c.useState(!0);c.useEffect(()=>{fo().then(w=>{ce(w),ye(w.cookie_ext_enabled??!0),L(w.modal_closer_enabled??!0)}).catch(()=>ce({}))},[]);const te=H!==null?H:(re==null?void 0:re.ublock_enabled)??!0,[ze,ne]=c.useState(!1);c.useEffect(()=>{["captureDialogLocator","captureDialogError","captureDialogBusy","captureDialogJobStatus","captureDialogJobUid"].forEach(w=>sessionStorage.removeItem(w)),o.forEach(w=>{w.jobUid&&!y.current.has(w.jobUid)&&ke(w.id,w.jobUid,w.locator,w.archiveId,null)})},[]),c.useEffect(()=>{const w=u.current;if(!w)return;const B=()=>{if(g.current.forEach(M=>clearTimeout(M)),g.current.clear(),!f.current){const M=v.current;p.current.forEach(z=>{var F;z.kind==="file"&&(z.uploadStatus==="uploading"?((F=m.current.get(z.id))==null||F(),m.current.delete(z.id)):z.uploadStatus==="done"&&z.uploadLocator&&wi(M,z.uploadLocator).catch(()=>{}))})}f.current=!1,n()};return w.addEventListener("close",B),()=>w.removeEventListener("close",B)},[n]),c.useEffect(()=>{const w=u.current;w&&(e?(d.current||P([Qn()]),d.current=!1,w.open||w.showModal()):(g.current.forEach(B=>clearTimeout(B)),g.current.clear(),w.open&&w.close()))},[e]),c.useEffect(()=>()=>{y.current.forEach(w=>clearInterval(w)),g.current.forEach(w=>clearTimeout(w))},[]);function ke(w,B,M,z,F=null){if(y.current.has(B))return;const U=setInterval(async()=>{var pe,de,Pe,he;try{const Qe=await ef(z,B);if(Qe.status==="completed"){clearInterval(y.current.get(B)),y.current.delete(B),await Promise.resolve((pe=k.current)==null?void 0:pe.call(k)),(de=T.current)==null||de.call(T,w);try{const ie=Qe.notes_json?JSON.parse(Qe.notes_json):null;if(ie!=null&&ie.ublock_skipped||ie!=null&&ie.cookie_ext_skipped){const yt=ie.ublock_skipped&&ie.cookie_ext_skipped?"Captured without ad-blocking or cookie-consent extension. Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config.":ie.ublock_skipped?"Captured without ad-blocking. ARCHIVR_UBLOCK=true but ARCHIVR_UBLOCK_EXT is not set or the path is invalid.":"Captured without cookie-consent extension. ARCHIVR_COOKIE_EXT is not set or the path is invalid.";E.current(yt,M,"warning"),oe(F,"warning",M)}else F||E.current(null,M,"success"),oe(F,"archived")}catch{F||E.current(null,M,"success"),oe(F,"archived")}}else if(Qe.status==="failed"){clearInterval(y.current.get(B)),y.current.delete(B),(Pe=T.current)==null||Pe.call(T,w);const ie=Qe.error_text||"Capture failed.";E.current(ie,M),oe(F,"failed",M)}}catch(Qe){clearInterval(y.current.get(B)),y.current.delete(B),(he=T.current)==null||he.call(T,w);const ie=Qe.message||"Network error";E.current(ie,M),oe(F,"failed",M)}},500);y.current.set(B,U)}function oe(w,B,M=null){if(!w)return;const z=h.current.get(w);if(!z||(B==="archived"||B==="warning"?(z.archived++,B==="warning"&&(z.warnings++,M&&z.warningLocators.push(M))):(z.failed++,M&&z.failedLocators.push(M)),z.archived+z.failed0?`${F} archived (${U} with warnings)`:`${F} archived`;he=pe>0?`${yt}, ${pe} failed`:yt}const Qe=F===0?"error":pe>0||U>0?"warning":"success",ie=[];de.length>0&&ie.push(`Failed:
${de.map(yt=>` ${yt}`).join(`
-`)}`),Te.length>0&&ie.push(`With warnings:
-${Te.map(yt=>` ${yt}`).join(`
-`)}`);const it=ie.length>0?ie.join(`
-`):null;E.current(it,null,Ve,he)}async function Ne(w,B){var Te,he,Ve;const M=v.current,z=((Te=crypto.randomUUID)==null?void 0:Te.call(crypto))??`job-${Date.now()}-${Math.random()}`;if(w.type==="text"){try{const ie=await Gh(M,{title:w.title,body:w.body,mime:w.mime}),it=`text:${w.title}`;(he=b.current)==null||he.call(b,{id:z,jobUid:ie.job_uid,locator:it,archiveId:M}),we(z,ie.job_uid,it,M,B)}catch(ie){const it=ie.message||"Submission failed.";E.current(it,`text:${w.title}`),oe(B,"failed",`text:${w.title}`)}return}const F=w.locator,U=w.quality,pe=w.extraExtensions||{},de={ublock_enabled:te,reader_mode:Oe,cookie_ext_enabled:De,modal_closer_enabled:A,via_freedium:V,...pe};try{const ie=await Jh(M,F,U,de);(Ve=b.current)==null||Ve.call(b,{id:z,jobUid:ie.job_uid,locator:F,archiveId:M}),we(z,ie.job_uid,F,M,B)}catch(ie){const it=ie.message||"Submission failed.";E.current(it,F),oe(B,"failed",F),F.startsWith("file://")&&ie.status&&wi(M,F).catch(()=>{})}}function $t(){var z,F;if(j.some(U=>U.kind==="file"&&U.uploadStatus==="uploading"))return;const w=j.filter(U=>U.kind==="file"?U.uploadStatus==="done"&&U.uploadLocator:U.kind==="text"?U.title.trim()&&U.body.trim():U.locator.trim());if(w.length===0||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&Pu(U))||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&(U.probeState==="probing"||Ln(U.locator)&&U.playlistProbeState!=="done"))||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&Array.isArray(U.playlistItems)&&U.playlistItems.length===0))return;const B=w.length>1?((z=crypto.randomUUID)==null?void 0:z.call(crypto))??`batch-${Date.now()}`:null;B&&h.current.set(B,{total:w.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]});const M=w.map(U=>U.kind==="file"?{type:"file",locator:U.uploadLocator,quality:"best",extraExtensions:{}}:U.kind==="text"?{type:"text",title:U.title.trim(),body:U.body.trim(),mime:U.mime}:{type:"url",locator:U.locator.trim(),quality:U.playlistItems!==null?null:U.quality||"best",extraExtensions:U.playlistItems!==null?{per_item_quality:Object.fromEntries(U.playlistItems.map(pe=>[pe.id,pe.quality])),sync:U.syncEnabled}:{}});f.current=!0,P([Qn()]),(F=u.current)==null||F.close(),M.forEach(U=>Ne(U,B))}function Dt(){P(w=>[...w,Qn()])}function _t(w){var M;clearTimeout(g.current.get(w)),g.current.delete(w);const B=p.current.find(z=>z.id===w);(B==null?void 0:B.kind)==="file"&&(B.uploadStatus==="uploading"?((M=m.current.get(w))==null||M(),m.current.delete(w)):B.uploadStatus==="done"&&B.uploadLocator&&wi(v.current,B.uploadLocator).catch(()=>{})),P(z=>{const F=z.filter(U=>U.id!==w);return F.length===0?[Qn()]:F})}function Fe(w,B){if(clearTimeout(g.current.get(w)),P(M=>M.map(z=>z.id===w?{...z,locator:B,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best",playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1}:z)),ef(B)){const M=setTimeout(async()=>{g.current.delete(w),P(z=>z.map(F=>F.id===w?{...F,probeState:"probing"}:F));try{const z=await Yh(v.current,B.trim());P(F=>F.map(U=>{if(U.id!==w||U.locator!==B)return U;const pe=z.qualities??[],de=z.has_audio??!1,Te=pe.length===0&&de?"audio":"best";return{...U,probeState:"done",probeQualities:pe,probeHasAudio:de,quality:Te}}))}catch{P(z=>z.map(F=>F.id===w?{...F,probeState:"idle",probeQualities:null}:F))}},600);g.current.set(w,M)}else if(Ln(B)){const M=setTimeout(async()=>{g.current.delete(w),P(z=>z.map(F=>F.id===w?{...F,playlistProbeState:"probing"}:F));try{const z=await Zh(v.current,B.trim());P(F=>F.map(U=>U.id!==w||U.locator!==B?U:{...U,playlistProbeState:"done",playlistInfo:z,playlistItems:z.items.map(pe=>({...pe,quality:null})),playlistQuality:null}))}catch{P(z=>z.map(F=>F.id===w?{...F,playlistProbeState:"error"}:F))}},800);g.current.set(w,M)}}function Ct(w,B){P(M=>M.map(z=>z.id===w?{...z,quality:B}:z))}function mt(w,B){P(M=>M.map(z=>{if(z.id!==w)return z;const F=Dm(B,z.playlistItems);return{...z,playlistQuality:B,playlistItems:F}}))}function st(w,B,M){P(z=>z.map(F=>F.id!==w?F:{...F,playlistItems:F.playlistItems.map(U=>U.id===B?{...U,quality:M}:U)}))}function Et(w){P(B=>B.map(M=>M.id===w?{...M,playlistExpanded:!M.playlistExpanded}:M))}function O(w,B){P(M=>M.map(z=>z.id===w?{...z,syncEnabled:B}:z))}function J(w,B){P(M=>M.map(z=>z.id!==w?z:{...z,playlistItems:z.playlistItems.filter(F=>F.id!==B)}))}function ve(w){const B=Array.from(w);B.length!==0&&B.forEach(M=>{const z=Im(M.name);P(de=>de.length===1&&de[0].kind!=="file"&&!de[0].locator.trim()?[z]:[...de,z]);const F=v.current,{promise:U,abort:pe}=Tm(F,M,de=>{P(Te=>Te.map(he=>he.id===z.id?{...he,uploadProgress:de}:he))});m.current.set(z.id,pe),U.then(de=>{m.current.delete(z.id),P(Te=>Te.map(he=>he.id===z.id?{...he,uploadStatus:"done",uploadLocator:de.locator,uploadProgress:100}:he))}).catch(de=>{m.current.delete(z.id),de.message!=="Upload cancelled"&&P(Te=>Te.map(he=>he.id===z.id?{...he,uploadStatus:"error",uploadError:de.message}:he))})})}function Ce(w){w.preventDefault(),w.stopPropagation(),w.dataTransfer.types.includes("Files")&&N(!0)}function Wt(w){w.currentTarget.contains(w.relatedTarget)||N(!1)}function Re(w){w.preventDefault(),w.stopPropagation(),N(!1),ve(w.dataTransfer.files)}function Bn(w){ve(w.target.files),w.target.value=""}const tn=j.some(w=>w.kind==="file"&&w.uploadStatus==="uploading"),gt=j.filter(w=>w.kind==="file"?w.uploadStatus==="done"&&w.uploadLocator:w.kind==="text"?w.title.trim()&&w.body.trim():w.locator.trim()).length,We=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&Pu(w)),Sn=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&Array.isArray(w.playlistItems)&&w.playlistItems.length===0),Nn=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&(w.probeState==="probing"||Ln(w.locator)&&w.playlistProbeState!=="done"));return s.jsx("dialog",{ref:u,className:`capture-dialog${S?" capture-dialog--dragover":""}`,onDragOver:Ce,onDragLeave:Wt,onDrop:Re,children:s.jsxs("div",{className:"capture-dialog-inner",children:[s.jsxs("div",{className:"capture-dialog-header",children:[s.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),s.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var w;return(w=u.current)==null?void 0:w.close()},"aria-label":"Close",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),s.jsx("div",{className:"capture-rows",children:j.map((w,B)=>w.kind==="file"?s.jsx(Mm,{item:w,onRemove:()=>_t(w.id)},w.id):w.kind==="text"?s.jsx(Fm,{item:w,autoFocus:B===j.length-1,onTitleChange:M=>P(z=>z.map(F=>F.id===w.id?{...F,title:M}:F)),onBodyChange:M=>P(z=>z.map(F=>F.id===w.id?{...F,body:M}:F)),onMimeChange:M=>P(z=>z.map(F=>F.id===w.id?{...F,mime:M}:F)),onRemove:()=>_t(w.id),onSubmit:$t},w.id):s.jsx(Am,{item:w,autoFocus:B===j.length-1,onLocatorChange:M=>Fe(w.id,M),onQualityChange:M=>Ct(w.id,M),onRemove:()=>_t(w.id),onSubmit:$t,onPlaylistQualityChange:M=>mt(w.id,M),onPlaylistItemQualityChange:(M,z)=>st(w.id,M,z),onPlaylistToggle:()=>Et(w.id),onSyncChange:M=>O(w.id,M),onPlaylistItemDelete:M=>J(w.id,M)},w.id))}),s.jsx("input",{ref:x,type:"file",multiple:!0,hidden:!0,onChange:Bn,"aria-hidden":"true",tabIndex:-1}),s.jsxs("div",{className:"capture-add-row-group",children:[s.jsxs("button",{type:"button",className:"capture-add-row",onClick:Dt,children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),s.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add URL"]}),s.jsxs("button",{type:"button",className:"capture-add-row capture-add-file",onClick:()=>{var w;return(w=x.current)==null?void 0:w.click()},children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]}),"Upload file"]}),s.jsxs("button",{type:"button",className:"capture-add-row capture-add-text",onClick:()=>P(w=>[...w,$m()]),children:[s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M2 3h12M2 7h12M2 11h8"})}),"Add text"]})]}),s.jsxs("div",{className:"capture-advanced",children:[s.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>G(w=>!w),"aria-expanded":R,children:[s.jsx("svg",{className:`capture-chevron${R?" capture-chevron--open":""}`,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("polyline",{points:"4 6 8 10 12 6"})}),"Advanced options"]}),R&&s.jsxs("div",{className:"capture-advanced-panel",children:[s.jsxs("label",{className:"capture-ext-row",children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"uBlock Origin Lite"}),s.jsx("span",{className:"capture-ext-desc",children:"Block ads during this capture"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":te,className:`ext-toggle ext-toggle--sm${te?" ext-toggle--on":""}`,onClick:()=>Z(w=>w===null?!te:!w),"aria-label":"Toggle uBlock for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Block cookie banners"}),s.jsx("span",{className:"capture-ext-desc",children:"Dismiss cookie consent banners during this capture"}),!(re!=null&&re.cookie_ext_available)&&s.jsxs("span",{className:"capture-ext-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":De,className:`ext-toggle ext-toggle--sm${De?" ext-toggle--on":""}`,onClick:()=>ye(w=>!w),"aria-label":"Toggle cookie banner blocking for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Reader mode"}),s.jsx("span",{className:"capture-ext-desc",children:"Distil to article text via Readability (off by default)"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":Oe,className:`ext-toggle ext-toggle--sm${Oe?" ext-toggle--on":""}`,onClick:()=>ne(w=>!w),"aria-label":"Toggle reader mode for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Close modals and dialogs"}),s.jsx("span",{className:"capture-ext-desc",children:"Auto-dismiss cookie banners and overlays during this capture"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":A,className:`ext-toggle ext-toggle--sm${A?" ext-toggle--on":""}`,onClick:()=>L(w=>!w),"aria-label":"Toggle modal closer for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Freedium mirror"}),s.jsx("span",{className:"capture-ext-desc",children:"Route paywalled articles through a Freedium mirror (Medium, NYT, WaPo, etc.)"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":V,className:`ext-toggle ext-toggle--sm${V?" ext-toggle--on":""}`,onClick:()=>K(w=>!w),"aria-label":"Toggle Freedium mirror for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]})]})]}),s.jsxs("div",{className:"capture-actions",children:[s.jsx("button",{type:"button",className:"capture-submit",onClick:$t,disabled:gt===0||We||Nn||Sn||tn,children:gt>1?`Archive ${gt}`:"Archive"}),s.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var w;return(w=u.current)==null?void 0:w.close()},children:"Cancel"})]})]})})}function Am({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onSubmit:i,onPlaylistQualityChange:a,onPlaylistItemQualityChange:o,onPlaylistToggle:u,onSyncChange:d,onPlaylistItemDelete:y}){const g=c.useRef(null);c.useEffect(()=>{var x;t&&((x=g.current)==null||x.focus())},[t]);const h=(()=>{if(Ln(e.locator)){if(e.playlistProbeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Probing playlist…",children:"…"});if(e.playlistProbeState==="done"){const x=[...new Set(e.playlistItems.flatMap(p=>p.qualities.map(f=>parseInt(f))))].sort((p,f)=>f-p),S=e.playlistItems.every(p=>p.has_audio),N=e.playlistItems.filter(p=>p.quality===null).length;return s.jsxs(s.Fragment,{children:[s.jsxs("select",{className:"capture-quality",value:e.playlistQuality??"",onChange:p=>a(p.target.value),"aria-label":"Playlist quality",children:[!e.playlistQuality&&s.jsx("option",{value:"",disabled:!0,children:"Select quality…"}),s.jsx("option",{value:"best",children:"Best quality"}),x.map(p=>s.jsxs("option",{value:`${p}p`,children:[p,"p"]},p)),S&&s.jsx("option",{value:"audio",children:"Audio only"})]}),N>0&&s.jsxs("span",{className:"capture-conflict-badge",children:[N," need selection"]})]})}return e.playlistProbeState==="error"?s.jsx("span",{className:"capture-quality-hint capture-quality-hint--error",children:"Probe failed — edit URL to retry"}):null}if(!ef(e.locator))return null;if(e.probeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const x=e.probeQualities??[],S=e.probeHasAudio??!1;return x.length===0&&!S?s.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):x.length===0&&S?s.jsx("select",{className:"capture-quality",value:"audio",onChange:N=>r(N.target.value),"aria-label":"Video quality",children:s.jsx("option",{value:"audio",children:"Audio only"})}):s.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:N=>r(N.target.value),"aria-label":"Video quality",children:[s.jsx("option",{value:"best",children:"Best quality"}),x.map(N=>s.jsx("option",{value:N,children:N},N)),S&&s.jsx("option",{value:"audio",children:"Audio only"})]})}return null})(),v=Ln(e.locator)&&e.playlistProbeState==="done"?s.jsxs("label",{className:"capture-sync-row",children:[s.jsx("input",{type:"checkbox",checked:e.syncEnabled,onChange:x=>d(x.target.checked)}),s.jsx("span",{children:"Sync — skip already-archived videos"})]}):null;return s.jsxs("div",{className:"capture-row",children:[s.jsxs("div",{className:"capture-row-main",children:[Ln(e.locator)&&e.playlistProbeState==="done"?s.jsx("button",{type:"button",className:"capture-playlist-toggle capture-playlist-toggle--left",onClick:u,"aria-label":e.playlistExpanded?"Collapse video list":"Expand video list","aria-expanded":e.playlistExpanded,children:e.playlistExpanded?"▲":"▼"}):null,s.jsx("input",{ref:g,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:x=>n(x.target.value),onKeyDown:x=>{x.key==="Enter"&&i()},autoComplete:"off",spellCheck:!1}),h,s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&s.jsx("p",{className:"capture-row-error",children:e.error}),Ln(e.locator)&&e.playlistProbeState==="done"&&e.playlistExpanded?s.jsxs("div",{className:"capture-playlist-items",children:[e.playlistItems.map(x=>s.jsxs("div",{className:`capture-playlist-item${x.quality===null?" capture-playlist-item--conflict":""}`,children:[s.jsx("span",{className:"capture-playlist-item-title",children:x.title||x.url}),s.jsxs("select",{className:"capture-item-quality",value:x.quality??"",onChange:S=>o(x.id,S.target.value),"aria-label":`Quality for ${x.title||x.url}`,children:[x.quality===null&&s.jsx("option",{value:"",disabled:!0,children:"Choose…"}),s.jsx("option",{value:"best",children:"Best quality"}),x.qualities.map(S=>s.jsx("option",{value:S,children:S},S)),x.has_audio&&s.jsx("option",{value:"audio",children:"Audio only"})]}),x.quality===null&&s.jsx("span",{className:"capture-playlist-conflict-badge",children:"Choose quality"}),s.jsx("button",{type:"button",className:"capture-playlist-item-remove","aria-label":`Remove ${x.title||x.url}`,onClick:()=>y(x.id),children:"×"})]},x.id)),v]}):v]})}function Mm({item:e,onRemove:t}){const n=e.uploadStatus==="uploading",r=e.uploadStatus==="done",l=e.uploadStatus==="error";return s.jsxs("div",{className:"capture-row",children:[s.jsxs("div",{className:"capture-row-main",children:[s.jsx("span",{className:"capture-file-icon","aria-hidden":"true",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",style:{width:14,height:14},children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]})}),s.jsx("span",{className:`capture-file-name${l?" capture-file-name--error":""}`,children:e.filename}),n&&s.jsxs("span",{className:"capture-file-progress-wrap","aria-label":`Uploading ${e.uploadProgress}%`,children:[s.jsx("span",{className:"capture-file-progress-bar",children:s.jsx("span",{className:"capture-file-progress-fill",style:{width:`${e.uploadProgress}%`}})}),s.jsxs("span",{className:"capture-file-progress-pct",children:[e.uploadProgress,"%"]})]}),r&&s.jsx("span",{className:"capture-file-badge capture-file-badge--done","aria-label":"Upload complete",children:s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{width:11,height:11},children:s.jsx("polyline",{points:"3 8.5 6.5 12 13 5"})})}),l&&s.jsx("span",{className:"capture-file-badge capture-file-badge--error",children:"!"}),s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:t,"aria-label":"Remove",disabled:n,children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),l&&s.jsx("p",{className:"capture-row-error",children:e.uploadError||"Upload failed"})]})}function Fm({item:e,autoFocus:t,onTitleChange:n,onBodyChange:r,onMimeChange:l,onRemove:i,onSubmit:a}){const o=c.useRef(null);return c.useEffect(()=>{var u;t&&((u=o.current)==null||u.focus())},[t]),s.jsx("div",{className:"capture-row capture-text-row",children:s.jsxs("div",{className:"capture-row-main",children:[s.jsx("span",{className:"capture-text-icon","aria-hidden":"true",children:s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",style:{width:14,height:14},children:s.jsx("path",{d:"M2 3h12M2 7h12M2 11h8"})})}),s.jsxs("div",{className:"capture-text-inputs",children:[s.jsx("input",{ref:o,className:"capture-text-input capture-text-title",type:"text",placeholder:"Title",value:e.title,onChange:u=>n(u.target.value),maxLength:500}),s.jsx("textarea",{className:"capture-text-input capture-text-body",placeholder:"Body (markdown or plain text)",value:e.body,onChange:u=>r(u.target.value),rows:6}),s.jsx("div",{className:"capture-text-footer",children:s.jsxs("select",{className:"capture-text-mime",value:e.mime,onChange:u=>l(u.target.value),children:[s.jsx("option",{value:"text/markdown",children:"Markdown"}),s.jsx("option",{value:"text/plain",children:"Plain text"})]})})]}),s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:i,"aria-label":"Remove",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]})})}const Bm=["list=","/playlist/","/channel/","yt:playlist:","yt:channel:","ytm:playlist:","spotify:playlist:","spotify:album:"];function Um(e){const t=e.toLowerCase();return Bm.some(n=>t.includes(n))}function Hm(e){return e.length>80?`${e.slice(0,79)}…`:e}function Wm({locator:e=""}){const t=String(e),n=Um(t);return s.jsxs("div",{className:"in-progress-entry-row",role:"status","aria-live":"polite",children:[s.jsx("span",{className:"cap-spinner in-progress-entry-row__spinner","aria-hidden":"true"}),s.jsx("span",{className:"in-progress-entry-row__locator",title:t,children:Hm(t)}),s.jsxs("span",{className:"in-progress-entry-row__status",children:["Archiving…",n&&s.jsx("span",{className:"in-progress-entry-row__kind",children:"(playlist)"})]})]})}function fl(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&r").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}function ut(e){return Vm(e)??""}function ho(e){if(!e)return"";const t=new Date(e);if(isNaN(t))return e;const n=r=>String(r).padStart(2,"0");return`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())} ${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}const Lu={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:''};function Bs(e){return Lu[e]??Lu.other}function tf(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Qm({entry:e,index:t,onRowClick:n,selectedUids:r}){const l=(r==null?void 0:r.size)===1&&r.has(e.entry_uid),i=(r==null?void 0:r.size)>=2&&r.has(e.entry_uid),a=["child-entry-row",t%2===0?"child-entry-row--light":"child-entry-row--dark",l&&"is-selected",i&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:a,tabIndex:0,"data-entry-uid":e.entry_uid,onMouseDown:o=>{o.shiftKey&&o.preventDefault()},onClick:o=>n(e,o),onKeyDown:o=>{o.key==="Enter"&&n(e,o)},children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:ho(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[s.jsx("span",{className:"source-icon",children:s.jsx("span",{dangerouslySetInnerHTML:{__html:Bs(e.source_kind)}})}),s.jsx("span",{className:"entry-title",children:ut(e.title)||ut(e.entry_uid)})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:ut(e.entity_kind)})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"size-total",children:fl(e.total_artifact_bytes)})}),s.jsx("div",{className:"url-cell col-url",children:ut(e.original_url)})]})}function qm({entry:e,archiveId:t,rowIndex:n,isSelected:r,isMultiSelected:l,onRowClick:i,selectedUids:a,deletedUids:o,isPublicSession:u}){const[d,y]=c.useState(!1),[g,h]=c.useState(!1),[v,x]=c.useState(null),[S,N]=c.useState(!1),f=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!d?s.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>y(!0),style:{objectFit:"contain"}}):s.jsx("span",{dangerouslySetInnerHTML:{__html:Bs(e.source_kind)}}),m=r||l,k=e.child_count>0&&!u;function E(j){j.stopPropagation(),i(e,{ctrlKey:!0,metaKey:!1,shiftKey:!1,preventDefault(){}})}async function b(j){if(j.stopPropagation(),g){h(!1);return}if(h(!0),v===null&&!S){N(!0);try{const P=await Bh(t,e.entry_uid);x(P)}catch{x([])}finally{N(!1)}}}const T=["entry-row-outer",n%2===0?"entry-row-outer--light":"entry-row-outer--dark",r&&"is-selected",l&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:T,"data-entry-uid":e.entry_uid,children:[s.jsxs("div",{className:"entry-row-main",tabIndex:0,onMouseDown:j=>{j.shiftKey&&j.preventDefault()},onClick:j=>i(e,j),onKeyDown:j=>{j.key==="Enter"&&i(e,j)},children:[s.jsx("div",{className:"col-check",children:s.jsx("button",{type:"button",className:`row-checkbox${m?" is-checked":""}`,"aria-pressed":m,"aria-label":m?"Deselect entry":"Select entry",onClick:E,onKeyDown:j=>j.stopPropagation()})}),s.jsx("div",{className:"col-added",children:ho(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[k&&s.jsx("button",{type:"button",className:`entry-expand-btn${g?" is-expanded":""}`,"aria-label":g?"Collapse children":`Expand ${e.child_count} items`,"aria-expanded":g,onClick:b,onKeyDown:j=>j.stopPropagation()}),s.jsx("span",{className:"source-icon",children:f}),s.jsx("span",{className:"entry-title",children:ut(e.title)||ut(e.entry_uid)}),k&&s.jsx("span",{className:"child-count-badge","aria-hidden":"true",children:e.child_count})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:ut(e.entity_kind)})}),s.jsxs("div",{className:"col-size",children:[s.jsx("span",{className:"size-total",children:fl(e.total_artifact_bytes)}),e.cached_bytes>0&&e.cacheable_bytes>0&&s.jsxs("span",{className:"size-cached-pct",title:`${fl(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.cacheable_bytes*100),"% cached"]})]}),s.jsx("div",{className:"url-cell col-url",children:ut(e.original_url)})]}),g&&s.jsxs(s.Fragment,{children:[S&&s.jsx("div",{className:"child-entries-loading",children:"Loading…"}),s.jsx("div",{className:"child-entries","aria-label":`${e.child_count} child entries`,children:v&&v.filter(j=>!(o!=null&&o.has(j.entry_uid))).map((j,P)=>s.jsx(Qm,{entry:j,index:P,onRowClick:i,selectedUids:a},j.entry_uid))})]})]})}function Km({entries:e,selectedUids:t,onRowClick:n,archiveId:r,pendingCaptures:l=[],deletedUids:i,isPublicSession:a}){return s.jsx("section",{id:"archive-view",className:"view is-active",children:s.jsxs("div",{className:"entry-table",children:[s.jsxs("div",{className:"entry-header-row",children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:"Added"}),s.jsx("div",{className:"col-title",children:"Title"}),s.jsx("div",{className:"col-type",children:"Type"}),s.jsx("div",{className:"col-size",children:"Size"}),s.jsx("div",{className:"col-url",children:"Original URL"})]}),s.jsxs("div",{id:"entries-body",children:[l.filter(o=>o.archiveId===r).reverse().map(o=>s.jsx(Wm,{locator:o.locator},o.id)),e.map((o,u)=>s.jsx(qm,{entry:o,rowIndex:u,archiveId:r,isSelected:t.size===1&&t.has(o.entry_uid),isMultiSelected:t.size>=2&&t.has(o.entry_uid),onRowClick:n,selectedUids:t,deletedUids:i,isPublicSession:a},o.entry_uid))]})]})})}function Xm(e){if(!e)return"—";try{return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return e}}function Jm({status:e}){const t=e==="completed"?"run-status--completed":e==="failed"?"run-status--failed":e==="in_progress"?"run-status--in-progress":"",n=e?e.replace(/_/g," "):"—";return s.jsx("span",{className:`run-status ${t}`,children:n})}function Gm({runs:e}){const[t,n]=c.useState(null);function r(l){n(i=>i===l?null:l)}return s.jsx("section",{id:"runs-view",className:"view is-active",children:s.jsxs("table",{className:"entry-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Started"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Requested"}),s.jsx("th",{children:"Completed"}),s.jsx("th",{children:"Failed"})]})}),s.jsx("tbody",{children:e.length===0?s.jsx("tr",{children:s.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const i=l.status==="failed"&&l.error_summary,a=t===l.run_uid;return[s.jsxs("tr",{className:i?"run-row run-row--failed":"run-row",onClick:i?()=>r(l.run_uid):void 0,title:i?a?"Click to hide error":"Click to view error":void 0,children:[s.jsx("td",{children:Xm(l.started_at)}),s.jsxs("td",{children:[s.jsx(Jm,{status:l.status}),i&&s.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:a?"▴":"▾"})]}),s.jsx("td",{children:l.requested_count??"—"}),s.jsx("td",{children:l.completed_count??"—"}),s.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),i&&a&&s.jsx("tr",{className:"run-error-row",children:s.jsx("td",{colSpan:5,children:s.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const Ym=4;function Zm({archives:e}){const{currentUser:t}=c.useContext(Us)??{},n=t&&(t.role_bits&Ym)!==0,[r,l]=c.useState("users"),[i,a]=c.useState([]),[o,u]=c.useState([]),[d,y]=c.useState(!1),[g,h]=c.useState(null),[v,x]=c.useState(""),[S,N]=c.useState(""),[p,f]=c.useState(""),[m,k]=c.useState(null),[E,b]=c.useState(!1),[T,j]=c.useState(""),[P,R]=c.useState(""),[G,H]=c.useState(null),[Z,re]=c.useState(!1),ce=c.useCallback(async()=>{if(n){y(!0),h(null);try{const[L,V]=await Promise.all([dm(),hm()]);a(L),u(V)}catch(L){h(L.message)}finally{y(!1)}}},[n]);c.useEffect(()=>{ce()},[ce]);async function De(L){const V=L.status==="active"?"disabled":"active";try{await pm(L.user_uid,V),a(K=>K.map(te=>te.user_uid===L.user_uid?{...te,status:V}:te))}catch(K){h(K.message)}}async function ye(L){if(L.preventDefault(),!v.trim()||!S){k("Username and password required");return}b(!0),k(null);try{await fm(v.trim(),S,p.trim()||void 0),x(""),N(""),f(""),await ce()}catch(V){k(V.message)}finally{b(!1)}}async function A(L){if(L.preventDefault(),!T.trim()||!P.trim()){H("Slug and name required");return}re(!0),H(null);try{await mm(T.trim(),P.trim()),j(""),R(""),await ce()}catch(V){H(V.message)}finally{re(!1)}}return n?s.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[s.jsx("h1",{children:"Admin"}),s.jsxs("div",{className:"view-tabs",children:[s.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),s.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),s.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),g&&s.jsx("div",{className:"form-msg form-msg--err",children:g}),r==="users"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Users"}),d?s.jsx("p",{className:"muted",children:"Loading…"}):s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Username"}),s.jsx("th",{children:"Email"}),s.jsx("th",{children:"Roles"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Actions"})]})}),s.jsx("tbody",{children:i.map(L=>s.jsxs("tr",{className:L.status==="disabled"?"admin-row-disabled":"",children:[s.jsx("td",{children:L.username}),s.jsx("td",{className:"muted",children:L.email||"—"}),s.jsx("td",{children:L.role_slugs.join(", ")||"—"}),s.jsx("td",{children:s.jsx("span",{className:`status-badge status-${L.status}`,children:L.status})}),s.jsx("td",{children:s.jsx("button",{className:"admin-action-btn",onClick:()=>De(L),children:L.status==="active"?"Ban":"Unban"})})]},L.user_uid))})]}),s.jsx("h3",{children:"Create User"}),s.jsxs("form",{className:"admin-form",onSubmit:ye,children:[s.jsx("input",{className:"admin-input",placeholder:"Username",value:v,onChange:L=>x(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:S,onChange:L=>N(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:p,onChange:L=>f(L.target.value)}),m&&s.jsx("div",{className:"form-msg form-msg--err",children:m}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"Creating…":"Create User"})]})]}),r==="roles"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Roles"}),d?s.jsx("p",{className:"muted",children:"Loading…"}):s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Slug"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Level"}),s.jsx("th",{children:"Bit"}),s.jsx("th",{children:"Built-in"})]})}),s.jsx("tbody",{children:o.map(L=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("code",{children:L.slug})}),s.jsx("td",{children:L.name}),s.jsx("td",{children:L.level}),s.jsx("td",{children:L.bit_position}),s.jsx("td",{children:L.is_builtin?"✓":""})]},L.role_uid))})]}),s.jsx("h3",{children:"Create Custom Role"}),s.jsxs("form",{className:"admin-form",onSubmit:A,children:[s.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:T,onChange:L=>j(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:P,onChange:L=>R(L.target.value),required:!0}),G&&s.jsx("div",{className:"form-msg form-msg--err",children:G}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:Z,children:Z?"Creating…":"Create Role"})]})]}),r==="archives"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Mounted Archives"}),s.jsx("div",{className:"admin-list",children:e.map(L=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:L.label}),s.jsx("div",{className:"muted",children:L.archive_path})]},L.id))})]})]}):s.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[s.jsx("h1",{children:"Admin"}),s.jsx("p",{className:"muted",children:"You need admin privileges to access this panel."}),s.jsx("h2",{children:"Mounted Archives"}),s.jsx("div",{className:"admin-list",children:e.map(L=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:L.label}),s.jsx("div",{className:"muted",children:L.archive_path})]},L.id))})]})}function nf({node:e,onPick:t}){var n;return s.jsxs("li",{children:[s.jsx("button",{className:"tag-picker-node-btn",title:e.tag.full_path,onClick:()=>t(e.tag),children:e.tag.slug}),((n=e.children)==null?void 0:n.length)>0&&s.jsx("div",{className:"tag-children",children:s.jsx("ul",{className:"tag-tree-list",children:e.children.map(r=>s.jsx(nf,{node:r,onPick:t},r.tag.tag_uid))})})]})}function Ru({title:e,tagNodes:t,excludeUid:n,onPick:r,onCancel:l}){c.useEffect(()=>{function o(u){u.key==="Escape"&&(u.preventDefault(),u.stopPropagation(),l())}return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[l]);function i(o){return o.filter(u=>u.tag.tag_uid!==n).map(u=>({...u,children:i(u.children)}))}const a=n?i(t):t;return s.jsx("div",{className:"tag-picker-backdrop",onClick:o=>{o.target===o.currentTarget&&l()},children:s.jsxs("div",{className:"tag-picker-modal",role:"dialog","aria-modal":"true",children:[s.jsxs("div",{className:"tag-picker-header",children:[s.jsx("span",{className:"tag-picker-title",children:e}),s.jsx("button",{className:"tag-picker-close",onClick:l,title:"Cancel","aria-label":"Cancel",children:"×"})]}),s.jsxs("div",{className:"tag-picker-body",children:[s.jsx("button",{className:"tag-picker-root-btn",onClick:()=>r(null),title:"Place at root level (no parent)",children:"↑ Root tag (no parent)"}),a.length>0?s.jsx("ul",{className:"tag-tree-list tag-picker-tree",children:a.map(o=>s.jsx(nf,{node:o,onPick:r},o.tag.tag_uid))}):s.jsx("p",{className:"tag-picker-empty",children:"No other tags available."})]})]})})}function rf({parentPath:e,archiveId:t,onDone:n,onCancel:r}){const[l,i]=c.useState(""),a=c.useRef(!1);async function o(){const u=l.trim();if(!u){r();return}const d=e?`${e}/${u}`:`/${u}`;try{await Kh(t,d),n()}catch(y){alert(y.message||"Create failed"),r()}}return s.jsx("input",{className:"tag-rename-input",autoFocus:!0,placeholder:"tag name",value:l,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur(),u.key==="Escape"&&(a.current=!0,u.currentTarget.blur())},onBlur:()=>{a.current?(a.current=!1,r()):o()}})}function lf({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:d,onMoveSourceSelect:y,pendingCreateParentUid:g,onCreateDone:h,onCreateCancel:v}){var G;const x=n===e.tag.full_path,[S,N]=c.useState(!1),[p,f]=c.useState(""),m=c.useRef(!1);function k(){if(S)return;if(d){y(e);return}const H=x?null:e.tag.full_path;r(H),l("archive")}function E(H){H.stopPropagation(),!d&&(f(e.tag.slug),N(!0))}async function b(){const H=p.trim();if(!H||H===e.tag.slug){N(!1);return}try{const Z=await Qh(t,e.tag.tag_uid,H);i(e.tag.full_path,Z.full_path),o()}catch{}finally{N(!1)}}async function T(H){var re;H.stopPropagation();const Z=((re=e.children)==null?void 0:re.length)>0?`Delete tag "${e.tag.full_path}" and all its child tags? This cannot be undone.`:`Delete tag "${e.tag.full_path}"? This cannot be undone.`;if(window.confirm(Z))try{await qh(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const j={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:d,onMoveSourceSelect:y,pendingCreateParentUid:g,onCreateDone:h,onCreateCancel:v},P=g===e.tag.tag_uid,R=((G=e.children)==null?void 0:G.length)>0;return s.jsxs("li",{children:[s.jsxs("div",{className:`tag-node-row${d?" tag-node-row--move-select":""}`,children:[S?s.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:p,onChange:H=>f(H.target.value),onKeyDown:H=>{H.key==="Enter"&&H.currentTarget.blur(),H.key==="Escape"&&(m.current=!0,H.currentTarget.blur())},onBlur:()=>{m.current?(m.current=!1,N(!1)):b()}}):s.jsxs("button",{className:`tag-node-btn${x?" is-active":""}${d?" tag-node-btn--move-select":""}`,title:d?`Select "${e.tag.full_path}" to move`:e.tag.full_path,onClick:k,onDoubleClick:d?void 0:E,children:[s.jsx("span",{className:"tag-node-label",children:u?e.tag.name:e.tag.slug}),s.jsx("span",{className:"tag-node-count",children:e.children.length===0?`(${e.entry_count})`:`(${e.entry_count}) (${e.subtree_count} Total)`}),!d&&s.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",title:"Rename tag",onClick:H=>{H.stopPropagation(),E(H)},children:s.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),!S&&!d&&s.jsx("button",{className:"remove tag-node-delete",title:`Delete "${e.tag.full_path}"`,onClick:T,"aria-label":`Delete "${e.tag.full_path}"`,children:"×"})]}),(R||P)&&s.jsx("div",{className:"tag-children",children:s.jsxs("ul",{className:"tag-tree-list",children:[e.children.map(H=>s.jsx(lf,{node:H,...j},H.tag.tag_uid)),P&&s.jsx("li",{children:s.jsx(rf,{parentPath:e.tag.full_path,archiveId:t,onDone:h,onCancel:v})})]})})]})}function eg({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){const[d,y]=c.useState(null),[g,h]=c.useState(null);function v(){y("select-source"),h(null)}function x(){y(null),h(null)}c.useEffect(()=>{if(d!=="select-source")return;function Z(re){re.key==="Escape"&&(re.preventDefault(),re.stopPropagation(),x())}return document.addEventListener("keydown",Z),()=>document.removeEventListener("keydown",Z)},[d]);function S(Z){h(Z),y("select-dest")}async function N(Z){const re=g.tag.full_path,ce=g.tag.tag_uid,De=(Z==null?void 0:Z.tag_uid)??null;x();try{const ye=await Xh(e,ce,De);i(re,ye.full_path),o()}catch(ye){alert(ye.message||"Move failed")}}const[p,f]=c.useState(null),[m,k]=c.useState(void 0);function E(){f("select-parent"),k(void 0)}function b(){f(null),k(void 0)}function T(Z){k(Z??null),f("input")}function j(){f(null),k(void 0),o()}const P=d==="select-source",R=p==="input"?m?m.tag_uid:"__root__":void 0,G={archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:P,onMoveSourceSelect:S,pendingCreateParentUid:R,onCreateDone:j,onCreateCancel:b},H=R==="__root__";return s.jsxs("section",{id:"tags-view",className:"view is-active",children:[s.jsxs("div",{className:"tag-tree",children:[s.jsx("div",{className:"tag-tree-header",children:P?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"tag-tree-title tag-tree-title--move",children:"Select a tag to move"}),s.jsx("button",{className:"tag-tree-action-btn tag-tree-action-btn--cancel",onClick:x,children:"Cancel"})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&s.jsxs("span",{className:"tag-tree-active",title:n,children:["Filtering: ",n]}),s.jsxs("div",{className:"tag-tree-actions",children:[s.jsx("button",{className:"tag-tree-action-btn",onClick:E,title:"Create a new tag",disabled:!!p||!!d,children:"+ New"}),s.jsx("button",{className:"tag-tree-action-btn",onClick:v,title:"Move a tag to a different parent",disabled:!!p||!!d||t.length===0,children:"Move"})]})]})}),t.length===0&&!H?s.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):s.jsxs("ul",{className:"tag-tree-list",children:[t.map(Z=>s.jsx(lf,{node:Z,...G},Z.tag.tag_uid)),H&&s.jsx("li",{children:s.jsx(rf,{parentPath:null,archiveId:e,onDone:j,onCancel:b})})]})]}),p==="select-parent"&&s.jsx(Ru,{title:"Create tag under…",tagNodes:t,excludeUid:null,onPick:T,onCancel:b}),d==="select-dest"&&g&&s.jsx(Ru,{title:`Move "${g.tag.slug}" under…`,tagNodes:t,excludeUid:g.tag.tag_uid,onPick:N,onCancel:x})]})}const Ar=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],tg=e=>{var t;return((t=Ar.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function ng({archiveId:e}){const[t,n]=c.useState([]),[r,l]=c.useState(!1),[i,a]=c.useState(null),[o,u]=c.useState(null),[d,y]=c.useState(null),[g,h]=c.useState(!1),[v,x]=c.useState(null),[S,N]=c.useState(""),[p,f]=c.useState(""),[m,k]=c.useState(2),[E,b]=c.useState(!1),[T,j]=c.useState(!0),[P,R]=c.useState(null),[G,H]=c.useState(""),[Z,re]=c.useState(2),[ce,De]=c.useState(!1),[ye,A]=c.useState(null),[L,V]=c.useState(!1),[K,te]=c.useState(""),Oe=c.useRef(null),ne=t.find(O=>O.collection_uid===o)??null,we=(ne==null?void 0:ne.slug)==="_default_",oe=c.useCallback(async()=>{if(e){l(!0),a(null);try{const O=await po(e);n(O)}catch(O){a(O.message)}finally{l(!1)}}},[e]),Ne=c.useCallback(async O=>{if(!O){y(null);return}h(!0),x(null);try{const J=await ym(e,O);y(J)}catch(J){x(J.message)}finally{h(!1)}},[e]);c.useEffect(()=>{oe()},[oe]),c.useEffect(()=>{Ne(o)},[o,Ne]),c.useEffect(()=>{L&&Oe.current&&Oe.current.focus()},[L]),c.useEffect(()=>{d!=null&&re(d.default_visibility_bits)},[d]);async function $t(O){O.preventDefault();const J=S.trim(),ve=p.trim();if(!(!J||!ve)){b(!0),R(null);try{const Ce=await gm(e,J,ve,m,T);N(""),f(""),k(2),j(!0),await oe(),u(Ce.collection_uid)}catch(Ce){R(Ce.message)}finally{b(!1)}}}async function Dt(){const O=K.trim();if(!O||!ne){V(!1);return}try{await xi(e,ne.collection_uid,{name:O}),await oe(),y(J=>J&&{...J,name:O})}catch(J){a(J.message)}finally{V(!1)}}async function _t(O){if(ne)try{await xi(e,ne.collection_uid,{default_visibility_bits:O}),await oe(),y(J=>J&&{...J,default_visibility_bits:O})}catch(J){a(J.message)}}async function Fe(O){if(ne)try{await xi(e,ne.collection_uid,{requires_auth:O}),await oe(),y(J=>J&&{...J,requires_auth:O})}catch(J){a(J.message)}}async function Ct(){if(ne&&window.confirm(`Delete collection "${ne.name}"? Entries will not be deleted.`))try{await wm(e,ne.collection_uid),u(null),y(null),await oe()}catch(O){a(O.message)}}async function mt(O){O.preventDefault();const J=G.trim();if(!(!J||!ne)){De(!0),A(null);try{await ga(e,ne.collection_uid,J,Z),H(""),await Ne(ne.collection_uid)}catch(ve){A(ve.message)}finally{De(!1)}}}async function st(O){if(ne)try{await vm(e,ne.collection_uid,O),await Ne(ne.collection_uid)}catch(J){x(J.message)}}async function Et(O,J){if(ne)try{await xm(e,ne.collection_uid,O,J),y(ve=>ve&&{...ve,entries:ve.entries.map(Ce=>Ce.entry_uid===O?{...Ce,collection_visibility_bits:J}:Ce)})}catch(ve){x(ve.message)}}return e?s.jsxs("div",{className:"collections-view",children:[s.jsx("h2",{className:"collections-heading",children:"Collections"}),r&&s.jsx("div",{className:"muted",children:"Loading…"}),i&&s.jsxs("div",{className:"collections-error",children:[i," ",s.jsx("button",{onClick:()=>a(null),className:"coll-dismiss",children:"×"})]}),s.jsxs("div",{className:"collections-layout",children:[s.jsxs("div",{className:"collections-sidebar",children:[t.map(O=>s.jsxs("button",{className:`coll-sidebar-row${o===O.collection_uid?" is-active":""}`,onClick:()=>u(O.collection_uid),children:[s.jsx("span",{className:"coll-row-name",children:O.name}),s.jsx("span",{className:"coll-row-meta",children:tg(O.default_visibility_bits)})]},O.collection_uid)),t.length===0&&!r&&s.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),ne?s.jsxs("div",{className:"coll-detail",children:[s.jsxs("div",{className:"coll-detail-header",children:[L?s.jsx("input",{ref:Oe,className:"coll-rename-input",value:K,onChange:O=>te(O.target.value),onBlur:Dt,onKeyDown:O=>{O.key==="Enter"&&Dt(),O.key==="Escape"&&V(!1)}}):s.jsxs("h3",{className:`coll-detail-name${we?"":" coll-detail-name--editable"}`,title:we?void 0:"Click to rename",onClick:()=>{we||(te(ne.name),V(!0))},children:[(d==null?void 0:d.name)??ne.name,!we&&s.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!we&&s.jsx("button",{className:"coll-delete-btn",onClick:Ct,title:"Delete collection",children:"Delete"})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Entries' default visibility"}),s.jsx("select",{className:"coll-vis-select",value:(d==null?void 0:d.default_visibility_bits)??ne.default_visibility_bits,onChange:O=>_t(Number(O.target.value)),children:Ar.map(O=>s.jsx("option",{value:O.value,children:O.label},O.value))})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Collection access"}),s.jsxs("label",{className:"coll-auth-label",children:[s.jsx("input",{type:"checkbox",checked:!!((d==null?void 0:d.requires_auth)??ne.requires_auth),onChange:O=>Fe(O.target.checked)})," Require authentication to view"]})]}),s.jsxs("div",{className:"coll-entries-section",children:[s.jsx("div",{className:"coll-section-heading",children:"Entries"}),g&&s.jsx("div",{className:"muted",children:"Loading…"}),v&&s.jsx("div",{className:"collections-error",children:v}),!g&&d&&(d.entries.length===0?s.jsx("div",{className:"muted",children:"No entries in this collection."}):s.jsx("ul",{className:"coll-entries-list",children:d.entries.map(O=>s.jsxs("li",{className:"coll-entry-row",children:[s.jsxs("div",{className:"coll-entry-info",children:[s.jsx("span",{className:"coll-entry-title",children:O.title||O.entry_uid}),s.jsx("span",{className:"coll-entry-kind muted",children:O.source_kind})]}),s.jsxs("div",{className:"coll-entry-actions",children:[s.jsx("select",{className:"coll-entry-vis-select",value:O.collection_visibility_bits,onChange:J=>Et(O.entry_uid,Number(J.target.value)),children:Ar.map(J=>s.jsx("option",{value:J.value,children:J.label},J.value))}),!we&&s.jsx("button",{className:"coll-entry-remove",onClick:()=>st(O.entry_uid),title:"Remove from collection",children:"×"})]})]},O.entry_uid))}))]}),!we&&s.jsxs("form",{className:"coll-add-entry-form",onSubmit:mt,children:[s.jsx("div",{className:"coll-section-heading",children:"Add entry"}),s.jsxs("div",{className:"coll-add-entry-row",children:[s.jsx("input",{className:"coll-add-entry-input",type:"text",value:G,onChange:O=>H(O.target.value),placeholder:"entry_uid",required:!0}),s.jsx("select",{className:"coll-vis-select",value:Z,onChange:O=>re(Number(O.target.value)),children:Ar.map(O=>s.jsx("option",{value:O.value,children:O.label},O.value))}),s.jsx("button",{className:"coll-add-btn",type:"submit",disabled:ce,children:ce?"…":"Add"})]}),ye&&s.jsx("div",{className:"collections-error",style:{marginTop:4},children:ye})]})]}):s.jsx("div",{className:"coll-detail coll-detail--empty",children:s.jsx("div",{className:"muted",children:"Select a collection to view details."})})]}),s.jsxs("details",{className:"coll-create-details",children:[s.jsx("summary",{children:"+ Create collection"}),s.jsxs("form",{className:"coll-create-form",onSubmit:$t,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),s.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:S,onChange:O=>{N(O.target.value),p||f(O.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),s.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:p,onChange:O=>f(O.target.value),placeholder:"my-collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Entries' default visibility"}),s.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:m,onChange:O=>k(Number(O.target.value)),children:Ar.map(O=>s.jsx("option",{value:O.value,children:O.label},O.value))})]}),s.jsx("div",{className:"form-field",children:s.jsxs("label",{className:"form-label",children:[s.jsx("input",{type:"checkbox",checked:T,onChange:O=>j(O.target.checked)})," Require authentication to view"]})}),P&&s.jsx("div",{className:"collections-error",children:P}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"Creating…":"Create collection"})]})]})]}):s.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const rg=4;function lg({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=c.useContext(Us)??{},i=r&&(r.role_bits&rg)!==0,a=["profile","tokens",...i?["instance","cookies","extensions","storage"]:[]],o={profile:"Profile",tokens:"API Tokens",instance:"Instance",cookies:"Cookies",extensions:"Extensions",storage:"Storage"};return s.jsxs("section",{className:"admin-view",children:[s.jsx("h1",{children:"Settings"}),s.jsx("div",{className:"view-tabs",children:a.map(u=>s.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:o[u]},u))}),e==="profile"&&s.jsx(sg,{currentUser:r,setCurrentUser:l}),e==="tokens"&&s.jsx(ig,{}),e==="instance"&&i&&s.jsx(ag,{}),e==="cookies"&&i&&s.jsx(ug,{}),e==="extensions"&&i&&s.jsx(cg,{}),e==="storage"&&i&&s.jsx(og,{archiveId:n})]})}function sg({currentUser:e,setCurrentUser:t}){const[n,r]=c.useState((e==null?void 0:e.display_name)??""),[l,i]=c.useState(!1),[a,o]=c.useState(null),[u,d]=c.useState(""),[y,g]=c.useState(""),[h,v]=c.useState(""),[x,S]=c.useState(!1),[N,p]=c.useState(null);async function f(k){k.preventDefault(),i(!0),o(null);try{await sm(n),t(E=>({...E,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(E){o({ok:!1,text:E.message})}finally{i(!1)}}async function m(k){if(k.preventDefault(),y!==h){p({ok:!1,text:"Passwords do not match."});return}S(!0),p(null);try{await am(u,y),d(""),g(""),v(""),p({ok:!0,text:"Password changed."})}catch(E){p({ok:!1,text:E.message})}finally{S(!1)}}return s.jsxs("div",{style:{maxWidth:440},children:[s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Display Name"}),s.jsxs("form",{onSubmit:f,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),s.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:k=>r(k.target.value)})]}),a&&s.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Display Preferences"}),s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async k=>{const E=k.target.checked;try{await im({humanize_slugs:E}),t(b=>({...b,humanize_slugs:E}))}catch{}}}),s.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),s.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Change Password"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),s.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:k=>d(k.target.value),required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),s.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:y,onChange:k=>g(k.target.value),required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),s.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:h,onChange:k=>v(k.target.value),required:!0})]}),N&&s.jsx("div",{className:`form-msg form-msg--${N.ok?"ok":"err"}`,children:N.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Changing…":"Change Password"})]})]})]})}function ig(){const[e,t]=c.useState([]),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState(""),[u,d]=c.useState(!1),[y,g]=c.useState(null),h=c.useCallback(async()=>{r(!0),i(null);try{t(await om())}catch(S){i(S.message)}finally{r(!1)}},[]);c.useEffect(()=>{h()},[h]);async function v(S){if(S.preventDefault(),!!a.trim()){d(!0);try{const N=await um(a.trim());g(N),o(""),h()}catch(N){i(N.message)}finally{d(!1)}}}async function x(S){try{await cm(S),t(N=>N.filter(p=>p.token_uid!==S))}catch(N){i(N.message)}}return s.jsx("div",{style:{maxWidth:600},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"API Tokens"}),y&&s.jsxs("div",{className:"token-banner",children:[s.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",s.jsx("code",{children:y.raw_token}),s.jsx("button",{className:"token-dismiss",onClick:()=>g(null),children:"Dismiss"})]}),s.jsxs("form",{className:"token-create-row",onSubmit:v,children:[s.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:S=>o(S.target.value),required:!0}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&s.jsx("div",{className:"form-msg form-msg--err",children:l}),n?s.jsx("div",{className:"muted",children:"Loading…"}):s.jsxs("div",{children:[e.length===0&&s.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(S=>s.jsxs("div",{className:"token-row",children:[s.jsxs("div",{className:"token-row-info",children:[s.jsx("strong",{children:S.name}),s.jsxs("div",{className:"muted",children:["Created ",S.created_at.slice(0,10),S.last_used_at&&` · Last used ${S.last_used_at.slice(0,10)}`]})]}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>x(S.token_uid),children:"Revoke"})]},S.token_uid))]})]})})}function ag(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState(!1),[u,d]=c.useState(null);c.useEffect(()=>{(async()=>{try{t(await fo())}catch(g){i(g.message)}finally{r(!1)}})()},[]);async function y(g){g.preventDefault(),o(!0),d(null);try{await Yl(e),d({ok:!0,text:"Saved."})}catch(h){d({ok:!1,text:h.message})}finally{o(!1)}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):e?s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Instance Settings"}),s.jsxs("form",{onSubmit:y,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([g,h])=>s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:!!e[g],onChange:v=>t(x=>({...x,[g]:v.target.checked}))}),h]},g)),s.jsxs("div",{className:"form-field",style:{marginTop:4},children:[s.jsx("label",{className:"form-label",children:"Default entry visibility"}),s.jsxs("select",{className:"field-input",value:e.default_entry_visibility,onChange:g=>t(h=>({...h,default_entry_visibility:Number(g.target.value)})),children:[s.jsx("option",{value:0,children:"Private"}),s.jsx("option",{value:2,children:"Unlisted"}),s.jsx("option",{value:3,children:"Public"})]})]}),u&&s.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:a,children:a?"Saving…":"Save Settings"})]})]})}):null}function ki(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,n)).toFixed(n===0?0:1)} ${t[n]}`}function og({archiveId:e}){const[t,n]=c.useState("idle"),[r,l]=c.useState(null),[i,a]=c.useState(null),[o,u]=c.useState(null);function d(){n("idle"),l(null),a(null),u(null)}async function y(){n("scanning"),u(null),l(null);try{const v=await km(e);l(v),n("scanned")}catch(v){u(v.message),n("error")}}async function g(){n("deleting"),u(null);try{const v=await jm(e);a(v),n("done")}catch(v){u(v.message),n("error")}}const h=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Orphan Cleanup"}),s.jsxs("p",{className:"muted",style:{marginBottom:16},children:["Scan for blob files and database records that are no longer referenced by any archive entry and safely delete them."," ",s.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&s.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&s.jsx("button",{className:"btn-ghost",onClick:y,children:"Scan for orphaned blobs"}),t==="scanning"&&s.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&h&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Done"})]}),t==="scanned"&&r&&!h&&s.jsxs("div",{children:[s.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",s.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",s.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",s.jsx("strong",{children:ki(r.total_bytes)})," recoverable."]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsxs("button",{className:"btn-danger",onClick:g,children:["Delete (",ki(r.total_bytes),")"]}),s.jsx("button",{className:"btn-ghost",onClick:d,children:"Cancel"})]})]}),t==="deleting"&&s.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&i&&s.jsxs("div",{children:[s.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",s.jsx("strong",{children:ki(i.freed_bytes)})," ","— removed ",i.deleted_files," file",i.deleted_files!==1?"s":""," ","and ",i.deleted_blob_rows," DB record",i.deleted_blob_rows!==1?"s":"","."]}),i.errors&&i.errors.length>0&&s.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[i.errors.length," file",i.errors.length!==1?"s":""," could not be deleted."]}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Scan again"})]}),t==="error"&&s.jsxs("div",{children:[s.jsx("div",{className:"form-msg form-msg--err",children:o}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Try again"})]})]})})}function ug(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState("global"),[u,d]=c.useState(""),[y,g]=c.useState("{}"),[h,v]=c.useState(null),[x,S]=c.useState(!1),[N,p]=c.useState({});c.useEffect(()=>{f()},[]);async function f(){r(!0),i(null);try{t(await _m())}catch(j){i(j.message)}finally{r(!1)}}async function m(j){j.preventDefault();try{JSON.parse(y)}catch{v({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}S(!0),v(null);try{await Cm(a==="global"?null:u.trim(),a,y),d(""),g("{}"),o("global"),v({ok:!0,text:"Rule added."}),await f()}catch(P){v({ok:!1,text:P.message})}finally{S(!1)}}async function k(j){try{await bm(j),await f()}catch(P){i(P.message)}}function E(j){p(P=>({...P,[j.rule_uid]:{cookiesInput:j.cookies_json,saving:!1,msg:null}}))}function b(j){p(P=>{const R={...P};return delete R[j],R})}async function T(j){const P=N[j.rule_uid];try{JSON.parse(P.cookiesInput)}catch{p(R=>({...R,[j.rule_uid]:{...R[j.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}p(R=>({...R,[j.rule_uid]:{...R[j.rule_uid],saving:!0,msg:null}}));try{await Em(j.rule_uid,{cookies_json:P.cookiesInput}),b(j.rule_uid),await f()}catch(R){p(G=>({...G,[j.rule_uid]:{...G[j.rule_uid],saving:!1,msg:{ok:!1,text:R.message}}}))}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):s.jsx("div",{style:{maxWidth:560},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Cookie Rules"}),s.jsx("p",{className:"muted",style:{marginBottom:12},children:"Cookies are injected into every capture network request (yt-dlp, HTTP downloads, web-page snapshots). Global rules apply to all URLs; wildcard and regex rules apply only to matching URLs."}),e&&e.length>0?s.jsxs("table",{className:"data-table",style:{width:"100%",marginBottom:16},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Pattern"}),s.jsx("th",{children:"Cookies"}),s.jsx("th",{style:{width:100},children:"Actions"})]})}),s.jsx("tbody",{children:e.map(j=>{const P=N[j.rule_uid],R=j.url_pattern?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted",children:[j.pattern_kind,":"]})," ",s.jsx("code",{children:j.url_pattern})]}):s.jsx("span",{className:"muted",children:"global (all URLs)"});return s.jsxs("tr",{children:[s.jsx("td",{children:R}),s.jsx("td",{children:P?s.jsxs(s.Fragment,{children:[s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:P.cookiesInput,onChange:G=>p(H=>({...H,[j.rule_uid]:{...H[j.rule_uid],cookiesInput:G.target.value}}))}),P.msg&&s.jsx("div",{className:`form-msg form-msg--${P.msg.ok?"ok":"err"}`,children:P.msg.text}),s.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[s.jsx("button",{className:"btn-primary",style:{fontSize:12,padding:"2px 8px"},disabled:P.saving,onClick:()=>T(j),children:P.saving?"Saving…":"Save"}),s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>b(j.rule_uid),children:"Cancel"})]})]}):s.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:j.cookies_json})}),s.jsx("td",{children:!P&&s.jsxs("div",{style:{display:"flex",gap:6},children:[s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>E(j),children:"Edit"}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>k(j.rule_uid),children:"Del"})]})})]},j.rule_uid)})})]}):s.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),s.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Pattern type"}),s.jsxs("select",{className:"field-input",value:a,onChange:j=>o(j.target.value),children:[s.jsx("option",{value:"global",children:"Global (all URLs)"}),s.jsx("option",{value:"wildcard",children:"Wildcard (e.g. *.youtube.com)"}),s.jsx("option",{value:"regex",children:"Regex (matched against full URL)"})]})]}),a!=="global"&&s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:a==="wildcard"?"URL/hostname pattern":"Regex pattern"}),s.jsx("input",{className:"field-input",type:"text",value:u,onChange:j=>d(j.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:y,onChange:j=>g(j.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),h&&s.jsx("div",{className:`form-msg form-msg--${h.ok?"ok":"err"}`,children:h.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Adding…":"Add Rule"})]})]})})}function cg(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(!1),[a,o]=c.useState(null);c.useEffect(()=>{(async()=>{try{t(await fo())}catch(N){o({ok:!1,text:N.message})}finally{r(!1)}})()},[]);async function u(N){i(!0),o(null);try{await Yl({ublock_enabled:N}),t(p=>({...p,ublock_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function d(N){i(!0),o(null);try{await Yl({cookie_ext_enabled:N}),t(p=>({...p,cookie_ext_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function y(N){i(!0),o(null);try{await Yl({modal_closer_enabled:N}),t(p=>({...p,modal_closer_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}if(n)return s.jsx("div",{className:"muted",children:"Loading\\u2026"});const g=(e==null?void 0:e.ublock_ext_available)??!1,h=(e==null?void 0:e.ublock_enabled)??!0,v=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0,S=(e==null?void 0:e.modal_closer_enabled)??!0;return s.jsx("div",{children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Extensions"}),s.jsx("p",{className:"form-hint",style:{marginBottom:20},children:"Extensions run inside the browser during WebPage captures and can block ads, accept cookie banners, and more. Changes take effect on the next capture."}),s.jsxs("div",{className:"ext-grid",children:[s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"uBlock Origin Lite"}),s.jsx("span",{className:"ext-card-desc",children:"Blocks ads, trackers, and other page clutter during archiving via Chrome’s declarativeNetRequest API (Manifest V3)."}),!g&&s.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_UBLOCK_EXT"})," to the unpacked extension directory to enable."]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":h,className:`ext-toggle${h?" ext-toggle--on":""}`,onClick:()=>u(!h),disabled:l,"aria-label":"Toggle uBlock Origin Lite",children:s.jsx("span",{className:"ext-toggle-knob"})})]})}),s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"I Still Don’t Care About Cookies"}),s.jsx("span",{className:"ext-card-desc",children:"Dismiss cookie consent banners during archiving."}),!v&&s.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})," to the unpacked extension directory to enable."]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":x,className:`ext-toggle${x?" ext-toggle--on":""}`,onClick:()=>d(!x),disabled:l,"aria-label":"Toggle I Still Don't Care About Cookies",children:s.jsx("span",{className:"ext-toggle-knob"})})]})}),s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"Modal & Dialog Closer"}),s.jsx("span",{className:"ext-card-desc",children:"Auto-dismiss cookie banners, consent overlays, and other modal dialogs before a WebPage capture is taken. Implemented as an injected browser script; no external extension required."})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":S,className:`ext-toggle${S?" ext-toggle--on":""}`,onClick:()=>y(!S),disabled:l,"aria-label":"Toggle Modal and Dialog Closer",children:s.jsx("span",{className:"ext-toggle-knob"})})]})})]}),a&&s.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text})]})})}const zu={0:"Private",1:"Public",2:"Users only",3:"Public"},Zl=[{value:"anthropic_http",label:"Anthropic API"},{value:"openai_compatible",label:"OpenAI-compatible API"},{value:"claude_cli",label:"Claude CLI"},{value:"codex_cli",label:"Codex CLI"}],dg=Object.fromEntries(Zl.map(e=>[e.value,e.label])),Iu="archivr:summary:provider",fg=1500;function pg(e){if(!e)return null;try{const t=JSON.parse(e);if(t&&typeof t=="object")return{tldr:typeof t.tldr=="string"?t.tldr:"",summary:typeof t.summary=="string"?t.summary:"",tags:Array.isArray(t.tags)?t.tags.filter(n=>typeof n=="string"):[]}}catch{}return{tldr:"",summary:e,tags:[]}}const hg=()=>s.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function mg({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:d,onBulkDeleted:y,humanizeTags:g,onDetailRefresh:h,onOpenPreview:v,onPlay:x,isPublicSession:S}){var q,Y,se;const[N,p]=c.useState([]),[f,m]=c.useState(""),[k,E]=c.useState([]),[b,T]=c.useState(""),j=c.useRef(0),P=c.useRef(!1),[R,G]=c.useState(!1),[H,Z]=c.useState(""),[re,ce]=c.useState("idle"),[De,ye]=c.useState(""),A=c.useRef(null),[L,V]=c.useState(!1);c.useEffect(()=>{V(!1)},[(q=l==null?void 0:l.summary)==null?void 0:q.entry_uid]);const[K,te]=c.useState(null),[Oe,ne]=c.useState(""),[we,oe]=c.useState(!1),[Ne,$t]=c.useState(()=>{try{return sessionStorage.getItem(Iu)||Zl[0].value}catch{return Zl[0].value}}),[Dt,_t]=c.useState(!1),Fe=c.useRef(null),Ct=(n==null?void 0:n.size)>=2,[mt,st]=c.useState(""),[Et,O]=c.useState("idle"),[J,ve]=c.useState(""),[Ce,Wt]=c.useState([]),[Re,Bn]=c.useState(""),[tn,gt]=c.useState("idle"),[We,Sn]=c.useState(""),[Nn,w]=c.useState("idle"),[B,M]=c.useState(""),[z,F]=c.useState("idle"),[U,pe]=c.useState("");c.useEffect(()=>{const C=++j.current;if(A.current&&(clearInterval(A.current),A.current=null),ce("idle"),ye(""),!t||!e){p([]),E([]);return}if(S){p([]),E([]);return}G(!1),Z(""),P.current=!1,p([]),Promise.all([Al(e,t.entry_uid),Tu(e,t.entry_uid)]).then(([Q,X])=>{C===j.current&&(p(Q),E(X))}).catch(()=>{})},[t,e,S]),c.useEffect(()=>()=>{clearInterval(A.current)},[]),c.useEffect(()=>{clearInterval(Fe.current),Fe.current=null,te((l==null?void 0:l.latest_summary)??null),ne(""),oe(!1),_t(!1)},[(Y=l==null?void 0:l.summary)==null?void 0:Y.entry_uid]);const de=K==null?void 0:K.status;c.useEffect(()=>{var Q;if(clearInterval(Fe.current),Fe.current=null,de!=="pending"&&de!=="running"||!e||!((Q=l==null?void 0:l.summary)!=null&&Q.entry_uid))return;const C=l.summary.entry_uid;return Fe.current=setInterval(async()=>{var X;try{const at=await Mh(e,C);te(at.summary??null);const Ot=(X=at.summary)==null?void 0:X.status;Ot!=="pending"&&Ot!=="running"&&(clearInterval(Fe.current),Fe.current=null,oe(!1),Ot==="completed"&&(h==null||h()))}catch{}},fg),()=>{clearInterval(Fe.current),Fe.current=null}},[de,e,(se=l==null?void 0:l.summary)==null?void 0:se.entry_uid]),c.useEffect(()=>()=>clearInterval(Fe.current),[]);async function Te(C=!1){var Q;if(!(!e||!((Q=l==null?void 0:l.summary)!=null&&Q.entry_uid)||we)){oe(!0),ne("");try{const X=await Fh(e,l.summary.entry_uid,{provider:Ne,force:C,includeImages:Dt});X.status==="completed"?(te(X),oe(!1),h==null||h()):te({...X??{},status:"pending"})}catch(X){ne(X.message||"Summary request failed"),oe(!1)}}}function he(C){$t(C),C==="claude_cli"&&_t(!1);try{sessionStorage.setItem(Iu,C)}catch{}}c.useEffect(()=>{if(!e){Wt([]);return}po(e).then(Wt).catch(()=>Wt([]))},[e]),c.useEffect(()=>{st(""),O("idle"),ve(""),Bn(""),gt("idle"),Sn(""),w("idle"),M(""),F("idle"),pe("")},[n]);async function Ve(){const C=n.size;if(!window.confirm(`Delete ${C} entr${C===1?"y":"ies"}? This cannot be undone.`))return;w("running");const Q=new Set;for(const X of n)try{await bu(e,X),Q.add(X)}catch{}w("idle"),y==null||y(Q)}async function ie(){const C=mt.trim();if(C){O("running"),ve("");try{for(const Q of n)await Eu(e,Q,C);st(""),O("done"),o==null||o(),setTimeout(()=>O("idle"),1800)}catch(Q){ve(Q.message),O("error")}}}async function it(){if(!Re)return;gt("running"),Sn("");const C=[],Q=Ce.find(X=>X.collection_uid===Re);for(const X of n)try{await ga(e,Re,X,(Q==null?void 0:Q.default_visibility_bits)??2)}catch{C.push(X)}C.length>0?(Sn(`Failed for ${C.length} entr${C.length===1?"y":"ies"}.`),gt("error")):(gt("done"),setTimeout(()=>gt("idle"),1800))}async function yt(){if(!B||!t)return;F("running"),pe("");const C=Ce.find(Q=>Q.collection_uid===B);try{await ga(e,B,t.entry_uid,(C==null?void 0:C.default_visibility_bits)??2),F("done"),M("");const Q=await Tu(e,t.entry_uid);E(Q),setTimeout(()=>F("idle"),1800)}catch(Q){pe(Q.message),F("error")}}async function Hs(){const C=H.trim()||null;try{await Wh(e,t.entry_uid,C),u==null||u(t.entry_uid,C)}catch{}finally{G(!1)}}async function vl(){const C=f.trim();if(!(!C||!t))try{await Eu(e,t.entry_uid,C),m(""),T("");const Q=await Al(e,t.entry_uid);p(Q),o()}catch(Q){T(Q.message)}}async function Ws(C){try{await Vh(e,t.entry_uid,C);const Q=await Al(e,t.entry_uid);p(Q),o()}catch{}}async function Un(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await bu(e,t.entry_uid),d==null||d(t.entry_uid)}catch{}}async function jr(){if(!t||!e||re==="running")return;const C=j.current,Q=t.entry_uid;ce("running"),ye("");try{const{job_uid:X}=await Sm(e,Q);if(j.current!==C)return;A.current=setInterval(async()=>{try{const at=await Zd(e,X);if(at.status==="completed"){if(clearInterval(A.current),A.current=null,j.current!==C)return;ce("done");const Ot=await Al(e,Q);if(j.current!==C)return;p(Ot),h==null||h()}else if(at.status==="failed"){if(clearInterval(A.current),A.current=null,j.current!==C)return;ce("error"),ye(at.error_text||"Re-archive failed.")}}catch{if(clearInterval(A.current),A.current=null,j.current!==C)return;ce("error"),ye("Network error while polling.")}},500)}catch(X){if(j.current!==C)return;ce("error"),ye(X.message||"Failed to start re-archive.")}}const _n=l?[["Added",ho(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",zu[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],xl=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),Vs=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Hn=l?l.artifacts.findIndex(C=>C.artifact_role==="primary_media"):-1,Wn=Hn>=0?l.artifacts[Hn]:null,wl=Wn?Wn.relpath.split(".").pop().toLowerCase():"",_=Wn&&xl.has(wl),I=Hn>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${Hn}`:null,D=l&&!_&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||Wn&&Vs.has(wl));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),Ct?S?s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}):s.jsxs("div",{className:"bulk-panel",children:[s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}),s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Assign tag"}),J&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:J}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:mt,onChange:C=>st(C.target.value),onKeyDown:C=>{C.key==="Enter"&&ie()}}),s.jsx("button",{className:"tag-add-btn",onClick:ie,disabled:Et==="running"||!mt.trim(),children:Et==="running"?"…":Et==="done"?"✓":"Add"})]})]}),Ce.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Add to collection"}),s.jsxs("div",{className:"bulk-coll-row",children:[s.jsxs("select",{className:"bulk-coll-select",value:Re,onChange:C=>Bn(C.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),Ce.filter(C=>C.slug!=="_default_").map(C=>s.jsx("option",{value:C.collection_uid,children:C.name},C.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:it,disabled:!Re||tn==="running",children:tn==="running"?"…":tn==="done"?"✓":tn==="error"?"!":"Add"})]}),We&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:We})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Ve,disabled:Nn==="running",children:Nn==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[S?s.jsx("h2",{className:"rail-title",children:ut(l.summary.title)||ut(l.summary.entry_uid)}):R?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:H,onChange:C=>Z(C.target.value),onKeyDown:C=>{C.key==="Enter"&&C.currentTarget.blur(),C.key==="Escape"&&(P.current=!0,C.currentTarget.blur())},onBlur:()=>{P.current?G(!1):Hs(),P.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{Z(l.summary.title??""),G(!0)},children:[ut(l.summary.title)||ut(l.summary.entry_uid),s.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:s.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),l.summary.original_url&&s.jsxs("a",{className:"url-tile",href:l.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[s.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:Bs(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(hg,{})})]}),_&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>x(I,t),children:"▶ Play"}),D&&v&&s.jsx("button",{className:"rail-preview-btn",onClick:v,children:"Preview"}),(()=>{const C=(K==null?void 0:K.status)==="completed"?pg(K.summary_text):null,Q=(K==null?void 0:K.status)==="pending"||(K==null?void 0:K.status)==="running";return S&&!C?null:s.jsxs("div",{className:"rail-section rail-summary",children:[s.jsx("div",{className:"rail-section-heading",children:"Summary"}),C&&s.jsxs("div",{className:"rail-summary-body",children:[C.tldr&&s.jsx("p",{className:"rail-summary-tldr",children:C.tldr}),C.summary&&s.jsx("p",{className:"rail-summary-text",children:C.summary}),C.tags.length>0&&s.jsx("div",{className:"rail-summary-tags",children:C.tags.map(X=>s.jsx("span",{className:"rail-summary-tag",children:X},X))}),s.jsxs("p",{className:"rail-summary-provider",children:[dg[K.provider_kind]||K.provider_kind,K.provider_model?` · ${K.provider_model}`:""]})]}),Q&&s.jsxs("p",{className:"rail-summary-status",children:[s.jsx("span",{className:"rail-summary-spinner","aria-hidden":"true"}),"Generating…"]}),(K==null?void 0:K.status)==="failed"&&K.error_text&&!S&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:K.error_text}),Oe&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:Oe}),!S&&!Q&&s.jsxs("div",{className:"rail-summary-controls",children:[s.jsx("select",{className:"rail-summary-select",value:Ne,onChange:X=>he(X.target.value),"aria-label":"Summary provider",children:Zl.map(X=>s.jsx("option",{value:X.value,children:X.label},X.value))}),s.jsxs("div",{className:`rail-summary-image-option${Ne==="claude_cli"?" rail-summary-image-option--disabled":""}`,children:[s.jsxs("label",{className:"rail-summary-image-option__label",children:[s.jsx("input",{type:"checkbox",checked:Dt,disabled:Ne==="claude_cli",onChange:X=>_t(X.target.checked)}),"Include attached images"]}),s.jsx("p",{className:"rail-summary-image-option__note",children:Ne==="claude_cli"?"Claude CLI cannot attach local images. Choose an HTTP provider or Codex CLI.":"Selected archived images are sent to the chosen provider. Up to 4 supported images (5 MiB each, 12 MiB total) can be attached; unsupported or oversized artifacts are skipped."})]}),s.jsx("button",{className:"rail-rearchive-btn",onClick:()=>Te(!!C),disabled:we,children:we?"…":C?"Regenerate":"Generate"})]})]})})(),s.jsx("div",{className:"meta-list",children:_n.filter(([,C])=>C!=null&&C!=="").map(([C,Q])=>s.jsxs("div",{className:"meta-item",children:[s.jsx("span",{className:"meta-k",children:C}),s.jsx("span",{className:`meta-v${C==="Root"?" mono":""}`,children:ut(Q)})]},C))}),l.artifacts.length>0&&(()=>{const C=l.artifacts.map((Pe,vt)=>({...Pe,_idx:vt})),Q=C.filter(Pe=>Pe.artifact_role==="font"),X=C.filter(Pe=>Pe.artifact_role!=="font"),at=Q.reduce((Pe,vt)=>Pe+(vt.byte_size||0),0),Ot=l.summary.entry_uid,Sr=Pe=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${Ot}/artifacts/${Pe._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:Pe.artifact_role==="font"?Pe.relpath.split("/").pop():Pe.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:Pe.byte_size!=null?fl(Pe.byte_size):"—"})]})},Pe._idx);return s.jsxs("div",{className:"rail-section",children:[s.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",s.jsx("span",{className:"num",children:l.artifacts.length})]}),s.jsxs("ul",{className:"artifact-list",children:[X.map(Sr),Q.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":L,onClick:()=>V(Pe=>!Pe),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${L?" open":""}`,children:"›"}),` fonts (${Q.length})`]}),s.jsx("span",{className:"artifact-size",children:fl(at)})]}),L&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:Q.map(Sr)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!Ct&&!S&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),N.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:N.map(C=>s.jsxs("span",{className:"tag-pill",title:C.full_path,children:[g?tf(C.full_path):C.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${C.full_path}`,onClick:()=>Ws(C.tag_uid),children:"×"})]},C.tag_uid))}),b&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:b}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:f,onChange:C=>m(C.target.value),onKeyDown:C=>{C.key==="Enter"&&vl()}}),s.jsx("button",{className:"tag-add-btn",onClick:vl,children:"Add"})]})]}),(k.length>0||Ce.filter(C=>C.slug!=="_default_").length>0)&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),k.map(C=>s.jsxs("div",{className:"coll-row",children:[s.jsx("span",{className:"coll-name",children:C.name}),s.jsx("span",{className:"vis-badge",children:zu[C.visibility_bits]??`bits:${C.visibility_bits}`})]},C.collection_uid)),Ce.filter(C=>C.slug!=="_default_").length>0&&s.jsxs("div",{className:"bulk-coll-row",style:{marginTop:8},children:[s.jsxs("select",{className:"bulk-coll-select",value:B,onChange:C=>M(C.target.value),children:[s.jsx("option",{value:"",children:"Add to collection…"}),Ce.filter(C=>C.slug!=="_default_").map(C=>s.jsx("option",{value:C.collection_uid,children:C.name},C.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:yt,disabled:!B||z==="running",children:z==="running"?"…":z==="done"?"✓":z==="error"?"!":"Add"})]}),U&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"4px 0 0"},children:U})]}),l&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread")&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Actions"}),s.jsx("button",{className:"rail-rearchive-btn",onClick:jr,disabled:re==="running",children:re==="running"?"Re-archiving…":"Re-archive"}),re==="done"&&s.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),re==="error"&&s.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:De})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Un,children:"Delete entry"})})]})]})}const gg=/\/api\/archives\/([^/]+)\/entries\/([^/]+)\/artifacts\/(\d+)/;function yg(){return s.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[s.jsx("path",{d:"M5 17H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2"}),s.jsx("polygon",{points:"12 15 17 21 7 21 12 15"})]})}function vg({src:e,contentType:t="video/mp4"}){const n=c.useRef(null),[r,l]=c.useState(null),[i,a]=c.useState(!1),[o,u]=c.useState(!1);c.useEffect(()=>{if(!e){l(null);return}const g=e.match(gg);if(!g){l(e);return}let h=!1;return l(null),Nm(g[1],g[2],parseInt(g[3],10)).then(({url:v})=>{h||l(v)}).catch(()=>{h||l(e)}),()=>{h=!0}},[e]),c.useEffect(()=>{n.current&&n.current.load()},[r]),c.useEffect(()=>{u(typeof HTMLVideoElement<"u"&&"webkitShowPlaybackTargetPicker"in HTMLVideoElement.prototype)},[]),c.useEffect(()=>{var h;const g=v=>{if(v)try{cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),a(!0)}catch{}};if((h=window.cast)!=null&&h.framework)g(!0);else if(window.__onGCastApiAvailable=g,!document.querySelector('script[src*="cast_sender"]')){const v=document.createElement("script");v.src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",document.head.appendChild(v)}},[]),c.useEffect(()=>{if(!i||!r)return;const g=cast.framework.CastContext.getInstance(),{CastContextEventType:h,SessionState:v}=cast.framework,x=N=>{if(!N)return;const p=new chrome.cast.media.MediaInfo(window.location.origin+r,t);N.loadMedia(new chrome.cast.media.LoadRequest(p)).catch(()=>{})};x(g.getCurrentSession());const S=N=>{(N.sessionState===v.SESSION_STARTED||N.sessionState===v.SESSION_RESUMED)&&x(g.getCurrentSession())};return g.addEventListener(h.SESSION_STATE_CHANGED,S),()=>g.removeEventListener(h.SESSION_STATE_CHANGED,S)},[i,r,t]);const d=()=>{var g,h;(h=(g=n.current)==null?void 0:g.webkitShowPlaybackTargetPicker)==null||h.call(g)},y=i||o;return s.jsx("div",{className:"preview-video-wrap",style:{position:"relative"},children:e?s.jsxs(s.Fragment,{children:[r?s.jsxs("video",{ref:n,controls:!0,autoPlay:!1,playsInline:!0,"x-webkit-airplay":"allow",style:{width:"100%",maxHeight:"100%",display:"block"},children:[s.jsx("source",{src:r}),"Your browser does not support the video element."]}):s.jsx("div",{className:"video-tv-loading","aria-label":"Loading video…"}),y&&r&&s.jsxs("div",{className:"video-tv-controls",children:[o&&s.jsx("button",{className:"video-tv-btn",title:"AirPlay to device","aria-label":"AirPlay to device",onClick:d,children:s.jsx(yg,{})}),i&&s.jsx("google-cast-launcher",{className:"video-tv-btn",title:"Cast to TV"})]})]}):s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function $u({src:e,type:t,title:n,originalUrl:r}){const l=r||e,i=n||null;return s.jsxs("div",{className:"preview-iframe-wrap",style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[s.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",flexDirection:"column",gap:"2px",padding:"6px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[i&&s.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--ink)",fontFamily:"var(--sans)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.78rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:l}),s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.78rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)",flexShrink:0},children:t==="pdf"?"Open PDF ↗":"Open in new tab ↗"})]})]}),s.jsx("iframe",{src:e,sandbox:"allow-same-origin allow-popups",allow:"autoplay 'none'",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%",minHeight:0},title:i||(t==="pdf"?"PDF preview":"Page preview")})]})}function xg({src:e,alt:t}){return s.jsx("div",{className:"preview-image-wrap",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",background:"var(--paper-2)",overflow:"hidden"},children:s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{display:"contents"},children:s.jsx("img",{src:e,alt:t||"",style:{objectFit:"contain",maxHeight:"100%",maxWidth:"100%",display:"block",cursor:"pointer"}})})})}function sf(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function Du(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const ee={card:{background:"var(--paper)",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},threadOuter:{border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},tweetRow:{display:"flex",gap:"10px",padding:"10px 12px"},tweetRowThread:{display:"flex",gap:"10px",padding:"10px 12px 0"},leftCol:{display:"flex",flexDirection:"column",alignItems:"center",flexShrink:0,width:"36px"},rightCol:{flex:1,minWidth:0,paddingBottom:"8px"},avatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},avatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},threadLine:{flex:1,width:"2px",background:"var(--line-soft, var(--line))",margin:"4px 0",minHeight:"12px",borderRadius:"1px"},authorRow:{display:"flex",alignItems:"baseline",gap:"4px",flexWrap:"wrap",marginBottom:"4px",lineHeight:"1.3"},authorName:{fontWeight:"700",fontSize:"14px",color:"var(--ink)"},authorHandle:{fontSize:"13px",color:"var(--muted)"},datePart:{fontSize:"13px",color:"var(--muted)"},tweetText:{fontSize:"14px",lineHeight:"1.5",color:"var(--ink)",whiteSpace:"pre-line",marginBottom:"8px",wordBreak:"break-word"},stats:{display:"flex",gap:"12px",fontSize:"13px",color:"var(--muted)"},link:{color:"var(--accent)",textDecoration:"none"},loading:{padding:"24px 16px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},error:{padding:"24px 16px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},mediaGrid:{marginBottom:"8px",borderRadius:"10px",overflow:"hidden",border:"1px solid var(--line)"},mediaImg:{display:"block",width:"100%",objectFit:"cover",maxHeight:"260px"},mediaVideo:{display:"block",width:"100%",maxHeight:"260px",background:"#000"},article:{maxWidth:"560px",margin:"0 auto",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"280px"},aMeta:{padding:"10px 14px 0"},aTweetTitle:{fontSize:"20px",fontWeight:"800",letterSpacing:"-0.3px",color:"var(--ink)",lineHeight:"1.3",marginBottom:"8px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},aAvatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},aAuthorName:{fontSize:"14px",fontWeight:"700",color:"var(--ink)",lineHeight:"1.3"},aAuthorSub:{fontSize:"13px",color:"var(--muted)",lineHeight:"1.3"},aDivider:{border:"none",borderTop:"1px solid var(--line)",margin:"0"},aBody:{padding:"4px 14px 16px"},bH1:{fontSize:"22px",fontWeight:"800",letterSpacing:"-0.4px",color:"var(--ink)",lineHeight:"1.25",margin:"16px 0 6px"},bH2:{fontSize:"18px",fontWeight:"700",letterSpacing:"-0.2px",color:"var(--ink)",lineHeight:"1.3",margin:"14px 0 4px"},bP:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.65",marginBottom:"12px",marginTop:"0"},bSpacer:{height:"4px",display:"block"},bQuote:{borderLeft:"3px solid var(--line)",padding:"2px 12px",margin:"12px 0",color:"var(--muted)",fontSize:"15px",lineHeight:"1.6"},bHr:{border:"none",borderTop:"1px solid var(--line)",margin:"14px 0"},bImg:{width:"100%",display:"block",borderRadius:"8px",margin:"12px 0"},bUl:{margin:"8px 0 12px",paddingLeft:"24px"},bOl:{margin:"8px 0 12px",paddingLeft:"24px"},bLi:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.6",marginBottom:"4px"},bTweet:{display:"flex",alignItems:"center",gap:"10px",border:"1px solid var(--line)",borderRadius:"10px",padding:"10px 14px",margin:"12px 0",color:"var(--muted)",fontSize:"14px",textDecoration:"none"},bMdPre:{borderRadius:"8px",margin:"10px 0",overflow:"auto",background:"var(--paper-3, var(--field))",padding:"12px 14px"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"12px",lineHeight:"1.6",color:"var(--ink)",background:"transparent",display:"block"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:"var(--paper-3, var(--field))",padding:"1px 5px",borderRadius:"4px",color:"var(--ink)"},qtBadge:{fontSize:"11px",color:"var(--muted)",display:"inline-flex",alignItems:"center",gap:"2px",marginLeft:"4px",letterSpacing:"0.03em",flexShrink:0},lightboxBackdrop:{position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.92)",display:"flex",alignItems:"center",justifyContent:"center",padding:"20px"},lightboxContent:{display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",maxWidth:"90vw",maxHeight:"90vh"},lightboxToolbar:{display:"flex",alignItems:"center",gap:"10px",alignSelf:"flex-end"},lightboxImg:{maxWidth:"88vw",maxHeight:"80vh",objectFit:"contain",borderRadius:"6px",display:"block"},lightboxNav:{display:"flex",gap:"12px",alignItems:"center"},lightboxNavBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"20px",cursor:"pointer",borderRadius:"50%",width:"36px",height:"36px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"16px",cursor:"pointer",borderRadius:"50%",width:"30px",height:"30px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxLink:{color:"rgba(255,255,255,0.7)",textDecoration:"none",fontSize:"14px"},lightboxCounter:{color:"rgba(255,255,255,0.6)",fontSize:"13px"}},ze={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},ji={article:{background:ze.bg,color:ze.text,minHeight:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'},articleInner:{maxWidth:"598px",margin:"0 auto",paddingBottom:"80px"},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"420px"},aMeta:{padding:"20px 16px 0"},aTweetTitle:{fontSize:"34px",fontWeight:"800",letterSpacing:"-0.5px",color:ze.text,lineHeight:"44px",marginBottom:"16px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"16px"},aAvatar:{width:"40px",height:"40px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"40px",height:"40px",borderRadius:"50%",background:ze.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:ze.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:ze.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${ze.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:ze.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:ze.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:ze.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${ze.border}`,padding:"2px 14px",margin:"14px 0",color:ze.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${ze.border}`,margin:"28px 0"},bImg:{width:"100%",display:"block",borderRadius:"12px",margin:"16px 0"},bUl:{margin:"10px 0 16px",paddingLeft:"28px"},bOl:{margin:"10px 0 16px",paddingLeft:"28px"},bLi:{fontSize:"17px",color:ze.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${ze.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:ze.dim,fontSize:"15px",textDecoration:"none"},bMdPre:{borderRadius:"12px",margin:"12px 0",overflow:"auto",background:"#1e2029"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"13px",lineHeight:"1.65",padding:"18px 20px",display:"block",color:ze.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:ze.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:ze.accent,textDecoration:"none"}};function wg(e,t,n){const r={};return n&&n.forEach((l,i)=>{l.relpath&&(r[l.relpath]=`/api/archives/${e}/entries/${t}/artifacts/${i}`)}),r}function dr(e,t,n){return e&&n[e]?n[e]:t||null}function af(){return s.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",style:{flexShrink:0,color:"var(--ink)"},children:s.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.748l7.73-8.835L1.254 2.25H8.08l4.259 5.63L18.244 2.25zm-1.161 17.52h1.833L7.084 4.126H5.117L17.083 19.77z"})})}function mo(e,t,...n){var r;if(e.fromIndex!=null&&e.toIndex!=null)return{s:e.fromIndex,e:e.toIndex};if(((r=e.indices)==null?void 0:r.length)===2)return{s:e.indices[0],e:e.indices[1]};if(t)for(const l of n){if(!l)continue;const i=t.indexOf(l);if(i!==-1)return{s:i,e:i+l.length}}return null}function of(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=mo(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function uf(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=mo(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const Ou=/https?:\/\/[^\s<>"'\])]+/g,kg=/[.,;:!?)()]+$/;function Ns(e,t){const n=[];let r=0,l;for(Ou.lastIndex=0;(l=Ou.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(kg,"");n.push(s.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:t,children:i},l.index));const a=l[0].slice(i.length);a&&n.push(a),r=l.index+l[0].length}return r===0?e:(rof(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>uf(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return Ns(Du(e),ee.link);const l=new Set([0,e.length]);for(const o of r)o.s>=0&&o.s<=e.length&&l.add(o.s),o.e>=0&&o.e<=e.length&&l.add(o.e);for(const[o,u]of n)o>=0&&o<=e.length&&l.add(o),u>=0&&u<=e.length&&l.add(u);const i=(o,u)=>n.some(([d,y])=>d<=o&&y>=u),a=[...l].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const d=a[u+1];if(i(o,d))return null;const y=e.slice(o,d),g=r.filter(x=>x.s<=o&&x.e>=d),h=g.find(x=>x.kind==="url");if(h)return s.jsx("a",{href:h.href,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:h.display||y},u);const v=g.find(x=>x.kind==="mention");return v?s.jsx("a",{href:`https://x.com/${v.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:y},u):s.jsx("span",{children:Ns(Du(y),ee.link)},u)}).filter(o=>o!==null)}function Sg(e,t,n,r,l=ee){if(!e)return null;t=t||[],n=n||[],r=r||[];const i=[];for(const u of t)u.length>0&&i.push({s:u.offset,e:u.offset+u.length,kind:"style",style:u.style});for(const u of n){const d=of(u,e);d&&i.push(d)}for(const u of r){const d=uf(u,e);d&&i.push(d)}if(i.length===0)return Ns(e,l.link);const a=new Set([0,e.length]);for(const u of i)u.s>=0&&u.s<=e.length&&a.add(u.s),u.e>=0&&u.e<=e.length&&a.add(u.e);const o=[...a].sort((u,d)=>u-d);return o.slice(0,-1).map((u,d)=>{const y=o[d+1],g=i.filter(N=>N.s<=u&&N.e>=y),h=e.slice(u,y);let v;if(h.includes(`
+`)}`),Pe.length>0&&ie.push(`With warnings:
+${Pe.map(yt=>` ${yt}`).join(`
+`)}`);const at=ie.length>0?ie.join(`
+`):null;E.current(at,null,Qe,he)}async function _e(w,B){var Pe,he,Qe;const M=v.current,z=((Pe=crypto.randomUUID)==null?void 0:Pe.call(crypto))??`job-${Date.now()}-${Math.random()}`;if(w.type==="text"){try{const ie=await em(M,{title:w.title,body:w.body,mime:w.mime}),at=`text:${w.title}`;(he=b.current)==null||he.call(b,{id:z,jobUid:ie.job_uid,locator:at,archiveId:M}),ke(z,ie.job_uid,at,M,B)}catch(ie){const at=ie.message||"Submission failed.";E.current(at,`text:${w.title}`),oe(B,"failed",`text:${w.title}`)}return}const F=w.locator,U=w.quality,pe=w.extraExtensions||{},de={ublock_enabled:te,reader_mode:ze,cookie_ext_enabled:Ae,modal_closer_enabled:A,via_freedium:V,...pe};try{const ie=await Zh(M,F,U,de);(Qe=b.current)==null||Qe.call(b,{id:z,jobUid:ie.job_uid,locator:F,archiveId:M}),ke(z,ie.job_uid,F,M,B)}catch(ie){const at=ie.message||"Submission failed.";E.current(at,F),oe(B,"failed",F),F.startsWith("file://")&&ie.status&&wi(M,F).catch(()=>{})}}function $t(){var z,F;if(j.some(U=>U.kind==="file"&&U.uploadStatus==="uploading"))return;const w=j.filter(U=>U.kind==="file"?U.uploadStatus==="done"&&U.uploadLocator:U.kind==="text"?U.title.trim()&&U.body.trim():U.locator.trim());if(w.length===0||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&Pu(U))||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&(U.probeState==="probing"||Ln(U.locator)&&U.playlistProbeState!=="done"))||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&Array.isArray(U.playlistItems)&&U.playlistItems.length===0))return;const B=w.length>1?((z=crypto.randomUUID)==null?void 0:z.call(crypto))??`batch-${Date.now()}`:null;B&&h.current.set(B,{total:w.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]});const M=w.map(U=>U.kind==="file"?{type:"file",locator:U.uploadLocator,quality:"best",extraExtensions:{}}:U.kind==="text"?{type:"text",title:U.title.trim(),body:U.body.trim(),mime:U.mime}:{type:"url",locator:U.locator.trim(),quality:U.playlistItems!==null?null:U.quality||"best",extraExtensions:U.playlistItems!==null?{per_item_quality:Object.fromEntries(U.playlistItems.map(pe=>[pe.id,pe.quality])),sync:U.syncEnabled}:{}});f.current=!0,P([Qn()]),(F=u.current)==null||F.close(),M.forEach(U=>_e(U,B))}function Dt(){P(w=>[...w,Qn()])}function _t(w){var M;clearTimeout(g.current.get(w)),g.current.delete(w);const B=p.current.find(z=>z.id===w);(B==null?void 0:B.kind)==="file"&&(B.uploadStatus==="uploading"?((M=m.current.get(w))==null||M(),m.current.delete(w)):B.uploadStatus==="done"&&B.uploadLocator&&wi(v.current,B.uploadLocator).catch(()=>{})),P(z=>{const F=z.filter(U=>U.id!==w);return F.length===0?[Qn()]:F})}function Be(w,B){if(clearTimeout(g.current.get(w)),P(M=>M.map(z=>z.id===w?{...z,locator:B,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best",playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1}:z)),tf(B)){const M=setTimeout(async()=>{g.current.delete(w),P(z=>z.map(F=>F.id===w?{...F,probeState:"probing"}:F));try{const z=await tm(v.current,B.trim());P(F=>F.map(U=>{if(U.id!==w||U.locator!==B)return U;const pe=z.qualities??[],de=z.has_audio??!1,Pe=pe.length===0&&de?"audio":"best";return{...U,probeState:"done",probeQualities:pe,probeHasAudio:de,quality:Pe}}))}catch{P(z=>z.map(F=>F.id===w?{...F,probeState:"idle",probeQualities:null}:F))}},600);g.current.set(w,M)}else if(Ln(B)){const M=setTimeout(async()=>{g.current.delete(w),P(z=>z.map(F=>F.id===w?{...F,playlistProbeState:"probing"}:F));try{const z=await nm(v.current,B.trim());P(F=>F.map(U=>U.id!==w||U.locator!==B?U:{...U,playlistProbeState:"done",playlistInfo:z,playlistItems:z.items.map(pe=>({...pe,quality:null})),playlistQuality:null}))}catch{P(z=>z.map(F=>F.id===w?{...F,playlistProbeState:"error"}:F))}},800);g.current.set(w,M)}}function Ct(w,B){P(M=>M.map(z=>z.id===w?{...z,quality:B}:z))}function mt(w,B){P(M=>M.map(z=>{if(z.id!==w)return z;const F=Mm(B,z.playlistItems);return{...z,playlistQuality:B,playlistItems:F}}))}function it(w,B,M){P(z=>z.map(F=>F.id!==w?F:{...F,playlistItems:F.playlistItems.map(U=>U.id===B?{...U,quality:M}:U)}))}function Et(w){P(B=>B.map(M=>M.id===w?{...M,playlistExpanded:!M.playlistExpanded}:M))}function O(w,B){P(M=>M.map(z=>z.id===w?{...z,syncEnabled:B}:z))}function J(w,B){P(M=>M.map(z=>z.id!==w?z:{...z,playlistItems:z.playlistItems.filter(F=>F.id!==B)}))}function ve(w){const B=Array.from(w);B.length!==0&&B.forEach(M=>{const z=Om(M.name);P(de=>de.length===1&&de[0].kind!=="file"&&!de[0].locator.trim()?[z]:[...de,z]);const F=v.current,{promise:U,abort:pe}=Rm(F,M,de=>{P(Pe=>Pe.map(he=>he.id===z.id?{...he,uploadProgress:de}:he))});m.current.set(z.id,pe),U.then(de=>{m.current.delete(z.id),P(Pe=>Pe.map(he=>he.id===z.id?{...he,uploadStatus:"done",uploadLocator:de.locator,uploadProgress:100}:he))}).catch(de=>{m.current.delete(z.id),de.message!=="Upload cancelled"&&P(Pe=>Pe.map(he=>he.id===z.id?{...he,uploadStatus:"error",uploadError:de.message}:he))})})}function Ee(w){w.preventDefault(),w.stopPropagation(),w.dataTransfer.types.includes("Files")&&N(!0)}function Wt(w){w.currentTarget.contains(w.relatedTarget)||N(!1)}function Ie(w){w.preventDefault(),w.stopPropagation(),N(!1),ve(w.dataTransfer.files)}function Bn(w){ve(w.target.files),w.target.value=""}const tn=j.some(w=>w.kind==="file"&&w.uploadStatus==="uploading"),gt=j.filter(w=>w.kind==="file"?w.uploadStatus==="done"&&w.uploadLocator:w.kind==="text"?w.title.trim()&&w.body.trim():w.locator.trim()).length,Ve=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&Pu(w)),Sn=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&Array.isArray(w.playlistItems)&&w.playlistItems.length===0),Nn=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&(w.probeState==="probing"||Ln(w.locator)&&w.playlistProbeState!=="done"));return s.jsx("dialog",{ref:u,className:`capture-dialog${S?" capture-dialog--dragover":""}`,onDragOver:Ee,onDragLeave:Wt,onDrop:Ie,children:s.jsxs("div",{className:"capture-dialog-inner",children:[s.jsxs("div",{className:"capture-dialog-header",children:[s.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),s.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var w;return(w=u.current)==null?void 0:w.close()},"aria-label":"Close",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),s.jsx("div",{className:"capture-rows",children:j.map((w,B)=>w.kind==="file"?s.jsx(Um,{item:w,onRemove:()=>_t(w.id)},w.id):w.kind==="text"?s.jsx(Hm,{item:w,autoFocus:B===j.length-1,onTitleChange:M=>P(z=>z.map(F=>F.id===w.id?{...F,title:M}:F)),onBodyChange:M=>P(z=>z.map(F=>F.id===w.id?{...F,body:M}:F)),onMimeChange:M=>P(z=>z.map(F=>F.id===w.id?{...F,mime:M}:F)),onRemove:()=>_t(w.id),onSubmit:$t},w.id):s.jsx(Bm,{item:w,autoFocus:B===j.length-1,onLocatorChange:M=>Be(w.id,M),onQualityChange:M=>Ct(w.id,M),onRemove:()=>_t(w.id),onSubmit:$t,onPlaylistQualityChange:M=>mt(w.id,M),onPlaylistItemQualityChange:(M,z)=>it(w.id,M,z),onPlaylistToggle:()=>Et(w.id),onSyncChange:M=>O(w.id,M),onPlaylistItemDelete:M=>J(w.id,M)},w.id))}),s.jsx("input",{ref:x,type:"file",multiple:!0,hidden:!0,onChange:Bn,"aria-hidden":"true",tabIndex:-1}),s.jsxs("div",{className:"capture-add-row-group",children:[s.jsxs("button",{type:"button",className:"capture-add-row",onClick:Dt,children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),s.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add URL"]}),s.jsxs("button",{type:"button",className:"capture-add-row capture-add-file",onClick:()=>{var w;return(w=x.current)==null?void 0:w.click()},children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]}),"Upload file"]}),s.jsxs("button",{type:"button",className:"capture-add-row capture-add-text",onClick:()=>P(w=>[...w,Am()]),children:[s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M2 3h12M2 7h12M2 11h8"})}),"Add text"]})]}),s.jsxs("div",{className:"capture-advanced",children:[s.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>G(w=>!w),"aria-expanded":R,children:[s.jsx("svg",{className:`capture-chevron${R?" capture-chevron--open":""}`,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("polyline",{points:"4 6 8 10 12 6"})}),"Advanced options"]}),R&&s.jsxs("div",{className:"capture-advanced-panel",children:[s.jsxs("label",{className:"capture-ext-row",children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"uBlock Origin Lite"}),s.jsx("span",{className:"capture-ext-desc",children:"Block ads during this capture"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":te,className:`ext-toggle ext-toggle--sm${te?" ext-toggle--on":""}`,onClick:()=>Z(w=>w===null?!te:!w),"aria-label":"Toggle uBlock for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Block cookie banners"}),s.jsx("span",{className:"capture-ext-desc",children:"Dismiss cookie consent banners during this capture"}),!(re!=null&&re.cookie_ext_available)&&s.jsxs("span",{className:"capture-ext-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":Ae,className:`ext-toggle ext-toggle--sm${Ae?" ext-toggle--on":""}`,onClick:()=>ye(w=>!w),"aria-label":"Toggle cookie banner blocking for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Reader mode"}),s.jsx("span",{className:"capture-ext-desc",children:"Distil to article text via Readability (off by default)"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":ze,className:`ext-toggle ext-toggle--sm${ze?" ext-toggle--on":""}`,onClick:()=>ne(w=>!w),"aria-label":"Toggle reader mode for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Close modals and dialogs"}),s.jsx("span",{className:"capture-ext-desc",children:"Auto-dismiss cookie banners and overlays during this capture"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":A,className:`ext-toggle ext-toggle--sm${A?" ext-toggle--on":""}`,onClick:()=>L(w=>!w),"aria-label":"Toggle modal closer for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Freedium mirror"}),s.jsx("span",{className:"capture-ext-desc",children:"Route paywalled articles through a Freedium mirror (Medium, NYT, WaPo, etc.)"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":V,className:`ext-toggle ext-toggle--sm${V?" ext-toggle--on":""}`,onClick:()=>Q(w=>!w),"aria-label":"Toggle Freedium mirror for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]})]})]}),s.jsxs("div",{className:"capture-actions",children:[s.jsx("button",{type:"button",className:"capture-submit",onClick:$t,disabled:gt===0||Ve||Nn||Sn||tn,children:gt>1?`Archive ${gt}`:"Archive"}),s.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var w;return(w=u.current)==null?void 0:w.close()},children:"Cancel"})]})]})})}function Bm({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onSubmit:i,onPlaylistQualityChange:a,onPlaylistItemQualityChange:o,onPlaylistToggle:u,onSyncChange:d,onPlaylistItemDelete:y}){const g=c.useRef(null);c.useEffect(()=>{var x;t&&((x=g.current)==null||x.focus())},[t]);const h=(()=>{if(Ln(e.locator)){if(e.playlistProbeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Probing playlist…",children:"…"});if(e.playlistProbeState==="done"){const x=[...new Set(e.playlistItems.flatMap(p=>p.qualities.map(f=>parseInt(f))))].sort((p,f)=>f-p),S=e.playlistItems.every(p=>p.has_audio),N=e.playlistItems.filter(p=>p.quality===null).length;return s.jsxs(s.Fragment,{children:[s.jsxs("select",{className:"capture-quality",value:e.playlistQuality??"",onChange:p=>a(p.target.value),"aria-label":"Playlist quality",children:[!e.playlistQuality&&s.jsx("option",{value:"",disabled:!0,children:"Select quality…"}),s.jsx("option",{value:"best",children:"Best quality"}),x.map(p=>s.jsxs("option",{value:`${p}p`,children:[p,"p"]},p)),S&&s.jsx("option",{value:"audio",children:"Audio only"})]}),N>0&&s.jsxs("span",{className:"capture-conflict-badge",children:[N," need selection"]})]})}return e.playlistProbeState==="error"?s.jsx("span",{className:"capture-quality-hint capture-quality-hint--error",children:"Probe failed — edit URL to retry"}):null}if(!tf(e.locator))return null;if(e.probeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const x=e.probeQualities??[],S=e.probeHasAudio??!1;return x.length===0&&!S?s.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):x.length===0&&S?s.jsx("select",{className:"capture-quality",value:"audio",onChange:N=>r(N.target.value),"aria-label":"Video quality",children:s.jsx("option",{value:"audio",children:"Audio only"})}):s.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:N=>r(N.target.value),"aria-label":"Video quality",children:[s.jsx("option",{value:"best",children:"Best quality"}),x.map(N=>s.jsx("option",{value:N,children:N},N)),S&&s.jsx("option",{value:"audio",children:"Audio only"})]})}return null})(),v=Ln(e.locator)&&e.playlistProbeState==="done"?s.jsxs("label",{className:"capture-sync-row",children:[s.jsx("input",{type:"checkbox",checked:e.syncEnabled,onChange:x=>d(x.target.checked)}),s.jsx("span",{children:"Sync — skip already-archived videos"})]}):null;return s.jsxs("div",{className:"capture-row",children:[s.jsxs("div",{className:"capture-row-main",children:[Ln(e.locator)&&e.playlistProbeState==="done"?s.jsx("button",{type:"button",className:"capture-playlist-toggle capture-playlist-toggle--left",onClick:u,"aria-label":e.playlistExpanded?"Collapse video list":"Expand video list","aria-expanded":e.playlistExpanded,children:e.playlistExpanded?"▲":"▼"}):null,s.jsx("input",{ref:g,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:x=>n(x.target.value),onKeyDown:x=>{x.key==="Enter"&&i()},autoComplete:"off",spellCheck:!1}),h,s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&s.jsx("p",{className:"capture-row-error",children:e.error}),Ln(e.locator)&&e.playlistProbeState==="done"&&e.playlistExpanded?s.jsxs("div",{className:"capture-playlist-items",children:[e.playlistItems.map(x=>s.jsxs("div",{className:`capture-playlist-item${x.quality===null?" capture-playlist-item--conflict":""}`,children:[s.jsx("span",{className:"capture-playlist-item-title",children:x.title||x.url}),s.jsxs("select",{className:"capture-item-quality",value:x.quality??"",onChange:S=>o(x.id,S.target.value),"aria-label":`Quality for ${x.title||x.url}`,children:[x.quality===null&&s.jsx("option",{value:"",disabled:!0,children:"Choose…"}),s.jsx("option",{value:"best",children:"Best quality"}),x.qualities.map(S=>s.jsx("option",{value:S,children:S},S)),x.has_audio&&s.jsx("option",{value:"audio",children:"Audio only"})]}),x.quality===null&&s.jsx("span",{className:"capture-playlist-conflict-badge",children:"Choose quality"}),s.jsx("button",{type:"button",className:"capture-playlist-item-remove","aria-label":`Remove ${x.title||x.url}`,onClick:()=>y(x.id),children:"×"})]},x.id)),v]}):v]})}function Um({item:e,onRemove:t}){const n=e.uploadStatus==="uploading",r=e.uploadStatus==="done",l=e.uploadStatus==="error";return s.jsxs("div",{className:"capture-row",children:[s.jsxs("div",{className:"capture-row-main",children:[s.jsx("span",{className:"capture-file-icon","aria-hidden":"true",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",style:{width:14,height:14},children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]})}),s.jsx("span",{className:`capture-file-name${l?" capture-file-name--error":""}`,children:e.filename}),n&&s.jsxs("span",{className:"capture-file-progress-wrap","aria-label":`Uploading ${e.uploadProgress}%`,children:[s.jsx("span",{className:"capture-file-progress-bar",children:s.jsx("span",{className:"capture-file-progress-fill",style:{width:`${e.uploadProgress}%`}})}),s.jsxs("span",{className:"capture-file-progress-pct",children:[e.uploadProgress,"%"]})]}),r&&s.jsx("span",{className:"capture-file-badge capture-file-badge--done","aria-label":"Upload complete",children:s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{width:11,height:11},children:s.jsx("polyline",{points:"3 8.5 6.5 12 13 5"})})}),l&&s.jsx("span",{className:"capture-file-badge capture-file-badge--error",children:"!"}),s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:t,"aria-label":"Remove",disabled:n,children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),l&&s.jsx("p",{className:"capture-row-error",children:e.uploadError||"Upload failed"})]})}function Hm({item:e,autoFocus:t,onTitleChange:n,onBodyChange:r,onMimeChange:l,onRemove:i,onSubmit:a}){const o=c.useRef(null);return c.useEffect(()=>{var u;t&&((u=o.current)==null||u.focus())},[t]),s.jsx("div",{className:"capture-row capture-text-row",children:s.jsxs("div",{className:"capture-row-main",children:[s.jsx("span",{className:"capture-text-icon","aria-hidden":"true",children:s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",style:{width:14,height:14},children:s.jsx("path",{d:"M2 3h12M2 7h12M2 11h8"})})}),s.jsxs("div",{className:"capture-text-inputs",children:[s.jsx("input",{ref:o,className:"capture-text-input capture-text-title",type:"text",placeholder:"Title",value:e.title,onChange:u=>n(u.target.value),maxLength:500}),s.jsx("textarea",{className:"capture-text-input capture-text-body",placeholder:"Body (markdown or plain text)",value:e.body,onChange:u=>r(u.target.value),rows:6}),s.jsx("div",{className:"capture-text-footer",children:s.jsxs("select",{className:"capture-text-mime",value:e.mime,onChange:u=>l(u.target.value),children:[s.jsx("option",{value:"text/markdown",children:"Markdown"}),s.jsx("option",{value:"text/plain",children:"Plain text"})]})})]}),s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:i,"aria-label":"Remove",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]})})}const Wm=["list=","/playlist/","/channel/","yt:playlist:","yt:channel:","ytm:playlist:","spotify:playlist:","spotify:album:"];function Vm(e){const t=e.toLowerCase();return Wm.some(n=>t.includes(n))}function Qm(e){return e.length>80?`${e.slice(0,79)}…`:e}function qm({locator:e=""}){const t=String(e),n=Vm(t);return s.jsxs("div",{className:"in-progress-entry-row",role:"status","aria-live":"polite",children:[s.jsx("span",{className:"cap-spinner in-progress-entry-row__spinner","aria-hidden":"true"}),s.jsx("span",{className:"in-progress-entry-row__locator",title:t,children:Qm(t)}),s.jsxs("span",{className:"in-progress-entry-row__status",children:["Archiving…",n&&s.jsx("span",{className:"in-progress-entry-row__kind",children:"(playlist)"})]})]})}function fl(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&r").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}function ut(e){return Km(e)??""}function ho(e){if(!e)return"";const t=new Date(e);if(isNaN(t))return e;const n=r=>String(r).padStart(2,"0");return`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())} ${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}const Lu={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:''};function Bs(e){return Lu[e]??Lu.other}function nf(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Xm({entry:e,index:t,onRowClick:n,selectedUids:r}){const l=(r==null?void 0:r.size)===1&&r.has(e.entry_uid),i=(r==null?void 0:r.size)>=2&&r.has(e.entry_uid),a=["child-entry-row",t%2===0?"child-entry-row--light":"child-entry-row--dark",l&&"is-selected",i&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:a,tabIndex:0,"data-entry-uid":e.entry_uid,onMouseDown:o=>{o.shiftKey&&o.preventDefault()},onClick:o=>n(e,o),onKeyDown:o=>{o.key==="Enter"&&n(e,o)},children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:ho(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[s.jsx("span",{className:"source-icon",children:s.jsx("span",{dangerouslySetInnerHTML:{__html:Bs(e.source_kind)}})}),s.jsx("span",{className:"entry-title",children:ut(e.title)||ut(e.entry_uid)})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:ut(e.entity_kind)})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"size-total",children:fl(e.total_artifact_bytes)})}),s.jsx("div",{className:"url-cell col-url",children:ut(e.original_url)})]})}function Jm({entry:e,archiveId:t,rowIndex:n,isSelected:r,isMultiSelected:l,onRowClick:i,selectedUids:a,deletedUids:o,isPublicSession:u}){const[d,y]=c.useState(!1),[g,h]=c.useState(!1),[v,x]=c.useState(null),[S,N]=c.useState(!1),f=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!d?s.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>y(!0),style:{objectFit:"contain"}}):s.jsx("span",{dangerouslySetInnerHTML:{__html:Bs(e.source_kind)}}),m=r||l,k=e.child_count>0&&!u;function E(j){j.stopPropagation(),i(e,{ctrlKey:!0,metaKey:!1,shiftKey:!1,preventDefault(){}})}async function b(j){if(j.stopPropagation(),g){h(!1);return}if(h(!0),v===null&&!S){N(!0);try{const P=await Wh(t,e.entry_uid);x(P)}catch{x([])}finally{N(!1)}}}const T=["entry-row-outer",n%2===0?"entry-row-outer--light":"entry-row-outer--dark",r&&"is-selected",l&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:T,"data-entry-uid":e.entry_uid,children:[s.jsxs("div",{className:"entry-row-main",tabIndex:0,onMouseDown:j=>{j.shiftKey&&j.preventDefault()},onClick:j=>i(e,j),onKeyDown:j=>{j.key==="Enter"&&i(e,j)},children:[s.jsx("div",{className:"col-check",children:s.jsx("button",{type:"button",className:`row-checkbox${m?" is-checked":""}`,"aria-pressed":m,"aria-label":m?"Deselect entry":"Select entry",onClick:E,onKeyDown:j=>j.stopPropagation()})}),s.jsx("div",{className:"col-added",children:ho(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[k&&s.jsx("button",{type:"button",className:`entry-expand-btn${g?" is-expanded":""}`,"aria-label":g?"Collapse children":`Expand ${e.child_count} items`,"aria-expanded":g,onClick:b,onKeyDown:j=>j.stopPropagation()}),s.jsx("span",{className:"source-icon",children:f}),s.jsx("span",{className:"entry-title",children:ut(e.title)||ut(e.entry_uid)}),k&&s.jsx("span",{className:"child-count-badge","aria-hidden":"true",children:e.child_count})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:ut(e.entity_kind)})}),s.jsxs("div",{className:"col-size",children:[s.jsx("span",{className:"size-total",children:fl(e.total_artifact_bytes)}),e.cached_bytes>0&&e.cacheable_bytes>0&&s.jsxs("span",{className:"size-cached-pct",title:`${fl(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.cacheable_bytes*100),"% cached"]})]}),s.jsx("div",{className:"url-cell col-url",children:ut(e.original_url)})]}),g&&s.jsxs(s.Fragment,{children:[S&&s.jsx("div",{className:"child-entries-loading",children:"Loading…"}),s.jsx("div",{className:"child-entries","aria-label":`${e.child_count} child entries`,children:v&&v.filter(j=>!(o!=null&&o.has(j.entry_uid))).map((j,P)=>s.jsx(Xm,{entry:j,index:P,onRowClick:i,selectedUids:a},j.entry_uid))})]})]})}function Gm({entries:e,selectedUids:t,onRowClick:n,archiveId:r,pendingCaptures:l=[],deletedUids:i,isPublicSession:a}){return s.jsx("section",{id:"archive-view",className:"view is-active",children:s.jsxs("div",{className:"entry-table",children:[s.jsxs("div",{className:"entry-header-row",children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:"Added"}),s.jsx("div",{className:"col-title",children:"Title"}),s.jsx("div",{className:"col-type",children:"Type"}),s.jsx("div",{className:"col-size",children:"Size"}),s.jsx("div",{className:"col-url",children:"Original URL"})]}),s.jsxs("div",{id:"entries-body",children:[l.filter(o=>o.archiveId===r).reverse().map(o=>s.jsx(qm,{locator:o.locator},o.id)),e.map((o,u)=>s.jsx(Jm,{entry:o,rowIndex:u,archiveId:r,isSelected:t.size===1&&t.has(o.entry_uid),isMultiSelected:t.size>=2&&t.has(o.entry_uid),onRowClick:n,selectedUids:t,deletedUids:i,isPublicSession:a},o.entry_uid))]})]})})}function Ym(e){if(!e)return"—";try{return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return e}}function Zm({status:e}){const t=e==="completed"?"run-status--completed":e==="failed"?"run-status--failed":e==="in_progress"?"run-status--in-progress":"",n=e?e.replace(/_/g," "):"—";return s.jsx("span",{className:`run-status ${t}`,children:n})}function eg({runs:e}){const[t,n]=c.useState(null);function r(l){n(i=>i===l?null:l)}return s.jsx("section",{id:"runs-view",className:"view is-active",children:s.jsxs("table",{className:"entry-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Started"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Requested"}),s.jsx("th",{children:"Completed"}),s.jsx("th",{children:"Failed"})]})}),s.jsx("tbody",{children:e.length===0?s.jsx("tr",{children:s.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const i=l.status==="failed"&&l.error_summary,a=t===l.run_uid;return[s.jsxs("tr",{className:i?"run-row run-row--failed":"run-row",onClick:i?()=>r(l.run_uid):void 0,title:i?a?"Click to hide error":"Click to view error":void 0,children:[s.jsx("td",{children:Ym(l.started_at)}),s.jsxs("td",{children:[s.jsx(Zm,{status:l.status}),i&&s.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:a?"▴":"▾"})]}),s.jsx("td",{children:l.requested_count??"—"}),s.jsx("td",{children:l.completed_count??"—"}),s.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),i&&a&&s.jsx("tr",{className:"run-error-row",children:s.jsx("td",{colSpan:5,children:s.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const tg=4;function ng({archives:e}){const{currentUser:t}=c.useContext(Us)??{},n=t&&(t.role_bits&tg)!==0,[r,l]=c.useState("users"),[i,a]=c.useState([]),[o,u]=c.useState([]),[d,y]=c.useState(!1),[g,h]=c.useState(null),[v,x]=c.useState(""),[S,N]=c.useState(""),[p,f]=c.useState(""),[m,k]=c.useState(null),[E,b]=c.useState(!1),[T,j]=c.useState(""),[P,R]=c.useState(""),[G,H]=c.useState(null),[Z,re]=c.useState(!1),ce=c.useCallback(async()=>{if(n){y(!0),h(null);try{const[L,V]=await Promise.all([hm(),ym()]);a(L),u(V)}catch(L){h(L.message)}finally{y(!1)}}},[n]);c.useEffect(()=>{ce()},[ce]);async function Ae(L){const V=L.status==="active"?"disabled":"active";try{await gm(L.user_uid,V),a(Q=>Q.map(te=>te.user_uid===L.user_uid?{...te,status:V}:te))}catch(Q){h(Q.message)}}async function ye(L){if(L.preventDefault(),!v.trim()||!S){k("Username and password required");return}b(!0),k(null);try{await mm(v.trim(),S,p.trim()||void 0),x(""),N(""),f(""),await ce()}catch(V){k(V.message)}finally{b(!1)}}async function A(L){if(L.preventDefault(),!T.trim()||!P.trim()){H("Slug and name required");return}re(!0),H(null);try{await vm(T.trim(),P.trim()),j(""),R(""),await ce()}catch(V){H(V.message)}finally{re(!1)}}return n?s.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[s.jsx("h1",{children:"Admin"}),s.jsxs("div",{className:"view-tabs",children:[s.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),s.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),s.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),g&&s.jsx("div",{className:"form-msg form-msg--err",children:g}),r==="users"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Users"}),d?s.jsx("p",{className:"muted",children:"Loading…"}):s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Username"}),s.jsx("th",{children:"Email"}),s.jsx("th",{children:"Roles"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Actions"})]})}),s.jsx("tbody",{children:i.map(L=>s.jsxs("tr",{className:L.status==="disabled"?"admin-row-disabled":"",children:[s.jsx("td",{children:L.username}),s.jsx("td",{className:"muted",children:L.email||"—"}),s.jsx("td",{children:L.role_slugs.join(", ")||"—"}),s.jsx("td",{children:s.jsx("span",{className:`status-badge status-${L.status}`,children:L.status})}),s.jsx("td",{children:s.jsx("button",{className:"admin-action-btn",onClick:()=>Ae(L),children:L.status==="active"?"Ban":"Unban"})})]},L.user_uid))})]}),s.jsx("h3",{children:"Create User"}),s.jsxs("form",{className:"admin-form",onSubmit:ye,children:[s.jsx("input",{className:"admin-input",placeholder:"Username",value:v,onChange:L=>x(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:S,onChange:L=>N(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:p,onChange:L=>f(L.target.value)}),m&&s.jsx("div",{className:"form-msg form-msg--err",children:m}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"Creating…":"Create User"})]})]}),r==="roles"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Roles"}),d?s.jsx("p",{className:"muted",children:"Loading…"}):s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Slug"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Level"}),s.jsx("th",{children:"Bit"}),s.jsx("th",{children:"Built-in"})]})}),s.jsx("tbody",{children:o.map(L=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("code",{children:L.slug})}),s.jsx("td",{children:L.name}),s.jsx("td",{children:L.level}),s.jsx("td",{children:L.bit_position}),s.jsx("td",{children:L.is_builtin?"✓":""})]},L.role_uid))})]}),s.jsx("h3",{children:"Create Custom Role"}),s.jsxs("form",{className:"admin-form",onSubmit:A,children:[s.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:T,onChange:L=>j(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:P,onChange:L=>R(L.target.value),required:!0}),G&&s.jsx("div",{className:"form-msg form-msg--err",children:G}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:Z,children:Z?"Creating…":"Create Role"})]})]}),r==="archives"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Mounted Archives"}),s.jsx("div",{className:"admin-list",children:e.map(L=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:L.label}),s.jsx("div",{className:"muted",children:L.archive_path})]},L.id))})]})]}):s.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[s.jsx("h1",{children:"Admin"}),s.jsx("p",{className:"muted",children:"You need admin privileges to access this panel."}),s.jsx("h2",{children:"Mounted Archives"}),s.jsx("div",{className:"admin-list",children:e.map(L=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:L.label}),s.jsx("div",{className:"muted",children:L.archive_path})]},L.id))})]})}function rf({node:e,onPick:t}){var n;return s.jsxs("li",{children:[s.jsx("button",{className:"tag-picker-node-btn",title:e.tag.full_path,onClick:()=>t(e.tag),children:e.tag.slug}),((n=e.children)==null?void 0:n.length)>0&&s.jsx("div",{className:"tag-children",children:s.jsx("ul",{className:"tag-tree-list",children:e.children.map(r=>s.jsx(rf,{node:r,onPick:t},r.tag.tag_uid))})})]})}function Ru({title:e,tagNodes:t,excludeUid:n,onPick:r,onCancel:l}){c.useEffect(()=>{function o(u){u.key==="Escape"&&(u.preventDefault(),u.stopPropagation(),l())}return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[l]);function i(o){return o.filter(u=>u.tag.tag_uid!==n).map(u=>({...u,children:i(u.children)}))}const a=n?i(t):t;return s.jsx("div",{className:"tag-picker-backdrop",onClick:o=>{o.target===o.currentTarget&&l()},children:s.jsxs("div",{className:"tag-picker-modal",role:"dialog","aria-modal":"true",children:[s.jsxs("div",{className:"tag-picker-header",children:[s.jsx("span",{className:"tag-picker-title",children:e}),s.jsx("button",{className:"tag-picker-close",onClick:l,title:"Cancel","aria-label":"Cancel",children:"×"})]}),s.jsxs("div",{className:"tag-picker-body",children:[s.jsx("button",{className:"tag-picker-root-btn",onClick:()=>r(null),title:"Place at root level (no parent)",children:"↑ Root tag (no parent)"}),a.length>0?s.jsx("ul",{className:"tag-tree-list tag-picker-tree",children:a.map(o=>s.jsx(rf,{node:o,onPick:r},o.tag.tag_uid))}):s.jsx("p",{className:"tag-picker-empty",children:"No other tags available."})]})]})})}function lf({parentPath:e,archiveId:t,onDone:n,onCancel:r}){const[l,i]=c.useState(""),a=c.useRef(!1);async function o(){const u=l.trim();if(!u){r();return}const d=e?`${e}/${u}`:`/${u}`;try{await Gh(t,d),n()}catch(y){alert(y.message||"Create failed"),r()}}return s.jsx("input",{className:"tag-rename-input",autoFocus:!0,placeholder:"tag name",value:l,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur(),u.key==="Escape"&&(a.current=!0,u.currentTarget.blur())},onBlur:()=>{a.current?(a.current=!1,r()):o()}})}function sf({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:d,onMoveSourceSelect:y,pendingCreateParentUid:g,onCreateDone:h,onCreateCancel:v}){var G;const x=n===e.tag.full_path,[S,N]=c.useState(!1),[p,f]=c.useState(""),m=c.useRef(!1);function k(){if(S)return;if(d){y(e);return}const H=x?null:e.tag.full_path;r(H),l("archive")}function E(H){H.stopPropagation(),!d&&(f(e.tag.slug),N(!0))}async function b(){const H=p.trim();if(!H||H===e.tag.slug){N(!1);return}try{const Z=await Xh(t,e.tag.tag_uid,H);i(e.tag.full_path,Z.full_path),o()}catch{}finally{N(!1)}}async function T(H){var re;H.stopPropagation();const Z=((re=e.children)==null?void 0:re.length)>0?`Delete tag "${e.tag.full_path}" and all its child tags? This cannot be undone.`:`Delete tag "${e.tag.full_path}"? This cannot be undone.`;if(window.confirm(Z))try{await Jh(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const j={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:d,onMoveSourceSelect:y,pendingCreateParentUid:g,onCreateDone:h,onCreateCancel:v},P=g===e.tag.tag_uid,R=((G=e.children)==null?void 0:G.length)>0;return s.jsxs("li",{children:[s.jsxs("div",{className:`tag-node-row${d?" tag-node-row--move-select":""}`,children:[S?s.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:p,onChange:H=>f(H.target.value),onKeyDown:H=>{H.key==="Enter"&&H.currentTarget.blur(),H.key==="Escape"&&(m.current=!0,H.currentTarget.blur())},onBlur:()=>{m.current?(m.current=!1,N(!1)):b()}}):s.jsxs("button",{className:`tag-node-btn${x?" is-active":""}${d?" tag-node-btn--move-select":""}`,title:d?`Select "${e.tag.full_path}" to move`:e.tag.full_path,onClick:k,onDoubleClick:d?void 0:E,children:[s.jsx("span",{className:"tag-node-label",children:u?e.tag.name:e.tag.slug}),s.jsx("span",{className:"tag-node-count",children:e.children.length===0?`(${e.entry_count})`:`(${e.entry_count}) (${e.subtree_count} Total)`}),!d&&s.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",title:"Rename tag",onClick:H=>{H.stopPropagation(),E(H)},children:s.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),!S&&!d&&s.jsx("button",{className:"remove tag-node-delete",title:`Delete "${e.tag.full_path}"`,onClick:T,"aria-label":`Delete "${e.tag.full_path}"`,children:"×"})]}),(R||P)&&s.jsx("div",{className:"tag-children",children:s.jsxs("ul",{className:"tag-tree-list",children:[e.children.map(H=>s.jsx(sf,{node:H,...j},H.tag.tag_uid)),P&&s.jsx("li",{children:s.jsx(lf,{parentPath:e.tag.full_path,archiveId:t,onDone:h,onCancel:v})})]})})]})}function rg({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){const[d,y]=c.useState(null),[g,h]=c.useState(null);function v(){y("select-source"),h(null)}function x(){y(null),h(null)}c.useEffect(()=>{if(d!=="select-source")return;function Z(re){re.key==="Escape"&&(re.preventDefault(),re.stopPropagation(),x())}return document.addEventListener("keydown",Z),()=>document.removeEventListener("keydown",Z)},[d]);function S(Z){h(Z),y("select-dest")}async function N(Z){const re=g.tag.full_path,ce=g.tag.tag_uid,Ae=(Z==null?void 0:Z.tag_uid)??null;x();try{const ye=await Yh(e,ce,Ae);i(re,ye.full_path),o()}catch(ye){alert(ye.message||"Move failed")}}const[p,f]=c.useState(null),[m,k]=c.useState(void 0);function E(){f("select-parent"),k(void 0)}function b(){f(null),k(void 0)}function T(Z){k(Z??null),f("input")}function j(){f(null),k(void 0),o()}const P=d==="select-source",R=p==="input"?m?m.tag_uid:"__root__":void 0,G={archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:P,onMoveSourceSelect:S,pendingCreateParentUid:R,onCreateDone:j,onCreateCancel:b},H=R==="__root__";return s.jsxs("section",{id:"tags-view",className:"view is-active",children:[s.jsxs("div",{className:"tag-tree",children:[s.jsx("div",{className:"tag-tree-header",children:P?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"tag-tree-title tag-tree-title--move",children:"Select a tag to move"}),s.jsx("button",{className:"tag-tree-action-btn tag-tree-action-btn--cancel",onClick:x,children:"Cancel"})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&s.jsxs("span",{className:"tag-tree-active",title:n,children:["Filtering: ",n]}),s.jsxs("div",{className:"tag-tree-actions",children:[s.jsx("button",{className:"tag-tree-action-btn",onClick:E,title:"Create a new tag",disabled:!!p||!!d,children:"+ New"}),s.jsx("button",{className:"tag-tree-action-btn",onClick:v,title:"Move a tag to a different parent",disabled:!!p||!!d||t.length===0,children:"Move"})]})]})}),t.length===0&&!H?s.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):s.jsxs("ul",{className:"tag-tree-list",children:[t.map(Z=>s.jsx(sf,{node:Z,...G},Z.tag.tag_uid)),H&&s.jsx("li",{children:s.jsx(lf,{parentPath:null,archiveId:e,onDone:j,onCancel:b})})]})]}),p==="select-parent"&&s.jsx(Ru,{title:"Create tag under…",tagNodes:t,excludeUid:null,onPick:T,onCancel:b}),d==="select-dest"&&g&&s.jsx(Ru,{title:`Move "${g.tag.slug}" under…`,tagNodes:t,excludeUid:g.tag.tag_uid,onPick:N,onCancel:x})]})}const Ar=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],lg=e=>{var t;return((t=Ar.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function sg({archiveId:e}){const[t,n]=c.useState([]),[r,l]=c.useState(!1),[i,a]=c.useState(null),[o,u]=c.useState(null),[d,y]=c.useState(null),[g,h]=c.useState(!1),[v,x]=c.useState(null),[S,N]=c.useState(""),[p,f]=c.useState(""),[m,k]=c.useState(2),[E,b]=c.useState(!1),[T,j]=c.useState(!0),[P,R]=c.useState(null),[G,H]=c.useState(""),[Z,re]=c.useState(2),[ce,Ae]=c.useState(!1),[ye,A]=c.useState(null),[L,V]=c.useState(!1),[Q,te]=c.useState(""),ze=c.useRef(null),ne=t.find(O=>O.collection_uid===o)??null,ke=(ne==null?void 0:ne.slug)==="_default_",oe=c.useCallback(async()=>{if(e){l(!0),a(null);try{const O=await po(e);n(O)}catch(O){a(O.message)}finally{l(!1)}}},[e]),_e=c.useCallback(async O=>{if(!O){y(null);return}h(!0),x(null);try{const J=await wm(e,O);y(J)}catch(J){x(J.message)}finally{h(!1)}},[e]);c.useEffect(()=>{oe()},[oe]),c.useEffect(()=>{_e(o)},[o,_e]),c.useEffect(()=>{L&&ze.current&&ze.current.focus()},[L]),c.useEffect(()=>{d!=null&&re(d.default_visibility_bits)},[d]);async function $t(O){O.preventDefault();const J=S.trim(),ve=p.trim();if(!(!J||!ve)){b(!0),R(null);try{const Ee=await xm(e,J,ve,m,T);N(""),f(""),k(2),j(!0),await oe(),u(Ee.collection_uid)}catch(Ee){R(Ee.message)}finally{b(!1)}}}async function Dt(){const O=Q.trim();if(!O||!ne){V(!1);return}try{await xi(e,ne.collection_uid,{name:O}),await oe(),y(J=>J&&{...J,name:O})}catch(J){a(J.message)}finally{V(!1)}}async function _t(O){if(ne)try{await xi(e,ne.collection_uid,{default_visibility_bits:O}),await oe(),y(J=>J&&{...J,default_visibility_bits:O})}catch(J){a(J.message)}}async function Be(O){if(ne)try{await xi(e,ne.collection_uid,{requires_auth:O}),await oe(),y(J=>J&&{...J,requires_auth:O})}catch(J){a(J.message)}}async function Ct(){if(ne&&window.confirm(`Delete collection "${ne.name}"? Entries will not be deleted.`))try{await Sm(e,ne.collection_uid),u(null),y(null),await oe()}catch(O){a(O.message)}}async function mt(O){O.preventDefault();const J=G.trim();if(!(!J||!ne)){Ae(!0),A(null);try{await ga(e,ne.collection_uid,J,Z),H(""),await _e(ne.collection_uid)}catch(ve){A(ve.message)}finally{Ae(!1)}}}async function it(O){if(ne)try{await km(e,ne.collection_uid,O),await _e(ne.collection_uid)}catch(J){x(J.message)}}async function Et(O,J){if(ne)try{await jm(e,ne.collection_uid,O,J),y(ve=>ve&&{...ve,entries:ve.entries.map(Ee=>Ee.entry_uid===O?{...Ee,collection_visibility_bits:J}:Ee)})}catch(ve){x(ve.message)}}return e?s.jsxs("div",{className:"collections-view",children:[s.jsx("h2",{className:"collections-heading",children:"Collections"}),r&&s.jsx("div",{className:"muted",children:"Loading…"}),i&&s.jsxs("div",{className:"collections-error",children:[i," ",s.jsx("button",{onClick:()=>a(null),className:"coll-dismiss",children:"×"})]}),s.jsxs("div",{className:"collections-layout",children:[s.jsxs("div",{className:"collections-sidebar",children:[t.map(O=>s.jsxs("button",{className:`coll-sidebar-row${o===O.collection_uid?" is-active":""}`,onClick:()=>u(O.collection_uid),children:[s.jsx("span",{className:"coll-row-name",children:O.name}),s.jsx("span",{className:"coll-row-meta",children:lg(O.default_visibility_bits)})]},O.collection_uid)),t.length===0&&!r&&s.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),ne?s.jsxs("div",{className:"coll-detail",children:[s.jsxs("div",{className:"coll-detail-header",children:[L?s.jsx("input",{ref:ze,className:"coll-rename-input",value:Q,onChange:O=>te(O.target.value),onBlur:Dt,onKeyDown:O=>{O.key==="Enter"&&Dt(),O.key==="Escape"&&V(!1)}}):s.jsxs("h3",{className:`coll-detail-name${ke?"":" coll-detail-name--editable"}`,title:ke?void 0:"Click to rename",onClick:()=>{ke||(te(ne.name),V(!0))},children:[(d==null?void 0:d.name)??ne.name,!ke&&s.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!ke&&s.jsx("button",{className:"coll-delete-btn",onClick:Ct,title:"Delete collection",children:"Delete"})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Entries' default visibility"}),s.jsx("select",{className:"coll-vis-select",value:(d==null?void 0:d.default_visibility_bits)??ne.default_visibility_bits,onChange:O=>_t(Number(O.target.value)),children:Ar.map(O=>s.jsx("option",{value:O.value,children:O.label},O.value))})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Collection access"}),s.jsxs("label",{className:"coll-auth-label",children:[s.jsx("input",{type:"checkbox",checked:!!((d==null?void 0:d.requires_auth)??ne.requires_auth),onChange:O=>Be(O.target.checked)})," Require authentication to view"]})]}),s.jsxs("div",{className:"coll-entries-section",children:[s.jsx("div",{className:"coll-section-heading",children:"Entries"}),g&&s.jsx("div",{className:"muted",children:"Loading…"}),v&&s.jsx("div",{className:"collections-error",children:v}),!g&&d&&(d.entries.length===0?s.jsx("div",{className:"muted",children:"No entries in this collection."}):s.jsx("ul",{className:"coll-entries-list",children:d.entries.map(O=>s.jsxs("li",{className:"coll-entry-row",children:[s.jsxs("div",{className:"coll-entry-info",children:[s.jsx("span",{className:"coll-entry-title",children:O.title||O.entry_uid}),s.jsx("span",{className:"coll-entry-kind muted",children:O.source_kind})]}),s.jsxs("div",{className:"coll-entry-actions",children:[s.jsx("select",{className:"coll-entry-vis-select",value:O.collection_visibility_bits,onChange:J=>Et(O.entry_uid,Number(J.target.value)),children:Ar.map(J=>s.jsx("option",{value:J.value,children:J.label},J.value))}),!ke&&s.jsx("button",{className:"coll-entry-remove",onClick:()=>it(O.entry_uid),title:"Remove from collection",children:"×"})]})]},O.entry_uid))}))]}),!ke&&s.jsxs("form",{className:"coll-add-entry-form",onSubmit:mt,children:[s.jsx("div",{className:"coll-section-heading",children:"Add entry"}),s.jsxs("div",{className:"coll-add-entry-row",children:[s.jsx("input",{className:"coll-add-entry-input",type:"text",value:G,onChange:O=>H(O.target.value),placeholder:"entry_uid",required:!0}),s.jsx("select",{className:"coll-vis-select",value:Z,onChange:O=>re(Number(O.target.value)),children:Ar.map(O=>s.jsx("option",{value:O.value,children:O.label},O.value))}),s.jsx("button",{className:"coll-add-btn",type:"submit",disabled:ce,children:ce?"…":"Add"})]}),ye&&s.jsx("div",{className:"collections-error",style:{marginTop:4},children:ye})]})]}):s.jsx("div",{className:"coll-detail coll-detail--empty",children:s.jsx("div",{className:"muted",children:"Select a collection to view details."})})]}),s.jsxs("details",{className:"coll-create-details",children:[s.jsx("summary",{children:"+ Create collection"}),s.jsxs("form",{className:"coll-create-form",onSubmit:$t,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),s.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:S,onChange:O=>{N(O.target.value),p||f(O.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),s.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:p,onChange:O=>f(O.target.value),placeholder:"my-collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Entries' default visibility"}),s.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:m,onChange:O=>k(Number(O.target.value)),children:Ar.map(O=>s.jsx("option",{value:O.value,children:O.label},O.value))})]}),s.jsx("div",{className:"form-field",children:s.jsxs("label",{className:"form-label",children:[s.jsx("input",{type:"checkbox",checked:T,onChange:O=>j(O.target.checked)})," Require authentication to view"]})}),P&&s.jsx("div",{className:"collections-error",children:P}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:E,children:E?"Creating…":"Create collection"})]})]})]}):s.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const ig=4;function ag({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=c.useContext(Us)??{},i=r&&(r.role_bits&ig)!==0,a=["profile","tokens",...i?["instance","cookies","extensions","storage"]:[]],o={profile:"Profile",tokens:"API Tokens",instance:"Instance",cookies:"Cookies",extensions:"Extensions",storage:"Storage"};return s.jsxs("section",{className:"admin-view",children:[s.jsx("h1",{children:"Settings"}),s.jsx("div",{className:"view-tabs",children:a.map(u=>s.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:o[u]},u))}),e==="profile"&&s.jsx(og,{currentUser:r,setCurrentUser:l}),e==="tokens"&&s.jsx(ug,{}),e==="instance"&&i&&s.jsx(cg,{}),e==="cookies"&&i&&s.jsx(fg,{}),e==="extensions"&&i&&s.jsx(pg,{}),e==="storage"&&i&&s.jsx(dg,{archiveId:n})]})}function og({currentUser:e,setCurrentUser:t}){const[n,r]=c.useState((e==null?void 0:e.display_name)??""),[l,i]=c.useState(!1),[a,o]=c.useState(null),[u,d]=c.useState(""),[y,g]=c.useState(""),[h,v]=c.useState(""),[x,S]=c.useState(!1),[N,p]=c.useState(null);async function f(k){k.preventDefault(),i(!0),o(null);try{await om(n),t(E=>({...E,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(E){o({ok:!1,text:E.message})}finally{i(!1)}}async function m(k){if(k.preventDefault(),y!==h){p({ok:!1,text:"Passwords do not match."});return}S(!0),p(null);try{await cm(u,y),d(""),g(""),v(""),p({ok:!0,text:"Password changed."})}catch(E){p({ok:!1,text:E.message})}finally{S(!1)}}return s.jsxs("div",{style:{maxWidth:440},children:[s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Display Name"}),s.jsxs("form",{onSubmit:f,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),s.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:k=>r(k.target.value)})]}),a&&s.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Display Preferences"}),s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async k=>{const E=k.target.checked;try{await um({humanize_slugs:E}),t(b=>({...b,humanize_slugs:E}))}catch{}}}),s.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),s.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Change Password"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),s.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:k=>d(k.target.value),required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),s.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:y,onChange:k=>g(k.target.value),required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),s.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:h,onChange:k=>v(k.target.value),required:!0})]}),N&&s.jsx("div",{className:`form-msg form-msg--${N.ok?"ok":"err"}`,children:N.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Changing…":"Change Password"})]})]})]})}function ug(){const[e,t]=c.useState([]),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState(""),[u,d]=c.useState(!1),[y,g]=c.useState(null),h=c.useCallback(async()=>{r(!0),i(null);try{t(await dm())}catch(S){i(S.message)}finally{r(!1)}},[]);c.useEffect(()=>{h()},[h]);async function v(S){if(S.preventDefault(),!!a.trim()){d(!0);try{const N=await fm(a.trim());g(N),o(""),h()}catch(N){i(N.message)}finally{d(!1)}}}async function x(S){try{await pm(S),t(N=>N.filter(p=>p.token_uid!==S))}catch(N){i(N.message)}}return s.jsx("div",{style:{maxWidth:600},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"API Tokens"}),y&&s.jsxs("div",{className:"token-banner",children:[s.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",s.jsx("code",{children:y.raw_token}),s.jsx("button",{className:"token-dismiss",onClick:()=>g(null),children:"Dismiss"})]}),s.jsxs("form",{className:"token-create-row",onSubmit:v,children:[s.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:S=>o(S.target.value),required:!0}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&s.jsx("div",{className:"form-msg form-msg--err",children:l}),n?s.jsx("div",{className:"muted",children:"Loading…"}):s.jsxs("div",{children:[e.length===0&&s.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(S=>s.jsxs("div",{className:"token-row",children:[s.jsxs("div",{className:"token-row-info",children:[s.jsx("strong",{children:S.name}),s.jsxs("div",{className:"muted",children:["Created ",S.created_at.slice(0,10),S.last_used_at&&` · Last used ${S.last_used_at.slice(0,10)}`]})]}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>x(S.token_uid),children:"Revoke"})]},S.token_uid))]})]})})}function cg(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState(!1),[u,d]=c.useState(null);c.useEffect(()=>{(async()=>{try{t(await fo())}catch(g){i(g.message)}finally{r(!1)}})()},[]);async function y(g){g.preventDefault(),o(!0),d(null);try{await Yl(e),d({ok:!0,text:"Saved."})}catch(h){d({ok:!1,text:h.message})}finally{o(!1)}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):e?s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Instance Settings"}),s.jsxs("form",{onSubmit:y,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([g,h])=>s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:!!e[g],onChange:v=>t(x=>({...x,[g]:v.target.checked}))}),h]},g)),s.jsxs("div",{className:"form-field",style:{marginTop:4},children:[s.jsx("label",{className:"form-label",children:"Default entry visibility"}),s.jsxs("select",{className:"field-input",value:e.default_entry_visibility,onChange:g=>t(h=>({...h,default_entry_visibility:Number(g.target.value)})),children:[s.jsx("option",{value:0,children:"Private"}),s.jsx("option",{value:2,children:"Unlisted"}),s.jsx("option",{value:3,children:"Public"})]})]}),u&&s.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:a,children:a?"Saving…":"Save Settings"})]})]})}):null}function ki(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,n)).toFixed(n===0?0:1)} ${t[n]}`}function dg({archiveId:e}){const[t,n]=c.useState("idle"),[r,l]=c.useState(null),[i,a]=c.useState(null),[o,u]=c.useState(null);function d(){n("idle"),l(null),a(null),u(null)}async function y(){n("scanning"),u(null),l(null);try{const v=await Nm(e);l(v),n("scanned")}catch(v){u(v.message),n("error")}}async function g(){n("deleting"),u(null);try{const v=await _m(e);a(v),n("done")}catch(v){u(v.message),n("error")}}const h=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Orphan Cleanup"}),s.jsxs("p",{className:"muted",style:{marginBottom:16},children:["Scan for blob files and database records that are no longer referenced by any archive entry and safely delete them."," ",s.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&s.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&s.jsx("button",{className:"btn-ghost",onClick:y,children:"Scan for orphaned blobs"}),t==="scanning"&&s.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&h&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Done"})]}),t==="scanned"&&r&&!h&&s.jsxs("div",{children:[s.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",s.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",s.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",s.jsx("strong",{children:ki(r.total_bytes)})," recoverable."]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsxs("button",{className:"btn-danger",onClick:g,children:["Delete (",ki(r.total_bytes),")"]}),s.jsx("button",{className:"btn-ghost",onClick:d,children:"Cancel"})]})]}),t==="deleting"&&s.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&i&&s.jsxs("div",{children:[s.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",s.jsx("strong",{children:ki(i.freed_bytes)})," ","— removed ",i.deleted_files," file",i.deleted_files!==1?"s":""," ","and ",i.deleted_blob_rows," DB record",i.deleted_blob_rows!==1?"s":"","."]}),i.errors&&i.errors.length>0&&s.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[i.errors.length," file",i.errors.length!==1?"s":""," could not be deleted."]}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Scan again"})]}),t==="error"&&s.jsxs("div",{children:[s.jsx("div",{className:"form-msg form-msg--err",children:o}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Try again"})]})]})})}function fg(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState("global"),[u,d]=c.useState(""),[y,g]=c.useState("{}"),[h,v]=c.useState(null),[x,S]=c.useState(!1),[N,p]=c.useState({});c.useEffect(()=>{f()},[]);async function f(){r(!0),i(null);try{t(await bm())}catch(j){i(j.message)}finally{r(!1)}}async function m(j){j.preventDefault();try{JSON.parse(y)}catch{v({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}S(!0),v(null);try{await Tm(a==="global"?null:u.trim(),a,y),d(""),g("{}"),o("global"),v({ok:!0,text:"Rule added."}),await f()}catch(P){v({ok:!1,text:P.message})}finally{S(!1)}}async function k(j){try{await Lm(j),await f()}catch(P){i(P.message)}}function E(j){p(P=>({...P,[j.rule_uid]:{cookiesInput:j.cookies_json,saving:!1,msg:null}}))}function b(j){p(P=>{const R={...P};return delete R[j],R})}async function T(j){const P=N[j.rule_uid];try{JSON.parse(P.cookiesInput)}catch{p(R=>({...R,[j.rule_uid]:{...R[j.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}p(R=>({...R,[j.rule_uid]:{...R[j.rule_uid],saving:!0,msg:null}}));try{await Pm(j.rule_uid,{cookies_json:P.cookiesInput}),b(j.rule_uid),await f()}catch(R){p(G=>({...G,[j.rule_uid]:{...G[j.rule_uid],saving:!1,msg:{ok:!1,text:R.message}}}))}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):s.jsx("div",{style:{maxWidth:560},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Cookie Rules"}),s.jsx("p",{className:"muted",style:{marginBottom:12},children:"Cookies are injected into every capture network request (yt-dlp, HTTP downloads, web-page snapshots). Global rules apply to all URLs; wildcard and regex rules apply only to matching URLs."}),e&&e.length>0?s.jsxs("table",{className:"data-table",style:{width:"100%",marginBottom:16},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Pattern"}),s.jsx("th",{children:"Cookies"}),s.jsx("th",{style:{width:100},children:"Actions"})]})}),s.jsx("tbody",{children:e.map(j=>{const P=N[j.rule_uid],R=j.url_pattern?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted",children:[j.pattern_kind,":"]})," ",s.jsx("code",{children:j.url_pattern})]}):s.jsx("span",{className:"muted",children:"global (all URLs)"});return s.jsxs("tr",{children:[s.jsx("td",{children:R}),s.jsx("td",{children:P?s.jsxs(s.Fragment,{children:[s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:P.cookiesInput,onChange:G=>p(H=>({...H,[j.rule_uid]:{...H[j.rule_uid],cookiesInput:G.target.value}}))}),P.msg&&s.jsx("div",{className:`form-msg form-msg--${P.msg.ok?"ok":"err"}`,children:P.msg.text}),s.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[s.jsx("button",{className:"btn-primary",style:{fontSize:12,padding:"2px 8px"},disabled:P.saving,onClick:()=>T(j),children:P.saving?"Saving…":"Save"}),s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>b(j.rule_uid),children:"Cancel"})]})]}):s.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:j.cookies_json})}),s.jsx("td",{children:!P&&s.jsxs("div",{style:{display:"flex",gap:6},children:[s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>E(j),children:"Edit"}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>k(j.rule_uid),children:"Del"})]})})]},j.rule_uid)})})]}):s.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),s.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Pattern type"}),s.jsxs("select",{className:"field-input",value:a,onChange:j=>o(j.target.value),children:[s.jsx("option",{value:"global",children:"Global (all URLs)"}),s.jsx("option",{value:"wildcard",children:"Wildcard (e.g. *.youtube.com)"}),s.jsx("option",{value:"regex",children:"Regex (matched against full URL)"})]})]}),a!=="global"&&s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:a==="wildcard"?"URL/hostname pattern":"Regex pattern"}),s.jsx("input",{className:"field-input",type:"text",value:u,onChange:j=>d(j.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:y,onChange:j=>g(j.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),h&&s.jsx("div",{className:`form-msg form-msg--${h.ok?"ok":"err"}`,children:h.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Adding…":"Add Rule"})]})]})})}function pg(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(!1),[a,o]=c.useState(null);c.useEffect(()=>{(async()=>{try{t(await fo())}catch(N){o({ok:!1,text:N.message})}finally{r(!1)}})()},[]);async function u(N){i(!0),o(null);try{await Yl({ublock_enabled:N}),t(p=>({...p,ublock_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function d(N){i(!0),o(null);try{await Yl({cookie_ext_enabled:N}),t(p=>({...p,cookie_ext_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function y(N){i(!0),o(null);try{await Yl({modal_closer_enabled:N}),t(p=>({...p,modal_closer_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}if(n)return s.jsx("div",{className:"muted",children:"Loading\\u2026"});const g=(e==null?void 0:e.ublock_ext_available)??!1,h=(e==null?void 0:e.ublock_enabled)??!0,v=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0,S=(e==null?void 0:e.modal_closer_enabled)??!0;return s.jsx("div",{children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Extensions"}),s.jsx("p",{className:"form-hint",style:{marginBottom:20},children:"Extensions run inside the browser during WebPage captures and can block ads, accept cookie banners, and more. Changes take effect on the next capture."}),s.jsxs("div",{className:"ext-grid",children:[s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"uBlock Origin Lite"}),s.jsx("span",{className:"ext-card-desc",children:"Blocks ads, trackers, and other page clutter during archiving via Chrome’s declarativeNetRequest API (Manifest V3)."}),!g&&s.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_UBLOCK_EXT"})," to the unpacked extension directory to enable."]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":h,className:`ext-toggle${h?" ext-toggle--on":""}`,onClick:()=>u(!h),disabled:l,"aria-label":"Toggle uBlock Origin Lite",children:s.jsx("span",{className:"ext-toggle-knob"})})]})}),s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"I Still Don’t Care About Cookies"}),s.jsx("span",{className:"ext-card-desc",children:"Dismiss cookie consent banners during archiving."}),!v&&s.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})," to the unpacked extension directory to enable."]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":x,className:`ext-toggle${x?" ext-toggle--on":""}`,onClick:()=>d(!x),disabled:l,"aria-label":"Toggle I Still Don't Care About Cookies",children:s.jsx("span",{className:"ext-toggle-knob"})})]})}),s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"Modal & Dialog Closer"}),s.jsx("span",{className:"ext-card-desc",children:"Auto-dismiss cookie banners, consent overlays, and other modal dialogs before a WebPage capture is taken. Implemented as an injected browser script; no external extension required."})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":S,className:`ext-toggle${S?" ext-toggle--on":""}`,onClick:()=>y(!S),disabled:l,"aria-label":"Toggle Modal and Dialog Closer",children:s.jsx("span",{className:"ext-toggle-knob"})})]})})]}),a&&s.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text})]})})}const zu={0:"Private",1:"Public",2:"Users only",3:"Public"},Zl=[{value:"anthropic_http",label:"Anthropic API"},{value:"openai_compatible",label:"OpenAI-compatible API"},{value:"claude_cli",label:"Claude CLI"},{value:"codex_cli",label:"Codex CLI"}],hg=Object.fromEntries(Zl.map(e=>[e.value,e.label])),Iu="archivr:summary:provider",mg=1500,af="This entry can’t be summarized yet.",of="It doesn’t contain archived text that a summary provider can read. Summaries currently support text notes, web pages, X posts and threads, and X Articles. Video, audio, and image-only entries need a transcript or text source.",$u=`${af}
+
+${of}`;function gg(e){if(!e)return null;try{const t=JSON.parse(e);if(t&&typeof t=="object")return{tldr:typeof t.tldr=="string"?t.tldr:"",summary:typeof t.summary=="string"?t.summary:"",tags:Array.isArray(t.tags)?t.tags.filter(n=>typeof n=="string"):[]}}catch{}return{tldr:"",summary:e,tags:[]}}const yg=()=>s.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function vg({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:d,onBulkDeleted:y,humanizeTags:g,onDetailRefresh:h,onOpenPreview:v,onPlay:x,isPublicSession:S}){var K,Y,se;const[N,p]=c.useState([]),[f,m]=c.useState(""),[k,E]=c.useState([]),[b,T]=c.useState(""),j=c.useRef(0),P=c.useRef(!1),[R,G]=c.useState(!1),[H,Z]=c.useState(""),[re,ce]=c.useState("idle"),[Ae,ye]=c.useState(""),A=c.useRef(null),[L,V]=c.useState(!1);c.useEffect(()=>{V(!1)},[(K=l==null?void 0:l.summary)==null?void 0:K.entry_uid]);const[Q,te]=c.useState(null),[ze,ne]=c.useState(""),[ke,oe]=c.useState(!1),[_e,$t]=c.useState(()=>{try{return sessionStorage.getItem(Iu)||Zl[0].value}catch{return Zl[0].value}}),[Dt,_t]=c.useState(!1),Be=c.useRef(null),Ct=(n==null?void 0:n.size)>=2,[mt,it]=c.useState(""),[Et,O]=c.useState("idle"),[J,ve]=c.useState(""),[Ee,Wt]=c.useState([]),[Ie,Bn]=c.useState(""),[tn,gt]=c.useState("idle"),[Ve,Sn]=c.useState(""),[Nn,w]=c.useState("idle"),[B,M]=c.useState(""),[z,F]=c.useState("idle"),[U,pe]=c.useState("");c.useEffect(()=>{const C=++j.current;if(A.current&&(clearInterval(A.current),A.current=null),ce("idle"),ye(""),!t||!e){p([]),E([]);return}if(S){p([]),E([]);return}G(!1),Z(""),P.current=!1,p([]),Promise.all([Al(e,t.entry_uid),Tu(e,t.entry_uid)]).then(([q,X])=>{C===j.current&&(p(q),E(X))}).catch(()=>{})},[t,e,S]),c.useEffect(()=>()=>{clearInterval(A.current)},[]),c.useEffect(()=>{clearInterval(Be.current),Be.current=null,te((l==null?void 0:l.latest_summary)??null),ne(""),oe(!1),_t(!1)},[(Y=l==null?void 0:l.summary)==null?void 0:Y.entry_uid]);const de=Q==null?void 0:Q.status;c.useEffect(()=>{var q;if(clearInterval(Be.current),Be.current=null,de!=="pending"&&de!=="running"||!e||!((q=l==null?void 0:l.summary)!=null&&q.entry_uid))return;const C=l.summary.entry_uid;return Be.current=setInterval(async()=>{var X;try{const xe=await Uh(e,C);te(xe.summary??null);const Ot=(X=xe.summary)==null?void 0:X.status;Ot!=="pending"&&Ot!=="running"&&(clearInterval(Be.current),Be.current=null,oe(!1),Ot==="completed"&&(h==null||h()))}catch{}},mg),()=>{clearInterval(Be.current),Be.current=null}},[de,e,(se=l==null?void 0:l.summary)==null?void 0:se.entry_uid]),c.useEffect(()=>()=>clearInterval(Be.current),[]);async function Pe(C=!1){var q;if(!(!e||!((q=l==null?void 0:l.summary)!=null&&q.entry_uid)||ke)){oe(!0),ne("");try{const X=await Hh(e,l.summary.entry_uid,{provider:_e,force:C,includeImages:Dt});X.status==="completed"?(te(X),oe(!1),h==null||h()):te({...X??{},status:"pending"})}catch(X){ne(X.message||"Summary request failed"),oe(!1)}}}function he(C){$t(C),C==="claude_cli"&&_t(!1);try{sessionStorage.setItem(Iu,C)}catch{}}c.useEffect(()=>{if(!e){Wt([]);return}po(e).then(Wt).catch(()=>Wt([]))},[e]),c.useEffect(()=>{it(""),O("idle"),ve(""),Bn(""),gt("idle"),Sn(""),w("idle"),M(""),F("idle"),pe("")},[n]);async function Qe(){const C=n.size;if(!window.confirm(`Delete ${C} entr${C===1?"y":"ies"}? This cannot be undone.`))return;w("running");const q=new Set;for(const X of n)try{await bu(e,X),q.add(X)}catch{}w("idle"),y==null||y(q)}async function ie(){const C=mt.trim();if(C){O("running"),ve("");try{for(const q of n)await Eu(e,q,C);it(""),O("done"),o==null||o(),setTimeout(()=>O("idle"),1800)}catch(q){ve(q.message),O("error")}}}async function at(){if(!Ie)return;gt("running"),Sn("");const C=[],q=Ee.find(X=>X.collection_uid===Ie);for(const X of n)try{await ga(e,Ie,X,(q==null?void 0:q.default_visibility_bits)??2)}catch{C.push(X)}C.length>0?(Sn(`Failed for ${C.length} entr${C.length===1?"y":"ies"}.`),gt("error")):(gt("done"),setTimeout(()=>gt("idle"),1800))}async function yt(){if(!B||!t)return;F("running"),pe("");const C=Ee.find(q=>q.collection_uid===B);try{await ga(e,B,t.entry_uid,(C==null?void 0:C.default_visibility_bits)??2),F("done"),M("");const q=await Tu(e,t.entry_uid);E(q),setTimeout(()=>F("idle"),1800)}catch(q){pe(q.message),F("error")}}async function Hs(){const C=H.trim()||null;try{await qh(e,t.entry_uid,C),u==null||u(t.entry_uid,C)}catch{}finally{G(!1)}}async function vl(){const C=f.trim();if(!(!C||!t))try{await Eu(e,t.entry_uid,C),m(""),T("");const q=await Al(e,t.entry_uid);p(q),o()}catch(q){T(q.message)}}async function Ws(C){try{await Kh(e,t.entry_uid,C);const q=await Al(e,t.entry_uid);p(q),o()}catch{}}async function Un(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await bu(e,t.entry_uid),d==null||d(t.entry_uid)}catch{}}async function jr(){if(!t||!e||re==="running")return;const C=j.current,q=t.entry_uid;ce("running"),ye("");try{const{job_uid:X}=await Cm(e,q);if(j.current!==C)return;A.current=setInterval(async()=>{try{const xe=await ef(e,X);if(xe.status==="completed"){if(clearInterval(A.current),A.current=null,j.current!==C)return;ce("done");const Ot=await Al(e,q);if(j.current!==C)return;p(Ot),h==null||h()}else if(xe.status==="failed"){if(clearInterval(A.current),A.current=null,j.current!==C)return;ce("error"),ye(xe.error_text||"Re-archive failed.")}}catch{if(clearInterval(A.current),A.current=null,j.current!==C)return;ce("error"),ye("Network error while polling.")}},500)}catch(X){if(j.current!==C)return;ce("error"),ye(X.message||"Failed to start re-archive.")}}const _n=l?[["Added",ho(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",zu[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],xl=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),Vs=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Hn=l?l.artifacts.findIndex(C=>C.artifact_role==="primary_media"):-1,Wn=Hn>=0?l.artifacts[Hn]:null,wl=Wn?Wn.relpath.split(".").pop().toLowerCase():"",_=Wn&&xl.has(wl),I=Hn>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${Hn}`:null,D=l&&!_&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||Wn&&Vs.has(wl));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),Ct?S?s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}):s.jsxs("div",{className:"bulk-panel",children:[s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}),s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Assign tag"}),J&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:J}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:mt,onChange:C=>it(C.target.value),onKeyDown:C=>{C.key==="Enter"&&ie()}}),s.jsx("button",{className:"tag-add-btn",onClick:ie,disabled:Et==="running"||!mt.trim(),children:Et==="running"?"…":Et==="done"?"✓":"Add"})]})]}),Ee.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Add to collection"}),s.jsxs("div",{className:"bulk-coll-row",children:[s.jsxs("select",{className:"bulk-coll-select",value:Ie,onChange:C=>Bn(C.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),Ee.filter(C=>C.slug!=="_default_").map(C=>s.jsx("option",{value:C.collection_uid,children:C.name},C.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:at,disabled:!Ie||tn==="running",children:tn==="running"?"…":tn==="done"?"✓":tn==="error"?"!":"Add"})]}),Ve&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:Ve})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Qe,disabled:Nn==="running",children:Nn==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[S?s.jsx("h2",{className:"rail-title",children:ut(l.summary.title)||ut(l.summary.entry_uid)}):R?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:H,onChange:C=>Z(C.target.value),onKeyDown:C=>{C.key==="Enter"&&C.currentTarget.blur(),C.key==="Escape"&&(P.current=!0,C.currentTarget.blur())},onBlur:()=>{P.current?G(!1):Hs(),P.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{Z(l.summary.title??""),G(!0)},children:[ut(l.summary.title)||ut(l.summary.entry_uid),s.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:s.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),l.summary.original_url&&s.jsxs("a",{className:"url-tile",href:l.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[s.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:Bs(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(yg,{})})]}),_&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>x(I,t),children:"▶ Play"}),D&&v&&s.jsx("button",{className:"rail-preview-btn",onClick:v,children:"Preview"}),(()=>{const C=(Q==null?void 0:Q.status)==="completed"?gg(Q.summary_text):null,q=(Q==null?void 0:Q.status)==="pending"||(Q==null?void 0:Q.status)==="running",X=(Q==null?void 0:Q.status)==="failed"&&Q.error_text===$u||ze===$u;return S&&!C?null:s.jsxs("div",{className:"rail-section rail-summary",children:[s.jsx("div",{className:"rail-section-heading",children:"Summary"}),C&&s.jsxs("div",{className:"rail-summary-body",children:[C.tldr&&s.jsx("p",{className:"rail-summary-tldr",children:C.tldr}),C.summary&&s.jsx("p",{className:"rail-summary-text",children:C.summary}),C.tags.length>0&&s.jsx("div",{className:"rail-summary-tags",children:C.tags.map(xe=>s.jsx("span",{className:"rail-summary-tag",children:xe},xe))}),s.jsxs("p",{className:"rail-summary-provider",children:[hg[Q.provider_kind]||Q.provider_kind,Q.provider_model?` · ${Q.provider_model}`:""]})]}),q&&s.jsxs("p",{className:"rail-summary-status",children:[s.jsx("span",{className:"rail-summary-spinner","aria-hidden":"true"}),"Generating…"]}),X&&!S&&s.jsxs("div",{className:"rail-summary-info",role:"status",children:[s.jsx("p",{className:"rail-summary-info__heading",children:af}),s.jsx("p",{className:"rail-summary-info__detail",children:of})]}),(Q==null?void 0:Q.status)==="failed"&&Q.error_text&&!X&&!S&&s.jsx("p",{className:"form-msg form-msg--err rail-summary-error",children:Q.error_text}),ze&&!X&&s.jsx("p",{className:"form-msg form-msg--err rail-summary-error",children:ze}),!S&&!q&&s.jsxs("div",{className:"rail-summary-controls",children:[s.jsx("select",{className:"rail-summary-select",value:_e,onChange:xe=>he(xe.target.value),"aria-label":"Summary provider",children:Zl.map(xe=>s.jsx("option",{value:xe.value,children:xe.label},xe.value))}),s.jsxs("div",{className:`rail-summary-image-option${_e==="claude_cli"?" rail-summary-image-option--disabled":""}`,children:[s.jsxs("label",{className:"rail-summary-image-option__label",children:[s.jsx("input",{type:"checkbox",checked:Dt,disabled:_e==="claude_cli",onChange:xe=>_t(xe.target.checked)}),"Include attached images"]}),s.jsx("p",{className:"rail-summary-image-option__note",children:_e==="claude_cli"?"Claude CLI cannot attach local images. Choose an HTTP provider or Codex CLI.":"Selected archived images are sent to the chosen provider. Up to 4 supported images (5 MiB each, 12 MiB total) can be attached; unsupported or oversized artifacts are skipped."})]}),s.jsx("button",{className:"rail-rearchive-btn",onClick:()=>Pe(!!C),disabled:ke,children:ke?"…":C?"Regenerate":"Generate"})]})]})})(),s.jsx("div",{className:"meta-list",children:_n.filter(([,C])=>C!=null&&C!=="").map(([C,q])=>s.jsxs("div",{className:"meta-item",children:[s.jsx("span",{className:"meta-k",children:C}),s.jsx("span",{className:`meta-v${C==="Root"?" mono":""}`,children:ut(q)})]},C))}),l.artifacts.length>0&&(()=>{const C=l.artifacts.map((Le,vt)=>({...Le,_idx:vt})),q=C.filter(Le=>Le.artifact_role==="font"),X=C.filter(Le=>Le.artifact_role!=="font"),xe=q.reduce((Le,vt)=>Le+(vt.byte_size||0),0),Ot=l.summary.entry_uid,Sr=Le=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${Ot}/artifacts/${Le._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:Le.artifact_role==="font"?Le.relpath.split("/").pop():Le.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:Le.byte_size!=null?fl(Le.byte_size):"—"})]})},Le._idx);return s.jsxs("div",{className:"rail-section",children:[s.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",s.jsx("span",{className:"num",children:l.artifacts.length})]}),s.jsxs("ul",{className:"artifact-list",children:[X.map(Sr),q.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":L,onClick:()=>V(Le=>!Le),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${L?" open":""}`,children:"›"}),` fonts (${q.length})`]}),s.jsx("span",{className:"artifact-size",children:fl(xe)})]}),L&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:q.map(Sr)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!Ct&&!S&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),N.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:N.map(C=>s.jsxs("span",{className:"tag-pill",title:C.full_path,children:[g?nf(C.full_path):C.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${C.full_path}`,onClick:()=>Ws(C.tag_uid),children:"×"})]},C.tag_uid))}),b&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:b}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:f,onChange:C=>m(C.target.value),onKeyDown:C=>{C.key==="Enter"&&vl()}}),s.jsx("button",{className:"tag-add-btn",onClick:vl,children:"Add"})]})]}),(k.length>0||Ee.filter(C=>C.slug!=="_default_").length>0)&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),k.map(C=>s.jsxs("div",{className:"coll-row",children:[s.jsx("span",{className:"coll-name",children:C.name}),s.jsx("span",{className:"vis-badge",children:zu[C.visibility_bits]??`bits:${C.visibility_bits}`})]},C.collection_uid)),Ee.filter(C=>C.slug!=="_default_").length>0&&s.jsxs("div",{className:"bulk-coll-row",style:{marginTop:8},children:[s.jsxs("select",{className:"bulk-coll-select",value:B,onChange:C=>M(C.target.value),children:[s.jsx("option",{value:"",children:"Add to collection…"}),Ee.filter(C=>C.slug!=="_default_").map(C=>s.jsx("option",{value:C.collection_uid,children:C.name},C.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:yt,disabled:!B||z==="running",children:z==="running"?"…":z==="done"?"✓":z==="error"?"!":"Add"})]}),U&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"4px 0 0"},children:U})]}),l&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread")&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Actions"}),s.jsx("button",{className:"rail-rearchive-btn",onClick:jr,disabled:re==="running",children:re==="running"?"Re-archiving…":"Re-archive"}),re==="done"&&s.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),re==="error"&&s.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:Ae})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Un,children:"Delete entry"})})]})]})}const xg=/\/api\/archives\/([^/]+)\/entries\/([^/]+)\/artifacts\/(\d+)/;function wg(){return s.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[s.jsx("path",{d:"M5 17H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2"}),s.jsx("polygon",{points:"12 15 17 21 7 21 12 15"})]})}function kg({src:e,contentType:t="video/mp4"}){const n=c.useRef(null),[r,l]=c.useState(null),[i,a]=c.useState(!1),[o,u]=c.useState(!1);c.useEffect(()=>{if(!e){l(null);return}const g=e.match(xg);if(!g){l(e);return}let h=!1;return l(null),Em(g[1],g[2],parseInt(g[3],10)).then(({url:v})=>{h||l(v)}).catch(()=>{h||l(e)}),()=>{h=!0}},[e]),c.useEffect(()=>{n.current&&n.current.load()},[r]),c.useEffect(()=>{u(typeof HTMLVideoElement<"u"&&"webkitShowPlaybackTargetPicker"in HTMLVideoElement.prototype)},[]),c.useEffect(()=>{var h;const g=v=>{if(v)try{cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),a(!0)}catch{}};if((h=window.cast)!=null&&h.framework)g(!0);else if(window.__onGCastApiAvailable=g,!document.querySelector('script[src*="cast_sender"]')){const v=document.createElement("script");v.src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",document.head.appendChild(v)}},[]),c.useEffect(()=>{if(!i||!r)return;const g=cast.framework.CastContext.getInstance(),{CastContextEventType:h,SessionState:v}=cast.framework,x=N=>{if(!N)return;const p=new chrome.cast.media.MediaInfo(window.location.origin+r,t);N.loadMedia(new chrome.cast.media.LoadRequest(p)).catch(()=>{})};x(g.getCurrentSession());const S=N=>{(N.sessionState===v.SESSION_STARTED||N.sessionState===v.SESSION_RESUMED)&&x(g.getCurrentSession())};return g.addEventListener(h.SESSION_STATE_CHANGED,S),()=>g.removeEventListener(h.SESSION_STATE_CHANGED,S)},[i,r,t]);const d=()=>{var g,h;(h=(g=n.current)==null?void 0:g.webkitShowPlaybackTargetPicker)==null||h.call(g)},y=i||o;return s.jsx("div",{className:"preview-video-wrap",style:{position:"relative"},children:e?s.jsxs(s.Fragment,{children:[r?s.jsxs("video",{ref:n,controls:!0,autoPlay:!1,playsInline:!0,"x-webkit-airplay":"allow",style:{width:"100%",maxHeight:"100%",display:"block"},children:[s.jsx("source",{src:r}),"Your browser does not support the video element."]}):s.jsx("div",{className:"video-tv-loading","aria-label":"Loading video…"}),y&&r&&s.jsxs("div",{className:"video-tv-controls",children:[o&&s.jsx("button",{className:"video-tv-btn",title:"AirPlay to device","aria-label":"AirPlay to device",onClick:d,children:s.jsx(wg,{})}),i&&s.jsx("google-cast-launcher",{className:"video-tv-btn",title:"Cast to TV"})]})]}):s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function Du({src:e,type:t,title:n,originalUrl:r}){const l=r||e,i=n||null;return s.jsxs("div",{className:"preview-iframe-wrap",style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[s.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",flexDirection:"column",gap:"2px",padding:"6px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[i&&s.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--ink)",fontFamily:"var(--sans)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.78rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:l}),s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.78rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)",flexShrink:0},children:t==="pdf"?"Open PDF ↗":"Open in new tab ↗"})]})]}),s.jsx("iframe",{src:e,sandbox:"allow-same-origin allow-popups",allow:"autoplay 'none'",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%",minHeight:0},title:i||(t==="pdf"?"PDF preview":"Page preview")})]})}function jg({src:e,alt:t}){return s.jsx("div",{className:"preview-image-wrap",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",background:"var(--paper-2)",overflow:"hidden"},children:s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{display:"contents"},children:s.jsx("img",{src:e,alt:t||"",style:{objectFit:"contain",maxHeight:"100%",maxWidth:"100%",display:"block",cursor:"pointer"}})})})}function uf(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function Ou(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const ee={card:{background:"var(--paper)",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},threadOuter:{border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},tweetRow:{display:"flex",gap:"10px",padding:"10px 12px"},tweetRowThread:{display:"flex",gap:"10px",padding:"10px 12px 0"},leftCol:{display:"flex",flexDirection:"column",alignItems:"center",flexShrink:0,width:"36px"},rightCol:{flex:1,minWidth:0,paddingBottom:"8px"},avatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},avatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},threadLine:{flex:1,width:"2px",background:"var(--line-soft, var(--line))",margin:"4px 0",minHeight:"12px",borderRadius:"1px"},authorRow:{display:"flex",alignItems:"baseline",gap:"4px",flexWrap:"wrap",marginBottom:"4px",lineHeight:"1.3"},authorName:{fontWeight:"700",fontSize:"14px",color:"var(--ink)"},authorHandle:{fontSize:"13px",color:"var(--muted)"},datePart:{fontSize:"13px",color:"var(--muted)"},tweetText:{fontSize:"14px",lineHeight:"1.5",color:"var(--ink)",whiteSpace:"pre-line",marginBottom:"8px",wordBreak:"break-word"},stats:{display:"flex",gap:"12px",fontSize:"13px",color:"var(--muted)"},link:{color:"var(--accent)",textDecoration:"none"},loading:{padding:"24px 16px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},error:{padding:"24px 16px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},mediaGrid:{marginBottom:"8px",borderRadius:"10px",overflow:"hidden",border:"1px solid var(--line)"},mediaImg:{display:"block",width:"100%",objectFit:"cover",maxHeight:"260px"},mediaVideo:{display:"block",width:"100%",maxHeight:"260px",background:"#000"},article:{maxWidth:"560px",margin:"0 auto",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"280px"},aMeta:{padding:"10px 14px 0"},aTweetTitle:{fontSize:"20px",fontWeight:"800",letterSpacing:"-0.3px",color:"var(--ink)",lineHeight:"1.3",marginBottom:"8px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},aAvatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},aAuthorName:{fontSize:"14px",fontWeight:"700",color:"var(--ink)",lineHeight:"1.3"},aAuthorSub:{fontSize:"13px",color:"var(--muted)",lineHeight:"1.3"},aDivider:{border:"none",borderTop:"1px solid var(--line)",margin:"0"},aBody:{padding:"4px 14px 16px"},bH1:{fontSize:"22px",fontWeight:"800",letterSpacing:"-0.4px",color:"var(--ink)",lineHeight:"1.25",margin:"16px 0 6px"},bH2:{fontSize:"18px",fontWeight:"700",letterSpacing:"-0.2px",color:"var(--ink)",lineHeight:"1.3",margin:"14px 0 4px"},bP:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.65",marginBottom:"12px",marginTop:"0"},bSpacer:{height:"4px",display:"block"},bQuote:{borderLeft:"3px solid var(--line)",padding:"2px 12px",margin:"12px 0",color:"var(--muted)",fontSize:"15px",lineHeight:"1.6"},bHr:{border:"none",borderTop:"1px solid var(--line)",margin:"14px 0"},bImg:{width:"100%",display:"block",borderRadius:"8px",margin:"12px 0"},bUl:{margin:"8px 0 12px",paddingLeft:"24px"},bOl:{margin:"8px 0 12px",paddingLeft:"24px"},bLi:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.6",marginBottom:"4px"},bTweet:{display:"flex",alignItems:"center",gap:"10px",border:"1px solid var(--line)",borderRadius:"10px",padding:"10px 14px",margin:"12px 0",color:"var(--muted)",fontSize:"14px",textDecoration:"none"},bMdPre:{borderRadius:"8px",margin:"10px 0",overflow:"auto",background:"var(--paper-3, var(--field))",padding:"12px 14px"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"12px",lineHeight:"1.6",color:"var(--ink)",background:"transparent",display:"block"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:"var(--paper-3, var(--field))",padding:"1px 5px",borderRadius:"4px",color:"var(--ink)"},qtBadge:{fontSize:"11px",color:"var(--muted)",display:"inline-flex",alignItems:"center",gap:"2px",marginLeft:"4px",letterSpacing:"0.03em",flexShrink:0},lightboxBackdrop:{position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.92)",display:"flex",alignItems:"center",justifyContent:"center",padding:"20px"},lightboxContent:{display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",maxWidth:"90vw",maxHeight:"90vh"},lightboxToolbar:{display:"flex",alignItems:"center",gap:"10px",alignSelf:"flex-end"},lightboxImg:{maxWidth:"88vw",maxHeight:"80vh",objectFit:"contain",borderRadius:"6px",display:"block"},lightboxNav:{display:"flex",gap:"12px",alignItems:"center"},lightboxNavBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"20px",cursor:"pointer",borderRadius:"50%",width:"36px",height:"36px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"16px",cursor:"pointer",borderRadius:"50%",width:"30px",height:"30px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxLink:{color:"rgba(255,255,255,0.7)",textDecoration:"none",fontSize:"14px"},lightboxCounter:{color:"rgba(255,255,255,0.6)",fontSize:"13px"}},$e={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},ji={article:{background:$e.bg,color:$e.text,minHeight:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'},articleInner:{maxWidth:"598px",margin:"0 auto",paddingBottom:"80px"},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"420px"},aMeta:{padding:"20px 16px 0"},aTweetTitle:{fontSize:"34px",fontWeight:"800",letterSpacing:"-0.5px",color:$e.text,lineHeight:"44px",marginBottom:"16px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"16px"},aAvatar:{width:"40px",height:"40px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"40px",height:"40px",borderRadius:"50%",background:$e.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:$e.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:$e.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${$e.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:$e.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:$e.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:$e.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${$e.border}`,padding:"2px 14px",margin:"14px 0",color:$e.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${$e.border}`,margin:"28px 0"},bImg:{width:"100%",display:"block",borderRadius:"12px",margin:"16px 0"},bUl:{margin:"10px 0 16px",paddingLeft:"28px"},bOl:{margin:"10px 0 16px",paddingLeft:"28px"},bLi:{fontSize:"17px",color:$e.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${$e.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:$e.dim,fontSize:"15px",textDecoration:"none"},bMdPre:{borderRadius:"12px",margin:"12px 0",overflow:"auto",background:"#1e2029"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"13px",lineHeight:"1.65",padding:"18px 20px",display:"block",color:$e.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:$e.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:$e.accent,textDecoration:"none"}};function Sg(e,t,n){const r={};return n&&n.forEach((l,i)=>{l.relpath&&(r[l.relpath]=`/api/archives/${e}/entries/${t}/artifacts/${i}`)}),r}function dr(e,t,n){return e&&n[e]?n[e]:t||null}function cf(){return s.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",style:{flexShrink:0,color:"var(--ink)"},children:s.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.748l7.73-8.835L1.254 2.25H8.08l4.259 5.63L18.244 2.25zm-1.161 17.52h1.833L7.084 4.126H5.117L17.083 19.77z"})})}function mo(e,t,...n){var r;if(e.fromIndex!=null&&e.toIndex!=null)return{s:e.fromIndex,e:e.toIndex};if(((r=e.indices)==null?void 0:r.length)===2)return{s:e.indices[0],e:e.indices[1]};if(t)for(const l of n){if(!l)continue;const i=t.indexOf(l);if(i!==-1)return{s:i,e:i+l.length}}return null}function df(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=mo(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function ff(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=mo(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const Au=/https?:\/\/[^\s<>"'\])]+/g,Ng=/[.,;:!?)()]+$/;function Ns(e,t){const n=[];let r=0,l;for(Au.lastIndex=0;(l=Au.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(Ng,"");n.push(s.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:t,children:i},l.index));const a=l[0].slice(i.length);a&&n.push(a),r=l.index+l[0].length}return r===0?e:(rdf(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>ff(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return Ns(Ou(e),ee.link);const l=new Set([0,e.length]);for(const o of r)o.s>=0&&o.s<=e.length&&l.add(o.s),o.e>=0&&o.e<=e.length&&l.add(o.e);for(const[o,u]of n)o>=0&&o<=e.length&&l.add(o),u>=0&&u<=e.length&&l.add(u);const i=(o,u)=>n.some(([d,y])=>d<=o&&y>=u),a=[...l].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const d=a[u+1];if(i(o,d))return null;const y=e.slice(o,d),g=r.filter(x=>x.s<=o&&x.e>=d),h=g.find(x=>x.kind==="url");if(h)return s.jsx("a",{href:h.href,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:h.display||y},u);const v=g.find(x=>x.kind==="mention");return v?s.jsx("a",{href:`https://x.com/${v.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:y},u):s.jsx("span",{children:Ns(Ou(y),ee.link)},u)}).filter(o=>o!==null)}function Cg(e,t,n,r,l=ee){if(!e)return null;t=t||[],n=n||[],r=r||[];const i=[];for(const u of t)u.length>0&&i.push({s:u.offset,e:u.offset+u.length,kind:"style",style:u.style});for(const u of n){const d=df(u,e);d&&i.push(d)}for(const u of r){const d=ff(u,e);d&&i.push(d)}if(i.length===0)return Ns(e,l.link);const a=new Set([0,e.length]);for(const u of i)u.s>=0&&u.s<=e.length&&a.add(u.s),u.e>=0&&u.e<=e.length&&a.add(u.e);const o=[...a].sort((u,d)=>u-d);return o.slice(0,-1).map((u,d)=>{const y=o[d+1],g=i.filter(N=>N.s<=u&&N.e>=y),h=e.slice(u,y);let v;if(h.includes(`
`)){const N=h.split(`
-`);v=N.flatMap((p,f)=>fN.kind==="style"&&N.style==="Code")&&(v=s.jsx("code",{style:l.iCode,children:v})),g.some(N=>N.kind==="style"&&N.style==="Bold")&&(v=s.jsx("strong",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Italic")&&(v=s.jsx("em",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Underline")&&(v=s.jsx("u",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Strikethrough")&&(v=s.jsx("s",{children:v}));const x=g.find(N=>N.kind==="url");if(x){const N=/^https?:\/\/t\.co\//i.test(v);v=s.jsx("a",{href:x.href,target:"_blank",rel:"noopener noreferrer",style:l.link,children:N?x.display:v})}const S=g.find(N=>N.kind==="mention");return S&&(v=s.jsx("a",{href:`https://x.com/${S.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:l.link,children:v})),s.jsx("span",{children:typeof v=="string"?Ns(v,l.link):v},d)})}function Ng(e,t,n){const r=(n==null?void 0:n.st)||ee,l=e.resolved_entities||[];return l.length===0?null:l.map((i,a)=>{var o;switch(i.type){case"divider":return s.jsx("hr",{style:r.bHr},a);case"media":{const u=dr(i.local_path,i.url,t);return u?s.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:d=>{var y;!d.metaKey&&!d.ctrlKey&&(d.preventDefault(),(y=n==null?void 0:n.onImgClick)==null||y.call(n,u))},children:s.jsx("img",{src:u,style:r.bImg,loading:"lazy",alt:""})},a):null}case"tweet":return i.tweet_id?s.jsxs("a",{href:`https://x.com/i/status/${i.tweet_id}`,target:"_blank",rel:"noopener noreferrer",style:r.bTweet,children:[s.jsx(af,{}),"View post on X"]},a):null;case"link":return i.url?s.jsx("p",{style:r.bP,children:s.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",style:r.link,children:i.url})},a):null;case"markdown":{const u=i.markdown??((o=i.data)==null?void 0:o.markdown)??"";return s.jsx("pre",{style:r.bMdPre,children:s.jsx("code",{style:r.bMdCode,children:u})},a)}case"emoji":return i.url?s.jsx("img",{src:i.url,alt:"",style:{height:"1.2em",verticalAlign:"middle",margin:"0 1px"}},a):null;default:return null}})}function Si(e,t,n,r){const l=(r==null?void 0:r.st)||ee,i=e.type||"",a=e.text||"",o=e.inline_style_ranges||[],u=e.data||{},d=Sg(a,o,u.urls||[],u.mentions||[],l);switch(i){case"header-one":return s.jsx("h1",{style:l.bH1,children:d},t);case"header-two":{const y=a.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return y?s.jsxs("a",{href:`https://x.com/i/status/${y[1]}`,target:"_blank",rel:"noopener noreferrer",style:l.bTweet,children:[s.jsx(af,{}),"View post on X"]},t):s.jsx("h2",{style:l.bH2,children:d},t)}case"unstyled":return a.trim()?s.jsx("p",{style:l.bP,children:d},t):s.jsx("span",{style:l.bSpacer},t);case"blockquote":return s.jsx("blockquote",{style:l.bQuote,children:d},t);case"unordered-list-item":case"ordered-list-item":return s.jsx("li",{style:l.bLi,children:d},t);case"atomic":return s.jsx("span",{children:Ng(e,n,r)},t);default:return a?s.jsx("p",{style:l.bP,children:d},t):null}}function _g(e,t,n){const r=(n==null?void 0:n.st)||ee,l=[];let i=0;for(;i{r&&(l==null||l(!0))},[r,l]);const o=r?ji:ee,u=e.cover_media||{},d=e.author||t||{},y=e.first_published_at_secs?sf(e.first_published_at_secs):"",h=[d.screen_name?`@${d.screen_name}`:"",y].filter(Boolean).join(" · "),v=dr(u.local_path,u.url,n),x=dr(d.avatar_local_path,d.avatar_url,n),S=s.jsxs(s.Fragment,{children:[i&&s.jsx(cf,{items:[{src:i,alt:""}],startIndex:0,onClose:()=>a(null)}),v&&s.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:N=>{!N.metaKey&&!N.ctrlKey&&(N.preventDefault(),a(v))},children:s.jsx("img",{src:v,style:o.aCover,alt:"Article cover"})}),s.jsxs("div",{style:o.aMeta,children:[e.title&&s.jsx("div",{style:o.aTweetTitle,children:e.title}),s.jsxs("div",{style:o.aAuthorRow,children:[x?s.jsx("img",{src:x,style:o.aAvatar,alt:d.name||""}):s.jsx("div",{style:o.aAvatarPh}),s.jsxs("div",{children:[s.jsx("div",{style:o.aAuthorName,children:d.name||d.screen_name||"Unknown"}),h&&s.jsx("div",{style:o.aAuthorSub,children:h})]})]})]}),s.jsx("hr",{style:o.aDivider}),s.jsx("div",{style:o.aBody,children:_g(e.blocks||[],n,{onImgClick:a,st:o})})]});return r?s.jsx("div",{style:ji.article,children:s.jsx("div",{style:ji.articleInner,children:S})}):s.jsx("div",{style:ee.article,children:S})}function Eg({photos:e,onOpen:t}){const n=e.length;if(n===0)return null;if(n===1)return s.jsx("a",{href:e[0].src,target:"_blank",rel:"noopener noreferrer",style:{display:"block"},onClick:l=>{!l.metaKey&&!l.ctrlKey&&(l.preventDefault(),t(0))},children:s.jsx("img",{src:e[0].src,alt:e[0].alt||"",style:ee.mediaImg,loading:"lazy"})});const r=n<=2?"180px":"140px";return s.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gridTemplateRows:n===2?r:`${r} ${r}`,gap:"2px"},children:e.map((l,i)=>s.jsx("a",{href:l.src,target:"_blank",rel:"noopener noreferrer",style:{display:"block",overflow:"hidden",gridRow:n===3&&i===0?"span 2":void 0},onClick:a=>{!a.metaKey&&!a.ctrlKey&&(a.preventDefault(),t(i))},children:s.jsx("img",{src:l.src,alt:l.alt||"",loading:"lazy",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},i))})}function cf({items:e,startIndex:t,onClose:n}){const[r,l]=c.useState(t);c.useEffect(()=>{const a=o=>{(o.key==="Escape"||o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.stopPropagation(),o.preventDefault()),o.key==="Escape"&&n(),o.key==="ArrowRight"&&l(u=>Math.min(u+1,e.length-1)),o.key==="ArrowLeft"&&l(u=>Math.max(u-1,0))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[n,e.length]);const i=e[r];return s.jsx("div",{style:ee.lightboxBackdrop,onClick:n,children:s.jsxs("div",{style:ee.lightboxContent,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{style:ee.lightboxToolbar,children:[e.length>1&&s.jsxs("span",{style:ee.lightboxCounter,children:[r+1," / ",e.length]}),s.jsx("a",{href:i.src,target:"_blank",rel:"noopener noreferrer",style:ee.lightboxLink,title:"Open in new tab",children:"↗"}),s.jsx("button",{style:ee.lightboxBtn,onClick:n,"aria-label":"Close",children:"×"})]}),s.jsx("img",{src:i.src,alt:i.alt||"",style:ee.lightboxImg}),e.length>1&&s.jsxs("div",{style:ee.lightboxNav,children:[s.jsx("button",{style:ee.lightboxNavBtn,onClick:()=>l(a=>Math.max(a-1,0)),disabled:r===0,children:"‹"}),s.jsx("button",{style:ee.lightboxNavBtn,onClick:()=>l(a=>Math.min(a+1,e.length-1)),disabled:r===e.length-1,children:"›"})]})]})})}function Au({tweet:e,isInThread:t,isLast:n,artifactMap:r}){var f,m;const[l,i]=c.useState(null),a=e.author||{},o=e.created_at_secs?sf(e.created_at_secs):"",u=e.entities||{},d=dr(a.avatar_local_path,a.avatar_url,r),y=t&&!n,g=e.is_quote_status===!0,h=t?ee.tweetRowThread:ee.tweetRow,v=e.full_text||"",x=((m=(f=e.extended_entities)==null?void 0:f.media)!=null&&m.length?e.extended_entities.media:u.media)||[],S=[],N=[];for(const k of x)if(k.type==="photo"){const E=dr(k.local_path,k.media_url_https,r);E&&S.push({kind:"photo",src:E,alt:k.alt_text||""})}else if(k.type==="video"||k.type==="animated_gif"){const E=k.local_path&&r[k.local_path]||(()=>{var T,j;return(j=(((T=k.video_info)==null?void 0:T.variants)||[]).filter(P=>P.content_type==="video/mp4").sort((P,R)=>(R.bitrate||0)-(P.bitrate||0))[0])==null?void 0:j.url})();E&&N.push({kind:k.type==="animated_gif"?"gif":"video",src:E})}const p=[];for(const k of x){if(!k.url||!(k.type==="photo"?S.some(T=>T.src===dr(k.local_path,k.media_url_https,r)):N.length>0))continue;const b=mo(k,v,k.url);b&&p.push([b.s,b.e])}return s.jsxs(s.Fragment,{children:[l!==null&&s.jsx(cf,{items:S,startIndex:l,onClose:()=>i(null)}),s.jsxs("div",{style:h,children:[s.jsxs("div",{style:ee.leftCol,children:[d?s.jsx("img",{src:d,style:ee.avatar,alt:a.name||""}):s.jsx("div",{style:ee.avatarPh}),y&&s.jsx("div",{style:ee.threadLine})]}),s.jsxs("div",{style:ee.rightCol,children:[s.jsxs("div",{style:ee.authorRow,children:[s.jsx("span",{style:ee.authorName,children:a.name||a.screen_name||"Unknown"}),a.screen_name&&s.jsxs("span",{style:ee.authorHandle,children:["@",a.screen_name]}),o&&s.jsxs("span",{style:ee.datePart,children:["· ",o]}),g&&s.jsx("span",{style:ee.qtBadge,title:"Quote tweet",children:"↻ QT"})]}),s.jsx("div",{style:ee.tweetText,children:jg(v,u,p)}),S.length>0&&s.jsx("div",{style:ee.mediaGrid,children:s.jsx(Eg,{photos:S,onOpen:k=>i(k)})}),N.map((k,E)=>s.jsx("div",{style:ee.mediaGrid,children:s.jsx("video",{src:k.src,style:ee.mediaVideo,controls:!0,loop:k.kind==="gif",muted:k.kind==="gif",autoPlay:k.kind==="gif"})},E)),(e.retweet_count>0||e.favorite_count>0)&&s.jsxs("div",{style:ee.stats,children:[e.favorite_count>0&&s.jsxs("span",{children:["❤️ ",e.favorite_count.toLocaleString()]}),e.retweet_count>0&&s.jsxs("span",{children:["🔁 ",e.retweet_count.toLocaleString()]})]})]})]})]})}function bg({archiveId:e,entryUid:t,artifacts:n,entityKind:r,fullPage:l,onXArticle:i}){const[a,o]=c.useState(!0),[u,d]=c.useState(null),[y,g]=c.useState([]);if(c.useEffect(()=>{if(o(!0),d(null),g([]),!n||!e||!t){o(!1);return}const x=n.map((N,p)=>({...N,index:p})).filter(N=>N.artifact_role==="raw_tweet_json");if(x.length===0){d("No tweet data found."),o(!1);return}let S=!1;return Uh(e,t,x.map(N=>N.index)).then(async N=>{if(S)return;const p=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,f=T=>{var P;const j=T.full_text||"";return(((P=T.entities)==null?void 0:P.urls)||[]).map(R=>{var G;if(R.fromIndex!=null&&R.toIndex!=null)return[R.fromIndex,R.toIndex];if(((G=R.indices)==null?void 0:G.length)===2)return[R.indices[0],R.indices[1]];if(R.url){const H=j.indexOf(R.url);if(H!==-1)return[H,H+R.url.length]}return null}).filter(Boolean)},m=(T,j,P)=>T.some(([R,G])=>R<=j&&G>=P),k=new Set;for(const T of N){const j=T.full_text||"",P=f(T);let R;for(p.lastIndex=0;(R=p.exec(j))!==null;)m(P,R.index,R.index+R[0].length)||k.add(R[0])}const E=k.size>0?await Hh([...k]).catch(()=>({})):{},b=N.map(T=>{var H;const j=T.full_text||"",P=f(T),R=[];let G;for(p.lastIndex=0;(G=p.exec(j))!==null;){const Z=G[0],re=E[Z];re&&re!==Z&&!m(P,G.index,G.index+Z.length)&&R.push({url:Z,expanded_url:re,display_url:(()=>{try{const ce=new URL(re);return ce.hostname+(ce.pathname.length>1?"/…":"")}catch{return re}})(),fromIndex:G.index,toIndex:G.index+Z.length})}return R.length===0?T:{...T,entities:{...T.entities||{},urls:[...((H=T.entities)==null?void 0:H.urls)||[],...R]}}});S||g(b)}).catch(N=>{S||d(N.message||"Failed to load tweet.")}).finally(()=>{S||o(!1)}),()=>{S=!0}},[e,t,n]),a)return s.jsx("div",{style:ee.loading,children:"Loading…"});if(u)return s.jsxs("div",{style:ee.error,children:["Error: ",u]});if(y.length===0)return null;const h=wg(e,t,n);if(r==="tweet_thread")return s.jsx("div",{style:ee.threadOuter,children:y.map((x,S)=>s.jsx(Au,{tweet:x,isInThread:!0,isLast:S===y.length-1,artifactMap:h},x.id||S))});const v=y[0];return v.is_article&&v.article?s.jsx(Cg,{article:v.article,tweetAuthor:v.author,artifactMap:h,fullPage:l,onXArticle:i}):s.jsx("div",{style:ee.card,children:s.jsx(Au,{tweet:v,isInThread:!1,isLast:!0,artifactMap:h})})}function Tg({src:e,mime:t,title:n}){const[r,l]=c.useState(null),[i,a]=c.useState(null);return c.useEffect(()=>{let o=!1;return l(null),a(null),fetch(e,{credentials:"same-origin"}).then(u=>{if(!u.ok)throw new Error(`HTTP ${u.status}`);return u.text()}).then(u=>{o||l(u)}).catch(u=>{o||a(u.message||String(u))}),()=>{o=!0}},[e]),i?s.jsxs("div",{className:"text-preview text-preview--error",children:["Failed to load text: ",i]}):r===null?s.jsx("div",{className:"text-preview text-preview--loading",children:"Loading…"}):s.jsxs("div",{className:"text-preview",children:[n&&s.jsx("h1",{className:"text-preview__title",children:n}),s.jsx("pre",{className:"text-preview__body",children:r}),t&&s.jsx("div",{className:"text-preview__mime",children:t})]})}const Pg=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),Lg=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),Rg=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]),zg=new Set(["md","markdown","txt"]),Ig={mp4:"video/mp4",webm:"video/webm",mov:"video/quicktime",mkv:"video/x-matroska",avi:"video/x-msvideo",m4v:"video/mp4",ogv:"video/ogg"};function df({archiveId:e,entry:t,detail:n,fullPage:r,onXArticle:l}){if(!t)return s.jsx("div",{className:"preview-panel preview-panel--empty",children:s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Select an entry to preview"})});if(!n)return s.jsx("div",{className:"preview-panel preview-panel--loading",children:s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Loading…"})});const{summary:i,artifacts:a}=n,o=i.entry_uid,u=i.entity_kind;if(u==="tweet"||u==="tweet_thread"){const v=s.jsx(bg,{archiveId:e,entryUid:o,artifacts:a,entityKind:u,fullPage:r,onXArticle:l});return r?v:s.jsx("div",{className:"preview-tweet-wrap",children:v})}const d=a.findIndex(v=>v.artifact_role==="primary_media");if(d===-1)return s.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),a.length>0&&s.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((v,x)=>s.jsxs("li",{children:[v.artifact_role,": ",v.relpath]},x))})]});const y=a[d],g=`/api/archives/${e}/entries/${o}/artifacts/${d}`,h=y.relpath.split(".").pop().toLowerCase();return Pg.has(h)?s.jsx("div",{className:"preview-panel",children:s.jsx(vg,{src:g,contentType:Ig[h]||"video/mp4"})}):Lg.has(h)?s.jsxs("div",{className:"preview-panel preview-panel--audio",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"12px",padding:"24px",fontFamily:"var(--sans)"},children:[s.jsx("span",{style:{fontSize:"2rem"},children:"🎵"}),s.jsx("span",{style:{color:"var(--ink)",fontSize:"0.95rem",fontWeight:600},children:i.title||o}),s.jsx("audio",{src:g,controls:!0,style:{marginTop:"8px",width:"100%",maxWidth:"400px"}})]}):h==="pdf"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx($u,{src:g,type:"pdf",title:i.title,originalUrl:i.original_url})}):h==="html"||h==="htm"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx($u,{src:g,type:"page",title:i.title,originalUrl:i.original_url})}):zg.has(h)?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0,overflow:"auto"},children:s.jsx(Tg,{src:g,mime:y.mime_type,title:i.title})}):Rg.has(h)?s.jsx("div",{className:"preview-panel",style:{height:"100%"},children:s.jsx(xg,{src:g,alt:i.title||"Image"})}):s.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),s.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((v,x)=>s.jsxs("li",{children:[v.artifact_role,": ",v.relpath]},x))})]})}function $g({archiveId:e,entry:t,detail:n,onClose:r}){var l,i;return c.useEffect(()=>{const a=o=>{o.key==="Escape"&&r()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r]),s.jsx("div",{className:"preview-modal-backdrop",onClick:r,children:s.jsxs("div",{className:`preview-modal${((l=n==null?void 0:n.summary)==null?void 0:l.entity_kind)==="tweet"||((i=n==null?void 0:n.summary)==null?void 0:i.entity_kind)==="tweet_thread"?"":" preview-modal--full"}`,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{className:"preview-modal-header",children:[s.jsx("span",{className:"preview-modal-title",children:(t==null?void 0:t.title)||(t==null?void 0:t.entry_uid)||"Preview"}),s.jsx("a",{className:"preview-modal-newtab",href:`/preview/${e}/${t==null?void 0:t.entry_uid}`,target:"_blank",rel:"noopener noreferrer",title:"Open in new tab",children:"↗"}),s.jsx("button",{className:"preview-modal-close",onClick:r,"aria-label":"Close preview",children:"×"})]}),s.jsx("div",{className:"preview-modal-body",children:s.jsx(df,{archiveId:e,entry:t,detail:n})})]})})}function Mu(e){if(!isFinite(e)||isNaN(e))return"--:--";const t=Math.floor(e/60),n=Math.floor(e%60);return`${t}:${String(n).padStart(2,"0")}`}function Dg({entry:e,src:t,archiveId:n,onClose:r}){const l=c.useRef(null),[i,a]=c.useState(!1),[o,u]=c.useState(0),[d,y]=c.useState(NaN),[g,h]=c.useState(1);c.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),y(NaN),a(!1))},[t]),c.useEffect(()=>{l.current&&(l.current.volume=g)},[g]);function v(){const f=l.current;f&&(i?f.pause():f.play().catch(()=>{}))}function x(f){const m=l.current;if(!m||!isFinite(d))return;const k=Number(f.target.value);m.currentTime=k,u(k)}function S(f){h(Number(f.target.value))}const N=(e==null?void 0:e.title)||(e==null?void 0:e.entry_uid)||"Unknown",p=(e==null?void 0:e.source_kind)||"other";return s.jsxs(s.Fragment,{children:[s.jsx("audio",{ref:l,src:t||void 0,preload:"auto",onPlay:()=>a(!0),onPause:()=>a(!1),onEnded:()=>a(!1),onTimeUpdate:()=>{var f;return u(((f=l.current)==null?void 0:f.currentTime)??0)},onLoadedMetadata:()=>{var f;return y(((f=l.current)==null?void 0:f.duration)??NaN)},onDurationChange:()=>{var f;return y(((f=l.current)==null?void 0:f.duration)??NaN)},style:{display:"none"}}),s.jsxs("div",{className:"audio-bar",style:{position:"fixed",bottom:0,left:0,right:0,zIndex:100,background:"var(--paper-3)",borderTop:"1px solid var(--line)",display:"flex",alignItems:"center",gap:"16px",padding:"0 16px",height:"56px",fontFamily:"var(--sans)"},children:[s.jsxs("div",{className:"audio-bar-info",style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flex:"0 1 220px",overflow:"hidden"},children:[s.jsx("span",{className:"source-icon",style:{flexShrink:0,width:"18px",height:"18px",display:"flex",alignItems:"center"},dangerouslySetInnerHTML:{__html:Bs(p)}}),s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:N,children:N})]}),s.jsxs("div",{className:"audio-bar-controls",style:{display:"flex",alignItems:"center",gap:"10px",flex:"1 1 0",minWidth:0},children:[s.jsx("button",{onClick:v,"aria-label":i?"Pause":"Play",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--ink)",flexShrink:0,fontSize:"1.2rem",lineHeight:1},children:i?"⏸":"▶"}),s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:Mu(o)}),s.jsx("input",{type:"range",min:0,max:isFinite(d)?d:0,step:.1,value:isFinite(o)?o:0,onChange:x,"aria-label":"Seek",style:{flex:1,minWidth:0,accentColor:"var(--accent)"}}),s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:Mu(d)})]}),s.jsxs("div",{className:"audio-bar-right",style:{display:"flex",alignItems:"center",gap:"8px",flex:"0 1 160px"},children:[s.jsx("span",{style:{fontSize:"0.85rem",color:"var(--muted)",flexShrink:0},children:"🔊"}),s.jsx("input",{type:"range",min:0,max:1,step:.01,value:g,onChange:S,"aria-label":"Volume",style:{width:"80px",accentColor:"var(--accent)"}}),s.jsx("button",{onClick:r,"aria-label":"Close audio player",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--muted)",fontSize:"1rem",lineHeight:1,marginLeft:"4px"},children:"✕"})]})]})]})}function Og({archiveId:e,entryUid:t}){var h,v;const[n,r]=c.useState(null),[l,i]=c.useState(!0),[a,o]=c.useState(null),[u,d]=c.useState(!1);c.useEffect(()=>{if(!u)return;const x=document.documentElement,S=document.body,N=x.style.colorScheme,p=S.style.background;return x.style.colorScheme="dark",S.style.background="#000",()=>{x.style.colorScheme=N,S.style.background=p}},[u]),c.useEffect(()=>{d(!1),Or(e,t).then(x=>{r(x),i(!1)}).catch(x=>{o((x==null?void 0:x.message)||"Failed to load entry"),i(!1)})},[e,t]);const y=((h=n==null?void 0:n.summary)==null?void 0:h.title)||t,g=(v=n==null?void 0:n.summary)==null?void 0:v.original_url;return s.jsxs("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column",background:u?"#000":"var(--paper)",fontFamily:"var(--sans)"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:u?"8px 12px":"10px 16px",borderBottom:u?"none":"1px solid var(--line)",flexShrink:0,position:u?"sticky":"relative",top:0,zIndex:20,background:u?"rgba(0,0,0,0.82)":"var(--paper-2)",backdropFilter:u?"blur(12px)":"none",WebkitBackdropFilter:u?"blur(12px)":"none"},children:[s.jsx("a",{href:"/",style:{color:u?"#1d9bf0":"var(--accent)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"← Archive"}),s.jsx("span",{style:{flex:1,fontSize:"14px",fontWeight:600,color:u?"#e7e9ea":"var(--ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),g&&s.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{color:u?"#71767b":"var(--muted)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"Original ↗"})]}),s.jsxs("div",{style:u?{flex:1}:{flex:1,minHeight:0,overflow:"auto",display:"flex",flexDirection:"column"},children:[l&&s.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},children:"Loading…"}),a&&s.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},children:a}),n&&s.jsx(df,{archiveId:e,entry:n.summary,detail:n,fullPage:!0,onXArticle:d})]})]})}const Ag=7e3;function Mg({toasts:e,onDismiss:t,onIgnoreUblock:n}){return e.length?s.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(r=>s.jsx(Bg,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function Fg(e){if(!e)return null;if(e.length<=52)return e;try{const{hostname:t,pathname:n,search:r}=new URL(e),l=n.split("/").filter(Boolean),i=(l[l.length-1]??"")+r,a=i?`${t}/…/${i}`:t;return a.length<=56?a:a.slice(0,53)+"…"}catch{return"…"+e.slice(-51)}}function Bg({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=c.useState(!1),i=e.type==="warning",a=e.type==="success";c.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),Ag);return()=>clearTimeout(u)},[r,e.id,t]);const o=Fg(e.locator);return a?s.jsx("div",{className:"toast toast--success",role:"alert","aria-atomic":"true",children:s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✓"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsx("div",{className:"toast-btns",children:s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})})]})}):i?s.jsxs("div",{className:"toast toast--warning",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"⚠"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived with warnings"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),"aria-expanded":r,children:r?"Hide":"Details"}),e.locator&&s.jsx("button",{type:"button",className:"toast-view-btn toast-ignore-btn",onClick:()=>{n==null||n(),t(e.id)},children:"Ignore"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&s.jsx("p",{className:"toast-warning-detail",children:e.text||"The page was captured but one or more browser extensions were unavailable (ad-blocking or cookie-consent). Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config."})]}):s.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Capture failed"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),children:r?"Hide":"View error"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&e.text&&s.jsx("pre",{className:"toast-error-detail",children:e.text})]})}const Us=c.createContext(null),Ug=["archive","tags","collections","runs","admin","settings"],Hg=["profile","tokens","instance","cookies","extensions","storage"],Rr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})();function Mt(){const e=window.location.pathname.split("/").filter(Boolean),t=Ug.includes(e[0])?e[0]:"archive",n=t==="settings"&&Hg.includes(e[1])?e[1]:"profile",r=new URLSearchParams(window.location.search),l=r.get("q")??"",i=t==="archive"?r.get("tag")??null:null,a=t==="archive"?r.get("entry")??null:null,o=t==="archive"?r.get("collection")??null:null,u=o==="main"?null:o,d=r.get("archive")??null;return{view:t,settingsTab:n,q:l,tag:i,entry:a,collection:u,archive:d}}function Wg(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function Vg(){const[e,t]=c.useState("loading"),[n,r]=c.useState(null);c.useEffect(()=>{(async()=>{var D,q,Y;if(await em()){t("setup");return}const I=await lm();if(!I){const{collection:se,archive:C}=Mt();try{const Q=await _u(),X=C?((D=Q.find(at=>at.id===C))==null?void 0:D.id)??((q=Q[0])==null?void 0:q.id):(Y=Q[0])==null?void 0:Y.id;if(X){await Cu(X,se),i(Q),o(X),d(se),t("authenticated");return}}catch{}t("login");return}r(I),t("authenticated")})()},[]),c.useEffect(()=>{const _=()=>{n&&(r(null),t("login"))};return window.addEventListener("auth:expired",_),()=>window.removeEventListener("auth:expired",_)},[n]),c.useEffect(()=>{const _=()=>{const{view:I,settingsTab:D,q,tag:Y,entry:se,collection:C}=Mt();P(I),G(D),Z(q),T(Y),p(se),m(null),E(se?new Set([se]):new Set),d(C)};return window.addEventListener("popstate",_),()=>window.removeEventListener("popstate",_)},[]);const[l,i]=c.useState([]),[a,o]=c.useState(null),[u,d]=c.useState(()=>Mt().collection),[y,g]=c.useState([]),[h,v]=c.useState([]),[x,S]=c.useState(()=>new Set),[N,p]=c.useState(()=>Mt().entry),[f,m]=c.useState(null),[k,E]=c.useState(()=>{const _=Mt().entry;return _?new Set([_]):new Set}),[b,T]=c.useState(()=>Mt().tag),[j,P]=c.useState(()=>Mt().view),[R,G]=c.useState(()=>Mt().settingsTab),[H,Z]=c.useState(()=>Mt().q),[re,ce]=c.useState(""),[De,ye]=c.useState(!1),[A,L]=c.useState([]),[V,K]=c.useState([]),[te,Oe]=c.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[ne,we]=c.useState([]),oe=c.useRef(0),[Ne,$t]=c.useState(()=>{try{const _=JSON.parse(sessionStorage.getItem("pendingCaptures")||"[]");if(Array.isArray(_))return _}catch{}return[]});c.useEffect(()=>{sessionStorage.setItem("pendingCaptures",JSON.stringify(Ne))},[Ne]);const[Dt,_t]=c.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[Fe,Ct]=c.useState(null),mt=c.useRef(0),st=c.useRef(null),Et=c.useRef(!1),O=c.useRef(!0),J=c.useRef(null),ve=c.useRef(0),Ce=c.useRef(new Map),Wt=(n==null?void 0:n.humanize_slugs)??!1;c.useEffect(()=>{const _=++mt.current;Ct(null),!(!f||!a)&&Or(a,f.entry_uid).then(I=>{_===mt.current&&Ct(I)}).catch(()=>{})},[f,a]),c.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",te)},[te]);const Re=c.useCallback(async(_,I,D,q)=>{if(_){ye(!0);try{let Y;I||D?Y=await Ah(_,I,D,q):Y=await Cu(_,q),v(Y),E(se=>{if(se.size<2)return se;const C=new Set(Y.map(X=>X.entry_uid)),Q=new Set([...se].filter(X=>C.has(X)));return Q.size===se.size?se:Q}),ce(Y.length===0?"No results":`${Y.length} result${Y.length===1?"":"s"}`)}catch{v([]),ce("Search failed. Try again.")}finally{ye(!1)}}},[]);c.useEffect(()=>{e==="authenticated"&&(a||_u().then(_=>{if(i(_),_.length>0){const{archive:I}=Mt(),D=I?_.find(q=>q.id===I):null;o((D==null?void 0:D.id)??_[0].id)}}))},[e,a]),c.useEffect(()=>{if(!a)return;const _=!n;if(O.current){O.current=!1;const D=[];_||(D.push(vi(a).then(L)),D.push(Ml(a).then(K))),D.length&&Promise.all(D);return}T(null),m(null),p(null),E(new Set),d(null);const I=[Re(a,"",null,null)];_||(I.push(vi(a).then(L)),I.push(Ml(a).then(K))),Promise.all(I)},[a,n]),c.useEffect(()=>{if(a===null)return;const _=setTimeout(()=>{Re(a,H,b,u)},300);return()=>clearTimeout(_)},[H,a,u]),c.useEffect(()=>{a!==null&&(b!==null&&P("archive"),Re(a,H,b,u))},[b,a,u]);const Bn=c.useCallback(_=>{o(_),d(null);const I=new URLSearchParams(window.location.search);I.set("archive",_),I.delete("collection");const D=I.toString();history.replaceState(null,"",window.location.pathname+(D?"?"+D:""))},[]);c.useEffect(()=>{if(!a){g([]);return}po(a).then(g).catch(()=>g([]))},[a]);const tn=c.useCallback(_=>{if(!n){const q=_?y.find(Y=>Y.collection_uid===_):y.find(Y=>Y.slug==="_default_");if(q!=null&&q.requires_auth){t("login");return}}d(_),m(null),p(null),E(new Set),Re(a,H,b,_);const I=new URLSearchParams(window.location.search);_?(I.set("collection",_),I.set("archive",a)):(I.delete("collection"),a&&I.set("archive",a));const D=I.toString();history.replaceState(null,"",window.location.pathname+(D?"?"+D:""))},[a,H,b,n,y,Re]),gt=c.useCallback(_=>{P(_),_==="tags"&&a&&Ml(a).then(K)},[a]);c.useEffect(()=>{if(Rr)return;const _=Wg(j,R);window.location.pathname!==_&&history.pushState(null,"",_+window.location.search)},[j,R]);const We=c.useCallback(_=>{p(_?_.entry_uid:null),m(_)},[]),Sn=c.useCallback((_,I)=>{if(Ce.current.set(_.entry_uid,_),++ve.current,I.shiftKey&&J.current!==null){I.preventDefault();const D=[...document.querySelectorAll("#entries-body [data-entry-uid]")],q=D.findIndex(X=>X.dataset.entryUid===J.current),Y=D.findIndex(X=>X.dataset.entryUid===_.entry_uid);if(q===-1||Y===-1){J.current=_.entry_uid,E(new Set([_.entry_uid])),We(_);return}const se=Math.min(q,Y),C=Math.max(q,Y),Q=new Set(D.slice(se,C+1).map(X=>X.dataset.entryUid));E(Q),Q.size===1&&We(_)}else if(I.ctrlKey||I.metaKey){J.current=_.entry_uid;const D=new Set(k);if(D.has(_.entry_uid)?D.delete(_.entry_uid):D.add(_.entry_uid),E(D),D.size===0)We(null);else if(D.size===1){const[q]=D,Y=Ce.current.get(q)??h.find(se=>se.entry_uid===q)??null;if(Y)We(Y);else{const se=++ve.current;Or(a,q).then(C=>{se===ve.current&&(C!=null&&C.summary)&&We(C.summary)}).catch(()=>{})}}else We(null)}else J.current=_.entry_uid,E(new Set([_.entry_uid])),We(_)},[h,k,We,a]),Nn=c.useCallback(_=>{T(_)},[]),w=c.useCallback(()=>{T(null)},[]),B=c.useCallback(()=>{a&&Ml(a).then(K)},[a]),M=c.useCallback((_,I)=>{b===_?T(I):b!=null&&b.startsWith(_+"/")&&T(I+b.slice(_.length))},[b]),z=c.useCallback(_=>{(b===_||b!=null&&b.startsWith(_+"/"))&&T(null)},[b]),F=c.useCallback((_,I)=>{v(D=>D.map(q=>q.entry_uid===_?{...q,title:I}:q)),m(D=>D&&D.entry_uid===_?{...D,title:I}:D),Ct(D=>D&&D.summary.entry_uid===_?{...D,summary:{...D.summary,title:I}}:D)},[]),U=c.useCallback(()=>{if(!a||!f)return;const _=++mt.current;Or(a,f.entry_uid).then(I=>{_===mt.current&&Ct(I)}).catch(()=>{})},[a,f]),pe=c.useCallback(_=>{const I=h.some(D=>D.entry_uid===_);S(D=>{const q=new Set(D);return q.add(_),q}),v(D=>D.filter(q=>q.entry_uid!==_)),m(D=>(D==null?void 0:D.entry_uid)===_?null:D),p(D=>D===_?null:D),E(D=>{const q=new Set(D);return q.delete(_),q}),I||Re(a,H,b,u)},[h,a,H,b,u,Re]),de=c.useCallback(_=>{const I=new Set(h.map(q=>q.entry_uid)),D=[..._].some(q=>!I.has(q));S(q=>{const Y=new Set(q);return _.forEach(se=>Y.add(se)),Y}),v(q=>q.filter(Y=>!_.has(Y.entry_uid))),E(new Set),m(null),p(null),D&&Re(a,H,b,u)},[h,a,H,b,u,Re]);c.useEffect(()=>{if(k.size>=2)p(null),m(null);else if(k.size===1){const[_]=k;p(_)}else p(null),m(null)},[k]);const Te=c.useMemo(()=>h.filter(_=>k.has(_.entry_uid)),[h,k]);c.useEffect(()=>{if(!N||f)return;const _=h.find(I=>I.entry_uid===N);_&&m(_)},[h,N,f]),c.useEffect(()=>{if(Rr)return;const _=new URLSearchParams(window.location.search).get("archive"),I=new URLSearchParams;H&&I.set("q",H),j==="archive"&&b&&I.set("tag",b),j==="archive"&&N&&I.set("entry",N),j==="archive"&&u?(I.set("collection",u),a&&I.set("archive",a)):_&&a&&I.set("archive",a);const D=I.toString(),q=window.location.pathname+(D?"?"+D:"");window.location.pathname+window.location.search!==q&&history.replaceState(null,"",q)},[H,b,N,u,a,j]),c.useEffect(()=>{const _=I=>{var se,C,Q,X;const D=I.key==="/"&&!I.metaKey&&!I.ctrlKey&&!I.altKey,q=(I.metaKey||I.ctrlKey)&&I.key==="k";if(!D&&!q)return;const Y=(se=document.activeElement)==null?void 0:se.tagName;D&&(Y==="INPUT"||Y==="TEXTAREA"||Y==="SELECT")||D&&((C=document.activeElement)!=null&&C.isContentEditable)||(I.preventDefault(),j==="archive"?((Q=st.current)==null||Q.focus(),(X=st.current)==null||X.select()):(Et.current=!0,P("archive")))};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[j]),c.useEffect(()=>{const _=I=>{var Sr,Pe;if(I.metaKey||I.ctrlKey||I.altKey||I.key!=="j"&&I.key!=="k")return;const D=(Sr=document.activeElement)==null?void 0:Sr.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||(Pe=document.activeElement)!=null&&Pe.isContentEditable)return;const q=[...document.querySelectorAll("#entries-body [data-entry-uid]")];if(q.length===0)return;const[Y]=k.size===1?k:[null],se=Y?q.findIndex(vt=>vt.dataset.entryUid===Y):-1,C=I.key==="j"?Math.min(se+1,q.length-1):Math.max(se-1,0);if(C===se&&se!==-1)return;const Q=q[C<0?0:C],X=Q.dataset.entryUid;J.current=X;const at=++ve.current;E(new Set([X]));const Ot=Ce.current.get(X)??h.find(vt=>vt.entry_uid===X)??null;Ot?We(Ot):Or(a,X).then(vt=>{at===ve.current&&(vt!=null&&vt.summary)&&We(vt.summary)}).catch(()=>{}),Q.scrollIntoView({block:"nearest"}),I.preventDefault()};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[k,h,We,a]),c.useEffect(()=>{j==="archive"&&Et.current&&(Et.current=!1,requestAnimationFrame(()=>{var _,I;(_=st.current)==null||_.focus(),(I=st.current)==null||I.select()}))},[j]);const he=c.useCallback(()=>{Oe(!0)},[]),Ve=c.useCallback(()=>{Oe(!1)},[]),ie=c.useCallback(()=>{if(a)return Promise.allSettled([Re(a,H,b,u),vi(a).then(L)])},[a,H,b,u,Re]),it=c.useCallback((_,I,D="error",q=null)=>{if(D==="warning"&&Dt&&I)return;const Y=++oe.current;we(se=>[...se,{id:Y,text:_,locator:I,type:D,headline:q}])},[Dt]),yt=c.useCallback(_=>{we(I=>I.filter(D=>D.id!==_))},[]),Hs=c.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),_t(!0),we(_=>_.filter(I=>!(I.type==="warning"&&I.locator)))},[]),vl=c.useCallback(_=>{$t(I=>[...I,_])},[]),Ws=c.useCallback(_=>{$t(I=>I.filter(D=>D.id!==_))},[]),[Un,jr]=c.useState(null),[_n,xl]=c.useState(null),Vs=c.useCallback(()=>{f&&jr(f.entry_uid)},[f]),Hn=c.useCallback(()=>jr(null),[]),Wn=c.useCallback((_,I)=>{xl({src:_,entry:I})},[]),wl=c.useCallback(()=>xl(null),[]);return c.useEffect(()=>{jr(null)},[f]),c.useEffect(()=>{const _=I=>{var q,Y,se;if(I.key!=="Escape"||te||Un)return;const D=(q=document.activeElement)==null?void 0:q.tagName;D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||k.size>0&&(I.preventDefault(),E(new Set),(se=(Y=document.activeElement)==null?void 0:Y.blur)==null||se.call(Y))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[te,Un,k]),c.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!_n),()=>document.body.classList.remove("has-audio-bar")),[_n]),Rr?s.jsx(Og,{archiveId:Rr.archiveId,entryUid:Rr.entryUid}):e==="loading"?s.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?s.jsx(Rm,{onComplete:()=>t("login")}):e==="login"?s.jsx(Lm,{onLogin:_=>{r(_),t("authenticated")}}):s.jsx(Us.Provider,{value:{currentUser:n,setCurrentUser:r},children:s.jsxs(s.Fragment,{children:[s.jsx(zm,{archives:l,archiveId:a,onArchiveChange:Bn,view:j,onViewChange:gt,onCaptureClick:he,collections:y,selectedCollectionUid:u,onCollectionChange:tn,isPublicSession:!n,onSignInClick:()=>t("login")}),s.jsxs("main",{className:"app-shell",children:[s.jsxs("div",{className:"workspace",children:[j==="archive"&&s.jsxs("div",{className:"toolbar",children:[s.jsxs("div",{className:"search-field",children:[s.jsx("span",{className:"ico","aria-hidden":"true",children:s.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("circle",{cx:"11",cy:"11",r:"7"}),s.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),s.jsx("input",{ref:st,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":De,placeholder:"Search titles, URLs, types, tags…",value:H,onChange:_=>Z(_.target.value)}),s.jsx("span",{className:"kbd",children:"⌘K"})]}),s.jsxs("span",{className:"result-count",children:[re&&s.jsxs(s.Fragment,{children:[s.jsx("b",{children:re.split(" ")[0]})," ",re.split(" ").slice(1).join(" ")]}),b&&s.jsxs("button",{className:"tag-filter-badge",onClick:w,children:["× ",Wt?tf(b):b]})]})]}),j==="archive"&&s.jsx(Km,{entries:h,selectedUids:k,onRowClick:Sn,archiveId:a,pendingCaptures:Ne,deletedUids:x,isPublicSession:!n}),j==="runs"&&s.jsx(Gm,{runs:A}),j==="admin"&&s.jsx(Zm,{archives:l}),j==="tags"&&s.jsx(eg,{archiveId:a,tagNodes:V,tagFilter:b,onTagFilterSet:Nn,onViewChange:gt,onTagRenamed:M,onTagDeleted:z,onTagsRefresh:B,humanizeTags:Wt}),j==="collections"&&s.jsx(ng,{archiveId:a}),j==="settings"&&s.jsx(lg,{tab:R,onTabChange:G,archiveId:a})]}),s.jsx(mg,{archiveId:a,selectedEntry:f,selectedUids:k,selectedEntries:Te,detail:Fe,onTagFilterSet:Nn,tagNodes:V,onTagsRefresh:B,onEntryTitleChange:F,onEntryDeleted:pe,onBulkDeleted:de,humanizeTags:Wt,onDetailRefresh:U,onOpenPreview:Vs,onPlay:Wn,isPublicSession:!n})]}),Un&&f&&f.entry_uid===Un&&s.jsx($g,{archiveId:a,entry:f,detail:Fe,onClose:Hn}),_n&&s.jsx(Dg,{entry:_n.entry,src:_n.src,archiveId:a,onClose:wl}),s.jsx(Om,{open:te,archiveId:a,onClose:Ve,onCaptured:ie,onToast:it,activeJobs:Ne,onJobStarted:vl,onJobSettled:Ws}),s.jsx(Mg,{toasts:ne,onDismiss:yt,onIgnoreUblock:Hs})]})})}Yd(document.getElementById("root")).render(s.jsx(c.StrictMode,{children:s.jsx(Vg,{})}));
+`);v=N.flatMap((p,f)=>fN.kind==="style"&&N.style==="Code")&&(v=s.jsx("code",{style:l.iCode,children:v})),g.some(N=>N.kind==="style"&&N.style==="Bold")&&(v=s.jsx("strong",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Italic")&&(v=s.jsx("em",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Underline")&&(v=s.jsx("u",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Strikethrough")&&(v=s.jsx("s",{children:v}));const x=g.find(N=>N.kind==="url");if(x){const N=/^https?:\/\/t\.co\//i.test(v);v=s.jsx("a",{href:x.href,target:"_blank",rel:"noopener noreferrer",style:l.link,children:N?x.display:v})}const S=g.find(N=>N.kind==="mention");return S&&(v=s.jsx("a",{href:`https://x.com/${S.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:l.link,children:v})),s.jsx("span",{children:typeof v=="string"?Ns(v,l.link):v},d)})}function Eg(e,t,n){const r=(n==null?void 0:n.st)||ee,l=e.resolved_entities||[];return l.length===0?null:l.map((i,a)=>{var o;switch(i.type){case"divider":return s.jsx("hr",{style:r.bHr},a);case"media":{const u=dr(i.local_path,i.url,t);return u?s.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:d=>{var y;!d.metaKey&&!d.ctrlKey&&(d.preventDefault(),(y=n==null?void 0:n.onImgClick)==null||y.call(n,u))},children:s.jsx("img",{src:u,style:r.bImg,loading:"lazy",alt:""})},a):null}case"tweet":return i.tweet_id?s.jsxs("a",{href:`https://x.com/i/status/${i.tweet_id}`,target:"_blank",rel:"noopener noreferrer",style:r.bTweet,children:[s.jsx(cf,{}),"View post on X"]},a):null;case"link":return i.url?s.jsx("p",{style:r.bP,children:s.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",style:r.link,children:i.url})},a):null;case"markdown":{const u=i.markdown??((o=i.data)==null?void 0:o.markdown)??"";return s.jsx("pre",{style:r.bMdPre,children:s.jsx("code",{style:r.bMdCode,children:u})},a)}case"emoji":return i.url?s.jsx("img",{src:i.url,alt:"",style:{height:"1.2em",verticalAlign:"middle",margin:"0 1px"}},a):null;default:return null}})}function Si(e,t,n,r){const l=(r==null?void 0:r.st)||ee,i=e.type||"",a=e.text||"",o=e.inline_style_ranges||[],u=e.data||{},d=Cg(a,o,u.urls||[],u.mentions||[],l);switch(i){case"header-one":return s.jsx("h1",{style:l.bH1,children:d},t);case"header-two":{const y=a.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return y?s.jsxs("a",{href:`https://x.com/i/status/${y[1]}`,target:"_blank",rel:"noopener noreferrer",style:l.bTweet,children:[s.jsx(cf,{}),"View post on X"]},t):s.jsx("h2",{style:l.bH2,children:d},t)}case"unstyled":return a.trim()?s.jsx("p",{style:l.bP,children:d},t):s.jsx("span",{style:l.bSpacer},t);case"blockquote":return s.jsx("blockquote",{style:l.bQuote,children:d},t);case"unordered-list-item":case"ordered-list-item":return s.jsx("li",{style:l.bLi,children:d},t);case"atomic":return s.jsx("span",{children:Eg(e,n,r)},t);default:return a?s.jsx("p",{style:l.bP,children:d},t):null}}function bg(e,t,n){const r=(n==null?void 0:n.st)||ee,l=[];let i=0;for(;i{r&&(l==null||l(!0))},[r,l]);const o=r?ji:ee,u=e.cover_media||{},d=e.author||t||{},y=e.first_published_at_secs?uf(e.first_published_at_secs):"",h=[d.screen_name?`@${d.screen_name}`:"",y].filter(Boolean).join(" · "),v=dr(u.local_path,u.url,n),x=dr(d.avatar_local_path,d.avatar_url,n),S=s.jsxs(s.Fragment,{children:[i&&s.jsx(pf,{items:[{src:i,alt:""}],startIndex:0,onClose:()=>a(null)}),v&&s.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:N=>{!N.metaKey&&!N.ctrlKey&&(N.preventDefault(),a(v))},children:s.jsx("img",{src:v,style:o.aCover,alt:"Article cover"})}),s.jsxs("div",{style:o.aMeta,children:[e.title&&s.jsx("div",{style:o.aTweetTitle,children:e.title}),s.jsxs("div",{style:o.aAuthorRow,children:[x?s.jsx("img",{src:x,style:o.aAvatar,alt:d.name||""}):s.jsx("div",{style:o.aAvatarPh}),s.jsxs("div",{children:[s.jsx("div",{style:o.aAuthorName,children:d.name||d.screen_name||"Unknown"}),h&&s.jsx("div",{style:o.aAuthorSub,children:h})]})]})]}),s.jsx("hr",{style:o.aDivider}),s.jsx("div",{style:o.aBody,children:bg(e.blocks||[],n,{onImgClick:a,st:o})})]});return r?s.jsx("div",{style:ji.article,children:s.jsx("div",{style:ji.articleInner,children:S})}):s.jsx("div",{style:ee.article,children:S})}function Pg({photos:e,onOpen:t}){const n=e.length;if(n===0)return null;if(n===1)return s.jsx("a",{href:e[0].src,target:"_blank",rel:"noopener noreferrer",style:{display:"block"},onClick:l=>{!l.metaKey&&!l.ctrlKey&&(l.preventDefault(),t(0))},children:s.jsx("img",{src:e[0].src,alt:e[0].alt||"",style:ee.mediaImg,loading:"lazy"})});const r=n<=2?"180px":"140px";return s.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gridTemplateRows:n===2?r:`${r} ${r}`,gap:"2px"},children:e.map((l,i)=>s.jsx("a",{href:l.src,target:"_blank",rel:"noopener noreferrer",style:{display:"block",overflow:"hidden",gridRow:n===3&&i===0?"span 2":void 0},onClick:a=>{!a.metaKey&&!a.ctrlKey&&(a.preventDefault(),t(i))},children:s.jsx("img",{src:l.src,alt:l.alt||"",loading:"lazy",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},i))})}function pf({items:e,startIndex:t,onClose:n}){const[r,l]=c.useState(t);c.useEffect(()=>{const a=o=>{(o.key==="Escape"||o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.stopPropagation(),o.preventDefault()),o.key==="Escape"&&n(),o.key==="ArrowRight"&&l(u=>Math.min(u+1,e.length-1)),o.key==="ArrowLeft"&&l(u=>Math.max(u-1,0))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[n,e.length]);const i=e[r];return s.jsx("div",{style:ee.lightboxBackdrop,onClick:n,children:s.jsxs("div",{style:ee.lightboxContent,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{style:ee.lightboxToolbar,children:[e.length>1&&s.jsxs("span",{style:ee.lightboxCounter,children:[r+1," / ",e.length]}),s.jsx("a",{href:i.src,target:"_blank",rel:"noopener noreferrer",style:ee.lightboxLink,title:"Open in new tab",children:"↗"}),s.jsx("button",{style:ee.lightboxBtn,onClick:n,"aria-label":"Close",children:"×"})]}),s.jsx("img",{src:i.src,alt:i.alt||"",style:ee.lightboxImg}),e.length>1&&s.jsxs("div",{style:ee.lightboxNav,children:[s.jsx("button",{style:ee.lightboxNavBtn,onClick:()=>l(a=>Math.max(a-1,0)),disabled:r===0,children:"‹"}),s.jsx("button",{style:ee.lightboxNavBtn,onClick:()=>l(a=>Math.min(a+1,e.length-1)),disabled:r===e.length-1,children:"›"})]})]})})}function Mu({tweet:e,isInThread:t,isLast:n,artifactMap:r}){var f,m;const[l,i]=c.useState(null),a=e.author||{},o=e.created_at_secs?uf(e.created_at_secs):"",u=e.entities||{},d=dr(a.avatar_local_path,a.avatar_url,r),y=t&&!n,g=e.is_quote_status===!0,h=t?ee.tweetRowThread:ee.tweetRow,v=e.full_text||"",x=((m=(f=e.extended_entities)==null?void 0:f.media)!=null&&m.length?e.extended_entities.media:u.media)||[],S=[],N=[];for(const k of x)if(k.type==="photo"){const E=dr(k.local_path,k.media_url_https,r);E&&S.push({kind:"photo",src:E,alt:k.alt_text||""})}else if(k.type==="video"||k.type==="animated_gif"){const E=k.local_path&&r[k.local_path]||(()=>{var T,j;return(j=(((T=k.video_info)==null?void 0:T.variants)||[]).filter(P=>P.content_type==="video/mp4").sort((P,R)=>(R.bitrate||0)-(P.bitrate||0))[0])==null?void 0:j.url})();E&&N.push({kind:k.type==="animated_gif"?"gif":"video",src:E})}const p=[];for(const k of x){if(!k.url||!(k.type==="photo"?S.some(T=>T.src===dr(k.local_path,k.media_url_https,r)):N.length>0))continue;const b=mo(k,v,k.url);b&&p.push([b.s,b.e])}return s.jsxs(s.Fragment,{children:[l!==null&&s.jsx(pf,{items:S,startIndex:l,onClose:()=>i(null)}),s.jsxs("div",{style:h,children:[s.jsxs("div",{style:ee.leftCol,children:[d?s.jsx("img",{src:d,style:ee.avatar,alt:a.name||""}):s.jsx("div",{style:ee.avatarPh}),y&&s.jsx("div",{style:ee.threadLine})]}),s.jsxs("div",{style:ee.rightCol,children:[s.jsxs("div",{style:ee.authorRow,children:[s.jsx("span",{style:ee.authorName,children:a.name||a.screen_name||"Unknown"}),a.screen_name&&s.jsxs("span",{style:ee.authorHandle,children:["@",a.screen_name]}),o&&s.jsxs("span",{style:ee.datePart,children:["· ",o]}),g&&s.jsx("span",{style:ee.qtBadge,title:"Quote tweet",children:"↻ QT"})]}),s.jsx("div",{style:ee.tweetText,children:_g(v,u,p)}),S.length>0&&s.jsx("div",{style:ee.mediaGrid,children:s.jsx(Pg,{photos:S,onOpen:k=>i(k)})}),N.map((k,E)=>s.jsx("div",{style:ee.mediaGrid,children:s.jsx("video",{src:k.src,style:ee.mediaVideo,controls:!0,loop:k.kind==="gif",muted:k.kind==="gif",autoPlay:k.kind==="gif"})},E)),(e.retweet_count>0||e.favorite_count>0)&&s.jsxs("div",{style:ee.stats,children:[e.favorite_count>0&&s.jsxs("span",{children:["❤️ ",e.favorite_count.toLocaleString()]}),e.retweet_count>0&&s.jsxs("span",{children:["🔁 ",e.retweet_count.toLocaleString()]})]})]})]})]})}function Lg({archiveId:e,entryUid:t,artifacts:n,entityKind:r,fullPage:l,onXArticle:i}){const[a,o]=c.useState(!0),[u,d]=c.useState(null),[y,g]=c.useState([]);if(c.useEffect(()=>{if(o(!0),d(null),g([]),!n||!e||!t){o(!1);return}const x=n.map((N,p)=>({...N,index:p})).filter(N=>N.artifact_role==="raw_tweet_json");if(x.length===0){d("No tweet data found."),o(!1);return}let S=!1;return Vh(e,t,x.map(N=>N.index)).then(async N=>{if(S)return;const p=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,f=T=>{var P;const j=T.full_text||"";return(((P=T.entities)==null?void 0:P.urls)||[]).map(R=>{var G;if(R.fromIndex!=null&&R.toIndex!=null)return[R.fromIndex,R.toIndex];if(((G=R.indices)==null?void 0:G.length)===2)return[R.indices[0],R.indices[1]];if(R.url){const H=j.indexOf(R.url);if(H!==-1)return[H,H+R.url.length]}return null}).filter(Boolean)},m=(T,j,P)=>T.some(([R,G])=>R<=j&&G>=P),k=new Set;for(const T of N){const j=T.full_text||"",P=f(T);let R;for(p.lastIndex=0;(R=p.exec(j))!==null;)m(P,R.index,R.index+R[0].length)||k.add(R[0])}const E=k.size>0?await Qh([...k]).catch(()=>({})):{},b=N.map(T=>{var H;const j=T.full_text||"",P=f(T),R=[];let G;for(p.lastIndex=0;(G=p.exec(j))!==null;){const Z=G[0],re=E[Z];re&&re!==Z&&!m(P,G.index,G.index+Z.length)&&R.push({url:Z,expanded_url:re,display_url:(()=>{try{const ce=new URL(re);return ce.hostname+(ce.pathname.length>1?"/…":"")}catch{return re}})(),fromIndex:G.index,toIndex:G.index+Z.length})}return R.length===0?T:{...T,entities:{...T.entities||{},urls:[...((H=T.entities)==null?void 0:H.urls)||[],...R]}}});S||g(b)}).catch(N=>{S||d(N.message||"Failed to load tweet.")}).finally(()=>{S||o(!1)}),()=>{S=!0}},[e,t,n]),a)return s.jsx("div",{style:ee.loading,children:"Loading…"});if(u)return s.jsxs("div",{style:ee.error,children:["Error: ",u]});if(y.length===0)return null;const h=Sg(e,t,n);if(r==="tweet_thread")return s.jsx("div",{style:ee.threadOuter,children:y.map((x,S)=>s.jsx(Mu,{tweet:x,isInThread:!0,isLast:S===y.length-1,artifactMap:h},x.id||S))});const v=y[0];return v.is_article&&v.article?s.jsx(Tg,{article:v.article,tweetAuthor:v.author,artifactMap:h,fullPage:l,onXArticle:i}):s.jsx("div",{style:ee.card,children:s.jsx(Mu,{tweet:v,isInThread:!1,isLast:!0,artifactMap:h})})}function Rg({src:e,mime:t,title:n}){const[r,l]=c.useState(null),[i,a]=c.useState(null);return c.useEffect(()=>{let o=!1;return l(null),a(null),fetch(e,{credentials:"same-origin"}).then(u=>{if(!u.ok)throw new Error(`HTTP ${u.status}`);return u.text()}).then(u=>{o||l(u)}).catch(u=>{o||a(u.message||String(u))}),()=>{o=!0}},[e]),i?s.jsxs("div",{className:"text-preview text-preview--error",children:["Failed to load text: ",i]}):r===null?s.jsx("div",{className:"text-preview text-preview--loading",children:"Loading…"}):s.jsxs("div",{className:"text-preview",children:[n&&s.jsx("h1",{className:"text-preview__title",children:n}),s.jsx("pre",{className:"text-preview__body",children:r}),t&&s.jsx("div",{className:"text-preview__mime",children:t})]})}const zg=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),Ig=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),$g=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Dg=new Set(["md","markdown","txt"]),Og={mp4:"video/mp4",webm:"video/webm",mov:"video/quicktime",mkv:"video/x-matroska",avi:"video/x-msvideo",m4v:"video/mp4",ogv:"video/ogg"};function hf({archiveId:e,entry:t,detail:n,fullPage:r,onXArticle:l}){if(!t)return s.jsx("div",{className:"preview-panel preview-panel--empty",children:s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Select an entry to preview"})});if(!n)return s.jsx("div",{className:"preview-panel preview-panel--loading",children:s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Loading…"})});const{summary:i,artifacts:a}=n,o=i.entry_uid,u=i.entity_kind;if(u==="tweet"||u==="tweet_thread"){const v=s.jsx(Lg,{archiveId:e,entryUid:o,artifacts:a,entityKind:u,fullPage:r,onXArticle:l});return r?v:s.jsx("div",{className:"preview-tweet-wrap",children:v})}const d=a.findIndex(v=>v.artifact_role==="primary_media");if(d===-1)return s.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),a.length>0&&s.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((v,x)=>s.jsxs("li",{children:[v.artifact_role,": ",v.relpath]},x))})]});const y=a[d],g=`/api/archives/${e}/entries/${o}/artifacts/${d}`,h=y.relpath.split(".").pop().toLowerCase();return zg.has(h)?s.jsx("div",{className:"preview-panel",children:s.jsx(kg,{src:g,contentType:Og[h]||"video/mp4"})}):Ig.has(h)?s.jsxs("div",{className:"preview-panel preview-panel--audio",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"12px",padding:"24px",fontFamily:"var(--sans)"},children:[s.jsx("span",{style:{fontSize:"2rem"},children:"🎵"}),s.jsx("span",{style:{color:"var(--ink)",fontSize:"0.95rem",fontWeight:600},children:i.title||o}),s.jsx("audio",{src:g,controls:!0,style:{marginTop:"8px",width:"100%",maxWidth:"400px"}})]}):h==="pdf"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(Du,{src:g,type:"pdf",title:i.title,originalUrl:i.original_url})}):h==="html"||h==="htm"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(Du,{src:g,type:"page",title:i.title,originalUrl:i.original_url})}):Dg.has(h)?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0,overflow:"auto"},children:s.jsx(Rg,{src:g,mime:y.mime_type,title:i.title})}):$g.has(h)?s.jsx("div",{className:"preview-panel",style:{height:"100%"},children:s.jsx(jg,{src:g,alt:i.title||"Image"})}):s.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),s.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((v,x)=>s.jsxs("li",{children:[v.artifact_role,": ",v.relpath]},x))})]})}function Ag({archiveId:e,entry:t,detail:n,onClose:r}){var l,i;return c.useEffect(()=>{const a=o=>{o.key==="Escape"&&r()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r]),s.jsx("div",{className:"preview-modal-backdrop",onClick:r,children:s.jsxs("div",{className:`preview-modal${((l=n==null?void 0:n.summary)==null?void 0:l.entity_kind)==="tweet"||((i=n==null?void 0:n.summary)==null?void 0:i.entity_kind)==="tweet_thread"?"":" preview-modal--full"}`,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{className:"preview-modal-header",children:[s.jsx("span",{className:"preview-modal-title",children:(t==null?void 0:t.title)||(t==null?void 0:t.entry_uid)||"Preview"}),s.jsx("a",{className:"preview-modal-newtab",href:`/preview/${e}/${t==null?void 0:t.entry_uid}`,target:"_blank",rel:"noopener noreferrer",title:"Open in new tab",children:"↗"}),s.jsx("button",{className:"preview-modal-close",onClick:r,"aria-label":"Close preview",children:"×"})]}),s.jsx("div",{className:"preview-modal-body",children:s.jsx(hf,{archiveId:e,entry:t,detail:n})})]})})}function Fu(e){if(!isFinite(e)||isNaN(e))return"--:--";const t=Math.floor(e/60),n=Math.floor(e%60);return`${t}:${String(n).padStart(2,"0")}`}function Mg({entry:e,src:t,archiveId:n,onClose:r}){const l=c.useRef(null),[i,a]=c.useState(!1),[o,u]=c.useState(0),[d,y]=c.useState(NaN),[g,h]=c.useState(1);c.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),y(NaN),a(!1))},[t]),c.useEffect(()=>{l.current&&(l.current.volume=g)},[g]);function v(){const f=l.current;f&&(i?f.pause():f.play().catch(()=>{}))}function x(f){const m=l.current;if(!m||!isFinite(d))return;const k=Number(f.target.value);m.currentTime=k,u(k)}function S(f){h(Number(f.target.value))}const N=(e==null?void 0:e.title)||(e==null?void 0:e.entry_uid)||"Unknown",p=(e==null?void 0:e.source_kind)||"other";return s.jsxs(s.Fragment,{children:[s.jsx("audio",{ref:l,src:t||void 0,preload:"auto",onPlay:()=>a(!0),onPause:()=>a(!1),onEnded:()=>a(!1),onTimeUpdate:()=>{var f;return u(((f=l.current)==null?void 0:f.currentTime)??0)},onLoadedMetadata:()=>{var f;return y(((f=l.current)==null?void 0:f.duration)??NaN)},onDurationChange:()=>{var f;return y(((f=l.current)==null?void 0:f.duration)??NaN)},style:{display:"none"}}),s.jsxs("div",{className:"audio-bar",style:{position:"fixed",bottom:0,left:0,right:0,zIndex:100,background:"var(--paper-3)",borderTop:"1px solid var(--line)",display:"flex",alignItems:"center",gap:"16px",padding:"0 16px",height:"56px",fontFamily:"var(--sans)"},children:[s.jsxs("div",{className:"audio-bar-info",style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flex:"0 1 220px",overflow:"hidden"},children:[s.jsx("span",{className:"source-icon",style:{flexShrink:0,width:"18px",height:"18px",display:"flex",alignItems:"center"},dangerouslySetInnerHTML:{__html:Bs(p)}}),s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:N,children:N})]}),s.jsxs("div",{className:"audio-bar-controls",style:{display:"flex",alignItems:"center",gap:"10px",flex:"1 1 0",minWidth:0},children:[s.jsx("button",{onClick:v,"aria-label":i?"Pause":"Play",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--ink)",flexShrink:0,fontSize:"1.2rem",lineHeight:1},children:i?"⏸":"▶"}),s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:Fu(o)}),s.jsx("input",{type:"range",min:0,max:isFinite(d)?d:0,step:.1,value:isFinite(o)?o:0,onChange:x,"aria-label":"Seek",style:{flex:1,minWidth:0,accentColor:"var(--accent)"}}),s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:Fu(d)})]}),s.jsxs("div",{className:"audio-bar-right",style:{display:"flex",alignItems:"center",gap:"8px",flex:"0 1 160px"},children:[s.jsx("span",{style:{fontSize:"0.85rem",color:"var(--muted)",flexShrink:0},children:"🔊"}),s.jsx("input",{type:"range",min:0,max:1,step:.01,value:g,onChange:S,"aria-label":"Volume",style:{width:"80px",accentColor:"var(--accent)"}}),s.jsx("button",{onClick:r,"aria-label":"Close audio player",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--muted)",fontSize:"1rem",lineHeight:1,marginLeft:"4px"},children:"✕"})]})]})]})}function Fg({archiveId:e,entryUid:t}){var h,v;const[n,r]=c.useState(null),[l,i]=c.useState(!0),[a,o]=c.useState(null),[u,d]=c.useState(!1);c.useEffect(()=>{if(!u)return;const x=document.documentElement,S=document.body,N=x.style.colorScheme,p=S.style.background;return x.style.colorScheme="dark",S.style.background="#000",()=>{x.style.colorScheme=N,S.style.background=p}},[u]),c.useEffect(()=>{d(!1),Or(e,t).then(x=>{r(x),i(!1)}).catch(x=>{o((x==null?void 0:x.message)||"Failed to load entry"),i(!1)})},[e,t]);const y=((h=n==null?void 0:n.summary)==null?void 0:h.title)||t,g=(v=n==null?void 0:n.summary)==null?void 0:v.original_url;return s.jsxs("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column",background:u?"#000":"var(--paper)",fontFamily:"var(--sans)"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:u?"8px 12px":"10px 16px",borderBottom:u?"none":"1px solid var(--line)",flexShrink:0,position:u?"sticky":"relative",top:0,zIndex:20,background:u?"rgba(0,0,0,0.82)":"var(--paper-2)",backdropFilter:u?"blur(12px)":"none",WebkitBackdropFilter:u?"blur(12px)":"none"},children:[s.jsx("a",{href:"/",style:{color:u?"#1d9bf0":"var(--accent)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"← Archive"}),s.jsx("span",{style:{flex:1,fontSize:"14px",fontWeight:600,color:u?"#e7e9ea":"var(--ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),g&&s.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{color:u?"#71767b":"var(--muted)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"Original ↗"})]}),s.jsxs("div",{style:u?{flex:1}:{flex:1,minHeight:0,overflow:"auto",display:"flex",flexDirection:"column"},children:[l&&s.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},children:"Loading…"}),a&&s.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},children:a}),n&&s.jsx(hf,{archiveId:e,entry:n.summary,detail:n,fullPage:!0,onXArticle:d})]})]})}const Bg=7e3;function Ug({toasts:e,onDismiss:t,onIgnoreUblock:n}){return e.length?s.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(r=>s.jsx(Wg,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function Hg(e){if(!e)return null;if(e.length<=52)return e;try{const{hostname:t,pathname:n,search:r}=new URL(e),l=n.split("/").filter(Boolean),i=(l[l.length-1]??"")+r,a=i?`${t}/…/${i}`:t;return a.length<=56?a:a.slice(0,53)+"…"}catch{return"…"+e.slice(-51)}}function Wg({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=c.useState(!1),i=e.type==="warning",a=e.type==="success";c.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),Bg);return()=>clearTimeout(u)},[r,e.id,t]);const o=Hg(e.locator);return a?s.jsx("div",{className:"toast toast--success",role:"alert","aria-atomic":"true",children:s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✓"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsx("div",{className:"toast-btns",children:s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})})]})}):i?s.jsxs("div",{className:"toast toast--warning",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"⚠"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived with warnings"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),"aria-expanded":r,children:r?"Hide":"Details"}),e.locator&&s.jsx("button",{type:"button",className:"toast-view-btn toast-ignore-btn",onClick:()=>{n==null||n(),t(e.id)},children:"Ignore"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&s.jsx("p",{className:"toast-warning-detail",children:e.text||"The page was captured but one or more browser extensions were unavailable (ad-blocking or cookie-consent). Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config."})]}):s.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Capture failed"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),children:r?"Hide":"View error"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&e.text&&s.jsx("pre",{className:"toast-error-detail",children:e.text})]})}const Us=c.createContext(null),Vg=["archive","tags","collections","runs","admin","settings"],Qg=["profile","tokens","instance","cookies","extensions","storage"],Rr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})();function Mt(){const e=window.location.pathname.split("/").filter(Boolean),t=Vg.includes(e[0])?e[0]:"archive",n=t==="settings"&&Qg.includes(e[1])?e[1]:"profile",r=new URLSearchParams(window.location.search),l=r.get("q")??"",i=t==="archive"?r.get("tag")??null:null,a=t==="archive"?r.get("entry")??null:null,o=t==="archive"?r.get("collection")??null:null,u=o==="main"?null:o,d=r.get("archive")??null;return{view:t,settingsTab:n,q:l,tag:i,entry:a,collection:u,archive:d}}function qg(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function Kg(){const[e,t]=c.useState("loading"),[n,r]=c.useState(null);c.useEffect(()=>{(async()=>{var D,K,Y;if(await rm()){t("setup");return}const I=await am();if(!I){const{collection:se,archive:C}=Mt();try{const q=await _u(),X=C?((D=q.find(xe=>xe.id===C))==null?void 0:D.id)??((K=q[0])==null?void 0:K.id):(Y=q[0])==null?void 0:Y.id;if(X){await Cu(X,se),i(q),o(X),d(se),t("authenticated");return}}catch{}t("login");return}r(I),t("authenticated")})()},[]),c.useEffect(()=>{const _=()=>{n&&(r(null),t("login"))};return window.addEventListener("auth:expired",_),()=>window.removeEventListener("auth:expired",_)},[n]),c.useEffect(()=>{const _=()=>{const{view:I,settingsTab:D,q:K,tag:Y,entry:se,collection:C}=Mt();P(I),G(D),Z(K),T(Y),p(se),m(null),E(se?new Set([se]):new Set),d(C)};return window.addEventListener("popstate",_),()=>window.removeEventListener("popstate",_)},[]);const[l,i]=c.useState([]),[a,o]=c.useState(null),[u,d]=c.useState(()=>Mt().collection),[y,g]=c.useState([]),[h,v]=c.useState([]),[x,S]=c.useState(()=>new Set),[N,p]=c.useState(()=>Mt().entry),[f,m]=c.useState(null),[k,E]=c.useState(()=>{const _=Mt().entry;return _?new Set([_]):new Set}),[b,T]=c.useState(()=>Mt().tag),[j,P]=c.useState(()=>Mt().view),[R,G]=c.useState(()=>Mt().settingsTab),[H,Z]=c.useState(()=>Mt().q),[re,ce]=c.useState(""),[Ae,ye]=c.useState(!1),[A,L]=c.useState([]),[V,Q]=c.useState([]),[te,ze]=c.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[ne,ke]=c.useState([]),oe=c.useRef(0),[_e,$t]=c.useState(()=>{try{const _=JSON.parse(sessionStorage.getItem("pendingCaptures")||"[]");if(Array.isArray(_))return _}catch{}return[]});c.useEffect(()=>{sessionStorage.setItem("pendingCaptures",JSON.stringify(_e))},[_e]);const[Dt,_t]=c.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[Be,Ct]=c.useState(null),mt=c.useRef(0),it=c.useRef(null),Et=c.useRef(!1),O=c.useRef(!0),J=c.useRef(null),ve=c.useRef(0),Ee=c.useRef(new Map),Wt=(n==null?void 0:n.humanize_slugs)??!1;c.useEffect(()=>{const _=++mt.current;Ct(null),!(!f||!a)&&Or(a,f.entry_uid).then(I=>{_===mt.current&&Ct(I)}).catch(()=>{})},[f,a]),c.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",te)},[te]);const Ie=c.useCallback(async(_,I,D,K)=>{if(_){ye(!0);try{let Y;I||D?Y=await Bh(_,I,D,K):Y=await Cu(_,K),v(Y),E(se=>{if(se.size<2)return se;const C=new Set(Y.map(X=>X.entry_uid)),q=new Set([...se].filter(X=>C.has(X)));return q.size===se.size?se:q}),ce(Y.length===0?"No results":`${Y.length} result${Y.length===1?"":"s"}`)}catch{v([]),ce("Search failed. Try again.")}finally{ye(!1)}}},[]);c.useEffect(()=>{e==="authenticated"&&(a||_u().then(_=>{if(i(_),_.length>0){const{archive:I}=Mt(),D=I?_.find(K=>K.id===I):null;o((D==null?void 0:D.id)??_[0].id)}}))},[e,a]),c.useEffect(()=>{if(!a)return;const _=!n;if(O.current){O.current=!1;const D=[];_||(D.push(vi(a).then(L)),D.push(Ml(a).then(Q))),D.length&&Promise.all(D);return}T(null),m(null),p(null),E(new Set),d(null);const I=[Ie(a,"",null,null)];_||(I.push(vi(a).then(L)),I.push(Ml(a).then(Q))),Promise.all(I)},[a,n]),c.useEffect(()=>{if(a===null)return;const _=setTimeout(()=>{Ie(a,H,b,u)},300);return()=>clearTimeout(_)},[H,a,u]),c.useEffect(()=>{a!==null&&(b!==null&&P("archive"),Ie(a,H,b,u))},[b,a,u]);const Bn=c.useCallback(_=>{o(_),d(null);const I=new URLSearchParams(window.location.search);I.set("archive",_),I.delete("collection");const D=I.toString();history.replaceState(null,"",window.location.pathname+(D?"?"+D:""))},[]);c.useEffect(()=>{if(!a){g([]);return}po(a).then(g).catch(()=>g([]))},[a]);const tn=c.useCallback(_=>{if(!n){const K=_?y.find(Y=>Y.collection_uid===_):y.find(Y=>Y.slug==="_default_");if(K!=null&&K.requires_auth){t("login");return}}d(_),m(null),p(null),E(new Set),Ie(a,H,b,_);const I=new URLSearchParams(window.location.search);_?(I.set("collection",_),I.set("archive",a)):(I.delete("collection"),a&&I.set("archive",a));const D=I.toString();history.replaceState(null,"",window.location.pathname+(D?"?"+D:""))},[a,H,b,n,y,Ie]),gt=c.useCallback(_=>{P(_),_==="tags"&&a&&Ml(a).then(Q)},[a]);c.useEffect(()=>{if(Rr)return;const _=qg(j,R);window.location.pathname!==_&&history.pushState(null,"",_+window.location.search)},[j,R]);const Ve=c.useCallback(_=>{p(_?_.entry_uid:null),m(_)},[]),Sn=c.useCallback((_,I)=>{if(Ee.current.set(_.entry_uid,_),++ve.current,I.shiftKey&&J.current!==null){I.preventDefault();const D=[...document.querySelectorAll("#entries-body [data-entry-uid]")],K=D.findIndex(X=>X.dataset.entryUid===J.current),Y=D.findIndex(X=>X.dataset.entryUid===_.entry_uid);if(K===-1||Y===-1){J.current=_.entry_uid,E(new Set([_.entry_uid])),Ve(_);return}const se=Math.min(K,Y),C=Math.max(K,Y),q=new Set(D.slice(se,C+1).map(X=>X.dataset.entryUid));E(q),q.size===1&&Ve(_)}else if(I.ctrlKey||I.metaKey){J.current=_.entry_uid;const D=new Set(k);if(D.has(_.entry_uid)?D.delete(_.entry_uid):D.add(_.entry_uid),E(D),D.size===0)Ve(null);else if(D.size===1){const[K]=D,Y=Ee.current.get(K)??h.find(se=>se.entry_uid===K)??null;if(Y)Ve(Y);else{const se=++ve.current;Or(a,K).then(C=>{se===ve.current&&(C!=null&&C.summary)&&Ve(C.summary)}).catch(()=>{})}}else Ve(null)}else J.current=_.entry_uid,E(new Set([_.entry_uid])),Ve(_)},[h,k,Ve,a]),Nn=c.useCallback(_=>{T(_)},[]),w=c.useCallback(()=>{T(null)},[]),B=c.useCallback(()=>{a&&Ml(a).then(Q)},[a]),M=c.useCallback((_,I)=>{b===_?T(I):b!=null&&b.startsWith(_+"/")&&T(I+b.slice(_.length))},[b]),z=c.useCallback(_=>{(b===_||b!=null&&b.startsWith(_+"/"))&&T(null)},[b]),F=c.useCallback((_,I)=>{v(D=>D.map(K=>K.entry_uid===_?{...K,title:I}:K)),m(D=>D&&D.entry_uid===_?{...D,title:I}:D),Ct(D=>D&&D.summary.entry_uid===_?{...D,summary:{...D.summary,title:I}}:D)},[]),U=c.useCallback(()=>{if(!a||!f)return;const _=++mt.current;Or(a,f.entry_uid).then(I=>{_===mt.current&&Ct(I)}).catch(()=>{})},[a,f]),pe=c.useCallback(_=>{const I=h.some(D=>D.entry_uid===_);S(D=>{const K=new Set(D);return K.add(_),K}),v(D=>D.filter(K=>K.entry_uid!==_)),m(D=>(D==null?void 0:D.entry_uid)===_?null:D),p(D=>D===_?null:D),E(D=>{const K=new Set(D);return K.delete(_),K}),I||Ie(a,H,b,u)},[h,a,H,b,u,Ie]),de=c.useCallback(_=>{const I=new Set(h.map(K=>K.entry_uid)),D=[..._].some(K=>!I.has(K));S(K=>{const Y=new Set(K);return _.forEach(se=>Y.add(se)),Y}),v(K=>K.filter(Y=>!_.has(Y.entry_uid))),E(new Set),m(null),p(null),D&&Ie(a,H,b,u)},[h,a,H,b,u,Ie]);c.useEffect(()=>{if(k.size>=2)p(null),m(null);else if(k.size===1){const[_]=k;p(_)}else p(null),m(null)},[k]);const Pe=c.useMemo(()=>h.filter(_=>k.has(_.entry_uid)),[h,k]);c.useEffect(()=>{if(!N||f)return;const _=h.find(I=>I.entry_uid===N);_&&m(_)},[h,N,f]),c.useEffect(()=>{if(Rr)return;const _=new URLSearchParams(window.location.search).get("archive"),I=new URLSearchParams;H&&I.set("q",H),j==="archive"&&b&&I.set("tag",b),j==="archive"&&N&&I.set("entry",N),j==="archive"&&u?(I.set("collection",u),a&&I.set("archive",a)):_&&a&&I.set("archive",a);const D=I.toString(),K=window.location.pathname+(D?"?"+D:"");window.location.pathname+window.location.search!==K&&history.replaceState(null,"",K)},[H,b,N,u,a,j]),c.useEffect(()=>{const _=I=>{var se,C,q,X;const D=I.key==="/"&&!I.metaKey&&!I.ctrlKey&&!I.altKey,K=(I.metaKey||I.ctrlKey)&&I.key==="k";if(!D&&!K)return;const Y=(se=document.activeElement)==null?void 0:se.tagName;D&&(Y==="INPUT"||Y==="TEXTAREA"||Y==="SELECT")||D&&((C=document.activeElement)!=null&&C.isContentEditable)||(I.preventDefault(),j==="archive"?((q=it.current)==null||q.focus(),(X=it.current)==null||X.select()):(Et.current=!0,P("archive")))};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[j]),c.useEffect(()=>{const _=I=>{var Sr,Le;if(I.metaKey||I.ctrlKey||I.altKey||I.key!=="j"&&I.key!=="k")return;const D=(Sr=document.activeElement)==null?void 0:Sr.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||(Le=document.activeElement)!=null&&Le.isContentEditable)return;const K=[...document.querySelectorAll("#entries-body [data-entry-uid]")];if(K.length===0)return;const[Y]=k.size===1?k:[null],se=Y?K.findIndex(vt=>vt.dataset.entryUid===Y):-1,C=I.key==="j"?Math.min(se+1,K.length-1):Math.max(se-1,0);if(C===se&&se!==-1)return;const q=K[C<0?0:C],X=q.dataset.entryUid;J.current=X;const xe=++ve.current;E(new Set([X]));const Ot=Ee.current.get(X)??h.find(vt=>vt.entry_uid===X)??null;Ot?Ve(Ot):Or(a,X).then(vt=>{xe===ve.current&&(vt!=null&&vt.summary)&&Ve(vt.summary)}).catch(()=>{}),q.scrollIntoView({block:"nearest"}),I.preventDefault()};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[k,h,Ve,a]),c.useEffect(()=>{j==="archive"&&Et.current&&(Et.current=!1,requestAnimationFrame(()=>{var _,I;(_=it.current)==null||_.focus(),(I=it.current)==null||I.select()}))},[j]);const he=c.useCallback(()=>{ze(!0)},[]),Qe=c.useCallback(()=>{ze(!1)},[]),ie=c.useCallback(()=>{if(a)return Promise.allSettled([Ie(a,H,b,u),vi(a).then(L)])},[a,H,b,u,Ie]),at=c.useCallback((_,I,D="error",K=null)=>{if(D==="warning"&&Dt&&I)return;const Y=++oe.current;ke(se=>[...se,{id:Y,text:_,locator:I,type:D,headline:K}])},[Dt]),yt=c.useCallback(_=>{ke(I=>I.filter(D=>D.id!==_))},[]),Hs=c.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),_t(!0),ke(_=>_.filter(I=>!(I.type==="warning"&&I.locator)))},[]),vl=c.useCallback(_=>{$t(I=>[...I,_])},[]),Ws=c.useCallback(_=>{$t(I=>I.filter(D=>D.id!==_))},[]),[Un,jr]=c.useState(null),[_n,xl]=c.useState(null),Vs=c.useCallback(()=>{f&&jr(f.entry_uid)},[f]),Hn=c.useCallback(()=>jr(null),[]),Wn=c.useCallback((_,I)=>{xl({src:_,entry:I})},[]),wl=c.useCallback(()=>xl(null),[]);return c.useEffect(()=>{jr(null)},[f]),c.useEffect(()=>{const _=I=>{var K,Y,se;if(I.key!=="Escape"||te||Un)return;const D=(K=document.activeElement)==null?void 0:K.tagName;D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||k.size>0&&(I.preventDefault(),E(new Set),(se=(Y=document.activeElement)==null?void 0:Y.blur)==null||se.call(Y))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[te,Un,k]),c.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!_n),()=>document.body.classList.remove("has-audio-bar")),[_n]),Rr?s.jsx(Fg,{archiveId:Rr.archiveId,entryUid:Rr.entryUid}):e==="loading"?s.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?s.jsx($m,{onComplete:()=>t("login")}):e==="login"?s.jsx(Im,{onLogin:_=>{r(_),t("authenticated")}}):s.jsx(Us.Provider,{value:{currentUser:n,setCurrentUser:r},children:s.jsxs(s.Fragment,{children:[s.jsx(Dm,{archives:l,archiveId:a,onArchiveChange:Bn,view:j,onViewChange:gt,onCaptureClick:he,collections:y,selectedCollectionUid:u,onCollectionChange:tn,isPublicSession:!n,onSignInClick:()=>t("login")}),s.jsxs("main",{className:"app-shell",children:[s.jsxs("div",{className:"workspace",children:[j==="archive"&&s.jsxs("div",{className:"toolbar",children:[s.jsxs("div",{className:"search-field",children:[s.jsx("span",{className:"ico","aria-hidden":"true",children:s.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("circle",{cx:"11",cy:"11",r:"7"}),s.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),s.jsx("input",{ref:it,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":Ae,placeholder:"Search titles, URLs, types, tags…",value:H,onChange:_=>Z(_.target.value)}),s.jsx("span",{className:"kbd",children:"⌘K"})]}),s.jsxs("span",{className:"result-count",children:[re&&s.jsxs(s.Fragment,{children:[s.jsx("b",{children:re.split(" ")[0]})," ",re.split(" ").slice(1).join(" ")]}),b&&s.jsxs("button",{className:"tag-filter-badge",onClick:w,children:["× ",Wt?nf(b):b]})]})]}),j==="archive"&&s.jsx(Gm,{entries:h,selectedUids:k,onRowClick:Sn,archiveId:a,pendingCaptures:_e,deletedUids:x,isPublicSession:!n}),j==="runs"&&s.jsx(eg,{runs:A}),j==="admin"&&s.jsx(ng,{archives:l}),j==="tags"&&s.jsx(rg,{archiveId:a,tagNodes:V,tagFilter:b,onTagFilterSet:Nn,onViewChange:gt,onTagRenamed:M,onTagDeleted:z,onTagsRefresh:B,humanizeTags:Wt}),j==="collections"&&s.jsx(sg,{archiveId:a}),j==="settings"&&s.jsx(ag,{tab:R,onTabChange:G,archiveId:a})]}),s.jsx(vg,{archiveId:a,selectedEntry:f,selectedUids:k,selectedEntries:Pe,detail:Be,onTagFilterSet:Nn,tagNodes:V,onTagsRefresh:B,onEntryTitleChange:F,onEntryDeleted:pe,onBulkDeleted:de,humanizeTags:Wt,onDetailRefresh:U,onOpenPreview:Vs,onPlay:Wn,isPublicSession:!n})]}),Un&&f&&f.entry_uid===Un&&s.jsx(Ag,{archiveId:a,entry:f,detail:Be,onClose:Hn}),_n&&s.jsx(Mg,{entry:_n.entry,src:_n.src,archiveId:a,onClose:wl}),s.jsx(Fm,{open:te,archiveId:a,onClose:Qe,onCaptured:ie,onToast:at,activeJobs:_e,onJobStarted:vl,onJobSettled:Ws}),s.jsx(Ug,{toasts:ne,onDismiss:yt,onIgnoreUblock:Hs})]})})}Zd(document.getElementById("root")).render(s.jsx(c.StrictMode,{children:s.jsx(Kg,{})}));
diff --git a/crates/archivr-server/static/index.html b/crates/archivr-server/static/index.html
index b6ad996..323be91 100644
--- a/crates/archivr-server/static/index.html
+++ b/crates/archivr-server/static/index.html
@@ -6,8 +6,8 @@
Archivr
-
-
+
+